mirror of
https://github.com/mist-devel/mist-firmware.git
synced 2026-04-26 12:27:47 +00:00
Add 32bit status version for 8bit cores. Allow more than 2 values for O option.
This commit is contained in:
83
menu.c
83
menu.c
@@ -415,8 +415,49 @@ void assign_ps2_modifier ( unsigned char mod, unsigned int* keys_ps2, unsigned c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned char getIdx(char *opt) {
|
||||
if((opt[1]>='0') && (opt[1]<='9')) return opt[1]-'0';
|
||||
if((opt[1]>='A') && (opt[1]<='V')) return opt[1]-'A'+10;
|
||||
return 0; // basically 0 cannot be valid because used as a reset. Thus can be used as a error.
|
||||
}
|
||||
|
||||
unsigned long getStatus(char *opt, unsigned long status) {
|
||||
char idx1 = getIdx(opt);
|
||||
char idx2 = getIdx(opt+1);
|
||||
unsigned long x = (status & (1<<idx1)) ? 1 : 0;
|
||||
|
||||
if(idx2>idx1) {
|
||||
x = status >> idx1;
|
||||
x = x & ~(0xffffffff << (idx2 - idx1 + 1));
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
unsigned long setStatus(char *opt, unsigned long status, unsigned long value) {
|
||||
unsigned char idx1 = getIdx(opt);
|
||||
unsigned char idx2 = getIdx(opt+1);
|
||||
unsigned long x = 1;
|
||||
|
||||
if(idx2>idx1) x = ~(0xffffffff << (idx2 - idx1 + 1));
|
||||
x = x << idx1;
|
||||
|
||||
return (status & ~x) | ((value << idx1) & x);
|
||||
}
|
||||
|
||||
unsigned long getStatusMask(char *opt) {
|
||||
char idx1 = getIdx(opt);
|
||||
char idx2 = getIdx(opt+1);
|
||||
unsigned long x = 1;
|
||||
|
||||
if(idx2>idx1) x = ~(0xffffffff << (idx2 - idx1 + 1));
|
||||
|
||||
//iprintf("grtStatusMask %d %d %x\n", idx1, idx2, x);
|
||||
|
||||
return x << idx1;
|
||||
}
|
||||
|
||||
void HandleUI(void)
|
||||
{
|
||||
char *p;
|
||||
@@ -712,7 +753,7 @@ void HandleUI(void)
|
||||
i = 2;
|
||||
do {
|
||||
char* pos;
|
||||
unsigned char status = user_io_8bit_set_status(0,0); // 0,0 gets status
|
||||
unsigned long status = user_io_8bit_set_status(0,0); // 0,0 gets status
|
||||
|
||||
p = user_io_8bit_get_string(i);
|
||||
// iprintf("Option %d: %s\n", i-1, p);
|
||||
@@ -740,8 +781,6 @@ void HandleUI(void)
|
||||
|
||||
// check for 'T'oggle strings
|
||||
if(p && (p[0] == 'T')) {
|
||||
// p[1] is the digit after the O, so O1 is status bit 1
|
||||
char x = (status & (1<<(p[1]-'0')))?1:0;
|
||||
|
||||
s[0] = ' ';
|
||||
substrcpy(s+1, p, 1);
|
||||
@@ -754,13 +793,12 @@ void HandleUI(void)
|
||||
|
||||
// check for 'O'ption strings
|
||||
if(p && (p[0] == 'O')) {
|
||||
// p[1] is the digit after the O, so O1 is status bit 1
|
||||
char x = (status & (1<<(p[1]-'0')))?1:0;
|
||||
unsigned long x = getStatus(p, status);
|
||||
|
||||
// get currently active option
|
||||
substrcpy(s, p, 2+x);
|
||||
char l = strlen(s);
|
||||
|
||||
|
||||
s[0] = ' ';
|
||||
substrcpy(s+1, p, 1);
|
||||
strcat(s, ":");
|
||||
@@ -843,10 +881,28 @@ void HandleUI(void)
|
||||
SelectFile(ext, SCAN_DIR | SCAN_LFN,
|
||||
(p[0] == 'F')?MENU_8BIT_MAIN_FILE_SELECTED:MENU_8BIT_MAIN_IMAGE_SELECTED,
|
||||
MENU_8BIT_MAIN1, 1);
|
||||
} else if(p[0] == 'O') {
|
||||
unsigned long status = user_io_8bit_set_status(0,0); // 0,0 gets status
|
||||
unsigned long x = getStatus(p, status) + 1;
|
||||
|
||||
//unsigned long mask = getStatusMask(p);
|
||||
//unsigned long x2 = x;
|
||||
|
||||
// check if next value available
|
||||
substrcpy(s, p, 2+x);
|
||||
if(!strlen(s)) x = 0;
|
||||
|
||||
//iprintf("Option %s %x %x %x %x\n", p, status, mask, x2, x);
|
||||
|
||||
user_io_8bit_set_status(setStatus(p, status, x), 0xffffffff);
|
||||
|
||||
menustate = MENU_8BIT_MAIN1;
|
||||
} else {
|
||||
// 'T' option
|
||||
|
||||
// determine which status bit is affected
|
||||
unsigned char mask = 1<<(p[1]-'0');
|
||||
unsigned char status = user_io_8bit_set_status(0,0); // 0,0 gets status
|
||||
unsigned long mask = 1<<getIdx(p);
|
||||
unsigned long status = user_io_8bit_set_status(0,0); // 0,0 gets status
|
||||
|
||||
// iprintf("Option %s %x\n", p, status ^ mask);
|
||||
|
||||
@@ -854,8 +910,7 @@ void HandleUI(void)
|
||||
user_io_8bit_set_status(status ^ mask, mask);
|
||||
|
||||
// ... and change it again in case of a toggle bit
|
||||
if(p[0] == 'T')
|
||||
user_io_8bit_set_status(status, mask);
|
||||
user_io_8bit_set_status(status, mask);
|
||||
|
||||
menustate = MENU_8BIT_MAIN1;
|
||||
}
|
||||
@@ -933,9 +988,9 @@ void HandleUI(void)
|
||||
// Save settings
|
||||
user_io_create_config_name(s);
|
||||
iprintf("Saving config to %s\n", s);
|
||||
if(FileNew(&file, s, 1)) {
|
||||
if(FileNew(&file, s, 4)) {
|
||||
// finally write data
|
||||
sector_buffer[0] = user_io_8bit_set_status(0,0);
|
||||
((unsigned long*)sector_buffer)[0] = user_io_8bit_set_status(0,0);
|
||||
FileWrite(&file, sector_buffer);
|
||||
iprintf("Settings for %s written\n", s);
|
||||
}
|
||||
|
||||
10
spi.c
10
spi.c
@@ -247,3 +247,13 @@ void spi_uio_cmd8(unsigned char cmd, unsigned char parm) {
|
||||
spi_uio_cmd8_cont(cmd, parm);
|
||||
DisableIO();
|
||||
}
|
||||
|
||||
void spi_uio_cmd32(unsigned char cmd, unsigned long parm) {
|
||||
EnableIO();
|
||||
SPI(cmd);
|
||||
SPI(parm);
|
||||
SPI(parm>>8);
|
||||
SPI(parm>>16);
|
||||
SPI(parm>>24);
|
||||
DisableIO();
|
||||
}
|
||||
|
||||
1
spi.h
1
spi.h
@@ -56,6 +56,7 @@ void spi_uio_cmd_cont(unsigned char cmd);
|
||||
void spi_uio_cmd(unsigned char cmd);
|
||||
void spi_uio_cmd8(unsigned char cmd, unsigned char parm);
|
||||
void spi_uio_cmd8_cont(unsigned char cmd, unsigned char parm);
|
||||
void spi_uio_cmd32(unsigned char cmd, unsigned long parm);
|
||||
|
||||
/* spi functions for max3421 */
|
||||
#define spi_max_start() { *AT91C_PIOA_CODR = USB_SEL; }
|
||||
|
||||
12
user_io.c
12
user_io.c
@@ -260,9 +260,10 @@ void user_io_detect_core_type() {
|
||||
|
||||
if (FileOpen(&file, s)) {
|
||||
iprintf("Found config\n");
|
||||
if(file.size == 1) {
|
||||
if(file.size <= 4) {
|
||||
((unsigned long*)sector_buffer)[0] = 0;
|
||||
FileRead(&file, sector_buffer);
|
||||
user_io_8bit_set_status(sector_buffer[0], 0xff);
|
||||
user_io_8bit_set_status(((unsigned long*)sector_buffer)[0], 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -642,7 +643,7 @@ void user_io_file_tx(fileTYPE *file, unsigned char index) {
|
||||
// to treat it
|
||||
char *user_io_8bit_get_string(char index) {
|
||||
unsigned char i, lidx = 0, j = 0;
|
||||
static char buffer[32+1]; // max 32 bytes per config item
|
||||
static char buffer[128+1]; // max 128 bytes per config item
|
||||
|
||||
// clear buffer
|
||||
buffer[0] = 0;
|
||||
@@ -686,8 +687,8 @@ char *user_io_8bit_get_string(char index) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
unsigned char user_io_8bit_set_status(unsigned char new_status, unsigned char mask) {
|
||||
static unsigned char status = 0;
|
||||
unsigned long user_io_8bit_set_status(unsigned long new_status, unsigned long mask) {
|
||||
static unsigned long status = 0;
|
||||
|
||||
// if mask is 0 just return the current status
|
||||
if(mask) {
|
||||
@@ -697,6 +698,7 @@ unsigned char user_io_8bit_set_status(unsigned char new_status, unsigned char ma
|
||||
status |= new_status & mask;
|
||||
|
||||
spi_uio_cmd8(UIO_SET_STATUS, status);
|
||||
spi_uio_cmd32(UIO_SET_STATUS2, status);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
#define UIO_SIO_IN 0x1b // serial in
|
||||
#define UIO_SET_SDSTAT 0x1c // set sd card status
|
||||
#define UIO_SET_SDINFO 0x1d // send info about mounted image
|
||||
#define UIO_SET_STATUS2 0x1e // 32bit status
|
||||
|
||||
// codes as used by 8bit (atari 800, zx81) via SS2
|
||||
#define UIO_GET_STATUS 0x50
|
||||
@@ -141,7 +142,7 @@ char user_io_user_button();
|
||||
void user_io_osd_key_enable(char);
|
||||
void user_io_serial_tx(char *, uint16_t);
|
||||
char *user_io_8bit_get_string(char);
|
||||
unsigned char user_io_8bit_set_status(unsigned char, unsigned char);
|
||||
unsigned long user_io_8bit_set_status(unsigned long, unsigned long);
|
||||
void user_io_file_tx(fileTYPE *, unsigned char);
|
||||
void user_io_sd_set_config(void);
|
||||
char user_io_dip_switch1(void);
|
||||
|
||||
Reference in New Issue
Block a user