diff --git a/Makefile.wii b/Makefile.wii index 01a9390..0827d2f 100644 --- a/Makefile.wii +++ b/Makefile.wii @@ -26,7 +26,7 @@ INCLUDES := source source/m68k source/z80 source/sound source/sound/SRC source/n # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -O3 -mrvl -Wall $(MACHDEP) -Wno-strict-aliasing $(INCLUDE) -DWORDS_BIGENDIAN -DNGC="1" -DHW_RVL +CFLAGS = -O3 -g -mrvl -Wall $(MACHDEP) -Wno-strict-aliasing $(INCLUDE) -DWORDS_BIGENDIAN -DNGC="1" -DHW_RVL CXXFLAGS = $(CFLAGS) LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map diff --git a/source/cart_hw/eeprom.c b/source/cart_hw/eeprom.c index bcfa342..041972f 100644 --- a/source/cart_hw/eeprom.c +++ b/source/cart_hw/eeprom.c @@ -28,7 +28,7 @@ typedef struct T_EEPROM_TYPE type; } T_GAME_ENTRY; -T_GAME_ENTRY database[24] = +T_GAME_ENTRY database[25] = { /* ACCLAIM mappers */ /* 24C02 (old mapper) */ @@ -43,11 +43,11 @@ T_GAME_ENTRY database[24] = /* 24C65 */ {{"T-81576" }, 0, {16, 0x1FFF, 0x1FFF, 0x200001, 0x200001, 0x200000, 0, 0, 0}}, /* College Slam */ {{"T-81476" }, 0, {16, 0x1FFF, 0x1FFF, 0x200001, 0x200001, 0x200000, 0, 0, 0}}, /* Frank Thomas Big Hurt Baseball */ - + /* EA mapper (24C01 only) */ {{"T-50396" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 7, 7, 6}}, /* NHLPA Hockey 93 (UE) */ {{"T-50176" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 7, 7, 6}}, /* Rings of Power */ - + /* SEGA mapper (24C01 only) */ {{"T-12046" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Megaman - The Wily Wars */ {{"T-12053" }, 0xEA80, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Rockman Mega World (J) [A] */ @@ -57,7 +57,8 @@ T_GAME_ENTRY database[24] = {{"PR-1993" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Greatest Heavyweights of the Ring (E) */ {{"G-4060" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Wonderboy in Monster World */ {{"00001211-00"}, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Sports Talk Baseball */ - + {{"00004076-00"}, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Honoo no Toukyuuji Dodge Danpei */ + /* CODEMASTERS mapper */ /* 24C01 */ {{"T-120106"}, 0, {7, 0x7F, 0x7F, 0x300000, 0x380001, 0x300000, 0, 7, 1}}, /* Brian Lara Cricket */ @@ -110,8 +111,8 @@ void eeprom_init() if ((sram.end - sram.start) < 2) { sram.custom = 1; - sram.on = 1; - sram.write = 1; + sram.on = 1; + sram.write = 1; /* set SEGA mapper as default */ memcpy(&eeprom.type, &database[9].type, sizeof(T_EEPROM_TYPE)); diff --git a/source/cart_hw/sram.c b/source/cart_hw/sram.c index 7b11a15..834706b 100644 --- a/source/cart_hw/sram.c +++ b/source/cart_hw/sram.c @@ -45,7 +45,7 @@ void sram_init() memset (&sram.sram[0], 0xFF, 0x10000); sram.crc = crc32 (0, &sram.sram[0], 0x10000); - if ((cart_rom[0x1b0] == 0x52) && (cart_rom[0x1b1] == 0x41)) + if ((READ_BYTE(cart_rom,0x1b0) == 0x52) && (READ_BYTE(cart_rom,0x1b1) == 0x41)) { /* retrieve informations from headezr */ sram.detected = 1; diff --git a/source/ngc/gui/menu.c b/source/ngc/gui/menu.c index 1760b63..8df6d57 100644 --- a/source/ngc/gui/menu.c +++ b/source/ngc/gui/menu.c @@ -1136,7 +1136,8 @@ void MainMenu () /* Switch to menu default rendering mode (60hz or 50hz, but always 480 lines) */ VIDEO_Configure (vmode); - VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); + VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); + VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); VIDEO_WaitVSync(); @@ -1221,11 +1222,11 @@ void MainMenu () while (WPAD_ButtonsHeld(0)) WPAD_ScanPads(); #endif - /*** Reinitialize GX ***/ - VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); + /*** Reinitialize VIDEO ***/ + VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); + VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_Flush(); VIDEO_WaitVSync(); - VIDEO_WaitVSync(); ogc_video__reset(); odd_frame = 1; diff --git a/source/ngc/ogc_audio.c b/source/ngc/ogc_audio.c index 32e5bb2..d85814e 100644 --- a/source/ngc/ogc_audio.c +++ b/source/ngc/ogc_audio.c @@ -35,6 +35,9 @@ u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32); /* Current work soundbuffer */ int mixbuffer; +/* Status of Audio playback */ +static int AudioStarted = 0; + /* Current DMA length (required to be a factor of 32-bytes) length is calculated regarding current emulation timings: PAL timings : 50 frames/sec, 48000 samples/sec = 960 samples per frame = 3840 bytes (16 bits stereo samples) @@ -97,10 +100,10 @@ void ogc_audio__update(void) void ogc_audio__start(void) { dma_len = vdp_pal ? 3840 : 3200; - memset(soundbuffer[0], 0, dma_len); AUDIO_InitDMA((u32) soundbuffer[0], dma_len); DCFlushRange(soundbuffer[0], dma_len); AUDIO_StartDMA(); + AudioStarted = 1; mixbuffer = 1; } @@ -113,5 +116,10 @@ void ogc_audio__start(void) ***/ void ogc_audio__stop(void) { - AUDIO_StopDMA (); + if (AudioStarted) + { + AUDIO_StopDMA (); + AudioStarted = 0; + memset(soundbuffer, 0, 2 * 3840); + } } diff --git a/source/ngc/ogc_video.c b/source/ngc/ogc_video.c index f7f3fb1..a8930b0 100644 --- a/source/ngc/ogc_video.c +++ b/source/ngc/ogc_video.c @@ -676,8 +676,8 @@ void ogc_video__init(void) ARAMPut ((char *) 0x80700000 + 0x20, (char *) 0x8000, genromsize); } - /* Get the current video mode then : - - set menu video mode (480p, 480i or 576i) + /* Get the current VIDEO mode then : + - set menu VIDEO mode (480p, 480i or 576i) - set emulator rendering TV modes (PAL/MPAL/NTSC/EURGB60) */ vmode = VIDEO_GetPreferredMode(NULL); @@ -729,7 +729,7 @@ void ogc_video__init(void) } #endif - /* Configure video mode */ + /* Configure VIDEO mode */ VIDEO_Configure (vmode); /* Configure the framebuffers (double-buffering) */ @@ -746,13 +746,14 @@ void ogc_video__init(void) /* Set the framebuffer to be displayed at next VBlank */ VIDEO_SetNextFramebuffer (xfb[0]); + /* Set Vertical Interrupt callbacks for VIDEO synchronization */ VIDEO_SetPreRetraceCallback(xfb_switch); VIDEO_SetPostRetraceCallback(xfb_copy); /* Enable Video Interface */ VIDEO_SetBlack (FALSE); - /* Update video settings for next VBlank */ + /* Update VIDEO settings for next VBlank */ VIDEO_Flush (); /* Wait for VBlank */ diff --git a/source/system.c b/source/system.c index bc22f86..6b43517 100644 --- a/source/system.c +++ b/source/system.c @@ -28,18 +28,12 @@ /* Global variables */ t_bitmap bitmap; t_snd snd; -uint8 vdp_rate; -uint16 lines_per_frame; -uint32 aim_m68k; uint32 count_m68k; uint32 line_m68k; uint32 hint_m68k; -uint32 aim_z80; uint32 count_z80; uint32 line_z80; int32 current_z80; -uint8 odd_frame; -uint8 interlaced; uint8 system_hw; static inline void audio_update (void); @@ -49,10 +43,6 @@ static inline void audio_update (void); ****************************************************************/ void system_init (void) { - /* PAL/NTSC timings */ - vdp_rate = vdp_pal ? 50 : 60; - lines_per_frame = vdp_pal ? 313 : 262; - gen_init (); vdp_init (); render_init (); @@ -60,31 +50,21 @@ void system_init (void) } /**************************************************************** - * Virtual Genesis Restart + * Virtual Genesis Hard Reset ****************************************************************/ void system_reset (void) { - aim_m68k = 0; - count_m68k = 0; - line_m68k = 0; - aim_z80 = 0; - count_z80 = 0; - line_z80 = 0; - current_z80 = 0; - odd_frame = 0; - interlaced = 0; - - /* Cart Hardware reset */ + /* Cartridge Hardware */ cart_hw_reset(); - /* Hard reset */ + /* Genesis Hardware */ gen_reset (1); vdp_reset (); render_reset (); io_reset(); SN76489_Reset(0); - /* Sound buffers reset */ + /* Sound Buffers */ memset (snd.psg.buffer, 0, SND_SIZE); memset (snd.fm.buffer[0], 0, SND_SIZE*2); memset (snd.fm.buffer[1], 0, SND_SIZE*2); @@ -111,10 +91,11 @@ int system_frame (int do_skip) return 0; } + int aim_m68k = 0; + int aim_z80 = 0; + /* reset cycles counts */ count_m68k = 0; - aim_m68k = 0; - aim_z80 = 0; count_z80 = 0; fifo_write_cnt = 0; fifo_lastwrite = 0; diff --git a/source/system.h b/source/system.h index b251d63..69ec40f 100644 --- a/source/system.h +++ b/source/system.h @@ -79,18 +79,12 @@ typedef struct /* Global variables */ extern t_bitmap bitmap; extern t_snd snd; -extern uint16 lines_per_frame; -extern uint8 vdp_rate; -extern uint32 aim_m68k; extern uint32 count_m68k; extern uint32 line_m68k; extern uint32 hint_m68k; -extern uint32 aim_z80; extern uint32 count_z80; extern uint32 line_z80; extern int32 current_z80; -extern uint8 interlaced; -extern uint8 odd_frame; extern uint8 system_hw; /* Function prototypes */ diff --git a/source/vdp.c b/source/vdp.c index e2f6d6c..adbc8e6 100644 --- a/source/vdp.c +++ b/source/vdp.c @@ -69,13 +69,16 @@ uint16 playfield_row_mask; /* Horizontal scroll mask */ uint32 y_mask; /* Name table Y-index bits mask */ uint16 hc_latch; /* latched HCounter (INT2) */ uint16 v_counter; /* VDP scanline counter */ -uint8 im2_flag; /* 1= Interlace mode 2 is being used */ uint32 dma_length; /* Current DMA remaining bytes */ int32 fifo_write_cnt; /* VDP writes fifo count */ uint32 fifo_lastwrite; /* last VDP write cycle */ uint8 fifo_latency; /* VDP write cycles latency */ -uint8 vdp_pal = 0; /* 1: PAL , 0: NTSC (default) */ - +uint8 odd_frame; /* 1: odd field , 0: even field */ +uint8 interlaced; /* 1: Interlace mode 1 or 2 */ +uint8 im2_flag; /* 1= Interlace mode 2 is being used */ +uint8 vdp_pal; /* 0: NTSC, 1: PAL */ +uint8 vdp_rate; /* NTSC: 60hz, PAL: 50hz */ +uint16 lines_per_frame; /* NTSC: 262 lines, PAL: 313 lines */ /* Tables that define the playfield layout */ static const uint8 shift_table[] = { 6, 7, 0, 8 }; @@ -133,9 +136,8 @@ static inline void data_write(unsigned int data); /*--------------------------------------------------------------------------*/ void vdp_init(void) { + /* DMA timings */ int i; - - /* reinitialize DMA timings table */ for (i=0; i<4; i++) { vdp_timings[0][i] = ((double)m68cycles_per_line) / ((double) dma_rates[i]); @@ -143,6 +145,10 @@ void vdp_init(void) vdp_timings[2][i] = ((double)m68cycles_per_line) / ((double) dma_rates[i + 8]); vdp_timings[3][i] = ((double)m68cycles_per_line) / ((double) dma_rates[i + 12]); } + + /* PAL/NTSC timings */ + vdp_rate = vdp_pal ? 50 : 60; + lines_per_frame = vdp_pal ? 313 : 262; } void vdp_reset(void) @@ -223,6 +229,10 @@ void vdp_reset(void) window_clip(1,0); } + /* non-interlaced display */ + odd_frame = 0; + interlaced = 0; + /* default latency */ fifo_latency = 27; } @@ -281,7 +291,7 @@ void dma_update() index += (reg[12] & 1); /* 32 or 40 Horizontal Cells */ /* calculate transfer quantity for the remaining 68k cycles */ - left_cycles = aim_m68k - count_m68k; + left_cycles = line_m68k + m68cycles_per_line - count_m68k; if (left_cycles < 0) left_cycles = 0; dma_bytes = (uint32)(((double)left_cycles / vdp_timings[dma_type][index]) + 0.5); @@ -310,7 +320,7 @@ void dma_update() /* VRAM Fill or VRAM Copy */ /* set DMA end cyles count */ dma_endCycles = count_m68k + dma_cycles; - + /* set DMA Busy flag */ status |= 0x0002; } @@ -382,7 +392,7 @@ static inline void dma_vbus (void) else if (source <= 0xa1001f) { temp = io_read((source >> 1) & 0x0f); - temp = (temp << 8 | temp); + temp = (temp << 8 | temp); } /* All remaining locations access work RAM */ @@ -906,7 +916,6 @@ void vdp_test_w(unsigned int value) int vdp_int_ack_callback(int int_level) { - /* VINT triggered ? */ if (irq_status&0x20) { diff --git a/source/vdp.h b/source/vdp.h index 813dd4f..395361c 100644 --- a/source/vdp.h +++ b/source/vdp.h @@ -57,12 +57,16 @@ extern uint16 playfield_row_mask; extern uint32 y_mask; extern uint16 hc_latch; extern uint16 v_counter; -extern uint8 im2_flag; extern uint32 dma_length; extern int32 fifo_write_cnt; extern uint32 fifo_lastwrite; extern uint8 fifo_latency; +extern uint8 im2_flag; +extern uint8 interlaced; +extern uint8 odd_frame; extern uint8 vdp_pal; +extern uint8 vdp_rate; +extern uint16 lines_per_frame; extern uint8 *vctab; extern uint8 *hctab;