diff --git a/CMakeLists.txt b/CMakeLists.txt index db47c20..d9bae24 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 2.8) -set (CMAKE_C_FLAGS "-O3 -Wuninitialized -Wmaybe-uninitialized -mcpu=68000 -mtune=68000 -m68000 -Wall") +set (CMAKE_C_FLAGS "-Ofast -Wuninitialized -Wmaybe-uninitialized -mcpu=68000 -mtune=68000 -m68000 -Wall") add_application(MessagesForMacintosh SerialHelper.c diff --git a/coprocessorjs.c b/coprocessorjs.c index 4ea6eed..156b3b8 100644 --- a/coprocessorjs.c +++ b/coprocessorjs.c @@ -21,8 +21,11 @@ int call_counter = 0; // from: https://stackoverflow.com/questions/29847915/implementing-strtok-whose-delimiter-has-more-than-one-character // basically multichar delimter strtok -char *strtokm(char *str, const char *delim) -{ +char *strtokm(char *str, const char *delim) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: strtokm"); + #endif static char *tok; static char *next; char *m; @@ -71,6 +74,10 @@ http://mirror.informatimago.com/next/developer.apple.com/documentation/mac/Devic // TODO: handle all OSErr - they are all unhandled at the moment void setupPBControlForSerialPort(short serialPortShort) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: setupPBControlForSerialPort"); + #endif + CntrlParam cb; cb.ioCRefNum = serialPortShort; // TODO: this is always 0 - does it matter? should we hard code 0 here? research cb.csCode = 8; // TODO: need to look up and document what csCode = 8 means @@ -93,6 +100,10 @@ void setupPBControlForSerialPort(short serialPortShort) { void setupSerialPort(const char *name) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: setupSerialPort"); + #endif #define MODEM_PORT_OUT "\p.AOut" #define MODEM_PORT_IN "\p.AIn" #define PRINTER_PORT_OUT "\p.BOut" @@ -162,6 +173,10 @@ void setupSerialPort(const char *name) { void wait(float timeInSeconds) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: wait"); + #endif + // from "Inside Macintosh: Macintosh Toolbox Essentials" pg 2-112 // You can use the TickCount function to get the current number of ticks (a tick is // approximately 1/60 of a second) since the system last started up. @@ -200,6 +215,10 @@ const int MAX_RECIEVE_LOOP_ITERATIONS = 1000; // void because this function re-assigns respo void readSerialPort(char* output) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: readSerialPort"); + #endif + if (DEBUGGING) { printf("readSerialPort\n"); @@ -325,6 +344,10 @@ void readSerialPort(char* output) { OSErr writeSerialPort(const char* stringToWrite) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: writeSerialPort"); + #endif if (DEBUGGING) { @@ -357,6 +380,10 @@ OSErr writeSerialPort(const char* stringToWrite) { } void setupCoprocessor(char *applicationId, const char *serialDeviceName) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: setupCoprocessor"); + #endif strcpy(application_id, applicationId); @@ -367,6 +394,10 @@ void setupCoprocessor(char *applicationId, const char *serialDeviceName) { OSErr closeSerialPort() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: closeSerialPort"); + #endif + OSErr err = MacCloseDriver(outgoingSerialPortReference.ioRefNum); if (PRINT_ERRORS) { @@ -381,6 +412,10 @@ OSErr closeSerialPort() { // return time is char but this is only for error messages - final param is output variable that will be re-assigned within this function char* _getReturnValueFromResponse(char* response, char* application_id, char* call_counter, char* operation, char* output) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: _getReturnValueFromResponse"); + #endif if (DEBUGGING) { @@ -483,6 +518,10 @@ char* _getReturnValueFromResponse(char* response, char* application_id, char* ca } void writeToCoprocessor(char* operation, char* operand) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: writeToCoprocessor"); + #endif if (DEBUGGING) { @@ -516,6 +555,10 @@ void writeToCoprocessor(char* operation, char* operand) { // must be called after writeToCoprocessor and before other writeToCoprocessor // operations because we depend on the location of call_counter void getReturnValueFromResponse(char *response, char *operation, char *output) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: getReturnValueFromResponse"); + #endif if (DEBUGGING) { @@ -539,6 +582,10 @@ void getReturnValueFromResponse(char *response, char *operation, char *output) { // TODO: these should all bubble up and return legible errors void sendProgramToCoprocessor(char* program, char *output) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: sendProgramToCoprocessor"); + #endif + if (DEBUGGING) { printf("sendProgramToCoprocessor\n"); @@ -560,6 +607,10 @@ void sendProgramToCoprocessor(char* program, char *output) { // TODO: this is a function we would want to expose in a library void callFunctionOnCoprocessor(char* functionName, char* parameters, char* output) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: callFunctionOnCoprocessor"); + #endif if (DEBUGGING) { @@ -594,6 +645,10 @@ void callFunctionOnCoprocessor(char* functionName, char* parameters, char* outpu // TODO: this is a function we would want to expose in a library void callEvalOnCoprocessor(char* toEval, char* output) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: callEvalOnCoprocessor"); + #endif if (DEBUGGING) { diff --git a/dist/MessagesForMacintosh.dsk b/dist/MessagesForMacintosh.dsk index e9e6a1c..419ad59 100644 Binary files a/dist/MessagesForMacintosh.dsk and b/dist/MessagesForMacintosh.dsk differ diff --git a/dist/MessagesForMacintosh.zip b/dist/MessagesForMacintosh.zip index b4bea1b..272fb71 100644 Binary files a/dist/MessagesForMacintosh.zip and b/dist/MessagesForMacintosh.zip differ diff --git a/mac_main.c b/mac_main.c index fa66117..c51322d 100644 --- a/mac_main.c +++ b/mac_main.c @@ -24,7 +24,8 @@ #include "mac_main.h" // #define MAC_APP_DEBUGGING -//#define PROFILING 1 +// #define PROFILING 1 +#define DEBUG_FUNCTION_CALLS #ifdef PROFILING OSErr writeSerialPortProfile(const char* str) @@ -318,6 +319,18 @@ void EventLoop(struct nk_context *ctx) // only re-render if there is an event, prevents screen flickering, speeds up app if (beganInput || firstOrMouseMove || forceRedraw) { + if (beganInput) { + writeSerialPortDebug(boutRefNum, "beganInput"); + } + + if (beganInput) { + writeSerialPortDebug(boutRefNum, "beganInput"); + } + + if (forceRedraw) { + writeSerialPortDebug(boutRefNum, "forceRedraw"); + } + #ifdef PROFILING PROFILE_START("nk_input_end"); #endif @@ -383,6 +396,9 @@ void EventLoop(struct nk_context *ctx) the appropriate routines. */ void DoEvent(EventRecord *event, struct nk_context *ctx) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: DoEvent"); + #endif short part; WindowPtr window; diff --git a/nuklear.h b/nuklear.h index af1e906..3119535 100644 --- a/nuklear.h +++ b/nuklear.h @@ -7713,6 +7713,9 @@ nk_draw_text(struct nk_command_buffer *b, struct nk_rect r, NK_API void nk_input_begin(struct nk_context *ctx) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_input_begin"); + #endif short i; struct nk_input *in; // NK_ASSERT(ctx); @@ -7733,6 +7736,9 @@ nk_input_begin(struct nk_context *ctx) NK_API void nk_input_end(struct nk_context *ctx) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_input_end"); + #endif struct nk_input *in; // NK_ASSERT(ctx); if (!ctx) return; @@ -9967,12 +9973,18 @@ NK_API nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_begin"); + #endif return nk_begin_titled(ctx, title, title, bounds, flags); } NK_API nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_begin_titled"); + #endif struct nk_window *win; struct nk_style *style; nk_hash name_hash; @@ -10132,6 +10144,10 @@ nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, NK_API void nk_end(struct nk_context *ctx) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_end"); + #endif struct nk_panel *layout; // NK_ASSERT(ctx); // NK_ASSERT(ctx->current && "if this triggers you forgot to call `nk_begin`"); diff --git a/nuklear_app.c b/nuklear_app.c index a45dc37..31c8de0 100644 --- a/nuklear_app.c +++ b/nuklear_app.c @@ -21,6 +21,10 @@ // based on https://github.com/jwerle/strsplit.c -- cleaned up and modified to use strtokm rather than strtok int strsplit (const char *str, char *parts[], const char *delimiter) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: strsplit"); + #endif + char *pch; int i = 0; char *copy = NULL; @@ -80,6 +84,10 @@ int strsplit (const char *str, char *parts[], const char *delimiter) { } void aFailed(char *file, int line) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: aFailed"); + #endif MoveTo(10, 10); char textoutput[255]; @@ -135,6 +143,10 @@ void refreshNuklearApp(Boolean blankInput); void getMessagesFromjsFunctionResponse() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: getMessagesFromjsFunctionResponse"); + #endif + for (int i = 0; i < MAX_CHAT_MESSAGES; i++) { memset(&activeChatMessages[i], '\0', 2048); @@ -158,6 +170,10 @@ void getMessagesFromjsFunctionResponse() { // function to send messages in chat void sendMessage() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: sendMessage"); + #endif + writeSerialPortDebug(boutRefNum, "sendMessage!"); char output[2048]; @@ -181,6 +197,10 @@ void sendMessage() { // interval is set by the event loop in mac_main void getChats() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: getChats"); + #endif + writeSerialPortDebug(boutRefNum, "getChats!"); callFunctionOnCoprocessor("getChats", "", jsFunctionResponse); @@ -198,6 +218,10 @@ void getChats() { void sendIPAddressToCoprocessor() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: sendIPAddressToCoprocessor"); + #endif + writeSerialPortDebug(boutRefNum, "sendIPAddressToCoprocessor!"); char output[2048]; @@ -217,6 +241,10 @@ void sendIPAddressToCoprocessor() { // figure out pagination?? button on the top that says "get previous chats"? void getMessages(char *thread, int page) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: getMessages"); + #endif + writeSerialPortDebug(boutRefNum, "getMessages!"); char output[68]; @@ -234,11 +262,19 @@ void getMessages(char *thread, int page) { // from https://stackoverflow.com/a/4770992 Boolean prefix(const char *pre, const char *str) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: prefix"); + #endif return strncmp(pre, str, strlen(pre)) == 0; } void getChatCounts() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: getChatCounts"); + #endif + writeSerialPortDebug(boutRefNum, "getChatCounts!"); callFunctionOnCoprocessor("getChatCounts", "", chatCountFunctionResponse); @@ -392,6 +428,10 @@ void getChatCounts() { void getHasNewMessagesInChat(char *thread) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: getHasNewMessagesInChat"); + #endif + writeSerialPortDebug(boutRefNum, "getHasNewMessagesInChat!"); char output[68]; @@ -421,6 +461,10 @@ Boolean chatWindowCollision; Boolean messageWindowCollision; Boolean checkCollision(struct nk_rect window) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: checkCollision"); + #endif // writeSerialPortDebug(boutRefNum, "checkCollision!"); // Boolean testout = (window.x < mouse_x && @@ -442,6 +486,10 @@ Boolean checkCollision(struct nk_rect window) { // UI setup and event handling goes here static void nuklearApp(struct nk_context *ctx) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nuklearApp"); + #endif + // prompt the user for the graphql instance if (!coprocessorLoaded) { @@ -476,10 +524,10 @@ static void nuklearApp(struct nk_context *ctx) { { nk_layout_row_push(ctx, WINDOW_WIDTH / 2 - 100); - nk_edit_string(ctx, NK_EDIT_SIMPLE, ip_input_buffer, &ip_input_buffer_len, 255, nk_filter_default); + short ip_edit_return_value = nk_edit_string(ctx, NK_EDIT_ALWAYS_INSERT_MODE|NK_EDIT_GOTO_END_ON_ACTIVATE, ip_input_buffer, &ip_input_buffer_len, 255, nk_filter_default); nk_layout_row_push(ctx, 55); - if (nk_button_label(ctx, "save")) { + if (nk_button_label(ctx, "save") || ip_edit_return_value == 17) { ipAddressSet = 1; forceRedraw = 2; @@ -491,6 +539,12 @@ static void nuklearApp(struct nk_context *ctx) { nk_end(ctx); } + // eliminate the initially-set force-redraw + if (forceRedraw) { + + forceRedraw--; + } + return; } @@ -608,6 +662,8 @@ static void nuklearApp(struct nk_context *ctx) { { nk_layout_row_push(ctx, 312); + nk_edit_focus(ctx, NK_EDIT_ALWAYS_INSERT_MODE); + short edit_return_value = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, box_input_buffer, &box_input_len, 2048, nk_filter_default); // this is the enter key, obviously @@ -648,6 +704,10 @@ static void nuklearApp(struct nk_context *ctx) { void refreshNuklearApp(Boolean blankInput) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: refreshNuklearApp"); + #endif + nk_input_begin(ctx); if (blankInput) { @@ -664,6 +724,10 @@ void refreshNuklearApp(Boolean blankInput) { struct nk_context* initializeNuklearApp() { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: initializeNuklearApp"); + #endif + sprintf(activeChat, "no active chat"); memset(&chatCountFunctionResponse, '\0', 32767); memset(&previousChatCountFunctionResponse, '\0', 32767); diff --git a/nuklear_quickdraw.h b/nuklear_quickdraw.h index 0ed88b7..77822e7 100644 --- a/nuklear_quickdraw.h +++ b/nuklear_quickdraw.h @@ -393,6 +393,11 @@ short widthFor12ptFont[128] = { // doing this in a "fast" way by using a precomputed table for a 12pt font static short nk_quickdraw_font_get_text_width(nk_handle handle, short height, const char *text, short len) { + // this is going to produce a lot of logging and not a lot of value: + // #ifdef DEBUG_FUNCTION_CALLS + // writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_quickdraw_font_get_text_width"); + // #endif + if (!text || len == 0) { return 0; @@ -410,6 +415,10 @@ static short nk_quickdraw_font_get_text_width(nk_handle handle, short height, co static int _get_text_width(const char *text, int len) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: _get_text_width"); + #endif + if (!text || len == 0) { return 0; @@ -449,6 +458,10 @@ int mostRight = WINDOW_WIDTH; void updateBounds(int top, int bottom, int left, int right) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: updateBounds"); + #endif + if (left < mostLeft) { mostLeft = left; @@ -475,6 +488,9 @@ void updateBounds(int top, int bottom, int left, int right) { #else void runDrawCommand(const struct nk_command *cmd) { #endif + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: runDrawCommand"); + #endif switch (cmd->type) { @@ -1063,6 +1079,10 @@ int currentCalls; NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) { + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_quickdraw_render"); + #endif + currentCalls = 1; #ifdef PROFILING @@ -1177,6 +1197,10 @@ NK_API void nk_quickdraw_render(WindowPtr window, struct nk_context *ctx) { } NK_API int nk_quickdraw_handle_event(EventRecord *event, struct nk_context *nuklear_context) { + + #ifdef DEBUG_FUNCTION_CALLS + writeSerialPortDebug(boutRefNum, "DEBUG_FUNCTION_CALLS: nk_quickdraw_handle_event"); + #endif // see: inside macintosh: toolbox essentials 2-4 // and inside macintosh toolbox essentials 2-79