lol its in c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.1 KiB

2 years ago
  1. #include "sdk/hardware.h"
  2. #include "sdk/video.h"
  3. #include "sdk/oam.h"
  4. #include "sdk/assets.h"
  5. #include "sdk/joypad.h"
  6. #include <string.h>
  7. ASSET(tiles, "tiles.2bpp");
  8. uint8_t cursor_x = 0;
  9. uint8_t cursor_y = 0;
  10. void main() {
  11. //Load our initial vram (this is slow, but always works, even outside of vblank)
  12. vram_memcpy(0x8000, tiles, tiles_end - tiles);
  13. vram_memcpy(0x9000, tiles, tiles_end - tiles);
  14. //Setup the OAM for sprite drawing
  15. oam_init();
  16. //Set some default DMG palette data
  17. rBGP = 0b11100100;
  18. rOBP0 = 0b11100100;
  19. rOBP1 = 0b11100100;
  20. //Put some sprites on the screen
  21. shadow_oam[0].y = 0x20;
  22. shadow_oam[0].x = 0x20;
  23. shadow_oam[0].tile = 0x04;
  24. shadow_oam[0].attr = 0x00;
  25. shadow_oam[1].y = 0x24;
  26. shadow_oam[1].x = 0x24;
  27. shadow_oam[1].tile = 0x02;
  28. shadow_oam[1].attr = 0x00;
  29. //Make sure sprites and the background are drawn
  30. rLCDC = LCDC_ON | LCDC_OBJON | LCDC_BGON;
  31. //Setup the VBLANK interrupt, but we don't actually enable interrupt handling.
  32. // We only do this, so HALT waits for VBLANK.
  33. rIF = 0;
  34. rIE = IE_VBLANK;
  35. vram_memset(0x9800, 0x05, 32 * 18);
  36. for(uint8_t x=0; x<20; x++) {
  37. vram_set(0x9800 + x, 0x07);
  38. vram_set(0x9A20 + x, 0x07);
  39. }
  40. for(uint8_t y=1; y<18; y++) {
  41. vram_set(0x9800 + y * 0x20, 0x07);
  42. vram_set(0x9800 + 19 + y * 0x20, 0x07);
  43. }
  44. vram_set(0x9800 + 3 + 3 * 0x20, 0x01);
  45. while(1) {
  46. joypad_update();
  47. if (joypad_state & PAD_LEFT) cursor_x --;
  48. if (joypad_state & PAD_RIGHT) cursor_x ++;
  49. if (joypad_state & PAD_UP) cursor_y --;
  50. if (joypad_state & PAD_DOWN) cursor_y ++;
  51. if (joypad_state & (PAD_A | PAD_B)) {
  52. vram_set(0x9800 + cursor_x / 8 + cursor_y / 8 * 0x20, 0x03);
  53. }
  54. // Screen to OAM coordinates
  55. shadow_oam[0].y = cursor_y + 16;
  56. shadow_oam[0].x = cursor_x + 8;
  57. //Wait for VBLANK
  58. HALT();
  59. rIF = 0; //As global interrupts are not enabled, we need to clear the interrupt flag.
  60. //Copy the sprites into OAM memory
  61. oam_dma_copy();
  62. }
  63. }