#143132 - Jim e - Wed Oct 17, 2007 5:45 am
Right now I'm working on a project that needs at least 512 tiles and scaling for tile maps. Based off the example setting one up for the sub core worked, but when I tried for the main core it failed. I don't understand why.
I know I could switch the core to render to the top LCD, but I wanted the main core to render the map because it has a bit more room for sprites and an easier memory layout.
Is there some trick that I don't know? Or is some limiting detail?
Code: |
#include <nds.h>
u16 mypal[] = { RGB15(00,00,00),RGB15(31,00,00), RGB15(00,31,00),RGB15(00,00,31), RGB15(31,00,31),RGB15(31,31,00) }; //This code works for the sub core void Init_good() { u32 i,x,y; //Set video modes and mem layout videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG_EXT_PALETTE); vramSetBankC(VRAM_C_SUB_BG); // Control registers SUB_BG3_CR = BG_TILE_BASE(1) | BG_MAP_BASE(0) | ROTBG_SIZE_256x256; SUB_BG3_XDX = 1<<8; SUB_BG3_XDY = 0; SUB_BG3_YDX = 0; SUB_BG3_YDY = 1<<8; //Make pointer for easy access u16 (*sub_tile)[8][4] = (u16 (*)[8][4])CHAR_BASE_BLOCK_SUB(1); u16 (*sub_map)[32] = (u16 (*)[32])SCREEN_BASE_BLOCK_SUB(0); //Make solid colored tiles for(i = 0; i < 4; i++) { for(y=0;y<8;y++) { for(x=0;x<4;x++) { sub_tile[i][y][x] = (i+1)|((i+1)<<8); } } } //Create a map of alternating tiles for(y=0;y<32;y++) { for(x=0;x<32;x++) { sub_map[y][x] = (x^y)&0x03; } } //Load Palette vramSetBankH(VRAM_H_LCD); for(i = 0; i < 6; i++) { VRAM_H_EXT_PALETTE[3][0][i]= mypal[i]; } vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); } //This code does not work for the main core. void Init_test() { u32 i,x,y; //Set video modes and mem layout videoSetMode(MODE_5_2D | DISPLAY_BG3_ACTIVE | DISPLAY_BG_EXT_PALETTE); vramSetBankA(VRAM_A_MAIN_BG); // Control registers BG3_CR = BG_TILE_BASE(1) | BG_MAP_BASE(0) | ROTBG_SIZE_256x256; BG3_XDX = 1<<8; BG3_XDY = 0; BG3_YDX = 0; BG3_YDY = 1<<8; //Make pointer for easy access u16 (*tile)[8][4] = (u16 (*)[8][4])CHAR_BASE_BLOCK(1); u16 (*map)[32] = (u16 (*)[32])SCREEN_BASE_BLOCK(0); //Make solid colored tiles for(i = 0; i < 4; i++) { for(y=0;y<8;y++) { for(x=0;x<4;x++) { tile[i][y][x] = (i+1)|((i+1)<<8); } } } //create a map of alternating tiles for(y=0;y<32;y++) { for(x=0;x<32;x++) { map[y][x] = (x^y)&0x03; } } //Load Palette vramSetBankG(VRAM_G_LCD); for(i = 0; i < 6; i++) { VRAM_G_EXT_PALETTE[3][0][i]= mypal[i]; } vramSetBankG(VRAM_G_BG_EXT_PALETTE); } int main(void) { irqInit(); irqEnable(IRQ_VBLANK); Init_good(); Init_test(); int scrollX = 0; int scrollY = 0; int scaleX = 1<<8; int scaleY = 1<<8; while(1) { scanKeys(); u32 keys = keysHeld(); if ( keys & KEY_LEFT ) scrollX++; if ( keys & KEY_RIGHT ) scrollX--; if ( keys & KEY_UP ) scrollY++; if ( keys & KEY_DOWN ) scrollY--; if ( keys & KEY_A ) scaleX++; if ( keys & KEY_Y ) scaleX--; if ( keys & KEY_X ) scaleY++; if ( keys & KEY_B ) scaleY--; swiWaitForVBlank(); SUB_BG3_CX = scrollX<<7; SUB_BG3_CY = scrollY<<7; SUB_BG3_XDX = scaleX; SUB_BG3_YDY = scaleY; BG3_CX = scrollX<<7; BG3_CY = scrollY<<7; BG3_XDX = scaleX; BG3_YDY = scaleY; } } |
I know I could switch the core to render to the top LCD, but I wanted the main core to render the map because it has a bit more room for sprites and an easier memory layout.
Is there some trick that I don't know? Or is some limiting detail?