c1541 -attach kasse.d64 -write items || exit 0
c1541 -attach kasse.d64 -write kasse || exit 0
-test: config.o test.o
- cl65 -t c128 config.o test.o -o test
+test: config.o test.o general.o
+ cl65 -t c128 config.o test.o general.o -o test
test-package: test
c1541 -attach test.d64 -delete state || exit 0
* must be called after load_items()
*/
void load_state(){
- FILE* f;
+ FILE * f;
char line[80];
char * sep;
char i, j;
while (!feof(f)) {
fgets(line, 79, f);
sep = strchr(line, '=');
+ if (sep==NULL)
+ continue;
*(line + (sep-line)) = 0;
for (i=0; i< MAX_ITEMS; i++) {
if (strcmp(line, status[i].item_name)==0) {
}
}
}
+ fclose(f);
}
-void save_state(){}
-
+void save_state(){
+ FILE * f;
+ int i;
+
+ f = fopen("state", "w");
+ if (f==NULL){
+ c128_perror(23, "cannot open state file");
+ return;
+ }
+ for (i=0;i<num_items;i++)
+ fprintf(f, "%s=%d\n",status[i].item_name, status[i].times_sold);
+ fclose(f);
+}
+/*
+void dump_state(){
+ FILE * f;
+ char buf[128];
+ int i, len;
+ memset(buf, 0, 128);
+ f = fopen("state", "r");
+ len = fread(buf, 1, 128, f);
+ printf("read %d bytes from state\n", len);
+ fclose(f);
+ for (i=0;i<len;i++)
+ printf("%x ", buf[i]);
+ printf("\n");
+
+}
+*/
void load_config() {
}
int main(){
BYTE i=0;
+ char euro[10];
load_items();
load_state();
- for (; i < num_items; ++i)
- printf("Eintrag %x: %s (%d Cents, %d mal verkauft)\n", i, status[i].item_name, status[i].price, status[i].times_sold);
+ for (i=0; i < num_items; ++i) {
+ printf("%x: %s (%s, %d mal)\n", i, status[i].item_name, format_euro(euro, 9, status[i].price), status[i].times_sold);
+ status[i].times_sold+=10;
+ }
+
+ save_state();
+ load_items();
+ load_state();
+ for (i=0; i < num_items; ++i) {
+ printf("%x: %s (%s, %d mal)\n", i, status[i].item_name, format_euro(euro, 9, status[i].price), status[i].times_sold);
+ }
+
+ printf("strlen(%s)==%d\n", status[1].item_name, strlen(status[1].item_name));
+ printf("%d %d %d\n", status[1].item_name[0], '\r', '\n');
}
\ No newline at end of file