Subversion Repositories Spectranet

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

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