]> git.sur5r.net Git - cc65/blob - libsrc/c128/irq.s
Removed a "cc65_" prefix.
[cc65] / libsrc / c128 / irq.s
1 ;
2 ; IRQ handling (C128 version)
3 ;
4
5         .export         initirq, doneirq
6         .import         callirq
7
8         .include        "c128.inc"
9
10 ; ------------------------------------------------------------------------
11
12 .segment        "ONCE"
13
14 initirq:
15         lda     IRQVec
16         ldx     IRQVec+1
17         sta     IRQInd+1
18         stx     IRQInd+2
19         lda     #<IRQStub
20         ldx     #>IRQStub
21         jmp     setvec
22
23 ; ------------------------------------------------------------------------
24
25 .code
26
27 doneirq:
28         lda     IRQInd+1
29         ldx     IRQInd+2
30 setvec: sei
31         sta     IRQVec
32         stx     IRQVec+1
33         cli
34         rts
35
36 ; ------------------------------------------------------------------------
37 ; The C128 has ROM parallel to the RAM starting from $4000. The startup code
38 ; above will change this setting so that we have RAM from $0000-$BFFF. This
39 ; works quite well with the exception of interrupts: The interrupt handler
40 ; is in ROM, and the ROM switches back to the ROM configuration, which means
41 ; that parts of our program may not be accessible. To solve this, we place
42 ; the following code into a special segment called "LOWCODE" which will be
43 ; placed just above the startup code, so it goes into a RAM area that is
44 ; not banked.
45
46 .segment        "LOWCODE"
47
48 IRQStub:
49         cld                             ; Just to be sure
50         lda     MMU_CR                  ; Get old register value
51         pha                             ; And save on stack
52         lda     #MMU_CFG_CC65           ; Bank 0 with kernal ROM
53         sta     MMU_CR
54         jsr     callirq                 ; Call the functions
55         pla                             ; Get old register value
56         sta     MMU_CR
57         jmp     IRQInd                  ; Jump to the saved IRQ vector