Subversion Repositories Spectranet

[/] [trunk/] [rom/] [zeropage.asm] - Blame information for rev 255

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
 
23
; ZEROPAGE ENTRY POINTS
24
; This file should be included first in "rom.asm"; it sets the org.
25
;
26
; RST 0xNN instructions - This is where all the restarts live:
27
; 00    Reset
28
; 08    Entry point for BASIC traps
29
; 10    CALLBAS restart for BASIC extensions
30
; 18
31
; 20
32
; 28
33
; 30
34
; 38    Maskable interrupt service routine
35
;
36
; NMI entry point at 0x0066
37
; Unpage entry point at 0x007C
38
 
39
        org 0x0000
40
RESET
41 77 winston
        di              ; This should be done already for a real reset.
42
        jp J_reset
43 24 winston
 
44
        block 0x08-$,0xFF
45
TRAPBAS
46 78 winston
        jp do_rst8
47 24 winston
        block 0x10-$,0xFF
48
CALLBAS
49 78 winston
        ld (v_hlsave), hl
50
        ld (v_desave), de
51
        pop hl
52
        jp do_callbas
53 171 winston
        block 0x28-$,0xFF
54
MODULECALL_NOPAGE
55
        jp J_moduledispatch
56 163 winston
        block 0x30-$,0xFF
57
MODULECALL
58 171 winston
        call J_moduledispatch
59
        ex (sp), hl             ; throw away return to 0x3FF9
60
        pop hl
61
        jr UNPAGE               ; unpage and return to caller
62 24 winston
        block 0x38-$,0xFF
63
INTERRUPT
64 255 winston
        push hl
65
        ld hl, (v_intcount)     ; really, just to indicate that an
66
        inc hl                  ; interrupt took place
67
        ld (v_intcount), hl
68
        pop hl
69 130 winston
        ei
70 255 winston
        reti                    ; TODO - do something!
71 24 winston
 
72
        block 0x66-$,0xFF
73
NMI
74 242 winston
        ld (NMISTACK), sp       ; save SP
75
        ld sp, NMISTACK-4       ; set up new stack
76
 
77 97 winston
        ; stack everything that will be changed.
78
        push hl
79
        push de
80
        push bc
81
        push af
82 129 winston
        ex af, af'
83
        push af
84 242 winston
        ld hl, (NMISTACK)       ; HL = address of the return address
85 97 winston
        jr NMI2
86 24 winston
 
87
        block 0x7C-$,0xFF
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
UNPAGE
91
        ret
92 97 winston
NMI2
93 126 winston
        ld bc, CTRLREG          ; test for trap enable
94
        in a, (c)
95
        and MASK_PROGTRAP_EN
96
        jr z, .nmimenu          ; not enabled
97
        ld a, (v_trapcomefrom)  ; get comefrom address LSB
98
        cp (hl)                 ; equal to low order?
99
        jr nz, .nmimenu         ; no
100
        inc hl                  ; return address MSB
101
        ld a, (v_trapcomefrom+1) ; comefrom MSB
102
        cp (hl)                 ; equal to high order?
103
        jr nz, .nmimenu         ; no
104 242 winston
        ld a, 6
105
        out (254), a
106 126 winston
 
107
        ; Set up the environment ready to handle the trap.
108
        ld a, (v_trappage)      ; get the page to page in
109
        and a                   ; if it's zero though, ignore it.
110
        call nz, F_pushpageB    ; page in requested page, stacking current
111
        ld hl, (v_trapaddr)     ; no paging to be done - just get the call addr
112
        jp (hl)                 ; jump to it
113
 
114
.nmimenu
115
        ld a, 0x02              ; Utility ROM
116
        call F_setpageB
117 97 winston
        ld hl, (NMI_VECTOR)     ; Test NMI_VECTOR
118
        ld a, 0xFF
119
        cp h                    ; FF = unset
120
        jr z, .nmidone
121
        ld de, .nmidone         ; get return address
122
        push de                 ; save it, so subsequent RET comes back
123
        jp (hl)                 ; jump to the NMI vector
124
.nmidone
125
        pop af
126 129 winston
        ex af, af'
127
        pop af
128 97 winston
        pop bc
129
        pop de
130 242 winston
        pop hl
131
        ld sp, (NMISTACK)       ; restore stack pointer
132
        push hl                 ; munge the stack
133
        ld hl, UNPAGE           ; so that RETN goes via unpage
134 97 winston
        ex (sp), hl
135
        retn
136 24 winston