Skip to content

Commit

Permalink
commit of modified files for rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
LaroldsJubilantJunkyard committed Dec 10, 2023
1 parent 3d72f44 commit 6621833
Show file tree
Hide file tree
Showing 57 changed files with 4,609 additions and 4,609 deletions.
240 changes: 120 additions & 120 deletions galactic-armada/Makefile
Original file line number Diff line number Diff line change
@@ -1,120 +1,120 @@
# You can set the name of the .gb ROM file here
PROJECTNAME = GalacticArmada
SRCDIR = src
LIBDIR = libs
OBJDIR = obj
DSTDIR = dist
RESDIR = $(SRCDIR)/resources
ASMDIR = $(SRCDIR)/main
RESSPRITES = $(RESDIR)/sprites
RESBACKGROUNDS = $(RESDIR)/backgrounds
GENDIR = $(SRCDIR)/generated
GENSPRITES = $(GENDIR)/sprites
GENBACKGROUNDS = $(GENDIR)/backgrounds
BINS = $(DSTDIR)/$(PROJECTNAME).gb

# Tools
RGBDS ?=
ASM := $(RGBDS)rgbasm
GFX := $(RGBDS)rgbgfx
LINK := $(RGBDS)rgblink
FIX := $(RGBDS)rgbfix

# Tool flags
ASMFLAGS := -L
FIXFLAGS := -v -p 0xFF

# https://stackoverflow.com/a/18258352
# Make does not offer a recursive wild card function, so here's one:
rwildcard = $(foreach d,\
$(wildcard $(1:=/*)), \
$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d) \
)

# https://stackoverflow.com/a/16151140
# This makes it so every entry in a space-delimited list appears only once
unique = $(if $1,\
$(firstword $1) $(call unique,$(filter-out $(firstword $1),$1)) \
)

# Collect ASM sources from ASMDIR and LIBDIR.
ASMSOURCES_COLLECTED = \
$(call rwildcard,$(ASMDIR),*.asm) $(call rwildcard,$(LIBDIR),*.asm)

OBJS = $(patsubst %.asm,$(OBJDIR)/%.o,$(notdir $(ASMSOURCES_COLLECTED)))

all: $(BINS)

# ANCHOR: generate-graphics
NEEDED_GRAPHICS = \
$(GENSPRITES)/player-ship.2bpp \
$(GENSPRITES)/enemy-ship.2bpp \
$(GENSPRITES)/bullet.2bpp \
$(GENBACKGROUNDS)/text-font.2bpp \
$(GENBACKGROUNDS)/star-field.tilemap \
$(GENBACKGROUNDS)/title-screen.tilemap

# Generate sprites, ensuring the containing directories have been created.
$(GENSPRITES)/%.2bpp: $(RESSPRITES)/%.png | $(GENSPRITES)
$(GFX) -c "#FFFFFF,#cfcfcf,#686868,#000000;" --columns -o $@ $<

# Generate background tile set, ensuring the containing directories have been created.
$(GENBACKGROUNDS)/%.2bpp: $(RESBACKGROUNDS)/%.png | $(GENBACKGROUNDS)
$(GFX) -c "#FFFFFF,#cbcbcb,#414141,#000000;" -o $@ $<

# Generate background tile map *and* tile set, ensuring the containing directories
# have been created.
$(GENBACKGROUNDS)/%.tilemap: $(RESBACKGROUNDS)/%.png | $(GENBACKGROUNDS)
$(GFX) -c "#FFFFFF,#cbcbcb,#414141,#000000;" \
--tilemap $@ \
--unique-tiles \
-o $(GENBACKGROUNDS)/$*.2bpp \
$<
# ANCHOR_END: generate-graphics

compile.bat: Makefile
@echo "REM Automatically generated from Makefile" > compile.bat
@make -sn | sed y/\\/\\\\/\\\\\\\^/ | grep -v make >> compile.bat


# ANCHOR: generate-objects
# Extract directories from collected ASM sources and append "%.asm" to each one,
# creating a wildcard-rule.
ASMSOURCES_DIRS = $(patsubst %,%%.asm,\
$(call unique,$(dir $(ASMSOURCES_COLLECTED))) \
)

# This is a Makefile "macro".
# It defines a %.o target from a corresponding %.asm, ensuring the
# "prepare" step has ran and the graphics are already generated.
define object-from-asm
$(OBJDIR)/%.o: $1 | $(OBJDIR) $(NEEDED_GRAPHICS)
$$(ASM) $$(ASMFLAGS) -o $$@ $$<
endef

# Run the macro for each directory listed in ASMSOURCES_DIRS, thereby
# creating the appropriate targets.
$(foreach i, $(ASMSOURCES_DIRS), $(eval $(call object-from-asm,$i)))
# ANCHOR_END: generate-objects

# Link and build the final ROM.
$(BINS): $(OBJS) | $(DSTDIR)
$(LINK) -n dist/GalacticArmada.sym -m dist/GalacticArmada.map -o $@ $^
$(FIX) $(FIXFLAGS) $@
# Ensure directories for generated files exist.
define ensure-directory
$1:
mkdir -p $$@
endef

PREPARE_DIRECTORIES = \
$(OBJDIR) $(GENSPRITES) $(GENBACKGROUNDS) $(DSTDIR)

$(foreach i, $(PREPARE_DIRECTORIES), $(eval $(call ensure-directory,$i)))

# Clean up generated directories.
clean:
rm -rfv $(PREPARE_DIRECTORIES)
# Declare these targets as "not actually files".
.PHONY: clean all

# You can set the name of the .gb ROM file here
PROJECTNAME = GalacticArmada
SRCDIR = src
LIBDIR = libs
OBJDIR = obj
DSTDIR = dist
RESDIR = $(SRCDIR)/resources
ASMDIR = $(SRCDIR)/main
RESSPRITES = $(RESDIR)/sprites
RESBACKGROUNDS = $(RESDIR)/backgrounds
GENDIR = $(SRCDIR)/generated
GENSPRITES = $(GENDIR)/sprites
GENBACKGROUNDS = $(GENDIR)/backgrounds
BINS = $(DSTDIR)/$(PROJECTNAME).gb

# Tools
RGBDS ?=
ASM := $(RGBDS)rgbasm
GFX := $(RGBDS)rgbgfx
LINK := $(RGBDS)rgblink
FIX := $(RGBDS)rgbfix

# Tool flags
ASMFLAGS := -L
FIXFLAGS := -v -p 0xFF

# https://stackoverflow.com/a/18258352
# Make does not offer a recursive wild card function, so here's one:
rwildcard = $(foreach d,\
$(wildcard $(1:=/*)), \
$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d) \
)

# https://stackoverflow.com/a/16151140
# This makes it so every entry in a space-delimited list appears only once
unique = $(if $1,\
$(firstword $1) $(call unique,$(filter-out $(firstword $1),$1)) \
)

# Collect ASM sources from ASMDIR and LIBDIR.
ASMSOURCES_COLLECTED = \
$(call rwildcard,$(ASMDIR),*.asm) $(call rwildcard,$(LIBDIR),*.asm)

OBJS = $(patsubst %.asm,$(OBJDIR)/%.o,$(notdir $(ASMSOURCES_COLLECTED)))

all: $(BINS)

# ANCHOR: generate-graphics
NEEDED_GRAPHICS = \
$(GENSPRITES)/player-ship.2bpp \
$(GENSPRITES)/enemy-ship.2bpp \
$(GENSPRITES)/bullet.2bpp \
$(GENBACKGROUNDS)/text-font.2bpp \
$(GENBACKGROUNDS)/star-field.tilemap \
$(GENBACKGROUNDS)/title-screen.tilemap

# Generate sprites, ensuring the containing directories have been created.
$(GENSPRITES)/%.2bpp: $(RESSPRITES)/%.png | $(GENSPRITES)
$(GFX) -c "#FFFFFF,#cfcfcf,#686868,#000000;" --columns -o $@ $<

# Generate background tile set, ensuring the containing directories have been created.
$(GENBACKGROUNDS)/%.2bpp: $(RESBACKGROUNDS)/%.png | $(GENBACKGROUNDS)
$(GFX) -c "#FFFFFF,#cbcbcb,#414141,#000000;" -o $@ $<

# Generate background tile map *and* tile set, ensuring the containing directories
# have been created.
$(GENBACKGROUNDS)/%.tilemap: $(RESBACKGROUNDS)/%.png | $(GENBACKGROUNDS)
$(GFX) -c "#FFFFFF,#cbcbcb,#414141,#000000;" \
--tilemap $@ \
--unique-tiles \
-o $(GENBACKGROUNDS)/$*.2bpp \
$<
# ANCHOR_END: generate-graphics

compile.bat: Makefile
@echo "REM Automatically generated from Makefile" > compile.bat
@make -sn | sed y/\\/\\\\/\\\\\\\^/ | grep -v make >> compile.bat


# ANCHOR: generate-objects
# Extract directories from collected ASM sources and append "%.asm" to each one,
# creating a wildcard-rule.
ASMSOURCES_DIRS = $(patsubst %,%%.asm,\
$(call unique,$(dir $(ASMSOURCES_COLLECTED))) \
)

# This is a Makefile "macro".
# It defines a %.o target from a corresponding %.asm, ensuring the
# "prepare" step has ran and the graphics are already generated.
define object-from-asm
$(OBJDIR)/%.o: $1 | $(OBJDIR) $(NEEDED_GRAPHICS)
$$(ASM) $$(ASMFLAGS) -o $$@ $$<
endef

# Run the macro for each directory listed in ASMSOURCES_DIRS, thereby
# creating the appropriate targets.
$(foreach i, $(ASMSOURCES_DIRS), $(eval $(call object-from-asm,$i)))
# ANCHOR_END: generate-objects

# Link and build the final ROM.
$(BINS): $(OBJS) | $(DSTDIR)
$(LINK) -n dist/GalacticArmada.sym -m dist/GalacticArmada.map -o $@ $^
$(FIX) $(FIXFLAGS) $@
# Ensure directories for generated files exist.
define ensure-directory
$1:
mkdir -p $$@
endef

PREPARE_DIRECTORIES = \
$(OBJDIR) $(GENSPRITES) $(GENBACKGROUNDS) $(DSTDIR)

$(foreach i, $(PREPARE_DIRECTORIES), $(eval $(call ensure-directory,$i)))

# Clean up generated directories.
clean:
rm -rfv $(PREPARE_DIRECTORIES)
# Declare these targets as "not actually files".
.PHONY: clean all

98 changes: 49 additions & 49 deletions galactic-armada/libs/input.asm
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; It's straight from: https://gbdev.io/gb-asm-tutorial/part2/input.html
; In their words (paraphrased): reading player input for gameboy is NOT a trivial task
; So it's best to use some tested code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

include "src/main/includes/hardware.inc"

SECTION "Input", ROM0

Input::

; Save th previous state
ld a, [wCurKeys]
ld [wLastKeys], a
; Poll half the controller
ld a, P1F_GET_BTN
call .onenibble
ld b, a ; B7-4 = 1; B3-0 = unpressed buttons

; Poll the other half
ld a, P1F_GET_DPAD
call .onenibble
swap a ; A3-0 = unpressed directions; A7-4 = 1
xor a, b ; A = pressed buttons + directions
ld b, a ; B = pressed buttons + directions

; And release the controller
ld a, P1F_GET_NONE
ldh [rP1], a

; Combine with previous wCurKeys to make wNewKeys
ld a, [wCurKeys]
xor a, b ; A = keys that changed state
and a, b ; A = keys that changed to pressed
ld [wNewKeys], a
ld a, b
ld [wCurKeys], a
ret

.onenibble
ldh [rP1], a ; switch the key matrix
call .knownret ; burn 10 cycles calling a known ret
ldh a, [rP1] ; ignore value while waiting for the key matrix to settle
ldh a, [rP1]
ldh a, [rP1] ; this read counts
or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys
.knownret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; It's straight from: https://gbdev.io/gb-asm-tutorial/part2/input.html
; In their words (paraphrased): reading player input for gameboy is NOT a trivial task
; So it's best to use some tested code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

include "src/main/includes/hardware.inc"

SECTION "Input", ROM0

Input::

; Save th previous state
ld a, [wCurKeys]
ld [wLastKeys], a
; Poll half the controller
ld a, P1F_GET_BTN
call .onenibble
ld b, a ; B7-4 = 1; B3-0 = unpressed buttons

; Poll the other half
ld a, P1F_GET_DPAD
call .onenibble
swap a ; A3-0 = unpressed directions; A7-4 = 1
xor a, b ; A = pressed buttons + directions
ld b, a ; B = pressed buttons + directions

; And release the controller
ld a, P1F_GET_NONE
ldh [rP1], a

; Combine with previous wCurKeys to make wNewKeys
ld a, [wCurKeys]
xor a, b ; A = keys that changed state
and a, b ; A = keys that changed to pressed
ld [wNewKeys], a
ld a, b
ld [wCurKeys], a
ret

.onenibble
ldh [rP1], a ; switch the key matrix
call .knownret ; burn 10 cycles calling a known ret
ldh a, [rP1] ; ignore value while waiting for the key matrix to settle
ldh a, [rP1]
ldh a, [rP1] ; this read counts
or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys
.knownret
ret
Loading

0 comments on commit 6621833

Please sign in to comment.