Subversion Repositories Spectranet

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

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 113 winston
        ld a, 0xC1              ; page 1 of Spectranet memory
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 113 winston
        ld a, 0xC2
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 113 winston
        ld a, 0xC1
62 97 winston
        call SETPAGEA
63
        ld hl, 0x1000
64
        ld de, 0x4000
65
        ld bc, 0x1000
66
        ldir
67 113 winston
        ld a, 0xC2
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
; F_loader
90
; Loads some data into RAM.
91
F_loader
92
        call CLEAR42
93
 
94
        ld c, SOCK_STREAM       ; open a TCP socket
95
        call SOCKET             ; file descriptor in A
96
        jp c, .borked           ; or c set if failed
97
        ld (v_sockfd), a        ; save the fd
98
 
99
        ld de, 2000             ; port 2000
100
        call BIND               ; bind to the port
101
        jp c, .borked
102
 
103
        ld a, (v_sockfd)        ; socket we want to listen on
104
        call LISTEN             ; listen
105
        jr c, .borked
106
 
107
        ; Display an informative message to the user showing the
108
        ; IP and port we are listening on.
109
        ld hl, STR_send
110
        call PRINT42
111
        ld de, buf_workspace    ; where to deposit our IP address
112
        call GET_IFCONFIG_INET
113
        ld hl, buf_workspace
114
        ld de, buf_workspace+4
115
        call LONG2IPSTRING
116
        ld hl, buf_workspace+4
117
        call PRINT42
118
        ld hl, STR_port
119
        call PRINT42
120
 
121
        ; Wait for a connection.
122
        ld a, (v_sockfd)
123
        call ACCEPT             ; block until something connects
124
        jr c, .borked
125
        ld (v_connfd), a        ; save the connection file descriptor
126
 
127
        ; Get the first 4 bytes which contains the start address and
128
        ; data length.
129
        ld de, buf_workspace    ; where to store
130
        ld bc, 4                ; how many bytes
131
        call RECV               ; block till we get them
132
        call F_printxfinfo      ; print information about the data
133
 
134
        ; Receive the data.
135
        ld de, (buf_workspace)  ; current address to write to
136
.recvloop
137
        ld a, (v_connfd)
138
        ld bc, 1024             ; receive up to 1K at a time
139
        call RECV
140
        jr c, .borked
141
        ld hl, (buf_workspace+2) ; get remaining length
142
        sbc hl, bc
143
        ld a, h                 ; are we done yet?
144
        or l
145
        jr z, .recvdone
146
        ld (buf_workspace+2), hl ; save remaining length
147
        ld hl, (buf_workspace)  ; get current pointer
148
        add hl, bc              ; increment it
149
        ld (buf_workspace), hl  ; save it
150
        ex de, hl
151
        ld a, '.'               ; progress marker
152
        call PUTCHAR42
153
        jr .recvloop            ; get the next block
154
.recvdone
155
        ld a, (v_connfd)        ; close the connection
156
        call CLOSE
157
        ld a, (v_sockfd)
158
        call CLOSE
159
.keymsg
160
        ld hl, STR_xtoexit
161
        call PRINT42
162
.waitforkey                     ; wait for a key so the user has a chance
163
        call GETKEY             ; to see what happened.
164
        cp 'x'                  ; press 'x' to exit
165
        jr nz, .waitforkey
166
        or 1                    ; ensure zero flag is cleared
167
        ret
168
.borked
169
        ld hl, buf_workspace
170
        call ITOH8
171
        ld hl, STR_borked
172
        call PRINT42
173
        ld hl, buf_workspace
174
        call PRINT42
175
        jr .keymsg
176
 
177
; internal function for the above - print info of what's being tx'd to us.
178
F_printxfinfo
179
        ld hl, STR_est
180
        call PRINT42
181
        ld hl, STR_start
182
        call PRINT42
183
        ld a, (buf_workspace+1)
184
        ld hl, buf_workspace+4
185
        call ITOH8
186
        ld a, (buf_workspace)
187
        call ITOH8
188
        ld hl, buf_workspace+4
189
        call PRINT42
190
        ld a, '\n'
191
        call PUTCHAR42
192
        ld hl, STR_len
193
        call PRINT42
194
        ld a, (buf_workspace+3)
195
        ld hl, buf_workspace+4
196
        call ITOH8
197
        ld a, (buf_workspace+2)
198
        call ITOH8
199
        ld hl, buf_workspace+4
200
        call PRINT42
201
        ld a, '\n'
202
        call PUTCHAR42
203
        ret
204
 
205
;---------------------------------------------------------------------
206
; F_exit
207
; A very short routine for the menu to be able to set the zero flag.
208
F_exit
209
        xor a                   ; set zero flag
210
        ret
211
 
212
MENU_nmi
213
        defw    STR_config,F_config
214
        defw    STR_loader,F_loader
215
        defw    STR_exit,F_exit
216
        defw    0,0
217
 
218
STR_config      defb "Configure network settings",0
219
STR_loader      defb "Load arbitrary data to RAM",0
220
STR_exit        defb "Exit",0
221
STR_nmimenu     defb "Spectranet NMI menu\n\n",0
222
STR_send        defb "Listening on ",0
223
STR_port        defb " port 2000\n",0
224
STR_start       defb " Start: ",0
225
STR_len         defb "Length: ",0
226
STR_xtoexit     defb "\nPress 'x' to exit.\n",0
227
STR_borked      defb "\nOperation failed with rc=",0
228
STR_est         defb "Connection established\n",0
229