File: export.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,586 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:			;; export.z
   2:			;; Timothy Mann, 8/24/97
   3:			;; Last modified on Sat Mar 25 21:36:04 PST 2000 by mann
   4:			;;
   5:			;; Use xtrs 1.9 emulator traps to copy a file from TRS-80 to Unix
   6:			;; Usage: EXPORT [-ln] fromfile [unixfile]
   7:			;; Parameter -l will convert the Unix file to lower case.
   8:			;;  (Needed for NEWDOS/80.  They insist on uppercasing the command line.)
   9:			;; If the -n parameter is given, each carriage return ('\r')
  10:			;;  in the TRS-80 file is converted to a newline ('\n') in the Unix file.
  11:			;; If the unixfile parameter is omitted, the fromfile parameter is used,
  12:			;;  with '/' changed to '.'.
  13:			
  14:			;; Model I/III addresses
  15:	441C          	@fspec  equ 441ch
  16:	4420          	@init   equ 4420h
  17:	4424          	@open   equ 4424h
  18:	4428          	@close  equ 4428h
  19:	4436          	@read   equ 4436h
  20:	4439          	@write  equ 4439h
  21:	4409          	@error  equ 4409h
  22:	402D          	@exit   equ 402dh
  23:	4030          	@abort  equ 4030h       
  24:	001B          	@put	equ 001bh
  25:	401D          	dodcb$	equ 401dh
  26:			
  27:			;; Model 4 SVCs
  28:	0028          	@svc	equ 40  ; rst address for SVCs
  29:			;@svc	equ 5   ; older zmac requires 8080-style "rst 5"
  30:	004E          	@fspec6	equ 78
  31:	003A          	@init6	equ 58
  32:	003B          	@open6	equ 59
  33:	003C          	@close6	equ 60
  34:	0043          	@read6	equ 67
  35:	004B          	@write6	equ 75
  36:	001A          	@error6	equ 26
  37:	0016          	@exit6	equ 22
  38:	0015          	@abort6	equ 21
  39:	000A          	@dsply6	equ 10
  40:			
  41:	5200          		org 5200h
  42:			
  43:			;; Jump tables for OS independence
  44:	5200          	startj:
  45:	5200  CD1C44  	fspec:	call @fspec
  46:	5203  C9      		ret
  47:	5204  CD2044  	init:	call @init
  48:	5207  C9      		ret
  49:	5208  CD2444  	open:	call @open
  50:	520B  C9      		ret
  51:	520C  CD2844  	close:	call @close
  52:	520F  C9      		ret
  53:	5210  CD3644  	reed:	call @read
  54:	5213  C9      		ret
  55:	5214  CD3944  	write:	call @write
  56:	5217  C9      		ret
  57:	5218  CD0944  	error:	call @error
  58:	521B  C9      		ret
  59:	521C  CD2D40  	exit:	call @exit
  60:	521F  C9      		ret
  61:	5220  CD3040  	abort:	call @abort
  62:	5223  C9      		ret
  63:	5224  CD9753  	dsply:	call dsply5
  64:	5227  C9      		ret
  65:	5228  CDC953  	getern:	call getern5
  66:	522B  C9      		ret
  67:	522C          	endj:
  68:			
  69:			; Model 4
  70:	522C          	startj6:
  71:	522C  3E4E    		ld a, @fspec6
  72:	522E  EF      		rst @svc
  73:	522F  C9      		ret
  74:	5230  3E3A    		ld a, @init6
  75:	5232  EF      		rst @svc
  76:	5233  C9      		ret
  77:	5234  3E3B    		ld a, @open6
  78:	5236  EF      		rst @svc
  79:	5237  C9      		ret
  80:	5238  3E3C    		ld a, @close6
  81:	523A  EF      		rst @svc
  82:	523B  C9      		ret
  83:	523C  3E43    		ld a, @read6
  84:	523E  EF      		rst @svc
  85:	523F  C9      		ret
  86:	5240  3E4B    		ld a, @write6
  87:	5242  EF      		rst @svc
  88:	5243  C9      		ret
  89:	5244  3E1A    		ld a, @error6
  90:	5246  EF      		rst @svc
  91:	5247  C9      		ret
  92:	5248  3E16    		ld a, @exit6
  93:	524A  EF      		rst @svc
  94:	524B  C9      		ret
  95:	524C  3E15    		ld a, @abort6
  96:	524E  EF      		rst @svc
  97:	524F  C9      		ret
  98:	5250  3E0A    		ld a, @dsply6
  99:	5252  EF      		rst @svc
 100:	5253  C9      		ret
 101:	5254  CDE153  		call getern6
 102:	5257  C9      		ret
 103:			
 104:			; Emulator trap instructions, byte-reversed for use in defw:
 105:	30ED          	emt_open	equ 30edh
 106:	31ED          	emt_close	equ 31edh
 107:	32ED          	emt_read	equ 32edh
 108:	33ED          	emt_write	equ 33edh
 109:	34ED          	emt_lseek	equ 34edh
 110:	35ED          	emt_strerror	equ 35edh
 111:			
 112:	0003          	EO_ACCMODE  equ     3q
 113:	0000          	EO_RDONLY   equ     0q
 114:	0001          	EO_WRONLY   equ     1q
 115:	0002          	EO_RDWR     equ     2q
 116:	0040          	EO_CREAT    equ   100q
 117:	0080          	EO_EXCL     equ   200q
 118:	0200          	EO_TRUNC    equ  1000q
 119:	0400          	EO_APPEND   equ  2000q
 120:			
 121:	5258          	export:
 122:	5258  3A0A00  		ld a, (000ah)		; Model 4?
 123:	525B  FE40    		cp 40h
 124:	525D  280D    		jr z, not4
 125:	525F  E5      		push hl
 126:	5260  110052  		ld de, startj
 127:	5263  212C52  		ld hl, startj6
 128:	5266  012C00  		ld bc, endj - startj
 129:	5269  EDB0    		ldir
 130:	526B  E1      		pop hl
 131:	526C          	not4:
 132:			
 133:	526C  7E      	flag0:	ld a, (hl)		; look for flags
 134:	526D  FE20    		cp ' '
 135:	526F  DA7B53  		jp c, usage		; error if line ends here
 136:	5272  2003    		jr nz, flag1
 137:	5274  23      		inc hl
 138:	5275  18F5    		jr flag0
 139:	5277  FE2D    	flag1:	cp '-'
 140:	5279  2022    		jr nz, fromf
 141:	527B  23      		inc hl
 142:	527C  7E      		ld a, (hl)
 143:	527D  F620    	flag3:	or 20h
 144:	527F  FE6C    		cp 'l'
 145:	5281  2007    		jr nz, flagn		; check for next flag
 146:	5283  3E01    		ld a, 1
 147:	5285  32E653  		ld (lflag), a
 148:	5288  180A    		jr flag2
 149:	528A  FE6E    	flagn:	cp 'n'
 150:	528C  C27B53  		jp nz, usage		; only -n or -N is accepted
 151:	528F  3E01    		ld a, 1
 152:	5291  32E753  		ld (nflag), a
 153:	5294  23      	flag2:	inc hl
 154:	5295  7E      		ld a, (hl)
 155:	5296  FE20    		cp ' '
 156:	5298  20E3    		jr nz, flag3		; another flag follows
 157:	529A  23      		inc hl
 158:	529B  18CF    		jr flag0
 159:			
 160:	529D  115354  	fromf:	ld de, dcb              ; ready to get LDOS filename from (HL)
 161:	52A0  22E853  		ld (lfname), hl		; save if needed to default Unix name
 162:	52A3  CD0052  	        call fspec
 163:	52A6  C27B53  	        jp nz, usage
 164:			
 165:	52A9  7E      	unix0:	ld a, (hl)              ; scan over Unix filename
 166:	52AA  FE20    	        cp ' '		        ; first skip spaces
 167:	52AC  3814    		jr c, usetrs            ; if no Unix name, use translated TRS name
 168:	52AE  2003    	        jr nz, unix1
 169:	52B0  23      	        inc hl
 170:	52B1  18F6    		jr unix0
 171:	52B3  118354  	unix1:	ld de, iobuf		; copy Unix filename
 172:	52B6  3E20    		ld a, ' '
 173:	52B8  BE      	unix2:	cp (hl)
 174:	52B9  EDA0    		ldi
 175:	52BB  38FB    		jr c, unix2
 176:	52BD  1B      		dec de
 177:	52BE  97      		sub a
 178:	52BF  12      		ld (de), a              ; NUL terminate Unix name
 179:	52C0  181C    	        jr gotu
 180:			
 181:	52C2  2AE853  	usetrs: ld hl, (lfname)		; translate TRS-80 name to Unix
 182:	52C5  118354  		ld de, iobuf
 183:	52C8  7E      	ut1:	ld a, (hl)
 184:	52C9  FE3A    		cp ':'			; drivespec?
 185:	52CB  280F    		jr z, utdone		; done if so
 186:	52CD  FE21    		cp ' '+1		; end of line?
 187:	52CF  380B    		jr c, utdone		; done if so
 188:	52D1  FE2F    		cp '/'			; change '/' to '.' for extension
 189:	52D3  2002    		jr nz, notsl
 190:	52D5  3E2E    		ld a, '.'
 191:	52D7  12      	notsl:	ld (de), a
 192:	52D8  23      		inc hl
 193:	52D9  13      		inc de
 194:	52DA  18EC    		jr ut1
 195:	52DC  97      	utdone: sub a			; NUL-terminate Unix name
 196:	52DD  12      		ld (de), a
 197:			
 198:	52DE  218354  	gotu:   ld hl, iobuf
 199:	52E1  115354  	        ld de, dcb
 200:	52E4  0600    	        ld b, 0
 201:	52E6  CD0852  	        call open               ; open the TRS-80 file
 202:	52E9  E1      	        pop hl
 203:	52EA  2807    	        jr z, uname
 204:	52EC  4F      		ld c, a
 205:	52ED  CD1852  	        call error
 206:	52F0  C32052  	        jp abort
 207:			
 208:	52F3  218354  	uname:	ld hl, iobuf		; path
 209:	52F6  3AE653  		ld a, (lflag)
 210:	52F9  B7      		or a
 211:	52FA  C4AC53  		call nz, lcconv		; convert filename to lower case
 212:	52FD  014102  	        ld bc, EO_WRONLY|EO_CREAT|EO_TRUNC
 213:	5300  11B601  	        ld de, 0666q            ; mode
 214:	5303  ED30    	        defw emt_open		; open the Unix file
 215:	5305  2806    	        jr z, opn2ok            ; go if OK
 216:	5307  211254  	        ld hl, uopner           ; error message and exit
 217:	530A  C38453  		jp uerror
 218:			
 219:			;; Read
 220:	530D  CD2852  	opn2ok:	call getern		; count down records in bc
 221:			
 222:	5310  D5      	loop:	push de			; save fd
 223:	5311  115354  		ld de, dcb
 224:	5314  CD1052  		call reed               ; read 256 bytes from file
 225:	5317  D1      		pop de
 226:	5318  280B    	        jr z, rdok		; got a full 256 bytes
 227:	531A  FE1C    		cp 28			; eof?
 228:	531C  283F    		jr z, closit		; yes, OK
 229:	531E  4F      		ld c, a
 230:	531F  CD1852  	        call error              ; oops, i/o error
 231:	5322  C32052  	        jp abort
 232:	5325  0B      	rdok:	dec bc
 233:			
 234:			;; Translate
 235:	5326  C5      		push bc			; save record count
 236:	5327  3AE753  	        ld a, (nflag)		; check for NL feature
 237:	532A  A7      		and a
 238:	532B  280F    		jr z, nlfals
 239:	532D  218354  		ld hl, iobuf
 240:	5330  3E0D    		ld a, 0dh
 241:	5332  010A00  		ld bc, 000ah		; b := 0, c := 0ah
 242:	5335  BE      	tloop:	cp (hl)
 243:	5336  2001    		jr nz, notlf
 244:	5338  71      		ld (hl), c
 245:	5339  23      	notlf:	inc hl
 246:	533A  10F9    		djnz tloop
 247:	533C  C1      	nlfals:	pop bc			; restore record count
 248:			
 249:			;; Write
 250:	533D  79      		ld a, c
 251:	533E  B0      		or b			; last record?
 252:	533F  C5      		push bc			; save record count
 253:	5340  010001  		ld bc, 0100h		; byte count
 254:	5343  2007    		jr nz, notlst
 255:	5345  47      		ld b, a
 256:	5346  3A5B54  		ld a, (dcb+8)
 257:	5349  4F      		ld c, a
 258:	534A  0D      		dec c			; EOF offset 0: write 256 bytes
 259:	534B  03      		inc bc
 260:	534C          	notlst:
 261:	534C  218354  		ld hl, iobuf
 262:	534F  ED33    		defw emt_write
 263:	5351  C1      		pop bc
 264:	5352  2805    		jr z, wrok
 265:	5354  212754  		ld hl, uwrer            ; write error
 266:	5357  182B    	        jr uerror
 267:	5359  79      	wrok:	ld a, c
 268:	535A  B0      		or b
 269:	535B  20B3    		jr nz, loop
 270:			
 271:			;; Close
 272:	535D  ED31    	closit:	defw emt_close		; close Unix file
 273:	535F  2805    		jr z, closok
 274:	5361  213D54  	        ld hl, uclser           ; close error
 275:	5364  181E    		jr uerror
 276:	5366  115354  	closok:	ld de, dcb
 277:	5369  CD0C52  	        call close              ; close the TRS-80 file
 278:	536C  2807    	        jr z, cls2ok
 279:	536E  4F      		ld c, a
 280:	536F  CD1852  	        call error              ; oops, i/o error
 281:	5372  C32052  	        jp abort
 282:	5375  210000  	cls2ok: ld hl, 0	        ; all is well
 283:	5378  C31C52  		jp exit
 284:			
 285:			;; Usage message
 286:	537B  21EA53  	usage:  ld hl, usager           ; error message and exit
 287:	537E  CD2452  	        call dsply
 288:	5381  C32052  	        jp abort
 289:			
 290:			;; Unix error, msg in hl, errno in a
 291:	5384  F5      	uerror: push af
 292:	5385  CD2452  		call dsply
 293:	5388  F1      		pop af
 294:	5389  218354  		ld hl, iobuf
 295:	538C  010001  		ld bc, 256
 296:	538F  ED35    		defw emt_strerror
 297:	5391  CD2452  		call dsply
 298:	5394  C32052  	        jp abort
 299:			
 300:			;; Display message in HL.  03h terminate, 0dh newline and terminate.
 301:	5397  111D40  	dsply5:	ld de, dodcb$
 302:	539A  E5      		push hl
 303:	539B  7E      	dsply0:	ld a, (hl)
 304:	539C  FE03    		cp 03h
 305:	539E  280A    		jr z, dsply1
 306:	53A0  F5      		push af
 307:	53A1  CD1B00  		call @put
 308:	53A4  F1      		pop af
 309:	53A5  23      		inc hl
 310:	53A6  FE0D    		cp 0dh
 311:	53A8  20F1    		jr nz, dsply0
 312:	53AA  E1      	dsply1:	pop hl
 313:	53AB  C9      		ret
 314:			
 315:			;; Convert (NUL terminated) string in HL to lower case.
 316:	53AC  E5      	lcconv:	push hl
 317:	53AD  54      		ld d, h
 318:	53AE  5D      		ld e, l
 319:	53AF  7E      	lcloop:	ld a, (hl)
 320:	53B0  FE5B    		cp 5bh			; use '[' or uparrow as escape
 321:	53B2  2004    		jr nz, lconv1
 322:	53B4  23      		inc hl
 323:	53B5  7E      		ld a, (hl)
 324:	53B6  1809    		jr lconv2		; char after esc: don't convert
 325:	53B8  D641    	lconv1:	sub 'A'
 326:	53BA  FE1A    		cp 26
 327:	53BC  7E      		ld a, (hl)
 328:	53BD  3002    		jr nc, lconv2
 329:	53BF  F620    		or 20h			; convert to lower case
 330:	53C1  12      	lconv2:	ld (de), a
 331:	53C2  23      		inc hl
 332:	53C3  13      		inc de
 333:	53C4  B7      		or a			; NUL terminator?
 334:	53C5  20E8    		jr nz, lcloop
 335:	53C7  E1      		pop hl
 336:	53C8  C9      		ret
 337:			
 338:			;; EOF handling is different for NEWDOS/80 and TRSDOS 1.3:
 339:			;;  For TRSDOS 2.3 and LDOS, word (dcb+12) contains the number of
 340:			;;  256 byte records in the file, byte (dcb+8) contains the EOF
 341:			;;  offset in the last record (0=256).
 342:			;;  For NEWDOS/80 and TRSDOS 1.3, byte (dcb+8) and word (dcb+12) 
 343:			;;  form a 24 bit number containing the relative byte address of EOF.
 344:			;;  Thus (dcb+12) differs by one if the file length is not a
 345:			;;  multiple of 256 bytes.
 346:			
 347:			; Returns number of (partial or full) records in BC, destroys A
 348:	53C9          	getern5:
 349:	53C9  ED4B5F54		ld bc, (dcb+12)
 350:	53CD  3A2744  		ld a, (4427h)		; system id for Newdos/80...
 351:	53D0  FE82    		cp 82h			; ...should be 82h (v2.0)
 352:	53D2  2806    		jr z, adj
 353:	53D4  3A1F44  		ld a, (441fh)		; system version number for most other DOSes
 354:	53D7  FE13    		cp 13h			; TRSDOS 1.3?
 355:	53D9  C0      		ret nz
 356:	53DA  3A5B54  	adj:	ld a, (dcb+8)		; length multiple of 256 bytes?
 357:	53DD  A7      		and a
 358:	53DE  C8      		ret z
 359:	53DF  03      		inc bc			; no, # of records = last full record + 1
 360:	53E0  C9      		ret	
 361:			
 362:			; All Model 4 mode operating systems should be TRSDOS/LS-DOS 6.x compatible
 363:	53E1          	getern6:
 364:	53E1  ED4B5F54		ld bc, (dcb+12)
 365:	53E5  C9      		ret
 366:			
 367:	53E6  00      	lflag:	defb 0
 368:	53E7  00      	nflag:	defb 0
 369:	53E8  0000    	lfname:	defw 0
 370:			
 371:	53EA  55736167	usager: defb 'Usage: EXPORT [-ln] fromfile [unixfile]', 0dh
	      653A2045
	      58504F52
	      54205B2D
	      6C6E5D20
	      66726F6D
	      66696C65
	      205B756E
	      69786669
	      6C655D0D
 372:	5412  4572726F	uopner:	defb 'Error in Unix open: ', 03h
	      7220696E
	      20556E69
	      78206F70
	      656E3A20
	      03
 373:	5427  4572726F	uwrer:	defb 'Error in Unix write: ', 03h
	      7220696E
	      20556E69
	      78207772
	      6974653A
	      2003
 374:	543D  4572726F	uclser:	defb 'Error in Unix close: ', 03h
	      7220696E
	      20556E69
	      7820636C
	      6F73653A
	      2003
 375:			
 376:	5453          	dcb:	defs 48			; 48 for Model III TRSDOS 1.3
 377:	5483          	iobuf:	defs 256
 378:			        
 379:	5258          	        end export



Statistics:

    99	symbols
   595	bytes



Symbol Table:

@abort         =4030     emt_lseek      =34ed+    lflag           53e6     
@abort6        =  15     emt_open       =30ed     lfname          53e8     
@close         =4428     emt_read       =32ed+    loop            5310     
@close6        =  3c     emt_strerror   =35ed     nflag           53e7     
@dsply6        =   a     emt_write      =33ed     nlfals          533c     
@error         =4409     endj            522c     not4            526c     
@error6        =  1a     eo_accmode     =   3+    notlf           5339     
@exit          =402d     eo_append      = 400+    notlst          534c     
@exit6         =  16     eo_creat       =  40     notsl           52d7     
@fspec         =441c     eo_excl        =  80+    open            5208     
@fspec6        =  4e     eo_rdonly      =   0+    opn2ok          530d     
@init          =4420     eo_rdwr        =   2+    rdok            5325     
@init6         =  3a     eo_trunc       = 200     reed            5210     
@open          =4424     eo_wronly      =   1     startj          5200     
@open6         =  3b     error           5218     startj6         522c     
@put           =  1b     exit            521c     tloop           5335     
@read          =4436     export          5258     uclser          543d     
@read6         =  43     flag0           526c     uerror          5384     
@svc           =  28     flag1           5277     uname           52f3     
@write         =4439     flag2           5294     unix0           52a9     
@write6        =  4b     flag3           527d     unix1           52b3     
abort           5220     flagn           528a     unix2           52b8     
adj             53da     fromf           529d     uopner          5412     
close           520c     fspec           5200     usage           537b     
closit          535d     getern          5228     usager          53ea     
closok          5366     getern5         53c9     usetrs          52c2     
cls2ok          5375     getern6         53e1     ut1             52c8     
dcb             5453     gotu            52de     utdone          52dc     
dodcb          =401d     init            5204+    uwrer           5427     
dsply           5224     iobuf           5483     write           5214+    
dsply0          539b     lcconv          53ac     wrok            5359     
dsply1          53aa     lcloop          53af     
dsply5          5397     lconv1          53b8     
emt_close      =31ed     lconv2          53c1