Author Topic: How to read the CRTC registers?  (Read 1317 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
How to read the CRTC registers?
« on: 22:06, 11 January 11 »
Hello,
I need help from an emu coder:
CRTC type 1 and 0 return different values when you read their registers.
(Some are readable, others not)

So what do I need to do exactly here?

Code: [Select]
    public int readPort(int port) {
        if ((port & registerStatusMask) == registerStatusTest && CRTCType == 1) {
            if (vSyncCount != 0) {
                System.out.println("Status register read: " + vSyncCount);
                return (1 << 5);
            } else {
                return 0;
            }

        } else if ((port & registerReadMask) == registerReadTest) {
                System.out.println("register read: " + selReg);
            if (CRTCType == 1 && (selReg >= 14 && selReg <= 17)) {
                return reg[selReg];
            } else if (CRTCType == 0 && (selReg >= 12 && selReg <= 17)) {
                return reg[selReg];
            } else {
                    if (CRTCType == 1)
                        return 0x00;
            }
        }
        return 0xff;
    }

When is 0x00 and when is 0xFF?
(From Scratch demo reads and wants 0x00 from unreadable registers, "Demo Iz Art" wants 0xFF to set CRTC type 1)
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 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: How to read the CRTC registers?
« Reply #1 on: 22:34, 11 January 11 »
Humm... I think I found my answer:
Code: [Select]
    public int readPort(int port) {
        if ((port & registerStatusMask) == registerStatusTest && CRTCType == 1) {
            if (vSyncCount != 0) {
                System.out.println("Status register read: " + vSyncCount);
                return (1 << 5);
            } else {
                return 0;
            }

        } else if ((port & registerReadMask) == registerReadTest) {
                System.out.println("register read: " + selReg);
                int value = reg[selReg];
                if (selReg < 10 || selReg > 17) {
                    return 0x00;
                }
                if (CRTCType == 0){
                    switch (selReg){
                        case 10:
                        case 11: return value & 0x1f;
                        case 12:
                        case 14:
                        case 16: return value & 0x3f;
                        default: return value & 0xff;
                    }
                } else {
                    switch (selReg){
                        case 10:
                        case 11: return value & 0x1f;
                        case 12:
                        case 13: return 0;
                        case 16: return value & 0x3f;
                        default: return value & 0xff;
                    }
                }
        }
        return 0xff;
    }

Perhaps someone could verify this?
« Last Edit: 22:41, 11 January 11 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