From: notaz Date: Sun, 25 May 2008 21:25:46 +0000 (+0000) Subject: new z80 scheduling method, timers are still wip X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7481dd3a117922274a69040085644ce388a7aab9;p=libpicofe.git new z80 scheduling method, timers are still wip git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@459 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/gp2x/940ctl.c b/gp2x/940ctl.c index f217dea..8c8b18b 100644 --- a/gp2x/940ctl.c +++ b/gp2x/940ctl.c @@ -51,160 +51,64 @@ static FILE *loaded_mp3 = 0; } /* these will be managed locally on our side */ -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 dacout; static UINT8 ST_address; /* address register */ +static INT32 addr_A1; /* address line A1 */ static int writebuff_ptr = 0; -/* OPN Mode Register Write */ -static int set_timers( int v ) -{ - int change; - - /* b7 = CSM MODE */ - /* b6 = 3 slot mode */ - /* b5 = reset b */ - /* b4 = reset a */ - /* b3 = timer enable b */ - /* b2 = timer enable a */ - /* b1 = load b */ - /* b0 = load a */ - change = (ym2612_st->mode ^ v) & 0xc0; - ym2612_st->mode = v; - - /* reset Timer b flag */ - if( v & 0x20 ) - ym2612_st->status &= ~2; - - /* reset Timer a flag */ - if( v & 0x10 ) - ym2612_st->status &= ~1; - - return change; -} - /* YM2612 write */ /* a = address */ /* v = value */ /* returns 1 if sample affecting state changed */ -int YM2612Write_940(unsigned int a, unsigned int v) +int YM2612Write_940(unsigned int a, unsigned int v, int scanline) { - int addr; int upd = 1; /* the write affects sample generation */ - v &= 0xff; /* adjust to 8 bit bus */ a &= 3; //printf("%05i:%03i: ym w ([%i] %02x)\n", Pico.m.frame_count, Pico.m.scanline, a, v); - switch( a ) { - case 0: /* address port 0 */ - 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 && - (v == 0x24 || v == 0x25 || v == 0x26 || v == 0x2a)) + switch (a) { + case 0: /* address port 0 */ + if (addr_A1 == 0 && ST_address == v) + return 0; /* address already selected, don't send this command to 940 */ + ST_address = v; + addr_A1 = 0; + /* don't send DAC or timer related address changes to 940 */ + if (v == 0x24 || v == 0x25 || v == 0x26 || v == 0x2a) return 0; - *addr_A1 = 0; - upd = 0; - break; - - case 1: /* data port 0 */ - if (*addr_A1 != 0) { - return 0; /* verified on real YM2608 */ - } + upd = 0; + break; - addr = ST_address; - REGS[addr] = v; + case 1: /* data port 0 */ + if (ST_address == 0x2b) upd = 0; /* DAC sel */ + break; - switch( addr & 0xf0 ) - { - case 0x20: /* 0x20-0x2f Mode */ - switch( addr ) - { - case 0x24: { // timer A High 8 - 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. - ym2612_st->TA = TAnew; - ym2612_st->TAC = (1024-TAnew)*18; - ym2612_st->TAT = 0; - } - return 0; - } - case 0x25: { // timer A Low 2 - 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 (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 */ - if (set_timers( v )) - break; // other side needs ST.mode for 3slot mode - return 0; - case 0x2a: /* DAC data (YM2612) */ - dacout = ((int)v - 0x80) << 6; /* level unknown (notaz: 8 seems to be too much) */ + case 2: /* address port 1 */ + if (addr_A1 == 1 && ST_address == v) return 0; - case 0x2b: /* DAC Sel (YM2612) */ - /* b7 = dac enable */ - dacen = v & 0x80; - upd = 0; - break; // other side has to know this - default: - break; - } + ST_address = v; + addr_A1 = 1; + upd = 0; break; - } - break; - - case 2: /* address port 1 */ - if (*addr_A1 && ST_address == v) - return 0; - ST_address = v; - *addr_A1 = 1; - upd = 0; - break; - - case 3: /* data port 1 */ - if (*addr_A1 != 1) { - return 0; /* verified on real YM2608 */ - } - - addr = ST_address | 0x100; - REGS[addr] = v; - break; } //printf("ym pass\n"); - if(currentConfig.EmuOpt & 4) { + if (currentConfig.EmuOpt & 4) + { UINT16 *writebuff = shared_ctl->writebuffsel ? shared_ctl->writebuff0 : shared_ctl->writebuff1; /* detect rapid ym updates */ - if (upd && !(writebuff_ptr & 0x80000000) && Pico.m.scanline < 224) { + if (upd && !(writebuff_ptr & 0x80000000) && scanline < 224) + { int mid = Pico.m.pal ? 68 : 93; - if (Pico.m.scanline > mid) { - //printf("%05i:%03i: rapid ym\n", Pico.m.frame_count, Pico.m.scanline); + if (scanline > mid) { + //printf("%05i:%03i: rapid ym\n", Pico.m.frame_count, scanline); writebuff[writebuff_ptr++ & 0xffff] = 0xfffe; writebuff_ptr |= 0x80000000; - //printf("%05i:%03i: ym w ([%02x] %02x, upd=%i)\n", Pico.m.frame_count, Pico.m.scanline, addr, v, upd); + //printf("%05i:%03i: ym w ([%02x] %02x, upd=%i)\n", Pico.m.frame_count, scanline, addr, v, upd); } } @@ -272,7 +176,9 @@ static void add_job_940(int job) void YM2612PicoStateLoad_940(void) { - int i, old_A1 = *addr_A1; + UINT8 *REGS = YM2612GetRegs(); + + int i; /* make sure JOB940_PICOSTATELOAD gets done before next JOB940_YM2612UPDATEONE */ add_job_940(JOB940_PICOSTATELOAD); @@ -282,32 +188,22 @@ void YM2612PicoStateLoad_940(void) // feed all the registers and update internal state for(i = 0; i < 0x100; i++) { - YM2612Write_940(0, i); - YM2612Write_940(1, REGS[i]); + YM2612Write_940(0, i, -1); + YM2612Write_940(1, REGS[i], -1); } for(i = 0; i < 0x100; i++) { - YM2612Write_940(2, i); - YM2612Write_940(3, REGS[i|0x100]); + YM2612Write_940(2, i, -1); + YM2612Write_940(3, REGS[i|0x100], -1); } - *addr_A1 = old_A1; + addr_A1 = *(INT32 *) (REGS + 0x200); } static void internal_reset(void) { writebuff_ptr = 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; + ST_address = addr_A1 = -1; } @@ -405,12 +301,6 @@ void YM2612Init_940(int baseclock, int rate) /* cause local ym2612 to init REGS */ YM2612Init_(baseclock, rate); - REGS = YM2612GetRegs(); - addr_A1 = (INT32 *) (REGS + 0x200); - - ym2612_dacen = &dacen; - ym2612_dacout = &dacout; - internal_reset(); loaded_mp3 = 0; @@ -440,6 +330,7 @@ void YM2612ResetChip_940(void) return; } + YM2612ResetChip_(); internal_reset(); add_job_940(JOB940_YM2612RESETCHIP); diff --git a/gp2x/940ctl.h b/gp2x/940ctl.h index 95e9a07..0318c1c 100644 --- a/gp2x/940ctl.h +++ b/gp2x/940ctl.h @@ -5,7 +5,7 @@ void YM2612Init_940(int baseclock, int rate); void YM2612ResetChip_940(void); int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty); -int YM2612Write_940(unsigned int a, unsigned int v); +int YM2612Write_940(unsigned int a, unsigned int v, int scanline); unsigned char YM2612Read_940(void); int YM2612PicoTick_940(int n); diff --git a/gp2x/Makefile b/gp2x/Makefile index 59a7c15..4ebecb4 100644 --- a/gp2x/Makefile +++ b/gp2x/Makefile @@ -74,7 +74,7 @@ OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pi ../../Pico/cd/Area.o ../../Pico/cd/Misc.o ../../Pico/cd/pcm.o ../../Pico/cd/buffering.o endif # Pico - Pico -OBJS += ../../Pico/Pico/Pico.o ../../Pico/Pico/Memory.o +OBJS += ../../Pico/Pico/Pico.o ../../Pico/Pico/Memory.o ../../Pico/Pico/xpcm.o # Pico - carthw OBJS += ../../Pico/carthw/carthw.o ../../Pico/carthw/svp/svp.o ../../Pico/carthw/svp/Memory.o \ ../../Pico/carthw/svp/ssp16.o ../../Pico/carthw/svp/compiler.o ../../Pico/carthw/svp/stub_arm.o @@ -203,6 +203,8 @@ up: PicoDrive.gpe ../../cpu/musashi/m68kops.c : @make -C ../../cpu/musashi +../../Pico/Pico.o : ../../Pico/PicoFrameHints.c ../../Pico/PicoInt.h +../../Pico/Memory.o Pico/cd/Memory.o : ../../Pico/MemoryCmn.c ../../Pico/PicoInt.h # build helix libs ../common/helix/helix_mp3.a: diff --git a/gp2x/version.h b/gp2x/version.h index 848b48b..580a8ae 100644 --- a/gp2x/version.h +++ b/gp2x/version.h @@ -1,2 +1,2 @@ -#define VERSION "1.40c" +#define VERSION "1.45" diff --git a/linux/940ctl_ym2612.c b/linux/940ctl_ym2612.c index 9e07b9f..32e672f 100644 --- a/linux/940ctl_ym2612.c +++ b/linux/940ctl_ym2612.c @@ -17,10 +17,6 @@ #include "../../Pico/PicoInt.h" -static YM2612 ym2612; - -YM2612 *ym2612_940 = &ym2612; - // static _940_data_t shared_data_; static _940_ctl_t shared_ctl_; // static _940_data_t *shared_data = &shared_data_; @@ -33,7 +29,7 @@ unsigned char *mp3_mem = 0; /***********************************************************/ -int YM2612Write_940(unsigned int a, unsigned int v) +int YM2612Write_940(unsigned int a, unsigned int v, int scanline) { YM2612Write_(a, v); diff --git a/linux/Makefile b/linux/Makefile index e3c89fc..cafe81e 100644 --- a/linux/Makefile +++ b/linux/Makefile @@ -99,8 +99,8 @@ mkdirs: mkdir -p $(DIRS) Pico/carthw/svp/compiler.o : ../../Pico/carthw/svp/gen_arm.c - -Pico/Pico.o : ../../Pico/PicoFrameHints.c +Pico/Pico.o : ../../Pico/PicoFrameHints.c ../../Pico/PicoInt.h +Pico/Memory.o Pico/cd/Memory.o : ../../Pico/MemoryCmn.c ../../Pico/PicoInt.h ../../cpu/musashi/m68kops.c : @make -C ../../cpu/musashi