wok view linld/stuff/src/ISOCRTL.ASM @ rev 23985

linld: up to 60k for header.com
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Nov 28 09:45:01 2020 +0000 (2020-11-28)
parents 431c14b76522
children f3eb71ce1913
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 _TEXT byte public use16 'CODE'
19 ends _TEXT
21 segment _DATA byte public use16 'DATA'
22 ends _DATA
24 segment _BSS byte public use16 'BSS'
26 include "isostate.inc"
28 public _isostate
29 _isostate isostate <?>
30 ; org $-7
32 ends _BSS
34 segment _TEXT byte public use16 'CODE'
36 global fold:near
37 fold:
38 org 130h-100h
39 global _cpu_features:dword
40 _cpu_features dd ?
41 org 0F000h-100h
42 global unfold:near
43 unfold:
44 jmp iso_open
45 extrn @isoreaddir$qv
46 dw @isoreaddir$qv
47 jmp @readmenu$qv
49 push dx
50 call readfd
51 push ds
52 pop es
53 mov di,128h ; TABLE
54 mov ax,offset iso_close_hack
55 stosw
56 inc ax ; iso_open_hack
57 stosw
58 add al,offset iso_read_hack-offset iso_open_hack
59 stosw
60 add al,offset iso_lseek_hack-offset iso_read_hack
61 stosw
62 ifdef NO386
63 global N_LXLSH@ES:near
64 N_LXLSH@ES:
65 mov dx,es
66 global N_LXLSH@:near
67 N_LXLSH@:
68 mov ch,0
69 @@lp:
70 shl ax,1
71 rcl dx,1
72 loop @@lp
73 endif
74 iso_close_hack:
75 ret
77 ;***************************************************************
78 ;_fastcall int open(bx:const char* name);
79 ;***************************************************************
80 iso_open_hack:
81 extrn @_isoopen$qv:near
82 cmp [byte bx],'!'
83 je @readmenu$qv
84 xchg ax,bx
85 iso_open:
86 mov [_isostate.filename2open],ax
87 call @_isoopen$qv
88 cmp al,1
89 cmc
90 ret
93 ;***************************************************************
94 ;_fastcall int read(bx:int fd=isostate.fd, dx:void* data, cx:int sz, ah=3Fh);
95 ;***************************************************************
96 iso_read_hack:
97 push dx
98 push cx
99 xor cx,cx
100 xor dx,dx
101 mov al,01h
102 call doseek ; bx = _isostate.fileofs
103 ifdef NO386
104 mov cx,[bx+4] ; _isostate.filesize
105 sub cx,ax
106 mov ax,[bx+6]
107 sbb ax,dx
108 pop ax
109 ja @@axok
110 je @@rem
111 xor ax,ax
112 @@rem:
113 cmp cx,ax
114 jb @@cxok
115 @@axok:
116 else
117 push dx
118 push ax
119 pop edx
120 mov eax,[bx+4] ; _isostate.filesize
121 sub eax,edx
122 pop cx
123 ja @@rem
124 xor cx,cx
125 @@rem:
126 movzx ecx,cx
127 cmp eax,ecx
128 ja @@cxok
129 endif
130 xchg ax,cx
131 @@cxok:
132 pop dx ; buffer
133 jmp readfd
136 ;***************************************************************
137 ;_fastcall long lseek(ax:int fd=isostate.fd, cxdx:unsigned long offset, bl:whence, bh=42h);
138 ;***************************************************************
139 iso_lseek_hack:
140 xchg ax,bx
141 ifdef SEEK_CUR
142 cmp al,1 ; current
143 je doseek
144 endif
145 mov bx,offset _isostate.fileofs
146 add dx,[bx]
147 adc cx,[bx+2]
148 cmp al,0 ; start
149 je doseek
150 add dx,[bx+4] ; _isostate.filesize
151 adc cx,[bx+6]
152 doseek:
153 call lseek ; lseek(,,al)
154 sub_fileofs:
155 mov bx,offset _isostate.fileofs
156 sub ax,[bx]
157 sbb dx,[bx+2]
158 ret
161 ;***************************************************************
162 ;_fastcall void readmenu(void);
163 ;***************************************************************
164 proc @readmenu$qv near
166 mov dx,18
167 xor cx,cx
168 call lseekset
169 mov dx,offset _isostate.filemod
170 mov cl,10
171 call readfd ; // read x->filemod + x->fileofs & x->filesize
172 mov bx,offset _isostate.fileofs
173 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
174 mov ax,7FF0h
175 cwd
176 mov [word bx+6],dx
177 sub ax,[bx+4]
178 mov [word bx+2],dx
179 mov [bx],ax
180 ; //magic = x->filemod;
182 endp @readmenu$qv
184 ;***************************************************************
185 ;_fastcall void isolseek(bx:const unsigned long *offset);
186 ;***************************************************************
187 global @isolseek$qpxul:near
188 proc @isolseek$qpxul near
190 isolseek:
191 mov dx,[bx]
192 mov cx,[bx+2]
193 lseekset:
194 mov al,00h ; bx=fd cx:dx=offset al=whence
195 lseek:
196 mov ah,42h
197 dosfd:
198 mov bx,[_isostate.fd]
199 dos:
200 int 21h
201 failifc:
202 jnc dosok
203 fail:
204 sbb ax,ax
205 cwd
206 dosok:
207 ret
209 endp @isolseek$qpxul
212 ;***************************************************************
213 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
214 ;***************************************************************
215 global @isoreadsector$qpxul:near
216 proc @isoreadsector$qpxul near
218 call isolseek
219 jc fail
220 mov ch,9 ; < 2560
221 mov dx,offset _isostate.buffer
222 readfd:
223 mov ah,3Fh
224 jmp dosfd
226 endp @isoreadsector$qpxul
229 ;***************************************************************
230 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
231 ;***************************************************************
232 global @strhead$qpxzct1:near
233 proc @strhead$qpxzct1 near
235 @@loop:
236 xchg ax,bx
237 mov cl,[bx] ; cl = *b++
238 inc bx
239 xchg ax,bx
240 or cl,cl ; clear C
241 jz fail ; return 0
242 xor cl,[bx] ; cl -= *a++
243 inc bx
244 or cl,cl
245 stc
246 jne fail ; return -1
247 jmp @@loop
249 endp @strhead$qpxzct1
252 ;***************************************************************
253 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
254 ;***************************************************************
255 global @strcmp$qpxzct1:near
256 proc @strcmp$qpxzct1 near
258 call @strhead$qpxzct1
259 jne dosok ; return -1
260 cmp cl,[bx]
261 jmp fail ; return 0 or -1
263 endp @strcmp$qpxzct1
265 ends _TEXT
267 end