Added converted car data and modified source to show car sprite.

This commit is contained in:
Truls Alexander Tangstad 2005-11-22 19:25:16 +00:00
parent c2d081f45d
commit 9b713b8edf
4 changed files with 71 additions and 138 deletions

BIN
gba/cartest/data/car.bin Normal file

Binary file not shown.

Binary file not shown.

71
gba/cartest/src/cartest.c Normal file
View File

@ -0,0 +1,71 @@
//---------------------------------------------------------------------------------
// Initial code from devkitARM - http://www.devkit.tk
//---------------------------------------------------------------------------------
#include "gba_video.h"
#include "gba_systemcalls.h"
#include "gba_input.h"
#include "gba_interrupt.h"
#include "gba_sprites.h"
#include "gba_dma.h"
#include "pcx.h"
#include "fade.h"
#include <stdlib.h>
#include <string.h>
//---------------------------------------------------------------------------------
// header for binary data generated by bin2o macro in makefile
//---------------------------------------------------------------------------------
#include "car_pal_bin.h"
#include "car_bin.h"
//---------------------------------------------------------------------------------
// storage space for palette data
//---------------------------------------------------------------------------------
u16 PaletteBuffer[256];
OBJATTR car;
unsigned int frame;
//---------------------------------------------------------------------------------
void VblankInterrupt()
//---------------------------------------------------------------------------------
{
frame += 1;
ScanKeys();
}
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void)
//---------------------------------------------------------------------------------
{
// Set up the interrupt handlers
InitInterrupt();
SetInterrupt( IE_VBL, VblankInterrupt);
// Enable Vblank Interrupt to allow VblankIntrWait
EnableInterrupt(IE_VBL);
// Allow Interrupts
REG_IME = 1;
// screen mode, background and objects to display
SetMode( MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP );
CpuFastSet(car_bin, BITMAP_OBJ_BASE_ADR, COPY32 | car_bin_size/4);
CpuFastSet(car_pal_bin, OBJ_COLORS, COPY32 | car_pal_bin_size/4);
memset(&car, 0, sizeof(car));
car.attr2 = OBJ_CHAR(512);
car.attr1 = OBJ_SIZE(1) | OBJ_X(175);
car.attr0 = OBJ_256_COLOR | OBJ_Y(49);
VBlankIntrWait();
CpuFastSet(&car, OAM, COPY32 | sizeof(car)/4);
while (1) {}
}

View File

@ -1,138 +0,0 @@
//---------------------------------------------------------------------------------
// Initial code from devkitARM - http://www.devkit.tk
//---------------------------------------------------------------------------------
#include "gba_video.h"
#include "gba_systemcalls.h"
#include "gba_input.h"
#include "gba_interrupt.h"
#include "gba_sprites.h"
#include "gba_dma.h"
#include "pcx.h"
#include "fade.h"
#include <stdlib.h>
#include <string.h>
//---------------------------------------------------------------------------------
// header for binary data generated by bin2o macro in makefile
//---------------------------------------------------------------------------------
#include "s_piece_bin.h"
#include "helds_logo_bin.h"
#include "helds_pal_bin.h"
#include "frog_bin.h"
#include "turret_bin.h"
//---------------------------------------------------------------------------------
// storage space for palette data
//---------------------------------------------------------------------------------
u16 PaletteBuffer[256];
OBJATTR s_sprite, frog_sprite;
unsigned int frame;
typedef struct
{
OBJATTR oam;
u8 frames;
u8 direction;
s8 frame;
} AnimSprite;
AnimSprite turret;
//---------------------------------------------------------------------------------
void VblankInterrupt()
//---------------------------------------------------------------------------------
{
frame += 1;
ScanKeys();
}
void move_show_and_wait(u16 x, u16 y, u16 wait_ticks) {
// assume we are in vblank
s_sprite.attr1 = OBJ_X(x);
s_sprite.attr0 = OBJ_256_COLOR | OBJ_Y(y);
CpuFastSet(&s_sprite, OAM, COPY32 | sizeof(s_sprite)/4);
u16 i;
for (i=0; i<wait_ticks; i++) VBlankIntrWait();
}
void update_sprite(AnimSprite* sprite, u16 char_base, u16 oam_index) {
sprite->oam.attr2 = OBJ_CHAR(char_base + sprite->frame*8);
VBlankIntrWait();
CpuFastSet(&sprite->oam, OAM + oam_index*sizeof(OBJATTR),
COPY32 | sizeof(OBJATTR)/4);
}
//---------------------------------------------------------------------------------
// Program entry point
//---------------------------------------------------------------------------------
int main(void)
//---------------------------------------------------------------------------------
{
// Set up the interrupt handlers
InitInterrupt();
SetInterrupt( IE_VBL, VblankInterrupt);
// Enable Vblank Interrupt to allow VblankIntrWait
EnableInterrupt(IE_VBL);
// Allow Interrupts
REG_IME = 1;
// screen mode, background and objects to display
SetMode( MODE_4 | BG2_ON | OBJ_ON | OBJ_1D_MAP );
CpuFastSet(helds_logo_bin, (u16*)VRAM, COPY32 | helds_logo_bin_size/4);
CpuFastSet(helds_pal_bin, PaletteBuffer, COPY32 | helds_pal_bin_size / 4);
FadeToPalette( PaletteBuffer, 60);
CpuFastSet(s_piece_bin, BITMAP_OBJ_BASE_ADR, COPY32 | s_piece_bin_size/4);
CpuFastSet(frog_bin, BITMAP_OBJ_BASE_ADR + s_piece_bin_size,
COPY32 | frog_bin_size/4);
CpuFastSet(turret_bin, BITMAP_OBJ_BASE_ADR + s_piece_bin_size + frog_bin_size,
COPY32 | turret_bin_size/4);
CpuFastSet(PaletteBuffer, OBJ_COLORS, COPY32 | sizeof(PaletteBuffer)/4);
memset(&s_sprite, 0, sizeof(s_sprite));
memset(&frog_sprite, 0, sizeof(frog_sprite));
memset(&turret, 0, sizeof(turret));
s_sprite.attr2 = OBJ_CHAR(512);
frog_sprite.attr2 = OBJ_CHAR(514);
frog_sprite.attr1 = OBJ_SIZE(1) | OBJ_X(175);
frog_sprite.attr0 = OBJ_256_COLOR | OBJ_Y(49);
// each frame is 16x16=256 bytes
turret.frames = 5;
turret.oam.attr2 = OBJ_CHAR(516);
turret.oam.attr1 = OBJ_SIZE(1) | OBJ_X(43);
turret.oam.attr0 = OBJ_256_COLOR | OBJ_Y(73);
VBlankIntrWait();
CpuFastSet(&frog_sprite, OAM + sizeof(s_sprite), COPY32 | sizeof(frog_sprite)/4);
u16 i;
while (1)
{
for (i=0; i<3; i++) VBlankIntrWait();
if (turret.direction)
turret.frame += 1;
else
turret.frame -= 1;
if (turret.frame >= turret.frames) {
turret.frame = turret.frames - 1;
turret.direction = 0;
} else if (turret.frame < 0) {
turret.frame = 0;
turret.direction = 1;
}
update_sprite(&turret, 522, 2);
}
}