writing to flashrom (2MB rom) and support for emulators

Страница 1/8
| 2 | 3 | 4 | 5 | 6

By norakomi

Paragon (1084)

Аватар пользователя norakomi

01-05-2020, 13:01

Hi All !!!

For Deva we wanna add the option to write savefiledata to flashrom.
Both games are 2MB roms.

Can anyone tell me how I can write to the flashrom, and how can I test this in bluemsx and openmsx ?
Is there already support for this in the emulators ?

Для того, чтобы оставить комментарий, необходимо регистрация или !login

By Grauw

Ascended (9342)

Аватар пользователя Grauw

01-05-2020, 14:01

I’ve never actually done this but,

1. OpenMSX is able to emulate MegaFlashROM SCC+ SD and Carnivore2
2. MegaFlashROM SCC+ SD uses the M29W640FB FlashROM.

The datasheets should in principle describe everything needed to write to flash ROM, and I think most FlashROMs work in the same way. Taking the M29W640FB datasheet as example, section 4 describes the “command interface” which you can use to erase blocks and enable writes. Each command starts by writing “magic values” 0AAH to address *AAAH and then 55H to address *555H, as you can see in table 7.

Flash memory works such that you can not erase individual bytes but only large blocks of e.g. 64K. Every time you erase you wear down the memory a bit, so you want to minimise this. The number of erases you can do per block is limited, see table 8, if you exceed it the memory block is no longer guaranteed to work. The erase sets every bit in the block to 1.

However, once erased you can write to memory byte-by-byte using the “program” command. The exact restriction is that you can change bits from 1 to 0 (so after an erase you can write any value), but you can never change bits from 0 to 1. This means that you can (afaik) even write to previously-written memory under those restrictions.

To minimise the number of block erases to not wear down the user’s FlashROM cartridges, you will want to slowly fill up a 64K block with save data until it’s full. Here’s a simple example method to store a single savegame:

Let’s say you divide a 64K block into 64 savegames each 1K in size, and the first byte of the savegame is a “status marker”: 0FFH to indicate “free”, 80H to indicate “used”. Then, each time you want to write a new savegame you find the first block with the 0FFH marker and write there. If you run out of free savegames, you erase the block and start from index 0. When you want to load the savegame you simply load the last available one.

A more advanced method to store multiple savegames could use the ability to re-write bytes with more zeroes. In this case you can introduce another status marker value: 00H to indicate “deleted”. Then to delete a previous savegame, you simply overwrite the status marker 80H “used” with 00H “deleted”.

By Louthrax

Prophet (2281)

Аватар пользователя Louthrax

01-05-2020, 14:07

Hi Norakomi,

There are differences between the different flash devices. In sofaROM, I have several routines to detect and access the different models, but it's coded in C (I can share that with you if you want, but it's kind of complex and messy...).

If you plan to release your games only on a physical and dedicated cartridge that has its own flash memory, it will be simpler of course (but not if you distribute your games as "generic" ROM images). Not sure which way you want to go ?

Also, if your save data is in flash memory, this will prevent the user to play another game that could erase that area. You'd then have provide a tool that can backup and restore this save area to disk.

Alternatives to that are saving game data to disk directly (several other games are already doing that), or use the FM-PAC SRAM (only 16KB, or maybe 8KB, not sure anymore...).

By norakomi

Paragon (1084)

Аватар пользователя norakomi

17-09-2020, 22:14

Thanks so much !!
@Grauw I have made a little bit of code to erase a block and to write data to flashrom.
You mentioned Openmsx supports this. How do I test this in openmsx ?
I tried adding extensions MegaFlashROM SCC+ or Carnivore2, but this didn't seem to work.
I think the rom is a Konami5 Mapper.

@louthrax any routines you can share are welcome. I don't need to detect a device. I just need 2 simple routines to:
1) erase a block
2) write to a block
Deva will be release in physical cartridge and .rom file.

By norakomi

Paragon (1084)

Аватар пользователя norakomi

01-05-2020, 14:39

on page 27 of the manual http://www.farnell.com/datasheets/40281.pdf
I find to erase a block:
;block erase 6 commands
ld a,$aa
ld ($4555),a
ld a,$55
ld ($42aa),a
ld a,$80
ld ($4555),a
ld a,$aa
ld ($4555),a
ld a,$55
ld ($42aa),a
ld a,$30
ld ($4000),a ;erase block $4000- $5fff
___________________________________________________
and I found:
;block Program (I guess this is writing the data to the flashrom)
ld a,$aa
ld ($4555),a
ld a,$55
ld ($42aa),a
ld a,$a0
ld ($4555),a

and after this I can just write my data like this
ld a,data
ld ($4000),a etc

By Grauw

Ascended (9342)

Аватар пользователя Grauw

01-05-2020, 14:57

If you extract this archive to the openMSX user share directory it should include the initial ROM data for the MegaFlashROM SCC+ SD. The emulation then works like the cartridge does on a real MSX, so you need to boot DOS2 and load the ROM onto the cartridge with opfxsd.

By gdx

Prophet (3762)

Аватар пользователя gdx

01-05-2020, 15:01

Try to flash with FL/FL8:
https://github.com/gdx-msx/FL

By Wolverine_nl

Paragon (1111)

Аватар пользователя Wolverine_nl

01-05-2020, 15:28

If these games are going to be on cartridges, then you are going to physically add a flashrom on the game cartridge? Or depend on people having something like a Megaflashrom ?

By norakomi

Paragon (1084)

Аватар пользователя norakomi

01-05-2020, 15:29

@Grauw,
I extracted the archive, and added it to my user share directory (Thanks!)
But then the next steps you describe are a bit too fast for me.
First I need to boot DOS2....
I did find a diskfile on my computer MDOS22DE.DSK
If I insert this in openmsx and start the emulator I end up in DOS2, but I don't think this is the right environment to flash a 2MB rom file to my inserted rom.....
So my guess is that I need to get that SD to work...
In my list of extensions in openmsx I see MegaflashROM SCC+, but I don't see MegaflashROM SCC+ SD.
I guess I need to enable some kind of harddisk functionality ?

By norakomi

Paragon (1084)

Аватар пользователя norakomi

17-09-2020, 22:14

also for playability, in the end it's nice if the ability to write to rom is possible in emulators without using a harddisk.

The same that was done back then for manbow2,
in bluemsx you can insert the .rom and choose the romtype: manbow2.
Then saving to flashrom is done directly to the rom...

Would that be possible as well for Deva?
So just insert the rom, choose rom type: flashrom 2MB (or something) and saving to rom is available ?

Страница 1/8
| 2 | 3 | 4 | 5 | 6