pcm1bit = new PCM1BIT(this, emu);
fdc = new MB8877(this, emu);
- switch(config.sound_device_type) {
- case 0:
- break;
- case 1:
- connect_opn = true;
- break;
- case 2:
- connect_whg = true;
- break;
- case 3:
- connect_whg = true;
- connect_opn = true;
- break;
- case 4:
- connect_thg = true;
- break;
- case 5:
- connect_thg = true;
- connect_opn = true;
- break;
- case 6:
- connect_thg = true;
- connect_whg = true;
- break;
- case 7:
- connect_thg = true;
- connect_whg = true;
- connect_opn = true;
- break;
- }
-
- if(config.sound_device_type != 0) {
- if(connect_opn) opn[0] = new YM2203(this, emu); // OPN
- if(connect_whg) opn[1] = new YM2203(this, emu); // WHG
- if(connect_thg) opn[2] = new YM2203(this, emu); // THG
- }
+ opn[0] = new YM2203(this, emu); // OPN
+ opn[1] = new YM2203(this, emu); // WHG
+ opn[2] = new YM2203(this, emu); // THG
#if !defined(_FM77AV_VARIANTS)
psg = new YM2203(this, emu);
event->set_context_sound(pcm1bit);
#if !defined(_FM77AV_VARIANTS)
- if(psg != NULL) {
+ //if(psg != NULL) {
mainio->set_context_psg(psg);
//psg->is_ym2608 = false;
event->set_context_sound(psg);
- }
+ //}
#endif
- if(connect_opn) {
- event->set_context_sound(opn[0]);
- }
- if(connect_whg) {
- event->set_context_sound(opn[1]);
- }
- if(connect_thg) {
- event->set_context_sound(opn[2]);
- }
+ event->set_context_sound(opn[0]);
+ event->set_context_sound(opn[1]);
+ event->set_context_sound(opn[2]);
#ifdef DATAREC_SOUND
event->set_context_sound(drec);
#endif
// SOUND
mainio->set_context_beep(pcm1bit);
- if(connect_opn) {
- opn[0]->set_context_irq(mainio, FM7_MAINIO_OPN_IRQ, 0xffffffff);
- //opn[0]->set_context_port_a(mainio, FM7_MAINIO_OPNPORTA_CHANGED, 0xff, 0);
- //opn[0]->set_context_port_b(mainio, FM7_MAINIO_OPNPORTB_CHANGED, 0xff, 0);
- mainio->set_context_opn(opn[0], 0);
- }
- if(connect_whg) {
- opn[1]->set_context_irq(mainio, FM7_MAINIO_WHG_IRQ, 0xffffffff);
- mainio->set_context_opn(opn[1], 1);
- }
-
- if(connect_thg) {
- opn[2]->set_context_irq(mainio, FM7_MAINIO_THG_IRQ, 0xffffffff);
- mainio->set_context_opn(opn[2], 2);
- }
+ opn[0]->set_context_irq(mainio, FM7_MAINIO_OPN_IRQ, 0xffffffff);
+ //opn[0]->set_context_port_a(mainio, FM7_MAINIO_OPNPORTA_CHANGED, 0xff, 0);
+ //opn[0]->set_context_port_b(mainio, FM7_MAINIO_OPNPORTB_CHANGED, 0xff, 0);
+ mainio->set_context_opn(opn[0], 0);
+ opn[1]->set_context_irq(mainio, FM7_MAINIO_WHG_IRQ, 0xffffffff);
+ mainio->set_context_opn(opn[1], 1);
+ opn[2]->set_context_irq(mainio, FM7_MAINIO_THG_IRQ, 0xffffffff);
+ mainio->set_context_opn(opn[2], 2);
mainmem->set_context_mainio(mainio);
mainmem->set_context_display(display);
void VM::reset()
{
+ int i, j;
+ uint8 data;
// reset all devices
for(DEVICE* device = first_device; device; device = device->next_device) {
device->reset();
}
- psg->SetReg(0x2e, 0); // set prescaler
+ // psg->SetReg(0x2e, 0); // set prescaler
+ //opn[0]->SetReg(0x2e, 0); // set prescaler
+ //opn[1]->SetReg(0x2e, 0); // set prescaler
+ //opn[2]->SetReg(0x2e, 0); // set prescaler
+#if 1
+ if(psg != NULL) {
+ for(i = 0; i < 0x0e; i++) {
+ psg->write_io8(0, i);
+ data = (i == 7) ? 0xff : 0x00;
+ psg->write_io8(1, data);
+ }
+ }
+ for(i = 0; i < 0x0e; i++) {
+ data = (i == 7) ? 0xff : 0x00;
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, i);
+ opn[j]->write_io8(1, data);
+ }
+ }
+ for(i = 0x30; i < 0x40; i++) {
+ if((i & 0x03) < 3) {
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, i);
+ opn[j]->write_io8(1, 0x00);
+ }
+ }
+ }
+ for(i = 0x40; i < 0x50; i++) {
+ if((i & 0x03) < 3) {
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, i);
+ opn[j]->write_io8(1, 0x7f);
+ }
+ }
+ }
+ for(i = 0x50; i < 0x60; i++) {
+ if((i & 0x03) < 3) {
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, i);
+ opn[j]->write_io8(1, 0x1f);
+ }
+ }
+ }
+ for(i = 0x60; i < 0xb4; i++) {
+ if((i & 0x03) < 3) {
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, i);
+ opn[j]->write_io8(1, 0x00);
+ }
+ }
+ }
+ for(i = 0x80; i < 0x90; i++) {
+ if((i & 0x03) < 3) {
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, i);
+ opn[j]->write_io8(1, 0xff);
+ }
+ }
+ }
+ for(i = 0; i < 3; i++) {
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, 0x28);
+ opn[j]->write_io8(1, i);
+ }
+ }
+ for(j = 0; j < 3; j++) {
+ opn[j]->write_io8(0, 0x27);
+ opn[j]->write_io8(1, 0);
+ }
+ psg->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
+ opn[0]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
+ opn[1]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
+ opn[2]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
+
+
+ // for(i = 0; i < 3; i++) {
+ // opn_data[i] = 0;
+ // opn_cmdreg[i] = 0;
+ // opn_address[i] = 0x27;
+ //}
+#endif
}
void VM::special_reset()
// init sound manager
event->initialize_sound(rate, samples);
// init sound gen
- if(connect_opn) opn[0]->init(rate, 1228800, samples, 0, 0);
- if(connect_whg) opn[1]->init(rate, 1228800, samples, 0, 0);
- if(connect_thg) opn[2]->init(rate, 1228800, samples, 0, 0);
+ opn[0]->init(rate, 1228800, samples, 0, 0);
+ opn[1]->init(rate, 1228800, samples, 0, 0);
+ opn[2]->init(rate, 1228800, samples, 0, 0);
#if !defined(_FM77AV_VARIANTS)
psg->init(rate, 1228800, samples, 0, 0);
#endif
#define USE_BOOT_MODE 4
#define USE_CPU_TYPE
#define USE_SPECIAL_RESET
-#undef HAS_YM2608
-#define SUPPORT_YM2203_PORT
+//#undef HAS_YM2608
+//#define SUPPORT_YM2203_PORT
//#define HAS_AY_3_8910
// 4:3
#define SCREEN_WIDTH_ASPECT 400
void FM7_MAINIO::reset(void)
{
- int i;
+ int i, j;
+ uint8 data;
if(event_beep >= 0) cancel_event(this, event_beep);
if(event_timerirq >= 0) cancel_event(this, event_timerirq);
event_beep = -1;
psg_data = 0;
psg_cmdreg = 0;
psg_address = 0;
- for(i = 0; i < 3; i++) {
- opn_data[i] = 0;
- opn_cmdreg[i] = 0;
- opn_address[i] = 0;
+ connect_opn = connect_whg = connect_thg = false;
+ if(opn_psg_77av) connect_opn = true;
+
+ switch(config.sound_device_type) {
+ case 0:
+ break;
+ case 1:
+ connect_opn = true;
+ break;
+ case 2:
+ connect_whg = true;
+ break;
+ case 3:
+ connect_whg = true;
+ connect_opn = true;
+ break;
+ case 4:
+ connect_thg = true;
+ break;
+ case 5:
+ connect_thg = true;
+ connect_opn = true;
+ break;
+ case 6:
+ connect_thg = true;
+ connect_whg = true;
+ break;
+ case 7:
+ connect_thg = true;
+ connect_whg = true;
+ connect_opn = true;
+ break;
}
nmi_count = 0;
irq_count = 0;
case 1: // Read Data
break;
case 2: // Write Data
- psg->write_io8(0, psg_address);
- psg->write_io8(1, val & 0x00ff);
+ printf("PSG WRITE 2 DATA %02x to REG ADDR=%02x\n", psg_data, psg_address);
+ psg->write_io8(0, psg_address & 0x0f);
+ psg->write_io8(1, psg_data);
//psg->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
break;
case 3: // Register address
psg_address = val & 0x0f;
+ //psg->write_io8(0, psg_address & 0x0f);
break;
}
}
}
switch(psg_cmdreg) {
case 0:
+ //val = 0xff;
+ // break;
case 1:
case 2:
case 3:
set_opn_cmd(0, cmd);
return;
}
+ uint32 mask[16] = { // Parameter is related by XM7. Thanks Ryu.
+ 0xff, 0x0f, 0xff, 0x0f,
+ 0xff, 0x0f, 0x1f, 0xff,
+ 0x1f, 0x1f, 0x1f, 0xff,
+ 0xff, 0x0f, 0xff, 0xff
+ };
psg_cmdreg = (uint8)(cmd & 0b00000011);
switch(psg_cmdreg) {
case 0:
break;
case 1:
- psg->write_io8(0, psg_address);
- psg_data = psg->read_io8(1);
- //printf("PSG READ DATA %02x from REG ADDR=%02x\n", psg_data, psg_address);
+ psg->write_io8(0, psg_address & 0x0f);
+ psg_data = psg->read_io8(1); // & mask[psg_address];
+ printf("PSG READ DATA %02x from REG ADDR=%02x\n", psg_data, psg_address);
break;
case 2:
- //printf("PSG WRITE DATA %02x to REG ADDR=%02x\n", psg_data, psg_address);
- psg->write_io8(0, psg_address);
+ printf("PSG WRITE DATA %02x to REG ADDR=%02x\n", psg_data, psg_address);
+ psg->write_io8(0, psg_address & 0x0f);
psg->write_io8(1, psg_data);
//psg->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
break;
case 3:
- psg_address = psg_data;
- //printf("PSG REG ADDR=%02x\n", psg_address);
+ psg_address = psg_data & 0x0f;
+ //psg->write_io8(0, psg_address & 0x0f);
+ printf("PSG REG ADDR=%02x\n", psg_address);
break;
default:
break;
case 0: // High inpedance
break;
case 1: // Read Data
- opn[index]->write_io8(0, opn_address[index]);
- opn_data[index] = opn[index]->read_io8(1);
+ //opn[index]->write_io8(0, opn_address[index]);
+ //opn_data[index] = opn[index]->read_io8(1);
break;
case 2: // Write Data
- //printf("OPN %d WRITE DATA %02x to REG ADDR=%02x\n", index, val, opn_address[index]);
+ printf("OPN %d WRITE DATA %02x to REG ADDR=%02x\n", index, val, opn_address[index]);
opn[index]->write_io8(0, opn_address[index]);
opn[index]->write_io8(1, val & 0x00ff);
//opn[index]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
break;
case 3: // Register address
opn_address[index] = val & 0xff;
+ //opn[index]->write_io8(0, opn_address[index]);
//printf("OPN %d REG ADDR=%02x\n", index, opn_address[index]);
if((val > 0x2c) && (val < 0x30)) {
opn_data[index] = 0;
}
if(opn_cmdreg[index] == 0b00000100) {
// Read Status
- opn_stat[index] = opn[index]->read_io8(0);
+ opn_stat[index] = opn[index]->read_io8(0) & 0x03;
return opn_stat[index];
}
switch(opn_cmdreg[index]) {
case 0:
+ //val = 0xff;
+ //break;
case 1:
case 2:
case 3:
if((index == 0) && (!connect_opn)) return;
if((index == 1) && (!connect_whg)) return;
if((index == 2) && (!connect_thg)) return;
-
+ uint32 mask[16] = { // Parameter is related by XM7. Thanks Ryu.
+ 0xff, 0x0f, 0xff, 0x0f,
+ 0xff, 0x0f, 0x1f, 0xff,
+ 0x1f, 0x1f, 0x1f, 0xff,
+ 0xff, 0x0f, 0xff, 0xff
+ };
opn_cmdreg[index] = cmd & 0b00001111;
switch(opn_cmdreg[index]) {
case 0:
break;
case 1:
+ //if(opn_address[index] > 0x0f) {
+ // opn_data[index] = 0xff;
+ // break;
+ // }
opn[index]->write_io8(0, opn_address[index]);
- opn_data[index] = opn[index]->read_io8(1);
- //printf("OPN %d READ DATA %02x from REG ADDR=%02x\n", index, opn_data[index], opn_address[index]);
+ opn_data[index] = opn[index]->read_io8(1) & mask[opn_address[index]];
+ printf("OPN %d READ DATA %02x from REG ADDR=%02x\n", index, opn_data[index], opn_address[index]);
break;
case 2:
- //printf("OPN %d WRITE DATA %02x to REG ADDR=%02x\n", index, opn_data[index], opn_address[index]);
+ printf("OPN %d WRITE DATA %02x to REG ADDR=%02x\n", index, opn_data[index], opn_address[index]);
+ //if(((opn_address[index] > 0x0d) && (opn_address[index] < 0x27)) ||
+ // ((opn_address[index] > 0x28) && (opn_address[index] < 0x2d))) break;
opn[index]->write_io8(0, opn_address[index]);
opn[index]->write_io8(1, opn_data[index]);
//opn[index]->write_signal(SIG_YM2203_MUTE, 0x00, 0x01); // Okay?
break;
case 3:
opn_address[index] = opn_data[index];
- //printf("OPN %d REG ADDR=%02x\n", index, opn_address[index]);
+ printf("OPN %d REG ADDR=%02x\n", index, opn_address[index]);
+ //opn[index]->write_io8(0, opn_address[index]);
if((opn_data[index] > 0x2c) && (opn_data[index] < 0x30)) {
opn_data[index] = 0;
opn[index]->write_io8(0, opn_address[index]);
cmt_invert = val_b;
break;
case FM7_MAINIO_TIMERIRQ: //
- //set_irq_timer(val_b);
+ set_irq_timer(val_b);
break;
case FM7_MAINIO_LPTIRQ: //
set_irq_printer(val_b);
break;
case FM7_MAINIO_OPN_IRQ:
intstat_opn = val_b;
- printf("OPN INTERRUPT\n");
do_irq(val_b);
break;
case FM7_MAINIO_WHG_IRQ:
- printf("WHG INTERRUPT\n");
intstat_whg = val_b;
do_irq(val_b);
break;
#define PUSHBYTE(b) --S; WM(SD,b)
#define PUSHWORD(w) --S; WM(SD, w.b.l); --S; WM(SD, w.b.h)
-#define PULLBYTE(b) b = RM(SD); S++
-#define PULLWORD(w) w = RM(SD) << 8; S++; w |= RM(SD); S++
+#define PULLBYTE(b) b = RM(SD); b &= 0xff; S++
+#define PULLWORD(w) w = RM(SD) << 8; S++; w |= RM(SD); w &= 0xffff; S++
#define PSHUBYTE(b) --U; WM(UD, b);
#define PSHUWORD(w) --U; WM(UD, w.b.l); --U; WM(UD, w.b.h)
-#define PULUBYTE(b) b = RM(UD); U++
-#define PULUWORD(w) w = RM(UD) << 8; U++; w |= RM(UD); U++
+#define PULUBYTE(b) b = RM(UD); b &= 0xff; U++
+#define PULUWORD(w) w = RM(UD) << 8; U++; w |= RM(UD); w &= 0xffff; U++
#define CLR_HNZVC CC &= ~(CC_H | CC_N | CC_Z | CC_V | CC_C)
#define CLR_NZV CC &= ~(CC_N | CC_Z | CC_V)
#define SET_FLAGS8(a,b,r) {SET_N8(r); SET_Z8(r); SET_V8(a, b, r); SET_C8(r);}
#define SET_FLAGS16(a,b,r) {SET_N16(r); SET_Z16(r); SET_V16(a, b, r); SET_C16(r);}
-#define NXORV ((CC & CC_N) ^ ((CC & CC_V) << 2) != 0)
+//#define NXORV ((CC & CC_N) ^ ((CC & CC_V) << 2) != 0)
+#define NXORV (((CC & CC_N) ^ ((CC & CC_V) << 2)) != 0)
/* for treating an unsigned byte as a signed word */
#define SIGNED(b) ((uint16)((b & 0x80) ? (b | 0xff00) : b))
U = 0;
S = 0;
EA = 0;
- PCD = RM16(0xfffe);
+ PCD = RM16(0xfffe) & 0xffff;
}
void MC6809::write_signal(int id, uint32 data, uint32 mask)
}
int_state &= ~(MC6809_SYNC_IN | MC6809_CWAI_IN | MC6809_NMI_BIT); // $FE1E
CC |= CC_IF | CC_II; /* inhibit FIRQ and IRQ */
- PCD = RM16(0xfffc);
+ PCD = RM16(0xfffc) & 0xffff;
//goto _int_cycle;
} else if(int_state & (MC6809_FIRQ_BIT | MC6809_IRQ_BIT)) {
//if((int_state & MC6809_SYNC_IN) != 0) int_state |= MC6809_SYNC_OUT;
icount -= 10; /* subtract +10 cycles */
}
CC |= CC_IF | CC_II; /* inhibit FIRQ and IRQ */
- PCD = RM16(0xfff6);
+ PCD = RM16(0xfff6) & 0xffff;
int_state &= ~(MC6809_SYNC_IN | MC6809_CWAI_IN); // $FE1E
} else if((int_state & MC6809_IRQ_BIT) && !(CC & CC_II)) {
/* standard IRQ */
icount -= 19; /* subtract +19 cycles */
}
CC = CC | CC_II ; /* inhibit IRQ */
- PCD = RM16(0xfff8);
+ PCD = RM16(0xfff8) & 0xffff;
int_state &= ~(MC6809_SYNC_IN | MC6809_CWAI_IN); // $FE1E
}
//goto _int_cycle;
break;
}
icount -= index_cycle_em[postbyte];
-
+ EAD &= 0xffff;
#else
uint8 postbyte = ROP_ARG(PCD);
uint8 postbyte_hi = (postbyte & 0xf0) >> 4;
inline void MC6809::illegal()
{
- //logerror("MC6809: illegal opcode at %04x\n", PC);
+ printf("M6809: illegal opcode at %04x %02x %02x %02x %02x %02x \n",
+ PC - 2, RM(PC - 2), RM(PC - 1), RM(PC), RM(PC + 1), RM(PC + 2));
}
/* $00 NEG direct ?**** */
r = (CC & CC_C) << 7;
CLR_NZC;
CC |= (t & CC_C);
- r |= (t >> 1);
+ // r |= (t >> 1);
+ t >>= 1;
+ r |= t;
SET_NZ8(r);
WM(EAD, r);
}
r = (CC & CC_C) | (t << 1);
CLR_NZVC;
SET_FLAGS8(t, t, r);
- WM(EAD, r);
+ WM(EAD, (uint8)r);
}
/* $0A DEC direct -***- */
/* $0B DCC direct */
inline void MC6809::dcc_di(void)
{
- BYTE t, s;
+ uint8 t, s;
DIRBYTE(t);
--t;
CLR_NZVC;
inline void MC6809::jmp_di()
{
DIRECT;
- PCD = EAD;
+ PCD = EAD & 0xffff;
}
/* $0F CLR direct -0100 */
PUSHBYTE(A);
PUSHBYTE(CC);
CC |= CC_IF | CC_II; /* inhibit FIRQ and IRQ */
- PCD = RM16(0xfffa);
+ PCD = RM16(0xfffa) & 0xffff;
}
/* $103F SWI2 absolute indirect ----- */
PUSHBYTE(B);
PUSHBYTE(A);
PUSHBYTE(CC);
- PCD = RM16(0xfff4);
+ PCD = RM16(0xfff4) & 0xffff;
}
/* $113F SWI3 absolute indirect ----- */
PUSHBYTE(B);
PUSHBYTE(A);
PUSHBYTE(CC);
- PCD = RM16(0xfff2);
+ PCD = RM16(0xfff2) & 0xffff;
}
/* $40 NEGA inherent ?**** */
/* $56 RORB inherent -**-* */
inline void MC6809::rorb()
{
- uint8 r;
+ uint8 r, t;
r = (CC & CC_C) << 7;
CLR_NZC;
CC |= (B & CC_C);
- r |= (B >> 1);
+ t = B >> 1;
+ r |= t;
SET_NZ8(r);
B = r;
}
inline void MC6809::jmp_ix()
{
fetch_effective_address();
- PCD = EAD;
+ PCD = EAD & 0xffff;
}
/* $6F CLR indexed -0100 */
inline void MC6809::jmp_ex()
{
EXTENDED;
- PCD = EAD;
+ PCD = EAD & 0xffff;
}
/* $7F CLR extended -0100 */
{
DIRECT;
PUSHWORD(pPC);
- PCD = EAD;
+ PCD = EAD & 0xffff;
}
/* $9E LDX (LDY) direct -**0- */
{
fetch_effective_address();
PUSHWORD(pPC);
- PCD = EAD;
+ PCD = EAD & 0xffff;
}
/* $aE LDX (LDY) indexed -**0- */
{
EXTENDED;
PUSHWORD(pPC);
- PCD = EAD;
+ PCD = EAD & 0xffff;
}
/* $bE LDX (LDY) extended -**0- */