wok-current view linld/stuff/src/CRTL.ASM @ rev 24014

linld: add quick boot switch (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Feb 19 18:33:17 2021 +0000 (2021-02-19)
parents bc4b94310a29
children 14ca5e18cfd9
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 sub di,dx
375 @@loop:
376 mov si,cx ; s
377 add di,dx
378 @@match:
379 lodsb ; *s++
380 or al,20h ; locase
381 cmp al,'/' ; 2f
382 jne @@notopt
383 mov al,'-'
384 @@notopt:
385 inc bx ; keywords++
386 cmp al,[bx]
387 je @@match
388 cmp [byte bx],dh
389 je @@lastal
390 cmp [byte bx],'|'
391 je @@testal
392 jl @@notsw ; } ~ <del>
393 cmp al,20h ; EOS or 20h
394 jne @@loop ; assume [bx] = '|'
395 @@notsw:
396 mov ax,-1
397 jne @@notopt
398 jmp @@setnum
399 @@testal:
400 inc ax
401 jz @@loop
402 @@lastal:
403 cmp al,'='+1
404 xchg ax,cx ; return s if failure
405 jne @@nokeyword
406 dec dx
407 dec dx
408 je @@done
409 call @strtol$qpxzc
410 @@setnum:
411 xchg ax,si
412 mov [di+2],dx
413 @@done:
414 mov [di],si
415 xchg ax,di
416 @@nokeyword:
417 pop di si bx
418 ret
420 endp @argstr$qpxzcxt1ppxzc
422 ;***************************************************************
423 ;_fastcall void puts(bx:const char* s):
424 ;***************************************************************
425 global @puts$qpxzc:near
427 ; global puts:near ; puts(bx)
428 @putsz:
429 call @putc
430 @puts$qpxzc:
431 puts:
432 mov dl,[bx]
433 inc bx
434 or dl,dl
435 jne @putsz
436 mov dl,10
437 @putc:
438 cmp dl,10
439 jne @putcz
440 call @putcz2
441 @putcz2:
442 xor dl,7 ; 10^13 1010^1101
443 @putcz:
444 mov ah,2
445 do_int21h:
446 int 21h
447 ret
450 include "himem.inc"
452 ;***************************************************************
453 ;_fastcall char* malloc_or_die(ax:unsigned size);
454 ;***************************************************************
455 xchg_heap_top:
456 xchg ax,[bx]
457 ret
459 proc @malloc_or_die$qui near
461 malloc_or_die: ; ax = malloc_or_die(ax)
462 extrn _heap_top
463 mov bx,offset _heap_top
464 add ax,[bx]
465 jnc xchg_heap_top
466 mov bx,offset msg_malloc
468 endp @malloc_or_die$qui
471 ;***************************************************************
472 ;_fastcall int die(bx:const char* msg);
473 ;int exit(ax:int status);
474 ;int abort(void);
475 ;***************************************************************
476 global @die$qpxzc:near
477 proc @die$qpxzc near
478 @die$qpxzc:
479 global die:near ; die(bx)
480 die:
481 call puts
482 global @exit$qv:near
483 @exit$qv:
484 _exit:
485 extrn _imgs:image_himem
486 mov cx,[(word _imgs.buf)+2] ; no_exit ?
487 mov ah,4Ch
488 jcxz do_int21h
489 mov bx, offset msg_hang
490 call puts
491 ; global _abort:near
492 _abort:
493 cli
494 hlt
495 jmp _abort
497 endp @die$qpxzc
499 ;***************************************************************
500 ;_fastcall void open_image(si:struct image_himem *m, ax:const char *name);
501 ;***************************************************************
503 global @open_image$qp11image_himempxzc:near
504 proc @open_image$qp11image_himempxzc near
506 mov [(image_himem si).state],ax
507 push ax
508 @@next:
509 call next_chunk
510 ifndef NO386
511 add eax,3
512 and al,0FCh
513 add [(image_himem si).size],eax ; m->size += m->chunk_size
514 or eax,eax
515 else
516 add ax,3
517 adc dx,0
518 and al,0FCh
519 add [word (image_himem si).size],ax ; m->size += m->chunk_size
520 adc [word ((image_himem si).size)+2],dx
521 or ax,dx
522 endif
523 jnz @@next
524 pop [(image_himem si).state]
526 endp @open_image$qp11image_himempxzc
529 ;***************************************************************
530 ;static long next_chunk(struct image_himem *si);
531 ;***************************************************************
532 proc next_chunk near
534 ifndef NO_CLOSE
535 mov ax,[(image_himem si).fd]
536 call close
537 endif
538 ifndef NO386
539 xor eax,eax
540 else
541 xor ax,ax
542 cwd
543 endif
544 mov [(image_himem si).fd],ax
545 mov bx,[(image_himem si).state]
546 cmp al,[bx] ; ""
547 jz @@end
548 dec bx
549 push di
550 @@scan:
551 inc bx
552 mov al,[bx]
553 mov di,bx
554 or al,al
555 jz @@eos
556 sub al,','
557 jnz @@scan
558 inc bx
559 @@eos:
560 xchg [(image_himem si).state],bx ; set start of string
561 mov [current_file],bx
562 xchg [di],ax ; set temp eos (ax == 0)
563 push ax
564 call @open$qpxzc
565 pop [word di] ; restore string
566 pop di
567 jnc @@opened
568 loadfailure:
569 ;***************************************************************
570 ;_fastcall void loadfailure(void);
571 ;***************************************************************
572 global @loadfailure$qv:near
573 @loadfailure$qv:
574 mov bx,0
575 org $-2
576 current_file dw ?
577 call puts
578 mov bx,offset loaderr
579 jmpdie:
580 jmp die
581 @@opened:
582 mov [(image_himem si).fd],ax
583 ifndef NO_CLOSE
584 mov [(image_himem si).fd2close],ax
585 endif
586 ifndef NO386
587 mov eax,[_isostate.filesize]
588 @@end:
589 mov [(image_himem si).chunk_size],eax
590 else
591 mov ax,[word _isostate.filesize]
592 mov dx,[(word _isostate.filesize)+2]
593 @@end:
594 mov [word (image_himem si).chunk_size],ax
595 mov [word ((image_himem si).chunk_size)+2],dx
596 endif
597 ret
599 endp next_chunk
601 ;***************************************************************
603 struc data_himem ;struct data_himem {
604 first dd ? ; 0 u32 first; *must* be the first one
605 cacheidx dw ? ; 4 int cacheidx; quad *
606 pageidx dw ? ; 6 int pageidx; byte *
607 cache dd 1024 dup(?) ; 8 int cache;
608 page dd 1024 dup(?) ;4104 int page;
609 ends data_himem ;};
611 ;***************************************************************
612 ;_fastcall u32* malloc_bufv_or_die(si:struct image_himem *m);
613 ;***************************************************************
614 global @malloc_bufv_or_die$qp11image_himem:near
615 proc @malloc_bufv_or_die$qp11image_himem near
617 p386
618 push si
619 ;mov ecx,[(image_himem si).size]
620 ;shr ecx,20 ; pages index size = size >> 20
621 ;mov ax,cx
622 ;add ax,size data_himem-4096
623 mov ax,size data_himem
624 call malloc_or_die
625 ;mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
626 mov ecx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
627 add ecx,[(image_himem si).size]
628 shr ecx,12
629 mov [curdata],ax
630 mov [(image_himem si).bufv],ax ; update m->bufv
631 xchg ax,si
632 @@vcpi_alloc:
633 mov ax,0DE04h ; allocate a 4K page => EDX
634 int 67h
635 or ah,ah
636 mov bx,offset vcpi_alloc_err
637 jnz jmpdie
638 ; for (i = cnt-1; i >= 0; i--)
639 mov eax,ecx
640 dec eax
641 shl eax,12 ; i*_4k
642 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
643 mov bx,offset _imgs.fallback
644 push eax
645 add eax,[bx-2+2]
646 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
647 pop eax ; i*_4k
648 jbe @@pmok
649 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
650 jae @@vcpi_alloc
651 @@pmok:
652 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
653 add eax,[bx-2+2+size image_himem] ; +initrd.fallback
654 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
655 ja @@initrdok
656 mov eax,[bx-2+6+size image_himem] ; initrd.size
657 add eax,[bx-2+2+size image_himem] ; +initrd.fallback
658 cmp eax,edx ; initrd.fallback+initrd.size > edx ?
659 @@ja_vcpi_alloc:
660 ja @@vcpi_alloc
661 @@initrdok:
662 cmp [(data_himem si).first],0
663 jne @@notfirst
664 mov [(data_himem si).first],edx
665 @@notfirst:
666 mov bx,[(data_himem si).cacheidx]
667 cmp bh,4
668 jae @@nextpage
669 shl bx,2
670 inc [(data_himem si).cacheidx]
671 mov [(data_himem bx+si).cache],edx ; cache[cacheidx++] = edx
672 loopd @@vcpi_alloc
673 mov [(data_himem bx+si).cache],ecx ; last is 0
674 @@nextpage:
675 and [(data_himem si).cacheidx],0
676 mov bx,[(data_himem si).pageidx]
677 mov [(data_himem bx+si).page],edx
678 add [(data_himem si).pageidx],4
679 push cx
680 lea cx,[(data_himem si).cache]
681 ifdef NO386
682 push edx
683 pop ax ; to dx:ax
684 pop dx
685 endif
686 call storepage ; storepage(edx,cx)
687 pop cx
688 or ecx,ecx ; clear C
689 jnz @@ja_vcpi_alloc
690 mov [dword (data_himem si).cacheidx],ecx
691 xchg ax,si
692 pop si
693 ret
694 ifdef NO386
695 p8086
696 endif
698 endp @malloc_bufv_or_die$qp11image_himem
701 ;***************************************************************
702 ;_fastcall void memcpy_image_initrd(si:struct image_himem *m);
703 ;_fastcall void memcpy_image_kernel(si:struct image_himem *m);
704 ;_fastcall void memcpy_image(bx:struct image_himem *m);
705 ;***************************************************************
706 global @memcpy_image_initrd$qv:near
707 @memcpy_image_initrd$qv:
708 lea bx,[si+size image_himem]
709 db 0A9h ; test ax,imm
710 global @memcpy_image_kernel$qv:near
711 @memcpy_image_kernel$qv:
712 mov bx,si
713 proc @memcpy_image$qp11image_himem near
715 ifndef NO386
716 mov edx,[(image_himem bx).fallback]
717 mov eax,[(image_himem bx).buf]
718 cmp eax,edx ; if (m->fallback != m->buf)
719 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
720 mov ecx,[(image_himem bx).size]
721 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
722 push ecx
723 push eax
724 push 0
725 call_memcpy32:
726 push edx
727 else
728 les ax,[dword ((image_himem bx).fallback)]
729 mov dx,es
730 les cx,[dword ((image_himem bx).buf)]
731 cmp ax,cx ; if (m->fallback != m->buf)
732 jnz @@do
733 cmp dx,[word ((image_himem bx).buf)+2]
734 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
735 @@do:
736 push [word ((image_himem bx).size)+2]
737 push [word ((image_himem bx).size)]
738 push es ; [word ((image_himem bx).buf)+2]
739 push cx ; [word ((image_himem bx).buf)]
740 xor cx,cx
741 push cx
742 call_memcpy32:
743 push dx ; push dx:ax
744 push ax
745 jmp @@memcpy
746 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
747 p386
748 push ecx
749 push eax
750 push 0
751 push edx
752 ifdef NO386
753 p8086
754 endif
755 endif
756 @@memcpy:
757 extrn memcpy32:near
758 call near memcpy32
759 @@skip:
760 ret
762 endp @memcpy_image$qp11image_himem
764 ;***************************************************************
765 ;_fastcall void storepage(di:u32 *dst);
766 ;***************************************************************
767 global @storepage$qpul:near
768 proc @storepage$qpul near
770 ifndef NO386
771 mov edx,[di]
772 else
773 les ax,[dword di]
774 mov dx,es ; to dx:ax
775 endif
776 mov cx,offset _xfer_buf
777 storepage: ; storepage(edx,cx)
778 ifndef NO386
779 push 0
780 push 4096
781 push 0
782 else
783 xor bx,bx
784 push bx
785 mov bh,4096/256
786 push bx
787 xor bx,bx
788 push bx
789 endif
790 push cx
791 push ds
792 jmp call_memcpy32
794 endp @storepage$qpul
797 p386
798 ;***************************************************************
799 ;_fastcall void reset_bufv(di:u32 *p);
800 ;***************************************************************
801 global @reset_bufv$qpul:near
802 proc @reset_bufv$qpul near
804 mov [curdata],di
805 and [dword (data_himem di).cacheidx],0 ; and pageidx=0
806 ret
808 endp @reset_bufv$qpul
810 ;***************************************************************
811 ;u32* di=prev_bufv();
812 ;u32* di=prev_bufv();
813 ;***************************************************************
814 global _prev_bufv:near
815 global _next_bufv:near
816 proc _prev_bufv near
818 stc
819 db 73h ; jnc
820 _next_bufv:
821 clc
822 push si
823 mov bx,0
824 org $-2
825 curdata dw ?
826 sbb ax,ax
827 cmc
828 adc ax,[(data_himem bx).cacheidx] ; -1/+1
829 mov si,3ffh
830 and si,ax
831 mov [(data_himem bx).cacheidx],si
832 shl si,2
833 xor ecx,ecx
834 test ax,0fc00h
835 jz @@gotpage ; FFFF / 0400
836 xchg al,ah ; FFFC / 0004
837 and al,0fch
838 add [(data_himem bx).pageidx],ax
839 mov di,[(data_himem bx).pageidx]
840 lea di,[(data_himem bx+di).page]
841 mov edx,ds
842 shl edx,4
843 lea cx,[(data_himem bx).cache]
844 add edx,ecx
845 mov eax,[di]
846 or eax,eax
847 jz @@ret
848 mov cx,4096 ; get page
849 call memcpy_imagez ; memcpy_imagez(edx,eax,ecx)
850 @@gotpage:
851 lea ax,[(data_himem bx+si).cache]
852 or si,[(data_himem bx).pageidx] ; !pageidx && !cacheidx
853 jnz @@notfirst2
854 xchg ax,bx ; &first
855 @@notfirst2:
856 xchg ax,di
857 @@ret:
858 pop si
859 ret
861 endp _prev_bufv
863 ifdef NO386
864 p8086
865 endif
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 mov di,4096
875 push di ; original size
876 @@loop:
877 ifndef NO386
878 movzx ecx,di
879 mov eax,[(image_himem si).chunk_size]
880 cmp ecx,eax
881 jb @@szok
882 else
883 mov cx,di
884 mov ax,[word (image_himem si).chunk_size]
885 cmp cx,ax
886 jb @@szok
887 cmp [word ((image_himem si).chunk_size)+2],0 ; hi m->chunk_size
888 jne @@szok
889 endif
890 xchg ax,cx
891 @@szok:
892 jcxz image_done
893 mov dx,offset _xfer_buf+4096
894 sub dx,di
895 mov bx,[si]
896 call @read$cxdxbx
897 jb image_done
898 xor cx,cx
899 cwd ; ax < 8000h
900 ifndef NO386
901 cwde ; ax < 8000h
902 sub [(image_himem si).chunk_size],eax
903 xchg eax,ebx
904 else
905 sub [word (image_himem si).chunk_size],ax
906 xchg ax,bx
907 sbb [word ((image_himem si).chunk_size)+2],dx
908 jnz @@fill
909 cmp [word (image_himem si).chunk_size],dx
910 endif
911 jnz @@fill
912 dec cx
913 @@fill:
914 test bl,3
915 je @@filled
916 mov [bx+_xfer_buf],dh
917 inc bx
918 jmp @@fill
919 @@filled:
920 ifndef NO386
921 sub [(image_himem si).remaining],ebx
922 else
923 sub [word (image_himem si).remaining],bx
924 sbb [word ((image_himem si).remaining)+2],dx
925 endif
926 sub di,bx
927 pushf
928 jcxz @@same_chunk
929 call next_chunk
930 @@same_chunk:
931 popf
932 jnz @@loop
933 image_done:
934 pop ax ; original size
935 sub ax,di
936 pop di
937 ret
939 endp @read_image$qp11image_himem
942 ;***************************************************************
943 ;_fastcall unsigned long strtol(const char *s);
944 ;***************************************************************
945 proc @strtol$qpxzc near
947 ifndef NO386
948 xor ecx,ecx
949 xor eax,eax
950 xor ebx,ebx
951 lodsb
952 or al,20h
953 cmp al,'a'
954 jb @@notvga
955 sub al,'o'
956 @@vgaloop:
957 dec cx
958 add al,6
959 jnb @@vgaloop ; vga=normal,extended,ask
960 @@vga:
961 dec cx
962 xchg ax,cx
963 cwd
964 jmp @@popsiret
965 @@notvga:
966 mov cl,10 ; radix
967 cmp al,'-'
968 jne @@radixkeep
969 lodsb
970 @@radixkeep:
971 pushf
972 cmp al,'0'
973 jne @@radixok
974 mov cl,8
975 lodsb
976 or al,20h
977 cmp al,'x'
978 jne @@radixok
979 mov cl,16
980 @@strtollp:
981 lodsb
982 @@radixok:
983 or al,20h
984 sub al,'0'
985 jb @@endstrtol
986 cmp al,9
987 jbe @@digitok
988 cmp al,'a'-'0'
989 jb @@endstrtol
990 sub al,'a'-'0'-10
991 @@digitok:
992 cmp al,cl
993 jae @@endstrtol
994 cbw
995 cwde
996 xchg eax,ebx
997 mul ecx
998 add ebx,eax
999 jmp @@strtollp
1000 @@endstrtol:
1001 mov cl,10
1002 cmp al,'k'-'a'+10
1003 je @@shift
1004 mov cl,20
1005 cmp al,'m'-'a'+10
1006 je @@shift
1007 mov cl,30
1008 cmp al,'g'-'a'+10
1009 jne @@noshift
1010 @@shift:
1011 shl ebx,cl
1012 @@noshift:
1013 popf
1014 jnc @@end
1015 neg ebx
1016 @@end:
1017 push ebx
1018 pop ax
1019 pop dx
1020 @@popsiret:
1021 else
1022 xor bx,bx
1023 xor cx,cx
1024 xor dx,dx
1025 lodsb
1026 or al,20h
1027 cmp al,'a'
1028 jb @@notvga
1029 sub al,'o'
1030 @@vgaloop:
1031 dec cx
1032 add al,6
1033 jnb @@vgaloop ; vga=normal,extended,ask
1034 @@vga:
1035 xchg ax,cx
1036 ;cwd
1037 jmp @@end
1038 @@notvga:
1039 mov cl,10 ; radix
1040 cmp al,'-'
1041 jne @@radixkeep
1042 lodsb
1043 @@radixkeep:
1044 pushf
1045 cmp al,'0'
1046 jne @@radixok
1047 mov cl,8
1048 lodsb
1049 or al,20h
1050 cmp al,'x'
1051 jne @@radixok
1052 mov cl,16
1053 @@strtollp:
1054 lodsb
1055 @@radixok:
1056 or al,20h
1057 sub al,'0'
1058 jb @@endstrtol
1059 cmp al,9
1060 jbe @@digitok
1061 cmp al,'a'-'0'
1062 jb @@endstrtol
1063 sub al,'a'-'0'-10
1064 @@digitok:
1065 cmp al,cl
1066 jae @@endstrtol
1067 cbw
1069 push ax
1070 xchg ax,dx
1071 mul cx
1072 xchg ax,bx
1073 mul cx
1074 add dx,bx
1075 pop bx
1076 add bx,ax
1077 adc dx,0
1079 jmp @@strtollp
1080 @@endstrtol:
1081 mov cl,10
1082 cmp al,'k'-'a'+10
1083 je @@shift
1084 mov cl,20
1085 cmp al,'m'-'a'+10
1086 je @@shift
1087 mov cl,30
1088 cmp al,'g'-'a'+10
1089 @@shift:
1090 xchg ax,bx
1091 jne @@noshift
1092 extrn N_LXLSH@:near
1093 call N_LXLSH@
1094 @@noshift:
1095 popf
1096 jne @@end
1097 not dx
1098 neg ax
1099 jne @@end
1100 inc dx
1101 @@end:
1102 endif
1103 strtol_ret:
1104 ret
1106 endp @strtol$qpxzc
1109 ends _TEXT
1111 end
1113 ;###### END OF FILE ############################################