OSDN Git Service

[VM][MC6809] Fixing some instructions. Sounds RELICS, not sound play instruction.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 15 Mar 2015 04:28:17 +0000 (13:28 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 15 Mar 2015 04:28:17 +0000 (13:28 +0900)
source/src/vm/fm7/fm7.cpp
source/src/vm/fm7/fm7.h
source/src/vm/fm7/fm7_mainio.cpp
source/src/vm/mc6809.cpp

index 2f9f406..8365f51 100644 (file)
@@ -56,42 +56,9 @@ VM::VM(EMU* parent_emu): emu(parent_emu)
        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);
@@ -184,21 +151,15 @@ void VM::connect_bus(void)
 
        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
@@ -239,21 +200,14 @@ void VM::connect_bus(void)
        // 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);
@@ -308,11 +262,93 @@ void VM::update_config()
 
 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()
@@ -378,9 +414,9 @@ void VM::initialize_sound(int rate, int samples)
        // 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   
index fc1f2b1..881f765 100644 (file)
@@ -17,8 +17,8 @@
 #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 
index a9b7993..33b4d58 100644 (file)
@@ -33,7 +33,8 @@ void FM7_MAINIO::initialize(void)
 
 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;
@@ -53,10 +54,38 @@ void FM7_MAINIO::reset(void)
        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;
@@ -369,12 +398,14 @@ void FM7_MAINIO::set_psg(uint8 val)
                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;
        }
 }
@@ -387,6 +418,8 @@ uint8 FM7_MAINIO::get_psg(void)
        }
        switch(psg_cmdreg) {
                case 0:
+                 //val = 0xff;
+                 //    break;
                case 1:
                case 2:
                case 3:
@@ -405,24 +438,31 @@ void FM7_MAINIO::set_psg_cmd(uint8 cmd)
                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;
@@ -538,17 +578,18 @@ void FM7_MAINIO::set_opn(int index, uint8 val)
                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;
@@ -602,11 +643,13 @@ uint8 FM7_MAINIO::get_opn(int index)
        }
        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:
@@ -624,25 +667,37 @@ void FM7_MAINIO::set_opn_cmd(int index, uint8 cmd)
        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]);
@@ -719,7 +774,7 @@ void FM7_MAINIO::write_signal(int id, uint32 data, uint32 mask)
                        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);
@@ -760,11 +815,9 @@ void FM7_MAINIO::write_signal(int id, uint32 data, uint32 mask)
                        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;
index 0fa647d..242a3e0 100644 (file)
 
 #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))
@@ -295,7 +296,7 @@ void MC6809::reset()
        U = 0;
        S = 0;
        EA = 0;
-       PCD = RM16(0xfffe);
+       PCD = RM16(0xfffe) & 0xffff;
 }
 
 void MC6809::write_signal(int id, uint32 data, uint32 mask)
@@ -400,7 +401,7 @@ check_nmi:
                }
                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;
@@ -420,7 +421,7 @@ check_nmi:
                                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 */
@@ -444,7 +445,7 @@ check_nmi:
                                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;
@@ -924,7 +925,7 @@ inline void MC6809::fetch_effective_address()
                        break;
        }
        icount -= index_cycle_em[postbyte];
-       
+       EAD &= 0xffff;
 #else    
        uint8 postbyte = ROP_ARG(PCD);
        uint8 postbyte_hi = (postbyte & 0xf0) >> 4;
@@ -1197,7 +1198,8 @@ inline void MC6809::fetch_effective_address()
 
 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 ?**** */
@@ -1258,7 +1260,9 @@ inline void MC6809::ror_di()
        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);
 }
@@ -1294,7 +1298,7 @@ inline void MC6809::rol_di()
        r = (CC & CC_C) | (t << 1);
        CLR_NZVC;
        SET_FLAGS8(t, t, r);
-       WM(EAD, r);
+       WM(EAD, (uint8)r);
 }
 
 /* $0A DEC direct -***- */
@@ -1311,7 +1315,7 @@ inline void MC6809::dec_di()
 /* $0B DCC direct */
 inline void MC6809::dcc_di(void)
 {
-       BYTE t, s;
+       uint8 t, s;
        DIRBYTE(t);
        --t;
        CLR_NZVC;
@@ -1349,7 +1353,7 @@ inline void MC6809::tst_di()
 inline void MC6809::jmp_di()
 {
        DIRECT;
-       PCD = EAD;
+       PCD = EAD & 0xffff;
 }
 
 /* $0F CLR direct -0100 */
@@ -1958,7 +1962,7 @@ inline void MC6809::swi()
        PUSHBYTE(A);
        PUSHBYTE(CC);
        CC |= CC_IF | CC_II;    /* inhibit FIRQ and IRQ */
-       PCD = RM16(0xfffa);
+       PCD = RM16(0xfffa) & 0xffff;
 }
 
 /* $103F SWI2 absolute indirect ----- */
@@ -1973,7 +1977,7 @@ inline void MC6809::swi2()
        PUSHBYTE(B);
        PUSHBYTE(A);
        PUSHBYTE(CC);
-       PCD = RM16(0xfff4);
+       PCD = RM16(0xfff4) & 0xffff;
 }
 
 /* $113F SWI3 absolute indirect ----- */
@@ -1988,7 +1992,7 @@ inline void MC6809::swi3()
        PUSHBYTE(B);
        PUSHBYTE(A);
        PUSHBYTE(CC);
-       PCD = RM16(0xfff2);
+       PCD = RM16(0xfff2) & 0xffff;
 }
 
 /* $40 NEGA inherent ?**** */
@@ -2175,11 +2179,12 @@ inline void MC6809::lsrb()
 /* $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;
 }
@@ -2419,7 +2424,7 @@ inline void MC6809::tst_ix()
 inline void MC6809::jmp_ix()
 {
        fetch_effective_address();
-       PCD = EAD;
+       PCD = EAD & 0xffff;
 }
 
 /* $6F CLR indexed -0100 */
@@ -2556,7 +2561,7 @@ inline void MC6809::tst_ex()
 inline void MC6809::jmp_ex()
 {
        EXTENDED;
-       PCD = EAD;
+       PCD = EAD & 0xffff;
 }
 
 /* $7F CLR extended -0100 */
@@ -3017,7 +3022,7 @@ inline void MC6809::jsr_di()
 {
        DIRECT;
        PUSHWORD(pPC);
-       PCD = EAD;
+       PCD = EAD & 0xffff;
 }
 
 /* $9E LDX (LDY) direct -**0- */
@@ -3253,7 +3258,7 @@ inline void MC6809::jsr_ix()
 {
        fetch_effective_address();
        PUSHWORD(pPC);
-       PCD = EAD;
+       PCD = EAD & 0xffff;
 }
 
 /* $aE LDX (LDY) indexed -**0- */
@@ -3482,7 +3487,7 @@ inline void MC6809::jsr_ex()
 {
        EXTENDED;
        PUSHWORD(pPC);
-       PCD = EAD;
+       PCD = EAD & 0xffff;
 }
 
 /* $bE LDX (LDY) extended -**0- */