Posted By
Harry Potter on 2023-11-24 12:29:18
| AdvSkelVic65: optimizing save game support?
Hi! I am working on updating AdvSkelVic65. Right now, I'm doing very well: I cut down the main executable of the default Vic20 version to 1.80k. Then, I added save game support, and, after some optimizing, the size grew to 2.40k. I am asking for help to optimize the save game code. I am asking for help to optimize it. The related code follows:
-------------- char gamefilename[]="@:advsavegamea,s"; static const unsigned char gamefilenumpos=13, gamefilelen=16; static unsigned char issave; static unsigned char __fastcall__ GetSaveLetter (void) { printtok ("Insert game disk.\n" "Type in letter of the game to "); printtokcr (c?"save":"load"); i=getkey(); if (i<'a' || i>='z'+1) return 0; gamefilename[11]=i; //printscr (gamefilename); return 1; }
static void opengamef (void) { __asm__ ( "\tlda\t#1\n" "\tldx\t#8\n" "\tldy\t_c\n" "\tjsr\tSETLFS\n" "\tlda\t_gamefilelen\n" "\tldx\t#<_gamefilename\n" "\tldy\t#>_gamefilename\n" "\tjsr\tSETNAM\n" "\tjmp\tOPEN\n" //"\tsta\t_i\n" ); }
void vSave (void) { c=1; if (!GetSaveLetter()) return; // s=c; //cbm_open (1, 8, CBM_WRITE, gamefilename); //c=CBM_WRITE; opengamef(); if (cbm_k_readst()) {printscr("Error saving game!"); return;} // cbm_open (CBM_WRITE); cbm_write (1, &Player, sizeof (Player)); cbm_write (1, &CRoom, 1); cbm_close (1); }
void vLoad (void) { c=0; if (!GetSaveLetter()) return; // s=c; //if (cbm_open (1, 8, CBM_READ, gamefilename)) goto err; // cbm_open (CBM_WRITE); //c=CBM_READ; opengamef(); if (cbm_k_readst()) goto err; if (cbm_read2 (1, &Player, sizeof (Player))) goto err; if (cbm_read2 (1, &CRoom, 1)) goto err; cbm_close (1); printtokcr ("Loading succcessful!"); vLook2(); return; err: cbm_close (1); printtokcr ("Error during load: player info might be corrupt!");
} ------------------
The code was written for cc65.
|