Previous Thread
Next Thread
Print Thread
#94373 - 05/20/14 12:54 AM Load default flash/nvram image only on first run?  
Joined: May 2014
Posts: 7
Jonimus Offline
Member
Jonimus  Offline
Member

Joined: May 2014
Posts: 7
For my work mentioned in http://forums.bannister.org/ubbthreads.php?ubb=showflat&Number=94327#Post94327 I need to work out saving and loading the flash device contents for the calculators which use a flash chip.

On first run the contents should be initialized from a ROM dump from a real calculator which contains the boot code and OS and possibly the other variables on the calc which are stored in flash.

On subsequent runs the calculator should use the saved contents from the last use of that rom.

Right now the rom properly gets saved as an nvram file and loaded upon startup, but it is then overridden by the rom file causing any user variables that had been "archived" or moved to flash during the last use are lost.

How do I either:
A) write the flash contents back out to the original rom file,
or
B) make sure the flash contents from last use take precedence over the default state in the rom?


Last edited by Jonimus; 05/20/14 12:54 AM.
#94374 - 05/20/14 01:08 AM Re: Load default flash/nvram image only on first run? [Re: Jonimus]  
Joined: Jan 2012
Posts: 678
crazyc Offline
Senior Member
crazyc  Offline
Senior Member

Joined: Jan 2012
Posts: 678
I think the correct way to do that would be to use MCFG_NVRAM_ADD_CUSTOM_DRIVER which can fill the nvram with the default state when it is first initialized.

#94375 - 05/20/14 01:16 AM Re: Load default flash/nvram image only on first run? [Re: crazyc]  
Joined: May 2014
Posts: 7
Jonimus Offline
Member
Jonimus  Offline
Member

Joined: May 2014
Posts: 7
Originally Posted By crazyc
I think the correct way to do that would be to use MCFG_NVRAM_ADD_CUSTOM_DRIVER which can fill the nvram with the default state when it is first initialized.
Do you know of an example device/machine that does this so I can see an example?

#94377 - 05/20/14 04:45 AM Re: Load default flash/nvram image only on first run? [Re: Jonimus]  
Joined: Jan 2006
Posts: 3,685
etabeta78 Offline
Very Senior Member
etabeta78  Offline
Very Senior Member

Joined: Jan 2006
Posts: 3,685
Trondheim, Norway
short answer: just grep the source for MCFG_NVRAM_ADD_CUSTOM_DRIVER wink

more complete answer: nvram devices do exactly what you want, except that they often expect a default NVRAM filled with a simpler pattern (1filled, 0filled, etc.)

an example of a driver/device that initialize manually the nvram at first load via a re-definition of nvram_init and MCFG_NVRAM_ADD_CUSTOM_DRIVER is the Saturn (see src/mess/drivers/saturn.c ). In this way you can handle manually the content which is loaded at first launch (for instance saturn needs the first 64bytes to have a specific pattern)

if you want to add the default nvram in the romset, instead, then you don't need to use that and you can do as mjkjidai does in MAME (see src/mame/drivers/mjkjidai.c ): you add a "nvram" rom region and use a MCFG_NVRAM_ADD_NO_FILL("nvram") in the machine config. when no custom nvram_init is provided, the core searches for a region with the same tag as the nvram ("nvram" in this case) to load from...

#94378 - 05/20/14 04:47 AM Re: Load default flash/nvram image only on first run? [Re: Jonimus]  
Joined: Mar 2001
Posts: 15,733
R. Belmont Offline
R. Belmont  Offline

Very Senior Member

Joined: Mar 2001
Posts: 15,733
USA
I'm not sure NVRAM_ADD_CUSTOM_DRIVER is the right pattern for flash ROMs though. What he wants to do is a very basic use case for those chips, so we should support it in a more intuitive way.

#94381 - 05/20/14 11:20 AM Re: Load default flash/nvram image only on first run? [Re: Jonimus]  
Joined: Mar 2006
Posts: 1,000
Lord Nightmare Offline
Very Senior Member
Lord Nightmare  Offline
Very Senior Member

Joined: Mar 2006
Posts: 1,000
PA, USA
I think if you load the intelfsh 'romspace' with ROM_LOAD with a default image, that default image should be written to the 'nvram file' on the first boot and then be modifiable and modifications will be saved to said 'nvram file'. (or so I understand, I could be wrong about this)
This may be somewhat complicated on the ti-83+ since it has both 32k(64k?) of 'real' nvram which is battery backed, AND the intelfsh flash chip of 512k, but it may 'just work' and be a non-issue.

LN


"When life gives you zombies... *CHA-CHIK!* ...you make zombie-ade!"
#94385 - 05/20/14 03:50 PM Re: Load default flash/nvram image only on first run? [Re: Lord Nightmare]  
Joined: Nov 2003
Posts: 803
smf Offline
Senior Member
smf  Offline
Senior Member

Joined: Nov 2003
Posts: 803
Originally Posted By Lord Nightmare
This may be somewhat complicated on the ti-83+ since it has both 32k(64k?) of 'real' nvram which is battery backed, AND the intelfsh flash chip of 512k, but it may 'just work' and be a non-issue.


If it's battery backed up static ram then you'll to register the ram to be saved in the driver init (which is horrible but it's the pattern). look in src/mess/drivers/nc.c for nvram

I believe you can pre-fill the nvram as well by specifying AM_REGION() in the memory map.

The saved files will override the files from the zip after the first run. I assume you've been memcpy'ing them in at some and think it's such an issue for the saved files to override the rom, but just don't do that.


If you need an intel flash example then look in src/mess/drivers/ksys573.c

Last edited by smf; 05/20/14 04:01 PM.
#94386 - 05/20/14 07:14 PM Re: Load default flash/nvram image only on first run? [Re: Jonimus]  
Joined: Dec 2005
Posts: 330
AWJ Offline
Senior Member
AWJ  Offline
Senior Member

Joined: Dec 2005
Posts: 330
Canada
You only have to "register the ram" manually if you allocated it manually (typically because it's bankswitched, or 8-bit RAM on a 16-bit bus, etc.) If the RAM is an AM_SHARE in an address map then the nvram device will find it automatically.

#94391 - 05/21/14 03:22 AM Re: Load default flash/nvram image only on first run? [Re: Jonimus]  
Joined: May 2014
Posts: 7
Jonimus Offline
Member
Jonimus  Offline
Member

Joined: May 2014
Posts: 7
Thanks to smf's suggestion on IRC I switched to using the bankdev device for my memory mapping and now things are working as expected for the flash side of things.

But now I have a new issue, something is causing the calculator's OS to think nvram is not properly saved where it was not giving me issues before this change.

I have the relevant code below but a fairly recent version of the full diff can be found at http://jonimoose.net/calcstuff/ti83pse.diff

EDIT: figured it out, I needed to remove the following code from the machine start member
Code:
 	m_ti8x_ram = auto_alloc_array(machine(), UINT8, 128*1024);
	memset(m_ti8x_ram, 0, sizeof(UINT8)*128*1024);

	machine().device<nvram_device>("nvram")->set_base(m_ti8x_ram, sizeof(UINT8)*128*1024);



Bank switching code
Code:
//needs to be updated with RO range for flash right now it is all RW
void ti85_state::update_ti83p_memory ()
{
	address_space &space = m_maincpu->space(AS_PROGRAM);
	
	m_membank1->set_bank(0); //Always flash page 0, well allmost
	
	if (m_ti83p_port4 & 1)
	{
		
		m_membank2->set_bank(m_ti8x_memory_page_1 & 0xfe);
		
		m_membank3->set_bank(m_ti8x_memory_page_1); 

		m_membank4->set_bank(m_ti8x_memory_page_2);

		
	}
	else
	{
		m_membank2->set_bank(m_ti8x_memory_page_1);

		m_membank3->set_bank(m_ti8x_memory_page_2);

		m_membank4->set_bank(0x40); //Always first ram page

	}
}

//needs to be updated to have a RO range for flash
void ti85_state::update_ti83pse_memory ()
{
	address_space &space = m_maincpu->space(AS_PROGRAM);
	
	m_membank1->set_bank(m_ti8x_memory_page_0);
	
	if (m_ti83p_port4 & 1)
	{
		
		m_membank2->set_bank(m_ti8x_memory_page_1 & 0xfe);
		
		m_membank3->set_bank(m_ti8x_memory_page_1 | 1);

		m_membank4->set_bank(m_ti8x_memory_page_2);

		
	}
	else
	{
		m_membank2->set_bank(m_ti8x_memory_page_1);

		m_membank3->set_bank(m_ti8x_memory_page_2);

		m_membank4->set_bank(m_ti8x_memory_page_3 + 0x80);

	}
}


Address maps
Code:
//needs to be updated to have a RO range for flash
static ADDRESS_MAP_START( ti83pse_banked_mem , AS_PROGRAM, 8, ti85_state )
	AM_RANGE(0x0000, 0x1fffff) AM_DEVREADWRITE("flash", intelfsh8_device, read, write)
	AM_RANGE(0x200000, 0x21BFFF) AM_RAM AM_SHARE("nvram")
ADDRESS_MAP_END

//needs to be updated to have a RO range for flash
static ADDRESS_MAP_START( ti83p_banked_mem , AS_PROGRAM, 8, ti85_state )
	AM_RANGE(0x00000, 0x7ffff) AM_DEVREADWRITE("flash", intelfsh8_device, read, write)
	AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_SHARE("nvram")
ADDRESS_MAP_END

static ADDRESS_MAP_START( ti83p_mem , AS_PROGRAM, 8, ti85_state )
	AM_RANGE(0x0000, 0x3fff) AM_DEVREADWRITE("membank1", address_map_bank_device, read8, write8)
	AM_RANGE(0x4000, 0x7fff) AM_DEVREADWRITE("membank2", address_map_bank_device, read8, write8)
	AM_RANGE(0x8000, 0xbfff) AM_DEVREADWRITE("membank3", address_map_bank_device, read8, write8)
	AM_RANGE(0xc000, 0xffff) AM_DEVREADWRITE("membank4", address_map_bank_device, read8, write8)
ADDRESS_MAP_END


Machine Config snippits
Code:
MCFG_DEVICE_ADD("membank1", ADDRESS_MAP_BANK, 0)
	MCFG_DEVICE_PROGRAM_MAP(ti83p_banked_mem)
	MCFG_ADDRESS_MAP_BANK_ENDIANNESS(ENDIANNESS_LITTLE)
	MCFG_ADDRESS_MAP_BANK_DATABUS_WIDTH(8)
	MCFG_ADDRESS_MAP_BANK_STRIDE(0x4000)

	MCFG_DEVICE_ADD("membank2", ADDRESS_MAP_BANK, 0)
	MCFG_DEVICE_PROGRAM_MAP(ti83p_banked_mem)
	MCFG_ADDRESS_MAP_BANK_ENDIANNESS(ENDIANNESS_LITTLE)
	MCFG_ADDRESS_MAP_BANK_DATABUS_WIDTH(8)
	MCFG_ADDRESS_MAP_BANK_STRIDE(0x4000)

	MCFG_DEVICE_ADD("membank3", ADDRESS_MAP_BANK, 0)
	MCFG_DEVICE_PROGRAM_MAP(ti83p_banked_mem)
	MCFG_ADDRESS_MAP_BANK_ENDIANNESS(ENDIANNESS_LITTLE)
	MCFG_ADDRESS_MAP_BANK_DATABUS_WIDTH(8)
	MCFG_ADDRESS_MAP_BANK_STRIDE(0x4000)

	MCFG_DEVICE_ADD("membank4", ADDRESS_MAP_BANK, 0)
	MCFG_DEVICE_PROGRAM_MAP(ti83p_banked_mem)
	MCFG_ADDRESS_MAP_BANK_ENDIANNESS(ENDIANNESS_LITTLE)
	MCFG_ADDRESS_MAP_BANK_DATABUS_WIDTH(8)
	MCFG_ADDRESS_MAP_BANK_STRIDE(0x4000)

--------snip------------

        MCFG_AMD_29F400T_ADD("flash")
MACHINE_CONFIG_END


static MACHINE_CONFIG_DERIVED( ti83pse, ti83p )
	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_CLOCK( 15000000) 
	MCFG_CPU_IO_MAP(ti83pse_io)
	
	MCFG_DEVICE_MODIFY("membank1")
	MCFG_DEVICE_PROGRAM_MAP(ti83pse_banked_mem)

	MCFG_DEVICE_MODIFY("membank2")
	MCFG_DEVICE_PROGRAM_MAP(ti83pse_banked_mem)
	
	MCFG_DEVICE_MODIFY("membank3")
	MCFG_DEVICE_PROGRAM_MAP(ti83pse_banked_mem)
	
	MCFG_DEVICE_MODIFY("membank4")
	MCFG_DEVICE_PROGRAM_MAP(ti83pse_banked_mem)

	MCFG_MACHINE_START_OVERRIDE(ti85_state, ti83pse )
	MCFG_MACHINE_RESET_OVERRIDE(ti85_state, ti83pse )
	MCFG_DEVICE_REPLACE("flash", FUJITSU_29F160T, 0)

	//MCFG_TI83PSERIAL_ADD( "tiserial" )
MACHINE_CONFIG_END


and finally the ROM loading code
Code:
ROM_START (ti83p)
	ROM_REGION (0x80000, "flash",0)
	ROM_DEFAULT_BIOS("v116")
	ROM_SYSTEM_BIOS( 0, "v103", "V 1.03" )
	ROMX_LOAD( "ti83pv103.bin", 0x00000, 0x80000, CRC(da466be0) SHA1(37eaeeb9fb5c18fb494e322b75070e80cc4d858e), ROM_BIOS(1) )
	ROM_SYSTEM_BIOS( 1, "v103m", "V 1.03 [m]" )
	ROMX_LOAD( "ti83pv103m.bin", 0x00000, 0x80000, CRC(281c9375) SHA1(80d698fed42976015a3e53fd59ebe7f49699b27e), ROM_BIOS(2))
	ROM_SYSTEM_BIOS( 2, "v103m2", "V 1.03 [m2]" )
	ROMX_LOAD( "ti83pv103m2.bin", 0x00000, 0x80000, CRC(690d9d30) SHA1(d215d3880e06c2ae31ec24b21d542d5bb2f3935b), ROM_BIOS(3))
	ROM_SYSTEM_BIOS( 3, "v110", "V 1.10" )
	ROMX_LOAD( "ti83pv110.bin", 0x00000, 0x80000, CRC(62683990) SHA1(F86CDEFE4ED5EF9965CD9EB667CB859E2CB10E19), ROM_BIOS(4) )
	ROM_SYSTEM_BIOS( 4, "v112", "V 1.12" )
	ROMX_LOAD( "ti83pv112.bin", 0x00000, 0x80000, CRC(ddca5026) SHA1(6615df5554076b6b81bd128bf847d2ff046e556b), ROM_BIOS(5) )
	ROM_SYSTEM_BIOS( 5, "v110-2", "V 1.10-2" )
	ROMX_LOAD( "ti83pv110-2.bin", 0x00000, 0x80000, CRC(504b9879) SHA1(8841d501870e8fc7173642d8a438205a040640fc), ROM_BIOS(6) )
	ROM_SYSTEM_BIOS( 6, "v112-2", "V 1.12-2" )
	ROMX_LOAD( "ti83pv112-2.bin", 0x00000, 0x80000, CRC(2126de12) SHA1(cbedc3a8cf8335eebf2b279d58720d8e7f86c569), ROM_BIOS(7) )
	ROM_SYSTEM_BIOS( 7, "v113", "V 1.13" )
	ROMX_LOAD( "ti83pv113.bin", 0x00000, 0x80000, CRC(30a243aa) SHA1(9b79e994ea1ce7af05b68f8ecee8b1b1fc3f0810), ROM_BIOS(8) )
	ROM_SYSTEM_BIOS( 8, "v114", "V 1.14" )
	ROMX_LOAD( "ti83pv114.bin", 0x00000, 0x80000, CRC(b32059c7) SHA1(46c66ba0421c03fc42f5afb06c7d3af812786140), ROM_BIOS(9) )
	ROM_SYSTEM_BIOS( 9, "v115", "V 1.15" )
	ROMX_LOAD( "ti83pv115.bin", 0x00000, 0x80000, CRC(9288029b) SHA1(8bd05fd47cab4028f275d1cc5383fd4f0e193474), ROM_BIOS(10) )
	ROM_SYSTEM_BIOS( 10, "v116", "V 1.16" )
	ROMX_LOAD( "ti83pv116.bin", 0x00000, 0x80000, CRC(0b7cd006) SHA1(290bc81159ea061d8ccb56a6f63e042f150afb32), ROM_BIOS(11) )
ROM_END

ROM_START (ti83pse)
	ROM_REGION (0x200000, "flash", 0)
	ROM_DEFAULT_BIOS("v116")
	ROM_SYSTEM_BIOS( 0, "v116", "V 1.16" )
	ROMX_LOAD( "ti83psev116.bin", 0x00000, 0x200000, CRC(d2570863) SHA1(d4214b3c0ebb26e10fe95294ac72a90d2ba99537), ROM_BIOS(1) )
ROM_END

etc


Last edited by Jonimus; 05/21/14 03:51 AM. Reason: Figured it out!

Who's Online Now
0 registered members (), 17 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Shout Box
Forum Statistics
Forums9
Topics8,425
Posts109,185
Members4,759
Most Online225
May 26th, 2014
Powered by UBB.threads™ PHP Forum Software 7.6.0
Page Time: 0.025s Queries: 14 (0.007s) Memory: 5.0050 MB (Peak: 5.2204 MB) Zlib enabled. Server Time: 2017-10-17 05:59:52 UTC