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.

C/C++ > Pern Projects mode7 tutorial on DAY 5

#10362 - Mr. GBA - Wed Sep 03, 2003 2:00 pm

Has anyone had any success in getting this to work? I mean, the "test.bin" inlcuded works but whenever I recompile the code the gba file does not appear in 3d.
Could someone please tell me what to add to the file(below) to get the mode7 effect to work: thanks

/********************************************************
*
*
* by devoto
*
*
********************************************************/
#include<math.h> //sign and cos stuff
#include"gba.h"
#include"screenmode.h"
#include"keypad.h"
#include"sprite.h"
#include"backgrounds.h"
#include "dma.h"
#include "interupts.h"

#include "sunset.h"

FIXED SIN[360]; //my LUTs for sign and cosign
FIXED COS[360];
FIXED div[160]; //a LUT table for divides

//global variables as it is kind of hard to pass variables to an interupt
int angle = 0; //rotation angle
FIXED x = 0; //x and y background scroll
FIXED y = 0;
int height = (32<<8); //height of the player

void GetInput(void);

///main entry point from the boot.asm startup file
int main(void)
{

u16 loop,loopx,loopy;

Bg bg2;

bg2.charBaseBlock = 0;
bg2.colorMode = BG_COLOR_256;
bg2.number = 2;
bg2.screenBaseBlock = 30;
bg2.wraparound = 1;
bg2.size = ROTBG_SIZE_256x256;


EnableBackground(&bg2);//this sets up my background if all the members are filled in
//and validates the tiledata and mapdata pointers

SetMode(MODE_2 | BG2_ENABLE);
//the palette is from a pcx file but I deleted all the graphics data and just put to tiles in there manualy
DMA_Copy(3,(void*)SunsetPalette,(void*)BGPaletteMem,128,DMA_32NOW); //da palette
DMA_Copy(3,(void*)SunsetDatatemp, (void*)bg2.tileData,32, DMA_32NOW); //just two tiles a black and a white


//just alternates the tiles to put blocks on the screen

for(loopy = 0; loopy<32; loopy++)
{
for(loopx = 0; loopx<16; loopx++)
{
if( loopx&1 && loopy&2)
bg2.mapData[loopy*16+loopx] = (1<<8)+1;
if( !(loopx&1) && !(loopy&2))
bg2.mapData[loopy*16+loopx] = (1<<8)+1;
}
}

//sine cos LUT
for(loop = 0; loop < 360; loop++)
{
SIN[loop] = (FIXED)(sin(RADIAN(loop)) * (float)(1<<16)); //sin and cos are computed and cast to fixed //fixed
COS[loop] = (FIXED)(cos(RADIAN(loop)) * (float)(1<<16));
}

//calculate my divide look up table so I can use the property x/y = x*(1/y) = x*div[y]
for(loop=0;loop <160;loop++)
{
div[loop] = (FIXED)( (float)( (1<<16)/loop) ); //our fixed point divide table is 8.24 (24 bits of fraction)
}




// EnableInterupts(INT_HBLANK | INT_VBLANK); //turn on my interupts...dont realy need vblank

while(1)
{
GetInput();
while(REG_VCOUNT < 160){}


}
return(0);

}

void GetInput(void)
{
static int angletemp = 0; //this to give us a bit slower change in angle. If i incremented it once per frame
//it would change 60 times a secont that is way too fast so I increment angletemp and divide by 64 before puting in angle
//. That means that angle temp has to increase
//by 64 before angle will increase by one.


if(!(*KEYS & KEY_LEFT)) //to move left and right is a simple sin of the angle...the shift is just to control how fast we move
{
y+=(SIN[angle])>>3;
x-=(COS[angle])>>3;
}
if(!(*KEYS & KEY_RIGHT))
{
y-=(SIN[angle])>>3;
x+=(COS[angle])>>3;
}

if(angle < 270) //since moving up and down we just rotate the angle by 90
angle += 90;//its okay that we destroy it because we restore it at the end of this function
else
angle-=270;


if(!(*KEYS & KEY_UP))
{
y-=(SIN[angle])>>3;
x+=(COS[angle])>>3;
}
if(!(*KEYS & KEY_DOWN))
{
y+=(SIN[angle])>>3;
x-=(COS[angle])>>3;
}

if(!(*KEYS & KEY_L))
{
angletemp--;
if(angletemp<0)
angletemp = (359<<6);
}
if(!(*KEYS & KEY_R))
{
angletemp++;
if(angletemp > (359<<6))
angletemp = 0;
}
if(!(*KEYS & KEY_A))
{
height++;
}
if(!(*KEYS & KEY_B))
{
height--;
}
if(!(*KEYS & KEY_START))
{

}
if(!(*KEYS & KEY_SELECT))
{

}
angle = angletemp>>6; //this is where I do the divide by 64

}
_________________
my dev/business site:

http://codebytesdev.afraid.org

#10403 - sajiimori - Thu Sep 04, 2003 7:17 am

You probably need to enable interrupts in your crt0.S. That is, assuming you're using devkit advance. It's not configured for interrupts by default.

#10417 - Mr. GBA - Thu Sep 04, 2003 1:30 pm

Sajimori, do you know how to configure interrupts using DevKitAdv?
_________________
my dev/business site:

http://codebytesdev.afraid.org

#10418 - Mr. GBA - Thu Sep 04, 2003 2:09 pm

I've been trying to configure interupts using the crt0 files and I get this from DevKitAdv:

C:\WINDOWSM\Desktop\mode7>
C:\WINDOWSM\Desktop\mode7>ld -o Mode7.elf crt0.o crtbegin.o crtend.o interupt.
o tutor.o DMA.o backgrounds.o
tutor.o: In function `main':
tutor.o(.text+0xa): undefined reference to `__gccmain'
tutor.o(.text+0xfa): undefined reference to `__floatsisf'
tutor.o(.text+0x104): undefined reference to `__divsf3'
tutor.o(.text+0x108): undefined reference to `__extendsfdf2'
tutor.o(.text+0x110): undefined reference to `__muldf3'
tutor.o(.text+0x118): undefined reference to `__muldf3'
tutor.o(.text+0x11c): undefined reference to `__fixdfsi'
tutor.o(.text+0x128): undefined reference to `__floatsisf'
tutor.o(.text+0x132): undefined reference to `__divsf3'
tutor.o(.text+0x136): undefined reference to `__extendsfdf2'
tutor.o(.text+0x13e): undefined reference to `__muldf3'
tutor.o(.text+0x146): undefined reference to `__muldf3'
tutor.o(.text+0x14a): undefined reference to `__fixdfsi'
tutor.o(.text+0x16a): undefined reference to `__divsi3'
tutor.o(.text+0x16e): undefined reference to `__floatsisf'
tutor.o(.text+0x172): undefined reference to `__fixsfsi'
tutor.o(.text+0x1a6): undefined reference to `__addsf3'
tutor.o(.text+0x1ae): undefined reference to `__addsf3'

Can anyone help?
Thanks
_________________
my dev/business site:

http://codebytesdev.afraid.org

#10435 - tepples - Thu Sep 04, 2003 8:03 pm

Mr. GBA wrote:
I've been trying to configure interupts using the crt0 files and I get this from DevKitAdv:

C:\WINDOWSM\Desktop\mode7>
C:\WINDOWSM\Desktop\mode7>ld -o Mode7.elf crt0.o crtbegin.o crtend.o interupt.o tutor.o DMA.o backgrounds.o

You'll need to add -lgcc -lc -lgcc if you're using ld.exe instead of gcc.exe.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.