Permalink
Browse files

A whole lot of refactoring and optimization.

Specifically, the parallax scrolling routines were changed to make
physical sense, sprite rendering was changed to a mapping-based
system with animation definitions, some redundant and misplaced
operations in main were removed or moved out of vblank, a
visible objects bitfield and counter were added to HiRAM, the
character graphics struct was removed entirely, and several ASM
micro-optimizations were made everywhere.
  • Loading branch information...
InvisibleUp committed Jun 24, 2018
1 parent 7e5b3bb commit 2e5e5b7436e824a1aa4265ffc971dc00425f7eae
Showing with 432 additions and 376 deletions.
  1. +31 −8 src/background.z80
  2. +68 −32 src/gfxinclude.z80
  3. +61 −76 src/main.z80
  4. +28 −24 src/math.z80
  5. +42 −0 src/objects.z80
  6. +167 −202 src/sprites.z80
  7. +35 −34 src/variables.z80
@@ -1,6 +1,17 @@
; Update parallax background timers
; Run once per increment of ScrollX
incParallax:
incFieldX:
ld hl, FieldX
ld a, [hl+]
ld d, a
ld a, [hl]
ld e, a
dec de
ld a, e
ld [hl-], a
ld a, d
ld [hl], a

ld a, [GlobalTimer]
ld b, a
ld hl, ParallaxLayer1
@@ -14,20 +25,31 @@ incParallax:
inc hl
ld b, a
call Modulo3
sub a, 0
or a
jr nz, .Layer3
inc [hl]
.Layer3:
inc hl
bit 0, a
jr nz, .return
rra
jr c, .return
inc [hl]
.return:
ret

; Update parallax background timers
; Run once per decrement of ScrollX
decParallax:
decFieldX:
ld hl, FieldX
ld a, [hl+]
ld d, a
ld a, [hl]
ld e, a
inc de
ld a, e
ld [hl-], a
ld a, d
ld [hl], a

ld a, [GlobalTimer]
ld b, a
ld hl, ParallaxLayer1
@@ -41,13 +63,13 @@ decParallax:
inc hl
ld b, a
call Modulo3
sub a, 0
or a
jr nz, .Layer3
dec [hl]
.Layer3:
inc hl
bit 0, a
jr nz, .return
rra
jr c, .return
dec [hl]
.return:
ret
@@ -93,6 +115,7 @@ scrollLayer:
pop af
reti

; Call this after every VBlank
resetScrollLayer:
; Reset scroll register
; ld hl, ParallaxLayer1
@@ -49,51 +49,87 @@ arcticfox_metadata_left EQU %110000

mappings_arcticfox_standing_right:
DB 4 ; length
DB arcticfox_standing_tile+0, -16, -8, arcticfox_metadata_right ; Top-left
DB arcticfox_standing_tile+1, 0, -8, arcticfox_metadata_right ; Bottom-left
DB arcticfox_standing_tile+2, -16, 0, arcticfox_metadata_right ; Top-right
DB arcticfox_standing_tile+3, 0, 0, arcticfox_metadata_right ; Bottom-right
DB -16, -8, arcticfox_standing_tile+0, arcticfox_metadata_right ; Top-left
DB 0, -8, arcticfox_standing_tile+2, arcticfox_metadata_right ; Bottom-left
DB -16, 0, arcticfox_standing_tile+4, arcticfox_metadata_right ; Top-right
DB 0, 0, arcticfox_standing_tile+6, arcticfox_metadata_right ; Bottom-right

mappings_arcticfox_standing_left:
DB 4 ; length
DB arcticfox_standing_tile+0, 16, 0, arcticfox_metadata_left ; Top-right
DB arcticfox_standing_tile+1, 0, 0, arcticfox_metadata_left ; Bottom-right
DB arcticfox_standing_tile+2, 16, -8, arcticfox_metadata_left ; Top-left
DB arcticfox_standing_tile+3, 0, -8, arcticfox_metadata_left ; Bottom-left

DB 0, 0, arcticfox_standing_tile+0, arcticfox_metadata_left ; Top-right
DB 16, 0, arcticfox_standing_tile+2, arcticfox_metadata_left ; Bottom-right
DB 0, -8, arcticfox_standing_tile+4, arcticfox_metadata_left ; Top-left
DB 16, -8, arcticfox_standing_tile+6, arcticfox_metadata_left ; Bottom-left
mappings_arcticfox_tail_right_1
DB arcticfox_tail_tile+0, -16, -32, arcticfox_metadata_right ; Tail left
DB arcticfox_tail_tile+1, -16, -16, arcticfox_metadata_right ; Tail right

DB 2
DB -16, -32, arcticfox_tail_tile+0, arcticfox_metadata_right ; Tail left
DB -16, -16, arcticfox_tail_tile+2, arcticfox_metadata_right ; Tail right

mappings_arcticfox_tail_right_2
DB arcticfox_tail_tile+2, -16, -32, arcticfox_metadata_right ; Tail left
DB arcticfox_tail_tile+3, -16, -16, arcticfox_metadata_right ; Tail right

DB 2
DB -16, -32, arcticfox_tail_tile+4, arcticfox_metadata_right ; Tail left
DB -16, -16, arcticfox_tail_tile+6, arcticfox_metadata_right ; Tail right

mappings_arcticfox_tail_right_3
DB arcticfox_tail_tile+4, -16, -32, arcticfox_metadata_right ; Tail left
DB arcticfox_tail_tile+5, -16, -16, arcticfox_metadata_right ; Tail right

DB 2
DB -16, -32, arcticfox_tail_tile+8, arcticfox_metadata_right ; Tail left
DB -16, -16, arcticfox_tail_tile+10, arcticfox_metadata_right ; Tail right

mappings_arcticfox_tail_right_4
DB arcticfox_tail_tile+6, -16, -32, arcticfox_metadata_right ; Tail left
DB arcticfox_tail_tile+7, -16, -16, arcticfox_metadata_right ; Tail right

DB 2
DB -16, -32, arcticfox_tail_tile+12, arcticfox_metadata_right ; Tail left
DB -16, -16, arcticfox_tail_tile+14, arcticfox_metadata_right ; Tail right

mappings_arcticfox_tail_left_1
DB arcticfox_tail_tile+0, 16, 16, arcticfox_metadata_left ; Tail right
DB arcticfox_tail_tile+1, 16, 8, arcticfox_metadata_left ; Tail left

DB 2
DB 16, 8, arcticfox_tail_tile+0, arcticfox_metadata_left ; Tail right
DB 16, 0, arcticfox_tail_tile+2, arcticfox_metadata_left ; Tail left

mappings_arcticfox_tail_left_2
DB arcticfox_tail_tile+2, 16, 16, arcticfox_metadata_left ; Tail right
DB arcticfox_tail_tile+3, 16, 8, arcticfox_metadata_left ; Tail left

DB 2
DB 16, 8, arcticfox_tail_tile+4, arcticfox_metadata_left ; Tail right
DB 16, 0, arcticfox_tail_tile+6, arcticfox_metadata_left ; Tail left

mappings_arcticfox_tail_left_3
DB arcticfox_tail_tile+4, 16, 16, arcticfox_metadata_left ; Tail right
DB arcticfox_tail_tile+5, 16, 8, arcticfox_metadata_left ; Tail left

DB 2
DB 16, 8, arcticfox_tail_tile+8, arcticfox_metadata_left ; Tail right
DB 16, 0, arcticfox_tail_tile+10, arcticfox_metadata_left ; Tail left

mappings_arcticfox_tail_left_4
DB arcticfox_tail_tile+6, 16, 16, arcticfox_metadata_left ; Tail right
DB arcticfox_tail_tile+7, 16, 8, arcticfox_metadata_left ; Tail left
DB 2
DB 16, 8, arcticfox_tail_tile+12, arcticfox_metadata_left ; Tail right
DB 16, 0, arcticfox_tail_tile+14, arcticfox_metadata_left ; Tail left

mappings_end:

animations_start:

animations_arcticfox_standing:
DB 2 ; Number of sprites
DB 4 ; Number of frames
DB 0 ; Loop Action (bit7=0: go to frame bit0-6; bit7=1; go to anim bit0-6 frame 0)
DB 8 ; sprites * frames
; Left
DW mappings_arcticfox_standing_left, mappings_arcticfox_standing_left
DW mappings_arcticfox_standing_left, mappings_arcticfox_standing_left

DW mappings_arcticfox_tail_left_1, mappings_arcticfox_tail_left_2
DW mappings_arcticfox_tail_left_3, mappings_arcticfox_tail_left_4

; Right
DW mappings_arcticfox_standing_right, mappings_arcticfox_standing_right
DW mappings_arcticfox_standing_right, mappings_arcticfox_standing_right

DW mappings_arcticfox_tail_right_1, mappings_arcticfox_tail_right_2
DW mappings_arcticfox_tail_right_3, mappings_arcticfox_tail_right_4

animations_end:

animations_pointers_start:
DW animations_arcticfox_standing
animations_pointers_end:

; BACKGROUNDS
bg_start:

Oops, something went wrong.

0 comments on commit 2e5e5b7

Please sign in to comment.