X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fgp2x%2F940ctl.c;h=917ed29c0d8284cecd1894f6b22fb38fefd7b58b;hb=b542be4686241c9e0722ff8e452980f9ac2b4d7c;hp=66a5d2b9afaafef6f6c0d9817cf5f865a54cc212;hpb=a12e01162349cd970e9b6fe5674497760631279b;p=picodrive.git diff --git a/platform/gp2x/940ctl.c b/platform/gp2x/940ctl.c index 66a5d2b..917ed29 100644 --- a/platform/gp2x/940ctl.c +++ b/platform/gp2x/940ctl.c @@ -14,9 +14,12 @@ #include "gp2x.h" #include "emu.h" #include "menu.h" -#include "asmutils.h" -#include "mp3.h" +#include "../common/mp3.h" +#include "../common/arm_utils.h" +#include "../common/menu.h" +#include "../common/emu.h" #include "../../Pico/PicoInt.h" +#include "../../Pico/sound/ym2612.h" #include "../../Pico/sound/mix.h" /* we will need some gp2x internals here */ @@ -48,23 +51,12 @@ static FILE *loaded_mp3 = 0; } /* these will be managed locally on our side */ -extern int *ym2612_dacen; -extern INT32 *ym2612_dacout; -extern void *ym2612_regs; - static UINT8 *REGS = 0; /* we will also keep local copy of regs for savestates and such */ -static INT32 addr_A1; /* address line A1 */ -static int dacen; +static INT32 *addr_A1; /* address line A1 */ + +static int dacen; static INT32 dacout; static UINT8 ST_address; /* address register */ -static UINT8 ST_status; /* status flag */ -static UINT8 ST_mode; /* mode CSM / 3SLOT */ -static int ST_TA; /* timer a */ -static int ST_TAC; /* timer a maxval */ -static int ST_TAT; /* timer a ticker */ -static UINT8 ST_TB; /* timer b */ -static int ST_TBC; /* timer b maxval */ -static int ST_TBT; /* timer b ticker */ static int writebuff_ptr = 0; @@ -82,16 +74,16 @@ static int set_timers( int v ) /* b2 = timer enable a */ /* b1 = load b */ /* b0 = load a */ - change = (ST_mode ^ v) & 0xc0; - ST_mode = v; + change = (ym2612_st->mode ^ v) & 0xc0; + ym2612_st->mode = v; /* reset Timer b flag */ if( v & 0x20 ) - ST_status &= ~2; + ym2612_st->status &= ~2; /* reset Timer a flag */ if( v & 0x10 ) - ST_status &= ~1; + ym2612_st->status &= ~1; return change; } @@ -112,19 +104,19 @@ int YM2612Write_940(unsigned int a, unsigned int v) switch( a ) { case 0: /* address port 0 */ - if (!addr_A1 && ST_address == v) + if (!*addr_A1 && ST_address == v) return 0; /* address already selected, don't send this command to 940 */ ST_address = v; /* don't send DAC or timer related address changes to 940 */ - if (!addr_A1 && (v & 0xf0) == 0x20 && + if (!*addr_A1 && (v & 0xf0) == 0x20 && (v == 0x24 || v == 0x25 || v == 0x26 || v == 0x2a)) return 0; - addr_A1 = 0; + *addr_A1 = 0; upd = 0; break; case 1: /* data port 0 */ - if (addr_A1 != 0) { + if (*addr_A1 != 0) { return 0; /* verified on real YM2608 */ } @@ -137,30 +129,30 @@ int YM2612Write_940(unsigned int a, unsigned int v) switch( addr ) { case 0x24: { // timer A High 8 - int TAnew = (ST_TA & 0x03)|(((int)v)<<2); - if(ST_TA != TAnew) { + int TAnew = (ym2612_st->TA & 0x03)|(((int)v)<<2); + if (ym2612_st->TA != TAnew) { // we should reset ticker only if new value is written. Outrun requires this. - ST_TA = TAnew; - ST_TAC = (1024-TAnew)*18; - ST_TAT = 0; + ym2612_st->TA = TAnew; + ym2612_st->TAC = (1024-TAnew)*18; + ym2612_st->TAT = 0; } return 0; } case 0x25: { // timer A Low 2 - int TAnew = (ST_TA & 0x3fc)|(v&3); - if(ST_TA != TAnew) { - ST_TA = TAnew; - ST_TAC = (1024-TAnew)*18; - ST_TAT = 0; + int TAnew = (ym2612_st->TA & 0x3fc)|(v&3); + if (ym2612_st->TA != TAnew) { + ym2612_st->TA = TAnew; + ym2612_st->TAC = (1024-TAnew)*18; + ym2612_st->TAT = 0; } return 0; } case 0x26: // timer B - if(ST_TB != v) { - ST_TB = v; - ST_TBC = (256-v)<<4; - ST_TBC *= 18; - ST_TBT = 0; + if (ym2612_st->TB != v) { + ym2612_st->TB = v; + ym2612_st->TBC = (256-v)<<4; + ym2612_st->TBC *= 18; + ym2612_st->TBT = 0; } return 0; case 0x27: /* mode, timer control */ @@ -183,15 +175,15 @@ int YM2612Write_940(unsigned int a, unsigned int v) break; case 2: /* address port 1 */ - if (addr_A1 && ST_address == v) + if (*addr_A1 && ST_address == v) return 0; ST_address = v; - addr_A1 = 1; + *addr_A1 = 1; upd = 0; break; case 3: /* data port 1 */ - if (addr_A1 != 1) { + if (*addr_A1 != 1) { return 0; /* verified on real YM2608 */ } @@ -227,38 +219,6 @@ int YM2612Write_940(unsigned int a, unsigned int v) return 0; // cause the engine to do updates once per frame only } -UINT8 YM2612Read_940(void) -{ - return ST_status; -} - - -int YM2612PicoTick_940(int n) -{ - //int ret = 0; - - // timer A - if(ST_mode & 0x01 && (ST_TAT+=64*n) >= ST_TAC) { - ST_TAT -= ST_TAC; - if(ST_mode & 0x04) ST_status |= 1; - // CSM mode total level latch and auto key on -/* FIXME - if(ST_mode & 0x80) { - CSMKeyControll( &(ym2612_940->CH[2]) ); // Vectorman2, etc. - ret = 1; - } -*/ - } - - // timer B - if(ST_mode & 0x02 && (ST_TBT+=64*n) >= ST_TBC) { - ST_TBT -= ST_TBC; - if(ST_mode & 0x08) ST_status |= 2; - } - - return 0; -} - #define CHECK_BUSY(job) \ (gp2x_memregs[0x3b46>>1] & (1<<(job-1))) @@ -312,7 +272,7 @@ static void add_job_940(int job) void YM2612PicoStateLoad_940(void) { - int i, old_A1 = addr_A1; + int i, old_A1 = *addr_A1; /* make sure JOB940_PICOSTATELOAD gets done before next JOB940_YM2612UPDATEONE */ add_job_940(JOB940_PICOSTATELOAD); @@ -330,20 +290,24 @@ void YM2612PicoStateLoad_940(void) YM2612Write_940(3, REGS[i|0x100]); } - addr_A1 = old_A1; + *addr_A1 = old_A1; } static void internal_reset(void) { writebuff_ptr = 0; - ST_mode = 0; - ST_status = 0; /* normal mode */ - ST_TA = 0; - ST_TAC = 0; - ST_TB = 0; - ST_TBC = 0; - dacen = 0; + ym2612_st->mode = 0; + ym2612_st->status = 0; /* normal mode */ + ym2612_st->TA = 0; + ym2612_st->TAC = 0; + ym2612_st->TAT = 0; + ym2612_st->TB = 0; + ym2612_st->TBC = 0; + ym2612_st->TBT = 0; + dacen = 0; + dacout = 0; + ST_address= 0; } @@ -438,7 +402,11 @@ void YM2612Init_940(int baseclock, int rate) memset(shared_data, 0, sizeof(*shared_data)); memset(shared_ctl, 0, sizeof(*shared_ctl)); + /* cause local ym2612 to init REGS */ + YM2612Init_(baseclock, rate); + REGS = YM2612GetRegs(); + addr_A1 = (INT32 *) (REGS + 0x200); ym2612_dacen = &dacen; ym2612_dacout = &dacout; @@ -525,9 +493,8 @@ void mp3_update(int *buffer, int length, int stereo) int length_mp3; int cdda_on; - // not data track, CDC is reading, playback was started, track not ended - cdda_on = !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1) && - loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len; + // playback was started, track not ended + cdda_on = loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len; if (!cdda_on) return; @@ -641,7 +608,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 int mp3_get_offset(void) { - int offs1024 = 0; + unsigned int offs1024 = 0; int cdda_on; cdda_on = (PicoMCD & 1) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) && @@ -649,10 +616,9 @@ int mp3_get_offset(void) if (cdda_on) { offs1024 = shared_ctl->mp3_offs << 7; - offs1024 /= shared_ctl->mp3_len; - offs1024 <<= 3; + offs1024 /= shared_ctl->mp3_len >> 3; } - printf("offs1024=%i (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len); + printf("offs1024=%u (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len); return offs1024; }