#118365 - neilio - Mon Feb 12, 2007 8:53 pm
Yet another query :)
I'm trying to get a first tiled background program working but I can't seem to get the tilemap to work - the character graphics and palette (apparently) loads fine but all I get is a screen full of the 1st character graphic...
I'm hazarding a guess that whatever is causing it is around the //copy in the tile map data area or with the pointer to the screen base block.
Apologies for including long program code in a post but I'm not familiar with any file hosting sites at the moment! As always I'm using PERN headers.
bob.c ->
bob.h ->
_________________
I'd like to think this signature is under development, but it isn't.
I'm trying to get a first tiled background program working but I can't seem to get the tilemap to work - the character graphics and palette (apparently) loads fine but all I get is a screen full of the 1st character graphic...
I'm hazarding a guess that whatever is causing it is around the //copy in the tile map data area or with the pointer to the screen base block.
Apologies for including long program code in a post but I'm not familiar with any file hosting sites at the moment! As always I'm using PERN headers.
Code: |
#include"gba.h" #include "bob.h" #include "bob.c" //graphics, palette and map data // Globals to hold the key state u16 key_curr=0, key_prev=0; //palette for background tiles #define BG_PALETTE_MEM (0x05000000) ///main entry point int main(void) { int i; u16 ii; //creat pointers to vram u16* vramMap = (u16*)SCREEN_BASE_BLOCK(31); u16* vramTiles = (u16*)MAP_BASE_BLOCK(0); u16* vramBGPalette = (u16*)BG_PALETTE_MEM; //copy the tile graphics in character graphics mem, 4bitsperpixel for(i = 0; i < 32; i++) vramTiles[i] = bobTiles[i]; //copy in the palette, 16 colour palette for(i = 0; i < 16; i++) vramBGPalette[i] = bobPal[i]; //copy in the tile map data for(i = 0; i < 16*16; i++) vramMap[i] = bobMapTiles[i]; // set up BG0 for a 4bpp 32x32t map, using // using charblock 0 and screenblock 31 REG_BG0CNT = MAP_BASE_BLOCK(0) | SCREEN_BASE_BLOCK(31) | BG_COLOR_16 | TEXTBG_SIZE_256x256; SetMode(MODE_0 | BG0_ENABLE); //main loop while(1) { if(key_released(KEY_A)) { ii=10; REG_BG0HOFS=ii; REG_BG0VOFS=ii; } } } |
bob.c ->
Code: |
const unsigned short bobPal[16]= { 0x0000,0xF0F0,0x0200,0x0210,0x4000,0x4010,0x4200,0x6318, 0x4210,0x001F,0x03E0,0x03FF,0x7C00,0x7C1F,0x7FE0,0x7FFF, }; const unsigned short bobTiles[32]= { 0x1000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000, 0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111, }; const unsigned short bobMapTiles[16*16]= { 0,1,1,1,1,1,1,1, 1,0,1,1,1,1,1,1, 1,1,0,1,1,1,1,1, 1,1,1,0,1,1,1,1, 1,1,1,1,0,1,1,1, 1,1,1,1,1,0,1,1, 1,1,1,1,1,1,0,1, 1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1, 1,0,1,1,1,1,1,1, 1,1,0,1,1,1,1,1, 1,1,1,0,1,1,1,1, 1,1,1,1,0,1,1,1, 1,1,1,1,1,0,1,1, 1,1,1,1,1,1,0,1, 1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1, 1,0,1,1,1,1,1,1, 1,1,0,1,1,1,1,1, 1,1,1,0,1,1,1,1, 1,1,1,1,0,1,1,1, 1,1,1,1,1,0,1,1, 1,1,1,1,1,1,0,1, 1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1, 1,0,1,1,1,1,1,1, 1,1,0,1,1,1,1,1, 1,1,1,0,1,1,1,1, 1,1,1,1,0,1,1,1, 1,1,1,1,1,0,1,1, 1,1,1,1,1,1,0,1, 1,1,1,1,1,1,1,0, }; |
bob.h ->
Code: |
#ifndef __BOB__ #define __BOB__ #define bobPalLen 32 extern const unsigned short bobbyPal[16]; #define bobTilesLen 64 extern const unsigned short bobbyTiles[32]; #endif // __BOB__ |
_________________
I'd like to think this signature is under development, but it isn't.