SDL2 introduced a bunch of new events, that old SDL1.2 implementation
did not have. We probably should start using some of them…
It's also extremely helpful for comparing order/number of window events
arriving on different OSes and WMs.
Move the code to a separate function to make it easier to understand and
modify. Remove traces of windowresolution=X% support - this option
causes more harm than benefit.
Add bound checks to prevent user from setting up window size bigger then
configured display allows.
Changing this option dynamically via "config" built-in never worked, it
was always broken. Set it to change'able only on start, otherwise all
broken edge-cases would need to be fixed.
And do small cleanup in surrounding area.
Using normal2x has several undesired side-effects:
- slightly slower performance (I did some perf flamegraphs and turns out
scaler code is a significant bottleneck, even when using normal1x aka
none) - we should limit it as much as possible before addressing the
problem directly.
- it makes default glshader=sharp less precise
- it will negatively affect window resizing code
The 'optinfo' build target asks GCC to print optimizations that
could not be performed to local 'missing.txt' files; these will
appear in each repsective subdirectory having source files.
Both GCC and Clang will now print Verbose vectorization information
during the build process, often describing why vectorization
cannot be performed.
This commit also enables basic instruction and math vectorization
for both the 'release' and 'optinfo' targets. This includes making
use of altivec instructions (available on all powerpc processors),
and at a minimum sse4.2 on all x86_64 processors (circa-2008+ AMD
and Intel CPUs).
Vectorization is also re-enabled for GCC FDO builds, which would
otherwise be disabled when we switch to -O2 optimizations.
These are false-positive findings, but they touch flimsy part of code,
that could very easily break.
In all 4 cases the code looked like this:
uint8_t buf[MEM_PAGE_SIZE]; // old lines 600, 601
…
if (region.bytes > MEM_PAGE_SIZE)
toread = MEM_PAGE_SIZE; // old line 635
else
toread = region.bytes;
// assert toread <= MEM_PAGE_SIZE
if (toread < remain) {
MEM_BlockWrite(…, buf, toread);
} else {
MEM_BlockWrite(…, buf, remain);
MEM_BlockWrite(…, &buf[remain], toread - remain);
// ~~~~~~~~~~~~
// ^
// Coverity flags buffer overrun here
// when: toread == remain == MEM_PAGE_SIZE
// because buf has size MEM_PAGE_SIZE
//
// Sometimes it's MEM_BlockRead, but the problem is the same
}
In such cases, second MEM_BlockWrite is a no-op because
(toread - remain == 0), but Coverity did not reach this point in
analysis (Coverity is right to check the corner case, but didn't know,
that we can assert toread <= MEM_PAGE_SIZE, so the corner case is the
only value triggering this buffer overrun).
Change `if (toread < remain)` to `if (toread <= remain)`, so corner case
will never trigger second (no-op) MEM_BlockRead/Write inside `else`.
This property can be used for selecting which display dosbox should
initially use. Number 0 can be either primary display or left-most
display, depending on OS and user settings.
AUTOTYPE performs scripted keyboard entry into the running
DOS program.
It can be used to reliably skip intros, answer Q&A style questions
that some games ask on startup, or conduct a simple demo.
It allows for delaying input by any number of fractional seconds,
as well defining the pacing between keystrokes. It uses the
comma character "," to insert additional delays similar to modern
phone numbers.
It uses key_* names as defined by the mapper to avoid using SDL
scancodes[1], which are unstable across platforms. This approach
also allows the triggering of custom key bindings the use has
defined.
[1] https://wiki.libsdl.org/SDL_GetScancodeName
"Warning: The returned name is by design not stable across
platforms, e.g. the name for SDL_SCANCODE_LGUI is "Left GUI" under
Linux but "Left Windows" under Microsoft Windows, and some
scancodes like SDL_SCANCODE_NONUSBACKSLASH don't have any name at
all. There are even scancodes that share names, e.g.
SDL_SCANCODE_RETURN and SDL_SCANCODE_RETURN2 (both called
"Return"). This function is therefore unsuitable for creating a
stable cross-platform two-way mapping between strings and
scancodes."
In the previous code, if the game attempted to seek beyond the track
length, or if a "seek & read" would add up to going beyond the
end-of-the-track, the code would pass those requests to the underlying
codecs to handle (and reject with a corresponding error code).
This PR moves those checks up into the CDROM CD-DA code, and will
short-circuit them. Illegal seeks won't be attempted, however the usual
negative return code will still be passed to the game just like before.
Likewise, reads beyond the end will be pruned so they will get as much
audio as possible, without asking the codec for extra.
Set AllowAllConstructorInitializersOnNextLine to false. This prevents
formatting problem when initializer list is long enough to be wrapped
once, but all initializers fitted into the next line.
Turn on AlignConsecutiveMacros option.
Adds LTO to the CI build for Linux, which bring it as close as possible
to the planned formal release, which will additionally use FDO.
Adds some helper scripts to work with FDO files.
Improves the build notes for how to create and use FDO files.
This script is intended to be used in two situations:
- When user can't configure clang-format in code editor or IDE
- Potentially to be used in CI in the future
Normal usecase is to run this script after commit, then review and
add formatted code, and amend the commit, e.g.:
git commit -m "Edit some C++ code"
./scripts/format-commit.sh
git add -p # select formatting changes you want to use
git commit --amend
Run:
./scripts/format-commit.sh --help
to learn about other options.
Rules are defined for all C/C++ code, except src/libs.
These rules are designed to emulate kernel coding convention with some
adaptations for C++11. Configuration file uses options available in
clang-format 8.0 (the newest version in 10.0) to provide compatibility
with older environments and operating systems. Some options are
commented out and marked with TODOs - those need to be investigated and
enabled/disabled during upgrade to clang-format 9.0.
DOSBox codebase is a mix of various styles with only few consistent
rules seen throughout the codebase, these clang-format rules preserve
some of existing conventions and conciously break with others.
Some unwritten upstream rules, that are now encoded in clang-format:
- Using tab for indentation.
- K&R-like indentation for control statements.
- Indentation rules for structs, classes, and non-anonymous enums.
- Case labels in switch statements are aligned the same way goto
statements would be (also K&R rule).
Some formatting aspects that were not followed consistently throughout
old DOSBox code, but are now encoded in clang-format:
- Space placing in control statements and function calls (makes the code
much more readable).
- Control statements (if-else, while) must be broken into multiple lines
(makes the code more readable, helps with debugging, reading compiler
logs and static analysis reports).
Some unwritten upstream rules, that are now changed by these rules:
- Placing opening function bracket in the same line as function
declaration (not in line with K&R). This rule makes it hard to make
constructor formatting consistent - old code dealt with it by not
formatting initializer lists at all. Unformatted initializer list can
result in lines hundreds of lines long and make it hard to add/remove
class fields while assuring correct initialization order.
In new clang-format rules K&R indentation is followed, allowing
initalizer lists to be formatted one initializer per line (which makes
it much easier to read and edit.