Subversion Repositories Spectranet

[/] [trunk/] [rom/] [progtrap.asm] - Blame information for rev 540

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 399 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 399 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 399 winston
        jr z, .usecurrent1
47 126 winston
        ldi                     ; copy page
48 399 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 540 winston
        in a, (c)               ; this resets the address toggle in the CPLD
58 126 winston
        inc b
59
        outi                    ; set LSB of trap address
60
        inc b
61
        outi                    ; set MSB of trap address
62
 
63
        ld bc, CTRLREG          ; Read the Spectranet control register
64
        in a, (c)
65
        or MASK_PROGTRAP_EN     ; enable the programmable trap
66
        out (c), a              ; write new register value
67
        ret
68
 
69 399 winston
.usecurrent1:
70 222 winston
        ld a, (v_pgb)
71
        ld (de), a
72
        inc de
73
        inc hl
74 399 winston
        jr .cprest1
75 222 winston
 
76 126 winston
;--------------------------------------------------------------------------
77
; F_disabletrap
78
; Disables the programmable trap.
79 399 winston
.globl F_disabletrap
80
F_disabletrap:
81 126 winston
        ld bc, CTRLREG
82
        in a, (c)               ; get current control register value
83
        res BIT_PROGTRAP_EN, a  ; reset the trap enable bit
84
        out (c), a              ; write register back
85
        ret
86
 
87
;--------------------------------------------------------------------------
88
; F_enabletrap
89
; Enables the programmable trap
90 399 winston
.globl F_enabletrap
91
F_enabletrap:
92 126 winston
        ld bc, CTRLREG
93
        in a, (c)               ; get current control register value
94
        or MASK_PROGTRAP_EN     ; set the trap enable bit
95
        out (c), a              ; and write it back
96
        ret
97
 
98 128 winston
;--------------------------------------------------------------------------
99
; J_pagetrapreturn
100
; Returns from a trap, restoring page area B, the stack, and unpaging
101
; the Spectranet
102 399 winston
.globl J_pagetrapreturn
103
J_pagetrapreturn:
104 128 winston
        call F_poppageB
105
;--------------------------------------------------------------------------
106
; J_trapreturn
107
; Returns from a trap, restoring the stack and unpaging the Spectranet
108 399 winston
.globl J_trapreturn
109
J_trapreturn:
110 128 winston
        pop af
111 129 winston
        ex af, af'
112
        pop af
113 128 winston
        pop bc
114
        pop de
115 242 winston
        pop hl
116
        ld sp, (NMISTACK)       ; restore SP
117
        push hl                 ; swap HL with the stack to put
118 399 winston
        ld hl, PAGEOUT          ; the page out address there for RETN
119 128 winston
        ex (sp), hl             ; restore hl, put page out on stack
120
        retn
121