-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.s
387 lines (330 loc) · 6.84 KB
/
io.s
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
copyr: call printstr
db ansiclrscn,green,'$'
mov ax,3d00h
mov dx,copyleft
int 21h
jc readtent.e1
mov bx,ax
.loop: mov ah,3fh ;read file
mov cx,1
mov dx,x0
int 21h
jc .exit
mov dl,[x0]
cmp dl,26
jz .exit
mov cx,2000
.delay: mov ah,2
loop .delay
int 21h
jmp .loop
.exit: call getkey
jmp setcolors.e1
setcolors:mov ax,3d00h
mov dx,cf
int 21h
jc readtent.e1
mov bx,ax
mov ah,3fh ;read file
mov cx,7
mov dx,palette
int 21h
.e1: jmp loadpat.e1
savecf: mov ah,3ch ;create a file
mov dx,cf
xor cx,cx
int 21h
jc readtent.e1
mov bx,ax
mov ah,40h ;write
mov cx,7
mov dx,palette
int 21h
jmp loadpat.e1
readtent:mov ah,3fh ;read file
mov bx,[filehl]
mov cx,3072
xor dx,dx
push ds
mov ds,[iobseg]
int 21h
pop ds
shr ax,1
mov [tsz],ax
sub [filesz],ax
.e1: retn
loadpat: mov ax,3d00h
mov dx,fn
int 21h
jc readtent.e1
mov [filehl],ax
mov bx,ax
mov ax,4202h ;fseek
xor cx,cx
xor dx,dx
int 21h
shr dx,1
rcr ax,1
or dx,dx
jnz .exit2
sub ax,3
jbe .exit2
mov [filesz],ax
mov ax,4200h
int 21h
mov si,[live]
mov di,[born]
mov ah,3fh ;read file
mov cx,6
mov dx,x0
int 21h
mov al,byte [live+1]
or al,byte [born+1]
cmp al,2
jnc .l1
test byte [born],1
jz .l2
.l1: mov [live],si
mov [born],di
jmp .exit2
.l2: push si
push di
call readtent ;should adjust filesz
call showrect
pop di
pop si
jc .l1
call fillrt
call puttent
cmp [filesz],0
je .exit2
.l3: mov ah,3fh
mov bx,[filehl]
mov cx,2
mov dx,x0
int 21h
call putpixel
dec [filesz]
jnz .l3
.exit2: mov bx,[filehl]
.e1: mov ah,3eh ;fclose
int 21h
retn
printbp: mov dl,' '
cmp bp,10
jnc .l1
mov ah,2
int 21h
.l1: cmp bp,100
jnc .l2
mov ah,2
int 21h
.l2: mov ax,bp
.ee: xor dx,dx
.ee1: call todec
lea si,[stringbuf+bx]
.l3: mov dl,[si]
dec si
mov ah,2
int 21h
dec bx
jnz .l3
retn
showdir: call printstr ;OUT: BP
db ansiclrscn,10,'$'
xor bp,bp
mov dx,svfn
mov cx,20h
mov ah,4eh
int 21h
jc .exit
.l3: call printstr
db red,'$'
call printbp
call printstr
db black,' $'
mov di,80h ;dta
push di
.l2: mov dl,[di+1eh] ;fn offset in DTA
inc di
cmp dl,'.'
jz .l1
mov ah,2
int 21h
jmp .l2
.l1: call printstr
db ' ',blue,'$'
pop di
mov ax,[di+1ah] ;size offset in DTA
call printbp.ee
call printstr
db green,'$'
test bp,1
jnz .l4
mov ah,3
xor bx,bx
int 10h
dec ah
mov dl,20
int 10h
jmp .l5
.l4: call printstr
db 0dh,10,'$'
.l5: inc bp
cmp bp,1000
jz .exit
mov ah,4fh
mov dx,80h ;dta
int 21h
jnc .l3
.exit: test bp,1
jz showfree
call printstr
db 0dh,10,'$'
showfree:mov ah,36h ;after showdir
xor dx,dx
int 21h
mul cx
mov cx,10 ;1024
.l1: shr dx,1
rcr ax,1
loop .l1
mul bx
call printbp.ee1
call printstr
db 'K free',black,'$'
retn
findfn: xor bp,bp ;in: ax
mov di,ax
mov dx,svfn
mov cx,20h
mov ah,4eh
int 21h
.l3: cmp di,bp
jz .l7
inc bp
mov ah,4fh
mov dx,80h
int 21h
jmp .l3
.l7: mov di,80h ;dta
mov si,fn
.l2: mov al,[di+1eh] ;fn offset in DTA
inc di
mov [si],al
inc si
or al,al
jnz .l2
jmp showdir.exit
savepat: mov ah,3ch ;create a file
mov dx,svfn
xor cx,cx
int 21h
jc .error
mov bx,ax
mov [filehl],ax
mov ah,40h ;write
mov cx,6
mov dx,x0
int 21h
mov si,tiles
mov dx,[boxsz_xmin] ;dl - xmin, dh - ymin
xor cx,cx ;cl - currow, ch - curcol
.loop0: xor bx,bx
.loop2: mov al,[si+bx]
or al,al
jnz .cont1
.loop4: inc bx
cmp bl,8
jnz .loop2
add si,tilesize
inc ch
cmp ch,hormax
jnz .loop0
xor ch,ch
inc cx
cmp cl,vermax
jnz .loop0
jmp loadpat.exit2
.error: call printstr
db 'can''t save$'
jmp getkey
.cont1: mov ah,0ffh
.loop3: inc ah
shl al,1
jc .cont4
jz .loop4
jmp .loop3
.cont4: push ax
mov al,ch
shl al,1
shl al,1
shl al,1
add al,ah
sub al,dl
mov [x0],al
mov al,cl
shl al,1
shl al,1
shl al,1
add al,bl
sub al,dh
mov [y0],al
push bx
push cx
push dx
mov ah,40h
mov bx,[filehl]
mov cx,2
mov dx,x0
int 21h
pop dx
pop cx
pop bx
pop ax
jmp .loop3
;;ioerror: tstb @#errst ;must be after iocf
;; beq exit20
;;ioerr1:
;; jsr r3,@#printstr
;; .byte 12
;; .asciz "IO ERROR"
;; jmp @#getkey
showcomm:cmp byte [fn],0
je .exit
call totext
mov si,fn
mov di,svfn
mov dx,di
.c1: lodsb
mov [di],al
inc di
cmp al,'.'
jne .c1
mov word [di],'T'+'X'*256
mov word [di+2],'T'
mov ax,3d00h
int 21h
jc .error
mov bx,ax
mov ax,3
int 10h
.loop: mov ah,3fh ;read file
mov cx,1
mov dx,x0
int 21h
jc .fin
or ax,ax
jz .fin
mov dl,[x0]
mov ah,2
int 21h
jmp .loop
.fin: mov ah,3eh ;fclose
int 21h
.exit: call curoff
call getkey
jmp tograph
.error: call printstr
db 'no comments$'
jmp .exit