1
0
Fork 0
Commit graph

992 commits

Author SHA1 Message Date
krcroft
d09f6ae665 Add AUTOTYPE to DOSBox's programs 2020-04-04 06:17:28 +02:00
krcroft
690a4f4efd Conform to white-space convention in GPL's copyright line 2020-04-04 04:10:06 +02:00
krcroft
1d353843b3 Add header guard 2020-04-04 04:10:06 +02:00
krcroft
cc80c19193 Add copyright header 2020-04-04 04:10:06 +02:00
krcroft
11643631f5 Apply clang-format rules 2020-04-04 04:10:06 +02:00
krcroft
f1d197ec5f Cleanup PVS warning unecessary code 2020-04-04 04:10:06 +02:00
krcroft
233cf5089b Cleanup PVS warning regarding combersome empty checks 2020-04-04 04:10:06 +02:00
krcroft
dad002203c Cleanup PVS warning regarding unecessary copy 2020-04-04 04:10:06 +02:00
krcroft
3df2734b52 Clarify choice of wrap-width 2020-04-04 04:10:06 +02:00
krcroft
9e086a882e Use WriteOut_NoParsing where possible 2020-04-04 04:10:06 +02:00
krcroft
75dd033cb0 Validate string to double using std::isfinite 2020-04-04 04:10:06 +02:00
krcroft
239396fec8 Add AUTOTYPE to DOSBox's programs
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."
2020-04-04 04:10:06 +02:00
krcroft
e8ac2d60f3 Ensure seeks and reads are within bounds of the track length
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.
2020-04-02 06:20:23 +02:00
krcroft
b71788dba6 Make a second harder attempt to seek if needed 2020-03-27 15:01:26 +01:00
Patryk Obara
a956f14de1 Inject newlines before displaying DOS prompt
In an earlier change, I removed appending newline outside of batch mode
in DOS shell code - that made DOSBox behave less like MS-DOS and more
like modern shells, that do not try to compensate for buggy
applications.

However, we should recognize that DOSBox (unlike e.g. FreeDOS) is designed
to run legacy applications, which might make assumptions about DOS
implementation. Some examples:

- PC Player Benchmark assumes, that help commands are displayed exactly
  at 80x25 terminal and formats the output to fill the whole screen
  (scrolling past DOS4GW messages).
- Quake and other ID games print shareware information on exit, but do
  it via a direct memory dump (not interrupts to print DOS text), and
  follow up with setting cursor exactly at line 22 (which is partly
  written already), expecting shell to inject newline.
- PCC Compiler prints status message on exit without newline, depending
  on MS-DOS shell behaviour.
- TEXTUTIL set of external commands do not print nothing to standard
  output, and are designed to clear the screen, therefore writing a
  newline after .COM commands would be a mistake.

Therefore we want to inject this newline, but not in every case.

New implementation reuses a static variable used by Program base class
(for purpose of translating UNIX newlines to DOS newlines) for detection
if it's appropriate to inject an additional newline or not.

Injecting the newline happens in function displaying the DOS prompt (so
we don't need to write additonal logic for separately handling batch
mode). When starting a non-COM, non-internal command the static variable
is set to the state indicating that next DOS prompt should inject the
newline.

Fixes: #208
2020-03-12 20:54:33 +01:00
krcroft
83f625178a Ensure the first seek isn't cached 2020-03-08 08:36:21 +01:00
Joshua Fern
f2029d71d8 Update copyright dates to 2020 2020-03-07 00:18:01 +01:00
krcroft
16dbd1cec6 Whitespace cleanup 2020-03-06 19:21:44 +01:00
krcroft
08c6fc10c1 Add a signed integer ceiling divide function 2020-03-06 19:21:44 +01:00
krcroft
96a9723df5 Drop "[bug]" postfix in assets 2020-03-06 19:21:44 +01:00
krcroft
1e65bb2cdc Curtail an excessively noisy DEBUG output case
Some games repeatedly query for the first track's position during
playback, perhaps as a dual-purpose "CDROM health/heart-beat"
check.

This excessive console output in DEBUG mode tends to add far more
noise than signal, and prevents the maintainer from seeing the
overall flow of the CDROM calls.
2020-03-06 19:21:44 +01:00
krcroft
818e923296 Let the code describe the functionality when reading sectors
Moves to using a member vector to provide a persistent buffer,
instead of repeatedly allocating and deleting memory on every
invocation (during DAE, this can be called hundreds of times
per second, with requsts of up 24 sectors or ~56KB of memory
per call).

The buffer is only resized upward, which avoids 'zig-zag'
re-allocations when switching between raw (2352-byte) and cooked
(2048-byte) sectors.

Only writes as much data was was successfully read into
the DOS program's buffer, avoiding (potential) garbage-fill.
2020-03-06 19:21:44 +01:00
krcroft
c76cc09d97 Add support for mono tracks when performing DAE (digital-audio-extraction)
This commit:
- Adds more sanity checks and comments
- Lets the seek() function to take care of monitoring the track's
  post-seek decode position, instead of managing it in read(..).
- Adds in-place conversion from mono-to-stereo
- Adds micro-second-level DEBUG timing around the mono converter
- Makes use of the more intuitive ceil_divide() support function
  to avoid excessive casting and floating-point conversion.
2020-03-06 19:21:44 +01:00
krcroft
cff1ded8e9 Improve seeking for audio tracks
This commit:
- Comments why we convert from byte-to-time offset.
- Checks for underlying stream validity before seeking.
- Tracks the new as-seeked decode position.
- Skips seeking if it's unecessary.
- Adds DEBUG messaging and a warning if the seek took
  longer than that of an average physical CDROM.
2020-03-06 19:21:44 +01:00
krcroft
e8e9e0ef4f Replace code with existing support function 2020-03-06 19:21:44 +01:00
krcroft
c7eebacde9 Allow the code to describe the return value 2020-03-06 19:21:44 +01:00
krcroft
9bebfdabd3 Make more logic assertions and cleanup multi-line comments 2020-03-06 19:21:44 +01:00
krcroft
1393c1316c Refine types and eliminate implicit-casting and magic-numbers
The commit refines several types to their logical use-cases.
For example, a CDROM will at-most contain 400,000 sectors and be
less than 1B bytes in size. Likewise, both are 'physical'
quantities and this should always be zero-or-greater
(therefore, uint32_t is used).

Fortunately, there are almost no cases where these values are
overloaded to mean something else (ie: negative return codes to
indicate failure).

Besides eliminating many implicit cast warnings, differing-signed
comparison warnings, and overflowable type-cast warnings, the
more correct use of types helps logically bound expectations of the
values they contain, which should improve maintainability.
2020-03-06 19:21:44 +01:00
krcroft
459f7d32f9 Define more CD-DA magic numbers 2020-03-06 19:21:44 +01:00
krcroft
a6251d7e9f Fix iterator-past-end-of-container Coverity warning 2020-03-04 16:03:40 +01:00
krcroft
eef8c51419 Address code-review comments (squash-me) 2020-03-04 05:11:40 +01:00
krcroft
908ddafb5f Reserve the trackFile shared_ptr prior to its test 2020-03-04 05:11:40 +01:00
krcroft
5bbf876f0c Expand trackFile's shared_ptr life 2020-03-04 05:11:40 +01:00
krcroft
1d123367a5 Use MixerObject's singleton-pattern to manage the channel 2020-03-04 05:11:40 +01:00
krcroft
91cd907c4e Migrate some members of the Player class to smart pointers
1. Moves the mutex and mixer channel members to unique pointers
2. Moves the trackFile to a weak pointer
3. Move member initialization to the class definition

This class still retains a raw *cd member, however fixing this
ripples up to the array of [26] CD images, and across more
code that generically deals with mount points; so this work
remains to do.
2020-03-04 05:11:40 +01:00
Patryk Obara
d47450c6d7 Fix memory leak in dos_execute 2020-03-01 21:23:04 +01:00
Patryk Obara
9fc21dc294 Allow GNU extensions for GCC to avoid MinGW bugs
Most MinGW versions work correctly with and without _POSIX_C_SOURCE
or XOPEN macros [1] and don't need any special handling, but some
installations refuse to work correctly.

To be more precise: *some* MinGW installations turn off POSIX support
after turning on -std=c++11 WITHOUT -ansi -Wpedantic, -pedantic-errors
and similar.  This behaviour is inconsistent between various Windows
versions and MinGW distributions and manifests itself only when using
GCC (Clang behaves correctly).

[1] https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
2020-03-01 21:13:19 +01:00
krcroft
6c0e1a4607 Switch write protected set to unordered_set 2020-02-24 12:08:01 +01:00
krcroft
b302b535c3 Add DEBUG messages for protected-file handling 2020-02-24 12:08:01 +01:00
krcroft
9603c961c0 Fix spacing and effc++ warnings
Apply code review recommendations
2020-02-24 12:07:53 +01:00
krcroft
c730e5d70a
Permit the use of protected game data files
Many DOS games open all their files in write-mode regardless if the
game actually intends to write to them or not.

This can result the files' metadata being updated (lossing the
original date-stamp) as well as putting the file at-risk of
corruption if the game crashes with the file open for writing.

Under the existing DOSBox implementation, if a user attempts to
write-protect their data files then DOSBox will quit with an error in
the above scenario.

This commit allows the use of write-protected files (similar to
running a game from CDROM) and indicates which files are being
actively protected against modification.

Typically the only files that need to be left writable are those that
the game actually changes, such as: save-game files, highscore
files, in-game settings, and so on.  If these are also protected,
then the game will quit/crash immediately after the protected message
is printed, and thus indicate which file require write-allowance.
2020-02-23 21:45:20 -08:00
krcroft
6804faf931 Fix a pointer invalidation corner-case in CD-DA 2020-02-23 13:08:08 +01:00
Patryk Obara
c619445003 Avoid buffer underflow by copying all fields
This code made silent assumption that first fields in direntry are
exactly 14 bytes - this was fine, except would break as soon as anyone
would touch the struct (or e.g. if a compiler would lack support for
packed structures and inject some padding in there); rewrite the copy
code to follow the same pattern as other fields - now the code will be
fine even if someone will change fields in the direntry struct.

Fixes 2 PVS static analysis issues (buffer underflow on src and dst).
2020-02-23 01:13:11 +01:00
Patryk Obara
6011c016c5 Replace var_read with host_to_le where possible
Effect is the same, except packed values are not referenced via pointer
so there's no address-of-packed-member warning, and no need for
unaligned memory access.
2020-02-22 22:47:40 +01:00
Patryk Obara
bdf67cdbcc Merge branch 'svn/trunk' r4330 2020-02-22 21:10:57 +01:00
Peter Veenstra
57bf045cc8 some big endian improvents and drive_fat fixes. (jmarsh)
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4330
2020-02-22 12:06:40 +00:00
krcroft
c132263116 Add partial DAE support for compressed Redbook-compliant tracks 2020-02-18 18:54:41 +01:00
krcroft
fdf103a111
Fix sector 0 playback bug
This bug prevented reporting of correct playback position on
pure-audio CDs with zero PREGAP.
2020-02-17 12:19:21 -08:00
Patryk Obara
5bd3a4ac8d Merge branch 'svn/trunk' r4328 2020-02-15 21:27:20 +01:00
Peter Veenstra
27610a2e66 Small cleanup and move to ++i instead of i++ for iterators in this file
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4328
2020-02-15 17:22:00 +00:00