Changes in / [7b50125:05e6dbe] in buchla-emu
Legend:
- Unmodified
- Added
- Removed
-
emu/cpu.c
r7b50125 r05e6dbe 75 75 { 0x180000, 0x200000, 0, fpu_init, fpu_quit, fpu_exec, fpu_read, fpu_write }, 76 76 { 0x200000, 0x280002, 0, vid_init, vid_quit, vid_exec, vid_read, vid_write }, 77 { 0x3a0001, 0x3a4001, 4, tim_init, tim_quit, tim_exec, tim_read, tim_write },77 { 0x3a0001, 0x3a4001, 0, tim_init, tim_quit, tim_exec, tim_read, tim_write }, 78 78 { 0x3a4001, 0x3a8001, 0, lcd_init, lcd_quit, lcd_exec, lcd_read, lcd_write }, 79 79 { 0x3a8001, 0x3ac001, 5, ser_init, ser_quit, ser_exec, ser_read, ser_write }, -
emu/tim.c
r7b50125 r05e6dbe 24 24 int32_t tim_verbose = 0; 25 25 26 #define REG_CRX 027 #define REG_CR2_SR 128 #define REG_T1H 229 #define REG_T1L 330 #define REG_T2H 431 #define REG_T2L 532 #define REG_T3H 633 #define REG_T3L 734 35 #define COUNT_1 3236 #define COUNT_2 320037 #define COUNT_3 80138 39 typedef struct {40 bool irq_e;41 bool irq;42 int32_t latch;43 int32_t count;44 } state_timer;45 46 static state_timer timers[] = {47 { .irq_e = false, .irq = false, .latch = COUNT_1, .count = COUNT_1 },48 { .irq_e = false, .irq = false, .latch = COUNT_2, .count = COUNT_2 },49 { .irq_e = false, .irq = false, .latch = COUNT_3, .count = COUNT_3 }50 };51 52 static bool wr_cr1 = false;53 static bool oper = false;54 55 26 void tim_init(void) 56 27 { … … 65 36 bool tim_exec(void) 66 37 { 67 if (oper) { 68 for (int32_t i = 0; i < ARRAY_COUNT(timers); ++i) { 69 --timers[i].count; 70 71 if (timers[i].count == 0) { 72 ver2("tim %d zero", i + 1); 73 timers[i].count = timers[i].latch; 74 75 if (timers[i].irq_e) { 76 ver2("tim %d irq", i + 1); 77 timers[i].irq = true; 78 } 79 } 80 } 81 } 82 83 return timers[0].irq || timers[1].irq || timers[2].irq; 38 ver3("tim exec"); 39 return false; 84 40 } 85 41 … … 87 43 { 88 44 ver2("tim rd %u:%d", off, sz * 8); 89 90 if (sz != 1 || off > 7) { 91 fail("invalid tim rd %u:%d", off, sz * 8); 92 } 93 94 uint32_t rv = 0x00; 95 96 switch (off) { 97 case REG_CR2_SR: 98 rv |= (uint32_t)timers[0].irq << 0; 99 rv |= (uint32_t)timers[1].irq << 1; 100 rv |= (uint32_t)timers[2].irq << 2; 101 102 ver2("tim irqs %u %u %u", 103 (uint32_t)timers[0].irq, (uint32_t)timers[1].irq, (uint32_t)timers[2].irq); 104 break; 105 106 case REG_T1L: 107 if (timers[0].irq) { 108 ver2("tim 1 !irq"); 109 timers[0].irq = false; 110 } 111 112 break; 113 114 case REG_T2L: 115 if (timers[1].irq) { 116 ver2("tim 2 !irq"); 117 timers[1].irq = false; 118 } 119 120 break; 121 122 case REG_T3L: 123 if (timers[2].irq) { 124 ver2("tim 3 !irq"); 125 timers[2].irq = false; 126 } 127 128 break; 129 130 default: 131 break; 132 } 133 134 return rv; 45 return 0; 135 46 } 136 47 … … 138 49 { 139 50 ver2("tim wr %u:%d 0x%0*x", off, sz * 8, sz * 2, val); 140 141 if (sz != 1 || off > 7) {142 fail("invalid tim wr %u:%d", off, sz * 8);143 }144 145 switch (off) {146 case REG_CRX:147 if (wr_cr1) {148 if ((val & 0x01) == 0) {149 ver2("tim start");150 oper = true;151 }152 153 timers[0].irq_e = (val & 0x40) != 0;154 }155 else {156 timers[2].irq_e = (val & 0x40) != 0;157 }158 159 break;160 161 case REG_CR2_SR:162 wr_cr1 = (val & 0x01) != 0;163 timers[1].irq_e = (val & 0x40) != 0;164 break;165 166 default:167 break;168 }169 51 }
Note:
See TracChangeset
for help on using the changeset viewer.