added support for one EEPROM game, code cleanup

This commit is contained in:
ekeeke31 2009-01-07 17:12:03 +00:00
parent e774dc03ae
commit cb7149fb6b
10 changed files with 59 additions and 60 deletions

View File

@ -26,7 +26,7 @@ INCLUDES := source source/m68k source/z80 source/sound source/sound/SRC source/n
# options for code generation # 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) CXXFLAGS = $(CFLAGS)
LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map

View File

@ -28,7 +28,7 @@ typedef struct
T_EEPROM_TYPE type; T_EEPROM_TYPE type;
} T_GAME_ENTRY; } T_GAME_ENTRY;
T_GAME_ENTRY database[24] = T_GAME_ENTRY database[25] =
{ {
/* ACCLAIM mappers */ /* ACCLAIM mappers */
/* 24C02 (old mapper) */ /* 24C02 (old mapper) */
@ -43,11 +43,11 @@ T_GAME_ENTRY database[24] =
/* 24C65 */ /* 24C65 */
{{"T-81576" }, 0, {16, 0x1FFF, 0x1FFF, 0x200001, 0x200001, 0x200000, 0, 0, 0}}, /* College Slam */ {{"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 */ {{"T-81476" }, 0, {16, 0x1FFF, 0x1FFF, 0x200001, 0x200001, 0x200000, 0, 0, 0}}, /* Frank Thomas Big Hurt Baseball */
/* EA mapper (24C01 only) */ /* EA mapper (24C01 only) */
{{"T-50396" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 7, 7, 6}}, /* NHLPA Hockey 93 (UE) */ {{"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 */ {{"T-50176" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 7, 7, 6}}, /* Rings of Power */
/* SEGA mapper (24C01 only) */ /* SEGA mapper (24C01 only) */
{{"T-12046" }, 0, {7, 0x7F, 0x7F, 0x200001, 0x200001, 0x200001, 0, 0, 1}}, /* Megaman - The Wily Wars */ {{"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] */ {{"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) */ {{"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 */ {{"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 */ {{"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 */ /* CODEMASTERS mapper */
/* 24C01 */ /* 24C01 */
{{"T-120106"}, 0, {7, 0x7F, 0x7F, 0x300000, 0x380001, 0x300000, 0, 7, 1}}, /* Brian Lara Cricket */ {{"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) if ((sram.end - sram.start) < 2)
{ {
sram.custom = 1; sram.custom = 1;
sram.on = 1; sram.on = 1;
sram.write = 1; sram.write = 1;
/* set SEGA mapper as default */ /* set SEGA mapper as default */
memcpy(&eeprom.type, &database[9].type, sizeof(T_EEPROM_TYPE)); memcpy(&eeprom.type, &database[9].type, sizeof(T_EEPROM_TYPE));

View File

@ -45,7 +45,7 @@ void sram_init()
memset (&sram.sram[0], 0xFF, 0x10000); memset (&sram.sram[0], 0xFF, 0x10000);
sram.crc = crc32 (0, &sram.sram[0], 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 */ /* retrieve informations from headezr */
sram.detected = 1; sram.detected = 1;

View File

@ -1136,7 +1136,8 @@ void MainMenu ()
/* Switch to menu default rendering mode (60hz or 50hz, but always 480 lines) */ /* Switch to menu default rendering mode (60hz or 50hz, but always 480 lines) */
VIDEO_Configure (vmode); 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_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
@ -1221,11 +1222,11 @@ void MainMenu ()
while (WPAD_ButtonsHeld(0)) WPAD_ScanPads(); while (WPAD_ButtonsHeld(0)) WPAD_ScanPads();
#endif #endif
/*** Reinitialize GX ***/ /*** Reinitialize VIDEO ***/
VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK);
VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK);
VIDEO_Flush(); VIDEO_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
VIDEO_WaitVSync();
ogc_video__reset(); ogc_video__reset();
odd_frame = 1; odd_frame = 1;

View File

@ -35,6 +35,9 @@ u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32);
/* Current work soundbuffer */ /* Current work soundbuffer */
int mixbuffer; int mixbuffer;
/* Status of Audio playback */
static int AudioStarted = 0;
/* Current DMA length (required to be a factor of 32-bytes) /* Current DMA length (required to be a factor of 32-bytes)
length is calculated regarding current emulation timings: 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) 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) void ogc_audio__start(void)
{ {
dma_len = vdp_pal ? 3840 : 3200; dma_len = vdp_pal ? 3840 : 3200;
memset(soundbuffer[0], 0, dma_len);
AUDIO_InitDMA((u32) soundbuffer[0], dma_len); AUDIO_InitDMA((u32) soundbuffer[0], dma_len);
DCFlushRange(soundbuffer[0], dma_len); DCFlushRange(soundbuffer[0], dma_len);
AUDIO_StartDMA(); AUDIO_StartDMA();
AudioStarted = 1;
mixbuffer = 1; mixbuffer = 1;
} }
@ -113,5 +116,10 @@ void ogc_audio__start(void)
***/ ***/
void ogc_audio__stop(void) void ogc_audio__stop(void)
{ {
AUDIO_StopDMA (); if (AudioStarted)
{
AUDIO_StopDMA ();
AudioStarted = 0;
memset(soundbuffer, 0, 2 * 3840);
}
} }

View File

@ -676,8 +676,8 @@ void ogc_video__init(void)
ARAMPut ((char *) 0x80700000 + 0x20, (char *) 0x8000, genromsize); ARAMPut ((char *) 0x80700000 + 0x20, (char *) 0x8000, genromsize);
} }
/* Get the current video mode then : /* Get the current VIDEO mode then :
- set menu video mode (480p, 480i or 576i) - set menu VIDEO mode (480p, 480i or 576i)
- set emulator rendering TV modes (PAL/MPAL/NTSC/EURGB60) - set emulator rendering TV modes (PAL/MPAL/NTSC/EURGB60)
*/ */
vmode = VIDEO_GetPreferredMode(NULL); vmode = VIDEO_GetPreferredMode(NULL);
@ -729,7 +729,7 @@ void ogc_video__init(void)
} }
#endif #endif
/* Configure video mode */ /* Configure VIDEO mode */
VIDEO_Configure (vmode); VIDEO_Configure (vmode);
/* Configure the framebuffers (double-buffering) */ /* Configure the framebuffers (double-buffering) */
@ -746,13 +746,14 @@ void ogc_video__init(void)
/* Set the framebuffer to be displayed at next VBlank */ /* Set the framebuffer to be displayed at next VBlank */
VIDEO_SetNextFramebuffer (xfb[0]); VIDEO_SetNextFramebuffer (xfb[0]);
/* Set Vertical Interrupt callbacks for VIDEO synchronization */
VIDEO_SetPreRetraceCallback(xfb_switch); VIDEO_SetPreRetraceCallback(xfb_switch);
VIDEO_SetPostRetraceCallback(xfb_copy); VIDEO_SetPostRetraceCallback(xfb_copy);
/* Enable Video Interface */ /* Enable Video Interface */
VIDEO_SetBlack (FALSE); VIDEO_SetBlack (FALSE);
/* Update video settings for next VBlank */ /* Update VIDEO settings for next VBlank */
VIDEO_Flush (); VIDEO_Flush ();
/* Wait for VBlank */ /* Wait for VBlank */

View File

@ -28,18 +28,12 @@
/* Global variables */ /* Global variables */
t_bitmap bitmap; t_bitmap bitmap;
t_snd snd; t_snd snd;
uint8 vdp_rate;
uint16 lines_per_frame;
uint32 aim_m68k;
uint32 count_m68k; uint32 count_m68k;
uint32 line_m68k; uint32 line_m68k;
uint32 hint_m68k; uint32 hint_m68k;
uint32 aim_z80;
uint32 count_z80; uint32 count_z80;
uint32 line_z80; uint32 line_z80;
int32 current_z80; int32 current_z80;
uint8 odd_frame;
uint8 interlaced;
uint8 system_hw; uint8 system_hw;
static inline void audio_update (void); static inline void audio_update (void);
@ -49,10 +43,6 @@ static inline void audio_update (void);
****************************************************************/ ****************************************************************/
void system_init (void) void system_init (void)
{ {
/* PAL/NTSC timings */
vdp_rate = vdp_pal ? 50 : 60;
lines_per_frame = vdp_pal ? 313 : 262;
gen_init (); gen_init ();
vdp_init (); vdp_init ();
render_init (); render_init ();
@ -60,31 +50,21 @@ void system_init (void)
} }
/**************************************************************** /****************************************************************
* Virtual Genesis Restart * Virtual Genesis Hard Reset
****************************************************************/ ****************************************************************/
void system_reset (void) void system_reset (void)
{ {
aim_m68k = 0; /* Cartridge Hardware */
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 */
cart_hw_reset(); cart_hw_reset();
/* Hard reset */ /* Genesis Hardware */
gen_reset (1); gen_reset (1);
vdp_reset (); vdp_reset ();
render_reset (); render_reset ();
io_reset(); io_reset();
SN76489_Reset(0); SN76489_Reset(0);
/* Sound buffers reset */ /* Sound Buffers */
memset (snd.psg.buffer, 0, SND_SIZE); memset (snd.psg.buffer, 0, SND_SIZE);
memset (snd.fm.buffer[0], 0, SND_SIZE*2); memset (snd.fm.buffer[0], 0, SND_SIZE*2);
memset (snd.fm.buffer[1], 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; return 0;
} }
int aim_m68k = 0;
int aim_z80 = 0;
/* reset cycles counts */ /* reset cycles counts */
count_m68k = 0; count_m68k = 0;
aim_m68k = 0;
aim_z80 = 0;
count_z80 = 0; count_z80 = 0;
fifo_write_cnt = 0; fifo_write_cnt = 0;
fifo_lastwrite = 0; fifo_lastwrite = 0;

View File

@ -79,18 +79,12 @@ typedef struct
/* Global variables */ /* Global variables */
extern t_bitmap bitmap; extern t_bitmap bitmap;
extern t_snd snd; extern t_snd snd;
extern uint16 lines_per_frame;
extern uint8 vdp_rate;
extern uint32 aim_m68k;
extern uint32 count_m68k; extern uint32 count_m68k;
extern uint32 line_m68k; extern uint32 line_m68k;
extern uint32 hint_m68k; extern uint32 hint_m68k;
extern uint32 aim_z80;
extern uint32 count_z80; extern uint32 count_z80;
extern uint32 line_z80; extern uint32 line_z80;
extern int32 current_z80; extern int32 current_z80;
extern uint8 interlaced;
extern uint8 odd_frame;
extern uint8 system_hw; extern uint8 system_hw;
/* Function prototypes */ /* Function prototypes */

View File

@ -69,13 +69,16 @@ uint16 playfield_row_mask; /* Horizontal scroll mask */
uint32 y_mask; /* Name table Y-index bits mask */ uint32 y_mask; /* Name table Y-index bits mask */
uint16 hc_latch; /* latched HCounter (INT2) */ uint16 hc_latch; /* latched HCounter (INT2) */
uint16 v_counter; /* VDP scanline counter */ uint16 v_counter; /* VDP scanline counter */
uint8 im2_flag; /* 1= Interlace mode 2 is being used */
uint32 dma_length; /* Current DMA remaining bytes */ uint32 dma_length; /* Current DMA remaining bytes */
int32 fifo_write_cnt; /* VDP writes fifo count */ int32 fifo_write_cnt; /* VDP writes fifo count */
uint32 fifo_lastwrite; /* last VDP write cycle */ uint32 fifo_lastwrite; /* last VDP write cycle */
uint8 fifo_latency; /* VDP write cycles latency */ 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 */ /* Tables that define the playfield layout */
static const uint8 shift_table[] = { 6, 7, 0, 8 }; 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) void vdp_init(void)
{ {
/* DMA timings */
int i; int i;
/* reinitialize DMA timings table */
for (i=0; i<4; i++) for (i=0; i<4; i++)
{ {
vdp_timings[0][i] = ((double)m68cycles_per_line) / ((double) dma_rates[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[2][i] = ((double)m68cycles_per_line) / ((double) dma_rates[i + 8]);
vdp_timings[3][i] = ((double)m68cycles_per_line) / ((double) dma_rates[i + 12]); 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) void vdp_reset(void)
@ -223,6 +229,10 @@ void vdp_reset(void)
window_clip(1,0); window_clip(1,0);
} }
/* non-interlaced display */
odd_frame = 0;
interlaced = 0;
/* default latency */ /* default latency */
fifo_latency = 27; fifo_latency = 27;
} }
@ -281,7 +291,7 @@ void dma_update()
index += (reg[12] & 1); /* 32 or 40 Horizontal Cells */ index += (reg[12] & 1); /* 32 or 40 Horizontal Cells */
/* calculate transfer quantity for the remaining 68k cycles */ /* 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; if (left_cycles < 0) left_cycles = 0;
dma_bytes = (uint32)(((double)left_cycles / vdp_timings[dma_type][index]) + 0.5); 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 */ /* VRAM Fill or VRAM Copy */
/* set DMA end cyles count */ /* set DMA end cyles count */
dma_endCycles = count_m68k + dma_cycles; dma_endCycles = count_m68k + dma_cycles;
/* set DMA Busy flag */ /* set DMA Busy flag */
status |= 0x0002; status |= 0x0002;
} }
@ -382,7 +392,7 @@ static inline void dma_vbus (void)
else if (source <= 0xa1001f) else if (source <= 0xa1001f)
{ {
temp = io_read((source >> 1) & 0x0f); temp = io_read((source >> 1) & 0x0f);
temp = (temp << 8 | temp); temp = (temp << 8 | temp);
} }
/* All remaining locations access work RAM */ /* 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) int vdp_int_ack_callback(int int_level)
{ {
/* VINT triggered ? */ /* VINT triggered ? */
if (irq_status&0x20) if (irq_status&0x20)
{ {

View File

@ -57,12 +57,16 @@ extern uint16 playfield_row_mask;
extern uint32 y_mask; extern uint32 y_mask;
extern uint16 hc_latch; extern uint16 hc_latch;
extern uint16 v_counter; extern uint16 v_counter;
extern uint8 im2_flag;
extern uint32 dma_length; extern uint32 dma_length;
extern int32 fifo_write_cnt; extern int32 fifo_write_cnt;
extern uint32 fifo_lastwrite; extern uint32 fifo_lastwrite;
extern uint8 fifo_latency; extern uint8 fifo_latency;
extern uint8 im2_flag;
extern uint8 interlaced;
extern uint8 odd_frame;
extern uint8 vdp_pal; extern uint8 vdp_pal;
extern uint8 vdp_rate;
extern uint16 lines_per_frame;
extern uint8 *vctab; extern uint8 *vctab;
extern uint8 *hctab; extern uint8 *hctab;