diff --git a/.gitattributes b/.gitattributes index 115ef26..dce9157 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ *.sta filter=lfs diff=lfs merge=lfs -text *.z5 filter=lfs diff=lfs merge=lfs -text +*.z8 filter=lfs diff=lfs merge=lfs -text +*.vec filter=lfs diff=lfs merge=lfs -text diff --git a/ansiterm.c b/ansiterm.c index 52bd580..4d96b32 100644 --- a/ansiterm.c +++ b/ansiterm.c @@ -13,38 +13,38 @@ segment "ansiterm"; typedef struct { - int x; - int y; -} Vector2T; + byte x; + byte y; +} PositionT; -static int _columns = 40; -static int _rows = 25; -static int _xoff = 0; -static int _yoff = 0; -static bool _escFound = false; -static bool _inEscape = false; -static bool _bold = false; -static bool _blink = false; -static bool _reverse = false; -static bool _destructiveBS = false; -static int _foreground = 7; -static int _background = 0; -static int _fColor = 7; -static int _bColor = 0; -static int _number = 0; -static int _parameters[5]; -static int _parameterCount = 0; -static jlStaT *_ansiFont = NULL; -static Vector2T _cursorSave; -static Vector2T _cursor; -static Vector2T *_screenBuffer = NULL; +static byte _columns = 40; +static byte _rows = 25; +static byte _xoff = 0; +static byte _yoff = 0; +static bool _escFound = false; +static bool _inEscape = false; +static bool _bold = false; +static bool _blink = false; +static bool _reverse = false; +static bool _destructiveBS = false; +static byte _foreground = 7; +static byte _background = 0; +static byte _fColor = 7; +static byte _bColor = 0; +static byte _number = 0; +static byte _parameters[5]; +static byte _parameterCount = 0; +static byte _hiddenLines = 0; +static jlStaT *_ansiFont = NULL; +static PositionT _cursorSave; +static PositionT _cursor; +static PositionT *_screenBuffer = NULL; void termDebug(const char *what, ...); bool termParseANSI(char c); void termRenderCharacterAtCursor(byte c); -void termRepaint(void); void termResetSequence(void); void termScrollUp(void); void termUpdateColors(void); @@ -81,13 +81,18 @@ void termDestruciveBackspace(bool dbs) { } -void termGetCursor(int *x, int *y) { +void termGetCursor(byte *x, byte *y) { *x = _cursor.x; *y = _cursor.y; } -void termMoveCursor(int x, int y) { +void termHideTopLines(byte count) { + _hiddenLines = count; +} + + +void termMoveCursor(byte x, byte y) { if (x < 1) { _cursor.x = 1; termDebug("Attempt to position cursor too far left: %d", x); @@ -114,13 +119,13 @@ void termMoveCursor(int x, int y) { bool termParseANSI(char c) { - int x; - int y; - int oldX; - int cx; - int p; - bool updateDisplay = false; - Vector2T cursor = _cursor; + bool x; + bool y; + bool oldX; + bool cx; + int p; + bool updateDisplay = false; + PositionT cursor = _cursor; // Find leading ESC character. if ((c == (char)27) && !_escFound && !_inEscape) { @@ -389,7 +394,7 @@ bool termParseANSI(char c) { default: // Number? if ((c >= '0') && (c <= '9')) { - _number = _number * 10 + (c - '0'); + _number = (byte)(_number * 10 + (c - '0')); } else { termDebug("Unknown sequence: %d", (int)c); termResetSequence(); @@ -489,23 +494,25 @@ void termPrintChar(char c) { void termRenderCharacterAtCursor(byte c) { - int r = (_reverse ? 7 : 0); - int cx = c % 40; - int cy = (c / 40) + r; + byte r = (_reverse ? 7 : 0); + byte cx = c % 40; + byte cy = (c / 40) + r; int i = ((_cursor.y - 1) * _columns) + (_cursor.x - 1); _screenBuffer[i].x = cx; _screenBuffer[i].y = cy; - jlDrawBlit8x8(_ansiFont, cx, cy, _cursor.x - 1 + _xoff, _cursor.y - 1 + _yoff); + if (_cursor.y > _hiddenLines) { + jlDrawBlit8x8(_ansiFont, cx, cy, _cursor.x - 1 + _xoff, _cursor.y - 1 + _yoff); + } } void termRepaint(void) { - int i = 0; + int i = _hiddenLines * _columns; int x; int y; - for (y=0; y<_rows; y++) { + for (y=_hiddenLines; y<_rows; y++) { for (x=0; x<_columns; x++) { - jlDrawBlit8x8(_ansiFont, _screenBuffer[i].x, _screenBuffer[i].y, x, y); + jlDrawBlit8x8(_ansiFont, _screenBuffer[i].x, _screenBuffer[i].y, x + _xoff, y + _yoff); i++; } } @@ -546,7 +553,7 @@ void termScrollUp(void) { } -void termStart(jlStaT *font, int xoff, int yoff, int cols, int rows) { +void termStart(jlStaT *font, byte xoff, byte yoff, byte cols, byte rows) { _ansiFont = font; _xoff = xoff; _yoff = yoff; @@ -556,7 +563,7 @@ void termStart(jlStaT *font, int xoff, int yoff, int cols, int rows) { _cursorSave.y = 1; _cursor.x = 1; _cursor.y = 1; - _screenBuffer = (Vector2T *)jlMalloc(sizeof(Vector2T) * (size_t)(_columns * _rows)); + _screenBuffer = (PositionT *)jlMalloc(sizeof(PositionT) * (size_t)(_columns * _rows)); termClearScreen(); } diff --git a/ansiterm.h b/ansiterm.h index 4519159..7db9d56 100644 --- a/ansiterm.h +++ b/ansiterm.h @@ -5,13 +5,15 @@ void termClearScreen(void); void termDestruciveBackspace(bool dbs); -void termGetCursor(int *x, int *y); -void termMoveCursor(int x, int y); +void termGetCursor(byte *x, byte *y); +void termHideTopLines(byte count); +void termMoveCursor(byte x, byte y); void termPrint(char *string); void termPrintChar(char c); +void termRepaint(void); void termRestoreCursor(void); void termSaveCursor(void); -void termStart(jlStaT *font, int xoff, int yoff, int cols, int rows); +void termStart(jlStaT *font, byte xoff, byte yoff, byte cols, byte rows); void termStop(void); #endif // _H_ANSITERM_ diff --git a/fileio.c b/fileio.c index 7af60ac..8a89fae 100644 --- a/fileio.c +++ b/fileio.c @@ -52,8 +52,8 @@ static FILE *rfp = NULL; /* Record file pointer */ static char gfpbuffer[BUFSIZ]; #endif #endif -static char sfpbuffer[BUFSIZ]; -static char rfpbuffer[BUFSIZ]; +//static char sfpbuffer[BUFSIZ]; +//static char rfpbuffer[BUFSIZ]; char save_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1] = "story.sav"; char script_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1] = "story.scr"; @@ -123,7 +123,8 @@ void set_names( const char *storyname ) void open_story( const char *storyname ) { - char *path, *p; + char *path = NULL; + char *p = NULL; char tmp[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; // if ( !STANDALONE_FLAG ) @@ -297,7 +298,7 @@ void read_page( int page, void *buffer ) #endif { /* Read failed. Are we in the last page? */ - file_size = ( unsigned long ) h_file_size *story_scaler; + file_size = ( unsigned long )(h_file_size *story_scaler); pages = ( unsigned int ) ( ( unsigned long ) file_size / PAGE_SIZE ); offset = ( unsigned int ) ( ( unsigned long ) file_size & PAGE_MASK ); @@ -401,7 +402,7 @@ void z_verify( void ) /* Calculate game file dimensions */ - file_size = ( unsigned long ) h_file_size *story_scaler; + file_size = ( unsigned long )(h_file_size *story_scaler); pages = ( unsigned int ) ( ( unsigned long ) file_size / PAGE_SIZE ); offset = ( unsigned int ) file_size & PAGE_MASK; @@ -410,7 +411,7 @@ void z_verify( void ) for ( i = 0; i <= pages; i++ ) { - read_page( i, buffer ); + read_page( (int)i, buffer ); start = ( i == 0 ) ? 64 : 0; end = ( i == pages ) ? offset : PAGE_SIZE; for ( j = start; j < end; j++ ) @@ -448,7 +449,7 @@ static void get_default_name( char *default_name, zword_t addr ) { addr++; c = get_byte( addr ); - default_name[i] = c; + default_name[i] = (char)c; } default_name[i] = 0; @@ -503,7 +504,7 @@ int z_save( int argc, zword_t table, zword_t bytes, zword_t name ) setbuf( afp, afpbuffer ); #endif - status = fwrite( datap + table, bytes, 1, afp ); + status = (int)fwrite( datap + table, bytes, 1, afp ); fclose( afp ); @@ -591,7 +592,7 @@ int z_restore( int argc, zword_t table, zword_t bytes, zword_t name ) setbuf( afp, afpbuffer ); #endif - status = fread( datap + table, bytes, 1, afp ); + status = (int)fread( datap + table, bytes, 1, afp ); fclose( afp ); @@ -1315,7 +1316,7 @@ int playback_line( int buflen, char *buffer, int *read_size ) { *cp = '\0'; } - *read_size = strlen( buffer ); + *read_size = (int)strlen( buffer ); output_line( buffer ); } diff --git a/gamedata.dat b/gamedata.dat new file mode 100644 index 0000000..8fefff2 --- /dev/null +++ b/gamedata.dat @@ -0,0 +1,3 @@ +IF Engine Test Game +output.z8 +8x8thin.sta diff --git a/gamedata.z5 b/gamedata.z5 deleted file mode 100644 index 474c9d9..0000000 Binary files a/gamedata.z5 and /dev/null differ diff --git a/ifengine.pro b/ifengine.pro index d5bad2b..2fd11d3 100644 --- a/ifengine.pro +++ b/ifengine.pro @@ -45,7 +45,6 @@ INCLUDEPATH += \ HEADERS += \ $$JOEY_HEADERS \ ansiterm.h \ - jzip.h \ ztypes.h SOURCES += \ diff --git a/input.c b/input.c index 2d494e9..6905f50 100644 --- a/input.c +++ b/input.c @@ -1,14 +1,14 @@ -/* $Id: input.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ +/* $Id: input.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ * -------------------------------------------------------------------- - * see doc/License.txt for License Information + * see doc/License.txt for License Information * -------------------------------------------------------------------- - * - * File name: $Id: input.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ - * - * Description: - * - * Modification history: + * + * File name: $Id: input.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ + * + * Description: + * + * Modification history: * $Log: input.c,v $ * Revision 1.3 2000/07/05 15:20:34 jholder * Updated code to remove warnings. @@ -57,63 +57,63 @@ static zword_t find_word( int, const char *, long ); void z_read_char( int argc, zword_t * argv ) { - int c; - zword_t arg_list[2]; + int c; + zword_t arg_list[2]; - /* Supply default parameters */ + /* Supply default parameters */ - if ( argc < 3 ) - argv[2] = 0; - if ( argc < 2 ) - argv[1] = 0; + if ( argc < 3 ) + argv[2] = 0; + if ( argc < 2 ) + argv[1] = 0; - /* Flush any buffered output before read */ + /* Flush any buffered output before read */ - flush_buffer( FALSE ); + flush_buffer( FALSE ); - /* Reset line count */ + /* Reset line count */ - lines_written = 0; + lines_written = 0; - /* If more than one characters was asked for then fail the call */ + /* If more than one characters was asked for then fail the call */ - if ( argv[0] != 1 ) + if ( argv[0] != 1 ) - c = 0; + c = 0; - else - { + else + { - if ( ( c = playback_key( ) ) == -1 ) - { + if ( ( c = playback_key( ) ) == -1 ) + { - /* Setup the timeout routine argument list */ + /* Setup the timeout routine argument list */ - arg_list[0] = argv[2]; - arg_list[1] = 0; /* as per spec 1.0 */ - /* was: arg_list[1] = argv[1]/10; */ + arg_list[0] = argv[2]; + arg_list[1] = 0; /* as per spec 1.0 */ + /* was: arg_list[1] = argv[1]/10; */ - /* Read a character with a timeout. If the input timed out then - * call the timeout action routine. If the return status from the - * timeout routine was 0 then try to read a character again */ + /* Read a character with a timeout. If the input timed out then + * call the timeout action routine. If the return status from the + * timeout routine was 0 then try to read a character again */ - do - { - flush_buffer( FALSE ); - c = input_character( ( int ) argv[1] ); - } - while ( c == -1 && z_call( 1, arg_list, ASYNC ) == 0 ); + do + { + flush_buffer( FALSE ); + c = input_character( ( int ) argv[1] ); + } + while ( c == -1 && z_call( 1, arg_list, ASYNC ) == 0 ); - /* Fail call if input timed out */ + /* Fail call if input timed out */ - if ( c == -1 ) - c = 0; - else - record_key( c ); - } - } + if ( c == -1 ) + c = 0; + else + record_key( c ); + } + } - store_operand( (zword_t)c ); + store_operand( (zword_t)c ); } /* z_read_char */ @@ -131,68 +131,68 @@ void z_read_char( int argc, zword_t * argv ) void z_sread_aread( int argc, zword_t * argv ) { - int i, in_size, out_size, terminator; - char *cbuf, *buffer; + int i, in_size, out_size, terminator; + char *cbuf, *buffer; - /* Supply default parameters */ + /* Supply default parameters */ - if ( argc < 4 ) - argv[3] = 0; - if ( argc < 3 ) - argv[2] = 0; - if ( argc < 2 ) - argv[1] = 0; + if ( argc < 4 ) + argv[3] = 0; + if ( argc < 3 ) + argv[2] = 0; + if ( argc < 2 ) + argv[1] = 0; - /* Refresh status line */ + /* Refresh status line */ - if ( h_type < V4 ) - z_show_status( ); + if ( h_type < V4 ) + z_show_status( ); - /* Flush any buffered output before read */ + /* Flush any buffered output before read */ - flush_buffer( TRUE ); + flush_buffer( TRUE ); - /* Reset line count */ + /* Reset line count */ - lines_written = 0; + lines_written = 0; - /* Initialise character pointer and initial read size */ + /* Initialise character pointer and initial read size */ - cbuf = ( char * ) &datap[argv[0]]; - in_size = ( h_type > V4 ) ? cbuf[1] : 0; + cbuf = ( char * ) &datap[argv[0]]; + in_size = ( h_type > V4 ) ? cbuf[1] : 0; - /* Read the line then script and record it */ + /* Read the line then script and record it */ - terminator = get_line( cbuf, argv[2], argv[3] ); - script_line( ( h_type > V4 ) ? &cbuf[2] : &cbuf[1] ); - record_line( ( h_type > V4 ) ? &cbuf[2] : &cbuf[1] ); + terminator = get_line( cbuf, argv[2], argv[3] ); + script_line( ( h_type > V4 ) ? &cbuf[2] : &cbuf[1] ); + record_line( ( h_type > V4 ) ? &cbuf[2] : &cbuf[1] ); - /* Convert new text in line to lowercase */ + /* Convert new text in line to lowercase */ - if ( h_type > V4 ) - { - buffer = &cbuf[2]; - out_size = cbuf[1]; - } - else - { - buffer = &cbuf[1]; - out_size = strlen( buffer ); - } + if ( h_type > V4 ) + { + buffer = &cbuf[2]; + out_size = cbuf[1]; + } + else + { + buffer = &cbuf[1]; + out_size = (int)strlen( buffer ); + } - if ( out_size > in_size ) - for ( i = in_size; i < out_size; i++ ) - buffer[i] = ( char ) tolower( buffer[i] ); + if ( out_size > in_size ) + for ( i = in_size; i < out_size; i++ ) + buffer[i] = ( char ) tolower( buffer[i] ); - /* Tokenise the line, if a token buffer is present */ + /* Tokenise the line, if a token buffer is present */ - if ( argv[1] ) - tokenise_line( argv[0], argv[1], h_words_offset, 0 ); + if ( argv[1] ) + tokenise_line( argv[0], argv[1], h_words_offset, 0 ); - /* Return the line terminator */ + /* Return the line terminator */ - if ( h_type > V4 ) - store_operand( ( zword_t ) terminator ); + if ( h_type > V4 ) + store_operand( ( zword_t ) terminator ); } /* z_sread_aread */ @@ -205,78 +205,78 @@ void z_sread_aread( int argc, zword_t * argv ) int get_line( char *cbuf, zword_t timeout, zword_t action_routine ) { - char *buffer; - int buflen, read_size, status, c; - zword_t arg_list[2]; + char *buffer; + int buflen, read_size, status, c; + zword_t arg_list[2]; - /* Set maximum buffer size to width of screen minus any - * right margin and 1 character for a terminating NULL */ + /* Set maximum buffer size to width of screen minus any + * right margin and 1 character for a terminating NULL */ - buflen = ( screen_cols > 127 ) ? 127 : screen_cols; - buflen -= right_margin + 1; - if ( ( int ) cbuf[0] <= buflen ) - buflen = cbuf[0]; + buflen = ( screen_cols > 127 ) ? 127 : screen_cols; + buflen -= right_margin + 1; + if ( ( int ) cbuf[0] <= buflen ) + buflen = cbuf[0]; - /* Set read size and start of read buffer. The buffer may already be - * primed with some text in V5 games. The Z-code will have already - * displayed the text so we don't have to do that */ + /* Set read size and start of read buffer. The buffer may already be + * primed with some text in V5 games. The Z-code will have already + * displayed the text so we don't have to do that */ - if ( h_type > V4 ) - { - read_size = cbuf[1]; - buffer = &cbuf[2]; - } - else - { - read_size = 0; - buffer = &cbuf[1]; - } + if ( h_type > V4 ) + { + read_size = cbuf[1]; + buffer = &cbuf[2]; + } + else + { + read_size = 0; + buffer = &cbuf[1]; + } - /* Try to read input from command file */ + /* Try to read input from command file */ - c = playback_line( buflen, buffer, &read_size ); + c = playback_line( buflen, buffer, &read_size ); - if ( c == -1 ) - { + if ( c == -1 ) + { - /* Setup the timeout routine argument list */ + /* Setup the timeout routine argument list */ - arg_list[0] = action_routine; - arg_list[1] = 0; /* as per spec.1.0 */ - /* arg_list[1] = timeout/10; */ + arg_list[0] = action_routine; + arg_list[1] = 0; /* as per spec.1.0 */ + /* arg_list[1] = timeout/10; */ - /* Read a line with a timeout. If the input timed out then - * call the timeout action routine. If the return status from the - * timeout routine was 0 then try to read the line again */ + /* Read a line with a timeout. If the input timed out then + * call the timeout action routine. If the return status from the + * timeout routine was 0 then try to read the line again */ - do - { - c = input_line( buflen, buffer, timeout, &read_size ); - status = 0; - } - while ( c == -1 && ( status = z_call( 1, arg_list, ASYNC ) ) == 0 ); + do + { + c = input_line( buflen, buffer, timeout, &read_size ); + status = 0; + } + while ( c == -1 && ( status = z_call( 1, arg_list, ASYNC ) ) == 0 ); - /* Throw away any input if timeout returns success */ + /* Throw away any input if timeout returns success */ - if ( status ) - read_size = 0; + if ( status ) + read_size = 0; - } + } - /* Zero terminate line */ + /* Zero terminate line */ - if ( h_type > V4 ) - { - cbuf[1] = ( char ) read_size; - } - else - { - /* Zero terminate line (V1-4 only) */ - buffer[read_size] = '\0'; - } + if ( h_type > V4 ) + { + cbuf[1] = ( char ) read_size; + } + else + { + /* Zero terminate line (V1-4 only) */ + buffer[read_size] = '\0'; + } - return ( c ); + return ( c ); } /* get_line */ @@ -295,108 +295,109 @@ int get_line( char *cbuf, zword_t timeout, zword_t action_routine ) static void tokenise_line( zword_t char_buf, zword_t token_buf, zword_t dictionary, zword_t flag ) { - int i, count, words, token_length; - long word_index, chop = 0; - int slen; - char *str_end; - char *cbuf, *tbuf, *tp; - const char *cp, *token; - char punctuation[16]; - zword_t word; + int i, count, words, token_length; + long word_index, chop = 0; + int slen; + char *str_end; + char *cbuf, *tbuf, *tp; + const char *cp, *token; + char punctuation[16]; + zword_t word; - /* Initialise character and token buffer pointers */ + /* Initialise character and token buffer pointers */ - cbuf = ( char * ) &datap[char_buf]; - tbuf = ( char * ) &datap[token_buf]; + cbuf = ( char * ) &datap[char_buf]; + tbuf = ( char * ) &datap[token_buf]; - /* Find the string length */ + /* Find the string length */ - if ( h_type > V4 ) - { - slen = ( unsigned char ) ( cbuf[1] ); - str_end = cbuf + 2 + slen; - } - else - { - slen = strlen( cbuf + 1 ); - str_end = cbuf + 1 + slen; - } + if ( h_type > V4 ) + { + slen = ( unsigned char ) ( cbuf[1] ); + str_end = cbuf + 2 + slen; + } + else + { + slen = (int)strlen( cbuf + 1 ); + str_end = cbuf + 1 + slen; + } - /* Initialise word count and pointers */ + /* Initialise word count and pointers */ - words = 0; - cp = ( h_type > V4 ) ? cbuf + 2 : cbuf + 1; - tp = tbuf + 2; + words = 0; + cp = ( h_type > V4 ) ? cbuf + 2 : cbuf + 1; + tp = tbuf + 2; - /* Initialise dictionary */ + /* Initialise dictionary */ - count = get_byte( dictionary++ ); - for ( i = 0; i < count; i++ ) - punctuation[i] = get_byte( dictionary++ ); - punctuation[i] = '\0'; - entry_size = get_byte( dictionary++ ); - dictionary_size = ( ZINT16 ) get_word( dictionary ); - dictionary_offset = dictionary + 2; + count = get_byte( dictionary++ ); + for ( i = 0; i < count; i++ ) + punctuation[i] = (char)get_byte( dictionary++ ); + punctuation[i] = '\0'; + entry_size = get_byte( dictionary++ ); + dictionary_size = ( ZINT16 ) get_word( dictionary ); + dictionary_offset = dictionary + 2; - /* Calculate the binary chop start position */ + /* Calculate the binary chop start position */ - if ( dictionary_size > 0 ) - { - word_index = dictionary_size / 2; - chop = 1; - do - chop *= 2; - while ( word_index /= 2 ); - } + if ( dictionary_size > 0 ) + { + word_index = dictionary_size / 2; + chop = 1; + do + chop *= 2; + while ( word_index /= 2 ); + } - /* Tokenise the line */ + /* Tokenise the line */ - do - { + do + { - /* Skip to next token */ + /* Skip to next token */ - cp = next_token( cp, str_end, &token, &token_length, punctuation ); - if ( token_length ) + cp = next_token( cp, str_end, &token, &token_length, punctuation ); + if ( token_length ) { - /* If still space in token buffer then store word */ + /* If still space in token buffer then store word */ - if ( words <= tbuf[0] ) - { + if ( words <= tbuf[0] ) + { - /* Get the word offset from the dictionary */ + /* Get the word offset from the dictionary */ - word = find_word( token_length, token, chop ); + word = find_word( token_length, token, chop ); - /* Store the dictionary offset, token length and offset */ + /* Store the dictionary offset, token length and offset */ - if ( word || flag == 0 ) - { - tp[0] = ( char ) ( word >> 8 ); - tp[1] = ( char ) ( word & 0xff ); - } - tp[2] = ( char ) token_length; - tp[3] = ( char ) ( token - cbuf ); + if ( word || flag == 0 ) + { + tp[0] = ( char ) ( word >> 8 ); + tp[1] = ( char ) ( word & 0xff ); + } + tp[2] = ( char ) token_length; + tp[3] = ( char ) ( token - cbuf ); - /* Step to next token position and count the word */ + /* Step to next token position and count the word */ - tp += 4; - words++; - } - else - { + tp += 4; + words++; + } + else + { - /* Moan if token buffer space exhausted */ + /* Moan if token buffer space exhausted */ - output_string( "Too many words typed, discarding: " ); - output_line( token ); - } - } - while ( token_length ); + output_string( "Too many words typed, discarding: " ); + output_line( token ); + } + } + } + while ( token_length ); - /* Store word count */ + /* Store word count */ - tbuf[1] = ( char ) words; + tbuf[1] = ( char ) words; } /* tokenise_line */ @@ -415,71 +416,71 @@ static void tokenise_line( zword_t char_buf, zword_t token_buf, zword_t dictiona */ static const char *next_token( const char *s, const char *str_end, const char **token, int *length, - const char *punctuation ) + const char *punctuation ) { - int i; + int i; - /* Set the token length to zero */ + /* Set the token length to zero */ - *length = 0; + *length = 0; - /* Step through the string looking for separators */ + /* Step through the string looking for separators */ - for ( ; s < str_end; s++ ) - { + for ( ; s < str_end; s++ ) + { - /* Look for game specific word separators first */ + /* Look for game specific word separators first */ - for ( i = 0; punctuation[i] && *s != punctuation[i]; i++ ) - ; + for ( i = 0; punctuation[i] && *s != punctuation[i]; i++ ) + ; - /* If a separator is found then return the information */ + /* If a separator is found then return the information */ - if ( punctuation[i] ) - { + if ( punctuation[i] ) + { - /* If length has been set then just return the word position */ + /* If length has been set then just return the word position */ - if ( *length ) - return ( s ); - else - { + if ( *length ) + return ( s ); + else + { - /* End of word, so set length, token pointer and return string */ + /* End of word, so set length, token pointer and return string */ - ( *length )++; - *token = s; - return ( ++s ); - } - } + ( *length )++; + *token = s; + return ( ++s ); + } + } - /* Look for statically defined separators last */ + /* Look for statically defined separators last */ - for ( i = 0; separators[i] && *s != separators[i]; i++ ) - ; + for ( i = 0; separators[i] && *s != separators[i]; i++ ) + ; - /* If a separator is found then return the information */ + /* If a separator is found then return the information */ - if ( separators[i] ) - { + if ( separators[i] ) + { - /* If length has been set then just return the word position */ + /* If length has been set then just return the word position */ - if ( *length ) - return ( ++s ); - } - else - { + if ( *length ) + return ( ++s ); + } + else + { - /* If first token character then remember its position */ + /* If first token character then remember its position */ - if ( *length == 0 ) - *token = s; - ( *length )++; - } - } + if ( *length == 0 ) + *token = s; + ( *length )++; + } + } - return ( s ); + return ( s ); } /* next_token */ @@ -493,89 +494,89 @@ static const char *next_token( const char *s, const char *str_end, const char ** static zword_t find_word( int len, const char *cp, long chop ) { - ZINT16 word[3]; - long word_index, offset, status; + ZINT16 word[3]; + long word_index, offset, status; - /* Don't look up the word if there are no dictionary entries */ + /* Don't look up the word if there are no dictionary entries */ - if ( dictionary_size == 0 ) - return ( 0 ); + if ( dictionary_size == 0 ) + return ( 0 ); - /* Encode target word */ + /* Encode target word */ - encode_text( len, cp, word ); + encode_text( len, cp, word ); - /* Do a binary chop search on the main dictionary, otherwise do - * a linear search */ + /* Do a binary chop search on the main dictionary, otherwise do + * a linear search */ - word_index = chop - 1; + word_index = chop - 1; - if ( dictionary_size > 0 ) - { + if ( dictionary_size > 0 ) + { - /* Binary chop until the word is found */ + /* Binary chop until the word is found */ - while ( chop ) - { + while ( chop ) + { - chop /= 2; + chop /= 2; - /* Calculate dictionary offset */ + /* Calculate dictionary offset */ - if ( word_index > ( dictionary_size - 1 ) ) - word_index = dictionary_size - 1; + if ( word_index > ( dictionary_size - 1 ) ) + word_index = dictionary_size - 1; - offset = dictionary_offset + ( word_index * entry_size ); + offset = dictionary_offset + ( word_index * entry_size ); - /* If word matches then return dictionary offset */ + /* If word matches then return dictionary offset */ - if ( ( status = word[0] - ( ZINT16 ) get_word( offset + 0 ) ) == 0 && - ( status = word[1] - ( ZINT16 ) get_word( offset + 2 ) ) == 0 && - ( h_type < V4 || ( status = word[2] - ( ZINT16 ) get_word( offset + 4 ) ) == 0 ) ) - return ( ( zword_t ) offset ); + if ( ( status = word[0] - ( ZINT16 ) get_word( offset + 0 ) ) == 0 && + ( status = word[1] - ( ZINT16 ) get_word( offset + 2 ) ) == 0 && + ( h_type < V4 || ( status = word[2] - ( ZINT16 ) get_word( offset + 4 ) ) == 0 ) ) + return ( ( zword_t ) offset ); - /* Set next position depending on direction of overshoot */ + /* Set next position depending on direction of overshoot */ - if ( status > 0 ) - { - word_index += chop; + if ( status > 0 ) + { + word_index += chop; - /* Deal with end of dictionary case */ + /* Deal with end of dictionary case */ - if ( word_index >= ( int ) dictionary_size ) - word_index = dictionary_size - 1; - } - else - { - word_index -= chop; + if ( word_index >= ( int ) dictionary_size ) + word_index = dictionary_size - 1; + } + else + { + word_index -= chop; - /* Deal with start of dictionary case */ + /* Deal with start of dictionary case */ - if ( word_index < 0 ) - word_index = 0; - } - } - } - else - { + if ( word_index < 0 ) + word_index = 0; + } + } + } + else + { - for ( word_index = 0; word_index < -dictionary_size; word_index++ ) - { + for ( word_index = 0; word_index < -dictionary_size; word_index++ ) + { - /* Calculate dictionary offset */ + /* Calculate dictionary offset */ - offset = dictionary_offset + ( word_index * entry_size ); + offset = dictionary_offset + ( word_index * entry_size ); - /* If word matches then return dictionary offset */ + /* If word matches then return dictionary offset */ - if ( ( status = word[0] - ( ZINT16 ) get_word( offset + 0 ) ) == 0 && - ( status = word[1] - ( ZINT16 ) get_word( offset + 2 ) ) == 0 && - ( h_type < V4 || ( status = word[2] - ( ZINT16 ) get_word( offset + 4 ) ) == 0 ) ) - return ( ( zword_t ) offset ); - } - } + if ( ( status = word[0] - ( ZINT16 ) get_word( offset + 0 ) ) == 0 && + ( status = word[1] - ( ZINT16 ) get_word( offset + 2 ) ) == 0 && + ( h_type < V4 || ( status = word[2] - ( ZINT16 ) get_word( offset + 4 ) ) == 0 ) ) + return ( ( zword_t ) offset ); + } + } - return ( 0 ); + return ( 0 ); } /* find_word */ @@ -592,15 +593,15 @@ static zword_t find_word( int len, const char *cp, long chop ) void z_tokenise( int argc, zword_t * argv ) { - /* Supply default parameters */ + /* Supply default parameters */ - if ( argc < 4 ) - argv[3] = 0; - if ( argc < 3 ) - argv[2] = h_words_offset; + if ( argc < 4 ) + argv[3] = 0; + if ( argc < 3 ) + argv[2] = h_words_offset; - /* Convert the line to tokens */ + /* Convert the line to tokens */ - tokenise_line( argv[0], argv[1], argv[2], argv[3] ); + tokenise_line( argv[0], argv[1], argv[2], argv[3] ); } /* z_tokenise */ diff --git a/joeyio.c b/joeyio.c index 246b762..2f91836 100644 --- a/joeyio.c +++ b/joeyio.c @@ -3,10 +3,31 @@ #include "ztypes.h" -static int _cursorIndex = 0; -static int _cursorSize = 9; -static unsigned int _cursorTime = 0; -static byte _cursor[] = { 32, 176, 177, 178, 219, 178, 177, 176, 32 }; +#define DISPLAY_MIXED_SIZE 5 +#define COMMAND_BUFFER_SIZE 32 + +typedef enum { + DISPLAY_MODE_TEXT = 0, + DISPLAY_MODE_GRAPHICS, + DISPLAY_MODE_MIXED, + DISPLAY_MODE_LAST +} DModeT; + + +static jlVecT *_vectorImage = NULL; +static jlStaT *_graphicsPage = NULL; +static jlSoundT *_soundEffect = NULL; +static DModeT _displayMode = DISPLAY_MODE_TEXT; +static byte _bufferCount = 0; +static char _buffer[COMMAND_BUFFER_SIZE]; +static bool _inCommand = false; +static byte _cursorIndex = 0; +static byte _cursorSize = 9; +static unsigned int _cursorTime = 0; +static byte _cursor[] = { 32, 176, 177, 178, 219, 178, 177, 176, 32 }; + + +void set_next_display_mode(void); void clear_line(void) { @@ -16,7 +37,7 @@ void clear_line(void) { void clear_screen(void) { termClearScreen(); - termMoveCursor(1, screen_rows); + termMoveCursor(1, (byte)screen_rows); jlDisplayPresent(); } @@ -58,17 +79,106 @@ void delete_status_window(void) { void display_char(int c) { - termPrintChar((char)c); + char command; + char *token; + int x; + int y; + // This also handles processing of embedded media commands: + // {I name x y} - Display Image "name" @ x, y + // {M name} - Play Music "name" + // {S name} - Play Sound "name" + // {Q} - Quiet! + if (_inCommand) { + if ((char) c == '}') { + // Exit command mode. + if (_bufferCount > 0) { + // Did we get a command we understand? + command = (char)toupper(_buffer[0]); + _buffer[_bufferCount] = 0; + (void)strtok(_buffer, " "); + switch (command) { + case 'I': + token = strtok(NULL, " "); + if (jlVecLoad(_vectorImage, token)) { + x = y = 0; + token = strtok(NULL, " "); + if (token != NULL) { + x = atoi(token); + token = strtok(NULL, " "); + if (token != NULL) { + y = atoi(token); + } + } + // Put user into GRAPHICS mode if they aren't. + _displayMode = DISPLAY_MODE_GRAPHICS - 1; + set_next_display_mode(); + // Render the image. + jlVecDisplay(_vectorImage, x, y); + // Save it to the graphics page. + jlStaCreate(_graphicsPage); + } + break; + + case 'M': + token = strtok(NULL, " "); + jlSoundMusicPlay(token); + break; + + case 'S': + token = strtok(NULL, " "); + if (jlSoundLoad(_soundEffect, token)) { + jlSoundPlay(_soundEffect); + } + break; + + case 'Q': + jlSoundMusicStop(); + break; + } + } + // Exit command mode + _bufferCount = 0; + _inCommand = false; + } else { + if (_bufferCount < COMMAND_BUFFER_SIZE - 1) { + // Add character to command buffer. + _buffer[_bufferCount++] = (char)c; + } else { + // Overflowed buffer - exit command mode + _bufferCount = 0; + _inCommand = false; + } + } + } else { + if ((char)c == '{') { + // Switch to embedded command mode. + _inCommand = true; + } else { + // Display game text. + termPrintChar((char)c); + } + } } void get_cursor_position(int *row, int *col) { - termGetCursor(col, row); + byte x; + byte y; + termGetCursor(&x, &y); + *col = (int)x; + *row = (int)y; } void initialize_screen(void) { - // Handled in main + // Also handled in main + + // Create initial empty graphics image. + jlDrawColor(0); + jlDrawClear(); + jlDrawColor(15); + jlDisplayPresent(); + jlStaCreate(_graphicsPage); } @@ -129,8 +239,12 @@ int input_line(int buflen, char *buffer, int timeout, int *read_size) { //***TODO*** Flash border or ding or something } else { if (c == 13) { - scroll_line(); - return c; + if (curr_char_pos == 0) { + set_next_display_mode(); + } else { + scroll_line(); + return c; + } } else { buffer[curr_char_pos++] = (char)c; if (*read_size < curr_char_pos) { @@ -148,12 +262,15 @@ int input_line(int buflen, char *buffer, int timeout, int *read_size) { void move_cursor(int row, int col) { - termMoveCursor(col, row); + termMoveCursor((byte)col, (byte)row); } void reset_screen(void) { - // Handled in main + // Also handled in main + jlStaFree(_graphicsPage); + jlVecFree(_vectorImage); + jlSoundFree(_soundEffect); } @@ -197,3 +314,37 @@ void set_attribute(int attribute) { termPrint("\33[7m"); } } + + +void set_next_display_mode(void) { + + _displayMode++; + if (_displayMode >= DISPLAY_MODE_LAST) { + _displayMode = DISPLAY_MODE_TEXT; + } + + switch (_displayMode) { + case DISPLAY_MODE_TEXT: + printf("Terminal now TEXT\n"); + termHideTopLines(0); + termRepaint(); + break; + + case DISPLAY_MODE_GRAPHICS: + printf("Terminal now GRAPHICS\n"); + termHideTopLines((byte)screen_rows); + jlStaDisplay(_graphicsPage); + break; + + case DISPLAY_MODE_MIXED: + printf("Terminal now MIXED\n"); + termHideTopLines((byte)screen_rows - DISPLAY_MIXED_SIZE); + jlStaDisplay(_graphicsPage); + termRepaint(); + break; + + case DISPLAY_MODE_LAST: + // Won't happen. Silences a warning. + break; + } +} diff --git a/jzip.h b/jzip.h deleted file mode 100644 index ba1497b..0000000 --- a/jzip.h +++ /dev/null @@ -1,37 +0,0 @@ - -/* $Id: jzip.h,v 1.5 2000/10/10 14:46:22 jholder Exp $ - * -------------------------------------------------------------------- - * see doc/License.txt for License Information - * -------------------------------------------------------------------- - * - * File name: $Id: jzip.h,v 1.5 2000/10/10 14:46:22 jholder Exp $ - * - * Description: - * - * Modification history: - * $Log: jzip.h,v $ - * Revision 1.5 2000/10/10 14:46:22 jholder - * Fixed text wrap bug when printing array w/ \r chars in it - * - * Revision 1.4 2000/10/05 17:09:12 jholder - * removed old email address - * - * Revision 1.3 2000/10/04 23:07:57 jholder - * fixed redirect problem with isolatin1 range chars - * - * Revision 1.2 2000/09/18 15:31:44 jholder - * Updated release date for package release - * - * Revision 1.1.1.1 2000/05/10 14:21:34 jholder - * - * imported - * - * - * -------------------------------------------------------------------- - */ - -#define JZIPVER "Jzip V2.1" -#define JZIPRELDATE "Tue, Oct 10 2000" -#define JZIPAUTHOR "John Holder (j-holder@home.com)" -#define JZIPURL "http://jzip.sourceforge.net/" - diff --git a/main.c b/main.c index fa582d4..70d4d55 100644 --- a/main.c +++ b/main.c @@ -1,5 +1,6 @@ #include #include +#include #include "joey.h" @@ -94,30 +95,48 @@ void process_arguments(char *game) { int main(void) { + FILE *in; jlStaT *font = NULL; + char name[40]; + char game[40]; + char text[40]; - jlUtilStartup("IF Engine"); - jlStaLoad(font, "8x8thin.sta"); + in = fopen("gamedata.dat", "rt"); + if (in != NULL) { - termStart(font, 0, 0, 40, 25); - termDestruciveBackspace(false); - termMoveCursor(1, 25); - termSaveCursor(); + fgets(name, 40, in); + fgets(game, 40, in); + fgets(text, 40, in); - process_arguments("gamedata.z5"); - configure(V1, V8); - initialize_screen(); - load_cache(); - z_restart(); - (void)interpret(); - unload_cache(); - close_story(); - close_script(); - reset_screen(); + fclose(in); - termStop(); + name[strlen(name) - 1] = 0; + game[strlen(game) - 1] = 0; + text[strlen(text) - 1] = 0; - jlStaFree(font); + jlUtilStartup(name); + jlStaLoad(font, text); + + termStart(font, 0, 0, 40, 25); + termDestruciveBackspace(false); + termMoveCursor(1, 25); + termSaveCursor(); + + process_arguments(game); + configure(V1, V8); + initialize_screen(); + load_cache(); + z_restart(); + (void)interpret(); + unload_cache(); + close_story(); + close_script(); + reset_screen(); + + termStop(); + + jlStaFree(font); + } jlUtilShutdown(); } diff --git a/nowhere.vec b/nowhere.vec new file mode 100644 index 0000000..e69de29 diff --git a/nowhere.vec.source b/nowhere.vec.source new file mode 100644 index 0000000..817fe39 --- /dev/null +++ b/nowhere.vec.source @@ -0,0 +1,29 @@ +# Reset Palette, Clear Screen to White, Draw in Black +# Hacky Border because we can't hit 319 yet. +R +C 0 +E +C 15 +S 0 0 255 199 +C 0 + +# Horizon +L 0 87 255 87 + +# Sun +L 255 64 248 61 240 61 233 62 228 66 223 72 220 78 220 87 + +# Beach +L 0 101 87 124 126 128 148 133 160 136 168 141 172 146 171 149 169 153 169 158 176 164 188 168 205 171 227 174 255 174 + +# Fill Sun +C 12 +F 242 74 + +# Fill Beach +C 14 +F 105 161 + +# Fill Ocean +C 1 +F 194 106 diff --git a/osdepend.c b/osdepend.c index 0bd0b3f..337444f 100644 --- a/osdepend.c +++ b/osdepend.c @@ -468,7 +468,8 @@ void set_font( int font_type ) void set_colours( zword_t foreground, zword_t background ) { - + (void)foreground; + (void)background; } /* set_colours */ #endif /* !defined MSDOS && !defined OS2 && !defined AMIGA !defined HARD_COLORS && !defined ATARIST */ @@ -519,6 +520,8 @@ void set_colours( zword_t foreground, zword_t background ) int codes_to_text( int c, char *s ) { + (void)c; + (void)s; return 1; } /* codes_to_text */ diff --git a/property.c b/property.c index 6bfcc94..65a84fc 100644 --- a/property.c +++ b/property.c @@ -1,14 +1,14 @@ -/* $Id: property.c,v 1.2 2000/05/25 22:28:56 jholder Exp $ +/* $Id: property.c,v 1.2 2000/05/25 22:28:56 jholder Exp $ * -------------------------------------------------------------------- - * see doc/License.txt for License Information + * see doc/License.txt for License Information * -------------------------------------------------------------------- - * - * File name: $Id: property.c,v 1.2 2000/05/25 22:28:56 jholder Exp $ - * - * Description: - * - * Modification history: + * + * File name: $Id: property.c,v 1.2 2000/05/25 22:28:56 jholder Exp $ + * + * Description: + * + * Modification history: * $Log: property.c,v $ * Revision 1.2 2000/05/25 22:28:56 jholder * changes routine names to reflect zmachine opcode names per spec 1.0 @@ -40,22 +40,22 @@ static zword_t get_property_addr( zword_t obj ) { - zword_t object_addr; - zword_t prop_addr; - zbyte_t size; + zword_t object_addr; + zword_t prop_addr; + zbyte_t size; - /* Calculate the address of the property pointer in the object */ + /* Calculate the address of the property pointer in the object */ - object_addr = get_object_address( obj ); - object_addr += ( h_type <= V3 ) ? O3_PROPERTY_OFFSET : O4_PROPERTY_OFFSET; + object_addr = get_object_address( obj ); + object_addr += ( h_type <= V3 ) ? O3_PROPERTY_OFFSET : O4_PROPERTY_OFFSET; - /* Read the property address */ - prop_addr = get_word( object_addr ); + /* Read the property address */ + prop_addr = get_word( object_addr ); - /* Skip past object description which is an ASCIC of encoded words */ - size = get_byte( prop_addr ); + /* Skip past object description which is an ASCIC of encoded words */ + size = get_byte( prop_addr ); - return prop_addr + ( size * 2 ) + 1; + return prop_addr + ( size * 2 ) + 1; } /* get_property_addr */ @@ -68,29 +68,29 @@ static zword_t get_property_addr( zword_t obj ) static zword_t get_next_property( zword_t prop_addr ) { - zbyte_t value; + zbyte_t value; - /* Load the current property id */ - value = get_byte( prop_addr ); - prop_addr++; + /* Load the current property id */ + value = get_byte( prop_addr ); + prop_addr++; - /* Calculate the length of this property */ + /* Calculate the length of this property */ - if ( h_type <= V3 ) - value >>= 5; - else if ( !( value & 0x80 ) ) - value >>= 6; - else - { - value = get_byte( prop_addr ); - value &= property_size_mask; + if ( h_type <= V3 ) + value >>= 5; + else if ( !( value & 0x80 ) ) + value >>= 6; + else + { + value = get_byte( prop_addr ); + value &= property_size_mask; - if ( value == 0 ) - value = 64; /* spec 1.0 */ - } + if ( value == 0 ) + value = 64; /* spec 1.0 */ + } - /* Address property length to current property pointer */ - return prop_addr + value + 1; + /* Address property length to current property pointer */ + return prop_addr + value + 1; } /* get_next_property */ @@ -106,58 +106,58 @@ static zword_t get_next_property( zword_t prop_addr ) void z_get_prop( zword_t obj, zword_t prop ) { - zword_t prop_addr; - zword_t wprop_val; - zbyte_t bprop_val; - zbyte_t value; + zword_t prop_addr; + zword_t wprop_val; + zbyte_t bprop_val; + zbyte_t value; #ifdef STRICTZ - if ( obj == 0 ) - { - report_strictz_error( STRZERR_GET_PROP, "@get_prop called with object 0" ); - store_operand( 0 ); - return; - } + if ( obj == 0 ) + { + report_strictz_error( STRZERR_GET_PROP, "@get_prop called with object 0" ); + store_operand( 0 ); + return; + } #endif - /* Load address of first property */ - prop_addr = get_property_addr( obj ); + /* Load address of first property */ + prop_addr = get_property_addr( obj ); - /* Scan down the property list */ - for ( ;; ) - { - value = get_byte( prop_addr ); - if ( ( zbyte_t ) ( value & property_mask ) <= ( zbyte_t ) prop ) - break; - prop_addr = get_next_property( prop_addr ); - } + /* Scan down the property list */ + for ( ;; ) + { + value = get_byte( prop_addr ); + if ( ( zbyte_t ) ( value & property_mask ) <= ( zbyte_t ) prop ) + break; + prop_addr = get_next_property( prop_addr ); + } - /* If the property ids match then load the first property */ + /* If the property ids match then load the first property */ - if ( ( zbyte_t ) ( value & property_mask ) == ( zbyte_t ) prop ) /* property found */ - { - prop_addr++; - /* Only load first property if it is a byte sized property */ - if ( h_type <= V3 && !( value & 0xe0 ) || h_type >= V4 && !( value & 0xc0 ) ) - { - bprop_val = get_byte( prop_addr ); - wprop_val = bprop_val; - } - else - { - wprop_val = get_word( prop_addr ); - } - } - else /* property not found */ - { - /* Calculate the address of the default property */ - prop_addr = h_objects_offset + ( ( prop - 1 ) * 2 ); - wprop_val = get_word( prop_addr ); - } + if ( ( zbyte_t ) ( value & property_mask ) == ( zbyte_t ) prop ) /* property found */ + { + prop_addr++; + /* Only load first property if it is a byte sized property */ + if ( (h_type <= V3 && !( value & 0xe0 )) || (h_type >= V4 && !( value & 0xc0 )) ) + { + bprop_val = get_byte( prop_addr ); + wprop_val = bprop_val; + } + else + { + wprop_val = get_word( prop_addr ); + } + } + else /* property not found */ + { + /* Calculate the address of the default property */ + prop_addr = h_objects_offset + ( ( prop - 1 ) * 2 ); + wprop_val = get_word( prop_addr ); + } - /* store the property value */ + /* store the property value */ - store_operand( wprop_val ); + store_operand( wprop_val ); } /* z_get_prop */ @@ -171,48 +171,48 @@ void z_get_prop( zword_t obj, zword_t prop ) void z_put_prop( zword_t obj, zword_t prop, zword_t setvalue ) { - zword_t prop_addr; - zword_t value; + zword_t prop_addr; + zword_t value; #ifdef STRICTZ - if ( obj == 0 ) - { - report_strictz_error( STRZERR_PUT_PROP, "@put_prop called with object 0" ); - return; - } + if ( obj == 0 ) + { + report_strictz_error( STRZERR_PUT_PROP, "@put_prop called with object 0" ); + return; + } #endif - /* Load address of first property */ - prop_addr = get_property_addr( obj ); + /* Load address of first property */ + prop_addr = get_property_addr( obj ); - /* Scan down the property list */ - for ( ;; ) - { - value = get_byte( prop_addr ); - if ( ( value & property_mask ) <= prop ) - break; - prop_addr = get_next_property( prop_addr ); - } + /* Scan down the property list */ + for ( ;; ) + { + value = get_byte( prop_addr ); + if ( ( value & property_mask ) <= prop ) + break; + prop_addr = get_next_property( prop_addr ); + } - /* If the property id was found, store a new value, otherwise complain */ + /* If the property id was found, store a new value, otherwise complain */ - if ( ( value & property_mask ) != prop ) - { - fatal( "store_property(): No such property" ); - } + if ( ( value & property_mask ) != prop ) + { + fatal( "store_property(): No such property" ); + } - /* Determine if this is a byte or word sized property */ + /* Determine if this is a byte or word sized property */ - prop_addr++; + prop_addr++; - if ( h_type <= V3 && !( value & 0xe0 ) || h_type >= V4 && !( value & 0xc0 ) ) - { - set_byte( prop_addr, ( zbyte_t ) setvalue ); - } - else - { - set_word( prop_addr, ( zword_t ) setvalue ); - } + if ( (h_type <= V3 && !( value & 0xe0 )) || (h_type >= V4 && !( value & 0xc0 )) ) + { + set_byte( prop_addr, ( zbyte_t ) setvalue ); + } + else + { + set_word( prop_addr, ( zword_t ) setvalue ); + } } /* z_put_prop */ @@ -226,43 +226,43 @@ void z_put_prop( zword_t obj, zword_t prop, zword_t setvalue ) void z_get_next_prop( zword_t obj, zword_t prop ) { - zword_t prop_addr; - zbyte_t value; + zword_t prop_addr; + zbyte_t value; #ifdef STRICTZ - if ( obj == 0 ) - { - report_strictz_error( STRZERR_GET_NEXT_PROP, "@get_next_prop called with object 0" ); - store_operand( 0 ); - return; - } + if ( obj == 0 ) + { + report_strictz_error( STRZERR_GET_NEXT_PROP, "@get_next_prop called with object 0" ); + store_operand( 0 ); + return; + } #endif - /* Load address of first property */ - prop_addr = get_property_addr( obj ); + /* Load address of first property */ + prop_addr = get_property_addr( obj ); - /* If the property id is non zero then find the next property */ - if ( prop != 0 ) - { - /* Scan down the property list while the target property id is less - * than the property id in the list */ - do - { - value = get_byte( prop_addr ); - prop_addr = get_next_property( prop_addr ); - } - while ( ( zbyte_t ) ( value & property_mask ) > ( zbyte_t ) prop ); + /* If the property id is non zero then find the next property */ + if ( prop != 0 ) + { + /* Scan down the property list while the target property id is less + * than the property id in the list */ + do + { + value = get_byte( prop_addr ); + prop_addr = get_next_property( prop_addr ); + } + while ( ( zbyte_t ) ( value & property_mask ) > ( zbyte_t ) prop ); - /* If the property id wasn't found then complain */ - if ( ( zbyte_t ) ( value & property_mask ) != ( zbyte_t ) prop ) - { - fatal( "load_next_property(): No such property" ); - } - } + /* If the property id wasn't found then complain */ + if ( ( zbyte_t ) ( value & property_mask ) != ( zbyte_t ) prop ) + { + fatal( "load_next_property(): No such property" ); + } + } - /* Return the next property id */ - value = get_byte( prop_addr ); - store_operand( ( zword_t ) ( value & property_mask ) ); + /* Return the next property id */ + value = get_byte( prop_addr ); + store_operand( ( zword_t ) ( value & property_mask ) ); } /* z_get_next_prop */ @@ -275,47 +275,47 @@ void z_get_next_prop( zword_t obj, zword_t prop ) void z_get_prop_addr( zword_t obj, zword_t prop ) { - zword_t prop_addr; - zbyte_t value; + zword_t prop_addr; + zbyte_t value; #ifdef STRICTZ - if ( obj == 0 ) - { - report_strictz_error( STRZERR_GET_PROP_ADDR, "@get_prop_addr called with object 0" ); - store_operand( 0 ); - return; - } + if ( obj == 0 ) + { + report_strictz_error( STRZERR_GET_PROP_ADDR, "@get_prop_addr called with object 0" ); + store_operand( 0 ); + return; + } #endif - /* Load address of first property */ - prop_addr = get_property_addr( obj ); + /* Load address of first property */ + prop_addr = get_property_addr( obj ); - /* Scan down the property list */ - for ( ;; ) - { - value = get_byte( prop_addr ); - if ( ( zbyte_t ) ( value & property_mask ) <= ( zbyte_t ) prop ) - break; - prop_addr = get_next_property( prop_addr ); - } + /* Scan down the property list */ + for ( ;; ) + { + value = get_byte( prop_addr ); + if ( ( zbyte_t ) ( value & property_mask ) <= ( zbyte_t ) prop ) + break; + prop_addr = get_next_property( prop_addr ); + } - /* If the property id was found, calc the prop addr, else return zero */ + /* If the property id was found, calc the prop addr, else return zero */ - if ( ( zbyte_t ) ( value & property_mask ) == ( zbyte_t ) prop ) - { - /* Skip past property id, can be a byte or a word */ + if ( ( zbyte_t ) ( value & property_mask ) == ( zbyte_t ) prop ) + { + /* Skip past property id, can be a byte or a word */ - if ( h_type >= V4 && ( value & 0x80 ) ) - { - prop_addr++; - } - store_operand( ( zword_t ) ( prop_addr + 1 ) ); - } - else - { - /* No property found, just return 0 */ - store_operand( 0 ); - } + if ( h_type >= V4 && ( value & 0x80 ) ) + { + prop_addr++; + } + store_operand( ( zword_t ) ( prop_addr + 1 ) ); + } + else + { + /* No property found, just return 0 */ + store_operand( 0 ); + } } /* z_get_prop_addr */ @@ -328,36 +328,36 @@ void z_get_prop_addr( zword_t obj, zword_t prop ) void z_get_prop_len( zword_t prop_addr ) { - zbyte_t value; + zbyte_t value; - /* This is proper according to an email to the Zmachine list by Graham*/ - if ( prop_addr == 0 ) - { - store_operand( ( zword_t ) 0 ); - return; - } + /* This is proper according to an email to the Zmachine list by Graham*/ + if ( prop_addr == 0 ) + { + store_operand( ( zword_t ) 0 ); + return; + } - /* Back up the property pointer to the property id */ - prop_addr--; - value = get_byte( prop_addr ); + /* Back up the property pointer to the property id */ + prop_addr--; + value = get_byte( prop_addr ); - if ( h_type <= V3 ) - { - value = ( zbyte_t ) ( ( value >> ( zbyte_t ) 5 ) + ( zbyte_t ) 1 ); - } - else if ( !( value & 0x80 ) ) - { - value = ( zbyte_t ) ( ( value >> ( zbyte_t ) 6 ) + ( zbyte_t ) 1 ); - } - else - { - value &= ( zbyte_t ) property_size_mask; + if ( h_type <= V3 ) + { + value = ( zbyte_t ) ( ( value >> ( zbyte_t ) 5 ) + ( zbyte_t ) 1 ); + } + else if ( !( value & 0x80 ) ) + { + value = ( zbyte_t ) ( ( value >> ( zbyte_t ) 6 ) + ( zbyte_t ) 1 ); + } + else + { + value &= ( zbyte_t ) property_size_mask; - if ( value == 0 ) - value = ( zbyte_t ) 64; /* spec 1.0 */ - } + if ( value == 0 ) + value = ( zbyte_t ) 64; /* spec 1.0 */ + } - store_operand( value ); + store_operand( value ); } /* z_get_prop_len */ @@ -372,76 +372,76 @@ void z_get_prop_len( zword_t prop_addr ) void z_scan_table( int argc, zword_t * argv ) { - unsigned long address; - unsigned int i, step; + unsigned long address; + unsigned int i, step; - /* Supply default parameters */ + /* Supply default parameters */ - if ( argc < 4 ) - argv[3] = 0x82; + if ( argc < 4 ) + argv[3] = 0x82; - address = argv[1]; - step = argv[3]; + address = argv[1]; + step = argv[3]; - /* Check size bit (bit 7 of step, 1 = word, 0 = byte) */ + /* Check size bit (bit 7 of step, 1 = word, 0 = byte) */ - if ( step & 0x80 ) - { + if ( step & 0x80 ) + { - step &= 0x7f; + step &= 0x7f; - /* Scan down an array for count words looking for a match */ + /* Scan down an array for count words looking for a match */ - for ( i = 0; i < argv[2]; i++ ) - { + for ( i = 0; i < argv[2]; i++ ) + { - /* If the word was found store its address and jump */ + /* If the word was found store its address and jump */ - if ( read_data_word( &address ) == argv[0] ) - { - store_operand( ( zword_t ) ( address - 2 ) ); - conditional_jump( TRUE ); - return; - } + if ( read_data_word( &address ) == argv[0] ) + { + store_operand( ( zword_t ) ( address - 2 ) ); + conditional_jump( TRUE ); + return; + } - /* Back up address then step by increment */ + /* Back up address then step by increment */ - address = ( address - 2 ) + step; + address = ( address - 2 ) + step; - } + } - } - else - { + } + else + { - step &= 0x7f; + step &= 0x7f; - /* Scan down an array for count bytes looking for a match */ + /* Scan down an array for count bytes looking for a match */ - for ( i = 0; i < argv[2]; i++ ) - { + for ( i = 0; i < argv[2]; i++ ) + { - /* If the byte was found store its address and jump */ + /* If the byte was found store its address and jump */ - if ( ( zword_t ) read_data_byte( &address ) == ( zword_t ) argv[0] ) - { - store_operand( ( zword_t ) ( address - 1 ) ); - conditional_jump( TRUE ); - return; - } + if ( ( zword_t ) read_data_byte( &address ) == ( zword_t ) argv[0] ) + { + store_operand( ( zword_t ) ( address - 1 ) ); + conditional_jump( TRUE ); + return; + } - /* Back up address then step by increment */ + /* Back up address then step by increment */ - address = ( address - 1 ) + step; + address = ( address - 1 ) + step; - } + } - } + } - /* If the data was not found store zero and jump */ + /* If the data was not found store zero and jump */ - store_operand( 0 ); - conditional_jump( FALSE ); + store_operand( 0 ); + conditional_jump( FALSE ); } /* z_scan_table */ @@ -452,41 +452,41 @@ void z_scan_table( int argc, zword_t * argv ) void z_copy_table( zword_t src, zword_t dst, zword_t count ) { - unsigned long address; - unsigned int i; + unsigned long address; + unsigned int i; - /* Catch no-op move case */ + /* Catch no-op move case */ - if ( src == dst || count == 0 ) - return; + if ( src == dst || count == 0 ) + return; - /* If destination address is zero then fill source with zeros */ + /* If destination address is zero then fill source with zeros */ - if ( dst == 0 ) - { - for ( i = 0; i < count; i++ ) - z_storeb( src++, 0, 0 ); - return; - } + if ( dst == 0 ) + { + for ( i = 0; i < count; i++ ) + z_storeb( src++, 0, 0 ); + return; + } - address = src; + address = src; - if ( ( ZINT16 ) count < 0 ) - { - while ( count++ ) - z_storeb( dst++, 0, read_data_byte( &address ) ); - } - else - { - address += ( unsigned long ) count; - dst += count; - while ( count-- ) - { - address--; - z_storeb( --dst, 0, read_data_byte( &address ) ); - address--; - } - } + if ( ( ZINT16 ) count < 0 ) + { + while ( count++ ) + z_storeb( dst++, 0, read_data_byte( &address ) ); + } + else + { + address += ( unsigned long ) count; + dst += count; + while ( count-- ) + { + address--; + z_storeb( --dst, 0, read_data_byte( &address ) ); + address--; + } + } } /* z_copy_table */ @@ -499,15 +499,15 @@ void z_copy_table( zword_t src, zword_t dst, zword_t count ) void z_loadw( zword_t addr, zword_t offset ) { - unsigned long address; + unsigned long address; - /* Calculate word array index address */ + /* Calculate word array index address */ - address = addr + ( offset * 2 ); + address = addr + ( offset * 2 ); - /* Store the byte */ + /* Store the byte */ - store_operand( read_data_word( &address ) ); + store_operand( read_data_word( &address ) ); } /* z_loadw */ @@ -520,15 +520,15 @@ void z_loadw( zword_t addr, zword_t offset ) void z_loadb( zword_t addr, zword_t offset ) { - unsigned long address; + unsigned long address; - /* Calculate byte array index address */ + /* Calculate byte array index address */ - address = addr + offset; + address = addr + offset; - /* Load the byte */ + /* Load the byte */ - store_operand( read_data_byte( &address ) ); + store_operand( read_data_byte( &address ) ); } /* z_loadb */ @@ -542,18 +542,18 @@ void z_loadb( zword_t addr, zword_t offset ) void z_storew( zword_t addr, zword_t offset, zword_t value ) { - /* Calculate word array index address */ + /* Calculate word array index address */ - addr += offset * 2; + addr += offset * 2; - /* Check we are not writing outside of the writeable data area */ + /* Check we are not writing outside of the writeable data area */ - if ( addr > data_size ) - fatal( "z_storew(): Attempted write outside of data area" ); + if ( addr > data_size ) + fatal( "z_storew(): Attempted write outside of data area" ); - /* Store the word */ + /* Store the word */ - set_word( addr, value ); + set_word( addr, value ); } /* z_storew */ @@ -567,17 +567,17 @@ void z_storew( zword_t addr, zword_t offset, zword_t value ) void z_storeb( zword_t addr, zword_t offset, zword_t value ) { - /* Calculate byte array index address */ + /* Calculate byte array index address */ - addr += offset; + addr += offset; - /* Check we are not writing outside of the writeable data area */ + /* Check we are not writing outside of the writeable data area */ - if ( addr > data_size ) - fatal( "z_storeb(): Attempted write outside of data area" ); + if ( addr > data_size ) + fatal( "z_storeb(): Attempted write outside of data area" ); - /* Store the byte */ + /* Store the byte */ - set_byte( addr, value ); + set_byte( addr, value ); } /* z_storeb */ diff --git a/quetzal.c b/quetzal.c index 291caf3..5abe208 100644 --- a/quetzal.c +++ b/quetzal.c @@ -1,14 +1,14 @@ -/* $Id: quetzal.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ +/* $Id: quetzal.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ * -------------------------------------------------------------------- - * see doc/License.txt for License Information + * see doc/License.txt for License Information * -------------------------------------------------------------------- - * - * File name: $Id: quetzal.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ - * - * Description: - * - * Modification history: + * + * File name: $Id: quetzal.c,v 1.3 2000/07/05 15:20:34 jholder Exp $ + * + * Description: + * + * Modification history: * $Log: quetzal.c,v $ * Revision 1.3 2000/07/05 15:20:34 jholder * Updated code to remove warnings. @@ -59,17 +59,17 @@ typedef unsigned long ul_t; #define ID_ANNO 0x414e4e4f /* macros to write QUETZAL files */ -#define write_byte(fp,b) (put_c ((unsigned)(b),fp) != EOF) +#define write_byte(fp,b) (put_c ((unsigned)(b),fp) != EOF) #define write_bytx(fp,b) write_byte(fp,(b) & 0xFF) #define write_word(fp,w) \ - (write_bytx(fp,(w)>> 8) && write_bytx(fp,(w))) + (write_bytx(fp,(w)>> 8) && write_bytx(fp,(w))) #define write_long(fp,l) \ - (write_bytx(fp,(ul_t)(l)>>24) && write_bytx(fp,(ul_t)(l)>>16) && \ - write_bytx(fp,(ul_t)(l)>> 8) && write_bytx(fp,(ul_t)(l))) + (write_bytx(fp,(ul_t)(l)>>24) && write_bytx(fp,(ul_t)(l)>>16) && \ + write_bytx(fp,(ul_t)(l)>> 8) && write_bytx(fp,(ul_t)(l))) #define write_chnk(fp,id,len) \ - (write_long(fp,id) && write_long(fp,len)) + (write_long(fp,id) && write_long(fp,len)) #define write_run(fp,run) \ - (write_byte(fp,0) && write_byte(fp,(run))) + (write_byte(fp,0) && write_byte(fp,(run))) /* save_quetzal * @@ -82,160 +82,160 @@ int save_quetzal( FILE * sfp, gzFile * gfp ) int save_quetzal( FILE * sfp, FILE * gfp ) #endif { - ul_t ifzslen = 0, cmemlen = 0, stkslen = 0, tmp_pc; - int c; - zword_t i, j, n, init_fp, tmp_fp, nstk, nvars, args; - zword_t frames[STACK_SIZE / 4 + 1]; - zbyte_t var; - long cmempos, stkspos; + ul_t ifzslen = 0, cmemlen = 0, stkslen = 0, tmp_pc; + int c; + zword_t i, j, n, init_fp, tmp_fp, nstk, nvars, args; + zword_t frames[STACK_SIZE / 4 + 1]; + zbyte_t var; + long cmempos, stkspos; - /* write IFZS header */ - if ( !write_chnk( sfp, ID_FORM, 0 ) ) - return FALSE; - if ( !write_long( sfp, ID_IFZS ) ) - return FALSE; + /* write IFZS header */ + if ( !write_chnk( sfp, ID_FORM, 0 ) ) + return FALSE; + if ( !write_long( sfp, ID_IFZS ) ) + return FALSE; - /* write IFhd chunk */ - if ( !write_chnk( sfp, ID_IFhd, 13 ) ) - return FALSE; - if ( !write_word( sfp, h_version ) ) - return FALSE; - for ( i = 0; i < 6; ++i ) - if ( !write_byte( sfp, get_byte( H_RELEASE_DATE + i ) ) ) - return FALSE; - if ( !write_word( sfp, h_checksum ) ) - return FALSE; - if ( !write_long( sfp, ( ( ul_t ) pc ) << 8 ) ) /* includes pad byte */ - return FALSE; + /* write IFhd chunk */ + if ( !write_chnk( sfp, ID_IFhd, 13 ) ) + return FALSE; + if ( !write_word( sfp, h_version ) ) + return FALSE; + for ( i = 0; i < 6; ++i ) + if ( !write_byte( sfp, get_byte( H_RELEASE_DATE + i ) ) ) + return FALSE; + if ( !write_word( sfp, h_checksum ) ) + return FALSE; + if ( !write_long( sfp, ( ( ul_t ) pc ) << 8 ) ) /* includes pad byte */ + return FALSE; - /* write CMem chunk */ - /* j is current run length */ - if ( ( cmempos = ftell( sfp ) ) < 0 ) - return FALSE; - if ( !write_chnk( sfp, ID_CMem, 0 ) ) - return FALSE; - jz_rewind( gfp ); - for ( i = 0, j = 0, cmemlen = 0; i < h_restart_size; ++i ) - { - if ( ( c = jz_getc( gfp ) ) == EOF ) - return FALSE; - c ^= get_byte( i ); - if ( c == 0 ) - ++j; - else - { - /* write any run there may be */ - if ( j > 0 ) - { - for ( ; j > 0x100; j -= 0x100 ) - { - if ( !write_run( sfp, 0xFF ) ) - return FALSE; - cmemlen += 2; - } - if ( !write_run( sfp, j - 1 ) ) - return FALSE; - cmemlen += 2; - j = 0; - } - /* write this byte */ - if ( !write_byte( sfp, c ) ) - return FALSE; - ++cmemlen; - } - } - /* there may be a run here, which we ignore */ - if ( cmemlen & 1 ) /* chunk length must be even */ - if ( !write_byte( sfp, 0 ) ) - return FALSE; + /* write CMem chunk */ + /* j is current run length */ + if ( ( cmempos = ftell( sfp ) ) < 0 ) + return FALSE; + if ( !write_chnk( sfp, ID_CMem, 0 ) ) + return FALSE; + jz_rewind( gfp ); + for ( i = 0, j = 0, cmemlen = 0; i < h_restart_size; ++i ) + { + if ( ( c = jz_getc( gfp ) ) == EOF ) + return FALSE; + c ^= get_byte( i ); + if ( c == 0 ) + ++j; + else + { + /* write any run there may be */ + if ( j > 0 ) + { + for ( ; j > 0x100; j -= 0x100 ) + { + if ( !write_run( sfp, 0xFF ) ) + return FALSE; + cmemlen += 2; + } + if ( !write_run( sfp, j - 1 ) ) + return FALSE; + cmemlen += 2; + j = 0; + } + /* write this byte */ + if ( !write_byte( sfp, c ) ) + return FALSE; + ++cmemlen; + } + } + /* there may be a run here, which we ignore */ + if ( cmemlen & 1 ) /* chunk length must be even */ + if ( !write_byte( sfp, 0 ) ) + return FALSE; - /* write Stks chunk */ - if ( ( stkspos = ftell( sfp ) ) < 0 ) - return FALSE; - if ( !write_chnk( sfp, ID_Stks, 0 ) ) - return FALSE; + /* write Stks chunk */ + if ( ( stkspos = ftell( sfp ) ) < 0 ) + return FALSE; + if ( !write_chnk( sfp, ID_Stks, 0 ) ) + return FALSE; - /* frames is a list of FPs, most recent first */ - frames[0] = sp - 5; /* what FP would be if we did a call now */ - for ( init_fp = fp, n = 0; init_fp <= STACK_SIZE - 5; init_fp = stack[init_fp + 2] ) - frames[++n] = init_fp; - init_fp = frames[n] + 4; + /* frames is a list of FPs, most recent first */ + frames[0] = sp - 5; /* what FP would be if we did a call now */ + for ( init_fp = fp, n = 0; init_fp <= STACK_SIZE - 5; init_fp = stack[init_fp + 2] ) + frames[++n] = init_fp; + init_fp = frames[n] + 4; - if ( h_type != 6 ) - { /* write a dummy frame for stack used before first call */ - for ( i = 0; i < 6; ++i ) - if ( !write_byte( sfp, 0 ) ) - return FALSE; - nstk = STACK_SIZE - 1 - init_fp; - if ( !write_word( sfp, nstk ) ) - return FALSE; - for ( i = STACK_SIZE - 1; i > init_fp; --i ) - if ( !write_word( sfp, stack[i] ) ) - return FALSE; - stkslen = 8 + 2 * nstk; - } - for ( i = n; i > 0; --i ) - { - /* write out one stack frame. - * - * tmp_fp : FP when this frame was current - * tmp_pc : PC on return from this frame, plus 000pvvvv - * nvars : number of local vars for this frame - * args : argument mask for this frame - * nstk : words of evaluation stack used for this frame - * var : variable to store result - */ - tmp_fp = frames[i]; - nvars = ( stack[tmp_fp + 1] & VARS_MASK ) >> VAR_SHIFT; - args = stack[tmp_fp + 1] & ARGS_MASK; - nstk = tmp_fp - frames[i - 1] - nvars - 4; - tmp_pc = stack[tmp_fp + 3] + ( ul_t ) stack[tmp_fp + 4] * PAGE_SIZE; - switch ( stack[tmp_fp + 1] & TYPE_MASK ) - { - case FUNCTION: - var = read_data_byte( &tmp_pc ); /* also increments tmp_pc */ - tmp_pc = ( tmp_pc << 8 ) | nvars; - break; - case PROCEDURE: - var = 0; - tmp_pc = ( tmp_pc << 8 ) | 0x10 | nvars; /* set procedure flag */ - break; - /* case ASYNC: */ - default: - output_line( "Illegal Z-machine operation: can't save while in interrupt." ); - return FALSE; - } - if ( args != 0 ) - args = ( 1 << args ) - 1; /* make args into bitmap */ - if ( !write_long( sfp, tmp_pc ) ) - return FALSE; - if ( !write_byte( sfp, var ) ) - return FALSE; - if ( !write_byte( sfp, args ) ) - return FALSE; - if ( !write_word( sfp, nstk ) ) - return FALSE; - for ( j = 0; j < nvars + nstk; ++j, --tmp_fp ) - if ( !write_word( sfp, stack[tmp_fp] ) ) - return FALSE; - stkslen += 8 + 2 * ( nvars + nstk ); - } + if ( h_type != 6 ) + { /* write a dummy frame for stack used before first call */ + for ( i = 0; i < 6; ++i ) + if ( !write_byte( sfp, 0 ) ) + return FALSE; + nstk = STACK_SIZE - 1 - init_fp; + if ( !write_word( sfp, nstk ) ) + return FALSE; + for ( i = STACK_SIZE - 1; i > init_fp; --i ) + if ( !write_word( sfp, stack[i] ) ) + return FALSE; + stkslen = 8 + 2 * nstk; + } + for ( i = n; i > 0; --i ) + { + /* write out one stack frame. + * + * tmp_fp : FP when this frame was current + * tmp_pc : PC on return from this frame, plus 000pvvvv + * nvars : number of local vars for this frame + * args : argument mask for this frame + * nstk : words of evaluation stack used for this frame + * var : variable to store result + */ + tmp_fp = frames[i]; + nvars = ( stack[tmp_fp + 1] & VARS_MASK ) >> VAR_SHIFT; + args = stack[tmp_fp + 1] & ARGS_MASK; + nstk = tmp_fp - frames[i - 1] - nvars - 4; + tmp_pc = stack[tmp_fp + 3] + ( ul_t ) stack[tmp_fp + 4] * PAGE_SIZE; + switch ( stack[tmp_fp + 1] & TYPE_MASK ) + { + case FUNCTION: + var = read_data_byte( &tmp_pc ); /* also increments tmp_pc */ + tmp_pc = ( tmp_pc << 8 ) | nvars; + break; + case PROCEDURE: + var = 0; + tmp_pc = ( tmp_pc << 8 ) | 0x10 | nvars; /* set procedure flag */ + break; + /* case ASYNC: */ + default: + output_line( "Illegal Z-machine operation: can't save while in interrupt." ); + return FALSE; + } + if ( args != 0 ) + args = ( 1 << args ) - 1; /* make args into bitmap */ + if ( !write_long( sfp, tmp_pc ) ) + return FALSE; + if ( !write_byte( sfp, var ) ) + return FALSE; + if ( !write_byte( sfp, args ) ) + return FALSE; + if ( !write_word( sfp, nstk ) ) + return FALSE; + for ( j = 0; j < nvars + nstk; ++j, --tmp_fp ) + if ( !write_word( sfp, stack[tmp_fp] ) ) + return FALSE; + stkslen += 8 + 2 * ( nvars + nstk ); + } - /* fill in lengths for variable-sized chunks */ - ifzslen = 3 * 8 + 4 + 14 + cmemlen + stkslen; - if ( cmemlen & 1 ) - ++ifzslen; - ( void ) fseek( sfp, ( long ) 4, SEEK_SET ); - if ( !write_long( sfp, ifzslen ) ) - return FALSE; - ( void ) fseek( sfp, cmempos + 4, SEEK_SET ); - if ( !write_long( sfp, cmemlen ) ) - return FALSE; - ( void ) fseek( sfp, stkspos + 4, SEEK_SET ); - if ( !write_long( sfp, stkslen ) ) - return FALSE; + /* fill in lengths for variable-sized chunks */ + ifzslen = 3 * 8 + 4 + 14 + cmemlen + stkslen; + if ( cmemlen & 1 ) + ++ifzslen; + ( void ) fseek( sfp, ( long ) 4, SEEK_SET ); + if ( !write_long( sfp, ifzslen ) ) + return FALSE; + ( void ) fseek( sfp, cmempos + 4, SEEK_SET ); + if ( !write_long( sfp, cmemlen ) ) + return FALSE; + ( void ) fseek( sfp, stkspos + 4, SEEK_SET ); + if ( !write_long( sfp, stkslen ) ) + return FALSE; - return TRUE; + return TRUE; } /* end save_quetzal */ @@ -247,14 +247,14 @@ int save_quetzal( FILE * sfp, FILE * gfp ) static int read_word( FILE * fp, zword_t * result ) { - int a, b; + int a, b; - if ( ( a = get_c( fp ) ) == EOF ) - return FALSE; - if ( ( b = get_c( fp ) ) == EOF ) - return FALSE; - *result = ( ( zword_t ) a << 8 ) | b; - return TRUE; + if ( ( a = get_c( fp ) ) == EOF ) + return FALSE; + if ( ( b = get_c( fp ) ) == EOF ) + return FALSE; + *result = ( ( zword_t ) a << 8 ) | b; + return TRUE; } /* read_long @@ -264,21 +264,21 @@ static int read_word( FILE * fp, zword_t * result ) static int read_long( FILE * fp, ul_t * result ) { - int a, b, c, d; + int a, b, c, d; - if ( ( a = get_c( fp ) ) == EOF ) - return FALSE; - if ( ( b = get_c( fp ) ) == EOF ) - return FALSE; - if ( ( c = get_c( fp ) ) == EOF ) - return FALSE; - if ( ( d = get_c( fp ) ) == EOF ) - return FALSE; - *result = ( ( ul_t ) a << 24 ) | ( ( ul_t ) b << 16 ) | ( ( ul_t ) c << 8 ) | d; + if ( ( a = get_c( fp ) ) == EOF ) + return FALSE; + if ( ( b = get_c( fp ) ) == EOF ) + return FALSE; + if ( ( c = get_c( fp ) ) == EOF ) + return FALSE; + if ( ( d = get_c( fp ) ) == EOF ) + return FALSE; + *result = ( ( ul_t ) a << 24 ) | ( ( ul_t ) b << 16 ) | ( ( ul_t ) c << 8 ) | d; #ifdef QDEBUG - printf( "%c%c%c%c", a, b, c, d ); + printf( "%c%c%c%c", a, b, c, d ); #endif - return TRUE; + return TRUE; } /* restore_quetzal @@ -299,274 +299,274 @@ int restore_quetzal( FILE * sfp, gzFile * gfp ) int restore_quetzal( FILE * sfp, FILE * gfp ) #endif { - ul_t ifzslen, currlen, tmpl, skip = 0; - zword_t i, tmpw; - zbyte_t progress = GOT_NONE; - int x, y; + ul_t ifzslen, currlen, tmpl, skip = 0; + zword_t i, tmpw; + zbyte_t progress = GOT_NONE; + int x, y; - /* check for IFZS file */ - if ( !read_long( sfp, &tmpl ) || !read_long( sfp, &ifzslen ) ) - return FALSE; - if ( !read_long( sfp, &currlen ) ) - return FALSE; - if ( tmpl != ID_FORM || currlen != ID_IFZS ) - { - output_line( "This is not a saved game file!" ); - return FALSE; - } - if ( ( ifzslen & 1 ) || ifzslen < 4 ) - return FALSE; - ifzslen -= 4; + /* check for IFZS file */ + if ( !read_long( sfp, &tmpl ) || !read_long( sfp, &ifzslen ) ) + return FALSE; + if ( !read_long( sfp, &currlen ) ) + return FALSE; + if ( tmpl != ID_FORM || currlen != ID_IFZS ) + { + output_line( "This is not a saved game file!" ); + return FALSE; + } + if ( ( ifzslen & 1 ) || ifzslen < 4 ) + return FALSE; + ifzslen -= 4; - /* read a chunk and process it */ - while ( ifzslen > 0 ) - { - /* read chunk header */ - if ( ifzslen < 8 ) - return FALSE; - if ( !read_long( sfp, &tmpl ) || !read_long( sfp, &currlen ) ) - return FALSE; - ifzslen -= 8; + /* read a chunk and process it */ + while ( ifzslen > 0 ) + { + /* read chunk header */ + if ( ifzslen < 8 ) + return FALSE; + if ( !read_long( sfp, &tmpl ) || !read_long( sfp, &currlen ) ) + return FALSE; + ifzslen -= 8; - /* body of chunk */ - if ( ifzslen < currlen ) - return FALSE; - skip = currlen & 1; - ifzslen -= currlen + skip; - switch ( tmpl ) - { - case ID_IFhd: - if ( progress & GOT_HEADER ) - { - output_line( "Save file has two IFhd chunks!" ); - return FALSE; - } - progress |= GOT_HEADER; - if ( currlen < 13 || !read_word( sfp, &i ) ) - return FALSE; - if ( i != h_version ) - progress = GOT_ERROR; - for ( i = H_RELEASE_DATE; i < H_RELEASE_DATE + 6; ++i ) - { - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - if ( x != ( int ) get_byte( i ) ) - progress = GOT_ERROR; - } - if ( !read_word( sfp, &i ) ) - return FALSE; - if ( i != h_checksum ) - progress = GOT_ERROR; - if ( progress == GOT_ERROR ) - { - output_line( "File was not saved from this story!" ); - return FALSE; - } - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - pc = ( ul_t ) x << 16; - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - pc |= ( ul_t ) x << 8; - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - pc |= ( ul_t ) x; - for ( i = 13; ( ul_t ) i < currlen; ++i ) - ( void ) get_c( sfp ); /* skip rest of chunk */ - break; - case ID_Stks: - if ( progress & GOT_STACK ) - { - output_line( "File contains two stack chunks!" ); - break; - } - progress |= GOT_STACK; - sp = STACK_SIZE; - if ( h_type != 6 ) - { - /* dummy stack frame for stack used before call */ - if ( currlen < 8 ) - return FALSE; - for ( i = 0; i < 6; ++i ) - if ( get_c( sfp ) != 0 ) - return FALSE; - if ( !read_word( sfp, &tmpw ) ) - return FALSE; - currlen -= 8; - if ( currlen < (unsigned long)(tmpw * 2) ) - return FALSE; - for ( i = 0; i < tmpw; ++i ) - if ( !read_word( sfp, stack + ( --sp ) ) ) - return FALSE; - currlen -= tmpw * 2; - } - for ( fp = STACK_SIZE - 1, frame_count = 0; currlen > 0; currlen -= 8 ) - { - if ( currlen < 8 ) - return FALSE; - if ( sp < 4 ) - { - output_line( "error: this save-file has too much stack, and I can't cope." ); - return FALSE; - } - /* read PC, procedure flag, and arg count */ - if ( !read_long( sfp, &tmpl ) ) - return FALSE; - y = ( zword_t ) tmpl & 0x0F; - tmpw = y << VAR_SHIFT; /* number of variables */ - /* read result variable */ - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; + /* body of chunk */ + if ( ifzslen < currlen ) + return FALSE; + skip = currlen & 1; + ifzslen -= currlen + skip; + switch ( tmpl ) + { + case ID_IFhd: + if ( progress & GOT_HEADER ) + { + output_line( "Save file has two IFhd chunks!" ); + return FALSE; + } + progress |= GOT_HEADER; + if ( currlen < 13 || !read_word( sfp, &i ) ) + return FALSE; + if ( i != h_version ) + progress = GOT_ERROR; + for ( i = H_RELEASE_DATE; i < H_RELEASE_DATE + 6; ++i ) + { + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + if ( x != ( int ) get_byte( i ) ) + progress = GOT_ERROR; + } + if ( !read_word( sfp, &i ) ) + return FALSE; + if ( i != h_checksum ) + progress = GOT_ERROR; + if ( progress == GOT_ERROR ) + { + output_line( "File was not saved from this story!" ); + return FALSE; + } + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + pc = ( ul_t ) x << 16; + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + pc |= ( ul_t ) x << 8; + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + pc |= ( ul_t ) x; + for ( i = 13; ( ul_t ) i < currlen; ++i ) + ( void ) get_c( sfp ); /* skip rest of chunk */ + break; + case ID_Stks: + if ( progress & GOT_STACK ) + { + output_line( "File contains two stack chunks!" ); + break; + } + progress |= GOT_STACK; + sp = STACK_SIZE; + if ( h_type != 6 ) + { + /* dummy stack frame for stack used before call */ + if ( currlen < 8 ) + return FALSE; + for ( i = 0; i < 6; ++i ) + if ( get_c( sfp ) != 0 ) + return FALSE; + if ( !read_word( sfp, &tmpw ) ) + return FALSE; + currlen -= 8; + if ( currlen < (unsigned long)(tmpw * 2) ) + return FALSE; + for ( i = 0; i < tmpw; ++i ) + if ( !read_word( sfp, stack + ( --sp ) ) ) + return FALSE; + currlen -= tmpw * 2; + } + for ( fp = STACK_SIZE - 1, frame_count = 0; currlen > 0; currlen -= 8 ) + { + if ( currlen < 8 ) + return FALSE; + if ( sp < 4 ) + { + output_line( "error: this save-file has too much stack, and I can't cope." ); + return FALSE; + } + /* read PC, procedure flag, and arg count */ + if ( !read_long( sfp, &tmpl ) ) + return FALSE; + y = ( zword_t ) tmpl & 0x0F; + tmpw = (zword_t)(y << VAR_SHIFT); /* number of variables */ + /* read result variable */ + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; - if ( tmpl & 0x10 ) - { - tmpw |= PROCEDURE; - tmpl >>= 8; - } - else - { - tmpw |= FUNCTION; - tmpl >>= 8; - --tmpl; - /* sanity check on result variable */ - if ( read_data_byte( &tmpl ) != ( zbyte_t ) x ) - { - output_line( "error: wrong variable number on stack (wrong story file?)." ); - return FALSE; - } - --tmpl; /* read_data_byte increments it */ - } - stack[--sp] = ( zword_t ) ( tmpl / PAGE_SIZE ); - stack[--sp] = ( zword_t ) ( tmpl % PAGE_SIZE ); - stack[--sp] = fp; + if ( tmpl & 0x10 ) + { + tmpw |= PROCEDURE; + tmpl >>= 8; + } + else + { + tmpw |= FUNCTION; + tmpl >>= 8; + --tmpl; + /* sanity check on result variable */ + if ( read_data_byte( &tmpl ) != ( zbyte_t ) x ) + { + output_line( "error: wrong variable number on stack (wrong story file?)." ); + return FALSE; + } + --tmpl; /* read_data_byte increments it */ + } + stack[--sp] = ( zword_t ) ( tmpl / PAGE_SIZE ); + stack[--sp] = ( zword_t ) ( tmpl % PAGE_SIZE ); + stack[--sp] = fp; - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - ++x; /* hopefully x now contains a single set bit */ + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + ++x; /* hopefully x now contains a single set bit */ - for ( i = 0; i < 8; ++i ) - if ( x & ( 1 << i ) ) - break; - if ( x ^ ( 1 << i ) ) /* if more than 1 bit set */ - { - output_line - ( "error: this game uses incomplete argument lists (which I can't handle)." ); - return FALSE; - } - tmpw |= i; - stack[--sp] = tmpw; - fp = sp - 1; /* FP for next frame */ - if ( !read_word( sfp, &tmpw ) ) - return FALSE; - tmpw += y; /* local vars plus eval stack used */ - if ( tmpw >= sp ) - { - output_line( "error: this save-file uses more stack than I can cope with." ); - return FALSE; - } - if ( currlen < (unsigned long)(tmpw * 2) ) - return FALSE; - for ( i = 0; i < tmpw; ++i ) - if ( !read_word( sfp, stack + ( --sp ) ) ) - return FALSE; - currlen -= tmpw * 2; - } - break; - case ID_ANNO: - z_buffer_mode( ON ); - for ( ; currlen > 0; --currlen ) - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - else - write_char( x ); - write_char( ( char ) 13 ); - break; - case ID_CMem: - if ( !( progress & GOT_MEMORY ) ) - { - jz_rewind( gfp ); - i = 0; /* bytes written to data area */ - for ( ; currlen > 0; --currlen ) - { - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - if ( x == 0 ) /* start run */ - { - if ( currlen < 2 ) - { - output_line( "File contains bogus CMem chunk" ); - for ( ; currlen > 0; --currlen ) - ( void ) get_c( sfp ); /* skip rest */ - currlen = 1; - i = 0xFFFF; - break; /* keep going in case there's a UMem */ - } - --currlen; - if ( ( x = get_c( sfp ) ) == EOF ) - return FALSE; - for ( ; x >= 0 && i < h_restart_size; --x, ++i ) - if ( ( y = jz_getc( gfp ) ) == EOF ) - return FALSE; - else - set_byte( i, y ); - } - else /* not a run */ - { - if ( ( y = jz_getc( gfp ) ) == EOF ) - return FALSE; - set_byte( i, x ^ y ); - ++i; - } - if ( i > h_restart_size ) - { - output_line( "warning: CMem chunk too long!" ); - for ( ; currlen > 1; --currlen ) - ( void ) get_c( sfp ); /* skip rest */ - break; /* keep going in case there's a UMem */ - } - } - /* if chunk is short, assume a run */ - for ( ; i < h_restart_size; ++i ) - if ( ( y = jz_getc( gfp ) ) == EOF ) - return FALSE; - else - set_byte( i, y ); - if ( currlen == 0 ) - progress |= GOT_MEMORY; /* only if succeeded */ - break; - } - /* Fall thru (to default) if already got memory */ - case ID_UMem: - if ( !( progress & GOT_MEMORY ) ) - { - if ( currlen == h_restart_size ) - { - if ( fread( datap, h_restart_size, 1, sfp ) == 1 ) - { - progress |= GOT_MEMORY; /* only if succeeded */ - break; - } - } - else - output_line( "warning: UMem chunk wrong size!" ); - /* and fall thru into default */ - } - /* Fall thru (to default) if already got memory */ - default: - ( void ) fseek( sfp, currlen, SEEK_CUR ); /* skip chunk */ - break; - } - if ( skip ) - ( void ) get_c( sfp ); /* skip pad byte */ - } + for ( i = 0; i < 8; ++i ) + if ( x & ( 1 << i ) ) + break; + if ( x ^ ( 1 << i ) ) /* if more than 1 bit set */ + { + output_line + ( "error: this game uses incomplete argument lists (which I can't handle)." ); + return FALSE; + } + tmpw |= i; + stack[--sp] = tmpw; + fp = sp - 1; /* FP for next frame */ + if ( !read_word( sfp, &tmpw ) ) + return FALSE; + tmpw += y; /* local vars plus eval stack used */ + if ( tmpw >= sp ) + { + output_line( "error: this save-file uses more stack than I can cope with." ); + return FALSE; + } + if ( currlen < (unsigned long)(tmpw * 2) ) + return FALSE; + for ( i = 0; i < tmpw; ++i ) + if ( !read_word( sfp, stack + ( --sp ) ) ) + return FALSE; + currlen -= tmpw * 2; + } + break; + case ID_ANNO: + z_buffer_mode( ON ); + for ( ; currlen > 0; --currlen ) + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + else + write_char( x ); + write_char( ( char ) 13 ); + break; + case ID_CMem: + if ( !( progress & GOT_MEMORY ) ) + { + jz_rewind( gfp ); + i = 0; /* bytes written to data area */ + for ( ; currlen > 0; --currlen ) + { + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + if ( x == 0 ) /* start run */ + { + if ( currlen < 2 ) + { + output_line( "File contains bogus CMem chunk" ); + for ( ; currlen > 0; --currlen ) + ( void ) get_c( sfp ); /* skip rest */ + currlen = 1; + i = 0xFFFF; + break; /* keep going in case there's a UMem */ + } + --currlen; + if ( ( x = get_c( sfp ) ) == EOF ) + return FALSE; + for ( ; x >= 0 && i < h_restart_size; --x, ++i ) + if ( ( y = jz_getc( gfp ) ) == EOF ) + return FALSE; + else + set_byte( i, y ); + } + else /* not a run */ + { + if ( ( y = jz_getc( gfp ) ) == EOF ) + return FALSE; + set_byte( i, x ^ y ); + ++i; + } + if ( i > h_restart_size ) + { + output_line( "warning: CMem chunk too long!" ); + for ( ; currlen > 1; --currlen ) + ( void ) get_c( sfp ); /* skip rest */ + break; /* keep going in case there's a UMem */ + } + } + /* if chunk is short, assume a run */ + for ( ; i < h_restart_size; ++i ) + if ( ( y = jz_getc( gfp ) ) == EOF ) + return FALSE; + else + set_byte( i, y ); + if ( currlen == 0 ) + progress |= GOT_MEMORY; /* only if succeeded */ + break; + } + /* Fall thru (to default) if already got memory */ + case ID_UMem: + if ( !( progress & GOT_MEMORY ) ) + { + if ( currlen == h_restart_size ) + { + if ( fread( datap, h_restart_size, 1, sfp ) == 1 ) + { + progress |= GOT_MEMORY; /* only if succeeded */ + break; + } + } + else + output_line( "warning: UMem chunk wrong size!" ); + /* and fall thru into default */ + } + /* Fall thru (to default) if already got memory */ + default: + ( void ) fseek( sfp, (long)currlen, SEEK_CUR ); /* skip chunk */ + break; + } + if ( skip ) + ( void ) get_c( sfp ); /* skip pad byte */ + } - if ( !( progress & GOT_HEADER ) ) - output_line( "error: no header chunk in file." ); - if ( !( progress & GOT_STACK ) ) - output_line( "error: no stack chunk in file." ); - if ( !( progress & GOT_MEMORY ) ) - output_line( "error: no memory chunk in file." ); - return ( progress == GOT_ALL ); + if ( !( progress & GOT_HEADER ) ) + output_line( "error: no header chunk in file." ); + if ( !( progress & GOT_STACK ) ) + output_line( "error: no stack chunk in file." ); + if ( !( progress & GOT_MEMORY ) ) + output_line( "error: no memory chunk in file." ); + return ( progress == GOT_ALL ); } diff --git a/text.c b/text.c index b1ae0a0..3e77d39 100644 --- a/text.c +++ b/text.c @@ -1,14 +1,14 @@ -/* $Id: text.c,v 1.5 2000/10/10 14:46:22 jholder Exp $ +/* $Id: text.c,v 1.5 2000/10/10 14:46:22 jholder Exp $ * -------------------------------------------------------------------- - * see doc/License.txt for License Information + * see doc/License.txt for License Information * -------------------------------------------------------------------- - * - * File name: $Id: text.c,v 1.5 2000/10/10 14:46:22 jholder Exp $ - * - * Description: - * - * Modification history: + * + * File name: $Id: text.c,v 1.5 2000/10/10 14:46:22 jholder Exp $ + * + * Description: + * + * Modification history: * $Log: text.c,v $ * Revision 1.5 2000/10/10 14:46:22 jholder * Fixed text wrap bug when printing array w/ \r chars in it @@ -60,211 +60,211 @@ static int char_count = 0; void decode_text( unsigned long *address ) { - int i, synonym_flag, synonym = 0, zscii_flag, zscii = 0; - int data, code, shift_state, shift_lock; - unsigned long addr; + int i, synonym_flag, synonym = 0, zscii_flag, zscii = 0; + int data, code, shift_state, shift_lock; + unsigned long addr; - /* Set state variables */ + /* Set state variables */ - shift_state = 0; - shift_lock = 0; - zscii_flag = 0; - synonym_flag = 0; + shift_state = 0; + shift_lock = 0; + zscii_flag = 0; + synonym_flag = 0; - do - { + do + { - /* - * Read one 16 bit word. Each word contains three 5 bit codes. If the - * high bit is set then this is the last word in the string. - */ + /* + * Read one 16 bit word. Each word contains three 5 bit codes. If the + * high bit is set then this is the last word in the string. + */ - data = read_data_word( address ); + data = read_data_word( address ); - for ( i = 10; i >= 0; i -= 5 ) - { + for ( i = 10; i >= 0; i -= 5 ) + { - /* Get code, high bits first */ + /* Get code, high bits first */ - code = ( data >> i ) & 0x1f; + code = ( data >> i ) & 0x1f; - /* Synonym codes */ + /* Synonym codes */ - if ( synonym_flag ) - { + if ( synonym_flag ) + { - synonym_flag = 0; - synonym = ( synonym - 1 ) * 64; - addr = ( unsigned long ) get_word( h_synonyms_offset + synonym + ( code * 2 ) ) * 2; - decode_text( &addr ); - shift_state = shift_lock; + synonym_flag = 0; + synonym = ( synonym - 1 ) * 64; + addr = ( unsigned long ) get_word( h_synonyms_offset + synonym + ( code * 2 ) ) * 2; + decode_text( &addr ); + shift_state = shift_lock; - } - /* ZSCII codes */ - else if ( zscii_flag ) - { + } + /* ZSCII codes */ + else if ( zscii_flag ) + { - /* - * If this is the first part ZSCII ten-bit code then remember it. - * Because the codes are only 5 bits you need two codes to make - * one eight bit ASCII character. The first code contains the - * top 5 bits (although only 3 bits are used at the moment). - * The second code contains the bottom 5 bits. - */ + /* + * If this is the first part ZSCII ten-bit code then remember it. + * Because the codes are only 5 bits you need two codes to make + * one eight bit ASCII character. The first code contains the + * top 5 bits (although only 3 bits are used at the moment). + * The second code contains the bottom 5 bits. + */ - if ( zscii_flag++ == 1 ) - { - zscii = code << 5; - } - /* - * If this is the second part of a ten-bit ZSCII code then assemble the - * character from the two codes and output it. - */ - else - { - zscii_flag = 0; - write_zchar( ( unsigned char ) ( zscii | code ) ); - } + if ( zscii_flag++ == 1 ) + { + zscii = code << 5; + } + /* + * If this is the second part of a ten-bit ZSCII code then assemble the + * character from the two codes and output it. + */ + else + { + zscii_flag = 0; + write_zchar( ( unsigned char ) ( zscii | code ) ); + } - } + } - /* Character codes */ - else if ( code > 5 ) - { + /* Character codes */ + else if ( code > 5 ) + { - code -= 6; + code -= 6; - /* - * If this is character 0 in the punctuation set then the next two - * codes make a ten-bit ZSCII character. (Std. Sec. 3.4) - */ + /* + * If this is character 0 in the punctuation set then the next two + * codes make a ten-bit ZSCII character. (Std. Sec. 3.4) + */ - if ( shift_state == 2 && code == 0 ) - { - zscii_flag = 1; - } + if ( shift_state == 2 && code == 0 ) + { + zscii_flag = 1; + } - /* - * If this is character 1 in the punctuation set then this - * is a new line. - */ + /* + * If this is character 1 in the punctuation set then this + * is a new line. + */ - else if ( shift_state == 2 && code == 1 && h_type > V1 ) - { - z_new_line( ); - } - /* - * This is a normal character so select it from the character - * table appropriate for the current shift state. - */ + else if ( shift_state == 2 && code == 1 && h_type > V1 ) + { + z_new_line( ); + } + /* + * This is a normal character so select it from the character + * table appropriate for the current shift state. + */ - else - { - write_zchar( lookup_table[shift_state][code] ); - } - shift_state = shift_lock; + else + { + write_zchar( lookup_table[shift_state][code] ); + } + shift_state = shift_lock; - } + } - /* Special codes 0 to 5 */ - else - { + /* Special codes 0 to 5 */ + else + { - /* Space: 0 Output a space character. */ + /* Space: 0 Output a space character. */ - if ( code == 0 ) - { - write_zchar( ' ' ); - } - else - { - /* The use of the synonym and shift codes is the only - * difference between the different versions. - */ + if ( code == 0 ) + { + write_zchar( ' ' ); + } + else + { + /* The use of the synonym and shift codes is the only + * difference between the different versions. + */ - if ( h_type < V3 ) - { + if ( h_type < V3 ) + { - /* Newline or synonym: 1 - * Output a newline character or set synonym flag. - */ + /* Newline or synonym: 1 + * Output a newline character or set synonym flag. + */ - if ( code == 1 ) - { - if ( h_type == V1 ) - { - z_new_line( ); - } - else - { - synonym_flag = 1; - synonym = code; - } - } - else - { - /* - * Shift keys: 2, 3, 4 or 5 - * - * Shift keys 2 & 3 only shift the next character and can be used regardless of - * the state of the shift lock. Shift keys 4 & 5 lock the shift until reset. - * - * The following code implements the the shift code state transitions: - * +-------------+-------------+-------------+-------------+ - * | Shift State | Lock State | - * +-------------+-------------+-------------+-------------+-------------+ - * | Code | 2 | 3 | 4 | 5 | - * +-------------+-------------+-------------+-------------+-------------+ - * | lowercase | uppercase | punctuation | uppercase | punctuation | - * | uppercase | punctuation | lowercase | punctuation | lowercase | - * | punctuation | lowercase | uppercase | lowercase | uppercase | - * +-------------+-------------+-------------+-------------+-------------+ - */ - if ( code < 4 ) - { - shift_state = ( shift_lock + code + 2 ) % 3; - } - else - { - shift_lock = shift_state = ( shift_lock + code ) % 3; - } - } + if ( code == 1 ) + { + if ( h_type == V1 ) + { + z_new_line( ); + } + else + { + synonym_flag = 1; + synonym = code; + } + } + else + { + /* + * Shift keys: 2, 3, 4 or 5 + * + * Shift keys 2 & 3 only shift the next character and can be used regardless of + * the state of the shift lock. Shift keys 4 & 5 lock the shift until reset. + * + * The following code implements the the shift code state transitions: + * +-------------+-------------+-------------+-------------+ + * | Shift State | Lock State | + * +-------------+-------------+-------------+-------------+-------------+ + * | Code | 2 | 3 | 4 | 5 | + * +-------------+-------------+-------------+-------------+-------------+ + * | lowercase | uppercase | punctuation | uppercase | punctuation | + * | uppercase | punctuation | lowercase | punctuation | lowercase | + * | punctuation | lowercase | uppercase | lowercase | uppercase | + * +-------------+-------------+-------------+-------------+-------------+ + */ + if ( code < 4 ) + { + shift_state = ( shift_lock + code + 2 ) % 3; + } + else + { + shift_lock = shift_state = ( shift_lock + code ) % 3; + } + } - } - else /* not V3 */ - { + } + else /* not V3 */ + { - /* - * Synonym table: 1, 2 or 3 - * - * Selects which of three synonym tables the synonym - * code following in the next code is to use. - */ - if ( code < 4 ) - { - synonym_flag = 1; - synonym = code; - } - /* - * Shift key: 4 or 5 - * - * Selects the shift state for the next character, - * either uppercase (4) or punctuation (5). The shift - * state automatically gets reset back to lowercase for - * V3+ games after the next character is output. - * - */ - else - { - shift_state = code - 3; - shift_lock = 0; - } - } - } - } - } - } - while ( ( data & 0x8000 ) == 0 ); + /* + * Synonym table: 1, 2 or 3 + * + * Selects which of three synonym tables the synonym + * code following in the next code is to use. + */ + if ( code < 4 ) + { + synonym_flag = 1; + synonym = code; + } + /* + * Shift key: 4 or 5 + * + * Selects the shift state for the next character, + * either uppercase (4) or punctuation (5). The shift + * state automatically gets reset back to lowercase for + * V3+ games after the next character is output. + * + */ + else + { + shift_state = code - 3; + shift_lock = 0; + } + } + } + } + } + } + while ( ( data & 0x8000 ) == 0 ); } /* decode_text */ @@ -277,162 +277,162 @@ void decode_text( unsigned long *address ) void encode_text( int len, const char *s, ZINT16 * buffer ) { - int i, j, prev_table, table, next_table, shift_state, code, codes_count; - char codes[9]; + int i, j, prev_table, table, next_table, shift_state, code, codes_count; + char codes[9]; - /* Initialise codes count and prev_table number */ + /* Initialise codes count and prev_table number */ - codes_count = 0; - prev_table = 0; + codes_count = 0; + prev_table = 0; - /* Scan do the string one character at a time */ + /* Scan do the string one character at a time */ - while ( len-- ) - { + while ( len-- ) + { - /* - * Set the table and code to be the ASCII character inducer, then - * look for the character in the three lookup tables. If the - * character isn't found then it will be an ASCII character. - */ + /* + * Set the table and code to be the ASCII character inducer, then + * look for the character in the three lookup tables. If the + * character isn't found then it will be an ASCII character. + */ - table = 2; - code = 0; - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 26; j++ ) - { - if ( lookup_table[i][j] == *s ) - { - table = i; - code = j; - } - } - } + table = 2; + code = 0; + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 26; j++ ) + { + if ( lookup_table[i][j] == *s ) + { + table = i; + code = j; + } + } + } - /* - * Type 1 and 2 games differ on how the shift keys are used. Switch - * now depending on the game version. - */ + /* + * Type 1 and 2 games differ on how the shift keys are used. Switch + * now depending on the game version. + */ - if ( h_type < V3 ) - { + if ( h_type < V3 ) + { - /* - * If the current table is the same as the previous table then - * just store the character code, otherwise switch tables. - */ + /* + * If the current table is the same as the previous table then + * just store the character code, otherwise switch tables. + */ - if ( table != prev_table ) - { + if ( table != prev_table ) + { - /* Find the table for the next character */ + /* Find the table for the next character */ - next_table = 0; - if ( len ) - { - next_table = 2; - for ( i = 0; i < 3; i++ ) - { - for ( j = 0; j < 26; j++ ) - { - if ( lookup_table[i][j] == s[1] ) - next_table = i; - } - } - } + next_table = 0; + if ( len ) + { + next_table = 2; + for ( i = 0; i < 3; i++ ) + { + for ( j = 0; j < 26; j++ ) + { + if ( lookup_table[i][j] == s[1] ) + next_table = i; + } + } + } - /* - * Calculate the shift key. This magic. See the description in - * decode_text for more information on version 1 and 2 shift - * key changes. - */ + /* + * Calculate the shift key. This magic. See the description in + * decode_text for more information on version 1 and 2 shift + * key changes. + */ - shift_state = ( table + ( prev_table * 2 ) ) % 3; + shift_state = ( table + ( prev_table * 2 ) ) % 3; - /* Only store the shift key if there is a change in table */ + /* Only store the shift key if there is a change in table */ - if ( shift_state ) - { + if ( shift_state ) + { - /* - * If the next character as the uses the same table as - * this character then change the shift from a single - * shift to a shift lock. Also remember the current - * table for the next iteration. - */ + /* + * If the next character as the uses the same table as + * this character then change the shift from a single + * shift to a shift lock. Also remember the current + * table for the next iteration. + */ - if ( next_table == table ) - { - shift_state += 2; - prev_table = table; - } - else - prev_table = 0; + if ( next_table == table ) + { + shift_state += 2; + prev_table = table; + } + else + prev_table = 0; - /* Store the code in the codes buffer */ + /* Store the code in the codes buffer */ - if ( codes_count < 9 ) - codes[codes_count++] = ( char ) ( shift_state + 1 ); - } - } - } - else - { + if ( codes_count < 9 ) + codes[codes_count++] = ( char ) ( shift_state + 1 ); + } + } + } + else + { - /* - * For V3 games each uppercase or punctuation table is preceded - * by a separate shift key. If this is such a shift key then - * put it in the codes buffer. - */ + /* + * For V3 games each uppercase or punctuation table is preceded + * by a separate shift key. If this is such a shift key then + * put it in the codes buffer. + */ - if ( table && codes_count < 9 ) - codes[codes_count++] = ( char ) ( table + 3 ); - } + if ( table && codes_count < 9 ) + codes[codes_count++] = ( char ) ( table + 3 ); + } - /* Put the character code in the code buffer */ + /* Put the character code in the code buffer */ - if ( codes_count < 9 ) - codes[codes_count++] = ( char ) ( code + 6 ); + if ( codes_count < 9 ) + codes[codes_count++] = ( char ) ( code + 6 ); - /* - * Cannot find character in table so treat it as a literal ASCII - * code. The ASCII code inducer (code 0 in table 2) is followed by - * the high 3 bits of the ASCII character followed by the low 5 - * bits to make 8 bits in total. - */ + /* + * Cannot find character in table so treat it as a literal ASCII + * code. The ASCII code inducer (code 0 in table 2) is followed by + * the high 3 bits of the ASCII character followed by the low 5 + * bits to make 8 bits in total. + */ - if ( table == 2 && code == 0 ) - { - if ( codes_count < 9 ) - codes[codes_count++] = ( char ) ( ( *s >> 5 ) & 0x07 ); - if ( codes_count < 9 ) - codes[codes_count++] = ( char ) ( *s & 0x1f ); - } + if ( table == 2 && code == 0 ) + { + if ( codes_count < 9 ) + codes[codes_count++] = ( char ) ( ( *s >> 5 ) & 0x07 ); + if ( codes_count < 9 ) + codes[codes_count++] = ( char ) ( *s & 0x1f ); + } - /* Advance to next character */ + /* Advance to next character */ - s++; + s++; - } + } - /* Pad out codes with shift 5's */ + /* Pad out codes with shift 5's */ - while ( codes_count < 9 ) - codes[codes_count++] = 5; + while ( codes_count < 9 ) + codes[codes_count++] = 5; - /* Pack codes into buffer */ + /* Pack codes into buffer */ - buffer[0] = ( ( ZINT16 ) codes[0] << 10 ) | ( ( ZINT16 ) codes[1] << 5 ) | ( ZINT16 ) codes[2]; - buffer[1] = ( ( ZINT16 ) codes[3] << 10 ) | ( ( ZINT16 ) codes[4] << 5 ) | ( ZINT16 ) codes[5]; - buffer[2] = ( ( ZINT16 ) codes[6] << 10 ) | ( ( ZINT16 ) codes[7] << 5 ) | ( ZINT16 ) codes[8]; + buffer[0] = (short)(( ( ZINT16 ) codes[0] << 10 ) | ( ( ZINT16 ) codes[1] << 5 ) | ( ZINT16 ) codes[2]); + buffer[1] = (short)(( ( ZINT16 ) codes[3] << 10 ) | ( ( ZINT16 ) codes[4] << 5 ) | ( ZINT16 ) codes[5]); + buffer[2] = (short)(( ( ZINT16 ) codes[6] << 10 ) | ( ( ZINT16 ) codes[7] << 5 ) | ( ZINT16 ) codes[8]); - /* Terminate buffer at 6 or 9 codes depending on the version */ + /* Terminate buffer at 6 or 9 codes depending on the version */ - if ( h_type < V4 ) - buffer[1] |= 0x8000; - else - buffer[2] |= 0x8000; + if ( h_type < V4 ) + buffer[1] |= 0x8000; + else + buffer[2] |= 0x8000; } /* encode_text */ @@ -448,86 +448,86 @@ void encode_text( int len, const char *s, ZINT16 * buffer ) void write_zchar( int c ) { - char xlat_buffer[MAX_TEXT_SIZE + 1]; - int i; + char xlat_buffer[MAX_TEXT_SIZE + 1]; + int i; - c = ( unsigned int ) ( c & 0xff ); + c = ( unsigned int ) ( c & 0xff ); - /* If character is not special character then just write it */ + /* If character is not special character then just write it */ - if ( c >= ' ' && c <= '~' ) - { - write_char( c ); - } - else if ( c == 13 ) - { - write_char( '\r' ); - } - else - { - /* Put default character in translation buffer */ - xlat_buffer[0] = '?'; - xlat_buffer[1] = '\0'; + if ( c >= ' ' && c <= '~' ) + { + write_char( c ); + } + else if ( c == 13 ) + { + write_char( '\r' ); + } + else + { + /* Put default character in translation buffer */ + xlat_buffer[0] = '?'; + xlat_buffer[1] = '\0'; - /* If translation fails then supply a default */ - if ( codes_to_text( c, xlat_buffer ) ) - { - if ( c > 23 && c < 28 ) - { - /* Arrow keys - these must the keyboard keys used for input */ - static char xlat[4] = { '\\', '/', '+', '-' }; + /* If translation fails then supply a default */ + if ( codes_to_text( c, xlat_buffer ) ) + { + if ( c > 23 && c < 28 ) + { + /* Arrow keys - these must the keyboard keys used for input */ + static char xlat[4] = { '\\', '/', '+', '-' }; - xlat_buffer[0] = xlat[c - 24]; - xlat_buffer[1] = '\0'; - } - else if ( c == 0 ) - { - /* Null - print nothing */ - xlat_buffer[0] = '\0'; - } - else if ( c < 32 ) - { - /* Some other control character: print an octal escape. */ - xlat_buffer[0] = '\\'; - xlat_buffer[1] = ( char ) ( '0' + ( ( c >> 6 ) & 7 ) ); - xlat_buffer[2] = ( char ) ( '0' + ( ( c >> 3 ) & 7 ) ); - xlat_buffer[3] = ( char ) ( '0' + ( c & 7 ) ); - xlat_buffer[4] = '\0'; - } - else if ( c > 178 && c < 219 ) - { - /* IBM line drawing characters to ASCII characters */ - if ( c == 179 ) - xlat_buffer[0] = '|'; - else if ( c == 186 ) - xlat_buffer[0] = '#'; - else if ( c == 196 ) - xlat_buffer[0] = '-'; - else if ( c == 205 ) - xlat_buffer[0] = '='; - else - xlat_buffer[0] = '+'; - xlat_buffer[1] = '\0'; - } - else if ( c > 154 && c < 164 ) - { - /* German character replacements */ - static char xlat[] = "aeoeueAeOeUess>><<"; + xlat_buffer[0] = xlat[c - 24]; + xlat_buffer[1] = '\0'; + } + else if ( c == 0 ) + { + /* Null - print nothing */ + xlat_buffer[0] = '\0'; + } + else if ( c < 32 ) + { + /* Some other control character: print an octal escape. */ + xlat_buffer[0] = '\\'; + xlat_buffer[1] = ( char ) ( '0' + ( ( c >> 6 ) & 7 ) ); + xlat_buffer[2] = ( char ) ( '0' + ( ( c >> 3 ) & 7 ) ); + xlat_buffer[3] = ( char ) ( '0' + ( c & 7 ) ); + xlat_buffer[4] = '\0'; + } + else if ( c > 178 && c < 219 ) + { + /* IBM line drawing characters to ASCII characters */ + if ( c == 179 ) + xlat_buffer[0] = '|'; + else if ( c == 186 ) + xlat_buffer[0] = '#'; + else if ( c == 196 ) + xlat_buffer[0] = '-'; + else if ( c == 205 ) + xlat_buffer[0] = '='; + else + xlat_buffer[0] = '+'; + xlat_buffer[1] = '\0'; + } + else if ( c > 154 && c < 164 ) + { + /* German character replacements */ + static char xlat[] = "aeoeueAeOeUess>><<"; - xlat_buffer[0] = xlat[( ( c - 155 ) * 2 ) + 0]; - xlat_buffer[1] = xlat[( ( c - 155 ) * 2 ) + 1]; - xlat_buffer[2] = '\0'; - } - } + xlat_buffer[0] = xlat[( ( c - 155 ) * 2 ) + 0]; + xlat_buffer[1] = xlat[( ( c - 155 ) * 2 ) + 1]; + xlat_buffer[2] = '\0'; + } + } - /* Substitute translated characters */ + /* Substitute translated characters */ - for ( i = 0; xlat_buffer[i] != '\0'; i++ ) - { - write_char( ( unsigned char ) xlat_buffer[i] ); - } + for ( i = 0; xlat_buffer[i] != '\0'; i++ ) + { + write_char( ( unsigned char ) xlat_buffer[i] ); + } - } + } } /* write_zchar */ /* @@ -537,27 +537,27 @@ void write_zchar( int c ) */ zbyte_t translate_to_zscii(int c) { - int i; + int i; - if( c>= 0xa0 ) - { - if( h_unicode_table !=0 ) - { - fprintf(stderr,"[[ Unicode support not enabled yet. ]]"); - } - else - { - for (i = 0x9b; i <= 0xdf; i++) - { - if (c == zscii2latin1[i - 0x9b]) - { - return (zbyte_t) i; - } - } - return '?'; - } - } - return (zbyte_t) c; + if( c>= 0xa0 ) + { + if( h_unicode_table !=0 ) + { + fprintf(stderr,"[[ Unicode support not enabled yet. ]]"); + } + else + { + for (i = 0x9b; i <= 0xdf; i++) + { + if (c == zscii2latin1[i - 0x9b]) + { + return (zbyte_t) i; + } + } + return '?'; + } + } + return (zbyte_t) c; } /* @@ -570,109 +570,109 @@ zbyte_t translate_to_zscii(int c) */ void write_char( int c ) { - char *cp; - int right_len; + char *cp; + int right_len; - /* Only do if text formatting is turned on */ + /* Only do if text formatting is turned on */ - if ( redirect_depth ) - { - /* If redirect is on then write the character to the status line - * for V1 to V3 games or into the writeable data area for V4+ games */ - if ( h_type < V4 ) - { - status_line[status_pos++] = ( char ) c; - } - else - { - set_byte( story_pos++, translate_to_zscii(c) ); - story_count++; - } - } - else if ( formatting == ON && screen_window == TEXT_WINDOW ) - { - if ( fit_line( line, line_pos, screen_cols - right_margin ) == 0 || char_count < 1 ) - { - /* Null terminate the line */ - line[line_pos] = '\0'; + if ( redirect_depth ) + { + /* If redirect is on then write the character to the status line + * for V1 to V3 games or into the writeable data area for V4+ games */ + if ( h_type < V4 ) + { + status_line[status_pos++] = ( char ) c; + } + else + { + set_byte( story_pos++, translate_to_zscii(c) ); + story_count++; + } + } + else if ( formatting == ON && screen_window == TEXT_WINDOW ) + { + if ( fit_line( line, line_pos, screen_cols - right_margin ) == 0 || char_count < 1 ) + { + /* Null terminate the line */ + line[line_pos] = '\0'; - /* If the next character is a space then no wrap is neccessary */ - if ( c == ' ' ) - { - z_new_line( ); - c = '\0'; - } - else - { - /* Wrap the line. First find the last space */ - cp = strrchr( line, ' ' ); + /* If the next character is a space then no wrap is neccessary */ + if ( c == ' ' ) + { + z_new_line( ); + c = '\0'; + } + else + { + /* Wrap the line. First find the last space */ + cp = strrchr( line, ' ' ); - /* If no spaces in the lines then cannot do wrap */ - if ( cp == NULL ) - { - /* Output the buffer and a new line */ - z_new_line( ); - } - - if (cp != NULL) - { - /* Terminate the line at the last space */ - *cp++ = '\0'; + /* If no spaces in the lines then cannot do wrap */ + if ( cp == NULL ) + { + /* Output the buffer and a new line */ + z_new_line( ); + } - /* Calculate the text length after the last space */ - right_len = &line[line_pos] - cp; + if (cp != NULL) + { + /* Terminate the line at the last space */ + *cp++ = '\0'; - /* Output the buffer and a new line */ - z_new_line( ); + /* Calculate the text length after the last space */ + right_len = &line[line_pos] - cp; - /* If any text to wrap then move it to the start of the line */ - if ( right_len > 0 ) - { - memmove( line, cp, right_len ); - line_pos = right_len; - } - } - } - } - /* Put the character into the buffer and count it. - * Decrement line width if the character is visible */ - if ( c ) - { - line[line_pos++] = ( char ) c; + /* Output the buffer and a new line */ + z_new_line( ); - /* Wrap the line when there is a newline in the stream. */ - cp = strrchr( line, 13 ); - if ( cp!= NULL ) - { - /* Terminate the line at the last space */ - *cp++ = '\0'; + /* If any text to wrap then move it to the start of the line */ + if ( right_len > 0 ) + { + memmove( line, cp, right_len ); + line_pos = right_len; + } + } + } + } + /* Put the character into the buffer and count it. + * Decrement line width if the character is visible */ + if ( c ) + { + line[line_pos++] = ( char ) c; - /* Calculate the text length after the last space */ - right_len = &line[line_pos] - cp; + /* Wrap the line when there is a newline in the stream. */ + cp = strrchr( line, 13 ); + if ( cp!= NULL ) + { + /* Terminate the line at the last space */ + *cp++ = '\0'; - /* Output the buffer and a new line */ - z_new_line( ); + /* Calculate the text length after the last space */ + right_len = &line[line_pos] - cp; - /* If any text to wrap then move it to the start of the line */ - if ( right_len > 0 ) - { - memmove( line, cp, right_len ); - line_pos = right_len; - } - } + /* Output the buffer and a new line */ + z_new_line( ); - if ( isprint( c ) ) - { - char_count--; - } - } - } - else - { - /* No formatting or output redirection, so just output the character */ - script_char( c ); - output_char( c ); - } + /* If any text to wrap then move it to the start of the line */ + if ( right_len > 0 ) + { + memmove( line, cp, right_len ); + line_pos = right_len; + } + } + + if ( isprint( c ) ) + { + char_count--; + } + } + } + else + { + /* No formatting or output redirection, so just output the character */ + script_char( c ); + output_char( c ); + } } /* write_char */ @@ -687,14 +687,15 @@ void write_char( int c ) void z_set_text_style( zword_t mode ) { - if ( mode >= MIN_ATTRIBUTE && mode <= MAX_ATTRIBUTE ) - { - set_attribute( mode ); - } - else - { - fatal( "@set_text_style called with invalid mode." ); - } + //if ( mode >= MIN_ATTRIBUTE && mode <= MAX_ATTRIBUTE ) + if (mode <= MAX_ATTRIBUTE ) + { + set_attribute( mode ); + } + else + { + fatal( "@set_text_style called with invalid mode." ); + } } /* z_set_text_style */ /* @@ -706,8 +707,8 @@ void z_set_text_style( zword_t mode ) void write_string( const char *s ) { - while ( *s ) - write_char( *s++ ); + while ( *s ) + write_char( *s++ ); } /* write_string */ @@ -720,24 +721,24 @@ void write_string( const char *s ) void flush_buffer( int flag ) { - /* Terminate the line */ - line[line_pos] = '\0'; + /* Terminate the line */ + line[line_pos] = '\0'; - /* Send the line buffer to the printer */ - script_string( line ); - flush_script( ); + /* Send the line buffer to the printer */ + script_string( line ); + flush_script( ); - /* Send the line buffer to the screen */ - output_string( line ); + /* Send the line buffer to the screen */ + output_string( line ); - /* Reset the character count only if a carriage return is expected */ - if ( flag == TRUE ) - { - char_count = screen_cols - right_margin; - } + /* Reset the character count only if a carriage return is expected */ + if ( flag == TRUE ) + { + char_count = screen_cols - right_margin; + } - /* Reset the buffer pointer */ - line_pos = 0; + /* Reset the buffer pointer */ + line_pos = 0; } /* flush_buffer */ @@ -745,21 +746,21 @@ void flush_buffer( int flag ) * z_buffer_mode * * Set the format mode flag. Formatting disables writing into the output buffer. - * If set to 1, text output in the lower window on stream one is buffered so that + * If set to 1, text output in the lower window on stream one is buffered so that * it can be word-wrapped properly. If set to 0, it isn't. * */ void z_buffer_mode( zword_t flag ) { - /* Flush any current output */ - flush_buffer( FALSE ); + /* Flush any current output */ + flush_buffer( FALSE ); - /* Set formatting depending on the flag */ - if ( flag ) - formatting = ON; - else - formatting = OFF; + /* Set formatting depending on the flag */ + if ( flag ) + formatting = ON; + else + formatting = OFF; } /* z_buffer_mode */ @@ -780,142 +781,142 @@ void z_buffer_mode( zword_t flag ) typedef struct redirect_stash_struct { - zword_t count; - zword_t buffer; - zword_t pos; + zword_t count; + zword_t buffer; + zword_t pos; } redirect_stash_t; void z_output_stream( zword_t type, zword_t option ) { - static int redirect_size = 0; - static redirect_stash_t *stash = NULL; + static int redirect_size = 0; + static redirect_stash_t *stash = NULL; - if ( ( ZINT16 ) type == 1 ) - { - /* Turn on text output */ - outputting = ON; - } - else if ( ( ZINT16 ) type == 2 ) - { - /* Turn on scripting */ - open_script( ); - } - else if ( ( ZINT16 ) type == 3 ) - { - /* Turn on output redirection */ - if ( redirect_depth == 0 ) - { - /* Disable text formatting during redirection */ - saved_formatting = formatting; - formatting = OFF; + if ( ( ZINT16 ) type == 1 ) + { + /* Turn on text output */ + outputting = ON; + } + else if ( ( ZINT16 ) type == 2 ) + { + /* Turn on scripting */ + open_script( ); + } + else if ( ( ZINT16 ) type == 3 ) + { + /* Turn on output redirection */ + if ( redirect_depth == 0 ) + { + /* Disable text formatting during redirection */ + saved_formatting = formatting; + formatting = OFF; - /* Enable text redirection */ - redirect_depth = 1; - } - else - { - if ( redirect_size == 0 ) - { - redirect_size = 4; - stash = ( redirect_stash_t * ) malloc( redirect_size * sizeof ( redirect_stash_t ) ); - } - if ( redirect_depth > redirect_size ) - { - redirect_size *= 2; - stash = ( redirect_stash_t * ) realloc( stash, redirect_size * sizeof ( redirect_stash_t ) ); - } + /* Enable text redirection */ + redirect_depth = 1; + } + else + { + if ( redirect_size == 0 ) + { + redirect_size = 4; + stash = ( redirect_stash_t * ) malloc( redirect_size * sizeof ( redirect_stash_t ) ); + } + if ( redirect_depth > redirect_size ) + { + redirect_size *= 2; + stash = ( redirect_stash_t * ) realloc( stash, redirect_size * sizeof ( redirect_stash_t ) ); + } - if ( h_type < V4 ) - { - stash[redirect_depth - 1].pos = status_pos; - } - else - { - stash[redirect_depth - 1].pos = story_pos; - stash[redirect_depth - 1].buffer = story_buffer; - stash[redirect_depth - 1].count = story_count; - } + if ( h_type < V4 ) + { + stash[redirect_depth - 1].pos = status_pos; + } + else + { + stash[redirect_depth - 1].pos = story_pos; + stash[redirect_depth - 1].buffer = story_buffer; + stash[redirect_depth - 1].count = story_count; + } - redirect_depth++; - } + redirect_depth++; + } - /* Set up the redirection pointers */ + /* Set up the redirection pointers */ - if ( h_type < V4 ) - { - status_pos = 0; - } - else - { - story_count = 0; - story_buffer = option; - story_pos = option + 2; - } + if ( h_type < V4 ) + { + status_pos = 0; + } + else + { + story_count = 0; + story_buffer = option; + story_pos = option + 2; + } - } - else if ( ( ZINT16 ) type == 4 ) - { - /* Turn on input recording */ - open_record( ); - } - else if ( ( ZINT16 ) type == -1 ) - { - /* Turn off text output */ - outputting = OFF; - } - else if ( ( ZINT16 ) type == -2 ) - { - /* Turn off scripting */ - close_script( ); - } - else if ( ( ZINT16 ) type == -3 ) - { - /* Turn off output redirection */ - if ( redirect_depth ) - { - if ( redirect_depth == 1 ) - { - /* Restore the format mode and turn off redirection */ - formatting = saved_formatting; - redirect_depth = 0; + } + else if ( ( ZINT16 ) type == 4 ) + { + /* Turn on input recording */ + open_record( ); + } + else if ( ( ZINT16 ) type == -1 ) + { + /* Turn off text output */ + outputting = OFF; + } + else if ( ( ZINT16 ) type == -2 ) + { + /* Turn off scripting */ + close_script( ); + } + else if ( ( ZINT16 ) type == -3 ) + { + /* Turn off output redirection */ + if ( redirect_depth ) + { + if ( redirect_depth == 1 ) + { + /* Restore the format mode and turn off redirection */ + formatting = saved_formatting; + redirect_depth = 0; - /* Terminate the redirection buffer and store the count of - * character in the buffer into the first word of the buffer */ - if ( h_type > V3 ) - { - set_word( story_buffer, story_count ); - } - } - else - { - if ( h_type > V3 ) - { - set_word( story_buffer, story_count ); - } + /* Terminate the redirection buffer and store the count of + * character in the buffer into the first word of the buffer */ + if ( h_type > V3 ) + { + set_word( story_buffer, story_count ); + } + } + else + { + if ( h_type > V3 ) + { + set_word( story_buffer, story_count ); + } - redirect_depth--; + redirect_depth--; - if ( h_type < V4 ) - { - status_pos = stash[redirect_depth - 1].pos; - } - else - { - story_pos = stash[redirect_depth - 1].pos; - story_buffer = stash[redirect_depth - 1].buffer; - story_count = stash[redirect_depth - 1].count; - } + if ( h_type < V4 ) + { + status_pos = stash[redirect_depth - 1].pos; + } + else + { + story_pos = stash[redirect_depth - 1].pos; + story_buffer = stash[redirect_depth - 1].buffer; + story_count = stash[redirect_depth - 1].count; + } - } - } + } + } - } - else if ( ( ZINT16 ) type == -4 ) - { - /* Turn off input recording */ - close_record( ); - } + } + else if ( ( ZINT16 ) type == -4 ) + { + /* Turn off input recording */ + close_record( ); + } } /* z_output_stream */ /* @@ -927,7 +928,7 @@ void z_output_stream( zword_t type, zword_t option ) void z_print_char( zword_t c ) { - write_zchar( ( char ) c ); + write_zchar( ( char ) c ); } /* z_print_char */ /* @@ -939,14 +940,14 @@ void z_print_char( zword_t c ) void z_print_num( zword_t num ) { - int i, count; - char buffer[10]; + int i, count; + char buffer[10]; - i = ( ZINT16 ) num; - sprintf( buffer, "%d", i ); - count = strlen( buffer ); - for ( i = 0; i < count; i++ ) - write_char( buffer[i] ); + i = ( ZINT16 ) num; + sprintf( buffer, "%d", i ); + count = strlen( buffer ); + for ( i = 0; i < count; i++ ) + write_char( buffer[i] ); } /* z_print_num */ @@ -960,13 +961,13 @@ void z_print_num( zword_t num ) void z_print_paddr( zword_t packed_address ) { - unsigned long address; + unsigned long address; - /* Convert packed address to real address */ - address = ( unsigned long ) packed_address * story_scaler; + /* Convert packed address to real address */ + address = ( unsigned long ) packed_address * story_scaler; - /* Decode and output text at address */ - decode_text( &address ); + /* Decode and output text at address */ + decode_text( &address ); } /* z_print_paddr */ @@ -980,12 +981,12 @@ void z_print_paddr( zword_t packed_address ) void z_print_addr( zword_t offset ) { - unsigned long address; + unsigned long address; - address = offset; + address = offset; - /* Decode and output text at address */ - decode_text( &address ); + /* Decode and output text at address */ + decode_text( &address ); } /* z_print_addr */ @@ -999,22 +1000,22 @@ void z_print_addr( zword_t offset ) void z_print_obj( zword_t obj ) { - zword_t offset; - unsigned long address; + zword_t offset; + unsigned long address; - /* Check for NULL object */ - if ( obj == 0 ) - return; + /* Check for NULL object */ + if ( obj == 0 ) + return; - /* Calculate address of property list */ - offset = get_object_address( obj ); - offset += ( h_type < V4 ) ? O3_PROPERTY_OFFSET : O4_PROPERTY_OFFSET; + /* Calculate address of property list */ + offset = get_object_address( obj ); + offset += ( h_type < V4 ) ? O3_PROPERTY_OFFSET : O4_PROPERTY_OFFSET; - /* Read the property list address and skip the count byte */ - address = ( unsigned long ) get_word( offset ) + 1; + /* Read the property list address and skip the count byte */ + address = ( unsigned long ) get_word( offset ) + 1; - /* Decode and output text at address */ - decode_text( &address ); + /* Decode and output text at address */ + decode_text( &address ); } /* z_print_obj */ @@ -1031,8 +1032,8 @@ void z_print_obj( zword_t obj ) void z_print( void ) { - /* Decode and output text at PC */ - decode_text( &pc ); + /* Decode and output text at PC */ + decode_text( &pc ); } /* z_print */ @@ -1048,9 +1049,9 @@ void z_print( void ) void z_print_ret( void ) { - z_print( ); - z_new_line( ); - z_ret( TRUE ); + z_print( ); + z_new_line( ); + z_ret( TRUE ); } /* z_print_ret */ @@ -1065,17 +1066,17 @@ void z_print_ret( void ) void z_new_line( void ) { - /* Only flush buffer if story redirect is off */ - if ( redirect_depth == 0 ) - { - flush_buffer( TRUE ); - script_new_line( ); - output_new_line( ); - } - else - { - write_char( '\r' ); - } + /* Only flush buffer if story redirect is off */ + if ( redirect_depth == 0 ) + { + flush_buffer( TRUE ); + script_new_line( ); + output_new_line( ); + } + else + { + write_char( '\r' ); + } } /* z_new_line */ @@ -1090,34 +1091,34 @@ void z_new_line( void ) void print_time( int hours, int minutes ) { - int pm_indicator; + int pm_indicator; - /* Remember if time is pm */ - pm_indicator = ( hours < 12 ) ? OFF : ON; + /* Remember if time is pm */ + pm_indicator = ( hours < 12 ) ? OFF : ON; - /* Convert 24 hour clock to 12 hour clock */ - hours %= 12; - if ( hours == 0 ) - hours = 12; + /* Convert 24 hour clock to 12 hour clock */ + hours %= 12; + if ( hours == 0 ) + hours = 12; - /* Write hour right justified */ - if ( hours < 10 ) - write_char( ' ' ); - z_print_num( (zword_t)hours ); + /* Write hour right justified */ + if ( hours < 10 ) + write_char( ' ' ); + z_print_num( (zword_t)hours ); - /* Write hours/minutes separator */ - write_char( ':' ); + /* Write hours/minutes separator */ + write_char( ':' ); - /* Write minutes zero filled */ - if ( minutes < 10 ) - write_char( '0' ); - z_print_num( (zword_t)minutes ); + /* Write minutes zero filled */ + if ( minutes < 10 ) + write_char( '0' ); + z_print_num( (zword_t)minutes ); - /* Write the am or pm string */ - if ( pm_indicator == ON ) - write_string( " pm" ); - else - write_string( " am" ); + /* Write the am or pm string */ + if ( pm_indicator == ON ) + write_string( " pm" ); + else + write_string( " am" ); } /* print_time */ @@ -1130,16 +1131,16 @@ void print_time( int hours, int minutes ) void z_encode( zword_t word_addr, zword_t word_length, zword_t word_offset, zword_t dest_addr ) { - ZINT16 word[3]; - int i; + ZINT16 word[3]; + int i; - /* Encode the word */ + /* Encode the word */ - encode_text( word_length, ( const char * ) &datap[word_addr + word_offset], word ); + encode_text( word_length, ( const char * ) &datap[word_addr + word_offset], word ); - /* Move the encoded word, byte swapped, into the destination buffer */ + /* Move the encoded word, byte swapped, into the destination buffer */ - for ( i = 0; i < 3; i++, dest_addr += 2 ) - set_word( dest_addr, word[i] ); + for ( i = 0; i < 3; i++, dest_addr += 2 ) + set_word( dest_addr, word[i] ); } /* z_encode */ diff --git a/ztypes.h b/ztypes.h index 81b4432..0fa488c 100644 --- a/ztypes.h +++ b/ztypes.h @@ -34,8 +34,8 @@ * */ -#if !defined(__ZTYPES_INCLUDED) -#define __ZTYPES_INCLUDED +#if !defined(ZTYPES_INCLUDED) +#define ZTYPES_INCLUDED // IIgs stuff - everyone gets it #include "joey.h" @@ -74,8 +74,11 @@ #endif /* MSDOS */ /* Set Version of JZIP */ +#define JZIPVER "Jzip V2.1" +#define JZIPRELDATE "Tue, Oct 10 2000" +#define JZIPAUTHOR "John Holder (j-holder@home.com)" +#define JZIPURL "http://jzip.sourceforge.net/" -#include "jzip.h" extern unsigned char JTERP; /* Configuration options */ @@ -456,6 +459,11 @@ zobjectv4_t; /* External data */ +extern char save_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; +extern char script_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; +extern char record_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; +extern char auxilary_name[Z_FILENAME_MAX + Z_PATHNAME_MAX + 1]; + extern int GLOBALVER; extern zbyte_t h_type; extern zbyte_t h_config; @@ -796,4 +804,4 @@ void z_load( zword_t ); void z_pull( zword_t ); void z_push( zword_t ); -#endif /* !defined(__ZTYPES_INCLUDED) */ +#endif /* !defined(ZTYPES_INCLUDED) */