]> git.sur5r.net Git - cc65/blob - libsrc/c128/mouseref.s
Removed a "cc65_" prefix.
[cc65] / libsrc / c128 / mouseref.s
1 ;
2 ; Pointer for library references by device drivers.
3 ;
4 ; Helper-routines for the interrupt handler that rejects bogus keypresses
5 ; that are caused by mouse-like devices.
6 ;
7 ; 2013-07-25, Greg King
8 ; 2014-04-26, Christian Groessler
9 ;
10
11         .include        "c128.inc"
12
13         .export         mouse_libref, _pen_adjuster
14
15         .data
16
17 mouse_libref:                   ; generic label for mouse-kernel
18
19 ; A program optionally can set this pointer to a function that gives
20 ; a calibration value to a driver.  If this pointer isn't NULL,
21 ; then a driver that wants a value can call that function.
22 ;
23 ; The function might read a value from a file; or, it might ask the user
24 ; to help calibrate the driver.
25 ;
26 ; void __fastcall__ (*pen_adjuster)(unsigned char *) = NULL;
27 ;
28 _pen_adjuster:
29         .addr   $0000
30
31         .addr   IRQStub2
32 callback:                       ; callback into mouse driver after ROM IRQ handler has been run
33         .addr   $0000           ; (filled in by mouse driver)
34 jmp_rom_hdlr:                   ; original ROM indirect IRQ handler address
35         .addr   $0000           ; (filled in by mouse driver)
36
37
38 .segment        "LOWCODE"
39
40 ; Called from irq.s when it thinks it chains to the original handler.
41 ; ROM is banked in again. In order to call the callback we have to
42 ; bank it out one more time.
43
44 IRQStub2:
45
46 ; Call ROM handler and prepare stack so that it will return to us.
47
48         ; setup fake IRQ stack frame which will return to "IRQCont"
49         lda     #>@IRQCont
50         pha
51         lda     #<@IRQCont
52         pha
53         php
54
55         ; mimic the contents saved on the stack by the ROM IRQ entry handler
56         pha                     ; A
57         pha                     ; X
58         pha                     ; Y
59         lda     #MMU_CFG_CC65   ; MMU configuration which will be active after the ROM handler returns
60         pha
61
62         ; map out ROM
63         ldy     MMU_CR
64         sta     MMU_CR
65
66         ; push address of ROM handler on stack and jump to it
67         lda     jmp_rom_hdlr+1
68         pha
69         lda     jmp_rom_hdlr
70         pha
71
72         sty     MMU_CR          ; map in ROM
73         rts                     ; jump to ROM handler
74
75         ; our MMU configuration byte we pushed on the stack before (MMU_CFG_CC65) is now active
76
77 @IRQCont:
78
79         ; call mouse driver callback routine
80         lda     #>(@IRQCont2-1)
81         pha
82         lda     #<(@IRQCont2-1)
83         pha
84         lda     callback+1
85         pha
86         lda     callback
87         pha
88         rts                     ; jump to callback routine
89
90 @IRQCont2:
91
92         ; return from interrupt
93         ; We could just jump to $FF33, but since I don't know whether this address is valid in all
94         ; ROM versions, duplicate that code here.
95
96         pla
97         sta     MMU_CR          ; MMU configuration register
98         pla
99         tay
100         pla
101         tax
102         pla
103         rti