Skip to content

Commit 3493df9

Browse files
committed
Color de-band top screen image
1 parent 1a1b3ed commit 3493df9

File tree

8 files changed

+8416
-24
lines changed

8 files changed

+8416
-24
lines changed

arm9/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
4444
#---------------------------------------------------------------------------------
4545
# any extra libraries we wish to link with the project (order is important)
4646
#---------------------------------------------------------------------------------
47-
LIBS := -lfat -lmm9 -lgl2d -lnds9
47+
LIBS := -lfat -lmm9 -lnds9
4848

4949

5050
#---------------------------------------------------------------------------------

arm9/source/graphics/graphics.cpp

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@
2020

2121
#include <nds.h>
2222
#include <gl2d.h>
23+
#include "lodepng.h"
2324
#include "bios_decompress_callback.h"
2425
#include "FontGraphic.h"
2526

2627
// Graphic files
2728
#include "_3ds_bottom.h"
2829
#include "_3ds_bottom_bubble.h"
2930

30-
#include "_3ds_top.h"
31+
#include "_3ds_top_png_bin.h"
3132

3233
#include "dialogbox.h"
3334
#include "_3ds_bubble.h"
@@ -90,6 +91,10 @@ bool showdialogbox = false;
9091
float dbox_movespeed = 22;
9192
float dbox_Ypos = -192;
9293

94+
u16 topBgImg[2][256*192] = {0};
95+
bool secondBuffer = false;
96+
97+
int topBg;
9398
int bottomBg;
9499

95100
int bottomBgState = 0; // 0 = Uninitialized 1 = No Bubble 2 = bubble.
@@ -222,6 +227,7 @@ void vBlankHandler()
222227
{
223228
execQueue(); // Execute any actions queued during last vblank.
224229

230+
dmaCopyHalfWordsAsynch(0, topBgImg[secondBuffer], bgGetGfxPtr(topBg), 0x18000);
225231
glBegin2D();
226232
{
227233
if(fadeType == true) {
@@ -347,6 +353,7 @@ void vBlankHandler()
347353
}
348354
glEnd2D();
349355
GFX_FLUSH = 0;
356+
secondBuffer = !secondBuffer;
350357

351358
startBorderZoomAnimDelay++;
352359
if (startBorderZoomAnimDelay == 8) {
@@ -358,11 +365,6 @@ void vBlankHandler()
358365
}
359366
}
360367

361-
void topBgLoad() {
362-
swiDecompressLZSSVram ((void*)_3ds_topTiles, (void*)CHAR_BASE_BLOCK_SUB(2), 0, &decompressBiosCallback);
363-
vramcpy_ui (&BG_PALETTE_SUB[0], _3ds_topPal, _3ds_topPalLen);
364-
}
365-
366368
void graphicsInit(int initTitleboxXpos)
367369
{
368370
*(u16*)(0x0400006C) |= BIT(14);
@@ -374,7 +376,7 @@ void graphicsInit(int initTitleboxXpos)
374376

375377
////////////////////////////////////////////////////////////
376378
videoSetMode(MODE_5_3D | DISPLAY_BG2_ACTIVE);
377-
videoSetModeSub(MODE_3_2D | DISPLAY_BG0_ACTIVE);
379+
videoSetModeSub(MODE_3_2D | DISPLAY_BG3_ACTIVE);
378380

379381
// Initialize gl2d
380382
glScreen2D();
@@ -385,37 +387,74 @@ void graphicsInit(int initTitleboxXpos)
385387
// Clear the GL texture state
386388
glResetTextures();
387389

388-
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
389-
390-
REG_BG0CNT_SUB = BG_MAP_BASE(0) | BG_COLOR_256 | BG_TILE_BASE(2);
391-
BG_PALETTE[0]=0;
392-
BG_PALETTE[255]=0xffff;
393-
u16* bgMapSub = (u16*)SCREEN_BASE_BLOCK_SUB(0);
394-
for (int i = 0; i < CONSOLE_SCREEN_WIDTH*CONSOLE_SCREEN_HEIGHT; i++) {
395-
bgMapSub[i] = (u16)i;
396-
}
397-
398390
lcdMainOnBottom();
399391

400-
topBgLoad();
401-
402392
// Set up enough texture memory for our textures
403393
// Bank A is just 128kb and we are using 194 kb of
404394
// sprites
405395
vramSetBankA(VRAM_A_TEXTURE);
406396
vramSetBankB(VRAM_B_TEXTURE);
397+
vramSetBankC(VRAM_C_SUB_BG_0x06200000);
407398
vramSetBankD(VRAM_D_MAIN_BG_0x06000000);
408399
vramSetBankE(VRAM_E_TEX_PALETTE);
409400
vramSetBankF(VRAM_F_TEX_PALETTE_SLOT4);
410401
vramSetBankG(VRAM_G_TEX_PALETTE_SLOT5); // 16Kb of palette ram, and font textures take up 8*16 bytes.
411402
vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
412403
vramSetBankI(VRAM_I_SUB_SPRITE_EXT_PALETTE);
413404

405+
topBg = bgInitSub(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
406+
407+
std::vector<unsigned char> image;
408+
unsigned width, height;
409+
lodepng::decode(image, width, height, _3ds_top_png_bin, _3ds_top_png_bin_size);
410+
bool alternatePixel = false;
411+
for(unsigned i=0;i<image.size()/4;i++) {
412+
image[(i*4)+3] = 0;
413+
if (alternatePixel) {
414+
if (image[(i*4)] >= 0x4) {
415+
image[(i*4)] -= 0x4;
416+
image[(i*4)+3] |= BIT(0);
417+
}
418+
if (image[(i*4)+1] >= 0x4) {
419+
image[(i*4)+1] -= 0x4;
420+
image[(i*4)+3] |= BIT(1);
421+
}
422+
if (image[(i*4)+2] >= 0x4) {
423+
image[(i*4)+2] -= 0x4;
424+
image[(i*4)+3] |= BIT(2);
425+
}
426+
}
427+
topBgImg[0][i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
428+
if (alternatePixel) {
429+
if (image[(i*4)+3] & BIT(0)) {
430+
image[(i*4)] += 0x4;
431+
}
432+
if (image[(i*4)+3] & BIT(1)) {
433+
image[(i*4)+1] += 0x4;
434+
}
435+
if (image[(i*4)+3] & BIT(2)) {
436+
image[(i*4)+2] += 0x4;
437+
}
438+
} else {
439+
if (image[(i*4)] >= 0x4) {
440+
image[(i*4)] -= 0x4;
441+
}
442+
if (image[(i*4)+1] >= 0x4) {
443+
image[(i*4)+1] -= 0x4;
444+
}
445+
if (image[(i*4)+2] >= 0x4) {
446+
image[(i*4)+2] -= 0x4;
447+
}
448+
}
449+
topBgImg[1][i] = image[i*4]>>3 | (image[(i*4)+1]>>3)<<5 | (image[(i*4)+2]>>3)<<10 | BIT(15);
450+
if ((i % 256) == 255) alternatePixel = !alternatePixel;
451+
alternatePixel = !alternatePixel;
452+
}
453+
414454
// Initialize the bottom background
415455
bottomBg = bgInit(2, BgType_ExRotation, BgSize_ER_256x256, 0,1);
416456

417457
bottomBgLoad(false, true);
418-
swiWaitForVBlank();
419458

420459
dialogboxTexID = glLoadTileSet(dialogboxImage, // pointer to glImage array
421460
16, // sprite width
@@ -507,6 +546,4 @@ void graphicsInit(int initTitleboxXpos)
507546
irqSet(IRQ_VBLANK, vBlankHandler);
508547
irqEnable(IRQ_VBLANK);
509548
//consoleDemoInit();
510-
511-
512549
}

0 commit comments

Comments
 (0)