Reading characters of a filename from a CD-ROM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Reading characters of a filename from a CD-ROM

Post by Isaac »

Hi. I'm trying to read the first two characters of a filename from the root directory on a CD-ROM, and print them on the screen.

So, if I load the root directory at address 0x9000, I should be able to do this as follows:

Code: Select all

mov bx,0x9021
mov al,[bx]
mov ah,0xe
int 0x10
mov al,[bx+1]
int 0x10
But when I try it, it prints letters that are not really the first letters of any of the filenames in the root directory (as far as I know).

Does anybody know why this happens?

Here is the command I used to make the image:

Code: Select all

genisoimage -R -b bootloader  -no-emul-boot -boot-load-size 4 -boot-load-seg 0x7C0 -boot-info-table -o bootable.iso BootLoader
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Reading characters of a filename from a CD-ROM

Post by iansjack »

Does anybody know why this happens?
At a guess, you are not loading the correct sector for the root directory. As you give no details of how you are locating the directory this is impossible to confirm.

The very first thing that you need to do is to use a debugger. Set a break point after you have loaded the sector and inspect the appropriate memory location to see what you have loaded.
freecrac
Member
Member
Posts: 69
Joined: Thu Sep 20, 2012 5:11 am
Location: germany hamburg

Re: Reading characters of a filename from a CD-ROM

Post by freecrac »

Hello Isaac,
I never try to load and to display a root directory from a CD-ROM, but for a teletype output the "BX"-register is used for the page number of screen pages and a foreground color in a graphic mode.

RBIL->inter61a.zip->INTERRUP.A
--------V-100E-------------------------------
INT 10 - VIDEO - TELETYPE OUTPUT
AH = 0Eh
AL = character to write
BH = page number
BL = foreground color (graphics modes only)
Return: nothing
Desc: display a character on the screen, advancing the cursor and scrolling
the screen as necessary
Notes: characters 07h (BEL), 08h (BS), 0Ah (LF), and 0Dh (CR) are interpreted
and do the expected things
IBM PC ROMs dated 1981/4/24 and 1981/10/19 require that BH be the same
as the current active page
BUG: if the write causes the screen to scroll, BP is destroyed by BIOSes
for which AH=06h destroys BP
SeeAlso: AH=02h,AH=06h,AH=0Ah
Dirk
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Reading characters of a filename from a CD-ROM

Post by Isaac »

I went through my bootloader using bochs. After it loaded the Primary Volume Descriptor at address 0x9000, I used the bochs command "x" to see what it loaded. The address 0x9000 contains the value 0x01, which means it really is the Primary Volume Descriptor. So far so good. I noticed that the third byte in the directory entry of the root directory which contains the LBA address of the root directory, contains the value 0x18. Okay, that makes sense. The root directory begins at block 0x18. But when it loaded the root directory, I noticed that the second bytes in the first two entries which contain the LBA addresses of the first two files in the root directory, both contain the value 0x18! So the root directory and the first two files in it, all start at block 0x18! How is that possible?

Nothing is wrong with the image. I can mount it using Image Mounter and see it's contents.

Here is the code of my bootloader that loads the root directory:

Code: Select all

; at this point the Primary Volume Descriptor is already loaded at address 0x9000
push dx                        ; we don't want to overwrite dl as it contains the number of the drive this bootloader came from
mov ax,[0x909E]
mov [bx+8],ax
mov ax,[0x90A6]
mov dx,[0x90A8]
mov cx,2048
div cx
add ax,1
mov [bx+2],ax
pop dx
mov ah,0x42
int 0x13
User avatar
iansjack
Member
Member
Posts: 4709
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Reading characters of a filename from a CD-ROM

Post by iansjack »

The first directory entry will be ".", the directory itself. The second wil be "..", the parent directory; in the case of the root directory this is, again, the directory itself. So it makes sense that the root directory, ".", and ".." are all located at the same place.
Isaac
Member
Member
Posts: 66
Joined: Sat Dec 07, 2013 7:08 pm

Re: Reading characters of a filename from a CD-ROM

Post by Isaac »

Thank you. That explains it. My bootloader is reading letters from the first two entries of the root directory. That is why some of them are not the first letters of any of the files of the root directory.
Post Reply