Page 1 of 2
GetFloppyType function prob
Posted: Wed Aug 07, 2002 6:47 am
by Silenger
I am trying to write a os in pascal, i use this code to get the floppy type but it crash when used.
type
TFloppyDrive = 0..7;
{Note}
{
0 = A
1 = B
n = nDrive
}
TFloppyType = 0..5;
{Note}
{
1 = 360K
2 = 1.2M
3 = 720K
4 = 1.44M
5 = 2.88M
}
function GetFloppyType(Drive: TFloppyDrive): TFloppyType;
var
dResult: TFloppyType;
begin
asm
PUSH Ax
PUSH Dx
MOV Ah, 08h
MOV Dl, Drive
INT 13h
{Result}
CMP Ah, 0
JNZ @None
CMP Ah, 0
JZ @Get
POP Dx
POP Ax
@None:
MOV dResult, 0
RET
@Get:
MOV dResult, Bl
RET
end;
GetFloppyType := dResult;
end;
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 6:57 am
by frank
The size is probably 512 bytes per sector..
The bios loads in the first sector, 0 head, 0 track, 0 cylinder into memory adress 0:7c00h if:
* the progam is 512 bytes long
* last 2 bytes MUST
contain 0xAA55
example program (asm):
--
org 7c00h
jmp main
main: jmp main
times 510-($-$$) db 0
sign db 0
---
Do that in pascal, and it'll work fine
Btw, this only works if your pascal compiler outputs 16 bit binary code.. (not 32)
If it is 32 bit binary code then you must switch to protected mode first -> then jump to your kernel.
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 7:00 am
by Silenger
Thx but the code is not for a bootloader but for use in the kernel
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 7:08 am
by frank
this might be usefull
ah = 08h
dl = drive nr
ah = errors (iff any)
cf = error 1 = yes, 0 is no
if no errors:
al =0
bh =0
bl= 0 = csmos
1 = 360kb
2 = 1.2 mb
3 = 720 kb
4 = 1.44 mb
5 = 2.88mb
ch = max tack nr
cl = max sec nr
dh = max head nr (always 1)
dl = number of installed floppydrives
es:di = pointer to floppy parametertable (11 bytes)
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 7:13 am
by Silenger
Thx
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 9:52 am
by Silenger
I still can find it, it should work? ???
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 10:20 am
by frank
maybe it should be like this
mov [bResult],bl
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 10:44 am
by Silenger
k will try it
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 10:47 am
by Silenger
nope
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 10:53 am
by Schol-R-LEA
Which Pascal compiler are you using? FreePascal only generates protected mode code, IIUC, which means that you can't use the BIOS calls from it.
This is assuming that you've already switched from real mode to p-mode before starting the kernel; otherwise, the Pascal code wouldn't work at all.
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 11:01 am
by Silenger
Iam using the old Turbo Pascal 7 compiler
Its just for trying things out.
I used debug and when i call the INT 13h he puts 04h in Bl so its k there, but then it commes at RET in the Get label it hangs!
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 11:06 am
by frank
what value is in dl? (0-tm - 3 = floppy)
and maybe you should put the value in dl like this:
mov dl,[drive]
(btw, did you put dl in drive before, if not, do that
)
check what disk it is, and if it is that disk.
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 11:15 am
by Silenger
I pas 0 as drive to use in the procedure.
0 = A drive.
Before MOV Dl, Drive -> Dl = 2Ah
After -> Dl = 00h
So it should be ok for that.
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 11:23 am
by frank
Try this:
type
TFloppyDrive = 0..7;
{Note}
{
0 = A
1 = B
n = nDrive
}
TFloppyType = 0..5;
{Note}
{
1 = 360K
2 = 1.2M
3 = 720K
4 = 1.44M
5 = 2.88M
}
function GetFloppyType(Drive: TFloppyDrive): TFloppyType;
var
dResult: TFloppyType;
begin
asm
PUSH Ax
PUSH Dx
MOV Ah, 08h
MOV Dl, Drive
INT 13h
CMP BL, 1
JE @1
CMP BL, 2
JE @2
CMP BL, 3
JE @3
CMP BL, 4
JE @4
CMP BL, 5
JE @5
POP Dx
POP Ax
@1: mov ah,0Eh
mov al,'1'
int 0x10
ret
@2: mov ah,0Eh
mov al,'2'
int 0x10
ret
@3: mov ah,0Eh
mov al,'3'
int 0x10
ret
@4: mov ah,0Eh
mov al,'4'
int 0x10
ret
@5: mov ah,0Eh
mov al,'5'
int 0x10
ret
@None:
MOV dResult, 0
RET
@Get:
MOV dResult, Bl
RET
end;
GetFloppyType := dResult;
end;
I know: it looks kinda ugly this way, but atlast you can find out what the disk size is... (I think)
Re:GetFloppyType function prob
Posted: Wed Aug 07, 2002 11:40 am
by Silenger
Thx but when i run your procedure its just crash again when RET is called
When CMP finds that Bl is 4 then he jumps to @4
and prints the char but then he commes on ret and crashes.
It makes a 208 runtime error 'memory out of bounds'.