wok view linld/stuff/src/CRTL.ASM @ rev 24152

linux64: built in nfs support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Mon Dec 06 10:55:21 2021 +0000 (2021-12-06)
parents 06547d8cf241
children dcf52a7882e6
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 255
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
12 ifdef NO386
13 p8086
14 else
15 p386
16 endif
18 group DGROUP _TEXT,_DATA,_BSS
19 assume cs:DGROUP,ds:DGROUP
21 segment _DATA byte public use16 'DATA'
23 loaderr db "Load failure",0
24 msg_hang db "Himem broken",0
25 ifdef VCPI
26 vcpi_alloc_err db "VCPI"
27 endif
28 global overflow:byte
29 overflow db "/"
30 msg_malloc db "Out of memory"
31 isorootofs dd 16*2048
33 ends _DATA
35 segment _BSS byte public use16 'BSS'
37 ifdef ISO9660
38 global _buf2k:byte
39 label _buf2k byte
40 db 2048 dup (?)
41 endif
42 global _buf4k:byte
43 label _buf4k byte
44 db 4096 dup (?)
46 ends _BSS
48 segment _TEXT byte public use16 'CODE'
50 ifdef VCPI
51 p386
52 ;***************************************************************
54 struc data_himem ;struct data_himem {
55 first dd ? ; 0 u32 first; *must* be the first one assume zero'd in bss
56 cacheidx dw ? ; 4 int cacheidx; quad * assume zero'd in bss
57 pageidx dw ? ; 6 int pageidx; byte * assume zero'd in bss
58 cache dd 1024 dup(?) ; 8 int cache;
59 page dd 1024 dup(?) ;4104 int page;
60 ends data_himem ;};
62 include "himem.inc"
64 ;***************************************************************
65 ;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m);
66 ;***************************************************************
67 global @malloc_bufv_or_die$qp11image_himem:near
68 proc @malloc_bufv_or_die$qp11image_himem near
70 p386
71 ;mov ecx,[(image_himem si).size]
72 ;shr ecx,20 ; pages index size = size >> 20
73 ;mov ax,cx
74 ;add ax,size data_himem-4096
75 mov ax,size data_himem
76 call malloc_or_die
77 ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
78 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
79 add ecx,[(image_himem si).size]
80 shr ecx,12
81 mov [(image_himem si).bufv],ax ; update m->bufv
82 xchg ax,di
83 @@vcpi_alloc:
84 mov ax,0DE04h ; allocate a 4K page => EDX
85 int 67h
86 or ah,ah
87 mov bx,offset vcpi_alloc_err
88 jnz jmpdie
89 ; for (i = cnt-1; i >= 0; i--)
90 ; if (edx < pm.fallback+pm.size) again
91 mov bx,offset _imgs.fallback+size image_himem
92 mov eax,[bx-2+6-size image_himem] ; pm.size
93 add eax,[bx-2+2-size image_himem]
94 cmp eax,edx ; pm.fallback+pm.size <= edx ?
95 ja @@vcpi_alloc
96 mov eax,ecx
97 dec eax
98 shl eax,12 ; i*_4k
99 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
100 add eax,[bx-2+2] ; +initrd.fallback
101 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
102 ja @@initrdok
103 mov eax,[bx-2+6] ; initrd.size
104 add eax,[bx-2+2] ; +initrd.fallback
105 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
106 @@ja_vcpi_alloc:
107 ja @@vcpi_alloc
108 @@initrdok:
109 cmp [(data_himem di).first],0 ; zero'd in bss
110 jne @@notfirst
111 mov [(data_himem di).first],edx
112 @@notfirst:
113 mov bx,[(data_himem di).cacheidx] ; zero'd in bss
114 cmp bh,4
115 jae @@nextpage
116 shl bx,2
117 inc [(data_himem di).cacheidx]
118 mov [(data_himem bx+di).cache],edx ; cache[cacheidx++] = edx
119 loopd @@vcpi_alloc
120 mov [(data_himem bx+di).cache],ecx ; last is 0
121 @@nextpage:
122 and [(data_himem di).cacheidx],0
123 mov bx,[(data_himem di).pageidx] ; zero'd in bss
124 mov [(data_himem bx+di).page],edx
125 add [(data_himem di).pageidx],4
126 push cx
127 lea cx,[(data_himem di).cache]
128 ifdef NO386
129 push edx
130 pop ax ; to es:ax
131 pop es
132 endif
133 call storepage ; storepage(edx/es:ax,cx)
134 pop cx
135 or ecx,ecx ; clear C
136 jnz @@ja_vcpi_alloc
138 endp @malloc_bufv_or_die$qp11image_himem
140 ;***************************************************************
141 ;_fastcall void reset_bufv(di:u32 *p);
142 ;***************************************************************
143 global @reset_bufv$qpul:near
144 proc @reset_bufv$qpul near
146 mov [curdata],di
147 and [dword (data_himem di).cacheidx],0 ; and pageidx=0
148 ret
150 endp @reset_bufv$qpul
152 ;***************************************************************
153 ;u32* di=prev_bufv();
154 ;u32* di=prev_bufv();
155 ;***************************************************************
156 global _prev_bufv:near
157 global _next_bufv:near
158 proc _prev_bufv near
160 stc
161 db 73h ; jnc
162 _next_bufv:
163 clc
164 push si
165 mov bx,0
166 org $-2
167 curdata dw ?
168 sbb ax,ax
169 cmc
170 adc ax,[(data_himem bx).cacheidx] ; -1/+1
171 mov si,3ffh
172 and si,ax
173 mov [(data_himem bx).cacheidx],si
174 shl si,2
175 xor ecx,ecx
176 test ax,0fc00h
177 jz @@gotpage ; FFFF / 0400
178 xchg al,ah ; FFFC / 0004
179 and al,0fch
180 add [(data_himem bx).pageidx],ax
181 mov di,[(data_himem bx).pageidx]
182 lea di,[(data_himem bx+di).page]
183 mov edx,ds
184 shl edx,4
185 lea cx,[(data_himem bx).cache]
186 add edx,ecx
187 mov eax,[di]
188 or eax,eax
189 jz @@ret
190 mov cx,4096 ; get page
191 call memcpy_imagez ; memcpy_imagez(edx,eax,ecx)
192 @@gotpage:
193 lea ax,[(data_himem bx+si).cache]
194 or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx
195 jnz @@notfirst2
196 xchg ax,bx ; &first
197 @@notfirst2:
198 xchg ax,di
199 @@ret:
200 pop si
201 ret
203 endp _prev_bufv
204 endif
206 ifdef NO386
207 p8086
208 endif
210 ;***************************************************************
211 ;_fastcall void memcpy_image_initrd(si:struct image_himem *m);
212 ;_fastcall void memcpy_image_kernel(si:struct image_himem *m);
213 ;_fastcall void memcpy_image(bx:struct image_himem *m);
214 ;***************************************************************
215 global @memcpy_image_initrd$qv:near
216 @memcpy_image_initrd$qv:
217 lea bx,[si+size image_himem]
218 db 0A9h ; test ax,imm
219 global @memcpy_image_kernel$qv:near
220 @memcpy_image_kernel$qv:
221 mov bx,si
222 proc @memcpy_image$qp11image_himem near
224 ifndef NO386
225 mov edx,[(image_himem bx).fallback]
226 mov eax,[(image_himem bx).buf]
227 cmp eax,edx ; if (m->fallback != m->buf)
228 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
229 mov ecx,[(image_himem bx).size]
230 else
231 les cx,[((image_himem bx).buf)]
232 mov dx,es
233 les ax,[((image_himem bx).fallback)]
234 cmp ax,cx ; if (m->fallback != m->buf)
235 jnz @@do
236 cmp dx,[word ((image_himem bx).fallback)+2]
237 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
238 @@do:
239 push [((image_himem bx).size)]
240 xor bx,bx
241 call_memcpy32: ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
242 push dx ; [word ((image_himem bx).buf)+2]
243 push cx ; [word ((image_himem bx).buf)]
244 push bx
245 push es ; push es:ax
246 push ax
247 jmp @@memcpy
248 endif
249 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
250 p386
251 push ecx
252 push eax
253 push 0
254 ifndef NO386
255 call_memcpy32: ; call_memcpy32(to=edx,fromseg,fromofs,size)
256 endif
257 push edx
258 ifdef NO386
259 p8086
260 endif
261 @@memcpy:
262 extrn memcpy32:near
263 call near memcpy32
264 @@skip:
265 ret
267 global movedend:near
268 movedend:
270 endp @memcpy_image$qp11image_himem
272 ;***************************************************************
273 ;_fastcall void storepage(di:u32 *dst);
274 ;***************************************************************
275 global @storepage$qpul:near
276 proc @storepage$qpul near
278 ifndef NO386
279 mov edx,[di]
280 else
281 les ax,[dword di]
282 endif
283 mov cx,offset _buf4k
284 storepage: ; storepage(edx,cx)
285 ifndef NO386
286 push 0
287 push 4096
288 push 0
289 push cx
290 push ds ; call_memcpy32(to=edx,fromseg,fromofs,size)
291 else
292 xor dx,dx
293 push dx ; 0
294 mov bx,4096
295 push bx ; 4096
296 mov bx,ds ; call_memcpy32(to=es:ax,fromseg=bx,fromofs=dx:cx,size)
297 endif
298 jmp call_memcpy32
300 endp @storepage$qpul
302 ;***************************************************************
303 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
304 ;***************************************************************
305 global @strcatb$qpxzct1:near
306 proc @strcatb$qpxzct1 near
308 push si
309 xchg ax,si ; b
310 dec bx
311 @@catlp:
312 inc bx
313 cmp [byte bx],0 ; a=bx
314 jne @@catlp
315 db 0b8h,20h ; mov ax,??20h
316 @@cpylp:
317 lodsb
318 mov [bx],al
319 inc bx
320 or al,al
321 jne @@cpylp
322 pop si
323 catret:
324 ret
326 endp @strcatb$qpxzct1
329 ifdef NO386
330 p8086
331 endif
333 ifndef ISO9660
334 ;***************************************************************
335 ;_fastcall int:C open(bx:const char* name, int flags=O_RDONLY);
336 ;_fastcall int:C openargs(bx:const char* name, int flags=O_RDONLY);
337 ;***************************************************************
338 global openargs:near ; openargs(bx)
339 openargs:
340 cmp [byte bx],'@'
341 jne fail
342 inc bx
344 global @open$qpxzc:near
345 @open$qpxzc:
346 endif
347 opendos:
348 ifdef LONG_FILENAME
349 ;xchg ax,cx ; attributes
350 mov ax,716Ch
351 push bx si
352 mov si,bx
353 xor bx,bx ; R/O
354 cwd ; action = open
355 stc
356 int 21h
357 pop si dx
358 jnc openok
359 mov ax,3d00h ; read-only+compatibility
360 else
361 mov ah,3dh ; read-only+compatibility
362 mov dx,bx ; open(DS:DX=filename,al=access,cl=attributes)
363 endif
364 ;mov cl,0 ; attribute mask
365 call dos
366 ifdef ISO9660
367 jc catret
368 openok:
369 xchg ax,bx
370 mov ax,4202h
371 cwd
372 xor cx,cx
373 int 21h
374 mov [word _isostate.filesize],ax
375 mov [(word _isostate.filesize)+2],dx
376 xchg ax,bx
377 ;xor cx,cx
378 cwd
379 call seeksetpos0 ; filepos = 0
380 else
381 openok:
382 endif
383 xchg ax,bx ; fd
384 ret
386 ifdef ISO9660
388 include "isostate.inc"
389 extrn _isostate:isostate
391 ;***************************************************************
392 ;_fastcall int:C open(bx:const char* name, int flags=O_RDONLY);
393 ;_fastcall int:C openargs(bx:const char* name, int flags=O_RDONLY);
394 ;***************************************************************
395 global openargs:near ; openargs(bx)
396 openargs:
397 cmp [byte bx],'@'
398 jne fail
399 inc bx
401 global @open$qpxzc:near
402 @open$qpxzc:
403 ifdef LONG_FILENAME
404 mov cx,[_isostate.fd]
405 jcxz opendos
406 xchg ax,cx
407 else
408 mov ax,[_isostate.fd]
409 or ax,ax
410 je opendos
411 endif
412 ifdef ISOHOOK
413 cmp [byte bx],'!'
414 je @readmenu$qv
415 endif
416 extrn @_isoopen$qv:near
417 mov [word _isostate.filename2open],bx
418 jmp @_isoopen$qv ; filepos = 0
419 endif
422 ;***************************************************************
423 ;_fastcall int fileexist(bx:const char* name);
424 ;***************************************************************
425 global @fileexist$qpxzc:near
426 @fileexist$qpxzc:
427 call @open$qpxzc
428 jc fail
430 ;***************************************************************
431 ;_fastcall int close(ax:int fd);
432 ;***************************************************************
433 global @close$qi:near
434 proc @close$qi near
436 global close:near ; close(ax)
437 close:
438 mov bh,3Eh ; close(BX:handle)
439 ifdef ISO9660
440 mov cx,[_isostate.fd]
441 jcxz dosbx
442 endif
443 jmp fail
445 endp @close$qi
448 ;***************************************************************
449 ;_fastcall int readrm(si:struct himem *m, ax:int sz);
450 ;***************************************************************
451 global @readrm$qp11image_himemi:near
452 @readrm$qp11image_himemi:
453 xchg ax,dx ; sz
454 mov ax,[si] ; fd
455 mov bx,[si-2] ; data
456 proc @read$qipvi near
458 @read$dxbxax:
459 xchg ax,bx ; fd
460 @read$dxaxbx:
461 xchg ax,dx ; data
462 xchg ax,cx ; sz
463 global @read$cxdxbx:near
464 @read$cxdxbx:
465 ifdef ISO9660
466 push bx
467 mov bx,offset _isostate.filepos
468 push cx
469 mov cx,[bx-4] ; filesize
470 sub cx,[bx] ; filepos
471 mov ax,[bx-2]
472 sbb ax,[bx+2]
473 pop ax
474 ja @@axok
475 ;je @@rem
476 ;xor ax,ax
477 @@rem:
478 cmp cx,ax
479 jb @@cxok
480 @@axok:
481 xchg ax,cx
482 @@cxok:
483 add [bx],cx
484 adc [(word bx)+2],0
485 pop bx
486 endif
487 readfd:
488 mov ah,3Fh ; read(BX=handle,DS:DX=to,CX=count)
489 ;jcxz fail
490 dos:
491 int 21h
492 jnc doret
493 fail:
494 stc
495 failifc:
496 sbb ax,ax ; ax=-1 CF
497 doret:
498 ret
500 endp @read$qipvi
502 ;***************************************************************
503 ;_fastcall long rewind(ax:int fd);
504 ;***************************************************************
506 global @rewind$qi:near ; fd=ax
507 proc @rewind$qi near
509 rewind:
510 ifdef ISO9660
511 mov bx,offset _isostate.fileofs
512 jmp lseek
513 else
514 mov bl,0
515 lseek0:
516 xor cx,cx
517 xor dx,dx
518 jmp lseek
519 endif
521 endp @rewind$qi
524 ifdef ISOHOOK
525 ;***************************************************************
526 ;_fastcall int:bx readmenu(void);
527 ;***************************************************************
528 proc @readmenu$qv near
530 mov dx,20
531 xor cx,cx
532 call seeksetpos0 ; filepos = 0
533 mov dx,offset _isostate.fileofs
534 mov cl,8
535 push dx
536 call readfd ; // read x->fileofs & x->filesize
537 pop bx
538 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
539 mov ax,7FF0h ; old way : up to md5 signature
540 @@oldway:
541 xor ax,6FF0h ; new way : between Apple partitions = up to 1000h
542 neg word ptr [bx+4] ; fix x->filesize
543 js @@oldway
544 cwd
545 mov [word bx+6],dx
546 sub ax,[bx+4]
547 mov [word bx+2],dx
548 mov [bx],ax
549 call isolseek ; filepos = 0
550 xchg ax,bx ; fd
551 ret
553 endp @readmenu$qv
554 endif
556 ;***************************************************************
557 ;_fastcall void isolseek(bx:const unsigned long *offset);
558 ;***************************************************************
559 global @isolseek$qpxul:near
560 proc @isolseek$qpxul near
562 ifdef ISO9660
563 isolseek:
564 mov ax,[_isostate.fd]
565 lseek:
566 les dx,[dword bx]
567 mov cx,es
568 seeksetpos0:
569 xor bx,bx
570 mov [word _isostate.filepos],bx
571 mov [(word _isostate.filepos)+2],bx
572 else
573 lseek:
574 endif
575 mov bh,42h ; bx=fd cx:dx=offset al=whence
576 dosbx:
577 xchg ax,bx
578 jmp dos ; bx = fd
580 endp @isolseek$qpxul
582 ifdef ISO9660
583 ;***************************************************************
584 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
585 ;_fastcall int isoreadrootsector(void);
586 ;***************************************************************
587 global @isoreadrootsector$qv:near
588 @isoreadrootsector$qv:
589 mov bx,offset isorootofs
590 global @isoreadsector$qpxul:near
591 proc @isoreadsector$qpxul near
593 call isolseek ; filepos = 0
594 jc fail
595 mov cx,2048
596 mov dx,offset _buf2k
597 jmp readfd ; read(fd,buf2k,2048)
599 endp @isoreadsector$qpxul
600 endif
603 ifdef ISO9660
604 ifdef ISOHOOK
605 ;***************************************************************
606 ;_fastcall int strhead(ax:const char* a, bx:const char* b);
607 ;***************************************************************
608 global @strhead$qpxzct1:near
609 proc @strhead$qpxzct1 near
611 @@loop:
612 mov dh,[bx] ; dh = *b++
613 inc bx
614 xchg ax,bx
615 or dh,dh ; clear C
616 jz failifc ; return 0, bx=a tail, dh=0
617 xor dh,[bx] ; dh -= *a++
618 jne fail ; return -1
619 inc bx
620 xchg ax,bx
621 jmp @@loop
623 endp @strhead$qpxzct1
626 ;***************************************************************
627 ;_fastcall int strcmp(ax:const char* a, bx:const char* b);
628 ;***************************************************************
629 global @strcmp$qpxzct1:near
630 proc @strcmp$qpxzct1 near
632 call @strhead$qpxzct1
633 jne fail ; return -1
634 xor dh,[bx] ; clear C
635 jne fail ; return -1
636 jmp failifc ; return 0, dh=0
638 endp @strcmp$qpxzct1
640 else
642 ;***************************************************************
643 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
644 ;***************************************************************
645 global @strcmp$qpxzct1:near
646 proc @strcmp$qpxzct1 near
648 @@loop:
649 xchg ax,bx
650 mov dl,[bx] ; dl = *b++
651 inc bx
652 xchg ax,bx
653 xor dl,[bx] ; dl ^= *a++
654 ifndef RAW_ISO9660
655 ifndef ROCKRIDGE
656 and dl,0dfh ; case insensitive
657 endif
658 endif
659 jne fail ; return -1
660 inc bx
661 or dl,dl ; clear C
662 jz failifc ; return 0
663 jmp @@loop
665 endp @strcmp$qpxzct1
666 endif
667 endif
669 ;***************************************************************
670 ;_fastcall void puts(bx:const char* s):
671 ;***************************************************************
672 global @puts$qpxzc:near
674 ; global puts:near ; puts(bx)
675 @putsz:
676 call @putc
677 @puts$qpxzc:
678 puts:
679 mov dl,[bx]
680 inc bx
681 or dl,dl
682 jne @putsz
683 mov dl,10
684 @putc:
685 cmp dl,10
686 jne @putcz
687 call @putcz2
688 @putcz2:
689 xor dl,7 ; 10^13 1010^1101
690 @putcz:
691 mov ah,2
692 do_int21h:
693 int 21h
694 ret
697 ;***************************************************************
698 ;_fastcall char* malloc_or_die(ax:unsigned size);
699 ;***************************************************************
700 xchg_heap_top:
701 xchg ax,[bx]
702 ret
704 proc @malloc_or_die$qui near
706 malloc_or_die: ; ax = malloc_or_die(ax)
707 extrn _heap_top
708 mov bx,offset _heap_top
709 add ax,[bx]
710 jnc xchg_heap_top
711 mov bx,offset msg_malloc
713 endp @malloc_or_die$qui
716 ;***************************************************************
717 ;_fastcall int die(bx:const char* msg);
718 ;int exit(ax:int status);
719 ;int abort(void);
720 ;***************************************************************
721 global @die$qpxzc:near
722 proc @die$qpxzc near
723 @die$qpxzc:
724 global die:near ; die(bx)
725 die:
726 call puts
727 global @exit$qv:near
728 @exit$qv:
729 _exit:
730 extrn _imgs:image_himem
731 mov cx,[(word _imgs.buf)+2] ; no_exit ?
732 mov ah,4Ch
733 jcxz do_int21h
734 mov bx, offset msg_hang
735 call puts
736 ; global _abort:near
737 _abort:
738 cli
739 hlt
740 jmp _abort
742 endp @die$qpxzc
744 ;***************************************************************
745 ;_fastcall void open_image(si:struct image_himem *m, ax:const char *name);
746 ;***************************************************************
748 global @open_image$qp11image_himempxzc:near
749 proc @open_image$qp11image_himempxzc near
751 mov [(image_himem si).state],ax
752 push ax
753 @@next:
754 call next_chunk
755 ifndef NO386
756 add eax,3
757 and al,0FCh
758 add [(image_himem si).size],eax ; m->size += m->chunk_size size zero'd in bss
759 or eax,eax
760 else
761 add ax,3
762 adc dx,0
763 and al,0FCh
764 add [word (image_himem si).size],ax ; m->size += m->chunk_size size zero'd in bss
765 adc [word ((image_himem si).size)+2],dx
766 or ax,dx
767 endif
768 jnz @@next
769 pop [(image_himem si).state]
771 endp @open_image$qp11image_himempxzc
774 ;***************************************************************
775 ;static long next_chunk(struct image_himem *si);
776 ;***************************************************************
777 proc next_chunk near
779 ifndef NO_CLOSE
780 mov ax,[(image_himem si).fd]
781 call close
782 endif
783 ifndef NO386
784 xor eax,eax
785 else
786 xor ax,ax
787 cwd
788 endif
789 mov [(image_himem si).fd],ax
790 mov bx,[(image_himem si).state]
791 cmp al,[bx] ; ""
792 jz @@end
793 dec bx
794 push di
795 @@scan:
796 inc bx
797 mov al,[bx]
798 mov di,bx
799 or al,al
800 jz @@eos
801 sub al,','
802 jnz @@scan
803 inc bx
804 @@eos:
805 xchg [(image_himem si).state],bx ; set start of string
806 mov [current_file],bx
807 xchg [di],ax ; set temp eos (ax == 0)
808 push ax
809 call @open$qpxzc
810 pop [word di] ; restore string
811 pop di
812 jnc @@opened
813 loadfailure:
814 ;***************************************************************
815 ;_fastcall void loadfailure(void);
816 ;***************************************************************
817 global @loadfailure$qv:near
818 @loadfailure$qv:
819 mov bx,0
820 org $-2
821 current_file dw ?
822 call puts
823 mov bx,offset loaderr
824 jmpdie:
825 jmp die
826 @@opened:
827 mov [(image_himem si).fd],ax
828 ifndef NO_CLOSE
829 mov [(image_himem si).fd2close],ax
830 endif
831 ifdef ISO9660
832 ifndef NO386
833 mov eax,[_isostate.filesize]
834 else
835 les ax,[_isostate.filesize]
836 mov dx,es
837 endif
838 else
839 mov bl,02h ; SEEK_END
840 call lseek0
841 ifndef NO386
842 push eax
843 mov ax,[(image_himem si).fd]
844 call rewind
845 pop eax
846 else
847 push ax
848 push dx
849 mov ax,[(image_himem si).fd]
850 call rewind
851 pop dx
852 pop ax
853 endif
854 endif
855 @@end:
856 ifndef NO386
857 mov [(image_himem si).chunk_size],eax
858 else
859 mov [word (image_himem si).chunk_size],ax
860 mov [word ((image_himem si).chunk_size)+2],dx
861 endif
862 ret
864 endp next_chunk
867 ;***************************************************************
868 ;_fastcall int read_image(si:struct image_himem *m);
869 ;***************************************************************
870 global @read_image$qp11image_himem:near
871 proc @read_image$qp11image_himem near
873 push di
874 xor di,di
875 @@loop:
876 ifndef NO386
877 xor ecx,ecx
878 mov ch,4096/256
879 sub cx,di
880 mov eax,[(image_himem si).chunk_size]
881 cmp ecx,eax
882 jb @@szok
883 else
884 mov cx,4096
885 sub cx,di
886 mov ax,[word (image_himem si).chunk_size]
887 cmp cx,ax
888 jb @@szok
889 cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size
890 jne @@szok
891 endif
892 xchg ax,cx
893 @@szok:
894 jcxz image_done
895 lea dx,[di+_buf4k]
896 mov bx,[(image_himem si).fd]
897 call @read$cxdxbx
898 jb image_done
899 add di,ax
900 ifndef NO386
901 cwde ; ax < 8000h
902 cdq
903 sub [(image_himem si).chunk_size],eax
904 else
905 cwd ; ax < 8000h
906 sub [word (image_himem si).chunk_size],ax
907 sbb [word ((image_himem si).chunk_size)+2],dx
908 endif
909 @@fill:
910 test al,3
911 je @@filled
912 mov [di+_buf4k],dl
913 inc di
914 inc ax
915 jmp @@fill
916 @@filled:
917 ifndef NO386
918 sub [(image_himem si).remaining],eax
919 or edx,[word (image_himem si).chunk_size]
920 else
921 sub [word (image_himem si).remaining],ax
922 sbb [word ((image_himem si).remaining)+2],dx
923 mov ax,[word (image_himem si).chunk_size]
924 or ax,[word ((image_himem si).chunk_size)+2]
925 endif
926 jnz @@same_chunk
927 call next_chunk
928 @@same_chunk:
929 jmp @@loop
930 image_done:
931 xchg ax,di
932 pop di
933 ret
935 endp @read_image$qp11image_himem
937 ;***************************************************************
938 ;_fastcall const char **argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
939 ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
940 ;***************************************************************
941 global @argstr$qpxzcxt1ppxzc:near
942 proc @argstr$qpxzcxt1ppxzc near
944 mov cl,2
945 db 0a9h ; test ax,#
946 global @argnum$qpzcxpxzcpul:near
947 @argnum$qpzcxpxzcpul:
948 mov cl,4
949 push bx
950 xchg ax,bx ; keywords -> bx
951 xchg ax,cx ; s -> cx
952 cbw ; argstr:0002 argnum:0004
953 xchg ax,dx ; vars -> ax
954 push si di
955 xchg ax,di ; vars => di
956 dec bx
957 sub di,dx
958 @@loop:
959 add di,dx
960 mov si,cx ; s
961 @@match:
962 lodsb ; *s++
963 or al,20h ; locase
964 cmp al,'/' ; 2f
965 jne @@notopt
966 mov al,'-'
967 @@notopt:
968 inc bx ; keywords++
969 cmp al,[bx]
970 je @@match
971 cmp [byte bx],dh
972 je @@lastal
973 cmp [byte bx],'|'
974 je @@testal
975 jl @@notsw ; } ~ <del>
976 ;mov dl,1
977 cmp al,20h ; EOS or 20h
978 jne @@loop ; assume [bx] = '|'
979 @@notsw:
980 mov al,-1
981 jne @@notopt
982 jmp @@setnum2
983 @@testal:
984 cmp al,-1
985 jz @@loop
986 @@lastal:
987 cmp al,'='
988 xchg ax,cx ; return s if failure
989 jne @@nokeyword
990 dec dx
991 dec dx
992 je @@done
993 @strtol$qpxzc:
994 ifndef NO386
995 xor ecx,ecx
996 xor ebx,ebx
997 else
998 xor bx,bx
999 xor cx,cx
1000 xor dx,dx
1001 endif
1002 lodsb
1003 or al,20h
1004 cmp al,'a'
1005 jb @@notvga
1006 sub al,'o'
1007 @@vgaloop:
1008 dec cx
1009 add al,6
1010 jnb @@vgaloop ; vga=normal,extended,ask
1011 @@vga:
1012 xchg ax,cx
1013 ;cwd
1014 jmp @@end
1015 @@endstrtol:
1016 mov cl,10
1017 cmp al,'k'-'a'+10
1018 je @@shift
1019 mov cl,20
1020 cmp al,'m'-'a'+10
1021 je @@shift
1022 mov cl,30
1023 cmp al,'g'-'a'+10
1024 ifndef NO386
1025 jne @@noshift
1026 @@shift:
1027 shl ebx,cl
1028 @@noshift:
1029 popf
1030 jnc @@end2
1031 neg ebx
1032 @@end2:
1033 push ebx
1034 pop ax
1035 pop dx
1036 else
1037 @@shift:
1038 xchg ax,bx
1039 jne @@noshift
1040 extrn N_LXLSH@:near
1041 call N_LXLSH@
1042 @@noshift:
1043 popf
1044 jne @@end
1045 not dx
1046 neg ax
1047 jne @@end
1048 inc dx
1049 endif
1050 @@end:
1051 @@setnum:
1052 mov [di+2],dx
1053 @@setnum2:
1054 xchg ax,si
1055 @@done:
1056 or [di],si
1057 xchg ax,di
1058 @@nokeyword:
1059 pop di si bx
1060 ret
1062 @@notvga:
1063 mov cl,10 ; radix
1064 cmp al,'-'
1065 jne @@radixkeep
1066 lodsb
1067 @@radixkeep:
1068 pushf
1069 cmp al,'0'
1070 jne @@radixok
1071 mov cl,8
1072 lodsb
1073 or al,20h
1074 cmp al,'x'
1075 jne @@radixok
1076 mov cl,16
1077 @@strtollp:
1078 lodsb
1079 @@radixok:
1080 or al,20h
1081 sub al,'0'
1082 jb @@endstrtol
1083 cmp al,9
1084 jbe @@digitok
1085 cmp al,'a'-'0'
1086 jb @@endstrtol
1087 sub al,'a'-'0'-10
1088 @@digitok:
1089 cmp al,cl
1090 jae @@endstrtol
1091 cbw
1092 ifndef NO386
1093 cwde
1094 xchg eax,ebx
1095 mul ecx
1096 add ebx,eax
1097 else
1098 push ax
1099 xchg ax,dx
1100 mul cx
1101 xchg ax,bx
1102 mul cx
1103 add dx,bx
1104 pop bx
1105 add bx,ax
1106 adc dx,0
1107 endif
1108 jmp @@strtollp
1110 endp @argstr$qpxzcxt1ppxzc
1113 ends _TEXT
1115 end
1117 ;###### END OF FILE ############################################