You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1154 lines
25 KiB
C

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include "video/gbuffer.h"
#include "display/display.h"
#include "cpu/65el02.h"
#include "memory/memory.h"
#include "drive/drive.h"
#include "monitor.h"
#include "screen.h"
#include "options.h"
void peripherals_print(int id, char *str);
int peripherals_seth(int id, int key, int keysym);
void options_print(int id, char *str);
int options_seth(int id, int key, int keysym);
void saveoptions();
int optdrive(int id);
optionmenustruct option_menu[] = {
{ 10, "Default (active) monitor id", 5, "default_monitor_id", NULL, options_print, options_seth},
{ 11, "Default disk drive id", 0, "default_drive_id", NULL, options_print, options_seth},
{ 0, NULL},
{ 1, "CPU Speed", 0, "cpu_speed", NULL, options_print, options_seth},
{ 2, "MMU type", 0, "mmu_type", NULL, options_print, options_seth},
{ 3, "IO penality", 0, "io_penality", NULL, options_print, options_seth},
{ 5, "Drive boost", 0, "drive_boost", NULL, options_print, options_seth},
{ 4, "Memory", 0, "memory_size", NULL, options_print, options_seth},
{ 0, NULL},
{ 12, "Stack pointer bug fix", 0, "spbugfix", NULL, options_print, options_seth},
{ 0, "(don't enable unless you"},
{ 0, " know what are you doing)"},
{ 0, NULL},
{ 100, "Peripherals -->", 0, NULL, NULL, NULL, options_seth},
{ 0, NULL},
{ 200, "Save settings", 0, NULL, NULL, NULL, options_seth},
{ 0, NULL},
{1000, "Back", 0, NULL, NULL, NULL, options_seth},
{-1}
};
optionmenustruct peripherals_menu[] = {
{ 1, "Device id 1", 25, NULL, NULL, peripherals_print, peripherals_seth},
{ 2, "Device id 2", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 3, "Device id 3", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 4, "Device id 4", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 5, "Device id 5", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 6, "Device id 6", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 7, "Device id 7", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 8, "Device id 8", 0, NULL, NULL, peripherals_print, peripherals_seth},
{ 9, "Device id 9", 0, NULL, NULL, peripherals_print, peripherals_seth},
{10, "Device id 10", 0, NULL, NULL, peripherals_print, peripherals_seth},
{0, NULL},
{11, "Device id 11", 0, NULL, NULL, peripherals_print, peripherals_seth},
{12, "Device id 12", 0, NULL, NULL, peripherals_print, peripherals_seth},
{13, "Device id 13", 0, NULL, NULL, peripherals_print, peripherals_seth},
{14, "Device id 14", 0, NULL, NULL, peripherals_print, peripherals_seth},
{15, "Device id 15", 0, NULL, NULL, peripherals_print, peripherals_seth},
{16, "Device id 16", 0, NULL, NULL, peripherals_print, peripherals_seth},
{17, "Device id 17", 0, NULL, NULL, peripherals_print, peripherals_seth},
{18, "Device id 18", 0, NULL, NULL, peripherals_print, peripherals_seth},
{19, "Device id 19", 0, NULL, NULL, peripherals_print, peripherals_seth},
{20, "Device id 20", 0, NULL, NULL, peripherals_print, peripherals_seth},
{0, NULL},
{21, "Device id 21", 0, NULL, NULL, peripherals_print, peripherals_seth},
{22, "Device id 22", 0, NULL, NULL, peripherals_print, peripherals_seth},
{23, "Device id 23", 0, NULL, NULL, peripherals_print, peripherals_seth},
{24, "Device id 24", 0, NULL, NULL, peripherals_print, peripherals_seth},
{25, "Device id 25", 0, NULL, NULL, peripherals_print, peripherals_seth},
{26, "Device id 26", 0, NULL, NULL, peripherals_print, peripherals_seth},
{27, "Device id 27", 0, NULL, NULL, peripherals_print, peripherals_seth},
{28, "Device id 28", 0, NULL, NULL, peripherals_print, peripherals_seth},
{29, "Device id 29", 0, NULL, NULL, peripherals_print, peripherals_seth},
{30, "Device id 30", 0, NULL, NULL, peripherals_print, peripherals_seth},
{0, NULL},
{31, "Device id 31", 0, NULL, NULL, peripherals_print, peripherals_seth},
{32, "Device id 32", 0, NULL, NULL, peripherals_print, peripherals_seth},
{33, "Device id 33", 0, NULL, NULL, peripherals_print, peripherals_seth},
{34, "Device id 34", 0, NULL, NULL, peripherals_print, peripherals_seth},
{35, "Device id 35", 0, NULL, NULL, peripherals_print, peripherals_seth},
{36, "Device id 36", 0, NULL, NULL, peripherals_print, peripherals_seth},
{37, "Device id 37", 0, NULL, NULL, peripherals_print, peripherals_seth},
{38, "Device id 38", 0, NULL, NULL, peripherals_print, peripherals_seth},
{39, "Device id 39", 0, NULL, NULL, peripherals_print, peripherals_seth},
{40, "Device id 40", 0, NULL, NULL, peripherals_print, peripherals_seth},
{0, NULL},
{1000, "Back", 0, NULL, NULL, NULL, options_seth},
{-1}
};
int last_iox = -1;
void peripherals_print(int id, char *str)
{
switch (peripherals[id] & 0xff)
{
case 0: strcpy(str, "-"); break;
case 1: strcpy(str, "monochrome monitor"); break;
case 2: strcpy(str, "color monitor"); break;
case 3: strcpy(str, "disk drive -->"); break;
case 4: strcpy(str, "io extender -->"); break;
default: break;
}
}
void options_print(int id, char *str)
{
switch(id)
{
case 1:
sprintf(str, "%dx", (cpu.cycles_per_tick / 1000));
break;
case 2:
if (cpu.mmu_type == 0)
strcpy(str,"original");
if (cpu.mmu_type == 1)
strcpy(str,"bigfoot");
break;
case 3:
if (!cpu.no_io_penality)
strcpy(str,"on");
else
strcpy(str,"off");
break;
case 4:
sprintf(str,"%dkb",memory_max >> 10); break;
case 5:
if (!drive_io_penality)
strcpy(str,"on");
else
strcpy(str,"off");
break;
case 10:
sprintf(str, "%d", cpu.byte1);
return;
case 11:
sprintf(str, "%d", cpu.byte0);
return;
case 12:
if (!nospbug)
strcpy(str,"disabled");
else
strcpy(str,"enabled");
break;
default:
*str = 0;
break;
}
}
int peripherals_seth(int id, int key, int keysym)
{
if (keysym == SDLK_RIGHT)
{
if (peripherals[id] < 4)
peripherals[id] ++;
else
peripherals[id] = 0;
}
if (keysym == SDLK_LEFT)
{
if (peripherals[id] > 0)
peripherals[id] --;
else
peripherals[id] = 4;
}
if ((peripherals[id] == 1) || (peripherals[id] == 2))
{
openscreen(id);
scrtype(id,peripherals[id] - 1);
}
if ( (peripherals[id] == 3) && ((key == 10) || (key == 13)) )
{
return optdrive(id);
}
if ( (peripherals[id] == 4) && ((key == 10) || (key == 13)) )
{
return optiox(id);
}
return 0;
}
int options_seth(int id, int key, int keysym)
{
int tmp;
// scrprintf(SCR_ID_OPTIONS,"id: %d key: %d keysym: %d\n", id, key, keysym);
// displayscreen(SCR_ID_OPTIONS);
// updateptc();
// SDL_Delay(1000);
if ((key == 10) || (key == 13))
{
if (id == 100)
return optperipherals();
if (id == 200)
{
saveoptions();
return 0;
}
if (id == 1000)
return 1;
}
if (keysym == SDLK_RIGHT)
{
if (id == 1)
{
tmp = (cpu.cycles_per_tick / 1000);
if (tmp < 2)
tmp = 2;
else if (tmp < 5)
tmp = 5;
else if (tmp < 10)
tmp = 10;
else
tmp = 100;
cpu.cycles_per_tick = tmp * 1000;
}
// if (id == 2)
// cpu.mmu_type ^= 1;
if (id == 3)
cpu.no_io_penality ^= 1;
if (id == 4) /* MEMORY SIZE */
{
tmp = (memory_max + 0x2000) & 0x1e000;
if (tmp > 0x10000)
tmp = 0x10000;
memory_max = tmp;
}
if (id == 5)
drive_io_penality ^= 1;
if (id == 10)
{
if (cpu.byte1 < 40)
cpu.byte1 ++;
openscreen(cpu.byte1);
}
if (id == 11)
if (cpu.byte0 < 40)
cpu.byte0 ++;
if (id == 12)
nospbug ^= 1;
}
else if (keysym == SDLK_LEFT)
{
if (id == 1) /* CPU SPEED */
{
tmp = (cpu.cycles_per_tick / 1000);
if (tmp > 10)
tmp = 10;
else if (tmp > 5)
tmp = 5;
else if (tmp > 2)
tmp = 2;
else
tmp = 1;
cpu.cycles_per_tick = tmp * 1000;
}
// if (id == 2)
// cpu.mmu_type ^= 1;
if (id == 3)
cpu.no_io_penality ^= 1;
if (id == 4) /* MEMORY SIZE */
{
tmp = (memory_max - 0x2000) & 0x1e000;
if (tmp < 0x2000)
tmp = 0x2000;
memory_max = tmp;
}
if (id == 5)
drive_io_penality ^= 1;
if (id == 10)
{
if (cpu.byte1 > 1)
cpu.byte1 --;
openscreen(cpu.byte1);
}
if (id == 11)
if (cpu.byte0 > 1)
cpu.byte0 --;
if (id == 12)
nospbug ^= 1;
}
return 0;
}
void optinit()
{
openscreen(SCR_ID_OPTIONS);
openscreen(SCR_ID_PERIPHERALS);
}
int options_handler(int id, optionmenustruct *opts, char *hdr, int src)
{
int quit = 0, esc = 0;
int maxlen = 0, maxlen2 = 0;
int elems = 0, elem = 0, pos = 0, add = 0;
int last_tick = -1, tmp;
int redraw = 1, selected;
char tempstring[256];
scrblink(id, 0);
drawstring(0, C_SIZEY-1, "\r Up/Down - Move Left/Right - Change Enter - Sub-options (-->) ESC - Back", 0x0f, 0x09, rom_charset);
if (opts)
{
while (opts[pos].id>=0)
{
if (opts[pos].name)
{
tmp = strlen(opts[pos].name);
if (maxlen < tmp)
maxlen = tmp;
if (maxlen2 < (maxlen + opts[0].len + 4) )
maxlen2 = maxlen + opts[0].len + 4;
}
elems++;
pos++;
}
scrprintf(id, "\nelements: %d\tmax len: %d\n", elems, maxlen);
}
pos = 0;
selected = -1;
while (!quit && !esc)
{
if ((redraw) && (opts))
{
selected = -1;
scrclr(id);
scrattr(id, 0x7b);
scrprintf(id, "%*s", SCR_COLS, "");
scrxy(id, (80-strlen(hdr))/2, 0);
scrprintf(id, "%s", hdr);
tmp = add;
while ((tmp + pos < elems) && (tmp < 46))
{
if ((opts[tmp + pos].id >= 0) && (opts[tmp + pos].name))
{
if ((tmp + pos) == elem)
{
scrattr(id, 0xdb);
selected = elem;
}
else
scrattr(id, 0xbd);
scrxy(id, (80-maxlen2)/2, tmp + 2);
scrprintf(id, "%*s", maxlen2, "");
scrxy(id, 1 + (80-maxlen2)/2 , tmp + 2);
scrprintf(id, "%s", opts[tmp + pos].name);
if (opts[tmp + pos].print_handler)
{
opts[tmp + pos].print_handler(opts[tmp + pos].id, tempstring);
scrxy(id, maxlen2 - 1 - strlen(tempstring) + (80-maxlen2)/2 , tmp + 2);
if ((tmp + pos) != elem)
scrattr(id, 0xbe);
scrprintf(id, "%s", tempstring);
}
}
tmp++;
}
redraw = 0;
}
displayscreen(id);
updateptc();
while (last_tick == timer_tick)
SDL_Delay(1);
last_tick = timer_tick;
while (getkeys())
{
redraw = 1;
if (lastkeysym >= 0)
{
if (lastkeysym == SDLK_ESCAPE)
esc = 1;
else if ((lastkeysym == SDLK_x) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-x
else if ((lastkeysym == SDLK_F4) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-f4
else if (lastkeysym == SDLK_DOWN)
{
if (elem < elems)
{
tmp = elem + 1;
while ((tmp < elems) && (opts[tmp].id == 0))
tmp++;
if (tmp < elems)
{
elem = tmp;
}
}
}
else if (lastkeysym == SDLK_UP)
{
if (elem < elems)
{
tmp = elem - 1;
while ((tmp >= 0) && (opts[tmp].id == 0))
tmp--;
if (tmp >= 0)
{
elem = tmp;
}
}
}
else if (lastkeysym == SDLK_HOME)
{
elem = 0;
}
else if (lastkeysym == SDLK_END)
{
elem = elems-1;
}
else if (lastkeysym == SDLK_PAGEUP)
{
tmp = elem-1;
while (tmp>0)
{
if (opts[tmp-1].id)
tmp--;
else
break;
}
while ((tmp>0) && !opts[tmp].id)
tmp --;
if (tmp<0) tmp = 0;
elem = tmp;
}
else if (lastkeysym == SDLK_PAGEDOWN)
{
tmp = elem;
while ((tmp<elems) && opts[tmp].id)
tmp ++;
while ((tmp<elems) && !opts[tmp].id)
tmp ++;
if (tmp>=elems)
tmp = elems - 1;
elem = tmp;
}
else if (selected >= 0)
{
// scrprintf(id,"key: %d keysym: %d\n", lastkey, lastkeysym);
// displayscreen(id);
// updateptc();
// SDL_Delay(1000);
if (opts[selected].set_handler)
esc = opts[selected].set_handler(opts[selected].id, lastkey, lastkeysym);
selected = -1;
}
}
if ((lastkey > 0) && !quit && !esc)
{
if (selected >= 0)
{
if (opts[selected].set_handler)
esc = opts[selected].set_handler(opts[selected].id, lastkey, lastkeysym);
}
}
if (lastkey == -2)
quit = 1;
}
}
return quit;
}
void saveoptions()
{
int qi;
char tempstring[256];
FILE *f;
scrwindow(SCR_ID_OPTIONS, 20, (SCR_ROWS/2)-2, 40, 5, 0x7c, "Save settings");
scrattr(SCR_ID_OPTIONS, 0x7b);
if ((f = fopen("emu65el02.ini", "wb")) != NULL)
{
qi = 0;
while (option_menu[qi].id>=0)
{
if (option_menu[qi].cfg_name)
{
if (option_menu[qi].print_handler)
{
option_menu[qi].print_handler(option_menu[qi].id, tempstring);
fprintf(f,"%s=%s\n",option_menu[qi].cfg_name,tempstring);
}
}
qi ++;
}
for (qi = 0; qi<256; qi++)
{
if (peripherals[qi])
{
fprintf(f,"dev_%d=%d\n",qi,peripherals[qi]);
}
}
fclose(f);
scrxy(SCR_ID_OPTIONS, 27, (SCR_ROWS/2));
scrprintf(SCR_ID_OPTIONS, "Settings saved sucessfully");
qi = 60;
}
else
{
scrxy(SCR_ID_OPTIONS, 24, (SCR_ROWS/2));
scrprintf(SCR_ID_OPTIONS, "File write error (emu65el02.ini)");
qi = 60000;
}
displayscreen(SCR_ID_OPTIONS);
while (!getkeys() && (qi-- > 0))
{
updateptc();
SDL_Delay(25);
};
}
void readoptions()
{
FILE *f;
char line[256];
char label[256];
char *ptr;
int tmp;
if ((f = fopen("emu65el02.ini", "rb")) != NULL)
{
while (!feof(f))
{
fgets(line, sizeof(line), f);
cleanstring(line);
if (*line)
{
ptr = getlabelfromstr(label,line);
// printf("%s = %s\n",label, ptr);
if (!strcasecmp(label,"default_monitor_id"))
cpu.byte1 = atoi(ptr);
if (!strcasecmp(label,"default_drive_id"))
cpu.byte0 = atoi(ptr);
if (!strcasecmp(label,"cpu_speed"))
{
if (!strcasecmp(ptr,"1x"))
cpu.cycles_per_tick = 1000;
if (!strcasecmp(ptr,"2x"))
cpu.cycles_per_tick = 2000;
if (!strcasecmp(ptr,"5x"))
cpu.cycles_per_tick = 5000;
if (!strcasecmp(ptr,"10x"))
cpu.cycles_per_tick = 10000;
if (!strcasecmp(ptr,"100x"))
cpu.cycles_per_tick = 100000;
}
if (!strcasecmp(label,"mmu_type"))
{
if (!strcasecmp(ptr,"bigfoot"))
cpu.mmu_type = 1;
}
if (!strcasecmp(label,"io_penality"))
{
if (!strcasecmp(ptr,"off"))
cpu.no_io_penality = 1;
}
if (!strcasecmp(label,"drive_boost"))
{
if (!strcasecmp(ptr,"on"))
drive_io_penality = 0;
}
if (!strcasecmp(label,"spbugfix"))
{
if (!strcasecmp(ptr,"enabled"))
nospbug = 1;
}
if (!strcasecmp(label,"memory_size"))
{
tmp = (atoi(ptr) << 10) & 0x1e000;
if (tmp > 0x10000)
tmp = 0x10000;
if (tmp < 0x2000)
tmp = 0x2000;
memory_max = tmp;
}
if (!strncasecmp(label,"dev_",4))
{
tmp = atoi(label+4);
peripherals[tmp & 0xff] = atoi(ptr);
// printf("%d = %d\n",tmp, atoi(ptr));
}
}
}
}
}
int options()
{
return options_handler(SCR_ID_OPTIONS, option_menu, "Options",0);
}
int optperipherals()
{
return options_handler(SCR_ID_PERIPHERALS, peripherals_menu, "Peripherals",0);
}
int help()
{
int esc = 0, quit = 0, last_tick = -1;
char hdr[] = "Help";
openscreen(SCR_ID_HELP);
scrblink(SCR_ID_HELP, 0);
drawstring(0, C_SIZEY-1, "\r ESC - Back", 0x0f, 0x09, rom_charset);
scrclr(SCR_ID_HELP);
scrattr(SCR_ID_HELP, 0x7b);
scrprintf(SCR_ID_HELP, "%*s", SCR_COLS, "");
scrxy(SCR_ID_HELP, (80-strlen(hdr))/2, 0);
scrprintf(SCR_ID_HELP, "%s", hdr);
scrattr(SCR_ID_HELP, 0xbe);
scrxy(SCR_ID_HELP,0,2);
scrprintf(SCR_ID_HELP,"Help isn't finished yet.\n\nPress ESC to leave this screen.\n");
while (!quit && !esc)
{
displayscreen(SCR_ID_HELP);
updateptc();
while (last_tick == timer_tick)
SDL_Delay(1);
last_tick = timer_tick;
while (getkeys())
{
if (lastkeysym >= 0)
{
if (lastkeysym == SDLK_ESCAPE)
esc = 1;
else if ((lastkeysym == SDLK_x) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-x
else if ((lastkeysym == SDLK_F4) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-f4
else if (lastkeysym == SDLK_DOWN)
{
}
else if (lastkeysym == SDLK_UP)
{
}
}
if ((lastkey > 0) && !quit && !esc)
{
}
if (lastkey == -2)
quit = 1;
}
}
return quit;
}
int optiox(int iox)
{
char hdr[] = "IO extenders";
int quit = 0, esc = 0;
int top_id = 0, row = 0, bit = 0;
int ref[256];
int maxref = 0;
int redraw = 1, last_tick = -1;
int qi, tmp, tmprow, selected;
int bit_colors[16] = { 0x10, 0x80, 0x1010, 0xe0,
0x70, 0xd0, 0x1020, 0xc0,
0xf0, 0x30, 0x40, 0x60,
0x90, 0x50, 0x2f, 0x0f };
char *str_colors[16] = {
"White",
"Orange",
"Magenta",
"Light blue",
"Yellow",
"Lime",
"Pink",
"Gray",
"Light gray",
"Cyan",
"Purple",
"Blue",
"Brown",
"Green",
"Red",
"Black" };
char tempstring[256];
// 0 - White 4 - Yellow 8 - Light Gray 12 - Brown
// 1 - Orange 5 - Lime 9 - Cyan 13 - Green
// 2 - Magenta 6 - Pink 10 - Purple 14 - Red
// 3 - Light blue 7 - Gray 11 - Blue 15 - Black
openscreen(SCR_ID_IOX);
scrblink(SCR_ID_IOX, 0);
drawstring(0, C_SIZEY-1, "\r Up/Down/Left/Right - Move Space - Set/unset ESC - Back", 0x0f, 0x09, rom_charset);
if (iox < 0)
iox = last_iox;
for (qi = 0; qi<256; qi++)
{
if (peripherals[qi] == 4)
ref[maxref++] = qi;
}
if (iox >= 0)
{
tmp = 0;
while ((tmp<maxref) && (ref[tmp] != iox))
tmp++;
printf("%d\n",tmp);
if ((tmp<maxref) && (tmp>0))
{
if (maxref >= 4)
{
if (tmp < maxref - 3)
{
top_id = tmp - 1;
row = 1;
}
else
{
top_id = maxref - 4;
row = tmp - top_id;
}
}
else
{
row = tmp;
}
}
}
while (!quit && !esc)
{
if (redraw)
{
selected = -1;
scrclr(SCR_ID_IOX);
scrattr(SCR_ID_IOX, 0x7b);
scrprintf(SCR_ID_IOX, "%*s", SCR_COLS, "");
scrxy(SCR_ID_IOX, (80-strlen(hdr))/2, 0);
scrprintf(SCR_ID_IOX, "%s", hdr);
for (qi = 0; qi < 16; qi++)
{
scrattr(SCR_ID_IOX, bit_colors[qi]);
scrxy(SCR_ID_IOX, 1 + (qi >> 2) * 20, 45 + (qi & 3));
scrprintf(SCR_ID_IOX," %x: %13s ", qi, str_colors[qi]);
}
if (maxref)
{
for (qi = 0; qi < 16; qi ++)
{
scrattr(SCR_ID_IOX, bit_colors[15-qi]);
scrxy(SCR_ID_IOX, 18 + qi * 3, 6);
scrprintf(SCR_ID_IOX, " %x ",15-qi);
}
tmp = top_id; tmprow = 0;
while ((tmp < maxref) && (tmprow<4))
{
if (tmprow == row)
{
selected = tmp;
scrattr(SCR_ID_IOX, 0x1007);
}
else
scrattr(SCR_ID_IOX, 0xb7);
scrxy(SCR_ID_IOX, 0, 8 + tmprow * 8);
scrprintf(SCR_ID_IOX, "%*s", SCR_COLS, "");
scrprintf(SCR_ID_IOX, "%*s", SCR_COLS, "");
scrprintf(SCR_ID_IOX, "%*s", SCR_COLS, "");
scrprintf(SCR_ID_IOX, "%*s", SCR_COLS, "");
scrprintf(SCR_ID_IOX, "%*s", SCR_COLS, "");
scrxy(SCR_ID_IOX, 3, 10 + tmprow * 8);
sprintf(tempstring,"#%d",ref[tmp]);
scrprintf(SCR_ID_IOX,"%4s",tempstring);
scrxy(SCR_ID_IOX, 10, 9 + tmprow * 8);
scrprintf(SCR_ID_IOX,"input:");
scrxy(SCR_ID_IOX, 9, 11 + tmprow * 8);
scrprintf(SCR_ID_IOX,"output:");
scrxy(SCR_ID_IOX, 69, 9 + tmprow * 8);
scrprintf(SCR_ID_IOX,"= $%04X",ioextender[ref[tmp]].input & 0xffff);
scrxy(SCR_ID_IOX, 69, 11 + tmprow * 8);
scrprintf(SCR_ID_IOX,"= $%04X",ioextender[ref[tmp]].output & 0xffff);
for (qi = 0; qi < 16; qi ++)
{
if (tmprow == row)
{
if (bit == qi)
scrattr(SCR_ID_IOX, 0xbe);
else
scrattr(SCR_ID_IOX, 0x1007);
}
else
scrattr(SCR_ID_IOX, 0xb7);
scrxy(SCR_ID_IOX, 18 + qi * 3, 9 + tmprow * 8);
if ( (ioextender[ref[tmp]].input >> (15 - qi)) & 1 )
scrprintf(SCR_ID_IOX," X ");
else
scrprintf(SCR_ID_IOX," _ ");
if (tmprow == row)
scrattr(SCR_ID_IOX, 0x1007);
else
scrattr(SCR_ID_IOX, 0xb7);
scrxy(SCR_ID_IOX, 18 + qi * 3, 11 + tmprow * 8);
if ( (ioextender[ref[tmp]].output >> (15 - qi)) & 1 )
scrprintf(SCR_ID_IOX," X ");
else
scrprintf(SCR_ID_IOX," _ ");
scrattr(SCR_ID_IOX, bit_colors[15-qi]);
scrxy(SCR_ID_IOX, 18 + qi * 3, 14 + tmprow * 8);
scrprintf(SCR_ID_IOX, " %x ",15-qi);
}
tmp++;
tmprow++;
}
}
else
{
scrattr(SCR_ID_IOX, 0xb7);
scrxy(SCR_ID_IOX, 30,22);
scrprintf(SCR_ID_IOX, "No IO extender configured.");
}
redraw = 0;
}
displayscreen(SCR_ID_IOX);
updateptc();
while (last_tick == timer_tick)
SDL_Delay(1);
last_tick = timer_tick;
while (getkeys())
{
redraw = 1;
if (lastkeysym >= 0)
{
if (lastkeysym == SDLK_ESCAPE)
esc = 1;
else if ((lastkeysym == SDLK_x) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-x
else if ((lastkeysym == SDLK_F4) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-f4
else if (lastkeysym == SDLK_DOWN)
{
if ( (top_id + row) < (maxref - 1) )
{
if (row < 3)
row ++;
else
top_id++;
}
}
else if (lastkeysym == SDLK_UP)
{
if (row > 0)
row --;
else if (top_id > 0)
top_id --;
}
else if (lastkeysym == SDLK_LEFT)
{
if (bit > 0)
bit --;
}
else if (lastkeysym == SDLK_RIGHT)
{
if (bit < 15)
bit ++;
}
}
if ((lastkey > 0) && !quit && !esc)
{
if ((lastkey == 0x20) && (selected >= 0))
{
ioextender[ref[selected]].input ^= (1 << (15 - bit));
}
}
if (lastkey == -2)
quit = 1;
}
}
if ((selected >= 0) && (selected < maxref))
last_iox = ref[selected];
return quit;
}
int optdrive(int id)
{
int quit = 0, esc = 0, last_tick = -1, pos = 0;
int redraw = 1;
char tempstring[256];
openscreen(SCR_ID_DRIVE);
while (!quit && !esc)
{
if (redraw)
{
scrclone(SCR_ID_DRIVE, SCR_ID_PERIPHERALS);
sprintf(tempstring,"Drive id %d setup",id);
scrwindow(SCR_ID_DRIVE, 15, 22, 50, 7, 0x100e, tempstring);
scrattr(SCR_ID_DRIVE, 0x100e);
scrxy(SCR_ID_DRIVE,17,24);
scrprintf(SCR_ID_DRIVE, "Image type: ");
if (pos == 0)
scrattr(SCR_ID_DRIVE, 0x97);
else
scrattr(SCR_ID_DRIVE, 0x100d);
if (!drives[id].name)
{
scrprintf(SCR_ID_DRIVE, "no disk");
scrattr(SCR_ID_DRIVE, 0x100e);
scrxy(SCR_ID_DRIVE,17,26);
scrprintf(SCR_ID_DRIVE, "Image name: ");
}
else if (!drives[id].type)
{
if (strlen(drives[id].name) > 30 )
sprintf(tempstring, "...%s -->", drives[id].name + strlen(drives[id].name) - 27);
else
sprintf(tempstring, "%s -->", drives[id].name);
scrprintf(SCR_ID_DRIVE, "user");
scrattr(SCR_ID_DRIVE, 0x100e);
scrxy(SCR_ID_DRIVE,17,26);
scrprintf(SCR_ID_DRIVE, "Image name: ");
scrattr(SCR_ID_DRIVE, 0xd10);
if (pos == 1)
scrattr(SCR_ID_DRIVE, 0x97);
else
scrattr(SCR_ID_DRIVE, 0x100d);
scrprintf(SCR_ID_DRIVE, "%s", tempstring);
}
else if (drives[id].type == 1)
{
scrprintf(SCR_ID_DRIVE, "built-in");
scrattr(SCR_ID_DRIVE, 0x100e);
scrxy(SCR_ID_DRIVE,17,26);
scrprintf(SCR_ID_DRIVE, "Attached image: ");
scrattr(SCR_ID_DRIVE, 0x100d);
scrprintf(SCR_ID_DRIVE, "MineOS (System)");
}
redraw = 0;
}
displayscreen(SCR_ID_DRIVE);
updateptc();
while (last_tick == timer_tick)
SDL_Delay(1);
last_tick = timer_tick;
while (getkeys())
{
redraw = 1;
if (lastkeysym >= 0)
{
if (lastkeysym == SDLK_ESCAPE)
esc = 1;
else if ((lastkeysym == SDLK_x) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-x
else if ((lastkeysym == SDLK_F4) && (lastkeymod & KMOD_ALT))
quit = 1; // alt-f4
else if (lastkeysym == SDLK_DOWN)
{
}
else if (lastkeysym == SDLK_UP)
{
}
}
if ((lastkey > 0) && !quit && !esc)
{
}
if (lastkey == -2)
quit = 1;
}
}
return quit;
}