apple2ix/src/test/testcommon.c

167 lines
4.6 KiB
C
Raw Normal View History

2014-04-26 21:01:26 +00:00
/*
* Apple // emulator for *ix
2014-04-26 21:01:26 +00:00
*
* This software package is subject to the GNU General Public License
* version 3 or later (your choice) as published by the Free Software
2014-04-26 21:01:26 +00:00
* Foundation.
*
* Copyright 2013-2015 Aaron Culliney
2014-04-26 21:01:26 +00:00
*
*/
#include "testcommon.h"
2014-04-28 18:56:36 +00:00
#define TESTBUF_SZ 1024
bool test_do_reboot = true;
char mdstr[(SHA_DIGEST_LENGTH*2)+1];
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 };
#if defined(ANDROID)
// We basically compile everything including audio into the Android build, even for testing =)
#else
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;
}
Refactor speaker system to prevent audio glitches and to support CPU automatic speed switching Squashed commit of the following: REFACTOR : fix comments, logging, and rename some variables REFACTOR : fix up some commentary, clean deadc0de REFACTOR : mostly fix all the audio glitches - amplitudes of samples are gradually shifted to zero when speaker has fallen silent - simplifies speaker state machine - fullspeed mode only enqueues quiet samples REFACTOR : fix up a number of other functions and comments REFACTOR : clean up code to submit normal speed wave buffer to OpenAL Move some initializations to the cpu_thread() REFACTOR : properly reset the speaker cycles access counter so we don't underflow and assert REFACTOR : should never get a split buffer from our soundcore implementation Fix warning from gcc ... static array size needs to be computed from integer values REFACTOR : gcc (but not clang) complains about these, so just make them preprocessor defines REFACTOR : use unsigned long long because we don't actually care that this counter is 64bit REFACTOR : remainder_buffer and miscellaneous tweaks - Adds implementation commentary to document remainder_buffer purpose - Also adds sample average for square wave boundary in case where remainder_buffer not used (whole-sample boundary) - Variable renaming and code shuffling REFACTOR : do not dynamically alloc remainder buffer - Never attribute to cache-coherancy bugs what is a simple thread race =P REFACTOR : comments and whitespace REFACTOR : rename public speaker API functions REFACTOR : clean up public speaker API REFACTOR : tabs to spaces REFACTOR : moar deadc0de clean up and renaming REFACTOR : remove deadc0de paths from soundcore REFACTOR : fully excise soundtype stuff now that we only support soundcard output Move a file static to function scope REFACTOR : rename more variables and remove deadc0de REFACTOR : samples_buffer naming and change to explict int16_t REFACTOR : removed deadc0de and shuffled code locations REFACTOR : remainder buffer naming and clarify type REFACTOR : move joystick timing to VM module and remove header visibility REFACTOR : clarify speaker variable name REFACTOR : clarify cycle counting codepaths REFACTOR : VBL/timing interfaces - eliminates passing around a common global REFACTOR : names and comments HACK around volume issue REFACTOR : rename speaker feedback variable REFACTOR : rename global total cycle count REFACTOR : rename a constant Fix test builds REFACTOR: rename to is_fullspeed REFACTOR : local variable naming changes REFACTOR : migrate cycle timing variables to correct location and remove header visibility Allow fullspeed codepath to update speaker REFACTOR : remove deadc0de paths in prep for cleanup REFACTOR : speaker now manages its own VM entry point
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) {
}
#endif
2014-04-26 21:01:26 +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, "DISPLAY NOTE: busy-spinning in test_breakpoint(), needs gdb/lldb intervention to continue...\n");
volatile bool debug_continue = false;
while (!debug_continue) {
struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL);
2014-04-26 21:01:26 +00:00
}
}
// ----------------------------------------------------------------------------
void test_common_init() {
2014-04-26 21:01:26 +00:00
GREATEST_SET_BREAKPOINT_CB(test_breakpoint, NULL);
//do_logging = false;// silence regular emulator logging
caps_lock = true;
2014-04-26 21:01:26 +00:00
// kludgey set max CPU speed...
cpu_scale_factor = CPU_SCALE_FASTEST;
cpu_altscale_factor = CPU_SCALE_FASTEST;
timing_initialize();
2014-04-26 21:01:26 +00:00
c_debugger_set_watchpoint(WATCHPOINT_ADDR);
if (0) {
c_debugger_set_timeout(15);
2015-01-31 22:23:18 +00:00
} else {
fprintf(stderr, "NOTE : RUNNING WITH DISPLAY\n");
fprintf(stderr, "Will spinloop on failed tests for debugger intervention\n");
c_debugger_set_timeout(0);
2014-04-26 21:01:26 +00:00
}
}
2014-11-02 01:44:54 +00:00
int test_setup_boot_disk(const char *fileName, int readonly) {
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);
CFStringRef filePath = CFURLCopyFileSystemPath(fileURL, kCFURLPOSIXPathStyle);
2015-03-10 03:44:31 +00:00
CFRELEASE(fileString);
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
asprintf(&disk, "%s/disks/%s", data_dir, fileName);
#endif
if (disk6_insert(0, disk, readonly)) {
int len = strlen(disk);
disk[len-3] = '\0'; // try again without '.gz' extension
err = (disk6_insert(0, disk, readonly) != NULL);
}
FREE(disk);
return err;
}
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');
}