Skip to content

Commit

Permalink
Various GBA Fixes/Improvements - Pre NDS port (#52)
Browse files Browse the repository at this point in the history
* Use header files instead of externs with proper Makefile dependencies
* Fix issue with not being able to quit monoscope
* Fix issue with monoscope turning green after pressing start
* Fix possible issue with pressing START while DMAs are active
* Have top pixel of Hill Zone Scroll Test also scroll
* Fix issue with bad sprite when changing image in Shadow Sprite
* Change .cS to .s

[Confession from Pino: Yes, it appears I'm that sloppy and
that I've treated the GBA as a red-headed stepchild.]
  • Loading branch information
Lorenzooone authored Mar 18, 2024
1 parent 7eb6842 commit ca14773
Show file tree
Hide file tree
Showing 20 changed files with 99 additions and 140 deletions.
23 changes: 12 additions & 11 deletions gba/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ GRAPHICS := tilesets ../common/tilesets
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
DEFINES := -D__GBA__
ARCH := -mthumb -mthumb-interwork

CFLAGS := -g -Wall -O2 -fno-common\
-mcpu=arm7tdmi -mtune=arm7tdmi\
$(ARCH)
$(ARCH) $(DEFINES)

CFLAGS += $(INCLUDE)

CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

ASFLAGS := -g $(ARCH)
ASFLAGS := -g $(ARCH) $(DEFINES) -x assembler-with-cpp
LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $*.map)

#---------------------------------------------------------------------------------
Expand Down Expand Up @@ -90,13 +91,13 @@ CFILES := \
shadowsprite.c stopwatch.c soundtest.c audiosync.c backlight.c megaton.c \
pads.c ppuclear.c vwfdraw.c vwflabels.c undte.c rand.c 4bcanvas.c
CPPFILES :=
SFILES := \
posprintf.s \
S_H_SFILES := \
bggfx_chr.s spritegfx_chr.s monoscope_chr.s sharpness_chr.s \
stopwatchface_chr.s stopwatchhand_chr.s stopwatchdigits_chr.s \
kikimap_chr.s kikitiles_chr.s greenhillzone_chr.s hepsie_chr.s \
Gus_portrait_chr.s convergence_chr.s pluge_shark_6color_chr.s \
vwf7.s helppages.s helpbgtiles_chr.s helpsprites_chr.s Donna_chr.s
helpbgtiles_chr.s helpsprites_chr.s Donna_chr.s vwf7.s helppages.s
SFILES := posprintf.s

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
Expand All @@ -114,11 +115,11 @@ endif

export OFILES_BIN := $(addsuffix .o,$(BINFILES))

export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) $(S_H_SFILES:.s=.o)

export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)

export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) $(subst .s,.h,$(S_H_SFILES))

export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
Expand Down Expand Up @@ -172,8 +173,8 @@ $(OFILES_SOURCES) : $(HFILES)
grit $< -ff$(word 2,$^) -fts -o$*_chr

# Convert a proportional font
vwf7.s: vwf7_cp144p.png ../tools/vwfbuild.py last-commit
$(PY) ../tools/vwfbuild.py $< $@
vwf7.s vwf7.h: vwf7_cp144p.png ../tools/vwfbuild.py last-commit
$(PY) ../tools/vwfbuild.py $< $(basename $@).s $(basename $@).h

# Update last-commit if it has changed
last-commit-now:
Expand All @@ -183,8 +184,8 @@ last-commit: last-commit-now
cmp $< $@ || cp $< $@

# Convert help files
helppages.s: helppages.txt last-commit ../tools/paginate_help.py
$(PY) ../tools/paginate_help.py -DCOMMIT="$$(cat last-commit)" $< -o $@
helppages.s helppages.h: helppages.txt last-commit ../tools/paginate_help.py
$(PY) ../tools/paginate_help.py -DCOMMIT="$$(cat last-commit)" $< -o $(basename $@).s -oh $(basename $@).h

-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion gba/src/audiosync.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_sound.h>
#include <gba_input.h>

extern const unsigned char helpsect_audio_sync[];
#define PFMAP 23

static const BarsListEntry audiosync_rects[] = {
Expand Down
2 changes: 0 additions & 2 deletions gba/src/backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_video.h>
#include <gba_input.h>

extern const unsigned char helpsect_backlight_zones[];

void activity_backlight_zone(void) {
unsigned inverted = 0, hidden = 0, high_gear = 0, held_keys = 0, sz = 1;
unsigned int x = 119, y = 79;
Expand Down
5 changes: 3 additions & 2 deletions gba/src/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sys/types.h>
#include <gba_sprites.h>
#include <gba_systemcalls.h>
#include "helppages.h"

// Size of a statically sized array
#define count(array) (sizeof((array)) / sizeof((array)[0]))
Expand All @@ -34,8 +35,8 @@ typedef void (*activity_func)(void);
extern char help_line_buffer[HELP_LINE_LEN];
extern unsigned char help_bg_loaded, help_wanted_page, help_cursor_y;
extern signed char help_wnd_progress;
unsigned int helpscreen(unsigned int doc_num, unsigned int keymask);
unsigned int read_pad_help_check(const void *doc_num_as_ptr);
unsigned int helpscreen(helpdoc_kind doc_num, unsigned int keymask);
unsigned int read_pad_help_check(helpdoc_kind doc_num);

// stills.c

Expand Down
25 changes: 10 additions & 15 deletions gba/src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_sound.h>
#include "global.h"
#include "posprintf.h"
#include "helpsprites_chr.h"
#include "helpbgtiles_chr.h"

// Code units
#define LF 0x0A
Expand Down Expand Up @@ -94,17 +96,6 @@ The window
*/

extern const unsigned int helpbgtiles_chrTiles[];
extern const unsigned short helpbgtiles_chrPal[16];
extern const unsigned char helpsprites_chrTiles[];
extern const unsigned short helpsprites_chrPal[16];

extern const char *const helppages[];
extern const char *const helptitles[];
extern const unsigned char help_cumul_pages[];
extern const void *HELP_NUM_PAGES;
extern const void *HELP_NUM_SECTS;

static void load_help_bg(void) {

// Load pattern table
Expand Down Expand Up @@ -198,7 +189,7 @@ static void help_draw_cursor(unsigned int objx) {
oam_used = ou + 1;
}

static void help_draw_page(unsigned int doc_num, unsigned int left, unsigned int keymask) {
static void help_draw_page(helpdoc_kind doc_num, unsigned int left, unsigned int keymask) {
// Draw document title
dma_memset16(PATRAM4(3, 0), FG_BGCOLOR*0x1111, WINDOW_WIDTH * 32);
vwf8Puts(PATRAM4(3, 0), helptitles[doc_num], 0, FG_FGCOLOR);
Expand Down Expand Up @@ -294,7 +285,7 @@ static unsigned int help_move_window(void) {
return x;
}

unsigned int helpscreen(unsigned int doc_num, unsigned int keymask) {
unsigned int helpscreen(helpdoc_kind doc_num, unsigned int keymask) {

// If not within this document, move to the first page
// and move the cursor (if any) to the top
Expand Down Expand Up @@ -395,7 +386,7 @@ unsigned int helpscreen(unsigned int doc_num, unsigned int keymask) {
* @param pg an extern helpsect_ value
* @return 1 if pressed, 0 if not
*/
unsigned int read_pad_help_check(const void *pg) {
unsigned int read_pad_help_check(helpdoc_kind pg) {
read_pad();
if (!(new_keys & KEY_START)) return 0;

Expand All @@ -405,8 +396,12 @@ unsigned int read_pad_help_check(const void *pg) {
REG_SOUND1CNT_X = 0x8000;
REG_SOUND2CNT_L = 0;
REG_SOUND2CNT_H = 0x8000;
REG_DMA0CNT = 0;
REG_DMA1CNT = 0;
REG_DMA2CNT = 0;
REG_DMA3CNT = 0;
help_wnd_progress = 0;
helpscreen((unsigned int)pg, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
helpscreen(pg, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
new_keys = 0;
help_wnd_progress = 0;
return 1;
Expand Down
16 changes: 4 additions & 12 deletions gba/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <stdlib.h>
#include "global.h"

// It's a bit tricky to import a document ID into C.
extern const unsigned char helpsect_160p_test_suite_menu[];
extern const unsigned char helpsect_160p_test_suite[];
extern const unsigned char helpsect_about[];
extern const unsigned char helpsect_to_do[];

#define DOC_MENU ((unsigned int)helpsect_160p_test_suite_menu)
#define DOC_CREDITS ((unsigned int)helpsect_160p_test_suite)
#define DOC_ABOUT ((unsigned int)helpsect_about)
#define DOC_TODO ((unsigned int)helpsect_to_do)
#define DOC_MENU helpsect_160p_test_suite_menu
#define DOC_CREDITS helpsect_160p_test_suite

// Notes:
// iprintf/siprintf is devkitARM-specific printf/sprintf without float
Expand Down Expand Up @@ -90,7 +82,7 @@ int main(void) {
irqInit();
irqEnable(IRQ_VBLANK);
//activity_overscan();
//helpscreen(DOC_TODO, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
//helpscreen(helpsect_to_do, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
activity_credits();

while (1) {
Expand All @@ -110,7 +102,7 @@ int main(void) {
}

void activity_about(void) {
helpscreen(DOC_ABOUT, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
helpscreen(helpsect_about, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
}

void activity_credits(void) {
Expand Down
1 change: 0 additions & 1 deletion gba/src/megaton.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_video.h>
#include "posprintf.h"

extern const unsigned char helpsect_timing_and_reflex_test[];
#define PFMAP 23
#define NUM_TRIALS 10
#define BLANK_TILE 0x0004
Expand Down
6 changes: 1 addition & 5 deletions gba/src/motionblur.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_video.h>
#include <gba_input.h>

extern const unsigned char helpsect_health_warning[];
#define DOC_HEALTH_WARNING ((unsigned int)helpsect_health_warning)

extern const unsigned char helpsect_motion_blur[];
#define PFMAP 23
#define NUM_PARAMS 6
#define BLANK_TILE 0x0004
Expand Down Expand Up @@ -57,7 +53,7 @@ void activity_motion_blur() {
unsigned int phase = 0, timeleft = 0, running = 0;

if (!flashing_accepted) {
helpscreen(DOC_HEALTH_WARNING, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
helpscreen(helpsect_health_warning, KEY_A|KEY_START|KEY_B|KEY_LEFT|KEY_RIGHT);
if (!(new_keys & (KEY_A | KEY_START))) return;
flashing_accepted = 1;
}
Expand Down
1 change: 0 additions & 1 deletion gba/src/overscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_video.h>
#include <stdint.h>

extern const unsigned char helpsect_overscan[];
#define PFMAP 23

static signed int keys_to_side(unsigned int keys) {
Expand Down
7 changes: 2 additions & 5 deletions gba/src/placeholder.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ it freely, subject to the following restrictions:
#include <string.h>
#include "global.h"

extern const unsigned char spritegfx_chrTiles[];
extern const unsigned short spritegfx_chrPal[16];

extern const unsigned char helpsect_lame_boy[];
#include "bggfx_chr.h"
#include "spritegfx_chr.h"

unsigned short player_x;
signed short player_dx;
Expand Down Expand Up @@ -127,7 +125,6 @@ static void draw_player_sprite(void) {
// Still trying to see whether GritHub will cause me to not need
// pilbmp2nes.py. <https://github.com/devkitPro/grit>
// It's in Virtual Boy format because that decompresses easily
extern const VBTILE bggfx_chrTiles[48];

static const unsigned short bgcolors00[16] = {
RGB5(25,25,31), RGB5(20,20, 0), RGB5(27,27, 0), RGB5(31,31, 0)
Expand Down
File renamed without changes.
13 changes: 4 additions & 9 deletions gba/src/scrolltest.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_compression.h>
#include <gba_interrupt.h>

extern const unsigned char helpsect_grid_scroll_test[];
extern const unsigned char helpsect_hill_zone_scroll_test[];
extern const unsigned char helpsect_vertical_scroll_test[];
#include "kikitiles_chr.h"
#include "kikimap_chr.h"
#include "greenhillzone_chr.h"

#define PFSCROLLTEST 22

Expand Down Expand Up @@ -144,8 +144,6 @@ static const unsigned char mt_belowR[] = {
8, 0, 3, 9, 0, 0, 0, 7, 7, 7
};

extern const unsigned int kikimap_chrTiles[32];
extern const VBTILE kikitiles_chrTiles[24];
static const unsigned short kikipalette0[] = {
RGB5( 0, 0, 0),RGB5(15,11, 7),RGB5(23,18,13),RGB5(31,25,19)
};
Expand Down Expand Up @@ -221,10 +219,6 @@ void activity_kiki_scroll(void) {

// Horizontal scroll (like Sonic the Hedgehog) //////////////////////

extern const unsigned short greenhillzone_chrPal[8];
extern const unsigned short greenhillzone_chrMap[]; // LZ77
extern const unsigned short greenhillzone_chrTiles[]; // LZ77

void hill_zone_load_bg(void) {
LZ77UnCompVram(greenhillzone_chrTiles, PATRAM4(0, 0));
LZ77UnCompVram(greenhillzone_chrMap, MAP[PFSCROLLTEST]);
Expand All @@ -251,6 +245,7 @@ void hill_zone_set_scroll(uint16_t *hdmaTable, unsigned int x) {
REG_DMA0SAD = (intptr_t)&(hdmaTable[1]);
REG_DMA0DAD = (intptr_t)&(BG_OFFSET[1].x);
REG_DMA0CNT = 1|DMA_DST_RELOAD|DMA_SRC_INC|DMA_REPEAT|DMA16|DMA_HBLANK|DMA_ENABLE;
BG_OFFSET[1].x = hdmaTable[0];
}

void activity_hill_zone_scroll(void) {
Expand Down
23 changes: 8 additions & 15 deletions gba/src/shadowsprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <gba_compression.h>
#include <stdint.h>

extern const unsigned char helpsect_shadow_sprite[];
#include "Donna_chr.h"
#include "Gus_portrait_chr.h"
#include "hepsie_chr.h"

#define PFSCROLLTEST 22
#define PFOVERLAY 21

extern const unsigned int Gus_portrait_chrTiles[];
extern const unsigned short Gus_portrait_chrMap[20][14];
extern const unsigned short Gus_portrait_chrPal[16];

extern const unsigned int Donna_chrTiles[];
extern const unsigned short Donna_chrMap[20][14];
extern const unsigned short Donna_chrPal[16];

static void gus_bg_setup(void) {
LZ77UnCompVram(Gus_portrait_chrTiles, PATRAM4(0, 0));
dma_memset16(MAP[PFSCROLLTEST], 0x0000, 32*20*2);
load_flat_map(&(MAP[PFSCROLLTEST][0][8]), Gus_portrait_chrMap[0], 14, 20);
load_flat_map(&(MAP[PFSCROLLTEST][0][8]), Gus_portrait_chrMap, 14, 20);
}

static void gus_bg_set_scroll(uint16_t *hdmaTable, unsigned int unused) {
Expand All @@ -54,7 +49,7 @@ static void gus_bg_set_scroll(uint16_t *hdmaTable, unsigned int unused) {
static void donna_bg_setup(void) {
LZ77UnCompVram(Donna_chrTiles, PATRAM4(0, 0));
dma_memset16(MAP[PFSCROLLTEST], 0x0000, 32*20*2);
load_flat_map(&(MAP[PFSCROLLTEST][0][0]), Donna_chrMap[0], 30, 20);
load_flat_map(&(MAP[PFSCROLLTEST][0][0]), Donna_chrMap, 30, 20);
}

static void donna_bg_set_scroll(uint16_t *hdmaTable, unsigned int unused) {
Expand Down Expand Up @@ -104,8 +99,6 @@ static const ShadowSpriteBG bgtypes[] = {

#define NUM_BGTYPES (sizeof bgtypes / sizeof bgtypes[0])

extern const VBTILE hepsie_chrTiles[32];

static const unsigned short shadow_sprite_palettes[3][3] = {
{RGB5( 0, 0, 0),RGB5( 0,31, 0),RGB5(31,25,19)}, // Hepsie top half
{RGB5( 0, 0, 0),RGB5(31, 0,31),RGB5(31,31, 0)}, // Hepsie bottom half
Expand Down Expand Up @@ -170,13 +163,13 @@ void activity_shadow_sprite() {
if (cur_keys & KEY_A) {
if (new_keys & KEY_RIGHT) {
if (++cur_bg >= NUM_BGTYPES) cur_bg = 0;
REG_DISPCNT = MODE_0 | BG0_ON | OBJ_ON;
REG_DISPCNT = MODE_0 | BG0_ON | OBJ_1D_MAP | OBJ_ON;
bgtypes[cur_bg].setup();
held_keys &= ~KEY_A;
}
if (new_keys & KEY_LEFT) {
cur_bg = cur_bg ? cur_bg - 1 : NUM_BGTYPES - 1;
REG_DISPCNT = MODE_0 | BG0_ON | OBJ_ON;
REG_DISPCNT = MODE_0 | BG0_ON | OBJ_1D_MAP | OBJ_ON;
bgtypes[cur_bg].setup();
held_keys &= ~KEY_A;
}
Expand Down
Loading

0 comments on commit ca14773

Please sign in to comment.