scanline simulator is back. yay.

This commit is contained in:
Dagen Brock 2017-01-21 16:31:32 -06:00
parent 9906f0187e
commit 0ff8dc524c
2 changed files with 509 additions and 475 deletions

View File

@ -51,6 +51,7 @@ int g_win_status_debug_request = 0; // Desired visibility of status lines.
int g_screen_mdepth = 0;
int kb_shift_control_state = 0;
void x_take_screenshot(); // screenshot stuff
int g_screenshot_requested = 0; // DB to know if we want to save a screenshot
extern char g_config_gsplus_name[];
@ -58,6 +59,7 @@ extern char g_config_gsplus_screenshot_dir[];
int screenshot_index = 0; // allows us to save time by not scanning from 0 each time
char screenshot_filename[256];
extern int g_scanline_simulator;
extern int g_screen_depth;
extern int g_quit_sim_now;
extern int g_border_sides_refresh_needed;
@ -77,6 +79,11 @@ extern const char g_gsplus_version_str[]; // version string for title bar
SDL_Window *window; // Declare a pointer
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Texture *overlay_texture; // This is used for scanline simulation. Could be more in future (HUD).
Uint32 *overlay_pixels;
static char *g_clipboard = NULL; // clipboard variables
static size_t g_clipboard_pos = 0;
void dev_video_init_sdl();
void handle_sdl_key_event(SDL_Event event);
@ -117,7 +124,7 @@ int a2_key_to_sdlkeycode[][3] = {
{ 0x18, '=', '+' },
{ 0x33, SDLK_BACKSPACE, 0 },
{ 0x72, SDLK_INSERT, 0 }, /* Help? XK_Help */
/* { 0x73, XK_Home, 0 }, alias XK_Home to be XK_KP_Equal! */
/* { 0x73, XK_Home, 0 }, alias XK_Home to be XK_KP_Equal! */
{ 0x74, SDLK_PAGEUP, 0 },
{ 0x47, SDLK_NUMLOCKCLEAR, 0 }, /* Clear, XK_Clear */
{ 0x51, SDLK_KP_EQUALS, 0 }, /* Note XK_Home alias! XK_Home */
@ -190,14 +197,15 @@ int a2_key_to_sdlkeycode[][3] = {
};
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
return gsplusmain(argc, argv);
}
const char *byte_to_binary(int x)
{
const char *byte_to_binary(int x) {
static char b[9];
b[0] = '\0';
@ -210,21 +218,20 @@ const char *byte_to_binary(int x)
return b;
}
/// Queries the Screen to see if it's set to Fullscreen or Not
/// @return SDL_FALSE if windowed, SDL_TRUE if fullscreen
SDL_bool IsFullScreen(SDL_Window *win)
{
// Queries the Screen to see if set to Fullscreen or Not
// @return SDL_FALSE when windowed, SDL_TRUE when fullscreen
SDL_bool IsFullScreen(SDL_Window *win) {
Uint32 flags = SDL_GetWindowFlags(win);
if (flags & SDL_WINDOW_FULLSCREEN) return SDL_TRUE; // return SDL_TRUE if fullscreen
if (flags & SDL_WINDOW_FULLSCREEN) {
return SDL_TRUE; // return SDL_TRUE if fullscreen
}
return SDL_FALSE; // Return SDL_FALSE if windowed
}
void
dev_video_init()
{
void dev_video_init() {
word32 lores_col;
// build keycode map ??
@ -262,9 +269,8 @@ dev_video_init()
}
void do_icon() {
#ifdef HAVE_ICON
#ifdef HAVE_ICON
//surface = SDL_CreateRGBSurfaceFrom(pixels,w,h,depth,pitch,rmask,gmask,bmask,amask);
int size = 256; // icon size
SDL_Surface *surface; // declare an SDL_Surface to be filled in with pixel data from an image file
@ -274,19 +280,16 @@ void do_icon() {
SDL_SetWindowIcon(window, surface);
// ...and the surface containing the icon pixel data is no longer required.
SDL_FreeSurface(surface);
#endif
#endif
}
// Initialize our SDL window and texture
void
dev_video_init_sdl()
{
void dev_video_init_sdl() {
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
// Create an application window with the following settings:
char window_title[50]; // @todo - unsafe assumption?
char window_title[32];
sprintf(window_title, "GSplus v%-6s", g_gsplus_version_str),
window = SDL_CreateWindow(
window_title, // window title (GSport vX.X)
@ -320,19 +323,47 @@ dev_video_init_sdl()
SDL_TEXTUREACCESS_STREAMING,
BASE_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT);
// The window is open: could enter program loop here (see SDL_PollEvent())
//overlay test
overlay_texture = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING,
BASE_WINDOW_WIDTH,
X_A2_WINDOW_HEIGHT);
SDL_SetTextureBlendMode(overlay_texture, SDL_BLENDMODE_BLEND);
overlay_pixels = malloc(BASE_WINDOW_WIDTH*X_A2_WINDOW_HEIGHT*sizeof(Uint32));
if (overlay_pixels) {
for (int y=0; y<X_A2_WINDOW_HEIGHT; y++) {
for (int x=0; x<BASE_WINDOW_WIDTH; x++) {
if (y%2 == 1) {
overlay_pixels[(y*BASE_WINDOW_WIDTH)+x] = 0x30000000;
printf("%d\n",(y*BASE_WINDOW_WIDTH)+x);
}
}
}
}
SDL_Rect dstrect;
dstrect.x = 0;
dstrect.y = 0;
dstrect.w = BASE_WINDOW_WIDTH;
dstrect.h = X_A2_WINDOW_HEIGHT;
int pitch = BASE_WINDOW_WIDTH;
// UPDATE A RECT OF THE APPLE II SCREEN TEXTURE
SDL_UpdateTexture(overlay_texture, &dstrect, overlay_pixels, pitch*sizeof(Uint32) );
SDL_ShowCursor(SDL_DISABLE);
}
// Copy a rect to our SDL window
void sdl_push_kimage(Kimage *kimage_ptr,
int destx, int desty, int srcx, int srcy, int width, int height)
{
void sdl_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, int width, int height) {
byte *src_ptr;
int pixel_size = 4;
src_ptr = kimage_ptr->data_ptr + (srcy * kimage_ptr->width_act + srcx) * pixel_size;
//src_ptr = kimage_ptr->data_ptr;
SDL_Rect dstrect;
dstrect.x = destx;
@ -342,22 +373,21 @@ void sdl_push_kimage(Kimage *kimage_ptr,
int pitch = 640;
if (width < 560) {
pitch = EFF_BORDER_WIDTH;
// This is another bad hack. Possibly not cross platform.
// seems to be the correct value, but would like clarification
pitch = BORDER_WIDTH+72;
//printf("EFF_BORDER_WIDTH : %d" ,EFF_BORDER_WIDTH);
}
//SDL_UpdateTexture(texture, NULL, src_ptr, 640 * sizeof (Uint32));
SDL_UpdateTexture(texture, &dstrect, src_ptr, pitch*4 );
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
if (g_scanline_simulator) {
SDL_RenderCopy(renderer, overlay_texture, NULL, NULL);
}
SDL_RenderPresent(renderer);
if (g_screenshot_requested) {
x_take_screenshot();
g_screenshot_requested = 0;
}
}
@ -371,8 +401,7 @@ void set_refresh_needed() {
}
void
x_get_kimage(Kimage *kimage_ptr) {
void x_get_kimage(Kimage *kimage_ptr) {
byte *data;
int width;
int height;
@ -387,16 +416,12 @@ x_get_kimage(Kimage *kimage_ptr) {
}
void
check_input_events()
{
void check_input_events() {
check_input_events_sdl();
}
void
check_input_events_sdl()
{
void check_input_events_sdl() {
int motion = 0;
SDL_Event event;
@ -430,7 +455,6 @@ check_input_events_sdl()
SDL_free(file);
}
break;
default:
break;
}
@ -438,9 +462,7 @@ check_input_events_sdl()
}
int
sdl_keysym_to_a2code(int keysym, int is_up)
{
int sdl_keysym_to_a2code(int keysym, int is_up) {
int i;
if(keysym == 0) {
@ -481,10 +503,7 @@ sdl_keysym_to_a2code(int keysym, int is_up)
}
void
handle_sdl_key_event(SDL_Event event)
{
void handle_sdl_key_event(SDL_Event event) {
int state_xor;
int state = 0;
int is_up;
@ -532,15 +551,29 @@ handle_sdl_key_event(SDL_Event event)
}
switch( event.key.keysym.sym ){
case SDLK_F11:
printf("Toggle Fullscreen");
if (kb_shift_control_state & ShiftMask) { // SHIFT+F11
if (!is_up) {
if (g_scanline_simulator) {
glog("Enable scanline simulator");
g_scanline_simulator = 0;
} else {
glog("Disable scanline simulator");
g_scanline_simulator = 1;
}
set_refresh_needed(); // make sure user sees it right away
}
} else {
if (!is_up) {
if (!IsFullScreen(window)) {
glog("Enable fullscreen");
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else {
glog("Disable fullscreen");
SDL_SetWindowFullscreen(window, 0);
SDL_SetWindowSize(window, BASE_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT);
}
}
}
break;
default:
a2code = sdl_keysym_to_a2code(event.key.keysym.sym, is_up);
@ -552,11 +585,9 @@ handle_sdl_key_event(SDL_Event event)
}
int
handle_sdl_mouse_motion_event(SDL_Event event) {
int handle_sdl_mouse_motion_event(SDL_Event event) {
int x, y;
// @todo: FIX MOUSE BUTTON MAPPING, AT LEAST CLEAN UP AND DOCUMENT BEHAVIOR
//printf (" %04x\t", event.motion.state &7);
x = event.motion.x - BASE_MARGIN_LEFT;
y = event.motion.y - BASE_MARGIN_TOP;
if (event.type == SDL_MOUSEBUTTONUP) {
@ -567,21 +598,18 @@ handle_sdl_mouse_motion_event(SDL_Event event) {
}
void
x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, int width, int height)
{
void x_push_kimage(Kimage *kimage_ptr, int destx, int desty, int srcx, int srcy, int width, int height) {
sdl_push_kimage(kimage_ptr, destx, desty, srcx, srcy, width, height);
}
// called by src/sim65816.c
void
x_dialog_create_gsport_conf(const char *str)
{
void x_dialog_create_gsport_conf(const char *str) {
// Just write the config file already...
config_write_config_gsplus_file();
}
void x_full_screen(int do_full) {
if (do_full) {
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
@ -591,18 +619,19 @@ void x_full_screen(int do_full) {
}
}
int file_exists(char *fname){
int file_exists(char *fname) {
if( access( fname, F_OK ) != -1 ) {
return 1; // file exists
} else {
return 0; // file doesn't exist
return 0; // file does not exist
}
}
// This tries to determine the next screenshot name.
// It uses the config name as the basename.
void make_next_screenshot_filename()
{
void make_next_screenshot_filename() {
char filepart[256];
char filename[256];
@ -629,6 +658,8 @@ void make_next_screenshot_filename()
strcpy(screenshot_filename, filename);
}
// @todo: some error with writing data direct to png. output is empty/transparent?
// workaround is this horrible hack of saving the bmp -> load bmp -> save png
void x_take_screenshot() {
@ -644,38 +675,16 @@ void x_take_screenshot() {
SDL_UnlockSurface(sshot);
SDL_FreeSurface(sshot);
SDL_Surface *s = SDL_CreateRGBSurface(0, BASE_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT,
32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
SDL_Surface *s = SDL_CreateRGBSurface(0, BASE_WINDOW_WIDTH, X_A2_WINDOW_HEIGHT, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
if (s) {
SDL_Surface * image = SDL_LoadBMP("screenshot.bmp");
IMG_SavePNG(image, screenshot_filename);
SDL_FreeSurface(image);
}
SDL_FreeSurface(s);
}
}
// Old driver cruft
// called by src/sim65816.c
int x_show_alert(int is_fatal, const char *str) { return 0; }
void get_ximage(Kimage *kimage_ptr) { }
void x_toggle_status_lines() { }
void x_redraw_status_lines() { }
void x_hide_pointer(int do_hide) { }
void x_auto_repeat_on(int must) { }
void x_auto_repeat_off(int must) { }
// OG Adding release
void x_release_kimage(Kimage* kimage_ptr) { }
// OG Addding ratio
int x_calc_ratio(float x,float y) { return 1; }
static char *g_clipboard = NULL;
static size_t g_clipboard_pos = 0;
void clipboard_paste(void) {
char *cp;
@ -695,6 +704,7 @@ void clipboard_paste(void) {
SDL_free(cp);
}
int clipboard_get_char(void) {
char c;
@ -723,6 +733,24 @@ int clipboard_get_char(void) {
return c | 0x80;
}
// BELOW ARE FUNCTIONS THAT ARE EITHER UNIMPLEMENTED, OR AR NOT RELEVANT TO
// THIS DRIVER.
// called by src/sim65816.c
int x_show_alert(int is_fatal, const char *str) { return 0; }
void get_ximage(Kimage *kimage_ptr) { }
void x_toggle_status_lines() { }
void x_redraw_status_lines() { }
void x_hide_pointer(int do_hide) { }
void x_auto_repeat_on(int must) { }
void x_auto_repeat_off(int must) { }
// OG Adding release
void x_release_kimage(Kimage* kimage_ptr) { }
// OG Addding ratio
int x_calc_ratio(float x,float y) { return 1; }
void x_set_mask_and_shift(word32 x_mask, word32 *mask_ptr, int *shift_left_ptr, int *shift_right_ptr) { return; }
void x_update_color(int col_num, int red, int green, int blue, word32 rgb) { }
void x_update_physical_colormap() { }

View File

@ -915,12 +915,14 @@ extern int g_use_shmem;
extern int g_use_dhr140;
extern int g_use_bw_hires;
/* display parameters */
char g_display_env[512];
int g_force_depth = -1;
int g_screen_depth = 8;
int g_scanline_simulator = 0;
void banner() {
printf("\x1b[32m _______ _______ _ \x1b[0m \n");
printf("\x1b[32m | ____|| _____| _| |_ \x1b[0m \n");
printf("\x1b[33m | | __ | |_____ |_ _| \x1b[0m \n");
@ -1042,6 +1044,10 @@ gsplusmain(int argc, char **argv)
printf("Forcing black-and-white hires modes\n");
g_cur_a2_stat |= ALL_STAT_COLOR_C021;
g_use_bw_hires = 1;
} else if(!strcmp("-scanline", argv[i])) {
g_scanline_simulator = 1;
} else if(!strcmp("-noscanline", argv[i])) {
g_scanline_simulator = 0;
} else if(!strcmp("-enet", argv[i])) {
if((i+1) >= argc) {
printf("Missing argument\n");