Subversion Repositories Spectranet

[/] [branches/] [gnubinutils/] [modules/] [basext/] [info.asm] - Blame information for rev 380

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