WIN32 build fixes
This commit is contained in:
parent
bb17a477b3
commit
5f0ed87581
9 changed files with 102 additions and 48 deletions
|
@ -14,6 +14,8 @@ add_compile_options(-Wall -pedantic -Wextra)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
include(FindPkgConfig)
|
||||||
|
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
|
@ -49,16 +51,38 @@ add_executable(
|
||||||
utils.cpp
|
utils.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pkg_check_modules(NCURSES REQUIRED ncurses)
|
||||||
|
target_link_libraries(kek ${NCURSES_LIBRARIES})
|
||||||
|
target_include_directories(kek PUBLIC ${NCURSES_INCLUDE_DIRS})
|
||||||
|
target_compile_options(kek PUBLIC ${NCURSES_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
pkg_check_modules(PANEL REQUIRED panel)
|
||||||
|
target_link_libraries(kek ${PANEL_LIBRARIES})
|
||||||
|
target_include_directories(kek PUBLIC ${PANEL_INCLUDE_DIRS})
|
||||||
|
target_compile_options(kek PUBLIC ${PANEL_CFLAGS_OTHER})
|
||||||
|
|
||||||
|
pkg_check_modules(JANSSON REQUIRED jansson)
|
||||||
|
target_link_libraries(kek ${JANSSON_LIBRARIES})
|
||||||
|
target_include_directories(kek PUBLIC ${JANSSON_INCLUDE_DIRS})
|
||||||
|
target_compile_options(kek PUBLIC ${JANSSON_CFLAGS_OTHER})
|
||||||
|
|
||||||
endif (NOT WIN32)
|
endif (NOT WIN32)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
||||||
add_executable(
|
add_executable(
|
||||||
kek-win32
|
kek-win32
|
||||||
|
breakpoint.cpp
|
||||||
|
breakpoint_and.cpp
|
||||||
|
breakpoint_memory.cpp
|
||||||
|
breakpoint_or.cpp
|
||||||
|
breakpoint_parser.cpp
|
||||||
|
breakpoint_register.cpp
|
||||||
bus.cpp
|
bus.cpp
|
||||||
console.cpp
|
console.cpp
|
||||||
console_posix.cpp
|
console_posix.cpp
|
||||||
cpu.cpp
|
cpu.cpp
|
||||||
|
dc11.cpp
|
||||||
debugger.cpp
|
debugger.cpp
|
||||||
disk_backend.cpp
|
disk_backend.cpp
|
||||||
disk_backend_file.cpp
|
disk_backend_file.cpp
|
||||||
|
@ -69,6 +93,7 @@ add_executable(
|
||||||
log.cpp
|
log.cpp
|
||||||
main.cpp
|
main.cpp
|
||||||
memory.cpp
|
memory.cpp
|
||||||
|
mmu.cpp
|
||||||
rk05.cpp
|
rk05.cpp
|
||||||
rl02.cpp
|
rl02.cpp
|
||||||
tm-11.cpp
|
tm-11.cpp
|
||||||
|
@ -95,20 +120,3 @@ target_link_libraries(kek-win32 Threads::Threads)
|
||||||
|
|
||||||
target_link_libraries(kek-win32 ws2_32)
|
target_link_libraries(kek-win32 ws2_32)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
include(FindPkgConfig)
|
|
||||||
|
|
||||||
pkg_check_modules(NCURSES REQUIRED ncurses)
|
|
||||||
target_link_libraries(kek ${NCURSES_LIBRARIES})
|
|
||||||
target_include_directories(kek PUBLIC ${NCURSES_INCLUDE_DIRS})
|
|
||||||
target_compile_options(kek PUBLIC ${NCURSES_CFLAGS_OTHER})
|
|
||||||
|
|
||||||
pkg_check_modules(PANEL REQUIRED panel)
|
|
||||||
target_link_libraries(kek ${PANEL_LIBRARIES})
|
|
||||||
target_include_directories(kek PUBLIC ${PANEL_INCLUDE_DIRS})
|
|
||||||
target_compile_options(kek PUBLIC ${PANEL_CFLAGS_OTHER})
|
|
||||||
|
|
||||||
pkg_check_modules(JANSSON REQUIRED jansson)
|
|
||||||
target_link_libraries(kek ${JANSSON_LIBRARIES})
|
|
||||||
target_include_directories(kek PUBLIC ${JANSSON_INCLUDE_DIRS})
|
|
||||||
target_compile_options(kek PUBLIC ${JANSSON_CFLAGS_OTHER})
|
|
||||||
|
|
43
dc11.cpp
43
dc11.cpp
|
@ -3,13 +3,18 @@
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#include <winsock2.h>
|
||||||
#else
|
#else
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
|
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
|
@ -24,7 +29,11 @@ dc11::dc11(const int base_port, bus *const b):
|
||||||
base_port(base_port),
|
base_port(base_port),
|
||||||
b(b)
|
b(b)
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
pfds = new WSAPOLLFD[dc11_n_lines * 2]();
|
||||||
|
#else
|
||||||
pfds = new pollfd[dc11_n_lines * 2]();
|
pfds = new pollfd[dc11_n_lines * 2]();
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO move to begin()
|
// TODO move to begin()
|
||||||
th = new std::thread(std::ref(*this));
|
th = new std::thread(std::ref(*this));
|
||||||
|
@ -55,7 +64,7 @@ void dc11::operator()()
|
||||||
|
|
||||||
for(int i=0; i<dc11_n_lines; i++) {
|
for(int i=0; i<dc11_n_lines; i++) {
|
||||||
// client session
|
// client session
|
||||||
pfds[dc11_n_lines + i].fd = -1;
|
pfds[dc11_n_lines + i].fd = INVALID_SOCKET;
|
||||||
pfds[dc11_n_lines + i].events = POLLIN;
|
pfds[dc11_n_lines + i].events = POLLIN;
|
||||||
|
|
||||||
// listen on port
|
// listen on port
|
||||||
|
@ -66,7 +75,7 @@ void dc11::operator()()
|
||||||
int reuse_addr = 1;
|
int reuse_addr = 1;
|
||||||
if (setsockopt(pfds[i].fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse_addr, sizeof(reuse_addr)) == -1) {
|
if (setsockopt(pfds[i].fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse_addr, sizeof(reuse_addr)) == -1) {
|
||||||
close(pfds[i].fd);
|
close(pfds[i].fd);
|
||||||
pfds[i].fd = -1;
|
pfds[i].fd = INVALID_SOCKET;
|
||||||
|
|
||||||
DOLOG(warning, true, "Cannot set reuseaddress for port %d (DC11)", port);
|
DOLOG(warning, true, "Cannot set reuseaddress for port %d (DC11)", port);
|
||||||
continue;
|
continue;
|
||||||
|
@ -82,7 +91,7 @@ void dc11::operator()()
|
||||||
|
|
||||||
if (bind(pfds[i].fd, reinterpret_cast<struct sockaddr *>(&listen_addr), sizeof(listen_addr)) == -1) {
|
if (bind(pfds[i].fd, reinterpret_cast<struct sockaddr *>(&listen_addr), sizeof(listen_addr)) == -1) {
|
||||||
close(pfds[i].fd);
|
close(pfds[i].fd);
|
||||||
pfds[i].fd = -1;
|
pfds[i].fd = INVALID_SOCKET;
|
||||||
|
|
||||||
DOLOG(warning, true, "Cannot bind to port %d (DC11)", port);
|
DOLOG(warning, true, "Cannot bind to port %d (DC11)", port);
|
||||||
continue;
|
continue;
|
||||||
|
@ -90,7 +99,7 @@ void dc11::operator()()
|
||||||
|
|
||||||
if (listen(pfds[i].fd, SOMAXCONN) == -1) {
|
if (listen(pfds[i].fd, SOMAXCONN) == -1) {
|
||||||
close(pfds[i].fd);
|
close(pfds[i].fd);
|
||||||
pfds[i].fd = -1;
|
pfds[i].fd = INVALID_SOCKET;
|
||||||
|
|
||||||
DOLOG(warning, true, "Cannot listen on port %d (DC11)", port);
|
DOLOG(warning, true, "Cannot listen on port %d (DC11)", port);
|
||||||
continue;
|
continue;
|
||||||
|
@ -100,7 +109,11 @@ void dc11::operator()()
|
||||||
}
|
}
|
||||||
|
|
||||||
while(!stop_flag) {
|
while(!stop_flag) {
|
||||||
|
#if defined(_WIN32)
|
||||||
|
int rc = WSAPoll(pfds, dc11_n_lines * 2, 100);
|
||||||
|
#else
|
||||||
int rc = poll(pfds, dc11_n_lines * 2, 100);
|
int rc = poll(pfds, dc11_n_lines * 2, 100);
|
||||||
|
#endif
|
||||||
if (rc == 0)
|
if (rc == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -113,14 +126,14 @@ void dc11::operator()()
|
||||||
|
|
||||||
// disconnect any existing client session
|
// disconnect any existing client session
|
||||||
// yes, one can ddos with this
|
// yes, one can ddos with this
|
||||||
if (pfds[client_i].fd != -1) {
|
if (pfds[client_i].fd != INVALID_SOCKET) {
|
||||||
close(pfds[client_i].fd);
|
close(pfds[client_i].fd);
|
||||||
DOLOG(info, false, "Restarting session for port %d", base_port + i + 1);
|
DOLOG(info, false, "Restarting session for port %d", base_port + i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pfds[client_i].fd = accept(pfds[i].fd, nullptr, nullptr);
|
pfds[client_i].fd = accept(pfds[i].fd, nullptr, nullptr);
|
||||||
|
|
||||||
if (pfds[client_i].fd != -1) {
|
if (pfds[client_i].fd != INVALID_SOCKET) {
|
||||||
set_nodelay(pfds[client_i].fd);
|
set_nodelay(pfds[client_i].fd);
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lck(input_lock[i]);
|
std::unique_lock<std::mutex> lck(input_lock[i]);
|
||||||
|
@ -149,7 +162,7 @@ void dc11::operator()()
|
||||||
registers[line_nr * 4 + 0] |= 0140000; // "ERROR", CARRIER TRANSITION
|
registers[line_nr * 4 + 0] |= 0140000; // "ERROR", CARRIER TRANSITION
|
||||||
|
|
||||||
close(pfds[i].fd);
|
close(pfds[i].fd);
|
||||||
pfds[i].fd = -1;
|
pfds[i].fd = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for(int k=0; k<rc; k++)
|
for(int k=0; k<rc; k++)
|
||||||
|
@ -166,7 +179,7 @@ void dc11::operator()()
|
||||||
DOLOG(info, true, "DC11 thread terminating");
|
DOLOG(info, true, "DC11 thread terminating");
|
||||||
|
|
||||||
for(int i=0; i<dc11_n_lines * 2; i++) {
|
for(int i=0; i<dc11_n_lines * 2; i++) {
|
||||||
if (pfds[i].fd != -1)
|
if (pfds[i].fd != INVALID_SOCKET)
|
||||||
close(pfds[i].fd);
|
close(pfds[i].fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +223,7 @@ uint16_t dc11::read_word(const uint16_t addr)
|
||||||
registers[line_nr * 4 + 0] &= ~1; // DTR: bit 0 [RCSR]
|
registers[line_nr * 4 + 0] &= ~1; // DTR: bit 0 [RCSR]
|
||||||
registers[line_nr * 4 + 0] &= ~4; // CD : bit 2
|
registers[line_nr * 4 + 0] &= ~4; // CD : bit 2
|
||||||
|
|
||||||
if (pfds[line_nr + dc11_n_lines].fd != -1) {
|
if (pfds[line_nr + dc11_n_lines].fd != INVALID_SOCKET) {
|
||||||
registers[line_nr * 4 + 0] |= 1;
|
registers[line_nr * 4 + 0] |= 1;
|
||||||
registers[line_nr * 4 + 0] |= 4;
|
registers[line_nr * 4 + 0] |= 4;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +259,7 @@ uint16_t dc11::read_word(const uint16_t addr)
|
||||||
registers[line_nr * 4 + 2] &= ~2; // CTS: bit 1 [TSCR]
|
registers[line_nr * 4 + 2] &= ~2; // CTS: bit 1 [TSCR]
|
||||||
registers[line_nr * 4 + 2] &= ~128; // READY: bit 7
|
registers[line_nr * 4 + 2] &= ~128; // READY: bit 7
|
||||||
|
|
||||||
if (pfds[line_nr + dc11_n_lines].fd != -1) {
|
if (pfds[line_nr + dc11_n_lines].fd != INVALID_SOCKET) {
|
||||||
registers[line_nr * 4 + 2] |= 2;
|
registers[line_nr * 4 + 2] |= 2;
|
||||||
registers[line_nr * 4 + 2] |= 128;
|
registers[line_nr * 4 + 2] |= 128;
|
||||||
}
|
}
|
||||||
|
@ -293,15 +306,15 @@ void dc11::write_word(const uint16_t addr, uint16_t v)
|
||||||
else
|
else
|
||||||
TRACE("DC11: transmit %c on line %d", c, line_nr);
|
TRACE("DC11: transmit %c on line %d", c, line_nr);
|
||||||
|
|
||||||
int fd = pfds[dc11_n_lines + line_nr].fd;
|
SOCKET fd = pfds[dc11_n_lines + line_nr].fd;
|
||||||
|
|
||||||
if (fd != -1 && write(fd, &c, 1) != 1) {
|
if (fd != INVALID_SOCKET && write(fd, &c, 1) != 1) {
|
||||||
DOLOG(info, false, "DC11 line %d disconnected\n", line_nr + 1);
|
DOLOG(info, false, "DC11 line %d disconnected\n", line_nr + 1);
|
||||||
|
|
||||||
registers[line_nr * 4 + 0] |= 0140000; // "ERROR", CARRIER TRANSITION
|
registers[line_nr * 4 + 0] |= 0140000; // "ERROR", CARRIER TRANSITION
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
pfds[dc11_n_lines + line_nr].fd = -1;
|
pfds[dc11_n_lines + line_nr].fd = INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_tx_interrupt_enabled(line_nr))
|
if (is_tx_interrupt_enabled(line_nr))
|
||||||
|
|
11
dc11.h
11
dc11.h
|
@ -8,6 +8,13 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
#else
|
||||||
|
#define SOCKET int
|
||||||
|
#define INVALID_SOCKET -1
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
|
@ -33,7 +40,11 @@ private:
|
||||||
std::thread *th { nullptr };
|
std::thread *th { nullptr };
|
||||||
|
|
||||||
// not statically allocated because of compiling problems on arduino
|
// not statically allocated because of compiling problems on arduino
|
||||||
|
#if defined(_WIN32)
|
||||||
|
WSAPOLLFD *pfds { nullptr };
|
||||||
|
#else
|
||||||
pollfd *pfds { nullptr };
|
pollfd *pfds { nullptr };
|
||||||
|
#endif
|
||||||
std::vector<char> recv_buffers[dc11_n_lines];
|
std::vector<char> recv_buffers[dc11_n_lines];
|
||||||
std::mutex input_lock[dc11_n_lines];
|
std::mutex input_lock[dc11_n_lines];
|
||||||
|
|
||||||
|
|
19
debugger.cpp
19
debugger.cpp
|
@ -3,22 +3,24 @@
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include "gen.h"
|
#include "gen.h"
|
||||||
#if IS_POSIX
|
#if IS_POSIX || defined(_WIN32)
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <jansson.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#else
|
#else
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if IS_POSIX
|
||||||
|
#include <jansson.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "breakpoint_parser.h"
|
#include "breakpoint_parser.h"
|
||||||
#include "bus.h"
|
#include "bus.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "disk_backend.h"
|
#include "disk_backend.h"
|
||||||
#if IS_POSIX
|
#if IS_POSIX || defined(_WIN32)
|
||||||
#include "disk_backend_file.h"
|
#include "disk_backend_file.h"
|
||||||
#else
|
#else
|
||||||
#include "disk_backend_esp32.h"
|
#include "disk_backend_esp32.h"
|
||||||
|
@ -45,7 +47,7 @@ void start_network(console *const cnsl);
|
||||||
void set_tty_serial_speed(console *const c, const uint32_t bps);
|
void set_tty_serial_speed(console *const c, const uint32_t bps);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(BUILD_FOR_RP2040) && !defined(linux)
|
#if !defined(BUILD_FOR_RP2040) && !defined(linux) && !defined(_WIN32)
|
||||||
extern SdFs SD;
|
extern SdFs SD;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -111,6 +113,7 @@ std::optional<std::string> select_host_file(console *const c)
|
||||||
|
|
||||||
entry.close();
|
entry.close();
|
||||||
}
|
}
|
||||||
|
#elif defined(_WIN32)
|
||||||
#else
|
#else
|
||||||
SD.ls("/", LS_DATE | LS_SIZE | LS_R);
|
SD.ls("/", LS_DATE | LS_SIZE | LS_R);
|
||||||
#endif
|
#endif
|
||||||
|
@ -127,9 +130,9 @@ std::optional<std::string> select_host_file(console *const c)
|
||||||
|
|
||||||
bool can_open_file = false;
|
bool can_open_file = false;
|
||||||
|
|
||||||
#if IS_POSIX
|
#if IS_POSIX || defined(_WIN32)
|
||||||
struct stat st { };
|
struct stat st { };
|
||||||
can_open_file = stat(selected_file.c_str(), &st) == 0;
|
can_open_file = ::stat(selected_file.c_str(), &st) == 0;
|
||||||
#else
|
#else
|
||||||
File32 fh;
|
File32 fh;
|
||||||
can_open_file = fh.open(selected_file.c_str(), O_RDWR);
|
can_open_file = fh.open(selected_file.c_str(), O_RDWR);
|
||||||
|
@ -147,7 +150,7 @@ std::optional<std::string> select_host_file(console *const c)
|
||||||
// disk image files
|
// disk image files
|
||||||
std::optional<disk_backend *> select_disk_file(console *const c)
|
std::optional<disk_backend *> select_disk_file(console *const c)
|
||||||
{
|
{
|
||||||
#if IS_POSIX
|
#if IS_POSIX || defined(_WIN32)
|
||||||
c->put_string_lf("Files in current directory: ");
|
c->put_string_lf("Files in current directory: ");
|
||||||
#else
|
#else
|
||||||
c->put_string_lf(format("MISO: %d", int(MISO)));
|
c->put_string_lf(format("MISO: %d", int(MISO)));
|
||||||
|
@ -179,7 +182,7 @@ std::optional<disk_backend *> select_disk_file(console *const c)
|
||||||
if (selected_file.has_value() == false)
|
if (selected_file.has_value() == false)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#if IS_POSIX
|
#if IS_POSIX || defined(_WIN32)
|
||||||
disk_backend *temp = new disk_backend_file(selected_file.value());
|
disk_backend *temp = new disk_backend_file(selected_file.value());
|
||||||
#else
|
#else
|
||||||
disk_backend *temp = new disk_backend_esp32(selected_file.value());
|
disk_backend *temp = new disk_backend_esp32(selected_file.value());
|
||||||
|
|
|
@ -45,7 +45,9 @@ disk_backend_file *disk_backend_file::deserialize(const json_t *const j)
|
||||||
|
|
||||||
bool disk_backend_file::begin(const bool snapshots)
|
bool disk_backend_file::begin(const bool snapshots)
|
||||||
{
|
{
|
||||||
|
#if IS_POSIX
|
||||||
use_overlay = snapshots;
|
use_overlay = snapshots;
|
||||||
|
#endif
|
||||||
|
|
||||||
fd = open(filename.c_str(), O_RDWR);
|
fd = open(filename.c_str(), O_RDWR);
|
||||||
|
|
||||||
|
@ -97,8 +99,10 @@ bool disk_backend_file::write(const off_t offset, const size_t n, const uint8_t
|
||||||
{
|
{
|
||||||
TRACE("disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
|
TRACE("disk_backend_file::write: write %zu bytes to offset %zu", n, offset);
|
||||||
|
|
||||||
|
#if IS_POSIX
|
||||||
if (store_mem_range_in_overlay(offset, n, from, sector_size))
|
if (store_mem_range_in_overlay(offset, n, from, sector_size))
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_WIN32) // hope for the best
|
#if defined(_WIN32) // hope for the best
|
||||||
if (lseek(fd, offset, SEEK_SET) == -1)
|
if (lseek(fd, offset, SEEK_SET) == -1)
|
||||||
|
|
7
log.cpp
7
log.cpp
|
@ -7,9 +7,14 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
#else
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
@ -72,7 +77,7 @@ void setlogfile(const char *const lf, const log_level_t ll_file, const log_level
|
||||||
bool setloghost(const char *const host, const log_level_t ll)
|
bool setloghost(const char *const host, const log_level_t ll)
|
||||||
{
|
{
|
||||||
syslog_ip_addr.sin_family = AF_INET;
|
syslog_ip_addr.sin_family = AF_INET;
|
||||||
bool ok = inet_aton(host, &syslog_ip_addr.sin_addr) == 1;
|
bool ok = inet_pton(AF_INET, host, &syslog_ip_addr.sin_addr) == 1;
|
||||||
syslog_ip_addr.sin_port = htons(514);
|
syslog_ip_addr.sin_port = htons(514);
|
||||||
|
|
||||||
is_file = false;
|
is_file = false;
|
||||||
|
|
9
main.cpp
9
main.cpp
|
@ -4,7 +4,9 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#if !defined(_WIN32)
|
||||||
#include <jansson.h>
|
#include <jansson.h>
|
||||||
|
#endif
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -53,7 +55,6 @@ void sw_handler(int s)
|
||||||
event = EVENT_TERMINATE;
|
event = EVENT_TERMINATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int run_cpu_validation(const std::string & filename)
|
int run_cpu_validation(const std::string & filename)
|
||||||
{
|
{
|
||||||
|
@ -262,6 +263,7 @@ int run_cpu_validation(const std::string & filename)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void get_metrics(cpu *const c)
|
void get_metrics(cpu *const c)
|
||||||
{
|
{
|
||||||
|
@ -493,8 +495,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
setlogfile(logfile, ll_file, ll_screen, timestamp);
|
setlogfile(logfile, ll_file, ll_screen, timestamp);
|
||||||
|
|
||||||
|
#if !defined(_WIN32)
|
||||||
if (validate_json.empty() == false)
|
if (validate_json.empty() == false)
|
||||||
return run_cpu_validation(validate_json);
|
return run_cpu_validation(validate_json);
|
||||||
|
#endif
|
||||||
|
|
||||||
DOLOG(info, true, "PDP11 emulator, by Folkert van Heusden");
|
DOLOG(info, true, "PDP11 emulator, by Folkert van Heusden");
|
||||||
|
|
||||||
|
@ -551,6 +555,7 @@ int main(int argc, char *argv[])
|
||||||
if (enable_bootloader)
|
if (enable_bootloader)
|
||||||
set_boot_loader(b, bootloader);
|
set_boot_loader(b, bootloader);
|
||||||
}
|
}
|
||||||
|
#if IS_POSIX
|
||||||
else {
|
else {
|
||||||
FILE *fh = fopen(deserialize.c_str(), "r");
|
FILE *fh = fopen(deserialize.c_str(), "r");
|
||||||
if (!fh)
|
if (!fh)
|
||||||
|
@ -568,9 +573,9 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
json_decref(j);
|
json_decref(j);
|
||||||
|
|
||||||
DOLOG(warning, true, "DO NOT FORGET TO DELETE AND NOT TO RE-USE THE STATE FILE (\"%s\")! (unless updated)", deserialize.c_str());
|
|
||||||
myusleep(251000);
|
myusleep(251000);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (b->getTty() == nullptr) {
|
if (b->getTty() == nullptr) {
|
||||||
tty *tty_ = new tty(cnsl, b);
|
tty *tty_ = new tty(cnsl, b);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
14
utils.cpp
14
utils.cpp
|
@ -6,11 +6,15 @@
|
||||||
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
#if defined(ESP32) || defined(BUILD_FOR_RP2040)
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "rp2040.h"
|
#include "rp2040.h"
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#elif defined(_WIN32)
|
||||||
|
#include <ws2tcpip.h>
|
||||||
|
#include <winsock2.h>
|
||||||
#else
|
#else
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#endif
|
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
@ -175,7 +179,7 @@ void set_thread_name(std::string name)
|
||||||
|
|
||||||
std::string get_thread_name()
|
std::string get_thread_name()
|
||||||
{
|
{
|
||||||
#if IS_POSIX
|
#if IS_POSIX || defined(_WIN32)
|
||||||
char buffer[16 + 1] { };
|
char buffer[16 + 1] { };
|
||||||
pthread_getname_np(pthread_self(), buffer, sizeof buffer);
|
pthread_getname_np(pthread_self(), buffer, sizeof buffer);
|
||||||
|
|
||||||
|
@ -246,10 +250,10 @@ void update_word(uint16_t *const w, const bool msb, const uint8_t v)
|
||||||
void set_nodelay(const int fd)
|
void set_nodelay(const int fd)
|
||||||
{
|
{
|
||||||
int flags = 1;
|
int flags = 1;
|
||||||
#if defined(__FreeBSD__) || defined(ESP32)
|
#if defined(__FreeBSD__) || defined(ESP32) || defined(_WIN32)
|
||||||
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) == -1)
|
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char *>(&flags), sizeof(flags)) == -1)
|
||||||
#else
|
#else
|
||||||
if (setsockopt(fd, SOL_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags)) == -1)
|
if (setsockopt(fd, SOL_TCP, TCP_NODELAY, reinterpret_cast<void *>(&flags), sizeof(flags)) == -1)
|
||||||
#endif
|
#endif
|
||||||
DOLOG(warning, true, "Cannot disable nagle algorithm");
|
DOLOG(warning, true, "Cannot disable nagle algorithm");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue