File: import.lst

package info (click to toggle)
xtrs 4.9-5
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 2,164 kB
  • ctags: 1,433
  • sloc: ansic: 19,840; makefile: 242; csh: 132; sh: 129
file content (449 lines) | stat: -rw-r--r-- 17,527 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
   1:			;; import.z
   2:			;; Timothy Mann, 8/24/97
   3:			;; Last modified on Sat Mar 25 21:35:11 PST 2000 by mann
   4:			;;
   5:			;; Use xtrs 1.9 emulator traps to copy a file from Unix to TRS-80
   6:			;; Usage: IMPORT [-ln] unixfile [tofile]
   7:			;; Parameter -l will convert the Unix file to lower case.
   8:			;;  (Needed for NEWDOS/80.  They insist on uppercasing the
   9:			;;  command line.)
  10:			;; If the -n parameter is given, each newline ('\n') in the Unix
  11:			;;  file is converted to a carriage return ('\r'), the TRS-80 end of
  12:			;;  line character.
  13:			;; If the tofile parameter is omitted, the last component of the
  14:			;;  Unix pathname is used, with '.' changed to '/'.  If this is
  15:			;;  not a legal TRS-80 filename, you get an error message.
  16:			
  17:			;; Model I/III addresses
  18:	441C          	@fspec  equ 441ch
  19:	4420          	@init   equ 4420h
  20:	4424          	@open   equ 4424h
  21:	4428          	@close  equ 4428h
  22:	4436          	@read   equ 4436h
  23:	4439          	@write  equ 4439h
  24:	4409          	@error  equ 4409h
  25:	402D          	@exit   equ 402dh
  26:	4030          	@abort  equ 4030h       
  27:	001B          	@put	equ 001bh
  28:	401D          	dodcb$	equ 401dh
  29:			
  30:			;; Model 4 SVCs
  31:	0028          	@svc	equ 40  ; rst address for SVCs
  32:			;@svc	equ 5   ; older zmac requires 8080-style "rst 5"
  33:	004E          	@fspec6	equ 78
  34:	003A          	@init6	equ 58
  35:	003B          	@open6	equ 59
  36:	003C          	@close6	equ 60
  37:	0043          	@read6	equ 67
  38:	004B          	@write6	equ 75
  39:	001A          	@error6	equ 26
  40:	0016          	@exit6	equ 22
  41:	0015          	@abort6	equ 21
  42:	000A          	@dsply6	equ 10
  43:			
  44:			
  45:	5200          		org 5200h
  46:			
  47:			;; Jump tables for OS independence
  48:	5200          	startj:
  49:	5200  CD1C44  	fspec:	call @fspec
  50:	5203  C9      		ret
  51:	5204  CD2044  	init:	call @init
  52:	5207  C9      		ret
  53:	5208  CD2444  	open:	call @open
  54:	520B  C9      		ret
  55:	520C  CD2844  	close:	call @close
  56:	520F  C9      		ret
  57:	5210  CD3644  	reed:	call @read
  58:	5213  C9      		ret
  59:	5214  CD3944  	write:	call @write
  60:	5217  C9      		ret
  61:	5218  CD0944  	error:	call @error
  62:	521B  C9      		ret
  63:	521C  CD2D40  	exit:	call @exit
  64:	521F  C9      		ret
  65:	5220  CD3040  	abort:	call @abort
  66:	5223  C9      		ret
  67:	5224  CD8B53  	dsply:	call dsply5
  68:	5227  C9      		ret
  69:	5228  CDBD53  	setern:	call setern5
  70:	522B  C9      		ret
  71:	522C          	endj:
  72:			
  73:			; Model 4
  74:	522C          	startj6:
  75:	522C  3E4E    		ld a, @fspec6
  76:	522E  EF      		rst @svc
  77:	522F  C9      		ret
  78:	5230  3E3A    		ld a, @init6
  79:	5232  EF      		rst @svc
  80:	5233  C9      		ret
  81:	5234  3E3B    		ld a, @open6
  82:	5236  EF      		rst @svc
  83:	5237  C9      		ret
  84:	5238  3E3C    		ld a, @close6
  85:	523A  EF      		rst @svc
  86:	523B  C9      		ret
  87:	523C  3E43    		ld a, @read6
  88:	523E  EF      		rst @svc
  89:	523F  C9      		ret
  90:	5240  3E4B    		ld a, @write6
  91:	5242  EF      		rst @svc
  92:	5243  C9      		ret
  93:	5244  3E1A    		ld a, @error6
  94:	5246  EF      		rst @svc
  95:	5247  C9      		ret
  96:	5248  3E16    		ld a, @exit6
  97:	524A  EF      		rst @svc
  98:	524B  C9      		ret
  99:	524C  3E15    		ld a, @abort6
 100:	524E  EF      		rst @svc
 101:	524F  C9      		ret
 102:	5250  3E0A    		ld a, @dsply6
 103:	5252  EF      		rst @svc
 104:	5253  C9      		ret
 105:	5254  CDD653  		call setern6
 106:	5257  C9      		ret
 107:			
 108:			; Emulator trap instructions, byte-reversed for use in defw:
 109:	30ED          	emt_open	equ 30edh
 110:	31ED          	emt_close	equ 31edh
 111:	32ED          	emt_read	equ 32edh
 112:	33ED          	emt_write	equ 33edh
 113:	34ED          	emt_lseek	equ 34edh
 114:	35ED          	emt_strerror	equ 35edh
 115:			
 116:	0003          	EO_ACCMODE  equ     3q
 117:	0000          	EO_RDONLY   equ     0q
 118:	0001          	EO_WRONLY   equ     1q
 119:	0002          	EO_RDWR     equ     2q
 120:	0040          	EO_CREAT    equ   100q
 121:	0080          	EO_EXCL     equ   200q
 122:	0200          	EO_TRUNC    equ  1000q
 123:	0400          	EO_APPEND   equ  2000q
 124:			
 125:	2000          	iobsize	equ 8192		; must be divisible by 256
 126:			
 127:	5258          	import: 
 128:	5258  3A0A00  		ld a, (000ah)		; Model 4?
 129:	525B  FE40    		cp 40h
 130:	525D  280D    		jr z, not4
 131:	525F  E5      		push hl
 132:	5260  110052  		ld de, startj
 133:	5263  212C52  		ld hl, startj6
 134:	5266  012C00  		ld bc, endj - startj
 135:	5269  EDB0    		ldir
 136:	526B  E1      		pop hl
 137:	526C          	not4:
 138:			
 139:	526C  7E      	flag0:	ld a, (hl)		; look for flags
 140:	526D  FE20    		cp ' '
 141:	526F  DAF652  		jp c, usage		; error if line ends here
 142:	5272  2003    		jr nz, flag1
 143:	5274  23      		inc hl
 144:	5275  18F5    		jr flag0
 145:	5277  FE2D    	flag1:	cp '-'
 146:	5279  2021    		jr nz, unix1
 147:	527B  23      		inc hl
 148:	527C  7E      		ld a, (hl)
 149:	527D  F620    	flag3:	or 20h
 150:	527F  FE6C    		cp 'l'
 151:	5281  2007    		jr nz, flagn		; check for next flag
 152:	5283  3E01    		ld a, 1
 153:	5285  32DD53  		ld (lflag), a
 154:	5288  1809    		jr flag2
 155:	528A  FE6E    	flagn:	cp 'n'
 156:	528C  2068    		jr nz, usage		; only -n or -N is accepted
 157:	528E  3E01    		ld a, 1
 158:	5290  32DE53  		ld (nflag), a
 159:	5293  23      	flag2:	inc hl
 160:	5294  7E      		ld a, (hl)
 161:	5295  FE20    		cp ' '
 162:	5297  20E4    		jr nz, flag3		; another flag follows
 163:	5299  23      		inc hl
 164:	529A  18D0    		jr flag0
 165:			
 166:	529C  117554  	unix1:	ld de, iobuf		; copy Unix filename
 167:	529F  3E20    		ld a, ' '
 168:	52A1  BE      	unix2:	cp (hl)
 169:	52A2  EDA0    		ldi
 170:	52A4  38FB    		jr c, unix2
 171:	52A6  1B      		dec de			; NUL terminate Unix name
 172:	52A7  3E00    		ld a, 0
 173:	52A9  12      		ld (de), a              
 174:	52AA  2812    		jr z, trs80		; go if two names given
 175:			
 176:			;; Translate last component of Unix name to TRS-80 name			
 177:	52AC  2B      		dec hl			; back up to terminator
 178:	52AD  2B      	unix3:	dec hl			; back up to last byte of name
 179:	52AE  7E      		ld a, (hl)
 180:	52AF  FE2E    		cp '.'			; change '.' to '/'
 181:	52B1  2002    		jr nz, notdot
 182:	52B3  362F    		ld (hl), '/'
 183:	52B5  FE2F    	notdot:	cp '/'
 184:	52B7  2804    		jr z, unix4
 185:	52B9  FE20    		cp ' '
 186:	52BB  20F0    		jr nz, unix3
 187:	52BD  23      	unix4:	inc hl			; point to start of modified last component 
 188:			
 189:	52BE  114554  	trs80:	ld de, dcb              ; ready to get TRS-80 filename from (HL)
 190:	52C1  CD0052  	        call fspec
 191:	52C4  2030    	        jr nz, usage
 192:	52C6  217554  		ld hl, iobuf		; Unix path
 193:	52C9  3ADD53  		ld a, (lflag)
 194:	52CC  B7      		or a
 195:	52CD  C4A053  		call nz, lcconv		; convert path to lower case
 196:	52D0  010000  		ld bc, EO_RDONLY
 197:	52D3  110000  		ld de, 0		; mode (ignored)
 198:	52D6  ED30    		defw emt_open
 199:	52D8  2806    		jr z, openok		; go if OK
 200:	52DA  210554  		ld hl, uopner		; error message and exit
 201:	52DD  C37853  		jp uerror
 202:			
 203:	52E0  D5      	openok:	push de			; save fd
 204:	52E1  217554  	        ld hl, iobuf
 205:	52E4  114554  	        ld de, dcb
 206:	52E7  0600    	        ld b, 0
 207:	52E9  CD0452  	        call init               ; open the file
 208:	52EC  D1      		pop de
 209:	52ED  2810    		jr z, opn2ok
 210:	52EF  4F      		ld c, a
 211:	52F0  CD1852  	        call error
 212:	52F3  C32052  	        jp abort
 213:	52F6  21DF53  	usage:  ld hl, usager           ; error message and exit
 214:	52F9  CD2452  	        call dsply
 215:	52FC  C32052  	        jp abort
 216:			
 217:			;; Read
 218:	52FF          	rloop:
 219:	52FF  217554  	opn2ok:	ld hl, iobuf            ; read a buffer
 220:	5302  010020  		ld bc, iobsize
 221:	5305  ED32    		defw emt_read
 222:	5307  2805    		jr z, readok
 223:	5309  211A54  	        ld hl, urder            ; read error (!!code in A)
 224:	530C  186A    		jr uerror
 225:	530E  D5      	readok:	push de			; save fd
 226:			
 227:			;; Translate
 228:	530F  3ADE53  	        ld a, (nflag)		; check for NL feature
 229:	5312  A7      		and a
 230:	5313  2817    		jr z, nlfals
 231:	5315  217554  		ld hl, iobuf
 232:	5318  C5      		push bc			; save byte count
 233:	5319  3E0A    		ld a, 0ah
 234:	531B  160D    		ld d, 0dh
 235:	531D  0C      		inc c			; deal with b=0 and/ c=0
 236:	531E  04      		inc b
 237:	531F  1805    		jr tstrt
 238:	5321  BE      	tloop:	cp (hl)
 239:	5322  2001    		jr nz, notcr
 240:	5324  72      		ld (hl), d
 241:	5325  23      	notcr:	inc hl
 242:	5326  0D      	tstrt:	dec c
 243:	5327  20F8    		jr nz, tloop
 244:	5329  10F6    		djnz tloop
 245:	532B  C1      		pop bc			; restore byte count
 246:			
 247:			;; Write
 248:	532C  C5      	nlfals:	push bc			; save byte count
 249:	532D  217554  		ld hl, iobuf
 250:	5330  114554  		ld de, dcb
 251:	5333  04      		inc b			; deal with b=0 and/or c=0
 252:	5334  79      		ld a, c
 253:	5335  A7      		and a
 254:	5336  2810    		jr z, wstrt
 255:	5338  224854  	wloop:  ld (dcb+3), hl
 256:	533B  CD1452  		call write              ; write 256 bytes to file
 257:	533E  2807    	        jr z, wrok
 258:	5340  4F      		ld c, a
 259:	5341  CD1852  	        call error              ; oops, i/o error
 260:	5344  C32052  	        jp abort
 261:	5347  24      	wrok:	inc h
 262:	5348  10EE    	wstrt:  djnz wloop
 263:	534A  C1      		pop bc			; restore byte count
 264:			
 265:			;; Done?
 266:	534B  D1      		pop de			; restore fd
 267:	534C  79      		ld a, c
 268:	534D  A7      		and a
 269:	534E  2003    		jr nz, closit		; done for sure
 270:	5350  B8      		cp b
 271:	5351  20AC    		jr nz, rloop		; maybe not done (sloppy)
 272:			
 273:	5353  ED31    	closit:	defw emt_close		; close Unix file
 274:	5355  2805    		jr z, closok
 275:	5357  212F54  	        ld hl, uclser           ; close error (!!code in A)
 276:	535A  181C    		jr uerror
 277:	535C  79      	closok:	ld a, c
 278:	535D  324D54  		ld (dcb+8), a		; set EOF offset
 279:	5360  CD2852  		call setern		; set ERN (in case shortening file)
 280:	5363  114554  		ld de, dcb
 281:	5366  CD0C52  	        call close              ; close the TRS-80 file
 282:	5369  2807    	        jr z, cls2ok
 283:	536B  4F      		ld c, a
 284:	536C  CD1852  	        call error              ; oops, i/o error
 285:	536F  C32052  	        jp abort
 286:	5372  210000  	cls2ok: ld hl, 0                ; all is well
 287:	5375  C31C52  		jp exit
 288:			
 289:			;; Unix error, msg in hl, errno in a
 290:	5378  F5      	uerror: push af
 291:	5379  CD2452  		call dsply
 292:	537C  F1      		pop af
 293:	537D  217554  		ld hl, iobuf
 294:	5380  010001  		ld bc, 256
 295:	5383  ED35    		defw emt_strerror
 296:	5385  CD2452  		call dsply
 297:	5388  C32052  	        jp abort
 298:			
 299:			;; Display message in HL.  03h terminate, 0dh newline and terminate.
 300:	538B  111D40  	dsply5:	ld de, dodcb$
 301:	538E  E5      		push hl
 302:	538F  7E      	dsply0:	ld a, (hl)
 303:	5390  FE03    		cp 03h
 304:	5392  280A    		jr z, dsply1
 305:	5394  F5      		push af
 306:	5395  CD1B00  		call @put
 307:	5398  F1      		pop af
 308:	5399  23      		inc hl
 309:	539A  FE0D    		cp 0dh
 310:	539C  20F1    		jr nz, dsply0
 311:	539E  E1      	dsply1:	pop hl
 312:	539F  C9      		ret
 313:			
 314:			;; Convert (NUL terminated) string in HL to lower case.
 315:	53A0  E5      	lcconv:	push hl
 316:	53A1  54      		ld d, h
 317:	53A2  5D      		ld e, l
 318:	53A3  7E      	lcloop:	ld a, (hl)
 319:	53A4  FE5B    		cp 5bh			; use '[' or uparrow as escape
 320:	53A6  2004    		jr nz, lconv1
 321:	53A8  23      		inc hl
 322:	53A9  7E      		ld a, (hl)
 323:	53AA  1809    		jr lconv2		; char after esc: don't convert
 324:	53AC  D641    	lconv1:	sub 'A'
 325:	53AE  FE1A    		cp 26
 326:	53B0  7E      		ld a, (hl)
 327:	53B1  3002    		jr nc, lconv2
 328:	53B3  F620    		or 20h			; convert to lower case
 329:	53B5  12      	lconv2:	ld (de), a
 330:	53B6  23      		inc hl
 331:	53B7  13      		inc de
 332:	53B8  B7      		or a			; NUL terminator?
 333:	53B9  20E8    		jr nz, lcloop
 334:	53BB  E1      		pop hl
 335:	53BC  C9      		ret
 336:			
 337:			;; EOF handling is different for NEWDOS/80 and TRSDOS 1.3:
 338:			;;  For TRSDOS 2.3 and LDOS, word (dcb+12) contains the number of
 339:			;;  256 byte records in the file, byte (dcb+8) contains the EOF
 340:			;;  offset in the last record (0=256).
 341:			;;  For NEWDOS/80 and TRSDOS 1.3, byte (dcb+8) and word (dcb+12) 
 342:			;;  form a 24 bit number containing the relative byte address of EOF.
 343:			;;  Thus (dcb+12) differs by one if the file length is not a
 344:			;;  multiple of 256 bytes.
 345:			
 346:			; Set ending record number of file to current position
 347:			; EOF offset in C; destroys A, HL
 348:	53BD          	setern5:
 349:	53BD  2A4F54  		ld hl, (dcb+10)		; current record number
 350:	53C0  3A2744  		ld a, (4427h)		; system id for Newdos/80...
 351:	53C3  D682    		sub 82h			; ...should be 82h (v2.0)
 352:	53C5  2807    		jr z, adj
 353:	53C7  3A1F44  		ld a, (441fh)		; system version number for most other DOSes
 354:	53CA  D613    		sub 13h			; TRSDOS 1.3?
 355:	53CC  2004    		jr nz, noadj
 356:	53CE  B1      	adj:	or c			; length multiple of 256 bytes?
 357:	53CF  2801    		jr z, noadj
 358:	53D1  2B      		dec hl			; no, # of records - 1
 359:	53D2  225154  	noadj:	ld (dcb+12), hl
 360:	53D5  C9      		ret	
 361:			
 362:			; All Model 4 mode operating systems should be TRSDOS/LS-DOS 6.x compatible
 363:	53D6          	setern6:
 364:	53D6  2A4F54  		ld hl, (dcb+10)
 365:	53D9  225154  		ld (dcb+12), hl
 366:	53DC  C9      		ret
 367:			
 368:	53DD  00      	lflag:	defb 0
 369:	53DE  00      	nflag:	defb 0
 370:			
 371:	53DF  55736167	usager: defb 'Usage: IMPORT [-ln] unixfile [tofile]', 0dh
	      653A2049
	      4D504F52
	      54205B2D
	      6C6E5D20
	      756E6978
	      66696C65
	      205B746F
	      66696C65
	      5D0D
 372:	5405  4572726F	uopner:	defb 'Error in Unix open: ', 03h
	      7220696E
	      20556E69
	      78206F70
	      656E3A20
	      03
 373:	541A  4572726F	urder:	defb 'Error in Unix read: ', 03h
	      7220696E
	      20556E69
	      78207265
	      61643A20
	      03
 374:	542F  4572726F	uclser:	defb 'Error in Unix close: ', 03h
	      7220696E
	      20556E69
	      7820636C
	      6F73653A
	      2003
 375:			
 376:	5445          	dcb:	defs 48			; 48 for Model III TRSDOS 1.3   
 377:	5475          	iobuf:	defs iobsize
 378:			        
 379:	5258          	        end import



Statistics:

    99	symbols
   581	bytes



Symbol Table:

@abort         =4030     emt_lseek      =34ed+    not4            526c     
@abort6        =  15     emt_open       =30ed     notcr           5325     
@close         =4428     emt_read       =32ed     notdot          52b5     
@close6        =  3c     emt_strerror   =35ed     open            5208+    
@dsply6        =   a     emt_write      =33ed+    openok          52e0     
@error         =4409     endj            522c     opn2ok          52ff     
@error6        =  1a     eo_accmode     =   3+    readok          530e     
@exit          =402d     eo_append      = 400+    reed            5210+    
@exit6         =  16     eo_creat       =  40+    rloop           52ff     
@fspec         =441c     eo_excl        =  80+    setern          5228     
@fspec6        =  4e     eo_rdonly      =   0     setern5         53bd     
@init          =4420     eo_rdwr        =   2+    setern6         53d6     
@init6         =  3a     eo_trunc       = 200+    startj          5200     
@open          =4424     eo_wronly      =   1+    startj6         522c     
@open6         =  3b     error           5218     tloop           5321     
@put           =  1b     exit            521c     trs80           52be     
@read          =4436     flag0           526c     tstrt           5326     
@read6         =  43     flag1           5277     uclser          542f     
@svc           =  28     flag2           5293     uerror          5378     
@write         =4439     flag3           527d     unix1           529c     
@write6        =  4b     flagn           528a     unix2           52a1     
abort           5220     fspec           5200     unix3           52ad     
adj             53ce     import          5258     unix4           52bd     
close           520c     init            5204     uopner          5405     
closit          5353     iobsize        =2000     urder           541a     
closok          535c     iobuf           5475     usage           52f6     
cls2ok          5372     lcconv          53a0     usager          53df     
dcb             5445     lcloop          53a3     wloop           5338     
dodcb          =401d     lconv1          53ac     write           5214     
dsply           5224     lconv2          53b5     wrok            5347     
dsply0          538f     lflag           53dd     wstrt           5348     
dsply1          539e     nflag           53de     
dsply5          538b     nlfals          532c     
emt_close      =31ed     noadj           53d2