clang-format in src/

This commit is contained in:
Jasmine Iwanek
2022-09-18 17:11:43 -04:00
parent 2267153edd
commit e6dbaefeb1
35 changed files with 7113 additions and 7387 deletions

View File

@@ -31,15 +31,15 @@
#include <stdatomic.h>
#ifndef _WIN32
#include <pwd.h>
#include <unistd.h>
# include <pwd.h>
# include <unistd.h>
#endif
#ifdef __APPLE__
#include <string.h>
#include <dispatch/dispatch.h>
#ifdef __aarch64__
#include <pthread.h>
#endif
# include <string.h>
# include <dispatch/dispatch.h>
# ifdef __aarch64__
# include <pthread.h>
# endif
#endif
#define HAVE_STDARG_H
@@ -99,11 +99,10 @@
// Disable c99-designator to avoid the warnings about int ng
#ifdef __clang__
#if __has_warning("-Wunused-but-set-variable")
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
# if __has_warning("-Wunused-but-set-variable")
# pragma clang diagnostic ignored "-Wunused-but-set-variable"
# endif
#endif
#endif
/* Stuff that used to be globally declared in plat.h but is now extern there
and declared here instead. */
@@ -133,10 +132,10 @@ int confirm_exit_cmdl = 1; /* (O) do not ask for confirmation on quit if set t
uint64_t unique_id = 0;
uint64_t source_hwnd = 0;
#endif
char rom_path[1024] = { '\0'}; /* (O) full path to ROMs */
char rom_path[1024] = { '\0' }; /* (O) full path to ROMs */
rom_path_t rom_paths = { "", NULL }; /* (O) full paths to ROMs */
char log_path[1024] = { '\0'}; /* (O) full path of logfile */
char vm_name[1024] = { '\0'}; /* (O) display name of the VM */
char log_path[1024] = { '\0' }; /* (O) full path of logfile */
char vm_name[1024] = { '\0' }; /* (O) display name of the VM */
#ifdef USE_INSTRUMENT
uint8_t instru_enabled = 0;
uint64_t instru_run_ms = 0;
@@ -162,7 +161,7 @@ int video_framerate = -1; /* (C) video */
char video_shader[512] = { '\0' }; /* (C) video */
int bugger_enabled = 0; /* (C) enable ISAbugger */
int postcard_enabled = 0; /* (C) enable POST card */
int isamem_type[ISAMEM_MAX] = { 0,0,0,0 }; /* (C) enable ISA mem cards */
int isamem_type[ISAMEM_MAX] = { 0, 0, 0, 0 }; /* (C) enable ISA mem cards */
int isartc_type = 0; /* (C) enable ISA RTC card */
int gfxcard = 0; /* (C) graphics/video card */
int gfxcard_2 = 0; /* (C) graphics/video card */
@@ -206,22 +205,19 @@ char exe_path[2048]; /* path (dir) of executable */
char usr_path[1024]; /* path (dir) of user data */
char cfg_path[1024]; /* full path of config file */
FILE *stdlog = NULL; /* file to log output to */
//int scrnsz_x = SCREEN_RES_X; /* current screen size, X */
//int scrnsz_y = SCREEN_RES_Y; /* current screen size, Y */
// int scrnsz_x = SCREEN_RES_X; /* current screen size, X */
// int scrnsz_y = SCREEN_RES_Y; /* current screen size, Y */
int config_changed; /* config has changed */
int title_update;
int framecountx = 0;
int hard_reset_pending = 0;
//int unscaled_size_x = SCREEN_RES_X; /* current unscaled size X */
//int unscaled_size_y = SCREEN_RES_Y; /* current unscaled size Y */
//int efscrnsz_y = SCREEN_RES_Y;
// int unscaled_size_x = SCREEN_RES_X; /* current unscaled size X */
// int unscaled_size_y = SCREEN_RES_Y; /* current unscaled size Y */
// int efscrnsz_y = SCREEN_RES_Y;
static wchar_t mouse_msg[3][200];
#ifndef RELEASE_BUILD
static char buff[1024];
static int seen = 0;
@@ -255,7 +251,7 @@ pclog_ex(const char *fmt, va_list ap)
}
vsprintf(temp, fmt, ap);
if (suppr_seen && ! strcmp(buff, temp))
if (suppr_seen && !strcmp(buff, temp))
seen++;
else {
if (suppr_seen && seen)
@@ -269,7 +265,6 @@ pclog_ex(const char *fmt, va_list ap)
#endif
}
void
pclog_toggle_suppr(void)
{
@@ -278,7 +273,6 @@ pclog_toggle_suppr(void)
#endif
}
/* Log something. We only do this in non-release builds. */
void
pclog(const char *fmt, ...)
@@ -292,7 +286,6 @@ pclog(const char *fmt, ...)
#endif
}
/* Log a fatal error, and display a UI message before exiting. */
void
fatal(const char *fmt, ...)
@@ -326,7 +319,8 @@ fatal(const char *fmt, ...)
#endif
/* Make sure the message does not have a trailing newline. */
if ((sp = strchr(temp, '\n')) != NULL) *sp = '\0';
if ((sp = strchr(temp, '\n')) != NULL)
*sp = '\0';
/* Cleanly terminate all of the emulator's components so as
to avoid things like threads getting stuck. */
@@ -339,7 +333,6 @@ fatal(const char *fmt, ...)
exit(-1);
}
void
fatal_ex(const char *fmt, va_list ap)
{
@@ -368,7 +361,8 @@ fatal_ex(const char *fmt, va_list ap)
#endif
/* Make sure the message does not have a trailing newline. */
if ((sp = strchr(temp, '\n')) != NULL) *sp = '\0';
if ((sp = strchr(temp, '\n')) != NULL)
*sp = '\0';
/* Cleanly terminate all of the emulator's components so as
to avoid things like threads getting stuck. */
@@ -379,11 +373,9 @@ fatal_ex(const char *fmt, va_list ap)
fflush(stdlog);
}
#ifdef ENABLE_PC_LOG
int pc_do_log = ENABLE_PC_LOG;
static void
pc_log(const char *fmt, ...)
{
@@ -396,10 +388,9 @@ pc_log(const char *fmt, ...)
}
}
#else
#define pc_log(fmt, ...)
# define pc_log(fmt, ...)
#endif
/*
* Perform initial startup of the PC.
*
@@ -425,7 +416,7 @@ pc_init(int argc, char *argv[])
uint32_t lang_init = 0;
/* Grab the executable's full path. */
plat_get_exe_name(exe_path, sizeof(exe_path)-1);
plat_get_exe_name(exe_path, sizeof(exe_path) - 1);
p = path_get_filename(exe_path);
*p = '\0';
#if defined(__APPLE__)
@@ -437,7 +428,7 @@ pc_init(int argc, char *argv[])
}
if (!strncmp(exe_path, "/private/var/folders/", 21)) {
ui_msgbox_header(MBX_FATAL, L"App Translocation", EMU_NAME_W L" cannot determine the emulated machine's location due to a macOS security feature. Please move the " EMU_NAME_W L" app to another folder (not /Applications), or make a copy of it and open that copy instead.");
return(0);
return (0);
}
#elif !defined(_WIN32)
/* Grab the actual path if we are an AppImage. */
@@ -459,8 +450,9 @@ pc_init(int argc, char *argv[])
plat_getcwd(usr_path, sizeof(usr_path) - 1);
plat_getcwd(rom_path, sizeof(rom_path) - 1);
for (c=1; c<argc; c++) {
if (argv[c][0] != '-') break;
for (c = 1; c < argc; c++) {
if (argv[c][0] != '-')
break;
if (!strcasecmp(argv[c], "--help") || !strcasecmp(argv[c], "-?")) {
usage:
@@ -488,99 +480,92 @@ usage:
printf("-V or --vmname name - overrides the name of the running VM\n");
printf("-Z or --lastvmpath - the last parameter is VM path rather than config\n");
printf("\nA config file can be specified. If none is, the default file will be used.\n");
return(0);
} else if (!strcasecmp(argv[c], "--lastvmpath") ||
!strcasecmp(argv[c], "-Z")) {
return (0);
} else if (!strcasecmp(argv[c], "--lastvmpath") || !strcasecmp(argv[c], "-Z")) {
lvmp = 1;
} else if (!strcasecmp(argv[c], "--dumpcfg") ||
!strcasecmp(argv[c], "-O")) {
} else if (!strcasecmp(argv[c], "--dumpcfg") || !strcasecmp(argv[c], "-O")) {
do_dump_config = 1;
#ifdef _WIN32
} else if (!strcasecmp(argv[c], "--debug") ||
!strcasecmp(argv[c], "-D")) {
} else if (!strcasecmp(argv[c], "--debug") || !strcasecmp(argv[c], "-D")) {
force_debug = 1;
#endif
#ifdef ENABLE_NG
} else if (!strcasecmp(argv[c], "--nographic") ||
!strcasecmp(argv[c], "-E")) {
} else if (!strcasecmp(argv[c], "--nographic") || !strcasecmp(argv[c], "-E")) {
/* Currently does nothing, but if/when we implement a built-in manager,
it's going to force the manager not to run, allowing the old usage
without parameter. */
ng = 1;
#endif
} else if (!strcasecmp(argv[c], "--fullscreen") ||
!strcasecmp(argv[c], "-F")) {
} else if (!strcasecmp(argv[c], "--fullscreen") || !strcasecmp(argv[c], "-F")) {
start_in_fullscreen = 1;
} else if (!strcasecmp(argv[c], "--logfile") ||
!strcasecmp(argv[c], "-L")) {
if ((c+1) == argc) goto usage;
} else if (!strcasecmp(argv[c], "--logfile") || !strcasecmp(argv[c], "-L")) {
if ((c + 1) == argc)
goto usage;
strcpy(log_path, argv[++c]);
} else if (!strcasecmp(argv[c], "--vmpath") ||
!strcasecmp(argv[c], "-P")) {
if ((c+1) == argc) goto usage;
} else if (!strcasecmp(argv[c], "--vmpath") || !strcasecmp(argv[c], "-P")) {
if ((c + 1) == argc)
goto usage;
ppath = argv[++c];
} else if (!strcasecmp(argv[c], "--rompath") ||
!strcasecmp(argv[c], "-R")) {
if ((c+1) == argc) goto usage;
} else if (!strcasecmp(argv[c], "--rompath") || !strcasecmp(argv[c], "-R")) {
if ((c + 1) == argc)
goto usage;
rpath = argv[++c];
rom_add_path(rpath);
} else if (!strcasecmp(argv[c], "--config") ||
!strcasecmp(argv[c], "-C")) {
if ((c+1) == argc || plat_dir_check(argv[c + 1])) goto usage;
} else if (!strcasecmp(argv[c], "--config") || !strcasecmp(argv[c], "-C")) {
if ((c + 1) == argc || plat_dir_check(argv[c + 1]))
goto usage;
cfg = argv[++c];
} else if (!strcasecmp(argv[c], "--vmname") ||
!strcasecmp(argv[c], "-V")) {
if ((c+1) == argc) goto usage;
} else if (!strcasecmp(argv[c], "--vmname") || !strcasecmp(argv[c], "-V")) {
if ((c + 1) == argc)
goto usage;
strcpy(vm_name, argv[++c]);
} else if (!strcasecmp(argv[c], "--settings") ||
!strcasecmp(argv[c], "-S")) {
} else if (!strcasecmp(argv[c], "--settings") || !strcasecmp(argv[c], "-S")) {
settings_only = 1;
} else if (!strcasecmp(argv[c], "--noconfirm") ||
!strcasecmp(argv[c], "-N")) {
} else if (!strcasecmp(argv[c], "--noconfirm") || !strcasecmp(argv[c], "-N")) {
confirm_exit_cmdl = 0;
#ifdef _WIN32
} else if (!strcasecmp(argv[c], "--hwnd") ||
!strcasecmp(argv[c], "-H")) {
} else if (!strcasecmp(argv[c], "--hwnd") || !strcasecmp(argv[c], "-H")) {
if ((c+1) == argc) goto usage;
if ((c + 1) == argc)
goto usage;
uid = (uint32_t *) &unique_id;
shwnd = (uint32_t *) &source_hwnd;
sscanf(argv[++c], "%08X%08X,%08X%08X", uid + 1, uid, shwnd + 1, shwnd);
} else if (!strcasecmp(argv[c], "--lang") ||
!strcasecmp(argv[c], "-G")) {
} else if (!strcasecmp(argv[c], "--lang") || !strcasecmp(argv[c], "-G")) {
#endif
//This function is currently unimplemented for *nix but has placeholders.
// This function is currently unimplemented for *nix but has placeholders.
lang_init = plat_language_code(argv[++c]);
if (!lang_init)
printf("\nWarning: Invalid language code, ignoring --lang parameter.\n\n");
//The return value of 0 only means that the code is invalid,
// The return value of 0 only means that the code is invalid,
// not related to that translation is exists or not for the
// selected language.
} else if (!strcasecmp(argv[c], "--test")) {
/* some (undocumented) test function here.. */
/* .. and then exit. */
return(0);
return (0);
#ifdef USE_INSTRUMENT
} else if (!strcasecmp(argv[c], "--instrument")) {
if ((c+1) == argc) goto usage;
if ((c + 1) == argc)
goto usage;
instru_enabled = 1;
sscanf(argv[++c], "%llu", &instru_run_ms);
#endif
}
/* Uhm... out of options here.. */
else goto usage;
else
goto usage;
}
/* One argument (config file) allowed. */
@@ -591,7 +576,8 @@ usage:
cfg = argv[c++];
}
if (c != argc) goto usage;
if (c != argc)
goto usage;
path_slash(usr_path);
path_slash(rom_path);
@@ -603,7 +589,7 @@ usage:
* make it absolute.
*/
if (ppath != NULL) {
if (! path_abs(ppath)) {
if (!path_abs(ppath)) {
/*
* This looks like a relative path.
*
@@ -621,7 +607,7 @@ usage:
/* If the specified path does not yet exist,
create it. */
if (! plat_dir_check(usr_path))
if (!plat_dir_check(usr_path))
plat_dir_create(usr_path);
}
@@ -642,7 +628,7 @@ usage:
* make it absolute.
*/
if (rpath != NULL) {
if (! path_abs(rpath)) {
if (!path_abs(rpath)) {
/*
* This looks like a relative path.
*
@@ -660,7 +646,7 @@ usage:
/* If the specified path does not yet exist,
create it. */
if (! plat_dir_check(rom_path))
if (!plat_dir_check(rom_path))
plat_dir_create(rom_path);
} else
rom_path[0] = '\0';
@@ -684,7 +670,7 @@ usage:
* path component. Separate the two, and
* add the path component to the cfg path.
*/
*(p-1) = '\0';
*(p - 1) = '\0';
/*
* If this is an absolute path, keep it, as
@@ -714,7 +700,7 @@ usage:
* working directory name as the VM's name.
*/
if (strlen(vm_name) == 0) {
char ltemp[1024] = { '\0'};
char ltemp[1024] = { '\0' };
path_get_dirname(ltemp, usr_path);
strcpy(vm_name, path_get_filename(ltemp));
}
@@ -723,7 +709,7 @@ usage:
* This is where we start outputting to the log file,
* if there is one. Create a little info header first.
*/
(void)time(&now);
(void) time(&now);
info = localtime(&now);
strftime(temp, sizeof(temp), "%Y/%m/%d %H:%M:%S", info);
pclog("#\n# %ls v%ls logfile, created %s\n#\n",
@@ -731,7 +717,7 @@ usage:
pclog("# VM: %s\n#\n", vm_name);
pclog("# Emulator path: %s\n", exe_path);
pclog("# Userfiles path: %s\n", usr_path);
for(rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
pclog("# ROM path: %s\n", rom_path->path);
}
@@ -759,10 +745,9 @@ usage:
gdbstub_init();
/* All good! */
return(1);
return (1);
}
void
pc_speed_changed(void)
{
@@ -772,18 +757,16 @@ pc_speed_changed(void)
pit_set_clock(14318184.0);
}
void
pc_full_speed(void)
{
if (! atfullspeed) {
if (!atfullspeed) {
pc_log("Set fullspeed - %i %i\n", is386, AT);
pc_speed_changed();
}
atfullspeed = 1;
}
/* Initialize modules, ran once, after pc_init. */
int
pc_init_modules(void)
@@ -822,12 +805,12 @@ pc_init_modules(void)
}
if (c == 0) {
/* No usable ROMs found, aborting. */
return(0);
return (0);
}
pc_log("A total of %d ROM sets have been loaded.\n", c);
/* Load the ROMs for the selected machine. */
if (! machine_available(machine)) {
if (!machine_available(machine)) {
swprintf(temp, sizeof(temp), plat_get_string(IDS_2063), machine_getname());
c = 0;
machine = -1;
@@ -843,12 +826,12 @@ pc_init_modules(void)
if (machine == -1) {
fatal("No available machines\n");
exit(-1);
return(0);
return (0);
}
}
/* Make sure we have a usable video card. */
if (! video_card_available(gfxcard)) {
if (!video_card_available(gfxcard)) {
memset(tempc, 0, sizeof(tempc));
device_get_name(video_card_getdevice(gfxcard), 0, tempc);
swprintf(temp, sizeof(temp), plat_get_string(IDS_2064), tempc);
@@ -866,11 +849,11 @@ pc_init_modules(void)
if (gfxcard == -1) {
fatal("No available video cards\n");
exit(-1);
return(0);
return (0);
}
}
if (! video_card_available(gfxcard_2)) {
if (!video_card_available(gfxcard_2)) {
char temp[1024] = { 0 };
char tempc[1024] = { 0 };
device_get_name(video_card_getdevice(gfxcard_2), 0, tempc);
@@ -886,13 +869,13 @@ pc_init_modules(void)
mem_init();
#ifdef USE_DYNAREC
#if defined(__APPLE__) && defined(__aarch64__)
# if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(0);
#endif
# endif
codegen_init();
#if defined(__APPLE__) && defined(__aarch64__)
# if defined(__APPLE__) && defined(__aarch64__)
pthread_jit_write_protect_np(1);
#endif
# endif
#endif
keyboard_init();
@@ -910,10 +893,9 @@ pc_init_modules(void)
machine_status_init();
return(1);
return (1);
}
void
pc_send_ca(uint16_t sc)
{
@@ -925,7 +907,6 @@ pc_send_ca(uint16_t sc)
keyboard_input(0, 0x1D); /* Ctrl key released */
}
/* Send the machine a Control-Alt-DEL sequence. */
void
pc_send_cad(void)
@@ -933,7 +914,6 @@ pc_send_cad(void)
pc_send_ca(0x153);
}
/* Send the machine a Control-Alt-ESC sequence. */
void
pc_send_cae(void)
@@ -941,7 +921,6 @@ pc_send_cae(void)
pc_send_ca(1);
}
void
pc_reset_hard_close(void)
{
@@ -985,7 +964,6 @@ pc_reset_hard_close(void)
cpu_close();
}
/*
* This is basically the spot where we start up the actual machine,
* by issuing a 'hard reset' to the entire configuration. Order is
@@ -1103,21 +1081,22 @@ pc_reset_hard_init(void)
update_mouse_msg();
}
void update_mouse_msg()
void
update_mouse_msg()
{
wchar_t wcpufamily[2048], wcpu[2048], wmachine[2048], *wcp;
mbstowcs(wmachine, machine_getname(), strlen(machine_getname())+1);
mbstowcs(wmachine, machine_getname(), strlen(machine_getname()) + 1);
if (!cpu_override)
mbstowcs(wcpufamily, cpu_f->name, strlen(cpu_f->name)+1);
mbstowcs(wcpufamily, cpu_f->name, strlen(cpu_f->name) + 1);
else
swprintf(wcpufamily, sizeof_w(wcpufamily), L"[U] %hs", cpu_f->name);
wcp = wcschr(wcpufamily, L'(');
if (wcp) /* remove parentheses */
*(wcp - 1) = L'\0';
mbstowcs(wcpu, cpu_s->name, strlen(cpu_s->name)+1);
mbstowcs(wcpu, cpu_s->name, strlen(cpu_s->name) + 1);
#ifdef _WIN32
swprintf(mouse_msg[0], sizeof_w(mouse_msg[0]), L"%%i%%%% - %ls",
plat_get_string(IDS_2077));
@@ -1142,7 +1121,6 @@ pc_reset_hard(void)
hard_reset_pending = 1;
}
void
pc_close(thread_t *ptr)
{
@@ -1175,7 +1153,7 @@ pc_close(thread_t *ptr)
lpt_devices_close();
for (i=0; i<FDD_NUM; i++)
for (i = 0; i < FDD_NUM; i++)
fdd_close(i);
#ifdef ENABLE_808X_LOG
@@ -1208,16 +1186,15 @@ pc_close(thread_t *ptr)
gdbstub_close();
}
#ifdef __APPLE__
static void _ui_window_title(void *s)
static void
_ui_window_title(void *s)
{
ui_window_title((wchar_t *) s);
free(s);
}
#endif
void
pc_run(void)
{
@@ -1261,7 +1238,6 @@ pc_run(void)
}
}
/* Handler for the 1-second timer to refresh the window title. */
void
pc_onesec(void)
@@ -1283,10 +1259,14 @@ set_screen_size_monitor(int x, int y, int monitor_index)
#if 0
pc_log("SetScreenSize(%d, %d) resize=%d\n", x, y, vid_resize);
#endif
if (x < 320) x = 320;
if (y < 200) y = 200;
if (x > 2048) x = 2048;
if (y > 2048) y = 2048;
if (x < 320)
x = 320;
if (y < 200)
y = 200;
if (x > 2048)
x = 2048;
if (y > 2048)
y = 2048;
/* Save the new values as "real" (unscaled) resolution. */
monitors[monitor_index].mon_unscaled_size_x = x;
@@ -1296,11 +1276,11 @@ set_screen_size_monitor(int x, int y, int monitor_index)
temp_overscan_x = temp_overscan_y = 0;
if (force_43) {
dx = (double)x;
dtx = (double)temp_overscan_x;
dx = (double) x;
dtx = (double) temp_overscan_x;
dy = (double)y;
dty = (double)temp_overscan_y;
dy = (double) y;
dty = (double) temp_overscan_y;
/* Account for possible overscan. */
if (video_get_type_monitor(monitor_index) != VIDEO_FLAG_TYPE_SPECIAL && (temp_overscan_y == 16)) {
@@ -1318,14 +1298,14 @@ set_screen_size_monitor(int x, int y, int monitor_index)
dy = (x / 4.0) * 3.0;
}
}
monitors[monitor_index].mon_unscaled_size_y = (int)dy;
monitors[monitor_index].mon_unscaled_size_y = (int) dy;
} else
monitors[monitor_index].mon_unscaled_size_y = monitors[monitor_index].mon_efscrnsz_y;
switch(scale) {
switch (scale) {
case 0: /* 50% */
monitors[monitor_index].mon_scrnsz_x = (monitors[monitor_index].mon_unscaled_size_x>>1);
monitors[monitor_index].mon_scrnsz_y = (monitors[monitor_index].mon_unscaled_size_y>>1);
monitors[monitor_index].mon_scrnsz_x = (monitors[monitor_index].mon_unscaled_size_x >> 1);
monitors[monitor_index].mon_scrnsz_y = (monitors[monitor_index].mon_unscaled_size_y >> 1);
break;
case 1: /* 100% */
@@ -1334,13 +1314,13 @@ set_screen_size_monitor(int x, int y, int monitor_index)
break;
case 2: /* 150% */
monitors[monitor_index].mon_scrnsz_x = ((monitors[monitor_index].mon_unscaled_size_x*3)>>1);
monitors[monitor_index].mon_scrnsz_y = ((monitors[monitor_index].mon_unscaled_size_y*3)>>1);
monitors[monitor_index].mon_scrnsz_x = ((monitors[monitor_index].mon_unscaled_size_x * 3) >> 1);
monitors[monitor_index].mon_scrnsz_y = ((monitors[monitor_index].mon_unscaled_size_y * 3) >> 1);
break;
case 3: /* 200% */
monitors[monitor_index].mon_scrnsz_x = (monitors[monitor_index].mon_unscaled_size_x<<1);
monitors[monitor_index].mon_scrnsz_y = (monitors[monitor_index].mon_unscaled_size_y<<1);
monitors[monitor_index].mon_scrnsz_x = (monitors[monitor_index].mon_unscaled_size_x << 1);
monitors[monitor_index].mon_scrnsz_y = (monitors[monitor_index].mon_unscaled_size_y << 1);
break;
}
@@ -1366,7 +1346,6 @@ reset_screen_size(void)
set_screen_size(monitors[i].mon_unscaled_size_x, monitors[i].mon_efscrnsz_y);
}
void
set_screen_size_natural(void)
{
@@ -1374,16 +1353,14 @@ set_screen_size_natural(void)
set_screen_size(monitors[i].mon_unscaled_size_x, monitors[i].mon_unscaled_size_y);
}
int
get_actual_size_x(void)
{
return(unscaled_size_x);
return (unscaled_size_x);
}
int
get_actual_size_y(void)
{
return(efscrnsz_y);
return (efscrnsz_y);
}

File diff suppressed because it is too large Load Diff

View File

@@ -27,11 +27,9 @@
#include <86box/io.h>
#include <86box/apm.h>
#ifdef ENABLE_APM_LOG
int apm_do_log = ENABLE_APM_LOG;
static void
apm_log(const char *fmt, ...)
{
@@ -44,17 +42,15 @@ apm_log(const char *fmt, ...)
}
}
#else
#define apm_log(fmt, ...)
# define apm_log(fmt, ...)
#endif
void
apm_set_do_smi(apm_t *dev, uint8_t do_smi)
{
dev->do_smi = do_smi;
}
static void
apm_out(uint16_t port, uint8_t val, void *p)
{
@@ -72,7 +68,6 @@ apm_out(uint16_t port, uint8_t val, void *p)
dev->stat = val;
}
static uint8_t
apm_in(uint16_t port, void *p)
{
@@ -91,27 +86,25 @@ apm_in(uint16_t port, void *p)
return ret;
}
static void
apm_reset(void *p)
{
apm_t *dev = (apm_t *)p;
apm_t *dev = (apm_t *) p;
dev->cmd = dev->stat = 0x00;
}
static void
apm_close(void *p)
{
apm_t *dev = (apm_t *)p;
apm_t *dev = (apm_t *) p;
free(dev);
}
static void
*apm_init(const device_t *info)
*
apm_init(const device_t *info)
{
apm_t *dev = (apm_t *) malloc(sizeof(apm_t));
memset(dev, 0, sizeof(apm_t));
@@ -122,7 +115,6 @@ static void
return dev;
}
const device_t apm_device = {
.name = "Advanced Power Management",
.internal_name = "apm",

View File

@@ -16,12 +16,12 @@
*/
#if defined(__arm__) || defined(__TARGET_ARCH_ARM)
#error ARCH arm
# error ARCH arm
#elif defined(__aarch64__) || defined(_M_ARM64)
#error ARCH arm64
# error ARCH arm64
#elif defined(__i386) || defined(__i386__) || defined(_M_IX86)
#error ARCH i386
# error ARCH i386
#elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64)
#error ARCH x86_64
# error ARCH x86_64
#endif
#error ARCH unknown

View File

@@ -73,7 +73,6 @@
#include <86box/ui.h>
#include <86box/snd_opl.h>
static int cx, cy, cw, ch;
static ini_t config;
@@ -796,10 +795,9 @@ load_network(void)
strcpy(net_cards_conf[c].host_dev_name, "none");
}
sprintf(temp, "net_%02i_link", c +1);
sprintf(temp, "net_%02i_link", c + 1);
net_cards_conf[c].link_state = ini_section_get_int(cat, temp,
(NET_LINK_10_HD|NET_LINK_10_FD|NET_LINK_100_HD|NET_LINK_100_FD|NET_LINK_1000_HD|NET_LINK_1000_FD));
(NET_LINK_10_HD | NET_LINK_10_FD | NET_LINK_100_HD | NET_LINK_100_FD | NET_LINK_1000_HD | NET_LINK_1000_FD));
}
}
@@ -1415,7 +1413,7 @@ load_floppy_and_cdrom_drives(void)
cdrom[c].image_history[i] = (char *) calloc(MAX_IMAGE_PATH_LEN + 1, sizeof(char));
sprintf(temp, "cdrom_%02i_image_history_%02i", c + 1, i + 1);
p = ini_section_get_string(cat, temp, NULL);
if(p) {
if (p) {
sprintf(cdrom[c].image_history[i], "%s", p);
}
}
@@ -2367,7 +2365,7 @@ save_network(void)
}
sprintf(temp, "net_%02i_link", c + 1);
if (net_cards_conf[c].link_state == (NET_LINK_10_HD|NET_LINK_10_FD|NET_LINK_100_HD|NET_LINK_100_FD|NET_LINK_1000_HD|NET_LINK_1000_FD)) {
if (net_cards_conf[c].link_state == (NET_LINK_10_HD | NET_LINK_10_FD | NET_LINK_100_HD | NET_LINK_100_FD | NET_LINK_1000_HD | NET_LINK_1000_FD)) {
ini_section_delete_var(cat, temp);
} else {
ini_section_set_int(cat, temp, net_cards_conf[c].link_state);
@@ -2392,12 +2390,12 @@ save_ports(void)
else
ini_section_set_int(cat, temp, com_ports[c].enabled);
/*
/*
sprintf(temp, "serial%d_type", c + 1);
if (!com_ports[c].enabled))
ini_section_delete_var(cat, temp);
// else
// ini_section_set_string(cat, temp, (char *) serial_type[c])
// else
// ini_section_set_string(cat, temp, (char *) serial_type[c])
sprintf(temp, "serial%d_device", c + 1);
if (com_ports[c].device == 0)
@@ -2733,7 +2731,7 @@ save_floppy_and_cdrom_drives(void)
for (int i = 0; i < MAX_PREV_IMAGES; i++) {
sprintf(temp, "cdrom_%02i_image_history_%02i", c + 1, i + 1);
if((cdrom[c].image_history[i] == 0) || strlen(cdrom[c].image_history[i]) == 0) {
if ((cdrom[c].image_history[i] == 0) || strlen(cdrom[c].image_history[i]) == 0) {
ini_section_delete_var(cat, temp);
} else {
ini_section_set_string(cat, temp, cdrom[c].image_history[i]);

View File

@@ -35,11 +35,9 @@
#include <86box/dma.h>
#include <86box/ddma.h>
#ifdef ENABLE_DDMA_LOG
int ddma_do_log = ENABLE_DDMA_LOG;
static void
ddma_log(const char *fmt, ...)
{
@@ -52,7 +50,7 @@ ddma_log(const char *fmt, ...)
}
}
#else
#define ddma_log(fmt, ...)
# define ddma_log(fmt, ...)
#endif
static uint8_t
@@ -87,7 +85,6 @@ ddma_reg_read(uint16_t addr, void *p)
return ret;
}
static void
ddma_reg_write(uint16_t addr, uint8_t val, void *p)
{
@@ -144,7 +141,6 @@ ddma_reg_write(uint16_t addr, uint8_t val, void *p)
}
}
void
ddma_update_io_mapping(ddma_t *dev, int ch, uint8_t base_l, uint8_t base_h, int enable)
{
@@ -158,7 +154,6 @@ ddma_update_io_mapping(ddma_t *dev, int ch, uint8_t base_l, uint8_t base_h, int
io_sethandler(dev->channels[ch].io_base, 0x10, ddma_reg_read, NULL, NULL, ddma_reg_write, NULL, NULL, &dev->channels[ch]);
}
static void
ddma_close(void *priv)
{
@@ -167,15 +162,15 @@ ddma_close(void *priv)
free(dev);
}
static void *
ddma_init(const device_t *info)
{
ddma_t *dev;
int i;
dev = (ddma_t *)malloc(sizeof(ddma_t));
if (dev == NULL) return(NULL);
dev = (ddma_t *) malloc(sizeof(ddma_t));
if (dev == NULL)
return (NULL);
memset(dev, 0x00, sizeof(ddma_t));
for (i = 0; i < 8; i++)

View File

@@ -53,19 +53,15 @@
#include <86box/rom.h>
#include <86box/sound.h>
#define DEVICE_MAX 256 /* max # of devices */
static device_t *devices[DEVICE_MAX];
static void *device_priv[DEVICE_MAX];
static device_context_t device_current, device_prev;
#ifdef ENABLE_DEVICE_LOG
int device_do_log = ENABLE_DEVICE_LOG;
static void
device_log(const char *fmt, ...)
{
@@ -78,10 +74,9 @@ device_log(const char *fmt, ...)
}
}
#else
#define device_log(fmt, ...)
# define device_log(fmt, ...)
#endif
/* Initialize the module for use. */
void
device_init(void)
@@ -89,7 +84,6 @@ device_init(void)
memset(devices, 0x00, sizeof(devices));
}
void
device_set_context(device_context_t *c, const device_t *d, int inst)
{
@@ -112,7 +106,6 @@ device_set_context(device_context_t *c, const device_t *d, int inst)
sprintf(c->name, "%s", d->name);
}
static void
device_context_common(const device_t *d, int inst)
{
@@ -120,28 +113,24 @@ device_context_common(const device_t *d, int inst)
device_set_context(&device_current, d, inst);
}
void
device_context(const device_t *d)
{
device_context_common(d, 0);
}
void
device_context_inst(const device_t *d, int inst)
{
device_context_common(d, inst);
}
void
device_context_restore(void)
{
memcpy(&device_current, &device_prev, sizeof(device_context_t));
}
static void *
device_add_common(const device_t *d, const device_t *cd, void *p, int inst)
{
@@ -153,14 +142,15 @@ device_add_common(const device_t *d, const device_t *cd, void *p, int inst)
device_log("DEVICE: device already exists!\n");
return (NULL);
}
if (devices[c] == NULL) break;
if (devices[c] == NULL)
break;
}
if (c >= DEVICE_MAX)
fatal("DEVICE: too many devices\n");
/* Do this so that a chained device_add will not identify the same ID
its master device is already trying to assign. */
devices[c] = (device_t *)d;
devices[c] = (device_t *) d;
if (p == NULL) {
memcpy(&device_prev, &device_current, sizeof(device_context_t));
@@ -177,7 +167,7 @@ device_add_common(const device_t *d, const device_t *cd, void *p, int inst)
devices[c] = NULL;
device_priv[c] = NULL;
return(NULL);
return (NULL);
}
}
@@ -191,10 +181,9 @@ device_add_common(const device_t *d, const device_t *cd, void *p, int inst)
} else
device_priv[c] = p;
return(priv);
return (priv);
}
char *
device_get_internal_name(const device_t *d)
{
@@ -204,14 +193,12 @@ device_get_internal_name(const device_t *d)
return (char *) d->internal_name;
}
void *
device_add(const device_t *d)
{
return device_add_common(d, d, NULL, 0);
}
/* For devices that do not have an init function (internal video etc.) */
void
device_add_ex(const device_t *d, void *priv)
@@ -219,14 +206,12 @@ device_add_ex(const device_t *d, void *priv)
device_add_common(d, d, priv, 0);
}
void *
device_add_inst(const device_t *d, int inst)
{
return device_add_common(d, d, NULL, inst);
}
/* For devices that do not have an init function (internal video etc.) */
void
device_add_inst_ex(const device_t *d, void *priv, int inst)
@@ -234,7 +219,6 @@ device_add_inst_ex(const device_t *d, void *priv, int inst)
device_add_common(d, d, priv, inst);
}
/* These four are to add a device with another device's context - will be
used to add machines' internal devices. */
void *
@@ -243,7 +227,6 @@ device_cadd(const device_t *d, const device_t *cd)
return device_add_common(d, cd, NULL, 0);
}
/* For devices that do not have an init function (internal video etc.) */
void
device_cadd_ex(const device_t *d, const device_t *cd, void *priv)
@@ -251,14 +234,12 @@ device_cadd_ex(const device_t *d, const device_t *cd, void *priv)
device_add_common(d, cd, priv, 0);
}
void *
device_cadd_inst(const device_t *d, const device_t *cd, int inst)
{
return device_add_common(d, cd, NULL, inst);
}
/* For devices that do not have an init function (internal video etc.) */
void
device_cadd_inst_ex(const device_t *d, const device_t *cd, void *priv, int inst)
@@ -266,7 +247,6 @@ device_cadd_inst_ex(const device_t *d, const device_t *cd, void *priv, int inst)
device_add_common(d, cd, priv, inst);
}
void
device_close_all(void)
{
@@ -283,7 +263,6 @@ device_close_all(void)
}
}
void
device_reset_all(void)
{
@@ -297,14 +276,13 @@ device_reset_all(void)
}
}
/* Reset all attached PCI devices - needed for PCI turbo reset control. */
void
device_reset_all_pci(void)
{
int c;
for (c=0; c<DEVICE_MAX; c++) {
for (c = 0; c < DEVICE_MAX; c++) {
if (devices[c] != NULL) {
if ((devices[c]->reset != NULL) && (devices[c]->flags & DEVICE_PCI))
devices[c]->reset(device_priv[c]);
@@ -312,7 +290,6 @@ device_reset_all_pci(void)
}
}
void *
device_get_priv(const device_t *d)
{
@@ -321,14 +298,13 @@ device_get_priv(const device_t *d)
for (c = 0; c < DEVICE_MAX; c++) {
if (devices[c] != NULL) {
if (devices[c] == d)
return(device_priv[c]);
return (device_priv[c]);
}
}
return(NULL);
return (NULL);
}
int
device_available(const device_t *d)
{
@@ -354,7 +330,7 @@ device_available(const device_t *d)
bios++;
}
return(roms_present ? -1 : 0);
return (roms_present ? -1 : 0);
}
config++;
}
@@ -362,16 +338,15 @@ device_available(const device_t *d)
/* No CONFIG_BIOS field present, use the classic available(). */
if (d->available != NULL)
return(d->available());
return (d->available());
else
return(1);
return (1);
}
/* A NULL device is never available. */
return(0);
return (0);
}
int
device_has_config(const device_t *d)
{
@@ -395,7 +370,6 @@ device_has_config(const device_t *d)
return (c > 0) ? 1 : 0;
}
int
device_poll(const device_t *d, int x, int y, int z, int b)
{
@@ -405,15 +379,14 @@ device_poll(const device_t *d, int x, int y, int z, int b)
if (devices[c] != NULL) {
if (devices[c] == d) {
if (devices[c]->poll)
return(devices[c]->poll(x, y, z, b, device_priv[c]));
return (devices[c]->poll(x, y, z, b, device_priv[c]));
}
}
}
return(0);
return (0);
}
void
device_register_pci_slot(const device_t *d, int device, int type, int inta, int intb, int intc, int intd)
{
@@ -432,7 +405,6 @@ device_register_pci_slot(const device_t *d, int device, int type, int inta, int
return;
}
void
device_get_name(const device_t *d, int bus, char *name)
{
@@ -475,7 +447,7 @@ device_get_name(const device_t *d, int bus, char *name)
/* Then change string from ISA16 to ISA if applicable. */
if (!strcmp(sbus, "ISA16"))
sbus = "ISA";
else if (!strcmp(sbus, "COM")|| !strcmp(sbus, "LPT")) {
else if (!strcmp(sbus, "COM") || !strcmp(sbus, "LPT")) {
sbus = NULL;
strcat(name, d->name);
return;
@@ -523,7 +495,6 @@ device_get_name(const device_t *d, int bus, char *name)
strcat(name, d->name);
}
void
device_speed_changed(void)
{
@@ -539,7 +510,6 @@ device_speed_changed(void)
sound_speed_changed();
}
void
device_force_redraw(void)
{
@@ -553,110 +523,103 @@ device_force_redraw(void)
}
}
const char *
device_get_config_string(const char *s)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_string((char *) device_current.name, (char *) s, (char *) c->default_string));
if (!strcmp(s, c->name))
return (config_get_string((char *) device_current.name, (char *) s, (char *) c->default_string));
c++;
}
return(NULL);
return (NULL);
}
int
device_get_config_int(const char *s)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_int((char *) device_current.name, (char *) s, c->default_int));
if (!strcmp(s, c->name))
return (config_get_int((char *) device_current.name, (char *) s, c->default_int));
c++;
}
return(0);
return (0);
}
int
device_get_config_int_ex(const char *s, int def)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_int((char *) device_current.name, (char *) s, def));
if (!strcmp(s, c->name))
return (config_get_int((char *) device_current.name, (char *) s, def));
c++;
}
return(def);
return (def);
}
int
device_get_config_hex16(const char *s)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_hex16((char *) device_current.name, (char *) s, c->default_int));
if (!strcmp(s, c->name))
return (config_get_hex16((char *) device_current.name, (char *) s, c->default_int));
c++;
}
return(0);
return (0);
}
int
device_get_config_hex20(const char *s)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_hex20((char *) device_current.name, (char *) s, c->default_int));
if (!strcmp(s, c->name))
return (config_get_hex20((char *) device_current.name, (char *) s, c->default_int));
c++;
}
return(0);
return (0);
}
int
device_get_config_mac(const char *s, int def)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_mac((char *) device_current.name, (char *) s, def));
if (!strcmp(s, c->name))
return (config_get_mac((char *) device_current.name, (char *) s, def));
c++;
}
return(def);
return (def);
}
void
device_set_config_int(const char *s, int val)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name)) {
if (!strcmp(s, c->name)) {
config_set_int((char *) device_current.name, (char *) s, val);
break;
}
@@ -665,14 +628,13 @@ device_set_config_int(const char *s, int val)
}
}
void
device_set_config_hex16(const char *s, int val)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name)) {
if (!strcmp(s, c->name)) {
config_set_hex16((char *) device_current.name, (char *) s, val);
break;
}
@@ -681,14 +643,13 @@ device_set_config_hex16(const char *s, int val)
}
}
void
device_set_config_hex20(const char *s, int val)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name)) {
if (!strcmp(s, c->name)) {
config_set_hex20((char *) device_current.name, (char *) s, val);
break;
}
@@ -697,14 +658,13 @@ device_set_config_hex20(const char *s, int val)
}
}
void
device_set_config_mac(const char *s, int val)
{
const device_config_t *c = device_current.dev->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name)) {
if (!strcmp(s, c->name)) {
config_set_mac((char *) device_current.name, (char *) s, val);
break;
}
@@ -713,71 +673,81 @@ device_set_config_mac(const char *s, int val)
}
}
int
device_is_valid(const device_t *device, int m)
{
if (device == NULL) return(1);
if (device == NULL)
return (1);
if ((device->flags & DEVICE_AT) && !machine_has_bus(m, MACHINE_BUS_ISA16)) return(0);
if ((device->flags & DEVICE_AT) && !machine_has_bus(m, MACHINE_BUS_ISA16))
return (0);
if ((device->flags & DEVICE_CBUS) && !machine_has_bus(m, MACHINE_BUS_CBUS)) return(0);
if ((device->flags & DEVICE_CBUS) && !machine_has_bus(m, MACHINE_BUS_CBUS))
return (0);
if ((device->flags & DEVICE_ISA) && !machine_has_bus(m, MACHINE_BUS_ISA)) return(0);
if ((device->flags & DEVICE_ISA) && !machine_has_bus(m, MACHINE_BUS_ISA))
return (0);
if ((device->flags & DEVICE_MCA) && !machine_has_bus(m, MACHINE_BUS_MCA)) return(0);
if ((device->flags & DEVICE_MCA) && !machine_has_bus(m, MACHINE_BUS_MCA))
return (0);
if ((device->flags & DEVICE_EISA) && !machine_has_bus(m, MACHINE_BUS_EISA)) return(0);
if ((device->flags & DEVICE_EISA) && !machine_has_bus(m, MACHINE_BUS_EISA))
return (0);
if ((device->flags & DEVICE_VLB) && !machine_has_bus(m, MACHINE_BUS_VLB)) return(0);
if ((device->flags & DEVICE_VLB) && !machine_has_bus(m, MACHINE_BUS_VLB))
return (0);
if ((device->flags & DEVICE_PCI) && !machine_has_bus(m, MACHINE_BUS_PCI)) return(0);
if ((device->flags & DEVICE_PCI) && !machine_has_bus(m, MACHINE_BUS_PCI))
return (0);
if ((device->flags & DEVICE_AGP) && !machine_has_bus(m, MACHINE_BUS_AGP)) return(0);
if ((device->flags & DEVICE_AGP) && !machine_has_bus(m, MACHINE_BUS_AGP))
return (0);
if ((device->flags & DEVICE_PS2) && !machine_has_bus(m, MACHINE_BUS_PS2)) return(0);
if ((device->flags & DEVICE_PS2) && !machine_has_bus(m, MACHINE_BUS_PS2))
return (0);
if ((device->flags & DEVICE_AC97) && !machine_has_bus(m, MACHINE_BUS_AC97)) return(0);
if ((device->flags & DEVICE_AC97) && !machine_has_bus(m, MACHINE_BUS_AC97))
return (0);
return(1);
return (1);
}
int
machine_get_config_int(char *s)
{
const device_t *d = machine_getdevice(machine);
const device_config_t *c;
if (d == NULL) return(0);
if (d == NULL)
return (0);
c = d->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_int((char *)d->name, s, c->default_int));
if (!strcmp(s, c->name))
return (config_get_int((char *) d->name, s, c->default_int));
c++;
}
return(0);
return (0);
}
char *
machine_get_config_string(char *s)
{
const device_t *d = machine_getdevice(machine);
const device_config_t *c;
if (d == NULL) return(0);
if (d == NULL)
return (0);
c = d->config;
while (c && c->type != -1) {
if (! strcmp(s, c->name))
return(config_get_string((char *)d->name, s, (char *)c->default_string));
if (!strcmp(s, c->name))
return (config_get_string((char *) d->name, s, (char *) c->default_string));
c++;
}
return(NULL);
return (NULL);
}

194
src/dma.c
View File

@@ -32,12 +32,10 @@
#include <86box/pic.h>
#include <86box/dma.h>
dma_t dma[8];
uint8_t dma_e;
uint8_t dma_m;
static uint8_t dmaregs[3][16];
static int dma_wp[2];
static uint8_t dma_stat;
@@ -60,7 +58,6 @@ static struct {
int is_ps2;
} dma_ps2;
#define DMA_PS2_IOA (1 << 0)
#define DMA_PS2_AUTOINIT (1 << 1)
#define DMA_PS2_XFER_MEM_TO_IO (1 << 2)
@@ -69,11 +66,9 @@ static struct {
#define DMA_PS2_DEC2 (1 << 4)
#define DMA_PS2_SIZE16 (1 << 6)
#ifdef ENABLE_DMA_LOG
int dma_do_log = ENABLE_DMA_LOG;
static void
dma_log(const char *fmt, ...)
{
@@ -86,20 +81,17 @@ dma_log(const char *fmt, ...)
}
}
#else
#define dma_log(fmt, ...)
# define dma_log(fmt, ...)
#endif
static void dma_ps2_run(int channel);
int
dma_get_drq(int channel)
{
return !!(dma_stat_rq_pc & (1 << channel));
}
void
dma_set_drq(int channel, int set)
{
@@ -108,21 +100,19 @@ dma_set_drq(int channel, int set)
dma_stat_rq_pc |= (1 << channel);
}
static int
dma_transfer_size(dma_t *dev)
{
return dev->transfer_mode & 0xff;
}
static void
dma_sg_next_addr(dma_t *dev)
{
int ts = dma_transfer_size(dev);
dma_bm_read(dev->ptr_cur, (uint8_t *)&(dev->addr), 4, ts);
dma_bm_read(dev->ptr_cur + 4, (uint8_t *)&(dev->count), 4, ts);
dma_bm_read(dev->ptr_cur, (uint8_t *) &(dev->addr), 4, ts);
dma_bm_read(dev->ptr_cur + 4, (uint8_t *) &(dev->count), 4, ts);
dma_log("DMA S/G DWORDs: %08X %08X\n", dev->addr, dev->count);
dev->eot = dev->count >> 31;
dev->count &= 0xfffe;
@@ -139,7 +129,6 @@ dma_sg_next_addr(dma_t *dev)
dev->ptr_cur += 8;
}
static void
dma_block_transfer(int channel)
{
@@ -167,7 +156,6 @@ dma_block_transfer(int channel)
dma_req_is_soft = 0;
}
static void
dma_mem_to_mem_transfer(void)
{
@@ -189,7 +177,6 @@ dma_mem_to_mem_transfer(void)
dma_req_is_soft = 0;
}
static void
dma_sg_write(uint16_t port, uint8_t val, void *priv)
{
@@ -244,7 +231,6 @@ dma_sg_write(uint16_t port, uint8_t val, void *priv)
}
}
static void
dma_sg_writew(uint16_t port, uint16_t val, void *priv)
{
@@ -275,7 +261,6 @@ dma_sg_writew(uint16_t port, uint16_t val, void *priv)
}
}
static void
dma_sg_writel(uint16_t port, uint32_t val, void *priv)
{
@@ -302,7 +287,6 @@ dma_sg_writel(uint16_t port, uint32_t val, void *priv)
}
}
static uint8_t
dma_sg_read(uint16_t port, void *priv)
{
@@ -348,7 +332,6 @@ dma_sg_read(uint16_t port, void *priv)
return ret;
}
static uint16_t
dma_sg_readw(uint16_t port, void *priv)
{
@@ -380,7 +363,6 @@ dma_sg_readw(uint16_t port, void *priv)
return ret;
}
static uint32_t
dma_sg_readl(uint16_t port, void *priv)
{
@@ -409,7 +391,6 @@ dma_sg_readl(uint16_t port, void *priv)
return ret;
}
static void
dma_ext_mode_write(uint16_t addr, uint8_t val, void *priv)
{
@@ -438,7 +419,6 @@ dma_ext_mode_write(uint16_t addr, uint8_t val, void *priv)
}
}
static uint8_t
dma_sg_int_status_read(uint16_t addr, void *priv)
{
@@ -453,7 +433,6 @@ dma_sg_int_status_read(uint16_t addr, void *priv)
return ret;
}
static uint8_t
dma_read(uint16_t addr, void *priv)
{
@@ -467,8 +446,8 @@ dma_read(uint16_t addr, void *priv)
case 6: /*Address registers*/
dma_wp[0] ^= 1;
if (dma_wp[0])
return(dma[channel].ac & 0xff);
return((dma[channel].ac >> 8) & 0xff);
return (dma[channel].ac & 0xff);
return ((dma[channel].ac >> 8) & 0xff);
case 1:
case 3:
@@ -479,23 +458,22 @@ dma_read(uint16_t addr, void *priv)
temp = dma[channel].cc & 0xff;
else
temp = dma[channel].cc >> 8;
return(temp);
return (temp);
case 8: /*Status register*/
temp = dma_stat_rq_pc & 0xf;
temp <<= 4;
temp |= dma_stat & 0xf;
dma_stat &= ~0xf;
return(temp);
return (temp);
case 0xd: /*Temporary register*/
return(0);
return (0);
}
return(dmaregs[0][addr & 0xf]);
return (dmaregs[0][addr & 0xf]);
}
static void
dma_write(uint16_t addr, uint8_t val, void *priv)
{
@@ -588,7 +566,6 @@ dma_write(uint16_t addr, uint8_t val, void *priv)
}
}
static uint8_t
dma_ps2_read(uint16_t addr, void *priv)
{
@@ -651,10 +628,9 @@ dma_ps2_read(uint16_t addr, void *priv)
}
break;
}
return(temp);
return (temp);
}
static void
dma_ps2_write(uint16_t addr, uint8_t val, void *priv)
{
@@ -747,7 +723,6 @@ dma_ps2_write(uint16_t addr, uint8_t val, void *priv)
}
}
static uint8_t
dma16_read(uint16_t addr, void *priv)
{
@@ -763,12 +738,12 @@ dma16_read(uint16_t addr, void *priv)
dma_wp[1] ^= 1;
if (dma_ps2.is_ps2) {
if (dma_wp[1])
return(dma[channel].ac);
return((dma[channel].ac >> 8) & 0xff);
return (dma[channel].ac);
return ((dma[channel].ac >> 8) & 0xff);
}
if (dma_wp[1])
return((dma[channel].ac >> 1) & 0xff);
return((dma[channel].ac >> 9) & 0xff);
return ((dma[channel].ac >> 1) & 0xff);
return ((dma[channel].ac >> 9) & 0xff);
case 1:
case 3:
@@ -779,19 +754,18 @@ dma16_read(uint16_t addr, void *priv)
temp = dma[channel].cc & 0xff;
else
temp = dma[channel].cc >> 8;
return(temp);
return (temp);
case 8: /*Status register*/
temp = (dma_stat_rq_pc & 0xf0);
temp |= dma_stat >> 4;
dma_stat &= ~0xf0;
return(temp);
return (temp);
}
return(dmaregs[1][addr & 0xf]);
return (dmaregs[1][addr & 0xf]);
}
static void
dma16_write(uint16_t addr, uint8_t val, void *priv)
{
@@ -885,9 +859,10 @@ dma16_write(uint16_t addr, uint8_t val, void *priv)
}
}
#define CHANNELS { 8, 2, 3, 1, 8, 8, 8, 0 }
#define CHANNELS \
{ \
8, 2, 3, 1, 8, 8, 8, 0 \
}
static void
dma_page_write(uint16_t addr, uint8_t val, void *priv)
@@ -922,7 +897,6 @@ dma_page_write(uint16_t addr, uint8_t val, void *priv)
}
}
static uint8_t
dma_page_read(uint16_t addr, void *priv)
{
@@ -943,7 +917,6 @@ dma_page_read(uint16_t addr, void *priv)
return ret;
}
static void
dma_high_page_write(uint16_t addr, uint8_t val, void *priv)
{
@@ -964,7 +937,6 @@ dma_high_page_write(uint16_t addr, uint8_t val, void *priv)
}
}
static uint8_t
dma_high_page_read(uint16_t addr, void *priv)
{
@@ -984,7 +956,6 @@ dma_high_page_read(uint16_t addr, void *priv)
return ret;
}
void
dma_set_params(uint8_t advanced, uint32_t mask)
{
@@ -992,7 +963,6 @@ dma_set_params(uint8_t advanced, uint32_t mask)
dma_mask = mask;
}
void
dma_set_mask(uint32_t mask)
{
@@ -1006,14 +976,12 @@ dma_set_mask(uint32_t mask)
}
}
void
dma_set_at(uint8_t at)
{
dma_at = at;
}
void
dma_reset(void)
{
@@ -1050,7 +1018,6 @@ dma_reset(void)
dma_at = is286;
}
void
dma_remove_sg(void)
{
@@ -1077,7 +1044,6 @@ dma_remove_sg(void)
}
}
void
dma_set_sg_base(uint8_t sg_base)
{
@@ -1106,115 +1072,104 @@ dma_set_sg_base(uint8_t sg_base)
}
}
void
dma_ext_mode_init(void)
{
io_sethandler(0x040b, 0x01,
NULL,NULL,NULL, dma_ext_mode_write,NULL,NULL, NULL);
NULL, NULL, NULL, dma_ext_mode_write, NULL, NULL, NULL);
io_sethandler(0x04d6, 0x01,
NULL,NULL,NULL, dma_ext_mode_write,NULL,NULL, NULL);
NULL, NULL, NULL, dma_ext_mode_write, NULL, NULL, NULL);
}
void
dma_high_page_init(void)
{
io_sethandler(0x0480, 8,
dma_high_page_read,NULL,NULL, dma_high_page_write,NULL,NULL, NULL);
dma_high_page_read, NULL, NULL, dma_high_page_write, NULL, NULL, NULL);
}
void
dma_init(void)
{
dma_reset();
io_sethandler(0x0000, 16,
dma_read,NULL,NULL, dma_write,NULL,NULL, NULL);
dma_read, NULL, NULL, dma_write, NULL, NULL, NULL);
io_sethandler(0x0080, 8,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
dma_ps2.is_ps2 = 0;
}
void
dma16_init(void)
{
dma_reset();
io_sethandler(0x00C0, 32,
dma16_read,NULL,NULL, dma16_write,NULL,NULL, NULL);
dma16_read, NULL, NULL, dma16_write, NULL, NULL, NULL);
io_sethandler(0x0088, 8,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
}
void
dma_alias_set(void)
{
io_sethandler(0x0090, 2,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_sethandler(0x0093, 13,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
}
void
dma_alias_set_piix(void)
{
io_sethandler(0x0090, 1,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_sethandler(0x0094, 3,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_sethandler(0x0098, 1,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_sethandler(0x009C, 3,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
}
void
dma_alias_remove(void)
{
io_removehandler(0x0090, 2,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_removehandler(0x0093, 13,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
}
void
dma_alias_remove_piix(void)
{
io_removehandler(0x0090, 1,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_removehandler(0x0094, 3,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_removehandler(0x0098, 1,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
io_removehandler(0x009C, 3,
dma_page_read,NULL,NULL, dma_page_write,NULL,NULL, NULL);
dma_page_read, NULL, NULL, dma_page_write, NULL, NULL, NULL);
}
void
ps2_dma_init(void)
{
dma_reset();
io_sethandler(0x0018, 1,
dma_ps2_read,NULL,NULL, dma_ps2_write,NULL,NULL, NULL);
dma_ps2_read, NULL, NULL, dma_ps2_write, NULL, NULL, NULL);
io_sethandler(0x001a, 1,
dma_ps2_read,NULL,NULL, dma_ps2_write,NULL,NULL, NULL);
dma_ps2_read, NULL, NULL, dma_ps2_write, NULL, NULL, NULL);
dma_ps2.is_ps2 = 1;
}
extern void dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int TransferSize);
extern void dma_bm_write(uint32_t PhysAddress, const uint8_t *DataWrite, uint32_t TotalSize, int TransferSize);
static int
dma_sg(uint8_t *data, int transfer_length, int out, void *priv)
{
@@ -1238,17 +1193,17 @@ dma_sg(uint8_t *data, int transfer_length, int out, void *priv)
if (dev->count <= transfer_length) {
dma_log("%sing %i bytes to %08X\n", sop, dev->count, dev->addr);
if (out)
dma_bm_read(dev->addr, (uint8_t *)(data + buffer_pos), dev->count, 4);
dma_bm_read(dev->addr, (uint8_t *) (data + buffer_pos), dev->count, 4);
else
dma_bm_write(dev->addr, (uint8_t *)(data + buffer_pos), dev->count, 4);
dma_bm_write(dev->addr, (uint8_t *) (data + buffer_pos), dev->count, 4);
transfer_length -= dev->count;
buffer_pos += dev->count;
} else {
dma_log("%sing %i bytes to %08X\n", sop, transfer_length, dev->addr);
if (out)
dma_bm_read(dev->addr, (uint8_t *)(data + buffer_pos), transfer_length, 4);
dma_bm_read(dev->addr, (uint8_t *) (data + buffer_pos), transfer_length, 4);
else
dma_bm_write(dev->addr, (uint8_t *)(data + buffer_pos), transfer_length, 4);
dma_bm_write(dev->addr, (uint8_t *) (data + buffer_pos), transfer_length, 4);
/* Increase addr and decrease count so that resumed transfers do not mess up. */
dev->addr += transfer_length;
dev->count -= transfer_length;
@@ -1279,7 +1234,6 @@ dma_sg(uint8_t *data, int transfer_length, int out, void *priv)
return 1;
}
uint8_t
_dma_read(uint32_t addr, dma_t *dma_c)
{
@@ -1293,10 +1247,9 @@ _dma_read(uint32_t addr, dma_t *dma_c)
} else
temp = mem_readb_phys(addr);
return(temp);
return (temp);
}
static uint16_t
_dma_readw(uint32_t addr, dma_t *dma_c)
{
@@ -1310,10 +1263,9 @@ _dma_readw(uint32_t addr, dma_t *dma_c)
} else
temp = _dma_read(addr, dma_c) | (_dma_read(addr + 1, dma_c) << 8);
return(temp);
return (temp);
}
static void
_dma_write(uint32_t addr, uint8_t val, dma_t *dma_c)
{
@@ -1329,7 +1281,6 @@ _dma_write(uint32_t addr, uint8_t val, dma_t *dma_c)
}
}
static void
_dma_writew(uint32_t addr, uint16_t val, dma_t *dma_c)
{
@@ -1344,7 +1295,6 @@ _dma_writew(uint32_t addr, uint16_t val, dma_t *dma_c)
}
}
static void
dma_retreat(dma_t *dma_c)
{
@@ -1361,7 +1311,6 @@ dma_retreat(dma_t *dma_c)
dma_c->ac = ((dma_c->ac & 0xffff0000) & dma_mask) | ((dma_c->ac - as) & 0xffff);
}
void
dma_advance(dma_t *dma_c)
{
@@ -1378,7 +1327,6 @@ dma_advance(dma_t *dma_c)
dma_c->ac = ((dma_c->ac & 0xffff0000) & dma_mask) | ((dma_c->ac + as) & 0xffff);
}
int
dma_channel_read(int channel)
{
@@ -1388,23 +1336,23 @@ dma_channel_read(int channel)
if (channel < 4) {
if (dma_command[0] & 0x04)
return(DMA_NODATA);
return (DMA_NODATA);
} else {
if (dma_command[1] & 0x04)
return(DMA_NODATA);
return (DMA_NODATA);
}
if (!(dma_e & (1 << channel)))
return(DMA_NODATA);
return (DMA_NODATA);
if ((dma_m & (1 << channel)) && !dma_req_is_soft)
return(DMA_NODATA);
return (DMA_NODATA);
if ((dma_c->mode & 0xC) != 8)
return(DMA_NODATA);
return (DMA_NODATA);
if (!dma_at && !channel)
refreshread();
if (! dma_c->size) {
if (!dma_c->size) {
temp = _dma_read(dma_c->ac, dma_c);
if (dma_c->mode & 0x20) {
@@ -1465,13 +1413,12 @@ dma_channel_read(int channel)
dma_c->sg_status |= 8;
}
return(temp | DMA_OVER);
return (temp | DMA_OVER);
}
return(temp);
return (temp);
}
int
dma_channel_write(int channel, uint16_t val)
{
@@ -1479,20 +1426,20 @@ dma_channel_write(int channel, uint16_t val)
if (channel < 4) {
if (dma_command[0] & 0x04)
return(DMA_NODATA);
return (DMA_NODATA);
} else {
if (dma_command[1] & 0x04)
return(DMA_NODATA);
return (DMA_NODATA);
}
if (!(dma_e & (1 << channel)))
return(DMA_NODATA);
return (DMA_NODATA);
if ((dma_m & (1 << channel)) && !dma_req_is_soft)
return(DMA_NODATA);
return (DMA_NODATA);
if ((dma_c->mode & 0xC) != 4)
return(DMA_NODATA);
return (DMA_NODATA);
if (! dma_c->size) {
if (!dma_c->size) {
_dma_write(dma_c->ac, val & 0xff, dma_c);
if (dma_c->mode & 0x20) {
@@ -1553,13 +1500,12 @@ dma_channel_write(int channel, uint16_t val)
dma_c->sg_status |= 8;
}
return(DMA_OVER);
return (DMA_OVER);
}
return(0);
return (0);
}
static void
dma_ps2_run(int channel)
{
@@ -1568,7 +1514,7 @@ dma_ps2_run(int channel)
switch (dma_c->ps2_mode & DMA_PS2_XFER_MASK) {
case DMA_PS2_XFER_MEM_TO_IO:
do {
if (! dma_c->size) {
if (!dma_c->size) {
uint8_t temp = _dma_read(dma_c->ac, dma_c);
outb(dma_c->io_addr, temp);
@@ -1597,7 +1543,7 @@ dma_ps2_run(int channel)
case DMA_PS2_XFER_IO_TO_MEM:
do {
if (! dma_c->size) {
if (!dma_c->size) {
uint8_t temp = inb(dma_c->io_addr);
_dma_write(dma_c->ac, temp, dma_c);
@@ -1627,7 +1573,7 @@ dma_ps2_run(int channel)
default: /*Memory verify*/
do {
if (! dma_c->size) {
if (!dma_c->size) {
if (dma_c->ps2_mode & DMA_PS2_DEC2)
dma_c->ac--;
else
@@ -1645,18 +1591,15 @@ dma_ps2_run(int channel)
dma_stat |= (1 << channel);
break;
}
}
int
dma_mode(int channel)
{
return(dma[channel].mode);
return (dma[channel].mode);
}
/* DMA Bus Master Page Read/Write */
void
dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int TransferSize)
@@ -1680,7 +1623,6 @@ dma_bm_read(uint32_t PhysAddress, uint8_t *DataRead, uint32_t TotalSize, int Tra
}
}
void
dma_bm_write(uint32_t PhysAddress, const uint8_t *DataWrite, uint32_t TotalSize, int TransferSize)
{

View File

@@ -21,16 +21,18 @@
#include <86box/86box.h>
#include <86box/fifo8.h>
void fifo8_create(Fifo8 *fifo, uint32_t capacity)
void
fifo8_create(Fifo8 *fifo, uint32_t capacity)
{
fifo->data = (uint8_t *)malloc(capacity);
fifo->data = (uint8_t *) malloc(capacity);
memset(fifo->data, 0, capacity);
fifo->capacity = capacity;
fifo->head = 0;
fifo->num = 0;
}
void fifo8_destroy(Fifo8 *fifo)
void
fifo8_destroy(Fifo8 *fifo)
{
if (fifo->data) {
free(fifo->data);
@@ -38,14 +40,16 @@ void fifo8_destroy(Fifo8 *fifo)
}
}
void fifo8_push(Fifo8 *fifo, uint8_t data)
void
fifo8_push(Fifo8 *fifo, uint8_t data)
{
assert(fifo->num < fifo->capacity);
fifo->data[(fifo->head + fifo->num) % fifo->capacity] = data;
fifo->num++;
}
void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num)
void
fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num)
{
uint32_t start, avail;
@@ -64,7 +68,8 @@ void fifo8_push_all(Fifo8 *fifo, const uint8_t *data, uint32_t num)
fifo->num += num;
}
uint8_t fifo8_pop(Fifo8 *fifo)
uint8_t
fifo8_pop(Fifo8 *fifo)
{
uint8_t ret;
@@ -75,7 +80,8 @@ uint8_t fifo8_pop(Fifo8 *fifo)
return ret;
}
const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num)
const uint8_t *
fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num)
{
uint8_t *ret;
@@ -88,28 +94,33 @@ const uint8_t *fifo8_pop_buf(Fifo8 *fifo, uint32_t max, uint32_t *num)
return ret;
}
void fifo8_reset(Fifo8 *fifo)
void
fifo8_reset(Fifo8 *fifo)
{
fifo->num = 0;
fifo->head = 0;
}
int fifo8_is_empty(Fifo8 *fifo)
int
fifo8_is_empty(Fifo8 *fifo)
{
return (fifo->num == 0);
}
int fifo8_is_full(Fifo8 *fifo)
int
fifo8_is_full(Fifo8 *fifo)
{
return (fifo->num == fifo->capacity);
}
uint32_t fifo8_num_free(Fifo8 *fifo)
uint32_t
fifo8_num_free(Fifo8 *fifo)
{
return fifo->capacity - fifo->num;
}
uint32_t fifo8_num_used(Fifo8 *fifo)
uint32_t
fifo8_num_used(Fifo8 *fifo)
{
return fifo->num;
}

View File

@@ -121,7 +121,7 @@ typedef struct _gdbstub_client_ {
struct sockaddr_in addr;
char packet[16384], response[16384];
int has_packet: 1, first_packet_received: 1, ida_mode: 1, waiting_stop: 1,
int has_packet : 1, first_packet_received : 1, ida_mode : 1, waiting_stop : 1,
packet_pos, response_pos;
event_t *processed_event, *response_event;

View File

@@ -30,10 +30,8 @@
#include "cpu.h"
#include <86box/m_amstrad.h>
#define NPORTS 65536 /* PC/AT supports 64K ports */
typedef struct _io_ {
uint8_t (*inb)(uint16_t addr, void *priv);
uint16_t (*inw)(uint16_t addr, void *priv);
@@ -58,11 +56,9 @@ typedef struct {
int initialized = 0;
io_t *io[NPORTS], *io_last[NPORTS];
#ifdef ENABLE_IO_LOG
int io_do_log = ENABLE_IO_LOG;
static void
io_log(const char *fmt, ...)
{
@@ -75,10 +71,9 @@ io_log(const char *fmt, ...)
}
}
#else
#define io_log(fmt, ...)
# define io_log(fmt, ...)
#endif
void
io_init(void)
{
@@ -86,12 +81,12 @@ io_init(void)
io_t *p, *q;
if (!initialized) {
for (c=0; c<NPORTS; c++)
for (c = 0; c < NPORTS; c++)
io[c] = io_last[c] = NULL;
initialized = 1;
}
for (c=0; c<NPORTS; c++) {
for (c = 0; c < NPORTS; c++) {
if (io_last[c]) {
/* Port c has at least one handler. */
p = io_last[c];
@@ -109,7 +104,6 @@ io_init(void)
}
}
void
io_sethandler_common(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -150,7 +144,6 @@ io_sethandler_common(uint16_t base, int size,
}
}
void
io_removehandler_common(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -168,12 +161,9 @@ io_removehandler_common(uint16_t base, int size,
p = io[base + c];
if (!p)
continue;
while(p) {
while (p) {
q = p->next;
if ((p->inb == inb) && (p->inw == inw) &&
(p->inl == inl) && (p->outb == outb) &&
(p->outw == outw) && (p->outl == outl) &&
(p->priv == priv)) {
if ((p->inb == inb) && (p->inw == inw) && (p->inl == inl) && (p->outb == outb) && (p->outw == outw) && (p->outl == outl) && (p->priv == priv)) {
if (p->prev)
p->prev->next = p->next;
else
@@ -191,7 +181,6 @@ io_removehandler_common(uint16_t base, int size,
}
}
void
io_handler_common(int set, uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -208,7 +197,6 @@ io_handler_common(int set, uint16_t base, int size,
io_removehandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, step);
}
void
io_sethandler(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -222,7 +210,6 @@ io_sethandler(uint16_t base, int size,
io_sethandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 1);
}
void
io_removehandler(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -236,7 +223,6 @@ io_removehandler(uint16_t base, int size,
io_removehandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 1);
}
void
io_handler(int set, uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -250,7 +236,6 @@ io_handler(int set, uint16_t base, int size,
io_handler_common(set, base, size, inb, inw, inl, outb, outw, outl, priv, 1);
}
void
io_sethandler_interleaved(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -264,7 +249,6 @@ io_sethandler_interleaved(uint16_t base, int size,
io_sethandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 2);
}
void
io_removehandler_interleaved(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -278,7 +262,6 @@ io_removehandler_interleaved(uint16_t base, int size,
io_removehandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 2);
}
void
io_handler_interleaved(int set, uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv),
@@ -292,7 +275,6 @@ io_handler_interleaved(int set, uint16_t base, int size,
io_handler_common(set, base, size, inb, inw, inl, outb, outw, outl, priv, 2);
}
uint8_t
inb(uint16_t port)
{
@@ -302,7 +284,7 @@ inb(uint16_t port)
int qfound = 0;
p = io[port];
while(p) {
while (p) {
q = p->next;
if (p->inb) {
ret &= p->inb(port, p->priv);
@@ -330,10 +312,9 @@ inb(uint16_t port)
io_log("[%04X:%08X] (%i, %i, %04i) in b(%04X) = %02X\n", CS, cpu_state.pc, in_smm, found, qfound, port, ret);
return(ret);
return (ret);
}
void
outb(uint16_t port, uint8_t val)
{
@@ -342,7 +323,7 @@ outb(uint16_t port, uint8_t val)
int qfound = 0;
p = io[port];
while(p) {
while (p) {
q = p->next;
if (p->outb) {
p->outb(port, val, p->priv);
@@ -365,7 +346,6 @@ outb(uint16_t port, uint8_t val)
return;
}
uint16_t
inw(uint16_t port)
{
@@ -377,7 +357,7 @@ inw(uint16_t port)
int i = 0;
p = io[port];
while(p) {
while (p) {
q = p->next;
if (p->inw) {
ret &= p->inw(port, p->priv);
@@ -391,7 +371,7 @@ inw(uint16_t port)
ret8[1] = (ret >> 8) & 0xff;
for (i = 0; i < 2; i++) {
p = io[(port + i) & 0xffff];
while(p) {
while (p) {
q = p->next;
if (p->inb && !p->inw) {
ret8[i] &= p->inb(port + i, p->priv);
@@ -420,7 +400,6 @@ inw(uint16_t port)
return ret;
}
void
outw(uint16_t port, uint16_t val)
{
@@ -430,7 +409,7 @@ outw(uint16_t port, uint16_t val)
int i = 0;
p = io[port];
while(p) {
while (p) {
q = p->next;
if (p->outw) {
p->outw(port, val, p->priv);
@@ -442,7 +421,7 @@ outw(uint16_t port, uint16_t val)
for (i = 0; i < 2; i++) {
p = io[(port + i) & 0xffff];
while(p) {
while (p) {
q = p->next;
if (p->outb && !p->outw) {
p->outb(port + i, val >> (i << 3), p->priv);
@@ -466,7 +445,6 @@ outw(uint16_t port, uint16_t val)
return;
}
uint32_t
inl(uint16_t port)
{
@@ -479,7 +457,7 @@ inl(uint16_t port)
int i = 0;
p = io[port];
while(p) {
while (p) {
q = p->next;
if (p->inl) {
ret &= p->inl(port, p->priv);
@@ -520,7 +498,7 @@ inl(uint16_t port)
ret8[3] = (ret >> 24) & 0xff;
for (i = 0; i < 4; i++) {
p = io[(port + i) & 0xffff];
while(p) {
while (p) {
q = p->next;
if (p->inb && !p->inw && !p->inl) {
ret8[i] &= p->inb(port + i, p->priv);
@@ -549,7 +527,6 @@ inl(uint16_t port)
return ret;
}
void
outl(uint16_t port, uint32_t val)
{
@@ -560,7 +537,7 @@ outl(uint16_t port, uint32_t val)
p = io[port];
if (p) {
while(p) {
while (p) {
q = p->next;
if (p->outl) {
p->outl(port, val, p->priv);
@@ -573,7 +550,7 @@ outl(uint16_t port, uint32_t val)
for (i = 0; i < 4; i += 2) {
p = io[(port + i) & 0xffff];
while(p) {
while (p) {
q = p->next;
if (p->outw && !p->outl) {
p->outw(port + i, val >> (i << 3), p->priv);
@@ -586,7 +563,7 @@ outl(uint16_t port, uint32_t val)
for (i = 0; i < 4; i++) {
p = io[(port + i) & 0xffff];
while(p) {
while (p) {
q = p->next;
if (p->outb && !p->outw && !p->outl) {
p->outb(port + i, val >> (i << 3), p->priv);
@@ -610,7 +587,6 @@ outl(uint16_t port, uint32_t val)
return;
}
static uint8_t
io_trap_readb(uint16_t addr, void *priv)
{
@@ -619,7 +595,6 @@ io_trap_readb(uint16_t addr, void *priv)
return 0xff;
}
static uint16_t
io_trap_readw(uint16_t addr, void *priv)
{
@@ -628,7 +603,6 @@ io_trap_readw(uint16_t addr, void *priv)
return 0xffff;
}
static uint32_t
io_trap_readl(uint16_t addr, void *priv)
{
@@ -637,7 +611,6 @@ io_trap_readl(uint16_t addr, void *priv)
return 0xffffffff;
}
static void
io_trap_writeb(uint16_t addr, uint8_t val, void *priv)
{
@@ -645,7 +618,6 @@ io_trap_writeb(uint16_t addr, uint8_t val, void *priv)
trap->func(1, addr, 1, val, trap->priv);
}
static void
io_trap_writew(uint16_t addr, uint16_t val, void *priv)
{
@@ -653,7 +625,6 @@ io_trap_writew(uint16_t addr, uint16_t val, void *priv)
trap->func(2, addr, 1, val, trap->priv);
}
static void
io_trap_writel(uint16_t addr, uint32_t val, void *priv)
{
@@ -661,7 +632,6 @@ io_trap_writel(uint16_t addr, uint32_t val, void *priv)
trap->func(4, addr, 1, val, trap->priv);
}
void *
io_trap_add(void (*func)(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv),
void *priv)
@@ -676,7 +646,6 @@ io_trap_add(void (*func)(int size, uint16_t addr, uint8_t write, uint8_t val, vo
return trap;
}
void
io_trap_remap(void *handle, int enable, uint16_t addr, uint16_t size)
{
@@ -709,7 +678,6 @@ io_trap_remap(void *handle, int enable, uint16_t addr, uint16_t size)
}
}
void
io_trap_remove(void *handle)
{

View File

@@ -28,16 +28,13 @@
#include <86box/mem.h>
#include <86box/chipset.h>
typedef struct {
uint8_t dummy;
} ioapic_t;
#ifdef ENABLE_IOAPIC_LOG
int ioapic_do_log = ENABLE_IOAPIC_LOG;
static void
ioapic_log(const char *fmt, ...)
{
@@ -50,10 +47,9 @@ ioapic_log(const char *fmt, ...)
}
}
#else
#define ioapic_log(fmt, ...)
# define ioapic_log(fmt, ...)
#endif
static void
ioapic_write(uint16_t port, uint8_t val, void *priv)
{
@@ -86,13 +82,11 @@ ioapic_write(uint16_t port, uint8_t val, void *priv)
}
}
static void
ioapic_reset(ioapic_t *dev)
{
}
static void
ioapic_close(void *priv)
{
@@ -104,7 +98,6 @@ ioapic_close(void *priv)
free(dev);
}
static void *
ioapic_init(const device_t *info)
{
@@ -119,7 +112,6 @@ ioapic_init(const device_t *info)
return dev;
}
const device_t ioapic_device = {
.name = "I/O Advanced Programmable Interrupt Controller",
.internal_name = "ioapic",

View File

@@ -34,7 +34,6 @@
#include <86box/version.h>
#include <86box/log.h>
#ifndef RELEASE_BUILD
typedef struct
{
@@ -42,10 +41,8 @@ typedef struct
int seen, suppr_seen;
} log_t;
extern FILE *stdlog; /* file to log output to */
void
log_set_suppr_seen(void *priv, int suppr_seen)
{
@@ -54,7 +51,6 @@ log_set_suppr_seen(void *priv, int suppr_seen)
log->suppr_seen = suppr_seen;
}
void
log_set_dev_name(void *priv, char *dev_name)
{
@@ -63,7 +59,6 @@ log_set_dev_name(void *priv, char *dev_name)
log->dev_name = dev_name;
}
static void
log_copy(log_t *log, char *dest, const char *src, size_t dest_size)
{
@@ -75,7 +70,6 @@ log_copy(log_t *log, char *dest, const char *src, size_t dest_size)
strcat(dest, src);
}
/*
* Log something to the logfile or stdout.
*
@@ -105,7 +99,7 @@ log_out(void *priv, const char *fmt, va_list ap)
}
vsprintf(temp, fmt, ap);
if (log->suppr_seen && ! strcmp(log->buff, temp))
if (log->suppr_seen && !strcmp(log->buff, temp))
log->seen++;
else {
if (log->suppr_seen && log->seen) {
@@ -121,7 +115,6 @@ log_out(void *priv, const char *fmt, va_list ap)
fflush(stdlog);
}
void
log_fatal(void *priv, const char *fmt, ...)
{
@@ -140,7 +133,6 @@ log_fatal(void *priv, const char *fmt, ...)
exit(-1);
}
void *
log_open(char *dev_name)
{
@@ -154,7 +146,6 @@ log_open(char *dev_name)
return (void *) log;
}
void
log_close(void *priv)
{

View File

@@ -26,7 +26,8 @@
machine_status_t machine_status;
void
machine_status_init() {
machine_status_init()
{
for (size_t i = 0; i < FDD_NUM; ++i) {
machine_status.fdd[i].empty = (strlen(floppyfns[i]) == 0);
machine_status.fdd[i].active = false;

View File

@@ -5,7 +5,6 @@
#include <86box/io.h>
#include <86box/mca.h>
void (*mca_card_write[8])(int addr, uint8_t val, void *priv);
uint8_t (*mca_card_read[8])(int addr, void *priv);
uint8_t (*mca_card_feedb[8])(void *priv);
@@ -15,8 +14,8 @@ void *mca_priv[8];
static int mca_index;
static int mca_nr_cards;
void mca_init(int nr_cards)
void
mca_init(int nr_cards)
{
int c;
@@ -31,12 +30,14 @@ void mca_init(int nr_cards)
mca_nr_cards = nr_cards;
}
void mca_set_index(int index)
void
mca_set_index(int index)
{
mca_index = index;
}
uint8_t mca_read(uint16_t port)
uint8_t
mca_read(uint16_t port)
{
if (mca_index >= mca_nr_cards)
return 0xff;
@@ -45,7 +46,8 @@ uint8_t mca_read(uint16_t port)
return mca_card_read[mca_index](port, mca_priv[mca_index]);
}
uint8_t mca_read_index(uint16_t port, int index)
uint8_t
mca_read_index(uint16_t port, int index)
{
if (mca_index >= mca_nr_cards)
return 0xff;
@@ -54,12 +56,14 @@ uint8_t mca_read_index(uint16_t port, int index)
return mca_card_read[index](port, mca_priv[index]);
}
int mca_get_nr_cards(void)
int
mca_get_nr_cards(void)
{
return mca_nr_cards;
}
void mca_write(uint16_t port, uint8_t val)
void
mca_write(uint16_t port, uint8_t val)
{
if (mca_index >= mca_nr_cards)
return;
@@ -67,7 +71,8 @@ void mca_write(uint16_t port, uint8_t val)
mca_card_write[mca_index](port, val, mca_priv[mca_index]);
}
uint8_t mca_feedb(void)
uint8_t
mca_feedb(void)
{
if (mca_card_feedb[mca_index])
return !!(mca_card_feedb[mca_index](mca_priv[mca_index]));
@@ -75,7 +80,8 @@ uint8_t mca_feedb(void)
return 0;
}
void mca_reset(void)
void
mca_reset(void)
{
int c;
@@ -85,8 +91,8 @@ void mca_reset(void)
}
}
void mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), uint8_t (*feedb)(void *priv), void (*reset)(void *priv), void *priv)
void
mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), uint8_t (*feedb)(void *priv), void (*reset)(void *priv), void *priv)
{
int c;

View File

@@ -8,17 +8,16 @@
#include <86box/io.h>
#include <86box/nmi.h>
int nmi_mask;
void nmi_write(uint16_t port, uint8_t val, void *p)
void
nmi_write(uint16_t port, uint8_t val, void *p)
{
nmi_mask = val & 0x80;
}
void nmi_init(void)
void
nmi_init(void)
{
io_sethandler(0x00a0, 0x000f, NULL, NULL, NULL, nmi_write, NULL, NULL, NULL);
nmi_mask = 0;

View File

@@ -62,19 +62,15 @@
#include <86box/plat.h>
#include <86box/nvr.h>
int nvr_dosave; /* NVR is dirty, needs saved */
static int8_t days_in_month[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
static int8_t days_in_month[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static struct tm intclk;
static nvr_t *saved_nvr = NULL;
#ifdef ENABLE_NVR_LOG
int nvr_do_log = ENABLE_NVR_LOG;
static void
nvr_log(const char *fmt, ...)
{
@@ -87,33 +83,33 @@ nvr_log(const char *fmt, ...)
}
}
#else
#define nvr_log(fmt, ...)
# define nvr_log(fmt, ...)
#endif
/* Determine whether or not the year is leap. */
int
nvr_is_leap(int year)
{
if (year % 400 == 0) return(1);
if (year % 100 == 0) return(0);
if (year % 4 == 0) return(1);
if (year % 400 == 0)
return (1);
if (year % 100 == 0)
return (0);
if (year % 4 == 0)
return (1);
return(0);
return (0);
}
/* Determine the days in the current month. */
int
nvr_get_days(int month, int year)
{
if (month != 2)
return(days_in_month[month - 1]);
return (days_in_month[month - 1]);
return(nvr_is_leap(year) ? 29 : 28);
return (nvr_is_leap(year) ? 29 : 28);
}
/* One more second has passed, update the internal clock. */
void
rtc_tick(void)
@@ -125,8 +121,7 @@ rtc_tick(void)
intclk.tm_min = 0;
if (++intclk.tm_hour == 24) {
intclk.tm_hour = 0;
if (++intclk.tm_mday == (nvr_get_days(intclk.tm_mon,
intclk.tm_year) + 1)) {
if (++intclk.tm_mday == (nvr_get_days(intclk.tm_mon, intclk.tm_year) + 1)) {
intclk.tm_mday = 1;
if (++intclk.tm_mon == 13) {
intclk.tm_mon = 1;
@@ -138,12 +133,11 @@ rtc_tick(void)
}
}
/* This is the RTC one-second timer. */
static void
onesec_timer(void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
nvr_t *nvr = (nvr_t *) priv;
int is_at;
if (++nvr->onesec_cnt >= 100) {
@@ -159,10 +153,9 @@ onesec_timer(void *priv)
nvr->onesec_cnt = 0;
}
timer_advance_u64(&nvr->onesec_time, (uint64_t)(10000ULL * TIMER_USEC));
timer_advance_u64(&nvr->onesec_time, (uint64_t) (10000ULL * TIMER_USEC));
}
/* Initialize the generic NVRAM/RTC device. */
void
nvr_init(nvr_t *nvr)
@@ -171,7 +164,7 @@ nvr_init(nvr_t *nvr)
/* Set up the NVR file's name. */
c = strlen(machine_get_internal_name()) + 5;
nvr->fn = (char *)malloc(c + 1);
nvr->fn = (char *) malloc(c + 1);
sprintf(nvr->fn, "%s.nvr", machine_get_internal_name());
/* Initialize the internal clock as needed. */
@@ -194,10 +187,9 @@ nvr_init(nvr_t *nvr)
saved_nvr = nvr;
/* Try to load the saved data. */
(void)nvr_load();
(void) nvr_load();
}
/* Get path to the NVR folder. */
char *
nvr_path(char *str)
@@ -210,17 +202,16 @@ nvr_path(char *str)
strcat(temp, NVR_PATH);
/* Create the directory if needed. */
if (! plat_dir_check(temp))
if (!plat_dir_check(temp))
plat_dir_create(temp);
/* Now append the actual filename. */
path_slash(temp);
strcat(temp, str);
return(temp);
return (temp);
}
/*
* Load an NVR from file.
*
@@ -240,7 +231,8 @@ nvr_load(void)
uint8_t regs[NVR_MAXSIZE] = { 0 };
/* Make sure we have been initialized. */
if (saved_nvr == NULL) return(0);
if (saved_nvr == NULL)
return (0);
/* Clear out any old data. */
memset(saved_nvr->regs, 0x00, sizeof(saved_nvr->regs));
@@ -262,7 +254,7 @@ nvr_load(void)
memcpy(saved_nvr->regs, regs, sizeof(regs));
saved_nvr->is_new = 1;
}
(void)fclose(fp);
(void) fclose(fp);
}
} else
saved_nvr->is_new = 1;
@@ -271,17 +263,15 @@ nvr_load(void)
if (saved_nvr->start != NULL)
saved_nvr->start(saved_nvr);
return(1);
return (1);
}
void
nvr_set_ven_save(void (*ven_save)(void))
{
saved_nvr->ven_save = ven_save;
}
/* Save the current NVR to a file. */
int
nvr_save(void)
@@ -290,7 +280,8 @@ nvr_save(void)
FILE *fp;
/* Make sure we have been initialized. */
if (saved_nvr == NULL) return(0);
if (saved_nvr == NULL)
return (0);
if (saved_nvr->size != 0) {
path = nvr_path(saved_nvr->fn);
@@ -298,7 +289,7 @@ nvr_save(void)
fp = plat_fopen(path, "wb");
if (fp != NULL) {
/* Save NVR contents to file. */
(void)fwrite(saved_nvr->regs, saved_nvr->size, 1, fp);
(void) fwrite(saved_nvr->regs, saved_nvr->size, 1, fp);
fclose(fp);
}
}
@@ -309,17 +300,15 @@ nvr_save(void)
/* Device is clean again. */
nvr_dosave = 0;
return(1);
return (1);
}
void
nvr_close(void)
{
saved_nvr = NULL;
}
void
nvr_time_sync(void)
{
@@ -327,8 +316,8 @@ nvr_time_sync(void)
time_t now;
/* Get the current time of day, and convert to local time. */
(void)time(&now);
if(time_sync & TIME_SYNC_UTC)
(void) time(&now);
if (time_sync & TIME_SYNC_UTC)
tm = gmtime(&now);
else
tm = localtime(&now);
@@ -337,7 +326,6 @@ nvr_time_sync(void)
nvr_time_set(tm);
}
/* Get current time from internal clock. */
void
nvr_time_get(struct tm *tm)
@@ -352,7 +340,7 @@ nvr_time_get(struct tm *tm)
mon = intclk.tm_mon;
yr = (intclk.tm_year % 100);
cent = ((intclk.tm_year - yr) / 100) % 4;
sum = dom+mon+yr+cent;
sum = dom + mon + yr + cent;
wd = ((sum + 6) % 7);
tm->tm_wday = wd;
tm->tm_mday = intclk.tm_mday;
@@ -360,7 +348,6 @@ nvr_time_get(struct tm *tm)
tm->tm_year = (intclk.tm_year - 1900);
}
/* Set internal clock time. */
void
nvr_time_set(struct tm *tm)
@@ -374,10 +361,9 @@ nvr_time_set(struct tm *tm)
intclk.tm_year = (tm->tm_year + 1900);
}
/* Open or create a file in the NVR area. */
FILE *
nvr_fopen(char *str, char *mode)
{
return(plat_fopen(nvr_path(str), mode));
return (plat_fopen(nvr_path(str), mode));
}

View File

@@ -238,47 +238,46 @@
#include <86box/device.h>
#include <86box/nvr.h>
/* RTC registers and bit definitions. */
#define RTC_SECONDS 0
#define RTC_ALSECONDS 1
# define AL_DONTCARE 0xc0 /* Alarm time is not set */
#define AL_DONTCARE 0xc0 /* Alarm time is not set */
#define RTC_MINUTES 2
#define RTC_ALMINUTES 3
#define RTC_HOURS 4
# define RTC_AMPM 0x80 /* PM flag if 12h format in use */
#define RTC_AMPM 0x80 /* PM flag if 12h format in use */
#define RTC_ALHOURS 5
#define RTC_DOW 6
#define RTC_DOM 7
#define RTC_MONTH 8
#define RTC_YEAR 9
#define RTC_REGA 10
# define REGA_UIP 0x80
# define REGA_DV2 0x40
# define REGA_DV1 0x20
# define REGA_DV0 0x10
# define REGA_DV 0x70
# define REGA_RS3 0x08
# define REGA_RS2 0x04
# define REGA_RS1 0x02
# define REGA_RS0 0x01
# define REGA_RS 0x0f
#define REGA_UIP 0x80
#define REGA_DV2 0x40
#define REGA_DV1 0x20
#define REGA_DV0 0x10
#define REGA_DV 0x70
#define REGA_RS3 0x08
#define REGA_RS2 0x04
#define REGA_RS1 0x02
#define REGA_RS0 0x01
#define REGA_RS 0x0f
#define RTC_REGB 11
# define REGB_SET 0x80
# define REGB_PIE 0x40
# define REGB_AIE 0x20
# define REGB_UIE 0x10
# define REGB_SQWE 0x08
# define REGB_DM 0x04
# define REGB_2412 0x02
# define REGB_DSE 0x01
#define REGB_SET 0x80
#define REGB_PIE 0x40
#define REGB_AIE 0x20
#define REGB_UIE 0x10
#define REGB_SQWE 0x08
#define REGB_DM 0x04
#define REGB_2412 0x02
#define REGB_DSE 0x01
#define RTC_REGC 12
# define REGC_IRQF 0x80
# define REGC_PF 0x40
# define REGC_AF 0x20
# define REGC_UF 0x10
#define REGC_IRQF 0x80
#define REGC_PF 0x40
#define REGC_AF 0x20
#define REGC_UF 0x10
#define RTC_REGD 13
# define REGD_VRT 0x80
#define REGD_VRT 0x80
#define RTC_CENTURY_AT 0x32 /* century register for AT etc */
#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */
#define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */
@@ -297,7 +296,6 @@
#define FLAG_P6RP4_HACK 0x10
#define FLAG_PIIX4 0x20
typedef struct {
int8_t stat;
@@ -317,15 +315,13 @@ typedef struct {
rtc_timer;
} local_t;
static uint8_t nvr_at_inited = 0;
/* Get the current NVR time. */
static void
time_get(nvr_t *nvr, struct tm *tm)
{
local_t *local = (local_t *)nvr->data;
local_t *local = (local_t *) nvr->data;
int8_t temp;
if (nvr->regs[RTC_REGB] & REGB_DM) {
@@ -356,15 +352,14 @@ time_get(nvr_t *nvr, struct tm *tm)
if (nvr->regs[RTC_REGB] & REGB_2412)
tm->tm_hour = temp;
else
tm->tm_hour = ((temp & ~RTC_AMPM)%12) + ((temp&RTC_AMPM) ? 12 : 0);
tm->tm_hour = ((temp & ~RTC_AMPM) % 12) + ((temp & RTC_AMPM) ? 12 : 0);
}
/* Set the current NVR time. */
static void
time_set(nvr_t *nvr, struct tm *tm)
{
local_t *local = (local_t *)nvr->data;
local_t *local = (local_t *) nvr->data;
int year = (tm->tm_year + 1900);
if (nvr->regs[RTC_REGB] & REGB_DM) {
@@ -412,41 +407,36 @@ time_set(nvr_t *nvr, struct tm *tm)
}
}
/* Check if the current time matches a set alarm time. */
static int8_t
check_alarm(nvr_t *nvr, int8_t addr)
{
return((nvr->regs[addr+1] == nvr->regs[addr]) ||
((nvr->regs[addr+1] & AL_DONTCARE) == AL_DONTCARE));
return ((nvr->regs[addr + 1] == nvr->regs[addr]) || ((nvr->regs[addr + 1] & AL_DONTCARE) == AL_DONTCARE));
}
/* Check for VIA stuff. */
static int8_t
check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2)
{
local_t *local = (local_t *)nvr->data;
local_t *local = (local_t *) nvr->data;
if (local->cent == RTC_CENTURY_VIA) {
return((nvr->regs[addr_2] == nvr->regs[addr]) ||
((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE));
return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE));
} else
return 1;
}
/* Update the NVR registers from the internal clock. */
static void
timer_update(void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *) nvr->data;
struct tm tm;
local->ecount = 0LL;
if (! (nvr->regs[RTC_REGB] & REGB_SET)) {
if (!(nvr->regs[RTC_REGB] & REGB_SET)) {
/* Get the current time from the internal clock. */
nvr_time_get(&tm);
@@ -457,13 +447,10 @@ timer_update(void *priv)
local->stat = 0x00;
/* Check for any alarms we need to handle. */
if (check_alarm(nvr, RTC_SECONDS) &&
check_alarm(nvr, RTC_MINUTES) &&
check_alarm(nvr, RTC_HOURS) &&
check_alarm_via(nvr, RTC_DOM, RTC_ALDAY) &&
check_alarm_via(nvr, RTC_MONTH, RTC_ALMONTH)/* &&
if (check_alarm(nvr, RTC_SECONDS) && check_alarm(nvr, RTC_MINUTES) && check_alarm(nvr, RTC_HOURS) && check_alarm_via(nvr, RTC_DOM, RTC_ALDAY) && check_alarm_via(nvr, RTC_MONTH, RTC_ALMONTH) /* &&
check_alarm_via(nvr, RTC_DOM, RTC_ALDAY_SIS) &&
check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/) {
check_alarm_via(nvr, RTC_MONTH, RTC_ALMONT_SIS)*/
) {
nvr->regs[RTC_REGC] |= REGC_AF;
if (nvr->regs[RTC_REGB] & REGB_AIE) {
/* Generate an interrupt. */
@@ -489,7 +476,6 @@ timer_update(void *priv)
}
}
static void
timer_load_count(nvr_t *nvr)
{
@@ -509,7 +495,8 @@ timer_load_count(nvr_t *nvr)
case 0:
local->state = 0;
break;
case 1: case 2:
case 1:
case 2:
local->count = 1 << (c + 6);
timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST);
break;
@@ -520,12 +507,11 @@ timer_load_count(nvr_t *nvr)
}
}
static void
timer_intr(void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *) nvr->data;
if (local->state == 1) {
timer_load_count(nvr);
@@ -541,15 +527,14 @@ timer_intr(void *priv)
}
}
/* Callback from internal clock, another second passed. */
static void
timer_tick(nvr_t *nvr)
{
local_t *local = (local_t *)nvr->data;
local_t *local = (local_t *) nvr->data;
/* Only update it there is no SET in progress. */
if (! (nvr->regs[RTC_REGB] & REGB_SET)) {
if (!(nvr->regs[RTC_REGB] & REGB_SET)) {
/* Set the UIP bit, announcing the update. */
local->stat = REGA_UIP;
@@ -561,7 +546,6 @@ timer_tick(nvr_t *nvr)
}
}
static void
nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local)
{
@@ -583,19 +567,18 @@ nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local)
}
}
/* This must be exposed because ACPI uses it. */
void
nvr_reg_write(uint16_t reg, uint8_t val, void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *) nvr->data;
struct tm tm;
uint8_t old;
uint8_t irq = 0, old_irq = 0;
old = nvr->regs[reg];
switch(reg) {
switch (reg) {
case RTC_REGA:
nvr->regs[RTC_REGA] = val;
timer_load_count(nvr);
@@ -604,7 +587,7 @@ nvr_reg_write(uint16_t reg, uint8_t val, void *priv)
case RTC_REGB:
old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70;
nvr->regs[RTC_REGB] = val;
if (((old^val) & REGB_SET) && (val & REGB_SET)) {
if (((old ^ val) & REGB_SET) && (val & REGB_SET)) {
/* According to the datasheet... */
nvr->regs[RTC_REGA] &= ~REGA_UIP;
nvr->regs[RTC_REGB] &= ~REGB_UIE;
@@ -651,13 +634,12 @@ nvr_reg_write(uint16_t reg, uint8_t val, void *priv)
}
}
/* Write to one of the NVR registers. */
static void
nvr_write(uint16_t addr, uint8_t val, void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *) nvr->data;
uint8_t addr_id = (addr & 0x0e) >> 1;
cycles -= ISA_CYCLES(8);
@@ -683,13 +665,12 @@ nvr_write(uint16_t addr, uint8_t val, void *priv)
}
}
/* Read from one of the NVR registers. */
static uint8_t
nvr_read(uint16_t addr, void *priv)
{
nvr_t *nvr = (nvr_t *)priv;
local_t *local = (local_t *)nvr->data;
nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *) nvr->data;
uint8_t ret;
uint8_t addr_id = (addr & 0x0e) >> 1;
uint16_t i, checksum = 0x0000;
@@ -698,7 +679,8 @@ nvr_read(uint16_t addr, void *priv)
if (local->bank[addr_id] == 0xff)
ret = 0xff;
else if (addr & 1) switch(local->addr[addr_id]) {
else if (addr & 1)
switch (local->addr[addr_id]) {
case RTC_REGA:
ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat;
break;
@@ -808,7 +790,8 @@ nvr_read(uint16_t addr, void *priv)
default:
ret = nvr->regs[local->addr[addr_id]];
break;
} else {
}
else {
ret = local->addr[addr_id];
if (!local->read_addr)
ret &= 0x80;
@@ -816,10 +799,9 @@ nvr_read(uint16_t addr, void *priv)
ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80);
}
return(ret);
return (ret);
}
/* Secondary NVR write - used by SMC. */
static void
nvr_sec_write(uint16_t addr, uint8_t val, void *priv)
@@ -827,7 +809,6 @@ nvr_sec_write(uint16_t addr, uint8_t val, void *priv)
nvr_write(0x72 + (addr & 1), val, priv);
}
/* Secondary NVR read - used by SMC. */
static uint8_t
nvr_sec_read(uint16_t addr, void *priv)
@@ -835,12 +816,11 @@ nvr_sec_read(uint16_t addr, void *priv)
return nvr_read(0x72 + (addr & 1), priv);
}
/* Reset the RTC state to 1980/01/01 00:00. */
static void
nvr_reset(nvr_t *nvr)
{
local_t *local = (local_t *)nvr->data;
local_t *local = (local_t *) nvr->data;
/* memset(nvr->regs, local->def, RTC_REGS); */
memset(nvr->regs, local->def, nvr->size);
@@ -884,11 +864,10 @@ nvr_start(nvr_t *nvr)
}
/* Start the RTC. */
nvr->regs[RTC_REGA] = (REGA_RS2|REGA_RS1);
nvr->regs[RTC_REGA] = (REGA_RS2 | REGA_RS1);
nvr->regs[RTC_REGB] = REGB_2412;
}
static void
nvr_at_speed_changed(void *priv)
{
@@ -905,20 +884,18 @@ nvr_at_speed_changed(void *priv)
timer_set_delay_u64(&nvr->onesec_time, (10000ULL * TIMER_USEC));
}
void
nvr_at_handler(int set, uint16_t base, nvr_t *nvr)
{
io_handler(set, base, 2,
nvr_read,NULL,NULL, nvr_write,NULL,NULL, nvr);
nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr);
}
void
nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr)
{
io_handler(set, base, 2,
nvr_sec_read,NULL,NULL, nvr_sec_write,NULL,NULL, nvr);
nvr_sec_read, NULL, NULL, nvr_sec_write, NULL, NULL, nvr);
}
void
@@ -929,7 +906,6 @@ nvr_read_addr_set(int set, nvr_t *nvr)
local->read_addr = set;
}
void
nvr_wp_set(int set, int h, nvr_t *nvr)
{
@@ -938,7 +914,6 @@ nvr_wp_set(int set, int h, nvr_t *nvr)
local->wp[h] = set;
}
void
nvr_via_wp_set(int set, int reg, nvr_t *nvr)
{
@@ -950,7 +925,6 @@ nvr_via_wp_set(int set, int reg, nvr_t *nvr)
local->wp_32 = set;
}
void
nvr_bank_set(int base, uint8_t bank, nvr_t *nvr)
{
@@ -959,7 +933,6 @@ nvr_bank_set(int base, uint8_t bank, nvr_t *nvr)
local->bank[base] = bank;
}
void
nvr_lock_set(int base, int size, int lock, nvr_t *nvr)
{
@@ -970,14 +943,12 @@ nvr_lock_set(int base, int size, int lock, nvr_t *nvr)
local->lock[base + i] = lock;
}
void
nvr_irq_set(int irq, nvr_t *nvr)
{
nvr->irq = irq;
}
static void
nvr_at_reset(void *priv)
{
@@ -988,7 +959,6 @@ nvr_at_reset(void *priv)
nvr->regs[RTC_REGC] &= ~(REGC_PF | REGC_AF | REGC_UF | REGC_IRQF);
}
static void *
nvr_at_init(const device_t *info)
{
@@ -996,11 +966,12 @@ nvr_at_init(const device_t *info)
nvr_t *nvr;
/* Allocate an NVR for this machine. */
nvr = (nvr_t *)malloc(sizeof(nvr_t));
if (nvr == NULL) return(NULL);
nvr = (nvr_t *) malloc(sizeof(nvr_t));
if (nvr == NULL)
return (NULL);
memset(nvr, 0x00, sizeof(nvr_t));
local = (local_t *)malloc(sizeof(local_t));
local = (local_t *) malloc(sizeof(local_t));
memset(local, 0x00, sizeof(local_t));
nvr->data = local;
@@ -1010,7 +981,7 @@ nvr_at_init(const device_t *info)
memset(local->lock, 0x00, nvr->size);
local->def = 0xff /*0x00*/;
local->flags = 0x00;
switch(info->local & 7) {
switch (info->local & 7) {
case 0: /* standard AT, no century register */
if (info->local == 16) {
local->flags |= FLAG_P6RP4_HACK;
@@ -1097,19 +1068,18 @@ nvr_at_init(const device_t *info)
/* Set up the I/O handler for this device. */
io_sethandler(0x0070, 2,
nvr_read,NULL,NULL, nvr_write,NULL,NULL, nvr);
nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr);
if (info->local & 8) {
io_sethandler(0x0072, 2,
nvr_read,NULL,NULL, nvr_write,NULL,NULL, nvr);
nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr);
}
nvr_at_inited = 1;
}
return(nvr);
return (nvr);
}
static void
nvr_at_close(void *priv)
{
@@ -1225,8 +1195,11 @@ const device_t ps_no_nmi_nvr_device = {
"ps1_nvr",
DEVICE_PS2,
10,
nvr_at_init, nvr_at_close, nvr_at_reset,
{ NULL }, nvr_at_speed_changed,
nvr_at_init,
nvr_at_close,
nvr_at_reset,
{ NULL },
nvr_at_speed_changed,
NULL
};
@@ -1235,8 +1208,11 @@ const device_t amstrad_no_nmi_nvr_device = {
"amstrad_nvr",
DEVICE_ISA | DEVICE_AT,
11,
nvr_at_init, nvr_at_close, nvr_at_reset,
{ NULL }, nvr_at_speed_changed,
nvr_at_init,
nvr_at_close,
nvr_at_reset,
{ NULL },
nvr_at_speed_changed,
NULL
};

View File

@@ -49,7 +49,6 @@
#include <86box/nvr_ps2.h>
#include <86box/rom.h>
typedef struct {
int addr;
@@ -59,11 +58,10 @@ typedef struct {
char *fn;
} ps2_nvr_t;
static uint8_t
ps2_nvr_read(uint16_t port, void *priv)
{
ps2_nvr_t *nvr = (ps2_nvr_t *)priv;
ps2_nvr_t *nvr = (ps2_nvr_t *) priv;
uint8_t ret = 0xff;
switch (port) {
@@ -80,14 +78,13 @@ ps2_nvr_read(uint16_t port, void *priv)
break;
}
return(ret);
return (ret);
}
static void
ps2_nvr_write(uint16_t port, uint8_t val, void *priv)
{
ps2_nvr_t *nvr = (ps2_nvr_t *)priv;
ps2_nvr_t *nvr = (ps2_nvr_t *) priv;
switch (port) {
case 0x74:
@@ -104,7 +101,6 @@ ps2_nvr_write(uint16_t port, uint8_t val, void *priv)
}
}
static void *
ps2_nvr_init(const device_t *info)
{
@@ -112,7 +108,7 @@ ps2_nvr_init(const device_t *info)
FILE *f = NULL;
int c;
nvr = (ps2_nvr_t *)malloc(sizeof(ps2_nvr_t));
nvr = (ps2_nvr_t *) malloc(sizeof(ps2_nvr_t));
memset(nvr, 0x00, sizeof(ps2_nvr_t));
if (info->local)
@@ -122,15 +118,15 @@ ps2_nvr_init(const device_t *info)
/* Set up the NVR file's name. */
c = strlen(machine_get_internal_name()) + 9;
nvr->fn = (char *)malloc(c + 1);
nvr->fn = (char *) malloc(c + 1);
sprintf(nvr->fn, "%s_sec.nvr", machine_get_internal_name());
io_sethandler(0x0074, 3,
ps2_nvr_read,NULL,NULL, ps2_nvr_write,NULL,NULL, nvr);
ps2_nvr_read, NULL, NULL, ps2_nvr_write, NULL, NULL, nvr);
f = nvr_fopen(nvr->fn, "rb");
nvr->ram = (uint8_t *)malloc(nvr->size);
nvr->ram = (uint8_t *) malloc(nvr->size);
memset(nvr->ram, 0xff, nvr->size);
if (f != NULL) {
if (fread(nvr->ram, 1, nvr->size, f) != nvr->size)
@@ -138,20 +134,19 @@ ps2_nvr_init(const device_t *info)
fclose(f);
}
return(nvr);
return (nvr);
}
static void
ps2_nvr_close(void *priv)
{
ps2_nvr_t *nvr = (ps2_nvr_t *)priv;
ps2_nvr_t *nvr = (ps2_nvr_t *) priv;
FILE *f = NULL;
f = nvr_fopen(nvr->fn, "wb");
if (f != NULL) {
(void)fwrite(nvr->ram, nvr->size, 1, f);
(void) fwrite(nvr->ram, nvr->size, 1, f);
fclose(f);
}

151
src/pci.c
View File

@@ -35,7 +35,6 @@
#include <86box/pci.h>
#include <86box/keyboard.h>
typedef struct {
uint8_t bus, id, type;
uint8_t irq_routing[4];
@@ -50,7 +49,6 @@ typedef struct {
uint8_t irq_line;
} pci_mirq_t;
int pci_burst_time, agp_burst_time,
pci_nonburst_time, agp_nonburst_time;
@@ -70,14 +68,11 @@ static int pci_type,
pci_key;
static int trc_reg = 0;
static void pci_reset_regs(void);
#ifdef ENABLE_PCI_LOG
int pci_do_log = ENABLE_PCI_LOG;
static void
pci_log(const char *fmt, ...)
{
@@ -90,10 +85,9 @@ pci_log(const char *fmt, ...)
}
}
#else
#define pci_log(fmt, ...)
# define pci_log(fmt, ...)
#endif
static void
pci_clear_slot(int card)
{
@@ -112,7 +106,6 @@ pci_clear_slot(int card)
pci_cards[card].priv = NULL;
}
void
pci_relocate_slot(int type, int new_slot)
{
@@ -140,7 +133,6 @@ pci_relocate_slot(int type, int new_slot)
pci_card_to_slot_mapping[0][new_slot] = mapping;
}
static void
pci_cf8_write(uint16_t port, uint32_t val, void *priv)
{
@@ -152,15 +144,12 @@ pci_cf8_write(uint16_t port, uint32_t val, void *priv)
pci_enable = (val >> 31) & 1;
}
static uint32_t
pci_cf8_read(uint16_t port, void *priv)
{
return pci_index | (pci_func << 8) |
(pci_card << 11) | (pci_bus << 16) | (pci_enable << 31);
return pci_index | (pci_func << 8) | (pci_card << 11) | (pci_bus << 16) | (pci_enable << 31);
}
static void
pci_write(uint16_t port, uint8_t val, void *priv)
{
@@ -170,8 +159,11 @@ pci_write(uint16_t port, uint8_t val, void *priv)
pci_log("(%i) %03x write: %02X\n", pci_enable, port, val);
switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff:
if (! pci_enable)
case 0xcfc:
case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return;
pci_log("Writing %02X to PCI card on bus %i, slot %02X (pci_cards[%i]) (%02X:%02X)...\n", val, pci_bus, pci_card, slot, pci_func, pci_index | (port & 3));
@@ -195,7 +187,6 @@ pci_write(uint16_t port, uint8_t val, void *priv)
}
}
static void
pci_writew(uint16_t port, uint16_t val, void *priv)
{
@@ -205,8 +196,11 @@ pci_writew(uint16_t port, uint16_t val, void *priv)
pci_log("(%i) %03x write: %02X\n", pci_enable, port, val);
switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff:
if (! pci_enable)
case 0xcfc:
case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return;
pci_log("Writing %04X to PCI card on bus %i, slot %02X (pci_cards[%i]) (%02X:%02X)...\n", val, pci_bus, pci_card, slot, pci_func, pci_index | (port & 3));
@@ -231,7 +225,6 @@ pci_writew(uint16_t port, uint16_t val, void *priv)
}
}
static void
pci_writel(uint16_t port, uint32_t val, void *priv)
{
@@ -241,8 +234,11 @@ pci_writel(uint16_t port, uint32_t val, void *priv)
pci_log("(%i) %03x write: %02X\n", pci_enable, port, val);
switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff:
if (! pci_enable)
case 0xcfc:
case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return;
pci_log("Writing %08X to PCI card on bus %i, slot %02X (pci_cards[%i]) (%02X:%02X)...\n", val, pci_bus, pci_card, slot, pci_func, pci_index | (port & 3));
@@ -269,7 +265,6 @@ pci_writel(uint16_t port, uint32_t val, void *priv)
}
}
static uint8_t
pci_read(uint16_t port, void *priv)
{
@@ -280,8 +275,11 @@ pci_read(uint16_t port, void *priv)
pci_log("(%i) %03x read\n", pci_enable, port);
switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff:
if (! pci_enable)
case 0xcfc:
case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return 0xff;
slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card];
@@ -304,7 +302,6 @@ pci_read(uint16_t port, void *priv)
return ret;
}
static uint16_t
pci_readw(uint16_t port, void *priv)
{
@@ -315,8 +312,11 @@ pci_readw(uint16_t port, void *priv)
pci_log("(%i) %03x read\n", pci_enable, port);
switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff:
if (! pci_enable)
case 0xcfc:
case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return 0xff;
slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card];
@@ -341,7 +341,6 @@ pci_readw(uint16_t port, void *priv)
return ret;
}
static uint32_t
pci_readl(uint16_t port, void *priv)
{
@@ -352,8 +351,11 @@ pci_readl(uint16_t port, void *priv)
pci_log("(%i) %03x read\n", pci_enable, port);
switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff:
if (! pci_enable)
case 0xcfc:
case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return 0xff;
slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card];
@@ -380,11 +382,9 @@ pci_readl(uint16_t port, void *priv)
return ret;
}
static void pci_type2_write(uint16_t port, uint8_t val, void *priv);
static uint8_t pci_type2_read(uint16_t port, void *priv);
void
pci_set_pmc(uint8_t pmc)
{
@@ -392,28 +392,27 @@ pci_set_pmc(uint8_t pmc)
if (!pci_pmc && (pmc & 0x01)) {
io_removehandler(0x0cf8, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
io_removehandler(0x0cfa, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
io_sethandler(0x0cf8, 1,
NULL,NULL,pci_cf8_read, NULL,NULL,pci_cf8_write, NULL);
NULL, NULL, pci_cf8_read, NULL, NULL, pci_cf8_write, NULL);
io_sethandler(0x0cfc, 4,
pci_read,NULL,NULL, pci_write,NULL,NULL, NULL);
pci_read, NULL, NULL, pci_write, NULL, NULL, NULL);
} else if (pci_pmc && !(pmc & 0x01)) {
io_removehandler(0x0cf8, 1,
NULL,NULL,pci_cf8_read, NULL,NULL,pci_cf8_write, NULL);
NULL, NULL, pci_cf8_read, NULL, NULL, pci_cf8_write, NULL);
io_removehandler(0x0cfc, 4,
pci_read,NULL,NULL, pci_write,NULL,NULL, NULL);
pci_read, NULL, NULL, pci_write, NULL, NULL, NULL);
io_sethandler(0x0cf8, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
io_sethandler(0x0cfa, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
}
pci_pmc = (pmc & 0x01);
}
static void
pci_type2_write(uint16_t port, uint8_t val, void *priv)
{
@@ -457,7 +456,6 @@ pci_type2_write(uint16_t port, uint8_t val, void *priv)
}
}
static void
pci_type2_writel(uint16_t port, uint32_t val, void *priv)
{
@@ -471,7 +469,6 @@ pci_type2_writel(uint16_t port, uint32_t val, void *priv)
}
}
static uint8_t
pci_type2_read(uint16_t port, void *priv)
{
@@ -504,35 +501,30 @@ pci_type2_read(uint16_t port, void *priv)
return 0xff;
}
void
pci_set_irq_routing(int pci_int, int irq)
{
pci_irqs[pci_int - 1] = irq;
}
void
pci_set_irq_level(int pci_int, int level)
{
pci_irq_level[pci_int - 1] = !!level;
}
void
pci_enable_mirq(int mirq)
{
pci_mirqs[mirq].enabled = 1;
}
void
pci_set_mirq_routing(int mirq, int irq)
{
pci_mirqs[mirq].irq_line = irq;
}
void
pci_set_mirq(uint8_t mirq, int level)
{
@@ -543,7 +535,7 @@ pci_set_mirq(uint8_t mirq, int level)
irq_line = mirq & 0x0f;
irq_bit = 0x1D;
} else {
if (! pci_mirqs[mirq].enabled) {
if (!pci_mirqs[mirq].enabled) {
pci_log("pci_set_mirq(%02X): MIRQ0 disabled\n", mirq);
return;
}
@@ -588,7 +580,6 @@ pci_set_mirq(uint8_t mirq, int level)
pci_log("pci_set_mirq(%02X): Edge-triggered interrupt, not marking\n", mirq);
}
void
pci_set_irq(uint8_t card, uint8_t pci_int)
{
@@ -598,7 +589,7 @@ pci_set_irq(uint8_t card, uint8_t pci_int)
uint8_t irq_line = 0;
uint8_t level = 0;
if (! last_pci_card) {
if (!last_pci_card) {
pci_log("pci_set_irq(%02X, %02X): No PCI slots (how are we even here?!)\n", card, pci_int);
return;
}
@@ -611,7 +602,7 @@ pci_set_irq(uint8_t card, uint8_t pci_int)
}
pci_log("pci_set_irq(%02X, %02X): Card is on PCI slot %02X\n", card, pci_int, slot);
if (! pci_cards[slot].irq_routing[pci_int_index]) {
if (!pci_cards[slot].irq_routing[pci_int_index]) {
pci_log("pci_set_irq(%02X, %02X): No IRQ routing for this slot and INT pin combination\n", card, pci_int);
return;
}
@@ -662,7 +653,6 @@ pci_set_irq(uint8_t card, uint8_t pci_int)
}
}
void
pci_clear_mirq(uint8_t mirq, int level)
{
@@ -678,7 +668,7 @@ pci_clear_mirq(uint8_t mirq, int level)
return;
}
if (! pci_mirqs[mirq].enabled) {
if (!pci_mirqs[mirq].enabled) {
pci_log("pci_clear_mirq(%02X): MIRQ0 disabled\n", mirq);
return;
}
@@ -703,7 +693,7 @@ pci_clear_mirq(uint8_t mirq, int level)
pci_log("pci_clear_mirq(%02X): Releasing this MIRQ's hold on the IRQ\n", mirq);
pci_irq_hold[irq_line] &= ~(1 << irq_bit);
if (! pci_irq_hold[irq_line]) {
if (!pci_irq_hold[irq_line]) {
pci_log("pci_clear_mirq(%02X): IRQ no longer held by any card, clearing it\n", mirq);
picintc(1 << irq_line);
} else {
@@ -715,7 +705,6 @@ pci_clear_mirq(uint8_t mirq, int level)
}
}
void
pci_clear_irq(uint8_t card, uint8_t pci_int)
{
@@ -725,7 +714,7 @@ pci_clear_irq(uint8_t card, uint8_t pci_int)
uint8_t irq_line = 0;
uint8_t level = 0;
if (! last_pci_card) {
if (!last_pci_card) {
// pci_log("pci_clear_irq(%02X, %02X): No PCI slots (how are we even here?!)\n", card, pci_int);
return;
}
@@ -738,7 +727,7 @@ pci_clear_irq(uint8_t card, uint8_t pci_int)
}
// pci_log("pci_clear_irq(%02X, %02X): Card is on PCI slot %02X\n", card, pci_int, slot);
if (! pci_cards[slot].irq_routing[pci_int_index]) {
if (!pci_cards[slot].irq_routing[pci_int_index]) {
// pci_log("pci_clear_irq(%02X, %02X): No IRQ routing for this slot and INT pin combination\n", card, pci_int);
return;
}
@@ -770,7 +759,7 @@ pci_clear_irq(uint8_t card, uint8_t pci_int)
// pci_log("pci_clear_irq(%02X, %02X): Releasing this card's hold on the IRQ\n", card, pci_int);
pci_irq_hold[irq_line] &= ~(1 << slot);
if (! pci_irq_hold[irq_line]) {
if (!pci_irq_hold[irq_line]) {
// pci_log("pci_clear_irq(%02X, %02X): IRQ no longer held by any card, clearing it\n", card, pci_int);
picintc(1 << irq_line);
} // else {
@@ -782,14 +771,12 @@ pci_clear_irq(uint8_t card, uint8_t pci_int)
}
}
uint8_t
pci_get_int(uint8_t slot, uint8_t pci_int)
{
return pci_cards[slot].irq_routing[pci_int - PCI_INTA];
}
static void
pci_reset_regs(void)
{
@@ -800,7 +787,6 @@ pci_reset_regs(void)
pci_type2_write, NULL, NULL, NULL);
}
void
pci_pic_reset(void)
{
@@ -808,7 +794,6 @@ pci_pic_reset(void)
pic_set_pci_flag(last_pci_card > 0);
}
static void
pci_reset_hard(void)
{
@@ -827,7 +812,6 @@ pci_reset_hard(void)
pci_pic_reset();
}
void
pci_reset(void)
{
@@ -835,19 +819,18 @@ pci_reset(void)
pci_pmc = 0x00;
io_removehandler(0x0cf8, 1,
NULL,NULL,pci_cf8_read, NULL,NULL,pci_cf8_write, NULL);
NULL, NULL, pci_cf8_read, NULL, NULL, pci_cf8_write, NULL);
io_removehandler(0x0cfc, 4,
pci_read,NULL,NULL, pci_write,NULL,NULL, NULL);
pci_read, NULL, NULL, pci_write, NULL, NULL, NULL);
io_sethandler(0x0cf8, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
io_sethandler(0x0cfa, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
}
pci_reset_hard();
}
static void
pci_slots_clear(void)
{
@@ -869,28 +852,24 @@ pci_slots_clear(void)
pci_bus_number_to_index_mapping[0] = 0; /* always map bus 0 to index 0 */
}
uint32_t
trc_readl(uint16_t port, void *priv)
{
return 0xffffffff;
}
uint16_t
trc_readw(uint16_t port, void *priv)
{
return 0xffff;
}
uint8_t
trc_read(uint16_t port, void *priv)
{
return trc_reg & 0xfb;
}
static void
trc_reset(uint8_t val)
{
@@ -914,19 +893,16 @@ trc_reset(uint8_t val)
resetx86();
}
void
trc_writel(uint16_t port, uint32_t val, void *priv)
{
}
void
trc_writew(uint16_t port, uint16_t val, void *priv)
{
}
void
trc_write(uint16_t port, uint8_t val, void *priv)
{
@@ -941,7 +917,6 @@ trc_write(uint16_t port, uint8_t val, void *priv)
trc_reg &= 0xfb;
}
void
trc_init(void)
{
@@ -951,7 +926,6 @@ trc_init(void)
trc_read, trc_readw, trc_readl, trc_write, trc_writew, trc_writel, NULL);
}
void
pci_init(int type)
{
@@ -970,7 +944,7 @@ pci_init(int type)
pci_pmc = 0x00;
io_sethandler(0x0cfb, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,pci_type2_writel, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, pci_type2_writel, NULL);
}
if (type & PCI_NO_IRQ_STEERING) {
@@ -983,15 +957,15 @@ pci_init(int type)
if ((type & PCI_CONFIG_TYPE_MASK) == PCI_CONFIG_TYPE_1) {
io_sethandler(0x0cf8, 1,
NULL,NULL,pci_cf8_read, NULL,NULL,pci_cf8_write, NULL);
NULL, NULL, pci_cf8_read, NULL, NULL, pci_cf8_write, NULL);
io_sethandler(0x0cfc, 4,
pci_read,pci_readw,pci_readl, pci_write,pci_writew,pci_writel, NULL);
pci_read, pci_readw, pci_readl, pci_write, pci_writew, pci_writel, NULL);
pci_pmc = 1;
} else {
io_sethandler(0x0cf8, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
io_sethandler(0x0cfa, 1,
pci_type2_read,NULL,NULL, pci_type2_write,NULL,NULL, NULL);
pci_type2_read, NULL, NULL, pci_type2_write, NULL, NULL, NULL);
pci_pmc = 0;
}
@@ -1008,14 +982,12 @@ pci_init(int type)
pic_set_pci_flag(1);
}
uint8_t
pci_register_bus()
{
return last_pci_bus++;
}
void
pci_remap_bus(uint8_t bus_index, uint8_t bus_number)
{
@@ -1029,14 +1001,12 @@ pci_remap_bus(uint8_t bus_index, uint8_t bus_number)
pci_bus_number_to_index_mapping[bus_number] = bus_index;
}
void
pci_register_slot(int card, int type, int inta, int intb, int intc, int intd)
{
pci_register_bus_slot(0, card, type, inta, intb, intc, intd);
}
void
pci_register_bus_slot(int bus, int card, int type, int inta, int intb, int intc, int intd)
{
@@ -1061,7 +1031,6 @@ pci_register_bus_slot(int bus, int card, int type, int inta, int intb, int intc,
last_pci_card++;
}
uint8_t
pci_find_slot(uint8_t add_type, uint8_t ignore_slot)
{
@@ -1078,8 +1047,7 @@ pci_find_slot(uint8_t add_type, uint8_t ignore_slot)
break;
}
} else {
if (((dev->type == PCI_CARD_NORMAL) && ((add_type & 0x7f) >= PCI_ADD_NORMAL)) ||
(dev->type == (add_type & 0x7f))) {
if (((dev->type == PCI_CARD_NORMAL) && ((add_type & 0x7f) >= PCI_ADD_NORMAL)) || (dev->type == (add_type & 0x7f))) {
ret = i;
break;
}
@@ -1090,7 +1058,6 @@ pci_find_slot(uint8_t add_type, uint8_t ignore_slot)
return ret;
}
uint8_t
pci_add_card(uint8_t add_type, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv)
{
@@ -1100,7 +1067,7 @@ pci_add_card(uint8_t add_type, uint8_t (*read)(int func, int addr, void *priv),
if (add_type < PCI_ADD_AGP)
pci_log("pci_add_card(): Adding PCI CARD at specific slot %02X [SPECIFIC]\n", add_type);
if (! last_pci_card) {
if (!last_pci_card) {
pci_log("pci_add_card(): Adding PCI CARD failed (no PCI slots) [%s]\n", (add_type == PCI_ADD_NORMAL) ? "NORMAL" : ((add_type == PCI_ADD_AGP) ? "AGP" : ((add_type == PCI_ADD_VIDEO) ? "VIDEO" : ((add_type == PCI_ADD_SCSI) ? "SCSI" : ((add_type == PCI_ADD_SOUND) ? "SOUND" : "SPECIFIC")))));
return 0xff;
}

View File

@@ -15,25 +15,22 @@ static bar_t pci_bar[2];
static uint8_t interrupt_on = 0x00;
static uint8_t card = 0;
static void pci_dummy_interrupt(int set)
static void
pci_dummy_interrupt(int set)
{
if (set)
{
if (set) {
pci_set_irq(card, pci_regs[0x3D]);
}
else
{
} else {
pci_clear_irq(card, pci_regs[0x3D]);
}
}
static uint8_t pci_dummy_read(uint16_t Port, void *p)
static uint8_t
pci_dummy_read(uint16_t Port, void *p)
{
uint8_t ret = 0;
switch(Port & 0x20)
{
switch (Port & 0x20) {
case 0x00:
return 0x1A;
case 0x01:
@@ -48,8 +45,7 @@ static uint8_t pci_dummy_read(uint16_t Port, void *p)
return pci_regs[0x3D];
case 0x06:
ret = interrupt_on;
if (interrupt_on)
{
if (interrupt_on) {
pci_dummy_interrupt(0);
interrupt_on = 0;
}
@@ -59,25 +55,24 @@ static uint8_t pci_dummy_read(uint16_t Port, void *p)
}
}
static uint16_t pci_dummy_readw(uint16_t Port, void *p)
static uint16_t
pci_dummy_readw(uint16_t Port, void *p)
{
return pci_dummy_read(Port, p);
}
static uint32_t pci_dummy_readl(uint16_t Port, void *p)
static uint32_t
pci_dummy_readl(uint16_t Port, void *p)
{
return pci_dummy_read(Port, p);
}
static void pci_dummy_write(uint16_t Port, uint8_t Val, void *p)
static void
pci_dummy_write(uint16_t Port, uint8_t Val, void *p)
{
switch(Port & 0x20)
{
switch (Port & 0x20) {
case 0x06:
if (!interrupt_on)
{
if (!interrupt_on) {
interrupt_on = 1;
pci_dummy_interrupt(1);
}
@@ -87,33 +82,36 @@ static void pci_dummy_write(uint16_t Port, uint8_t Val, void *p)
}
}
static void pci_dummy_writew(uint16_t Port, uint16_t Val, void *p)
static void
pci_dummy_writew(uint16_t Port, uint16_t Val, void *p)
{
pci_dummy_write(Port, Val & 0xFF, p);
}
static void pci_dummy_writel(uint16_t Port, uint32_t Val, void *p)
static void
pci_dummy_writel(uint16_t Port, uint32_t Val, void *p)
{
pci_dummy_write(Port, Val & 0xFF, p);
}
static void pci_dummy_io_remove(void)
static void
pci_dummy_io_remove(void)
{
io_removehandler(pci_bar[0].addr, 0x0020, pci_dummy_read, pci_dummy_readw, pci_dummy_readl, pci_dummy_write, pci_dummy_writew, pci_dummy_writel, NULL);
}
static void pci_dummy_io_set(void)
static void
pci_dummy_io_set(void)
{
io_sethandler(pci_bar[0].addr, 0x0020, pci_dummy_read, pci_dummy_readw, pci_dummy_readl, pci_dummy_write, pci_dummy_writew, pci_dummy_writel, NULL);
}
static uint8_t pci_dummy_pci_read(int func, int addr, void *priv)
static uint8_t
pci_dummy_pci_read(int func, int addr, void *priv)
{
pclog("AB0B:071A: PCI_Read(%d, %04x)\n", func, addr);
switch(addr) {
switch (addr) {
case 0x00:
return 0x1A;
case 0x01:
@@ -173,20 +171,19 @@ static uint8_t pci_dummy_pci_read(int func, int addr, void *priv)
}
}
static void pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv)
static void
pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv)
{
uint8_t valxor;
pclog("AB0B:071A: PCI_Write(%d, %04x, %02x)\n", func, addr, val);
switch(addr) {
switch (addr) {
case 0x04: /* PCI_COMMAND_LO */
valxor = (val & 0x03) ^ pci_regs[addr];
if (valxor & PCI_COMMAND_IO)
{
if (valxor & PCI_COMMAND_IO) {
pci_dummy_io_remove();
if (((pci_bar[0].addr & 0xffe0) != 0) && (val & PCI_COMMAND_IO))
{
if (((pci_bar[0].addr & 0xffe0) != 0) && (val & PCI_COMMAND_IO)) {
pci_dummy_io_set();
}
}
@@ -214,10 +211,8 @@ static void pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv)
pclog("AB0B:071A: PCI: new I/O base is %04X\n", pci_bar[0].addr);
/* We're done, so get out of the here. */
if (pci_regs[4] & PCI_COMMAND_IO)
{
if ((pci_bar[0].addr) != 0)
{
if (pci_regs[4] & PCI_COMMAND_IO) {
if ((pci_bar[0].addr) != 0) {
pci_dummy_io_set();
}
}
@@ -230,8 +225,8 @@ static void pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv)
}
}
void pci_dummy_init(void)
void
pci_dummy_init(void)
{
card = pci_add_card(PCI_ADD_NORMAL, pci_dummy_pci_read, pci_dummy_pci_write, NULL);

View File

@@ -36,19 +36,15 @@
#include <86box/nvr.h>
#include <86box/acpi.h>
enum
{
enum {
STATE_NONE = 0,
STATE_ICW2,
STATE_ICW3,
STATE_ICW4
};
pic_t pic, pic2;
static pc_timer_t pic_timer;
static int shadow = 0, elcr_enabled = 0,
@@ -60,11 +56,9 @@ static uint16_t smi_irq_mask = 0x0000,
static void (*update_pending)(void);
#ifdef ENABLE_PIC_LOG
int pic_do_log = ENABLE_PIC_LOG;
static void
pic_log(const char *fmt, ...)
{
@@ -77,17 +71,15 @@ pic_log(const char *fmt, ...)
}
}
#else
#define pic_log(fmt, ...)
# define pic_log(fmt, ...)
#endif
void
pic_reset_smi_irq_mask(void)
{
smi_irq_mask = 0x0000;
}
void
pic_set_smi_irq_mask(int irq, int set)
{
@@ -105,7 +97,6 @@ pic_get_smi_irq_status(void)
return smi_irq_status;
}
void
pic_clear_smi_irq_status(int irq)
{
@@ -113,7 +104,6 @@ pic_clear_smi_irq_status(int irq)
smi_irq_status &= ~(1 << irq);
}
void
pic_elcr_write(uint16_t port, uint8_t val, void *priv)
{
@@ -140,7 +130,6 @@ pic_elcr_write(uint16_t port, uint8_t val, void *priv)
(val & 0x80) ? 'L' : 'E');
}
uint8_t
pic_elcr_read(uint16_t port, void *priv)
{
@@ -151,21 +140,18 @@ pic_elcr_read(uint16_t port, void *priv)
return dev->elcr;
}
int
pic_elcr_get_enabled(void)
{
return elcr_enabled;
}
void
pic_elcr_set_enabled(int enabled)
{
elcr_enabled = enabled;
}
void
pic_elcr_io_handler(int set)
{
@@ -177,24 +163,20 @@ pic_elcr_io_handler(int set)
pic_elcr_write, NULL, NULL, &pic2);
}
static uint8_t
pic_cascade_mode(pic_t *dev)
{
return !(dev->icw1 & 2);
}
static __inline uint8_t
pic_slave_on(pic_t *dev, int channel)
{
pic_log("pic_slave_on(%i): %i, %02X, %02X\n", channel, pic_cascade_mode(dev), dev->icw4 & 0x0c, dev->icw3 & (1 << channel));
return pic_cascade_mode(dev) && (dev->is_master || ((dev->icw4 & 0x0c) == 0x0c)) &&
(dev->icw3 & (1 << channel));
return pic_cascade_mode(dev) && (dev->is_master || ((dev->icw4 & 0x0c) == 0x0c)) && (dev->icw3 & (1 << channel));
}
static __inline int
find_best_interrupt(pic_t *dev)
{
@@ -228,7 +210,6 @@ find_best_interrupt(pic_t *dev)
return ret;
}
static __inline void
pic_update_pending_xt(void)
{
@@ -240,7 +221,6 @@ pic_update_pending_xt(void)
pic.int_pending = 0;
}
static __inline void
pic_update_pending_at(void)
{
@@ -254,7 +234,6 @@ pic_update_pending_at(void)
pic.int_pending = (find_best_interrupt(&pic) != -1);
}
static void
pic_callback(void *priv)
{
@@ -267,7 +246,6 @@ pic_callback(void *priv)
timer_on_auto(&pic_timer, 0.35);
}
void
pic_reset()
{
@@ -298,21 +276,18 @@ pic_reset()
pic_pci = 0;
}
void
pic_set_shadow(int sh)
{
shadow = sh;
}
void
pic_set_pci_flag(int pci)
{
pic_pci = pci;
}
static uint8_t
pic_level_triggered(pic_t *dev, int irq)
{
@@ -322,14 +297,12 @@ pic_level_triggered(pic_t *dev, int irq)
return !!(dev->icw1 & 8);
}
int
picint_is_level(int irq)
{
return pic_level_triggered(((irq > 7) ? &pic2 : &pic), irq & 7);
}
static void
pic_acknowledge(pic_t *dev)
{
@@ -341,7 +314,6 @@ pic_acknowledge(pic_t *dev)
dev->irr &= ~pic_int_num;
}
/* Find IRQ for non-specific EOI (either by command or automatic) by finding the highest IRQ
priority with ISR bit set, that is also not masked if the PIC is in special mask mode. */
static uint8_t
@@ -363,7 +335,6 @@ pic_non_specific_find(pic_t *dev)
return irq;
}
/* Do the EOI and rotation, if either is requested, on the given IRQ. */
static void
pic_action(pic_t *dev, uint8_t irq, uint8_t eoi, uint8_t rotate)
@@ -380,7 +351,6 @@ pic_action(pic_t *dev, uint8_t irq, uint8_t eoi, uint8_t rotate)
}
}
/* Automatic non-specific EOI. */
static __inline void
pic_auto_non_specific_eoi(pic_t *dev)
@@ -394,7 +364,6 @@ pic_auto_non_specific_eoi(pic_t *dev)
}
}
/* Do the PIC command specified by bits 7-5 of the value written to the OCW2 register. */
static void
pic_command(pic_t *dev)
@@ -412,7 +381,6 @@ pic_command(pic_t *dev)
dev->auto_eoi_rotate = !!(dev->ocw2 & 0x80);
}
uint8_t
pic_read(uint16_t addr, void *priv)
{
@@ -464,7 +432,6 @@ pic_read(uint16_t addr, void *priv)
return dev->data_bus;
}
static void
pic_write(uint16_t addr, uint8_t val, void *priv)
{
@@ -528,7 +495,6 @@ pic_write(uint16_t addr, uint8_t val, void *priv)
}
}
void
pic_set_pci(void)
{
@@ -545,7 +511,6 @@ pic_set_pci(void)
}
}
void
pic_init(void)
{
@@ -555,7 +520,6 @@ pic_init(void)
io_sethandler(0x0020, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic);
}
void
pic_init_pcjr(void)
{
@@ -565,7 +529,6 @@ pic_init_pcjr(void)
io_sethandler(0x0020, 0x0008, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic);
}
void
pic2_init(void)
{
@@ -573,7 +536,6 @@ pic2_init(void)
pic.slaves[2] = &pic2;
}
void
picint_common(uint16_t num, int level, int set)
{
@@ -645,35 +607,30 @@ picint_common(uint16_t num, int level, int set)
update_pending();
}
void
picint(uint16_t num)
{
picint_common(num, 0, 1);
}
void
picintlevel(uint16_t num)
{
picint_common(num, 1, 1);
}
void
picintc(uint16_t num)
{
picint_common(num, 0, 0);
}
static uint8_t
pic_i86_mode(pic_t *dev)
{
return !!(dev->icw4 & 1);
}
static uint8_t
pic_irq_ack_read(pic_t *dev, int phase)
{
@@ -718,7 +675,6 @@ pic_irq_ack_read(pic_t *dev, int phase)
return dev->data_bus;
}
uint8_t
pic_irq_ack(void)
{
@@ -750,7 +706,6 @@ pic_irq_ack(void)
return ret;
}
int
picinterrupt()
{

116
src/pit.c
View File

@@ -58,20 +58,16 @@ uint64_t PITCONST, ISACONST,
int refresh_at_enable = 1,
io_delay = 5;
int64_t firsttime = 1;
#define PIT_PS2 16 /* The PIT is the PS/2's second PIT. */
#define PIT_EXT_IO 32 /* The PIT has externally specified port I/O. */
#define PIT_CUSTOM_CLOCK 64 /* The PIT uses custom clock inputs provided by another provider. */
#define PIT_SECONDARY 128 /* The PIT is secondary (ports 0048-004B). */
#ifdef ENABLE_PIT_LOG
int pit_do_log = ENABLE_PIT_LOG;
static void
pit_log(const char *fmt, ...)
{
@@ -84,10 +80,9 @@ pit_log(const char *fmt, ...)
}
}
#else
#define pit_log(fmt, ...)
# define pit_log(fmt, ...)
#endif
static void
ctr_set_out(ctr_t *ctr, int out)
{
@@ -99,7 +94,6 @@ ctr_set_out(ctr_t *ctr, int out)
ctr->out = out;
}
static void
ctr_decrease_count(ctr_t *ctr)
{
@@ -127,7 +121,6 @@ ctr_decrease_count(ctr_t *ctr)
ctr->count = (ctr->count - 1) & 0xffff;
}
static void
ctr_load_count(ctr_t *ctr)
{
@@ -139,7 +132,6 @@ ctr_load_count(ctr_t *ctr)
ctr->newcount = !!(l & 1);
}
static void
ctr_tick(ctr_t *ctr)
{
@@ -154,7 +146,7 @@ ctr_tick(ctr_t *ctr)
return;
}
switch(ctr->m & 0x07) {
switch (ctr->m & 0x07) {
case 0:
/* Interrupt on terminal count */
switch (state) {
@@ -194,7 +186,8 @@ ctr_tick(ctr_t *ctr)
break;
}
break;
case 2: case 6:
case 2:
case 6:
/* Rate generator */
switch (state) {
case 3:
@@ -215,7 +208,8 @@ ctr_tick(ctr_t *ctr)
break;
}
break;
case 3: case 7:
case 3:
case 7:
/* Square wave mode */
switch (state) {
case 2:
@@ -257,11 +251,12 @@ ctr_tick(ctr_t *ctr)
break;
}
break;
case 4: case 5:
case 4:
case 5:
/* Software triggered strobe */
/* Hardware triggered strobe */
if ((ctr->gate != 0) || (ctr->m != 4)) {
switch(state) {
switch (state) {
case 0:
ctr_decrease_count(ctr);
break;
@@ -286,11 +281,10 @@ ctr_tick(ctr_t *ctr)
}
}
static void
ctr_clock(void *data, int counter_id)
{
pit_t *pit = (pit_t *)data;
pit_t *pit = (pit_t *) data;
ctr_t *ctr = &pit->counters[counter_id];
/* FIXME: Is this even needed? */
@@ -303,7 +297,6 @@ ctr_clock(void *data, int counter_id)
ctr_tick(ctr);
}
static void
ctr_set_state_1(ctr_t *ctr)
{
@@ -313,7 +306,6 @@ ctr_set_state_1(ctr_t *ctr)
ctr->state = 1;
}
static void
ctr_load(ctr_t *ctr)
{
@@ -337,7 +329,6 @@ ctr_load(ctr_t *ctr)
pit_log("Counter loaded, state = %i, gate = %i\n", ctr->state, ctr->gate);
}
static __inline void
ctr_latch_status(ctr_t *ctr)
{
@@ -345,7 +336,6 @@ ctr_latch_status(ctr_t *ctr)
ctr->do_read_status = 1;
}
static __inline void
ctr_latch_count(ctr_t *ctr)
{
@@ -375,47 +365,43 @@ ctr_latch_count(ctr_t *ctr)
pit_log("latched counter = %04X\n", ctr->rl & 0xffff);
}
uint16_t
pit_ctr_get_count(void *data, int counter_id)
{
pit_t *pit = (pit_t *)data;
pit_t *pit = (pit_t *) data;
ctr_t *ctr = &pit->counters[counter_id];
return (uint16_t) ctr->l;
}
void
pit_ctr_set_load_func(void *data, int counter_id, void (*func)(uint8_t new_m, int new_count))
{
if (data == NULL)
return;
pit_t *pit = (pit_t *)data;
pit_t *pit = (pit_t *) data;
ctr_t *ctr = &pit->counters[counter_id];
ctr->load_func = func;
}
void
pit_ctr_set_out_func(void *data, int counter_id, void (*func)(int new_out, int old_out))
{
if (data == NULL)
return;
pit_t *pit = (pit_t *)data;
pit_t *pit = (pit_t *) data;
ctr_t *ctr = &pit->counters[counter_id];
ctr->out_func = func;
}
void
pit_ctr_set_gate(void *data, int counter_id, int gate)
{
pit_t *pit = (pit_t *)data;
pit_t *pit = (pit_t *) data;
ctr_t *ctr = &pit->counters[counter_id];
int old = ctr->gate;
@@ -424,7 +410,12 @@ pit_ctr_set_gate(void *data, int counter_id, int gate)
ctr->gate = gate;
switch (mode) {
case 1: case 2: case 3: case 5: case 6: case 7:
case 1:
case 2:
case 3:
case 5:
case 6:
case 7:
if (!old && gate) {
/* Here we handle the rising edges. */
if (mode & 1) {
@@ -442,7 +433,6 @@ pit_ctr_set_gate(void *data, int counter_id, int gate)
}
}
static __inline void
pit_ctr_set_clock_common(ctr_t *ctr, int clock)
{
@@ -471,25 +461,22 @@ pit_ctr_set_clock_common(ctr_t *ctr, int clock)
}
}
void
pit_ctr_set_clock(ctr_t *ctr, int clock)
{
pit_ctr_set_clock_common(ctr, clock);
}
void
pit_ctr_set_using_timer(void *data, int counter_id, int using_timer)
{
if (tsc > 0)
timer_process();
pit_t *pit = (pit_t *)data;
pit_t *pit = (pit_t *) data;
ctr_t *ctr = &pit->counters[counter_id];
ctr->using_timer = using_timer;
}
static void
pit_timer_over(void *p)
{
@@ -504,11 +491,10 @@ pit_timer_over(void *p)
timer_advance_u64(&dev->callback_timer, PITCONST >> 1ULL);
}
static void
pit_write(uint16_t addr, uint8_t val, void *priv)
{
pit_t *dev = (pit_t *)priv;
pit_t *dev = (pit_t *) priv;
int t = (addr & 3);
ctr_t *ctr;
@@ -588,7 +574,8 @@ pit_write(uint16_t addr, uint8_t val, void *priv)
ctr_set_out(ctr, 0);
ctr_load(ctr);
break;
case 3: case 0x83:
case 3:
case 0x83:
if (ctr->wm & 0x80) {
ctr->l = (ctr->l & 0x00ff) | (val << 8);
pit_log("PIT %i: Written high byte %02X, latch now %04X\n", t, val, ctr->l);
@@ -612,11 +599,10 @@ pit_write(uint16_t addr, uint8_t val, void *priv)
}
}
static uint8_t
pit_read(uint16_t addr, void *priv)
{
pit_t *dev = (pit_t *)priv;
pit_t *dev = (pit_t *) priv;
uint8_t ret = 0xff;
int count, t = (addr & 3);
ctr_t *ctr;
@@ -649,8 +635,10 @@ pit_read(uint16_t addr, void *priv)
ctr->rm |= 0x80;
ctr->latched--;
} else switch (ctr->rm) {
case 0: case 0x80:
} else
switch (ctr->rm) {
case 0:
case 0x80:
ret = 0x00;
break;
@@ -662,7 +650,8 @@ pit_read(uint16_t addr, void *priv)
ret = count >> 8;
break;
case 3: case 0x83:
case 3:
case 0x83:
/* Yes, wm is correct here - this is to ensure correct readout while the
count is being written. */
if (ctr->wm & 0x80)
@@ -684,7 +673,6 @@ pit_read(uint16_t addr, void *priv)
return ret;
}
void
pit_irq0_timer_ps2(int new_out, int old_out)
{
@@ -700,7 +688,6 @@ pit_irq0_timer_ps2(int new_out, int old_out)
pit_devs[1].ctr_clock(pit_devs[1].data, 0);
}
void
pit_refresh_timer_xt(int new_out, int old_out)
{
@@ -708,7 +695,6 @@ pit_refresh_timer_xt(int new_out, int old_out)
dma_channel_read(0);
}
void
pit_refresh_timer_at(int new_out, int old_out)
{
@@ -716,7 +702,6 @@ pit_refresh_timer_at(int new_out, int old_out)
ppi.pb ^= 0x10;
}
void
pit_speaker_timer(int new_out, int old_out)
{
@@ -737,7 +722,6 @@ pit_speaker_timer(int new_out, int old_out)
ppispeakon = new_out;
}
void
pit_nmi_timer_ps2(int new_out, int old_out)
{
@@ -747,7 +731,6 @@ pit_nmi_timer_ps2(int new_out, int old_out)
nmi_auto_clear = 1;
}
static void
ctr_reset(ctr_t *ctr)
{
@@ -765,7 +748,6 @@ ctr_reset(ctr_t *ctr)
ctr->l_det = 0;
}
void
pit_reset(pit_t *dev)
{
@@ -782,14 +764,12 @@ pit_reset(pit_t *dev)
dev->counters[2].gate = 0;
}
void
pit_handler(int set, uint16_t base, int size, void *priv)
{
io_handler(set, base, size, pit_read, NULL, NULL, pit_write, NULL, NULL, priv);
}
static void
pit_close(void *priv)
{
@@ -805,7 +785,6 @@ pit_close(void *priv)
free(dev);
}
static void *
pit_init(const device_t *info)
{
@@ -923,7 +902,6 @@ pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(i
pit = device_add(&i8254_fast_device);
*pit_intf = pit_fast_intf;
break;
}
pit_intf->data = pit;
@@ -943,7 +921,6 @@ pit_common_init(int type, void (*out0)(int new_out, int old_out), void (*out1)(i
return pit;
}
pit_t *
pit_ps2_init(int type)
{
@@ -980,7 +957,6 @@ pit_ps2_init(int type)
return pit;
}
void
pit_set_clock(int clock)
{
@@ -995,9 +971,9 @@ pit_set_clock(int clock)
cpuclock = (double) clock;
PITCONSTD = (cpuclock / 1193182.0);
PITCONST = (uint64_t) (PITCONSTD * (double)(1ull << 32));
CGACONST = (uint64_t) ((cpuclock / (19687503.0/11.0)) * (double)(1ull << 32));
ISACONST = (uint64_t) ((cpuclock / (double)cpu_isa_speed) * (double)(1ull << 32));
PITCONST = (uint64_t) (PITCONSTD * (double) (1ull << 32));
CGACONST = (uint64_t) ((cpuclock / (19687503.0 / 11.0)) * (double) (1ull << 32));
ISACONST = (uint64_t) ((cpuclock / (double) cpu_isa_speed) * (double) (1ull << 32));
xt_cpu_multi = 1ULL;
} else {
cpuclock = 14318184.0;
@@ -1045,8 +1021,8 @@ pit_set_clock(int clock)
CGACONST = (16ULL << 32LL);
} else if (cpuclock != 14318184.0) {
PITCONSTD = (cpuclock / 1193182.0);
PITCONST = (uint64_t) (PITCONSTD * (double)(1ull << 32));
CGACONST = (uint64_t) (((cpuclock/(19687503.0/11.0)) * (double)(1ull << 32)));
PITCONST = (uint64_t) (PITCONSTD * (double) (1ull << 32));
CGACONST = (uint64_t) (((cpuclock / (19687503.0 / 11.0)) * (double) (1ull << 32)));
}
ISACONST = (1ULL << 32ULL);
@@ -1056,21 +1032,21 @@ pit_set_clock(int clock)
/* Delay for empty I/O ports. */
io_delay = (int) round(((double) cpu_s->rspeed) / 3000000.0);
MDACONST = (uint64_t) (cpuclock / 2032125.0 * (double)(1ull << 32));
MDACONST = (uint64_t) (cpuclock / 2032125.0 * (double) (1ull << 32));
HERCCONST = MDACONST;
VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double)(1ull << 32));
VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double)(1ull << 32));
RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double)(1ull << 32));
VGACONST1 = (uint64_t) (cpuclock / 25175000.0 * (double) (1ull << 32));
VGACONST2 = (uint64_t) (cpuclock / 28322000.0 * (double) (1ull << 32));
RTCCONST = (uint64_t) (cpuclock / 32768.0 * (double) (1ull << 32));
TIMER_USEC = (uint64_t)((cpuclock / 1000000.0) * (double)(1ull << 32));
TIMER_USEC = (uint64_t) ((cpuclock / 1000000.0) * (double) (1ull << 32));
isa_timing = (cpuclock / (double)cpu_isa_speed);
isa_timing = (cpuclock / (double) cpu_isa_speed);
if (cpu_64bitbus)
bus_timing = (cpuclock / ((double)cpu_busspeed / 2));
bus_timing = (cpuclock / ((double) cpu_busspeed / 2));
else
bus_timing = (cpuclock / (double)cpu_busspeed);
pci_timing = (cpuclock / (double)cpu_pci_speed);
agp_timing = (cpuclock / (double)cpu_agp_speed);
bus_timing = (cpuclock / (double) cpu_busspeed);
pci_timing = (cpuclock / (double) cpu_pci_speed);
agp_timing = (cpuclock / (double) cpu_agp_speed);
/* PCICLK in us for use with timer_on_auto(). */
PCICLK = pci_timing / (cpuclock / 1000000.0);

View File

@@ -61,7 +61,7 @@ pit_log(const char *fmt, ...)
}
}
#else
#define pit_log(fmt, ...)
# define pit_log(fmt, ...)
#endif
static void
@@ -81,7 +81,7 @@ pitf_ctr_set_load_func(void *data, int counter_id, void (*func)(uint8_t new_m, i
if (data == NULL)
return;
pitf_t *pit = (pitf_t *)data;
pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id];
ctr->load_func = func;
@@ -90,7 +90,7 @@ pitf_ctr_set_load_func(void *data, int counter_id, void (*func)(uint8_t new_m, i
static uint16_t
pitf_ctr_get_count(void *data, int counter_id)
{
pitf_t *pit = (pitf_t *)data;
pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id];
return (uint16_t) ctr->l;
}
@@ -101,7 +101,7 @@ pitf_ctr_set_out_func(void *data, int counter_id, void (*func)(int new_out, int
if (data == NULL)
return;
pitf_t *pit = (pitf_t *)data;
pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id];
ctr->out_func = func;
@@ -113,7 +113,7 @@ pitf_ctr_set_using_timer(void *data, int counter_id, int using_timer)
if (tsc > 0)
timer_process();
pitf_t *pit = (pitf_t *)data;
pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id];
ctr->using_timer = using_timer;
}
@@ -275,7 +275,7 @@ pitf_set_gate_no_timer(ctrf_t *ctr, int gate)
static void
pitf_ctr_set_gate(void *data, int counter_id, int gate)
{
pitf_t *pit = (pitf_t *)data;
pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id];
if (ctr->disabled) {
@@ -548,7 +548,7 @@ pitf_timer_over(void *p)
static void
pitf_ctr_clock(void *data, int counter_id)
{
pitf_t *pit = (pitf_t *)data;
pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id];
if (ctr->thit || !ctr->enabled)
@@ -613,7 +613,7 @@ pitf_init(const device_t *info)
if (!(dev->flags & PIT_PS2) && !(dev->flags & PIT_CUSTOM_CLOCK)) {
for (int i = 0; i < 3; i++) {
ctrf_t *ctr = &dev->counters[i];
timer_add(&ctr->timer, pitf_timer_over, (void *)ctr, 0);
timer_add(&ctr->timer, pitf_timer_over, (void *) ctr, 0);
}
}

View File

@@ -35,7 +35,6 @@
#include <86box/video.h>
#include <86box/port_6x.h>
#define PS2_REFRESH_TIME (16 * TIMER_USEC)
#define PORT_6X_TURBO 1
@@ -43,7 +42,6 @@
#define PORT_6X_MIRROR 4
#define PORT_6X_SWA 8
static void
port_6x_write(uint16_t port, uint8_t val, void *priv)
{
@@ -79,7 +77,7 @@ port_61_read_simple(uint16_t port, void *priv)
if (ppispeakon)
ret |= 0x20;
return(ret);
return (ret);
}
static uint8_t
@@ -102,7 +100,7 @@ port_61_read(uint16_t port, void *priv)
if (dev->flags & PORT_6X_TURBO)
ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00);
return(ret);
return (ret);
}
static uint8_t
@@ -138,7 +136,7 @@ port_62_read(uint16_t port, void *priv)
ret |= 0x02;
}
return(ret);
return (ret);
}
static void
@@ -150,7 +148,6 @@ port_6x_refresh(void *priv)
timer_advance_u64(&dev->refresh_timer, PS2_REFRESH_TIME);
}
static void
port_6x_close(void *priv)
{
@@ -161,7 +158,6 @@ port_6x_close(void *priv)
free(dev);
}
void *
port_6x_init(const device_t *info)
{

View File

@@ -30,14 +30,12 @@
#include <86box/pit.h>
#include <86box/port_92.h>
#define PORT_92_INV 1
#define PORT_92_WORD 2
#define PORT_92_PCI 4
#define PORT_92_RESET 8
#define PORT_92_A20 16
static uint8_t
port_92_readb(uint16_t port, void *priv)
{
@@ -47,8 +45,7 @@ port_92_readb(uint16_t port, void *priv)
if (port == 0x92) {
/* Return bit 1 directly from mem_a20_alt, so the
pin can be reset independently of the device. */
ret = (dev->reg & ~0x03) | (mem_a20_alt & 2) |
(cpu_alt_reset & 1);
ret = (dev->reg & ~0x03) | (mem_a20_alt & 2) | (cpu_alt_reset & 1);
if (dev->flags & PORT_92_INV)
ret |= 0xfc;
@@ -60,7 +57,6 @@ port_92_readb(uint16_t port, void *priv)
return ret;
}
static uint16_t
port_92_readw(uint16_t port, void *priv)
{
@@ -73,7 +69,6 @@ port_92_readw(uint16_t port, void *priv)
return ret;
}
static void
port_92_pulse(void *priv)
{
@@ -81,7 +76,6 @@ port_92_pulse(void *priv)
cpu_set_edx();
}
static void
port_92_writeb(uint16_t port, uint8_t val, void *priv)
{
@@ -108,7 +102,6 @@ port_92_writeb(uint16_t port, uint8_t val, void *priv)
dev->reg |= 0xfc;
}
static void
port_92_writew(uint16_t port, uint16_t val, void *priv)
{
@@ -118,7 +111,6 @@ port_92_writew(uint16_t port, uint16_t val, void *priv)
port_92_writeb(port, val & 0xff, priv);
}
void
port_92_set_period(void *priv, uint64_t pulse_period)
{
@@ -127,7 +119,6 @@ port_92_set_period(void *priv, uint64_t pulse_period)
dev->pulse_period = pulse_period;
}
void
port_92_set_features(void *priv, int reset, int a20)
{
@@ -149,7 +140,6 @@ port_92_set_features(void *priv, int reset, int a20)
mem_a20_recalc();
}
void
port_92_add(void *priv)
{
@@ -163,7 +153,6 @@ port_92_add(void *priv)
port_92_readb, NULL, NULL, port_92_writeb, NULL, NULL, dev);
}
void
port_92_remove(void *priv)
{
@@ -177,7 +166,6 @@ port_92_remove(void *priv)
port_92_readb, NULL, NULL, port_92_writeb, NULL, NULL, dev);
}
static void
port_92_close(void *priv)
{
@@ -188,7 +176,6 @@ port_92_close(void *priv)
free(dev);
}
void *
port_92_init(const device_t *info)
{
@@ -209,7 +196,7 @@ port_92_init(const device_t *info)
port_92_add(dev);
dev->pulse_period = (uint64_t) (4.0 * SYSCLK * (double)(1ULL << 32ULL));
dev->pulse_period = (uint64_t) (4.0 * SYSCLK * (double) (1ULL << 32ULL));
dev->flags |= (PORT_92_RESET | PORT_92_A20);

View File

@@ -15,11 +15,9 @@
#include <86box/pit.h>
#include <86box/ppi.h>
PPI ppi;
int ppispeakon;
void
ppi_reset(void)
{

View File

@@ -18,59 +18,63 @@
#include <stdlib.h>
#include <86box/random.h>
#if !(defined(__i386__) || defined (__x86_64__))
#include <time.h>
#if !(defined(__i386__) || defined(__x86_64__))
# include <time.h>
#endif
uint32_t preconst = 0x6ED9EBA1;
static __inline uint32_t rotl32c (uint32_t x, uint32_t n)
static __inline uint32_t
rotl32c(uint32_t x, uint32_t n)
{
#if 0
assert (n<32);
#endif
return (x<<n) | (x>>(-n&31));
return (x << n) | (x >> (-n & 31));
}
static __inline uint32_t rotr32c (uint32_t x, uint32_t n)
static __inline uint32_t
rotr32c(uint32_t x, uint32_t n)
{
#if 0
assert (n<32);
#endif
return (x>>n) | (x<<(-n&31));
return (x >> n) | (x << (-n & 31));
}
#define ROTATE_LEFT rotl32c
#define ROTATE_RIGHT rotr32c
static __inline unsigned long long rdtsc(void)
static __inline unsigned long long
rdtsc(void)
{
#if defined(__i386__) || defined (__x86_64__)
#if defined(__i386__) || defined(__x86_64__)
unsigned hi, lo;
#ifdef _MSC_VER
# ifdef _MSC_VER
__asm {
rdtsc
mov hi, edx ; EDX:EAX is already standard return!!
mov lo, eax
}
#else
__asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
#endif
return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
# else
__asm__ __volatile__("rdtsc"
: "=a"(lo), "=d"(hi));
# endif
return ((unsigned long long) lo) | (((unsigned long long) hi) << 32);
#else
return time(NULL);
#endif
}
static uint32_t RDTSC(void)
static uint32_t
RDTSC(void)
{
return (uint32_t) (rdtsc());
}
static void random_twist(uint32_t *val)
static void
random_twist(uint32_t *val)
{
*val = ROTATE_LEFT(*val, rand() % 32);
*val ^= 0x5A827999;
@@ -78,8 +82,8 @@ static void random_twist(uint32_t *val)
*val ^= 0x4ED32706;
}
uint8_t random_generate(void)
uint8_t
random_generate(void)
{
uint16_t r = 0;
r = (RDTSC() ^ ROTATE_LEFT(preconst, rand() % 32)) % 256;
@@ -87,8 +91,8 @@ uint8_t random_generate(void)
return (r & 0xff);
}
void random_init(void)
void
random_init(void)
{
uint32_t seed = RDTSC();
srand(seed);

View File

@@ -5,8 +5,7 @@
#include <86box/plat.h>
#include <86box/thread.h>
struct event_cpp11_t
{
struct event_cpp11_t {
std::condition_variable cond;
std::mutex mutex;
bool state = false;
@@ -26,8 +25,9 @@ thread_create(void (*thread_rout)(void *param), void *param)
int
thread_wait(thread_t *arg)
{
if (!arg) return 0;
auto thread = reinterpret_cast<std::thread*>(arg);
if (!arg)
return 0;
auto thread = reinterpret_cast<std::thread *>(arg);
thread->join();
return 0;
}
@@ -45,7 +45,7 @@ thread_test_mutex(mutex_t *_mutex)
if (_mutex == nullptr)
return 0;
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
auto mutex = reinterpret_cast<std::mutex *>(_mutex);
return mutex->try_lock() ? 1 : 0;
}
@@ -55,28 +55,26 @@ thread_wait_mutex(mutex_t *_mutex)
if (_mutex == nullptr)
return 0;
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
auto mutex = reinterpret_cast<std::mutex *>(_mutex);
mutex->lock();
return 1;
}
int
thread_release_mutex(mutex_t *_mutex)
{
if (_mutex == nullptr)
return 0;
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
auto mutex = reinterpret_cast<std::mutex *>(_mutex);
mutex->unlock();
return 1;
}
void
thread_close_mutex(mutex_t *_mutex)
{
auto mutex = reinterpret_cast<std::mutex*>(_mutex);
auto mutex = reinterpret_cast<std::mutex *>(_mutex);
delete mutex;
}
@@ -90,7 +88,7 @@ thread_create_event()
int
thread_wait_event(event_t *handle, int timeout)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
auto event = reinterpret_cast<event_cpp11_t *>(handle);
auto lock = std::unique_lock<std::mutex>(event->mutex);
if (timeout < 0) {
@@ -113,7 +111,7 @@ thread_wait_event(event_t *handle, int timeout)
void
thread_set_event(event_t *handle)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
auto event = reinterpret_cast<event_cpp11_t *>(handle);
{
auto lock = std::unique_lock<std::mutex>(event->mutex);
event->state = true;
@@ -124,7 +122,7 @@ thread_set_event(event_t *handle)
void
thread_reset_event(event_t *handle)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
auto event = reinterpret_cast<event_cpp11_t *>(handle);
auto lock = std::unique_lock<std::mutex>(event->mutex);
event->state = false;
}
@@ -132,8 +130,7 @@ thread_reset_event(event_t *handle)
void
thread_destroy_event(event_t *handle)
{
auto event = reinterpret_cast<event_cpp11_t*>(handle);
auto event = reinterpret_cast<event_cpp11_t *>(handle);
delete event;
}
}

View File

@@ -5,7 +5,6 @@
#include <86box/86box.h>
#include <86box/timer.h>
uint64_t TIMER_USEC;
uint32_t timer_target;
@@ -16,7 +15,6 @@ pc_timer_t *timer_head = NULL;
/* Are we initialized? */
int timer_inited = 0;
void
timer_enable(pc_timer_t *timer)
{
@@ -59,7 +57,7 @@ timer_enable(pc_timer_t *timer)
pc_timer_t *prev = timer_head;
timer_node = timer_head->next;
while(1) {
while (1) {
/*Timer expires before timer_node. Add to list in front of timer_node*/
if (TIMER_LESS_THAN(timer, timer_node)) {
timer->next = timer_node;
@@ -81,7 +79,6 @@ timer_enable(pc_timer_t *timer)
}
}
void
timer_disable(pc_timer_t *timer)
{
@@ -102,7 +99,6 @@ timer_disable(pc_timer_t *timer)
timer->prev = timer->next = NULL;
}
void
timer_process(void)
{
@@ -111,10 +107,10 @@ timer_process(void)
if (!timer_head)
return;
while(1) {
while (1) {
timer = timer_head;
if (!TIMER_LESS_THAN_VAL(timer, (uint32_t)tsc))
if (!TIMER_LESS_THAN_VAL(timer, (uint32_t) tsc))
break;
timer_head = timer->next;
@@ -133,7 +129,6 @@ timer_process(void)
timer_target = timer_head->ts.ts32.integer;
}
void
timer_close(void)
{
@@ -153,7 +148,6 @@ timer_close(void)
timer_inited = 0;
}
void
timer_init(void)
{
@@ -163,7 +157,6 @@ timer_init(void)
timer_inited = 1;
}
void
timer_add(pc_timer_t *timer, void (*callback)(void *p), void *p, int start_timer)
{
@@ -177,7 +170,6 @@ timer_add(pc_timer_t *timer, void (*callback)(void *p), void *p, int start_timer
timer_set_delay_u64(timer, 0);
}
/* The API for big timer periods starts here. */
void
timer_stop(pc_timer_t *timer)
@@ -190,7 +182,6 @@ timer_stop(pc_timer_t *timer)
timer->flags &= ~TIMER_SPLIT;
}
static void
timer_do_period(pc_timer_t *timer, uint64_t period, int start)
{
@@ -203,7 +194,6 @@ timer_do_period(pc_timer_t *timer, uint64_t period, int start)
timer_advance_u64(timer, period);
}
void
timer_advance_ex(pc_timer_t *timer, int start)
{
@@ -224,7 +214,6 @@ timer_advance_ex(pc_timer_t *timer, int start)
}
}
void
timer_on(pc_timer_t *timer, double period, int start)
{
@@ -235,7 +224,6 @@ timer_on(pc_timer_t *timer, double period, int start)
timer_advance_ex(timer, start);
}
void
timer_on_auto(pc_timer_t *timer, double period)
{

View File

@@ -31,18 +31,16 @@
fflush(stdout); \
}
#else
#include <stdarg.h>
#define HAVE_STDARG_H
#include <86box/86box.h>
#include <86box/device.h>
#include <86box/io.h>
#include <86box/timer.h>
# include <stdarg.h>
# define HAVE_STDARG_H
# include <86box/86box.h>
# include <86box/device.h>
# include <86box/io.h>
# include <86box/timer.h>
#ifdef ENABLE_UPI42_LOG
# ifdef ENABLE_UPI42_LOG
int upi42_do_log = ENABLE_UPI42_LOG;
void
upi42_log(const char *fmt, ...)
{
@@ -54,9 +52,9 @@ upi42_log(const char *fmt, ...)
va_end(ap);
}
}
#else
#define upi42_log(fmt, ...)
#endif
# else
# define upi42_log(fmt, ...)
# endif
#endif
#define UPI42_REG(upi42, r, op) ((upi42->psw & 0x10) ? (upi42->ram[24 + ((r) &7)] op) : (upi42->ram[(r) &7] op))
@@ -1290,7 +1288,6 @@ upi42_write(uint16_t port, uint8_t val, void *priv)
}
}
static uint8_t
upi42_read(uint16_t port, void *priv)
{
@@ -1372,8 +1369,7 @@ upi42_read(uint16_t port, void *priv)
/* 0 = I, 1 = I Raise, 2 = TCNTI Raise, 3 = IRQ Mask, 4 = T0, 5 = T1, 6 = Flags, 7 = DBF. */
case 0x0194:
ret = (upi42->i & 0x01) || ((upi42->i_raise & 0x01) << 1) || ((upi42->tcnti_raise & 0x01) << 2) || ((upi42->irq_mask & 0x01) << 3) ||
((upi42->t0 & 0x01) << 4) || ((upi42->t1 & 0x01) << 5) || ((upi42->flags & 0x01) << 6) || ((upi42->dbf & 0x01) << 7);
ret = (upi42->i & 0x01) || ((upi42->i_raise & 0x01) << 1) || ((upi42->tcnti_raise & 0x01) << 2) || ((upi42->irq_mask & 0x01) << 3) || ((upi42->t0 & 0x01) << 4) || ((upi42->t1 & 0x01) << 5) || ((upi42->flags & 0x01) << 6) || ((upi42->dbf & 0x01) << 7);
break;
/* 0 = Suspend. */

View File

@@ -29,11 +29,9 @@
#include <86box/usb.h>
#include "cpu.h"
#ifdef ENABLE_USB_LOG
int usb_do_log = ENABLE_USB_LOG;
static void
usb_log(const char *fmt, ...)
{
@@ -46,10 +44,9 @@ usb_log(const char *fmt, ...)
}
}
#else
#define usb_log(fmt, ...)
# define usb_log(fmt, ...)
#endif
static uint8_t
uhci_reg_read(uint16_t addr, void *p)
{
@@ -63,7 +60,6 @@ uhci_reg_read(uint16_t addr, void *p)
return ret;
}
static void
uhci_reg_write(uint16_t addr, uint8_t val, void *p)
{
@@ -82,7 +78,8 @@ uhci_reg_write(uint16_t addr, uint8_t val, void *p)
case 0x09:
regs[0x09] = (val & 0xf0);
break;
case 0x0a: case 0x0b:
case 0x0a:
case 0x0b:
regs[addr] = val;
break;
case 0x0c:
@@ -91,7 +88,6 @@ uhci_reg_write(uint16_t addr, uint8_t val, void *p)
}
}
static void
uhci_reg_writew(uint16_t addr, uint16_t val, void *p)
{
@@ -111,7 +107,8 @@ uhci_reg_writew(uint16_t addr, uint16_t val, void *p)
case 0x06:
regs[0x03] = (val & 0x07ff);
break;
case 0x10: case 0x12:
case 0x10:
case 0x12:
regs[addr >> 1] = ((regs[addr >> 1] & 0xedbb) | (val & 0x1244)) & ~(val & 0x080a);
break;
default:
@@ -121,7 +118,6 @@ uhci_reg_writew(uint16_t addr, uint16_t val, void *p)
}
}
void
uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable)
{
@@ -135,7 +131,6 @@ uhci_update_io_mapping(usb_t *dev, uint8_t base_l, uint8_t base_h, int enable)
io_sethandler(dev->uhci_io_base, 0x20, uhci_reg_read, NULL, NULL, uhci_reg_write, uhci_reg_writew, NULL, dev);
}
static uint8_t
ohci_mmio_read(uint32_t addr, void *p)
{
@@ -152,7 +147,6 @@ ohci_mmio_read(uint32_t addr, void *p)
return ret;
}
static void
ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
{
@@ -188,7 +182,8 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
case 0x0c:
dev->ohci_mmio[addr] &= ~(val & 0x7f);
return;
case 0x0d: case 0x0e:
case 0x0d:
case 0x0e:
return;
case 0x0f:
dev->ohci_mmio[addr] &= ~(val & 0x40);
@@ -196,15 +191,22 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
case 0x3b:
dev->ohci_mmio[addr] = (val & 0x80);
return;
case 0x39: case 0x41:
case 0x39:
case 0x41:
dev->ohci_mmio[addr] = (val & 0x3f);
return;
case 0x45:
dev->ohci_mmio[addr] = (val & 0x0f);
return;
case 0x3a:
case 0x3e: case 0x3f: case 0x42: case 0x43:
case 0x46: case 0x47: case 0x48: case 0x4a:
case 0x3e:
case 0x3f:
case 0x42:
case 0x43:
case 0x46:
case 0x47:
case 0x48:
case 0x4a:
return;
case 0x49:
dev->ohci_mmio[addr] = (val & 0x1b);
@@ -216,19 +218,22 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
case 0x4b:
dev->ohci_mmio[addr] = (val & 0x03);
return;
case 0x4c: case 0x4e:
case 0x4c:
case 0x4e:
dev->ohci_mmio[addr] = (val & 0x06);
if ((addr == 0x4c) && !(val & 0x04)) {
if (!(dev->ohci_mmio[0x58] & 0x01))
dev->ohci_mmio[0x5a] |= 0x01;
dev->ohci_mmio[0x58] |= 0x01;
} if ((addr == 0x4c) && !(val & 0x02)) {
}
if ((addr == 0x4c) && !(val & 0x02)) {
if (!(dev->ohci_mmio[0x54] & 0x01))
dev->ohci_mmio[0x56] |= 0x01;
dev->ohci_mmio[0x54] |= 0x01;
}
return;
case 0x4d: case 0x4f:
case 0x4d:
case 0x4f:
return;
case 0x50:
if (val & 0x01) {
@@ -275,7 +280,8 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
if (val & 0x80)
dev->ohci_mmio[0x51] &= ~0x80;
return;
case 0x54: case 0x58:
case 0x54:
case 0x58:
old = dev->ohci_mmio[addr];
if (val & 0x10) {
@@ -314,7 +320,8 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
dev->ohci_mmio[addr] &= ~0x01;
dev->ohci_mmio[0x54] &= ~0x17;
dev->ohci_mmio[0x56] &= ~0x17;
} if ((val & 0x01) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x02)) {
}
if ((val & 0x01) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x02)) {
dev->ohci_mmio[addr] |= 0x01;
dev->ohci_mmio[0x58] &= ~0x17;
dev->ohci_mmio[0x5a] &= ~0x17;
@@ -326,17 +333,18 @@ ohci_mmio_write(uint32_t addr, uint8_t val, void *p)
if ((val & 0x01) && ((dev->ohci_mmio[0x49] & 0x03) == 0x00) && (dev->ohci_mmio[0x4e] & 0x04))
dev->ohci_mmio[addr] |= 0x01;
return;
case 0x56: case 0x5a:
case 0x56:
case 0x5a:
dev->ohci_mmio[addr] &= ~(val & 0x1f);
return;
case 0x57: case 0x5b:
case 0x57:
case 0x5b:
return;
}
dev->ohci_mmio[addr] = val;
}
void
ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3, int enable)
{
@@ -350,7 +358,6 @@ ohci_update_mem_mapping(usb_t *dev, uint8_t base1, uint8_t base2, uint8_t base3,
mem_mapping_set_addr(&dev->ohci_mmio_mapping, dev->ohci_mem_base, 0x1000);
}
static void
usb_reset(void *priv)
{
@@ -372,7 +379,6 @@ usb_reset(void *priv)
dev->ohci_enable = 0;
}
static void
usb_close(void *priv)
{
@@ -381,14 +387,14 @@ usb_close(void *priv)
free(dev);
}
static void *
usb_init(const device_t *info)
{
usb_t *dev;
dev = (usb_t *)malloc(sizeof(usb_t));
if (dev == NULL) return(NULL);
dev = (usb_t *) malloc(sizeof(usb_t));
if (dev == NULL)
return (NULL);
memset(dev, 0x00, sizeof(usb_t));
memset(dev->uhci_io, 0x00, 128);

View File

@@ -32,13 +32,11 @@
#include <86box/ui.h>
#include <86box/vnc.h>
#define VNC_MIN_X 320
#define VNC_MAX_X 2048
#define VNC_MIN_Y 200
#define VNC_MAX_Y 2048
static rfbScreenInfoPtr rfb = NULL;
static int clients;
static int updatingSize;
@@ -46,11 +44,9 @@ static int allowedX,
allowedY;
static int ptr_x, ptr_y, ptr_but;
#ifdef ENABLE_VNC_LOG
int vnc_do_log = ENABLE_VNC_LOG;
static void
vnc_log(const char *fmt, ...)
{
@@ -63,29 +59,28 @@ vnc_log(const char *fmt, ...)
}
}
#else
#define vnc_log(fmt, ...)
# define vnc_log(fmt, ...)
#endif
static void
vnc_kbdevent(rfbBool down, rfbKeySym k, rfbClientPtr cl)
{
(void)cl;
(void) cl;
/* Handle it through the lookup tables. */
vnc_kbinput(down?1:0, (int)k);
vnc_kbinput(down ? 1 : 0, (int) k);
}
static void
vnc_ptrevent(int but, int x, int y, rfbClientPtr cl)
{
if (x>=0 && x<allowedX && y>=0 && y<allowedY) {
if (x >= 0 && x < allowedX && y >= 0 && y < allowedY) {
/* VNC uses absolute positions within the window, no deltas. */
if (x != ptr_x || y != ptr_y) {
mouse_x += (x - ptr_x) / 100;
mouse_y += (y - ptr_y) / 100;
ptr_x = x; ptr_y = y;
ptr_x = x;
ptr_y = y;
}
if (but != ptr_but) {
@@ -103,7 +98,6 @@ vnc_ptrevent(int but, int x, int y, rfbClientPtr cl)
rfbDefaultPtrAddEvent(but, x, y, cl);
}
static void
vnc_clientgone(rfbClientPtr cl)
{
@@ -122,7 +116,6 @@ vnc_clientgone(rfbClientPtr cl)
}
}
static enum rfbNewClientAction
vnc_newclient(rfbClientPtr cl)
{
@@ -132,8 +125,8 @@ vnc_newclient(rfbClientPtr cl)
vnc_log("VNC: new client: %s\n", cl->host);
if (++clients == 1) {
/* Reset the mouse. */
ptr_x = allowedX/2;
ptr_y = allowedY/2;
ptr_x = allowedX / 2;
ptr_y = allowedY / 2;
mouse_x = mouse_y = mouse_z = 0;
mouse_buttons = 0x00;
@@ -147,10 +140,9 @@ vnc_newclient(rfbClientPtr cl)
}
/* For now, we always accept clients. */
return(RFB_CLIENT_ACCEPT);
return (RFB_CLIENT_ACCEPT);
}
static void
vnc_display(rfbClientPtr cl)
{
@@ -165,7 +157,6 @@ vnc_display(rfbClientPtr cl)
}
}
static void
vnc_blit(int x, int y, int w, int h, int monitor_index)
{
@@ -177,11 +168,11 @@ vnc_blit(int x, int y, int w, int h, int monitor_index)
return;
}
for (yy=0; yy<h; yy++) {
p = (uint32_t *)&(((uint32_t *)rfb->frameBuffer)[yy*VNC_MAX_X]);
for (yy = 0; yy < h; yy++) {
p = (uint32_t *) &(((uint32_t *) rfb->frameBuffer)[yy * VNC_MAX_X]);
if ((y+yy) >= 0 && (y+yy) < VNC_MAX_Y)
video_copy(p, &(buffer32->line[yy]), w*sizeof(uint32_t));
if ((y + yy) >= 0 && (y + yy) < VNC_MAX_Y)
video_copy(p, &(buffer32->line[yy]), w * sizeof(uint32_t));
}
if (screenshots)
@@ -189,11 +180,10 @@ vnc_blit(int x, int y, int w, int h, int monitor_index)
video_blit_complete_monitor(monitor_index);
if (! updatingSize)
rfbMarkRectAsModified(rfb, 0,0, allowedX,allowedY);
if (!updatingSize)
rfbMarkRectAsModified(rfb, 0, 0, allowedX, allowedY);
}
/* Initialize VNC for operation. */
int
vnc_init(UNUSED(void *arg))
@@ -209,7 +199,7 @@ vnc_init(UNUSED(void *arg))
* red shift 16; green shift 8; blue shift 0;
* padding
*/
32, 32, 0, 1, 255,255,255, 16, 8, 0, 0, 0
32, 32, 0, 1, 255, 255, 255, 16, 8, 0, 0, 0
};
plat_pause(1);
@@ -223,7 +213,7 @@ vnc_init(UNUSED(void *arg))
rfb = rfbGetScreen(0, NULL, VNC_MAX_X, VNC_MAX_Y, 8, 3, 4);
rfb->desktopName = title;
rfb->frameBuffer = (char *)malloc(VNC_MAX_X*VNC_MAX_Y*4);
rfb->frameBuffer = (char *) malloc(VNC_MAX_X * VNC_MAX_Y * 4);
rfb->serverFormat = rpf;
rfb->alwaysShared = TRUE;
@@ -248,10 +238,9 @@ vnc_init(UNUSED(void *arg))
vnc_log("VNC: init complete.\n");
return(1);
return (1);
}
void
vnc_close(void)
{
@@ -266,14 +255,14 @@ vnc_close(void)
}
}
void
vnc_resize(int x, int y)
{
rfbClientIteratorPtr iterator;
rfbClientPtr cl;
if (rfb == NULL) return;
if (rfb == NULL)
return;
/* TightVNC doesn't like certain sizes.. */
if (x < VNC_MIN_X || x > VNC_MAX_X || y < VNC_MIN_Y || y > VNC_MAX_Y) {
@@ -299,15 +288,13 @@ vnc_resize(int x, int y)
}
}
/* Tell them to pause if we have no clients. */
int
vnc_pause(void)
{
return((clients > 0) ? 0 : 1);
return ((clients > 0) ? 0 : 1);
}
void
vnc_take_screenshot(wchar_t *fn)
{

View File

@@ -41,7 +41,6 @@
#include <86box/plat.h>
#include <86box/vnc.h>
static int keysyms_00[] = {
0x0000, /* 0x00 */
0x0000,
@@ -622,12 +621,10 @@ static int keysyms_ff[] = {
0xe053 /* 0xff (XK_Delete) */
};
#ifdef ENABLE_VNC_KEYMAP_LOG
int vnc_keymap_do_log = ENABLE_VNC_KEYMAP_LOG;
#endif
static void
vnc_keymap_log(const char *format, ...)
{
@@ -642,13 +639,12 @@ vnc_keymap_log(const char *format, ...)
#endif
}
void
vnc_kbinput(int down, int k)
{
uint16_t scan;
switch(k >> 8) {
switch (k >> 8) {
case 0x00: /* page 00, Latin-1 */
scan = keysyms_00[k & 0xff];
break;
@@ -658,7 +654,7 @@ vnc_kbinput(int down, int k)
break;
default:
vnc_keymap_log("VNC: unhandled Xkbd page: %02x\n", k>>8);
vnc_keymap_log("VNC: unhandled Xkbd page: %02x\n", k >> 8);
return;
}