}\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
\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
\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
/* 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
return;\r
}\r
\r
+ YM2612ResetChip_();\r
internal_reset();\r
\r
add_job_940(JOB940_YM2612RESETCHIP);\r