forked from joncampbell123/dosbox-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
1822 lines (1361 loc) · 73.6 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
DOSBox-X Manual (always use the latest version from www.dosbox-x.com)
DOSBox-X is a fork of the original DOSBox project (www.dosbox.com)
This project has a Code of Conduct in CODE_OF_CONDUCT.md, please read it.
I am rewriting this README, and new information will be added over time --J.C.
How to compile DOSBox-X in Ubuntu (kapper1224)
----------------------------------------------
sudo apt install libavformat-* libswscale-* libavcodec-*
./autogen.sh
./configure
make
sudo make install
How to compile in general
-------------------------
General Linux compile (FFMPEG/libav support required)
./build-debug
General Linux compile if FFMPEG/libav not desired
./build-debug-no-avcodec
Mac OS X compile
./build-macosx
Mac OS X compile (SDL2)
./build-macosx-sdl2
MinGW compile (on Windows, using MinGW64) for 32-bit Windows XP
./build-mingw
MinGW compile (on Windows, using MinGW64) for 32-bit Windows XP, lower-end systems that lack MMX/SSE
./build-mingw-lowend
MinGW compile (on Windows, using MinGW, not MinGW64) to target MS-DOS and the HX DOS extender
./build-mingw-hx-dos
NOTICE: Use the 32-bit toolchain from the main MinGW project, not the MinGW64 project.
Binaries compiled with MinGW64 have extra dependencies not provided by the HX DOS extender.
Mac OS X: If you want to make an .app bundle you can run from the Finder, compile the
program as instructed then run "make dosbox-x.app".
Visual Studio 2017 compile for 32/64-bit Windows Vista or higher
Use the ./vs2015/dosbox-x.sln "solution" file and compile.
You will need the DirectX 2010 SDK for Direct3D9 support.
As of 2018/06/06, VS2017 builds (32-bit and 64-bit) explicitly require
a processor that supports the SSE instruction set.
Visual Studio Code is supported, too.
Check the README.Windows file for more information about this platform.
XCode (on Mac OS X, from the Terminal) to target Mac OS X
./build-debug
Open source development
-----------------------
Ideas and patches are always welcome, though not necessarily accepted.
If you really need that feature or change, and your changes are not
accepted into this main project (or you just want to mess around with
the code), feel free to fork this project and make your changes in
your fork.
As joncampbell123 only has limited time to work on DOSBox-X, help is
greatly appreciated:
- Testing
- Features
- Hardware accuracy
- Software accuracy
- Games, applications, demoscene executables
- Windows 1.x through Millenium guest OS support
- Retro development
- Bug fixes, patches, improvements, refinements
- Suggestions, ideas, general conversation
- Platform support (primarily Linux and Windows, but others are welcome)
- Documentation
- Notes regarding games, applications, hacks, weird MS-DOS tricks, etc.
If you want to tweak or write some code and you don't know what to work
on, feel free to visit the issue tracker to get some ideas.
Warnings regarding C integer types
----------------------------------
Contrary to initial assumptions, never assume that int and long have specific
sizes. Even long long.
The general assumption is that int is 32 bit and long is 32 bit.
That is not always true, and that can get you in trouble when
working on this or other projects.
Another common problem is the use of integers for pointer manipulation.
Storing pointers or computing differences between pointers may happen
to work on 32-bit, where ints and pointers are the same size, but the
same code may break on 64-bit.
Therefore, for manipulating pointers, use uintptr_t instead of int or
long.
For quick reference, here is a breakdown of the development
targets and their sizes:
Windows (Microsoft C++) 32-bit:
sizeof(int) == 32-bit
sizeof(long) == 32-bit
sizeof(long long) == 64-bit
sizeof(uintptr_t) == 32-bit
Windows (Microsoft C++) 64-bit:
sizeof(int) == 32-bit
sizeof(long) == 32-bit
sizeof(long long) == 64-bit
sizeof(uintptr_t) == 64-bit
NOTE: If you ever intend to compile against older versions of Microsoft C++/Visual Studio,
the "long long" type will need to be replaced by __int64.
Linux 32-bit:
sizeof(int) == 32-bit
sizeof(long) == 32-bit
sizeof(long long) == 64-bit
sizeof(uintptr_t) == 32-bit
Linux 64-bit:
sizeof(int) == 32-bit
sizeof(long) == 64-bit
sizeof(long long) == 64-bit
sizeof(uintptr_t) == 64-bit
This code is written to assume that sizeof(int) >= 32-bit.
However know that there are platforms where sizeof(int) is
even smaller. In real-mode MS-DOS and 16-bit Windows for
example, sizeof(int) == 16 bits (2 bytes). DOSBox-X will
not target 16-bit DOS and Windows, so this is not a problem
so far.
For obvious reasons, far pointers are not supported. The
memory map of the runtime environment is assumed to be
flat with possible virtual memory and paging.
When working on this code, please understand the limits of
the integer type in the code you are writing to avoid
problems. Pick a data type that is large enough for the
expected range of input.
It is suggested to use C header constants if possible
for min and max integer values, like UINT_MAX.
If the code needs to operate with specific widths of
integer, please use data types like uint16_t, uint32_t,
int16_t and int32_t provided by modern C libraries, and
do not assume the width of int and long.
If compiling with older versions of Visual Studio, you will
need to include a header file to provide the uintptr_t and
uint32_t datatypes to fill in what is lacking in the C library.
When multiplying integers, overflow cases can be avoided
with a * b by rejecting the operation if b > (UINT_MAX / a)
or by multiplying a * b with a and b typecast to the next
largest datatype.
Remember that signed and unsigned integers have the same
width but the MSB changes the interpretation. This code
is written for processors (such as x86) where signed integers
are 2's complement. It will not work correctly with any
other type of signed integer.
2's complement means that the MSB bit of an integer indicates
the number is negative. When it is negative, the value could
be thought of as N - (2^sizeof_in_bits(int)). For a 16-bit
signed integer:
2^16 = 0x10000 = 65536
hex int unsigned int equiv
0x7FFE 32766 32766 32766 - 0
0x7FFF 32767 32767 32767 - 0
0x8000 -32768 32768 32768 - 65536
0x8001 -32767 32769 32769 - 65536
...
0xFFFE -2 65534 65534 - 65536
0xFFFF -1 65535 65535 - 65536
(carry, overflow all 16-bits, roll back to 0)
0x0000 0 0 0 - 0
0x0001 1 1 1 - 0
Another possible problem may lie in using negation (-) or
inverting all bits (~) of an integer for masking. The
result may be treated by the compiler as an integer. Make
sure to typecast it to clarify.
Another possible incompatiblity lies with printf() and
long long integers.
Always typecast the printf() parameters to the data type
intended to avoid problems and warnings.
While Mac OS X and Linux have runtimes that can take %llu
or %llx, Microsoft's runtime in Windows cannot. Either
avoid printing long long integers or add conditional code
to use %llx or %llx on Linux and %I64u or %I64d on Windows.
Note that MinGW compilation on Windows suffers from the
same limitation due to use of Microsoft C runtime.
When dealing with sizes, including file I/O and byte counts,
use size_t (unsigned value) and ssize_t (signed value) instead.
This will help with using the C++ standard template library
and the C file I/O library. If compiling for a target where
read and write use int for a return value instead, then
use typecasting.
When handling file offsets, use off_t instead of long.
Modern C runtime versions of lseek and tell will use that
datatype. For older runtimes that use "long", make a typecast
in a header file for your target to declare off_t. Remember
that off_t is a signed value and that it can be negative.
Make sure to use the 64-bit version of lseek (often named
lseek64 or _lseeki64) in order to support files 4GB or
larger if allowed by the runtime environment.
On most modern runtimes, an alternate version of open()
may be required in order to open or create files larger
than 2GB. However the alternate open() reference can be
eliminated in certain cases.
On 32-bit Linux, direct calls to open64() can be avoided
if CFLAGS contains -D_FILE_OFFSET_BITS=64 or
#define _FILE_OFFSET_BITS=64 is added to the project.
Remember that lseek() can return -1 to indicate an error.
lseek() however will permit seeking past the end of a file.
writing at that point will extend the file to allow the
file write to occur at that offset. Depending on the platform,
that will either cause a sparse file (Linux + ext) or will
cause a loop within the filesystem driver to extend the file
and zero clusters to make it happen (Windows XP through 10).
Use of the FILE* file I/O layer is OK, but not recommended
unless there is a need to use text parsing with functions
like fgets() or fprintf(). For other uses, please use C
functions open, close, read, write, lseek and learn to use
file handles.
Understand that when fgets() returns with the buffer filled
with the line of text, the end of the string will always include
the newline (\n) that fgets() stopped reading at.
If fopen() was called with the "b" flag on DOS and Windows
formatted text files, the end of the string will probably
contain \r\n (CR LF). On platforms other than DOS and Windows,
\r\n will always appear if it is in the file.
C file handles are signed integers. They can be negative.
File handles returned by the C runtime however are never
negative except to indicate an error.
A good way to track whether an int holds an open file therefore,
is to initialize at startup that integer to -1, and then when
open succeeds, assign that value the file handle. When closing
the file, assign -1 to the integer to record that the handle was
closed.
Other parts of the code can also check if the file handle is
non-negative before operating on the file as a safety measure
against calling that function when the file was never opened.
On Windows, the HANDLE value at the Win32 API level can be obtained
from an integer file handle using _get_osfhandle() for use with
the Win32 API functions directly.
When using open(), make sure to use O_BINARY to avoid
CR/LF translation on DOS and Windows systems. Make sure
there is a header that defines O_BINARY as (0) if the
platform does not provide O_BINARY to avoid #ifdef's
around each open() call.
When using arithmetic with C pointers and integers,
understand that the pointer is adjusted by the value of the
integer times the size of the pointer type. If you intend
to adjust by bytes, then typecast the pointer to char* or
unsigned char* first, or typecast to uintptr_t to operate
on the pointer value as if an integer, then add the integer
value to the pointer.
At the lowest level, a pointer could be thought of as an
integer that is interepreted by the CPU as a memory address
to operate on, rather than an integer value directly.
Therefore, when adding an integer to a pointer value, the
result could be thought of as:
(new pointer value in bytes) = (current pointer value in bytes) + integer value * sizeof(pointer data type)
If the pointer is char, then adding 4 will advance by 4 bytes.
If the pointer is int, then adding 4 will advance by 4 * sizeof(int) bytes, or, 4 memory locations of type int.
Keep this in mind when manipulating pointers while working
on this code.
Software security comments
--------------------------
DOSBox-X cannot claim to be a "secure" application. It contains a lot of
code designed for performance, not security. There may be vulnerabilities,
bugs, and flaws in the emulation that could permit malicious DOS executables
within to cause problems or exploit bugs in the emulator to cause harm.
There is no guarantee of complete containment by DOSBox-X of the guest
operating system or application.
If security is a priority, then:
Do not use DOSBox-X on a secure system.
Do not run DOSBox-X as root or Administrator.
If you need to use DOSBox-X, run it under a lesser privileged user, or in
a chroot jail or sandbox.
If your Linux distribution has it enabled, consider using the auditing
system to limit what the DOSBox-X executable is allowed to do.
Comments on DOSBox-X development
--------------------------------
The four major operating systems and platforms of DOSBox-X are (in this order):
1. Linux (with X11) 32-bit and 64-bit x86.
2. Windows 10 (followed by Windows 8, and Windows 7) for 32-bit and 64-bit x86.
3. Linux (with X11) on a Raspberry Pi 3 (arm 7).
4. Mac OS X Sierra 10.12 or higher 64-bit.
Linux and MinGW Windows builds are expected to compile with the GNU autotools.
A preliminary CMake build system is available, see README.cmake.md for details.
Straight Windows builds are expected to compile using the free community edition
of Visual Studio 2015 or Visual Studio 2017 and the DirectX 2010 SDK.
Mac OS X builds are expected to compile on the terminal using GNU autotools
and the LLVM/Clang compiler provided by XCode.
In all cases, the code requires a C++ compiler that can support the C++11
standard.
Note that DOSBox-X is written to compile against the in-tree copy of the
SDL 1.x (Simple Directmedia Libary), or against the SDL 2.x library provided
by your Linux distribution.
For Visual Studio and MinGW compilation, the in-tree copy of SDL is always
used.
The in-tree SDL 1.x library has been HEAVILY MODIFIED from the original
SDL 1.x source code and is somewhat incompatible with the stock library.
The modifications provide additional functions needed to improve DOSBox-X
and fix many issues with keyboard input, window mangement, and display
management that previously required terrible kludges within the DOSBox
and DOSBox-X source code.
In Windows, the modifications also permit the emulation to run independent
of the main window so that moving, resizing, or using menus does not cause
emulation to pause.
In Mac OS X, the modifications provide an interface to allow DOSBox-X to
replace and manage the OS X menu bar.
Comments on what DOSBox-X is lacking
------------------------------------
DOSBox-X aims for accuracy in emulation however there are some things the
design as implemented now cannot accomodate.
* Cycle-accurate timing of x86 instructions and execution.
Instructions generally run one per cycle in DOSBox-X, except for I/O
and memory access.
If accurate emulation of cycles per instruction is needed, please
consider using PCem or PCem-X instead.
* Full precision floating point emulation.
Unless using the dynamic core, DOSBox and DOSBox-X emulate the FPU
registers using the "double" 64-bit floating point data type.
The Intel FPU registers are 80-bit "extended precision" floating
point values, not 64-bit double precision, so this is effectively
12 bits of precision loss and 5 bits of range loss (64 to 53 mantissa
bits and 16 to 11 exponent bits).
This slight loss of precision is perfectly fine considering DOSBox's
original goal in supporting DOS games, but may cause problems in
other cases that need the full precision.
It is known at this time that this lack of precision is enough to
cause otherwise straightforward comparisons against integers to
fail in DOS applications originally written in QBasic or Turbo Basic.
There are such DOS games written that check their file size using
a floating point compare that will fail in this manner. To run these
games, you will need to disable FPU emulation (fpu=false) to force
the QBasic/TurboBasic runtime to use software emulation instead.
* Pentium II or higher CPU level emulation.
DOSBox-X contains code only to emulate the 8088 through the Pentium Pro.
If Pentium II or higher emulation is desired, consider using Bochs
or QEMU instead. DOSBox-X may eventually develop Pentium II emulation,
if wanted by the DOSBox-X community in general.
* Emulation of PC hardware 2001 or later.
The official cutoff for DOSBox-X is 2001, when updated "PC 2001"
specifications from Microsoft mandated the removal of the ISA slots
from motherboards.
The focus is on implementing hardware emulation for hardware made
before that point.
Contributers are free to focus on emulating hardware within the
1980-2001 timeframe of their choice.
* Windows guest emulation, Windows XP or later.
DOSBox-X emulation, in terms of running Windows in DOSBox-X, will
focus primarily on Windows 1.0 through Windows Millenium Edition,
and then on Windows NT through Windows 2000. Windows XP and later
versions are not a priority and will not be considered at this time.
If you need to run Windows XP and later, please consider using
QEMU, Bochs, or VirtualBox.
* Any MS-DOS system other than IBM PC/XT/AT, Tandy, PCjr, and NEC PC-98.
Only the above listed systems will be considered for development
in DOSBox-X. This restriction prevents stretching of the codebase
to an unmanageable level and helps keep the code base organized.
However, if adding emulation of the system requires only small
minimal changes, then the new system in question may be considered.
You are strongly encouraged to fork this project and implement
your own variation if you need to develop MS-DOS emulation for
any other system or console. In doing that, you gain the complete
freedom to focus on implementing the particular MS-DOS based
system of interest, and if desired, the ability to strip away
conflicting IBM PC/XT/AT emulation and unnecessary code to keep
your branch's code manageable and maintainable.
It would be easier on myself and the open source community if
developers could focus on emulating their platform of interest in
parallel instead of putting everything into one project that,
most likely, will do a worse job overall emulating all platforms.
If you are starting a fork, feel free to let me know where your
fork is and what system it is emulating, so I can list it in
this README file for others seeking emulation of that system.
To help, I have added machine and video mode enumerations as
"stubs" to provide a starting point for your branch's implementation
of the platform.
Stubs implemented so far:
- FM Towns emulation (machine=fm_towns)
Known DOSBox-X forks
--------------------
DOSBox-X Emscripten port (runnable in a web browser) by Yksoft1.
Significant changes are made in order to run efficiently within the web browser when compiled using LLVM/Emscripten.
These significant changes require dropping some useful features (including the menus) but are required for performance.
url: https://github.com/yksoft1/dosbox-x-vanilla-sdl/tree/emscripten (look for clone URL and use the emscripten branch)
Origins, and crediting of source code
-------------------------------------
by Jonathan Campbell.
As the developer of DOSBox-X, I cannot legitimately claim to have
written all of the code in this project.
DOSBox-X started as a fork of the main DOSBox project sometime
mid 2011. It was started out of a desire to improve the emulator
without having to fight with or worry about submitting patches
upstream.
As the forums make it clear, DOSBox's main focus is on DOS games.
This is evident by the fact that much of the code is somewhat
accurate code with kludges to make DOS games run, instead of
focusing on what hardware actually does.
Many of the changes I wanted to make were non-game related, and
therefore were unlikely to be accepted by the developers.
Since then, I have been modifying the source code over time to
improve emulation, fix bugs, and resolve incompatibilities with
Windows 95 through ME. I have added options so that DOSBox-X
by default can emulate a wider variety of configurations more
accurately, while allowing the user to enable hacks if needed
to run their favorite DOS game. I have also been cleaning up
and organizing the code to improve stability and portability
where possible.
It's more accurate to say then, that I wrote *some* of the code,
that I rewrote other parts of the code, and the rest is the DOSBox
SVN code as it existed since mid 2011.
The purpose of this section, is to try and build a comprehensive
list of source code in this repository that was borrowed from
other projects.
Some of the code is DOSBox SVN code in which some of the SVN
commits made since 2011 were incorporated into DOSBox-X.
The main DOSBox project was not written by one programmer. It has
been under development since late 2000 with patches, fixes, and
improvements from members all over the Vogons forums. Despite
not having an official release since DOSBox 0.74 over 10 years
ago, the project is still in active development today. Some of
the changes themselves incorporated code from other projects,
which are also credited in the list below.
Some of the code in this source tree also came from another
branch of DOSBox known as DOSBox Daum (http://ykhwong.x-y.net)
which itself incorporated code from the main DOSBox project,
DOSBox-X, and many experimental patches. Although the Daum
branch seems to be dead, the code borrowed from it still
exists in DOSBox-X.
This is my attempt to properly credit the code and it's
sources below. Feel free to revise and correct this list
if there are errors.
NE2000 network card emulation (Bochs; LGPLv2+)
src/hardware/ne2000.cpp
MT32 synthesizer (MUNT; LGPLv2.1+)
src/mt32/*.cpp
src/mt32/*.h
AVI writer with OpenDML support (written by myself; GPLv2+)
src/aviwriter/*.cpp
src/aviwriter/*.h
Framework-agnostic GUI toolkit (Jorg Walter; GPLv3+)
src/libs/gui_tk/*.cpp
src/libs/gui_tk/*.h
Porttalk library, to read/write I/O ports directly (Unknown source)
src/libs/porttalk/*.cpp
src/libs/porttalk/*.h
FreeDOS utilities as binary blobs (FreeDOS; no license)
src/builtin/*.cpp
NukedOPL OPL3 emulation (Alexey Khokholov; GPLv2+)
src/hardware/nukedopl.cpp
OPL emulation based on Ken Silverman OPL2 emulation (LGPLv2.1+)
src/hardware/opl.cpp
MOS6581 SID emulation (GPLv2+)
src/hardware/reSID/*.cpp
src/hardware/reSID/*.h
SN76496 emulation (MAME project; GPLv2+)
src/hardware/sn76496.h
src/hardware/tandy_sound.cpp
PC-98 video rendering and I/O handling code (written by myself; GPLv2+)
src/hardware/vga_pc98*.cpp
3dfx Voodoo Graphics SST-1/2 emulation (Aaron Giles; BSD 3-clause)
src/hardware/voodoo_emu.cpp
PC-98 FM board emulation (Neko Project II; BSD 3-clause)
src/hardware/snd_pc98/*
QCOW image support (Michael Greger; GPLv2+)
src/ints/qcow2_disk.cpp
HQ2X and HQ3X render scaler (ScummVM, Maxim Stepin; GPLv2+)
src/gui/render_templates_hq2x.h
Tips for hacking and modifying the source code
----------------------------------------------
As a SDL (Simple Directmedia Layer) based application,
DOSBox-X starts execution from main(), which is either
the real main() function or a redefined main() function
called from SDLmain depending on the platform.
On Linux and Mac OS X, main() is the real main function.
On Windows, main() is SDLmain() and is called from the
WinMain function defined in the SDL library.
The entry point main() is in src/gui/sdlmain.cpp,
somewhere closer to the bottom.
Configuration and control state (from dosbox.conf and
the command line) are accessible through a globally
scoped pointer named "control".
In the original DOSBox SVN project, "control" is
most often used for accessing the sections and
settings of dosbox.conf.
In DOSBox-X, "control" also holds flags and variables
gathered from the command line (such as -conf).
Most (though not all) of the sections and settings
are defined in src/dosbox.cpp. There is one function
DOSBox_SetupConfigSections() that adds sections and
settings.
Each section has a list of settings by name. Each
setting can be defined as an int, hexadecimal,
string, double, and multivalue item. Read
include/setup.h and src/misc/setup.cpp for more
information.
There is one section (the autoexec section) that
is defined as lines of text.
In the original DOSBox SVN project, each section
also has an init and destructor function. The
codebase in SVN is heavily written around emulator
setup from each section, which is why the order
of the sections is important. DOSBox-X eliminated
these init and destructor functions and encourages
initial setup from functions called in main(),
and additional setup/teardown through VM event
callbacks (see include/setup.h). A callback
mechanism is provided however (at a section level)
when settings change.
Most of the code in this codebase assumes that
it can retrieve a section by name, and a setting
by name, without checking whether the returned
referce to a setting is NULL. Therefore, removing
a setting or referring to settings before the
creation of them can cause this code to crash
until that reference is removed.
Time and cycles in DOSBox-X
---------------------------
Time is handled as a macro unit of 1ms time called "ticks",
tied heavily to SDL_GetTicks() to track time.
Within each 1ms tick, a cycle count specified by the user
is executed as CPU time.
Setting cycles=3000 therefore, instructs DOSBox and DOSBox-X
to execute 3000 cpu cycles per millisecond. That generally
means (though not always) that 3000 instructions are executed
per millisecond.
Other parts of emulation may consume additional CPU cycles
to simulate I/O or video RAM delay.
Normal_Loop() in src/dosbox.cpp controls per-tick execution
as directed by PIC_RunQueue() whether or not the 1ms tick
has completed.
Generally the CPU core will execute instructions for the
entire 1ms tick, but the loop will cut short if events
are scheduled to execute sooner.
Events are scheduled in src/hardware/timer.cpp, using
PIC_AddEvent() given a callback and a delay in milliseconds.
Scheduling an event will cut the CPU cycle count back to
enable the event to execute on time.
PIC_AddEvent() events are scheduled once. Periodic events
should call PIC_AddEvent() again within the callback. For
precision reasons, PIC_AddEvent() can identify whether it
is being called from an event callback, and it will use
the delta time differently to help periodic events maintain
regular intervals.
Events can be removed using PIC_RemoveEvents().
Per-tick event handlers can be added using the
TIMER_AddTickHandler() function in src/hardware/pic.cpp.
The callback will be called at the completion of the
1ms tick.
Emulator code can query emulator time at any time
using the functions in include/pic.h.
PIC_TickIndex() returns the time within the 1ms
tick as a floating point value from 0.0 to 1.0.
PIC_TickIndexND() returns the same as cycle counts
within the 1ms tick.
PIC_FullIndex() returns absolute emulator time
by combining ticks and cycle count time.
How DOSBox and DOSBox-X mix x86 and native code
-----------------------------------------------
Much of the DOS and BIOS handling in DOSBox and DOSBox-X
is done through the use of the "callback" instruction
and a callback system in src/cpu/callback.cpp.
Each BIOS interrupt is a callback, as is the DOS kernel
interrupts. INT 21h is handled as a callback to src/dos/dos.cpp
function DOS21_Handler(), for example. That native code
function can then manipulate CPU registers and memory as
needed to emulate the DOS call.
Some callback functions will also modify the stack frame
to set or clear specific CPU flags on return, using
functions CALLBACK_SCF(), CALLBACK_SZF(), and CALLBACK_SIF().
The callback instruction is 0xFE 0x38 <uint16_t>. This
is an invalid opcode on actual x86 hardware, but it is
a call into a callback function within the DOSBox
emulation. The uint16_t value specifies which callback.
Callbacks are registered through CALLBACK_Allocate(),
which then returns an integer value that is an index into
the callback table. 0 is an invalid callback value that
indicates no callback was allocated, though at this time,
CALLBACK_Allocate() is written to E_Exit() and abort
emulation in the case that none are available, instead
of returning zero.
CALLBACK_DeAllocate() can be used with the index to
free that slot so that other code can use CALLBACK_Allocate()
to take that slot if needed, though it is rare to use
CALLBACK_DeAllocate() so far.
When allocated, the emulation code can then write x86
instructions where needed that include the callback
instruction in order to work from native code at that
point in execution. Generally, most of the x86 code
generation is done within the callback framework itself
using CALLBACK_SetupExtra to write common patterns of
x86 code depending on how the native code is meant to
execute or return to the caller.
When the CPU core encounters a callback instruction,
the index of the instruction (nonzero, remember) is
returned from the execution loop with the expectation
the caller will then index the callback array with it.
If the callback instruction is called from protected
mode, memory and I/O access may cause recursion of
the emulator. Memory access functions called by the
native code may trigger an I/O port or page fault
exception within the guest. DOSBox and DOSBox-X
resolve the fault by pushing an exception frame
onto the stack and then recursing into another
emulation loop which does not break until the fault
is resolved. While this is perfectly fine for
DOS and Windows 3.1 simple fault handling, this
may cause recursion issues with more advanced
task switching and fault handling in Windows 95
and later.
The most common reason a callback handler might
get caught with a page fault is the emulation
of DOS and BIOS interrupts while running within
the virtualization environment of Windows 3.0
through Windows ME.
Another possible source of page faults may occur
with DOS extenders that enable paging of memory
to disk.
Callback functions will typically return CBRET_NONE.
General description of source code
----------------------------------
src/shell/shell.cpp SHELL init, SHELL run, fake COMMAND.COM setup,
startup messages and ANSI art, AUTOEXEC.BAT
emulation and setup, shell interface,
input, parsing, and execution
src/shell/shell_batch.cpp Batch file (*.BAT) handling
src/shell/shell_cmds.cpp Shell internal command handling, shell commands:
DIR CHDIR ATTRIB CALL CD CHOICE
CLS COPY DATE DEL DELETE ERASE
ECHO EXIT GOTO HELP IF LOADHIGH
LH MKDIR MD PATH PAUSE RMDIR
RD REM RENAME REN SET SHIFT
SUBST TIME TYPE VER ADDKEY VOL
PROMPT LABEL MORE FOR INT2FDBG
CTTY DEBUGBOX
src/shell/shell_misc.cpp PROMPT generator, command line input interface,
shell execution, and command location via PATH
interface.
src/gui/sdlmain.cpp Entry point, emulator setup, runtime execution,
cleanup. Menu management, GFX start/end handling,
GFX mode setup and management. Menu handling.
Logging of GFX state. A lot of other misc code.
src/gui/sdlmain_linux.cpp Linux-specific state tracking and handling.
src/gui/sdl_mapper.cpp Mapper interface, mapper event handling and routing,
mapper file reading and writing. Keyboard, mouse,
joystick, and shortcut handling. In DOSBox-X,
also ties mapper shortcuts to the menu system.
src/gui/sdl_gui.cpp Configuration GUI (using gui_tk), dialog boxes,
background "golden blur" behind dialog boxes,
input management and display of dialog boxes.
src/gui/menu.cpp Menu handling and management, processing,
application of menu to host OS menu framework
if applicable. In DOSBox-X, contains the menu
C++ class and menu item object system which then
maps to Windows HMENU, Mac OS X NSMenu, or the
custom drawn SDL menus if neither are available.
Which menu framework is used depends on the
assignment of the DOSBOXMENU_* constant as defined
in include/menu.h. By default:
Windows (HMENU) is used if targeting Windows
and not HX DOS and not SDL2
Mac OS X (NSMENU) is used if targeting Apple
Mac OS X and not SDL2
SDL drawn menus are used in all other cases.
A define is available via configure.ac if
SDL drawn menus should be used regardless of
the host OS and environment.
A NULL menu define is provided if a build
with no visible menus is desired.
src/gui/render.cpp RENDER_ and render scaler code. Also handles
color palette, aspect ratio, autofit options.
The selection of render scaler is defined and
chosen here.
src/gui/render_scalers.cpp Render scaler definitions and code. Note that
scalers are defined using header files as
templates and #defines to support each color
format.
src/gui/midi.cpp MIDI output framework. Header files include
additional platform-specific code.
src/gui/menu_osx.mm Mac OS X Objective C++ code to bridge Objective C
and C++ so that the menu manipulation code can
work correctly.
src/gui/direct3d.cpp Windows Direct3D9 support code. This code allows
output=direct3d to work properly. Uses DirectX 9
interfaces.
include/bitop.h Header file to provide compile-time and runtime
inline functions for bit manipulation and masking.
Additional code is in src/gui/bitop.cpp
include/ptrop.h Header file to provide compile-time and runtime
inline functions for pointer manipulation and
alignment. Additional code is in src/gui/ptrop.cpp.
src/aviwriter/* AVI writer library, written by Jonathan Campbell
sometime around 2010, and incorporated into DOSBox-X.
Unlike the initial code from DOSBox SVN, this code
can support writing OpenDML AVI files that exceed
the 2GB file size limit.
All definitions, including Windows PCM formats and
GUIDs, are provided here.
src/misc/cross.cpp Cross-platform utility functions.
src/misc/messages.cpp Message translation table functions.
src/misc/setup.cpp Configuration, section, and setting management.
src/misc/shiftjis.cpp Shift-JIS utility functions.
src/misc/support.cpp String support functions including case conversion.
src/builtin/*.cpp Built-in executable binaries, defined as unsigned char[]
arrays and registered at runtime:
25.COM 28.COM 50.COM APPEND.EXE
BUFFERS.COM COPY.EXE CWSDPMI.EXE DEBUG.EXE
DEVICE.COM DOS32A.EXE DOS4GW.EXE DOSIDLE.EXE
EDIT.COM FCBS.COM FIND.EXE HEXMEM16.EXE
HEXMEM32.EXE LASTDRIV.COM MEM.COM MOVE.EXE
TREE.EXE XCOPY.EXE
src/cpu/paging.cpp Paging and page handling code, TLB (translation lookaside buffer),
Page handlers
src/cpu/modrm.cpp x86 mod/reg/rm effective address handling and lookup
src/cpu/mmx.cpp Minimalist MMX register handling and effective address lookup
src/cpu/lazyflags.cpp Lazy CPU flag evalulation. CPU flags are evaluated only if needed.
src/cpu/flags.cpp CPU flag evaluation code.
src/cpu/cpu.cpp NMI emulation, protected mode descriptors, stack push/pop,
Selector base/limit handling, CPL, flags, exception handling,
TSS (Task State Segment), task switching, I/O exception
handling, general exception handling, interrupt handling,
general flow control instruction handling, evaluation of
[cpu] section settings and application of settings and
changes to settings, I/O instruction stubs, model-specific
register emulation, CMPXCHG8B.
src/cpu/core_simple.cpp Simple CPU core (core=simple). Uses normal core header files.
Core cannot be used if paging is enabled or when executing
from memory outside the valid range of system memory.
src/cpu/core_prefetch.cpp Prefetch CPU core (cputype=*_prefetch). Uses normal core header files.
This core should be used for any application that is dependent
on CPU prefetch including anti-debugger, copy protection, or
self modifying code.
src/cpu/core_normal.cpp Normal CPU core.
src/cpu/core_normal_286.cpp Normal CPU core, 286 emulation.
src/cpu/core_normal_8086.cpp Normal CPU core, 8086 emulation.
src/cpu/core_full.cpp Full CPU core (core=full). Appears to have been borrowed from
Bochs.
src/cpu/core_dyn_x86.cpp Dynamic CPU core (core=dynamic). On 32-bit x86 builds, this code
interprets the guest executable code and produces executable
code for the host process. This core is faster than the other
cores however it may have problems with paging and it does not
emulate CPU cycle counts accurately.
src/cpu/callback.cpp DOSBox/DOSBox-X callback instruction and callback handling system.
src/debug/debug.cpp Debugger, breakpoint handling and enforcement, debugger commands,
debugger interface, debug runtime loop (when broken into the