Subversion Repositories Spectranet

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 78 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        "sysvars.inc"
23
.include        "zxsysvars.inc"
24
.include        "spectranet.inc"
25
.include        "zxrom.inc"
26 78 winston
 
27
;---------------------------------------------------------------------------
28
; do_callbas
29
; Not really a trap, but it handles the effects of an RST 0x10 'callbas'
30
; exit (which will get re-trapped by a subsequent return via RST 8)
31 384 winston
.text
32
.globl do_callbas
33
do_callbas:
34 78 winston
        ld e, (hl)              ; Get the subroutine address into DE
35
        inc hl
36
        ld d, (hl)
37
        inc hl                  ; hl now is the return address
38
        push hl                 ; put the return address back on the stack
39
        ld hl, 0                ; entry code to RST 8
40
        push hl
41
        ld hl, 8                ; return address for Spectrum ROM to return
42
        push hl
43
        push de                 ; the actual address in ROM we want to call
44
        ld hl, (v_hlsave)       ; restore HL
45
        ld de, (v_desave)       ; restore de
46 384 winston
        jp PAGEOUT              ; page out
47 78 winston
 
48
;---------------------------------------------------------------------------
49
; do_rst8
50
; Figure out what needs to be done when an RST 8 trap occurs.
51 384 winston
.globl do_rst8
52
do_rst8:
53 78 winston
        ld (v_hlsave), hl       ; save hl without disturbing stack
54
        pop hl                  ; get stack value - entry code
55 129 winston
        push hl
56 78 winston
        push af
57
        ld a, h                 ; check for zero - Spectrum ROM routine return
58
        or l
59 384 winston
        jr z, .returnfromzxrom0 ; returning from a Spectrum ROM call
60 129 winston
 
61
        ; This is to allow testing of RST8 routines without
62
        ; flashing a new ROM each time.
63
        ex de, hl               ; keep the stack value in DE
64
        ld hl, (v_rst8vector)
65
        ld a, h
66
        or l
67 384 winston
        jr z, .done0
68 129 winston
        jp (hl)
69 384 winston
.done0:
70 78 winston
        ; The call to the interpreter would end up here.
71
        ; For now just reshuffle the stack so we can pass control back
72
        ; to the ZX rom.
73
        pop af
74
        ld hl, 0x000B           ; address to return to
75 384 winston
        push hl                 ; stack it for the RET at PAGEOUT
76 78 winston
        ld hl, (ZX_CH_ADD)      ; do the same as the first RST 8 instruction
77 384 winston
        jp PAGEOUT              ; re-enter the ZX ROM
78 78 winston
 
79 384 winston
.returnfromzxrom0:
80 78 winston
        pop af                  ; restore af
81 129 winston
        pop hl                  ; fix stack
82 78 winston
        ld hl, (v_hlsave)       ; restore hl
83
        ret                     ; go back to the calling routine.
84