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

linld: fix bootiso/strhead
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Nov 25 20:41:41 2020 +0000 (2020-11-25)
parents fc88d0826de4
children 555bcdab610b
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_open_hack
55 stosw
56 mov al,offset iso_read_hack-0F000h
57 stosw
58 mov al,offset iso_lseek_hack-0F000h
59 stosw
60 mov al,offset iso_close_hack-0F000h
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 ret
76 ;***************************************************************
77 ;_fastcall int open(bx:const char* name);
78 ;***************************************************************
79 iso_open_hack:
80 extrn @_isoopen$qv:near
81 cmp [byte bx],'!'
82 je @readmenu$qv
83 xchg ax,bx
84 global iso_open:near
85 iso_open:
86 mov [_isostate.filename2open],ax
87 call @_isoopen$qv
88 cmp al,1
89 cmc
90 iso_close_hack:
91 pop bx
92 ret
95 ;***************************************************************
96 ;_fastcall void readmenu(void);
97 ;***************************************************************
98 global @readmenu$qv:near
99 proc @readmenu$qv near
101 pop ax
102 mov dx,18
103 xor cx,cx
104 call lseekset
105 mov dx,offset _isostate.filemod
106 mov cx,10
107 call readfd ; // read x->filemod + x->fileofs & x->filesize
108 mov bx,offset _isostate.fileofs
109 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
110 mov ax,7FF0h
111 cwd
112 mov [word bx+6],dx
113 sub ax,[bx+4]
114 mov [word bx+2],dx
115 mov [bx],ax
116 ; //magic = x->filemod;
118 endp @readmenu$qv
120 ;***************************************************************
121 ;_fastcall void isolseek(bx:const unsigned long *offset);
122 ;***************************************************************
123 global @isolseek$qpxul:near
124 proc @isolseek$qpxul near
126 isolseek:
127 mov dx,[bx]
128 mov cx,[bx+2]
129 lseekset:
130 mov ax,4200h ; bx=fd cx:dx=offset al=whence
131 dosfd:
132 mov bx,[_isostate.fd]
133 dos:
134 int 21h
135 failifc:
136 jnc dosok
137 fail:
138 sbb ax,ax
139 cwd
140 dosok:
141 ret
143 endp @isolseek$qpxul
145 ;***************************************************************
146 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
147 ;***************************************************************
148 global @isoreadsector$qpxul:near
149 proc @isoreadsector$qpxul near
151 call isolseek
152 jc fail
153 mov cx,2560
154 mov dx,offset _isostate.buffer
155 global readfd:near
156 readfd:
157 mov ah,3Fh
158 jmp dosfd
160 endp @isoreadsector$qpxul
162 ;***************************************************************
163 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
164 ;***************************************************************
165 global @strhead$qpxzct1:near
166 proc @strhead$qpxzct1 near
168 @@loop:
169 xchg ax,bx
170 mov cl,[bx] ; cl = *b++
171 inc bx
172 or cl,cl ; clear C
173 jz fail ; return 0
174 xchg ax,bx
175 xor cl,[bx] ; cl -= *a++
176 inc bx
177 or cl,cl
178 stc
179 jne fail ; return -1
180 jmp @@loop
182 endp @strhead$qpxzct1
184 ;***************************************************************
185 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
186 ;***************************************************************
187 global @strcmp$qpxzct1:near
188 proc @strcmp$qpxzct1 near
190 call @strhead$qpxzct1
191 jne dosok ; return -1
192 xchg ax,bx
193 cmp cl,[bx]
194 jmp fail ; return 0 or -1
196 endp @strcmp$qpxzct1
198 ;***************************************************************
199 ;_fastcall int read(bx:int fd=isostate.fd, dx:void* data, cx:int sz);
200 ;***************************************************************
201 iso_read_hack:
202 push dx
203 push cx
204 xor cx,cx
205 mov ax,4201h
206 cwd
207 ifdef SEEK_CUR
208 call curpos ; bx = _isostate.fileofs
209 else
210 call dosfd ; lseek(,0L,SEEK_CUR)
211 call sub_fileofs ; bx = _isostate.fileofs
212 endif
213 ifdef NO386
214 mov cx,[bx+4] ; _isostate.filesize
215 sub cx,ax
216 mov ax,[bx+6]
217 sbb ax,dx
218 pop ax
219 ja @@axok
220 je @@rem
221 xor ax,ax
222 @@rem:
223 cmp cx,ax
224 jb @@cxok
225 @@axok:
226 else
227 push dx
228 push ax
229 pop edx
230 mov eax,[bx+4] ; _isostate.filesize
231 sub eax,edx
232 pop cx
233 ja @@rem
234 xor cx,cx
235 @@rem:
236 movzx ecx,cx
237 cmp eax,ecx
238 ja @@cxok
239 endif
240 xchg ax,cx
241 @@cxok:
242 pop dx ; buffer
243 pop bx ; skip last caller
244 jmp readfd
246 ;***************************************************************
247 ;_fastcall long lseek(ax:int fd=isostate.fd, cxdx:unsigned long offset, bl:whence);
248 ;***************************************************************
249 iso_lseek_hack:
250 xchg ax,bx
251 pop bx ; skip last caller
252 ifdef SEEK_CUR
253 cmp al,1 ; current
254 jne @@nocurrent
255 curpos:
256 call dosfd ; lseek(,0L,SEEK_CUR)
257 jmp sub_fileofs
258 @@nocurrent:
259 endif
260 mov bx,offset _isostate.fileofs
261 add dx,[bx]
262 adc cx,[bx+2]
263 cmp al,0 ; start
264 je @@doseek
265 add dx,[bx+4] ; _isostate.filesize
266 adc cx,[bx+6]
267 @@doseek:
268 call lseekset ; lseek(,0L,SEEK_SET)
269 sub_fileofs:
270 mov bx,offset _isostate.fileofs
271 sub ax,[bx]
272 sbb dx,[bx+2]
273 ret
275 ends _TEXT
277 end