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;
27
OAMCopy[i].st.attribute[0] := ATTR0_DISABLED;
30
//---------------------------------------------------------------------------------
31
procedure updateOAM();
33
dmaCopy(@OAMCopy, OAM, sizeof(OAMCopy));
38
TTouchType = (ttContinuous, ttSingle);
42
TouchType: TTouchType = ttContinuous;
45
//---------------------------------------------------------------------------------
46
function Vblank(): pointer;
48
//---------------------------------------------------------------------------------
54
min_x, min_y, max_x, max_y: integer;
55
min_px, min_py, max_px, max_py: integer;
58
pressed, held: integer;
71
powerON(POWER_ALL_2D);
73
// put the main screen on the bottom lcd
76
// Initialise the interrupt system
78
// install our simple vblank handler
79
irqSet(IRQ_VBLANK, @Vblank);
80
// enable the interrupt
81
irqEnable(IRQ_VBLANK);
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
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
97
// Sprite initialisation
99
SPRITE_PALETTE[i] := u32(ballpalette_bin[i]);
101
for i := 0 to 32*16 - 1 do
102
SPRITE_GFX[i] := u32(balldata_bin[i]);
105
BG_PALETTE[0] := (RGB15(0,0,0));
107
BG0_CR^ := BG_MAP_BASE(31);//use bg0 for the text
109
BG_PALETTE[255] := (RGB15(31,31,31));//by default font rendered with color 255
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);
115
printf(#27 + '[4;8H' + 'Touch Screen Test');
116
printf(#27 + '[15;4H' + 'Right Shoulder toggles');
123
// read the button states
126
// read the touchscreen coordinates
127
touch := touchReadXY();
129
pressed := keysDown(); // buttons pressed this loop
130
held := keysHeld(); // buttons currently held
132
// Right Shoulder button toggles the mode
133
if ( pressed and KEY_R) <> 0 then Inc(TouchType);
135
if TouchType = ttContinuous then
136
printf(#27 + '[14;4H' + 'Touch mode: CONTINUOUS ')
138
printf(#27 + '[14;4H' + 'Touch mode: SINGLE SHOT');
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]);
144
iprintf(#27 + '[0;18H' + 'keys: %08X' + #10, [keysHeld()]);
145
iprintf(#27 + '[9;10H' + 'Frame %d' + #10, [frame]);
147
if (TouchType = ttSingle) and not ( (pressed and KEY_TOUCH) <> 0) then continue;
149
if ((held and KEY_TOUCH)<0) or (touch.x = 0) or (touch.y = 0) then continue;
151
iprintf(#27 + '[12;12H' + '(%d,%d) ', [touch.px,touch.py]);
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;
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;
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]);
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);