im using int 13h to load the second sector. the second 512 bytes on the floppy.
im using
es = 0000h
bx = 7e00h
ax = 0201h
cx = 0002h
dx = 0001h
int 13h
im also using debug to write the data to the floppy. its a 550 byte bin file and im using the w 100 0 0 1 command.
So?
Whats the problem/question?
Seems that you are writing OS (in this case boot sector to floppy).
Sector 0: cyl 0, head 0, sec 1
Sector 1: cyl 0, head 1, sec 1
Sector 2: cyl 0, head 0, sec 2
Sector 3: cyl 0, head 1, sec 2
Sector 4: cyl 0, head 0, sec 3
Sector 5: cyl 0, head 1, sec 3
Sector 6: cyl 0, head 0, sec 4
Sector 7: cyl 0, head 1, sec 4
.
.
.
thanks tedd
i changed it around and im still getting garbage data in my program. i remember reading that i would want to read from the drive 3 times with a drive reset imbetween each one. would that be a factor in this or not.
i've used debug to check the disk integrity and the data is there properly. my program is suppose to be loaded at 7c00. not sure if the bios is actually dumping me at 7c00. im calling int 13 and giving it 0000: 7e00h as the memory address for the data.
Quote from: ninjarider on September 01, 2006, 12:53:23 AM
not sure if the bios is actually dumping me at 7c00.
Did you use the trick with the JMP at the beginning I mentioned in the other thread?
You should reset and retry if int 13h returns with the carry flag set (ignore the value in ax, it's not reliable) - indicating there was an error.
If it's not set then you can assume the read/write was successful.
As for what's going wrong - post code (the whole thing) :bdg
From what I remember of debug, it uses INT 25h to write to a disk, which is a logical disk (i.e. it has a drive letter according to DOS).
INT 13h writes to a physical disk (i.e. it has a drive number according to the BIOS).
So using "w 100 0 0 1" will write the boot sector. To write your 550-byte file, you need to write 2x512-byte sectors, starting from
the second sector e.g. "w 100 0 1 2" and have your boot sector load 2 sectors to 0000h:7e00h then jump to it.
DOSSEG
.186
.MODEL SMALL
.STACK 200h
.CODE
org 07c00h
START:
jmp Begin
nop
BD_OEMNAME DB "SMITH ", 0
BS_BYTESPERSEC DW 512
BPB_SECPERCLUS DB 1
BPB_RSVDSECCNT DW 1
BPB_NUMFATS DB 2
BPB_ROOTENTCHT DW 224
BPB_TOTSEC16 DW 2880
BPB_MEDIAID DB 0F0H
BPB_FATSZ16 DW 9
BPB_SECPERTRK DW 18
BPB_NUMHEADS DW 2
BPB_HIDDSEC DD 0
BPB_TOTSEC32 DD 0
ResetDisk:
mov ah, 00h
mov dl, 0
int 13h
Begin:
xor ax, ax
mov ds, ax
mov es, ax
mov di, offset CommandLine
mov bx, 07e00h; memory offset address, es segment address
mov ax, 0201h; ah = 02h, al = number of sectors to read
mov cx, 0002h; ch = low 8 bits of cyl, cl = sector number bits 0 - 5 bits 6,7 hard disk only
mov dx, 0100h; dh = head number, dl = drive number
int 13h
jc ResetDisk
mov si, offset Blog
call PrintString
mov si, offset Version
call PrintString
mov si, offset Prompt
call PrintString
OsLoop:
mov ax, 1000h
int 16h
cmp ax, 0e08h
je OsBackSpace
cmp ax, 4be0h
je OsMoveBackChar
cmp ax, 4de0h
je OsMoveForwardChar
cmp ax, 1c0dh
je OsEnter
cmp al, 32
jb OsLoop
mov ah, 0eh
int 10h
mov byte ptr [di], 0
stosb
mov byte ptr [di], 0
jmp OsLoop
OsMoveBackChar:
mov ax, 0e08h
int 10h
dec di
jmp OsLoop
OsMoveForwardChar:
mov al, byte ptr [di]
test al, al
jz OsLoop
mov ah, 0eh
int 10h
inc di
jmp OsLoop
OsBackSpace:
mov ax, offset CommandLine
cmp di, ax
jbe OsLoop
push offset OsLoop
mov si, offset BackSpace
dec di
mov byte ptr [di], 0
jmp PrintString
OsEnter:
push offset OsLoop
mov si, offset CarraigeReturn
call PrintString
mov si, offset CommandLine
call PrintString
mov si, offset CarraigeReturn
call PrintString
mov si, offset CommandLine
lodsb
cmp al, "?"
je PrintHelp
cmp al, 32
je OsBeginMath
mov si, offset Invalid
call PrintString
OsReturnToEnter:
mov si, offset CarraigeReturn
call PrintString
mov si, offset Prompt
call PrintString
mov di, offset CommandLine
ret
OsBeginMath:
mov di, offset MathLine
push OsReturnToEnter
lodsb
cmp al, "b"
je MathB
cmp al, "o"
je MathO
cmp al, "h"
je MathH
cmp al, "B"
je MathB
cmp al, "O"
je MathO
cmp al, "H"
je MathH
dec si
mov dx, 10
MathLoop:
push ax
xor ax, ax
lodsb
mov cx, ax
pop ax
test cl, cl
jz ExitMath
cmp cl, 42
jb ExitMathInvalid
cmp cl, 48
jb MathSymbol
cmp cl, 48
jb ExitMathInvalid
cmp cl, 57
ja ExitMathInvalid
sub cl, 48
mul dx
add ax, cx
jmp MathLoop
MathSymbol:
stosw
sub cl, 42
stosw
jmp MathLoop
MathB:
mov dx, 2
jmp MathLoop
MathO:
mov dx, 8
jmp MathLoop
MathH:
mov dx, 16
jmp MathLoop
ExitMathInvalid:
mov si, offset InvalidMath
jmp PrintString
ExitMath:
ret
PrintHelp:
mov si, offset HelpScreen
push offset OsReturnToEnter
PrintString:
mov ah, 0eh
StrLoop:
lodsb
test al, al
jz ExitStrLoop
int 10h
jmp StrLoop
ExitStrLoop:
ret
HelpScreen db 10, 13, "?-Help Screen", 10, 13, " B-Binary Math", 10, 13, " O-Octal Math", 10, 13, " H-Hexadecimal Math", 10, 13, 0
BackSpace db 8, 32, 8, 0
InvalidMath db "Invalid Operand", 10, 13, 0
Invalid db "Invalid Instruction", 10, 13, 0
Prompt db ">", 0
CarraigeReturn db 10, 13, 0
CommandLine db 0
Version db "Welcome To Indigo V0.0.1X", 10, 13, "By Tommy", 10, 13, 0
Padding db 0,0,0
MathLine dw 0
BootSig dw 0aa55h
Blog db "This is an extended memory test", 0
END START
from a program that i wrote i know for fact that cs, ds, es are 0000h from a program i made.
The head switch occurs at the end of the track, so the correct sequence is:
cylinder 0, head 0, sector 1
cylinder 0, head 0, sector 2
...
cylinder 0, head 0, sector 18
cylinder 0, head 1, sector 1
...
On my system, I had to set up a workable stack before I could get the code to display the blog string.
push cs
pop ss
mov sp, 7c00h
This places the stack immediately below the loaded sector.
tried that too. what i ment by not sure if the bios is dumping me at 7c00h. im not sure if its putting me at that address at all. i wrote a little program to display the value of all the registers besides ax, bx, cx, dx, and they all came back 0 except the ss which was 30h and sp which was 100 h.
dont know how but i got it to work. michealw thanks for mentioning that it goes to sector 18 before flipping heads. even though i checked it i dont think debug was writting to the floppy properly.
Quote from: MichaelW on September 01, 2006, 11:11:18 PM
The head switch occurs at the end of the track, so the correct sequence is:
cylinder 0, head 0, sector 1
cylinder 0, head 0, sector 2
...
cylinder 0, head 0, sector 18
cylinder 0, head 1, sector 1
...
:dazzled: Oops :red
Sorry, don't know what I was thinking at the time! Must've been a long day :lol
its ok it happens. important thing is that my code now works.
Quote from: Tedd on September 04, 2006, 11:38:56 AM
:dazzled: Oops :red
Sorry, don't know what I was thinking at the time! Must've been a long day :lol
I thought your explanation was wrong when I read it, but then I had to check the references to be sure, because I can't recall ever seeing you post bad information.
Yeh, I obviously wasn't thinking straight.. I think I had something in mind about reading multiple sectors at once since the head is in the same place (over the sectors of both sides) at the same time; while this could be possible (I think some controllers do even allow it), it's not the same as reading the sectors as they're layed out on the disk.
Maybe I should take it as a signal that I'm getting old :lol
hey it happens to the best of us.