diff --git a/targets/mega65/configdb.c b/targets/mega65/configdb.c index 5f92852f..798adcd1 100644 --- a/targets/mega65/configdb.c +++ b/targets/mega65/configdb.c @@ -74,6 +74,7 @@ static const struct xemutools_configdef_str_st str_options[] = { { "keymap", KEYMAP_USER_FILENAME, "Set keymap configuration file to be used", &configdb.keymap }, #endif { "gui", NULL, "Select GUI type for usage. Specify some insane str to get a list", &configdb.selectedgui }, + { "importbas", NULL, "Import and RUN BASIC65 program from TEXT file", &configdb.importbas }, { NULL } }; @@ -143,7 +144,7 @@ static const struct xemutools_configdef_float_st float_options[] = { // etc), however if the user saves the config in Xemu when started this way, it would also save these // CLI-given options, which is not the thing he wants, 99.999999% of time, I guess ... -static const void *do_not_save_opts[] = { &configdb.prg, &configdb.autoload, &configdb.go64, &configdb.hyperserialfile, NULL }; +static const void *do_not_save_opts[] = { &configdb.prg, &configdb.autoload, &configdb.go64, &configdb.hyperserialfile, &configdb.importbas, NULL }; void configdb_define_emulator_options ( size_t size ) diff --git a/targets/mega65/configdb.h b/targets/mega65/configdb.h index 7932ad4c..ed0d58f1 100644 --- a/targets/mega65/configdb.h +++ b/targets/mega65/configdb.h @@ -49,6 +49,7 @@ struct configdb_st { int defd81fromsd; int testing; char *prg; + char *importbas; char *sdimg; char *dumpmem; char *dumpscreen; diff --git a/targets/mega65/inject.c b/targets/mega65/inject.c index 32c4e20b..d9c43dd0 100644 --- a/targets/mega65/inject.c +++ b/targets/mega65/inject.c @@ -25,12 +25,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "xemu/f011_core.h" #include "input_devices.h" #include "hypervisor.h" +#include "sdcard.h" +#include "configdb.h" #define C64_BASIC_LOAD_ADDR 0x0801 #define C65_BASIC_LOAD_ADDR 0x2001 #define KEY_PRESS_TIMEOUT 6 +#define IMPORT_BAS_TEXT_TEMPFILE "@lastimporttext.bas" + static int check_status = 0; static int key2release = -1; static int key2release_timeout; @@ -159,6 +163,26 @@ static void prg_inject_callback ( void *unused ) } +static void import_callback2 ( void *unused ) +{ + CBM_SCREEN_PRINTF(under_ready_p, " SCNCLR:RUN:"); + if (configdb.disk9) + sdcard_external_mount(1, configdb.disk9, NULL); + press_key(1); +} + + +static void import_callback ( void *unused ) +{ + DEBUGPRINT("INJECT: hit 'READY.' trigger, about to import BASIC65 text program." NL); + fdc_allow_disk_access(FDC_ALLOW_DISK_ACCESS); // re-allow disk access + sdcard_external_mount(1, IMPORT_BAS_TEXT_TEMPFILE, "Mount failure for BASIC65 import"); + CBM_SCREEN_PRINTF(under_ready_p, " IMPORT\"FILESEQ\",U9:"); + press_key(1); + inject_register_ready_status("BASIC65 text import2", import_callback2, NULL); +} + + static void command_callback ( void *unused ) { if (!prg.cmd_p) @@ -327,3 +351,38 @@ void inject_ready_check_do ( void ) } else check_status++; // we're "let's wait some time after READY." phase } + + +static int basic_text_conv ( char *dst, const char *src, int len ) +{ + // TODO: currently it's only a copy!!!! + memcpy(dst, src, len); + dst[len] = 0; + return 0; +} + + +int inject_register_import_basic_text ( const char *fn ) +{ + if (!fn || !*fn) + return 0; + const int len = xemu_load_file(fn, NULL, 1, 65535, "Could not open/load text import for BASIC65"); + if (len < 1) + return -1; + char *buf = xemu_malloc(len + 1); + if (basic_text_conv(buf, xemu_load_buffer_p, len)) { + free(buf); + free(xemu_load_buffer_p); + return -1; + } + free(xemu_load_buffer_p); + if (xemu_save_file(IMPORT_BAS_TEXT_TEMPFILE, buf, len, "Could not save prepared text for BASIC65 import") < 0) { + free(buf); + return -1; + } + free(buf); + if (inject_register_ready_status("BASIC65 text import", import_callback, NULL)) // prg inject does not use the userdata ... + return -1; + fdc_allow_disk_access(FDC_DENY_DISK_ACCESS); // deny now, to avoid problem on PRG load while autoboot disk is mounted + return 0; +} diff --git a/targets/mega65/inject.h b/targets/mega65/inject.h index f032ab15..448f52d8 100644 --- a/targets/mega65/inject.h +++ b/targets/mega65/inject.h @@ -25,5 +25,6 @@ extern int inject_register_ready_status ( const char *debug_msg, void (*callbac extern int inject_register_prg ( const char *prg_file, int prg_mode ); extern void inject_register_allow_disk_access ( void ); extern void inject_register_command ( const char *s ); +extern int inject_register_import_basic_text ( const char *fn ); #endif diff --git a/targets/mega65/mega65.c b/targets/mega65/mega65.c index 1587be3a..5556535d 100644 --- a/targets/mega65/mega65.c +++ b/targets/mega65/mega65.c @@ -844,6 +844,8 @@ int main ( int argc, char **argv ) "run\"*\"" // for C65/MEGA65 mode, we have nice command for that functionality ... ); } + if (!configdb.prg && !configdb.go64 && !configdb.autoload && configdb.importbas) + inject_register_import_basic_text(configdb.importbas); rom_stubrom_requested = configdb.usestubrom; rom_initrom_requested = configdb.useinitrom; rom_from_prefdir_allowed = !configdb.romfromsd;