src/mame/machine/snes.c
| r7682 | r7683 | |
| 105 | 105 | snes_hdma_init(cpu0space); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | static TIMER_CALLBACK( snes_update_io ) |
| 109 | { |
| 110 | snes_state *state = (snes_state *)machine->driver_data; |
| 111 | const address_space *cpu0space = cpu_get_address_space(state->maincpu, ADDRESS_SPACE_PROGRAM); |
| 112 | state->io_read(cpu0space->machine); |
| 113 | snes_ram[HVBJOY] &= 0xfe; /* Clear busy bit */ |
| 114 | } |
| 115 | |
| 108 | 116 | static TIMER_CALLBACK( snes_scanline_tick ) |
| 109 | 117 | { |
| 110 | 118 | snes_state *state = (snes_state *)machine->driver_data; |
| r7682 | r7683 | |
| 168 | 176 | // NMI goes off about 12 cycles after this (otherwise Chrono Trigger, NFL QB Club, etc. lock up) |
| 169 | 177 | timer_adjust_oneshot(state->nmi_timer, cpu_clocks_to_attotime(state->maincpu, 12), 0); |
| 170 | 178 | } |
| 179 | |
| 180 | /* three lines after start of vblank we update the controllers (value from snes9x) */ |
| 181 | timer_adjust_oneshot(state->io_timer, video_screen_get_time_until_pos(machine->primary_screen, snes_ppu.beam.current_vert + 2, 0), 0); |
| 171 | 182 | } |
| 172 | 183 | |
| 173 | 184 | // hdma reset happens at scanline 0, H=~6 |
| r7682 | r7683 | |
| 177 | 188 | snes_hdma_init(cpu0space); |
| 178 | 189 | } |
| 179 | 190 | |
| 180 | | /* three lines after start of vblank we update the controllers (value from snes9x) */ |
| 181 | | if (snes_ppu.beam.current_vert == snes_ppu.beam.last_visible_line + 2) |
| 182 | | { |
| 183 | | state->io_read(machine); |
| 184 | | snes_ram[HVBJOY] &= 0xfe; /* Clear busy bit */ |
| 185 | | } |
| 186 | | |
| 187 | 191 | if (snes_ppu.beam.current_vert == 0) |
| 188 | 192 | { /* VBlank is over, time for a new frame */ |
| 189 | 193 | snes_ram[HVBJOY] &= 0x7f; /* Clear vblank bit */ |
| r7682 | r7683 | |
| 196 | 200 | |
| 197 | 201 | timer_adjust_oneshot(state->scanline_timer, attotime_never, 0); |
| 198 | 202 | timer_adjust_oneshot(state->hblank_timer, video_screen_get_time_until_pos(machine->primary_screen, snes_ppu.beam.current_vert, state->hblank_offset * state->htmult), 0); |
| 203 | |
| 204 | // printf("%02x %d\n",snes_ram[HVBJOY],snes_ppu.beam.current_vert); |
| 199 | 205 | } |
| 200 | 206 | |
| 201 | 207 | /* This is called at the start of hblank *before* the scanline indicated in current_vert! */ |
| r7682 | r7683 | |
| 559 | 565 | if((snes_ram[NMITIMEN] & 0x30) == 0x00) |
| 560 | 566 | { |
| 561 | 567 | cpu_set_input_line(state->maincpu, G65816_LINE_IRQ, CLEAR_LINE ); |
| 562 | | snes_ram[TIMEUP] = 0; // flag is cleared on both read and write |
| 568 | snes_ram[TIMEUP] = 0; // clear pending IRQ if irq is disabled here, 3x3 Eyes - Seima Korin Den behaves on this |
| 563 | 569 | } |
| 564 | 570 | break; |
| 565 | 571 | case OLDJOY2: /* Old NES joystick support */ |
| r7682 | r7683 | |
| 1425 | 1431 | timer_adjust_oneshot(state->div_timer, attotime_never, 0); |
| 1426 | 1432 | state->mult_timer = timer_alloc(machine, snes_mult_callback, NULL); |
| 1427 | 1433 | timer_adjust_oneshot(state->mult_timer, attotime_never, 0); |
| 1434 | state->io_timer = timer_alloc(machine, snes_update_io, NULL); |
| 1435 | timer_adjust_oneshot(state->io_timer, attotime_never, 0); |
| 1428 | 1436 | |
| 1429 | 1437 | // SNES hcounter has a 0-339 range. hblank starts at counter 260. |
| 1430 | 1438 | // clayfighter sets an HIRQ at 260, apparently it wants it to be before hdma kicks off, so we'll delay 2 pixels. |