diff --git a/Makefile b/Makefile index 1be7f610..5917680b 100644 --- a/Makefile +++ b/Makefile @@ -178,15 +178,15 @@ updatebin: $(TOOL_PNGPREPARE): tools/pngprepare.c @mkdir -p build/tools - $(CC) -O2 -g -Wall -I/usr/local/include -L/usr/local/lib -o $@ $< -lpng + $(CC) -O2 -Wall -I/usr/local/include -L/usr/local/lib -o $@ $< -lpng build/tools/%: tools/%.c @mkdir -p build/tools - $(CC) -O2 -g -Wall -o $@ $< + $(CC) -O2 -Wall -o $@ $< build/tools/%: tools/%.cc tools/common.h @mkdir -p build/tools - $(CXX) -O2 -g -Wall -o $@ $< + $(CXX) -O0 -g -Wall -o $@ $< # Rules - CHARGEN diff --git a/c64/basic/assets/packed_str_keywords_V2.s b/c64/basic/assets/packed_dictionary.s similarity index 58% rename from c64/basic/assets/packed_str_keywords_V2.s rename to c64/basic/assets/packed_dictionary.s index 5247b32e..b7f9c640 100644 --- a/c64/basic/assets/packed_str_keywords_V2.s +++ b/c64/basic/assets/packed_dictionary.s @@ -4,6 +4,10 @@ // #LAYOUT# * * #IGNORE -packed_str_keywords_V2: +#if CONFIG_COMPRESSION_LVL_2 - put_freq_packed_keywords_V2() +packed_dictionary: + + put_packed_freq_DICTIONARY() + +#endif diff --git a/c64/basic/assets/packed_errors.s b/c64/basic/assets/packed_errors.s new file mode 100644 index 00000000..d71177b0 --- /dev/null +++ b/c64/basic/assets/packed_errors.s @@ -0,0 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +#if CONFIG_COMPRESSION_LVL_2 + +packed_dict_errors: + + put_packed_dict_errors() + +#else + +packed_freq_errors: + + put_packed_freq_errors() + +#endif diff --git a/c64/basic/assets/packed_str_errors.s b/c64/basic/assets/packed_keywords_CC.s similarity index 69% rename from c64/basic/assets/packed_str_errors.s rename to c64/basic/assets/packed_keywords_CC.s index 4582fb54..8cbf9bed 100644 --- a/c64/basic/assets/packed_str_errors.s +++ b/c64/basic/assets/packed_keywords_CC.s @@ -4,6 +4,6 @@ // #LAYOUT# * * #IGNORE -packed_str_errors: +packed_freq_keywords_CC: - put_freq_packed_errors() + put_packed_freq_keywords_CC() diff --git a/c64/basic/assets/packed_str_keywords_CC.s b/c64/basic/assets/packed_keywords_CD.s similarity index 69% rename from c64/basic/assets/packed_str_keywords_CC.s rename to c64/basic/assets/packed_keywords_CD.s index 4fe84295..c474d947 100644 --- a/c64/basic/assets/packed_str_keywords_CC.s +++ b/c64/basic/assets/packed_keywords_CD.s @@ -4,6 +4,6 @@ // #LAYOUT# * * #IGNORE -packed_str_keywords_CC: +packed_freq_keywords_CD: - put_freq_packed_keywords_CC() + put_packed_freq_keywords_CD() diff --git a/c64/basic/assets/packed_str_keywords_CD.s b/c64/basic/assets/packed_keywords_V2.s similarity index 69% rename from c64/basic/assets/packed_str_keywords_CD.s rename to c64/basic/assets/packed_keywords_V2.s index 8c9e51f3..b6cd2eab 100644 --- a/c64/basic/assets/packed_str_keywords_CD.s +++ b/c64/basic/assets/packed_keywords_V2.s @@ -4,6 +4,6 @@ // #LAYOUT# * * #IGNORE -packed_str_keywords_CD: +packed_freq_keywords_V2: - put_freq_packed_keywords_CD() + put_packed_freq_keywords_V2() diff --git a/c64/basic/assets/packed_misc.s b/c64/basic/assets/packed_misc.s new file mode 100644 index 00000000..3af051b7 --- /dev/null +++ b/c64/basic/assets/packed_misc.s @@ -0,0 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +#if CONFIG_COMPRESSION_LVL_2 + +packed_dict_misc: + + put_packed_dict_misc() + +#else + +packed_freq_misc: + + put_packed_freq_misc() + +#endif diff --git a/c64/basic/assets/packed_str_misc.s b/c64/basic/assets/packed_str_misc.s deleted file mode 100644 index bceadcdf..00000000 --- a/c64/basic/assets/packed_str_misc.s +++ /dev/null @@ -1,9 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# M65 BASIC_1 #TAKE -// #LAYOUT# X16 BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - - -packed_str_misc: - - put_freq_packed_misc() diff --git a/c64/basic/print/print_packed_dict_string.s b/c64/basic/print/print_packed_dict_string.s new file mode 100644 index 00000000..4683b730 --- /dev/null +++ b/c64/basic/print/print_packed_dict_string.s @@ -0,0 +1,67 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +#if CONFIG_COMPRESSION_LVL_2 + +print_packed_error: // .X - error string index + + lda #packed_dict_errors + bne print_dict_packed_string // branch always + +print_packed_misc_str: // .X - misc string index + + lda #packed_dict_misc + + // FALLTROUGH + +print_dict_packed_string: + + // Search for the packed string on the list + + jsr print_packed_search + + ldy #$00 +!: + // At this point FRESPC contains a pointer to the string to display + // Fetch a byte-code + + lda (FRESPC), y + beq print_dict_packed_string_end // branch if everything displayed + tax + dex + + // Call 'print_freq_packed_string' - but preserve all the data needed to progress further + + phy_trash_a + lda FRESPC+0 + pha + lda FRESPC+1 + pha + + lda #packed_dictionary + + jsr print_freq_packed_string + + pla + sta FRESPC+1 + pla + sta FRESPC+0 + ply_trash_a + + // Next iteration + + iny + bne !- // branch always + +print_dict_packed_string_end: + + rts + + +#endif diff --git a/c64/basic/print/print_packed_string.s b/c64/basic/print/print_packed_freq_string.s similarity index 77% rename from c64/basic/print/print_packed_string.s rename to c64/basic/print/print_packed_freq_string.s index 84b6f3d7..a936a675 100644 --- a/c64/basic/print/print_packed_string.s +++ b/c64/basic/print/print_packed_freq_string.s @@ -23,69 +23,46 @@ print_packed_misc_str: #else +#if !CONFIG_COMPRESSION_LVL_2 + print_packed_error: // .X - error string index - lda #packed_str_errors + lda #packed_freq_errors bne print_freq_packed_string // branch always print_packed_misc_str: // .X - misc string index - lda #packed_str_misc + lda #packed_freq_misc bne print_freq_packed_string // branch always +#endif + print_packed_keyword_CC: // .X - token number - lda #packed_str_keywords_CC + lda #packed_freq_keywords_CC bne print_freq_packed_string // branch always print_packed_keyword_CD: // .X - token number - lda #packed_str_keywords_CD + lda #packed_freq_keywords_CD bne print_freq_packed_string // branch always print_packed_keyword_V2: // .X - token number - lda #packed_str_keywords_V2 + lda #packed_freq_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 + // Search for the packed string on the 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: + jsr print_packed_search // At this point FRESPC contains a pointer to the string to display // and we should start from the lower nibble diff --git a/c64/basic/print/print_packed_search.s b/c64/basic/print/print_packed_search.s new file mode 100644 index 00000000..f536eb2e --- /dev/null +++ b/c64/basic/print/print_packed_search.s @@ -0,0 +1,40 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + +print_packed_search: + + // 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_packed_done // 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_packed_done: + + rts diff --git a/c64/basic/tokenizer/tokenise_line.s b/c64/basic/tokenizer/tokenise_line.s index fc817293..dc52f9de 100644 --- a/c64/basic/tokenizer/tokenise_line.s +++ b/c64/basic/tokenizer/tokenise_line.s @@ -72,9 +72,9 @@ tokenise_line_loop: // Check for BASIC V2 tokens - lda #packed_str_keywords_V2 + lda #>packed_freq_keywords_V2 sta FRESPC+1 jsr tk_search @@ -82,17 +82,17 @@ tokenise_line_loop: // Check for extended tokens - lda #packed_str_keywords_CC + lda #>packed_freq_keywords_CC sta FRESPC+1 jsr tk_search bcc tokenise_line_keyword_CC // branch if keyword identified - lda #packed_str_keywords_CD + lda #>packed_freq_keywords_CD sta FRESPC+1 jsr tk_search diff --git a/tools/generate_strings.cc b/tools/generate_strings.cc index 9a97792f..c8e547b1 100644 --- a/tools/generate_strings.cc +++ b/tools/generate_strings.cc @@ -1279,16 +1279,19 @@ void DataSet::prepareOutput() const auto &stringEntryList = stringEntryLists[idxList]; const auto &stringEncodedList = stringEncodedLists[idxList]; - stream << std::endl; - for (uint8_t idxString = 0; idxString < stringEncodedList.size(); idxString++) + if (stringEntryList.type != ListType::DICTIONARY) { - const auto &stringEntry = stringEntryList.list[idxString]; - const auto &stringEncoded = stringEncodedList[idxString]; - - if (!stringEncoded.empty()) + stream << std::endl; + for (uint8_t idxString = 0; idxString < stringEncodedList.size(); idxString++) { - stream << ".label IDX__" << stringEntry.alias << std::string(maxAliasLen - stringEntry.alias.length(), ' ') << - " = $" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << +idxString << std::endl; + const auto &stringEntry = stringEntryList.list[idxString]; + const auto &stringEncoded = stringEncodedList[idxString]; + + if (!stringEncoded.empty()) + { + stream << ".label IDX__" << stringEntry.alias << std::string(maxAliasLen - stringEntry.alias.length(), ' ') << + " = $" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << +idxString << std::endl; + } } } @@ -1302,11 +1305,11 @@ void DataSet::prepareOutput() if (isCompressionLvl2(stringEntryList)) { - stream << std::endl << ".macro put_dict_packed_"; + stream << std::endl << ".macro put_packed_dict_"; } else { - stream << std::endl << ".macro put_freq_packed_"; + stream << std::endl << ".macro put_packed_freq_"; } stream << stringEntryList.name << "()" << std::endl << "{" << std::endl; @@ -1314,20 +1317,24 @@ void DataSet::prepareOutput() enum LastStr { NONE, SKIPPED, WRITTEN } lastStr = LastStr::NONE; for (uint8_t idxString = 0; idxString < stringEncodedList.size(); idxString++) { - const auto &stringEntry = stringEntryList.list[idxString]; const auto &stringEncoded = stringEncodedList[idxString]; if (stringEncoded.empty()) { + if (stringEntryList.type == ListType::DICTIONARY) ERROR("internal error"); // should never happen + if (lastStr == LastStr::WRITTEN) stream << std::endl; - stream << "\t.byte $00 // skipped " << stringEntry.alias << std::endl; + stream << "\t.byte $00 // skipped " << stringEntryList.list[idxString].alias << std::endl; lastStr = LastStr::SKIPPED; } else { if (lastStr != LastStr::NONE) stream << std::endl; - stream << "\t// IDX__" << stringEntry.alias << std::endl; + if (stringEntryList.type != ListType::DICTIONARY) + { + stream << "\t// IDX__" << stringEntryList.list[idxString].alias << std::endl; + } stream << "\t.byte "; bool first = true;