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

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