Page 1 of 1
Parsing directory entries?
Posted: Thu Jul 15, 2010 1:49 pm
by CWood
Probably me being a noob again, but I am trying to parse directories in ISO 9660. I use this code:
Code: Select all
ParseDirectoryEntry:
mov ecx, [es:bx+0x0A]
mov eax, [es:bx+0x02]
push ax
xor eax, eax
pop ax
xor ah, ah
cmp eax, 0
je ParseDirectoryEntry
cmp cl, 0
je .zero
ret
.zero:
mov cl, 1
ret
However for some reason, I get a value of 0 in cl, and a value in eax which makes my reading code err, with an error code for the FDD, even though my drive number is still fish (the ASCII, haven't got an ASCII table handy to look it up, somewhere in the range of 240 last time I checked). But either way, the reading code works because I am getting the PVD, but not the root with this code (asside: for some reason, I can't read higher than something like sector 0x87 or 0xB7, I forget which. Is this normal for int 13 42?)
Re: Parsing directory entries?
Posted: Fri Jul 16, 2010 12:50 am
by JohnWilson
Without symbols or comments it's hard to understand what you're trying to do. So I assume your point is that ES:BX point at an ISO 9660 dir entry. Do you really want your code to go into an infinite loop just because the file's starting logical block number is a multiple of 256? And why do you want to add one to the length of a file just because it's a multiple of 256? I doubt you intended either of those (you're mixing bytes and dwords oddly -- and even when MOVZX used to be slow it was still a better deal than a four-instruction sequence, FWIW). What were you intending to have happen? And obviously, you should make sure ES:BX really are pointing at good data.
John Wilson
D Bit
Re: Parsing directory entries?
Posted: Fri Jul 16, 2010 1:25 am
by Brendan
Hi,
To make things easier, I've added comments and optimised it a bit:
Code: Select all
;Parse A Directory Entry
;
;This routine checks some stuff in a thingy-whatsit that may or may not be related to some
;sort of (page directory, phone directory?) entry; and may return some sort of values and other
;stuff (but might not return too).
;Input
; es:bx The address of a thingy-whatsit
;
;Output
; eax Something that's guaranteed to be non-zero
; ecx "stuff" in the highest 24-bits, with maybe some sort of flag in the lowest byte?
;_______________________________________________________________________________________________
ParseDirectoryEntry:
mov ecx,[es:bx+0x0A] ;ecx = something
movzx eax,byte [es:bx+0x02] ;eax = something else
xor cl,cl ;ecx = assumed value to return, with "stuff" in highest 24-bits
test al,al ;Is something else zero?
je ParseDirectoryEntry ; yes, keep looping until an IRQ changes the thingy-whatsit
cmp [es:bx+0x0A],1 ;Is something less than one (or, is something zero)?
adc cl,0 ;Set CL=1 if something was zero, else leave CL=0 (and don't upset the "stuff"!)
ret
Hope that helps someone ...
Cheers,
Brendan
Re: Parsing directory entries?
Posted: Sun Jul 18, 2010 1:07 pm
by JohnWilson
Still there, death2all?
Re: Parsing directory entries?
Posted: Sun Jul 18, 2010 1:55 pm
by CWood
Certainly am, yes. That code, Brendan, was, in fact, more than it was worth. I think the bug lies elsewhere... possibly in this code here:
Code: Select all
;************************************************;
; Reads a series of sectors
; Cx=>Number of blocks to read
; EAX=>Starting sector - Anything above B6 causes an err???
; ES:BX=>Buffer to read to
; DL=>Drive #
; Carry set on err
;************************************************;
ReadSectors:
.MAIN:
mov [DriveNum], dl
mov di, 5
push ax
mov ah, 45h
mov al, 0x00 ; Lock drive to prevent tray opening
int 0x13
cmp ah, 0
pop ax
jne .End
.SECTORLOOP:
push eax
push ds
push es
push bx
push cx
push di
push dword 0 ;Block number
push dword eax
push word es ; Read to es:bx
push word bx
push word cx
push word 10h ; Size: 10h
mov ah, 0x42
push ss
pop ds
mov si, sp
mov dl, [DriveNum]
int 0x13
push ax
mov al, ah
mov ah, 0x0E
int 0x10
pop ax
add esp, 0x10
.CONTINUE:
pop di
pop cx
pop bx
pop es
pop ds
cmp ah, 0
pop eax
je .SUCCESS
.LOOP:
dec di
jnz .SECTORLOOP
.SUCCESS:
clc
push ax
mov ax, 0x4501 ; Unlock drive
mov dl, [DriveNum]
int 0x13
cmp ah, 0
pop ax
jne .SUCCESS
.End:
ret
Please excuse my lack of comments, I don't have much time to devote, and I try to get as much done as possible in what time I have.
Re: Parsing directory entries?
Posted: Sun Jul 18, 2010 2:28 pm
by Combuster
death2all wrote:Please excuse my lack of comments, I don't have much time to devote, and I try to get as much done as possible in what time I have.
From personal experience: short term gain = long term fail here. I know that some well placed comments saved me a lot of time later on. I've also seen a lot of cases where I didn't bother to document and I had again to figure out how some things worked.
Re: Parsing directory entries?
Posted: Sun Jul 18, 2010 2:42 pm
by Solar
+{infinity}
Re: Parsing directory entries?
Posted: Thu Jul 22, 2010 10:55 am
by CWood
haha oops... trying to read in #bytes rather than #sectors :S