SpriteExtendedPalettes.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. program SpriteExtendedPalettes;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9;
  5. var
  6. i: integer;
  7. touch: touchPosition;
  8. gfx1, gfx2: pcuint16;
  9. begin
  10. videoSetMode(MODE_0_2D);
  11. vramSetBankA(VRAM_A_MAIN_SPRITE);
  12. oamInit(oamMain, SpriteMapping_1D_32, true);
  13. gfx1 := oamAllocateGfx(oamMain, SpriteSize_16x16, SpriteColorFormat_256Color);
  14. gfx2 := oamAllocateGfx(oamMain, SpriteSize_16x16, SpriteColorFormat_256Color);
  15. //------------------------------------------------------------------
  16. // notice both sprites are filled with color 1
  17. //------------------------------------------------------------------
  18. for i := 0 to (16 * 16 div 2) - 1 do
  19. begin
  20. gfx1[i] := 1 or (1 shl 8);
  21. gfx2[i] := 1 or (1 shl 8);
  22. end;
  23. //------------------------------------------------------------------
  24. // unlock vram (cannot write to vram while mapped as palette memory)
  25. //------------------------------------------------------------------
  26. vramSetBankF(VRAM_F_LCD);
  27. VRAM_F_EXT_PALETTE^[0][1] := RGB15(31,0,0);
  28. VRAM_F_EXT_PALETTE^[1][1] := RGB15(0,31,0);
  29. // set vram to ex palette
  30. vramSetBankF(VRAM_F_SPRITE_EXT_PALETTE);
  31. while true do
  32. begin
  33. scanKeys();
  34. if (keysHeld() and KEY_TOUCH) <> 0 then
  35. touchRead(touch);
  36. oamSet(oamMain, //main graphics engine context
  37. 0, //oam index (0 to 127)
  38. touch.px, touch.py, //x and y pixle location of the sprite
  39. 0, //priority, lower renders last (on top)
  40. 0, //this is the palette index if multiple palettes or the alpha value if bmp sprite
  41. SpriteSize_16x16,
  42. SpriteColorFormat_256Color,
  43. gfx1, //pointer to the loaded graphics
  44. -1, //sprite rotation data
  45. false, //double the size when rotating?
  46. false, //hide the sprite?
  47. false, false, //vflip, hflip
  48. false //apply mosaic
  49. );
  50. oamSet(oamMain,
  51. 1,
  52. SCREEN_WIDTH - touch.px,
  53. SCREEN_HEIGHT - touch.py,
  54. 0,
  55. 1, //use second palette
  56. SpriteSize_16x16,
  57. SpriteColorFormat_256Color,
  58. gfx2,
  59. -1,
  60. false,
  61. false,
  62. false, false,
  63. false
  64. );
  65. swiWaitForVBlank();
  66. oamUpdate(oamMain);
  67. end;
  68. end.