Author Topic: Everdrive SDK / SD card IO  (Read 2243 times)

megatron-uk

  • Full Member
  • ***
  • Posts: 219
Everdrive SDK / SD card IO
« on: December 30, 2013, 10:11:44 PM »
Has anyone made any further progress in interacting with the Everdrive SD filesystem side of things from the PCE?

I found the following posts relating to reading from the SD card:

http://krikzz.com/forum/index.php?topic=69.msg358#msg358
http://pcedev.blockos.org/viewtopic.php?f=5&t=90
https://gist.github.com/BlockoS/3240689 (or saf

Unfortunately it doesn't look like any of the work has got to a point where it is easy to include a library within HuC to read and write from the SD card... though some of the above is very promising. I'd love to be able to write a simple tool to backup/restore save ram to/from the SD card, and with the BRAM functions in HuC it looks fairly trivial to do so (I'm poking about with some test code in Mednafen to read out individual saves - the existing hooks in HuC are really quite nice!).

Sadly my assembly skill is virtually non-existent, so I have no idea where to go from here. It would seem the easiest way forward would be get the edio.c library from Krikzz to a point where reading (and writing!) sectors to and from the SD card is as simple as calling diskReadSector() and diskWriteSector(). Add an embedded FAT wrapper around that (PetitFS has been mentioned in the above posts - 4k library plus 44 bytes work ram) and it should be possible to use the Everdrive as an (effectively) unlimited storage device with normal C-style file() calls.

Info - As of January 2014, the source code for my everdrive-fat HuC library is available on github at:
https://github.com/megatron-uk/everdrive-fat

This also includes the low-level SD library as written by MooZ. I will be trying to keep it as closely synced to my current local version as possible. If I commit any major new functionality I will post the details in this thread.

2014-02-03
Committed latest everdrive-fat code to github. Optimised several math32.h functions and removed debug code from fat-files.h. Initial basic implementation of file read functionality via fread(). We can read file contents now! Still to test multi-cluster directories (don't use with directories with lots of files in as yet!).

2014-01-27
Updated github, added support for fopen(), fclose() in fat-files.h, directory traversal and finding file entries within root or sub directories. Multi-cluster directories not yet tested.

2014-01-21
Initial commit. Added test example which scans your card/everdrive to look for FAT partitions and report FAT filesystem details via fat-dev.h and fat-vol.h. No user-accessible functions available in fat-files.h yet.
« Last Edit: February 03, 2014, 09:15:55 AM by megatron-uk »

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Everdrive SDK / SD card IO
« Reply #1 on: December 31, 2013, 05:50:17 AM »
MooZ is the man :)

megatron-uk

  • Full Member
  • ***
  • Posts: 219
Re: Everdrive SDK / SD card IO
« Reply #2 on: January 04, 2014, 02:55:24 AM »
I've been in contact with MooZ and he's updated his ed_sd.asm library for interacting with the Everdrive.

The latest version is available here:
https://gist.github.com/BlockoS/3240689

He's also updated the syntax to be callable from HuC. I've put together a basic set of tests around the asm code:

#asm
   .include "ed_sd.asm"
#endasm
main() {
   char ed_error;
   
   init_screen();
   put_string("init_screen", 1, 0);
   
   put_string("ed_begin", 1, 2);
   ed_begin();
   put_string("OK", 20, 2)   ;

   put_string("disk_init", 1, 3);
   ed_error = 0;
   ed_error = disk_init();
   put_hex(ed_error, 2, 10, 3);
   
   put_string("ed_end", 1, 4);
   ed_end();
   put_string("OK", 20, 4)   ;
   
   for (;;) {
      vsync();
      joytrg(0);
   }
}

Unfortunately I'm currently halting at the disk_init() stage - although things must be partially working as the red led on the everdrive lights up and stays lit as soon as my code runs.

More info when I make any further progress.

NightWolve

  • Hero Member
  • *****
  • Posts: 5277
Re: Everdrive SDK / SD card IO
« Reply #3 on: January 04, 2014, 10:39:22 AM »
MooZ is the man :)

Ah, I remember him from #UtopiaSoft on Efnet IRC. One of the big-time players in the French PCE scene as I recall, or something. ;)

megatron-uk

  • Full Member
  • ***
  • Posts: 219
Re: Everdrive SDK / SD card IO
« Reply #4 on: January 04, 2014, 09:16:36 PM »
Thanks to MooZ, his latest asm code now initialises the Everdrive hardware and performs a disk_read_open call without locking the hardware. The call to disk_read_sector still returns an error code (62) however.

In the meantime, I'm working on writing a simple FAT filesystem driver in HuC using the docs from:
http://www.pjrc.com/tech/8051/ide/fat32.html

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Everdrive SDK / SD card IO
« Reply #5 on: January 05, 2014, 02:49:37 AM »
MooZ is the man :)

Ah, I remember him from #UtopiaSoft on Efnet IRC. One of the big-time players in the French PCE scene as I recall, or something. ;)

 Yeah. PCE Parisian :D He's done coding, hacking, translations, demos, etc for PCE.

megatron-uk

  • Full Member
  • ***
  • Posts: 219
Re: Everdrive SDK / SD card IO
« Reply #6 on: January 05, 2014, 07:22:06 AM »
Raw sector reading is now working courtesy of MooZ. I'm still playing around with things and attempting to read MBR and partition information, but things are looking *very* promising!

NightWolve

  • Hero Member
  • *****
  • Posts: 5277
Re: Everdrive SDK / SD card IO
« Reply #7 on: January 05, 2014, 08:07:00 AM »
Don't suppose it's possible to upgrade his loader to add support for a simple save/load state feature ? Just one slot would be great.

megatron-uk

  • Full Member
  • ***
  • Posts: 219
Re: Everdrive SDK / SD card IO
« Reply #8 on: January 05, 2014, 09:59:13 AM »
Not sure if it would be possible - you'd have to have something PCE-side that was capable of freezing the state of all memory and registers and dumping them to disk. Without running some sort of monitor process on the FPGA to do it, I'm not sure how you'd grab all that state info. I don't know if it's even feasible for the Everdrive side of things to read back from the console hardware - the process is normally the other way around.

My idea was simply to make the existing BRAM functionality built in to the standard PCE hardware more flexible via writing a tool for loading pre-existing saves from SD and being able to save them back out again.

BTW - I'm now in the midst of trying to extract partition table information from the sd card - I'm aiming to use the first available FAT partition of the 4 possible primary partitions for now. The MBR layout is pretty simple:

446 bytes boot code, followed by a 64byte partition table (4 x 16 byte data areas), then by 2 checksum bytes (always 0x55 & 0xAA)

I'm picking up the two check bytes now (at least my mbr is valid, lol!) and am writing some code to extract the filesystem type (byte 5 of the 16 byte area) and LBA start sector (bytes 9 - 12).

Once I have the start sector I can then pass the info to a second disk_read_sector call to read the FAT volume sector for that partition, which contains info about where the filesystem starts and where the root directory is located on disk.

NightWolve

  • Hero Member
  • *****
  • Posts: 5277
Re: Everdrive SDK / SD card IO
« Reply #9 on: January 05, 2014, 10:06:26 AM »
I don't know if it's even feasible for the Everdrive side of things to read back from the console hardware - the process is normally the other way around.

Ah yeah, you got a point. Unless this has been accomplished in other flashcarts, can't think of a case ATM, but I wonder if it was done. Has it ?? I dunno... Well, I guess the only feasible cheats are what somebody here was already doing which was to catalog all the offsets in PCE ROM files that correspond to number of lives, or continues, etc. and overwriting them to activate a cheat prior to loading the ROM.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Everdrive SDK / SD card IO
« Reply #10 on: January 05, 2014, 11:15:48 AM »


If you can write to the SD card from the PCE side, then you can save BRAM quite easily to the card. But save state? Some registers are read only. You'd have to hack the game to keep track of those regs (write hook code to make copies to a set in ram. And extra ram at that, like CD base 64k ram). Else you'd need a pass through card device, that monitors the bus and save those writes (as well as keeps track of start/end of the video frame - to sync with). BRAM yes, save states: per game hack dependent.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Everdrive SDK / SD card IO
« Reply #11 on: January 06, 2014, 09:56:31 AM »
Oh man, I just thought of something; if you can get write support for the SD card... music tracker time! Both MooZ and I worked on trackers native to the PCE, but there was no way save your songs (other than some convoluted method). That would be awesome, if you could save them to the card. Or even load instruments/samples/songs from the SD card (into ram, like CD base ram). I've already got mouse support code up and running for the PCE mouse.

 Make this happen, megatron-uk! :D

esteban

  • Hero Member
  • *****
  • Posts: 24063
Everdrive SDK / SD card IO
« Reply #12 on: January 06, 2014, 10:05:18 AM »
Oh man, I just thought of something; if you can get write support for the SD card... music tracker time! Both MooZ and I worked on trackers native to the PCE, but there was no way save your songs (other than some convoluted method). That would be awesome, if you could save them to the card. Or even load instruments/samples/songs from the SD card (into ram, like CD base ram). I've already got mouse support code up and running for the PCE mouse.

 Make this happen, megatron-uk! :D

I would buy a PCE mouse simply for this!
« Last Edit: January 06, 2014, 10:07:07 AM by esteban »
  |    | 

megatron-uk

  • Full Member
  • ***
  • Posts: 219
Re: Everdrive SDK / SD card IO
« Reply #13 on: January 07, 2014, 09:43:59 AM »
Just been working on a basic set of math functions for 32bit integers in HuC (needed for FAT32 LBA addressing), now that I have that done I should be able to start looking at reading directory and file positions from the volume sector at the beginning of the filesystem.

MooZ has stated he is going to tweak the asm library to tidy things up and then turn his attention to write support.

It might take some time, but I think we have got a good chance of getting to a point where we can use the Everdrive as a general purpose filesystem.

Bonknuts

  • Hero Member
  • *****
  • Posts: 3292
Re: Everdrive SDK / SD card IO
« Reply #14 on: January 08, 2014, 04:32:37 AM »
It'd also be nice to be able to dump CD data (all of it) directly to the SD card as well.