# HG changeset patch # User Michael Pavone # Date 1488788615 28800 # Node ID 3772bb926be55c77452a7342281d9a071cd1ae8e # Parent a4fa897c99ce83aea1b711aa16074b0f51ea21ca Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill diff -r a4fa897c99ce -r 3772bb926be5 default.cfg --- a/default.cfg Sat Mar 04 21:34:15 2017 -0800 +++ b/default.cfg Mon Mar 06 00:23:35 2017 -0800 @@ -147,6 +147,10 @@ #comment out those two lines and uncomment these #top 11 #bottom 8 + + #these values will completely hide the horizontal border + left 13 + right 14 } } pal { @@ -161,6 +165,10 @@ #coment out those two lines and uncomment these #top 30 #bottom 24 + + #these values will completely hide the horizontal border + left 13 + right 14 } } } diff -r a4fa897c99ce -r 3772bb926be5 render_sdl.c --- a/render_sdl.c Sat Mar 04 21:34:15 2017 -0800 +++ b/render_sdl.c Mon Mar 06 00:23:35 2017 -0800 @@ -256,7 +256,7 @@ #endif //TODO: Fixme for invalid display mode - sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 588); + sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, LINEBUF_SIZE, 588); #ifndef DISABLE_OPENGL } #endif @@ -324,6 +324,8 @@ static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; +static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; +static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; static vid_std video_standard = VID_NTSC; static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal"}; void render_init(int width, int height, char * title, uint8_t fullscreen) @@ -375,6 +377,14 @@ if (val) { overscan_bot[i] = atoi(val); } + val = tern_find_path_default(std_settings, "overscan\0left\0", (tern_val){.ptrval = NULL}).ptrval; + if (val) { + overscan_left[i] = atoi(val); + } + val = tern_find_path_default(std_settings, "overscan\0right\0", (tern_val){.ptrval = NULL}).ptrval; + if (val) { + overscan_right[i] = atoi(val); + } } } } @@ -504,7 +514,7 @@ { #ifndef DISABLE_OPENGL if (render_gl && which <= FRAMEBUFFER_EVEN) { - *pitch = 320 * sizeof(uint32_t); //TODO: change this to LINEBUF_SIZE once border rendering is added + *pitch = LINEBUF_SIZE * sizeof(uint32_t); return texture_buf; } else { #endif @@ -548,6 +558,7 @@ uint32_t height = which <= FRAMEBUFFER_EVEN ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) : 240; + width -= overscan_left[video_standard] + overscan_right[video_standard]; FILE *screenshot_file = NULL; uint32_t shot_height; if (screenshot_path && which == FRAMEBUFFER_ODD) { @@ -564,7 +575,7 @@ #ifndef DISABLE_OPENGL if (render_gl && which <= FRAMEBUFFER_EVEN) { glBindTexture(GL_TEXTURE_2D, textures[which]); - glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, height, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf + 320 * overscan_top[video_standard]); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); @@ -594,7 +605,7 @@ if (screenshot_file) { //properly supporting interlaced modes here is non-trivial, so only save the odd field for now - save_ppm(screenshot_file, texture_buf, width, shot_height, 320*sizeof(uint32_t)); + save_ppm(screenshot_file, texture_buf, width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); } } else { #endif @@ -625,7 +636,7 @@ } SDL_UnlockTexture(sdl_textures[which]); SDL_Rect src_clip = { - .x = 0, + .x = overscan_left[video_standard], .y = overscan_top[video_standard], .w = width, .h = height diff -r a4fa897c99ce -r 3772bb926be5 vdp.c --- a/vdp.c Sat Mar 04 21:34:15 2017 -0800 +++ b/vdp.c Mon Mar 06 00:23:35 2017 -0800 @@ -711,8 +711,8 @@ #define VSRAM_BITS 0x7FF #define VSRAM_DIRTY_BITS 0xF800 -//rough estimate of slot number at which active display starts -#define BG_START_SLOT 9 +//rough estimate of slot number at which border display starts +#define BG_START_SLOT 0 void write_cram(vdp_context * context, uint16_t address, uint16_t value) { @@ -733,7 +733,7 @@ context->vcounter < context->inactive_start + context->border_bot || context->vcounter > 0x200 - context->border_top )) { - uint8_t bg_end_slot = BG_START_SLOT + (context->regs[REG_MODE_4] & BIT_H40) ? 320/2 : 256/2; + uint8_t bg_end_slot = BG_START_SLOT + (context->regs[REG_MODE_4] & BIT_H40) ? LINEBUF_SIZE/2 : (256+HORIZ_BORDER)/2; if (context->hslot < bg_end_slot) { uint32_t color = (context->regs[REG_MODE_2] & BIT_MODE_5) ? context->colors[addr] : context->colors[addr + CRAM_SIZE*3]; context->output[(context->hslot - BG_START_SLOT)*2 + 1] = color; @@ -1204,7 +1204,7 @@ if (col) { col-=2; - dst = context->output + col * 8; + dst = context->output + BORDER_LEFT + col * 8; if (context->debug < 2) { sprite_buf = context->linebuf + col * 8; uint8_t a_src, src; @@ -1486,7 +1486,7 @@ context->vcounter &= 0x1FF; } else { if (context->vcounter == context->inactive_start) { - render_framebuffer_updated(context->flags2 & FLAG2_EVEN_FIELD ? FRAMEBUFFER_EVEN: FRAMEBUFFER_ODD, context->h40_lines > (context->inactive_start + context->border_top) / 2 ? 320 : 256); + render_framebuffer_updated(context->flags2 & FLAG2_EVEN_FIELD ? FRAMEBUFFER_EVEN: FRAMEBUFFER_ODD, context->h40_lines > (context->inactive_start + context->border_top) / 2 ? LINEBUF_SIZE : (256+HORIZ_BORDER)); if (context->double_res) { context->flags2 ^= FLAG2_EVEN_FIELD; } @@ -1528,6 +1528,12 @@ read_map_scroll_a(column, context->vcounter, context);\ CHECK_LIMIT\ case ((startcyc+1)&0xFF):\ + if (column == 2) {\ + uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F];\ + for (int i = 0; i < BORDER_LEFT; i++) {\ + context->output[i] = bg_color;\ + }\ + }\ external_slot(context);\ CHECK_LIMIT\ case ((startcyc+2)&0xFF):\ @@ -1838,9 +1844,15 @@ case 161: external_slot(context); CHECK_LIMIT - case 162: + case 162: { external_slot(context); + uint32_t bg_color = context->colors[context->regs[REG_BG_COLOR] & 0x3F]; + for (int i = LINEBUF_SIZE-BORDER_RIGHT; i < LINEBUF_SIZE; i++) + { + context->output[i] = bg_color; + } CHECK_LIMIT + } //sprite render to line buffer starts case 163: context->cur_slot = MAX_DRAWS-1; @@ -2199,7 +2211,7 @@ if (is_h40) { buf_clear_slot = 161; index_reset_slot = 165; - bg_end_slot = BG_START_SLOT + 320/2; + bg_end_slot = BG_START_SLOT + LINEBUF_SIZE/2; max_draws = MAX_DRAWS-1; max_sprites = MAX_SPRITES_LINE; index_reset_value = 0x80; @@ -2208,7 +2220,7 @@ jump_start = 182; jump_dest = 229; } else { - bg_end_slot = BG_START_SLOT + 256/2; + bg_end_slot = BG_START_SLOT + (256+HORIZ_BORDER)/2; max_draws = MAX_DRAWS_H32-1; max_sprites = MAX_SPRITES_LINE_H32; buf_clear_slot = 128; @@ -2222,7 +2234,7 @@ vint_line = context->inactive_start; active_line = 0x1FF; } else { - bg_end_slot = BG_START_SLOT + 256/2; + bg_end_slot = BG_START_SLOT + (256+HORIZ_BORDER)/2; max_draws = MAX_DRAWS_H32_MODE4; buf_clear_slot = 136; index_reset_slot = 253; @@ -2277,6 +2289,9 @@ } *(dst++) = bg_color; *(dst++) = bg_color; + if (context->hslot == (bg_end_slot-1)) { + *(dst++) = bg_color; + } } if (!is_refresh(context, context->hslot)) { diff -r a4fa897c99ce -r 3772bb926be5 vdp.h --- a/vdp.h Sat Mar 04 21:34:15 2017 -0800 +++ b/vdp.h Mon Mar 06 00:23:35 2017 -0800 @@ -14,7 +14,10 @@ #define CRAM_SIZE 64 #define VSRAM_SIZE 40 #define VRAM_SIZE (64*1024) -#define LINEBUF_SIZE (320+27) //H40 + full border +#define BORDER_LEFT 13 +#define BORDER_RIGHT 14 +#define HORIZ_BORDER (BORDER_LEFT+BORDER_RIGHT) +#define LINEBUF_SIZE (320+HORIZ_BORDER) //H40 + full border #define BORDER_BOTTOM 13 //TODO: Replace with actual value #define MAX_DRAWS 40 #define MAX_DRAWS_H32 32