Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 10:40:51 GMT -5
So, Elusive posted some working save game code (provided below)
It only uses a single variable. How would I allocate ALL of that save RAM as either an array or a string? Especially since BEX integers are 16 bit? I heard save RAM is 8-bit.
option EXTERNALSRAM, &h200000, 8192, ODD
randomize
asm "move #$2700,sr" a = peek(&h200001) ' Read from SRAM at address &h200001 asm "move #$2000,sr"
locate 1,1: print "SRAM Data: "; a while 1 j = joypad() sleep 1 if j > 0 then randomize a = rnd(99) + 1 locate 3,1: print "New SRAM Data: "; a gosub SaveData end if wend
SaveData: asm "move #$2700,sr" poke &hA130F1, &h01 poke &h200001, a asm "move #$2000,sr" return
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 11:18:57 GMT -5
You can't, you need to copy the data from the SRAM to the RAM if you want to use it as a array* .. no idea why you'd want to do this though.
*Keep in mind that a array is a compiler / BEX concept, and doesn't exist on the hardware itself.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 11:35:39 GMT -5
You can't, you need to copy the data from the SRAM to the RAM if you want to use it as a array* .. no idea why you'd want to do this though. *Keep in mind that a array is a compiler / BEX concept, and doesn't exist on the hardware itself. Hmmn. So you can't somehow DIM the save RAM as an array. Drat. In that case you'd need to do some sort of for-next loop right? This code of course wouldn't work. I suspect the real code would look similar though. You could use this to store data for an RPG Maker or Dezaemon clone. ' Read save game RAM into array DIM saveram(63) as integer
for i=0 to 63 saveram(i) = peek(&h200001+i) next
' Write save game RAM into array DIM saveram(63) as integer
for i=0 to 63 poke(&h200001+i) = saveram(i) next
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 11:44:52 GMT -5
You could use this to store data for an RPG Maker or Dezaemon clone. The first? console RPG Maker ( RPG Tsukūru: Super Dante for SNES ) used 256Kb SRAM .. so, good luck with that.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 11:49:13 GMT -5
You can at least read and write a single variable to save RAM. Which means you can make some sort of loop to feed that info into an array or from an array. If anyone can contribute to the topic I'm all ears!
|
|
|
Post by Mairtrus on Aug 31, 2011 18:14:09 GMT -5
Actually, you CAN access to the SRAM as an array. I know because I have done it in real hardware (with some cache chips trough the EXP port, but the principle is the same...). Just define it like:
Dim SRAM(8191) as Integer at &h200000 The only problem is that most official carts had only one memory tied to the low byte of the bus, that's why everyone says the SRAM is 8-bit. However, I'm not sure if Tototek and similar carts has this limitation. Physically, you can add as many SRAM as you want, but most emulators define a maximum of 64kb, which makes it really difficult to debug correctly.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 18:42:43 GMT -5
Actually, you CAN access to the SRAM as an array. I know because I have done it in real hardware (with some cache chips trough the EXP port, but the principle is the same...). Just define it like: Dim SRAM(8191) as Integer at &h200000 The only problem is that most official carts had only one memory tied to the low byte of the bus, that's why everyone says the SRAM is 8-bit. However, I'm not sure if Tototek and similar carts has this limitation. Physically, you can add as many SRAM as you want, but most emulators define a maximum of 64kb, which makes it really difficult to debug correctly. Thanks Mairtrus! Hmmn.. The only business I know to sell reproduction Genesis carts salvages boards from commercial games. That means my game would have that low byte limitation. Would simply not using every other element in that SRAM(8191) array work? Or would BEX update the array stomping on even bits that aren't there and crash the hardware?
|
|
|
Post by Mairtrus on Aug 31, 2011 19:36:40 GMT -5
Don't worry, as far I know it SHOULD not crash. But when reading, probably you will get garbage in the upper byte. When writing, the content of the upper byte will be lost.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 21:59:39 GMT -5
IMPORTANT UPDATE: I'm currently blocked from sending moon messages. Apparently I pissed him off too many times with confusing questions. I didn't always listen to him properly either which seems to be one of his pet peeves. For this and other offenses I publicly apologize. Here is the message I would have sent him. Hopefully he will see it. Even though I have permanently wounded any kinship with him I will always appreciate the time he sacrificed and his patience.
Well, the SRAM Fusion emulates does work with the Mairtrus method. It does NOT work on a real Genesis via EverDrive.
Somehow I missed what moon was saying:
I tied together Elusives code that did a single variable and then added my own loops to both feed and then unload an array to SRAM.
On Fusion everything works great. On a real Genesis with an EverDrive every other element has a value of 76 usually. This is probably due to the SRAM layout Mairtrus describe commercial carts use.
Even if just half of those 8191 elements can be used - and they're only 8 bit values - I' m satisfied.
Thanks again for the help moon, Mairtrus and Elusive!
option EXTERNALSRAM, &h200000, 8192, ODD
Dim SRAM(8191) AS INTEGER ' Temporary copy of SRAM DIM x AS INTEGER ' Mainly used for loops DIM y AS INTEGER ' Element in SRAM array we want to track DIM j AS INTEGER ' Variable to store joypad readings GLOBAL temp AS INTEGER ' A throw away variable
' Set variables to default values x = 0 y = 8189 a = 0 j = 0 temp = 0
' Copy SRAM to array for x = 0 to 8191 sram(x) = READSRAM(x) next
' Print contents of SRAM at place Y to prove saving to SRAM locate 1,1: print "SRAM Data: "; READSRAM(y) while j.6 != 1 ' Press and HOLD A button for program to continue j = joypad() sleep 1 for x = 0 to 8191 ' Write values to temporary SRAM array sram(x) = x next wend
' Write back contents of array to real SRAM for x = 0 to 8191 WRITESRAM sram(x), x next
' Print out some of the SRAM contents for x = 0 to 191 PRINT READSRAM(sram(x), x) next
' Write 111 to Y element in real SRAM to prove on next boot things are saved.. WRITESRAM 111, y
' Write value to real SRAM based on Elusives code ' Note emulators will write to even elements fine while real genesis ' may be forcing 8 bit values. DECLARE SUB WRITESRAM(w_val AS INTEGER, w_place AS INTEGER) asm "move #$2700,sr" poke &hA130F1, &h01 poke &h200001+w_place, w_val asm "move #$2000,sr" END SUB
' Read value from real SRAM based on Elusives code ' Note emulators will read even elements fine while real genesis ' may be forcing 8 bit values. DECLARE FUNCTION READSRAM(r_place AS INTEGER) asm "move #$2700,sr" temp = peek(&h200001+r_place) asm "move #$2000,sr" RETURN temp END FUNCTION
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Aug 31, 2011 22:59:00 GMT -5
Glad you found a solution with something I posted lol. It's nice to know I'm useful at times haha
|
|
|
Post by jlf65 on Sept 1, 2011 0:27:00 GMT -5
The Tototek MD-Pro gives you four banks of 32KB of sram, accessed on odd bytes from 0x200000 to 0x20FFFF. If you want to know how to switch banks, I can dig that up (it's in a notebook somewhere). It's designed to be compatible with games that use sram.
The Neo Myth gives you anywhere from 4KB to 64KB of sram, with a total number of banks equal to how many times the bank divides into 256KB. The sram is accessed on odd bytes from 0x200000 to 0x21FFFF (for 64KB sram size). It's also designed to be compatible with sram games. The Neo Myth also has a mode for EEPROM which makes a 1Kbit EEPROM available at 0x200001 using the "normal" method of accessing EEPROMs used by most games that use an EEPROM.
The Everdrive-MD uses one bank of 32KB, or (if you have v3+ firmware) four banks of 8KB. It's accessed at 0x200000 at odd bytes like usual for sram.
So all the major flash carts have at least 32KB of sram at 0x200000 to 0x20FFFF accessed on odd bytes.
Remember that if your rom is over 2MB in size, you MUST disable ints and enable the sram before reading or writing, then disable the ram and disable ints after reading or writing. If the 32X is enabled, you MUST set the RV bit BEFORE enabling the sram to halt the SH2s. Clear the RV bit after you disable the sram.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 1, 2011 9:46:53 GMT -5
If you don't want to waste your RAM on garbage every other byte, you can use this approach.
dim foo(7) as integer ' Fill SRAM with numbers for i = 0 to 30 step 2 poke &h200000 + i, i next ' Copy SRAM to RAM dataptr& = varptr&(foo) for i = 0 to 30 step 2 write peek(&h200000 + i) next ' Print RAM p& = varptr&(foo) for i = 0 to 15 print peek(p& + i) next
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 1, 2011 16:33:47 GMT -5
If you don't want to waste your RAM on garbage every other byte, you can use this approach. dim foo(7) as integer ' Fill SRAM with numbers for i = 0 to 30 step 2 poke &h200000 + i, i next ' Copy SRAM to RAM dataptr& = varptr&(foo) for i = 0 to 30 step 2 write peek(&h200000 + i) next ' Print RAM p& = varptr&(foo) for i = 0 to 15 print peek(p& + i) next Wouldn't you need to set the SRAM info to EVEN instead of ODD in this case? Would this also work on the real hardware? I haven't tested out EVEN bytes for some reason, I forget why, but there was a reason why I stuck with ODD...
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 1, 2011 16:48:48 GMT -5
Wouldn't you need to set the SRAM info to EVEN instead of ODD in this case? Would this also work on the real hardware? Probably, haven't tried it without setting the proper OPTION. I haven't tested out EVEN bytes for some reason, I forget why, but there was a reason why I stuck with ODD... Because most cartridges are "wired" that way?
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Sept 1, 2011 19:43:48 GMT -5
Wouldn't you need to set the SRAM info to EVEN instead of ODD in this case? Would this also work on the real hardware? Probably, haven't tried it without setting the proper OPTION. I haven't tested out EVEN bytes for some reason, I forget why, but there was a reason why I stuck with ODD... Because most cartridges are "wired" that way? Ah, so using EVEN wouldn't work on real hardware, or are you saying that it would have to be wired that way? I know nothing about the cart constructions yet, so I'm kind of clueless at that. Would it be possible to wire it to use both odd and even?
|
|