Repository navigation
firmware: a C128-mode launch drops Kernal Replace as the next IO handler - #98
Merged
SensoriumEmbedded merged 1 commit intoNov 11, 2026
Conversation
In 128 mode the MMU ignores GAME and EXROM, so the internal KERNAL stays mapped at $E000-$FFFF. If a C64-mode launch earlier in the session loaded a kernal, InitHndlr_KernalReplace re-stages KernalCheck when the C128 boot ROM signals rCtlRunningPRG, and the Teensy then drives KernalBin onto the bus against the C128's own ROM on every KERNAL read, and asserts DMA for the HIRAM sense on $00/$01 accesses. LaunchC128BasicPrg now overrides the Special IO setting for that launch only, the way a CRT does; InitHndlr_TeensyROM restores it from EEPROM on the next return to the menu. Reported by Wes Biggs on SensoriumEmbedded#96.
kfox
force-pushed
the
fix/c128-skip-c64-handlers
branch
from
November 11, 2026 04:01
2493f60 to
d3047fe
Compare
kfox
marked this pull request as ready for review
November 11, 2026 04:32
SensoriumEmbedded
left a comment
Owner
There was a problem hiding this comment.
Thank you for the quick fix, and for the tests that pin it down! :) And thank you @wesbiggs for catching this one on #96, a great find that could have caused C128 bus contention.
I reviewed this merged onto current main (d1a7ab7) and built both targets. There's nothing I'd like you to change before merging.
Memory: TR+ flash code grows 16 bytes, and nothing else changes on either target. The plain TR image is identical, since the change is TR+ only.
Hardware tested
NTSC C128, TR+ main image built from this branch, Special IO = Kernal Replace with a JiffyDOS kernal:
- A C64 PRG loads the kernal and selects Kernal Replace (JiffyDOS banner)
- A C128 BASIC PRG launched next, with that kernal still loaded, selects no IO handler and runs in 128 mode
- Exit to C128 BASIC selects no IO handler and comes up in empty BASIC 7.0
- A C64 PRG launched after that gets Kernal Replace again
- A C128 cartridge launched with that kernal loaded runs, and Kernal Replace doesn't arm: the C128 boots on its own kernal
Hardware testing: Just to document. I'll hit these at some point, not a request or requirement! :)
- PAL C128
Thank you!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On a TR+, a C128 BASIC program launched in 128 mode no longer gets Kernal Replace as its IO handler. This fixes the case @wesbiggs raised on #96.
The problem
If Special IO is set to Kernal Replace and a C64-mode launch earlier in the session loaded a kernal,
KernalBinis still allocated. When the C128 boot ROM writesrCtlRunningPRG,fBusSnoopisHandshakeSnoop, soInitHndlr_KernalReplace()stagesKernalCheckArm(). In 128 mode the MMU ignores GAME and EXROM, so the internal KERNAL stays mapped at$E000-$FFFF.KernalCheckthen drivesKernalBinonto the data bus against the C128's own ROM on every read there, including the MMU registers at$FF00. With the DMA HIRAM sense, which Auto picks on a C128, it also asserts DMA on$00/$01accesses.The fix
LaunchC128BasicPrg()replaces Kernal Replace withIOH_Noneas the next IO handler, for that launch only. A CRT overridesrwRegNextIOHndlrthe same way, andInitHndlr_TeensyROM()restores the setting from EEPROM on the next return to the menu. The override comes after both refusal checks, so a refused launch leaves the setting alone. It covers the program launch and Exit to C128 BASIC.Kernal Replace is the only handler this applies to. TR BASIC is C64-only too, but every menu item associated with it loads at
$0801, so none of them takes the C128 path. Handlers that work in 128 mode, such as Swiftlink, MIDI and REU, are left alone. Kernal Replace exists only on the TR+ (Fab04_KernalReplace), so the plain TR compiles none of this.Verification
npm test: 366 pass on macOS. Under Linux GCC (node:24, linux/amd64): 324 pass and 8 skip, whereacmeisn't installed. The new tests inSource/Teensy/tests/c128-prg.test.jscover a program launch and Exit to C128 BASIC, which drop Kernal Replace; Swiftlink, which is kept; and a refused launch on a C64 or for an oversized program, which keeps Kernal Replace. They fail with the override removed, and with it moved afterIOHandlerSelectInit().build:tr-plusandbuild:tr(Docker linux/amd64, Teensyduino 1.61.0).Kernal replace Enabled, DMA sense), then a C128 BASIC PRG.Loading IO handler: Kernal Replace. The program still ran, and a checksum of$E000-$FEFFin BANK 15 matched this branch, so this run showed no contention on CPU reads. Most likely the DMA sense judged HIRAM as RAM. The handler was armed all the same.Loading IO handler: None, the program runs, and the checksum is the same. Exit to C128 BASIC selectsNoneand starts 128 mode. A C64 PRG launched afterwards loads the kernal and selects Kernal Replace again.Memory
Main image, base d1a7ab7 vs this branch, same build configuration:
MinimalBoot and the extension image are unchanged.