This thread is for a custom build of ZSNES which I released for hackers dreams. The basic premise is that the emulator uses shared memory so that the game's SRAM is visible to other processes on your computer. What that means is that you can create an .exe that reads that SRAM and does whatever you want to do with that information. This could include but is not limited to
1. Playing music files of arbitrarily high quality
2. Drawing graphics on top of the ZSNES window of arbitrarily high quality
3. etc etc etc
The purpose of this thread is to separately offer this small emulator modification as well as a general purpose music player that you can use for your own hacks. I will give a basic tutorial on how to set this up and how you can use the feature more generally.
Building addons for aZSNES
This assumes you know how to write a cpp program. Use the functions
OpenFileMapping and
MapViewOfFile to access the shared memory. Once you have acces to the shared memory, infinite loop the program and respond to whatever addresses you need. You can use CopyMemory to grab the address you need to look at.
Code HANDLE hMapFile = NULL;
LPCTSTR fast_sram = NULL;
hMapFile = NULL;
hMapFile = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
"ZSNES"); // name of mapping object
char sram_value = 0;
if (hMapFile != NULL)
{
fast_sram = (LPTSTR)MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0x0000,
0x0000,
0);
CopyMemory((PVOID)(((char*)fast_sram)+0x01C089), &sram_value, sizeof(TCHAR)); // example: using an address to play audio
}
while(true)
{
//do stuff based on address
//read address again
}
Using the prebuilt music player:
For the music player, all you have to do is write to $41C089*. The exe will lookup the value in this address and if it sees a change, play the a file named "#value_of_41C089.wav". It will not play on #$00. To mute just create an empty wav file and play that.
Here is a little routine that will play MSU-1 if the emulator/console supports that, else fallback on ZSNES and play the music through this application:
CodePlayMusic: ; A = music file to play, with $00 being mute
PHA
LDA $002002
CMP #$53
BNE ++
PLA
CMP $2004
BEQ +
STA $2004
stz $2005 ; track 0
lda #$ff
sta $2006 ; full volume
-
bit $2000
bvs -
lda #$03
sta $2007
BRA +
++
PLA ;ZSNES audio
BNE ++
LDA #$08 ;I use 7 wav files and 8.wav as mute. you can use a different number if you want
++
STA $41C089
+
RTS
*this assumes you are using SA-1. if you are not using SA-1 use a different address and read that in your exe instead.
Preliminary FAQ:
ZSNES doesn't support SA-1
this version does because it is based on FuSoYa's zsnes build. it will save sram on SA-1.
ZSNES has input lag
see previous response. latency is superior to snes9x.
ZSNES can run arbitrary code due to a security bug
see previous response. Also, you are running exes to make this functionlity work, so its the same thing in a deliberate context. Difference is you are choosing to click the exe, same as you would any other program you download on the internet.
I don't want to use ZSNES because I have a preconceived notion in my head about the quality.
thats more of a comment.
Future Projects
It should be emphasized that you can do whatever arbitrary computations you want based on the SRAM data, so this is more than just a music player. The next thing I would like to try doing is drawing a transparent window ontop of ZSNES with opengl, and mirroring $146x in SRAM during an autoscroller or something in order to patch in a super-high resolution background. I'm curious what other ideas people can imagine doing with this and my hope is that people will play around and make more than just music players using this concept.
I'm not a particularly good programmer and this isn't really a huge programming feat. 99.999% of it is just built on top of existing code with a tiny change to make the SRAM viewable. I just think this is cool tech and would like to encourage other people to do it. Its really easy to get this working and it allows for things that would be impossible in any other context. Please enjoy
Download Link