St and X86 moved to support
This commit is contained in:
655
support/st/st_ikbd.cpp
Normal file
655
support/st/st_ikbd.cpp
Normal file
@@ -0,0 +1,655 @@
|
||||
/*
|
||||
|
||||
http://removers.free.fr/wikipendium/wakka.php?wiki=IntelligentKeyboardBible
|
||||
https://www.kernel.org/doc/Documentation/input/atarikbd.txt
|
||||
|
||||
ikbd ToDo:
|
||||
|
||||
Feature Example using/needing it impl. tested
|
||||
---------------------------------------------------------------------
|
||||
mouse y at bottom Bolo X X
|
||||
mouse button key events Goldrunner/A_008 X X
|
||||
joystick interrogation mode Xevious/A_004 X X
|
||||
Absolute mouse mode Addicataball/A_050 X X
|
||||
disable mouse ? X
|
||||
disable joystick ? X
|
||||
Joysticks also generate Goldrunner X -X
|
||||
mouse button events!
|
||||
Pause/Resume PACMANIA_STE/Gembench X
|
||||
mouse keycode mode Goldrunner X X
|
||||
|
||||
Games that have ikbd problems:
|
||||
PowerMonger/PP_106 fixed
|
||||
Stardust fixed
|
||||
M1 tank platoon/A_385 fixed
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../user_io.h"
|
||||
#include "../../spi.h"
|
||||
#include "st_ikbd.h"
|
||||
#include "../../debug.h"
|
||||
|
||||
#define IKBD_AUTO_MS 20
|
||||
|
||||
// atari ikbd stuff
|
||||
#define IKBD_STATE_JOYSTICK_EVENT_REPORTING 0x01
|
||||
#define IKBD_STATE_MOUSE_Y_BOTTOM 0x02
|
||||
#define IKBD_STATE_MOUSE_BUTTON_AS_KEY 0x04 // mouse buttons act like keys
|
||||
#define IKBD_STATE_MOUSE_DISABLED 0x08
|
||||
#define IKBD_STATE_MOUSE_ABSOLUTE 0x10
|
||||
#define IKBD_STATE_MOUSE_ABSOLUTE_IN_PROGRESS 0x20
|
||||
#define IKBD_STATE_WAIT4RESET 0x40
|
||||
#define IKBD_STATE_PAUSED 0x80
|
||||
|
||||
#define IKBD_DEFAULT IKBD_STATE_JOYSTICK_EVENT_REPORTING
|
||||
|
||||
/* ------------------- transmit queue ------------------- */
|
||||
#define QUEUE_LEN 16 // power of 2!
|
||||
static unsigned short tx_queue[QUEUE_LEN];
|
||||
static unsigned char wptr = 0, rptr = 0;
|
||||
static unsigned long ikbd_timer = 0;
|
||||
|
||||
/* -------- main structure to keep track of ikbd state -------- */
|
||||
static struct {
|
||||
unsigned char state;
|
||||
unsigned long auto_timer; // auto report timer (50hz/20ms)
|
||||
unsigned long rtc_timer;
|
||||
// ----- joystick state -------
|
||||
struct {
|
||||
unsigned char state; // current state
|
||||
unsigned char prev; // last reported state
|
||||
} joy[2];
|
||||
|
||||
// ----- mouse state -------
|
||||
struct {
|
||||
// current state
|
||||
unsigned char but, but_prev;
|
||||
short x, y;
|
||||
|
||||
struct {
|
||||
// absolute mouse state
|
||||
unsigned char buttons;
|
||||
struct { unsigned short x, y; } max;
|
||||
struct { unsigned char x, y; } scale;
|
||||
struct { unsigned short x, y; } pos;
|
||||
} abs;
|
||||
} mouse;
|
||||
|
||||
// ----- clock state ------
|
||||
unsigned char date[6];
|
||||
|
||||
unsigned int tx_cnt; // tx byte counter for debugging
|
||||
|
||||
// ----- buffer tp hold incoming commands ------
|
||||
struct {
|
||||
char size;
|
||||
|
||||
union {
|
||||
struct {
|
||||
unsigned char code; // cmd code
|
||||
|
||||
// command specific structures
|
||||
union {
|
||||
unsigned char mouse_button_action;
|
||||
unsigned char reset;
|
||||
struct { unsigned short max_x, max_y; } __attribute__((packed)) abs_mouse_pos;
|
||||
struct { unsigned char dist_x, dist_y; } __attribute__((packed)) mouse_keycode;
|
||||
struct { unsigned char x, y; } __attribute__((packed)) mouse_threshold;
|
||||
struct { unsigned char x, y; } __attribute__((packed)) mouse_scale;
|
||||
struct { unsigned char f; unsigned short x, y; } __attribute__((packed)) load_mouse_pos;
|
||||
unsigned char date[6];
|
||||
};
|
||||
} __attribute__((packed)) command;
|
||||
|
||||
unsigned char byte[0];
|
||||
};
|
||||
} buffer;
|
||||
|
||||
} ikbd;
|
||||
|
||||
// read a 16 bit word in big endian
|
||||
unsigned short be16(unsigned short in) {
|
||||
return ((in & 0xff) << 8) + ((in & 0xff00) >> 8);
|
||||
}
|
||||
|
||||
static void enqueue(unsigned short b) {
|
||||
if (((wptr + 1)&(QUEUE_LEN - 1)) == rptr)
|
||||
return;
|
||||
|
||||
tx_queue[wptr] = b;
|
||||
wptr = (wptr + 1)&(QUEUE_LEN - 1);
|
||||
}
|
||||
|
||||
unsigned char bcd2bin(unsigned char in) {
|
||||
return 10 * (in >> 4) + (in & 0x0f);
|
||||
}
|
||||
|
||||
unsigned char bin2bcd(unsigned char in) {
|
||||
return 16 * (in / 10) + (in % 10);
|
||||
}
|
||||
|
||||
// convert internal joystick format into atari ikbd format
|
||||
static unsigned char joystick_map2ikbd(unsigned char in) {
|
||||
unsigned char out = 0;
|
||||
|
||||
if (in & JOY_UP) out |= 0x01;
|
||||
if (in & JOY_DOWN) out |= 0x02;
|
||||
if (in & JOY_LEFT) out |= 0x04;
|
||||
if (in & JOY_RIGHT) out |= 0x08;
|
||||
if (in & JOY_BTN1) out |= 0x80;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void ikbd_handler_mouse_button_action(void) {
|
||||
unsigned char action = ikbd.buffer.command.mouse_button_action;
|
||||
ikbd_debugf("mouse button action = %d", action);
|
||||
|
||||
// bit 2: Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
|
||||
if (action & 0x04) ikbd.state |= IKBD_STATE_MOUSE_BUTTON_AS_KEY;
|
||||
else ikbd.state &= ~IKBD_STATE_MOUSE_BUTTON_AS_KEY;
|
||||
}
|
||||
|
||||
void ikbd_handler_set_relative_mouse_pos(void) {
|
||||
ikbd_debugf("Set relative mouse positioning");
|
||||
ikbd.state &= ~IKBD_STATE_MOUSE_DISABLED;
|
||||
ikbd.state &= ~IKBD_STATE_MOUSE_ABSOLUTE;
|
||||
}
|
||||
|
||||
void ikbd_handler_set_abs_mouse_pos(void) {
|
||||
ikbd.mouse.abs.max.x = be16(ikbd.buffer.command.abs_mouse_pos.max_x);
|
||||
ikbd.mouse.abs.max.y = be16(ikbd.buffer.command.abs_mouse_pos.max_y);
|
||||
|
||||
ikbd_debugf("Set absolute mouse positioning, max = %u/%u",
|
||||
ikbd.mouse.abs.max.x, ikbd.mouse.abs.max.y);
|
||||
|
||||
ikbd.state &= ~IKBD_STATE_MOUSE_DISABLED;
|
||||
ikbd.state |= IKBD_STATE_MOUSE_ABSOLUTE;
|
||||
ikbd.mouse.abs.buttons = 2 | 8;
|
||||
}
|
||||
|
||||
void ikbd_handler_set_mouse_keycode_mode(void) {
|
||||
ikbd_debugf("Set mouse keycode mode dist %u/%u",
|
||||
ikbd.buffer.command.mouse_keycode.dist_x,
|
||||
ikbd.buffer.command.mouse_keycode.dist_y);
|
||||
}
|
||||
|
||||
void ikbd_handler_set_mouse_threshold(void) {
|
||||
ikbd_debugf("Set mouse threshold %u/%u",
|
||||
ikbd.buffer.command.mouse_threshold.x,
|
||||
ikbd.buffer.command.mouse_threshold.y);
|
||||
}
|
||||
|
||||
void ikbd_handler_set_mouse_scale(void) {
|
||||
ikbd_debugf("Set mouse scale %u/%u",
|
||||
ikbd.buffer.command.mouse_scale.x,
|
||||
ikbd.buffer.command.mouse_scale.y);
|
||||
|
||||
ikbd.mouse.abs.scale.x = ikbd.buffer.command.mouse_scale.x;
|
||||
ikbd.mouse.abs.scale.y = ikbd.buffer.command.mouse_scale.y;
|
||||
}
|
||||
|
||||
void ikbd_handler_interrogate_mouse_pos(void) {
|
||||
// ikbd_debugf("Interrogate Mouse Position");
|
||||
if (ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE) {
|
||||
|
||||
enqueue(0x8000 + 3); // 3ms delay, hatari uses 18000 cycles (~2.25ms)
|
||||
enqueue(0xf7);
|
||||
enqueue(ikbd.mouse.abs.buttons);
|
||||
enqueue(ikbd.mouse.abs.pos.x >> 8);
|
||||
enqueue(ikbd.mouse.abs.pos.x & 0xff);
|
||||
enqueue(ikbd.mouse.abs.pos.y >> 8);
|
||||
enqueue(ikbd.mouse.abs.pos.y & 0xff);
|
||||
|
||||
ikbd.mouse.abs.buttons = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ikbd_handler_load_mouse_pos(void) {
|
||||
ikbd.mouse.abs.pos.x = be16(ikbd.buffer.command.load_mouse_pos.x);
|
||||
ikbd.mouse.abs.pos.y = be16(ikbd.buffer.command.load_mouse_pos.y);
|
||||
|
||||
ikbd_debugf("Load mouse position %u/%u", ikbd.mouse.abs.pos.x, ikbd.mouse.abs.pos.y);
|
||||
}
|
||||
|
||||
void ikbd_handler_set_y_bottom(void) {
|
||||
ikbd_debugf("Set Y at bottom");
|
||||
ikbd.state |= IKBD_STATE_MOUSE_Y_BOTTOM;
|
||||
}
|
||||
|
||||
void ikbd_handler_set_y_top(void) {
|
||||
ikbd_debugf("Set Y at top");
|
||||
ikbd.state &= ~IKBD_STATE_MOUSE_Y_BOTTOM;
|
||||
}
|
||||
|
||||
void ikbd_handler_resume(void) {
|
||||
ikbd.state &= ~IKBD_STATE_PAUSED;
|
||||
}
|
||||
|
||||
void ikbd_handler_disable_mouse(void) {
|
||||
ikbd_debugf("Disable mouse");
|
||||
ikbd.state |= IKBD_STATE_MOUSE_DISABLED;
|
||||
}
|
||||
|
||||
void ikbd_handler_pause(void) {
|
||||
ikbd.state |= IKBD_STATE_PAUSED;
|
||||
}
|
||||
|
||||
void ikbd_handler_set_joystick_event_reporting(void) {
|
||||
ikbd_debugf("Set Joystick event reporting");
|
||||
ikbd.state |= IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
||||
ikbd.state &= ~IKBD_STATE_PAUSED;
|
||||
}
|
||||
|
||||
void ikbd_handler_set_joystick_interrogation_mode(void) {
|
||||
ikbd_debugf("Set Joystick interrogation mode");
|
||||
ikbd.state &= ~IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
||||
ikbd.state &= ~IKBD_STATE_PAUSED;
|
||||
}
|
||||
|
||||
void ikbd_handler_interrogate_joystick(void) {
|
||||
// send reply
|
||||
enqueue(0xfd);
|
||||
enqueue(ikbd.joy[0].state | ((ikbd.mouse.but & (1 << 0)) ? 0x80 : 0x00));
|
||||
enqueue(ikbd.joy[1].state | ((ikbd.mouse.but & (1 << 1)) ? 0x80 : 0x00));
|
||||
}
|
||||
|
||||
void ikbd_handler_disable_joysticks(void) {
|
||||
ikbd_debugf("Disable joysticks");
|
||||
ikbd.state &= ~IKBD_STATE_JOYSTICK_EVENT_REPORTING;
|
||||
}
|
||||
|
||||
void ikbd_handler_time_set(void) {
|
||||
unsigned char c;
|
||||
for (c = 0; c<6; c++)
|
||||
ikbd.date[c] = bcd2bin(ikbd.buffer.command.date[c]);
|
||||
|
||||
// release SPI since it will be used by usb when
|
||||
// reading the time from the rtc
|
||||
DisableIO();
|
||||
|
||||
// try to set time on rtc if present
|
||||
//usb_rtc_set_time(ikbd.date);
|
||||
|
||||
spi_uio_cmd_cont(UIO_IKBD_IN);
|
||||
|
||||
ikbd_debugf("Time of day clock set: %u:%02u:%02u %u.%u.%u",
|
||||
ikbd.date[3], ikbd.date[4], ikbd.date[5],
|
||||
ikbd.date[2], ikbd.date[1], 1900 + ikbd.date[0]);
|
||||
}
|
||||
|
||||
void ikbd_handler_interrogate_time(void) {
|
||||
unsigned char i;
|
||||
|
||||
// release SPI since it will be used by usb when
|
||||
// reading the time from the rtc
|
||||
DisableIO();
|
||||
|
||||
// try to fetch time from rtc if present
|
||||
//usb_rtc_get_time(ikbd.date);
|
||||
|
||||
spi_uio_cmd_cont(UIO_IKBD_IN);
|
||||
|
||||
ikbd_debugf("Interrogate time of day %u:%02u:%02u %u.%u.%u",
|
||||
ikbd.date[3], ikbd.date[4], ikbd.date[5],
|
||||
ikbd.date[2], ikbd.date[1], 1900 + ikbd.date[0]);
|
||||
|
||||
enqueue(0x8000 + 64); // wait 64ms
|
||||
enqueue(0xfc);
|
||||
for (i = 0; i<6; i++) enqueue(bin2bcd(ikbd.date[i]));
|
||||
}
|
||||
|
||||
void ikbd_handler_reset(void) {
|
||||
ikbd_debugf("Reset %x", ikbd.buffer.command.reset);
|
||||
|
||||
if (ikbd.buffer.command.reset == 1) {
|
||||
ikbd.state = IKBD_DEFAULT;
|
||||
|
||||
enqueue(0x8000 + 300); // wait 300ms
|
||||
enqueue(0xf0);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- list of supported ikbd commands ----
|
||||
struct ikbd_command_handler_t {
|
||||
unsigned char code;
|
||||
unsigned char length;
|
||||
void(*handler)(void);
|
||||
};
|
||||
|
||||
ikbd_command_handler_t ikbd_command_handler[] =
|
||||
{
|
||||
{ 0x07, 2, ikbd_handler_mouse_button_action },
|
||||
{ 0x08, 1, ikbd_handler_set_relative_mouse_pos },
|
||||
{ 0x09, 5, ikbd_handler_set_abs_mouse_pos },
|
||||
{ 0x0a, 3, ikbd_handler_set_mouse_keycode_mode },
|
||||
{ 0x0b, 3, ikbd_handler_set_mouse_threshold },
|
||||
{ 0x0c, 3, ikbd_handler_set_mouse_scale },
|
||||
{ 0x0d, 1, ikbd_handler_interrogate_mouse_pos },
|
||||
{ 0x0e, 6, ikbd_handler_load_mouse_pos },
|
||||
{ 0x0f, 1, ikbd_handler_set_y_bottom },
|
||||
{ 0x10, 1, ikbd_handler_set_y_top },
|
||||
{ 0x11, 1, ikbd_handler_resume },
|
||||
{ 0x12, 1, ikbd_handler_disable_mouse },
|
||||
{ 0x13, 1, ikbd_handler_pause },
|
||||
{ 0x14, 1, ikbd_handler_set_joystick_event_reporting },
|
||||
{ 0x15, 1, ikbd_handler_set_joystick_interrogation_mode },
|
||||
{ 0x16, 1, ikbd_handler_interrogate_joystick },
|
||||
{ 0x1a, 1, ikbd_handler_disable_joysticks },
|
||||
{ 0x1c, 1, ikbd_handler_interrogate_time },
|
||||
{ 0x1b, 7, ikbd_handler_time_set },
|
||||
{ 0x80, 2, ikbd_handler_reset },
|
||||
{ 0, 0, NULL } // end of list
|
||||
};
|
||||
|
||||
void ikbd_init() {
|
||||
// reset ikbd state
|
||||
memset(&ikbd, 0, sizeof(ikbd));
|
||||
ikbd.state = IKBD_DEFAULT | IKBD_STATE_WAIT4RESET;
|
||||
|
||||
ikbd.mouse.abs.max.x = ikbd.mouse.abs.max.y = 65535;
|
||||
ikbd.mouse.abs.scale.x = ikbd.mouse.abs.scale.y = 1;
|
||||
|
||||
ikbd_debugf("Init");
|
||||
|
||||
// init ikbd date to some default
|
||||
ikbd.date[0] = 113;
|
||||
ikbd.date[1] = 7;
|
||||
ikbd.date[2] = 20;
|
||||
ikbd.date[3] = 20;
|
||||
ikbd.date[4] = 58;
|
||||
|
||||
// handle auto events
|
||||
ikbd.auto_timer = GetTimer(0);
|
||||
ikbd.rtc_timer = GetTimer(1000);
|
||||
}
|
||||
|
||||
void ikbd_reset(void) {
|
||||
ikbd.tx_cnt = 0;
|
||||
ikbd.state |= IKBD_STATE_WAIT4RESET;
|
||||
}
|
||||
|
||||
// process inout from atari core into ikbd
|
||||
void ikbd_handle_input(unsigned char cmd) {
|
||||
// store byte in buffer
|
||||
ikbd.buffer.byte[ikbd.buffer.size++] = cmd;
|
||||
|
||||
// check if there's a known command in the buffer
|
||||
char c;
|
||||
for (c = 0; ikbd_command_handler[c].length &&
|
||||
(ikbd_command_handler[c].code != ikbd.buffer.command.code); c++);
|
||||
|
||||
// not a valid command? -> flush buffer
|
||||
if (!ikbd_command_handler[c].length)
|
||||
ikbd.buffer.size = 0;
|
||||
else {
|
||||
// valid command and enough bytes?
|
||||
if (ikbd_command_handler[c].length == ikbd.buffer.size) {
|
||||
ikbd_command_handler[c].handler();
|
||||
ikbd.buffer.size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// advance the ikbd time by one second
|
||||
static void ikbd_update_time()
|
||||
{
|
||||
static const char mdays[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
||||
|
||||
short year = 1900 + ikbd.date[0];
|
||||
char is_leap = (!(year % 4) && (year % 100)) || !(year % 400);
|
||||
|
||||
// advance seconds
|
||||
ikbd.date[5]++;
|
||||
if (ikbd.date[5] == 60)
|
||||
{
|
||||
ikbd.date[5] = 0;
|
||||
|
||||
// advance minutes
|
||||
ikbd.date[4]++;
|
||||
if (ikbd.date[4] == 60)
|
||||
{
|
||||
ikbd.date[4] = 0;
|
||||
|
||||
// advance hours
|
||||
ikbd.date[3]++;
|
||||
if (ikbd.date[3] == 24)
|
||||
{
|
||||
ikbd.date[3] = 0;
|
||||
|
||||
// advance days
|
||||
ikbd.date[2]++;
|
||||
if ((ikbd.date[2] == mdays[ikbd.date[1] - 1] + 1) ||
|
||||
(is_leap && (ikbd.date[1] == 2) && (ikbd.date[2] == 29)))
|
||||
{
|
||||
ikbd.date[2] = 1;
|
||||
|
||||
// advance month
|
||||
ikbd.date[1]++;
|
||||
if (ikbd.date[1] == 13)
|
||||
{
|
||||
ikbd.date[1] = 0;
|
||||
|
||||
// advance year
|
||||
ikbd.date[0]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ikbd_poll(void) {
|
||||
#ifdef IKBD_DEBUG
|
||||
static unsigned long xtimer = 0;
|
||||
static int last_cnt = 0;
|
||||
if (CheckTimer(xtimer)) {
|
||||
xtimer = GetTimer(2000);
|
||||
if (ikbd.tx_cnt != last_cnt) {
|
||||
ikbd_debugf("sent bytes: %d", ikbd.tx_cnt);
|
||||
last_cnt = ikbd.tx_cnt;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (CheckTimer(ikbd.rtc_timer))
|
||||
{
|
||||
ikbd.rtc_timer = GetTimer(1000);
|
||||
ikbd_update_time();
|
||||
}
|
||||
|
||||
// do auto events every 20ms
|
||||
if (CheckTimer(ikbd.auto_timer)) {
|
||||
ikbd.auto_timer = GetTimer(IKBD_AUTO_MS);
|
||||
|
||||
if (!(ikbd.state & IKBD_STATE_WAIT4RESET) &&
|
||||
!(ikbd.state & IKBD_STATE_PAUSED)) {
|
||||
|
||||
/* --------- joystick ---------- */
|
||||
if (ikbd.state & IKBD_STATE_JOYSTICK_EVENT_REPORTING) {
|
||||
char i;
|
||||
for (i = 0; i<2; i++) {
|
||||
unsigned char state = ikbd.joy[i].state;
|
||||
|
||||
// left mouse button 1 is also joystick 0 fire button
|
||||
// right mouse button 0 is also joystick 1 fire button
|
||||
if (ikbd.mouse.but & (2 >> i)) state |= 0x80;
|
||||
|
||||
if (state != ikbd.joy[i].prev) {
|
||||
// printf("JOY%d: %x\n", i, state);
|
||||
enqueue(0xfe + i);
|
||||
enqueue(state);
|
||||
ikbd.joy[i].prev = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------- relative mouse ---------- */
|
||||
if (!(ikbd.state & IKBD_STATE_MOUSE_DISABLED) &&
|
||||
!(ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE)) {
|
||||
unsigned char b = ikbd.mouse.but;
|
||||
|
||||
// include joystick buttons into mouse state
|
||||
if (ikbd.joy[0].state & 0x80) b |= 2;
|
||||
if (ikbd.joy[1].state & 0x80) b |= 1;
|
||||
|
||||
if (ikbd.mouse.x || ikbd.mouse.y || (b != ikbd.mouse.but_prev)) {
|
||||
do {
|
||||
char x, y;
|
||||
if (ikbd.mouse.x < -128) x = -128;
|
||||
else if (ikbd.mouse.x > 127) x = 127;
|
||||
else x = ikbd.mouse.x;
|
||||
|
||||
if (ikbd.mouse.y < -128) y = -128;
|
||||
else if (ikbd.mouse.y > 127) y = 127;
|
||||
else y = ikbd.mouse.y;
|
||||
|
||||
// printf("RMOUSE: %x %x %x\n", b, x&0xff, y&0xff);
|
||||
enqueue(0xf8 | b);
|
||||
enqueue(x & 0xff);
|
||||
enqueue(y & 0xff);
|
||||
|
||||
ikbd.mouse.x -= x;
|
||||
ikbd.mouse.y -= y;
|
||||
|
||||
} while (ikbd.mouse.x || ikbd.mouse.y);
|
||||
|
||||
// check if mouse buttons are supposed to be treated like keys
|
||||
if (ikbd.state & IKBD_STATE_MOUSE_BUTTON_AS_KEY) {
|
||||
|
||||
// check if mouse button state has changed
|
||||
if (b != ikbd.mouse.but_prev) {
|
||||
// Mouse buttons act like keys (LEFT=0x74 & RIGHT=0x75)
|
||||
|
||||
// handle left mouse button
|
||||
if ((b ^ ikbd.mouse.but_prev) & 2) ikbd_keyboard(0x74 | ((b & 2) ? 0x00 : 0x80));
|
||||
// handle right mouse button
|
||||
if ((b ^ ikbd.mouse.but_prev) & 1) ikbd_keyboard(0x75 | ((b & 1) ? 0x00 : 0x80));
|
||||
}
|
||||
}
|
||||
|
||||
ikbd.mouse.but_prev = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned long mtimer = 0;
|
||||
if (CheckTimer(mtimer)) {
|
||||
mtimer = GetTimer(10);
|
||||
|
||||
// check for incoming ikbd data
|
||||
spi_uio_cmd_cont(UIO_IKBD_IN);
|
||||
|
||||
while (spi_in())
|
||||
ikbd_handle_input(spi_in());
|
||||
|
||||
DisableIO();
|
||||
}
|
||||
|
||||
// everything below must not happen faster than 1khz
|
||||
static unsigned long rtimer = 0;
|
||||
if (!CheckTimer(rtimer))
|
||||
return;
|
||||
|
||||
// next event 1 ms later
|
||||
rtimer = GetTimer(1);
|
||||
|
||||
// timer active?
|
||||
if (ikbd_timer) {
|
||||
if (!CheckTimer(ikbd_timer))
|
||||
return;
|
||||
|
||||
ikbd_timer = 0;
|
||||
}
|
||||
|
||||
if (rptr == wptr) return;
|
||||
|
||||
if (tx_queue[rptr] & 0x8000) {
|
||||
|
||||
// request to start timer?
|
||||
if (tx_queue[rptr] & 0x8000)
|
||||
ikbd_timer = GetTimer(tx_queue[rptr] & 0x3fff);
|
||||
|
||||
rptr = (rptr + 1)&(QUEUE_LEN - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// transmit data from queue
|
||||
spi_uio_cmd_cont(UIO_IKBD_OUT);
|
||||
spi8(tx_queue[rptr]);
|
||||
DisableIO();
|
||||
|
||||
ikbd.tx_cnt++;
|
||||
|
||||
rptr = (rptr + 1)&(QUEUE_LEN - 1);
|
||||
}
|
||||
|
||||
// called from external parts to report joystick states
|
||||
void ikbd_joystick(unsigned char joystick, unsigned char map) {
|
||||
ikbd.joy[joystick].state = joystick_map2ikbd(map);
|
||||
}
|
||||
|
||||
void ikbd_keyboard(unsigned char code) {
|
||||
#ifdef IKBD_DEBUG
|
||||
ikbd_debugf("send keycode %x%s", code & 0x7f, (code & 0x80) ? " BREAK" : "");
|
||||
#endif
|
||||
enqueue(code);
|
||||
}
|
||||
|
||||
void ikbd_mouse(unsigned char b, char x, char y) {
|
||||
|
||||
// honour reversal of y axis
|
||||
if (ikbd.state & IKBD_STATE_MOUSE_Y_BOTTOM)
|
||||
y = -y;
|
||||
|
||||
// update relative mouse state
|
||||
ikbd.mouse.but = ((b & 1) ? 2 : 0) | ((b & 2) ? 1 : 0);
|
||||
ikbd.mouse.x += x;
|
||||
ikbd.mouse.y += y;
|
||||
|
||||
// save button state for absolute mouse reports
|
||||
|
||||
if (ikbd.state & IKBD_STATE_MOUSE_ABSOLUTE) {
|
||||
// include joystick buttons into mouse state
|
||||
if (ikbd.joy[0].state & 0x80) b |= 2;
|
||||
if (ikbd.joy[1].state & 0x80) b |= 1;
|
||||
|
||||
if (b & 2) ikbd.mouse.abs.buttons |= 1;
|
||||
else ikbd.mouse.abs.buttons |= 2;
|
||||
if (b & 1) ikbd.mouse.abs.buttons |= 4;
|
||||
else ikbd.mouse.abs.buttons |= 8;
|
||||
|
||||
if (ikbd.mouse.abs.scale.x > 1) x *= ikbd.mouse.abs.scale.x;
|
||||
if (ikbd.mouse.abs.scale.y > 1) y *= ikbd.mouse.abs.scale.y;
|
||||
|
||||
// ikbd_debugf("abs inc %d %d -> ", x, y);
|
||||
|
||||
if (x < 0) {
|
||||
x = -x;
|
||||
|
||||
if (ikbd.mouse.abs.pos.x > x) ikbd.mouse.abs.pos.x -= x;
|
||||
else ikbd.mouse.abs.pos.x = 0;
|
||||
}
|
||||
else if (x > 0) {
|
||||
if (ikbd.mouse.abs.pos.x < ikbd.mouse.abs.max.x - x)
|
||||
ikbd.mouse.abs.pos.x += x;
|
||||
else
|
||||
ikbd.mouse.abs.pos.x = ikbd.mouse.abs.max.x;
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
y = -y;
|
||||
if (ikbd.mouse.abs.pos.y > y) ikbd.mouse.abs.pos.y -= y;
|
||||
else ikbd.mouse.abs.pos.y = 0;
|
||||
}
|
||||
else if (y > 0) {
|
||||
if (ikbd.mouse.abs.pos.y < ikbd.mouse.abs.max.y - y)
|
||||
ikbd.mouse.abs.pos.y += y;
|
||||
else
|
||||
ikbd.mouse.abs.pos.y = ikbd.mouse.abs.max.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
support/st/st_ikbd.h
Normal file
11
support/st/st_ikbd.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef __ST_IKBD_H__
|
||||
#define __ST_IKBD_H__
|
||||
|
||||
void ikbd_init(void);
|
||||
void ikbd_poll(void);
|
||||
void ikbd_reset(void);
|
||||
void ikbd_joystick(unsigned char joy, unsigned char map);
|
||||
void ikbd_mouse(unsigned char buttons, char x, char y);
|
||||
void ikbd_keyboard(unsigned char code);
|
||||
|
||||
#endif // IKBD_H
|
||||
1154
support/st/st_tos.cpp
Normal file
1154
support/st/st_tos.cpp
Normal file
File diff suppressed because it is too large
Load Diff
107
support/st/st_tos.h
Normal file
107
support/st/st_tos.h
Normal file
@@ -0,0 +1,107 @@
|
||||
#ifndef __ST_TOS_H__
|
||||
#define __ST_TOS_H__
|
||||
|
||||
#include "../../file_io.h"
|
||||
|
||||
// FPGA spi cmommands
|
||||
#define MIST_INVALID 0x00
|
||||
|
||||
// memory interface
|
||||
#define MIST_SET_ADDRESS 0x01
|
||||
#define MIST_WRITE_MEMORY 0x02
|
||||
#define MIST_READ_MEMORY 0x03
|
||||
#define MIST_SET_CONTROL 0x04
|
||||
#define MIST_GET_DMASTATE 0x05 // reads state of dma and floppy controller
|
||||
#define MIST_ACK_DMA 0x06 // acknowledge a dma command
|
||||
#define MIST_BUS_REQ 0x07 // request bus
|
||||
#define MIST_BUS_REL 0x08 // release bus
|
||||
#define MIST_SET_VADJ 0x09
|
||||
#define MIST_NAK_DMA 0x0a // reject a dma command
|
||||
|
||||
// tos sysconfig bits:
|
||||
// 0 - RESET
|
||||
// 1-3 - Memory configuration
|
||||
// 4-5 - CPU configuration
|
||||
// 6-7 - Floppy A+B write protection
|
||||
// 8 - Color/Monochrome mode
|
||||
// 9 - PAL mode in 56 or 50 Hz
|
||||
// 10-17 - ACSI device enable
|
||||
|
||||
// memory configurations (0x02/0x04/0x08)
|
||||
// (currently 4MB are fixed and cannot be changed)
|
||||
#define TOS_MEMCONFIG_512K (0<<1) // not yet supported
|
||||
#define TOS_MEMCONFIG_1M (1<<1) // not yet supported
|
||||
#define TOS_MEMCONFIG_2M (2<<1) // not yet supported
|
||||
#define TOS_MEMCONFIG_4M (3<<1) // not yet supported
|
||||
#define TOS_MEMCONFIG_8M (4<<1)
|
||||
#define TOS_MEMCONFIG_14M (5<<1)
|
||||
#define TOS_MEMCONFIG_RES0 (6<<1) // reserved
|
||||
#define TOS_MEMCONFIG_RES1 (7<<1) // reserved
|
||||
|
||||
// cpu configurations (0x10/0x20)
|
||||
#define TOS_CPUCONFIG_68000 (0<<4)
|
||||
#define TOS_CPUCONFIG_68010 (1<<4)
|
||||
#define TOS_CPUCONFIG_RESERVED (2<<4)
|
||||
#define TOS_CPUCONFIG_68020 (3<<4)
|
||||
|
||||
// control bits (all control bits have unknown state after core startup)
|
||||
#define TOS_CONTROL_CPU_RESET 0x00000001
|
||||
#define TOS_CONTROL_FDC_WR_PROT_A 0x00000040
|
||||
#define TOS_CONTROL_FDC_WR_PROT_B 0x00000080
|
||||
#define TOS_CONTROL_VIDEO_COLOR 0x00000100 // input to mfp
|
||||
#define TOS_CONTROL_PAL50HZ 0x00000200 // display pal at 50hz (56 hz otherwise)
|
||||
|
||||
// up to eight acsi devices can be enabled
|
||||
#define TOS_ACSI0_ENABLE 0x00000400
|
||||
#define TOS_ACSI1_ENABLE 0x00000800
|
||||
#define TOS_ACSI2_ENABLE 0x00001000
|
||||
#define TOS_ACSI3_ENABLE 0x00002000
|
||||
#define TOS_ACSI4_ENABLE 0x00004000
|
||||
#define TOS_ACSI5_ENABLE 0x00008000
|
||||
#define TOS_ACSI6_ENABLE 0x00010000
|
||||
#define TOS_ACSI7_ENABLE 0x00020000
|
||||
|
||||
#define TOS_CONTROL_TURBO 0x00040000
|
||||
#define TOS_CONTROL_BLITTER 0x00080000
|
||||
|
||||
#define TOS_CONTROL_SCANLINES0 0x00100000 // 0 = off, 1 = 25%, 2 = 50%, 3 = 75%
|
||||
#define TOS_CONTROL_SCANLINES1 0x00200000
|
||||
#define TOS_CONTROL_SCANLINES (TOS_CONTROL_SCANLINES0|TOS_CONTROL_SCANLINES1)
|
||||
|
||||
#define TOS_CONTROL_STEREO 0x00400000
|
||||
#define TOS_CONTROL_STE 0x00800000
|
||||
#define TOS_CONTROL_MSTE 0x01000000
|
||||
#define TOS_CONTROL_ETHERNET 0x02000000
|
||||
|
||||
// USB redirection modes
|
||||
// (NONE=0, RS232=1, PARALLEL=2, MIDI=3)
|
||||
#define TOS_CONTROL_REDIR0 0x04000000
|
||||
#define TOS_CONTROL_REDIR1 0x08000000
|
||||
|
||||
#define TOS_CONTROL_VIKING 0x10000000 // Viking graphics card
|
||||
|
||||
unsigned long tos_system_ctrl(void);
|
||||
|
||||
void tos_upload(const char *);
|
||||
void tos_poll();
|
||||
void tos_update_sysctrl(unsigned long);
|
||||
char *tos_get_disk_name(char);
|
||||
char tos_disk_is_inserted(char index);
|
||||
void tos_insert_disk(char i, const char *name);
|
||||
void tos_eject_all();
|
||||
void tos_select_hdd_image(char i, const char *name);
|
||||
void tos_set_direct_hdd(char on);
|
||||
char tos_get_direct_hdd();
|
||||
void tos_reset(char cold);
|
||||
char *tos_get_image_name();
|
||||
char *tos_get_cartridge_name();
|
||||
char tos_cartridge_is_inserted();
|
||||
void tos_load_cartridge(const char *);
|
||||
|
||||
void tos_set_video_adjust(char axis, char value);
|
||||
char tos_get_video_adjust(char axis);
|
||||
|
||||
void tos_config_init(void);
|
||||
void tos_config_save(void);
|
||||
|
||||
#endif
|
||||
773
support/x86/x86.cpp
Normal file
773
support/x86/x86.cpp
Normal file
@@ -0,0 +1,773 @@
|
||||
/*
|
||||
* Copyright (c) 2014, Aleksander Osman
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <fcntl.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "../../spi.h"
|
||||
#include "../../user_io.h"
|
||||
#include "../../file_io.h"
|
||||
#include "../../fpga_io.h"
|
||||
|
||||
#define ALT_CPU_CPU_FREQ 90000000u
|
||||
|
||||
#define FLOPPY0_BASE 0x8800
|
||||
#define HDD0_BASE 0x8840
|
||||
#define FLOPPY1_BASE 0x9800
|
||||
#define HDD1_BASE 0x9840
|
||||
#define PC_BUS_BASE 0x88a0
|
||||
#define PIO_OUTPUT_BASE 0x8860
|
||||
#define SOUND_BASE 0x9000
|
||||
#define PIT_BASE 0x8880
|
||||
#define RTC_BASE 0x8c00
|
||||
#define SD_BASE 0x0A00
|
||||
|
||||
#define CFG_VER 2
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t ver;
|
||||
char fdd_name[1024];
|
||||
char hdd0_name[1024];
|
||||
char hdd1_name[1024];
|
||||
} x86_config;
|
||||
|
||||
static x86_config config;
|
||||
|
||||
static uint8_t dma_sdio(int status)
|
||||
{
|
||||
uint8_t res;
|
||||
EnableFpga();
|
||||
spi8(UIO_DMA_SDIO);
|
||||
res = spi_w((uint16_t)status);
|
||||
DisableFpga();
|
||||
return res;
|
||||
}
|
||||
|
||||
static uint32_t dma_get(uint32_t address)
|
||||
{
|
||||
EnableFpga();
|
||||
spi8(UIO_DMA_READ);
|
||||
spi32w(address);
|
||||
uint32_t res = spi32w(0);
|
||||
DisableFpga();
|
||||
return res;
|
||||
}
|
||||
|
||||
static void dma_set(uint32_t address, uint32_t data)
|
||||
{
|
||||
EnableFpga();
|
||||
spi8(UIO_DMA_WRITE);
|
||||
spi32w(address);
|
||||
spi32w(data);
|
||||
DisableFpga();
|
||||
}
|
||||
|
||||
static void dma_sendbuf(uint32_t address, uint32_t length, uint32_t *data)
|
||||
{
|
||||
EnableFpga();
|
||||
spi8(UIO_DMA_WRITE);
|
||||
spi32w(address);
|
||||
while (length--) spi32w(*data++);
|
||||
DisableFpga();
|
||||
}
|
||||
|
||||
static void dma_rcvbuf(uint32_t address, uint32_t length, uint32_t *data)
|
||||
{
|
||||
EnableFpga();
|
||||
spi8(UIO_DMA_READ);
|
||||
spi32w(address);
|
||||
while (length--) *data++ = spi32w(0);
|
||||
DisableFpga();
|
||||
}
|
||||
|
||||
static int load_bios(const char* name, uint8_t index)
|
||||
{
|
||||
fileTYPE f = { 0 };
|
||||
static uint32_t buf[128];
|
||||
|
||||
if (!FileOpen(&f, name)) return 0;
|
||||
|
||||
unsigned long bytes2send = f.size;
|
||||
printf("BIOS %s, %lu bytes.\n", name, bytes2send);
|
||||
|
||||
EnableFpga();
|
||||
spi8(UIO_DMA_WRITE);
|
||||
spi32w( index ? 0x80C0000 : 0x80F0000 );
|
||||
|
||||
while (bytes2send)
|
||||
{
|
||||
printf(".");
|
||||
|
||||
uint16_t chunk = (bytes2send>512) ? 512 : bytes2send;
|
||||
bytes2send -= chunk;
|
||||
|
||||
FileReadSec(&f, buf);
|
||||
|
||||
chunk = (chunk + 3) >> 2;
|
||||
uint32_t* p = buf;
|
||||
while(chunk--) spi32w(*p++);
|
||||
}
|
||||
DisableFpga();
|
||||
FileClose(&f);
|
||||
|
||||
printf("\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static bool floppy_is_160k = false;
|
||||
static bool floppy_is_180k = false;
|
||||
static bool floppy_is_320k = false;
|
||||
static bool floppy_is_360k = false;
|
||||
static bool floppy_is_720k = false;
|
||||
static bool floppy_is_1_2m = false;
|
||||
static bool floppy_is_1_44m= false;
|
||||
static bool floppy_is_1_68m= false;
|
||||
static bool floppy_is_2_88m= false;
|
||||
|
||||
#define CMOS_FDD_TYPE ((floppy_is_2_88m) ? 0x50 : (floppy_is_1_44m || floppy_is_1_68m) ? 0x40 : (floppy_is_720k) ? 0x30 : (floppy_is_1_2m) ? 0x20 : 0x10)
|
||||
|
||||
static fileTYPE fdd_image0 = { 0 };
|
||||
static fileTYPE fdd_image1 = { 0 };
|
||||
static fileTYPE hdd_image0 = { 0 };
|
||||
static fileTYPE hdd_image1 = { 0 };
|
||||
static bool boot_from_floppy = 1;
|
||||
|
||||
#define IMG_TYPE_FDD0 0x0800
|
||||
#define IMG_TYPE_FDD1 0x1800
|
||||
|
||||
#define IMG_TYPE_HDD0 0x0000
|
||||
#define IMG_TYPE_HDD1 0x1000
|
||||
|
||||
static __inline fileTYPE *get_image(uint32_t type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case IMG_TYPE_HDD0: return &hdd_image0;
|
||||
case IMG_TYPE_HDD1: return &hdd_image1;
|
||||
case IMG_TYPE_FDD0: return &fdd_image0;
|
||||
}
|
||||
return &fdd_image1;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
get_image(type)->size = 0;
|
||||
printf("Failed to open file %s\n", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Mount %s as %s\n", name, writable ? "read-write" : "read-only");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int img_read(uint32_t type, uint32_t lba, void *buf, uint32_t len)
|
||||
{
|
||||
if (!FileSeekLBA(get_image(type), lba)) return 0;
|
||||
return FileReadAdv(get_image(type), buf, len);
|
||||
}
|
||||
|
||||
static int img_write(uint32_t type, uint32_t lba, void *buf, uint32_t len)
|
||||
{
|
||||
if (!FileSeekLBA(get_image(type), lba)) return 0;
|
||||
return FileWriteAdv(get_image(type), buf, len);
|
||||
}
|
||||
|
||||
#define IOWR(base, reg, value) dma_set(base+(reg<<2), value)
|
||||
|
||||
static uint32_t cmos[128];
|
||||
|
||||
void cmos_set(int addr, uint8_t val)
|
||||
{
|
||||
if (addr >= sizeof(cmos)) return;
|
||||
|
||||
cmos[addr] = val;
|
||||
return;
|
||||
|
||||
uint16_t sum = 0;
|
||||
for (int i = 0x10; i <= 0x2D; i++) sum += cmos[i];
|
||||
|
||||
cmos[0x2E] = sum >> 8;
|
||||
cmos[0x2F] = sum & 0xFF;
|
||||
|
||||
IOWR(RTC_BASE, addr, cmos[addr]);
|
||||
|
||||
IOWR(RTC_BASE, 0x2E, cmos[0x2E]);
|
||||
IOWR(RTC_BASE, 0x2F, cmos[0x2F]);
|
||||
}
|
||||
|
||||
static int fdd_set(char* filename)
|
||||
{
|
||||
floppy_is_160k = false;
|
||||
floppy_is_180k = false;
|
||||
floppy_is_320k = false;
|
||||
floppy_is_360k = false;
|
||||
floppy_is_720k = false;
|
||||
floppy_is_1_2m = false;
|
||||
floppy_is_1_44m = false;
|
||||
floppy_is_1_68m = false;
|
||||
floppy_is_2_88m = false;
|
||||
|
||||
int floppy = img_mount(IMG_TYPE_FDD0, filename);
|
||||
uint32_t size = get_image(IMG_TYPE_FDD0)->size/512;
|
||||
if (floppy && size)
|
||||
{
|
||||
if (size >= 5760) floppy_is_2_88m = true;
|
||||
else if (size >= 3360) floppy_is_1_68m = true;
|
||||
else if (size >= 2880) floppy_is_1_44m = true;
|
||||
else if (size >= 2400) floppy_is_1_2m = true;
|
||||
else if (size >= 1440) floppy_is_720k = true;
|
||||
else if (size >= 720) floppy_is_360k = true;
|
||||
else if (size >= 640) floppy_is_320k = true;
|
||||
else if (size >= 360) floppy_is_180k = true;
|
||||
else floppy_is_160k = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
floppy = 0;
|
||||
floppy_is_1_44m = true;
|
||||
}
|
||||
|
||||
/*
|
||||
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_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_1_68m) ? 21 :
|
||||
(floppy_is_2_88m) ? 36 :
|
||||
0;
|
||||
|
||||
int floppy_cylinders = (floppy_is_2_88m || floppy_is_1_68m || floppy_is_1_44m || floppy_is_1_2m || floppy_is_720k) ? 80 : 40;
|
||||
int floppy_heads = (floppy_is_160k || floppy_is_180k) ? 1 : 2;
|
||||
int floppy_total_sectors = floppy_spt * floppy_heads * floppy_cylinders;
|
||||
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(FLOPPY0_BASE, 0x0, floppy ? 1 : 0);
|
||||
IOWR(FLOPPY0_BASE, 0x1, (floppy && (get_image(IMG_TYPE_FDD0)->mode & O_RDWR)) ? 0 : 1);
|
||||
IOWR(FLOPPY0_BASE, 0x2, floppy_cylinders);
|
||||
IOWR(FLOPPY0_BASE, 0x3, floppy_spt);
|
||||
IOWR(FLOPPY0_BASE, 0x4, floppy_total_sectors);
|
||||
IOWR(FLOPPY0_BASE, 0x5, floppy_heads);
|
||||
IOWR(FLOPPY0_BASE, 0x6, 0); // base LBA
|
||||
IOWR(FLOPPY0_BASE, 0x7, (int)(floppy_wait_cycles / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(FLOPPY0_BASE, 0x8, (int)(1000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(FLOPPY0_BASE, 0x9, (int)(1666666.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(FLOPPY0_BASE, 0xA, (int)(2000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(FLOPPY0_BASE, 0xB, (int)(500000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(FLOPPY0_BASE, 0xC, floppy_media);
|
||||
|
||||
//cmos_set(0x10, CMOS_FDD_TYPE);
|
||||
return floppy;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t type;
|
||||
uint32_t base;
|
||||
uint32_t hd_cylinders;
|
||||
uint32_t hd_heads;
|
||||
uint32_t hd_spt;
|
||||
uint32_t hd_total_sectors;
|
||||
uint32_t present;
|
||||
char* name;
|
||||
} hdd_config;
|
||||
|
||||
static hdd_config hdd[2] = {
|
||||
{ IMG_TYPE_HDD0, HDD0_BASE, 0, 0, 0, 0, 0, config.hdd0_name },
|
||||
{ IMG_TYPE_HDD1, HDD1_BASE, 0, 0, 0, 0, 0, config.hdd1_name }
|
||||
};
|
||||
|
||||
static int hdd_set(uint32_t num)
|
||||
{
|
||||
hdd[num].hd_cylinders = 0;
|
||||
hdd[num].hd_heads = 0;
|
||||
hdd[num].hd_spt = 0;
|
||||
hdd[num].hd_total_sectors = 0;
|
||||
|
||||
hdd[num].present = img_mount(hdd[num].type, hdd[num].name);
|
||||
if (!hdd[num].present) return 0;
|
||||
|
||||
hdd[num].hd_heads = 16;
|
||||
hdd[num].hd_spt = 63;
|
||||
hdd[num].hd_cylinders = get_image(hdd[num].type)->size / (hdd[num].hd_heads * hdd[num].hd_spt * 512);
|
||||
|
||||
//Maximum 8GB images are supported.
|
||||
if (hdd[num].hd_cylinders > 16383) hdd[num].hd_cylinders = 16383;
|
||||
hdd[num].hd_total_sectors = hdd[num].hd_spt*hdd[num].hd_heads*hdd[num].hd_cylinders;
|
||||
|
||||
/*
|
||||
0x00.[31:0]: identify write
|
||||
0x01.[16:0]: media cylinders
|
||||
0x02.[4:0]: media heads
|
||||
0x03.[8:0]: media spt
|
||||
0x04.[13:0]: media sectors per cylinder = spt * heads
|
||||
0x05.[31:0]: media sectors total
|
||||
0x06.[31:0]: media sd base
|
||||
*/
|
||||
|
||||
uint32_t identify[256] =
|
||||
{
|
||||
0x0040, //word 0
|
||||
hdd[num].hd_cylinders, //word 1
|
||||
0x0000, //word 2 reserved
|
||||
hdd[num].hd_heads, //word 3
|
||||
(uint16_t)(512 * hdd[num].hd_spt), //word 4
|
||||
512, //word 5
|
||||
hdd[num].hd_spt, //word 6
|
||||
0x0000, //word 7 vendor specific
|
||||
0x0000, //word 8 vendor specific
|
||||
0x0000, //word 9 vendor specific
|
||||
('A' << 8) | 'O', //word 10
|
||||
('H' << 8) | 'D', //word 11
|
||||
('0' << 8) | '0', //word 12
|
||||
('0' << 8) | '0', //word 13
|
||||
('0' << 8) | ' ', //word 14
|
||||
(' ' << 8) | ' ', //word 15
|
||||
(' ' << 8) | ' ', //word 16
|
||||
(' ' << 8) | ' ', //word 17
|
||||
(' ' << 8) | ' ', //word 18
|
||||
(' ' << 8) | ' ', //word 19
|
||||
3, //word 20 buffer type
|
||||
512, //word 21 cache size
|
||||
4, //word 22 number of ecc bytes
|
||||
0,0,0,0, //words 23..26 firmware revision
|
||||
(' ' << 8) | ' ', //words 27..46 model number
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
(' ' << 8) | ' ',
|
||||
16, //word 47 max multiple sectors
|
||||
1, //word 48 dword io
|
||||
1 << 9, //word 49 lba supported
|
||||
0x0000, //word 50 reserved
|
||||
0x0200, //word 51 pio timing
|
||||
0x0200, //word 52 pio timing
|
||||
0x0007, //word 53 valid fields
|
||||
hdd[num].hd_cylinders, //word 54
|
||||
hdd[num].hd_heads, //word 55
|
||||
hdd[num].hd_spt, //word 56
|
||||
hdd[num].hd_total_sectors & 0xFFFF, //word 57
|
||||
hdd[num].hd_total_sectors >> 16, //word 58
|
||||
0x0000, //word 59 multiple sectors
|
||||
hdd[num].hd_total_sectors & 0xFFFF, //word 60
|
||||
hdd[num].hd_total_sectors >> 16, //word 61
|
||||
0x0000, //word 62 single word dma modes
|
||||
0x0000, //word 63 multiple word dma modes
|
||||
0x0000, //word 64 pio modes
|
||||
120,120,120,120, //word 65..68
|
||||
0,0,0,0,0,0,0,0,0,0,0, //word 69..79
|
||||
0x007E, //word 80 ata modes
|
||||
0x0000, //word 81 minor version number
|
||||
1 << 14, //word 82 supported commands
|
||||
(1 << 14) | (1 << 13) | (1 << 12) | (1 << 10), //word 83
|
||||
1 << 14, //word 84
|
||||
1 << 14, //word 85
|
||||
(1 << 14) | (1 << 13) | (1 << 12) | (1 << 10), //word 86
|
||||
1 << 14, //word 87
|
||||
0x0000, //word 88
|
||||
0,0,0,0, //word 89..92
|
||||
1 | (1 << 14) | 0x2000, //word 93
|
||||
0,0,0,0,0,0, //word 94..99
|
||||
hdd[num].hd_total_sectors & 0xFFFF, //word 100
|
||||
hdd[num].hd_total_sectors >> 16, //word 101
|
||||
0, //word 102
|
||||
0, //word 103
|
||||
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,//word 104..127
|
||||
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, //word 128..255
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
if (hdd[num].present)
|
||||
{
|
||||
char *name = get_image(hdd[num].type)->name;
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
if (*name) identify[27 + i] = ((*name++) << 8) | 0x20;
|
||||
if (*name) identify[27 + i] = (identify[27 + i] & 0xFF00) | (*name++);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i<128; i++) IOWR(hdd[num].base, 0, hdd[num].present ? ((unsigned int)identify[2 * i + 1] << 16) | (unsigned int)identify[2 * i + 0] : 0);
|
||||
|
||||
IOWR(hdd[num].base, 1, hdd[num].hd_cylinders);
|
||||
IOWR(hdd[num].base, 2, hdd[num].hd_heads);
|
||||
IOWR(hdd[num].base, 3, hdd[num].hd_spt);
|
||||
IOWR(hdd[num].base, 4, hdd[num].hd_spt * hdd[num].hd_heads);
|
||||
IOWR(hdd[num].base, 5, hdd[num].hd_spt * hdd[num].hd_heads * hdd[num].hd_cylinders);
|
||||
IOWR(hdd[num].base, 6, 0); // base LBA
|
||||
|
||||
printf("HDD%d:\n present %d\n hd_cylinders %d\n hd_heads %d\n hd_spt %d\n hd_total_sectors %d\n\n", num, hdd[num].present, hdd[num].hd_cylinders, hdd[num].hd_heads, hdd[num].hd_spt, hdd[num].hd_total_sectors);
|
||||
return hdd[num].present;
|
||||
}
|
||||
|
||||
static uint8_t bin2bcd(unsigned val)
|
||||
{
|
||||
return ((val / 10) << 4) + (val % 10);
|
||||
}
|
||||
|
||||
void x86_init()
|
||||
{
|
||||
user_io_8bit_set_status(UIO_STATUS_RESET, UIO_STATUS_RESET);
|
||||
|
||||
load_bios("ao486/boot0.rom", 0);
|
||||
load_bios("ao486/boot1.rom", 1);
|
||||
|
||||
IOWR(PC_BUS_BASE, 0, 0x00FFF0EA);
|
||||
IOWR(PC_BUS_BASE, 1, 0x000000F0);
|
||||
|
||||
//-------------------------------------------------------------------------- sound
|
||||
/*
|
||||
0-255.[15:0]: cycles in period
|
||||
256.[12:0]: cycles in 80us
|
||||
257.[9:0]: cycles in 1 sample: 96000 Hz
|
||||
*/
|
||||
|
||||
double cycle_in_ns = (1000000000.0 / ALT_CPU_CPU_FREQ); //33.333333;
|
||||
for(int i=0; i<256; i++)
|
||||
{
|
||||
double f = 1000000.0 / (256.0-i);
|
||||
|
||||
double cycles_in_period = 1000000000.0 / (f * cycle_in_ns);
|
||||
IOWR(SOUND_BASE, i, (int)cycles_in_period);
|
||||
}
|
||||
|
||||
IOWR(SOUND_BASE, 256, (int)(80000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(SOUND_BASE, 257, (int)((1000000000.0/96000.0) / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
|
||||
//-------------------------------------------------------------------------- pit
|
||||
/*
|
||||
0.[7:0]: cycles in sysclock 1193181 Hz
|
||||
*/
|
||||
|
||||
IOWR(PIT_BASE, 0, (int)((1000000000.0/1193181.0) / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
|
||||
//-------------------------------------------------------------------------- floppy
|
||||
|
||||
fdd_set(config.fdd_name);
|
||||
|
||||
//-------------------------------------------------------------------------- hdd
|
||||
|
||||
hdd_set(0);
|
||||
hdd_set(1);
|
||||
|
||||
//-------------------------------------------------------------------------- rtc
|
||||
|
||||
/*
|
||||
128.[26:0]: cycles in second
|
||||
129.[12:0]: cycles in 122.07031 us
|
||||
*/
|
||||
|
||||
IOWR(RTC_BASE, 128, (int)(1000000000.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
IOWR(RTC_BASE, 129, (int)(122070.0 / (1000000000.0 / ALT_CPU_CPU_FREQ)));
|
||||
|
||||
unsigned char translate_mode = 1; //LBA
|
||||
translate_mode = (translate_mode << 6) | (translate_mode << 4) | (translate_mode << 2) | translate_mode;
|
||||
|
||||
time_t t = time(NULL);
|
||||
struct tm tm = *localtime(&t);
|
||||
|
||||
//rtc contents 0-127
|
||||
uint32_t tmp[128] = {
|
||||
bin2bcd(tm.tm_sec), //0x00: SEC BCD
|
||||
0x00, //0x01: ALARM SEC BCD
|
||||
bin2bcd(tm.tm_min), //0x02: MIN BCD
|
||||
0x00, //0x03: ALARM MIN BCD
|
||||
bin2bcd(tm.tm_hour), //0x04: HOUR BCD 24h
|
||||
0x12, //0x05: ALARM HOUR BCD 24h
|
||||
(uint32_t)tm.tm_wday+1, //0x06: DAY OF WEEK Sunday=1
|
||||
bin2bcd(tm.tm_mday), //0x07: DAY OF MONTH BCD from 1
|
||||
bin2bcd(tm.tm_mon+1), //0x08: MONTH BCD from 1
|
||||
bin2bcd((tm.tm_year<117) ? 17 : tm.tm_year-100), //0x09: YEAR BCD
|
||||
0x26, //0x0A: REG A
|
||||
0x02, //0x0B: REG B
|
||||
0x00, //0x0C: REG C
|
||||
0x80, //0x0D: REG D
|
||||
0x00, //0x0E: REG E - POST status
|
||||
0x00, //0x0F: REG F - shutdown status
|
||||
|
||||
(uint32_t)CMOS_FDD_TYPE, //0x10: floppy drive type; 0-none, 1-360K, 2-1.2M, 3-720K, 4-1.44M, 5-2.88M
|
||||
0x00, //0x11: configuration bits; not used
|
||||
0x00, //0x12: hard disk types; 0-none, 1:E-type, F-type 16+ (unused)
|
||||
0x00, //0x13: advanced configuration bits; not used
|
||||
0x0D, //0x14: equipment bits
|
||||
0x80, //0x15: base memory in 1k LSB
|
||||
0x02, //0x16: base memory in 1k MSB
|
||||
0x00, //0x17: memory size above 1m in 1k LSB
|
||||
0xFC, //0x18: memory size above 1m in 1k MSB
|
||||
0x00, //0x19: extended hd types 1/2; type 47d (unused)
|
||||
0x00, //0x1A: extended hd types 2/2 (unused)
|
||||
|
||||
//these hd parameters aren't used anymore
|
||||
0x00, //0x1B: hd 0 configuration 1/9; cylinders low
|
||||
0x00, //0x1C: hd 0 configuration 2/9; cylinders high
|
||||
0x00, //0x1D: hd 0 configuration 3/9; heads
|
||||
0x00, //0x1E: hd 0 configuration 4/9; write pre-comp low
|
||||
0x00, //0x1F: hd 0 configuration 5/9; write pre-comp high
|
||||
0x00, //0x20: hd 0 configuration 6/9; retries/bad map/heads>8
|
||||
0x00, //0x21: hd 0 configuration 7/9; landing zone low
|
||||
0x00, //0x22: hd 0 configuration 8/9; landing zone high
|
||||
0x00, //0x23: hd 0 configuration 9/9; sectors/track
|
||||
0x00, //0x24: hd 1 configuration 1/9; cylinders low
|
||||
0x00, //0x25: hd 1 configuration 2/9; cylinders high
|
||||
0x00, //0x26: hd 1 configuration 3/9; heads
|
||||
0x00, //0x27: hd 1 configuration 4/9; write pre-comp low
|
||||
0x00, //0x28: hd 1 configuration 5/9; write pre-comp high
|
||||
0x00, //0x29: hd 1 configuration 6/9; retries/bad map/heads>8
|
||||
0x00, //0x2A: hd 1 configuration 7/9; landing zone low
|
||||
0x00, //0x2B: hd 1 configuration 8/9; landing zone high
|
||||
0x00, //0x2C: hd 1 configuration 9/9; sectors/track
|
||||
|
||||
(boot_from_floppy)? 0x20u : 0x00u, //0x2D: boot sequence
|
||||
|
||||
0x00, //0x2E: checksum MSB
|
||||
0x00, //0x2F: checksum LSB
|
||||
|
||||
0x00, //0x30: memory size above 1m in 1k LSB
|
||||
0xFC, //0x31: memory size above 1m in 1k MSB
|
||||
|
||||
0x20, //0x32: IBM century
|
||||
0x00, //0x33: ?
|
||||
|
||||
0x00, //0x34: memory size above 16m in 64k LSB
|
||||
0x07, //0x35: memory size above 16m in 64k MSB; 128 MB
|
||||
|
||||
0x00, //0x36: ?
|
||||
0x20, //0x37: IBM PS/2 century
|
||||
|
||||
0x00, //0x38: eltorito boot sequence; not used
|
||||
translate_mode, //0x39: ata translation policy 1-4
|
||||
0x00, //0x3A: ata translation policy 5-8
|
||||
|
||||
0x00, //0x3B: ?
|
||||
0x00, //0x3C: ?
|
||||
|
||||
0x00, //0x3D: eltorito boot sequence; not used
|
||||
|
||||
0x00, //0x3E: ?
|
||||
0x00, //0x3F: ?
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
memcpy(cmos, tmp, sizeof(cmos));
|
||||
|
||||
//count checksum
|
||||
unsigned short sum = 0;
|
||||
for(int i=0x10; i<=0x2D; i++) sum += cmos[i];
|
||||
|
||||
cmos[0x2E] = sum >> 8;
|
||||
cmos[0x2F] = sum & 0xFF;
|
||||
|
||||
for(unsigned int i=0; i<sizeof(cmos)/sizeof(unsigned int); i++) IOWR(RTC_BASE, i, cmos[i]);
|
||||
|
||||
user_io_8bit_set_status(0, UIO_STATUS_RESET);
|
||||
}
|
||||
|
||||
struct sd_param_t
|
||||
{
|
||||
uint32_t addr;
|
||||
uint32_t lba;
|
||||
uint32_t bl_cnt;
|
||||
};
|
||||
|
||||
static struct sd_param_t sd_params = { 0 };
|
||||
|
||||
void x86_poll()
|
||||
{
|
||||
int res = 0;
|
||||
static uint32_t secbuf[128 * 4];
|
||||
|
||||
char sd_req = dma_sdio(0);
|
||||
if (sd_req == 1)
|
||||
{
|
||||
dma_rcvbuf(SD_BASE + (4 << 2), sizeof(sd_params) >> 2, (uint32_t*)&sd_params);
|
||||
//printf("Read: 0x%08x, 0x%08x, %d\n", sd_params.addr, sd_params.lba, sd_params.bl_cnt);
|
||||
|
||||
if (get_image(sd_params.addr)->size)
|
||||
{
|
||||
if (sd_params.bl_cnt>0 && sd_params.bl_cnt<=4)
|
||||
{
|
||||
if (img_read(sd_params.addr, sd_params.lba, secbuf, sd_params.bl_cnt * 512))
|
||||
{
|
||||
dma_sendbuf(sd_params.addr, sd_params.bl_cnt * 128, secbuf);
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: Block count %d is out of range 1..4.\n", sd_params.bl_cnt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: image is not ready.\n");
|
||||
}
|
||||
|
||||
dma_sdio(res ? 1 : 2);
|
||||
}
|
||||
else if (sd_req == 2)
|
||||
{
|
||||
dma_rcvbuf(SD_BASE + (4 << 2), sizeof(sd_params) >> 2, (uint32_t*)&sd_params);
|
||||
//printf("Write: 0x%08x, 0x%08x, %d\n", sd_params.addr, sd_params.lba, sd_params.bl_cnt);
|
||||
|
||||
if (get_image(sd_params.addr)->size)
|
||||
{
|
||||
if (sd_params.bl_cnt>0 && sd_params.bl_cnt <= 4)
|
||||
{
|
||||
if (get_image(sd_params.addr)->mode & O_RDWR)
|
||||
{
|
||||
dma_rcvbuf(sd_params.addr, sd_params.bl_cnt * 128, secbuf);
|
||||
if (img_write(sd_params.addr, sd_params.lba, secbuf, sd_params.bl_cnt * 512))
|
||||
{
|
||||
res = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: image is read-only.\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: Block count %d is out of range 1..4.\n", sd_params.bl_cnt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Error: image is not ready.\n");
|
||||
}
|
||||
|
||||
dma_sdio(res ? 1 : 2);
|
||||
}
|
||||
}
|
||||
|
||||
void x86_set_image(int num, char *filename)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
case 0:
|
||||
strcpy(config.fdd_name, filename);
|
||||
fdd_set(filename);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
strcpy(config.hdd0_name, filename);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
strcpy(config.hdd1_name, filename);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void x86_config_save()
|
||||
{
|
||||
config.ver = CFG_VER;
|
||||
FileSaveConfig("ao486sys.cfg", &config, sizeof(config));
|
||||
}
|
||||
|
||||
void x86_config_load()
|
||||
{
|
||||
static x86_config tmp;
|
||||
memset(&config, 0, sizeof(config));
|
||||
if (FileLoadConfig("ao486sys.cfg", &tmp, sizeof(tmp)) && (tmp.ver == CFG_VER))
|
||||
{
|
||||
memcpy(&config, &tmp, sizeof(config));
|
||||
}
|
||||
}
|
||||
|
||||
void x86_set_fdd_boot(uint32_t boot)
|
||||
{
|
||||
boot_from_floppy = (boot != 0);
|
||||
}
|
||||
13
support/x86/x86.h
Normal file
13
support/x86/x86.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef X86_H
|
||||
#define X86_H
|
||||
|
||||
void x86_init();
|
||||
void x86_poll();
|
||||
|
||||
void x86_set_image(int num, char *filename);
|
||||
|
||||
void x86_config_load();
|
||||
void x86_config_save();
|
||||
void x86_set_fdd_boot(uint32_t boot);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user