UltiMem Flash Programming

Modding and Technical Issues

Moderator: Moderators

Post Reply
brain
Vic 20 Nerd
Posts: 538
Joined: Sun Jul 04, 2004 10:12 pm

UltiMem Flash Programming

Post by brain »

Programming the Ultimem (and the VICMIDI) is not too difficult, and you can do it in BASIC. That said, here is how you do it.

First, you need to find out what FLASH ROM chip you have. VIC-MIDI uses the AM29F040B, while the Ultimem cart uses a S29GL064N90TFI040. Here's where things get a little interesting.

Grab a copy of the two data sheets:

http://instrumentation.obs.carnegiescie ... 9F040B.pdf
https://www.spansion.com/Support/Datash ... L-N_01.pdf

On the 040B, look at the datasheet on page 14. Most, if not all flash ROMs use "magic values" to unlock their commands. In this case, you are interested in the Manufacturer ID and Device ID lines.

First thing you need to do is verify you have an Ultimem device. register 3 of the ultimem register set ($9ff3) should contain a $11 or $12. Make sure it contains one of those numbers

Assuming it does, I encourage you to continue on. Yes, for now, you could assume the VIC-MIDI has the 29040 and the Ultimem has the 29GL, but it seems someone should just write the correct code, and then everyone can use it.

We'll first try to see if the ROM is a 29040.

Map the ROM into BLK5 and zero out the bank register

$40 -> $9ff2
$00 -> $9ffe/$9fff

Now, try the magic sequence:

$aa -> $a555
$55 -> $a2aa
$90 -> $a555
read $a000 (should contain 01

if so, let's check device:

$aa -> $a555
$55 -> $a2aa
$90 -> $a555
read $a001 (should contain a4

if so, you know you have a 29f040b

If not, try for the 29gl. For this, look at page 52 of the 29gl datasheet.

$aa -> $aaaa
$55 -> $a555
$90 -> $aaaa
read $a000 (should contain 01)

$aa -> $aaaa
$55 -> $a555
$90 -> $aaaa
read $a002 (should contain 7e)

Now, if you have a match, I'd encourage you to read the next two pieces as well:

read $a01c
read $a01e

and store them off, as you might need them

So, by this point, you should know that you have:

present or not
VIC-MIDI or UltiMem
FLASH ROM MFR, DEVICE, and size.

Truly, I think this should be in an .INIT routine...

You'll now need to set some constants:

For the 29F040, commands are typically:

x555,aa
x2aa,55
x555,command

while the 29GL is:

xaaa,aa
x555,55
xaaa,command

the FLASH commands seem constant, but beware that may not always be the case.

To flash a byte, you'll first need to make sure the correct memory location is in the memory map. Say you wanted to flash byte $071234. You first need to segment the space into 8kB chunks and determine which bank you need. I say this is bank $38 (shift left 13 times). So, set $9ffe to $38 and $9fff to 0. Bank 38 of the ROM shows up in $a000. You now need to reference byte $1234 in that bank (or $b234). Assuming we want to store a $87 into that location, you would do:

lda #$a0
jsr send_command (from above)
lda $87
sta $b234

Now, we need to make sure the byte programmed. Read page 55 of the 29gl datasheet. It talks about DQ7 polling.

loop:
lda $b234 (can be $a000, just needs to be in the bank)
eor $b234
and #$80
bne loop
done: // should really put some limit on this polling.

One should also check bit 5, which will output a 1 if a timer limit is exceeded. Table 10.5 on page 60 provides all of the bits you can check.

With that, you are done. increment your pointers and program a new byte. Remember, flash can only be programmed from 1->0. GOing back to a 1 means erasing the sector.

To erase a FLASH sector, realize that sectors are not equivalent to banks. An Ultimem bank is 8kB, but a sector can be 8KB or 64kB. The 29040 has 8 64kB sectors, while the 29gl has 8 sectors of 8kB and the rest are 64kB.

The erase command is performed like the others, but you must have the sector you wish to erase (or some part of it) visible in the VIC-20 memory map. I'd recommend putting the lowest 8kB of the sector into the memory map, just to make it easier.

You can use the 1->0 thing to your advantage, marking off used banks in a BAM table by seting the bit of interest to 0 when it is used. Or, update a pointer to be deleted or not used by setting it to 0.

Jim
brain
Vic 20 Nerd
Posts: 538
Joined: Sun Jul 04, 2004 10:12 pm

Re: UltiMem Flash Programming

Post by brain »

I would encourage users to adopt the Easy API construct for a library:

http://skoe.de/easyflash/files/devdocs/ ... rogRef.pdf

UAPI is my choice for the Identifier

Jim
User avatar
pixel
Vic 20 Scientist
Posts: 1356
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: UltiMem Flash Programming

Post by pixel »

And don't fall into the trap of the STA instruction's dummy reads when using indexed addressing! Instead use

Code: Select all

	ldx #0
	sta (ptr,x)
I like to think this might save some sleepless nights. :D
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
majikeyric
Vic 20 Afficionado
Posts: 351
Joined: Fri Oct 24, 2014 2:08 pm
Website: http://majikeyric.free.fr
Location: France

Re: UltiMem Flash Programming

Post by majikeyric »

I'm trying to figure out how to flash my custom boot program...
User avatar
pixel
Vic 20 Scientist
Posts: 1356
Joined: Fri Feb 28, 2014 3:56 am
Website: http://hugbox.org/
Location: Berlin, Germany
Occupation: Pan–galactic shaman

Re: UltiMem Flash Programming

Post by pixel »

You need to make an 8Mb image whose first 8kB (which will be mapped to $a000) start with an autostart signature followed by your program. See here http://sleepingelephant.com/ipw-web/bul ... &start=135 to make one with the Ultitools.
AFAIK your image always has too be filled up to be exactly 8Mb in size. Easily testable in VICE.

The autostart signature is:

Code: Select all

	.word cold_start
	.word warm_start ; Just make this the same as cold_start
	.byte "A0", $c3, $c2, $cd
A man without talent or ambition is most easily pleased. Others set his path and he is content.
https://github.com/SvenMichaelKlose
User avatar
majikeyric
Vic 20 Afficionado
Posts: 351
Joined: Fri Oct 24, 2014 2:08 pm
Website: http://majikeyric.free.fr
Location: France

Re: UltiMem Flash Programming

Post by majikeyric »

Thanks for the info pixel I gonna give it a try! :)
Post Reply