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