BackgroundAllInOne.pp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. program AllInOne;
  2. {$L build/RotBackgrounds.o}
  3. {$L build/TextBackgrounds.o}
  4. {$L build/Multilayer.o}
  5. {$mode objfpc}
  6. uses
  7. ctypes, nds9, basic, advanced, handmade, scrolling;
  8. type
  9. Demo = record
  10. go: fp;
  11. name: pchar;
  12. description: pchar;
  13. end;
  14. PDemo = ^Demo;
  15. Category = record
  16. name: pchar;
  17. demos: PDemo;
  18. count: integer;
  19. end;
  20. PCategory = ^Category;
  21. var
  22. basicExamples: array [0..12] of Demo = (
  23. (go: @HandMadeTiles; name: 'Handmade Text 256x256'; description: 'Displays a handmade 256 x 256 Text background';),
  24. (go: @Text256x256; name: 'Text 256x256'; description: 'Displays a 256 x 256 Text background';),
  25. (go: @Text256x512; name: 'Text 256x512'; description: 'Displays a 256 x 512 Text background';),
  26. (go: @Text512x256; name: 'Text 512x256'; description: 'Displays a 512 x 256 Text background';),
  27. (go: @Text512x512; name: 'Text 512x512'; description: 'Displays a 512 x 512 Text background';),
  28. (go: @ExRot128x128; name: 'Extended Rotation 128x128'; description: 'Displays a 128 x 128 Extended Rotation background';),
  29. (go: @ExRot256x256; name: 'Extended Rotation 256x256'; description: 'Displays a 256 x 256 Extended Rotation background';),
  30. (go: @ExRot512x512; name: 'Extended Rotation 512x512'; description: 'Displays a 512 x 512 Extended Rotation background';),
  31. (go: @ExRot1024x1024; name: 'Extended Rotation 1024x1024'; description: 'Displays a 1024 x 1024 Extended Rotation background';),
  32. (go: @Rot128x128; name: 'Rotation 128x128'; description: 'Displays a 256 x 256 Rotation background';),
  33. (go: @Rot256x256; name: 'Rotation 256x256'; description: 'Displays a 256 x 256 Rotation background';),
  34. (go: @Rot512x512; name: 'Rotation 512x512'; description: 'Displays a 512 x 512 Rotation background';),
  35. (go: @Rot1024x1024; name: 'Rotation 1024x1024'; description: 'Displays a 1024 x 1024 Rotation background';)
  36. );
  37. bitmapExamples: array [0..9] of Demo = (
  38. (go: @Bmp8_128x128; name: '256 color 128x128'; description: 'Displays a 128 x 128 Bitmap background';),
  39. (go: @Bmp8_256x256; name: '256 color 256x256'; description: 'Displays a 256 x 256 Bitmap background';),
  40. (go: @Bmp8_512x256; name: '256 color 512x256'; description: 'Displays a 512 x 256 Bitmap background';),
  41. (go: @Bmp8_512x512; name: '256 color 512x512'; description: 'Displays a 512 x 512 Bitmap background';),
  42. (go: @Bmp8_512x1024; name: '256 color 512x1024'; description: 'Displays a 512 x 1024 Bitmap background';),
  43. (go: @Bmp8_1024x512; name: '256 color 1024x512'; description: 'Displays a 1024 x 512 Bitmap background';),
  44. (go: @Bmp16_128x128; name: '16-bit color 128x128'; description: 'Displays a 128 x 128 Bitmap background';),
  45. (go: @Bmp16_256x256; name: '16-bit color 256x256'; description: 'Displays a 256 x 256 Bitmap background';),
  46. (go: @Bmp16_512x256; name: '16-bit color 512x256'; description: 'Displays a 512 x 256 Bitmap background';),
  47. (go: @Bmp16_512x512; name: '16-bit color 512x512'; description: 'Displays a 512 x 512 Bitmap background';)
  48. );
  49. scrollingExamples: array [0..6] of Demo = (
  50. (go: @scrollText; name: 'Text Backgrounds'; description: 'Hardware Scrolling of a Text background';),
  51. (go: @scrollRotation; name: 'Rot Backgrounds'; description: 'Hardware Scrolling of a Rotation background';),
  52. (go: @scrollVertical; name: 'Vertical Scrolling'; description: 'Scrolling a large map vertically';),
  53. (go: @scrollHorizontalText; name: 'Horizontal Scrolling (Text)'; description: 'Scrolling a large map horzontally on a text background';),
  54. (go: @scrollHorizontalExRotation; name: 'Horizontal Scrolling (ExRot)'; description: 'Scrolling a large map horzontally on an extended rotation background';),
  55. (go: @scroll4wayText; name: '4 Way Scrolling (Text)'; description: 'Scrolling a large map 4 ways on a text background';),
  56. (go: @scroll4wayExRotation; name: '4 Way Scrolling (Rotation)'; description: 'Scrolling a large map 4 ways on a ex rotation background';)
  57. );
  58. advancedExamples: array [0..4] of Demo = (
  59. (go: @advMosaic; name: 'Mosaic'; description: 'A demo of the Mosaic scaling';),
  60. (go: @advRotating; name: 'Rotation'; description: '';),
  61. (go: @advScaling; name: 'Scaling'; description: '';),
  62. (go: @advExtendedPalette; name: 'Extended Palette'; description: '';),
  63. (go: @advMultipleLayers; name: 'Multiple Text Layers'; description: '';)
  64. );
  65. categories: array [0..3] of Category = (
  66. (name: 'Basic'; demos: @basicExamples; count: sizeof(basicExamples) div sizeof(Demo);),
  67. (name: 'Bitmap'; demos: @bitmapExamples; count: sizeof(bitmapExamples) div sizeof(Demo);),
  68. (name: 'Scrolling'; demos: @scrollingExamples; count: sizeof(scrollingExamples) div sizeof(Demo);),
  69. (name: 'Advanced'; demos: @advancedExamples; count: sizeof(advancedExamples) div sizeof(Demo);)
  70. );
  71. var
  72. keys: integer;
  73. selectedCategory: integer = 0;
  74. selectedDemo: integer = 0;
  75. selected: boolean = false;
  76. catCount: integer;
  77. demoCount: integer = 0;
  78. ci: integer;
  79. di: integer;
  80. begin
  81. while true do
  82. begin
  83. catCount := sizeof(categories) div sizeof(Category);
  84. demoCount := 0;
  85. videoSetModeSub(MODE_0_2D);
  86. consoleDemoInit();
  87. while not selected do
  88. begin
  89. scanKeys();
  90. keys := keysDown();
  91. if (keys and KEY_UP) <> 0 then dec(selectedCategory);
  92. if (keys and KEY_DOWN) <> 0 then inc(selectedCategory);
  93. if (keys and KEY_A) <> 0 then selected := true;
  94. if (selectedCategory < 0) then selectedCategory := catCount - 1;
  95. if (selectedCategory >= catCount) then selectedCategory := 0;
  96. swiWaitForVBlank();
  97. consoleClear();
  98. for ci := 0 to catCount - 1 do
  99. begin
  100. if ci = selectedCategory then
  101. iprintf('%c%d: %s'#10, '*', ci + 1, categories[ci].name)
  102. else
  103. iprintf('%c%d: %s'#10, ' ', ci + 1, categories[ci].name);
  104. end;
  105. end;
  106. selected := false;
  107. demoCount := categories[selectedCategory].count;
  108. while not (selected) do
  109. begin
  110. scanKeys();
  111. keys := keysDown();
  112. if (keys and KEY_UP) <> 0 then dec(selectedDemo);
  113. if (keys and KEY_DOWN) <> 0 then inc(selectedDemo);
  114. if (keys and KEY_A) <> 0 then selected := true;
  115. if (keys and KEY_B) <> 0 then break;
  116. if (selectedDemo < 0) then selectedDemo := demoCount - 1;
  117. if (selectedDemo >= demoCount) then selectedDemo := 0;
  118. swiWaitForVBlank();
  119. consoleClear();
  120. for di := 0 to demoCount - 1 do
  121. begin
  122. if di = selectedDemo then
  123. iprintf('%c%d: %s'#10, '*', di + 1, categories[selectedCategory].demos[di].name)
  124. else
  125. iprintf('%c%d: %s'#10, ' ', di + 1, categories[selectedCategory].demos[di].name);
  126. end;
  127. end;
  128. if (selected) then
  129. begin
  130. consoleClear();
  131. iprintf('Use arrow keys to scroll'#10'Press ''B'' to exit');
  132. categories[selectedCategory].demos[selectedDemo].go();
  133. end;
  134. end;
  135. end.