Browse Source

Partition tile data and add font

master
Forest Belton 3 years ago
parent
commit
ce2337d732
7 changed files with 3235 additions and 25 deletions
  1. +56
    -0
      inc/font.inc
  2. +14
    -5
      inc/game.inc
  3. +3117
    -0
      inc/ibmpc1.inc
  4. +26
    -0
      src/font.s
  5. +2
    -0
      src/game.s
  6. +11
    -6
      src/map.s
  7. +9
    -14
      src/player.s

+ 56
- 0
inc/font.inc View File

@ -0,0 +1,56 @@
IF !DEF(FONT_INC)
DEF FONT_INC EQU 1
INCLUDE "ibmpc1.inc"
MACRO FONT_TILE_DATA
chr_IBMPC1 $20, $20
chr_IBMPC1 $2e, $2e
chr_IBMPC1 $3f, $3f
chr_IBMPC1 $30, $39
chr_IBMPC1 $41, $5a
ENDM
NEWCHARMAP IBMPC1
CHARMAP " ", $0
CHARMAP ".", $1
CHARMAP "?", $2
CHARMAP "0", $3
CHARMAP "1", $4
CHARMAP "2", $5
CHARMAP "3", $6
CHARMAP "4", $7
CHARMAP "5", $8
CHARMAP "6", $9
CHARMAP "7", $a
CHARMAP "8", $b
CHARMAP "9", $c
CHARMAP "A", $d
CHARMAP "B", $e
CHARMAP "C", $f
CHARMAP "D", $10
CHARMAP "E", $11
CHARMAP "F", $12
CHARMAP "G", $13
CHARMAP "H", $14
CHARMAP "I", $15
CHARMAP "J", $16
CHARMAP "K", $17
CHARMAP "L", $18
CHARMAP "M", $19
CHARMAP "N", $1a
CHARMAP "O", $1b
CHARMAP "P", $1c
CHARMAP "Q", $1d
CHARMAP "R", $1e
CHARMAP "S", $1f
CHARMAP "T", $20
CHARMAP "U", $21
CHARMAP "V", $22
CHARMAP "W", $23
CHARMAP "X", $24
CHARMAP "Y", $25
CHARMAP "Z", $26
ENDC

+ 14
- 5
inc/game.inc View File

@ -1,3 +1,6 @@
IF !DEF(GAME_INC)
DEF GAME_INC EQU 1
; Game states
DEF GAME_STATEF_TITLE EQU (1 << 0)
DEF GAME_STATEF_GAME EQU (1 << 1)
@ -7,7 +10,11 @@ DEF PLAYER_STATEF_WALK EQU (1 << 0)
DEF PLAYER_STATEF_JUMP EQU (1 << 1)
; Tile data allocations
DEF ALLOC_SIZE_FONT EQU 37
DEF TILE_SIZE EQU 16
DEF TILE_WIDTH EQU 8 ; Width of tile in bytes
DEF TILE_HEIGHT EQU 8 ; Height of tile in bytes
DEF ALLOC_SIZE_FONT EQU 39
DEF ALLOC_SIZE_PLAYER EQU 52
DEF ALLOC_SIZE_BACKGROUND EQU 32
DEF ALLOC_SIZE_ITEMS EQU 20
@ -19,8 +26,10 @@ DEF TILE_INDEX_BACKGROUND EQU ALLOC_SIZE_FONT + ALLOC_SIZE_PLAYER
DEF TILE_INDEX_ITEMS EQU ALLOC_SIZE_FONT + ALLOC_SIZE_PLAYER + ALLOC_SIZE_BACKGROUND
DEF TILE_INDEX_MONSTERS EQU ALLOC_SIZE_FONT + ALLOC_SIZE_PLAYER + ALLOC_SIZE_BACKGROUND + ALLOC_SIZE_ITEMS
ASSERT TILE_INDEX_PLAYER == 37
ASSERT TILE_INDEX_BACKGROUND == 89
ASSERT TILE_INDEX_ITEMS == 121
ASSERT TILE_INDEX_MONSTERS == 141
ASSERT TILE_INDEX_PLAYER == 39
ASSERT TILE_INDEX_BACKGROUND == 91
ASSERT TILE_INDEX_ITEMS == 123
ASSERT TILE_INDEX_MONSTERS == 143
ASSERT TILE_INDEX_MONSTERS + ALLOC_SIZE_MONSTERS < 256
ENDC

+ 3117
- 0
inc/ibmpc1.inc
File diff suppressed because it is too large
View File


+ 26
- 0
src/font.s View File

@ -0,0 +1,26 @@
INCLUDE "font.inc"
INCLUDE "game.inc"
INCLUDE "hardware.inc"
SECTION "Font Data", ROM0
fontTiles:: FONT_TILE_DATA
fontTilesEnd::
SECTION "Font Code", ROM0
Font_Init::
; copy font to tile VRAM. font data must be doubled to render correctly
ld hl, _VRAM + TILE_INDEX_FONT * TILE_SIZE
ld de, fontTiles
ld bc, fontTilesEnd - fontTiles
.loop:
ld a, [de]
ld [hli], a
ld [hli], a
inc de
dec bc
ld a, b
or c
jr nz, .loop
ret

+ 2
- 0
src/game.s View File

@ -14,6 +14,8 @@ Game_Start::
call Player_Init
call Font_Init
; re-enable ldc & interrupts
ld hl, rLCDC
set 7, [hl]

+ 11
- 6
src/map.s View File

@ -1,3 +1,4 @@
INCLUDE "game.inc"
INCLUDE "hardware.inc"
INCLUDE "util.inc"
@ -76,7 +77,7 @@ Map_Load::
ld a, [CURRENT_TILE_SIZE]
ld d, a
ld hl, _VRAM
ld hl, _VRAM + TILE_INDEX_BACKGROUND * TILE_SIZE
MEMCPY hl, bc, d
; Write initial map data
@ -604,7 +605,7 @@ enqueue_row_write:
ret z
; *ROW++ = 0
xor a
ld a, TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -627,6 +628,7 @@ enqueue_row_write:
; *ROW++ = *MAP++
ld a, [hl+]
add TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -642,7 +644,7 @@ enqueue_row_write:
ret z
; *ROW++ = 0
xor a
ld a, TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -731,7 +733,7 @@ enqueue_col_write:
ret z
; *ROW++ = 0
xor a
ld a, TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -773,6 +775,7 @@ enqueue_col_write:
; *ROW++ = *MAP
ld a, [hl]
add TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -792,7 +795,7 @@ enqueue_col_write:
ret z
; *ROW++ = 0
xor a
ld a, TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -881,6 +884,7 @@ init_row_write:
ret z
; *ROW++ = 0
ld a, TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -903,6 +907,7 @@ init_row_write:
; *ROW++ = *MAP++
ld a, [hl+]
add TILE_INDEX_BACKGROUND
ld [de], a
inc de
@ -918,7 +923,7 @@ init_row_write:
ret z
; *ROW++ = 0
xor a
ld a, TILE_INDEX_BACKGROUND
ld [de], a
inc de

+ 9
- 14
src/player.s View File

@ -21,15 +21,10 @@ spriteData:
INCBIN "png/sprite/player.2bpp"
DEF SPRITE_OAM_IDX EQU 0
DEF SPRITE_IDX EQU 32 ; tile index, rename later
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 ; -1.1015625
@ -44,7 +39,7 @@ Player_Init::
ENDR
; Copy sprite to VRAM
ld bc, _VRAM8000 + SPRITE_IDX * TILE_SIZE
ld bc, _VRAM8000 + TILE_INDEX_PLAYER * TILE_SIZE
ld hl, spriteData
ld d, TILE_SIZE * (SPRITE_WIDTH * SPRITE_HEIGHT)
call memcpy
@ -268,7 +263,7 @@ Player_UpdateOAM::
ld [hli], a
ld [hl], b
inc hl
ld [hl], SPRITE_IDX
ld [hl], TILE_INDEX_PLAYER
inc hl
ld [hl], c
inc hl
@ -283,7 +278,7 @@ Player_UpdateOAM::
ld [hli], a
ld [hl], b
inc hl
ld [hl], SPRITE_IDX + 1
ld [hl], TILE_INDEX_PLAYER + 1
inc hl
ld [hl], c
inc hl
@ -299,7 +294,7 @@ Player_UpdateOAM::
ld [hli], a
ld [hl], b
inc hl
ld [hl], SPRITE_IDX + 2
ld [hl], TILE_INDEX_PLAYER + 2
inc hl
ld [hl], c
inc hl
@ -314,7 +309,7 @@ Player_UpdateOAM::
ld [hli], a
ld [hl], b
inc hl
ld [hl], SPRITE_IDX + 3
ld [hl], TILE_INDEX_PLAYER + 3
inc hl
ld [hl], c
@ -325,16 +320,16 @@ Player_UpdateOAM::
; TODO: Can be sped up by using LD A, [NN]
ld_OAM_tile hl, SPRITE_OAM_IDX
ld [hl], SPRITE_IDX + 1
ld [hl], TILE_INDEX_PLAYER + 1
ld_OAM_tile hl, SPRITE_OAM_IDX + 1
ld [hl], SPRITE_IDX
ld [hl], TILE_INDEX_PLAYER
ld_OAM_tile hl, SPRITE_OAM_IDX + 2
ld [hl], SPRITE_IDX + 3
ld [hl], TILE_INDEX_PLAYER + 3
ld_OAM_tile hl, SPRITE_OAM_IDX + 3
ld [hl], SPRITE_IDX + 2
ld [hl], TILE_INDEX_PLAYER + 2
.done:
ret

Loading…
Cancel
Save