Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [trapdispatch.asm] - Diff between revs 371 and 384

Show entire file | Details | Blame | View Log

Rev 371 Rev 384
Line 17... Line 17...
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
;THE SOFTWARE.
;THE SOFTWARE.
 
.include        "sysvars.inc"
 
.include        "zxsysvars.inc"
 
.include        "spectranet.inc"
 
.include        "zxrom.inc"
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; do_callbas
; do_callbas
; Not really a trap, but it handles the effects of an RST 0x10 'callbas'
; Not really a trap, but it handles the effects of an RST 0x10 'callbas'
; exit (which will get re-trapped by a subsequent return via RST 8)
; exit (which will get re-trapped by a subsequent return via RST 8)
do_callbas
.text
 
.globl do_callbas
 
do_callbas:
        ld e, (hl)              ; Get the subroutine address into DE
        ld e, (hl)              ; Get the subroutine address into DE
        inc hl
        inc hl
        ld d, (hl)
        ld d, (hl)
        inc hl                  ; hl now is the return address
        inc hl                  ; hl now is the return address
        push hl                 ; put the return address back on the stack
        push hl                 ; put the return address back on the stack
Line 35... Line 41...
        ld hl, 8                ; return address for Spectrum ROM to return
        ld hl, 8                ; return address for Spectrum ROM to return
        push hl
        push hl
        push de                 ; the actual address in ROM we want to call
        push de                 ; the actual address in ROM we want to call
        ld hl, (v_hlsave)       ; restore HL
        ld hl, (v_hlsave)       ; restore HL
        ld de, (v_desave)       ; restore de
        ld de, (v_desave)       ; restore de
        jp UNPAGE               ; page out
        jp PAGEOUT              ; page out
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; do_rst8
; do_rst8
; Figure out what needs to be done when an RST 8 trap occurs.
; Figure out what needs to be done when an RST 8 trap occurs.
do_rst8
.globl do_rst8
 
do_rst8:
        ld (v_hlsave), hl       ; save hl without disturbing stack
        ld (v_hlsave), hl       ; save hl without disturbing stack
        pop hl                  ; get stack value - entry code
        pop hl                  ; get stack value - entry code
        push hl
        push hl
        push af
        push af
        ld a, h                 ; check for zero - Spectrum ROM routine return
        ld a, h                 ; check for zero - Spectrum ROM routine return
        or l
        or l
        jr z, .returnfromzxrom  ; returning from a Spectrum ROM call
        jr z, .returnfromzxrom0 ; returning from a Spectrum ROM call
 
 
        ; This is to allow testing of RST8 routines without
        ; This is to allow testing of RST8 routines without
        ; flashing a new ROM each time.
        ; flashing a new ROM each time.
        ex de, hl               ; keep the stack value in DE
        ex de, hl               ; keep the stack value in DE
        ld hl, (v_rst8vector)
        ld hl, (v_rst8vector)
        ld a, h
        ld a, h
        or l
        or l
        jr z, .done
        jr z, .done0
        jp (hl)
        jp (hl)
.done
.done0:
        ; The call to the interpreter would end up here.
        ; The call to the interpreter would end up here.
        ; For now just reshuffle the stack so we can pass control back
        ; For now just reshuffle the stack so we can pass control back
        ; to the ZX rom.
        ; to the ZX rom.
        pop af
        pop af
        ld hl, 0x000B           ; address to return to
        ld hl, 0x000B           ; address to return to
        push hl                 ; stack it for the RET at UNPAGE
        push hl                 ; stack it for the RET at PAGEOUT
        ld hl, (ZX_CH_ADD)      ; do the same as the first RST 8 instruction
        ld hl, (ZX_CH_ADD)      ; do the same as the first RST 8 instruction
        jp UNPAGE               ; re-enter the ZX ROM
        jp PAGEOUT              ; re-enter the ZX ROM
 
 
.returnfromzxrom
.returnfromzxrom0:
        pop af                  ; restore af
        pop af                  ; restore af
        pop hl                  ; fix stack
        pop hl                  ; fix stack
        ld hl, (v_hlsave)       ; restore hl
        ld hl, (v_hlsave)       ; restore hl
        ret                     ; go back to the calling routine.
        ret                     ; go back to the calling routine.