Subversion Repositories Spectranet

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 97 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 383 winston
.include        "spectranet.inc"
23
.include        "sysvars.inc"
24
.include        "ctrlchars.inc"
25 384 winston
.include        "sockdefs.inc"
26 97 winston
 
27
; Utility ROM - NMI handler
28 383 winston
.text
29
.globl F_nmihandler
30
F_nmihandler:
31 97 winston
        call F_savescreen       ; save frame buffer contents
32 301 winston
        call F_detectpages      ; Detect 128K mode and value of port 0x7ffd
33 265 winston
        ld a, (v_machinetype)
34
        cp 1                    ; 128K machine?
35 383 winston
        jr nz, .menuloop1       ; If not, continue
36 265 winston
        ld a, (v_port7ffd)      ; If so, make sure the normal screen
37
        res 3, a                ; is in use.
38
        ld bc, 0x7ffd
39
        out (c), a
40 383 winston
.menuloop1:
41 268 winston
        ld a, 7
42
        out (254), a            ; border = white
43 117 winston
        call CLEAR42
44
        ld hl, STR_nmimenu      ; title
45
        call PRINT42
46
        ld hl, MENU_nmi         ; generate the menu
47
        call F_genmenu
48
        ld hl, MENU_nmi
49
        call F_getmenuopt       ; act on user keypress
50 383 winston
        jr nz, .menuloop1       ; routines set Z if they want to exit
51 265 winston
 
52 97 winston
        call F_restorescreen
53 265 winston
        ld a, (v_port7ffd)      ; Restore port 0x7FFD
54
        ld bc, 0x7ffd
55
        out (c), a
56 268 winston
        ld a, (v_border)        ; Restore the border colour
57
        out (254), a
58 97 winston
        ret
59
 
60 117 winston
 
61 97 winston
;-------------------------------------------------------------------------
62
; F_savescreen
63
; Save the current Spectrum frame buffer into our static memory.
64 383 winston
.globl F_savescreen
65
F_savescreen:
66 270 winston
        ld bc, CTRLREG          ; save border colour
67
        in a, (c)
68
        and 7
69
        ld (v_border), a
70
 
71 177 winston
        ld a, 0xDA              ; Use pages 0xDA, 0xDB of RAM
72 97 winston
        call SETPAGEA
73
        ld hl, 0x4000           ; Spectrum screen buffer
74
        ld de, 0x1000           ; Page area A
75
        ld bc, 0x1000           ; 4K
76
        ldir
77 177 winston
        ld a, 0xDB
78 97 winston
        call SETPAGEA
79
        ld hl, 0x5000
80
        ld de, 0x1000
81
        ld bc, 0xB00            ; Remainder of screen, including attrs.
82
        ldir
83
        ret
84
 
85
;---------------------------------------------------------------------------
86
; F_restorescreen
87
; Restore the Spectrum framebuffer.
88 383 winston
.globl F_restorescreen
89
F_restorescreen:
90 177 winston
        ld a, 0xDA
91 97 winston
        call SETPAGEA
92
        ld hl, 0x1000
93
        ld de, 0x4000
94
        ld bc, 0x1000
95
        ldir
96 177 winston
        ld a, 0xDB
97 97 winston
        call SETPAGEA
98
        ld hl, 0x1000
99
        ld de, 0x5000
100
        ld bc, 0xB00
101
        ldir
102
        ret
103
 
104 117 winston
;---------------------------------------------------------------------
105
; F_config
106
; Invokes the configuration program
107 383 winston
.globl F_config
108
F_config:
109 288 winston
        ld hl, 0xFE00           ; module FE (configuration) call 0x00
110
        rst MODULECALL_NOPAGE
111 117 winston
        ret
112 97 winston
 
113 117 winston
;-----------------------------------------------------------------------
114 169 winston
; F_rom
115
; Invokes the ROM module utility. This is stored in page 0x01 of flash
116
; as a binary object.
117 383 winston
.globl F_rom
118
F_rom:
119 169 winston
        ld a, 0x01
120
        call SETPAGEA           ; this utility's executable code is in the
121
        ld hl, ROMMODCONF_START ; data ROM, so page it in and copy it from
122
        ld de, 0x3000           ; 0x1000 to 0x3000.
123 383 winston
        ld bc, ROMMODCONF_LEN
124 169 winston
        ldir
125
        call 0x3000             ; call it
126
        or 1                    ; reset Z
127
        ret
128
 
129 383 winston
.data
130
ROMMODCONF_START:
131
.incbin "modman.bin"
132
ROMMODCONF_LEN  equ $-ROMMODCONF_START
133
 
134
.text
135 169 winston
;-----------------------------------------------------------------------
136 117 winston
; F_loader
137
; Loads some data into RAM.
138 383 winston
.globl F_loader
139
F_loader:
140 117 winston
        call CLEAR42
141
 
142
        ld c, SOCK_STREAM       ; open a TCP socket
143
        call SOCKET             ; file descriptor in A
144 383 winston
        jp c, .borked6          ; or c set if failed
145 117 winston
        ld (v_sockfd), a        ; save the fd
146
 
147
        ld de, 2000             ; port 2000
148
        call BIND               ; bind to the port
149 383 winston
        jp c, .borked6
150 117 winston
 
151
        ld a, (v_sockfd)        ; socket we want to listen on
152
        call LISTEN             ; listen
153 383 winston
        jr c, .borked6
154 117 winston
 
155
        ; Display an informative message to the user showing the
156
        ; IP and port we are listening on.
157
        ld hl, STR_send
158
        call PRINT42
159
        ld de, buf_workspace    ; where to deposit our IP address
160
        call GET_IFCONFIG_INET
161
        ld hl, buf_workspace
162
        ld de, buf_workspace+4
163
        call LONG2IPSTRING
164
        ld hl, buf_workspace+4
165
        call PRINT42
166
        ld hl, STR_port
167
        call PRINT42
168
 
169
        ; Wait for a connection.
170
        ld a, (v_sockfd)
171
        call ACCEPT             ; block until something connects
172 383 winston
        jr c, .borked6
173 117 winston
        ld (v_connfd), a        ; save the connection file descriptor
174
 
175
        ; Get the first 4 bytes which contains the start address and
176
        ; data length.
177
        ld de, buf_workspace    ; where to store
178
        ld bc, 4                ; how many bytes
179
        call RECV               ; block till we get them
180
        call F_printxfinfo      ; print information about the data
181
 
182
        ; Receive the data.
183
        ld de, (buf_workspace)  ; current address to write to
184 383 winston
.recvloop6:
185 117 winston
        ld a, (v_connfd)
186
        ld bc, 1024             ; receive up to 1K at a time
187
        call RECV
188 383 winston
        jr c, .borked6
189 117 winston
        ld hl, (buf_workspace+2) ; get remaining length
190
        sbc hl, bc
191
        ld a, h                 ; are we done yet?
192
        or l
193 383 winston
        jr z, .recvdone6
194 117 winston
        ld (buf_workspace+2), hl ; save remaining length
195
        ld hl, (buf_workspace)  ; get current pointer
196
        add hl, bc              ; increment it
197
        ld (buf_workspace), hl  ; save it
198
        ex de, hl
199
        ld a, '.'               ; progress marker
200
        call PUTCHAR42
201 383 winston
        jr .recvloop6           ; get the next block
202
.recvdone6:
203 117 winston
        ld a, (v_connfd)        ; close the connection
204
        call CLOSE
205
        ld a, (v_sockfd)
206
        call CLOSE
207 383 winston
.keymsg6:
208 117 winston
        ld hl, STR_xtoexit
209
        call PRINT42
210 383 winston
.waitforkey6:                   ; wait for a key so the user has a chance
211 117 winston
        call GETKEY             ; to see what happened.
212
        cp 'x'                  ; press 'x' to exit
213 383 winston
        jr nz, .waitforkey6
214 117 winston
        or 1                    ; ensure zero flag is cleared
215
        ret
216 383 winston
.borked6:
217 117 winston
        ld hl, buf_workspace
218
        call ITOH8
219
        ld hl, STR_borked
220
        call PRINT42
221
        ld hl, buf_workspace
222
        call PRINT42
223 383 winston
        jr .keymsg6
224 117 winston
 
225
; internal function for the above - print info of what's being tx'd to us.
226 383 winston
.globl F_printxfinfo
227
F_printxfinfo:
228 117 winston
        ld hl, STR_est
229
        call PRINT42
230
        ld hl, STR_start
231
        call PRINT42
232
        ld a, (buf_workspace+1)
233
        ld hl, buf_workspace+4
234
        call ITOH8
235
        ld a, (buf_workspace)
236
        call ITOH8
237
        ld hl, buf_workspace+4
238
        call PRINT42
239 383 winston
        ld a, NEWLINE
240 117 winston
        call PUTCHAR42
241
        ld hl, STR_len
242
        call PRINT42
243
        ld a, (buf_workspace+3)
244
        ld hl, buf_workspace+4
245
        call ITOH8
246
        ld a, (buf_workspace+2)
247
        call ITOH8
248
        ld hl, buf_workspace+4
249
        call PRINT42
250 383 winston
        ld a, NEWLINE
251 117 winston
        call PUTCHAR42
252
        ret
253
 
254 383 winston
.globl F_snapshot
255
F_snapshot:
256 282 winston
        ld hl, 0xFB00           ; ROM ID 0xFB call 0x00
257 255 winston
        rst MODULECALL_NOPAGE
258
        ret
259
 
260 117 winston
;---------------------------------------------------------------------
261
; F_exit
262
; A very short routine for the menu to be able to set the zero flag.
263 383 winston
.globl F_exit
264
F_exit:
265 117 winston
        xor a                   ; set zero flag
266
        ret
267
 
268 383 winston
MENU_nmi:
269 117 winston
        defw    STR_config,F_config
270 169 winston
        defw    STR_rom,F_rom
271 117 winston
        defw    STR_loader,F_loader
272 255 winston
        defw    STR_snapshot,F_snapshot
273 117 winston
        defw    STR_exit,F_exit
274
        defw    0,0
275