new z80 scheduling method, timers are still wip
authornotaz <notasas@gmail.com>
Sun, 25 May 2008 21:25:46 +0000 (21:25 +0000)
committernotaz <notasas@gmail.com>
Sun, 25 May 2008 21:25:46 +0000 (21:25 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@459 be3aeb3a-fb24-0410-a615-afba39da0efa

gp2x/940ctl.c
gp2x/940ctl.h
gp2x/Makefile
gp2x/version.h
linux/940ctl_ym2612.c
linux/Makefile

index f217dea..8c8b18b 100644 (file)
@@ -51,160 +51,64 @@ static FILE *loaded_mp3 = 0;
 }\r
 \r
 /* these will be managed locally on our side */\r
-static UINT8 *REGS = 0;                /* we will also keep local copy of regs for savestates and such */\r
-static INT32 *addr_A1;         /* address line A1      */\r
-\r
-static int   dacen;\r
-static INT32 dacout;\r
 static UINT8 ST_address;       /* address register     */\r
+static INT32 addr_A1;          /* address line A1      */\r
 \r
 static int   writebuff_ptr = 0;\r
 \r
 \r
-/* OPN Mode Register Write */\r
-static int set_timers( int v )\r
-{\r
-       int change;\r
-\r
-       /* b7 = CSM MODE */\r
-       /* b6 = 3 slot mode */\r
-       /* b5 = reset b */\r
-       /* b4 = reset a */\r
-       /* b3 = timer enable b */\r
-       /* b2 = timer enable a */\r
-       /* b1 = load b */\r
-       /* b0 = load a */\r
-       change = (ym2612_st->mode ^ v) & 0xc0;\r
-       ym2612_st->mode = v;\r
-\r
-       /* reset Timer b flag */\r
-       if( v & 0x20 )\r
-               ym2612_st->status &= ~2;\r
-\r
-       /* reset Timer a flag */\r
-       if( v & 0x10 )\r
-               ym2612_st->status &= ~1;\r
-\r
-       return change;\r
-}\r
-\r
 /* YM2612 write */\r
 /* a = address */\r
 /* v = value   */\r
 /* returns 1 if sample affecting state changed */\r
-int YM2612Write_940(unsigned int a, unsigned int v)\r
+int YM2612Write_940(unsigned int a, unsigned int v, int scanline)\r
 {\r
-       int addr;\r
        int upd = 1;    /* the write affects sample generation */\r
 \r
-       v &= 0xff;      /* adjust to 8 bit bus */\r
        a &= 3;\r
 \r
        //printf("%05i:%03i: ym w ([%i] %02x)\n", Pico.m.frame_count, Pico.m.scanline, a, v);\r
 \r
-       switch( a ) {\r
-       case 0: /* address port 0 */\r
-               if (!*addr_A1 && ST_address == v)\r
-                       return 0;       /* address already selected, don't send this command to 940 */\r
-               ST_address = v;\r
-               /* don't send DAC or timer related address changes to 940 */\r
-               if (!*addr_A1 && (v & 0xf0) == 0x20 &&\r
-                       (v == 0x24 || v == 0x25 || v == 0x26 || v == 0x2a))\r
+       switch (a) {\r
+               case 0: /* address port 0 */\r
+                       if (addr_A1 == 0 && ST_address == v)\r
+                               return 0; /* address already selected, don't send this command to 940 */\r
+                       ST_address = v;\r
+                       addr_A1 = 0;\r
+                       /* don't send DAC or timer related address changes to 940 */\r
+                       if (v == 0x24 || v == 0x25 || v == 0x26 || v == 0x2a)\r
                                return 0;\r
-               *addr_A1 = 0;\r
-               upd = 0;\r
-               break;\r
-\r
-       case 1: /* data port 0    */\r
-               if (*addr_A1 != 0) {\r
-                       return 0;       /* verified on real YM2608 */\r
-               }\r
+                       upd = 0;\r
+                       break;\r
 \r
-               addr = ST_address;\r
-               REGS[addr] = v;\r
+               case 1: /* data port 0    */\r
+                       if (ST_address == 0x2b) upd = 0; /* DAC sel */\r
+                       break;\r
 \r
-               switch( addr & 0xf0 )\r
-               {\r
-               case 0x20:      /* 0x20-0x2f Mode */\r
-                       switch( addr )\r
-                       {\r
-                       case 0x24: { // timer A High 8\r
-                                       int TAnew = (ym2612_st->TA & 0x03)|(((int)v)<<2);\r
-                                       if (ym2612_st->TA != TAnew) {\r
-                                               // we should reset ticker only if new value is written. Outrun requires this.\r
-                                               ym2612_st->TA = TAnew;\r
-                                               ym2612_st->TAC = (1024-TAnew)*18;\r
-                                               ym2612_st->TAT = 0;\r
-                                       }\r
-                                       return 0;\r
-                               }\r
-                       case 0x25: { // timer A Low 2\r
-                                       int TAnew = (ym2612_st->TA & 0x3fc)|(v&3);\r
-                                       if (ym2612_st->TA != TAnew) {\r
-                                               ym2612_st->TA = TAnew;\r
-                                               ym2612_st->TAC = (1024-TAnew)*18;\r
-                                               ym2612_st->TAT = 0;\r
-                                       }\r
-                                       return 0;\r
-                               }\r
-                       case 0x26: // timer B\r
-                               if (ym2612_st->TB != v) {\r
-                                       ym2612_st->TB = v;\r
-                                       ym2612_st->TBC  = (256-v)<<4;\r
-                                       ym2612_st->TBC *= 18;\r
-                                       ym2612_st->TBT  = 0;\r
-                               }\r
-                               return 0;\r
-                       case 0x27:      /* mode, timer control */\r
-                               if (set_timers( v ))\r
-                                       break; // other side needs ST.mode for 3slot mode\r
-                               return 0;\r
-                       case 0x2a:      /* DAC data (YM2612) */\r
-                               dacout = ((int)v - 0x80) << 6;  /* level unknown (notaz: 8 seems to be too much) */\r
+               case 2: /* address port 1 */\r
+                       if (addr_A1 == 1 && ST_address == v)\r
                                return 0;\r
-                       case 0x2b:      /* DAC Sel  (YM2612) */\r
-                               /* b7 = dac enable */\r
-                               dacen = v & 0x80;\r
-                               upd = 0;\r
-                               break; // other side has to know this\r
-                       default:\r
-                               break;\r
-                       }\r
+                       ST_address = v;\r
+                       addr_A1 = 1;\r
+                       upd = 0;\r
                        break;\r
-               }\r
-               break;\r
-\r
-       case 2: /* address port 1 */\r
-               if (*addr_A1 && ST_address == v)\r
-                       return 0;\r
-               ST_address = v;\r
-               *addr_A1 = 1;\r
-               upd = 0;\r
-               break;\r
-\r
-       case 3: /* data port 1    */\r
-               if (*addr_A1 != 1) {\r
-                       return 0;       /* verified on real YM2608 */\r
-               }\r
-\r
-               addr = ST_address | 0x100;\r
-               REGS[addr] = v;\r
-               break;\r
        }\r
 \r
        //printf("ym pass\n");\r
 \r
-       if(currentConfig.EmuOpt & 4) {\r
+       if (currentConfig.EmuOpt & 4)\r
+       {\r
                UINT16 *writebuff = shared_ctl->writebuffsel ? shared_ctl->writebuff0 : shared_ctl->writebuff1;\r
 \r
                /* detect rapid ym updates */\r
-               if (upd && !(writebuff_ptr & 0x80000000) && Pico.m.scanline < 224) {\r
+               if (upd && !(writebuff_ptr & 0x80000000) && scanline < 224)\r
+               {\r
                        int mid = Pico.m.pal ? 68 : 93;\r
-                       if (Pico.m.scanline > mid) {\r
-                               //printf("%05i:%03i: rapid ym\n", Pico.m.frame_count, Pico.m.scanline);\r
+                       if (scanline > mid) {\r
+                               //printf("%05i:%03i: rapid ym\n", Pico.m.frame_count, scanline);\r
                                writebuff[writebuff_ptr++ & 0xffff] = 0xfffe;\r
                                writebuff_ptr |= 0x80000000;\r
-                               //printf("%05i:%03i: ym w ([%02x] %02x, upd=%i)\n", Pico.m.frame_count, Pico.m.scanline, addr, v, upd);\r
+                               //printf("%05i:%03i: ym w ([%02x] %02x, upd=%i)\n", Pico.m.frame_count, scanline, addr, v, upd);\r
                        }\r
                }\r
 \r
@@ -272,7 +176,9 @@ static void add_job_940(int job)
 \r
 void YM2612PicoStateLoad_940(void)\r
 {\r
-       int i, old_A1 = *addr_A1;\r
+       UINT8 *REGS = YM2612GetRegs();\r
+\r
+       int i;\r
 \r
        /* make sure JOB940_PICOSTATELOAD gets done before next JOB940_YM2612UPDATEONE */\r
        add_job_940(JOB940_PICOSTATELOAD);\r
@@ -282,32 +188,22 @@ void YM2612PicoStateLoad_940(void)
 \r
        // feed all the registers and update internal state\r
        for(i = 0; i < 0x100; i++) {\r
-               YM2612Write_940(0, i);\r
-               YM2612Write_940(1, REGS[i]);\r
+               YM2612Write_940(0, i, -1);\r
+               YM2612Write_940(1, REGS[i], -1);\r
        }\r
        for(i = 0; i < 0x100; i++) {\r
-               YM2612Write_940(2, i);\r
-               YM2612Write_940(3, REGS[i|0x100]);\r
+               YM2612Write_940(2, i, -1);\r
+               YM2612Write_940(3, REGS[i|0x100], -1);\r
        }\r
 \r
-       *addr_A1 = old_A1;\r
+       addr_A1 = *(INT32 *) (REGS + 0x200);\r
 }\r
 \r
 \r
 static void internal_reset(void)\r
 {\r
        writebuff_ptr = 0;\r
-       ym2612_st->mode   = 0;\r
-       ym2612_st->status = 0;  /* normal mode */\r
-       ym2612_st->TA     = 0;\r
-       ym2612_st->TAC    = 0;\r
-       ym2612_st->TAT    = 0;\r
-       ym2612_st->TB     = 0;\r
-       ym2612_st->TBC    = 0;\r
-       ym2612_st->TBT    = 0;\r
-       dacen     = 0;\r
-       dacout    = 0;\r
-       ST_address= 0;\r
+       ST_address = addr_A1 = -1;\r
 }\r
 \r
 \r
@@ -405,12 +301,6 @@ void YM2612Init_940(int baseclock, int rate)
        /* cause local ym2612 to init REGS */\r
        YM2612Init_(baseclock, rate);\r
 \r
-       REGS = YM2612GetRegs();\r
-       addr_A1 = (INT32 *) (REGS + 0x200);\r
-\r
-       ym2612_dacen  = &dacen;\r
-       ym2612_dacout = &dacout;\r
-\r
        internal_reset();\r
 \r
        loaded_mp3 = 0;\r
@@ -440,6 +330,7 @@ void YM2612ResetChip_940(void)
                return;\r
        }\r
 \r
+       YM2612ResetChip_();\r
        internal_reset();\r
 \r
        add_job_940(JOB940_YM2612RESETCHIP);\r
index 95e9a07..0318c1c 100644 (file)
@@ -5,7 +5,7 @@ void YM2612Init_940(int baseclock, int rate);
 void YM2612ResetChip_940(void);\r
 int  YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty);\r
 \r
-int  YM2612Write_940(unsigned int a, unsigned int v);\r
+int  YM2612Write_940(unsigned int a, unsigned int v, int scanline);\r
 unsigned char YM2612Read_940(void);\r
 \r
 int  YM2612PicoTick_940(int n);\r
index 59a7c15..4ebecb4 100644 (file)
@@ -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\r
 endif\r
 # Pico - Pico\r
-OBJS += ../../Pico/Pico/Pico.o ../../Pico/Pico/Memory.o\r
+OBJS += ../../Pico/Pico/Pico.o ../../Pico/Pico/Memory.o ../../Pico/Pico/xpcm.o\r
 # Pico - carthw\r
 OBJS += ../../Pico/carthw/carthw.o ../../Pico/carthw/svp/svp.o ../../Pico/carthw/svp/Memory.o \\r
                ../../Pico/carthw/svp/ssp16.o ../../Pico/carthw/svp/compiler.o ../../Pico/carthw/svp/stub_arm.o\r
@@ -203,6 +203,8 @@ up: PicoDrive.gpe
 ../../cpu/musashi/m68kops.c :\r
        @make -C ../../cpu/musashi\r
 \r
+../../Pico/Pico.o : ../../Pico/PicoFrameHints.c ../../Pico/PicoInt.h\r
+../../Pico/Memory.o Pico/cd/Memory.o : ../../Pico/MemoryCmn.c ../../Pico/PicoInt.h\r
 \r
 # build helix libs\r
 ../common/helix/helix_mp3.a:\r
index 848b48b..580a8ae 100644 (file)
@@ -1,2 +1,2 @@
-#define VERSION "1.40c"\r
+#define VERSION "1.45"\r
 \r
index 9e07b9f..32e672f 100644 (file)
 #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);
 
index e3c89fc..cafe81e 100644 (file)
@@ -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