Subversion Repositories Spectranet

[/] [trunk/] [rom/] [utilnmi.asm] - Blame information for rev 288

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