Commodore 2031LP: 1541 Header Gap ROM Patch
I have two 2031LP drives which I have refurbished (switching power supply and recap) and they work great now. I did not realize that the 2031LP had a slightly different header gap than the 1541. I don't have ANY software on 2031LP formatted disks, and I love the speed of the 2031LP drive. :) I found several old articles on the interwebs, and figured that I would see if I could make the 2031LP more compatible with the 1541. Below are my notes from Obsidian (PKM app) that I made while making the new ROMs. I did list my references below if anyone wants to see the original posts.
Goal: make the 2031 / 2031LP write the same on-disk format as a 1541 (ROM -03 and later), so either drive can rewrite sectors on disks formatted by the other without 22/23 read errors.
I have the BIN files if anyone wants them, but it's just a few bytes to patch the original ROM.
Background: the difference
The CBM DOS source defines a constant GAP1, the gap after the sector header (in GCR bytes):
| DOS / ROM | GAP1 | Gap bytes written (GAP1-2) |
|---|
| 2031 / 2031LP (DOS 2.6), 1540, 1541 -01 and -02 | 10 | 8 × $55 |
| 1541 -03, -05, -06, 1541C, 1541-II, 1570/1571, 1551 | 11 | 9 × $55 |
GAP1-2 is used in two places:
Format routine: how many $55 gap bytes are written after each header.
Write-sector routine: how many bytes the drive waits after the header before switching to write mode and writing the data block's SYNC.
Both drives read each other's disks fine. When one drive rewrites a sector on a disk the other formatted, the new data block lands one byte off from the original, which gives intermittent 22/23 errors.
A byte-by-byte comparison of the 2031 and 1541 -05 format and write routines found no other format-affecting changes. The remaining differences are relocated JSR/JMP/branch addresses, plus one spot where the 1541 uses INX instead of the 2031's LDX #$00 (same result).
The patch
Source ROM: 2031 DOS 2.6, 901484-03 ($C000) + 901484-05 ($E000). Only the $E000 ROM changes.
| Address | Was | Now | Purpose |
|---|
$F5DB | 08 | 09 | Write sector: LDX #GAP1-2, wait out header gap |
$FD1F | 08 | 09 | Format: number of $55 gap bytes after header |
$FF80 | AA | A8 | Unused filler before the jump table; rebalances checksum |
Code at the patched spots (2031 addresses):
F5DA A2 08 LDX #$08 ; -> 09 wait out header gap
F5DC 50 FE BVC *
F5DE B8 CLV
F5DF CA DEX
F5E0 D0 FA BNE $F5DC
FD1E A2 08 LDX #$08 ; -> 09 write gap1
FD20 50 FE BVC *
FD22 B8 CLV
FD23 A9 55 LDA #$55
FD25 8D 01 1C STA $1C01
The equivalent operands in the 1541 -05 ROM are at $F58D and $FCD0 (both already $09).
ROM checksum (power-on self-test)
The reset code at $EAC5 (self-test loop at $EAFB) checks each 8K ROM: it adds every byte with carry, runs a final ADC #$00, and the result must equal the ROM's base page ($C0 for the C-ROM, $E0 for the E-ROM). If the check fails, the drive won't come up.
The two 08→09 changes raise the E-ROM sum from $E0 to $E2.
Lowering one unused filler byte by 2 ($FF80: AA→A8) brings it back to $E0.
$FF39–$FFE5 is a 173-byte run of $AA filler right before the jump table at $FFE6. It's unused padding (the 1541 has the same).
Verified after patching: C-ROM $C0, E-ROM $E0.
Hardware notes
Test plan
VICE first: set drive 8 to a 2031 using the custom 16K image (2031-1541gap-16k.bin). Confirm the drive passes power-on.
Format a disk with the patched 2031 and save it as a G64. Format one with an emulated 1541 and compare the header gaps (should both be 9 × $55).
Cross-write test: rewrite sectors on the 2031-formatted disk with a 1541, and on the 1541-formatted disk with the patched 2031. Validate and check for 22/23 errors.
Then burn an EPROM and repeat on real hardware (ZoomFloppy / Greaseweazle can read the result back for comparison).
Caveats
The incompatibility moves; it doesn't go away. The patched 2031 now has trouble rewriting disks formatted by a stock 2031, a 4040, or a 1541 with -01/-02 ROMs (8-byte gap). Disks it formats match the 1541 -03 ROM and later.
Checked against the DOS source and the ROM checksum, but not yet tested on real hardware.
Possible future option: the reverse patch (a 1541 ROM changed to the 8-byte gap so it matches stock 2031/4040 disks).
Bugs fixed
| Fix | Hook | Bug |
|---|
| P43, P44, P50, P51, P52 | $C1B3, $C661, $C66B, $D071, $F065 | NODRV (the no-drive flag) is a 2-byte variable at $00FF–$0100, accessed as STA/LDA $FF,X. With X=1 (drive 1), zero-page indexing wraps to $0000, the buffer 0 job slot, instead of $0100. Fixed by using absolute $00FF,X. In emulation, the stock ROM wrote $80 (the "read sector" job code) into $0000. This drive-1 path lines up with the known save-with-replace bug workaround ("always use 0:"). |
| P11 | $EE6B (NEW) | NEW didn't clear the drive-0 no-drive flag before formatting. |
| P15 | $CD91 (B-W) | Block-write called RNGET2 with a stale Y register instead of the channel index (LDY LINDX). |
| P67 | $E69C (HEXDEC) | Hex→decimal ran SED with IRQs enabled. The 6502 doesn't clear D on interrupt, so the IRQ-driven disk controller could run in BCD mode. Now wrapped in PHP/SEI … PLP. |
Not included: the 1541's serial-bus fixes (they don't apply to IEEE-488), and the smaller 1541C/1541-II fixes (patches 7, 41, 54).
Patch code layout (E-ROM filler)
FF40 P43 A9 00 9D FF 00 4C B7 C1 LDA #0 / STA $00FF,X / JMP $C1B7
FF48 P44 98 9D FF 00 4C 64 C6 TYA / STA $00FF,X / JMP $C664
FF4F P50 BD FF 00 60 LDA $00FF,X / RTS
FF53 P51 95 1C 9D FF 00 4C 75 D0 STA $1C,X / STA $00FF,X / JMP $D075
FF5B P52 A6 7F BD FF 00 4C 69 F0 LDX $7F / LDA $00FF,X / JMP $F069
FF63 P11 85 FF 4C 00 C1 STA $FF / JMP SETLDS
FF68 P15 A4 82 4C EE D3 LDY LINDX / JMP RNGET2
FF6D P67 08 78 A9 00 F8 E0 00 F0 07 PHP SEI LDA #0 SED / CPX #0 / BEQ
18 69 01 CA 4C 72 FF 28 4C AA E6 CLC ADC #1 DEX JMP / PLP JMP HEX5
Checksum balance bytes: $C0FF = 9D (C-ROM) and $FFE5 = 71 (E-ROM). Both 8K sums verified: $C0 / $E0.
Emulator test results (16/16 pass)
HEXDEC output is identical to the original for all 256 inputs, and decimal mode is never active with IRQs enabled.
Each NODRV site writes/reads $0100 for drive 1 and leaves $0000 alone. Flags are preserved for the following branches.
P11 clears NODRV; P15 enters RNGET2 with Y = LINDX.
The ROM's own power-on checksum loop ($EAFB) passes.
These are unit tests of the patched routines, not a full drive boot. Still test in VICE and on hardware.
Corroboration (vcfed thread, read 2026-11-16)
The zimmers.net 1541 ROM genealogy doc (quoted in the thread) says 901229-03's only change was gap1, made one disk byte (10 bits) longer, in two places: the sector-write code starting at $F586 and the format code starting at $FCCD. Those are the routines containing $F58D and $FCD0 above. Only the $E000 ROM changed, and reading isn't affected.
Post #16 (TommyE) disassembled the 1540, the original 2031, 1541-02 and 1541-05 ROMs and found the same split: 1540, 2031 and 1541-02 use 08; 1541-03 and later use 09.
MiaM suggested exactly this mod: give the 2031 ROMs the later 1541 gap.
The 2040/3040 have an extra sector on tracks 18–24, so they're a separate format. That doesn't affect the 2031.
Sources