Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,501,771
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 04-29-24 05:07 PM
Guest: Register | Login

0 users currently in Computing | 1 guest

Main - Computing - help with background in HAM for GBA New thread | New reply


joels341
Posted on 04-06-07 10:44 PM Link | Quote | ID: 24130

Newcomer
Level: 3

Posts: 1/1
EXP: 78
Next: 50

Since: 04-06-07

Last post: 6232 days
Last view: 6232 days
Hi.
I am trying to load a background in HAM for the GBA.
The background uses 8x8 tiles, and is 240x160 pixels

The Palette and Tiles seem to load correctly, but the tiles don't appear in the correct order.

Everything works fine when I use the built in HAM functions, but I am trying to stay away from those and directly use the GBA's registers.

Here is my code, what am I doing wrong?

//#include
//#include "Apoc_GBA.h"

//#include "gfx/master_palette/master.pal.c"
#include "gfx/map/map1.map.c"
#include "gfx/map/map1.raw.c"
#include "gfx/map/map1.pal.c"


#define MULTIBOOT int __gba_multiboot;
MULTIBOOT

#define REG_DMA3SAD *(volatile unsigned int*)0x40000D4
#define REG_DMA3DAD *(volatile unsigned int*)0x40000D8
#define REG_DMA3CNT *(volatile unsigned int*)0x40000DC
#define DMA_ENABLE 0x80000000
#define DMA_TIMING_IMMEDIATE 0x00000000
#define DMA_16 0x00000000
#define DMA_32 0x04000000
#define DMA_32NOW (DMA_ENABLE | DMA_TIMING_IMMEDIATE | DMA_32)
#define DMA_16NOW (DMA_ENABLE | DMA_TIMING_IMMEDIATE | DMA_16)
//scrolling registers for background 0
#define REG_BG0HOFS *(volatile unsigned short*)0x4000010
#define REG_BG0VOFS *(volatile unsigned short*)0x4000012
//background setup registers and data
#define REG_BG0CNT *(volatile unsigned short*)0x4000008
#define REG_BG1CNT *(volatile unsigned short*)0x400000A
#define REG_BG2CNT *(volatile unsigned short*)0x400000C
#define REG_BG3CNT *(volatile unsigned short*)0x400000E
#define BG_COLOR256 0x80
#define CHAR_SHIFT 2
#define SCREEN_SHIFT 8
#define WRAPAROUND 0x1
//background tile bitmap sizes
#define TEXTBG_SIZE_256x256 0x0
#define TEXTBG_SIZE_256x512 0x8000
#define TEXTBG_SIZE_512x256 0x4000
#define TEXTBG_SIZE_512x512 0xC000

#define CharBaseBlock(n) (((n)*0x4000)+0x6000000)
#define ScreenBaseBlock(n) (((n)*0x800)+0x6000000)
//background mode identifiers
#define BG0_ENABLE 0x100
#define BG1_ENABLE 0x200
#define BG2_ENABLE 0x400
#define BG3_ENABLE 0x800
//video identifiers
#define REG_DISPCNT *(unsigned int*)0x4000000
#define BGPaletteMem ((unsigned short*)0x5000000)
#define SetMode(mode) REG_DISPCNT = (mode)
//vertical refresh register
#define REG_DISPSTAT *(volatile unsigned short*)0x4000004

//DMAFastcopy for graphics display
////////////////////////////////////////////////////////////
// Function: DMAFastCopy
// Fast memory copy function built into hardware
////////////////////////////////////////////////////////////
void DMAFastCopy(void* source, void* dest, unsigned int count, unsigned int mode)
{
if (mode == DMA_16NOW || mode == DMA_32NOW)
{
REG_DMA3SAD = (unsigned int)source;
REG_DMA3DAD = (unsigned int)dest;
REG_DMA3CNT = count | mode;
}
}

void WaitVBlank(void)
{
while((REG_DISPSTAT & 1));
}

#define FrontBuffer ((u16*)0x6000000) // Front Display Memory (the screen in mode 3-5)
#define BG_PaletteMem ((u16*)0x5000000) // Background Palette(256/16 colors)

int main(void)
{

unsigned short *cur_map_ptr = (unsigned short*)ScreenBaseBlock(31);
REG_BG0CNT = BG_COLOR256 | TEXTBG_SIZE_256x256 | (31 << SCREEN_SHIFT) | WRAPAROUND;

/*| OBJ_ENABLE | OBJ_MAP_1D*/
SetMode(0 | BG0_ENABLE);
DMAFastCopy((void*)map1_Palette, (void*)BGPaletteMem, 256, DMA_16NOW);
DMAFastCopy((void*)map1_Tiles, (void*)CharBaseBlock(0), 14496, DMA_32NOW);
DMAFastCopy((void*)map1_Map, (void*)cur_map_ptr, 512, DMA_32NOW);


while(1)
{
WaitVBlank();

//DMAFastCopy((void*)map1_Map, (void*)cur_map_ptr, 512, DMA_32NOW);

WaitVBlank();

}

return 0;
}

Main - Computing - help with background in HAM for GBA New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.017 seconds. (329KB of memory used)
MySQL - queries: 37, rows: 46/47, time: 0.014 seconds.