Commit faff5d05 authored by ROOL's avatar ROOL 🤖
Browse files

Take advantage of tail of generate functions being common

Detail:
  Now all generation steps end in compute_modedescription()/add_proposed_mode()/display_mode_parameters(), combine these steps into the add_proposed_mode() function.
  Fix for CVT and GTF generation steps never setting the 'priority' member of the descriptor. These are now set to 6 per Table 5.1 of EDID spec 1.4.
Admin:
  Submission for the EDID bounty.

Version 0.56. Tagged as 'ScrModes-0_56'
parent 11cf5235
/* (0.55)
/* (0.56)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.55
#define Module_MajorVersion_CMHG 0.56
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 30 Jul 2016
#define Module_MajorVersion "0.55"
#define Module_Version 55
#define Module_MajorVersion "0.56"
#define Module_Version 56
#define Module_MinorVersion ""
#define Module_Date "30 Jul 2016"
......@@ -18,6 +18,6 @@
#define Module_ComponentName "ScrModes"
#define Module_ComponentPath "castle/RiscOS/Sources/Video/UserI/ScrModes"
#define Module_FullVersion "0.55"
#define Module_HelpVersion "0.55 (30 Jul 2016)"
#define Module_LibraryVersionInfo "0:55"
#define Module_FullVersion "0.56"
#define Module_HelpVersion "0.56 (30 Jul 2016)"
#define Module_LibraryVersionInfo "0:56"
......@@ -45,15 +45,23 @@
/* By default we only use DMT timings; we will check for additional support later */
static int timing_support = EDID_USE_DMT;
/* Check if a new mode is present already.
* If it has, we won't be adding it to the chain.
* Return 1 if successful, and 0 if we have rejected it for any reason
/* Check if a new mode is present already, don't add it if it is.
* Return true if successful, and false if rejected for any reason.
*/
static int add_proposed_mode(MonitorDescriptionRef monitor_definition, ModeDescriptionRef proposed_mode)
static bool add_proposed_mode(MonitorDescriptionRef monitor_definition, ModeDescriptionRef proposed_mode, int32_t frame_hz, uint8_t priority)
{
compute_modedescription(proposed_mode);
if (frame_hz != -1)
{
proposed_mode->frame_hz = frame_hz; /* Override computed value */
}
proposed_mode->priority = priority;
proposed_mode->next = monitor_definition->modelist;
monitor_definition->modelist = proposed_mode;
return 1;
#if DODEBUG
display_mode_parameters(proposed_mode);
#endif
return true;
}
#if DODEBUG
......@@ -102,19 +110,10 @@ static _kernel_oserror *add_builtin_mode(MonitorDescriptionRef monitor, const Mo
}
mode_desc->definition = *mode;
compute_modedescription(mode_desc);
mode_desc->frame_hz = mode->freq; /* Override computed value */
mode_desc->priority = priority;
if (add_proposed_mode(monitor, mode_desc) == 0)
if (!add_proposed_mode(monitor, mode_desc, mode->freq, priority))
{
free(mode_desc);
return NULL;
}
#if DODEBUG
display_mode_parameters(mode_desc);
#endif
return NULL;
}
......@@ -140,15 +139,17 @@ static _kernel_oserror *generate_dmt_mode(char dmt, MonitorDescriptionRef monito
return 0;
}
static _kernel_oserror *Check_EDID_Checksum(EDIDBlockRef edidblock, bool checkall)
static _kernel_oserror *check_edid_checksum(EDIDBlockRef edidblock, bool checkall)
{
_kernel_oserror *res = NULL;
size_t byte, block, blocks_to_check = 0;
for (block = 0; block <= blocks_to_check; block++) {
for (block = 0; block <= blocks_to_check; block++)
{
uint8_t count = 0;
uint8_t *ediddata = (uint8_t *)&edidblock[block];
for (byte = 0; byte < sizeof(EDIDBlock); byte++) {
for (byte = 0; byte < sizeof(EDIDBlock); byte++)
{
count = count + ediddata[byte];
}
if (count != 0)
......@@ -355,15 +356,10 @@ static bool generate_mode_using_gtf(uint32_t h_pixels, uint32_t v_lines, uint32_
mode_desc->definition.interlaced = int_rqd ? 1 : 0;
sprintf(mode_desc->definition.name, "%d x %d", h_pixels, v_lines);
compute_modedescription(mode_desc);
if (add_proposed_mode(monitor, mode_desc) == 0)
if (!add_proposed_mode(monitor, mode_desc, ip_freq_rqd, 6))
{
return false;
}
#if DODEBUG
display_mode_parameters(mode_desc);
#endif
return true;
}
......@@ -561,15 +557,10 @@ static bool generate_mode_using_cvt_rb(uint32_t h_pixels, uint32_t v_lines, uint
mode_desc->definition.interlaced = int_rqd ? 1 : 0;
sprintf(mode_desc->definition.name, "%d x %d", h_pixels, v_lines);
compute_modedescription(mode_desc);
if (add_proposed_mode(monitor, mode_desc) == 0)
if (!add_proposed_mode(monitor, mode_desc, ip_freq_rqd, 6))
{
return false;
}
#if DODEBUG
display_mode_parameters(mode_desc);
#endif
return true;
}
......@@ -593,20 +584,13 @@ static _kernel_oserror *generate_standard_timing(char std1, char std2, MonitorDe
{
return error(ERR_NOSPACE, 0, 0, 0);
}
mode_desc->definition = display_monitor_timings[std_timings[i].dmt-1];
compute_modedescription(mode_desc);
mode_desc->frame_hz = display_monitor_timings[std_timings[i].dmt-1].freq;
mode_desc->priority = 5;
if (add_proposed_mode(monitor, mode_desc) == 0)
mode_desc->definition = display_monitor_timings[std_timings[i].dmt-1];
if (!add_proposed_mode(monitor, mode_desc,
display_monitor_timings[std_timings[i].dmt-1].freq, 5))
{
free(mode_desc);
return NULL;
}
#if DODEBUG
printf("(derived from DMT standard):\n");
display_mode_parameters(mode_desc);
#endif
return NULL;
}
i++;
......@@ -693,20 +677,13 @@ static _kernel_oserror *generate_cvt3_timing(char cvt1, char cvt2, char cvt3, Mo
{
return error(ERR_NOSPACE, 0, 0, 0);
}
mode_desc->definition = display_monitor_timings[cvt_timings[i].dmt-1];
compute_modedescription(mode_desc);
mode_desc->frame_hz = display_monitor_timings[cvt_timings[i].dmt-1].freq;
mode_desc->priority = 4; /* CVT timing */
if (add_proposed_mode(monitor, mode_desc) == 0)
mode_desc->definition = display_monitor_timings[cvt_timings[i].dmt-1];
if (!add_proposed_mode(monitor, mode_desc,
display_monitor_timings[cvt_timings[i].dmt-1].freq, 4))
{
free(mode_desc);
return NULL;
}
#if DODEBUG
printf("(derived from DMT standard):\n");
display_mode_parameters(mode_desc);
#endif
return NULL;
}
i++;
......@@ -900,17 +877,10 @@ static bool dtd_block_to_modedesc(const uint8_t *dtd_data, MonitorDescriptionRef
}
sprintf(mode_desc->definition.name, "%d x %d", mode_desc->definition.xres, mode_desc->definition.yres);
compute_modedescription(mode_desc);
mode_desc->priority = priority;
if (add_proposed_mode(monitor, mode_desc) == 0)
if (!add_proposed_mode(monitor, mode_desc, -1, priority))
{
return false;
}
#if DODEBUG
display_mode_parameters(mode_desc);
#endif
return true;
}
......@@ -1214,7 +1184,8 @@ static _kernel_oserror *process_vtb_extension_block(EDIDExtensionBlockRef ext_bl
return NULL;
}
/* Unused bytes should be zero */
for (int byte = 0x5 + w*0x12 + y*0x3 + z*0x2; byte < 127; byte++) {
for (int byte = 0x5 + w*0x12 + y*0x3 + z*0x2; byte < 127; byte++)
{
if (extdata[byte])
{
return NULL;
......@@ -1247,8 +1218,8 @@ static _kernel_oserror *process_vtb_extension_block(EDIDExtensionBlockRef ext_bl
int cvt_byte = 0x5 + w*0x12 + cvt_blockno*0x3;
if (!((extdata[cvt_byte] == 0) &&
(extdata[cvt_byte+1] == 0) &&
(extdata[cvt_byte+2] == 0))) {
(extdata[cvt_byte+2] == 0)))
{
res = generate_cvt3_timing(extdata[cvt_byte], extdata[cvt_byte+1], extdata[cvt_byte+2], new_monitor);
if (res)
{
......@@ -1267,8 +1238,8 @@ static _kernel_oserror *process_vtb_extension_block(EDIDExtensionBlockRef ext_bl
}
int std_byte = 0x5 + w*0x12 + y*0x3 + std_blockno*0x2;
if (!((extdata[std_byte] == 0x1) &&
(extdata[std_byte+1] == 0x1))) {
(extdata[std_byte+1] == 0x1)))
{
res = generate_standard_timing(extdata[std_byte], extdata[std_byte+1], new_monitor);
if (res)
{
......@@ -1443,7 +1414,8 @@ static _kernel_oserror *parseedid(char *ediddata, const char *file)
{
if (!((edidblockref->data_block[blockno][cvt_byte] == 0) &&
(edidblockref->data_block[blockno][cvt_byte+1] == 0) &&
(edidblockref->data_block[blockno][cvt_byte+2] == 0))) {
(edidblockref->data_block[blockno][cvt_byte+2] == 0)))
{
res = generate_cvt3_timing(
edidblockref->data_block[blockno][cvt_byte],
edidblockref->data_block[blockno][cvt_byte+1],
......@@ -1673,7 +1645,8 @@ static _kernel_oserror *parseedid(char *ediddata, const char *file)
fprintf(f,"# Uses %s frequency pixel clocks\n", ((edidblockref->feature_support & 1) == 1)?"Continuous":"Specific");
char *rules="unknown";
switch (timing_support) {
switch (timing_support)
{
case EDID_USE_CVT:rules="CVT";break;
case EDID_USE_DMT:rules="DMT";break;
case EDID_USE_CVTRB:rules="CVTRB";break;
......@@ -1688,7 +1661,8 @@ static _kernel_oserror *parseedid(char *ediddata, const char *file)
fprintf(f,"DPMS_state:%d\n",new_monitor->dpms_state);
}
ModeDescriptionRef this = new_monitor->modelist;
do {
do
{
fprintf(f,"\n# Mode: %d x %d @ %dHz",this->definition.xres,this->definition.yres,this->frame_hz);
fprintf(f,"\nstartmode");
fprintf(f,"\n mode_name:%d x %d",this->definition.xres,this->definition.yres);
......@@ -1707,7 +1681,8 @@ static _kernel_oserror *parseedid(char *ediddata, const char *file)
} while (this);
/* now fo hex dump of EDID block */
fprintf(f,"# EDID block dump\n#\n");
for (int i=0; i<(edidblockref->extension_block_count+1)*0x80;i+=16) {
for (int i=0; i<(edidblockref->extension_block_count+1)*0x80;i+=16)
{
fprintf(f,"# %02x %02x %02x %02x %02x %02x %02x %02x",
ediddata[i],ediddata[i+1],ediddata[i+2],ediddata[i+3],
ediddata[i+4],ediddata[i+5],ediddata[i+6],ediddata[i+7]);
......@@ -1835,7 +1810,7 @@ _kernel_oserror *loadedid(const char *file)
/* Check the block is valid */
if (!res)
{
res = Check_EDID_Checksum((EDIDBlockRef)edidblock, true);
res = check_edid_checksum((EDIDBlockRef)edidblock, true);
}
if (!res)
{
......@@ -1861,7 +1836,7 @@ _kernel_oserror *readedid(int displaynum, const char *file)
/* Check the block is valid */
if (!res)
{
res = Check_EDID_Checksum(edidblock, false);
res = check_edid_checksum(edidblock, false);
}
/* Now use a separate pointer to the block for extending it and
......@@ -1891,7 +1866,7 @@ _kernel_oserror *readedid(int displaynum, const char *file)
/* Check the block is valid */
if (!res)
{
res = Check_EDID_Checksum(edidblock, true);
res = check_edid_checksum(edidblock, true);
}
}
}
......
......@@ -180,9 +180,9 @@ typedef struct
char name[MAXMODENAME+1];
uint32_t xres; /* User quoted xres (may differ from hpar[FR_DISP], especially in interlaced modes) */
uint32_t yres; /* User quoted yres (may differ from vpar[FR_DISP], ... */
uint16_t hpar[FR__COUNT]; /* H. framing in vidc pixel times */
uint16_t vpar[FR__COUNT]; /* V. framing in vidc raster times */
uint32_t pixel_khz; /* vidc pixel rate in kHz */
uint16_t hpar[FR__COUNT]; /* H. framing in pixel times */
uint16_t vpar[FR__COUNT]; /* V. framing in raster times */
uint32_t pixel_khz; /* pixel rate in kHz */
uint32_t external_clock; /* rate of external clock in kHz (use it instead of VCO), or -1 */
uint8_t syncpol; /* sync polarity code (0..3 for now) */
uint8_t interlaced; /* whether mode is interlaced using two seperate framebuffers (0 or 1) */
......@@ -199,16 +199,16 @@ typedef struct mode_description_
uint32_t line_hz; /* line rate in Hz (for diagnostics only) */
uint32_t frame_hz:8; /* frame rate in Hz, for user frame rate selection */
uint32_t frame_mhz:24; /* also in mHz (millihertz), for more precise cmp */
uint8_t priority; /* Bits 0-2 = 'Parameter type' - where did the definition come from? (EDID 1.4 Section 5 */
uint8_t priority; /* Bits 0-2 = 'Parameter type' from? (EDID 1.4 Section 5) */
/* 0 = Undefined (MDF or something which overrides all else) */
/* 1 = Preferred Timing Mode from base EDID */
/* 2 = A Detailed timing mode in the base EDID */
/* 2 = Detailed Timing Mode in the base EDID */
/* 3 = Any detailed timing modes in extension blocks */
/* 4 = Any optional 3-byte CVT codes in the base EDID or extension block */
/* 5 = Standard Timings listed in Base EDID or extension blocks */
/* 5 = Standard Timings listed in base EDID or extension blocks */
/* 6 = Additional timing mode information: Established Timings I, II, III, */
/* default GTF, GTF secondary curve and CVT */
/* 7 = Base VIDEO MODE (defined as 640 X 480 X 60Hz). */
/* 7 = Base VIDEO MODE (defined as 640 x 480 x 60Hz). */
} ModeDescription, *ModeDescriptionRef;
/* Audio format information extracted from EDID */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment