2014-04-26 21:01:26 +00:00
|
|
|
/*
|
|
|
|
* Apple // emulator for *nix
|
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
|
|
|
* version 2 or later (your choice) as published by the Free Software
|
|
|
|
* Foundation.
|
|
|
|
*
|
|
|
|
* THERE ARE NO WARRANTIES WHATSOEVER.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "testcommon.h"
|
|
|
|
|
2014-04-28 18:56:36 +00:00
|
|
|
#define TESTBUF_SZ 1024
|
|
|
|
|
2014-12-28 22:50:43 +00:00
|
|
|
bool test_do_reboot = true;
|
2014-12-29 00:10:32 +00:00
|
|
|
char mdstr[(SHA_DIGEST_LENGTH*2)+1];
|
2014-12-28 22:50:43 +00:00
|
|
|
|
2014-04-26 22:43:40 +00:00
|
|
|
static char input_str[TESTBUF_SZ]; // ASCII
|
|
|
|
static unsigned int input_length = 0;
|
|
|
|
static unsigned int input_counter = 0;
|
|
|
|
|
|
|
|
static struct timespec t0 = { 0 };
|
|
|
|
static struct timespec ti = { 0 };
|
|
|
|
|
2014-04-26 21:01:26 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Stub functions because I've reached diminishing returns with the build system ...
|
|
|
|
//
|
|
|
|
// NOTE: You'd think the commandline CFLAGS set specifically for this test program would pass down to the sources in
|
|
|
|
// subdirectories, but it apparently isn't. GNU buildsystem bug? Also see HACK FIXME TODO NOTE in Makefile.am
|
|
|
|
//
|
|
|
|
|
|
|
|
uint8_t c_MB_Read(uint16_t addr) {
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void c_MB_Write(uint16_t addr, uint8_t byte) {
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t c_PhasorIO(uint16_t addr) {
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
|
2015-01-31 21:57:10 +00:00
|
|
|
void c_speaker_toggle(void) {
|
2014-04-26 21:01:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void c_interface_print(int x, int y, const int cs, const char *s) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-04-26 22:43:40 +00:00
|
|
|
void test_common_setup() {
|
|
|
|
input_counter = 0;
|
|
|
|
input_length = 0;
|
|
|
|
input_str[0] = '\0';
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &t0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// test video functions and stubs
|
|
|
|
|
|
|
|
void testing_video_sync() {
|
|
|
|
|
|
|
|
if (!input_length) {
|
|
|
|
input_length = strlen(input_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input_counter >= input_length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t ch = (uint8_t)input_str[input_counter];
|
|
|
|
if (ch == '\n') {
|
|
|
|
ch = '\r';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (apple_ii_64k[0][0xC000] & 0x80) || (apple_ii_64k[1][0xC000] & 0x80) ) {
|
|
|
|
// last character typed not processed by emulator...
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
apple_ii_64k[0][0xC000] = ch | 0x80;
|
|
|
|
apple_ii_64k[1][0xC000] = ch | 0x80;
|
|
|
|
|
|
|
|
++input_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_type_input(const char *input) {
|
|
|
|
strcat(input_str, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-04-26 21:01:26 +00:00
|
|
|
void test_breakpoint(void *arg) {
|
|
|
|
fprintf(GREATEST_STDOUT, "set breakpoint on test_breakpoint to check for problems...\n");
|
|
|
|
#if !HEADLESS
|
|
|
|
if (!is_headless) {
|
2014-11-22 22:08:53 +00:00
|
|
|
fprintf(GREATEST_STDOUT, "DISPLAY NOTE: busy-spinning, needs gdb/lldb intervention to continue...\n");
|
2015-01-03 21:11:56 +00:00
|
|
|
volatile bool debug_continue = false;
|
2014-11-22 22:08:53 +00:00
|
|
|
while (!debug_continue) {
|
|
|
|
struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
|
|
|
|
nanosleep(&ts, NULL);
|
|
|
|
}
|
2014-04-26 21:01:26 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-26 22:43:40 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-04-26 21:01:26 +00:00
|
|
|
void test_common_init(bool do_cputhread) {
|
|
|
|
GREATEST_SET_BREAKPOINT_CB(test_breakpoint, NULL);
|
|
|
|
|
|
|
|
do_logging = false;// silence regular emulator logging
|
|
|
|
setenv("APPLE2IXCFG", "nosuchconfigfile", 1);
|
|
|
|
|
|
|
|
c_initialize_firsttime();
|
|
|
|
|
|
|
|
// kludgey set max CPU speed...
|
|
|
|
cpu_scale_factor = CPU_SCALE_FASTEST;
|
|
|
|
cpu_altscale_factor = CPU_SCALE_FASTEST;
|
2015-01-31 21:57:10 +00:00
|
|
|
is_fullspeed = true;
|
2014-04-26 21:01:26 +00:00
|
|
|
|
|
|
|
caps_lock = true;
|
|
|
|
|
|
|
|
if (do_cputhread) {
|
|
|
|
// spin off cpu thread
|
|
|
|
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
|
|
|
|
c_debugger_set_watchpoint(WATCHPOINT_ADDR);
|
|
|
|
if (is_headless) {
|
2015-01-12 02:37:57 +00:00
|
|
|
c_debugger_set_timeout(15);
|
2014-04-26 21:01:26 +00:00
|
|
|
} else {
|
2014-12-29 00:14:54 +00:00
|
|
|
fprintf(stderr, "NOTE : RUNNING WITH DISPLAY\n");
|
|
|
|
fprintf(stderr, "Will spinloop on failed tests for debugger intervention\n");
|
|
|
|
fprintf(stderr, "Pass HEADLESS=1 to environment to run nonstop\n");
|
2014-04-26 21:01:26 +00:00
|
|
|
c_debugger_set_timeout(0);
|
|
|
|
}
|
2015-01-31 22:23:18 +00:00
|
|
|
} else {
|
|
|
|
#ifdef AUDIO_ENABLED
|
|
|
|
DSInit();
|
|
|
|
speaker_init();
|
|
|
|
MB_Initialize();
|
|
|
|
#endif
|
|
|
|
reinitialize();
|
2014-04-26 21:01:26 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 22:43:40 +00:00
|
|
|
|
2014-11-02 01:44:54 +00:00
|
|
|
int test_setup_boot_disk(const char *fileName, int readonly) {
|
2014-10-12 19:24:54 +00:00
|
|
|
char *disk = NULL;
|
|
|
|
int err = 0;
|
|
|
|
#ifdef __APPLE__
|
|
|
|
CFBundleRef mainBundle = CFBundleGetMainBundle();
|
|
|
|
CFStringRef fileString = CFStringCreateWithCString(/*allocator*/NULL, fileName, CFStringGetSystemEncoding());
|
|
|
|
CFURLRef fileURL = CFBundleCopyResourceURL(mainBundle, fileString, NULL, NULL);
|
|
|
|
CFRELEASE(fileString);
|
|
|
|
CFStringRef filePath = CFURLCopyFileSystemPath(fileURL, kCFURLPOSIXPathStyle);
|
|
|
|
CFRELEASE(fileURL);
|
|
|
|
CFIndex length = CFStringGetLength(filePath);
|
|
|
|
CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
|
|
|
|
disk = (char *)malloc(maxSize);
|
|
|
|
if (!CFStringGetCString(filePath, disk, maxSize, kCFStringEncodingUTF8)) {
|
|
|
|
FREE(disk);
|
|
|
|
}
|
|
|
|
CFRELEASE(filePath);
|
|
|
|
#else
|
2014-10-25 15:26:53 +00:00
|
|
|
asprintf(&disk, "./disks/%s", fileName);
|
2014-10-12 19:24:54 +00:00
|
|
|
#endif
|
2014-11-02 01:44:54 +00:00
|
|
|
if (c_new_diskette_6(0, disk, readonly)) {
|
2014-10-12 19:24:54 +00:00
|
|
|
int len = strlen(disk);
|
|
|
|
disk[len-3] = '\0';
|
2014-11-02 01:44:54 +00:00
|
|
|
err = (c_new_diskette_6(0, disk, readonly) != NULL);
|
2014-10-12 19:24:54 +00:00
|
|
|
}
|
|
|
|
FREE(disk);
|
|
|
|
return err;
|
|
|
|
}
|
2014-12-28 22:50:43 +00:00
|
|
|
|
|
|
|
void sha1_to_str(const uint8_t * const md, char *buf) {
|
|
|
|
int i=0;
|
|
|
|
for (int j=0; j<SHA_DIGEST_LENGTH; j++, i+=2) {
|
|
|
|
sprintf(buf+i, "%02X", md[j]);
|
|
|
|
}
|
|
|
|
sprintf(buf+i, "%c", '\0');
|
|
|
|
}
|
|
|
|
|