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

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