rev |
line source |
pascal@19515
|
1 ;***************************************************************
|
pascal@19515
|
2 ;****** This file is distributed under GPL
|
pascal@19515
|
3 ;***************************************************************
|
pascal@19515
|
4 ideal
|
pascal@19515
|
5 %crefref
|
pascal@19515
|
6 %noincl
|
pascal@19515
|
7 %nomacs
|
pascal@19636
|
8 ifdef NO386
|
pascal@19636
|
9 p8086
|
pascal@19636
|
10 else
|
pascal@19515
|
11 p386
|
pascal@19636
|
12 endif
|
pascal@19515
|
13
|
pascal@19515
|
14 group DGROUP _TEXT,_DATA,_BSS
|
pascal@19515
|
15 assume cs:DGROUP,ds:DGROUP
|
pascal@19515
|
16
|
pascal@19515
|
17 segment _DATA byte public use16 'DATA'
|
pascal@19515
|
18
|
pascal@20451
|
19 global _heap_top
|
pascal@20451
|
20 extrn _bss_end
|
pascal@19546
|
21 _heap_top dw _bss_end
|
pascal@19546
|
22 msg_hang db "High mem corrupted - not exiting to DOS"
|
pascal@19546
|
23 msg_crlf db 13,10,0
|
pascal@20451
|
24 vcpi_alloc_err db "VCPI "
|
pascal@20451
|
25 msg_malloc db "malloc error",0
|
pascal@19825
|
26 ifdef EXTRA
|
pascal@19825
|
27 tazboot_cmd db "tazboot.cmd",0
|
pascal@19825
|
28 endif
|
pascal@19515
|
29
|
pascal@19515
|
30 ends _DATA
|
pascal@19515
|
31
|
pascal@19515
|
32 segment _BSS byte public use16 'BSS'
|
pascal@19515
|
33
|
pascal@19515
|
34 global _no_exit:byte
|
pascal@19515
|
35 _no_exit db ?
|
pascal@19515
|
36 filecnt db ? ; in fact 0 minus file count...
|
pascal@19515
|
37 nextfilename dw ?
|
pascal@19571
|
38 ifdef LARGE_IMAGES
|
pascal@19571
|
39 curdata dw ?
|
pascal@19571
|
40 endif
|
pascal@19825
|
41 ifdef EXTRA
|
pascal@19825
|
42 ultoabuf db 12 dup (?)
|
pascal@19825
|
43 endif
|
pascal@19515
|
44
|
pascal@19515
|
45 ends _BSS
|
pascal@19515
|
46
|
pascal@19515
|
47 segment _TEXT byte public use16 'CODE'
|
pascal@19515
|
48
|
pascal@19515
|
49 ;***************************************************************
|
pascal@19538
|
50 ;char* strcpy(const char* a, const char* b);
|
pascal@19580
|
51 ;char* strcat(const char* a, const char* b);
|
pascal@19634
|
52 ;char* strcatb(const char* a, const char* b);
|
pascal@19538
|
53 ;***************************************************************
|
pascal@19826
|
54 global _strcatb:near
|
pascal@19826
|
55 proc _strcatb near
|
pascal@19538
|
56
|
pascal@19826
|
57 ifdef EXTRA
|
pascal@20142
|
58 mov cl,7Fh
|
pascal@19580
|
59 db 0bbh ; mov bx,imm opcode
|
pascal@19580
|
60 global _strcat:near
|
pascal@19580
|
61 _strcat:
|
pascal@20142
|
62 mov cl,80h
|
pascal@19634
|
63 db 0bbh ; mov bx,imm opcode
|
pascal@19826
|
64 global _strcpy:near
|
pascal@19826
|
65 _strcpy:
|
pascal@20142
|
66 xor cx,cx
|
pascal@19826
|
67 endif
|
pascal@19538
|
68 pop ax ;caller return address
|
pascal@20142
|
69 pop dx ; a
|
pascal@19538
|
70 pop bx ; b
|
pascal@19538
|
71 push bx
|
pascal@20142
|
72 push dx
|
pascal@19538
|
73 push ax
|
pascal@19538
|
74 push si
|
pascal@20142
|
75 mov si,dx
|
pascal@19826
|
76 ifdef EXTRA
|
pascal@20142
|
77 jcxz @@nocat
|
pascal@19826
|
78 endif
|
pascal@19538
|
79 @@catlp:
|
pascal@19538
|
80 lodsb
|
pascal@19538
|
81 cmp al,0
|
pascal@19538
|
82 jne @@catlp
|
pascal@19538
|
83 dec si
|
pascal@19826
|
84 ifdef EXTRA
|
pascal@20142
|
85 cmp dx,si
|
pascal@20142
|
86 adc al,cl ; set S when dx != si or cl = 80
|
pascal@20142
|
87 mov al,20h
|
pascal@20142
|
88 jns @@cpyhead
|
pascal@19826
|
89 endif
|
pascal@19538
|
90 @@nocat:
|
pascal@19538
|
91 @@cpylp:
|
pascal@20142
|
92 mov al,[bx]
|
pascal@20142
|
93 inc bx
|
pascal@20142
|
94 @@cpyhead:
|
pascal@19538
|
95 mov [si],al
|
pascal@19538
|
96 inc si
|
pascal@19538
|
97 cmp al,0
|
pascal@19538
|
98 jne @@cpylp
|
pascal@20142
|
99 strfound:
|
pascal@20142
|
100 xchg ax,dx
|
pascal@20142
|
101 strend:
|
pascal@19538
|
102 pop si
|
pascal@20142
|
103 ret
|
pascal@19538
|
104
|
pascal@19826
|
105 endp _strcatb
|
pascal@19538
|
106
|
pascal@19538
|
107
|
pascal@20146
|
108 ifdef EXTRA
|
pascal@20146
|
109 p8086
|
pascal@20146
|
110 ;***************************************************************
|
pascal@20146
|
111 ;char strstr(const char* a,const char* b);
|
pascal@20146
|
112 ;***************************************************************
|
pascal@20146
|
113 global _strstr:near
|
pascal@20146
|
114 proc _strstr near
|
pascal@20146
|
115
|
pascal@20146
|
116 pop ax ;caller return address
|
pascal@20146
|
117 pop dx ; a
|
pascal@20146
|
118 pop cx ; b
|
pascal@20146
|
119 push cx
|
pascal@20146
|
120 push dx
|
pascal@20146
|
121 push ax
|
pascal@20146
|
122 push si
|
pascal@20146
|
123 @@loop:
|
pascal@20146
|
124 xor ax,ax
|
pascal@20146
|
125 mov si,dx
|
pascal@20146
|
126 cmp [si],al ; *a
|
pascal@20146
|
127 jz strend ; return ax = NULL
|
pascal@20146
|
128 mov bx,cx
|
pascal@20146
|
129 @@match:
|
pascal@20146
|
130 or ah,[bx] ; *b
|
pascal@20146
|
131 jz strfound
|
pascal@20146
|
132 inc bx
|
pascal@20146
|
133 lodsb
|
pascal@20146
|
134 sub ah,al
|
pascal@20146
|
135 jz @@match
|
pascal@20146
|
136 inc dx
|
pascal@20146
|
137 jmp @@loop
|
pascal@20146
|
138
|
pascal@20146
|
139 endp _strstr
|
pascal@20146
|
140
|
pascal@20146
|
141
|
pascal@20146
|
142 ;***************************************************************
|
pascal@20146
|
143 ;int strcmp(const char* a,const char* b);
|
pascal@20146
|
144 ;***************************************************************
|
pascal@20146
|
145 global _strcmp:near
|
pascal@20146
|
146 proc _strcmp near
|
pascal@20146
|
147
|
pascal@20146
|
148 pop cx ;caller return address
|
pascal@20146
|
149 pop bx ; a
|
pascal@20146
|
150 pop ax ; b
|
pascal@20146
|
151 push ax
|
pascal@20146
|
152 push bx
|
pascal@20146
|
153 push cx
|
pascal@20146
|
154 push si
|
pascal@20146
|
155 xchg ax,si
|
pascal@20146
|
156 dec bx
|
pascal@20146
|
157 @@lp:
|
pascal@20146
|
158 inc bx
|
pascal@20146
|
159 lodsb
|
pascal@20146
|
160 sub al,[bx]
|
pascal@20146
|
161 jnz @@out
|
pascal@20510
|
162 or al,al
|
pascal@20146
|
163 jnz @@lp
|
pascal@20146
|
164 @@out:
|
pascal@20146
|
165 cbw
|
pascal@20146
|
166 pop si
|
pascal@20146
|
167 ret
|
pascal@20146
|
168
|
pascal@20146
|
169 endp _strcmp
|
pascal@20146
|
170 endif
|
pascal@20146
|
171
|
pascal@20146
|
172
|
pascal@19538
|
173 ;***************************************************************
|
pascal@19515
|
174 ;void puts(const char* s):
|
pascal@19515
|
175 ;***************************************************************
|
pascal@19515
|
176 global _puts:near
|
pascal@19515
|
177 proc _puts near
|
pascal@19515
|
178
|
pascal@19515
|
179 pop ax ;caller return address
|
pascal@19515
|
180 pop bx ; s
|
pascal@19515
|
181 push bx
|
pascal@19515
|
182 push ax
|
pascal@20486
|
183 ; global puts:near ; puts(bx)
|
pascal@19515
|
184 puts:
|
pascal@20510
|
185 call @@putsz
|
pascal@19515
|
186 mov bx,offset msg_crlf
|
pascal@20510
|
187 jmp @@putsz
|
pascal@20510
|
188 @@putcz:
|
pascal@20160
|
189 mov ah,2
|
pascal@20146
|
190 int 21h
|
pascal@20510
|
191 @@putsz:
|
pascal@20160
|
192 mov dl,[bx]
|
pascal@20146
|
193 inc bx
|
pascal@20160
|
194 or dl,dl
|
pascal@20510
|
195 jne @@putcz ; ZF=1 (for malloc failure)
|
pascal@19538
|
196 ret
|
pascal@19515
|
197
|
pascal@19515
|
198 endp _puts
|
pascal@19515
|
199
|
pascal@19515
|
200
|
pascal@19515
|
201 ;***************************************************************
|
pascal@19538
|
202 ;int fileattr(const char* name);
|
pascal@19538
|
203 ;***************************************************************
|
pascal@19538
|
204 global _fileattr:near
|
pascal@19538
|
205 proc _fileattr near
|
pascal@19538
|
206
|
pascal@19538
|
207 pop ax ;caller return address
|
pascal@19538
|
208 pop dx ; name
|
pascal@19538
|
209 push dx
|
pascal@19538
|
210 push ax
|
pascal@19538
|
211 mov ax,4300h
|
pascal@19538
|
212 int 21h
|
pascal@19538
|
213 xchg ax,cx
|
pascal@19538
|
214 jmp chkc
|
pascal@19538
|
215
|
pascal@19538
|
216 endp _fileattr
|
pascal@19538
|
217
|
pascal@19538
|
218
|
pascal@19538
|
219 ;***************************************************************
|
pascal@19546
|
220 ;int open(const char* name, int flags=O_RDONLY);
|
pascal@19515
|
221 ;***************************************************************
|
pascal@19515
|
222 global _open:near
|
pascal@19515
|
223 proc _open near
|
pascal@19515
|
224
|
pascal@19546
|
225 pop ax ;caller return address
|
pascal@19515
|
226 pop bx ; name
|
pascal@19546
|
227 push bx
|
pascal@19515
|
228 push ax
|
pascal@19546
|
229 global open:near ; open(bx)
|
pascal@19515
|
230 open:
|
pascal@19515
|
231 mov dx,bx
|
pascal@20146
|
232 ;mov cl,0 ; attribute mask
|
pascal@20146
|
233 mov ax,3d00h ; read-only+compatibility
|
pascal@19515
|
234 dos:
|
pascal@19515
|
235 int 21h
|
pascal@19538
|
236 chkc:
|
pascal@19515
|
237 jnc doret
|
pascal@19515
|
238 fail:
|
pascal@19515
|
239 sbb ax,ax ; ax=-1 CF
|
pascal@19515
|
240 cwd
|
pascal@19515
|
241 doret:
|
pascal@19515
|
242 ifndef NO386
|
pascal@19538
|
243 push dx ; see next_chunk:lseek
|
pascal@19538
|
244 push ax
|
pascal@19538
|
245 pop eax
|
pascal@19515
|
246 endif
|
pascal@19515
|
247 ret
|
pascal@19515
|
248
|
pascal@19515
|
249 endp _open
|
pascal@19515
|
250
|
pascal@19515
|
251
|
pascal@19515
|
252 ;***************************************************************
|
pascal@19515
|
253 ;int close(int fd);
|
pascal@19515
|
254 ;***************************************************************
|
pascal@19515
|
255 global _close:near
|
pascal@19515
|
256 proc _close near
|
pascal@19515
|
257
|
pascal@19515
|
258 pop ax ;caller return address
|
pascal@19515
|
259 pop bx ; fd
|
pascal@19515
|
260 push bx
|
pascal@19515
|
261 push ax
|
pascal@19515
|
262 global close:near ; close(bx)
|
pascal@19515
|
263 close:
|
pascal@19515
|
264 mov ah,3Eh
|
pascal@19515
|
265 or bx,bx
|
pascal@19515
|
266 jnz dos
|
pascal@19515
|
267 ret
|
pascal@19515
|
268
|
pascal@19515
|
269 endp _close
|
pascal@19515
|
270
|
pascal@19515
|
271
|
pascal@19515
|
272 ;***************************************************************
|
pascal@19515
|
273 ;int read(int fd, void* data, int sz);
|
pascal@19580
|
274 ;int write(int fd, const void* data, int sz);
|
pascal@19515
|
275 ;***************************************************************
|
pascal@19515
|
276 global _read:near
|
pascal@19515
|
277 proc _read near
|
pascal@19515
|
278
|
pascal@20146
|
279 ifdef WRITE
|
pascal@19580
|
280 stc
|
pascal@19634
|
281 db 0B0h ; mov al,im
|
pascal@19580
|
282 global _write:near
|
pascal@19580
|
283 clc
|
pascal@20146
|
284 endif
|
pascal@19580
|
285 pop ax ;caller return address
|
pascal@19580
|
286 pop bx ; fd
|
pascal@19580
|
287 pop dx ; data
|
pascal@19515
|
288 pop cx ; sz
|
pascal@19515
|
289 push cx
|
pascal@19515
|
290 push dx
|
pascal@19580
|
291 push bx
|
pascal@19580
|
292 push ax
|
pascal@20146
|
293 ifdef WRITE
|
pascal@19580
|
294 mov ah,40h
|
pascal@19580
|
295 sbb ah,0
|
pascal@20146
|
296 else
|
pascal@20146
|
297 mov ah,3Fh
|
pascal@20146
|
298 endif
|
pascal@19515
|
299 jcxz fail
|
pascal@19515
|
300 jmp dos
|
pascal@19515
|
301
|
pascal@19515
|
302 endp _read
|
pascal@19515
|
303
|
pascal@20146
|
304 proc _lseekset near
|
pascal@20147
|
305 ;ifdef EXTRA
|
pascal@19515
|
306 ;***************************************************************
|
pascal@19825
|
307 ;long lseekset(int fd, unsigned long sz);
|
pascal@19515
|
308 ;***************************************************************
|
pascal@19899
|
309
|
pascal@19571
|
310 global _lseekset:near
|
pascal@19515
|
311
|
pascal@19515
|
312 pop ax ;caller return address
|
pascal@19515
|
313 pop bx ; fd
|
pascal@19571
|
314 pop dx ; sz lo
|
pascal@19571
|
315 pop cx ; sz hi
|
pascal@19571
|
316 push cx
|
pascal@20146
|
317 push dx
|
pascal@19515
|
318 push bx
|
pascal@19515
|
319 push ax
|
pascal@20147
|
320 ;endif
|
pascal@20486
|
321 ; global lseekset:near
|
pascal@19571
|
322 lseekset:
|
pascal@19571
|
323 clc
|
pascal@19634
|
324 db 0B0h ; mov al,im
|
pascal@20486
|
325 ; global rewind:near
|
pascal@19634
|
326 rewind: ; rewind(bx)
|
pascal@19634
|
327 stc
|
pascal@19571
|
328 mov ax,4200h
|
pascal@19571
|
329 jnc dos
|
pascal@19571
|
330 lseek0: ; lseek0(bx,ax=dir)
|
pascal@19571
|
331 cwd
|
pascal@19571
|
332 xor cx,cx
|
pascal@19515
|
333 jmp dos
|
pascal@19515
|
334
|
pascal@19571
|
335 endp _lseekset
|
pascal@19825
|
336
|
pascal@19825
|
337 ifdef EXTRA
|
pascal@19825
|
338 struc isostate ; struct isostate {
|
pascal@19825
|
339 fd dw ? ; 0 int fd;
|
pascal@19825
|
340 fileofs dd ? ; 2 unsigned long fileofs;
|
pascal@19825
|
341 filesize dd ? ; 6 unsigned long filesize;
|
pascal@19825
|
342 filemod dw ? ;10 unsigned short filemod;
|
pascal@19825
|
343 filename dw ? ;12 char *filename;
|
pascal@19825
|
344 dirofs dd ? ;14 unsigned long dirofs;
|
pascal@19825
|
345 dirsize dd ? ;16 unsigned long dirsize;
|
pascal@19825
|
346 curdirofs dd ? ;20 unsigned long curdirofs;
|
pascal@19825
|
347 curdirsize dd ? ;24 unsigned long curdirsize;
|
pascal@19825
|
348 curpos dd ? ;28 unsigned long curpos;
|
pascal@19825
|
349 ends ; } isostate;
|
pascal@19825
|
350 ;***************************************************************
|
pascal@19825
|
351 ;unsigned long isolseek(const unsigned long *offset);
|
pascal@19825
|
352 ;***************************************************************
|
pascal@19825
|
353 global _isolseek:near
|
pascal@19825
|
354 proc _isolseek near
|
pascal@19825
|
355
|
pascal@19825
|
356 pop ax
|
pascal@19825
|
357 pop bx
|
pascal@19825
|
358 push bx
|
pascal@19825
|
359 push ax
|
pascal@19825
|
360 mov dx,[bx]
|
pascal@19825
|
361 mov cx,[bx+2]
|
pascal@19825
|
362 extrn _isostate:isostate
|
pascal@19825
|
363 mov bx,[_isostate.fd]
|
pascal@19825
|
364 jmp lseekset ; (bx=fd, sz=cx:dx)
|
pascal@19825
|
365
|
pascal@19825
|
366 endp _isolseek
|
pascal@19825
|
367 endif
|
pascal@19515
|
368
|
pascal@19515
|
369
|
pascal@19515
|
370 ;***************************************************************
|
pascal@19515
|
371 ;int strhead(const char* a,const char* b);
|
pascal@19515
|
372 ;***************************************************************
|
pascal@19515
|
373 global _strhead:near
|
pascal@19515
|
374 proc _strhead near
|
pascal@19515
|
375
|
pascal@19515
|
376 pop cx ;caller return address
|
pascal@19634
|
377 pop bx ; a
|
pascal@19634
|
378 pop ax ; b
|
pascal@19634
|
379 push ax
|
pascal@19515
|
380 push bx
|
pascal@19515
|
381 push cx
|
pascal@19515
|
382 @@loop:
|
pascal@19634
|
383 xchg ax,bx
|
pascal@19515
|
384 mov cl,[bx] ; cl = *b++
|
pascal@19515
|
385 inc bx
|
pascal@19515
|
386 or cl,cl ; clear C
|
pascal@19515
|
387 jz fail ; return 0
|
pascal@19515
|
388 xchg ax,bx
|
pascal@19515
|
389 xor cl,[bx] ; cl -= *a++
|
pascal@19634
|
390 inc bx
|
pascal@19515
|
391 and cl,0dfh ; case insensitive
|
pascal@19634
|
392 jz @@loop
|
pascal@19634
|
393 ret ; return b (is not 0)
|
pascal@19515
|
394
|
pascal@19515
|
395 endp _strhead
|
pascal@19515
|
396
|
pascal@19515
|
397
|
pascal@19515
|
398 ;***************************************************************
|
pascal@19515
|
399 ;char* malloc_or_die(unsigned size);
|
pascal@19515
|
400 ;***************************************************************
|
pascal@19515
|
401 global _malloc_or_die:near
|
pascal@19515
|
402 proc _malloc_or_die near
|
pascal@19515
|
403
|
pascal@19515
|
404 pop ax ;caller return address
|
pascal@19515
|
405 pop cx ; size
|
pascal@19515
|
406 push cx
|
pascal@19515
|
407 push ax
|
pascal@19515
|
408 global malloc_or_die:near ; malloc_or_die(cx)
|
pascal@19515
|
409 malloc_or_die:
|
pascal@20510
|
410 mov ax,[_heap_top] ; return value
|
pascal@20510
|
411 mov bx,sp
|
pascal@20510
|
412 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
|
pascal@20510
|
413 sub bx,ax ; can't overflow
|
pascal@20510
|
414 cmp bx,cx
|
pascal@20456
|
415 mov bx,offset msg_malloc
|
pascal@20510
|
416 jb die
|
pascal@20510
|
417 add [_heap_top],cx ; _BEG has zero'd heap
|
pascal@19515
|
418 ret
|
pascal@19515
|
419
|
pascal@19515
|
420 endp _malloc_or_die
|
pascal@19515
|
421
|
pascal@19515
|
422
|
pascal@19515
|
423 ;***************************************************************
|
pascal@19515
|
424 ;int die(const char* msg);
|
pascal@19538
|
425 ;int exit();
|
pascal@19515
|
426 ;int abort();
|
pascal@19515
|
427 ;***************************************************************
|
pascal@19515
|
428 global _die:near
|
pascal@19515
|
429 proc _die near
|
pascal@19515
|
430
|
pascal@19515
|
431 pop ax ;caller return address
|
pascal@19515
|
432 pop bx ; s
|
pascal@19515
|
433 push bx
|
pascal@19515
|
434 push ax
|
pascal@19515
|
435 global die:near ; die(bx)
|
pascal@19515
|
436 die:
|
pascal@19515
|
437 call puts
|
pascal@20486
|
438 ; global _exit:near
|
pascal@19538
|
439 _exit:
|
pascal@19515
|
440 mov al,[_no_exit]
|
pascal@19515
|
441 cmp al,0
|
pascal@19515
|
442 jne @@hang
|
pascal@19515
|
443 extrn exit:near
|
pascal@19515
|
444 inc ax
|
pascal@19515
|
445 jmp near exit
|
pascal@19515
|
446 @@hang:
|
pascal@19515
|
447 mov bx, offset msg_hang
|
pascal@19515
|
448 call puts
|
pascal@20486
|
449 ; global _abort:near
|
pascal@19515
|
450 _abort:
|
pascal@19515
|
451 cli
|
pascal@19515
|
452 @@stop:
|
pascal@19515
|
453 hlt
|
pascal@19515
|
454 jmp @@stop
|
pascal@19515
|
455
|
pascal@19515
|
456 endp _die
|
pascal@19515
|
457
|
pascal@19546
|
458 struc image_himem ;struct image_himem {
|
pascal@19546
|
459 fd dw ? ; 0 int fd;
|
pascal@19546
|
460 fallback dd ? ; 2 u32 fallback;
|
pascal@19546
|
461 size dd ? ; 6 u32 size;
|
pascal@19546
|
462 remaining dd ? ;10 u32 remaining;
|
pascal@19546
|
463 buf dd ? ;14 u32 buf;
|
pascal@19546
|
464 bufv dw ? ;18 u32 *bufv;
|
pascal@19546
|
465 errmsg dw ? ;20 char *errmsg;
|
pascal@19546
|
466 chunk_size dd ? ;22 u32 chunk_size;
|
pascal@19546
|
467 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
|
pascal@19546
|
468 state dw ? ;28 u16 state;
|
pascal@19546
|
469 fd2close dw ? ;30 u16 fd2close;
|
pascal@19546
|
470 ends ;};
|
pascal@19515
|
471
|
pascal@19636
|
472 ;***************************************************************
|
pascal@20484
|
473 ;long next_chunk(struct image_himem *di);
|
pascal@19636
|
474 ;***************************************************************
|
pascal@19636
|
475 proc next_chunk near
|
pascal@19636
|
476
|
pascal@19636
|
477 push si
|
pascal@19636
|
478 mov bx,[(image_himem di).fd]
|
pascal@19636
|
479 call close
|
pascal@19636
|
480 ifndef NO386
|
pascal@19636
|
481 xor eax,eax
|
pascal@19636
|
482 else
|
pascal@19636
|
483 xor ax,ax
|
pascal@20485
|
484 cwd
|
pascal@19636
|
485 endif
|
pascal@19636
|
486 mov [(image_himem di).fd],ax
|
pascal@19636
|
487 mov bx,[(image_himem di).state]
|
pascal@19636
|
488 cmp al,[bx] ; ""
|
pascal@19636
|
489 jz @@end
|
pascal@19636
|
490 mov si,bx
|
pascal@19636
|
491 @@scan:
|
pascal@19636
|
492 lodsb
|
pascal@19636
|
493 mov cx,si
|
pascal@19636
|
494 cmp al,','
|
pascal@19636
|
495 jz @@eos
|
pascal@19636
|
496 cmp al,0
|
pascal@19636
|
497 jnz @@scan
|
pascal@19636
|
498 dec cx
|
pascal@19636
|
499 @@eos:
|
pascal@19636
|
500 mov [(image_himem di).state],cx
|
pascal@19636
|
501 dec si
|
pascal@19636
|
502 push [word si]
|
pascal@20485
|
503 mov [byte si],ah ; set temp eos
|
pascal@19636
|
504 call open
|
pascal@19636
|
505 pop [word si] ; restore string
|
pascal@19636
|
506 jc @@die
|
pascal@19636
|
507 mov [(image_himem di).fd],ax
|
pascal@19636
|
508 mov [(image_himem di).fd2close],ax
|
pascal@19636
|
509 xchg ax,bx
|
pascal@19636
|
510 mov ax,4202h ; SEEK_END
|
pascal@19636
|
511 call lseek0
|
pascal@19636
|
512 @@die:
|
pascal@19636
|
513 mov bx,[(image_himem di).errmsg]
|
pascal@19636
|
514 jc die
|
pascal@19636
|
515 mov bx,[(image_himem di).fd]
|
pascal@19636
|
516 ifndef NO386
|
pascal@19636
|
517 push eax
|
pascal@19636
|
518 call rewind
|
pascal@19636
|
519 pop eax
|
pascal@19636
|
520 @@end:
|
pascal@19636
|
521 mov [(image_himem di).chunk_size],eax
|
pascal@19636
|
522 else
|
pascal@19636
|
523 push ax
|
pascal@19636
|
524 push dx
|
pascal@19636
|
525 call rewind
|
pascal@19636
|
526 pop dx
|
pascal@19636
|
527 pop ax
|
pascal@19636
|
528 @@end:
|
pascal@19636
|
529 mov [word (image_himem di).chunk_size],ax
|
pascal@19636
|
530 mov [word ((image_himem di).chunk_size)+2],dx
|
pascal@19636
|
531 endif
|
pascal@19636
|
532 pop si
|
pascal@19636
|
533 ret
|
pascal@19636
|
534
|
pascal@19636
|
535 endp next_chunk
|
pascal@19636
|
536
|
pascal@19636
|
537
|
pascal@19571
|
538 ifdef LARGE_IMAGES
|
pascal@19571
|
539 struc data_himem ;struct data_himem {
|
pascal@19571
|
540 first dd ? ; 0 u32 first;
|
pascal@19571
|
541 cacheidx dw ? ; 4 int cacheidx;
|
pascal@19571
|
542 pageidx dw ? ; 6 int pageidx;
|
pascal@19571
|
543 cache dd 1024 dup(?) ; 8 int cache;
|
pascal@19571
|
544 page dd 1024 dup(?) ;4104 int page;
|
pascal@19571
|
545 ends ;}; // size=8200
|
pascal@19571
|
546 endif
|
pascal@19571
|
547
|
pascal@19515
|
548 ;***************************************************************
|
pascal@19538
|
549 ;u32* malloc_bufv_or_die(struct image_himem *m);
|
pascal@19538
|
550 ;***************************************************************
|
pascal@19538
|
551 global _malloc_bufv_or_die:near
|
pascal@19538
|
552 proc _malloc_bufv_or_die near
|
pascal@19538
|
553
|
pascal@19636
|
554 p386
|
pascal@19538
|
555 pop bx ;caller return address
|
pascal@19538
|
556 pop ax
|
pascal@19538
|
557 push ax
|
pascal@19538
|
558 push bx
|
pascal@19538
|
559 push si
|
pascal@19538
|
560 xchg ax,si
|
pascal@19571
|
561 ifdef LARGE_IMAGES
|
pascal@19571
|
562 mov cx,[word ((image_himem si).size) + 2]
|
pascal@19571
|
563 shr cx,4 ; pages index size = size >> 20
|
pascal@19571
|
564 add cx,8+4096+8
|
pascal@19571
|
565 call malloc_or_die
|
pascal@19571
|
566 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
|
pascal@19571
|
567 add ecx,[(image_himem si).size]
|
pascal@19571
|
568 shr ecx,12
|
pascal@19571
|
569 mov [curdata],ax
|
pascal@19571
|
570 else
|
pascal@19546
|
571 mov ecx,[(image_himem si).size]
|
pascal@19538
|
572 dec ecx
|
pascal@19538
|
573 shr ecx,12
|
pascal@19538
|
574 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
|
pascal@19538
|
575 push cx
|
pascal@19538
|
576 inc cx ; cnt+1
|
pascal@19538
|
577 shl cx,2 ; bufv => vcpi => vm86
|
pascal@19538
|
578 ; our malloc zeroes allocated mem: bufv[cnt]=0;
|
pascal@19538
|
579 ; Allocate pages, storing addrs in addrbuf
|
pascal@19538
|
580 call malloc_or_die
|
pascal@19571
|
581 pop cx
|
pascal@19571
|
582 push ax
|
pascal@19571
|
583 endif
|
pascal@19546
|
584 mov [(image_himem si).bufv],ax
|
pascal@19571
|
585 xchg ax,si
|
pascal@19538
|
586 @@vcpi_alloc:
|
pascal@19538
|
587 xor edx,edx
|
pascal@19538
|
588 mov ax,0DE04h
|
pascal@19538
|
589 int 67h
|
pascal@19538
|
590 or ah,ah
|
pascal@19538
|
591 mov bx,offset vcpi_alloc_err
|
pascal@19571
|
592 jnz die
|
pascal@19571
|
593 ; for (i = cnt-1; i >= 0; i--)
|
pascal@19571
|
594 ifdef LARGE_IMAGES
|
pascal@19571
|
595 mov eax,ecx
|
pascal@19571
|
596 dec eax
|
pascal@19571
|
597 else
|
pascal@19571
|
598 mov ax,cx
|
pascal@19571
|
599 dec ax
|
pascal@19571
|
600 cwde
|
pascal@19571
|
601 endif
|
pascal@19571
|
602 shl eax,12 ; i*_4k
|
pascal@19571
|
603 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
|
pascal@19899
|
604 extrn _imgs
|
pascal@19899
|
605 mov bx,offset _imgs+2
|
pascal@19571
|
606 push eax
|
pascal@19571
|
607 add eax,[bx-2+2]
|
pascal@19571
|
608 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
|
pascal@19571
|
609 pop eax ; i*_4k
|
pascal@19571
|
610 jbe @@pmok
|
pascal@19571
|
611 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
|
pascal@19571
|
612 jae @@vcpi_alloc
|
pascal@19571
|
613 @@pmok:
|
pascal@19571
|
614 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
|
pascal@19899
|
615 extrn _imgs
|
pascal@19899
|
616 mov bx,offset _imgs+32+2
|
pascal@19571
|
617 add eax,[bx-2+2] ; +initrd.fallback
|
pascal@19571
|
618 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
|
pascal@19571
|
619 ja @@initrdok
|
pascal@19571
|
620 mov eax,[bx-2+6] ; initrd.size
|
pascal@19571
|
621 add eax,[bx-2+2] ; +initrd.fallback
|
pascal@19571
|
622 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
|
pascal@19571
|
623 @@jnc_vcpi_alloc:
|
pascal@19571
|
624 ja @@vcpi_alloc
|
pascal@19571
|
625 @@initrdok:
|
pascal@19571
|
626 ifdef LARGE_IMAGES
|
pascal@19571
|
627 cmp [(data_himem si).first],0
|
pascal@19571
|
628 jne @@notfirst
|
pascal@19571
|
629 mov [(data_himem si).first],edx
|
pascal@19571
|
630 @@notfirst:
|
pascal@19571
|
631 mov bx,[(data_himem si).cacheidx]
|
pascal@19571
|
632 cmp bh,4
|
pascal@19571
|
633 jae @@nextpage
|
pascal@19571
|
634 shl bx,2
|
pascal@19571
|
635 inc [(data_himem si).cacheidx]
|
pascal@19571
|
636 mov [(data_himem bx+si).cache],edx
|
pascal@19571
|
637 loopd @@vcpi_alloc
|
pascal@19571
|
638 mov [(data_himem bx+si).cache],ecx ; last is 0
|
pascal@19571
|
639 @@nextpage:
|
pascal@19571
|
640 and [(data_himem si).cacheidx],0
|
pascal@19571
|
641 mov bx,[(data_himem si).pageidx]
|
pascal@19571
|
642 mov [(data_himem bx+si).page],edx
|
pascal@19571
|
643 add [(data_himem si).pageidx],4
|
pascal@19571
|
644 push cx
|
pascal@19571
|
645 lea cx,[(data_himem si).cache]
|
pascal@19571
|
646 ifdef NO386
|
pascal@19571
|
647 push edx
|
pascal@19571
|
648 pop dx
|
pascal@19571
|
649 pop ax
|
pascal@19571
|
650 endif
|
pascal@19571
|
651 call storepage ; storepage(edx,cx)
|
pascal@19571
|
652 pop cx
|
pascal@19571
|
653 or ecx,ecx ; clear C
|
pascal@19571
|
654 jnz @@jnc_vcpi_alloc
|
pascal@19571
|
655 mov [dword (data_himem si).cacheidx],ecx
|
pascal@19571
|
656 xchg ax,si
|
pascal@19571
|
657 else
|
pascal@19571
|
658 mov [si],edx
|
pascal@19571
|
659 lodsd ; si=+4
|
pascal@19538
|
660 loop @@vcpi_alloc
|
pascal@19538
|
661 pop ax
|
pascal@19571
|
662 endif
|
pascal@19538
|
663 pop si
|
pascal@19538
|
664 ret
|
pascal@19636
|
665 ifdef NO386
|
pascal@19636
|
666 p8086
|
pascal@19636
|
667 endif
|
pascal@19538
|
668
|
pascal@19538
|
669 endp _malloc_bufv_or_die
|
pascal@19538
|
670
|
pascal@19538
|
671
|
pascal@19538
|
672 ;***************************************************************
|
pascal@19571
|
673 ; void memcpy_image(struct image_himem *m);
|
pascal@19515
|
674 ;***************************************************************
|
pascal@19571
|
675 global _memcpy_image:near
|
pascal@19571
|
676 proc _memcpy_image near
|
pascal@19515
|
677
|
pascal@19571
|
678 pop ax ;caller return address
|
pascal@19515
|
679 pop bx
|
pascal@19571
|
680 push bx
|
pascal@19571
|
681 push ax
|
pascal@19571
|
682 ifndef NO386
|
pascal@19571
|
683 mov edx,[(image_himem bx).fallback]
|
pascal@19571
|
684 mov eax,[(image_himem bx).buf]
|
pascal@19571
|
685 cmp eax,edx ; if (m->fallback != m->buf)
|
pascal@19571
|
686 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
|
pascal@19571
|
687 ifdef LARGE_IMAGES
|
pascal@19571
|
688 mov ecx,[(image_himem bx).size]
|
pascal@20146
|
689 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
|
pascal@19571
|
690 push ecx
|
pascal@19571
|
691 else
|
pascal@19571
|
692 push [(image_himem bx).size]
|
pascal@19571
|
693 endif
|
pascal@19571
|
694 push eax
|
pascal@19571
|
695 push 0
|
pascal@19571
|
696 call_memcpy32:
|
pascal@19571
|
697 push edx
|
pascal@19571
|
698 else
|
pascal@19571
|
699 mov ax,[word ((image_himem bx).fallback)]
|
pascal@19571
|
700 mov dx,[word ((image_himem bx).fallback)+2]
|
pascal@19571
|
701 mov cx,[word ((image_himem bx).buf)]
|
pascal@19571
|
702 cmp ax,cx ; if (m->fallback != m->buf)
|
pascal@19571
|
703 jnz @@do
|
pascal@19571
|
704 cmp dx,[word ((image_himem bx).buf)+2]
|
pascal@19571
|
705 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
|
pascal@19571
|
706 @@do:
|
pascal@19571
|
707 push [word ((image_himem bx).size)+2]
|
pascal@19571
|
708 push [word ((image_himem bx).size)]
|
pascal@19571
|
709 push [word ((image_himem bx).buf)+2]
|
pascal@19571
|
710 push cx
|
pascal@19571
|
711 xor cx,cx
|
pascal@19571
|
712 push cx
|
pascal@19571
|
713 call_memcpy32:
|
pascal@19571
|
714 push dx
|
pascal@19571
|
715 push ax
|
pascal@19571
|
716 ifdef LARGE_IMAGES
|
pascal@19571
|
717 jmp @@memcpy
|
pascal@20146
|
718 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
|
pascal@19636
|
719 p386
|
pascal@19571
|
720 push ecx
|
pascal@19571
|
721 push eax
|
pascal@19571
|
722 push 0
|
pascal@19571
|
723 push edx
|
pascal@19636
|
724 ifdef NO386
|
pascal@19636
|
725 p8086
|
pascal@19636
|
726 endif
|
pascal@19571
|
727 endif
|
pascal@19571
|
728 endif
|
pascal@19571
|
729 @@memcpy:
|
pascal@19571
|
730 extrn _memcpy32:near
|
pascal@19571
|
731 call near _memcpy32
|
pascal@19571
|
732 add sp,14
|
pascal@19571
|
733 @@skip:
|
pascal@19571
|
734 ret
|
pascal@19571
|
735
|
pascal@19571
|
736 endp _memcpy_image
|
pascal@19571
|
737
|
pascal@19571
|
738 ;***************************************************************
|
pascal@19571
|
739 ;void storepage(u32 *dst, u16 src);
|
pascal@19571
|
740 ;***************************************************************
|
pascal@19571
|
741 global _storepage:near
|
pascal@19571
|
742 proc _storepage near
|
pascal@19571
|
743
|
pascal@19571
|
744 pop ax ;caller return address
|
pascal@19571
|
745 pop bx
|
pascal@19571
|
746 pop cx
|
pascal@19571
|
747 push cx
|
pascal@19571
|
748 push bx
|
pascal@19571
|
749 push ax
|
pascal@19571
|
750 ifndef NO386
|
pascal@19571
|
751 mov edx,[bx]
|
pascal@19571
|
752 else
|
pascal@19571
|
753 mov ax,[bx]
|
pascal@19571
|
754 mov dx,[bx+2]
|
pascal@19571
|
755 endif
|
pascal@20146
|
756 storepage: ; storepage(edx,cx)
|
pascal@19571
|
757 ifndef NO386
|
pascal@19571
|
758 push 0
|
pascal@19571
|
759 push 4096
|
pascal@19571
|
760 push 0
|
pascal@19571
|
761 else
|
pascal@19571
|
762 xor bx,bx
|
pascal@19571
|
763 push bx
|
pascal@19571
|
764 mov bh,4096/256
|
pascal@19571
|
765 push bx
|
pascal@19571
|
766 xor bx,bx
|
pascal@19571
|
767 push bx
|
pascal@19571
|
768 endif
|
pascal@19571
|
769 push cx
|
pascal@19571
|
770 push ds
|
pascal@19571
|
771 jmp call_memcpy32
|
pascal@19571
|
772
|
pascal@19571
|
773 endp _storepage
|
pascal@19571
|
774
|
pascal@19571
|
775
|
pascal@19571
|
776 ifdef LARGE_IMAGES
|
pascal@19636
|
777 p386
|
pascal@19571
|
778 ;***************************************************************
|
pascal@19571
|
779 ;void reset_bufv(u32 *p);
|
pascal@19571
|
780 ;***************************************************************
|
pascal@19571
|
781 global _reset_bufv:near
|
pascal@19571
|
782 proc _reset_bufv near
|
pascal@19571
|
783
|
pascal@20510
|
784 pop bx ;caller return address
|
pascal@20510
|
785 pop ax
|
pascal@20510
|
786 push ax
|
pascal@19634
|
787 push bx
|
pascal@20510
|
788 mov [curdata],ax
|
pascal@19571
|
789 and [dword (data_himem bx).cacheidx],0
|
pascal@19571
|
790 ret
|
pascal@19571
|
791
|
pascal@19571
|
792 endp _reset_bufv
|
pascal@19571
|
793
|
pascal@19571
|
794 ;***************************************************************
|
pascal@19571
|
795 ;u32* prev_bufv();
|
pascal@19571
|
796 ;u32* prev_bufv();
|
pascal@19571
|
797 ;***************************************************************
|
pascal@19571
|
798 global _prev_bufv:near
|
pascal@19571
|
799 global _next_bufv:near
|
pascal@19571
|
800 proc _prev_bufv near
|
pascal@19571
|
801
|
pascal@19571
|
802 stc
|
pascal@19571
|
803 db 73h ; jnc
|
pascal@19571
|
804 _next_bufv:
|
pascal@19571
|
805 clc
|
pascal@19571
|
806 sbb ax,ax
|
pascal@19571
|
807 stc
|
pascal@19571
|
808 rcl ax,1 ; -1/+1
|
pascal@19571
|
809 xor ecx,ecx
|
pascal@19571
|
810 push si
|
pascal@19571
|
811 mov si,[curdata]
|
pascal@19571
|
812 add ax,[(data_himem si).cacheidx]
|
pascal@19571
|
813 test ax,0fc00h
|
pascal@19571
|
814 jz @@gotpage
|
pascal@19571
|
815 push ax ; FFFF / 0400
|
pascal@19571
|
816 sar ax,8 ; FFFC / 0004
|
pascal@19571
|
817 and al,0fch
|
pascal@19571
|
818 add [(data_himem si).pageidx],ax
|
pascal@19571
|
819 mov bx,[(data_himem si).pageidx]
|
pascal@19571
|
820 lea bx,[(data_himem bx+si).page]
|
pascal@19571
|
821 mov edx,ds
|
pascal@19571
|
822 shl edx,4
|
pascal@19571
|
823 lea cx,[(data_himem si).cache]
|
pascal@19571
|
824 add edx,ecx
|
pascal@19571
|
825 mov eax,[bx]
|
pascal@19571
|
826 or eax,eax
|
pascal@19571
|
827 jnz @@pageok
|
pascal@19571
|
828 pop ax
|
pascal@19571
|
829 xchg ax,bx
|
pascal@19571
|
830 pop si
|
pascal@19571
|
831 ret
|
pascal@19571
|
832 @@pageok:
|
pascal@19571
|
833 mov cx,4096
|
pascal@19571
|
834 call memcpy_imagez ; get page
|
pascal@19571
|
835 pop ax ; FFFF / 0400
|
pascal@19571
|
836 cbw
|
pascal@19571
|
837 shr ax,6 ; 03FF / 0000
|
pascal@19571
|
838 @@gotpage:
|
pascal@19571
|
839 mov [(data_himem si).cacheidx],ax
|
pascal@19571
|
840 shl ax,2
|
pascal@19571
|
841 xchg ax,bx
|
pascal@19571
|
842 lea ax,[(data_himem bx+si).cache]
|
pascal@19571
|
843 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
|
pascal@19571
|
844 jnz @@notfirst2
|
pascal@19571
|
845 xchg ax,si ; &first
|
pascal@19571
|
846 @@notfirst2:
|
pascal@19571
|
847 pop si
|
pascal@19571
|
848 ret
|
pascal@19571
|
849
|
pascal@19571
|
850 endp _prev_bufv
|
pascal@19571
|
851 endif
|
pascal@19571
|
852
|
pascal@20146
|
853 ifdef NO386
|
pascal@20146
|
854 p8086
|
pascal@20146
|
855 endif
|
pascal@19571
|
856
|
pascal@19571
|
857 ;***************************************************************
|
pascal@19515
|
858 ;void open_image(const char *name, struct image_himem *m);
|
pascal@19515
|
859 ;***************************************************************
|
pascal@19515
|
860 global _open_image:near
|
pascal@19515
|
861 proc _open_image near
|
pascal@19515
|
862
|
pascal@20485
|
863 pop cx ;caller return address
|
pascal@20484
|
864 pop bx ; name
|
pascal@20485
|
865 pop ax ; m
|
pascal@20485
|
866 push ax
|
pascal@20485
|
867 push bx
|
pascal@20484
|
868 push cx
|
pascal@20484
|
869 push di
|
pascal@20485
|
870 xchg ax,di
|
pascal@19571
|
871 mov [(image_himem di).next_chunk],offset next_chunk
|
pascal@20484
|
872 mov [(image_himem di).state],bx
|
pascal@20484
|
873 push bx
|
pascal@19515
|
874 @@next:
|
pascal@19546
|
875 call [(image_himem di).next_chunk] ; m->next_chunk()
|
pascal@19515
|
876 ifndef NO386
|
pascal@19515
|
877 add eax,3
|
pascal@19515
|
878 and al,0FCh
|
pascal@19546
|
879 add [(image_himem di).size],eax ; m->size += m->chunk_size
|
pascal@19515
|
880 or eax,eax
|
pascal@19515
|
881 jnz @@next
|
pascal@19515
|
882 else
|
pascal@19515
|
883 mov cx,ax
|
pascal@19515
|
884 or cx,dx
|
pascal@19515
|
885 add ax,3
|
pascal@19515
|
886 adc dx,0
|
pascal@19515
|
887 and al,0FCh
|
pascal@19546
|
888 add [word (image_himem di).size],ax ; m->size += m->chunk_size
|
pascal@19546
|
889 adc [word ((image_himem di).size)+2],dx
|
pascal@19538
|
890 inc cx ; jcxnz
|
pascal@19515
|
891 loop @@next
|
pascal@19515
|
892 endif
|
pascal@20484
|
893 pop [(image_himem di).state]
|
pascal@19546
|
894 call [(image_himem di).next_chunk] ; m->next_chunk()
|
pascal@20484
|
895 pop di
|
pascal@19515
|
896 ret
|
pascal@19515
|
897
|
pascal@19515
|
898 endp _open_image
|
pascal@19515
|
899
|
pascal@19515
|
900
|
pascal@19515
|
901 ;***************************************************************
|
pascal@20484
|
902 ;int read_image(struct image_himem *m, char* data, int sz);
|
pascal@19515
|
903 ;***************************************************************
|
pascal@19515
|
904 global _read_image:near
|
pascal@19515
|
905 proc _read_image near
|
pascal@19515
|
906
|
pascal@19515
|
907 arg m :word, \
|
pascal@19515
|
908 data :word, \
|
pascal@19515
|
909 sz :word = PARAM_SIZE
|
pascal@19515
|
910
|
pascal@19515
|
911 push bp
|
pascal@19515
|
912 mov bp,sp
|
pascal@20484
|
913 push di
|
pascal@19515
|
914 ifndef NO386
|
pascal@19515
|
915 push 0 ; return value
|
pascal@19515
|
916 else
|
pascal@19515
|
917 xor ax,ax
|
pascal@19515
|
918 push ax
|
pascal@19515
|
919 endif
|
pascal@19515
|
920 mov di,[m]
|
pascal@19515
|
921 @@loop:
|
pascal@19538
|
922 ifndef NO386
|
pascal@20484
|
923 movzx ecx,[word sz]
|
pascal@19546
|
924 mov eax,[(image_himem di).chunk_size]
|
pascal@19538
|
925 cmp ecx,eax
|
pascal@19538
|
926 jb @@szok
|
pascal@19538
|
927 else
|
pascal@19538
|
928 mov cx,[word sz]
|
pascal@19546
|
929 mov ax,[word (image_himem di).chunk_size]
|
pascal@19538
|
930 cmp cx,ax
|
pascal@19515
|
931 jb @@szok
|
pascal@19546
|
932 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
|
pascal@19515
|
933 jne @@szok
|
pascal@20484
|
934 endif
|
pascal@19515
|
935 xchg ax,cx
|
pascal@19515
|
936 @@szok:
|
pascal@19538
|
937 jcxz image_done
|
pascal@19538
|
938 push cx
|
pascal@19515
|
939 push [word data]
|
pascal@19515
|
940 push [word di]
|
pascal@19515
|
941 call _read
|
pascal@19538
|
942 pop dx
|
pascal@19515
|
943 pop bx
|
pascal@20484
|
944 pop cx
|
pascal@19538
|
945 jc image_done
|
pascal@19515
|
946 add bx,ax
|
pascal@19515
|
947 xor cx,cx
|
pascal@19538
|
948 ifndef NO386
|
pascal@19538
|
949 cwde ; ax < 8000h
|
pascal@19546
|
950 sub [(image_himem di).chunk_size],eax
|
pascal@19538
|
951 else
|
pascal@19538
|
952 cwd ; ax < 8000h
|
pascal@19546
|
953 sub [word (image_himem di).chunk_size],ax
|
pascal@19546
|
954 sbb [word ((image_himem di).chunk_size)+2],dx
|
pascal@19538
|
955 jnz @@fill
|
pascal@19546
|
956 cmp [word (image_himem di).chunk_size],dx
|
pascal@19538
|
957 endif
|
pascal@19538
|
958 jnz @@fill
|
pascal@19538
|
959 dec cx
|
pascal@19515
|
960 @@fill:
|
pascal@19515
|
961 test al,3
|
pascal@19515
|
962 je @@filled
|
pascal@20484
|
963 mov [bx],dh
|
pascal@19515
|
964 inc bx
|
pascal@19515
|
965 inc ax
|
pascal@19515
|
966 jmp @@fill
|
pascal@19515
|
967 @@filled:
|
pascal@19538
|
968 ifndef NO386
|
pascal@19546
|
969 sub [(image_himem di).remaining],eax
|
pascal@19538
|
970 else
|
pascal@19546
|
971 sub [word (image_himem di).remaining],ax
|
pascal@19546
|
972 sbb [word ((image_himem di).remaining)+2],dx
|
pascal@19538
|
973 endif
|
pascal@20484
|
974 add [bp-2-2],ax
|
pascal@19515
|
975 add [word data],ax
|
pascal@19515
|
976 sub [word sz],ax
|
pascal@19538
|
977 pushf
|
pascal@20484
|
978 jcxz @@same_chunk
|
pascal@20484
|
979 call [(image_himem di).next_chunk]
|
pascal@19538
|
980 @@same_chunk:
|
pascal@19538
|
981 popf
|
pascal@19538
|
982 jnz @@loop
|
pascal@20484
|
983 image_done:
|
pascal@20484
|
984 pop ax
|
pascal@20484
|
985 pop di bp
|
pascal@20484
|
986 ret
|
pascal@19515
|
987
|
pascal@19515
|
988 endp _read_image
|
pascal@19515
|
989
|
pascal@19515
|
990
|
pascal@19515
|
991 ;***************************************************************
|
pascal@19515
|
992 ;unsigned long strtol(const char *s);
|
pascal@19515
|
993 ;***************************************************************
|
pascal@19515
|
994 global _strtol:near
|
pascal@19515
|
995 proc _strtol near
|
pascal@19515
|
996
|
pascal@19515
|
997 ifndef NO386
|
pascal@19515
|
998 pop ax ;caller return address
|
pascal@19515
|
999 pop cx ; s
|
pascal@19515
|
1000 push cx
|
pascal@19515
|
1001 push ax
|
pascal@19515
|
1002 xor ebx,ebx
|
pascal@19515
|
1003 push si
|
pascal@19634
|
1004 jcxz @@end
|
pascal@19515
|
1005 mov si,cx
|
pascal@19515
|
1006 xor ecx,ecx
|
pascal@19515
|
1007 xor eax,eax
|
pascal@19515
|
1008 lodsb
|
pascal@19634
|
1009 mov dx,ax
|
pascal@19634
|
1010 or al,20h
|
pascal@19634
|
1011 cmp al,'n' ; vga=normal
|
pascal@19538
|
1012 je @@vga
|
pascal@19538
|
1013 dec cx
|
pascal@19634
|
1014 cmp al,'e' ; vga=extended
|
pascal@19538
|
1015 je @@vga
|
pascal@19538
|
1016 dec cx
|
pascal@19634
|
1017 cmp al,'a' ; vga=ask
|
pascal@19538
|
1018 jne @@notvga
|
pascal@19538
|
1019 @@vga:
|
pascal@19538
|
1020 dec cx
|
pascal@19538
|
1021 xchg ax,cx
|
pascal@19538
|
1022 cwd
|
pascal@19634
|
1023 jmp @@popsiret
|
pascal@19538
|
1024 @@notvga:
|
pascal@19538
|
1025 mov cx,10 ; radix
|
pascal@19634
|
1026 xchg ax,dx
|
pascal@19515
|
1027 cmp al,'+'
|
pascal@19515
|
1028 je @@radixskip
|
pascal@19515
|
1029 cmp al,'-'
|
pascal@19515
|
1030 clc
|
pascal@19515
|
1031 jne @@radixkeep
|
pascal@19515
|
1032 stc
|
pascal@19515
|
1033 @@radixskip:
|
pascal@19515
|
1034 lodsb
|
pascal@19515
|
1035 @@radixkeep:
|
pascal@19515
|
1036 pushf
|
pascal@19515
|
1037 cmp al,'0'
|
pascal@19515
|
1038 jne @@radixok
|
pascal@19515
|
1039 mov cl,8
|
pascal@19515
|
1040 lodsb
|
pascal@19634
|
1041 or al,20h
|
pascal@19634
|
1042 cmp al,'x'
|
pascal@19515
|
1043 jne @@radixok
|
pascal@19515
|
1044 mov cl,16
|
pascal@19515
|
1045 @@strtollp:
|
pascal@19515
|
1046 lodsb
|
pascal@19515
|
1047 @@radixok:
|
pascal@19634
|
1048 or al,20h
|
pascal@19515
|
1049 sub al,'0'
|
pascal@19515
|
1050 jb @@endstrtol
|
pascal@19515
|
1051 cmp al,9
|
pascal@19515
|
1052 jbe @@digitok
|
pascal@19515
|
1053 cmp al,'a'-'0'
|
pascal@19515
|
1054 jb @@endstrtol
|
pascal@19515
|
1055 sub al,'a'-'0'-10
|
pascal@19515
|
1056 @@digitok:
|
pascal@19515
|
1057 cmp al,cl
|
pascal@19515
|
1058 jae @@endstrtol
|
pascal@19515
|
1059 xchg eax,ebx
|
pascal@19515
|
1060 mul ecx
|
pascal@19515
|
1061 add eax,ebx
|
pascal@19515
|
1062 xchg eax,ebx
|
pascal@19515
|
1063 jmp @@strtollp
|
pascal@19515
|
1064 @@endstrtol:
|
pascal@19515
|
1065 mov cl,10
|
pascal@19515
|
1066 cmp al,'k'-'a'+10
|
pascal@19515
|
1067 je @@shift
|
pascal@19515
|
1068 mov cl,20
|
pascal@19515
|
1069 cmp al,'m'-'a'+10
|
pascal@19515
|
1070 je @@shift
|
pascal@19515
|
1071 mov cl,30
|
pascal@19515
|
1072 cmp al,'g'-'a'+10
|
pascal@19515
|
1073 jne @@noshift
|
pascal@19515
|
1074 @@shift:
|
pascal@19515
|
1075 shl ebx,cl
|
pascal@19515
|
1076 @@noshift:
|
pascal@19515
|
1077 popf
|
pascal@19515
|
1078 jnc @@end
|
pascal@19515
|
1079 neg ebx
|
pascal@19515
|
1080 @@end:
|
pascal@19515
|
1081 push ebx
|
pascal@19515
|
1082 pop ax
|
pascal@19515
|
1083 pop dx
|
pascal@19634
|
1084 @@popsiret:
|
pascal@19515
|
1085 pop si
|
pascal@19515
|
1086 else
|
pascal@19515
|
1087 pop ax ;caller return address
|
pascal@19515
|
1088 pop cx ; s
|
pascal@19515
|
1089 push cx
|
pascal@19515
|
1090 push ax
|
pascal@19515
|
1091 push si
|
pascal@19515
|
1092 push di
|
pascal@19515
|
1093 xor ax,ax
|
pascal@19515
|
1094 cwd
|
pascal@19634
|
1095 jcxz @@goend
|
pascal@19515
|
1096 xchg ax,di
|
pascal@19515
|
1097 mov si,cx
|
pascal@19538
|
1098 lodsb
|
pascal@19634
|
1099 mov bx,ax
|
pascal@19634
|
1100 or al,20h
|
pascal@19538
|
1101 mov cx,-1
|
pascal@19634
|
1102 cmp al,'n' ; vga=normal
|
pascal@19538
|
1103 je @@vga
|
pascal@19538
|
1104 dec cx
|
pascal@19634
|
1105 cmp al,'e' ; vga=extended
|
pascal@19538
|
1106 je @@vga
|
pascal@19538
|
1107 dec cx
|
pascal@19634
|
1108 cmp al,'a' ; vga=ask
|
pascal@19538
|
1109 jne @@notvga
|
pascal@19538
|
1110 @@vga:
|
pascal@19538
|
1111 xchg ax,cx
|
pascal@19538
|
1112 @@goend:
|
pascal@19634
|
1113 jmp @@popdisiret
|
pascal@19538
|
1114 @@notvga:
|
pascal@19515
|
1115 mov cx,10 ; radix
|
pascal@19634
|
1116 xchg ax,bx
|
pascal@19515
|
1117 cmp al,'+'
|
pascal@19515
|
1118 je @@radixskip
|
pascal@19515
|
1119 cmp al,'-'
|
pascal@19515
|
1120 clc
|
pascal@19515
|
1121 jne @@radixkeep
|
pascal@19515
|
1122 stc
|
pascal@19515
|
1123 @@radixskip:
|
pascal@19515
|
1124 lodsb
|
pascal@19515
|
1125 @@radixkeep:
|
pascal@19515
|
1126 pushf
|
pascal@19515
|
1127 cmp al,'0'
|
pascal@19515
|
1128 jne @@radixok
|
pascal@19515
|
1129 mov cl,8
|
pascal@19515
|
1130 lodsb
|
pascal@20146
|
1131 or al,20h
|
pascal@19634
|
1132 cmp al,'x'
|
pascal@19515
|
1133 jne @@radixok
|
pascal@19515
|
1134 mov cl,16
|
pascal@19515
|
1135 @@strtollp:
|
pascal@19515
|
1136 lodsb
|
pascal@19515
|
1137 @@radixok:
|
pascal@19634
|
1138 or al,20h
|
pascal@19515
|
1139 sub al,'0'
|
pascal@19515
|
1140 jb @@endstrtol
|
pascal@19515
|
1141 cmp al,9
|
pascal@19515
|
1142 jbe @@digitok
|
pascal@19515
|
1143 cmp al,'a'-'0'
|
pascal@19515
|
1144 jb @@endstrtol
|
pascal@19515
|
1145 sub al,'a'-'0'-10
|
pascal@19515
|
1146 @@digitok:
|
pascal@19515
|
1147 cmp al,cl
|
pascal@19515
|
1148 jae @@endstrtol
|
pascal@19515
|
1149
|
pascal@19515
|
1150 push ax
|
pascal@19515
|
1151 push si
|
pascal@19515
|
1152 push dx
|
pascal@19515
|
1153 xchg ax,di
|
pascal@19515
|
1154 mul cx
|
pascal@19515
|
1155 xchg ax,di
|
pascal@19515
|
1156 xchg ax,dx
|
pascal@19515
|
1157 xchg ax,si
|
pascal@19515
|
1158 pop ax
|
pascal@19515
|
1159 mul cx
|
pascal@19515
|
1160 add ax,si
|
pascal@19515
|
1161 pop si
|
pascal@19515
|
1162 xchg ax,dx
|
pascal@19515
|
1163 pop ax
|
pascal@19515
|
1164 mov ah,0
|
pascal@19515
|
1165 add di,ax
|
pascal@19515
|
1166 adc dx,0
|
pascal@19515
|
1167
|
pascal@19515
|
1168 jmp @@strtollp
|
pascal@19515
|
1169 @@endstrtol:
|
pascal@19515
|
1170 mov cl,10
|
pascal@19515
|
1171 cmp al,'k'-'a'+10
|
pascal@19515
|
1172 je @@shift
|
pascal@19515
|
1173 mov cl,20
|
pascal@19515
|
1174 cmp al,'m'-'a'+10
|
pascal@19515
|
1175 je @@shift
|
pascal@19515
|
1176 mov cl,30
|
pascal@19515
|
1177 cmp al,'g'-'a'+10
|
pascal@19515
|
1178 jne @@noshift
|
pascal@19515
|
1179 @@shift:
|
pascal@19515
|
1180 rcl di,1
|
pascal@19515
|
1181 shl dx,1
|
pascal@19515
|
1182 loop @@shift
|
pascal@19515
|
1183 @@noshift:
|
pascal@19515
|
1184 popf
|
pascal@19515
|
1185 jnc @@end
|
pascal@19515
|
1186 not dx
|
pascal@19515
|
1187 neg di
|
pascal@19515
|
1188 jne @@end
|
pascal@19515
|
1189 inc dx
|
pascal@19515
|
1190 @@end:
|
pascal@19515
|
1191 xchg ax,di
|
pascal@19634
|
1192 @@popdisiret:
|
pascal@19515
|
1193 pop di
|
pascal@19515
|
1194 pop si
|
pascal@19515
|
1195 endif
|
pascal@19515
|
1196 ret
|
pascal@19515
|
1197
|
pascal@19515
|
1198 endp _strtol
|
pascal@19515
|
1199
|
pascal@19515
|
1200
|
pascal@19515
|
1201 ifdef NO386
|
pascal@19515
|
1202 ;***************************************************************
|
pascal@19515
|
1203 ;u16 topseg();
|
pascal@19515
|
1204 ;***************************************************************
|
pascal@19515
|
1205 global _topseg:near
|
pascal@19515
|
1206 proc _topseg near
|
pascal@19515
|
1207
|
pascal@19515
|
1208 int 12h
|
pascal@19515
|
1209 jnc @@max640k
|
pascal@19515
|
1210 mov ax,640 ; 9000
|
pascal@19515
|
1211 @@max640k:
|
pascal@19634
|
1212 dec ax
|
pascal@19515
|
1213 and al,0C0h
|
pascal@19515
|
1214 mov cl,6
|
pascal@19515
|
1215 shl ax,cl
|
pascal@19515
|
1216 ret
|
pascal@19515
|
1217
|
pascal@19515
|
1218 endp _topseg
|
pascal@19515
|
1219 endif
|
pascal@19515
|
1220
|
pascal@19825
|
1221 ifdef EXTRA
|
pascal@19825
|
1222 p8086
|
pascal@19825
|
1223 ;***************************************************************
|
pascal@19825
|
1224 ;char *progname(void)
|
pascal@19825
|
1225 ;***************************************************************
|
pascal@19825
|
1226 global _progname:near
|
pascal@19825
|
1227 proc _progname near
|
pascal@19825
|
1228
|
pascal@19825
|
1229 push si di es
|
pascal@19825
|
1230 mov ah,30h
|
pascal@19825
|
1231 int 21h
|
pascal@19875
|
1232 xor di,di
|
pascal@19825
|
1233 cmp al,3
|
pascal@19874
|
1234 mov ax,di
|
pascal@19825
|
1235 jb @@skip
|
pascal@19873
|
1236 ;mov es,[cs:2Ch]
|
pascal@19874
|
1237 mov es,[di+2Ch]
|
pascal@20146
|
1238 mov cx,sp ; big enough
|
pascal@19870
|
1239 @@loop:
|
pascal@19825
|
1240 repne
|
pascal@19825
|
1241 scasb
|
pascal@19825
|
1242 scasb
|
pascal@19870
|
1243 jne @@loop
|
pascal@19870
|
1244 inc di
|
pascal@19870
|
1245 inc di
|
pascal@19870
|
1246 mov si,di ; progname @es:di
|
pascal@19870
|
1247 repne
|
pascal@19870
|
1248 scasb
|
pascal@19870
|
1249 mov cx,di
|
pascal@19874
|
1250 sub cx,si ; progname len
|
pascal@19870
|
1251 call malloc_or_die ; keep cx
|
pascal@19870
|
1252 mov di,ax
|
pascal@19825
|
1253 push ds
|
pascal@19825
|
1254 push es
|
pascal@19825
|
1255 pop ds
|
pascal@19825
|
1256 pop es
|
pascal@19870
|
1257 rep
|
pascal@19870
|
1258 movsb
|
pascal@19870
|
1259 push es
|
pascal@19825
|
1260 pop ds
|
pascal@19825
|
1261 @@skip:
|
pascal@19825
|
1262 pop es di si
|
pascal@19825
|
1263 ret
|
pascal@19825
|
1264
|
pascal@19825
|
1265 endp _progname
|
pascal@19825
|
1266
|
pascal@19825
|
1267
|
pascal@19825
|
1268 ;***************************************************************
|
pascal@19875
|
1269 ;void chdirname(char *path)
|
pascal@19825
|
1270 ;***************************************************************
|
pascal@19825
|
1271 global _chdirname:near
|
pascal@19825
|
1272 proc _chdirname near
|
pascal@19825
|
1273
|
pascal@19825
|
1274 pop ax
|
pascal@19825
|
1275 pop bx
|
pascal@19825
|
1276 push bx
|
pascal@19825
|
1277 push ax
|
pascal@19825
|
1278
|
pascal@20146
|
1279 cmp [byte bx+1],3Ah ; ':'
|
pascal@19825
|
1280 jne @@nodisk
|
pascal@19875
|
1281 mov dl,20h
|
pascal@19875
|
1282 or dl,[bx]
|
pascal@19825
|
1283 sub dl,61h
|
pascal@19825
|
1284 mov ah,0Eh
|
pascal@19825
|
1285 int 21h
|
pascal@19825
|
1286 inc bx
|
pascal@19825
|
1287 inc bx
|
pascal@19825
|
1288 @@nodisk:
|
pascal@19825
|
1289 xor cx,cx
|
pascal@19825
|
1290 @@next:
|
pascal@19825
|
1291 mov al,[bx]
|
pascal@19825
|
1292 cmp al,5Ch
|
pascal@19825
|
1293 jne @@tsteos
|
pascal@19875
|
1294 mov dx,bx
|
pascal@19875
|
1295 inc cx
|
pascal@19825
|
1296 @@tsteos:
|
pascal@19825
|
1297 inc bx
|
pascal@19825
|
1298 or al,al
|
pascal@19825
|
1299 jnz @@next
|
pascal@19825
|
1300 jcxz @@end
|
pascal@19875
|
1301 mov bx,dx
|
pascal@19825
|
1302 push [word bx]
|
pascal@19825
|
1303 mov [bx],al
|
pascal@19875
|
1304 stc
|
pascal@20146
|
1305 mov ax,713Bh ; chdir long filename (ds:dx)
|
pascal@19875
|
1306 int 21h
|
pascal@20146
|
1307 mov ah,3Bh ; chdir(ds:dx)
|
pascal@20510
|
1308 jnc @@chdirdone
|
pascal@19875
|
1309 int 21h
|
pascal@20510
|
1310 @@chdirdone:
|
pascal@19825
|
1311 pop [word bx]
|
pascal@19825
|
1312 @@end:
|
pascal@19825
|
1313 ret
|
pascal@19825
|
1314
|
pascal@19825
|
1315 endp _chdirname
|
pascal@19825
|
1316
|
pascal@19825
|
1317
|
pascal@19825
|
1318 ;***************************************************************
|
pascal@19825
|
1319 ;char *ultoa(unsigned long n);
|
pascal@19825
|
1320 ;***************************************************************
|
pascal@19825
|
1321 global _ultoa:near
|
pascal@19825
|
1322 proc _ultoa near
|
pascal@19825
|
1323
|
pascal@19825
|
1324 pop ax
|
pascal@19825
|
1325 pop cx
|
pascal@19825
|
1326 pop dx
|
pascal@19825
|
1327 push dx
|
pascal@19825
|
1328 push cx
|
pascal@19825
|
1329 push ax ; DX:CX = n
|
pascal@19825
|
1330 push si
|
pascal@19825
|
1331 mov si,10
|
pascal@19825
|
1332 mov bx,offset ultoabuf+11
|
pascal@19825
|
1333 @@loop:
|
pascal@19825
|
1334 dec bx
|
pascal@19825
|
1335 xchg ax,dx
|
pascal@19825
|
1336 xor dx,dx
|
pascal@19825
|
1337 div si ; DX:AX = 0000:hi(n)
|
pascal@19825
|
1338 xchg ax,cx ; CX = hi(n)/10
|
pascal@19825
|
1339 div si ; DX:AX = hi(n)%10:lo(n)
|
pascal@19825
|
1340 xchg ax,cx ; CX = lo(n/10)
|
pascal@19825
|
1341 xchg ax,dx ; DX = hi(n)/10 = hi(n/10)
|
pascal@19825
|
1342 add al,'0'
|
pascal@19825
|
1343 mov [bx],al
|
pascal@19825
|
1344 mov ax,cx
|
pascal@19825
|
1345 or ax,dx
|
pascal@19825
|
1346 jnz @@loop
|
pascal@19825
|
1347 xchg ax,bx
|
pascal@19825
|
1348 pop si
|
pascal@19825
|
1349 ret
|
pascal@19825
|
1350
|
pascal@19825
|
1351 endp _ultoa
|
pascal@19825
|
1352
|
pascal@19825
|
1353
|
pascal@19825
|
1354 ;***************************************************************
|
pascal@19825
|
1355 ;unsigned long kver2ul(char *kernel_version);
|
pascal@19825
|
1356 ;***************************************************************
|
pascal@19825
|
1357 global _kver2ul:near
|
pascal@19825
|
1358 proc _kver2ul near
|
pascal@19825
|
1359
|
pascal@19825
|
1360 pop bx
|
pascal@19825
|
1361 pop ax
|
pascal@19825
|
1362 push ax
|
pascal@19825
|
1363 push bx
|
pascal@20146
|
1364 push si
|
pascal@19825
|
1365 xchg ax,si
|
pascal@20146
|
1366 xor bx,bx
|
pascal@20146
|
1367 mov cx,304h
|
pascal@19825
|
1368 @@number:
|
pascal@19825
|
1369 xor ax,ax
|
pascal@20146
|
1370 cwd
|
pascal@19825
|
1371 @@digit:
|
pascal@19825
|
1372 shl al,cl
|
pascal@19825
|
1373 shl ax,cl
|
pascal@19825
|
1374 lodsb
|
pascal@19825
|
1375 sub al,30h
|
pascal@19825
|
1376 cmp al,9
|
pascal@19825
|
1377 jbe @@digit
|
pascal@20146
|
1378 mov dl,bh
|
pascal@20146
|
1379 mov bh,bl
|
pascal@20146
|
1380 mov bl,ah
|
pascal@20146
|
1381 dec ch
|
pascal@20146
|
1382 jnz @@number
|
pascal@20146
|
1383 xchg ax,bx
|
pascal@20146
|
1384 pop si
|
pascal@19825
|
1385 kver2ulret:
|
pascal@19825
|
1386 ret
|
pascal@19825
|
1387
|
pascal@19825
|
1388 endp _kver2ul
|
pascal@19825
|
1389
|
pascal@19825
|
1390
|
pascal@19825
|
1391 ;***************************************************************
|
pascal@19825
|
1392 ;void try_default_args();
|
pascal@19825
|
1393 ;***************************************************************
|
pascal@19825
|
1394 global _try_default_args:near
|
pascal@19825
|
1395 proc _try_default_args near
|
pascal@19825
|
1396
|
pascal@19825
|
1397 mov bx,offset tazboot_cmd
|
pascal@19825
|
1398 call open
|
pascal@19825
|
1399 jc kver2ulret
|
pascal@19825
|
1400 mov cx,4096
|
pascal@19825
|
1401 mov di,[_heap_top]
|
pascal@19825
|
1402 push cx
|
pascal@19825
|
1403 extrn read_cmdline:near
|
pascal@19825
|
1404 jmp near read_cmdline ; read_cmdline(ax,di,cx)
|
pascal@19825
|
1405
|
pascal@19825
|
1406 endp _try_default_args
|
pascal@19825
|
1407
|
pascal@19825
|
1408 endif
|
pascal@19825
|
1409
|
pascal@19515
|
1410 ends _TEXT
|
pascal@19515
|
1411
|
pascal@19515
|
1412 end
|
pascal@19515
|
1413
|
pascal@19515
|
1414 ;###### END OF FILE ############################################
|
pascal@19825
|
1415
|