The following patch will change the zip (or jzip) save game routine so
it uses a platform independant format.
For example I move saved games between my HP700 (hppa) system at work
and my 486 (Linux or DOS) system at home.
The format used is big-endian (ie. HP, MC68k style), this means that
old saved games made on little-endian (ie. Intel) machines will not be
readable.
If you really want to use old (Intel) format saved games you can
easily produce a special version of the interpretor which reads the
old format and writes the new, which can be used to convert them to
the portable format.
Have fun
Mark Phillips
- -------------------------------------cut here---------------------------------
*** fileio.c.orig Tue Jul 25 14:45:10 1995
- --- fileio.c Wed Sep 6 13:53:49 1995
***************
*** 389,394 ****
- --- 389,427 ----
}/* undo_restore */
/*
+ * Swap the low byte with the high byte in every word of the specified array.
+ * The length is specified in BYTES!
+ */
+ #ifdef __STDC__
+ void swap_bytes(zword_t *ptr, int len)
+ #else
+ void swap_bytes(ptr, len)
+ zword_t *ptr;
+ int len;
+ #endif
+ {
+ unsigned char *pbyte;
+ unsigned char tmp;
+
+ len /= 2; /* Convert length into words. */
+
+ pbyte=(unsigned char*)ptr;
+
+ while(len) {
+ tmp=pbyte[0];
+ pbyte[0]=pbyte[1];
+ pbyte[1]=tmp;
+ pbyte += 2;
+ len--;
+ }
+ return;
+ }
+
+
+
+
+
+ /*
* save_restore
*
* Common save and restore code. Just save or restore the game stack and the
***************
*** 406,411 ****
- --- 439,454 ----
{
FILE *tfp = NULL;
int scripting_flag = 0, status = 0;
+ zword_t zw;
+ int little_endian=0;
+
+ /* Find out if we are big-endian */
+ zw=0x0001;
+ if( *((zbyte_t *)&zw) ) {
+ /* Little-endian (like an Intel 80x86 series chip). */
+ little_endian=1;
+ }
+
/* Open the save file and disable scripting */
***************
*** 429,439 ****
/* Save or restore stack */
if (flag == GAME_SAVE) {
! if (status == 0 && fwrite (stack, sizeof (stack), 1, tfp) != 1)
status = 1;
} else if (flag == GAME_RESTORE) {
if (status == 0 && fread (stack, sizeof (stack), 1, tfp) != 1)
status = 1;
} else if (flag == UNDO_SAVE) {
memmove (undo_stack, stack, sizeof (stack));
} else /* if (flag == UNDO_RESTORE) */
- --- 472,486 ----
/* Save or restore stack */
if (flag == GAME_SAVE) {
! if(little_endian) swap_bytes(stack, sizeof(stack));
! if (status == 0 && fwrite (stack, sizeof (stack), 1, tfp) != 1)
status = 1;
+ if(little_endian) swap_bytes(stack, sizeof(stack));
} else if (flag == GAME_RESTORE) {
+ if(little_endian) swap_bytes(stack, sizeof(stack));
if (status == 0 && fread (stack, sizeof (stack), 1, tfp) != 1)
status = 1;
+ if(little_endian) swap_bytes(stack, sizeof(stack));
} else if (flag == UNDO_SAVE) {
memmove (undo_stack, stack, sizeof (stack));
} else /* if (flag == UNDO_RESTORE) */
- -------------------------------------cut here---------------------------------
-----BEGIN PGP SIGNATURE-----
Version: 2.6.2i
iQCVAgUBMFVyZz5MHbMBc++NAQE/oQP9Emfjz3hR1fo+350BycmhKeol/8TbyHDm
IdnQrepuYWB3KE//jTkOUhSzHtFG0LG5OZrijBRM9pXzVd+eIB3QIq2WZ6Q6wPBf
ZJH9d8lr2XXlloi+ls5Ya3a07V/cdZwtKoDXTXxPQmblFLi40xXTfFkIkUKy8X36
Vx39e3RFJrk=
=oVGQ
-----END PGP SIGNATURE-----
-- Mark Phillips msp@bnr.co.uk