diff --git a/file_io.h b/file_io.h
index 6020fd2..3949f99 100644
--- a/file_io.h
+++ b/file_io.h
@@ -29,7 +29,8 @@ extern int iFirstEntry;
#define SCAN_SET_ITEM 3 // find exact item
// options flags
-#define SCAN_DIR 1 // include subdirectories
+#define SCAN_DIR 1 // include subdirectories
+#define SCAN_UMOUNT 2 // include subdirectories
void FindStorage();
int getStorage(int from_setting);
diff --git a/main.c b/main.c
index d07ade9..f63020c 100644
--- a/main.c
+++ b/main.c
@@ -87,7 +87,6 @@ void core_init()
int main(int argc, char *argv[])
{
fpga_io_init();
- fpga_core_reset(1);
fpga_gpo_write(0);
DISKLED_OFF;
diff --git a/menu.c b/menu.c
index 18bec9a..421a42d 100644
--- a/menu.c
+++ b/menu.c
@@ -46,6 +46,7 @@ along with this program. If not, see .
#include
#include "mist_cfg.h"
#include "input.h"
+#include "x86.h"
/*menu states*/
enum MENU
@@ -269,7 +270,7 @@ static void SelectFile(char* pFileExt, unsigned char Options, unsigned char Menu
iprintf("%s - %s\n", pFileExt, fs_pFileExt);
AdjustDirectory(SelectedPath);
- if (strncmp(pFileExt, fs_pFileExt, 12) != 0) // check desired file extension
+ if (strncmp(pFileExt, fs_pFileExt, 12) != 0 || !strlen(SelectedPath)) // check desired file extension
{ // if different from the current one go to the root directory and init entry buffer
SelectedPath[0] = 0;
@@ -808,7 +809,11 @@ void HandleUI(void)
}
// check for 'O'ption strings
- if (p && (p[0] == 'O')) {
+ if (p && (p[0] == 'O'))
+ {
+ //option handled by ARM
+ if (p[1] == 'X') p++;
+
unsigned long x = getStatus(p, status);
// get currently active option
@@ -945,15 +950,26 @@ void HandleUI(void)
static char ext[13];
substrcpy(ext, p, 1);
while (strlen(ext) < 3) strcat(ext, " ");
- SelectFile(ext, SCAN_DIR,
+ SelectFile(ext, SCAN_DIR | ((p[0] == 'S') ? SCAN_UMOUNT : 0),
(p[0] == 'F') ? MENU_8BIT_MAIN_FILE_SELECTED : MENU_8BIT_MAIN_IMAGE_SELECTED,
MENU_8BIT_MAIN1, 1);
}
else if (p[0] == 'O')
{
+ int byarm = 0;
+ if (p[1] == 'X')
+ {
+ byarm = 1;
+ p++;
+ }
+
unsigned long status = user_io_8bit_set_status(0, 0); // 0,0 gets status
unsigned long x = getStatus(p, status) + 1;
+ if (byarm && is_x86_core())
+ {
+ if (p[1] == '2') x86_set_fdd_boot(!(x&1));
+ }
// check if next value available
substrcpy(s, p, 2 + x);
if (!strlen(s)) x = 0;
@@ -966,12 +982,20 @@ void HandleUI(void)
{
// determine which status bit is affected
unsigned long mask = 1 << getIdx(p);
- unsigned long status = user_io_8bit_set_status(0, 0);
+ if (mask == 1 && is_x86_core())
+ {
+ x86_init();
+ menustate = MENU_NONE1;
+ }
+ else
+ {
+ unsigned long status = user_io_8bit_set_status(0, 0);
- user_io_8bit_set_status(status ^ mask, mask);
- user_io_8bit_set_status(status, mask);
+ user_io_8bit_set_status(status ^ mask, mask);
+ user_io_8bit_set_status(status, mask);
+ menustate = MENU_8BIT_MAIN1;
+ }
- menustate = MENU_8BIT_MAIN1;
}
}
}
@@ -990,9 +1014,16 @@ void HandleUI(void)
case MENU_8BIT_MAIN_IMAGE_SELECTED:
iprintf("Image selected: %s\n", SelectedPath);
- user_io_set_index(user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1));
- user_io_file_mount(drive_num, SelectedPath);
- menustate = MENU_NONE1;
+ if (is_x86_core())
+ {
+ x86_set_image(drive_num, SelectedPath);
+ }
+ else
+ {
+ user_io_set_index(user_io_ext_idx(SelectedPath, fs_pFileExt) << 6 | (menusub + 1));
+ user_io_file_mount(drive_num, SelectedPath);
+ }
+ menustate = SelectedPath[0] ? MENU_NONE1 : MENU_8BIT_MAIN1;
break;
case MENU_8BIT_SYSTEM1:
@@ -1069,6 +1100,7 @@ void HandleUI(void)
unsigned long status = user_io_8bit_set_status(0, 0);
iprintf("Saving config to %s\n", filename);
FileSaveConfig(filename, &status, 4);
+ if (is_x86_core()) x86_config_save();
menustate = MENU_8BIT_MAIN1;
menusub = 0;
}
@@ -1932,8 +1964,14 @@ void HandleUI(void)
if (c == KEY_BACKSPACE)
{
- changeDir("..");
- menustate = MENU_FILE_SELECT1;
+ if (fs_Options & SCAN_UMOUNT)
+ {
+ for (int i = 0; i < OsdGetSize() - 1; i++) OsdWrite(i, "", 0, 0);
+ OsdWrite(OsdGetSize() / 2, " Unmounting the image", 0, 0);
+ usleep(1500000);
+ SelectedPath[0] = 0;
+ menustate = fs_MenuSelect;
+ }
}
if ((c == KEY_PAGEUP) || (c == KEY_LEFT))
diff --git a/menu.h b/menu.h
index 0f2e36b..82ccf09 100644
--- a/menu.h
+++ b/menu.h
@@ -23,6 +23,8 @@ void ShowSplash();
void HideSplash();
void EjectAllFloppies();
+unsigned long getStatus(char *opt, unsigned long status);
+
void menu_key_set(uint32_t c);
void menu_mod_set(uint32_t m);
diff --git a/user_io.c b/user_io.c
index 70b76f3..7ec6518 100644
--- a/user_io.c
+++ b/user_io.c
@@ -180,12 +180,6 @@ static int joy_force = 0;
static void parse_config()
{
- // check if core has a config string
- core_type_8bit_with_config_string = (user_io_8bit_get_string(0) != NULL);
-
- // set core name. This currently only sets a name for the 8 bit cores
- user_io_read_core_name();
-
joy_force = 0;
if (core_type_8bit_with_config_string)
{
@@ -202,6 +196,19 @@ static void parse_config()
input_notify_mode();
set_kbd_led(HID_LED_NUM_LOCK, true);
}
+
+ if (p[0] == 'O' && p[1] == 'X')
+ {
+ unsigned long status = user_io_8bit_set_status(0, 0);
+ printf("found OX option: %s, 0x%08X\n", p, status);
+
+ unsigned long x = getStatus(p+1, status);
+
+ if (is_x86_core())
+ {
+ if (p[2] == '2') x86_set_fdd_boot(!(x&1));
+ }
+ }
}
i++;
} while (p);
@@ -266,8 +273,11 @@ void user_io_detect_core_type()
// forward SD card config to core in case it uses the local
// SD card implementation
user_io_sd_set_config();
+ // check if core has a config string
+ core_type_8bit_with_config_string = (user_io_8bit_get_string(0) != NULL);
- parse_config();
+ // set core name. This currently only sets a name for the 8 bit cores
+ user_io_read_core_name();
// send a reset
user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET);
@@ -283,6 +293,7 @@ void user_io_detect_core_type()
iprintf("Found config\n");
user_io_8bit_set_status(status, 0xffffffff);
}
+ parse_config();
// check for multipart rom
sprintf(mainpath, "%s/boot0.rom", user_io_get_core_name());
@@ -312,6 +323,7 @@ void user_io_detect_core_type()
if (is_x86_core())
{
+ x86_config_load();
x86_init();
}
else
diff --git a/x86.c b/x86.c
index 7b2f232..e3ba0ef 100644
--- a/x86.c
+++ b/x86.c
@@ -34,6 +34,7 @@
#include "spi.h"
#include "user_io.h"
#include "file_io.h"
+#include "fpga_io.h"
#define ALT_CPU_CPU_FREQ 90000000u
@@ -46,6 +47,17 @@
#define RTC_BASE 0x8c00
#define SD_BASE 0x0A00
+#define CFG_VER 1
+
+typedef struct
+{
+ uint32_t ver;
+ char fdd_name[1024];
+ char hdd_name[1024];
+} x86_config;
+
+static x86_config config;
+
static uint8_t dma_sdio(int status)
{
uint8_t res;
@@ -202,6 +214,7 @@ static bool floppy_is_2_88m= false;
static fileTYPE fdd_image = { 0 };
static fileTYPE hdd_image = { 0 };
+static bool boot_from_floppy = 1;
#define IMG_TYPE_FDD 0x800
#define IMG_TYPE_HDD 0x000
@@ -213,6 +226,8 @@ static __inline fileTYPE *get_image(uint32_t type)
static int img_mount(uint32_t type, char *name)
{
+ FileClose(get_image(type));
+
int writable = FileCanWrite(name);
int ret = FileOpenEx(get_image(type), name, writable ? (O_RDWR | O_SYNC) : O_RDONLY);
if (!ret)
@@ -240,8 +255,88 @@ static int img_write(uint32_t type, uint32_t lba, void *buf, uint32_t len)
#define IOWR(base, reg, value) dma_set(base+(reg<<2), value)
+static int fdd_set(char* filename)
+{
+ int floppy = img_mount(IMG_TYPE_FDD, filename);
+
+ /*
+ 0x00.[0]: media present
+ 0x01.[0]: media writeprotect
+ 0x02.[7:0]: media cylinders
+ 0x03.[7:0]: media sectors per track
+ 0x04.[31:0]: media total sector count
+ 0x05.[1:0]: media heads
+ 0x06.[31:0]: media sd base
+ 0x07.[15:0]: media wait cycles: 200000 us / spt
+ 0x08.[15:0]: media wait rate 0: 1000 us
+ 0x09.[15:0]: media wait rate 1: 1666 us
+ 0x0A.[15:0]: media wait rate 2: 2000 us
+ 0x0B.[15:0]: media wait rate 3: 500 us
+ 0x0C.[7:0]: media type: 8'h20 none; 8'h00 old; 8'hC0 720k; 8'h80 1_44M; 8'h40 2_88M
+ */
+
+ int floppy_cylinders = (floppy_is_2_88m || floppy_is_1_44m || floppy_is_1_2m || floppy_is_720k) ? 80 : 40;
+ int floppy_spt =
+ (floppy_is_160k) ? 8 :
+ (floppy_is_180k) ? 9 :
+ (floppy_is_320k) ? 8 :
+ (floppy_is_360k) ? 9 :
+ (floppy_is_720k) ? 9 :
+ (floppy_is_1_2m) ? 15 :
+ (floppy_is_1_44m) ? 18 :
+ (floppy_is_2_88m) ? 36 :
+ 0;
+ int floppy_total_sectors =
+ (floppy_is_160k) ? 320 :
+ (floppy_is_180k) ? 360 :
+ (floppy_is_320k) ? 640 :
+ (floppy_is_360k) ? 720 :
+ (floppy_is_720k) ? 1440 :
+ (floppy_is_1_2m) ? 2400 :
+ (floppy_is_1_44m) ? 2880 :
+ (floppy_is_2_88m) ? 5760 :
+ 0;
+ int floppy_heads = (floppy_is_160k || floppy_is_180k) ? 1 : 2;
+
+ int floppy_wait_cycles = 200000000 / floppy_spt;
+
+ int floppy_media =
+ (!floppy) ? 0x20 :
+ (floppy_is_160k) ? 0x00 :
+ (floppy_is_180k) ? 0x00 :
+ (floppy_is_320k) ? 0x00 :
+ (floppy_is_360k) ? 0x00 :
+ (floppy_is_720k) ? 0xC0 :
+ (floppy_is_1_2m) ? 0x00 :
+ (floppy_is_1_44m) ? 0x80 :
+ (floppy_is_2_88m) ? 0x40 :
+ 0x20;
+
+ IOWR(FLOPPY_BASE, 0x0, floppy ? 1 : 0);
+ IOWR(FLOPPY_BASE, 0x1, (floppy && (get_image(IMG_TYPE_FDD)->mode & O_RDWR)) ? 0 : 1);
+ IOWR(FLOPPY_BASE, 0x2, floppy_cylinders);
+ IOWR(FLOPPY_BASE, 0x3, floppy_spt);
+ IOWR(FLOPPY_BASE, 0x4, floppy_total_sectors);
+ IOWR(FLOPPY_BASE, 0x5, floppy_heads);
+ IOWR(FLOPPY_BASE, 0x6, 0); // base LBA
+ IOWR(FLOPPY_BASE, 0x7, (int)(floppy_wait_cycles / (1000000000.0 / ALT_CPU_CPU_FREQ)));
+ IOWR(FLOPPY_BASE, 0x8, (int)(1000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
+ IOWR(FLOPPY_BASE, 0x9, (int)(1666666.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
+ IOWR(FLOPPY_BASE, 0xA, (int)(2000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
+ IOWR(FLOPPY_BASE, 0xB, (int)(500000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
+ IOWR(FLOPPY_BASE, 0xC, floppy_media);
+
+ return floppy;
+}
+
void x86_init()
{
+ user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET);
+ fpga_core_reset(1);
+ usleep(10000);
+ fpga_gpo_write(0);
+ spi_uio_cmd(0);
+
IOWR(PC_BUS_BASE, 0, 0x00FFF0EA);
IOWR(PC_BUS_BASE, 1, 0x000000F0);
@@ -273,75 +368,8 @@ void x86_init()
//-------------------------------------------------------------------------- floppy
- int floppy = img_mount(IMG_TYPE_FDD, "ao486/floppy.img");
-
- /*
- 0x00.[0]: media present
- 0x01.[0]: media writeprotect
- 0x02.[7:0]: media cylinders
- 0x03.[7:0]: media sectors per track
- 0x04.[31:0]: media total sector count
- 0x05.[1:0]: media heads
- 0x06.[31:0]: media sd base
- 0x07.[15:0]: media wait cycles: 200000 us / spt
- 0x08.[15:0]: media wait rate 0: 1000 us
- 0x09.[15:0]: media wait rate 1: 1666 us
- 0x0A.[15:0]: media wait rate 2: 2000 us
- 0x0B.[15:0]: media wait rate 3: 500 us
- 0x0C.[7:0]: media type: 8'h20 none; 8'h00 old; 8'hC0 720k; 8'h80 1_44M; 8'h40 2_88M
- */
-
- int floppy_cylinders = (floppy_is_2_88m || floppy_is_1_44m || floppy_is_1_2m || floppy_is_720k)? 80 : 40;
- int floppy_spt =
- (floppy_is_160k)? 8 :
- (floppy_is_180k)? 9 :
- (floppy_is_320k)? 8 :
- (floppy_is_360k)? 9 :
- (floppy_is_720k)? 9 :
- (floppy_is_1_2m)? 15 :
- (floppy_is_1_44m)? 18 :
- (floppy_is_2_88m)? 36 :
- 0;
- int floppy_total_sectors =
- (floppy_is_160k)? 320 :
- (floppy_is_180k)? 360 :
- (floppy_is_320k)? 640 :
- (floppy_is_360k)? 720 :
- (floppy_is_720k)? 1440 :
- (floppy_is_1_2m)? 2400 :
- (floppy_is_1_44m)? 2880 :
- (floppy_is_2_88m)? 5760 :
- 0;
- int floppy_heads = (floppy_is_160k || floppy_is_180k)? 1 : 2;
-
- int floppy_wait_cycles = 200000000 / floppy_spt;
-
- int floppy_media =
- (!floppy)? 0x20 :
- (floppy_is_160k)? 0x00 :
- (floppy_is_180k)? 0x00 :
- (floppy_is_320k)? 0x00 :
- (floppy_is_360k)? 0x00 :
- (floppy_is_720k)? 0xC0 :
- (floppy_is_1_2m)? 0x00 :
- (floppy_is_1_44m)? 0x80 :
- (floppy_is_2_88m)? 0x40 :
- 0x20;
-
- IOWR(FLOPPY_BASE, 0x0, floppy? 1 : 0);
- IOWR(FLOPPY_BASE, 0x1, (floppy && (get_image(IMG_TYPE_FDD)->mode & O_RDWR)) ? 0 : 1);
- IOWR(FLOPPY_BASE, 0x2, floppy_cylinders);
- IOWR(FLOPPY_BASE, 0x3, floppy_spt);
- IOWR(FLOPPY_BASE, 0x4, floppy_total_sectors);
- IOWR(FLOPPY_BASE, 0x5, floppy_heads);
- IOWR(FLOPPY_BASE, 0x6, 0); // base LBA
- IOWR(FLOPPY_BASE, 0x7, (int)(floppy_wait_cycles / (1000000000.0 / ALT_CPU_CPU_FREQ)));
- IOWR(FLOPPY_BASE, 0x8, (int)(1000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
- IOWR(FLOPPY_BASE, 0x9, (int)(1666666.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
- IOWR(FLOPPY_BASE, 0xA, (int)(2000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
- IOWR(FLOPPY_BASE, 0xB, (int)(500000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
- IOWR(FLOPPY_BASE, 0xC, floppy_media);
-
+ int floppy = fdd_set(config.fdd_name);
+
//-------------------------------------------------------------------------- hdd
unsigned int hd_cylinders = 0;
@@ -350,7 +378,7 @@ void x86_init()
unsigned int hd_total_sectors = 0;
unsigned int hdd_sd_base = 0;
- int hdd = img_mount(IMG_TYPE_HDD, "ao486/hdd.vhd");
+ int hdd = img_mount(IMG_TYPE_HDD, config.hdd_name);
if (hdd)
{
hd_cylinders = 1024;
@@ -478,8 +506,6 @@ void x86_init()
//-------------------------------------------------------------------------- rtc
- bool boot_from_floppy = floppy;
-
/*
128.[26:0]: cycles in second
129.[12:0]: cycles in 122.07031 us
@@ -590,6 +616,8 @@ void x86_init()
cmos[0x2F] = sum & 0xFF;
for(unsigned int i=0; i