Kevin Vance - Useful DS tips!

Entries | Archive | Friends | Friends' Friends | User Info

10:25 pm

Useful DS tips!

Monday, June 26th, 2006
Previous Entry Share Next Entry

FINALLY, I've gotten something onto a hardware surface. Little things I've learned:
  • YOU CAN'T DO 8-BIT WRITES INTO VRAM. This is worth saying twice. YOU CAN'T DO 8-BIT WRITES INTO VRAM. Even though the hardware supports 8-bit surfaces, you can't address a single pixel. It works in the emulator, but not on the hardware. So make your bitmaps ahead of time, or just waste CPU and memory and use a 16-bit surface instead (that's what I did).
  • Setting up a hardware surface (aka background):
    • Choose a mode and enable some backgrounds. Different backgrounds are good for different things depending on what mode you selected. This page has a table of modes and backgrounds.
      videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
    • Choose a bank of VRAM. Then pick an address to map it to. The same page has a good list of VRAM banks. Different banks are different sizes, and can be used for different things.
    • Pick a surface type (resolution and depth). You also have to determine how many 16k chunks your VRAM address is from the base of 0x6000000. In our case, 0x20000 / 16k = 8. Set the control register for the appropriate background:
      BG2_CR = BG_BMP16_256x256 | BG_BMP_BASE(8);
    • You can get a pointer to your surface with the BG_BMP_RAM(x) macro, where x is that 16k offset again.
      u16 *surface = (u16*)BG_BMP_RAM(8);
  • Keep searching the GBADev forum for relevant function calls, register names, etc. until you find someone who already had your problem :P
Link )Reply )

[User Picture]From: spagnutty
2006-09-21 05:56 am (UTC)
Your post really helped me. Thanks!
(Reply) (Thread)
[User Picture]From: kvance
2006-09-21 06:19 am (UTC)
Glad to have helped. Are you working on anything interesting?
(Reply) (Parent) (Thread)
[User Picture]From: spagnutty
2006-09-21 06:26 am (UTC)
I'm a senior CS major at Elon University, and I'm working with the DS for my honors thesis. It's called "A Framework for the Implementation of Human Cognitive Assessments on a Handheld Device." My mentor and I building it for something that the psychology department can use. Half of the thesis will be making a drag and drop script editor that the psychologists can use to create tests. The scripted tests will then run on the DS or maybe a Nokia 770 as well. Most of what we've done so far is grunt work on the DS.

It's probably not a project that will benefit the overall homebrew community, but I'm enjoying it. It's been extremely challenging so far.
(Reply) (Parent) (Thread)
[User Picture]From: kvance
2006-09-21 06:47 am (UTC)
Neat. I smiled a little thinking about people doing serious work on this little gaming machine :)
(Reply) (Parent) (Thread)