src/mess/machine/pokemini.c
| r2798 | r2799 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | Pokemini machine emulation. |
| 4 | |
| 5 | |
| 6 | **********************************************************************/ |
| 7 | |
| 8 | |
| 1 | 9 | #include "driver.h" |
| 2 | 10 | #include "includes/pokemini.h" |
| 3 | 11 | #include "cpu/minx/minx.h" |
| r2798 | r2799 | |
| 3 | 11 | |
| 4 | 12 | |
| 5 | | struct VDP { |
| 6 | | UINT8 colors_inverted; |
| 7 | | UINT8 background_enabled; |
| 8 | | UINT8 sprites_enabled; |
| 9 | | UINT8 rendering_enabled; |
| 10 | | UINT8 map_size; |
| 11 | | UINT8 map_size_x; |
| 12 | | UINT32 bg_tiles; |
| 13 | | UINT32 spr_tiles; |
| 13 | struct PRC |
| 14 | { |
| 15 | UINT8 colors_inverted; |
| 16 | UINT8 background_enabled; |
| 17 | UINT8 sprites_enabled; |
| 18 | UINT8 copy_enabled; |
| 19 | UINT8 map_size; |
| 20 | UINT8 map_size_x; |
| 21 | UINT8 frame_count; |
| 22 | UINT8 max_frame_count; |
| 23 | UINT32 bg_tiles; |
| 24 | UINT32 spr_tiles; |
| 25 | UINT8 count; |
| 26 | emu_timer *count_timer; |
| 14 | 27 | }; |
| 15 | 28 | |
| 16 | | struct TIMERS { |
| 17 | | UINT8 seconds_running; /* Seconds timer running */ |
| 18 | | UINT32 seconds_counter; /* Seconds timer counter */ |
| 29 | |
| 30 | struct TIMERS |
| 31 | { |
| 19 | 32 | emu_timer *seconds_timer; |
| 20 | | UINT8 hz256_running; /* 256Hz timer running */ |
| 21 | | UINT8 hz256_counter; /* 256Hz timer counter */ |
| 22 | 33 | emu_timer *hz256_timer; |
| 23 | | UINT8 timers_enabled; /* Timers 1 to 3 enabled */ |
| 24 | | UINT16 timer1_counter; |
| 25 | | emu_timer *timer1_timer; /* Timer 1 */ |
| 26 | | UINT16 timer2_counter; |
| 27 | | emu_timer *timer2_timer; /* Timer 2 */ |
| 28 | | UINT16 timer3_counter; |
| 29 | | emu_timer *timer3_timer; /* Timer 3 */ |
| 34 | emu_timer *timer1; /* Timer 1 low or 16bit */ |
| 35 | emu_timer *timer1_hi; /* Timer 1 hi */ |
| 36 | emu_timer *timer2; /* Timer 2 low or 16bit */ |
| 37 | emu_timer *timer2_hi; /* Timer 2 high */ |
| 38 | emu_timer *timer3; /* Timer 3 low or 16bit */ |
| 39 | emu_timer *timer3_hi; /* Timer 3 high */ |
| 30 | 40 | }; |
| 31 | 41 | |
| 42 | |
| 32 | 43 | UINT8 *pokemini_ram; |
| 33 | | |
| 34 | | static UINT8 pokemini_hwreg[0x100]; |
| 35 | | static struct VDP vdp; |
| 44 | static UINT8 pm_reg[0x100]; |
| 45 | static struct PRC prc; |
| 36 | 46 | static struct TIMERS timers; |
| 37 | 47 | |
| 48 | |
| 49 | static void pokemini_check_irqs( running_machine *machine ) |
| 50 | { |
| 51 | int irq_set[4] = { 1, 0, 0, 0 }; |
| 52 | int prio, vector; |
| 53 | |
| 54 | /* Check IRQ $03-$04 */ |
| 55 | prio = ( pm_reg[0x20] >> 6 ) & 0x03; |
| 56 | if ( ! irq_set[prio] ) |
| 57 | { |
| 58 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x40 ) |
| 59 | irq_set[prio] = 0x04; |
| 60 | |
| 61 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x80 ) |
| 62 | irq_set[prio] = 0x03; |
| 63 | } |
| 64 | |
| 65 | /* Check IRQ $05-$06 */ |
| 66 | prio = ( pm_reg[0x20] >> 4 ) & 0x03; |
| 67 | if ( ! irq_set[prio] ) |
| 68 | { |
| 69 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x10 ) |
| 70 | irq_set[prio] = 0x06; |
| 71 | |
| 72 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x20 ) |
| 73 | irq_set[prio] = 0x05; |
| 74 | } |
| 75 | |
| 76 | /* Check IRQ $07-$08 */ |
| 77 | prio = ( pm_reg[0x20] >> 2 ) & 0x03; |
| 78 | if ( ! irq_set[prio] ) |
| 79 | { |
| 80 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x04 ) |
| 81 | irq_set[prio] = 0x08; |
| 82 | |
| 83 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x08 ) |
| 84 | irq_set[prio] = 0x07; |
| 85 | } |
| 86 | |
| 87 | /* Check IRQ $09-$0A */ |
| 88 | prio = ( pm_reg[0x20] >> 0 ) & 0x03; |
| 89 | if ( ! irq_set[prio] ) |
| 90 | { |
| 91 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x01 ) |
| 92 | irq_set[prio] = 0x0A; |
| 93 | |
| 94 | if ( pm_reg[0x23] & pm_reg[0x27] & 0x02 ) |
| 95 | irq_set[prio] = 0x09; |
| 96 | } |
| 97 | |
| 98 | /* Check IRQ $0B-$0E */ |
| 99 | prio = ( pm_reg[0x21] >> 6 ) & 0x03; |
| 100 | if ( ! irq_set[prio] ) |
| 101 | { |
| 102 | if ( pm_reg[0x24] & pm_reg[0x28] & 0x04 ) |
| 103 | irq_set[prio] = 0x0E; |
| 104 | |
| 105 | if ( pm_reg[0x24] & pm_reg[0x28] & 0x08 ) |
| 106 | irq_set[prio] = 0x0D; |
| 107 | |
| 108 | if ( pm_reg[0x24] & pm_reg[0x28] & 0x10 ) |
| 109 | irq_set[prio] = 0x0C; |
| 110 | |
| 111 | if ( pm_reg[0x24] & pm_reg[0x28] & 0x20 ) |
| 112 | irq_set[prio] = 0x0B; |
| 113 | } |
| 114 | |
| 115 | /* Check IRQ $0F-$10 */ |
| 116 | prio = ( pm_reg[0x22] >> 0 ) & 0x03; |
| 117 | if ( ! irq_set[prio] ) |
| 118 | { |
| 119 | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x40 ) |
| 120 | irq_set[prio] = 0x10; |
| 121 | |
| 122 | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x80 ) |
| 123 | irq_set[prio] = 0x0F; |
| 124 | } |
| 125 | |
| 126 | /* Check IRQ $13-$14 */ |
| 127 | prio = ( pm_reg[0x21] >> 4 ) & 0x03; |
| 128 | if ( ! irq_set[prio] ) |
| 129 | { |
| 130 | if ( pm_reg[0x24] & pm_reg[0x28] & 0x01 ) |
| 131 | irq_set[prio] = 0x14; |
| 132 | |
| 133 | if ( pm_reg[0x24] & pm_reg[0x28] & 0x02 ) |
| 134 | irq_set[prio] = 0x13; |
| 135 | } |
| 136 | |
| 137 | /* Check IRQ $15-$1C */ |
| 138 | prio = ( pm_reg[0x21] >> 2 ) & 0x03; |
| 139 | if ( ! irq_set[prio] ) |
| 140 | { |
| 141 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x01 ) |
| 142 | irq_set[prio] = 0x1C; |
| 143 | |
| 144 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x02 ) |
| 145 | irq_set[prio] = 0x1B; |
| 146 | |
| 147 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x04 ) |
| 148 | irq_set[prio] = 0x1A; |
| 149 | |
| 150 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x08 ) |
| 151 | irq_set[prio] = 0x19; |
| 152 | |
| 153 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x10 ) |
| 154 | irq_set[prio] = 0x18; |
| 155 | |
| 156 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x20 ) |
| 157 | irq_set[prio] = 0x17; |
| 158 | |
| 159 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x40 ) |
| 160 | irq_set[prio] = 0x16; |
| 161 | |
| 162 | if ( pm_reg[0x25] & pm_reg[0x29] & 0x80 ) |
| 163 | irq_set[prio] = 0x15; |
| 164 | } |
| 165 | |
| 166 | /* Check IRQ $1D-$1F */ |
| 167 | prio = ( pm_reg[0x21] >> 0 ) & 0x03; |
| 168 | if ( ! irq_set[prio] && ( pm_reg[0x26] & pm_reg[0x2A] & 0x07 ) ) |
| 169 | { |
| 170 | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x01 ) |
| 171 | irq_set[prio] = 0x1F; |
| 172 | |
| 173 | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x02 ) |
| 174 | irq_set[prio] = 0x1E; |
| 175 | |
| 176 | if ( pm_reg[0x26] & pm_reg[0x2A] & 0x04 ) |
| 177 | irq_set[prio] = 0x1D; |
| 178 | } |
| 179 | |
| 180 | /* Determine vector */ |
| 181 | vector = 0; |
| 182 | if ( irq_set[1] ) |
| 183 | vector = irq_set[1]; |
| 184 | if ( irq_set[2] ) |
| 185 | vector = irq_set[2]; |
| 186 | if ( irq_set[3] ) |
| 187 | vector = irq_set[3]; |
| 188 | |
| 189 | if ( vector ) |
| 190 | { |
| 191 | logerror("Triggering IRQ with vector %02x\n", vector ); |
| 192 | /* Trigger interrupt and set vector */ |
| 193 | cpunum_set_input_line_and_vector( machine, 0, 0, ASSERT_LINE, vector ); |
| 194 | } |
| 195 | else |
| 196 | { |
| 197 | cpunum_set_input_line( machine, 0, 0, CLEAR_LINE ); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | |
| 38 | 202 | static TIMER_CALLBACK(pokemini_seconds_timer_callback) |
| 39 | 203 | { |
| 40 | | if ( timers.seconds_running ) { |
| 41 | | timers.seconds_counter += 1; |
| 204 | if ( pm_reg[0x08] & 0x01 ) |
| 205 | { |
| 206 | pm_reg[0x09] += 1; |
| 207 | if ( ! pm_reg[0x09] ) |
| 208 | { |
| 209 | pm_reg[0x0A] += 1; |
| 210 | if ( ! pm_reg[0x0A] ) |
| 211 | { |
| 212 | pm_reg[0x0B] += 1; |
| 213 | } |
| 214 | } |
| 42 | 215 | } |
| 43 | 216 | } |
| 44 | 217 | |
| 218 | |
| 45 | 219 | static TIMER_CALLBACK(pokemini_256hz_timer_callback) |
| 46 | 220 | { |
| 47 | | if ( timers.hz256_running ) { |
| 48 | | timers.hz256_counter += 1; |
| 221 | if ( pm_reg[0x40] & 0x01 ) |
| 222 | { |
| 223 | pm_reg[0x41] += 1; |
| 224 | /* Check if the 32Hz IRQ should be triggered */ |
| 225 | if ( ! ( pm_reg[0x41] & 0x07 ) ) |
| 226 | { |
| 227 | pm_reg[0x28] |= 0x20; |
| 228 | |
| 229 | /* Check if the 8Hz IRQ should be triggered */ |
| 230 | if ( ! ( pm_reg[0x41] & 0x1F ) ) |
| 231 | { |
| 232 | pm_reg[0x28] |= 0x10; |
| 233 | |
| 234 | /* Check if the 2Hz IRQ should be triggered */ |
| 235 | if ( ! ( pm_reg[0x41] & 0x7F ) ) |
| 236 | { |
| 237 | pm_reg[0x28] |= 0x08; |
| 238 | |
| 239 | /* Check if the 1Hz IRQ should be triggered */ |
| 240 | if ( ! pm_reg[0x41] ) |
| 241 | { |
| 242 | pm_reg[0x28] |= 0x04; |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | pokemini_check_irqs( machine ); |
| 248 | } |
| 49 | 249 | } |
| 50 | 250 | } |
| 51 | 251 | |
| 252 | |
| 52 | 253 | static TIMER_CALLBACK(pokemini_timer1_callback) |
| 53 | 254 | { |
| 54 | | timers.timer1_counter -= 1; |
| 255 | pm_reg[0x36] -= 1; |
| 55 | 256 | /* Check for underflow of timer */ |
| 56 | | if ( timers.timer1_counter == 0xFFFF ) { |
| 57 | | /* TODO: Check for interrupt condition/generation */ |
| 58 | | timers.timer1_counter = ( pokemini_hwreg[0x33] << 8 ) | pokemini_hwreg[0x32]; |
| 257 | if ( pm_reg[0x36] == 0xFF ) |
| 258 | { |
| 259 | /* Check if timer1 is running in 16bit mode */ |
| 260 | if ( pm_reg[0x30] & 0x80 ) |
| 261 | { |
| 262 | pm_reg[0x37] -= 1; |
| 263 | if ( pm_reg[0x37] == 0xFF ) |
| 264 | { |
| 265 | pm_reg[0x27] |= 0x08; |
| 266 | pokemini_check_irqs( machine ); |
| 267 | pm_reg[0x36] = pm_reg[0x32]; |
| 268 | pm_reg[0x37] = pm_reg[0x33]; |
| 269 | } |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | pm_reg[0x27] |= 0x04; |
| 274 | pokemini_check_irqs( machine ); |
| 275 | pm_reg[0x36] = pm_reg[0x32]; |
| 276 | } |
| 59 | 277 | } |
| 60 | | pokemini_hwreg[0x37] = timers.timer1_counter >> 8; |
| 61 | | if ( pokemini_hwreg[0x30] & 0x80 ) { |
| 62 | | pokemini_hwreg[0x36] = timers.timer1_counter & 0xFF; |
| 278 | } |
| 279 | |
| 280 | |
| 281 | static TIMER_CALLBACK(pokemini_timer1_hi_callback) |
| 282 | { |
| 283 | pm_reg[0x37] -= 1; |
| 284 | /* Check for underflow of timer */ |
| 285 | if ( pm_reg[0x37] == 0xFF ) |
| 286 | { |
| 287 | pm_reg[0x27] |= 0x08; |
| 288 | pokemini_check_irqs( machine ); |
| 289 | pm_reg[0x37] = pm_reg[0x33]; |
| 63 | 290 | } |
| 64 | 291 | } |
| 65 | 292 | |
| 293 | |
| 66 | 294 | static TIMER_CALLBACK(pokemini_timer2_callback) |
| 67 | 295 | { |
| 68 | | timers.timer2_counter -= 1; |
| 296 | pm_reg[0x3E] -= 1; |
| 69 | 297 | /* Check for underflow of timer */ |
| 70 | | if ( timers.timer2_counter == 0xFFFF ) { |
| 71 | | /* TODO: Check for interrupt condition/generation */ |
| 72 | | timers.timer2_counter = ( pokemini_hwreg[0x3b] << 8 ) | pokemini_hwreg[0x3a]; |
| 298 | if ( pm_reg[0x3E] == 0xFF ) |
| 299 | { |
| 300 | /* Check if timer2 is running in 16bit mode */ |
| 301 | if ( pm_reg[0x38] & 0x80 ) |
| 302 | { |
| 303 | pm_reg[0x3F] -= 1; |
| 304 | if ( pm_reg[0x3F] == 0xFF ) |
| 305 | { |
| 306 | pm_reg[0x27] |= 0x20; |
| 307 | pokemini_check_irqs( machine ); |
| 308 | pm_reg[0x3E] = pm_reg[0x3A]; |
| 309 | pm_reg[0x3F] = pm_reg[0x3B]; |
| 310 | } |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | pm_reg[0x27] |= 0x10; |
| 315 | pokemini_check_irqs( machine ); |
| 316 | pm_reg[0x3E] = pm_reg[0x3A]; |
| 317 | } |
| 73 | 318 | } |
| 74 | | pokemini_hwreg[0x3f] = timers.timer2_counter >> 8; |
| 75 | | if ( pokemini_hwreg[0x38] & 0x80 ) { |
| 76 | | pokemini_hwreg[0x3e] = timers.timer2_counter & 0xFF; |
| 319 | } |
| 320 | |
| 321 | |
| 322 | static TIMER_CALLBACK(pokemini_timer2_hi_callback) |
| 323 | { |
| 324 | pm_reg[0x3F] -= 1; |
| 325 | /* Check for underfow of timer */ |
| 326 | if ( pm_reg[0x3F] == 0xFF ) |
| 327 | { |
| 328 | pm_reg[0x27] |= 0x20; |
| 329 | pokemini_check_irqs( machine ); |
| 330 | pm_reg[0x3F] = pm_reg[0x3B]; |
| 77 | 331 | } |
| 78 | 332 | } |
| 79 | 333 | |
| 334 | |
| 80 | 335 | static TIMER_CALLBACK(pokemini_timer3_callback) |
| 81 | 336 | { |
| 82 | | timers.timer3_counter -= 1; |
| 337 | pm_reg[0x4E] -= 1; |
| 83 | 338 | /* Check for underflow of timer */ |
| 84 | | if ( timers.timer3_counter == 0xFFFF ) { |
| 85 | | /* TODO: Check for interrupt condition/generation */ |
| 86 | | timers.timer3_counter = ( pokemini_hwreg[0x4b] << 8 ) | pokemini_hwreg[0x4a]; |
| 339 | if ( pm_reg[0x4E] == 0xFF ) |
| 340 | { |
| 341 | /* Check if timer3 is running in 16bit mode */ |
| 342 | if ( pm_reg[0x48] & 0x80 ) |
| 343 | { |
| 344 | pm_reg[0x4F] -= 1; |
| 345 | if ( pm_reg[0x4F] == 0xFF ) |
| 346 | { |
| 347 | pm_reg[0x27] |= 0x02; |
| 348 | pokemini_check_irqs( machine ); |
| 349 | pm_reg[0x4E] = pm_reg[0x4A]; |
| 350 | pm_reg[0x4F] = pm_reg[0x4B]; |
| 351 | } |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | pm_reg[0x4E] = pm_reg[0x4A]; |
| 356 | } |
| 87 | 357 | } |
| 88 | | pokemini_hwreg[0x4f] = timers.timer3_counter >> 8; |
| 89 | | if ( pokemini_hwreg[0x4e] & 0x80 ) { |
| 90 | | pokemini_hwreg[0x4e] = timers.timer3_counter & 0xFF; |
| 91 | | } |
| 92 | 358 | } |
| 93 | 359 | |
| 94 | | MACHINE_RESET( pokemini ) { |
| 95 | | memset( &vdp, 0, sizeof(vdp) ); |
| 96 | | memset( &timers, 0, sizeof(timers) ); |
| 97 | | memset( pokemini_hwreg, 0, sizeof(pokemini_hwreg) ); |
| 98 | | timers.seconds_timer = timer_alloc( pokemini_seconds_timer_callback , NULL); |
| 99 | | timers.hz256_timer = timer_alloc( pokemini_256hz_timer_callback , NULL); |
| 100 | | timers.timer1_timer = timer_alloc( pokemini_timer1_callback , NULL); |
| 101 | | timers.timer2_timer = timer_alloc( pokemini_timer2_callback , NULL); |
| 102 | | timers.timer3_timer = timer_alloc( pokemini_timer3_callback , NULL); |
| 360 | |
| 361 | static TIMER_CALLBACK(pokemini_timer3_hi_callback) |
| 362 | { |
| 363 | pm_reg[0x4F] -= 1; |
| 364 | /* Check for underflow of timer */ |
| 365 | if ( pm_reg[0x4F] == 0xFF ) |
| 366 | { |
| 367 | pm_reg[0x27] |= 0x02; |
| 368 | pokemini_check_irqs( machine ); |
| 369 | pm_reg[0x4F] = pm_reg[0x4B]; |
| 370 | } |
| 103 | 371 | } |
| 104 | 372 | |
| 105 | | WRITE8_HANDLER( pokemini_hwreg_w ) { |
| 106 | | static const int timer_to_cycles[8] = { 2, 8, 32, 64, 128, 256, 1024, 4096 }; |
| 373 | |
| 374 | WRITE8_HANDLER( pokemini_hwreg_w ) |
| 375 | { |
| 376 | static const int timer_to_cycles_fast[8] = { 2, 8, 32, 64, 128, 256, 1024, 4096 }; |
| 377 | static const int timer_to_cycles_slow[8] = { 128, 256, 512, 1024, 2048, 4096, 8192, 16384 }; |
| 378 | |
| 107 | 379 | logerror( "%0X: Write to hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 108 | | switch( offset ) { |
| 380 | |
| 381 | switch( offset ) |
| 382 | { |
| 109 | 383 | case 0x00: /* start-up contrast |
| 110 | 384 | Bit 0-1 R/W Must be 1(?) |
| r2798 | r2799 | |
| 124 | 398 | Bit 1 W Timer reset |
| 125 | 399 | Bit 2-7 Unused |
| 126 | 400 | */ |
| 127 | | if ( data & 0x01 ) { /* enable timer */ |
| 128 | | if ( ! timers.seconds_running ) { |
| 129 | | timer_adjust_oneshot(timers.seconds_timer, ATTOTIME_IN_SEC(1), 0); |
| 130 | | timers.seconds_running = 1; |
| 131 | | } |
| 132 | | } else { /* pause timer */ |
| 133 | | if ( timers.seconds_running ) { |
| 134 | | timer_reset( timers.seconds_timer, attotime_never ); |
| 135 | | timers.seconds_running = 0; |
| 136 | | } |
| 137 | | } |
| 138 | | if ( data & 0x02 ) { |
| 139 | | timers.seconds_counter = 0; |
| 401 | if ( data & 0x02 ) |
| 402 | { |
| 403 | pm_reg[0x09] = 0x00; |
| 404 | pm_reg[0x0A] = 0x00; |
| 405 | pm_reg[0x0B] = 0x00; |
| 140 | 406 | data &= ~0x02; |
| 141 | 407 | } |
| 142 | 408 | break; |
| 143 | | case 0x09: /* Seconds-timer (low) |
| 409 | case 0x09: /* Seconds-timer (low), read only |
| 144 | 410 | Bit 0-7 R Seconds timer bit 0-7 |
| 145 | 411 | */ |
| 146 | | case 0x0A: /* Seconds-timer (mid) |
| 412 | return; |
| 413 | case 0x0A: /* Seconds-timer (mid), read only |
| 147 | 414 | Bit 0-7 R Seconds timer bit 8-15 |
| 148 | 415 | */ |
| 149 | | case 0x0B: /* Seconds-timer (high) |
| 416 | return; |
| 417 | case 0x0B: /* Seconds-timer (high), read only |
| 150 | 418 | Bit 0-7 R Seconds timer bit 16-23 |
| 151 | 419 | */ |
| 152 | | /* ignore writes to these registers */ |
| 153 | | logerror( "%0X: Invalid write to seconds counter\n", activecpu_get_pc() ); |
| 154 | 420 | return; |
| 155 | 421 | case 0x10: /* Low power detector |
| 156 | 422 | Bit 0-4 R/W Unknown |
| r2798 | r2799 | |
| 160 | 426 | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 161 | 427 | break; |
| 162 | 428 | case 0x18: /* Timer 1 pre-scale + enable |
| 163 | | Bit 0-2 R/W 000 - 2000000 Hz - 2 cycles |
| 164 | | 001 - 500000 Hz - 8 cycles |
| 165 | | 010 - 125000 Hz - 32 cycles |
| 166 | | 011 - 62500 Hz - 64 cycles |
| 167 | | 100 - 31250 Hz - 128 cycles |
| 168 | | 101 - 15625 Hz - 256 cycles |
| 169 | | 110 - 3906.25 Hz - 1024 cycles |
| 170 | | 111 - 976.5625 Hz - 4096 cycles |
| 171 | | Bit 3 R/W Enable counting |
| 172 | | Bit 4-7 R/W Unused |
| 429 | Bit 0-2 R/W low timer 1 prescaler select |
| 430 | 000 - 2 or 128 cycles |
| 431 | 001 - 8 or 256 cycles |
| 432 | 010 - 32 or 512 cycles |
| 433 | 011 - 64 or 1024 cycles |
| 434 | 100 - 128 or 2048 cycles |
| 435 | 101 - 256 or 4096 cycles |
| 436 | 110 - 1024 or 8192 cycles |
| 437 | 111 - 4096 or 16384 cycles |
| 438 | Bit 3 R/W Enable low counting |
| 439 | Bit 4-6 R/W high timer 1 prescaler select |
| 440 | Bit 7 R/W Enable high counting |
| 173 | 441 | */ |
| 174 | | if ( ( data & 0x07 ) != ( pokemini_hwreg[0x18] & 0x07 ) ) { |
| 175 | | timer_adjust_periodic(timers.timer1_timer, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ), 0, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 )); |
| 442 | /* Check for prescaler change for the low counter */ |
| 443 | if ( ( data & 0x07 ) != ( pm_reg[0x18] & 0x07 ) ) |
| 444 | { |
| 445 | int index = data & 0x07; |
| 446 | int cycles = ( pm_reg[0x19] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 447 | |
| 448 | timer_adjust_periodic(timers.timer1, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 176 | 449 | } |
| 177 | | if ( ( data & 0x08 ) && timers.timers_enabled ) { |
| 178 | | timer_enable( timers.timer1_timer, 1 ); |
| 179 | | } else { |
| 180 | | timer_enable( timers.timer1_timer, 0 ); |
| 450 | |
| 451 | /* Check for prescaler change for the high counter */ |
| 452 | if ( ( data & 0x70 ) != ( pm_reg[0x18] & 0x70 ) ) |
| 453 | { |
| 454 | int index = ( data >> 4 ) & 0x07; |
| 455 | int cycles = ( pm_reg[0x19] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 456 | |
| 457 | timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 181 | 458 | } |
| 459 | |
| 460 | /* Check if timer1 low should be enabled */ |
| 461 | if ( ( data & 0x08 ) && ( pm_reg[0x30] & 0x04 ) && |
| 462 | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) || |
| 463 | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) ) ) |
| 464 | { |
| 465 | timer_enable( timers.timer1, 1 ); |
| 466 | } |
| 467 | else |
| 468 | { |
| 469 | timer_enable( timers.timer1, 0 ); |
| 470 | } |
| 471 | |
| 472 | /* Check if timer1 high should be enabled */ |
| 473 | if ( ( data & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && |
| 474 | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) || |
| 475 | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) ) ) |
| 476 | { |
| 477 | timer_enable( timers.timer1_hi, 1 ); |
| 478 | } |
| 479 | else |
| 480 | { |
| 481 | timer_enable( timers.timer1_hi, 0 ); |
| 482 | } |
| 182 | 483 | break; |
| 183 | | case 0x19: /* Timers 1 to 3 enabler |
| 184 | | Bit 0 R/W SET IT TO "0" |
| 185 | | Bit 1-3 Unused |
| 186 | | Bit 4 R/W SET IT TO "0" |
| 187 | | Bit 5 R/W Enable timers 1 to 3 circuits |
| 484 | case 0x19: /* Timers 1 speed |
| 485 | Bit 0 R/W Select slow timer for timer 1 lo |
| 486 | Bit 1 R/W Select slow timer for timer 1 hi |
| 487 | Bit 2-3 Unused |
| 488 | Bit 4 R/W Enable slow timers |
| 489 | Bit 5 R/W Enable fast timers |
| 188 | 490 | Bit 6-7 Unused |
| 189 | 491 | */ |
| 190 | | timers.timers_enabled = ( data & 0x20 ) ? 1 : 0; |
| 191 | | if ( timers.timers_enabled ) { |
| 192 | | if ( pokemini_hwreg[0x18] & 0x08 ) { |
| 193 | | timer_enable( timers.timer1_timer, 1 ); |
| 492 | /* Check for prescaler change for the high counter */ |
| 493 | if ( ( data & 0x01 ) != ( pm_reg[0x19] & 0x01 ) ) |
| 494 | { |
| 495 | int index = pm_reg[0x18] & 0x07; |
| 496 | int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 497 | |
| 498 | timer_adjust_periodic(timers.timer1, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 499 | } |
| 500 | |
| 501 | /* Check for prescaler change for the low counter */ |
| 502 | if ( ( data & 0x02 ) != ( pm_reg[0x19] & 0x02 ) ) |
| 503 | { |
| 504 | int index = ( pm_reg[0x18] >> 4 ) & 0x07; |
| 505 | int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 506 | |
| 507 | timer_adjust_periodic(timers.timer1_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 508 | } |
| 509 | |
| 510 | { |
| 511 | int timer1_enable = 0, timer1_hi_enable = 0; |
| 512 | int timer2_enable = 0, timer2_hi_enable = 0; |
| 513 | int timer3_enable = 0, timer3_hi_enable = 0; |
| 514 | |
| 515 | /* Check which fast timers should be enabled */ |
| 516 | if ( data & 0x20 ) |
| 517 | { |
| 518 | if ( ( pm_reg[0x18] & 0x08 ) && ( pm_reg[0x30] & 0x04 ) && ! ( data & 0x01 ) ) |
| 519 | timer1_enable = 1; |
| 520 | |
| 521 | if ( ( pm_reg[0x18] & 0x80 ) && ( pm_reg[0x31] & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ! ( data & 0x02 ) ) |
| 522 | timer1_hi_enable = 1; |
| 523 | |
| 524 | if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && ! ( pm_reg[0x1B] & 0x01 ) ) |
| 525 | timer2_enable = 1; |
| 526 | |
| 527 | if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ! ( pm_reg[0x1B] & 0x02 ) ) |
| 528 | timer2_hi_enable = 1; |
| 529 | |
| 530 | if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && ! ( pm_reg[0x1D] & 0x01 ) ) |
| 531 | timer3_enable = 1; |
| 532 | |
| 533 | if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ! ( pm_reg[0x1D] & 0x02 ) ) |
| 534 | timer3_hi_enable = 1; |
| 194 | 535 | } |
| 195 | | if ( pokemini_hwreg[0x1A] & 0x08 ) { |
| 196 | | timer_enable( timers.timer2_timer, 1 ); |
| 536 | |
| 537 | /* Check which slow timers should be enabled */ |
| 538 | if ( data & 0x10 ) |
| 539 | { |
| 540 | if ( ( pm_reg[0x18] & 0x08 ) && ( data & 0x01 ) ) |
| 541 | timer1_enable = 1; |
| 542 | |
| 543 | if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x1B] & 0x01 ) ) |
| 544 | timer2_enable = 1; |
| 545 | |
| 546 | if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x1D] & 0x01 ) ) |
| 547 | timer3_enable = 1; |
| 197 | 548 | } |
| 198 | | if ( pokemini_hwreg[0x1C] & 0x08 ) { |
| 199 | | timer_enable( timers.timer3_timer, 1 ); |
| 200 | | } |
| 201 | | } else { |
| 202 | | timer_enable( timers.timer1_timer, 0 ); |
| 203 | | timer_enable( timers.timer2_timer, 0 ); |
| 204 | | timer_enable( timers.timer3_timer, 0 ); |
| 549 | timer_enable( timers.timer1, timer1_enable ); |
| 550 | timer_enable( timers.timer1_hi, timer1_hi_enable ); |
| 551 | timer_enable( timers.timer2, timer2_enable ); |
| 552 | timer_enable( timers.timer2_hi, timer2_hi_enable ); |
| 553 | timer_enable( timers.timer3, timer3_enable ); |
| 554 | timer_enable( timers.timer3_hi, timer3_hi_enable ); |
| 205 | 555 | } |
| 206 | 556 | break; |
| 207 | 557 | case 0x1A: /* Timer 2 pre-scale + enable |
| 208 | | Bit 0-2 R/W 000 - 2000000 Hz - 2 cycles |
| 209 | | 001 - 500000 Hz - 8 cycles |
| 210 | | 010 - 125000 Hz - 32 cycles |
| 211 | | 011 - 62500 Hz - 64 cycles |
| 212 | | 100 - 31250 Hz - 128 cycles |
| 213 | | 101 - 15625 Hz - 256 cycles |
| 214 | | 110 - 3906.25 Hz - 1024 cycles |
| 215 | | 111 - 976.5625 Hz - 4096 cycles |
| 216 | | Bit 3 R/W Enable counting |
| 217 | | Bit 4-7 Unused |
| 558 | Bit 0-2 R/W low timer 2 prescaler select |
| 559 | 000 - 2 or 128 cycles |
| 560 | 001 - 8 or 256 cycles |
| 561 | 010 - 32 or 512 cycles |
| 562 | 011 - 64 or 1024 cycles |
| 563 | 100 - 128 or 2048 cycles |
| 564 | 101 - 256 or 4096 cycles |
| 565 | 110 - 1024 or 8192 cycles |
| 566 | 111 - 4096 or 16384 cycles |
| 567 | Bit 3 R/W Enable low counting |
| 568 | Bit 4-6 R/W high timer 2 prescaler select |
| 569 | Bit 7 R/W Enable high counting |
| 218 | 570 | */ |
| 219 | | if ( ( data & 0x07 ) != ( pokemini_hwreg[0x1A] & 0x07 ) ) { |
| 220 | | timer_adjust_periodic(timers.timer2_timer, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ), 0, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 )); |
| 571 | /* Check for prescaler change for the low counter */ |
| 572 | if ( ( data & 0x07 ) != ( pm_reg[0x1A] & 0x07 ) ) |
| 573 | { |
| 574 | int index = data & 0x07; |
| 575 | int cycles = ( pm_reg[0x1B] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 576 | |
| 577 | timer_adjust_periodic(timers.timer2, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 221 | 578 | } |
| 222 | | if ( ( data & 0x08 ) && timers.timers_enabled ) { |
| 223 | | timer_enable( timers.timer2_timer, 1 ); |
| 224 | | } else { |
| 225 | | timer_enable( timers.timer2_timer, 0 ); |
| 579 | |
| 580 | /* Check for prescaler change for the high counter */ |
| 581 | if ( ( data & 0x70 ) != ( pm_reg[0x1A] & 0x70 ) ) |
| 582 | { |
| 583 | int index = ( data >> 4 ) & 0x07; |
| 584 | int cycles = ( pm_reg[0x1B] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 585 | |
| 586 | timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 226 | 587 | } |
| 588 | |
| 589 | /* Check if timer2 low should be enabled */ |
| 590 | if ( ( data & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && |
| 591 | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x01 ) ) || |
| 592 | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x01 ) ) ) ) |
| 593 | { |
| 594 | timer_enable( timers.timer2, 1 ); |
| 595 | } |
| 596 | else |
| 597 | { |
| 598 | timer_enable( timers.timer2, 0 ); |
| 599 | } |
| 600 | |
| 601 | /* Check if timer2 high should be enabled */ |
| 602 | if ( ( data & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && |
| 603 | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) || |
| 604 | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) ) ) |
| 605 | { |
| 606 | timer_enable( timers.timer2_hi, 1 ); |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | timer_enable( timers.timer2_hi, 0 ); |
| 611 | } |
| 227 | 612 | break; |
| 613 | case 0x1B: /* Timer 2 speeds |
| 614 | Bit 0 R/W Select slow timer for timer 2 lo |
| 615 | Bit 1 R/W Select slow timer for timer 2 hi |
| 616 | */ |
| 617 | /* Check for prescaler change for the high counter */ |
| 618 | if ( ( data & 0x01 ) != ( pm_reg[0x1B] & 0x01 ) ) |
| 619 | { |
| 620 | int index = pm_reg[0x1A] & 0x07; |
| 621 | int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 622 | |
| 623 | timer_adjust_periodic(timers.timer2, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 624 | |
| 625 | if ( ( pm_reg[0x1A] & 0x08 ) && ( pm_reg[0x38] & 0x04 ) && |
| 626 | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) || |
| 627 | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) ) |
| 628 | { |
| 629 | timer_enable( timers.timer2, 1 ); |
| 630 | } |
| 631 | else |
| 632 | { |
| 633 | timer_enable( timers.timer2, 0 ); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /* Check for prescaler change for the low counter */ |
| 638 | if ( ( data & 0x02 ) != ( pm_reg[0x1B] & 0x02 ) ) |
| 639 | { |
| 640 | int index = ( pm_reg[0x1A] >> 4 ) & 0x07; |
| 641 | int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 642 | |
| 643 | timer_adjust_periodic(timers.timer2_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 644 | |
| 645 | if ( ( pm_reg[0x1A] & 0x80 ) && ( pm_reg[0x39] & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && |
| 646 | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) || |
| 647 | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) ) |
| 648 | { |
| 649 | timer_enable( timers.timer2_hi, 1 ); |
| 650 | } |
| 651 | else |
| 652 | { |
| 653 | timer_enable( timers.timer2_hi, 0 ); |
| 654 | } |
| 655 | } |
| 656 | break; |
| 228 | 657 | case 0x1C: /* Timer 3 pre-scale + enable |
| 229 | | Bit 0-2 R/W 000 - 2000000 Hz - 2 cycles |
| 230 | | 001 - 500000 Hz - 8 cycles |
| 231 | | 010 - 125000 Hz - 32 cycles |
| 232 | | 011 - 62500 Hz - 64 cycles |
| 233 | | 100 - 31250 Hz - 128 cycles |
| 234 | | 101 - 15625 Hz - 256 cycles |
| 235 | | 110 - 3906.25 Hz - 1024 cycles |
| 236 | | 111 - 976.5625 Hz - 4096 cycles |
| 237 | | Bit 3 R/W Enable counting |
| 238 | | Bit 4-7 Unused |
| 658 | Bit 0-2 R/W low timer 3 prescaler select |
| 659 | 000 - 2 or 128 cycles |
| 660 | 001 - 8 or 256 cycles |
| 661 | 010 - 32 or 512 cycles |
| 662 | 011 - 64 or 1024 cycles |
| 663 | 100 - 128 or 2048 cycles |
| 664 | 101 - 256 or 4096 cycles |
| 665 | 110 - 1024 or 8192 cycles |
| 666 | 111 - 4096 or 16384 cycles |
| 667 | Bit 3 R/W Enable low counting |
| 668 | Bit 4-6 R/W high timer 3 prescaler select |
| 669 | Bit 7 R/W Enable high counting |
| 239 | 670 | */ |
| 240 | | if ( ( data & 0x07 ) != ( pokemini_hwreg[0x1C] & 0x07 ) ) { |
| 241 | | timer_adjust_periodic(timers.timer3_timer, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 ), 0, ATTOTIME_IN_CYCLES( timer_to_cycles[data & 0x07], 0 )); |
| 671 | /* Check for prescaler change for the low counter */ |
| 672 | if ( ( data & 0x07 ) != ( pm_reg[0x1C] & 0x07 ) ) |
| 673 | { |
| 674 | int index = data & 0x07; |
| 675 | int cycles = ( pm_reg[0x1D] & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 676 | |
| 677 | timer_adjust_periodic(timers.timer3, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 242 | 678 | } |
| 243 | | if ( ( data & 0x08 ) && timers.timers_enabled ) { |
| 244 | | timer_enable( timers.timer3_timer, 1 ); |
| 245 | | } else { |
| 246 | | timer_enable( timers.timer3_timer, 0 ); |
| 679 | |
| 680 | /* Check for prescaler change for the high counter */ |
| 681 | if ( ( data & 0x70 ) != ( pm_reg[0x1C] & 0x70 ) ) |
| 682 | { |
| 683 | int index = ( data >> 4 ) & 0x07; |
| 684 | int cycles = ( pm_reg[0x1D] & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 685 | |
| 686 | timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 247 | 687 | } |
| 688 | |
| 689 | /* Check if timer2 low should be enabled */ |
| 690 | if ( ( data & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && |
| 691 | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) || |
| 692 | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) ) ) |
| 693 | { |
| 694 | timer_enable( timers.timer3, 1 ); |
| 695 | } |
| 696 | else |
| 697 | { |
| 698 | timer_enable( timers.timer3, 0 ); |
| 699 | } |
| 700 | |
| 701 | /* Check if timer2 high should be enabled */ |
| 702 | if ( ( data & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && |
| 703 | ( ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) || |
| 704 | ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) ) ) |
| 705 | { |
| 706 | timer_enable( timers.timer3_hi, 1 ); |
| 707 | } |
| 708 | else |
| 709 | { |
| 710 | timer_enable( timers.timer3_hi, 0 ); |
| 711 | } |
| 248 | 712 | break; |
| 249 | | case 0x20: /* Event #1-#8 primary enable |
| 713 | case 0x1D: /* Timer 3 speeds |
| 714 | Bit 0 R/W Select slow timer for timer 3 lo |
| 715 | Bit 1 R/W Select slow timer for timer 3 hi |
| 716 | */ |
| 717 | /* Check for prescaler change for the high counter */ |
| 718 | if ( ( data & 0x01 ) != ( pm_reg[0x1D] & 0x01 ) ) |
| 719 | { |
| 720 | int index = pm_reg[0x1C] & 0x07; |
| 721 | int cycles = ( data & 0x01 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 722 | |
| 723 | timer_adjust_periodic(timers.timer3, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 724 | |
| 725 | if ( ( pm_reg[0x1C] & 0x08 ) && ( pm_reg[0x48] & 0x04 ) && |
| 726 | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x01 ) ) || |
| 727 | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x01 ) ) ) ) |
| 728 | { |
| 729 | timer_enable( timers.timer3, 1 ); |
| 730 | } |
| 731 | else |
| 732 | { |
| 733 | timer_enable( timers.timer3, 0 ); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | /* Check for prescaler change for the low counter */ |
| 738 | if ( ( data & 0x02 ) != ( pm_reg[0x1D] & 0x02 ) ) |
| 739 | { |
| 740 | int index = ( pm_reg[0x1C] >> 4 ) & 0x07; |
| 741 | int cycles = ( data & 0x02 ) ? timer_to_cycles_slow[index] : timer_to_cycles_fast[index]; |
| 742 | |
| 743 | timer_adjust_periodic(timers.timer3_hi, attotime_zero, 0, ATTOTIME_IN_CYCLES( cycles, 0 )); |
| 744 | |
| 745 | if ( ( pm_reg[0x1C] & 0x80 ) && ( pm_reg[0x49] & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && |
| 746 | ( ( ( pm_reg[0x19] & 0x10 ) && ( data & 0x02 ) ) || |
| 747 | ( ( pm_reg[0x19] & 0x20 ) && ! ( data & 0x02 ) ) ) ) |
| 748 | { |
| 749 | timer_enable( timers.timer3_hi, 1 ); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | timer_enable( timers.timer3_hi, 0 ); |
| 754 | } |
| 755 | } |
| 756 | break; |
| 757 | case 0x20: /* Event #1-#8 priority |
| 250 | 758 | Bit 0-1 R/W Timer 3 overflow Interrupt #7-#8 |
| 251 | 759 | Bit 2-3 R/W Timer 1 overflow Interrupt #5-#6 |
| 252 | 760 | Bit 4-5 R/W Timer 2 overflow Interrupt #3-#4 |
| 253 | 761 | Bit 6-7 R/W VDraw/VBlank trigger Interrupt #1-#2 |
| 254 | 762 | */ |
| 763 | pm_reg[0x20] = data; |
| 764 | pokemini_check_irqs( machine ); |
| 255 | 765 | break; |
| 256 | | case 0x21: /* Event #15-#22 primary enable |
| 766 | case 0x21: /* Event #15-#22 priority |
| 257 | 767 | Bit 0-1 R/W Unknown |
| 258 | 768 | Bit 2-3 R/W All keypad interrupts - Interrupt #15-#22 |
| 259 | 769 | Bit 4-7 R/W Unknown |
| 260 | 770 | */ |
| 771 | pm_reg[0x21] = data; |
| 772 | pokemini_check_irqs( machine ); |
| 261 | 773 | break; |
| 262 | | case 0x22: /* Event #9-#14 primary enable |
| 774 | case 0x22: /* Event #9-#14 priority |
| 263 | 775 | Bit 0-1 R/W All #9 - #14 events - Interrupt #9-#14 |
| 264 | 776 | Bit 2-7 Unused |
| 265 | 777 | */ |
| 778 | pm_reg[0x22] = data; |
| 779 | pokemini_check_irqs( machine ); |
| 266 | 780 | break; |
| 267 | | case 0x23: /* Event #1-#8 secondary enable |
| 781 | case 0x23: /* Event #1-#8 enable |
| 268 | 782 | Bit 0 R/W Timer 3 overflow (mirror) - Enable Interrupt #8 |
| 269 | 783 | Bit 1 R/W Timer 3 overflow - Enable Interrupt #7 |
| 270 | 784 | Bit 2 R/W Not called... - Enable Interrupt #6 |
| r2798 | r2799 | |
| 274 | 788 | Bit 6 R/W V-Draw trigger - Enable Interrupt #2 |
| 275 | 789 | Bit 7 R/W V-Blank trigger - Enable Interrupt #1 |
| 276 | 790 | */ |
| 791 | pm_reg[0x23] = data; |
| 792 | pokemini_check_irqs( machine ); |
| 277 | 793 | break; |
| 278 | | case 0x24: /* Event #9-#12 secondary enable |
| 794 | case 0x24: /* Event #9-#12 enable |
| 279 | 795 | Bit 0-5 R/W Unknown |
| 280 | 796 | Bit 6-7 Unused |
| 281 | 797 | */ |
| 798 | pm_reg[0x24] = data; |
| 799 | pokemini_check_irqs( machine ); |
| 282 | 800 | break; |
| 283 | | case 0x25: /* Event #15-#22 secondary enable |
| 801 | case 0x25: /* Event #15-#22 enable |
| 284 | 802 | Bit 0 R/W Press key "A" event - Enable interrupt #22 |
| 285 | 803 | Bit 1 R/W Press key "B" event - Enable interrupt #21 |
| 286 | 804 | Bit 2 R/W Press key "C" event - Enable interrupt #20 |
| r2798 | r2799 | |
| 290 | 808 | Bit 6 R/W Press D-pad right key event - Enable interrupt #16 |
| 291 | 809 | Bit 7 R/W Press power button event - Enable interrupt #15 |
| 292 | 810 | */ |
| 811 | pm_reg[0x25] = data; |
| 812 | pokemini_check_irqs( machine ); |
| 293 | 813 | break; |
| 294 | | case 0x26: /* Event #13-#14 secondary enable |
| 814 | case 0x26: /* Event #13-#14 enable |
| 295 | 815 | Bit 0-2 R/W Unknown |
| 296 | 816 | Bit 3 Unused |
| 297 | 817 | Bit 4-5 R/W Unknown |
| 298 | 818 | Bit 6 R/W Shock detector trigger - Enable interrupt #14 |
| 299 | 819 | Bit 7 R/W IR receiver - low to high trigger - Enable interrupt #13 |
| 300 | 820 | */ |
| 821 | pm_reg[0x26] = data; |
| 822 | pokemini_check_irqs( machine ); |
| 301 | 823 | break; |
| 302 | | case 0x27: /* Interrupt flag #1-#8 |
| 824 | case 0x27: /* Interrupt active flag #1-#8 |
| 303 | 825 | Bit 0 Timer 3 overflow (mirror) / Clear interrupt #8 |
| 304 | 826 | Bit 1 Timer 3 overflow / Clear interrupt #7 |
| 305 | 827 | Bit 2 Not called ... / Clear interrupt #6 |
| r2798 | r2799 | |
| 309 | 831 | Bit 6 VDraw trigger / Clear interrupt #2 |
| 310 | 832 | Bit 7 VBlank trigger / Clear interrupt #1 |
| 311 | 833 | */ |
| 312 | | case 0x28: /* Interrupt flag #9-#12 |
| 834 | pm_reg[0x27] &= ~data; |
| 835 | pokemini_check_irqs( machine ); |
| 836 | return; |
| 837 | case 0x28: /* Interrupt active flag #9-#12 |
| 313 | 838 | Bit 0-1 Unknown |
| 314 | 839 | Bit 2 Unknown / Clear interrupt #12 |
| 315 | 840 | Bit 3 Unknown / Clear interrupt #11 |
| r2798 | r2799 | |
| 317 | 842 | Bit 5 Unknown / Clear interrupt #9 |
| 318 | 843 | Bit 6-7 Unknown |
| 319 | 844 | */ |
| 320 | | case 0x29: /* Interrupt flag #15-#22 |
| 845 | pm_reg[0x28] &= ~data; |
| 846 | pokemini_check_irqs( machine ); |
| 847 | return; |
| 848 | case 0x29: /* Interrupt active flag #15-#22 |
| 321 | 849 | Bit 0 Press key "A" event / Clear interrupt #22 |
| 322 | 850 | Bit 1 Press key "B" event / Clear interrupt #21 |
| 323 | 851 | Bit 2 Press key "C" event / Clear interrupt #20 |
| r2798 | r2799 | |
| 327 | 855 | Bit 6 Press D-pad right key event / Clear interrupt #16 |
| 328 | 856 | Bit 7 Press power button event / Clear interrupt #15 |
| 329 | 857 | */ |
| 330 | | case 0x2A: /* Interrupt flag #13-#14 |
| 858 | pm_reg[0x29] &= ~data; |
| 859 | pokemini_check_irqs( machine ); |
| 860 | return; |
| 861 | case 0x2A: /* Interrupt active flag #13-#14 |
| 331 | 862 | Bit 0-5 Unknown |
| 332 | 863 | Bit 6 Shock detector trigger / Clear interrupt #14 |
| 333 | 864 | Bit 7 Unknown / Clear interrupt #13 |
| 334 | 865 | */ |
| 335 | | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 336 | | break; |
| 866 | pm_reg[0x2A] &= ~data; |
| 867 | pokemini_check_irqs( machine ); |
| 868 | return; |
| 337 | 869 | case 0x30: /* Timer 1 control 1 |
| 338 | 870 | Bit 0 R/W Unknown |
| 339 | | Bit 1 Unused |
| 340 | | Bit 2 W Preset timer |
| 341 | | Bit 3-6 Unused |
| 342 | | Bit 7 R/W Enable timer 1 counting (this seems to unlock/lock register 0x36) |
| 871 | Bit 1 W Reset low counter |
| 872 | Bit 2 R/W Enable high counter |
| 873 | Bit 3 R/W Unknown |
| 874 | Bit 4-6 Unused |
| 875 | Bit 7 R/W Enable 16bit mode |
| 343 | 876 | */ |
| 344 | | if ( data & 0x04 ) { |
| 345 | | timers.timer1_counter = ( pokemini_hwreg[0x33] << 8 ) | pokemini_hwreg[0x32]; |
| 346 | | pokemini_hwreg[0x36] = pokemini_hwreg[0x32]; |
| 347 | | pokemini_hwreg[0x37] = pokemini_hwreg[0x33]; |
| 877 | if ( data & 0x02 ) |
| 878 | { |
| 879 | pm_reg[0x36] = pm_reg[0x32]; |
| 880 | data &= ~0x02; |
| 348 | 881 | } |
| 349 | | data &= ~0x04; |
| 882 | |
| 883 | if ( ( data & 0x04 ) && ( pm_reg[0x18] & 0x08 ) && |
| 884 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x01 ) ) || |
| 885 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x01 ) ) ) ) |
| 886 | { |
| 887 | timer_enable( timers.timer1, 1 ); |
| 888 | } |
| 889 | else |
| 890 | { |
| 891 | timer_enable( timers.timer1, 0 ); |
| 892 | } |
| 893 | |
| 894 | if ( ( pm_reg[0x31] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x18] & 0x80 ) && |
| 895 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) || |
| 896 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) ) |
| 897 | { |
| 898 | timer_enable( timers.timer1_hi, 1 ); |
| 899 | } |
| 900 | else |
| 901 | { |
| 902 | timer_enable( timers.timer1_hi, 0 ); |
| 903 | } |
| 350 | 904 | break; |
| 351 | 905 | case 0x31: /* Timer 1 control 2 |
| 352 | | Bit 0-2 Unused |
| 906 | Bit 0 R/W Unknown |
| 907 | Bit 1 W Reset hi counter |
| 908 | Bit 2 R/W Enable high counter |
| 353 | 909 | Bit 3 R/W Unknown |
| 354 | 910 | Bit 4-7 Unused |
| 355 | 911 | */ |
| 912 | if ( data & 0x02 ) |
| 913 | { |
| 914 | pm_reg[0x37] = pm_reg[0x33]; |
| 915 | data &= ~0x02; |
| 916 | } |
| 917 | |
| 918 | if ( ( data & 0x04 ) && ! ( pm_reg[0x30] & 0x80 ) && ( pm_reg[0x18] & 0x80 ) && |
| 919 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x19] & 0x02 ) ) || |
| 920 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x19] & 0x02 ) ) ) ) |
| 921 | { |
| 922 | timer_enable( timers.timer1_hi, 1 ); |
| 923 | } |
| 924 | else |
| 925 | { |
| 926 | timer_enable( timers.timer1_hi, 0 ); |
| 927 | } |
| 928 | break; |
| 356 | 929 | case 0x32: /* Timer 1 preset value (low) |
| 357 | 930 | Bit 0-7 R/W Timer 1 preset value bit 0-7 |
| 358 | 931 | */ |
| 932 | break; |
| 359 | 933 | case 0x33: /* Timer 1 preset value (high) |
| 360 | 934 | Bit 0-7 R/W Timer 1 preset value bit 8-15 |
| 361 | 935 | */ |
| 936 | break; |
| 362 | 937 | case 0x34: /* Timer 1 sound-pivot (low, unused) |
| 363 | 938 | */ |
| 364 | 939 | case 0x35: /* Timer 1 sound-pivot (high, unused) |
| 365 | 940 | */ |
| 366 | | case 0x36: /* Timer 1 counter (low) |
| 367 | | Bit 0-7 R/W Timer 1 counter value bit 0-7 |
| 941 | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 942 | break; |
| 943 | case 0x36: /* Timer 1 counter (low), read only |
| 368 | 944 | */ |
| 369 | | case 0x37: /* Timer 1 counter (high) |
| 370 | | Bit 0-7 R/W Timer 1 counter value bit 8-15 |
| 945 | return; |
| 946 | case 0x37: /* Timer 1 counter (high), read only |
| 371 | 947 | */ |
| 372 | | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 373 | | break; |
| 948 | return; |
| 374 | 949 | case 0x38: /* Timer 2 control 1 |
| 375 | 950 | Bit 0 R/W Unknown |
| 376 | | Bit 1 Unused |
| 377 | | Bit 2 W Preset Timer |
| 378 | | Bit 3-6 Unused |
| 379 | | Bit 7 R/W Enable timer 2 counting (this seems to unlock/lock register 0x3E) |
| 951 | Bit 1 W Reset low counter |
| 952 | Bit 2 R/W Enable high counter |
| 953 | Bit 3 R/W Unknown |
| 954 | Bit 4-6 Unused |
| 955 | Bit 7 R/W Enable 16bit mode |
| 380 | 956 | */ |
| 381 | | if ( data & 0x04 ) { |
| 382 | | timers.timer2_counter = ( pokemini_hwreg[0x3b] << 8 ) | pokemini_hwreg[0x3a]; |
| 383 | | pokemini_hwreg[0x3e] = pokemini_hwreg[0x3a]; |
| 384 | | pokemini_hwreg[0x3f] = pokemini_hwreg[0x3b]; |
| 385 | | data &= ~0x04; |
| 957 | if ( data & 0x02 ) |
| 958 | { |
| 959 | pm_reg[0x3E] = pm_reg[0x3A]; |
| 960 | data &= ~0x02; |
| 386 | 961 | } |
| 962 | |
| 963 | if ( ( data & 0x04 ) && ( pm_reg[0x1A] & 0x08 ) && |
| 964 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1A] & 0x01 ) ) || |
| 965 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1A] & 0x01 ) ) ) ) |
| 966 | { |
| 967 | timer_enable( timers.timer2, 1 ); |
| 968 | } |
| 969 | else |
| 970 | { |
| 971 | timer_enable( timers.timer2, 0 ); |
| 972 | } |
| 973 | if ( ( pm_reg[0x39] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) && |
| 974 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) || |
| 975 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) ) |
| 976 | { |
| 977 | timer_enable( timers.timer2_hi, 1 ); |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | timer_enable( timers.timer2_hi, 0 ); |
| 982 | } |
| 387 | 983 | break; |
| 388 | 984 | case 0x39: /* Timer 2 control 2 |
| 389 | | Bit 0-2 Unused |
| 985 | Bit 0 R/W Unknown |
| 986 | Bit 1 W Reset hi counter |
| 987 | Bit 2 R/W Enable high counter |
| 390 | 988 | Bit 3 R/W Unknown |
| 391 | 989 | Bit 4-7 Unused |
| 392 | 990 | */ |
| 991 | if ( data & 0x02 ) |
| 992 | { |
| 993 | pm_reg[0x3F] = pm_reg[0x3A]; |
| 994 | data &= ~0x02; |
| 995 | } |
| 996 | |
| 997 | if ( ( data & 0x04 ) && ! ( pm_reg[0x38] & 0x80 ) && ( pm_reg[0x1A] & 0x80 ) && |
| 998 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1B] & 0x02 ) ) || |
| 999 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1B] & 0x02 ) ) ) ) |
| 1000 | { |
| 1001 | timer_enable( timers.timer2_hi, 1 ); |
| 1002 | } |
| 1003 | else |
| 1004 | { |
| 1005 | timer_enable( timers.timer2_hi, 0 ); |
| 1006 | } |
| 1007 | break; |
| 393 | 1008 | case 0x3A: /* Timer 2 preset value (low) |
| 394 | 1009 | Bit 0-7 R/W Timer 2 preset value bit 0-7 |
| 395 | 1010 | */ |
| 1011 | break; |
| 396 | 1012 | case 0x3B: /* Timer 2 preset value (high) |
| 397 | 1013 | Bit 0-7 R/W Timer 2 preset value bit 8-15 |
| 398 | 1014 | */ |
| 1015 | break; |
| 399 | 1016 | case 0x3C: /* Timer 2 sound-pivot (low, unused) |
| 400 | 1017 | */ |
| 401 | 1018 | case 0x3D: /* Timer 2 sound-pivot (high, unused) |
| 402 | 1019 | */ |
| 403 | | case 0x3E: /* Timer 2 counter (low) |
| 1020 | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 1021 | break; |
| 1022 | case 0x3E: /* Timer 2 counter (low), read only |
| 404 | 1023 | Bit 0-7 R/W Timer 2 counter value bit 0-7 |
| 405 | 1024 | */ |
| 406 | | case 0x3F: /* Timer 2 counter (high) |
| 1025 | return; |
| 1026 | case 0x3F: /* Timer 2 counter (high), read only |
| 407 | 1027 | Bit 0-7 R/W Timer 2 counter value bit 8-15 |
| 408 | 1028 | */ |
| 409 | | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 410 | | break; |
| 1029 | return; |
| 411 | 1030 | case 0x40: /* 256Hz timer control |
| 412 | 1031 | Bit 0 R/W Enable Timer |
| 413 | 1032 | Bit 1 W Reset Timer |
| 414 | 1033 | Bit 2-7 Unused |
| 415 | 1034 | */ |
| 416 | | if ( data & 0x01 ) { /* enable timer */ |
| 417 | | if ( ! timers.hz256_running ) { |
| 418 | | timer_adjust_oneshot(timers.hz256_timer, ATTOTIME_IN_HZ(256), 0); |
| 419 | | timers.hz256_running = 1; |
| 420 | | } |
| 421 | | } else { /* pause timer */ |
| 422 | | if ( timers.hz256_running ) { |
| 423 | | timer_reset( timers.hz256_timer, attotime_never ); |
| 424 | | timers.hz256_running = 0; |
| 425 | | } |
| 426 | | } |
| 427 | | if ( data & 0x02 ) { |
| 428 | | timers.hz256_counter = 0; |
| 1035 | if ( data & 0x02 ) |
| 1036 | { |
| 1037 | pm_reg[0x41] = 0; |
| 429 | 1038 | data &= ~0x02; |
| 430 | 1039 | } |
| 431 | 1040 | break; |
| r2798 | r2799 | |
| 435 | 1044 | return; |
| 436 | 1045 | case 0x48: /* Timer 3 control 1 |
| 437 | 1046 | Bit 0 R/W Unknown |
| 438 | | Bit 1 Unused |
| 439 | | Bit 2 W Preset timer |
| 440 | | Bit 3-6 Unused |
| 441 | | Bit 7 R/W Enable timer 3 counting (this seems to unlock/lock register 0x4E) |
| 1047 | Bit 1 W Reset low counter |
| 1048 | Bit 2 R/W Enable high counter |
| 1049 | Bit 3 R/W Unknown |
| 1050 | Bit 4-6 Unused |
| 1051 | Bit 7 R/W Enable 16bit mode |
| 442 | 1052 | */ |
| 443 | | if ( data & 0x04 ) { |
| 444 | | timers.timer3_counter = ( pokemini_hwreg[0x4f] << 8 ) | pokemini_hwreg[0x4e]; |
| 445 | | pokemini_hwreg[0x4a] = pokemini_hwreg[0x4e]; |
| 446 | | pokemini_hwreg[0x4b] = pokemini_hwreg[0x4f]; |
| 447 | | data &= ~0x04; |
| 1053 | if ( data & 0x02 ) |
| 1054 | { |
| 1055 | pm_reg[0x4E] = pm_reg[0x4A]; |
| 1056 | data &= ~0x02; |
| 448 | 1057 | } |
| 1058 | |
| 1059 | if ( ( data & 0x04 ) && ( pm_reg[0x1C] & 0x08 ) && |
| 1060 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x01 ) ) || |
| 1061 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x01 ) ) ) ) |
| 1062 | { |
| 1063 | timer_enable( timers.timer3, 1 ); |
| 1064 | } |
| 1065 | else |
| 1066 | { |
| 1067 | timer_enable( timers.timer3, 0 ); |
| 1068 | } |
| 1069 | if ( ( pm_reg[0x49] & 0x04 ) && ! ( data & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) && |
| 1070 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) || |
| 1071 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) ) |
| 1072 | { |
| 1073 | timer_enable( timers.timer3_hi, 1 ); |
| 1074 | } |
| 1075 | else |
| 1076 | { |
| 1077 | timer_enable( timers.timer3_hi, 0 ); |
| 1078 | } |
| 449 | 1079 | break; |
| 450 | 1080 | case 0x49: /* Timer 3 control 2 |
| 451 | | Bit 0-2 Unused |
| 1081 | Bit 0 R/W Unknown |
| 1082 | Bit 1 W Reset hi counter |
| 1083 | Bit 2 R/W Enable high counter |
| 452 | 1084 | Bit 3 R/W Unknown |
| 453 | 1085 | Bit 4-7 Unused |
| 454 | 1086 | */ |
| 1087 | if ( data & 0x02 ) |
| 1088 | { |
| 1089 | pm_reg[0x4F] = pm_reg[0x4B]; |
| 1090 | data &= ~0x02; |
| 1091 | } |
| 1092 | |
| 1093 | if ( ( data & 0x04 ) && ! ( pm_reg[0x48] & 0x80 ) && ( pm_reg[0x1C] & 0x80 ) && |
| 1094 | ( ( ( pm_reg[0x19] & 0x20 ) && ! ( pm_reg[0x1D] & 0x02 ) ) || |
| 1095 | ( ( pm_reg[0x19] & 0x10 ) && ( pm_reg[0x1D] & 0x02 ) ) ) ) |
| 1096 | { |
| 1097 | timer_enable( timers.timer3_hi, 1 ); |
| 1098 | } |
| 1099 | else |
| 1100 | { |
| 1101 | timer_enable( timers.timer3_hi, 0 ); |
| 1102 | } |
| 1103 | break; |
| 455 | 1104 | case 0x4A: /* Timer 3 preset value (low) |
| 456 | 1105 | Bit 0-7 R/W Timer 3 preset value bit 0-7 |
| 457 | 1106 | */ |
| 1107 | break; |
| 458 | 1108 | case 0x4B: /* Timer 3 preset value (high) |
| 459 | 1109 | Bit 0-7 R/W Timer 3 preset value bit 8-15 |
| 460 | 1110 | */ |
| 1111 | break; |
| 461 | 1112 | case 0x4C: /* Timer 3 sound-pivot (low) |
| 462 | 1113 | Bit 0-7 R/W Timer 3 sound-pivot value bit 0-7 |
| 463 | 1114 | */ |
| r2798 | r2799 | |
| 469 | 1120 | Pulse-Width of 50% = Half of preset-value |
| 470 | 1121 | Pulse-Width of 100% = Same as preset-value |
| 471 | 1122 | */ |
| 472 | | case 0x4E: /* Timer 3 counter (low) |
| 1123 | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 1124 | break; |
| 1125 | case 0x4E: /* Timer 3 counter (low), read only |
| 473 | 1126 | Bit 0-7 R/W Timer 3 counter value bit 0-7 |
| 474 | 1127 | */ |
| 475 | | case 0x4F: /* Timer 3 counter (high) |
| 1128 | return; |
| 1129 | case 0x4F: /* Timer 3 counter (high), read only |
| 476 | 1130 | Bit 0-7 R/W Timer 3 counter value bit 8-15 |
| 477 | 1131 | */ |
| 478 | | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 479 | | break; |
| 1132 | return; |
| 480 | 1133 | case 0x52: /* Keypad status |
| 481 | 1134 | Bit 0 R Key "A" |
| 482 | 1135 | Bit 1 R Key "B" |
| r2798 | r2799 | |
| 523 | 1176 | Bit 0 R/W Invert colors; 0 - normal, 1 - inverted |
| 524 | 1177 | Bit 1 R/W Enable rendering of background |
| 525 | 1178 | Bit 2 R/W Enable rendering of sprites |
| 526 | | Bit 3 R/W Global rendering enable |
| 1179 | Bit 3 R/W Enable copy to LCD ram |
| 527 | 1180 | Bit 4-5 R/W Map size |
| 528 | 1181 | 00 - 12x16 |
| 529 | 1182 | 01 - 16x12 |
| r2798 | r2799 | |
| 531 | 1184 | 11 - 24x8 (prohibited code) |
| 532 | 1185 | Bit 6-7 Unused |
| 533 | 1186 | */ |
| 534 | | vdp.colors_inverted = ( data & 0x01 ) ? 1 : 0; |
| 535 | | vdp.background_enabled = ( data & 0x02 ) ? 1 : 0; |
| 536 | | vdp.sprites_enabled = ( data & 0x04 ) ? 1 : 0; |
| 537 | | vdp.rendering_enabled = ( data & 0x08 ) ? 1 : 0; |
| 538 | | vdp.map_size = ( data >> 4 ) & 0x03; |
| 539 | | switch( vdp.map_size ) { |
| 1187 | prc.colors_inverted = ( data & 0x01 ) ? 1 : 0; |
| 1188 | prc.background_enabled = ( data & 0x02 ) ? 1 : 0; |
| 1189 | prc.sprites_enabled = ( data & 0x04 ) ? 1 : 0; |
| 1190 | prc.copy_enabled = ( data & 0x08 ) ? 1 : 0; |
| 1191 | prc.map_size = ( data >> 4 ) & 0x03; |
| 1192 | switch( prc.map_size ) |
| 1193 | { |
| 540 | 1194 | case 0: |
| 541 | | vdp.map_size_x = 12; break; |
| 1195 | prc.map_size_x = 12; break; |
| 542 | 1196 | case 1: |
| 543 | | vdp.map_size_x = 16; break; |
| 1197 | prc.map_size_x = 16; break; |
| 544 | 1198 | case 2: |
| 545 | 1199 | case 3: |
| 546 | | vdp.map_size_x = 24; break; |
| 1200 | prc.map_size_x = 24; break; |
| 547 | 1201 | } |
| 548 | 1202 | break; |
| 549 | 1203 | case 0x81: /* LCD render refresh rate |
| r2798 | r2799 | |
| 552 | 1206 | 000 - 60Hz / 3 = 20Hz (0 - 2) |
| 553 | 1207 | 001 - 60Hz / 6 = 10Hz (0 - 5) |
| 554 | 1208 | 010 - 60Hz / 9 = 6,6Hz (0 - 8) |
| 555 | | 011 - 60Hz / 12 = 5Hz (0 - 8) |
| 1209 | 011 - 60Hz / 12 = 5Hz (0 - B) |
| 556 | 1210 | 100 - 60Hz / 2 = 30Hz (0 - 1) |
| 557 | 1211 | 101 - 60Hz / 4 = 15Hz (0 - 3) |
| 558 | 1212 | 110 - 60Hz / 6 = 10Hz (0 - 5) |
| 559 | 1213 | 111 - 60Hz / 8 = 7,5Hz (0 - 7) |
| 560 | 1214 | Bit 4-7 R Divider position, when overflow the LCD is updated |
| 561 | 1215 | */ |
| 562 | | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 1216 | switch ( data & 0x0E ) |
| 1217 | { |
| 1218 | case 0x00: prc.max_frame_count = 3; break; |
| 1219 | case 0x02: prc.max_frame_count = 6; break; |
| 1220 | case 0x04: prc.max_frame_count = 9; break; |
| 1221 | case 0x06: prc.max_frame_count = 12; break; |
| 1222 | case 0x08: prc.max_frame_count = 2; break; |
| 1223 | case 0x0A: prc.max_frame_count = 4; break; |
| 1224 | case 0x0C: prc.max_frame_count = 6; break; |
| 1225 | case 0x0E: prc.max_frame_count = 8; break; |
| 1226 | } |
| 563 | 1227 | break; |
| 564 | 1228 | case 0x82: /* BG tile data memory offset (low) |
| 565 | 1229 | Bit 0-2 Always "0" |
| 566 | 1230 | Bit 3-7 R/W BG tile data memory offset bit 3-7 |
| 567 | 1231 | */ |
| 568 | 1232 | data &= 0xF8; |
| 569 | | vdp.bg_tiles = ( vdp.bg_tiles & 0xFFFF00 ) | data; |
| 1233 | prc.bg_tiles = ( prc.bg_tiles & 0xFFFF00 ) | data; |
| 570 | 1234 | break; |
| 571 | 1235 | case 0x83: /* BG tile data memory offset (mid) |
| 572 | 1236 | Bit 0-7 R/W BG tile data memory offset bit 8-15 |
| 573 | 1237 | */ |
| 574 | | vdp.bg_tiles = ( vdp.bg_tiles & 0xFF00FF ) | ( data << 8 ); |
| 1238 | prc.bg_tiles = ( prc.bg_tiles & 0xFF00FF ) | ( data << 8 ); |
| 575 | 1239 | break; |
| 576 | 1240 | case 0x84: /* BG tile data memory offset (high) |
| 577 | 1241 | Bit 0-4 R/W BG tile data memory offset bit 16-20 |
| 578 | 1242 | Bit 5-7 Unused |
| 579 | 1243 | */ |
| 580 | 1244 | data &= 0x1F; |
| 581 | | vdp.bg_tiles = ( vdp.bg_tiles & 0x00FFFF ) | ( data << 16 ); |
| 1245 | prc.bg_tiles = ( prc.bg_tiles & 0x00FFFF ) | ( data << 16 ); |
| 582 | 1246 | break; |
| 583 | 1247 | case 0x85: /* BG vertical move |
| 584 | 1248 | Bit 0-6 R/W Move the background up, move range: |
| r2798 | r2799 | |
| 601 | 1265 | Bit 6-7 R/W Sprite tile data memory offset bit 6-7 |
| 602 | 1266 | */ |
| 603 | 1267 | data &= 0xC0; |
| 604 | | vdp.spr_tiles = ( vdp.spr_tiles & 0xFFFF00 ) | data; |
| 1268 | prc.spr_tiles = ( prc.spr_tiles & 0xFFFF00 ) | data; |
| 605 | 1269 | break; |
| 606 | 1270 | case 0x88: /* Sprite tile data memory offset (med) |
| 607 | 1271 | Bit 0-7 R/W Sprite tile data memory offset bit 8-15 |
| 608 | 1272 | */ |
| 609 | | vdp.spr_tiles = ( vdp.spr_tiles & 0xFF00FF ) | ( data << 8 ); |
| 1273 | prc.spr_tiles = ( prc.spr_tiles & 0xFF00FF ) | ( data << 8 ); |
| 610 | 1274 | break; |
| 611 | 1275 | case 0x89: /* Sprite tile data memory offset (high) |
| 612 | 1276 | Bit 0-4 R/W Sprite tile data memory offset bit 16-20 |
| 613 | 1277 | Bit 5-7 Unused |
| 614 | 1278 | */ |
| 615 | 1279 | data &= 0x1F; |
| 616 | | vdp.spr_tiles = ( vdp.spr_tiles & 0x00FFFF ) | ( data << 16 ); |
| 1280 | prc.spr_tiles = ( prc.spr_tiles & 0x00FFFF ) | ( data << 16 ); |
| 617 | 1281 | break; |
| 618 | 1282 | case 0x8A: /* LCD status |
| 619 | 1283 | Bit 0 R Unknown |
| 620 | 1284 | Bit 1 R Unknown |
| 621 | 1285 | Bit 2 R Unknown |
| 622 | 1286 | Bit 3 R Unknown |
| 623 | | Bit 4 R LCD during V-Sync |
| 1287 | Bit 4 R LCD during V-Sync / Rendering circuitry active or not ( 1 = not active) |
| 624 | 1288 | Bit 5 R Unknown |
| 625 | 1289 | Bit 6-7 Unused |
| 626 | 1290 | */ |
| 627 | 1291 | case 0xFE: /* Direct LCD control / data |
| 628 | 1292 | Bit 0-7 R/W Direct LCD command or data |
| 629 | 1293 | */ |
| 1294 | // lcd_command_w( data ); |
| 1295 | break; |
| 630 | 1296 | case 0xFF: /* Direct LCD data |
| 631 | 1297 | Bit 0-7 R/W Direct LCD data |
| 632 | 1298 | */ |
| 1299 | // lcd_data_w( data ); |
| 1300 | break; |
| 633 | 1301 | default: |
| 634 | 1302 | logerror( "%0X: Write to unknown hardware address: %02X, %02X\n", activecpu_get_pc(), offset, data ); |
| 635 | 1303 | break; |
| 636 | 1304 | } |
| 637 | | pokemini_hwreg[offset] = data; |
| 1305 | pm_reg[offset] = data; |
| 638 | 1306 | } |
| 639 | 1307 | |
| 640 | | READ8_HANDLER( pokemini_hwreg_r ) { |
| 641 | | switch( offset ) { |
| 642 | | case 0x09: return timers.seconds_counter & 0xFF; |
| 643 | | case 0x0A: return ( timers.seconds_counter >> 8 ) & 0xFF; |
| 644 | | case 0x0B: return ( timers.seconds_counter >> 16 ) & 0xFF; |
| 645 | | case 0x41: return timers.hz256_counter; |
| 1308 | READ8_HANDLER( pokemini_hwreg_r ) |
| 1309 | { |
| 1310 | switch( offset ) |
| 1311 | { |
| 646 | 1312 | case 0x52: return input_port_read(machine, "INPUTS"); |
| 1313 | case 0x81: return ( pm_reg[offset] & 0x0F ) | ( prc.frame_count << 4 ); |
| 1314 | case 0x8A: return prc.count; |
| 647 | 1315 | } |
| 648 | | logerror( "%0X: Read from unknown hardware address: %02X\n", activecpu_get_pc(), offset ); |
| 649 | | return pokemini_hwreg[offset]; |
| 1316 | return pm_reg[offset]; |
| 650 | 1317 | } |
| 651 | 1318 | |
| 652 | | DEVICE_START( pokemini_cart ) { |
| 1319 | DEVICE_START( pokemini_cart ) |
| 1320 | { |
| 653 | 1321 | } |
| 654 | 1322 | |
| 655 | | DEVICE_IMAGE_LOAD( pokemini_cart ) { |
| 1323 | DEVICE_IMAGE_LOAD( pokemini_cart ) |
| 1324 | { |
| 656 | 1325 | int size = image_length( image ); |
| 657 | 1326 | |
| 658 | 1327 | /* Verify that the image is big enough */ |
| 659 | | if ( size <= 0x2100 ) { |
| 1328 | if ( size <= 0x2100 ) |
| 1329 | { |
| 660 | 1330 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too small" ); |
| 661 | 1331 | return INIT_FAIL; |
| 662 | 1332 | } |
| 663 | 1333 | |
| 664 | 1334 | /* Verify that the image is not too big */ |
| 665 | | if ( size > 0x1FFFFF ) { |
| 1335 | if ( size > 0x1FFFFF ) |
| 1336 | { |
| 666 | 1337 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid ROM image: ROM image is too big" ); |
| 667 | 1338 | return INIT_FAIL; |
| 668 | 1339 | } |
| r2798 | r2799 | |
| 671 | 1342 | image_fseek( image, 0x2100, SEEK_SET ); |
| 672 | 1343 | size -= 0x2100; |
| 673 | 1344 | |
| 674 | | if ( size != image_fread( image, memory_region(REGION_CPU1) + 0x2100, size ) ) { |
| 1345 | if ( size != image_fread( image, memory_region(REGION_CPU1) + 0x2100, size ) ) |
| 1346 | { |
| 675 | 1347 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Error occured while reading ROM image" ); |
| 676 | 1348 | return INIT_FAIL; |
| 677 | 1349 | } |
| r2798 | r2799 | |
| 679 | 1351 | return INIT_PASS; |
| 680 | 1352 | } |
| 681 | 1353 | |
| 682 | | static void pokemini_render( void ) { |
| 683 | | if ( vdp.background_enabled ) { |
| 684 | | int x, y; |
| 685 | | for ( y = 0; y < 8; y++ ) { |
| 686 | | for ( x = 0; x < 12; x++ ) { |
| 687 | | UINT8 tile = pokemini_ram[ 0x360 + ( y * vdp.map_size_x ) + x ]; |
| 688 | | int i; |
| 689 | | for( i = 0; i < 8; i++ ) { |
| 690 | | pokemini_ram[ ( y * 96 ) + ( x * 8 ) + i ] = program_read_byte( vdp.bg_tiles + ( tile * 8 ) + i ); |
| 1354 | |
| 1355 | static TIMER_CALLBACK( pokemini_prc_counter_callback ) |
| 1356 | { |
| 1357 | prc.count++; |
| 1358 | |
| 1359 | logerror("prc.count is %02x\n", prc.count); |
| 1360 | /* Check for overflow */ |
| 1361 | if ( prc.count >= 0x42 ) |
| 1362 | { |
| 1363 | prc.count = 0; |
| 1364 | prc.frame_count++; |
| 1365 | |
| 1366 | if ( prc.frame_count >= prc.max_frame_count ) |
| 1367 | { |
| 1368 | prc.frame_count = 0; |
| 1369 | |
| 1370 | /* Check if the background should be drawn */ |
| 1371 | if ( prc.background_enabled ) |
| 1372 | { |
| 1373 | int x, y; |
| 1374 | for ( y = 0; y < 8; y++ ) { |
| 1375 | for ( x = 0; x < 12; x++ ) { |
| 1376 | UINT8 tile = pokemini_ram[ 0x360 + ( y * prc.map_size_x ) + x ]; |
| 1377 | int i; |
| 1378 | for( i = 0; i < 8; i++ ) { |
| 1379 | pokemini_ram[ ( y * 96 ) + ( x * 8 ) + i ] = program_read_byte( prc.bg_tiles + ( tile * 8 ) + i ); |
| 1380 | } |
| 1381 | } |
| 691 | 1382 | } |
| 692 | 1383 | } |
| 693 | | } |
| 694 | | } |
| 695 | | } |
| 696 | 1384 | |
| 697 | | INTERRUPT_GEN( pokemini_int ) { |
| 698 | | /* Check if drawing is enabled */ |
| 699 | | if ( vdp.rendering_enabled ) { |
| 700 | | int x, y; |
| 1385 | /* Check if the sprites should be drawn */ |
| 1386 | if ( prc.sprites_enabled ) |
| 1387 | { |
| 1388 | } |
| 701 | 1389 | |
| 702 | | pokemini_render(); |
| 1390 | /* Set PRC Render interrupt */ |
| 1391 | pm_reg[0x27] |= 0x40; |
| 1392 | pokemini_check_irqs( machine ); |
| 703 | 1393 | |
| 704 | | for( y = 0; y < 64; y += 8 ) { |
| 705 | | for( x = 0; x < 96; x++ ) { |
| 706 | | UINT8 data = pokemini_ram[ ( y * 12 ) + x ]; |
| 707 | | *BITMAP_ADDR16(tmpbitmap, y + 0, x) = ( data & 0x01 ) ? 3 : 0; |
| 708 | | *BITMAP_ADDR16(tmpbitmap, y + 1, x) = ( data & 0x02 ) ? 3 : 0; |
| 709 | | *BITMAP_ADDR16(tmpbitmap, y + 2, x) = ( data & 0x04 ) ? 3 : 0; |
| 710 | | *BITMAP_ADDR16(tmpbitmap, y + 3, x) = ( data & 0x08 ) ? 3 : 0; |
| 711 | | *BITMAP_ADDR16(tmpbitmap, y + 4, x) = ( data & 0x10 ) ? 3 : 0; |
| 712 | | *BITMAP_ADDR16(tmpbitmap, y + 5, x) = ( data & 0x20 ) ? 3 : 0; |
| 713 | | *BITMAP_ADDR16(tmpbitmap, y + 6, x) = ( data & 0x40 ) ? 3 : 0; |
| 714 | | *BITMAP_ADDR16(tmpbitmap, y + 7, x) = ( data & 0x80 ) ? 3 : 0; |
| 1394 | /* Check if the rendered data should be copied to the LCD */ |
| 1395 | if ( prc.copy_enabled ) |
| 1396 | { |
| 1397 | int x, y; |
| 1398 | |
| 1399 | for( y = 0; y < 64; y += 8 ) { |
| 1400 | for( x = 0; x < 96; x++ ) { |
| 1401 | UINT8 data = pokemini_ram[ ( y * 12 ) + x ]; |
| 1402 | |
| 1403 | *BITMAP_ADDR16(tmpbitmap, y + 0, x) = ( data & 0x01 ) ? 3 : 0; |
| 1404 | *BITMAP_ADDR16(tmpbitmap, y + 1, x) = ( data & 0x02 ) ? 3 : 0; |
| 1405 | *BITMAP_ADDR16(tmpbitmap, y + 2, x) = ( data & 0x04 ) ? 3 : 0; |
| 1406 | *BITMAP_ADDR16(tmpbitmap, y + 3, x) = ( data & 0x08 ) ? 3 : 0; |
| 1407 | *BITMAP_ADDR16(tmpbitmap, y + 4, x) = ( data & 0x10 ) ? 3 : 0; |
| 1408 | *BITMAP_ADDR16(tmpbitmap, y + 5, x) = ( data & 0x20 ) ? 3 : 0; |
| 1409 | *BITMAP_ADDR16(tmpbitmap, y + 6, x) = ( data & 0x40 ) ? 3 : 0; |
| 1410 | *BITMAP_ADDR16(tmpbitmap, y + 7, x) = ( data & 0x80 ) ? 3 : 0; |
| 1411 | } |
| 1412 | } |
| 715 | 1413 | } |
| 1414 | |
| 1415 | /* Set PRC Copy interrupt */ |
| 1416 | pm_reg[0x27] |= 0x80; |
| 1417 | pokemini_check_irqs( machine ); |
| 716 | 1418 | } |
| 1419 | |
| 1420 | /* Set possible input irqs */ |
| 1421 | pm_reg[0x29] |= ~ input_port_read( machine, "INPUTS" ); |
| 717 | 1422 | } |
| 718 | 1423 | } |
| 719 | 1424 | |
| 720 | 1425 | |
| 1426 | MACHINE_RESET( pokemini ) |
| 1427 | { |
| 1428 | /* Clear internal structures */ |
| 1429 | memset( &prc, 0, sizeof(prc) ); |
| 1430 | memset( &timers, 0, sizeof(timers) ); |
| 1431 | memset( pm_reg, 0, sizeof(pm_reg) ); |
| 1432 | |
| 1433 | /* Set up timers */ |
| 1434 | timers.seconds_timer = timer_alloc( pokemini_seconds_timer_callback , NULL ); |
| 1435 | timer_adjust_periodic( timers.seconds_timer, attotime_zero, 0, ATTOTIME_IN_SEC( 1 ) ); |
| 1436 | |
| 1437 | timers.hz256_timer = timer_alloc( pokemini_256hz_timer_callback , NULL ); |
| 1438 | timer_adjust_periodic( timers.hz256_timer, attotime_zero, 0, ATTOTIME_IN_HZ( 256 ) ); |
| 1439 | |
| 1440 | timers.timer1 = timer_alloc( pokemini_timer1_callback , NULL ); |
| 1441 | timers.timer1_hi = timer_alloc( pokemini_timer1_hi_callback, NULL ); |
| 1442 | timers.timer2 = timer_alloc( pokemini_timer2_callback , NULL ); |
| 1443 | timers.timer2_hi = timer_alloc( pokemini_timer2_hi_callback, NULL ); |
| 1444 | timers.timer3 = timer_alloc( pokemini_timer3_callback , NULL ); |
| 1445 | timers.timer3_hi = timer_alloc( pokemini_timer3_hi_callback, NULL ); |
| 1446 | |
| 1447 | /* Set up the PRC */ |
| 1448 | prc.max_frame_count = 2; |
| 1449 | prc.count_timer = timer_alloc( pokemini_prc_counter_callback, NULL ); |
| 1450 | timer_adjust_periodic( prc.count_timer, attotime_zero, 0, ATTOTIME_IN_CYCLES( 55640 / 65, 0 ) ); |
| 1451 | } |
| 1452 | |