Boot from a disk image when initially invoked with it

This commit is contained in:
David Schmidt 2012-02-28 06:16:34 +00:00
parent 4a092e181b
commit 1a92935d20
7 changed files with 101 additions and 17 deletions

View File

@ -1,6 +1,6 @@
/*
GSport - an Apple //gs Emulator
Copyright (C) 2010 by GSport contributors
Copyright (C) 2010 - 2012 by GSport contributors
Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey
@ -48,6 +48,8 @@ extern int g_c034_val;
byte g_bram[2][256];
byte *g_bram_ptr = &(g_bram[0][0]);
byte g_temp_boot_slot = 254;
byte g_orig_boot_slot = 0;
word32 g_clk_cur_time = 0xa0000000;
int g_clk_next_vbl_update = 0;
@ -165,6 +167,36 @@ clk_write_bram(FILE *fconf)
}
}
void
clk_calculate_bram_checksum(void) {
int checksum = 0;
int i;
if (g_bram_ptr[251] == 0xff) {
// Only make the checksum valid if we have non-zeron data!
// Otherwise you have very valid zeroes, which confuses the GS firmware mightily.
for (i = 250; i >= 0; i--) {
checksum = (checksum & 0xFFFF) << 1;
checksum = (checksum & 0xFFFF)
+ g_bram_ptr[i]
+ ((int)g_bram_ptr[i + 1] << 8)
+ (checksum >> 16);
}
checksum &= 0xFFFF;
checksum += ((checksum ^ 0xAAAA) << 16);
#ifdef GSPORT_LITTLE_ENDIAN
g_bram_ptr[252] = (checksum & 0xFF);
g_bram_ptr[253] = (checksum >> 8);
g_bram_ptr[254] = (checksum >> 16);
g_bram_ptr[255] = (checksum >> 24);
#else
g_bram_ptr[255] = (checksum & 0xFF);
g_bram_ptr[254] = (checksum >> 8);
g_bram_ptr[253] = (checksum >> 16);
g_bram_ptr[252] = (checksum >> 24);
#endif
}
}
void
update_cur_time()
{
@ -325,7 +357,13 @@ do_clock_data()
if(read) {
if(g_clk_read) {
/* Yup, read */
g_c033_data = g_bram_ptr[g_clk_reg1];
if ((g_clk_reg1 == 0x28) && (g_temp_boot_slot != 254)){
// Modify boot slot
g_c033_data = g_temp_boot_slot;
clk_calculate_bram_checksum();
} else {
g_c033_data = g_bram_ptr[g_clk_reg1];
}
clk_printf("Reading BRAM loc %02x: %02x\n",
g_clk_reg1, g_c033_data);
} else {
@ -336,9 +374,15 @@ do_clock_data()
halt_printf("CLK_BRAM1: said rd, now write\n");
} else {
/* Yup, write */
if ((g_clk_reg1 == 0x28) && (g_temp_boot_slot != 254)) {
// Modify boot slot
g_bram_ptr[g_clk_reg1] = g_temp_boot_slot;
clk_calculate_bram_checksum();
} else {
g_bram_ptr[g_clk_reg1] = g_c033_data;
}
clk_printf("Writing BRAM loc %02x with %02x\n",
g_clk_reg1, g_c033_data);
g_bram_ptr[g_clk_reg1] = g_c033_data;
g_config_gsport_update_needed = 1;
}
}

View File

@ -96,6 +96,10 @@ extern word32 g_full_refresh_needed;
extern word32 g_a2_screen_buffer_changed;
extern int g_a2_new_all_stat[];
extern int g_new_a2_stat_cur_line;
extern byte g_bram[2][256];
extern byte* g_bram_ptr;
extern byte g_temp_boot_slot;
extern byte g_orig_boot_slot;
extern int g_key_down;
extern const char g_gsport_version_str[];
@ -2669,18 +2673,19 @@ cfg_file_readdir(const char *pathptr)
}
void
cfg_inspect_maybe_insert_file(char *filename)
cfg_inspect_maybe_insert_file(char *filename, int should_boot)
{
/*
Take a look at a file. Based on its size, guess a slot/drive to insert it into.
Used for blind operations like dragging/dropping files.
Used for blind operations like dragging/dropping files.
Optionally boot from that slot.
*/
int rc = 0;
int slot = 0;
rc = cfg_guess_image_size(filename);
switch (rc)
{
case 0: slot = 5; break;
case 0: slot = 7; break;
case 1: slot = 6; break;
case 2: slot = 5; break;
case 3: slot = 7; break;
@ -2689,7 +2694,11 @@ Used for blind operations like dragging/dropping files.
if (slot > 0)
{
insert_disk(slot,0,filename,0,0,0,-1);
printf("Inserted disk in slot %d, drive 1. Filename: %s\n",slot,filename);
printf("Inserted disk in slot %d, drive 1. Filename: %s\n", slot, filename);
if (should_boot) {
g_temp_boot_slot = slot;
printf("That slot has been set to boot.\n");
}
}
else
printf("Unable to determine appropriate place to insert file %s.\n",filename);
@ -3296,8 +3305,6 @@ config_control_panel()
g_a2_screen_buffer_changed = -1;
}
extern byte g_bram[2][256];
extern byte* g_bram_ptr;
void x_clk_setup_bram_version()
{
if(g_rom_version < 3) {

View File

@ -1,6 +1,6 @@
/*
GSport - an Apple //gs Emulator
Copyright (C) 2010 by GSport contributors
Copyright (C) 2010 - 2012 by GSport contributors
Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey
@ -334,6 +334,11 @@ iwm_flush_disk_to_unix(Disk *dsk)
/* Check for dirty disk 3 times a second */
extern byte g_bram[2][256];
extern byte* g_bram_ptr;
extern byte g_temp_boot_slot;
extern byte g_orig_boot_slot;
extern int g_config_gsport_update_needed;
void
iwm_vbl_update(int doit_3_persec)
{
@ -347,6 +352,13 @@ iwm_vbl_update(int doit_3_persec)
g_vbl_count);
iwm.motor_on = 0;
iwm.motor_off = 0;
if (g_temp_boot_slot != 254) {
// Drive is off, now's a good time to turn off the temp boot slot if it was on.
g_temp_boot_slot = 254;
g_bram_ptr[40] = g_orig_boot_slot;
clk_calculate_bram_checksum();
g_config_gsport_update_needed = 1;
}
}
}
@ -357,6 +369,14 @@ iwm_vbl_update(int doit_3_persec)
motor_on = iwm.motor_on;
if(g_c031_disk35 & 0x40) {
motor_on = iwm.motor_on35;
if (g_temp_boot_slot != 254) {
// Now's a good time to turn off the temp boot slot if it was on.
g_temp_boot_slot = 254;
g_bram_ptr[40] = g_orig_boot_slot;
clk_calculate_bram_checksum();
g_config_gsport_update_needed = 1;
}
}
if(motor_on == 0 || iwm.motor_off) {

View File

@ -1,6 +1,6 @@
/*
GSport - an Apple //gs Emulator
Copyright (C) 2010 by GSport contributors
Copyright (C) 2010 - 2012 by GSport contributors
Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey
@ -139,6 +139,7 @@ double get_dtime(void);
int micro_sleep(double dtime);
void clk_bram_zero(void);
void clk_bram_set(int bram_num, int offset, int val);
void clk_calculate_bram_checksum(void);
void clk_setup_bram_version(void);
void clk_write_bram(FILE *fconf);
void update_cur_time(void);
@ -158,7 +159,7 @@ void cfg_exit(void);
void cfg_toggle_config_panel(void);
void cfg_text_screen_dump(void);
void cfg_get_tfe_name(void);
void cfg_inspect_maybe_insert_file(char *filename);
void cfg_inspect_maybe_insert_file(char *filename, int should_boot);
int cfg_guess_image_size(char *filename);
void config_vbl_update(int doit_3_persec);
void config_parse_option(char *buf, int pos, int len, int line);

View File

@ -1060,7 +1060,8 @@ gsportmain(int argc, char **argv)
config_init();
// If the final argument was not a switch, then treat it like a disk image filename to insert
if (final_arg) {
cfg_inspect_maybe_insert_file(final_arg);
// ...and flag it to boot
cfg_inspect_maybe_insert_file(final_arg, 1);
}
printer_init(g_printer_dpi,85,110,g_printer_output,g_printer_multipage);
//If ethernet is enabled in config.gsport, let's initialize it

View File

@ -1,6 +1,6 @@
/*
GSport - an Apple //gs Emulator
Copyright (C) 2010 by GSport contributors
Copyright (C) 2010 - 2012 by GSport contributors
Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey
@ -757,11 +757,22 @@ do_format_c7(int unit_num)
}
extern byte g_bram[2][256];
extern byte* g_bram_ptr;
extern byte g_temp_boot_slot;
extern byte g_orig_boot_slot;
extern int g_config_gsport_update_needed;
void
do_c700(word32 ret)
{
disk_printf("do_c700 called, ret: %08x\n", ret);
if (g_temp_boot_slot != 254) {
// Booting from slot 7 - now is a good time to turn off the temp boot slot, if it was on.
g_temp_boot_slot = 254;
g_bram_ptr[40] = g_orig_boot_slot;
clk_calculate_bram_checksum();
g_config_gsport_update_needed = 1;
}
ret = do_read_c7(0, 0x800, 0);
set_memory_c(0x7f8, 7, 0);

View File

@ -1,6 +1,6 @@
/*
GSport - an Apple //gs Emulator
Copyright (C) 2010 by GSport contributors
Copyright (C) 2010 - 2012 by GSport contributors
Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey
@ -473,7 +473,7 @@ LPTSTR lpszFile;
szFilename = DragQueryFile((HDROP)wParam, i, NULL, 0);
lpszFile = (LPTSTR)malloc(szFilename + 1);
szFilename = DragQueryFile((HDROP)wParam, i, lpszFile, szFilename + 1);
cfg_inspect_maybe_insert_file(lpszFile);
cfg_inspect_maybe_insert_file(lpszFile, 0);
free(lpszFile);
}
DragFinish((HDROP)wParam);