Writing / Reading from hd0, etc

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
blah569
Posts: 16
Joined: Wed Feb 07, 2007 9:57 pm
Location: America
Contact:

Writing / Reading from hd0, etc

Post by blah569 »

If you looked at my screenshots, I'm able to access directories from the shell, however, I kind of 'cheated.' I just store virtual memory that is read from, it isn't actually on the disk. I'm wondering how we can write files to the disk, and read files from the disk. Basically the concept of how to implement such feature?

I was thinking about having a directory "conts" in my ISO file that formats the drive and sets the entire drive to the format of "conts." Would that be practical?

Thanks!
There's no place like 127.0.0.1.
User avatar
BastetFurry
Posts: 4
Joined: Sun Nov 01, 2009 4:36 pm

Re: Writing / Reading from hd0, etc

Post by BastetFurry »

In my Z80 Thingy i will have some kernel routines accessing the SD card and stepping trough the FAT for the caller app.
So when i have a filemanager app i only need to get the cluster of the root dir trough function GetRootDirCluster
and pass that to WriteClusterToMemory.
When i want to write something i call GetFirstFreeCluster which returns an unused (0x00000000) cluster, call WriteMemToCluster with the cluster, the starting address i want to write and how much i want to write. When i need to write more than 512 byte i just call GetNextFreeCluster and WriteFollowCluster with the new and old cluster number. At the end i just call CloseClusterchain which writes 0x0fffffff into the last cluster.

Get yourself the FAT specs and try to read a file from a FAT media, if you get the hang of it its a walk in the park implementing it. My problem will be implementing 32 bit stuff on an 8 bit CPU, but thats just a hill in said park and no wall... ;)

BTW: If you search trough the microcontroller world there are some nice FAT implementations to learn from.
Its German and for the AVR using gcc-avr, but you might be able to make something out of it: http://www.mikrocontroller.net/articles/AVR_FAT32
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Writing / Reading from hd0, etc

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: Writing / Reading from hd0, etc

Post by Dex »

Also see this http://forum.osdev.org/viewtopic.php?t= ... hdd#p85105
And then as BastetFurry said read about how fat works.
blah569
Posts: 16
Joined: Wed Feb 07, 2007 9:57 pm
Location: America
Contact:

Re: Writing / Reading from hd0, etc

Post by blah569 »

Thanks for the replies! I'm wanting to write / read to 1f0?

Basically, does it work similar to this?

Broken into sectors that can be divided by data and organized by a 'divider' (/) of the sorts? Am I wanting to write to 1f0?
There's no place like 127.0.0.1.
smeezekitty
Member
Member
Posts: 50
Joined: Sat Mar 21, 2009 9:42 pm

Re: Writing / Reading from hd0, etc

Post by smeezekitty »

@blah569
in real mode you can use 0x13h bios.
in protected mode you have to program the ATA controller.
@BastetFurry
isnt programming an 8 bit processor a bit too 1980s?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: Writing / Reading from hd0, etc

Post by Brynet-Inc »

smeezekitty wrote:@blah569
in real mode you can use 0x13h bios.
You can, but don't have to.
smeezekitty wrote:@BastetFurry
isnt programming an 8 bit processor a bit too 1980s?
A lot of embedded devices still use 8-bit processors, including the Z80 or the i8051/i8052.. my USB 2.0 disk enclosure has one.

There is nothing wrong with expanding ones knowledge of other architectures and programming within new constraints.

Please think before posting, the 1980's gave us BSD and The Smurf's.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Writing / Reading from hd0, etc

Post by Firestryke31 »

Also, the TI-83+ series calculators (including the current TI-84+) uses the z80 processor, so there are many z80 assembly programmers still out there today.

IIRC the TI-82, TI-83, TI-83+, TI-83+ SE, TI-84+, TI-84+ SE, and TI-85 calculators all use the z80. The TI-89 series, as well as a couple others that I can't remember right now, all use the Motorola 68K.

I'm sure there are many other still-manufactured products that use the z80, since you can still buy them from the manufacturer.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
blah569
Posts: 16
Joined: Wed Feb 07, 2007 9:57 pm
Location: America
Contact:

Re: Writing / Reading from hd0, etc

Post by blah569 »

Thanks for the replies! However, in using real mode, how would you go about querying the BIOS to find all active medias? (If querying the BIOS is needed). What would basically be the logic to send a query to the BIOS (or whatever else) to return a list of all active medias present?

For the concept of formatting, you would basically write 0x0 to all sectors on the drive following the guidelines for the desired file system?
There's no place like 127.0.0.1.
Post Reply