1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-04-28 13:08:19 +00:00

Config save, ikbd timer and more

This commit is contained in:
harbaum
2013-08-30 18:32:30 +00:00
parent 04ff9833d8
commit ffefe19116
10 changed files with 339 additions and 191 deletions

View File

@@ -27,7 +27,7 @@
// -------------- TOS debugging --------------
#if 0
#define tos_debugf(...) iprintf(__VA_ARGS__)
#define tos_debugf(a, ...) iprintf("\033[1;32mTOS: " a "\033[0m\n", ##__VA_ARGS__)
#else
#define tos_debugf(...)
#endif

View File

@@ -239,9 +239,54 @@ unsigned long CheckButton(void)
#endif
}
void Timer_Init(void)
{
*AT91C_PITC_PIMR = AT91C_PITC_PITEN | ((MCLK / 16 / 1000 - 1) & AT91C_PITC_PIV); // counting period 1ms
void timer0_c_irq_handler(void) {
//* Acknowledge interrupt status
unsigned int dummy = AT91C_BASE_TC0->TC_SR;
ikbd_update_time();
}
void Timer_Init(void) {
unsigned int dummy;
//* Open timer0
AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_TC0;
//* Disable the clock and the interrupts
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS ;
AT91C_BASE_TC0->TC_IDR = 0xFFFFFFFF ;
//* Clear status bit
dummy = AT91C_BASE_TC0->TC_SR;
//* Set the Mode of the Timer Counter
AT91C_BASE_TC0->TC_CMR = 0x04; // :1024
//* Enable the clock
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKEN ;
//* Open Timer 0 interrupt
//* Disable the interrupt on the interrupt controller
AT91C_BASE_AIC->AIC_IDCR = 1 << AT91C_ID_TC0;
//* Save the interrupt handler routine pointer and the interrupt priority
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (unsigned int)timer0_c_irq_handler;
//* Store the Source Mode Register
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 1 | AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL;
//* Clear the interrupt on the interrupt controller
AT91C_BASE_AIC->AIC_ICCR = 1 << AT91C_ID_TC0;
AT91C_BASE_TC0->TC_IER = AT91C_TC_CPCS; // IRQ enable CPC
AT91C_BASE_AIC->AIC_IECR = 1 << AT91C_ID_TC0;
//* Start timer0
AT91C_BASE_TC0->TC_CCR = AT91C_TC_SWTRG ;
*AT91C_PITC_PIMR = AT91C_PITC_PITEN | ((MCLK / 16 / 1000 - 1) & AT91C_PITC_PIV); // counting period 1ms
}
// 12 bits accuracy at 1ms = 4096 ms

86
ikbd.c
View File

@@ -1,5 +1,6 @@
/*
http://removers.free.fr/wikipendium/wakka.php?wiki=IntelligentKeyboardBible
https://www.kernel.org/doc/Documentation/input/atarikbd.txt
ikbd ToDo:
@@ -51,6 +52,7 @@ static struct {
// joystick state
unsigned char joystick[2];
unsigned char date_buffer[6];
// mouse state
unsigned short mouse_abs_max_x, mouse_abs_max_y;
@@ -68,6 +70,14 @@ void ikbd_init() {
ikbd.mouse_abs_max_x = ikbd.mouse_abs_max_y = 65535;
ikbd.mouse_abs_scale_x = ikbd.mouse_abs_scale_y = 1;
// init ikbd date
ikbd.date_buffer[0] = 113;
ikbd.date_buffer[1] = 7;
ikbd.date_buffer[2] = 20;
ikbd.date_buffer[3] = 20;
ikbd.date_buffer[4] = 58;
ikbd.date_buffer[5] = 0;
}
static void enqueue(unsigned short b) {
@@ -93,6 +103,14 @@ static unsigned char joystick_map2ikbd(unsigned in) {
return out;
}
unsigned char bcd2bin(unsigned char in) {
return 10*(in >> 4) + (in & 0x0f);
}
unsigned char bin2bcd(unsigned char in) {
return 16*(in/10) + (in % 10);
}
// process inout from atari core into ikbd
void ikbd_handle_input(unsigned char cmd) {
// expecting a second byte for command
@@ -137,6 +155,15 @@ void ikbd_handle_input(unsigned char cmd) {
ikbd_debugf("absolute scale = %u/%u", ikbd.mouse_abs_scale_x, ikbd.mouse_abs_scale_y);
break;
case 0x1b:
ikbd.date_buffer[5-ikbd.expect] = bcd2bin(cmd);
if(!ikbd.expect) {
ikbd_debugf("time/date = %u:%u:%u %u.%u.%u",
ikbd.date_buffer[3], ikbd.date_buffer[4], ikbd.date_buffer[5],
ikbd.date_buffer[2], ikbd.date_buffer[1], 1900 + ikbd.date_buffer[0]);
}
break;
case 0x80: // ibkd reset
// reply "everything is ok"
enqueue(0x8000 + 100); // wait 100ms
@@ -252,15 +279,17 @@ void ikbd_handle_input(unsigned char cmd) {
case 0x1c:
ikbd_debugf("Interrogate time of day");
ikbd_debugf("time/date = %u:%u:%u %u.%u.%u",
ikbd.date_buffer[3], ikbd.date_buffer[4], ikbd.date_buffer[5],
ikbd.date_buffer[2], ikbd.date_buffer[1], 1900 + ikbd.date_buffer[0]);
enqueue(0x8000 + 64); // wait 64ms
enqueue(0xfc);
enqueue(0xb3); // year bcd
enqueue(0x03); // month bcd
enqueue(0x07); // day bcd
enqueue(0x20); // hour bcd
enqueue(0x58); // minute bcd
enqueue(0x00); // second bcd
{
int i;
for(i=0;i<6;i++)
enqueue(bin2bcd(ikbd.date_buffer[i]));
}
break;
@@ -467,3 +496,48 @@ void ikbd_mouse(unsigned char b, char x, char y) {
enqueue(y & 0xff);
}
}
// advance the ikbd time by one second
void ikbd_update_time(void) {
static const char mdays[] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
short year = 1900 + ikbd.date_buffer[0];
char is_leap = (!(year % 4) && (year % 100)) || !(year % 400);
ikbd_debugf("time update %u:%02u:%02u %u.%u.%u",
ikbd.date_buffer[3], ikbd.date_buffer[4], ikbd.date_buffer[5],
ikbd.date_buffer[2], ikbd.date_buffer[1], year);
// advance seconds
ikbd.date_buffer[5]++;
if(ikbd.date_buffer[5] == 60) {
ikbd.date_buffer[5] = 0;
// advance minutes
ikbd.date_buffer[4]++;
if(ikbd.date_buffer[4] == 60) {
ikbd.date_buffer[4] = 0;
// advance hours
ikbd.date_buffer[3]++;
if(ikbd.date_buffer[3] == 24) {
ikbd.date_buffer[3] = 0;
// advance days
ikbd.date_buffer[2]++;
if((ikbd.date_buffer[2] == mdays[ikbd.date_buffer[1]-1]+1) ||
(is_leap && (ikbd.date_buffer[1] == 2) && (ikbd.date_buffer[2] == 29))) {
ikbd.date_buffer[2] = 1;
// advance month
ikbd.date_buffer[1]++;
if(ikbd.date_buffer[1] == 13) {
ikbd.date_buffer[1] = 0;
// advance year
ikbd.date_buffer[0]++;
}
}
}
}
}
}

1
ikbd.h
View File

@@ -6,5 +6,6 @@ void ikbd_poll(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);
void ikbd_update_time(void);
#endif // IKBD_H

View File

@@ -262,18 +262,6 @@ const unsigned short usb2atari[] = {
MISS // 6f: F20
};
// OSD uses amiga keycodes. This table translates from usb to OSD/amiga
// const unsigned char usb2osd[][2] = {
// { 0x45, KEY_MENU },
// { 0x65, KEY_MENU },
// { 0x52, KEY_UP },
// { 0x51, KEY_DOWN },
// { 0x28, KEY_ENTER },
// { 0x29, KEY_ESC },
// { 0x2c, KEY_SPACE },
// { 0,0 }
// };
#if 0
// #define KEY_UPSTROKE 0x80
#define KEY_MENU 0x69

2
main.c
View File

@@ -150,6 +150,8 @@ int main(void)
user_io_init();
tos_config_init();
fpga_init(NULL);
while (1) {

105
menu.c
View File

@@ -303,29 +303,29 @@ void HandleUI(void)
/******************************************************************/
case MENU_MIST_MAIN1 :
menumask=0x7f;
menumask=0xff;
OsdSetTitle("Mist", 0);
// most important: main page has setup for floppy A: and screen
strcpy(s, " A: ");
strcat(s, tos_get_disk_name(0));
if(tos_system_ctrl & TOS_CONTROL_FDC_WR_PROT_A) strcat(s, " \x17");
if(tos_system_ctrl() & TOS_CONTROL_FDC_WR_PROT_A) strcat(s, " \x17");
OsdWrite(0, s, menusub == 0,0);
strcpy(s, " Screen: ");
if(tos_system_ctrl & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color");
if(tos_system_ctrl() & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color");
else strcat(s, "Mono");
OsdWrite(1, s, menusub == 1,0);
OsdWrite(2, "", 0,0);
/* everything else is in submenus */
OsdWrite(3, " Storage \x16", menusub == 2,0);
OsdWrite(4, " System \x16", menusub == 3,0);
OsdWrite(5, " Audio / Video \x16", menusub == 4,0);
OsdWrite(6, " Firmware & Core \x16", menusub == 5,0);
OsdWrite(2, " Storage \x16", menusub == 2,0);
OsdWrite(3, " System \x16", menusub == 3,0);
OsdWrite(4, " Audio / Video \x16", menusub == 4,0);
OsdWrite(5, " Firmware & Core \x16", menusub == 5,0);
OsdWrite(7, STD_EXIT, menusub == 6,0);
OsdWrite(6, " Save config ", menusub == 6,0);
OsdWrite(7, STD_EXIT, menusub == 7,0);
menustate = MENU_MIST_MAIN2;
parentstate=MENU_MIST_MAIN1;
@@ -346,7 +346,7 @@ void HandleUI(void)
break;
case 1:
tos_update_sysctrl(tos_system_ctrl ^ TOS_CONTROL_VIDEO_COLOR);
tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_VIDEO_COLOR);
menustate = MENU_MIST_MAIN1;
break;
@@ -370,11 +370,15 @@ void HandleUI(void)
menusub = 1;
break;
case 6: // Exit
case 6: // Save config
menustate = MENU_NONE1;
tos_config_save();
break;
case 7: // Exit
menustate = MENU_NONE1;
break;
}
}
break;
@@ -392,14 +396,14 @@ void HandleUI(void)
strcpy(s, " A: ");
strcat(s, tos_get_disk_name(i));
s[1] = 'A'+i;
if(tos_system_ctrl & (TOS_CONTROL_FDC_WR_PROT_A << i))
if(tos_system_ctrl() & (TOS_CONTROL_FDC_WR_PROT_A << i))
strcat(s, " \x17");
OsdWrite(i, s, menusub == i,0);
}
strcpy(s, " Write protect: ");
strcat(s, config_tos_wrprot[(tos_system_ctrl >> 6)&3]);
strcat(s, config_tos_wrprot[(tos_system_ctrl() >> 6)&3]);
OsdWrite(2, s, menusub == 2,0);
OsdWrite(3, "", 0, 0);
@@ -437,8 +441,8 @@ void HandleUI(void)
else if(menusub == 2) {
// remove current write protect bits and increase by one
tos_update_sysctrl((tos_system_ctrl & ~(TOS_CONTROL_FDC_WR_PROT_A | TOS_CONTROL_FDC_WR_PROT_B))
| (((((tos_system_ctrl >> 6)&3) + 1)&3)<<6) );
tos_update_sysctrl((tos_system_ctrl() & ~(TOS_CONTROL_FDC_WR_PROT_A | TOS_CONTROL_FDC_WR_PROT_B))
| (((((tos_system_ctrl() >> 6)&3) + 1)&3)<<6) );
menustate = MENU_MIST_STORAGE1;
} else if((menusub == 3) || (menusub == 4)) {
@@ -465,15 +469,20 @@ void HandleUI(void)
break;
case MENU_MIST_SYSTEM1 :
#ifdef ENABLE_TURBO
menumask=0xff;
#else
menumask=0x7f;
#endif
OsdSetTitle("System", 0);
strcpy(s, " Memory: ");
strcat(s, config_tos_mem[(tos_system_ctrl >> 1)&7]);
strcat(s, config_tos_mem[(tos_system_ctrl() >> 1)&7]);
OsdWrite(0, s, menusub == 0,0);
strcpy(s, " CPU: ");
strcat(s, config_cpu_msg[(tos_system_ctrl >> 4)&3]);
strcat(s, config_cpu_msg[(tos_system_ctrl() >> 4)&3]);
OsdWrite(1, s, menusub == 1, 0);
strcpy(s, " TOS: ");
@@ -484,14 +493,25 @@ void HandleUI(void)
strcat(s, tos_get_cartridge_name());
OsdWrite(3, s, menusub == 3, 0);
#ifdef ENABLE_TURBO
strcpy(s, " Turbo: ");
strcat(s, (tos_system_ctrl & TOS_CONTROL_TURBO)?"on":"off");
strcat(s, (tos_system_ctrl() & TOS_CONTROL_TURBO)?"on":"off");
OsdWrite(4, s, menusub == 4, 0);
OsdWrite(5, " Reset", menusub == 5, 0);
OsdWrite(6, " Cold boot", menusub == 6, 0);
OsdWrite(7, STD_EXIT, menusub == 7,0);
#else
strcpy(s, " Turbo: ");
strcat(s, (tos_system_ctrl() & TOS_CONTROL_TURBO)?"on":"off");
OsdWrite(4, s, 0, 1);
OsdWrite(5, " Reset", menusub == 4, 0);
OsdWrite(6, " Cold boot", menusub == 5, 0);
OsdWrite(7, STD_EXIT, menusub == 6,0);
#endif
parentstate = menustate;
menustate = MENU_MIST_SYSTEM2;
@@ -505,19 +525,19 @@ void HandleUI(void)
if(select) {
switch(menusub) {
case 0: { // RAM
int mem = (tos_system_ctrl >> 1)&7; // current memory config
int mem = (tos_system_ctrl() >> 1)&7; // current memory config
mem++;
if(mem > 5) mem = 3; // cycle 4MB/8MB/14MB
tos_update_sysctrl((tos_system_ctrl & ~0x0e) | (mem<<1) );
tos_update_sysctrl((tos_system_ctrl() & ~0x0e) | (mem<<1) );
tos_reset(1);
menustate = MENU_MIST_SYSTEM1;
} break;
case 1: { // CPU
int cpu = (tos_system_ctrl >> 4)&3; // current cpu config
int cpu = (tos_system_ctrl() >> 4)&3; // current cpu config
cpu = (cpu+1)&3;
if(cpu == 2) cpu = 3; // skip unused config
tos_update_sysctrl((tos_system_ctrl & ~0x30) | (cpu<<4) );
tos_update_sysctrl((tos_system_ctrl() & ~0x30) | (cpu<<4) );
tos_reset(0);
menustate = MENU_MIST_SYSTEM1;
} break;
@@ -535,8 +555,9 @@ void HandleUI(void)
SelectFile("IMG", SCAN_LFN, MENU_MIST_SYSTEM_FILE_SELECTED, MENU_MIST_SYSTEM1);
break;
#ifdef ENABLE_TURBO
case 4:
tos_update_sysctrl(tos_system_ctrl ^ TOS_CONTROL_TURBO );
tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_TURBO );
menustate = MENU_MIST_SYSTEM1;
break;
@@ -553,6 +574,24 @@ void HandleUI(void)
case 7:
menustate = MENU_MIST_MAIN1;
menusub = 3;
break;
#else
case 4: // Reset
tos_reset(0);
menustate = MENU_NONE1;
break;
case 5: // Cold Boot
tos_reset(1);
menustate = MENU_NONE1;
break;
case 6:
menustate = MENU_MIST_MAIN1;
menusub = 3;
break;
#endif
}
}
break;
@@ -575,16 +614,16 @@ void HandleUI(void)
OsdSetTitle("A/V", 0);
strcpy(s, " PAL mode: ");
if(tos_system_ctrl & TOS_CONTROL_PAL50HZ) strcat(s, "50Hz");
if(tos_system_ctrl() & TOS_CONTROL_PAL50HZ) strcat(s, "50Hz");
else strcat(s, "56Hz");
OsdWrite(0, s, menusub == 0,0);
strcpy(s, " Blitter: ");
strcat(s, (tos_system_ctrl & TOS_CONTROL_BLITTER)?"on":"off");
strcat(s, (tos_system_ctrl() & TOS_CONTROL_BLITTER)?"on":"off");
OsdWrite(1, s, menusub == 1, 0);
strcpy(s, " Screen: ");
if(tos_system_ctrl & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color");
if(tos_system_ctrl() & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color");
else strcat(s, "Mono");
OsdWrite(2, "", 0,0);
@@ -613,28 +652,28 @@ void HandleUI(void)
if(select) {
switch(menusub) {
case 0:
tos_update_sysctrl(tos_system_ctrl ^ TOS_CONTROL_PAL50HZ);
tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_PAL50HZ);
menustate = MENU_MIST_VIDEO1;
break;
case 1:
tos_update_sysctrl(tos_system_ctrl ^ TOS_CONTROL_BLITTER );
tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_BLITTER );
menustate = MENU_MIST_VIDEO1;
break;
case 2:
tos_update_sysctrl(tos_system_ctrl ^ TOS_CONTROL_VIDEO_COLOR);
tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_VIDEO_COLOR);
menustate = MENU_MIST_VIDEO1;
break;
case 3:
scan=(scan+1) & 0x3;
tos_update_sysctrl((tos_system_ctrl & 0x3fffffff) | (scan<<30));
tos_update_sysctrl((tos_system_ctrl() & 0x3fffffff) | (scan<<30));
menustate=MENU_MIST_VIDEO1;
break;
case 4:
sstereo++;
tos_update_sysctrl(tos_system_ctrl ^ 0x20000000);
tos_update_sysctrl(tos_system_ctrl() ^ 0x20000000);
menustate=MENU_MIST_VIDEO1;
break;
case 5:

227
tos.c
View File

@@ -8,19 +8,24 @@
#include "fpga.h"
#include "debug.h"
#define CONFIG_FILENAME "MIST CFG"
typedef struct {
unsigned long system_ctrl; // system control word
char tos_img[12];
char cart_img[12];
char acsi_img[2][12];
} tos_config_t;
static tos_config_t config;
#define TOS_BASE_ADDRESS_192k 0xfc0000
#define TOS_BASE_ADDRESS_256k 0xe00000
#define CART_BASE_ADDRESS 0xfa0000
#define VIDEO_BASE_ADDRESS 0x010000
unsigned long tos_system_ctrl = TOS_MEMCONFIG_4M | TOS_CONTROL_BLITTER;
static unsigned char font[2048]; // buffer for 8x16 atari font
// default name of TOS image
static char tos_img[12] = "TOS IMG";
static char cart_img[12] = "";
// two floppies
static struct {
fileTYPE file;
@@ -173,9 +178,9 @@ static void handle_acsi(unsigned char *buffer) {
unsigned short length = buffer[13];
if(length == 0) length = 256;
tos_debugf("ACSI: target %d, \"%s\"\n", target, acsi_cmd_name(cmd));
tos_debugf("ACSI: lba %lu, length %u\n", lba, length);
tos_debugf("DMA: scnt %u, addr %p\n", scnt, dma_address);
tos_debugf("ACSI: target %d, \"%s\"", target, acsi_cmd_name(cmd));
tos_debugf("ACSI: lba %lu, length %u", lba, length);
tos_debugf("DMA: scnt %u, addr %p", scnt, dma_address);
// only a harddisk on ACSI 0 is supported
// ACSI 0 is only supported if a image is loaded
@@ -206,7 +211,7 @@ static void handle_acsi(unsigned char *buffer) {
break;
case 0x12: // inquiry
tos_debugf("ACSI: Inquiry %11s\n", hdd_image[target].name);
tos_debugf("ACSI: Inquiry %11s", hdd_image[target].name);
memset(dma_buffer, 0, 512);
dma_buffer[2] = 1; // ANSI version
dma_buffer[4] = length-8; // len
@@ -218,7 +223,7 @@ static void handle_acsi(unsigned char *buffer) {
case 0x1a: // mode sense
{ unsigned int blocks = hdd_image[target].size / 512;
tos_debugf("ACSI: mode sense, blocks = %u\n", blocks);
tos_debugf("ACSI: mode sense, blocks = %u", blocks);
memset(dma_buffer, 0, 512);
dma_buffer[3] = 8; // size of extent descriptor list
dma_buffer[5] = blocks >> 16;
@@ -230,11 +235,11 @@ static void handle_acsi(unsigned char *buffer) {
break;
default:
tos_debugf("ACSI: Unsupported command\n");
tos_debugf("ACSI: Unsupported command");
break;
}
} else
tos_debugf("ACSI: Request for unsupported target\n");
tos_debugf("ACSI: Request for unsupported target");
EnableFpga();
SPI(MIST_ACK_DMA);
@@ -414,19 +419,18 @@ void tos_load_cartridge(char *name) {
fileTYPE file;
if(name)
strncpy(cart_img, name, 11);
strncpy(config.cart_img, name, 11);
// upload cartridge
if(cart_img[0] && FileOpen(&file, cart_img)) {
if(config.cart_img[0] && FileOpen(&file, config.cart_img)) {
int i;
char buffer[512];
tos_debugf("%s:\n size = %d\n", cart_img, file.size);
tos_debugf("%s:\n size = %d", config.cart_img, file.size);
int blocks = file.size / 512;
tos_debugf(" blocks = %d\n", blocks);
tos_debugf(" blocks = %d", blocks);
tos_debugf("Uploading: [");
mist_memory_set_address(CART_BASE_ADDRESS);
DISKLED_ON;
@@ -434,37 +438,35 @@ void tos_load_cartridge(char *name) {
FileRead(&file, buffer);
mist_memory_write(buffer, 256);
if(!(i & 7)) tos_debugf(".");
if(i != blocks-1)
FileNextSector(&file);
}
DISKLED_OFF;
tos_debugf("]\n");
tos_debugf("%s uploaded\r", cart_img);
tos_debugf("%s uploaded", config.cart_img);
return;
}
// erase that ram area to remove any previously uploaded
// image
tos_debugf("Erasing cart memory\n");
tos_debugf("Erasing cart memory");
mist_memory_set_address(CART_BASE_ADDRESS);
mist_memory_set(0, 128*1024/2);
}
char tos_cartridge_is_inserted() {
return cart_img[0];
return config.cart_img[0];
}
void tos_upload(char *name) {
fileTYPE file;
if(name)
strncpy(tos_img, name, 11);
strncpy(config.tos_img, name, 11);
// put cpu into reset
tos_system_ctrl |= TOS_CONTROL_CPU_RESET;
mist_set_control(tos_system_ctrl);
config.system_ctrl |= TOS_CONTROL_CPU_RESET;
mist_set_control(config.system_ctrl);
tos_font_load();
tos_clr();
@@ -474,29 +476,28 @@ void tos_upload(char *name) {
// do the MiST core handling
tos_write("\x0e\x0f MIST core \x0e\x0f ");
tos_write("Uploading TOS ... ");
tos_debugf("Uploading TOS ...\n");
tos_debugf("Uploading TOS ...");
DISKLED_ON;
// upload and verify tos image
fileTYPE file;
if(FileOpen(&file, tos_img)) {
if(FileOpen(&file, config.tos_img)) {
int i;
char buffer[512];
unsigned long time;
unsigned long tos_base = TOS_BASE_ADDRESS_192k;
tos_debugf("TOS.IMG:\n size = %d\n", file.size);
tos_debugf("TOS.IMG:\n size = %d", file.size);
if(file.size >= 256*1024)
tos_base = TOS_BASE_ADDRESS_256k;
else if(file.size != 192*1024)
tos_debugf("WARNING: Unexpected TOS size!\n");
tos_debugf("WARNING: Unexpected TOS size!");
int blocks = file.size / 512;
tos_debugf(" blocks = %d\n", blocks);
tos_debugf(" blocks = %d", blocks);
tos_debugf(" address = $%08x\n", tos_base);
tos_debugf(" address = $%08x", tos_base);
// clear first 16k
mist_memory_set_address(0);
@@ -561,7 +562,7 @@ void tos_upload(char *name) {
#endif
time = GetTimer(0);
tos_debugf("Uploading: [");
tos_debugf("Uploading ...");
for(i=0;i<blocks;i++) {
FileRead(&file, buffer);
@@ -579,66 +580,17 @@ void tos_upload(char *name) {
mist_memory_write(buffer, 256);
if(!(i & 7)) tos_debugf(".");
if(i != blocks-1)
FileNextSector(&file);
}
tos_debugf("]\n");
time = GetTimer(0) - time;
tos_debugf("TOS.IMG uploaded in %lu ms (%d kB/s / %d kBit/s)\r",
tos_debugf("TOS.IMG uploaded in %lu ms (%d kB/s / %d kBit/s)",
time >> 20, file.size/(time >> 20), 8*file.size/(time >> 20));
} else
tos_debugf("Unable to find tos.img\n");
tos_debugf("Unable to find tos.img");
#if 0
{
char rx[512], buffer[512];
int i,j;
int blocks = file.size / 512;
FileSeek(&file, 0, SEEK_SET);
mist_memory_set_address(TOS_BASE_ADDRESS);
tos_debugf("Verifying: [");
for(i=0;i<blocks;i++) {
FileRead(&file, buffer);
mist_memory_read(rx, 256);
if(!(i & 7)) tos_debugf("+");
for(j=0;j<512;j++) {
if(buffer[j] != rx[j]) {
tos_debugf("Verify error block %d, byte %x\n", i, j);
tos_debugf("should be:\n");
hexdump(buffer, 512, 0);
tos_debugf("is:\n");
hexdump(rx, 512, 0);
// try to re-read to check whether read or write failed
mist_memory_set_address(TOS_BASE_ADDRESS+i*512);
mist_memory_read(rx, 256);
tos_debugf("re-read: %s\n", (buffer[j] != rx[j])?"failed":"ok");
hexdump(rx, 512, 0);
while(1);
}
}
if(i != blocks-1)
FileNextSector(&file);
}
tos_debugf("]\n");
}
#endif
DISKLED_OFF;
// This is the initial boot if no name was given. Otherwise the
@@ -662,17 +614,21 @@ void tos_upload(char *name) {
}
// try to open harddisk image
if(FileOpen(&file, "HARDDISKHD ")) {
tos_write("Found hard disk image ");
tos_select_hdd_image(0, &file);
for(i=0;i<2;i++) {
if(FileOpen(&file, config.acsi_img[i])) {
char msg[] = "Found hard disk image for ACSIX";
msg[30] = '0'+i;
tos_write(msg);
tos_select_hdd_image(i, &file);
}
}
}
tos_write("Booting ... ");
// let cpu run (release reset)
tos_system_ctrl &= ~TOS_CONTROL_CPU_RESET;
mist_set_control(tos_system_ctrl);
config.system_ctrl &= ~TOS_CONTROL_CPU_RESET;
mist_set_control(config.system_ctrl);
}
static unsigned long get_long(char *buffer, int offset) {
@@ -690,8 +646,8 @@ void tos_poll() {
}
void tos_update_sysctrl(unsigned long n) {
tos_system_ctrl = n;
mist_set_control(tos_system_ctrl);
config.system_ctrl = n;
mist_set_control(config.system_ctrl);
}
static char buffer[13]; // local buffer to assemble file name (8+3+2)
@@ -726,15 +682,15 @@ char *tos_get_disk_name(char index) {
}
char *tos_get_image_name() {
nice_name(buffer, tos_img);
nice_name(buffer, config.tos_img);
return buffer;
}
char *tos_get_cartridge_name() {
if(!cart_img[0]) // no cart name set
if(!config.cart_img[0]) // no cart name set
strcpy(buffer, "* no cartridge *");
else
nice_name(buffer, cart_img);
nice_name(buffer, config.cart_img);
return buffer;
}
@@ -747,19 +703,22 @@ char tos_disk_is_inserted(char index) {
}
void tos_select_hdd_image(char i, fileTYPE *file) {
tos_debugf("Select ACSI%c image %11s\n", '0'+i, file->name);
tos_debugf("Select ACSI%c image %11s", '0'+i, file->name);
if(file) memcpy(config.acsi_img[i], file->name, 12);
else config.acsi_img[i][0] = 0;
// try to open harddisk image
hdd_image[i].size = 0;
tos_system_ctrl &= ~(TOS_ACSI0_ENABLE<<i);
config.system_ctrl &= ~(TOS_ACSI0_ENABLE<<i);
if(file) {
tos_system_ctrl |= (TOS_ACSI0_ENABLE<<i);
config.system_ctrl |= (TOS_ACSI0_ENABLE<<i);
hdd_image[i] = *file;
}
// update system control
mist_set_control(tos_system_ctrl);
mist_set_control(config.system_ctrl);
}
void tos_insert_disk(char i, fileTYPE *file) {
@@ -768,13 +727,13 @@ void tos_insert_disk(char i, fileTYPE *file) {
return;
}
tos_debugf("%c: eject\n", i+'A');
tos_debugf("%c: eject", i+'A');
// toggle write protect bit to help tos detect a media change
int wp_bit = (!i)?TOS_CONTROL_FDC_WR_PROT_A:TOS_CONTROL_FDC_WR_PROT_B;
// any disk ejected is "write protected" (as nothing covers the write protect mechanism)
mist_set_control(tos_system_ctrl | wp_bit);
mist_set_control(config.system_ctrl | wp_bit);
// first "eject" disk
fdd_image[i].file.size = 0;
@@ -786,7 +745,7 @@ void tos_insert_disk(char i, fileTYPE *file) {
// open floppy
fdd_image[i].file = *file;
tos_debugf("%c: insert %.11s\n", i+'A', fdd_image[i].file.name);
tos_debugf("%c: insert %.11s", i+'A', fdd_image[i].file.name);
// check image size and parameters
@@ -813,8 +772,8 @@ void tos_insert_disk(char i, fileTYPE *file) {
if(fdd_image[i].file.size) {
// restore state of write protect bit
tos_update_sysctrl(tos_system_ctrl);
tos_debugf("%c: detected %d sides with %d sectors per track\n",
tos_update_sysctrl(config.system_ctrl);
tos_debugf("%c: detected %d sides with %d sectors per track",
i+'A', fdd_image[i].sides, fdd_image[i].spt);
}
}
@@ -835,7 +794,7 @@ void tos_eject_all() {
}
void tos_reset(char cold) {
tos_update_sysctrl(tos_system_ctrl | TOS_CONTROL_CPU_RESET); // set reset
tos_update_sysctrl(config.system_ctrl | TOS_CONTROL_CPU_RESET); // set reset
if(cold) {
// clear first 16k
@@ -843,5 +802,57 @@ void tos_reset(char cold) {
mist_memory_set(0x00, 8192-4);
}
tos_update_sysctrl(tos_system_ctrl & ~TOS_CONTROL_CPU_RESET); // release reset
tos_update_sysctrl(config.system_ctrl & ~TOS_CONTROL_CPU_RESET); // release reset
}
unsigned long tos_system_ctrl(void) {
return config.system_ctrl;
}
void tos_config_init(void) {
fileTYPE file;
// set default values
config.system_ctrl = TOS_MEMCONFIG_4M | TOS_CONTROL_BLITTER;
memcpy(config.tos_img, "TOS IMG", 12);
config.cart_img[0] = 0;
memcpy(config.acsi_img[0], "HARDDISKHD ", 12);
config.acsi_img[1][0] = 0;
// try to load config
if (FileOpen(&file, CONFIG_FILENAME)) {
tos_debugf("Configuration file size: %lu (should be %lu)", file.size, sizeof(tos_config_t));
if(file.size == sizeof(tos_config_t)) {
FileRead(&file, sector_buffer);
memcpy(&config, sector_buffer, sizeof(tos_config_t));
}
}
}
// save configuration
void tos_config_save(void) {
fileTYPE file;
// save configuration data
if (FileOpen(&file, CONFIG_FILENAME)) {
tos_debugf("Existing conf file size: %lu", file.size);
if(file.size != sizeof(tos_config_t)) {
file.size = sizeof(tos_config_t);
if (!UpdateEntry(&file))
return;
}
} else {
tos_debugf("Creating new config");
strncpy(file.name, CONFIG_FILENAME, 11);
file.attributes = 0;
file.size = sizeof(tos_config_t);
if(!FileCreate(0, &file)) {
tos_debugf("File creation failed.");
return;
}
}
// finally write the config
memcpy(sector_buffer, &config, sizeof(tos_config_t));
FileWrite(&file, sector_buffer);
}

5
tos.h
View File

@@ -62,7 +62,7 @@
#define TOS_CONTROL_TURBO 0x00040000
#define TOS_CONTROL_BLITTER 0x00080000
extern unsigned long tos_system_ctrl;
unsigned long tos_system_ctrl(void);
void tos_upload(char *);
void tos_poll();
@@ -78,4 +78,7 @@ char *tos_get_cartridge_name();
char tos_cartridge_is_inserted();
void tos_load_cartridge(char *);
void tos_config_init(void);
void tos_config_save(void);
#endif

View File

@@ -148,8 +148,10 @@ void user_io_poll() {
if(core_type == CORE_TYPE_MIST) {
ikbd_poll();
#if 1
// check for incoming serial data
#if 0
// check for incoming serial data. thisis directly forwarded to the
// arm rs232 and mixes with debug output. Useful for debugging only of
// e.g. the diagnostic cartridge
EnableIO();
SPI(UIO_SERIAL_IN);
@@ -305,12 +307,11 @@ unsigned short keycode(unsigned char in) {
return MISS;
}
void check_reset(unsigned char modifiers)
{
if(core_type==CORE_TYPE_MINIMIG){
if(modifiers==0x45) // ctrl - alt - alt
OsdReset(RESET_NORMAL);
}
void check_reset(unsigned char modifiers) {
if(core_type==CORE_TYPE_MINIMIG) {
if(modifiers==0x45) // ctrl - alt - alt
OsdReset(RESET_NORMAL);
}
}
unsigned char modifier_keycode(unsigned char index) {
@@ -334,17 +335,6 @@ unsigned char modifier_keycode(unsigned char index) {
return MISS;
}
// unsigned char osdcode(unsigned char c) {
// int i = 0;
// while(usb2osd[i][0] && usb2osd[i][0] != c)
// i++;
// if(!usb2osd[i][0])
// iprintf("ERROR: Unsupported OSD code %x!\n", c);
// return usb2osd[i][1];
// }
// set by OSD code to suppress forwarding of those keys to the core which
// may be in use by an active OSD
static char osd_eats_keys = false;
@@ -355,8 +345,7 @@ void user_io_osd_key_enable(char on) {
static char key_used_by_osd(unsigned short s) {
if((s & OSD_LOC) && !(s & 0xff)) return true; // this key is only used in OSD and has no keycode
if(!osd_eats_keys) return false; // OSD currently doesn't use keyboard
return((s & OSD_LOC) != 0);
return(osd_eats_keys);
}
void user_io_kbd(unsigned char m, unsigned char *k) {
@@ -422,9 +411,7 @@ void user_io_kbd(unsigned char m, unsigned char *k) {
// don't send break for caps lock
if(j == 6) {
// special OSD key handled internally
//if(code & OSD_LOC)
//OsdKeySet(0x80 | osdcode(pressed[i]));
OsdKeySet(0x80 | usb2ami[pressed[i]]);
OsdKeySet(0x80 | usb2ami[pressed[i]]);
if(!key_used_by_osd(code)) {
if(is_emu_key(pressed[i])) {
@@ -452,9 +439,7 @@ void user_io_kbd(unsigned char m, unsigned char *k) {
if(j == 6) {
// special OSD key handled internally
//if(code & OSD_LOC)
//OsdKeySet(osdcode(k[i]));
OsdKeySet(usb2ami[k[i]]);
OsdKeySet(usb2ami[k[i]]);
// no further processing of any key that is currently
// redirected to the OSD