Wed, 16 Apr 2014 02:20:43 -0600
fixed bus error handling for real this time (save registers before every instruction and push the saved registers if a bus error occurs, since the instruction may have changed registers before the bus error, and also stop the instruction immediately with longjmp so it won't change memory after the bus error)
This isn't actually what a real 68k does, but it is a good enough approximation. A real 68k will jump back into the middle of the faulted instruction and resume it from the memory access that faulted as opposed to restarting from the beginning like this CPU emulation does. It would be a lot harder to do that with the way this CPU library is designed. Newer versions of MESS basically do the same thing (they use a newer version of this library).
philpem@88 | 1 | #ifndef _UTILS_H |
philpem@88 | 2 | #define _UTILS_H |
philpem@71 | 3 | |
philpem@89 | 4 | #include <stdio.h> |
philpem@89 | 5 | |
philpem@71 | 6 | #ifndef NDEBUG |
philpem@71 | 7 | /// Log a message to stderr |
philpem@71 | 8 | # define LOG(x, ...) do { fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0) |
philpem@98 | 9 | # define LOGS(x) do { fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); } while (0) |
philpem@71 | 10 | /// Log a message to stderr if 'cond' is true |
philpem@71 | 11 | # define LOG_IF(cond, x, ...) do { if (cond) fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__); } while (0) |
philpem@98 | 12 | # define LOG_IFS(cond, x) do { if (cond) fprintf(stderr, "%s:%d:%s(): " x "\n", __FILE__, __LINE__, __PRETTY_FUNCTION__); } while (0) |
philpem@71 | 13 | #else |
philpem@71 | 14 | #define LOG(x, ...) |
philpem@98 | 15 | #define LOGS(x) |
philpem@71 | 16 | #define LOG_IF(cond, x, ...) |
philpem@98 | 17 | #define LOG_IFS(cond, x) |
philpem@71 | 18 | #endif |
philpem@71 | 19 | |
philpem@88 | 20 | /// Get the number of elements in an array |
philpem@88 | 21 | #define NELEMS(x) (sizeof(x)/sizeof(x[0])) |
philpem@88 | 22 | |
philpem@71 | 23 | #endif // _H_UTILS |