Skip to content

Instantly share code, notes, and snippets.

@reidrac
Last active November 5, 2018 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidrac/5abf8a036a6da2d14f9064c8b54e621e to your computer and use it in GitHub Desktop.
Save reidrac/5abf8a036a6da2d14f9064c8b54e621e to your computer and use it in GitHub Desktop.
Using ASCII 8K mapper with 2KB of SRAM

This is for OpenMSX

OpenMSX won't detect this type of cart automatically, so you need to say the cart type with:

openmsx -carta game.rom -romtype ASCII8SRAM2

OpenMSX will create a file game.rom.SRAM to store 2KB of persistent memory (in Linux this is in $HOME/.openMSX/persistent/roms/game.rom).

Init and detect

	  ; set banks for the ASCII 8K mapper
	  ; (this doesn't have effect if there's no mapper)
	  xor a
	  ld hl, #0x6000
	  ld (hl), a
	  inc a
	  ld h, #0x68
	  ld (hl), a
	  inc a
	  ld h, #0x70
	  ld (hl), a
	  inc a
	  ld h, #0x78
	  ld (hl), a

Because is a 8K block mapper, this maps the ROM from 4000h to bfffh; as explained in: http://bifi.msxnet.org/msxnet/tech/megaroms#ascii8sram

Then you can setup the memory normally with ports or the BIOS, thats up to you.

To detect if there's SRAM:

	  ; test for SRAM

	  ; 1. enable SRAM (for write because is on last bank)
	  ld a, #255
	  ld (#0x7800), a

	  ; 2. check if writing works
	  ld a, #'*'
	  ld (0xa7ff), a
	  ld a, (0xa7ff)
	  cp #'*'
	  jr z, has_sram
	  xor a
  has_sram:
	  ld (_has_sram), a

	  ; restore mapping
	  ld a, #3
	  ld (0x7800), a

If SRAM is not available, _has_sram will be zero. Note: the SRAM detection writes in the last byte of the SRAM, take that into account when saving your game state!

Any issues, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment