Subversion Repositories Spectranet

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 126 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 126 winston
 
26
; This code is used to set up the programmable trap.
27
; The programmable trap may be anywhere in memory. When the CPU fetches
28
; the instruction at the trap address, a non maskable interrupt is fired.
29
; Once this instruction is complete, the CPU jumps to the NMI address.
30
 
31
;=========================================================================
32
; F_settrap: Sets the programmable trap.
33
; Parameters:
34
;    hl = Address of a block of memory containing data to set up the trap.
35
;         Format:
36
;         byte 0   - Memory page for page B on trap (0 to do no paging)
37
;         byte 1,2 - Address to call when trap fires
38
;         byte 3,4 - Address that trap comes from
39
;         byte 5,6 - Address of the actual trap
40 384 winston
.text
41
.globl F_settrap
42
F_settrap:
43 126 winston
        ld de, v_trappage       ; Copy trap details to sysvars
44 222 winston
        ld a, (hl)              ; check for 0xFF as the page
45
        cp 0xFF                 ; since this indicates 'current page B rom'
46 384 winston
        jr z, .usecurrent1
47 126 winston
        ldi                     ; copy page
48 384 winston
.cprest1:
49 126 winston
        ldi                     ; copy lsb of call address
50
        ldi                     ; copy msb of call address
51
        ldi                     ; call lsb of comefrom address
52
        ldi                     ; call msb of comefrom address
53
 
54
        ; (hl) now points at the actual trap address. Note that OUTI
55
        ; affects B so we have to reset it each time! B is pre-decremented.
56
        ld bc, TRAPSET          ; Set trap address I/O port
57
        inc b
58
        outi                    ; set LSB of trap address
59
        inc b
60
        outi                    ; set MSB of trap address
61
 
62
        ld bc, CTRLREG          ; Read the Spectranet control register
63
        in a, (c)
64
        or MASK_PROGTRAP_EN     ; enable the programmable trap
65
        out (c), a              ; write new register value
66
        ret
67
 
68 384 winston
.usecurrent1:
69 222 winston
        ld a, (v_pgb)
70
        ld (de), a
71
        inc de
72
        inc hl
73 384 winston
        jr .cprest1
74 222 winston
 
75 126 winston
;--------------------------------------------------------------------------
76
; F_disabletrap
77
; Disables the programmable trap.
78 384 winston
.globl F_disabletrap
79
F_disabletrap:
80 126 winston
        ld bc, CTRLREG
81
        in a, (c)               ; get current control register value
82
        res BIT_PROGTRAP_EN, a  ; reset the trap enable bit
83
        out (c), a              ; write register back
84
        ret
85
 
86
;--------------------------------------------------------------------------
87
; F_enabletrap
88
; Enables the programmable trap
89 384 winston
.globl F_enabletrap
90
F_enabletrap:
91 126 winston
        ld bc, CTRLREG
92
        in a, (c)               ; get current control register value
93
        or MASK_PROGTRAP_EN     ; set the trap enable bit
94
        out (c), a              ; and write it back
95
        ret
96
 
97 128 winston
;--------------------------------------------------------------------------
98
; J_pagetrapreturn
99
; Returns from a trap, restoring page area B, the stack, and unpaging
100
; the Spectranet
101 384 winston
.globl J_pagetrapreturn
102
J_pagetrapreturn:
103 128 winston
        call F_poppageB
104
;--------------------------------------------------------------------------
105
; J_trapreturn
106
; Returns from a trap, restoring the stack and unpaging the Spectranet
107 384 winston
.globl J_trapreturn
108
J_trapreturn:
109 128 winston
        pop af
110 129 winston
        ex af, af'
111
        pop af
112 128 winston
        pop bc
113
        pop de
114 242 winston
        pop hl
115
        ld sp, (NMISTACK)       ; restore SP
116
        push hl                 ; swap HL with the stack to put
117 384 winston
        ld hl, PAGEOUT          ; the page out address there for RETN
118 128 winston
        ex (sp), hl             ; restore hl, put page out on stack
119
        retn
120