From d272682f48d1be18fc700e1ce65991ba09d7900a Mon Sep 17 00:00:00 2001 From: David Schmidt Date: Sat, 8 May 2010 13:33:38 +0000 Subject: [PATCH] Split drivers into pieces --- src/macdriver.c | 1132 ----------------------------------------------- src/windriver.c | 817 ---------------------------------- 2 files changed, 1949 deletions(-) delete mode 100644 src/macdriver.c delete mode 100644 src/windriver.c diff --git a/src/macdriver.c b/src/macdriver.c deleted file mode 100644 index 9c0bf66..0000000 --- a/src/macdriver.c +++ /dev/null @@ -1,1132 +0,0 @@ -/* - GSport - an Apple //gs Emulator - Copyright (C) 2010 by GSport contributors - - Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -// Quartz: CreateCGContextForPort vs QDBeginCGContext - -// Use CGDisplayMoveCursorToPoint(kCGDirectMainDisplay) to warp pointer -// Use CGPointMake to get a point - -#include -#include - -#include "defc.h" -#include "protos_macdriver.h" - -#define MAX_STATUS_LINES 7 -#define X_LINE_LENGTH 88 -#define MAX_MAC_ARGS 128 - -WindowRef g_main_window; -WindowRef g_main_window_saved; -Rect g_main_window_saved_rect; -Ptr g_mac_fullscreen_state = 0; -int g_quit_seen = 0; -EventHandlerUPP g_quit_handler_UPP; -EventHandlerUPP g_dummy_event_handler_UPP; -RgnHandle g_event_rgnhandle = 0; -int g_ignore_next_click = 0; -int g_mainwin_active = 0; -GDHandle g_gdhandle = 0; - -int g_mac_mouse_x = 0; -int g_mac_mouse_y = 0; - -FMFontFamily g_status_font_family; - -extern Kimage g_mainwin_kimage; - -int g_mac_argc = 0; -char *g_mac_argv[MAX_MAC_ARGS]; -word32 g_mac_shift_control_state = 0; -extern char g_argv0_path[]; -extern char *g_fatal_log_strs[]; -extern int g_fatal_log; - -extern word32 g_red_mask; -extern word32 g_green_mask; -extern word32 g_blue_mask; -extern int g_red_left_shift; -extern int g_green_left_shift; -extern int g_blue_left_shift; -extern int g_red_right_shift; -extern int g_green_right_shift; -extern int g_blue_right_shift; - -int g_use_shmem = 0; - -extern int Verbose; - -extern int g_warp_pointer; -extern int g_screen_depth; -extern int g_force_depth; -int g_screen_mdepth = 0; - -extern int g_send_sound_to_file; - -extern int g_quit_sim_now; -extern int g_config_control_panel; - -extern int g_video_act_width; -extern int g_video_act_height; -extern int g_video_act_margin_left; -extern int g_video_act_margin_right; -extern int g_video_act_margin_top; -extern int g_video_act_margin_bottom; - -int g_auto_repeat_on = -1; -int g_x_shift_control_state = 0; - - -extern int Max_color_size; - -extern word32 g_palette_8to1624[256]; -extern word32 g_a2palette_8to1624[256]; - -int g_alt_left_up = 1; -int g_alt_right_up = 1; - -extern word32 g_full_refresh_needed; - -extern int g_border_sides_refresh_needed; -extern int g_border_special_refresh_needed; -extern int g_status_refresh_needed; - -extern int g_lores_colors[]; - -extern int g_a2vid_palette; - -extern int g_installed_full_superhires_colormap; - -extern int g_screen_redraw_skip_amt; - -extern word32 g_a2_screen_buffer_changed; -extern char *g_status_ptrs[MAX_STATUS_LINES]; -extern const char g_gsport_version_str[]; - -#if 0 -extern int g_debug_file_fd; - -/* HACK to debug startup issues when launched from Finder */ -int -printf(const char *fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - - if(g_debug_file_fd < 0) { - g_debug_file_fd = open("/tmp/GSport.out", - O_CREAT | O_WRONLY | O_TRUNC, 0x1b6); - fprintf(stdout, "g_debug_file_fd = %d, %d\n", g_debug_file_fd, - errno); - } - ret = gsport_vprintf(fmt, ap); - - va_end(ap); - - return ret; -} -#endif - -pascal OSStatus -quit_event_handler(EventHandlerCallRef call_ref, EventRef event, void *ignore) -{ - OSStatus err; - - err = CallNextEventHandler(call_ref, event); - if(err == noErr) { - g_quit_seen = 1; - } - return err; -} - -void -show_simple_alert(char *str1, char *str2, char *str3, int num) -{ - char buf[256]; - - g_fatal_log_strs[0] = gsport_malloc_str(str1); - g_fatal_log_strs[1] = gsport_malloc_str(str2); - g_fatal_log_strs[2] = gsport_malloc_str(str3); - g_fatal_log = 3; - if(num != 0) { - snprintf(buf, 250, ": %d", num); - g_fatal_log_strs[g_fatal_log++] = gsport_malloc_str(buf); - } - x_show_alert(0, 0); -} - -void -x_dialog_create_gsport_conf(const char *str) -{ - char *path; - char tmp_buf[512]; - int ret; - - ret = x_show_alert(1, str); - if(ret) { - // Create empty file - path = "~"; - snprintf(tmp_buf, 500, "touch %s/%s", path, str); - system(tmp_buf); - } -} - -int -x_show_alert(int is_fatal, const char *str) -{ - DialogRef alert; - DialogItemIndex out_item_hit; - CFStringRef cfstrref, cfstrref2; - CFStringRef okstrref; - AlertStdCFStringAlertParamRec alert_param; - OSStatus osstat; - char *bufptr, *buf2ptr; - int sum, len; - int i; - - /* The dialog eats all events--including key-up events */ - /* Call adb_all_keys_up() to prevent annoying key-repeat problems */ - /* for instance, a key-down causes a dialog to appear--and the */ - /* eats the key-up event...then as soon as the dialog goes, adb.c */ - /* auto-repeat will repeat the key, and the dialog re-appears...*/ - adb_all_keys_up(); - - sum = 20; - for(i = 0; i < g_fatal_log; i++) { - sum += strlen(g_fatal_log_strs[i]); - } - bufptr = malloc(sum); - buf2ptr = bufptr; - for(i = 0; i < g_fatal_log; i++) { - len = strlen(g_fatal_log_strs[i]); - len = MIN(len, sum); - len = MAX(len, 0); - memcpy(bufptr, g_fatal_log_strs[i], MIN(len, sum)); - bufptr += len; - bufptr[0] = 0; - sum = sum - len; - } - - cfstrref = CFStringCreateWithCString(NULL, buf2ptr, - kCFStringEncodingMacRoman); - - printf("buf2ptr: :%s:\n", buf2ptr); - - osstat = GetStandardAlertDefaultParams(&alert_param, - kStdCFStringAlertVersionOne); - - if(str) { - // Provide an extra option--create a file - cfstrref2 = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, - CFSTR("Create ~/%s"), str); - alert_param.otherText = cfstrref2; - } - okstrref = CFSTR("Click OK to continue"); - if(is_fatal) { - okstrref = CFSTR("Click OK to exit GSport"); - } - CreateStandardAlert(kAlertStopAlert, cfstrref, okstrref, - &alert_param, &alert); - out_item_hit = -1; - RunStandardAlert(alert, NULL, &out_item_hit); - printf("out_item_hit: %d\n", out_item_hit); - free(buf2ptr); - - clear_fatal_logs(); /* free the fatal_log string memory */ - return (out_item_hit >= 3); -} - - -pascal OSStatus -my_cmd_handler( EventHandlerCallRef handlerRef, EventRef event, void *userdata) -{ - OSStatus osresult; - HICommand command; - word32 command_id; - - osresult = eventNotHandledErr; - - GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, - sizeof(HICommand), NULL, &command); - - command_id = (word32)command.commandID; - switch(command_id) { - case 'Kbep': - SysBeep(10); - osresult = noErr; - break; - case 'abou': - show_simple_alert("GSport v", (char *)g_gsport_version_str, - ", Copyright 2010 GSport Contributors\n" - "Latest version at http://gsport.sourceforge.net/\n", 0); - osresult = noErr; - break; - case 'KCFG': - cfg_toggle_config_panel(); - osresult = noErr; - break; - case 'quit': - break; - case 'swin': - /* not sure what this is, but Panther sends it */ - break; - default: - printf("commandID %08x unknown\n", command_id); - SysBeep(90); - break; - } - return osresult; -} - -int g_upd_count = 0; - -void -update_window(void) -{ - SetPortWindowPort(g_main_window); - - PenNormal(); - - g_full_refresh_needed = -1; - g_a2_screen_buffer_changed = -1; - g_status_refresh_needed = 1; - g_border_sides_refresh_needed = 1; - g_border_special_refresh_needed = 1; - - g_upd_count++; - if(g_upd_count > 250) { - g_upd_count = 0; - } - -} - -struct char_int_un { - union { - char c[4]; - UInt32 uint; - } u; - char c2[2]; -}; - -typedef struct char_int_un Char_int; - -int g_event_count = 0; - -void -show_event(UInt32 event_class, UInt32 event_kind, int handled) -{ - Char_int char_int; - - if(handled == 0 && event_class != 'cgs ') { - char_int.c2[0] = 0; - char_int.u.uint = event_class; - printf("Event %d: %08x = %s, %d\n", g_event_count, - (int)event_class, &(char_int.u.c[0]), (int)event_kind); - } - g_event_count++; -} - -pascal OSStatus -my_win_handler(EventHandlerCallRef handlerRef, EventRef event, void *userdata) -{ - OSStatus os_result; - UInt32 event_kind; - - os_result = eventNotHandledErr; - - // SysBeep(1); - - event_kind = GetEventKind(event); - // show_alert("win handler", event_kind); - if(event_kind == kEventWindowDrawContent) { - update_window(); - } if(event_kind == kEventWindowClose) { - g_quit_sim_now = 1; - g_quit_seen = 1; - my_exit(0); - } else { - show_event(GetEventClass(event), event_kind, 0); - update_window(); - } - - return os_result; -} - - -pascal OSStatus -dummy_event_handler(EventHandlerCallRef call_ref, EventRef in_event, - void *ignore) -{ - OSStatus err; - EventHandlerRef installed_handler; - EventTypeSpec event_spec = { kEventClassApplication, kEventAppQuit }; - - // From http://developer.apple.com/qa/qa2001/qa1061.html - // Trick to move main event queue to use ReceiveNextEvent in an event - // handler called by RunApplicationEventLoop - - err = InstallApplicationEventHandler(g_quit_handler_UPP, 1, &event_spec, - NULL, &installed_handler); - - gsportmain(g_mac_argc, g_mac_argv); - - return noErr; -} - -void -mac_update_modifiers(word32 state) -{ - word32 state_xor; - int is_up; - - state = state & (cmdKey | shiftKey | alphaLock | optionKey | - controlKey); - state_xor = g_mac_shift_control_state ^ state; - is_up = 0; - if(state_xor & controlKey) { - is_up = ((state & controlKey) == 0); - adb_physical_key_update(0x36, is_up); - } - if(state_xor & alphaLock) { - is_up = ((state & alphaLock) == 0); - adb_physical_key_update(0x39, is_up); - } - if(state_xor & shiftKey) { - is_up = ((state & shiftKey) == 0); - adb_physical_key_update(0x38, is_up); - } - if(state_xor & cmdKey) { - is_up = ((state & cmdKey) == 0); - adb_physical_key_update(0x37, is_up); - } - if(state_xor & optionKey) { - is_up = ((state & optionKey) == 0); - adb_physical_key_update(0x3a, is_up); - } - - g_mac_shift_control_state = state; -} - -void -mac_warp_mouse() -{ - Rect port_rect; - Point win_origin_pt; - CGPoint cgpoint; - CGDisplayErr cg_err; - - GetPortBounds(GetWindowPort(g_main_window), &port_rect); - SetPt(&win_origin_pt, port_rect.left, port_rect.top); - LocalToGlobal(&win_origin_pt); - - cgpoint = CGPointMake( (float)(win_origin_pt.h + X_A2_WINDOW_WIDTH/2), - (float)(win_origin_pt.v + X_A2_WINDOW_HEIGHT/2)); - cg_err = CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint); -} - -void -check_input_events() -{ - OSStatus err; - EventTargetRef target; - EventRef event; - UInt32 event_class, event_kind; - byte mac_keycode; - UInt32 keycode; - UInt32 modifiers; - Point mouse_point, mouse_delta_point; - WindowRef window_ref; - int button, button_state; - EventMouseButton mouse_button; - int handled; - int mouse_events; - int is_up; - int in_win; - int ignore; - - if(g_quit_seen) { - exit(0); - } - - SetPortWindowPort(g_main_window); - - mouse_events = 0; - target = GetEventDispatcherTarget(); - while(1) { - err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, - true, &event); - - if(err == eventLoopTimedOutErr) { - break; - } - if(err != noErr) { - printf("ReceiveNextEvent err: %d\n", (int)err); - break; - } - - event_class = GetEventClass(event); - event_kind = GetEventKind(event); - handled = 0; - switch(event_class) { - case kEventClassKeyboard: - handled = 1; - keycode = 0; - modifiers = 0; - GetEventParameter(event, kEventParamKeyMacCharCodes, - typeChar, NULL, sizeof(byte), NULL, - &mac_keycode); - GetEventParameter(event, kEventParamKeyCode, - typeUInt32, NULL, sizeof(UInt32), NULL, - &keycode); - GetEventParameter(event, kEventParamKeyModifiers, - typeUInt32, NULL, sizeof(UInt32), NULL, - &modifiers); - - mac_update_modifiers((word32)modifiers); - - // Key up/down event - is_up = -1; - switch(event_kind) { - case kEventRawKeyDown: - is_up = 0; - //printf("key down: %02x, %08x\n", - // (int)mac_keycode, (int)keycode); - break; - case kEventRawKeyUp: - is_up = 1; - //printf("key up: %02x, %08x\n", - // (int)mac_keycode, (int)keycode); - break; - case kEventRawKeyModifiersChanged: - is_up = -1; - //printf("key xxx: %08x\n", (int)modifiers); - break; - } - if(is_up >= 0) { - adb_physical_key_update((int)keycode, is_up); - } - break; - case kEventClassMouse: - handled = 2; - mouse_events++; - GetEventParameter(event, kEventParamMouseLocation, - typeQDPoint, NULL, sizeof(Point), NULL, - &mouse_point); - GetWindowRegion(g_main_window, kWindowContentRgn, - g_event_rgnhandle); - in_win = PtInRgn(mouse_point, g_event_rgnhandle); - // in_win = 1 if it was in the contect region of window - err = GetEventParameter(event, kEventParamMouseDelta, - typeQDPoint, NULL, sizeof(Point), NULL, - &mouse_delta_point); - button = 0; - button_state = -1; - switch(event_kind) { - case kEventMouseDown: - button_state = 7; - handled = 3; - break; - case kEventMouseUp: - button_state = 0; - handled = 3; - break; - } - if(button_state >= 0) { - GetEventParameter(event, kEventParamMouseButton, - typeMouseButton, NULL, - sizeof(EventMouseButton), NULL, - &mouse_button); - button = mouse_button; - if(button > 1) { - button = 4 - button; - button = 1 << button; - } - ignore = (button_state != 0) && - (!in_win || g_ignore_next_click); - ignore = ignore || !g_mainwin_active; - if(ignore) { - // Outside of A2 window, ignore clicks - button = 0; - } - if(button_state == 0) { - g_ignore_next_click = 0; - } - } - - GlobalToLocal(&mouse_point); - - if(g_warp_pointer) { - if(err == 0) { - g_mac_mouse_x += mouse_delta_point.h; - g_mac_mouse_y += mouse_delta_point.v; - } - mac_warp_mouse(); - } else { - g_mac_mouse_x = mouse_point.h - - g_video_act_margin_left; - g_mac_mouse_y = mouse_point.v - - g_video_act_margin_top; - } - -#if 0 - printf("Mouse %d at: %d,%d button:%d, button_st:%d\n", - mouse_events, g_mac_mouse_x, g_mac_mouse_y, - button, button_state); - printf("Mouse deltas: err:%d, %d,%d\n", (int)err, - mouse_delta_point.h, mouse_delta_point.v); -#endif - - update_mouse(g_mac_mouse_x, g_mac_mouse_y, - button_state, button & 7); - if(g_warp_pointer) { - g_mac_mouse_x = A2_WINDOW_WIDTH/2; - g_mac_mouse_y = A2_WINDOW_HEIGHT/2; - update_mouse(g_mac_mouse_x, g_mac_mouse_y,0,-1); - } - break; - case kEventClassApplication: - switch(event_kind) { - case kEventAppActivated: - handled = 1; - g_mainwin_active = 1; - window_ref = 0; - GetEventParameter(event, kEventParamWindowRef, - typeWindowRef, NULL, sizeof(WindowRef), - NULL, &window_ref); - if(window_ref == g_main_window) { - g_ignore_next_click = 1; - } - break; - case kEventAppDeactivated: - handled = 1; - g_mainwin_active = 0; - g_ignore_next_click = 1; - break; - } - break; - } - show_event(event_class, event_kind, handled); - if(handled != 1) { - (void)SendEventToEventTarget(event, target); - } - ReleaseEvent(event); - } - - return; -} - -void -temp_run_application_event_loop(void) -{ - OSStatus err; - EventRef dummy_event; - EventHandlerRef install_handler; - EventTypeSpec event_spec = { 'KWIN', 'KWIN' }; - - // Create UPP for dummy_event_handler and for quit_event_handler - err = noErr; - dummy_event = 0; - - g_dummy_event_handler_UPP = NewEventHandlerUPP(dummy_event_handler); - g_quit_handler_UPP = NewEventHandlerUPP(quit_event_handler); - if((g_dummy_event_handler_UPP == 0) || (g_quit_handler_UPP == 0)) { - err = memFullErr; - } - - if(err == noErr) { - err = InstallApplicationEventHandler(g_dummy_event_handler_UPP, - 1, &event_spec, 0, &install_handler); - if(err == noErr) { - err = MacCreateEvent(NULL, 'KWIN', 'KWIN', - GetCurrentEventTime(), kEventAttributeNone, - &dummy_event); - if(err == noErr) { - err = PostEventToQueue(GetMainEventQueue(), - dummy_event, kEventPriorityHigh); - } - if(err == noErr) { - RunApplicationEventLoop(); - } - - (void)RemoveEventHandler(install_handler); - } - } - - if(dummy_event != NULL) { - ReleaseEvent(dummy_event); - } -} - -int -main(int argc, char* argv[]) -{ - ProcessSerialNumber my_psn; - IBNibRef nibRef; - EventHandlerUPP handlerUPP; - EventTypeSpec cmd_event[3]; -#if 0 - MenuBarHandle mbar_handle; - MenuRef menu_ref; -#endif - Rect win_rect; - OSStatus err; - char *argptr; - int slash_cnt; - int i; - - /* Prepare argv0 */ - slash_cnt = 0; - argptr = argv[0]; - for(i = strlen(argptr); i >= 0; i--) { - if(argptr[i] == '/') { - slash_cnt++; - if(slash_cnt == 3) { - strncpy(&(g_argv0_path[0]), argptr, i); - g_argv0_path[i] = 0; - } - } - } - - printf("g_argv0_path is %s\n", g_argv0_path); - - g_mac_argv[0] = argv[0]; - g_mac_argc = 1; - i = 1; - while((i < argc) && (g_mac_argc < MAX_MAC_ARGS)) { - if(!strncmp(argv[i], "-psn", 4)) { - /* skip this argument */ - } else { - g_mac_argv[g_mac_argc++] = argv[i]; - } - i++; - } - - InitCursor(); - g_event_rgnhandle = NewRgn(); - g_status_font_family = FMGetFontFamilyFromName("\pCourier"); - SetRect(&win_rect, 0, 0, X_A2_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT + - MAX_STATUS_LINES*16 + 8); - OffsetRect(&win_rect, 64, 50); - - // Create a Nib reference passing the name of the nib file - // CreateNibReference only searches into the application bundle. - err = CreateNibReference(CFSTR("main"), &nibRef); - require_noerr( err, CantGetNibRef ); - - // Once the nib reference is created, set the menu bar. - err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar")); - require_noerr( err, CantSetMenuBar ); - - -#if 0 - mbar_handle = GetMenuBar(); - SetMenuBar(mbar_handle); - printf("mbar_handle: %p\n", mbar_handle); - - menu_ref = NewMenu(1, "\pTest"); - printf("menu_ref: %p\n", menu_ref); - AppendMenu(menu_ref, "\pTest item 1"); - InsertMenu(menu_ref, 0); -// ShowMenuBar(); // Don't call ShowMenuBar: it prevents menubar update! - DrawMenuBar(); - InvalMenuBar(); -#endif - - err = CreateNewWindow(kDocumentWindowClass, - kWindowStandardDocumentAttributes | - kWindowStandardHandlerAttribute, - &win_rect, &g_main_window); - - //printf("CreateNewWindow ret: %d, g_main_window: %p\n", (int)err, - // g_main_window); - - err = SetWindowTitleWithCFString(g_main_window, CFSTR("GSport")); - - // We don't need the nib reference anymore. - DisposeNibReference(nibRef); - - SysBeep(120); - - handlerUPP = NewEventHandlerUPP( my_cmd_handler ); - - cmd_event[0].eventClass = kEventClassCommand; - cmd_event[0].eventKind = kEventProcessCommand; - InstallWindowEventHandler(g_main_window, handlerUPP, 1, &cmd_event[0], - (void *)g_main_window, NULL); - - handlerUPP = NewEventHandlerUPP(my_win_handler); - cmd_event[0].eventClass = kEventClassWindow; - cmd_event[0].eventKind = kEventWindowDrawContent; - cmd_event[1].eventClass = kEventClassWindow; - cmd_event[1].eventKind = kEventWindowUpdate; - cmd_event[2].eventClass = kEventClassWindow; - cmd_event[2].eventKind = kEventWindowClose; - err = InstallWindowEventHandler(g_main_window, handlerUPP, 3, - &cmd_event[0], (void *)g_main_window, NULL); - require_noerr(err, CantCreateWindow); - - // Get screen depth - g_gdhandle = GetGDevice(); - g_screen_mdepth = (**((**g_gdhandle).gdPMap)).pixelSize; - - g_screen_depth = g_screen_mdepth; - - //printf("g_screen_depth = %d, depth: %d, bytes: %d\n", g_screen_depth, - // (**g_gdhandle).gdCCDepth, (**g_gdhandle).gdCCBytes); - - if(g_screen_depth > 16) { - /* 32-bit display */ - g_red_mask = 0xff; - g_green_mask = 0xff; - g_blue_mask = 0xff; - g_red_left_shift = 16; - g_green_left_shift = 8; - g_blue_left_shift = 0; - g_red_right_shift = 0; - g_green_right_shift = 0; - g_blue_right_shift = 0; - } else if(g_screen_depth > 8) { - /* 16-bit display */ - g_red_mask = 0x1f; - g_green_mask = 0x1f; - g_blue_mask = 0x1f; - g_red_left_shift = 10; - g_green_left_shift = 5; - g_blue_left_shift = 0; - g_red_right_shift = 3; - g_green_right_shift = 3; - g_blue_right_shift = 3; - } - - // show_alert("About to show window", (int)g_main_window); - update_main_window_size(); - - update_window(); - - // The window was created hidden so show it. - ShowWindow( g_main_window ); - BringToFront( g_main_window ); - update_window(); - - // Make us pop to the front a different way - err = GetCurrentProcess(&my_psn); - if(err == noErr) { - (void)SetFrontProcess(&my_psn); - } - - // Call the event loop - temp_run_application_event_loop(); - -CantCreateWindow: -CantSetMenuBar: -CantGetNibRef: - show_simple_alert("ending", "", "error code", err); - return err; -} - - -void -x_update_color(int col_num, int red, int green, int blue, word32 rgb) -{ -} - - -void -x_update_physical_colormap() -{ -} - -void -show_xcolor_array() -{ - int i; - - for(i = 0; i < 256; i++) { - printf("%02x: %08x\n", i, g_palette_8to1624[i]); - } -} - -void -xdriver_end() -{ - - printf("xdriver_end\n"); - if(g_fatal_log >= 0) { - x_show_alert(1, 0); - } -} - -void -x_get_kimage(Kimage *kimage_ptr) -{ - PixMapHandle pixmap_handle; - GWorldPtr world; - Rect world_rect; - OSStatus err; - word32 *wptr; - byte *ptr; - int row_bytes; - int width; - int height; - int depth, mdepth; - int size; - - width = kimage_ptr->width_req; - height = kimage_ptr->height; - depth = kimage_ptr->depth; - mdepth = kimage_ptr->mdepth; - - size = 0; - if(depth == g_screen_depth) { - SetRect(&world_rect, 0, 0, width, height); - err = NewGWorld( &world, 0, &world_rect, NULL, NULL, 0); - pixmap_handle = GetGWorldPixMap(world); - err = LockPixels(pixmap_handle); - ptr = (byte *)GetPixBaseAddr(pixmap_handle); - row_bytes = ((*pixmap_handle)->rowBytes & 0x3fff); - kimage_ptr->width_act = row_bytes / (mdepth >> 3); - mac_printf("Got depth: %d, bitmap_ptr: %p, width: %d\n", depth, - ptr, kimage_ptr->width_act); - mac_printf("pixmap->base: %08x, rowbytes: %08x, pixType:%08x\n", - (int)(*pixmap_handle)->baseAddr, - (*pixmap_handle)->rowBytes, - (*pixmap_handle)->pixelType); - wptr = (word32 *)(*pixmap_handle); - mac_printf("wptr: %p=%08x %08x %08x %08x %08x %08x %08x %08x\n", - wptr, - wptr[0], wptr[1], wptr[2], wptr[3], - wptr[4], wptr[5], wptr[6], wptr[7]); - kimage_ptr->dev_handle = pixmap_handle; - kimage_ptr->data_ptr = ptr; - } else { - - /* allocate buffers for video.c to draw into */ - - size = (width*height*mdepth) >> 3; - ptr = (byte *)malloc(size); - - if(ptr == 0) { - mac_printf("malloc for data fail, mdepth:%d\n", mdepth); - exit(2); - } - - kimage_ptr->data_ptr = ptr; - - kimage_ptr->dev_handle = (void *)-1; - } - - mac_printf("kim: %p, dev:%p data: %p, size: %08x\n", kimage_ptr, - kimage_ptr->dev_handle, kimage_ptr->data_ptr, size); - -} - -void -dev_video_init() -{ - int lores_col; - int i; - - printf("Preparing graphics system\n"); - - video_get_kimages(); - - if(g_screen_depth != 8) { - // Get g_mainwin_kimage - video_get_kimage(&g_mainwin_kimage, 0, g_screen_depth, - g_screen_mdepth); - } - - for(i = 0; i < 256; i++) { - lores_col = g_lores_colors[i & 0xf]; - video_update_color_raw(i, lores_col); - g_a2palette_8to1624[i] = g_palette_8to1624[i]; - } - - g_installed_full_superhires_colormap = 1; - - fflush(stdout); -} - - -void -x_redraw_status_lines() -{ - Rect rect; - Pattern white_pattern; - char tmp_buf[256]; - char *buf; - int len; - int line; - int height; - int margin; - - SetPortWindowPort(g_main_window); - PenNormal(); - height = 16; - margin = 0; - TextFont(g_status_font_family); - TextFace(normal); - TextSize(12); - - SetRect(&rect, 0, X_A2_WINDOW_HEIGHT + margin, X_A2_WINDOW_WIDTH, - X_A2_WINDOW_HEIGHT + margin + MAX_STATUS_LINES*height); - GetQDGlobalsWhite(&white_pattern); - FillRect(&rect, &white_pattern); - - for(line = 0; line < MAX_STATUS_LINES; line++) { - buf = g_status_ptrs[line]; - if(buf == 0) { - /* skip it */ - continue; - } - MoveTo(10, X_A2_WINDOW_HEIGHT + height*line + margin + height); - len = MIN(250, strlen(buf)); - strncpy(&tmp_buf[1], buf, len); - tmp_buf[0] = len; - DrawString(&tmp_buf[0]); - } - -} - - -void -x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, - int width, int height) -{ - PixMapHandle pixmap_handle; - Rect src_rect, dest_rect; - CGrafPtr window_port; - - SetPortWindowPort(g_main_window); - - pixmap_handle = kimage_ptr->dev_handle; - window_port = GetWindowPort(g_main_window); - SetRect(&src_rect, srcx, srcy, srcx + width, srcy + height); - SetRect(&dest_rect, destx, desty, destx + width, desty + height); - - CopyBits( (BitMap *)(*pixmap_handle), - GetPortBitMapForCopyBits(window_port), &src_rect, &dest_rect, - srcCopy, NULL); - -} - -void -x_push_done() -{ - CGrafPtr window_port; - - SetPortWindowPort(g_main_window); - window_port = GetWindowPort(g_main_window); - - QDFlushPortBuffer(window_port, 0); -} - -void -x_auto_repeat_on(int must) -{ -} - -void -x_auto_repeat_off(int must) -{ -} - -void -x_hide_pointer(int do_hide) -{ - if(do_hide) { - HideCursor(); - } else { - ShowCursor(); - } -} - -void -x_full_screen(int do_full) -{ - WindowRef new_window; - short width, height; - OSErr ret; - - width = 640; - height = 480; - if(do_full && (g_mac_fullscreen_state == 0)) { - g_main_window_saved = g_main_window; - - GetWindowBounds(g_main_window, kWindowContentRgn, - &g_main_window_saved_rect); - ret = BeginFullScreen(&g_mac_fullscreen_state, 0, - &width, &height, &new_window, 0, 0); - printf("Ret beginfullscreen: %d\n", (int)ret); - printf("New width: %d, new height: %d\n", width, height); - if(ret == noErr) { - g_main_window = new_window; - } else { - g_mac_fullscreen_state = 0; - } - } else if(!do_full && (g_mac_fullscreen_state != 0)) { - ret = EndFullScreen(g_mac_fullscreen_state, 0); - printf("ret endfullscreen: %d\n", (int)ret); - g_main_window = g_main_window_saved; - g_mac_fullscreen_state = 0; - //InitCursor(); - SetWindowBounds(g_main_window, kWindowContentRgn, - &g_main_window_saved_rect); - } - - update_main_window_size(); - - ShowWindow(g_main_window); - BringToFront(g_main_window); - update_window(); -} - -void -update_main_window_size() -{ - Rect win_rect; - int width, height; - int left, excess_height; - int top, bottom; - - GetPortBounds(GetWindowPort(g_main_window), &win_rect); - width = win_rect.right - win_rect.left; - height = win_rect.bottom - win_rect.top; - g_video_act_width = width; - g_video_act_height = height; - - left = MAX(0, (width - A2_WINDOW_WIDTH) / 2); - left = MIN(left, BASE_MARGIN_LEFT); - g_video_act_margin_left = left; - g_video_act_margin_right = left; - - - excess_height = (height - A2_WINDOW_HEIGHT) / 2; - bottom = MAX(0, excess_height / 2); // No less than 0 - bottom = MIN(BASE_MARGIN_BOTTOM, bottom); // No more than 30 - g_video_act_margin_bottom = bottom; - excess_height -= bottom; - top = MAX(0, excess_height); - top = MIN(BASE_MARGIN_TOP, top); - g_video_act_margin_top = top; -} diff --git a/src/windriver.c b/src/windriver.c deleted file mode 100644 index 094ca09..0000000 --- a/src/windriver.c +++ /dev/null @@ -1,817 +0,0 @@ -/* - GSport - an Apple //gs Emulator - Copyright (C) 2010 by GSport contributors - - Based on the KEGS emulator written by and Copyright (C) 2003 Kent Dickey - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -/* Based on code from Chea Chee Keong from KEGS32, which is available at */ -/* http://www.geocities.com/akilgard/kegs32 */ - -#define WIN32_LEAN_AND_MEAN /* Tell windows we want less header gunk */ -#define STRICT /* Tell Windows we want compile type checks */ - -#include -#include -#include -#include -#include -#include - -#include "defc.h" -#include "protos.h" -#include "protos_windriver.h" - -extern int Verbose; - -extern int g_pause; // OG Added Pause - -extern int g_warp_pointer; -extern int g_screen_depth; -extern int g_force_depth; -int g_screen_mdepth = 0; - -// OG replaced g_quit_sim_now by quitEmulator -// extern int g_quit_sim_now; -extern void quitEmulator(); - -int g_use_shmem = 1; -int g_has_focus = 0; -int g_auto_repeat_on = -1; - -extern Kimage g_mainwin_kimage; - -//HDC g_main_dc; // OG dc cannot be a global -HDC g_main_cdc; -//int g_main_height = 0; - -int g_win_capslock_down = 0; - -extern word32 g_palette_8to1624[256]; -extern word32 g_a2palette_8to1624[256]; - -extern word32 g_full_refresh_needed; - -extern int g_border_sides_refresh_needed; -extern int g_border_special_refresh_needed; -extern int g_status_refresh_needed; - -extern int g_lores_colors[]; -extern int g_cur_a2_stat; - -extern int g_a2vid_palette; - -extern int g_installed_full_superhires_colormap; - -extern int g_screen_redraw_skip_amt; - -extern word32 g_a2_screen_buffer_changed; - -HWND g_hwnd_main; -BITMAPINFO *g_bmapinfo_ptr = 0; -volatile BITMAPINFOHEADER *g_bmaphdr_ptr = 0; - -int g_num_a2_keycodes = 0; - -extern char *g_status_ptrs[MAX_STATUS_LINES]; - -int g_win_button_states = 0; - -// OG Added calc_ratio -int x_calc_ratio(float& ratiox,float& ratioy); - -/* this table is used to search for the Windows VK_* in col 1 or 2 */ -/* flags bit 8 is or'ed into the VK, so we can distinguish keypad keys */ -/* regardless of numlock */ -int g_a2_key_to_wsym[][3] = { - { 0x35, VK_ESCAPE, 0 }, - { 0x7a, VK_F1, 0 }, - { 0x78, VK_F2, 0 }, // OG Was 7B but F2 is defined has 0x78 in a2_key_to_ascii - { 0x63, VK_F3, 0 }, - { 0x76, VK_F4, 0 }, - { 0x60, VK_F5, 0 }, - { 0x61, VK_F6, 0 }, - { 0x62, VK_F7, 0 }, - { 0x64, VK_F8, 0 }, - { 0x65, VK_F9, 0 }, - { 0x6d, VK_F10, 0 }, - { 0x67, VK_F11, 0 }, - { 0x6f, VK_F12, 0 }, - { 0x69, VK_F13, 0 }, - { 0x6b, VK_F14, 0 }, - { 0x71, VK_F15, 0 }, - { 0x7f, VK_PAUSE, VK_CANCEL+0x100 }, - - { 0x32, 0xc0, 0 }, /* '`' */ - { 0x12, '1', 0 }, - { 0x13, '2', 0 }, - { 0x14, '3', 0 }, - { 0x15, '4', 0 }, - { 0x17, '5', 0 }, - { 0x16, '6', 0 }, - { 0x1a, '7', 0 }, - { 0x1c, '8', 0 }, - { 0x19, '9', 0 }, - { 0x1d, '0', 0 }, - { 0x1b, 0xbd, 0 }, /* '-' */ - { 0x18, 0xbb, 0 }, /* '=' */ - { 0x33, VK_BACK, 0 }, /* backspace */ - { 0x72, VK_INSERT+0x100, 0 }, /* Insert key */ -/* { 0x73, XK_Home, 0 }, alias VK_HOME to be KP_Equal! */ - { 0x74, VK_PRIOR+0x100, 0 }, /* pageup */ - { 0x47, VK_NUMLOCK, VK_NUMLOCK+0x100 }, /* clear */ - { 0x51, VK_HOME+0x100, 0 }, /* KP_equal is HOME key */ - { 0x4b, VK_DIVIDE, VK_DIVIDE+0x100 }, - { 0x43, VK_MULTIPLY, VK_MULTIPLY+0x100 }, - - { 0x30, VK_TAB, 0 }, - { 0x0c, 'Q', 0 }, - { 0x0d, 'W', 0 }, - { 0x0e, 'E', 0 }, - { 0x0f, 'R', 0 }, - { 0x11, 'T', 0 }, - { 0x10, 'Y', 0 }, - { 0x20, 'U', 0 }, - { 0x22, 'I', 0 }, - { 0x1f, 'O', 0 }, - { 0x23, 'P', 0 }, - { 0x21, 0xdb, 0 }, /* [ */ - { 0x1e, 0xdd, 0 }, /* ] */ - { 0x2a, 0xdc, 0 }, /* backslash, bar */ - { 0x75, VK_DELETE+0x100, 0 }, - { 0x77, VK_END+0x100, VK_END }, - { 0x79, VK_NEXT+0x100, 0 }, - { 0x59, VK_NUMPAD7, VK_HOME }, - { 0x5b, VK_NUMPAD8, VK_UP }, - { 0x5c, VK_NUMPAD9, VK_PRIOR }, - { 0x4e, VK_SUBTRACT, VK_SUBTRACT+0x100 }, - - // { 0x39, VK_CAPITAL, 0 }, // Handled specially! - { 0x00, 'A', 0 }, - { 0x01, 'S', 0 }, - { 0x02, 'D', 0 }, - { 0x03, 'F', 0 }, - { 0x05, 'G', 0 }, - { 0x04, 'H', 0 }, - { 0x26, 'J', 0 }, - { 0x28, 'K', 0 }, - { 0x25, 'L', 0 }, - { 0x29, 0xba, 0 }, /* ; */ - { 0x27, 0xde, 0 }, /* single quote */ - { 0x24, VK_RETURN, 0 }, - { 0x56, VK_NUMPAD4, VK_LEFT }, - { 0x57, VK_NUMPAD5, VK_CLEAR }, - { 0x58, VK_NUMPAD6, VK_RIGHT }, - { 0x45, VK_ADD, 0 }, - - { 0x38, VK_SHIFT, 0 }, - { 0x06, 'Z', 0 }, - { 0x07, 'X', 0 }, - { 0x08, 'C', 0 }, - { 0x09, 'V', 0 }, - { 0x0b, 'B', 0 }, - { 0x2d, 'N', 0 }, - { 0x2e, 'M', 0 }, - { 0x2b, 0xbc, 0 }, /* , */ - { 0x2f, 0xbe, 0 }, /* . */ - { 0x2c, 0xbf, 0 }, /* / */ - { 0x3e, VK_UP+0x100, 0 }, - { 0x53, VK_NUMPAD1, VK_END }, - { 0x54, VK_NUMPAD2, VK_DOWN }, - { 0x55, VK_NUMPAD3, VK_NEXT }, - - { 0x36, VK_CONTROL, VK_CONTROL+0x100 }, - { 0x3a, VK_SNAPSHOT+0x100, VK_MENU+0x100 },/* Opt=prntscrn or alt-r */ - -// OG ActiveGS map OA-CA to Win & AltKey -#ifndef ACTIVEGS - { 0x37, VK_SCROLL, VK_MENU }, /* Command=scr_lock or alt-l */ -#else - { 0x7f, VK_CANCEL, 0 }, - { 0x3A, VK_LWIN+0x100, VK_LWIN }, - { 0x37, VK_MENU, 0 }, /* Command=alt-l */ - { 0x37, VK_LMENU, 0 }, /* Command=alt-l */ - { 0x7F, VK_SCROLL,0 }, /* RESET */ - { 0x36, VK_LCONTROL, 0 }, // CTRL -#endif - - { 0x31, ' ', 0 }, - { 0x3b, VK_LEFT+0x100, 0 }, - { 0x3d, VK_DOWN+0x100, 0 }, - { 0x3c, VK_RIGHT+0x100, 0 }, - { 0x52, VK_NUMPAD0, VK_INSERT }, - { 0x41, VK_DECIMAL, VK_DECIMAL }, - { 0x4c, VK_RETURN+0x100, 0 }, - { -1, -1, -1 } -}; - -extern int g_config_control_panel; - -int -win_update_mouse(int x, int y, int button_states, int buttons_valid) -{ - int buttons_changed; - -#ifdef ACTIVEGS - if (g_config_control_panel) // OG ignore input events while in debugger - return 0; - - buttons_valid &= 1; // filter out middle & right button - -#endif - - buttons_changed = ((g_win_button_states & buttons_valid) != - button_states); - g_win_button_states = (g_win_button_states & ~buttons_valid) | - (button_states & buttons_valid); - if(g_warp_pointer && (x == A2_WINDOW_WIDTH/2) && - (y == A2_WINDOW_HEIGHT/2) && (!buttons_changed) ) { - /* tell adb routs to recenter but ignore this motion */ - update_mouse(x, y, 0, -1); - return 0; - } - return update_mouse(x, y, button_states, buttons_valid & 7); -} - - -// OG Added asynchronous key & mouse handler -#define ASYNCEVENT - -#ifndef ASYNCEVENT -#define WIN_EVENT_MOUSE win_event_mouse -#define WIN_EVENT_KEY win_event_key -#else -extern void add_event_mouse(int umsg,WPARAM wParam, LPARAM lParam); -extern void add_event_key(HWND hwnd, UINT raw_vk, BOOL down, int repeat, UINT flags); -#define WIN_EVENT_MOUSE add_event_mouse -#define WIN_EVENT_KEY add_event_key -#endif - -struct win32_mouse -{ - int umsg; - int wparam; - int lparam; -}; - -struct win32_key -{ - UINT raw_vk; - BOOL down; - int repeat; - UINT flags; -}; - -int last_win32_mouse=0; -int next_win32_mouse=0; - -int nb_win32_key=0; - -#define MAX_EVENT 1024 -struct win32_mouse win32_mouses[MAX_EVENT]; -struct win32_key win32_keys[MAX_EVENT]; - -extern int g_config_control_panel; // OG Expose g_config_control_panel - -// OG Push Mouse Event - -void add_event_mouse(int umsg,WPARAM wParam, LPARAM lParam) -{ - -#ifdef ACTIVEGS - if (g_config_control_panel) // OG ignore input events while in debugger - return ; -#endif - - win32_mouses[next_win32_mouse].umsg = umsg; - win32_mouses[next_win32_mouse].wparam = wParam; - win32_mouses[next_win32_mouse].lparam = lParam; - next_win32_mouse = (next_win32_mouse+1)%MAX_EVENT; - -// ASSERT (next_win32_mouse==last_win32_mouse) -} - -// OG Push Key Event - -void -add_event_key(HWND hwnd, UINT raw_vk, BOOL down, int repeat, UINT flags) -{ - -#ifdef ACTIVEGS - if (g_config_control_panel) // OG ignore input events while in debugger - return ; -#endif - - if (nb_win32_key>=MAX_EVENT) - return ; - - win32_keys[nb_win32_key].raw_vk = raw_vk; - win32_keys[nb_win32_key].down = down; - win32_keys[nb_win32_key].repeat = repeat; - win32_keys[nb_win32_key].flags = flags; - - nb_win32_key++; - -} - - -void -win_event_mouse(int umsg, WPARAM wParam, LPARAM lParam) -{ - POINT pt; - word32 flags; - int buttons; - int x, y; - int motion; - - x = LOWORD(lParam); - y = HIWORD(lParam); - - - // OG Reformat the mouse coordinates - float ratiox,ratioy; - if (!g_warp_pointer && x_calc_ratio(ratiox,ratioy)) - { - x = (int)((float)(x)/ratiox); - y = (int)((float)(y)/ratioy); - } - - flags = wParam; - x -= BASE_MARGIN_LEFT; - y -= BASE_MARGIN_TOP; - - buttons = (flags & 1) + - (((flags >> 1) & 1) << 2) + - (((flags >> 4) & 1) << 1); -#if 0 - if (umsg!=WM_MOUSEMOVE) - printf("Mouse at %d, %d fl: %08x, but: %d\n", x, y, flags, buttons); -#endif - motion = win_update_mouse(x, y, buttons, 7); - - if(motion && g_warp_pointer) { - /* move mouse to center of screen */ - pt.x = BASE_MARGIN_LEFT + A2_WINDOW_WIDTH/2; - pt.y = BASE_MARGIN_TOP + A2_WINDOW_HEIGHT/2; - ClientToScreen(g_hwnd_main, &pt); - SetCursorPos(pt.x, pt.y); - } -} - -void -win_event_key(HWND hwnd, UINT raw_vk, BOOL down, int repeat, UINT flags) -{ - word32 vk; - int a2code; - int is_up; - int capslock_down; - int i; - - if((flags & 0x4000) && down) { - /* auto-repeating, just ignore it */ - return; - } - - vk = raw_vk + (flags & 0x100); -#if 0 - printf("Key event, vk=%04x, down:%d, repeat: %d, flags: %08x\n", - vk, down, repeat, flags); -#endif - - /* remap a few keys here.. sigh */ - if((vk & 0xff) == VK_APPS) { - /* remap to command */ - vk = VK_MENU; - } - - if((vk & 0xff) == VK_CAPITAL) { - // Windows gives us up-and-down events of the actual key - // Use GetKeyState to get the true toggle state, and pass - // that on to the adb interface - capslock_down = GetKeyState(VK_CAPITAL) & 0x01; - if(capslock_down != g_win_capslock_down) { - g_win_capslock_down = capslock_down; - adb_physical_key_update(0x39, !capslock_down); - } - - return; // Do no more processing! - } - - /* search a2key_to_wsym to find wsym in col 1 or 2 */ - i = 0; - is_up = !down; - for(i = g_num_a2_keycodes-1; i >= 0; i--) { - a2code = g_a2_key_to_wsym[i][0]; - if((vk == g_a2_key_to_wsym[i][1]) || - (vk == g_a2_key_to_wsym[i][2])) { - vid_printf("Found vk:%04x = %02x\n", vk, a2code); - adb_physical_key_update(a2code, is_up); - return; - } - } - printf("VK: %04x unknown\n", vk); -} - -void -win_event_quit(HWND hwnd) -{ - quitEmulator(); -} - -extern int g_needfullrefreshfornextframe ; - -void -win_event_redraw() -{ -// outputInfo("win_event_redraw()\n"); - g_needfullrefreshfornextframe = 1; -} - -LRESULT CALLBACK -win_event_handler(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) -{ -int i; -int numDraggedFiles; -int szFilename; -LPTSTR lpszFile; - - switch(umsg) { - case WM_MOUSEMOVE: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - win_event_mouse(umsg, wParam, lParam); - return 0; - case WM_PAINT: - win_event_redraw(); - break; - case WM_DROPFILES: - numDraggedFiles = DragQueryFile((HDROP)wParam, 0xFFFFFFFF, NULL, 0); - for (i = 0; i < numDraggedFiles; i++) { - szFilename = DragQueryFile((HDROP)wParam, i, NULL, 0); - lpszFile = malloc(szFilename + 1); - szFilename = DragQueryFile((HDROP)wParam, i, lpszFile, szFilename + 1); - cfg_inspect_maybe_insert_file(lpszFile); - free(lpszFile); - } - DragFinish((HDROP)wParam); - break; - } - switch(umsg) { - HANDLE_MSG(hwnd, WM_KEYUP, win_event_key); - HANDLE_MSG(hwnd, WM_KEYDOWN, win_event_key); - HANDLE_MSG(hwnd, WM_SYSKEYUP, win_event_key); - HANDLE_MSG(hwnd, WM_SYSKEYDOWN, win_event_key); - HANDLE_MSG(hwnd, WM_DESTROY, win_event_quit); - } - -#if 0 - switch(umsg) { - case WM_NCACTIVATE: - case WM_NCHITTEST: - case WM_NCMOUSEMOVE: - case WM_SETCURSOR: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - case WM_CONTEXTMENU: - case WM_RBUTTONUP: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_PAINT: - - break; - default: - printf("Got umsg2: %d\n", umsg); - } -#endif - - return DefWindowProc(hwnd, umsg, wParam, lParam); -} - - -int -main(int argc, char **argv) -{ - WNDCLASS wndclass; - RECT rect; - int height; - - InitCommonControls(); - - wndclass.style = 0; - wndclass.lpfnWndProc = (WNDPROC)win_event_handler; - wndclass.cbClsExtra = 0; - wndclass.cbWndExtra = 0; - wndclass.hInstance = GetModuleHandle(NULL); - wndclass.hIcon = LoadIcon((HINSTANCE)NULL, IDI_APPLICATION); - wndclass.hCursor = LoadCursor((HINSTANCE) NULL, IDC_ARROW); - wndclass.hbrBackground = GetStockObject(WHITE_BRUSH); - wndclass.lpszMenuName = NULL; - wndclass.lpszClassName = "gsport"; - - // Register the window - if(!RegisterClass(&wndclass)) { - printf("Registering window failed\n"); - exit(1); - } - - height = X_A2_WINDOW_HEIGHT + (MAX_STATUS_LINES * 16) + 32; - g_main_height = height; - - g_hwnd_main = CreateWindowEx(WS_EX_ACCEPTFILES, "gsport", "GSport - Apple //gs Emulator", - WS_TILED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, - CW_USEDEFAULT, CW_USEDEFAULT, - X_A2_WINDOW_WIDTH, height, - NULL, NULL, GetModuleHandle(NULL), NULL); - - printf("g_hwnd_main = %p, height = %d\n", g_hwnd_main, height); - GetWindowRect(g_hwnd_main, &rect); - printf("...rect is: %ld, %ld, %ld, %ld\n", rect.left, rect.top, - rect.right, rect.bottom); - - g_main_dc = GetDC(g_hwnd_main); - - SetTextColor(g_main_dc, 0); - SetBkColor(g_main_dc, 0xffffff); - - g_main_cdc = CreateCompatibleDC(g_main_dc); - - g_screen_depth = 24; - g_screen_mdepth = 32; - - - // Call gsportmain - return gsportmain(argc, argv); -} - - -void -check_input_events() -{ - MSG msg; - - while(PeekMessage(&msg, g_hwnd_main, 0, 0, PM_NOREMOVE)) { - if(GetMessage(&msg, g_hwnd_main, 0, 0) > 0) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } else { - printf("GetMessage returned <= 0\n"); - my_exit(2); - } - } - - return; -} - - -void -x_update_color(int col_num, int red, int green, int blue, word32 rgb) -{ -} - -void -x_update_physical_colormap() -{ -} - -void -show_xcolor_array() -{ - int i; - - for(i = 0; i < 256; i++) { - printf("%02x: %08x\n", i, g_palette_8to1624[i]); - } -} - - -// OG Add function to clear all get_images loaded (dev dependent) -void x_release_kimage(Kimage *kimage_ptr) -{ - if ((int)kimage_ptr->dev_handle != -1) - { - DeleteObject(kimage_ptr->dev_handle); - kimage_ptr->dev_handle = (void*)-1; - } - else - if (kimage_ptr->data_ptr) - { - free(kimage_ptr->data_ptr); - kimage_ptr->data_ptr = NULL; - } -} - -// OG Free video global memory -void -xdriver_end() // Should be renamed to dev_video_shut() ??? -{ - - x_release_kimage(&g_mainwin_kimage); - - GlobalFree(g_bmapinfo_ptr); // allocated in dev_video_init - g_bmapinfo_ptr = 0; - - printf("win32 video driver end\n"); -} - - -void -x_get_kimage(Kimage *kimage_ptr) -{ - byte *ptr; - int width; - int height; - int depth, mdepth; - int size; - - width = kimage_ptr->width_req; - height = kimage_ptr->height; - depth = kimage_ptr->depth; - mdepth = kimage_ptr->mdepth; - - size = 0; - if(depth == g_screen_depth) { - /* Use g_bmapinfo_ptr, adjusting width, height */ - g_bmaphdr_ptr->biWidth = width; - g_bmaphdr_ptr->biHeight = -height; - kimage_ptr->dev_handle = CreateDIBSection(g_main_dc, - g_bmapinfo_ptr, DIB_RGB_COLORS, - (VOID **)&(kimage_ptr->data_ptr), NULL, 0); - } else { - /* allocate buffers for video.c to draw into */ - - size = (width*height*mdepth) >> 3; - ptr = (byte *)malloc(size); - - if(ptr == 0) { - printf("malloc for data failed, mdepth: %d\n", mdepth); - exit(2); - } - - kimage_ptr->data_ptr = ptr; - - kimage_ptr->dev_handle = (void *)-1; - - } - printf("kim: %p, dev:%p data: %p, size: %08x\n", kimage_ptr, - kimage_ptr->dev_handle, kimage_ptr->data_ptr, size); - - return; -} - - -void -dev_video_init() -{ - int extra_size; - int lores_col; - int a2code; - int i; - - printf("Preparing graphics system\n"); - - g_num_a2_keycodes = 0; - for(i = 0; i < 0x7f; i++) { - a2code = g_a2_key_to_wsym[i][0]; - if(a2code < 0) { - g_num_a2_keycodes = i; - } - } - - g_screen_depth = 24; - g_screen_mdepth = 32; - - extra_size = sizeof(RGBQUAD); - if(g_screen_depth == 8) { - extra_size = 256 * sizeof(RGBQUAD); - } - g_bmapinfo_ptr = (BITMAPINFO *)GlobalAlloc(GPTR, - sizeof(BITMAPINFOHEADER) + extra_size); - - g_bmaphdr_ptr = (BITMAPINFOHEADER *)g_bmapinfo_ptr; - g_bmaphdr_ptr->biSize = sizeof(BITMAPINFOHEADER); - g_bmaphdr_ptr->biWidth = A2_WINDOW_WIDTH; - g_bmaphdr_ptr->biHeight = -A2_WINDOW_HEIGHT; - g_bmaphdr_ptr->biPlanes = 1; - g_bmaphdr_ptr->biBitCount = g_screen_mdepth; - g_bmaphdr_ptr->biCompression = BI_RGB; - g_bmaphdr_ptr->biClrUsed = 0; - - video_get_kimages(); - - if(g_screen_depth != 8) { - // Allocate g_mainwin_kimage - video_get_kimage(&g_mainwin_kimage, 0, g_screen_depth, - g_screen_mdepth); - } - - for(i = 0; i < 256; i++) { - lores_col = g_lores_colors[i & 0xf]; - video_update_color_raw(i, lores_col); - g_a2palette_8to1624[i] = g_palette_8to1624[i]; - } - - g_installed_full_superhires_colormap = 1; - - ShowWindow(g_hwnd_main, SW_SHOWDEFAULT); - UpdateWindow(g_hwnd_main); - - printf("Done with dev_video_init\n"); - fflush(stdout); - -} - -void -x_redraw_status_lines() -{ - COLORREF oldtextcolor, oldbkcolor; - char *buf; - int line; - int len; - int height; - int margin; - - height = 16; - margin = 0; - - oldtextcolor = SetTextColor(g_main_dc, 0); - oldbkcolor = SetBkColor(g_main_dc, 0xffffff); - for(line = 0; line < MAX_STATUS_LINES; line++) { - buf = g_status_ptrs[line]; - if(buf != 0) { - len = strlen(buf); - TextOut(g_main_dc, 10, X_A2_WINDOW_HEIGHT + - height*line + margin, buf, len); - } - } - SetTextColor(g_main_dc, oldtextcolor); - SetBkColor(g_main_dc, oldbkcolor); -} - - -void -x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, - int width, int height) -{ - void *bitm_old; - POINT point; - - point.x = 0; - point.y = 0; - ClientToScreen(g_hwnd_main, &point); - bitm_old = SelectObject(g_main_cdc, kimage_ptr->dev_handle); - - BitBlt(g_main_dc, destx, desty, width, height, - g_main_cdc, srcx, srcy, SRCCOPY); - - SelectObject(g_main_cdc, bitm_old); -} - -void -x_push_done() -{ -} - -void -x_auto_repeat_on(int must) -{ -} - -void -x_auto_repeat_off(int must) -{ -} - -void -x_hide_pointer(int do_hide) -{ - if(do_hide) { - ShowCursor(0); - } else { - ShowCursor(1); - } -} - -void -x_full_screen(int do_full) -{ - return; -}