gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Accessing CART with MB code

#14614 - slboytoy - Fri Jan 09, 2004 5:24 pm

Ok I need some help writing some code here. I have a program that resides in the IWRAM and i want to access the CART bus to light up some LEDs.

For example. I have a program that loads in the IWRAM and when you push either button A or button B, it will save a value '1' in two different memory locations. (ie. 0x8000001, 0x8000002). And when there is a '1' placed in those locations, corresponding LEDs will light up.

I'm pretty sure I know how to hook up SRAM correctly using a latch to latch the address when CS is selected.

But i have the program, and i hook up a logic analyzer to see if when I do press a button, if any activity happends on the CART bus. But i'm coming up with nothing. All the lines are high, and stay high.

#define CART_SRAM 0xe000000

*(u16*)(ADDR+0xFFFF) = i;

That is my sample part of my program. Can anyone help me out?

#14615 - gb_feedback - Fri Jan 09, 2004 6:18 pm

Quote:
u8* GamePakRam = (u8*) 0x0e000000;

GamePakRam[4] = (u8) m_lineNoTopOfScreen & 0xff;
GamePakRam[5] = (u8) (m_lineNoTopOfScreen >> 8) & 0xff;
GamePakRam[6] = (u8) (m_lineNoTopOfScreen >> 16) & 0xff;
GamePakRam[7] = (u8) (m_lineNoTopOfScreen >> 24) & 0xff;

5 lines from a working program. Notice that access to this address space is 8 bit wide. Otherwise hard to comment as it's not clear what ADDR+0xFFFF evaluates to
_________________
http://www.bookreader.co.uk/

#14676 - slboytoy - Sat Jan 10, 2004 10:39 pm

"m_lineNoTopOfScreen >> 8"

What are you doing by this action? Is m_lineNoTopOfScreen just a variable "int"?

Sorry for silly question.

#14677 - sajiimori - Sat Jan 10, 2004 11:00 pm

Apparently, it's saving a 32-bit value one byte at a time. Getting the low byte is as easy as doing a bitwise AND with 0xff. The others can be reached by shifting the value right by 8, 16, or 24 bits.

#14752 - gb_feedback - Mon Jan 12, 2004 10:37 am

Yes that's right. Sorry for the unnecessary part of the example, but I just don't like writing code on the fly without trying it first, so I took this example straight out of Bookreader (which probably explains the variable m_lineNoTopOfScreen to you). The example just emphasises the 8 bit width of the sram.
_________________
http://www.bookreader.co.uk/

#15098 - slboytoy - Sat Jan 17, 2004 2:32 am

Thanks a lot. I wasn't & FF with the data I was reading. It works fine now. Thanks for your help.