Skip to content

SoftIEC compatibility with C64 OS [HyperSpeed KERNAL / UCI] #985

Open

Description

@radius75

SoftIEC compatibility with C64 OS [HyperSpeed KERNAL / UCI]

Related to #975 — Hyperspeed: Should not require extra zero page addresses

Debugging and experimental fixes with ChatGPT assistance

The issue was investigated and the experimental fixes were developed with the assistance of ChatGPT. All reported results were verified through testing on real Ultimate II+ hardware.

Description

As already discussed in #975, C64 OS has compatibility issues when using HyperSpeed KERNAL with SoftIEC through UCI.

Previously, C64 OS could not complete a normal startup and would hang at "Loading App Launcher".

It was possible to work around this by starting C64 OS with JiffyDOS, creating an REU preload, and then restoring it under HyperSpeed KERNAL. With this workaround, Desktop 1 was displayed with its background and icons, but switching to Desktop 2 caused the system to hang.

I tested two changes in kernal/uci.s.

1. EOI handling in my_chrin

Adding an EOI check before attempting to read more data allowed C64 OS to boot from scratch without using an REU preload and reach Desktop 1.

However, the desktop background and icons were not displayed, and switching to Desktop 2 caused the system to hang.

2. Relocating HyperSpeed UCI variables outside Zero Page

The original uci.s source already contains commented-out definitions suggesting alternative addresses at $02BC–$02BF.

I used these suggested addresses to relocate the four UCI state variables outside Zero Page.

The four variables currently reuse existing Zero Page locations:

Variable         Original    Test
----------------------------------
MY_OUTLEN        $9B         $02BF
UCI_PENDING_CMD  $9C         $02BE
UCI_LAST_CMD     $BE         $02BD
UCI_LAST_SA      $96         $02BC

A comparison of two 64 KB memory dumps taken under JiffyDOS, one after loading Desktop 1 and the other after switching to Desktop 2, showed that the contents of $02BC–$02BF remained unchanged.

This suggests that these addresses may be available at these stages of C64 OS operation. However, this does not prove that they are unused, nor does it guarantee that C64 OS will not overwrite them later during normal operation or when running applications.

After relocating the variables, C64 OS 1.09 successfully booted from scratch under HyperSpeed KERNAL with SoftIEC/UCI enabled, without an REU preload.

Desktop 1 displayed its background and icons correctly, and switching to Desktop 2 also worked.

These results strongly suggest that reusing the existing Zero Page locations causes a compatibility conflict with C64 OS.

Experimental diff

kernal/uci.s

@@ -45,19 +45,16 @@
         NAMELEN    = $B7
         LOADADDR   = $C3
         SAVEADDR   = $C1
         SAVEEND    = $AE
 
-;        MY_OUTLEN       = $02BF ; Last byte of free area, before sprite 11
-;        UCI_PENDING_CMD = $02BE
-;        UCI_LAST_CMD    = $02BD
-;        UCI_LAST_SA     = $02BC
-
-        MY_OUTLEN       = prty
-        UCI_PENDING_CMD = dpsw
-        UCI_LAST_CMD    = fsblk
-        UCI_LAST_SA     = syno
+; Experimental relocation of HyperSpeed UCI state outside zero page.
+; WARNING: $02BC-$02BF are not confirmed free under C64 OS.
+        MY_OUTLEN       = $02BF
+        UCI_PENDING_CMD = $02BE
+        UCI_LAST_CMD    = $02BD
+        UCI_LAST_SA     = $02BC
 
 ulti_restor
             lda CMD_IF_COMMAND
             cmp #UCI_IDENTIFIER
             bne rest1
@@ -256,10 +253,19 @@ ultichrin   cmp OUR_DEVICE
             bne cin1        ;no...
             jmp bn15
 cin1        jmp bn20
 
 my_chrin
+            ; Experimental: stop after EOI, but do not treat unrelated
+            ; KERNAL status bits as end of stream.
+            lda STATUS
+            and #$40
+            beq _check_uci_data
+            lda #$0D
+            clc
+            rts
+_check_uci_data
 ; is there any data available in the current buffer?
             lda CMD_IF_CONTROL
             bpl _no_data_avail
 
             ; read available data and store it on the stack

Test environment

Notes

The addresses $02BC–$02BF were already present as commented-out alternatives in uci.s. I reused them for this experiment.

These addresses have not been confirmed safe for general use, so this should be considered a diagnostic workaround rather than a final fix.

The results suggest that both EOI handling and the location of the UCI state variables deserve further investigation.

A permanent solution should avoid conflicts with memory used by C64 software.

Activity

  1. added
    soft iec
    enhancement
    on Oct 12, 2026
  2. chrisgleissner commented on Oct 12, 2026

    @chrisgleissner
    Collaborator

    Hi @radius75 , thanks for that. Given there are vast model differences, could you please also add which concrete model and effort level you used? Currently, you must mention ChatGPT. Many thanks.

  3. added
    kernal
    uci
    on Oct 12, 2026
  4. radius75 commented on Oct 12, 2026

    @radius75
    ContributorAuthor

    Hi @chrisgleissner,
    I used ChatGPT GPT-6 in Instant mode.

  5. chrisgleissner commented on Oct 12, 2026

    @chrisgleissner
    Collaborator

    Thanks @radius75.

    BTW great work on getting C64os to start with the Hyperspeed kernal. Why don't you open a draft PR with your change and some e2e tests. It could provide further context to the discussion. I very strongly recommend Anthropic Opus 5.5 High for any such work as it is currently the best model for software engineering.

    Also, maybe you could do an impact analysis of your suggested change, ie. whether the approach you took would be viable and what potential downsides are, and whether there are any alternatives, again with pros and cons.

    @markusC64 @bvl1999 Any thoughts on this change?

  6. markusC64 commented on Oct 12, 2026

    @markusC64

    Well, those extended zero page locations are probably used in another software, so every other zer page location or extended zero page location is not a real solution. It might help C64 OS or not, there might be even a C64 OS application that uses those extended zeropage memory locations.
    Therefore I still think that having those in the IO2 area as mentioned is the better way, T guess @radius75 has done the test this way because that only needed a kernal change and not an updated FPGA for the ultimate. Right?

    For the other change, I hope @bvl1999 can comment on that.

  7. radius75 commented on Oct 12, 2026

    @radius75
    ContributorAuthor

    Attached is the compiled HyperSpeed KERNAL containing these changes.

    As mentioned earlier, this build should be considered a diagnostic workaround, not a final fix.

    u64hskernal931+.zip

  8. chrisgleissner commented on Oct 12, 2026

    @chrisgleissner
    Collaborator

    Yeah, my concern would also be incompatibility with existing applications that rely on these zero page addresses. It will be impossible to tell without an exhaustive scan of all 20k (?) C64 programs, which not sure anyone would be keen to do. My vote would also be for the IO area.

    Which area specifically did you have in mind @markusC64, and was there prior discussion on this?

    Thanks @radius75 for sharing the patched Kernal. I'd still very much prefer draft PRs with such changes as they make it much easier to see what has been changed, instead of sharing binaries. PRs also allow for easy discussion of the changes via in-line comments.

    And yeah, would be good to get @bvl1999 's opinion as he is listed as Hyperspeed Kernal expert in our CONTRIBUTING.md guide.

  9. markusC64 commented on Oct 12, 2026

    @markusC64

    Which area specifically did you have in mind @markusC64, and was there prior discussion on this?

    @radius75 has linked my proposal in the very first sentence of this issue (except the headline) - it mentions my suggestion explicitly.

  10. chrisgleissner commented on Oct 12, 2026

    @chrisgleissner
    Collaborator

    The ticket here is so similar to #975 - I fail to see any relevant difference. Why do we need two tickets @markusC64 @radius75 ? Are they not both about C64OS + Hyperspeed Kernal?

    Normally, when we start working on a ticket, we create draft PRs, not a spin-off ticket with code snippets.

  11. radius75 commented on Oct 13, 2026

    @radius75
    ContributorAuthor

    Hi Christian,

    I created a separate issue for the C64 OS compatibility problem because I didn't want to shift the focus of #975 away from the broader HyperSpeed KERNAL improvement.

    Markus himself explicitly stated in #975 that he didn't intend to debug C64 OS compatibility issues there.

    My issue actually reinforces his reasoning behind #975.

  12. markusC64 commented on Oct 13, 2026

    @markusC64

    Good question, why two issues? Well, the other ticket is about changing the firmware so the RAM is available in the IO2 Area. This ticket is about changing the hyper speed kernal, which is not part of the firmware release package. Only the sources are in the same repository.
    You see, this way, you can update the hyperspeed kernal independent from the release of the firmware. One the one hand firmware, on the other hand the kernal, that is C64 Software.

    PS: es, my mechanical keyboard is sometimes repeating something I do not want to have repeated.

  13. changed the title [-]SoftIEC compatibility with C64 OS[/-] [+]SoftIEC compatibility with C64 OS [HyperSpeed KERNAL / UCI][/+] on Oct 13, 2026
  14. chrisgleissner commented on Oct 13, 2026

    @chrisgleissner
    Collaborator

    Hi @markusC64 and @radius75, thanks for explaining. Maybe we need a build step on our CI build that automatically builds the Hyperspeed UCI kernal so people can just download and use it. It would also avoid the need to hand build it and attach it to github issues.

    By the way, which mechanical keyboard are you using @markusC64 ? I also like them a lot. I use the Keychron C3 Pro as my main retro dev keyboard. It is programmable and has adjustable lighting effects. Recently the s key got stuck so it would not actuate anymore, the reverse problem that you seem to face, but some cleaning of the key made it work again.

  15. markusC64 commented on Oct 13, 2026

    @markusC64

    Well, perhaps. It’s up to Gideon to decide what to package with the firmware.

    OT: I am using a Keychron K10 with alternative 3rd party key caps (E1 German layout, quite rare to get).

  16. chrisgleissner commented on Oct 14, 2026

    @chrisgleissner
    Collaborator

    @markusC64 We could also just offer it as an artifact that is added to each build. Does not need to be part of the firmware image. Makes it also easier to spot regressions and we can then easily add tests for it.

  17. radius75 commented on Oct 14, 2026

    @radius75
    ContributorAuthor

    I've updated the patch with several optimizations to address the performance regression introduced by the previous version.

    I tested the previous patch using several benchmarks and found that loading was approximately 10% slower than with the original HyperSpeed KERNAL.

    The latest patch includes several optimizations to eliminate this overhead. In my 100 × 4 KB SEQ read benchmark, the results are now:

    • Original HyperSpeed KERNAL 931: ~34.46 seconds
    • Previous patch: ~37.78 seconds
    • Latest optimized patch: ~34.43 seconds

    So the performance is now practically identical to the original.

    I also tested the latest version with Image BBS 3.0, C64 OS, Sonic, and BattleTech. All tests passed, but of course this does not guarantee that I haven't introduced any regressions.

    Another difficulty is testing compatibility with different software when the four UCI state variables may conflict with memory used by an application. To investigate such conflicts, I would need to compile and maintain several HyperSpeed KERNAL variants with these variables placed at different memory locations, which is rather inconvenient.

    Regarding Christian's suggestion to provide the HyperSpeed KERNAL as a CI build artifact: I think this would be very useful, especially for testing and identifying regressions. It would make comparing different builds much easier without having to compile each variant manually.

    u64hskernal931+++.zip

    I've committed the latest version.
    radius75@2e3ee00

    @@ -45,19 +45,19 @@
             NAMELEN    = $B7
             LOADADDR   = $C3
             SAVEADDR   = $C1
             SAVEEND    = $AE
     
    -;        MY_OUTLEN       = $02BF ; Last byte of free area, before sprite 11
    -;        UCI_PENDING_CMD = $02BE
    -;        UCI_LAST_CMD    = $02BD
    -;        UCI_LAST_SA     = $02BC
    +        MY_OUTLEN       = $02BF ; Last byte of free area, before sprite 11
    +        UCI_PENDING_CMD = $02BE
    +        UCI_LAST_CMD    = $02BD
    +        UCI_LAST_SA     = $02BC
     
    -        MY_OUTLEN       = prty
    -        UCI_PENDING_CMD = dpsw
    -        UCI_LAST_CMD    = fsblk
    -        UCI_LAST_SA     = syno
    +;        MY_OUTLEN       = prty
    +;        UCI_PENDING_CMD = dpsw
    +;        UCI_LAST_CMD    = fsblk
    +;        UCI_LAST_SA     = syno
     
     ulti_restor
                 lda CMD_IF_COMMAND
                 cmp #UCI_IDENTIFIER
                 bne rest1
    @@ -285,20 +285,34 @@ _ok         pla
                 clc
                 rts ; done!!
     
     
     _no_data_avail
    +            ; Check EOI only when UCI has no data available.
    +            bit STATUS
    +            bvs _chrin_eoi
    +
    +            ; BIT changes flags, but preserves A.
                 ; Current buffer is empty. Are we in the MORE data state?
                 and #CMD_STATE_BITS
                 cmp #CMD_STATE_MORE_DATA
                 bne _read_error
     
                 ; Get next block of data
    -            jsr uci_ack
    +            lda #CMD_NEXT_DATA
    +            sta CMD_IF_CONTROL
    +_chrin_ack  lda CMD_IF_CONTROL
    +            and #CMD_NEXT_DATA
    +            bne _chrin_ack
                 jsr uci_wait_busy
                 jmp my_chrin
     
    +_chrin_eoi
    +            lda #$0D
    +            clc
    +            rts
    +
     _read_error
                 ; No data could be read. We return $0D, and set EOF + Read Error
                 lda #$42
                 ora STATUS
                 sta STATUS
  18. radius75 commented on Oct 19, 2026

    @radius75
    ContributorAuthor

    I found another HSKernal compatibility issue while testing C64 OS Gallery.

    With HSK, loading a nonexistent INIT.O repeatedly fails instead of continuing to MAIN.O:

    SoftIEC: open failed ... txt="INIT.O" -> 62,FILE NOT FOUND
    SoftIEC: open failed ... txt="INIT.O" -> 62,FILE NOT FOUND
    SoftIEC: open failed ... txt="INIT.O" -> 62,FILE NOT FOUND
    ...
    

    The problem is that HSK returns A=4, Carry=1, ST=0 on a failed KERNAL LOAD, while the original CBM KERNAL and JiffyDOS return A=4, Carry=1, ST=66.

    The fix in kernal/uci.s is:

    @@ -109,10 +109,13 @@ ld3         ldx SECADDR
                 jsr uci_setup_range
                 jsr uci_filename ; also executes
                 lda CMD_IF_STATUS
                 jsr uci_ack ; restores A
                 beq ld4 ; all OK when zero
    +            lda STATUS
    +            ora #$42 ; preserve status flags
    +            sta STATUS
                 jmp error4
     
     ld4         jsr loding ; print LOADING
     
                 ldx #UCI_CMD_LOADEX

    After the fix, Gallery correctly continues from the missing INIT.O to MAIN.O.

    u64hskernal931v3.zip

    Using the latest patched u64hskernal931v3, I successfully performed a clean installation of C64 OS 1.08 on a DNP partition
    and upgraded it to version 1.09 without encountering any issues.

  19. radius75 commented on Oct 21, 2026

    @radius75
    ContributorAuthor

    During further HyperSpeed KERNAL compatibility testing, I found several differences in the returned register values compared with the standard Commodore KERNAL and JiffyDOS.

    I have not determined whether these differences affect C64 OS functionality. They are simply compatibility discrepancies discovered during testing.

    The following results were recorded before the latest HSK fixes.

    Format: A / X / Y / Carry / ST

    Test CBM + SoftIEC (11) JiffyDOS + SoftIEC (11) CBM + 1541-II (8) HSK 931v3 + SoftIEC (11)
    3. OPEN — missing SEQ file 199/0/26/0/0 199/0/26/0/0 199/0/26/0/0 243/19/26/0/0
    6. CHRIN — invalid filename 13/11/26/0/66 13/11/26/0/66 13/8/26/0/66 13/21/5/0/66
    6. CHRIN — valid file 65/11/13/0/0 65/11/13/0/0 65/8/13/0/0 65/21/13/0/0

    One difference was the X register returned by the UCI implementation of CHKIN. HSK returned 21 ($15, the UCI CHKIN command code) instead of the device number.

    In HSK 931v4, I changed the CHKIN return path to restore X from DFLTN, preserving the processor flags:

    @@ -403,11 +403,14 @@ _my_chkin   sta dfltn
                 cmp #CMD_STATE_MORE_DATA
                 beq _chkin_cont ; another buffer follows
     
     _chkin_su   jsr uci_setup_cmd
                 jsr uci_execute
    -_chkin_cont clc
    +_chkin_cont php
    +            ldx dfltn
    +            plp
    +            clc
                 rts
     
     ; $FFC9   
     ; CHKOUT. Define file as default output. (Must call OPEN beforehand.)
     ; Input: X = Logical number.

    u64hskernal931v4.zip

    HSK 931v4 test results:

    • CHKIN returns X=11 for SoftIEC device 11.
    • LOAD of a nonexistent file returns ST=66.
    • C64 OS Gallery — PASS.
    • Sonic loading into REU from /Temp — PASS.
    • No confirmed loading-speed regression compared with v3.

    The remaining differences in OPEN and CHRIN register values have not yet been investigated further.

  20. radius75 commented on Oct 21, 2026

    @radius75
    ContributorAuthor

    Hi @chrisgleissner

    While testing HSKERNAL compatibility with C64OS, I noticed a possible inconsistency in the JiffyDOS/SoftIEC implementation.

    The test opens a non-existing SEQ file, performs CHKIN followed by CHRIN, and records the returned A/X/Y registers, Carry, ST, and processor status register P.

    I initially noticed that JiffyDOS 6.01 with SoftIEC returns A=$47 instead of A=$C7, even though both configurations report ST=66.

    Diagnostic program repeats the OPEN → CHKIN → CHRIN sequence 20 times.

    Results on Ultimate II+

    Configuration Device A X Y Carry ST P
    CBM KERNAL + SoftIEC 11 199 ($C7) 11 26 0 66 176 ($B0)
    JiffyDOS 6.01 + Drive A (1541-II, JiffyDOS ROM) 8 199 ($C7) 8 26 0 66 176 ($B0)
    JiffyDOS 6.01 + SoftIEC 11 71 ($47) 11 26 0 66 112 ($70)

    All results were consistent across 20 out of 20 runs for each configuration.

    UCI was disabled, so communication with SoftIEC went through the physical IEC bus.

    So far, only the JiffyDOS 6.01 + SoftIEC combination produces A=$47 instead of $C7.

    Additional observations

    • OPEN and CHKIN returned Carry=0 and ST=0 in all configurations.
    • ST=66 appeared only after CHRIN.
    • A=$C7 and A=$47 differ only in bit 7.
    • P=$B0 and P=$70 differ in both the Negative (N) and Overflow (V) flags.
    • Memory location $A4 remained unchanged during CHRIN: 0→0 for CBM + SoftIEC and JiffyDOS + Drive A, but 255→255 for JiffyDOS + SoftIEC.

    I also ran the same test program in VICE with both the standard CBM KERNAL and JiffyDOS 6.01, using an emulated 1541-II.

    Both configurations produced identical results, matching those obtained with Ultimate Drive A: A=$C7, Carry=0 and ST=66.

    Possible cause

    Looking at the SoftIEC source, I noticed that IecChannel::prefetch_data() returns IEC_NO_FILE when the channel is in an error state.

    In iec_interface.cc, this leads to IEC_CMD_TX_TERM, terminating the transmission without supplying another data byte.

    I wonder whether the JiffyDOS transfer termination or error handling in SoftIEC differs slightly from the behavior of an emulated 1541-II.

    I'm not claiming this is necessarily a functional bug, since ST=66 is reported correctly and the accumulator and processor flags may not be defined after an unsuccessful CHRIN.

    However, the difference is fully reproducible and appears specific to the JiffyDOS + SoftIEC combination.

    Do you think this is worth investigating?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementkernalsoft iecuci

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions