Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #2 (bad type of some parameters for some z80/68k low-level commands) #86

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,7 @@
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# sane defaults + hardening
set(GLOBAL_COMPILE_FLAGS "-W -Wall -Wextra -Wno-unused-parameter -Werror=shadow -Werror=write-strings -Wredundant-decls -Werror=date-time -Werror=return-type -Werror=pointer-arith")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_COMPILE_FLAGS} -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-prototypes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLOBAL_COMPILE_FLAGS}")
# useful flags for debugging
set(GLOBAL_DEBUG_FLAGS "-fno-omit-frame-pointer -fsanitize=address,bounds -fsanitize-undefined-trap-on-error")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
# only for clang/gcc
add_compile_definitions(HAVE_FVISIBILITY=1)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

if(APPLE)
add_compile_definitions(__MACOSX__)
Expand All @@ -125,6 +113,36 @@
include_directories(${CMAKE_SOURCE_DIR}/win32_config)
endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# sane defaults + hardening
set(GLOBAL_COMPILE_FLAGS "-W -Wall -Wextra -Wno-unused-parameter -Werror=shadow -Werror=write-strings -Wredundant-decls -Werror=date-time -Werror=return-type -Werror=pointer-arith")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_COMPILE_FLAGS} -Werror=declaration-after-statement -Werror=implicit-function-declaration -Werror=missing-prototypes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLOBAL_COMPILE_FLAGS}")
if(LINUX)
add_link_options("-Wl,-z,relro,-z,now -Wl,-z,noexecstack -Wl,-z,separate-code")
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_link_options("-Wl,--as-needed")
endif()
endif()
# useful flags for debugging
set(GLOBAL_DEBUG_FLAGS "-fno-omit-frame-pointer -fsanitize=address,bounds -fsanitize-undefined-trap-on-error -fstack-protector-strong -fstack-clash-protection")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
# only for clang/gcc
add_compile_definitions(HAVE_FVISIBILITY=1)
elseif (MSVC)
# sane defaults + hardening. /wd4996 to disable deprecated functions warnings
set(GLOBAL_COMPILE_FLAGS "/Wall /sdl /guard:cf /guard:ehcont /wd4996")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GLOBAL_COMPILE_FLAGS} ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GLOBAL_COMPILE_FLAGS} ")
# useful flags for debugging
set(GLOBAL_DEBUG_FLAGS "/fsanitize=address")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${GLOBAL_DEBUG_FLAGS} ")
endif()

# i18n support checking
include(FindGettext)
include(FindIntl)
Expand All @@ -147,7 +165,7 @@
link_libraries(${Intl_LIBRARIES})
endif()
else()
message(WARNING "The Intl and GetText libs are needed for translations - Only English will be available")

Check warning on line 168 in CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build: x64 - shared deps

The Intl and GetText libs are needed for translations - Only English will

Check warning on line 168 in CMakeLists.txt

View workflow job for this annotation

GitHub Actions / Build: x64 - static deps

The Intl and GetText libs are needed for translations - Only English will
endif()
set(LOCALEDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LOCALEDIR}")

Expand Down
10 changes: 5 additions & 5 deletions libticalcs/trunk/src/cmd68k.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ TIEXPORT3 int TICALL ti68k_recv_EOT(CalcHandle *handle);


/* TI-89 family, send functions */
static inline int ti89_send_VAR(CalcHandle* handle, uint8_t varsize, uint8_t vartype, const char* varname) { return ti68k_send_VAR(handle, varsize, vartype, varname, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_VAR(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char* varname) { return ti68k_send_VAR(handle, varsize, vartype, varname, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_CTS(CalcHandle* handle) { return ti68k_send_CTS(handle, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_XDP(CalcHandle* handle, uint8_t length, uint8_t* data) { return ti68k_send_XDP(handle, length, data, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_XDP(CalcHandle* handle, uint32_t length, uint8_t* data) { return ti68k_send_XDP(handle, length, data, ti68k_handle_to_dbus_mid(handle)); }
TIEXPORT3 int TICALL ti89_send_SKP(CalcHandle *handle, uint8_t rej_code);
static inline int ti89_send_ACK(CalcHandle* handle) { return ti68k_send_ACK(handle, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_ERR(CalcHandle* handle) { return ti68k_send_ERR(handle, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_RDY(CalcHandle* handle) { return ti68k_send_RDY(handle, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_SCR(CalcHandle* handle) { return ti68k_send_SCR(handle, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_CNT(CalcHandle* handle) { return ti68k_send_CNT(handle, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_KEY(CalcHandle* handle, uint8_t scancode) { return ti68k_send_KEY(handle, scancode, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_KEY(CalcHandle* handle, uint16_t scancode) { return ti68k_send_KEY(handle, scancode, ti68k_handle_to_dbus_mid(handle)); }
static inline int ti89_send_EOT(CalcHandle* handle) { return ti68k_send_EOT(handle, ti68k_handle_to_dbus_mid(handle)); }
TIEXPORT3 int TICALL ti89_send_REQ(CalcHandle *handle, uint32_t varsize, uint8_t vartype, const char *varname);
TIEXPORT3 int TICALL ti89_send_RTS(CalcHandle *handle, uint32_t varsize, uint8_t vartype, const char *varname);
Expand All @@ -85,14 +85,14 @@ TIEXPORT3 int TICALL ti89_recv_RTS(CalcHandle *handle, uint32_t * varsize, uint8
/* TI-92, send functions */
static inline int ti92_send_VAR(CalcHandle* handle, uint32_t varsize, uint8_t vartype, const char* varname) { return ti68k_send_VAR(handle, varsize, vartype, varname, DBUS_MID_PC_TI92); }
static inline int ti92_send_CTS(CalcHandle* handle) { return ti68k_send_CTS(handle, DBUS_MID_PC_TI92); }
static inline int ti92_send_XDP(CalcHandle* handle, uint8_t length, uint8_t* data) { return ti68k_send_XDP(handle, length, data, DBUS_MID_PC_TI92); }
static inline int ti92_send_XDP(CalcHandle* handle, uint32_t length, uint8_t* data) { return ti68k_send_XDP(handle, length, data, DBUS_MID_PC_TI92); }
TIEXPORT3 int TICALL ti92_send_SKP(CalcHandle *handle, uint8_t rej_code);
static inline int ti92_send_ACK(CalcHandle* handle) { return ti68k_send_ACK(handle, DBUS_MID_PC_TI92); }
static inline int ti92_send_ERR(CalcHandle* handle) { return ti68k_send_ERR(handle, DBUS_MID_PC_TI92); }
static inline int ti92_send_RDY(CalcHandle* handle) { return ti68k_send_RDY(handle, DBUS_MID_PC_TI92); }
static inline int ti92_send_SCR(CalcHandle* handle) { return ti68k_send_SCR(handle, DBUS_MID_PC_TI92); }
static inline int ti92_send_CNT(CalcHandle* handle) { return ti68k_send_CNT(handle, DBUS_MID_PC_TI92); }
static inline int ti92_send_KEY(CalcHandle* handle, uint8_t scancode) { return ti68k_send_KEY(handle, scancode, DBUS_MID_PC_TI92); }
static inline int ti92_send_KEY(CalcHandle* handle, uint16_t scancode) { return ti68k_send_KEY(handle, scancode, DBUS_MID_PC_TI92); }
static inline int ti92_send_EOT(CalcHandle* handle) { return ti68k_send_EOT(handle, DBUS_MID_PC_TI92); }
TIEXPORT3 int TICALL ti92_send_REQ(CalcHandle *handle, uint32_t varsize, uint8_t vartype, const char *varname);
TIEXPORT3 int TICALL ti92_send_RTS(CalcHandle *handle, uint32_t varsize, uint8_t vartype, const char *varname);
Expand Down
3 changes: 3 additions & 0 deletions libticalcs/trunk/src/cmdz80.cc
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,10 @@ int ti82_send_asm_exec(CalcHandle* handle, VarEntry * var)
endptr = (var->name[0] == 0x24 ? fpBase : tempMem);
buffer[8] = 0x2a; buffer[9] = LSB(endptr); buffer[10] = MSB(endptr);
/* ld de, -program_size */
#pragma warning(push)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#pragma isn't portable in the first place, but would #pragma msvc ... be possible at least for the warning(disable:4146) ?

Copy link
Contributor Author

@adriweb adriweb Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well I know, but gcc and clang just warn that it's an unknown pragma and ignore it anyway :P

But contrary to those two compilers with a compiler-name-as-first-arg, it looks like #pragma msvc isn't a thing...
So I suppose we could add #ifdef _MSC_VER/#endif for each. but that's whole lot of extra lines just to disable a warning, bleh.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a step back... fixing the code would be better :)
offset should be int32_t, and after adding an early bounds check against < 2 and >= 32768 (both models have 32 KB of physical RAM) on var->size below VALIDATE_VARENTRY(var), something like offset = -(int32_t)((uint16_t)var->size - 2); should do the job, hopefully without the compilers complaining about numerical value truncation or overflows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's probably better. We'll have to compare the actual output in buffer just in case...

#pragma warning(disable:4146)
offset = -(var->size - 2);
#pragma warning(pop)
buffer[11] = 0x11; buffer[12] = LSB(offset); buffer[13] = MSB(offset);
/* add hl, de */
buffer[14] = 0x19;
Expand Down
12 changes: 6 additions & 6 deletions libticalcs/trunk/src/cmdz80.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ static inline int ti80_recv_ACK(CalcHandle* handle, uint16_t* status) { return t
TIEXPORT3 int TICALL ti73_send_VAR(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr, uint8_t version);
TIEXPORT3 int TICALL ti73_send_VAR2(CalcHandle *handle, uint32_t length, uint8_t type, uint8_t flag, uint16_t offset, uint16_t page);
static inline int ti73_send_CTS(CalcHandle* handle) { return tiz80_send_CTS(handle, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_XDP(CalcHandle* handle, uint8_t length, uint8_t* data) { return tiz80_send_XDP(handle, length, data, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_XDP(CalcHandle* handle, uint16_t length, uint8_t* data) { return tiz80_send_XDP(handle, length, data, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_SKP(CalcHandle* handle, uint8_t rej_code) { return tiz80_send_SKP(handle, rej_code, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_ACK(CalcHandle* handle) { return tiz80_send_ACK(handle, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_ERR(CalcHandle* handle) { return tiz80_send_ERR(handle, tiz80_handle_to_dbus_mid_7383p(handle)); }
TIEXPORT3 int TICALL ti73_send_RDY(CalcHandle *handle);
static inline int ti73_send_SCR(CalcHandle* handle) { return tiz80_send_SCR(handle, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_KEY(CalcHandle* handle, uint8_t scancode) { return tiz80_send_KEY(handle, scancode, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_KEY(CalcHandle* handle, uint16_t scancode) { return tiz80_send_KEY(handle, scancode, tiz80_handle_to_dbus_mid_7383p(handle)); }
static inline int ti73_send_EOT(CalcHandle* handle) { return tiz80_send_EOT(handle, tiz80_handle_to_dbus_mid_7383p(handle)); }
TIEXPORT3 int TICALL ti73_send_REQ(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname, uint8_t varattr, uint8_t version);
TIEXPORT3 int TICALL ti73_send_REQ2(CalcHandle *handle, uint16_t appsize, uint8_t apptype, const char *appname, uint8_t appattr);
Expand Down Expand Up @@ -113,12 +113,12 @@ TIEXPORT3 int TICALL ti73_recv_RTS(CalcHandle *handle, uint16_t * varsize, uint8
/* TI-82 & TI-83, send functions */
TIEXPORT3 int TICALL ti82_send_VAR(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname);
static inline int ti82_send_CTS(CalcHandle* handle) { return tiz80_send_CTS(handle, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_XDP(CalcHandle* handle, uint8_t length, uint8_t* data) { return tiz80_send_XDP(handle, length, data, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_XDP(CalcHandle* handle, uint16_t length, uint8_t* data) { return tiz80_send_XDP(handle, length, data, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_SKP(CalcHandle* handle, uint8_t rej_code) { return tiz80_send_SKP(handle, rej_code, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_ACK(CalcHandle* handle) { return tiz80_send_ACK(handle, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_ERR(CalcHandle* handle) { return tiz80_send_ERR(handle, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_SCR(CalcHandle* handle) { return tiz80_send_SCR(handle, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_KEY(CalcHandle* handle, uint8_t scancode) { return tiz80_send_KEY(handle, scancode, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_KEY(CalcHandle* handle, uint16_t scancode) { return tiz80_send_KEY(handle, scancode, tiz80_handle_to_dbus_mid_8283(handle)); }
static inline int ti82_send_EOT(CalcHandle* handle) { return tiz80_send_EOT(handle, tiz80_handle_to_dbus_mid_8283(handle)); }
TIEXPORT3 int TICALL ti82_send_REQ(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname);
TIEXPORT3 int TICALL ti82_send_RTS(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname);
Expand All @@ -136,12 +136,12 @@ TIEXPORT3 int TICALL ti82_recv_RTS(CalcHandle *handle, uint16_t * varsize, uint8
/* TI-85 & TI-86, send functions */
TIEXPORT3 int TICALL ti85_send_VAR(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname);
static inline int ti85_send_CTS(CalcHandle* handle) { return tiz80_send_CTS(handle, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_XDP(CalcHandle* handle, uint8_t length, uint8_t* data) { return tiz80_send_XDP(handle, length, data, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_XDP(CalcHandle* handle, uint16_t length, uint8_t* data) { return tiz80_send_XDP(handle, length, data, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_SKP(CalcHandle* handle, uint8_t rej_code) { return tiz80_send_SKP(handle, rej_code, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_ACK(CalcHandle* handle) { return tiz80_send_ACK(handle, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_ERR(CalcHandle* handle) { return tiz80_send_ERR(handle, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_SCR(CalcHandle* handle) { return tiz80_send_SCR(handle, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_KEY(CalcHandle* handle, uint8_t scancode) { return tiz80_send_KEY(handle, scancode, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_KEY(CalcHandle* handle, uint16_t scancode) { return tiz80_send_KEY(handle, scancode, tiz80_handle_to_dbus_mid_8586(handle)); }
static inline int ti85_send_EOT(CalcHandle* handle) { return tiz80_send_EOT(handle, tiz80_handle_to_dbus_mid_8586(handle)); }
TIEXPORT3 int TICALL ti85_send_REQ(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname);
TIEXPORT3 int TICALL ti85_send_RTS(CalcHandle *handle, uint16_t varsize, uint8_t vartype, const char *varname);
Expand Down
Loading