Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clcd.cpp: Added IEC bus connections. #9843

Merged
merged 1 commit into from
May 28, 2022
Merged

Conversation

mnaberez
Copy link
Member

Add IEC bus connections to the Commodore LCD based on firmware evidence from Bil Herd's LCD prototype and the schematics released by Bil.

I disassembled the IEC code in the KERNAL ROM to find the connections. With these additions and the clock fix, IEC almost works but most of the time it locks up. Since we don't know if the IEC support in the LCD prototype ever actually worked, the problem could be the KERNAL or an emulation bug.

Out of dozens of attempts, I got a disk directory from c1541 twice. Since it got that far, I think the signals are hooked up correctly. I asked Curt about it and he thought so too. I hadn't committed the patch because I wanted to look into it more, but then Bil released the schematics. They confirm the connections. Since that is the case, and the emulator still works as it did before this change, I don't see any harm in committing this.

Disassembly

The IEC routines are extremely similar to those in the C64 (see below). The pin assignments are the same but the two input lines are inverted.

Routines (click to expand)
BE1A  CLKHI:  lda     VIA1_PORTB
BE1D          and     #$EF
BE1F          sta     VIA1_PORTB
BE22          rts
BE23
BE23  CLKLO:  lda     VIA1_PORTB
BE26          ora     #$10
BE28          sta     VIA1_PORTB
BE2B          rts
BE2C
BE2C  DATAHI: lda     VIA1_PORTB
BE2F          and     #$DF
BE31          sta     VIA1_PORTB
BE34          rts
BE35
BE35  DATALO: lda     VIA1_PORTB
BE38          ora     #$20
BE3A          sta     VIA1_PORTB
BE3D          rts
BE3E
BE3E  DEBPIA: lda     VIA1_PORTB
BE41          cmp     VIA1_PORTB
BE44          bne     DEBPIA
BE46          eor     #$C0          ;XXX different from C64 (lines inverted)
BE48          asl     a
BE49          rts

The IEC signals are connected to VIA1 ($F800):

Pin IEC Signal Polarity Source
VIA1 PB7 DAT_IN inverted from C64 DEBPIA $BE3E
VIA1 PB6 CLK_IN inverted from C64 DEBPIA $BE3E
VIA1 PB5 DAT_OUT same as C64 DATAHI $BE2C, DATALO $BE35
VIA1 PB4 CLK_OUT same as C64 CLKHI $BE1A, CLKLO $BE23
VIA1 PB3 ATN_OUT same as C64 SCATN $BD4C, LIST5 $BCB8

VIA1 Timer 2 is used in one-shot mode for IEC bus timing. It is not used for interrupts but is polled by the IEC bus routines (ISRCLK at $BD11, ISR04 at $BD2C, EOIACP at $BDB3, and ACP00 at $BDBB).

Testing

Run mame clcd with no drive options and the emulator will work as before. The device tree will show the IEC bus but no attached drive, since the LCD is a laptop that wouldn't normally have an external drive attached.

Run it again with -iec8 c1541. In the debugger, switch to c1541's CPU and bpset ea2d. In the drive ROM, $EA2D is the end of ACPTR, the routine that receives a byte from IEC. When sitting at the LCD's power-on menu, the breakpoint will soon be hit and the accumulator will contain $5F. This shows that the 1541 successfully received the UNLISTEN ($5F) command on IEC. The menu sends UNLISTEN periodically due to a bug in the LCD KERNAL's CLRCHN routine described below.

CLRCHN Bug (click to expand)
BAD7  ;XXX This is a bug.  This routine assumes that any device > 3 is an
BAD7  ;IEC device that needs to be UNTLKed or UNLSNed.  That was true on other
BAD7  ;machines but the LCD has two new devices, the Centronics port ($1E / 30)
BAD7  ;and the RTC ($1F / 31), that are not IEC.  When one of these devices is
BAD7  ;open, this routine will needlessly send UNLSN or UNTLK to IEC.  This can
BAD7  ;be seen at the power-on menu.  The menu continuously polls the RTC via
BAD7  ;CHRIN and calls CLALL after each poll, which comes here (CLRCHN), and an
BAD7  ;unnecessary UNTLK is sent.  To fix this, ignore devices $1E and $1F here.
BAD7  CLRCHN: ldx     #3        ;Device 3 (Screen)
BAD9
BAD9          cpx     DFLTO     ;Compare 3 to default output channel
BADC          bcs     LBAE1     ;Branch if DFLTO <= 3 (not IEC)
BADE          jsr     UNLSN     ;Device is IEC so UNLSN
BAE1
BAE1  LBAE1:  cpx     DFLTN     ;Compare 3 to default input channel
BAE4          bcs     LBAE9     ;Branch if DFLTN <= 3 (not IEC)
BAE6          jsr     UNTLK     ;Device is IEC so UNTLK
BAE9
BAE9  LBAE9:  stx     DFLTO     ;Default output device = 3 (Screen)
BAEC          stz     DFLTN     ;Default output device = 0 (Keyboard)
BAEF          rts

If the LCD menu does not come up, delete the nvram. That issue is not related to this change.

Screenshot

I took the attached screenshot after one of the times I saw it work. However, most of the time, it locks up.

screenshot

@smf- smf- merged commit 5d0a5ab into mamedev:master May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants