Advanced.pp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. unit advanced;
  2. interface
  3. uses
  4. ctypes, nds9, scrolling, RotBackgrounds, TextBackgrounds, Multilayer;
  5. procedure advMosaic();
  6. procedure advRotating();
  7. procedure advScaling();
  8. procedure advExtendedPalette();
  9. procedure advMultipleLayers();
  10. implementation
  11. procedure advMosaic();
  12. var
  13. bg: cint;
  14. keys: integer;
  15. mosaic_x: integer;
  16. mosaic_y: integer;
  17. begin
  18. videoSetMode(MODE_0_2D);
  19. vramSetBankA(VRAM_A_MAIN_BG);
  20. bg := bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0,1);
  21. dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
  22. dmaCopy(@Layer256x256Map, bgGetMapPtr(bg), Layer256x256MapLen);
  23. dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
  24. bgMosaicEnable(bg);
  25. while ((keys and KEY_B) = 0) do
  26. begin
  27. scanKeys();
  28. keys := keysDown();
  29. if (keys and KEY_UP) <> 0 then mosaic_y := mosaic_y - 1;
  30. if (keys and KEY_DOWN) <> 0 then mosaic_y := mosaic_y + 1;
  31. if (keys and KEY_LEFT) <> 0 then mosaic_x := mosaic_x - 1;
  32. if (keys and KEY_RIGHT) <> 0 then mosaic_x := mosaic_x + 1;
  33. if (mosaic_x > 15) then mosaic_x := 15;
  34. if (mosaic_x < 0) then mosaic_x := 0;
  35. if (mosaic_y > 15) then mosaic_y := 15;
  36. if (mosaic_y < 0) then mosaic_y := 0;
  37. swiWaitForVBlank();
  38. bgSetMosaic(mosaic_x, mosaic_y);
  39. consoleClear();
  40. iprintf('Press B to exit'#10);
  41. iprintf('DX: %d DY: %d', mosaic_x, mosaic_y);
  42. end;
  43. end;
  44. procedure advRotating();
  45. var
  46. bg: cint;
  47. keys: integer;
  48. angle: integer;
  49. mosaic_x: integer;
  50. mosaic_y: integer;
  51. center_x: integer;
  52. center_y: integer;
  53. begin
  54. videoSetMode(MODE_5_2D);
  55. vramSetBankA(VRAM_A_MAIN_BG);
  56. bg := bgInit(3, BgType_ExRotation, BgSize_ER_256x256, 0,1);
  57. dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
  58. dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
  59. dmaCopy(@Layer256x256Map, bgGetMapPtr(bg), Layer256x256MapLen);
  60. bgMosaicEnable(bg);
  61. while ((keys and KEY_B) = 0) do
  62. begin
  63. scanKeys();
  64. keys := keysHeld();
  65. if (keys and KEY_UP) <> 0 then center_y := center_y - 1;
  66. if (keys and KEY_DOWN) <> 0 then center_y := center_y + 1;
  67. if (keys and KEY_LEFT) <> 0 then center_x := center_x - 1;
  68. if (keys and KEY_RIGHT) <> 0 then center_x := center_x + 1;
  69. if (keys and KEY_L) <> 0 then angle := angle - 1;
  70. if (keys and KEY_R) <> 0 then angle := angle + 1;
  71. if (center_x > 256) then center_x := 256;
  72. if (center_x < 0) then center_x := 0;
  73. if (center_y > 192) then center_y := 192;
  74. if (center_y < 0) then center_y := 0;
  75. swiWaitForVBlank();
  76. bgSetRotate(bg, angle);
  77. bgSetScroll(bg, center_x, center_y);
  78. bgSetCenter(bg, center_x, center_y);
  79. bgUpdate();
  80. consoleClear();
  81. iprintf('Press B to exit.'#10);
  82. iprintf('Angle: %d '#10'center X: %d center Y: %d', angle, center_x, center_y);
  83. end;
  84. end;
  85. procedure advScaling();
  86. var
  87. bg: cint;
  88. keys, scale_x, scale_y: integer;
  89. begin
  90. videoSetMode(MODE_5_2D);
  91. vramSetBankA(VRAM_A_MAIN_BG);
  92. bg := bgInit(3, BgType_ExRotation, BgSize_ER_256x256, 0,1);
  93. dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
  94. dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
  95. dmaCopy(@Layer256x256Map, bgGetMapPtr(bg), Layer256x256MapLen);
  96. bgMosaicEnable(bg);
  97. scale_x := 1 shl 8;
  98. scale_y := 1 shl 8;
  99. while ((keys and KEY_B) = 0) do
  100. begin
  101. scanKeys();
  102. keys := keysHeld();
  103. if (keys and KEY_UP) <> 0 then scale_y := scale_y - 1;
  104. if (keys and KEY_DOWN) <> 0 then scale_y := scale_y + 1;
  105. if (keys and KEY_LEFT) <> 0 then scale_x := scale_x + 1;
  106. if (keys and KEY_RIGHT) <> 0 then scale_x := scale_x - 1;
  107. swiWaitForVBlank();
  108. bgSetScale(bg, scale_x , scale_y );
  109. bgUpdate();
  110. consoleClear();
  111. iprintf('Press B to exit.'#10);
  112. iprintf('scale X: %d scale Y: %d', scale_x, scale_y);
  113. end;
  114. end;
  115. procedure advExtendedPalette();
  116. begin
  117. end;
  118. procedure advMultipleLayers();
  119. var
  120. bg1, bg2, bg3: cint;
  121. keys: integer;
  122. bg1_hidden, bg2_hidden, bg3_hidden: boolean;
  123. begin
  124. videoSetMode(MODE_5_2D);
  125. vramSetBankA(VRAM_A_MAIN_BG);
  126. //initialize the backgrounds
  127. bg1 := bgInit(0, BgType_Text8bpp, BgSize_ER_256x256, 0,1);
  128. bg2 := bgInit(1, BgType_Text8bpp, BgSize_ER_256x256, 1,1);
  129. bg3 := bgInit(2, BgType_ExRotation, BgSize_ER_256x256, 2,1);
  130. //make sure the floor is on the bottom (by default hardware layer 0 will be rendered last)
  131. bgSetPriority(bg1, 3);
  132. bgSetPriority(bg2, 2);
  133. bgSetPriority(bg3, 1);
  134. //they all share tiles and a palette
  135. dmaCopy(@MultilayerTiles, bgGetGfxPtr(bg1), sizeof(MultilayerTiles));
  136. dmaCopy(@MultilayerPal, BG_PALETTE, sizeof(MultilayerPal));
  137. //all we need to do is copy in the maps
  138. dmaCopy(@Layer_1Map, bgGetMapPtr(bg1), Layer_1MapLen);
  139. dmaCopy(@Layer_2Map, bgGetMapPtr(bg2), Layer_2MapLen);
  140. dmaCopy(@Layer_3Map, bgGetMapPtr(bg3), Layer_3MapLen);
  141. keys := 0;
  142. bg1_hidden := false;
  143. bg2_hidden := false;
  144. bg3_hidden := false;
  145. while ((keys and KEY_B) = 0) do
  146. begin
  147. scanKeys();
  148. keys := keysDown();
  149. if (keys and KEY_UP) <> 0 then bg1_hidden := not bg1_hidden;
  150. if (keys and KEY_DOWN) <> 0 then bg2_hidden := not bg2_hidden;
  151. if (keys and KEY_LEFT) <> 0 then bg3_hidden := not bg3_hidden;
  152. swiWaitForVBlank();
  153. if bg1_hidden then bgHide(bg1) else bgShow(bg1);
  154. if bg2_hidden then bgHide(bg2) else bgShow(bg2);
  155. if bg3_hidden then bgHide(bg3) else bgShow(bg3);
  156. consoleClear();
  157. iprintf('Press UP DOWN LEFT to toggle the layers'#10#10);
  158. if bg1_hidden then
  159. iprintf('Floor (UP): %s'#10, 'hidden')
  160. else
  161. iprintf('Floor (UP): %s'#10, 'displayed');
  162. if bg2_hidden then
  163. iprintf('Walls (DOWN): %s'#10, 'hidden')
  164. else
  165. iprintf('Walls (DOWN): %s'#10, 'displayed');
  166. if bg3_hidden then
  167. iprintf('Decorations (LEFT): %s'#10, 'hidden')
  168. else
  169. iprintf('Decorations (LEFT): %s'#10, 'displayed');
  170. end;
  171. end;
  172. end.