mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
ym2612 full saves wip
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@479 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
e5fa981777
commit
d2721b08bb
6 changed files with 199 additions and 55 deletions
|
@ -145,7 +145,6 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile)
|
|||
SCAN_VAR(Pico.m ,"misc")
|
||||
SCAN_VAR(Pico.video,"video")
|
||||
|
||||
// notaz: save/load z80, YM2612, sn76496 states instead of Pico.s (which is unused anyway)
|
||||
if (PicoOpt&7) {
|
||||
if((PmovAction&3)==1) z80_pack(cpu_z80);
|
||||
ret = SCAN_VAR(cpu_z80,"cpu_z80")
|
||||
|
@ -158,6 +157,7 @@ static int PicoAreaScan(int PmovAction,unsigned int ver, void *PmovFile)
|
|||
if (PicoOpt&3)
|
||||
ScanVar(sn76496_regs,28*4,"SN76496state", PmovFile, PmovAction); // regs and other stuff
|
||||
if (PicoOpt&1) {
|
||||
if((PmovAction&3)==1) ym2612_pack_state();
|
||||
ScanVar(ym2612_regs, 0x200+4, "YM2612state", PmovFile, PmovAction); // regs + addr line
|
||||
if((PmovAction&3)==2) ym2612_unpack_state(); // reload YM2612 state from it's regs
|
||||
}
|
||||
|
|
|
@ -796,7 +796,7 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80)
|
|||
{
|
||||
//elprintf(EL_STATUS, "timer a set %i", TAnew);
|
||||
ym2612.OPN.ST.TA = TAnew;
|
||||
//ym2612.OPN.ST.TAC = (1024-TAnew)*18;
|
||||
ym2612.OPN.ST.TAC = (1024-TAnew)*18;
|
||||
//ym2612.OPN.ST.TAT = 0;
|
||||
//
|
||||
timer_a_step = timer_a_offset = 16466 * (1024 - TAnew);
|
||||
|
@ -812,8 +812,7 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80)
|
|||
if (ym2612.OPN.ST.TB != d) {
|
||||
//elprintf(EL_STATUS, "timer b set %i", d);
|
||||
ym2612.OPN.ST.TB = d;
|
||||
//ym2612.OPN.ST.TBC = (256-d)<<4;
|
||||
//ym2612.OPN.ST.TBC *= 18;
|
||||
ym2612.OPN.ST.TBC = (256-d) * 288;
|
||||
//ym2612.OPN.ST.TBT = 0;
|
||||
timer_b_step = timer_b_offset = 262800 * (256 - d); // 262881
|
||||
if (ym2612.OPN.ST.mode & 2) {
|
||||
|
@ -912,21 +911,38 @@ u32 ym2612_read_local_68k(void)
|
|||
return ym2612.OPN.ST.status;
|
||||
}
|
||||
|
||||
// TODO: new ym2612 savestates, also save timers
|
||||
void ym2612_pack_state(void)
|
||||
{
|
||||
// TODO timers
|
||||
#ifdef __GP2X__
|
||||
if (PicoOpt & POPT_EXT_FM)
|
||||
/*YM2612PicoStateSave2_940(0, 0)*/;
|
||||
else
|
||||
#endif
|
||||
YM2612PicoStateSave2(0, 0);
|
||||
}
|
||||
|
||||
void ym2612_unpack_state(void)
|
||||
{
|
||||
int i;
|
||||
int i, ret, tat, tbt;
|
||||
YM2612PicoStateLoad();
|
||||
|
||||
// feed all the registers and update internal state
|
||||
for (i = 0x20; i < 0xC0; i++) {
|
||||
for (i = 0x20; i < 0xB8; i++) {
|
||||
ym2612_write_local(0, i, 0);
|
||||
ym2612_write_local(1, ym2612.REGS[i], 0);
|
||||
}
|
||||
for (i = 0x30; i < 0xC0; i++) {
|
||||
for (i = 0x30; i < 0xB8; i++) {
|
||||
ym2612_write_local(2, i, 0);
|
||||
ym2612_write_local(3, ym2612.REGS[i|0x100], 0);
|
||||
}
|
||||
|
||||
#ifdef __GP2X__
|
||||
if (PicoOpt & POPT_EXT_FM)
|
||||
/*ret = YM2612PicoStateLoad2_940(&tat, &tbt)*/;
|
||||
else
|
||||
#endif
|
||||
ret = YM2612PicoStateLoad2(&tat, &tbt);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
|
|
@ -476,6 +476,7 @@ extern int timer_a_next_oflow, timer_a_step, timer_a_offset; // in z80 cycles
|
|||
extern int timer_b_next_oflow, timer_b_step, timer_b_offset;
|
||||
|
||||
void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);
|
||||
void ym2612_pack_state(void);
|
||||
void ym2612_unpack_state(void);
|
||||
|
||||
#define timers_cycle() \
|
||||
|
|
|
@ -121,8 +121,10 @@ PICO_INTERNAL int PicoCdSaveState(void *file)
|
|||
}
|
||||
if (PicoOpt&3)
|
||||
CHECKED_WRITE(CHUNK_PSG, 28*4, sn76496_regs);
|
||||
if (PicoOpt&1)
|
||||
if (PicoOpt&1) {
|
||||
ym2612_pack_state();
|
||||
CHECKED_WRITE(CHUNK_FM, 0x200+4, ym2612_regs);
|
||||
}
|
||||
|
||||
if (PicoAHW & PAHW_MCD)
|
||||
{
|
||||
|
|
|
@ -1087,12 +1087,25 @@ void chan_render_loop(chan_rend_context *ct, int *buffer, unsigned short length)
|
|||
|
||||
static chan_rend_context crct;
|
||||
|
||||
static void chan_render_prep(void)
|
||||
{
|
||||
crct.eg_timer_add = ym2612.OPN.eg_timer_add;
|
||||
crct.lfo_inc = ym2612.OPN.lfo_inc;
|
||||
}
|
||||
|
||||
static void chan_render_finish(void)
|
||||
{
|
||||
ym2612.OPN.eg_cnt = crct.eg_cnt;
|
||||
ym2612.OPN.eg_timer = crct.eg_timer;
|
||||
g_lfo_ampm = crct.pack >> 16; // need_save
|
||||
ym2612.OPN.lfo_cnt = crct.lfo_cnt;
|
||||
}
|
||||
|
||||
static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: stereo, ?, disabled, ?, pan_r, pan_l
|
||||
{
|
||||
crct.CH = &ym2612.CH[c];
|
||||
crct.mem = crct.CH->mem_value; /* one sample delay memory */
|
||||
crct.lfo_cnt = ym2612.OPN.lfo_cnt;
|
||||
crct.lfo_inc = ym2612.OPN.lfo_inc;
|
||||
|
||||
flags &= 0x35;
|
||||
|
||||
|
@ -1109,7 +1122,6 @@ static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: s
|
|||
|
||||
crct.eg_cnt = ym2612.OPN.eg_cnt; /* envelope generator counter */
|
||||
crct.eg_timer = ym2612.OPN.eg_timer;
|
||||
crct.eg_timer_add = ym2612.OPN.eg_timer_add;
|
||||
|
||||
/* precalculate phase modulation incr */
|
||||
crct.phase1 = crct.CH->SLOT[SLOT1].phase;
|
||||
|
@ -1185,15 +1197,6 @@ static int chan_render(int *buffer, int length, int c, UINT32 flags) // flags: s
|
|||
else
|
||||
ym2612.slot_mask &= ~(0xf << (c*4));
|
||||
|
||||
// if this the last call, write back persistent stuff:
|
||||
if ((ym2612.slot_mask >> ((c+1)*4)) == 0)
|
||||
{
|
||||
ym2612.OPN.eg_cnt = crct.eg_cnt;
|
||||
ym2612.OPN.eg_timer = crct.eg_timer;
|
||||
g_lfo_ampm = crct.pack >> 16;
|
||||
ym2612.OPN.lfo_cnt = crct.lfo_cnt;
|
||||
}
|
||||
|
||||
return (crct.algo & 8) >> 3; // had output
|
||||
}
|
||||
|
||||
|
@ -1212,10 +1215,10 @@ INLINE void refresh_fc_eg_slot(FM_SLOT *SLOT, int fc, int kc)
|
|||
SLOT->ksr = ksr;
|
||||
|
||||
/* calculate envelope generator rates */
|
||||
if ((SLOT->ar + SLOT->ksr) < 32+62)
|
||||
if ((SLOT->ar + ksr) < 32+62)
|
||||
{
|
||||
eg_sh = eg_rate_shift [SLOT->ar + SLOT->ksr ];
|
||||
eg_sel = eg_rate_select[SLOT->ar + SLOT->ksr ];
|
||||
eg_sh = eg_rate_shift [SLOT->ar + ksr ];
|
||||
eg_sel = eg_rate_select[SLOT->ar + ksr ];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1225,18 +1228,18 @@ INLINE void refresh_fc_eg_slot(FM_SLOT *SLOT, int fc, int kc)
|
|||
|
||||
SLOT->eg_pack_ar = eg_inc_pack[eg_sel] | (eg_sh<<24);
|
||||
|
||||
eg_sh = eg_rate_shift [SLOT->d1r + SLOT->ksr];
|
||||
eg_sel = eg_rate_select[SLOT->d1r + SLOT->ksr];
|
||||
eg_sh = eg_rate_shift [SLOT->d1r + ksr];
|
||||
eg_sel = eg_rate_select[SLOT->d1r + ksr];
|
||||
|
||||
SLOT->eg_pack_d1r = eg_inc_pack[eg_sel] | (eg_sh<<24);
|
||||
|
||||
eg_sh = eg_rate_shift [SLOT->d2r + SLOT->ksr];
|
||||
eg_sel = eg_rate_select[SLOT->d2r + SLOT->ksr];
|
||||
eg_sh = eg_rate_shift [SLOT->d2r + ksr];
|
||||
eg_sel = eg_rate_select[SLOT->d2r + ksr];
|
||||
|
||||
SLOT->eg_pack_d2r = eg_inc_pack[eg_sel] | (eg_sh<<24);
|
||||
|
||||
eg_sh = eg_rate_shift [SLOT->rr + SLOT->ksr];
|
||||
eg_sel = eg_rate_select[SLOT->rr + SLOT->ksr];
|
||||
eg_sh = eg_rate_shift [SLOT->rr + ksr];
|
||||
eg_sel = eg_rate_select[SLOT->rr + ksr];
|
||||
|
||||
SLOT->eg_pack_rr = eg_inc_pack[eg_sel] | (eg_sh<<24);
|
||||
}
|
||||
|
@ -1634,12 +1637,14 @@ int YM2612UpdateOne_(int *buffer, int length, int stereo, int is_buf_empty)
|
|||
|
||||
/* mix to 32bit dest */
|
||||
// flags: stereo, ?, disabled, ?, pan_r, pan_l
|
||||
chan_render_prep();
|
||||
if (ym2612.slot_mask & 0x00000f) active_chs |= chan_render(buffer, length, 0, stereo|((pan&0x003)<<4)) << 0;
|
||||
if (ym2612.slot_mask & 0x0000f0) active_chs |= chan_render(buffer, length, 1, stereo|((pan&0x00c)<<2)) << 1;
|
||||
if (ym2612.slot_mask & 0x000f00) active_chs |= chan_render(buffer, length, 2, stereo|((pan&0x030) )) << 2;
|
||||
if (ym2612.slot_mask & 0x00f000) active_chs |= chan_render(buffer, length, 3, stereo|((pan&0x0c0)>>2)) << 3;
|
||||
if (ym2612.slot_mask & 0x0f0000) active_chs |= chan_render(buffer, length, 4, stereo|((pan&0x300)>>4)) << 4;
|
||||
if (ym2612.slot_mask & 0xf00000) active_chs |= chan_render(buffer, length, 5, stereo|((pan&0xc00)>>6)|(ym2612.dacen<<2)) << 5;
|
||||
chan_render_finish();
|
||||
|
||||
return active_chs; // 1 if buffer updated
|
||||
}
|
||||
|
@ -1864,6 +1869,124 @@ int YM2612PicoTick_(int n)
|
|||
void YM2612PicoStateLoad_(void)
|
||||
{
|
||||
reset_channels( &ym2612.CH[0] );
|
||||
ym2612.slot_mask = 0xffffff;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 state_phase;
|
||||
INT16 volume;
|
||||
} ym_save_addon_slot;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT32 magic;
|
||||
UINT8 address;
|
||||
UINT8 status;
|
||||
UINT8 addr_A1;
|
||||
UINT8 unused;
|
||||
int TAT;
|
||||
int TBT;
|
||||
UINT32 eg_cnt;
|
||||
UINT32 eg_timer;
|
||||
UINT32 lfo_cnt;
|
||||
UINT16 lfo_ampm;
|
||||
UINT16 unused2;
|
||||
} ym_save_addon;
|
||||
|
||||
void YM2612PicoStateSave2(int tat, int tbt)
|
||||
{
|
||||
ym_save_addon_slot ss;
|
||||
ym_save_addon sa;
|
||||
unsigned char *ptr;
|
||||
int c, s;
|
||||
|
||||
// chans 1,2,3
|
||||
ptr = &ym2612.REGS[0x0b8];
|
||||
for (c = 0; c < 3; c++)
|
||||
{
|
||||
for (s = 0; s < 4; s++) {
|
||||
ss.state_phase = (ym2612.CH[c].SLOT[s].state << 29) | (ym2612.CH[c].SLOT[s].phase >> 3);
|
||||
ss.volume = ym2612.CH[c].SLOT[s].volume;
|
||||
memcpy(ptr, &ss, 6);
|
||||
ptr += 6;
|
||||
}
|
||||
}
|
||||
// chans 4,5,6
|
||||
ptr = &ym2612.REGS[0x1b8];
|
||||
for (; c < 6; c++)
|
||||
{
|
||||
for (s = 0; s < 4; s++) {
|
||||
ss.state_phase = (ym2612.CH[c].SLOT[s].state << 29) | (ym2612.CH[c].SLOT[s].phase >> 3);
|
||||
ss.volume = ym2612.CH[c].SLOT[s].volume;
|
||||
memcpy(ptr, &ss, 6);
|
||||
ptr += 6;
|
||||
}
|
||||
}
|
||||
// other things
|
||||
ptr = &ym2612.REGS[0x100];
|
||||
sa.magic = 0x41534d59; // 'YMSA'
|
||||
sa.address = ym2612.OPN.ST.address;
|
||||
sa.status = ym2612.OPN.ST.status;
|
||||
sa.addr_A1 = ym2612.addr_A1;
|
||||
sa.unused = 0;
|
||||
sa.TAT = tat;
|
||||
sa.TBT = tbt;
|
||||
sa.eg_cnt = ym2612.OPN.eg_cnt;
|
||||
sa.eg_timer = ym2612.OPN.eg_timer;
|
||||
sa.lfo_cnt = ym2612.OPN.lfo_cnt;
|
||||
sa.lfo_ampm = g_lfo_ampm;
|
||||
sa.unused2 = 0;
|
||||
memcpy(ptr, &sa, sizeof(sa)); // 0x30 max
|
||||
}
|
||||
|
||||
int YM2612PicoStateLoad2(int *tat, int *tbt)
|
||||
{
|
||||
ym_save_addon_slot ss;
|
||||
ym_save_addon sa;
|
||||
unsigned char *ptr;
|
||||
int c, s;
|
||||
|
||||
ptr = &ym2612.REGS[0x100];
|
||||
memcpy(&sa, ptr, sizeof(sa)); // 0x30 max
|
||||
if (sa.magic != 0x41534d59) return -1;
|
||||
|
||||
ym2612.OPN.ST.address = sa.address;
|
||||
ym2612.OPN.ST.status = sa.status;
|
||||
ym2612.addr_A1 = sa.addr_A1;
|
||||
ym2612.OPN.eg_cnt = sa.eg_cnt;
|
||||
ym2612.OPN.eg_timer = sa.eg_timer;
|
||||
ym2612.OPN.lfo_cnt = sa.lfo_cnt;
|
||||
g_lfo_ampm = sa.lfo_ampm;
|
||||
if (tat != NULL) *tat = sa.TAT;
|
||||
if (tbt != NULL) *tbt = sa.TBT;
|
||||
|
||||
// chans 1,2,3
|
||||
ptr = &ym2612.REGS[0x0b8];
|
||||
for (c = 0; c < 3; c++)
|
||||
{
|
||||
for (s = 0; s < 4; s++) {
|
||||
memcpy(&ss, ptr, 6);
|
||||
ym2612.CH[c].SLOT[s].state = ss.state_phase >> 29;
|
||||
ym2612.CH[c].SLOT[s].phase = ss.state_phase << 3;
|
||||
ym2612.CH[c].SLOT[s].volume = ss.volume;
|
||||
ptr += 6;
|
||||
}
|
||||
}
|
||||
// chans 4,5,6
|
||||
ptr = &ym2612.REGS[0x1b8];
|
||||
for (; c < 6; c++)
|
||||
{
|
||||
for (s = 0; s < 4; s++) {
|
||||
memcpy(&ss, ptr, 6);
|
||||
ym2612.CH[c].SLOT[s].state = ss.state_phase >> 29;
|
||||
ym2612.CH[c].SLOT[s].phase = ss.state_phase << 3;
|
||||
ym2612.CH[c].SLOT[s].volume = ss.volume;
|
||||
ptr += 6;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef EXTERNAL_YM2612
|
||||
|
|
|
@ -29,8 +29,8 @@ typedef struct
|
|||
UINT32 mul; /* #0x08 multiple :ML_TABLE[ML] */
|
||||
|
||||
/* Phase Generator */
|
||||
UINT32 phase; /* #0x0c phase counter */
|
||||
UINT32 Incr; /* #0x10 phase step */
|
||||
UINT32 phase; /* #0x0c phase counter | need_save */
|
||||
UINT32 Incr; /* #0x10 phase step | need_save */
|
||||
|
||||
UINT8 KSR; /* #0x14 key scale rate :3-KSR */
|
||||
UINT8 ksr; /* #0x15 key scale rate :kcode>>(3-KSR) */
|
||||
|
@ -38,9 +38,9 @@ typedef struct
|
|||
UINT8 key; /* #0x16 0=last key was KEY OFF, 1=KEY ON */
|
||||
|
||||
/* Envelope Generator */
|
||||
UINT8 state; /* #0x17 phase type: EG_OFF=0, EG_REL, EG_SUS, EG_DEC, EG_ATT */
|
||||
UINT8 state; /* #0x17 phase type: EG_OFF=0, EG_REL, EG_SUS, EG_DEC, EG_ATT | need_save */
|
||||
UINT16 tl; /* #0x18 total level: TL << 3 */
|
||||
INT16 volume; /* #0x1a envelope counter */
|
||||
INT16 volume; /* #0x1a envelope counter | need_save */
|
||||
UINT32 sl; /* #0x1c sustain level:sl_table[SL] */
|
||||
|
||||
UINT32 eg_pack_ar; /* #0x20 (attack state) */
|
||||
|
@ -77,17 +77,17 @@ typedef struct
|
|||
int clock; /* master clock (Hz) */
|
||||
int rate; /* sampling rate (Hz) */
|
||||
double freqbase; /* 08 frequency base */
|
||||
UINT8 address; /* 10 address register */
|
||||
UINT8 status; /* 11 status flag */
|
||||
UINT8 address; /* 10 address register | need_save */
|
||||
UINT8 status; /* 11 status flag | need_save */
|
||||
UINT8 mode; /* mode CSM / 3SLOT */
|
||||
UINT8 fn_h; /* freq latch */
|
||||
int TA; /* timer a */
|
||||
int TAC; /* timer a maxval */
|
||||
int TAT; /* timer a ticker */
|
||||
int TAT; /* timer a ticker | need_save */
|
||||
UINT8 TB; /* timer b */
|
||||
UINT8 pad[3];
|
||||
int TBC; /* timer b maxval */
|
||||
int TBT; /* timer b ticker */
|
||||
int TBT; /* timer b ticker | need_save */
|
||||
/* local time tables */
|
||||
INT32 dt_tab[8][32];/* DeTune table */
|
||||
} FM_ST;
|
||||
|
@ -112,12 +112,12 @@ typedef struct
|
|||
FM_3SLOT SL3; /* 3 slot mode state */
|
||||
UINT32 pan; /* fm channels output mask (bit 1 = enable) */
|
||||
|
||||
UINT32 eg_cnt; /* #0xb38 global envelope generator counter */
|
||||
UINT32 eg_timer; /* #0xb3c global envelope generator counter works at frequency = chipclock/64/3 */
|
||||
UINT32 eg_cnt; /* #0xb38 global envelope generator counter | need_save */
|
||||
UINT32 eg_timer; /* #0xb3c global envelope generator counter works at frequency = chipclock/64/3 | need_save */
|
||||
UINT32 eg_timer_add; /* #0xb40 step of eg_timer */
|
||||
|
||||
/* LFO */
|
||||
UINT32 lfo_cnt;
|
||||
UINT32 lfo_cnt; /* need_save */
|
||||
UINT32 lfo_inc;
|
||||
|
||||
UINT32 lfo_freq[8]; /* LFO FREQ table */
|
||||
|
@ -127,7 +127,7 @@ typedef struct
|
|||
typedef struct
|
||||
{
|
||||
UINT8 REGS[0x200]; /* registers (for save states) */
|
||||
INT32 addr_A1; /* address line A1 */
|
||||
INT32 addr_A1; /* address line A1 | need_save */
|
||||
|
||||
FM_CH CH[6]; /* channel state (0x168 bytes each)? */
|
||||
|
||||
|
@ -156,6 +156,8 @@ int YM2612PicoTick_(int n);
|
|||
void YM2612PicoStateLoad_(void);
|
||||
|
||||
void *YM2612GetRegs(void);
|
||||
void YM2612PicoStateSave2(int tat, int tbt);
|
||||
int YM2612PicoStateLoad2(int *tat, int *tbt);
|
||||
|
||||
#ifndef __GP2X__
|
||||
#define YM2612Init YM2612Init_
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue