Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [snapman/] [loadsna.asm] - Diff between revs 371 and 372

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 371 Rev 372
Line 18... Line 18...
;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.
 
 
; Functions to load .SNA (snapshot) files
; Functions to load  .SNA0 (snapshot) files
 
.include        "snapheader.inc"
; SNA file definitions
.include        "snapman.inc"
HEADER          equ 0x3000
.include        "fcntl.inc"
SNA_I           equ HEADER
.include        "spectranet.inc"
SNA_HLALT       equ HEADER+1
 
SNA_DEALT       equ HEADER+3
 
SNA_BCALT       equ HEADER+5
 
SNA_AFALT       equ HEADER+7
 
SNA_HL          equ HEADER+9
 
SNA_DE          equ HEADER+11
 
SNA_BC          equ HEADER+13
 
SNA_IY          equ HEADER+15
 
SNA_IX          equ HEADER+17
 
SNA_EIDI        equ HEADER+19
 
SNA_R           equ HEADER+20
 
SNA_AF          equ HEADER+21
 
SNA_SP          equ HEADER+23
 
SNA_IM          equ HEADER+25
 
SNA_BORDER      equ HEADER+26
 
HEADERSZ        equ 27
 
SNA_PC          equ HEADER+27           ; 128K .SNA file - program counter
 
SNA_7FFD        equ HEADER+29           ; value of port 0x7FFD
 
SNA_TRDOS       equ HEADER+30           ; TR-DOS flagm
 
 
 
;------------------------------------------------------------------------
;------------------------------------------------------------------------
; F_loadsnap
; F_loadsnap
; Determine if the filename passed in HL is a snapshot file we can handle
; Determine if the filename passed in HL is a snapshot file we can handle
; and call the correct routine to handle it. On error, it returns.
; and call the correct routine to handle it. On error, it returns.
; If no error is encountered, the snapshot is run.
; If no error is encountered, the snapshot is run.
F_loadsnap_modcall
.globl F_loadsnap_modcall
 
F_loadsnap_modcall:
        ex de, hl
        ex de, hl
        push hl                 ; if called from another program set the
        push hl                 ; if called from another program set the
        ld de, v_curfilename    ; current filename in case the user enters
        ld de, v_curfilename    ; current filename in case the user enters
        call F_strcpy           ; the UI.
        call F_strcpy           ; the UI.
        pop hl
        pop hl
F_loadsnap
.globl F_loadsnap
 
F_loadsnap:
        ; simple detection - look at the size to see if it's 48K or 128K
        ; simple detection - look at the size to see if it's 48K or 128K
        push hl                 ; save the filename pointer
        push hl                 ; save the filename pointer
        ld de, v_statinfo       ; where to put the data from stat
        ld de, v_statinfo       ; where to put the data from stat
        call STAT
        call STAT
        pop hl
        pop hl
Line 74... Line 57...
        ld sp, v_snapstack      ; Set the stack for snapshot loading.
        ld sp, v_snapstack      ; Set the stack for snapshot loading.
 
 
        ld hl, (v_statinfo+8)   ; Less than 64K in size?
        ld hl, (v_statinfo+8)   ; Less than 64K in size?
        ld a, h
        ld a, h
        or l
        or l
        jr z, .fortyeight
        jr z,  .fortyeight2
 
 
        call F_loadsna128       ; Load a 128K snapshot
        call F_loadsna128       ; Load a 128K snapshot
        ld sp, (v_stacksave)    ; Restore the stack
        ld sp, (v_stacksave)    ; Restore the stack
        ret
        ret
.fortyeight
.fortyeight2:
        call F_loadsna48
        call F_loadsna48
        ld sp, (v_stacksave)
        ld sp, (v_stacksave)
        ret
        ret
 
 
;---------------------------------------------------------------------------
;---------------------------------------------------------------------------
; F_loadsna48: Load a 48K snapshot. File handle is in (v_snapfd)
; F_loadsna48: Load a 48K snapshot. File handle is in (v_snapfd)
; On error carry is set and A=errno
; On error carry is set and A=errno
; On success, snapshot is launched (effectively, we don't return)
; On success, snapshot is launched (effectively, we don't return)
F_loadsna48
.globl F_loadsna48
 
F_loadsna48:
        di                      ; don't want the stack getting meddled by int
        di                      ; don't want the stack getting meddled by int
        ld a, (v_snapfd)
        ld a, (v_snapfd)
        ld de, HEADER           ; where to put the header
        ld de, HEADER           ; where to put the header
        ld bc, 27               ; length of the header
        ld bc, 27               ; length of the header
        call READ               ; read it
        call READ               ; read it
Line 108... Line 92...
        jp c, J_snapdie
        jp c, J_snapdie
 
 
        ld a, (v_snapfd)        ; close the fd
        ld a, (v_snapfd)        ; close the fd
        call VCLOSE
        call VCLOSE
 
 
J_unloadheader
.globl J_unloadheader
 
J_unloadheader:
        ; At this point we've successfully loaded the snapshot file.
        ; At this point we've successfully loaded the snapshot file.
        ; First deal with the screen.
        ; First deal with the screen.
        call F_restorescreen
        call F_restorescreen
 
 
        ; Set register values.
        ; Set register values.
Line 129... Line 114...
        ld bc, (SNA_BC)
        ld bc, (SNA_BC)
        ld ix, (SNA_IX)
        ld ix, (SNA_IX)
        ld iy, (SNA_IY)
        ld iy, (SNA_IY)
        ld a, (SNA_IM)          ; Set the interrupt mode
        ld a, (SNA_IM)          ; Set the interrupt mode
        and a
        and a
        jr nz, .im1
        jr nz,  .im13
        im 0
        im 0
        jr .imdone
        jr  .imdone3
.im1    cp 1
.im13: cp 1
        jr nz, .im2
        jr nz,  .im23
        im 1
        im 1
        jr .imdone
        jr  .imdone3
.im2    im 2
.im23: im 2
.imdone
.imdone3:
        ld a, (SNA_I)           ; Set the I register
        ld a, (SNA_I)           ; Set the I register
        ld i, a
        ld i, a
        ld a, (SNA_BORDER)      ; Set the border colour
        ld a, (SNA_BORDER)      ; Set the border colour
        out (254), a
        out (254), a
        ld hl, (SNA_AF)         ; Set AF
        ld hl, (SNA_AF)         ; Set AF
        push hl
        push hl
        pop af
        pop af
        ld hl, SNA_EIDI         ; Interrupt state
        ld hl, SNA_EIDI         ; Interrupt state
        bit 2, (hl)             ; nz = enable interrupts
        bit 2, (hl)             ; nz = enable interrupts
        jr z, .noei             ; interrupts are currently disabled anyway
        jr z,  .noei3           ; interrupts are currently disabled anyway
        ld hl, (SNA_HL)         ; Set HL
        ld hl, (SNA_HL)         ; Set HL
        ld sp, (SNA_SP)         ; and SP, finally EI and return via UNPAGE
        ld sp, (SNA_SP)         ; and SP, finally EI and return via UNPAGE
        ei                      ; and EI at the last possible moment.
        ei                      ; and EI at the last possible moment.
        jp 0x007C
        jp 0x007C
.noei
.noei3:
        ld hl, (SNA_HL)
        ld hl, (SNA_HL)
        ld sp, (SNA_SP)         ; Snapshot's stack pointer
        ld sp, (SNA_SP)         ; Snapshot's stack pointer
        jp 0x007C               ; unpage
        jp 0x007C               ; unpage
 
 
J_snapdie
.globl J_snapdie
 
J_snapdie:
        push af                 ; preserve error status
        push af                 ; preserve error status
        ld a, 2
        ld a, 2
        out (254), a
        out (254), a
        ld a, (v_snapfd)
        ld a, (v_snapfd)
        call VCLOSE
        call VCLOSE
        pop af
        pop af
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_readscreen: Read the screen memory into Spectranet RAM
; F_readscreen: Read the screen memory into Spectranet RAM
F_readscreen
.globl F_readscreen
 
F_readscreen:
        ld a, 0xDA              ; first page
        ld a, 0xDA              ; first page
        call PUSHPAGEA          ; switch and store page number
        call PUSHPAGEA          ; switch and store page number
        ld de, 0x1000
        ld de, 0x1000
        ld bc, 0x1000
        ld bc, 0x1000
        ld a, (v_snapfd)
        ld a, (v_snapfd)
        call READ
        call READ
        jr c, .restoreerr
        jr c,  .restoreerr4
        ld a, 0xDB
        ld a, 0xDB
        call SETPAGEA
        call SETPAGEA
        ld de, 0x1000
        ld de, 0x1000
        ld bc, 0xB00
        ld bc, 0xB00
        ld a, (v_snapfd)
        ld a, (v_snapfd)
        call READ
        call READ
.restoreerr
.restoreerr4:
        call POPPAGEA
        call POPPAGEA
        ret
        ret
 
 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; F_loadsna128 - Loads a 128K snapshot.
; F_loadsna128 - Loads a 128K snapshot.
; File descriptor in (v_snapfd)
; File descriptor in (v_snapfd)
; On error carry is set and A=errno
; On error carry is set and A=errno
; On success, snapshot is launched (effectively, we don't return)
; On success, snapshot is launched (effectively, we don't return)
F_loadsna128
.globl F_loadsna128
 
F_loadsna128:
        ld a, (v_snapfd)
        ld a, (v_snapfd)
        ld de, HEADER           ; where to put the header
        ld de, HEADER           ; where to put the header
        ld bc, HEADERSZ         ; length of the header
        ld bc, HEADERSZ         ; length of the header
        call READ
        call READ
        jp c, J_snapdie
        jp c, J_snapdie
Line 229... Line 217...
        call READ
        call READ
        jp c, J_snapdie
        jp c, J_snapdie
 
 
        ; Load the pages except the paged page, and pages 2 and 5
        ; Load the pages except the paged page, and pages 2 and 5
        ld d, 0                 ; start with page 0
        ld d, 0                 ; start with page 0
.pageloadloop
.pageloadloop5:
        ld a, (SNA_7FFD)        ; find out what page is paged in 0xC000
        ld a, (SNA_7FFD)        ; find out what page is paged in 0xC000
        and 7                   ; to know which to skip loading
        and 7                   ; to know which to skip loading
        cp d
        cp d
        jr z, .next
        jr z,  .next5
        ld a, d
        ld a, d
        cp 2                    ; also skip pages 2 and 5
        cp 2                    ; also skip pages 2 and 5
        jr z, .next
        jr z,  .next5
        cp 5
        cp 5
        jr z, .next
        jr z,  .next5
 
 
        ld bc, 0x7FFD           ; now page in the page that should be
        ld bc, 0x7FFD           ; now page in the page that should be
        out (c), d              ; loaded.
        out (c), d              ; loaded.
        push de
        push de
        ld de, 0xC000           ; the pageable area starts at 0xC000
        ld de, 0xC000           ; the pageable area starts at 0xC000
        ld bc, 16384            ; for 16K
        ld bc, 16384            ; for 16K
        ld a, (v_snapfd)
        ld a, (v_snapfd)
        call READ
        call READ
        pop de
        pop de
        jp c, J_snapdie
        jp c, J_snapdie
.next
.next5:
        inc d                   ; increment page number
        inc d                   ; increment page number
        ld a, d
        ld a, d
        cp 8                    ; finished?
        cp 8                    ; finished?
        jr nz, .pageloadloop
        jr nz,  .pageloadloop5
 
 
        ; Now load the reaming page - for this we need to seek backwards
        ; Now load the reaming page - for this we need to seek backwards
        ; to where it's stored... given that SNA files can be of two lengths
        ; to where it's stored... given that SNA files can be of two lengths
        ; seeking from the start is the best.
        ; seeking from the start is the best.
        ld de, 0                ; seek to 32K from the start
        ld de, 0                ; seek to 32K from the start