Skip to content

Commit

Permalink
Apple2: Don't forcefully re-enable IRQ
Browse files Browse the repository at this point in the history
Avoid enabling IRQ after disabling them in driver code, remember
previous state instead (in case user had them disabled already).
  • Loading branch information
colinleroy authored and oliverschmidt committed Dec 9, 2024
1 parent 162bc6b commit 852b622
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
19 changes: 13 additions & 6 deletions libsrc/apple2/mou/a2.stdmou.s
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ next: inc ptr1+1
; Disable interrupts now because setting the slot number makes
; the IRQ handler (maybe called due to some non-mouse IRQ) try
; calling the firmware which isn't correctly set up yet
php
sei

; Convert to and save slot number
Expand Down Expand Up @@ -211,7 +212,7 @@ next: inc ptr1+1
common: jsr firmware

; Enable interrupts and return success
cli
plp
lda #<MOUSE_ERR_OK
ldx #>MOUSE_ERR_OK
rts
Expand All @@ -220,6 +221,7 @@ common: jsr firmware
; No return code required (the driver is removed from memory on return).
UNINSTALL:
; Hide cursor
php
sei
jsr CHIDE

Expand Down Expand Up @@ -249,7 +251,8 @@ SETBOX:
; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
; "Disable interrupts before placing position information in the
; screen holes."
: sei
: php
sei

; Set low clamp
lda (ptr1),y
Expand Down Expand Up @@ -298,6 +301,7 @@ GETBOX:
; the screen). No return code required.
MOVE:
ldy slot
php
sei

; Set y
Expand Down Expand Up @@ -328,9 +332,10 @@ MOVE:
; no special action is required besides hiding the mouse cursor.
; No return code required.
HIDE:
php
sei
jsr CHIDE
cli
plp
rts

; SHOW: Is called to show the mouse cursor. The mouse kernel manages a
Expand All @@ -339,9 +344,10 @@ HIDE:
; no special action is required besides enabling the mouse cursor.
; No return code required.
SHOW:
php
sei
jsr CSHOW
cli
plp
rts

; BUTTONS: Return the button mask in A/X.
Expand All @@ -360,12 +366,13 @@ POS:
; struct pointed to by ptr1. No return code required.
INFO:
ldy #.sizeof(MOUSE_INFO)-1
copy: sei
copy: php
sei
: lda info,y
sta (ptr1),y
dey
bpl :-
cli
plp
rts

; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
Expand Down
12 changes: 7 additions & 5 deletions libsrc/apple2/ser/a2.gs.s
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,9 @@ IIgs:

ldx Channel

; Deactivate interrupts
sei
php ; Deactivate interrupts
sei ; if enabled

ldy #WR_MASTER_IRQ_RST
lda #MASTER_IRQ_SHUTDOWN
jsr writeSCCReg
Expand Down Expand Up @@ -334,7 +335,7 @@ IIgs:
ldx #$00
stx Opened ; Mark port as closed

cli
plp ; Reenable interrupts if needed
: txa ; Promote char return value
rts

Expand All @@ -352,7 +353,8 @@ getClockSource:
; Must return an SER_ERR_xx code in a/x.

SER_OPEN:
sei
php ; Deactivate interrupts
sei ; if enabled

; Check if the handshake setting is valid
ldy #SER_PARAMS::HANDSHAKE ; Handshake
Expand Down Expand Up @@ -497,9 +499,9 @@ BaudOK:
lda #SER_ERR_OK

SetupOut:
plp ; Reenable interrupts if needed
ldx #$00 ; Promote char return value
sty Opened
cli
rts

;----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions libsrc/apple2/waitvsync.s
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ iigs: bit RDVBLBAR
rts

; Apple IIc TechNote #9, Detecting VBL
iic: sei
iic: php
sei
sta IOUDISOFF
lda RDVBLMSK
bit ENVBL
Expand All @@ -40,7 +41,7 @@ iic: sei
bcs :+ ; VBL interrupts were already enabled
bit DISVBL
: sta IOUDISON ; IIc Tech Ref Man: The firmware normally leaves IOUDIS on.
cli
plp
rts

.endif ; __APPLE2ENH__

0 comments on commit 852b622

Please sign in to comment.