PageRenderTime 42ms CodeModel.GetById 15ms app.highlight 24ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/libndsfpc/examples/graphics/Backgrounds/all_in_one/Basic.pp

https://github.com/slibre/freepascal
Puppet | 527 lines | 388 code | 139 blank | 0 comment | 29 complexity | 4d3bc03e8d916e22fd81c28881c9519b MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
  1unit basic;
  2
  3interface
  4
  5uses
  6  ctypes, nds9, scrolling, TextBackgrounds, RotBackgrounds, Multilayer;
  7
  8
  9procedure Text256x256();
 10procedure Text256x512();
 11procedure Text512x256();
 12procedure Text512x512();
 13procedure ExRot128x128();
 14procedure ExRot256x256();
 15procedure ExRot512x512();
 16procedure ExRot1024x1024();
 17procedure Rot128x128();
 18procedure Rot256x256();
 19procedure Rot512x512();
 20procedure Rot1024x1024();
 21procedure Bmp8_128x128();
 22procedure Bmp8_256x256();
 23procedure Bmp8_512x256();
 24procedure Bmp8_512x512();
 25procedure Bmp8_512x1024();
 26procedure Bmp8_1024x512();
 27procedure Bmp16_128x128();
 28procedure Bmp16_512x256();
 29procedure Bmp16_256x256();
 30procedure Bmp16_512x512();
 31
 32
 33
 34implementation
 35
 36procedure Text256x256();
 37var
 38  bg: cint;
 39begin
 40  videoSetMode(MODE_0_2D);
 41  vramSetBankA(VRAM_A_MAIN_BG);
 42
 43  bg := bgInit(0, BgType_Text8bpp, BgSize_T_256x256, 0,1);
 44
 45  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
 46  dmaCopy(@Layer256x256Map, bgGetMapPtr(bg),  Layer256x256MapLen);
 47  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
 48
 49  scroll(bg, 256, 256);
 50end;
 51
 52procedure Text256x512();
 53var
 54  bg: cint;
 55begin
 56  videoSetMode(MODE_0_2D);
 57  vramSetBankA(VRAM_A_MAIN_BG);
 58
 59  bg := bgInit(0, BgType_Text8bpp, BgSize_T_256x512, 0,1);
 60
 61  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
 62  dmaCopy(@Layer256x512Map, bgGetMapPtr(bg),  Layer256x512MapLen);
 63  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
 64
 65  scroll(bg, 256, 512);
 66end;
 67
 68procedure Text512x256();
 69var
 70  bg: cint;
 71  map: pcuint16;
 72  iy, ix: integer;
 73begin
 74  videoSetMode(MODE_0_2D);
 75  vramSetBankA(VRAM_A_MAIN_BG);
 76
 77  bg := bgInit(0, BgType_Text8bpp, BgSize_T_512x256, 0, 1);
 78
 79  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
 80  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
 81
 82  map := pcuint16(bgGetMapPtr(bg));
 83
 84  for iy := 0 to 31 do
 85  begin
 86    //first the left half
 87		dmaCopy(@Layer512x256Map + iy * 64 * 2, @map[iy * 32],  32 * 2);
 88
 89		//then the right half
 90		dmaCopy(@Layer512x256Map + iy * 64 * 2 + 64, @map[(32 * 32) + (iy * 32)],  32 * 2);
 91  end;
 92
 93  scroll(bg, 512, 256);
 94end;
 95
 96procedure Text512x512();
 97var
 98  bg: cint;
 99  map: pcuint16;
100  iy, ix: integer;
101begin
102
103  videoSetMode(MODE_0_2D);
104  vramSetBankA(VRAM_A_MAIN_BG);
105
106  bg := bgInit(0, BgType_Text8bpp, BgSize_T_512x512, 0,1);
107
108  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
109  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
110
111  map := pcuint16(bgGetMapPtr(bg));
112
113  //draw top half
114  for iy := 0 to 31 do
115  begin
116    //first the left half
117    dmaCopy(@Layer512x512Map + iy * 64 * 2, map + iy * 32, 32 * 2);
118
119    //then the right half
120    dmaCopy(@Layer512x512Map + iy * 64 * 2 + 64, map + (32 * 32) + iy * 32, 32 * 2);
121  end;
122
123  map := map + (32 * 32 * 2);
124
125  //draw bottom half
126  for iy := 0 to 31 do
127  begin
128    //copy one line at a time
129    //first the left half
130    dmaCopy(@Layer512x512Map + (iy + 32) * 64 * 2, map + iy * 32,  32 * 2);
131
132    //then the right half
133    dmaCopy(@Layer512x512Map + (iy + 32) * 64 * 2 + 64, map + (32 * 32) + iy * 32,  32 * 2);
134  end;
135
136  scroll(bg, 512, 512);
137end;
138
139procedure ExRot128x128();
140var
141  bg: cint;
142begin
143
144  videoSetMode(MODE_5_2D);
145  vramSetBankA(VRAM_A_MAIN_BG);
146
147  bg := bgInit(3, BgType_ExRotation, BgSize_ER_128x128, 0, 1);
148
149  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
150  dmaCopy(@Layer128x128Map, bgGetMapPtr(bg),  Layer128x128MapLen);
151  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
152
153  scroll(bg, 128, 128);
154end;
155
156procedure ExRot256x256();
157var
158  bg: cint;
159begin
160
161  videoSetMode(MODE_5_2D);
162  vramSetBankA(VRAM_A_MAIN_BG);
163
164  bg := bgInit(3, BgType_ExRotation, BgSize_ER_256x256, 0,1);
165
166  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
167  dmaCopy(@Layer256x256Map, bgGetMapPtr(bg),  Layer256x256MapLen);
168  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
169
170  scroll(bg, 256, 256);
171end;
172
173
174procedure ExRot512x512();
175var
176  bg: cint;
177begin
178
179  videoSetMode(MODE_5_2D);
180  vramSetBankA(VRAM_A_MAIN_BG);
181
182  bg := bgInit(3, BgType_ExRotation, BgSize_ER_512x512, 0,1);
183
184  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
185  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
186  dmaCopy(@Layer512x512Map, bgGetMapPtr(bg),  Layer512x512MapLen);
187
188  scroll(bg, 512, 512);
189end;
190
191procedure ExRot1024x1024();
192var
193  bg: cint;
194begin
195
196  videoSetMode(MODE_5_2D);
197  vramSetBankA(VRAM_A_MAIN_BG);
198
199  bg := bgInit(3, BgType_ExRotation, BgSize_ER_1024x1024, 0,2);
200
201  dmaCopy(@TextBackgroundsTiles, bgGetGfxPtr(bg), sizeof(TextBackgroundsTiles));
202  dmaCopy(@TextBackgroundsPal, BG_PALETTE, sizeof(TextBackgroundsPal));
203  dmaCopy(@Layer1024x1024Map, bgGetMapPtr(bg),  Layer1024x1024MapLen);
204
205  scroll(bg, 1024, 1024);
206end;
207
208procedure Rot128x128();
209var
210  bg: cint;
211begin
212
213  videoSetMode(MODE_2_2D);
214  vramSetBankA(VRAM_A_MAIN_BG);
215
216  bg := bgInit(3, BgType_Rotation, BgSize_R_128x128, 0, 1);
217
218  dmaCopy(@RotBackgroundsTiles, bgGetGfxPtr(bg), sizeof(RotBackgroundsTiles));
219  dmaCopy(@RotBackgroundsPal, BG_PALETTE, sizeof(RotBackgroundsPal));
220  dmaCopy(@Layer128x128rMap, bgGetMapPtr(bg),  Layer128x128rMapLen);
221
222  scroll(bg, 128, 128);
223end;
224
225procedure Rot256x256();
226var
227  bg: cint;
228begin
229
230  videoSetMode(MODE_2_2D);
231  vramSetBankA(VRAM_A_MAIN_BG);
232
233  bg := bgInit(3, BgType_Rotation, BgSize_R_256x256, 0,2);
234
235  dmaCopy(@RotBackgroundsTiles, bgGetGfxPtr(bg), sizeof(RotBackgroundsTiles));
236  dmaCopy(@RotBackgroundsPal, BG_PALETTE, sizeof(RotBackgroundsPal));
237  dmaCopy(@Layer256x256rMap, bgGetMapPtr(bg),  Layer256x256rMapLen);
238
239  scroll(bg, 256, 256);
240end;
241
242
243procedure Rot512x512();
244var
245  bg: cint;
246begin
247
248  videoSetMode(MODE_2_2D);
249  vramSetBankA(VRAM_A_MAIN_BG);
250
251  bg := bgInit(3, BgType_Rotation, BgSize_R_512x512, 0,2);
252
253  dmaCopy(@RotBackgroundsTiles, bgGetGfxPtr(bg), sizeof(RotBackgroundsTiles));
254  dmaCopy(@RotBackgroundsPal, BG_PALETTE, sizeof(RotBackgroundsPal));
255  dmaCopy(@Layer512x512rMap, bgGetMapPtr(bg),  Layer512x512rMapLen);
256
257  scroll(bg, 512, 512);
258end;
259
260procedure Rot1024x1024();
261var
262  bg: cint;
263begin
264
265  videoSetMode(MODE_2_2D);
266  vramSetBankA(VRAM_A_MAIN_BG);
267
268  bg := bgInit(3, BgType_Rotation, BgSize_R_1024x1024, 0,3);
269
270  dmaCopy(@RotBackgroundsTiles, bgGetGfxPtr(bg), sizeof(RotBackgroundsTiles));
271  dmaCopy(@RotBackgroundsPal, BG_PALETTE, sizeof(RotBackgroundsPal));
272  dmaCopy(@Layer1024x1024rMap, bgGetMapPtr(bg),  Layer1024x1024rMapLen);
273
274  scroll(bg, 1024, 1024);
275end;
276
277
278
279procedure Bmp8_128x128();
280var
281  bg: cint;
282  buffer: pcuint16;
283  i, iy, ix: integer;
284begin
285  randomize;
286  videoSetMode(MODE_5_2D);
287  vramSetBankA(VRAM_A_MAIN_BG);
288
289  bg := bgInit(3, BgType_Bmp8, BgSize_B8_128x128,0,0);
290
291  for i := 0 to 255 do
292    BG_PALETTE[i] := random(high(cuint16));
293
294  buffer := pcuint16(bgGetGfxPtr(bg));
295
296  for iy := 0 to 127 do
297    for ix := 0 to (128 div 2) - 1 do
298      buffer[ix + iy * 64] := random(high(cuint16));
299
300  scroll(bg, 128, 128);
301end;
302
303procedure Bmp8_256x256();
304var
305  bg: cint;
306  buffer: pcuint16;
307  i, iy, ix: integer;
308begin
309  randomize;
310  videoSetMode(MODE_5_2D);
311  vramSetBankA(VRAM_A_MAIN_BG);
312
313  bg := bgInit(3, BgType_Bmp8, BgSize_B8_256x256,0,0);
314
315  for i := 0 to 255 do
316    BG_PALETTE[i] := random(high(cuint16));
317
318  buffer := pcuint16(bgGetGfxPtr(bg));
319
320  for iy := 0 to 255 do
321    for ix := 0 to (256 div 2) - 1 do
322      buffer[ix + iy * 128] := random(high(cuint16));
323
324  scroll(bg, 256, 256);
325
326end;
327
328procedure Bmp8_512x256();
329var
330  bg: cint;
331  buffer: pcuint16;
332  iy, ix: integer;
333  i: integer;
334begin
335  randomize;
336  videoSetMode(MODE_5_2D);
337  vramSetBankA(VRAM_A_MAIN_BG);
338
339  bg := bgInit(3, BgType_Bmp8, BgSize_B8_512x256,0,0);
340
341  for i := 0 to 255 do
342    BG_PALETTE[i] := random(high(cuint16));
343
344  buffer := pcuint16(bgGetGfxPtr(bg));
345
346  for iy := 0 to 255 do
347    for ix := 0 to (512 div 2) - 1 do
348      buffer[ix + iy * 256] := random(high(cuint16));
349
350  scroll(bg, 512, 256);
351end;
352
353procedure Bmp8_512x512();
354var
355  bg: cint;
356  buffer: pcuint16;
357  iy, ix: integer;
358  i: integer;
359begin
360  randomize;
361  videoSetMode(MODE_5_2D);
362  vramSetBankA(VRAM_A_MAIN_BG);
363  vramSetBankB(VRAM_B_MAIN_BG);
364
365  bg := bgInit(3, BgType_Bmp8, BgSize_B8_512x512,0,0);
366
367  for i := 0 to 255 do
368    BG_PALETTE[i] := random(high(cuint16));
369
370  buffer := pcuint16(bgGetGfxPtr(bg));
371
372  for iy := 0 to 511 do
373    for ix := 0 to (512 div 2) -1 do
374      buffer[ix + iy * 256] := random(high(cuint16));
375
376  scroll(bg, 512, 512);
377end;
378
379procedure Bmp8_512x1024();
380var
381  bg: cint;
382  buffer: pcuint16;
383  iy, ix: integer;
384  i: integer;
385begin
386  randomize;
387  videoSetMode(MODE_6_2D);
388  vramSetBankA(VRAM_A_MAIN_BG);
389  vramSetBankB(VRAM_B_MAIN_BG);
390  vramSetBankC(VRAM_C_MAIN_BG);
391  vramSetBankD(VRAM_D_MAIN_BG);
392
393  bg := bgInit(2, BgType_Bmp8, BgSize_B8_512x1024,0,0);
394
395  for i := 0 to 255 do
396    BG_PALETTE[i] := random(high(cuint16));
397
398  buffer := pcuint16(bgGetGfxPtr(bg));
399
400  for iy := 0 to 1023 do
401    for ix := 0  to (512 div 2) -1 do
402      buffer[ix + iy * 256] := random(high(cuint16));
403
404  scroll(bg, 512, 1024);
405end;
406
407procedure Bmp8_1024x512();
408var
409  bg: cint;
410  buffer: pcuint16;
411  iy, ix: integer;
412  i: integer;
413begin
414  randomize;
415  videoSetMode(MODE_6_2D);
416  vramSetBankA(VRAM_A_MAIN_BG);
417  vramSetBankB(VRAM_B_MAIN_BG);
418  vramSetBankC(VRAM_C_MAIN_BG);
419  vramSetBankD(VRAM_D_MAIN_BG);
420
421  bg := bgInit(2, BgType_Bmp8, BgSize_B8_1024x512,0,0);
422
423  for i := 0 to 255 do
424    BG_PALETTE[i] := random(high(cuint16));
425
426  buffer := pcuint16(bgGetGfxPtr(bg));
427
428  for iy := 0 to 511 do
429    for ix := 0 to (1024 div 2) -1 do
430      buffer[ix + iy * 512] := random(high(cuint16));
431
432  scroll(bg, 1024, 512);
433end;
434
435procedure Bmp16_128x128();
436var
437  bg: cint;
438  buffer: pcuint16;
439  iy, ix: integer;
440begin
441  randomize;
442  videoSetMode(MODE_5_2D);
443  vramSetBankA(VRAM_A_MAIN_BG);
444
445  bg := bgInit(2, BgType_Bmp16, BgSize_B16_128x128,0,0);
446
447  buffer := pcuint16(bgGetGfxPtr(bg));
448
449  for iy := 0 to 127 do
450    for ix := 0 to 127 do
451      buffer[ix + iy * 128] := random(high(cuint16));
452
453  scroll(bg, 128, 128);
454end;
455
456procedure Bmp16_256x256();
457var
458  bg: cint;
459  buffer: pcuint16;
460  iy, ix: integer;
461begin
462  randomize;
463  videoSetMode(MODE_5_2D);
464  vramSetBankA(VRAM_A_MAIN_BG);
465
466  bg := bgInit(2, BgType_Bmp16, BgSize_B16_256x256,0,0);
467
468
469  buffer := pcuint16(bgGetGfxPtr(bg));
470
471  for iy := 0 to 255 do
472    for ix := 0 to 255 do
473      buffer[ix + iy * 256] := random(high(cuint16));
474
475  scroll(bg, 256, 256);
476end;
477
478procedure Bmp16_512x256();
479var
480  bg: cint;
481  buffer: pcuint16;
482  iy, ix: integer;
483begin
484  randomize;
485  videoSetMode(MODE_5_2D);
486  vramSetBankA(VRAM_A_MAIN_BG);
487  vramSetBankB(VRAM_B_MAIN_BG);
488
489  bg := bgInit(2, BgType_Bmp16, BgSize_B16_512x256,0,0);
490
491
492  buffer := pcuint16(bgGetGfxPtr(bg));
493
494  for iy := 0 to 255 do
495    for ix := 0 to 512 do
496      buffer[ix + iy * 512] := random(high(cuint16));
497
498  scroll(bg, 512, 256);
499end;
500
501procedure Bmp16_512x512();
502var
503  bg: cint;
504  buffer: pcuint16;
505  iy, ix: integer;
506begin
507  randomize;
508  videoSetMode(MODE_5_2D);
509  vramSetBankA(VRAM_A_MAIN_BG);
510  vramSetBankB(VRAM_B_MAIN_BG);
511  vramSetBankC(VRAM_C_MAIN_BG);
512  vramSetBankD(VRAM_D_MAIN_BG);
513
514  bg := bgInit(2, BgType_Bmp16, BgSize_B16_512x512,0,0);
515
516
517  buffer := pcuint16(bgGetGfxPtr(bg));
518
519  for iy := 0 to 511 do
520    for ix := 0 to 511 do
521      buffer[ix + iy * 512] := random(high(cuint16));
522
523  scroll(bg, 512, 512);
524end;
525
526
527end.