Gameboy Development Forum

Discussion about software development for the old-school Gameboys, ranging from the "Gray brick" to Gameboy Color
(Launched in 2008)

You are not logged in.

Ads

#1 2009-07-18 01:32:26

EricSchrodinger
New member
Registered: 2009-07-18
Posts: 3

Getting value from cart memory

Hey,

I'm designing my own cart for GB, and I was planning on using a 256k EEPROM which leaves A15 free. I want to use it in a chip enable fashion for a microcontroller but I can't figure out how to read/write bytes directly to a memory address. I went through all the GBDK help files and includes but it didn't help. I also looked in the opcodes but some aren't particularly descriptive so I couldn't find anything useful. I'm looking for something like poke and peek on GB-BASIC. Does anyone know how it is done?

Love From Eric

P.S.
I've been interested in GB dev for a while now, and I have no idea how I've never seen this website.

Offline

 

#2 2009-07-18 02:21:02

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 242

Re: Getting value from cart memory

This site has only been up for a year now or so, and it's pretty new compared to other sites.
I would advice you to switch to assembly language, especially if you only have 32 kB at your disposal. But GBDK is using a pretty standard C compiler, so you could use pointers for it.
For example:

Code:

UBYTE *baseaddr = 0;
baseaddr[0x555] = 0xAA;

UBYTE defines the data type you probably want to use, an usgined byte. baseaddr is a pointer defined to point to address 0. baseaddr[0x555] uses baseaddr as if it was an array (Oh, the wonders of C) and writes to the position you want to write to.
The more traditional schoolbook example of writing to a given address is:

Code:

*(UBYTE*)(0x555) = 0xAA

But I personally like the former, and probably lesser known syntax better. (Mainly because you define the type in only one place)

In asm it's quite more easy. (You can also combine C and asm in GBDK and call asm functions from C and vice versa)

Code:

_write_somewhere::
  ld    a,#0xAA    ; Load the accumulator with 0xAA
  ld    (0x555),a  ; Write the value to the address in qeustion
  ret              ; Return

Of course things get a bit more complicated if you want to pass an argument to the function, but not much.

And lastly, there's already a project called GB-PIC that does this already that may be interesting to you.

And feel free to drop by #gbdev on IRC. (EFNet)


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

#3 2009-07-18 03:14:14

EricSchrodinger
New member
Registered: 2009-07-18
Posts: 3

Re: Getting value from cart memory

Thanks for the code snippets. That's exactly what I needed.

I think I'll be OK with C without banking 'cause the main use will be printing/graphing debug information and control. The uC should take care of the rest.

The GB-PIC project is pretty cool, and similiar to what I want to do. It's just more fun to do things from scratch.
I'll probably use a uC with hardware USB though (kind of like BleepBloops I guess).

A little off topic but is an EEPROM with a 150ns read time fast enough?

Offline

 

#4 2009-07-18 07:16:44

nitro2k01
Administrator
Registered: 2008-02-22
Posts: 242

Re: Getting value from cart memory

Use Google. smile
Google has this neat calculator feature, so if you enter 1/(150 ns) you'll get 6.6... megahertz, which is enough for Game Boy, and GBC in normal speed, but not GBC in double speed mode. (The normal speed of either hardware is 4 MHz, while the double speed is 8 MHz)


Blog: Gameboy Genius
"A journey of a thousand miles begins with one small step"
Old Chinese Proverb

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson