diff --git a/inc/input.inc b/inc/input.inc deleted file mode 100644 index ca0bc61..0000000 --- a/inc/input.inc +++ /dev/null @@ -1,8 +0,0 @@ -DEF BTN_START EQU $80 -DEF BTN_SELECT EQU $40 -DEF BTN_B EQU $20 -DEF BTN_A EQU $10 -DEF BTN_DOWN EQU $8 -DEF BTN_UP EQU $4 -DEF BTN_LEFT EQU $2 -DEF BTN_RIGHT EQU $1 \ No newline at end of file diff --git a/src/input.s b/src/input.s index 156f17b..f5203ec 100644 --- a/src/input.s +++ b/src/input.s @@ -46,6 +46,10 @@ Keys_Update:: or b ld b, a + ; swap to use flag macros from hardware.inc + ; TODO: optimize this code to avoid swap (very small win) + swap b + ; lastKeys <- keys ; keys <- B ld hl, keys ld a, [hl] diff --git a/src/main.s b/src/main.s index 9db92d4..57bc4d7 100644 --- a/src/main.s +++ b/src/main.s @@ -1,5 +1,4 @@ INCLUDE "hardware.inc" -INCLUDE "input.inc" INCLUDE "util.inc" SECTION "Header", ROM0[$100] @@ -65,7 +64,7 @@ start: ; TODO: remove once scrolling is implemented ; scroll map with arrow keys ld a, [keys] - and BTN_UP + and PADF_UP jr z, .down ; don't scroll up if on last tile @@ -98,7 +97,7 @@ start: .down: ld a, [keys] - and BTN_DOWN + and PADF_DOWN jr z, .right ; don't scroll down if on last tile @@ -131,7 +130,7 @@ start: .right: ld a, [keys] - and BTN_RIGHT + and PADF_RIGHT jr z, .left ld hl, rSCX @@ -140,7 +139,7 @@ start: .left: ld a, [keys] - and BTN_LEFT + and PADF_LEFT jr z, .vbl ld hl, rSCX diff --git a/src/map.s b/src/map.s index 4a1c83f..a340e63 100644 --- a/src/map.s +++ b/src/map.s @@ -96,9 +96,7 @@ Map_Scroll:: cp [hl] jr nz, .scroll_down_check - ; map coords = CURRENT_CAMERA_X, CURRENT_CAMERA_Y - 2 - ; HL = _SCRN0 + 32 * (32 - page_y/8 - 2) - ; TODO: WTF does this shit even do... + ; B = CAMERA_X - SCX/8 ld a, [rSCX] ld b, a ld a, [CURRENT_CAMERA_X] @@ -108,6 +106,7 @@ Map_Scroll:: sub b ld b, a + ; TODO: WTF does this shit even do... ld a, [CURRENT_CAMERA_Y] cp 2 jr c, .done @@ -129,7 +128,8 @@ Map_Scroll:: .loop0: sub 2 - ; hl = _SCRN0 + 32 * a + ; HL = _SCRN0 + 32 * (32 - page_y/8 - 2) + ; HL = _SCRN0 + 32 * A ld e, a ld hl, _SCRN0 .loop: @@ -178,9 +178,13 @@ Map_Scroll:: sub b ld b, a + ; C = CAMERA_Y + 18 + 1 + ; TODO: Figure out if a similar method to this one is sufficient for + ; whatever the fuck the scroll up check is doing ld a, [CURRENT_CAMERA_Y] add SCRN_Y_B + 1 ld c, a + call enqueue_row_write ld a, [PAGEY] diff --git a/src/oam.s b/src/oam.s index b9280a6..a8703dc 100644 --- a/src/oam.s +++ b/src/oam.s @@ -5,7 +5,7 @@ SECTION "OAM Mirror", WRAM0, ALIGN[8] _OAM:: ds OAM_COUNT * sizeof_OAM_ATTRS _OAM_end: -SECTION "OAM DMA routine", ROM0 +SECTION "OAM Code", ROM0 ; Initialize OAM OAM_Init:: diff --git a/src/player.s b/src/player.s index 885117c..e3ba365 100644 --- a/src/player.s +++ b/src/player.s @@ -1,5 +1,4 @@ INCLUDE "hardware.inc" -INCLUDE "input.inc" INCLUDE "oam.inc" INCLUDE "util.inc" @@ -27,6 +26,10 @@ DEF SPRITE_WIDTH EQU 2 DEF SPRITE_HEIGHT EQU 2 DEF PLAYER_SPEED EQU 2 +DEF TILE_WIDTH EQU 8 ; Width of tile in bytes +DEF TILE_HEIGHT EQU 8 ; Height of tile in bytes +DEF TILE_SIZE EQU 16 ; Total length of tile in bytes + DEF GRAVITY EQU (0 << 8) | $2e ; 0.18 DEF INIT_VY EQU (3 << 8) | $99 ; 3.60 DEF INIT_FALL_VY EQU ($ff << 8) | $1a ; a.b @@ -36,7 +39,7 @@ Player_Init:: ld hl, PLAYER_X ld [hl], 0 inc hl - ld [hl], 144-32 + ld [hl], SCRN_Y - SPRITE_HEIGHT * (SCRN_Y - SPRITE_HEIGHT * TILE_HEIGHT) inc hl xor a ld [hl+], a @@ -46,9 +49,9 @@ Player_Init:: ld [hl+], a ; Copy sprite to VRAM - ld bc, _VRAM8000 + SPRITE_IDX * 16 + ld bc, _VRAM8000 + SPRITE_IDX * TILE_SIZE ld hl, spriteData - ld d, 16 * (SPRITE_WIDTH * SPRITE_HEIGHT) + ld d, TILE_SIZE * (SPRITE_WIDTH * SPRITE_HEIGHT) call memcpy ; Initialize OAM entries with player state @@ -59,7 +62,7 @@ Player_Init:: Player_Update:: ; check for jump ld a, [keys] - and BTN_UP + and PADF_UP jr z, .jump_update_check ; initialize jump state if not already jumping @@ -147,7 +150,7 @@ Player_Update:: ; check for move right .right: ld a, [keys] - and BTN_RIGHT + and PADF_RIGHT jr z, .left ; check for right boundary @@ -180,7 +183,7 @@ Player_Update:: ; check for left button ld hl, keys ld a, [hl] - and BTN_LEFT + and PADF_LEFT jr z, .fall ; check for left boundary