Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [rom/] [progtrap.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        "sysdefs.inc"
 
.include        "sysvars.inc"
 
.include        "spectranet.inc"
 
 
; This code is used to set up the programmable trap.
; This code is used to set up the programmable trap.
; The programmable trap may be anywhere in memory. When the CPU fetches
; The programmable trap may be anywhere in memory. When the CPU fetches
; the instruction at the trap address, a non maskable interrupt is fired.
; the instruction at the trap address, a non maskable interrupt is fired.
; Once this instruction is complete, the CPU jumps to the NMI address.
; Once this instruction is complete, the CPU jumps to the NMI address.
Line 32... Line 35...
;         Format:
;         Format:
;         byte 0   - Memory page for page B on trap (0 to do no paging)
;         byte 0   - Memory page for page B on trap (0 to do no paging)
;         byte 1,2 - Address to call when trap fires
;         byte 1,2 - Address to call when trap fires
;         byte 3,4 - Address that trap comes from
;         byte 3,4 - Address that trap comes from
;         byte 5,6 - Address of the actual trap
;         byte 5,6 - Address of the actual trap
F_settrap
.text
 
.globl F_settrap
 
F_settrap:
        ld de, v_trappage       ; Copy trap details to sysvars
        ld de, v_trappage       ; Copy trap details to sysvars
        ld a, (hl)              ; check for 0xFF as the page
        ld a, (hl)              ; check for 0xFF as the page
        cp 0xFF                 ; since this indicates 'current page B rom'
        cp 0xFF                 ; since this indicates 'current page B rom'
        jr z, .usecurrent
        jr z, .usecurrent1
        ldi                     ; copy page
        ldi                     ; copy page
.cprest
.cprest1:
        ldi                     ; copy lsb of call address
        ldi                     ; copy lsb of call address
        ldi                     ; copy msb of call address
        ldi                     ; copy msb of call address
        ldi                     ; call lsb of comefrom address
        ldi                     ; call lsb of comefrom address
        ldi                     ; call msb of comefrom address
        ldi                     ; call msb of comefrom address
 
 
Line 58... Line 63...
        in a, (c)
        in a, (c)
        or MASK_PROGTRAP_EN     ; enable the programmable trap
        or MASK_PROGTRAP_EN     ; enable the programmable trap
        out (c), a              ; write new register value
        out (c), a              ; write new register value
        ret
        ret
 
 
.usecurrent
.usecurrent1:
        ld a, (v_pgb)
        ld a, (v_pgb)
        ld (de), a
        ld (de), a
        inc de
        inc de
        inc hl
        inc hl
        jr .cprest
        jr .cprest1
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_disabletrap
; F_disabletrap
; Disables the programmable trap.
; Disables the programmable trap.
F_disabletrap
.globl F_disabletrap
 
F_disabletrap:
        ld bc, CTRLREG
        ld bc, CTRLREG
        in a, (c)               ; get current control register value
        in a, (c)               ; get current control register value
        res BIT_PROGTRAP_EN, a  ; reset the trap enable bit
        res BIT_PROGTRAP_EN, a  ; reset the trap enable bit
        out (c), a              ; write register back
        out (c), a              ; write register back
        ret
        ret
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; F_enabletrap
; F_enabletrap
; Enables the programmable trap
; Enables the programmable trap
F_enabletrap
.globl F_enabletrap
 
F_enabletrap:
        ld bc, CTRLREG
        ld bc, CTRLREG
        in a, (c)               ; get current control register value
        in a, (c)               ; get current control register value
        or MASK_PROGTRAP_EN     ; set the trap enable bit
        or MASK_PROGTRAP_EN     ; set the trap enable bit
        out (c), a              ; and write it back
        out (c), a              ; and write it back
        ret
        ret
 
 
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; J_pagetrapreturn
; J_pagetrapreturn
; Returns from a trap, restoring page area B, the stack, and unpaging
; Returns from a trap, restoring page area B, the stack, and unpaging
; the Spectranet
; the Spectranet
J_pagetrapreturn
.globl J_pagetrapreturn
 
J_pagetrapreturn:
        call F_poppageB
        call F_poppageB
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------
; J_trapreturn
; J_trapreturn
; Returns from a trap, restoring the stack and unpaging the Spectranet
; Returns from a trap, restoring the stack and unpaging the Spectranet
J_trapreturn
.globl J_trapreturn
 
J_trapreturn:
        pop af
        pop af
        ex af, af'
        ex af, af'
        pop af
        pop af
        pop bc
        pop bc
        pop de
        pop de
        pop hl
        pop hl
        ld sp, (NMISTACK)       ; restore SP
        ld sp, (NMISTACK)       ; restore SP
        push hl                 ; swap HL with the stack to put
        push hl                 ; swap HL with the stack to put
        ld hl, UNPAGE           ; the page out address there for RETN
        ld hl, PAGEOUT          ; the page out address there for RETN
        ex (sp), hl             ; restore hl, put page out on stack
        ex (sp), hl             ; restore hl, put page out on stack
        retn
        retn