video: Vertical Scaling Changes (#608)

Integer Resolution Scaling
Generate a video mode whose vertical resolution is an integer multiple
of the cores vertical resolution. The video mode set via the
`video_mode` parameter is considered the maximum resolution. There are
two modes of operation: vscale_mode=4 - Both vertical and horizontal
resolution are modified. The horizontal resolution is scaled in
propotion to the vertical, so the aspect ratio is maintained. This will
be most suited to VGA CRTs that expect a specific aspect ratio signal.
vscale_mode=5 - Only the vertical resolution is modified. This will be
suitable for most modern LCD/OLED displays. The additional horizontal
resolution provides more space for wide aspect ratio cores.

Video Mode Calculation
CVT timing calculations are used to generate the modified video modes
for Interger Resolution Scaling, this mode generation is also exposed as
an additional way to specify video modes in the MiSTer.ini. Modes can be
specified with just the width, height and refresh rate:
`video_mode=1920,1200,60`. Whether to use the original CVT or the
reduced blanking CVT-RB timings can be specified with an optional flag,
e.g. `video_mode=1024,768,60,cvt`. Additionally the sync polarities can
also be expressed using flags now, e.g.
`video_mode=1280,110,40,220,720,5,5,20,74250,+hsync,-vsync`

Code Changes
More functionality was broken out of `video_mode_adjust`.
`video_mode_select` determines what the correct base video mode is based
on the timing and vsync_adjust configuration. The mode selected there is
then passed to `video_resolution_adjust` which modifies it based on the
integer resolution scaling selected. Other than that the functionality
of `video_mode_adjust` remains the same.

The `video_calculate_cvt` function was added to calculated video mode
timings.

`parse_custom_video_mode` was changed to support the additional flags.
It now uses `str_tokenize` to split up the input string so it is more
easy to manage the different variations of parameter counts allowed for
the modes.

`vmode_custom_param_t` was added to alias the items in the
vmode_custom_t instead of using raw array indexing everywhere.

`str_util.h/.cpp` added to provide some safer and easy to use string
functions. `strcpyz`, `strncpyz`, `sprintfz` all ensure that the
resulting string is null terminated and doesn't overrun memory.
This commit is contained in:
Martin Donlon
2022-05-20 10:48:19 -07:00
committed by GitHub
parent b43e5cfc34
commit edcb3fcefc
5 changed files with 411 additions and 94 deletions

34
str_util.cpp Executable file
View File

@@ -0,0 +1,34 @@
#include "str_util.h"
#include <string.h>
int str_tokenize(char *s, const char *delim, char **tokens, int max_tokens)
{
char *save_ptr = nullptr;
int count = 0;
char *token = strtok_r(s, delim, &save_ptr);
while (token && count < max_tokens)
{
tokens[count] = token;
count++;
token = strtok_r(nullptr, delim, &save_ptr);
}
return count;
}
char *strncpyz(char *dest, size_t dest_size, const char *src, size_t num)
{
size_t n = num >= dest_size ? dest_size - 1 : num;
strncpy(dest, src, n);
dest[n] = '\0';
return dest;
}
char *strcpyz(char *dest, size_t dest_size, const char *src)
{
return strncpyz(dest, dest_size, src, dest_size - 1);
}