From 50f6f0d1235269c3ff4f0534347b8e4663d41aec Mon Sep 17 00:00:00 2001 From: Paul Gardner-Stephen Date: Thu, 25 Apr 2019 16:45:39 +0930 Subject: [PATCH] fix text compression and decompression routines. --- c64/basic/print_packed_message.s | 23 +++++++++++++++-------- src/compress_text.c | 20 ++++++++++---------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/c64/basic/print_packed_message.s b/c64/basic/print_packed_message.s index 2fa33a6b..71e5607f 100644 --- a/c64/basic/print_packed_message.s +++ b/c64/basic/print_packed_message.s @@ -100,11 +100,9 @@ found_packed_word: clc adc temp_string_ptr+0 sta temp_string_ptr+0 - sta $0426 lda temp_string_ptr+1 adc #$00 sta temp_string_ptr+1 - sta $0427 ldy #$ff next_packed_word_char: @@ -176,21 +174,30 @@ has_nybl: no_lo_nybl_char: ;; If current byte has $0F in low nybl, then the next - ;; byte is a whole byte shifted left one bit. - ;; bit 0 indicates if it is the end of the word. + ;; byte is a whole byte. lda (temp_string_ptr),y and #$0f - bne + + cmp #$0f + beq next_is_literal_char - ;; XXX - Implement decoding of this case - -* +ready_for_next_char: cpy #$ff bne next_packed_word_char end_of_packed_word: ;; Hit end of packed data rts +next_is_literal_char: + ;; Output the literal char, and ready for next char + iny + tya + pha + lda (temp_string_ptr),y + jsr $ffd2 + pla + tay + jmp ready_for_next_char + is_uncommon_char: ;; Lower nybl has offset into low-frequency part of the table diff --git a/src/compress_text.c b/src/compress_text.c index ae516071..cbde0ada 100644 --- a/src/compress_text.c +++ b/src/compress_text.c @@ -293,15 +293,8 @@ int pack_word(const char *w,unsigned char *out,int *len) fprintf(stderr,"ERROR: Extended characters must be < 0x80\n"); exit(-1); } - if (w[j+1]) { - out[(*len)++]=(char_num<<1)+1; - fprintf(stderr," XS[$%02x]",char_num); - } - else { - out[(*len)++]=(char_num<<1)+0; - fprintf(stderr," XS0[$%02x]\n",char_num); - return 0; - } + out[(*len)++]=w[j]; + fprintf(stderr," XS[$%02x]",w[j]); } else { if (char_num < (14+13)) { out[(*len)++]=0xF1+(char_num-14); @@ -396,9 +389,16 @@ int main(void) // Now encode the words for(int i=0;i