20
20
21
21
#include < nds.h>
22
22
#include < gl2d.h>
23
+ #include " lodepng.h"
23
24
#include " bios_decompress_callback.h"
24
25
#include " FontGraphic.h"
25
26
26
27
// Graphic files
27
28
#include " _3ds_bottom.h"
28
29
#include " _3ds_bottom_bubble.h"
29
30
30
- #include " _3ds_top .h"
31
+ #include " _3ds_top_png_bin .h"
31
32
32
33
#include " dialogbox.h"
33
34
#include " _3ds_bubble.h"
@@ -90,6 +91,10 @@ bool showdialogbox = false;
90
91
float dbox_movespeed = 22 ;
91
92
float dbox_Ypos = -192 ;
92
93
94
+ u16 topBgImg[2 ][256 *192 ] = {0 };
95
+ bool secondBuffer = false ;
96
+
97
+ int topBg;
93
98
int bottomBg;
94
99
95
100
int bottomBgState = 0 ; // 0 = Uninitialized 1 = No Bubble 2 = bubble.
@@ -222,6 +227,7 @@ void vBlankHandler()
222
227
{
223
228
execQueue (); // Execute any actions queued during last vblank.
224
229
230
+ dmaCopyHalfWordsAsynch (0 , topBgImg[secondBuffer], bgGetGfxPtr (topBg), 0x18000 );
225
231
glBegin2D ();
226
232
{
227
233
if (fadeType == true ) {
@@ -347,6 +353,7 @@ void vBlankHandler()
347
353
}
348
354
glEnd2D ();
349
355
GFX_FLUSH = 0 ;
356
+ secondBuffer = !secondBuffer;
350
357
351
358
startBorderZoomAnimDelay++;
352
359
if (startBorderZoomAnimDelay == 8 ) {
@@ -358,11 +365,6 @@ void vBlankHandler()
358
365
}
359
366
}
360
367
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
-
366
368
void graphicsInit (int initTitleboxXpos)
367
369
{
368
370
*(u16 *)(0x0400006C ) |= BIT (14 );
@@ -374,7 +376,7 @@ void graphicsInit(int initTitleboxXpos)
374
376
375
377
// //////////////////////////////////////////////////////////
376
378
videoSetMode (MODE_5_3D | DISPLAY_BG2_ACTIVE);
377
- videoSetModeSub (MODE_3_2D | DISPLAY_BG0_ACTIVE );
379
+ videoSetModeSub (MODE_3_2D | DISPLAY_BG3_ACTIVE );
378
380
379
381
// Initialize gl2d
380
382
glScreen2D ();
@@ -385,37 +387,74 @@ void graphicsInit(int initTitleboxXpos)
385
387
// Clear the GL texture state
386
388
glResetTextures ();
387
389
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
-
398
390
lcdMainOnBottom ();
399
391
400
- topBgLoad ();
401
-
402
392
// Set up enough texture memory for our textures
403
393
// Bank A is just 128kb and we are using 194 kb of
404
394
// sprites
405
395
vramSetBankA (VRAM_A_TEXTURE);
406
396
vramSetBankB (VRAM_B_TEXTURE);
397
+ vramSetBankC (VRAM_C_SUB_BG_0x06200000);
407
398
vramSetBankD (VRAM_D_MAIN_BG_0x06000000);
408
399
vramSetBankE (VRAM_E_TEX_PALETTE);
409
400
vramSetBankF (VRAM_F_TEX_PALETTE_SLOT4);
410
401
vramSetBankG (VRAM_G_TEX_PALETTE_SLOT5); // 16Kb of palette ram, and font textures take up 8*16 bytes.
411
402
vramSetBankH (VRAM_H_SUB_BG_EXT_PALETTE);
412
403
vramSetBankI (VRAM_I_SUB_SPRITE_EXT_PALETTE);
413
404
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
+
414
454
// Initialize the bottom background
415
455
bottomBg = bgInit (2 , BgType_ExRotation, BgSize_ER_256x256, 0 ,1 );
416
456
417
457
bottomBgLoad (false , true );
418
- swiWaitForVBlank ();
419
458
420
459
dialogboxTexID = glLoadTileSet (dialogboxImage, // pointer to glImage array
421
460
16 , // sprite width
@@ -507,6 +546,4 @@ void graphicsInit(int initTitleboxXpos)
507
546
irqSet (IRQ_VBLANK, vBlankHandler);
508
547
irqEnable (IRQ_VBLANK);
509
548
// consoleDemoInit();
510
-
511
-
512
549
}
0 commit comments