Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [zeropage.asm] - Blame information for rev 384

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 winston
;The MIT License
2
;
3
;Copyright (c) 2008 Dylan Smith
4
;
5
;Permission is hereby granted, free of charge, to any person obtaining a copy
6
;of this software and associated documentation files (the "Software"), to deal
7
;in the Software without restriction, including without limitation the rights
8
;to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
;copies of the Software, and to permit persons to whom the Software is
10
;furnished to do so, subject to the following conditions:
11
;
12
;The above copyright notice and this permission notice shall be included in
13
;all copies or substantial portions of the Software.
14
;
15
;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
;IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
;THE SOFTWARE.
22 384 winston
.include        "sysdefs.inc"
23
.include        "sysvars.inc"
24
.include        "spectranet.inc"
25 24 winston
 
26
; ZEROPAGE ENTRY POINTS
27 384 winston
; This file should be included first in "rom.asm0"; it sets the org.
28 24 winston
;
29
; RST 0xNN instructions - This is where all the restarts live:
30
; 00    Reset
31
; 08    Entry point for BASIC traps
32
; 10    CALLBAS restart for BASIC extensions
33
; 18
34
; 20
35
; 28
36
; 30
37
; 38    Maskable interrupt service routine
38
;
39
; NMI entry point at 0x0066
40
; Unpage entry point at 0x007C
41 384 winston
.section rst0
42
RESET:
43 77 winston
        di              ; This should be done already for a real reset.
44
        jp J_reset
45 24 winston
 
46 384 winston
.section rst8
47
TRAPBAS:
48 78 winston
        jp do_rst8
49 384 winston
.section rst10
50
CALLBAS:
51 78 winston
        ld (v_hlsave), hl
52
        ld (v_desave), de
53
        pop hl
54
        jp do_callbas
55 384 winston
.section rst28
56
MODULECALL_NOPAGE:
57 171 winston
        jp J_moduledispatch
58 384 winston
.section rst30
59
MODULECALL:
60 171 winston
        call J_moduledispatch
61
        ex (sp), hl             ; throw away return to 0x3FF9
62
        pop hl
63
        jr UNPAGE               ; unpage and return to caller
64 384 winston
.section isr
65
INTERRUPT:                      ; 0x0038
66 255 winston
        push hl
67
        ld hl, (v_intcount)     ; really, just to indicate that an
68
        inc hl                  ; interrupt took place
69
        ld (v_intcount), hl
70
        pop hl
71 130 winston
        ei
72 255 winston
        reti                    ; TODO - do something!
73 24 winston
 
74 384 winston
.section nmi                    ; 0x0066
75 242 winston
        ld (NMISTACK), sp       ; save SP
76
        ld sp, NMISTACK-4       ; set up new stack
77
 
78 97 winston
        ; stack everything that will be changed.
79
        push hl
80
        push de
81
        push bc
82
        push af
83 129 winston
        ex af, af'
84
        push af
85 242 winston
        ld hl, (NMISTACK)       ; HL = address of the return address
86 97 winston
        jr NMI2
87 24 winston
 
88
        ; When unpaging, put the address where you want to end up on
89
        ; the stack, and the RET instruction will set the PC to this address.
90 384 winston
.section unpage                 ; 0x007B
91 265 winston
        ei
92 384 winston
UNPAGE:
93 24 winston
        ret
94 384 winston
.text
95
NMI2:
96 126 winston
        ld bc, CTRLREG          ; test for trap enable
97
        in a, (c)
98
        and MASK_PROGTRAP_EN
99 384 winston
        jr z, .nmimenu0         ; not enabled
100 126 winston
        ld a, (v_trapcomefrom)  ; get comefrom address LSB
101
        cp (hl)                 ; equal to low order?
102 384 winston
        jr nz, .nmimenu0                ; no
103 126 winston
        inc hl                  ; return address MSB
104
        ld a, (v_trapcomefrom+1) ; comefrom MSB
105
        cp (hl)                 ; equal to high order?
106 384 winston
        jr nz, .nmimenu0                ; no
107 126 winston
 
108
        ; Set up the environment ready to handle the trap.
109
        ld a, (v_trappage)      ; get the page to page in
110
        and a                   ; if it's zero though, ignore it.
111
        call nz, F_pushpageB    ; page in requested page, stacking current
112
        ld hl, (v_trapaddr)     ; no paging to be done - just get the call addr
113
        jp (hl)                 ; jump to it
114
 
115 384 winston
.nmimenu0:
116 126 winston
        ld a, 0x02              ; Utility ROM
117
        call F_setpageB
118 97 winston
        ld hl, (NMI_VECTOR)     ; Test NMI_VECTOR
119
        ld a, 0xFF
120
        cp h                    ; FF = unset
121 384 winston
        jr z, .nmidone0
122
        ld de, .nmidone0                ; get return address
123 97 winston
        push de                 ; save it, so subsequent RET comes back
124
        jp (hl)                 ; jump to the NMI vector
125 384 winston
.nmidone0:
126 97 winston
        pop af
127 129 winston
        ex af, af'
128
        pop af
129 97 winston
        pop bc
130
        pop de
131 242 winston
        pop hl
132
        ld sp, (NMISTACK)       ; restore stack pointer
133
        push hl                 ; munge the stack
134
        ld hl, UNPAGE           ; so that RETN goes via unpage
135 97 winston
        ex (sp), hl
136
        retn
137 24 winston