mirror of
https://github.com/ekeeke/Genesis-Plus-GX.git
synced 2024-08-14 03:49:11 +02:00
[Core/CPU] fixed Z80 registers initial state, added proper initialization when using PBC (verified on real hardware by Charles McDonald)
This commit is contained in:
parent
a3519baa93
commit
7579d92c25
@ -327,8 +327,33 @@ void gen_reset(int hard_reset)
|
|||||||
|
|
||||||
/* reset Z80 */
|
/* reset Z80 */
|
||||||
z80_reset();
|
z80_reset();
|
||||||
}
|
|
||||||
|
|
||||||
|
/* some Z80 registers need to be initialized on Power ON */
|
||||||
|
if (hard_reset)
|
||||||
|
{
|
||||||
|
/* Power Base Converter specific */
|
||||||
|
if (system_hw == SYSTEM_PBC)
|
||||||
|
{
|
||||||
|
/* startup code logic (verified on real hardware): */
|
||||||
|
/* 21 01 E1 : LD HL, $E101
|
||||||
|
25 -- -- : DEC H
|
||||||
|
F9 -- -- : LD SP,HL
|
||||||
|
C7 -- -- : RST $00
|
||||||
|
01 01 -- : LD BC, $xx01
|
||||||
|
*/
|
||||||
|
Z80.hl.w.l = 0xE001;
|
||||||
|
Z80.sp.w.l = 0xDFFF;
|
||||||
|
Z80.r = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Master System specific (when BIOS is disabled) */
|
||||||
|
else if ((system_hw & SYSTEM_SMS) && (!(config.bios & 1) || !(system_bios & SYSTEM_SMS)))
|
||||||
|
{
|
||||||
|
/* usually done by BIOS & required by some SMS games that don't initialize SP */
|
||||||
|
Z80.sp.w.l = 0xDFFF;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* OS ROM / TMSS register control functions (Genesis mode) */
|
/* OS ROM / TMSS register control functions (Genesis mode) */
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
* This Z80 emulator assumes a ZiLOG NMOS model.
|
* This Z80 emulator assumes a ZiLOG NMOS model.
|
||||||
*
|
*
|
||||||
* Additional changes [Eke-Eke]:
|
* Additional changes [Eke-Eke]:
|
||||||
|
* - Removed z80_burn function (unused)
|
||||||
* - Discarded multi-chip support (unused)
|
* - Discarded multi-chip support (unused)
|
||||||
* - Fixed cycle counting for FD and DD prefixed instructions
|
* - Fixed cycle counting for FD and DD prefixed instructions
|
||||||
* - Fixed behavior of chained FD and DD prefixes (R register should be only incremented by one
|
* - Fixed behavior of chained FD and DD prefixes (R register should be only incremented by one
|
||||||
@ -3358,11 +3359,9 @@ void z80_init(const void *config, int (*irqcallback)(int))
|
|||||||
Z80.daisy = config;
|
Z80.daisy = config;
|
||||||
Z80.irq_callback = irqcallback;
|
Z80.irq_callback = irqcallback;
|
||||||
|
|
||||||
/* Reset registers to their initial values (NB: should be random on real hardware) */
|
/* Clear registers values (NB: should be random on real hardware ?) */
|
||||||
AF = BC = DE = HL = 0;
|
AF = BC = DE = HL = SP = IX = IY =0;
|
||||||
F = ZF; /* Zero flag is set */
|
F = ZF; /* Zero flag is set */
|
||||||
IX = IY = 0xffff; /* IX and IY are FFFF after a reset! (from MAME) */
|
|
||||||
SP = 0xdfff; /* required by some SMS games that don't initialize SP */
|
|
||||||
|
|
||||||
/* setup cycle tables */
|
/* setup cycle tables */
|
||||||
cc[Z80_TABLE_op] = cc_op;
|
cc[Z80_TABLE_op] = cc_op;
|
||||||
@ -3411,20 +3410,6 @@ void z80_run(unsigned int cycles)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Burn 'cycles' T-states. Adjust R register for the lost time
|
|
||||||
****************************************************************************/
|
|
||||||
void z80_burn(unsigned int cycles)
|
|
||||||
{
|
|
||||||
if( cycles > 0 )
|
|
||||||
{
|
|
||||||
/* NOP takes 4 cycles per instruction */
|
|
||||||
int n = (cycles + 3) / 4;
|
|
||||||
R += n;
|
|
||||||
Z80.cycles += 4 * n * 15;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Get all registers in given buffer
|
* Get all registers in given buffer
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -62,7 +62,6 @@ extern unsigned char (*z80_readport)(unsigned int port);
|
|||||||
extern void z80_init(const void *config, int (*irqcallback)(int));
|
extern void z80_init(const void *config, int (*irqcallback)(int));
|
||||||
extern void z80_reset (void);
|
extern void z80_reset (void);
|
||||||
extern void z80_run(unsigned int cycles);
|
extern void z80_run(unsigned int cycles);
|
||||||
extern void z80_burn(unsigned int cycles);
|
|
||||||
extern void z80_get_context (void *dst);
|
extern void z80_get_context (void *dst);
|
||||||
extern void z80_set_context (void *src);
|
extern void z80_set_context (void *src);
|
||||||
extern void z80_set_irq_line(unsigned int state);
|
extern void z80_set_irq_line(unsigned int state);
|
||||||
|
Loading…
Reference in New Issue
Block a user