Rotation.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. program BG_Rotation;
  2. {$L build/drunkenlogo.bin.o}
  3. {$L build/palette.bin.o}
  4. {$mode objfpc}
  5. uses
  6. ctypes, nds9;
  7. {$include inc/drunkenlogo.bin.inc}
  8. {$include inc/palette.bin.inc}
  9. var
  10. angle: u32;
  11. scrollX, scrollY: s16;
  12. scaleX, scaleY: s16;
  13. rcX, rcY: s16;
  14. keys: u32;
  15. s, c: s16;
  16. bg3: integer;
  17. begin
  18. videoSetMode(MODE_5_2D );
  19. vramSetBankA(VRAM_A_MAIN_BG);
  20. consoleDemoInit();
  21. bg3 := bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);
  22. dmaCopy(@drunkenlogo_bin, bgGetGfxPtr(bg3), 256*256);
  23. dmaCopy(@palette_bin, BG_PALETTE, 256*2);
  24. angle := 0;
  25. // the screen origin is at the rotation center...so scroll to the rotation
  26. // center + a small 32 pixle offset so our image is centered
  27. scrollX := 128;
  28. scrollY := 128 ;
  29. //scale is fixed point
  30. scaleX := 1 shl 8;
  31. scaleY := 1 shl 8;
  32. //this is the screen pixel that the image will rotate about
  33. rcX := 128;
  34. rcY := 96;
  35. while true do
  36. begin
  37. printf(#10#10#9 + 'Hello DS devers' + #10);
  38. printf(#9 + 'www.drunkencoders.com' + #10);
  39. printf(#9 + 'BG Rotation demo' + #10);
  40. iprintf('Angle %3d(actual) %3d(degrees)' + #10, angle, (angle * 360) div (1 shl 15));
  41. iprintf('Scroll X: %4d Y: %4d' + #10, scrollX, scrollY);
  42. iprintf('Rot center X: %4d Y: %4d' + #10, rcX, rcY);
  43. iprintf('Scale X: %4d Y: %4d' + #10, scaleX, scaleY);
  44. scanKeys();
  45. keys := keysHeld();
  46. if ( keys and KEY_L ) <> 0 then angle := angle + 20;
  47. if ( keys and KEY_R ) <> 0 then angle := angle - 20;
  48. if ( keys and KEY_LEFT ) <> 0 then scrollX := scrollX + 1;
  49. if ( keys and KEY_RIGHT ) <> 0 then scrollX := scrollX - 1;
  50. if ( keys and KEY_UP ) <> 0 then scrollY := scrollY + 1;
  51. if ( keys and KEY_DOWN ) <> 0 then scrollY := scrollY - 1;
  52. if ( keys and KEY_A ) <> 0 then scaleX := scaleX + 1;
  53. if ( keys and KEY_B ) <> 0 then scaleX := scaleX - 1;
  54. if ( keys and KEY_START ) <> 0 then rcX := rcX + 1;
  55. if ( keys and KEY_SELECT ) <> 0 then rcY := rcY + 1;
  56. if ( keys and KEY_X ) <> 0 then scaleY := scaleY + 1;
  57. if ( keys and KEY_Y ) <> 0 then scaleY := scaleY - 1;
  58. swiWaitForVBlank();
  59. if (keysDown() and KEY_START) <> 0 then
  60. exit;
  61. bgSetCenter(bg3, rcX, rcY);
  62. bgSetRotateScale(bg3, angle, scaleX, scaleY);
  63. bgSetScroll(bg3, scrollX, scrollY);
  64. bgUpdate();
  65. // clear the console screen (ansi escape sequence)
  66. iprintf(#$1b'[2J');
  67. end;
  68. end.