]> git.sur5r.net Git - cc65/blob - libsrc/apple2/_sys.s
cfg/atari-xex.cfg: fix typo in comment
[cc65] / libsrc / apple2 / _sys.s
1 ;
2 ; void __fastcall__ _sys (struct regs* r);
3 ;
4
5         .export         __sys
6         .import         jmpvec
7
8         .include        "zeropage.inc"
9
10         .segment        "LOWCODE"
11
12 __sys:  sta     ptr1
13         stx     ptr1+1          ; Save the pointer to r
14
15         ; Fetch the PC and store it into the jump vector
16         ldy     #5
17         lda     (ptr1),y
18         sta     jmpvec+2
19         dey
20         lda     (ptr1),y
21         sta     jmpvec+1
22
23         ; Remember the flags so we can restore them to a known state after calling the
24         ; routine
25         php
26
27         ; Get the flags, keep the state of bit 4 and 5 using the other flags from
28         ; the flags value passed by the caller. Push the new flags and push A.
29         dey
30         php
31         pla                     ; Current flags -> A
32         eor     (ptr1),y
33         and     #%00110000
34         eor     (ptr1),y
35         pha                     ; Push new flags value
36         ldy     #0
37         lda     (ptr1),y
38         pha
39
40         ; Get and assign X and Y
41         iny
42         lda     (ptr1),y
43         tax
44         iny
45         lda     (ptr1),y
46         tay
47
48         ; Switch in ROM
49         bit     $C082
50
51         ; Set A and the flags, call the machine code routine
52         pla
53         plp
54         jsr     jmpvec
55
56         ; Back from the routine. Save the flags and A.
57         php
58         pha
59
60         ; Switch in LC bank 2 for R/O
61         bit     $C080
62
63         ; Put the register values into the regs structure
64         tya
65         ldy     #2
66         sta     (ptr1),y
67         dey
68         txa
69         sta     (ptr1),y
70         dey
71         pla
72         sta     (ptr1),y
73         ldy     #3
74         pla
75         sta     (ptr1),y
76
77         ; Restore the old flags value
78         plp
79
80         ; Done
81         rts