Browse Source

Initial commit

master
Forest Belton 2 years ago
commit
e9e4b2badf
7 changed files with 117 additions and 0 deletions
  1. +5
    -0
      .gitignore
  2. +3
    -0
      .gitmodules
  3. +24
    -0
      LICENSE
  4. +8
    -0
      Makefile
  5. BIN
      assets/tiles.png
  6. +1
    -0
      gbsdk
  7. +76
    -0
      src/main.c

+ 5
- 0
.gitignore View File

@ -0,0 +1,5 @@
_build
*.gb
*.map
*.sym

+ 3
- 0
.gitmodules View File

@ -0,0 +1,3 @@
[submodule "gbsdk"]
path = gbsdk
url = git@github.com:daid/gbsdk.git

+ 24
- 0
LICENSE View File

@ -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 <https://unlicense.org>

+ 8
- 0
Makefile View File

@ -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

BIN
assets/tiles.png View File

Before After
Width: 32  |  Height: 32  |  Size: 245 B

+ 1
- 0
gbsdk

@ -0,0 +1 @@
Subproject commit ac612c4c1a416d7b5cc42859e3dcc37f0d23dc77

+ 76
- 0
src/main.c View File

@ -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 <string.h>
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();
}
}

Loading…
Cancel
Save