Refactor video_sync() and friends

- main thread render loop goes into X11 video driver
    - removes video_sync()
This commit is contained in:
Aaron Culliney
2014-09-06 20:04:32 -07:00
parent 8621b1ac53
commit a929ef854c
10 changed files with 38 additions and 50 deletions

View File

@@ -26,7 +26,7 @@
static uint8_t vga_mem_page_0[SCANWIDTH*SCANHEIGHT];
static uint8_t vga_mem_page_1[SCANWIDTH*SCANHEIGHT];
extern A2Color colormap[256] = { 0 };
A2Color colormap[256] = { 0 };
uint8_t video__wider_font[0x8000];
uint8_t video__font[0x4000];
@@ -574,10 +574,12 @@ void video_plotchar( int x, int y, int scheme, uint8_t c ) {
}
#if !HEADLESS
extern void video_driver_init();
extern void video_driver_shutdown();
extern void video_driver_init(void);
extern void video_driver_main_loop(void);
extern void video_driver_sync(void);
extern void video_driver_shutdown(void);
#endif
void video_init() {
void video_init(void) {
video__fb1 = vga_mem_page_0;
video__fb2 = vga_mem_page_1;
@@ -594,12 +596,18 @@ void video_init() {
#endif
}
void video_shutdown(void)
{
void video_main_loop(void) {
#if !HEADLESS
video_driver_main_loop();
#endif
}
void video_shutdown(void) {
#if !HEADLESS
if (!is_headless) {
video_driver_shutdown();
}
exit(0);
#endif
}

View File

@@ -1443,7 +1443,6 @@ void c_interface_credits()
static struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL);
video_sync(1);
}
c_interface_exit(ch);

View File

@@ -311,7 +311,6 @@ static void c_calibrate_pc_joystick()
SHOW_BUTTONS(joymenu, CALIBRATE_JOYMENU_H);
SHOW_JOYSTICK_AXES(joymenu, CALIBRATE_JOYMENU_W, CALIBRATE_JOYMENU_H, joy_x, joy_y);
video_sync(0);
spinney_idx = (spinney_idx+1) % 4;

View File

@@ -166,7 +166,7 @@ int c_keys_is_shifted()
}
/* -------------------------------------------------------------------------
void c_handle_input() : Handle input : keys and joystick.
Handle input : keys and joystick.
------------------------------------------------------------------------- */
void c_keys_handle_input(int scancode, int pressed)
{
@@ -459,13 +459,8 @@ int c_mygetch(int block)
{
static struct timespec ts = { .tv_sec=0, .tv_nsec=33333333 };
nanosleep(&ts, NULL); // 30Hz framerate
video_sync(1);
}
}
else
{
video_sync(0);
}
retval = next_key;
next_key = -1;

View File

@@ -624,21 +624,9 @@ void c_initialize_firsttime()
}
#if !defined(TESTING) && !defined(__APPLE__)
static void main_thread(void *dummyptr) {
struct timespec sleeptime = { .tv_sec=0, .tv_nsec=8333333 }; // 120Hz
c_keys_set_key(kF8); // show credits
do
{
video_sync(0);
nanosleep(&sleeptime, NULL);
} while (1);
}
extern void cpu_thread(void *dummyptr);
int main(int _argc, char **_argv)
{
int main(int _argc, char **_argv) {
argc = _argc;
argv = _argv;
@@ -648,8 +636,9 @@ int main(int _argc, char **_argv)
// spin off cpu thread
pthread_create(&cpu_thread_id, NULL, (void *) &cpu_thread, (void *)NULL);
// continue with main render thread
main_thread(NULL);
c_keys_set_key(kF8); // show credits
video_main_loop();
}
#endif // TESTING

View File

@@ -59,6 +59,7 @@ void test_common_setup() {
// ----------------------------------------------------------------------------
// test video functions and stubs
extern void video_driver_sync(void);
void testing_video_sync() {
#if !HEADLESS
@@ -66,7 +67,7 @@ void testing_video_sync() {
clock_gettime(CLOCK_MONOTONIC, &ti);
struct timespec deltat = timespec_diff(t0, ti, NULL);
if (deltat.tv_sec || (deltat.tv_nsec >= NANOSECONDS/15) ) {
video_sync(0);
video_driver_sync();
ti = t0;
}
}
@@ -106,7 +107,7 @@ void test_breakpoint(void *arg) {
fprintf(GREATEST_STDOUT, "set breakpoint on test_breakpoint to check for problems...\n");
#if !HEADLESS
if (!is_headless) {
video_sync(0);
video_driver_sync();
}
#endif
}

View File

@@ -345,8 +345,6 @@ TEST test_80col_hires() {
// ----------------------------------------------------------------------------
// Test Suite
extern void cpu_thread(void *dummyptr);
GREATEST_SUITE(test_suite_display) {
GREATEST_SET_SETUP_CB(testdisplay_setup, NULL);

View File

@@ -3208,8 +3208,6 @@ TEST test_check_cxrom(bool flag_cxrom) {
// ----------------------------------------------------------------------------
// Test Suite
extern void cpu_thread(void *dummyptr);
GREATEST_SUITE(test_suite_vm) {
GREATEST_SET_SETUP_CB(testvm_setup, NULL);

View File

@@ -38,7 +38,11 @@ extern A2Color colormap[];
*/
void video_init(void);
/* Undo anything done by video_init. This is called before exiting the
/* Begin main video loop (does not return)
*/
void video_main_loop(void);
/* Undo anything done by video_init() and video_start(). Called before exiting the
* emulator.
*/
void video_shutdown(void);
@@ -105,15 +109,6 @@ void video_loadfont_int(int first, int qty, const uint8_t *data);
*/
void video_plotchar(int row, int col, int color, uint8_t code);
/*
* Draws video and possibly handles keyboard input.
*
* Should flush any video data to the real screen (if any kind of caching
* is in use), check for keyboard input (presently reported via
* c_read_raw_key), and handle flashing text characters.
*/
void video_sync(int block);
void video_set_mode(a2_video_mode_t mode);
/*

View File

@@ -430,8 +430,7 @@ static void c_flash_cursor(int on) {
}
}
/* FIXME: blocking not implemented... */
void video_sync(int block) {
void video_driver_sync(void) {
if (is_headless) {
return;
}
@@ -478,6 +477,7 @@ void video_sync(int block) {
} while (keyevent);
#endif
#warning HACKISH flash count needs refactoring ...
switch (++flash_count)
{
case 6:
@@ -492,6 +492,14 @@ void video_sync(int block) {
}
}
void video_driver_main_loop(void) {
struct timespec sleeptime = { .tv_sec=0, .tv_nsec=8333333 }; // 120Hz
do {
video_driver_sync();
nanosleep(&sleeptime, NULL);
} while (1);
}
#if 0
static Cursor hidecursor() {
Pixmap cursormask;
@@ -900,9 +908,7 @@ void video_driver_init() {
#endif
}
void video_driver_shutdown(void)
{
void video_driver_shutdown(void) {
_destroy_image();
exit(0);
}