Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [basext/] [boot.asm] - Blame information for rev 380

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 341 winston
;The MIT License
2
;
3
;Copyright (c) 2010 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
 
23
; Handles post-BASIC initialization, allowing the machine to boot
24 380 winston
; from a file named boot.zx0.
25 341 winston
;
26
; This routine does the following:
27 380 winston
; If SHIFT is held, it tries to load 'boot.zx0' off the currently
28 341 winston
; mounted filesystem, using the normal BASIC loader that is contained
29
; in this module. The return stack is altered such that everything is
30
; skipped (the (c) message, entry into the editor etc) up to the point
31 380 winston
; where lines get interpreted. If 'boot.zx0' is loaded and was saved
32 341 winston
; with a LINE parameter, this line is jumped to (by putting CONTINUE
33
; into the interpreter and setting OLDPPC to NEWPPC). If the LINE
34
; parameter was not used, the BASIC program loaded is listed.
35
;
36
; On error, the stack is restored back to its original state such that
37
; we re-enter BASIC at the point the (c) message is generated.
38 380 winston
.include        "spectranet.inc"
39
.include        "defs.inc"
40
.include        "sysvars.inc"
41
.include        "zxrom.inc"
42
.include        "zxsysvars.inc"
43
.include        "ctrlchars.inc"
44
.include        "../config/config_interface.inc"
45
.text
46
.globl F_boot
47
F_boot:
48 365 winston
        call F_shouldboot       ; set zero flag if we should boot
49 341 winston
        ret nz                  ; no, do nothing.
50
        ld hl, STR_bootmsg
51
        call PRINT42
52
 
53
        ld hl, 0
54
        add hl, sp              ; hl = sp
55
        ld sp, (NMISTACK)
56
        pop de                  ; remove return addr from stack
57
        ld de, 0x12B4           ; and return to ROM at CALL LINE-SCAN
58
        push de                 ; and place it on the ZX stack
59
        push hl                 ; save NMI stack pointer
60
 
61
        rst CALLBAS
62
        defw 0x16B0             ; SET-MIN routine
63
        ld a, 0
64
        rst CALLBAS             ; Open K chan
65
        defw 0x1601
66
        ld a, 0xFF              ; ensure ERR_NR is set
67
        ld (ZX_ERR_NR), a
68
 
69
        ld hl, STR_BOOTDOTZX    ; file to boot with
70
        ld de, INTERPWKSPC
71
        ld bc, STR_BOOTDOTZXLEN
72
        ldir                    ; move to common memory
73
        ld hl, INTERPWKSPC
74
        xor a                   ; file type = 0 (BASIC)
75
        call F_tbas_loader      ; Try to load the file
76 380 winston
        jr c, .err1             ; leave here if the loader had an error
77 341 winston
 
78
        ld hl, (ZX_NEWPPC)      ; get the value of NEWPPC
79
        ld a, h                 ; Is NEWPPC unset?
80
        or l
81 380 winston
        jr z, .leave1
82 341 winston
 
83
        ld (ZX_OLDPPC), hl      ; Put in OLDPPC so 'CONTINUE' jumps
84
        ld a, 0xE8              ; keyword 'CONTINUE'
85
        rst CALLBAS
86
        defw 0x0F81             ; ADD-CHAR
87 380 winston
        ld a, NEWLINE
88 341 winston
        rst CALLBAS
89
        defw 0x0F81
90 380 winston
.leave1:
91 341 winston
        pop hl                  ; get NMI stack pointer
92
        ld sp, hl               ; and restore it
93
        ret
94 380 winston
.err1:
95 341 winston
        pop hl                  ; get NMI stack pointer
96
        pop de                  ; now restore return address
97
        ld de, 0x1299
98
        push de
99
        ld sp, hl               ; and restore it
100
        ld hl, STR_loaderr      ; or print an error message
101
        call PRINT42
102
        ret
103 365 winston
 
104
;--------------------------------------------------------------------------
105
; F_shouldboot: See if we should boot (either configured to do so or
106
; SHIFT is pressed down) Zero flag is set if we should boot, non zero
107
; return if not.
108 380 winston
.globl F_shouldboot
109
F_shouldboot:
110 365 winston
        ld de, ROM_ID           ; section ID
111
        ld hl, CFG_FINDSECTION  ; go and find it
112
        rst MODULECALL_NOPAGE
113 380 winston
        jr c, .bootonshift2     ; we don't have a section, jump forward.
114 365 winston
 
115
        ld a, AUTOBOOT          ; get 'autoboot' option
116
        ld hl, CFG_GETCFBYTE
117
        rst MODULECALL_NOPAGE
118 380 winston
        jr c, .bootonshift2     ; not found, take no action
119 365 winston
        and a                   ; if set to zero, then don't autoboot
120 380 winston
        jr z, .bootonshift2
121 365 winston
        xor a                   ; set the zero flag to signal 'boot'
122
        ret
123
 
124 380 winston
.bootonshift2:
125 365 winston
        ld bc, 0xFEFE           ; read SHIFT through V
126
        in a, (c)
127
        cp 0xBE                 ; SHIFT pressed?
128
        ret
129 380 winston
 
130
.data
131
STR_bootmsg:    defb "Booting...",NEWLINE,0
132
STR_loaderr:    defb "Error loading boot.zx",NEWLINE,0
133 341 winston