From d235e806b25d219701fc19f297d7eb5209207393 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Wed, 28 Feb 2018 01:58:21 +0800 Subject: [PATCH] Move to C++. Use C++14 as it adds binary literals -> HDL friendly. --- DiskImage.cpp | 4 +- DiskImage.h | 11 +- Makefile | 2 +- MiSTer.ini | 2 +- MiSTer.vcxproj | 44 +++--- MiSTer.vcxproj.filters | 44 +++--- archie.c => archie.cpp | 8 +- archie.h | 4 +- battery.c => battery.cpp | 0 brightness.c => brightness.cpp | 0 cfg.c => cfg.cpp | 2 +- file_io.c => file_io.cpp | 28 ++-- file_io.h | 26 ++- fpga_io.c => fpga_io.cpp | 12 +- fpga_io.h | 2 +- hardware.c => hardware.cpp | 2 +- ini_parser.c => ini_parser.cpp | 0 ini_parser.h | 4 +- input.c => input.cpp | 2 +- main.c => main.cpp | 3 +- menu.c => menu.cpp | 211 +++++++++---------------- menu.h | 8 +- minimig_boot.c => minimig_boot.cpp | 8 +- minimig_boot.h | 2 +- minimig_config.c => minimig_config.cpp | 0 minimig_fdd.c => minimig_fdd.cpp | 0 minimig_hdd.c => minimig_hdd.cpp | 0 osd.c => osd.cpp | 10 +- osd.h | 10 +- spi.c => spi.cpp | 6 +- spi.h | 6 +- st_ikbd.c => st_ikbd.cpp | 7 +- st_tos.c => st_tos.cpp | 29 ++-- st_tos.h | 8 +- tzx2wav.c => tzx2wav.cpp | 4 +- user_io.c => user_io.cpp | 139 ++++++++-------- user_io.h | 27 ++-- x86.c => x86.cpp | 6 +- 38 files changed, 309 insertions(+), 372 deletions(-) rename archie.c => archie.cpp (98%) rename battery.c => battery.cpp (100%) rename brightness.c => brightness.cpp (100%) rename cfg.c => cfg.cpp (94%) rename file_io.c => file_io.cpp (91%) rename fpga_io.c => fpga_io.cpp (92%) rename hardware.c => hardware.cpp (94%) rename ini_parser.c => ini_parser.cpp (100%) rename input.c => input.cpp (95%) rename main.c => main.cpp (92%) rename menu.c => menu.cpp (91%) rename minimig_boot.c => minimig_boot.cpp (98%) rename minimig_config.c => minimig_config.cpp (100%) rename minimig_fdd.c => minimig_fdd.cpp (100%) rename minimig_hdd.c => minimig_hdd.cpp (100%) rename osd.c => osd.cpp (92%) rename spi.c => spi.cpp (90%) rename st_ikbd.c => st_ikbd.cpp (99%) rename st_tos.c => st_tos.cpp (93%) rename tzx2wav.c => tzx2wav.cpp (95%) rename user_io.c => user_io.cpp (93%) rename x86.c => x86.cpp (98%) diff --git a/DiskImage.cpp b/DiskImage.cpp index 91a29e9..abf96f5 100644 --- a/DiskImage.cpp +++ b/DiskImage.cpp @@ -3002,7 +3002,7 @@ unsigned unpack_lzh(unsigned char *src, unsigned size, unsigned char *buf) } //-------------------------------------------------------------------------- -extern "C" int x2trd(char *name, fileTYPE *f) +int x2trd(const char *name, fileTYPE *f) { TDiskImage *img = new TDiskImage; img->Open(getFullPath(name), true); @@ -3033,7 +3033,7 @@ extern "C" int x2trd(char *name, fileTYPE *f) return 1; } -extern "C" int x2trd_ext_supp(char *name) +int x2trd_ext_supp(const char *name) { const char *ext = ""; if (strlen(name) > 4) ext = name + strlen(name) - 4; diff --git a/DiskImage.h b/DiskImage.h index eb4be11..d819de8 100644 --- a/DiskImage.h +++ b/DiskImage.h @@ -1,8 +1,9 @@ #ifndef __DISKIMAGE_H #define __DISKIMAGE_H + //----------------------------------------------------------------------------- -#ifdef __cplusplus +#include "file_io.h" enum TDiskImageType { DIT_UNK, DIT_SCL, DIT_FDI, DIT_TD0, DIT_UDI, DIT_HOB, DIT_FDD }; @@ -184,12 +185,8 @@ struct TRDOS_DIR_ELEMENT // 16 bytes }; #pragma pack() -#else - -int x2trd(char *name, fileTYPE *f); -int x2trd_ext_supp(char *name); - -#endif +int x2trd(const char *name, fileTYPE *f); +int x2trd_ext_supp(const char *name); //----------------------------------------------------------------------------- #endif \ No newline at end of file diff --git a/Makefile b/Makefile index 40190e4..8df6380 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ clean: %.o: %.cpp @$(info $<) - @$(CC) $(CFLAGS) -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' + @$(CC) $(CFLAGS) -std=gnu++14 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g' -include $(DEP) %.d: %.c diff --git a/MiSTer.ini b/MiSTer.ini index 4f269df..b0f9346 100644 --- a/MiSTer.ini +++ b/MiSTer.ini @@ -34,7 +34,7 @@ dvi_mode=0 ; set to 1 for DVI mode. Audio won't be transmitted throu ; 1,1280,48,112,248,1024,1,3,38,108 video_mode=0 -; set to 1-10 to display video info on startup/change +; set to 1-10 (seconds) to display video info on startup/change video_info=0 ; set to 1 for automatic HDMI VSync rate adjust to match original VSync. diff --git a/MiSTer.vcxproj b/MiSTer.vcxproj index 9cad680..967f04f 100644 --- a/MiSTer.vcxproj +++ b/MiSTer.vcxproj @@ -39,29 +39,29 @@ - - - - + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + diff --git a/MiSTer.vcxproj.filters b/MiSTer.vcxproj.filters index 05f443b..0798ceb 100644 --- a/MiSTer.vcxproj.filters +++ b/MiSTer.vcxproj.filters @@ -11,73 +11,73 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files diff --git a/archie.c b/archie.cpp similarity index 98% rename from archie.c rename to archie.cpp index 52eb648..76609c9 100644 --- a/archie.c +++ b/archie.cpp @@ -73,9 +73,9 @@ static unsigned char flags; static unsigned long hold_off_timer; #endif -static char sector_buffer[1024]; +static uint8_t sector_buffer[1024]; -char *archie_get_rom_name(void) +const char *archie_get_rom_name(void) { char *p = strrchr(config.rom_img, '/'); if (!p) p = config.rom_img; else p++; @@ -83,7 +83,7 @@ char *archie_get_rom_name(void) return p; } -char *archie_get_floppy_name(char i) +const char *archie_get_floppy_name(char i) { if (!floppy[i].size) return "* no disk *"; @@ -229,7 +229,7 @@ static void archie_kbd_tx(unsigned char state, unsigned char byte) spi8(byte); DisableIO(); - kbd_state = state; + kbd_state = (enum state)state; ack_timeout = GetTimer(10); // 10ms timeout } diff --git a/archie.h b/archie.h index bfa1fee..f35d56d 100644 --- a/archie.h +++ b/archie.h @@ -7,8 +7,8 @@ void archie_init(void); void archie_poll(void); void archie_kbd(unsigned short code); void archie_mouse(unsigned char b, int16_t x, int16_t y); -char *archie_get_rom_name(void); -char *archie_get_floppy_name(char b); +const char *archie_get_rom_name(void); +const char *archie_get_floppy_name(char b); void archie_set_rom(char *); void archie_set_floppy(char i, char *); char archie_floppy_is_inserted(char i); diff --git a/battery.c b/battery.cpp similarity index 100% rename from battery.c rename to battery.cpp diff --git a/brightness.c b/brightness.cpp similarity index 100% rename from brightness.c rename to brightness.cpp diff --git a/cfg.c b/cfg.cpp similarity index 94% rename from cfg.c rename to cfg.cpp index bfd6421..4c3e2f2 100644 --- a/cfg.c +++ b/cfg.cpp @@ -27,7 +27,7 @@ const ini_var_t ini_vars[] = { { "COMPOSITE_SYNC", (void*)(&(cfg.csync)), UINT8, 0, 1, 1 }, { "FORCED_SCANDOUBLER", (void*)(&(cfg.forced_scandoubler)), UINT8, 0, 1, 1 }, { "VGA_SCALER", (void*)(&(cfg.vga_scaler)), UINT8, 0, 1, 1 }, - { "KEYRAH_MODE", (void*)(&(cfg.keyrah_mode)), UINT32, 0, 0xFFFFFFFF, 1 }, + { "KEYRAH_MODE", (void*)(&(cfg.keyrah_mode)), UINT32, 0, (int)0xFFFFFFFF, 1 }, { "RESET_COMBO", (void*)(&(cfg.reset_combo)), UINT8, 0, 3, 1 }, { "KEY_MENU_AS_RGUI", (void*)(&(cfg.key_menu_as_rgui)), UINT8, 0, 1, 1 }, { "VIDEO_MODE", (void*)(cfg.video_conf), STRING, 0, sizeof(cfg.video_conf)-1, 1 }, diff --git a/file_io.c b/file_io.cpp similarity index 91% rename from file_io.c rename to file_io.cpp index 075198a..7f87370 100644 --- a/file_io.c +++ b/file_io.cpp @@ -233,7 +233,7 @@ int FileWriteSec(fileTYPE *file, void *pBuffer) return FileWriteAdv(file, pBuffer, 512); } -int FileSave(char *name, void *pBuffer, int size) +int FileSave(const char *name, void *pBuffer, int size) { sprintf(full_path, "%s/%s", getRootDir(), name); int fd = open(full_path, O_WRONLY | O_CREAT | O_TRUNC | O_SYNC, S_IRWXU | S_IRWXG | S_IRWXO); @@ -255,14 +255,14 @@ int FileSave(char *name, void *pBuffer, int size) return ret; } -int FileSaveConfig(char *name, void *pBuffer, int size) +int FileSaveConfig(const char *name, void *pBuffer, int size) { char path[256] = { CONFIG_DIR"/" }; strcat(path, name); return FileSave(path, pBuffer, size); } -int FileLoad(char *name, void *pBuffer, int size) +int FileLoad(const char *name, void *pBuffer, int size) { sprintf(full_path, "%s/%s", getRootDir(), name); int fd = open(full_path, O_RDONLY); @@ -299,14 +299,14 @@ int FileLoad(char *name, void *pBuffer, int size) return ret; } -int FileLoadConfig(char *name, void *pBuffer, int size) +int FileLoadConfig(const char *name, void *pBuffer, int size) { char path[256] = { CONFIG_DIR"/" }; strcat(path, name); return FileLoad(path, pBuffer, size); } -int FileCanWrite(char *name) +int FileCanWrite(const char *name) { sprintf(full_path, "%s/%s", getRootDir(), name); @@ -324,7 +324,7 @@ int FileCanWrite(char *name) static int device = 0; static int usbnum = 0; -char *getStorageDir(int dev) +const char *getStorageDir(int dev) { static char path[32]; if (!dev) return "/media/fat"; @@ -332,12 +332,12 @@ char *getStorageDir(int dev) return path; } -char *getRootDir() +const char *getRootDir() { return getStorageDir(device); } -char *getFullPath(char *name) +const char *getFullPath(const char *name) { sprintf(full_path, "%s/%s", getRootDir(), name); return full_path; @@ -480,7 +480,7 @@ void FindStorage(void) printf("Using SD card as a root device\n"); } - sprintf(full_path, "%s/"CONFIG_DIR, getRootDir()); + sprintf(full_path, "%s/" CONFIG_DIR, getRootDir()); DIR* dir = opendir(full_path); if (dir) closedir(dir); else if (ENOENT == errno) mkdir(full_path, S_IRWXU | S_IRWXG | S_IRWXO); @@ -488,8 +488,8 @@ void FindStorage(void) int de_cmp(const void *e1, const void *e2) { - const struct dirent *de1 = e1; - const struct dirent *de2 = e2; + const struct dirent *de1 = (struct dirent *)e1; + const struct dirent *de2 = (struct dirent *)e2; if ((de1->d_type == DT_DIR) && !strcmp(de1->d_name, "..")) return -1; if ((de2->d_type == DT_DIR) && !strcmp(de2->d_name, "..")) return 1; @@ -543,10 +543,10 @@ void AdjustDirectory(char *path) } } -int ScanDirectory(char* path, int mode, char *extension, int options) +int ScanDirectory(const char* path, int mode, const char *extension, int options) { int has_trd = 0; - char *ext = extension; + const char *ext = extension; while (*ext) { if (!strncasecmp(ext, "TRD", 3)) has_trd = 1; @@ -603,7 +603,7 @@ int ScanDirectory(char* path, int mode, char *extension, int options) if (extlen > 0) { int len = strlen(de->d_name); - char *ext = extension; + const char *ext = extension; int found = (has_trd && x2trd_ext_supp(de->d_name)); while(!found && *ext) diff --git a/file_io.h b/file_io.h index f201999..32b039e 100644 --- a/file_io.h +++ b/file_io.h @@ -6,10 +6,6 @@ #include #include "spi.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { int fd; @@ -62,25 +58,21 @@ int FileReadSec(fileTYPE *file, void *pBuffer); int FileWriteAdv(fileTYPE *file, void *pBuffer, int length); int FileWriteSec(fileTYPE *file, void *pBuffer); -int FileCanWrite(char *name); +int FileCanWrite(const char *name); -int FileSave(char *name, void *pBuffer, int size); -int FileLoad(char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading +int FileSave(const char *name, void *pBuffer, int size); +int FileLoad(const char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading //save/load from config dir #define CONFIG_DIR "config" -int FileSaveConfig(char *name, void *pBuffer, int size); -int FileLoadConfig(char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading +int FileSaveConfig(const char *name, void *pBuffer, int size); +int FileLoadConfig(const char *name, void *pBuffer, int size); // supply pBuffer = 0 to get the file size without loading void AdjustDirectory(char *path); -int ScanDirectory(char* path, int mode, char *extension, int options); +int ScanDirectory(const char* path, int mode, const char *extension, int options); -char *getStorageDir(int dev); -char *getRootDir(); -char *getFullPath(char *name); - -#ifdef __cplusplus -} -#endif +const char *getStorageDir(int dev); +const char *getRootDir(); +const char *getFullPath(const char *name); #endif diff --git a/fpga_io.c b/fpga_io.cpp similarity index 92% rename from fpga_io.c rename to fpga_io.cpp index b67b62e..57a15f9 100644 --- a/fpga_io.c +++ b/fpga_io.cpp @@ -26,10 +26,10 @@ #define fatal(x) munmap((void*)map_base, FPGA_REG_SIZE); close(fd); exit(x) -static struct socfpga_reset_manager *reset_regs = (void *)SOCFPGA_RSTMGR_ADDRESS; -static struct socfpga_fpga_manager *fpgamgr_regs = (void *)SOCFPGA_FPGAMGRREGS_ADDRESS; -static struct socfpga_system_manager *sysmgr_regs = (void *)SOCFPGA_SYSMGR_ADDRESS; -static struct nic301_registers *nic301_regs = (void *)SOCFPGA_L3REGS_ADDRESS; +static struct socfpga_reset_manager *reset_regs = (socfpga_reset_manager *)SOCFPGA_RSTMGR_ADDRESS; +static struct socfpga_fpga_manager *fpgamgr_regs = (socfpga_fpga_manager *)SOCFPGA_FPGAMGRREGS_ADDRESS; +static struct socfpga_system_manager *sysmgr_regs = (socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS; +static struct nic301_registers *nic301_regs = (nic301_registers *)SOCFPGA_L3REGS_ADDRESS; static uint32_t *map_base; static int fd; @@ -446,7 +446,7 @@ static int save_core_name(char *name) } #endif -int fpga_load_rbf(char *name) +int fpga_load_rbf(const char *name) { char path[512]; int ret = 0; @@ -518,7 +518,7 @@ int fpga_io_init() { if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) return -1; - map_base = mmap(0, FPGA_REG_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, FPGA_REG_BASE); + map_base = (uint32_t*)mmap(0, FPGA_REG_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, FPGA_REG_BASE); if (map_base == (void *)-1) { printf("Unable to mmap(/dev/mem)\n"); diff --git a/fpga_io.h b/fpga_io.h index f2f8863..cc085ad 100644 --- a/fpga_io.h +++ b/fpga_io.h @@ -28,7 +28,7 @@ int is_fpga_ready(int quick); int fpga_get_fio_size(); int fpga_get_io_version(); -int fpga_load_rbf(char *name); +int fpga_load_rbf(const char *name); void reboot(int cold); void app_restart(); diff --git a/hardware.c b/hardware.cpp similarity index 94% rename from hardware.c rename to hardware.cpp index a7eb24e..8aadfe6 100644 --- a/hardware.c +++ b/hardware.cpp @@ -31,7 +31,7 @@ void hexdump(void *data, uint16_t size, uint16_t offset) { uint8_t i, b2c; uint16_t n = 0; - char *ptr = data; + char *ptr = (char*)data; if (!size) return; diff --git a/ini_parser.c b/ini_parser.cpp similarity index 100% rename from ini_parser.c rename to ini_parser.cpp diff --git a/ini_parser.h b/ini_parser.h index f571521..f7eb4ef 100644 --- a/ini_parser.h +++ b/ini_parser.h @@ -11,7 +11,7 @@ //// type definitions //// typedef struct { int id; - char* name; + const char* name; } ini_section_t; typedef enum { @@ -22,7 +22,7 @@ typedef enum { typedef void custom_handler_t(char*); typedef struct { - char* name; + const char* name; void* var; ini_vartypes_t type; int min; diff --git a/input.c b/input.cpp similarity index 95% rename from input.c rename to input.cpp index 3d9e8b8..60e7dca 100644 --- a/input.c +++ b/input.cpp @@ -1229,7 +1229,7 @@ static int check_devs() return result; } -static void INThandler() +static void INThandler(int code) { printf("\nExiting...\n"); diff --git a/main.c b/main.cpp similarity index 92% rename from main.c rename to main.cpp index bf07836..ce72c44 100644 --- a/main.c +++ b/main.cpp @@ -19,7 +19,6 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#define _GNU_SOURCE #include #include #include @@ -30,7 +29,7 @@ along with this program. If not, see . #include "input.h" #include "fpga_io.h" -const char version[] = { "$VER:HPS" VDATE }; +const char *version = "$VER:HPS" VDATE; int main(int argc, char *argv[]) { diff --git a/menu.c b/menu.cpp similarity index 91% rename from menu.c rename to menu.cpp index e0e608c..120ce9f 100644 --- a/menu.c +++ b/menu.cpp @@ -151,7 +151,7 @@ extern adfTYPE df[4]; extern configTYPE config; -extern const char version[]; +extern const char *version; const char *config_tos_mem[] = { "512 kB", "1 MB", "2 MB", "4 MB", "8 MB", "14 MB", "--", "--" }; const char *config_tos_wrprot[] = { "none", "A:", "B:", "A: and B:" }; const char *config_tos_usb[] = { "none", "control", "debug", "serial", "parallel", "midi" }; @@ -169,11 +169,11 @@ const char *config_cpu_msg[] = { "68000", "68010", "-----","68020" }; const char *config_hdf_msg[] = { "Disabled", "Hardfile (disk img)", "MMC/SD card", "MMC/SD partition 1", "MMC/SD partition 2", "MMC/SD partition 3", "MMC/SD partition 4" }; const char *config_chipset_msg[] = { "OCS-A500", "OCS-A1000", "ECS", "---", "---", "---", "AGA", "---" }; const char *config_turbo_msg[] = { "none", "CHIPRAM", "KICK", "BOTH" }; -char *config_autofire_msg[] = { " AUTOFIRE OFF", " AUTOFIRE FAST", " AUTOFIRE MEDIUM", " AUTOFIRE SLOW" }; +const char *config_autofire_msg[] = { " AUTOFIRE OFF", " AUTOFIRE FAST", " AUTOFIRE MEDIUM", " AUTOFIRE SLOW" }; const char *config_cd32pad_msg[] = { "OFF", "ON" }; -char *config_button_turbo_msg[] = { "OFF", "FAST", "MEDIUM", "SLOW" }; -char *config_button_turbo_choice_msg[] = { "A only", "B only", "A & B" }; -char *joy_button_map[] = { "RIGHT", "LEFT", "DOWN", "UP", "BUTTON 1", "BUTTON 2", "BUTTON 3", "BUTTON 4", "KBD TOGGLE", "BUTTON OSD" }; +const char *config_button_turbo_msg[] = { "OFF", "FAST", "MEDIUM", "SLOW" }; +const char *config_button_turbo_choice_msg[] = { "A only", "B only", "A & B" }; +const char *joy_button_map[] = { "RIGHT", "LEFT", "DOWN", "UP", "BUTTON 1", "BUTTON 2", "BUTTON 3", "BUTTON 4", "KBD TOGGLE", "BUTTON OSD" }; const char *config_stereo_msg[] = { "0%", "25%", "50%", "100%" }; char joy_bnames[12][32]; @@ -270,7 +270,7 @@ int changeDir(char *dir) return 1; } -static void SelectFile(char* pFileExt, unsigned char Options, unsigned char MenuSelect, unsigned char MenuCancel, char chdir) +static void SelectFile(const char* pFileExt, unsigned char Options, unsigned char MenuSelect, unsigned char MenuCancel, char chdir) { // this function displays file selection menu @@ -393,7 +393,7 @@ unsigned long getStatusMask(char *opt) { return x << idx1; } -char* get_keycode_table() +const char* get_keycode_table() { switch (user_io_core_type()) { @@ -526,7 +526,7 @@ char* getNet(int spec) } static long sysinfo_timer; -void infowrite(int pos, char* txt) +static void infowrite(int pos, const char* txt) { char str[40]; memset(str, 0x20, 29); @@ -635,7 +635,7 @@ void HandleUI(void) char *p; char s[40]; - unsigned char i, m, up, down, select, menu, right, left, plus, minus; + unsigned char m, up, down, select, menu, right, left, plus, minus; uint8_t mod; unsigned long len; static hardfileTYPE t_hardfile[2]; // temporary copy of former hardfile configuration @@ -958,7 +958,7 @@ void HandleUI(void) } // add options as requested by core - i = 2; + int i = 2; do { char* pos; unsigned long status = user_io_8bit_set_status(0, 0); // 0,0 gets status @@ -1378,59 +1378,61 @@ void HandleUI(void) break; case MENU_JOYDIGMAP1: - p = 0; - if (get_map_button() < 4) { - p = joy_button_map[get_map_button()]; - } - else if(joy_bcount) - { - p = (get_map_button() < joy_bcount + 4) ? joy_bnames[get_map_button() - 4] : joy_button_map[8+get_map_type()]; - } - else - { - p = (get_map_button() < 8) ? joy_button_map[get_map_button()] : joy_button_map[8 + get_map_type()]; - } - - - { - s[0] = 0; - int len = (30-(strlen(p)+7))/2; - while (len > 0) + const char* p = 0; + if (get_map_button() < 4) { - strcat(s, " "); - len--; + p = joy_button_map[get_map_button()]; } - } - strcat(s, "Press: "); - strcat(s, p); - OsdWrite(3, s, 0, 0); - if (get_map_button()) - { - if(get_map_type()) OsdWrite(OsdGetSize() - 1, " finish (SPACE - skip)", menusub == 0, 0); - else OsdWrite(OsdGetSize() - 1, "", 0, 0); - - sprintf(s, " %s ID: %04x:%04x", get_map_type() ? "Joystick" : "Keyboard", get_map_vid(), get_map_pid()); - OsdWrite(5, s, 0, 0); - } - - if (select || menu || get_map_button() >= (joy_bcount ? joy_bcount + 5 : 9)) - { - finish_map_setting(menu); - if (is_menu_core()) + else if (joy_bcount) { - menustate = MENU_FIRMWARE1; - menusub = 2; - } - else if (is_archie()) - { - menustate = MENU_ARCHIE_MAIN1; - menusub = 4; + p = (get_map_button() < joy_bcount + 4) ? joy_bnames[get_map_button() - 4] : joy_button_map[8 + get_map_type()]; } else { - menustate = MENU_8BIT_SYSTEM1; - menusub = 1; + p = (get_map_button() < 8) ? joy_button_map[get_map_button()] : joy_button_map[8 + get_map_type()]; + } + + + { + s[0] = 0; + int len = (30 - (strlen(p) + 7)) / 2; + while (len > 0) + { + strcat(s, " "); + len--; + } + } + strcat(s, "Press: "); + strcat(s, p); + OsdWrite(3, s, 0, 0); + if (get_map_button()) + { + if (get_map_type()) OsdWrite(OsdGetSize() - 1, " finish (SPACE - skip)", menusub == 0, 0); + else OsdWrite(OsdGetSize() - 1, "", 0, 0); + + sprintf(s, " %s ID: %04x:%04x", get_map_type() ? "Joystick" : "Keyboard", get_map_vid(), get_map_pid()); + OsdWrite(5, s, 0, 0); + } + + if (select || menu || get_map_button() >= (joy_bcount ? joy_bcount + 5 : 9)) + { + finish_map_setting(menu); + if (is_menu_core()) + { + menustate = MENU_FIRMWARE1; + menusub = 2; + } + else if (is_archie()) + { + menustate = MENU_ARCHIE_MAIN1; + menusub = 4; + } + else + { + menustate = MENU_8BIT_SYSTEM1; + menusub = 1; + } } } break; @@ -1566,7 +1568,7 @@ void HandleUI(void) menumask = tos_get_direct_hdd() ? 0x3f : 0x7f; OsdSetTitle("Storage", 0); // entries for both floppies - for (i = 0; i<2; i++) { + for (int i = 0; i<2; i++) { strcpy(s, " A: "); strcat(s, tos_get_disk_name(i)); s[1] = 'A' + i; @@ -1581,7 +1583,7 @@ void HandleUI(void) strcpy(s, " ACSI0 direct SD: "); strcat(s, tos_get_direct_hdd() ? "on" : "off"); OsdWrite(4, s, menusub == 3, 0); - for (i = 0; i<2; i++) { + for (int i = 0; i<2; i++) { strcpy(s, " ACSI0: "); s[5] = '0' + i; @@ -1940,7 +1942,7 @@ void HandleUI(void) // We display a line for each drive that's active // in the config file, but grey out any that the FPGA doesn't think are active. // We also print a help text in place of the last drive if it's inactive. - for (i = 0; i < 4; i++) + for (int i = 0; i < 4; i++) { if (i == config.floppy.drives + 1) OsdWrite(i+1, " KP +/- to add/remove drives", 0, 1); @@ -2079,9 +2081,7 @@ void HandleUI(void) } else if (c == KEY_BACKSPACE) // eject all floppies { - for (i = 0; i <= drives; i++) - df[i].status = 0; - + for (int i = 0; i <= drives; i++) df[i].status = 0; menustate = MENU_MAIN1; } else if (right) @@ -2221,11 +2221,14 @@ void HandleUI(void) menustate = MENU_FILE_SELECT1; } - if ((i = GetASCIIKey(c))>1) - { - // find an entry beginning with given character - ScanDirectory(SelectedPath, i, fs_pFileExt, fs_Options); - menustate = MENU_FILE_SELECT1; + { + int i; + if ((i = GetASCIIKey(c)) > 1) + { + // find an entry beginning with given character + ScanDirectory(SelectedPath, i, fs_pFileExt, fs_Options); + menustate = MENU_FILE_SELECT1; + } } if (select) @@ -3366,72 +3369,6 @@ void ScrollLongName(void) ScrollText(iSelectedEntry-iFirstEntry, DirItem[iSelectedEntry].d_name, 2, len, max_len, 1); } -char* GetDiskInfo(char* lfn, long len) -{ - // extracts disk number substring form file name - // if file name contains "X of Y" substring where X and Y are one or two digit number - // then the number substrings are extracted and put into the temporary buffer for further processing - // comparision is case sensitive - - short i, k; - static char info[] = "XX/XX"; // temporary buffer - static char template[4] = " of "; // template substring to search for - char *ptr1, *ptr2, c; - unsigned char cmp; - - if (len > 20) // scan only names which can't be fully displayed - { - for (i = (unsigned short)len - 1 - sizeof(template); i > 0; i--) // scan through the file name starting from its end - { - ptr1 = &lfn[i]; // current start position - ptr2 = template; - cmp = 0; - for (k = 0; k < sizeof(template); k++) // scan through template - { - cmp |= *ptr1++ ^ *ptr2++; // compare substrings' characters one by one - if (cmp) - break; // stop further comparing if difference already found - } - - if (!cmp) // match found - { - k = i - 1; // no need to check if k is valid since i is greater than zero - - c = lfn[k]; // get the first character to the left of the matched template substring - if (c >= '0' && c <= '9') // check if a digit - { - info[1] = c; // copy to buffer - info[0] = ' '; // clear previous character - k--; // go to the preceding character - if (k >= 0) // check if index is valid - { - c = lfn[k]; - if (c >= '0' && c <= '9') // check if a digit - info[0] = c; // copy to buffer - } - - k = i + sizeof(template); // get first character to the right of the mached template substring - c = lfn[k]; // no need to check if index is valid - if (c >= '0' && c <= '9') // check if a digit - { - info[3] = c; // copy to buffer - info[4] = ' '; // clear next char - k++; // go to the followwing character - if (k < len) // check if index is valid - { - c = lfn[k]; - if (c >= '0' && c <= '9') // check if a digit - info[4] = c; // copy to buffer - } - return info; - } - } - } - } - } - return NULL; -} - // print directory contents void PrintDirectory(void) { @@ -3610,7 +3547,7 @@ void ErrorMessage(const char *message, unsigned char code) OsdEnable(0); // do not disable KEYBOARD } -void InfoMessage(char *message) +void InfoMessage(const char *message) { if (menustate != MENU_INFO) { @@ -3624,13 +3561,13 @@ void InfoMessage(char *message) menustate = MENU_INFO; } -void InfoMessageEx(char *message, int timeout) +void InfoMessageEx(const char *message, int timeout) { InfoMessage(message); menu_timer = GetTimer(timeout); } -void InfoEx(char *message, int width, int height, int timeout) +void InfoEx(const char *message, int width, int height, int timeout) { if (!user_io_osd_is_visible()) { @@ -3642,7 +3579,7 @@ void InfoEx(char *message, int width, int height, int timeout) } } -void Info(char *message, int width, int height) +void Info(const char *message, int width, int height) { InfoEx(message, width, height, 2000); } diff --git a/menu.h b/menu.h index b1bdc7b..8ff798a 100644 --- a/menu.h +++ b/menu.h @@ -18,10 +18,10 @@ void HandleUI(void); void PrintDirectory(void); void ScrollLongName(void); void ErrorMessage(const char *message, unsigned char code); -void InfoMessage(char *message); -void InfoMessageEx(char *message, int timeout); -void InfoEx(char *message, int width, int height, int timeout); -void Info(char *message, int width, int height); +void InfoMessage(const char *message); +void InfoMessageEx(const char *message, int timeout); +void InfoEx(const char *message, int width, int height, int timeout); +void Info(const char *message, int width, int height); void ShowSplash(); void HideSplash(); diff --git a/minimig_boot.c b/minimig_boot.cpp similarity index 98% rename from minimig_boot.c rename to minimig_boot.cpp index ef94b6a..9b2e4ed 100644 --- a/minimig_boot.c +++ b/minimig_boot.cpp @@ -179,7 +179,7 @@ void BootUploadLogo() int i = 0; int adr; - if (FileOpen(&file, "Amiga/"LOGO_FILE) || FileOpen(&file, LOGO_FILE)) { + if (FileOpen(&file, "Amiga/" LOGO_FILE) || FileOpen(&file, LOGO_FILE)) { FileReadSec(&file, buffer); mem_upload_init(SCREEN_BPL1 + LOGO_OFFSET); adr = SCREEN_BPL1 + LOGO_OFFSET; @@ -240,7 +240,7 @@ void BootUploadBall() int i = 0; int adr; - if (FileOpen(&file, "Amiga/"BALL_FILE) || FileOpen(&file, BALL_FILE)) + if (FileOpen(&file, "Amiga/" BALL_FILE) || FileOpen(&file, BALL_FILE)) { FileReadSec(&file, buffer); mem_upload_init(BALL_ADDRESS); @@ -272,7 +272,7 @@ void BootUploadCopper() int i = 0; int adr; - if (FileOpen(&file, "Amiga/"COPPER_FILE) || FileOpen(&file, COPPER_FILE)) + if (FileOpen(&file, "Amiga/" COPPER_FILE) || FileOpen(&file, COPPER_FILE)) { FileReadSec(&file, buffer); mem_upload_init(COPPER_ADDRESS); @@ -467,7 +467,7 @@ void BootInit() //// BootPrint() //// -void BootPrintEx(char * str) +void BootPrintEx(const char * str) { unsigned char i, j; unsigned char len; diff --git a/minimig_boot.h b/minimig_boot.h index 15bfdf5..e2ab0d9 100644 --- a/minimig_boot.h +++ b/minimig_boot.h @@ -36,7 +36,7 @@ //// functions //// void BootInit(); -void BootPrintEx(char * str); +void BootPrintEx(const char * str); void BootHome(); #define BootPrint(text) printf("%s\n", text) diff --git a/minimig_config.c b/minimig_config.cpp similarity index 100% rename from minimig_config.c rename to minimig_config.cpp diff --git a/minimig_fdd.c b/minimig_fdd.cpp similarity index 100% rename from minimig_fdd.c rename to minimig_fdd.cpp diff --git a/minimig_hdd.c b/minimig_hdd.cpp similarity index 100% rename from minimig_hdd.c rename to minimig_hdd.cpp diff --git a/osd.c b/osd.cpp similarity index 92% rename from osd.c rename to osd.cpp index f9fc9b2..4deac08 100644 --- a/osd.c +++ b/osd.cpp @@ -141,7 +141,7 @@ static void rotatechar(unsigned char *in, unsigned char *out) #define OSDHEIGHT (osd_size*8) -void OsdSetTitle(char *s, int a) +void OsdSetTitle(const char *s, int a) { // Compose the title, condensing character gaps arrow = a; @@ -198,13 +198,13 @@ void OsdSetTitle(char *s, int a) } } -void OsdWrite(unsigned char n, char *s, unsigned char invert, unsigned char stipple) +void OsdWrite(unsigned char n, const char *s, unsigned char invert, unsigned char stipple) { OsdWriteOffset(n, s, invert, stipple, 0, 0); } // write a null-terminated string to the OSD buffer starting at line -void OsdWriteOffset(unsigned char n, char *s, unsigned char invert, unsigned char stipple, char offset, char leftchar) +void OsdWriteOffset(unsigned char n, const char *s, unsigned char invert, unsigned char stipple, char offset, char leftchar) { //printf("OsdWriteOffset(%d)\n", n); unsigned short i; @@ -392,7 +392,7 @@ void OsdDrawLogo(unsigned char n, char row, char superimpose) } // write a null-terminated string to the OSD buffer starting at line -void OSD_PrintText(unsigned char line, char *text, unsigned long start, unsigned long width, unsigned long offset, unsigned char invert) +void OSD_PrintText(unsigned char line, const char *text, unsigned long start, unsigned long width, unsigned long offset, unsigned char invert) { // line : OSD line number (0-7) // text : pointer to null-terminated string @@ -461,7 +461,7 @@ void OSD_PrintText(unsigned char line, char *text, unsigned long start, unsigned #define INFO_MAXW 32 #define INFO_MAXH 16 -void OSD_PrintInfo(char *message, int width, int height, int frame) +void OSD_PrintInfo(const char *message, int width, int height, int frame) { static char str[INFO_MAXW * INFO_MAXH]; diff --git a/osd.h b/osd.h index a2e2a69..fb4486c 100644 --- a/osd.h +++ b/osd.h @@ -66,9 +66,9 @@ #include /*functions*/ -void OsdSetTitle(char *s, int arrow); // arrow > 0 = display right arrow in bottom right, < 0 = display left arrow -void OsdWrite(unsigned char n, char *s, unsigned char inver, unsigned char stipple); -void OsdWriteOffset(unsigned char n, char *s, unsigned char inver, unsigned char stipple, char offset, char leftchar); // Used for scrolling "Exit" text downwards... +void OsdSetTitle(const char *s, int arrow); // arrow > 0 = display right arrow in bottom right, < 0 = display left arrow +void OsdWrite(unsigned char n, const char *s, unsigned char inver, unsigned char stipple); +void OsdWriteOffset(unsigned char n, const char *s, unsigned char inver, unsigned char stipple, char offset, char leftchar); // Used for scrolling "Exit" text downwards... void OsdClear(void); void OsdEnable(unsigned char mode); void InfoEnable(int x, int y, int width, int height); @@ -81,8 +81,8 @@ void ConfigCPU(unsigned char cpu); void ConfigChipset(unsigned char chipset); void ConfigFloppy(unsigned char drives, unsigned char speed); void ConfigAutofire(unsigned char autofire, unsigned char mask); -void OSD_PrintText(unsigned char line, char *text, unsigned long start, unsigned long width, unsigned long offset, unsigned char invert); -void OSD_PrintInfo(char *message, int width, int height, int frame); +void OSD_PrintText(unsigned char line, const char *text, unsigned long start, unsigned long width, unsigned long offset, unsigned char invert); +void OSD_PrintInfo(const char *message, int width, int height, int frame); void OsdDrawLogo(unsigned char n, char row, char superimpose); void ScrollText(char n, const char *str, int off, int len, int max_len, unsigned char invert); void ScrollReset(); diff --git a/spi.c b/spi.cpp similarity index 90% rename from spi.c rename to spi.cpp index ed2d166..9318001 100644 --- a/spi.c +++ b/spi.cpp @@ -281,7 +281,7 @@ void spi_read(uint8_t *addr, uint16_t len, int wide) } } -void spi_write(uint8_t *addr, uint16_t len, int wide) +void spi_write(const uint8_t *addr, uint16_t len, int wide) { if (wide) { @@ -301,12 +301,12 @@ void spi_block_read(uint8_t *addr, int wide) spi_read(addr, 512, wide); } -void spi_block_write(uint8_t *addr, int wide) +void spi_block_write(const uint8_t *addr, int wide) { spi_write(addr, 512, wide); } -void spi_block_write_16be(uint16_t *addr) +void spi_block_write_16be(const uint16_t *addr) { uint16_t len = 256; uint16_t tmp; diff --git a/spi.h b/spi.h index 26ff901..940bf86 100644 --- a/spi.h +++ b/spi.h @@ -34,9 +34,9 @@ uint32_t spi32w(uint32_t parm); /* block transfer functions */ void spi_block_read(uint8_t *addr, int wide); void spi_read(uint8_t *addr, uint16_t len, int wide); -void spi_block_write(uint8_t *addr, int wide); -void spi_write(uint8_t *addr, uint16_t len, int wide); -void spi_block_write_16be(uint16_t *addr); +void spi_block_write(const uint8_t *addr, int wide); +void spi_write(const uint8_t *addr, uint16_t len, int wide); +void spi_block_write_16be(const uint16_t *addr); void spi_block_read_16be(uint16_t *addr); /* OSD related SPI functions */ diff --git a/st_ikbd.c b/st_ikbd.cpp similarity index 99% rename from st_ikbd.c rename to st_ikbd.cpp index 727be1e..ab44543 100644 --- a/st_ikbd.c +++ b/st_ikbd.cpp @@ -314,11 +314,14 @@ void ikbd_handler_reset(void) { } // ---- list of supported ikbd commands ---- -struct { +struct ikbd_command_handler_t { unsigned char code; unsigned char length; void(*handler)(void); -} ikbd_command_handler[] = { +}; + +ikbd_command_handler_t ikbd_command_handler[] = +{ { 0x07, 2, ikbd_handler_mouse_button_action }, { 0x08, 1, ikbd_handler_set_relative_mouse_pos }, { 0x09, 5, ikbd_handler_set_abs_mouse_pos }, diff --git a/st_tos.c b/st_tos.cpp similarity index 93% rename from st_tos.c rename to st_tos.cpp index 73ee637..e0e8a60 100644 --- a/st_tos.c +++ b/st_tos.cpp @@ -118,7 +118,7 @@ static void mist_memory_read(char *data, unsigned long words) { DisableFpga(); } -static void mist_memory_write(char *data, unsigned long words) { +static void mist_memory_write(unsigned char *data, unsigned long words) { EnableFpga(); spi8(MIST_WRITE_MEMORY); @@ -130,7 +130,7 @@ static void mist_memory_write(char *data, unsigned long words) { DisableFpga(); } -static void mist_memory_read_block(char *data) { +static void mist_memory_read_block(unsigned char *data) { EnableFpga(); spi8(MIST_READ_MEMORY); @@ -139,7 +139,7 @@ static void mist_memory_read_block(char *data) { DisableFpga(); } -static void mist_memory_write_block(char *data) { +static void mist_memory_write_block(unsigned char *data) { EnableFpga(); spi8(MIST_WRITE_MEMORY); @@ -533,7 +533,7 @@ static void mist_get_dmastate() { #define COLORS 20 #define PLANES 4 -static void tos_write(char *str); +static void tos_write(const char *str); static void tos_color_test() { unsigned short buffer[COLORS][PLANES]; @@ -546,7 +546,7 @@ static void tos_color_test() { for (i = 0; i<16; i++) { mist_memory_set_address(VIDEO_BASE_ADDRESS + (16 * y + i) * 160, 1, 0); - mist_memory_write((char*)buffer, COLORS*PLANES); + mist_memory_write((unsigned char*)buffer, COLORS*PLANES); } } @@ -570,7 +570,7 @@ static void tos_color_test() { #endif } -static void tos_write(char *str) { +static void tos_write(const char *str) { static int y = 0; int l; @@ -584,12 +584,13 @@ static void tos_write(char *str) { // as dma works in 16 bytes chunks only int c = (strlen(str) + 15) & ~15; { - char *buffer = malloc(c); + unsigned char *buffer = (unsigned char*)malloc(c); // 16 pixel lines for (l = 0; l<16; l++) { - char *p = str, *f = buffer; + const char *p = str; + unsigned char *f = buffer; while (*p) *f++ = font[16 * *p++ + l]; while (f < buffer + c) *f++ = font[16 * ' ' + l]; @@ -645,7 +646,7 @@ static void tos_font_load() { } } -void tos_load_cartridge(char *name) +void tos_load_cartridge(const char *name) { fileTYPE file = { 0 }; @@ -655,7 +656,7 @@ void tos_load_cartridge(char *name) // upload cartridge if (config.cart_img[0] && FileOpen(&file, config.cart_img)) { int i; - char buffer[512]; + unsigned char buffer[512]; tos_debugf("%s:\n size = %d", config.cart_img, file.size); @@ -694,7 +695,7 @@ char tos_cartridge_is_inserted() { return config.cart_img[0]; } -void tos_upload(char *name) +void tos_upload(const char *name) { fileTYPE file = { 0 }; @@ -722,7 +723,7 @@ void tos_upload(char *name) // upload and verify tos image if (FileOpen(&file, config.tos_img)) { int i; - char buffer[512]; + unsigned char buffer[512]; unsigned long time; unsigned long tos_base = TOS_BASE_ADDRESS_192k; @@ -989,7 +990,7 @@ char tos_disk_is_inserted(char index) { return hdd_image[index - 2].size != 0; } -void tos_select_hdd_image(char i, char *name) +void tos_select_hdd_image(char i, const char *name) { tos_debugf("Select ACSI%c image %s", '0' + i, name); @@ -1014,7 +1015,7 @@ void tos_select_hdd_image(char i, char *name) mist_set_control(config.system_ctrl); } -void tos_insert_disk(char i, char *name) +void tos_insert_disk(char i, const char *name) { if (i > 1) { diff --git a/st_tos.h b/st_tos.h index af3673b..21691b2 100644 --- a/st_tos.h +++ b/st_tos.h @@ -82,21 +82,21 @@ unsigned long tos_system_ctrl(void); -void tos_upload(char *); +void tos_upload(const char *); void tos_poll(); void tos_update_sysctrl(unsigned long); char *tos_get_disk_name(char); char tos_disk_is_inserted(char index); -void tos_insert_disk(char i, char *name); +void tos_insert_disk(char i, const char *name); void tos_eject_all(); -void tos_select_hdd_image(char i, char *name); +void tos_select_hdd_image(char i, const char *name); void tos_set_direct_hdd(char on); char tos_get_direct_hdd(); void tos_reset(char cold); char *tos_get_image_name(); char *tos_get_cartridge_name(); char tos_cartridge_is_inserted(); -void tos_load_cartridge(char *); +void tos_load_cartridge(const char *); void tos_set_video_adjust(char axis, char value); char tos_get_video_adjust(char axis); diff --git a/tzx2wav.c b/tzx2wav.cpp similarity index 95% rename from tzx2wav.c rename to tzx2wav.cpp index 0d27fa9..2bda290 100644 --- a/tzx2wav.c +++ b/tzx2wav.cpp @@ -139,9 +139,9 @@ static char tstr4[255]; static char spdstr[255]; static char pstr[255]; -static void core_write(void *buf, int size) +static void core_write(const void *buf, int size) { - char *addr = (char*)buf; + const char *addr = (const char*)buf; while (size--) { spi8(*addr++); diff --git a/user_io.c b/user_io.cpp similarity index 93% rename from user_io.c rename to user_io.cpp index 8fcffeb..8498b31 100644 --- a/user_io.c +++ b/user_io.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "hardware.h" #include "osd.h" @@ -36,7 +37,7 @@ unsigned long vol_set_timeout = 0; fileTYPE sd_image[4] = { 0 }; // mouse and keyboard emulation state -static emu_mode_t emu_mode = EMU_NONE; +static int emu_mode = EMU_NONE; // keep state over core type and its capabilities static unsigned char core_type = CORE_TYPE_UNKNOWN; @@ -112,7 +113,7 @@ char *user_io_get_core_name() return core_name; } -char *user_io_get_core_name_ex() +const char *user_io_get_core_name_ex() { switch (user_io_core_type()) { @@ -968,67 +969,10 @@ void user_io_rtc_reset() rtc_timer = 0; } -static int api1_5 = 0; -int hasAPI1_5() -{ - return api1_5; -} - static int coldreset_req = 0; -static uint32_t vitems[32]; -double Fpix = 0; - -int adjust_video_mode(uint32_t vtime); -uint32_t show_video_info(int force) -{ - static uint8_t nres = 0; - spi_uio_cmd_cont(UIO_GET_VRES); - uint8_t res = spi_in(); - if ((nres != res) || force) - { - nres = res; - uint32_t width = spi_w(0) | (spi_w(0) << 16); - uint32_t height = spi_w(0) | (spi_w(0) << 16); - uint32_t htime = spi_w(0) | (spi_w(0) << 16); - uint32_t vtime = spi_w(0) | (spi_w(0) << 16); - uint32_t ptime = spi_w(0) | (spi_w(0) << 16); - uint32_t vtimeh = spi_w(0) | (spi_w(0) << 16); - DisableIO(); - - float vrate = 100000000; - if (vtime) vrate /= vtime; else vrate = 0; - float hrate = 100000; - if (htime) hrate /= htime; else hrate = 0; - - float prate = width * 100; - prate /= ptime; - - printf("\033[1;33mINFO: Video resolution: %u x %u, fHorz = %.1fKHz, fVert = %.1fHz, fPix = %.2fMHz\033[0m\n", width, height, hrate, vrate, prate); - printf("\033[1;33mINFO: Frame time (100MHz counter): VGA = %d, HDMI = %d\033[0m\n", vtime, vtimeh); - - if (vtimeh) api1_5 = 1; - if (hasAPI1_5() && cfg.video_info) - { - static char str[128]; - float vrateh = 100000000; - if (vtimeh) vrateh /= vtimeh; else vrateh = 0; - sprintf(str, "\n %4dx%-4d %6.2fKHz %4.1fHz" \ - "\n \x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81" \ - "\n %4dx%-4d %6.2fMHz %4.1fHz", - width, height, hrate, vrate, vitems[1], vitems[5], Fpix, vrateh); - InfoEx(str, 28, 5, cfg.video_info*1000); - } - - if (vtime && vtimeh) return vtime; - } - else - { - DisableIO(); - } - - return 0; -} +static int adjust_video_mode(uint32_t vtime); +static uint32_t show_video_info(int force); void user_io_poll() { @@ -1187,8 +1131,8 @@ void user_io_poll() } else { - static char buffer[4][512]; - static uint64_t buffer_lba[4] = { -1,-1,-1,-1 }; + static uint8_t buffer[4][512]; + static uint64_t buffer_lba[4] = { ULLONG_MAX,ULLONG_MAX,ULLONG_MAX,ULLONG_MAX }; uint32_t lba; uint16_t c = user_io_sd_get_status(&lba); //if(c&3) printf("user_io_sd_get_status: cmd=%02x, lba=%08x\n", c, lba); @@ -2020,16 +1964,18 @@ unsigned char user_io_ext_idx(char *name, char* ext) return 0; } -emu_mode_t user_io_get_kbdemu() +int user_io_get_kbdemu() { return emu_mode; } -struct +struct vmode_t { uint32_t vpar[8]; double Fpix; -} vmodes[] = +}; + +vmode_t vmodes[] = { { { 1280, 110, 40, 220, 720, 5, 5, 20 }, 74.25 }, { { 1024, 24, 136, 160, 768, 3, 6, 29 }, 65 }, @@ -2044,6 +1990,9 @@ struct }; #define VMODES_NUM (sizeof(vmodes) / sizeof(vmodes[0])) +static uint32_t vitems[32]; +double Fpix = 0; + static uint32_t getPLLdiv(uint32_t div) { if (div & 1) return 0x20000 | (((div / 2) + 1) << 8) | (div / 2); @@ -2208,7 +2157,7 @@ void parse_video_mode() setVideo(); } -int adjust_video_mode(uint32_t vtime) +static int adjust_video_mode(uint32_t vtime) { printf("Adjust VSync.\n"); @@ -2224,3 +2173,59 @@ int adjust_video_mode(uint32_t vtime) setVideo(); user_io_send_buttons(1); } + +static int api1_5 = 0; +static uint32_t show_video_info(int force) +{ + static uint8_t nres = 0; + spi_uio_cmd_cont(UIO_GET_VRES); + uint8_t res = spi_in(); + if ((nres != res) || force) + { + nres = res; + uint32_t width = spi_w(0) | (spi_w(0) << 16); + uint32_t height = spi_w(0) | (spi_w(0) << 16); + uint32_t htime = spi_w(0) | (spi_w(0) << 16); + uint32_t vtime = spi_w(0) | (spi_w(0) << 16); + uint32_t ptime = spi_w(0) | (spi_w(0) << 16); + uint32_t vtimeh = spi_w(0) | (spi_w(0) << 16); + DisableIO(); + + float vrate = 100000000; + if (vtime) vrate /= vtime; else vrate = 0; + float hrate = 100000; + if (htime) hrate /= htime; else hrate = 0; + + float prate = width * 100; + prate /= ptime; + + printf("\033[1;33mINFO: Video resolution: %u x %u, fHorz = %.1fKHz, fVert = %.1fHz, fPix = %.2fMHz\033[0m\n", width, height, hrate, vrate, prate); + printf("\033[1;33mINFO: Frame time (100MHz counter): VGA = %d, HDMI = %d\033[0m\n", vtime, vtimeh); + + if (vtimeh) api1_5 = 1; + if (hasAPI1_5() && cfg.video_info) + { + static char str[128]; + float vrateh = 100000000; + if (vtimeh) vrateh /= vtimeh; else vrateh = 0; + sprintf(str, "\n %4dx%-4d %6.2fKHz %4.1fHz" \ + "\n \x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81" \ + "\n %4dx%-4d %6.2fMHz %4.1fHz", + width, height, hrate, vrate, vitems[1], vitems[5], Fpix, vrateh); + InfoEx(str, 30, 5, cfg.video_info * 1000); + } + + if (vtime && vtimeh) return vtime; + } + else + { + DisableIO(); + } + + return 0; +} + +int hasAPI1_5() +{ + return api1_5; +} diff --git a/user_io.h b/user_io.h index b5c60d1..bf7a20d 100644 --- a/user_io.h +++ b/user_io.h @@ -83,9 +83,6 @@ #define JOY_BTN4 0x80 #define JOY_MOVE (JOY_RIGHT|JOY_LEFT|JOY_UP|JOY_DOWN) -#define BUTTON1 0x01 -#define BUTTON2 0x02 - // virtual gamepad buttons #define JOY_A JOY_BTN1 #define JOY_B JOY_BTN2 @@ -113,12 +110,15 @@ #define KBD_LED_FLAG_MASK 0xC0 #define KBD_LED_FLAG_STATUS 0x40 -#define CONF_VGA_SCALER 0x04 -#define CONF_CSYNC 0x08 -#define CONF_FORCED_SCANDOUBLER 0x10 -#define CONF_YPBPR 0x20 -#define CONF_AUDIO_96K 0x40 -#define CONF_DVI 0x80 + +#define BUTTON1 0b00000001 +#define BUTTON2 0b00000010 +#define CONF_VGA_SCALER 0b00000100 +#define CONF_CSYNC 0b00001000 +#define CONF_FORCED_SCANDOUBLER 0b00010000 +#define CONF_YPBPR 0b00100000 +#define CONF_AUDIO_96K 0b01000000 +#define CONF_DVI 0b10000000 #define CONF_RES_MASK 0x700 #define CONF_RES_SHIFT 8 @@ -146,7 +146,10 @@ #define UIO_PRIORITY_KEYBOARD 0 #define UIO_PRIORITY_GAMEPAD 1 -typedef enum { EMU_NONE, EMU_MOUSE, EMU_JOY0, EMU_JOY1 } emu_mode_t; +#define EMU_NONE 0 +#define EMU_MOUSE 1 +#define EMU_JOY0 2 +#define EMU_JOY1 3 // serial status data type returned from the core typedef struct { @@ -176,12 +179,12 @@ char user_io_dip_switch1(void); char user_io_serial_status(serial_status_t *, uint8_t); int user_io_file_mount(int num, char *name); char *user_io_get_core_name(); -char *user_io_get_core_name_ex(); +const char *user_io_get_core_name_ex(); char is_menu_core(); char is_x86_core(); char has_menu(); -emu_mode_t user_io_get_kbdemu(); +int user_io_get_kbdemu(); // io controllers interface for FPGA ethernet emulation using usb ethernet // devices attached to the io controller (ethernec emulation) diff --git a/x86.c b/x86.cpp similarity index 98% rename from x86.c rename to x86.cpp index 28fee93..828763a 100644 --- a/x86.c +++ b/x86.cpp @@ -109,7 +109,7 @@ static void dma_rcvbuf(uint32_t address, uint32_t length, uint32_t *data) DisableFpga(); } -static int load_bios(char* name, uint8_t index) +static int load_bios(const char* name, uint8_t index) { fileTYPE f = { 0 }; static uint32_t buf[128]; @@ -563,7 +563,7 @@ void x86_init() 0x00, //0x03: ALARM MIN BCD bin2bcd(tm.tm_hour), //0x04: HOUR BCD 24h 0x12, //0x05: ALARM HOUR BCD 24h - tm.tm_wday+1, //0x06: DAY OF WEEK Sunday=1 + (uint32_t)tm.tm_wday+1, //0x06: DAY OF WEEK Sunday=1 bin2bcd(tm.tm_mday), //0x07: DAY OF MONTH BCD from 1 bin2bcd(tm.tm_mon+1), //0x08: MONTH BCD from 1 bin2bcd((tm.tm_year<117) ? 17 : tm.tm_year-100), //0x09: YEAR BCD @@ -574,7 +574,7 @@ void x86_init() 0x00, //0x0E: REG E - POST status 0x00, //0x0F: REG F - shutdown status - CMOS_FDD_TYPE, //0x10: floppy drive type; 0-none, 1-360K, 2-1.2M, 3-720K, 4-1.44M, 5-2.88M + (uint32_t)CMOS_FDD_TYPE, //0x10: floppy drive type; 0-none, 1-360K, 2-1.2M, 3-720K, 4-1.44M, 5-2.88M 0x00, //0x11: configuration bits; not used 0x00, //0x12: hard disk types; 0-none, 1:E-type, F-type 16+ (unused) 0x00, //0x13: advanced configuration bits; not used