]> git.sur5r.net Git - cc65/blob - libsrc/common/_sys.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / common / _sys.s
1 ;
2 ; void __fastcall__ _sys (struct regs* r);
3 ;
4 ; Ullrich von Bassewitz, 16.12.1998
5 ;
6
7         .export         __sys
8         .import         jmpvec
9         .importzp       ptr1
10
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
17         ldy     #5
18         lda     (ptr1),y
19         sta     jmpvec+2
20         dey
21         lda     (ptr1),y
22         sta     jmpvec+1
23
24 ; Remember the flags so we can restore them to a known state after calling the
25 ; routine
26
27         php
28
29 ; Get the flags, keep the state of bit 4 and 5 using the other flags from
30 ; the flags value passed by the caller. Push the new flags and push A.
31
32         dey
33         php
34         pla                     ; Current flags -> A
35         eor     (ptr1),y
36         and     #%00110000
37         eor     (ptr1),y
38         pha                     ; Push new flags value
39         ldy     #0
40         lda     (ptr1),y
41         pha
42
43 ; Get and assign X and Y
44
45         iny
46         lda     (ptr1),y
47         tax
48         iny
49         lda     (ptr1),y
50         tay
51
52 ; Set a and the flags, call the machine code routine
53
54         pla
55         plp
56         jsr     jmpvec
57
58 ; Back from the routine. Save the flags and A.
59
60         php
61         pha
62
63 ; Put the register values into the regs structure
64
65         tya
66         ldy     #2
67         sta     (ptr1),y
68         dey
69         txa
70         sta     (ptr1),y
71         dey
72         pla
73         sta     (ptr1),y
74         ldy     #3
75         pla
76         sta     (ptr1),y
77
78 ; Restore the old flags value
79
80         plp
81
82 ; Done
83
84         rts
85