commit e9e4b2badfed103ea889d51d77cc71a36717a8cd Author: Forest Belton Date: Fri Sep 24 04:21:21 2021 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..96e0439 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +_build +*.gb +*.map +*.sym + diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d27307c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "gbsdk"] + path = gbsdk + url = git@github.com:daid/gbsdk.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..be7d0ac --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +# Name of your project, will set the name of your ROM. +PROJECT_NAME := Template +# Run "rgbfix --mbc-type help" for possible MBC types +MBC := ROM +# Target should be a combination of DMG, CGB and SGB +TARGETS := DMG + +include gbsdk/rules.mk diff --git a/assets/tiles.png b/assets/tiles.png new file mode 100644 index 0000000..97f5df9 Binary files /dev/null and b/assets/tiles.png differ diff --git a/gbsdk b/gbsdk new file mode 160000 index 0000000..ac612c4 --- /dev/null +++ b/gbsdk @@ -0,0 +1 @@ +Subproject commit ac612c4c1a416d7b5cc42859e3dcc37f0d23dc77 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..492a958 --- /dev/null +++ b/src/main.c @@ -0,0 +1,76 @@ +#include "sdk/hardware.h" +#include "sdk/video.h" +#include "sdk/oam.h" +#include "sdk/assets.h" +#include "sdk/joypad.h" +#include + +ASSET(tiles, "tiles.2bpp"); + +uint8_t cursor_x = 0; +uint8_t cursor_y = 0; + + +void main() { + //Load our initial vram (this is slow, but always works, even outside of vblank) + vram_memcpy(0x8000, tiles, tiles_end - tiles); + vram_memcpy(0x9000, tiles, tiles_end - tiles); + //Setup the OAM for sprite drawing + oam_init(); + + //Set some default DMG palette data + rBGP = 0b11100100; + rOBP0 = 0b11100100; + rOBP1 = 0b11100100; + + //Put some sprites on the screen + shadow_oam[0].y = 0x20; + shadow_oam[0].x = 0x20; + shadow_oam[0].tile = 0x04; + shadow_oam[0].attr = 0x00; + shadow_oam[1].y = 0x24; + shadow_oam[1].x = 0x24; + shadow_oam[1].tile = 0x02; + shadow_oam[1].attr = 0x00; + + //Make sure sprites and the background are drawn + rLCDC = LCDC_ON | LCDC_OBJON | LCDC_BGON; + + //Setup the VBLANK interrupt, but we don't actually enable interrupt handling. + // We only do this, so HALT waits for VBLANK. + rIF = 0; + rIE = IE_VBLANK; + + vram_memset(0x9800, 0x05, 32 * 18); + for(uint8_t x=0; x<20; x++) { + vram_set(0x9800 + x, 0x07); + vram_set(0x9A20 + x, 0x07); + } + for(uint8_t y=1; y<18; y++) { + vram_set(0x9800 + y * 0x20, 0x07); + vram_set(0x9800 + 19 + y * 0x20, 0x07); + } + vram_set(0x9800 + 3 + 3 * 0x20, 0x01); + + while(1) { + joypad_update(); + if (joypad_state & PAD_LEFT) cursor_x --; + if (joypad_state & PAD_RIGHT) cursor_x ++; + if (joypad_state & PAD_UP) cursor_y --; + if (joypad_state & PAD_DOWN) cursor_y ++; + if (joypad_state & (PAD_A | PAD_B)) { + vram_set(0x9800 + cursor_x / 8 + cursor_y / 8 * 0x20, 0x03); + } + + // Screen to OAM coordinates + shadow_oam[0].y = cursor_y + 16; + shadow_oam[0].x = cursor_x + 8; + + //Wait for VBLANK + HALT(); + rIF = 0; //As global interrupts are not enabled, we need to clear the interrupt flag. + + //Copy the sprites into OAM memory + oam_dma_copy(); + } +}