From 02f532e2ec083a9fe2bcf3bd277a7b20ef598ee6 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 12 Jul 2020 06:13:04 +0200 Subject: [PATCH] added test command to display memory information --- doc/Extended-BASIC.md | 61 +++++++----- .../basic_commands_CC/cmd__jumptable_CC.s | 3 +- src/basic/basic_commands_CC/cmd_mem.s | 98 +++++++++++++++++++ .../basic_commands_CC/helper_mem_tab_str.s | 17 ++++ .../basic_commands_CC/helper_mem_tab_x.s | 17 ++++ .../basic_commands_CC/helper_mem_tab_y.s | 17 ++++ .../board_m65/4000.mega65_vectable_basic_1.s | 2 + src/basic/board_m65/mega65_imports.s | 3 +- src/basic/engine/do_error.s | 22 +++++ tools/generate_strings.cc | 21 ++-- 10 files changed, 227 insertions(+), 34 deletions(-) create mode 100644 src/basic/basic_commands_CC/cmd_mem.s create mode 100644 src/basic/basic_commands_CC/helper_mem_tab_str.s create mode 100644 src/basic/basic_commands_CC/helper_mem_tab_x.s create mode 100644 src/basic/basic_commands_CC/helper_mem_tab_y.s diff --git a/doc/Extended-BASIC.md b/doc/Extended-BASIC.md index 020c007f..29f27e61 100644 --- a/doc/Extended-BASIC.md +++ b/doc/Extended-BASIC.md @@ -39,31 +39,7 @@ Like above, but merges a BASIC program to the one already stored in memory. Launches a built-in tape head alignment tool. Destroys program in memory. Press `RUN/STOP` to terminate the tool. -## Additional BASIC commands - -### `COLD` - -Resets the machine. In direct mode asks for confirmation first. - -### `FAST` - -Tries to switch the machine to turbo mode - details differ depending on the configured machine / motherboard. - -### `SLOW` - -Tries to switch the machine back to 1 MHz operation mode. - -### `OLD` - -Tries to restore program destroyed by `NEW` or a reset. - -### `CLEAR` - -Clears the screen content. - -### `DISPOSE` - -Runs the garbage collector - disposes outdated strings. +## Additional BASIC commands - I/O ### `MERGE "file_name" [, device_number]` @@ -81,6 +57,41 @@ Verify operation for the binary data starting from a given addres. NOTE: for now Saves the binary data from the given memory area. NOTE: for now syntax differs from the BASIC V3.5+ - this will be changed once the necessary BASIC infrastructure is implemented. +## Additional BASIC commands - misc + +### `COLD` + +Resets the machine. In direct mode asks for confirmation first. + +### `FAST` + +Tries to switch the machine to turbo mode - details differ depending on the configured machine / motherboard. + +### `SLOW` + +Tries to switch the machine back to 1 MHz operation mode. + +### `OLD` + +Tries to restore program destroyed by the `NEW` command or a reset. + +### `MEM` + +Displays BASIC memory usage information: +* `TXT` - size of BASIC program text, always at least 2 bytes are used +* `VAR` - bytes occupied by float and integer variables, string variable descriptors, and function descriptors +* `ARR` - bytes occupied by arrays (note: for string arrays only descriptors are stored here) +* `STR` - bytes occupied by strings, also the ones belonging to arrays +* `SPC` - unused space + +### `CLEAR` + +Clears the screen content. + +### `DISPOSE` + +Runs the garbage collector - disposes outdated strings. + # Planned BASIC features, when V2 compatibility is reached Ideas for the future, most of them suitable for Mega65 or other power machines only diff --git a/src/basic/basic_commands_CC/cmd__jumptable_CC.s b/src/basic/basic_commands_CC/cmd__jumptable_CC.s index 6df67cdc..68245e36 100644 --- a/src/basic/basic_commands_CC/cmd__jumptable_CC.s +++ b/src/basic/basic_commands_CC/cmd__jumptable_CC.s @@ -19,7 +19,8 @@ cmd_cold, cmd_clear, - varstr_garbage_collect // cmd_dispose + varstr_garbage_collect, // cmd_dispose + cmd_mem ) diff --git a/src/basic/basic_commands_CC/cmd_mem.s b/src/basic/basic_commands_CC/cmd_mem.s new file mode 100644 index 00000000..1a1fe5be --- /dev/null +++ b/src/basic/basic_commands_CC/cmd_mem.s @@ -0,0 +1,98 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 * #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + + + +#if (!ROM_LAYOUT_M65 || SEGMENT_BASIC_0) + +cmd_mem: + + // First perform the garbage collection - to be able to determine real values + + jsr varstr_garbage_collect + +#endif // ROM layout + +#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_0) + + jsr map_BASIC_1 + jsr_ind VB1__cmd_mem_cont + jmp map_NORMAL + +#else + +#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_1) + +cmd_mem_cont: + +#endif + + // Print all the information, in a loop, in reverse order + + ldy #$04 +!: + // First print the information string + + ldx helper_mem_tab_str, y + phy_trash_a + jsr print_packed_misc_str + + // Fetch addresses of zeropage variables + +#if HAS_OPCODES_65C02 + ply + phy +#else + pla + pha + tay +#endif + + ldx helper_mem_tab_x, y + lda helper_mem_tab_y, y + tay + + // Print difference between two zeropage variables + + sec + lda $00, x + sbc $0000, y + pha + inx + iny + lda $00, x + sbc $0000, y + +#if HAS_OPCODES_65C02 + plx +#else + tay + pla + tax + tya +#endif + + // Before printing, make sure the result is not negative + + bcc cmd_mem_error + jsr print_integer + + // Check if more iterations needed + + ply_trash_a + dey + bpl !- + + // Finish + + jmp print_return + + +cmd_mem_error: + + jsr print_return + jmp do_MEMORY_CORRUPT_error + +#endif // ROM layout diff --git a/src/basic/basic_commands_CC/helper_mem_tab_str.s b/src/basic/basic_commands_CC/helper_mem_tab_str.s new file mode 100644 index 00000000..816add66 --- /dev/null +++ b/src/basic/basic_commands_CC/helper_mem_tab_str.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Helper table for 'MEM' command - list of strings to print +// + + +helper_mem_tab_str: + + .byte IDX__STR_MEM_FREE + .byte IDX__STR_MEM_STRS + .byte IDX__STR_MEM_ARRS + .byte IDX__STR_MEM_VARS + .byte IDX__STR_MEM_TEXT diff --git a/src/basic/basic_commands_CC/helper_mem_tab_x.s b/src/basic/basic_commands_CC/helper_mem_tab_x.s new file mode 100644 index 00000000..2df7e5f9 --- /dev/null +++ b/src/basic/basic_commands_CC/helper_mem_tab_x.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Helper table for 'MEM' command - list of minuend zeropage variables +// + + +helper_mem_tab_x: + + .byte FRETOP + .byte MEMSIZ + .byte STREND + .byte ARYTAB + .byte VARTAB diff --git a/src/basic/basic_commands_CC/helper_mem_tab_y.s b/src/basic/basic_commands_CC/helper_mem_tab_y.s new file mode 100644 index 00000000..74861e4a --- /dev/null +++ b/src/basic/basic_commands_CC/helper_mem_tab_y.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE +// #LAYOUT# X16 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Helper table for 'MEM' command - list of subtrahend zeropage variables +// + + +helper_mem_tab_y: + + .byte STREND + .byte FRETOP + .byte ARYTAB + .byte VARTAB + .byte TXTTAB diff --git a/src/basic/board_m65/4000.mega65_vectable_basic_1.s b/src/basic/board_m65/4000.mega65_vectable_basic_1.s index d83bbfdd..2f116b08 100644 --- a/src/basic/board_m65/4000.mega65_vectable_basic_1.s +++ b/src/basic/board_m65/4000.mega65_vectable_basic_1.s @@ -20,6 +20,7 @@ .label VB1__do_new = $4000 + 2 * 6 .label VB1__do_clr = $4000 + 2 * 7 .label VB1__do_restore = $4000 + 2 * 8 + .label VB1__cmd_mem_cont = $4000 + 2 * 9 #else @@ -34,5 +35,6 @@ .word do_new .word do_clr .word do_restore + .word cmd_mem_cont #endif diff --git a/src/basic/board_m65/mega65_imports.s b/src/basic/board_m65/mega65_imports.s index 210dac22..ac3d8582 100644 --- a/src/basic/board_m65/mega65_imports.s +++ b/src/basic/board_m65/mega65_imports.s @@ -22,5 +22,6 @@ #if CONFIG_SHOW_FEATURES .label print_features = BASIC_0.proxy_B1_print_features #endif -.label do_STRING_TOO_LONG_error = BASIC_0.do_STRING_TOO_LONG_error +.label do_error_fetch = BASIC_0.do_error_fetch +.label do_basic_error = BASIC_0.do_basic_error .label str_rev_question = BASIC_0.str_rev_question diff --git a/src/basic/engine/do_error.s b/src/basic/engine/do_error.s index e4979e86..c8d51e0a 100644 --- a/src/basic/engine/do_error.s +++ b/src/basic/engine/do_error.s @@ -1,4 +1,5 @@ // #LAYOUT# STD * #TAKE +// #LAYOUT# M65 BASIC_1 #TAKE // #LAYOUT# * BASIC_0 #TAKE // #LAYOUT# * * #IGNORE @@ -43,7 +44,11 @@ do_kernal_error: // .A = KERNAL error code, also almost ma beq do_BREAK_error // XXX is 0 really a proper error code? dex +#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_1) + jmp do_basic_error +#else bpl do_basic_error // branch always +#endif // Error messages specific to OpenROMs BASIC dialect @@ -138,6 +143,16 @@ do_FILE_OPEN_error: do_TO_MANY_FILES_error: .byte $EA +#if (ROM_LAYOUT_M65 && SEGMENT_BASIC_1) + + jmp do_error_fetch + +#else + + // FALLTROUGH + +do_error_fetch: + // Now get the error id and restore $E6 to its correct value lda $E6 @@ -162,6 +177,11 @@ do_TO_MANY_FILES_error: do_basic_error: // error code in .X +#if ROM_LAYOUT_M65 + // Make sure we are back with normal memory map + jsr map_NORMAL +#endif + // "?" phx_trash_a @@ -197,3 +217,5 @@ do_basic_error: // error code in .X txs jmp shell_main_loop + +#endif // ROM layout diff --git a/tools/generate_strings.cc b/tools/generate_strings.cc index dc308b79..62075488 100644 --- a/tools/generate_strings.cc +++ b/tools/generate_strings.cc @@ -186,6 +186,7 @@ const StringEntryList GLOBAL_Keywords_CC = { ListType::KEYWORDS, "keywords_CC", { true, true, true, true, "KCC_06", "COLD", }, // Not present in CBM BASIC dialects, but common to some extensions (*) { true, true, true, true, "KCC_07", "CLEAR", }, // Not present in CBM BASIC dialects, OpenROMs specific { true, true, true, true, "KCC_08", "DISPOSE", }, // Not present in CBM BASIC dialects, OpenROMs specific + { true, true, true, true, "KCC_09", "MEM", }, // Not present in CBM BASIC dialects, OpenROMs specific // (*) see https://sourceforge.net/p/vice-emu/code/HEAD/tree/trunk/vice/src/petcat.c } }; @@ -310,14 +311,20 @@ const StringEntryList GLOBAL_Errors = { ListType::STRINGS_BASIC, "errors", const StringEntryList GLOBAL_MiscStrings = { ListType::STRINGS_BASIC, "misc", { // STD M65 U64 X16 --- misc strings as on CBM machines - { true, true, true, true, "STR_RET_QM", "\r?" }, - { true, true, true, true, "STR_BYTES", " BASIC BYTES FREE" }, // https://github.com/stefanhaustein/expressionparser - { true, true, true, true, "STR_READY", "\rREADY.\r" }, // https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zconcepts/zconc_whatistsonative.htm https://github.com/stefanhaustein/expressionparser - { true, true, true, true, "STR_ERROR", " ERROR" }, // simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html - { true, true, true, true, "STR_IN", " IN " }, - { true, true, true, true, "STR_IF_SURE", "\rARE YOU SURE? " }, // https://docs.microsoft.com/en-us/windows/win32/uxguide/mess-confirm + { true, true, true, true, "STR_RET_QM", "\r?" }, + { true, true, true, true, "STR_BYTES", " BASIC BYTES FREE" }, // https://github.com/stefanhaustein/expressionparser + { true, true, true, true, "STR_READY", "\rREADY.\r" }, // https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zconcepts/zconc_whatistsonative.htm https://github.com/stefanhaustein/expressionparser + { true, true, true, true, "STR_ERROR", " ERROR" }, // simply the word error that is attached to the other parts of messages https://fjkraan.home.xs4all.nl/comp/apple2faq/app2asoftfaq.html + { true, true, true, true, "STR_IN", " IN " }, + { true, true, true, true, "STR_IF_SURE", "\rARE YOU SURE? " }, // https://docs.microsoft.com/en-us/windows/win32/uxguide/mess-confirm // STD M65 U64 X16 --- misc strings specific to OpenROMs, not present in CBM ROMs - { true, true, true, true, "STR_BRK_AT", "\rBRK AT $" }, + { true, true, true, true, "STR_BRK_AT", "\rBRK AT $" }, + { true, true, true, true, "STR_MEM_TEXT", "\rTXT: " }, + { true, true, true, true, "STR_MEM_VARS", "\rVAR: " }, + { true, true, true, true, "STR_MEM_ARRS", "\rARR: " }, + { true, true, true, true, "STR_MEM_STRS", "\rSTR: " }, + { true, true, true, true, "STR_MEM_FREE", "\r\rSPC: " }, + // Note: depending on configuration, additional strings will be added here } };