Compare commits
8
Commits
cb77683a87
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7a3dad3d0 | ||
|
|
1e1e753be1
|
||
|
|
4bc31ea1fc
|
||
|
|
79a27ccbae
|
||
|
|
dd6b92300e | ||
|
|
a6937448c0
|
||
|
|
59c44c2b45
|
||
|
|
1141765231
|
No files matched your search
@@ -4,11 +4,11 @@ CC := $(TOOL_PREFIX)gcc
|
||||
OBJCOPY := $(TOOL_PREFIX)objcopy
|
||||
CFLAGS := -mcpu=arm7tdmi -marm -O2 -g -Wall -Wextra -Werror -ffreestanding -fno-builtin -fno-common -Wa,--noexecstack
|
||||
GAME_SOURCES := source/main.c source/video.c source/scenery.c source/world.c \
|
||||
source/actors.c source/battle.c source/story.c source/hud.c source/audio.c source/beach.c
|
||||
source/actors.c source/battle.c source/story.c source/hud.c source/audio.c source/beach.c source/menu.c source/save.c
|
||||
GAME_OBJECTS := $(GAME_SOURCES:source/%.c=build/%.o)
|
||||
TEST_SOURCES := tests/test_game.c tests/test_support.c tests/test_maps.c \
|
||||
tests/test_story.c tests/test_battle.c tests/test_rendering.c tests/test_movement.c tests/test_audio.c \
|
||||
tests/test_catching.c
|
||||
tests/test_catching.c tests/test_menu.c tests/test_progress.c tests/test_location.c
|
||||
|
||||
.PHONY: all play check check-host
|
||||
all: game.gba
|
||||
@@ -25,8 +25,9 @@ build/%.o: source/%.c source/game.h | build
|
||||
build/actors.o: source/wild_creatures.h
|
||||
build/audio.o build/main.o: source/audio.h
|
||||
|
||||
build/game.elf: build/start.o $(GAME_OBJECTS) gba.ld
|
||||
$(CC) -mcpu=arm7tdmi -marm -nostdlib -T gba.ld -Wl,-z,noexecstack -Wl,-Map,build/game.map build/start.o $(GAME_OBJECTS) -lgcc -o $@
|
||||
# The bare-metal .data segment intentionally contains startup-relocated EWRAM code.
|
||||
build/game.elf: build/start.o $(GAME_OBJECTS) gba.ld Makefile
|
||||
$(CC) -mcpu=arm7tdmi -marm -nostdlib -T gba.ld -Wl,-z,noexecstack -Wl,--no-warn-rwx-segments -Wl,-Map,build/game.map build/start.o $(GAME_OBJECTS) -lgcc -o $@
|
||||
|
||||
game.gba: build/game.elf tools/rom_header.py
|
||||
$(OBJCOPY) -O binary $< $@
|
||||
|
||||
@@ -24,17 +24,17 @@ The game file is **game.gba**. You can also open it directly in mGBA without reb
|
||||
- **Return to the village:** on Sunpetal Trail, follow the central path up to the top edge. Press X beside the wooden sign to read the directions.
|
||||
- **Visit Professor Mellon:** follow the village's horizontal sandy path right through the fence opening. Her blue-roofed house is in the garden. Press X on its steps to enter, then walk close to the professor and press X to talk. Leave through the bottom doorway, then follow the garden path left to return to town.
|
||||
- **Visit Seashell Beach:** from Professor Mellon's garden, follow the central sandy path down through the bottom fence gap. Walk up the beach's northern path to return to the garden. Explore the dry sand, palms, umbrella, shells, and starfish; the sea is not walkable. Sprout comes along, and the beach uses the calm trail music.
|
||||
- **Go fishing:** talk to **Fisher Coral**, the red-haired person in turquoise on the right side of Seashell Beach. Press X again to receive a **Poké Rod**, saved permanently in your bag. Bring Sprout, walk to the water's edge, face down toward the sea, and press **X** to hook **Tidefin**, an original Water-type fish. Weaken it and press **Backspace** to throw a Poké Ball. The rod is reusable; catching still requires balls from Ranger Finn and space on your team. Older saves keep their gifts and catches.
|
||||
- **Go fishing:** talk to **Fisher Coral**, the red-haired person in turquoise on the right side of Seashell Beach. Press X again to receive a reusable **Poké Rod** in your bag; choose Save from the Start menu to keep it after restarting. Bring Sprout, walk to the water's edge, face down toward the sea, and press **X** to hook **Tidefin**, an original Water-type fish. Weaken it and press **Backspace** to throw a Poké Ball. Catching still requires balls from Ranger Finn and space on your team. Older saves keep their gifts and catches.
|
||||
- **Get your first partner:** talk to Professor Mellon and press X to advance her conversation. She gives you **Sprout**, an original Grass-type partner at level five. This is a one-time gift; later conversations check on Sprout instead.
|
||||
- **Character artwork:** the player and Ranger Finn use boy sprites; Mila and Professor Mellon use distinct long-haired girl sprites. Mellon keeps her white coat and gray hair. Both styles have front, back, and side views.
|
||||
- **Backspace (GBA Select button):** open your team. Use Left/Right to browse Sprout and your caught creatures, then press **X (A)** to choose the displayed creature as your following and battling partner. Backspace or Z (B) returns without changing your choice. Your selection is saved automatically. Movement pauses while the team screen is open.
|
||||
- **Backspace (GBA Select button):** open your team directly while exploring. Use Left/Right to browse Sprout and your caught creatures, then press **X (A)** to choose the displayed creature as your following and battling partner and return. Backspace or Z (B) returns without changing your choice. Team opened directly returns to the world; Team opened from Start returns to the sidebar. Choose Save from the Start menu to retain your selection.
|
||||
- **Your partner follows you:** Sprout or your selected caught creature follows your path and travels through doors and map exits with you. Each uses its own artwork. Choose Sprout again from the team screen whenever you like.
|
||||
- **Battle the golden creature:** with Sprout on your team, walk close to the golden creature in Greenleaf Village and press X. Use Left/Right to choose **Tackle** or **Leaf Tap**, then X to attack. The golden creature responds with Bump. Press Z (B) to run away. At the result screen, press X or Z to return to the map. Sprout recovers fully after each battle.
|
||||
- **Wild encounters:** with Sprout, walk around either tall-grass patch on Sunpetal Trail. **Fernfox** (Grass), **Emberwing** (Fire), or **Pebblit** (Rock) can appear automatically. Each has its own original 24×24 sprite, palette, health, and attack. Encounters only happen while moving in grass, with a short breather between battles. Leaf Tap is stronger against Pebblit and weaker against Emberwing. Fighting and running use the same keys as the golden-creature battle.
|
||||
- **Get Poké Balls:** talk to **Ranger Finn**, the person in orange just left of Sunpetal Trail's central path. Press X again to receive **five Poké Balls**. This gift is given once. Press Backspace to see the count on the team screen, even if you do not have Sprout yet.
|
||||
- **Catch a creature:** press **Backspace during a battle** to throw one Poké Ball. Lower health improves the chance; at one-quarter health or less, the catch is guaranteed. A failed throw still uses the ball and lets the creature attack. You cannot catch a fainted creature. Successful catches join your saved team, with room for Sprout plus five catches (duplicates are allowed). A full team does not waste a ball. The village's golden creature disappears from the map once caught. Press X after the catch result, then Backspace and Left/Right to view your new friend. Press X to make it your partner.
|
||||
- **Battle with caught creatures:** your selected partner fights in both land and fishing battles, using its own maximum health, Tackle, and a second move: Golden's Bump, Fernfox's Leaf Tap, Emberwing's Spark, Pebblit's Roll, or Tidefin's Water Jet. Partners recover fully after battles. Choose partners outside battle, not during a turn.
|
||||
- **Return (GBA Start button):** return to your starting position in the current map.
|
||||
- **Return (GBA Start button):** open the **Team / Bag / Save / Close** right sidebar while exploring. Up/Down wraps through the four options and X (A) activates one. Team uses the same screen as Select. Bag shows your Poké Ball count (including zero) and rod ownership; it is read-only, with X or Z returning to the sidebar. Z (B) closes the sidebar or returns from a submenu; Return closes the entire menu from any page. Saved/failed messages wait for a fresh X, Z, or Return press. All menu pages pause walking and encounters; closing restores the same scene and position. Start no longer resets your position, and menus cannot open during conversations or battles. Music and S (R) mute continue working while menus are open.
|
||||
- **S (GBA R shoulder button):** mute or unmute the music, including during battles and menus. This setting lasts until you restart the ROM.
|
||||
|
||||
If those keys do not match your emulator settings, check mGBA's keyboard input settings.
|
||||
@@ -59,8 +59,10 @@ Those numbers mean red, green, and blue, each from 0 to 31. Try `RGB(29, 6, 6)`
|
||||
- `source/world.c`: movement, collisions, doors, map travel, and following.
|
||||
- `source/actors.c`: character and creature artwork and drawing.
|
||||
- `source/battle.c`: species, battle rules, and the battle screen.
|
||||
- `source/story.c`: conversations, gifts, and cartridge SRAM saves.
|
||||
- `source/story.c`: conversations and gifts.
|
||||
- `source/save.c`: versioned cartridge SRAM records and validation.
|
||||
- `source/hud.c`: map status, scene drawing, and the team screen.
|
||||
- `source/menu.c`: Team / Bag / Save / Close menu input and drawing, including the Select shortcut.
|
||||
- `source/audio.c` and `source/audio.h`: original chiptune scores and the GBA sound-channel sequencer.
|
||||
- `source/wild_creatures.h`: original wild-creature sprites and palettes.
|
||||
- `source/start.s`: code that starts the GBA hardware.
|
||||
@@ -79,9 +81,19 @@ Sprite artwork is decoded once into cached palette indices. Character and creatu
|
||||
|
||||
Movement has a separate 60 Hz fixed-step clock using cascaded GBA timers 2 and 3, independent of rendering. Walking is two pixels per tick (120 pixels/second), with normalized diagonal speed. Every pixel is collision-checked and recorded for Sprout and grass encounters, so faster movement does not skip walls or map exits or double the following distance. Missed updates can catch up by at most five ticks; older backlog is dropped after a long stall. Menus, conversations, battles, and map-loading time do not build up movement backlog. The existing footstep artwork is unchanged, with its phase now clocked by simulation ticks rather than rendered frames.
|
||||
|
||||
## Saving your partner and items
|
||||
## Saving your adventure
|
||||
|
||||
Receiving gifts, throwing Poké Balls, and choosing partners automatically write a small cartridge SRAM save, stored by mGBA alongside the ROM as `game.sav`. Keep that file to retain your gifts, caught creatures, remaining balls, and selected partner after reopening the game. Older saves remain compatible and default to Sprout as the active partner. Your map and position are not saved. Partners recover after battles. Experience is not implemented yet.
|
||||
Only choosing **Save** in the Start sidebar writes cartridge SRAM, stored by mGBA alongside the ROM as `game.sav`. Save retains Sprout ownership, Finn's gift flag, remaining balls, the rod, caught species, your selected partner, map, position and facing. Gifts, throwing balls (successful or failed, including battle losses), partner selection, walking and map changes affect the current session only until you choose Save. There are no startup, exit, or gameplay autosaves. Battle state, health, conversations, open doors, follower trail, movement timing and music mute are not saved; partners recover after battles.
|
||||
|
||||
The sidebar states **SAVES TEAM / ITEMS AND / LOCATION**. **GAME / SAVED** means the complete v6 cartridge record was written and read back, not that mGBA has flushed it to disk. **SAVE / FAILED** means validation or read-back failed. Invalid in-memory progress or location is rejected before writing. The single record uses CRC-16/CCITT-FALSE to detect corruption, not guarantee recovery or atomicity: interrupted writes or read-back failures can lose the previous record. Close mGBA normally, then reopen the same ROM without loading an emulator save state to check persistence. Preserve backups and use disposable ROM/save copies when testing.
|
||||
|
||||
Existing v1–v5 saves still load without changing their bytes; newly introduced fields receive defaults. These saves start outside in Greenleaf Village at (108,103), facing down. A v6 record with valid integrity and progress but an invalid/outdated location retains progress and uses that same default spawn. Invalid integrity, invalid progress or an unknown version rejects the whole record and starts with empty progress at the default spawn, without repairing or overwriting stored bytes. Only explicit Save writes/upgrades to v6. **Older builds cannot read v6**; do not use them with a newer save, as a subsequent save could overwrite your progress.
|
||||
|
||||
The v6 format is 19 bytes: `FQSP` (0–3), version 6 (4), v5 flags (5: Sprout bit 0, balls gift bit 1, rod bit 2, active member bits 3–5), ball count (6), caught count (7), five species IDs/unused `FF` (8–12), room (13), facing (14), x (15), y (16), then CRC high/low bytes (17–18). CRC covers bytes 0–16 with initial `FFFF`, polynomial `1021`, no reflection or final XOR. Byte 0 is invalidated first and committed as `F` last. Persistent room IDs are Outside 0, Cottage 1, Route 2, Mellon Garden 3, Mellon House 4, Beach 5; facing IDs are down 0, up 1, left 2, right 3. These IDs must not be reordered or reused.
|
||||
|
||||
The ROM uses homebrew game code `QST0`. The previous `FQ01` collided with mGBA 0.10.5's Classic NES detection, which forced EEPROM instead of SRAM.
|
||||
|
||||
The SRAM backend sets eight waitstates without changing other WAITCNT bits and performs byte reads from a startup-relocated EWRAM routine; writes use byte accesses from ROM. Physical cartridges remain unverified. Hot cartridge removal and its Game Pak IRQ protection are not supported; power off before removing a cartridge.
|
||||
|
||||
## Music
|
||||
|
||||
@@ -118,6 +130,6 @@ We are making an original game. No existing Pokémon ROM or separate BIOS downlo
|
||||
|
||||
## Project status
|
||||
|
||||
Greenleaf Village connects south to Sunpetal Trail and east to Professor Mellon's garden and house. Seashell Beach is south of the garden, with a return path north. Both houses have working doors. Mila and the professor have conversations, and Mellon gives you Sprout once. Ranger Finn gives you five usable Poké Balls. Sprout follows your footsteps and battles the village's golden creature and three wild route species. Battles support two moves, species-specific replies, health bars, catching, victory, defeat, running away, and free recovery. Caught creatures and spent balls are saved, and the team screen lets you browse up to six members.
|
||||
Greenleaf Village connects south to Sunpetal Trail and east to Professor Mellon's garden and house. Seashell Beach is south of the garden, with a return path north. Both houses have working doors. Mila and the professor have conversations, and Mellon gives you Sprout once. Ranger Finn gives you five usable Poké Balls. Sprout follows your footsteps and battles the village's golden creature and three wild route species. Battles support two moves, species-specific replies, health bars, catching, victory, defeat, running away, and free recovery. The team screen lets you browse up to six members; use the Start sidebar to save your team and items.
|
||||
|
||||
All artwork and music are original; no Pokémon game assets or ROMs are included. Experience, mid-battle partner switching, sound effects, and full progress saving are not implemented yet.
|
||||
All artwork and music are original; no Pokémon game assets or ROMs are included. Experience, mid-battle partner switching and sound effects are not implemented yet.
|
||||
@@ -14,9 +14,11 @@ SECTIONS {
|
||||
. = ALIGN(4);
|
||||
} > ROM
|
||||
|
||||
/* Startup copies this range, including the leaf SRAM reader, before main. */
|
||||
.data : {
|
||||
__data_start = .;
|
||||
*(.data*)
|
||||
*(.ewram.text.sram_read)
|
||||
. = ALIGN(4);
|
||||
__data_end = .;
|
||||
} > RAM AT > ROM
|
||||
|
||||
@@ -89,7 +89,6 @@ static int throw_ball(void)
|
||||
battle.notice = NOTICE_BROKE_FREE;
|
||||
enemy_reply();
|
||||
}
|
||||
save_progress(); /* Save spent balls as well as successful catches. */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
+29
-4
@@ -11,15 +11,18 @@ enum { A = 1, B = 2, SELECT = 4, START = 8, RIGHT = 16, LEFT = 32, UP = 64, DOWN
|
||||
R_BUTTON = 256 };
|
||||
enum { MOVEMENT_HZ = 60, MOVEMENT_CLOCK_HZ = 16384, WALK_SPEED = 2, MAX_MOVEMENT_TICKS = 5 };
|
||||
enum { NPC_X = 146, NPC_Y = 106, PROF_X = 113, PROF_Y = 92, RANGER_X = 83, RANGER_Y = 97 };
|
||||
enum Room { OUTSIDE, COTTAGE, ROUTE, MELLON_GARDEN, MELLON_HOUSE, BEACH };
|
||||
enum Facing { FACING_DOWN, FACING_UP, FACING_LEFT, FACING_RIGHT };
|
||||
/* Room and facing IDs are persistent: never reorder or reuse them. */
|
||||
enum Room { OUTSIDE = 0, COTTAGE = 1, ROUTE = 2, MELLON_GARDEN = 3,
|
||||
MELLON_HOUSE = 4, BEACH = 5, ROOM_COUNT = 6 };
|
||||
enum Facing { FACING_DOWN = 0, FACING_UP = 1, FACING_LEFT = 2, FACING_RIGHT = 3 };
|
||||
struct Location { int room, x, y, facing; };
|
||||
enum CharacterStyle { BOY_STYLE, GIRL_STYLE };
|
||||
enum { DIALOGUE_X = 8, DIALOGUE_Y = 96, DIALOGUE_W = 224, DIALOGUE_H = 44 };
|
||||
enum { FOLLOW_STEPS = 14, SPROUT_HP = 24, GOLDEN_HP = 18 };
|
||||
enum BattlePhase { BATTLE_OFF, BATTLE_TURN, BATTLE_WON, BATTLE_LOST, BATTLE_FLED, BATTLE_CAUGHT };
|
||||
enum Species { GOLDEN, FERNFOX, EMBERWING, PEBBLIT, TIDEFIN, SPECIES_COUNT };
|
||||
enum { FISHER_X = 178, FISHER_Y = 80 };
|
||||
enum { CAUGHT_CAPACITY = 5, SAVE_RECORD_SIZE = 15 };
|
||||
enum { CAUGHT_CAPACITY = 5, SAVE_RECORD_SIZE = 19 };
|
||||
enum BattleNotice { NOTICE_NONE, NOTICE_NO_BALLS, NOTICE_TEAM_FULL, NOTICE_BROKE_FREE };
|
||||
enum WalkResult { WALK_NORMAL, WALK_MAP_CHANGED, WALK_ENCOUNTER };
|
||||
|
||||
@@ -95,6 +98,10 @@ int near_map_exit(int x, int y);
|
||||
int near_route_sign(int x, int y);
|
||||
int use_door(int *x, int *y);
|
||||
void reset_position(int *x, int *y);
|
||||
int room_walkable(int room, int x, int y);
|
||||
int location_valid(const struct Location *location);
|
||||
void default_location(struct Location *out);
|
||||
void enter_location(const struct Location *location, int *x, int *y);
|
||||
enum WalkResult walk_movement(unsigned keys, int *x, int *y, int ticks);
|
||||
void scaled_creature(int x, int y, int scale, const u16 *palette);
|
||||
void draw_wild_creature(enum Species enemy, int x, int y);
|
||||
@@ -107,7 +114,24 @@ int battle_input(unsigned pressed);
|
||||
void draw_battle_hud(void);
|
||||
void draw_battle(void);
|
||||
void load_progress(void);
|
||||
void save_progress(void);
|
||||
void saved_location(struct Location *out);
|
||||
int save_progress(const struct Location *location);
|
||||
enum SaveMenuPhase { SAVE_MENU_CLOSED, SAVE_MENU_OPTIONS, SAVE_MENU_SAVED, SAVE_MENU_FAILED,
|
||||
SAVE_MENU_TEAM, SAVE_MENU_BAG };
|
||||
enum { MENU_TEAM, MENU_BAG, MENU_SAVE, MENU_CLOSE, MENU_COUNT };
|
||||
enum { SAVE_MENU_X = 160, SAVE_MENU_Y = 6, SAVE_MENU_W = 74, SAVE_MENU_H = 148 };
|
||||
struct SaveMenuState {
|
||||
enum SaveMenuPhase phase;
|
||||
int selection;
|
||||
unsigned previous;
|
||||
};
|
||||
extern struct SaveMenuState save_menu;
|
||||
int save_menu_input(unsigned keys, int can_open, const struct Location *location);
|
||||
void draw_save_menu(void);
|
||||
void draw_menu_scene(int x, int y);
|
||||
int menu_redraw_is_panel(enum SaveMenuPhase before, enum SaveMenuPhase after);
|
||||
void draw_menu_panel(enum SaveMenuPhase before);
|
||||
void draw_bag(void);
|
||||
int has_caught(enum Species kind);
|
||||
int near_npc(int x, int y);
|
||||
int begin_conversation(int x, int y);
|
||||
@@ -120,6 +144,7 @@ void draw_team(void);
|
||||
void draw_team_member(int member);
|
||||
|
||||
#ifdef GAME_TEST
|
||||
unsigned save_crc(const unsigned char *bytes, int length);
|
||||
extern const unsigned char large_alphabet[26][7];
|
||||
extern u16 background_cache[WIDTH * HEIGHT];
|
||||
extern enum Room background_room;
|
||||
|
||||
+24
-3
@@ -1,4 +1,5 @@
|
||||
#include "game.h"
|
||||
static void draw_bag_summary(void);
|
||||
|
||||
void status(const char *message)
|
||||
{
|
||||
@@ -33,7 +34,7 @@ void draw_scene(int x, int y)
|
||||
{
|
||||
restore(0, 0, WIDTH, HEIGHT);
|
||||
location_status(x, y);
|
||||
text(8, 148, "ARROWS MOVE A USE SELECT TEAM START RESET R MUSIC", RGB(5, 9, 11));
|
||||
text(8, 148, "ARROWS MOVE A USE SELECT TEAM START MENU R MUSIC", RGB(5, 9, 11));
|
||||
actors(x, y, 0);
|
||||
}
|
||||
|
||||
@@ -81,7 +82,14 @@ void draw_team_member(int member)
|
||||
large_text(28, 76, "VISIT PROFESSOR MELLON", ink);
|
||||
text(28, 96, "HER HOUSE IS EAST OF GREENLEAF VILLAGE", ink);
|
||||
}
|
||||
/* A small bag summary is visible even before you receive Sprout. */
|
||||
draw_bag_summary();
|
||||
rectangle(0, 142, WIDTH, 18, cream);
|
||||
text(8, 148, "LEFT RIGHT TEAM A CHOOSE B SELECT BACK", ink);
|
||||
}
|
||||
|
||||
static void draw_bag_summary(void)
|
||||
{
|
||||
u16 ink = RGB(5, 8, 11);
|
||||
rectangle(24, 118, 8, 8, ink);
|
||||
rectangle(25, 119, 6, 3, RGB(29, 8, 9));
|
||||
rectangle(25, 122, 6, 3, RGB(31, 31, 28));
|
||||
@@ -94,6 +102,19 @@ void draw_team_member(int member)
|
||||
count_text[count_index] = 0;
|
||||
text(88, 119, count_text, ink);
|
||||
if (rod_owned) text(133, 119, "POKE ROD", ink);
|
||||
}
|
||||
|
||||
void draw_bag(void)
|
||||
{
|
||||
u16 ink = RGB(5, 8, 11), cream = RGB(30, 30, 26);
|
||||
rectangle(0, 0, WIDTH, HEIGHT, RGB(15, 24, 20));
|
||||
status("YOUR BAG");
|
||||
rectangle(8, 25, 224, 112, ink);
|
||||
rectangle(10, 27, 220, 108, cream);
|
||||
large_text(24, 45, "ITEMS", ink);
|
||||
text(24, 66, "POKE BALLS ARE USED DURING BATTLE", ink);
|
||||
text(24, 80, "THIS SCREEN IS READ ONLY", ink);
|
||||
draw_bag_summary();
|
||||
rectangle(0, 142, WIDTH, 18, cream);
|
||||
text(8, 148, "ARROWS TEAM A CHOOSE PARTNER B BACK", ink);
|
||||
text(8, 148, "A B BACK START CLOSE", ink);
|
||||
}
|
||||
+22
-45
@@ -66,13 +66,13 @@ int main(void)
|
||||
DISPLAY = 0x0080; /* Hide the screen until the scene is drawn. */
|
||||
int x = 108, y = 103, frame = 0, greeting = 0;
|
||||
int dialogue_page = -1; /* -1 means we are not talking. */
|
||||
int team_open = 0;
|
||||
int team_member = 0;
|
||||
unsigned previous = 0;
|
||||
start_movement_timer();
|
||||
music_init(movement_time());
|
||||
load_progress();
|
||||
reset_follower(x, y);
|
||||
struct Location start;
|
||||
saved_location(&start);
|
||||
enter_location(&start, &x, &y);
|
||||
music_init(movement_time());
|
||||
reset_dirty_rows();
|
||||
draw_scene(x, y);
|
||||
present_frame();
|
||||
@@ -86,34 +86,29 @@ int main(void)
|
||||
unsigned now = movement_time();
|
||||
music_update(now);
|
||||
if (pressed & R_BUTTON) music_toggle_mute();
|
||||
enum SaveMenuPhase menu_before = save_menu.phase;
|
||||
const struct Location here = {current_room, x, y, player_facing};
|
||||
int menu_changed = save_menu_input(keys,
|
||||
battle.phase == BATTLE_OFF && dialogue_page < 0, &here);
|
||||
if (menu_before != SAVE_MENU_CLOSED || save_menu.phase != SAVE_MENU_CLOSED) {
|
||||
pause_movement_at(now);
|
||||
if (menu_changed) {
|
||||
int panel_only = menu_redraw_is_panel(menu_before, save_menu.phase);
|
||||
if (!panel_only) DISPLAY = 0x0080;
|
||||
if (panel_only) draw_menu_panel(menu_before);
|
||||
else draw_menu_scene(x, y);
|
||||
present_frame();
|
||||
if (!panel_only) DISPLAY = 0x0403;
|
||||
pause_movement_at(movement_time());
|
||||
} else present_frame();
|
||||
continue;
|
||||
}
|
||||
int movement_ticks = 0;
|
||||
if (team_open || battle.phase != BATTLE_OFF || dialogue_page >= 0)
|
||||
if (battle.phase != BATTLE_OFF || dialogue_page >= 0)
|
||||
pause_movement_at(now);
|
||||
else
|
||||
movement_ticks = movement_ticks_at(now);
|
||||
random_state += 0x9e3779b9u; /* Mix in how long the player waits. */
|
||||
if (team_open) {
|
||||
if (partner_owned && (pressed & (LEFT | RIGHT))) {
|
||||
int members = caught_count + 1;
|
||||
team_member = (team_member + ((pressed & RIGHT) ? 1 : members - 1)) % members;
|
||||
DISPLAY = 0x0080;
|
||||
draw_team_member(team_member);
|
||||
present_frame();
|
||||
DISPLAY = 0x0403;
|
||||
pause_movement_at(movement_time());
|
||||
} else if (pressed & (SELECT | A | B)) {
|
||||
if ((pressed & A) && choose_partner(team_member)) reset_follower(x, y);
|
||||
team_open = 0;
|
||||
DISPLAY = 0x0080;
|
||||
draw_scene(x, y);
|
||||
present_frame();
|
||||
DISPLAY = 0x0403;
|
||||
pause_movement_at(movement_time());
|
||||
} else {
|
||||
present_frame();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (battle.phase != BATTLE_OFF) {
|
||||
if (battle_input(pressed)) {
|
||||
if (battle.phase == BATTLE_OFF) {
|
||||
@@ -155,29 +150,11 @@ int main(void)
|
||||
present_frame();
|
||||
continue;
|
||||
}
|
||||
if (pressed & SELECT) {
|
||||
team_open = 1;
|
||||
team_member = 0;
|
||||
DISPLAY = 0x0080;
|
||||
draw_team();
|
||||
present_frame();
|
||||
DISPLAY = 0x0403;
|
||||
pause_movement_at(movement_time());
|
||||
continue;
|
||||
}
|
||||
int old_x = x, old_y = y;
|
||||
int old_follower_x = follower_x, old_follower_y = follower_y;
|
||||
enum Facing old_facing = player_facing;
|
||||
enum WalkResult walk = WALK_NORMAL;
|
||||
if (pressed & START) {
|
||||
reset_position(&x, &y);
|
||||
greeting = 0;
|
||||
location_status(x, y);
|
||||
pause_movement_at(now);
|
||||
movement_ticks = 0;
|
||||
} else {
|
||||
walk = walk_movement(keys, &x, &y, movement_ticks);
|
||||
}
|
||||
if (walk == WALK_MAP_CHANGED) {
|
||||
greeting = 0;
|
||||
dialogue_page = -1;
|
||||
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
#include "game.h"
|
||||
|
||||
struct SaveMenuState save_menu;
|
||||
static int team_member, team_parent;
|
||||
static u16 panel_underlay[SAVE_MENU_H][SAVE_MENU_W];
|
||||
|
||||
static void copy_panel_underlay(int restoring)
|
||||
{
|
||||
for (int y = 0; y < SAVE_MENU_H; ++y)
|
||||
for (int x = 0; x < SAVE_MENU_W; ++x) {
|
||||
int pixel = (SAVE_MENU_Y + y) * WIDTH + SAVE_MENU_X + x;
|
||||
if (restoring) SCREEN[pixel] = panel_underlay[y][x];
|
||||
else panel_underlay[y][x] = SCREEN[pixel];
|
||||
}
|
||||
if (restoring) mark_dirty(SAVE_MENU_X, SAVE_MENU_Y, SAVE_MENU_W, SAVE_MENU_H);
|
||||
}
|
||||
|
||||
void draw_menu_panel(enum SaveMenuPhase before)
|
||||
{
|
||||
/* World stays paused; fullscreen returns recapture after rebuilding actors/HUD. */
|
||||
if (before == SAVE_MENU_CLOSED) copy_panel_underlay(0);
|
||||
if (save_menu.phase == SAVE_MENU_CLOSED) copy_panel_underlay(1);
|
||||
else draw_save_menu();
|
||||
}
|
||||
|
||||
int save_menu_input(unsigned keys, int can_open, const struct Location *location)
|
||||
{
|
||||
unsigned pressed = keys & ~save_menu.previous;
|
||||
save_menu.previous = keys;
|
||||
if (save_menu.phase == SAVE_MENU_CLOSED) {
|
||||
if (!can_open || !(pressed & (START | SELECT))) return 0;
|
||||
save_menu.phase = pressed & START ? SAVE_MENU_OPTIONS : SAVE_MENU_TEAM;
|
||||
team_parent = 0;
|
||||
team_member = 0;
|
||||
save_menu.selection = 0;
|
||||
return 1;
|
||||
}
|
||||
if (pressed & START) {
|
||||
save_menu.phase = SAVE_MENU_CLOSED;
|
||||
return 1;
|
||||
}
|
||||
if (save_menu.phase == SAVE_MENU_TEAM || save_menu.phase == SAVE_MENU_BAG) {
|
||||
if (pressed & (B | SELECT | A)) {
|
||||
if (save_menu.phase == SAVE_MENU_TEAM && (pressed & A) &&
|
||||
!(pressed & (B | SELECT)) && choose_partner(team_member))
|
||||
reset_follower(location->x, location->y);
|
||||
save_menu.phase = team_parent ? SAVE_MENU_OPTIONS : SAVE_MENU_CLOSED;
|
||||
return 1;
|
||||
}
|
||||
unsigned direction = pressed & (LEFT | RIGHT);
|
||||
if (save_menu.phase == SAVE_MENU_TEAM && partner_owned &&
|
||||
(direction == LEFT || direction == RIGHT)) {
|
||||
int members = caught_count + 1;
|
||||
team_member = (team_member + (direction == RIGHT ? 1 : members - 1)) % members;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (pressed & B) {
|
||||
save_menu.phase = SAVE_MENU_CLOSED;
|
||||
return 1;
|
||||
}
|
||||
if (save_menu.phase != SAVE_MENU_OPTIONS) {
|
||||
if (!(pressed & A)) return 0;
|
||||
save_menu.phase = SAVE_MENU_CLOSED;
|
||||
return 1;
|
||||
}
|
||||
if (pressed & A) {
|
||||
if (save_menu.selection == MENU_CLOSE) save_menu.phase = SAVE_MENU_CLOSED;
|
||||
else if (save_menu.selection == MENU_SAVE)
|
||||
save_menu.phase = save_progress(location) ? SAVE_MENU_SAVED : SAVE_MENU_FAILED;
|
||||
else {
|
||||
team_parent = 1;
|
||||
team_member = 0;
|
||||
save_menu.phase = save_menu.selection == MENU_TEAM ? SAVE_MENU_TEAM : SAVE_MENU_BAG;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
unsigned direction = pressed & (UP | DOWN);
|
||||
if (direction == UP || direction == DOWN) {
|
||||
save_menu.selection = (save_menu.selection + (direction == DOWN ? 1 : MENU_COUNT - 1)) % MENU_COUNT;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void draw_menu_scene(int x, int y)
|
||||
{
|
||||
if (save_menu.phase == SAVE_MENU_TEAM) draw_team_member(team_member);
|
||||
else if (save_menu.phase == SAVE_MENU_BAG) draw_bag();
|
||||
else {
|
||||
draw_scene(x, y);
|
||||
if (save_menu.phase != SAVE_MENU_CLOSED) {
|
||||
copy_panel_underlay(0);
|
||||
draw_save_menu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int menu_redraw_is_panel(enum SaveMenuPhase before, enum SaveMenuPhase after)
|
||||
{
|
||||
return before <= SAVE_MENU_FAILED && after <= SAVE_MENU_FAILED &&
|
||||
(before != SAVE_MENU_CLOSED || after != SAVE_MENU_CLOSED);
|
||||
}
|
||||
|
||||
void draw_save_menu(void)
|
||||
{
|
||||
u16 ink = RGB(5, 8, 11), cream = RGB(30, 30, 26);
|
||||
int x = SAVE_MENU_X, y = SAVE_MENU_Y;
|
||||
rectangle(x, y, SAVE_MENU_W, SAVE_MENU_H, ink);
|
||||
rectangle(x + 2, y + 2, SAVE_MENU_W - 4, SAVE_MENU_H - 4, cream);
|
||||
large_text(x + 16, y + 10, "MENU", ink);
|
||||
rectangle(x + 6, y + 23, SAVE_MENU_W - 12, 1, RGB(15, 24, 20));
|
||||
text(x + 8, y + 99, "SAVES TEAM", ink);
|
||||
text(x + 8, y + 108, "ITEMS AND", ink);
|
||||
text(x + 8, y + 117, "LOCATION", ink);
|
||||
if (save_menu.phase == SAVE_MENU_OPTIONS) {
|
||||
int selected_y = y + 28 + save_menu.selection * 16;
|
||||
rectangle(x + 6, selected_y, SAVE_MENU_W - 12, 16, RGB(23, 28, 21));
|
||||
rectangle(x + 10, selected_y + 5, 1, 5, ink);
|
||||
rectangle(x + 11, selected_y + 6, 1, 3, ink);
|
||||
rectangle(x + 12, selected_y + 7, 1, 1, ink);
|
||||
static const char *const labels[] = {"TEAM", "BAG", "SAVE", "CLOSE"};
|
||||
for (int i = 0; i < MENU_COUNT; ++i) large_text(x + 20, y + 33 + i * 16, labels[i], ink);
|
||||
text(x + 8, y + 126, "UP DOWN", ink);
|
||||
text(x + 8, y + 133, "A SELECT", ink);
|
||||
text(x + 8, y + 142, "B START CLOSE", ink);
|
||||
} else {
|
||||
int saved = save_menu.phase == SAVE_MENU_SAVED;
|
||||
large_text(x + 16, y + 37, saved ? "GAME" : "SAVE", ink);
|
||||
large_text(x + 16, y + 55, saved ? "SAVED" : "FAILED", ink);
|
||||
text(x + 8, y + 126, "A B START", ink);
|
||||
text(x + 8, y + 136, "TO CLOSE", ink);
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
#include "game.h"
|
||||
|
||||
static const char save_signature[] __attribute__((used)) = "SRAM_V113";
|
||||
#ifndef GAME_TEST
|
||||
#define SAVE_MEMORY ((volatile unsigned char *)0x0e000000)
|
||||
#endif
|
||||
|
||||
static void configure_sram(void)
|
||||
{
|
||||
#ifndef GAME_TEST
|
||||
volatile u16 *const waitcnt = (volatile u16 *)0x04000204;
|
||||
*waitcnt = (u16)(*waitcnt | 3u); /* SRAM: eight waitstates; preserve ROM timings. */
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Startup relocates this leaf reader; SRAM reads must execute from WRAM. */
|
||||
#ifndef GAME_TEST
|
||||
__attribute__((section(".ewram.text.sram_read"), noinline, long_call))
|
||||
#endif
|
||||
static void read_save_bytes(unsigned char *bytes)
|
||||
{
|
||||
for (int i = 0; i < SAVE_RECORD_SIZE; ++i) bytes[i] = SAVE_MEMORY[i];
|
||||
}
|
||||
|
||||
struct Progress {
|
||||
int partner, given, rod, count, members, active;
|
||||
unsigned char kinds[CAUGHT_CAPACITY];
|
||||
};
|
||||
|
||||
static void clear_progress(struct Progress *p)
|
||||
{
|
||||
p->partner = p->given = p->rod = p->count = p->members = p->active = 0;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) p->kinds[i] = 0xff;
|
||||
}
|
||||
|
||||
static int valid_progress(const struct Progress *p)
|
||||
{
|
||||
if (p->count < 0 || p->count > 99 || (!p->given && p->count != 0) ||
|
||||
p->members < 0 || p->members > CAUGHT_CAPACITY || (p->members && !p->partner) ||
|
||||
p->active < 0 || p->active > p->members || (p->active && !p->partner)) return 0;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i)
|
||||
if (i < p->members ? p->kinds[i] >= SPECIES_COUNT : p->kinds[i] != 0xff) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* CRC-16/CCITT-FALSE: init FFFF, polynomial 1021, high byte first. */
|
||||
TEST_INTERNAL unsigned save_crc(const unsigned char *bytes, int length)
|
||||
{
|
||||
unsigned crc = 0xffff;
|
||||
for (int i = 0; i < length; ++i) {
|
||||
crc ^= (unsigned)bytes[i] << 8;
|
||||
for (int bit = 0; bit < 8; ++bit)
|
||||
crc = ((crc << 1) ^ ((crc & 0x8000) ? 0x1021u : 0u)) & 0xffff;
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
static int read_progress(struct Progress *p, struct Location *location)
|
||||
{
|
||||
unsigned char bytes[SAVE_RECORD_SIZE];
|
||||
configure_sram();
|
||||
read_save_bytes(bytes);
|
||||
clear_progress(p);
|
||||
default_location(location);
|
||||
if (bytes[0] != 'F' || bytes[1] != 'Q' || bytes[2] != 'S' || bytes[3] != 'P') return 0;
|
||||
/* Keep Sprout from the original version-one save format. */
|
||||
if (bytes[4] == 1) {
|
||||
p->partner = bytes[5] == 1 && bytes[6] == 0xa5 && bytes[7] == 0x5a;
|
||||
return p->partner && valid_progress(p);
|
||||
}
|
||||
unsigned flags = bytes[5], count = bytes[6], version = bytes[4];
|
||||
if (flags > (version >= 5 ? 47u : version == 4 ? 7u : 3u)) return 0;
|
||||
if (version == 2) {
|
||||
if (bytes[8] != 0x5a || bytes[7] != (0xa5 ^ 2 ^ flags ^ count)) return 0;
|
||||
} else if (version >= 3 && version <= 6) {
|
||||
unsigned checksum = 0xa5 ^ version ^ flags ^ count ^ bytes[7];
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) {
|
||||
p->kinds[i] = bytes[8 + i];
|
||||
checksum ^= bytes[8 + i];
|
||||
}
|
||||
if (version == 6) {
|
||||
if (save_crc(bytes, 17) != ((unsigned)bytes[17] << 8 | bytes[18])) return 0;
|
||||
location->room = bytes[13]; location->facing = bytes[14];
|
||||
location->x = bytes[15]; location->y = bytes[16];
|
||||
} else if (bytes[14] != 0x5a || bytes[13] != checksum) return 0;
|
||||
p->members = bytes[7];
|
||||
} else return 0;
|
||||
p->partner = !!(flags & 1);
|
||||
p->given = !!(flags & 2);
|
||||
p->rod = !!(flags & 4);
|
||||
p->count = (int)count;
|
||||
p->active = version >= 5 ? (int)(flags >> 3) : 0;
|
||||
return valid_progress(p);
|
||||
}
|
||||
|
||||
void load_progress(void)
|
||||
{
|
||||
struct Progress p;
|
||||
struct Location location;
|
||||
if (!read_progress(&p, &location)) clear_progress(&p);
|
||||
partner_owned = p.partner;
|
||||
balls_given = p.given;
|
||||
rod_owned = p.rod;
|
||||
ball_count = p.count;
|
||||
caught_count = p.members;
|
||||
active_member = p.active;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = p.kinds[i];
|
||||
}
|
||||
|
||||
void saved_location(struct Location *out)
|
||||
{
|
||||
struct Progress p;
|
||||
if (!read_progress(&p, out) || !location_valid(out)) default_location(out);
|
||||
}
|
||||
|
||||
int save_progress(const struct Location *location)
|
||||
{
|
||||
struct Progress p, readback;
|
||||
struct Location restored;
|
||||
p.partner = !!partner_owned;
|
||||
p.given = !!balls_given;
|
||||
p.rod = !!rod_owned;
|
||||
p.count = ball_count;
|
||||
p.members = caught_count;
|
||||
p.active = active_member;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i)
|
||||
p.kinds[i] = i < caught_count ? caught_species[i] : 0xff;
|
||||
if (!valid_progress(&p) || !location_valid(location)) return 0;
|
||||
unsigned char bytes[SAVE_RECORD_SIZE];
|
||||
bytes[0] = 'F'; bytes[1] = 'Q'; bytes[2] = 'S'; bytes[3] = 'P'; bytes[4] = 6;
|
||||
bytes[5] = (unsigned char)(p.partner | (p.given << 1) | (p.rod << 2) | (p.active << 3));
|
||||
bytes[6] = (unsigned char)p.count; bytes[7] = (unsigned char)p.members;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) bytes[8 + i] = p.kinds[i];
|
||||
bytes[13] = (unsigned char)location->room; bytes[14] = (unsigned char)location->facing;
|
||||
bytes[15] = (unsigned char)location->x; bytes[16] = (unsigned char)location->y;
|
||||
unsigned crc = save_crc(bytes, 17);
|
||||
bytes[17] = (unsigned char)(crc >> 8); bytes[18] = (unsigned char)crc;
|
||||
/* Invalidate first, commit last; a single record cannot recover interrupted writes. */
|
||||
configure_sram();
|
||||
SAVE_MEMORY[0] = 0;
|
||||
for (int i = 1; i < SAVE_RECORD_SIZE; ++i) SAVE_MEMORY[i] = bytes[i];
|
||||
SAVE_MEMORY[0] = 'F';
|
||||
if (!read_progress(&readback, &restored) || p.partner != readback.partner || p.given != readback.given ||
|
||||
p.rod != readback.rod || p.count != readback.count || p.members != readback.members ||
|
||||
p.active != readback.active || location->room != restored.room ||
|
||||
location->x != restored.x || location->y != restored.y || location->facing != restored.facing) return 0;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i)
|
||||
if (p.kinds[i] != readback.kinds[i]) return 0;
|
||||
return 1;
|
||||
}
|
||||
@@ -10,60 +10,11 @@ int active_member;
|
||||
unsigned char caught_species[CAUGHT_CAPACITY];
|
||||
TEST_INTERNAL int ball_gift_conversation = 0;
|
||||
|
||||
/* mGBA detects this marker and provides cartridge SRAM for the gift record. */
|
||||
static const char save_signature[] __attribute__((used)) = "SRAM_V113";
|
||||
#ifndef GAME_TEST
|
||||
#define SAVE_MEMORY ((volatile unsigned char *)0x0e000000)
|
||||
#endif
|
||||
|
||||
void load_progress(void)
|
||||
{
|
||||
partner_owned = ball_count = balls_given = caught_count = 0;
|
||||
rod_owned = 0;
|
||||
active_member = 0;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = 0xff;
|
||||
if (SAVE_MEMORY[0] != 'F' || SAVE_MEMORY[1] != 'Q' ||
|
||||
SAVE_MEMORY[2] != 'S' || SAVE_MEMORY[3] != 'P') return;
|
||||
/* Keep Sprout from the original version-one save format. */
|
||||
if (SAVE_MEMORY[4] == 1) {
|
||||
partner_owned = SAVE_MEMORY[5] == 1 && SAVE_MEMORY[6] == 0xa5 && SAVE_MEMORY[7] == 0x5a;
|
||||
return;
|
||||
}
|
||||
unsigned flags = SAVE_MEMORY[5], count = SAVE_MEMORY[6];
|
||||
unsigned version = SAVE_MEMORY[4];
|
||||
if (flags > (version == 5 ? 47u : version == 4 ? 7u : 3u) || count > 99 || (!(flags & 2) && count != 0)) return;
|
||||
if (SAVE_MEMORY[4] == 2) {
|
||||
if (SAVE_MEMORY[8] != 0x5a || SAVE_MEMORY[7] != (0xa5 ^ 2 ^ flags ^ count)) return;
|
||||
} else if (version == 3 || version == 4 || version == 5) {
|
||||
unsigned members = SAVE_MEMORY[7];
|
||||
if (members > CAUGHT_CAPACITY || (members && !(flags & 1)) || SAVE_MEMORY[14] != 0x5a)
|
||||
return;
|
||||
if (version == 5 && ((flags >> 3) > members || ((flags >> 3) && !(flags & 1)))) return;
|
||||
unsigned checksum = 0xa5 ^ version ^ flags ^ count ^ members;
|
||||
for (unsigned i = 0; i < CAUGHT_CAPACITY; ++i) {
|
||||
unsigned kind = SAVE_MEMORY[8 + i];
|
||||
if (i < members ? kind >= SPECIES_COUNT : kind != 0xff) return;
|
||||
checksum ^= kind;
|
||||
}
|
||||
if (SAVE_MEMORY[13] != checksum) return;
|
||||
caught_count = (int)members;
|
||||
for (int i = 0; i < caught_count; ++i) caught_species[i] = SAVE_MEMORY[8 + i];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
partner_owned = !!(flags & 1);
|
||||
balls_given = !!(flags & 2);
|
||||
rod_owned = !!(flags & 4);
|
||||
ball_count = (int)count;
|
||||
active_member = version == 5 ? (int)(flags >> 3) : 0;
|
||||
}
|
||||
|
||||
int choose_partner(int member)
|
||||
{
|
||||
if (!partner_owned || battle.phase != BATTLE_OFF || member < 0 || member > caught_count)
|
||||
return 0;
|
||||
active_member = member;
|
||||
save_progress();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -89,29 +40,6 @@ const char *partner_move(void)
|
||||
}
|
||||
}
|
||||
|
||||
void save_progress(void)
|
||||
{
|
||||
unsigned flags = (partner_owned ? 1u : 0u) | (balls_given ? 2u : 0u) | (rod_owned ? 4u : 0u) | ((unsigned)active_member << 3);
|
||||
unsigned checksum = 0xa5 ^ 5 ^ flags ^ (unsigned)ball_count ^ (unsigned)caught_count;
|
||||
/* Commit the first magic byte last so an interrupted write is invalid. */
|
||||
SAVE_MEMORY[0] = 0;
|
||||
SAVE_MEMORY[1] = 'Q';
|
||||
SAVE_MEMORY[2] = 'S';
|
||||
SAVE_MEMORY[3] = 'P';
|
||||
SAVE_MEMORY[4] = 5;
|
||||
SAVE_MEMORY[5] = (unsigned char)flags;
|
||||
SAVE_MEMORY[6] = (unsigned char)ball_count;
|
||||
SAVE_MEMORY[7] = (unsigned char)caught_count;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) {
|
||||
unsigned kind = i < caught_count ? caught_species[i] : 0xff;
|
||||
SAVE_MEMORY[8 + i] = (unsigned char)kind;
|
||||
checksum ^= kind;
|
||||
}
|
||||
SAVE_MEMORY[13] = (unsigned char)checksum;
|
||||
SAVE_MEMORY[14] = 0x5a;
|
||||
SAVE_MEMORY[0] = 'F';
|
||||
}
|
||||
|
||||
int has_caught(enum Species kind)
|
||||
{
|
||||
for (int i = 0; i < caught_count; ++i)
|
||||
@@ -188,7 +116,6 @@ TEST_INTERNAL int receive_partner(void)
|
||||
{
|
||||
if (current_room != MELLON_HOUSE || !gift_conversation || partner_owned) return 0;
|
||||
partner_owned = 1;
|
||||
save_progress();
|
||||
reset_follower(PROF_X, PROF_Y + 22);
|
||||
return 1;
|
||||
}
|
||||
@@ -199,7 +126,6 @@ TEST_INTERNAL int receive_balls(void)
|
||||
ball_count += 5;
|
||||
if (ball_count > 99) ball_count = 99;
|
||||
balls_given = 1;
|
||||
save_progress();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -210,7 +136,6 @@ int advance_conversation(int page)
|
||||
if (next == 1 && ball_gift_conversation) receive_balls();
|
||||
if (next == 1 && rod_gift_conversation && current_room == BEACH && !rod_owned) {
|
||||
rod_owned = 1;
|
||||
save_progress();
|
||||
}
|
||||
if (next < 0) rod_gift_conversation = 0;
|
||||
if (next < 0) gift_conversation = ball_gift_conversation = 0;
|
||||
|
||||
+43
-14
@@ -87,6 +87,35 @@ int near_map_exit(int x, int y)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void reset_arrival(int x, int y)
|
||||
{
|
||||
grass_steps = 0;
|
||||
diagonal_fraction = 0;
|
||||
reset_follower(x, y);
|
||||
}
|
||||
|
||||
void default_location(struct Location *out)
|
||||
{
|
||||
out->room = OUTSIDE; out->x = 108; out->y = 103; out->facing = FACING_DOWN;
|
||||
}
|
||||
|
||||
int location_valid(const struct Location *location)
|
||||
{
|
||||
return location && location->room >= OUTSIDE && location->room < ROOM_COUNT &&
|
||||
location->facing >= FACING_DOWN && location->facing <= FACING_RIGHT &&
|
||||
location->x >= 0 && location->x < WIDTH && location->y >= 0 && location->y < HEIGHT &&
|
||||
room_walkable(location->room, location->x, location->y);
|
||||
}
|
||||
|
||||
void enter_location(const struct Location *location, int *x, int *y)
|
||||
{
|
||||
current_room = (enum Room)location->room;
|
||||
*x = location->x; *y = location->y;
|
||||
player_facing = (enum Facing)location->facing;
|
||||
door_open = 0;
|
||||
reset_arrival(*x, *y);
|
||||
}
|
||||
|
||||
/* Walk across a map boundary. Arrivals are away from the return trigger. */
|
||||
TEST_INTERNAL int use_map_exit(int *x, int *y, unsigned keys)
|
||||
{
|
||||
@@ -125,9 +154,7 @@ TEST_INTERNAL int use_map_exit(int *x, int *y, unsigned keys)
|
||||
return 0;
|
||||
}
|
||||
door_open = 0;
|
||||
grass_steps = 0;
|
||||
diagonal_fraction = 0;
|
||||
reset_follower(*x, *y);
|
||||
reset_arrival(*x, *y);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -159,9 +186,7 @@ int use_door(int *x, int *y)
|
||||
}
|
||||
door_open = 0;
|
||||
player_facing = FACING_DOWN;
|
||||
grass_steps = 0;
|
||||
diagonal_fraction = 0;
|
||||
reset_follower(*x, *y);
|
||||
reset_arrival(*x, *y);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -171,20 +196,24 @@ void reset_position(int *x, int *y)
|
||||
*y = indoors() ? 119 : (current_room == ROUTE || current_room == BEACH) ? 60 :
|
||||
current_room == MELLON_GARDEN ? 113 : 103;
|
||||
player_facing = FACING_DOWN;
|
||||
grass_steps = 0;
|
||||
diagonal_fraction = 0;
|
||||
reset_follower(*x, *y);
|
||||
reset_arrival(*x, *y);
|
||||
}
|
||||
|
||||
TEST_INTERNAL int can_walk(int x, int y)
|
||||
{
|
||||
if (current_room == BEACH) {
|
||||
return room_walkable(current_room, x, y);
|
||||
}
|
||||
|
||||
int room_walkable(int room, int x, int y)
|
||||
{
|
||||
if (room < OUTSIDE || room >= ROOM_COUNT) return 0;
|
||||
if (room == BEACH) {
|
||||
if (x < 17 || x > 222 || y < 47 || y > beach_shoreline(x) - 5) return 0;
|
||||
if ((x < 42 || x > 194) && y < 72) return 0; /* Palm trunks. */
|
||||
if (x > 35 && x < 75 && y > 68 && y < 98) return 0; /* Umbrella and towel. */
|
||||
return 1;
|
||||
}
|
||||
if (current_room == ROUTE) {
|
||||
if (room == ROUTE) {
|
||||
if (x < 32 || x > 207 || y < 47 || y > 131) return 0;
|
||||
if (x > 143 && x < 216 && y < 85) return 0; /* Pond. */
|
||||
if (x > 116 && x < 154 && y > 53 && y < 79) return 0; /* Sign. */
|
||||
@@ -193,19 +222,19 @@ TEST_INTERNAL int can_walk(int x, int y)
|
||||
y > RANGER_Y - 9 && y < RANGER_Y + 9) return 0;
|
||||
return 1;
|
||||
}
|
||||
if (indoors()) {
|
||||
if (room == COTTAGE || room == MELLON_HOUSE) {
|
||||
if (x < 34 || x > 205 || y < 75 || y > 131) return 0;
|
||||
if (x > 26 && x < 77 && y < 105) return 0; /* Bed. */
|
||||
if (x > 141 && x < 196 && y < 109) return 0; /* Table. */
|
||||
if (x > 187 && y < 85) return 0; /* Plant. */
|
||||
if (current_room == MELLON_HOUSE && x > PROF_X - 13 && x < PROF_X + 13 &&
|
||||
if (room == MELLON_HOUSE && x > PROF_X - 13 && x < PROF_X + 13 &&
|
||||
y > PROF_Y - 9 && y < PROF_Y + 9) return 0;
|
||||
return 1;
|
||||
}
|
||||
if (x < 17 || x > 222 || y < 47 || y > 131) return 0;
|
||||
if (x > 16 && x < 82 && y > 42 && y < 92) return 0;
|
||||
if (x > 141 && x < 212 && y < 78) return 0;
|
||||
if (current_room == OUTSIDE && x > NPC_X - 13 && x < NPC_X + 13 &&
|
||||
if (room == OUTSIDE && x > NPC_X - 13 && x < NPC_X + 13 &&
|
||||
y > NPC_Y - 9 && y < NPC_Y + 9) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
+39
-20
@@ -12,8 +12,17 @@ void check_partner_selection(void)
|
||||
caught_count = CAUGHT_CAPACITY;
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) caught_species[i] = (unsigned char)i;
|
||||
assert(!choose_partner(-1) && !choose_partner(6));
|
||||
save_from_menu();
|
||||
for (int member = 0; member <= caught_count; ++member) {
|
||||
unsigned char previous[sizeof(test_save)];
|
||||
memcpy(previous, test_save, sizeof(previous));
|
||||
int previous_member = active_member;
|
||||
assert(choose_partner(member));
|
||||
assert(memcmp(previous, test_save, sizeof(previous)) == 0);
|
||||
load_progress();
|
||||
assert(active_member == previous_member);
|
||||
assert(choose_partner(member));
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(active_member == member && rod_owned && ball_count == 5);
|
||||
assert(strcmp(partner_name(), member ? species[member - 1].name : "SPROUT") == 0);
|
||||
@@ -55,13 +64,11 @@ void check_partner_selection(void)
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
/* Reject an out-of-range selection even with a correct checksum. */
|
||||
test_save[5] ^= (5 ^ 6) << 3;
|
||||
test_save[13] ^= (5 ^ 6) << 3;
|
||||
checksum_fixture();
|
||||
load_progress();
|
||||
assert(!partner_owned && active_member == 0);
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[4] = 4;
|
||||
test_save[5] &= 7;
|
||||
test_save[13] ^= 5 ^ 4 ^ (5 << 3);
|
||||
legacy_fixture(4);
|
||||
load_progress();
|
||||
assert(partner_owned && rod_owned && caught_count == 5 && active_member == 0);
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
@@ -84,11 +91,16 @@ void check_fishing(void)
|
||||
assert(begin_conversation(FISHER_X - 14, FISHER_Y));
|
||||
assert(!rod_owned);
|
||||
assert(advance_conversation(0) == 1 && rod_owned);
|
||||
assert(test_save[4] == 5);
|
||||
for (int i = 0; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
dialogue_box(1);
|
||||
write_preview("build/rod-gift-preview.ppm");
|
||||
assert(advance_conversation(1) == -1);
|
||||
load_progress();
|
||||
assert(!rod_owned);
|
||||
assert(begin_conversation(FISHER_X - 14, FISHER_Y));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(rod_owned && !partner_owned);
|
||||
assert(!cast_rod(x, y));
|
||||
assert(begin_conversation(FISHER_X, FISHER_Y));
|
||||
@@ -114,7 +126,9 @@ void check_fishing(void)
|
||||
battle.enemy_hp = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
|
||||
assert(ball_count == 4 && has_caught(TIDEFIN));
|
||||
assert(memcmp(before, test_save, sizeof(before)) == 0);
|
||||
assert(battle_input(A));
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(rod_owned && has_caught(TIDEFIN) && ball_count == 4);
|
||||
draw_team_member(1);
|
||||
@@ -122,9 +136,7 @@ void check_fishing(void)
|
||||
assert(cast_rod(x, y));
|
||||
assert(battle_input(B) && battle_input(A));
|
||||
/* An old save keeps catches and balls without granting a rod. */
|
||||
test_save[4] = 3;
|
||||
test_save[5] &= (unsigned char)~4;
|
||||
test_save[13] ^= 5 ^ 3 ^ 4;
|
||||
legacy_fixture(3);
|
||||
load_progress();
|
||||
assert(!rod_owned && has_caught(TIDEFIN) && ball_count == 4);
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
@@ -160,7 +172,7 @@ void check_catching(void)
|
||||
assert(battle_input(SELECT));
|
||||
assert(ball_count == 4 && caught_count == 0 && battle.turns == 1);
|
||||
assert(battle.notice == NOTICE_BROKE_FREE && battle.sprout_hp == 20);
|
||||
assert(test_save[4] == 5 && test_save[6] == 4);
|
||||
assert(memcmp(before, test_save, sizeof(before)) == 0);
|
||||
assert(!battle_input(0) && ball_count == 4); /* Holding Select cannot throw twice. */
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
@@ -168,7 +180,7 @@ void check_catching(void)
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
write_preview("build/catch-failed-preview.ppm");
|
||||
load_progress();
|
||||
assert(partner_owned && ball_count == 4 && caught_count == 0);
|
||||
assert(partner_owned && ball_count == 5 && caught_count == 0);
|
||||
|
||||
assert(battle_input(RIGHT));
|
||||
assert(battle_input(A) && battle.enemy_hp == 11);
|
||||
@@ -178,7 +190,7 @@ void check_catching(void)
|
||||
copy_pending_rows(visible);
|
||||
assert(battle_input(SELECT)); /* Quarter health is a guaranteed catch. */
|
||||
assert(battle.phase == BATTLE_CAUGHT && battle.sprout_hp == hp);
|
||||
assert(ball_count == 3 && caught_count == 1 && caught_species[0] == FERNFOX);
|
||||
assert(ball_count == 4 && caught_count == 1 && caught_species[0] == FERNFOX);
|
||||
assert(has_caught(FERNFOX) && !has_caught(GOLDEN));
|
||||
draw_battle_hud();
|
||||
assert(pending_pixels() < 16500);
|
||||
@@ -188,10 +200,12 @@ void check_catching(void)
|
||||
draw_battle();
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
write_preview("build/caught-preview.ppm");
|
||||
assert(!battle_input(SELECT) && ball_count == 3 && caught_count == 1);
|
||||
load_progress();
|
||||
assert(ball_count == 3 && caught_count == 1 && caught_species[0] == FERNFOX);
|
||||
assert(!battle_input(SELECT) && ball_count == 4 && caught_count == 1);
|
||||
assert(memcmp(before, test_save, sizeof(before)) == 0);
|
||||
assert(battle_input(A) && battle.phase == BATTLE_OFF);
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(ball_count == 4 && caught_count == 1 && caught_species[0] == FERNFOX);
|
||||
draw_team_member(1);
|
||||
write_preview("build/caught-team-preview.ppm");
|
||||
|
||||
@@ -200,13 +214,14 @@ void check_catching(void)
|
||||
assert(begin_battle(182, 113));
|
||||
battle.enemy_hp = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_CAUGHT);
|
||||
assert(ball_count == 2 && caught_count == 2 && caught_species[1] == GOLDEN);
|
||||
assert(ball_count == 3 && caught_count == 2 && caught_species[1] == GOLDEN);
|
||||
assert(!near_golden(182, 113));
|
||||
assert(battle_input(A));
|
||||
assert(!begin_battle(182, 113));
|
||||
reset_follower(108, 103);
|
||||
render_scene(108, 103);
|
||||
assert(SCREEN[95 * WIDTH + 181] == scenery(181, 95));
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(has_caught(GOLDEN) && !near_golden(182, 113));
|
||||
|
||||
@@ -221,6 +236,7 @@ void check_catching(void)
|
||||
assert(battle_input(A));
|
||||
}
|
||||
assert(caught_count == CAUGHT_CAPACITY && ball_count == 2);
|
||||
save_from_menu();
|
||||
memcpy(before, test_save, sizeof(before));
|
||||
assert(start_battle(FERNFOX));
|
||||
rng = random_state;
|
||||
@@ -245,31 +261,34 @@ void check_catching(void)
|
||||
}
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[7] = 6;
|
||||
test_save[13] ^= 5 ^ 6; /* Valid checksum, invalid party length. */
|
||||
checksum_fixture(); /* Valid CRC, invalid party length. */
|
||||
load_progress();
|
||||
assert(!partner_owned && caught_count == 0);
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[8] = SPECIES_COUNT;
|
||||
test_save[13] ^= FERNFOX ^ SPECIES_COUNT;
|
||||
checksum_fixture();
|
||||
load_progress();
|
||||
assert(!partner_owned && caught_count == 0);
|
||||
memcpy(test_save, before, sizeof(before));
|
||||
test_save[5] &= (unsigned char)~1;
|
||||
test_save[13] ^= 1;
|
||||
checksum_fixture();
|
||||
load_progress();
|
||||
assert(!partner_owned && caught_count == 0); /* No captured team without Sprout. */
|
||||
|
||||
/* A failed attempt can end a battle, and the used ball still stays spent. */
|
||||
/* Loss does not autosave a spent ball: reload restores the last menu save. */
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
partner_owned = balls_given = 1;
|
||||
ball_count = 1;
|
||||
save_from_menu();
|
||||
memcpy(before, test_save, sizeof(before));
|
||||
assert(start_battle(EMBERWING));
|
||||
battle.sprout_hp = 1;
|
||||
random_state = 1;
|
||||
assert(battle_input(SELECT) && battle.phase == BATTLE_LOST && ball_count == 0);
|
||||
assert(memcmp(before, test_save, sizeof(before)) == 0);
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 0 && caught_count == 0);
|
||||
assert(partner_owned && balls_given && ball_count == 1 && caught_count == 0);
|
||||
assert(battle_input(A));
|
||||
ball_count = 1;
|
||||
assert(start_battle(PEBBLIT));
|
||||
|
||||
@@ -209,6 +209,9 @@ int main(void)
|
||||
check_catching();
|
||||
check_fishing();
|
||||
check_partner_selection();
|
||||
check_progress();
|
||||
check_location_save();
|
||||
check_save_menu();
|
||||
assert(test_pixels[0] == 0xbeef);
|
||||
assert(test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
puts("Ball gift/inventory/save migration, wild encounters, battles, following, and map checks passed");
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
#include "test_support.h"
|
||||
|
||||
static void same_location(const struct Location *a, const struct Location *b)
|
||||
{
|
||||
assert(a->room == b->room && a->x == b->x && a->y == b->y && a->facing == b->facing);
|
||||
}
|
||||
|
||||
static void team_loaded(void)
|
||||
{
|
||||
assert(partner_owned && balls_given && rod_owned && ball_count == 3 &&
|
||||
caught_count == 2 && active_member == 2);
|
||||
assert(caught_species[0] == FERNFOX && caught_species[1] == TIDEFIN);
|
||||
for (int i = 2; i < CAUGHT_CAPACITY; ++i) assert(caught_species[i] == 0xff);
|
||||
}
|
||||
|
||||
void check_location_save(void)
|
||||
{
|
||||
assert(save_crc((const unsigned char *)"123456789", 9) == 0x29b1);
|
||||
struct Location fallback, restored;
|
||||
default_location(&fallback);
|
||||
assert(location_valid(&fallback));
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
partner_owned = balls_given = rod_owned = 1;
|
||||
ball_count = 3; caught_count = active_member = 2;
|
||||
caught_species[0] = FERNFOX; caught_species[1] = TIDEFIN;
|
||||
struct Location beach = {BEACH, 120, 100, FACING_RIGHT};
|
||||
save_at_menu(&beach, SAVE_MENU_SAVED);
|
||||
/* Golden bytes calculated independently with Python binascii.crc_hqx(..., 0xffff). */
|
||||
const unsigned char golden[] = {'F','Q','S','P',6,0x17,3,2,1,4,255,255,255,5,3,120,100,0xa1,0xa4};
|
||||
assert(memcmp(test_save, golden, sizeof(golden)) == 0);
|
||||
unsigned char saved[sizeof(test_save)], fixture[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
const int positions[ROOM_COUNT][2][2] = {
|
||||
{{108,103},{222,131}}, {{120,119},{80,75}}, {{108,60},{207,131}},
|
||||
{{31,113},{177,83}}, {{120,119},{80,75}}, {{108,60},{120,103}}
|
||||
};
|
||||
for (int room = 0; room < ROOM_COUNT; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
int x, y;
|
||||
reset_position(&x, &y);
|
||||
struct Location spawn = {room, x, y, FACING_DOWN};
|
||||
assert(location_valid(&spawn));
|
||||
for (int edge = 0; edge < 2; ++edge)
|
||||
for (int facing = FACING_DOWN; facing <= FACING_RIGHT; ++facing) {
|
||||
struct Location here = {room, positions[room][edge][0], positions[room][edge][1], facing};
|
||||
assert(location_valid(&here));
|
||||
save_at_menu(&here, SAVE_MENU_SAVED);
|
||||
partner_owned = balls_given = rod_owned = caught_count = active_member = ball_count = 0;
|
||||
load_progress();
|
||||
team_loaded();
|
||||
saved_location(&restored);
|
||||
same_location(&here, &restored);
|
||||
door_open = grass_steps = diagonal_fraction = 7;
|
||||
follower_ready = 0;
|
||||
enter_location(&restored, &x, &y);
|
||||
assert((int)current_room == room && x == here.x && y == here.y && (int)player_facing == facing);
|
||||
assert(!door_open && !grass_steps && !diagonal_fraction && follower_ready && !trail_head);
|
||||
assert(follower_x == x && follower_y == y);
|
||||
move_follower(x, y, x + 1, y);
|
||||
assert(follower_x == x && follower_y == y);
|
||||
}
|
||||
}
|
||||
/* Walking, turning, doors, map exits and unsaved inventory cannot replace A. */
|
||||
save_at_menu(&fallback, SAVE_MENU_SAVED);
|
||||
memcpy(fixture, test_save, sizeof(fixture));
|
||||
int x, y;
|
||||
enter_location(&fallback, &x, &y);
|
||||
walk_movement(RIGHT, &x, &y, 2);
|
||||
ball_count = 1; rod_owned = 0; active_member = 0;
|
||||
x = 177; y = 83; assert(use_door(&x, &y));
|
||||
y = 125; assert(use_door(&x, &y));
|
||||
x = 108; y = 131; assert(use_map_exit(&x, &y, DOWN));
|
||||
assert(memcmp(fixture, test_save, sizeof(fixture)) == 0);
|
||||
load_progress(); team_loaded(); saved_location(&restored); same_location(&fallback, &restored);
|
||||
|
||||
for (int version = 1; version <= 5; ++version) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
legacy_fixture(version);
|
||||
memcpy(fixture, test_save, sizeof(fixture));
|
||||
load_progress(); saved_location(&restored);
|
||||
assert(partner_owned && balls_given == (version >= 2) && ball_count == (version >= 2 ? 3 : 0));
|
||||
assert(rod_owned == (version >= 4) && caught_count == (version >= 3 ? 2 : 0));
|
||||
assert(active_member == (version == 5 ? 2 : 0));
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i)
|
||||
assert(caught_species[i] == (version >= 3 && i < 2 ? saved[8 + i] : 0xff));
|
||||
same_location(&fallback, &restored);
|
||||
assert(memcmp(fixture, test_save, sizeof(fixture)) == 0);
|
||||
}
|
||||
for (int damage = 0; damage < SAVE_RECORD_SIZE * 2; ++damage) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
if (damage < SAVE_RECORD_SIZE) test_save[damage] ^= 1;
|
||||
else if (damage == SAVE_RECORD_SIZE) { test_save[4] = 7; checksum_fixture(); }
|
||||
else {
|
||||
int cut = damage - SAVE_RECORD_SIZE;
|
||||
memset(test_save + cut, 0xff, sizeof(test_save) - (unsigned)cut);
|
||||
}
|
||||
memcpy(fixture, test_save, sizeof(fixture));
|
||||
load_progress(); saved_location(&restored);
|
||||
assert(!partner_owned && !balls_given && !rod_owned && !ball_count && !caught_count && !active_member);
|
||||
same_location(&fallback, &restored);
|
||||
assert(memcmp(fixture, test_save, sizeof(fixture)) == 0);
|
||||
}
|
||||
const unsigned char bad_progress[][2] = {{5,0x57}, {6,100}, {7,6}, {8,SPECIES_COUNT}, {12,0}, {5,0x1f}};
|
||||
for (unsigned i = 0; i < sizeof(bad_progress) / sizeof(bad_progress[0]); ++i) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[bad_progress[i][0]] = bad_progress[i][1];
|
||||
checksum_fixture();
|
||||
memcpy(fixture, test_save, sizeof(fixture));
|
||||
load_progress(); saved_location(&restored);
|
||||
assert(!partner_owned && !caught_count && !ball_count);
|
||||
same_location(&fallback, &restored);
|
||||
assert(memcmp(fixture, test_save, sizeof(fixture)) == 0);
|
||||
}
|
||||
const struct Location invalid[] = {
|
||||
{ROOM_COUNT,108,103,0}, {-1,108,103,0}, {OUTSIDE,108,103,4}, {OUTSIDE,108,103,-1},
|
||||
{256,108,103,0}, {OUTSIDE,108,103,256},
|
||||
{OUTSIDE,-1,103,0}, {OUTSIDE,256,103,0}, {OUTSIDE,108,-1,0}, {OUTSIDE,108,256,0},
|
||||
{OUTSIDE,255,103,0}, {OUTSIDE,108,255,0}, {COTTAGE,25,120,0}, {BEACH,120,130,0},
|
||||
{ROUTE,180,60,0}, {OUTSIDE,NPC_X,NPC_Y,0}, {MELLON_HOUSE,PROF_X,PROF_Y,0}
|
||||
};
|
||||
for (unsigned i = 0; i < sizeof(invalid) / sizeof(invalid[0]); ++i) {
|
||||
assert(!location_valid(&invalid[i]));
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[13] = (unsigned char)invalid[i].room; test_save[14] = (unsigned char)invalid[i].facing;
|
||||
test_save[15] = (unsigned char)invalid[i].x; test_save[16] = (unsigned char)invalid[i].y;
|
||||
checksum_fixture();
|
||||
memcpy(fixture, test_save, sizeof(fixture));
|
||||
load_progress(); saved_location(&restored); team_loaded(); same_location(&fallback, &restored);
|
||||
assert(memcmp(fixture, test_save, sizeof(fixture)) == 0);
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
enter_location(&beach, &x, &y);
|
||||
struct Location bad = invalid[i];
|
||||
save_at_menu(&bad, SAVE_MENU_FAILED);
|
||||
same_location(&bad, &invalid[i]); team_loaded();
|
||||
assert(current_room == BEACH && player_facing == FACING_RIGHT && x == beach.x && y == beach.y);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
}
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress(); enter_location(&fallback, &x, &y);
|
||||
puts("Location saves: v6 CRC, all rooms/facings, legacy reads, fallback and no-autosave checks passed");
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
#include "test_support.h"
|
||||
|
||||
static void release_keys(void) { assert(!menu_input(0, 1)); }
|
||||
|
||||
static void press(unsigned keys)
|
||||
{
|
||||
release_keys();
|
||||
assert(menu_input(keys, 1));
|
||||
}
|
||||
|
||||
static void check_submenus(void)
|
||||
{
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
static u16 expected[WIDTH * HEIGHT], zero[WIDTH * HEIGHT];
|
||||
current_room = OUTSIDE;
|
||||
int x = 108, y = 103;
|
||||
player_facing = FACING_UP;
|
||||
partner_owned = caught_count = active_member = ball_count = rod_owned = 0;
|
||||
for (int owned = 0; owned < 2; ++owned) {
|
||||
partner_owned = owned;
|
||||
caught_count = owned ? 2 : 0;
|
||||
caught_species[0] = FERNFOX; caught_species[1] = TIDEFIN;
|
||||
for (int parent = 0; parent < 2; ++parent) {
|
||||
press(parent ? START : SELECT);
|
||||
if (parent) press(A);
|
||||
assert(save_menu.phase == SAVE_MENU_TEAM);
|
||||
assert(!menu_input(parent ? A : SELECT, 1));
|
||||
draw_menu_scene(x, y);
|
||||
write_preview(owned ? "build/menu-team-owned-preview.ppm" : "build/menu-team-empty-preview.ppm");
|
||||
if (owned) {
|
||||
press(LEFT); assert(!menu_input(LEFT, 1));
|
||||
press(RIGHT); press(LEFT);
|
||||
draw_menu_scene(x, y);
|
||||
write_preview("build/menu-team-caught-preview.ppm");
|
||||
press(A);
|
||||
assert(active_member == 2);
|
||||
} else {
|
||||
int fx = follower_x, fy = follower_y, head = trail_head;
|
||||
press(B);
|
||||
assert(follower_x == fx && follower_y == fy && trail_head == head);
|
||||
}
|
||||
assert(save_menu.phase == (parent ? SAVE_MENU_OPTIONS : SAVE_MENU_CLOSED));
|
||||
assert(!menu_input(owned ? A : B, 1));
|
||||
if (parent) {
|
||||
render_scene(x, y); draw_save_menu();
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
draw_team(); draw_menu_scene(x, y);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
press(A); press(SELECT);
|
||||
assert(save_menu.phase == SAVE_MENU_OPTIONS);
|
||||
press(B);
|
||||
}
|
||||
render_scene(x, y); memcpy(expected, SCREEN, sizeof(expected));
|
||||
draw_bag(); draw_menu_scene(x, y);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
}
|
||||
}
|
||||
press(START);
|
||||
for (int i = 1; i <= MENU_COUNT; ++i) {
|
||||
press(DOWN); assert(save_menu.selection == i % MENU_COUNT);
|
||||
assert(!menu_input(DOWN, 1));
|
||||
}
|
||||
press(DOWN); press(A);
|
||||
assert(save_menu.phase == SAVE_MENU_BAG);
|
||||
assert(!menu_input(A, 1));
|
||||
for (int full = 0; full < 2; ++full) {
|
||||
ball_count = full ? 99 : 0; rod_owned = full;
|
||||
test_pixels[0] = test_pixels[WIDTH * HEIGHT + 1] = 0xbeef;
|
||||
reset_dirty_rows(); draw_menu_scene(x, y);
|
||||
assert(pending_pixels() == WIDTH * HEIGHT);
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
write_preview(full ? "build/bag-full-preview.ppm" : "build/bag-zero-preview.ppm");
|
||||
if (!full) memcpy(zero, SCREEN, sizeof(zero));
|
||||
else assert(memcmp(zero, SCREEN, sizeof(zero)) != 0);
|
||||
}
|
||||
press(B); assert(save_menu.phase == SAVE_MENU_OPTIONS);
|
||||
assert(!menu_input(B, 1));
|
||||
press(A); press(START);
|
||||
assert(save_menu.phase == SAVE_MENU_CLOSED && !menu_input(START, 1));
|
||||
press(SELECT); press(START);
|
||||
assert(save_menu.phase == SAVE_MENU_CLOSED);
|
||||
assert(x == 108 && y == 103 && player_facing == FACING_UP && current_room == OUTSIDE);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
load_progress();
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_CLOSED, 0, 0};
|
||||
}
|
||||
|
||||
static void check_highlight_redraw(void)
|
||||
{
|
||||
static u16 before[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
enum Room old_room = current_room;
|
||||
for (int from = SAVE_MENU_CLOSED; from <= SAVE_MENU_BAG; ++from)
|
||||
for (int to = SAVE_MENU_CLOSED; to <= SAVE_MENU_BAG; ++to)
|
||||
assert(menu_redraw_is_panel((enum SaveMenuPhase)from, (enum SaveMenuPhase)to) ==
|
||||
(from <= SAVE_MENU_FAILED && to <= SAVE_MENU_FAILED &&
|
||||
(from != SAVE_MENU_CLOSED || to != SAVE_MENU_CLOSED)));
|
||||
for (int room = OUTSIDE; room < ROOM_COUNT; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
for (int up = 0; up < 2; ++up) {
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_OPTIONS, 0, 0};
|
||||
draw_menu_scene(108, 103);
|
||||
copy_pending_rows(visible);
|
||||
for (int step = 0; step < MENU_COUNT; ++step) {
|
||||
memcpy(before, SCREEN, sizeof(before));
|
||||
enum SaveMenuPhase previous = save_menu.phase;
|
||||
press(up ? UP : DOWN);
|
||||
assert(save_menu.selection == (up ? (MENU_COUNT - step - 1) % MENU_COUNT : (step + 1) % MENU_COUNT));
|
||||
assert(menu_redraw_is_panel(previous, save_menu.phase));
|
||||
assert(!menu_input(up ? UP : DOWN, 1));
|
||||
reset_dirty_rows();
|
||||
test_pixels[0] = test_pixels[WIDTH * HEIGHT + 1] = 0xbeef;
|
||||
draw_save_menu();
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
for (int y = 0; y < HEIGHT; ++y)
|
||||
for (int x = 0; x < WIDTH; ++x)
|
||||
if (x < SAVE_MENU_X || x >= SAVE_MENU_X + SAVE_MENU_W ||
|
||||
y < SAVE_MENU_Y || y >= SAVE_MENU_Y + SAVE_MENU_H)
|
||||
assert(SCREEN[y * WIDTH + x] == before[y * WIDTH + x]);
|
||||
assert(memcmp(before, SCREEN, sizeof(before)) != 0);
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(visible, SCREEN, sizeof(visible)) == 0);
|
||||
if (room == OUTSIDE && !up) {
|
||||
const char *paths[] = {"build/highlight-team-preview.ppm", "build/highlight-bag-preview.ppm",
|
||||
"build/highlight-save-preview.ppm", "build/highlight-close-preview.ppm"};
|
||||
write_preview(paths[save_menu.selection]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
current_room = old_room;
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_CLOSED, 0, 0};
|
||||
}
|
||||
|
||||
static void check_panel_underlay(void)
|
||||
{
|
||||
static u16 expected[WIDTH * HEIGHT], visible[WIDTH * HEIGHT];
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
partner_owned = caught_count = 1; active_member = 0;
|
||||
caught_species[0] = TIDEFIN;
|
||||
for (int room = OUTSIDE; room < ROOM_COUNT; ++room)
|
||||
for (int facing = FACING_DOWN; facing <= FACING_RIGHT; ++facing) {
|
||||
current_room = (enum Room)room;
|
||||
player_facing = (enum Facing)facing;
|
||||
int x = indoors() ? 200 : room == ROUTE ? 207 : 210;
|
||||
int y = room == BEACH ? 85 : 119;
|
||||
reset_follower(x - 14, y);
|
||||
render_scene(x, y);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
copy_pending_rows(visible);
|
||||
int fx = follower_x, fy = follower_y, head = trail_head;
|
||||
for (int phase = SAVE_MENU_OPTIONS; phase <= SAVE_MENU_FAILED; ++phase) {
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_CLOSED, 0, 0};
|
||||
if (room == OUTSIDE && facing == FACING_DOWN && phase == SAVE_MENU_OPTIONS)
|
||||
write_preview("build/panel-before-preview.ppm");
|
||||
press(START);
|
||||
assert(menu_redraw_is_panel(SAVE_MENU_CLOSED, save_menu.phase));
|
||||
draw_menu_panel(SAVE_MENU_CLOSED);
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
copy_pending_rows(visible);
|
||||
assert(!menu_input(START, 1));
|
||||
for (int py = 0; py < HEIGHT; ++py)
|
||||
for (int px = 0; px < WIDTH; ++px)
|
||||
if (px < SAVE_MENU_X || px >= SAVE_MENU_X + SAVE_MENU_W ||
|
||||
py < SAVE_MENU_Y || py >= SAVE_MENU_Y + SAVE_MENU_H)
|
||||
assert(SCREEN[py * WIDTH + px] == expected[py * WIDTH + px]);
|
||||
save_menu.phase = (enum SaveMenuPhase)phase;
|
||||
draw_menu_panel(SAVE_MENU_OPTIONS);
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
copy_pending_rows(visible);
|
||||
if (room == OUTSIDE && facing == FACING_DOWN && phase == SAVE_MENU_OPTIONS)
|
||||
write_preview("build/panel-open-preview.ppm");
|
||||
unsigned close = phase == SAVE_MENU_OPTIONS ? B : phase == SAVE_MENU_SAVED ? A : START;
|
||||
press(close);
|
||||
assert(save_menu.phase == SAVE_MENU_CLOSED);
|
||||
assert(menu_redraw_is_panel((enum SaveMenuPhase)phase, save_menu.phase));
|
||||
draw_menu_panel((enum SaveMenuPhase)phase);
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(expected, visible, sizeof(expected)) == 0);
|
||||
assert(!menu_input(close, 1));
|
||||
if (room == OUTSIDE && facing == FACING_DOWN && phase == SAVE_MENU_OPTIONS)
|
||||
write_preview("build/panel-closed-preview.ppm");
|
||||
}
|
||||
assert(player_facing == (enum Facing)facing && follower_x == fx && follower_y == fy && trail_head == head);
|
||||
/* A partner change on a fullscreen page must replace, not reuse, old underlay. */
|
||||
press(START); draw_menu_panel(SAVE_MENU_CLOSED);
|
||||
press(A); assert(save_menu.phase == SAVE_MENU_TEAM); draw_menu_scene(x, y);
|
||||
press(RIGHT); release_keys();
|
||||
const struct Location here = {room, x, y, facing};
|
||||
assert(save_menu_input(A, 1, &here));
|
||||
assert(active_member == 1 && save_menu.phase == SAVE_MENU_OPTIONS);
|
||||
render_scene(x, y); memcpy(expected, SCREEN, sizeof(expected));
|
||||
draw_menu_scene(x, y); copy_pending_rows(visible);
|
||||
press(B); draw_menu_panel(SAVE_MENU_OPTIONS);
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(expected, visible, sizeof(expected)) == 0);
|
||||
press(START); draw_menu_panel(SAVE_MENU_CLOSED);
|
||||
press(DOWN); press(A); assert(save_menu.phase == SAVE_MENU_BAG);
|
||||
draw_menu_scene(x, y);
|
||||
press(B); draw_menu_scene(x, y); copy_pending_rows(visible);
|
||||
press(B); draw_menu_panel(SAVE_MENU_OPTIONS);
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
copy_pending_rows(visible);
|
||||
assert(memcmp(expected, visible, sizeof(expected)) == 0);
|
||||
active_member = 0;
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
}
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
load_progress();
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_CLOSED, 0, 0};
|
||||
}
|
||||
|
||||
void check_save_menu(void)
|
||||
{
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_CLOSED, 0, 0};
|
||||
for (int mode = 0; mode < 3; ++mode) {
|
||||
release_keys();
|
||||
assert(!menu_input(START, 0));
|
||||
assert(!menu_input(START, 1));
|
||||
}
|
||||
release_keys();
|
||||
assert(menu_input(START | A, 1));
|
||||
assert(save_menu.phase == SAVE_MENU_OPTIONS && save_menu.selection == 0);
|
||||
assert(!menu_input(A, 1));
|
||||
release_keys();
|
||||
assert(menu_input(DOWN, 1) && save_menu.selection == 1);
|
||||
assert(!menu_input(DOWN, 1));
|
||||
release_keys();
|
||||
assert(!menu_input(UP | DOWN, 1));
|
||||
release_keys();
|
||||
assert(menu_input(UP, 1) && save_menu.selection == 0);
|
||||
release_keys();
|
||||
assert(menu_input(UP, 1) && save_menu.selection == MENU_CLOSE);
|
||||
release_keys();
|
||||
assert(menu_input(A, 1) && save_menu.phase == SAVE_MENU_CLOSED);
|
||||
const unsigned cancel[] = {B, START};
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
release_keys();
|
||||
assert(menu_input(START, 1));
|
||||
release_keys();
|
||||
assert(menu_input(cancel[i], 1) && save_menu.phase == SAVE_MENU_CLOSED);
|
||||
assert(!menu_input(cancel[i], 1));
|
||||
}
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
release_keys();
|
||||
assert(menu_input(START, 1));
|
||||
for (int i = 0; i < MENU_SAVE; ++i) {
|
||||
release_keys();
|
||||
assert(menu_input(DOWN, 1));
|
||||
}
|
||||
release_keys();
|
||||
assert(menu_input(A, 1) && save_menu.phase == SAVE_MENU_SAVED);
|
||||
test_save[0] = 0;
|
||||
for (int i = 0; i < 10; ++i) assert(!menu_input(A, 1));
|
||||
assert(test_save[0] == 0 && save_menu.phase == SAVE_MENU_SAVED);
|
||||
release_keys();
|
||||
assert(!menu_input(DOWN, 1));
|
||||
release_keys();
|
||||
assert(menu_input(A, 1) && save_menu.phase == SAVE_MENU_CLOSED);
|
||||
assert(!menu_input(A, 1));
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
|
||||
static u16 expected[WIDTH * HEIGHT];
|
||||
enum Room old_room = current_room;
|
||||
int old_fx = follower_x, old_fy = follower_y, old_ready = follower_ready;
|
||||
unsigned rng = random_state;
|
||||
int grass = grass_steps, door = door_open;
|
||||
for (int room = OUTSIDE; room <= BEACH; ++room) {
|
||||
current_room = (enum Room)room;
|
||||
render_scene(108, 103);
|
||||
memcpy(expected, SCREEN, sizeof(expected));
|
||||
for (int phase = SAVE_MENU_OPTIONS; phase <= SAVE_MENU_FAILED; ++phase) {
|
||||
save_menu.phase = (enum SaveMenuPhase)phase;
|
||||
for (int choice = 0; choice < MENU_COUNT; ++choice) {
|
||||
save_menu.selection = choice;
|
||||
test_pixels[0] = test_pixels[WIDTH * HEIGHT + 1] = 0xbeef;
|
||||
reset_dirty_rows();
|
||||
draw_save_menu();
|
||||
assert(pending_pixels() == SAVE_MENU_W * SAVE_MENU_H);
|
||||
for (int y = 0; y < HEIGHT; ++y) {
|
||||
int row = y >= SAVE_MENU_Y && y < SAVE_MENU_Y + SAVE_MENU_H;
|
||||
if (row) {
|
||||
assert(dirty_first[y] == SAVE_MENU_X);
|
||||
assert(dirty_end[y] == SAVE_MENU_X + SAVE_MENU_W);
|
||||
} else assert(dirty_first[y] >= dirty_end[y]);
|
||||
for (int x = 0; x < WIDTH; ++x)
|
||||
if (!row || x < SAVE_MENU_X || x >= SAVE_MENU_X + SAVE_MENU_W)
|
||||
assert(SCREEN[y * WIDTH + x] == expected[y * WIDTH + x]);
|
||||
}
|
||||
assert(test_pixels[0] == 0xbeef && test_pixels[WIDTH * HEIGHT + 1] == 0xbeef);
|
||||
if (room == OUTSIDE && choice == 0) {
|
||||
const char *paths[] = {"build/save-menu-preview.ppm",
|
||||
"build/game-saved-preview.ppm", "build/save-failed-preview.ppm"};
|
||||
write_preview(paths[phase - SAVE_MENU_OPTIONS]);
|
||||
}
|
||||
if (room == OUTSIDE && phase == SAVE_MENU_OPTIONS) {
|
||||
const char *paths[] = {"build/menu-team-preview.ppm", "build/menu-bag-preview.ppm",
|
||||
"build/menu-save-preview.ppm", "build/menu-close-preview.ppm"};
|
||||
write_preview(paths[choice]);
|
||||
}
|
||||
}
|
||||
render_scene(108, 103);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
}
|
||||
}
|
||||
assert(follower_x == old_fx && follower_y == old_fy && follower_ready == old_ready);
|
||||
assert(random_state == rng && grass_steps == grass && door_open == door);
|
||||
current_room = old_room;
|
||||
save_menu = (struct SaveMenuState){SAVE_MENU_CLOSED, 0, 0};
|
||||
check_highlight_redraw();
|
||||
check_panel_underlay();
|
||||
check_submenus();
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#include "test_support.h"
|
||||
|
||||
static void assert_empty_progress(void)
|
||||
{
|
||||
assert(!partner_owned && !balls_given && !rod_owned && !ball_count && !caught_count && !active_member);
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) assert(caught_species[i] == 0xff);
|
||||
}
|
||||
|
||||
void check_progress(void)
|
||||
{
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
assert_empty_progress();
|
||||
save_from_menu();
|
||||
const unsigned char empty[] = {'F','Q','S','P',6,0,0,0,255,255,255,255,255,0,0,108,103,0xde,0x32};
|
||||
assert(memcmp(test_save, empty, sizeof(empty)) == 0);
|
||||
partner_owned = balls_given = 1;
|
||||
ball_count = 5;
|
||||
save_from_menu();
|
||||
/* An unsaved expanded team and rod roll back to the previous snapshot. */
|
||||
rod_owned = 1;
|
||||
caught_count = active_member = 1;
|
||||
caught_species[0] = TIDEFIN;
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5 && !rod_owned && !caught_count && !active_member);
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) assert(caught_species[i] == 0xff);
|
||||
rod_owned = 1;
|
||||
caught_count = active_member = 2;
|
||||
caught_species[0] = FERNFOX;
|
||||
caught_species[1] = TIDEFIN;
|
||||
ball_count = 3;
|
||||
save_from_menu();
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
partner_owned = balls_given = rod_owned = caught_count = active_member = ball_count = 0;
|
||||
memset(caught_species, 0xff, sizeof(caught_species));
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && rod_owned && caught_count == 2 && active_member == 2 && ball_count == 3);
|
||||
assert(caught_species[0] == FERNFOX && caught_species[1] == TIDEFIN);
|
||||
|
||||
for (int invalid = 0; invalid < 9; ++invalid) {
|
||||
load_progress();
|
||||
switch (invalid) {
|
||||
case 0: ball_count = -1; break;
|
||||
case 1: ball_count = 100; break;
|
||||
case 2: balls_given = 0; break;
|
||||
case 3: caught_count = -1; break;
|
||||
case 4: caught_count = CAUGHT_CAPACITY + 1; break;
|
||||
case 5: partner_owned = 0; break;
|
||||
case 6: active_member = -1; break;
|
||||
case 7: active_member = 3; break;
|
||||
default: caught_species[1] = SPECIES_COUNT; break;
|
||||
}
|
||||
int state[] = {partner_owned, balls_given, rod_owned, ball_count, caught_count, active_member};
|
||||
unsigned char kinds[CAUGHT_CAPACITY];
|
||||
memcpy(kinds, caught_species, sizeof(kinds));
|
||||
assert(!menu_input(0, 1));
|
||||
assert(menu_input(START, 1));
|
||||
for (int i = 0; i < MENU_SAVE; ++i) {
|
||||
assert(!menu_input(0, 1));
|
||||
assert(menu_input(DOWN, 1));
|
||||
}
|
||||
assert(!menu_input(0, 1));
|
||||
assert(menu_input(A, 1) && save_menu.phase == SAVE_MENU_FAILED);
|
||||
int after[] = {partner_owned, balls_given, rod_owned, ball_count, caught_count, active_member};
|
||||
assert(memcmp(state, after, sizeof(state)) == 0);
|
||||
assert(memcmp(kinds, caught_species, sizeof(kinds)) == 0);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
assert(!menu_input(A, 1));
|
||||
assert(!menu_input(0, 1));
|
||||
assert(menu_input(B, 1));
|
||||
}
|
||||
load_progress();
|
||||
partner_owned = 2; balls_given = 7; rod_owned = -1;
|
||||
save_from_menu();
|
||||
assert(partner_owned == 2 && balls_given == 7 && rod_owned == -1);
|
||||
assert(memcmp(saved, test_save, sizeof(saved)) == 0);
|
||||
for (int byte = 0; byte < SAVE_RECORD_SIZE; ++byte) {
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[byte] ^= 1;
|
||||
load_progress();
|
||||
assert_empty_progress();
|
||||
}
|
||||
/* v2 ignores newer trailing bytes and defaults rod, catches and selection. */
|
||||
const unsigned char v2[] = {'F','Q','S','P',2,3,5,0xa1,0x5a};
|
||||
memset(test_save, 0x31, sizeof(test_save));
|
||||
memcpy(test_save, v2, sizeof(v2));
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5 && !rod_owned && !caught_count && !active_member);
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) assert(caught_species[i] == 0xff);
|
||||
assert(memcmp(test_save, v2, sizeof(v2)) == 0 && test_save[14] == 0x31);
|
||||
memset(test_save, 0xff, sizeof(test_save));
|
||||
load_progress();
|
||||
}
|
||||
@@ -22,6 +22,9 @@ class HeaderTests(unittest.TestCase):
|
||||
def test_sram_save_marker_is_in_rom(self):
|
||||
self.assertIn(b"SRAM_V113", self.rom)
|
||||
|
||||
def test_homebrew_code_avoids_classic_nes_override(self):
|
||||
self.assertEqual(self.rom[172:176], b"QST0")
|
||||
|
||||
def test_bad_logo_is_rejected(self):
|
||||
self.rom[4] ^= 1
|
||||
with self.assertRaisesRegex(ValueError, "hardware header"):
|
||||
@@ -54,6 +57,7 @@ class HeaderTests(unittest.TestCase):
|
||||
result = path.read_bytes()
|
||||
self.assertEqual(len(result), 32768)
|
||||
self.assertEqual(result[160:172], b"FIRSTQUEST\0\0")
|
||||
self.assertEqual(result[172:176], b"QST0")
|
||||
header.verify(result)
|
||||
|
||||
|
||||
|
||||
+23
-2
@@ -33,6 +33,11 @@ void check_starter_gift(void)
|
||||
dialogue_box(1);
|
||||
write_preview("build/starter-gift-preview.ppm");
|
||||
assert(!receive_partner()); /* The same gift cannot add a second partner. */
|
||||
for (int i = 0; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
load_progress();
|
||||
assert(!partner_owned);
|
||||
assert(receive_partner());
|
||||
save_from_menu();
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
assert(advance_conversation(1) == -1);
|
||||
@@ -58,6 +63,11 @@ void check_starter_gift(void)
|
||||
partner_owned = 0;
|
||||
load_progress();
|
||||
assert(partner_owned);
|
||||
current_room = MELLON_HOUSE;
|
||||
assert(begin_conversation(PROF_X, PROF_Y + 22) && !gift_conversation);
|
||||
assert(!receive_partner());
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
current_room = OUTSIDE;
|
||||
draw_team();
|
||||
write_preview("build/team-preview.ppm");
|
||||
static u16 expected[WIDTH * HEIGHT];
|
||||
@@ -132,7 +142,13 @@ void check_ball_gift(void)
|
||||
restore(DIALOGUE_X, DIALOGUE_Y, DIALOGUE_W, DIALOGUE_H);
|
||||
actors(99, 97, 0);
|
||||
assert(memcmp(expected, SCREEN, sizeof(expected)) == 0);
|
||||
assert(test_save[4] == 5);
|
||||
assert(test_save[4] == 1 && memcmp(test_save, legacy, sizeof(legacy)) == 0);
|
||||
load_progress();
|
||||
assert(partner_owned && !balls_given && ball_count == 0);
|
||||
assert(begin_conversation(99, 97));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
save_from_menu();
|
||||
assert(test_save[4] == 6);
|
||||
unsigned char saved[sizeof(test_save)];
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
for (int visit = 0; visit < 10; ++visit) {
|
||||
@@ -144,6 +160,9 @@ void check_ball_gift(void)
|
||||
partner_owned = balls_given = ball_count = 0;
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5);
|
||||
assert(begin_conversation(99, 97) && !ball_gift_conversation);
|
||||
assert(!receive_balls());
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
draw_team();
|
||||
write_preview("build/poke-balls-preview.ppm");
|
||||
for (int i = SAVE_RECORD_SIZE; i < (int)sizeof(test_save); ++i) assert(test_save[i] == 0xff);
|
||||
@@ -157,11 +176,13 @@ void check_ball_gift(void)
|
||||
current_room = ROUTE;
|
||||
assert(begin_conversation(99, 97));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(!partner_owned && balls_given && ball_count == 5);
|
||||
current_room = MELLON_HOUSE;
|
||||
assert(begin_conversation(PROF_X, PROF_Y + 22));
|
||||
assert(advance_conversation(0) == 1 && advance_conversation(1) == -1);
|
||||
save_from_menu();
|
||||
load_progress();
|
||||
assert(partner_owned && balls_given && ball_count == 5);
|
||||
memcpy(saved, test_save, sizeof(saved));
|
||||
@@ -173,7 +194,7 @@ void check_ball_gift(void)
|
||||
}
|
||||
memcpy(test_save, saved, sizeof(saved));
|
||||
test_save[6] = 100;
|
||||
test_save[13] ^= (unsigned char)(5 ^ 100); /* Keep checksum valid; count itself is invalid. */
|
||||
checksum_fixture(); /* Keep CRC valid; count itself is invalid. */
|
||||
load_progress();
|
||||
assert(!partner_owned && !balls_given && ball_count == 0);
|
||||
for (int page = 0; page < DIALOGUE_PAGES; ++page)
|
||||
|
||||
@@ -3,6 +3,62 @@
|
||||
u16 test_pixels[WIDTH * HEIGHT + 2];
|
||||
unsigned char test_save[32];
|
||||
|
||||
void save_from_menu(void)
|
||||
{
|
||||
struct Location location;
|
||||
default_location(&location);
|
||||
save_at_menu(&location, SAVE_MENU_SAVED);
|
||||
}
|
||||
|
||||
int menu_input(unsigned keys, int can_open)
|
||||
{
|
||||
struct Location location;
|
||||
default_location(&location);
|
||||
return save_menu_input(keys, can_open, &location);
|
||||
}
|
||||
|
||||
void save_at_menu(const struct Location *location, enum SaveMenuPhase expected)
|
||||
{
|
||||
assert(!save_menu_input(0, 1, location));
|
||||
assert(save_menu_input(START, 1, location) && save_menu.phase == SAVE_MENU_OPTIONS);
|
||||
for (int i = 0; i < MENU_SAVE; ++i) {
|
||||
assert(!save_menu_input(0, 1, location));
|
||||
assert(save_menu_input(DOWN, 1, location));
|
||||
}
|
||||
assert(!save_menu_input(0, 1, location));
|
||||
assert(save_menu_input(A, 1, location) && save_menu.phase == expected);
|
||||
assert(!save_menu_input(0, 1, location));
|
||||
assert(save_menu_input(B, 1, location) && save_menu.phase == SAVE_MENU_CLOSED);
|
||||
assert(!save_menu_input(0, 1, location));
|
||||
}
|
||||
|
||||
void checksum_fixture(void)
|
||||
{
|
||||
if (test_save[4] == 6) {
|
||||
unsigned crc = save_crc(test_save, 17);
|
||||
test_save[17] = (unsigned char)(crc >> 8);
|
||||
test_save[18] = (unsigned char)crc;
|
||||
} else {
|
||||
unsigned checksum = 0xa5 ^ test_save[4] ^ test_save[5] ^ test_save[6];
|
||||
if (test_save[4] >= 3) {
|
||||
checksum ^= test_save[7];
|
||||
for (int i = 0; i < CAUGHT_CAPACITY; ++i) checksum ^= test_save[8 + i];
|
||||
}
|
||||
test_save[test_save[4] == 2 ? 7 : 13] = (unsigned char)checksum;
|
||||
test_save[test_save[4] == 2 ? 8 : 14] = 0x5a;
|
||||
}
|
||||
}
|
||||
|
||||
/* Convert a fixture, never player data, retaining only fields supported by that version. */
|
||||
void legacy_fixture(int version)
|
||||
{
|
||||
test_save[4] = (unsigned char)version;
|
||||
test_save[5] &= version == 5 ? 63 : version == 4 ? 7 : 3;
|
||||
if (version == 1) {
|
||||
test_save[5] = 1; test_save[6] = 0xa5; test_save[7] = 0x5a;
|
||||
} else checksum_fixture();
|
||||
}
|
||||
|
||||
void render_scene(int x, int y)
|
||||
{
|
||||
draw_scene(x, y);
|
||||
|
||||
@@ -27,5 +27,13 @@ void check_music(void);
|
||||
void check_catching(void);
|
||||
void check_fishing(void);
|
||||
void check_partner_selection(void);
|
||||
void check_save_menu(void);
|
||||
void check_progress(void);
|
||||
void save_from_menu(void);
|
||||
int menu_input(unsigned keys, int can_open);
|
||||
void save_at_menu(const struct Location *location, enum SaveMenuPhase expected);
|
||||
void legacy_fixture(int version);
|
||||
void checksum_fixture(void);
|
||||
void check_location_save(void);
|
||||
|
||||
#endif
|
||||
+1
-1
@@ -44,7 +44,7 @@ def main():
|
||||
raise ValueError("Missing cartridge header space")
|
||||
rom[4:160] = LOGO
|
||||
rom[160:172] = b"FIRSTQUEST".ljust(12, b"\0")
|
||||
rom[172:176] = b"FQ01"
|
||||
rom[172:176] = b"QST0"
|
||||
rom[176:178] = b"00"
|
||||
rom[178:189] = bytes([0x96]) + bytes(10)
|
||||
rom[189] = (-0x19 - sum(rom[160:189])) & 0xFF
|
||||
|
||||
Reference in new issue
Block a user