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

syslinux: fix iso2exe/init
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Dec 02 12:35:41 2020 +0000 (2020-12-02)
parents 555bcdab610b
children 3d19917d3a03
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 mov al,0
153 doseek:
154 call lseek ; lseek(,,al)
155 sub_fileofs:
156 mov bx,offset _isostate.fileofs
157 sub ax,[bx]
158 sbb dx,[bx+2]
159 ret
162 ;***************************************************************
163 ;_fastcall void readmenu(void);
164 ;***************************************************************
165 proc @readmenu$qv near
167 mov dx,18
168 xor cx,cx
169 call lseekset
170 mov dx,offset _isostate.filemod
171 mov cl,10
172 call readfd ; // read x->filemod + x->fileofs & x->filesize
173 mov bx,offset _isostate.fileofs
174 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
175 mov ax,7FF0h
176 cwd
177 mov [word bx+6],dx
178 sub ax,[bx+4]
179 mov [word bx+2],dx
180 mov [bx],ax
181 ; //magic = x->filemod;
183 endp @readmenu$qv
185 ;***************************************************************
186 ;_fastcall void isolseek(bx:const unsigned long *offset);
187 ;***************************************************************
188 global @isolseek$qpxul:near
189 proc @isolseek$qpxul near
191 isolseek:
192 mov dx,[bx]
193 mov cx,[bx+2]
194 lseekset:
195 mov al,00h ; bx=fd cx:dx=offset al=whence
196 lseek:
197 mov ah,42h
198 dosfd:
199 mov bx,[_isostate.fd]
200 dos:
201 int 21h
202 failifc:
203 jnc dosok
204 fail:
205 sbb ax,ax
206 cwd
207 dosok:
208 ret
210 endp @isolseek$qpxul
213 ;***************************************************************
214 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
215 ;***************************************************************
216 global @isoreadsector$qpxul:near
217 proc @isoreadsector$qpxul near
219 call isolseek
220 jc fail
221 mov ch,9 ; < 2560
222 mov dx,offset _isostate.buffer
223 readfd:
224 mov ah,3Fh
225 jmp dosfd
227 endp @isoreadsector$qpxul
230 ;***************************************************************
231 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
232 ;***************************************************************
233 global @strhead$qpxzct1:near
234 proc @strhead$qpxzct1 near
236 @@loop:
237 xchg ax,bx
238 mov cl,[bx] ; cl = *b++
239 inc bx
240 xchg ax,bx
241 or cl,cl ; clear C
242 jz fail ; return 0
243 xor cl,[bx] ; cl -= *a++
244 inc bx
245 or cl,cl
246 stc
247 jne fail ; return -1
248 jmp @@loop
250 endp @strhead$qpxzct1
253 ;***************************************************************
254 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
255 ;***************************************************************
256 global @strcmp$qpxzct1:near
257 proc @strcmp$qpxzct1 near
259 call @strhead$qpxzct1
260 jne dosok ; return -1
261 cmp cl,[bx]
262 jmp fail ; return 0 or -1
264 endp @strcmp$qpxzct1
266 ends _TEXT
268 end