From 7c2671be2a8c365f4254abec8682928ff72651de Mon Sep 17 00:00:00 2001
From: Oliver Schmidt
Date: Wed, 12 Mar 2025 21:33:13 +0100
Subject: [PATCH] Disable interrupts during aux memory access.
Interrupt handlers rather likely access text screen holes. Especially MSLOT is obligatory for every interrupt handler that requires access to an extension ROM ($C800-$CFFE) in order to be able to re-enable the extension ROM that was enabled when the interrupt occured. Those text screen holes only hold valid values in main memory so interrupts must be disabled while the aux memory text screen is mapped.
---
libsrc/apple2/cgetc.s | 5 +++--
libsrc/apple2/cpeekc.s | 11 ++++++++---
libsrc/apple2/cputc.s | 16 +++++++++++-----
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/libsrc/apple2/cgetc.s b/libsrc/apple2/cgetc.s
index ecce9f9de..d2ebe5db8 100644
--- a/libsrc/apple2/cgetc.s
+++ b/libsrc/apple2/cgetc.s
@@ -9,6 +9,7 @@
.export _cgetc
.import cursor, putchardirect
+ .include "zeropage.inc"
.include "apple2.inc"
_cgetc:
@@ -22,7 +23,7 @@ _cgetc:
.else
lda #' ' | $40 ; Blank, flashing
.endif
- jsr putchardirect ; Returns old character in X
+ jsr putchardirect ; Saves old character in tmp3
; Wait for keyboard strobe.
: inc RNDL ; Increment random counter low
@@ -37,7 +38,7 @@ _cgetc:
; Restore old character.
pha
- txa
+ lda tmp3
jsr putchardirect
pla
diff --git a/libsrc/apple2/cpeekc.s b/libsrc/apple2/cpeekc.s
index a547f7867..200206177 100644
--- a/libsrc/apple2/cpeekc.s
+++ b/libsrc/apple2/cpeekc.s
@@ -11,18 +11,23 @@
_cpeekc:
ldy CH
.ifdef __APPLE2ENH__
+ sec ; Assume main memory
bit RD80VID ; In 80 column mode?
bpl peek ; No, just go ahead
tya
lsr ; Div by 2
tay
bcs peek ; Odd cols are in main memory
+ php
+ sei ; No valid MSLOT et al. in aux memory
bit HISCR ; Assume SET80COL
.endif
peek: lda (BASL),Y ; Get character
.ifdef __APPLE2ENH__
- bit LOWSCR ; Doesn't hurt in 40 column mode
- .endif
+ bcs :+ ; In main memory
+ bit LOWSCR
+ plp
+: .endif
eor #$80 ; Invert high bit
- ldx #$00
+ ldx #>$0000
rts
diff --git a/libsrc/apple2/cputc.s b/libsrc/apple2/cputc.s
index 0a27abacd..2dcfa1e00 100644
--- a/libsrc/apple2/cputc.s
+++ b/libsrc/apple2/cputc.s
@@ -15,6 +15,7 @@
.import uppercasemask
.endif
+ .include "zeropage.inc"
.include "apple2.inc"
.macpack cpu
@@ -87,23 +88,28 @@ putchar:
mask: and INVFLG ; Apply normal, inverse, flash
putchardirect:
- pha
+ tax
.ifdef __APPLE2ENH__
lda CH
+ sec ; Assume main memory
bit RD80VID ; In 80 column mode?
bpl put ; No, just go ahead
lsr ; Div by 2
bcs put ; Odd cols go in main memory
+ php
+ sei ; No valid MSLOT et al. in aux memory
bit HISCR ; Assume SET80COL
put: tay
.else
ldy CH
.endif
lda (BASL),Y ; Get current character
- tax ; Return old character for _cgetc
- pla
+ sta tmp3 ; Save old character for _cgetc
+ txa
sta (BASL),Y
.ifdef __APPLE2ENH__
- bit LOWSCR ; Doesn't hurt in 40 column mode
- .endif
+ bcs :+ ; In main memory
+ bit LOWSCR
+ plp
+: .endif
rts