#65193 - jake2431 - Sat Dec 31, 2005 6:20 am
Hi, I am reading Programming the "Nintendo Game Boy Advance" and one of the challenges is to modify the following code to use memset and memcopy(from string.h).
I am having trouble seeing exactly how to do this. If you have the pdf version of this book it is challenge 2 on page 196. Could someone show me how this is done and maybe explain it a little bit?
Thanks
-Jake
Code: |
#define MULTIBOOT int __gba_multiboot;
MULTIBOOT //add support for rand function #include <stdlib.h> //declare the function prototype void DrawPixel3(int, int, unsigned short); void DrawBox3(int,int,int,int, unsigned short); //declare some defines for the video mode #define REG_DISPCNT *(unsigned long*)0x4000000 #define MODE_3 0x3 #define BG2_ENABLE 0x400 //changes the video mode #define SetMode(mode) REG_DISPCNT = (mode) //packs three values into a 15-bit color #define RGB(r,g,b) ((r) + (g<<5) + (b<<10)) //create a pointer to the video buffer unsigned short *videoBuffer = (unsigned short*)0x6000000; int main(void) { int x1; int y1; int x2; int y2; unsigned short color; SetMode(MODE_3 | BG2_ENABLE); while(1) { x1 = rand() % 240; y1 = rand() % 160; x2 = x1 + rand() % 60; y2 = y1 + rand() % 60; color = RGB(rand()%31, rand()%31, rand()%31); DrawBox3(x1,y1,x2,y2, color); } return 0; } void DrawPixel3(int x, int y, unsigned short color) { videoBuffer[y * 240 + x] = color; } void DrawBox3(int left, int top, int right, int bottom, unsigned short color) { int x; int y; for(y = top; y<bottom; y++) for(x = left; x < right; x++) DrawPixel3(x,y,color); } |
I am having trouble seeing exactly how to do this. If you have the pdf version of this book it is challenge 2 on page 196. Could someone show me how this is done and maybe explain it a little bit?
Thanks
-Jake