Page 1 of 1
Writing / Reading from hd0, etc
Posted: Mon Nov 02, 2009 8:23 am
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!
Re: Writing / Reading from hd0, etc
Posted: Mon Nov 02, 2009 8:48 am
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
Re: Writing / Reading from hd0, etc
Posted: Mon Nov 02, 2009 1:05 pm
by Combuster
Re: Writing / Reading from hd0, etc
Posted: Mon Nov 02, 2009 1:13 pm
by Dex
Also see this
http://forum.osdev.org/viewtopic.php?t= ... hdd#p85105
And then as BastetFurry said read about how fat works.
Re: Writing / Reading from hd0, etc
Posted: Mon Nov 02, 2009 10:25 pm
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?
Re: Writing / Reading from hd0, etc
Posted: Wed Nov 04, 2009 12:42 pm
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?
Re: Writing / Reading from hd0, etc
Posted: Wed Nov 04, 2009 8:03 pm
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.
Re: Writing / Reading from hd0, etc
Posted: Wed Nov 04, 2009 9:50 pm
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.
Re: Writing / Reading from hd0, etc
Posted: Wed Nov 04, 2009 10:12 pm
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?