56 lines
3.8 KiB
C
56 lines
3.8 KiB
C
/* Offline renderer. Supply your own private ROM; never distribute that image. */
|
|
#define HOST
|
|
#include "main-en.c"
|
|
#define main upstream_host_main
|
|
#define g_out host_output_path
|
|
#include "host.c"
|
|
#undef main
|
|
#undef g_out
|
|
#include <assert.h>
|
|
#include <sys/stat.h>
|
|
static const char *proof_root;
|
|
static void proof(const char *name,void (*fn)(void),const char *keys){
|
|
static char folder[512];snprintf(folder,sizeof folder,"%s/%s",proof_root,name);mkdir(folder,0700);g_dir=folder;g_frame=0;
|
|
g_seq=keys;g_pos=0;if(!setjmp(g_jb))fn();
|
|
}
|
|
static void fields(void){field_menu(0,0);}
|
|
static void persist(void){set_write("OK");}
|
|
static u32 quantity_result,quantity_owned;
|
|
static void quantity(void){quantity_result=count_add(5001,quantity_owned);}
|
|
int main(int argc,char **argv){
|
|
if(argc!=4)return 2;
|
|
host_flash=malloc(0x1000000);FILE *f=fopen(argv[1],"rb");if(!f)return 3;
|
|
if(fread(host_flash,1,0x1000000,f)!=0x1000000)return 4;fclose(f);
|
|
u32 offset=(u32)strtoul(argv[2],0,0);memcpy((void*)&g_cfg,host_flash+offset+0x140,sizeof g_cfg);
|
|
proof_root=argv[3];for(u32 i=0;i<PAGE;i++)g_ff[i]=255;assert(set_load()==0);g_cur=0;g_act=0;g_napp=0;
|
|
proof("main",main_menu,"nnnc");proof("character",chr_pick,"nbcc");
|
|
proof("character-scroll",chr_pick,"nnnnnnnnnnnnnbcc");
|
|
proof("item",cat_pick,"nnbnncc");proof("points",points_menu,"c");proof("fields",fields,"nc");
|
|
// The picture/quantity screen must not mutate inventory on cancellation.
|
|
u8 snapshot[PAGE];memcpy(snapshot,g_set,PAGE);g_dirty=0;
|
|
proof("cancel",cat_pick,"bnnncc");assert(!memcmp(snapshot,g_set,PAGE));assert(!g_dirty);
|
|
quantity_owned=2;proof("add-three",quantity,"nnb");assert(quantity_result==5);
|
|
quantity_owned=14;proof("capacity",quantity,"nnnnb");assert(quantity_result==15);
|
|
quantity_owned=15;proof("full",quantity,"b");assert(quantity_result==16);
|
|
quantity_owned=0;proof("minimum",quantity,"ppb");assert(quantity_result==1);
|
|
quantity_owned=0;proof("maximum",quantity,"nnnnnnnnnnnnnnnnnb");assert(quantity_result==15);
|
|
quantity_owned=2;proof("quantity-cancel",quantity,"nnc");assert(quantity_result==16);
|
|
// Batch insertion and additive updates exercise the real packed save fields.
|
|
memset(g_set+g_cfg.list_off,0,1280);memset(g_set+g_cfg.count_off,0,320);g_dirty=0;
|
|
proof("insert",cat_pick,"bnnnb");assert(g_dirty);assert(list_len()==1);assert(count_get(0)==4);
|
|
u32 item=list_id(0);g_dirty=0;proof("append",cat_pick,"bnnb");assert(g_dirty);assert(list_id(0)==item);assert(list_len()==1);assert(count_get(0)==7);
|
|
// Cancelling character preview returns to the list without writing any save.
|
|
memcpy(snapshot,g_set,PAGE);u8 *flash_snapshot=malloc(0x1000000);memcpy(flash_snapshot,host_flash,0x1000000);
|
|
proof("character-dial",chr_pick,"bnnpppnncc");assert(!memcmp(snapshot,g_set,PAGE));assert(!memcmp(flash_snapshot,host_flash,0x1000000));
|
|
// Moving from the last row cannot read beyond the catalog. Returning to the
|
|
// list and reopening must keep the item selected in the picture screen.
|
|
char edge[300];edge[0]='b';memset(edge+1,'n',256);strcpy(edge+257,"cbc");
|
|
proof("character-edge",chr_pick,edge);assert(!memcmp(flash_snapshot,host_flash,0x1000000));
|
|
// B applies the character currently pictured, not the originally opened row.
|
|
chr_build(t_stage()>=3u&&t_stage()<=5u?t_stage():5u);u32 expected=rd16(g_cfg.cat_off+8u+28u*g_chr[1]);
|
|
proof("character-confirm",chr_pick,"bnnb");expected=rd16(g_cfg.cat_off+8u+28u*g_chr[2]);assert(t_id()==expected);
|
|
memcpy(host_flash,flash_snapshot,0x1000000);memcpy(g_set,snapshot,PAGE);free(flash_snapshot);
|
|
proof("persist",persist,"b");memset(g_set,0,PAGE);assert(set_load()==0);assert(list_id(0)==item);assert(count_get(0)==7);
|
|
printf("PASS: text lists, picture dial selection and bounds, unchanged flash on cancellation, B commits pictured character, quantity 1..15, additive batch inventory\n");free(host_flash);return 0;
|
|
}
|