Skip to content

Commit

Permalink
Add apple IIGS line length compensation and change FBsize values for …
Browse files Browse the repository at this point in the history
…clarity
  • Loading branch information
IanSB committed Jun 12, 2021
1 parent 7468549 commit 25bbc35
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/defs.h
Expand Up @@ -194,7 +194,7 @@ typedef struct {

typedef struct {
int clock; // sample clock frequency (Hz)
int line_len; // length of a line (in sample clocks)
double line_len; // length of a line (in sample clocks)
int clock_ppm; // sample clock frequency (Hz)
int lines_per_frame;
} clk_info_t;
Expand Down
28 changes: 16 additions & 12 deletions src/geometry.c
Expand Up @@ -131,7 +131,7 @@ void geometry_init(int version) {
mode7_geometry.max_v_height = 270 & 0xfffffffe;
mode7_geometry.h_aspect = 3;
mode7_geometry.v_aspect = 4;
mode7_geometry.fb_sizex2 = 1;
mode7_geometry.fb_sizex2 = SIZEX2_DOUBLE_HEIGHT;
mode7_geometry.fb_bpp = 0;
mode7_geometry.clock = 12000000;
mode7_geometry.line_len = 12 * 64;
Expand All @@ -150,7 +150,7 @@ void geometry_init(int version) {
default_geometry.max_v_height= 270 & 0xfffffffe;
default_geometry.h_aspect = 1;
default_geometry.v_aspect = 2;
default_geometry.fb_sizex2 = 1;
default_geometry.fb_sizex2 = SIZEX2_DOUBLE_HEIGHT;
default_geometry.fb_bpp = 1;
default_geometry.clock = 16000000;
default_geometry.line_len = 16 * 64;
Expand Down Expand Up @@ -446,18 +446,18 @@ void geometry_get_fb_params(capture_info_t *capinfo) {

#ifdef INHIBIT_DOUBLE_HEIGHT
if (capinfo->video_type == VIDEO_PROGRESSIVE) {
capinfo->sizex2 &= 2;
capinfo->sizex2 &= SIZEX2_DOUBLE_WIDTH;
}
#endif

if ((capinfo->detected_sync_type & SYNC_BIT_INTERLACED) && capinfo->video_type != VIDEO_PROGRESSIVE) {
capinfo->sizex2 |= 1;
capinfo->sizex2 |= SIZEX2_DOUBLE_HEIGHT;
} else {
if (get_scanlines() && !(menu_active() || osd_active())) {
if ((capinfo->sizex2 & 1) == 0) {
capinfo->sizex2 |= 4; //flag basic scanlines
if ((capinfo->sizex2 & SIZEX2_DOUBLE_HEIGHT) == 0) {
capinfo->sizex2 |= SIZEX2_BASIC_SCANLINES; //flag basic scanlines
}
capinfo->sizex2 |= 1; // force double height
capinfo->sizex2 |= SIZEX2_DOUBLE_HEIGHT; // force double height
}
}

Expand Down Expand Up @@ -569,16 +569,16 @@ void geometry_get_fb_params(capture_info_t *capinfo) {
//}
}

int double_width = (capinfo->sizex2 & 2) >> 1;
int double_height = capinfo->sizex2 & 1;
int double_width = (capinfo->sizex2 & SIZEX2_DOUBLE_WIDTH) >> 1;
int double_height = capinfo->sizex2 & SIZEX2_DOUBLE_HEIGHT;
if ((geometry_min_h_width << double_width) > h_size43) {
double_width = 0;
}
if ((geometry_min_v_height << double_height) > v_size43) {
double_height = 0;
}
if (double_height && (capinfo->sizex2 & 4)) {
capinfo->sizex2 = double_height | (double_width << 1) | 4;
if (double_height && (capinfo->sizex2 & SIZEX2_BASIC_SCANLINES)) {
capinfo->sizex2 = double_height | (double_width << 1) | SIZEX2_BASIC_SCANLINES;
} else {
capinfo->sizex2 = double_height | (double_width << 1);
}
Expand Down Expand Up @@ -930,7 +930,11 @@ int get_vdisplay() {

void geometry_get_clk_params(clk_info_t *clkinfo) {
clkinfo->clock = geometry->clock;
clkinfo->line_len = geometry->line_len;
clkinfo->line_len = (double) geometry->line_len;
// workaround for 16.363Mhz Apple II GS pixel clock
if (clkinfo->clock > 16250000 && clkinfo->clock < 16370000 && clkinfo->line_len == 1042) {
clkinfo->line_len = 1042.285714285f;
}
clkinfo->lines_per_frame = geometry->lines_per_frame;
if (geometry->setup_mode == SETUP_NORMAL) {
clkinfo->clock_ppm = geometry->clock_ppm;
Expand Down
8 changes: 4 additions & 4 deletions src/rgb_to_hdmi.c
Expand Up @@ -805,7 +805,7 @@ int calibrate_sampling_clock(int profile_changed) {

// Default values for the Beeb
clkinfo.clock = 16000000;
clkinfo.line_len = 1024;
clkinfo.line_len = 1024.0f;

//log_plla();
//log_pllb();
Expand All @@ -816,11 +816,11 @@ int calibrate_sampling_clock(int profile_changed) {
geometry_get_clk_params(&clkinfo);

log_info(" clkinfo.clock = %d Hz", clkinfo.clock);
log_info(" clkinfo.line_len = %d", clkinfo.line_len);
log_info(" clkinfo.line_len = %f", clkinfo.line_len);
log_info(" clkinfo.clock_ppm = %d ppm", clkinfo.clock_ppm);

int nlines = MEASURE_NLINES; // Measure over N=100 lines
nlines_ref_ns = nlines * (int) (1e9 * ((double) clkinfo.line_len) / ((double) clkinfo.clock));
nlines_ref_ns = nlines * (int) (1e9 * clkinfo.line_len / ((double) clkinfo.clock));

hsync_threshold = OTHER_HSYNC_THRESHOLD * cpuspeed / 1000; // set to longest value for initial measurement which works with all systems
nlines_time_ns = (int)((double) measure_n_lines(nlines) * 1000 / cpuspeed);
Expand Down Expand Up @@ -2918,7 +2918,7 @@ void setup_profile(int profile_changed) {
geometry_get_fb_params(capinfo);

if (autoswitch == AUTOSWITCH_PC && sub_profiles_available(profile)) { // set window around expected time from sub-profile
double line_time = (double) clkinfo.line_len * 1000000000 / (double) clkinfo.clock;
double line_time = clkinfo.line_len * 1000000000 / (double) clkinfo.clock;
int window = (int) ((double) clkinfo.clock_ppm * line_time / 1000000);
hsync_comparison_lo = (line_time - window) * cpuspeed / 1000;
hsync_comparison_hi = (line_time + window) * cpuspeed / 1000;
Expand Down

0 comments on commit 25bbc35

Please sign in to comment.