summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/libndsfpc/examples/graphics/Backgrounds/rotation/Rotation.pp
blob: 80f61c906b2c48fcc24f4cfa8de363c92b3618ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
program BG_Rotation;
{$L build/drunkenlogo.bin.o}
{$L build/palette.bin.o}

{$mode objfpc}

uses
  ctypes, nds9;

{$include inc/drunkenlogo.bin.inc}
{$include inc/palette.bin.inc}

var
  angle: u32;
  scrollX, scrollY: s16;
  scaleX, scaleY: s16;
  rcX, rcY: s16;
  keys: u32;
  s, c: s16;
  bg3: integer;


begin
  videoSetMode(MODE_5_2D );

  vramSetBankA(VRAM_A_MAIN_BG);

  consoleDemoInit();


  bg3 := bgInit(3, BgType_Bmp8, BgSize_B8_256x256, 0,0);


  dmaCopy(@drunkenlogo_bin, bgGetGfxPtr(bg3), 256*256);
  dmaCopy(@palette_bin, BG_PALETTE, 256*2);

  angle := 0;

  // the screen origin is at the rotation center...so scroll to the rotation
  // center + a small 32 pixle offset so our image is centered
  scrollX := 128;
  scrollY := 128 ;

  //scale is fixed point
  scaleX := 1 shl 8;
  scaleY := 1 shl 8;

  //this is the screen pixel that the image will rotate about
  rcX := 128;
  rcY := 96;

  while true do
  begin
    printf(#10#10#9 + 'Hello DS devers' + #10);
    printf(#9 + 'www.drunkencoders.com' + #10);
    printf(#9 + 'BG Rotation demo' + #10);

    iprintf('Angle %3d(actual) %3d(degrees)' + #10, angle, (angle * 360) div (1 shl 15));
    iprintf('Scroll  X: %4d Y: %4d' + #10, scrollX, scrollY);
    iprintf('Rot center X: %4d Y: %4d' + #10, rcX, rcY);
    iprintf('Scale X: %4d Y: %4d' + #10, scaleX, scaleY);

    scanKeys();
    keys := keysHeld();

    if ( keys and KEY_L ) <> 0 then angle := angle + 20;
    if ( keys and KEY_R ) <> 0 then angle := angle - 20;
    if ( keys and KEY_LEFT ) <> 0 then scrollX := scrollX + 1;
    if ( keys and KEY_RIGHT ) <> 0 then  scrollX := scrollX - 1;
    if ( keys and KEY_UP ) <> 0 then scrollY := scrollY + 1;
    if ( keys and KEY_DOWN ) <> 0 then scrollY := scrollY - 1;
    if ( keys and KEY_A ) <> 0 then scaleX := scaleX + 1;
    if ( keys and KEY_B ) <> 0 then scaleX := scaleX - 1;
    if ( keys and KEY_START ) <> 0 then rcX := rcX + 1;
    if ( keys and KEY_SELECT ) <> 0 then rcY := rcY + 1;
    if ( keys and KEY_X ) <> 0 then scaleY := scaleY + 1;
    if ( keys and KEY_Y ) <> 0 then scaleY := scaleY - 1;


    swiWaitForVBlank();
		if (keysDown() and KEY_START) <> 0 then 
      exit;

    bgSetCenter(bg3, rcX, rcY);
    bgSetRotateScale(bg3, angle, scaleX, scaleY);
    bgSetScroll(bg3, scrollX, scrollY);
    bgUpdate();

    // clear the console screen (ansi escape sequence)
    iprintf(#$1b'[2J');

  end;
end.