#117361 - jonathanc - Sun Feb 04, 2007 5:06 am
Hi there, letme first introduce a little about myself. Recently started a course in computing tech and I have to do a module on GBA programming. Very hectic and demanding module >< Well, I have really tried looking and asking around (some people are really selfish in sharing knowledge as this is a competitive course) but I am afraid I am getting no where :( So I turn to this forums for some help.
Ok, to the point then. I am supposed to write a basic macro or function for the devadvkit environment that takes a value between 0-31 and convert it into 16 bit bgr format (mode 3). I am supposed to use this macro to draw a yellow pixel in the middle of the screen and use the D pads to move it around the boundaries of the screen and also A and B buttons to change the colors.
I have read through millions of guides and tutorials but I still fail at producing a working example. I am wondering if anyone could give me some help here. Thanks and much appreciated!
I have found a method of using this code:
#include "toolbox.h"
int main()
{
REG_DISPCNT= DCNT_MODE3 | DCNT_BG2_ON;
m3_plot( 120, 80, RGB15(31, 31, 0) ); // or CLR_RED
while(1);
return 0;
}
which of course needs this header file:
// toolbox.h:
#ifndef TOOLBOX_H
#define TOOLBOX_H
// === (from types.h) ================================================
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef u16 COLOR;
#define INLINE static inline
// === (from regs.h) ==================================================
#define MEM_IO 0x04000000
#define MEM_VRAM 0x06000000
#define REG_DISPCNT *((volatile u32*)(MEM_IO+0x0000))
// === (from vid.h) ===================================================
#define VID_WIDTH 240
#define VID_HEIGHT 160
#define vid_mem ((u16*)MEM_VRAM)
// --- some REG_DISPCNT #defines ---
#define _DCNT_MODE0 0x0000
#define DCNT_MODE1 0x0001
#define DCNT_MODE2 0x0002
#define DCNT_MODE3 0x0003
#define DCNT_MODE4 0x0004
#define DCNT_MODE5 0x0005
// layers
#define DCNT_BG0_ON 0x0100
#define DCNT_BG1_ON 0x0200
#define DCNT_BG2_ON 0x0400
#define DCNT_BG3_ON 0x0800
#define DCNT_OBJ_ON 0x1000
INLINE void m3_plot(int x, int y, COLOR clr)
{ vid_mem[y*VID_WIDTH+x]= clr; }
// === (from color.h) =================================================
#define CLR_BLACK 0x0000
#define CLR_RED 0x001F
#define CLR_LIME 0x03E0
#define CLR_YELLOW 0x03FF
#define CLR_BLUE 0x7C00
#define CLR_MAG 0x7C1F
#define CLR_CYAN 0x7FE0
#define CLR_WHITE 0x7FFF
INLINE COLOR RGB15(u32 rr, u32 gg, u32 bb)
{ return (rr&31) | ((gg&31)<<5) | ((bb&31)<<10); }
#endif // TOOLBOX_H
However, I am not sure if I am on the right track as I think I am required to write something in this format:
u16 BGR(u16 b, u16 g, u16 r);
Please advice as I am quite confused.
Ok, to the point then. I am supposed to write a basic macro or function for the devadvkit environment that takes a value between 0-31 and convert it into 16 bit bgr format (mode 3). I am supposed to use this macro to draw a yellow pixel in the middle of the screen and use the D pads to move it around the boundaries of the screen and also A and B buttons to change the colors.
I have read through millions of guides and tutorials but I still fail at producing a working example. I am wondering if anyone could give me some help here. Thanks and much appreciated!
I have found a method of using this code:
#include "toolbox.h"
int main()
{
REG_DISPCNT= DCNT_MODE3 | DCNT_BG2_ON;
m3_plot( 120, 80, RGB15(31, 31, 0) ); // or CLR_RED
while(1);
return 0;
}
which of course needs this header file:
// toolbox.h:
#ifndef TOOLBOX_H
#define TOOLBOX_H
// === (from types.h) ================================================
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef u16 COLOR;
#define INLINE static inline
// === (from regs.h) ==================================================
#define MEM_IO 0x04000000
#define MEM_VRAM 0x06000000
#define REG_DISPCNT *((volatile u32*)(MEM_IO+0x0000))
// === (from vid.h) ===================================================
#define VID_WIDTH 240
#define VID_HEIGHT 160
#define vid_mem ((u16*)MEM_VRAM)
// --- some REG_DISPCNT #defines ---
#define _DCNT_MODE0 0x0000
#define DCNT_MODE1 0x0001
#define DCNT_MODE2 0x0002
#define DCNT_MODE3 0x0003
#define DCNT_MODE4 0x0004
#define DCNT_MODE5 0x0005
// layers
#define DCNT_BG0_ON 0x0100
#define DCNT_BG1_ON 0x0200
#define DCNT_BG2_ON 0x0400
#define DCNT_BG3_ON 0x0800
#define DCNT_OBJ_ON 0x1000
INLINE void m3_plot(int x, int y, COLOR clr)
{ vid_mem[y*VID_WIDTH+x]= clr; }
// === (from color.h) =================================================
#define CLR_BLACK 0x0000
#define CLR_RED 0x001F
#define CLR_LIME 0x03E0
#define CLR_YELLOW 0x03FF
#define CLR_BLUE 0x7C00
#define CLR_MAG 0x7C1F
#define CLR_CYAN 0x7FE0
#define CLR_WHITE 0x7FFF
INLINE COLOR RGB15(u32 rr, u32 gg, u32 bb)
{ return (rr&31) | ((gg&31)<<5) | ((bb&31)<<10); }
#endif // TOOLBOX_H
However, I am not sure if I am on the right track as I think I am required to write something in this format:
u16 BGR(u16 b, u16 g, u16 r);
Please advice as I am quite confused.