neophob / wpc-emu

Williams Pinball machine emulator, Play it @
https://playfield.dev
Apache License 2.0
68 stars 12 forks source link

TickCount mistake in Indexed addressing calc? #84

Open ecurtz opened 3 years ago

ecurtz commented 3 years ago

You'll have to double check this, but I believe there's an error in the cycle count for index address mode 0x0F. TickCount is increased by 5, which is the correct total, but this case is only available as indirect which will add another 3 cycles.

This is around line 595 of cpu6809.js:

        case 0x0F: // EA = ADDRESS
          EA = this.fetch16();
          this.tickCount += 5;
          break;
        default: {
          const mode = postByte & ADDRESSINGMODE_FIELD;
          throw new Error('INVALID_ADDRESS_MODE_' + mode);
        }
      }

      EA &= 0xFFFF;
      if (postByte & INDIRECT_FIELD) {
        /* TODO: Indirect "Increment/Decrement by 1" is not valid
        const adrmode = postByte & ADDRESSINGMODE_FIELD
        if (adrmode === 0 || adrmode === 2) {
          throw new Error('INVALID_INDIRECT_ADDRESSMODE_', adrmode);
        }
        */
        // INDIRECT addressing
        EA = this.ReadWord(EA);
        this.tickCount += 3;
      }
neophob commented 3 years ago

Thenks @ecurtz .. I quickly checked http://gtoal.com/SBTPROJECT/6809sbt/reference-emulators/larry-bank/6809.C - there also 5 and 3 cycles are used for this call...

also mame looks like they use 5 or 8 cycles (case 0xff: IMMWORD(ea); EAD=RM16(EAD); m6809_ICount-=8; break;).

But I'm not that knee deep into the cpu6809 at the moment so this make's me wonder how did you find out?

ecurtz commented 3 years ago

I was looking into doing a version that works with the real 6809 quad clock timing rather than abstract cycle counts so I was going through the instructions and that one didn't seem to match. This chart is from the data sheet, I believe bottom right is the op in question. https://drive.google.com/file/d/1GmlqhsqqrwYNgE2mRUsZC9HS0Hply8xc/view?usp=sharing

neophob commented 3 years ago

thanks, this looks interesting.. do you have time for a pr? this would be fantastic!

ecurtz commented 3 years ago

I have a PCB on order that should let me test it on a real 6809 and I'll report back whenever that arrives. It would just be changing a single number, so not much of a PR, but I'll be happy to do so if it turns out the current one is wrong.

neophob commented 3 years ago

would be fantastic, thanks! I do have some in depth tests that run and where we can see what the actual difference is (like https://github.com/neophob/wpc-emu-dumps)