File: _sys.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (81 lines) | stat: -rw-r--r-- 1,773 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
;
; void __fastcall__ _sys (struct regs* r);
;

        .export         __sys
        .import         jmpvec

        .include        "zeropage.inc"

        .segment        "LOWCODE"

__sys:  sta     ptr1
        stx     ptr1+1          ; Save the pointer to r

        ; Fetch the PC and store it into the jump vector
        ldy     #5
        lda     (ptr1),y
        sta     jmpvec+2
        dey
        lda     (ptr1),y
        sta     jmpvec+1

        ; Remember the flags so we can restore them to a known state after calling the
        ; routine
        php

        ; Get the flags, keep the state of bit 4 and 5 using the other flags from
        ; the flags value passed by the caller. Push the new flags and push A.
        dey
        php
        pla                     ; Current flags -> A
        eor     (ptr1),y
        and     #%00110000
        eor     (ptr1),y
        pha                     ; Push new flags value
        ldy     #0
        lda     (ptr1),y
        pha

        ; Get and assign X and Y
        iny
        lda     (ptr1),y
        tax
        iny
        lda     (ptr1),y
        tay

        ; Switch in ROM
        bit     $C082

        ; Set A and the flags, call the machine code routine
        pla
        plp
        jsr     jmpvec

        ; Back from the routine. Save the flags and A.
        php
        pha

        ; Switch in LC bank 2 for R/O
        bit     $C080

        ; Put the register values into the regs structure
        tya
        ldy     #2
        sta     (ptr1),y
        dey
        txa
        sta     (ptr1),y
        dey
        pla
        sta     (ptr1),y
        ldy     #3
        pla
        sta     (ptr1),y

        ; Restore the old flags value
        plp

        ; Done
        rts