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

Openssh (8.5p1)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 08 09:21:26 2021 +0000 (2021-04-08)
parents 217c02cbbe8d
children 06547d8cf241
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
540 cwd
541 mov [word bx+6],dx
542 sub ax,[bx+4]
543 mov [word bx+2],dx
544 mov [bx],ax
545 call isolseek ; filepos = 0
546 xchg ax,bx ; fd
547 ret
549 endp @readmenu$qv
550 endif
552 ;***************************************************************
553 ;_fastcall void isolseek(bx:const unsigned long *offset);
554 ;***************************************************************
555 global @isolseek$qpxul:near
556 proc @isolseek$qpxul near
558 ifdef ISO9660
559 isolseek:
560 mov ax,[_isostate.fd]
561 lseek:
562 les dx,[dword bx]
563 mov cx,es
564 seeksetpos0:
565 xor bx,bx
566 mov [word _isostate.filepos],bx
567 mov [(word _isostate.filepos)+2],bx
568 else
569 lseek:
570 endif
571 mov bh,42h ; bx=fd cx:dx=offset al=whence
572 dosbx:
573 xchg ax,bx
574 jmp dos ; bx = fd
576 endp @isolseek$qpxul
578 ifdef ISO9660
579 ;***************************************************************
580 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
581 ;_fastcall int isoreadrootsector(void);
582 ;***************************************************************
583 global @isoreadrootsector$qv:near
584 @isoreadrootsector$qv:
585 mov bx,offset isorootofs
586 global @isoreadsector$qpxul:near
587 proc @isoreadsector$qpxul near
589 call isolseek ; filepos = 0
590 jc fail
591 mov cx,2048
592 mov dx,offset _buf2k
593 jmp readfd ; read(fd,buf2k,2048)
595 endp @isoreadsector$qpxul
596 endif
599 ifdef ISO9660
600 ifdef ISOHOOK
601 ;***************************************************************
602 ;_fastcall int strhead(ax:const char* a, bx:const char* b);
603 ;***************************************************************
604 global @strhead$qpxzct1:near
605 proc @strhead$qpxzct1 near
607 @@loop:
608 mov dh,[bx] ; dh = *b++
609 inc bx
610 xchg ax,bx
611 or dh,dh ; clear C
612 jz failifc ; return 0, bx=a tail, dh=0
613 xor dh,[bx] ; dh -= *a++
614 jne fail ; return -1
615 inc bx
616 xchg ax,bx
617 jmp @@loop
619 endp @strhead$qpxzct1
622 ;***************************************************************
623 ;_fastcall int strcmp(ax:const char* a, bx:const char* b);
624 ;***************************************************************
625 global @strcmp$qpxzct1:near
626 proc @strcmp$qpxzct1 near
628 call @strhead$qpxzct1
629 jne fail ; return -1
630 xor dh,[bx] ; clear C
631 jne fail ; return -1
632 jmp failifc ; return 0, dh=0
634 endp @strcmp$qpxzct1
636 else
638 ;***************************************************************
639 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
640 ;***************************************************************
641 global @strcmp$qpxzct1:near
642 proc @strcmp$qpxzct1 near
644 @@loop:
645 xchg ax,bx
646 mov dl,[bx] ; dl = *b++
647 inc bx
648 xchg ax,bx
649 xor dl,[bx] ; dl ^= *a++
650 ifndef RAW_ISO9660
651 ifndef ROCKRIDGE
652 and dl,0dfh ; case insensitive
653 endif
654 endif
655 jne fail ; return -1
656 inc bx
657 or dl,dl ; clear C
658 jz failifc ; return 0
659 jmp @@loop
661 endp @strcmp$qpxzct1
662 endif
663 endif
665 ;***************************************************************
666 ;_fastcall void puts(bx:const char* s):
667 ;***************************************************************
668 global @puts$qpxzc:near
670 ; global puts:near ; puts(bx)
671 @putsz:
672 call @putc
673 @puts$qpxzc:
674 puts:
675 mov dl,[bx]
676 inc bx
677 or dl,dl
678 jne @putsz
679 mov dl,10
680 @putc:
681 cmp dl,10
682 jne @putcz
683 call @putcz2
684 @putcz2:
685 xor dl,7 ; 10^13 1010^1101
686 @putcz:
687 mov ah,2
688 do_int21h:
689 int 21h
690 ret
693 ;***************************************************************
694 ;_fastcall char* malloc_or_die(ax:unsigned size);
695 ;***************************************************************
696 xchg_heap_top:
697 xchg ax,[bx]
698 ret
700 proc @malloc_or_die$qui near
702 malloc_or_die: ; ax = malloc_or_die(ax)
703 extrn _heap_top
704 mov bx,offset _heap_top
705 add ax,[bx]
706 jnc xchg_heap_top
707 mov bx,offset msg_malloc
709 endp @malloc_or_die$qui
712 ;***************************************************************
713 ;_fastcall int die(bx:const char* msg);
714 ;int exit(ax:int status);
715 ;int abort(void);
716 ;***************************************************************
717 global @die$qpxzc:near
718 proc @die$qpxzc near
719 @die$qpxzc:
720 global die:near ; die(bx)
721 die:
722 call puts
723 global @exit$qv:near
724 @exit$qv:
725 _exit:
726 extrn _imgs:image_himem
727 mov cx,[(word _imgs.buf)+2] ; no_exit ?
728 mov ah,4Ch
729 jcxz do_int21h
730 mov bx, offset msg_hang
731 call puts
732 ; global _abort:near
733 _abort:
734 cli
735 hlt
736 jmp _abort
738 endp @die$qpxzc
740 ;***************************************************************
741 ;_fastcall void open_image(si:struct image_himem *m, ax:const char *name);
742 ;***************************************************************
744 global @open_image$qp11image_himempxzc:near
745 proc @open_image$qp11image_himempxzc near
747 mov [(image_himem si).state],ax
748 push ax
749 @@next:
750 call next_chunk
751 ifndef NO386
752 add eax,3
753 and al,0FCh
754 add [(image_himem si).size],eax ; m->size += m->chunk_size size zero'd in bss
755 or eax,eax
756 else
757 add ax,3
758 adc dx,0
759 and al,0FCh
760 add [word (image_himem si).size],ax ; m->size += m->chunk_size size zero'd in bss
761 adc [word ((image_himem si).size)+2],dx
762 or ax,dx
763 endif
764 jnz @@next
765 pop [(image_himem si).state]
767 endp @open_image$qp11image_himempxzc
770 ;***************************************************************
771 ;static long next_chunk(struct image_himem *si);
772 ;***************************************************************
773 proc next_chunk near
775 ifndef NO_CLOSE
776 mov ax,[(image_himem si).fd]
777 call close
778 endif
779 ifndef NO386
780 xor eax,eax
781 else
782 xor ax,ax
783 cwd
784 endif
785 mov [(image_himem si).fd],ax
786 mov bx,[(image_himem si).state]
787 cmp al,[bx] ; ""
788 jz @@end
789 dec bx
790 push di
791 @@scan:
792 inc bx
793 mov al,[bx]
794 mov di,bx
795 or al,al
796 jz @@eos
797 sub al,','
798 jnz @@scan
799 inc bx
800 @@eos:
801 xchg [(image_himem si).state],bx ; set start of string
802 mov [current_file],bx
803 xchg [di],ax ; set temp eos (ax == 0)
804 push ax
805 call @open$qpxzc
806 pop [word di] ; restore string
807 pop di
808 jnc @@opened
809 loadfailure:
810 ;***************************************************************
811 ;_fastcall void loadfailure(void);
812 ;***************************************************************
813 global @loadfailure$qv:near
814 @loadfailure$qv:
815 mov bx,0
816 org $-2
817 current_file dw ?
818 call puts
819 mov bx,offset loaderr
820 jmpdie:
821 jmp die
822 @@opened:
823 mov [(image_himem si).fd],ax
824 ifndef NO_CLOSE
825 mov [(image_himem si).fd2close],ax
826 endif
827 ifdef ISO9660
828 ifndef NO386
829 mov eax,[_isostate.filesize]
830 else
831 les ax,[_isostate.filesize]
832 mov dx,es
833 endif
834 else
835 mov bl,02h ; SEEK_END
836 call lseek0
837 ifndef NO386
838 push eax
839 mov ax,[(image_himem si).fd]
840 call rewind
841 pop eax
842 else
843 push ax
844 push dx
845 mov ax,[(image_himem si).fd]
846 call rewind
847 pop dx
848 pop ax
849 endif
850 endif
851 @@end:
852 ifndef NO386
853 mov [(image_himem si).chunk_size],eax
854 else
855 mov [word (image_himem si).chunk_size],ax
856 mov [word ((image_himem si).chunk_size)+2],dx
857 endif
858 ret
860 endp next_chunk
863 ;***************************************************************
864 ;_fastcall int read_image(si:struct image_himem *m);
865 ;***************************************************************
866 global @read_image$qp11image_himem:near
867 proc @read_image$qp11image_himem near
869 push di
870 xor di,di
871 @@loop:
872 ifndef NO386
873 xor ecx,ecx
874 mov ch,4096/256
875 sub cx,di
876 mov eax,[(image_himem si).chunk_size]
877 cmp ecx,eax
878 jb @@szok
879 else
880 mov cx,4096
881 sub cx,di
882 mov ax,[word (image_himem si).chunk_size]
883 cmp cx,ax
884 jb @@szok
885 cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size
886 jne @@szok
887 endif
888 xchg ax,cx
889 @@szok:
890 jcxz image_done
891 lea dx,[di+_buf4k]
892 mov bx,[(image_himem si).fd]
893 call @read$cxdxbx
894 jb image_done
895 add di,ax
896 ifndef NO386
897 cwde ; ax < 8000h
898 cdq
899 sub [(image_himem si).chunk_size],eax
900 else
901 cwd ; ax < 8000h
902 sub [word (image_himem si).chunk_size],ax
903 sbb [word ((image_himem si).chunk_size)+2],dx
904 endif
905 @@fill:
906 test al,3
907 je @@filled
908 mov [di+_buf4k],dl
909 inc di
910 inc ax
911 jmp @@fill
912 @@filled:
913 ifndef NO386
914 sub [(image_himem si).remaining],eax
915 or edx,[word (image_himem si).chunk_size]
916 else
917 sub [word (image_himem si).remaining],ax
918 sbb [word ((image_himem si).remaining)+2],dx
919 mov ax,[word (image_himem si).chunk_size]
920 or ax,[word ((image_himem si).chunk_size)+2]
921 endif
922 jnz @@same_chunk
923 call next_chunk
924 @@same_chunk:
925 jmp @@loop
926 image_done:
927 xchg ax,di
928 pop di
929 ret
931 endp @read_image$qp11image_himem
933 ;***************************************************************
934 ;_fastcall const char **argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
935 ;_fastcall unsigned long *argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
936 ;***************************************************************
937 global @argstr$qpxzcxt1ppxzc:near
938 proc @argstr$qpxzcxt1ppxzc near
940 mov cl,2
941 db 0a9h ; test ax,#
942 global @argnum$qpzcxpxzcpul:near
943 @argnum$qpzcxpxzcpul:
944 mov cl,4
945 push bx
946 xchg ax,bx ; keywords -> bx
947 xchg ax,cx ; s -> cx
948 cbw ; argstr:0002 argnum:0004
949 xchg ax,dx ; vars -> ax
950 push si di
951 xchg ax,di ; vars => di
952 dec bx
953 sub di,dx
954 @@loop:
955 mov si,cx ; s
956 add di,dx
957 @@match:
958 lodsb ; *s++
959 or al,20h ; locase
960 cmp al,'/' ; 2f
961 jne @@notopt
962 mov al,'-'
963 @@notopt:
964 inc bx ; keywords++
965 cmp al,[bx]
966 je @@match
967 cmp [byte bx],dh
968 je @@lastal
969 cmp [byte bx],'|'
970 je @@testal
971 jl @@notsw ; } ~ <del>
972 cmp al,20h ; EOS or 20h
973 jne @@loop ; assume [bx] = '|'
974 @@notsw:
975 mov al,-1
976 jne @@notopt
977 jmp @@setnum
978 @@testal:
979 cmp al,-1
980 jz @@loop
981 @@lastal:
982 cmp al,'='
983 xchg ax,cx ; return s if failure
984 jne @@nokeyword
985 dec dx
986 dec dx
987 je @@done
988 @strtol$qpxzc:
989 ifndef NO386
990 xor ecx,ecx
991 xor ebx,ebx
992 else
993 xor bx,bx
994 xor cx,cx
995 xor dx,dx
996 endif
997 lodsb
998 or al,20h
999 cmp al,'a'
1000 jb @@notvga
1001 sub al,'o'
1002 @@vgaloop:
1003 dec cx
1004 add al,6
1005 jnb @@vgaloop ; vga=normal,extended,ask
1006 @@vga:
1007 xchg ax,cx
1008 ;cwd
1009 jmp @@end
1010 @@endstrtol:
1011 mov cl,10
1012 cmp al,'k'-'a'+10
1013 je @@shift
1014 mov cl,20
1015 cmp al,'m'-'a'+10
1016 je @@shift
1017 mov cl,30
1018 cmp al,'g'-'a'+10
1019 ifndef NO386
1020 jne @@noshift
1021 @@shift:
1022 shl ebx,cl
1023 @@noshift:
1024 popf
1025 jnc @@end2
1026 neg ebx
1027 @@end2:
1028 push ebx
1029 pop ax
1030 pop dx
1031 else
1032 @@shift:
1033 xchg ax,bx
1034 jne @@noshift
1035 extrn N_LXLSH@:near
1036 call N_LXLSH@
1037 @@noshift:
1038 popf
1039 jne @@end
1040 not dx
1041 neg ax
1042 jne @@end
1043 inc dx
1044 endif
1045 @@end:
1046 @@setnum:
1047 xchg ax,si
1048 mov [di+2],dx
1049 @@done:
1050 mov [di],si
1051 xchg ax,di
1052 @@nokeyword:
1053 pop di si bx
1054 ret
1056 @@notvga:
1057 mov cl,10 ; radix
1058 cmp al,'-'
1059 jne @@radixkeep
1060 lodsb
1061 @@radixkeep:
1062 pushf
1063 cmp al,'0'
1064 jne @@radixok
1065 mov cl,8
1066 lodsb
1067 or al,20h
1068 cmp al,'x'
1069 jne @@radixok
1070 mov cl,16
1071 @@strtollp:
1072 lodsb
1073 @@radixok:
1074 or al,20h
1075 sub al,'0'
1076 jb @@endstrtol
1077 cmp al,9
1078 jbe @@digitok
1079 cmp al,'a'-'0'
1080 jb @@endstrtol
1081 sub al,'a'-'0'-10
1082 @@digitok:
1083 cmp al,cl
1084 jae @@endstrtol
1085 cbw
1086 ifndef NO386
1087 cwde
1088 xchg eax,ebx
1089 mul ecx
1090 add ebx,eax
1091 else
1092 push ax
1093 xchg ax,dx
1094 mul cx
1095 xchg ax,bx
1096 mul cx
1097 add dx,bx
1098 pop bx
1099 add bx,ax
1100 adc dx,0
1101 endif
1102 jmp @@strtollp
1104 endp @argstr$qpxzcxt1ppxzc
1107 ends _TEXT
1109 end
1111 ;###### END OF FILE ############################################