Browse Source

Small cleanup

master
Forest Belton 2 years ago
parent
commit
162c8cd88b
6 changed files with 27 additions and 25 deletions
  1. +0
    -8
      inc/input.inc
  2. +4
    -0
      src/input.s
  3. +4
    -5
      src/main.s
  4. +8
    -4
      src/map.s
  5. +1
    -1
      src/oam.s
  6. +10
    -7
      src/player.s

+ 0
- 8
inc/input.inc View File

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

+ 4
- 0
src/input.s View File

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

+ 4
- 5
src/main.s View File

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

+ 8
- 4
src/map.s View File

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

+ 1
- 1
src/oam.s View File

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

+ 10
- 7
src/player.s View File

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

Loading…
Cancel
Save