main.pp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. program main;
  2. {$L font.o}
  3. {$apptype arm9}
  4. {$define ARM9}
  5. {$mode objfpc}
  6. uses
  7. ctypes, nds9;
  8. var
  9. i: integer;
  10. sub_tile: pu16;
  11. sub_map: pu16;
  12. scaleX, scaleY: s16;
  13. scrollX, scrollY: s16;
  14. rcX, rcY: s16;
  15. angle: cuint = 0;
  16. keys: u32;
  17. angleSin, angleCos: s16;
  18. const
  19. font_WIDTH = 8;
  20. font_HEIGHT = 768;
  21. fontPalLen = 512;
  22. fontBitmapLen = 6144;
  23. var
  24. //byte array representing the picture
  25. fontBitmap: array [0..1535] of cuint16; cvar; external;
  26. fontPal: array [0..255] of cuint16; cvar; external;
  27. const
  28. char_base = 0;
  29. screen_base = 20;
  30. begin
  31. irqInit();
  32. irqEnable(IRQ_VBLANK);
  33. videoSetMode(0);
  34. videoSetModeSub(MODE_5_2D or DISPLAY_BG3_ACTIVE or DISPLAY_BG_EXT_PALETTE);
  35. vramSetBankC(VRAM_C_SUB_BG);
  36. SUB_BG3_CR^ := BG_TILE_BASE(char_base) or BG_MAP_BASE(screen_base) or ROTBG_SIZE_256x256;
  37. sub_tile := pu16(CHAR_BASE_BLOCK_SUB(char_base));
  38. sub_map := pu16(SCREEN_BASE_BLOCK_SUB(screen_base));
  39. //95 and 32 show how many characters there are and 32 shows which ASCII character to start, respectively
  40. //95 is the smaller set of ACSII characters. It usually will start with 32
  41. consoleInit(pu16(fontBitmap), sub_tile, 95, 32, sub_map, CONSOLE_USE_COLOR255, 8);
  42. //Load the Font Data and Palette stuff here
  43. for i := 0 to fontBitmapLen - 1 do
  44. sub_tile[i] := u32(fontBitmap[i]);
  45. // extended palettes are written with bank mapped to lcd
  46. vramSetBankH(VRAM_H_LCD);
  47. for i := 0 to fontPalLen - 1 do
  48. VRAM_H_EXT_PALETTE[3, 0, i] := u32(fontPal[i]);
  49. // map bank to extended palette after writing data
  50. vramSetBankH(VRAM_H_SUB_BG_EXT_PALETTE);
  51. iprintf('Custom Font Demo' + #10);
  52. iprintf(' by Poffy' + #10);
  53. iprintf('modified by WinterMute' + #10);
  54. iprintf('for libnds examples' + #10);
  55. //scale is fixed point
  56. scaleX := 1 shl 8;
  57. scaleY := 1 shl 8;
  58. scrollX := 128;
  59. scrollY := 96;
  60. //this is the screen pixel that the image will rotate about
  61. rcX := 128;
  62. rcY := 96;
  63. angle := 0;
  64. while true do
  65. begin
  66. scanKeys();
  67. keys := keysHeld();
  68. if ( keys and KEY_L ) <> 0 then angle := angle + 1;
  69. if ( keys and KEY_R ) <> 0 then angle := angle - 1;
  70. if ( keys and KEY_LEFT ) <> 0 then scrollX := scrollX + 1;
  71. if ( keys and KEY_RIGHT ) <> 0 then scrollX := scrollX - 1;
  72. if ( keys and KEY_UP ) <> 0 then scrollY := scrollY + 1;
  73. if ( keys and KEY_DOWN ) <> 0 then scrollY := scrollY - 1;
  74. if ( keys and KEY_A ) <> 0 then scaleX := scaleX + 1;
  75. if ( keys and KEY_B ) <> 0 then scaleX := scaleX - 1;
  76. if( keys and KEY_X ) <> 0 then scaleY := scaleY + 1;
  77. if( keys and KEY_Y ) <> 0 then scaleY := scaleY - 1;
  78. // wrap angle
  79. angle := angle and $1ff;
  80. // Compute sin and cos
  81. angleSin := SIN_bin[angle] shr 4;
  82. angleCos := COS_bin[angle] shr 4;
  83. swiWaitForVBlank();
  84. // Set the background registers
  85. SUB_BG3_XDX^ := cuint16(( angleCos * scaleX ) shr 8);
  86. SUB_BG3_XDY^ := cuint16((-angleSin * scaleX ) shr 8);
  87. SUB_BG3_YDX^ := cuint16(( angleSin * scaleY ) shr 8);
  88. SUB_BG3_YDY^ := cuint16(( angleCos * scaleY ) shr 8);
  89. SUB_BG3_CX^ := cuint16((scrollX shl 8) - rcX * ( angleCos - angleSin));
  90. SUB_BG3_CY^ := cuint16((scrollY shl 8) - rcY * ( angleSin + angleCos));
  91. end;
  92. end.