backgrounds.pp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. program backgrounds;
  2. {$L build/drunkenlogo.o}
  3. {$L build/devkitlogo.o}
  4. {$mode objfpc}
  5. uses
  6. ctypes, nds9;
  7. {$include inc/drunkenlogo.inc}
  8. {$include inc/devkitlogo.inc}
  9. var
  10. bg: array [0..3] of integer = (0,0,0,0);
  11. i: integer;
  12. frames: integer = 0;
  13. begin
  14. // initialize video
  15. videoSetMode(MODE_0_2D);
  16. videoSetModeSub(MODE_0_2D);
  17. vramSetBankA(VRAM_A_MAIN_BG);
  18. vramSetBankC(VRAM_C_SUB_BG);
  19. // enable extended palettes
  20. bgExtPaletteEnable();
  21. bgExtPaletteEnableSub();
  22. // initialize backgrounds
  23. // extended palettes only work on 8bpp tiled bg's with 16-bit map entries
  24. // this means you can only use BgType_Text8bpp or BgType_ExRotation
  25. // http://mtheall.com/vram.html#T0=1&NT0=192&MB0=6&TB0=0&S0=0&T1=1&NT1=576&MB1=7&TB1=1&S1=0
  26. bg[0] := bgInit (0, BgType_Text8bpp, BgSize_T_256x256, 6, 0);
  27. bg[1] := bgInit (1, BgType_Text8bpp, BgSize_T_256x256, 7, 1);
  28. // we're using identical settings on the sub screen
  29. bg[2] := bgInitSub(0, BgType_Text8bpp, BgSize_T_256x256, 6, 0);
  30. bg[3] := bgInitSub(1, BgType_Text8bpp, BgSize_T_256x256, 7, 1);
  31. // copy graphics to vram
  32. dmaCopy(@devkitlogoTiles, bgGetGfxPtr(bg[0]), devkitlogoTilesLen);
  33. dmaCopy(@drunkenlogoTiles, bgGetGfxPtr(bg[1]), drunkenlogoTilesLen);
  34. // same for sub engine
  35. dmaCopy(@devkitlogoTiles, bgGetGfxPtr(bg[2]), devkitlogoTilesLen);
  36. dmaCopy(@drunkenlogoTiles, bgGetGfxPtr(bg[3]), drunkenlogoTilesLen);
  37. // copy maps to vram
  38. dmaCopy(@devkitlogoMap, bgGetMapPtr(bg[0]), devkitlogoMapLen);
  39. dmaCopy(@drunkenlogoMap, bgGetMapPtr(bg[1]), drunkenlogoMapLen);
  40. // same for sub engine
  41. dmaCopy(@devkitlogoMap, bgGetMapPtr(bg[2]), devkitlogoMapLen);
  42. dmaCopy(@drunkenlogoMap, bgGetMapPtr(bg[3]), drunkenlogoMapLen);
  43. // you can only access extended palettes in LCD mode
  44. vramSetBankE(VRAM_E_LCD); // for main engine
  45. vramSetBankH(VRAM_H_LCD); // for sub engine
  46. // copy palettes to extended palette area
  47. // there are 16 256-color palettes per bg
  48. // use '-mp #' to make grit use # for the slot number
  49. // we used '-mp 12' for drunkenlogo for demonstrative purposes
  50. dmaCopy(@devkitlogoPal, @(VRAM_E_EXT_PALETTE[0, 0]), devkitlogoPalLen); // bg 0, slot 0
  51. dmaCopy(@drunkenlogoPal, @(VRAM_E_EXT_PALETTE[1, 12]), drunkenlogoPalLen); // bg 1, slot 12
  52. // same for sub engine
  53. dmaCopy(@devkitlogoPal, @(VRAM_H_EXT_PALETTE[0, 0]), devkitlogoPalLen); // bg 0, slot 0
  54. dmaCopy(@drunkenlogoPal, @(VRAM_H_EXT_PALETTE[1, 12]), drunkenlogoPalLen); // bg 1, slot 12
  55. // map vram banks to extended palettes
  56. // http://mtheall.com/banks.html#A=MBG0&C=MBG2&E=BGEPAL&H=SBGEPAL
  57. vramSetBankE(VRAM_E_BG_EXT_PALETTE); // for main engine
  58. vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE); // for sub engine
  59. while keysDown() = 0 do
  60. begin
  61. swiWaitForVBlank();
  62. inc(frames);
  63. bgUpdate();
  64. scanKeys();
  65. // let's make it obvious there are multiple backgrounds
  66. for i := 0 to 7 do
  67. bgSetScroll(i, frames div ((i and 3) + 1), frames div ((i and 3) + 1));
  68. end;
  69. end.