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

updated libdvdcss and libdvdcss-dev (1.2.12 -> 1.4.2)
author Hans-G?nter Theisgen
date Mon Apr 01 15:12:18 2019 +0100 (2019-04-01)
parents 03507e8ec4b9
children 87b6697bb350
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT,_DATA,_BSS
15 assume cs:DGROUP,ds:DGROUP
17 segment _DATA byte public use16 'DATA'
19 global _heap_top
20 extrn _bss_end
21 _heap_top dw _bss_end
22 msg_hang db "High mem corrupted - not exiting to DOS"
23 msg_lf db 10,0
24 vcpi_alloc_err db "VCPI "
25 msg_malloc db "malloc error",0
26 ifdef EXTRA
27 tazboot_cmd db "tazboot.cmd",0
28 endif
30 ends _DATA
32 segment _BSS byte public use16 'BSS'
34 _xfer_buf db 4096 dup (?)
35 global _no_exit:byte
36 _no_exit db ?
37 filecnt db ? ; in fact 0 minus file count...
38 nextfilename dw ?
39 ifdef LARGE_IMAGES
40 curdata dw ?
41 endif
42 ifdef EXTRA
43 ultoabuf db 12 dup (?)
44 endif
46 ends _BSS
48 segment _TEXT byte public use16 'CODE'
50 ;***************************************************************
51 ;_fastcall void strcpy(bx:const char* a, ax:const char* b);
52 ;_fastcall void strcat(bx:const char* a, ax:const char* b);
53 ;_fastcall void strcatb(bx:const char* a, ax:const char* b);
54 ;***************************************************************
55 ifdef EXTRA
56 global @strcat$qpxzct1:near
57 @strcat$qpxzct1:
58 mov cx,1h
59 db 0bah ; mov dx,imm opcode
60 endif
61 global @strcatb$qpxzct1:near
62 proc @strcatb$qpxzct1 near
64 ifdef EXTRA
65 mov cl,7Fh
66 db 0bah ; mov dx,imm opcode
67 global @strcpy$qpxzct1:near
68 @strcpy$qpxzct1:
69 xor cx,cx
70 endif
71 push si
72 xchg ax,si ; b
73 ifdef EXTRA
74 jcxz @@nocat
75 endif
76 dec bx
77 @@catlp:
78 inc bx
79 cmp [byte bx],0 ; a=bx
80 jne @@catlp
81 ifdef EXTRA
82 mov al,20h
83 loop @@cpyhead
84 else
85 db 0b8h,20h ; mov ax,??20h
86 endif
87 @@nocat:
88 @@cpylp:
89 lodsb
90 @@cpyhead:
91 mov [bx],al
92 inc bx
93 or al,al
94 jne @@cpylp
95 strfound:
96 xchg ax,dx
97 strend:
98 pop si
99 ret
101 endp @strcatb$qpxzct1
104 ifdef EXTRA
105 p8086
106 ;***************************************************************
107 ;_fastcall int strstr(bx:const char* a, ax:const char* b);
108 ;***************************************************************
109 global @strstr$qpxzct1:near
110 proc @strstr$qpxzct1 near
112 xchg ax,cx ; b
113 mov dx,bx ; a
114 push si
115 @@loop:
116 xor ax,ax
117 mov si,dx
118 cmp [si],al ; *a
119 jz strend ; return ax = NULL
120 mov bx,cx
121 @@match:
122 or ah,[bx] ; *b
123 jz strfound
124 inc bx
125 lodsb
126 sub ah,al
127 jz @@match
128 inc dx
129 jmp @@loop
131 endp @strstr$qpxzct1
134 ;***************************************************************
135 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
136 ;***************************************************************
137 global @strcmp$qpxzct1:near
138 proc @strcmp$qpxzct1 near
140 push si
141 xchg ax,si
142 dec bx
143 @@lp:
144 inc bx
145 lodsb
146 sub al,[bx]
147 jnz @@out
148 or al,[bx]
149 jnz @@lp
150 @@out:
151 cbw
152 pop si
153 ret
155 endp @strcmp$qpxzct1
156 endif
159 ;***************************************************************
160 ;_fastcall void puts(bx:const char* s):
161 ;***************************************************************
162 global @puts$qpxzc:near
163 proc @puts$qpxzc near
165 ; global puts:near ; puts(bx)
166 puts:
167 call @@putsz
168 mov bx,offset msg_lf
169 mov dl,13
170 @@putcz:
171 mov ah,2
172 int 21h
173 @@putsz:
174 mov dl,[bx]
175 inc bx
176 or dl,dl
177 jne @@putcz ; ZF=1 (for malloc failure)
178 ret
180 endp @puts$qpxzc
184 ;***************************************************************
185 ;_fastcall int open(bx:const char* name, int flags=O_RDONLY);
186 ;***************************************************************
187 global openargs:near ; openargs(bx)
188 openargs:
189 cmp [byte bx],'@'
190 stc
191 jne fail
192 inc bx
194 global @open$qpxzc:near
195 proc @open$qpxzc near
197 global open:near ; open(bx)
198 open:
199 ifdef LONG_FILENAME
200 mov ax,716Ch
201 push bx di si
202 mov si,bx
203 xor bx,bx ; R/O
204 xor cx,cx ; attributes
205 xor di,di ; alias hint
206 cwd ; action = open
207 stc
208 int 21h
209 pop si di bx
210 jnc doret
211 endif
212 mov ax,3d00h ; read-only+compatibility
213 ;mov cl,0 ; attribute mask
214 mov dx,bx
215 dos:
216 int 21h
217 chkc:
218 jnc doret
219 fail:
220 sbb ax,ax ; ax=-1 CF
221 cwd
222 doret:
223 ifndef NO386
224 push dx ; see next_chunk:lseek
225 push ax
226 pop eax
227 endif
228 ret
230 endp @open$qpxzc
233 ;***************************************************************
234 ;_fastcall int fileexist(bx:const char* name);
235 ;***************************************************************
236 global @fileexist$qpxzc:near
237 @fileexist$qpxzc:
238 call @open$qpxzc
239 jc fail
241 ;***************************************************************
242 ;_fastcall int close(ax:int fd);
243 ;***************************************************************
244 global @close$qi:near
245 proc @close$qi near
247 global close:near ; close(ax)
248 close:
249 xchg ax,bx
250 mov ah,3Eh
251 or bx,bx
252 jnz dos
253 ret
255 endp @close$qi
258 ;***************************************************************
259 ;_fastcall int readrm(bx:struct himem *m, ax:int sz);
260 ;_fastcall int read(ax:int fd, bx:void* data, dx:int sz);
261 ;_fastcall int write(ax:int fd, bx:const void* data, dx:int sz);
262 ;***************************************************************
263 global @readrm$qp11image_himemi:near
264 @readrm$qp11image_himemi:
265 xchg ax,dx ; sz
266 mov ax,[bx] ; fd
267 mov bx,[bx-2] ; data
268 global @read$qipvi:near
269 proc @read$qipvi near
271 ifdef WRITE
272 stc
273 db 0B0h ; mov al,im
274 global @write$qipvi:near
275 @write$qipvi:
276 clc
277 endif
278 @read$dxbxax:
279 xchg ax,bx ; fd
280 xchg ax,dx ; data
281 xchg ax,cx ; sz
282 ifdef WRITE
283 mov ah,40h
284 sbb ah,0
285 else
286 global @read$cxdxbx:near
287 @read$cxdxbx:
288 mov ah,3Fh
289 endif
290 jcxz fail
291 jmp dos
293 endp @read$qipvi
295 ;***************************************************************
296 ;_fastcall long lseekcur(ax:int fd, dx:int whence);
297 ;***************************************************************
299 global @lseekcur$qii:near ; fd=ax whence=dx
300 proc @lseekcur$qii near
302 mov cl,1
303 xchg ax,bx
304 xchg ax,dx
305 cwd
306 xchg ax,dx
307 xchg ax,cx
308 jmp lseek
309 rewind: ; rewind(ax)
310 mov bl,0
311 lseek0: ; lseek0(ax,bl=dir)
312 xor dx,dx
313 xor cx,cx
314 lseekset:
315 xchg ax,bx
316 lseek:
317 mov ah,42h ; bx=fd cx:dx=offset al=whence
318 jmp dos
320 endp @lseekcur$qii
322 ifdef EXTRA
324 ;typedef unsigned dirsizetype;
325 struc isostate ; struct isostate {
326 fd dw ? ; 0 int fd;
327 filemod dw ? ; 2 unsigned short filemod;
328 fileofs dd ? ; 4 unsigned long fileofs;
329 filesize dd ? ; 8 unsigned long filesize;
330 filename dw ? ;12 char *filename;
331 curdirsize dw ? ;14 dirsizetype curdirsize;
332 dirsize dw ? ;16 dirsizetype dirsize;
333 curdirofs dd ? ;18 unsigned long curdirofs;
334 dirofs dd ? ;22 unsigned long dirofs;
335 curpos dw ? ;26 unsigned curpos;
336 buffer db 2560 dup(?) ;28 char buffer[2048+512];
337 ends ; } isostate;
338 ;***************************************************************
339 ;_fastcall long isolseek(bx:const unsigned long *offset);
340 ;_fastcall long lseekset2(ax:int fd, bx:unsigned long* whence);
341 ;***************************************************************
342 global @isolseek$qpxul:near
343 proc @isolseek$qpxul near
345 isolseek:
346 extrn _isostate:isostate
347 mov ax,[_isostate.fd]
348 global @lseekset2$qipul:near
349 @lseekset2$qipul:
350 mov dx,[bx]
351 mov cx,[bx+2]
352 mov bl,0
353 jmp lseekset
355 endp @isolseek$qpxul
357 ;***************************************************************
358 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
359 ;***************************************************************
360 global @isoreadsector$qpxul:near
361 proc @isoreadsector$qpxul near
363 call isolseek
364 jc doret
365 mov dx,2560
366 mov bx,offset _isostate.buffer
367 mov ax,[_isostate.fd]
368 jmp @read$dxbxax ; read(fd,buffer,2560)
370 endp @isoreadsector$qpxul
372 endif
375 ifdef USE_ARGSTR
376 ;***************************************************************
377 ;_fastcall int argstr(bx:const char *s, ax:const char keywords[], dx:const char **var);
378 ;_fastcall int argnum(bx:char *s, ax:const char keywords[], dx:unsigned long *var);
379 ;***************************************************************
380 global @argstr$qpxzcxt1ppxzc:near
381 proc @argstr$qpxzcxt1ppxzc near
383 stc
384 db 73h ; jnc
385 global @argnum$qpzcxpxzcpul:near
386 @argnum$qpzcxpxzcpul:
387 clc
389 xchg ax,bx ; keywords
390 xchg ax,cx ; s
391 xchg ax,dx ; vars
392 sbb dx,dx ; str:-1 num:0
393 sbb dx,-4 ; str:2 num:4
394 push si di
395 xchg ax,di ; vars
396 dec bx
397 mov al,0
398 @@testalt:
399 sub di,dx
400 @@test:
401 cmp al,'='
402 je @@found
403 mov si,cx ; s
404 add di,dx
405 @@match:
406 inc bx
407 lodsb
408 or al,20h
409 cmp al,[bx]
410 je @@match
411 cmp al,'/' ; 2f
412 jne @@notopt
413 cmp [byte bx],'-'
414 je @@match
415 @@notopt:
416 ifdef EXTRA
417 add di,dx
418 cmp [byte bx],'/'
419 je @@testalt
420 sub di,dx
421 endif
422 cmp [byte bx],'|'
423 je @@test
424 mov al,0
425 inc bx
426 cmp [bx-1],al
427 jne @@notopt
428 stc
429 jmp @@nokeyword
430 @@found:
431 mov [di],si
432 dec dx
433 dec dx
434 je @@done
435 push si
436 call @strtol$qpxzc
437 mov [di],ax
438 mov [di+2],dx
439 @@done:
440 clc
441 @@nokeyword:
442 sbb ax,ax
443 pop di si
444 ret
446 endp @argstr$qpxzcxt1ppxzc
448 else
450 ;***************************************************************
451 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
452 ;***************************************************************
453 global @strhead$qpxzct1:near
454 proc @strhead$qpxzct1 near
456 @@loop:
457 xchg ax,bx
458 mov cl,[bx] ; cl = *b++
459 inc bx
460 or cl,cl ; clear C
461 jz fail ; return 0
462 xchg ax,bx
463 xor cl,[bx] ; cl -= *a++
464 inc bx
465 and cl,0dfh ; case insensitive
466 jz @@loop
467 ret ; return b (is not 0)
469 endp @strhead$qpxzct1
471 endif
473 ;***************************************************************
474 ;_fastcall char* malloc_or_die(ax:unsigned size);
475 ;***************************************************************
476 global @malloc_or_die$qui:near
477 proc @malloc_or_die$qui near
479 xchg ax,cx ; size
480 global malloc_or_die:near ; malloc_or_die(cx)
481 malloc_or_die:
482 mov ax,[_heap_top] ; return value
483 mov bx,sp
484 add bh,-14h ; MIN_STACK=_1k+PAGE_SIZE
485 sub bx,ax ; can't overflow
486 cmp bx,cx
487 mov bx,offset msg_malloc
488 jb die
489 add [_heap_top],cx ; _BEG has zero'd heap
490 ret
492 endp @malloc_or_die$qui
495 ;***************************************************************
496 ;_fastcall int die(bx:const char* msg);
497 ;int exit();
498 ;int abort();
499 ;***************************************************************
500 global @die$qpxzc:near
501 proc @die$qpxzc near
502 @die$qpxzc:
503 global die:near ; die(bx)
504 die:
505 call puts
506 ; global _exit:near
507 _exit:
508 mov al,[_no_exit]
509 or al,al
510 jne @@hang
511 extrn exit:near
512 inc ax
513 jmp near exit
514 @@hang:
515 mov bx, offset msg_hang
516 call puts
517 ; global _abort:near
518 _abort:
519 cli
520 hlt
521 jmp _abort
523 endp @die$qpxzc
525 struc image_himem ;struct image_himem {
526 fd dw ? ; 0 int fd;
527 fallback dd ? ; 2 u32 fallback;
528 size dd ? ; 6 u32 size;
529 remaining dd ? ;10 u32 remaining;
530 buf dd ? ;14 u32 buf;
531 bufv dw ? ;18 u32 *bufv;
532 errmsg dw ? ;20 char *errmsg;
533 chunk_size dd ? ;22 u32 chunk_size;
534 next_chunk dw ? ;26 void (*next_chunk)(struct image_himem *);
535 state dw ? ;28 u16 state;
536 fd2close dw ? ;30 u16 fd2close;
537 ends ;};
539 ;***************************************************************
540 ;static long next_chunk(struct image_himem *di);
541 ;***************************************************************
542 proc next_chunk near
544 push si
545 mov ax,[(image_himem di).fd]
546 call close
547 ifndef NO386
548 xor eax,eax
549 else
550 xor ax,ax
551 cwd
552 endif
553 mov [(image_himem di).fd],ax
554 mov bx,[(image_himem di).state]
555 cmp al,[bx] ; ""
556 jz @@end
557 mov si,bx
558 @@scan:
559 lodsb
560 mov cx,si
561 cmp al,','
562 jz @@eos
563 or al,al
564 jnz @@scan
565 dec cx
566 @@eos:
567 mov [(image_himem di).state],cx
568 dec si
569 push [word si]
570 mov [byte si],ah ; set temp eos
571 call open
572 pop [word si] ; restore string
573 jc @@die
574 mov [(image_himem di).fd],ax
575 mov [(image_himem di).fd2close],ax
576 mov bl,02h ; SEEK_END
577 call lseek0
578 @@die:
579 mov bx,[(image_himem di).errmsg]
580 jc die
581 ifndef NO386
582 push eax
583 mov ax,[(image_himem di).fd]
584 call rewind
585 pop eax
586 @@end:
587 mov [(image_himem di).chunk_size],eax
588 else
589 push ax
590 push dx
591 mov ax,[(image_himem di).fd]
592 call rewind
593 pop dx
594 pop ax
595 @@end:
596 mov [word (image_himem di).chunk_size],ax
597 mov [word ((image_himem di).chunk_size)+2],dx
598 endif
599 pop si
600 ret
602 endp next_chunk
605 ifdef LARGE_IMAGES
606 struc data_himem ;struct data_himem {
607 first dd ? ; 0 u32 first;
608 cacheidx dw ? ; 4 int cacheidx;
609 pageidx dw ? ; 6 int pageidx;
610 cache dd 1024 dup(?) ; 8 int cache;
611 page dd 1024 dup(?) ;4104 int page;
612 ends ;}; // size=8200
613 endif
615 ;***************************************************************
616 ;_fastcall u32* malloc_bufv_or_die(bx:struct image_himem *m);
617 ;***************************************************************
618 global @malloc_bufv_or_die$qp11image_himem:near
619 proc @malloc_bufv_or_die$qp11image_himem near
621 p386
622 push si
623 mov si,bx
624 ifdef LARGE_IMAGES
625 movzx ecx,[word ((image_himem si).size) + 2]
626 shr cx,4 ; pages index size = size >> 20
627 add cx,8+4096+8
628 call malloc_or_die
629 mov cx,4096+4095 ; cnt = 1+(m->size+PAGE_MASK)/PAGE_SIZE;
630 add ecx,[(image_himem si).size]
631 shr ecx,12
632 mov [curdata],ax
633 else
634 mov ecx,[(image_himem si).size]
635 dec ecx
636 shr ecx,12
637 inc cx ; cnt = (m->size+PAGE_MASK)/PAGE_SIZE;
638 push cx
639 inc cx ; cnt+1
640 shl cx,2 ; bufv => vcpi => vm86
641 ; our malloc zeroes allocated mem: bufv[cnt]=0;
642 ; Allocate pages, storing addrs in addrbuf
643 call malloc_or_die
644 pop cx
645 push ax
646 endif
647 mov [(image_himem si).bufv],ax
648 xchg ax,si
649 @@vcpi_alloc:
650 xor edx,edx
651 mov ax,0DE04h
652 int 67h
653 or ah,ah
654 mov bx,offset vcpi_alloc_err
655 jnz die
656 ; for (i = cnt-1; i >= 0; i--)
657 ifdef LARGE_IMAGES
658 mov eax,ecx
659 dec eax
660 else
661 mov ax,cx
662 dec ax
663 cwde
664 endif
665 shl eax,12 ; i*_4k
666 ; if (edx < pm.fallback+i*_4k && edx >= pm.fallback) again
667 extrn _imgs
668 mov bx,offset _imgs+2
669 push eax
670 add eax,[bx-2+2]
671 cmp eax,edx ; pm.fallback+i*_4k <= edx ?
672 pop eax ; i*_4k
673 jbe @@pmok
674 cmp edx,[bx-2+2] ; edx >= pm.fallback ?
675 jae @@vcpi_alloc
676 @@pmok:
677 ; if (edx >= initrd.fallback+i*_4k && edx < initrd.fallback+initrd.size) again
678 extrn _imgs
679 mov bx,offset _imgs+32+2
680 add eax,[bx-2+2] ; +initrd.fallback
681 cmp eax,edx ; initrd.fallback+i*_4k > edx ?
682 ja @@initrdok
683 mov eax,[bx-2+6] ; initrd.size
684 add eax,[bx-2+2] ; +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 dx
712 pop ax
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$qp11image_himem:near
739 proc @memcpy_image$qp11image_himem near
741 ifndef NO386
742 mov edx,[(image_himem bx).fallback]
743 mov eax,[(image_himem bx).buf]
744 cmp eax,edx ; if (m->fallback != m->buf)
745 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
746 ifdef LARGE_IMAGES
747 mov ecx,[(image_himem bx).size]
748 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
749 push ecx
750 else
751 push [(image_himem bx).size]
752 endif
753 push eax
754 push 0
755 call_memcpy32:
756 push edx
757 else
758 mov ax,[word ((image_himem bx).fallback)]
759 mov dx,[word ((image_himem bx).fallback)+2]
760 mov cx,[word ((image_himem bx).buf)]
761 cmp ax,cx ; if (m->fallback != m->buf)
762 jnz @@do
763 cmp dx,[word ((image_himem bx).buf)+2]
764 jz @@skip ; memcpy32(m->fallback,0,m->buf,m->size)
765 @@do:
766 push [word ((image_himem bx).size)+2]
767 push [word ((image_himem bx).size)]
768 push [word ((image_himem bx).buf)+2]
769 push cx
770 xor cx,cx
771 push cx
772 call_memcpy32:
773 push dx
774 push ax
775 ifdef LARGE_IMAGES
776 jmp @@memcpy
777 memcpy_imagez: ; memcpy_imagez(edx,eax,ecx)
778 p386
779 push ecx
780 push eax
781 push 0
782 push edx
783 ifdef NO386
784 p8086
785 endif
786 endif
787 endif
788 @@memcpy:
789 extrn memcpy32:near
790 call near memcpy32
791 @@skip:
792 ret
794 endp @memcpy_image$qp11image_himem
796 ;***************************************************************
797 ;_fastcall void storepage(bx:u32 *dst);
798 ;***************************************************************
799 global @storepage$qpul:near
800 proc @storepage$qpul near
802 ifndef NO386
803 mov edx,[bx]
804 else
805 mov ax,[bx]
806 mov dx,[bx+2]
807 endif
808 mov cx,offset _xfer_buf
809 storepage: ; storepage(edx,cx)
810 ifndef NO386
811 push 0
812 push 4096
813 push 0
814 else
815 xor bx,bx
816 push bx
817 mov bh,4096/256
818 push bx
819 xor bx,bx
820 push bx
821 endif
822 push cx
823 push ds
824 jmp call_memcpy32
826 endp @storepage$qpul
829 ifdef LARGE_IMAGES
830 p386
831 ;***************************************************************
832 ;_fastcall void reset_bufv(bx:u32 *p);
833 ;***************************************************************
834 global @reset_bufv$qpul:near
835 proc @reset_bufv$qpul near
837 mov [curdata],bx
838 and [dword (data_himem bx).cacheidx],0
839 ret
841 endp @reset_bufv$qpul
843 ;***************************************************************
844 ;u32* prev_bufv();
845 ;u32* prev_bufv();
846 ;***************************************************************
847 global _prev_bufv:near
848 global _next_bufv:near
849 proc _prev_bufv near
851 stc
852 db 73h ; jnc
853 _next_bufv:
854 clc
855 push si
856 mov si,[curdata]
857 sbb ax,ax
858 cmc
859 adc ax,[(data_himem si).cacheidx] ; -1/+1
860 xor ecx,ecx
861 test ax,0fc00h
862 jz @@gotpage
863 push ax ; FFFF / 0400
864 sar ax,8 ; FFFC / 0004
865 and al,0fch
866 add [(data_himem si).pageidx],ax
867 mov bx,[(data_himem si).pageidx]
868 lea bx,[(data_himem bx+si).page]
869 mov edx,ds
870 shl edx,4
871 lea cx,[(data_himem si).cache]
872 add edx,ecx
873 mov eax,[bx]
874 or eax,eax
875 jnz @@pageok
876 pop ax
877 xchg ax,bx
878 pop si
879 ret
880 @@pageok:
881 mov cx,4096
882 call memcpy_imagez ; get page
883 pop ax ; FFFF / 0400
884 cbw
885 shr ax,6 ; 03FF / 0000
886 @@gotpage:
887 mov [(data_himem si).cacheidx],ax
888 shl ax,2
889 xchg ax,bx
890 lea ax,[(data_himem bx+si).cache]
891 or bx,[(data_himem si).pageidx] ; !pageidx && !cacheidx
892 jnz @@notfirst2
893 xchg ax,si ; &first
894 @@notfirst2:
895 pop si
896 ret
898 endp _prev_bufv
899 endif
901 ifdef NO386
902 p8086
903 endif
905 ;***************************************************************
906 ;_fastcall void open_image(bx:const char *name, ax:struct image_himem *m);
907 ;***************************************************************
908 global @open_image$qpxzcp11image_himem:near
909 proc @open_image$qpxzcp11image_himem near
911 push di
912 xchg ax,di
913 ifdef EXTRA
914 cmp [(image_himem di).fd],0 ; iso image/kernel ?
915 jnz @@alreadydone
916 endif
917 mov [(image_himem di).state],bx
918 push bx
919 ifdef EXTRA
920 cmp [(image_himem di).next_chunk],0 ; iso image/initrd ?
921 jnz @@next
922 mov [(image_himem di).next_chunk],offset next_chunk
923 @@next:
924 call [(image_himem di).next_chunk] ; m->next_chunk()
925 else
926 @@next:
927 call next_chunk
928 endif
929 ifndef NO386
930 add eax,3
931 and al,0FCh
932 add [(image_himem di).size],eax ; m->size += m->chunk_size
933 or eax,eax
934 else
935 add ax,3
936 adc dx,0
937 and al,0FCh
938 add [word (image_himem di).size],ax ; m->size += m->chunk_size
939 adc [word ((image_himem di).size)+2],dx
940 or ax,dx
941 endif
942 jnz @@next
943 pop [(image_himem di).state]
944 ifdef EXTRA
945 call [(image_himem di).next_chunk] ; m->next_chunk()
946 else
947 call next_chunk
948 endif
949 @@alreadydone:
950 pop di
951 ret
953 endp @open_image$qpxzcp11image_himem
956 ;***************************************************************
957 ;_fastcall int read_image(bx:struct image_himem *m);
958 ;***************************************************************
959 global @read_image$qp11image_himem:near
960 proc @read_image$qp11image_himem near
962 push si di
963 mov di,bx
964 mov si,4096
965 push si ; original size
966 @@loop:
967 ifndef NO386
968 movzx ecx,si
969 mov eax,[(image_himem di).chunk_size]
970 cmp ecx,eax
971 jb @@szok
972 else
973 mov cx,si
974 mov ax,[word (image_himem di).chunk_size]
975 cmp cx,ax
976 jb @@szok
977 cmp [word ((image_himem di).chunk_size)+2],0 ; hi m->chunk_size
978 jne @@szok
979 endif
980 xchg ax,cx
981 @@szok:
982 jcxz image_done
983 mov dx,offset _xfer_buf+4096
984 sub dx,si
985 mov bx,[di]
986 call @read$cxdxbx
987 jc image_done
988 xor cx,cx
989 cwd ; ax < 8000h
990 ifndef NO386
991 cwde ; ax < 8000h
992 sub [(image_himem di).chunk_size],eax
993 xchg eax,ebx
994 else
995 sub [word (image_himem di).chunk_size],ax
996 xchg ax,bx
997 sbb [word ((image_himem di).chunk_size)+2],dx
998 jnz @@fill
999 cmp [word (image_himem di).chunk_size],dx
1000 endif
1001 jnz @@fill
1002 dec cx
1003 @@fill:
1004 test bl,3
1005 je @@filled
1006 mov [bx+_xfer_buf],dh
1007 inc bx
1008 jmp @@fill
1009 @@filled:
1010 ifndef NO386
1011 sub [(image_himem di).remaining],ebx
1012 else
1013 sub [word (image_himem di).remaining],bx
1014 sbb [word ((image_himem di).remaining)+2],dx
1015 endif
1016 sub si,bx
1017 pushf
1018 ifdef EXTRA
1019 and cx,[(image_himem di).next_chunk]
1020 jcxz @@same_chunk
1021 push di
1022 call cx
1023 pop cx
1024 else
1025 jcxz @@same_chunk
1026 call next_chunk
1027 endif
1028 @@same_chunk:
1029 popf
1030 jnz @@loop
1031 image_done:
1032 pop ax ; original size
1033 sub ax,si
1034 pop di si
1035 ret
1037 endp @read_image$qp11image_himem
1040 ;***************************************************************
1041 ;pascal unsigned long strtol(const char *s);
1042 ;***************************************************************
1043 global @strtol$qpxzc:near
1044 proc @strtol$qpxzc near
1046 pop ax
1047 pop bx ; s
1048 push ax
1049 ifndef NO386
1050 xor ebx,ebx
1051 push si
1052 jcxz @@end
1053 mov si,cx
1054 xor ecx,ecx
1055 xor eax,eax
1056 lodsb
1057 mov dx,ax
1058 or al,20h
1059 cmp al,'n' ; vga=normal
1060 je @@vga
1061 dec cx
1062 cmp al,'e' ; vga=extended
1063 je @@vga
1064 dec cx
1065 cmp al,'a' ; vga=ask
1066 jne @@notvga
1067 @@vga:
1068 dec cx
1069 xchg ax,cx
1070 cwd
1071 jmp @@popsiret
1072 @@notvga:
1073 mov cx,10 ; radix
1074 xchg ax,dx
1075 cmp al,'+'
1076 je @@radixskip
1077 cmp al,'-'
1078 clc
1079 jne @@radixkeep
1080 stc
1081 @@radixskip:
1082 lodsb
1083 @@radixkeep:
1084 pushf
1085 cmp al,'0'
1086 jne @@radixok
1087 mov cl,8
1088 lodsb
1089 or al,20h
1090 cmp al,'x'
1091 jne @@radixok
1092 mov cl,16
1093 @@strtollp:
1094 lodsb
1095 @@radixok:
1096 or al,20h
1097 sub al,'0'
1098 jb @@endstrtol
1099 cmp al,9
1100 jbe @@digitok
1101 cmp al,'a'-'0'
1102 jb @@endstrtol
1103 sub al,'a'-'0'-10
1104 @@digitok:
1105 cmp al,cl
1106 jae @@endstrtol
1107 xchg eax,ebx
1108 mul ecx
1109 add eax,ebx
1110 xchg eax,ebx
1111 jmp @@strtollp
1112 @@endstrtol:
1113 mov cl,10
1114 cmp al,'k'-'a'+10
1115 je @@shift
1116 mov cl,20
1117 cmp al,'m'-'a'+10
1118 je @@shift
1119 mov cl,30
1120 cmp al,'g'-'a'+10
1121 jne @@noshift
1122 @@shift:
1123 shl ebx,cl
1124 @@noshift:
1125 popf
1126 jnc @@end
1127 neg ebx
1128 @@end:
1129 push ebx
1130 pop ax
1131 pop dx
1132 @@popsiret:
1133 pop si
1134 else
1135 push si
1136 push di
1137 xor ax,ax
1138 cwd
1139 jcxz @@goend
1140 xchg ax,di
1141 mov si,cx
1142 lodsb
1143 mov bx,ax
1144 or al,20h
1145 mov cx,-1
1146 cmp al,'n' ; vga=normal
1147 je @@vga
1148 dec cx
1149 cmp al,'e' ; vga=extended
1150 je @@vga
1151 dec cx
1152 cmp al,'a' ; vga=ask
1153 jne @@notvga
1154 @@vga:
1155 xchg ax,cx
1156 @@goend:
1157 jmp @@popdisiret
1158 @@notvga:
1159 mov cx,10 ; radix
1160 xchg ax,bx
1161 cmp al,'+'
1162 je @@radixskip
1163 cmp al,'-'
1164 clc
1165 jne @@radixkeep
1166 stc
1167 @@radixskip:
1168 lodsb
1169 @@radixkeep:
1170 pushf
1171 cmp al,'0'
1172 jne @@radixok
1173 mov cl,8
1174 lodsb
1175 or al,20h
1176 cmp al,'x'
1177 jne @@radixok
1178 mov cl,16
1179 @@strtollp:
1180 lodsb
1181 @@radixok:
1182 or al,20h
1183 sub al,'0'
1184 jb @@endstrtol
1185 cmp al,9
1186 jbe @@digitok
1187 cmp al,'a'-'0'
1188 jb @@endstrtol
1189 sub al,'a'-'0'-10
1190 @@digitok:
1191 cmp al,cl
1192 jae @@endstrtol
1194 push ax
1195 push si
1196 push dx
1197 xchg ax,di
1198 mul cx
1199 xchg ax,di
1200 xchg ax,dx
1201 xchg ax,si
1202 pop ax
1203 mul cx
1204 add ax,si
1205 pop si
1206 xchg ax,dx
1207 pop ax
1208 mov ah,0
1209 add di,ax
1210 adc dx,0
1212 jmp @@strtollp
1213 @@endstrtol:
1214 mov cl,10
1215 cmp al,'k'-'a'+10
1216 je @@shift
1217 mov cl,20
1218 cmp al,'m'-'a'+10
1219 je @@shift
1220 mov cl,30
1221 cmp al,'g'-'a'+10
1222 jne @@noshift
1223 @@shift:
1224 rcl di,1
1225 shl dx,1
1226 loop @@shift
1227 @@noshift:
1228 popf
1229 jnc @@end
1230 not dx
1231 neg di
1232 jne @@end
1233 inc dx
1234 @@end:
1235 xchg ax,di
1236 @@popdisiret:
1237 pop di
1238 pop si
1239 endif
1240 strtol_ret:
1241 ret
1243 endp @strtol$qpxzc
1246 ifdef USE_ARGSTR
1247 ;***************************************************************
1248 ;_fastcall void set_cmdline(bx:const char *filename);
1249 ;***************************************************************
1250 global @set_cmdline$qpxzc:near
1251 proc @set_cmdline$qpxzc near
1252 call openargs
1253 jc strtol_ret
1254 mov cx,4096
1255 mov di,[_heap_top]
1256 extrn read_cmdline:near
1257 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1259 endp @set_cmdline$qpxzc
1260 endif
1263 ifdef NO386
1264 ;***************************************************************
1265 ;u16 topseg();
1266 ;***************************************************************
1267 global _topseg:near
1268 proc _topseg near
1270 int 12h
1271 jnc @@max640k
1272 mov ax,640 ; 9000
1273 @@max640k:
1274 dec ax
1275 and al,0C0h
1276 mov cl,6
1277 shl ax,cl
1278 ret
1280 endp _topseg
1281 endif
1283 ifdef EXTRA
1284 p8086
1285 ;***************************************************************
1286 ;char *progname(void)
1287 ;***************************************************************
1288 global _progname:near
1289 proc _progname near
1291 push si di es
1292 mov ah,30h
1293 int 21h
1294 xor di,di
1295 cmp al,3
1296 mov ax,di
1297 jb @@skip
1298 ;mov es,[cs:2Ch]
1299 mov es,[di+2Ch]
1300 mov cx,sp ; big enough
1301 @@loop:
1302 repne
1303 scasb
1304 scasb
1305 jne @@loop
1306 inc di
1307 inc di
1308 mov si,di ; progname @es:di
1309 repne
1310 scasb
1311 mov cx,di
1312 sub cx,si ; progname len
1313 call malloc_or_die ; keep cx
1314 mov di,ax
1315 push ds
1316 push es
1317 pop ds
1318 pop es
1319 rep
1320 movsb
1321 push es
1322 pop ds
1323 @@skip:
1324 pop es di si
1325 ret
1327 endp _progname
1330 ;***************************************************************
1331 ;_fastcall void chdirname(bx:char *path)
1332 ;***************************************************************
1333 global @chdirname$qpzc:near
1334 proc @chdirname$qpzc near
1336 cmp [byte bx+1],3Ah ; ':'
1337 jne @@nodisk
1338 mov dl,20h
1339 or dl,[bx]
1340 sub dl,61h
1341 mov ah,0Eh
1342 int 21h
1343 inc bx
1344 inc bx
1345 @@nodisk:
1346 xor cx,cx
1347 @@next:
1348 mov al,[bx]
1349 cmp al,5Ch
1350 jne @@tsteos
1351 mov dx,bx
1352 inc cx
1353 @@tsteos:
1354 inc bx
1355 or al,al
1356 jnz @@next
1357 jcxz @@end
1358 mov bx,dx
1359 push [word bx]
1360 mov [bx],al
1361 ifdef LONG_FILENAME
1362 stc
1363 mov ax,713Bh ; chdir long filename (ds:dx)
1364 int 21h
1365 jnc @@chdirdone
1366 endif
1367 mov ah,3Bh ; chdir(ds:dx)
1368 int 21h
1369 @@chdirdone:
1370 pop [word bx]
1371 @@end:
1372 ret
1374 endp @chdirname$qpzc
1377 ;***************************************************************
1378 ;_fastcall char *ultoa(axdx:unsigned long n);
1379 ;***************************************************************
1380 global @ultoa$qul:near
1381 proc @ultoa$qul near
1383 xchg ax,cx
1384 xchg ax,dx ; AX:CX = n
1385 push si
1386 mov si,10
1387 mov bx,offset ultoabuf+11
1388 @@loop:
1389 dec bx
1390 xor dx,dx
1391 div si ; DX:AX = 0000:hi(n)
1392 xchg ax,cx ; CX = hi(n)/10
1393 div si ; DX:AX = hi(n)%10:lo(n)
1394 xchg ax,cx ; CX = lo(n/10)
1395 ; AX = hi(n)/10 = hi(n/10)
1396 mov [byte bx],'0'
1397 add [bx],dl ; DL = n%10
1398 mov dx,ax
1399 or dx,cx
1400 jnz @@loop
1401 xchg ax,bx
1402 pop si
1403 ret
1405 endp @ultoa$qul
1408 ;***************************************************************
1409 ;_fastcall unsigned long kver2ul(bx:char *kernel_version);
1410 ;***************************************************************
1411 global @kver2ul$qpzc:near
1412 proc @kver2ul$qpzc near
1414 push si
1415 mov si,bx
1416 xor bx,bx
1417 mov cx,304h
1418 @@number:
1419 xor ax,ax
1420 cwd
1421 @@digit:
1422 shl al,cl
1423 shl ax,cl
1424 lodsb
1425 sub al,30h
1426 cmp al,9
1427 jbe @@digit
1428 mov dl,bh
1429 mov bh,bl
1430 mov bl,ah
1431 dec ch
1432 jnz @@number
1433 xchg ax,bx
1434 pop si
1435 kver2ulret:
1436 ret
1438 endp @kver2ul$qpzc
1440 endif
1442 ;***************************************************************
1443 ;void try_default_args();
1444 ;***************************************************************
1445 ifdef EXTRA
1447 global _try_default_args:near
1448 proc _try_default_args near
1450 mov bx,offset tazboot_cmd
1451 call open
1452 jc kver2ulret
1453 mov cx,4096
1454 mov di,[_heap_top]
1455 extrn read_cmdline:near
1456 jmp near read_cmdline ; read_cmdline(ax,di,cx)
1458 endp _try_default_args
1460 endif
1462 ends _TEXT
1464 end
1466 ;###### END OF FILE ############################################