Skip to content

Commit

Permalink
MEGA65: prelim. support for BASIC text IMPORT #352
Browse files Browse the repository at this point in the history
This uses the BASIC65 ROM's command IMPORT. Xemu just fakes the given
file as a disk image, so BASIC65 ROM can load the SEQ file.

Crude, and preliminary support! Only works if the file is "well
formatted"!
  • Loading branch information
lgblgblgb committed Jul 24, 2023
1 parent 4062b91 commit 0f81b61
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion targets/mega65/configdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

Expand Down Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions targets/mega65/configdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct configdb_st {
int defd81fromsd;
int testing;
char *prg;
char *importbas;
char *sdimg;
char *dumpmem;
char *dumpscreen;
Expand Down
59 changes: 59 additions & 0 deletions targets/mega65/inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions targets/mega65/inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions targets/mega65/mega65.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0f81b61

Please sign in to comment.