Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [snapman/] [inputloop.asm] - Blame information for rev 372

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 278 winston
;The MIT License
2
;
3
;Copyright (c) 2009 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
;------------------------------------------------------------------------
24
; Handle user interaction for the snapshot manager.
25 372 winston
.include        "spectranet.inc"
26
.include        "snapman.inc"
27
.include        "sysvars.inc"
28 278 winston
 
29
; Create the user interface and enter the input loop.
30 372 winston
.globl F_startui
31
F_startui:
32 280 winston
        call F_fetchpage
33
        jp c, F_nopage
34
        call CLEAR42
35
        xor a
36
        ld (v_viewflags), a     ; reset view flags
37
        ld (v_inputflags), a    ; and input flags
38
        call F_makestaticui     ; create the static user interface
39
        call F_printcwd         ; initialize the CWD line
40 284 winston
        call F_printcurfile     ; show the current file
41 280 winston
        call F_loaddir          ; get the contents of the current dir
42
        ld a, (v_numsnas)
43
        ld hl, BOXSTARTADDR
44
        ld bc, BOXDIMENSIONS
45
        ld de, v_snatable       ; start with the snapshot view
46
        call F_makeselection
47 278 winston
 
48 280 winston
;----------------------------------------------------------------------
49
; Main UI loop
50 372 winston
.globl F_mainloop
51
F_mainloop:
52 278 winston
        call F_inputloop        ; call UI control input loop, wait for a key
53
        ld b, a                 ; save the keypress in B
54
        ld c, 0                 ; use C as a counter
55
        ld hl, INPUTTABLE
56 372 winston
.getactionloop2:
57 278 winston
        ld a, (hl)
58
        and a                   ; check for "end of list"
59
        jr z, F_mainloop        ; invalid key, ignore it
60
        cp b                    ; See if the key press is recognised.
61 372 winston
        jr z,  .handlekey2
62 278 winston
        inc c                   ; inc. counter
63 280 winston
        inc hl
64 372 winston
        jr  .getactionloop2
65
.handlekey2:
66 278 winston
        rlc c                   ; double the counter to form the offset
67
        ld b, 0                 ; in BC
68
        ld hl, INPUTADDRS       ; Calculate the address of the address
69
        add hl, bc              ; that we need to find
70
        ld e, (hl)              ; and get its LSB
71
        inc hl
72
        ld d, (hl)              ; and MSB
73
        ex de, hl               ; put it in hl
74 372 winston
        ld de,  .return2
75 278 winston
        push de                 ; effectively, we want to CALL (HL)
76
        jp (hl)
77 372 winston
.return2:
78 278 winston
        ld a, (v_inputflags)
79
        bit 0, a                ; signal to leave?
80
        jr z, F_mainloop        ; ...no, so continue
81
        res 0, a
82
        ld (v_inputflags), a    ; reset the flag
83 280 winston
        jp F_leave              ; restore memory and leave
84 278 winston
 
85
;------------------------------------------------------------------------
86
; F_exit
87
; Leave the main input loop, by setting the 'done' flag.
88 372 winston
.globl F_exit
89
F_exit:
90 278 winston
        ld a, (v_inputflags)
91
        set 0, a
92
        ld (v_inputflags), a
93
        ret
94
 
95
;------------------------------------------------------------------------
96 280 winston
; F_enterpressed
97 372 winston
.globl F_enterpressed
98
F_enterpressed:
99 280 winston
        call F_getselected
100 281 winston
        ret z                   ; nothing to do - no entries
101 280 winston
        ld a, (v_viewflags)
102
        and 1                   ; bit 1 set - directory mode
103 372 winston
        jr z,  .loadsnap4
104 280 winston
        ld de, WORKSPACE        ; copy directory name to where the
105
        call F_strcpy           ; FS module will be able to see it
106
        ld hl, WORKSPACE
107
        call CHDIR
108
        jp c, F_error
109
        call F_printcwd
110
        call F_loaddir
111
        ld hl, BOXSTARTADDR     ; start address of the box
112
        ld bc, BOXDIMENSIONS    ; box dimensions
113
        ld de, v_dirtable
114
        ld a, (v_numdirs)
115
        jp F_makeselection      ; make the selection and return.
116 372 winston
.loadsnap4:
117 280 winston
        ld de, WORKSPACE
118
        push hl
119
        call F_strcpy           ; copy the filename into common workspace
120
        pop hl
121
        ld de, v_curfilename    ; copy the filename to our "current file"
122
        call F_strcpy
123
        ld hl, WORKSPACE        ; filename pointed to by HL
124
        call F_loadsnap         ; load the snapshot
125 372 winston
.globl F_error
126
F_error:                        ; ends up here if there is an error
127 280 winston
        ld a, 2
128
        out (254), a
129
        ret
130
 
131
;------------------------------------------------------------------------
132
; F_saveas
133 372 winston
.globl F_saveas
134
F_saveas:
135 280 winston
        ld hl, STR_filename
136
        ld de, v_strbuf
137
        ld c, FNAMESZ
138
        call F_userinput
139
        ret z                   ; nothing entered, continue
140
 
141
        ld de, v_curfilename    ; copy the string entered to the current
142
        ld hl, v_strbuf
143
        call F_strcpy           ; filename.
144
        ld hl, v_strbuf
145 372 winston
.globl F_saveas2
146
F_saveas2:
147 280 winston
        ld de, WORKSPACE        ; and copy it to the workspace
148
        call F_strcpy           ; so the FS module can see it too
149
        ld hl, WORKSPACE
150
        call F_savesna
151
        jp c, F_error
152 284 winston
        call F_printcurfile
153 280 winston
 
154
        ret
155
 
156
;------------------------------------------------------------------------
157
; F_save
158 372 winston
.globl F_save
159
F_save:
160 280 winston
        ld a, (v_viewflags)     ; directory view or file view?
161
        and 1
162 372 winston
        jr nz,  .needfilename8
163 280 winston
        call F_getselected
164
        jr z, F_saveas
165
        ld (v_hlsave), hl       ; save the pointer but don't disturb stack
166
        ld de, v_curfilename
167
        call F_strcmp           ; selected = current?
168 372 winston
        jr nz,  .confirm8
169
.save8:
170 280 winston
        ld hl, (v_hlsave)
171
        jp F_saveas2
172 372 winston
.confirm8:
173 280 winston
        ld hl, STR_cfoverwrite
174
        ld de, v_strbuf
175
        ld c, 2
176
        call F_userinput
177
        ret z                   ; nothing entered, nothing to do
178
        ld a, (v_strbuf)
179
        cp CHAR_YES
180
        ret nz                  ; user didn't answer "yes"
181
        ld hl, (v_hlsave)
182
        ld de, v_curfilename
183
        call F_strcpy           ; set this as the current file
184 372 winston
        jr  .save8
185
.needfilename8:
186 280 winston
        ld a, (v_curfilename)   ; Already have a filename?
187
        and a                   ; if zero, no
188
        jr z, F_saveas
189
 
190
;------------------------------------------------------------------------
191 278 winston
; F_userinput
192
; HL = pointer to prompt string
193
; DE = pointer to buffer in which to return the data
194
;  C = size of input buffer
195 372 winston
.globl F_userinput
196
F_userinput:
197 278 winston
        push bc
198
        push hl
199
        ld bc, 0x1600           ; line 24, col 0
200
        call F_printat          ; HL now is the address of the line
201
        pop hl                  ; prompt to print
202
        call PRINT42
203
        pop bc
204
        push de                 ; save buffer address
205
        call INPUTSTRING
206
        ld bc, 0x1600           ; set the position again...
207
        call F_printat
208
        ld bc, 32
209
        call F_clearline2       ; ...to clear the line
210
        pop hl
211
        ld a, (hl)
212
        and a                   ; return with Z set if nothing entered
213
        ret
214
 
215
;----------------------------------------------------------------------
216 287 winston
; F_rename
217
; Renames a snapshot file.
218 372 winston
.globl F_rename
219
F_rename:
220 287 winston
        ld a, (v_viewflags)     ; check we are in snapshot view
221
        rra                     ; if LSB = 1 we are in directory view
222
        ret c                   ; so leave.
223
 
224
        call F_getselected
225
        ret z                   ; nothing to do - no entries
226
        ld de, WORKSPACE+0x100
227
        call F_strcpy           ; copy the selected name to workspace
228
        ld hl, WORKSPACE
229
        ld de, v_curfilename
230
        call F_strcpy           ; copy to current filename so we can
231
        call F_printcurfile     ; update the "current file" UI
232
 
233
        ld hl, STR_newname
234
        ld de, WORKSPACE
235
        ld c, 0x10              ; max filename size
236
        call F_userinput        ; Prompt for the new name
237
        ld a, (WORKSPACE)
238
        and a
239
        ret z                   ; no filename entered
240
 
241
        ld hl, WORKSPACE        ; copy the filename
242
        ld de, v_curfilename    ; to the "current selected" filename
243
        call F_strcpy
244
 
245
        ld hl, WORKSPACE+0x100  ; source filename
246
        ld de, WORKSPACE        ; destination
247
        call RENAME
248
        jp c, F_error
249
 
250
        call F_loaddir          ; Update the directory listing
251
        call F_printcurfile     ; show the current file
252
        jp F_snapview           ; and update the window
253
 
254
;----------------------------------------------------------------------
255
; F_erase
256
; Erases a snapshot file.
257 372 winston
.globl F_erase
258
F_erase:
259 287 winston
        ld a, (v_viewflags)     ; check we are in snapshot view
260
        rra                     ; if LSB = 1 we are in directory view
261
        ret c                   ; so leave.
262
 
263
        call F_getselected
264
        ret z                   ; nothing to do - no entries
265
 
266
        ld de, WORKSPACE
267
        call F_strcpy           ; copy the filename into workspace
268
        ld hl, WORKSPACE
269
        ld de, v_curfilename    ; copy the filename into the current file
270
        call F_strcpy
271
        call F_printcurfile     ; update the current filename
272
 
273
        ld hl, STR_cferase
274
        ld de, v_strbuf
275
        ld c, 2
276
        call F_userinput
277
        ret z                   ; nothing entered, nothing to do
278
        ld a, (v_strbuf)
279
        cp CHAR_YES
280
        ret nz                  ; user didn't answer "yes"
281
 
282
        ld hl, WORKSPACE
283
        call UNLINK             ; erase the file
284
        jp c, F_error
285
        xor a
286
        ld (v_curfilename), a   ; clear the current filename
287
        call F_loaddir          ; reload the dir
288
        call F_printcurfile
289
        jp F_snapview           ; update the UI
290
 
291
;----------------------------------------------------------------------
292 278 winston
; F_switchdirview
293
; Switch between directory and file views.
294 372 winston
.globl F_switchdirview
295
F_switchdirview:
296 278 winston
        ld a, (v_viewflags)
297
        xor 1                   ; flip "dir view" bit
298
        ld (v_viewflags), a     ; and save
299
        rra                     ; push lsb into the carry flag
300 287 winston
        jr c, showdir           ; switch from file to dir view
301 372 winston
.globl F_snapview
302
F_snapview:
303 280 winston
        ld de, v_snatable
304
        ld a, (v_numsnas)
305 372 winston
makesel:
306 280 winston
        ld hl, BOXSTARTADDR     ; start address of the box
307
        ld bc, BOXDIMENSIONS    ; box dimensions
308 278 winston
        jp F_makeselection      ; make the selection and return.
309 372 winston
showdir:
310 278 winston
        ld de, v_dirtable
311 280 winston
        ld a, (v_numdirs)
312 287 winston
        jr makesel
313 280 winston
 
314
; We end up here if the allocated page wasn't found.
315 372 winston
.globl F_nopage
316
F_nopage:
317 280 winston
        ld hl, STR_nomempage
318
        call PRINT42
319
        ret
320
 
321 278 winston