Author Topic: Flash save type Save Manager  (Read 39734 times)

0 Members and 3 Guests are viewing this topic.

Offline ChillyWilly

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1751
  • Just a coding machine.
Re: Flash save type Save Manager
« Reply #15 on: January 17, 2014, 03:27:17 AM »
Yes, I need to update that as well as the GameShark code. I'll try to work on the update soon. I just switched to a new system, so I still need to re-setup all my N64 tools.

Offline SuperNintendoDisney

  • Newbie
  • *
  • Posts: 3
  • NEO newbie
Re: Flash save type Save Manager
« Reply #16 on: July 10, 2014, 12:23:17 AM »
I have scoured the internet for ways to restore a save from my PC directly to the original cart. Using the DexDrive + N64 Gameshark 3.3 setup is one of the biggest hassles I have ever dealt with in all my years of gaming. I haven't been able to get it to work with every game, only a few that the setup allows. I registered with this forum for the sole purpose of replying to this topic. I want to agree with many other users that I would instantly buy your Neo Myth 64 product if it was capable of restoring saves onto a cart from the PC. I could not find any webpage that confirmed whether or not it was possible, but after reading through the forum, I realize it is not yet possible. Your Neo Myth 64 appears to be an amazing product, having such capabilities to restore saves directly to the cart would make it near perfect in my eyes. Please add this functionality, you are doing an excellent job

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Flash save type Save Manager
« Reply #17 on: July 11, 2014, 12:53:48 PM »
I just had a quick look at the source code of the n64 myth menu and it seems like the necessary functions are already written by ChillyWilly, just not implemented in the actual user menu.

I'm sure that as soon as Chillywilly finds the time he will wrap this up  ~sm-55.gif~.gif

Offline SuperNintendoDisney

  • Newbie
  • *
  • Posts: 3
  • NEO newbie
Re: Flash save type Save Manager
« Reply #18 on: July 24, 2014, 07:33:32 PM »
Writing saves from the SD card to the game cartridge will soon be a feature? That is excellent news! Take your time, you have made someone very happy today! Once I purchase a NeoMythCart, will I need to do a software update in order to gain access to the full functionality of the product? When will the update to the software that allows writing to carts be available? In other words, how long until this becomes an actual feature
« Last Edit: August 15, 2014, 06:50:36 PM by SuperNintendoDisney »

Offline nintendo60george

  • Newbie
  • *
  • Posts: 6
  • NEO newbie
Re: Flash save type Save Manager
« Reply #19 on: September 27, 2014, 02:55:26 PM »
I ordered my N64 Myth. I await when the menu is updated to restore flashram saves, only a few games use this but they are very good games. Until then my new Mega Man, Majora's Mask, Paper Mario, and Pokemon Stadium cartridges will be sad and empty. Restoring saves to these games is also helpful for speedrunners. No other device can do this, so when this is updated it will be the first.

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Flash save type Save Manager
« Reply #20 on: October 21, 2014, 12:13:43 AM »
Today I finished writing my little Jet Force Gemini Unlocker.
It writes a 100% complete flashram save game to a real Jet Force Gemini cartridge attached to the back of the Neo N64 Myth.

WARNING: USE AT OWN RISK.

Manual:
- Either copy "UNLOCK_JFG.z64" to your SD card or burn it to your Neo2 512 GBA cart. Be sure to set the save type to EXT CARD or it won't work.  Now plug a Jet Force Gemini cart into your Neo N64 Myth and launch the Unlocker.



I used parts of the following open source projects:
- Flashram read/write code from http://themanbehindcurtain.blogspot.de

I had to make a few changes to the original flashsram routines by themanbehindcurtain to make it work with my setup:
- In N64FlashRAM.c change from "PI_DMAFromSRAM(dst, (offset / 2), size)" to "PI_DMAFromSRAM(dst, offset, size)"
- In N64FlashRAM.c change the size of the slots from 960 to 1024
- In the main function change _1M_FLASHRAM to 131072
- In the main function change the Bank size to 16384 ( example FRAM_ReadBank(savegame + (i * 16384), i); )
« Last Edit: October 15, 2018, 12:34:02 AM by sanni »

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Flash save type Save Manager
« Reply #21 on: October 21, 2014, 01:17:08 PM »
Good work sanni  :)

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Flash save type Save Manager
« Reply #22 on: October 21, 2014, 03:22:56 PM »
Here the same deal just for Zelda Majoras Mask.
The difference compared to Jet Force Gemini was that for reading the flash it actually needed the "/2" in "PI_DMAFromSRAM(dst, (offset / 2), size)"

This means that reading out flashram saves is different for different games.

Now I need to hunt down more flashram games :P
« Last Edit: October 15, 2018, 12:33:48 AM by sanni »

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Flash save type Save Manager
« Reply #23 on: October 21, 2014, 08:03:11 PM »

Maybe it is that you're running your app as mythaware homebrew with
the whole system mounted and you're forgetting to disable NEO2 sram
in flash ram R/W operations ?

Have a look at neo_copyfrom_fram in neo_2.c and make a copy of it
that does the opposite(writes to flash ram (You simply swtich the operations
(now you're writing to flash ram) and set the status register to 2  before writes).

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Flash save type Save Manager
« Reply #24 on: October 21, 2014, 09:50:33 PM »
Good thinking.

I did the following test. I formated my Neo2 512 cart, the one without the SD slot. Then burned both the MM and the JFG flashram writer apps to it. The ones without "_SD" in their name aren't using the Neo2.c or anything else related to the Myth and are literally just a stripped down version of the reader/writer made by themanbehindcurtain, with the changes made by me to the reading/writing routines as posted in aboves posts.

The only difference between the two apps besides the included save file (stored as byte array in the main.c) is this line "PI_DMAFromSRAM(dst, (offset / 2), size)" where MM has the "offset / 2" while JFG just has "offset". Writing is the same for both.

Now with the MM writer app I can write and read to the Majoras Mask cartridge without error but reading from a Jet Force Gemini cart fails. The same applies to the JFG writer, so the JFG writer works with JFG but fails with MM.
It also seems like the reading routine from the Neo Myth Menu's save manager also fails reading JFG correctly.

Therefore for some unknown reasons, reading out the flashram seems to be different for different cartridges.

I attached the source code below in case anyone want's to try some other flashram game like Pokemon. I compiled it with the standard libdragon toolchain for Windows from here: https://dragonminded.com/n64dev
« Last Edit: October 15, 2018, 12:33:37 AM by sanni »

Offline Conle

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2203
Re: Flash save type Save Manager
« Reply #25 on: October 22, 2014, 11:11:19 AM »

I'm quite busy to try it out now , but the help i can offer at the moment is :

 
Code: [Select]
change in main.c
static uint8_t buffer[_1M_FLASHRAM];
to
static uint8_t  __attribute__((aligned(16))) buffer[_1M_FLASHRAM];

Replace fram bank read loop with just a call to:

Code: [Select]
//add it somewhere in main

void fram_read(uint8_t* dst,uint32_t offset,uint32_t size) {
uint8_t* e_dst = dst + size;
for (;dst < e_dst;dst += 128U,offset += 128U) {
fram_cmd(FRAM_READ_MODE_CMD);
delay(1);
ctl_sram_rd(dst,offset >> 1U,128);
}
}


Replace fram_writeblock with:
Code: [Select]
void FRAM_WriteBlock(uint8_t *src, uint32_t blockNo) {
fram_cmd(FRAM_WRITE_MODE_CMD);
delay(1);
ctl_sram_wr(src,0,128);
FRAM_SetWritingOffset(blockNo);
fram_cmd(FRAM_EXECUTE_CMD);
delay(1);
}


Replace all stack buffers with a generic aligned one in the flashram module to make sure mem offsets dont get aligned in  dma functions    , or if you want hacks :
Code: [Select]
replace uint8_t buffer[16 * 1024];
with
static uint8_t  __attribute__((aligned(16))) buffer[16 * 1024];

replace uint8_t buffer[1024];
with
static uint8_t  __attribute__((aligned(16))) buffer[1024];

Note the dma/ctl_read/ctl_write functions used come from my gnuboy64 port (You need a special module for it) since i spotted a few issues
with libdragon back then:
https://code.google.com/p/gnuboy64/source/browse/trunk/ctl.c?spec=svn9&r=9

 

Offline nintendo60george

  • Newbie
  • *
  • Posts: 6
  • NEO newbie
Re: Flash save type Save Manager
« Reply #26 on: December 29, 2014, 03:04:37 AM »
How do I compile the flash writing code so it can run as an app on the Myth? I'm using Windows and downloaded the 2009 compiled libdragon toolchain, set the path as an environment variable, ran the makefile, and instead of making a .z64 file it made me totally confused. ~sm-73.gif~.gif

I found and tried the tutorial at http://www.neoflash.com/forum/index.php?topic=7444.0 and I could compile and run the programs in the virtual machine. In order to get the program on the virtual machine, I copied the program to the SD card, then open that card with VirtualBox's Devices menu.

I was able to write a save to a Pokemon Stadium cartridge simply by pasting a byte-flipped Project64 save (flip every two bytes, so the line "ZELDA001" would say "DLEZ100A" in a hex editor) over the savegame variable then making the makefile.

Besides that one writing success I've had several problems.
1. The Neo Myth's built-in save read function for flash-128kb saves doesn't read the Pokemon Stadium 1 save correctly.
2. I then tried writing Pokemon Stadium 2 with the modified Majora's Mask writer (only replaced the savegame variable), but it couldn't erase the old save. Something different is going on here, because the offset / 2 change doesn't work either.
« Last Edit: January 01, 2015, 10:29:27 PM by nintendo60george »

Offline sanni

  • Moderator
  • Hero Member
  • *****
  • Posts: 502
Re: Flash save type Save Manager
« Reply #27 on: January 02, 2015, 02:47:31 AM »
I noticed the following with my Pokemon Stadium 1 cartridge:
- As you said it's basicly the same type as Majoras Mask
- But I had to erase twice before the flash was truly erased

Yes, the Flashram reader that is currently build into the N64 Myth Menu doesn't work for the cartridges I tried (Jet Force and Majoras Mask) either. :(

For sake of completeness I attached a rom that writes a 100% save to a Pokemon Stadium 1 cartridge. I does give some write errors but it still works, my guess is that the Pokemon Stadium Flashram is a little bit smaller in size than the one from Majoras Mask.
« Last Edit: October 15, 2018, 12:33:26 AM by sanni »

Offline nintendo60george

  • Newbie
  • *
  • Posts: 6
  • NEO newbie
Re: Flash save type Save Manager
« Reply #28 on: January 03, 2015, 12:30:13 AM »
The built-in save reader is consistently wrong for the flash saves. At the end of every 0x100 byte area, it reads 0x40 bytes from the start of the next area instead. So if I had erased the first 0x4000 bytes then it should all be FF, but it reads 0x3FC0-0x3FFF the same as 0x4000-0x403F instead. I was able to check what my erasing test code was doing to Pokemon Stadium 2 this way.

When erasing just the first bank of Stadium 2, it erases the first 0x8000 bytes of the save (this is the same behavior I got from using the Majora's/Stadium 1 code, which erases eight banks in a loop). Stadium 1 erases the first 0x4000 bytes as expected, so something different is happening. So far I've tried many variations on the erase function and haven't been able to erase anything but the first quarter of the Pokemon Stadium 2 save. Maybe there's a bank switching command? I can't find any documentation on how the N64 flash commands work. I found code here that uses the same seven flash commands, so nothing new.

Writing the flash save works as expected (it can write 0 over 1, but not 1 over 0).
« Last Edit: January 03, 2015, 02:23:55 AM by nintendo60george »

Offline nintendo60george

  • Newbie
  • *
  • Posts: 6
  • NEO newbie
Re: Flash save type Save Manager
« Reply #29 on: January 03, 2015, 02:22:25 AM »
I tinkered with the code and figured out what was happening with Pokemon Stadium 2.

First, its banks are twice the size. Instead of having 8 banks 0x4000 long like the other flash cartridges, it has 4 banks 0x8000 long.

Second, the flash erase command only happened the first time it was called, then did nothing. I could only erase the first 0x8000 bytes because I was always starting by erasing at address 0x7F. Erasing anywhere between 0x000 and 0x07F erases bank 1, between 0x080 and 0x0FF erases bank 2, between 0x100 and 0x17F erases bank 3, and between 0x180 and 0x1FF erases bank 4.

I was able to erase the entire save by calling erase on first sector, recompile and erase on third sector, then recompile and erase the other two one by one. Why is this happening? I guessed that it needs to call the write command before another erase command will work, so I made another write loop that erases at the start of each 256 blocks before writing. That wrote the first 0x8000 bytes correctly, then left the other three banks at 0xFF (and this was after I wrote a dummy save over the cartridge). Very strange! I got the save to work after writing over the FFs without doing an erase, but I'd like to get the erase then write to work cleanly. I'll try tinkering with delays and see if that changes anything.