Subversion Repositories Spectranet

[/] [trunk/] [modules/] [basext/] [info.asm] - Blame information for rev 442

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

Line No. Rev Author Line
1 225 winston
;The MIT License
2
;
3
;Copyright (c) 2009 Dylan Smith, except 32 bit divide routine by Baze
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
; Routines for the %info command.
24 399 winston
.include        "defs.inc"
25
.include        "zxrom.inc"
26
.include        "spectranet.inc"
27
.include        "fcntl.inc"
28
.include        "sysvars.inc"
29 442 winston
.include        "errno.inc"
30 399 winston
.text
31 225 winston
;---------------------------------------------------------------------------
32
; F_showfileinfo
33
; Shows information on a file.
34 399 winston
.globl F_showfileinfo
35
F_showfileinfo:
36 225 winston
        ld hl, INTERPWKSPC
37
        call F_basstrcpy        ; prepare BASIC string for use
38
 
39
        ld hl, INTERPWKSPC
40
        ld de, INTERPWKSPC+256  ; where to return the data
41
        call STAT
42
        ret c                   ; return on error
43
 
44
        ld a, (INTERPWKSPC+256+1) ; get file type flags
45
        bit 7, a                ; test for regular file
46 399 winston
        jr nz, .rfinfo1
47 225 winston
 
48
        bit 6, a                ; test for directory
49 399 winston
        jp nz, .dirinfo1
50 225 winston
 
51 399 winston
        ld a, 0x26              ; Unknown file type - TODO - errno.asm1
52 225 winston
        scf
53
        ret
54
 
55 399 winston
.rfinfo1:
56 225 winston
        ld a, 2
57
        rst CALLBAS
58
        defw 0x1601             ; set channel
59
 
60
        ld hl, STR_size
61
        call F_tbas_zxprint     ; print the file size
62
 
63
        ld de, (INTERPWKSPC+256+8)      ; MSW of file size
64
        ld hl, (INTERPWKSPC+256+6)      ; LSW of file size
65
        call F_print32
66
 
67
        ld hl, STR_bytes
68
        call F_tbas_zxprint
69
 
70
        call F_lf
71
 
72
        ; Now see if it's a TAP file, in which case more information
73
        ; can be given. This means opening and reading the file.
74
        ld hl, INTERPWKSPC      ; filename
75
        ld d, 0x00              ; flags
76
        ld e, O_RDONLY          ; read only
77
        call OPEN
78
        ret c                   ; failed top open the file!
79 235 winston
        ld (v_vfs_curfd), a     ; save the FD
80 225 winston
 
81 399 winston
.gethdrinfo1:
82 225 winston
        ld de, INTERPWKSPC      ; we no longer need the filename
83
        call F_tbas_getheader
84 399 winston
        jr c, .nottap1          ; Not a TAP file (or an error)
85
        call .hdrinfo1
86 225 winston
 
87
        ; At this point we list any remaining blocks, some of which may
88
        ; lack normal headers, so we have to do it in a new block of code.
89
        ; Seek forward past the data block and try to analyze the rest
90
        ; of the TAP file.
91 399 winston
.getblocks1:
92 225 winston
        ld de, INTERPWKSPC
93
        ld bc, 2                ; read the length value
94 235 winston
        ld a, (v_vfs_curfd)
95 225 winston
        call READ
96 399 winston
        jr c, .cleanuperr1      ; shouldn't die here.
97 225 winston
 
98
        ld hl, (INTERPWKSPC)    ; get the length of the block
99 399 winston
.seeknextblock1:
100 225 winston
        ld de, 0                ; and make dehl = 32 bit version of it
101 235 winston
        ld a, (v_vfs_curfd)
102 225 winston
        ld c, SEEK_CUR          ; and seek forwards that many bytes
103
        call LSEEK
104 399 winston
        jr c, .cleanuperr1
105 225 winston
 
106
        ld de, INTERPWKSPC      ; see if we've got another header
107
        call F_tbas_getheader
108 399 winston
        jr nc, .disphdr1
109 225 winston
        cp TBADLENGTH
110 399 winston
        jr z, .dispnonhdr1      ; suspected headerless block
111 225 winston
        cp TBADTYPE
112 399 winston
        jr z, .dispnonhdr1
113 225 winston
        cp EOF                  ; reached end of file?
114 399 winston
        jr z, .done1
115
.disphdr1:
116
        call .hdrinfo1          ; show the header information
117
        jr .getblocks1
118 225 winston
 
119 399 winston
.dispnonhdr1:
120 225 winston
        ld hl, STR_headerless   ; print "Headerless block"
121
        call F_tbas_zxprint
122
        ld de, 0                ; most significant word is always 0
123
        ld hl, (INTERPWKSPC)
124
        dec hl                  ; Remove the 2 byte block type and check
125
        dec hl                  ; byte from the length to display
126
        call F_print32
127
        ld hl, STR_bytes
128
        call F_tbas_zxprint
129
        call F_lf
130
        ld hl, (INTERPWKSPC)
131
        ld de, TNFS_HDR_LEN-2   ; already read this much, subtract from
132
        sbc hl, de              ; the block size. TODO: block sizes
133 399 winston
        jr .seeknextblock1      ; smaller than a standard header!
134 225 winston
 
135 399 winston
.done1:
136 235 winston
        ld a, (v_vfs_curfd)
137 290 winston
        call VCLOSE
138 225 winston
        ret
139 399 winston
.nottap1:
140 225 winston
        cp TBADLENGTH
141 399 winston
        jr z, .data1
142 225 winston
        cp TBADTYPE
143 399 winston
        jr z, .data1
144
.cleanuperr1:
145 225 winston
        push af                 ; store original error
146 235 winston
        ld a, (v_vfs_curfd)
147 225 winston
        call CLOSE
148
        pop af
149
        ret
150 399 winston
.data1:
151 225 winston
        ld hl, STR_data
152
        call F_tbas_zxprint
153
        call F_lf
154 399 winston
        jr .done1
155 225 winston
 
156 399 winston
.dirinfo1:
157 225 winston
        ld a, 2
158
        rst CALLBAS
159
        defw 0x1601             ; set channel
160
 
161
        ld hl, STR_directory
162
        call F_tbas_zxprint     ; print the word "Directory"
163
 
164
        ld de, (INTERPWKSPC+256+8)      ; MSW of file size
165
        ld hl, (INTERPWKSPC+256+6)      ; LSW of file size
166
        call F_print32
167
 
168
        ld hl, STR_bytes
169
        call F_tbas_zxprint
170
 
171
        call F_lf
172
        ret
173
 
174
        ; A should be the block type as returned by getheader
175 399 winston
.hdrinfo1:
176 225 winston
        and a
177 399 winston
        jr z, .program1
178 225 winston
        cp 1
179 399 winston
        jr z, .numarray1
180 225 winston
        cp 2
181 399 winston
        jr z, .strarray1
182 225 winston
        cp 3
183 399 winston
        jr z, .code1
184 225 winston
        ld hl, STR_unknown
185
        call F_tbas_zxprint
186 399 winston
.continue1:
187 225 winston
        ld hl, INTERPWKSPC+4    ; Filename in the TAP block
188
        ld b, 10
189 399 winston
.fnloop1:                               ; Print the filename of this TAP block
190 225 winston
        ld a, (hl)
191
        rst CALLBAS
192
        defw 16
193
        inc hl
194 399 winston
        djnz .fnloop1
195 225 winston
        call F_lf
196
 
197
        ld hl, STR_blksize
198
        call F_tbas_zxprint
199
        ld de, 0
200
        ld hl, (INTERPWKSPC+14)
201
        call F_print32          ; Display the size
202
        call F_lf
203
 
204
        ld hl, STR_param1
205
        call F_tbas_zxprint
206
        ld de, 0
207
        ld hl, (INTERPWKSPC+16)
208
        call F_print32          ; Display parameter 1 value
209
        call F_lf
210
 
211
        ld hl, STR_param2
212
        call F_tbas_zxprint
213
        ld de, 0
214
        ld hl, (INTERPWKSPC+18)
215
        call F_print32          ; Display parameter 2 value
216
        call F_lf
217
        ret
218
 
219 399 winston
.program1:
220 225 winston
        ld hl, STR_basic
221 399 winston
        jr .pr1
222
.numarray1:
223 225 winston
        ld hl, STR_numarray
224 399 winston
        jr .pr1
225
.strarray1:
226 225 winston
        ld hl, STR_strarray
227 399 winston
        jr .pr1
228
.code1:
229 225 winston
        ld hl, STR_code
230 399 winston
.pr1:
231 225 winston
        call F_tbas_zxprint
232 399 winston
        jr .continue1
233 225 winston
 
234
 
235
; F_lf: Print an "enter"
236 399 winston
.globl F_lf
237
F_lf:
238 225 winston
        ld a, 0x0d
239
        rst CALLBAS
240
        defw 16
241
        ret
242
 
243
;---------------------------------------------------------------------------
244
; F_print32
245
; Converts the 32 bit value in DEHL to ASCII and displays it on the
246
; current ZX channel.
247 399 winston
.globl F_print32
248
F_print32:
249 225 winston
        ld ix, INTERPWKSPC+512
250
        ld (ix), 0
251 399 winston
.divloop3:
252 225 winston
        inc ix
253
        ld c, 10
254
        call F_div32
255
        add a, '0'              ; convert to ascii
256
        ld (ix), a              ; save it
257
        ld a, h
258
        or l                    ; has DEHL reached 0?
259
        or d
260
        or e
261 399 winston
        jr nz, .divloop3
262
.loop3:
263 225 winston
        ld a, (ix)
264
        and a
265
        ret z
266
        rst CALLBAS
267
        defw 16
268
        dec ix
269 399 winston
        jr .loop3
270 225 winston
 
271
; Modified version of baze's 32 bit divide routine
272 399 winston
.globl F_div32
273
F_div32:
274 225 winston
        xor a
275
        ld b, 32
276 399 winston
.loop4:
277 225 winston
        add hl,hl
278
        rl e
279
        rl d
280
        rla
281
        cp c
282
        jr c,$+4
283
        sub c
284
        inc l
285 399 winston
        djnz .loop4
286 225 winston
        ret
287