From b530334e9dd5848d0532956718fe56d16d3f2cd9 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 03:22:50 +0100 Subject: [PATCH 01/19] use typedef's where appropriate z80asm still compiles & runs on Coherent. --- altairsim/srcsim/simio.c | 6 +- altairsim/srcsim/simio.h | 6 +- altairsim/srcsim/simmem.c | 2 +- altairsim/srcsim/simmem.h | 6 +- cpmsim/srcsim/simio.c | 6 +- cpmsim/srcsim/simio.h | 10 +- cromemcosim/srcsim/simio.c | 6 +- cromemcosim/srcsim/simio.h | 6 +- cromemcosim/srcsim/simmem.c | 2 +- cromemcosim/srcsim/simmem.h | 6 +- imsaisim/srcsim/simio.c | 6 +- imsaisim/srcsim/simio.h | 6 +- imsaisim/srcsim/simmem.c | 2 +- imsaisim/srcsim/simmem.h | 6 +- intelmdssim/srcsim/simio.c | 8 +- intelmdssim/srcsim/simio.h | 8 +- iodevices/unix_network.c | 4 +- iodevices/unix_network.h | 12 +-- mosteksim/srcsim/simio.c | 4 +- mosteksim/srcsim/simio.h | 4 +- picosim/srcsim/simio.h | 4 +- webfrontend/netsrv.h | 20 ++-- z80asm/z80alst.c | 2 +- z80asm/z80amfun.c | 179 ++++++++++++++++++------------------ z80asm/z80amfun.h | 2 +- z80asm/z80anum.c | 16 ++-- z80asm/z80aopc.c | 50 +++++----- z80asm/z80aopc.h | 8 +- z80asm/z80apfun.c | 2 +- z80asm/z80asm.c | 2 +- z80asm/z80atab.c | 41 ++++----- z80asm/z80atab.h | 14 +-- z80core/alt8080.h | 2 +- z80core/altregs.h | 38 ++++---- z80core/altz80.h | 4 +- z80core/simcore.c | 2 +- z80core/simcore.h | 3 +- z80core/simdefs.h | 5 + z80core/simglb.c | 4 +- z80core/simglb.h | 2 +- z80core/simice.c | 21 +++-- z80core/simice.h | 12 +-- z80sim/srcsim/simio.c | 4 +- z80sim/srcsim/simio.h | 4 +- 44 files changed, 278 insertions(+), 279 deletions(-) diff --git a/altairsim/srcsim/simio.c b/altairsim/srcsim/simio.c index 3ee97493..51f4a66f 100644 --- a/altairsim/srcsim/simio.c +++ b/altairsim/srcsim/simio.c @@ -81,13 +81,13 @@ static BYTE io_no_card_in(void); static int printer; /* fd for file "printer.txt" */ static BYTE hwctl_lock = 0xff; /* lock status hardware control port */ -struct unix_connectors ucons[NUMUSOC]; /* socket connections for SIO's */ +unix_connector_t ucons[NUMUSOC]; /* socket connections for SIO's */ /* * This array contains function pointers for every * input I/O port (0 - 255), to do the required I/O. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { [ 0] = altair_sio0_status_in, /* SIO 0 connected to console */ [ 1] = altair_sio0_data_in, /* " */ [ 2] = lpt_status_in, /* printer status */ @@ -117,7 +117,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every * output I/O port (0 - 255), to do the required I/O. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { [ 0] = altair_sio0_status_out, /* SIO 0 connected to console */ [ 1] = altair_sio0_data_out, /* " */ [ 2] = lpt_status_out, /* printer status */ diff --git a/altairsim/srcsim/simio.h b/altairsim/srcsim/simio.h index bfc1746c..79768022 100644 --- a/altairsim/srcsim/simio.h +++ b/altairsim/srcsim/simio.h @@ -13,10 +13,10 @@ #define IO_DATA_UNUSED 0xff /* data returned on unused ports */ -extern struct unix_connectors ucons[NUMUSOC]; +extern unix_connector_t ucons[NUMUSOC]; -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); diff --git a/altairsim/srcsim/simmem.c b/altairsim/srcsim/simmem.c index 95ecc098..dde05d54 100644 --- a/altairsim/srcsim/simmem.c +++ b/altairsim/srcsim/simmem.c @@ -34,7 +34,7 @@ #include "log.h" static const char *TAG = "memory"; -struct memmap memconf[MAXMEMSECT][MAXMEMMAP] /* memory map */ +memmap_t memconf[MAXMEMSECT][MAXMEMMAP] /* memory map */ = { { { MEM_RW, 0, 0x100, NULL } } }; /* default config to 64K RAM only */ WORD _boot_switch[MAXMEMSECT]; /* boot address for switch */ diff --git a/altairsim/srcsim/simmem.h b/altairsim/srcsim/simmem.h index 83d2d16b..da108a6e 100644 --- a/altairsim/srcsim/simmem.h +++ b/altairsim/srcsim/simmem.h @@ -53,14 +53,14 @@ #define MAXMEMMAP 6 #define MAXMEMSECT 15 -struct memmap { +typedef struct memmap { int type; /* type of memory pages */ BYTE spage; /* start page of segment */ WORD size; /* size of segment in pages */ char *rom_file; -}; +} memmap_t; -extern struct memmap memconf[MAXMEMSECT][MAXMEMMAP]; +extern memmap_t memconf[MAXMEMSECT][MAXMEMMAP]; extern WORD _boot_switch[MAXMEMSECT]; /* boot address */ extern BYTE memory[65536], mem_wp; diff --git a/cpmsim/srcsim/simio.c b/cpmsim/srcsim/simio.c index 7c562c0c..27e16bbd 100644 --- a/cpmsim/srcsim/simio.c +++ b/cpmsim/srcsim/simio.c @@ -214,7 +214,7 @@ static int sdirection = -1; /* protocol direction, 0 = send 1 = receive */ #endif /* NETWORKING */ -struct dskdef disks[16] = { +dskdef_t disks[16] = { { "drivea.dsk", &drivea, 77, 26 }, { "driveb.dsk", &driveb, 77, 26 }, { "drivec.dsk", &drivec, 77, 26 }, @@ -298,7 +298,7 @@ static void int_io(int sig); * This array contains function pointers for every * input port. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { [ 0] = cons_in, [ 1] = cond_in, [ 2] = prts_in, @@ -340,7 +340,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every * output port. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { [ 0] = cons_out, [ 1] = cond_out, [ 2] = prts_out, diff --git a/cpmsim/srcsim/simio.h b/cpmsim/srcsim/simio.h index 56700b76..07bddf49 100644 --- a/cpmsim/srcsim/simio.h +++ b/cpmsim/srcsim/simio.h @@ -15,17 +15,17 @@ /* * Structure for the disk images */ -struct dskdef { +typedef struct dskdef { const char *fn; /* filename */ int *fd; /* file descriptor */ unsigned int tracks; /* number of tracks */ unsigned int sectors; /* number of sectors */ -}; +} dskdef_t; -extern struct dskdef disks[16]; +extern dskdef_t disks[16]; -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); diff --git a/cromemcosim/srcsim/simio.c b/cromemcosim/srcsim/simio.c index 021d8c4e..d33bae4c 100644 --- a/cromemcosim/srcsim/simio.c +++ b/cromemcosim/srcsim/simio.c @@ -98,7 +98,7 @@ int lpt1, lpt2; /* fds for lpt printer files */ static BYTE hwctl_lock = 0xff; /* lock status hardware control port */ /* network connections for serial ports on the TU-ART's */ -struct net_connectors ncons[NUMNSOC]; +net_connector_t ncons[NUMNSOC]; static int th_suspend; /* timing thread suspend flag */ @@ -106,7 +106,7 @@ static int th_suspend; /* timing thread suspend flag */ * This array contains function pointers for every * input I/O port (0 - 255), to do the required I/O. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { [ 0] = cromemco_tuart_0a_status_in, [ 1] = cromemco_tuart_0a_data_in, [ 3] = cromemco_tuart_0a_interrupt_in, @@ -158,7 +158,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every * output I/O port (0 - 255), to do the required I/O. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { [ 0] = cromemco_tuart_0a_baud_out, [ 1] = cromemco_tuart_0a_data_out, [ 2] = cromemco_tuart_0a_command_out, diff --git a/cromemcosim/srcsim/simio.h b/cromemcosim/srcsim/simio.h index a2481721..1493ef43 100644 --- a/cromemcosim/srcsim/simio.h +++ b/cromemcosim/srcsim/simio.h @@ -16,10 +16,10 @@ extern int lpt1, lpt2; -extern struct net_connectors ncons[NUMNSOC]; +extern net_connector_t ncons[NUMNSOC]; -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); diff --git a/cromemcosim/srcsim/simmem.c b/cromemcosim/srcsim/simmem.c index 81c435a8..a1875aef 100644 --- a/cromemcosim/srcsim/simmem.c +++ b/cromemcosim/srcsim/simmem.c @@ -32,7 +32,7 @@ #include "log.h" static const char *TAG = "memory"; -struct memmap memconf[MAXMEMSECT][MAXMEMMAP] /* memory map */ +memmap_t memconf[MAXMEMSECT][MAXMEMMAP] /* memory map */ = { { { MEM_RW, 0, 0x100, NULL } } }; /* default config to 64K RAM only */ WORD boot_switch[MAXMEMSECT]; /* boot address */ diff --git a/cromemcosim/srcsim/simmem.h b/cromemcosim/srcsim/simmem.h index ff6b6b21..9426d248 100644 --- a/cromemcosim/srcsim/simmem.h +++ b/cromemcosim/srcsim/simmem.h @@ -56,14 +56,14 @@ #define BANKED_ROM_MSG "FDC Banked ROM enabled" -struct memmap { +typedef struct memmap { int type; /* type of memory pages */ BYTE spage; /* start page of segment */ WORD size; /* size of segment in pages */ char *rom_file; -}; +} memmap_t; -extern struct memmap memconf[MAXMEMSECT][MAXMEMMAP]; +extern memmap_t memconf[MAXMEMSECT][MAXMEMMAP]; extern WORD boot_switch[MAXMEMSECT]; /* boot address */ extern BYTE *memory[MAXSEG]; diff --git a/imsaisim/srcsim/simio.c b/imsaisim/srcsim/simio.c index e182ed57..e8c0b741 100644 --- a/imsaisim/srcsim/simio.c +++ b/imsaisim/srcsim/simio.c @@ -117,7 +117,7 @@ static void apu_status_out(BYTE data); #endif static int printer; /* fd for file "printer.txt" */ -struct unix_connectors ucons[NUMUSOC]; /* socket connections for SIO's */ +unix_connector_t ucons[NUMUSOC]; /* socket connections for SIO's */ static BYTE hwctl_lock = 0xff; /* lock status hardware control port */ #ifdef HAS_APU static void *am9511 = NULL; /* am9511 instantiation */ @@ -127,7 +127,7 @@ static void *am9511 = NULL; /* am9511 instantiation */ * This array contains function pointers for every * input I/O port (0 - 255), to do the required I/O. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { [ 0] = imsai_sio_nofun_in, /* IMSAI SIO-2 */ [ 1] = imsai_sio_nofun_in, [ 2] = imsai_sio1a_data_in, /* Channel A, console */ @@ -200,7 +200,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every * output I/O port (0 - 255), to do the required I/O. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { [ 0] = imsai_sio_nofun_out, /* IMSAI SIO-2 */ [ 1] = imsai_sio_nofun_out, [ 2] = imsai_sio1a_data_out, /* Channel A, console */ diff --git a/imsaisim/srcsim/simio.h b/imsaisim/srcsim/simio.h index 7a7f4277..f157144d 100644 --- a/imsaisim/srcsim/simio.h +++ b/imsaisim/srcsim/simio.h @@ -17,10 +17,10 @@ extern void lpt_reset(void); -extern struct unix_connectors ucons[NUMUSOC]; /* socket connections for SIO's */ +extern unix_connector_t ucons[NUMUSOC]; /* socket connections for SIO's */ -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); diff --git a/imsaisim/srcsim/simmem.c b/imsaisim/srcsim/simmem.c index d5ac740e..c1463db9 100644 --- a/imsaisim/srcsim/simmem.c +++ b/imsaisim/srcsim/simmem.c @@ -34,7 +34,7 @@ #include "log.h" static const char *TAG = "memory"; -struct memmap memconf[MAXMEMSECT][MAXMEMMAP] /* memory map */ +memmap_t memconf[MAXMEMSECT][MAXMEMMAP] /* memory map */ = { { { MEM_RW, 0, 0x100, NULL } } }; /* default config to 64K RAM only */ WORD boot_switch[MAXMEMSECT]; /* boot address */ diff --git a/imsaisim/srcsim/simmem.h b/imsaisim/srcsim/simmem.h index 9ff50f3b..c3ad0b9c 100644 --- a/imsaisim/srcsim/simmem.h +++ b/imsaisim/srcsim/simmem.h @@ -58,14 +58,14 @@ #define BANKED_ROM_MSG "MPU-B Banked ROM/RAM enabled" -struct memmap { +typedef struct memmap { int type; /* type of memory pages */ BYTE spage; /* start page of segment */ WORD size; /* size of segment in pages */ char *rom_file; -}; +} memmap_t; -extern struct memmap memconf[MAXMEMSECT][MAXMEMMAP]; +extern memmap_t memconf[MAXMEMSECT][MAXMEMMAP]; extern WORD boot_switch[MAXMEMSECT]; /* boot address */ extern BYTE memory[64 << 10], *banks[MAXSEG]; diff --git a/intelmdssim/srcsim/simio.c b/intelmdssim/srcsim/simio.c index a52047ff..01c23412 100644 --- a/intelmdssim/srcsim/simio.c +++ b/intelmdssim/srcsim/simio.c @@ -77,15 +77,15 @@ static int rtc_status1, rtc_status0; /* RTC status flip-flops */ static int th_suspend; /* RTC/interrupt thread suspend flag */ int lpt_fd; /* fd for file "printer.txt" */ -struct net_connectors ncons[NUMNSOC]; /* network connection for TTY */ -struct unix_connectors ucons[NUMUSOC]; /* socket connection for PTR/PTP */ +net_connector_t ncons[NUMNSOC]; /* network connection for TTY */ +unix_connector_t ucons[NUMUSOC]; /* socket connection for PTR/PTP */ static BYTE hwctl_lock = 0xff; /* lock status hardware control port */ /* * This array contains function pointers for every input * I/O port (0 - 255), to do the required I/O. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { #ifdef HAS_ISBC206 [104] = isbc206_status_in, /* iSBC 206 subsystem status input */ [105] = isbc206_res_type_in, /* iSBC 206 result type input */ @@ -120,7 +120,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every output * I/O port (0 - 255), to do the required I/O. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { #ifdef HAS_ISBC206 [105] = isbc206_iopbl_out, /* iSBC 206 IOPB address LSB output */ [106] = isbc206_iopbh_out, /* iSBC 206 IOPB address MSB output */ diff --git a/intelmdssim/srcsim/simio.h b/intelmdssim/srcsim/simio.h index da68cc10..2ef7744b 100644 --- a/intelmdssim/srcsim/simio.h +++ b/intelmdssim/srcsim/simio.h @@ -19,11 +19,11 @@ extern BYTE int_requests; extern int lpt_fd; -extern struct net_connectors ncons[NUMNSOC]; -extern struct unix_connectors ucons[NUMUSOC]; +extern net_connector_t ncons[NUMNSOC]; +extern unix_connector_t ucons[NUMUSOC]; -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); diff --git a/iodevices/unix_network.c b/iodevices/unix_network.c index 4a91c6a0..06ccbfda 100644 --- a/iodevices/unix_network.c +++ b/iodevices/unix_network.c @@ -42,7 +42,7 @@ static const char *TAG = "net"; /* * initialize a server UNIX domain socket */ -void init_unix_server_socket(struct unix_connectors *p, const char *fn) +void init_unix_server_socket(unix_connector_t *p, const char *fn) { struct sockaddr_un sun; struct stat sbuf; @@ -79,7 +79,7 @@ void init_unix_server_socket(struct unix_connectors *p, const char *fn) /* * initialize a server TCP/IP socket */ -void init_tcp_server_socket(struct net_connectors *p) +void init_tcp_server_socket(net_connector_t *p) { struct sockaddr_in sin; int on = 1; diff --git a/iodevices/unix_network.h b/iodevices/unix_network.h index 543616ac..23935862 100644 --- a/iodevices/unix_network.h +++ b/iodevices/unix_network.h @@ -20,22 +20,22 @@ #define TELNET_TIMEOUT 800 /* telnet negotiation timeout in milliseconds */ /* structure for UNIX socket connections */ -struct unix_connectors { +typedef struct unix_connector { int ss; /* server socket descriptor */ int ssc; /* connected server socket descriptor */ -}; +} unix_connector_t; /* structure for TCP/IP socket connections */ -struct net_connectors { +typedef struct net_connector { int ss; /* server socket descriptor */ int ssc; /* connected server socket descriptor */ int port; /* TCP/IP port for server socket */ int telnet; /* telnet protocol flag for TCP/IP server socket */ -}; +} net_connector_t; -extern void init_unix_server_socket(struct unix_connectors *p, const char *fn); +extern void init_unix_server_socket(unix_connector_t *p, const char *fn); -extern void init_tcp_server_socket(struct net_connectors *p); +extern void init_tcp_server_socket(net_connector_t *p); extern void sigio_tcp_server_socket(int sig); extern void telnet_negotiation(int fd); diff --git a/mosteksim/srcsim/simio.c b/mosteksim/srcsim/simio.c index 10828892..202721d9 100644 --- a/mosteksim/srcsim/simio.c +++ b/mosteksim/srcsim/simio.c @@ -37,7 +37,7 @@ static void io_no_card_out(BYTE data); * This array contains function pointers for every * input I/O port (0 - 255), to do the required I/O. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { [208] = io_no_card_in, /* (d0) PIO1 Data A */ [209] = io_no_card_in, /* (d1) PIO1 Control A */ [210] = io_no_card_in, /* (d2) PIO1 Data B */ @@ -66,7 +66,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every * output I/O port (0 - 255), to do the required I/O. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { [161] = host_bdos_out, /* host file I/O hook */ [208] = io_no_card_out, /* (d0) PIO1 Data A */ [209] = io_no_card_out, /* (d1) PIO1 Control A */ diff --git a/mosteksim/srcsim/simio.h b/mosteksim/srcsim/simio.h index f8f45316..446259b8 100644 --- a/mosteksim/srcsim/simio.h +++ b/mosteksim/srcsim/simio.h @@ -9,8 +9,8 @@ #define IO_DATA_UNUSED 0xff /* data returned on unused ports */ -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); diff --git a/picosim/srcsim/simio.h b/picosim/srcsim/simio.h index da69cc39..5f37ad5b 100644 --- a/picosim/srcsim/simio.h +++ b/picosim/srcsim/simio.h @@ -14,8 +14,8 @@ extern BYTE fp_value; -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); diff --git a/webfrontend/netsrv.h b/webfrontend/netsrv.h index 7e0c3e35..85c2a78c 100644 --- a/webfrontend/netsrv.h +++ b/webfrontend/netsrv.h @@ -2,7 +2,7 @@ * netsrv.h * * Copyright (C) 2018 by David McNaughton - * + * * History: * 12-JUL-2018 1.0 Initial Release */ @@ -36,19 +36,15 @@ enum net_device { typedef enum net_device net_device_t; -struct msgbuf_s { +typedef struct msgbuf_s { long mtype; unsigned char mtext[128]; -}; +} msgbuf_t; -typedef struct msgbuf_s msgbuf_t; - -struct ws_client { +typedef struct ws_client { struct mg_connection *conn; int state; -}; - -typedef struct ws_client ws_client_t; +} ws_client_t; extern int net_device_alive(net_device_t device); extern void net_device_service(net_device_t device, void (*cbfunc)(BYTE *data)); @@ -79,14 +75,12 @@ enum http_method { typedef enum http_method http_method_t; -struct request { +typedef struct request { const struct mg_request_info *mg; http_method_t method; const char *args[_HTTP_MAX_ARGS]; long long len; -}; - -typedef struct request request_t; +} request_t; extern request_t *get_request(const HttpdConnection_t *conn); diff --git a/z80asm/z80alst.c b/z80asm/z80alst.c index ff419e7b..b2562031 100644 --- a/z80asm/z80alst.c +++ b/z80asm/z80alst.c @@ -298,7 +298,7 @@ void lst_mac(void) void lst_sym(void) { register int col; - register struct sym *sp; + register sym_t *sp; int prev_rf; if (sort_mode == SYM_NONE) diff --git a/z80asm/z80amfun.c b/z80asm/z80amfun.c index 9fbacedb..a26fcb32 100644 --- a/z80asm/z80amfun.c +++ b/z80asm/z80amfun.c @@ -30,64 +30,66 @@ #define CAT_BEFORE 1 #define CAT_AFTER 2 -struct dum { /* macro dummy */ +typedef struct dum { /* macro dummy */ char *dum_name; /* dummy name */ struct dum *dum_next; /* next dummy in list */ -}; +} dum_t; -struct line { /* macro source line */ +typedef struct line { /* macro source line */ char *line_text; /* source line */ struct line *line_next; /* next line in list */ -}; +} line_t; -struct expn; +struct expn; /* forward declaration */ -struct mac { /* macro */ - void (*mac_start)(struct expn *e, - char *operand); /* start expansion function */ - int (*mac_rept)(struct expn *e); /* repeat expansion function */ +typedef void (start_func_t)(struct expn *e, char *operand); +typedef int (rept_func_t)(struct expn *e); + +typedef struct mac { /* macro */ + start_func_t *mac_start; /* start expansion function */ + rept_func_t *mac_rept; /* repeat expansion function */ char *mac_name; /* macro name */ int mac_refflg; /* macro reference flag */ WORD mac_nrept; /* REPT count */ char *mac_irp; /* IRP, IRPC character list */ - struct dum *mac_dums, *mac_dums_last; /* macro dummies */ - struct line *mac_lines, *mac_lines_last; /* macro body */ + dum_t *mac_dums, *mac_dums_last; /* macro dummies */ + line_t *mac_lines, *mac_lines_last; /* macro body */ struct mac *mac_prev, *mac_next; /* prev./next macro in list */ -}; +} mac_t; -struct parm { /* expansion parameter */ +typedef struct parm { /* expansion parameter */ char *parm_name; /* dummy name */ char *parm_val; /* parameter value */ struct parm *parm_next; /* next parameter in list */ -}; +} parm_t; -struct loc { /* expansion local label */ +typedef struct loc { /* expansion local label */ char *loc_name; /* local label name */ char loc_val[8]; /* local label value ??xxxx */ struct loc *loc_next; /* next local label in list */ -}; +} loc_t; -struct expn { /* macro expansion */ - struct mac *expn_mac; /* macro being expanded */ - struct parm *expn_parms, *expn_parms_last; /* macro parameters */ - struct loc *expn_locs, *expn_locs_last; /* local labels */ - struct line *expn_line; /* current expansion line */ +typedef struct expn { /* macro expansion */ + mac_t *expn_mac; /* macro being expanded */ + parm_t *expn_parms, *expn_parms_last; /* macro parameters */ + loc_t *expn_locs, *expn_locs_last; /* local labels */ + line_t *expn_line; /* current expansion line */ int expn_cond_state[COND_STATE_SIZE]; /* cond state before expn */ WORD expn_iter; /* curr. expansion iteration */ char *expn_irp; /* IRP, IRPC character list */ struct expn *expn_next; /* next expansion in list */ -}; +} expn_t; -static struct mac *mac_table; /* MACRO table */ -static struct mac *mac_curr; /* current macro */ -static struct mac **mac_array; /* sorted table for iterator */ +static mac_t *mac_table; /* MACRO table */ +static mac_t *mac_curr; /* current macro */ +static mac_t **mac_array; /* sorted table for iterator */ static int mac_def_nest; /* macro def nesting level */ static int mac_exp_nest; /* macro exp nesting level */ static int mac_symmax; /* max. macro len observed */ static int mac_index; /* index for iterator */ static int mac_sort; /* sort mode for iterator */ static int mac_count; /* number of macros defined */ -static struct expn *mac_expn; /* macro expansion stack */ +static expn_t *mac_expn; /* macro expansion stack */ static WORD mac_loc_cnt; /* counter for LOCAL labels */ static char tmp[MAXLINE + 1]; /* temporary buffer */ @@ -141,8 +143,8 @@ static int is_symbol(char *s) */ static int mac_compare(const void *p1, const void *p2) { - return strcmp((*(const struct mac **) p1)->mac_name, - (*(const struct mac **) p2)->mac_name); + return strcmp((*(const mac_t **) p1)->mac_name, + (*(const mac_t **) p2)->mac_name); } /* @@ -151,7 +153,7 @@ static int mac_compare(const void *p1, const void *p2) */ char *mac_first(int sort_mode, int *rp) { - register struct mac *m; + register mac_t *m; register int i; if (mac_count == 0) @@ -166,14 +168,13 @@ char *mac_first(int sort_mode, int *rp) return mac_curr->mac_name; case SYM_SORTN: case SYM_SORTA: - mac_array = (struct mac **) malloc(sizeof(struct mac *) - * mac_count); + mac_array = (mac_t **) malloc(sizeof(mac_t *) * mac_count); if (mac_array == NULL) fatal(F_OUTMEM, "sorting macro table"); i = 0; for (m = mac_table; m != NULL; m = m->mac_next) mac_array[i++] = m; - qsort(mac_array, mac_count, sizeof(struct mac *), mac_compare); + qsort(mac_array, mac_count, sizeof(mac_t *), mac_compare); mac_index = 0; *rp = mac_array[mac_index]->mac_refflg; return mac_array[mac_index]->mac_name; @@ -205,14 +206,12 @@ char *mac_next(int *rp) * allocate a new macro with optional name and * start/repeat expansion function */ -static struct mac *mac_new(const char *name, - void (*start)(struct expn *e, char *operand), - int (*rept)(struct expn *e)) +static mac_t *mac_new(const char *name, start_func_t *start, rept_func_t *rept) { - register struct mac *m; + register mac_t *m; register int n; - if ((m = (struct mac *) malloc(sizeof(struct mac))) == NULL) + if ((m = (mac_t *) malloc(sizeof(mac_t))) == NULL) fatal(F_OUTMEM, "macro"); if (name != NULL) { n = strlen(name); @@ -237,12 +236,12 @@ static struct mac *mac_new(const char *name, /* * delete a macro */ -static void mac_delete(struct mac *m) +static void mac_delete(mac_t *m) { - register struct dum *d; - register struct line *l; - struct dum *d1; - struct line *l1; + register dum_t *d; + register line_t *l; + dum_t *d1; + line_t *l1; for (d = m->mac_dums; d != NULL; d = d1) { d1 = d->dum_next; @@ -276,7 +275,7 @@ void mac_start_pass(int pass) */ void mac_end_pass(int pass) { - register struct mac *m; + register mac_t *m; if (pass == 1) while (mac_table != NULL) { @@ -290,11 +289,11 @@ void mac_end_pass(int pass) /* * add a dummy to a macro */ -static void mac_add_dum(struct mac *m, char *name) +static void mac_add_dum(mac_t *m, char *name) { - register struct dum *d; + register dum_t *d; - if ((d = (struct dum *) malloc(sizeof(struct dum))) == NULL) + if ((d = (dum_t *) malloc(sizeof(dum_t))) == NULL) fatal(F_OUTMEM, "macro dummy"); d->dum_name = strsave(name); d->dum_next = NULL; @@ -308,13 +307,13 @@ static void mac_add_dum(struct mac *m, char *name) /* * add a local to a macro expansion */ -static void expn_add_loc(struct expn *e, char *name) +static void expn_add_loc(expn_t *e, char *name) { - register struct loc *l; + register loc_t *l; register char *s; register char c; - if ((l = (struct loc *) malloc(sizeof(struct loc))) == NULL) + if ((l = (loc_t *) malloc(sizeof(loc_t))) == NULL) fatal(F_OUTMEM, "macro local label"); l->loc_name = strsave(name); s = l->loc_val; @@ -350,12 +349,12 @@ static void expn_add_loc(struct expn *e, char *name) * start macro expansion * assign values to parameters, save cond state */ -static void mac_start_expn(struct mac *m, char *operand) +static void mac_start_expn(mac_t *m, char *operand) { - register struct expn *e; - register struct parm *p; - register struct dum *d; - struct expn *e1; + register expn_t *e; + register parm_t *p; + register dum_t *d; + expn_t *e1; if (mac_exp_nest == MACNEST) { /* abort macro expansion */ @@ -370,12 +369,12 @@ static void mac_start_expn(struct mac *m, char *operand) asmerr(E_MACNST); return; } - if ((e = (struct expn *) malloc(sizeof(struct expn))) == NULL) + if ((e = (expn_t *) malloc(sizeof(expn_t))) == NULL) fatal(F_OUTMEM, "macro expansion"); e->expn_mac = m; e->expn_parms_last = e->expn_parms = NULL; for (d = m->mac_dums; d != NULL; d = d->dum_next) { - p = (struct parm *) malloc(sizeof(struct parm)); + p = (parm_t *) malloc(sizeof(parm_t)); if (p == NULL) fatal(F_OUTMEM, "macro parameter"); p->parm_name = d->dum_name; @@ -405,12 +404,12 @@ static void mac_start_expn(struct mac *m, char *operand) */ static void mac_end_expn(void) { - register struct parm *p; - register struct loc *l; - register struct expn *e; - struct mac *m; - struct parm *p1; - struct loc *l1; + register parm_t *p; + register loc_t *l; + register expn_t *e; + mac_t *m; + parm_t *p1; + loc_t *l1; e = mac_expn; for (p = e->expn_parms; p != NULL; p = p1) { @@ -440,15 +439,15 @@ static void mac_end_expn(void) */ static int mac_rept_expn(void) { - register struct expn *e; - register struct loc *l; - register struct mac *m; - struct loc *l1; + register expn_t *e; + register loc_t *l; + register mac_t *m; + loc_t *l1; e = mac_expn; e->expn_iter++; m = e->expn_mac; - if (*m->mac_rept != NULL && (*m->mac_rept)(e)) { + if (m->mac_rept != NULL && (*m->mac_rept)(e)) { for (l = e->expn_locs; l != NULL; l = l1) { l1 = l->loc_next; free(l->loc_name); @@ -467,12 +466,12 @@ static int mac_rept_expn(void) /* * add source line l to current macro definition */ -void mac_add_line(struct opc *op, char *line) +void mac_add_line(opc_t *op, char *line) { - register struct line *l; - register struct mac *m; + register line_t *l; + register mac_t *m; - if ((l = (struct line *) malloc(sizeof(struct line))) == NULL) + if ((l = (line_t *) malloc(sizeof(line_t))) == NULL) fatal(F_OUTMEM, "macro body line"); l->line_text = strsave(line); l->line_next = NULL; @@ -500,9 +499,9 @@ void mac_add_line(struct opc *op, char *line) /* * get value of dummy s, NULL if not found */ -static const char *mac_get_dummy(struct expn *e, char *s) +static const char *mac_get_dummy(expn_t *e, char *s) { - register struct parm *p; + register parm_t *p; for (p = e->expn_parms; p != NULL; p = p->parm_next) if (strcmp(p->parm_name, s) == 0) @@ -513,9 +512,9 @@ static const char *mac_get_dummy(struct expn *e, char *s) /* * get value of local label s, NULL if not found */ -static const char *mac_get_local(struct expn *e, char *s) +static const char *mac_get_local(expn_t *e, char *s) { - register struct loc *l; + register loc_t *l; for (l = e->expn_locs; l != NULL; l = l->loc_next) if (strcmp(l->loc_name, s) == 0) @@ -527,8 +526,8 @@ static const char *mac_get_local(struct expn *e, char *s) * substitute dummies or locals with actual values in source line s * returns the result in t */ -static void mac_subst(char *t, char *s, struct expn *e, - const char *(*getf)(struct expn *e, char *s)) +static void mac_subst(char *t, char *s, expn_t *e, + const char *(*getf)(expn_t *e, char *s)) { register const char *v; register int m; @@ -679,7 +678,7 @@ static void mac_subst(char *t, char *s, struct expn *e, */ char *mac_expand(char *line) { - register struct expn *e; + register expn_t *e; e = mac_expn; if (e->expn_line == NULL && !mac_rept_expn()) @@ -697,7 +696,7 @@ char *mac_expand(char *line) */ int mac_lookup(char *sym_name) { - register struct mac *m; + register mac_t *m; mac_curr = NULL; for (m = mac_table; m != NULL; m = m->mac_next) @@ -841,7 +840,7 @@ static char *mac_next_parm(char *s) /* * start IRP macro expansion */ -static void mac_start_irp(struct expn *e, char *operand) +static void mac_start_irp(expn_t *e, char *operand) { register char *s; @@ -858,7 +857,7 @@ static void mac_start_irp(struct expn *e, char *operand) /* * repeat IRP macro expansion */ -static int mac_rept_irp(struct expn *e) +static int mac_rept_irp(expn_t *e) { register char *s; @@ -882,7 +881,7 @@ static int mac_rept_irp(struct expn *e) /* * start IRPC macro expansion */ -static void mac_start_irpc(struct expn *e, char *operand) +static void mac_start_irpc(expn_t *e, char *operand) { register char *s; @@ -900,7 +899,7 @@ static void mac_start_irpc(struct expn *e, char *operand) /* * repeat IRPC macro expansion */ -static int mac_rept_irpc(struct expn *e) +static int mac_rept_irpc(expn_t *e) { if (*e->expn_irp != '\0') { *e->expn_parms->parm_val = *e->expn_irp++; @@ -912,10 +911,10 @@ static int mac_rept_irpc(struct expn *e) /* * start MACRO macro expansion */ -static void mac_start_macro(struct expn *e, char *operand) +static void mac_start_macro(expn_t *e, char *operand) { register char *s; - register struct parm *p; + register parm_t *p; s = operand; p = e->expn_parms; @@ -936,7 +935,7 @@ static void mac_start_macro(struct expn *e, char *operand) /* * start REPT macro expansion */ -static void mac_start_rept(struct expn *e, char *operand) +static void mac_start_rept(expn_t *e, char *operand) { UNUSED(operand); @@ -947,7 +946,7 @@ static void mac_start_rept(struct expn *e, char *operand) /* * repeat REPT macro expansion */ -static int mac_rept_rept(struct expn *e) +static int mac_rept_rept(expn_t *e) { return e->expn_iter < e->expn_mac->mac_nrept; } @@ -1048,7 +1047,7 @@ WORD op_irp(int pass, BYTE op_code, BYTE dummy, char *operand, BYTE *ops) { register char *s, *t; register int i; - struct mac *m; + mac_t *m; int err = FALSE, n; UNUSED(pass); @@ -1147,7 +1146,7 @@ WORD op_local(int pass, BYTE dummy1, BYTE dummy2, char *operand, BYTE *ops) WORD op_macro(int pass, BYTE dummy1, BYTE dummy2, char *operand, BYTE *ops) { register char *s, *s1; - register struct mac *m; + register mac_t *m; UNUSED(pass); UNUSED(dummy1); @@ -1183,7 +1182,7 @@ WORD op_macro(int pass, BYTE dummy1, BYTE dummy2, char *operand, BYTE *ops) */ WORD op_rept(int pass, BYTE dummy1, BYTE dummy2, char *operand, BYTE *ops) { - register struct mac *m; + register mac_t *m; UNUSED(pass); UNUSED(dummy1); diff --git a/z80asm/z80amfun.h b/z80asm/z80amfun.h index 85b05ca5..8e3db52e 100644 --- a/z80asm/z80amfun.h +++ b/z80asm/z80amfun.h @@ -19,7 +19,7 @@ extern char *mac_next(int *rp); extern void mac_start_pass(int pass); extern void mac_end_pass(int pass); -extern void mac_add_line(struct opc *op, char *line); +extern void mac_add_line(opc_t *op, char *line); extern char *mac_expand(char *line); extern int mac_lookup(char *sym_name); extern void mac_call(char *operand); diff --git a/z80asm/z80anum.c b/z80asm/z80anum.c index be676a48..fa4b73a1 100644 --- a/z80asm/z80anum.c +++ b/z80asm/z80anum.c @@ -50,18 +50,18 @@ BYTE ctype[256]; /* table for character classification */ #define T_RPAREN 25 /* ) */ /* - * structure operator table + * structure type operator table */ -struct opr { +typedef struct opr { const char *opr_name; /* operator name */ BYTE opr_type; /* operator token type */ -}; +} opr_t; /* * table with operators * must be sorted in ascending order! */ -static struct opr oprtab[] = { +static opr_t oprtab[] = { { "AND", T_AND }, { "EQ", T_EQ }, { "GE", T_GE }, @@ -80,7 +80,7 @@ static struct opr oprtab[] = { { "TYPE", T_TYPE }, { "XOR", T_XOR } }; -static int no_operators = sizeof(oprtab) / sizeof(struct opr); +static int no_operators = sizeof(oprtab) / sizeof(opr_t); static BYTE tok_type; /* token type and flags */ static WORD tok_val; /* token value for T_VAL type */ @@ -121,8 +121,8 @@ void init_ctype(void) */ static BYTE search_opr(char *s) { - register struct opr *low, *mid; - register struct opr *high; + register opr_t *low, *mid; + register opr_t *high; int cond; low = &oprtab[0]; @@ -165,7 +165,7 @@ static int get_token(void) register char *s, *p1; register char *p2; WORD n, m, base; - struct sym *sp; + sym_t *sp; s = scan_pos; tok_val = 0; diff --git a/z80asm/z80aopc.c b/z80asm/z80aopc.c index f87a5b0e..efc2a44d 100644 --- a/z80asm/z80aopc.c +++ b/z80asm/z80aopc.c @@ -24,17 +24,17 @@ static int opccmp(const void *p1, const void *p2); /* * structure operand table */ -struct ope { +typedef struct ope { const char *ope_name; /* operand name */ BYTE ope_sym; /* operand symbol value */ BYTE ope_flags; /* operand flags */ -}; +} ope_t; /* * pseudo op table * includes entries for all common pseudo ops */ -static struct opc opctab_psd[] = { +static opc_t opctab_psd[] = { { ".8080", op_instrset, 2, 0, A_NONE, OP_NOLBL | OP_NOOPR }, { ".DEPHASE", op_org, 3, 0, A_NONE, OP_NOLBL | OP_NOOPR }, { ".LALL", op_misc, 8, 0, A_NONE, OP_NOLBL | OP_NOOPR }, @@ -107,14 +107,14 @@ static struct opc opctab_psd[] = { { "REPT", op_rept, 3, 0, A_NONE, OP_MDEF }, { "TITLE", op_misc, 6, 0, A_NONE, OP_NOLBL | OP_NOPRE } }; -static int no_opc_psd = sizeof(opctab_psd) / sizeof(struct opc); +static int no_opc_psd = sizeof(opctab_psd) / sizeof(opc_t); /* * Z80 opcode table * includes entries for all Z80 opcodes * must not contain any ops already in opctab_psd! */ -static struct opc opctab_z80[] = { +static opc_t opctab_z80[] = { { "ADC", op_sbadc, 0x88, 0x4a, A_STD, 0 }, { "ADD", op_add, 0x80, 0x09, A_STD, 0 }, { "AND", op_alu, 0xa0, 0, A_STD, 0 }, @@ -184,13 +184,13 @@ static struct opc opctab_z80[] = { { "SUB", op_alu, 0x90, 0, A_STD, 0 }, { "XOR", op_alu, 0xa8, 0, A_STD, 0 } }; -static int no_opc_z80 = sizeof(opctab_z80) / sizeof(struct opc); +static int no_opc_z80 = sizeof(opctab_z80) / sizeof(opc_t); /* * table with reserved Z80 register and flag operand words * must be sorted in ascending order! */ -static struct ope opetab_z80[] = { +static ope_t opetab_z80[] = { { "(BC)", REGIBC, 0 }, { "(DE)", REGIDE, 0 }, { "(HL)", REGIHL, 0 }, @@ -226,14 +226,14 @@ static struct ope opetab_z80[] = { { "SP", REGSP, 0 }, { "Z", FLGZ, 0 } }; -static int no_ope_z80 = sizeof(opetab_z80) / sizeof(struct ope); +static int no_ope_z80 = sizeof(opetab_z80) / sizeof(ope_t); /* * 8080 opcode table * includes entries for all 8080 opcodes and 8080 specific pseudo ops * must not contain any ops already in opctab_psd! */ -static struct opc opctab_8080[] = { +static opc_t opctab_8080[] = { { "ACI", op8080_imm, 0xce, 0, A_STD, 0 }, { "ADC", op8080_alu, 0x88, 0, A_STD, 0 }, { "ADD", op8080_alu, 0x80, 0, A_STD, 0 }, @@ -314,13 +314,13 @@ static struct opc opctab_8080[] = { { "XRI", op8080_imm, 0xee, 0, A_STD, 0 }, { "XTHL", op_1b, 0xe3, 0, A_STD, OP_NOOPR } }; -static int no_opc_8080 = sizeof(opctab_8080) / sizeof(struct opc); +static int no_opc_8080 = sizeof(opctab_8080) / sizeof(opc_t); /* * table with reserved 8080 register and flag operand words * must be sorted in ascending order! */ -static struct ope opetab_8080[] = { +static ope_t opetab_8080[] = { { "A", REGA, 0 }, { "B", REGB, 0 }, { "C", REGC, 0 }, @@ -332,12 +332,12 @@ static struct ope opetab_8080[] = { { "PSW", REGPSW, 0 }, { "SP", REGSP, 0 } }; -static int no_ope_8080 = sizeof(opetab_8080) / sizeof(struct ope); +static int no_ope_8080 = sizeof(opetab_8080) / sizeof(ope_t); static int curr_instrset; /* current instructions set */ -static struct opc **opctab; /* current sorted operations table */ +static opc_t **opctab; /* current sorted operations table */ static int no_opcodes; /* current of operations */ -static struct ope *opetab; /* current sorted register/flags table */ +static ope_t *opetab; /* current sorted register/flags table */ static int no_operands; /* current number of register/flags */ /* @@ -345,9 +345,9 @@ static int no_operands; /* current number of register/flags */ */ void instrset(int is) { - register struct opc *p, **q; + register opc_t *p, **q; register int i; - struct opc *opc; + opc_t *opc; int nopc; if (is == curr_instrset) @@ -372,7 +372,7 @@ void instrset(int is) if (opctab == NULL) { i = no_opc_psd; i += (no_opc_z80 > no_opc_8080 ? no_opc_z80 : no_opc_8080); - opctab = (struct opc **) malloc(sizeof(struct opc *) * i); + opctab = (opc_t **) malloc(sizeof(opc_t *) * i); if (opctab == NULL) fatal(F_OUTMEM, "operations table"); } @@ -382,7 +382,7 @@ void instrset(int is) *q++ = p++; for (i = 0, p = opc; i < nopc; i++) *q++ = p++; - qsort(opctab, no_opcodes, sizeof(struct opc *), opccmp); + qsort(opctab, no_opcodes, sizeof(opc_t *), opccmp); curr_instrset = is; } @@ -391,18 +391,18 @@ void instrset(int is) */ static int opccmp(const void *p1, const void *p2) { - return strcmp((*(const struct opc **) p1)->op_name, - (*(const struct opc **) p2)->op_name); + return strcmp((*(const opc_t **) p1)->op_name, + (*(const opc_t **) p2)->op_name); } /* * do binary search for op_name in sorted table opctab * returns pointer to table element, or NULL if not found */ -struct opc *search_op(char *op_name) +opc_t *search_op(char *op_name) { - register struct opc **low, **mid; - register struct opc **high; + register opc_t **low, **mid; + register opc_t **high; int cond; low = opctab; @@ -428,8 +428,8 @@ struct opc *search_op(char *op_name) */ BYTE get_reg(char *s) { - register struct ope *low, *mid; - register struct ope *high; + register ope_t *low, *mid; + register ope_t *high; int cond; if (s == NULL || *s == '\0') diff --git a/z80asm/z80aopc.h b/z80asm/z80aopc.h index 069a2456..ecdde41a 100644 --- a/z80asm/z80aopc.h +++ b/z80asm/z80aopc.h @@ -88,9 +88,9 @@ #define OPE_UNDOC 0x01 /* undocumented operand */ /* - * structure opcode table + * structure type opcode table */ -struct opc { +typedef struct opc { const char *op_name; /* opcode name */ WORD (*op_func)(int pass, BYTE b1, BYTE b2, char *operand, BYTE *ops); /* opcode function */ @@ -98,10 +98,10 @@ struct opc { BYTE op_c2; /* second base opcode */ BYTE op_a_mode; /* listing address mode */ WORD op_flags; /* opcode flags */ -}; +} opc_t; extern void instrset(int is); -extern struct opc *search_op(char *op_name); +extern opc_t *search_op(char *op_name); extern BYTE get_reg(char *s); #endif /* !Z80AOPC_INC */ diff --git a/z80asm/z80apfun.c b/z80asm/z80apfun.c index 5305d616..01b9f2a6 100644 --- a/z80asm/z80apfun.c +++ b/z80asm/z80apfun.c @@ -169,7 +169,7 @@ WORD op_radix(int pass, BYTE dummy1, BYTE dummy2, char *operand, BYTE *ops) */ WORD op_equ(int pass, BYTE dummy1, BYTE dummy2, char *operand, BYTE *ops) { - register struct sym *sp; + register sym_t *sp; const char *label; WORD addr; diff --git a/z80asm/z80asm.c b/z80asm/z80asm.c index 152cbbda..5a3feb0b 100644 --- a/z80asm/z80asm.c +++ b/z80asm/z80asm.c @@ -451,7 +451,7 @@ static void process_file(char *fn) */ static int process_line(char *line) { - register struct opc *op; + register opc_t *op; register WORD op_count; char *p; int gencode; /* we are not in a false conditional section */ diff --git a/z80asm/z80atab.c b/z80asm/z80atab.c index 6bea4e14..f1944676 100644 --- a/z80asm/z80atab.c +++ b/z80asm/z80atab.c @@ -20,12 +20,12 @@ static int hash(const char *name); static int namecmp(const void *p1, const void *p2); static int valcmp(const void *p1, const void *p2); -static struct sym *symtab[HASHSIZE]; /* symbol table */ +static sym_t *symtab[HASHSIZE]; /* symbol table */ static int symcnt; /* number of symbols defined */ -static struct sym **symarray; /* sorted symbol table */ +static sym_t **symarray; /* sorted symbol table */ static int symsort; /* sort mode for iterator */ static int symidx; /* hash table index for iterator */ -static struct sym *symptr; /* symbol pointer for iterator */ +static sym_t *symptr; /* symbol pointer for iterator */ static int symmax; /* max. symbol name length observed */ static WORD last_symval; /* value of last used symbol */ @@ -33,9 +33,9 @@ static WORD last_symval; /* value of last used symbol */ * hash search for sym_name in symbol table symtab * returns pointer to table element, or NULL if not found */ -struct sym *look_sym(const char *sym_name) +sym_t *look_sym(const char *sym_name) { - register struct sym *sp; + register sym_t *sp; for (sp = symtab[hash(sym_name)]; sp != NULL; sp = sp->sym_next) if (strcmp(sym_name, sp->sym_name) == 0) { @@ -50,9 +50,9 @@ struct sym *look_sym(const char *sym_name) * set refflg when found * returns pointer to table element, or NULL if not found */ -struct sym *get_sym(const char *sym_name) +sym_t *get_sym(const char *sym_name) { - register struct sym *sp; + register sym_t *sp; if ((sp = look_sym(sym_name)) != NULL) sp->sym_refflg = TRUE; @@ -72,12 +72,12 @@ WORD sym_lastval(void) */ void new_sym(const char *sym_name, WORD sym_val) { - register struct sym *sp; + register sym_t *sp; register int n; register int hashval; n = strlen(sym_name); - sp = (struct sym *) malloc(sizeof(struct sym)); + sp = (sym_t *) malloc(sizeof(sym_t)); if (sp == NULL || (sp->sym_name = (char *) malloc(n + 1)) == NULL) fatal(F_OUTMEM, "symbols"); strcpy(sp->sym_name, sym_name); @@ -97,7 +97,7 @@ void new_sym(const char *sym_name, WORD sym_val) */ void put_sym(const char *sym_name, WORD sym_val) { - register struct sym *sp; + register sym_t *sp; if ((sp = get_sym(sym_name)) == NULL) new_sym(sym_name, sym_val); @@ -111,7 +111,7 @@ void put_sym(const char *sym_name, WORD sym_val) */ void put_label(const char *label, WORD addr, int pass) { - register struct sym *sp; + register sym_t *sp; if ((sp = look_sym(label)) == NULL) new_sym(label, addr); @@ -143,9 +143,9 @@ int get_symmax(void) /* * get first symbol for listing, sorted as specified in sort_mode */ -struct sym *first_sym(int sort_mode) +sym_t *first_sym(int sort_mode) { - register struct sym *sp; + register sym_t *sp; register int j; register int i; @@ -161,14 +161,13 @@ struct sym *first_sym(int sort_mode) return symptr; case SYM_SORTN: case SYM_SORTA: - symarray = (struct sym **) malloc(sizeof(struct sym *) - * symcnt); + symarray = (sym_t **) malloc(sizeof(sym_t *) * symcnt); if (symarray == NULL) fatal(F_OUTMEM, "sorting symbol table"); for (i = 0, j = 0; i < HASHSIZE; i++) for (sp = symtab[i]; sp != NULL; sp = sp->sym_next) symarray[j++] = sp; - qsort(symarray, symcnt, sizeof(struct sym *), + qsort(symarray, symcnt, sizeof(sym_t *), sort_mode == SYM_SORTN ? namecmp : valcmp); symidx = 0; return symarray[symidx]; @@ -181,7 +180,7 @@ struct sym *first_sym(int sort_mode) /* * get next symbol for listing */ -struct sym *next_sym(void) +sym_t *next_sym(void) { if (symsort == SYM_UNSORT) { if ((symptr = symptr->sym_next) == NULL) { @@ -203,8 +202,8 @@ struct sym *next_sym(void) */ static int namecmp(const void *p1, const void *p2) { - return strcmp((*(const struct sym **) p1)->sym_name, - (*(const struct sym **) p2)->sym_name); + return strcmp((*(const sym_t **) p1)->sym_name, + (*(const sym_t **) p2)->sym_name); } /* @@ -215,8 +214,8 @@ static int valcmp(const void *p1, const void *p2) { register WORD n1, n2; - n1 = (*(const struct sym **) p1)->sym_val; - n2 = (*(const struct sym **) p2)->sym_val; + n1 = (*(const sym_t **) p1)->sym_val; + n2 = (*(const sym_t **) p2)->sym_val; if (n1 < n2) return -1; else if (n1 > n2) diff --git a/z80asm/z80atab.h b/z80asm/z80atab.h index 74e07bc9..ab807ee6 100644 --- a/z80asm/z80atab.h +++ b/z80asm/z80atab.h @@ -10,17 +10,17 @@ #include "z80asm.h" /* - * structure symbol table entries + * structure type symbol table entries */ -struct sym { +typedef struct sym { char *sym_name; /* symbol name */ WORD sym_val; /* symbol value */ int sym_refflg; /* symbol reference flag */ struct sym *sym_next; /* next entry */ -}; +} sym_t; -extern struct sym *look_sym(const char *sym_name); -extern struct sym *get_sym(const char *sym_name); +extern sym_t *look_sym(const char *sym_name); +extern sym_t *get_sym(const char *sym_name); extern WORD sym_lastval(void); extern void new_sym(const char *sym_name, WORD sym_val); @@ -28,7 +28,7 @@ extern void put_sym(const char *sym_name, WORD sym_val); extern void put_label(const char *label, WORD addr, int pass); extern int get_symmax(void); -extern struct sym *first_sym(int sort_mode); -extern struct sym *next_sym(void); +extern sym_t *first_sym(int sort_mode); +extern sym_t *next_sym(void); #endif /* !Z80ATAB_INC */ diff --git a/z80core/alt8080.h b/z80core/alt8080.h index 7fbe73fd..a01e554f 100644 --- a/z80core/alt8080.h +++ b/z80core/alt8080.h @@ -75,7 +75,7 @@ #undef P BYTE t, res, cout, P; - struct cpu_reg w; /* working register */ + cpu_reg_t w; /* working register */ uint64_t clk; #define W w.w diff --git a/z80core/altregs.h b/z80core/altregs.h index aea08112..3043beef 100644 --- a/z80core/altregs.h +++ b/z80core/altregs.h @@ -14,43 +14,45 @@ #define ALTREGS_INC #if _BYTE_ORDER == _LITTLE_ENDIAN -struct cpu_reg { +typedef struct cpu_reg { union { struct { BYTE l; BYTE h; }; WORD w; }; -}; +} cpu_reg_t; #elif _BYTE_ORDER == _BIG_ENDIAN -struct cpu_reg { +typedef struct cpu_reg { union { struct { BYTE h; BYTE l; }; WORD w; }; -}; +} cpu_reg_t; #else #error "Unsupported byte order" #endif -extern struct cpu_regs { - struct cpu_reg af; /* primary registers */ - struct cpu_reg bc; - struct cpu_reg de; - struct cpu_reg hl; - struct cpu_reg sp; /* stack pointer */ - struct cpu_reg pc; /* program counter */ +typedef struct cpu_regs { + cpu_reg_t af; /* primary registers */ + cpu_reg_t bc; + cpu_reg_t de; + cpu_reg_t hl; + cpu_reg_t sp; /* stack pointer */ + cpu_reg_t pc; /* program counter */ #ifndef EXCLUDE_Z80 - struct cpu_reg af_; /* Z80 alternate registers */ - struct cpu_reg bc_; - struct cpu_reg de_; - struct cpu_reg hl_; - struct cpu_reg ix; /* Z80 index registers */ - struct cpu_reg iy; + cpu_reg_t af_; /* Z80 alternate registers */ + cpu_reg_t bc_; + cpu_reg_t de_; + cpu_reg_t hl_; + cpu_reg_t ix; /* Z80 index registers */ + cpu_reg_t iy; BYTE i; /* Z80 interrupt register */ BYTE r; /* Z80 refresh register (7-bit counter) */ BYTE r_; /* 8th bit of R (can be loaded with LD R,A) */ #endif BYTE iff; /* interrupt flags */ -} cpu_regs; +} cpu_regs_t; + +extern cpu_regs_t cpu_regs; #define AF cpu_regs.af.w #define A cpu_regs.af.h diff --git a/z80core/altz80.h b/z80core/altz80.h index 2d09a32c..5c8ec98d 100644 --- a/z80core/altz80.h +++ b/z80core/altz80.h @@ -83,8 +83,8 @@ WORD s, d; int32_t tl; /* loops can run for 65535 * 21 + 16 cycles */ #endif - struct cpu_reg w; /* working register */ - struct cpu_reg ir; /* current index register (HL, IX, IY) */ + cpu_reg_t w; /* working register */ + cpu_reg_t ir; /* current index register (HL, IX, IY) */ uint64_t clk; #define W w.w diff --git a/z80core/simcore.c b/z80core/simcore.c index 73dc074e..23dbcb4c 100644 --- a/z80core/simcore.c +++ b/z80core/simcore.c @@ -366,7 +366,7 @@ void io_out(BYTE addrl, BYTE addrh, BYTE data) /* * Start a bus request cycle */ -void start_bus_request(BusDMA_t mode, Tstates_t (*bus_master)(BYTE bus_ack)) +void start_bus_request(BusDMA_t mode, BusDMAFunc_t *bus_master) { bus_mode = mode; dma_bus_master = bus_master; diff --git a/z80core/simcore.h b/z80core/simcore.h index d55b10b1..e70426cb 100644 --- a/z80core/simcore.h +++ b/z80core/simcore.h @@ -25,8 +25,7 @@ extern void report_cpu_stats(void); extern BYTE io_in(BYTE addrl, BYTE addrh); extern void io_out(BYTE addrl, BYTE addrh, BYTE data); -extern void start_bus_request(BusDMA_t mode, - Tstates_t (*bus_master)(BYTE bus_ack)); +extern void start_bus_request(BusDMA_t mode, BusDMAFunc_t *bus_master); extern void end_bus_request(void); #endif /* !SIMCORE_INC */ diff --git a/z80core/simdefs.h b/z80core/simdefs.h index 0ad9222f..069c681e 100644 --- a/z80core/simdefs.h +++ b/z80core/simdefs.h @@ -89,9 +89,14 @@ typedef int16_t SWORD; /* 16 bit signed */ typedef uint8_t BYTE; /* 8 bit unsigned */ typedef int8_t SBYTE; /* 8 bit signed */ +typedef BYTE (in_func_t)(void); /* port input function */ +typedef void (out_func_t)(const BYTE data); /* port output function */ + typedef uint64_t Tstates_t; /* uint64 for counting T-states */ + typedef enum { BUS_DMA_NONE, BUS_DMA_BYTE, BUS_DMA_BURST, BUS_DMA_CONTINUOUS } BusDMA_t; +typedef Tstates_t (BusDMAFunc_t)(const BYTE bus_ack); #ifdef IOPANEL typedef struct port_flags { diff --git a/z80core/simglb.c b/z80core/simglb.c index 4230f95a..c0767907 100644 --- a/z80core/simglb.c +++ b/z80core/simglb.c @@ -40,7 +40,7 @@ WORD PC; /* program counter */ WORD SP; /* stack pointer */ BYTE IFF; /* interrupt flags */ #else -struct cpu_regs cpu_regs; /* CPU registers */ +cpu_regs_t cpu_regs; /* CPU registers */ #endif Tstates_t T; /* CPU clock */ uint64_t cpu_time; /* time spent running CPU in us */ @@ -65,7 +65,7 @@ int int_data = -1; /* data from interrupting device on data bus */ int int_protection; /* to delay interrupts after EI */ BYTE bus_request; /* request address/data bus from CPU */ BusDMA_t bus_mode; /* current bus mode for DMA */ -Tstates_t (*dma_bus_master)(BYTE bus_ack); /* DMA bus master call back func */ +BusDMAFunc_t *dma_bus_master; /* DMA bus master call back func */ int tmax; /* max t-states to execute in 10ms */ int cpu_needed; /* don't adjust CPU freq if needed */ diff --git a/z80core/simglb.h b/z80core/simglb.h index 005654d0..38eed75c 100644 --- a/z80core/simglb.h +++ b/z80core/simglb.h @@ -50,7 +50,7 @@ extern int int_nmi, int_mode; extern int int_int, int_data, int_protection; extern BYTE bus_request; extern BusDMA_t bus_mode; -extern Tstates_t (*dma_bus_master)(BYTE); +extern BusDMAFunc_t *dma_bus_master; extern int tmax, cpu_needed; #ifdef FRONTPANEL diff --git a/z80core/simice.c b/z80core/simice.c index b1c9a92a..779702c3 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -41,7 +41,7 @@ * Variables for history memory */ #ifdef HISIZE -struct history his[HISIZE]; /* memory to hold trace information */ +history_t his[HISIZE]; /* memory to hold trace information */ int h_next; /* index into trace memory */ int h_flag; /* flag for trace memory overrun */ #endif @@ -50,7 +50,7 @@ int h_flag; /* flag for trace memory overrun */ * Variables for breakpoint memory */ #ifdef SBSIZE -struct softbreak soft[SBSIZE]; /* memory to hold breakpoint information */ +softbreak_t soft[SBSIZE]; /* memory to hold breakpoint information */ #endif /* @@ -658,7 +658,7 @@ static void do_port(char *s) /* * register definitions table (must be sorted by name length) */ -static const struct reg_def { +typedef struct reg_def { const char *name; /* register name */ char len; /* register name length */ const char *prt; /* printable register name */ @@ -674,7 +674,9 @@ static const struct reg_def { int *rf; /* F or F' register pointer */ BYTE rm; /* status register flag mask */ }; -} regs[] = { +} reg_def_t; + +static reg_def_t const regs[] = { #ifndef EXCLUDE_Z80 { "bc'", 3, "BC'", 1, R_88, .r8h = &B_, .r8l = &C_ }, { "de'", 3, "DE'", 1, R_88, .r8h = &D_, .r8l = &E_ }, @@ -726,7 +728,7 @@ static const struct reg_def { { "h", 1, "H", 0, R_8, .r8 = &H }, { "l", 1, "L", 0, R_8, .r8 = &L } }; -static int nregs = sizeof(regs) / sizeof(struct reg_def); +static int nregs = sizeof(regs) / sizeof(reg_def_t); /* * Register modify @@ -734,7 +736,7 @@ static int nregs = sizeof(regs) / sizeof(struct reg_def); static void do_reg(char *s) { register int i; - register const struct reg_def *p; + register const reg_def_t *p; WORD w; while (isspace((unsigned char) *s)) @@ -979,8 +981,7 @@ static void do_break(char *s) while (isspace((unsigned char) *s)) s++; if (*s == '\0') { - memset((char *) soft, 0, - sizeof(struct softbreak) * SBSIZE); + memset((char *) soft, 0, sizeof(softbreak_t) * SBSIZE); return; } if (!isxdigit((unsigned char) *s)) { @@ -995,7 +996,7 @@ static void do_break(char *s) if (i == SBSIZE) printf("No software breakpoint at address %04x\n", a); else - memset((char *) &soft[i], 0, sizeof(struct softbreak)); + memset((char *) &soft[i], 0, sizeof(softbreak_t)); return; } while (isspace((unsigned char) *s)) @@ -1065,7 +1066,7 @@ static void do_hist(char *s) int i, l, b, e, sa; if (tolower((unsigned char) *s) == 'c') { - memset((char *) his, 0, sizeof(struct history) * HISIZE); + memset((char *) his, 0, sizeof(history_t) * HISIZE); h_next = 0; h_flag = 0; return; diff --git a/z80core/simice.h b/z80core/simice.h index ccbeff77..5279a402 100644 --- a/z80core/simice.h +++ b/z80core/simice.h @@ -14,7 +14,7 @@ #ifdef WANT_ICE #ifdef HISIZE -struct history { /* structure of a history entry */ +typedef struct history { /* structure of a history entry */ int h_cpu; /* CPU type */ WORD h_addr; /* address of execution */ WORD h_af; /* register AF */ @@ -26,21 +26,21 @@ struct history { /* structure of a history entry */ WORD h_iy; /* register IY */ #endif WORD h_sp; /* register SP */ -}; +} history_t; -extern struct history his[HISIZE]; +extern history_t his[HISIZE]; extern int h_next, h_flag; #endif #ifdef SBSIZE -struct softbreak { /* structure of a breakpoint */ +typedef struct softbreak { /* structure of a breakpoint */ WORD sb_addr; /* address of breakpoint */ BYTE sb_oldopc; /* op-code at address of breakpoint */ int sb_passcount; /* pass counter of breakpoint */ int sb_pass; /* no. of pass to break */ -}; +} softbreak_t; -extern struct softbreak soft[SBSIZE]; +extern softbreak_t soft[SBSIZE]; #endif #ifdef WANT_TIM diff --git a/z80sim/srcsim/simio.c b/z80sim/srcsim/simio.c index c9733aaf..784449d3 100644 --- a/z80sim/srcsim/simio.c +++ b/z80sim/srcsim/simio.c @@ -51,7 +51,7 @@ static BYTE fp_value; /* port 255 value, can be set with p command */ * This array contains function pointers for every input * I/O port (0 - 255), to do the required I/O. */ -BYTE (*const port_in[256])(void) = { +in_func_t *const port_in[256] = { [ 0] = p000_in, [ 1] = p001_in, [160] = hwctl_in, /* virtual hardware control */ @@ -63,7 +63,7 @@ BYTE (*const port_in[256])(void) = { * This array contains function pointers for every output * I/O port (0 - 255), to do the required I/O. */ -void (*const port_out[256])(BYTE data) = { +out_func_t *const port_out[256] = { [ 1] = p001_out, [160] = hwctl_out, /* virtual hardware control */ [254] = p254_out, /* write to front panel switches */ diff --git a/z80sim/srcsim/simio.h b/z80sim/srcsim/simio.h index 23b0a5a1..2db99140 100644 --- a/z80sim/srcsim/simio.h +++ b/z80sim/srcsim/simio.h @@ -12,8 +12,8 @@ #define IO_DATA_UNUSED 0xff /* data returned on unused ports */ -extern BYTE (*const port_in[256])(void); -extern void (*const port_out[256])(BYTE data); +extern in_func_t *const port_in[256]; +extern out_func_t *const port_out[256]; extern void init_io(void); extern void exit_io(void); From e5adec88d8ed8aaf14817398803d4e193a3ac2d4 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 03:53:57 +0100 Subject: [PATCH 02/19] make m1_step and wait_step() bool --- altairsim/srcsim/simctl.c | 15 ++++++++------- altairsim/srcsim/simctl.h | 4 +++- cromemcosim/srcsim/simctl.c | 15 ++++++++------- cromemcosim/srcsim/simctl.h | 4 +++- imsaisim/srcsim/simctl.c | 15 ++++++++------- imsaisim/srcsim/simctl.h | 4 +++- intelmdssim/srcsim/simctl.c | 8 ++++---- intelmdssim/srcsim/simctl.h | 4 +++- z80core/altz80.h | 8 ++++---- z80core/sim8080.c | 3 ++- z80core/simcore.c | 3 ++- z80core/simglb.c | 3 ++- z80core/simglb.h | 5 ++++- z80core/simz80-cb.c | 6 +++++- z80core/simz80-dd.c | 6 +++++- z80core/simz80-ed.c | 6 +++++- z80core/simz80-fd.c | 6 +++++- z80core/simz80.c | 3 ++- 18 files changed, 76 insertions(+), 42 deletions(-) diff --git a/altairsim/srcsim/simctl.c b/altairsim/srcsim/simctl.c index a5fd0341..ca65bbe7 100644 --- a/altairsim/srcsim/simctl.c +++ b/altairsim/srcsim/simctl.c @@ -35,6 +35,7 @@ * 04-JAN-2025 add SDL2 support */ +#include #include #include #include @@ -318,13 +319,13 @@ static void step_clicked(int state, int val) /* * Single step through the machine cycles after first M1 */ -int wait_step(void) +bool wait_step(void) { - int ret = 0; + bool ret = false; if (cpu_state != ST_SINGLE_STEP) { cpu_bus &= ~CPU_M1; - m1_step = 0; + m1_step = false; return ret; } @@ -345,11 +346,11 @@ int wait_step(void) fp_clock++; fp_sampleData(); sleep_for_ms(1); - ret = 1; + ret = true; } cpu_bus &= ~CPU_M1; - m1_step = 0; + m1_step = false; return ret; } @@ -386,7 +387,7 @@ static void reset_clicked(int state, int val) reset = 1; cpu_state |= ST_RESET; IFF = 0; - m1_step = 0; + m1_step = false; break; case FP_SW_CENTER: if (reset) { @@ -412,7 +413,7 @@ static void reset_clicked(int state, int val) /* reset CPU and I/O devices */ reset = 2; cpu_state |= ST_RESET; - m1_step = 0; + m1_step = false; IFF = 0; reset_io(); break; diff --git a/altairsim/srcsim/simctl.h b/altairsim/srcsim/simctl.h index 43178266..cc395df5 100644 --- a/altairsim/srcsim/simctl.h +++ b/altairsim/srcsim/simctl.h @@ -7,11 +7,13 @@ #ifndef SIMCTL_INC #define SIMCTL_INC +#include + extern int boot_switch; /* boot address for switch */ extern void mon(void); -extern int wait_step(void); +extern bool wait_step(void); extern void wait_int_step(void); #endif /* !SIMCTL_INC */ diff --git a/cromemcosim/srcsim/simctl.c b/cromemcosim/srcsim/simctl.c index 6dc9c7de..4eb4dcab 100644 --- a/cromemcosim/srcsim/simctl.c +++ b/cromemcosim/srcsim/simctl.c @@ -30,6 +30,7 @@ * 04-JAN-2025 add SDL2 support */ +#include #include #include #include @@ -323,13 +324,13 @@ static void step_clicked(int state, int val) /* * Single step through the machine cycles after M1 */ -int wait_step(void) +bool wait_step(void) { - int ret = 0; + bool ret = false; if (cpu_state != ST_SINGLE_STEP) { cpu_bus &= ~CPU_M1; - m1_step = 0; + m1_step = false; return ret; } @@ -350,11 +351,11 @@ int wait_step(void) fp_clock++; fp_sampleData(); sleep_for_ms(10); - ret = 1; + ret = true; } cpu_bus &= ~CPU_M1; - m1_step = 0; + m1_step = false; return ret; } @@ -390,7 +391,7 @@ static void reset_clicked(int state, int val) /* reset CPU only */ reset = 1; cpu_state |= ST_RESET; - m1_step = 0; + m1_step = false; IFF = 0; fp_led_output = 0; break; @@ -414,7 +415,7 @@ static void reset_clicked(int state, int val) /* reset CPU and I/O devices */ reset = 2; cpu_state |= ST_RESET; - m1_step = 0; + m1_step = false; IFF = 0; fp_led_output = 0; reset_io(); diff --git a/cromemcosim/srcsim/simctl.h b/cromemcosim/srcsim/simctl.h index 31535e59..081d513d 100644 --- a/cromemcosim/srcsim/simctl.h +++ b/cromemcosim/srcsim/simctl.h @@ -7,9 +7,11 @@ #ifndef SIMCTL_INC #define SIMCTL_INC +#include + extern void mon(void); -extern int wait_step(void); +extern bool wait_step(void); extern void wait_int_step(void); #endif /* !SIMCTL_INC */ diff --git a/imsaisim/srcsim/simctl.c b/imsaisim/srcsim/simctl.c index 08777141..767536dd 100644 --- a/imsaisim/srcsim/simctl.c +++ b/imsaisim/srcsim/simctl.c @@ -34,6 +34,7 @@ * 04-JAN-2025 add SDL2 support */ +#include #include #include #include @@ -324,13 +325,13 @@ static void step_clicked(int state, int val) /* * Single step through the machine cycles after M1 */ -int wait_step(void) +bool wait_step(void) { - int ret = 0; + bool ret = false; if (cpu_state != ST_SINGLE_STEP) { cpu_bus &= ~CPU_M1; - m1_step = 0; + m1_step = false; return ret; } @@ -351,11 +352,11 @@ int wait_step(void) fp_clock++; fp_sampleData(); sleep_for_ms(10); - ret = 1; + ret = true; } cpu_bus &= ~CPU_M1; - m1_step = 0; + m1_step = false; return ret; } @@ -392,7 +393,7 @@ static void reset_clicked(int state, int val) /* reset CPU only */ reset = 1; cpu_state |= ST_RESET; - m1_step = 0; + m1_step = false; IFF = 0; fp_led_output = 0; break; @@ -413,7 +414,7 @@ static void reset_clicked(int state, int val) /* reset CPU and I/O devices */ reset = 1; cpu_state |= ST_RESET; - m1_step = 0; + m1_step = false; IFF = 0; fp_led_output = 0; reset_io(); diff --git a/imsaisim/srcsim/simctl.h b/imsaisim/srcsim/simctl.h index fa3aaec9..0c2300f0 100644 --- a/imsaisim/srcsim/simctl.h +++ b/imsaisim/srcsim/simctl.h @@ -7,9 +7,11 @@ #ifndef SIMCTL_INC #define SIMCTL_INC +#include + extern void mon(void); -extern int wait_step(void); +extern bool wait_step(void); extern void wait_int_step(void); #endif /* !SIMCTL_INC */ diff --git a/intelmdssim/srcsim/simctl.c b/intelmdssim/srcsim/simctl.c index 9815f5b6..3eda345f 100644 --- a/intelmdssim/srcsim/simctl.c +++ b/intelmdssim/srcsim/simctl.c @@ -221,11 +221,11 @@ static void int_clicked(int state, int val) /* * Single step through the machine cycles after M1 */ -int wait_step(void) +bool wait_step(void) { cpu_bus &= ~CPU_M1; - m1_step = 0; - return 0; + m1_step = false; + return false; } /* @@ -250,7 +250,7 @@ static void reset_clicked(int state, int val) break; case FP_SW_UP: cpu_state |= ST_RESET; - m1_step = 0; + m1_step = false; IFF = 0; reset_io(); reset_cpu(); diff --git a/intelmdssim/srcsim/simctl.h b/intelmdssim/srcsim/simctl.h index 143f8b92..a41aed40 100644 --- a/intelmdssim/srcsim/simctl.h +++ b/intelmdssim/srcsim/simctl.h @@ -8,11 +8,13 @@ #ifndef SIMCTL_INC #define SIMCTL_INC +#include + extern BYTE boot_switch; extern void mon(void); -extern int wait_step(void); +extern bool wait_step(void); extern void wait_int_step(void); #endif /* !SIMCTL_INC */ diff --git a/z80core/altz80.h b/z80core/altz80.h index 5c8ec98d..edc7f26f 100644 --- a/z80core/altz80.h +++ b/z80core/altz80.h @@ -1380,7 +1380,7 @@ #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { @@ -1624,7 +1624,7 @@ #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { @@ -1722,7 +1722,7 @@ #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { @@ -2402,7 +2402,7 @@ #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { diff --git a/z80core/sim8080.c b/z80core/sim8080.c index 8bed6805..0678eb60 100644 --- a/z80core/sim8080.c +++ b/z80core/sim8080.c @@ -19,6 +19,7 @@ #include "sim8080.h" #ifdef FRONTPANEL +#include #include "frontpanel.h" #include "simctl.h" #endif @@ -582,7 +583,7 @@ void cpu_8080(void) int_data = -1; #ifdef FRONTPANEL if (F_flag) - m1_step = 1; + m1_step = true; #endif } leave: diff --git a/z80core/simcore.c b/z80core/simcore.c index 23dbcb4c..036b46f7 100644 --- a/z80core/simcore.c +++ b/z80core/simcore.c @@ -29,6 +29,7 @@ #include "simcore.h" #ifdef FRONTPANEL +#include #include "frontpanel.h" #include "simctl.h" #endif @@ -255,7 +256,7 @@ BYTE io_in(BYTE addrl, BYTE addrh) { uint64_t clk; #ifdef FRONTPANEL - int val; + bool val; #else #ifndef SIMPLEPANEL UNUSED(addrh); diff --git a/z80core/simglb.c b/z80core/simglb.c index c0767907..2d419916 100644 --- a/z80core/simglb.c +++ b/z80core/simglb.c @@ -10,6 +10,7 @@ * This module contains the global variables other than memory management */ +#include #include #include @@ -47,7 +48,7 @@ uint64_t cpu_time; /* time spent running CPU in us */ #ifdef BUS_8080 BYTE cpu_bus; /* CPU bus status, for frontpanels */ -int m1_step; /* flag for waiting at M1 in single step */ +bool m1_step; /* flag for waiting at M1 in single step */ #endif BYTE io_port; /* I/O port used */ diff --git a/z80core/simglb.h b/z80core/simglb.h index 38eed75c..7cc742ed 100644 --- a/z80core/simglb.h +++ b/z80core/simglb.h @@ -13,6 +13,9 @@ * Declaration of variables in simglb.c */ +#include +#include + #include "sim.h" #include "simdefs.h" @@ -36,7 +39,7 @@ extern uint64_t cpu_time; #ifdef BUS_8080 extern BYTE cpu_bus; -extern int m1_step; +extern bool m1_step; #endif extern BYTE io_port, io_data; diff --git a/z80core/simz80-cb.c b/z80core/simz80-cb.c index f5b55216..b81b165b 100644 --- a/z80core/simz80-cb.c +++ b/z80core/simz80-cb.c @@ -16,6 +16,10 @@ #include "simmem.h" #include "simz80-cb.h" +#ifdef BUS_8080 +#include +#endif + #ifdef FRONTPANEL #include #include "frontpanel.h" @@ -380,7 +384,7 @@ int op_cb_handle(void) #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { diff --git a/z80core/simz80-dd.c b/z80core/simz80-dd.c index 19b7e619..67956b0d 100644 --- a/z80core/simz80-dd.c +++ b/z80core/simz80-dd.c @@ -17,6 +17,10 @@ #include "simz80-dd.h" #include "simz80-ddcb.h" +#ifdef BUS_8080 +#include +#endif + #ifdef FRONTPANEL #include #include "frontpanel.h" @@ -347,7 +351,7 @@ int op_dd_handle(void) #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { diff --git a/z80core/simz80-ed.c b/z80core/simz80-ed.c index bf01b14e..76894cd7 100644 --- a/z80core/simz80-ed.c +++ b/z80core/simz80-ed.c @@ -17,6 +17,10 @@ #include "simmem.h" #include "simz80-ed.h" +#ifdef BUS_8080 +#include +#endif + #ifdef FRONTPANEL #include #include "frontpanel.h" @@ -329,7 +333,7 @@ int op_ed_handle(void) #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { diff --git a/z80core/simz80-fd.c b/z80core/simz80-fd.c index b487da22..9d5836b5 100644 --- a/z80core/simz80-fd.c +++ b/z80core/simz80-fd.c @@ -17,6 +17,10 @@ #include "simz80-fd.h" #include "simz80-fdcb.h" +#ifdef BUS_8080 +#include +#endif + #ifdef FRONTPANEL #include #include "frontpanel.h" @@ -347,7 +351,7 @@ int op_fd_handle(void) #ifdef BUS_8080 /* M1 opcode fetch */ cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - m1_step = 1; + m1_step = true; #endif #ifdef FRONTPANEL if (F_flag) { diff --git a/z80core/simz80.c b/z80core/simz80.c index a35ec382..686e48d6 100644 --- a/z80core/simz80.c +++ b/z80core/simz80.c @@ -23,6 +23,7 @@ #include "simz80-fd.h" #ifdef FRONTPANEL +#include #include "frontpanel.h" #include "simctl.h" #endif @@ -591,7 +592,7 @@ void cpu_z80(void) int_data = -1; #ifdef FRONTPANEL if (F_flag) - m1_step = 1; + m1_step = true; #endif R++; /* increment refresh register */ } From 6aa9c51551bea08e0f3a07cb8d9f83cd1fc57655 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 04:24:14 +0100 Subject: [PATCH 03/19] clean-up std types includes simdefs.h now includes inttypes.h, stdbool.h, and stddef.h. Don't include these explicitly anymore in machines and iodevices. --- altairsim/srcsim/simcfg.c | 1 - altairsim/srcsim/simctl.c | 1 - altairsim/srcsim/simctl.h | 3 ++- altairsim/srcsim/simio.c | 1 - altairsim/srcsim/simmem.c | 1 - altairsim/srcsim/simport.h | 3 +-- cpmsim/srcsim/simctl.c | 1 - cpmsim/srcsim/simio.c | 1 - cpmsim/srcsim/simmem.c | 1 - cpmsim/srcsim/simport.h | 3 +-- cromemcosim/srcsim/simcfg.c | 1 - cromemcosim/srcsim/simctl.c | 1 - cromemcosim/srcsim/simctl.h | 3 ++- cromemcosim/srcsim/simio.c | 1 - cromemcosim/srcsim/simmem.c | 1 - cromemcosim/srcsim/simport.h | 3 +-- imsaisim/srcsim/simcfg.c | 1 - imsaisim/srcsim/simcfg.h | 3 +++ imsaisim/srcsim/simctl.c | 1 - imsaisim/srcsim/simctl.h | 3 ++- imsaisim/srcsim/simio.c | 1 - imsaisim/srcsim/simmem.c | 1 - imsaisim/srcsim/simport.h | 3 +-- intelmdssim/srcsim/simcfg.c | 1 - intelmdssim/srcsim/simctl.h | 3 ++- intelmdssim/srcsim/simio.c | 2 -- intelmdssim/srcsim/simmem.c | 1 - intelmdssim/srcsim/simport.h | 3 +-- iodevices/altair-88-2sio.c | 2 -- iodevices/altair-88-dcdd.c | 1 - iodevices/altair-88-sio.c | 2 -- iodevices/cromemco-88ccc.c | 7 ++----- iodevices/cromemco-dazzler.c | 8 +++----- iodevices/cromemco-fdc.c | 1 - iodevices/cromemco-hal.c | 1 - iodevices/cromemco-wdi.c | 1 - iodevices/diskmanager.c | 2 +- iodevices/diskmanager.h | 1 + iodevices/generic-at-modem.c | 3 --- iodevices/imsai-fif.c | 1 - iodevices/imsai-hal.c | 1 - iodevices/imsai-sio2.c | 1 - iodevices/imsai-vio.c | 2 -- iodevices/imsai-vio.h | 3 ++- iodevices/mds-isbc201.c | 1 - iodevices/mds-isbc202.c | 1 - iodevices/mds-isbc202.h | 1 + iodevices/mds-isbc206.c | 1 - iodevices/mds-monitor.c | 1 - iodevices/mostek-cpu.c | 1 - iodevices/mostek-fdc.c | 1 - iodevices/mostek-fdc.h | 1 + iodevices/proctec-vdm.c | 3 --- iodevices/proctec-vdm.h | 2 -- iodevices/simbdos.c | 1 - iodevices/tarbell_fdc.c | 1 - mosteksim/srcsim/simcfg.c | 1 - mosteksim/srcsim/simio.h | 3 +++ mosteksim/srcsim/simport.h | 3 +-- picosim/srcsim/disks.c | 1 - picosim/srcsim/gpio.h | 2 +- picosim/srcsim/rgbled.h | 2 +- picosim/srcsim/simcfg.c | 1 - picosim/srcsim/simport.h | 4 +++- webfrontend/netsrv.c | 6 ++---- webfrontend/netsrv.h | 4 +++- z80core/sim8080.c | 3 --- z80core/sim8080.h | 1 + z80core/simcore.c | 3 --- z80core/simdefs.h | 3 ++- z80core/simfun.c | 2 -- z80core/simfun.h | 3 +-- z80core/simglb.c | 4 ---- z80core/simglb.h | 3 --- z80core/simice.c | 3 --- z80core/simmain.c | 2 -- z80core/simsdl.c | 12 +++++++----- z80core/simsdl.h | 4 +++- z80core/simz80-cb.c | 5 ----- z80core/simz80-cb.h | 1 + z80core/simz80-dd.c | 5 ----- z80core/simz80-dd.h | 1 + z80core/simz80-ddcb.h | 1 + z80core/simz80-ed.c | 5 ----- z80core/simz80-ed.h | 1 + z80core/simz80-fd.c | 5 ----- z80core/simz80-fd.h | 1 + z80core/simz80-fdcb.h | 1 + z80core/simz80.c | 3 --- z80core/simz80.h | 1 + z80sim/srcsim/simport.h | 3 +-- 91 files changed, 63 insertions(+), 141 deletions(-) diff --git a/altairsim/srcsim/simcfg.c b/altairsim/srcsim/simcfg.c index ad74134b..a5af1b86 100644 --- a/altairsim/srcsim/simcfg.c +++ b/altairsim/srcsim/simcfg.c @@ -33,7 +33,6 @@ * 03-JAN-2025 changed colors configuration to RGB-triple */ -#include #include #include #include diff --git a/altairsim/srcsim/simctl.c b/altairsim/srcsim/simctl.c index ca65bbe7..de9cd96d 100644 --- a/altairsim/srcsim/simctl.c +++ b/altairsim/srcsim/simctl.c @@ -35,7 +35,6 @@ * 04-JAN-2025 add SDL2 support */ -#include #include #include #include diff --git a/altairsim/srcsim/simctl.h b/altairsim/srcsim/simctl.h index cc395df5..7e12a2c1 100644 --- a/altairsim/srcsim/simctl.h +++ b/altairsim/srcsim/simctl.h @@ -7,7 +7,8 @@ #ifndef SIMCTL_INC #define SIMCTL_INC -#include +#include "sim.h" +#include "simdefs.h" extern int boot_switch; /* boot address for switch */ diff --git a/altairsim/srcsim/simio.c b/altairsim/srcsim/simio.c index 51f4a66f..db381565 100644 --- a/altairsim/srcsim/simio.c +++ b/altairsim/srcsim/simio.c @@ -36,7 +36,6 @@ #include #include #include -#include #include #include diff --git a/altairsim/srcsim/simmem.c b/altairsim/srcsim/simmem.c index dde05d54..0d9a06dc 100644 --- a/altairsim/srcsim/simmem.c +++ b/altairsim/srcsim/simmem.c @@ -17,7 +17,6 @@ * 29-AUG-2021 new memory configuration sections */ -#include #include #include diff --git a/altairsim/srcsim/simport.h b/altairsim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/altairsim/srcsim/simport.h +++ b/altairsim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); diff --git a/cpmsim/srcsim/simctl.c b/cpmsim/srcsim/simctl.c index 707e8ec0..80797e82 100644 --- a/cpmsim/srcsim/simctl.c +++ b/cpmsim/srcsim/simctl.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include diff --git a/cpmsim/srcsim/simio.c b/cpmsim/srcsim/simio.c index 27e16bbd..8248d42d 100644 --- a/cpmsim/srcsim/simio.c +++ b/cpmsim/srcsim/simio.c @@ -113,7 +113,6 @@ * 160 - hardware control */ -#include #include #include #include diff --git a/cpmsim/srcsim/simmem.c b/cpmsim/srcsim/simmem.c index c42400ba..43e49b19 100644 --- a/cpmsim/srcsim/simmem.c +++ b/cpmsim/srcsim/simmem.c @@ -28,7 +28,6 @@ * 09-APR-2018 modified MMU write protect port as used by Alan Cox for FUZIX */ -#include #include #include "sim.h" diff --git a/cpmsim/srcsim/simport.h b/cpmsim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/cpmsim/srcsim/simport.h +++ b/cpmsim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); diff --git a/cromemcosim/srcsim/simcfg.c b/cromemcosim/srcsim/simcfg.c index 057fccff..e4e150e1 100644 --- a/cromemcosim/srcsim/simcfg.c +++ b/cromemcosim/srcsim/simcfg.c @@ -18,7 +18,6 @@ * 30-AUG-2021 new memory configuration sections */ -#include #include #include #include diff --git a/cromemcosim/srcsim/simctl.c b/cromemcosim/srcsim/simctl.c index 4eb4dcab..69e8fd98 100644 --- a/cromemcosim/srcsim/simctl.c +++ b/cromemcosim/srcsim/simctl.c @@ -30,7 +30,6 @@ * 04-JAN-2025 add SDL2 support */ -#include #include #include #include diff --git a/cromemcosim/srcsim/simctl.h b/cromemcosim/srcsim/simctl.h index 081d513d..2687713a 100644 --- a/cromemcosim/srcsim/simctl.h +++ b/cromemcosim/srcsim/simctl.h @@ -7,7 +7,8 @@ #ifndef SIMCTL_INC #define SIMCTL_INC -#include +#include "sim.h" +#include "simdefs.h" extern void mon(void); diff --git a/cromemcosim/srcsim/simio.c b/cromemcosim/srcsim/simio.c index d33bae4c..b10730ef 100644 --- a/cromemcosim/srcsim/simio.c +++ b/cromemcosim/srcsim/simio.c @@ -34,7 +34,6 @@ * 27-MAY-2024 moved io_in & io_out to simcore */ -#include #include #include #include diff --git a/cromemcosim/srcsim/simmem.c b/cromemcosim/srcsim/simmem.c index a1875aef..0d7e9f28 100644 --- a/cromemcosim/srcsim/simmem.c +++ b/cromemcosim/srcsim/simmem.c @@ -16,7 +16,6 @@ * 02-SEP-2021 implement banked ROM */ -#include #include #include #include diff --git a/cromemcosim/srcsim/simport.h b/cromemcosim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/cromemcosim/srcsim/simport.h +++ b/cromemcosim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); diff --git a/imsaisim/srcsim/simcfg.c b/imsaisim/srcsim/simcfg.c index 07c4398f..c47afe2d 100644 --- a/imsaisim/srcsim/simcfg.c +++ b/imsaisim/srcsim/simcfg.c @@ -37,7 +37,6 @@ * 03-JAN-2025 changed colors configuration to RGB-triple */ -#include #include #include #include diff --git a/imsaisim/srcsim/simcfg.h b/imsaisim/srcsim/simcfg.h index 6e31d3bf..3d90044e 100644 --- a/imsaisim/srcsim/simcfg.h +++ b/imsaisim/srcsim/simcfg.h @@ -38,6 +38,9 @@ #ifndef SIMCFG_INC #define SIMCFG_INC +#include "sim.h" +#include "simdefs.h" + extern int fp_size; extern BYTE fp_port; extern int ns_port; diff --git a/imsaisim/srcsim/simctl.c b/imsaisim/srcsim/simctl.c index 767536dd..634d9d5f 100644 --- a/imsaisim/srcsim/simctl.c +++ b/imsaisim/srcsim/simctl.c @@ -34,7 +34,6 @@ * 04-JAN-2025 add SDL2 support */ -#include #include #include #include diff --git a/imsaisim/srcsim/simctl.h b/imsaisim/srcsim/simctl.h index 0c2300f0..7d04615e 100644 --- a/imsaisim/srcsim/simctl.h +++ b/imsaisim/srcsim/simctl.h @@ -7,7 +7,8 @@ #ifndef SIMCTL_INC #define SIMCTL_INC -#include +#include "sim.h" +#include "simdefs.h" extern void mon(void); diff --git a/imsaisim/srcsim/simio.c b/imsaisim/srcsim/simio.c index e8c0b741..240d6bc2 100644 --- a/imsaisim/srcsim/simio.c +++ b/imsaisim/srcsim/simio.c @@ -40,7 +40,6 @@ * 27-MAY-2024 moved io_in & io_out to simcore */ -#include #include #include #include diff --git a/imsaisim/srcsim/simmem.c b/imsaisim/srcsim/simmem.c index c1463db9..4540ad22 100644 --- a/imsaisim/srcsim/simmem.c +++ b/imsaisim/srcsim/simmem.c @@ -19,7 +19,6 @@ * 29-AUG-2021 new memory configuration sections */ -#include #include #include #include diff --git a/imsaisim/srcsim/simport.h b/imsaisim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/imsaisim/srcsim/simport.h +++ b/imsaisim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); diff --git a/intelmdssim/srcsim/simcfg.c b/intelmdssim/srcsim/simcfg.c index 03d8648a..8295e6a6 100644 --- a/intelmdssim/srcsim/simcfg.c +++ b/intelmdssim/srcsim/simcfg.c @@ -12,7 +12,6 @@ * 07-JUN-2024 rewrite of the monitor ports and the timing thread */ -#include #include #include #include diff --git a/intelmdssim/srcsim/simctl.h b/intelmdssim/srcsim/simctl.h index a41aed40..14724854 100644 --- a/intelmdssim/srcsim/simctl.h +++ b/intelmdssim/srcsim/simctl.h @@ -8,7 +8,8 @@ #ifndef SIMCTL_INC #define SIMCTL_INC -#include +#include "sim.h" +#include "simdefs.h" extern BYTE boot_switch; diff --git a/intelmdssim/srcsim/simio.c b/intelmdssim/srcsim/simio.c index 01c23412..9b54d928 100644 --- a/intelmdssim/srcsim/simio.c +++ b/intelmdssim/srcsim/simio.c @@ -14,8 +14,6 @@ * 09-JUN-2024 add hwctl and simbdos ports */ -#include -#include #include #include #include diff --git a/intelmdssim/srcsim/simmem.c b/intelmdssim/srcsim/simmem.c index 4617fcb9..8c56e829 100644 --- a/intelmdssim/srcsim/simmem.c +++ b/intelmdssim/srcsim/simmem.c @@ -11,7 +11,6 @@ * 03-JUN-2024 first version */ -#include #include #include diff --git a/intelmdssim/srcsim/simport.h b/intelmdssim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/intelmdssim/srcsim/simport.h +++ b/intelmdssim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); diff --git a/iodevices/altair-88-2sio.c b/iodevices/altair-88-2sio.c index 701161dd..d6f3fdcf 100644 --- a/iodevices/altair-88-2sio.c +++ b/iodevices/altair-88-2sio.c @@ -25,8 +25,6 @@ * 19-JUL-2020 avoid problems with some third party terminal emulations */ -#include -#include #include #include #include diff --git a/iodevices/altair-88-dcdd.c b/iodevices/altair-88-dcdd.c index 654c827d..342052b1 100644 --- a/iodevices/altair-88-dcdd.c +++ b/iodevices/altair-88-dcdd.c @@ -12,7 +12,6 @@ * 02-DEC-2019 use disk names different from Tarbell controller */ -#include #include #include #include diff --git a/iodevices/altair-88-sio.c b/iodevices/altair-88-sio.c index 63f93e48..cfdb6239 100644 --- a/iodevices/altair-88-sio.c +++ b/iodevices/altair-88-sio.c @@ -22,8 +22,6 @@ * 19-JUL-2020 avoid problems with some third party terminal emulations */ -#include -#include #include #include #include diff --git a/iodevices/cromemco-88ccc.c b/iodevices/cromemco-88ccc.c index 589c3516..b7f1b313 100644 --- a/iodevices/cromemco-88ccc.c +++ b/iodevices/cromemco-88ccc.c @@ -10,8 +10,6 @@ * 04-NOV-2019 remove fake DMA bus request */ -#include -#include #include #include #include @@ -19,15 +17,14 @@ #include #include "sim.h" - -#if defined(HAS_NETSERVER) && defined(HAS_CYCLOPS) - #include "simdefs.h" #include "simglb.h" #include "simcfg.h" #include "simmem.h" #include "simport.h" +#if defined(HAS_NETSERVER) && defined(HAS_CYCLOPS) + #include "netsrv.h" #include "cromemco-88ccc.h" diff --git a/iodevices/cromemco-dazzler.c b/iodevices/cromemco-dazzler.c index d304b472..cd4da974 100644 --- a/iodevices/cromemco-dazzler.c +++ b/iodevices/cromemco-dazzler.c @@ -27,21 +27,17 @@ * 04-JAN-2025 add SDL2 support */ -#include #include #include #ifdef WANT_SDL -#include #include #else #include #include #include #endif -#include "sim.h" - -#ifdef HAS_DAZZLER +#include "sim.h" #include "simdefs.h" #include "simglb.h" #include "simcfg.h" @@ -51,6 +47,8 @@ #include "simsdl.h" #endif +#ifdef HAS_DAZZLER + #ifdef HAS_NETSERVER #include "netsrv.h" #endif diff --git a/iodevices/cromemco-fdc.c b/iodevices/cromemco-fdc.c index 8bf14247..72fed1da 100644 --- a/iodevices/cromemco-fdc.c +++ b/iodevices/cromemco-fdc.c @@ -39,7 +39,6 @@ * 15-MAY-2024 make disk manager standard */ -#include #include #include #include diff --git a/iodevices/cromemco-hal.c b/iodevices/cromemco-hal.c index ca61dd45..1b1301dc 100644 --- a/iodevices/cromemco-hal.c +++ b/iodevices/cromemco-hal.c @@ -10,7 +10,6 @@ * */ -#include #include #include #include diff --git a/iodevices/cromemco-wdi.c b/iodevices/cromemco-wdi.c index 553bf4ae..fc4f5c4f 100644 --- a/iodevices/cromemco-wdi.c +++ b/iodevices/cromemco-wdi.c @@ -10,7 +10,6 @@ * */ -#include #include #include #include diff --git a/iodevices/diskmanager.c b/iodevices/diskmanager.c index 870f93c6..85c3afb4 100644 --- a/iodevices/diskmanager.c +++ b/iodevices/diskmanager.c @@ -40,7 +40,6 @@ * * cromemco-fdc.c */ -#include #include #include #include @@ -49,6 +48,7 @@ #include #include "sim.h" +#include "simdefs.h" #include "disks.h" #ifdef HAS_NETSERVER diff --git a/iodevices/diskmanager.h b/iodevices/diskmanager.h index 289b9510..7a87995c 100644 --- a/iodevices/diskmanager.h +++ b/iodevices/diskmanager.h @@ -11,6 +11,7 @@ #define DISKMANAGER_INC #include "sim.h" +#include "simdefs.h" #ifdef HAS_NETSERVER #include "netsrv.h" diff --git a/iodevices/generic-at-modem.c b/iodevices/generic-at-modem.c index 32d14687..931e3401 100644 --- a/iodevices/generic-at-modem.c +++ b/iodevices/generic-at-modem.c @@ -15,10 +15,7 @@ */ #include -#include -#include #include -#include #include #include #include diff --git a/iodevices/imsai-fif.c b/iodevices/imsai-fif.c index c24c6907..02edc850 100644 --- a/iodevices/imsai-fif.c +++ b/iodevices/imsai-fif.c @@ -31,7 +31,6 @@ * 15-MAY-2024 make disk manager standard */ -#include #include #include #include diff --git a/iodevices/imsai-hal.c b/iodevices/imsai-hal.c index a974de9d..849ff47c 100644 --- a/iodevices/imsai-hal.c +++ b/iodevices/imsai-hal.c @@ -10,7 +10,6 @@ * */ -#include #include #include #include diff --git a/iodevices/imsai-sio2.c b/iodevices/imsai-sio2.c index 236c44ff..475eab07 100644 --- a/iodevices/imsai-sio2.c +++ b/iodevices/imsai-sio2.c @@ -34,7 +34,6 @@ * 01-AUG-2021 integrated HAL */ -#include #include #include #include diff --git a/iodevices/imsai-vio.c b/iodevices/imsai-vio.c index ca517242..c3410cb7 100644 --- a/iodevices/imsai-vio.c +++ b/iodevices/imsai-vio.c @@ -23,11 +23,9 @@ * 04-JAN-2025 add SDL2 support */ -#include #include #include #ifdef WANT_SDL -#include #include #else #include diff --git a/iodevices/imsai-vio.h b/iodevices/imsai-vio.h index 9e92558d..56a41679 100644 --- a/iodevices/imsai-vio.h +++ b/iodevices/imsai-vio.h @@ -26,7 +26,8 @@ #ifndef IMSAI_VIO_INC #define IMSAI_VIO_INC -#include +#include "sim.h" +#include "simdefs.h" extern int slf; /* VIO scanlines factor */ extern uint8_t bg_color[3]; /* VIO background color */ diff --git a/iodevices/mds-isbc201.c b/iodevices/mds-isbc201.c index fef01f11..47ffd1eb 100644 --- a/iodevices/mds-isbc201.c +++ b/iodevices/mds-isbc201.c @@ -12,7 +12,6 @@ * 09-JUN-2024 first version */ -#include #include #include #include diff --git a/iodevices/mds-isbc202.c b/iodevices/mds-isbc202.c index 473f745c..f3054d8b 100644 --- a/iodevices/mds-isbc202.c +++ b/iodevices/mds-isbc202.c @@ -12,7 +12,6 @@ * 04-JUN-2024 first version */ -#include #include #include #include diff --git a/iodevices/mds-isbc202.h b/iodevices/mds-isbc202.h index 59d2f453..10479e97 100644 --- a/iodevices/mds-isbc202.h +++ b/iodevices/mds-isbc202.h @@ -15,6 +15,7 @@ #ifndef MDS_ISBC202_INC #define MDS_ISBC202_INC +#include "sim.h" #include "simdefs.h" extern BYTE isbc202_status_in(void), isbc202_res_type_in(void); diff --git a/iodevices/mds-isbc206.c b/iodevices/mds-isbc206.c index f8be4011..119031ca 100644 --- a/iodevices/mds-isbc206.c +++ b/iodevices/mds-isbc206.c @@ -20,7 +20,6 @@ * 08-JUN-2024 first version */ -#include #include #include #include diff --git a/iodevices/mds-monitor.c b/iodevices/mds-monitor.c index 6e8846ca..5d06d2da 100644 --- a/iodevices/mds-monitor.c +++ b/iodevices/mds-monitor.c @@ -15,7 +15,6 @@ * 07-JUN-2024 rewrite of the monitor ports and the timing thread */ -#include #include #include #include diff --git a/iodevices/mostek-cpu.c b/iodevices/mostek-cpu.c index 26b9db20..5608529e 100644 --- a/iodevices/mostek-cpu.c +++ b/iodevices/mostek-cpu.c @@ -11,7 +11,6 @@ * 15-SEP-2019 (Mike Douglas) created from altair-88-2sio.c */ -#include #include #include #include diff --git a/iodevices/mostek-fdc.c b/iodevices/mostek-fdc.c index 759bead1..d1353b3f 100644 --- a/iodevices/mostek-fdc.c +++ b/iodevices/mostek-fdc.c @@ -14,7 +14,6 @@ * 11-MAY-2024 (Thomas Eberhardt) add diskdir option support */ -#include #include #include #include diff --git a/iodevices/mostek-fdc.h b/iodevices/mostek-fdc.h index e4630a1f..5279095a 100644 --- a/iodevices/mostek-fdc.h +++ b/iodevices/mostek-fdc.h @@ -16,6 +16,7 @@ #ifndef MOSTEK_FDC_INC #define MOSTEK_FDC_INC +#include "sim.h" #include "simdefs.h" extern BYTE fdcBoard_stat_in(void), fdcBoard_ctl_in(void); diff --git a/iodevices/proctec-vdm.c b/iodevices/proctec-vdm.c index e0478936..45667771 100644 --- a/iodevices/proctec-vdm.c +++ b/iodevices/proctec-vdm.c @@ -17,12 +17,9 @@ * 03-JAN-2025 use SDL2 instead of X11 */ -#include -#include #include #include #ifdef WANT_SDL -#include #include #else #include diff --git a/iodevices/proctec-vdm.h b/iodevices/proctec-vdm.h index 0cae5622..8ea6e80b 100644 --- a/iodevices/proctec-vdm.h +++ b/iodevices/proctec-vdm.h @@ -19,8 +19,6 @@ #ifndef PROCTEC_VDM_INC #define PROCTEC_VDM_INC -#include - #include "sim.h" #include "simdefs.h" diff --git a/iodevices/simbdos.c b/iodevices/simbdos.c index 3282b178..662af7c2 100644 --- a/iodevices/simbdos.c +++ b/iodevices/simbdos.c @@ -30,7 +30,6 @@ * 03-OCT-2019 (Mike Douglas) Original */ -#include #include #include #include diff --git a/iodevices/tarbell_fdc.c b/iodevices/tarbell_fdc.c index 70822b76..ba9d410d 100644 --- a/iodevices/tarbell_fdc.c +++ b/iodevices/tarbell_fdc.c @@ -25,7 +25,6 @@ * 24-SEP-2019 restore and seek also affect step direction */ -#include #include #include #include diff --git a/mosteksim/srcsim/simcfg.c b/mosteksim/srcsim/simcfg.c index 2a406dd1..3f0e52cf 100644 --- a/mosteksim/srcsim/simcfg.c +++ b/mosteksim/srcsim/simcfg.c @@ -14,7 +14,6 @@ * 11-MAY-2024 (Thomas Eberhardt) add confdir/rompath option support */ -#include #include #include diff --git a/mosteksim/srcsim/simio.h b/mosteksim/srcsim/simio.h index 446259b8..646daa1a 100644 --- a/mosteksim/srcsim/simio.h +++ b/mosteksim/srcsim/simio.h @@ -7,6 +7,9 @@ #ifndef SIMIO_INC #define SIMIO_INC +#include "sim.h" +#include "simdefs.h" + #define IO_DATA_UNUSED 0xff /* data returned on unused ports */ extern in_func_t *const port_in[256]; diff --git a/mosteksim/srcsim/simport.h b/mosteksim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/mosteksim/srcsim/simport.h +++ b/mosteksim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); diff --git a/picosim/srcsim/disks.c b/picosim/srcsim/disks.c index 081e743f..8cbdd3e6 100644 --- a/picosim/srcsim/disks.c +++ b/picosim/srcsim/disks.c @@ -13,7 +13,6 @@ * 29-JUN-2024 split of from memsim.c and picosim.c */ -#include #include #include #include diff --git a/picosim/srcsim/gpio.h b/picosim/srcsim/gpio.h index e50b1917..da8992a9 100644 --- a/picosim/srcsim/gpio.h +++ b/picosim/srcsim/gpio.h @@ -26,4 +26,4 @@ #define SD_SPI_SO 16 /* SPI so pin used for SD card */ #define SD_SPI_CS 17 /* SPI cs pin used for SD card */ -#endif +#endif /* !GPIO_INC */ diff --git a/picosim/srcsim/rgbled.h b/picosim/srcsim/rgbled.h index 0d209202..318b31e0 100644 --- a/picosim/srcsim/rgbled.h +++ b/picosim/srcsim/rgbled.h @@ -11,4 +11,4 @@ static inline void put_pixel(uint32_t pixel_grb) { pio_sm_put_blocking(pio, sm, pixel_grb << 8u); } -#endif +#endif /* !RGBLED_INC */ diff --git a/picosim/srcsim/simcfg.c b/picosim/srcsim/simcfg.c index 74d24c88..f8356c5d 100644 --- a/picosim/srcsim/simcfg.c +++ b/picosim/srcsim/simcfg.c @@ -15,7 +15,6 @@ * 02-SEP-2024 read date/time from an optional I2C battery backed RTC */ -#include #include #include #include diff --git a/picosim/srcsim/simport.h b/picosim/srcsim/simport.h index 0ae2029d..31e2dd87 100644 --- a/picosim/srcsim/simport.h +++ b/picosim/srcsim/simport.h @@ -7,9 +7,11 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include #include "pico/time.h" +#include "sim.h" +#include "simdefs.h" + static inline void sleep_for_us(long time) { sleep_us(time); } static inline void sleep_for_ms(int time) { sleep_ms(time); } diff --git a/webfrontend/netsrv.c b/webfrontend/netsrv.c index c4558345..b2c8deb6 100644 --- a/webfrontend/netsrv.c +++ b/webfrontend/netsrv.c @@ -11,7 +11,6 @@ * This web server module provides... */ -#include #include #include #include @@ -23,9 +22,6 @@ #include #include "sim.h" - -#ifdef HAS_NETSERVER - #include "simdefs.h" #include "simglb.h" #include "simmem.h" @@ -48,6 +44,8 @@ #endif #include "diskmanager.h" +#ifdef HAS_NETSERVER + #include "log.h" static const char *TAG = "netsrv"; diff --git a/webfrontend/netsrv.h b/webfrontend/netsrv.h index 85c2a78c..528b0f97 100644 --- a/webfrontend/netsrv.h +++ b/webfrontend/netsrv.h @@ -13,11 +13,13 @@ /** * This web server module provides... */ -#include #include #include #include +#include "sim.h" +#include "simdefs.h" + #include "civetweb.h" enum net_device { diff --git a/z80core/sim8080.c b/z80core/sim8080.c index 0678eb60..86d01cbf 100644 --- a/z80core/sim8080.c +++ b/z80core/sim8080.c @@ -5,8 +5,6 @@ * Copyright (C) 2024 by Thomas Eberhardt */ -#include - #include "sim.h" #include "simdefs.h" #include "simglb.h" @@ -19,7 +17,6 @@ #include "sim8080.h" #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simctl.h" #endif diff --git a/z80core/sim8080.h b/z80core/sim8080.h index 42241f98..fcd91a65 100644 --- a/z80core/sim8080.h +++ b/z80core/sim8080.h @@ -9,6 +9,7 @@ #define SIM8080_INC #include "sim.h" +#include "simdefs.h" #ifndef EXCLUDE_I8080 extern void cpu_8080(void); diff --git a/z80core/simcore.c b/z80core/simcore.c index 036b46f7..23f3981e 100644 --- a/z80core/simcore.c +++ b/z80core/simcore.c @@ -9,8 +9,6 @@ * This module contains functions for CPU/Bus-handling */ -#include -#include #include #include @@ -29,7 +27,6 @@ #include "simcore.h" #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simctl.h" #endif diff --git a/z80core/simdefs.h b/z80core/simdefs.h index 069c681e..d9373e88 100644 --- a/z80core/simdefs.h +++ b/z80core/simdefs.h @@ -8,8 +8,9 @@ #ifndef SIMDEFS_INC #define SIMDEFS_INC +#include #include -#include +#include #define COPYR "Copyright (C) 1987-2024 by Udo Munk and others" #define RELEASE "1.39" diff --git a/z80core/simfun.c b/z80core/simfun.c index 073b4162..f531d947 100644 --- a/z80core/simfun.c +++ b/z80core/simfun.c @@ -15,8 +15,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/z80core/simfun.h b/z80core/simfun.h index 3c4db50e..40261665 100644 --- a/z80core/simfun.h +++ b/z80core/simfun.h @@ -16,9 +16,8 @@ * running on an OS using the POSIX API. The implementations are * included in simfun.c: * - * #include - * * #include "sim.h" + * #include "simdefs.h" * * extern void sleep_for_us(long time); * extern void sleep_for_ms(int time); diff --git a/z80core/simglb.c b/z80core/simglb.c index 2d419916..6af4e137 100644 --- a/z80core/simglb.c +++ b/z80core/simglb.c @@ -10,10 +10,6 @@ * This module contains the global variables other than memory management */ -#include -#include -#include - #include "sim.h" #include "simdefs.h" #include "simglb.h" diff --git a/z80core/simglb.h b/z80core/simglb.h index 7cc742ed..746108b8 100644 --- a/z80core/simglb.h +++ b/z80core/simglb.h @@ -13,9 +13,6 @@ * Declaration of variables in simglb.c */ -#include -#include - #include "sim.h" #include "simdefs.h" diff --git a/z80core/simice.c b/z80core/simice.c index 779702c3..7d4b8351 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -12,9 +12,6 @@ */ #include -#include -#include -#include #include #include #include diff --git a/z80core/simmain.c b/z80core/simmain.c index 0d5dc8d1..1f748f6f 100644 --- a/z80core/simmain.c +++ b/z80core/simmain.c @@ -19,8 +19,6 @@ #include #include -#include -#include #include #include #include diff --git a/z80core/simsdl.c b/z80core/simsdl.c index 3db71c9f..9e50d782 100644 --- a/z80core/simsdl.c +++ b/z80core/simsdl.c @@ -8,18 +8,20 @@ * This module contains the SDL2 integration for the simulator. */ -#include #include #include -#ifdef FRONTPANEL -#include -#include -#endif #include +#include "sim.h" +#include "simdefs.h" #include "simsdl.h" #include "simmain.h" +#ifdef FRONTPANEL +#include +#include +#endif + #define MAX_WINDOWS 5 static int sim_thread_func(void *data); diff --git a/z80core/simsdl.h b/z80core/simsdl.h index ffc78f0e..7324a75c 100644 --- a/z80core/simsdl.h +++ b/z80core/simsdl.h @@ -7,9 +7,11 @@ #ifndef SIMSDL_INC #define SIMSDL_INC -#include #include +#include "sim.h" +#include "simdefs.h" + typedef struct win_funcs { void (*open)(void); void (*close)(void); diff --git a/z80core/simz80-cb.c b/z80core/simz80-cb.c index b81b165b..c16fe4cf 100644 --- a/z80core/simz80-cb.c +++ b/z80core/simz80-cb.c @@ -16,12 +16,7 @@ #include "simmem.h" #include "simz80-cb.h" -#ifdef BUS_8080 -#include -#endif - #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simport.h" #endif diff --git a/z80core/simz80-cb.h b/z80core/simz80-cb.h index 2c4fa756..a4fd8cb6 100644 --- a/z80core/simz80-cb.h +++ b/z80core/simz80-cb.h @@ -9,6 +9,7 @@ #define SIMZ80_CB_INC #include "sim.h" +#include "simdefs.h" #if !defined(EXCLUDE_Z80) && !defined(ALT_Z80) extern int op_cb_handle(void); diff --git a/z80core/simz80-dd.c b/z80core/simz80-dd.c index 67956b0d..ccbc353e 100644 --- a/z80core/simz80-dd.c +++ b/z80core/simz80-dd.c @@ -17,12 +17,7 @@ #include "simz80-dd.h" #include "simz80-ddcb.h" -#ifdef BUS_8080 -#include -#endif - #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simport.h" #endif diff --git a/z80core/simz80-dd.h b/z80core/simz80-dd.h index e60b90a0..4cf5a0e2 100644 --- a/z80core/simz80-dd.h +++ b/z80core/simz80-dd.h @@ -9,6 +9,7 @@ #define SIMZ80_DD_INC #include "sim.h" +#include "simdefs.h" #if !defined(EXCLUDE_Z80) && !defined(ALT_Z80) extern int op_dd_handle(void); diff --git a/z80core/simz80-ddcb.h b/z80core/simz80-ddcb.h index 8a73009e..903327cf 100644 --- a/z80core/simz80-ddcb.h +++ b/z80core/simz80-ddcb.h @@ -9,6 +9,7 @@ #define SIMZ80_DDCB_INC #include "sim.h" +#include "simdefs.h" #if !defined(EXCLUDE_Z80) && !defined(ALT_Z80) extern int op_ddcb_handle(void); diff --git a/z80core/simz80-ed.c b/z80core/simz80-ed.c index 76894cd7..386535f4 100644 --- a/z80core/simz80-ed.c +++ b/z80core/simz80-ed.c @@ -17,12 +17,7 @@ #include "simmem.h" #include "simz80-ed.h" -#ifdef BUS_8080 -#include -#endif - #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simport.h" #endif diff --git a/z80core/simz80-ed.h b/z80core/simz80-ed.h index 1caea04e..d487fdad 100644 --- a/z80core/simz80-ed.h +++ b/z80core/simz80-ed.h @@ -9,6 +9,7 @@ #define SIMZ80_ED_INC #include "sim.h" +#include "simdefs.h" #if !defined(EXCLUDE_Z80) && !defined(ALT_Z80) extern int op_ed_handle(void); diff --git a/z80core/simz80-fd.c b/z80core/simz80-fd.c index 9d5836b5..9e600d3b 100644 --- a/z80core/simz80-fd.c +++ b/z80core/simz80-fd.c @@ -17,12 +17,7 @@ #include "simz80-fd.h" #include "simz80-fdcb.h" -#ifdef BUS_8080 -#include -#endif - #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simport.h" #endif diff --git a/z80core/simz80-fd.h b/z80core/simz80-fd.h index 6c9cba9e..0eccded5 100644 --- a/z80core/simz80-fd.h +++ b/z80core/simz80-fd.h @@ -9,6 +9,7 @@ #define SIMZ80_FD_INC #include "sim.h" +#include "simdefs.h" #if !defined(EXCLUDE_Z80) && !defined(ALT_Z80) extern int op_fd_handle(void); diff --git a/z80core/simz80-fdcb.h b/z80core/simz80-fdcb.h index ada00c71..3244b911 100644 --- a/z80core/simz80-fdcb.h +++ b/z80core/simz80-fdcb.h @@ -9,6 +9,7 @@ #define SIMZ80_FDCB_INC #include "sim.h" +#include "simdefs.h" #if !defined(EXCLUDE_Z80) && !defined(ALT_Z80) extern int op_fdcb_handle(void); diff --git a/z80core/simz80.c b/z80core/simz80.c index 686e48d6..b60b7656 100644 --- a/z80core/simz80.c +++ b/z80core/simz80.c @@ -5,8 +5,6 @@ * Copyright (C) 2024 by Thomas Eberhardt */ -#include - #include "sim.h" #include "simdefs.h" #include "simglb.h" @@ -23,7 +21,6 @@ #include "simz80-fd.h" #ifdef FRONTPANEL -#include #include "frontpanel.h" #include "simctl.h" #endif diff --git a/z80core/simz80.h b/z80core/simz80.h index caebdf1a..7decec24 100644 --- a/z80core/simz80.h +++ b/z80core/simz80.h @@ -9,6 +9,7 @@ #define SIMZ80_INC #include "sim.h" +#include "simdefs.h" #ifndef EXCLUDE_Z80 extern void cpu_z80(void); diff --git a/z80sim/srcsim/simport.h b/z80sim/srcsim/simport.h index b10fa817..0b1fe2af 100644 --- a/z80sim/srcsim/simport.h +++ b/z80sim/srcsim/simport.h @@ -7,9 +7,8 @@ #ifndef SIMPORT_INC #define SIMPORT_INC -#include - #include "sim.h" +#include "simdefs.h" extern void sleep_for_us(long time); extern void sleep_for_ms(int time); From a81b50be55f3543aa31fa6c15b68a2ca0f720981 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 04:46:43 +0100 Subject: [PATCH 04/19] make int_int, int_nmi, int_protection, and cpu_needed bool --- altairsim/srcsim/simctl.c | 2 +- altairsim/srcsim/simio.c | 2 +- cpmsim/srcsim/simio.c | 2 +- cpmsim/srcsim/simmem.h | 2 +- cromemcosim/srcsim/simio.c | 30 +++++++++++++++--------------- imsaisim/srcsim/simio.c | 2 +- intelmdssim/srcsim/simio.c | 4 ++-- z80core/alt8080.h | 7 +++---- z80core/altz80.h | 9 ++++----- z80core/sim8080.c | 10 +++++----- z80core/simcore.c | 6 ++++-- z80core/simglb.c | 8 ++++---- z80core/simglb.h | 10 +++++++--- z80core/simz80.c | 14 +++++++------- 14 files changed, 56 insertions(+), 52 deletions(-) diff --git a/altairsim/srcsim/simctl.c b/altairsim/srcsim/simctl.c index de9cd96d..a712b720 100644 --- a/altairsim/srcsim/simctl.c +++ b/altairsim/srcsim/simctl.c @@ -537,7 +537,7 @@ static void int_clicked(int state, int val) switch (state) { case FP_SW_UP: - int_int = 1; + int_int = true; break; case FP_SW_DOWN: fp_led_address = boot_switch; diff --git a/altairsim/srcsim/simio.c b/altairsim/srcsim/simio.c index db381565..8e05b9aa 100644 --- a/altairsim/srcsim/simio.c +++ b/altairsim/srcsim/simio.c @@ -246,7 +246,7 @@ static void int_timer(int sig) { UNUSED(sig); - int_int = 1; + int_int = true; int_data = 0xff; /* RST 38H for IM 0 */ } diff --git a/cpmsim/srcsim/simio.c b/cpmsim/srcsim/simio.c index 8248d42d..04a1f707 100644 --- a/cpmsim/srcsim/simio.c +++ b/cpmsim/srcsim/simio.c @@ -2095,7 +2095,7 @@ static void int_timer(int sig) { UNUSED(sig); - int_int = 1; + int_int = true; int_data = 0xff; /* RST 38H for IM 0, 0FFH for IM 2 */ } diff --git a/cpmsim/srcsim/simmem.h b/cpmsim/srcsim/simmem.h index 80f88983..a7433e05 100644 --- a/cpmsim/srcsim/simmem.h +++ b/cpmsim/srcsim/simmem.h @@ -70,7 +70,7 @@ static inline void memwrt(WORD addr, BYTE data) wp_common |= 0x80; #ifndef EXCLUDE_Z80 if (wp_common & 0x40) - int_nmi = 1; + int_nmi = true; #endif return; } diff --git a/cromemcosim/srcsim/simio.c b/cromemcosim/srcsim/simio.c index b10730ef..398bb52c 100644 --- a/cromemcosim/srcsim/simio.c +++ b/cromemcosim/srcsim/simio.c @@ -539,7 +539,7 @@ static void *timing(void *arg) uart0a_int = 0xc7; uart0a_int_pending = 1; int_data = 0xc7; - int_int = 1; + int_int = true; uart0a_timer1 = 0; goto next; } @@ -549,7 +549,7 @@ static void *timing(void *arg) uart0a_int = 0xcf; uart0a_int_pending = 1; int_data = 0xcf; - int_int = 1; + int_int = true; uart0a_timer2 = 0; goto next; } @@ -559,7 +559,7 @@ static void *timing(void *arg) uart0a_int = 0xd7; uart0a_int_pending = 1; int_data = 0xd7; - int_int = 1; + int_int = true; goto next; } @@ -568,7 +568,7 @@ static void *timing(void *arg) uart0a_int = 0xdf; uart0a_int_pending = 1; int_data = 0xdf; - int_int = 1; + int_int = true; uart0a_timer3 = 0; goto next; } @@ -578,7 +578,7 @@ static void *timing(void *arg) uart0a_int = 0xe7; uart0a_int_pending = 1; int_data = 0xe7; - int_int = 1; + int_int = true; goto next; } @@ -591,7 +591,7 @@ static void *timing(void *arg) uart0a_int = 0xef; uart0a_int_pending = 1; int_data = 0xef; - int_int = 1; + int_int = true; goto next; } } @@ -601,7 +601,7 @@ static void *timing(void *arg) uart0a_int = 0xf7; uart0a_int_pending = 1; int_data = 0xf7; - int_int = 1; + int_int = true; uart0a_timer4 = 0; goto next; } @@ -611,7 +611,7 @@ static void *timing(void *arg) uart0a_int = 0xff; uart0a_int_pending = 1; int_data = 0xff; - int_int = 1; + int_int = true; uart0a_timer5 = 0; goto next; } @@ -623,7 +623,7 @@ static void *timing(void *arg) uart0a_int = 0xff; uart0a_int_pending = 1; int_data = 0xff; - int_int = 1; + int_int = true; goto next; } } @@ -640,7 +640,7 @@ static void *timing(void *arg) if (uart1a_int_mask & 4) { uart1a_sense = 0; int_data = 0x24; - int_int = 1; + int_int = true; goto next; } } @@ -650,7 +650,7 @@ static void *timing(void *arg) uart1a_int = 0xe7; uart1a_int_pending = 1; int_data = 0x28; - int_int = 1; + int_int = true; goto next; } @@ -661,7 +661,7 @@ static void *timing(void *arg) uart1a_int = 0xef; uart1a_int_pending = 1; int_data = 0x2a; - int_int = 1; + int_int = true; goto next; } } @@ -678,7 +678,7 @@ static void *timing(void *arg) if (uart1b_int_mask & 4) { uart1b_sense = 0; int_data = 0x34; - int_int = 1; + int_int = true; goto next; } } @@ -688,7 +688,7 @@ static void *timing(void *arg) uart1b_int = 0xe7; uart1b_int_pending = 1; int_data = 0x38; - int_int = 1; + int_int = true; goto next; } @@ -699,7 +699,7 @@ static void *timing(void *arg) uart1b_int = 0xef; uart1b_int_pending = 1; int_data = 0x3a; - int_int = 1; + int_int = true; goto next; } } diff --git a/imsaisim/srcsim/simio.c b/imsaisim/srcsim/simio.c index 240d6bc2..2856ecd5 100644 --- a/imsaisim/srcsim/simio.c +++ b/imsaisim/srcsim/simio.c @@ -405,7 +405,7 @@ static void int_timer(int sig) { UNUSED(sig); - int_int = 1; + int_int = true; int_data = 0xff; /* RST 38H */ } diff --git a/intelmdssim/srcsim/simio.c b/intelmdssim/srcsim/simio.c index 9b54d928..d4e759c4 100644 --- a/intelmdssim/srcsim/simio.c +++ b/intelmdssim/srcsim/simio.c @@ -307,13 +307,13 @@ static void int_pending(void) { int irq, mask; - if (int_int == 0 && (mask = (int_requests & ~int_mask)) != 0) { + if (!int_int && (mask = (int_requests & ~int_mask)) != 0) { irq = int_highest(mask); if (irq < int_highest(int_in_service)) { pthread_mutex_lock(&int_mutex); int_in_service |= 1 << irq; int_requests &= ~(1 << irq); - int_int = 1; + int_int = true; int_data = 0xc7 /* RST0 */ + (irq << 3); pthread_mutex_unlock(&int_mutex); } diff --git a/z80core/alt8080.h b/z80core/alt8080.h index a01e554f..2c70b89b 100644 --- a/z80core/alt8080.h +++ b/z80core/alt8080.h @@ -755,7 +755,7 @@ cpu_state = ST_STOPPED; } else { /* else wait for INT or user interrupt */ - while ((int_int == 0) && + while (!int_int && (cpu_state == ST_CONTIN_RUN)) { sleep_for_ms(1); } @@ -786,8 +786,7 @@ } else { /* else wait for INT, frontpanel reset or user interrupt */ - while ((int_int == 0) && - !(cpu_state & ST_RESET)) { + while (!int_int && !(cpu_state & ST_RESET)) { fp_clock++; fp_sampleData(); sleep_for_ms(1); @@ -1539,7 +1538,7 @@ case 0xfb: /* EI */ IFF = 3; - int_protection = 1; /* protect next instruction */ + int_protection = true; /* protect next instruction */ break; case 0xfc: /* CM nn */ diff --git a/z80core/altz80.h b/z80core/altz80.h index edc7f26f..a28f4976 100644 --- a/z80core/altz80.h +++ b/z80core/altz80.h @@ -817,7 +817,7 @@ cpu_state = ST_STOPPED; } else { /* else wait for INT, NMI or user interrupt */ - while ((int_int == 0) && (int_nmi == 0) && + while (!int_int && !int_nmi && (cpu_state == ST_CONTIN_RUN)) { sleep_for_ms(1); R += 99; @@ -839,8 +839,7 @@ if (IFF == 0) { /* INT disabled, wait for NMI, frontpanel reset or user interrupt */ - while ((int_nmi == 0) && - !(cpu_state & ST_RESET)) { + while (!int_nmi && !(cpu_state & ST_RESET)) { fp_clock++; fp_sampleData(); sleep_for_ms(1); @@ -851,7 +850,7 @@ } else { /* else wait for INT, NMI, frontpanel reset or user interrupt */ - while ((int_int == 0) && (int_nmi == 0) && + while (!int_int && !int_nmi && !(cpu_state & ST_RESET)) { fp_clock++; fp_sampleData(); @@ -2391,7 +2390,7 @@ case 0xfb: /* EI */ IFF = 3; - int_protection = 1; /* protect next instruction */ + int_protection = true; /* protect next instruction */ break; case 0xfc: /* CALL M,nn */ diff --git a/z80core/sim8080.c b/z80core/sim8080.c index 86d01cbf..f32a0f48 100644 --- a/z80core/sim8080.c +++ b/z80core/sim8080.c @@ -576,7 +576,7 @@ void cpu_8080(void) continue; } T += 11; - int_int = 0; + int_int = false; int_data = -1; #ifdef FRONTPANEL if (F_flag) @@ -590,7 +590,7 @@ void cpu_8080(void) cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; #endif - int_protection = 0; + int_protection = false; #ifndef ALT_I8080 T += (*op_sim[memrdr(PC++)])(); /* execute next opcode */ #else @@ -689,7 +689,7 @@ static int op_hlt(void) /* HLT */ cpu_state = ST_STOPPED; } else { /* else wait for INT or user interrupt */ - while ((int_int == 0) && (cpu_state == ST_CONTIN_RUN)) { + while (!int_int && (cpu_state == ST_CONTIN_RUN)) { sleep_for_ms(1); } } @@ -718,7 +718,7 @@ static int op_hlt(void) /* HLT */ } else { /* else wait for INT, frontpanel reset or user interrupt */ - while ((int_int == 0) && !(cpu_state & ST_RESET)) { + while (!int_int && !(cpu_state & ST_RESET)) { fp_clock++; fp_sampleData(); sleep_for_ms(1); @@ -792,7 +792,7 @@ static int op_daa(void) /* DAA */ static int op_ei(void) /* EI */ { IFF = 3; - int_protection = 1; /* protect next instruction */ + int_protection = true; /* protect next instruction */ return 4; } diff --git a/z80core/simcore.c b/z80core/simcore.c index 23f3981e..00857dba 100644 --- a/z80core/simcore.c +++ b/z80core/simcore.c @@ -79,7 +79,8 @@ void init_cpu(void) */ void reset_cpu(void) { - IFF = int_int = int_protection = 0; + IFF = 0; + int_int = int_protection = false; int_data = -1; PC = 0; @@ -87,7 +88,8 @@ void reset_cpu(void) #ifndef EXCLUDE_Z80 I = 0; R_ = R = 0; - int_nmi = int_mode = 0; + int_mode = 0; + int_nmi = false; #endif } diff --git a/z80core/simglb.c b/z80core/simglb.c index 6af4e137..eaff91dc 100644 --- a/z80core/simglb.c +++ b/z80core/simglb.c @@ -55,16 +55,16 @@ BYTE cpu_state; /* state of CPU emulation */ int cpu_error; /* error status of CPU emulation */ #ifndef EXCLUDE_Z80 int int_mode; /* CPU interrupt mode (IM 0, IM 1, IM 2) */ -int int_nmi; /* non-maskable interrupt request */ +bool int_nmi; /* non-maskable interrupt request */ #endif -int int_int; /* interrupt request */ +bool int_int; /* interrupt request */ int int_data = -1; /* data from interrupting device on data bus */ -int int_protection; /* to delay interrupts after EI */ +bool int_protection; /* to delay interrupts after EI */ BYTE bus_request; /* request address/data bus from CPU */ BusDMA_t bus_mode; /* current bus mode for DMA */ BusDMAFunc_t *dma_bus_master; /* DMA bus master call back func */ int tmax; /* max t-states to execute in 10ms */ -int cpu_needed; /* don't adjust CPU freq if needed */ +bool cpu_needed; /* don't adjust CPU freq if needed */ /* * Variables for frontpanel emulation diff --git a/z80core/simglb.h b/z80core/simglb.h index 746108b8..b789decb 100644 --- a/z80core/simglb.h +++ b/z80core/simglb.h @@ -45,13 +45,17 @@ extern int busy_loop_cnt; extern BYTE cpu_state; extern int cpu_error; #ifndef EXCLUDE_Z80 -extern int int_nmi, int_mode; +extern int int_mode; +extern bool int_nmi; #endif -extern int int_int, int_data, int_protection; +extern bool int_int; +extern int int_data; +extern bool int_protection; extern BYTE bus_request; extern BusDMA_t bus_mode; extern BusDMAFunc_t *dma_bus_master; -extern int tmax, cpu_needed; +extern int tmax; +extern bool cpu_needed; #ifdef FRONTPANEL extern uint64_t fp_clock; diff --git a/z80core/simz80.c b/z80core/simz80.c index b60b7656..377a408c 100644 --- a/z80core/simz80.c +++ b/z80core/simz80.c @@ -480,7 +480,7 @@ void cpu_z80(void) memwrt(--SP, PC >> 8); memwrt(--SP, PC); PC = 0x66; - int_nmi = 0; + int_nmi = false; T += 11; R++; /* increment refresh register */ } @@ -585,7 +585,7 @@ void cpu_z80(void) T += 19; break; } - int_int = 0; + int_int = false; int_data = -1; #ifdef FRONTPANEL if (F_flag) @@ -602,7 +602,7 @@ void cpu_z80(void) R++; /* increment refresh register */ - int_protection = 0; + int_protection = false; #ifndef ALT_Z80 T += (*op_sim[memrdr(PC++)])(); /* execute next opcode */ #else @@ -691,7 +691,7 @@ static int op_halt(void) /* HALT */ cpu_state = ST_STOPPED; } else { /* else wait for INT, NMI or user interrupt */ - while ((int_int == 0) && (int_nmi == 0) && + while (!int_int && !int_nmi && (cpu_state == ST_CONTIN_RUN)) { sleep_for_ms(1); R += 99; @@ -712,7 +712,7 @@ static int op_halt(void) /* HALT */ if (IFF == 0) { /* INT disabled, wait for NMI, frontpanel reset or user interrupt */ - while ((int_nmi == 0) && !(cpu_state & ST_RESET)) { + while (!int_nmi && !(cpu_state & ST_RESET)) { fp_clock++; fp_sampleData(); sleep_for_ms(1); @@ -723,7 +723,7 @@ static int op_halt(void) /* HALT */ } else { /* else wait for INT, NMI, frontpanel reset or user interrupt */ - while ((int_int == 0) && (int_nmi == 0) && + while (!int_int && !int_nmi && !(cpu_state & ST_RESET)) { fp_clock++; fp_sampleData(); @@ -852,7 +852,7 @@ static int op_daa(void) /* DAA */ static int op_ei(void) /* EI */ { IFF = 3; - int_protection = 1; /* protect next instruction */ + int_protection = true; /* protect next instruction */ return 4; } From 353259eefe8e3b68fb90fda793b9c010157d81ef Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 05:19:02 +0100 Subject: [PATCH 05/19] make [slxiurcRFn]_flag bool, change names of [mfM]_flag to [mfM]_value Also make tarbell_rom_[enabled,active] bool. Also change ice_cmd_loop parameter name from go_flag to go_mode. --- altairsim/srcsim/simctl.c | 2 +- altairsim/srcsim/simmem.c | 52 ++++++++++++++++---------------- altairsim/srcsim/simmem.h | 6 ++-- cpmsim/srcsim/simio.c | 6 ++-- cpmsim/srcsim/simmem.c | 4 +-- cromemcosim/srcsim/simctl.c | 4 +-- cromemcosim/srcsim/simmem.c | 58 +++++++++++++++++------------------ imsaisim/srcsim/simmem.c | 60 ++++++++++++++++++------------------- intelmdssim/srcsim/simmem.c | 4 +-- iodevices/tarbell_fdc.c | 6 ++-- iodevices/tarbell_fdc.h | 2 +- mosteksim/srcsim/simcfg.c | 2 +- mosteksim/srcsim/simmem.c | 4 +-- picosim/srcsim/picosim.c | 2 +- webfrontend/netsrv.c | 18 +++++------ z80core/sim8080.c | 10 +++---- z80core/simglb.c | 26 ++++++++-------- z80core/simglb.h | 12 ++++---- z80core/simice.c | 14 ++++----- z80core/simice.h | 2 +- z80core/simmain.c | 44 +++++++++++++-------------- z80core/simz80.c | 10 +++---- z80sim/srcsim/simctl.c | 2 +- z80sim/srcsim/simmem.c | 4 +-- 24 files changed, 177 insertions(+), 177 deletions(-) diff --git a/altairsim/srcsim/simctl.c b/altairsim/srcsim/simctl.c index a712b720..68928bff 100644 --- a/altairsim/srcsim/simctl.c +++ b/altairsim/srcsim/simctl.c @@ -394,7 +394,7 @@ static void reset_clicked(int state, int val) reset_cpu(); if (reset == 2) if (!R_flag) - PC = _boot_switch[M_flag]; + PC = _boot_switch[M_value]; reset = 0; cpu_state &= ~ST_RESET; diff --git a/altairsim/srcsim/simmem.c b/altairsim/srcsim/simmem.c index 0d9a06dc..92fe8270 100644 --- a/altairsim/srcsim/simmem.c +++ b/altairsim/srcsim/simmem.c @@ -56,10 +56,10 @@ void init_memory(void) strcat(fn, "/"); pfn = &fn[strlen(fn)]; - if (!memconf[M_flag][0].size) { + if (!memconf[M_value][0].size) { LOGW(TAG, "The [MEMORY %d] section appears missing or empty, " - "setting memory map to default", M_flag + 1); - M_flag = 0; + "setting memory map to default", M_value + 1); + M_value = 0; } /* initialize memory page table, no memory available */ @@ -68,47 +68,47 @@ void init_memory(void) /* set memory configuration from system.conf */ for (i = 0; i < MAXMEMMAP; i++) { - if (memconf[M_flag][i].size) { + if (memconf[M_value][i].size) { - for (j = 0; j < memconf[M_flag][i].size; j++) - p_tab[memconf[M_flag][i].spage + j] = memconf[M_flag][i].type; + for (j = 0; j < memconf[M_value][i].size; j++) + p_tab[memconf[M_value][i].spage + j] = memconf[M_value][i].type; - switch (memconf[M_flag][i].type) { + switch (memconf[M_value][i].type) { case MEM_RW: /* fill memory content with some initial value */ - for (j = memconf[M_flag][i].spage << 8; - j < (memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8; + for (j = memconf[M_value][i].spage << 8; + j < (memconf[M_value][i].spage + memconf[M_value][i].size) << 8; j++) { - if (m_flag >= 0) { - memory[j] = m_flag; + if (m_value >= 0) { + memory[j] = m_value; } else { memory[j] = (BYTE) (rand() % 256); } } LOG(TAG, "RAM %04XH - %04XH\r\n", - memconf[M_flag][i].spage << 8, - ((memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8) - 1); + memconf[M_value][i].spage << 8, + ((memconf[M_value][i].spage + memconf[M_value][i].size) << 8) - 1); break; case MEM_RO: /* fill the ROM's with 0xff in case no firmware loaded */ - for (j = memconf[M_flag][i].spage; - j < (memconf[M_flag][i].spage + memconf[M_flag][i].size); + for (j = memconf[M_value][i].spage; + j < (memconf[M_value][i].spage + memconf[M_value][i].size); j++) { memset(&memory[j << 8], 0xff, 256); } LOG(TAG, "ROM %04XH - %04XH %s\r\n\r\n", - memconf[M_flag][i].spage << 8, - ((memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8) - 1, - memconf[M_flag][i].rom_file ? memconf[M_flag][i].rom_file : ""); + memconf[M_value][i].spage << 8, + ((memconf[M_value][i].spage + memconf[M_value][i].size) << 8) - 1, + memconf[M_value][i].rom_file ? memconf[M_value][i].rom_file : ""); /* load firmware into ROM if specified */ - if (memconf[M_flag][i].rom_file) { - strcpy(pfn, memconf[M_flag][i].rom_file); - load_file(fn, memconf[M_flag][i].spage << 8, - memconf[M_flag][i].size << 8); + if (memconf[M_value][i].rom_file) { + strcpy(pfn, memconf[M_value][i].rom_file); + load_file(fn, memconf[M_value][i].spage << 8, + memconf[M_value][i].size << 8); } break; } @@ -116,10 +116,10 @@ void init_memory(void) } /* set preferred start of boot ROM if specified */ - if (_boot_switch[M_flag]) { - LOG(TAG, "Boot switch address at %04XH\r\n", _boot_switch[M_flag]); - boot_switch = _boot_switch[M_flag]; - PC = _boot_switch[M_flag]; + if (_boot_switch[M_value]) { + LOG(TAG, "Boot switch address at %04XH\r\n", _boot_switch[M_value]); + boot_switch = _boot_switch[M_value]; + PC = _boot_switch[M_value]; } else { PC = 0x0000; } diff --git a/altairsim/srcsim/simmem.h b/altairsim/srcsim/simmem.h index da108a6e..216020ff 100644 --- a/altairsim/srcsim/simmem.h +++ b/altairsim/srcsim/simmem.h @@ -126,7 +126,7 @@ static inline BYTE memrdr(WORD addr) data = memory[addr]; else data = 0xff; - tarbell_rom_active = 0; + tarbell_rom_active = false; } } else { if (p_tab[addr >> 8] != MEM_NONE) @@ -165,7 +165,7 @@ static inline BYTE dma_read(WORD addr) if (addr <= 0x001f) return tarbell_rom[addr]; else - tarbell_rom_active = 0; + tarbell_rom_active = false; } if (p_tab[addr >> 8] != MEM_NONE) @@ -210,7 +210,7 @@ static inline BYTE fp_read(WORD addr) if (addr <= 0x001f) return tarbell_rom[addr]; else - tarbell_rom_active = 0; + tarbell_rom_active = false; } if (p_tab[addr >> 8] != MEM_NONE) diff --git a/cpmsim/srcsim/simio.c b/cpmsim/srcsim/simio.c index 04a1f707..b859edd1 100644 --- a/cpmsim/srcsim/simio.c +++ b/cpmsim/srcsim/simio.c @@ -2067,7 +2067,7 @@ static void speedl_out(BYTE data) */ static BYTE speedl_in(void) { - return f_flag & 0xff; + return f_value & 0xff; } /* @@ -2077,7 +2077,7 @@ static void speedh_out(BYTE data) { speed += data << 8; tmax = speed * 10000; - f_flag = speed; + f_value = speed; } /* @@ -2085,7 +2085,7 @@ static void speedh_out(BYTE data) */ static BYTE speedh_in(void) { - return f_flag >> 8; + return f_value >> 8; } /* diff --git a/cpmsim/srcsim/simmem.c b/cpmsim/srcsim/simmem.c index 43e49b19..1fea911e 100644 --- a/cpmsim/srcsim/simmem.c +++ b/cpmsim/srcsim/simmem.c @@ -59,9 +59,9 @@ void init_memory(void) selbnk = 0; /* fill memory content of bank 0 with some initial value */ - if (m_flag >= 0) { + if (m_value >= 0) { for (i = 0; i < 65536; i++) - putmem(i, m_flag); + putmem(i, m_value); } else { for (i = 0; i < 65536; i++) putmem(i, (BYTE) (rand() % 256)); diff --git a/cromemcosim/srcsim/simctl.c b/cromemcosim/srcsim/simctl.c index 69e8fd98..e7705ef0 100644 --- a/cromemcosim/srcsim/simctl.c +++ b/cromemcosim/srcsim/simctl.c @@ -399,7 +399,7 @@ static void reset_clicked(int state, int val) /* reset CPU */ reset_cpu(); #ifdef HAS_BANKED_ROM - PC = boot_switch[M_flag]; + PC = boot_switch[M_value]; #endif reset = 0; cpu_state &= ~ST_RESET; @@ -497,7 +497,7 @@ static void power_clicked(int state, int val) cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; fp_led_address = PC; fp_led_data = getmem(PC); - fp_led_speed = (f_flag == 0 || f_flag >= 4) ? 1 : 0; + fp_led_speed = (f_value == 0 || f_value >= 4) ? 1 : 0; fp_led_wait = 1; fp_led_output = 0; if (!isatty(fileno(stdout)) || (system("tput clear") == -1)) diff --git a/cromemcosim/srcsim/simmem.c b/cromemcosim/srcsim/simmem.c index 0d7e9f28..bc42d1d6 100644 --- a/cromemcosim/srcsim/simmem.c +++ b/cromemcosim/srcsim/simmem.c @@ -58,10 +58,10 @@ void init_memory(void) LOG(TAG, "\r\n"); - if (!memconf[M_flag][0].size) { + if (!memconf[M_value][0].size) { LOGW(TAG, "The [MEMORY %d] section appears missing or empty, " - "setting memory map to default", M_flag + 1); - M_flag = 0; + "setting memory map to default", M_value + 1); + M_value = 0; } /* initialize memory page table, no memory available */ @@ -77,35 +77,35 @@ void init_memory(void) /* set memory configuration from system.conf only for bank 0 */ for (i = 0; i < MAXMEMMAP; i++) { - if (memconf[M_flag][i].size) { - switch (memconf[M_flag][i].type) { + if (memconf[M_value][i].size) { + switch (memconf[M_value][i].type) { case MEM_RW: /* set the pages to RAM */ - for (j = 0; j < memconf[M_flag][i].size; j++) - MEM_RESERVE_RAM(memconf[M_flag][i].spage + j); + for (j = 0; j < memconf[M_value][i].size; j++) + MEM_RESERVE_RAM(memconf[M_value][i].spage + j); /* fill memory content with some initial value */ - for (j = memconf[M_flag][i].spage << 8; - j < (memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8; + for (j = memconf[M_value][i].spage << 8; + j < (memconf[M_value][i].spage + memconf[M_value][i].size) << 8; j++) { - if (m_flag >= 0) { - memory[0][j] = m_flag; + if (m_value >= 0) { + memory[0][j] = m_value; } else { memory[0][j] = (BYTE) (rand() % 256); } } LOG(TAG, "RAM %04XH - %04XH\r\n", - memconf[M_flag][i].spage << 8, - ((memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8) - 1); + memconf[M_value][i].spage << 8, + ((memconf[M_value][i].spage + memconf[M_value][i].size) << 8) - 1); break; case MEM_RO: /* set the pages to ROM */ LOG(TAG, "ROM %04XH - %04XH %s\r\n", - memconf[M_flag][i].spage << 8, - ((memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8) - 1, - memconf[M_flag][i].rom_file ? memconf[M_flag][i].rom_file : ""); + memconf[M_value][i].spage << 8, + ((memconf[M_value][i].spage + memconf[M_value][i].size) << 8) - 1, + memconf[M_value][i].rom_file ? memconf[M_value][i].rom_file : ""); /* for the CROMEMCO Z-1, ROM must be initialized after FDC banked ROM is initialized */ @@ -116,9 +116,9 @@ void init_memory(void) } /* set preferred start of boot ROM if specified */ - if (boot_switch[M_flag]) { - LOG(TAG, "Power-on jump address at %04XH\r\n", boot_switch[M_flag]); - PC = boot_switch[M_flag]; + if (boot_switch[M_value]) { + LOG(TAG, "Power-on jump address at %04XH\r\n", boot_switch[M_value]); + PC = boot_switch[M_value]; } else { PC = 0x0000; } @@ -134,9 +134,9 @@ void init_memory(void) cromemco_fdc_reset(); /* activates FDC banked ROM */ for (i = 0; i < MAXMEMMAP; i++) { - if (memconf[M_flag][i].size) { + if (memconf[M_value][i].size) { - switch (memconf[M_flag][i].type) { + switch (memconf[M_value][i].type) { case MEM_RW: /* set the pages to RAM */ /* for the CROMEMCO Z-1, RAM must be @@ -146,21 +146,21 @@ void init_memory(void) break; case MEM_RO: /* set the pages to ROM */ - for (j = 0; j < memconf[M_flag][i].size; j++) - MEM_RESERVE_ROM(memconf[M_flag][i].spage + j); + for (j = 0; j < memconf[M_value][i].size; j++) + MEM_RESERVE_ROM(memconf[M_value][i].spage + j); /* fill the ROM's with 0xff in case no firmware loaded */ - for (j = memconf[M_flag][i].spage; - j < (memconf[M_flag][i].spage + memconf[M_flag][i].size); + for (j = memconf[M_value][i].spage; + j < (memconf[M_value][i].spage + memconf[M_value][i].size); j++) { memset(&memory[0][j << 8], 0xff, 256); } /* load firmware into ROM if specified */ - if (memconf[M_flag][i].rom_file) { - strcpy(pfn, memconf[M_flag][i].rom_file); - load_file(fn, memconf[M_flag][i].spage << 8, - memconf[M_flag][i].size << 8); + if (memconf[M_value][i].rom_file) { + strcpy(pfn, memconf[M_value][i].rom_file); + load_file(fn, memconf[M_value][i].spage << 8, + memconf[M_value][i].size << 8); } break; } diff --git a/imsaisim/srcsim/simmem.c b/imsaisim/srcsim/simmem.c index 4540ad22..4c64732c 100644 --- a/imsaisim/srcsim/simmem.c +++ b/imsaisim/srcsim/simmem.c @@ -161,10 +161,10 @@ void init_memory(void) LOG(TAG, "\r\n"); - if (!memconf[M_flag][0].size) { + if (!memconf[M_value][0].size) { LOGW(TAG, "The [MEMORY %d] section appears missing or empty, " - "setting memory map to default", M_flag + 1); - M_flag = 0; + "setting memory map to default", M_value + 1); + M_value = 0; } /* initialize memory page table, no memory available */ @@ -175,35 +175,35 @@ void init_memory(void) } for (i = 0; i < MAXMEMMAP; i++) { - if (memconf[M_flag][i].size) { - switch (memconf[M_flag][i].type) { + if (memconf[M_value][i].size) { + switch (memconf[M_value][i].type) { case MEM_RW: /* set the pages to RAM */ - for (j = 0; j < memconf[M_flag][i].size; j++) - MEM_RESERVE_RAM(memconf[M_flag][i].spage + j); + for (j = 0; j < memconf[M_value][i].size; j++) + MEM_RESERVE_RAM(memconf[M_value][i].spage + j); /* fill memory content of bank 0 with some initial value */ - for (j = memconf[M_flag][i].spage << 8; - j < (memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8; + for (j = memconf[M_value][i].spage << 8; + j < (memconf[M_value][i].spage + memconf[M_value][i].size) << 8; j++) { - if (m_flag >= 0) { - _MEMMAPPED(j) = m_flag; + if (m_value >= 0) { + _MEMMAPPED(j) = m_value; } else { _MEMMAPPED(j) = (BYTE) (rand() % 256); } } LOG(TAG, "RAM %04XH - %04XH\r\n", - memconf[M_flag][i].spage << 8, - ((memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8) - 1); + memconf[M_value][i].spage << 8, + ((memconf[M_value][i].spage + memconf[M_value][i].size) << 8) - 1); break; case MEM_RO: /* set the pages to ROM */ LOG(TAG, "ROM %04XH - %04XH %s\r\n", - memconf[M_flag][i].spage << 8, - ((memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8) - 1, - memconf[M_flag][i].rom_file ? memconf[M_flag][i].rom_file : ""); + memconf[M_value][i].spage << 8, + ((memconf[M_value][i].spage + memconf[M_value][i].size) << 8) - 1, + memconf[M_value][i].rom_file ? memconf[M_value][i].rom_file : ""); /* for the IMSAI, ROM must be initialized after MPU-B banked ROM is initialized */ @@ -213,8 +213,8 @@ void init_memory(void) } } - if (boot_switch[M_flag]) { - LOG(TAG, "Power-on jump address at %04XH\r\n", boot_switch[M_flag]); + if (boot_switch[M_value]) { + LOG(TAG, "Power-on jump address at %04XH\r\n", boot_switch[M_value]); } /* copy RAM page table for MPU-B banked ROM/RAM handling */ @@ -238,8 +238,8 @@ void init_memory(void) LOG(TAG, "\r\n"); for (i = 0; i < MAXMEMMAP; i++) { - if (memconf[M_flag][i].size) { - switch (memconf[M_flag][i].type) { + if (memconf[M_value][i].size) { + switch (memconf[M_value][i].type) { case MEM_RW: /* set the pages to RAM */ /* for the IMSAI, RAM must be @@ -250,21 +250,21 @@ void init_memory(void) case MEM_RO: /* set the pages to ROM */ - for (j = 0; j < memconf[M_flag][i].size; j++) - MEM_RESERVE_ROM(memconf[M_flag][i].spage + j); + for (j = 0; j < memconf[M_value][i].size; j++) + MEM_RESERVE_ROM(memconf[M_value][i].spage + j); /* fill the ROM's with 0xff in case no firmware loaded */ - for (j = memconf[M_flag][i].spage << 8; - j < (memconf[M_flag][i].spage + memconf[M_flag][i].size) << 8; + for (j = memconf[M_value][i].spage << 8; + j < (memconf[M_value][i].spage + memconf[M_value][i].size) << 8; j++) { _MEMMAPPED(j) = 0xff; } /* load firmware into ROM if specified */ - if (memconf[M_flag][i].rom_file) { - strcpy(pfn, memconf[M_flag][i].rom_file); - load_file(fn, memconf[M_flag][i].spage << 8, - memconf[M_flag][i].size << 8); + if (memconf[M_value][i].rom_file) { + strcpy(pfn, memconf[M_value][i].rom_file); + load_file(fn, memconf[M_value][i].spage << 8, + memconf[M_value][i].size << 8); } break; } @@ -272,8 +272,8 @@ void init_memory(void) } /* set preferred start of boot ROM if specified */ - if (boot_switch[M_flag]) { - PC = boot_switch[M_flag]; + if (boot_switch[M_value]) { + PC = boot_switch[M_value]; } else { PC = 0x0000; } diff --git a/intelmdssim/srcsim/simmem.c b/intelmdssim/srcsim/simmem.c index 8c56e829..4a031005 100644 --- a/intelmdssim/srcsim/simmem.c +++ b/intelmdssim/srcsim/simmem.c @@ -69,9 +69,9 @@ void init_memory(void) } /* fill memory content with some initial value */ - if (m_flag >= 0) { + if (m_value >= 0) { for (i = 0; i < 65536; i++) - putmem(i, m_flag); + putmem(i, m_value); } else { for (i = 0; i < 65536; i++) putmem(i, (BYTE) (rand() % 256)); diff --git a/iodevices/tarbell_fdc.c b/iodevices/tarbell_fdc.c index ba9d410d..e2691d28 100644 --- a/iodevices/tarbell_fdc.c +++ b/iodevices/tarbell_fdc.c @@ -79,8 +79,8 @@ BYTE tarbell_rom[32] = { 0x00, 0xdb, 0xf8, 0xb7, 0xca, 0x7d, 0x00, 0x76 }; -int tarbell_rom_enabled = 0; /* ROM not enabled by default */ -int tarbell_rom_active = 1; /* ROM is active at power on */ +bool tarbell_rom_enabled = false; /* ROM not enabled by default */ +bool tarbell_rom_active = true; /* ROM is active at power on */ /* * find and set path for disk images @@ -502,5 +502,5 @@ void tarbell_ext_out(BYTE data) void tarbell_reset(void) { fdc_stat = fdc_track = fdc_sec = disk = state = dcnt = 0; - tarbell_rom_active = 1; + tarbell_rom_active = true; } diff --git a/iodevices/tarbell_fdc.h b/iodevices/tarbell_fdc.h index 847cd4c8..fc15dde6 100644 --- a/iodevices/tarbell_fdc.h +++ b/iodevices/tarbell_fdc.h @@ -32,7 +32,7 @@ #include "simdefs.h" extern BYTE tarbell_rom[32]; -extern int tarbell_rom_enabled, tarbell_rom_active; +extern bool tarbell_rom_enabled, tarbell_rom_active; extern void dsk_path(void); diff --git a/mosteksim/srcsim/simcfg.c b/mosteksim/srcsim/simcfg.c index 3f0e52cf..cfc5a78d 100644 --- a/mosteksim/srcsim/simcfg.c +++ b/mosteksim/srcsim/simcfg.c @@ -59,7 +59,7 @@ void config(void) strcpy(xfn, rompath); strcat(xfn, "/"); strcat(xfn, t2); - x_flag = 1; + x_flag = true; } else if (0 == strcmp(t1, "drive0")) { LOG(TAG, "\r\nDrive 0: %s\r\n", t2); } else if (0 == strcmp(t1, "drive1")) { diff --git a/mosteksim/srcsim/simmem.c b/mosteksim/srcsim/simmem.c index d12ada7e..368a21ae 100644 --- a/mosteksim/srcsim/simmem.c +++ b/mosteksim/srcsim/simmem.c @@ -26,9 +26,9 @@ void init_memory(void) register int i; /* fill memory content with some initial value */ - if (m_flag >= 0) { + if (m_value >= 0) { for (i = 0; i < 65536; i++) - putmem(i, m_flag); + putmem(i, m_value); } else { for (i = 0; i < 65536; i++) putmem(i, (BYTE) (rand() % 256)); diff --git a/picosim/srcsim/picosim.c b/picosim/srcsim/picosim.c index 9a13ab0f..be67962c 100644 --- a/picosim/srcsim/picosim.c +++ b/picosim/srcsim/picosim.c @@ -204,7 +204,7 @@ int main(void) PC = 0xff00; /* power on jump into the boot ROM */ config(); /* configure the machine */ - f_flag = speed; /* setup speed of the CPU */ + f_value = speed; /* setup speed of the CPU */ tmax = speed * 10000; /* theoretically */ put_pixel(0x440000); /* LED green */ diff --git a/webfrontend/netsrv.c b/webfrontend/netsrv.c index b2c8deb6..b7b9284e 100644 --- a/webfrontend/netsrv.c +++ b/webfrontend/netsrv.c @@ -310,7 +310,7 @@ static int SystemHandler(HttpdConnection_t *conn, void *unused) { httpdPrintf(conn, "\"%s\": %d, ", "cpa", 1); } #endif - httpdPrintf(conn, "\"%s\": %d ", "clock", f_flag); + httpdPrintf(conn, "\"%s\": %d ", "clock", f_value); httpdPrintf(conn, "} "); #ifdef HAS_HAL @@ -362,15 +362,15 @@ static int SystemHandler(HttpdConnection_t *conn, void *unused) { httpdPrintf(conn, ", \"memmap\": [ "); for (int i=0; i < MAXMEMMAP; i++) { - if (memconf[M_flag][i].size) { + if (memconf[M_value][i].size) { if (i > 0) httpdPrintf(conn, ", "); - httpdPrintf(conn, "{ \"type\": \"%s\"", (memconf[M_flag][i].type==MEM_RW)?"RAM":"ROM"); - httpdPrintf(conn, ", \"from\": %d", memconf[M_flag][i].spage << 8); - httpdPrintf(conn, ", \"to\": %d", (memconf[M_flag][i].spage << 8) + (memconf[M_flag][i].size << 8) - 1); - if (memconf[M_flag][i].type==MEM_RO && memconf[M_flag][i].rom_file) - httpdPrintf(conn, ", \"file\": \"%s\"", memconf[M_flag][i].rom_file); + httpdPrintf(conn, "{ \"type\": \"%s\"", (memconf[M_value][i].type==MEM_RW)?"RAM":"ROM"); + httpdPrintf(conn, ", \"from\": %d", memconf[M_value][i].spage << 8); + httpdPrintf(conn, ", \"to\": %d", (memconf[M_value][i].spage << 8) + (memconf[M_value][i].size << 8) - 1); + if (memconf[M_value][i].type==MEM_RO && memconf[M_value][i].rom_file) + httpdPrintf(conn, ", \"file\": \"%s\"", memconf[M_value][i].rom_file); httpdPrintf(conn, "}"); } } @@ -379,8 +379,8 @@ static int SystemHandler(HttpdConnection_t *conn, void *unused) { httpdPrintf(conn, ", \"memextra\": [ "); - if (boot_switch[M_flag]) { - httpdPrintf(conn, "\"Power-on jump address %04XH\", ", boot_switch[M_flag]); + if (boot_switch[M_value]) { + httpdPrintf(conn, "\"Power-on jump address %04XH\", ", boot_switch[M_value]); } if (R_flag) { httpdPrintf(conn, "\"%s\", ", BANKED_ROM_MSG); diff --git a/z80core/sim8080.c b/z80core/sim8080.c index f32a0f48..d584aca6 100644 --- a/z80core/sim8080.c +++ b/z80core/sim8080.c @@ -453,8 +453,8 @@ void cpu_8080(void) /* hand control to the DMA bus master without BUS_ACK */ T += (T_dma = (*dma_bus_master)(0)); - if (f_flag) - cpu_time += T_dma / f_flag; + if (f_value) + cpu_time += T_dma / f_value; } } @@ -471,8 +471,8 @@ void cpu_8080(void) /* hand control to the DMA bus master with BUS_ACK */ T += (T_dma = (*dma_bus_master)(1)); - if (f_flag) - cpu_time += T_dma / f_flag; + if (f_value) + cpu_time += T_dma / f_value; } /* FOR NOW - MAY BE NEED A PRIORITY SYSTEM LATER */ @@ -597,7 +597,7 @@ void cpu_8080(void) #include "alt8080.h" #endif - if (f_flag) { /* adjust CPU speed */ + if (f_value) { /* adjust CPU speed */ if (T >= T_max && !cpu_needed) { t2 = get_clock_us(); tdiff = t2 - t1; diff --git a/z80core/simglb.c b/z80core/simglb.c index eaff91dc..70384052 100644 --- a/z80core/simglb.c +++ b/z80core/simglb.c @@ -90,26 +90,26 @@ port_flags_t port_flags[256]; /* port access flags */ /* * Flags to control operation of simulation */ -int s_flag; /* flag for -s option */ -int l_flag; /* flag for -l option */ -int m_flag = -1; /* flag for -m option */ -int x_flag; /* flag for -x option */ -int i_flag; /* flag for -i option */ -int f_flag; /* flag for -f option */ -int u_flag; /* flag for -u option */ -int r_flag; /* flag for -r option */ -int c_flag; /* flag for -c option */ +bool s_flag; /* flag for -s option */ +bool l_flag; /* flag for -l option */ +int m_value = -1; /* value of -m option */ +bool x_flag; /* flag for -x option */ +bool i_flag; /* flag for -i option */ +int f_value; /* value of -f option */ +bool u_flag; /* flag for -u option */ +bool r_flag; /* flag for -r option */ +bool c_flag; /* flag for -c option */ #ifdef HAS_CONFIG -int M_flag = 0; /* flag for -M option */ +int M_value = 0; /* value of -M option */ #endif #ifdef HAS_BANKED_ROM -int R_flag = 0; /* flag for -R option */ +bool R_flag = false; /* flag for -R option */ #endif #ifdef FRONTPANEL -int F_flag = 1; /* flag for -F option */ +bool F_flag = true; /* flag for -F option */ #endif #ifdef HAS_NETSERVER -int n_flag; /* flag for -n option */ +bool n_flag; /* flag for -n option */ #endif /* diff --git a/z80core/simglb.h b/z80core/simglb.h index b789decb..231c6f06 100644 --- a/z80core/simglb.h +++ b/z80core/simglb.h @@ -72,19 +72,19 @@ extern BYTE fp_led_output; extern port_flags_t port_flags[256]; #endif -extern int s_flag, l_flag, m_flag, x_flag, i_flag, f_flag, - u_flag, r_flag, c_flag; +extern bool s_flag, l_flag, x_flag, i_flag, u_flag, r_flag, c_flag; +extern int m_value, f_value; #ifdef HAS_CONFIG -extern int M_flag; +extern int M_value; #endif #ifdef HAS_BANKED_ROM -extern int R_flag; +extern bool R_flag; #endif #ifdef FRONTPANEL -extern int F_flag; +extern bool F_flag; #endif #ifdef HAS_NETSERVER -extern int n_flag; +extern bool n_flag; #endif extern char xfn[MAX_LFN]; diff --git a/z80core/simice.c b/z80core/simice.c index 7d4b8351..0ae47634 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -114,9 +114,9 @@ void (*ice_cust_help)(void); /* * The function "ice_cmd_loop()" is the dialog user interface, called - * from the simulation when desired with go_flag set to 0, or, when + * from the simulation when desired with go_mode set to 0, or, when * no other user interface is needed, directly after any necessary - * initialization work at program start with go_flag set to 1 (or 2 + * initialization work at program start with go_mode set to 1 (or 2 * with timing output). * * There are also two function pointers "ice_before_go" and @@ -130,12 +130,12 @@ void (*ice_cust_help)(void); * parameters. "ice_cust_help" can be set to a void function(void) * to display help for custom commands. */ -void ice_cmd_loop(int go_flag) +void ice_cmd_loop(int go_mode) { register int eoj = 1; static char cmd[LENCMD]; - if (!go_flag) { + if (!go_mode) { report_cpu_error(); print_head(); print_reg(); @@ -144,9 +144,9 @@ void ice_cmd_loop(int go_flag) wrk_addr = PC; while (eoj) { - if (go_flag) { - strcpy(cmd, (go_flag > 1) ? "g *" : "g"); - go_flag = 0; + if (go_mode) { + strcpy(cmd, (go_mode > 1) ? "g *" : "g"); + go_mode = 0; } else { printf(">>> "); fflush(stdout); diff --git a/z80core/simice.h b/z80core/simice.h index 5279a402..220f7314 100644 --- a/z80core/simice.h +++ b/z80core/simice.h @@ -64,7 +64,7 @@ extern void (*ice_after_go)(void); extern void (*ice_cust_cmd)(char *cmd, WORD *wrk_addr); extern void (*ice_cust_help)(void); -extern void ice_cmd_loop(int go_flag); +extern void ice_cmd_loop(int go_mode); #endif /* WANT_ICE */ diff --git a/z80core/simmain.c b/z80core/simmain.c index 1f748f6f..87788d57 100644 --- a/z80core/simmain.c +++ b/z80core/simmain.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) #endif #endif #ifdef CPU_SPEED - f_flag = CPU_SPEED; + f_value = CPU_SPEED; tmax = CPU_SPEED * 10000; /* theoretically */ #endif @@ -70,50 +70,50 @@ int main(int argc, char *argv[]) switch (*s) { case 's': /* save core and CPU on exit */ - s_flag = 1; + s_flag = true; break; case 'l': /* load core and CPU from file */ - l_flag = 1; + l_flag = true; break; case 'u': /* trap undocumented ops */ - u_flag = 1; + u_flag = true; break; case 'i': /* trap I/O on unused ports */ - i_flag = 1; + i_flag = true; break; case 'm': /* initialize memory */ if (*(s + 1) != '\0') { - m_flag = strtol(s + 1, NULL, 16); + m_value = strtol(s + 1, NULL, 16); s += strlen(s + 1); } else { if (argc <= 1) goto usage; argc--; argv++; - m_flag = strtol(argv[0], NULL, 16); + m_value = strtol(argv[0], NULL, 16); } break; case 'f': /* set emulation speed */ if (*(s + 1) != '\0') { - f_flag = atoi(s + 1); + f_value = atoi(s + 1); s += strlen(s + 1); } else { if (argc <= 1) goto usage; argc--; argv++; - f_flag = atoi(argv[0]); + f_value = atoi(argv[0]); } - tmax = f_flag * 10000; /* theoretically */ + tmax = f_value * 10000; /* theoretically */ break; case 'x': /* get filename with executable */ - x_flag = 1; + x_flag = true; s++; if (*s == '\0') { if (argc <= 1) @@ -148,8 +148,8 @@ int main(int argc, char *argv[]) #else /* !HAS_CONFIG */ #ifdef BOOTROM case 'r': /* load default boot ROM */ - r_flag = 1; - x_flag = 1; + r_flag = true; + x_flag = true; strcpy(xfn, BOOTROM); break; #endif @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) #ifdef HAS_CONFIG case 'c': /* get config file */ - c_flag = 1; + c_flag = true; s++; if (*s == '\0') { if (argc <= 1) @@ -194,16 +194,16 @@ int main(int argc, char *argv[]) #if MAXMEMSECT > 0 case 'M': /* use memory map section nn */ if (*(s + 1) != '\0') { - M_flag = atoi(s + 1) - 1; + M_value = atoi(s + 1) - 1; s += strlen(s + 1); } else { if (argc <= 1) goto usage; argc--; argv++; - M_flag = atoi(argv[0]) - 1; + M_value = atoi(argv[0]) - 1; } - if (M_flag < 0 || M_flag > (MAXMEMSECT - 1)) + if (M_value < 0 || M_value > (MAXMEMSECT - 1)) goto usage; break; #endif @@ -213,7 +213,7 @@ int main(int argc, char *argv[]) #ifdef HAS_BANKED_ROM case 'R': /* enable banked ROM for machines that implement it */ - R_flag = 1; + R_flag = true; break; #endif @@ -230,12 +230,12 @@ int main(int argc, char *argv[]) #endif #ifdef FRONTPANEL case 'F': /* disable front panel emulation */ - F_flag = 0; + F_flag = false; break; #endif #ifdef HAS_NETSERVER case 'n': /* enable web-based frontend */ - n_flag = 1; + n_flag = true; break; #endif @@ -366,8 +366,8 @@ puts(" ##### ### ##### ### ##### ### # #"); putchar('\n'); #endif - if (f_flag > 0) - printf("CPU speed is %d MHz", f_flag); + if (f_value > 0) + printf("CPU speed is %d MHz", f_value); else fputs("CPU speed is unlimited", stdout); diff --git a/z80core/simz80.c b/z80core/simz80.c index 377a408c..7c7276f1 100644 --- a/z80core/simz80.c +++ b/z80core/simz80.c @@ -436,8 +436,8 @@ void cpu_z80(void) /* hand control to the DMA bus master without BUS_ACK */ T += (T_dma = (*dma_bus_master)(0)); - if (f_flag) - cpu_time += T_dma / f_flag; + if (f_value) + cpu_time += T_dma / f_value; } } @@ -454,8 +454,8 @@ void cpu_z80(void) /* hand control to the DMA bus master with BUS_ACK */ T += (T_dma = (*dma_bus_master)(1)); - if (f_flag) - cpu_time += T_dma / f_flag; + if (f_value) + cpu_time += T_dma / f_value; } /* FOR NOW - MAY BE NEED A PRIORITY SYSTEM LATER */ @@ -609,7 +609,7 @@ void cpu_z80(void) #include "altz80.h" #endif - if (f_flag) { /* adjust CPU speed */ + if (f_value) { /* adjust CPU speed */ if (T >= T_max && !cpu_needed) { t2 = get_clock_us(); tdiff = t2 - t1; diff --git a/z80sim/srcsim/simctl.c b/z80sim/srcsim/simctl.c index 83d06118..802fecaf 100644 --- a/z80sim/srcsim/simctl.c +++ b/z80sim/srcsim/simctl.c @@ -26,5 +26,5 @@ void mon(void) ice_before_go = set_unix_terminal; ice_after_go = reset_unix_terminal; atexit(reset_unix_terminal); - ice_cmd_loop(x_flag); + ice_cmd_loop(x_flag ? 1 : 0); } diff --git a/z80sim/srcsim/simmem.c b/z80sim/srcsim/simmem.c index f1618970..0ab0d892 100644 --- a/z80sim/srcsim/simmem.c +++ b/z80sim/srcsim/simmem.c @@ -26,9 +26,9 @@ void init_memory(void) register int i; /* fill memory content with some initial value */ - if (m_flag >= 0) { + if (m_value >= 0) { for (i = 0; i < 65536; i++) - putmem(i, m_flag); + putmem(i, m_value); } else { for (i = 0; i < 65536; i++) putmem(i, (BYTE) (rand() % 256)); From 39c91b6fd7bfa7655c2a28bf904bd5b1f6dbc232 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 05:39:07 +0100 Subject: [PATCH 06/19] boolify mds-monitor --- intelmdssim/srcsim/simcfg.c | 24 ++++----- iodevices/mds-monitor.c | 102 +++++++++++++++++++----------------- iodevices/mds-monitor.h | 12 ++--- 3 files changed, 71 insertions(+), 67 deletions(-) diff --git a/intelmdssim/srcsim/simcfg.c b/intelmdssim/srcsim/simcfg.c index 8295e6a6..160dcbde 100644 --- a/intelmdssim/srcsim/simcfg.c +++ b/intelmdssim/srcsim/simcfg.c @@ -61,10 +61,10 @@ void config(void) if (!strcmp(t1, "tty_upper_case")) { switch (*t2) { case '0': - tty_upper_case = 0; + tty_upper_case = false; break; case '1': - tty_upper_case = 1; + tty_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -73,10 +73,10 @@ void config(void) } else if (!strcmp(t1, "crt_upper_case")) { switch (*t2) { case '0': - crt_upper_case = 0; + crt_upper_case = false; break; case '1': - crt_upper_case = 1; + crt_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -85,10 +85,10 @@ void config(void) } else if (!strcmp(t1, "tty_strip_parity")) { switch (*t2) { case '0': - tty_strip_parity = 0; + tty_strip_parity = false; break; case '1': - tty_strip_parity = 1; + tty_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -97,10 +97,10 @@ void config(void) } else if (!strcmp(t1, "crt_strip_parity")) { switch (*t2) { case '0': - crt_strip_parity = 0; + crt_strip_parity = false; break; case '1': - crt_strip_parity = 1; + crt_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -109,10 +109,10 @@ void config(void) } else if (!strcmp(t1, "tty_drop_nulls")) { switch (*t2) { case '0': - tty_drop_nulls = 0; + tty_drop_nulls = false; break; case '1': - tty_drop_nulls = 1; + tty_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -121,10 +121,10 @@ void config(void) } else if (!strcmp(t1, "crt_drop_nulls")) { switch (*t2) { case '0': - crt_drop_nulls = 0; + crt_drop_nulls = false; break; case '1': - crt_drop_nulls = 1; + crt_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); diff --git a/iodevices/mds-monitor.c b/iodevices/mds-monitor.c index 5d06d2da..98a5e160 100644 --- a/iodevices/mds-monitor.c +++ b/iodevices/mds-monitor.c @@ -81,34 +81,34 @@ static const char *TAG = "MONITOR"; static BYTE mon_int; /* Interrupts enabled & signals */ static pthread_mutex_t mon_int_mutex = PTHREAD_MUTEX_INITIALIZER; -int tty_upper_case; -int tty_strip_parity; -int tty_drop_nulls; +bool tty_upper_case; +bool tty_strip_parity; +bool tty_drop_nulls; int tty_clock_div = 32; /* 1200 baud */ -static int tty_init; /* TTY initialized flag */ +static bool tty_init; /* TTY initialized flag */ static BYTE tty_cmd; /* TTY command byte */ -static int tty_trdy; /* TTY transmit ready */ -static int tty_rbr; /* TTY receiver buffer ready */ +static bool tty_trdy; /* TTY transmit ready */ +static bool tty_rbr; /* TTY receiver buffer ready */ -int crt_upper_case; -int crt_strip_parity; -int crt_drop_nulls; +bool crt_upper_case; +bool crt_strip_parity; +bool crt_drop_nulls; int crt_clock_div = 1; /* 38400 baud */ -static int crt_init; /* CRT initialized flag */ +static bool crt_init; /* CRT initialized flag */ static BYTE crt_cmd; /* CRT command byte */ -static int crt_trdy; /* CRT transmit ready */ -static int crt_rbr; /* CRT receiver buffer ready */ +static bool crt_trdy; /* CRT transmit ready */ +static bool crt_rbr; /* CRT receiver buffer ready */ int pt_clock_div = 16; /* 2400 baud */ -static int ptp_rdy; /* PTP ready */ -static int ptr_rdy; /* PTR ready */ +static bool ptp_rdy; /* PTP ready */ +static bool ptr_rdy; /* PTR ready */ int lpt_clock_div = 1; /* 38400 baud */ -static int lpt_rdy; /* LPT ready */ +static bool lpt_rdy; /* LPT ready */ /* * PROM programmer interface data input @@ -211,13 +211,13 @@ void mon_tty_periodic(void) close(ncons[0].ssc); ncons[0].ssc = 0; } else if (p[0].revents & POLLIN) { - tty_rbr = 1; + tty_rbr = true; iset |= ITTYI; } } /* if socket is connected and transceiver is enabled output is ready */ if (ncons[0].ssc != 0 && (tty_cmd & TXEN) && !tty_trdy) { - tty_trdy = 1; + tty_trdy = true; iset |= ITTYO; } if (iset) @@ -266,7 +266,7 @@ BYTE mon_tty_data_in(void) last = data; done: - tty_rbr = 0; + tty_rbr = false; mon_int_update(ITTYI, 0); return data; @@ -317,7 +317,7 @@ void mon_tty_data_out(BYTE data) } done: - tty_trdy = 0; + tty_trdy = false; mon_int_update(ITTYO, 0); } @@ -330,20 +330,21 @@ void mon_tty_ctl_out(BYTE data) if (!tty_init) { /* ignore baud rate, character length, parity and stop bits */ - tty_init = 1; + tty_init = true; return; } - if (data & USRST) - tty_init = tty_cmd = 0; - else + if (data & USRST) { + tty_init = false; + tty_cmd = 0; + } else tty_cmd = data & (RTS | CLERR | RXEN | DTR | TXEN); iclr = 0; if (!(tty_cmd & RXEN) && tty_rbr) { - tty_rbr = 0; + tty_rbr = false; iclr |= ITTYI; } if (!(tty_cmd & TXEN) && tty_trdy) { - tty_trdy = 0; + tty_trdy = false; iclr |= ITTYO; } if (iclr) @@ -365,7 +366,7 @@ void mon_crt_periodic(void) p[0].revents = 0; poll(p, 1, 0); if (p[0].revents & POLLIN) { - crt_rbr = 1; + crt_rbr = true; iset |= ICRTI; } if (p[0].revents & POLLNVAL) { @@ -376,7 +377,7 @@ void mon_crt_periodic(void) } } if ((tty_cmd & TXEN) && !crt_trdy) { - crt_trdy = 1; + crt_trdy = true; iset |= ICRTO; } if (iset) @@ -408,7 +409,7 @@ BYTE mon_crt_data_in(void) data = toupper(data); last = data; - crt_rbr = 0; + crt_rbr = false; mon_int_update(ICRTI, 0); return data; @@ -455,7 +456,7 @@ void mon_crt_data_out(BYTE data) } done: - crt_trdy = 0; + crt_trdy = false; mon_int_update(ICRTO, 0); } @@ -468,20 +469,21 @@ void mon_crt_ctl_out(BYTE data) if (!crt_init) { /* ignore baud rate, character length, parity and stop bits */ - crt_init = 1; + crt_init = true; return; } - if (data & USRST) - crt_init = crt_cmd = 0; - else + if (data & USRST) { + crt_init = false; + crt_cmd = 0; + } else crt_cmd = data & (RTS | CLERR | RXEN | DTR | TXEN); iclr = 0; if (!(crt_cmd & RXEN) && crt_rbr) { - crt_rbr = 0; + crt_rbr = false; iclr |= ICRTI; } if (!(crt_cmd & TXEN) && crt_trdy) { - crt_trdy = 0; + crt_trdy = false; iclr |= ICRTO; } if (iclr) @@ -504,20 +506,20 @@ void mon_pt_periodic(void) p[0].revents = 0; poll(p, 1, 0); if ((p[0].revents & POLLIN) && !ptr_rdy) { - ptr_rdy = 1; + ptr_rdy = true; iset |= IPTR; } if ((p[0].revents & POLLOUT) && !ptp_rdy) { - ptp_rdy = 1; + ptp_rdy = true; iset |= IPTP; } } else { if (ptr_rdy) { - ptr_rdy = 0; + ptr_rdy = false; iclr |= IPTR; } if (ptp_rdy) { - ptp_rdy = 0; + ptp_rdy = false; iclr |= IPTP; } } @@ -554,7 +556,7 @@ BYTE mon_ptr_data_in(void) last = data; done: - ptr_rdy = 0; + ptr_rdy = false; mon_int_update(IPTR, 0); return data; @@ -616,7 +618,7 @@ void mon_ptp_data_out(BYTE data) } done: - ptp_rdy = 0; + ptp_rdy = false; mon_int_update(IPTP, 0); } @@ -634,7 +636,7 @@ void mon_pt_ctl_out(BYTE data) void mon_lpt_periodic(void) { if (!lpt_rdy) { - lpt_rdy = 1; + lpt_rdy = true; mon_int_update(0, ILPT); } } @@ -682,7 +684,7 @@ void mon_lpt_data_out(BYTE data) } done: - lpt_rdy = 0; + lpt_rdy = false; mon_int_update(ILPT, 0); } @@ -699,12 +701,14 @@ void mon_lpt_ctl_out(BYTE data) */ void mon_reset(void) { - tty_init = tty_cmd = 0; - tty_trdy = tty_rbr = 0; - crt_init = crt_cmd = 0; - crt_trdy = crt_rbr = 0; - ptp_rdy = ptr_rdy = 0; - lpt_rdy = 0; + tty_init = false; + tty_cmd = 0; + tty_trdy = tty_rbr = false; + crt_init = false; + crt_cmd = 0; + crt_trdy = crt_rbr = false; + ptp_rdy = ptr_rdy = false; + lpt_rdy = false; pthread_mutex_lock(&mon_int_mutex); mon_int = 0; pthread_mutex_unlock(&mon_int_mutex); diff --git a/iodevices/mds-monitor.h b/iodevices/mds-monitor.h index 134d7126..1b02e224 100644 --- a/iodevices/mds-monitor.h +++ b/iodevices/mds-monitor.h @@ -20,14 +20,14 @@ #include "sim.h" #include "simdefs.h" -extern int tty_upper_case; /* TTY translate input to upper case */ -extern int tty_strip_parity; /* TTY strip parity from output */ -extern int tty_drop_nulls; /* TTY drop nulls after CR/LF */ +extern bool tty_upper_case; /* TTY translate input to upper case */ +extern bool tty_strip_parity; /* TTY strip parity from output */ +extern bool tty_drop_nulls; /* TTY drop nulls after CR/LF */ extern int tty_clock_div; /* TTY clock divisor */ -extern int crt_upper_case; /* CRT translate input to upper case */ -extern int crt_strip_parity; /* CRT strip parity from output */ -extern int crt_drop_nulls; /* CRT drop nulls after CR/LF */ +extern bool crt_upper_case; /* CRT translate input to upper case */ +extern bool crt_strip_parity; /* CRT strip parity from output */ +extern bool crt_drop_nulls; /* CRT drop nulls after CR/LF */ extern int crt_clock_div; /* CRT clock divisor */ extern int pt_clock_div; /* PTR/PTP clock divisor */ From e2e10dda135f41d1fc357079edf57ba6355906d3 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 05:44:40 +0100 Subject: [PATCH 07/19] boolify altair-88-sio and altair-88-2sio --- altairsim/srcsim/simcfg.c | 40 +++++++++++++++++++------------------- iodevices/altair-88-2sio.c | 12 ++++++------ iodevices/altair-88-2sio.h | 12 ++++++------ iodevices/altair-88-sio.c | 6 +++--- iodevices/altair-88-sio.h | 6 +++--- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/altairsim/srcsim/simcfg.c b/altairsim/srcsim/simcfg.c index a5af1b86..e6078b22 100644 --- a/altairsim/srcsim/simcfg.c +++ b/altairsim/srcsim/simcfg.c @@ -89,10 +89,10 @@ void config(void) if (!strcmp(t1, "sio0_upper_case")) { switch (*t2) { case '0': - sio0_upper_case = 0; + sio0_upper_case = false; break; case '1': - sio0_upper_case = 1; + sio0_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -101,10 +101,10 @@ void config(void) } else if (!strcmp(t1, "sio1_upper_case")) { switch (*t2) { case '0': - sio1_upper_case = 0; + sio1_upper_case = false; break; case '1': - sio1_upper_case = 1; + sio1_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -113,10 +113,10 @@ void config(void) } else if (!strcmp(t1, "sio2_upper_case")) { switch (*t2) { case '0': - sio2_upper_case = 0; + sio2_upper_case = false; break; case '1': - sio2_upper_case = 1; + sio2_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -125,10 +125,10 @@ void config(void) } else if (!strcmp(t1, "sio0_strip_parity")) { switch (*t2) { case '0': - sio0_strip_parity = 0; + sio0_strip_parity = false; break; case '1': - sio0_strip_parity = 1; + sio0_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -137,10 +137,10 @@ void config(void) } else if (!strcmp(t1, "sio1_strip_parity")) { switch (*t2) { case '0': - sio1_strip_parity = 0; + sio1_strip_parity = false; break; case '1': - sio1_strip_parity = 1; + sio1_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -149,10 +149,10 @@ void config(void) } else if (!strcmp(t1, "sio2_strip_parity")) { switch (*t2) { case '0': - sio2_strip_parity = 0; + sio2_strip_parity = false; break; case '1': - sio2_strip_parity = 1; + sio2_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -161,10 +161,10 @@ void config(void) } else if (!strcmp(t1, "sio0_drop_nulls")) { switch (*t2) { case '0': - sio0_drop_nulls = 0; + sio0_drop_nulls = false; break; case '1': - sio0_drop_nulls = 1; + sio0_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -173,10 +173,10 @@ void config(void) } else if (!strcmp(t1, "sio1_drop_nulls")) { switch (*t2) { case '0': - sio1_drop_nulls = 0; + sio1_drop_nulls = false; break; case '1': - sio1_drop_nulls = 1; + sio1_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -185,10 +185,10 @@ void config(void) } else if (!strcmp(t1, "sio2_drop_nulls")) { switch (*t2) { case '0': - sio2_drop_nulls = 0; + sio2_drop_nulls = false; break; case '1': - sio2_drop_nulls = 1; + sio2_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -197,10 +197,10 @@ void config(void) } else if (!strcmp(t1, "sio0_revision")) { switch (*t2) { case '0': - sio0_revision = 0; + sio0_revision = false; break; case '1': - sio0_revision = 1; + sio0_revision = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); diff --git a/iodevices/altair-88-2sio.c b/iodevices/altair-88-2sio.c index d6f3fdcf..6dcef272 100644 --- a/iodevices/altair-88-2sio.c +++ b/iodevices/altair-88-2sio.c @@ -49,17 +49,17 @@ static const char *TAG = "2SIO"; #define BAUDTIME 10000000 -int sio1_upper_case; -int sio1_strip_parity; -int sio1_drop_nulls; +bool sio1_upper_case; +bool sio1_strip_parity; +bool sio1_drop_nulls; int sio1_baud_rate = 115200; static uint64_t sio1_t1, sio1_t2; static BYTE sio1_stat; -int sio2_upper_case; -int sio2_strip_parity; -int sio2_drop_nulls; +bool sio2_upper_case; +bool sio2_strip_parity; +bool sio2_drop_nulls; int sio2_baud_rate = 115200; static uint64_t sio2_t1, sio2_t2; diff --git a/iodevices/altair-88-2sio.h b/iodevices/altair-88-2sio.h index 9b1dbb0d..d9b656c5 100644 --- a/iodevices/altair-88-2sio.h +++ b/iodevices/altair-88-2sio.h @@ -31,14 +31,14 @@ #include "sim.h" #include "simdefs.h" -extern int sio1_upper_case; /* SIO 1 translate input to upper case */ -extern int sio1_strip_parity; /* SIO 1 strip parity from output */ -extern int sio1_drop_nulls; /* SIO 1 drop nulls after CR/LF */ +extern bool sio1_upper_case; /* SIO 1 translate input to upper case */ +extern bool sio1_strip_parity; /* SIO 1 strip parity from output */ +extern bool sio1_drop_nulls; /* SIO 1 drop nulls after CR/LF */ extern int sio1_baud_rate; /* SIO 1 baud rate */ -extern int sio2_upper_case; /* SIO 2 translate input to upper case */ -extern int sio2_strip_parity; /* SIO 2 strip parity from output */ -extern int sio2_drop_nulls; /* SIO 2 drop nulls after CR/LF */ +extern bool sio2_upper_case; /* SIO 2 translate input to upper case */ +extern bool sio2_strip_parity; /* SIO 2 strip parity from output */ +extern bool sio2_drop_nulls; /* SIO 2 drop nulls after CR/LF */ extern int sio2_baud_rate; /* SIO 2 baud rate */ extern BYTE altair_sio1_status_in(void); diff --git a/iodevices/altair-88-sio.c b/iodevices/altair-88-sio.c index cfdb6239..2f8f1a51 100644 --- a/iodevices/altair-88-sio.c +++ b/iodevices/altair-88-sio.c @@ -46,9 +46,9 @@ static const char *TAG = "SIO"; #define BAUDTIME 10000000 -int sio0_upper_case; -int sio0_strip_parity; -int sio0_drop_nulls; +bool sio0_upper_case; +bool sio0_strip_parity; +bool sio0_drop_nulls; int sio0_revision; int sio0_baud_rate = 115200; diff --git a/iodevices/altair-88-sio.h b/iodevices/altair-88-sio.h index d9755204..001fd660 100644 --- a/iodevices/altair-88-sio.h +++ b/iodevices/altair-88-sio.h @@ -28,9 +28,9 @@ #include "sim.h" #include "simdefs.h" -extern int sio0_upper_case; /* SIO 0 translate input to upper case */ -extern int sio0_strip_parity; /* SIO 0 strip parity from output */ -extern int sio0_drop_nulls; /* SIO 0 drop nulls after CR/LF */ +extern bool sio0_upper_case; /* SIO 0 translate input to upper case */ +extern bool sio0_strip_parity; /* SIO 0 strip parity from output */ +extern bool sio0_drop_nulls; /* SIO 0 drop nulls after CR/LF */ extern int sio0_revision; /* SIO 0 Rev 0 or Rev 1 */ extern int sio0_baud_rate; /* SIO 0 baud rate */ From ea84d8658af9c4a4d4fb962a25ee4ccdfa217dff Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 06:03:15 +0100 Subject: [PATCH 08/19] boolify simice --- picosim/srcsim/picosim.c | 4 ++-- z80core/sim8080.c | 6 +++--- z80core/simice.c | 46 ++++++++++++++++++++-------------------- z80core/simice.h | 8 ++++--- z80core/simz80.c | 6 +++--- 5 files changed, 36 insertions(+), 34 deletions(-) diff --git a/picosim/srcsim/picosim.c b/picosim/srcsim/picosim.c index be67962c..38e71782 100644 --- a/picosim/srcsim/picosim.c +++ b/picosim/srcsim/picosim.c @@ -293,7 +293,7 @@ static void picosim_ice_cmd(char *cmd, WORD *wrk_addr) WORD save_PC; Tstates_t T0; #ifdef WANT_HB - int save_hb_flag; + bool save_hb_flag; #endif switch (tolower((unsigned char) *cmd)) { @@ -313,7 +313,7 @@ static void picosim_ice_cmd(char *cmd, WORD *wrk_addr) #ifdef WANT_HB save_hb_flag = hb_flag; - hb_flag = 0; + hb_flag = false; #endif save[0] = getmem(0x0000); /* save memory locations */ save[1] = getmem(0x0001); /* 0000H - 0002H */ diff --git a/z80core/sim8080.c b/z80core/sim8080.c index d584aca6..6509507e 100644 --- a/z80core/sim8080.c +++ b/z80core/sim8080.c @@ -430,7 +430,7 @@ void cpu_8080(void) his[h_next].h_sp = SP; h_next++; if (h_next == HISIZE) { - h_flag = 1; + h_flag = true; h_next = 0; } #endif @@ -438,7 +438,7 @@ void cpu_8080(void) #ifdef WANT_TIM /* check for start address of runtime measurement */ if (PC == t_start && !t_flag) { - t_flag = 1; /* turn measurement on */ + t_flag = true; /* turn measurement on */ t_states_s = t_states_e = T; /* initialize markers */ } #endif @@ -615,7 +615,7 @@ void cpu_8080(void) if (t_flag) { t_states_e = T; /* set end marker for this opcode */ if (PC == t_end) /* check for end address */ - t_flag = 0; /* if reached, switch off */ + t_flag = false; /* if reached, switch off */ } #endif diff --git a/z80core/simice.c b/z80core/simice.c index 0ae47634..4ecbec2b 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -40,7 +40,7 @@ #ifdef HISIZE history_t his[HISIZE]; /* memory to hold trace information */ int h_next; /* index into trace memory */ -int h_flag; /* flag for trace memory overrun */ +bool h_flag; /* flag for trace memory overrun */ #endif /* @@ -56,7 +56,7 @@ softbreak_t soft[SBSIZE]; /* memory to hold breakpoint information */ #ifdef WANT_TIM Tstates_t t_states_s; /* T states marker at start of measurement */ Tstates_t t_states_e; /* T states marker at end of measurement */ -int t_flag; /* flag, 1 = on, 0 = off */ +bool t_flag; /* flag, true = on, false = off */ WORD t_start = 65535; /* start address for measurement */ WORD t_end = 65535; /* end address for measurement */ #endif @@ -65,7 +65,7 @@ WORD t_end = 65535; /* end address for measurement */ * Variables for hardware breakpoint */ #ifdef WANT_HB -int hb_flag; /* hardware breakpoint enabled flag */ +bool hb_flag; /* hardware breakpoint enabled flag */ WORD hb_addr; /* address of hardware breakpoint */ int hb_mode; /* access mode of hardware breakpoint */ int hb_trig; /* hardware breakpoint triggered flag */ @@ -76,7 +76,7 @@ static void do_trace(char *s); static void do_go(char *s); static void install_softbp(void); static void uninstall_softbp(void); -static int handle_break(void); +static bool handle_break(void); static void do_dump(char *s); static void do_list(char *s); static void do_modify(char *s); @@ -132,7 +132,7 @@ void (*ice_cust_help)(void); */ void ice_cmd_loop(int go_mode) { - register int eoj = 1; + register bool eoj = true; static char cmd[LENCMD]; if (!go_mode) { @@ -151,7 +151,7 @@ void ice_cmd_loop(int go_mode) printf(">>> "); fflush(stdout); if (get_cmdline(cmd, LENCMD)) { - eoj = 0; + eoj = false; continue; } } @@ -225,7 +225,7 @@ void ice_cmd_loop(int go_mode) break; #endif case 'q': - eoj = 0; + eoj = false; break; default: if (ice_cust_cmd) @@ -356,10 +356,10 @@ static void uninstall_softbp(void) /* * Handling of software (HALT opcode) / hardware breakpoints: * - * Output: 0 breakpoint or other HALT opcode reached (stop) - * 1 breakpoint hit, pass counter not reached (continue) + * Output: false breakpoint or other HALT opcode reached (stop) + * true breakpoint hit, pass counter not reached (continue) */ -static int handle_break(void) +static bool handle_break(void) { #ifdef SBSIZE register int i; @@ -377,7 +377,7 @@ static int handle_break(void) printf(" access to %04x\n", hb_addr); hb_trig = 0; cpu_error = NONE; - return 0; + return false; } #endif #ifdef SBSIZE @@ -385,7 +385,7 @@ static int handle_break(void) if (soft[i].sb_pass && soft[i].sb_addr == PC - 1) break; if (i == SBSIZE) /* no breakpoint found */ - return 0; + return false; #ifdef HISIZE if (h_next) /* correct history */ h_next--; @@ -398,12 +398,12 @@ static int handle_break(void) putmem(soft[i].sb_addr, 0x76); /* restore HALT opcode again */ soft[i].sb_passcount++; /* increment pass counter */ if (soft[i].sb_passcount != soft[i].sb_pass) - return 1; /* pass not reached, continue */ + return true; /* pass not reached, continue */ printf("Software breakpoint hit at %04x\n", soft[i].sb_addr); soft[i].sb_passcount = 0; /* reset pass counter */ - return 0; /* pass reached, stop */ + return false; /* pass reached, stop */ #else /* !SBSIZE */ - return 0; + return false; #endif /* !SBSIZE */ } @@ -908,7 +908,7 @@ static void do_break(char *s) return; } if (tolower((unsigned char) *s) == 'c') { - hb_flag = 0; + hb_flag = false; return; } while (isspace((unsigned char) *s)) @@ -949,7 +949,7 @@ static void do_break(char *s) #endif hb_addr = a; hb_mode = n; - hb_flag = 1; + hb_flag = true; #endif /* WANT_HB */ return; } @@ -1065,15 +1065,15 @@ static void do_hist(char *s) if (tolower((unsigned char) *s) == 'c') { memset((char *) his, 0, sizeof(history_t) * HISIZE); h_next = 0; - h_flag = 0; + h_flag = false; return; } - if (h_next == 0 && h_flag == 0) { + if (h_next == 0 && !h_flag) { puts("History memory is empty"); return; } e = h_next; - b = (h_flag) ? h_next + 1 : 0; + b = h_flag ? h_next + 1 : 0; l = 0; while (isspace((unsigned char) *s)) s++; @@ -1163,7 +1163,7 @@ static void do_count(char *s) t_start = start; t_end = strtol(s, NULL, 16); t_states_s = t_states_e = T; - t_flag = 0; + t_flag = false; #endif } @@ -1345,10 +1345,10 @@ static void do_clock(void) static struct itimerval tim; const char *s = NULL; #ifdef WANT_HB - int save_hb_flag; + bool save_hb_flag; save_hb_flag = hb_flag; - hb_flag = 0; + hb_flag = false; #endif save[0] = getmem(0x0000); /* save memory locations */ save[1] = getmem(0x0001); /* 0000H - 0002H */ diff --git a/z80core/simice.h b/z80core/simice.h index 220f7314..77231ef4 100644 --- a/z80core/simice.h +++ b/z80core/simice.h @@ -29,7 +29,8 @@ typedef struct history { /* structure of a history entry */ } history_t; extern history_t his[HISIZE]; -extern int h_next, h_flag; +extern int h_next; +extern bool h_flag; #endif #ifdef SBSIZE @@ -45,7 +46,7 @@ extern softbreak_t soft[SBSIZE]; #ifdef WANT_TIM extern Tstates_t t_states_s, t_states_e; -extern int t_flag; +extern bool t_flag; extern WORD t_start, t_end; #endif @@ -55,7 +56,8 @@ extern WORD t_start, t_end; #define HB_WRITE 2 /* write memory */ #define HB_EXEC 4 /* execute (op-code fetch) */ -extern int hb_flag, hb_mode, hb_trig; +extern bool hb_flag; +extern int hb_mode, hb_trig; extern WORD hb_addr; #endif diff --git a/z80core/simz80.c b/z80core/simz80.c index 7c7276f1..1efc8a31 100644 --- a/z80core/simz80.c +++ b/z80core/simz80.c @@ -413,7 +413,7 @@ void cpu_z80(void) his[h_next].h_sp = SP; h_next++; if (h_next == HISIZE) { - h_flag = 1; + h_flag = true; h_next = 0; } #endif @@ -421,7 +421,7 @@ void cpu_z80(void) #ifdef WANT_TIM /* check for start address of runtime measurement */ if (PC == t_start && !t_flag) { - t_flag = 1; /* turn measurement on */ + t_flag = true; /* turn measurement on */ t_states_s = t_states_e = T; /* initialize markers */ } #endif @@ -627,7 +627,7 @@ void cpu_z80(void) if (t_flag) { t_states_e = T; /* set end marker for this opcode */ if (PC == t_end) /* check for end address */ - t_flag = 0; /* if reached, switch off */ + t_flag = false; /* if reached, switch off */ } #endif From 407838dc4ee4208273131d60398132f513915dcf Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 06:20:43 +0100 Subject: [PATCH 09/19] boolify imsai-sio2 --- imsaisim/srcsim/simcfg.c | 48 ++++++++++++++++++++-------------------- iodevices/imsai-sio2.c | 24 ++++++++++---------- iodevices/imsai-sio2.h | 24 ++++++++++---------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/imsaisim/srcsim/simcfg.c b/imsaisim/srcsim/simcfg.c index c47afe2d..a7d27e50 100644 --- a/imsaisim/srcsim/simcfg.c +++ b/imsaisim/srcsim/simcfg.c @@ -94,10 +94,10 @@ void config(void) if (!strcmp(t1, "sio1a_upper_case")) { switch (*t2) { case '0': - sio1a_upper_case = 0; + sio1a_upper_case = false; break; case '1': - sio1a_upper_case = 1; + sio1a_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -106,10 +106,10 @@ void config(void) } else if (!strcmp(t1, "sio1b_upper_case")) { switch (*t2) { case '0': - sio1b_upper_case = 0; + sio1b_upper_case = false; break; case '1': - sio1b_upper_case = 1; + sio1b_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -118,10 +118,10 @@ void config(void) } else if (!strcmp(t1, "sio2a_upper_case")) { switch (*t2) { case '0': - sio2a_upper_case = 0; + sio2a_upper_case = false; break; case '1': - sio2a_upper_case = 1; + sio2a_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -130,10 +130,10 @@ void config(void) } else if (!strcmp(t1, "sio2b_upper_case")) { switch (*t2) { case '0': - sio2b_upper_case = 0; + sio2b_upper_case = false; break; case '1': - sio2b_upper_case = 1; + sio2b_upper_case = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -142,10 +142,10 @@ void config(void) } else if (!strcmp(t1, "sio1a_strip_parity")) { switch (*t2) { case '0': - sio1a_strip_parity = 0; + sio1a_strip_parity = false; break; case '1': - sio1a_strip_parity = 1; + sio1a_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -154,10 +154,10 @@ void config(void) } else if (!strcmp(t1, "sio1b_strip_parity")) { switch (*t2) { case '0': - sio1b_strip_parity = 0; + sio1b_strip_parity = false; break; case '1': - sio1b_strip_parity = 1; + sio1b_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -166,10 +166,10 @@ void config(void) } else if (!strcmp(t1, "sio2a_strip_parity")) { switch (*t2) { case '0': - sio2a_strip_parity = 0; + sio2a_strip_parity = false; break; case '1': - sio2a_strip_parity = 1; + sio2a_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -178,10 +178,10 @@ void config(void) } else if (!strcmp(t1, "sio2b_strip_parity")) { switch (*t2) { case '0': - sio2b_strip_parity = 0; + sio2b_strip_parity = false; break; case '1': - sio2b_strip_parity = 1; + sio2b_strip_parity = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -190,10 +190,10 @@ void config(void) } else if (!strcmp(t1, "sio1a_drop_nulls")) { switch (*t2) { case '0': - sio1a_drop_nulls = 0; + sio1a_drop_nulls = false; break; case '1': - sio1a_drop_nulls = 1; + sio1a_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -202,10 +202,10 @@ void config(void) } else if (!strcmp(t1, "sio1b_drop_nulls")) { switch (*t2) { case '0': - sio1b_drop_nulls = 0; + sio1b_drop_nulls = false; break; case '1': - sio1b_drop_nulls = 1; + sio1b_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -214,10 +214,10 @@ void config(void) } else if (!strcmp(t1, "sio2a_drop_nulls")) { switch (*t2) { case '0': - sio2a_drop_nulls = 0; + sio2a_drop_nulls = false; break; case '1': - sio2a_drop_nulls = 1; + sio2a_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); @@ -226,10 +226,10 @@ void config(void) } else if (!strcmp(t1, "sio2b_drop_nulls")) { switch (*t2) { case '0': - sio2b_drop_nulls = 0; + sio2b_drop_nulls = false; break; case '1': - sio2b_drop_nulls = 1; + sio2b_drop_nulls = true; break; default: LOGW(TAG, "invalid value for %s: %s", t1, t2); diff --git a/iodevices/imsai-sio2.c b/iodevices/imsai-sio2.c index 475eab07..a411a79a 100644 --- a/iodevices/imsai-sio2.c +++ b/iodevices/imsai-sio2.c @@ -55,33 +55,33 @@ static const char *TAG = "SIO"; static BYTE sio1_ctl, sio2_ctl; -int sio1a_upper_case; -int sio1a_strip_parity; -int sio1a_drop_nulls; +bool sio1a_upper_case; +bool sio1a_strip_parity; +bool sio1a_drop_nulls; int sio1a_baud_rate = 115200; static uint64_t sio1a_t1, sio1a_t2; static BYTE sio1a_stat = 0; -int sio1b_upper_case; -int sio1b_strip_parity; -int sio1b_drop_nulls; +bool sio1b_upper_case; +bool sio1b_strip_parity; +bool sio1b_drop_nulls; int sio1b_baud_rate = 110; static uint64_t sio1b_t1, sio1b_t2; static BYTE sio1b_stat = 0; -int sio2a_upper_case; -int sio2a_strip_parity; -int sio2a_drop_nulls; +bool sio2a_upper_case; +bool sio2a_strip_parity; +bool sio2a_drop_nulls; int sio2a_baud_rate = 115200; static uint64_t sio2a_t1, sio2a_t2; static BYTE sio2a_stat = 0; -int sio2b_upper_case; -int sio2b_strip_parity; -int sio2b_drop_nulls; +bool sio2b_upper_case; +bool sio2b_strip_parity; +bool sio2b_drop_nulls; int sio2b_baud_rate = 2400; static uint64_t sio2b_t1, sio2b_t2; diff --git a/iodevices/imsai-sio2.h b/iodevices/imsai-sio2.h index a23bfc8a..881b38ff 100644 --- a/iodevices/imsai-sio2.h +++ b/iodevices/imsai-sio2.h @@ -40,24 +40,24 @@ #include "sim.h" #include "simdefs.h" -extern int sio1a_upper_case; /* SIO 1 A translate input to upper case */ -extern int sio1a_strip_parity; /* SIO 1 A strip parity from output */ -extern int sio1a_drop_nulls; /* SIO 1 A drop nulls after CR/LF */ +extern bool sio1a_upper_case; /* SIO 1 A translate input to upper case */ +extern bool sio1a_strip_parity; /* SIO 1 A strip parity from output */ +extern bool sio1a_drop_nulls; /* SIO 1 A drop nulls after CR/LF */ extern int sio1a_baud_rate; /* SIO 1 A simulated baud rate */ -extern int sio1b_upper_case; /* SIO 1 B translate input to upper case */ -extern int sio1b_strip_parity; /* SIO 1 B strip parity from output */ -extern int sio1b_drop_nulls; /* SIO 1 B drop nulls after CR/LF */ +extern bool sio1b_upper_case; /* SIO 1 B translate input to upper case */ +extern bool sio1b_strip_parity; /* SIO 1 B strip parity from output */ +extern bool sio1b_drop_nulls; /* SIO 1 B drop nulls after CR/LF */ extern int sio1b_baud_rate; /* SIO 1 B simulated baud rate */ -extern int sio2a_upper_case; /* SIO 2 A translate input to upper case */ -extern int sio2a_strip_parity; /* SIO 2 A strip parity from output */ -extern int sio2a_drop_nulls; /* SIO 2 A drop nulls after CR/LF */ +extern bool sio2a_upper_case; /* SIO 2 A translate input to upper case */ +extern bool sio2a_strip_parity; /* SIO 2 A strip parity from output */ +extern bool sio2a_drop_nulls; /* SIO 2 A drop nulls after CR/LF */ extern int sio2a_baud_rate; /* SIO 2 A simulated baud rate */ -extern int sio2b_upper_case; /* SIO 2 B translate input to upper case */ -extern int sio2b_strip_parity; /* SIO 2 B strip parity from output */ -extern int sio2b_drop_nulls; /* SIO 2 B drop nulls after CR/LF */ +extern bool sio2b_upper_case; /* SIO 2 B translate input to upper case */ +extern bool sio2b_strip_parity; /* SIO 2 B strip parity from output */ +extern bool sio2b_drop_nulls; /* SIO 2 B drop nulls after CR/LF */ extern int sio2b_baud_rate; /* SIO 2 B simulated baud rate */ extern BYTE imsai_sio_nofun_in(void); From a3129990e73c42daa517ad02101a8876f3953199 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 06:58:01 +0100 Subject: [PATCH 10/19] boolify cromemco_[dazzler,fdc,tu-art] and simbdos --- cromemcosim/srcsim/simio.c | 84 ++++++++++++++++++------------------ iodevices/cromemco-dazzler.c | 16 +++---- iodevices/cromemco-fdc.c | 40 ++++++++--------- iodevices/cromemco-fdc.h | 5 ++- iodevices/cromemco-tu-art.c | 78 +++++++++++++++++---------------- iodevices/cromemco-tu-art.h | 20 +++++---- iodevices/simbdos.c | 6 +-- 7 files changed, 129 insertions(+), 120 deletions(-) diff --git a/cromemcosim/srcsim/simio.c b/cromemcosim/srcsim/simio.c index 398bb52c..7271e227 100644 --- a/cromemcosim/srcsim/simio.c +++ b/cromemcosim/srcsim/simio.c @@ -91,7 +91,7 @@ static void hwctl_out(BYTE data); static void *timing(void *arg); static void interrupt(int sig); -static int rtc; /* flag for 512ms RTC interrupt */ +static bool rtc; /* flag for 512ms RTC interrupt */ int lpt1, lpt2; /* fds for lpt printer files */ static BYTE hwctl_lock = 0xff; /* lock status hardware control port */ @@ -99,7 +99,7 @@ static BYTE hwctl_lock = 0xff; /* lock status hardware control port */ /* network connections for serial ports on the TU-ART's */ net_connector_t ncons[NUMNSOC]; -static int th_suspend; /* timing thread suspend flag */ +static bool th_suspend; /* timing thread suspend flag */ /* * This array contains function pointers for every @@ -309,11 +309,11 @@ void exit_io(void) */ void reset_io(void) { - th_suspend = 1; /* suspend timing thread */ - sleep_for_ms(20); /* give it enough time to suspend */ + th_suspend = true; /* suspend timing thread */ + sleep_for_ms(20); /* give it enough time to suspend */ cromemco_tuart_reset(); cromemco_fdc_reset(); - th_suspend = 0; /* resume timing thread */ + th_suspend = false; /* resume timing thread */ selbnk = 0; cromemco_dazzler_off(); wdi_exit(); @@ -424,7 +424,7 @@ static void mmu_out(BYTE data) bankio = data; if (fdc_rom_active) { - fdc_rom_active = 0; + fdc_rom_active = false; reset_fdc_rom_map(); } @@ -537,7 +537,7 @@ static void *timing(void *arg) /* UART 0A timer 1 */ if ((uart0a_timer1 == -1) && (uart0a_int_mask & 1)) { uart0a_int = 0xc7; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xc7; int_int = true; uart0a_timer1 = 0; @@ -547,7 +547,7 @@ static void *timing(void *arg) /* UART 0A timer 2 */ if ((uart0a_timer2 == -1) && (uart0a_int_mask & 2)) { uart0a_int = 0xcf; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xcf; int_int = true; uart0a_timer2 = 0; @@ -557,7 +557,7 @@ static void *timing(void *arg) /* EOJ from disk */ if ((fdc_flags & 1) && (uart0a_int_mask & 4)) { uart0a_int = 0xd7; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xd7; int_int = true; goto next; @@ -566,7 +566,7 @@ static void *timing(void *arg) /* UART 0A timer 3 */ if ((uart0a_timer3 == -1) && (uart0a_int_mask & 8)) { uart0a_int = 0xdf; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xdf; int_int = true; uart0a_timer3 = 0; @@ -576,7 +576,7 @@ static void *timing(void *arg) /* UART 0A receive data available */ if ((uart0a_rda) && (uart0a_int_mask & 16)) { uart0a_int = 0xe7; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xe7; int_int = true; goto next; @@ -589,7 +589,7 @@ static void *timing(void *arg) uart0a_tbe = 1; if (uart0a_int_mask & 32) { uart0a_int = 0xef; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xef; int_int = true; goto next; @@ -599,7 +599,7 @@ static void *timing(void *arg) /* UART 0A timer 4 */ if ((uart0a_timer4 == -1) && (uart0a_int_mask & 64)) { uart0a_int = 0xf7; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xf7; int_int = true; uart0a_timer4 = 0; @@ -609,7 +609,7 @@ static void *timing(void *arg) /* UART 0A timer 5 */ if ((uart0a_timer5 == -1) && (uart0a_int_mask & 128) && !uart0a_rst7) { uart0a_int = 0xff; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xff; int_int = true; uart0a_timer5 = 0; @@ -618,10 +618,10 @@ static void *timing(void *arg) /* 512ms RTC */ if (rtc && uart0a_rst7) { - rtc = 0; + rtc = false; if (uart0a_int_mask & 128) { uart0a_int = 0xff; - uart0a_int_pending = 1; + uart0a_int_pending = true; int_data = 0xff; int_int = true; goto next; @@ -630,15 +630,15 @@ static void *timing(void *arg) /* UART 0A no pending interrupt */ uart0a_int = 0xff; - uart0a_int_pending = 0; + uart0a_int_pending = false; /* UART 1A parallel port sense */ - uart1a_lpt_busy = 0; - if (uart1a_sense != 0) { - uart1a_int_pending = 1; + uart1a_lpt_busy = false; + if (uart1a_sense) { + uart1a_int_pending = true; uart1a_int = 0xd7; if (uart1a_int_mask & 4) { - uart1a_sense = 0; + uart1a_sense = false; int_data = 0x24; int_int = true; goto next; @@ -648,18 +648,18 @@ static void *timing(void *arg) /* UART 1A receive data available */ if ((uart1a_rda) && (uart1a_int_mask & 16)) { uart1a_int = 0xe7; - uart1a_int_pending = 1; + uart1a_int_pending = true; int_data = 0x28; int_int = true; goto next; } /* UART 1A transmit buffer empty */ - if (uart1a_tbe == 0) { - uart1a_tbe = 1; + if (!uart1a_tbe) { + uart1a_tbe = true; if (uart1a_int_mask & 32) { uart1a_int = 0xef; - uart1a_int_pending = 1; + uart1a_int_pending = true; int_data = 0x2a; int_int = true; goto next; @@ -667,16 +667,16 @@ static void *timing(void *arg) } /* UART 1A no pending interrupt */ - uart1a_int_pending = 0; + uart1a_int_pending = false; uart1a_int = 0xff; /* UART 1B parallel port sense */ - uart1b_lpt_busy = 0; - if (uart1b_sense != 0) { - uart1b_int_pending = 1; + uart1b_lpt_busy = false; + if (uart1b_sense) { + uart1b_int_pending = true; uart1b_int = 0xd7; if (uart1b_int_mask & 4) { - uart1b_sense = 0; + uart1b_sense = false; int_data = 0x34; int_int = true; goto next; @@ -686,18 +686,18 @@ static void *timing(void *arg) /* UART 1B receive data available */ if ((uart1b_rda) && (uart1b_int_mask & 16)) { uart1b_int = 0xe7; - uart1b_int_pending = 1; + uart1b_int_pending = true; int_data = 0x38; int_int = true; goto next; } /* UART 1B transmit buffer empty */ - if (uart1b_tbe == 0) { - uart1b_tbe = 1; + if (!uart1b_tbe) { + uart1b_tbe = true; if (uart1b_int_mask & 32) { uart1b_int = 0xef; - uart1b_int_pending = 1; + uart1b_int_pending = true; int_data = 0x3a; int_int = true; goto next; @@ -705,7 +705,7 @@ static void *timing(void *arg) } /* UART 1B no pending interrupt */ - uart1b_int_pending = 0; + uart1b_int_pending = false; uart1b_int = 0xff; next: @@ -751,7 +751,7 @@ static void interrupt(int sig) /* set RTC interrupt flag every 510ms */ if ((counter % 51) == 0) - rtc = 1; + rtc = true; #ifndef TCPASYNC /* poll TCP sockets if SIGIO not working */ @@ -762,27 +762,27 @@ static void interrupt(int sig) hal_status_in(TUART0A, &status); if (status & 2) { - uart0a_rda = 1; + uart0a_rda = true; } else { - uart0a_rda = 0; + uart0a_rda = false; } status = 0; hal_status_in(TUART1A, &status); if (status & 2) { - uart1a_rda = 1; + uart1a_rda = true; } else { - uart1a_rda = 0; + uart1a_rda = false; } status = 0; hal_status_in(TUART1B, &status); if (status & 2) { - uart1b_rda = 1; + uart1b_rda = true; } else { - uart1b_rda = 0; + uart1b_rda = false; } } diff --git a/iodevices/cromemco-dazzler.c b/iodevices/cromemco-dazzler.c index cd4da974..37b99070 100644 --- a/iodevices/cromemco-dazzler.c +++ b/iodevices/cromemco-dazzler.c @@ -151,7 +151,7 @@ static char gray15[] = "#FFFFFF"; #endif /* !WANT_SDL */ /* DAZZLER stuff */ -static int state; +static bool state; static WORD dma_addr; static BYTE flags = 64; static BYTE format; @@ -310,7 +310,7 @@ static void kill_thread(void) /* switch DAZZLER off from front panel */ void cromemco_dazzler_off(void) { - state = 0; + state = false; #ifdef WANT_SDL #ifdef HAS_NETSERVER @@ -714,7 +714,7 @@ static void update_display(bool tick) /* draw one frame dependent on graphics format */ set_fg_color(0); SDL_RenderClear(renderer); - if (state == 1) { /* draw frame if on */ + if (state) { /* draw frame if on */ if (format & 64) draw_hires(); else @@ -751,7 +751,7 @@ static void *update_thread(void *arg) while (1) { /* do forever or until canceled */ /* draw one frame dependent on graphics format */ - if (state == 1) { /* draw frame if on */ + if (state) { /* draw frame if on */ #ifdef HAS_NETSERVER if (!n_flag) { #endif @@ -820,11 +820,11 @@ void cromemco_dazzler_ctl_out(BYTE data) #endif #ifdef HAS_NETSERVER } else { - if (state == 0) + if (!state) ws_clear(); } #endif - state = 1; + state = true; #if defined(WANT_SDL) && defined(HAS_NETSERVER) if (n_flag) { #endif @@ -841,8 +841,8 @@ void cromemco_dazzler_ctl_out(BYTE data) } #endif } else { - if (state == 1) { - state = 0; + if (state) { + state = false; sleep_for_ms(50); #ifdef HAS_NETSERVER if (!n_flag) { diff --git a/iodevices/cromemco-fdc.c b/iodevices/cromemco-fdc.c index 72fed1da..8ba2bbd6 100644 --- a/iodevices/cromemco-fdc.c +++ b/iodevices/cromemco-fdc.c @@ -90,15 +90,15 @@ static int side = 0; /* disk side */ static int secsz = SEC_SZSD; /* current used sector size */ static int state; /* internal fdc state */ static int dcnt; /* data counter read/write */ -static int mflag; /* multiple sectors flag */ +static bool mflag; /* multiple sectors flag */ static char fn[MAX_LFN]; /* path/filename for disk image */ static int fd; /* fd for disk i/o */ static BYTE buf[SEC_SZDD]; /* buffer for one sector */ int index_pulse = 0; /* disk index pulse */ -static int autowait; /* autowait flag */ - int motoron; /* motor on flag */ +static bool autowait; /* autowait flag */ + bool motoron; /* motor on flag */ int motortimer; /* motor on timer */ -static int headloaded; /* head loaded flag */ +static bool headloaded; /* head loaded flag */ /* these are our disk drives, 8" SS SD initially */ Diskdef disks[4] = { @@ -109,7 +109,7 @@ Diskdef disks[4] = { }; BYTE fdc_banked_rom[8 << 10]; /* 8K of ROM (from 64FDC) to support RDOS 3 */ -int fdc_rom_active = 0; +bool fdc_rom_active = false; /* * find and set path for disk images @@ -307,7 +307,7 @@ BYTE cromemco_fdc_diskflags_in(void) fdc_flags &= ~1; /* process autowait timeout */ - if (!(ret & 1) && !(ret & 128) && (autowait == 1)) { + if (!(ret & 1) && !(ret & 128) && autowait) { ret |= 2; } @@ -316,7 +316,7 @@ BYTE cromemco_fdc_diskflags_in(void) if (motortimer > 0) ret |= 8; else { - motoron = 0; + motoron = false; ret |= 4; } } @@ -342,7 +342,7 @@ BYTE cromemco_fdc_diskflags_in(void) void cromemco_fdc_diskctl_out(BYTE data) { /* get autowait */ - autowait = (data & 128) ? 1 : 0; + autowait = (data & 128) ? true : false; /* get selected disk */ if (data & 8) @@ -374,10 +374,10 @@ void cromemco_fdc_diskctl_out(BYTE data) /* motor on/off */ if (data & 32) { - motoron = 1; + motoron = true; motortimer = 800; } else { - motoron = 0; + motoron = false; motortimer = 0; } } @@ -919,7 +919,7 @@ void cromemco_fdc_cmd_out(BYTE data) fdc_flags &= ~1; if ((data & 0xf0) == 0) { /* restore (seek track 0) */ - headloaded = (data & 8) ? 1 : 0; + headloaded = (data & 8) ? true : false; if (fdc_track != 0) step_dir = -1; fdc_track = 0; @@ -929,7 +929,7 @@ void cromemco_fdc_cmd_out(BYTE data) fdc_stat |= 32; } else if ((data & 0xf0) == 0x10) { /* seek */ - headloaded = (data & 8) ? 1 : 0; + headloaded = (data & 8) ? true : false; fdc_flags |= 1; /* set EOJ */ if (fdc_track <= disks[disk].tracks) fdc_stat = (fdc_track == 0) ? 4 : 0; @@ -939,7 +939,7 @@ void cromemco_fdc_cmd_out(BYTE data) fdc_stat |= 32; } else if ((data & 0xe0) == 0x20) { /* step */ - headloaded = (data & 8) ? 1 : 0; + headloaded = (data & 8) ? true : false; fdc_track += step_dir; fdc_flags |= 1; /* set EOJ */ if (fdc_track <= disks[disk].tracks) @@ -950,7 +950,7 @@ void cromemco_fdc_cmd_out(BYTE data) fdc_stat |= 32; } else if ((data & 0xe0) == 0x40) { /* step in */ - headloaded = (data & 8) ? 1 : 0; + headloaded = (data & 8) ? true : false; fdc_track++; fdc_flags |= 1; /* set EOJ */ step_dir = 1; @@ -962,7 +962,7 @@ void cromemco_fdc_cmd_out(BYTE data) fdc_stat |= 32; } else if ((data & 0xe0) == 0x60) { /* step out */ - headloaded = (data & 8) ? 1 : 0; + headloaded = (data & 8) ? true : false; fdc_track--; fdc_flags |= 1; /* set EOJ */ step_dir = -1; @@ -981,7 +981,7 @@ void cromemco_fdc_cmd_out(BYTE data) fdc_flags |= 1; /* set EOJ */ } else if ((data & 0xe0) == 0x80) { /* read sector(s) */ - mflag = (data & 16) ? 1 : 0; + mflag = (data & 16) ? true : false; state = FDC_READ; dcnt = 0; fdc_stat = 3; /* set DRQ & busy */ @@ -1024,18 +1024,18 @@ void cromemco_fdc_cmd_out(BYTE data) void cromemco_fdc_reset(void) { - state = dcnt = mflag = index_pulse = disk = side = 0; - motoron = motortimer = headloaded = autowait = 0; + state = dcnt = index_pulse = disk = side = motortimer = 0; + mflag = motoron = autowait = headloaded = false; fdc_stat = fdc_aux = 0; fdc_flags = AUTOBOOT; secsz = SEC_SZSD; #ifdef HAS_BANKED_ROM if (R_flag) { - fdc_rom_active = 1; + fdc_rom_active = true; reset_fdc_rom_map(); } else { - fdc_rom_active = 0; + fdc_rom_active = false; } #endif diff --git a/iodevices/cromemco-fdc.h b/iodevices/cromemco-fdc.h index e223b603..7953e00b 100644 --- a/iodevices/cromemco-fdc.h +++ b/iodevices/cromemco-fdc.h @@ -69,12 +69,13 @@ typedef struct { extern BYTE fdc_flags; extern enum Disk_type dtype; extern int index_pulse; -extern int motoron, motortimer; +extern bool motoron; +extern int motortimer; extern Diskdef disks[4]; extern BYTE fdc_banked_rom[8 << 10]; /* 8K of ROM (from 64FDC) to support RDOS 3 */ -extern int fdc_rom_active; +extern bool fdc_rom_active; extern char *dsk_path(void); diff --git a/iodevices/cromemco-tu-art.c b/iodevices/cromemco-tu-art.c index c497924e..7eca4aad 100644 --- a/iodevices/cromemco-tu-art.c +++ b/iodevices/cromemco-tu-art.c @@ -62,9 +62,11 @@ void lpt_reset(void) /* Device 0A */ /************************/ -int uart0a_int_mask, uart0a_int, uart0a_int_pending, uart0a_rst7; +int uart0a_int_mask, uart0a_int; +bool uart0a_int_pending, uart0a_rst7; int uart0a_timer1, uart0a_timer2, uart0a_timer3, uart0a_timer4, uart0a_timer5; -int uart0a_tbe, uart0a_rda; +int uart0a_tbe; +bool uart0a_rda; /* * D7 Transmit Buffer Empty @@ -112,7 +114,7 @@ BYTE cromemco_tuart_0a_data_in(void) int data; static BYTE last; - uart0a_rda = 0; + uart0a_rda = false; data = hal_data_in(TUART0A); /* if no new data available return last */ @@ -147,17 +149,17 @@ void cromemco_tuart_0a_data_out(BYTE data) */ void cromemco_tuart_0a_command_out(BYTE data) { - uart0a_rst7 = (data & 4) ? 1 : 0; + uart0a_rst7 = (data & 4) ? true : false; if (data & 1) { - uart0a_rda = 0; + uart0a_rda = false; uart0a_tbe = 1; uart0a_timer1 = 0; uart0a_timer2 = 0; uart0a_timer3 = 0; uart0a_timer4 = 0; uart0a_timer5 = 0; - uart0a_int_pending = 0; + uart0a_int_pending = false; } } @@ -236,9 +238,10 @@ void cromemco_tuart_0a_timer5_out(BYTE data) /* Device 1A */ /************************/ -int uart1a_int_mask, uart1a_int, uart1a_int_pending; -int uart1a_sense, uart1a_lpt_busy; -int uart1a_tbe, uart1a_rda; +int uart1a_int_mask, uart1a_int; +bool uart1a_int_pending; +bool uart1a_sense, uart1a_lpt_busy; +bool uart1a_tbe, uart1a_rda; BYTE cromemco_tuart_1a_status_in(void) { @@ -268,7 +271,7 @@ BYTE cromemco_tuart_1a_data_in(void) int data; static BYTE last; - uart1a_rda = 0; + uart1a_rda = false; data = hal_data_in(TUART1A); /* if no new data available return last */ @@ -282,7 +285,7 @@ BYTE cromemco_tuart_1a_data_in(void) void cromemco_tuart_1a_data_out(BYTE data) { - uart1a_tbe = 0; + uart1a_tbe = false; data &= 0x7f; if (data == 0x00) return; @@ -293,9 +296,9 @@ void cromemco_tuart_1a_data_out(BYTE data) void cromemco_tuart_1a_command_out(BYTE data) { if (data & 1) { - uart1a_rda = 0; - uart1a_tbe = 1; - uart1a_int_pending = 0; + uart1a_rda = false; + uart1a_tbe = true; + uart1a_int_pending = false; } } @@ -311,7 +314,7 @@ void cromemco_tuart_1a_interrupt_out(BYTE data) BYTE cromemco_tuart_1a_parallel_in(void) { - if (uart1a_lpt_busy == 0) + if (!uart1a_lpt_busy) return (BYTE) ~0x20; else return (BYTE) 0xff; @@ -329,8 +332,8 @@ void cromemco_tuart_1a_parallel_out(BYTE data) } } - uart1a_sense = 1; - uart1a_lpt_busy = 1; + uart1a_sense = true; + uart1a_lpt_busy = true; /* bit 7 is strobe, every byte is send 3 times. First with strobe on, then with strobe off, then with on again. @@ -354,9 +357,10 @@ void cromemco_tuart_1a_parallel_out(BYTE data) /* Device 1B */ /************************/ -int uart1b_int_mask, uart1b_int, uart1b_int_pending; -int uart1b_sense, uart1b_lpt_busy; -int uart1b_tbe, uart1b_rda; +int uart1b_int_mask, uart1b_int; +bool uart1b_int_pending; +bool uart1b_sense, uart1b_lpt_busy; +bool uart1b_tbe, uart1b_rda; BYTE cromemco_tuart_1b_status_in(void) { @@ -386,7 +390,7 @@ BYTE cromemco_tuart_1b_data_in(void) int data; static BYTE last; - uart1b_rda = 0; + uart1b_rda = false; data = hal_data_in(TUART1B); /* if no new data available return last */ @@ -400,7 +404,7 @@ BYTE cromemco_tuart_1b_data_in(void) void cromemco_tuart_1b_data_out(BYTE data) { - uart1b_tbe = 0; + uart1b_tbe = false; data &= 0x7f; if (data == 0x00) return; @@ -411,9 +415,9 @@ void cromemco_tuart_1b_data_out(BYTE data) void cromemco_tuart_1b_command_out(BYTE data) { if (data & 1) { - uart1b_rda = 0; - uart1b_tbe = 1; - uart1b_int_pending = 0; + uart1b_rda = false; + uart1b_tbe = true; + uart1b_int_pending = false; } } @@ -429,7 +433,7 @@ void cromemco_tuart_1b_interrupt_out(BYTE data) BYTE cromemco_tuart_1b_parallel_in(void) { - if (uart1b_lpt_busy == 0) + if (!uart1b_lpt_busy) return (BYTE) ~0x20; else return (BYTE) 0xff; @@ -447,8 +451,8 @@ void cromemco_tuart_1b_parallel_out(BYTE data) } } - uart1b_sense = 1; - uart1b_lpt_busy = 1; + uart1b_sense = true; + uart1b_lpt_busy = true; /* bit 7 is strobe, every byte is send 3 times. First with strobe on, then with strobe off, then with on again. @@ -480,22 +484,22 @@ void cromemco_tuart_reset(void) { uart0a_int = 0xff; uart0a_int_mask = 0; - uart0a_int_pending = 0; - uart0a_rda = 0; + uart0a_int_pending = false; + uart0a_rda = false; uart0a_tbe = 1; uart0a_timer1 = uart0a_timer2 = uart0a_timer3 = 0; uart0a_timer4 = uart0a_timer5 = 0; - uart0a_rst7 = 0; + uart0a_rst7 = false; uart1a_int = 0xff; uart1a_int_mask = 0; - uart1a_int_pending = 0; - uart1a_rda = 0; - uart1a_tbe = 1; + uart1a_int_pending = false; + uart1a_rda = false; + uart1a_tbe = true; uart1b_int = 0xff; uart1b_int_mask = 0; - uart1b_int_pending = 0; - uart1b_rda = 0; - uart1b_tbe = 1; + uart1b_int_pending = false; + uart1b_rda = false; + uart1b_tbe = true; } diff --git a/iodevices/cromemco-tu-art.h b/iodevices/cromemco-tu-art.h index 9edf997f..45224a28 100644 --- a/iodevices/cromemco-tu-art.h +++ b/iodevices/cromemco-tu-art.h @@ -52,10 +52,12 @@ extern void cromemco_tuart_0a_timer5_out(BYTE data); extern void cromemco_tuart_reset(void); -extern int uart0a_int_mask, uart0a_int, uart0a_int_pending, uart0a_rst7; +extern int uart0a_int_mask, uart0a_int; +extern bool uart0a_int_pending, uart0a_rst7; extern int uart0a_timer1, uart0a_timer2, uart0a_timer3; extern int uart0a_timer4, uart0a_timer5; -extern int uart0a_tbe, uart0a_rda; +extern int uart0a_tbe; +extern bool uart0a_rda; /* <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> */ @@ -73,9 +75,10 @@ extern void cromemco_tuart_1a_interrupt_out(BYTE data); extern BYTE cromemco_tuart_1a_parallel_in(void); extern void cromemco_tuart_1a_parallel_out(BYTE data); -extern int uart1a_int_mask, uart1a_int, uart1a_int_pending; -extern int uart1a_sense, uart1a_lpt_busy; -extern int uart1a_tbe, uart1a_rda; +extern int uart1a_int_mask, uart1a_int; +extern bool uart1a_int_pending; +extern bool uart1a_sense, uart1a_lpt_busy; +extern bool uart1a_tbe, uart1a_rda; /* <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> */ @@ -93,8 +96,9 @@ extern void cromemco_tuart_1b_interrupt_out(BYTE data); extern BYTE cromemco_tuart_1b_parallel_in(void); extern void cromemco_tuart_1b_parallel_out(BYTE data); -extern int uart1b_int_mask, uart1b_int, uart1b_int_pending; -extern int uart1b_sense, uart1b_lpt_busy; -extern int uart1b_tbe, uart1b_rda; +extern int uart1b_int_mask, uart1b_int; +extern bool uart1b_int_pending; +extern bool uart1b_sense, uart1b_lpt_busy; +extern bool uart1b_tbe, uart1b_rda; #endif /* !CROMEMCO_TU_ART_INC */ diff --git a/iodevices/simbdos.c b/iodevices/simbdos.c index 662af7c2..224a33db 100644 --- a/iodevices/simbdos.c +++ b/iodevices/simbdos.c @@ -65,7 +65,7 @@ static const char *textExts[] = { static FILE *fp = NULL; /* file pointer */ static WORD dmaAddr = 0x80; /* buffer address in emulated space */ -static int textFile = 0; /* text file flag */ +static bool textFile = false; /* text file flag */ /* * host_bdos_out - an output to this I/O device is somewhat equivalent @@ -123,10 +123,10 @@ void host_bdos_out(BYTE outByte) openFlags[0] = 0; /* yes, don't over-write */ } #endif - textFile = 0; /* binary file is assumed */ + textFile = false; /* binary file is assumed */ for (i = 0; textExts[i] != NULL; i++) if (strcmp(extension, textExts[i]) == 0) { - textFile = 1; /* it's a text file */ + textFile = true; /* it's a text file */ break; } } else From cece4815ae1cd6e03ad7556b2cbf7fd19be2efa3 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 07:13:47 +0100 Subject: [PATCH 11/19] boolify VIO and VDM --- iodevices/imsai-vio.c | 44 +++++++++++++++++++++-------------------- iodevices/proctec-vdm.c | 20 +++++++++---------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/iodevices/imsai-vio.c b/iodevices/imsai-vio.c index c3410cb7..19029198 100644 --- a/iodevices/imsai-vio.c +++ b/iodevices/imsai-vio.c @@ -95,12 +95,14 @@ static char text[10]; #endif /* !WANT_SDL */ /* VIO stuff */ -static int state; /* state on/off for refresh thread */ +static bool state; /* state on/off for refresh thread */ static int mode; /* video mode written to command port memory */ static int modebuf; /* and double buffer for it */ -static int vmode, res, inv; /* video mode, resolution & inverse */ +static int vmode, res; /* video mode, resolution */ +static bool inv; /* inverse */ #if !defined(WANT_SDL) || defined(HAS_NETSERVER) -static int kbd_status, kbd_data; /* keyboard status & data */ +static bool kbd_status; /* keyboard status */ +static int kbd_data; /* keyboard data */ /* UNIX stuff */ static pthread_t thread; @@ -203,7 +205,7 @@ static void kill_thread(void) /* shutdown VIO thread and window */ void imsai_vio_off(void) { - state = 0; /* tell web refresh thread to stop */ + state = false; /* tell web refresh thread to stop */ #ifdef WANT_SDL #ifdef HAS_NETSERVER @@ -273,17 +275,17 @@ static inline void draw_point(int x, int y) static void dc1(BYTE c) { register int x, y; - int cinv = (c & 128) ? 1 : 0; + bool cinv = (c & 128) ? true : false; for (x = 0; x < 7; x++) { for (y = 0; y < 10; y++) { if (charset[(c << 1) & 0xff][y][x] == 1) { - if ((cinv ^ inv) == 0) + if (cinv == inv) set_fg_color(); else set_bg_color(); } else { - if ((cinv ^ inv) == 0) + if (cinv == inv) set_bg_color(); else set_fg_color(); @@ -306,17 +308,17 @@ static void dc1(BYTE c) static void dc2(BYTE c) { register int x, y; - int cinv = (c & 128) ? 1 : 0; + bool cinv = (c & 128) ? true : false; for (x = 0; x < 7; x++) { for (y = 0; y < 10; y++) { if (charset[c & 0x7f][y][x] == 1) { - if ((cinv ^ inv) == 0) + if (cinv == inv) set_fg_color(); else set_bg_color(); } else { - if ((cinv ^ inv) == 0) + if (cinv == inv) set_bg_color(); else set_fg_color(); @@ -343,12 +345,12 @@ static void dc3(BYTE c) for (x = 0; x < 7; x++) { for (y = 0; y < 10; y++) { if (charset[c][y][x] == 1) { - if (inv == 0) + if (!inv) set_fg_color(); else set_bg_color(); } else { - if (inv == 0) + if (!inv) set_bg_color(); else set_fg_color(); @@ -433,7 +435,7 @@ static inline void event_handler(void) int res = net_device_get(DEV_VIO); if (res >= 0) { kbd_data = res; - kbd_status = 2; + kbd_status = true; } } } @@ -450,7 +452,7 @@ static inline void event_handler(void) { /* if the last character wasn't processed already do nothing */ /* keep event in queue until the CPU emulation got current one */ - if (kbd_status != 0) + if (kbd_status) return; /* if there is a keyboard event get it and convert with keymap */ @@ -459,7 +461,7 @@ static inline void event_handler(void) if ((event.type == KeyPress) && XLookupString(&event.xkey, text, 1, &key, 0) == 1) { kbd_data = text[0]; - kbd_status = 2; + kbd_status = true; } } #ifdef HAS_NETSERVER @@ -467,7 +469,7 @@ static inline void event_handler(void) int res = net_device_get(DEV_VIO); if (res >= 0) { kbd_data = res; - kbd_status = 2; + kbd_status = true; } } #endif @@ -491,7 +493,7 @@ static void refresh(void) vmode = (mode >> 2) & 3; res = mode & 3; - inv = (mode & 16) ? 1 : 0; + inv = (mode & 16) ? true : false; if (res & 1) { cols = 40; @@ -748,7 +750,7 @@ void imsai_vio_init(void) } #endif - state = 1; + state = true; modebuf = -1; putmem(0xf7ff, 0x00); @@ -773,7 +775,7 @@ BYTE imsai_vio_kbd_status_in(void) #ifdef WANT_SDL data = keyn ? 2 : 0; #else - data = (BYTE) kbd_status; + data = kbd_status ? 2 : 0; #endif return data; @@ -794,10 +796,10 @@ int imsai_vio_kbd_in(void) } else data = -1; #else - if (kbd_status != 0) { + if (kbd_status) { /* take over data and reset status */ data = (BYTE) kbd_data; - kbd_status = 0; + kbd_status = false; } else data = -1; #endif diff --git a/iodevices/proctec-vdm.c b/iodevices/proctec-vdm.c index 45667771..83d92d16 100644 --- a/iodevices/proctec-vdm.c +++ b/iodevices/proctec-vdm.c @@ -84,10 +84,10 @@ static char text[10]; #endif /* VDM stuff */ -static int state; /* state on/off for refresh thread */ +static bool state; /* state on/off for refresh thread */ static int mode; /* video mode from I/O port */ #ifndef WANT_SDL -static int kbd_status = 1; /* keyboard status */ +static bool kbd_status; /* keyboard status */ static int kbd_data; /* keyboard data */ #endif static int first; /* first displayed screen position */ @@ -185,7 +185,7 @@ static void close_display(void) /* shutdown VDM window */ void proctec_vdm_off(void) { - state = 0; /* tell refresh thread to stop */ + state = false; /* tell refresh thread to stop */ #ifdef WANT_SDL if (proctec_win_id >= 0) { @@ -299,7 +299,7 @@ static inline void event_handler(void) { /* if the last character wasn't processed already do nothing */ /* keep event in queue until the CPU emulation got current one */ - if (kbd_status == 0) + if (kbd_status) return; /* if there is a keyboard event get it and convert with keymap */ @@ -308,7 +308,7 @@ static inline void event_handler(void) if ((event.type == KeyPress) && XLookupString(&event.xkey, text, 1, &key, 0) == 1) { kbd_data = text[0]; - kbd_status = 0; + kbd_status = true; } } } @@ -334,7 +334,7 @@ static inline void draw_point(int x, int y) static void dc(BYTE c) { register int x, y; - int inv = (c & 128) ? 1 : 0; + bool inv = (c & 128) ? true : false; for (x = 0; x < 9; x++) { for (y = 0; y < 13; y++) { @@ -457,7 +457,7 @@ void proctec_vdm_ctl_out(BYTE data) first = (data & 0xf0) >> 4; beg = data & 0x0f; - state = 1; + state = true; #ifdef WANT_SDL if (proctec_win_id < 0) @@ -484,7 +484,7 @@ BYTE proctec_vdm_kbd_status_in(void) #ifdef WANT_SDL data = keyn ? 0 : 1; #else - data = (BYTE) kbd_status; + data = kbd_status ? 0 : 1; #endif return data; @@ -508,10 +508,10 @@ BYTE proctec_vdm_kbd_in(void) } else data = 0; #else - if (kbd_status == 0) { + if (kbd_status) { /* take over data and reset status */ data = (BYTE) kbd_data; - kbd_status = 1; + kbd_status = false; } else data = 0; #endif From f43821beef56f72698ddacd5e22d08ee467f3841 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 07:41:28 +0100 Subject: [PATCH 12/19] change sleep_for_* parameter to unsigned --- altairsim/srcsim/simport.h | 4 ++-- cpmsim/srcsim/simport.h | 4 ++-- cromemcosim/srcsim/simport.h | 4 ++-- imsaisim/srcsim/simport.h | 4 ++-- intelmdssim/srcsim/simport.h | 4 ++-- mosteksim/srcsim/simport.h | 4 ++-- picosim/srcsim/simport.h | 4 ++-- z80core/simfun.c | 4 ++-- z80core/simfun.h | 4 ++-- z80sim/srcsim/simport.h | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/altairsim/srcsim/simport.h b/altairsim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/altairsim/srcsim/simport.h +++ b/altairsim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); diff --git a/cpmsim/srcsim/simport.h b/cpmsim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/cpmsim/srcsim/simport.h +++ b/cpmsim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); diff --git a/cromemcosim/srcsim/simport.h b/cromemcosim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/cromemcosim/srcsim/simport.h +++ b/cromemcosim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); diff --git a/imsaisim/srcsim/simport.h b/imsaisim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/imsaisim/srcsim/simport.h +++ b/imsaisim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); diff --git a/intelmdssim/srcsim/simport.h b/intelmdssim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/intelmdssim/srcsim/simport.h +++ b/intelmdssim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); diff --git a/mosteksim/srcsim/simport.h b/mosteksim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/mosteksim/srcsim/simport.h +++ b/mosteksim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); diff --git a/picosim/srcsim/simport.h b/picosim/srcsim/simport.h index 31e2dd87..30ebd39c 100644 --- a/picosim/srcsim/simport.h +++ b/picosim/srcsim/simport.h @@ -12,8 +12,8 @@ #include "sim.h" #include "simdefs.h" -static inline void sleep_for_us(long time) { sleep_us(time); } -static inline void sleep_for_ms(int time) { sleep_ms(time); } +static inline void sleep_for_us(unsigned long time) { sleep_us(time); } +static inline void sleep_for_ms(unsigned time) { sleep_ms(time); } static inline uint64_t get_clock_us(void) { diff --git a/z80core/simfun.c b/z80core/simfun.c index f531d947..0655abec 100644 --- a/z80core/simfun.c +++ b/z80core/simfun.c @@ -40,7 +40,7 @@ static int load_hex(char *fn, WORD start, int size); /* * Sleep for time microseconds, 999999 max */ -void sleep_for_us(long time) +void sleep_for_us(unsigned long time) { struct timespec timer, rem; int err; @@ -68,7 +68,7 @@ void sleep_for_us(long time) /* * Sleep for time milliseconds, 999 max */ -void sleep_for_ms(int time) +void sleep_for_ms(unsigned time) { struct timespec timer, rem; int err; diff --git a/z80core/simfun.h b/z80core/simfun.h index 40261665..a3f45f13 100644 --- a/z80core/simfun.h +++ b/z80core/simfun.h @@ -19,8 +19,8 @@ * #include "sim.h" * #include "simdefs.h" * - * extern void sleep_for_us(long time); - * extern void sleep_for_ms(int time); + * extern void sleep_for_us(unsigned long time); + * extern void sleep_for_ms(unsigned time); * extern uint64_t get_clock_us(void); * #ifdef WANT_ICE * extern int get_cmdline(char *buf, int len); diff --git a/z80sim/srcsim/simport.h b/z80sim/srcsim/simport.h index 0b1fe2af..bdbd35b0 100644 --- a/z80sim/srcsim/simport.h +++ b/z80sim/srcsim/simport.h @@ -10,8 +10,8 @@ #include "sim.h" #include "simdefs.h" -extern void sleep_for_us(long time); -extern void sleep_for_ms(int time); +extern void sleep_for_us(unsigned long time); +extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE extern int get_cmdline(char *buf, int len); From 2c310816c0303d3e765a424d4c3cd73fbec63f0e Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 07:58:15 +0100 Subject: [PATCH 13/19] boolify load_core, load_file and get_cmdline (return of true means success) Also flipped handle_break in simice. --- altairsim/srcsim/simport.h | 2 +- cpmsim/srcsim/simport.h | 2 +- cromemcosim/srcsim/simport.h | 2 +- imsaisim/srcsim/simport.h | 2 +- intelmdssim/srcsim/simmem.c | 4 +-- intelmdssim/srcsim/simport.h | 2 +- mosteksim/srcsim/simport.h | 2 +- picosim/srcsim/picosim.c | 4 +-- picosim/srcsim/simport.h | 2 +- z80core/simfun.c | 52 ++++++++++++++++++------------------ z80core/simfun.h | 4 +-- z80core/simice.c | 36 ++++++++++++------------- z80core/simmain.c | 14 +++++----- z80sim/srcsim/simport.h | 2 +- 14 files changed, 65 insertions(+), 65 deletions(-) diff --git a/altairsim/srcsim/simport.h b/altairsim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/altairsim/srcsim/simport.h +++ b/altairsim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ diff --git a/cpmsim/srcsim/simport.h b/cpmsim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/cpmsim/srcsim/simport.h +++ b/cpmsim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ diff --git a/cromemcosim/srcsim/simport.h b/cromemcosim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/cromemcosim/srcsim/simport.h +++ b/cromemcosim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ diff --git a/imsaisim/srcsim/simport.h b/imsaisim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/imsaisim/srcsim/simport.h +++ b/imsaisim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ diff --git a/intelmdssim/srcsim/simmem.c b/intelmdssim/srcsim/simmem.c index 4a031005..10c2b7a4 100644 --- a/intelmdssim/srcsim/simmem.c +++ b/intelmdssim/srcsim/simmem.c @@ -52,7 +52,7 @@ void init_memory(void) } strcpy(pfn, boot_rom_file); - if (load_file(fn, 0, BOOT_SIZE)) { + if (!load_file(fn, 0, BOOT_SIZE)) { LOGE(TAG, "couldn't load bootstrap ROM"); exit(EXIT_FAILURE); } @@ -61,7 +61,7 @@ void init_memory(void) if (mon_enabled) { mon_enabled = 0; strcpy(pfn, mon_rom_file); - if (load_file(fn, 65536 - MON_SIZE, MON_SIZE)) { + if (!load_file(fn, 65536 - MON_SIZE, MON_SIZE)) { LOGE(TAG, "couldn't load monitor ROM"); exit(EXIT_FAILURE); } diff --git a/intelmdssim/srcsim/simport.h b/intelmdssim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/intelmdssim/srcsim/simport.h +++ b/intelmdssim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ diff --git a/mosteksim/srcsim/simport.h b/mosteksim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/mosteksim/srcsim/simport.h +++ b/mosteksim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ diff --git a/picosim/srcsim/picosim.c b/picosim/srcsim/picosim.c index 38e71782..5dddccda 100644 --- a/picosim/srcsim/picosim.c +++ b/picosim/srcsim/picosim.c @@ -241,7 +241,7 @@ int main(void) * from the terminal. For single character requests (len == 2), * returns immediately after input is received. */ -int get_cmdline(char *buf, int len) +bool get_cmdline(char *buf, int len) { int i = 0; char c; @@ -268,7 +268,7 @@ int get_cmdline(char *buf, int len) } buf[i] = '\0'; putchar('\n'); - return 0; + return true; } #ifdef WANT_ICE diff --git a/picosim/srcsim/simport.h b/picosim/srcsim/simport.h index 30ebd39c..e61e32d2 100644 --- a/picosim/srcsim/simport.h +++ b/picosim/srcsim/simport.h @@ -20,6 +20,6 @@ static inline uint64_t get_clock_us(void) return to_us_since_boot(get_absolute_time()); } -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif /* !SIMPORT_INC */ diff --git a/z80core/simfun.c b/z80core/simfun.c index 0655abec..c4e9c8a7 100644 --- a/z80core/simfun.c +++ b/z80core/simfun.c @@ -34,8 +34,8 @@ static const char *TAG = "func"; #define BUFSIZE 256 /* buffer size for file I/O */ -static int load_mos(char *fn, WORD start, int size); -static int load_hex(char *fn, WORD start, int size); +static bool load_mos(char *fn, WORD start, int size); +static bool load_hex(char *fn, WORD start, int size); /* * Sleep for time microseconds, 999999 max @@ -109,9 +109,9 @@ uint64_t get_clock_us(void) * Read an ICE command line from stdin. * Sets buf to an empty string on EOF and signal interruptions. */ -int get_cmdline(char *buf, int len) +bool get_cmdline(char *buf, int len) { - int err = 0; + bool res = true; if (fgets(buf, len, stdin) == NULL) { putchar('\n'); @@ -119,9 +119,9 @@ int get_cmdline(char *buf, int len) clearerr(stdin); *buf = '\0'; } else - err = 1; + res = false; } - return err; + return res; } #endif @@ -137,26 +137,26 @@ int get_cmdline(char *buf, int len) * size > 0 check it is loaded in memory range * "start" and "start + size - 1" */ -int load_file(char *fn, WORD start, int size) +bool load_file(char *fn, WORD start, int size) { BYTE d; int fd, n; if (strlen(fn) == 0) { LOGE(TAG, "no input file given"); - return 1; + return false; } if ((fd = open(fn, O_RDONLY)) == -1) { LOGE(TAG, "can't open file %s", fn); - return 1; + return false; } n = read(fd, (char *) &d, 1); /* read first byte of file */ close(fd); if (n != 1) { LOGE(TAG, "invalid file %s", fn); - return 1; + return false; } if (size > 0) @@ -179,7 +179,7 @@ int load_file(char *fn, WORD start, int size) * ll = load address low * lh = load address high */ -static int load_mos(char *fn, WORD start, int size) +static bool load_mos(char *fn, WORD start, int size) { register int i; int c, c2; @@ -188,7 +188,7 @@ static int load_mos(char *fn, WORD start, int size) if ((fp = fopen(fn, "r")) == NULL) { LOGE(TAG, "can't open file %s", fn); - return 1; + return false; } /* read load address */ @@ -196,7 +196,7 @@ static int load_mos(char *fn, WORD start, int size) || (c = getc(fp)) == EOF || (c2 = getc(fp)) == EOF) { LOGE(TAG, "invalid Mostek file %s", fn); fclose(fp); - return 1; + return false; } laddr = (c2 << 8) | c; @@ -206,7 +206,7 @@ static int load_mos(char *fn, WORD start, int size) LOGW(TAG, "tried to load Mostek file outside " "expected address range. Address: %04X", laddr); fclose(fp); - return 1; + return false; } count = 0; @@ -217,7 +217,7 @@ static int load_mos(char *fn, WORD start, int size) "expected address range. " "Address: %04X", i); fclose(fp); - return 1; + return false; } count++; putmem(i, (BYTE) c); @@ -236,13 +236,13 @@ static int load_mos(char *fn, WORD start, int size) LOG(TAG, "PC : %04XH\r\n", PC); LOG(TAG, "LOADED: %04XH (%d)\r\n\r\n", count, count); - return 0; + return true; } /* * Loader for Intel HEX */ -static int load_hex(char *fn, WORD start, int size) +static bool load_hex(char *fn, WORD start, int size) { register char *s; register BYTE *p; @@ -259,7 +259,7 @@ static int load_hex(char *fn, WORD start, int size) if ((fp = fopen(fn, "r")) == NULL) { LOGE(TAG, "can't open file %s", fn); - return 1; + return false; } while (fgets(inbuf, BUFSIZE, fp) != NULL) { @@ -279,7 +279,7 @@ static int load_hex(char *fn, WORD start, int size) LOGE(TAG, "invalid character in " "HEX record %s", s0); fclose(fp); - return 1; + return false; } *p = (*s <= '9' ? *s - '0' : *s - 'A' + 10) << 4; s++; @@ -287,13 +287,13 @@ static int load_hex(char *fn, WORD start, int size) LOGE(TAG, "odd number of characters in " "HEX record %s", s0); fclose(fp); - return 1; + return false; } else if (!(*s >= '0' && *s <= '9') && !(*s >= 'A' && *s <= 'F')) { LOGE(TAG, "invalid character in " "HEX record %s", s0); fclose(fp); - return 1; + return false; } *p |= (*s <= '9' ? *s - '0' : *s - 'A' + 10); s++; @@ -303,12 +303,12 @@ static int load_hex(char *fn, WORD start, int size) if (n < 5) { LOGE(TAG, "invalid HEX record %s", s0); fclose(fp); - return 1; + return false; } if ((chksum & 255) != 0) { LOGE(TAG, "invalid checksum in HEX record %s", s0); fclose(fp); - return 1; + return false; } p = outbuf; @@ -316,7 +316,7 @@ static int load_hex(char *fn, WORD start, int size) if (count + 5 != n) { LOGE(TAG, "invalid count in HEX record %s", s0); fclose(fp); - return 1; + return false; } addr = *p++; addr = (addr << 8) | *p++; @@ -331,7 +331,7 @@ static int load_hex(char *fn, WORD start, int size) "Address: %04X-%04X", addr, addr + count - 1); fclose(fp); - return 1; + return false; } } @@ -356,5 +356,5 @@ static int load_hex(char *fn, WORD start, int size) LOG(TAG, "PC : %04XH\r\n", PC); LOG(TAG, "LOADED: %04XH (%d)\r\n\r\n", count & 0xffff, count & 0xffff); - return 0; + return true; } diff --git a/z80core/simfun.h b/z80core/simfun.h index a3f45f13..0d0fdc62 100644 --- a/z80core/simfun.h +++ b/z80core/simfun.h @@ -23,10 +23,10 @@ * extern void sleep_for_ms(unsigned time); * extern uint64_t get_clock_us(void); * #ifdef WANT_ICE - * extern int get_cmdline(char *buf, int len); + * extern bool get_cmdline(char *buf, int len); * #endif */ -extern int load_file(char *fn, WORD start, int size); +extern bool load_file(char *fn, WORD start, int size); #endif /* !SIMFUN_INC */ diff --git a/z80core/simice.c b/z80core/simice.c index 4ecbec2b..8da18bc9 100644 --- a/z80core/simice.c +++ b/z80core/simice.c @@ -150,7 +150,7 @@ void ice_cmd_loop(int go_mode) } else { printf(">>> "); fflush(stdout); - if (get_cmdline(cmd, LENCMD)) { + if (!get_cmdline(cmd, LENCMD)) { eoj = false; continue; } @@ -273,7 +273,7 @@ static void do_trace(char *s) for (i = 0; i < count; i++) { step_cpu(); print_reg(); - if (cpu_error && (cpu_error != OPHALT || !handle_break())) + if (cpu_error && (cpu_error != OPHALT || handle_break())) break; } uninstall_softbp(); @@ -304,7 +304,7 @@ static void do_go(char *s) start_time = cpu_time; for (;;) { run_cpu(); - if (cpu_error && (cpu_error != OPHALT || !handle_break())) + if (cpu_error && (cpu_error != OPHALT || handle_break())) break; } stop_time = cpu_time; @@ -356,8 +356,8 @@ static void uninstall_softbp(void) /* * Handling of software (HALT opcode) / hardware breakpoints: * - * Output: false breakpoint or other HALT opcode reached (stop) - * true breakpoint hit, pass counter not reached (continue) + * Output: false breakpoint hit, pass counter not reached (continue) + * true breakpoint or other HALT opcode reached (stop) */ static bool handle_break(void) { @@ -377,7 +377,7 @@ static bool handle_break(void) printf(" access to %04x\n", hb_addr); hb_trig = 0; cpu_error = NONE; - return false; + return true; } #endif #ifdef SBSIZE @@ -385,7 +385,7 @@ static bool handle_break(void) if (soft[i].sb_pass && soft[i].sb_addr == PC - 1) break; if (i == SBSIZE) /* no breakpoint found */ - return false; + return true; #ifdef HISIZE if (h_next) /* correct history */ h_next--; @@ -398,12 +398,12 @@ static bool handle_break(void) putmem(soft[i].sb_addr, 0x76); /* restore HALT opcode again */ soft[i].sb_passcount++; /* increment pass counter */ if (soft[i].sb_passcount != soft[i].sb_pass) - return true; /* pass not reached, continue */ + return false; /* pass not reached, continue */ printf("Software breakpoint hit at %04x\n", soft[i].sb_addr); soft[i].sb_passcount = 0; /* reset pass counter */ - return false; /* pass reached, stop */ + return true; /* pass reached, stop */ #else /* !SBSIZE */ - return false; + return true; #endif /* !SBSIZE */ } @@ -496,7 +496,7 @@ static void do_modify(char *s) for (;;) { printf("%04x = %02x : ", (unsigned int) wrk_addr, getmem(wrk_addr)); - if (get_cmdline(arg, LENCMD) || arg[0] == '\0') + if (!get_cmdline(arg, LENCMD) || arg[0] == '\0') break; s = arg; while (isspace((unsigned char) *s)) @@ -629,7 +629,7 @@ static void do_port(char *s) data = io_in(port, 0); report_cpu_error(); printf("%02x = %02x : ", port, data); - if (!get_cmdline(arg, LENCMD)) { + if (get_cmdline(arg, LENCMD)) { s = arg; while (isspace((unsigned char) *s)) s++; @@ -774,7 +774,7 @@ static void do_reg(char *s) default: break; } - if (!get_cmdline(arg, LENCMD)) { + if (get_cmdline(arg, LENCMD)) { s = arg; while (isspace((unsigned char) *s)) s++; @@ -1112,7 +1112,7 @@ static void do_hist(char *s) l = 0; fputs("q = quit, else continue: ", stdout); fflush(stdout); - if (!get_cmdline(arg, LENCMD) && + if (get_cmdline(arg, LENCMD) && (arg[0] == '\0' || tolower((unsigned char) arg[0]) == 'q')) break; } @@ -1424,13 +1424,13 @@ static void do_load(char *s) while (isspace((unsigned char) *s)) s++; if (isxdigit((unsigned char) *s)) { - load_file(fn, strtol(s, NULL, 16), -1); - wrk_addr = PC; + if (load_file(fn, strtol(s, NULL, 16), -1)) + wrk_addr = PC; return; } } - load_file(fn, 0, 0); - wrk_addr = PC; + if (load_file(fn, 0, 0)) + wrk_addr = PC; } /* diff --git a/z80core/simmain.c b/z80core/simmain.c index 87788d57..00350759 100644 --- a/z80core/simmain.c +++ b/z80core/simmain.c @@ -38,7 +38,7 @@ #include "simint.h" static void save_core(void); -static int load_core(void); +static bool load_core(void); #ifdef WANT_SDL int sim_main(int argc, char *argv[]) @@ -413,10 +413,10 @@ puts(" ##### ### ##### ### ##### ### # #"); init_memory(); /* initialize memory configuration */ if (l_flag) { /* load core */ - if (load_core()) + if (!load_core()) return EXIT_FAILURE; } else if (x_flag) { /* OR load memory from file */ - if (load_file(xfn, 0, 0)) /* don't care where it loads */ + if (!load_file(xfn, 0, 0)) /* don't care where it loads */ return EXIT_FAILURE; } @@ -522,7 +522,7 @@ static void save_core(void) * This function loads the CPU and memory from the * file core.z80 or core.8080 */ -static int load_core(void) +static bool load_core(void) { register FILE *fp; register int i, c; @@ -539,7 +539,7 @@ static int load_core(void) #endif if ((fp = fopen(fname, "r")) == NULL) { printf("can't open file %s\n", fname); - return 1; + return false; } err = false; @@ -597,7 +597,7 @@ static int load_core(void) if (err) { printf("error reading %s\n", fname); - return 1; + return false; } else - return 0; + return true; } diff --git a/z80sim/srcsim/simport.h b/z80sim/srcsim/simport.h index bdbd35b0..2acb8600 100644 --- a/z80sim/srcsim/simport.h +++ b/z80sim/srcsim/simport.h @@ -14,7 +14,7 @@ extern void sleep_for_us(unsigned long time); extern void sleep_for_ms(unsigned time); extern uint64_t get_clock_us(void); #ifdef WANT_ICE -extern int get_cmdline(char *buf, int len); +extern bool get_cmdline(char *buf, int len); #endif #endif /* !SIMPORT_INC */ From 042d3913e79452551e445fbf4f63ef279e7bdd71 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 08:10:09 +0100 Subject: [PATCH 14/19] boolify intelmdssim --- intelmdssim/srcsim/simctl.c | 6 +++--- intelmdssim/srcsim/simio.c | 26 +++++++++++++------------- intelmdssim/srcsim/simmem.c | 6 +++--- intelmdssim/srcsim/simmem.h | 2 +- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/intelmdssim/srcsim/simctl.c b/intelmdssim/srcsim/simctl.c index 3eda345f..a721372e 100644 --- a/intelmdssim/srcsim/simctl.c +++ b/intelmdssim/srcsim/simctl.c @@ -48,7 +48,7 @@ static void reset_clicked(int state, int val); static void power_clicked(int state, int val); static void quit_callback(void); -static int cpu_wait; /* CPU wait flag */ +static bool cpu_wait; /* CPU wait flag */ #ifdef WANT_SDL static int fp_win_id; /* frontpanel window id */ @@ -256,7 +256,7 @@ static void reset_clicked(int state, int val) reset_cpu(); cpu_state &= ~ST_RESET; cpu_bus = CPU_WO | CPU_M1 | CPU_MEMR; - cpu_wait = 0; + cpu_wait = false; break; default: break; @@ -282,7 +282,7 @@ static void power_clicked(int state, int val) if (power) break; power = 1; - cpu_wait = 1; + cpu_wait = true; if (!isatty(fileno(stdout)) || (system("tput clear") == -1)) puts("\r\n\r\n\r\n"); break; diff --git a/intelmdssim/srcsim/simio.c b/intelmdssim/srcsim/simio.c index d4e759c4..f32fdd34 100644 --- a/intelmdssim/srcsim/simio.c +++ b/intelmdssim/srcsim/simio.c @@ -69,10 +69,10 @@ static BYTE int_in_service; /* interrupts in service */ static pthread_mutex_t int_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t rtc_mutex = PTHREAD_MUTEX_INITIALIZER; -static int rtc_int_enabled; -static int rtc_status1, rtc_status0; /* RTC status flip-flops */ +static bool rtc_int_enabled; +static bool rtc_status1, rtc_status0; /* RTC status flip-flops */ -static int th_suspend; /* RTC/interrupt thread suspend flag */ +static bool th_suspend; /* RTC/interrupt thread suspend flag */ int lpt_fd; /* fd for file "printer.txt" */ net_connector_t ncons[NUMNSOC]; /* network connection for TTY */ @@ -170,9 +170,9 @@ void init_io(void) int_requests = 0; int_in_service = 0; - rtc_int_enabled = 0; /* reset real time clock */ - rtc_status0 = 0; - rtc_status1 = 0; + rtc_int_enabled = false; /* reset real time clock */ + rtc_status0 = false; + rtc_status1 = false; mon_reset(); /* reset monitor module */ #ifdef HAS_ISBC201 @@ -253,13 +253,13 @@ void exit_io(void) */ void reset_io(void) { - th_suspend = 1; /* suspend timing thread */ + th_suspend = true; /* suspend timing thread */ sleep_for_ms(20); /* give it enough time to suspend */ pthread_mutex_lock(&rtc_mutex); - rtc_int_enabled = 0; /* reset real time clock */ - rtc_status0 = 0; - rtc_status1 = 0; + rtc_int_enabled = false; /* reset real time clock */ + rtc_status0 = false; + rtc_status1 = false; pthread_mutex_unlock(&rtc_mutex); pthread_mutex_lock(&int_mutex); @@ -279,7 +279,7 @@ void reset_io(void) isbc206_reset(); /* reset iSBC 206 disk controller */ #endif - th_suspend = 0; /* resume timing thread */ + th_suspend = false; /* resume timing thread */ } /* @@ -398,7 +398,7 @@ static BYTE rtc_in(void) data |= 0x01; pthread_mutex_lock(&rtc_mutex); rtc_status1 = rtc_status0; - rtc_status0 = 0; + rtc_status0 = false; pthread_mutex_unlock(&rtc_mutex); return data; } @@ -485,7 +485,7 @@ static void *timing(void *arg) /* 0.9765ms RTC (here 1.04 ms) */ if (tick % 4 == 0) { pthread_mutex_lock(&rtc_mutex); - rtc_status0 = 1; + rtc_status0 = true; pthread_mutex_unlock(&rtc_mutex); if (rtc_int_enabled) int_request(RTC_IRQ); diff --git a/intelmdssim/srcsim/simmem.c b/intelmdssim/srcsim/simmem.c index 10c2b7a4..e4b5e01a 100644 --- a/intelmdssim/srcsim/simmem.c +++ b/intelmdssim/srcsim/simmem.c @@ -30,7 +30,7 @@ BYTE boot_rom[BOOT_SIZE]; /* bootstrap ROM */ char *boot_rom_file; /* bootstrap ROM file path */ char *mon_rom_file; /* monitor ROM file path */ -int mon_enabled; /* monitor ROM enabled flag */ +bool mon_enabled; /* monitor ROM enabled flag */ void init_memory(void) { @@ -59,13 +59,13 @@ void init_memory(void) memcpy(boot_rom, memory, BOOT_SIZE); if (mon_enabled) { - mon_enabled = 0; + mon_enabled = false; strcpy(pfn, mon_rom_file); if (!load_file(fn, 65536 - MON_SIZE, MON_SIZE)) { LOGE(TAG, "couldn't load monitor ROM"); exit(EXIT_FAILURE); } - mon_enabled = 1; + mon_enabled = true; } /* fill memory content with some initial value */ diff --git a/intelmdssim/srcsim/simmem.h b/intelmdssim/srcsim/simmem.h index 11b3537c..8069717f 100644 --- a/intelmdssim/srcsim/simmem.h +++ b/intelmdssim/srcsim/simmem.h @@ -31,7 +31,7 @@ extern BYTE memory[65536], boot_rom[BOOT_SIZE]; extern char *boot_rom_file, *mon_rom_file; -extern int mon_enabled; +extern bool mon_enabled; extern void init_memory(void); From 6519559a5fe57e14e66a5affb67cbf7e591dcf82 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 08:18:32 +0100 Subject: [PATCH 15/19] boolify cromemcosim and while (1) --- cpmsim/srcsim/simio.c | 2 +- cromemcosim/srcsim/simio.c | 18 +++++++++--------- cromemcosim/srcsim/simmem.c | 2 +- cromemcosim/srcsim/simmem.h | 3 ++- intelmdssim/srcsim/simio.c | 2 +- iodevices/altair-88-dcdd.c | 2 +- iodevices/cromemco-dazzler.c | 2 +- iodevices/unix_network.c | 2 +- picosim/srcsim/disks.c | 2 +- 9 files changed, 18 insertions(+), 17 deletions(-) diff --git a/cpmsim/srcsim/simio.c b/cpmsim/srcsim/simio.c index b859edd1..8b7f429d 100644 --- a/cpmsim/srcsim/simio.c +++ b/cpmsim/srcsim/simio.c @@ -2172,7 +2172,7 @@ void telnet_negotiation(int fd) /* and reject all others offered */ p[0].fd = fd; p[0].events = POLLIN; - while (1) { + while (true) { /* wait for input */ p[0].revents = 0; poll(p, 1, TELNET_TIMEOUT); diff --git a/cromemcosim/srcsim/simio.c b/cromemcosim/srcsim/simio.c index 7271e227..5ec314bc 100644 --- a/cromemcosim/srcsim/simio.c +++ b/cromemcosim/srcsim/simio.c @@ -433,36 +433,36 @@ static void mmu_out(BYTE data) case 0x00: case 0x01: sel = 0; - common = 0; + common = false; break; case 0x02: sel = 1; - common = 0; + common = false; break; case 0x04: sel = 2; - common = 0; + common = false; break; case 0x08: sel = 3; - common = 0; + common = false; break; case 0x10: sel = 4; - common = 0; + common = false; break; case 0x20: sel = 5; - common = 0; + common = false; break; case 0x40: sel = 6; - common = 0; + common = false; break; case 0x80: case 0x81: sel = 0; - common = 1; + common = true; break; default: LOGE(TAG, "Not supported bank select = %02x", data); @@ -481,7 +481,7 @@ static void *timing(void *arg) { UNUSED(arg); - while (1) { /* 1 msec per loop iteration */ + while (true) { /* 1 msec per loop iteration */ /* do nothing if thread is suspended */ if (th_suspend) diff --git a/cromemcosim/srcsim/simmem.c b/cromemcosim/srcsim/simmem.c index bc42d1d6..fb1e0b68 100644 --- a/cromemcosim/srcsim/simmem.c +++ b/cromemcosim/srcsim/simmem.c @@ -37,7 +37,7 @@ WORD boot_switch[MAXMEMSECT]; /* boot address */ BYTE *memory[MAXSEG]; /* MMU with pointers to the banks */ int selbnk; /* current selected bank */ -int common; /* flag for common writes to all banks */ +bool common; /* flag for common writes to all banks */ int bankio; /* data written to banking I/O port */ int num_banks = MAXSEG; diff --git a/cromemcosim/srcsim/simmem.h b/cromemcosim/srcsim/simmem.h index 9426d248..1b6b1891 100644 --- a/cromemcosim/srcsim/simmem.h +++ b/cromemcosim/srcsim/simmem.h @@ -67,7 +67,8 @@ extern memmap_t memconf[MAXMEMSECT][MAXMEMMAP]; extern WORD boot_switch[MAXMEMSECT]; /* boot address */ extern BYTE *memory[MAXSEG]; -extern int selbnk, common, bankio, num_banks; +extern int selbnk, bankio, num_banks; +extern bool common; extern int p_tab[MAXPAGES]; /* 256 pages of 256 bytes */ diff --git a/intelmdssim/srcsim/simio.c b/intelmdssim/srcsim/simio.c index f32fdd34..8a44e3c1 100644 --- a/intelmdssim/srcsim/simio.c +++ b/intelmdssim/srcsim/simio.c @@ -464,7 +464,7 @@ static void *timing(void *arg) tick = 0; - while (1) { /* 260 usec per loop iteration */ + while (true) { /* 260 usec per loop iteration */ t = get_clock_us(); diff --git a/iodevices/altair-88-dcdd.c b/iodevices/altair-88-dcdd.c index 342052b1..d5cff36a 100644 --- a/iodevices/altair-88-dcdd.c +++ b/iodevices/altair-88-dcdd.c @@ -169,7 +169,7 @@ static void *timing(void *arg) UNUSED(arg); /* 1 msec per loop iteration */ - while (1) { + while (true) { /* advance sector position, 5ms at 360 RPM */ if (++cnt_sec > TIMESEC) { cnt_sec = 0; diff --git a/iodevices/cromemco-dazzler.c b/iodevices/cromemco-dazzler.c index 37b99070..a3ff4cca 100644 --- a/iodevices/cromemco-dazzler.c +++ b/iodevices/cromemco-dazzler.c @@ -748,7 +748,7 @@ static void *update_thread(void *arg) t1 = get_clock_us(); - while (1) { /* do forever or until canceled */ + while (true) { /* do forever or until canceled */ /* draw one frame dependent on graphics format */ if (state) { /* draw frame if on */ diff --git a/iodevices/unix_network.c b/iodevices/unix_network.c index 06ccbfda..408d64f1 100644 --- a/iodevices/unix_network.c +++ b/iodevices/unix_network.c @@ -206,7 +206,7 @@ void telnet_negotiation(int fd) /* and reject all others offered */ p[0].fd = fd; p[0].events = POLLIN; - while (1) { + while (true) { /* wait for input */ p[0].revents = 0; poll(p, 1, TELNET_TIMEOUT); diff --git a/picosim/srcsim/disks.c b/picosim/srcsim/disks.c index 8cbdd3e6..abe714bd 100644 --- a/picosim/srcsim/disks.c +++ b/picosim/srcsim/disks.c @@ -118,7 +118,7 @@ void list_files(const char *dir, const char *ext) res = f_findfirst(&dp, &fno, dir, ext); if (res == FR_OK) { - while (1) { + while (true) { printf("%s\t", fno.fname); if (strlen(fno.fname) < 8) putchar('\t'); From f452cea1722557582bcc19f98fef89863a9fb69d Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 12:45:27 +0100 Subject: [PATCH 16/19] re-format David McNaughton's code in project style, max 100 chars Also some by-Hand formatting. Verified generated object code stayed the same. --- iodevices/cromemco-88ccc.c | 26 +- iodevices/cromemco-88ccc.h | 4 +- iodevices/cromemco-d+7a.c | 42 +- iodevices/cromemco-d+7a.h | 6 +- iodevices/cromemco-hal.c | 663 +++++----- iodevices/cromemco-hal.h | 54 +- iodevices/cromemco-wdi.c | 1996 +++++++++++++++--------------- iodevices/diskmanager.c | 675 +++++------ iodevices/generic-at-modem.c | 2200 +++++++++++++++++----------------- iodevices/imsai-hal.c | 694 ++++++----- iodevices/imsai-hal.h | 50 +- webfrontend/netsrv.c | 858 ++++++------- webfrontend/netsrv.h | 22 +- 13 files changed, 3716 insertions(+), 3574 deletions(-) diff --git a/iodevices/cromemco-88ccc.c b/iodevices/cromemco-88ccc.c index b7f1b313..8cc100a9 100644 --- a/iodevices/cromemco-88ccc.c +++ b/iodevices/cromemco-88ccc.c @@ -64,7 +64,6 @@ static void *store_image(void *arg) while (state) { /* do until total frame is received */ if (net_device_alive(DEV_88ACC)) { - msg.auxiliary = flags & 0x0f; msg.bias = (flags & 0x20) >> 5; msg.fields = format & 0x0f; @@ -72,19 +71,21 @@ static void *store_image(void *arg) msgB = format | (msg.bias << 6); - LOGD(TAG, "CCC/ACC Capture: to addr %04x, fields: %d, interval %d", dma_addr, msg.fields, msg.interval); + LOGD(TAG, "CCC/ACC Capture: to addr %04x, fields: %d, interval %d", + dma_addr, msg.fields, msg.interval); - net_device_send(DEV_88ACC, (char *)&msgB, sizeof(msgB)); + net_device_send(DEV_88ACC, (char *) &msgB, sizeof(msgB)); for (i = 0; i < msg.fields; i++) { len = net_device_get_data(DEV_88ACC, (char *) buffer, FIELDSIZE); if (len != FIELDSIZE) { - LOGW(TAG,"Error in frame length, received %d of %d bytes.", len, FIELDSIZE); + LOGW(TAG, "Error in frame length, received %d of %d bytes.", + len, FIELDSIZE); } else { - LOGD(TAG, "received frame %d, length %d, %d stored at %04x", i, len, (BYTE)*buffer, dma_addr + (i * FIELDSIZE)); - for (j = 0; j < FIELDSIZE; j++) { - dma_write(dma_addr + (i * FIELDSIZE) + j, buffer[j]); - } + LOGD(TAG, "received frame %d, length %d, %d stored at %04x", + i, len, (BYTE) *buffer, dma_addr + (i * FIELDSIZE)); + for (j = 0; j < FIELDSIZE; j++) + dma_write(dma_addr + i * FIELDSIZE + j, buffer[j]); } } } else { @@ -93,15 +94,15 @@ static void *store_image(void *arg) } /* frame done, calculate total frame time */ - j = msg.fields * (msg.interval +1) * 2; + j = msg.fields * (msg.interval + 1) * 2; /* sleep_for_ms(j); */ /* sleep rest of total frame time */ t2 = get_clock_us(); tdiff = t2 - t1; - if (tdiff < (j*1000)) - sleep_for_ms(j - tdiff/1000); + if (tdiff < (j * 1000)) + sleep_for_ms(j - tdiff / 1000); LOGD(TAG, "Time: %d", tdiff); @@ -116,7 +117,6 @@ static void *store_image(void *arg) void cromemco_88ccc_ctrl_a_out(BYTE data) { - flags = data & 0x7f; if (data & 0x80) { @@ -154,7 +154,7 @@ void cromemco_88ccc_ctrl_b_out(BYTE data) void cromemco_88ccc_ctrl_c_out(BYTE data) { /* get DMA address for storage memory */ - dma_addr = (WORD)data << 7; + dma_addr = (WORD) data << 7; } BYTE cromemco_88ccc_ctrl_a_in(void) diff --git a/iodevices/cromemco-88ccc.h b/iodevices/cromemco-88ccc.h index 803b9d19..575774fc 100644 --- a/iodevices/cromemco-88ccc.h +++ b/iodevices/cromemco-88ccc.h @@ -1,10 +1,10 @@ /** * cromemco-88ccc.h - * + * * Emulation of the Cromemco 88 CCC - Cyclops Camera Controller * * Copyright (C) 2018 by David McNaughton - * + * * History: * 14-AUG-2018 1.0 Initial Release * 04-NOV-2019 remove fake DMA bus request diff --git a/iodevices/cromemco-d+7a.c b/iodevices/cromemco-d+7a.c index 9ddcbe9f..60b65e0b 100644 --- a/iodevices/cromemco-d+7a.c +++ b/iodevices/cromemco-d+7a.c @@ -31,44 +31,42 @@ static BYTE inPort[PORT_COUNT]; static BYTE outPort[PORT_COUNT]; #ifdef HAS_NETSERVER -static void cromemco_d7a_callback(BYTE *data) { +static void cromemco_d7a_callback(BYTE *data) +{ + int i; - int i; - inPort[0] = *data++; - for (i=1; i < PORT_COUNT; i++) { - inPort[i] = (*data++) - 128; - } + inPort[0] = *data++; + for (i = 1; i < PORT_COUNT; i++) + inPort[i] = (*data++) - 128; } #endif -void cromemco_d7a_init(void) { - - inPort[0] = 0xFF; +void cromemco_d7a_init(void) +{ + inPort[0] = 0xFF; #ifdef HAS_NETSERVER - if (n_flag) { - net_device_service(DEV_D7AIO, cromemco_d7a_callback); - } + if (n_flag) + net_device_service(DEV_D7AIO, cromemco_d7a_callback); #endif - } static void cromemco_d7a_out(BYTE port, BYTE data) { - outPort[port] = data; + outPort[port] = data; - LOGD(TAG, "Output %d on port %d", data, port); + LOGD(TAG, "Output %d on port %d", data, port); #ifdef HAS_NETSERVER - if (n_flag) { - // if (net_device_alive(DEV_D7AIO)) { - net_device_send(DEV_D7AIO, (char *)&data, 1); - // } - } + if (n_flag) { + // if (net_device_alive(DEV_D7AIO)) { + net_device_send(DEV_D7AIO, (char *) &data, 1); + // } + } #endif } -void cromemco_d7a_D_out(BYTE data) { cromemco_d7a_out(0, data); } +void cromemco_d7a_D_out (BYTE data) { cromemco_d7a_out(0, data); } void cromemco_d7a_A1_out(BYTE data) { cromemco_d7a_out(1, data); } void cromemco_d7a_A2_out(BYTE data) { cromemco_d7a_out(2, data); } void cromemco_d7a_A3_out(BYTE data) { cromemco_d7a_out(3, data); } @@ -82,7 +80,7 @@ static BYTE cromemco_d7a_in(BYTE port) return inPort[port]; } -BYTE cromemco_d7a_D_in(void) { return cromemco_d7a_in(0); }; +BYTE cromemco_d7a_D_in (void) { return cromemco_d7a_in(0); }; BYTE cromemco_d7a_A1_in(void) { return cromemco_d7a_in(1); }; BYTE cromemco_d7a_A2_in(void) { return cromemco_d7a_in(2); }; BYTE cromemco_d7a_A3_in(void) { return cromemco_d7a_in(3); }; diff --git a/iodevices/cromemco-d+7a.h b/iodevices/cromemco-d+7a.h index 8728cec5..048a0bb4 100644 --- a/iodevices/cromemco-d+7a.h +++ b/iodevices/cromemco-d+7a.h @@ -1,10 +1,10 @@ /** * cromemco-d+7a.h - * - * Emulation of the Cromemco D+7A I/O + * + * Emulation of the Cromemco D+7A I/O * * Copyright (C) 2020 by David McNaughton - * + * * History: * 14-JAN-2020 1.0 Initial Release */ diff --git a/iodevices/cromemco-hal.c b/iodevices/cromemco-hal.c index 1b1301dc..2117e5c7 100644 --- a/iodevices/cromemco-hal.c +++ b/iodevices/cromemco-hal.c @@ -1,14 +1,14 @@ - /* - * cromemco-hal.c - * - * Copyright (C) 2022 by David McNaughton - * - * Cromemco TU-ART hardware abstraction layer - * - * History: - * 9-JUL-2022 1.0 Initial Release - * - */ +/* +* cromemco-hal.c +* +* Copyright (C) 2022 by David McNaughton +* +* Cromemco TU-ART hardware abstraction layer +* +* History: +* 9-JUL-2022 1.0 Initial Release +* +*/ #include #include @@ -38,148 +38,169 @@ static const char *TAG = "HAL"; /* -------------------- NULL device HAL -------------------- */ -static int null_alive(int dev) { - UNUSED(dev); +static int null_alive(int dev) +{ + UNUSED(dev); - return 1; /* NULL is always alive */ + return 1; /* NULL is always alive */ } + #if !defined(HAS_NETSERVER) || !defined(HAS_MODEM) -static int null_dead(int dev) { - UNUSED(dev); +static int null_dead(int dev) +{ + UNUSED(dev); - return 0; /* NULL is always dead */ + return 0; /* NULL is always dead */ } #endif -static void null_status(int dev, BYTE *stat) { - UNUSED(dev); - UNUSED(stat); - return; +static void null_status(int dev, BYTE *stat) +{ + UNUSED(dev); + UNUSED(stat); + + return; } -static int null_in(int dev) { - UNUSED(dev); - return -1; +static int null_in(int dev) +{ + UNUSED(dev); + + return -1; } -static void null_out(int dev, BYTE data) { - UNUSED(dev); - UNUSED(data); - return; +static void null_out(int dev, BYTE data) +{ + UNUSED(dev); + UNUSED(data); + + return; } /* -------------------- WEBTTY HAL -------------------- */ #ifdef HAS_NETSERVER -static int net_tty_alive(int dev) { - if (n_flag) { - // LOG(TAG, "WEBTTY %d: %d\r\n", dev, net_device_alive(dev)); - /* WEBTTY is only alive if websocket is connected */ - return net_device_alive((net_device_t) dev); - } else { - return 0; - } + +static int net_tty_alive(int dev) +{ + if (n_flag) { + // LOG(TAG, "WEBTTY %d: %d\r\n", dev, net_device_alive(dev)); + /* WEBTTY is only alive if websocket is connected */ + return net_device_alive((net_device_t) dev); + } else + return 0; } -static void net_tty_status(int dev, BYTE *stat) { - *stat &= (BYTE)(~3); - if (n_flag) { - if (net_device_poll((net_device_t) dev)) { - *stat |= 2; - } - *stat |= 1; - } + +static void net_tty_status(int dev, BYTE *stat) +{ + *stat &= (BYTE) (~3); + if (n_flag) { + if (net_device_poll((net_device_t) dev)) + *stat |= 2; + *stat |= 1; + } } -static int net_tty_in(int dev) { - if (n_flag) { - return net_device_get((net_device_t) dev); - } else { - return -1; - } + +static int net_tty_in(int dev) +{ + if (n_flag) + return net_device_get((net_device_t) dev); + else + return -1; } -static void net_tty_out(int dev, BYTE data) { - if (n_flag) { - net_device_send((net_device_t) dev, (char *)&data, 1); - } + +static void net_tty_out(int dev, BYTE data) +{ + if (n_flag) + net_device_send((net_device_t) dev, (char *)&data, 1); } -#endif + +#endif /* HAS_NETSERVER */ /* -------------------- STDIO HAL -------------------- */ -static int stdio_alive(int dev) { - UNUSED(dev); +static int stdio_alive(int dev) +{ + UNUSED(dev); - return 1; /* STDIO is always alive */ + return 1; /* STDIO is always alive */ } -static void stdio_status(int dev, BYTE *stat) { - struct pollfd p[1]; - - UNUSED(dev); - - p[0].fd = fileno(stdin); - p[0].events = POLLIN; - p[0].revents = 0; - poll(p, 1, 0); - *stat &= (BYTE)(~3); - if (p[0].revents & POLLIN) - *stat |= 2; - if (p[0].revents & POLLNVAL) { - LOGE(TAG, "can't use terminal, try 'screen simulation ...'"); - exit(EXIT_FAILURE); - // cpu_error = IOERROR; - // cpu_state = STOPPED; - } - *stat |= 1; +static void stdio_status(int dev, BYTE *stat) +{ + struct pollfd p[1]; + + UNUSED(dev); + + p[0].fd = fileno(stdin); + p[0].events = POLLIN; + p[0].revents = 0; + poll(p, 1, 0); + *stat &= (BYTE) (~3); + if (p[0].revents & POLLIN) + *stat |= 2; + if (p[0].revents & POLLNVAL) { + LOGE(TAG, "can't use terminal, try 'screen simulation ...'"); + exit(EXIT_FAILURE); + // cpu_error = IOERROR; + // cpu_state = STOPPED; + } + *stat |= 1; } -static int stdio_in(int dev) { - int data; - struct pollfd p[1]; - UNUSED(dev); +static int stdio_in(int dev) +{ + int data; + struct pollfd p[1]; + + UNUSED(dev); again: - /* if no input waiting return last */ - p[0].fd = fileno(stdin); - p[0].events = POLLIN; - p[0].revents = 0; - poll(p, 1, 0); - if (!(p[0].revents & POLLIN)) - return -1; - - if (read(fileno(stdin), &data, 1) == 0) { - /* try to reopen tty, input redirection exhausted */ - if (freopen("/dev/tty", "r", stdin) == NULL) - LOGE(TAG, "can't reopen /dev/tty"); - set_unix_terminal(); - goto again; - } - - return data; + /* if no input waiting return last */ + p[0].fd = fileno(stdin); + p[0].events = POLLIN; + p[0].revents = 0; + poll(p, 1, 0); + if (!(p[0].revents & POLLIN)) + return -1; + + if (read(fileno(stdin), &data, 1) == 0) { + /* try to reopen tty, input redirection exhausted */ + if (freopen("/dev/tty", "r", stdin) == NULL) + LOGE(TAG, "can't reopen /dev/tty"); + set_unix_terminal(); + goto again; + } + + return data; } -static void stdio_out(int dev, BYTE data) { - UNUSED(dev); + +static void stdio_out(int dev, BYTE data) +{ + UNUSED(dev); again: - if (write(fileno(stdout), (char *) &data, 1) != 1) { - if (errno == EINTR) { - goto again; - } else { - LOGE(TAG, "can't write data"); - cpu_error = IOERROR; - cpu_state = ST_STOPPED; - } - } + if (write(fileno(stdout), (char *) &data, 1) != 1) { + if (errno == EINTR) + goto again; + else { + LOGE(TAG, "can't write data"); + cpu_error = IOERROR; + cpu_state = ST_STOPPED; + } + } } /* -------------------- SOCKET SERVER HAL -------------------- */ -static int scktsrv_alive(int dev) { - +static int scktsrv_alive(int dev) +{ return ncons[dev].ssc; /* SCKTSRV is alive if there is an open socket */ } -static void scktsrv_status(int dev, BYTE *stat) { - struct pollfd p[1]; +static void scktsrv_status(int dev, BYTE *stat) +{ + struct pollfd p[1]; /* if socket is connected check for I/O */ if (ncons[dev].ssc != 0) { @@ -187,22 +208,22 @@ static void scktsrv_status(int dev, BYTE *stat) { p[0].events = POLLIN; p[0].revents = 0; poll(p, 1, 0); - *stat &= (BYTE)(~3); + *stat &= (BYTE) (~3); if (p[0].revents & POLLHUP) { close(ncons[dev].ssc); ncons[dev].ssc = 0; - *stat = 0; - } else if (p[0].revents & POLLIN) { + *stat = 0; + } else if (p[0].revents & POLLIN) *stat |= 2; - } else { + else *stat |= 1; - } - } else { + } else *stat = 0; - } } -static int scktsrv_in(int dev) { - BYTE data, dummy; + +static int scktsrv_in(int dev) +{ + BYTE data, dummy; struct pollfd p[1]; /* if not connected return last */ @@ -218,30 +239,30 @@ static int scktsrv_in(int dev) { return -1; if (read(ncons[dev].ssc, &data, 1) != 1) { - if ((errno == EAGAIN) || (errno == EINTR)) { - /* EOF, close socket and return last */ - close(ncons[dev].ssc); - ncons[dev].ssc = 0; - return -1; - } else { - LOGE(TAG, "can't read tcpsocket %d data", dev); - cpu_error = IOERROR; - cpu_state = ST_STOPPED; - return 0; - } + if ((errno == EAGAIN) || (errno == EINTR)) { + /* EOF, close socket and return last */ + close(ncons[dev].ssc); + ncons[dev].ssc = 0; + return -1; + } else { + LOGE(TAG, "can't read tcpsocket %d data", dev); + cpu_error = IOERROR; + cpu_state = ST_STOPPED; + return 0; + } } - /* process read data */ - /* telnet client sends \r\n or \r\0, drop second character */ - if (ncons[dev].telnet && (data == '\r')) - if (read(ncons[dev].ssc, &dummy, 1) != 1) - LOGE(TAG, "can't read tcpsocket %d data", dev); - + /* process read data */ + /* telnet client sends \r\n or \r\0, drop second character */ + if (ncons[dev].telnet && (data == '\r')) + if (read(ncons[dev].ssc, &dummy, 1) != 1) + LOGE(TAG, "can't read tcpsocket %d data", dev); - return data; + return data; } -static void scktsrv_out(int dev, BYTE data) { +static void scktsrv_out(int dev, BYTE data) +{ /* return if socket not connected */ if (ncons[dev].ssc == 0) return; @@ -251,9 +272,9 @@ static void scktsrv_out(int dev, BYTE data) { if (errno == EINTR) { goto again; } else { - LOGE(TAG, "can't write socket %d data", dev); - cpu_error = IOERROR; - cpu_state = ST_STOPPED; + LOGE(TAG, "can't write socket %d data", dev); + cpu_error = IOERROR; + cpu_state = ST_STOPPED; } } } @@ -261,233 +282,237 @@ static void scktsrv_out(int dev, BYTE data) { /* -------------------- MODEM HAL -------------------- */ #ifdef HAS_MODEM + #include "generic-at-modem.h" -static int modem_alive(int dev) { - UNUSED(dev); +static int modem_alive(int dev) +{ + UNUSED(dev); - return modem_device_alive(0); + return modem_device_alive(0); } -static void modem_status(int dev, BYTE *stat) { - UNUSED(dev); - - *stat &= (BYTE)(~3); - if (modem_device_poll(0)) { - *stat |= 2; - } - *stat |= 1; + +static void modem_status(int dev, BYTE *stat) +{ + UNUSED(dev); + + *stat &= (BYTE) (~3); + if (modem_device_poll(0)) + *stat |= 2; + *stat |= 1; } -static int modem_in(int dev) { - UNUSED(dev); - return modem_device_get(0); +static int modem_in(int dev) +{ + UNUSED(dev); + + return modem_device_get(0); } -static void modem_out(int dev, BYTE data){ - UNUSED(dev); - modem_device_send(0, (char) data); +static void modem_out(int dev, BYTE data) +{ + UNUSED(dev); + + modem_device_send(0, (char) data); } -#endif /*HAS_MODEM*/ + +#endif /* HAS_MODEM */ /* -------------------- HAL port/device mappings -------------------- */ -const char *tuart_port_name[MAX_TUART_PORT] = { "TUART0.deviceA", "TUART1.deviceA", "TUART1.deviceB" }; +const char *tuart_port_name[MAX_TUART_PORT] = + { "TUART0.deviceA", "TUART1.deviceA", "TUART1.deviceB" }; static const hal_device_t devices[] = { #ifdef HAS_NETSERVER - { "WEBTTY", 0, DEV_TTY, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, - { "WEBTTY2", 0, DEV_TTY2, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, - { "WEBTTY3", 0, DEV_TTY3, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, - { "WEBPTR", 0, DEV_PTR, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBTTY", 0, DEV_TTY, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBTTY2", 0, DEV_TTY2, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBTTY3", 0, DEV_TTY3, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBPTR", 0, DEV_PTR, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, #else - { "WEBTTY", 0, 0, null_dead, null_status, null_in, null_out }, - { "WEBTTY2", 0, 0, null_dead, null_status, null_in, null_out }, - { "WEBTTY3", 0, 0, null_dead, null_status, null_in, null_out }, - { "WEBPTR", 0, 0, null_dead, null_status, null_in, null_out }, + { "WEBTTY", 0, 0, null_dead, null_status, null_in, null_out }, + { "WEBTTY2", 0, 0, null_dead, null_status, null_in, null_out }, + { "WEBTTY3", 0, 0, null_dead, null_status, null_in, null_out }, + { "WEBPTR", 0, 0, null_dead, null_status, null_in, null_out }, #endif - { "STDIO", 0, 0, stdio_alive, stdio_status, stdio_in, stdio_out }, - { "SCKTSRV1", 0, 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, - { "SCKTSRV2", 0, 1, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, + { "STDIO", 0, 0, stdio_alive, stdio_status, stdio_in, stdio_out }, + { "SCKTSRV1", 0, 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, + { "SCKTSRV2", 0, 1, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, #ifdef HAS_MODEM - { "MODEM", 0, 0, modem_alive, modem_status, modem_in, modem_out }, + { "MODEM", 0, 0, modem_alive, modem_status, modem_in, modem_out }, #else - { "MODEM", 0, 0, null_dead, null_status, null_in, null_out }, + { "MODEM", 0, 0, null_dead, null_status, null_in, null_out }, #endif - { "", 0, 0, null_alive, null_status, null_in, null_out } + { "", 0, 0, null_alive, null_status, null_in, null_out } }; hal_device_t tuart[MAX_TUART_PORT][MAX_HAL_DEV]; /* -------------------- HAL utility functions -------------------- */ -static void hal_report(void) { - - int i, j; - - LOG(TAG, "\r\nTU-ART DEVICE MAP:\r\n"); - - for (i = 0; i < MAX_TUART_PORT; i++) { - - LOG(TAG, "%s = ", tuart_port_name[i]); - j = 0; - - while (tuart[i][j].name && j < MAX_HAL_DEV) { - - LOG(TAG, "%s%s", tuart[i][j].name, (tuart[i][j].fallthrough?"+":" ")); - - j++; - } - LOG(TAG, "\r\n"); - } +static void hal_report(void) +{ + int i, j; + + LOG(TAG, "\r\nTU-ART DEVICE MAP:\r\n"); + for (i = 0; i < MAX_TUART_PORT; i++) { + LOG(TAG, "%s = ", tuart_port_name[i]); + j = 0; + while (tuart[i][j].name && j < MAX_HAL_DEV) { + LOG(TAG, "%s%s", tuart[i][j].name, tuart[i][j].fallthrough ? "+" : " "); + j++; + } + LOG(TAG, "\r\n"); + } } -static int hal_find_device(char *dev) { - - int i=0; - while (i < MAX_HAL_DEV) { - if (!strcmp(dev, devices[i].name)) { - return i; - } - i++; - } - return -1; +static int hal_find_device(char *dev) +{ + int i = 0; + while (i < MAX_HAL_DEV) { + if (!strcmp(dev, devices[i].name)) + return i; + i++; + } + return -1; } -static void hal_init(void) { - - int i, j, d; - char *setting; - char match[80]; - char *dev; - - /** - * Initialize HAL with default configuration, as follows: - * - * TUART0.deviceA.device=WEBTTY,STDIO - * TUART1.deviceA.device=SCKTSRV1,WEBTTY2 - * TUART1.deviceB.device=SCKTSRV2,WEBTTY3 - * - * Notes: - * - all ports end with NULL and that is always alive - * - the first HAL device in the list that is alive will service the request - */ - tuart[0][0] = devices[WEBTTYDEV]; - tuart[0][1] = devices[STDIODEV]; - tuart[0][2] = devices[NULLDEV]; - - tuart[1][0] = devices[SCKTSRV1DEV]; - tuart[1][1] = devices[WEBTTY2DEV]; - tuart[1][2] = devices[NULLDEV]; - - tuart[2][0] = devices[SCKTSRV2DEV]; - tuart[2][1] = devices[WEBTTY3DEV]; - tuart[2][2] = devices[NULLDEV]; - - for (i = 0; i < MAX_TUART_PORT; i++) { - - j = 0; - strcpy(match, tuart_port_name[i]); - strcat(match, ".device"); - - if ((setting = getenv(match)) != NULL) { - LOGI(TAG, "%s = %s", match, setting); - - strcpy(match, setting); - - dev = strtok(match, ",\r"); - while (dev) { - - char k = dev[strlen(dev) - 1]; - int fallthrough = 0; - if (k == '+') { - dev[strlen(dev) - 1] = 0; - fallthrough = 1; - } - - d = hal_find_device(dev); - LOGI(TAG, "\tAdding %s to %s", dev, tuart_port_name[i]); - - if (d >= 0) { - memcpy(&tuart[i][j], &devices[d], sizeof(hal_device_t)); - tuart[i][j].fallthrough = fallthrough; - j++; - } - dev = strtok(NULL, ",\r"); - } - memcpy(&tuart[i][j], &devices[NULLDEV], sizeof(hal_device_t)); - } - } +static void hal_init(void) +{ + int i, j, d; + char *setting; + char match[80]; + char *dev; + + /** + * Initialize HAL with default configuration, as follows: + * + * TUART0.deviceA.device=WEBTTY,STDIO + * TUART1.deviceA.device=SCKTSRV1,WEBTTY2 + * TUART1.deviceB.device=SCKTSRV2,WEBTTY3 + * + * Notes: + * - all ports end with NULL and that is always alive + * - the first HAL device in the list that is alive will service the request + */ + tuart[0][0] = devices[WEBTTYDEV]; + tuart[0][1] = devices[STDIODEV]; + tuart[0][2] = devices[NULLDEV]; + + tuart[1][0] = devices[SCKTSRV1DEV]; + tuart[1][1] = devices[WEBTTY2DEV]; + tuart[1][2] = devices[NULLDEV]; + + tuart[2][0] = devices[SCKTSRV2DEV]; + tuart[2][1] = devices[WEBTTY3DEV]; + tuart[2][2] = devices[NULLDEV]; + + for (i = 0; i < MAX_TUART_PORT; i++) { + j = 0; + strcpy(match, tuart_port_name[i]); + strcat(match, ".device"); + + if ((setting = getenv(match)) != NULL) { + LOGI(TAG, "%s = %s", match, setting); + + strcpy(match, setting); + + dev = strtok(match, ",\r"); + while (dev) { + char k = dev[strlen(dev) - 1]; + int fallthrough = 0; + + if (k == '+') { + dev[strlen(dev) - 1] = 0; + fallthrough = 1; + } + + d = hal_find_device(dev); + LOGI(TAG, "\tAdding %s to %s", dev, tuart_port_name[i]); + + if (d >= 0) { + memcpy(&tuart[i][j], &devices[d], sizeof(hal_device_t)); + tuart[i][j].fallthrough = fallthrough; + j++; + } + dev = strtok(NULL, ",\r"); + } + memcpy(&tuart[i][j], &devices[NULLDEV], sizeof(hal_device_t)); + } + } } -void hal_reset(void) { - hal_init(); - hal_report(); +void hal_reset(void) +{ + hal_init(); + hal_report(); } /* -------------------- HAL - TU-ART interface -------------------- */ -void hal_status_in(tuart_port_t dev, BYTE *stat) { - - int p = 0; - BYTE s; - *stat = 0; +void hal_status_in(tuart_port_t dev, BYTE *stat) +{ + int p = 0; + BYTE s; + *stat = 0; next: - while(!tuart[dev][p].alive(tuart[dev][p].device_id)) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!tuart[dev][p].alive(tuart[dev][p].device_id)) + p++; - tuart[dev][p].status(tuart[dev][p].device_id, &s); - *stat |= s; + tuart[dev][p].status(tuart[dev][p].device_id, &s); + *stat |= s; - if (tuart[dev][p].fallthrough) { - p++; - goto next; - } + if (tuart[dev][p].fallthrough) { + p++; + goto next; + } } -int hal_data_in(tuart_port_t dev) { - - int p = 0; - int in = 0; +int hal_data_in(tuart_port_t dev) +{ + int p = 0; + int in = 0; next: - while(!tuart[dev][p].alive(tuart[dev][p].device_id)) { /* Find the first device that is alive */ - p++; - } - - in = tuart[dev][p].in(tuart[dev][p].device_id); - - if (in < 0 && tuart[dev][p].fallthrough) { - p++; - goto next; - } else { - return in; - } -} + /* Find the first device that is alive */ + while (!tuart[dev][p].alive(tuart[dev][p].device_id)) + p++; + + in = tuart[dev][p].in(tuart[dev][p].device_id); -void hal_data_out(tuart_port_t dev, BYTE data) { + if (in < 0 && tuart[dev][p].fallthrough) { + p++; + goto next; + } else + return in; +} - int p = 0; +void hal_data_out(tuart_port_t dev, BYTE data) +{ + int p = 0; next: - while(!tuart[dev][p].alive(tuart[dev][p].device_id)) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!tuart[dev][p].alive(tuart[dev][p].device_id)) + p++; tuart[dev][p].out(tuart[dev][p].device_id, data); - if (tuart[dev][p].fallthrough) { - p++; - goto next; - } + if (tuart[dev][p].fallthrough) { + p++; + goto next; + } } -int hal_alive(tuart_port_t dev) { +int hal_alive(tuart_port_t dev) +{ + int p = 0; - int p = 0; - while(!tuart[dev][p].alive(tuart[dev][p].device_id)) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!tuart[dev][p].alive(tuart[dev][p].device_id)) + p++; - return tuart[dev][p].name?1:0; /* return "alive" (true) when not the NULL device */ + /* return "alive" (true) when not the NULL device */ + return tuart[dev][p].name ? 1 : 0; } diff --git a/iodevices/cromemco-hal.h b/iodevices/cromemco-hal.h index 67271ae0..2d616516 100644 --- a/iodevices/cromemco-hal.h +++ b/iodevices/cromemco-hal.h @@ -16,39 +16,35 @@ #include "sim.h" #include "simdefs.h" -enum tuart_port { +typedef enum tuart_port { TUART0A, TUART1A, TUART1B, - MAX_TUART_PORT -}; - -typedef enum tuart_port tuart_port_t; - -enum hal_dev { - WEBTTYDEV, - WEBTTY2DEV, - WEBTTY3DEV, - WEBPTRDEV, - STDIODEV, - SCKTSRV1DEV, - SCKTSRV2DEV, - MODEMDEV, - NULLDEV, - MAX_HAL_DEV -}; - -struct hal_device { - const char *name; - int fallthrough; - int device_id; + MAX_TUART_PORT +} tuart_port_t; + +typedef enum hal_dev { + WEBTTYDEV, + WEBTTY2DEV, + WEBTTY3DEV, + WEBPTRDEV, + STDIODEV, + SCKTSRV1DEV, + SCKTSRV2DEV, + MODEMDEV, + NULLDEV, + MAX_HAL_DEV +} hal_dev_t; + +typedef struct hal_device { + const char *name; + int fallthrough; + int device_id; int (*alive)(int dev); - void (*status)(int dev, BYTE *stat); - int (*in)(int dev); - void (*out)(int dev, BYTE data); -}; - -typedef struct hal_device hal_device_t; + void (*status)(int dev, BYTE *stat); + int (*in)(int dev); + void (*out)(int dev, BYTE data); +} hal_device_t; extern void hal_reset(void); diff --git a/iodevices/cromemco-wdi.c b/iodevices/cromemco-wdi.c index fc4f5c4f..5a7a652a 100644 --- a/iodevices/cromemco-wdi.c +++ b/iodevices/cromemco-wdi.c @@ -34,613 +34,653 @@ #include "log.h" static const char *TAG = "wdi"; -#define WDI_UNITS 3 -#define WDI_SECTORS 0x14 -#define WDI_BLOCK_SIZE 512 +#define WDI_UNITS 3 +#define WDI_SECTORS 0x14 +#define WDI_BLOCK_SIZE 512 + +#define WDI_MAX_BUFFER (WDI_BLOCK_SIZE + 8) -#define WDI_MAX_BUFFER WDI_BLOCK_SIZE + 8 static BYTE buffer[WDI_MAX_BUFFER]; -static const char *images[WDI_UNITS] = { "hd0.hdd", "hd1.hdd", "hd2.hdd" }; //, "hd3.hdd" }; +static const char *images[WDI_UNITS] = + { "hd0.hdd", "hd1.hdd", "hd2.hdd" }; //, "hd3.hdd" }; + +#define MAX_DISK_PARAM 3 -#define MAX_DISK_PARAM 3 static struct { - int rpm; - int heads; - int cyl; - const char *type; + int rpm; + int heads; + int cyl; + const char *type; } disk_param[MAX_DISK_PARAM] = { - { 3600, 3, 0x162, "H8-1" }, - { 3600, 5, 0x184, "H8-3" }, - { 3600, 5, 0x308, "H8-4" } + { 3600, 3, 0x162, "H8-1" }, + { 3600, 5, 0x184, "H8-3" }, + { 3600, 5, 0x308, "H8-4" } }; -#define INDEX_INT (1000000*60*4) /* Index interval in T ticks per minute @ 4MHz */ +/* Index interval in T ticks per minute @ 4MHz */ +#define INDEX_INT (1000000 * 60 * 4) -enum wreg { WR_BASE, WR0, WR1, WR2, WR3, WR4, WR5, WR6 }; -typedef enum wreg wreg_t; +typedef enum wreg { WR_BASE, WR0, WR1, WR2, WR3, WR4, WR5, WR6 } wreg_t; -enum rreg { RR_BASE, RR0, RR1, RR2, RR3, RR4, RR5, RR6 }; -typedef enum rreg rreg_t; +typedef enum rreg { RR_BASE, RR0, RR1, RR2, RR3, RR4, RR5, RR6 } rreg_t; -enum dma_dev { MREQ, IORQ }; -typedef enum dma_dev dma_dev_t; +typedef enum dma_dev { MREQ, IORQ } dma_dev_t; static struct { - struct { - BYTE cmd_A; - BYTE cmd_B; - BYTE data_A; - BYTE data_B; - } pio0; - struct { - BYTE cmd_A; - BYTE cmd_A_state; - BYTE cmd_B; - BYTE cmd_B_state; - BYTE data_A; - BYTE data_B; - BYTE dir_A; - BYTE dir_B; - BYTE mode_A; - BYTE mode_B; - - BYTE _cmd_ak; - BYTE brd; - BYTE _seek_cmp; - BYTE dsk_id; - BYTE _cmd_stb; - BYTE _cmd_sel1; - BYTE _cmd_sel0; - BYTE cmd__r_w; - - BYTE _sel_un_ad3; - BYTE _sel_un_ad2; - BYTE _sel_un_ad1; - BYTE _sel_un_ad0; - BYTE dma_rdy; - BYTE _disk_op; - - BYTE bus_addr; - } pio1; - struct { - wreg_t wr_state; - rreg_t rr_state; - struct { - BYTE base; - BYTE dest; - BYTE mode; - WORD a_start; - WORD len; - WORD a_addr_counter; - WORD byte_counter; - } wr0; - struct { - BYTE base; - BYTE a_timing; - - dma_dev_t a_device; - BYTE a_fixed; - } wr1; - struct { - BYTE base; - BYTE b_timing; - - dma_dev_t b_device; - BYTE b_fixed; - } wr2; - struct { - BYTE base; - BYTE mask; - BYTE match; - } wr3; - struct { - BYTE base; - WORD b_start; - WORD b_addr_counter; - BYTE intr_control; - BYTE pulse_control; - BYTE intr_vector; - } wr4; - struct { - BYTE base; - } wr5; - struct { - BYTE base; - BYTE mask; - } wr6; - struct { - BYTE status; - } rr0; - BYTE force_ready; - BYTE enable_dma; - } dma; - struct { - BYTE mode0; - BYTE mode1; - BYTE mode2; - BYTE time0; - BYTE time1; - BYTE time2; - BYTE now0; - BYTE now1; - BYTE now2; - BYTE state0; - BYTE state1; - BYTE state2; - Tstates_t T0; - Tstates_t T1; - Tstates_t T2; - } ctc; - struct { - BYTE sector; - - int fd; - BYTE online; - BYTE _crc_error; - BYTE _fault; - - const char *fn; - int type; - char type_s[8]; - - struct { - BYTE uas; - BYTE has; - WORD cas; - BYTE write_gate; - BYTE read_gate; - } command; - struct { - BYTE uav; - BYTE hav; - WORD cav; - BYTE unit_rdy; - BYTE on_cyl; - BYTE seeking; - BYTE rezeroing; - BYTE write_prot; - BYTE illegal_address; - } status; - } hd[8]; /* always allow for the maximum number of units */ - - int unit; /* current selected hard disk unit*/ + struct { + BYTE cmd_A; + BYTE cmd_B; + BYTE data_A; + BYTE data_B; + } pio0; + struct { + BYTE cmd_A; + BYTE cmd_A_state; + BYTE cmd_B; + BYTE cmd_B_state; + BYTE data_A; + BYTE data_B; + BYTE dir_A; + BYTE dir_B; + BYTE mode_A; + BYTE mode_B; + + BYTE _cmd_ak; + BYTE brd; + BYTE _seek_cmp; + BYTE dsk_id; + BYTE _cmd_stb; + BYTE _cmd_sel1; + BYTE _cmd_sel0; + BYTE cmd__r_w; + + BYTE _sel_un_ad3; + BYTE _sel_un_ad2; + BYTE _sel_un_ad1; + BYTE _sel_un_ad0; + BYTE dma_rdy; + BYTE _disk_op; + + BYTE bus_addr; + } pio1; + struct { + wreg_t wr_state; + rreg_t rr_state; + struct { + BYTE base; + BYTE dest; + BYTE mode; + WORD a_start; + WORD len; + WORD a_addr_counter; + WORD byte_counter; + } wr0; + struct { + BYTE base; + BYTE a_timing; + + dma_dev_t a_device; + BYTE a_fixed; + } wr1; + struct { + BYTE base; + BYTE b_timing; + + dma_dev_t b_device; + BYTE b_fixed; + } wr2; + struct { + BYTE base; + BYTE mask; + BYTE match; + } wr3; + struct { + BYTE base; + WORD b_start; + WORD b_addr_counter; + BYTE intr_control; + BYTE pulse_control; + BYTE intr_vector; + } wr4; + struct { + BYTE base; + } wr5; + struct { + BYTE base; + BYTE mask; + } wr6; + struct { + BYTE status; + } rr0; + BYTE force_ready; + BYTE enable_dma; + } dma; + struct { + BYTE mode0; + BYTE mode1; + BYTE mode2; + BYTE time0; + BYTE time1; + BYTE time2; + BYTE now0; + BYTE now1; + BYTE now2; + BYTE state0; + BYTE state1; + BYTE state2; + Tstates_t T0; + Tstates_t T1; + Tstates_t T2; + } ctc; + struct { + BYTE sector; + + int fd; + BYTE online; + BYTE _crc_error; + BYTE _fault; + + const char *fn; + int type; + char type_s[8]; + + struct { + BYTE uas; + BYTE has; + WORD cas; + BYTE write_gate; + BYTE read_gate; + } command; + struct { + BYTE uav; + BYTE hav; + WORD cav; + BYTE unit_rdy; + BYTE on_cyl; + BYTE seeking; + BYTE rezeroing; + BYTE write_prot; + BYTE illegal_address; + } status; + } hd[8]; /* always allow for the maximum number of units */ + + int unit; /* current selected hard disk unit*/ } wdi; void wdi_exit(void) { - int unit; - - for (unit = 0; unit < WDI_UNITS; unit++) { - - if (wdi.hd[unit].fd) { - fsync(wdi.hd[unit].fd); - close(wdi.hd[unit].fd); - wdi.hd[unit].fd =0; - } - wdi.hd[unit].online = 0; - } + int unit; + + for (unit = 0; unit < WDI_UNITS; unit++) { + if (wdi.hd[unit].fd) { + fsync(wdi.hd[unit].fd); + close(wdi.hd[unit].fd); + wdi.hd[unit].fd = 0; + } + wdi.hd[unit].online = 0; + } } + void wdi_init(void) { - char fn[MAX_LFN]; /* path/filename for hard disk image */ - int fd; /* fd for hard disk i/o */ - int unit; - int i; - - wdi.pio1.cmd_A = 0xff; - wdi.pio1.cmd_B = 0xff; - wdi.pio1.cmd_A_state = 0; - wdi.pio1.cmd_B_state = 0; - wdi.pio1.data_A = 0; - wdi.pio1.data_B = 0; - wdi.pio1.dir_A = 0xFF; - wdi.pio1.dir_B = 0xFF; - wdi.pio1.mode_A = 1; - wdi.pio1.mode_B = 1; - - wdi.dma.wr_state = WR_BASE; - wdi.dma.rr_state = RR_BASE; - - wdi.ctc.now0 = 0; - wdi.ctc.now1 = 0; - wdi.ctc.now2 = 0; - - wdi.ctc.state0 = 0; - wdi.ctc.state1 = 0; - wdi.ctc.state2 = 0; - - LOG(TAG, "HARD DISK MAP: [%s]\r\n", dsk_path()); - - for (unit = 0; unit < WDI_UNITS; unit++) { - - wdi.hd[unit].online = 0; - wdi.hd[unit]._fault = 1; - wdi.hd[unit]._crc_error = 0; - - wdi.hd[unit].command.write_gate = 0; - wdi.hd[unit].command.read_gate = 0; - - wdi.hd[unit].status.unit_rdy = 0; - wdi.hd[unit].status.on_cyl = 0; - wdi.hd[unit].status.seeking = 0; - wdi.hd[unit].status.rezeroing = 0; - wdi.hd[unit].status.write_prot = 0; - wdi.hd[unit].status.illegal_address = 0; - - wdi.hd[unit].fn = images[unit]; - - strcpy(fn, (const char *)dsk_path()); - strcat(fn, "/"); - strcat(fn, wdi.hd[unit].fn); - - int got_eintr = 0; + char fn[MAX_LFN]; /* path/filename for hard disk image */ + int fd; /* fd for hard disk i/o */ + int unit; + int i; + + wdi.pio1.cmd_A = 0xff; + wdi.pio1.cmd_B = 0xff; + wdi.pio1.cmd_A_state = 0; + wdi.pio1.cmd_B_state = 0; + wdi.pio1.data_A = 0; + wdi.pio1.data_B = 0; + wdi.pio1.dir_A = 0xFF; + wdi.pio1.dir_B = 0xFF; + wdi.pio1.mode_A = 1; + wdi.pio1.mode_B = 1; + + wdi.dma.wr_state = WR_BASE; + wdi.dma.rr_state = RR_BASE; + + wdi.ctc.now0 = 0; + wdi.ctc.now1 = 0; + wdi.ctc.now2 = 0; + + wdi.ctc.state0 = 0; + wdi.ctc.state1 = 0; + wdi.ctc.state2 = 0; + + LOG(TAG, "HARD DISK MAP: [%s]\r\n", dsk_path()); + + for (unit = 0; unit < WDI_UNITS; unit++) { + wdi.hd[unit].online = 0; + wdi.hd[unit]._fault = 1; + wdi.hd[unit]._crc_error = 0; + + wdi.hd[unit].command.write_gate = 0; + wdi.hd[unit].command.read_gate = 0; + + wdi.hd[unit].status.unit_rdy = 0; + wdi.hd[unit].status.on_cyl = 0; + wdi.hd[unit].status.seeking = 0; + wdi.hd[unit].status.rezeroing = 0; + wdi.hd[unit].status.write_prot = 0; + wdi.hd[unit].status.illegal_address = 0; + + wdi.hd[unit].fn = images[unit]; + + strcpy(fn, (const char *)dsk_path()); + strcat(fn, "/"); + strcat(fn, wdi.hd[unit].fn); + + int got_eintr = 0; again: - if ((fd = open(fn, O_RDWR)) == -1) { - if (errno == EINTR) { - if (!got_eintr) LOGW(TAG, "INIT: GOT EINTR - %s : errno %d", fn, errno); - got_eintr++; - goto again; - } else if ((fd = open(fn, O_RDONLY)) != -1) { - wdi.hd[unit].status.write_prot = 1; - } else { - LOGW(TAG, "INIT: HDD FILE DOES NOT EXIST - %s : %s [%d]", fn, strerror(errno), errno); - wdi.hd[unit]._fault = 0; /* SET FAULT */ - wdi.hd[unit].online = 0; - LOG(TAG, "HD%d: OFFLINE - NO FILE '%s'\r\n", unit, wdi.hd[unit].fn); - continue; - } - } - - if (got_eintr) LOGW(TAG, "INIT: GOT EINTR: total %d", got_eintr); - - wdi.hd[unit].online = 1; - wdi.hd[unit].fd = fd; - - struct stat s; - fstat(fd, &s); - - wdi.hd[unit].type = -1; - - for (i = 0; i < MAX_DISK_PARAM; i++) { - - int size = WDI_BLOCK_SIZE * WDI_SECTORS * disk_param[i].cyl * disk_param[i].heads; - - if (s.st_size == size) { - wdi.hd[unit].type = i; - if (read(fd, buffer, WDI_BLOCK_SIZE) == WDI_BLOCK_SIZE) { - memcpy(wdi.hd[unit].type_s, (char *)&buffer[0x78], 4); - wdi.hd[unit].type_s[5] = '\0'; - } else { - wdi.hd[unit]._fault = 0; /* read fault */ - } - } - } - if (wdi.hd[unit].type < 0) { - wdi.hd[unit]._fault = 0; - wdi.hd[unit].type = 0; - strcpy(wdi.hd[unit].type_s, disk_param[wdi.hd[unit].type].type); - LOGW(TAG, "UNKNOWN DISK IMAGE SIZE [%lld] FOR %s", (long long) s.st_size, wdi.hd[unit].fn); - } - - LOG(TAG, "HD%d:[%s]='%s'\r\n", unit, wdi.hd[unit].type_s, wdi.hd[unit].fn); - } - - LOG(TAG, "\r\n"); - - wdi.unit = 0; + if ((fd = open(fn, O_RDWR)) == -1) { + if (errno == EINTR) { + if (!got_eintr) + LOGW(TAG, "INIT: GOT EINTR - %s : errno %d", + fn, errno); + got_eintr++; + goto again; + } else if ((fd = open(fn, O_RDONLY)) != -1) + wdi.hd[unit].status.write_prot = 1; + else { + LOGW(TAG, "INIT: HDD FILE DOES NOT EXIST - %s : %s [%d]", + fn, strerror(errno), errno); + wdi.hd[unit]._fault = 0; /* SET FAULT */ + wdi.hd[unit].online = 0; + LOG(TAG, "HD%d: OFFLINE - NO FILE '%s'\r\n", + unit, wdi.hd[unit].fn); + continue; + } + } + + if (got_eintr) + LOGW(TAG, "INIT: GOT EINTR: total %d", got_eintr); + + wdi.hd[unit].online = 1; + wdi.hd[unit].fd = fd; + + struct stat s; + + fstat(fd, &s); + + wdi.hd[unit].type = -1; + + for (i = 0; i < MAX_DISK_PARAM; i++) { + int size = (WDI_BLOCK_SIZE * WDI_SECTORS * disk_param[i].cyl + * disk_param[i].heads); + + if (s.st_size == size) { + wdi.hd[unit].type = i; + if (read(fd, buffer, WDI_BLOCK_SIZE) == WDI_BLOCK_SIZE) { + memcpy(wdi.hd[unit].type_s, (char *) &buffer[0x78], 4); + wdi.hd[unit].type_s[5] = '\0'; + } else + wdi.hd[unit]._fault = 0; /* read fault */ + } + } + if (wdi.hd[unit].type < 0) { + wdi.hd[unit]._fault = 0; + wdi.hd[unit].type = 0; + strcpy(wdi.hd[unit].type_s, disk_param[wdi.hd[unit].type].type); + LOGW(TAG, "UNKNOWN DISK IMAGE SIZE [%lld] FOR %s", + (long long) s.st_size, wdi.hd[unit].fn); + } + + LOG(TAG, "HD%d:[%s]='%s'\r\n", unit, wdi.hd[unit].type_s, wdi.hd[unit].fn); + } + + LOG(TAG, "\r\n"); + + wdi.unit = 0; } + #ifdef HAS_NETSERVER void sendHardDisks(HttpdConnection_t *conn) { - int i; - for (i = 0; i < WDI_UNITS; i++) { - httpdPrintf(conn, ",\"HD%d\": { \"type\": \"%s\", \"file\": \"%s\"}", i, wdi.hd[i].type_s, wdi.hd[i].online?wdi.hd[i].fn:""); - } + int i; + + for (i = 0; i < WDI_UNITS; i++) + httpdPrintf(conn, ",\"HD%d\": { \"type\": \"%s\", \"file\": \"%s\"}", + i, wdi.hd[i].type_s, wdi.hd[i].online ? wdi.hd[i].fn : ""); } #endif + static off_t wdi_pos(BYTE *buf) { - off_t p; - const int c = disk_param[wdi.hd[wdi.unit].type].cyl; - const int s = WDI_SECTORS; - const int b = WDI_BLOCK_SIZE; + off_t p; + const int c = disk_param[wdi.hd[wdi.unit].type].cyl; + const int s = WDI_SECTORS; + const int b = WDI_BLOCK_SIZE; - int cyl = buf[1] + (buf[2] << 8); + int cyl = buf[1] + (buf[2] << 8); - p = buf[0] * c * s * b; - p += cyl * s * b; - p += buf[3] * b; + p = buf[0] * c * s * b; + p += cyl * s * b; + p += buf[3] * b; - return p; + return p; } + static Tstates_t wdi_dma_write(BYTE bus_ack) { - int i; - - if (!bus_ack) return 0; - - LOGI(TAG, "WRITE: head: %d, cyl: %x", wdi.hd[wdi.unit].status.hav, wdi.hd[wdi.unit].status.cav); - LOGI(TAG, " start: %04x, addr: %04x, len: %d", wdi.dma.wr4.b_start, wdi.dma.wr4.b_addr_counter, wdi.dma.wr0.len); - - if (wdi.dma.wr0.len >= WDI_MAX_BUFFER) { - wdi.hd[wdi.unit]._fault = 0; /* SET FAULT */ - LOGE(TAG, "DMA length: %d > buffer: %d", wdi.dma.wr0.len, WDI_MAX_BUFFER); - return 0; - } - - for (i = 0; i <= wdi.dma.wr0.len; i++) { - buffer[i] = dma_read(wdi.dma.wr4.b_addr_counter++); - } - - LOGI(TAG, " SYNC: %02x, HEAD: %02x, CYL: %02x%02x, SEC: %02x", buffer[0], buffer[1], buffer[3], buffer[2], buffer[4]); - - int cyl = (buffer[3] << 8 ) | buffer[2]; - - if (wdi.hd[wdi.unit].status.hav != buffer[1]) { - LOGE(TAG, "DISK WRITE ERROR UNIT [%d] - BAD HEAD %d : %d", wdi.unit, wdi.hd[wdi.unit].status.hav, buffer[1]); - wdi.hd[wdi.unit]._fault = 0; /* SET FAULT */ - return 0; - } - if (wdi.hd[wdi.unit].status.cav != cyl) { - LOGE(TAG, "DISK WRITE ERROR UNIT [%d] - BAD CYLINDER %d : %d", wdi.unit, wdi.hd[wdi.unit].status.cav, cyl); - wdi.hd[wdi.unit]._fault = 0; /* SET FAULT */ - return 0; - } - - struct stat s; - - fstat(wdi.hd[wdi.unit].fd, &s); - if (s.st_mode & S_IWUSR) - wdi.hd[wdi.unit].status.write_prot = 0; - else - wdi.hd[wdi.unit].status.write_prot = 1; - - off_t pos = wdi_pos(&buffer[1]); - - if (lseek(wdi.hd[wdi.unit].fd, pos, SEEK_SET) == -1L) { - wdi.hd[wdi.unit]._fault = 0; /* write fault */ - return 0; - } - - /* write the sector */ - if (write(wdi.hd[wdi.unit].fd, &buffer[5], WDI_BLOCK_SIZE) == WDI_BLOCK_SIZE) - wdi.hd[wdi.unit]._fault = 1; - else - wdi.hd[wdi.unit]._fault = 0; /* write fault */ - - // if (fsync(wdi.hd[wdi.unit].fd) == -1) { - // LOGW(TAG, "WRITE: SYNC FAILED - %s [%d]", strerror(errno), errno); - // }; - - return wdi.dma.wr0.len * 3; /* 3 t-states per byte of DMA */ + int i; + + if (!bus_ack) + return 0; + + LOGI(TAG, "WRITE: head: %d, cyl: %x", wdi.hd[wdi.unit].status.hav, + wdi.hd[wdi.unit].status.cav); + LOGI(TAG, " start: %04x, addr: %04x, len: %d", wdi.dma.wr4.b_start, + wdi.dma.wr4.b_addr_counter, wdi.dma.wr0.len); + + if (wdi.dma.wr0.len >= WDI_MAX_BUFFER) { + wdi.hd[wdi.unit]._fault = 0; /* SET FAULT */ + LOGE(TAG, "DMA length: %d > buffer: %d", wdi.dma.wr0.len, WDI_MAX_BUFFER); + return 0; + } + + for (i = 0; i <= wdi.dma.wr0.len; i++) + buffer[i] = dma_read(wdi.dma.wr4.b_addr_counter++); + + LOGI(TAG, " SYNC: %02x, HEAD: %02x, CYL: %02x%02x, SEC: %02x", + buffer[0], buffer[1], buffer[3], buffer[2], buffer[4]); + + int cyl = (buffer[3] << 8) | buffer[2]; + + if (wdi.hd[wdi.unit].status.hav != buffer[1]) { + LOGE(TAG, "DISK WRITE ERROR UNIT [%d] - BAD HEAD %d : %d", + wdi.unit, wdi.hd[wdi.unit].status.hav, buffer[1]); + wdi.hd[wdi.unit]._fault = 0; /* SET FAULT */ + return 0; + } + if (wdi.hd[wdi.unit].status.cav != cyl) { + LOGE(TAG, "DISK WRITE ERROR UNIT [%d] - BAD CYLINDER %d : %d", + wdi.unit, wdi.hd[wdi.unit].status.cav, cyl); + wdi.hd[wdi.unit]._fault = 0; /* SET FAULT */ + return 0; + } + + struct stat s; + + fstat(wdi.hd[wdi.unit].fd, &s); + if (s.st_mode & S_IWUSR) + wdi.hd[wdi.unit].status.write_prot = 0; + else + wdi.hd[wdi.unit].status.write_prot = 1; + + off_t pos = wdi_pos(&buffer[1]); + + if (lseek(wdi.hd[wdi.unit].fd, pos, SEEK_SET) == -1L) { + wdi.hd[wdi.unit]._fault = 0; /* write fault */ + return 0; + } + + /* write the sector */ + if (write(wdi.hd[wdi.unit].fd, &buffer[5], WDI_BLOCK_SIZE) == WDI_BLOCK_SIZE) + wdi.hd[wdi.unit]._fault = 1; + else + wdi.hd[wdi.unit]._fault = 0; /* write fault */ + + // if (fsync(wdi.hd[wdi.unit].fd) == -1) { + // LOGW(TAG, "WRITE: SYNC FAILED - %s [%d]", strerror(errno), errno); + // }; + + return wdi.dma.wr0.len * 3; /* 3 t-states per byte of DMA */ } + static Tstates_t wdi_dma_read(BYTE bus_ack) { - register int v; - int i; - - if (!bus_ack) return 0; - - buffer[0] = wdi.hd[wdi.unit].status.hav; - buffer[1] = wdi.hd[wdi.unit].status.cav & 0xff; - buffer[2] = wdi.hd[wdi.unit].status.cav >> 8; - buffer[3] = wdi.hd[wdi.unit].sector; - - LOGI(TAG, "READ %s: head: %d, cyl: %d, sec: %d", (wdi.dma.wr0.len==4)?"HEADER":"DATA", wdi.hd[wdi.unit].status.hav, wdi.hd[wdi.unit].status.cav, wdi.hd[wdi.unit].sector); - LOGI(TAG, " start: %04x, addr: %04x, len: %d", wdi.dma.wr4.b_start, wdi.dma.wr4.b_addr_counter, wdi.dma.wr0.len); - - wdi.hd[wdi.unit].sector++; - wdi.hd[wdi.unit].sector %= WDI_SECTORS; - - struct stat s; - - fstat(wdi.hd[wdi.unit].fd, &s); - if (s.st_mode & S_IWUSR) - wdi.hd[wdi.unit].status.write_prot = 0; - else - wdi.hd[wdi.unit].status.write_prot = 1; - - off_t pos = wdi_pos(buffer); - - if (lseek(wdi.hd[wdi.unit].fd, pos, SEEK_SET) == -1L) { - wdi.hd[wdi.unit]._fault = 0; /* read fault */ - return 0; - } - - /* read the sector */ - if (read(wdi.hd[wdi.unit].fd, &buffer[4], WDI_BLOCK_SIZE) == WDI_BLOCK_SIZE) { - wdi.hd[wdi.unit]._fault = 1; - } else { - wdi.hd[wdi.unit]._fault = 0; /* read fault */ - return 0; - } - - for (i = 0; i < wdi.dma.wr0.len; i++) { - v = buffer[i]; - - dma_write(wdi.dma.wr4.b_addr_counter, v); - wdi.dma.wr4.b_addr_counter++; - } - - return wdi.dma.wr0.len * 3; /* 3 t-states per byte of DMA */ + register int v; + int i; + + if (!bus_ack) + return 0; + + buffer[0] = wdi.hd[wdi.unit].status.hav; + buffer[1] = wdi.hd[wdi.unit].status.cav & 0xff; + buffer[2] = wdi.hd[wdi.unit].status.cav >> 8; + buffer[3] = wdi.hd[wdi.unit].sector; + + LOGI(TAG, "READ %s: head: %d, cyl: %d, sec: %d", + (wdi.dma.wr0.len == 4) ? "HEADER" : "DATA", + wdi.hd[wdi.unit].status.hav, wdi.hd[wdi.unit].status.cav, + wdi.hd[wdi.unit].sector); + LOGI(TAG, " start: %04x, addr: %04x, len: %d", wdi.dma.wr4.b_start, + wdi.dma.wr4.b_addr_counter, wdi.dma.wr0.len); + + wdi.hd[wdi.unit].sector++; + wdi.hd[wdi.unit].sector %= WDI_SECTORS; + + struct stat s; + + fstat(wdi.hd[wdi.unit].fd, &s); + if (s.st_mode & S_IWUSR) + wdi.hd[wdi.unit].status.write_prot = 0; + else + wdi.hd[wdi.unit].status.write_prot = 1; + + off_t pos = wdi_pos(buffer); + + if (lseek(wdi.hd[wdi.unit].fd, pos, SEEK_SET) == -1L) { + wdi.hd[wdi.unit]._fault = 0; /* read fault */ + return 0; + } + + /* read the sector */ + if (read(wdi.hd[wdi.unit].fd, &buffer[4], WDI_BLOCK_SIZE) == WDI_BLOCK_SIZE) + wdi.hd[wdi.unit]._fault = 1; + else { + wdi.hd[wdi.unit]._fault = 0; /* read fault */ + return 0; + } + + for (i = 0; i < wdi.dma.wr0.len; i++) { + v = buffer[i]; + + dma_write(wdi.dma.wr4.b_addr_counter, v); + wdi.dma.wr4.b_addr_counter++; + } + + return wdi.dma.wr0.len * 3; /* 3 t-states per byte of DMA */ } + BYTE cromemco_wdi_pio0a_data_in(void) { LOGW(TAG, "E0 IN:"); return (BYTE) 0xFF; } + BYTE cromemco_wdi_pio0b_data_in(void) { - BYTE val = 0; - int bus = wdi.pio1.bus_addr; - - LOGD(TAG, "E1 IN: - bus %d",bus); - - switch (bus) - { - case 0: - case 1: - case 2: - case 3: - val = wdi.pio0.data_A; - break; - case 4: - case 5: - case 6: - case 7: - val = wdi.pio0.data_B; - break; - default: - break; - } - LOGD(TAG, "STATUS %d = %02x", bus, val); + BYTE val = 0; + int bus = wdi.pio1.bus_addr; + + LOGD(TAG, "E1 IN: - bus %d", bus); + + switch (bus) { + case 0: + case 1: + case 2: + case 3: + val = wdi.pio0.data_A; + break; + case 4: + case 5: + case 6: + case 7: + val = wdi.pio0.data_B; + break; + default: + break; + } + LOGD(TAG, "STATUS %d = %02x", bus, val); return val; } + BYTE cromemco_wdi_pio0a_cmd_in(void) { LOGW(TAG, "E2 IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_pio0b_cmd_in(void) { LOGW(TAG, "E3 IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_pio1a_data_in(void) { BYTE val = wdi.pio1.dir_A; /* pull inputs HIGH */ - if (!wdi.pio1.brd) { - val ^= 0x40; - } + if (!wdi.pio1.brd) + val ^= 0x40; - if (wdi.hd[wdi.unit].online) { /* Only respond if online */ - if (!wdi.hd[wdi.unit].status.seeking) { - val ^= 0x20; /* _SEEK_COMPLETE if not SEEKING */ - } - if (wdi.pio1._cmd_stb) { - val ^= 0x80; /* _CMD_AK on _CMD_STB */ - } - } + if (wdi.hd[wdi.unit].online) { /* Only respond if online */ + if (!wdi.hd[wdi.unit].status.seeking) + val ^= 0x20; /* _SEEK_COMPLETE if not SEEKING */ + if (wdi.pio1._cmd_stb) + val ^= 0x80; /* _CMD_AK on _CMD_STB */ + } - val = (wdi.pio1.data_A & ~wdi.pio1.dir_A) | val; + val = (wdi.pio1.data_A & ~wdi.pio1.dir_A) | val; - LOGD(TAG, "E4 IN: = %02x", val); + LOGD(TAG, "E4 IN: = %02x", val); return val; } + BYTE cromemco_wdi_pio1b_data_in(void) { BYTE val = wdi.pio1.dir_B; /* pull inputs HIGH */ - if (wdi.hd[wdi.unit].online) { /* Only respond if online */ - if (!wdi.hd[wdi.unit]._fault) { - val ^= 0x02; - } - if (!wdi.hd[wdi.unit]._crc_error) { /* Note: CRC_ERROR is not inverted */ - val ^= 0x80; - } - val ^= wdi.hd[wdi.unit].status.uav << 3; - } + if (wdi.hd[wdi.unit].online) { /* Only respond if online */ + if (!wdi.hd[wdi.unit]._fault) + val ^= 0x02; + if (!wdi.hd[wdi.unit]._crc_error) /* Note: CRC_ERROR is not inverted */ + val ^= 0x80; + val ^= wdi.hd[wdi.unit].status.uav << 3; + } - val = (wdi.pio1.data_B & ~wdi.pio1.dir_B) | val; + val = (wdi.pio1.data_B & ~wdi.pio1.dir_B) | val; LOGD(TAG, "E5 IN: = %02x", val); return val; } + BYTE cromemco_wdi_pio1a_cmd_in(void) { LOGW(TAG, "E6 IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_pio1b_cmd_in(void) { LOGW(TAG, "E7 IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_dma0_in(void) { - /* DMA READ STATUS NOT YET COMPLETE */ + /* DMA READ STATUS NOT YET COMPLETE */ LOGE(TAG, "E8 IN: [%d]", wdi.dma.rr_state); - if (wdi.dma.rr_state == RR_BASE) return wdi.dma.rr0.status; - else return (BYTE) 0xff; + if (wdi.dma.rr_state == RR_BASE) + return wdi.dma.rr0.status; + else + return (BYTE) 0xff; } + BYTE cromemco_wdi_dma1_in(void) { LOGW(TAG, "E9 IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_dma2_in(void) { LOGW(TAG, "EA IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_dma3_in(void) { LOGW(TAG, "EB IN:"); return (BYTE) 0xff; } + BYTE cromemco_wdi_ctc0_in(void) { - BYTE val = wdi.ctc.now0; - Tstates_t index_ticks = INDEX_INT / disk_param[wdi.hd[wdi.unit].type].rpm; + BYTE val = wdi.ctc.now0; + Tstates_t index_ticks = INDEX_INT / disk_param[wdi.hd[wdi.unit].type].rpm; LOGD(TAG, "IN: CTC #0 = %02x - Tdiff=%" PRIu64 "", val, T - wdi.ctc.T0); - if (wdi.hd[wdi.unit].online) { /* Only count indexes if online */ - - if (T < wdi.ctc.T0) wdi.ctc.T0 = T; /* clock rollover has occurred in T */ - else if ((T - wdi.ctc.T0) > index_ticks) { - if (val > 0) wdi.ctc.now0--; - wdi.hd[wdi.unit].sector = 0; - wdi.ctc.T0 += index_ticks; - } - } + if (wdi.hd[wdi.unit].online) { /* Only count indexes if online */ + if (T < wdi.ctc.T0) + wdi.ctc.T0 = T; /* clock rollover has occurred in T */ + else if ((T - wdi.ctc.T0) > index_ticks) { + if (val > 0) + wdi.ctc.now0--; + wdi.hd[wdi.unit].sector = 0; + wdi.ctc.T0 += index_ticks; + } + } return val; } + BYTE cromemco_wdi_ctc1_in(void) { - Tstates_t Tdiff = T - wdi.ctc.T1; - Tstates_t index_ticks = INDEX_INT / disk_param[wdi.hd[wdi.unit].type].rpm; - unsigned int sectors = (Tdiff * WDI_SECTORS + index_ticks / 10) / index_ticks; /* -10% on sector time */ - - LOGD(TAG, "IN: CTC #1 = %02x - Tdiff=%" PRIu64 " = %d sectors", wdi.ctc.now1, T - wdi.ctc.T1, sectors); - - if (sectors && wdi.hd[wdi.unit].online) { /* Only count sectors if online */ - if (wdi.ctc.now1 > 0) { - int r = (int)wdi.ctc.now1 - sectors; - if (r < 0) r = 0; - wdi.ctc.now1 = r; - } - wdi.hd[wdi.unit].sector += sectors; - wdi.hd[wdi.unit].sector %= WDI_SECTORS; - // LOGI(TAG, "IN: CTC #1 = %02x, sect: %02x", wdi.ctc.now1, wdi.hd[wdi.unit].sector); - - wdi.ctc.T1 = T; - } + Tstates_t Tdiff = T - wdi.ctc.T1; + Tstates_t index_ticks = INDEX_INT / disk_param[wdi.hd[wdi.unit].type].rpm; + /* -10% on sector time */ + unsigned int sectors = (Tdiff * WDI_SECTORS + index_ticks / 10) / index_ticks; + + LOGD(TAG, "IN: CTC #1 = %02x - Tdiff=%" PRIu64 " = %d sectors", + wdi.ctc.now1, T - wdi.ctc.T1, sectors); + + if (sectors && wdi.hd[wdi.unit].online) { /* Only count sectors if online */ + if (wdi.ctc.now1 > 0) { + int r = (int) wdi.ctc.now1 - sectors; + + if (r < 0) + r = 0; + wdi.ctc.now1 = r; + } + wdi.hd[wdi.unit].sector += sectors; + wdi.hd[wdi.unit].sector %= WDI_SECTORS; + // LOGI(TAG, "IN: CTC #1 = %02x, sect: %02x", wdi.ctc.now1, + // wdi.hd[wdi.unit].sector); + + wdi.ctc.T1 = T; + } return wdi.ctc.now1; } + BYTE cromemco_wdi_ctc2_in(void) { - BYTE val = wdi.ctc.now2; + BYTE val = wdi.ctc.now2; LOGD(TAG, "IN: CTC #2 = %d", val); -/** - * COULD SIMULATE HEAD SEEK TIME HERE - * IMI-7710 spec gives: - * single track access time 10 ms - * average access time 50 ms - * maximum access time 100 ms - * - * For now, seek is complete the first time this counter is checked - */ + /** + * COULD SIMULATE HEAD SEEK TIME HERE + * IMI-7710 spec gives: + * single track access time 10 ms + * average access time 50 ms + * maximum access time 100 ms + * + * For now, seek is complete the first time this counter is checked + */ - /* Only count seek complete if online */ - if (val > 0 && wdi.hd[wdi.unit].online) wdi.ctc.now2--; + /* Only count seek complete if online */ + if (val > 0 && wdi.hd[wdi.unit].online) + wdi.ctc.now2--; return val; } + BYTE cromemco_wdi_ctc3_in(void) { LOGW(TAG, "EF IN:"); @@ -649,563 +689,595 @@ BYTE cromemco_wdi_ctc3_in(void) static void command_bus_strobe(void) { - - int bus = wdi.pio1.bus_addr; - BYTE data = wdi.pio0.data_A; - BYTE _head; - WORD _cyl; - - /* Only rezero if online */ - if (wdi.hd[wdi.unit].status.rezeroing && wdi.hd[wdi.unit].online) { - LOGI(TAG, "REZEROING"); - wdi.hd[wdi.unit].status.hav = 0; - wdi.hd[wdi.unit].status.cav = 0; - wdi.hd[wdi.unit].status.rezeroing = 0; - wdi.hd[wdi.unit].status.on_cyl = 1; - wdi.hd[wdi.unit].status.unit_rdy = 1; - } - /* Only seek if online */ - if (wdi.hd[wdi.unit].status.seeking && wdi.hd[wdi.unit].online) { - LOGI(TAG, "SEEKING: UNIT: %02x, HEAD: %02x, CYL: %03x", wdi.hd[wdi.unit].command.uas, wdi.hd[wdi.unit].command.has, wdi.hd[wdi.unit].command.cas); - wdi.hd[wdi.unit].status.uav = wdi.hd[wdi.unit].command.uas; - wdi.hd[wdi.unit].status.hav = wdi.hd[wdi.unit].command.has; - wdi.hd[wdi.unit].status.cav = wdi.hd[wdi.unit].command.cas; - wdi.hd[wdi.unit].status.seeking = 0; - wdi.hd[wdi.unit].status.on_cyl = 1; - wdi.hd[wdi.unit].status.unit_rdy = 1; - } - - switch (bus) - { - case 0: - wdi.unit = (data >> 4) & 0x07; /* only 3 LSB of Unit */ - _head = ((data & 0x0c) >> 2) | ((data & 0x80) >> 5); /* reuse MSB of Unit for Head*/ - _cyl = (wdi.hd[wdi.unit].command.cas & 0xff) | ((data & 0x03) << 8); - - if ((wdi.unit >= WDI_UNITS)) { - LOGE(TAG, "DISK COMMAND 0 - ILLEGAL UNIT: %02x", wdi.unit); - wdi.hd[wdi.unit].online = 0; - wdi.hd[wdi.unit].command.uas = wdi.unit; - wdi.hd[wdi.unit].status.illegal_address = 1; - wdi.hd[wdi.unit].status.unit_rdy = 0; - wdi.hd[wdi.unit]._fault = 0; - } else if (!wdi.hd[wdi.unit].online) { - LOGW(TAG, "DISK COMMAND 0 - UNIT: %02x - OFFLINE", wdi.unit); - wdi.hd[wdi.unit].command.uas = wdi.unit; - wdi.hd[wdi.unit].status.illegal_address = 1; - wdi.hd[wdi.unit].status.unit_rdy = 0; - wdi.hd[wdi.unit]._fault = 0; - } else if (_head >= disk_param[wdi.hd[wdi.unit].type].heads) { - LOGE(TAG, "DISK COMMAND 0 - ILLEGAL HEAD: %02x", _head); - wdi.hd[wdi.unit].command.uas = wdi.unit; - wdi.hd[wdi.unit].status.uav = wdi.unit; - wdi.hd[wdi.unit].status.illegal_address = 1; - wdi.hd[wdi.unit].status.unit_rdy = 0; - wdi.hd[wdi.unit]._fault = 0; - /* - * Illegal cylinder should only be checked on COMMAND 1 - * when a full cylinder address is received (COMMAND 0 followed by COMMAND 1) - * otherwise there can be a false negative (illegal address) - */ - } else { - wdi.hd[wdi.unit].command.uas = wdi.unit; - wdi.hd[wdi.unit].command.has = _head; - wdi.hd[wdi.unit].command.cas = _cyl; - wdi.hd[wdi.unit].status.seeking = 1; - wdi.hd[wdi.unit].status.on_cyl = 0; - wdi.hd[wdi.unit].status.unit_rdy = 0; - wdi.hd[wdi.unit].status.illegal_address = 0; - - LOGI(TAG, "DISK COMMAND 0 - UNIT: %02x, HEAD: %02x, CYL: %03x", wdi.hd[wdi.unit].command.uas, wdi.hd[wdi.unit].command.has, wdi.hd[wdi.unit].command.cas); - } - break; - case 1: - _cyl = (wdi.hd[wdi.unit].command.cas & 0xf00) | data; - - if (_cyl >= disk_param[wdi.hd[wdi.unit].type].cyl) { - LOGE(TAG, "DISK COMMAND 1 - ILLEGAL CYLINDER: %03x", _cyl); - wdi.hd[wdi.unit].status.illegal_address = 1; - wdi.hd[wdi.unit].status.unit_rdy = 0; - wdi.hd[wdi.unit]._fault = 0; - } else { - wdi.hd[wdi.unit].command.cas = _cyl; - wdi.hd[wdi.unit].status.cav = wdi.hd[wdi.unit].command.cas; - wdi.hd[wdi.unit].status.seeking = 1; - wdi.hd[wdi.unit].status.on_cyl = 0; - wdi.hd[wdi.unit].status.unit_rdy = 0; - - LOGI(TAG, "DISK COMMAND 1 - CYL: %03x", wdi.hd[wdi.unit].status.cav); - } - break; - case 2: - if (data & 0xfc) { - LOGE(TAG, "DISK COMMAND 2 - %d NOT IMPLEMENTED - %02x", bus, data); - } - break; - case 3: - if (data & 1) { - LOGI(TAG, "DISK COMMAND 3 - FAULT CLEAR "); - wdi.hd[wdi.unit]._fault = 1; /* CLEAR FAULT */ - } - if (data & 2) { - LOGI(TAG, "DISK COMMAND 3 - REZERO"); - - wdi.hd[wdi.unit].status.rezeroing = 1; - wdi.hd[wdi.unit].status.on_cyl = 0; - wdi.hd[wdi.unit].status.unit_rdy = 0; - wdi.hd[wdi.unit]._fault = 1; /* CLEAR FAULT */ - } - break; - case 4: - wdi.pio0.data_B = wdi.hd[wdi.unit].status.unit_rdy; - wdi.pio0.data_B |= wdi.hd[wdi.unit].status.on_cyl << 1; - wdi.pio0.data_B |= wdi.hd[wdi.unit].status.seeking << 2; - wdi.pio0.data_B |= wdi.hd[wdi.unit].status.rezeroing << 3; - wdi.pio0.data_B |= wdi.hd[wdi.unit].status.illegal_address << 6; - break; - case 5: - wdi.pio0.data_B = !(wdi.hd[wdi.unit]._fault); /* Inverse of _fault */ - wdi.pio0.data_B |= wdi.hd[wdi.unit].type << 5; /* Drive type in unused bits 5 & 6 of Status #5 */ - wdi.pio0.data_B |= wdi.hd[wdi.unit].status.write_prot << 4; - break; - case 6: - wdi.pio0.data_B = wdi.hd[wdi.unit].status.cav & 0xff; - break; - case 7: - wdi.pio0.data_B = wdi.hd[wdi.unit].status.cav >> 8; - wdi.pio0.data_B |= wdi.hd[wdi.unit].status.uav << 4; - wdi.pio0.data_B |= (wdi.hd[wdi.unit].status.hav & 0x3) << 2; - wdi.pio0.data_B |= (wdi.hd[wdi.unit].status.hav & 0x4) << 5; /* reuse MSB of Unit for Head*/ - break; - default: - break; - } + int bus = wdi.pio1.bus_addr; + BYTE data = wdi.pio0.data_A; + BYTE _head; + WORD _cyl; + + /* Only rezero if online */ + if (wdi.hd[wdi.unit].status.rezeroing && wdi.hd[wdi.unit].online) { + LOGI(TAG, "REZEROING"); + wdi.hd[wdi.unit].status.hav = 0; + wdi.hd[wdi.unit].status.cav = 0; + wdi.hd[wdi.unit].status.rezeroing = 0; + wdi.hd[wdi.unit].status.on_cyl = 1; + wdi.hd[wdi.unit].status.unit_rdy = 1; + } + /* Only seek if online */ + if (wdi.hd[wdi.unit].status.seeking && wdi.hd[wdi.unit].online) { + LOGI(TAG, "SEEKING: UNIT: %02x, HEAD: %02x, CYL: %03x", + wdi.hd[wdi.unit].command.uas, wdi.hd[wdi.unit].command.has, + wdi.hd[wdi.unit].command.cas); + wdi.hd[wdi.unit].status.uav = wdi.hd[wdi.unit].command.uas; + wdi.hd[wdi.unit].status.hav = wdi.hd[wdi.unit].command.has; + wdi.hd[wdi.unit].status.cav = wdi.hd[wdi.unit].command.cas; + wdi.hd[wdi.unit].status.seeking = 0; + wdi.hd[wdi.unit].status.on_cyl = 1; + wdi.hd[wdi.unit].status.unit_rdy = 1; + } + + switch (bus) { + case 0: + /* only 3 LSB of Unit */ + wdi.unit = (data >> 4) & 0x07; + /* reuse MSB of Unit for Head */ + _head = ((data & 0x0c) >> 2) | ((data & 0x80) >> 5); + _cyl = (wdi.hd[wdi.unit].command.cas & 0xff) | ((data & 0x03) << 8); + + if ((wdi.unit >= WDI_UNITS)) { + LOGE(TAG, "DISK COMMAND 0 - ILLEGAL UNIT: %02x", wdi.unit); + wdi.hd[wdi.unit].online = 0; + wdi.hd[wdi.unit].command.uas = wdi.unit; + wdi.hd[wdi.unit].status.illegal_address = 1; + wdi.hd[wdi.unit].status.unit_rdy = 0; + wdi.hd[wdi.unit]._fault = 0; + } else if (!wdi.hd[wdi.unit].online) { + LOGW(TAG, "DISK COMMAND 0 - UNIT: %02x - OFFLINE", wdi.unit); + wdi.hd[wdi.unit].command.uas = wdi.unit; + wdi.hd[wdi.unit].status.illegal_address = 1; + wdi.hd[wdi.unit].status.unit_rdy = 0; + wdi.hd[wdi.unit]._fault = 0; + } else if (_head >= disk_param[wdi.hd[wdi.unit].type].heads) { + LOGE(TAG, "DISK COMMAND 0 - ILLEGAL HEAD: %02x", _head); + wdi.hd[wdi.unit].command.uas = wdi.unit; + wdi.hd[wdi.unit].status.uav = wdi.unit; + wdi.hd[wdi.unit].status.illegal_address = 1; + wdi.hd[wdi.unit].status.unit_rdy = 0; + wdi.hd[wdi.unit]._fault = 0; + /* + * Illegal cylinder should only be checked on COMMAND 1 when a full + * cylinder address is received (COMMAND 0 followed by COMMAND 1) + * otherwise there can be a false negative (illegal address) + */ + } else { + wdi.hd[wdi.unit].command.uas = wdi.unit; + wdi.hd[wdi.unit].command.has = _head; + wdi.hd[wdi.unit].command.cas = _cyl; + wdi.hd[wdi.unit].status.seeking = 1; + wdi.hd[wdi.unit].status.on_cyl = 0; + wdi.hd[wdi.unit].status.unit_rdy = 0; + wdi.hd[wdi.unit].status.illegal_address = 0; + + LOGI(TAG, "DISK COMMAND 0 - UNIT: %02x, HEAD: %02x, CYL: %03x", + wdi.hd[wdi.unit].command.uas, wdi.hd[wdi.unit].command.has, + wdi.hd[wdi.unit].command.cas); + } + break; + case 1: + _cyl = (wdi.hd[wdi.unit].command.cas & 0xf00) | data; + + if (_cyl >= disk_param[wdi.hd[wdi.unit].type].cyl) { + LOGE(TAG, "DISK COMMAND 1 - ILLEGAL CYLINDER: %03x", _cyl); + wdi.hd[wdi.unit].status.illegal_address = 1; + wdi.hd[wdi.unit].status.unit_rdy = 0; + wdi.hd[wdi.unit]._fault = 0; + } else { + wdi.hd[wdi.unit].command.cas = _cyl; + wdi.hd[wdi.unit].status.cav = wdi.hd[wdi.unit].command.cas; + wdi.hd[wdi.unit].status.seeking = 1; + wdi.hd[wdi.unit].status.on_cyl = 0; + wdi.hd[wdi.unit].status.unit_rdy = 0; + + LOGI(TAG, "DISK COMMAND 1 - CYL: %03x", wdi.hd[wdi.unit].status.cav); + } + break; + case 2: + if (data & 0xfc) { + LOGE(TAG, "DISK COMMAND 2 - %d NOT IMPLEMENTED - %02x", bus, data); + } + break; + case 3: + if (data & 1) { + LOGI(TAG, "DISK COMMAND 3 - FAULT CLEAR "); + wdi.hd[wdi.unit]._fault = 1; /* CLEAR FAULT */ + } + if (data & 2) { + LOGI(TAG, "DISK COMMAND 3 - REZERO"); + + wdi.hd[wdi.unit].status.rezeroing = 1; + wdi.hd[wdi.unit].status.on_cyl = 0; + wdi.hd[wdi.unit].status.unit_rdy = 0; + wdi.hd[wdi.unit]._fault = 1; /* CLEAR FAULT */ + } + break; + case 4: + wdi.pio0.data_B = wdi.hd[wdi.unit].status.unit_rdy; + wdi.pio0.data_B |= wdi.hd[wdi.unit].status.on_cyl << 1; + wdi.pio0.data_B |= wdi.hd[wdi.unit].status.seeking << 2; + wdi.pio0.data_B |= wdi.hd[wdi.unit].status.rezeroing << 3; + wdi.pio0.data_B |= wdi.hd[wdi.unit].status.illegal_address << 6; + break; + case 5: + /* Inverse of _fault */ + wdi.pio0.data_B = !(wdi.hd[wdi.unit]._fault); + /* Drive type in unused bits 5 & 6 of Status #5 */ + wdi.pio0.data_B |= wdi.hd[wdi.unit].type << 5; + wdi.pio0.data_B |= wdi.hd[wdi.unit].status.write_prot << 4; + break; + case 6: + wdi.pio0.data_B = wdi.hd[wdi.unit].status.cav & 0xff; + break; + case 7: + wdi.pio0.data_B = wdi.hd[wdi.unit].status.cav >> 8; + wdi.pio0.data_B |= wdi.hd[wdi.unit].status.uav << 4; + wdi.pio0.data_B |= (wdi.hd[wdi.unit].status.hav & 0x3) << 2; + /* reuse MSB of Unit for Head*/ + wdi.pio0.data_B |= (wdi.hd[wdi.unit].status.hav & 0x4) << 5; + break; + default: + break; + } } + void cromemco_wdi_pio0a_data_out(BYTE data) { - int bus = wdi.pio1.bus_addr; + int bus = wdi.pio1.bus_addr; LOGD(TAG, "E0 OUT: %02x - bus:%d", data, bus); - wdi.pio0.data_A = data; + wdi.pio0.data_A = data; - if (bus == 2) { - wdi.hd[wdi.unit].command.write_gate = data & 1; - wdi.hd[wdi.unit].command.read_gate = data & 2; - } + if (bus == 2) { + wdi.hd[wdi.unit].command.write_gate = data & 1; + wdi.hd[wdi.unit].command.read_gate = data & 2; + } } + void cromemco_wdi_pio0b_data_out(BYTE data) { LOGD(TAG, "E1 OUT: %02x", data); - wdi.pio0.data_B = data; + wdi.pio0.data_B = data; - if (data) LOGE(TAG, "Extended Address non-zero [%02x]", data); + if (data) + LOGE(TAG, "Extended Address non-zero [%02x]", data); } + void cromemco_wdi_pio0a_cmd_out(BYTE data) { LOGW(TAG, "E2 OUT: %02x", data); } + void cromemco_wdi_pio0b_cmd_out(BYTE data) { LOGW(TAG, "E3 OUT: %02x", data); } + void cromemco_wdi_pio1a_data_out(BYTE data) { LOGD(TAG, "E4 OUT: %02x", data); - wdi.pio1.data_A = data; - wdi.pio1.dsk_id = data & 0x10; - wdi.pio1.brd = wdi.pio1.dsk_id << 2; - wdi.pio1._cmd_stb = data & 0x08; - wdi.pio1._cmd_sel1 = data & 0x04; - wdi.pio1._cmd_sel0 = data & 0x02; - wdi.pio1.cmd__r_w = data & 0x01; - - wdi.pio1.bus_addr = (wdi.pio1.cmd__r_w << 2) | (wdi.pio1._cmd_sel1 >> 1) | (wdi.pio1._cmd_sel0 >> 1); + wdi.pio1.data_A = data; + wdi.pio1.dsk_id = data & 0x10; + wdi.pio1.brd = wdi.pio1.dsk_id << 2; + wdi.pio1._cmd_stb = data & 0x08; + wdi.pio1._cmd_sel1 = data & 0x04; + wdi.pio1._cmd_sel0 = data & 0x02; + wdi.pio1.cmd__r_w = data & 0x01; + + wdi.pio1.bus_addr = (wdi.pio1.cmd__r_w << 2) | (wdi.pio1._cmd_sel1 >> 1) | + (wdi.pio1._cmd_sel0 >> 1); LOGD(TAG, "OUT - PIO A : %02x - bus: %d", data, wdi.pio1.bus_addr); - if (wdi.pio1._cmd_stb) { - LOGD(TAG, "PIO A - STROBE: %02x - bus: %d", data, wdi.pio1.bus_addr); + if (wdi.pio1._cmd_stb) { + LOGD(TAG, "PIO A - STROBE: %02x - bus: %d", data, wdi.pio1.bus_addr); - command_bus_strobe(); - } + command_bus_strobe(); + } } + void cromemco_wdi_pio1b_data_out(BYTE data) { LOGD(TAG, "E5 OUT: %02x", data); - wdi.pio1.data_B = data; - wdi.pio1.dma_rdy = data & 0x04; - wdi.pio1._disk_op = data & 0x01; - - LOGD(TAG, "E5 OUT: %02x, DMA RDY: %d, DISK_OP: %d", data, wdi.pio1.dma_rdy, wdi.pio1._disk_op); - - if (wdi.pio1._disk_op) { - /* NOTHING YET IDENTIFIED TO HAPPEN HERE */ - } - - if (wdi.pio1.dma_rdy && wdi.hd[wdi.unit].command.write_gate) { - start_bus_request(BUS_DMA_CONTINUOUS, &wdi_dma_write); - }; - if (wdi.pio1.dma_rdy && wdi.hd[wdi.unit].command.read_gate) { - start_bus_request(BUS_DMA_CONTINUOUS, &wdi_dma_read); - } + wdi.pio1.data_B = data; + wdi.pio1.dma_rdy = data & 0x04; + wdi.pio1._disk_op = data & 0x01; + + LOGD(TAG, "E5 OUT: %02x, DMA RDY: %d, DISK_OP: %d", + data, wdi.pio1.dma_rdy, wdi.pio1._disk_op); + + if (wdi.pio1._disk_op) { + /* NOTHING YET IDENTIFIED TO HAPPEN HERE */ + } + + if (wdi.pio1.dma_rdy && wdi.hd[wdi.unit].command.write_gate) + start_bus_request(BUS_DMA_CONTINUOUS, &wdi_dma_write); + if (wdi.pio1.dma_rdy && wdi.hd[wdi.unit].command.read_gate) + start_bus_request(BUS_DMA_CONTINUOUS, &wdi_dma_read); } + void cromemco_wdi_pio1a_cmd_out(BYTE data) { LOGD(TAG, "E6 OUT: %02x", data); - wdi.pio1.cmd_A = data; - - switch (wdi.pio1.cmd_A_state) - { - case 0: - if (data & 0x0f) { - if ((wdi.pio1.mode_A = data >> 6) == 3) { - wdi.pio1.cmd_A_state = 1; - } else { - // LOGW(TAG, "Unexpected PIO A mode [%02x]", wdi.pio1.mode_A); - } - } else { - // LOGW(TAG, "Unexpected PIO A command [%02x]", data); - } - break; - case 1: - wdi.pio1.cmd_A_state = 0; - wdi.pio1.dir_A = data; - LOGD(TAG, "PIO1_A DIR=[%02x]", data); - - break; - default: - LOGE(TAG, "Unknown PIO A cmd state [%d]", wdi.pio1.cmd_A_state); - break; - } + wdi.pio1.cmd_A = data; + + switch (wdi.pio1.cmd_A_state) { + case 0: + if (data & 0x0f) { + if ((wdi.pio1.mode_A = data >> 6) == 3) + wdi.pio1.cmd_A_state = 1; + else { + // LOGW(TAG, "Unexpected PIO A mode [%02x]", wdi.pio1.mode_A); + } + } else { + // LOGW(TAG, "Unexpected PIO A command [%02x]", data); + } + break; + case 1: + wdi.pio1.cmd_A_state = 0; + wdi.pio1.dir_A = data; + LOGD(TAG, "PIO1_A DIR=[%02x]", data); + + break; + default: + LOGE(TAG, "Unknown PIO A cmd state [%d]", wdi.pio1.cmd_A_state); + break; + } } + void cromemco_wdi_pio1b_cmd_out(BYTE data) { LOGD(TAG, "E7 OUT: %02x", data); - wdi.pio1.cmd_B = data; - - switch (wdi.pio1.cmd_B_state) - { - case 0: - if (data & 0x0f) { - if ((wdi.pio1.mode_B = data >> 6) == 3) { - wdi.pio1.cmd_B_state = 1; - } else { - // LOGW(TAG, "Unexpected PIO B mode [%02x]", wdi.pio1.mode_B); - } - } else { - // LOGW(TAG, "Unexpected PIO B command [%02x]", data); - } - break; - case 1: - wdi.pio1.cmd_B_state = 0; - wdi.pio1.dir_B = data; - LOGD(TAG, "PIO1_B DIR=[%02x]", data); - break; - default: - LOGE(TAG, "Unknown PIO B cmd state [%d]", wdi.pio1.cmd_B_state); - break; - } + wdi.pio1.cmd_B = data; + + switch (wdi.pio1.cmd_B_state) { + case 0: + if (data & 0x0f) { + if ((wdi.pio1.mode_B = data >> 6) == 3) + wdi.pio1.cmd_B_state = 1; + else { + // LOGW(TAG, "Unexpected PIO B mode [%02x]", wdi.pio1.mode_B); + } + } else { + // LOGW(TAG, "Unexpected PIO B command [%02x]", data); + } + break; + case 1: + wdi.pio1.cmd_B_state = 0; + wdi.pio1.dir_B = data; + LOGD(TAG, "PIO1_B DIR=[%02x]", data); + break; + default: + LOGE(TAG, "Unknown PIO B cmd state [%d]", wdi.pio1.cmd_B_state); + break; + } } + static Tstates_t wdi_dma_mem_to_mem(BYTE bus_ack) { - register int v; - int i; + register int v; + int i; - if (!bus_ack) return 0; + if (!bus_ack) + return 0; - for (i = 0; i <= wdi.dma.wr0.len; i++) { - v = dma_read(wdi.dma.wr0.a_addr_counter++); - dma_write(wdi.dma.wr4.b_addr_counter++, v); - } - return wdi.dma.wr0.len * 6; /* 6 t-states (3 read + 3 write) for each byte */ + for (i = 0; i <= wdi.dma.wr0.len; i++) { + v = dma_read(wdi.dma.wr0.a_addr_counter++); + dma_write(wdi.dma.wr4.b_addr_counter++, v); + } + return wdi.dma.wr0.len * 6; /* 6 t-states (3 read + 3 write) for each byte */ } + void cromemco_wdi_dma0_out(BYTE data) { - const char *cmd; + const char *cmd; - cmd = ""; + cmd = ""; LOGD(TAG, "E8 OUT: %02x", data); - switch (wdi.dma.wr_state) - { - case WR_BASE: - - if (data & 0x80) { /* WR4 - WR6 */ - - if ((data & 0x03) == 1) { /* WR4 */ - wdi.dma.wr4.base = data; - if (wdi.dma.wr4.base & 0x1C) { - wdi.dma.wr_state = WR4; - } - } else if ((data & 0x03) == 2) { /* WR5 */ - wdi.dma.wr5.base = data; - LOGD(TAG, "WR5 = %02x", data); - } else if ((data & 0x03) == 3) { /* WR6 */ - wdi.dma.wr6.base = data; - - switch (data) - { - case 0x83: - cmd = "DISABLE DMA"; - wdi.dma.enable_dma = 0; - break; - case 0x87: - cmd = "ENABLE DMA"; - wdi.dma.enable_dma = 1; - - if (wdi.dma.force_ready - && wdi.dma.wr0.dest - && (wdi.dma.wr0.mode == 3) /* TRANSFER/SEARCH */ - && (wdi.dma.wr1.a_device == MREQ)) { - - LOGD(TAG, "DMA: MEMORY-TO-MEMORY from: %04x to: %04x length: %04x", - wdi.dma.wr0.a_addr_counter, - wdi.dma.wr4.b_addr_counter, - wdi.dma.wr0.len - ); - - start_bus_request(BUS_DMA_CONTINUOUS, &wdi_dma_mem_to_mem); - - } else if (!wdi.dma.force_ready - && !wdi.dma.wr0.dest - && (wdi.dma.wr0.mode == 2) /* SEARCH */ - && (wdi.dma.wr1.a_device == MREQ)) { - - LOGD(TAG, "DMA: R/W-TO/FROM-DISK addr: %04x length: %04x", - wdi.dma.wr4.b_addr_counter, - wdi.dma.wr0.len - ); - LOGD(TAG, "UNIT: %d, HEAD: %d, CYL: %d", wdi.hd[wdi.unit].status.uav, wdi.hd[wdi.unit].status.hav, wdi.hd[wdi.unit].status.cav); - - } else { - LOGE(TAG, "DMA FUNCTION NOT IMPLEMENTED"); - LOGE(TAG, "FORCE_READY = %02x", wdi.dma.force_ready); - LOGE(TAG, "DEVICE = %02x", wdi.dma.wr1.a_device); - LOGE(TAG, "MODE = %02x", wdi.dma.wr0.mode); - LOGE(TAG, "DEST = %02x", wdi.dma.wr0.dest); - } - break; - case 0xB3: - cmd = "FORCE READY"; - wdi.dma.force_ready = 1; - break; - case 0xC3: - cmd = "RESET"; - wdi.dma.enable_dma = 0; - wdi.dma.force_ready = 0; - wdi.dma.wr1.a_timing = 0; - wdi.dma.wr2.b_timing = 0; - break; - case 0xcf: - cmd = "LOAD"; - wdi.dma.wr0.a_addr_counter = wdi.dma.wr0.a_start; - wdi.dma.wr4.b_addr_counter = wdi.dma.wr4.b_start; - wdi.dma.wr0.byte_counter = 0; - wdi.dma.force_ready = 0; - break; - default: - cmd = "NOT IMPLEMENTED"; - break; - } - LOGD(TAG, "DMA WR6 = %02x - %s", data, cmd); - } else { - LOGE(TAG, "DMA WR [%02x] NOT IMPLEMENTED", data); - } - } else { /* WR0 - WR3 */ - - if (data & 0x03) { /* WR0 */ - wdi.dma.wr0.base = data; - wdi.dma.wr0.dest = data & 0x04; - wdi.dma.wr0.mode = data & 0x03; - - LOGD(TAG, "DMA WR0: source %c, mode %d", wdi.dma.wr0.dest?'A':'B', wdi.dma.wr0.mode); - - if (wdi.dma.wr0.base & 0x78) { - wdi.dma.wr_state = WR0; - } - } else { /* WR1 - WR3 */ - - if ((data & 0x07) == 4) { /* WR1 */ - wdi.dma.wr1.base = data; - wdi.dma.wr1.a_device = (dma_dev_t) ((data & 0x08) >> 3); - wdi.dma.wr1.a_fixed = (data & 0x30) >> 4; - if (wdi.dma.wr1.base & 0x40) { - wdi.dma.wr_state = WR1; - } - LOGD(TAG, "DMA WR1: Port A: inc. mode %d, dev %c", wdi.dma.wr1.a_device, wdi.dma.wr1.a_device?'I':'M'); - } else if ((data & 0x07) == 0) { /* WR2 */ - wdi.dma.wr2.base = data; - wdi.dma.wr2.b_device = (dma_dev_t) ((data & 0x08) >> 3); - wdi.dma.wr2.b_fixed = (data & 0x30) >> 4; - if (wdi.dma.wr2.base & 0x40) { - wdi.dma.wr_state = WR2; - } - LOGD(TAG, "DMA WR2: Port B: inc. mode %d, dev %c", wdi.dma.wr1.a_device, wdi.dma.wr1.a_device?'I':'M'); - } else { - - LOGE(TAG, "WR [%02x] NOT IMPLEMENTED", data); - } - } - } - break; - case WR0: - if (wdi.dma.wr0.base & 0x08) { - wdi.dma.wr0.a_start = (wdi.dma.wr0.a_start & 0xff00) | data; - wdi.dma.wr0.base &= ~0x08; - } else if (wdi.dma.wr0.base & 0x10) { - wdi.dma.wr0.a_start = (wdi.dma.wr0.a_start & 0xff) | (data << 8); - wdi.dma.wr0.base &= ~0x10; - } else if (wdi.dma.wr0.base & 0x20) { - wdi.dma.wr0.len = (wdi.dma.wr0.len & 0xff00) | data; - wdi.dma.wr0.base &= ~0x20; - } else if (wdi.dma.wr0.base & 0x40) { - wdi.dma.wr0.len = (wdi.dma.wr0.len & 0xff) | (data << 8); - wdi.dma.wr0.base &= ~0x40; - } - - if (!(wdi.dma.wr0.base & 0x78)) { - wdi.dma.wr_state = WR_BASE; - LOGD(TAG, "DMA WR0 [%02x] A start: %04x len: %02x", wdi.dma.wr0.base, wdi.dma.wr0.a_start, wdi.dma.wr0.len); - } - break; - case WR1: - wdi.dma.wr1.a_timing = data; - wdi.dma.wr_state = WR_BASE; - LOGD(TAG, "DMA WR1 [%02x] A timing: %02x", wdi.dma.wr1.base, wdi.dma.wr1.a_timing); - break; - case WR2: - wdi.dma.wr2.b_timing = data; - wdi.dma.wr_state = WR_BASE; - LOGD(TAG, "DMA WR2 [%02x] B timing: %02x", wdi.dma.wr2.base, wdi.dma.wr2.b_timing); - break; - case WR4: - if (wdi.dma.wr4.base & 0x04) { - wdi.dma.wr4.b_start = (wdi.dma.wr4.b_start & 0xff00) | data; - wdi.dma.wr4.base &= ~0x04; - } else if (wdi.dma.wr4.base & 0x08) { - wdi.dma.wr4.b_start = (wdi.dma.wr4.b_start & 0xff) | (data << 8); - wdi.dma.wr4.base &= ~0x08; - } else if (wdi.dma.wr4.base & 0x10) { - wdi.dma.wr4.intr_control = data; - wdi.dma.wr4.base &= ~0x10; - } - - if (!(wdi.dma.wr4.base & 0x1C)) { - wdi.dma.wr_state = WR_BASE; - LOGD(TAG, "DMA WR4 [%02x] B start: %04x int: %02x", wdi.dma.wr4.base, wdi.dma.wr4.b_start, wdi.dma.wr4.intr_control); - } - break; - default: - LOGE(TAG, "DMA WR STATE [%d] NOT IMPLEMENTED", wdi.dma.wr_state); - break; - } + switch (wdi.dma.wr_state) { + case WR_BASE: + if (data & 0x80) { /* WR4 - WR6 */ + if ((data & 0x03) == 1) { /* WR4 */ + wdi.dma.wr4.base = data; + if (wdi.dma.wr4.base & 0x1C) + wdi.dma.wr_state = WR4; + } else if ((data & 0x03) == 2) { /* WR5 */ + wdi.dma.wr5.base = data; + LOGD(TAG, "WR5 = %02x", data); + } else if ((data & 0x03) == 3) { /* WR6 */ + wdi.dma.wr6.base = data; + + switch (data) { + case 0x83: + cmd = "DISABLE DMA"; + wdi.dma.enable_dma = 0; + break; + case 0x87: + cmd = "ENABLE DMA"; + wdi.dma.enable_dma = 1; + + if (wdi.dma.force_ready + && wdi.dma.wr0.dest + && (wdi.dma.wr0.mode == 3) /* TRANSFER/SEARCH */ + && (wdi.dma.wr1.a_device == MREQ)) { + LOGD(TAG, "DMA: MEMORY-TO-MEMORY from: " + "%04x to: %04x length: %04x", + wdi.dma.wr0.a_addr_counter, + wdi.dma.wr4.b_addr_counter, + wdi.dma.wr0.len); + + start_bus_request(BUS_DMA_CONTINUOUS, + &wdi_dma_mem_to_mem); + } else if (!wdi.dma.force_ready + && !wdi.dma.wr0.dest + && (wdi.dma.wr0.mode == 2) /* SEARCH */ + && (wdi.dma.wr1.a_device == MREQ)) { + LOGD(TAG, "DMA: R/W-TO/FROM-DISK addr: " + "%04x length: %04x", + wdi.dma.wr4.b_addr_counter, + wdi.dma.wr0.len); + LOGD(TAG, "UNIT: %d, HEAD: %d, CYL: %d", + wdi.hd[wdi.unit].status.uav, + wdi.hd[wdi.unit].status.hav, + wdi.hd[wdi.unit].status.cav); + } else { + LOGE(TAG, "DMA FUNCTION NOT IMPLEMENTED"); + LOGE(TAG, "FORCE_READY = %02x", + wdi.dma.force_ready); + LOGE(TAG, "DEVICE = %02x", wdi.dma.wr1.a_device); + LOGE(TAG, "MODE = %02x", wdi.dma.wr0.mode); + LOGE(TAG, "DEST = %02x", wdi.dma.wr0.dest); + } + break; + case 0xB3: + cmd = "FORCE READY"; + wdi.dma.force_ready = 1; + break; + case 0xC3: + cmd = "RESET"; + wdi.dma.enable_dma = 0; + wdi.dma.force_ready = 0; + wdi.dma.wr1.a_timing = 0; + wdi.dma.wr2.b_timing = 0; + break; + case 0xCF: + cmd = "LOAD"; + wdi.dma.wr0.a_addr_counter = wdi.dma.wr0.a_start; + wdi.dma.wr4.b_addr_counter = wdi.dma.wr4.b_start; + wdi.dma.wr0.byte_counter = 0; + wdi.dma.force_ready = 0; + break; + default: + cmd = "NOT IMPLEMENTED"; + break; + } + LOGD(TAG, "DMA WR6 = %02x - %s", data, cmd); + } else { + LOGE(TAG, "DMA WR [%02x] NOT IMPLEMENTED", data); + } + } else { /* WR0 - WR3 */ + if (data & 0x03) { /* WR0 */ + wdi.dma.wr0.base = data; + wdi.dma.wr0.dest = data & 0x04; + wdi.dma.wr0.mode = data & 0x03; + + LOGD(TAG, "DMA WR0: source %c, mode %d", + wdi.dma.wr0.dest ? 'A' : 'B', wdi.dma.wr0.mode); + + if (wdi.dma.wr0.base & 0x78) + wdi.dma.wr_state = WR0; + } else { /* WR1 - WR3 */ + if ((data & 0x07) == 4) { /* WR1 */ + wdi.dma.wr1.base = data; + wdi.dma.wr1.a_device = (dma_dev_t) ((data & 0x08) >> 3); + wdi.dma.wr1.a_fixed = (data & 0x30) >> 4; + if (wdi.dma.wr1.base & 0x40) + wdi.dma.wr_state = WR1; + LOGD(TAG, "DMA WR1: Port A: inc. mode %d, dev %c", + wdi.dma.wr1.a_device, + wdi.dma.wr1.a_device ? 'I' : 'M'); + } else if ((data & 0x07) == 0) { /* WR2 */ + wdi.dma.wr2.base = data; + wdi.dma.wr2.b_device = (dma_dev_t) ((data & 0x08) >> 3); + wdi.dma.wr2.b_fixed = (data & 0x30) >> 4; + if (wdi.dma.wr2.base & 0x40) + wdi.dma.wr_state = WR2; + LOGD(TAG, "DMA WR2: Port B: inc. mode %d, dev %c", + wdi.dma.wr1.a_device, + wdi.dma.wr1.a_device ? 'I' : 'M'); + } else { + LOGE(TAG, "WR [%02x] NOT IMPLEMENTED", data); + } + } + } + break; + case WR0: + if (wdi.dma.wr0.base & 0x08) { + wdi.dma.wr0.a_start = (wdi.dma.wr0.a_start & 0xff00) | data; + wdi.dma.wr0.base &= ~0x08; + } else if (wdi.dma.wr0.base & 0x10) { + wdi.dma.wr0.a_start = (wdi.dma.wr0.a_start & 0xff) | (data << 8); + wdi.dma.wr0.base &= ~0x10; + } else if (wdi.dma.wr0.base & 0x20) { + wdi.dma.wr0.len = (wdi.dma.wr0.len & 0xff00) | data; + wdi.dma.wr0.base &= ~0x20; + } else if (wdi.dma.wr0.base & 0x40) { + wdi.dma.wr0.len = (wdi.dma.wr0.len & 0xff) | (data << 8); + wdi.dma.wr0.base &= ~0x40; + } + + if (!(wdi.dma.wr0.base & 0x78)) { + wdi.dma.wr_state = WR_BASE; + LOGD(TAG, "DMA WR0 [%02x] A start: %04x len: %02x", + wdi.dma.wr0.base, wdi.dma.wr0.a_start, wdi.dma.wr0.len); + } + break; + case WR1: + wdi.dma.wr1.a_timing = data; + wdi.dma.wr_state = WR_BASE; + LOGD(TAG, "DMA WR1 [%02x] A timing: %02x", wdi.dma.wr1.base, wdi.dma.wr1.a_timing); + break; + case WR2: + wdi.dma.wr2.b_timing = data; + wdi.dma.wr_state = WR_BASE; + LOGD(TAG, "DMA WR2 [%02x] B timing: %02x", wdi.dma.wr2.base, wdi.dma.wr2.b_timing); + break; + case WR4: + if (wdi.dma.wr4.base & 0x04) { + wdi.dma.wr4.b_start = (wdi.dma.wr4.b_start & 0xff00) | data; + wdi.dma.wr4.base &= ~0x04; + } else if (wdi.dma.wr4.base & 0x08) { + wdi.dma.wr4.b_start = (wdi.dma.wr4.b_start & 0xff) | (data << 8); + wdi.dma.wr4.base &= ~0x08; + } else if (wdi.dma.wr4.base & 0x10) { + wdi.dma.wr4.intr_control = data; + wdi.dma.wr4.base &= ~0x10; + } + + if (!(wdi.dma.wr4.base & 0x1C)) { + wdi.dma.wr_state = WR_BASE; + LOGD(TAG, "DMA WR4 [%02x] B start: %04x int: %02x", + wdi.dma.wr4.base, wdi.dma.wr4.b_start, wdi.dma.wr4.intr_control); + } + break; + default: + LOGE(TAG, "DMA WR STATE [%d] NOT IMPLEMENTED", wdi.dma.wr_state); + break; + } } void cromemco_wdi_dma1_out(BYTE data) { LOGW(TAG, "E9 OUT: %02x", data); } + void cromemco_wdi_dma2_out(BYTE data) { LOGW(TAG, "EA OUT: %02x", data); } + void cromemco_wdi_dma3_out(BYTE data) { LOGW(TAG, "EB OUT: %02x", data); } + void cromemco_wdi_ctc0_out(BYTE data) { LOGD(TAG, "OUT: CTC #0 - %02x", data); - switch (wdi.ctc.state0) - { - case 0: - wdi.ctc.mode0 = data; - - if (data & 0x80 ) LOGE(TAG, "CTC #0 - INT set"); - if (!(data & 0x40)) LOGE(TAG, "CTC #0 - TIMER set"); - if (data & 0x04 ) wdi.ctc.state0 = 1; - if (data & 0x02 ) wdi.ctc.now0 = 0; - if (!(data & 0x01)) LOGE(TAG, "CTC #0 - not CONTROL"); - break; - case 1: - if (wdi.ctc.mode0 & 0x40) LOGD(TAG, "CTC #0 - COUNTER set to %02x", data); - wdi.ctc.state0 = 0; - wdi.ctc.time0 = data; - wdi.ctc.now0 = data; - wdi.ctc.T0 = T; - break; - default: - LOGE(TAG, "CTC #0 - unknown state %d", wdi.ctc.state0); - break; - } + switch (wdi.ctc.state0) { + case 0: + wdi.ctc.mode0 = data; + + if (data & 0x80) + LOGE(TAG, "CTC #0 - INT set"); + if (!(data & 0x40)) + LOGE(TAG, "CTC #0 - TIMER set"); + if (data & 0x04) + wdi.ctc.state0 = 1; + if (data & 0x02) + wdi.ctc.now0 = 0; + if (!(data & 0x01)) + LOGE(TAG, "CTC #0 - not CONTROL"); + break; + case 1: + if (wdi.ctc.mode0 & 0x40) + LOGD(TAG, "CTC #0 - COUNTER set to %02x", data); + wdi.ctc.state0 = 0; + wdi.ctc.time0 = data; + wdi.ctc.now0 = data; + wdi.ctc.T0 = T; + break; + default: + LOGE(TAG, "CTC #0 - unknown state %d", wdi.ctc.state0); + break; + } } + void cromemco_wdi_ctc1_out(BYTE data) { - LOGD(TAG, "OUT: CTC #1 - %02x", data); - - switch (wdi.ctc.state1) - { - case 0: - wdi.ctc.mode1 = data; - - if (data & 0x80 ) LOGE(TAG, "CTC #1 - INT set"); - - if (!(data & 0x40)) { - LOGD(TAG, "CTC #1 - TIMER set"); - } else { - LOGD(TAG, "CTC #1 - COUNTER set"); - } - - if (data & 0x04 ) wdi.ctc.state1 = 1; - if (data & 0x02 ) wdi.ctc.now1 = 0; - if (!(data & 0x01)) LOGE(TAG, "CTC #1 - not CONTROL"); - break; - case 1: - wdi.ctc.state1 = 0; - wdi.ctc.time1 = data; - wdi.ctc.now1 = data; - wdi.ctc.T1 = T; - - if (wdi.ctc.mode1 & 0x40) { - LOGD(TAG, "CTC #1 - COUNTER set to %02x", data); - LOGI(TAG, "COUNT %d SECTOR PULSES", data - 1); - } else { - LOGD(TAG, "CTC #1 - TIMER set to %02x", data); - } - - break; - default: - LOGE(TAG, "CTC #1 - unknown state %d", wdi.ctc.state0); - break; - } + LOGD(TAG, "OUT: CTC #1 - %02x", data); + + switch (wdi.ctc.state1) { + case 0: + wdi.ctc.mode1 = data; + + if (data & 0x80) + LOGE(TAG, "CTC #1 - INT set"); + + if (!(data & 0x40)) { + LOGD(TAG, "CTC #1 - TIMER set"); + } else { + LOGD(TAG, "CTC #1 - COUNTER set"); + } + + if (data & 0x04) + wdi.ctc.state1 = 1; + if (data & 0x02) + wdi.ctc.now1 = 0; + if (!(data & 0x01)) + LOGE(TAG, "CTC #1 - not CONTROL"); + break; + case 1: + wdi.ctc.state1 = 0; + wdi.ctc.time1 = data; + wdi.ctc.now1 = data; + wdi.ctc.T1 = T; + + if (wdi.ctc.mode1 & 0x40) { + LOGD(TAG, "CTC #1 - COUNTER set to %02x", data); + LOGI(TAG, "COUNT %d SECTOR PULSES", data - 1); + } else { + LOGD(TAG, "CTC #1 - TIMER set to %02x", data); + } + + break; + default: + LOGE(TAG, "CTC #1 - unknown state %d", wdi.ctc.state0); + break; + } } + void cromemco_wdi_ctc2_out(BYTE data) { LOGD(TAG, "OUT: CTC #2 - %02x", data); - switch (wdi.ctc.state2) - { - case 0: - wdi.ctc.mode2 = data; - - if (data & 0x80 ) LOGE(TAG, "CTC #2 - INT set"); - if (!(data & 0x40)) LOGE(TAG, "CTC #2 - TIMER set"); - if (data & 0x04 ) wdi.ctc.state2 = 1; - if (data & 0x02 ) wdi.ctc.now2 = 0; - if (!(data & 0x01)) LOGE(TAG, "CTC #2 - not CONTROL"); - break; - case 1: - wdi.ctc.state2 = 0; - wdi.ctc.time2 = data; - wdi.ctc.now2 = data; - wdi.ctc.T2 = T; - break; - default: - LOGE(TAG, "CTC #2 - unknown state %d", wdi.ctc.state2); - break; - } + switch (wdi.ctc.state2) { + case 0: + wdi.ctc.mode2 = data; + + if (data & 0x80) + LOGE(TAG, "CTC #2 - INT set"); + if (!(data & 0x40)) + LOGE(TAG, "CTC #2 - TIMER set"); + if (data & 0x04) + wdi.ctc.state2 = 1; + if (data & 0x02) + wdi.ctc.now2 = 0; + if (!(data & 0x01)) + LOGE(TAG, "CTC #2 - not CONTROL"); + break; + case 1: + wdi.ctc.state2 = 0; + wdi.ctc.time2 = data; + wdi.ctc.now2 = data; + wdi.ctc.T2 = T; + break; + default: + LOGE(TAG, "CTC #2 - unknown state %d", wdi.ctc.state2); + break; + } } + void cromemco_wdi_ctc3_out(BYTE data) { LOGW(TAG, "EF OUT: %02x", data); diff --git a/iodevices/diskmanager.c b/iodevices/diskmanager.c index 85c3afb4..dbd42b41 100644 --- a/iodevices/diskmanager.c +++ b/iodevices/diskmanager.c @@ -10,34 +10,34 @@ /** * This diskmanager module provides an alternate interface for the array * - * char *disks[]; + * char *disks[]; * * that is typically implemented in a disk controller simulators e.g. - * - imsai-fif.c - * - tarbell_fdc.c + * - imsai-fif.c + * - tarbell_fdc.c * * It persists the array in a file, typically "disk.map" [DISKMAP] in the * provided path. * * The "disk.map" file is a simple text file with a line for each disk * starting at 'A' up to [LAST_DISK], typically 'D'. - * - If a line is empty of starts with '#' the disk is "ejected" - * - If a disk image is "inserted" the line contains only the file name + * - If a line is empty of starts with '#' the disk is "ejected" + * - If a disk image is "inserted" the line contains only the file name * * The diskmanager provides functions to: - * - populate the array from the file - * - write the array to the file - * - insert a disk - * - stat() disk image files to validate them before inserting - * - reject inserting the same disk image in 2 disk drives - * - eject a disk - * - and some other support functions. + * - populate the array from the file + * - write the array to the file + * - insert a disk + * - stat() disk image files to validate them before inserting + * - reject inserting the same disk image in 2 disk drives + * - eject a disk + * - and some other support functions. * * TODO: - * - fully support paths to allow a disk library hierarchy - * - support more complex disk arrays that contain structures e.g. - * * cpmsim::iosim.c - * * cromemco-fdc.c + * - fully support paths to allow a disk library hierarchy + * - support more complex disk arrays that contain structures e.g. + * * cpmsim::iosim.c + * * cromemco-fdc.c */ #include @@ -60,371 +60,376 @@ #include "log.h" static const char *TAG = "diskmanager"; -static char path[MAX_LFN+1]; /* path/filename for disk image */ +static char path[MAX_LFN + 1]; /* path/filename for disk image */ static char *file_start; + #define APPENDTOPATH(file) strncpy(file_start, file, MAX_LFN - strlen(path)); -enum disk_err { - SUCCESS, - INVALID_DISK_NUM, - DRIVE_EMPTY, - DRIVE_NOT_EMPTY, - IMAGE_ALREADY_INSERTED, - IMAGE_NOT_VALID, - FAILURE -}; - -typedef enum disk_err disk_err_t; - -static disk_err_t insertDisk(int disk, const char *image) { - - char *name; - struct stat image_status; - int i; - - if (disk >= 0 && disk < _MAX_DISK) { - - if (DISKNAME(disk) != NULL) { - return DRIVE_NOT_EMPTY; - } - - if (image != NULL && strlen(image) < MAX_LFN) { - - for (i = 0; i < _MAX_DISK; i++) { - if (DISKNAME(i) != NULL && strcmp(image, DISKNAME(i)) == 0) { - return IMAGE_ALREADY_INSERTED; - } - } - - APPENDTOPATH(image); - - if (stat(path, &image_status) == 0) { - if (S_ISREG(image_status.st_mode)) { - name = strndup(image, MAX_LFN); - if (name == NULL) { - LOGW(TAG, "Failed to insert disk, not enough memory."); - return FAILURE; - } else { - /* Everything is OK, we can insert the disk */ - DISKNAME(disk) = name; - return SUCCESS; - } - } else { - return IMAGE_NOT_VALID; - } - } else { - LOGW(TAG, "Failed to stat disk image: %s, error: %d", image, errno); - return IMAGE_NOT_VALID; - } - } - - return IMAGE_NOT_VALID; - } - - return INVALID_DISK_NUM; +typedef enum disk_err { + SUCCESS, + INVALID_DISK_NUM, + DRIVE_EMPTY, + DRIVE_NOT_EMPTY, + IMAGE_ALREADY_INSERTED, + IMAGE_NOT_VALID, + FAILURE +} disk_err_t; + +static disk_err_t insertDisk(int disk, const char *image) +{ + char *name; + struct stat image_status; + int i; + + if (disk >= 0 && disk < _MAX_DISK) { + if (DISKNAME(disk) != NULL) + return DRIVE_NOT_EMPTY; + + if (image != NULL && strlen(image) < MAX_LFN) { + for (i = 0; i < _MAX_DISK; i++) { + if (DISKNAME(i) != NULL && strcmp(image, DISKNAME(i)) == 0) + return IMAGE_ALREADY_INSERTED; + } + + APPENDTOPATH(image); + + if (stat(path, &image_status) == 0) { + if (S_ISREG(image_status.st_mode)) { + name = strndup(image, MAX_LFN); + if (name == NULL) { + LOGW(TAG, "Failed to insert disk, " + "not enough memory."); + return FAILURE; + } else { + /* Everything is OK, we can insert the disk */ + DISKNAME(disk) = name; + return SUCCESS; + } + } else + return IMAGE_NOT_VALID; + } else { + LOGW(TAG, "Failed to stat disk image: %s, error: %d", + image, errno); + return IMAGE_NOT_VALID; + } + } + + return IMAGE_NOT_VALID; + } + + return INVALID_DISK_NUM; } -static void writeDiskmap(void) { - FILE *map; - int i; +static void writeDiskmap(void) +{ + FILE *map; + int i; - if (*path == '\0') { - LOGW(TAG, "Path to disk map not set. Call readDiskmap(path) first."); - return; - } + if (*path == '\0') { + LOGW(TAG, "Path to disk map not set. Call readDiskmap(path) first."); + return; + } - APPENDTOPATH(DISKMAP); + APPENDTOPATH(DISKMAP); - map = fopen(path, "w"); - if (map == NULL) { - LOGW(TAG, "Can't create disk map: %s", path); - return; - } + map = fopen(path, "w"); + if (map == NULL) { + LOGW(TAG, "Can't create disk map: %s", path); + return; + } - for (i = 0; i < _MAX_DISK; i++) { - fprintf(map, "%s\n", DISKNAME(i)==NULL?"#":DISKNAME(i)); - } - fclose(map); + for (i = 0; i < _MAX_DISK; i++) + fprintf(map, "%s\n", DISKNAME(i) == NULL ? "#" : DISKNAME(i)); + fclose(map); } -void readDiskmap(char *path_name) { - FILE *map; - char *line = NULL; - char *name; - size_t len; - ssize_t res; - int i; - disk_err_t insert; +void readDiskmap(char *path_name) +{ + FILE *map; + char *line = NULL; + char *name; + size_t len; + ssize_t res; + int i; + disk_err_t insert; - for (i = 0; i < _MAX_DISK; i++) { - DISKNAME(i) = NULL; - } + for (i = 0; i < _MAX_DISK; i++) + DISKNAME(i) = NULL; - strncpy(path, path_name, MAX_LFN); - strncat(path, "/", MAX_LFN - strlen(path)); - file_start = path + strlen(path); + strncpy(path, path_name, MAX_LFN); + strncat(path, "/", MAX_LFN - strlen(path)); + file_start = path + strlen(path); - APPENDTOPATH(DISKMAP); - LOGD(TAG, "LIB: path: %s, diskmap: %s", path, file_start); + APPENDTOPATH(DISKMAP); + LOGD(TAG, "LIB: path: %s, diskmap: %s", path, file_start); - i = 0; + i = 0; again: - map = fopen(path, "r"); - if (map == NULL) { - if (i++ == 0) { - LOGW(TAG, "No disk map: %s, attempting to create file.", path); - writeDiskmap(); - goto again; - } - return; - } - - LOG(TAG, "DISK MAP: [%s]\r\n", path); - - for (i = 0; i < _MAX_DISK; i++) { - line = NULL; - res = getline(&line, &len, map); - - if (res != -1) { - if (line[res-1] == '\n') - line[res-1] = '\0'; - - /* empty lines or lines that begin with # are empty disks */ - name = ((line[0]=='\0') || (line[0]=='#'))?NULL:line; - if (name != NULL) { - insert = insertDisk(i, name); - - switch (insert) { - case SUCCESS : - LOG(TAG, "%c:DSK:='%s'\r\n", i+'A', DISKNAME(i)); - break; - case IMAGE_ALREADY_INSERTED : - LOGW(TAG, "%c:DSK: Image file '%s' already in use", i+'A', name); - break; - case IMAGE_NOT_VALID : - LOGW(TAG, "%c:DSK: Image file '%s' is invalid", i+'A', name); - break; - default: - LOGW(TAG, "%c:DSK: Failed to insert disk, error: %d", i+'A', insert); - break; - } - } - } - free(line); - } - fclose(map); + map = fopen(path, "r"); + if (map == NULL) { + if (i++ == 0) { + LOGW(TAG, "No disk map: %s, attempting to create file.", path); + writeDiskmap(); + goto again; + } + return; + } + + LOG(TAG, "DISK MAP: [%s]\r\n", path); + + for (i = 0; i < _MAX_DISK; i++) { + line = NULL; + res = getline(&line, &len, map); + + if (res != -1) { + if (line[res - 1] == '\n') + line[res - 1] = '\0'; + + /* empty lines or lines that begin with # are empty disks */ + name = ((line[0] == '\0') || (line[0] == '#')) ? NULL : line; + if (name != NULL) { + insert = insertDisk(i, name); + + switch (insert) { + case SUCCESS : + LOG(TAG, "%c:DSK:='%s'\r\n", i + 'A', DISKNAME(i)); + break; + case IMAGE_ALREADY_INSERTED : + LOGW(TAG, "%c:DSK: Image file '%s' already in use", + i + 'A', name); + break; + case IMAGE_NOT_VALID : + LOGW(TAG, "%c:DSK: Image file '%s' is invalid", + i + 'A', name); + break; + default: + LOGW(TAG, "%c:DSK: Failed to insert disk, error: %d", + i + 'A', insert); + break; + } + } + } + free(line); + } + fclose(map); } #ifdef HAS_NETSERVER -static int findDiskImage(const char *image) { - int i; - - for (i = 0; i < _MAX_DISK; i++) { - if (DISKNAME(i) != NULL) { - if (strcmp(image, DISKNAME(i)) == 0) { - return 1; - } - } - } - return 0; -} +static int findDiskImage(const char *image) +{ + int i; -static int getDiskNumByID(const char *id) { - int disk = -1; - - /* id is in the form X:DSK: making it 6 characters long */ - LOGD(TAG, "GET ID: %s, %ld", id, strlen(id)); - if (id != NULL && strlen(id) == 6 && strcmp(id+1, ":DSK:") == 0) { - disk = *id - 'A'; - if (disk < 0 || disk > (_MAX_DISK - 1)) { - LOGW(TAG, "BAD DISK ID: %c", *id); - disk = -1; - } - } else { - LOGW(TAG, "DISK ID required, got: %s", id); - disk = -1; - } - return disk; + for (i = 0; i < _MAX_DISK; i++) { + if (DISKNAME(i) != NULL) { + if (strcmp(image, DISKNAME(i)) == 0) + return 1; + } + } + return 0; } -static disk_err_t ejectDisk(int disk) { - - char *name; +static int getDiskNumByID(const char *id) +{ + int disk = -1; + + /* id is in the form X:DSK: making it 6 characters long */ + LOGD(TAG, "GET ID: %s, %ld", id, strlen(id)); + if (id != NULL && strlen(id) == 6 && strcmp(id + 1, ":DSK:") == 0) { + disk = *id - 'A'; + if (disk < 0 || disk > (_MAX_DISK - 1)) { + LOGW(TAG, "BAD DISK ID: %c", *id); + disk = -1; + } + } else { + LOGW(TAG, "DISK ID required, got: %s", id); + disk = -1; + } + return disk; +} - if (disk >= 0 || disk < _MAX_DISK) { +static disk_err_t ejectDisk(int disk) +{ + char *name; - if (DISKNAME(disk) == NULL) { - return DRIVE_EMPTY; - } + if (disk >= 0 || disk < _MAX_DISK) { + if (DISKNAME(disk) == NULL) + return DRIVE_EMPTY; - name = DISKNAME(disk); - DISKNAME(disk) = NULL; - free(name); + name = DISKNAME(disk); + DISKNAME(disk) = NULL; + free(name); - return SUCCESS; - } + return SUCCESS; + } - return INVALID_DISK_NUM; + return INVALID_DISK_NUM; } /** * Web Server handlers for LIB: and X:DSK: * */ -int LibraryHandler(HttpdConnection_t *conn, void *unused) { - request_t *req = get_request(conn); +int LibraryHandler(HttpdConnection_t *conn, void *unused) +{ + request_t *req = get_request(conn); int i = 0; - UNUSED(unused); - - if (*path == '\0') { - LOGW(TAG, "Path to disk map not set. Call readDiskmap(path) first."); - return 0; - } - - *file_start = '\0'; - - switch (req->method) { - case HTTP_GET: - DirectoryHandler(conn, path); - break; - case HTTP_PUT: - UploadHandler(conn, path); - LOGI(TAG, "PUT image: image uploaded."); - break; - case HTTP_DELETE: - if (req->len > 0) { - i = mg_read(conn, file_start, MAX_LFN - strlen(path)); - *(file_start + i) = '\0'; - - LOGD(TAG, "DELETE image: %s, length: %lld", file_start, req->len); - - if (findDiskImage(file_start)) { - LOGW(TAG, "DELETE image: %s, currently inserted in disks", file_start); - httpdStartResponse(conn, 404); /* http error code 'Not Found' */ - httpdEndHeaders(conn); - return 1; - } - - if (unlink(path) < 0) { - LOGW(TAG, "DELETE image: %s, unlink failed [%d]", path, errno); - httpdStartResponse(conn, 410); /* http error code 'Gone' */ - httpdEndHeaders(conn); - } else { - LOGI(TAG, "DELETE image: %s, deleted.", path); - httpdStartResponse(conn, 200); - httpdEndHeaders(conn); - httpdPrintf(conn, "Deleted"); - }; - } - break; - default: - httpdStartResponse(conn, 405); /* http error code 'Method Not Allowed' */ - httpdEndHeaders(conn); - break; - } + UNUSED(unused); + + if (*path == '\0') { + LOGW(TAG, "Path to disk map not set. Call readDiskmap(path) first."); + return 0; + } + + *file_start = '\0'; + + switch (req->method) { + case HTTP_GET: + DirectoryHandler(conn, path); + break; + case HTTP_PUT: + UploadHandler(conn, path); + LOGI(TAG, "PUT image: image uploaded."); + break; + case HTTP_DELETE: + if (req->len > 0) { + i = mg_read(conn, file_start, MAX_LFN - strlen(path)); + *(file_start + i) = '\0'; + + LOGD(TAG, "DELETE image: %s, length: %lld", file_start, req->len); + + if (findDiskImage(file_start)) { + LOGW(TAG, "DELETE image: %s, currently inserted in disks", + file_start); + httpdStartResponse(conn, 404); /* http error code 'Not Found' */ + httpdEndHeaders(conn); + return 1; + } + + if (unlink(path) < 0) { + LOGW(TAG, "DELETE image: %s, unlink failed [%d]", path, errno); + httpdStartResponse(conn, 410); /* http error code 'Gone' */ + httpdEndHeaders(conn); + } else { + LOGI(TAG, "DELETE image: %s, deleted.", path); + httpdStartResponse(conn, 200); + httpdEndHeaders(conn); + httpdPrintf(conn, "Deleted"); + }; + } + break; + default: + httpdStartResponse(conn, 405); /* http error code 'Method Not Allowed' */ + httpdEndHeaders(conn); + break; + } return 1; } -static void sendDisks(HttpdConnection_t *conn) { - - int i; +static void sendDisks(HttpdConnection_t *conn) +{ + int i; - httpdStartResponse(conn, 200); - httpdHeader(conn, "Content-Type", "application/json"); - httpdEndHeaders(conn); + httpdStartResponse(conn, 200); + httpdHeader(conn, "Content-Type", "application/json"); + httpdEndHeaders(conn); - httpdPrintf(conn, "{"); + httpdPrintf(conn, "{"); - for (i = 0; i < _MAX_DISK; i++) { - httpdPrintf(conn, "\"%c\": \"%s\"", i+'A', DISKNAME(i)==NULL?"":DISKNAME(i)); - if (i < (_MAX_DISK - 1)) httpdPrintf(conn, ","); - } + for (i = 0; i < _MAX_DISK; i++) { + httpdPrintf(conn, "\"%c\": \"%s\"", i + 'A', + DISKNAME(i) == NULL ? "" : DISKNAME(i)); + if (i < (_MAX_DISK - 1)) + httpdPrintf(conn, ","); + } - sendHardDisks(conn); + sendHardDisks(conn); - httpdPrintf(conn, "}"); + httpdPrintf(conn, "}"); } -int DiskHandler(HttpdConnection_t *conn, void *unused) { - request_t *req = get_request(conn); - int disk, i; - char image[MAX_LFN]; - disk_err_t result; - UNUSED(unused); - - switch (req->method) { - case HTTP_GET: - LOGD(TAG, "GET /disks"); - sendDisks(conn); - break; - case HTTP_PUT: - LOGD(TAG, "PUT /disks: %s", req->args[0]); - - disk = getDiskNumByID(req->args[0]); - image[0] = '\0'; - - if (req->len > 0) { - i = mg_read(conn, image, MAX_LFN); - image[i] = '\0'; - }; - - LOGD(TAG, "PUT image length: %d [%s]", (int) req->len, image); - - result = insertDisk(disk, image); - - switch (result) { - case SUCCESS : - writeDiskmap(); - sendDisks(conn); - break; - case DRIVE_NOT_EMPTY : - LOGW(TAG, "PUT /disks NOT EMPTY"); - httpdStartResponse(conn, 404); /* http error code 'Not Found' */ - httpdEndHeaders(conn); - break; - case IMAGE_ALREADY_INSERTED : - LOGW(TAG, "PUT image: %s, already inserted in disks", image); - httpdStartResponse(conn, 404); /* http error code 'Not Found' */ - httpdEndHeaders(conn); - break; - default: - LOGW(TAG, "PUT image: %s, failed to insert disk: %d, error: %d", image, disk, result); - httpdStartResponse(conn, 404); /* http error code 'Not Found' */ - httpdEndHeaders(conn); - break; - } - break; - case HTTP_DELETE: - LOGD(TAG, "DELETE /disks: %s", req->args[0]); - - disk = getDiskNumByID(req->args[0]); - result = ejectDisk(disk); - - switch (result) { - case SUCCESS : - sendDisks(conn); - writeDiskmap(); - break; - case DRIVE_EMPTY : - LOGW(TAG, "DELETE /disks ALREADY EMPTY"); - httpdStartResponse(conn, 404); /* http error code 'Not Found' */ - httpdEndHeaders(conn); - break; - default: - LOGW(TAG, "DELETE /disks failed to eject disk: %d, error: %d", disk, result); - httpdStartResponse(conn, 404); /* http error code 'Not Found' */ - httpdEndHeaders(conn); - break; - } - break; - default: - httpdStartResponse(conn, 405); /* http error code 'Method Not Allowed' */ - httpdEndHeaders(conn); - break; +int DiskHandler(HttpdConnection_t *conn, void *unused) +{ + request_t *req = get_request(conn); + int disk, i; + char image[MAX_LFN]; + disk_err_t result; + UNUSED(unused); + + switch (req->method) { + case HTTP_GET: + LOGD(TAG, "GET /disks"); + sendDisks(conn); + break; + case HTTP_PUT: + LOGD(TAG, "PUT /disks: %s", req->args[0]); + + disk = getDiskNumByID(req->args[0]); + image[0] = '\0'; + + if (req->len > 0) { + i = mg_read(conn, image, MAX_LFN); + image[i] = '\0'; + }; + + LOGD(TAG, "PUT image length: %d [%s]", (int) req->len, image); + + result = insertDisk(disk, image); + + switch (result) { + case SUCCESS: + writeDiskmap(); + sendDisks(conn); + break; + case DRIVE_NOT_EMPTY: + LOGW(TAG, "PUT /disks NOT EMPTY"); + httpdStartResponse(conn, 404); /* http error code 'Not Found' */ + httpdEndHeaders(conn); + break; + case IMAGE_ALREADY_INSERTED: + LOGW(TAG, "PUT image: %s, already inserted in disks", image); + httpdStartResponse(conn, 404); /* http error code 'Not Found' */ + httpdEndHeaders(conn); + break; + default: + LOGW(TAG, "PUT image: %s, failed to insert disk: %d, error: %d", + image, disk, result); + httpdStartResponse(conn, 404); /* http error code 'Not Found' */ + httpdEndHeaders(conn); + break; + } + break; + case HTTP_DELETE: + LOGD(TAG, "DELETE /disks: %s", req->args[0]); + + disk = getDiskNumByID(req->args[0]); + result = ejectDisk(disk); + + switch (result) { + case SUCCESS: + sendDisks(conn); + writeDiskmap(); + break; + case DRIVE_EMPTY: + LOGW(TAG, "DELETE /disks ALREADY EMPTY"); + httpdStartResponse(conn, 404); /* http error code 'Not Found' */ + httpdEndHeaders(conn); + break; + default: + LOGW(TAG, "DELETE /disks failed to eject disk: %d, error: %d", + disk, result); + httpdStartResponse(conn, 404); /* http error code 'Not Found' */ + httpdEndHeaders(conn); + break; + } + break; + default: + httpdStartResponse(conn, 405); /* http error code 'Method Not Allowed' */ + httpdEndHeaders(conn); + break; } - return 1; + return 1; } -#endif +#endif /* HAS_NETSERVER */ diff --git a/iodevices/generic-at-modem.c b/iodevices/generic-at-modem.c index 931e3401..969fbc41 100644 --- a/iodevices/generic-at-modem.c +++ b/iodevices/generic-at-modem.c @@ -38,65 +38,66 @@ #define LOG_LOCAL_LEVEL LOG_WARN #include "log.h" -static const char* TAG = "at-modem"; - -#define MODEM_ID "'AT' Modem" - -#define BASE_DECIMAL 10 - -#define AT_BUF_LEN 81 -#define DEFAULT_LISTENER_PORT 8023 -#define _QUOTE(arg) #arg -#define STR_VALUE(arg) _QUOTE(arg) - -#define SREG_AA 0 -#define SREG_RINGS 1 -#define SREG_ESCAPE 2 -#define SREG_CR 3 -#define SREG_LF 4 -#define SREG_BS 5 -#define SREG_HUP_DELAY 10 -#define SREG_OPT 13 -#define SREG_PORT 14 -#define SREG_TELNET 15 -#define SREG_TN_SGA 16 -#define SREG_TN_ECHO 17 -#define SREG_TN_BIN 18 -#define SREG_TN_NAWS 19 -#define SREG_COLS 20 -#define SREG_ROWS 21 -#define SREG_TN_TTYPE 22 -#define SREG_FLOW_CTRL 39 -#define MAX_REG_NUM 50 +static const char *TAG = "at-modem"; + +#define MODEM_ID "'AT' Modem" + +#define BASE_DECIMAL 10 + +#define AT_BUF_LEN 81 +#define DEFAULT_LISTENER_PORT 8023 + +#define _QUOTE(arg) #arg +#define STR_VALUE(arg) _QUOTE(arg) + +#define SREG_AA 0 +#define SREG_RINGS 1 +#define SREG_ESCAPE 2 +#define SREG_CR 3 +#define SREG_LF 4 +#define SREG_BS 5 +#define SREG_HUP_DELAY 10 +#define SREG_OPT 13 +#define SREG_PORT 14 +#define SREG_TELNET 15 +#define SREG_TN_SGA 16 +#define SREG_TN_ECHO 17 +#define SREG_TN_BIN 18 +#define SREG_TN_NAWS 19 +#define SREG_COLS 20 +#define SREG_ROWS 21 +#define SREG_TN_TTYPE 22 +#define SREG_FLOW_CTRL 39 +#define MAX_REG_NUM 50 #define SREG_DEFAULTS { \ - /* SREG_AA */ 0, \ - /* SREG_RINGS */ 0, \ - /* SREG_ESCAPE */ 43, \ - /* SREG_CR */ 13, \ - /* SREG_LF */ 10, \ - /* SREG_BS */ 8, \ - 0, 0, 0, 0, \ - /* SREG_HUP_DELAY */ 14, \ - 0, 0, \ - /* SREG_OPT */ 1, \ - /* SREG_PORT */ DEFAULT_LISTENER_PORT, \ - /* SREG_TELNET */ 0, \ - /* SREG_TN_SGA */ 3, \ - /* SREG_TN_ECHO */ 3, \ - /* SREG_TN_BIN */ 0, \ - /* SREG_TN_NAWS */ 3, \ - /* SREG_COLS */ 80, \ - /* SREG_ROWS */ 24, \ - /* SREG_TN_TTYPE */ 3, \ - 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, 0, 0, 0, 0, 0, \ - 0, 0, 0, \ -}; - -#define OPT_ECHO 0x1 -#define OPT_QUIET 0x2 + /* SREG_AA */ 0, \ + /* SREG_RINGS */ 0, \ + /* SREG_ESCAPE */ 43, \ + /* SREG_CR */ 13, \ + /* SREG_LF */ 10, \ + /* SREG_BS */ 8, \ + 0, 0, 0, 0, \ + /* SREG_HUP_DELAY */ 14, \ + 0, 0, \ + /* SREG_OPT */ 1, \ + /* SREG_PORT */ DEFAULT_LISTENER_PORT, \ + /* SREG_TELNET */ 0, \ + /* SREG_TN_SGA */ 3, \ + /* SREG_TN_ECHO */ 3, \ + /* SREG_TN_BIN */ 0, \ + /* SREG_TN_NAWS */ 3, \ + /* SREG_COLS */ 80, \ + /* SREG_ROWS */ 24, \ + /* SREG_TN_TTYPE */ 3, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, \ + }; + +#define OPT_ECHO 0x1 +#define OPT_QUIET 0x2 static bool daemon_f = false; @@ -117,380 +118,379 @@ static telnet_telopt_t telnet_opts[10]; static int carrier_detect; -static void init_telnet_opts(void) { - - int i=0; - - telnet_opts[i].telopt = TELNET_TELOPT_SGA; - telnet_opts[i].us = (s_reg[SREG_TN_SGA] & 1)? TELNET_WILL : TELNET_WONT; - telnet_opts[i].him = (s_reg[SREG_TN_SGA] & 2)? TELNET_DO : TELNET_DONT; - i++; - telnet_opts[i].telopt = TELNET_TELOPT_ECHO; - telnet_opts[i].us = (s_reg[SREG_TN_ECHO] & 1)? TELNET_WILL : TELNET_WONT; - telnet_opts[i].him = (s_reg[SREG_TN_ECHO] & 2)? TELNET_DO : TELNET_DONT; - i++; - telnet_opts[i].telopt = TELNET_TELOPT_BINARY; - telnet_opts[i].us = (s_reg[SREG_TN_BIN] & 1)? TELNET_WILL : TELNET_WONT; - telnet_opts[i].him = (s_reg[SREG_TN_BIN] & 2)? TELNET_DO : TELNET_DONT; - i++; - telnet_opts[i].telopt = TELNET_TELOPT_NAWS; - telnet_opts[i].us = (s_reg[SREG_TN_NAWS] & 1)? TELNET_WILL : TELNET_WONT; - telnet_opts[i].him = (s_reg[SREG_TN_NAWS] & 2)? TELNET_DO : TELNET_DONT; - i++; - telnet_opts[i].telopt = TELNET_TELOPT_TTYPE; - telnet_opts[i].us = (s_reg[SREG_TN_TTYPE] & 1)? TELNET_WILL : TELNET_WONT; - telnet_opts[i].him = (s_reg[SREG_TN_TTYPE] & 2)? TELNET_DO : TELNET_DONT; - i++; - telnet_opts[i].telopt = -1; - telnet_opts[i].us = 0; - telnet_opts[i].him = 0; +static void init_telnet_opts(void) +{ + int i = 0; + + telnet_opts[i].telopt = TELNET_TELOPT_SGA; + telnet_opts[i].us = (s_reg[SREG_TN_SGA] & 1) ? TELNET_WILL : TELNET_WONT; + telnet_opts[i].him = (s_reg[SREG_TN_SGA] & 2) ? TELNET_DO : TELNET_DONT; + i++; + telnet_opts[i].telopt = TELNET_TELOPT_ECHO; + telnet_opts[i].us = (s_reg[SREG_TN_ECHO] & 1) ? TELNET_WILL : TELNET_WONT; + telnet_opts[i].him = (s_reg[SREG_TN_ECHO] & 2) ? TELNET_DO : TELNET_DONT; + i++; + telnet_opts[i].telopt = TELNET_TELOPT_BINARY; + telnet_opts[i].us = (s_reg[SREG_TN_BIN] & 1) ? TELNET_WILL : TELNET_WONT; + telnet_opts[i].him = (s_reg[SREG_TN_BIN] & 2) ? TELNET_DO : TELNET_DONT; + i++; + telnet_opts[i].telopt = TELNET_TELOPT_NAWS; + telnet_opts[i].us = (s_reg[SREG_TN_NAWS] & 1) ? TELNET_WILL : TELNET_WONT; + telnet_opts[i].him = (s_reg[SREG_TN_NAWS] & 2) ? TELNET_DO : TELNET_DONT; + i++; + telnet_opts[i].telopt = TELNET_TELOPT_TTYPE; + telnet_opts[i].us = (s_reg[SREG_TN_TTYPE] & 1) ? TELNET_WILL : TELNET_WONT; + telnet_opts[i].him = (s_reg[SREG_TN_TTYPE] & 2) ? TELNET_DO : TELNET_DONT; + i++; + telnet_opts[i].telopt = -1; + telnet_opts[i].us = 0; + telnet_opts[i].him = 0; } -#define TELNET_TTYPE "ansi" +#define TELNET_TTYPE "ansi" static telnet_t *telnet = NULL; static unsigned char tn_recv; static int tn_len = 0; -static void telnet_hdlr(telnet_t *telnet, telnet_event_t *ev, void *user_data) { +static void telnet_hdlr(telnet_t *telnet, telnet_event_t *ev, void *user_data) +{ + char buf[81]; + char *p; + int i; - char buf[81]; - char * p; - int i; + UNUSED(user_data); - UNUSED(user_data); - - switch (ev->type) { - case TELNET_EV_DATA: + switch (ev->type) { + case TELNET_EV_DATA: if (ev->data.size) { - if (ev->data.size != 1) { - LOGW(TAG, "LONGER THAN EXPECTED [%zd]", ev->data.size); - } else { - tn_recv = *(ev->data.buffer); - tn_len = ev->data.size; - } - LOGD(TAG, "Telnet IN: %c[%zd]", tn_recv, ev->data.size); + if (ev->data.size != 1) { + LOGW(TAG, "LONGER THAN EXPECTED [%zd]", ev->data.size); + } else { + tn_recv = *(ev->data.buffer); + tn_len = ev->data.size; + } + LOGD(TAG, "Telnet IN: %c[%zd]", tn_recv, ev->data.size); } break; - case TELNET_EV_SEND: + case TELNET_EV_SEND: if (ev->data.size) { - p = buf; - for(i=0;i<(int)ev->data.size;i++) { - p += sprintf (p, "%d ", *(ev->data.buffer+i)); - } - LOGD(TAG, "Telnet OUT: %s[%zd]", buf, ev->data.size); + p = buf; + for (i = 0; i < (int) ev->data.size; i++) + p += sprintf(p, "%d ", *(ev->data.buffer + i)); + LOGD(TAG, "Telnet OUT: %s[%zd]", buf, ev->data.size); } if (write(*active_sfd, ev->data.buffer, ev->data.size) != (ssize_t) ev->data.size) LOGE(TAG, "Telnet OUT: can't send data"); break; - case TELNET_EV_WILL: - if (ev->neg.telopt == TELNET_TELOPT_SGA) { - LOGI(TAG, "Telnet WILL SGA"); - } else if (ev->neg.telopt == TELNET_TELOPT_ECHO) { - LOGI(TAG, "Telnet WILL ECHO"); - } else if (ev->neg.telopt == TELNET_TELOPT_BINARY) { - LOGI(TAG, "Telnet WILL BINARY"); - } else { - LOGW(TAG, "Telnet WILL unknown opt: %d", ev->neg.telopt); - } + case TELNET_EV_WILL: + if (ev->neg.telopt == TELNET_TELOPT_SGA) { + LOGI(TAG, "Telnet WILL SGA"); + } else if (ev->neg.telopt == TELNET_TELOPT_ECHO) { + LOGI(TAG, "Telnet WILL ECHO"); + } else if (ev->neg.telopt == TELNET_TELOPT_BINARY) { + LOGI(TAG, "Telnet WILL BINARY"); + } else { + LOGW(TAG, "Telnet WILL unknown opt: %d", ev->neg.telopt); + } + break; + case TELNET_EV_DO: + if (ev->neg.telopt == TELNET_TELOPT_SGA) { + LOGI(TAG, "Telnet DO SGA"); + } else if (ev->neg.telopt == TELNET_TELOPT_ECHO) { + LOGI(TAG, "Telnet DO ECHO"); + } else if (ev->neg.telopt == TELNET_TELOPT_BINARY) { + LOGI(TAG, "Telnet DO BINARY"); + } else if (ev->neg.telopt == TELNET_TELOPT_TTYPE) { + LOGI(TAG, "Telnet DO TTYPE"); + } else if (ev->neg.telopt == TELNET_TELOPT_NAWS) { + telnet_begin_sb(telnet, TELNET_TELOPT_NAWS); + buf[0] = 0; + buf[1] = s_reg[SREG_COLS]; + buf[2] = 0; + buf[3] = s_reg[SREG_ROWS]; + telnet_send(telnet, buf, 4); + telnet_finish_sb(telnet); + LOGI(TAG, "Telnet DO NAWS [%d x %d]", + (buf[0] << 8) + buf[1], (buf[2] << 8) + buf[3]); + } else { + LOGW(TAG, "Telnet DO unknown opt: %d", ev->neg.telopt); + } break; - case TELNET_EV_DO: - if (ev->neg.telopt == TELNET_TELOPT_SGA) { - LOGI(TAG, "Telnet DO SGA"); - } else if (ev->neg.telopt == TELNET_TELOPT_ECHO) { - LOGI(TAG, "Telnet DO ECHO"); - } else if (ev->neg.telopt == TELNET_TELOPT_BINARY) { - LOGI(TAG, "Telnet DO BINARY"); - } else if (ev->neg.telopt == TELNET_TELOPT_TTYPE) { - LOGI(TAG, "Telnet DO TTYPE"); - } else if (ev->neg.telopt == TELNET_TELOPT_NAWS) { - telnet_begin_sb(telnet, TELNET_TELOPT_NAWS); - buf[0] = 0; - buf[1] = s_reg[SREG_COLS]; - buf[2] = 0; - buf[3] = s_reg[SREG_ROWS]; - telnet_send(telnet, buf, 4); - telnet_finish_sb(telnet); - LOGI(TAG, "Telnet DO NAWS [%d x %d]", (buf[0]<<8) + buf[1], (buf[2]<<8) + buf[3]); - } else { - LOGW(TAG, "Telnet DO unknown opt: %d", ev->neg.telopt); - } - break; - case TELNET_EV_SUBNEGOTIATION: + case TELNET_EV_SUBNEGOTIATION: LOGI(TAG, "SUBNEGOTIATION [%d]", ev->sub.telopt); - break; - case TELNET_EV_TTYPE: + break; + case TELNET_EV_TTYPE: LOGI(TAG, "TTYPE negotiation cmd:%d", ev->ttype.cmd); - const char *ttype; - if (((ttype = getenv("TERM")) == NULL) || (s_reg[SREG_TN_TTYPE] & 4)) { - ttype = TELNET_TTYPE; - } - if (ev->ttype.cmd == TELNET_TTYPE_SEND) { - LOGI(TAG, "TTYPE SEND : %s", ttype); - telnet_ttype_is(telnet, ttype); - } else if (ev->ttype.cmd == TELNET_TTYPE_IS) { - LOGI(TAG, "TTYPE IS : %s", ev->ttype.name); - } - break; - case TELNET_EV_ERROR: + const char *ttype; + if (((ttype = getenv("TERM")) == NULL) || (s_reg[SREG_TN_TTYPE] & 4)) + ttype = TELNET_TTYPE; + if (ev->ttype.cmd == TELNET_TTYPE_SEND) { + LOGI(TAG, "TTYPE SEND : %s", ttype); + telnet_ttype_is(telnet, ttype); + } else if (ev->ttype.cmd == TELNET_TTYPE_IS) { + LOGI(TAG, "TTYPE IS : %s", ev->ttype.name); + } + break; + case TELNET_EV_ERROR: LOGE(TAG, "ERROR: %s", ev->error.msg); - break; - default: - LOGW(TAG, "Telnet Event unknown [%d] opt: %d", ev->type, ev->neg.telopt); - break; - } + break; + default: + LOGW(TAG, "Telnet Event unknown [%d] opt: %d", ev->type, ev->neg.telopt); + break; + } } -/****************************************************************************************************************************/ -static void close_socket(void) { - - if (telnet != NULL) { - telnet_free(telnet); - telnet = NULL; - LOGI(TAG, "Telnet session ended"); - } - - if (shutdown(*active_sfd, SHUT_RDWR) == 0) { - LOGI(TAG, "Socket shutdown"); - } - if (close(*active_sfd) == 0) { - LOGI(TAG, "Socket closed"); - *active_sfd = 0; - } - carrier_detect = 0; -} +/*************************************************************************************************/ + +static void close_socket(void) +{ + if (telnet != NULL) { + telnet_free(telnet); + telnet = NULL; + LOGI(TAG, "Telnet session ended"); + } -static int open_socket(void) { - - struct addrinfo hints; - struct addrinfo *result, *rp; - int s; - void *addrptr = NULL; - uint16_t port = 0; - struct sockaddr_in *sktv4 = NULL; - /* struct sockaddr_in6 *sktv6 = NULL; */ - int on = 1; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_INET; /* Allow only IPv4 not IPv6 */ - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = 0; - hints.ai_protocol = 0; /* Any protocol */ - - s = getaddrinfo(addr, port_num, &hints, &result); - if (s != 0) { - LOGI(TAG, "getaddrinfo: %s", "failed"); - return 1; - } - - for (rp = result; rp != NULL; rp = rp->ai_next) { - - LOGD(TAG, "Address: %d", rp->ai_family); - switch (rp->ai_family) { - case AF_INET: - sktv4 = (struct sockaddr_in *)rp->ai_addr; - port = sktv4->sin_port; - addrptr = &sktv4->sin_addr; - break; - case AF_INET6: - /* - sktv6 = (struct sockaddr_in6 *)rp->ai_addr; - port = sktv6->sin6_port; - addrptr = &sktv6->sin6_addr; - */ - LOGE(TAG, "Not expecting IPV6 addresses"); - return 1; - default: - LOGE(TAG, "Not expecting address family type %d", rp->ai_family); - return 1; - } - - inet_ntop(rp->ai_family, addrptr, addr, 100); - LOGI(TAG, "Address: %s:%d", addr, ntohs(port)); - - if ((sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0) { - LOGE(TAG, "Failed to create socket"); - return 1; - }; - - active_sfd = &sfd; - carrier_detect = 1; - LOGI(TAG, "Socket created"); - - if (connect(sfd, rp->ai_addr, sizeof(struct sockaddr_in)) < 0) { - LOGW(TAG, "Failed to connect to socket: %d", errno); - close_socket(); - return 1; - } - LOGI(TAG, "Socket connected"); - - if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on)) == -1) { - LOGE(TAG, "can't set sockopt TCP_NODELAY"); - close_socket(); - return 1; - } - - /* Initialize Telnet session */ - if (s_reg[SREG_TELNET]) { - init_telnet_opts(); - if ((telnet = telnet_init(telnet_opts, telnet_hdlr, 0, NULL)) == 0) { - LOGE(TAG, "can't initialize telnet session"); - close_socket(); - return 1; - } else { - LOGI(TAG, "Telnet session started"); - }; - }; - - return 0; - } - - return 1; + if (shutdown(*active_sfd, SHUT_RDWR) == 0) { + LOGI(TAG, "Socket shutdown"); + } + if (close(*active_sfd) == 0) { + LOGI(TAG, "Socket closed"); + *active_sfd = 0; + } + carrier_detect = 0; } -static int hangup_timeout(bool start) { - static uint64_t hup_t1, hup_t2; - static int waiting = 0; - int tdiff; - - if (*active_sfd) { - - if (start) { - hup_t1 = get_clock_us(); - waiting = 1; - LOGI(TAG, "Waiting to HUP"); - } else if (waiting) { - hup_t2 = get_clock_us(); - tdiff = (hup_t2 - hup_t1) / 100000; /* scale usec to 10ths of seconds */ - if (tdiff >= (int)(s_reg[SREG_HUP_DELAY])) { /* SREG_HUP_DELAY is in 10ths of seconds */ - waiting = 0; - s_reg[SREG_RINGS] = 0; - close_socket(); - LOGI(TAG, "HUP timeout - closing socket"); - return 1; - } - } - } else { - waiting = 0; - } - return 0; +static int open_socket(void) +{ + struct addrinfo hints; + struct addrinfo *result, *rp; + int s; + void *addrptr = NULL; + uint16_t port = 0; + struct sockaddr_in *sktv4 = NULL; + /* struct sockaddr_in6 *sktv6 = NULL; */ + int on = 1; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_INET; /* Allow only IPv4 not IPv6 */ + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = 0; + hints.ai_protocol = 0; /* Any protocol */ + + s = getaddrinfo(addr, port_num, &hints, &result); + if (s != 0) { + LOGI(TAG, "getaddrinfo: %s", "failed"); + return 1; + } + + for (rp = result; rp != NULL; rp = rp->ai_next) { + LOGD(TAG, "Address: %d", rp->ai_family); + switch (rp->ai_family) { + case AF_INET: + sktv4 = (struct sockaddr_in *)rp->ai_addr; + port = sktv4->sin_port; + addrptr = &sktv4->sin_addr; + break; + case AF_INET6: + /* + sktv6 = (struct sockaddr_in6 *)rp->ai_addr; + port = sktv6->sin6_port; + addrptr = &sktv6->sin6_addr; + */ + LOGE(TAG, "Not expecting IPV6 addresses"); + return 1; + default: + LOGE(TAG, "Not expecting address family type %d", rp->ai_family); + return 1; + } + + inet_ntop(rp->ai_family, addrptr, addr, 100); + LOGI(TAG, "Address: %s:%d", addr, ntohs(port)); + + if ((sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) < 0) { + LOGE(TAG, "Failed to create socket"); + return 1; + }; + + active_sfd = &sfd; + carrier_detect = 1; + LOGI(TAG, "Socket created"); + + if (connect(sfd, rp->ai_addr, sizeof(struct sockaddr_in)) < 0) { + LOGW(TAG, "Failed to connect to socket: %d", errno); + close_socket(); + return 1; + } + LOGI(TAG, "Socket connected"); + + if (setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on)) == -1) { + LOGE(TAG, "can't set sockopt TCP_NODELAY"); + close_socket(); + return 1; + } + + /* Initialize Telnet session */ + if (s_reg[SREG_TELNET]) { + init_telnet_opts(); + if ((telnet = telnet_init(telnet_opts, telnet_hdlr, 0, NULL)) == 0) { + LOGE(TAG, "can't initialize telnet session"); + close_socket(); + return 1; + } else { + LOGI(TAG, "Telnet session started"); + }; + }; + + return 0; + } + + return 1; } -/****************************************************************************************************************************/ - -static int answer_init(void) { - - struct sockaddr_in serv_addr; - int enable = 1; - - if (answer_sfd) { - LOGE(TAG, "Already listening"); - return 1; - } - - if ((answer_sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - LOGE(TAG, "Failed to create Answer socket"); - answer_sfd = 0; - return 1; - }; - if (setsockopt(answer_sfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) { - LOGE(TAG, "Failed to setsockopt Answer socket"); - return 1; - }; - - memset(&serv_addr, 0, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - serv_addr.sin_addr.s_addr = INADDR_ANY; - serv_addr.sin_port = htons(s_reg[SREG_PORT]); - if (bind(answer_sfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { - LOGE(TAG, "ERROR on binding %d %s", errno, strerror(errno)); - return 1; - } - listen(answer_sfd,1); - inet_ntop(AF_INET, &serv_addr.sin_addr, addr, 100); - LOGI(TAG, "Listening on %s:%d", addr, ntohs(serv_addr.sin_port)); - return 0; +static int hangup_timeout(bool start) +{ + static uint64_t hup_t1, hup_t2; + static int waiting = 0; + int tdiff; + + if (*active_sfd) { + if (start) { + hup_t1 = get_clock_us(); + waiting = 1; + LOGI(TAG, "Waiting to HUP"); + } else if (waiting) { + hup_t2 = get_clock_us(); + /* scale usec to 10ths of seconds */ + tdiff = (hup_t2 - hup_t1) / 100000; + /* SREG_HUP_DELAY is in 10ths of seconds */ + if (tdiff >= (int) (s_reg[SREG_HUP_DELAY])) { + waiting = 0; + s_reg[SREG_RINGS] = 0; + close_socket(); + LOGI(TAG, "HUP timeout - closing socket"); + return 1; + } + } + } else + waiting = 0; + return 0; } -static int answer(void) { - - struct sockaddr_in cli_addr; - socklen_t clilen; - int on = 1; - - clilen = sizeof(cli_addr); - newsockfd = accept(answer_sfd, (struct sockaddr *) &cli_addr, &clilen); - if (newsockfd < 0) { - LOGE(TAG, "ERROR on accept"); - return 1; - } - - inet_ntop(AF_INET, &cli_addr.sin_addr, addr, 100); - LOGI(TAG, "New Remote Connection: %s:%d", addr, ntohs(cli_addr.sin_port)); - active_sfd = &newsockfd; - carrier_detect = 1; - - if (setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on)) == -1) { - LOGE(TAG, "can't set sockopt TCP_NODELAY"); - close_socket(); - return 1; - } - - /* Initialize Telnet session */ - if (s_reg[SREG_TELNET]) { - init_telnet_opts(); - if ((telnet = telnet_init(telnet_opts, telnet_hdlr, 0, NULL)) == 0) { - LOGE(TAG, "can't initialize telnet server session"); - close_socket(); - return 1; - } else { - LOGI(TAG, "Telnet server session started"); - }; - telnet_negotiate(telnet, (s_reg[SREG_TN_SGA] & 1) ? TELNET_WILL : TELNET_WONT , TELNET_TELOPT_SGA); - telnet_negotiate(telnet, (s_reg[SREG_TN_ECHO] & 1) ? TELNET_WILL : TELNET_WONT, TELNET_TELOPT_ECHO); - }; - - return 0; +/*************************************************************************************************/ + +static int answer_init(void) +{ + struct sockaddr_in serv_addr; + int enable = 1; + + if (answer_sfd) { + LOGE(TAG, "Already listening"); + return 1; + } + + if ((answer_sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + LOGE(TAG, "Failed to create Answer socket"); + answer_sfd = 0; + return 1; + }; + if (setsockopt(answer_sfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) { + LOGE(TAG, "Failed to setsockopt Answer socket"); + return 1; + }; + + memset(&serv_addr, 0, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + serv_addr.sin_addr.s_addr = INADDR_ANY; + serv_addr.sin_port = htons(s_reg[SREG_PORT]); + if (bind(answer_sfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) { + LOGE(TAG, "ERROR on binding %d %s", errno, strerror(errno)); + return 1; + } + listen(answer_sfd, 1); + inet_ntop(AF_INET, &serv_addr.sin_addr, addr, 100); + LOGI(TAG, "Listening on %s:%d", addr, ntohs(serv_addr.sin_port)); + return 0; } -static int answer_check_ring(void) { +static int answer(void) +{ + struct sockaddr_in cli_addr; + socklen_t clilen; + int on = 1; + + clilen = sizeof(cli_addr); + newsockfd = accept(answer_sfd, (struct sockaddr *) &cli_addr, &clilen); + if (newsockfd < 0) { + LOGE(TAG, "ERROR on accept"); + return 1; + } + + inet_ntop(AF_INET, &cli_addr.sin_addr, addr, 100); + LOGI(TAG, "New Remote Connection: %s:%d", addr, ntohs(cli_addr.sin_port)); + active_sfd = &newsockfd; + carrier_detect = 1; + + if (setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on)) == -1) { + LOGE(TAG, "can't set sockopt TCP_NODELAY"); + close_socket(); + return 1; + } + + /* Initialize Telnet session */ + if (s_reg[SREG_TELNET]) { + init_telnet_opts(); + if ((telnet = telnet_init(telnet_opts, telnet_hdlr, 0, NULL)) == 0) { + LOGE(TAG, "can't initialize telnet server session"); + close_socket(); + return 1; + } else { + LOGI(TAG, "Telnet server session started"); + }; + telnet_negotiate(telnet, (s_reg[SREG_TN_SGA] & 1) ? TELNET_WILL : TELNET_WONT, + TELNET_TELOPT_SGA); + telnet_negotiate(telnet, (s_reg[SREG_TN_ECHO] & 1) ? TELNET_WILL : TELNET_WONT, + TELNET_TELOPT_ECHO); + }; + return 0; +} + +static int answer_check_ring(void) +{ struct pollfd p[1]; - static int ringing = 0; - static uint64_t ring_t1, ring_t2; - int tdiff; - - if (answer_sfd) { - - if (ringing) { - ring_t2 = get_clock_us(); - tdiff = (ring_t2 - ring_t1) / 1000000; - if (tdiff < 3) { - return 0; - } else { - ringing = 0; - } - } - - p[0].fd = answer_sfd; - p[0].events = POLLIN; - p[0].revents = 0; - poll(p, 1, 0); - - if (p[0].revents == POLLIN) { - - if (!ringing) { - ring_t1 = get_clock_us(); - ringing = 1; - LOGI(TAG, "Ringing"); - } - return 1; - } - } - return 0; + static int ringing = 0; + static uint64_t ring_t1, ring_t2; + int tdiff; + + if (answer_sfd) { + if (ringing) { + ring_t2 = get_clock_us(); + tdiff = (ring_t2 - ring_t1) / 1000000; + if (tdiff < 3) + return 0; + else + ringing = 0; + } + + p[0].fd = answer_sfd; + p[0].events = POLLIN; + p[0].revents = 0; + poll(p, 1, 0); + + if (p[0].revents == POLLIN) { + if (!ringing) { + ring_t1 = get_clock_us(); + ringing = 1; + LOGI(TAG, "Ringing"); + } + return 1; + } + } + return 0; } -/****************************************************************************************************************************/ +/*************************************************************************************************/ static char at_buf[AT_BUF_LEN * 2] = ""; static char at_cmd[AT_BUF_LEN] = ""; @@ -498,545 +498,542 @@ static char at_prev[AT_BUF_LEN] = ""; static char at_err[AT_BUF_LEN * 2] = ""; static char *at_out = at_buf; -enum at_states { cmd, A_recv, AT_recv, AS_recv, dat, intr, help }; -typedef enum at_states at_state_t; + +typedef enum at_state { cmd, A_recv, AT_recv, AS_recv, dat, intr, help } at_state_t; static at_state_t at_state = cmd; -#define CR "\r" -#define LF "\n" +#define CR "\r" +#define LF "\n" #define CRLF CR LF -#define END NULL +#define END NULL -#define AT_OK "OK" CRLF -#define AT_ERROR "ERROR" CRLF +#define AT_OK "OK" CRLF +#define AT_ERROR "ERROR" CRLF #define AT_NO_ANSWER "NO ANSWER" CRLF #define AT_NO_CARRIER "NO CARRIER" CRLF #define AT_NO_DIALTONE "NO DIALTONE" CRLF -#define AT_RING "RING" CRLF +#define AT_RING "RING" CRLF static const char *at_help[] = { - LF "AT COMMANDS:" CRLF, - "AT - 'AT' Test ", - "| A/ - (immediate) Repeat last" CRLF, - "AT$ - Help ", - "| ATIn - Information " CRLF, - "ATZ - Reset modem" CRLF, - "AT&F - Restore factory defaults ", + LF "AT COMMANDS:" CRLF, + "AT - 'AT' Test ", + "| A/ - (immediate) Repeat last" CRLF, + "AT$ - Help ", + "| ATIn - Information " CRLF, + "ATZ - Reset modem" CRLF, + "AT&F - Restore factory defaults ", #ifdef MODEM_NVRAM - "| AT&W - Write settings to NVRAM" CRLF, + "| AT&W - Write settings to NVRAM" CRLF, #else - CRLF, + CRLF, #endif - "ATDhostname:port - Dial hostname, port optional (default:" STR_VALUE(DEFAULT_LISTENER_PORT) ")" CRLF, - "+++ - Return to command mode ", - "| ATO - Return Online" CRLF, - "ATH - Hangup" CRLF, - "AT&An - Enable Answer mode - 0=interactive, 1=daemon" CRLF, - "ATA - Answer" CRLF, - "ATSn - Select register n" CRLF, - "AT? - Query current register ", - "| AT=r - Set current register to r" CRLF, - "ATEn - Command Echo 0=off, 1=on ", - "| ATQn - Quiet Results 0=off, 1=on" CRLF, + "ATDhostname:port - Dial hostname, port optional (default:" + STR_VALUE(DEFAULT_LISTENER_PORT) ")" CRLF, + "+++ - Return to command mode ", + "| ATO - Return Online" CRLF, + "ATH - Hangup" CRLF, + "AT&An - Enable Answer mode - 0=interactive, 1=daemon" CRLF, + "ATA - Answer" CRLF, + "ATSn - Select register n" CRLF, + "AT? - Query current register ", + "| AT=r - Set current register to r" CRLF, + "ATEn - Command Echo 0=off, 1=on ", + "| ATQn - Quiet Results 0=off, 1=on" CRLF, #ifdef MODEM_UART - "AT&K0 - Disable flow control ", - "| AT&K1 - Enable RTS/CTS flow control" CRLF, + "AT&K0 - Disable flow control ", + "| AT&K1 - Enable RTS/CTS flow control" CRLF, #endif #ifdef MODEM_WIFI - "AT+W? - Query WiFi AP Join status" CRLF, - "AT+W=ssid,password - Join WiFI AP" CRLF, - "AT+W$ - Show WiFi IP address ", - "| AT+W# - Show WiFi MAC address" CRLF, - "AT+W+ - Reconnect WiFI AP ", - "| AT+W- - Quit WiFi AP" CRLF, - "AT+U? - Query OTA Update ", - "| AT+U=url - Set custom URL for OTA update" CRLF, - "AT+U^ - Upgrade to OTA Update ", - "| AT+U! - Force Upgrade to OTA Update" CRLF, - "AT+U$ - Show OTA Partition Status" CRLF, + "AT+W? - Query WiFi AP Join status" CRLF, + "AT+W=ssid,password - Join WiFI AP" CRLF, + "AT+W$ - Show WiFi IP address ", + "| AT+W# - Show WiFi MAC address" CRLF, + "AT+W+ - Reconnect WiFI AP ", + "| AT+W- - Quit WiFi AP" CRLF, + "AT+U? - Query OTA Update ", + "| AT+U=url - Set custom URL for OTA update" CRLF, + "AT+U^ - Upgrade to OTA Update ", + "| AT+U! - Force Upgrade to OTA Update" CRLF, + "AT+U$ - Show OTA Partition Status" CRLF, #endif #ifdef MODEM_UART - "AT+B? - Query Baud Rate ", - "| AT+B=nnn - Set Baud Rate (4800..115200)" CRLF, + "AT+B? - Query Baud Rate ", + "| AT+B=nnn - Set Baud Rate (4800..115200)" CRLF, #endif - "AT+T? - Query Telnet TERM ", - "| AT+T=name - Set Telnet TERM" CRLF, - END + "AT+T? - Query Telnet TERM ", + "| AT+T=name - Set Telnet TERM" CRLF, + END }; static const char **msg; -static void at_cat_c(char c) { - if (strlen(at_cmd) >= AT_BUF_LEN - 1) { - LOGE(TAG, "Buffer overflow"); - return; - } +static void at_cat_c(char c) +{ + if (strlen(at_cmd) >= AT_BUF_LEN - 1) { + LOGE(TAG, "Buffer overflow"); + return; + } if (c == '\b') { /*TODO: use s_reg[SREG_BS] */ - if(strlen(at_cmd) > 2) { - if (s_reg[SREG_OPT] & OPT_ECHO) { - at_buf[strlen(at_buf) + 3] = 0; - at_buf[strlen(at_buf) + 2] = c; - at_buf[strlen(at_buf) + 1] = ' '; - at_buf[strlen(at_buf)] = c; - } + if (strlen(at_cmd) > 2) { + if (s_reg[SREG_OPT] & OPT_ECHO) { + at_buf[strlen(at_buf) + 3] = 0; + at_buf[strlen(at_buf) + 2] = c; + at_buf[strlen(at_buf) + 1] = ' '; + at_buf[strlen(at_buf)] = c; + } at_cmd[strlen(at_cmd) - 1] = 0; } } else { - if (s_reg[SREG_OPT] & OPT_ECHO) { - at_buf[strlen(at_buf) + 1] = 0; - at_buf[strlen(at_buf)] = c; - } + if (s_reg[SREG_OPT] & OPT_ECHO) { + at_buf[strlen(at_buf) + 1] = 0; + at_buf[strlen(at_buf)] = c; + } at_cmd[strlen(at_cmd) + 1] = 0; at_cmd[strlen(at_cmd)] = c; } LOGD(TAG, "AT CMD: [%s]", at_cmd); } -static void at_cat_s(const char *s) { - if (s_reg[SREG_OPT] & OPT_QUIET) return; - if ((strlen(at_buf) + strlen(s)) >= (AT_BUF_LEN*2) - 1) { - LOGE(TAG, "Buffer overflow"); - return; - } +static void at_cat_s(const char *s) +{ + if (s_reg[SREG_OPT] & OPT_QUIET) + return; + if ((strlen(at_buf) + strlen(s)) >= (AT_BUF_LEN * 2) - 1) { + LOGE(TAG, "Buffer overflow"); + return; + } strcat(at_buf, s); } -static int process_at_cmd(void) { - int tmp_reg; +static int process_at_cmd(void) +{ + int tmp_reg; char *at_ptr = at_cmd; - char *arg_ptr; + char *arg_ptr; + strcpy(at_prev, at_cmd); - if ((*at_ptr++ =='A') && (*at_ptr++ == 'T')) { + if ((*at_ptr++ == 'A') && (*at_ptr++ == 'T')) at_cmd[0] = 0; - } else { + else { at_cmd[0] = 0; strcpy(at_err, LF AT_ERROR CRLF); return 1; } -#define AT_END_CMD (at_ptr = &at_cmd[strlen(at_cmd)]) -#define AT_NEXT_CMD (at_ptr++) -#define AT_NEXT_CMD2 (at_ptr += 2) -#define AT_NEXT_CMD_ARGS (at_ptr = arg_ptr) +#define AT_END_CMD (at_ptr = &at_cmd[strlen(at_cmd)]) +#define AT_NEXT_CMD (at_ptr++) +#define AT_NEXT_CMD2 (at_ptr += 2) +#define AT_NEXT_CMD_ARGS (at_ptr = arg_ptr) - while (*at_ptr != 0) { - LOGD(__func__, "AT CMD: [%s]", at_ptr); - switch (*at_ptr++) { - /*TODO: add a command to check connection status */ + while (*at_ptr != 0) { + LOGD(__func__, "AT CMD: [%s]", at_ptr); + switch (*at_ptr++) { + /*TODO: add a command to check connection status */ case '\r': /* AT */ /*TODO: use s_reg[SREG_CR] */ break; - case 'I': - tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); + case 'I': + tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); - if (tmp_reg == 0) { - strcpy(at_err, LF MODEM_ID CRLF); - at_cat_s(at_err); + if (tmp_reg == 0) { + strcpy(at_err, LF MODEM_ID CRLF); + at_cat_s(at_err); #ifdef MODEM_ESP32 - } else if (tmp_reg == 1) { - const esp_app_desc_t* desc = esp_ota_get_app_description(); - sprintf(at_err, LF "%s" CRLF, desc->version); - at_cat_s(at_err); - } else if (tmp_reg == 2) { - sprintf(at_err, LF "%s" CRLF, esp_get_idf_version()); - at_cat_s(at_err); - } else if (tmp_reg == 3) { - const esp_app_desc_t* desc = esp_ota_get_app_description(); - sprintf(at_err, LF "%s" CRLF, desc->project_name); - at_cat_s(at_err); - } else if (tmp_reg == 4) { - sprintf(at_err, LF "DMA %d" CRLF, heap_caps_get_free_size(MALLOC_CAP_DMA)); - at_cat_s(at_err); - } else if (tmp_reg == 5) { - sprintf(at_err, LF "INTERNAL %d" CRLF, heap_caps_get_free_size(MALLOC_CAP_INTERNAL)); - at_cat_s(at_err); - } else if (tmp_reg == 6) { - sprintf(at_err, LF "TOTAL %d" CRLF, heap_caps_get_free_size(MALLOC_CAP_32BIT)); - at_cat_s(at_err); + } else if (tmp_reg == 1) { + const esp_app_desc_t *desc = esp_ota_get_app_description(); + + sprintf(at_err, LF "%s" CRLF, desc->version); + at_cat_s(at_err); + } else if (tmp_reg == 2) { + sprintf(at_err, LF "%s" CRLF, esp_get_idf_version()); + at_cat_s(at_err); + } else if (tmp_reg == 3) { + const esp_app_desc_t *desc = esp_ota_get_app_description(); + + sprintf(at_err, LF "%s" CRLF, desc->project_name); + at_cat_s(at_err); + } else if (tmp_reg == 4) { + sprintf(at_err, LF "DMA %d" CRLF, + heap_caps_get_free_size(MALLOC_CAP_DMA)); + at_cat_s(at_err); + } else if (tmp_reg == 5) { + sprintf(at_err, LF "INTERNAL %d" CRLF, + heap_caps_get_free_size(MALLOC_CAP_INTERNAL)); + at_cat_s(at_err); + } else if (tmp_reg == 6) { + sprintf(at_err, LF "TOTAL %d" CRLF, + heap_caps_get_free_size(MALLOC_CAP_32BIT)); + at_cat_s(at_err); #ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS - } else if (tmp_reg == 8) { - char buff[1024]; - vTaskGetRunTimeStats(buff); - fwrite(buff, strlen(buff), 1, stdout); /* Writes to FTDI UART not the modem */ - at_cat_s(LF "TASK TIMES" CRLF); + } else if (tmp_reg == 8) { + char buff[1024]; + vTaskGetRunTimeStats(buff); + /* Writes to FTDI UART not the modem */ + fwrite(buff, strlen(buff), 1, stdout); + at_cat_s(LF "TASK TIMES" CRLF); #endif #ifdef CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS - } else if (tmp_reg == 9) { - char buff[1024]; - vTaskList(buff); - fwrite(buff, strlen(buff), 1, stdout); /* Writes to FTDI UART not the modem */ - at_cat_s(LF "TASKS" CRLF); -#endif + } else if (tmp_reg == 9) { + char buff[1024]; + vTaskList(buff); + /* Writes to FTDI UART not the modem */ + fwrite(buff, strlen(buff), 1, stdout); + at_cat_s(LF "TASKS" CRLF); #endif - } else { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - AT_NEXT_CMD_ARGS; - break; +#endif /* MODEM_ESP32 */ + } else { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + AT_NEXT_CMD_ARGS; + break; case '$': /* AT$ */ - at_state = help; - msg = at_help; + at_state = help; + msg = at_help; break; case 'Z': /* ATZ */ - memset(at_prev, 0, sizeof(at_prev)); - modem_device_init(); + memset(at_prev, 0, sizeof(at_prev)); + modem_device_init(); AT_END_CMD; - break; + break; case 'H': /* ATH */ - if (*active_sfd) { - AT_END_CMD; - s_reg[SREG_RINGS] = 0; - close_socket(); - at_cat_s(LF "HANGUP" CR); - } + if (*active_sfd) { + AT_END_CMD; + s_reg[SREG_RINGS] = 0; + close_socket(); + at_cat_s(LF "HANGUP" CR); + } break; case 'D': /* ATDaddr[:port=23] */ #ifdef MODEM_WIFI - if (WiFi_status() != 3) { - strcpy(at_err, LF AT_NO_DIALTONE CRLF); - return 1; - } + if (WiFi_status() != 3) { + strcpy(at_err, LF AT_NO_DIALTONE CRLF); + return 1; + } #endif - if (*active_sfd) { - strcpy(at_err, LF "ALREADY IN CALL" CRLF); - return 1; - } - - strcpy(at_err, at_ptr); - arg_ptr = strtok(at_err, ":\r"); - - if(arg_ptr == NULL) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - - strncpy(addr, arg_ptr, AT_BUF_LEN - 1); - LOGI(TAG, "Addr: [%s]", addr); - arg_ptr = strtok(NULL, "\r"); - if (arg_ptr != NULL) { - strncpy(port_num, arg_ptr, 10); - } else { - strcpy(port_num, STR_VALUE(DEFAULT_LISTENER_PORT)); - } - LOGI(TAG, "Port: [%s]", port_num); - - if (open_socket()) { - strcpy(at_err, LF AT_NO_ANSWER CRLF); - return 1; - }; + if (*active_sfd) { + strcpy(at_err, LF "ALREADY IN CALL" CRLF); + return 1; + } + + strcpy(at_err, at_ptr); + arg_ptr = strtok(at_err, ":\r"); + + if (arg_ptr == NULL) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + + strncpy(addr, arg_ptr, AT_BUF_LEN - 1); + LOGI(TAG, "Addr: [%s]", addr); + arg_ptr = strtok(NULL, "\r"); + if (arg_ptr != NULL) + strncpy(port_num, arg_ptr, 10); + else + strcpy(port_num, STR_VALUE(DEFAULT_LISTENER_PORT)); + LOGI(TAG, "Port: [%s]", port_num); + + if (open_socket()) { + strcpy(at_err, LF AT_NO_ANSWER CRLF); + return 1; + }; AT_END_CMD; - at_state = dat; - if (telnet) { - at_cat_s(LF "CONNECT TELNET" CRLF); - } else { - at_cat_s(LF "CONNECT" CRLF); - } - *at_err = 0; - return 1; /* Not an error, just want to suppress the OK message */ + at_state = dat; + if (telnet) + at_cat_s(LF "CONNECT TELNET" CRLF); + else + at_cat_s(LF "CONNECT" CRLF); + *at_err = 0; + return 1; /* Not an error, just want to suppress the OK message */ case 'S': /* ATSn */ - tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); + tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); - if (tmp_reg < 0 || tmp_reg > (MAX_REG_NUM - 1) || arg_ptr == at_ptr) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } + if (tmp_reg < 0 || tmp_reg > (MAX_REG_NUM - 1) || arg_ptr == at_ptr) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } - reg = tmp_reg; - LOGI(TAG, "AT Register set to %d", reg); - AT_NEXT_CMD_ARGS; + reg = tmp_reg; + LOGI(TAG, "AT Register set to %d", reg); + AT_NEXT_CMD_ARGS; break; case '?': /* AT? */ - LOGI(TAG, "ATS%d? is %d", reg, s_reg[reg]); - sprintf(at_err, LF "%d" CRLF, s_reg[reg]); - at_cat_s(at_err); + LOGI(TAG, "ATS%d? is %d", reg, s_reg[reg]); + sprintf(at_err, LF "%d" CRLF, s_reg[reg]); + at_cat_s(at_err); break; case '=': /* AT=r */ - tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); + tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); - if (tmp_reg < 0 || tmp_reg > 255 || arg_ptr == at_ptr) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } + if (tmp_reg < 0 || tmp_reg > 255 || arg_ptr == at_ptr) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } - LOGI(TAG, "ATS%d = %d", reg, tmp_reg); - AT_NEXT_CMD_ARGS; - s_reg[reg] = tmp_reg; + LOGI(TAG, "ATS%d = %d", reg, tmp_reg); + AT_NEXT_CMD_ARGS; + s_reg[reg] = tmp_reg; break; case 'O': /* ATO */ AT_END_CMD; - if (*active_sfd == 0) { - strcpy(at_err, LF AT_NO_CARRIER CRLF); - return 1; - } - at_state = dat; + if (*active_sfd == 0) { + strcpy(at_err, LF AT_NO_CARRIER CRLF); + return 1; + } + at_state = dat; + break; + case 'E': /* ATE - Command echo */ + tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); + AT_NEXT_CMD_ARGS; + if (tmp_reg < 0 || tmp_reg > 1) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + if (tmp_reg) + s_reg[SREG_OPT] |= OPT_ECHO; + else + s_reg[SREG_OPT] &= ~OPT_ECHO; break; - case 'E': /* ATE - Command echo */ - tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); - AT_NEXT_CMD_ARGS; - if (tmp_reg < 0 || tmp_reg > 1) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - if (tmp_reg) { - s_reg[SREG_OPT] |= OPT_ECHO; - } else { - s_reg[SREG_OPT] &= ~OPT_ECHO; - } - break; - case 'Q': /* ATQ - Quiet mode */ - tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); - AT_NEXT_CMD_ARGS; - if (tmp_reg < 0 || tmp_reg > 1) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - if (tmp_reg) { - s_reg[SREG_OPT] |= OPT_QUIET; - } else { - s_reg[SREG_OPT] &= ~OPT_QUIET; - } - break; - case '&': - if (*at_ptr == 'A') { /* AT&A - enable answer - listen */ - tmp_reg = strtol(++at_ptr, &arg_ptr, BASE_DECIMAL); - AT_NEXT_CMD_ARGS; + case 'Q': /* ATQ - Quiet mode */ + tmp_reg = strtol(at_ptr, &arg_ptr, BASE_DECIMAL); + AT_NEXT_CMD_ARGS; + if (tmp_reg < 0 || tmp_reg > 1) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + if (tmp_reg) + s_reg[SREG_OPT] |= OPT_QUIET; + else + s_reg[SREG_OPT] &= ~OPT_QUIET; + break; + case '&': + if (*at_ptr == 'A') { /* AT&A - enable answer - listen */ + tmp_reg = strtol(++at_ptr, &arg_ptr, BASE_DECIMAL); + AT_NEXT_CMD_ARGS; #ifdef MODEM_WIFI - if (WiFi_status() != 3) { - strcpy(at_err, LF AT_NO_DIALTONE CRLF); - return 1; - } + if (WiFi_status() != 3) { + strcpy(at_err, LF AT_NO_DIALTONE CRLF); + return 1; + } #endif - if (answer_init()) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - }; - if (tmp_reg) { - daemon_f = true; - s_reg[SREG_OPT] &= ~OPT_ECHO; - s_reg[SREG_OPT] |= OPT_QUIET; - LOGI(TAG, "MODEM will be daemon and listen (No Echo & Quiet)"); - } - break; - } else if (*at_ptr == 'F') { /* AT&F - reset to Factory defaults */ - for (tmp_reg = 0; tmp_reg < MAX_REG_NUM; tmp_reg++) { - s_reg[tmp_reg] = s_reg_defaults[tmp_reg]; - } - LOGI(TAG, "Reset to Factory defaults"); - AT_NEXT_CMD; - break; + if (answer_init()) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + }; + if (tmp_reg) { + daemon_f = true; + s_reg[SREG_OPT] &= ~OPT_ECHO; + s_reg[SREG_OPT] |= OPT_QUIET; + LOGI(TAG, "MODEM will be daemon and listen " + "(No Echo & Quiet)"); + } + break; + } else if (*at_ptr == 'F') { /* AT&F - reset to Factory defaults */ + for (tmp_reg = 0; tmp_reg < MAX_REG_NUM; tmp_reg++) + s_reg[tmp_reg] = s_reg_defaults[tmp_reg]; + LOGI(TAG, "Reset to Factory defaults"); + AT_NEXT_CMD; + break; #ifdef MODEM_NVRAM - } else if (*at_ptr == 'W') { /* AT&W - write settings to NVRAM */ - Modem_nvramWriteAllSreg(s_reg, MAX_REG_NUM); - LOGI(TAG, "Settings written to NVRAM"); - AT_NEXT_CMD; - break; + } else if (*at_ptr == 'W') { /* AT&W - write settings to NVRAM */ + Modem_nvramWriteAllSreg(s_reg, MAX_REG_NUM); + LOGI(TAG, "Settings written to NVRAM"); + AT_NEXT_CMD; + break; #endif #ifdef MODEM_UART - } else if (*at_ptr == 'K') { - tmp_reg = strtol(++at_ptr, &arg_ptr, BASE_DECIMAL); - AT_NEXT_CMD_ARGS; - if (tmp_reg == 0) { /* AT&K0 - disable flow control */ - s_reg[SREG_FLOW_CTRL] = 0; - /* clear UART flow control */ - Modem_setFlowControl(0); - LOGI(TAG, "Flow Control Disabled"); - } else if (tmp_reg == 1) { /* AT&K1 - enable RTS/CTS flow control */ - s_reg[SREG_FLOW_CTRL] = 1; - /* set UART RTS/CTS flow control */ - Modem_setFlowControl(1); - LOGI(TAG, "RTS/CTS Flow Control Enabled"); - } else { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } + } else if (*at_ptr == 'K') { + tmp_reg = strtol(++at_ptr, &arg_ptr, BASE_DECIMAL); + AT_NEXT_CMD_ARGS; + if (tmp_reg == 0) { /* AT&K0 - disable flow control */ + s_reg[SREG_FLOW_CTRL] = 0; + /* clear UART flow control */ + Modem_setFlowControl(0); + LOGI(TAG, "Flow Control Disabled"); + } else if (tmp_reg == 1) { /* AT&K1 - enable RTS/CTS flow control */ + s_reg[SREG_FLOW_CTRL] = 1; + /* set UART RTS/CTS flow control */ + Modem_setFlowControl(1); + LOGI(TAG, "RTS/CTS Flow Control Enabled"); + } else { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } #endif - } else { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - break; - case '+': - if (*at_ptr == 'T' && *(at_ptr+1) == '?') { - const char *ttype; - if ((ttype = getenv("TERM")) == NULL) { - ttype = TELNET_TTYPE; - } - sprintf(at_err, LF "%s" CRLF, ttype); - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'T' && *(at_ptr+1) == '=') { - strcpy(at_err, at_ptr+2); - arg_ptr = strtok(at_err, "\r"); - - if(arg_ptr == NULL) { - unsetenv("TERM"); - LOGI(TAG, "TERM cleared"); - } else { - setenv("TERM", arg_ptr, 1); - LOGI(TAG, "TERM: [%s]", getenv("TERM")); - } + } else { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + break; + case '+': + if (*at_ptr == 'T' && *(at_ptr + 1) == '?') { + const char *ttype; + + if ((ttype = getenv("TERM")) == NULL) { + ttype = TELNET_TTYPE; + } + sprintf(at_err, LF "%s" CRLF, ttype); + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'T' && *(at_ptr + 1) == '=') { + strcpy(at_err, at_ptr + 2); + arg_ptr = strtok(at_err, "\r"); + + if (arg_ptr == NULL) { + unsetenv("TERM"); + LOGI(TAG, "TERM cleared"); + } else { + setenv("TERM", arg_ptr, 1); + LOGI(TAG, "TERM: [%s]", getenv("TERM")); + } #ifdef MODEM_NVRAM - Modem_nvramWriteEnv("TERM"); + Modem_nvramWriteEnv("TERM"); #endif - AT_END_CMD; + AT_END_CMD; #ifdef MODEM_WIFI -/** - * WIFI CONFIG HANDLING - */ - } else if (*at_ptr == 'W' && *(at_ptr+1) == '=') { - - char ssid[MAX_SSID + 1] = ""; - char psw[MAX_PWD + 1] = ""; - - strcpy(at_err, at_ptr+2); - arg_ptr = strtok(at_err, ",\r"); - - if(arg_ptr == NULL) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - strncpy(ssid, arg_ptr, MAX_SSID); - - arg_ptr = strtok(NULL, "\r"); - if (arg_ptr != NULL) { - strncpy(psw, arg_ptr, MAX_PWD); - } - - WiFi_begin(ssid, psw); - AT_END_CMD; - } else if (*at_ptr == 'W' && *(at_ptr+1) == '?') { - sprintf(at_err, LF "%s" CRLF, WiFi_status_str()); - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'W' && *(at_ptr+1) == '+') { - if (WiFi_status() == 255) { - WiFi_begin_x(); - } - sprintf(at_err, LF "%s" CRLF, WiFi_reconnect()); - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'W' && *(at_ptr+1) == '-') { - sprintf(at_err, LF "%s" CRLF, WiFi_disconnect()); - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'W' && *(at_ptr+1) == '$') { - sprintf(at_err, LF "%s" CRLF, WiFi_IP()); - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'W' && *(at_ptr+1) == '#') { - sprintf(at_err, LF "%s" CRLF, WiFi_MAC()); - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'U' && *(at_ptr+1) == '=') { - - if (WiFi_status() != 3) { - strcpy(at_err, LF AT_NO_DIALTONE CRLF); - return 1; - } - - strcpy(at_err, at_ptr+2); - arg_ptr = strtok(at_err, "\r"); - - if(arg_ptr == NULL) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - - if (ota_setURL(at_err, arg_ptr)) { - return 1; - } - - at_cat_s(at_err); - AT_END_CMD; - } else if (*at_ptr == 'U' && *(at_ptr+1) == '?') { - - if (WiFi_status() != 3) { - strcpy(at_err, LF AT_NO_DIALTONE CRLF); - return 1; - } - - at_err[0] = *(at_ptr+2); - - if (ota_start(at_err)) { - return 1; - } - - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'U' && *(at_ptr+1) == '$') { - - if (ota_partitionQuery(at_err)) { - return 1; - } - - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'U' && *(at_ptr+1) == '^') { - - if (ota_upgrade(at_err)) { - return 1; - } - - at_cat_s(at_err); - AT_NEXT_CMD2; - } else if (*at_ptr == 'U' && *(at_ptr+1) == '!') { - - if (ota_forceUpgrade(at_err)) { - return 1; - } - - at_cat_s(at_err); - AT_NEXT_CMD2; -#endif + /** + * WIFI CONFIG HANDLING + */ + } else if (*at_ptr == 'W' && *(at_ptr + 1) == '=') { + char ssid[MAX_SSID + 1] = ""; + char psw[MAX_PWD + 1] = ""; + + strcpy(at_err, at_ptr + 2); + arg_ptr = strtok(at_err, ",\r"); + + if (arg_ptr == NULL) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + strncpy(ssid, arg_ptr, MAX_SSID); + + arg_ptr = strtok(NULL, "\r"); + if (arg_ptr != NULL) + strncpy(psw, arg_ptr, MAX_PWD); + + WiFi_begin(ssid, psw); + AT_END_CMD; + } else if (*at_ptr == 'W' && *(at_ptr + 1) == '?') { + sprintf(at_err, LF "%s" CRLF, WiFi_status_str()); + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'W' && *(at_ptr + 1) == '+') { + if (WiFi_status() == 255) + WiFi_begin_x(); + sprintf(at_err, LF "%s" CRLF, WiFi_reconnect()); + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'W' && *(at_ptr + 1) == '-') { + sprintf(at_err, LF "%s" CRLF, WiFi_disconnect()); + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'W' && *(at_ptr + 1) == '$') { + sprintf(at_err, LF "%s" CRLF, WiFi_IP()); + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'W' && *(at_ptr + 1) == '#') { + sprintf(at_err, LF "%s" CRLF, WiFi_MAC()); + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'U' && *(at_ptr + 1) == '=') { + if (WiFi_status() != 3) { + strcpy(at_err, LF AT_NO_DIALTONE CRLF); + return 1; + } + + strcpy(at_err, at_ptr + 2); + arg_ptr = strtok(at_err, "\r"); + + if (arg_ptr == NULL) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + + if (ota_setURL(at_err, arg_ptr)) + return 1; + + at_cat_s(at_err); + AT_END_CMD; + } else if (*at_ptr == 'U' && *(at_ptr + 1) == '?') { + if (WiFi_status() != 3) { + strcpy(at_err, LF AT_NO_DIALTONE CRLF); + return 1; + } + + at_err[0] = *(at_ptr + 2); + + if (ota_start(at_err)) + return 1; + + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'U' && *(at_ptr + 1) == '$') { + if (ota_partitionQuery(at_err)) + return 1; + + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'U' && *(at_ptr + 1) == '^') { + if (ota_upgrade(at_err)) + return 1; + + at_cat_s(at_err); + AT_NEXT_CMD2; + } else if (*at_ptr == 'U' && *(at_ptr + 1) == '!') { + if (ota_forceUpgrade(at_err)) + return 1; + + at_cat_s(at_err); + AT_NEXT_CMD2; +#endif /* MODEM_WIFI */ #ifdef MODEM_UART -/** - * SERIAL CONFIG HANDLING - */ - } else if (*at_ptr == 'B' && *(at_ptr+1) == '=') { - tmp_reg = strtol(at_ptr+2, &arg_ptr, BASE_DECIMAL); - - if (tmp_reg < 4800 || tmp_reg > 115200 || arg_ptr == (at_ptr+2)) { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - - Modem_updateBaudRate(tmp_reg); - sprintf(at_err, LF "%d" CRLF, Modem_baudRate()); - at_cat_s(at_err); - AT_NEXT_CMD_ARGS; - } else if (*at_ptr == 'B' && *(at_ptr+1) == '?') { - sprintf(at_err, LF "%d" CRLF, Modem_baudRate()); - at_cat_s(at_err); - AT_NEXT_CMD2; -#endif -/** - * - */ - } else { - strcpy(at_err, LF AT_ERROR CRLF); - return 1; - } - break; - case 'A': /* ATA - answer */ + /** + * SERIAL CONFIG HANDLING + */ + } else if (*at_ptr == 'B' && *(at_ptr + 1) == '=') { + tmp_reg = strtol(at_ptr + 2, &arg_ptr, BASE_DECIMAL); + + if (tmp_reg < 4800 || tmp_reg > 115200 || arg_ptr == (at_ptr + 2)) { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + + Modem_updateBaudRate(tmp_reg); + sprintf(at_err, LF "%d" CRLF, Modem_baudRate()); + at_cat_s(at_err); + AT_NEXT_CMD_ARGS; + } else if (*at_ptr == 'B' && *(at_ptr + 1) == '?') { + sprintf(at_err, LF "%d" CRLF, Modem_baudRate()); + at_cat_s(at_err); + AT_NEXT_CMD2; +#endif /* MODEM_UART */ + /** + * + */ + } else { + strcpy(at_err, LF AT_ERROR CRLF); + return 1; + } + break; + case 'A': /* ATA - answer */ #ifdef MODEM_WIFI - if (WiFi_status() != 3) { - strcpy(at_err, LF AT_NO_DIALTONE CRLF); - return 1; - } + if (WiFi_status() != 3) { + strcpy(at_err, LF AT_NO_DIALTONE CRLF); + return 1; + } #endif - answer(); - AT_END_CMD; - at_state = dat; - break; + answer(); + AT_END_CMD; + at_state = dat; + break; default: strcpy(at_err, LF AT_ERROR CRLF); return 1; + } } - } return 0; } @@ -1044,308 +1041,299 @@ static int process_at_cmd(void) { static uint64_t at_t1, at_t2; static int tdiff; -int modem_device_poll(int i); - -int modem_device_alive(int i) { - - UNUSED(i); +int modem_device_alive(int i) +{ + UNUSED(i); - if (!daemon_f) return 1; + if (!daemon_f) + return 1; - if (answer_sfd) { - if (*active_sfd) { - return 1; - } else { - if (at_state == cmd) { - modem_device_poll(0); - return 0; - } - } - } - return 0; + if (answer_sfd) { + if (*active_sfd) + return 1; + else { + if (at_state == cmd) { + modem_device_poll(0); + return 0; + } + } + } + return 0; } -static int _read(void) { - - unsigned char data; +static int _read(void) +{ + unsigned char data; - if (read(*active_sfd, &data, 1) == 0) { - /* this will occur if the socket is disconnected */ - LOGI(TAG, "Socket disconnected"); - at_buf[0] = 0; - at_cat_s(CRLF AT_NO_CARRIER); - hangup_timeout(true); - at_cmd[0] = 0; - at_state = cmd; - carrier_detect = 0; - - return -1; - } + if (read(*active_sfd, &data, 1) == 0) { + /* this will occur if the socket is disconnected */ + LOGI(TAG, "Socket disconnected"); + at_buf[0] = 0; + at_cat_s(CRLF AT_NO_CARRIER); + hangup_timeout(true); + at_cmd[0] = 0; + at_state = cmd; + carrier_detect = 0; - return data; -} + return -1; + } -int modem_device_poll(int i) { - - UNUSED(i); - - struct pollfd p[1]; - - if (at_state == help) { - if (strlen(at_buf) == 0) { - at_cat_s(*msg); - msg++; - if (*msg == NULL) { - at_state = cmd; - } - } - return strlen(at_out) > 0; - } else if (at_state == intr) { - if (strlen(at_buf) == 3) { - at_t2 = get_clock_us(); - tdiff = (at_t2 - at_t1) / 1000000; - if (tdiff > 0) { - at_state = cmd; - LOGI(TAG, "+++ Returning to CMD mode"); - at_cat_s(CRLF AT_OK); - return strlen(at_buf) > 0; - } - } - return 0; - } else if (at_state == dat && strlen(at_out) == 0) { - - /** - * In telnet mode this "clocks" the inbound connection into telnet_recv() - * and lets the event handler buffer the input (1 character) - * then it can check the buffer and report on available data in the buffer - */ - - if ((telnet != NULL) && tn_len) return POLLIN; - - p[0].fd = *active_sfd; - p[0].events = POLLIN | POLLOUT; - p[0].revents = 0; - poll(p, 1, 0); - - if (telnet == NULL) return p[0].revents & POLLIN; - - if (p[0].revents & POLLIN) { - int res; - char data; - res = _read(); - if (res != -1) { - data = res; - telnet_recv(telnet, (char *) &data, 1); - } - if (tn_len) return POLLIN; - } - - return 0; - - } else { - if (answer_check_ring()) { - s_reg[SREG_RINGS]++; - at_cat_s(CRLF AT_RING); - if ((s_reg[SREG_AA] > 0) && (s_reg[SREG_RINGS] >= s_reg[SREG_AA])) { - if (!answer()) { - at_state = dat; - } - } - } else if(hangup_timeout(false)) { - at_cat_s(CRLF "HANGUP" CRLF); - } - - return strlen(at_out) > 0; - } + return data; } -int modem_device_get(int i) { - - UNUSED(i); - - struct pollfd p[1]; - unsigned char data; +int modem_device_poll(int i) +{ + UNUSED(i); - if (at_state == dat && strlen(at_out) == 0) { + struct pollfd p[1]; - if (telnet != NULL) { - if (tn_len) { - tn_len = 0; - return tn_recv; - } else { - return -1; - } - } else { + if (at_state == help) { + if (strlen(at_buf) == 0) { + at_cat_s(*msg); + msg++; + if (*msg == NULL) + at_state = cmd; + } + return strlen(at_out) > 0; + } else if (at_state == intr) { + if (strlen(at_buf) == 3) { + at_t2 = get_clock_us(); + tdiff = (at_t2 - at_t1) / 1000000; + if (tdiff > 0) { + at_state = cmd; + LOGI(TAG, "+++ Returning to CMD mode"); + at_cat_s(CRLF AT_OK); + return strlen(at_buf) > 0; + } + } + return 0; + } else if (at_state == dat && strlen(at_out) == 0) { + /** + * In telnet mode this "clocks" the inbound connection into telnet_recv() + * and lets the event handler buffer the input (1 character) + * then it can check the buffer and report on available data in the buffer + */ + + if ((telnet != NULL) && tn_len) + return POLLIN; + + p[0].fd = *active_sfd; + p[0].events = POLLIN | POLLOUT; + p[0].revents = 0; + poll(p, 1, 0); + + if (telnet == NULL) + return p[0].revents & POLLIN; + + if (p[0].revents & POLLIN) { + int res; + char data; + res = _read(); + if (res != -1) { + data = res; + telnet_recv(telnet, (char *) &data, 1); + } + if (tn_len) + return POLLIN; + } - p[0].fd = *active_sfd; - p[0].events = POLLIN; - p[0].revents = 0; - poll(p, 1, 0); + return 0; + } else { + if (answer_check_ring()) { + s_reg[SREG_RINGS]++; + at_cat_s(CRLF AT_RING); + if ((s_reg[SREG_AA] > 0) && (s_reg[SREG_RINGS] >= s_reg[SREG_AA])) { + if (!answer()) + at_state = dat; + } + } else if (hangup_timeout(false)) + at_cat_s(CRLF "HANGUP" CRLF); - if (!(p[0].revents & POLLIN)) return -1; + return strlen(at_out) > 0; + } +} - return _read(); - } - } else { +int modem_device_get(int i) +{ + UNUSED(i); - if (strlen(at_out) > 0) { - data = *at_out; - at_out++; - if (strlen(at_out) == 0) { - at_out = at_buf; - at_buf[0] = 0; - } - } else { - return -1; - } - } + struct pollfd p[1]; + unsigned char data; + + if (at_state == dat && strlen(at_out) == 0) { + if (telnet != NULL) { + if (tn_len) { + tn_len = 0; + return tn_recv; + } else + return -1; + } else { + p[0].fd = *active_sfd; + p[0].events = POLLIN; + p[0].revents = 0; + poll(p, 1, 0); + + if (!(p[0].revents & POLLIN)) + return -1; + + return _read(); + } + } else { + if (strlen(at_out) > 0) { + data = *at_out; + at_out++; + if (strlen(at_out) == 0) { + at_out = at_buf; + at_buf[0] = 0; + } + } else + return -1; + } - return data; + return data; } -void modem_device_send(int i, char data) { - - UNUSED(i); +void modem_device_send(int i, char data) +{ + UNUSED(i); switch (at_state) { - /*** - * data mode - */ - case intr: - if (data == '+' && strlen(at_buf) < 3) { - at_buf[strlen(at_buf)+1] = 0; - at_buf[strlen(at_buf)] = data; - at_t1 = get_clock_us(); - return; - } else { - if (telnet != NULL) { - telnet_send(telnet, at_buf, strlen(at_buf)); - } else { - if (write(*active_sfd, at_buf, strlen(at_buf)) != (ssize_t) strlen(at_buf)) - LOGE(TAG, "can't send at_buf to active_sfd"); - } - - at_state = dat; - } - /*** - * NO break; - * Intentional fallthrough here. - */ - /* fall through */ - case dat: - at_t2 = get_clock_us(); - tdiff = (at_t2 - at_t1) / 1000000; - - if (data == '+' && (tdiff > 0) && !daemon_f) { - at_buf[0] = data; - at_buf[1] = 0; - at_out = at_buf; - at_state = intr; - return; - } - if (telnet != NULL) { - telnet_send(telnet, (char *) &data, 1); - } else { - if (write(*active_sfd, (char *) &data, 1) != 1) - LOGE(TAG, "can't send data to active_sfd"); - } - break; /*** - * AT command mode + * data mode */ - case cmd: - at_cat_c(data); - if (data == 'A') { - at_state = A_recv; - } else { - at_cat_s(CRLF AT_ERROR); - at_cmd[0] = 0; - at_state = cmd; - } - break; - case A_recv: - at_cat_c(data); - if (data == 'T') { - at_state = AT_recv; - } else if (data == '/') { - at_state = AS_recv; - at_cat_s(CR); - strcpy(at_cmd, at_prev); - if (process_at_cmd()) { - at_cat_s(at_err); - } else { - at_cat_s(LF AT_OK); - } - at_state = cmd; - } else { - at_cat_s(CRLF AT_ERROR); - at_cmd[0] = 0; - at_state = cmd; - } - break; - case AT_recv: - at_cat_c(data); - if (data == '\r') { - at_state = cmd; - if (process_at_cmd()) { - at_cat_s(at_err); - } else { - at_cat_s(LF AT_OK); - } + case intr: + if (data == '+' && strlen(at_buf) < 3) { + at_buf[strlen(at_buf) +1] = 0; + at_buf[strlen(at_buf)] = data; + at_t1 = get_clock_us(); + return; + } else { + if (telnet != NULL) + telnet_send(telnet, at_buf, strlen(at_buf)); + else { + if (write(*active_sfd, at_buf, strlen(at_buf)) + != (ssize_t) strlen(at_buf)) + LOGE(TAG, "can't send at_buf to active_sfd"); } - break; - case AS_recv: - LOGE(TAG, "A/: Didn't expect to get here"); - break; - default: - LOGE(TAG, "AT statemachine unknown [%d]", at_state); - break; + + at_state = dat; + } + /*** + * NO break; + * Intentional fallthrough here. + */ + /* fall through */ + case dat: + at_t2 = get_clock_us(); + tdiff = (at_t2 - at_t1) / 1000000; + + if (data == '+' && (tdiff > 0) && !daemon_f) { + at_buf[0] = data; + at_buf[1] = 0; + at_out = at_buf; + at_state = intr; + return; + } + if (telnet != NULL) + telnet_send(telnet, (char *) &data, 1); + else { + if (write(*active_sfd, (char *) &data, 1) != 1) + LOGE(TAG, "can't send data to active_sfd"); + } + break; + /*** + * AT command mode + */ + case cmd: + at_cat_c(data); + if (data == 'A') + at_state = A_recv; + else { + at_cat_s(CRLF AT_ERROR); + at_cmd[0] = 0; + at_state = cmd; + } + break; + case A_recv: + at_cat_c(data); + if (data == 'T') + at_state = AT_recv; + else if (data == '/') { + at_state = AS_recv; + at_cat_s(CR); + strcpy(at_cmd, at_prev); + if (process_at_cmd()) + at_cat_s(at_err); + else + at_cat_s(LF AT_OK); + at_state = cmd; + } else { + at_cat_s(CRLF AT_ERROR); + at_cmd[0] = 0; + at_state = cmd; + } + break; + case AT_recv: + at_cat_c(data); + if (data == '\r') { + at_state = cmd; + if (process_at_cmd()) + at_cat_s(at_err); + else + at_cat_s(LF AT_OK); + } + break; + case AS_recv: + LOGE(TAG, "A/: Didn't expect to get here"); + break; + default: + LOGE(TAG, "AT statemachine unknown [%d]", at_state); + break; } - if (at_state == dat) at_t1 = get_clock_us(); + if (at_state == dat) + at_t1 = get_clock_us(); } -int modem_device_carrier(int i) { - UNUSED(i); +int modem_device_carrier(int i) +{ + UNUSED(i); - return carrier_detect; + return carrier_detect; } -void modem_device_init(void) { - if (*active_sfd) { - close_socket(); - } - if (answer_sfd) { - active_sfd = &answer_sfd; - close_socket(); - active_sfd = &sfd; +void modem_device_init(void) +{ + if (*active_sfd) + close_socket(); + if (answer_sfd) { + active_sfd = &answer_sfd; + close_socket(); + active_sfd = &sfd; - } - at_state = cmd; + } + at_state = cmd; #ifdef MODEM_NVRAM - int tmp_reg; - for (tmp_reg = 0; tmp_reg < MAX_REG_NUM; tmp_reg++) { - s_reg[tmp_reg] = Modem_nvramReadSreg(tmp_reg, s_reg_defaults[tmp_reg]); - } - Modem_nvramReadEnv("TERM"); - Modem_nvramReadEnv("MODEM.init"); + int tmp_reg; + for (tmp_reg = 0; tmp_reg < MAX_REG_NUM; tmp_reg++) + s_reg[tmp_reg] = Modem_nvramReadSreg(tmp_reg, s_reg_defaults[tmp_reg]); + Modem_nvramReadEnv("TERM"); + Modem_nvramReadEnv("MODEM.init"); #else - memcpy(s_reg, s_reg_defaults, sizeof(s_reg_defaults)); + memcpy(s_reg, s_reg_defaults, sizeof(s_reg_defaults)); #endif - char *modem_init_string; - if ((modem_init_string = getenv("MODEM.init")) != NULL) { - LOG(TAG, "MODEM.init string: %s\r\n", modem_init_string); - while (*modem_init_string) { - modem_device_send(0, *modem_init_string++); - } - modem_device_send(0, '\r'); - while (modem_device_poll(0)) { - modem_device_get(0); - } - } + char *modem_init_string; + if ((modem_init_string = getenv("MODEM.init")) != NULL) { + LOG(TAG, "MODEM.init string: %s\r\n", modem_init_string); + while (*modem_init_string) + modem_device_send(0, *modem_init_string++); + modem_device_send(0, '\r'); + while (modem_device_poll(0)) + modem_device_get(0); + } #ifdef MODEM_UART - /* set/clear UART flow control based on S39 */ - Modem_setFlowControl(s_reg[SREG_FLOW_CTRL]); + /* set/clear UART flow control based on S39 */ + Modem_setFlowControl(s_reg[SREG_FLOW_CTRL]); #endif } diff --git a/iodevices/imsai-hal.c b/iodevices/imsai-hal.c index 849ff47c..a2c8cdfd 100644 --- a/iodevices/imsai-hal.c +++ b/iodevices/imsai-hal.c @@ -1,14 +1,14 @@ - /* - * imsai-hal.c - * - * Copyright (C) 2021 by David McNaiughton - * - * IMSAI SIO-2 hardware abstraction layer - * - * History: - * 1-JUL-2021 1.0 Initial Release - * - */ +/* +* imsai-hal.c +* +* Copyright (C) 2021 by David McNaiughton +* +* IMSAI SIO-2 hardware abstraction layer +* +* History: +* 1-JUL-2021 1.0 Initial Release +* +*/ #include #include @@ -39,192 +39,223 @@ static const char *TAG = "HAL"; /* -------------------- NULL device HAL -------------------- */ -static int null_alive(void) { - return 1; /* NULL is always alive */ +static int null_alive(void) +{ + return 1; /* NULL is always alive */ } + #if !defined(HAS_NETSERVER) || !defined(HAS_MODEM) -static int null_dead(void) { - return 0; /* NULL is always dead */ +static int null_dead(void) +{ + return 0; /* NULL is always dead */ } #endif -static void null_status(BYTE *stat) { - UNUSED(stat); - return; +static void null_status(BYTE *stat) +{ + UNUSED(stat); + + return; } -static int null_in(void) { - return -1; + +static int null_in(void) +{ + return -1; } -static void null_out(BYTE data) { - UNUSED(data); - return; +static void null_out(BYTE data) +{ + UNUSED(data); + + return; } -static int null_cd(void) { - return 0; + +static int null_cd(void) +{ + return 0; } /* -------------------- VIOKBD HAL -------------------- */ -static int vio_kbd_alive(void) { +static int vio_kbd_alive(void) +{ #ifdef HAS_NETSERVER - if (n_flag) { - /* VIO (webUI) keyboard is only alive if websocket is connected */ - return net_device_alive(DEV_VIO); - } else { + if (n_flag) { + /* VIO (webUI) keyboard is only alive if websocket is connected */ + return net_device_alive(DEV_VIO); + } else { #endif - /* VIO (xterm) keyboard is always alive */ - return 1; + /* VIO (xterm) keyboard is always alive */ + return 1; #ifdef HAS_NETSERVER - } + } #endif } + static void vio_kbd_status(BYTE *stat) { - *stat = imsai_vio_kbd_status_in(); + *stat = imsai_vio_kbd_status_in(); } + static int vio_kbd_in(void) { - return imsai_vio_kbd_in(); + return imsai_vio_kbd_in(); } -static void vio_kbd_out(BYTE data) { - UNUSED(data); + +static void vio_kbd_out(BYTE data) +{ + UNUSED(data); } /* -------------------- WEBTTY HAL -------------------- */ #ifdef HAS_NETSERVER -static int net_tty_alive(void) { - if (n_flag) { - /* WEBTTY is only alive if websocket is connected */ - return net_device_alive(DEV_TTY); - } else { - return 0; - } -} -static void net_tty_status(BYTE *stat) { - *stat &= (BYTE)(~3); - if (n_flag) { - if (net_device_poll(DEV_TTY)) { - *stat |= 2; - } - *stat |= 1; - } -} -static int net_tty_in(void) { - if (n_flag) { - return net_device_get(DEV_TTY); - } else { - return -1; - } -} -static void net_tty_out(BYTE data) { - if (n_flag) { - net_device_send(DEV_TTY, (char *)&data, 1); - } + +static int net_tty_alive(void) +{ + if (n_flag) { + /* WEBTTY is only alive if websocket is connected */ + return net_device_alive(DEV_TTY); + } else + return 0; } -#endif + +static void net_tty_status(BYTE *stat) +{ + *stat &= (BYTE) (~3); + if (n_flag) { + if (net_device_poll(DEV_TTY)) + *stat |= 2; + *stat |= 1; + } +} + +static int net_tty_in(void) +{ + if (n_flag) + return net_device_get(DEV_TTY); + else + return -1; +} + +static void net_tty_out(BYTE data) +{ + if (n_flag) + net_device_send(DEV_TTY, (char *)&data, 1); +} + +#endif /* HAS_NETSERVER */ /* -------------------- WEBPTR HAL -------------------- */ #ifdef HAS_NETSERVER -static int net_ptr_alive(void) { - if (n_flag) { - /* WEBPTR is only alive if websocket is connected */ - return net_device_alive(DEV_PTR); - } else { - return 0; - } -} -static void net_ptr_status(BYTE *stat) { - *stat &= (BYTE)(~3); - if (n_flag) { - if (net_device_poll(DEV_PTR)) { - *stat |= 2; - } - *stat |= 1; - } -} -static int net_ptr_in(void) { - if (n_flag) { - return net_device_get(DEV_PTR); - } else { - return -1; - } -} -static void net_ptr_out(BYTE data) { - if (n_flag) { - net_device_send(DEV_PTR, (char *)&data, 1); - } + +static int net_ptr_alive(void) +{ + if (n_flag) { + /* WEBPTR is only alive if websocket is connected */ + return net_device_alive(DEV_PTR); + } else + return 0; } -#endif + +static void net_ptr_status(BYTE *stat) +{ + *stat &= (BYTE) (~3); + if (n_flag) { + if (net_device_poll(DEV_PTR)) + *stat |= 2; + *stat |= 1; + } +} + +static int net_ptr_in(void) +{ + if (n_flag) + return net_device_get(DEV_PTR); + else + return -1; +} + +static void net_ptr_out(BYTE data) +{ + if (n_flag) + net_device_send(DEV_PTR, (char *)&data, 1); +} + +#endif /* HAS_NETSERVER */ /* -------------------- STDIO HAL -------------------- */ -static int stdio_alive(void) { - return 1; /* STDIO is always alive */ -} -static void stdio_status(BYTE *stat) { - struct pollfd p[1]; - - p[0].fd = fileno(stdin); - p[0].events = POLLIN; - p[0].revents = 0; - poll(p, 1, 0); - *stat &= (BYTE)(~3); - if (p[0].revents & POLLIN) - *stat |= 2; - if (p[0].revents & POLLNVAL) { - LOGE(TAG, "can't use terminal, try 'screen simulation ...'"); - cpu_error = IOERROR; - cpu_state = ST_STOPPED; - } - *stat |= 1; - -} -static int stdio_in(void) { - int data; +static int stdio_alive(void) +{ + return 1; /* STDIO is always alive */ +} + +static void stdio_status(BYTE *stat) +{ + struct pollfd p[1]; + + p[0].fd = fileno(stdin); + p[0].events = POLLIN; + p[0].revents = 0; + poll(p, 1, 0); + *stat &= (BYTE) (~3); + if (p[0].revents & POLLIN) + *stat |= 2; + if (p[0].revents & POLLNVAL) { + LOGE(TAG, "can't use terminal, try 'screen simulation ...'"); + cpu_error = IOERROR; + cpu_state = ST_STOPPED; + } + *stat |= 1; +} + +static int stdio_in(void) +{ + int data; struct pollfd p[1]; again: - /* if no input waiting return last */ - p[0].fd = fileno(stdin); - p[0].events = POLLIN; - p[0].revents = 0; - poll(p, 1, 0); - if (!(p[0].revents & POLLIN)) - return -1; - - if (read(fileno(stdin), &data, 1) == 0) { - /* try to reopen tty, input redirection exhausted */ - if (freopen("/dev/tty", "r", stdin) == NULL) - LOGE(TAG, "can't reopen /dev/tty"); - set_unix_terminal(); - goto again; - } - - return data; -} -static void stdio_out(BYTE data) { + /* if no input waiting return last */ + p[0].fd = fileno(stdin); + p[0].events = POLLIN; + p[0].revents = 0; + poll(p, 1, 0); + if (!(p[0].revents & POLLIN)) + return -1; + if (read(fileno(stdin), &data, 1) == 0) { + /* try to reopen tty, input redirection exhausted */ + if (freopen("/dev/tty", "r", stdin) == NULL) + LOGE(TAG, "can't reopen /dev/tty"); + set_unix_terminal(); + goto again; + } + + return data; +} + +static void stdio_out(BYTE data) +{ again: - if (write(fileno(stdout), (char *) &data, 1) != 1) { - if (errno == EINTR) { - goto again; - } else { - LOGE(TAG, "can't write data"); - cpu_error = IOERROR; - cpu_state = ST_STOPPED; - } - } + if (write(fileno(stdout), (char *) &data, 1) != 1) { + if (errno == EINTR) + goto again; + else { + LOGE(TAG, "can't write data"); + cpu_error = IOERROR; + cpu_state = ST_STOPPED; + } + } } /* -------------------- SOCKET SERVER HAL -------------------- */ -static int scktsrv_alive(void) { - - struct pollfd p[1]; +static int scktsrv_alive(void) +{ + struct pollfd p[1]; /* if socket not connected check for a new connection */ if (ucons[0].ssc == 0) { @@ -234,8 +265,7 @@ static int scktsrv_alive(void) { poll(p, 1, 0); /* accept a new connection */ if (p[0].revents) { - if ((ucons[0].ssc = accept(ucons[0].ss, NULL, - NULL)) == -1) { + if ((ucons[0].ssc = accept(ucons[0].ss, NULL, NULL)) == -1) { LOGW(TAG, "can't accept server socket"); ucons[0].ssc = 0; } @@ -244,9 +274,10 @@ static int scktsrv_alive(void) { return ucons[0].ssc; /* SCKTSRV is alive if there is an open socket */ } -static void scktsrv_status(BYTE *stat) { - struct pollfd p[1]; +static void scktsrv_status(BYTE *stat) +{ + struct pollfd p[1]; /* if socket is connected check for I/O */ if (ucons[0].ssc != 0) { @@ -254,17 +285,18 @@ static void scktsrv_status(BYTE *stat) { p[0].events = POLLIN | POLLOUT; p[0].revents = 0; poll(p, 1, 0); - *stat &= (BYTE)(~3); + *stat &= (BYTE) (~3); if (p[0].revents & POLLIN) *stat |= 2; if (p[0].revents & POLLOUT) *stat |= 1; - } else { + } else *stat = 0; - } } -static int scktsrv_in(void) { - BYTE data; + +static int scktsrv_in(void) +{ + BYTE data; struct pollfd p[1]; /* if not connected return last */ @@ -286,10 +318,11 @@ static int scktsrv_in(void) { return -1; } - return data; + return data; } -static void scktsrv_out(BYTE data) { +static void scktsrv_out(BYTE data) +{ struct pollfd p[1]; /* return if socket not connected */ @@ -309,9 +342,9 @@ static void scktsrv_out(BYTE data) { again: if (write(ucons[0].ssc, &data, 1) != 1) { - if (errno == EINTR) { + if (errno == EINTR) goto again; - } else { + else { close(ucons[0].ssc); ucons[0].ssc = 0; } @@ -321,225 +354,234 @@ static void scktsrv_out(BYTE data) { /* -------------------- MODEM HAL -------------------- */ #ifdef HAS_MODEM + #include "generic-at-modem.h" -static int modem_alive(void) { - return modem_device_alive(0); +static int modem_alive(void) +{ + return modem_device_alive(0); } -static void modem_status(BYTE *stat) { - *stat &= (BYTE)(~3); - if (modem_device_poll(0)) { - *stat |= 2; - } - *stat |= 1; + +static void modem_status(BYTE *stat) +{ + *stat &= (BYTE) (~3); + if (modem_device_poll(0)) + *stat |= 2; + *stat |= 1; } -static int modem_in(void) { - return modem_device_get(0); + +static int modem_in(void) +{ + return modem_device_get(0); } -static void modem_out(BYTE data){ - modem_device_send(0, (char) data); + +static void modem_out(BYTE data) +{ + modem_device_send(0, (char) data); } -static int modem_cd(void) { - return modem_device_carrier(0); + +static int modem_cd(void) +{ + return modem_device_carrier(0); } -#endif /*HAS_MODEM*/ + +#endif /* HAS_MODEM */ /* -------------------- HAL port/device mappings -------------------- */ -const char *sio_port_name[MAX_SIO_PORT] = { "SIO1.portA", "SIO1.portB", "SIO2.portA", "SIO2.portB" }; +const char *sio_port_name[MAX_SIO_PORT] = + { "SIO1.portA", "SIO1.portB", "SIO2.portA", "SIO2.portB" }; static const hal_device_t devices[] = { #ifdef HAS_NETSERVER - { "WEBTTY", 0, net_tty_alive, net_tty_status, net_tty_in, net_tty_out, null_cd }, - { "WEBPTR", 0, net_ptr_alive, net_ptr_status, net_ptr_in, net_ptr_out, null_cd }, + { "WEBTTY", 0, net_tty_alive, net_tty_status, net_tty_in, net_tty_out, null_cd }, + { "WEBPTR", 0, net_ptr_alive, net_ptr_status, net_ptr_in, net_ptr_out, null_cd }, #else - { "WEBTTY", 0, null_dead, null_status, null_in, null_out, null_cd }, - { "WEBPTR", 0, null_dead, null_status, null_in, null_out, null_cd }, + { "WEBTTY", 0, null_dead, null_status, null_in, null_out, null_cd }, + { "WEBPTR", 0, null_dead, null_status, null_in, null_out, null_cd }, #endif - { "STDIO", 0, stdio_alive, stdio_status, stdio_in, stdio_out, null_cd }, - { "SCKTSRV", 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out, null_cd }, + { "STDIO", 0, stdio_alive, stdio_status, stdio_in, stdio_out, null_cd }, + { "SCKTSRV", 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out, null_cd }, #ifdef HAS_MODEM - { "MODEM", 0, modem_alive, modem_status, modem_in, modem_out, modem_cd }, + { "MODEM", 0, modem_alive, modem_status, modem_in, modem_out, modem_cd }, #else - { "MODEM", 0, null_dead, null_status, null_in, null_out, null_cd }, + { "MODEM", 0, null_dead, null_status, null_in, null_out, null_cd }, #endif - { "VIOKBD", 0, vio_kbd_alive, vio_kbd_status, vio_kbd_in, vio_kbd_out, null_cd }, - { "", 0, null_alive, null_status, null_in, null_out, null_cd } + { "VIOKBD", 0, vio_kbd_alive, vio_kbd_status, vio_kbd_in, vio_kbd_out, null_cd }, + { "", 0, null_alive, null_status, null_in, null_out, null_cd } }; hal_device_t sio[MAX_SIO_PORT][MAX_HAL_DEV]; /* -------------------- HAL utility functions -------------------- */ -static void hal_report(void) { - - int i, j; - - LOG(TAG, "\r\nSIO PORT MAP:\r\n"); - - for (i = 0; i < MAX_SIO_PORT; i++) { - - LOG(TAG, "%s = ", sio_port_name[i]); - j = 0; - - while (sio[i][j].name && j < MAX_HAL_DEV) { - - LOG(TAG, "%s%s", sio[i][j].name, (sio[i][j].fallthrough?"+":" ")); - - j++; - } - LOG(TAG, "\r\n"); - } +static void hal_report(void) +{ + int i, j; + + LOG(TAG, "\r\nSIO PORT MAP:\r\n"); + for (i = 0; i < MAX_SIO_PORT; i++) { + LOG(TAG, "%s = ", sio_port_name[i]); + j = 0; + while (sio[i][j].name && j < MAX_HAL_DEV) { + LOG(TAG, "%s%s", sio[i][j].name, (sio[i][j].fallthrough ? "+" : " ")); + j++; + } + LOG(TAG, "\r\n"); + } } -static int hal_find_device(char *dev) { +static int hal_find_device(char *dev) +{ + int i = 0; - int i=0; - while (i < MAX_HAL_DEV) { - if (!strcmp(dev, devices[i].name)) { - return i; - } - i++; - } - return -1; + while (i < MAX_HAL_DEV) { + if (!strcmp(dev, devices[i].name)) + return i; + i++; + } + return -1; } -static void hal_init(void) { - - int i, j, d; - char *setting; - char match[80]; - char *dev; - - /** - * Initialize HAL with default configuration, as follows: - * - * SIO1.portA.device=WEBTTY,STDIO - * SIO1.portB.device=VIOKBD - * SIO2.portA.device=SCKTSRV - * SIO2.portB.device=MODEM - * - * Notes: - * - all ports end with NULL and that is always alive - * - the first HAL device in the list that is alive will service the request - */ - sio[0][0] = devices[WEBTTYDEV]; - sio[0][1] = devices[STDIODEV]; - sio[0][2] = devices[NULLDEV]; - - sio[1][0] = devices[VIOKBD]; - sio[1][1] = devices[NULLDEV]; - - sio[2][0] = devices[WEBPTRDEV]; - sio[2][1] = devices[SCKTSRVDEV]; - sio[2][2] = devices[NULLDEV]; - - sio[3][0] = devices[MODEMDEV]; - sio[3][1] = devices[NULLDEV]; - - for (i = 0; i < MAX_SIO_PORT; i++) { - - j = 0; - strcpy(match, sio_port_name[i]); - strcat(match, ".device"); - - if ((setting = getenv(match)) != NULL) { - LOGI(TAG, "%s = %s", match, setting); - - strcpy(match, setting); - - dev = strtok(match, ",\r"); - while (dev) { - - char k = dev[strlen(dev) - 1]; - int fallthrough = 0; - if (k == '+') { - dev[strlen(dev) - 1] = 0; - fallthrough = 1; - } - - d = hal_find_device(dev); - LOGI(TAG, "\tAdding %s to %s", dev, sio_port_name[i]); - - if (d >= 0) { - memcpy(&sio[i][j], &devices[d], sizeof(hal_device_t)); - sio[i][j].fallthrough = fallthrough; - j++; - } - dev = strtok(NULL, ",\r"); - } - memcpy(&sio[i][j], &devices[NULLDEV], sizeof(hal_device_t)); - } - } +static void hal_init(void) +{ + int i, j, d; + char *setting; + char match[80]; + char *dev; + + /** + * Initialize HAL with default configuration, as follows: + * + * SIO1.portA.device=WEBTTY,STDIO + * SIO1.portB.device=VIOKBD + * SIO2.portA.device=SCKTSRV + * SIO2.portB.device=MODEM + * + * Notes: + * - all ports end with NULL and that is always alive + * - the first HAL device in the list that is alive will service the request + */ + sio[0][0] = devices[WEBTTYDEV]; + sio[0][1] = devices[STDIODEV]; + sio[0][2] = devices[NULLDEV]; + + sio[1][0] = devices[VIOKBD]; + sio[1][1] = devices[NULLDEV]; + + sio[2][0] = devices[WEBPTRDEV]; + sio[2][1] = devices[SCKTSRVDEV]; + sio[2][2] = devices[NULLDEV]; + + sio[3][0] = devices[MODEMDEV]; + sio[3][1] = devices[NULLDEV]; + + for (i = 0; i < MAX_SIO_PORT; i++) { + j = 0; + strcpy(match, sio_port_name[i]); + strcat(match, ".device"); + + if ((setting = getenv(match)) != NULL) { + LOGI(TAG, "%s = %s", match, setting); + + strcpy(match, setting); + + dev = strtok(match, ",\r"); + while (dev) { + char k = dev[strlen(dev) - 1]; + int fallthrough = 0; + + if (k == '+') { + dev[strlen(dev) - 1] = 0; + fallthrough = 1; + } + + d = hal_find_device(dev); + LOGI(TAG, "\tAdding %s to %s", dev, sio_port_name[i]); + + if (d >= 0) { + memcpy(&sio[i][j], &devices[d], sizeof(hal_device_t)); + sio[i][j].fallthrough = fallthrough; + j++; + } + dev = strtok(NULL, ",\r"); + } + memcpy(&sio[i][j], &devices[NULLDEV], sizeof(hal_device_t)); + } + } } -void hal_reset(void) { - hal_init(); - hal_report(); +void hal_reset(void) +{ + hal_init(); + hal_report(); } /* -------------------- HAL - SIO interface -------------------- */ -void hal_status_in(sio_port_t dev, BYTE *stat) { +void hal_status_in(sio_port_t dev, BYTE *stat) +{ + int p = 0; + BYTE s; - int p = 0; - BYTE s; - *stat = 0; + *stat = 0; next: - while(!sio[dev][p].alive()) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!sio[dev][p].alive()) + p++; - sio[dev][p].status(&s); - *stat |= s; + sio[dev][p].status(&s); + *stat |= s; - if (sio[dev][p].fallthrough) { - p++; - goto next; - } + if (sio[dev][p].fallthrough) { + p++; + goto next; + } } -int hal_data_in(sio_port_t dev) { +int hal_data_in(sio_port_t dev) +{ + int p = 0; + int in = 0; - int p = 0; - int in = 0; next: - while(!sio[dev][p].alive()) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!sio[dev][p].alive()) + p++; - in = sio[dev][p].in(); + in = sio[dev][p].in(); - if (in < 0 && sio[dev][p].fallthrough) { - p++; - goto next; - } else { - return in; - } + if (in < 0 && sio[dev][p].fallthrough) { + p++; + goto next; + } else + return in; } -void hal_data_out(sio_port_t dev, BYTE data) { +void hal_data_out(sio_port_t dev, BYTE data) +{ + int p = 0; - int p = 0; next: - while(!sio[dev][p].alive()) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!sio[dev][p].alive()) + p++; sio[dev][p].out(data); - if (sio[dev][p].fallthrough) { - p++; - goto next; - } + if (sio[dev][p].fallthrough) { + p++; + goto next; + } } -int hal_carrier_detect(sio_port_t dev) { +int hal_carrier_detect(sio_port_t dev) +{ + int p = 0; - int p = 0; - while(!sio[dev][p].alive()) { /* Find the first device that is alive */ - p++; - } + /* Find the first device that is alive */ + while (!sio[dev][p].alive()) + p++; return sio[dev][p].cd(); } diff --git a/iodevices/imsai-hal.h b/iodevices/imsai-hal.h index 4baef04d..f0872b19 100644 --- a/iodevices/imsai-hal.h +++ b/iodevices/imsai-hal.h @@ -16,38 +16,34 @@ #include "sim.h" #include "simdefs.h" -enum sio_port { +typedef enum sio_port { SIO1A, SIO1B, SIO2A, SIO2B, - MAX_SIO_PORT -}; - -typedef enum sio_port sio_port_t; - -enum hal_dev { - WEBTTYDEV, - WEBPTRDEV, - STDIODEV, - SCKTSRVDEV, - MODEMDEV, - VIOKBD, - NULLDEV, - MAX_HAL_DEV -}; - -struct hal_device { - const char *name; - int fallthrough; + MAX_SIO_PORT +} sio_port_t; + +typedef enum hal_dev { + WEBTTYDEV, + WEBPTRDEV, + STDIODEV, + SCKTSRVDEV, + MODEMDEV, + VIOKBD, + NULLDEV, + MAX_HAL_DEV +} hal_dev_t; + +typedef struct hal_device { + const char *name; + int fallthrough; int (*alive)(void); - void (*status)(BYTE *stat); - int (*in)(void); - void (*out)(BYTE data); - int (*cd)(void); -}; - -typedef struct hal_device hal_device_t; + void (*status)(BYTE *stat); + int (*in)(void); + void (*out)(BYTE data); + int (*cd)(void); +} hal_device_t; extern void hal_reset(void); diff --git a/webfrontend/netsrv.c b/webfrontend/netsrv.c index b7b9284e..3389bdff 100644 --- a/webfrontend/netsrv.c +++ b/webfrontend/netsrv.c @@ -55,8 +55,8 @@ static msgbuf_t msg; struct { int queue; - ws_client_t ws_client; - void (*cbfunc)(BYTE *); + ws_client_t ws_client; + void (*cbfunc)(BYTE *); } dev[MAX_WS_CLIENTS]; net_device_t net_device_a[_DEV_MAX] = { @@ -79,6 +79,7 @@ const char *dev_name[] = { }; int last_error = 0; //TODO: replace + /* extern int reset; extern int power; @@ -88,66 +89,69 @@ extern void quit_callback(void); /** * Check if a queue is provisioned */ -int net_device_alive(net_device_t device) { +int net_device_alive(net_device_t device) +{ return dev[device].queue; } -void net_device_service(net_device_t device, void (*cbfunc)(BYTE *data)) { - dev[device].cbfunc = cbfunc; +void net_device_service(net_device_t device, void (*cbfunc)(BYTE *data)) +{ + dev[device].cbfunc = cbfunc; } /** * Assumes the data is: - * TEXT if only a single byte - * BINARY if there are multiple bytes - * TTY & LPT are always BINARY now + * TEXT if only a single byte + * BINARY if there are multiple bytes + * TTY & LPT are always BINARY now */ -void net_device_send(net_device_t device, char *msg, int len) { - +void net_device_send(net_device_t device, char *msg, int len) +{ int op_code; switch (device) { - case DEV_TTY: - case DEV_TTY2: - case DEV_TTY3: - case DEV_PTR: - case DEV_LPT: - op_code = MG_WEBSOCKET_OPCODE_BINARY; - break; - default: - op_code = (len==1)?MG_WEBSOCKET_OPCODE_TEXT:MG_WEBSOCKET_OPCODE_BINARY; - break; + case DEV_TTY: + case DEV_TTY2: + case DEV_TTY3: + case DEV_PTR: + case DEV_LPT: + op_code = MG_WEBSOCKET_OPCODE_BINARY; + break; + default: + op_code = (len == 1) ? MG_WEBSOCKET_OPCODE_TEXT : MG_WEBSOCKET_OPCODE_BINARY; + break; } - if(dev[device].queue) { + if (dev[device].queue) mg_websocket_write(dev[device].ws_client.conn, - op_code, - msg, len); - } + op_code, + msg, len); } /** * Always removes something from the queue is data waiting * returns: - * char if data is waiting in the queue - * -1 if the queue is not open, is empty + * char if data is waiting in the queue + * -1 if the queue is not open, is empty */ -int net_device_get(net_device_t device) { +int net_device_get(net_device_t device) +{ ssize_t res; msgbuf_t msg; if (dev[device].queue) { res = msgrcv(dev[device].queue, &msg, 2, 1L, IPC_NOWAIT); - LOGD(TAG, "GET: device[%d] res[%ld] msg[%ld, %s]", device, res, msg.mtype, msg.mtext); - if (res == 2) { + LOGD(TAG, "GET: device[%d] res[%ld] msg[%ld, %s]", + device, res, msg.mtype, msg.mtext); + if (res == 2) return msg.mtext[0]; - } } return -1; } -int net_device_get_data(net_device_t device, char *dst, int len) { +int net_device_get_data(net_device_t device, char *dst, int len) +{ ssize_t res; msgbuf_t msg; @@ -163,10 +167,11 @@ int net_device_get_data(net_device_t device, char *dst, int len) { /** * Doesn't remove data from the queue * returns: - * 1 if data is waiting in the queue - * 0 if the queue is not open or is empty + * 1 if data is waiting in the queue + * 0 if the queue is not open or is empty */ -int net_device_poll(net_device_t device) { +int net_device_poll(net_device_t device) +{ ssize_t res; msgbuf_t msg; @@ -181,22 +186,22 @@ int net_device_poll(net_device_t device) { return 0; } -request_t *get_request(const HttpdConnection_t *conn) { +request_t *get_request(const HttpdConnection_t *conn) +{ static request_t req; req.mg = mg_get_request_info(conn); - if (!strcmp(req.mg->request_method, "GET")) { + if (!strcmp(req.mg->request_method, "GET")) req.method = HTTP_GET; - } else if (!strcmp(req.mg->request_method, "POST")) { + else if (!strcmp(req.mg->request_method, "POST")) req.method = HTTP_POST; - } else if (!strcmp(req.mg->request_method, "PUT")) { + else if (!strcmp(req.mg->request_method, "PUT")) req.method = HTTP_PUT; - } else if (!strcmp(req.mg->request_method, "DELETE")) { + else if (!strcmp(req.mg->request_method, "DELETE")) req.method = HTTP_DELETE; - } else { + else req.method = HTTP_UNKNOWN; - } //TODO: split query_string on '&' into args[] - for now its all jammed into args[0] req.args[0] = req.mg->query_string; @@ -226,276 +231,292 @@ static void InformWebsockets(struct mg_context *ctx) mg_lock_context(ctx); for (i = 0; i < MAX_WS_CLIENTS; i++) { - if (dev[i].ws_client.state == 2) { + if (dev[i].ws_client.state == 2) mg_websocket_write(dev[i].ws_client.conn, - MG_WEBSOCKET_OPCODE_TEXT, - text, - strlen(text)); - } + MG_WEBSOCKET_OPCODE_TEXT, + text, + strlen(text)); } mg_unlock_context(ctx); } struct utsname uts; -static int SystemHandler(HttpdConnection_t *conn, void *unused) { - request_t *req = get_request(conn); +static int SystemHandler(HttpdConnection_t *conn, void *unused) +{ + request_t *req = get_request(conn); UNUSED(unused); - switch (req->method) { - case HTTP_GET: + switch (req->method) { + case HTTP_GET: LOGD(TAG, "Sending SYS: details."); if (req->args[0] && *req->args[0] == 'm') { + httpdStartResponse(conn, 200); + httpdHeader(conn, "Content-Type", "application/json"); + httpdEndHeaders(conn); - httpdStartResponse(conn, 200); - httpdHeader(conn, "Content-Type", "application/json"); - httpdEndHeaders(conn); - - httpdPrintf(conn, "{ \"machine\": \"" MACHINE "\" }"); + httpdPrintf(conn, "{ \"machine\": \"" MACHINE "\" }"); - return 1; - } + return 1; + } - httpdStartResponse(conn, 200); - httpdHeader(conn, "Content-Type", "application/json"); - httpdEndHeaders(conn); + httpdStartResponse(conn, 200); + httpdHeader(conn, "Content-Type", "application/json"); + httpdEndHeaders(conn); uname(&uts); - httpdPrintf(conn, "{"); + httpdPrintf(conn, "{"); - httpdPrintf(conn, "\"machine\": \"" MACHINE "\", "); + httpdPrintf(conn, "\"machine\": \"" MACHINE "\", "); - httpdPrintf(conn, "\"platform\": \"%s\", ", uts.sysname); + httpdPrintf(conn, "\"platform\": \"%s\", ", uts.sysname); - httpdPrintf(conn, "\"network\": { "); + httpdPrintf(conn, "\"network\": { "); - httpdPrintf(conn, "\"hostname\": \"%s\" ", uts.nodename); + httpdPrintf(conn, "\"hostname\": \"%s\" ", uts.nodename); - httpdPrintf(conn, "}, "); + httpdPrintf(conn, "}, "); - httpdPrintf(conn, "\"paths\": { "); - httpdPrintf(conn, "\"%s\": \"%s\", ", "CONFDIR", confdir); - httpdPrintf(conn, "\"%s\": \"%s\", ", "DISKSDIR", diskdir); - httpdPrintf(conn, "\"%s\": \"%s\" ", "BOOTROM", rompath); - httpdPrintf(conn, "}, "); + httpdPrintf(conn, "\"paths\": { "); + httpdPrintf(conn, "\"%s\": \"%s\", ", "CONFDIR", confdir); + httpdPrintf(conn, "\"%s\": \"%s\", ", "DISKSDIR", diskdir); + httpdPrintf(conn, "\"%s\": \"%s\" ", "BOOTROM", rompath); + httpdPrintf(conn, "}, "); - httpdPrintf(conn, "\"system\": { "); - httpdPrintf(conn, "\"%s\": \"%s\",", "VER", uts.version); - httpdPrintf(conn, "\"%s\": \"%s\",", "MACHINE", uts.machine); - httpdPrintf(conn, "\"free_mem\": %d, ", 0); - httpdPrintf(conn, "\"time\": %ld, ", time(NULL)); - httpdPrintf(conn, "\"uptime\": %d ", 0); - httpdPrintf(conn, "}, "); + httpdPrintf(conn, "\"system\": { "); + httpdPrintf(conn, "\"%s\": \"%s\",", "VER", uts.version); + httpdPrintf(conn, "\"%s\": \"%s\",", "MACHINE", uts.machine); + httpdPrintf(conn, "\"free_mem\": %d, ", 0); + httpdPrintf(conn, "\"time\": %ld, ", time(NULL)); + httpdPrintf(conn, "\"uptime\": %d ", 0); + httpdPrintf(conn, "}, "); - httpdPrintf(conn, "\"state\": { "); - httpdPrintf(conn, "\"last_error\": %d, ", last_error); - httpdPrintf(conn, "\"cpu_error\": %d, ", cpu_error); - httpdPrintf(conn, "\"reset\": %d, ", 0 /*reset*/); - httpdPrintf(conn, "\"power\": %d ", 0 /*power*/); - httpdPrintf(conn, "}, "); + httpdPrintf(conn, "\"state\": { "); + httpdPrintf(conn, "\"last_error\": %d, ", last_error); + httpdPrintf(conn, "\"cpu_error\": %d, ", cpu_error); + httpdPrintf(conn, "\"reset\": %d, ", 0 /*reset*/); + httpdPrintf(conn, "\"power\": %d ", 0 /*power*/); + httpdPrintf(conn, "}, "); - httpdPrintf(conn, "\"about\": { "); - httpdPrintf(conn, "\"%s\": \"%s\", ", "USR_COM", USR_COM); - httpdPrintf(conn, "\"%s\": \"%s\", ", "USR_REL", USR_REL); - httpdPrintf(conn, "\"%s\": \"%s\", ", "USR_CPR", USR_CPR); - httpdPrintf(conn, "\"%s\": \"%s\", ", "cpu", cpu==Z80?"Z80":"I8080"); - if(x_flag) { - httpdPrintf(conn, "\"%s\": \"%s\", ", "bootrom", xfn); - } + httpdPrintf(conn, "\"about\": { "); + httpdPrintf(conn, "\"%s\": \"%s\", ", "USR_COM", USR_COM); + httpdPrintf(conn, "\"%s\": \"%s\", ", "USR_REL", USR_REL); + httpdPrintf(conn, "\"%s\": \"%s\", ", "USR_CPR", USR_CPR); + httpdPrintf(conn, "\"%s\": \"%s\", ", "cpu", cpu == Z80 ? "Z80" : "I8080"); + if (x_flag) + httpdPrintf(conn, "\"%s\": \"%s\", ", "bootrom", xfn); #ifdef FRONTPANEL - if (F_flag) { - httpdPrintf(conn, "\"%s\": %d, ", "cpa", 1); - } + if (F_flag) + httpdPrintf(conn, "\"%s\": %d, ", "cpa", 1); #endif - httpdPrintf(conn, "\"%s\": %d ", "clock", f_value); - httpdPrintf(conn, "} "); + httpdPrintf(conn, "\"%s\": %d ", "clock", f_value); + httpdPrintf(conn, "} "); #ifdef HAS_HAL #ifdef IMSAISIM - httpdPrintf(conn, ", \"hal\": \"SIO Ports\""); - httpdPrintf(conn, ", \"hal_ports\": [ "); - for(int i = 0; i < MAX_SIO_PORT; i++) { - httpdPrintf(conn, "{ "); - httpdPrintf(conn, "\"%s\": \"%s\", ", "name", sio_port_name[i]); - int j = 0; - httpdPrintf(conn, "\"%s\": [ ", "devices"); - while (sio[i][j].name && j < MAX_HAL_DEV) { - if (*sio[i][j].name) - httpdPrintf(conn, "%s\"%s%s\"", - (j==0)?"":", ", - sio[i][j].name, - sio[i][j].fallthrough?"+":"" - ); - j++; - } - httpdPrintf(conn, "] }%s ", (i < (MAX_SIO_PORT-1))?",":""); - } - httpdPrintf(conn, "]"); + httpdPrintf(conn, ", \"hal\": \"SIO Ports\""); + httpdPrintf(conn, ", \"hal_ports\": [ "); + for (int i = 0; i < MAX_SIO_PORT; i++) { + httpdPrintf(conn, "{ "); + httpdPrintf(conn, "\"%s\": \"%s\", ", "name", sio_port_name[i]); + + int j = 0; + httpdPrintf(conn, "\"%s\": [ ", "devices"); + while (sio[i][j].name && j < MAX_HAL_DEV) { + if (*sio[i][j].name) + httpdPrintf(conn, "%s\"%s%s\"", + (j == 0) ? "" : ", ", + sio[i][j].name, + sio[i][j].fallthrough ? "+" : "" + ); + j++; + } + httpdPrintf(conn, "] }%s ", (i < (MAX_SIO_PORT - 1)) ? "," : ""); + } + httpdPrintf(conn, "]"); #endif #ifdef CROMEMCOSIM - httpdPrintf(conn, ", \"hal\": \"TU-ART Devices\""); - httpdPrintf(conn, ", \"hal_ports\": [ "); - for(int i = 0; i < MAX_TUART_PORT; i++) { - httpdPrintf(conn, "{ "); - httpdPrintf(conn, "\"%s\": \"%s\", ", "name", tuart_port_name[i]); - int j = 0; - httpdPrintf(conn, "\"%s\": [ ", "devices"); - while (tuart[i][j].name && j < MAX_HAL_DEV) { - if (*tuart[i][j].name) - httpdPrintf(conn, "%s\"%s%s\"", - (j==0)?"":", ", - tuart[i][j].name, - tuart[i][j].fallthrough?"+":"" - ); - j++; - } - httpdPrintf(conn, "] }%s ", (i < (MAX_TUART_PORT-1))?",":""); - } - httpdPrintf(conn, "]"); + httpdPrintf(conn, ", \"hal\": \"TU-ART Devices\""); + httpdPrintf(conn, ", \"hal_ports\": [ "); + for (int i = 0; i < MAX_TUART_PORT; i++) { + httpdPrintf(conn, "{ "); + httpdPrintf(conn, "\"%s\": \"%s\", ", "name", tuart_port_name[i]); + + int j = 0; + httpdPrintf(conn, "\"%s\": [ ", "devices"); + while (tuart[i][j].name && j < MAX_HAL_DEV) { + if (*tuart[i][j].name) + httpdPrintf(conn, "%s\"%s%s\"", + (j == 0) ? "" : ", ", + tuart[i][j].name, + tuart[i][j].fallthrough ? "+" : "" + ); + j++; + } + httpdPrintf(conn, "] }%s ", (i < (MAX_TUART_PORT - 1)) ? "," : ""); + } + httpdPrintf(conn, "]"); #endif #endif #ifdef HAS_CONFIG - httpdPrintf(conn, ", \"memmap\": [ "); - - for (int i=0; i < MAXMEMMAP; i++) { - if (memconf[M_value][i].size) { + httpdPrintf(conn, ", \"memmap\": [ "); + + for (int i = 0; i < MAXMEMMAP; i++) { + if (memconf[M_value][i].size) { + if (i > 0) + httpdPrintf(conn, ", "); + httpdPrintf(conn, "{ \"type\": \"%s\"", + (memconf[M_value][i].type == MEM_RW) ? "RAM" : "ROM"); + httpdPrintf(conn, ", \"from\": %d", + memconf[M_value][i].spage << 8); + httpdPrintf(conn, ", \"to\": %d", + ((memconf[M_value][i].spage << 8) + + (memconf[M_value][i].size << 8) - 1)); + if (memconf[M_value][i].type == MEM_RO + && memconf[M_value][i].rom_file) + httpdPrintf(conn, ", \"file\": \"%s\"", + memconf[M_value][i].rom_file); + httpdPrintf(conn, "}"); + } + } + httpdPrintf(conn, "]"); - if (i > 0) httpdPrintf(conn, ", "); - httpdPrintf(conn, "{ \"type\": \"%s\"", (memconf[M_value][i].type==MEM_RW)?"RAM":"ROM"); - httpdPrintf(conn, ", \"from\": %d", memconf[M_value][i].spage << 8); - httpdPrintf(conn, ", \"to\": %d", (memconf[M_value][i].spage << 8) + (memconf[M_value][i].size << 8) - 1); - if (memconf[M_value][i].type==MEM_RO && memconf[M_value][i].rom_file) - httpdPrintf(conn, ", \"file\": \"%s\"", memconf[M_value][i].rom_file); - httpdPrintf(conn, "}"); - } - } + httpdPrintf(conn, ", \"memextra\": [ "); - httpdPrintf(conn, "]"); + if (boot_switch[M_value]) + httpdPrintf(conn, "\"Power-on jump address %04XH\", ", + boot_switch[M_value]); + if (R_flag) + httpdPrintf(conn, "\"%s\", ", BANKED_ROM_MSG); - httpdPrintf(conn, ", \"memextra\": [ "); + if (num_banks) + httpdPrintf(conn, "\"MMU has %d additional RAM banks of %d KB\",", + num_banks, SEGSIZ >> 10); - if (boot_switch[M_value]) { - httpdPrintf(conn, "\"Power-on jump address %04XH\", ", boot_switch[M_value]); - } - if (R_flag) { - httpdPrintf(conn, "\"%s\", ", BANKED_ROM_MSG); - } - - if (num_banks) { - httpdPrintf(conn, "\"MMU has %d additional RAM banks of %d KB\",", num_banks, SEGSIZ >> 10); - } - - httpdPrintf(conn, " \"\" ]"); + httpdPrintf(conn, " \"\" ]"); #endif - { - int i=0, o=0; - const char *t1, *t2; - extern char **environ; - char buf[2048]; - - httpdPrintf(conn, ", \"env\": { "); - while(environ[i] != NULL) { - strcpy(buf, environ[i]); - t1 = strtok(buf, "="); - t2 = strtok(NULL, "\0"); + { + int i = 0, o = 0; + const char *t1, *t2; + extern char **environ; + char buf[2048]; + + httpdPrintf(conn, ", \"env\": { "); + while (environ[i] != NULL) { + strcpy(buf, environ[i]); + t1 = strtok(buf, "="); + t2 = strtok(NULL, "\0"); #define BULLET "\xE2\x80\xA2" - if(!strcmp(t1, "PASSWORD") && (getenv("WIFI.password.hide") != NULL)) - t2 = BULLET BULLET BULLET BULLET BULLET BULLET BULLET BULLET; - /* Filter out only TERM and non-shell environment variables of the form '*.*' ie. contain '.' */ - if(!strcmp(t1, "TERM") || index(t1, '.')) - httpdPrintf(conn, "%s \"%s\": \"%s\" ", (o++)==0?"":",", t1, (t2==NULL)?"":t2); - i++; - } - httpdPrintf(conn, "} "); - } - - httpdPrintf(conn, "}"); + if (!strcmp(t1, "PASSWORD") + && (getenv("WIFI.password.hide") != NULL)) + t2 = BULLET BULLET BULLET BULLET + BULLET BULLET BULLET BULLET; + /* Filter out only TERM and non-shell environment + variables of the form '*.*' ie. contain '.' */ + if (!strcmp(t1, "TERM") || index(t1, '.')) + httpdPrintf(conn, "%s \"%s\": \"%s\" ", + (o++) == 0 ? "" : ",", + t1, (t2 == NULL) ? "" : t2); + i++; + } + httpdPrintf(conn, "} "); + } + + httpdPrintf(conn, "}"); break; - case HTTP_DELETE: - httpdStartResponse(conn, 205); + case HTTP_DELETE: + httpdStartResponse(conn, 205); httpdEndHeaders(conn); //TODO: make this a bit smarter // quit_callback(); break; default: httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' - httpdEndHeaders(conn); - break; + httpdEndHeaders(conn); + break; } return 1; } -int DirectoryHandler(HttpdConnection_t *conn, void *path) { - request_t *req = get_request(conn); - struct dirent *pDirent; - DIR *pDir; - int i = 0; - struct stat sb; - char fullpath[MAX_LFN]; - bool showSize = false; - - if (req->args[0] && *req->args[0] == 'S') { - showSize = true; - } - - switch (req->method) { - case HTTP_GET: - pDir = opendir ((char *)path); - if (pDir == NULL) { - httpdStartResponse(conn, 404); //http error code 'Not Found' - httpdEndHeaders(conn); - } else { - httpdStartResponse(conn, 200); - httpdHeader(conn, "Content-Type", "application/json"); - httpdEndHeaders(conn); - - httpdPrintf(conn, "["); - - while ((pDirent = readdir(pDir)) != NULL) { - LOGD(TAG, "GET directory: %s type: %d", pDirent->d_name, pDirent->d_type); - snprintf(fullpath, MAX_LFN, "%s/%s", (char *) path, pDirent->d_name); - /* - * not working with some filesystems like Linux xfs, need to use stat() - * if (pDirent->d_type==DT_REG) { - */ - if (stat(fullpath, &sb) != -1 && S_ISREG(sb.st_mode)) { - if (showSize) { - httpdPrintf(conn, "%c{ \"%s\":\"%s\",", (i++ > 0)?',':' ', "filename",pDirent->d_name); - httpdPrintf(conn, "\"%s\":%lld}", "size", (long long) sb.st_size); - } else { - httpdPrintf(conn, "%c\"%s\"", (i++ > 0)?',':' ', pDirent->d_name); +int DirectoryHandler(HttpdConnection_t *conn, void *path) +{ + request_t *req = get_request(conn); + struct dirent *pDirent; + DIR *pDir; + int i = 0; + struct stat sb; + char fullpath[MAX_LFN]; + bool showSize = false; + + if (req->args[0] && *req->args[0] == 'S') + showSize = true; + + switch (req->method) { + case HTTP_GET: + pDir = opendir((char *)path); + if (pDir == NULL) { + httpdStartResponse(conn, 404); //http error code 'Not Found' + httpdEndHeaders(conn); + } else { + httpdStartResponse(conn, 200); + httpdHeader(conn, "Content-Type", "application/json"); + httpdEndHeaders(conn); + + httpdPrintf(conn, "["); + + while ((pDirent = readdir(pDir)) != NULL) { + LOGD(TAG, "GET directory: %s type: %d", + pDirent->d_name, pDirent->d_type); + snprintf(fullpath, MAX_LFN, "%s/%s", + (char *) path, pDirent->d_name); + /* + * not working with some filesystems like Linux xfs, + * need to use stat() + * if (pDirent->d_type==DT_REG) { + */ + if (stat(fullpath, &sb) != -1 && S_ISREG(sb.st_mode)) { + if (showSize) { + httpdPrintf(conn, "%c{ \"%s\":\"%s\",", + (i++ > 0) ? ',' : ' ', + "filename", pDirent->d_name); + httpdPrintf(conn, "\"%s\":%lld}", "size", + (long long) sb.st_size); + } else + httpdPrintf(conn, "%c\"%s\"", + (i++ > 0) ? ',' : ' ', + pDirent->d_name); + } } - } - } - closedir (pDir); - httpdPrintf(conn, "]"); - } + closedir(pDir); + httpdPrintf(conn, "]"); + } break; default: - httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' - httpdEndHeaders(conn); + httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' + httpdEndHeaders(conn); break; - } + } return 1; } -int UploadHandler(HttpdConnection_t *conn, void *path) { - request_t *req = get_request(conn); +int UploadHandler(HttpdConnection_t *conn, void *path) +{ + request_t *req = get_request(conn); int filelen; char output[MAX_LFN]; - switch (req->method) { - case HTTP_PUT: + switch (req->method) { + case HTTP_PUT: strncpy(output, (char *) path, MAX_LFN - 1); output[MAX_LFN - 1] = '\0'; - if (output[strlen(output)-1] != '/') + if (output[strlen(output) -1] != '/') strncat(output, "/", MAX_LFN - strlen(output)); strncat(output, req->args[0], MAX_LFN - strlen(output)); @@ -503,76 +524,77 @@ int UploadHandler(HttpdConnection_t *conn, void *path) { //filelen = 0; filelen = mg_store_body(conn, output); - LOGI(TAG, "%d bytes written to %s, received %d", filelen, output, (int) req->len); - httpdStartResponse(conn, 200); - httpdHeader(conn, "Content-Type", "application/json"); - httpdEndHeaders(conn); + LOGI(TAG, "%d bytes written to %s, received %d", filelen, output, (int) req->len); + httpdStartResponse(conn, 200); + httpdHeader(conn, "Content-Type", "application/json"); + httpdEndHeaders(conn); - httpdPrintf(conn, "{"); - httpdPrintf(conn, "\"filename\": \"%s\", ", output); - httpdPrintf(conn, "\"size\": \"%d\" ", filelen); - httpdPrintf(conn, "}"); + httpdPrintf(conn, "{"); + httpdPrintf(conn, "\"filename\": \"%s\", ", output); + httpdPrintf(conn, "\"size\": \"%d\" ", filelen); + httpdPrintf(conn, "}"); break; default: - httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' - httpdEndHeaders(conn); + httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' + httpdEndHeaders(conn); break; - } + } return 1; } -static int ConfigHandler(HttpdConnection_t *conn, void *path) { - request_t *req = get_request(conn); +static int ConfigHandler(HttpdConnection_t *conn, void *path) +{ + request_t *req = get_request(conn); - switch (req->method) { - case HTTP_GET: - DirectoryHandler(conn, path); + switch (req->method) { + case HTTP_GET: + DirectoryHandler(conn, path); break; - case HTTP_PUT: - UploadHandler(conn, path); + case HTTP_PUT: + UploadHandler(conn, path); break; default: - httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' - httpdEndHeaders(conn); + httpdStartResponse(conn, 405); //http error code 'Method Not Allowed' + httpdEndHeaders(conn); break; - } + } return 1; } -static int WebSocketConnectHandler(const HttpdConnection_t *conn, void *device) { +static int WebSocketConnectHandler(const HttpdConnection_t *conn, void *device) +{ struct mg_context *ctx = mg_get_context(conn); int reject = 1; int res; net_device_t d = *(net_device_t *) device; mg_lock_context(ctx); - if (dev[d].ws_client.conn == NULL) { - dev[d].ws_client.conn = (struct mg_connection *)conn; - dev[d].ws_client.state = 1; - mg_set_user_connection_data(dev[d].ws_client.conn, (void *)(&(dev[d].ws_client))); - - switch (d) { - case DEV_TTY: - case DEV_TTY2: - case DEV_TTY3: - case DEV_PTR: - case DEV_VIO: - case DEV_LPT: - case DEV_DZLR: - case DEV_88ACC: - case DEV_D7AIO: - res = msgget(IPC_PRIVATE, 0644 | IPC_CREAT); //TODO: check flags - if (res > 0) { - dev[d].queue = res; - } else { - perror("msgget()"); - } - break; - default: - break; - } - reject = 0; + if (dev[d].ws_client.conn == NULL) { + dev[d].ws_client.conn = (struct mg_connection *) conn; + dev[d].ws_client.state = 1; + mg_set_user_connection_data(dev[d].ws_client.conn, (void *) (&(dev[d].ws_client))); + + switch (d) { + case DEV_TTY: + case DEV_TTY2: + case DEV_TTY3: + case DEV_PTR: + case DEV_VIO: + case DEV_LPT: + case DEV_DZLR: + case DEV_88ACC: + case DEV_D7AIO: + res = msgget(IPC_PRIVATE, 0644 | IPC_CREAT); //TODO: check flags + if (res > 0) + dev[d].queue = res; + else + perror("msgget()"); + break; + default: + break; } + reject = 0; + } mg_unlock_context(ctx); LOGD(TAG, "Websocket client %s", (reject ? "rejected" : "accepted")); @@ -580,7 +602,8 @@ static int WebSocketConnectHandler(const HttpdConnection_t *conn, void *device) return reject; } -static void WebSocketReadyHandler(HttpdConnection_t *conn, void *device) { +static void WebSocketReadyHandler(HttpdConnection_t *conn, void *device) +{ const char *text = "\r\nConnected to the OSX port of Z80PACK\r\n"; ws_client_t *client = (ws_client_t *) mg_get_user_connection_data(conn); net_device_t d = *(net_device_t *) device; @@ -590,6 +613,7 @@ static void WebSocketReadyHandler(HttpdConnection_t *conn, void *device) { if (d == DEV_VIO) { BYTE mode = dma_read(0xf7ff); + dma_write(0xf7ff, 0x00); sleep_for_ms(100); dma_write(0xf7ff, mode); @@ -601,18 +625,15 @@ static void WebSocketReadyHandler(HttpdConnection_t *conn, void *device) { } static int WebsocketDataHandler(HttpdConnection_t *conn, - int bits, - char *data, - size_t len, - void *device) { - + int bits, char *data, size_t len, void *device) +{ net_device_t d = *(net_device_t *) device; UNUSED(conn); #ifdef DEBUG - fprintf(stdout, "Websocket [%d] got %z bytes of ", (int)device, len); - switch (((unsigned char)bits) & 0x0F) { + fprintf(stdout, "Websocket [%d] got %z bytes of ", (int) device, len); + switch (((unsigned char) bits) & 0x0F) { case MG_WEBSOCKET_OPCODE_CONTINUATION: fprintf(stdout, "continuation"); break; @@ -632,7 +653,7 @@ static int WebsocketDataHandler(HttpdConnection_t *conn, fprintf(stdout, "pong"); break; default: - fprintf(stdout, "unknown(%1xh)", ((unsigned char)bits) & 0x0F); + fprintf(stdout, "unknown(%1xh)", ((unsigned char) bits) & 0x0F); break; } fprintf(stdout, " data:\r\n"); @@ -640,83 +661,82 @@ static int WebsocketDataHandler(HttpdConnection_t *conn, fprintf(stdout, "\r\n"); #endif - if ((((unsigned char)bits) & 0x0F) == MG_WEBSOCKET_OPCODE_BINARY) { - - switch (d) { + if ((((unsigned char) bits) & 0x0F) == MG_WEBSOCKET_OPCODE_BINARY) { + switch (d) { case DEV_D7AIO: if (dev[DEV_D7AIO].cbfunc != NULL && (len == 8)) { - (*(dev[DEV_D7AIO].cbfunc))((BYTE *)data); - } + (*(dev[DEV_D7AIO].cbfunc))((BYTE *) data); + } break; case DEV_PTR: if (len != 1) { - LOGW(TAG, "Websocket received too many [%d] characters", (int)len); + LOGW(TAG, "Websocket received too many [%d] characters", + (int) len); return 0; } - msg.mtype = 1L; - msg.mtext[0] = data[0]; - msg.mtext[1] = '\0'; - if (msgsnd(dev[d].queue, &msg, 2, IPC_NOWAIT)) { - if (errno == EAGAIN) { + msg.mtype = 1L; + msg.mtext[0] = data[0]; + msg.mtext[1] = '\0'; + if (msgsnd(dev[d].queue, &msg, 2, IPC_NOWAIT)) { + if (errno == EAGAIN) { LOGW(TAG, "%s Overflow", dev_name[d]); - } else { + } else perror("msgsnd()"); - } return 0; - }; - break; + }; + break; case DEV_88ACC: // LOGI(TAG, "rec: %d, %d", (int)len, (BYTE)*data); - msg.mtype = 1L; - memcpy(msg.mtext, data, len); + msg.mtype = 1L; + memcpy(msg.mtext, data, len); if (msgsnd(dev[d].queue, &msg, len, IPC_NOWAIT)) { - if (errno == EAGAIN) { + if (errno == EAGAIN) { LOGW(TAG, "%s Overflow", dev_name[d]); - } else { + } else perror("msgsnd()"); - } return 0; - }; + }; break; default: break; }; } - if ((((unsigned char)bits) & 0x0F) == MG_WEBSOCKET_OPCODE_TEXT) { - - switch (d) { + if ((((unsigned char) bits) & 0x0F) == MG_WEBSOCKET_OPCODE_TEXT) { + switch (d) { case DEV_LPT: - if (len == 1 && *data == 'R') lpt_reset(); + if (len == 1 && *data == 'R') + lpt_reset(); break; - case DEV_TTY: - case DEV_TTY2: - case DEV_TTY3: - case DEV_VIO: + case DEV_TTY: + case DEV_TTY2: + case DEV_TTY3: + case DEV_VIO: if (len != 1) { - LOGW(TAG, "Websocket received too many [%d] characters", (int)len); + LOGW(TAG, "Websocket received too many [%d] characters", + (int) len); return 0; } - msg.mtype = 1L; - msg.mtext[0] = data[0]; - msg.mtext[1] = '\0'; - if (msgsnd(dev[d].queue, &msg, 2, IPC_NOWAIT)) { - if (errno == EAGAIN) { + msg.mtype = 1L; + msg.mtext[0] = data[0]; + msg.mtext[1] = '\0'; + if (msgsnd(dev[d].queue, &msg, 2, IPC_NOWAIT)) { + if (errno == EAGAIN) { LOGW(TAG, "%s Overflow", dev_name[d]); - } else { + } else perror("msgsnd()"); - } return 0; - }; - break; - default: - break; + }; + break; + default: + break; }; - } + } return 1; } -static void WebSocketCloseHandler(const HttpdConnection_t *conn, void *device) { +static void WebSocketCloseHandler(const HttpdConnection_t *conn, void *device) +{ struct mg_context *ctx = mg_get_context(conn); ws_client_t *client = (ws_client_t *) mg_get_user_connection_data(conn); net_device_t d = *(net_device_t *) device; @@ -728,9 +748,8 @@ static void WebSocketCloseHandler(const HttpdConnection_t *conn, void *device) { LOGI(TAG, "WS CLIENT CLOSED %s", dev_name[d]); - if (dev[d].queue && msgctl(dev[d].queue, IPC_RMID, NULL) == -1) { + if (dev[d].queue && msgctl(dev[d].queue, IPC_RMID, NULL) == -1) perror("msgctl()"); - } dev[d].queue = 0; LOGD(TAG, "Message queue closed (%d) [%08X]", d, dev[d].queue); @@ -738,8 +757,8 @@ static void WebSocketCloseHandler(const HttpdConnection_t *conn, void *device) { static struct mg_context *ctx = NULL; -void stop_net_services (void) { - +void stop_net_services(void) +{ if (ctx != NULL) { InformWebsockets(ctx); @@ -752,30 +771,33 @@ void stop_net_services (void) { } } -int start_net_services (int port) { +int start_net_services(int port) +{ //TODO: add config for DOCUMENT_ROOT - char sport[6]; + char sport[6]; #ifdef SYSDOCROOT struct stat sbuf; #endif const char *options[] = { - "document_root", - DOCUMENT_ROOT, - "listening_ports", - sport, - "request_timeout_ms", - "10000", - "error_log_file", - "error.log", - "websocket_timeout_ms", - "3600000", - "enable_auth_domain_check", - "no", + "document_root", + DOCUMENT_ROOT, + "listening_ports", + sport, + "request_timeout_ms", + "10000", + "error_log_file", + "error.log", + "websocket_timeout_ms", + "3600000", + "enable_auth_domain_check", + "no", "url_rewrite_patterns", - "/" MACHINE "/disks/=./disks/, /" MACHINE "/conf/=./conf/, /" MACHINE "/printer.txt=./printer.txt", - 0}; + "/" MACHINE "/disks/=./disks/, /" MACHINE "/conf/=./conf/, /" + MACHINE "/printer.txt=./printer.txt", + 0 + }; struct mg_callbacks callbacks; @@ -783,7 +805,7 @@ int start_net_services (int port) { struct mg_server_ports ports[32]; int port_cnt, n; int err = 0; - const struct mg_option *opts; + const struct mg_option *opts; #endif atexit(stop_net_services); @@ -791,12 +813,11 @@ int start_net_services (int port) { snprintf(sport, sizeof(sport), "%d", port); #ifdef SYSDOCROOT - if (stat(DOCUMENT_ROOT, &sbuf) == -1 || !S_ISDIR(sbuf.st_mode)) { + if (stat(DOCUMENT_ROOT, &sbuf) == -1 || !S_ISDIR(sbuf.st_mode)) options[1] = SYSDOCROOT; - } #endif - /* Start CivetWeb web server */ + /* Start CivetWeb web server */ memset(&callbacks, 0, sizeof(callbacks)); callbacks.log_message = log_message; @@ -809,80 +830,80 @@ int start_net_services (int port) { } //TODO: sort out all the paths for the handlers - mg_set_request_handler(ctx, "/system", SystemHandler, 0); - mg_set_request_handler(ctx, "/conf", ConfigHandler, (void *) "conf"); - mg_set_request_handler(ctx, "/library", LibraryHandler, 0); - mg_set_request_handler(ctx, "/disks", DiskHandler, 0); + mg_set_request_handler(ctx, "/system", SystemHandler, 0); + mg_set_request_handler(ctx, "/conf", ConfigHandler, (void *) "conf"); + mg_set_request_handler(ctx, "/library", LibraryHandler, 0); + mg_set_request_handler(ctx, "/disks", DiskHandler, 0); mg_set_websocket_handler(ctx, "/tty", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_TTY]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_TTY]); mg_set_websocket_handler(ctx, "/tty2", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_TTY2]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_TTY2]); mg_set_websocket_handler(ctx, "/tty3", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_TTY3]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_TTY3]); mg_set_websocket_handler(ctx, "/ptr", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_PTR]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_PTR]); mg_set_websocket_handler(ctx, "/lpt", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_LPT]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_LPT]); mg_set_websocket_handler(ctx, "/vio", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_VIO]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_VIO]); mg_set_websocket_handler(ctx, "/dazzler", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_DZLR]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_DZLR]); mg_set_websocket_handler(ctx, "/cpa", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_CPA]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_CPA]); mg_set_websocket_handler(ctx, "/acc", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_88ACC]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_88ACC]); mg_set_websocket_handler(ctx, "/d7aio", - WebSocketConnectHandler, - WebSocketReadyHandler, - WebsocketDataHandler, - WebSocketCloseHandler, - (void *) &net_device_a[DEV_D7AIO]); + WebSocketConnectHandler, + WebSocketReadyHandler, + WebsocketDataHandler, + WebSocketCloseHandler, + (void *) &net_device_a[DEV_D7AIO]); #ifdef DEBUG /* List all listening ports */ @@ -893,4 +914,5 @@ int start_net_services (int port) { return EXIT_SUCCESS; } + #endif /* HAS_NETSERVER */ diff --git a/webfrontend/netsrv.h b/webfrontend/netsrv.h index 528b0f97..61e6b283 100644 --- a/webfrontend/netsrv.h +++ b/webfrontend/netsrv.h @@ -35,12 +35,11 @@ enum net_device { DEV_PTR, _DEV_MAX }; - typedef enum net_device net_device_t; typedef struct msgbuf_s { - long mtype; - unsigned char mtext[128]; + long mtype; + unsigned char mtext[128]; } msgbuf_t; typedef struct ws_client { @@ -56,14 +55,14 @@ extern int net_device_get_data(net_device_t device, char *dst, int len); extern int net_device_poll(net_device_t device); /* -* convenience macros for http output -*/ + * convenience macros for http output + */ typedef struct mg_connection HttpdConnection_t; -#define httpdPrintf(conn, args...) mg_printf(conn, args) -#define httpdStartResponse(conn, code) mg_printf(conn, "HTTP/1.1 %d OK\r\n", code) -#define httpdHeader(conn, key, val) mg_printf(conn, "%s: %s\r\n", key, val) -#define httpdEndHeaders(conn) mg_printf(conn, "\r\n") +#define httpdPrintf(conn, args...) mg_printf(conn, args) +#define httpdStartResponse(conn, code) mg_printf(conn, "HTTP/1.1 %d OK\r\n", code) +#define httpdHeader(conn, key, val) mg_printf(conn, "%s: %s\r\n", key, val) +#define httpdEndHeaders(conn) mg_printf(conn, "\r\n") #define _HTTP_MAX_ARGS 8 @@ -74,7 +73,6 @@ enum http_method { HTTP_DELETE, HTTP_UNKNOWN }; - typedef enum http_method http_method_t; typedef struct request { @@ -89,7 +87,7 @@ extern request_t *get_request(const HttpdConnection_t *conn); extern int DirectoryHandler(HttpdConnection_t *conn, void *path); extern int UploadHandler(HttpdConnection_t *conn, void *path); -extern void stop_net_services (void); -extern int start_net_services (int port); +extern void stop_net_services(void); +extern int start_net_services(int port); #endif /* !NETSRV_INC */ From e2ee0d73a389702ba8c7ad76c92c09eca3779dd1 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 13:00:26 +0100 Subject: [PATCH 17/19] boolify David McNaughton's code and clean-up netsrv.[ch] Moved types only used in netsrv.c from netsrv.h to netsrv.c. Made internal functions/variables of netsrv.c static. --- iodevices/cromemco-88ccc.c | 16 +++++----- iodevices/cromemco-hal.c | 58 ++++++++++++++++----------------- iodevices/cromemco-hal.h | 6 ++-- iodevices/diskmanager.c | 6 ++-- iodevices/generic-at-modem.c | 22 ++++++------- iodevices/generic-at-modem.h | 4 +-- iodevices/imsai-hal.c | 62 ++++++++++++++++++------------------ iodevices/imsai-hal.h | 8 ++--- iodevices/imsai-sio2.c | 12 +++---- webfrontend/netsrv.c | 24 ++++++++++---- webfrontend/netsrv.h | 22 +++---------- 11 files changed, 119 insertions(+), 121 deletions(-) diff --git a/iodevices/cromemco-88ccc.c b/iodevices/cromemco-88ccc.c index 8cc100a9..b5c0993d 100644 --- a/iodevices/cromemco-88ccc.c +++ b/iodevices/cromemco-88ccc.c @@ -33,7 +33,7 @@ static const char *TAG = "88CCC"; /* 88CCC stuff */ -static int state; +static bool state; static WORD dma_addr; static BYTE flags; static BYTE format; @@ -106,11 +106,11 @@ static void *store_image(void *arg) LOGD(TAG, "Time: %d", tdiff); - state = 0; + state = false; } /* DMA complete, end the thread */ - state = 0; + state = false; thread = 0; pthread_exit(NULL); } @@ -121,7 +121,7 @@ void cromemco_88ccc_ctrl_a_out(BYTE data) if (data & 0x80) { if (net_device_alive(DEV_88ACC)) { - state = 1; + state = true; if (thread == 0) { if (pthread_create(&thread, NULL, store_image, (void *) NULL)) { @@ -134,11 +134,11 @@ void cromemco_88ccc_ctrl_a_out(BYTE data) } else { /* No 88ACC camera attached */ LOGW(TAG, "No Cromemeco Cyclops 88ACC attached."); - state = 0; + state = false; } } else { - if (state == 1) { - state = 0; + if (state) { + state = false; sleep_for_ms(50); /* Arbitrary 50ms timeout to let thread exit after state change, TODO: maybe should end thread? */ @@ -160,7 +160,7 @@ void cromemco_88ccc_ctrl_c_out(BYTE data) BYTE cromemco_88ccc_ctrl_a_in(void) { /* return flags along with state in the msb */ - return flags | (state << 7); + return flags | (state ? 128 : 0); } #endif /* HAS_NETSERVER && HAS_CYCLOPS */ diff --git a/iodevices/cromemco-hal.c b/iodevices/cromemco-hal.c index 2117e5c7..423b5088 100644 --- a/iodevices/cromemco-hal.c +++ b/iodevices/cromemco-hal.c @@ -38,19 +38,19 @@ static const char *TAG = "HAL"; /* -------------------- NULL device HAL -------------------- */ -static int null_alive(int dev) +static bool null_alive(int dev) { UNUSED(dev); - return 1; /* NULL is always alive */ + return true; /* NULL is always alive */ } #if !defined(HAS_NETSERVER) || !defined(HAS_MODEM) -static int null_dead(int dev) +static bool null_dead(int dev) { UNUSED(dev); - return 0; /* NULL is always dead */ + return false; /* NULL is always dead */ } #endif @@ -81,14 +81,14 @@ static void null_out(int dev, BYTE data) #ifdef HAS_NETSERVER -static int net_tty_alive(int dev) +static bool net_tty_alive(int dev) { if (n_flag) { // LOG(TAG, "WEBTTY %d: %d\r\n", dev, net_device_alive(dev)); /* WEBTTY is only alive if websocket is connected */ return net_device_alive((net_device_t) dev); } else - return 0; + return false; } static void net_tty_status(int dev, BYTE *stat) @@ -119,11 +119,11 @@ static void net_tty_out(int dev, BYTE data) /* -------------------- STDIO HAL -------------------- */ -static int stdio_alive(int dev) +static bool stdio_alive(int dev) { UNUSED(dev); - return 1; /* STDIO is always alive */ + return true; /* STDIO is always alive */ } static void stdio_status(int dev, BYTE *stat) @@ -193,9 +193,9 @@ static void stdio_out(int dev, BYTE data) /* -------------------- SOCKET SERVER HAL -------------------- */ -static int scktsrv_alive(int dev) +static bool scktsrv_alive(int dev) { - return ncons[dev].ssc; /* SCKTSRV is alive if there is an open socket */ + return ncons[dev].ssc != 0; /* SCKTSRV is alive if there is an open socket */ } static void scktsrv_status(int dev, BYTE *stat) @@ -285,7 +285,7 @@ static void scktsrv_out(int dev, BYTE data) #include "generic-at-modem.h" -static int modem_alive(int dev) +static bool modem_alive(int dev) { UNUSED(dev); @@ -325,25 +325,25 @@ const char *tuart_port_name[MAX_TUART_PORT] = static const hal_device_t devices[] = { #ifdef HAS_NETSERVER - { "WEBTTY", 0, DEV_TTY, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, - { "WEBTTY2", 0, DEV_TTY2, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, - { "WEBTTY3", 0, DEV_TTY3, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, - { "WEBPTR", 0, DEV_PTR, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBTTY", false, DEV_TTY, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBTTY2", false, DEV_TTY2, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBTTY3", false, DEV_TTY3, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, + { "WEBPTR", false, DEV_PTR, net_tty_alive, net_tty_status, net_tty_in, net_tty_out }, #else - { "WEBTTY", 0, 0, null_dead, null_status, null_in, null_out }, - { "WEBTTY2", 0, 0, null_dead, null_status, null_in, null_out }, - { "WEBTTY3", 0, 0, null_dead, null_status, null_in, null_out }, - { "WEBPTR", 0, 0, null_dead, null_status, null_in, null_out }, + { "WEBTTY", false, 0, null_dead, null_status, null_in, null_out }, + { "WEBTTY2", false, 0, null_dead, null_status, null_in, null_out }, + { "WEBTTY3", false, 0, null_dead, null_status, null_in, null_out }, + { "WEBPTR", false, 0, null_dead, null_status, null_in, null_out }, #endif - { "STDIO", 0, 0, stdio_alive, stdio_status, stdio_in, stdio_out }, - { "SCKTSRV1", 0, 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, - { "SCKTSRV2", 0, 1, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, + { "STDIO", false, 0, stdio_alive, stdio_status, stdio_in, stdio_out }, + { "SCKTSRV1", false, 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, + { "SCKTSRV2", false, 1, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out }, #ifdef HAS_MODEM - { "MODEM", 0, 0, modem_alive, modem_status, modem_in, modem_out }, + { "MODEM", false, 0, modem_alive, modem_status, modem_in, modem_out }, #else - { "MODEM", 0, 0, null_dead, null_status, null_in, null_out }, + { "MODEM", false, 0, null_dead, null_status, null_in, null_out }, #endif - { "", 0, 0, null_alive, null_status, null_in, null_out } + { "", false, 0, null_alive, null_status, null_in, null_out } }; hal_device_t tuart[MAX_TUART_PORT][MAX_HAL_DEV]; @@ -420,11 +420,11 @@ static void hal_init(void) dev = strtok(match, ",\r"); while (dev) { char k = dev[strlen(dev) - 1]; - int fallthrough = 0; + bool fallthrough = false; if (k == '+') { dev[strlen(dev) - 1] = 0; - fallthrough = 1; + fallthrough = true; } d = hal_find_device(dev); @@ -505,7 +505,7 @@ void hal_data_out(tuart_port_t dev, BYTE data) } } -int hal_alive(tuart_port_t dev) +bool hal_alive(tuart_port_t dev) { int p = 0; @@ -514,5 +514,5 @@ int hal_alive(tuart_port_t dev) p++; /* return "alive" (true) when not the NULL device */ - return tuart[dev][p].name ? 1 : 0; + return tuart[dev][p].name ? true : false; } diff --git a/iodevices/cromemco-hal.h b/iodevices/cromemco-hal.h index 2d616516..9b5951a7 100644 --- a/iodevices/cromemco-hal.h +++ b/iodevices/cromemco-hal.h @@ -38,9 +38,9 @@ typedef enum hal_dev { typedef struct hal_device { const char *name; - int fallthrough; + bool fallthrough; int device_id; - int (*alive)(int dev); + bool (*alive)(int dev); void (*status)(int dev, BYTE *stat); int (*in)(int dev); void (*out)(int dev, BYTE data); @@ -51,7 +51,7 @@ extern void hal_reset(void); extern void hal_status_in(tuart_port_t dev, BYTE *stat); extern int hal_data_in(tuart_port_t dev); extern void hal_data_out(tuart_port_t dev, BYTE data); -extern int hal_alive(tuart_port_t dev); +extern bool hal_alive(tuart_port_t dev); extern const char *tuart_port_name[MAX_TUART_PORT]; extern hal_device_t tuart[MAX_TUART_PORT][MAX_HAL_DEV]; diff --git a/iodevices/diskmanager.c b/iodevices/diskmanager.c index dbd42b41..7b0b7596 100644 --- a/iodevices/diskmanager.c +++ b/iodevices/diskmanager.c @@ -216,17 +216,17 @@ void readDiskmap(char *path_name) #ifdef HAS_NETSERVER -static int findDiskImage(const char *image) +static bool findDiskImage(const char *image) { int i; for (i = 0; i < _MAX_DISK; i++) { if (DISKNAME(i) != NULL) { if (strcmp(image, DISKNAME(i)) == 0) - return 1; + return true; } } - return 0; + return false; } static int getDiskNumByID(const char *id) diff --git a/iodevices/generic-at-modem.c b/iodevices/generic-at-modem.c index 969fbc41..6c90d106 100644 --- a/iodevices/generic-at-modem.c +++ b/iodevices/generic-at-modem.c @@ -116,7 +116,7 @@ static char port_num[11]; static telnet_telopt_t telnet_opts[10]; -static int carrier_detect; +static bool carrier_detect; static void init_telnet_opts(void) { @@ -258,7 +258,7 @@ static void close_socket(void) LOGI(TAG, "Socket closed"); *active_sfd = 0; } - carrier_detect = 0; + carrier_detect = false; } static int open_socket(void) @@ -314,7 +314,7 @@ static int open_socket(void) }; active_sfd = &sfd; - carrier_detect = 1; + carrier_detect = true; LOGI(TAG, "Socket created"); if (connect(sfd, rp->ai_addr, sizeof(struct sockaddr_in)) < 0) { @@ -429,7 +429,7 @@ static int answer(void) inet_ntop(AF_INET, &cli_addr.sin_addr, addr, 100); LOGI(TAG, "New Remote Connection: %s:%d", addr, ntohs(cli_addr.sin_port)); active_sfd = &newsockfd; - carrier_detect = 1; + carrier_detect = true; if (setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *) &on, sizeof(on)) == -1) { LOGE(TAG, "can't set sockopt TCP_NODELAY"); @@ -1041,24 +1041,24 @@ static int process_at_cmd(void) static uint64_t at_t1, at_t2; static int tdiff; -int modem_device_alive(int i) +bool modem_device_alive(int i) { UNUSED(i); if (!daemon_f) - return 1; + return true; if (answer_sfd) { if (*active_sfd) - return 1; + return true; else { if (at_state == cmd) { modem_device_poll(0); - return 0; + return false; } } } - return 0; + return false; } static int _read(void) @@ -1073,7 +1073,7 @@ static int _read(void) hangup_timeout(true); at_cmd[0] = 0; at_state = cmd; - carrier_detect = 0; + carrier_detect = false; return -1; } @@ -1295,7 +1295,7 @@ void modem_device_send(int i, char data) at_t1 = get_clock_us(); } -int modem_device_carrier(int i) +bool modem_device_carrier(int i) { UNUSED(i); diff --git a/iodevices/generic-at-modem.h b/iodevices/generic-at-modem.h index e6379f3c..cf6eb8db 100644 --- a/iodevices/generic-at-modem.h +++ b/iodevices/generic-at-modem.h @@ -17,11 +17,11 @@ #ifndef GENERIC_AT_MODEM_INC #define GENERIC_AT_MODEM_INC -extern int modem_device_alive(int i); +extern bool modem_device_alive(int i); extern int modem_device_poll(int i); extern int modem_device_get(int i); extern void modem_device_send(int i, char data); -extern int modem_device_carrier(int i); +extern bool modem_device_carrier(int i); extern void modem_device_init(void); #define DEV_SIO2B 0 diff --git a/iodevices/imsai-hal.c b/iodevices/imsai-hal.c index a2c8cdfd..48bdbb1e 100644 --- a/iodevices/imsai-hal.c +++ b/iodevices/imsai-hal.c @@ -39,15 +39,15 @@ static const char *TAG = "HAL"; /* -------------------- NULL device HAL -------------------- */ -static int null_alive(void) +static bool null_alive(void) { - return 1; /* NULL is always alive */ + return true; /* NULL is always alive */ } #if !defined(HAS_NETSERVER) || !defined(HAS_MODEM) -static int null_dead(void) +static bool null_dead(void) { - return 0; /* NULL is always dead */ + return false; /* NULL is always dead */ } #endif @@ -70,14 +70,14 @@ static void null_out(BYTE data) return; } -static int null_cd(void) +static bool null_cd(void) { - return 0; + return false; } /* -------------------- VIOKBD HAL -------------------- */ -static int vio_kbd_alive(void) +static bool vio_kbd_alive(void) { #ifdef HAS_NETSERVER if (n_flag) { @@ -86,7 +86,7 @@ static int vio_kbd_alive(void) } else { #endif /* VIO (xterm) keyboard is always alive */ - return 1; + return true; #ifdef HAS_NETSERVER } #endif @@ -112,13 +112,13 @@ static void vio_kbd_out(BYTE data) #ifdef HAS_NETSERVER -static int net_tty_alive(void) +static bool net_tty_alive(void) { if (n_flag) { /* WEBTTY is only alive if websocket is connected */ return net_device_alive(DEV_TTY); } else - return 0; + return false; } static void net_tty_status(BYTE *stat) @@ -151,13 +151,13 @@ static void net_tty_out(BYTE data) #ifdef HAS_NETSERVER -static int net_ptr_alive(void) +static bool net_ptr_alive(void) { if (n_flag) { /* WEBPTR is only alive if websocket is connected */ return net_device_alive(DEV_PTR); } else - return 0; + return false; } static void net_ptr_status(BYTE *stat) @@ -188,9 +188,9 @@ static void net_ptr_out(BYTE data) /* -------------------- STDIO HAL -------------------- */ -static int stdio_alive(void) +static bool stdio_alive(void) { - return 1; /* STDIO is always alive */ + return true; /* STDIO is always alive */ } static void stdio_status(BYTE *stat) @@ -253,7 +253,7 @@ static void stdio_out(BYTE data) /* -------------------- SOCKET SERVER HAL -------------------- */ -static int scktsrv_alive(void) +static bool scktsrv_alive(void) { struct pollfd p[1]; @@ -272,7 +272,7 @@ static int scktsrv_alive(void) } } - return ucons[0].ssc; /* SCKTSRV is alive if there is an open socket */ + return ucons[0].ssc != 0; /* SCKTSRV is alive if there is an open socket */ } static void scktsrv_status(BYTE *stat) @@ -357,7 +357,7 @@ static void scktsrv_out(BYTE data) #include "generic-at-modem.h" -static int modem_alive(void) +static bool modem_alive(void) { return modem_device_alive(0); } @@ -380,7 +380,7 @@ static void modem_out(BYTE data) modem_device_send(0, (char) data); } -static int modem_cd(void) +static bool modem_cd(void) { return modem_device_carrier(0); } @@ -394,21 +394,21 @@ const char *sio_port_name[MAX_SIO_PORT] = static const hal_device_t devices[] = { #ifdef HAS_NETSERVER - { "WEBTTY", 0, net_tty_alive, net_tty_status, net_tty_in, net_tty_out, null_cd }, - { "WEBPTR", 0, net_ptr_alive, net_ptr_status, net_ptr_in, net_ptr_out, null_cd }, + { "WEBTTY", false, net_tty_alive, net_tty_status, net_tty_in, net_tty_out, null_cd }, + { "WEBPTR", false, net_ptr_alive, net_ptr_status, net_ptr_in, net_ptr_out, null_cd }, #else - { "WEBTTY", 0, null_dead, null_status, null_in, null_out, null_cd }, - { "WEBPTR", 0, null_dead, null_status, null_in, null_out, null_cd }, + { "WEBTTY", false, null_dead, null_status, null_in, null_out, null_cd }, + { "WEBPTR", false, null_dead, null_status, null_in, null_out, null_cd }, #endif - { "STDIO", 0, stdio_alive, stdio_status, stdio_in, stdio_out, null_cd }, - { "SCKTSRV", 0, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out, null_cd }, + { "STDIO", false, stdio_alive, stdio_status, stdio_in, stdio_out, null_cd }, + { "SCKTSRV", false, scktsrv_alive, scktsrv_status, scktsrv_in, scktsrv_out, null_cd }, #ifdef HAS_MODEM - { "MODEM", 0, modem_alive, modem_status, modem_in, modem_out, modem_cd }, + { "MODEM", false, modem_alive, modem_status, modem_in, modem_out, modem_cd }, #else - { "MODEM", 0, null_dead, null_status, null_in, null_out, null_cd }, + { "MODEM", false, null_dead, null_status, null_in, null_out, null_cd }, #endif - { "VIOKBD", 0, vio_kbd_alive, vio_kbd_status, vio_kbd_in, vio_kbd_out, null_cd }, - { "", 0, null_alive, null_status, null_in, null_out, null_cd } + { "VIOKBD", false, vio_kbd_alive, vio_kbd_status, vio_kbd_in, vio_kbd_out, null_cd }, + { "", false, null_alive, null_status, null_in, null_out, null_cd } }; hal_device_t sio[MAX_SIO_PORT][MAX_HAL_DEV]; @@ -489,11 +489,11 @@ static void hal_init(void) dev = strtok(match, ",\r"); while (dev) { char k = dev[strlen(dev) - 1]; - int fallthrough = 0; + bool fallthrough = false; if (k == '+') { dev[strlen(dev) - 1] = 0; - fallthrough = 1; + fallthrough = true; } d = hal_find_device(dev); @@ -575,7 +575,7 @@ void hal_data_out(sio_port_t dev, BYTE data) } } -int hal_carrier_detect(sio_port_t dev) +bool hal_carrier_detect(sio_port_t dev) { int p = 0; diff --git a/iodevices/imsai-hal.h b/iodevices/imsai-hal.h index f0872b19..906cbc23 100644 --- a/iodevices/imsai-hal.h +++ b/iodevices/imsai-hal.h @@ -37,12 +37,12 @@ typedef enum hal_dev { typedef struct hal_device { const char *name; - int fallthrough; - int (*alive)(void); + bool fallthrough; + bool (*alive)(void); void (*status)(BYTE *stat); int (*in)(void); void (*out)(BYTE data); - int (*cd)(void); + bool (*cd)(void); } hal_device_t; extern void hal_reset(void); @@ -50,7 +50,7 @@ extern void hal_reset(void); extern void hal_status_in(sio_port_t sio, BYTE *stat); extern int hal_data_in(sio_port_t sio); extern void hal_data_out(sio_port_t sio, BYTE data); -extern int hal_carrier_detect(sio_port_t sio); +extern bool hal_carrier_detect(sio_port_t sio); extern const char *sio_port_name[MAX_SIO_PORT]; extern hal_device_t sio[MAX_SIO_PORT][MAX_HAL_DEV]; diff --git a/iodevices/imsai-sio2.c b/iodevices/imsai-sio2.c index a411a79a..5940b8fa 100644 --- a/iodevices/imsai-sio2.c +++ b/iodevices/imsai-sio2.c @@ -438,18 +438,18 @@ void imsai_sio2b_data_out(BYTE data) */ BYTE imsai_sio1_ctl_in(void) { - int cd_a = hal_carrier_detect(SIO1A); - int cd_b = hal_carrier_detect(SIO1B); + bool cd_a = hal_carrier_detect(SIO1A); + bool cd_b = hal_carrier_detect(SIO1B); - return 0b10111011 | (cd_a << 2) | cd_b << 6; + return 0b10111011 | (cd_a ? 4 : 0) | (cd_b ? 64 : 0); } BYTE imsai_sio2_ctl_in(void) { - int cd_a = hal_carrier_detect(SIO2A); - int cd_b = hal_carrier_detect(SIO2B); + bool cd_a = hal_carrier_detect(SIO2A); + bool cd_b = hal_carrier_detect(SIO2B); - return 0b10111011 | (cd_a << 2) | cd_b << 6; + return 0b10111011 | (cd_a ? 4 : 0) | (cd_b ? 64 : 0); } /* diff --git a/webfrontend/netsrv.c b/webfrontend/netsrv.c index 3389bdff..f446a364 100644 --- a/webfrontend/netsrv.c +++ b/webfrontend/netsrv.c @@ -51,21 +51,31 @@ static const char *TAG = "netsrv"; #define MAX_WS_CLIENTS (_DEV_MAX) +typedef struct msgbuf_s { + long mtype; + unsigned char mtext[128]; +} msgbuf_t; + static msgbuf_t msg; -struct { +typedef struct ws_client { + struct mg_connection *conn; + int state; +} ws_client_t; + +static struct { int queue; ws_client_t ws_client; void (*cbfunc)(BYTE *); } dev[MAX_WS_CLIENTS]; -net_device_t net_device_a[_DEV_MAX] = { +static net_device_t net_device_a[_DEV_MAX] = { DEV_TTY, DEV_TTY2, DEV_TTY3, DEV_LPT, DEV_VIO, DEV_CPA, DEV_DZLR, DEV_88ACC, DEV_D7AIO, DEV_PTR }; -const char *dev_name[] = { +static const char *dev_name[] = { "TTY", "TTY2", "TTY3", @@ -78,7 +88,7 @@ const char *dev_name[] = { "PTR" }; -int last_error = 0; //TODO: replace +static int last_error = 0; //TODO: replace /* extern int reset; @@ -89,9 +99,9 @@ extern void quit_callback(void); /** * Check if a queue is provisioned */ -int net_device_alive(net_device_t device) +bool net_device_alive(net_device_t device) { - return dev[device].queue; + return dev[device].queue != 0; } void net_device_service(net_device_t device, void (*cbfunc)(BYTE *data)) @@ -240,7 +250,7 @@ static void InformWebsockets(struct mg_context *ctx) mg_unlock_context(ctx); } -struct utsname uts; +static struct utsname uts; static int SystemHandler(HttpdConnection_t *conn, void *unused) { diff --git a/webfrontend/netsrv.h b/webfrontend/netsrv.h index 61e6b283..4c36ee13 100644 --- a/webfrontend/netsrv.h +++ b/webfrontend/netsrv.h @@ -22,7 +22,7 @@ #include "civetweb.h" -enum net_device { +typedef enum net_device { DEV_TTY, DEV_TTY2, DEV_TTY3, @@ -34,20 +34,9 @@ enum net_device { DEV_D7AIO, DEV_PTR, _DEV_MAX -}; -typedef enum net_device net_device_t; +} net_device_t; -typedef struct msgbuf_s { - long mtype; - unsigned char mtext[128]; -} msgbuf_t; - -typedef struct ws_client { - struct mg_connection *conn; - int state; -} ws_client_t; - -extern int net_device_alive(net_device_t device); +extern bool net_device_alive(net_device_t device); extern void net_device_service(net_device_t device, void (*cbfunc)(BYTE *data)); extern void net_device_send(net_device_t device, char *msg, int len); extern int net_device_get(net_device_t device); @@ -66,14 +55,13 @@ typedef struct mg_connection HttpdConnection_t; #define _HTTP_MAX_ARGS 8 -enum http_method { +typedef enum http_method { HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_DELETE, HTTP_UNKNOWN -}; -typedef enum http_method http_method_t; +} http_method_t; typedef struct request { const struct mg_request_info *mg; From b8c3a189d7564ba2972a845ffa57c9af9b4341a0 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 13:42:49 +0100 Subject: [PATCH 18/19] clean-up netsrv and fix zero bug with message queue ids Move system includes not needed in netsrv.h to netsrv.c. This revealed that cromemco-dazzler and imsai-vio need to include string.h with HAS_NETSERVER. At least on Linux the first message queue created has an id of 0, this triped up the code which expected a value > 0. Use -1 to mean no queue connected and not 0. The manual page of msgget(2) also states that the returned id is a nonnegative integer, so 0 is a completely legal value. --- iodevices/cromemco-dazzler.c | 1 + iodevices/imsai-vio.c | 1 + webfrontend/netsrv.c | 27 +++++++++++++++++---------- webfrontend/netsrv.h | 4 ---- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/iodevices/cromemco-dazzler.c b/iodevices/cromemco-dazzler.c index a3ff4cca..2757de8a 100644 --- a/iodevices/cromemco-dazzler.c +++ b/iodevices/cromemco-dazzler.c @@ -50,6 +50,7 @@ #ifdef HAS_DAZZLER #ifdef HAS_NETSERVER +#include #include "netsrv.h" #endif diff --git a/iodevices/imsai-vio.c b/iodevices/imsai-vio.c index 19029198..5dbdeb4f 100644 --- a/iodevices/imsai-vio.c +++ b/iodevices/imsai-vio.c @@ -43,6 +43,7 @@ #endif #ifdef HAS_NETSERVER +#include #include "netsrv.h" #endif diff --git a/webfrontend/netsrv.c b/webfrontend/netsrv.c index f446a364..220e2018 100644 --- a/webfrontend/netsrv.c +++ b/webfrontend/netsrv.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -101,7 +103,7 @@ extern void quit_callback(void); */ bool net_device_alive(net_device_t device) { - return dev[device].queue != 0; + return dev[device].queue >= 0; } void net_device_service(net_device_t device, void (*cbfunc)(BYTE *data)) @@ -132,7 +134,7 @@ void net_device_send(net_device_t device, char *msg, int len) break; } - if (dev[device].queue) + if (dev[device].queue >= 0) mg_websocket_write(dev[device].ws_client.conn, op_code, msg, len); @@ -149,7 +151,7 @@ int net_device_get(net_device_t device) ssize_t res; msgbuf_t msg; - if (dev[device].queue) { + if (dev[device].queue >= 0) { res = msgrcv(dev[device].queue, &msg, 2, 1L, IPC_NOWAIT); LOGD(TAG, "GET: device[%d] res[%ld] msg[%ld, %s]", device, res, msg.mtype, msg.mtext); @@ -165,7 +167,7 @@ int net_device_get_data(net_device_t device, char *dst, int len) ssize_t res; msgbuf_t msg; - if (dev[device].queue) { + if (dev[device].queue >= 0) { res = msgrcv(dev[device].queue, &msg, len, 1L, MSG_NOERROR); memcpy((void *)dst, (void *)msg.mtext, res); return res; @@ -185,7 +187,7 @@ int net_device_poll(net_device_t device) ssize_t res; msgbuf_t msg; - if (dev[device].queue) { + if (dev[device].queue >= 0) { res = msgrcv(dev[device].queue, &msg, 1, 1L, IPC_NOWAIT); LOGV(TAG, "POLL: device[%d] res[%ld] errno[%d]", device, res, errno); if (res == -1 && errno == E2BIG) { @@ -595,10 +597,10 @@ static int WebSocketConnectHandler(const HttpdConnection_t *conn, void *device) case DEV_88ACC: case DEV_D7AIO: res = msgget(IPC_PRIVATE, 0644 | IPC_CREAT); //TODO: check flags - if (res > 0) - dev[d].queue = res; - else + if (res < 0) perror("msgget()"); + else + dev[d].queue = res; break; default: break; @@ -758,11 +760,12 @@ static void WebSocketCloseHandler(const HttpdConnection_t *conn, void *device) LOGI(TAG, "WS CLIENT CLOSED %s", dev_name[d]); - if (dev[d].queue && msgctl(dev[d].queue, IPC_RMID, NULL) == -1) + if (dev[d].queue >= 0 && msgctl(dev[d].queue, IPC_RMID, NULL) == -1) perror("msgctl()"); - dev[d].queue = 0; LOGD(TAG, "Message queue closed (%d) [%08X]", d, dev[d].queue); + + dev[d].queue = -1; } static struct mg_context *ctx = NULL; @@ -785,6 +788,7 @@ int start_net_services(int port) { //TODO: add config for DOCUMENT_ROOT + int i; char sport[6]; #ifdef SYSDOCROOT struct stat sbuf; @@ -818,6 +822,9 @@ int start_net_services(int port) const struct mg_option *opts; #endif + for (i = 0; i < MAX_WS_CLIENTS; i++) + dev[i].queue = -1; + atexit(stop_net_services); snprintf(sport, sizeof(sport), "%d", port); diff --git a/webfrontend/netsrv.h b/webfrontend/netsrv.h index 4c36ee13..dd461715 100644 --- a/webfrontend/netsrv.h +++ b/webfrontend/netsrv.h @@ -13,10 +13,6 @@ /** * This web server module provides... */ -#include -#include -#include - #include "sim.h" #include "simdefs.h" From abc3c7bff173133ef929ee8c2865900d29e9a0a7 Mon Sep 17 00:00:00 2001 From: Thomas Eberhardt Date: Sun, 19 Jan 2025 14:07:36 +0100 Subject: [PATCH 19/19] netsrv.c: replace ancient index(3) with strchr(3) --- webfrontend/netsrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webfrontend/netsrv.c b/webfrontend/netsrv.c index 220e2018..ec54722d 100644 --- a/webfrontend/netsrv.c +++ b/webfrontend/netsrv.c @@ -430,7 +430,7 @@ static int SystemHandler(HttpdConnection_t *conn, void *unused) BULLET BULLET BULLET BULLET; /* Filter out only TERM and non-shell environment variables of the form '*.*' ie. contain '.' */ - if (!strcmp(t1, "TERM") || index(t1, '.')) + if (!strcmp(t1, "TERM") || strchr(t1, '.')) httpdPrintf(conn, "%s \"%s\": \"%s\" ", (o++) == 0 ? "" : ",", t1, (t2 == NULL) ? "" : t2);