src/mess/drivers/gba.c
| r7509 | r7510 | |
| 73 | 73 | |
| 74 | 74 | static void gba_request_irq(running_machine *machine, UINT32 int_type) |
| 75 | 75 | { |
| 76 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 76 | gba_state *state = (gba_state *)machine->driver_data; |
| 77 | 77 | |
| 78 | 78 | // set flag for later recovery |
| 79 | | gba_state->IF |= int_type; |
| 79 | state->IF |= int_type; |
| 80 | 80 | |
| 81 | 81 | // is this specific interrupt enabled? |
| 82 | | int_type &= gba_state->IE; |
| 82 | int_type &= state->IE; |
| 83 | 83 | if (int_type != 0) |
| 84 | 84 | { |
| 85 | 85 | // master enable? |
| 86 | | if (gba_state->IME & 1) |
| 86 | if (state->IME & 1) |
| 87 | 87 | { |
| 88 | 88 | cpu_set_input_line(devtag_get_device(machine, "maincpu"), ARM7_IRQ_LINE, ASSERT_LINE); |
| 89 | 89 | cpu_set_input_line(devtag_get_device(machine, "maincpu"), ARM7_IRQ_LINE, CLEAR_LINE); |
| r7509 | r7510 | |
| 96 | 96 | int ctrl; |
| 97 | 97 | FPTR ch; |
| 98 | 98 | static UINT32 ch_int[4] = { INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3 }; |
| 99 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 99 | gba_state *state = (gba_state *)machine->driver_data; |
| 100 | 100 | |
| 101 | 101 | ch = param; |
| 102 | 102 | |
| 103 | 103 | // printf("dma complete: ch %d\n", ch); |
| 104 | 104 | |
| 105 | | timer_adjust_oneshot(gba_state->dma_timer[ch], attotime_never, 0); |
| 105 | timer_adjust_oneshot(state->dma_timer[ch], attotime_never, 0); |
| 106 | 106 | |
| 107 | | ctrl = gba_state->dma_regs[(ch*3)+2] >> 16; |
| 107 | ctrl = state->dma_regs[(ch*3)+2] >> 16; |
| 108 | 108 | |
| 109 | 109 | // IRQ |
| 110 | 110 | if (ctrl & 0x4000) |
| r7509 | r7510 | |
| 117 | 117 | if (!((ctrl>>9) & 1) || ((ctrl & 0x3000) == 0)) |
| 118 | 118 | { |
| 119 | 119 | // printf("clear active for ch %d\n", ch); |
| 120 | | gba_state->dma_regs[(ch*3)+2] &= ~0x80000000; // clear "active" bit |
| 120 | state->dma_regs[(ch*3)+2] &= ~0x80000000; // clear "active" bit |
| 121 | 121 | } |
| 122 | 122 | else |
| 123 | 123 | { |
| 124 | 124 | // if repeat, reload the count |
| 125 | 125 | if ((ctrl>>9) & 1) |
| 126 | 126 | { |
| 127 | | gba_state->dma_cnt[ch] = gba_state->dma_regs[(ch*3)+2]&0xffff; |
| 127 | state->dma_cnt[ch] = state->dma_regs[(ch*3)+2]&0xffff; |
| 128 | 128 | |
| 129 | 129 | // if increment & reload mode, reload the destination |
| 130 | 130 | if (((ctrl>>5)&3) == 3) |
| 131 | 131 | { |
| 132 | | gba_state->dma_dst[ch] = gba_state->dma_regs[(ch*3)+1]; |
| 132 | state->dma_dst[ch] = state->dma_regs[(ch*3)+1]; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | } |
| r7509 | r7510 | |
| 142 | 142 | int srcadd, dstadd; |
| 143 | 143 | UINT32 src, dst; |
| 144 | 144 | const address_space *space = cpu_get_address_space(devtag_get_device(machine, "maincpu"), ADDRESS_SPACE_PROGRAM); |
| 145 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 145 | gba_state *state = (gba_state *)machine->driver_data; |
| 146 | 146 | |
| 147 | | src = gba_state->dma_src[ch]; |
| 148 | | dst = gba_state->dma_dst[ch]; |
| 149 | | ctrl = gba_state->dma_regs[(ch*3)+2] >> 16; |
| 150 | | srcadd = gba_state->dma_srcadd[ch]; |
| 151 | | dstadd = gba_state->dma_dstadd[ch]; |
| 147 | src = state->dma_src[ch]; |
| 148 | dst = state->dma_dst[ch]; |
| 149 | ctrl = state->dma_regs[(ch*3)+2] >> 16; |
| 150 | srcadd = state->dma_srcadd[ch]; |
| 151 | dstadd = state->dma_dstadd[ch]; |
| 152 | 152 | |
| 153 | | cnt = gba_state->dma_cnt[ch]; |
| 153 | cnt = state->dma_cnt[ch]; |
| 154 | 154 | if (!cnt) |
| 155 | 155 | { |
| 156 | 156 | if (ch == 3) |
| r7509 | r7510 | |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | | gba_state->dma_src[ch] = src; |
| 267 | | gba_state->dma_dst[ch] = dst; |
| 266 | state->dma_src[ch] = src; |
| 267 | state->dma_dst[ch] = dst; |
| 268 | 268 | |
| 269 | | // printf("settng DMA timer %d for %d cycs (tmr %x)\n", ch, cnt, (UINT32)gba_state->dma_timer[ch]); |
| 270 | | // timer_adjust_oneshot(gba_state->dma_timer[ch], ATTOTIME_IN_CYCLES(0, cnt), ch); |
| 269 | // printf("settng DMA timer %d for %d cycs (tmr %x)\n", ch, cnt, (UINT32)state->dma_timer[ch]); |
| 270 | // timer_adjust_oneshot(state->dma_timer[ch], ATTOTIME_IN_CYCLES(0, cnt), ch); |
| 271 | 271 | dma_complete(machine, NULL, ch); |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | static void audio_tick(running_machine *machine, int ref) |
| 275 | 275 | { |
| 276 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 276 | gba_state *state = (gba_state *)machine->driver_data; |
| 277 | 277 | |
| 278 | | if (!(gba_state->SOUNDCNT_X & 0x80)) |
| 278 | if (!(state->SOUNDCNT_X & 0x80)) |
| 279 | 279 | { |
| 280 | 280 | return; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | if (!ref) |
| 284 | 284 | { |
| 285 | | if (gba_state->fifo_a_ptr != gba_state->fifo_a_in) |
| 285 | if (state->fifo_a_ptr != state->fifo_a_in) |
| 286 | 286 | { |
| 287 | | if (gba_state->fifo_a_ptr == 17) |
| 287 | if (state->fifo_a_ptr == 17) |
| 288 | 288 | { |
| 289 | | gba_state->fifo_a_ptr = 0; |
| 289 | state->fifo_a_ptr = 0; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | | if (gba_state->SOUNDCNT_H & 0x100) |
| 292 | if (state->SOUNDCNT_H & 0x100) |
| 293 | 293 | { |
| 294 | 294 | running_device *dac_device = devtag_get_device(machine, "direct_a_left"); |
| 295 | 295 | |
| 296 | | dac_signed_data_w(dac_device, gba_state->fifo_a[gba_state->fifo_a_ptr]^0x80); |
| 296 | dac_signed_data_w(dac_device, state->fifo_a[state->fifo_a_ptr]^0x80); |
| 297 | 297 | } |
| 298 | | if (gba_state->SOUNDCNT_H & 0x200) |
| 298 | if (state->SOUNDCNT_H & 0x200) |
| 299 | 299 | { |
| 300 | 300 | running_device *dac_device = devtag_get_device(machine, "direct_a_right"); |
| 301 | 301 | |
| 302 | | dac_signed_data_w(dac_device, gba_state->fifo_a[gba_state->fifo_a_ptr]^0x80); |
| 302 | dac_signed_data_w(dac_device, state->fifo_a[state->fifo_a_ptr]^0x80); |
| 303 | 303 | } |
| 304 | | gba_state->fifo_a_ptr++; |
| 304 | state->fifo_a_ptr++; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // fifo empty? |
| 308 | | if (gba_state->fifo_a_ptr == gba_state->fifo_a_in) |
| 308 | if (state->fifo_a_ptr == state->fifo_a_in) |
| 309 | 309 | { |
| 310 | 310 | // is a DMA set up to feed us? |
| 311 | | if ((gba_state->dma_regs[(1*3)+1] == 0x40000a0) && ((gba_state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000)) |
| 311 | if ((state->dma_regs[(1*3)+1] == 0x40000a0) && ((state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000)) |
| 312 | 312 | { |
| 313 | 313 | // channel 1 it is |
| 314 | 314 | dma_exec(machine, 1); |
| 315 | 315 | } |
| 316 | | if ((gba_state->dma_regs[(2*3)+1] == 0x40000a0) && ((gba_state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000)) |
| 316 | if ((state->dma_regs[(2*3)+1] == 0x40000a0) && ((state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000)) |
| 317 | 317 | { |
| 318 | 318 | // channel 2 it is |
| 319 | 319 | dma_exec(machine, 2); |
| r7509 | r7510 | |
| 322 | 322 | } |
| 323 | 323 | else |
| 324 | 324 | { |
| 325 | | if (gba_state->fifo_b_ptr != gba_state->fifo_b_in) |
| 325 | if (state->fifo_b_ptr != state->fifo_b_in) |
| 326 | 326 | { |
| 327 | | if (gba_state->fifo_b_ptr == 17) |
| 327 | if (state->fifo_b_ptr == 17) |
| 328 | 328 | { |
| 329 | | gba_state->fifo_b_ptr = 0; |
| 329 | state->fifo_b_ptr = 0; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | | if (gba_state->SOUNDCNT_H & 0x1000) |
| 332 | if (state->SOUNDCNT_H & 0x1000) |
| 333 | 333 | { |
| 334 | 334 | running_device *dac_device = devtag_get_device(machine, "direct_b_left"); |
| 335 | 335 | |
| 336 | | dac_signed_data_w(dac_device, gba_state->fifo_b[gba_state->fifo_b_ptr]^0x80); |
| 336 | dac_signed_data_w(dac_device, state->fifo_b[state->fifo_b_ptr]^0x80); |
| 337 | 337 | } |
| 338 | | if (gba_state->SOUNDCNT_H & 0x2000) |
| 338 | if (state->SOUNDCNT_H & 0x2000) |
| 339 | 339 | { |
| 340 | 340 | running_device *dac_device = devtag_get_device(machine, "direct_b_right"); |
| 341 | 341 | |
| 342 | | dac_signed_data_w(dac_device, gba_state->fifo_b[gba_state->fifo_b_ptr]^0x80); |
| 342 | dac_signed_data_w(dac_device, state->fifo_b[state->fifo_b_ptr]^0x80); |
| 343 | 343 | } |
| 344 | | gba_state->fifo_b_ptr++; |
| 344 | state->fifo_b_ptr++; |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | | if (gba_state->fifo_b_ptr == gba_state->fifo_b_in) |
| 347 | if (state->fifo_b_ptr == state->fifo_b_in) |
| 348 | 348 | { |
| 349 | 349 | // is a DMA set up to feed us? |
| 350 | | if ((gba_state->dma_regs[(1*3)+1] == 0x40000a4) && ((gba_state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000)) |
| 350 | if ((state->dma_regs[(1*3)+1] == 0x40000a4) && ((state->dma_regs[(1*3)+2] & 0x30000000) == 0x30000000)) |
| 351 | 351 | { |
| 352 | 352 | // channel 1 it is |
| 353 | 353 | dma_exec(machine, 1); |
| 354 | 354 | } |
| 355 | | if ((gba_state->dma_regs[(2*3)+1] == 0x40000a4) && ((gba_state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000)) |
| 355 | if ((state->dma_regs[(2*3)+1] == 0x40000a4) && ((state->dma_regs[(2*3)+2] & 0x30000000) == 0x30000000)) |
| 356 | 356 | { |
| 357 | 357 | // channel 2 it is |
| 358 | 358 | dma_exec(machine, 2); |
| r7509 | r7510 | |
| 365 | 365 | { |
| 366 | 366 | static UINT32 tmr_ints[4] = { INT_TM0_OVERFLOW, INT_TM1_OVERFLOW, INT_TM2_OVERFLOW, INT_TM3_OVERFLOW }; |
| 367 | 367 | FPTR tmr = (FPTR) param; |
| 368 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 368 | gba_state *state = (gba_state *)machine->driver_data; |
| 369 | 369 | |
| 370 | | // printf("Timer %d expired, SOUNDCNT_H %04x\n", tmr, gba_state->SOUNDCNT_H); |
| 370 | // printf("Timer %d expired, SOUNDCNT_H %04x\n", tmr, state->SOUNDCNT_H); |
| 371 | 371 | |
| 372 | 372 | // check if timers 0 or 1 are feeding directsound |
| 373 | 373 | if (tmr == 0) |
| 374 | 374 | { |
| 375 | | if ((gba_state->SOUNDCNT_H & 0x400) == 0) |
| 375 | if ((state->SOUNDCNT_H & 0x400) == 0) |
| 376 | 376 | { |
| 377 | 377 | audio_tick(machine, 0); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | | if ((gba_state->SOUNDCNT_H & 0x4000) == 0) |
| 380 | if ((state->SOUNDCNT_H & 0x4000) == 0) |
| 381 | 381 | { |
| 382 | 382 | audio_tick(machine, 1); |
| 383 | 383 | } |
| r7509 | r7510 | |
| 385 | 385 | |
| 386 | 386 | if (tmr == 1) |
| 387 | 387 | { |
| 388 | | if ((gba_state->SOUNDCNT_H & 0x400) == 0x400) |
| 388 | if ((state->SOUNDCNT_H & 0x400) == 0x400) |
| 389 | 389 | { |
| 390 | 390 | audio_tick(machine, 0); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | | if ((gba_state->SOUNDCNT_H & 0x4000) == 0x4000) |
| 393 | if ((state->SOUNDCNT_H & 0x4000) == 0x4000) |
| 394 | 394 | { |
| 395 | 395 | audio_tick(machine, 1); |
| 396 | 396 | } |
| r7509 | r7510 | |
| 400 | 400 | switch (tmr) |
| 401 | 401 | { |
| 402 | 402 | case 0: |
| 403 | | if (gba_state->timer_regs[1] & 0x40000) |
| 403 | if (state->timer_regs[1] & 0x40000) |
| 404 | 404 | { |
| 405 | | gba_state->timer_regs[1] = ( ( gba_state->timer_regs[1] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 406 | | if( ( gba_state->timer_regs[1] & 0x0000ffff ) == 0 ) |
| 405 | state->timer_regs[1] = ( ( state->timer_regs[1] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 406 | if( ( state->timer_regs[1] & 0x0000ffff ) == 0 ) |
| 407 | 407 | { |
| 408 | | gba_state->timer_regs[1] |= gba_state->timer_reload[1]; |
| 409 | | if( ( gba_state->timer_regs[1] & 0x400000 ) && ( gba_state->IME != 0 ) ) |
| 408 | state->timer_regs[1] |= state->timer_reload[1]; |
| 409 | if( ( state->timer_regs[1] & 0x400000 ) && ( state->IME != 0 ) ) |
| 410 | 410 | { |
| 411 | 411 | gba_request_irq( machine, tmr_ints[1] ); |
| 412 | 412 | } |
| 413 | | if( ( gba_state->timer_regs[2] & 0x40000 ) ) |
| 413 | if( ( state->timer_regs[2] & 0x40000 ) ) |
| 414 | 414 | { |
| 415 | | gba_state->timer_regs[2] = ( ( gba_state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 416 | | if( ( gba_state->timer_regs[2] & 0x0000ffff ) == 0 ) |
| 415 | state->timer_regs[2] = ( ( state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 416 | if( ( state->timer_regs[2] & 0x0000ffff ) == 0 ) |
| 417 | 417 | { |
| 418 | | gba_state->timer_regs[2] |= gba_state->timer_reload[2]; |
| 419 | | if( ( gba_state->timer_regs[2] & 0x400000 ) && ( gba_state->IME != 0 ) ) |
| 418 | state->timer_regs[2] |= state->timer_reload[2]; |
| 419 | if( ( state->timer_regs[2] & 0x400000 ) && ( state->IME != 0 ) ) |
| 420 | 420 | { |
| 421 | 421 | gba_request_irq( machine, tmr_ints[2] ); |
| 422 | 422 | } |
| 423 | | if( ( gba_state->timer_regs[3] & 0x40000 ) ) |
| 423 | if( ( state->timer_regs[3] & 0x40000 ) ) |
| 424 | 424 | { |
| 425 | | gba_state->timer_regs[3] = ( ( gba_state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 426 | | if( ( gba_state->timer_regs[3] & 0x0000ffff ) == 0 ) |
| 425 | state->timer_regs[3] = ( ( state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 426 | if( ( state->timer_regs[3] & 0x0000ffff ) == 0 ) |
| 427 | 427 | { |
| 428 | | gba_state->timer_regs[3] |= gba_state->timer_reload[3]; |
| 429 | | if( ( gba_state->timer_regs[3] & 0x400000 ) && ( gba_state->IME != 0 ) ) |
| 428 | state->timer_regs[3] |= state->timer_reload[3]; |
| 429 | if( ( state->timer_regs[3] & 0x400000 ) && ( state->IME != 0 ) ) |
| 430 | 430 | { |
| 431 | 431 | gba_request_irq( machine, tmr_ints[3] ); |
| 432 | 432 | } |
| r7509 | r7510 | |
| 438 | 438 | } |
| 439 | 439 | break; |
| 440 | 440 | case 1: |
| 441 | | if (gba_state->timer_regs[2] & 0x40000) |
| 441 | if (state->timer_regs[2] & 0x40000) |
| 442 | 442 | { |
| 443 | | gba_state->timer_regs[2] = ( ( gba_state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 444 | | if( ( gba_state->timer_regs[2] & 0x0000ffff ) == 0 ) |
| 443 | state->timer_regs[2] = ( ( state->timer_regs[2] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 444 | if( ( state->timer_regs[2] & 0x0000ffff ) == 0 ) |
| 445 | 445 | { |
| 446 | | gba_state->timer_regs[2] |= gba_state->timer_reload[2]; |
| 447 | | if( ( gba_state->timer_regs[2] & 0x400000 ) && ( gba_state->IME != 0 ) ) |
| 446 | state->timer_regs[2] |= state->timer_reload[2]; |
| 447 | if( ( state->timer_regs[2] & 0x400000 ) && ( state->IME != 0 ) ) |
| 448 | 448 | { |
| 449 | 449 | gba_request_irq( machine, tmr_ints[2] ); |
| 450 | 450 | } |
| 451 | | if( ( gba_state->timer_regs[3] & 0x40000 ) ) |
| 451 | if( ( state->timer_regs[3] & 0x40000 ) ) |
| 452 | 452 | { |
| 453 | | gba_state->timer_regs[3] = ( ( gba_state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 454 | | if( ( gba_state->timer_regs[3] & 0x0000ffff ) == 0 ) |
| 453 | state->timer_regs[3] = ( ( state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 454 | if( ( state->timer_regs[3] & 0x0000ffff ) == 0 ) |
| 455 | 455 | { |
| 456 | | gba_state->timer_regs[2] |= gba_state->timer_reload[2]; |
| 457 | | if( ( gba_state->timer_regs[3] & 0x400000 ) && ( gba_state->IME != 0 ) ) |
| 456 | state->timer_regs[2] |= state->timer_reload[2]; |
| 457 | if( ( state->timer_regs[3] & 0x400000 ) && ( state->IME != 0 ) ) |
| 458 | 458 | { |
| 459 | 459 | gba_request_irq( machine, tmr_ints[3] ); |
| 460 | 460 | } |
| r7509 | r7510 | |
| 464 | 464 | } |
| 465 | 465 | break; |
| 466 | 466 | case 2: |
| 467 | | if (gba_state->timer_regs[3] & 0x40000) |
| 467 | if (state->timer_regs[3] & 0x40000) |
| 468 | 468 | { |
| 469 | | gba_state->timer_regs[3] = ( ( gba_state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 470 | | if( ( gba_state->timer_regs[3] & 0x0000ffff ) == 0 ) |
| 469 | state->timer_regs[3] = ( ( state->timer_regs[3] & 0x0000ffff ) + 1 ) & 0x0000ffff; |
| 470 | if( ( state->timer_regs[3] & 0x0000ffff ) == 0 ) |
| 471 | 471 | { |
| 472 | | gba_state->timer_regs[3] |= gba_state->timer_reload[3]; |
| 473 | | if( ( gba_state->timer_regs[3] & 0x400000 ) && ( gba_state->IME != 0 ) ) |
| 472 | state->timer_regs[3] |= state->timer_reload[3]; |
| 473 | if( ( state->timer_regs[3] & 0x400000 ) && ( state->IME != 0 ) ) |
| 474 | 474 | { |
| 475 | 475 | gba_request_irq( machine, tmr_ints[3] ); |
| 476 | 476 | } |
| r7509 | r7510 | |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | 482 | // are we supposed to IRQ? |
| 483 | | if ((gba_state->timer_regs[tmr] & 0x400000) && (gba_state->IME != 0)) |
| 483 | if ((state->timer_regs[tmr] & 0x400000) && (state->IME != 0)) |
| 484 | 484 | { |
| 485 | 485 | gba_request_irq(machine, tmr_ints[tmr]); |
| 486 | 486 | } |
| r7509 | r7510 | |
| 488 | 488 | |
| 489 | 489 | static TIMER_CALLBACK(handle_irq) |
| 490 | 490 | { |
| 491 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 491 | gba_state *state = (gba_state *)machine->driver_data; |
| 492 | 492 | |
| 493 | | gba_request_irq(machine, gba_state->IF); |
| 493 | gba_request_irq(machine, state->IF); |
| 494 | 494 | |
| 495 | | timer_adjust_oneshot(gba_state->irq_timer, attotime_never, 0); |
| 495 | timer_adjust_oneshot(state->irq_timer, attotime_never, 0); |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | static READ32_HANDLER( gba_io_r ) |
| r7509 | r7510 | |
| 500 | 500 | UINT32 retval = 0; |
| 501 | 501 | running_machine *machine = space->machine; |
| 502 | 502 | running_device *gb_device = devtag_get_device(space->machine, "custom"); |
| 503 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 503 | gba_state *state = (gba_state *)machine->driver_data; |
| 504 | 504 | |
| 505 | 505 | switch( offset ) |
| 506 | 506 | { |
| 507 | 507 | case 0x0000/4: |
| 508 | 508 | if( (mem_mask) & 0x0000ffff ) |
| 509 | 509 | { |
| 510 | | verboselog(machine, 2, "GBA IO Register Read: DISPCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->DISPCNT ); |
| 511 | | retval |= gba_state->DISPCNT; |
| 510 | verboselog(machine, 2, "GBA IO Register Read: DISPCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->DISPCNT ); |
| 511 | retval |= state->DISPCNT; |
| 512 | 512 | } |
| 513 | 513 | if( (mem_mask) & 0xffff0000 ) |
| 514 | 514 | { |
| 515 | | verboselog(machine, 2, "GBA IO Register Read: Green Swap (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->GRNSWAP ); |
| 516 | | retval |= gba_state->GRNSWAP << 16; |
| 515 | verboselog(machine, 2, "GBA IO Register Read: Green Swap (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->GRNSWAP ); |
| 516 | retval |= state->GRNSWAP << 16; |
| 517 | 517 | } |
| 518 | 518 | break; |
| 519 | 519 | case 0x0004/4: |
| 520 | | retval = (gba_state->DISPSTAT & 0xffff) | (video_screen_get_vpos(machine->primary_screen)<<16); |
| 520 | retval = (state->DISPSTAT & 0xffff) | (video_screen_get_vpos(machine->primary_screen)<<16); |
| 521 | 521 | break; |
| 522 | 522 | case 0x0008/4: |
| 523 | 523 | if( (mem_mask) & 0x0000ffff ) |
| 524 | 524 | { |
| 525 | | verboselog(machine, 2, "GBA IO Register Read: BG0CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->BG0CNT ); |
| 526 | | retval |= gba_state->BG0CNT; |
| 525 | verboselog(machine, 2, "GBA IO Register Read: BG0CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->BG0CNT ); |
| 526 | retval |= state->BG0CNT; |
| 527 | 527 | } |
| 528 | 528 | if( (mem_mask) & 0xffff0000 ) |
| 529 | 529 | { |
| 530 | | verboselog(machine, 2, "GBA IO Register Read: BG1CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->BG1CNT ); |
| 531 | | retval |= gba_state->BG1CNT << 16; |
| 530 | verboselog(machine, 2, "GBA IO Register Read: BG1CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->BG1CNT ); |
| 531 | retval |= state->BG1CNT << 16; |
| 532 | 532 | } |
| 533 | 533 | break; |
| 534 | 534 | case 0x000c/4: |
| 535 | 535 | if( (mem_mask) & 0x0000ffff ) |
| 536 | 536 | { |
| 537 | | verboselog(machine, 2, "GBA IO Register Read: BG2CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->BG2CNT ); |
| 538 | | retval |= gba_state->BG2CNT; |
| 537 | verboselog(machine, 2, "GBA IO Register Read: BG2CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->BG2CNT ); |
| 538 | retval |= state->BG2CNT; |
| 539 | 539 | } |
| 540 | 540 | if( (mem_mask) & 0xffff0000 ) |
| 541 | 541 | { |
| 542 | | verboselog(machine, 2, "GBA IO Register Read: BG3CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->BG3CNT ); |
| 543 | | retval |= gba_state->BG3CNT << 16; |
| 542 | verboselog(machine, 2, "GBA IO Register Read: BG3CNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->BG3CNT ); |
| 543 | retval |= state->BG3CNT << 16; |
| 544 | 544 | } |
| 545 | 545 | break; |
| 546 | 546 | case 0x0010/4: |
| r7509 | r7510 | |
| 686 | 686 | case 0x0048/4: |
| 687 | 687 | if( (mem_mask) & 0x0000ffff ) |
| 688 | 688 | { |
| 689 | | verboselog(machine, 2, "GBA IO Register Read: WININ (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->WININ ); |
| 690 | | retval |= gba_state->WININ; |
| 689 | verboselog(machine, 2, "GBA IO Register Read: WININ (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->WININ ); |
| 690 | retval |= state->WININ; |
| 691 | 691 | } |
| 692 | 692 | if( (mem_mask) & 0xffff0000 ) |
| 693 | 693 | { |
| 694 | | verboselog(machine, 2, "GBA IO Register Read: WINOUT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->WINOUT ); |
| 695 | | retval |= gba_state->WINOUT << 16; |
| 694 | verboselog(machine, 2, "GBA IO Register Read: WINOUT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->WINOUT ); |
| 695 | retval |= state->WINOUT << 16; |
| 696 | 696 | } |
| 697 | 697 | break; |
| 698 | 698 | case 0x004c/4: |
| r7509 | r7510 | |
| 708 | 708 | case 0x0050/4: |
| 709 | 709 | if( (mem_mask) & 0x0000ffff ) |
| 710 | 710 | { |
| 711 | | verboselog(machine, 2, "GBA IO Register Read: BLDCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->BLDCNT ); |
| 712 | | retval |= gba_state->BLDCNT; |
| 711 | verboselog(machine, 2, "GBA IO Register Read: BLDCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->BLDCNT ); |
| 712 | retval |= state->BLDCNT; |
| 713 | 713 | } |
| 714 | 714 | if( (mem_mask) & 0xffff0000 ) |
| 715 | 715 | { |
| r7509 | r7510 | |
| 774 | 774 | retval = gb_sound_r(gb_device, 0x14) | gb_sound_r(gb_device, 0x15)<<8; |
| 775 | 775 | if( (mem_mask) & 0xffff0000 ) |
| 776 | 776 | { |
| 777 | | verboselog(machine, 2, "GBA IO Register Read: SOUNDCNT_H (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SOUNDCNT_H ); |
| 778 | | retval |= gba_state->SOUNDCNT_H << 16; |
| 777 | verboselog(machine, 2, "GBA IO Register Read: SOUNDCNT_H (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SOUNDCNT_H ); |
| 778 | retval |= state->SOUNDCNT_H << 16; |
| 779 | 779 | } |
| 780 | 780 | break; |
| 781 | 781 | case 0x0084/4: |
| r7509 | r7510 | |
| 784 | 784 | case 0x0088/4: |
| 785 | 785 | if( (mem_mask) & 0x0000ffff ) |
| 786 | 786 | { |
| 787 | | verboselog(machine, 2, "GBA IO Register Read: SOUNDBIAS (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SOUNDBIAS ); |
| 788 | | retval |= gba_state->SOUNDBIAS; |
| 787 | verboselog(machine, 2, "GBA IO Register Read: SOUNDBIAS (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SOUNDBIAS ); |
| 788 | retval |= state->SOUNDBIAS; |
| 789 | 789 | } |
| 790 | 790 | if( (mem_mask) & 0xffff0000 ) |
| 791 | 791 | { |
| r7509 | r7510 | |
| 824 | 824 | // no idea why here, but it matches VBA better |
| 825 | 825 | if (((offset-0xb0/4) % 3) == 2) |
| 826 | 826 | { |
| 827 | | return gba_state->dma_regs[offset-(0xb0/4)] & 0xff000000; |
| 827 | return state->dma_regs[offset-(0xb0/4)] & 0xff000000; |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | | return gba_state->dma_regs[offset-(0xb0/4)]; |
| 830 | return state->dma_regs[offset-(0xb0/4)]; |
| 831 | 831 | } |
| 832 | 832 | break; |
| 833 | 833 | case 0x0100/4: |
| r7509 | r7510 | |
| 842 | 842 | // printf("Read timer reg %x (PC=%x)\n", timer, cpu_get_pc(space->cpu)); |
| 843 | 843 | |
| 844 | 844 | // update times for |
| 845 | | if (gba_state->timer_regs[timer] & 0x800000) |
| 845 | if (state->timer_regs[timer] & 0x800000) |
| 846 | 846 | { |
| 847 | | time = attotime_to_double(timer_timeelapsed(gba_state->tmr_timer[timer])); |
| 847 | time = attotime_to_double(timer_timeelapsed(state->tmr_timer[timer])); |
| 848 | 848 | |
| 849 | | ticks = (double)(0x10000 - (gba_state->timer_regs[timer] & 0xffff)); |
| 849 | ticks = (double)(0x10000 - (state->timer_regs[timer] & 0xffff)); |
| 850 | 850 | |
| 851 | | // printf("time %f ticks %f 1/hz %f\n", time, ticks, 1.0 / gba_state->timer_hz[timer]); |
| 851 | // printf("time %f ticks %f 1/hz %f\n", time, ticks, 1.0 / state->timer_hz[timer]); |
| 852 | 852 | |
| 853 | 853 | time *= ticks; |
| 854 | | time /= (1.0 / gba_state->timer_hz[timer]); |
| 854 | time /= (1.0 / state->timer_hz[timer]); |
| 855 | 855 | |
| 856 | 856 | elapsed = (UINT32)time; |
| 857 | 857 | |
| r7509 | r7510 | |
| 863 | 863 | elapsed = 0; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | | return (gba_state->timer_regs[timer] & 0xffff0000) | (elapsed & 0xffff); |
| 866 | return (state->timer_regs[timer] & 0xffff0000) | (elapsed & 0xffff); |
| 867 | 867 | } |
| 868 | 868 | break; |
| 869 | 869 | case 0x0120/4: |
| 870 | 870 | if( (mem_mask) & 0x0000ffff ) |
| 871 | 871 | { |
| 872 | | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI0 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SIOMULTI0 ); |
| 873 | | retval |= gba_state->SIOMULTI0; |
| 872 | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI0 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SIOMULTI0 ); |
| 873 | retval |= state->SIOMULTI0; |
| 874 | 874 | } |
| 875 | 875 | if( (mem_mask) & 0xffff0000 ) |
| 876 | 876 | { |
| 877 | | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI1 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SIOMULTI1 ); |
| 878 | | retval |= gba_state->SIOMULTI1 << 16; |
| 877 | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI1 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SIOMULTI1 ); |
| 878 | retval |= state->SIOMULTI1 << 16; |
| 879 | 879 | } |
| 880 | 880 | break; |
| 881 | 881 | case 0x0124/4: |
| 882 | 882 | if( (mem_mask) & 0x0000ffff ) |
| 883 | 883 | { |
| 884 | | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI2 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SIOMULTI2 ); |
| 885 | | retval |= gba_state->SIOMULTI2; |
| 884 | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI2 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SIOMULTI2 ); |
| 885 | retval |= state->SIOMULTI2; |
| 886 | 886 | } |
| 887 | 887 | if( (mem_mask) & 0xffff0000 ) |
| 888 | 888 | { |
| 889 | | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI3 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SIOMULTI3 ); |
| 890 | | retval |= gba_state->SIOMULTI3 << 16; |
| 889 | verboselog(machine, 2, "GBA IO Register Read: SIOMULTI3 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SIOMULTI3 ); |
| 890 | retval |= state->SIOMULTI3 << 16; |
| 891 | 891 | } |
| 892 | 892 | break; |
| 893 | 893 | case 0x0128/4: |
| 894 | 894 | if( (mem_mask) & 0x0000ffff ) |
| 895 | 895 | { |
| 896 | | verboselog(machine, 2, "GBA IO Register Read: SIOCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->SIOCNT ); |
| 897 | | retval |= gba_state->SIOCNT; |
| 896 | verboselog(machine, 2, "GBA IO Register Read: SIOCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->SIOCNT ); |
| 897 | retval |= state->SIOCNT; |
| 898 | 898 | } |
| 899 | 899 | if( (mem_mask) & 0xffff0000 ) |
| 900 | 900 | { |
| 901 | | verboselog(machine, 2, "GBA IO Register Read: SIODATA8 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->SIODATA8 ); |
| 902 | | retval |= gba_state->SIODATA8 << 16; |
| 901 | verboselog(machine, 2, "GBA IO Register Read: SIODATA8 (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->SIODATA8 ); |
| 902 | retval |= state->SIODATA8 << 16; |
| 903 | 903 | } |
| 904 | 904 | break; |
| 905 | 905 | case 0x0130/4: |
| r7509 | r7510 | |
| 909 | 909 | } |
| 910 | 910 | if( (mem_mask) & 0xffff0000 ) |
| 911 | 911 | { |
| 912 | | verboselog(machine, 2, "GBA IO Register Read: KEYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->KEYCNT ); |
| 913 | | retval |= gba_state->KEYCNT << 16; |
| 912 | verboselog(machine, 2, "GBA IO Register Read: KEYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->KEYCNT ); |
| 913 | retval |= state->KEYCNT << 16; |
| 914 | 914 | } |
| 915 | 915 | break; |
| 916 | 916 | case 0x0134/4: |
| 917 | 917 | if( (mem_mask) & 0x0000ffff ) |
| 918 | 918 | { |
| 919 | | verboselog(machine, 2, "GBA IO Register Read: RCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->RCNT ); |
| 920 | | retval |= gba_state->RCNT; |
| 919 | verboselog(machine, 2, "GBA IO Register Read: RCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->RCNT ); |
| 920 | retval |= state->RCNT; |
| 921 | 921 | } |
| 922 | 922 | if( (mem_mask) & 0xffff0000 ) |
| 923 | 923 | { |
| r7509 | r7510 | |
| 927 | 927 | case 0x0140/4: |
| 928 | 928 | if( (mem_mask) & 0x0000ffff ) |
| 929 | 929 | { |
| 930 | | verboselog(machine, 2, "GBA IO Register Read: JOYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOYCNT ); |
| 931 | | retval |= gba_state->JOYCNT; |
| 930 | verboselog(machine, 2, "GBA IO Register Read: JOYCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOYCNT ); |
| 931 | retval |= state->JOYCNT; |
| 932 | 932 | } |
| 933 | 933 | if( (mem_mask) & 0xffff0000 ) |
| 934 | 934 | { |
| r7509 | r7510 | |
| 938 | 938 | case 0x0150/4: |
| 939 | 939 | if( (mem_mask) & 0x0000ffff ) |
| 940 | 940 | { |
| 941 | | verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOY_RECV & 0x0000ffff ); |
| 942 | | retval |= gba_state->JOY_RECV & 0x0000ffff; |
| 941 | verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOY_RECV & 0x0000ffff ); |
| 942 | retval |= state->JOY_RECV & 0x0000ffff; |
| 943 | 943 | } |
| 944 | 944 | if( (mem_mask) & 0xffff0000 ) |
| 945 | 945 | { |
| 946 | | verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( gba_state->JOY_RECV & 0xffff0000 ) >> 16 ); |
| 947 | | retval |= gba_state->JOY_RECV & 0xffff0000; |
| 946 | verboselog(machine, 2, "GBA IO Register Read: JOY_RECV_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( state->JOY_RECV & 0xffff0000 ) >> 16 ); |
| 947 | retval |= state->JOY_RECV & 0xffff0000; |
| 948 | 948 | } |
| 949 | 949 | break; |
| 950 | 950 | case 0x0154/4: |
| 951 | 951 | if( (mem_mask) & 0x0000ffff ) |
| 952 | 952 | { |
| 953 | | verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOY_TRANS & 0x0000ffff ); |
| 954 | | retval |= gba_state->JOY_TRANS & 0x0000ffff; |
| 953 | verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_LSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOY_TRANS & 0x0000ffff ); |
| 954 | retval |= state->JOY_TRANS & 0x0000ffff; |
| 955 | 955 | } |
| 956 | 956 | if( (mem_mask) & 0xffff0000 ) |
| 957 | 957 | { |
| 958 | | verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( gba_state->JOY_TRANS & 0xffff0000 ) >> 16 ); |
| 959 | | retval |= gba_state->JOY_TRANS & 0xffff0000; |
| 958 | verboselog(machine, 2, "GBA IO Register Read: JOY_TRANS_MSW (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, ( state->JOY_TRANS & 0xffff0000 ) >> 16 ); |
| 959 | retval |= state->JOY_TRANS & 0xffff0000; |
| 960 | 960 | } |
| 961 | 961 | break; |
| 962 | 962 | case 0x0158/4: |
| 963 | 963 | if( (mem_mask) & 0x0000ffff ) |
| 964 | 964 | { |
| 965 | | verboselog(machine, 2, "GBA IO Register Read: JOYSTAT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->JOYSTAT ); |
| 966 | | retval |= gba_state->JOYSTAT; |
| 965 | verboselog(machine, 2, "GBA IO Register Read: JOYSTAT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->JOYSTAT ); |
| 966 | retval |= state->JOYSTAT; |
| 967 | 967 | } |
| 968 | 968 | if( (mem_mask) & 0xffff0000 ) |
| 969 | 969 | { |
| r7509 | r7510 | |
| 973 | 973 | case 0x0200/4: |
| 974 | 974 | if( (mem_mask) & 0x0000ffff ) |
| 975 | 975 | { |
| 976 | | // printf("Read: IE (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->IE ); |
| 976 | // printf("Read: IE (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->IE ); |
| 977 | 977 | } |
| 978 | 978 | if( (mem_mask) & 0xffff0000 ) |
| 979 | 979 | { |
| 980 | | verboselog(machine, 2, "GBA IO Register Read: IF (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, gba_state->IF ); |
| 980 | verboselog(machine, 2, "GBA IO Register Read: IF (%08x) = %04x\n", 0x04000000 + ( offset << 2 ) + 2, state->IF ); |
| 981 | 981 | } |
| 982 | 982 | |
| 983 | | retval = gba_state->IE | (gba_state->IF<<16); |
| 983 | retval = state->IE | (state->IF<<16); |
| 984 | 984 | break; |
| 985 | 985 | case 0x0204/4: |
| 986 | 986 | if( (mem_mask) & 0x0000ffff ) |
| 987 | 987 | { |
| 988 | | verboselog(machine, 2, "GBA IO Register Read: WAITCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->WAITCNT ); |
| 989 | | retval |= gba_state->WAITCNT; |
| 988 | verboselog(machine, 2, "GBA IO Register Read: WAITCNT (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->WAITCNT ); |
| 989 | retval |= state->WAITCNT; |
| 990 | 990 | } |
| 991 | 991 | if( (mem_mask) & 0xffff0000 ) |
| 992 | 992 | { |
| r7509 | r7510 | |
| 996 | 996 | case 0x0208/4: |
| 997 | 997 | if( (mem_mask) & 0x0000ffff ) |
| 998 | 998 | { |
| 999 | | verboselog(machine, 2, "GBA IO Register Read: IME (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), gba_state->IME ); |
| 1000 | | retval |= gba_state->IME; |
| 999 | verboselog(machine, 2, "GBA IO Register Read: IME (%08x) = %04x\n", 0x04000000 + ( offset << 2 ), state->IME ); |
| 1000 | retval |= state->IME; |
| 1001 | 1001 | } |
| 1002 | 1002 | if( (mem_mask) & 0xffff0000 ) |
| 1003 | 1003 | { |
| r7509 | r7510 | |
| 1005 | 1005 | } |
| 1006 | 1006 | break; |
| 1007 | 1007 | case 0x0300/4: |
| 1008 | | retval = gba_state->HALTCNT << 8; |
| 1008 | retval = state->HALTCNT << 8; |
| 1009 | 1009 | break; |
| 1010 | 1010 | default: |
| 1011 | 1011 | // verboselog(machine, 0, "Unknown GBA I/O register Read: %08x (%08x)\n", 0x04000000 + ( offset << 2 ), ~mem_mask ); |
| r7509 | r7510 | |
| 1018 | 1018 | { |
| 1019 | 1019 | running_machine *machine = space->machine; |
| 1020 | 1020 | running_device *gb_device = devtag_get_device(space->machine, "custom"); |
| 1021 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 1021 | gba_state *state = (gba_state *)machine->driver_data; |
| 1022 | 1022 | |
| 1023 | 1023 | switch( offset ) |
| 1024 | 1024 | { |
| r7509 | r7510 | |
| 1026 | 1026 | if( (mem_mask) & 0x0000ffff ) |
| 1027 | 1027 | { |
| 1028 | 1028 | verboselog(machine, 2, "GBA IO Register Write: DISPCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1029 | | gba_state->DISPCNT = ( gba_state->DISPCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1030 | | if(gba_state->DISPCNT & (DISPCNT_WIN0_EN | DISPCNT_WIN1_EN)) |
| 1029 | state->DISPCNT = ( state->DISPCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1030 | if(state->DISPCNT & (DISPCNT_WIN0_EN | DISPCNT_WIN1_EN)) |
| 1031 | 1031 | { |
| 1032 | | gba_state->windowOn = 1; |
| 1032 | state->windowOn = 1; |
| 1033 | 1033 | } |
| 1034 | 1034 | else |
| 1035 | 1035 | { |
| 1036 | | gba_state->windowOn = 0; |
| 1036 | state->windowOn = 0; |
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | 1039 | if( (mem_mask) & 0xffff0000 ) |
| 1040 | 1040 | { |
| 1041 | 1041 | verboselog(machine, 2, "GBA IO Register Write: Green Swap (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1042 | | gba_state->GRNSWAP = ( gba_state->GRNSWAP & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1042 | state->GRNSWAP = ( state->GRNSWAP & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1043 | 1043 | } |
| 1044 | 1044 | break; |
| 1045 | 1045 | case 0x0004/4: |
| 1046 | | COMBINE_DATA(&gba_state->DISPSTAT); |
| 1046 | COMBINE_DATA(&state->DISPSTAT); |
| 1047 | 1047 | break; |
| 1048 | 1048 | case 0x0008/4: |
| 1049 | 1049 | if( (mem_mask) & 0x0000ffff ) |
| 1050 | 1050 | { |
| 1051 | 1051 | verboselog(machine, 2, "GBA IO Register Write: BG0CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1052 | | gba_state->BG0CNT = ( gba_state->BG0CNT & ~mem_mask ) | ( data & mem_mask ); |
| 1052 | state->BG0CNT = ( state->BG0CNT & ~mem_mask ) | ( data & mem_mask ); |
| 1053 | 1053 | } |
| 1054 | 1054 | if( (mem_mask) & 0xffff0000 ) |
| 1055 | 1055 | { |
| 1056 | 1056 | verboselog(machine, 2, "GBA IO Register Write: BG1CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1057 | | gba_state->BG1CNT = ( gba_state->BG1CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1057 | state->BG1CNT = ( state->BG1CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1058 | 1058 | } |
| 1059 | 1059 | break; |
| 1060 | 1060 | case 0x000c/4: |
| 1061 | 1061 | if( (mem_mask) & 0x0000ffff ) |
| 1062 | 1062 | { |
| 1063 | 1063 | verboselog(machine, 2, "GBA IO Register Write: BG2CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1064 | | gba_state->BG2CNT = ( gba_state->BG2CNT & ~mem_mask ) | ( data & mem_mask ); |
| 1064 | state->BG2CNT = ( state->BG2CNT & ~mem_mask ) | ( data & mem_mask ); |
| 1065 | 1065 | } |
| 1066 | 1066 | if( (mem_mask) & 0xffff0000 ) |
| 1067 | 1067 | { |
| 1068 | 1068 | verboselog(machine, 2, "GBA IO Register Write: BG3CNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1069 | | gba_state->BG3CNT = ( gba_state->BG3CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1069 | state->BG3CNT = ( state->BG3CNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1070 | 1070 | } |
| 1071 | 1071 | break; |
| 1072 | 1072 | case 0x0010/4: |
| 1073 | 1073 | if( (mem_mask) & 0x0000ffff ) |
| 1074 | 1074 | { |
| 1075 | 1075 | verboselog(machine, 2, "GBA IO Register Write: BG0HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1076 | | gba_state->BG0HOFS = ( gba_state->BG0HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1076 | state->BG0HOFS = ( state->BG0HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1077 | 1077 | } |
| 1078 | 1078 | if( (mem_mask) & 0xffff0000 ) |
| 1079 | 1079 | { |
| 1080 | 1080 | verboselog(machine, 2, "GBA IO Register Write: BG0VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1081 | | gba_state->BG0VOFS = ( gba_state->BG0VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1081 | state->BG0VOFS = ( state->BG0VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1082 | 1082 | } |
| 1083 | 1083 | break; |
| 1084 | 1084 | case 0x0014/4: |
| 1085 | 1085 | if( (mem_mask) & 0x0000ffff ) |
| 1086 | 1086 | { |
| 1087 | 1087 | verboselog(machine, 2, "GBA IO Register Write: BG1HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1088 | | gba_state->BG1HOFS = ( gba_state->BG1HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1088 | state->BG1HOFS = ( state->BG1HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1089 | 1089 | } |
| 1090 | 1090 | if( (mem_mask) & 0xffff0000 ) |
| 1091 | 1091 | { |
| 1092 | 1092 | verboselog(machine, 2, "GBA IO Register Write: BG1VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1093 | | gba_state->BG1VOFS = ( gba_state->BG1VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1093 | state->BG1VOFS = ( state->BG1VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1094 | 1094 | } |
| 1095 | 1095 | break; |
| 1096 | 1096 | case 0x0018/4: |
| 1097 | 1097 | if( (mem_mask) & 0x0000ffff ) |
| 1098 | 1098 | { |
| 1099 | 1099 | verboselog(machine, 2, "GBA IO Register Write: BG2HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1100 | | gba_state->BG2HOFS = ( gba_state->BG2HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1100 | state->BG2HOFS = ( state->BG2HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1101 | 1101 | } |
| 1102 | 1102 | if( (mem_mask) & 0xffff0000 ) |
| 1103 | 1103 | { |
| 1104 | 1104 | verboselog(machine, 2, "GBA IO Register Write: BG2VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1105 | | gba_state->BG2VOFS = ( gba_state->BG2VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1105 | state->BG2VOFS = ( state->BG2VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1106 | 1106 | } |
| 1107 | 1107 | break; |
| 1108 | 1108 | case 0x001c/4: |
| 1109 | 1109 | if( (mem_mask) & 0x0000ffff ) |
| 1110 | 1110 | { |
| 1111 | 1111 | verboselog(machine, 2, "GBA IO Register Write: BG3HOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1112 | | gba_state->BG3HOFS = ( gba_state->BG3HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1112 | state->BG3HOFS = ( state->BG3HOFS & ~mem_mask ) | ( data & mem_mask ); |
| 1113 | 1113 | } |
| 1114 | 1114 | if( (mem_mask) & 0xffff0000 ) |
| 1115 | 1115 | { |
| 1116 | 1116 | verboselog(machine, 2, "GBA IO Register Write: BG3VOFS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1117 | | gba_state->BG3VOFS = ( gba_state->BG3VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1117 | state->BG3VOFS = ( state->BG3VOFS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1118 | 1118 | } |
| 1119 | 1119 | break; |
| 1120 | 1120 | case 0x0020/4: |
| 1121 | 1121 | if( (mem_mask) & 0x0000ffff ) |
| 1122 | 1122 | { |
| 1123 | 1123 | verboselog(machine, 2, "GBA IO Register Write: BG2PA (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1124 | | gba_state->BG2PA = ( gba_state->BG2PA & ~mem_mask ) | ( data & mem_mask ); |
| 1124 | state->BG2PA = ( state->BG2PA & ~mem_mask ) | ( data & mem_mask ); |
| 1125 | 1125 | } |
| 1126 | 1126 | if( (mem_mask) & 0xffff0000 ) |
| 1127 | 1127 | { |
| 1128 | 1128 | verboselog(machine, 2, "GBA IO Register Write: BG2PB (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1129 | | gba_state->BG2PB = ( gba_state->BG2PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1129 | state->BG2PB = ( state->BG2PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1130 | 1130 | } |
| 1131 | 1131 | break; |
| 1132 | 1132 | case 0x0024/4: |
| 1133 | 1133 | if( (mem_mask) & 0x0000ffff ) |
| 1134 | 1134 | { |
| 1135 | 1135 | verboselog(machine, 2, "GBA IO Register Write: BG2PC (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1136 | | gba_state->BG2PC = ( gba_state->BG2PC & ~mem_mask ) | ( data & mem_mask ); |
| 1136 | state->BG2PC = ( state->BG2PC & ~mem_mask ) | ( data & mem_mask ); |
| 1137 | 1137 | } |
| 1138 | 1138 | if( (mem_mask) & 0xffff0000 ) |
| 1139 | 1139 | { |
| 1140 | 1140 | verboselog(machine, 2, "GBA IO Register Write: BG2PD (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1141 | | gba_state->BG2PD = ( gba_state->BG2PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1141 | state->BG2PD = ( state->BG2PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1142 | 1142 | } |
| 1143 | 1143 | break; |
| 1144 | 1144 | case 0x0028/4: |
| r7509 | r7510 | |
| 1150 | 1150 | { |
| 1151 | 1151 | verboselog(machine, 2, "GBA IO Register Write: BG2X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1152 | 1152 | } |
| 1153 | | COMBINE_DATA(&gba_state->BG2X); |
| 1154 | | gba_state->gfxBG2Changed |= 1; |
| 1153 | COMBINE_DATA(&state->BG2X); |
| 1154 | state->gfxBG2Changed |= 1; |
| 1155 | 1155 | break; |
| 1156 | 1156 | case 0x002c/4: |
| 1157 | 1157 | if( (mem_mask) & 0x0000ffff ) |
| r7509 | r7510 | |
| 1162 | 1162 | { |
| 1163 | 1163 | verboselog(machine, 2, "GBA IO Register Write: BG2Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1164 | 1164 | } |
| 1165 | | COMBINE_DATA(&gba_state->BG2Y); |
| 1166 | | gba_state->gfxBG2Changed |= 2; |
| 1165 | COMBINE_DATA(&state->BG2Y); |
| 1166 | state->gfxBG2Changed |= 2; |
| 1167 | 1167 | break; |
| 1168 | 1168 | case 0x0030/4: |
| 1169 | 1169 | if( (mem_mask) & 0x0000ffff ) |
| 1170 | 1170 | { |
| 1171 | 1171 | verboselog(machine, 2, "GBA IO Register Write: BG3PA (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1172 | | gba_state->BG3PA = ( gba_state->BG3PA & ~mem_mask ) | ( data & mem_mask ); |
| 1172 | state->BG3PA = ( state->BG3PA & ~mem_mask ) | ( data & mem_mask ); |
| 1173 | 1173 | } |
| 1174 | 1174 | if( (mem_mask) & 0xffff0000 ) |
| 1175 | 1175 | { |
| 1176 | 1176 | verboselog(machine, 2, "GBA IO Register Write: BG3PB (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1177 | | gba_state->BG3PB = ( gba_state->BG3PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1177 | state->BG3PB = ( state->BG3PB & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1178 | 1178 | } |
| 1179 | 1179 | break; |
| 1180 | 1180 | case 0x0034/4: |
| 1181 | 1181 | if( (mem_mask) & 0x0000ffff ) |
| 1182 | 1182 | { |
| 1183 | 1183 | verboselog(machine, 2, "GBA IO Register Write: BG3PC (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1184 | | gba_state->BG3PC = ( gba_state->BG3PC & ~mem_mask ) | ( data & mem_mask ); |
| 1184 | state->BG3PC = ( state->BG3PC & ~mem_mask ) | ( data & mem_mask ); |
| 1185 | 1185 | } |
| 1186 | 1186 | if( (mem_mask) & 0xffff0000 ) |
| 1187 | 1187 | { |
| 1188 | 1188 | verboselog(machine, 2, "GBA IO Register Write: BG3PD (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1189 | | gba_state->BG3PD = ( gba_state->BG3PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1189 | state->BG3PD = ( state->BG3PD & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1190 | 1190 | } |
| 1191 | 1191 | break; |
| 1192 | 1192 | case 0x0038/4: |
| r7509 | r7510 | |
| 1198 | 1198 | { |
| 1199 | 1199 | verboselog(machine, 2, "GBA IO Register Write: BG3X_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1200 | 1200 | } |
| 1201 | | COMBINE_DATA(&gba_state->BG3X); |
| 1202 | | gba_state->gfxBG3Changed |= 1; |
| 1201 | COMBINE_DATA(&state->BG3X); |
| 1202 | state->gfxBG3Changed |= 1; |
| 1203 | 1203 | break; |
| 1204 | 1204 | case 0x003c/4: |
| 1205 | 1205 | if( (mem_mask) & 0x0000ffff ) |
| r7509 | r7510 | |
| 1210 | 1210 | { |
| 1211 | 1211 | verboselog(machine, 2, "GBA IO Register Write: BG3Y_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1212 | 1212 | } |
| 1213 | | COMBINE_DATA(&gba_state->BG3Y); |
| 1214 | | gba_state->gfxBG3Changed |= 2; |
| 1213 | COMBINE_DATA(&state->BG3Y); |
| 1214 | state->gfxBG3Changed |= 2; |
| 1215 | 1215 | break; |
| 1216 | 1216 | case 0x0040/4: |
| 1217 | 1217 | if( (mem_mask) & 0x0000ffff ) |
| 1218 | 1218 | { |
| 1219 | 1219 | verboselog(machine, 2, "GBA IO Register Write: WIN0H (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1220 | | gba_state->WIN0H = ( gba_state->WIN0H & ~mem_mask ) | ( data & mem_mask ); |
| 1220 | state->WIN0H = ( state->WIN0H & ~mem_mask ) | ( data & mem_mask ); |
| 1221 | 1221 | } |
| 1222 | 1222 | if( (mem_mask) & 0xffff0000 ) |
| 1223 | 1223 | { |
| 1224 | 1224 | verboselog(machine, 2, "GBA IO Register Write: WIN1H (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1225 | | gba_state->WIN1H = ( gba_state->WIN1H & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1225 | state->WIN1H = ( state->WIN1H & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1226 | 1226 | } |
| 1227 | 1227 | break; |
| 1228 | 1228 | case 0x0044/4: |
| 1229 | 1229 | if( (mem_mask) & 0x0000ffff ) |
| 1230 | 1230 | { |
| 1231 | 1231 | verboselog(machine, 2, "GBA IO Register Write: WIN0V (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1232 | | gba_state->WIN0V = ( gba_state->WIN0V & ~mem_mask ) | ( data & mem_mask ); |
| 1232 | state->WIN0V = ( state->WIN0V & ~mem_mask ) | ( data & mem_mask ); |
| 1233 | 1233 | } |
| 1234 | 1234 | if( (mem_mask) & 0xffff0000 ) |
| 1235 | 1235 | { |
| 1236 | 1236 | verboselog(machine, 2, "GBA IO Register Write: WIN1V (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1237 | | gba_state->WIN1V = ( gba_state->WIN1V & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1237 | state->WIN1V = ( state->WIN1V & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1238 | 1238 | } |
| 1239 | 1239 | break; |
| 1240 | 1240 | case 0x0048/4: |
| 1241 | 1241 | if( (mem_mask) & 0x0000ffff ) |
| 1242 | 1242 | { |
| 1243 | 1243 | verboselog(machine, 2, "GBA IO Register Write: WININ (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1244 | | gba_state->WININ = ( gba_state->WININ & ~mem_mask ) | ( data & mem_mask ); |
| 1244 | state->WININ = ( state->WININ & ~mem_mask ) | ( data & mem_mask ); |
| 1245 | 1245 | } |
| 1246 | 1246 | if( (mem_mask) & 0xffff0000 ) |
| 1247 | 1247 | { |
| 1248 | 1248 | verboselog(machine, 2, "GBA IO Register Write: WINOUT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1249 | | gba_state->WINOUT = ( gba_state->WINOUT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1249 | state->WINOUT = ( state->WINOUT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1250 | 1250 | } |
| 1251 | 1251 | break; |
| 1252 | 1252 | case 0x004c/4: |
| 1253 | 1253 | if( (mem_mask) & 0x0000ffff ) |
| 1254 | 1254 | { |
| 1255 | 1255 | verboselog(machine, 2, "GBA IO Register Write: MOSAIC (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1256 | | gba_state->MOSAIC = ( gba_state->MOSAIC & ~mem_mask ) | ( data & mem_mask ); |
| 1256 | state->MOSAIC = ( state->MOSAIC & ~mem_mask ) | ( data & mem_mask ); |
| 1257 | 1257 | } |
| 1258 | 1258 | if( (mem_mask) & 0xffff0000 ) |
| 1259 | 1259 | { |
| r7509 | r7510 | |
| 1264 | 1264 | if( (mem_mask) & 0x0000ffff ) |
| 1265 | 1265 | { |
| 1266 | 1266 | verboselog(machine, 2, "GBA IO Register Write: BLDCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1267 | | gba_state->BLDCNT = ( gba_state->BLDCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1268 | | if(gba_state->BLDCNT & BLDCNT_SFX) |
| 1267 | state->BLDCNT = ( state->BLDCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1268 | if(state->BLDCNT & BLDCNT_SFX) |
| 1269 | 1269 | { |
| 1270 | | gba_state->fxOn = 1; |
| 1270 | state->fxOn = 1; |
| 1271 | 1271 | } |
| 1272 | 1272 | else |
| 1273 | 1273 | { |
| 1274 | | gba_state->fxOn = 0; |
| 1274 | state->fxOn = 0; |
| 1275 | 1275 | } |
| 1276 | 1276 | } |
| 1277 | 1277 | if( (mem_mask) & 0xffff0000 ) |
| 1278 | 1278 | { |
| 1279 | 1279 | verboselog(machine, 2, "GBA IO Register Write: BLDALPHA (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & 0xffff0000 ) >> 16, ~mem_mask ); |
| 1280 | | gba_state->BLDALPHA = ( gba_state->BLDALPHA & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1280 | state->BLDALPHA = ( state->BLDALPHA & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1281 | 1281 | } |
| 1282 | 1282 | break; |
| 1283 | 1283 | case 0x0054/4: |
| 1284 | 1284 | if( (mem_mask) & 0x0000ffff ) |
| 1285 | 1285 | { |
| 1286 | 1286 | verboselog(machine, 2, "GBA IO Register Write: BLDY (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1287 | | gba_state->BLDY = ( gba_state->BLDY & ~mem_mask ) | ( data & mem_mask ); |
| 1287 | state->BLDY = ( state->BLDY & ~mem_mask ) | ( data & mem_mask ); |
| 1288 | 1288 | } |
| 1289 | 1289 | if( (mem_mask) & 0xffff0000 ) |
| 1290 | 1290 | { |
| r7509 | r7510 | |
| 1412 | 1412 | if ((mem_mask) & 0xffff0000) |
| 1413 | 1413 | { |
| 1414 | 1414 | data >>= 16; |
| 1415 | | gba_state->SOUNDCNT_H = data; |
| 1415 | state->SOUNDCNT_H = data; |
| 1416 | 1416 | |
| 1417 | 1417 | // DAC A reset? |
| 1418 | 1418 | if (data & 0x0800) |
| r7509 | r7510 | |
| 1420 | 1420 | running_device *gb_a_l = devtag_get_device(machine, "direct_a_left"); |
| 1421 | 1421 | running_device *gb_a_r = devtag_get_device(machine, "direct_a_right"); |
| 1422 | 1422 | |
| 1423 | | gba_state->fifo_a_ptr = 17; |
| 1424 | | gba_state->fifo_a_in = 17; |
| 1423 | state->fifo_a_ptr = 17; |
| 1424 | state->fifo_a_in = 17; |
| 1425 | 1425 | dac_signed_data_w(gb_a_l, 0x80); |
| 1426 | 1426 | dac_signed_data_w(gb_a_r, 0x80); |
| 1427 | 1427 | } |
| r7509 | r7510 | |
| 1432 | 1432 | running_device *gb_b_l = devtag_get_device(machine, "direct_b_left"); |
| 1433 | 1433 | running_device *gb_b_r = devtag_get_device(machine, "direct_b_right"); |
| 1434 | 1434 | |
| 1435 | | gba_state->fifo_b_ptr = 17; |
| 1436 | | gba_state->fifo_b_in = 17; |
| 1435 | state->fifo_b_ptr = 17; |
| 1436 | state->fifo_b_in = 17; |
| 1437 | 1437 | dac_signed_data_w(gb_b_l, 0x80); |
| 1438 | 1438 | dac_signed_data_w(gb_b_r, 0x80); |
| 1439 | 1439 | } |
| r7509 | r7510 | |
| 1448 | 1448 | running_device *gb_b_r = devtag_get_device(machine, "direct_b_right"); |
| 1449 | 1449 | |
| 1450 | 1450 | gb_sound_w(gb_device, 0x16, data); |
| 1451 | | if ((data & 0x80) && !(gba_state->SOUNDCNT_X & 0x80)) |
| 1451 | if ((data & 0x80) && !(state->SOUNDCNT_X & 0x80)) |
| 1452 | 1452 | { |
| 1453 | | gba_state->fifo_a_ptr = gba_state->fifo_a_in = 17; |
| 1454 | | gba_state->fifo_b_ptr = gba_state->fifo_b_in = 17; |
| 1453 | state->fifo_a_ptr = state->fifo_a_in = 17; |
| 1454 | state->fifo_b_ptr = state->fifo_b_in = 17; |
| 1455 | 1455 | dac_signed_data_w(gb_a_l, 0x80); |
| 1456 | 1456 | dac_signed_data_w(gb_a_r, 0x80); |
| 1457 | 1457 | dac_signed_data_w(gb_b_l, 0x80); |
| 1458 | 1458 | dac_signed_data_w(gb_b_r, 0x80); |
| 1459 | 1459 | } |
| 1460 | | gba_state->SOUNDCNT_X = data; |
| 1460 | state->SOUNDCNT_X = data; |
| 1461 | 1461 | } |
| 1462 | 1462 | break; |
| 1463 | 1463 | case 0x0088/4: |
| 1464 | 1464 | if( (mem_mask) & 0x0000ffff ) |
| 1465 | 1465 | { |
| 1466 | 1466 | verboselog(machine, 2, "GBA IO Register Write: SOUNDBIAS (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x0000ffff, ~mem_mask ); |
| 1467 | | gba_state->SOUNDBIAS = ( gba_state->SOUNDBIAS & ~mem_mask ) | ( data & mem_mask ); |
| 1467 | state->SOUNDBIAS = ( state->SOUNDBIAS & ~mem_mask ) | ( data & mem_mask ); |
| 1468 | 1468 | } |
| 1469 | 1469 | if( (mem_mask) & 0xffff0000 ) |
| 1470 | 1470 | { |
| r7509 | r7510 | |
| 1544 | 1544 | } |
| 1545 | 1545 | break; |
| 1546 | 1546 | case 0x00a0/4: |
| 1547 | | gba_state->fifo_a_in %= 17; |
| 1548 | | gba_state->fifo_a[gba_state->fifo_a_in++] = (data)&0xff; |
| 1549 | | gba_state->fifo_a_in %= 17; |
| 1550 | | gba_state->fifo_a[gba_state->fifo_a_in++] = (data>>8)&0xff; |
| 1551 | | gba_state->fifo_a_in %= 17; |
| 1552 | | gba_state->fifo_a[gba_state->fifo_a_in++] = (data>>16)&0xff; |
| 1553 | | gba_state->fifo_a_in %= 17; |
| 1554 | | gba_state->fifo_a[gba_state->fifo_a_in++] = (data>>24)&0xff; |
| 1547 | state->fifo_a_in %= 17; |
| 1548 | state->fifo_a[state->fifo_a_in++] = (data)&0xff; |
| 1549 | state->fifo_a_in %= 17; |
| 1550 | state->fifo_a[state->fifo_a_in++] = (data>>8)&0xff; |
| 1551 | state->fifo_a_in %= 17; |
| 1552 | state->fifo_a[state->fifo_a_in++] = (data>>16)&0xff; |
| 1553 | state->fifo_a_in %= 17; |
| 1554 | state->fifo_a[state->fifo_a_in++] = (data>>24)&0xff; |
| 1555 | 1555 | break; |
| 1556 | 1556 | case 0x00a4/4: |
| 1557 | | gba_state->fifo_b_in %= 17; |
| 1558 | | gba_state->fifo_b[gba_state->fifo_b_in++] = (data)&0xff; |
| 1559 | | gba_state->fifo_b_in %= 17; |
| 1560 | | gba_state->fifo_b[gba_state->fifo_b_in++] = (data>>8)&0xff; |
| 1561 | | gba_state->fifo_b_in %= 17; |
| 1562 | | gba_state->fifo_b[gba_state->fifo_b_in++] = (data>>16)&0xff; |
| 1563 | | gba_state->fifo_b_in %= 17; |
| 1564 | | gba_state->fifo_b[gba_state->fifo_b_in++] = (data>>24)&0xff; |
| 1557 | state->fifo_b_in %= 17; |
| 1558 | state->fifo_b[state->fifo_b_in++] = (data)&0xff; |
| 1559 | state->fifo_b_in %= 17; |
| 1560 | state->fifo_b[state->fifo_b_in++] = (data>>8)&0xff; |
| 1561 | state->fifo_b_in %= 17; |
| 1562 | state->fifo_b[state->fifo_b_in++] = (data>>16)&0xff; |
| 1563 | state->fifo_b_in %= 17; |
| 1564 | state->fifo_b[state->fifo_b_in++] = (data>>24)&0xff; |
| 1565 | 1565 | break; |
| 1566 | 1566 | case 0x00b0/4: |
| 1567 | 1567 | case 0x00b4/4: |
| r7509 | r7510 | |
| 1594 | 1594 | // retrigger/restart on a rising edge. |
| 1595 | 1595 | // also reload internal regs |
| 1596 | 1596 | // (note: Metroid Fusion fails if we enforce the "rising edge" requirement...) |
| 1597 | | if (ctrl & 0x8000) //&& !(gba_state->dma_regs[offset] & 0x80000000)) |
| 1597 | if (ctrl & 0x8000) //&& !(state->dma_regs[offset] & 0x80000000)) |
| 1598 | 1598 | { |
| 1599 | | gba_state->dma_src[ch] = gba_state->dma_regs[(ch*3)+0]; |
| 1600 | | gba_state->dma_dst[ch] = gba_state->dma_regs[(ch*3)+1]; |
| 1601 | | gba_state->dma_srcadd[ch] = (ctrl>>7)&3; |
| 1602 | | gba_state->dma_dstadd[ch] = (ctrl>>5)&3; |
| 1599 | state->dma_src[ch] = state->dma_regs[(ch*3)+0]; |
| 1600 | state->dma_dst[ch] = state->dma_regs[(ch*3)+1]; |
| 1601 | state->dma_srcadd[ch] = (ctrl>>7)&3; |
| 1602 | state->dma_dstadd[ch] = (ctrl>>5)&3; |
| 1603 | 1603 | |
| 1604 | | COMBINE_DATA(&gba_state->dma_regs[offset]); |
| 1605 | | gba_state->dma_cnt[ch] = gba_state->dma_regs[(ch*3)+2]&0xffff; |
| 1604 | COMBINE_DATA(&state->dma_regs[offset]); |
| 1605 | state->dma_cnt[ch] = state->dma_regs[(ch*3)+2]&0xffff; |
| 1606 | 1606 | |
| 1607 | 1607 | // immediate start |
| 1608 | 1608 | if ((ctrl & 0x3000) == 0) |
| r7509 | r7510 | |
| 1613 | 1613 | } |
| 1614 | 1614 | } |
| 1615 | 1615 | |
| 1616 | | COMBINE_DATA(&gba_state->dma_regs[offset]); |
| 1616 | COMBINE_DATA(&state->dma_regs[offset]); |
| 1617 | 1617 | } |
| 1618 | 1618 | break; |
| 1619 | 1619 | case 0x0100/4: |
| r7509 | r7510 | |
| 1625 | 1625 | |
| 1626 | 1626 | offset -= (0x100/4); |
| 1627 | 1627 | |
| 1628 | | COMBINE_DATA(&gba_state->timer_regs[offset]); |
| 1628 | COMBINE_DATA(&state->timer_regs[offset]); |
| 1629 | 1629 | |
| 1630 | 1630 | // printf("%x to timer %d (mask %x PC %x)\n", data, offset, ~mem_mask, cpu_get_pc(space->cpu)); |
| 1631 | 1631 | |
| 1632 | 1632 | if (ACCESSING_BITS_0_15) |
| 1633 | 1633 | { |
| 1634 | | gba_state->timer_reload[offset] = ( gba_state->timer_reload[offset] & ~mem_mask ) | ( ( data & 0x0000ffff ) & mem_mask ); |
| 1634 | state->timer_reload[offset] = ( state->timer_reload[offset] & ~mem_mask ) | ( ( data & 0x0000ffff ) & mem_mask ); |
| 1635 | 1635 | } |
| 1636 | 1636 | |
| 1637 | 1637 | // enabling this timer? |
| r7509 | r7510 | |
| 1639 | 1639 | { |
| 1640 | 1640 | double final; |
| 1641 | 1641 | |
| 1642 | | rate = 0x10000 - (gba_state->timer_regs[offset] & 0xffff); |
| 1642 | rate = 0x10000 - (state->timer_regs[offset] & 0xffff); |
| 1643 | 1643 | |
| 1644 | | clocksel = timer_clks[(gba_state->timer_regs[offset] >> 16) & 3]; |
| 1644 | clocksel = timer_clks[(state->timer_regs[offset] >> 16) & 3]; |
| 1645 | 1645 | |
| 1646 | 1646 | final = clocksel / rate; |
| 1647 | 1647 | |
| 1648 | | gba_state->timer_hz[offset] = final; |
| 1648 | state->timer_hz[offset] = final; |
| 1649 | 1649 | |
| 1650 | 1650 | // printf("Enabling timer %d @ %f Hz\n", offset, final); |
| 1651 | 1651 | |
| 1652 | 1652 | // enable the timer |
| 1653 | 1653 | if( !(data & 0x40000) ) // if we're not in Count-Up mode |
| 1654 | 1654 | { |
| 1655 | | timer_adjust_periodic(gba_state->tmr_timer[offset], ATTOTIME_IN_HZ(final), offset, ATTOTIME_IN_HZ(final)); |
| 1655 | timer_adjust_periodic(state->tmr_timer[offset], ATTOTIME_IN_HZ(final), offset, ATTOTIME_IN_HZ(final)); |
| 1656 | 1656 | } |
| 1657 | 1657 | } |
| 1658 | 1658 | } |
| r7509 | r7510 | |
| 1661 | 1661 | if( (mem_mask) & 0x0000ffff ) |
| 1662 | 1662 | { |
| 1663 | 1663 | verboselog(machine, 2, "GBA IO Register Write: SIOMULTI0 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1664 | | gba_state->SIOMULTI0 = ( gba_state->SIOMULTI0 & ~mem_mask ) | ( data & mem_mask ); |
| 1664 | state->SIOMULTI0 = ( state->SIOMULTI0 & ~mem_mask ) | ( data & mem_mask ); |
| 1665 | 1665 | } |
| 1666 | 1666 | if( (mem_mask) & 0xffff0000 ) |
| 1667 | 1667 | { |
| 1668 | 1668 | verboselog(machine, 2, "GBA IO Register Write: SIOMULTI1 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1669 | | gba_state->SIOMULTI1 = ( gba_state->SIOMULTI1 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1669 | state->SIOMULTI1 = ( state->SIOMULTI1 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1670 | 1670 | } |
| 1671 | 1671 | break; |
| 1672 | 1672 | case 0x0124/4: |
| 1673 | 1673 | if( (mem_mask) & 0x0000ffff ) |
| 1674 | 1674 | { |
| 1675 | 1675 | verboselog(machine, 2, "GBA IO Register Write: SIOMULTI2 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1676 | | gba_state->SIOMULTI2 = ( gba_state->SIOMULTI2 & ~mem_mask ) | ( data & mem_mask ); |
| 1676 | state->SIOMULTI2 = ( state->SIOMULTI2 & ~mem_mask ) | ( data & mem_mask ); |
| 1677 | 1677 | } |
| 1678 | 1678 | if( (mem_mask) & 0xffff0000 ) |
| 1679 | 1679 | { |
| 1680 | 1680 | verboselog(machine, 2, "GBA IO Register Write: SIOMULTI3 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1681 | | gba_state->SIOMULTI3 = ( gba_state->SIOMULTI3 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1681 | state->SIOMULTI3 = ( state->SIOMULTI3 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1682 | 1682 | } |
| 1683 | 1683 | break; |
| 1684 | 1684 | case 0x0128/4: |
| 1685 | 1685 | if( (mem_mask) & 0x0000ffff ) |
| 1686 | 1686 | { |
| 1687 | 1687 | verboselog(machine, 2, "GBA IO Register Write: SIOCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1688 | | gba_state->SIOCNT = ( gba_state->SIOCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1688 | state->SIOCNT = ( state->SIOCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1689 | 1689 | } |
| 1690 | 1690 | if( (mem_mask) & 0xffff0000 ) |
| 1691 | 1691 | { |
| 1692 | 1692 | verboselog(machine, 2, "GBA IO Register Write: SIODATA8 (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1693 | | gba_state->SIODATA8 = ( gba_state->SIODATA8 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1693 | state->SIODATA8 = ( state->SIODATA8 & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1694 | 1694 | } |
| 1695 | 1695 | break; |
| 1696 | 1696 | case 0x0130/4: |
| r7509 | r7510 | |
| 1698 | 1698 | { |
| 1699 | 1699 | // printf("KEYCNT = %04x\n", data>>16); |
| 1700 | 1700 | verboselog(machine, 2, "GBA IO Register Write: KEYCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1701 | | gba_state->KEYCNT = ( gba_state->KEYCNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1701 | state->KEYCNT = ( state->KEYCNT & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1702 | 1702 | } |
| 1703 | 1703 | break; |
| 1704 | 1704 | case 0x0134/4: |
| 1705 | 1705 | if( (mem_mask) & 0x0000ffff ) |
| 1706 | 1706 | { |
| 1707 | 1707 | verboselog(machine, 2, "GBA IO Register Write: RCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1708 | | gba_state->RCNT = ( gba_state->RCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1708 | state->RCNT = ( state->RCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1709 | 1709 | } |
| 1710 | 1710 | if( (mem_mask) & 0xffff0000 ) |
| 1711 | 1711 | { |
| 1712 | 1712 | verboselog(machine, 2, "GBA IO Register Write: IR (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1713 | | gba_state->IR = ( gba_state->IR & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1713 | state->IR = ( state->IR & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1714 | 1714 | } |
| 1715 | 1715 | break; |
| 1716 | 1716 | case 0x0140/4: |
| 1717 | 1717 | if( (mem_mask) & 0x0000ffff ) |
| 1718 | 1718 | { |
| 1719 | 1719 | verboselog(machine, 2, "GBA IO Register Write: JOYCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1720 | | gba_state->JOYCNT = ( gba_state->JOYCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1720 | state->JOYCNT = ( state->JOYCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1721 | 1721 | } |
| 1722 | 1722 | if( (mem_mask) & 0xffff0000 ) |
| 1723 | 1723 | { |
| r7509 | r7510 | |
| 1728 | 1728 | if( (mem_mask) & 0x0000ffff ) |
| 1729 | 1729 | { |
| 1730 | 1730 | verboselog(machine, 2, "GBA IO Register Write: JOY_RECV_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1731 | | gba_state->JOY_RECV = ( gba_state->JOY_RECV & ~mem_mask ) | ( data & mem_mask ); |
| 1731 | state->JOY_RECV = ( state->JOY_RECV & ~mem_mask ) | ( data & mem_mask ); |
| 1732 | 1732 | } |
| 1733 | 1733 | if( (mem_mask) & 0xffff0000 ) |
| 1734 | 1734 | { |
| 1735 | 1735 | verboselog(machine, 2, "GBA IO Register Write: JOY_RECV_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1736 | | gba_state->JOY_RECV = ( gba_state->JOY_RECV & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1736 | state->JOY_RECV = ( state->JOY_RECV & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1737 | 1737 | } |
| 1738 | 1738 | break; |
| 1739 | 1739 | case 0x0154/4: |
| 1740 | 1740 | if( (mem_mask) & 0x0000ffff ) |
| 1741 | 1741 | { |
| 1742 | 1742 | verboselog(machine, 2, "GBA IO Register Write: JOY_TRANS_LSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1743 | | gba_state->JOY_TRANS = ( gba_state->JOY_TRANS & ~mem_mask ) | ( data & mem_mask ); |
| 1743 | state->JOY_TRANS = ( state->JOY_TRANS & ~mem_mask ) | ( data & mem_mask ); |
| 1744 | 1744 | } |
| 1745 | 1745 | if( (mem_mask) & 0xffff0000 ) |
| 1746 | 1746 | { |
| 1747 | 1747 | verboselog(machine, 2, "GBA IO Register Write: JOY_TRANS_MSW (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1748 | | gba_state->JOY_TRANS = ( gba_state->JOY_TRANS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1748 | state->JOY_TRANS = ( state->JOY_TRANS & ( ~mem_mask >> 16 ) ) | ( ( data & mem_mask ) >> 16 ); |
| 1749 | 1749 | } |
| 1750 | 1750 | break; |
| 1751 | 1751 | case 0x0158/4: |
| 1752 | 1752 | if( (mem_mask) & 0x0000ffff ) |
| 1753 | 1753 | { |
| 1754 | 1754 | verboselog(machine, 2, "GBA IO Register Write: JOYSTAT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1755 | | gba_state->JOYSTAT = ( gba_state->JOYSTAT & ~mem_mask ) | ( data & mem_mask ); |
| 1755 | state->JOYSTAT = ( state->JOYSTAT & ~mem_mask ) | ( data & mem_mask ); |
| 1756 | 1756 | } |
| 1757 | 1757 | if( (mem_mask) & 0xffff0000 ) |
| 1758 | 1758 | { |
| r7509 | r7510 | |
| 1763 | 1763 | if( (mem_mask) & 0x0000ffff ) |
| 1764 | 1764 | { |
| 1765 | 1765 | // printf("IE (%08x) = %04x raw %x (%08x) (scan %d PC %x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, data, ~mem_mask, video_screen_get_vpos(machine->primary_screen), cpu_get_pc(space->cpu)); |
| 1766 | | gba_state->IE = ( gba_state->IE & ~mem_mask ) | ( data & mem_mask ); |
| 1766 | state->IE = ( state->IE & ~mem_mask ) | ( data & mem_mask ); |
| 1767 | 1767 | #if 0 |
| 1768 | | if (gba_state->IE & gba_state->IF) |
| 1768 | if (state->IE & state->IF) |
| 1769 | 1769 | { |
| 1770 | | gba_request_irq(machine, gba_state->IF); |
| 1770 | gba_request_irq(machine, state->IF); |
| 1771 | 1771 | } |
| 1772 | 1772 | #endif |
| 1773 | 1773 | } |
| 1774 | 1774 | if( (mem_mask) & 0xffff0000 ) |
| 1775 | 1775 | { |
| 1776 | 1776 | verboselog(machine, 2, "GBA IO Register Write: IF (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ) + 2, ( data & mem_mask ) >> 16, ~mem_mask ); |
| 1777 | | gba_state->IF &= ~( ( data & mem_mask ) >> 16 ); |
| 1777 | state->IF &= ~( ( data & mem_mask ) >> 16 ); |
| 1778 | 1778 | |
| 1779 | 1779 | // if we still have interrupts, yank the IRQ line again |
| 1780 | | if (gba_state->IF) |
| 1780 | if (state->IF) |
| 1781 | 1781 | { |
| 1782 | | timer_adjust_oneshot(gba_state->irq_timer, cpu_clocks_to_attotime(devtag_get_device(machine, "maincpu"), 120), 0); |
| 1782 | timer_adjust_oneshot(state->irq_timer, cpu_clocks_to_attotime(devtag_get_device(machine, "maincpu"), 120), 0); |
| 1783 | 1783 | } |
| 1784 | 1784 | } |
| 1785 | 1785 | break; |
| r7509 | r7510 | |
| 1787 | 1787 | if( (mem_mask) & 0x0000ffff ) |
| 1788 | 1788 | { |
| 1789 | 1789 | verboselog(machine, 2, "GBA IO Register Write: WAITCNT (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1790 | | gba_state->WAITCNT = ( gba_state->WAITCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1790 | state->WAITCNT = ( state->WAITCNT & ~mem_mask ) | ( data & mem_mask ); |
| 1791 | 1791 | } |
| 1792 | 1792 | if( (mem_mask) & 0xffff0000 ) |
| 1793 | 1793 | { |
| r7509 | r7510 | |
| 1798 | 1798 | if( (mem_mask) & 0x0000ffff ) |
| 1799 | 1799 | { |
| 1800 | 1800 | verboselog(machine, 3, "GBA IO Register Write: IME (%08x) = %04x (%08x)\n", 0x04000000 + ( offset << 2 ), data & mem_mask, ~mem_mask ); |
| 1801 | | gba_state->IME = ( gba_state->IME & ~mem_mask ) | ( data & mem_mask ); |
| 1802 | | if (gba_state->IF) |
| 1801 | state->IME = ( state->IME & ~mem_mask ) | ( data & mem_mask ); |
| 1802 | if (state->IF) |
| 1803 | 1803 | { |
| 1804 | | timer_adjust_oneshot(gba_state->irq_timer, attotime_zero, 0); |
| 1804 | timer_adjust_oneshot(state->irq_timer, attotime_zero, 0); |
| 1805 | 1805 | } |
| 1806 | 1806 | } |
| 1807 | 1807 | if( (mem_mask) & 0xffff0000 ) |
| r7509 | r7510 | |
| 1815 | 1815 | if( (mem_mask) & 0x000000ff ) |
| 1816 | 1816 | { |
| 1817 | 1817 | verboselog(machine, 2, "GBA IO Register Write: POSTFLG (%08x) = %02x (%08x)\n", 0x04000000 + ( offset << 2 ), data & 0x000000ff, ~mem_mask ); |
| 1818 | | gba_state->POSTFLG = data & 0x000000ff; |
| 1818 | state->POSTFLG = data & 0x000000ff; |
| 1819 | 1819 | } |
| 1820 | 1820 | else |
| 1821 | 1821 | { |
| 1822 | | gba_state->HALTCNT = data & 0x000000ff; |
| 1822 | state->HALTCNT = data & 0x000000ff; |
| 1823 | 1823 | |
| 1824 | 1824 | // either way, wait for an IRQ |
| 1825 | 1825 | cpu_spinuntil_int(devtag_get_device(machine, "maincpu")); |
| r7509 | r7510 | |
| 1866 | 1866 | static WRITE32_HANDLER(gba_pram_w) |
| 1867 | 1867 | { |
| 1868 | 1868 | running_machine *machine = space->machine; |
| 1869 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 1869 | gba_state *state = (gba_state *)machine->driver_data; |
| 1870 | 1870 | |
| 1871 | | gba_state->gba_pram[offset] = COMBINE_DATA32_16(gba_state->gba_pram[offset], data, mem_mask); |
| 1871 | state->gba_pram[offset] = COMBINE_DATA32_16(state->gba_pram[offset], data, mem_mask); |
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | 1874 | static WRITE32_HANDLER(gba_vram_w) |
| 1875 | 1875 | { |
| 1876 | 1876 | running_machine *machine = space->machine; |
| 1877 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 1877 | gba_state *state = (gba_state *)machine->driver_data; |
| 1878 | 1878 | |
| 1879 | | gba_state->gba_vram[offset] = COMBINE_DATA32_16(gba_state->gba_vram[offset], data, mem_mask); |
| 1879 | state->gba_vram[offset] = COMBINE_DATA32_16(state->gba_vram[offset], data, mem_mask); |
| 1880 | 1880 | } |
| 1881 | 1881 | |
| 1882 | 1882 | static WRITE32_HANDLER(gba_oam_w) |
| 1883 | 1883 | { |
| 1884 | 1884 | running_machine *machine = space->machine; |
| 1885 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 1885 | gba_state *state = (gba_state *)machine->driver_data; |
| 1886 | 1886 | |
| 1887 | | gba_state->gba_oam[offset] = COMBINE_DATA32_16(gba_state->gba_oam[offset], data, mem_mask); |
| 1887 | state->gba_oam[offset] = COMBINE_DATA32_16(state->gba_oam[offset], data, mem_mask); |
| 1888 | 1888 | } |
| 1889 | 1889 | |
| 1890 | 1890 | static ADDRESS_MAP_START( gbadvance_map, ADDRESS_SPACE_PROGRAM, 32 ) |
| r7509 | r7510 | |
| 1892 | 1892 | AM_RANGE(0x02000000, 0x0203ffff) AM_RAM AM_MIRROR(0xfc0000) |
| 1893 | 1893 | AM_RANGE(0x03000000, 0x03007fff) AM_RAM AM_MIRROR(0xff8000) |
| 1894 | 1894 | AM_RANGE(0x04000000, 0x040003ff) AM_READWRITE( gba_io_r, gba_io_w ) |
| 1895 | | AM_RANGE(0x05000000, 0x050003ff) AM_RAM_WRITE(gba_pram_w) AM_BASE_MEMBER(gba_state_t, gba_pram) // Palette RAM |
| 1896 | | AM_RANGE(0x06000000, 0x06017fff) AM_RAM_WRITE(gba_vram_w) AM_BASE_MEMBER(gba_state_t, gba_vram) // VRAM |
| 1897 | | AM_RANGE(0x07000000, 0x070003ff) AM_RAM_WRITE(gba_oam_w) AM_BASE_MEMBER(gba_state_t, gba_oam) // OAM |
| 1895 | AM_RANGE(0x05000000, 0x050003ff) AM_RAM_WRITE(gba_pram_w) AM_BASE_MEMBER(gba_state, gba_pram) // Palette RAM |
| 1896 | AM_RANGE(0x06000000, 0x06017fff) AM_RAM_WRITE(gba_vram_w) AM_BASE_MEMBER(gba_state, gba_vram) // VRAM |
| 1897 | AM_RANGE(0x07000000, 0x070003ff) AM_RAM_WRITE(gba_oam_w) AM_BASE_MEMBER(gba_state, gba_oam) // OAM |
| 1898 | 1898 | AM_RANGE(0x08000000, 0x09ffffff) AM_ROM AM_REGION("cartridge", 0) // cartridge ROM (mirror 0) |
| 1899 | 1899 | AM_RANGE(0x0a000000, 0x0bffffff) AM_ROM AM_REGION("cartridge", 0) // cartridge ROM (mirror 1) |
| 1900 | 1900 | AM_RANGE(0x0c000000, 0x0cffffff) AM_ROM AM_REGION("cartridge", 0) // final mirror |
| r7509 | r7510 | |
| 1918 | 1918 | static TIMER_CALLBACK( perform_hbl ) |
| 1919 | 1919 | { |
| 1920 | 1920 | int ch, ctrl; |
| 1921 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 1921 | gba_state *state = (gba_state *)machine->driver_data; |
| 1922 | 1922 | int scanline = video_screen_get_vpos(machine->primary_screen); |
| 1923 | 1923 | |
| 1924 | 1924 | // draw only visible scanlines |
| r7509 | r7510 | |
| 1926 | 1926 | { |
| 1927 | 1927 | gba_draw_scanline(machine, scanline); |
| 1928 | 1928 | } |
| 1929 | | gba_state->DISPSTAT |= DISPSTAT_HBL; |
| 1930 | | if ((gba_state->DISPSTAT & DISPSTAT_HBL_IRQ_EN ) != 0) |
| 1929 | state->DISPSTAT |= DISPSTAT_HBL; |
| 1930 | if ((state->DISPSTAT & DISPSTAT_HBL_IRQ_EN ) != 0) |
| 1931 | 1931 | { |
| 1932 | 1932 | gba_request_irq(machine, INT_HBL); |
| 1933 | 1933 | } |
| 1934 | 1934 | |
| 1935 | 1935 | for (ch = 0; ch < 4; ch++) |
| 1936 | 1936 | { |
| 1937 | | ctrl = gba_state->dma_regs[(ch*3)+2]>>16; |
| 1937 | ctrl = state->dma_regs[(ch*3)+2]>>16; |
| 1938 | 1938 | |
| 1939 | 1939 | // HBL-triggered DMA? |
| 1940 | 1940 | if ((ctrl & 0x8000) && ((ctrl & 0x3000) == 0x2000)) |
| r7509 | r7510 | |
| 1943 | 1943 | } |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | | timer_adjust_oneshot(gba_state->hbl_timer, attotime_never, 0); |
| 1946 | timer_adjust_oneshot(state->hbl_timer, attotime_never, 0); |
| 1947 | 1947 | } |
| 1948 | 1948 | |
| 1949 | 1949 | static TIMER_CALLBACK( perform_scan ) |
| 1950 | 1950 | { |
| 1951 | 1951 | int scanline; |
| 1952 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 1952 | gba_state *state = (gba_state *)machine->driver_data; |
| 1953 | 1953 | |
| 1954 | 1954 | // clear hblank and raster IRQ flags |
| 1955 | | gba_state->DISPSTAT &= ~(DISPSTAT_HBL|DISPSTAT_VCNT); |
| 1955 | state->DISPSTAT &= ~(DISPSTAT_HBL|DISPSTAT_VCNT); |
| 1956 | 1956 | |
| 1957 | 1957 | scanline = video_screen_get_vpos(machine->primary_screen); |
| 1958 | 1958 | |
| 1959 | 1959 | // VBL is set for scanlines 160 through 226 (but not 227, which is the last line) |
| 1960 | 1960 | if (scanline >= 160 && scanline < 227) |
| 1961 | 1961 | { |
| 1962 | | gba_state->DISPSTAT |= DISPSTAT_VBL; |
| 1962 | state->DISPSTAT |= DISPSTAT_VBL; |
| 1963 | 1963 | } |
| 1964 | 1964 | else |
| 1965 | 1965 | { |
| 1966 | | gba_state->DISPSTAT &= ~DISPSTAT_VBL; |
| 1966 | state->DISPSTAT &= ~DISPSTAT_VBL; |
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | 1969 | // handle VCNT match interrupt/flag |
| 1970 | | if (scanline == ((gba_state->DISPSTAT >> 8) & 0xff)) |
| 1970 | if (scanline == ((state->DISPSTAT >> 8) & 0xff)) |
| 1971 | 1971 | { |
| 1972 | | gba_state->DISPSTAT |= DISPSTAT_VCNT; |
| 1973 | | if (gba_state->DISPSTAT & DISPSTAT_VCNT_IRQ_EN) |
| 1972 | state->DISPSTAT |= DISPSTAT_VCNT; |
| 1973 | if (state->DISPSTAT & DISPSTAT_VCNT_IRQ_EN) |
| 1974 | 1974 | { |
| 1975 | 1975 | gba_request_irq(machine, INT_VCNT); |
| 1976 | 1976 | } |
| r7509 | r7510 | |
| 1981 | 1981 | { |
| 1982 | 1982 | int ch, ctrl; |
| 1983 | 1983 | |
| 1984 | | if (gba_state->DISPSTAT & DISPSTAT_VBL_IRQ_EN) |
| 1984 | if (state->DISPSTAT & DISPSTAT_VBL_IRQ_EN) |
| 1985 | 1985 | { |
| 1986 | 1986 | gba_request_irq(machine, INT_VBL); |
| 1987 | 1987 | } |
| 1988 | 1988 | |
| 1989 | 1989 | for (ch = 0; ch < 4; ch++) |
| 1990 | 1990 | { |
| 1991 | | ctrl = gba_state->dma_regs[(ch*3)+2]>>16; |
| 1991 | ctrl = state->dma_regs[(ch*3)+2]>>16; |
| 1992 | 1992 | |
| 1993 | 1993 | // VBL-triggered DMA? |
| 1994 | 1994 | if ((ctrl & 0x8000) && ((ctrl & 0x3000) == 0x1000)) |
| r7509 | r7510 | |
| 1998 | 1998 | } |
| 1999 | 1999 | } |
| 2000 | 2000 | |
| 2001 | | timer_adjust_oneshot(gba_state->hbl_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline, 240), 0); |
| 2002 | | timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, ( scanline + 1 ) % 228, 0), 0); |
| 2001 | timer_adjust_oneshot(state->hbl_timer, video_screen_get_time_until_pos(machine->primary_screen, scanline, 240), 0); |
| 2002 | timer_adjust_oneshot(state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, ( scanline + 1 ) % 228, 0), 0); |
| 2003 | 2003 | } |
| 2004 | 2004 | |
| 2005 | 2005 | static MACHINE_RESET( gba ) |
| r7509 | r7510 | |
| 2008 | 2008 | running_device *gb_a_r = devtag_get_device(machine, "direct_a_right"); |
| 2009 | 2009 | running_device *gb_b_l = devtag_get_device(machine, "direct_b_left"); |
| 2010 | 2010 | running_device *gb_b_r = devtag_get_device(machine, "direct_b_right"); |
| 2011 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 2011 | gba_state *state = (gba_state *)machine->driver_data; |
| 2012 | 2012 | |
| 2013 | | memset(gba_state, 0, sizeof(gba_state)); |
| 2014 | | gba_state->SOUNDBIAS = 0x0200; |
| 2015 | | gba_state->flash64k_state = FLASH_IDLEBYTE0; |
| 2016 | | gba_state->eeprom_state = EEP_IDLE; |
| 2017 | | gba_state->SIOMULTI0 = 0xffff; |
| 2018 | | gba_state->SIOMULTI1 = 0xffff; |
| 2019 | | gba_state->SIOMULTI2 = 0xffff; |
| 2020 | | gba_state->SIOMULTI3 = 0xffff; |
| 2021 | | gba_state->KEYCNT = 0x03ff; |
| 2022 | | gba_state->RCNT = 0x8000; |
| 2023 | | gba_state->JOYSTAT = 0x0002; |
| 2024 | | gba_state->gfxBG2Changed = 0; |
| 2025 | | gba_state->gfxBG3Changed = 0; |
| 2026 | | gba_state->gfxBG2X = 0; |
| 2027 | | gba_state->gfxBG2Y = 0; |
| 2028 | | gba_state->gfxBG3X = 0; |
| 2029 | | gba_state->gfxBG3Y = 0; |
| 2013 | memset(state, 0, sizeof(state)); |
| 2014 | state->SOUNDBIAS = 0x0200; |
| 2015 | state->flash64k_state = FLASH_IDLEBYTE0; |
| 2016 | state->eeprom_state = EEP_IDLE; |
| 2017 | state->SIOMULTI0 = 0xffff; |
| 2018 | state->SIOMULTI1 = 0xffff; |
| 2019 | state->SIOMULTI2 = 0xffff; |
| 2020 | state->SIOMULTI3 = 0xffff; |
| 2021 | state->KEYCNT = 0x03ff; |
| 2022 | state->RCNT = 0x8000; |
| 2023 | state->JOYSTAT = 0x0002; |
| 2024 | state->gfxBG2Changed = 0; |
| 2025 | state->gfxBG3Changed = 0; |
| 2026 | state->gfxBG2X = 0; |
| 2027 | state->gfxBG2Y = 0; |
| 2028 | state->gfxBG3X = 0; |
| 2029 | state->gfxBG3Y = 0; |
| 2030 | 2030 | |
| 2031 | | gba_state->windowOn = 0; |
| 2032 | | gba_state->fxOn = 0; |
| 2031 | state->windowOn = 0; |
| 2032 | state->fxOn = 0; |
| 2033 | 2033 | |
| 2034 | | timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 2035 | | timer_adjust_oneshot(gba_state->hbl_timer, attotime_never, 0); |
| 2036 | | timer_adjust_oneshot(gba_state->dma_timer[0], attotime_never, 0); |
| 2037 | | timer_adjust_oneshot(gba_state->dma_timer[1], attotime_never, 1); |
| 2038 | | timer_adjust_oneshot(gba_state->dma_timer[2], attotime_never, 2); |
| 2039 | | timer_adjust_oneshot(gba_state->dma_timer[3], attotime_never, 3); |
| 2034 | timer_adjust_oneshot(state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 2035 | timer_adjust_oneshot(state->hbl_timer, attotime_never, 0); |
| 2036 | timer_adjust_oneshot(state->dma_timer[0], attotime_never, 0); |
| 2037 | timer_adjust_oneshot(state->dma_timer[1], attotime_never, 1); |
| 2038 | timer_adjust_oneshot(state->dma_timer[2], attotime_never, 2); |
| 2039 | timer_adjust_oneshot(state->dma_timer[3], attotime_never, 3); |
| 2040 | 2040 | |
| 2041 | | gba_state->fifo_a_ptr = gba_state->fifo_b_ptr = 17; // indicate empty |
| 2042 | | gba_state->fifo_a_in = gba_state->fifo_b_in = 17; |
| 2041 | state->fifo_a_ptr = state->fifo_b_ptr = 17; // indicate empty |
| 2042 | state->fifo_a_in = state->fifo_b_in = 17; |
| 2043 | 2043 | |
| 2044 | 2044 | // and clear the DACs |
| 2045 | 2045 | dac_signed_data_w(gb_a_l, 0x80); |
| r7509 | r7510 | |
| 2050 | 2050 | |
| 2051 | 2051 | static MACHINE_START( gba ) |
| 2052 | 2052 | { |
| 2053 | | gba_state_t *gba_state = (gba_state_t *)machine->driver_data; |
| 2053 | gba_state *state = (gba_state *)machine->driver_data; |
| 2054 | 2054 | |
| 2055 | 2055 | /* add a hook for battery save */ |
| 2056 | 2056 | add_exit_callback(machine, gba_machine_stop); |
| 2057 | 2057 | |
| 2058 | 2058 | /* create a timer to fire scanline functions */ |
| 2059 | | gba_state->scan_timer = timer_alloc(machine, perform_scan, 0); |
| 2060 | | gba_state->hbl_timer = timer_alloc(machine, perform_hbl, 0); |
| 2061 | | timer_adjust_oneshot(gba_state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 2059 | state->scan_timer = timer_alloc(machine, perform_scan, 0); |
| 2060 | state->hbl_timer = timer_alloc(machine, perform_hbl, 0); |
| 2061 | timer_adjust_oneshot(state->scan_timer, video_screen_get_time_until_pos(machine->primary_screen, 0, 0), 0); |
| 2062 | 2062 | |
| 2063 | 2063 | /* and one for each DMA channel */ |
| 2064 | | gba_state->dma_timer[0] = timer_alloc(machine, dma_complete, 0); |
| 2065 | | gba_state->dma_timer[1] = timer_alloc(machine, dma_complete, 0); |
| 2066 | | gba_state->dma_timer[2] = timer_alloc(machine, dma_complete, 0); |
| 2067 | | gba_state->dma_timer[3] = timer_alloc(machine, dma_complete, 0); |
| 2068 | | timer_adjust_oneshot(gba_state->dma_timer[0], attotime_never, 0); |
| 2069 | | timer_adjust_oneshot(gba_state->dma_timer[1], attotime_never, 1); |
| 2070 | | timer_adjust_oneshot(gba_state->dma_timer[2], attotime_never, 2); |
| 2071 | | timer_adjust_oneshot(gba_state->dma_timer[3], attotime_never, 3); |
| 2064 | state->dma_timer[0] = timer_alloc(machine, dma_complete, 0); |
| 2065 | state->dma_timer[1] = timer_alloc(machine, dma_complete, 0); |
| 2066 | state->dma_timer[2] = timer_alloc(machine, dma_complete, 0); |
| 2067 | state->dma_timer[3] = timer_alloc(machine, dma_complete, 0); |
| 2068 | timer_adjust_oneshot(state->dma_timer[0], attotime_never, 0); |
| 2069 | timer_adjust_oneshot(state->dma_timer[1], attotime_never, 1); |
| 2070 | timer_adjust_oneshot(state->dma_timer[2], attotime_never, 2); |
| 2071 | timer_adjust_oneshot(state->dma_timer[3], attotime_never, 3); |
| 2072 | 2072 | |
| 2073 | 2073 | /* also one for each timer (heh) */ |
| 2074 | | gba_state->tmr_timer[0] = timer_alloc(machine, timer_expire, 0); |
| 2075 | | gba_state->tmr_timer[1] = timer_alloc(machine, timer_expire, 0); |
| 2076 | | gba_state->tmr_timer[2] = timer_alloc(machine, timer_expire, 0); |
| 2077 | | gba_state->tmr_timer[3] = timer_alloc(machine, timer_expire, 0); |
| 2078 | | timer_adjust_oneshot(gba_state->tmr_timer[0], attotime_never, 0); |
| 2079 | | timer_adjust_oneshot(gba_state->tmr_timer[1], attotime_never, 1); |
| 2080 | | timer_adjust_oneshot(gba_state->tmr_timer[2], attotime_never, 2); |
| 2081 | | timer_adjust_oneshot(gba_state->tmr_timer[3], attotime_never, 3); |
| 2074 | state->tmr_timer[0] = timer_alloc(machine, timer_expire, 0); |
| 2075 | state->tmr_timer[1] = timer_alloc(machine, timer_expire, 0); |
| 2076 | state->tmr_timer[2] = timer_alloc(machine, timer_expire, 0); |
| 2077 | state->tmr_timer[3] = timer_alloc(machine, timer_expire, 0); |
| 2078 | timer_adjust_oneshot(state->tmr_timer[0], attotime_never, 0); |
| 2079 | timer_adjust_oneshot(state->tmr_timer[1], attotime_never, 1); |
| 2080 | timer_adjust_oneshot(state->tmr_timer[2], attotime_never, 2); |
| 2081 | timer_adjust_oneshot(state->tmr_timer[3], attotime_never, 3); |
| 2082 | 2082 | |
| 2083 | 2083 | /* and an IRQ handling timer */ |
| 2084 | | gba_state->irq_timer = timer_alloc(machine, handle_irq, 0); |
| 2085 | | timer_adjust_oneshot(gba_state->irq_timer, attotime_never, 0); |
| 2084 | state->irq_timer = timer_alloc(machine, handle_irq, 0); |
| 2085 | timer_adjust_oneshot(state->irq_timer, attotime_never, 0); |
| 2086 | 2086 | |
| 2087 | 2087 | gba_video_start(machine); |
| 2088 | 2088 | } |
| r7509 | r7510 | |
| 2097 | 2097 | |
| 2098 | 2098 | static READ32_HANDLER( sram_r ) |
| 2099 | 2099 | { |
| 2100 | | gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data; |
| 2100 | gba_state *state = (gba_state *)space->machine->driver_data; |
| 2101 | 2101 | |
| 2102 | | return gba_state->gba_sram[offset]; |
| 2102 | return state->gba_sram[offset]; |
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | static WRITE32_HANDLER( sram_w ) |
| 2106 | 2106 | { |
| 2107 | | gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data; |
| 2107 | gba_state *state = (gba_state *)space->machine->driver_data; |
| 2108 | 2108 | |
| 2109 | | COMBINE_DATA(&gba_state->gba_sram[offset]); |
| 2109 | COMBINE_DATA(&state->gba_sram[offset]); |
| 2110 | 2110 | } |
| 2111 | 2111 | |
| 2112 | 2112 | static READ32_HANDLER( flash64k_r ) |
| 2113 | 2113 | { |
| 2114 | | gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data; |
| 2115 | | switch( gba_state->flash64k_state ) |
| 2114 | gba_state *state = (gba_state *)space->machine->driver_data; |
| 2115 | switch( state->flash64k_state ) |
| 2116 | 2116 | { |
| 2117 | 2117 | case FLASH_IDLEBYTE0: |
| 2118 | 2118 | case FLASH_IDLEBYTE1: |
| r7509 | r7510 | |
| 2120 | 2120 | case FLASH_ERASEBYTE0: |
| 2121 | 2121 | case FLASH_ERASEBYTE1: |
| 2122 | 2122 | case FLASH_ERASEBYTE2: |
| 2123 | | return gba_state->gba_flash64k[offset]; |
| 2123 | return state->gba_flash64k[offset]; |
| 2124 | 2124 | case FLASH_IDENT: |
| 2125 | 2125 | if( offset == 0 ) |
| 2126 | 2126 | { |
| 2127 | | return ( gba_state->gba_flash64k[0] & 0xffff0000 ) | 0x00001b32; |
| 2127 | return ( state->gba_flash64k[0] & 0xffff0000 ) | 0x00001b32; |
| 2128 | 2128 | } |
| 2129 | 2129 | else |
| 2130 | 2130 | { |
| 2131 | | return gba_state->gba_flash64k[offset]; |
| 2131 | return state->gba_flash64k[offset]; |
| 2132 | 2132 | } |
| 2133 | 2133 | return 0x00001b32; |
| 2134 | 2134 | case FLASH_ERASE_ALL: |
| 2135 | 2135 | case FLASH_ERASE_4K: |
| 2136 | | return gba_state->gba_flash64k[offset]; |
| 2136 | return state->gba_flash64k[offset]; |
| 2137 | 2137 | } |
| 2138 | | return gba_state->gba_flash64k[offset]; |
| 2138 | return state->gba_flash64k[offset]; |
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | static WRITE32_HANDLER( flash64k_w ) |
| 2142 | 2142 | { |
| 2143 | | gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data; |
| 2143 | gba_state *state = (gba_state *)space->machine->driver_data; |
| 2144 | 2144 | |
| 2145 | | switch( gba_state->flash64k_state ) |
| 2145 | switch( state->flash64k_state ) |
| 2146 | 2146 | { |
| 2147 | 2147 | case FLASH_IDLEBYTE0: |
| 2148 | 2148 | case FLASH_ERASEBYTE0: |
| r7509 | r7510 | |
| 2150 | 2150 | { |
| 2151 | 2151 | if( ( data & mem_mask ) == 0x0000aa00 ) |
| 2152 | 2152 | { |
| 2153 | | if( gba_state->flash64k_state == FLASH_IDLEBYTE0 ) |
| 2153 | if( state->flash64k_state == FLASH_IDLEBYTE0 ) |
| 2154 | 2154 | { |
| 2155 | | gba_state->flash64k_state = FLASH_IDLEBYTE1; |
| 2155 | state->flash64k_state = FLASH_IDLEBYTE1; |
| 2156 | 2156 | } |
| 2157 | | else if( gba_state->flash64k_state == FLASH_ERASEBYTE0 ) |
| 2157 | else if( state->flash64k_state == FLASH_ERASEBYTE0 ) |
| 2158 | 2158 | { |
| 2159 | | gba_state->flash64k_state = FLASH_ERASEBYTE1; |
| 2159 | state->flash64k_state = FLASH_ERASEBYTE1; |
| 2160 | 2160 | } |
| 2161 | 2161 | } |
| 2162 | 2162 | } |
| r7509 | r7510 | |
| 2167 | 2167 | { |
| 2168 | 2168 | if( ( data & mem_mask ) == 0x00550000 ) |
| 2169 | 2169 | { |
| 2170 | | if( gba_state->flash64k_state == FLASH_IDLEBYTE1 ) |
| 2170 | if( state->flash64k_state == FLASH_IDLEBYTE1 ) |
| 2171 | 2171 | { |
| 2172 | | gba_state->flash64k_state = FLASH_IDLEBYTE2; |
| 2172 | state->flash64k_state = FLASH_IDLEBYTE2; |
| 2173 | 2173 | } |
| 2174 | | else if( gba_state->flash64k_state == FLASH_ERASEBYTE1 ) |
| 2174 | else if( state->flash64k_state == FLASH_ERASEBYTE1 ) |
| 2175 | 2175 | { |
| 2176 | | gba_state->flash64k_state = FLASH_ERASEBYTE2; |
| 2176 | state->flash64k_state = FLASH_ERASEBYTE2; |
| 2177 | 2177 | } |
| 2178 | 2178 | } |
| 2179 | 2179 | } |
| r7509 | r7510 | |
| 2182 | 2182 | case FLASH_ERASEBYTE2: |
| 2183 | 2183 | if( offset == 0x5555/4 && ~mem_mask == 0xffff00ff ) |
| 2184 | 2184 | { |
| 2185 | | if( gba_state->flash64k_state == FLASH_IDLEBYTE2 ) |
| 2185 | if( state->flash64k_state == FLASH_IDLEBYTE2 ) |
| 2186 | 2186 | { |
| 2187 | 2187 | switch( ( data & mem_mask ) >> 8 ) |
| 2188 | 2188 | { |
| 2189 | 2189 | case 0x80: |
| 2190 | | gba_state->flash64k_state = FLASH_ERASEBYTE0; |
| 2190 | state->flash64k_state = FLASH_ERASEBYTE0; |
| 2191 | 2191 | break; |
| 2192 | 2192 | case 0x90: |
| 2193 | | gba_state->flash64k_state = FLASH_IDENT; |
| 2193 | state->flash64k_state = FLASH_IDENT; |
| 2194 | 2194 | break; |
| 2195 | 2195 | case 0xa0: |
| 2196 | | gba_state->flash64k_state = FLASH_WRITE; |
| 2196 | state->flash64k_state = FLASH_WRITE; |
| 2197 | 2197 | break; |
| 2198 | 2198 | } |
| 2199 | 2199 | } |
| 2200 | | else if( gba_state->flash64k_state == FLASH_ERASEBYTE2 ) |
| 2200 | else if( state->flash64k_state == FLASH_ERASEBYTE2 ) |
| 2201 | 2201 | { |
| 2202 | 2202 | if( ( data & mem_mask ) == 0x00001000 ) |
| 2203 | 2203 | { |
| 2204 | 2204 | UINT32 flashWord; |
| 2205 | 2205 | for( flashWord = 0; flashWord < 0x10000/4; flashWord++ ) |
| 2206 | 2206 | { |
| 2207 | | gba_state->gba_flash64k[flashWord] = 0xffffffff; |
| 2207 | state->gba_flash64k[flashWord] = 0xffffffff; |
| 2208 | 2208 | } |
| 2209 | | gba_state->flash64k_state = FLASH_ERASE_ALL; |
| 2209 | state->flash64k_state = FLASH_ERASE_ALL; |
| 2210 | 2210 | } |
| 2211 | 2211 | } |
| 2212 | 2212 | } |
| 2213 | 2213 | else if( ( offset & 0xffffc3ff ) == 0 && ( data & mem_mask ) == 0x00000030 ) |
| 2214 | 2214 | { |
| 2215 | 2215 | UINT32 flashWord; |
| 2216 | | gba_state->flash64k_page = offset >> 10; |
| 2216 | state->flash64k_page = offset >> 10; |
| 2217 | 2217 | for( flashWord = offset; flashWord < offset + 0x1000/4; flashWord++ ) |
| 2218 | 2218 | { |
| 2219 | | gba_state->gba_flash64k[flashWord] = 0xffffffff; |
| 2219 | state->gba_flash64k[flashWord] = 0xffffffff; |
| 2220 | 2220 | } |
| 2221 | | gba_state->flash64k_state = FLASH_ERASE_4K; |
| 2221 | state->flash64k_state = FLASH_ERASE_4K; |
| 2222 | 2222 | } |
| 2223 | 2223 | break; |
| 2224 | 2224 | case FLASH_IDENT: |
| 2225 | 2225 | // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0. |
| 2226 | | gba_state->flash64k_state = FLASH_IDLEBYTE0; |
| 2226 | state->flash64k_state = FLASH_IDLEBYTE0; |
| 2227 | 2227 | flash64k_w( space, offset, data, ~mem_mask ); |
| 2228 | 2228 | break; |
| 2229 | 2229 | case FLASH_ERASE_4K: |
| 2230 | 2230 | // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0. |
| 2231 | | gba_state->flash64k_state = FLASH_IDLEBYTE0; |
| 2231 | state->flash64k_state = FLASH_IDLEBYTE0; |
| 2232 | 2232 | flash64k_w( space, offset, data, ~mem_mask ); |
| 2233 | 2233 | break; |
| 2234 | 2234 | case FLASH_ERASE_ALL: |
| 2235 | 2235 | // Hack; any sensibly-written game should follow up with the relevant read, which will reset the state to FLASH_IDLEBYTE0. |
| 2236 | | gba_state->flash64k_state = FLASH_IDLEBYTE0; |
| 2236 | state->flash64k_state = FLASH_IDLEBYTE0; |
| 2237 | 2237 | flash64k_w( space, offset, data, ~mem_mask ); |
| 2238 | 2238 | break; |
| 2239 | 2239 | case FLASH_WRITE: |
| 2240 | | COMBINE_DATA(&gba_state->gba_flash64k[offset]); |
| 2241 | | gba_state->flash64k_state = FLASH_IDLEBYTE0; |
| 2240 | COMBINE_DATA(&state->gba_flash64k[offset]); |
| 2241 | state->flash64k_state = FLASH_IDLEBYTE0; |
| 2242 | 2242 | break; |
| 2243 | 2243 | } |
| 2244 | 2244 | } |
| r7509 | r7510 | |
| 2246 | 2246 | static READ32_HANDLER( eeprom_r ) |
| 2247 | 2247 | { |
| 2248 | 2248 | UINT32 out; |
| 2249 | | gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data; |
| 2249 | gba_state *state = (gba_state *)space->machine->driver_data; |
| 2250 | 2250 | |
| 2251 | | switch (gba_state->eeprom_state) |
| 2251 | switch (state->eeprom_state) |
| 2252 | 2252 | { |
| 2253 | 2253 | case EEP_IDLE: |
| 2254 | | // printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, gba_state->eeprom_state, activecpu_get_pc(), 1); |
| 2254 | // printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, state->eeprom_state, activecpu_get_pc(), 1); |
| 2255 | 2255 | return 0x00010001; // "ready" |
| 2256 | 2256 | |
| 2257 | 2257 | case EEP_READFIRST: |
| 2258 | | gba_state->eeprom_count--; |
| 2258 | state->eeprom_count--; |
| 2259 | 2259 | |
| 2260 | | if (!gba_state->eeprom_count) |
| 2260 | if (!state->eeprom_count) |
| 2261 | 2261 | { |
| 2262 | | gba_state->eeprom_count = 64; |
| 2263 | | gba_state->eeprom_bits = 0; |
| 2264 | | gba_state->eep_data = 0; |
| 2265 | | gba_state->eeprom_state = EEP_READ; |
| 2262 | state->eeprom_count = 64; |
| 2263 | state->eeprom_bits = 0; |
| 2264 | state->eep_data = 0; |
| 2265 | state->eeprom_state = EEP_READ; |
| 2266 | 2266 | } |
| 2267 | 2267 | break; |
| 2268 | 2268 | case EEP_READ: |
| 2269 | | if ((gba_state->eeprom_bits == 0) && (gba_state->eeprom_count)) |
| 2269 | if ((state->eeprom_bits == 0) && (state->eeprom_count)) |
| 2270 | 2270 | { |
| 2271 | | gba_state->eep_data = gba_state->gba_eeprom[gba_state->eeprom_addr]; |
| 2272 | | // printf("EEPROM read @ %x = %x (%x)\n", gba_state->eeprom_addr, gba_state->eep_data, (gba_state->eep_data & 0x80) ? 1 : 0); |
| 2273 | | gba_state->eeprom_addr++; |
| 2274 | | gba_state->eeprom_bits = 8; |
| 2271 | state->eep_data = state->gba_eeprom[state->eeprom_addr]; |
| 2272 | // printf("EEPROM read @ %x = %x (%x)\n", state->eeprom_addr, state->eep_data, (state->eep_data & 0x80) ? 1 : 0); |
| 2273 | state->eeprom_addr++; |
| 2274 | state->eeprom_bits = 8; |
| 2275 | 2275 | } |
| 2276 | 2276 | |
| 2277 | | out = (gba_state->eep_data & 0x80) ? 1 : 0; |
| 2277 | out = (state->eep_data & 0x80) ? 1 : 0; |
| 2278 | 2278 | out |= (out<<16); |
| 2279 | | gba_state->eep_data <<= 1; |
| 2279 | state->eep_data <<= 1; |
| 2280 | 2280 | |
| 2281 | | gba_state->eeprom_bits--; |
| 2282 | | gba_state->eeprom_count--; |
| 2281 | state->eeprom_bits--; |
| 2282 | state->eeprom_count--; |
| 2283 | 2283 | |
| 2284 | | if (!gba_state->eeprom_count) |
| 2284 | if (!state->eeprom_count) |
| 2285 | 2285 | { |
| 2286 | | gba_state->eeprom_state = EEP_IDLE; |
| 2286 | state->eeprom_state = EEP_IDLE; |
| 2287 | 2287 | } |
| 2288 | 2288 | |
| 2289 | 2289 | // printf("out = %08x\n", out); |
| 2290 | | // printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %08x\n", offset, ~mem_mask, gba_state->eeprom_state, activecpu_get_pc(), out); |
| 2290 | // printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %08x\n", offset, ~mem_mask, state->eeprom_state, activecpu_get_pc(), out); |
| 2291 | 2291 | return out; |
| 2292 | 2292 | } |
| 2293 | | // printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, gba_state->eeprom_state, activecpu_get_pc(), 0); |
| 2293 | // printf("eeprom_r: @ %x, mask %08x (state %d) (PC=%x) = %d\n", offset, ~mem_mask, state->eeprom_state, activecpu_get_pc(), 0); |
| 2294 | 2294 | return 0; |
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | 2297 | static WRITE32_HANDLER( eeprom_w ) |
| 2298 | 2298 | { |
| 2299 | | gba_state_t *gba_state = (gba_state_t *)space->machine->driver_data; |
| 2299 | gba_state *state = (gba_state *)space->machine->driver_data; |
| 2300 | 2300 | |
| 2301 | 2301 | if (~mem_mask == 0x0000ffff) |
| 2302 | 2302 | { |
| 2303 | 2303 | data >>= 16; |
| 2304 | 2304 | } |
| 2305 | 2305 | |
| 2306 | | // printf("eeprom_w: %x @ %x (state %d) (PC=%x)\n", data, offset, gba_state->eeprom_state, activecpu_get_pc()); |
| 2306 | // printf("eeprom_w: %x @ %x (state %d) (PC=%x)\n", data, offset, state->eeprom_state, activecpu_get_pc()); |
| 2307 | 2307 | |
| 2308 | | switch (gba_state->eeprom_state) |
| 2308 | switch (state->eeprom_state) |
| 2309 | 2309 | { |
| 2310 | 2310 | case EEP_IDLE: |
| 2311 | 2311 | if (data == 1) |
| 2312 | 2312 | { |
| 2313 | | gba_state->eeprom_state++; |
| 2313 | state->eeprom_state++; |
| 2314 | 2314 | } |
| 2315 | 2315 | break; |
| 2316 | 2316 | |
| 2317 | 2317 | case EEP_COMMAND: |
| 2318 | 2318 | if (data == 1) |
| 2319 | 2319 | { |
| 2320 | | gba_state->eeprom_command = EEP_READFIRST; |
| 2320 | state->eeprom_command = EEP_READFIRST; |
| 2321 | 2321 | } |
| 2322 | 2322 | else |
| 2323 | 2323 | { |
| 2324 | | gba_state->eeprom_command = EEP_WRITE; |
| 2324 | state->eeprom_command = EEP_WRITE; |
| 2325 | 2325 | } |
| 2326 | | gba_state->eeprom_state = EEP_ADDR; |
| 2327 | | gba_state->eeprom_count = 6; |
| 2328 | | gba_state->eeprom_addr = 0; |
| 2326 | state->eeprom_state = EEP_ADDR; |
| 2327 | state->eeprom_count = 6; |
| 2328 | state->eeprom_addr = 0; |
| 2329 | 2329 | break; |
| 2330 | 2330 | |
| 2331 | 2331 | case EEP_ADDR: |
| 2332 | | gba_state->eeprom_addr <<= 1; |
| 2333 | | gba_state->eeprom_addr |= (data & 1); |
| 2334 | | gba_state->eeprom_count--; |
| 2335 | | if (!gba_state->eeprom_count) |
| 2332 | state->eeprom_addr <<= 1; |
| 2333 | state->eeprom_addr |= (data & 1); |
| 2334 | state->eeprom_count--; |
| 2335 | if (!state->eeprom_count) |
| 2336 | 2336 | { |
| 2337 | | gba_state->eeprom_addr *= 8; // each address points to 8 bytes |
| 2338 | | if (gba_state->eeprom_command == EEP_READFIRST) |
| 2337 | state->eeprom_addr *= 8; // each address points to 8 bytes |
| 2338 | if (state->eeprom_command == EEP_READFIRST) |
| 2339 | 2339 | { |
| 2340 | | gba_state->eeprom_state = EEP_AFTERADDR; |
| 2340 | state->eeprom_state = EEP_AFTERADDR; |
| 2341 | 2341 | } |
| 2342 | 2342 | else |
| 2343 | 2343 | { |
| 2344 | | gba_state->eeprom_count = 64; |
| 2345 | | gba_state->eeprom_bits = 8; |
| 2346 | | gba_state->eeprom_state = EEP_WRITE; |
| 2347 | | gba_state->eep_data = 0; |
| 2344 | state->eeprom_count = 64; |
| 2345 | state->eeprom_bits = 8; |
| 2346 | state->eeprom_state = EEP_WRITE; |
| 2347 | state->eep_data = 0; |
| 2348 | 2348 | } |
| 2349 | 2349 | } |
| 2350 | 2350 | break; |
| 2351 | 2351 | |
| 2352 | 2352 | case EEP_AFTERADDR: |
| 2353 | | gba_state->eeprom_state = gba_state->eeprom_command; |
| 2354 | | gba_state->eeprom_count = 64; |
| 2355 | | gba_state->eeprom_bits = 0; |
| 2356 | | gba_state->eep_data = 0; |
| 2357 | | if( gba_state->eeprom_state == EEP_READFIRST ) |
| 2353 | state->eeprom_state = state->eeprom_command; |
| 2354 | state->eeprom_count = 64; |
| 2355 | state->eeprom_bits = 0; |
| 2356 | state->eep_data = 0; |
| 2357 | if( state->eeprom_state == EEP_READFIRST ) |
| 2358 | 2358 | { |
| 2359 | | gba_state->eeprom_count = 4; |
| 2359 | state->eeprom_count = 4; |
| 2360 | 2360 | } |
| 2361 | 2361 | break; |
| 2362 | 2362 | |
| 2363 | 2363 | case EEP_WRITE: |
| 2364 | | gba_state->eep_data<<= 1; |
| 2365 | | gba_state->eep_data |= (data & 1); |
| 2366 | | gba_state->eeprom_bits--; |
| 2367 | | gba_state->eeprom_count--; |
| 2364 | state->eep_data<<= 1; |
| 2365 | state->eep_data |= (data & 1); |
| 2366 | state->eeprom_bits--; |
| 2367 | state->eeprom_count--; |
| 2368 | 2368 | |
| 2369 | | if (gba_state->eeprom_bits == 0) |
| 2369 | if (state->eeprom_bits == 0) |
| 2370 | 2370 | { |
| 2371 | | mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(devtag_get_device(space->machine, "maincpu")), gba_state->eep_data, gba_state->eeprom_addr ); |
| 2372 | | gba_state->gba_eeprom[gba_state->eeprom_addr] = gba_state->eep_data; |
| 2373 | | gba_state->eeprom_addr++; |
| 2374 | | gba_state->eep_data = 0; |
| 2375 | | gba_state->eeprom_bits = 8; |
| 2371 | mame_printf_verbose("%08x: EEPROM: %02x to %x\n", cpu_get_pc(devtag_get_device(space->machine, "maincpu")), state->eep_data, state->eeprom_addr ); |
| 2372 | state->gba_eeprom[state->eeprom_addr] = state->eep_data; |
| 2373 | state->eeprom_addr++; |
| 2374 | state->eep_data = 0; |
| 2375 | state->eeprom_bits = 8; |
| 2376 | 2376 | } |
| 2377 | 2377 | |
| 2378 | | if (!gba_state->eeprom_count) |
| 2378 | if (!state->eeprom_count) |
| 2379 | 2379 | { |
| 2380 | | gba_state->eeprom_state = EEP_AFTERWRITE; |
| 2380 | state->eeprom_state = EEP_AFTERWRITE; |
| 2381 | 2381 | } |
| 2382 | 2382 | break; |
| 2383 | 2383 | |
| 2384 | 2384 | case EEP_AFTERWRITE: |
| 2385 | | gba_state->eeprom_state = EEP_IDLE; |
| 2385 | state->eeprom_state = EEP_IDLE; |
| 2386 | 2386 | break; |
| 2387 | 2387 | } |
| 2388 | 2388 | } |
| r7509 | r7510 | |
| 2391 | 2391 | { |
| 2392 | 2392 | UINT8 *ROM = memory_region(image->machine, "cartridge"); |
| 2393 | 2393 | int i; |
| 2394 | | gba_state_t *gba_state = (gba_state_t *)image->machine->driver_data; |
| 2394 | gba_state *state = (gba_state *)image->machine->driver_data; |
| 2395 | 2395 | |
| 2396 | 2396 | nvsize = 0; |
| 2397 | 2397 | nvptr = (UINT8 *)NULL; |
| r7509 | r7510 | |
| 2402 | 2402 | { |
| 2403 | 2403 | if (!memcmp(&ROM[i], "EEPROM_", 7)) |
| 2404 | 2404 | { |
| 2405 | | nvptr = (UINT8 *)&gba_state->gba_eeprom; |
| 2405 | nvptr = (UINT8 *)&state->gba_eeprom; |
| 2406 | 2406 | nvsize = 0x2000; |
| 2407 | 2407 | |
| 2408 | 2408 | if (image_length(image) <= (16*1024*1024)) |
| r7509 | r7510 | |
| 2419 | 2419 | } |
| 2420 | 2420 | else if (!memcmp(&ROM[i], "SRAM_", 5)) |
| 2421 | 2421 | { |
| 2422 | | nvptr = (UINT8 *)&gba_state->gba_sram; |
| 2422 | nvptr = (UINT8 *)&state->gba_sram; |
| 2423 | 2423 | nvsize = 0x10000; |
| 2424 | 2424 | |
| 2425 | 2425 | memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe00ffff, 0, 0, sram_r); |
| r7509 | r7510 | |
| 2433 | 2433 | } |
| 2434 | 2434 | else if (!memcmp(&ROM[i], "FLASH", 5)) |
| 2435 | 2435 | { |
| 2436 | | nvptr = (UINT8 *)&gba_state->gba_flash64k; |
| 2436 | nvptr = (UINT8 *)&state->gba_flash64k; |
| 2437 | 2437 | nvsize = 0x10000; |
| 2438 | 2438 | |
| 2439 | 2439 | memory_install_read32_handler(cpu_get_address_space(devtag_get_device(image->machine, "maincpu"), ADDRESS_SPACE_PROGRAM), 0xe000000, 0xe007fff, 0, 0, flash64k_r); |
| r7509 | r7510 | |
| 2480 | 2480 | } |
| 2481 | 2481 | |
| 2482 | 2482 | static MACHINE_DRIVER_START( gbadv ) |
| 2483 | | MDRV_DRIVER_DATA(gba_state_t) |
| 2483 | MDRV_DRIVER_DATA(gba_state) |
| 2484 | 2484 | |
| 2485 | 2485 | MDRV_CPU_ADD("maincpu", ARM7, 16777216) |
| 2486 | 2486 | MDRV_CPU_PROGRAM_MAP(gbadvance_map) |