.macpack generic
+IRQInd = $2FD
+
; ------------------------------------------------------------------------
; Header. Includes jump table
; Library reference
+libref:
.addr $0000
; Jump table
SCREEN_HEIGHT = 200
SCREEN_WIDTH = 320
+;----------------------------------------------------------------------------
+; data segment
+
+.data
+
+chainIRQ:
+ .byte $4c ; JMP opcode
+ .word 0 ; pointer to ROM IRQ handler (will be set at runtime)
+
;----------------------------------------------------------------------------
; Global variables. The bounding box values are sorted so that they can be
; written with the least effort in the SETBOX and GETBOX routines, so don't
NewValue: .res 1 ; Temp for MoveCheck routine
INIT_save: .res 1
+Buttons: .res 1 ; Button mask
+
+; Keyboard buffer fill level at start of interrupt
+
+old_key_count: .res 1
.rodata
lda YPos
ldx YPos+1
jsr CMOVEY
+
+; Initialize our IRQ magic
+
+ lda IRQInd+1
+ sta chainIRQ+1
+ lda IRQInd+2
+ sta chainIRQ+2
+ lda libref
+ sta ptr3
+ lda libref+1
+ sta ptr3+1
+ ldy #2
+ lda (ptr3),y
+ sta IRQInd+1
+ iny
+ lda (ptr3),y
+ sta IRQInd+2
+ iny
+ lda #<(callback-1)
+ sta (ptr3),y
+ iny
+ lda #>(callback-1)
+ sta (ptr3),y
+ iny
+ lda #<(chainIRQ-1)
+ sta (ptr3),y
+ iny
+ lda #>(chainIRQ-1)
+ sta (ptr3),y
cli
; Done, return zero (= MOUSE_ERR_OK)
; No return code required (the driver is removed from memory on return).
UNINSTALL:
+ lda chainIRQ+1
+ sei
+ sta IRQInd+1
+ lda chainIRQ+2
+ sta IRQInd+2
+ cli
+
jsr HIDE ; Hide cursor on exit
lda INIT_save
sta INIT_STATUS
; BUTTONS: Return the button mask in a/x.
BUTTONS:
- lda #$7F
- sei
- sta CIA1_PRA
- lda CIA1_PRB ; Read joystick #0
- cli
- ldx #0
- and #$1F
- eor #$1F
+ lda Buttons
+ ldx #$00
rts
;----------------------------------------------------------------------------
;
IRQ: jsr CPREP
+ lda KEY_COUNT
+ sta old_key_count
+ lda #$7F
+ sta CIA1_PRA
+ lda CIA1_PRB ; Read joystick #0
+ and #$1F
+ eor #$1F ; Make all bits active high
+ sta Buttons
+
lda SID_ADConv1 ; Get mouse X movement
ldy OldPotX
jsr MoveCheck ; Calculate movement vector
clc
rts
+.define OLD_BUTTONS Buttons ; tells callback.inc where the old port status is stored
+.include "callback.inc"
clc ; Interrupt not "handled"
rts
-;----------------------------------------------------------------------------
-; Called after ROM IRQ handler has been run.
-; Check if there was joystick activity before and/or after the ROM handler.
-; If there was activity, discard the key presses since they are most
-; probably "phantom" key presses.
-
-callback:
- ldx old_key_count
- cpx KEY_COUNT
- beq @nokey
-
- lda Temp ; keypress before?
- bne @discard_key ; yes, discard key
-
- lda #$7F
- sta CIA1_PRA
- lda CIA1_PRB ; Read joystick #0
- and #$1F
- eor #$1F ; keypress after
- beq @nokey ; no, probably a real key press
-
-@discard_key:
- stx KEY_COUNT ; set old keyboard buffer fill level
-
-@nokey: rts
+.define OLD_BUTTONS Temp ; tells callback.inc where the old port status is stored
+.include "callback.inc"
--- /dev/null
+;
+; Callback routine called from the IRQ handler after the ROM IRQ handler
+; had been run.
+;
+; Christian Groessler, 24.04.2014
+;
+; Check if there was joystick activity before and/or after the ROM handler.
+; If there was activity, discard the key presses since they are most
+; probably "phantom" key presses.
+
+callback:
+ ldx old_key_count
+ cpx KEY_COUNT
+ beq @nokey
+
+ lda OLD_BUTTONS ; keypress before?
+ bne @discard_key ; yes, discard key
+
+ lda #$7F
+ sta CIA1_PRA
+ lda CIA1_PRB ; Read joystick #0
+ and #$1F
+ eor #$1F ; keypress after
+ beq @nokey ; no, probably a real key press
+
+@discard_key:
+ stx KEY_COUNT ; set old keyboard buffer fill level
+
+@nokey: rts