wok-6.x view linld/stuff/src/ISOCRTL.ASM @ rev 23844

linld/readmenu: do not forget to lseek
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jun 13 10:41:01 2020 +0000 (2020-06-13)
parents d70f7cc6e3ac
children c04335df099f
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
9 p8086
11 group DGROUP _TEXT,_DATA,_BSS
12 assume cs:DGROUP,ds:DGROUP
14 segment _TEXT byte public use16 'CODE'
15 ends _TEXT
17 segment _DATA byte public use16 'DATA'
18 ends _DATA
20 segment _BSS byte public use16 'BSS'
22 include "isostate.inc"
24 public _isostate
25 _isostate isostate <?>
26 org $-7
28 ends _BSS
30 segment _TEXT byte public use16 'CODE'
32 global fold:near
33 fold:
34 org 0F000h
35 global unfold:near
36 unfold:
37 push dx
38 call readfd
39 push ds
40 pop es
41 mov di,128h ; TABLE
42 mov ax,offset iso_open_hack
43 stosw
44 mov ax,offset iso_read_hack
45 stosw
46 mov ax,offset iso_lseek_hack
47 stosw
48 mov ax,offset iso_close_hack
49 stosw
50 mov ax,offset iso_cleanup_hack
51 stosw
52 global @_cpuhaslm$qv:near
53 @_cpuhaslm$qv:
54 mov ax,[132h]
55 and al,20h
56 ret
58 iso_open_hack:
59 pop ax
60 extrn @_isoopen$qv:near
61 cmp [byte bx],'!'
62 je @readmenu$qv
63 xchg ax,bx
64 global iso_open:near
65 iso_open:
66 mov [_isostate.filename2open],ax
67 call @_isoopen$qv
68 inc ax
69 jnz open_ok
70 dec ax
71 stc
72 open_ok:
73 push bx
74 iso_close_hack:
75 pop bx
76 ret
79 macro curseek
80 push cx
81 xor cx,cx
82 xor dx,dx
83 mov ax,4201h
84 call dosfd ; lseek(,0L,SEEK_CUR)
85 call @doseek2
86 ifndef NO386
87 push dx
88 push ax
89 pop eax
90 endif
91 pop cx
92 endm
94 iso_read_hack:
95 ifdef NO386
96 push dx
97 curseek
98 mov bx,[word _isostate.filesize]
99 sub bx,ax
100 mov ax,[(word _isostate.filesize)+2]
101 sbb ax,dx
102 ja @@cxok
103 je @@rem
104 xor cx,cx
105 @@rem:
106 cmp bx,cx
107 ja @@cxok
108 mov cx,bx
109 @@cxok:
110 pop dx
111 else
112 p386
113 push edx
114 curseek
115 mov edx,[_isostate.filesize]
116 sub edx,eax
117 jnb @@rem
118 xor cx,cx
119 @@rem:
120 movzx eax,cx
121 cmp edx,eax
122 ja @@cxok
123 mov cx,dx
124 @@cxok:
125 pop edx
126 endif
127 or cx,cx
128 pop bx
129 jmp readfd
131 iso_lseek_hack:
132 xchg ax,bx
133 pop bx
134 ifdef SEEK_CUR
135 cmp al,1 ; current
136 jne @@nocurrent
137 call dosfd ; lseek(,0L,SEEK_CUR)
138 jmp @doseek2
139 @nocurrent:
140 endif
141 add dx,[word _isostate.fileofs]
142 adc cx,[(word _isostate.fileofs)+2]
143 cmp al,0 ; start
144 je @@doseek
145 add dx,[word _isostate.filesize]
146 adc cx,[(word _isostate.filesize)+2]
147 @@doseek:
148 call lseekset ; lseek(,0L,SEEK_SET)
149 @doseek2:
150 sub ax,[word _isostate.fileofs]
151 sbb dx,[(word _isostate.fileofs)+2]
152 ret
154 iso_cleanup_hack:
155 mov ah,3Eh ; close file
156 jmp dosfd
160 global @readmenu$qv:near
161 @readmenu$qv:
162 mov dx,18
163 xor cx,cx
164 call lseekset
165 mov dx,offset _isostate.filemod
166 mov cx,10
167 call readfd ; // read x->filemod + x->fileofs & x->filesize
168 mov bx,offset _isostate.fileofs
169 ; x->fileofs = 0x7FF0 - (x->filesize &= 0xFFFF);
170 and [word bx+6],0
171 mov ax,7FF0h
172 sub ax,[bx+4]
173 and [word bx+2],0
174 mov [bx],ax
175 ; //magic = x->filemod;
177 ;***************************************************************
178 ;_fastcall void isolseek(bx:const unsigned long *offset);
179 ;***************************************************************
180 global @isolseek$qpxul:near
181 proc @isolseek$qpxul near
183 isolseek:
184 mov dx,[bx]
185 mov cx,[bx+2]
186 lseekset:
187 mov ax,4200h ; bx=fd cx:dx=offset al=whence
188 dosfd:
189 mov bx,[_isostate.fd]
190 dos:
191 int 21h
192 failifc:
193 jnc @@dosok
194 fail:
195 sbb ax,ax
196 cwd
197 @@dosok:
198 ret
200 endp @isolseek$qpxul
202 ;***************************************************************
203 ;_fastcall int isoreadsector(bx:const unsigned long *offset);
204 ;***************************************************************
205 global @isoreadsector$qpxul:near
206 proc @isoreadsector$qpxul near
208 call isolseek
209 jc fail
210 mov cx,2560
211 mov dx,offset _isostate.buffer
212 global readfd:near
213 readfd:
214 mov ah,3Fh
215 jmp dosfd
217 endp @isoreadsector$qpxul
219 ;***************************************************************
220 ;_fastcall int strhead(bx:const char* a, ax:const char* b);
221 ;***************************************************************
222 global @strhead$qpxzct1:near
223 proc @strhead$qpxzct1 near
225 @@loop:
226 xchg ax,bx
227 mov cl,[bx] ; cl = *b++
228 inc bx
229 or cl,cl ; clear C
230 jz failifc ; return 0
231 xchg ax,bx
232 xor cl,[bx] ; cl -= *a++
233 inc bx
234 and cl,0dfh ; case insensitive
235 jne fail ; return -1
236 jmp @@loop
238 endp @strhead$qpxzct1
240 ;***************************************************************
241 ;_fastcall int strcmp(bx:const char* a, ax:const char* b);
242 ;***************************************************************
243 global @strcmp$qpxzct1:near
244 proc @strcmp$qpxzct1 near
246 push si
247 xchg ax,si
248 dec bx
249 @@lp:
250 inc bx
251 lodsb
252 sub al,[bx]
253 jnz @@out
254 or al,[bx]
255 jnz @@lp
256 @@out:
257 cbw
258 pop si
259 ret
261 endp @strcmp$qpxzct1
263 ifdef NO386
264 global N_LXLSH@ES:near
265 N_LXLSH@ES:
266 mov dx,es
267 global N_LXLSH@:near
268 N_LXLSH@:
269 mov ch,0
270 @@lp:
271 shl ax,1
272 rcl dx,1
273 loop @@lp
274 ret
275 endif
277 ends _TEXT
279 end