From 44bd859b04728026b0bd8c20581664d602173f72 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 17 Feb 2019 01:51:44 +0100 Subject: Added sdl testkeys as a tool again. (nw) --- scripts/src/tools.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'scripts/src/tools.lua') diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index 4073f9c7336..9ab0af409df 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -791,3 +791,40 @@ if _OPTIONS["targetos"] == "macosx" then strip() end + +-------------------------------------------------- +-- testkeys +-------------------------------------------------- + +if (_OPTIONS["osd"] == "sdl") then + project("testkeys") + uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") + kind "ConsoleApp" + + flags { + "Symbols", -- always include minimum symbols for executables + } + + if _OPTIONS["SEPARATE_BIN"]~="1" then + targetdir(MAME_DIR) + end + + links { + } + + dofile("osd/sdl_cfg.lua") + + includedirs { + } + + files { + MAME_DIR .. "src/tools/testkeys.cpp", + } + + configuration { "mingw*" or "vs*" } + targetextension ".exe" + + configuration { } + + strip() +end -- cgit v1.2.3-70-g09d2 From d72df29988fdf0a3076ca85d2f506f87ef1ffb0d Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 17 Feb 2019 12:45:16 +0100 Subject: testkeys: remove dead code, don't build on windows. (nw) --- scripts/src/tools.lua | 62 +++++++++++++++++---------------- src/tools/testkeys.cpp | 93 ++++---------------------------------------------- 2 files changed, 38 insertions(+), 117 deletions(-) (limited to 'scripts/src/tools.lua') diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index 9ab0af409df..f1f595b8719 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -796,35 +796,37 @@ end -- testkeys -------------------------------------------------- -if (_OPTIONS["osd"] == "sdl") then - project("testkeys") - uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") - kind "ConsoleApp" +if _OPTIONS["targetos"] ~= "windows" then + if (_OPTIONS["osd"] == "sdl") then + project("testkeys") + uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") + kind "ConsoleApp" + + flags { + "Symbols", -- always include minimum symbols for executables + } + + if _OPTIONS["SEPARATE_BIN"]~="1" then + targetdir(MAME_DIR) + end + + links { + } + + dofile("osd/sdl_cfg.lua") - flags { - "Symbols", -- always include minimum symbols for executables - } - - if _OPTIONS["SEPARATE_BIN"]~="1" then - targetdir(MAME_DIR) + includedirs { + } + + files { + MAME_DIR .. "src/tools/testkeys.cpp", + } + + configuration { "mingw*" or "vs*" } + targetextension ".exe" + + configuration { } + + strip() end - - links { - } - - dofile("osd/sdl_cfg.lua") - - includedirs { - } - - files { - MAME_DIR .. "src/tools/testkeys.cpp", - } - - configuration { "mingw*" or "vs*" } - targetextension ".exe" - - configuration { } - - strip() -end +end \ No newline at end of file diff --git a/src/tools/testkeys.cpp b/src/tools/testkeys.cpp index d891984cab3..473392bd421 100644 --- a/src/tools/testkeys.cpp +++ b/src/tools/testkeys.cpp @@ -25,13 +25,7 @@ struct key_lookup_table const char *name; }; -#if (SDLMAME_SDL2) #define KE(x) { SDL_SCANCODE_ ## x, "SDL_SCANCODE_" #x }, -#define KE8(A, B, C, D, E, F, G, H) KE(A) KE(B) KE(C) KE(D) KE(E) KE(F) KE(G) KE(H) -#define KE7(A, B, C, D, E, F, G) KE(A) KE(B) KE(C) KE(D) KE(E) KE(F) KE(G) -#define KE5(A, B, C, D, E) KE(A) KE(B) KE(C) KE(D) KE(E) -#define KE3(A, B, C) KE(A) KE(B) KE(C) - static key_lookup_table sdl_lookup[] = { @@ -296,46 +290,6 @@ static key_lookup_table sdl_lookup[] = {-1, ""} }; -#else -#define KE(x) { SDLK_ ## x, "SDLK_" #x }, -#define KE8(A, B, C, D, E, F, G, H) KE(A) KE(B) KE(C) KE(D) KE(E) KE(F) KE(G) KE(H) - -static key_lookup_table sdl_lookup[] = -{ - KE8(UNKNOWN, FIRST, BACKSPACE, TAB, CLEAR, RETURN, PAUSE, ESCAPE ) - KE8(SPACE, EXCLAIM, QUOTEDBL, HASH, DOLLAR, AMPERSAND, QUOTE, LEFTPAREN ) - KE8(RIGHTPAREN, ASTERISK, PLUS, COMMA, MINUS, PERIOD, SLASH, 0 ) - KE8(1, 2, 3, 4, 5, 6, 7, 8 ) - KE8(9, COLON, SEMICOLON, LESS, EQUALS, GREATER, QUESTION, AT ) - KE8(LEFTBRACKET,BACKSLASH, RIGHTBRACKET, CARET, UNDERSCORE, BACKQUOTE, a, b ) - KE8(c, d, e, f, g, h, i, j ) - KE8(k, l, m, n, o, p, q, r ) - KE8(s, t, u, v, w, x, y, z ) - KE8(DELETE, WORLD_0, WORLD_1, WORLD_2, WORLD_3, WORLD_4, WORLD_5, WORLD_6 ) - KE8(WORLD_7, WORLD_8, WORLD_9, WORLD_10, WORLD_11, WORLD_12, WORLD_13, WORLD_14 ) - KE8(WORLD_15, WORLD_16, WORLD_17, WORLD_18, WORLD_19, WORLD_20, WORLD_21, WORLD_22 ) - KE8(WORLD_23, WORLD_24, WORLD_25, WORLD_26, WORLD_27, WORLD_28, WORLD_29, WORLD_30 ) - KE8(WORLD_31, WORLD_32, WORLD_33, WORLD_34, WORLD_35, WORLD_36, WORLD_37, WORLD_38 ) - KE8(WORLD_39, WORLD_40, WORLD_41, WORLD_42, WORLD_43, WORLD_44, WORLD_45, WORLD_46 ) - KE8(WORLD_47, WORLD_48, WORLD_49, WORLD_50, WORLD_51, WORLD_52, WORLD_53, WORLD_54 ) - KE8(WORLD_55, WORLD_56, WORLD_57, WORLD_58, WORLD_59, WORLD_60, WORLD_61, WORLD_62 ) - KE8(WORLD_63, WORLD_64, WORLD_65, WORLD_66, WORLD_67, WORLD_68, WORLD_69, WORLD_70 ) - KE8(WORLD_71, WORLD_72, WORLD_73, WORLD_74, WORLD_75, WORLD_76, WORLD_77, WORLD_78 ) - KE8(WORLD_79, WORLD_80, WORLD_81, WORLD_82, WORLD_83, WORLD_84, WORLD_85, WORLD_86 ) - KE8(WORLD_87, WORLD_88, WORLD_89, WORLD_90, WORLD_91, WORLD_92, WORLD_93, WORLD_94 ) - KE8(WORLD_95, KP0, KP1, KP2, KP3, KP4, KP5, KP6 ) - KE8(KP7, KP8, KP9, KP_PERIOD, KP_DIVIDE, KP_MULTIPLY,KP_MINUS, KP_PLUS ) - KE8(KP_ENTER, KP_EQUALS, UP, DOWN, RIGHT, LEFT, INSERT, HOME ) - KE8(END, PAGEUP, PAGEDOWN, F1, F2, F3, F4, F5 ) - KE8(F6, F7, F8, F9, F10, F11, F12, F13 ) - KE8(F14, F15, NUMLOCK, CAPSLOCK, SCROLLOCK, RSHIFT, LSHIFT, RCTRL ) - KE8(LCTRL, RALT, LALT, RMETA, LMETA, LSUPER, RSUPER, MODE ) - KE8(COMPOSE, HELP, PRINT, SYSREQ, BREAK, MENU, POWER, EURO ) - KE(UNDO) - KE(LAST) - {-1, ""} -}; -#endif static const char * lookup_key_name(const key_lookup_table *kt, int kc) { @@ -357,23 +311,15 @@ int main(int argc, char *argv[]) { SDL_Event event; int quit = 0; -#if (SDLMAME_SDL2) char lasttext[20] = ""; -#else - char buf[20]; -#endif if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } -#if (SDLMAME_SDL2) SDL_CreateWindow("Input Test", 0, 0, 100, 100,0 ); -#else - SDL_SetVideoMode(100, 50, 16, SDL_ANYFORMAT); - SDL_EnableUNICODE(1); -#endif + while(SDL_PollEvent(&event) || !quit) { switch(event.type) { case SDL_QUIT: @@ -384,46 +330,19 @@ int main(int argc, char *argv[]) quit=1; else { -#if (SDLMAME_SDL2) - printf("ITEM_ID_XY %s 0x%x 0x%x %s\n", - lookup_key_name(sdl_lookup, event.key.keysym.scancode), - (int) event.key.keysym.scancode, - 0, //(int) event.key.keysym.unicode, - ""); + printf("ITEM_ID_XY %s %s\n", + lookup_key_name(sdl_lookup, event.key.keysym.scancode), ""); lasttext[0] = 0; -#else - memset(buf, 0, 19); - utf8_from_uchar(buf, sizeof(buf), event.key.keysym.unicode); - printf("ITEM_ID_XY %s 0x%x 0x%x %s\n", - lookup_key_name(sdl_lookup, event.key.keysym.sym), - (int) event.key.keysym.scancode, - (int) event.key.keysym.unicode, - buf); -#endif } break; case SDL_KEYUP: -#if (SDLMAME_SDL2) - printf("ITEM_ID_XY %s 0x%x 0x%x %s\n", - lookup_key_name(sdl_lookup, event.key.keysym.scancode), - (int) event.key.keysym.scancode, - 0, //(int) event.key.keysym.unicode, - lasttext); -#else - memset(buf, 0, 19); - utf8_from_uchar(buf, sizeof(buf), event.key.keysym.unicode); - printf("ITEM_ID_XY %s 0x%x 0x%x %s\n", - lookup_key_name(sdl_lookup, event.key.keysym.sym), - (int) event.key.keysym.scancode, - (int) event.key.keysym.unicode, - buf); -#endif + printf("ITEM_ID_XY %s %s\n", + lookup_key_name(sdl_lookup, event.key.keysym.scancode), lasttext); break; -#if (SDLMAME_SDL2) + case SDL_TEXTINPUT: strcpy(lasttext, event.text.text); break; -#endif } event.type = 0; -- cgit v1.2.3-70-g09d2 From c1ea2817618b621faf2a13415b5f3f66217c5a50 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sun, 17 Feb 2019 14:00:46 +0100 Subject: Fix testkeys compile/link on windows. (nw) --- scripts/genie.lua | 2 +- scripts/src/tools.lua | 70 ++++++++++++++++++++++++++++---------------------- src/tools/testkeys.cpp | 5 +--- 3 files changed, 42 insertions(+), 35 deletions(-) (limited to 'scripts/src/tools.lua') diff --git a/scripts/genie.lua b/scripts/genie.lua index fd09446d595..0d379308d52 100644 --- a/scripts/genie.lua +++ b/scripts/genie.lua @@ -87,7 +87,7 @@ function addprojectflags() end if version >= 60000 then buildoptions_cpp { - "-flifetime-dse=1", + --"-flifetime-dse=1", } end end diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index f1f595b8719..e1e1081a203 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -796,37 +796,47 @@ end -- testkeys -------------------------------------------------- -if _OPTIONS["targetos"] ~= "windows" then - if (_OPTIONS["osd"] == "sdl") then - project("testkeys") - uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") - kind "ConsoleApp" - - flags { - "Symbols", -- always include minimum symbols for executables - } - - if _OPTIONS["SEPARATE_BIN"]~="1" then - targetdir(MAME_DIR) - end - - links { - } - - dofile("osd/sdl_cfg.lua") +if (_OPTIONS["osd"] == "sdl") then + project("testkeys") + uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") + kind "ConsoleApp" - includedirs { + flags { + "Symbols", -- always include minimum symbols for executables + } + + if _OPTIONS["SEPARATE_BIN"]~="1" then + targetdir(MAME_DIR) + end + + if _OPTIONS["targetos"] == "macosx" then + links { + "ocore_" .. _OPTIONS["osd"], + ext_lib("utf8proc"), } - - files { - MAME_DIR .. "src/tools/testkeys.cpp", + else + links { + "SDL2", + "SDL2main", + "ocore_" .. _OPTIONS["osd"], + ext_lib("utf8proc"), } - - configuration { "mingw*" or "vs*" } - targetextension ".exe" - - configuration { } - - strip() end -end \ No newline at end of file + + dofile("osd/sdl_cfg.lua") + + includedirs { + MAME_DIR .. "src/osd", + } + + files { + MAME_DIR .. "src/tools/testkeys.cpp", + } + + configuration { "mingw*" or "vs*" } + targetextension ".exe" + + configuration { } + + strip() +end diff --git a/src/tools/testkeys.cpp b/src/tools/testkeys.cpp index 473392bd421..ce802d90685 100644 --- a/src/tools/testkeys.cpp +++ b/src/tools/testkeys.cpp @@ -16,6 +16,7 @@ #include #include "SDL2/SDL.h" +#include "osdcore.h" //#include "unicode.h" @@ -303,11 +304,7 @@ static const char * lookup_key_name(const key_lookup_table *kt, int kc) return NULL; } -#ifdef SDLMAME_WIN32 -int utf8_main(int argc, char *argv[]) -#else int main(int argc, char *argv[]) -#endif { SDL_Event event; int quit = 0; -- cgit v1.2.3-70-g09d2 From 176ba64b260e32e792f7a6381e8bcd112f1ea415 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 18 Feb 2019 14:26:10 +1100 Subject: attempt to fix testkeys linking in more configurations (nw) --- scripts/src/osd/sdl.lua | 2 +- scripts/src/tools.lua | 116 +++++++++++++++++++++++++++++++++--------------- 2 files changed, 82 insertions(+), 36 deletions(-) (limited to 'scripts/src/tools.lua') diff --git a/scripts/src/osd/sdl.lua b/scripts/src/osd/sdl.lua index f94f0f35613..28e126ecee3 100644 --- a/scripts/src/osd/sdl.lua +++ b/scripts/src/osd/sdl.lua @@ -91,11 +91,11 @@ function maintargetosdoptions(_target,_subtarget) libdirs { path.join(_OPTIONS["SDL_INSTALL_ROOT"],"lib","x64") } + configuration { } end links { "psapi", } - configuration {} elseif _OPTIONS["targetos"]=="haiku" then links { "network", diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index e1e1081a203..157cbde1e7e 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -797,46 +797,92 @@ end -------------------------------------------------- if (_OPTIONS["osd"] == "sdl") then - project("testkeys") - uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") - kind "ConsoleApp" + project("testkeys") + uuid ("b3f5a5b8-3203-11e9-93e4-670b4f4e359d") + kind "ConsoleApp" - flags { - "Symbols", -- always include minimum symbols for executables - } + flags { + "Symbols", -- always include minimum symbols for executables + } - if _OPTIONS["SEPARATE_BIN"]~="1" then - targetdir(MAME_DIR) - end + if _OPTIONS["SEPARATE_BIN"]~="1" then + targetdir(MAME_DIR) + end - if _OPTIONS["targetos"] == "macosx" then - links { - "ocore_" .. _OPTIONS["osd"], - ext_lib("utf8proc"), - } - else - links { - "SDL2", - "SDL2main", - "ocore_" .. _OPTIONS["osd"], - ext_lib("utf8proc"), - } - end + links { + "ocore_" .. _OPTIONS["osd"], + ext_lib("utf8proc"), + } + + if _OPTIONS["targetos"]=="windows" then + if _OPTIONS["with-bundled-sdl2"]~=nil then + configuration { "mingw*"} + links { + "SDL2", + "Imm32", + "Version", + "Ole32", + "OleAut32", + } + configuration { "vs*" } + links { + "SDL2", + "Imm32", + "Version", + } + configuration { } + else + if _OPTIONS["USE_LIBSDL"]~="1" then + configuration { "mingw*"} + links { + "SDL2main", + "SDL2", + } + configuration { "vs*" } + links { + "SDL2", + "Imm32", + "Version", + } + configuration { } + else + local str = backtick(sdlconfigcmd() .. " --libs | sed 's/ -lSDLmain//'") + addlibfromstring(str) + addoptionsfromstring(str) + end + configuration { "x32", "vs*" } + libdirs { + path.join(_OPTIONS["SDL_INSTALL_ROOT"],"lib","x86") + } + configuration { "x64", "vs*" } + libdirs { + path.join(_OPTIONS["SDL_INSTALL_ROOT"],"lib","x64") + } + end + end + + if BASE_TARGETOS=="unix" then + if _OPTIONS["with-bundled-sdl2"]~=nil then + links { + "SDL2", + } + end + end - dofile("osd/sdl_cfg.lua") + dofile("osd/sdl_cfg.lua") - includedirs { - MAME_DIR .. "src/osd", - } + includedirs { + MAME_DIR .. "src/osd", + } - files { - MAME_DIR .. "src/tools/testkeys.cpp", - } - - configuration { "mingw*" or "vs*" } - targetextension ".exe" - - configuration { } + files { + MAME_DIR .. "src/tools/testkeys.cpp", + } - strip() + configuration { "mingw*" or "vs*" } + targetextension ".exe" + + configuration { } + + strip() end -- cgit v1.2.3-70-g09d2 From 8ffff5d2d3bcebbdbefec2508ddd2ecd264a399a Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 18 Feb 2019 21:13:44 +1100 Subject: (nw) misc stuff: * Document cross-compilation options * Use lowercase for some libraries that are lowercase in system32 on Windows anyway * Make USE_BUNDLED_LIB_SDL2=0 not use the bundled SDL --- docs/source/initialsetup/compilingmame.rst | 35 +++++++++++++++++++++++++++--- makefile | 2 ++ scripts/src/osd/sdl.lua | 16 +++++++------- scripts/src/tools.lua | 16 +++++++------- 4 files changed, 50 insertions(+), 19 deletions(-) (limited to 'scripts/src/tools.lua') diff --git a/docs/source/initialsetup/compilingmame.rst b/docs/source/initialsetup/compilingmame.rst index 1c102f66e63..44d416d3108 100644 --- a/docs/source/initialsetup/compilingmame.rst +++ b/docs/source/initialsetup/compilingmame.rst @@ -252,15 +252,27 @@ IGNORE_GIT revision description in the version string. Tool locations -~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~ OVERRIDE_CC - Set the C/Objective-C compiler command. + Set the C/Objective-C compiler command. (This sets the target C compiler + command when cross-compiling.) OVERRIDE_CXX - Set the C++/Objective-C++ compiler command. + Set the C++/Objective-C++ compiler command. (This sets the target C++ + compiler command when cross-compiling.) +OVERRIDE_LD + Set the linker command. This is often not necessary or useful because the C + or C++ compiler command is used to invoke the linker. (This sets the target + linker command when cross-compiling.) PYTHON_EXECUTABLE Set the Python interpreter command. You need Python 2.7 or Python 3 to build MAME. +CROSS_BUILD + Set to **1** to use separate host and target compilers and linkers, as + required for cross-compilation. In this case, **OVERRIDE_CC**, + **OVERRIDE_CXX** and **OVERRIDE_LD** set the target C compiler, C++ compiler + and linker commands, while **CC**, **CXX** and **LD** set the host C + compiler, C++ compiler and linker commands. Optional features ~~~~~~~~~~~~~~~~~ @@ -439,6 +451,23 @@ variables. Unusual Build Configurations ---------------------------- +Cross-compiling MAME +~~~~~~~~~~~~~~~~~~~~ + +MAME's build system has basic support for cross-compilation. Set +**CROSS_BUILD=1** to enable separate host and target compilers, set +**OVERRIDE_CC** and **OVERRIDE_CXX** to the target C/C++ compiler commands, and +if necessary set **CC** and **CXX** to the host C/C++ compiler commands. If the +target OS is different to the host OS, set it with **TARGETOS**. For example it +may be possible to build a MinGW32 x64 build on a Linux host using a command +like this: + +**make TARGETOS=windows PTR64=1 OVERRIDE_CC=x86_64-w64-mingw32-gcc OVERRIDE_CXX=x86_64-w64-mingw32-g++ OVERRIDE_LD=x86_64-w64-mingw32-ld MINGW64=/usr** + +(The additional packages required for producing a standard MinGW32 x64 build on +a Fedora Linux host are `mingw64-gcc-c++`, `mingw64-winpthreads-static` and +their dependencies. Non-standard builds may require additional packages.) + Using libc++ on Linux ~~~~~~~~~~~~~~~~~~~~~ diff --git a/makefile b/makefile index d5dc79988f3..1895eeffcfc 100644 --- a/makefile +++ b/makefile @@ -505,8 +505,10 @@ endif # reverse logic for this one ifdef USE_BUNDLED_LIB_SDL2 +ifneq '$(USE_BUNDLED_LIB_SDL2)' '0' PARAMS += --with-bundled-sdl2 endif +endif #------------------------------------------------- # distribution may change things diff --git a/scripts/src/osd/sdl.lua b/scripts/src/osd/sdl.lua index 28e126ecee3..c9a63dcb24e 100644 --- a/scripts/src/osd/sdl.lua +++ b/scripts/src/osd/sdl.lua @@ -52,16 +52,16 @@ function maintargetosdoptions(_target,_subtarget) configuration { "mingw*"} links { "SDL2", - "Imm32", - "Version", - "Ole32", - "OleAut32", + "imm32", + "version", + "ole32", + "oleaut32", } configuration { "vs*" } links { "SDL2", - "Imm32", - "Version", + "imm32", + "version", } configuration { } else @@ -74,8 +74,8 @@ function maintargetosdoptions(_target,_subtarget) configuration { "vs*" } links { "SDL2", - "Imm32", - "Version", + "imm32", + "version", } configuration { } else diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index 157cbde1e7e..25790c257ac 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -819,16 +819,16 @@ if (_OPTIONS["osd"] == "sdl") then configuration { "mingw*"} links { "SDL2", - "Imm32", - "Version", - "Ole32", - "OleAut32", + "imm32", + "version", + "ole32", + "oleaut32", } configuration { "vs*" } links { "SDL2", - "Imm32", - "Version", + "imm32", + "version", } configuration { } else @@ -841,8 +841,8 @@ if (_OPTIONS["osd"] == "sdl") then configuration { "vs*" } links { "SDL2", - "Imm32", - "Version", + "imm32", + "version", } configuration { } else -- cgit v1.2.3-70-g09d2 From 8313f096d3d959965430bf68afcebc6e3891db80 Mon Sep 17 00:00:00 2001 From: Sergey Svishchev Date: Fri, 8 Feb 2019 01:11:01 +0300 Subject: imgtool: new read-only filesystem: DEC RT-11 (take 2) --- scripts/src/tools.lua | 1 + src/tools/imgtool/main.cpp | 2 + src/tools/imgtool/modules.cpp | 1 + src/tools/imgtool/modules/rt11.cpp | 695 +++++++++++++++++++++++++++++++++++++ 4 files changed, 699 insertions(+) create mode 100644 src/tools/imgtool/modules/rt11.cpp (limited to 'scripts/src/tools.lua') diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index 25790c257ac..f991c16bbea 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -741,6 +741,7 @@ files { MAME_DIR .. "src/tools/imgtool/modules/hp48.cpp", MAME_DIR .. "src/tools/imgtool/modules/hp9845_tape.cpp", MAME_DIR .. "src/tools/imgtool/modules/hp85_tape.cpp", + MAME_DIR .. "src/tools/imgtool/modules/rt11.cpp", } configuration { "mingw*" or "vs*" } diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp index 5c55535932e..6ed8b486825 100644 --- a/src/tools/imgtool/main.cpp +++ b/src/tools/imgtool/main.cpp @@ -287,6 +287,8 @@ static int cmd_dir(const struct command *c, int argc, char *argv[]) util::stream_format(std::wcout, L"%8i File(s) %8i bytes", total_count, total_size); if (!freespace_err) util::stream_format(std::wcout, L" %8u bytes free\n", (unsigned int)freespace); + else + util::stream_format(std::wcout, L"\n"); done: if (err) diff --git a/src/tools/imgtool/modules.cpp b/src/tools/imgtool/modules.cpp index ec2762d34fc..35b31a38be0 100644 --- a/src/tools/imgtool/modules.cpp +++ b/src/tools/imgtool/modules.cpp @@ -103,5 +103,6 @@ MODULE(bml3) MODULE(hp48) MODULE(hp9845_tape) MODULE(hp85_tape) +MODULE(rt11) #endif /* MODULES_RECURSIVE */ diff --git a/src/tools/imgtool/modules/rt11.cpp b/src/tools/imgtool/modules/rt11.cpp new file mode 100644 index 00000000000..3cce60a050f --- /dev/null +++ b/src/tools/imgtool/modules/rt11.cpp @@ -0,0 +1,695 @@ +// license:BSD-3-Clause +// copyright-holders:Sergey Svishchev +/**************************************************************************** + + rt11.cpp + + DEC RT-11 disk images + + References: + + VaFFM -- bitsavers://pdf/dec/pdp11/rt11/v5.6_Aug91/AA-PD6PA-TC_RT-11_Volume_and_File_Formats_Manual_Aug91.pdf + DHM -- bitsavers://pdf/dec/pdp11/rt11/v5.6_Aug91/AA-PE7VA-TC_RT-11_Device_Handlers_Manual_Aug91.pdf + SSM -- bitsavers://pdf/dec/pdp11/rt11/v5.0_Mar83/AA-H379B-TC_5.0_SWsuppMar83.pdf + TSX+ -- bitsavers://pdf/dec/pdp11/tsxPlus/manuals_6.31/TSX-Plus_UsersRef_Jan88.pdf + PUTR -- http://www.dbit.com/pub/putr/putr.asm + + To do: + - filter for text files + - read-write support + - report empty 'last modified' time if date field is all zeros + - report free space + - arbitrary sized images + - don't crash when strings in home block have non-ascii chars (charconverter does not apply) + - do something about bootblock bug in imgtool (commit aca90520) + + LBN Contents + --- -------- + 0 Reserved (primary bootstrap) + 1 Reserved (home block) + 2-5 Reserved (secondary bootstrap) + 6-7 Directory segment 1 + ... Directory segment 2-n + ... Data + + Home block + ---------- + 000-201 Bad block replacement table + 202-203 ? + 204-251 INITIALIZE/RESTORE data area + 252-273 BUP information area + 274-677 ? + 700-701 (Reserved for Digital, must be zero) + 702-703 (Reserved for Digital, must be zero) + 704-721 ? + 722-723 Pack cluster size (= 1) + 724-725 Block number of first directory segment + 726-727 System version (RAD50) + 730-742 Volume Identification + 744-757 Owner name + 760-773 System Identification + 776-777 Checksum + + Directory segment header + ------------------------ + 0 The total number of segments in this directory. + 1 The segment number of the next logical directory segment. If this word is 0, there are no more segments in the list. + 2 The number of the highest segment currently in use. Valid only in the first directory segment. + 3 The number of extra bytes per directory entry, always an unsigned, even octal number. + 4 The block number on the volume where the actual stored data identified by this segment begins. + + Directory entry + --------------- + 0 Status word + 1 File name 1-3 (RAD50) + 2 File name 4-6 (RAD50) + 3 File type 1-3 (RAD50) + 4 Total file length (blocks) + 5 Job#, Channel# (RT-11 uses this information only for tentative files) + 6 Creation date + 7- Optional extra words + +****************************************************************************/ + +#include "imgtool.h" +#include "formats/imageutl.h" +#include "iflopimg.h" + +#include +#include +#include + + +namespace +{ + struct rt11_diskinfo + { + uint16_t directory_start; + uint16_t total_segments; + uint16_t last_segment; + uint16_t dirent_size; + int dirents_per_block; + // autodetected + int tracks; + int heads; + int sectors; + uint32_t sector_size; + // cache + int map[16]; + int cached_track; + int cached_head; + }; + + enum misc_t + { + HOME_BLOCK = 1, + BLOCK_SIZE = 512 + }; + + struct rt11_direnum + { + uint8_t segment_data[2 * BLOCK_SIZE]; + uint16_t segment; + uint16_t index; + uint16_t data; + }; + + struct rt11_dirent + { + uint16_t status; + uint16_t filename[3]; + uint16_t time; + // synthetic + uint64_t filesize; + uint16_t data; + }; + + enum rt11_status + { + E_PRE = 0000020, + E_TENT = 0000400, + E_MPTY = 0001000, + E_PERM = 0002000, + E_EOS = 0004000, + E_READ = 0040000, + E_PROT = 0100000 + }; + + enum creation_policy_t + { + CREATE_NONE, + CREATE_FILE, + }; + + + util::arbitrary_datetime _rt11_crack_time(uint16_t rt11_time) + { + util::arbitrary_datetime dt; + + dt.second = 0; + dt.minute = 0; + dt.hour = 0; + dt.day_of_month = (rt11_time >> 5) & 31; + dt.month = (rt11_time >> 10) & 15; + dt.year = 1972 + (rt11_time & 31) + 32 * ((rt11_time >> 14) & 3); + + return dt; + } + + imgtool::datetime rt11_crack_time(uint16_t rt11_time) + { + util::arbitrary_datetime dt; + imgtool::datetime it; + + if (rt11_time == 0) + { + return imgtool::datetime(imgtool::datetime::datetime_type::NONE, dt); + } + + dt = _rt11_crack_time(rt11_time); + + it = imgtool::datetime(imgtool::datetime::datetime_type::LOCAL, dt); + + return it; + } + + void rt11_from_rad50(char *ascii, uint16_t *rad50, int num) + { + const char rad[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.%0123456789:"; + + for (int i = 0, j = 0; i < num; i++) + { + ascii[j++] = rad[ rad50[i] / (050 * 050)]; + ascii[j++] = rad[(rad50[i] / 050) % 050]; + ascii[j++] = rad[ rad50[i] % 050]; + } + } + + void rt11_filename_from_rad50(char *ascii, uint16_t *rad50) + { + int i, j; + + rt11_from_rad50(&ascii[0], &rad50[0], 2); + for (i = 0; i < 6; i++) + { + if (ascii[i] == ' ') break; + } + ascii[i++] = '.'; + rt11_from_rad50(&ascii[i], &rad50[2], 1); + for (j = i; j < i + 3; j++) + { + if (ascii[j] == ' ') break; + } + ascii[j] = '\0'; + } + + int is_file_storagetype(uint16_t status) + { + return !(status & (E_MPTY | E_EOS | E_TENT)); + } + + rt11_diskinfo *get_rt11_info(imgtool::image &image) + { + return (rt11_diskinfo *)imgtool_floppy_extrabytes(image); + } +} + + +static imgtoolerr_t rt11_image_get_geometry(imgtool::image &image, uint32_t *tracks, uint32_t *heads, uint32_t *sectors) +{ + const rt11_diskinfo *di = get_rt11_info(image); + + *sectors = di->sectors; + *heads = di->heads; + *tracks = di->tracks; + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_get_sector_position(imgtool::image &image, uint32_t sector_index, + uint32_t &head, uint32_t &track, uint32_t §or) +{ + imgtoolerr_t err; + rt11_diskinfo *di = get_rt11_info(image); + uint32_t tracks, heads, sectors; + + err = image.get_geometry(&tracks, &heads, §ors); + if (err) + return err; + + track = sector_index / sectors / heads; + head = (sector_index / sectors) % heads; + + // map 1-based sector numbers, possibly interleaved, to sector indexes + if (track != di->cached_track || head != di->cached_head) + { + memset(di->map, -1, sizeof(di->map)); + for (int i = 0; i < 256; i++) + { + int sector_id; + + if (floppy_get_indexed_sector_info(imgtool_floppy(image), head, track, i, NULL, NULL, §or_id, NULL, NULL)) + continue; + + if (sector_id > 0 && sector_id <= sectors) + di->map[sector_id - 1] = i; + } + di->cached_track = track; + di->cached_head = head; + } + + if (di->map[(sector_index % sectors)] < 0) + { + return IMGTOOLERR_SEEKERROR; + } + else + { + sector = di->map[(sector_index % sectors)]; + return IMGTOOLERR_SUCCESS; + } +} + + +static imgtoolerr_t rt11_image_readblock(imgtool::image &image, void *buffer, uint64_t block) +{ + imgtoolerr_t err; + floperr_t ferr; + const rt11_diskinfo *di = get_rt11_info(image); + uint32_t track, head, sector; + unsigned long flags; + + if (di->sector_size == 256) + { + err = rt11_get_sector_position(image, block * 2, head, track, sector); + if (err) + return err; + + ferr = floppy_read_indexed_sector(imgtool_floppy(image), head, track, sector, 0, buffer, 256); + if (ferr) + return imgtool_floppy_error(ferr); + + ferr = floppy_get_indexed_sector_info(imgtool_floppy(image), head, track, sector, NULL, NULL, NULL, NULL, &flags); + if (ferr) + return imgtool_floppy_error(ferr); + + if (flags) + return IMGTOOLERR_READERROR; + + err = rt11_get_sector_position(image, (block * 2) + 1, head, track, sector); + if (err) + return err; + + ferr = floppy_read_indexed_sector(imgtool_floppy(image), head, track, sector, 0, ((uint8_t *) buffer) + 256, 256); + if (ferr) + return imgtool_floppy_error(ferr); + + ferr = floppy_get_indexed_sector_info(imgtool_floppy(image), head, track, sector, NULL, NULL, NULL, NULL, &flags); + if (ferr) + return imgtool_floppy_error(ferr); + + if (flags) + return IMGTOOLERR_READERROR; + } + else + { + err = rt11_get_sector_position(image, block, head, track, sector); + if (err) + return err; + + ferr = floppy_read_indexed_sector(imgtool_floppy(image), head, track, sector, 0, buffer, BLOCK_SIZE); + if (ferr) + return imgtool_floppy_error(ferr); + + ferr = floppy_get_indexed_sector_info(imgtool_floppy(image), head, track, sector, NULL, NULL, NULL, NULL, &flags); + if (ferr) + return imgtool_floppy_error(ferr); + + if (flags) + return IMGTOOLERR_READERROR; + } + + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_probe_geometry(imgtool::image &image) +{ + floperr_t ferr; + rt11_diskinfo *di = get_rt11_info(image); + + // MX (11x256 byte sectors) or MY (10x512 byte sectors)? + ferr = floppy_get_indexed_sector_info(imgtool_floppy(image), 0, 0, 0, NULL, NULL, NULL, &di->sector_size, NULL); + if (ferr) + return imgtool_floppy_error(ferr); + + if (di->sector_size == 256) + di->sectors = 11; + else + di->sectors = 10; + + // double- or single-sided? + ferr = floppy_get_indexed_sector_info(imgtool_floppy(image), 1, 0, 0, NULL, NULL, NULL, NULL, NULL); + if (ferr) + di->heads = 1; + else + di->heads = 2; + + // 80 or 40 tracks? + ferr = floppy_get_indexed_sector_info(imgtool_floppy(image), 0, 50, 0, NULL, NULL, NULL, NULL, NULL); + if (ferr) + di->tracks = 40; + else + di->tracks = 80; + + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_image_open(imgtool::image &image, imgtool::stream::ptr &&dummy) +{ + imgtoolerr_t err; + uint8_t buffer[BLOCK_SIZE]; + rt11_diskinfo *di = get_rt11_info(image); + + di->cached_head = -1; + di->cached_track = -1; + memset(di->map, -1, sizeof(di->map)); + // dummy values for rt11_image_readblock + di->tracks = 40; + di->heads = 1; + + err = rt11_probe_geometry(image); + if (err) + return err; + + /* load home block */ + err = rt11_image_readblock(image, buffer, HOME_BLOCK); + if (err) + return err; + + di->directory_start = pick_integer_le(buffer, 0724, 2); + + // real-world images seem to never have a valid checksum, but directory_start is always 6 +#if 0 + uint16_t tmp, cksum; + + tmp = 0; + cksum = pick_integer_le(buffer, 0776, 2); + for (int i = 0; i < 510; i+=2) + { + tmp += pick_integer_le(buffer, i, 2); + } + + /* sanity check these values */ + if (cksum != tmp) + { + fprintf(stderr, "cksum stored:computed %04x:%04x\n", cksum, tmp); + return IMGTOOLERR_CORRUPTIMAGE; + } +#endif + if (di->directory_start != 6) + { + return IMGTOOLERR_CORRUPTIMAGE; + } + + /* load first directory segment */ + err = rt11_image_readblock(image, buffer, di->directory_start); + if (err) + return err; + + di->total_segments = pick_integer_le(buffer, 0, 2); + di->last_segment = pick_integer_le(buffer, 4, 2); + di->dirent_size = (pick_integer_le(buffer, 6, 2) + 7) * 2; + di->dirents_per_block = (2 * BLOCK_SIZE - 10) / di->dirent_size; + + return IMGTOOLERR_SUCCESS; +} + +static void rt11_image_info(imgtool::image &image, std::ostream &stream) +{ + uint8_t buffer[BLOCK_SIZE]; + char system[4]; + char vid[13], oid[13], sid[13]; + + rt11_image_readblock(image, buffer, HOME_BLOCK); + rt11_from_rad50(system, (uint16_t *)&buffer[0726], 1); + system[3] = '\0'; + + memcpy(vid, &buffer[0730], 12); + memcpy(oid, &buffer[0744], 12); + memcpy(sid, &buffer[0760], 12); + vid[12] = '\0'; + oid[12] = '\0'; + sid[12] = '\0'; + + stream << "System version: '" << system << "', System ID: '" << sid << "', Volume ID: '" << vid << "', Owner: '" << oid << "'"; +} + +// directory operations + +static imgtoolerr_t rt11_enum_seek(imgtool::image &image, + rt11_direnum *rt11enum, uint16_t segment, uint16_t index) +{ + const rt11_diskinfo *di = get_rt11_info(image); + imgtoolerr_t err; + uint8_t buffer[BLOCK_SIZE]; + + if (rt11enum->segment != segment) + { + if (segment != 0) + { + err = rt11_image_readblock(image, buffer, di->directory_start + (segment - 1) * 2); + if (err) + return err; + memcpy(rt11enum->segment_data, buffer, sizeof(buffer)); + + err = rt11_image_readblock(image, buffer, di->directory_start + (segment - 1) * 2 + 1); + if (err) + return err; + memcpy(&rt11enum->segment_data[BLOCK_SIZE], buffer, sizeof(buffer)); + + rt11enum->data = pick_integer_le(rt11enum->segment_data, 8, 2); + } + rt11enum->segment = segment; + } + + rt11enum->index = index; + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_get_next_dirent(imgtool::image &image, + rt11_direnum *rt11enum, rt11_dirent &rt_ent) +{ + imgtoolerr_t err; + const rt11_diskinfo *di = get_rt11_info(image); + uint32_t next_segment, next_index; + uint32_t offset; + + memset(&rt_ent, 0, sizeof(rt_ent)); + + /* have we hit the end of the file? */ + if (rt11enum->segment == 0) + return IMGTOOLERR_SUCCESS; + + /* populate the resulting dirent */ + offset = (rt11enum->index * di->dirent_size) + 10; + rt_ent.status = pick_integer_le(rt11enum->segment_data, offset, 2); + memcpy(rt_ent.filename, &rt11enum->segment_data[offset + 2], 6); + rt_ent.filesize = pick_integer_le(rt11enum->segment_data, offset + 8, 2) * BLOCK_SIZE; + rt_ent.data = rt11enum->data; + rt_ent.time = pick_integer_le(rt11enum->segment_data, offset + 12, 2); + rt11enum->data += pick_integer_le(rt11enum->segment_data, offset + 8, 2); + + /* identify next entry */ + next_segment = rt11enum->segment; + next_index = rt11enum->index + 1; + if (next_index >= di->dirents_per_block || (rt_ent.status & E_EOS)) + { + next_segment = pick_integer_le(rt11enum->segment_data, 2, 2); + next_index = 0; + } + + if (next_segment > di->total_segments || next_segment > di->last_segment) + return IMGTOOLERR_CORRUPTIMAGE; + + /* seek next segment */ + err = rt11_enum_seek(image, rt11enum, next_segment, next_index); + if (err) + return err; + + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_image_beginenum(imgtool::directory &enumeration, const char *path) +{ + imgtoolerr_t err; + imgtool::image &image(enumeration.image()); + + /* seek initial block */ + err = rt11_enum_seek(image, (rt11_direnum *) enumeration.extra_bytes(), 1, 0); + if (err) + return err; + + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_image_nextenum(imgtool::directory &enumeration, imgtool_dirent &ent) +{ + imgtoolerr_t err; + imgtool::image &image(enumeration.image()); + rt11_direnum *rt11enum = (rt11_direnum *)enumeration.extra_bytes(); + rt11_dirent rt_ent; + + do + { + err = rt11_get_next_dirent(image, rt11enum, rt_ent); + if (err) + return err; + } + while (rt11enum->segment && !is_file_storagetype(rt_ent.status)); + + /* end of file? */ + if (rt11enum->segment == 0) + { + ent.eof = 1; + return IMGTOOLERR_SUCCESS; + } + + ent.directory = 0; + ent.lastmodified_time = rt11_crack_time(rt_ent.time); + ent.filesize = rt_ent.filesize; + + rt11_filename_from_rad50(ent.filename, rt_ent.filename); + + snprintf(ent.attr, sizeof(ent.attr), "%c%c%c %4d %06o", + rt_ent.status & E_PROT ? 'P' : '.', + rt_ent.time == 0 ? 'B' : '.', + rt_ent.status & E_TENT ? 'T' : '.', + rt_ent.data, rt_ent.status); + + return IMGTOOLERR_SUCCESS; +} + +// file operations + +static imgtoolerr_t rt11_lookup_path(imgtool::image &image, const char *path, + creation_policy_t create, rt11_direnum *direnum, rt11_dirent *rt_ent) +{ + imgtoolerr_t err; + rt11_direnum my_direnum; + uint16_t this_segment; + uint32_t this_index; + char filename[16]; + + if (!direnum) + direnum = &my_direnum; + + memset(direnum, 0, sizeof(*direnum)); + err = rt11_enum_seek(image, direnum, 1, 0); + if (err) + goto done; + + do + { + this_segment = direnum->segment; + this_index = direnum->index; + + err = rt11_get_next_dirent(image, direnum, *rt_ent); + if (err) + goto done; + rt11_filename_from_rad50(filename, rt_ent->filename); + } + while(direnum->segment && (strcmp(path, filename) || + !is_file_storagetype(rt_ent->status))); + + if (!direnum->segment) + { + /* did not find file; maybe we need to create it */ + if (create == CREATE_NONE) + { + err = IMGTOOLERR_FILENOTFOUND; + goto done; + } + } + else + { + /* we've found the file; seek that dirent */ + err = rt11_enum_seek(image, direnum, this_segment, this_index); + if (err) + goto done; + } + + err = IMGTOOLERR_SUCCESS; +done: + return err; +} + +static imgtoolerr_t rt11_read_bootblock(imgtool::partition &partition, imgtool::stream &stream) +{ + imgtoolerr_t err; + uint8_t block[BLOCK_SIZE]; + + err = rt11_image_readblock(partition.image(), block, 0); + if (err) + return err; + + stream.write(block, sizeof(block)); + return IMGTOOLERR_SUCCESS; +} + +static imgtoolerr_t rt11_image_readfile(imgtool::partition &partition, const char *filename, const char *fork, imgtool::stream &destf) +{ + imgtoolerr_t err; + imgtool::image &image(partition.image()); + rt11_dirent rt_ent; + uint8_t buffer[BLOCK_SIZE]; + + if (filename == FILENAME_BOOTBLOCK) + return rt11_read_bootblock(partition, destf); + + err = rt11_lookup_path(image, filename, CREATE_NONE, NULL, &rt_ent); + if (err) + return err; + + for (uint16_t i = rt_ent.data; i < rt_ent.data + (rt_ent.filesize / BLOCK_SIZE); i++) + { + err = rt11_image_readblock(image, buffer, i); + if (err) + return err; + + destf.write(buffer, BLOCK_SIZE); + } + + return IMGTOOLERR_SUCCESS; +} + + +void rt11_get_info(const imgtool_class *imgclass, uint32_t state, union imgtoolinfo *info) +{ + switch (state) + { + /* --- the following bits of info are returned as 64-bit signed integers --- */ + case IMGTOOLINFO_INT_PREFER_UCASE: info->i = 1; break; + case IMGTOOLINFO_INT_OPEN_IS_STRICT: info->i = 1; break; + case IMGTOOLINFO_INT_SUPPORTS_LASTMODIFIED_TIME: info->i = 1; break; + case IMGTOOLINFO_INT_SUPPORTS_BOOTBLOCK: info->i = 1; break; + case IMGTOOLINFO_INT_BLOCK_SIZE: info->i = BLOCK_SIZE; break; + case IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES: info->i = sizeof(rt11_diskinfo); break; + case IMGTOOLINFO_INT_DIRECTORY_EXTRA_BYTES: info->i = sizeof(rt11_direnum); break; + + /* --- the following bits of info are returned as NULL-terminated strings --- */ + case IMGTOOLINFO_STR_NAME: strcpy(info->s = imgtool_temp_str(), "rt11"); break; + case IMGTOOLINFO_STR_DESCRIPTION: strcpy(info->s = imgtool_temp_str(), "RT11 format"); break; + case IMGTOOLINFO_STR_FILE: strcpy(info->s = imgtool_temp_str(), __FILE__); break; + case IMGTOOLINFO_STR_EOLN: strcpy(info->s = imgtool_temp_str(), EOLN_CRLF); break; + + /* --- the following bits of info are returned as pointers to data or functions --- */ + case IMGTOOLINFO_PTR_INFO: info->info = rt11_image_info; break; + case IMGTOOLINFO_PTR_MAKE_CLASS: info->make_class = imgtool_floppy_make_class; break; + case IMGTOOLINFO_PTR_GET_GEOMETRY: info->get_geometry = rt11_image_get_geometry; break; + case IMGTOOLINFO_PTR_READ_BLOCK: info->read_block = rt11_image_readblock; break; + case IMGTOOLINFO_PTR_BEGIN_ENUM: info->begin_enum = rt11_image_beginenum; break; + case IMGTOOLINFO_PTR_NEXT_ENUM: info->next_enum = rt11_image_nextenum; break; + case IMGTOOLINFO_PTR_READ_FILE: info->read_file = rt11_image_readfile; break; + + case IMGTOOLINFO_PTR_FLOPPY_OPEN: info->open = rt11_image_open; break; + case IMGTOOLINFO_PTR_FLOPPY_FORMAT: info->p = (void *) floppyoptions_default; break; + } +} -- cgit v1.2.3-70-g09d2 From 672f9b092a0a93048e8db600a9dce86f29f465d3 Mon Sep 17 00:00:00 2001 From: couriersud Date: Sat, 23 Feb 2019 17:45:08 +0100 Subject: Move ptime struct into plib namespace and fix relative includes. (nw) --- scripts/src/netlist.lua | 6 +- scripts/src/tools.lua | 2 + src/devices/machine/netlist.h | 3 +- src/lib/netlist/analog/nlid_fourterm.h | 2 +- src/lib/netlist/analog/nlid_twoterm.h | 2 +- src/lib/netlist/build/makefile | 2 +- src/lib/netlist/devices/nld_log.cpp | 4 +- src/lib/netlist/devices/nlid_system.h | 2 +- src/lib/netlist/devices/nlid_truthtable.cpp | 4 +- src/lib/netlist/devices/nlid_truthtable.h | 2 +- src/lib/netlist/netlist_types.h | 114 ------------------- src/lib/netlist/nl_base.h | 4 +- src/lib/netlist/nl_factory.h | 2 +- src/lib/netlist/nl_lists.h | 2 +- src/lib/netlist/nl_setup.h | 2 +- src/lib/netlist/nl_time.h | 159 --------------------------- src/lib/netlist/nl_types.h | 140 +++++++++++++++++++++++ src/lib/netlist/plib/ptime.h | 136 +++++++++++++++++++++++ src/lib/netlist/prg/nlwav.cpp | 10 +- src/lib/netlist/solver/nld_matrix_solver.cpp | 2 +- src/lib/netlist/solver/nld_ms_direct.h | 4 +- src/lib/netlist/solver/nld_ms_gcr.h | 11 +- src/lib/netlist/solver/nld_ms_gmres.h | 8 +- src/lib/netlist/solver/nld_ms_sm.h | 2 +- src/lib/netlist/solver/nld_ms_w.h | 2 +- src/lib/netlist/solver/nld_solver.cpp | 2 +- src/lib/netlist/solver/nld_solver.h | 2 +- src/lib/netlist/tools/nl_convert.cpp | 4 +- src/lib/netlist/tools/nl_convert.h | 8 +- 29 files changed, 324 insertions(+), 319 deletions(-) delete mode 100644 src/lib/netlist/netlist_types.h delete mode 100644 src/lib/netlist/nl_time.h create mode 100644 src/lib/netlist/nl_types.h create mode 100644 src/lib/netlist/plib/ptime.h (limited to 'scripts/src/tools.lua') diff --git a/scripts/src/netlist.lua b/scripts/src/netlist.lua index 5e6d239373e..09575cacffc 100644 --- a/scripts/src/netlist.lua +++ b/scripts/src/netlist.lua @@ -32,6 +32,7 @@ project "netlist" includedirs { MAME_DIR .. "src/lib", + MAME_DIR .. "src/lib/netlist", } files { @@ -47,7 +48,7 @@ project "netlist" MAME_DIR .. "src/lib/netlist/nl_parser.h", MAME_DIR .. "src/lib/netlist/nl_setup.cpp", MAME_DIR .. "src/lib/netlist/nl_setup.h", - MAME_DIR .. "src/lib/netlist/nl_time.h", + MAME_DIR .. "src/lib/netlist/nl_types.h", MAME_DIR .. "src/lib/netlist/plib/pconfig.h", MAME_DIR .. "src/lib/netlist/plib/palloc.h", MAME_DIR .. "src/lib/netlist/plib/pchrono.cpp", @@ -74,10 +75,9 @@ project "netlist" MAME_DIR .. "src/lib/netlist/plib/pstate.h", MAME_DIR .. "src/lib/netlist/plib/pstring.cpp", MAME_DIR .. "src/lib/netlist/plib/pstring.h", - MAME_DIR .. "src/lib/netlist/plib/pstring.cpp", - MAME_DIR .. "src/lib/netlist/plib/pstring.h", MAME_DIR .. "src/lib/netlist/plib/pstream.cpp", MAME_DIR .. "src/lib/netlist/plib/pstream.h", + MAME_DIR .. "src/lib/netlist/plib/ptime.h", MAME_DIR .. "src/lib/netlist/plib/ptypes.h", MAME_DIR .. "src/lib/netlist/plib/putil.cpp", MAME_DIR .. "src/lib/netlist/plib/putil.h", diff --git a/scripts/src/tools.lua b/scripts/src/tools.lua index f991c16bbea..564653f5a4a 100644 --- a/scripts/src/tools.lua +++ b/scripts/src/tools.lua @@ -499,6 +499,7 @@ links { includedirs { MAME_DIR .. "src/lib", + MAME_DIR .. "src/lib/netlist", } files { @@ -543,6 +544,7 @@ links { includedirs { MAME_DIR .. "src/lib", + MAME_DIR .. "src/lib/netlist", } files { diff --git a/src/devices/machine/netlist.h b/src/devices/machine/netlist.h index 182c77ece2c..58a8c065b14 100644 --- a/src/devices/machine/netlist.h +++ b/src/devices/machine/netlist.h @@ -13,8 +13,7 @@ #include -#include "netlist/nl_time.h" -#include "netlist/netlist_types.h" +#include "../../lib/netlist/nl_types.h" class nld_sound_out; class nld_sound_in; diff --git a/src/lib/netlist/analog/nlid_fourterm.h b/src/lib/netlist/analog/nlid_fourterm.h index 2d0d1ec174f..9eb2fbc5f36 100644 --- a/src/lib/netlist/analog/nlid_fourterm.h +++ b/src/lib/netlist/analog/nlid_fourterm.h @@ -9,7 +9,7 @@ #define NLID_FOURTERM_H_ #include "../nl_base.h" -#include "../plib/putil.h" +#include "plib/putil.h" namespace netlist { namespace analog { diff --git a/src/lib/netlist/analog/nlid_twoterm.h b/src/lib/netlist/analog/nlid_twoterm.h index 546e8193734..131504d86e4 100644 --- a/src/lib/netlist/analog/nlid_twoterm.h +++ b/src/lib/netlist/analog/nlid_twoterm.h @@ -33,7 +33,7 @@ #ifndef NLID_TWOTERM_H_ #define NLID_TWOTERM_H_ -#include "../plib/pfunction.h" +#include "plib/pfunction.h" #include "netlist/nl_base.h" #include "netlist/nl_setup.h" diff --git a/src/lib/netlist/build/makefile b/src/lib/netlist/build/makefile index d4296c1b007..f628e9eaed6 100644 --- a/src/lib/netlist/build/makefile +++ b/src/lib/netlist/build/makefile @@ -49,7 +49,7 @@ endif # LTO = -flto=4 -fuse-linker-plugin -flto-partition=balanced -Wodr -CFLAGS = $(LTO) -g -O3 -std=c++11 -I../.. $(CEXTRAFLAGS) +CFLAGS = $(LTO) -g -O3 -std=c++11 -I$(CURDIR)/.. -I$(CURDIR)/../.. $(CEXTRAFLAGS) LDFLAGS = $(LTO) -g -O3 -std=c++11 $(LDEXTRAFLAGS) LIBS = -lpthread -ldl diff --git a/src/lib/netlist/devices/nld_log.cpp b/src/lib/netlist/devices/nld_log.cpp index c99fcb5a9bc..8cbcf0c81ca 100644 --- a/src/lib/netlist/devices/nld_log.cpp +++ b/src/lib/netlist/devices/nld_log.cpp @@ -6,8 +6,8 @@ */ #include "../nl_base.h" -#include "../plib/pfmtlog.h" -#include "../plib/pstream.h" +#include "plib/pfmtlog.h" +#include "plib/pstream.h" #include "nld_log.h" //#include "sound/wavwrite.h" diff --git a/src/lib/netlist/devices/nlid_system.h b/src/lib/netlist/devices/nlid_system.h index 10cbc498a6b..e744ee11dc6 100644 --- a/src/lib/netlist/devices/nlid_system.h +++ b/src/lib/netlist/devices/nlid_system.h @@ -14,7 +14,7 @@ #include "../analog/nlid_twoterm.h" #include "../nl_base.h" #include "../nl_setup.h" -#include "../plib/putil.h" +#include "plib/putil.h" namespace netlist { diff --git a/src/lib/netlist/devices/nlid_truthtable.cpp b/src/lib/netlist/devices/nlid_truthtable.cpp index 78fd076b560..e1a6f5e9046 100644 --- a/src/lib/netlist/devices/nlid_truthtable.cpp +++ b/src/lib/netlist/devices/nlid_truthtable.cpp @@ -7,8 +7,8 @@ #include "nlid_truthtable.h" #include "../nl_setup.h" -#include "../plib/palloc.h" -#include "../plib/plists.h" +#include "plib/palloc.h" +#include "plib/plists.h" #include diff --git a/src/lib/netlist/devices/nlid_truthtable.h b/src/lib/netlist/devices/nlid_truthtable.h index a4b9e1e238e..c995b1c766e 100644 --- a/src/lib/netlist/devices/nlid_truthtable.h +++ b/src/lib/netlist/devices/nlid_truthtable.h @@ -12,7 +12,7 @@ #include "../nl_base.h" #include "../nl_setup.h" -#include "../plib/putil.h" +#include "plib/putil.h" #define NETLIB_TRUTHTABLE(cname, nIN, nOUT) \ class NETLIB_NAME(cname) : public nld_truthtable_t \ diff --git a/src/lib/netlist/netlist_types.h b/src/lib/netlist/netlist_types.h deleted file mode 100644 index b2a507fe0fe..00000000000 --- a/src/lib/netlist/netlist_types.h +++ /dev/null @@ -1,114 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/*! - * - * \file netlist_types.h - * - */ - -#ifndef NETLIST_TYPES_H_ -#define NETLIST_TYPES_H_ - -#include -#include - -#include "nl_config.h" -#include "plib/pchrono.h" -#include "plib/pfmtlog.h" -#include "plib/pmempool.h" -#include "plib/pstring.h" - - -namespace netlist -{ - /*! @brief netlist_sig_t is the type used for logic signals. - * - * This may be any of bool, uint8_t, uint16_t, uin32_t and uint64_t. - * The choice has little to no impact on performance. - */ - using netlist_sig_t = std::uint32_t; - - /* FIXME: belongs into nl_base.h to nlstate */ - /** - * @brief Interface definition for netlist callbacks into calling code - * - * A class inheriting from netlist_callbacks_t has to be passed to the netlist_t - * constructor. Netlist does processing during construction and thus needs - * the object passed completely constructed. - * - */ - class callbacks_t - { - public: - - callbacks_t() = default; - /* what is done before this is passed as a unique_ptr to netlist - * we should not limit. - */ - virtual ~callbacks_t() = default; - COPYASSIGNMOVE(callbacks_t, default) - - /* logging callback */ - virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0; - - }; - - using log_type = plib::plog_base; - - - //============================================================ - // Performance tracking - //============================================================ - - template - using nperftime_t = plib::chrono::timer; - - template - using nperfcount_t = plib::chrono::counter; - - //============================================================ - // Types needed by various includes - //============================================================ - - /*! The memory pool for netlist objects - * - * \note This is not the right location yet. - * - */ - -#if (USE_MEMPOOL) - using nlmempool = plib::mempool; -#else - using nlmempool = plib::mempool_default; -#endif - - /*! Owned pointer type for pooled allocations. - * - */ - template - using poolptr = nlmempool::poolptr; - - inline nlmempool &pool() - { - static nlmempool static_pool(655360, 16); - return static_pool; - } - - namespace detail { - - /*! Enum specifying the type of object */ - enum terminal_type { - TERMINAL = 0, /*!< object is an analog terminal */ - INPUT = 1, /*!< object is an input */ - OUTPUT = 2, /*!< object is an output */ - }; - - /*! Type of the model map used. - * This is used to hold all #Models in an unordered map - */ - using model_map_t = std::unordered_map; - - } // namespace detail -} // namespace netlist - -#endif /* NETLIST_TYPES_H_ */ diff --git a/src/lib/netlist/nl_base.h b/src/lib/netlist/nl_base.h index dccfb32f896..adbda1d679d 100644 --- a/src/lib/netlist/nl_base.h +++ b/src/lib/netlist/nl_base.h @@ -24,10 +24,10 @@ #include "plib/pstate.h" #include "plib/pstream.h" -#include "netlist_types.h" +#include "nl_types.h" #include "nl_errstr.h" #include "nl_lists.h" -#include "nl_time.h" +#include "plib/ptime.h" //============================================================ // MACROS / New Syntax diff --git a/src/lib/netlist/nl_factory.h b/src/lib/netlist/nl_factory.h index cd7e74944eb..abf41ef9f93 100644 --- a/src/lib/netlist/nl_factory.h +++ b/src/lib/netlist/nl_factory.h @@ -11,7 +11,7 @@ #include -#include "netlist_types.h" +#include "nl_types.h" #include "plib/palloc.h" #include "plib/ptypes.h" diff --git a/src/lib/netlist/nl_lists.h b/src/lib/netlist/nl_lists.h index 5443cd86c86..32e31998b7a 100644 --- a/src/lib/netlist/nl_lists.h +++ b/src/lib/netlist/nl_lists.h @@ -10,7 +10,6 @@ #ifndef NLLISTS_H_ #define NLLISTS_H_ -#include "netlist_types.h" #include "nl_config.h" #include "plib/pchrono.h" #include "plib/plists.h" @@ -21,6 +20,7 @@ #include #include #include +#include "nl_types.h" // ---------------------------------------------------------------------------------------- // timed queue diff --git a/src/lib/netlist/nl_setup.h b/src/lib/netlist/nl_setup.h index 50536d9da3b..dd4f9b381ac 100644 --- a/src/lib/netlist/nl_setup.h +++ b/src/lib/netlist/nl_setup.h @@ -18,9 +18,9 @@ #include "plib/pstring.h" #include "plib/putil.h" -#include "netlist_types.h" #include "nl_config.h" #include "nl_factory.h" +#include "nl_types.h" //============================================================ // MACROS / inline netlist definitions diff --git a/src/lib/netlist/nl_time.h b/src/lib/netlist/nl_time.h deleted file mode 100644 index 1db22241d64..00000000000 --- a/src/lib/netlist/nl_time.h +++ /dev/null @@ -1,159 +0,0 @@ -// license:GPL-2.0+ -// copyright-holders:Couriersud -/* - * nltime.h - */ - -#ifndef NLTIME_H_ -#define NLTIME_H_ - -#include "nl_config.h" -#include "plib/pstate.h" -#include "plib/ptypes.h" - -#include - -// ---------------------------------------------------------------------------------------- -// netlist_time -// ---------------------------------------------------------------------------------------- - -namespace netlist -{ - - template - struct ptime final - { - public: - - using internal_type = TYPE; - using mult_type = TYPE; - - constexpr ptime() noexcept : m_time(0) {} - - ~ptime() noexcept = default; - - constexpr ptime(const ptime &rhs) noexcept = default; - constexpr ptime(ptime &&rhs) noexcept = default; - constexpr explicit ptime(const internal_type &time) noexcept : m_time(time) {} - constexpr explicit ptime(internal_type &&time) noexcept : m_time(time) {} - C14CONSTEXPR ptime &operator=(const ptime &rhs) noexcept = default; - C14CONSTEXPR ptime &operator=(ptime &&rhs) noexcept = default; - - constexpr explicit ptime(const double t) = delete; - //: m_time((internal_type) ( t * (double) resolution)) { } - constexpr explicit ptime(const internal_type nom, const internal_type den) noexcept - : m_time(nom * (RES / den)) { } - - C14CONSTEXPR ptime &operator+=(const ptime rhs) noexcept { m_time += rhs.m_time; return *this; } - C14CONSTEXPR ptime &operator-=(const ptime rhs) noexcept { m_time -= rhs.m_time; return *this; } - C14CONSTEXPR ptime &operator*=(const mult_type factor) noexcept { m_time *= static_cast(factor); return *this; } - - friend C14CONSTEXPR ptime operator-(ptime lhs, const ptime rhs) noexcept - { - return lhs -= rhs; - } - - friend C14CONSTEXPR ptime operator+(ptime lhs, const ptime rhs) noexcept - { - return lhs += rhs; - } - - friend C14CONSTEXPR ptime operator*(ptime lhs, const mult_type &factor) noexcept - { - return lhs *= factor; - } - - friend constexpr mult_type operator/(const ptime lhs, const ptime rhs) noexcept - { - return static_cast(lhs.m_time / rhs.m_time); - } - - friend constexpr bool operator<(const ptime lhs, const ptime rhs) noexcept - { - return (lhs.m_time < rhs.m_time); - } - - friend constexpr bool operator>(const ptime lhs, const ptime rhs) noexcept - { - return (rhs < lhs); - } - - friend constexpr bool operator<=(const ptime lhs, const ptime rhs) noexcept - { - return !(lhs > rhs); - } - - friend constexpr bool operator>=(const ptime lhs, const ptime rhs) noexcept - { - return !(lhs < rhs); - } - - friend constexpr bool operator==(const ptime lhs, const ptime rhs) noexcept - { - return lhs.m_time == rhs.m_time; - } - - friend constexpr bool operator!=(const ptime lhs, const ptime rhs) noexcept - { - return !(lhs == rhs); - } - - constexpr internal_type as_raw() const noexcept { return m_time; } - constexpr double as_double() const noexcept - { - return static_cast(m_time) * inv_res; - } - - // for save states .... - C14CONSTEXPR internal_type *get_internaltype_ptr() noexcept { return &m_time; } - - static constexpr ptime from_nsec(const internal_type ns) noexcept { return ptime(ns, UINT64_C(1000000000)); } - static constexpr ptime from_usec(const internal_type us) noexcept { return ptime(us, UINT64_C( 1000000)); } - static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C( 1000)); } - static constexpr ptime from_sec(const internal_type s) noexcept { return ptime(s, UINT64_C( 1)); } - static constexpr ptime from_hz(const internal_type hz) noexcept { return ptime(1 , hz); } - static constexpr ptime from_raw(const internal_type raw) noexcept { return ptime(raw); } - static constexpr ptime from_double(const double t) noexcept { return ptime(static_cast( t * static_cast(RES)), RES); } - - static constexpr ptime zero() noexcept { return ptime(0, RES); } - static constexpr ptime quantum() noexcept { return ptime(1, RES); } - static constexpr ptime never() noexcept { return ptime(plib::numeric_limits::max(), RES); } - static constexpr internal_type resolution() noexcept { return RES; } - - constexpr internal_type in_nsec() const noexcept { return m_time / (RES / UINT64_C(1000000000)); } - constexpr internal_type in_usec() const noexcept { return m_time / (RES / UINT64_C( 1000000)); } - constexpr internal_type in_msec() const noexcept { return m_time / (RES / UINT64_C( 1000)); } - constexpr internal_type in_sec() const noexcept { return m_time / (RES / UINT64_C( 1)); } - - private: - static constexpr const double inv_res = 1.0 / static_cast(RES); - internal_type m_time; - }; - -#if (PHAS_INT128) - using netlist_time = ptime; -#else - using netlist_time = ptime; - static_assert(noexcept(netlist_time::from_nsec(1)) == true, "Not evaluated as constexpr"); -#endif - - //============================================================ - // MACROS - //============================================================ - - template inline constexpr netlist_time NLTIME_FROM_NS(T &&t) noexcept { return netlist_time::from_nsec(t); } - template inline constexpr netlist_time NLTIME_FROM_US(T &&t) noexcept { return netlist_time::from_usec(t); } - template inline constexpr netlist_time NLTIME_FROM_MS(T &&t) noexcept { return netlist_time::from_msec(t); } - -} // namespace netlist - -namespace plib { - - template<> - inline void state_manager_t::save_item(const void *owner, netlist::netlist_time &nlt, const pstring &stname) - { - save_state_ptr(owner, stname, datatype_t(sizeof(netlist::netlist_time::internal_type), true, false), 1, nlt.get_internaltype_ptr()); - } -} // namespace plib - -#endif /* NLTIME_H_ */ diff --git a/src/lib/netlist/nl_types.h b/src/lib/netlist/nl_types.h new file mode 100644 index 00000000000..8b229e85bf5 --- /dev/null +++ b/src/lib/netlist/nl_types.h @@ -0,0 +1,140 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/*! + * + * \file nl_types.h + * + */ + +#ifndef NL_TYPES_H_ +#define NL_TYPES_H_ + +#include "nl_config.h" +#include "plib/ptime.h" +#include "plib/pchrono.h" +#include "plib/pfmtlog.h" +#include "plib/pmempool.h" +#include "plib/pstring.h" +#include "plib/pstate.h" + +#include +#include + +namespace netlist +{ + /*! @brief netlist_sig_t is the type used for logic signals. + * + * This may be any of bool, uint8_t, uint16_t, uin32_t and uint64_t. + * The choice has little to no impact on performance. + */ + using netlist_sig_t = std::uint32_t; + + /* FIXME: belongs into nl_base.h to nlstate */ + /** + * @brief Interface definition for netlist callbacks into calling code + * + * A class inheriting from netlist_callbacks_t has to be passed to the netlist_t + * constructor. Netlist does processing during construction and thus needs + * the object passed completely constructed. + * + */ + class callbacks_t + { + public: + + callbacks_t() = default; + /* what is done before this is passed as a unique_ptr to netlist + * we should not limit. + */ + virtual ~callbacks_t() = default; + COPYASSIGNMOVE(callbacks_t, default) + + /* logging callback */ + virtual void vlog(const plib::plog_level &l, const pstring &ls) const = 0; + + }; + + using log_type = plib::plog_base; + + + //============================================================ + // Performance tracking + //============================================================ + + template + using nperftime_t = plib::chrono::timer; + + template + using nperfcount_t = plib::chrono::counter; + + //============================================================ + // Types needed by various includes + //============================================================ + + /*! The memory pool for netlist objects + * + * \note This is not the right location yet. + * + */ + +#if (USE_MEMPOOL) + using nlmempool = plib::mempool; +#else + using nlmempool = plib::mempool_default; +#endif + + /*! Owned pointer type for pooled allocations. + * + */ + template + using poolptr = nlmempool::poolptr; + + inline nlmempool &pool() + { + static nlmempool static_pool(655360, 16); + return static_pool; + } + + namespace detail { + + /*! Enum specifying the type of object */ + enum terminal_type { + TERMINAL = 0, /*!< object is an analog terminal */ + INPUT = 1, /*!< object is an input */ + OUTPUT = 2, /*!< object is an output */ + }; + + /*! Type of the model map used. + * This is used to hold all #Models in an unordered map + */ + using model_map_t = std::unordered_map; + + } // namespace detail + +#if (PHAS_INT128) + using netlist_time = ptime; +#else + using netlist_time = plib::ptime; + static_assert(noexcept(netlist_time::from_nsec(1)) == true, "Not evaluated as constexpr"); +#endif + + //============================================================ + // MACROS + //============================================================ + + template inline constexpr netlist_time NLTIME_FROM_NS(T &&t) noexcept { return netlist_time::from_nsec(t); } + template inline constexpr netlist_time NLTIME_FROM_US(T &&t) noexcept { return netlist_time::from_usec(t); } + template inline constexpr netlist_time NLTIME_FROM_MS(T &&t) noexcept { return netlist_time::from_msec(t); } + +} // namespace netlist + +namespace plib { + + template<> + inline void state_manager_t::save_item(const void *owner, netlist::netlist_time &nlt, const pstring &stname) + { + save_state_ptr(owner, stname, datatype_t(sizeof(netlist::netlist_time::internal_type), true, false), 1, nlt.get_internaltype_ptr()); + } +} // namespace plib + +#endif /* NL_TYPES_H_ */ diff --git a/src/lib/netlist/plib/ptime.h b/src/lib/netlist/plib/ptime.h new file mode 100644 index 00000000000..4767a197342 --- /dev/null +++ b/src/lib/netlist/plib/ptime.h @@ -0,0 +1,136 @@ +// license:GPL-2.0+ +// copyright-holders:Couriersud +/* + * ptime.h + */ + +#ifndef PTIME_H_ +#define PTIME_H_ + +#include "pconfig.h" +#include "ptypes.h" + +#include + +// ---------------------------------------------------------------------------------------- +// netlist_time +// ---------------------------------------------------------------------------------------- + +namespace plib +{ + + template + struct ptime final + { + public: + + using internal_type = TYPE; + using mult_type = TYPE; + + constexpr ptime() noexcept : m_time(0) {} + + ~ptime() noexcept = default; + + constexpr ptime(const ptime &rhs) noexcept = default; + constexpr ptime(ptime &&rhs) noexcept = default; + constexpr explicit ptime(const internal_type &time) noexcept : m_time(time) {} + constexpr explicit ptime(internal_type &&time) noexcept : m_time(time) {} + C14CONSTEXPR ptime &operator=(const ptime &rhs) noexcept = default; + C14CONSTEXPR ptime &operator=(ptime &&rhs) noexcept = default; + + constexpr explicit ptime(const double t) = delete; + //: m_time((internal_type) ( t * (double) resolution)) { } + constexpr explicit ptime(const internal_type nom, const internal_type den) noexcept + : m_time(nom * (RES / den)) { } + + C14CONSTEXPR ptime &operator+=(const ptime rhs) noexcept { m_time += rhs.m_time; return *this; } + C14CONSTEXPR ptime &operator-=(const ptime rhs) noexcept { m_time -= rhs.m_time; return *this; } + C14CONSTEXPR ptime &operator*=(const mult_type factor) noexcept { m_time *= static_cast(factor); return *this; } + + friend C14CONSTEXPR ptime operator-(ptime lhs, const ptime rhs) noexcept + { + return lhs -= rhs; + } + + friend C14CONSTEXPR ptime operator+(ptime lhs, const ptime rhs) noexcept + { + return lhs += rhs; + } + + friend C14CONSTEXPR ptime operator*(ptime lhs, const mult_type &factor) noexcept + { + return lhs *= factor; + } + + friend constexpr mult_type operator/(const ptime lhs, const ptime rhs) noexcept + { + return static_cast(lhs.m_time / rhs.m_time); + } + + friend constexpr bool operator<(const ptime lhs, const ptime rhs) noexcept + { + return (lhs.m_time < rhs.m_time); + } + + friend constexpr bool operator>(const ptime lhs, const ptime rhs) noexcept + { + return (rhs < lhs); + } + + friend constexpr bool operator<=(const ptime lhs, const ptime rhs) noexcept + { + return !(lhs > rhs); + } + + friend constexpr bool operator>=(const ptime lhs, const ptime rhs) noexcept + { + return !(lhs < rhs); + } + + friend constexpr bool operator==(const ptime lhs, const ptime rhs) noexcept + { + return lhs.m_time == rhs.m_time; + } + + friend constexpr bool operator!=(const ptime lhs, const ptime rhs) noexcept + { + return !(lhs == rhs); + } + + constexpr internal_type as_raw() const noexcept { return m_time; } + constexpr double as_double() const noexcept + { + return static_cast(m_time) * inv_res; + } + + // for save states .... + C14CONSTEXPR internal_type *get_internaltype_ptr() noexcept { return &m_time; } + + static constexpr ptime from_nsec(const internal_type ns) noexcept { return ptime(ns, UINT64_C(1000000000)); } + static constexpr ptime from_usec(const internal_type us) noexcept { return ptime(us, UINT64_C( 1000000)); } + static constexpr ptime from_msec(const internal_type ms) noexcept { return ptime(ms, UINT64_C( 1000)); } + static constexpr ptime from_sec(const internal_type s) noexcept { return ptime(s, UINT64_C( 1)); } + static constexpr ptime from_hz(const internal_type hz) noexcept { return ptime(1 , hz); } + static constexpr ptime from_raw(const internal_type raw) noexcept { return ptime(raw); } + static constexpr ptime from_double(const double t) noexcept { return ptime(static_cast( t * static_cast(RES)), RES); } + + static constexpr ptime zero() noexcept { return ptime(0, RES); } + static constexpr ptime quantum() noexcept { return ptime(1, RES); } + static constexpr ptime never() noexcept { return ptime(plib::numeric_limits::max(), RES); } + static constexpr internal_type resolution() noexcept { return RES; } + + constexpr internal_type in_nsec() const noexcept { return m_time / (RES / UINT64_C(1000000000)); } + constexpr internal_type in_usec() const noexcept { return m_time / (RES / UINT64_C( 1000000)); } + constexpr internal_type in_msec() const noexcept { return m_time / (RES / UINT64_C( 1000)); } + constexpr internal_type in_sec() const noexcept { return m_time / (RES / UINT64_C( 1)); } + + private: + static constexpr const double inv_res = 1.0 / static_cast(RES); + internal_type m_time; + }; + + +} // namespace plib + + +#endif /* PTIME_H_ */ diff --git a/src/lib/netlist/prg/nlwav.cpp b/src/lib/netlist/prg/nlwav.cpp index bd30e93d7e6..384d11f5781 100644 --- a/src/lib/netlist/prg/nlwav.cpp +++ b/src/lib/netlist/prg/nlwav.cpp @@ -1,11 +1,11 @@ // license:GPL-2.0+ // copyright-holders:Couriersud -#include "../plib/pstring.h" +#include "plib/pstring.h" #include "../nl_setup.h" -#include "../plib/plists.h" -#include "../plib/pmain.h" -#include "../plib/ppmf.h" -#include "../plib/pstream.h" +#include "plib/plists.h" +#include "plib/pmain.h" +#include "plib/ppmf.h" +#include "plib/pstream.h" #include diff --git a/src/lib/netlist/solver/nld_matrix_solver.cpp b/src/lib/netlist/solver/nld_matrix_solver.cpp index 6494ca6eaee..68cad1422ea 100644 --- a/src/lib/netlist/solver/nld_matrix_solver.cpp +++ b/src/lib/netlist/solver/nld_matrix_solver.cpp @@ -6,7 +6,7 @@ */ #include "nld_matrix_solver.h" -#include "../plib/putil.h" +#include "plib/putil.h" #include // <<= needed by windows build diff --git a/src/lib/netlist/solver/nld_ms_direct.h b/src/lib/netlist/solver/nld_ms_direct.h index 13f187f41b5..c0995d99e54 100644 --- a/src/lib/netlist/solver/nld_ms_direct.h +++ b/src/lib/netlist/solver/nld_ms_direct.h @@ -10,8 +10,8 @@ #include #include -#include -#include +#include "plib/mat_cr.h" +#include "plib/vector_ops.h" #include "nld_matrix_solver.h" #include "nld_solver.h" diff --git a/src/lib/netlist/solver/nld_ms_gcr.h b/src/lib/netlist/solver/nld_ms_gcr.h index d2caa944434..0a9f720f104 100644 --- a/src/lib/netlist/solver/nld_ms_gcr.h +++ b/src/lib/netlist/solver/nld_ms_gcr.h @@ -10,15 +10,16 @@ #ifndef NLD_MS_GCR_H_ #define NLD_MS_GCR_H_ -#include -#include +#include "plib/mat_cr.h" -#include "../plib/pdynlib.h" -#include "../plib/pstream.h" -#include "../plib/vector_ops.h" +#include "plib/pdynlib.h" +#include "plib/pstream.h" +#include "plib/vector_ops.h" #include "nld_ms_direct.h" #include "nld_solver.h" +#include + namespace netlist { namespace devices diff --git a/src/lib/netlist/solver/nld_ms_gmres.h b/src/lib/netlist/solver/nld_ms_gmres.h index e8963578452..bee5c25e3d5 100644 --- a/src/lib/netlist/solver/nld_ms_gmres.h +++ b/src/lib/netlist/solver/nld_ms_gmres.h @@ -8,10 +8,10 @@ #ifndef NLD_MS_GMRES_H_ #define NLD_MS_GMRES_H_ -#include "../plib/gmres.h" -#include "../plib/mat_cr.h" -#include "../plib/parray.h" -#include "../plib/vector_ops.h" +#include "plib/gmres.h" +#include "plib/mat_cr.h" +#include "plib/parray.h" +#include "plib/vector_ops.h" #include "nld_ms_direct.h" #include "nld_solver.h" diff --git a/src/lib/netlist/solver/nld_ms_sm.h b/src/lib/netlist/solver/nld_ms_sm.h index c473b6131e7..6c0f610e3f2 100644 --- a/src/lib/netlist/solver/nld_ms_sm.h +++ b/src/lib/netlist/solver/nld_ms_sm.h @@ -35,7 +35,7 @@ #include -#include "../plib/vector_ops.h" +#include "plib/vector_ops.h" #include "nld_matrix_solver.h" #include "nld_solver.h" diff --git a/src/lib/netlist/solver/nld_ms_w.h b/src/lib/netlist/solver/nld_ms_w.h index e5935462f03..584d50fdb15 100644 --- a/src/lib/netlist/solver/nld_ms_w.h +++ b/src/lib/netlist/solver/nld_ms_w.h @@ -42,7 +42,7 @@ #include -#include "../plib/vector_ops.h" +#include "plib/vector_ops.h" #include "nld_matrix_solver.h" #include "nld_solver.h" diff --git a/src/lib/netlist/solver/nld_solver.cpp b/src/lib/netlist/solver/nld_solver.cpp index be008a21706..ab75b7d7dc4 100644 --- a/src/lib/netlist/solver/nld_solver.cpp +++ b/src/lib/netlist/solver/nld_solver.cpp @@ -33,7 +33,7 @@ #include "../nl_lists.h" -#include "../plib/pomp.h" +#include "plib/pomp.h" #include "../nl_factory.h" diff --git a/src/lib/netlist/solver/nld_solver.h b/src/lib/netlist/solver/nld_solver.h index 646271e0ebd..87e02d215ec 100644 --- a/src/lib/netlist/solver/nld_solver.h +++ b/src/lib/netlist/solver/nld_solver.h @@ -9,7 +9,7 @@ #define NLD_SOLVER_H_ #include "../nl_base.h" -#include "../plib/pstream.h" +#include "plib/pstream.h" #include "nld_matrix_solver.h" #include diff --git a/src/lib/netlist/tools/nl_convert.cpp b/src/lib/netlist/tools/nl_convert.cpp index 16a3cfd6960..a9e17d56120 100644 --- a/src/lib/netlist/tools/nl_convert.cpp +++ b/src/lib/netlist/tools/nl_convert.cpp @@ -5,8 +5,8 @@ * */ -#include "../plib/palloc.h" -#include "../plib/putil.h" +#include "plib/palloc.h" +#include "plib/putil.h" #include "nl_convert.h" #include #include diff --git a/src/lib/netlist/tools/nl_convert.h b/src/lib/netlist/tools/nl_convert.h index b031ef72618..367546092be 100644 --- a/src/lib/netlist/tools/nl_convert.h +++ b/src/lib/netlist/tools/nl_convert.h @@ -10,10 +10,10 @@ #ifndef NL_CONVERT_H_ #define NL_CONVERT_H_ -#include "../plib/plists.h" -#include "../plib/pparser.h" -#include "../plib/pstring.h" -#include "../plib/ptypes.h" +#include "plib/plists.h" +#include "plib/pparser.h" +#include "plib/pstring.h" +#include "plib/ptypes.h" #include /*------------------------------------------------- -- cgit v1.2.3-70-g09d2