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

View File

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

View File

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

View File

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

View File

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

194
src/dma.c
View File

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

View File

@@ -121,7 +121,7 @@ typedef struct _gdbstub_client_ {
struct sockaddr_in addr; struct sockaddr_in addr;
char packet[16384], response[16384]; 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; packet_pos, response_pos;
event_t *processed_event, *response_event; event_t *processed_event, *response_event;

View File

@@ -30,10 +30,8 @@
#include "cpu.h" #include "cpu.h"
#include <86box/m_amstrad.h> #include <86box/m_amstrad.h>
#define NPORTS 65536 /* PC/AT supports 64K ports */ #define NPORTS 65536 /* PC/AT supports 64K ports */
typedef struct _io_ { typedef struct _io_ {
uint8_t (*inb)(uint16_t addr, void *priv); uint8_t (*inb)(uint16_t addr, void *priv);
uint16_t (*inw)(uint16_t addr, void *priv); uint16_t (*inw)(uint16_t addr, void *priv);
@@ -58,11 +56,9 @@ typedef struct {
int initialized = 0; int initialized = 0;
io_t *io[NPORTS], *io_last[NPORTS]; io_t *io[NPORTS], *io_last[NPORTS];
#ifdef ENABLE_IO_LOG #ifdef ENABLE_IO_LOG
int io_do_log = ENABLE_IO_LOG; int io_do_log = ENABLE_IO_LOG;
static void static void
io_log(const char *fmt, ...) io_log(const char *fmt, ...)
{ {
@@ -75,10 +71,9 @@ io_log(const char *fmt, ...)
} }
} }
#else #else
#define io_log(fmt, ...) # define io_log(fmt, ...)
#endif #endif
void void
io_init(void) io_init(void)
{ {
@@ -86,12 +81,12 @@ io_init(void)
io_t *p, *q; io_t *p, *q;
if (!initialized) { if (!initialized) {
for (c=0; c<NPORTS; c++) for (c = 0; c < NPORTS; c++)
io[c] = io_last[c] = NULL; io[c] = io_last[c] = NULL;
initialized = 1; initialized = 1;
} }
for (c=0; c<NPORTS; c++) { for (c = 0; c < NPORTS; c++) {
if (io_last[c]) { if (io_last[c]) {
/* Port c has at least one handler. */ /* Port c has at least one handler. */
p = io_last[c]; p = io_last[c];
@@ -109,7 +104,6 @@ io_init(void)
} }
} }
void void
io_sethandler_common(uint16_t base, int size, io_sethandler_common(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), uint8_t (*inb)(uint16_t addr, void *priv),
@@ -150,7 +144,6 @@ io_sethandler_common(uint16_t base, int size,
} }
} }
void void
io_removehandler_common(uint16_t base, int size, io_removehandler_common(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), uint8_t (*inb)(uint16_t addr, void *priv),
@@ -168,12 +161,9 @@ io_removehandler_common(uint16_t base, int size,
p = io[base + c]; p = io[base + c];
if (!p) if (!p)
continue; continue;
while(p) { while (p) {
q = p->next; q = p->next;
if ((p->inb == inb) && (p->inw == inw) && if ((p->inb == inb) && (p->inw == inw) && (p->inl == inl) && (p->outb == outb) && (p->outw == outw) && (p->outl == outl) && (p->priv == priv)) {
(p->inl == inl) && (p->outb == outb) &&
(p->outw == outw) && (p->outl == outl) &&
(p->priv == priv)) {
if (p->prev) if (p->prev)
p->prev->next = p->next; p->prev->next = p->next;
else else
@@ -191,7 +181,6 @@ io_removehandler_common(uint16_t base, int size,
} }
} }
void void
io_handler_common(int set, uint16_t base, int size, io_handler_common(int set, uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_removehandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, step);
} }
void void
io_sethandler(uint16_t base, int size, io_sethandler(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_sethandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 1);
} }
void void
io_removehandler(uint16_t base, int size, io_removehandler(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_removehandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 1);
} }
void void
io_handler(int set, uint16_t base, int size, io_handler(int set, uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_handler_common(set, base, size, inb, inw, inl, outb, outw, outl, priv, 1);
} }
void void
io_sethandler_interleaved(uint16_t base, int size, io_sethandler_interleaved(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_sethandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 2);
} }
void void
io_removehandler_interleaved(uint16_t base, int size, io_removehandler_interleaved(uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_removehandler_common(base, size, inb, inw, inl, outb, outw, outl, priv, 2);
} }
void void
io_handler_interleaved(int set, uint16_t base, int size, io_handler_interleaved(int set, uint16_t base, int size,
uint8_t (*inb)(uint16_t addr, void *priv), 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); io_handler_common(set, base, size, inb, inw, inl, outb, outw, outl, priv, 2);
} }
uint8_t uint8_t
inb(uint16_t port) inb(uint16_t port)
{ {
@@ -302,7 +284,7 @@ inb(uint16_t port)
int qfound = 0; int qfound = 0;
p = io[port]; p = io[port];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->inb) { if (p->inb) {
ret &= p->inb(port, p->priv); 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); 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 void
outb(uint16_t port, uint8_t val) outb(uint16_t port, uint8_t val)
{ {
@@ -342,7 +323,7 @@ outb(uint16_t port, uint8_t val)
int qfound = 0; int qfound = 0;
p = io[port]; p = io[port];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->outb) { if (p->outb) {
p->outb(port, val, p->priv); p->outb(port, val, p->priv);
@@ -365,7 +346,6 @@ outb(uint16_t port, uint8_t val)
return; return;
} }
uint16_t uint16_t
inw(uint16_t port) inw(uint16_t port)
{ {
@@ -377,7 +357,7 @@ inw(uint16_t port)
int i = 0; int i = 0;
p = io[port]; p = io[port];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->inw) { if (p->inw) {
ret &= p->inw(port, p->priv); ret &= p->inw(port, p->priv);
@@ -391,7 +371,7 @@ inw(uint16_t port)
ret8[1] = (ret >> 8) & 0xff; ret8[1] = (ret >> 8) & 0xff;
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
p = io[(port + i) & 0xffff]; p = io[(port + i) & 0xffff];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->inb && !p->inw) { if (p->inb && !p->inw) {
ret8[i] &= p->inb(port + i, p->priv); ret8[i] &= p->inb(port + i, p->priv);
@@ -420,7 +400,6 @@ inw(uint16_t port)
return ret; return ret;
} }
void void
outw(uint16_t port, uint16_t val) outw(uint16_t port, uint16_t val)
{ {
@@ -430,7 +409,7 @@ outw(uint16_t port, uint16_t val)
int i = 0; int i = 0;
p = io[port]; p = io[port];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->outw) { if (p->outw) {
p->outw(port, val, p->priv); p->outw(port, val, p->priv);
@@ -442,7 +421,7 @@ outw(uint16_t port, uint16_t val)
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {
p = io[(port + i) & 0xffff]; p = io[(port + i) & 0xffff];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->outb && !p->outw) { if (p->outb && !p->outw) {
p->outb(port + i, val >> (i << 3), p->priv); p->outb(port + i, val >> (i << 3), p->priv);
@@ -466,7 +445,6 @@ outw(uint16_t port, uint16_t val)
return; return;
} }
uint32_t uint32_t
inl(uint16_t port) inl(uint16_t port)
{ {
@@ -479,7 +457,7 @@ inl(uint16_t port)
int i = 0; int i = 0;
p = io[port]; p = io[port];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->inl) { if (p->inl) {
ret &= p->inl(port, p->priv); ret &= p->inl(port, p->priv);
@@ -520,7 +498,7 @@ inl(uint16_t port)
ret8[3] = (ret >> 24) & 0xff; ret8[3] = (ret >> 24) & 0xff;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
p = io[(port + i) & 0xffff]; p = io[(port + i) & 0xffff];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->inb && !p->inw && !p->inl) { if (p->inb && !p->inw && !p->inl) {
ret8[i] &= p->inb(port + i, p->priv); ret8[i] &= p->inb(port + i, p->priv);
@@ -549,7 +527,6 @@ inl(uint16_t port)
return ret; return ret;
} }
void void
outl(uint16_t port, uint32_t val) outl(uint16_t port, uint32_t val)
{ {
@@ -560,7 +537,7 @@ outl(uint16_t port, uint32_t val)
p = io[port]; p = io[port];
if (p) { if (p) {
while(p) { while (p) {
q = p->next; q = p->next;
if (p->outl) { if (p->outl) {
p->outl(port, val, p->priv); p->outl(port, val, p->priv);
@@ -573,7 +550,7 @@ outl(uint16_t port, uint32_t val)
for (i = 0; i < 4; i += 2) { for (i = 0; i < 4; i += 2) {
p = io[(port + i) & 0xffff]; p = io[(port + i) & 0xffff];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->outw && !p->outl) { if (p->outw && !p->outl) {
p->outw(port + i, val >> (i << 3), p->priv); 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++) { for (i = 0; i < 4; i++) {
p = io[(port + i) & 0xffff]; p = io[(port + i) & 0xffff];
while(p) { while (p) {
q = p->next; q = p->next;
if (p->outb && !p->outw && !p->outl) { if (p->outb && !p->outw && !p->outl) {
p->outb(port + i, val >> (i << 3), p->priv); p->outb(port + i, val >> (i << 3), p->priv);
@@ -610,7 +587,6 @@ outl(uint16_t port, uint32_t val)
return; return;
} }
static uint8_t static uint8_t
io_trap_readb(uint16_t addr, void *priv) io_trap_readb(uint16_t addr, void *priv)
{ {
@@ -619,7 +595,6 @@ io_trap_readb(uint16_t addr, void *priv)
return 0xff; return 0xff;
} }
static uint16_t static uint16_t
io_trap_readw(uint16_t addr, void *priv) io_trap_readw(uint16_t addr, void *priv)
{ {
@@ -628,7 +603,6 @@ io_trap_readw(uint16_t addr, void *priv)
return 0xffff; return 0xffff;
} }
static uint32_t static uint32_t
io_trap_readl(uint16_t addr, void *priv) io_trap_readl(uint16_t addr, void *priv)
{ {
@@ -637,7 +611,6 @@ io_trap_readl(uint16_t addr, void *priv)
return 0xffffffff; return 0xffffffff;
} }
static void static void
io_trap_writeb(uint16_t addr, uint8_t val, void *priv) 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); trap->func(1, addr, 1, val, trap->priv);
} }
static void static void
io_trap_writew(uint16_t addr, uint16_t val, void *priv) 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); trap->func(2, addr, 1, val, trap->priv);
} }
static void static void
io_trap_writel(uint16_t addr, uint32_t val, void *priv) 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); trap->func(4, addr, 1, val, trap->priv);
} }
void * void *
io_trap_add(void (*func)(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv), io_trap_add(void (*func)(int size, uint16_t addr, uint8_t write, uint8_t val, void *priv),
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; return trap;
} }
void void
io_trap_remap(void *handle, int enable, uint16_t addr, uint16_t size) 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 void
io_trap_remove(void *handle) io_trap_remove(void *handle)
{ {

View File

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

View File

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

View File

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

View File

@@ -5,7 +5,6 @@
#include <86box/io.h> #include <86box/io.h>
#include <86box/mca.h> #include <86box/mca.h>
void (*mca_card_write[8])(int addr, uint8_t val, void *priv); 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_read[8])(int addr, void *priv);
uint8_t (*mca_card_feedb[8])(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_index;
static int mca_nr_cards; static int mca_nr_cards;
void
void mca_init(int nr_cards) mca_init(int nr_cards)
{ {
int c; int c;
@@ -31,12 +30,14 @@ void mca_init(int nr_cards)
mca_nr_cards = nr_cards; mca_nr_cards = nr_cards;
} }
void mca_set_index(int index) void
mca_set_index(int index)
{ {
mca_index = index; mca_index = index;
} }
uint8_t mca_read(uint16_t port) uint8_t
mca_read(uint16_t port)
{ {
if (mca_index >= mca_nr_cards) if (mca_index >= mca_nr_cards)
return 0xff; return 0xff;
@@ -45,7 +46,8 @@ uint8_t mca_read(uint16_t port)
return mca_card_read[mca_index](port, mca_priv[mca_index]); 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) if (mca_index >= mca_nr_cards)
return 0xff; 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]); 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; 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) if (mca_index >= mca_nr_cards)
return; 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]); 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]) if (mca_card_feedb[mca_index])
return !!(mca_card_feedb[mca_index](mca_priv[mca_index])); return !!(mca_card_feedb[mca_index](mca_priv[mca_index]));
@@ -75,7 +80,8 @@ uint8_t mca_feedb(void)
return 0; return 0;
} }
void mca_reset(void) void
mca_reset(void)
{ {
int c; int c;
@@ -85,8 +91,8 @@ void mca_reset(void)
} }
} }
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) 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; int c;

View File

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

View File

@@ -62,19 +62,15 @@
#include <86box/plat.h> #include <86box/plat.h>
#include <86box/nvr.h> #include <86box/nvr.h>
int nvr_dosave; /* NVR is dirty, needs saved */ 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 struct tm intclk;
static nvr_t *saved_nvr = NULL; static nvr_t *saved_nvr = NULL;
#ifdef ENABLE_NVR_LOG #ifdef ENABLE_NVR_LOG
int nvr_do_log = ENABLE_NVR_LOG; int nvr_do_log = ENABLE_NVR_LOG;
static void static void
nvr_log(const char *fmt, ...) nvr_log(const char *fmt, ...)
{ {
@@ -87,33 +83,33 @@ nvr_log(const char *fmt, ...)
} }
} }
#else #else
#define nvr_log(fmt, ...) # define nvr_log(fmt, ...)
#endif #endif
/* Determine whether or not the year is leap. */ /* Determine whether or not the year is leap. */
int int
nvr_is_leap(int year) nvr_is_leap(int year)
{ {
if (year % 400 == 0) return(1); if (year % 400 == 0)
if (year % 100 == 0) return(0); return (1);
if (year % 4 == 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. */ /* Determine the days in the current month. */
int int
nvr_get_days(int month, int year) nvr_get_days(int month, int year)
{ {
if (month != 2) 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. */ /* One more second has passed, update the internal clock. */
void void
rtc_tick(void) rtc_tick(void)
@@ -125,8 +121,7 @@ rtc_tick(void)
intclk.tm_min = 0; intclk.tm_min = 0;
if (++intclk.tm_hour == 24) { if (++intclk.tm_hour == 24) {
intclk.tm_hour = 0; intclk.tm_hour = 0;
if (++intclk.tm_mday == (nvr_get_days(intclk.tm_mon, if (++intclk.tm_mday == (nvr_get_days(intclk.tm_mon, intclk.tm_year) + 1)) {
intclk.tm_year) + 1)) {
intclk.tm_mday = 1; intclk.tm_mday = 1;
if (++intclk.tm_mon == 13) { if (++intclk.tm_mon == 13) {
intclk.tm_mon = 1; intclk.tm_mon = 1;
@@ -138,12 +133,11 @@ rtc_tick(void)
} }
} }
/* This is the RTC one-second timer. */ /* This is the RTC one-second timer. */
static void static void
onesec_timer(void *priv) onesec_timer(void *priv)
{ {
nvr_t *nvr = (nvr_t *)priv; nvr_t *nvr = (nvr_t *) priv;
int is_at; int is_at;
if (++nvr->onesec_cnt >= 100) { if (++nvr->onesec_cnt >= 100) {
@@ -159,10 +153,9 @@ onesec_timer(void *priv)
nvr->onesec_cnt = 0; 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. */ /* Initialize the generic NVRAM/RTC device. */
void void
nvr_init(nvr_t *nvr) nvr_init(nvr_t *nvr)
@@ -171,7 +164,7 @@ nvr_init(nvr_t *nvr)
/* Set up the NVR file's name. */ /* Set up the NVR file's name. */
c = strlen(machine_get_internal_name()) + 5; 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()); sprintf(nvr->fn, "%s.nvr", machine_get_internal_name());
/* Initialize the internal clock as needed. */ /* Initialize the internal clock as needed. */
@@ -194,10 +187,9 @@ nvr_init(nvr_t *nvr)
saved_nvr = nvr; saved_nvr = nvr;
/* Try to load the saved data. */ /* Try to load the saved data. */
(void)nvr_load(); (void) nvr_load();
} }
/* Get path to the NVR folder. */ /* Get path to the NVR folder. */
char * char *
nvr_path(char *str) nvr_path(char *str)
@@ -210,17 +202,16 @@ nvr_path(char *str)
strcat(temp, NVR_PATH); strcat(temp, NVR_PATH);
/* Create the directory if needed. */ /* Create the directory if needed. */
if (! plat_dir_check(temp)) if (!plat_dir_check(temp))
plat_dir_create(temp); plat_dir_create(temp);
/* Now append the actual filename. */ /* Now append the actual filename. */
path_slash(temp); path_slash(temp);
strcat(temp, str); strcat(temp, str);
return(temp); return (temp);
} }
/* /*
* Load an NVR from file. * Load an NVR from file.
* *
@@ -240,7 +231,8 @@ nvr_load(void)
uint8_t regs[NVR_MAXSIZE] = { 0 }; uint8_t regs[NVR_MAXSIZE] = { 0 };
/* Make sure we have been initialized. */ /* Make sure we have been initialized. */
if (saved_nvr == NULL) return(0); if (saved_nvr == NULL)
return (0);
/* Clear out any old data. */ /* Clear out any old data. */
memset(saved_nvr->regs, 0x00, sizeof(saved_nvr->regs)); memset(saved_nvr->regs, 0x00, sizeof(saved_nvr->regs));
@@ -262,7 +254,7 @@ nvr_load(void)
memcpy(saved_nvr->regs, regs, sizeof(regs)); memcpy(saved_nvr->regs, regs, sizeof(regs));
saved_nvr->is_new = 1; saved_nvr->is_new = 1;
} }
(void)fclose(fp); (void) fclose(fp);
} }
} else } else
saved_nvr->is_new = 1; saved_nvr->is_new = 1;
@@ -271,17 +263,15 @@ nvr_load(void)
if (saved_nvr->start != NULL) if (saved_nvr->start != NULL)
saved_nvr->start(saved_nvr); saved_nvr->start(saved_nvr);
return(1); return (1);
} }
void void
nvr_set_ven_save(void (*ven_save)(void)) nvr_set_ven_save(void (*ven_save)(void))
{ {
saved_nvr->ven_save = ven_save; saved_nvr->ven_save = ven_save;
} }
/* Save the current NVR to a file. */ /* Save the current NVR to a file. */
int int
nvr_save(void) nvr_save(void)
@@ -290,7 +280,8 @@ nvr_save(void)
FILE *fp; FILE *fp;
/* Make sure we have been initialized. */ /* Make sure we have been initialized. */
if (saved_nvr == NULL) return(0); if (saved_nvr == NULL)
return (0);
if (saved_nvr->size != 0) { if (saved_nvr->size != 0) {
path = nvr_path(saved_nvr->fn); path = nvr_path(saved_nvr->fn);
@@ -298,7 +289,7 @@ nvr_save(void)
fp = plat_fopen(path, "wb"); fp = plat_fopen(path, "wb");
if (fp != NULL) { if (fp != NULL) {
/* Save NVR contents to file. */ /* 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); fclose(fp);
} }
} }
@@ -309,17 +300,15 @@ nvr_save(void)
/* Device is clean again. */ /* Device is clean again. */
nvr_dosave = 0; nvr_dosave = 0;
return(1); return (1);
} }
void void
nvr_close(void) nvr_close(void)
{ {
saved_nvr = NULL; saved_nvr = NULL;
} }
void void
nvr_time_sync(void) nvr_time_sync(void)
{ {
@@ -327,8 +316,8 @@ nvr_time_sync(void)
time_t now; time_t now;
/* Get the current time of day, and convert to local time. */ /* Get the current time of day, and convert to local time. */
(void)time(&now); (void) time(&now);
if(time_sync & TIME_SYNC_UTC) if (time_sync & TIME_SYNC_UTC)
tm = gmtime(&now); tm = gmtime(&now);
else else
tm = localtime(&now); tm = localtime(&now);
@@ -337,7 +326,6 @@ nvr_time_sync(void)
nvr_time_set(tm); nvr_time_set(tm);
} }
/* Get current time from internal clock. */ /* Get current time from internal clock. */
void void
nvr_time_get(struct tm *tm) nvr_time_get(struct tm *tm)
@@ -352,7 +340,7 @@ nvr_time_get(struct tm *tm)
mon = intclk.tm_mon; mon = intclk.tm_mon;
yr = (intclk.tm_year % 100); yr = (intclk.tm_year % 100);
cent = ((intclk.tm_year - yr) / 100) % 4; cent = ((intclk.tm_year - yr) / 100) % 4;
sum = dom+mon+yr+cent; sum = dom + mon + yr + cent;
wd = ((sum + 6) % 7); wd = ((sum + 6) % 7);
tm->tm_wday = wd; tm->tm_wday = wd;
tm->tm_mday = intclk.tm_mday; tm->tm_mday = intclk.tm_mday;
@@ -360,7 +348,6 @@ nvr_time_get(struct tm *tm)
tm->tm_year = (intclk.tm_year - 1900); tm->tm_year = (intclk.tm_year - 1900);
} }
/* Set internal clock time. */ /* Set internal clock time. */
void void
nvr_time_set(struct tm *tm) nvr_time_set(struct tm *tm)
@@ -374,10 +361,9 @@ nvr_time_set(struct tm *tm)
intclk.tm_year = (tm->tm_year + 1900); intclk.tm_year = (tm->tm_year + 1900);
} }
/* Open or create a file in the NVR area. */ /* Open or create a file in the NVR area. */
FILE * FILE *
nvr_fopen(char *str, char *mode) 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/device.h>
#include <86box/nvr.h> #include <86box/nvr.h>
/* RTC registers and bit definitions. */ /* RTC registers and bit definitions. */
#define RTC_SECONDS 0 #define RTC_SECONDS 0
#define RTC_ALSECONDS 1 #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_MINUTES 2
#define RTC_ALMINUTES 3 #define RTC_ALMINUTES 3
#define RTC_HOURS 4 #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_ALHOURS 5
#define RTC_DOW 6 #define RTC_DOW 6
#define RTC_DOM 7 #define RTC_DOM 7
#define RTC_MONTH 8 #define RTC_MONTH 8
#define RTC_YEAR 9 #define RTC_YEAR 9
#define RTC_REGA 10 #define RTC_REGA 10
# define REGA_UIP 0x80 #define REGA_UIP 0x80
# define REGA_DV2 0x40 #define REGA_DV2 0x40
# define REGA_DV1 0x20 #define REGA_DV1 0x20
# define REGA_DV0 0x10 #define REGA_DV0 0x10
# define REGA_DV 0x70 #define REGA_DV 0x70
# define REGA_RS3 0x08 #define REGA_RS3 0x08
# define REGA_RS2 0x04 #define REGA_RS2 0x04
# define REGA_RS1 0x02 #define REGA_RS1 0x02
# define REGA_RS0 0x01 #define REGA_RS0 0x01
# define REGA_RS 0x0f #define REGA_RS 0x0f
#define RTC_REGB 11 #define RTC_REGB 11
# define REGB_SET 0x80 #define REGB_SET 0x80
# define REGB_PIE 0x40 #define REGB_PIE 0x40
# define REGB_AIE 0x20 #define REGB_AIE 0x20
# define REGB_UIE 0x10 #define REGB_UIE 0x10
# define REGB_SQWE 0x08 #define REGB_SQWE 0x08
# define REGB_DM 0x04 #define REGB_DM 0x04
# define REGB_2412 0x02 #define REGB_2412 0x02
# define REGB_DSE 0x01 #define REGB_DSE 0x01
#define RTC_REGC 12 #define RTC_REGC 12
# define REGC_IRQF 0x80 #define REGC_IRQF 0x80
# define REGC_PF 0x40 #define REGC_PF 0x40
# define REGC_AF 0x20 #define REGC_AF 0x20
# define REGC_UF 0x10 #define REGC_UF 0x10
#define RTC_REGD 13 #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_AT 0x32 /* century register for AT etc */
#define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */ #define RTC_CENTURY_PS 0x37 /* century register for PS/1 PS/2 */
#define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */ #define RTC_ALDAY 0x7D /* VIA VT82C586B - alarm day */
@@ -297,7 +296,6 @@
#define FLAG_P6RP4_HACK 0x10 #define FLAG_P6RP4_HACK 0x10
#define FLAG_PIIX4 0x20 #define FLAG_PIIX4 0x20
typedef struct { typedef struct {
int8_t stat; int8_t stat;
@@ -317,15 +315,13 @@ typedef struct {
rtc_timer; rtc_timer;
} local_t; } local_t;
static uint8_t nvr_at_inited = 0; static uint8_t nvr_at_inited = 0;
/* Get the current NVR time. */ /* Get the current NVR time. */
static void static void
time_get(nvr_t *nvr, struct tm *tm) 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; int8_t temp;
if (nvr->regs[RTC_REGB] & REGB_DM) { 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) if (nvr->regs[RTC_REGB] & REGB_2412)
tm->tm_hour = temp; tm->tm_hour = temp;
else 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. */ /* Set the current NVR time. */
static void static void
time_set(nvr_t *nvr, struct tm *tm) 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); int year = (tm->tm_year + 1900);
if (nvr->regs[RTC_REGB] & REGB_DM) { 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. */ /* Check if the current time matches a set alarm time. */
static int8_t static int8_t
check_alarm(nvr_t *nvr, int8_t addr) check_alarm(nvr_t *nvr, int8_t addr)
{ {
return((nvr->regs[addr+1] == nvr->regs[addr]) || return ((nvr->regs[addr + 1] == nvr->regs[addr]) || ((nvr->regs[addr + 1] & AL_DONTCARE) == AL_DONTCARE));
((nvr->regs[addr+1] & AL_DONTCARE) == AL_DONTCARE));
} }
/* Check for VIA stuff. */ /* Check for VIA stuff. */
static int8_t static int8_t
check_alarm_via(nvr_t *nvr, int8_t addr, int8_t addr_2) 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) { if (local->cent == RTC_CENTURY_VIA) {
return((nvr->regs[addr_2] == nvr->regs[addr]) || return ((nvr->regs[addr_2] == nvr->regs[addr]) || ((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE));
((nvr->regs[addr_2] & AL_DONTCARE) == AL_DONTCARE));
} else } else
return 1; return 1;
} }
/* Update the NVR registers from the internal clock. */ /* Update the NVR registers from the internal clock. */
static void static void
timer_update(void *priv) timer_update(void *priv)
{ {
nvr_t *nvr = (nvr_t *)priv; nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *)nvr->data; local_t *local = (local_t *) nvr->data;
struct tm tm; struct tm tm;
local->ecount = 0LL; 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. */ /* Get the current time from the internal clock. */
nvr_time_get(&tm); nvr_time_get(&tm);
@@ -457,13 +447,10 @@ timer_update(void *priv)
local->stat = 0x00; local->stat = 0x00;
/* Check for any alarms we need to handle. */ /* Check for any alarms we need to handle. */
if (check_alarm(nvr, RTC_SECONDS) && 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(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_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; nvr->regs[RTC_REGC] |= REGC_AF;
if (nvr->regs[RTC_REGB] & REGB_AIE) { if (nvr->regs[RTC_REGB] & REGB_AIE) {
/* Generate an interrupt. */ /* Generate an interrupt. */
@@ -489,7 +476,6 @@ timer_update(void *priv)
} }
} }
static void static void
timer_load_count(nvr_t *nvr) timer_load_count(nvr_t *nvr)
{ {
@@ -509,7 +495,8 @@ timer_load_count(nvr_t *nvr)
case 0: case 0:
local->state = 0; local->state = 0;
break; break;
case 1: case 2: case 1:
case 2:
local->count = 1 << (c + 6); local->count = 1 << (c + 6);
timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST); timer_set_delay_u64(&local->rtc_timer, (local->count) * RTCCONST);
break; break;
@@ -520,12 +507,11 @@ timer_load_count(nvr_t *nvr)
} }
} }
static void static void
timer_intr(void *priv) timer_intr(void *priv)
{ {
nvr_t *nvr = (nvr_t *)priv; nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *)nvr->data; local_t *local = (local_t *) nvr->data;
if (local->state == 1) { if (local->state == 1) {
timer_load_count(nvr); timer_load_count(nvr);
@@ -541,15 +527,14 @@ timer_intr(void *priv)
} }
} }
/* Callback from internal clock, another second passed. */ /* Callback from internal clock, another second passed. */
static void static void
timer_tick(nvr_t *nvr) 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. */ /* 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. */ /* Set the UIP bit, announcing the update. */
local->stat = REGA_UIP; local->stat = REGA_UIP;
@@ -561,7 +546,6 @@ timer_tick(nvr_t *nvr)
} }
} }
static void static void
nvr_reg_common_write(uint16_t reg, uint8_t val, nvr_t *nvr, local_t *local) 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. */ /* This must be exposed because ACPI uses it. */
void void
nvr_reg_write(uint16_t reg, uint8_t val, void *priv) nvr_reg_write(uint16_t reg, uint8_t val, void *priv)
{ {
nvr_t *nvr = (nvr_t *)priv; nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *)nvr->data; local_t *local = (local_t *) nvr->data;
struct tm tm; struct tm tm;
uint8_t old; uint8_t old;
uint8_t irq = 0, old_irq = 0; uint8_t irq = 0, old_irq = 0;
old = nvr->regs[reg]; old = nvr->regs[reg];
switch(reg) { switch (reg) {
case RTC_REGA: case RTC_REGA:
nvr->regs[RTC_REGA] = val; nvr->regs[RTC_REGA] = val;
timer_load_count(nvr); timer_load_count(nvr);
@@ -604,7 +587,7 @@ nvr_reg_write(uint16_t reg, uint8_t val, void *priv)
case RTC_REGB: case RTC_REGB:
old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70; old_irq = (nvr->regs[RTC_REGB] & nvr->regs[RTC_REGC]) & 0x70;
nvr->regs[RTC_REGB] = val; 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... */ /* According to the datasheet... */
nvr->regs[RTC_REGA] &= ~REGA_UIP; nvr->regs[RTC_REGA] &= ~REGA_UIP;
nvr->regs[RTC_REGB] &= ~REGB_UIE; 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. */ /* Write to one of the NVR registers. */
static void static void
nvr_write(uint16_t addr, uint8_t val, void *priv) nvr_write(uint16_t addr, uint8_t val, void *priv)
{ {
nvr_t *nvr = (nvr_t *)priv; nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *)nvr->data; local_t *local = (local_t *) nvr->data;
uint8_t addr_id = (addr & 0x0e) >> 1; uint8_t addr_id = (addr & 0x0e) >> 1;
cycles -= ISA_CYCLES(8); 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. */ /* Read from one of the NVR registers. */
static uint8_t static uint8_t
nvr_read(uint16_t addr, void *priv) nvr_read(uint16_t addr, void *priv)
{ {
nvr_t *nvr = (nvr_t *)priv; nvr_t *nvr = (nvr_t *) priv;
local_t *local = (local_t *)nvr->data; local_t *local = (local_t *) nvr->data;
uint8_t ret; uint8_t ret;
uint8_t addr_id = (addr & 0x0e) >> 1; uint8_t addr_id = (addr & 0x0e) >> 1;
uint16_t i, checksum = 0x0000; uint16_t i, checksum = 0x0000;
@@ -698,7 +679,8 @@ nvr_read(uint16_t addr, void *priv)
if (local->bank[addr_id] == 0xff) if (local->bank[addr_id] == 0xff)
ret = 0xff; ret = 0xff;
else if (addr & 1) switch(local->addr[addr_id]) { else if (addr & 1)
switch (local->addr[addr_id]) {
case RTC_REGA: case RTC_REGA:
ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat; ret = (nvr->regs[RTC_REGA] & 0x7f) | local->stat;
break; break;
@@ -808,7 +790,8 @@ nvr_read(uint16_t addr, void *priv)
default: default:
ret = nvr->regs[local->addr[addr_id]]; ret = nvr->regs[local->addr[addr_id]];
break; break;
} else { }
else {
ret = local->addr[addr_id]; ret = local->addr[addr_id];
if (!local->read_addr) if (!local->read_addr)
ret &= 0x80; ret &= 0x80;
@@ -816,10 +799,9 @@ nvr_read(uint16_t addr, void *priv)
ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80); ret = (ret & 0x7f) | (nmi_mask ? 0x00 : 0x80);
} }
return(ret); return (ret);
} }
/* Secondary NVR write - used by SMC. */ /* Secondary NVR write - used by SMC. */
static void static void
nvr_sec_write(uint16_t addr, uint8_t val, void *priv) 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); nvr_write(0x72 + (addr & 1), val, priv);
} }
/* Secondary NVR read - used by SMC. */ /* Secondary NVR read - used by SMC. */
static uint8_t static uint8_t
nvr_sec_read(uint16_t addr, void *priv) 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); return nvr_read(0x72 + (addr & 1), priv);
} }
/* Reset the RTC state to 1980/01/01 00:00. */ /* Reset the RTC state to 1980/01/01 00:00. */
static void static void
nvr_reset(nvr_t *nvr) 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, RTC_REGS); */
memset(nvr->regs, local->def, nvr->size); memset(nvr->regs, local->def, nvr->size);
@@ -884,11 +864,10 @@ nvr_start(nvr_t *nvr)
} }
/* Start the RTC. */ /* 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; nvr->regs[RTC_REGB] = REGB_2412;
} }
static void static void
nvr_at_speed_changed(void *priv) 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)); timer_set_delay_u64(&nvr->onesec_time, (10000ULL * TIMER_USEC));
} }
void void
nvr_at_handler(int set, uint16_t base, nvr_t *nvr) nvr_at_handler(int set, uint16_t base, nvr_t *nvr)
{ {
io_handler(set, base, 2, io_handler(set, base, 2,
nvr_read,NULL,NULL, nvr_write,NULL,NULL, nvr); nvr_read, NULL, NULL, nvr_write, NULL, NULL, nvr);
} }
void void
nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr) nvr_at_sec_handler(int set, uint16_t base, nvr_t *nvr)
{ {
io_handler(set, base, 2, 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 void
@@ -929,7 +906,6 @@ nvr_read_addr_set(int set, nvr_t *nvr)
local->read_addr = set; local->read_addr = set;
} }
void void
nvr_wp_set(int set, int h, nvr_t *nvr) 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; local->wp[h] = set;
} }
void void
nvr_via_wp_set(int set, int reg, nvr_t *nvr) 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; local->wp_32 = set;
} }
void void
nvr_bank_set(int base, uint8_t bank, nvr_t *nvr) 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; local->bank[base] = bank;
} }
void void
nvr_lock_set(int base, int size, int lock, nvr_t *nvr) 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; local->lock[base + i] = lock;
} }
void void
nvr_irq_set(int irq, nvr_t *nvr) nvr_irq_set(int irq, nvr_t *nvr)
{ {
nvr->irq = irq; nvr->irq = irq;
} }
static void static void
nvr_at_reset(void *priv) 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); nvr->regs[RTC_REGC] &= ~(REGC_PF | REGC_AF | REGC_UF | REGC_IRQF);
} }
static void * static void *
nvr_at_init(const device_t *info) nvr_at_init(const device_t *info)
{ {
@@ -996,11 +966,12 @@ nvr_at_init(const device_t *info)
nvr_t *nvr; nvr_t *nvr;
/* Allocate an NVR for this machine. */ /* Allocate an NVR for this machine. */
nvr = (nvr_t *)malloc(sizeof(nvr_t)); nvr = (nvr_t *) malloc(sizeof(nvr_t));
if (nvr == NULL) return(NULL); if (nvr == NULL)
return (NULL);
memset(nvr, 0x00, sizeof(nvr_t)); 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)); memset(local, 0x00, sizeof(local_t));
nvr->data = local; nvr->data = local;
@@ -1010,7 +981,7 @@ nvr_at_init(const device_t *info)
memset(local->lock, 0x00, nvr->size); memset(local->lock, 0x00, nvr->size);
local->def = 0xff /*0x00*/; local->def = 0xff /*0x00*/;
local->flags = 0x00; local->flags = 0x00;
switch(info->local & 7) { switch (info->local & 7) {
case 0: /* standard AT, no century register */ case 0: /* standard AT, no century register */
if (info->local == 16) { if (info->local == 16) {
local->flags |= FLAG_P6RP4_HACK; 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. */ /* Set up the I/O handler for this device. */
io_sethandler(0x0070, 2, 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) { if (info->local & 8) {
io_sethandler(0x0072, 2, 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; nvr_at_inited = 1;
} }
return(nvr); return (nvr);
} }
static void static void
nvr_at_close(void *priv) nvr_at_close(void *priv)
{ {
@@ -1225,8 +1195,11 @@ const device_t ps_no_nmi_nvr_device = {
"ps1_nvr", "ps1_nvr",
DEVICE_PS2, DEVICE_PS2,
10, 10,
nvr_at_init, nvr_at_close, nvr_at_reset, nvr_at_init,
{ NULL }, nvr_at_speed_changed, nvr_at_close,
nvr_at_reset,
{ NULL },
nvr_at_speed_changed,
NULL NULL
}; };
@@ -1235,8 +1208,11 @@ const device_t amstrad_no_nmi_nvr_device = {
"amstrad_nvr", "amstrad_nvr",
DEVICE_ISA | DEVICE_AT, DEVICE_ISA | DEVICE_AT,
11, 11,
nvr_at_init, nvr_at_close, nvr_at_reset, nvr_at_init,
{ NULL }, nvr_at_speed_changed, nvr_at_close,
nvr_at_reset,
{ NULL },
nvr_at_speed_changed,
NULL NULL
}; };

View File

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

151
src/pci.c
View File

@@ -35,7 +35,6 @@
#include <86box/pci.h> #include <86box/pci.h>
#include <86box/keyboard.h> #include <86box/keyboard.h>
typedef struct { typedef struct {
uint8_t bus, id, type; uint8_t bus, id, type;
uint8_t irq_routing[4]; uint8_t irq_routing[4];
@@ -50,7 +49,6 @@ typedef struct {
uint8_t irq_line; uint8_t irq_line;
} pci_mirq_t; } pci_mirq_t;
int pci_burst_time, agp_burst_time, int pci_burst_time, agp_burst_time,
pci_nonburst_time, agp_nonburst_time; pci_nonburst_time, agp_nonburst_time;
@@ -70,14 +68,11 @@ static int pci_type,
pci_key; pci_key;
static int trc_reg = 0; static int trc_reg = 0;
static void pci_reset_regs(void); static void pci_reset_regs(void);
#ifdef ENABLE_PCI_LOG #ifdef ENABLE_PCI_LOG
int pci_do_log = ENABLE_PCI_LOG; int pci_do_log = ENABLE_PCI_LOG;
static void static void
pci_log(const char *fmt, ...) pci_log(const char *fmt, ...)
{ {
@@ -90,10 +85,9 @@ pci_log(const char *fmt, ...)
} }
} }
#else #else
#define pci_log(fmt, ...) # define pci_log(fmt, ...)
#endif #endif
static void static void
pci_clear_slot(int card) pci_clear_slot(int card)
{ {
@@ -112,7 +106,6 @@ pci_clear_slot(int card)
pci_cards[card].priv = NULL; pci_cards[card].priv = NULL;
} }
void void
pci_relocate_slot(int type, int new_slot) 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; pci_card_to_slot_mapping[0][new_slot] = mapping;
} }
static void static void
pci_cf8_write(uint16_t port, uint32_t val, void *priv) 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; pci_enable = (val >> 31) & 1;
} }
static uint32_t static uint32_t
pci_cf8_read(uint16_t port, void *priv) pci_cf8_read(uint16_t port, void *priv)
{ {
return pci_index | (pci_func << 8) | return pci_index | (pci_func << 8) | (pci_card << 11) | (pci_bus << 16) | (pci_enable << 31);
(pci_card << 11) | (pci_bus << 16) | (pci_enable << 31);
} }
static void static void
pci_write(uint16_t port, uint8_t val, void *priv) 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); pci_log("(%i) %03x write: %02X\n", pci_enable, port, val);
switch (port) { switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff: case 0xcfc:
if (! pci_enable) case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return; 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)); 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 static void
pci_writew(uint16_t port, uint16_t val, void *priv) 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); pci_log("(%i) %03x write: %02X\n", pci_enable, port, val);
switch (port) { switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff: case 0xcfc:
if (! pci_enable) case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return; 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)); 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 static void
pci_writel(uint16_t port, uint32_t val, void *priv) 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); pci_log("(%i) %03x write: %02X\n", pci_enable, port, val);
switch (port) { switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff: case 0xcfc:
if (! pci_enable) case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return; 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)); 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 static uint8_t
pci_read(uint16_t port, void *priv) 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); pci_log("(%i) %03x read\n", pci_enable, port);
switch (port) { switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff: case 0xcfc:
if (! pci_enable) case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return 0xff; return 0xff;
slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; 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; return ret;
} }
static uint16_t static uint16_t
pci_readw(uint16_t port, void *priv) 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); pci_log("(%i) %03x read\n", pci_enable, port);
switch (port) { switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff: case 0xcfc:
if (! pci_enable) case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return 0xff; return 0xff;
slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; 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; return ret;
} }
static uint32_t static uint32_t
pci_readl(uint16_t port, void *priv) 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); pci_log("(%i) %03x read\n", pci_enable, port);
switch (port) { switch (port) {
case 0xcfc: case 0xcfd: case 0xcfe: case 0xcff: case 0xcfc:
if (! pci_enable) case 0xcfd:
case 0xcfe:
case 0xcff:
if (!pci_enable)
return 0xff; return 0xff;
slot = pci_card_to_slot_mapping[pci_bus_number_to_index_mapping[pci_bus]][pci_card]; 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; return ret;
} }
static void pci_type2_write(uint16_t port, uint8_t val, void *priv); static void pci_type2_write(uint16_t port, uint8_t val, void *priv);
static uint8_t pci_type2_read(uint16_t port, void *priv); static uint8_t pci_type2_read(uint16_t port, void *priv);
void void
pci_set_pmc(uint8_t pmc) pci_set_pmc(uint8_t pmc)
{ {
@@ -392,28 +392,27 @@ pci_set_pmc(uint8_t pmc)
if (!pci_pmc && (pmc & 0x01)) { if (!pci_pmc && (pmc & 0x01)) {
io_removehandler(0x0cf8, 1, 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, 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, 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, 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)) { } else if (pci_pmc && !(pmc & 0x01)) {
io_removehandler(0x0cf8, 1, 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, 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, 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, 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); pci_pmc = (pmc & 0x01);
} }
static void static void
pci_type2_write(uint16_t port, uint8_t val, void *priv) 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 static void
pci_type2_writel(uint16_t port, uint32_t val, void *priv) 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 static uint8_t
pci_type2_read(uint16_t port, void *priv) pci_type2_read(uint16_t port, void *priv)
{ {
@@ -504,35 +501,30 @@ pci_type2_read(uint16_t port, void *priv)
return 0xff; return 0xff;
} }
void void
pci_set_irq_routing(int pci_int, int irq) pci_set_irq_routing(int pci_int, int irq)
{ {
pci_irqs[pci_int - 1] = irq; pci_irqs[pci_int - 1] = irq;
} }
void void
pci_set_irq_level(int pci_int, int level) pci_set_irq_level(int pci_int, int level)
{ {
pci_irq_level[pci_int - 1] = !!level; pci_irq_level[pci_int - 1] = !!level;
} }
void void
pci_enable_mirq(int mirq) pci_enable_mirq(int mirq)
{ {
pci_mirqs[mirq].enabled = 1; pci_mirqs[mirq].enabled = 1;
} }
void void
pci_set_mirq_routing(int mirq, int irq) pci_set_mirq_routing(int mirq, int irq)
{ {
pci_mirqs[mirq].irq_line = irq; pci_mirqs[mirq].irq_line = irq;
} }
void void
pci_set_mirq(uint8_t mirq, int level) 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_line = mirq & 0x0f;
irq_bit = 0x1D; irq_bit = 0x1D;
} else { } else {
if (! pci_mirqs[mirq].enabled) { if (!pci_mirqs[mirq].enabled) {
pci_log("pci_set_mirq(%02X): MIRQ0 disabled\n", mirq); pci_log("pci_set_mirq(%02X): MIRQ0 disabled\n", mirq);
return; 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); pci_log("pci_set_mirq(%02X): Edge-triggered interrupt, not marking\n", mirq);
} }
void void
pci_set_irq(uint8_t card, uint8_t pci_int) 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 irq_line = 0;
uint8_t level = 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); pci_log("pci_set_irq(%02X, %02X): No PCI slots (how are we even here?!)\n", card, pci_int);
return; 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); 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); pci_log("pci_set_irq(%02X, %02X): No IRQ routing for this slot and INT pin combination\n", card, pci_int);
return; return;
} }
@@ -662,7 +653,6 @@ pci_set_irq(uint8_t card, uint8_t pci_int)
} }
} }
void void
pci_clear_mirq(uint8_t mirq, int level) pci_clear_mirq(uint8_t mirq, int level)
{ {
@@ -678,7 +668,7 @@ pci_clear_mirq(uint8_t mirq, int level)
return; return;
} }
if (! pci_mirqs[mirq].enabled) { if (!pci_mirqs[mirq].enabled) {
pci_log("pci_clear_mirq(%02X): MIRQ0 disabled\n", mirq); pci_log("pci_clear_mirq(%02X): MIRQ0 disabled\n", mirq);
return; 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_log("pci_clear_mirq(%02X): Releasing this MIRQ's hold on the IRQ\n", mirq);
pci_irq_hold[irq_line] &= ~(1 << irq_bit); 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); pci_log("pci_clear_mirq(%02X): IRQ no longer held by any card, clearing it\n", mirq);
picintc(1 << irq_line); picintc(1 << irq_line);
} else { } else {
@@ -715,7 +705,6 @@ pci_clear_mirq(uint8_t mirq, int level)
} }
} }
void void
pci_clear_irq(uint8_t card, uint8_t pci_int) 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 irq_line = 0;
uint8_t level = 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); // pci_log("pci_clear_irq(%02X, %02X): No PCI slots (how are we even here?!)\n", card, pci_int);
return; 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); // 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); // pci_log("pci_clear_irq(%02X, %02X): No IRQ routing for this slot and INT pin combination\n", card, pci_int);
return; 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_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); 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); // pci_log("pci_clear_irq(%02X, %02X): IRQ no longer held by any card, clearing it\n", card, pci_int);
picintc(1 << irq_line); picintc(1 << irq_line);
} // else { } // else {
@@ -782,14 +771,12 @@ pci_clear_irq(uint8_t card, uint8_t pci_int)
} }
} }
uint8_t uint8_t
pci_get_int(uint8_t slot, uint8_t pci_int) pci_get_int(uint8_t slot, uint8_t pci_int)
{ {
return pci_cards[slot].irq_routing[pci_int - PCI_INTA]; return pci_cards[slot].irq_routing[pci_int - PCI_INTA];
} }
static void static void
pci_reset_regs(void) pci_reset_regs(void)
{ {
@@ -800,7 +787,6 @@ pci_reset_regs(void)
pci_type2_write, NULL, NULL, NULL); pci_type2_write, NULL, NULL, NULL);
} }
void void
pci_pic_reset(void) pci_pic_reset(void)
{ {
@@ -808,7 +794,6 @@ pci_pic_reset(void)
pic_set_pci_flag(last_pci_card > 0); pic_set_pci_flag(last_pci_card > 0);
} }
static void static void
pci_reset_hard(void) pci_reset_hard(void)
{ {
@@ -827,7 +812,6 @@ pci_reset_hard(void)
pci_pic_reset(); pci_pic_reset();
} }
void void
pci_reset(void) pci_reset(void)
{ {
@@ -835,19 +819,18 @@ pci_reset(void)
pci_pmc = 0x00; pci_pmc = 0x00;
io_removehandler(0x0cf8, 1, 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, 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, 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, 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(); pci_reset_hard();
} }
static void static void
pci_slots_clear(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 */ pci_bus_number_to_index_mapping[0] = 0; /* always map bus 0 to index 0 */
} }
uint32_t uint32_t
trc_readl(uint16_t port, void *priv) trc_readl(uint16_t port, void *priv)
{ {
return 0xffffffff; return 0xffffffff;
} }
uint16_t uint16_t
trc_readw(uint16_t port, void *priv) trc_readw(uint16_t port, void *priv)
{ {
return 0xffff; return 0xffff;
} }
uint8_t uint8_t
trc_read(uint16_t port, void *priv) trc_read(uint16_t port, void *priv)
{ {
return trc_reg & 0xfb; return trc_reg & 0xfb;
} }
static void static void
trc_reset(uint8_t val) trc_reset(uint8_t val)
{ {
@@ -914,19 +893,16 @@ trc_reset(uint8_t val)
resetx86(); resetx86();
} }
void void
trc_writel(uint16_t port, uint32_t val, void *priv) trc_writel(uint16_t port, uint32_t val, void *priv)
{ {
} }
void void
trc_writew(uint16_t port, uint16_t val, void *priv) trc_writew(uint16_t port, uint16_t val, void *priv)
{ {
} }
void void
trc_write(uint16_t port, uint8_t val, void *priv) 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; trc_reg &= 0xfb;
} }
void void
trc_init(void) trc_init(void)
{ {
@@ -951,7 +926,6 @@ trc_init(void)
trc_read, trc_readw, trc_readl, trc_write, trc_writew, trc_writel, NULL); trc_read, trc_readw, trc_readl, trc_write, trc_writew, trc_writel, NULL);
} }
void void
pci_init(int type) pci_init(int type)
{ {
@@ -970,7 +944,7 @@ pci_init(int type)
pci_pmc = 0x00; pci_pmc = 0x00;
io_sethandler(0x0cfb, 1, 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) { if (type & PCI_NO_IRQ_STEERING) {
@@ -983,15 +957,15 @@ pci_init(int type)
if ((type & PCI_CONFIG_TYPE_MASK) == PCI_CONFIG_TYPE_1) { if ((type & PCI_CONFIG_TYPE_MASK) == PCI_CONFIG_TYPE_1) {
io_sethandler(0x0cf8, 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, 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; pci_pmc = 1;
} else { } else {
io_sethandler(0x0cf8, 1, 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, 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; pci_pmc = 0;
} }
@@ -1008,14 +982,12 @@ pci_init(int type)
pic_set_pci_flag(1); pic_set_pci_flag(1);
} }
uint8_t uint8_t
pci_register_bus() pci_register_bus()
{ {
return last_pci_bus++; return last_pci_bus++;
} }
void void
pci_remap_bus(uint8_t bus_index, uint8_t bus_number) 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; pci_bus_number_to_index_mapping[bus_number] = bus_index;
} }
void void
pci_register_slot(int card, int type, int inta, int intb, int intc, int intd) 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); pci_register_bus_slot(0, card, type, inta, intb, intc, intd);
} }
void void
pci_register_bus_slot(int bus, int card, int type, int inta, int intb, int intc, int intd) 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++; last_pci_card++;
} }
uint8_t uint8_t
pci_find_slot(uint8_t add_type, uint8_t ignore_slot) 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; break;
} }
} else { } else {
if (((dev->type == PCI_CARD_NORMAL) && ((add_type & 0x7f) >= PCI_ADD_NORMAL)) || if (((dev->type == PCI_CARD_NORMAL) && ((add_type & 0x7f) >= PCI_ADD_NORMAL)) || (dev->type == (add_type & 0x7f))) {
(dev->type == (add_type & 0x7f))) {
ret = i; ret = i;
break; break;
} }
@@ -1090,7 +1058,6 @@ pci_find_slot(uint8_t add_type, uint8_t ignore_slot)
return ret; return ret;
} }
uint8_t 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) 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) if (add_type < PCI_ADD_AGP)
pci_log("pci_add_card(): Adding PCI CARD at specific slot %02X [SPECIFIC]\n", add_type); 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"))))); 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; return 0xff;
} }

View File

@@ -15,25 +15,22 @@ static bar_t pci_bar[2];
static uint8_t interrupt_on = 0x00; static uint8_t interrupt_on = 0x00;
static uint8_t card = 0; 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]); pci_set_irq(card, pci_regs[0x3D]);
} } else {
else
{
pci_clear_irq(card, pci_regs[0x3D]); pci_clear_irq(card, pci_regs[0x3D]);
} }
} }
static uint8_t
static uint8_t pci_dummy_read(uint16_t Port, void *p) pci_dummy_read(uint16_t Port, void *p)
{ {
uint8_t ret = 0; uint8_t ret = 0;
switch(Port & 0x20) switch (Port & 0x20) {
{
case 0x00: case 0x00:
return 0x1A; return 0x1A;
case 0x01: case 0x01:
@@ -48,8 +45,7 @@ static uint8_t pci_dummy_read(uint16_t Port, void *p)
return pci_regs[0x3D]; return pci_regs[0x3D];
case 0x06: case 0x06:
ret = interrupt_on; ret = interrupt_on;
if (interrupt_on) if (interrupt_on) {
{
pci_dummy_interrupt(0); pci_dummy_interrupt(0);
interrupt_on = 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); return pci_dummy_read(Port, p);
} }
static uint32_t
static uint32_t pci_dummy_readl(uint16_t Port, void *p) pci_dummy_readl(uint16_t Port, void *p)
{ {
return pci_dummy_read(Port, p); return pci_dummy_read(Port, p);
} }
static void
static void pci_dummy_write(uint16_t Port, uint8_t Val, void *p) pci_dummy_write(uint16_t Port, uint8_t Val, void *p)
{ {
switch(Port & 0x20) switch (Port & 0x20) {
{
case 0x06: case 0x06:
if (!interrupt_on) if (!interrupt_on) {
{
interrupt_on = 1; interrupt_on = 1;
pci_dummy_interrupt(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); 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); pci_dummy_write(Port, Val & 0xFF, p);
} }
static void
static void pci_dummy_io_remove(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); 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); 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
static uint8_t pci_dummy_pci_read(int func, int addr, void *priv) pci_dummy_pci_read(int func, int addr, void *priv)
{ {
pclog("AB0B:071A: PCI_Read(%d, %04x)\n", func, addr); pclog("AB0B:071A: PCI_Read(%d, %04x)\n", func, addr);
switch(addr) { switch (addr) {
case 0x00: case 0x00:
return 0x1A; return 0x1A;
case 0x01: 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; uint8_t valxor;
pclog("AB0B:071A: PCI_Write(%d, %04x, %02x)\n", func, addr, val); pclog("AB0B:071A: PCI_Write(%d, %04x, %02x)\n", func, addr, val);
switch(addr) { switch (addr) {
case 0x04: /* PCI_COMMAND_LO */ case 0x04: /* PCI_COMMAND_LO */
valxor = (val & 0x03) ^ pci_regs[addr]; valxor = (val & 0x03) ^ pci_regs[addr];
if (valxor & PCI_COMMAND_IO) if (valxor & PCI_COMMAND_IO) {
{
pci_dummy_io_remove(); 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(); 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); pclog("AB0B:071A: PCI: new I/O base is %04X\n", pci_bar[0].addr);
/* We're done, so get out of the here. */ /* We're done, so get out of the here. */
if (pci_regs[4] & PCI_COMMAND_IO) if (pci_regs[4] & PCI_COMMAND_IO) {
{ if ((pci_bar[0].addr) != 0) {
if ((pci_bar[0].addr) != 0)
{
pci_dummy_io_set(); pci_dummy_io_set();
} }
} }
@@ -230,8 +225,8 @@ static void pci_dummy_pci_write(int func, int addr, uint8_t val, void *priv)
} }
} }
void
void pci_dummy_init(void) pci_dummy_init(void)
{ {
card = pci_add_card(PCI_ADD_NORMAL, pci_dummy_pci_read, pci_dummy_pci_write, NULL); 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/nvr.h>
#include <86box/acpi.h> #include <86box/acpi.h>
enum {
enum
{
STATE_NONE = 0, STATE_NONE = 0,
STATE_ICW2, STATE_ICW2,
STATE_ICW3, STATE_ICW3,
STATE_ICW4 STATE_ICW4
}; };
pic_t pic, pic2; pic_t pic, pic2;
static pc_timer_t pic_timer; static pc_timer_t pic_timer;
static int shadow = 0, elcr_enabled = 0, static int shadow = 0, elcr_enabled = 0,
@@ -60,11 +56,9 @@ static uint16_t smi_irq_mask = 0x0000,
static void (*update_pending)(void); static void (*update_pending)(void);
#ifdef ENABLE_PIC_LOG #ifdef ENABLE_PIC_LOG
int pic_do_log = ENABLE_PIC_LOG; int pic_do_log = ENABLE_PIC_LOG;
static void static void
pic_log(const char *fmt, ...) pic_log(const char *fmt, ...)
{ {
@@ -77,17 +71,15 @@ pic_log(const char *fmt, ...)
} }
} }
#else #else
#define pic_log(fmt, ...) # define pic_log(fmt, ...)
#endif #endif
void void
pic_reset_smi_irq_mask(void) pic_reset_smi_irq_mask(void)
{ {
smi_irq_mask = 0x0000; smi_irq_mask = 0x0000;
} }
void void
pic_set_smi_irq_mask(int irq, int set) pic_set_smi_irq_mask(int irq, int set)
{ {
@@ -105,7 +97,6 @@ pic_get_smi_irq_status(void)
return smi_irq_status; return smi_irq_status;
} }
void void
pic_clear_smi_irq_status(int irq) pic_clear_smi_irq_status(int irq)
{ {
@@ -113,7 +104,6 @@ pic_clear_smi_irq_status(int irq)
smi_irq_status &= ~(1 << irq); smi_irq_status &= ~(1 << irq);
} }
void void
pic_elcr_write(uint16_t port, uint8_t val, void *priv) 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'); (val & 0x80) ? 'L' : 'E');
} }
uint8_t uint8_t
pic_elcr_read(uint16_t port, void *priv) pic_elcr_read(uint16_t port, void *priv)
{ {
@@ -151,21 +140,18 @@ pic_elcr_read(uint16_t port, void *priv)
return dev->elcr; return dev->elcr;
} }
int int
pic_elcr_get_enabled(void) pic_elcr_get_enabled(void)
{ {
return elcr_enabled; return elcr_enabled;
} }
void void
pic_elcr_set_enabled(int enabled) pic_elcr_set_enabled(int enabled)
{ {
elcr_enabled = enabled; elcr_enabled = enabled;
} }
void void
pic_elcr_io_handler(int set) pic_elcr_io_handler(int set)
{ {
@@ -177,24 +163,20 @@ pic_elcr_io_handler(int set)
pic_elcr_write, NULL, NULL, &pic2); pic_elcr_write, NULL, NULL, &pic2);
} }
static uint8_t static uint8_t
pic_cascade_mode(pic_t *dev) pic_cascade_mode(pic_t *dev)
{ {
return !(dev->icw1 & 2); return !(dev->icw1 & 2);
} }
static __inline uint8_t static __inline uint8_t
pic_slave_on(pic_t *dev, int channel) 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)); 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)) && return pic_cascade_mode(dev) && (dev->is_master || ((dev->icw4 & 0x0c) == 0x0c)) && (dev->icw3 & (1 << channel));
(dev->icw3 & (1 << channel));
} }
static __inline int static __inline int
find_best_interrupt(pic_t *dev) find_best_interrupt(pic_t *dev)
{ {
@@ -228,7 +210,6 @@ find_best_interrupt(pic_t *dev)
return ret; return ret;
} }
static __inline void static __inline void
pic_update_pending_xt(void) pic_update_pending_xt(void)
{ {
@@ -240,7 +221,6 @@ pic_update_pending_xt(void)
pic.int_pending = 0; pic.int_pending = 0;
} }
static __inline void static __inline void
pic_update_pending_at(void) pic_update_pending_at(void)
{ {
@@ -254,7 +234,6 @@ pic_update_pending_at(void)
pic.int_pending = (find_best_interrupt(&pic) != -1); pic.int_pending = (find_best_interrupt(&pic) != -1);
} }
static void static void
pic_callback(void *priv) pic_callback(void *priv)
{ {
@@ -267,7 +246,6 @@ pic_callback(void *priv)
timer_on_auto(&pic_timer, 0.35); timer_on_auto(&pic_timer, 0.35);
} }
void void
pic_reset() pic_reset()
{ {
@@ -298,21 +276,18 @@ pic_reset()
pic_pci = 0; pic_pci = 0;
} }
void void
pic_set_shadow(int sh) pic_set_shadow(int sh)
{ {
shadow = sh; shadow = sh;
} }
void void
pic_set_pci_flag(int pci) pic_set_pci_flag(int pci)
{ {
pic_pci = pci; pic_pci = pci;
} }
static uint8_t static uint8_t
pic_level_triggered(pic_t *dev, int irq) pic_level_triggered(pic_t *dev, int irq)
{ {
@@ -322,14 +297,12 @@ pic_level_triggered(pic_t *dev, int irq)
return !!(dev->icw1 & 8); return !!(dev->icw1 & 8);
} }
int int
picint_is_level(int irq) picint_is_level(int irq)
{ {
return pic_level_triggered(((irq > 7) ? &pic2 : &pic), irq & 7); return pic_level_triggered(((irq > 7) ? &pic2 : &pic), irq & 7);
} }
static void static void
pic_acknowledge(pic_t *dev) pic_acknowledge(pic_t *dev)
{ {
@@ -341,7 +314,6 @@ pic_acknowledge(pic_t *dev)
dev->irr &= ~pic_int_num; dev->irr &= ~pic_int_num;
} }
/* Find IRQ for non-specific EOI (either by command or automatic) by finding the highest IRQ /* 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. */ priority with ISR bit set, that is also not masked if the PIC is in special mask mode. */
static uint8_t static uint8_t
@@ -363,7 +335,6 @@ pic_non_specific_find(pic_t *dev)
return irq; return irq;
} }
/* Do the EOI and rotation, if either is requested, on the given IRQ. */ /* Do the EOI and rotation, if either is requested, on the given IRQ. */
static void static void
pic_action(pic_t *dev, uint8_t irq, uint8_t eoi, uint8_t rotate) 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. */ /* Automatic non-specific EOI. */
static __inline void static __inline void
pic_auto_non_specific_eoi(pic_t *dev) 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. */ /* Do the PIC command specified by bits 7-5 of the value written to the OCW2 register. */
static void static void
pic_command(pic_t *dev) pic_command(pic_t *dev)
@@ -412,7 +381,6 @@ pic_command(pic_t *dev)
dev->auto_eoi_rotate = !!(dev->ocw2 & 0x80); dev->auto_eoi_rotate = !!(dev->ocw2 & 0x80);
} }
uint8_t uint8_t
pic_read(uint16_t addr, void *priv) pic_read(uint16_t addr, void *priv)
{ {
@@ -464,7 +432,6 @@ pic_read(uint16_t addr, void *priv)
return dev->data_bus; return dev->data_bus;
} }
static void static void
pic_write(uint16_t addr, uint8_t val, void *priv) 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 void
pic_set_pci(void) pic_set_pci(void)
{ {
@@ -545,7 +511,6 @@ pic_set_pci(void)
} }
} }
void void
pic_init(void) pic_init(void)
{ {
@@ -555,7 +520,6 @@ pic_init(void)
io_sethandler(0x0020, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic); io_sethandler(0x0020, 0x0002, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic);
} }
void void
pic_init_pcjr(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); io_sethandler(0x0020, 0x0008, pic_read, NULL, NULL, pic_write, NULL, NULL, &pic);
} }
void void
pic2_init(void) pic2_init(void)
{ {
@@ -573,7 +536,6 @@ pic2_init(void)
pic.slaves[2] = &pic2; pic.slaves[2] = &pic2;
} }
void void
picint_common(uint16_t num, int level, int set) picint_common(uint16_t num, int level, int set)
{ {
@@ -645,35 +607,30 @@ picint_common(uint16_t num, int level, int set)
update_pending(); update_pending();
} }
void void
picint(uint16_t num) picint(uint16_t num)
{ {
picint_common(num, 0, 1); picint_common(num, 0, 1);
} }
void void
picintlevel(uint16_t num) picintlevel(uint16_t num)
{ {
picint_common(num, 1, 1); picint_common(num, 1, 1);
} }
void void
picintc(uint16_t num) picintc(uint16_t num)
{ {
picint_common(num, 0, 0); picint_common(num, 0, 0);
} }
static uint8_t static uint8_t
pic_i86_mode(pic_t *dev) pic_i86_mode(pic_t *dev)
{ {
return !!(dev->icw4 & 1); return !!(dev->icw4 & 1);
} }
static uint8_t static uint8_t
pic_irq_ack_read(pic_t *dev, int phase) 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; return dev->data_bus;
} }
uint8_t uint8_t
pic_irq_ack(void) pic_irq_ack(void)
{ {
@@ -750,7 +706,6 @@ pic_irq_ack(void)
return ret; return ret;
} }
int int
picinterrupt() picinterrupt()
{ {

116
src/pit.c
View File

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

View File

@@ -61,7 +61,7 @@ pit_log(const char *fmt, ...)
} }
} }
#else #else
#define pit_log(fmt, ...) # define pit_log(fmt, ...)
#endif #endif
static void 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) if (data == NULL)
return; return;
pitf_t *pit = (pitf_t *)data; pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id]; ctrf_t *ctr = &pit->counters[counter_id];
ctr->load_func = func; 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 static uint16_t
pitf_ctr_get_count(void *data, int counter_id) 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]; ctrf_t *ctr = &pit->counters[counter_id];
return (uint16_t) ctr->l; 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) if (data == NULL)
return; return;
pitf_t *pit = (pitf_t *)data; pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id]; ctrf_t *ctr = &pit->counters[counter_id];
ctr->out_func = func; ctr->out_func = func;
@@ -113,7 +113,7 @@ pitf_ctr_set_using_timer(void *data, int counter_id, int using_timer)
if (tsc > 0) if (tsc > 0)
timer_process(); timer_process();
pitf_t *pit = (pitf_t *)data; pitf_t *pit = (pitf_t *) data;
ctrf_t *ctr = &pit->counters[counter_id]; ctrf_t *ctr = &pit->counters[counter_id];
ctr->using_timer = using_timer; ctr->using_timer = using_timer;
} }
@@ -275,7 +275,7 @@ pitf_set_gate_no_timer(ctrf_t *ctr, int gate)
static void static void
pitf_ctr_set_gate(void *data, int counter_id, int gate) 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]; ctrf_t *ctr = &pit->counters[counter_id];
if (ctr->disabled) { if (ctr->disabled) {
@@ -548,7 +548,7 @@ pitf_timer_over(void *p)
static void static void
pitf_ctr_clock(void *data, int counter_id) 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]; ctrf_t *ctr = &pit->counters[counter_id];
if (ctr->thit || !ctr->enabled) 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)) { if (!(dev->flags & PIT_PS2) && !(dev->flags & PIT_CUSTOM_CLOCK)) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
ctrf_t *ctr = &dev->counters[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/video.h>
#include <86box/port_6x.h> #include <86box/port_6x.h>
#define PS2_REFRESH_TIME (16 * TIMER_USEC) #define PS2_REFRESH_TIME (16 * TIMER_USEC)
#define PORT_6X_TURBO 1 #define PORT_6X_TURBO 1
@@ -43,7 +42,6 @@
#define PORT_6X_MIRROR 4 #define PORT_6X_MIRROR 4
#define PORT_6X_SWA 8 #define PORT_6X_SWA 8
static void static void
port_6x_write(uint16_t port, uint8_t val, void *priv) 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) if (ppispeakon)
ret |= 0x20; ret |= 0x20;
return(ret); return (ret);
} }
static uint8_t static uint8_t
@@ -102,7 +100,7 @@ port_61_read(uint16_t port, void *priv)
if (dev->flags & PORT_6X_TURBO) if (dev->flags & PORT_6X_TURBO)
ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00); ret = (ret & 0xfb) | (xi8088_turbo_get() ? 0x04 : 0x00);
return(ret); return (ret);
} }
static uint8_t static uint8_t
@@ -138,7 +136,7 @@ port_62_read(uint16_t port, void *priv)
ret |= 0x02; ret |= 0x02;
} }
return(ret); return (ret);
} }
static void static void
@@ -150,7 +148,6 @@ port_6x_refresh(void *priv)
timer_advance_u64(&dev->refresh_timer, PS2_REFRESH_TIME); timer_advance_u64(&dev->refresh_timer, PS2_REFRESH_TIME);
} }
static void static void
port_6x_close(void *priv) port_6x_close(void *priv)
{ {
@@ -161,7 +158,6 @@ port_6x_close(void *priv)
free(dev); free(dev);
} }
void * void *
port_6x_init(const device_t *info) port_6x_init(const device_t *info)
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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