Author Topic: CRTC-ports - read/write only?  (Read 1505 times)

0 Members and 1 Guest are viewing this topic.

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1012
  • Likes Given: 926
CRTC-ports - read/write only?
« on: 00:00, 21 November 09 »
Hi together,
Megachur gave me a DSK with a music compilation on it.
He told me, that 1 tune causes a crash in JavaCPC.
So I asked him for sources.
I compiled the sources, and played the music manually. I saw the screen moving.
The music was ripped from the game "Night Shift"
"Night Shift".
Then I also tried the game itself.
Result: When music begun to play, the graphics were corrupted.

So I searched in CRTC emulation and fixed the bug:

Grim writes in his CRTC-docs, that Ports >=&BE00 are read only.
Because this info I modified this code:
Code: [Select]
  public void writePort(int port, int value) {
    if (port >= 0xbe00){
        if (debug)
            System.err.println("Port "+Util.hex(port)+" is Read-Only!");
        return;
    }
    if ((port & registerSelectMask) == registerSelectTest){
      selReg = value & 0x1f;
      if (debug)
          System.out.println("CRTC-Port register selection from port:"+port+ " selReg:"+selReg);
    }
    else{
      setRegister(selReg,value);
      if (debug)
          System.out.println("CRTC-Port register write from port:"+port+ " selReg:"+selReg + " written value:"+value);
    }
}

This solved the problem.

The question I have now is:
Is this bugfix correct here in CRTC emulation or not?
@Executioner: I don't understand the port mappings in CPC.java. Maybe it need to be fixed there?

Cruel bug with really funny result! We first suggested, that the z80 emulation was bad here.
« Last Edit: 00:05, 21 November 09 by Devilmarkus »
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 391
  • Likes Given: 60
Re: CRTC-ports - read/write only?
« Reply #1 on: 03:24, 23 November 09 »
That looks like it should fix the problem for the CPC implementation, but it's not actually correct. The correct code should be:

if ((port & registerSelectMask) == registerSelectTest)
      selReg = value & 0x1f;
else if ((port & registerWriteMask) == registerWriteTest)
      setRegister(selReg, value);


Of course, you need to add the new variables and a set routine similar to setRegisterSelectMask() called setRegisterWriteMask() which must be called from CPC.java. eg.

crtc.setRegisterSelectMask(0x0300, 0x0000);
crtc.setRegisterWriteMask(0x0300, 0x0100);

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1012
  • Likes Given: 926
Re: CRTC-ports - read/write only?
« Reply #2 on: 12:01, 23 November 09 »
Of course, you need to add the new variables and a set routine similar to setRegisterSelectMask() called setRegisterWriteMask() which must be called from CPC.java. eg.

crtc.setRegisterSelectMask(0x0300, 0x0000);
crtc.setRegisterWriteMask(0x0300, 0x0100);


Thanks for advice.

Please also explain me, what do the values mean in here. (0x0300, 0x0000, 0x0100)
« Last Edit: 12:26, 23 November 09 by Devilmarkus »
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 783
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 391
  • Likes Given: 60
Re: CRTC-ports - read/write only?
« Reply #3 on: 02:55, 24 November 09 »
Please also explain me, what do the values mean in here. (0x0300, 0x0000, 0x0100)

The test routine (in writePort) does a bitwise AND of the first value, then tests for equality with the second. So it takes the input value BC00..BFFF, AND's it with 0x300 to give one of 0x0000, 0x0100, 0x0200, 0x0300 and then compares that with 0x0000 for register select or 0x0100 for register write.

Cheers,
Richard