Shannon Posted March 16, 2008 Share Posted March 16, 2008 I'm trying to convert some cheat/rumble code to work within the confines of the atari 8-bit peek/poke system. Some of the cheat code types plug 2 bytes (16-bit) into an address location. The codes are based around the gameshark which makes me wonder if the 16-bit codes are even intended for an 8-bit system. I figure they would be handy for consecutive bytes. What do you all think? Leave the 16-bit codes alone if they were not intended for use on 8-bit systems? Here is a sample of code that assigns the value at a given address to "value" and then calls a function to see if the controller is supposed to rumble. "i" is an integer, m_consoleMemory is a byte that points to the actual atari memory which consists of unsigned char (extern unsigned char memory[65536]; ) unsigned int value = *((unsigned short*)(&m_consoleMemory[ m_cheatCodes[i].adr - offset ])); checkRumbleMethod( i, value ); This code then stores "pokes" the 16-bit value into the address... I'm assuming on an 8-bit system the lower byte would be stored at memory address m_cheatCodes.adr-offset and the upper byte in m_cheatCodes.adr+1-offset. (sorry if I got the order backwards). *((unsigned short*)(&m_consoleMemory[ m_cheatCodes[i].adr - offset ])) = ( m_cheatCodes[i].val & 0xFFFF ); The a800 code provides a function for peek'ing/poke'ing values into an address, but it only does single bytes. The functions are unsigned char Atari800_GetByte(unsigned short addr); void Atari800_PutByte(unsigned short addr, unsigned char byte); Actually it's a little more complicated than that, but I wanna keep things simple for this discussion. But basically I wanna modify the code so it calls the PutByte and GetByte functions so that the hardware registers react they way they are supposed to. Anyways any comments, suggestions are welcomed. Thanks! Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted March 17, 2008 Share Posted March 17, 2008 Something like this should work: unsigned short GetShort(unsigned short addr) { return (unsigned short)(Atari800_GetByte(addr) | (Atari800_GetByte(++addr) << 8)); } And similar in reverse. The MSB/LSB order is a bit dubious, since 8-Bit code can arrange 16-Bit numbers either way. If it's pointers and not numbers, then the above should work hopefully (...not sure if the shifting works without a cast. The compiler will tell you ). Quote Link to comment Share on other sites More sharing options...
Shannon Posted March 17, 2008 Author Share Posted March 17, 2008 Thanks CyberG. I actually ended up doing something similar, but your version is shorter. I really didn't know if it would work until I compiled it. Still need to test all the codes but the one I tested so far seems to work ok. And yeah it took me a while to get the MSB/LSB order straight in my head. Since like you said it could go either way. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.