ytmytm / c64-lng

LUnix Next Generation - a Little Unix operating system for C64/128/Atari and any 6502-based machine
http://lng.sourceforge.net/
GNU General Public License v2.0
68 stars 6 forks source link

IEC protocol violation: LNG sends UNLISTEN instead of UNTALK in file read operations #3

Closed tmcintos closed 1 year ago

tmcintos commented 1 year ago

Playing around with LNG in my own C64/1541 emulator, I noticed that LNG sends UNLISTEN when it should send UNTALK, e.g. in sequences like this:

(TALK 8) (SECOND 9) (UNLISTEN)

Looking at the code in this repository, it seems there is a bug here:

https://github.com/ytmytm/c64-lng/blob/c1fb00d2ab26ceb1c513ab3852e66b7698dd712d/kernel/opt/iec_1541.s#L141

.byte $2c and the following two bytes (lda #0) constitute a BIT instruction which is meant to skip the following lda #$3f instruction in case of UNTALK ($3F is the UNLISTEN command):

send_untalk_iec:
        sei
        jsr  CLOCK_hi
        jsr  ATN_hi
        lda  #$5f
        .byte $2c

send_unlisten_iec:
        lda  #0
        sta  ch_state
        lda  #$3f
        pha

It seems that a possible fix may be to swap these lines around so that the .byte $2c skips the lda #$3f instruction as expected:

send_unlisten_iec:
        lda  #$3f
        pha
        lda  #0
        sta  ch_state

I presume the existing code works as-is with a real 1541, but it turned out that my emulator was sensitive to this protocol violation.

ytmytm commented 1 year ago

I applied your fix. Awesome that you found it. Thanks!