~ubuntu-branches/ubuntu/lucid/fpc/lucid-proposed

« back to all changes in this revision

Viewing changes to fpcsrc/packages/libndsfpc/examples/devkitPro/input/TouchTest/main.pp

  • Committer: Bazaar Package Importer
  • Author(s): Mazen Neifer, Torsten Werner, Mazen Neifer
  • Date: 2008-10-09 23:29:00 UTC
  • mfrom: (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081009232900-553f61m37jkp6upv
Tags: 2.2.2-4
[ Torsten Werner ]
* Update ABI version in fpc-depends automatically.
* Remove empty directories from binary package fpc-source.

[ Mazen Neifer ]
* Removed leading path when calling update-alternatives to remove a Linitian
  error.
* Fixed clean target.
* Improved description of packages. (Closes: #498882)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
program main;
 
2
{$L ballpalette.bin.o}
 
3
{$L balldata.bin.o}
 
4
{$apptype arm9}
 
5
{$define ARM9}
 
6
 
 
7
{$mode objfpc}
 
8
 
 
9
uses
 
10
  ctypes, nds9;
 
11
 
 
12
var
 
13
  OAMCopy: array [0..127] of SpriteEntry;
 
14
  ballpalette_bin_end: array [0..0] of u8; cvar; external;
 
15
  ballpalette_bin: array [0..0] of u16; cvar; external;
 
16
  ballpalette_bin_size: u32; cvar; external;
 
17
  balldata_bin_end: array [0..0] of u8; cvar; external;
 
18
  balldata_bin: array [0..0] of u16; cvar; external;
 
19
  balldata_bin_size: u32; cvar; external;
 
20
 
 
21
 
 
22
procedure initOAM();
 
23
var
 
24
  i: integer;
 
25
begin
 
26
        for i := 0 to 127 do
 
27
                OAMCopy[i].st.attribute[0] := ATTR0_DISABLED;
 
28
end;
 
29
 
 
30
//---------------------------------------------------------------------------------
 
31
procedure updateOAM();
 
32
begin   
 
33
  dmaCopy(@OAMCopy, OAM, sizeof(OAMCopy));
 
34
end;
 
35
 
 
36
 
 
37
type
 
38
  TTouchType = (ttContinuous, ttSingle);
 
39
 
 
40
var
 
41
  frame: integer;
 
42
  TouchType: TTouchType = ttContinuous;
 
43
 
 
44
 
 
45
//---------------------------------------------------------------------------------
 
46
function Vblank(): pointer;
 
47
begin
 
48
//---------------------------------------------------------------------------------
 
49
        inc(frame);
 
50
end;
 
51
 
 
52
 
 
53
var
 
54
  min_x, min_y, max_x, max_y: integer;
 
55
  min_px, min_py, max_px, max_py: integer;
 
56
        touch: touchPosition;
 
57
  i: integer;
 
58
        pressed, held: integer;
 
59
 
 
60
begin
 
61
        min_x  := 4096;
 
62
  min_y  := 4096; 
 
63
  max_x  := 0;
 
64
  max_y  := 0;
 
65
        min_px := 4096;
 
66
  min_py := 4096;
 
67
  max_px := 0;
 
68
  max_py := 0;
 
69
  
 
70
 
 
71
        powerON(POWER_ALL_2D);
 
72
        
 
73
        // put the main screen on the bottom lcd
 
74
        lcdMainOnBottom();
 
75
        
 
76
        // Initialise the interrupt system
 
77
        irqInit();
 
78
        // install our simple vblank handler
 
79
        irqSet(IRQ_VBLANK, @Vblank);
 
80
        // enable the interrupt
 
81
        irqEnable(IRQ_VBLANK);
 
82
        initOAM();
 
83
    //enable vram and map it to the right places
 
84
    vramSetMainBanks(   VRAM_A_MAIN_SPRITE,        //A and B maped consecutivly as sprite memory
 
85
                        VRAM_B_MAIN_SPRITE,        //this gives us 256KB which is the max
 
86
                        VRAM_C_MAIN_BG_0x06000000,  //map C to background memory
 
87
                        VRAM_D_LCD                 //not using D
 
88
                        ); 
 
89
   
 
90
   //set the video mode
 
91
    videoSetMode(  MODE_0_2D or 
 
92
                   DISPLAY_SPR_ACTIVE or                //turn on sprites
 
93
                   DISPLAY_BG0_ACTIVE or                //turn on background 0
 
94
                   DISPLAY_SPR_1D                       //this is used when in tile mode
 
95
                    );
 
96
        
 
97
        // Sprite initialisation
 
98
        for i := 0 to 255 do
 
99
                SPRITE_PALETTE[i] := u32(ballpalette_bin[i]);
 
100
 
 
101
        for i := 0 to 32*16 - 1 do
 
102
                SPRITE_GFX[i] := u32(balldata_bin[i]);
 
103
 
 
104
        // black backdrop
 
105
        BG_PALETTE[0] := (RGB15(0,0,0));
 
106
 
 
107
        BG0_CR^ := BG_MAP_BASE(31);//use bg0 for the text
 
108
        
 
109
        BG_PALETTE[255] := (RGB15(31,31,31));//by default font rendered with color 255
 
110
        
 
111
        //consoleInit() is a lot more flexible but this gets you up and running quick
 
112
        consoleInitDefault(pu16(SCREEN_BASE_BLOCK(31)), pu16(CHAR_BASE_BLOCK(0)), 16);
 
113
 
 
114
 
 
115
        printf(#27 + '[4;8H' + 'Touch Screen Test');
 
116
        printf(#27 + '[15;4H' + 'Right Shoulder toggles');
 
117
 
 
118
        while true do
 
119
        begin
 
120
                swiWaitForVBlank();
 
121
                updateOAM();
 
122
 
 
123
                // read the button states
 
124
                scanKeys();
 
125
 
 
126
                // read the touchscreen coordinates
 
127
                touch := touchReadXY();
 
128
                
 
129
                pressed := keysDown();  // buttons pressed this loop
 
130
                held := keysHeld();             // buttons currently held
 
131
 
 
132
                // Right Shoulder button toggles the mode
 
133
                if ( pressed and KEY_R) <> 0 then Inc(TouchType);
 
134
 
 
135
                if TouchType = ttContinuous then 
 
136
      printf(#27 + '[14;4H' + 'Touch mode: CONTINUOUS ')
 
137
    else
 
138
      printf(#27 + '[14;4H' + 'Touch mode: SINGLE SHOT');
 
139
 
 
140
                iprintf(#27 + '[6;5H' + 'Touch x = %04X, %04X' + #10, [touch.x, touch.px]);
 
141
                iprintf(#27 + '[7;5H' + 'Touch x = %04X, %04X' + #10, [touch.x, touch.px]);
 
142
 
 
143
 
 
144
                iprintf(#27 + '[0;18H' + 'keys: %08X' + #10, [keysHeld()]);
 
145
                iprintf(#27 + '[9;10H' + 'Frame %d' + #10, [frame]);
 
146
 
 
147
                if (TouchType = ttSingle) and not ( (pressed and KEY_TOUCH) <> 0) then continue;
 
148
 
 
149
                if ((held and KEY_TOUCH)<0) or (touch.x = 0) or (touch.y = 0) then continue;
 
150
                
 
151
                iprintf(#27 + '[12;12H' + '(%d,%d)      ', [touch.px,touch.py]);
 
152
 
 
153
                if ( touch.x > max_x)   then    max_x := touch.x;
 
154
                if ( touch.y > max_y)           then    max_y := touch.y;
 
155
                if ( touch.px > max_px) then    max_px := touch.px;
 
156
                if ( touch.py > max_py) then    max_py := touch.py;
 
157
 
 
158
                if ( touch.x < min_x)           then    min_x := touch.x;
 
159
                if ( touch.y < min_y)           then    min_y := touch.y;
 
160
                if ( touch.px < min_px) then    min_px := touch.px;
 
161
                if ( touch.py < min_py) then    min_py := touch.py;
 
162
 
 
163
                iprintf(#27 + '[0;0H' + '(%d,%d)      ',[min_px,min_py]);
 
164
                iprintf(#27 + '[1;0H' + '(%d,%d)      ',[min_x,min_y]);
 
165
                iprintf(#27 + '[22;21H' + '(%d,%d)',[max_x,max_y]);
 
166
                iprintf(#27 + '[23;23H' + '(%d,%d)',[max_px,max_py]);
 
167
 
 
168
                OAMCopy[0].st.attribute[2] := 0;
 
169
                OAMCopy[0].st.attribute[1] := ATTR1_SIZE_32 or ((touch.px - 16) and $01FF);
 
170
                OAMCopy[0].st.attribute[0] := ATTR0_COLOR_256 or ATTR0_SQUARE or ((touch.py -16) and $00FF);
 
171
                
 
172
        end;
 
173
 
 
174
end.