shift translation for DOS too
[dosdemo] / README.md
1 Unnamed Mindlapse DOS demo for Pentium 133
2 ------------------------------------------
3 The demo requires VESA Bios Extensions (VBE) 2.0. If your graphics card doesn't
4 support VBE 2.0 or greater, then make sure to load the `univbe` TSR first.
5
6 Source structure
7 ----------------
8  - src/          cross-platform demo framework and miscellaneous utility code
9  - src/scr/      demo screens (parts) and effects support code
10  - src/dos/      DOS platform code
11  - src/sdl/      SDL 1.x platform code (windows/UNIX version)
12  - libs/cgmath/  math library, header-file only
13  - libs/imago/   image loading library (includes libpng, zlib, libjpeg)
14  - libs/anim/    keyframe animation library
15
16 Building on DOS with Watcom
17 ---------------------------
18 NOTE: Don't. Watcom produces significantly worse code than GCC, and at the
19 moment watcom-compiled version of the demo crashes on 3D scenes for some reason
20 which I need to investigate at some point. Suspect either inline assembly with
21 missing "modify" part, or more likely some FPU optimization which fucks up the
22 clipper.
23
24 Make sure you have Watcom or OpenWatcom installed, and the appropriate env-vars
25 set (the watcom installer automatically adds them to autoexec.bat by default).
26
27 Run wmake to build. Needs dos4gw.exe in current dir.
28
29 OpenWatcom cross-compilation on UNIX
30 ------------------------------------
31 source owdev script with contents (change WATCOM var as necessary):
32
33   export WATCOM=$HOME/devel/ow
34   export PATH=$WATCOM/binl:$PATH
35   export INCLUDE=$WATCOM/h:$INCLUDE
36
37 Run wmake to build. Needs dos4gw.exe and wstub.exe in current dir or PATH
38
39 Simply running ./demo.exe might invoke magic of the ancients to start wine,
40 which will in turn start dosbox, which will execute the DOS binary! If the gods
41 are slumbering in valhalla, just typing `dosbox demo.exe` should do the trick.
42
43 Building with DJGPP
44 -------------------
45 The DJGPP port of GCC is the recommended toolchain to use for building the demo,
46 either natively or cross-compiled on UNIX.
47
48 For native DOS builds add the DJGPP bin directory to the path (usually
49 `c:\djgpp\bin`) and set the DJGPP environment variable to point to the
50 `djgpp.env` file.
51
52 For cross-compiling on UNIX simply source the `setenv` file which comes with
53 DJGPP, which will set the `PATH` and `DJDIR` variables as necessary.
54
55 In both cases, run `make -f Makefile.dj` to build. To run the resulting
56 `demo.exe` you'll need to copy `cwsdpmi.exe` to the same directory. You can find
57 it here: ftp://ftp.fu-berlin.de/pc/languages/djgpp/current/v2misc/csdpmi7b.zip
58
59 When building natively on an old computer, and encounter a huge amount of disk
60 swapping, and corresponding ridiculously long compile times, make sure to
61 disable any memory managers and try again. `EMM386` may interfere with
62 `CWSDPMI`'s ability to use more than 32mb of RAM, and modern versions of GCC
63 need way more than that. Disable the memory manager with `emm386 off`, and
64 verify the amount of usable RAM with `go32-v2`.
65
66 Another problem is the MS-DOS version of `HIMEM.SYS` which only reports up to
67 64mb. To use more than that, which is necessary for modern versions of GCC, you
68 can either disable `HIMEM.SYS` completely, or use the `HIMEM.SYS` driver that
69 comes with Windows 9x (DOS >= 7). Here's a copy in case you need it:
70 http://mutantstargoat.com/~nuclear/tmp/d7himem.sys
71
72
73 Building and running with the SDL backend
74 -----------------------------------------
75 Run make to build (assuming make on your system is GNU make), or use the visual
76 studio 2013 project on Windows.
77
78 The SDL backend will scale the framebuffer up, by the factor specified in the
79 `FBSCALE` environment variable. So run the demo as: `FBSCALE=3 ./demo` for
80 a 3x scale factor, or just export the `FBSCALE` env var in the shell you are
81 going to use for running the demo. The default scale factor is 2x.
82
83 Datafiles
84 ---------
85 The demo datafiles are in their own subversion repo. To checkout the data files
86 run the following in the demo root directory:
87
88   svn co svn://mutantstargoat.com/datadirs/dosdemo data
89
90 Random optimization details about the Pentium1 (p54c)
91 -----------------------------------------------------
92 Use cround64 (util.h) for float -> integer conversions, instead of casts.
93
94 Performance measurement with RDTSC:
95     perf_start();
96     /* code under test */
97     perf_end(); /* result in perf_interval_count */
98
99 Cache organization (L1): 8kb data / 8kb instruction
100 128 sets of 2 cache lines, 32 bytes per cache line.
101
102 Addresses which are multiples of 4096 fall in the same set and can only have
103 two of them in cache at any time.
104
105 U/V pipe pairing rules:
106  - both instructions must be simple
107  - no read-after-write or write-after-write reg dependencies
108  - no displacement AND immediate in either instruction
109  - instr. with prefixes (except 0x0f) can only run on U pipe.
110  - prefixes are treated as separate 1-byte instructions (except 0x0f).
111  - branches can be paired if they are the second instr. of the pair only.
112
113 Simple instructions are:
114  - mov reg, reg/mem/imm
115  - mov mem, reg/imm
116  - alu reg, reg/mem/imm (alu: add/sub/cmp/and/or/xor)
117  - alu mem, reg/imm
118  - inc reg/mem
119  - dec reg/mem
120  - push reg/mem
121  - pop reg
122  - lea reg,mem
123  - jmp/call/jcc near
124  - nop
125  - test reg,reg/mem
126  - test acc,imm
127
128 U-only pairable instructions:
129  - adc, sbb
130  - shr, sar, shl, sal with immediate
131  - ror, rol, rcr, rcl with immediate=1