new text compression and tokeniser - faster, about 100 bytes saved
This commit is contained in:
1 parent
51e45e9983
commit
94170f156c
24 files changed
+1848
-872
No files matched your search
@@ -86,22 +86,16 @@ list_not_quote:
|
||||
pha
|
||||
phy_trash_a
|
||||
|
||||
// Get pointer to compressed keyword list
|
||||
lda #<packed_keywords
|
||||
sta FRESPC+0
|
||||
lda #>packed_keywords
|
||||
sta FRESPC+1
|
||||
|
||||
// Subtract $80 from token to get offset in word
|
||||
// list
|
||||
|
||||
// Subtract $80 from token to get offset in token list
|
||||
txa
|
||||
and #$7f
|
||||
tax
|
||||
|
||||
// Now ask for it to be printed
|
||||
ldy #$ff
|
||||
jsr packed_word_search
|
||||
jsr print_packed_keyword_V2
|
||||
|
||||
// Restore registers
|
||||
ply_trash_a
|
||||
pla
|
||||
|
||||
|
||||
@@ -1,244 +0,0 @@
|
||||
// #LAYOUT# STD * #TAKE
|
||||
// #LAYOUT# M65 * #TAKE
|
||||
// #LAYOUT# X16 BASIC_0 #TAKE
|
||||
// #LAYOUT# * * #IGNORE
|
||||
|
||||
// This routine prints messages that have been packed
|
||||
// using the make_error_tables program.
|
||||
// The general idea is to save space in the ROM.
|
||||
|
||||
// The output of make_error_tables is written to packed_messages.s, and
|
||||
// contains the following:
|
||||
//
|
||||
// packed_message_words - List of nybl packed words.
|
||||
// packed_message_tokens - List of tokens that get joined to make messages
|
||||
// packed_message_chars - List of characters in messages sorted by frequency.
|
||||
|
||||
|
||||
print_packed_message:
|
||||
// .X = message number
|
||||
|
||||
#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_0)
|
||||
|
||||
jsr map_BASIC_1
|
||||
jsr_ind VB1__print_packed_message
|
||||
jmp map_NORMAL
|
||||
|
||||
#else
|
||||
|
||||
lda #$ff
|
||||
ldy #$ff
|
||||
packed_message_search:
|
||||
iny
|
||||
cpx #$00
|
||||
beq found_message_in_token_stream
|
||||
lda packed_message_tokens,y
|
||||
cmp #$ff
|
||||
bne !+
|
||||
dex
|
||||
!:
|
||||
cpy #$ff
|
||||
bne packed_message_search
|
||||
// Could not find message
|
||||
sec
|
||||
rts
|
||||
|
||||
found_message_in_token_stream: // XXX size-optimize this
|
||||
// Now print each word in the message
|
||||
phy_trash_a
|
||||
lda packed_message_tokens,y
|
||||
cmp #$FF
|
||||
beq found_message_in_token_stream_done
|
||||
|
||||
jsr print_packed_word
|
||||
ply_trash_a
|
||||
iny
|
||||
beq found_message_in_token_stream_done
|
||||
!:
|
||||
phy_trash_a
|
||||
lda packed_message_tokens,y
|
||||
cmp #$FF
|
||||
beq found_message_in_token_stream_done
|
||||
|
||||
pha
|
||||
jsr print_space
|
||||
pla
|
||||
|
||||
jsr print_packed_word
|
||||
ply_trash_a
|
||||
iny
|
||||
bne !-
|
||||
|
||||
found_message_in_token_stream_done:
|
||||
pla
|
||||
rts
|
||||
|
||||
print_packed_word:
|
||||
// A = the word to print
|
||||
tax
|
||||
|
||||
// Setup pointer to packed words
|
||||
lda #<packed_message_words
|
||||
sta FRESPC+0
|
||||
lda #>packed_message_words
|
||||
sta FRESPC+1
|
||||
|
||||
// Find the word in the list
|
||||
ldy #$ff
|
||||
packed_word_search:
|
||||
iny
|
||||
cpx #$00
|
||||
beq found_packed_word
|
||||
|
||||
// $x0 is an end of work marker
|
||||
lda (FRESPC),y
|
||||
and #$0f
|
||||
cmp #$00
|
||||
bne !+
|
||||
dex
|
||||
!:
|
||||
// $FE $xx is an end of work marker
|
||||
lda (FRESPC),y
|
||||
cmp #$fe
|
||||
bne !+
|
||||
dex
|
||||
iny // skip next byte
|
||||
!:
|
||||
cmp #$ff
|
||||
bne !+
|
||||
iny // skip next byte
|
||||
!:
|
||||
|
||||
// Advance to next page if required
|
||||
cpy #$ff
|
||||
bne packed_word_search
|
||||
inc FRESPC+1
|
||||
jmp packed_word_search
|
||||
|
||||
found_packed_word:
|
||||
|
||||
// Get pointer to start of packed word
|
||||
// Make sure we do not wrap on a page boundary
|
||||
tya
|
||||
clc
|
||||
adc FRESPC+0
|
||||
sta FRESPC+0
|
||||
lda FRESPC+1
|
||||
adc #$00
|
||||
sta FRESPC+1
|
||||
|
||||
print_packed_string:
|
||||
ldy #$ff
|
||||
|
||||
next_packed_word_char:
|
||||
// .Y = offset into packed word data - 1
|
||||
iny
|
||||
|
||||
// Check for end of word
|
||||
lda (FRESPC),y
|
||||
cmp #$00
|
||||
beq end_of_packed_word
|
||||
cmp #$fe
|
||||
beq last_literal
|
||||
cmp #$ff
|
||||
beq next_is_literal_char
|
||||
and #$f0
|
||||
beq end_of_packed_word
|
||||
|
||||
// Check if it is an uncommon char
|
||||
lda (FRESPC),y
|
||||
and #$f0
|
||||
cmp #$f0
|
||||
beq is_uncommon_char
|
||||
|
||||
// Is not an uncommon char, so get char of upper nybl
|
||||
lda (FRESPC),y
|
||||
|
||||
// Put high nybl into low bits of X
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
tax
|
||||
|
||||
// X=1-14 = first 14 chars, so subtract one
|
||||
lda packed_message_chars-1,x
|
||||
jsr JCHROUT // preserves .Y
|
||||
|
||||
// See if there is a char in the low nybl to print
|
||||
lda (FRESPC),y
|
||||
and #$0f
|
||||
beq end_of_packed_word
|
||||
cmp #$0f
|
||||
beq no_lo_nybl_char
|
||||
|
||||
has_lo_nybl_char:
|
||||
// We need to print the low nybl char as well
|
||||
tax
|
||||
phy_trash_a
|
||||
|
||||
// Skip lower nybls of $F or $0 in nybl packed
|
||||
// bytes, as these do not encode characters
|
||||
cpx #$f
|
||||
beq !+
|
||||
has_nybl:
|
||||
cpx #0
|
||||
beq !+
|
||||
|
||||
// X=1-14 = first 14 chars, so subtract one
|
||||
lda packed_message_chars-1,x
|
||||
jsr JCHROUT
|
||||
!:
|
||||
ply_trash_a
|
||||
// FALLTHROUGH
|
||||
|
||||
no_lo_nybl_char:
|
||||
|
||||
// If current byte has $0F in low nybl, then the next
|
||||
// byte is a whole byte.
|
||||
lda (FRESPC),y
|
||||
and #$0f
|
||||
cmp #$0f
|
||||
beq next_is_literal_char
|
||||
|
||||
ready_for_next_char:
|
||||
cpy #$ff
|
||||
bne next_packed_word_char
|
||||
end_of_packed_word:
|
||||
// Hit end of packed data
|
||||
rts
|
||||
|
||||
last_literal:
|
||||
jsr unpack_literal_char
|
||||
rts
|
||||
|
||||
next_is_literal_char:
|
||||
jsr unpack_literal_char
|
||||
jmp ready_for_next_char
|
||||
|
||||
unpack_literal_char:
|
||||
// Output the literal char, and ready for next char
|
||||
iny
|
||||
phy_trash_a
|
||||
lda (FRESPC),y
|
||||
jsr JCHROUT
|
||||
pla
|
||||
tay
|
||||
rts
|
||||
|
||||
is_uncommon_char:
|
||||
// Lower nybl has offset into low-frequency part of the table
|
||||
|
||||
lda (FRESPC),y
|
||||
and #$0f
|
||||
clc
|
||||
adc #14
|
||||
|
||||
// We need to print the low nybl char as well
|
||||
tax
|
||||
phy_trash_a
|
||||
|
||||
jmp has_nybl
|
||||
|
||||
|
||||
#endif // ROM layout
|
||||
@@ -0,0 +1,182 @@
|
||||
// #LAYOUT# STD * #TAKE
|
||||
// #LAYOUT# M65 * #TAKE
|
||||
// #LAYOUT# X16 BASIC_0 #TAKE
|
||||
// #LAYOUT# * * #IGNORE
|
||||
|
||||
// This routine prints strings that have been packed using the 'generate_trings' tool.
|
||||
// The general idea is to save space in the ROM.
|
||||
|
||||
|
||||
#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_0)
|
||||
|
||||
print_packed_error:
|
||||
|
||||
jsr map_BASIC_1
|
||||
jsr_ind VB1__print_packed_error
|
||||
jmp map_NORMAL
|
||||
|
||||
print_packed_misc_str:
|
||||
|
||||
jsr map_BASIC_1
|
||||
jsr_ind VB1__print_packed_misc_str
|
||||
jmp map_NORMAL
|
||||
|
||||
print_packed_keyword_V2:
|
||||
|
||||
jsr map_BASIC_1
|
||||
jsr_ind VB1__print_packed_keyword_V2
|
||||
jmp map_NORMAL
|
||||
|
||||
#else
|
||||
|
||||
print_packed_error: // .X - error string index
|
||||
|
||||
lda #<packed_str_errors
|
||||
ldy #>packed_str_errors
|
||||
bne print_freq_packed_string // branch always
|
||||
|
||||
print_packed_misc_str: // .X - misc string index
|
||||
|
||||
lda #<packed_str_misc
|
||||
ldy #>packed_str_misc
|
||||
bne print_freq_packed_string // branch always
|
||||
|
||||
print_packed_keyword_V2: // .X - token number
|
||||
|
||||
lda #<packed_str_keywords_V2
|
||||
ldy #>packed_str_keywords_V2
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
print_freq_packed_string: // not to be used directly XXX rename to print_packed_string
|
||||
|
||||
// First store the initial address of the packed strings list
|
||||
|
||||
sta FRESPC+0
|
||||
sty FRESPC+1
|
||||
|
||||
// Now find the address of the string to print out
|
||||
// The implementation assumes no packed string is longer than 255 bytes, including trailing zero
|
||||
!:
|
||||
cpx #$00
|
||||
beq print_freq_packed_string_found // branch if no need to advance anymore
|
||||
dex
|
||||
|
||||
ldy #$00
|
||||
!:
|
||||
lda (FRESPC), y
|
||||
iny
|
||||
cmp #$00
|
||||
bne !- // branch if not the end of packed string
|
||||
|
||||
clc // advance FREESPC pointer
|
||||
tya
|
||||
adc FRESPC+0
|
||||
sta FRESPC+0
|
||||
lda #$00
|
||||
adc FRESPC+1
|
||||
sta FRESPC+1
|
||||
|
||||
jmp !--
|
||||
|
||||
print_freq_packed_string_found:
|
||||
|
||||
// At this point FRESPC contains a pointer to the string to display
|
||||
// and we should start from the lower nibble
|
||||
|
||||
ldy #$00
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
print_freq_packed_string_nibble_lo:
|
||||
|
||||
// Get the low nibble and check for the end of packed string
|
||||
|
||||
lda (FRESPC), y
|
||||
and #$0F
|
||||
beq print_freq_packed_string_end
|
||||
|
||||
// Not the end - check if this is a common character, encoded by a single nibble
|
||||
|
||||
cmp #$0F
|
||||
beq print_freq_packed_string_3n_split
|
||||
|
||||
// Character is encoded by a single nibble - fetch it and display
|
||||
|
||||
tax
|
||||
lda packed_as_1n-1, x
|
||||
jsr JCHROUT // preserves .Y
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
print_freq_packed_string_nibble_hi:
|
||||
|
||||
// Get the high nibble and check for the end of packed string
|
||||
|
||||
lda (FRESPC), y
|
||||
and #$F0
|
||||
beq print_freq_packed_string_end
|
||||
|
||||
// Not the end - check if this is a common character, encoded by a single nibble
|
||||
|
||||
cmp #$F0
|
||||
beq print_freq_packed_string_3n_single
|
||||
|
||||
// Character is encoded by a single nibble - fetch it and display
|
||||
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
lsr
|
||||
|
||||
tax
|
||||
lda packed_as_1n-1, x
|
||||
jmp !+ // XXX should be bra on some CPUs
|
||||
|
||||
print_freq_packed_string_3n_single:
|
||||
|
||||
// Character is encoded using 3 nibbles (1st is a mark, already interpreted)
|
||||
|
||||
iny
|
||||
lda (FRESPC), y
|
||||
tax
|
||||
lda packed_as_3n-1, x
|
||||
!:
|
||||
jsr JCHROUT // preserves .Y
|
||||
|
||||
// Advance to next nibble
|
||||
|
||||
iny
|
||||
bne print_freq_packed_string_nibble_lo // branch always
|
||||
|
||||
print_freq_packed_string_3n_split:
|
||||
|
||||
// Character is encoded using 3 nibbles (1st is a mark, already interpreted),
|
||||
// but the 2 remaining nibbles are in two neighbour bytes; use a stack to combine them
|
||||
|
||||
lda (FRESPC), y
|
||||
and #$F0
|
||||
tsx
|
||||
pha
|
||||
|
||||
iny
|
||||
lda (FRESPC), y
|
||||
and #$0F
|
||||
|
||||
clc
|
||||
adc STACK, x
|
||||
|
||||
txs // one cycle faster than PLA
|
||||
|
||||
tax
|
||||
lda packed_as_3n-1, x
|
||||
jsr JCHROUT // preserves .Y
|
||||
|
||||
jmp print_freq_packed_string_nibble_hi
|
||||
|
||||
print_freq_packed_string_end:
|
||||
|
||||
rts
|
||||
|
||||
|
||||
#endif // ROM layout
|
||||
Reference in new issue
Block a user