From f21a08ebfa362022df2b3b1b06b3add73a31f636 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Sun, 30 May 2010 18:42:03 +0000 Subject: [PATCH] [Core] .improved Z80 bus reset accuracy .improved Z80 locks & VDP access accuracy .improved soft-reset accuracy .adjusted Horizontal Counter timing in H32 mode (fixes Sonic 3D Blast 'bonus' levels) .updated win32 port to compile with recent changes .input code cleanup [GCN] .fixed soft-reset (reset switch should also works now) IMPORTANT: Because of some internal changes, saved states from previous revisions are not compatible ! --- source/cart_hw/eeprom.c | 5 +- source/gen_input.c | 96 +++++++++++++------------ source/gen_input.h | 36 +++++----- source/genesis.c | 141 +++++++++++++++++++------------------ source/genesis.h | 13 ++-- source/gx/gui/menu.c | 14 ++-- source/gx/gx_input.c | 89 +++++++++++++---------- source/gx/gx_video.c | 38 ++++------ source/hvc.h | 5 +- source/mem68k.c | 32 ++++----- source/membnk.c | 24 ++++--- source/memz80.c | 20 ++++-- source/system.c | 16 ++--- source/system.h | 2 +- source/unused/win/Makefile | 13 ++-- source/unused/win/config.c | 4 +- source/unused/win/config.h | 2 + source/unused/win/main.c | 90 +++++++++++++---------- source/vdp.c | 34 ++++----- source/vdp.h | 5 +- 20 files changed, 360 insertions(+), 319 deletions(-) diff --git a/source/cart_hw/eeprom.c b/source/cart_hw/eeprom.c index aaac2f5..180450b 100644 --- a/source/cart_hw/eeprom.c +++ b/source/cart_hw/eeprom.c @@ -95,7 +95,7 @@ void eeprom_init() sram.custom = 0; /* look into game database */ - while ((i> 1; @@ -82,7 +85,7 @@ static inline void lightgun_reset(int num) static inline void lightgun_update(int num) { - if ((input.analog[num][1] == v_counter + input.y_offset)) + if ((input.analog[num][1] == v_counter + y_offset)) { /* HL enabled ? */ if (io_reg[5] & 0x80) @@ -99,9 +102,9 @@ static inline void lightgun_update(int num) */ hvc_latch = 0x10000 | (vctab[v_counter] << 8); if (reg[12] & 1) - hvc_latch |= hc_320[((input.analog[num][0] * 290) / (2 * 320) + input.x_offset) % 210]; + hvc_latch |= hc_320[((input.analog[num][0] * 290) / (2 * 320) + x_offset) % 210]; else - hvc_latch |= hc_256[(input.analog[num][0] / 2 + input.x_offset)%171]; + hvc_latch |= hc_256[(input.analog[num][0] / 2 + x_offset)%171]; } } } @@ -539,17 +542,22 @@ static inline void teamplayer_write(uint32 port, uint32 data) * 4-WAYPLAY adapter support * *****************************************************************************/ +static struct wayplay +{ + uint8 current; +} wayplay; + static inline void wayplay_write(uint32 port, uint32 data) { - if (port == 0) gamepad_write(input.current, data); - else input.current = (data >> 4) & 0x07; + if (port == 0) gamepad_write(wayplay.current, data); + else wayplay.current = (data >> 4) & 0x07; } static inline uint32 wayplay_read(uint32 port) { if (port == 1) return 0x7F; - if (input.current >= 4) return 0x70; /* multitap detection (TH2 = 1) */ - return gamepad_read(input.current); /* 0x0C = Pad1, 0x1C = Pad2, ... */ + if (wayplay.current >= 4) return 0x70; /* multitap detection (TH2 = 1) */ + return gamepad_read(wayplay.current); /* 0x0C = Pad1, 0x1C = Pad2, ... */ } @@ -637,8 +645,7 @@ void jcart_write(uint32 address, uint32 data) void input_init(void) { int i,j; - - input.max = 0; + int player = 0; for (i=0; ibuttons[0].y -= 90; m->buttons[1].y -= 90; m->buttons[2].y -= 90; + m->buttons[0].shift[1] = 3; + m->buttons[1].shift[1] = 3; + m->buttons[2].shift[1] = 3; + m->buttons[2].shift[3] = 1; m->buttons[3].state |= (BUTTON_VISIBLE | BUTTON_ACTIVE); m->buttons[4].state |= (BUTTON_VISIBLE | BUTTON_ACTIVE); m->buttons[5].state |= (BUTTON_VISIBLE | BUTTON_ACTIVE); diff --git a/source/gx/gx_input.c b/source/gx/gx_input.c index 2e462f8..cd5de24 100644 --- a/source/gx/gx_input.c +++ b/source/gx/gx_input.c @@ -58,9 +58,6 @@ static const char *keys_name[MAX_KEYS] = "MODE Button" }; -static int held_cnt = 0; - - #ifdef HW_RVL #define PAD_UP 0 @@ -75,8 +72,11 @@ static u32 wpad_dirmap[3][4] = {WPAD_BUTTON_UP, WPAD_BUTTON_DOWN, WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT}, /* WIIMOTE + NUNCHUK */ {WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT} /* CLASSIC */ }; + #endif +static int held_cnt = 0; +static int softreset = 0; /***************************************************************************************/ /* Gamecube PAD support */ @@ -159,23 +159,29 @@ static void pad_update(s8 chan, u8 i) s8 x = PAD_StickX (chan); s8 y = PAD_StickY (chan); + /* Soft Reset */ + if ((p & PAD_TRIGGER_Z) && (p & PAD_TRIGGER_L)) + { + gen_softreset(1); + softreset = 1; + return; + } + else if (softreset & 1) + { + gen_softreset(0); + softreset = 0; + return; + } + + /* Menu Request */ if (p & PAD_TRIGGER_Z) { - /* Menu Request */ ConfigRequested = 1; return; } - else if ((p & PAD_TRIGGER_L) && (p & PAD_TRIGGER_Z)) - { - /* Soft RESET */ - if (config.lock_on == TYPE_AR) - datel_reset(0); - gen_reset(0); - } /* Retrieve current key mapping */ - u16 pad_keymap[MAX_KEYS]; - memcpy(pad_keymap, config.pad_keymap[chan], MAX_KEYS * sizeof(u16)); + u16 *pad_keymap = config.pad_keymap[chan]; /* Generic buttons */ if (p & pad_keymap[KEY_BUTTONA]) @@ -214,7 +220,7 @@ static void pad_update(s8 chan, u8 i) case DEVICE_MOUSE: { - /* MOUSE relative movement (-255,255) */ + /* Mouse relative movement (-255,255) */ input.analog[2][0] = (x / ANALOG_SENSITIVITY) * 2; input.analog[2][1] = (y / ANALOG_SENSITIVITY) * 2; if (config.invert_mouse) @@ -226,7 +232,7 @@ static void pad_update(s8 chan, u8 i) { if (system_hw != SYSTEM_PICO) { - /* gamepad */ + /* Gamepad */ if ((p & PAD_BUTTON_UP) || (y > ANALOG_SENSITIVITY)) input.pad[i] |= INPUT_UP; else if ((p & PAD_BUTTON_DOWN) || (y < -ANALOG_SENSITIVITY)) @@ -463,21 +469,27 @@ static void wpad_update(s8 chan, u8 i, u32 exp) s8 x = 0; s8 y = 0; u32 p = data->btns_h; - u32 u = data->btns_u; - if ((u & WPAD_BUTTON_HOME) || (u & WPAD_CLASSIC_BUTTON_HOME)) + /* Soft Reset */ + if (((p & WPAD_BUTTON_PLUS) && (p & WPAD_BUTTON_MINUS)) || + ((p & WPAD_CLASSIC_BUTTON_PLUS) && (p & WPAD_CLASSIC_BUTTON_MINUS))) { - /* Menu Request */ - ConfigRequested = 1; + gen_softreset(1); + softreset = 1; return; } - else if (((p & WPAD_BUTTON_PLUS) && (p & WPAD_BUTTON_MINUS)) || - ((p & WPAD_CLASSIC_BUTTON_PLUS) && (p & WPAD_CLASSIC_BUTTON_MINUS))) + else if (softreset & 1) { - /* Soft RESET */ - if (config.lock_on == TYPE_AR) - datel_reset(0); - gen_reset(0); + gen_softreset(0); + softreset = 0; + return; + } + + /* Menu Request */ + if ((p & WPAD_BUTTON_HOME) || (p & WPAD_CLASSIC_BUTTON_HOME)) + { + ConfigRequested = 1; + return; } /* Retrieve current key mapping */ @@ -816,38 +828,43 @@ void gx_input_UpdateEmu(void) int i; int player = 0; - /* update controllers */ + /* Update controllers */ PAD_ScanPads(); #ifdef HW_RVL WPAD_ScanPads(); #endif -#ifdef HW_RVL + /* Check RESET button status */ if (SYS_ResetButtonDown()) { - /* Soft RESET */ - if (config.lock_on == TYPE_AR) - datel_reset(0); - gen_reset(0); + gen_softreset(1); + softreset = 2; + return; + } + else if (softreset & 2) + { + gen_softreset(0); + softreset = 0; + return; } -#endif for (i=0; i 0) wpad_update(config.input[player].port,i, config.input[player].device - 1); #endif + /* increment player index */ player ++; } } diff --git a/source/gx/gx_video.c b/source/gx/gx_video.c index f505148..d8c5f9a 100644 --- a/source/gx/gx_video.c +++ b/source/gx/gx_video.c @@ -60,8 +60,6 @@ u32 gc_pal = 0; /*** NTSC Filters ***/ sms_ntsc_t *sms_ntsc; md_ntsc_t *md_ntsc; -static const sms_ntsc_setup_t *sms_setup; -static const md_ntsc_setup_t *md_setup; /*** GX FIFO ***/ static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32); @@ -1267,10 +1265,10 @@ void gxTextureClose(gx_texture **p_texture) void gx_video_Stop(void) { /* unallocate NTSC filters */ - if (sms_ntsc) - free(sms_ntsc); - if (md_ntsc) - free(md_ntsc); + if (sms_ntsc) free(sms_ntsc); + if (md_ntsc) free(md_ntsc); + sms_ntsc = NULL; + md_ntsc = NULL; /* lightgun textures */ gxTextureClose(&crosshair[0]); @@ -1351,36 +1349,33 @@ void gx_video_Start(void) /* reinitialize video size */ vwidth = bitmap.viewport.w + (2 * bitmap.viewport.x); vheight = bitmap.viewport.h + (2 * bitmap.viewport.y); + bitmap.viewport.changed = 1; /* NTSC filter */ - sms_ntsc = NULL; - md_ntsc = NULL; if (config.ntsc) { /* allocate filters */ - sms_ntsc = (sms_ntsc_t *)memalign(32,sizeof(sms_ntsc_t)); - md_ntsc = (md_ntsc_t *)memalign(32,sizeof(md_ntsc_t)); + if (!sms_ntsc) + sms_ntsc = (sms_ntsc_t *)memalign(32,sizeof(sms_ntsc_t)); + if (!md_ntsc) + md_ntsc = (md_ntsc_t *)memalign(32,sizeof(md_ntsc_t)); /* setup filters default configuration */ switch (config.ntsc) { case 1: - sms_setup = &sms_ntsc_composite; - md_setup = &md_ntsc_composite; + sms_ntsc_init(sms_ntsc, &sms_ntsc_composite); + md_ntsc_init(md_ntsc, &md_ntsc_composite); break; case 2: - sms_setup = &sms_ntsc_svideo; - md_setup = &md_ntsc_svideo; + sms_ntsc_init(sms_ntsc, &sms_ntsc_svideo); + md_ntsc_init(md_ntsc, &md_ntsc_svideo); break; case 3: - sms_setup = &sms_ntsc_rgb; - md_setup = &md_ntsc_rgb; + sms_ntsc_init(sms_ntsc, &sms_ntsc_rgb); + md_ntsc_init(md_ntsc, &md_ntsc_rgb); break; } - - /* initialize filters */ - sms_ntsc_init(sms_ntsc, sms_setup); - md_ntsc_init(md_ntsc, md_setup); } /* lightgun textures */ @@ -1389,9 +1384,6 @@ void gx_video_Start(void) if (config.gun_cursor[1] && (input.dev[5] == DEVICE_LIGHTGUN)) crosshair[1] = gxTextureOpenPNG(Crosshair_p2_png,0); - /* force changes on next video update */ - bitmap.viewport.changed = 1; - /* GX emulation rendering */ gxResetRendering(0); diff --git a/source/hvc.h b/source/hvc.h index 8a74083..a6214f4 100644 --- a/source/hvc.h +++ b/source/hvc.h @@ -516,7 +516,7 @@ const uint8 cycle2hc40[3420] = const uint8 cycle2hc32[3420] = { /* end of active display (16 pixels -> 160 Mcycles) , HINT triggered ? , Vcounter jump */ - 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, + 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x86, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x87, 0x88, 0x88, 0x88, 0x88, @@ -748,7 +748,8 @@ const uint8 cycle2hc32[3420] = 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x83, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, - 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, + 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x84, 0x85, 0x85, 0x85, 0x85, + 0x85, 0x85, 0x85, 0x85, 0x85, 0x85, }; const uint8 *vctab; diff --git a/source/mem68k.c b/source/mem68k.c index 2522533..567df58 100644 --- a/source/mem68k.c +++ b/source/mem68k.c @@ -67,8 +67,7 @@ void m68k_lockup_w_8 (uint32 address, uint32 data) #ifdef LOGERROR error ("Lockup %08X = %02X (%08X)\n", address, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif - gen_running = config.force_dtack; - if (!gen_running) + if (!config.force_dtack) m68k_pulse_halt (); } @@ -77,8 +76,7 @@ void m68k_lockup_w_16 (uint32 address, uint32 data) #ifdef LOGERROR error ("Lockup %08X = %04X (%08X)\n", address, data, m68k_get_reg (NULL, M68K_REG_PC)); #endif - gen_running = config.force_dtack; - if (!gen_running) + if (!config.force_dtack) m68k_pulse_halt (); } @@ -87,8 +85,7 @@ uint32 m68k_lockup_r_8 (uint32 address) #ifdef LOGERROR error ("Lockup %08X.b (%08X)\n", address, m68k_get_reg (NULL, M68K_REG_PC)); #endif - gen_running = config.force_dtack; - if (!gen_running) + if (!config.force_dtack) m68k_pulse_halt (); return -1; } @@ -98,8 +95,7 @@ uint32 m68k_lockup_r_16 (uint32 address) #ifdef LOGERROR error ("Lockup %08X.w (%08X)\n", address, m68k_get_reg (NULL, M68K_REG_PC)); #endif - gen_running = config.force_dtack; - if (!gen_running) + if (!config.force_dtack) m68k_pulse_halt (); return -1; } @@ -371,14 +367,14 @@ void ctrl_io_write_byte(uint32 address, uint32 data) if (address & 1) m68k_unused_8_w(address, data); else - gen_busreq_w(data & 1); + gen_busreq_w(data & 1, mcycles_68k); return; case 0x12: /* RESET */ if (address & 1) m68k_unused_8_w(address, data); else - gen_reset_w(data & 1); + gen_reset_w(data & 1, mcycles_68k); return; case 0x30: /* TIME */ @@ -430,11 +426,11 @@ void ctrl_io_write_word(uint32 address, uint32 data) return; case 0x11: /* BUSREQ */ - gen_busreq_w ((data >> 8) & 1); + gen_busreq_w ((data >> 8) & 1, mcycles_68k); return; case 0x12: /* RESET */ - gen_reset_w ((data >> 8) & 1); + gen_reset_w ((data >> 8) & 1, mcycles_68k); return; case 0x50: /* SVP REGISTERS */ @@ -503,18 +499,18 @@ uint32 vdp_read_byte(uint32 address) return (vdp_data_r() & 0xff); case 0x04: /* CTRL */ - return ((m68k_read_pcrelative_8(REG_PC) & 0xfc) | ((vdp_ctrl_r() >> 8) & 3)); + return ((m68k_read_pcrelative_8(REG_PC) & 0xfc) | ((vdp_ctrl_r(mcycles_68k) >> 8) & 3)); case 0x05: /* CTRL */ - return (vdp_ctrl_r() & 0xff); + return (vdp_ctrl_r(mcycles_68k) & 0xff); case 0x08: /* HVC */ case 0x0c: - return (vdp_hvc_r() >> 8); + return (vdp_hvc_r(mcycles_68k) >> 8); case 0x09: /* HVC */ case 0x0d: - return (vdp_hvc_r() & 0xff); + return (vdp_hvc_r(mcycles_68k) & 0xff); case 0x18: /* Unused */ case 0x19: @@ -535,11 +531,11 @@ uint32 vdp_read_word(uint32 address) return vdp_data_r(); case 0x04: /* CTRL */ - return ((vdp_ctrl_r() & 0x3FF) | (m68k_read_pcrelative_16(REG_PC) & 0xFC00)); + return ((vdp_ctrl_r(mcycles_68k) & 0x3FF) | (m68k_read_pcrelative_16(REG_PC) & 0xFC00)); case 0x08: /* HVC */ case 0x0c: - return vdp_hvc_r(); + return vdp_hvc_r(mcycles_68k); case 0x18: /* Unused */ case 0x1c: diff --git a/source/membnk.c b/source/membnk.c index 3b616f2..af49a90 100644 --- a/source/membnk.c +++ b/source/membnk.c @@ -47,7 +47,11 @@ uint32 zbank_lockup_r(uint32 address) #ifdef LOGERROR error("Z80 bank lockup read %06X\n", address); #endif - gen_running = config.force_dtack; + if (!config.force_dtack) + { + mcycles_z80 = 0xffffffff; + zstate = 0; + } return 0xFF; } @@ -56,7 +60,11 @@ void zbank_lockup_w(uint32 address, uint32 data) #ifdef LOGERROR error("Z80 bank lockup write %06X = %02X\n", address, data); #endif - gen_running = config.force_dtack; + if (!config.force_dtack) + { + mcycles_z80 = 0xffffffff; + zstate = 0; + } } /* I/O & Control registers */ @@ -108,14 +116,14 @@ void zbank_write_ctrl_io(uint32 address, uint32 data) if (address & 1) zbank_unused_w(address, data); else - gen_busreq_w(data & 1); + gen_busreq_w(data & 1, mcycles_z80); return; case 0x12: /* RESET */ if (address & 1) zbank_unused_w(address, data); else - gen_reset_w(data & 1); + gen_reset_w(data & 1, mcycles_z80); return; case 0x30: /* TIME */ @@ -168,18 +176,18 @@ uint32 zbank_read_vdp(uint32 address) return (vdp_data_r() & 0xff); case 0x04: /* CTRL */ - return (0xfc | ((vdp_ctrl_r() >> 8) & 3)); + return (0xfc | ((vdp_ctrl_r(mcycles_z80) >> 8) & 3)); case 0x05: /* CTRL */ - return (vdp_ctrl_r() & 0xff); + return (vdp_ctrl_r(mcycles_z80) & 0xff); case 0x08: /* HVC */ case 0x0c: - return (vdp_hvc_r() >> 8); + return (vdp_hvc_r(mcycles_z80) >> 8); case 0x09: /* HVC */ case 0x0d: - return (vdp_hvc_r() & 0xff); + return (vdp_hvc_r(mcycles_z80) & 0xff); case 0x18: /* Unused */ case 0x19: diff --git a/source/memz80.c b/source/memz80.c index 649f4e5..29c9b8a 100644 --- a/source/memz80.c +++ b/source/memz80.c @@ -46,7 +46,11 @@ static inline void z80_lockup_w(unsigned int address, unsigned int data) #ifdef LOGERROR error("Z80 lockup write %04X = %02X\n", address, data); #endif - gen_running = config.force_dtack; + if (!config.force_dtack) + { + mcycles_z80 = 0xffffffff; + zstate = 0; + } } static inline unsigned int z80_lockup_r(unsigned int address) @@ -54,7 +58,11 @@ static inline unsigned int z80_lockup_r(unsigned int address) #ifdef LOGERROR error("Z80 lockup read %04X\n", address); #endif - gen_running = config.force_dtack; + if (!config.force_dtack) + { + mcycles_z80 = 0xffffffff; + zstate = 0; + } return 0xff; } /* @@ -71,18 +79,18 @@ static inline unsigned int z80_vdp_r(unsigned int address) return (vdp_data_r() & 0xff); case 0x04: /* CTRL */ - return (0xfc | (vdp_ctrl_r() >> 8)); + return (0xfc | (vdp_ctrl_r(mcycles_z80) >> 8)); case 0x05: /* CTRL */ - return (vdp_ctrl_r() & 0xff); + return (vdp_ctrl_r(mcycles_z80) & 0xff); case 0x08: /* HVC */ case 0x0c: - return (vdp_hvc_r() >> 8); + return (vdp_hvc_r(mcycles_z80) >> 8); case 0x09: /* HVC */ case 0x0d: - return (vdp_hvc_r() & 0xff); + return (vdp_hvc_r(mcycles_z80) & 0xff); case 0x18: /* Unused */ case 0x19: diff --git a/source/system.c b/source/system.c index 96860f2..aa0ac1d 100644 --- a/source/system.c +++ b/source/system.c @@ -300,7 +300,7 @@ void system_reset (void) cart_hw_reset(); /* Genesis hardware */ - gen_reset(1); + gen_hardreset(); io_reset(); vdp_reset(); render_reset(); @@ -325,14 +325,8 @@ void system_shutdown (void) /**************************************************************** * Virtual Genesis Frame emulation ****************************************************************/ -int system_frame (int do_skip) +void system_frame (int do_skip) { - if (!gen_running) - { - osd_input_Update(); - return 0; - } - /* update display settings */ int line; int vdp_height = bitmap.viewport.h; @@ -346,8 +340,7 @@ int system_frame (int do_skip) im2_flag = ((reg[12] & 6) == 6); odd_frame = 1; } - odd_frame ^= 1; - + /* clear VBLANK, DMA, FIFO FULL & field flags */ status &= 0xFEE5; @@ -355,6 +348,7 @@ int system_frame (int do_skip) status |= 0x0200; /* even/odd field flag (interlaced modes only) */ + odd_frame ^= 1; if (odd_frame && interlaced) status |= 0x0010; @@ -473,6 +467,4 @@ int system_frame (int do_skip) /* adjust cpu cycle count for next frame */ mcycles_68k -= mcycles_vdp; mcycles_z80 -= mcycles_vdp; - - return gen_running; } diff --git a/source/system.h b/source/system.h index adf9d76..6d8e263 100644 --- a/source/system.h +++ b/source/system.h @@ -89,7 +89,7 @@ extern void audio_set_equalizer(void); extern void system_init (void); extern void system_reset (void); extern void system_shutdown (void); -extern int system_frame(int skip); +extern void system_frame(int do_skip); #endif /* _SYSTEM_H_ */ diff --git a/source/unused/win/Makefile b/source/unused/win/Makefile index f049a84..9b8d2ec 100644 --- a/source/unused/win/Makefile +++ b/source/unused/win/Makefile @@ -5,19 +5,18 @@ # modified by Eke-Eke # # Defines : -# LSB_FIRST : for little endian systems. -# X86_ASM : enable x86 assembly optimizations -# LOGERROR -# LOGVDP -# LOGSOUND +# -DLSB_FIRST : for little endian systems. +# -DLOGERROR : enable message log +# -DLOGVDP : enable VDP debug messages +# -DLOGSOUND : enable AUDIO debug messages NAME = gen_sdl.exe CC = gcc -CFLAGS = `sdl-config --cflags` -O6 -march=i686 -fomit-frame-pointer +CFLAGS = `sdl-config --cflags` -march=i686 -O6 -fomit-frame-pointer -Wall -Wno-strict-aliasing #-g -ggdb -pg #-fomit-frame-pointer -#LDFLAGS = -g -ggdb -pg +#LDFLAGS = -pg DEFINES = -DLSB_FIRST -DX86_ASM INCLUDES = -I. -I.. -I../z80 -I../m68k -I../sound -I../cart_hw -I../cart_hw/svp -I../ntsc diff --git a/source/unused/win/config.c b/source/unused/win/config.c index 209f03c..afd9daa 100644 --- a/source/unused/win/config.c +++ b/source/unused/win/config.c @@ -20,6 +20,8 @@ void set_config_defaults(void) config.mg = 1.0; config.hg = 1.0; config.lp_range = 50; + config.rolloff = 0.999; + config.dac_bits = 14; /* system options */ config.region_detect = 0; @@ -30,7 +32,7 @@ void set_config_defaults(void) config.romtype = 0; /* display options */ - config.overscan = 1; + config.overscan = 0; config.render = 0; /* controllers options */ diff --git a/source/unused/win/config.h b/source/unused/win/config.h index ca026ab..3b2a917 100644 --- a/source/unused/win/config.h +++ b/source/unused/win/config.h @@ -24,6 +24,8 @@ typedef struct float lg; float mg; float hg; + float rolloff; + uint8 dac_bits; uint8 region_detect; uint8 force_dtack; uint8 addr_error; diff --git a/source/unused/win/main.c b/source/unused/win/main.c index e975a2c..0638019 100644 --- a/source/unused/win/main.c +++ b/source/unused/win/main.c @@ -10,8 +10,8 @@ #define SOUND_FREQUENCY 48000 #define SOUND_SAMPLES_SIZE 2048 -#define VIDEO_WIDTH 640 -#define VIDEO_HEIGHT 480 +#define VIDEO_WIDTH 320 +#define VIDEO_HEIGHT 240 int joynum = 0; @@ -117,8 +117,8 @@ static void sdl_sound_close() } /* video */ -md_ntsc_t md_ntsc; -sms_ntsc_t sms_ntsc; +md_ntsc_t *md_ntsc; +sms_ntsc_t *sms_ntsc; struct { SDL_Surface* surf_screen; @@ -158,29 +158,41 @@ static void sdl_video_update() rect.x=(VIDEO_WIDTH-rect.w)/2; rect.y=(VIDEO_HEIGHT-rect.h)/2; - /* init NTSC filter */ - md_ntsc_setup_t md_setup; - sms_ntsc_setup_t sms_setup; - if (config.ntsc == 1) + /* NTSC filters */ + if (config.ntsc) { - sms_setup = sms_ntsc_composite; - md_setup = md_ntsc_composite; - sms_ntsc_init( &sms_ntsc, &sms_setup ); - md_ntsc_init( &md_ntsc, &md_setup ); + sms_ntsc = (sms_ntsc_t *)malloc(sizeof(sms_ntsc_t)); + md_ntsc = (md_ntsc_t *)malloc(sizeof(md_ntsc_t)); + + switch (config.ntsc) + { + case 1: + sms_ntsc_init(sms_ntsc, &sms_ntsc_composite); + md_ntsc_init(md_ntsc, &md_ntsc_composite); + break; + case 2: + sms_ntsc_init(sms_ntsc, &sms_ntsc_svideo); + md_ntsc_init(md_ntsc, &md_ntsc_svideo); + break; + case 3: + sms_ntsc_init(sms_ntsc, &sms_ntsc_rgb); + md_ntsc_init(md_ntsc, &md_ntsc_rgb); + break; + } } - else if (config.ntsc == 2) + else { - sms_setup = sms_ntsc_svideo; - md_setup = md_ntsc_svideo; - sms_ntsc_init( &sms_ntsc, &sms_setup ); - md_ntsc_init( &md_ntsc, &md_setup ); - } - else if (config.ntsc == 3) - { - sms_setup = sms_ntsc_rgb; - md_setup = md_ntsc_rgb; - sms_ntsc_init( &sms_ntsc, &sms_setup ); - md_ntsc_init( &md_ntsc, &md_setup ); + if (sms_ntsc) + { + free(sms_ntsc); + sms_ntsc = NULL; + } + + if (md_ntsc) + { + free(md_ntsc); + md_ntsc = NULL; + } } } @@ -193,8 +205,10 @@ static void sdl_video_update() static void sdl_video_close() { - if (sdl_video.surf_bitmap) SDL_FreeSurface(sdl_video.surf_bitmap); - if (sdl_video.surf_screen) SDL_FreeSurface(sdl_video.surf_screen); + if (sdl_video.surf_bitmap) + SDL_FreeSurface(sdl_video.surf_bitmap); + if (sdl_video.surf_screen) + SDL_FreeSurface(sdl_video.surf_screen); } /* Timer Sync */ @@ -209,18 +223,13 @@ struct { static Uint32 sdl_sync_timer_callback(Uint32 interval) { SDL_SemPost(sdl_sync.sem_sync); - char caption[100]; - char region[10]; - if (region_code == REGION_USA) sprintf(region,"USA"); - else if (region_code == REGION_EUROPE) sprintf(region,"EUR"); - else sprintf(region,"JAP"); - + char caption[100]; sdl_sync.ticks++; if (sdl_sync.ticks == (vdp_pal ? 50 : 20)) { int fps = vdp_pal ? (sdl_video.frames_rendered / 3) : sdl_video.frames_rendered; sdl_sync.ticks = sdl_video.frames_rendered = 0; - sprintf(caption, "Genesis Plus/SDL - %s (%s) - 0x%04X - %d fps", rominfo.international, region, rominfo.realchecksum, fps); + sprintf(caption, "Genesis Plus SDL - %d fps", fps); SDL_WM_SetCaption(caption, NULL); } return interval; @@ -228,10 +237,12 @@ static Uint32 sdl_sync_timer_callback(Uint32 interval) static int sdl_sync_init() { - if(SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_EVENTTHREAD) < 0) { + if(SDL_InitSubSystem(SDL_INIT_TIMER|SDL_INIT_EVENTTHREAD) < 0) + { MessageBox(NULL, "SDL Timer initialization failed", "Error", 0); return 0; } + sdl_sync.sem_sync = SDL_CreateSemaphore(0); sdl_sync.ticks = 0; return 1; @@ -347,7 +358,7 @@ static int sdl_control_update(SDLKey keystate) case SDLK_F10: { - set_softreset(); + gen_softreset(0); break; } @@ -433,7 +444,8 @@ int sdl_input_update(void) input.analog[2][1] = y; /* Vertical movement is upsidedown */ - if (!config.invert_mouse) input.analog[2][1] = 0 - input.analog[2][1]; + if (!config.invert_mouse) + input.analog[2][1] = 0 - input.analog[2][1]; /* Map mouse buttons to player #1 inputs */ if(state & SDL_BUTTON_MMASK) input.pad[joynum] |= INPUT_C; @@ -463,8 +475,8 @@ int sdl_input_update(void) int state = SDL_GetMouseState(&x,&y); /* Calculate X Y axis values */ - input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / 640; - input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / 480; + input.analog[0][0] = 0x3c + (x * (0x17c-0x03c+1)) / VIDEO_WIDTH; + input.analog[0][1] = 0x1fc + (y * (0x2f7-0x1fc+1)) / VIDEO_HEIGHT; /* Map mouse buttons to player #1 inputs */ if(state & SDL_BUTTON_MMASK) pico_current++; @@ -601,7 +613,7 @@ int main (int argc, char **argv) f = fopen("./game.srm", "wb"); if (f!=NULL) { - fwrite(&sram.sram,0x10000,1, f); + fwrite(sram.sram,0x10000,1, f); fclose(f); } diff --git a/source/vdp.c b/source/vdp.c index f80cec0..614995b 100644 --- a/source/vdp.c +++ b/source/vdp.c @@ -50,7 +50,8 @@ uint16 status; /* VDP status flags */ uint8 dmafill; /* next VDP Write is DMA Fill */ uint8 hint_pending; /* 0= Line interrupt is pending */ uint8 vint_pending; /* 1= Frame interrupt is pending */ -uint8 irq_status; /* Interrupt lines updated */ +uint8 zirq; /* Z80 IRQ status */ +uint8 irq_status; /* 68K IRQ status */ /* Global variables */ uint16 ntab; /* Name table A base address */ @@ -127,7 +128,7 @@ static const uint32 dma_rates[16] = { /*--------------------------------------------------------------------------*/ /* Functions prototype */ /*--------------------------------------------------------------------------*/ -static void fifo_update(); +static void fifo_update(unsigned int cycles); static void data_w(unsigned int data); static void reg_w(unsigned int r, unsigned int d); static void dma_copy(void); @@ -160,6 +161,7 @@ void vdp_reset(void) pending = 0; hint_pending = 0; vint_pending = 0; + zirq = 0; irq_status = 0; hvc_latch = 0; v_counter = 0; @@ -172,7 +174,7 @@ void vdp_reset(void) interlaced = 0; fifo_write_cnt = 0; fifo_lastwrite = 0; - fifo_latency = 190; /* default FIFO timings */ + fifo_latency = 190; status = vdp_pal | 0x0200; /* FIFO empty */ @@ -422,13 +424,13 @@ void vdp_ctrl_w(unsigned int data) * 9 Write FIFO empty * 10 - 15 Open Bus */ -unsigned int vdp_ctrl_r(void) +unsigned int vdp_ctrl_r(unsigned int cycles) { /* update FIFO flags */ - fifo_update(); + fifo_update(cycles); /* update DMA Busy flag */ - if ((status & 2) && !dma_length && (mcycles_68k >= dma_endCycles)) + if ((status & 2) && !dma_length && (cycles >= dma_endCycles)) status &= 0xFFFD; unsigned int temp = status; @@ -438,7 +440,7 @@ unsigned int vdp_ctrl_r(void) temp |= 0x08; /* HBLANK flag (Sonic 3 and Sonic 2 "VS Modes", Lemmings 2, Mega Turrican, V.R Troopers, Gouketsuji Ichizoku, ...) */ - if ((mcycles_68k % MCYCLES_PER_LINE) < 588) + if ((cycles % MCYCLES_PER_LINE) < 588) temp |= 0x04; /* clear pending flag */ @@ -448,19 +450,19 @@ unsigned int vdp_ctrl_r(void) status &= 0xFF9F; #ifdef LOGVDP - error("[%d(%d)][%d(%d)] VDP status read -> 0x%x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE, temp, m68k_get_reg (NULL, M68K_REG_PC)); + error("[%d(%d)][%d(%d)] VDP status read -> 0x%x (%x)\n", v_counter, cycles/MCYCLES_PER_LINE, cycles, cycles%MCYCLES_PER_LINE, temp, m68k_get_reg (NULL, M68K_REG_PC)); #endif return (temp); } -unsigned int vdp_hvc_r(void) +unsigned int vdp_hvc_r(unsigned int cycles) { - /* HVC is frozen (Lightgun games + Sunset Riders) */ + /* HVC is frozen (Lightgun games, Sunset Riders) */ if (hvc_latch) return (hvc_latch & 0xffff); - /* Horizontal Counter (Striker, Mickey Mania, Skitchin, Road Rash I,II,III, ...) */ - uint8 hc = hctab[mcycles_68k%MCYCLES_PER_LINE]; + /* Horizontal Counter (Striker, Mickey Mania, Skitchin, Road Rash I,II,III, Sonic 3D Blast...) */ + uint8 hc = hctab[cycles%MCYCLES_PER_LINE]; /* Vertical Counter */ uint8 vc = vctab[v_counter]; @@ -470,7 +472,7 @@ unsigned int vdp_hvc_r(void) vc = (vc << 1) | ((vc >> 7) & 1); #ifdef LOGVDP - error("[%d(%d)][%d(%d)] VDP HVC Read -> 0x%04x (%x)\n", v_counter, mcycles_68k/MCYCLES_PER_LINE, mcycles_68k, mcycles_68k%MCYCLES_PER_LINE,(vc << 8) | hc, m68k_get_reg (NULL, M68K_REG_PC)); + error("[%d(%d)][%d(%d)] VDP HVC Read -> 0x%04x (%x)\n", v_counter, cycles/MCYCLES_PER_LINE, cycles, cycles%MCYCLES_PER_LINE,(vc << 8) | hc, m68k_get_reg (NULL, M68K_REG_PC)); #endif return ((vc << 8) | hc); } @@ -497,7 +499,7 @@ void vdp_data_w(unsigned int data) if (!(status&8) && (reg[1]&0x40)) { /* update VDP FIFO */ - fifo_update(); + fifo_update(mcycles_68k); if (fifo_write_cnt == 0) { @@ -625,12 +627,12 @@ int vdp_int_ack_callback(int int_level) /*--------------------------------------------------------------------------*/ /* FIFO emulation */ /*--------------------------------------------------------------------------*/ -static void fifo_update() +static void fifo_update(unsigned int cycles) { if (fifo_write_cnt > 0) { /* update FIFO reads */ - int fifo_read = ((mcycles_68k - fifo_lastwrite) / fifo_latency); + int fifo_read = ((cycles - fifo_lastwrite) / fifo_latency); if (fifo_read > 0) { fifo_write_cnt -= fifo_read; diff --git a/source/vdp.h b/source/vdp.h index ea3d09a..5ebecdd 100644 --- a/source/vdp.h +++ b/source/vdp.h @@ -38,6 +38,7 @@ extern uint16 status; extern uint8 dmafill; extern uint8 hint_pending; extern uint8 vint_pending; +extern uint8 zirq; extern uint8 irq_status; /* Global variables */ @@ -80,10 +81,10 @@ extern void vdp_shutdown(void); extern void vdp_restore(uint8 *vdp_regs); extern void vdp_update_dma(); extern void vdp_ctrl_w(unsigned int data); -extern unsigned int vdp_ctrl_r(void); +extern unsigned int vdp_ctrl_r(unsigned int cycles); extern void vdp_data_w(unsigned int data); extern unsigned int vdp_data_r(void); -extern unsigned int vdp_hvc_r(void); +extern unsigned int vdp_hvc_r(unsigned int cycles); extern void vdp_test_w(unsigned int value); extern int vdp_int_ack_callback(int int_level);