Analysis model: gpt-5.5 xhigh
Mentality by Mental Design - Technical Dissection
Scope
This is a binary-level pass over Mentality by Mental Design, released in
1993 for MS-DOS. The archive sits in the Assembly 1993 PC demo collection and
the NFO calls the production a "dentro". The package is technically interesting
because it is not just a normal packed EXE: the public MENTAL.EXE is an EXOS
container with a tiny DOS loader, an internal executable filesystem, multiple
embedded real-mode MZ programs, two MOD files, graphics assets, palettes, and a
small command/setup layer.
Useful public references:
- Scene.org archive: https://files.scene.org/view/parties/1993/assembly93/demo/mentalit.zip
- Assembly 1993 PC demo archive: https://archive.assembly.org/1993/pc-demo
This writeup intentionally omits old address and dial-up distribution details from the NFO. They are not needed to understand the executable. The useful technical context is that the NFO describes the production as partly derived from work done around Extreme's Exterminate demo: after Assembly 1993, some members formed Mental Design, reused and redesigned selected parts, added new sections, redid graphics/music, and optimized older code.
Examined Archive
The distributed archive used here:
313b219e2799b0d63757d82bf051a9d0a4b293b33cad2ec39024798f30ec2d9e mentalit.zip
Extracted files:
4c9da727e5d52f89f77f28738fb4ea6e02e2ff0fedb1eb8a6bb6f01def00f9f6 FILE_ID.DIZ
c38e1cba527924c08cdf4ac2dcd535be3e88d26acb492f695fbeae1af5b6778a MENTAL.EXE
03e4f342af5a7329bea187ce4cbccae5c275adf3a4909a618bb778c94346d84d MENTALIT.NFO
The NFO requirements are also useful for reading the code:
minimum: 386, VGA, about 500 KB free DOS memory
recommended: 486DX/33, about 630 KB free, Sound Blaster Pro
The runtime switches explain several branches in the loader and the fractal zoomer:
/DOTWEAK or /DT enable lower/tweaked fractal zoomer modes
/NOSOUND or /NS run without the sound system
/SHOWSPEED or /SS print measured CPU/video/memory speed indexes
/SPEED=a,b,c or /SP=a,b,c override CPU/video/memory indexes
The parser image contains a compile timestamp string of Dec 21 1993 and
00:00:18; the NFO is dated the next day. I treat the release year as 1993.
Outer MZ And EXOS Container
MENTAL.EXE looks small if only the MZ header is trusted:
file size: 402167 bytes
declared MZ image: 4180 bytes
header: 512 bytes
relocations: 3
entry: 003f:0000
stack: 0000:03e8
minalloc/maxalloc: 0 / 1
The real payload is an overlay/container after the tiny MZ body. The boot code contains EXOS strings:
EXOS ver 1.00 (c) 1993 by Wizard
INT FF Services available
INT FF Services not available
FATAL ERROR: Unable to initialize file system
FATAL ERROR: Requires DOS 3.0 or higher
EXTREME_EXEA_WIZ
The core model is:
start tiny MZ loader
check DOS version
install or query EXOS INT FF services
initialize internal file system
load a child executable or asset by EXOS table entry
child parts call back into INT FF for file/service queries
return to the loader for the next part
This matters because several child images contain no normal DOS filenames for their assets. They ask the resident EXOS layer for numbered/name-table entries instead.
The internal records begin near 0x1060. They give a start offset, end offset,
and a name. The executable parts and assets are packed into one file:
| Id | Record offset | Data range | Name |
|---|---|---|---|
| 00 | 0x1060 |
0x0015a4..0x0034a4 |
Part_Loader |
| 01 | 0x10a0 |
0x0034a5..0x004200 |
VTextMorpher_by_Moleql |
| 02 | 0x10e0 |
0x004201..0x009923 |
Intro_by_Wizard |
| 03 | 0x1120 |
0x009924..0x00afdc |
interferance_by_Moleql |
| 04 | 0x1160 |
0x00afdd..0x011a44 |
Ifs_by_Wizard |
| 05 | 0x11a0 |
0x011a45..0x012b2c |
Many_faced_glenz_by_Moleql |
| 06 | 0x11e0 |
0x012b2d..0x018b9e |
Fractal_zoomer_by_Wizard |
| 07 | 0x1220 |
0x018b9f..0x01e144 |
texture_cubes_by_Moleql |
| 08 | 0x1260 |
0x01e145..0x01fe75 |
End_scroller_by_Wizard |
| 09 | 0x12a0 |
0x01fe76..0x020381 |
setup_for_shit |
| 10 | 0x12e0 |
0x020382..0x02253d |
Command_line_parser |
| 11 | 0x1320 |
0x02253e..0x025098 |
Fframe_for_ifs_by_NiK |
| 12 | 0x1360 |
0x025099..0x026eba |
pic_b4_fractalzoomer_by_NiK |
| 13 | 0x13a0 |
0x026ebb..0x0271ba |
Mandelbrot_palette |
| 14 | 0x13e0 |
0x0271bb..0x030833 |
Mental_D_logo_by_NiK |
| 15 | 0x1420 |
0x030834..0x0366a7 |
mentality_logo_by_Nik |
| 16 | 0x1460 |
0x0366a8..0x038f04 |
presents_logo_by_NiK |
| 17 | 0x14a0 |
0x038f05..0x039204 |
The_sides_palette |
| 18 | 0x14e0 |
0x039205..0x047278 |
Exterminate_mod_by_Dune |
| 19 | 0x1520 |
0x047279..0x05ca7a |
Another_MOD_by_Dune |
The visual parts are normal MZ programs after carving and unpacking. Restored image sizes:
P00 Part_Loader 31350 bytes
P01 VTextMorpher_by_Moleql 78769 bytes
P02 Intro_by_Wizard 32348 bytes
P03 interferance_by_Moleql 14949 bytes
P04 Ifs_by_Wizard 86136 bytes
P05 Many_faced_glenz_by_Moleql 13597 bytes
P06 Fractal_zoomer_by_Wizard 43716 bytes
P07 texture_cubes_by_Moleql 271049 bytes
P08 End_scroller_by_Wizard 44836 bytes
P09 setup_for_shit 3350 bytes
P10 Command_line_parser 10814 bytes
Restored image hashes:
429a48f68cb42e43d188224e7146652592cc5ce4850312f9fdc055cfa02db703 P00.EXE
a2381d8d6cddfb74f517eb98329e7c8620cc500f6ce72e74f237741bce9983d7 P01.EXE
d59e5af6f7ed55aa0b5d842bb842ce61119f568ef340c1e598498022a22b0160 P02.EXE
21055275c8594b22c12dccb4445dc12150d7c7938719a208d57d875747a3f620 P03.EXE
8972d9da71a39317d5b4bbc364d2319ccc306d0bc64804e7c45842468502d44f P04.EXE
06386c5fb841440889d7022799c78cabbb41d4902fefc98ae626cb241d1b40c4 P05.EXE
d191416a22b85be2e25cb1d5c6099a0886fdc530b4727f7f5694477c648802aa P06.EXE
92ceb5fc3cd96db198341d8451d003aa35593b84249e4251da910ce6e46747a1 P07.EXE
10f770f8cb10a876eeea38a0a441d343500e3791991d84fe3f3d2413afcbcc17 P08.EXE
fcd0d24b85088fcd18506bba1651a40ec976acc0a678741ea68826f79ce37ada P09.EXE
11b8d730d65f0479e633179d6824b875504aa827a6a26b2d02f767300c302504 P10.EXE
Loader, Setup, And Command Parser
The Part_Loader image is the coordinator. It checks the EXOS INT FF
service, checks available conventional memory, checks for a 386, detects or
configures sound, and measures machine speed. Several strings line up with its
branches:
requires about 500 KB
please wait 5 seconds...
CPU speed index
Video speed index
Memory speed index
Please do not use any V86 - memory managers!
could not detect Sound Blaster
The speed test is not cosmetic. The fractal zoomer later queries the same
service state and chooses lower detail or tweaked resolutions from the measured
CPU/video/memory indexes. /SPEED exists because a user could override those
indexes if the detection gave poor choices.
The loader also contains tracker/channel markers:
FLT8
6CHN
FLT4
Those are consistent with a module player that must handle both old four- channel and expanded formats. The demo ships two MOD assets in the EXOS table, so the loader is effectively a tiny demo shell plus a music setup tool.
setup_for_shit is the small sound setup front-end. It allows:
no sound
Covox on LPT1 or LPT2
Honker
Sound Blaster
Sound Blaster Pro
port / DMA / IRQ / frequency choices
Command_line_parser is a small C-built helper. Its option strings match the
NFO switches:
/DOTWEAK
/NOSOUND
/SHOWSPEED
/SPEED=%x,%x,%x
/SP=%x,%x,%x
The parser writes compact flags or numeric overrides for the loader. The visual parts do not all parse their own command lines; they rely on EXOS/shared state.
Part 01: VTextMorpher By Moleql
The text morpher starts at image offset 0x12fe0. It is a mode-13h particle
glyph morph. The effect looks like text whose letter pixels dissolve and
reassemble into the next text, but the implementation is not a high-level
vector font. It is a point-list transformer:
set video mode 13h
set DS/ES to the data segment at 0200h
translate script bytes through an alphabet table
build source pixel coordinate list
build target pixel coordinate list
resample both lists to the same point count
for each phase, interpolate source -> target
plot interpolated points to an offscreen segment
copy offscreen image to A000h
The script mapping step reads text bytes at 0x8e5c, maps them through an
alphabet table at 0x8f4d, and writes symbol IDs back in place. The inner
effects therefore work on compact glyph indices rather than ASCII.
The clear stage prepares two buffers:
segment 0b2eh: clear 0xe10 dwords ; displayed point field
segment 0c08h: clear 0x640 dwords ; temporary/glyph work
The important builder is around 0x13259. It scans glyph bitmaps twice. First
it walks the source glyph pixels by column and row. Every nonzero source pixel
is stored as a byte offset in a list at 0x2508.
Then it resamples that list into another list at 0x6b08:
accumulator = 0xf740
for each wanted output point:
accumulator += source_pixel_count
if carry or threshold reached:
advance source pointer
output selected source offset
The exact constants are code-specific, but the purpose is clear: a glyph with few lit pixels and a glyph with many lit pixels must still morph with a stable number of points. Instead of drawing missing pixels or deleting extra pixels at the end, the code stretches or decimates the source list up front.
The second pass scans the target glyph. It stores target (x,y) pairs through
the same temporary list, then resamples the target into 0x4808. Finally it
converts the source byte offsets back to (x,y) and subtracts source positions
from target positions, producing per-point deltas at 0x7c88:
source_points[i] = (source_x, source_y)
target_points[i] = (target_x, target_y)
delta[i] = target_points[i] - source_points[i]
The frame interpolator at 0x13163 is the hot loop. It handles 0x8c0 points:
phase = byte [0x8e08]
for i in 0..0x8bf:
x = source_x[i] + ((delta_x[i] * phase) >> 6)
y = source_y[i] + ((delta_y[i] * phase) >> 6)
screen_offset[i] = y * pitch + x
The shift by 6 means the phase space is effectively 0..64-ish rather than 0..255. Multiplication is done per point, but the list is small enough for a 386/486, and the display copy is just a compact block.
The plot loop at 0x131a7 then writes the points:
color = phase + 1
for i in 0..0x8bf:
offscreen[screen_offset[i]] = color
The display loop at 0x131df copies 0xe10 dwords from the offscreen segment
to A000h. Palette handling is separated:
0x131c2 load/update a palette ramp from timeline pointer 0x8e5a
0x13356..0x13393 fade loop; BL descends from 0x3e by two
0x13396..0x133a6 retrace wait around the DAC update
The main timing loop waits about 0x78 retraces between larger phases, clears
old ranges, then rerenders with the new point positions. The expensive work is
the one-time source/target list build; each animated frame only does fixed-point
interpolation, point plotting, a block copy, and a DAC ramp.
Part 02: Intro By Wizard
The intro is a C-runtime-backed program with several small hand-coded VGA helpers. It is less self-contained than the Moleql parts; the useful code is in the helpers rather than a single obvious renderer.
The retrace waits:
0x0f21 wait while vertical retrace is active
0x0f40 wait until vertical retrace becomes active
The split-screen/line-compare routine at 0x0f5f writes CRTC register 0x18
and the overflow bits:
CRTC[18h] = line & 0xff
CRTC[07h].bit4 = line bit 8
CRTC[09h].bit6 = line bit 9
That is the standard VGA line-compare mechanism. It makes the VGA address generator wrap or split at a programmed scanline, so one part of the screen can scroll or page independently of another.
The start-address routine at 0x0fab computes:
start_address = line * 0x50
0x50 is 80 bytes per scanline, the natural byte pitch for an unchained
320-wide planar display. The code writes the high and low start address bytes
to CRTC registers 0x0c and 0x0d.
The planar copy helper around 0x0fe1 is the normal four-plane Mode X upload:
for mask in 1, 2, 4, 8:
Sequencer[02h] = mask
copy 80-byte spans for that plane into A000h
The helper at 0x12a3 is the map-mask primitive:
out 3c4h, 02h
out 3c5h, mask
Palette setup is split between Attribute Controller writes and BIOS palette services:
0x124c..0x1289 Attribute Controller palette/control setup
BIOS AX=1012h bulk DAC palette load
The large routines at 0x2a00, 0x2aca, and 0x2b28 are C-runtime block
copy/fill primitives with segment-boundary handling. When they appear in the
intro call graph, they usually mean "copy a large planar/logo block" rather
than an original effect algorithm.
Part 03: Interference By Moleql
The interference part is a compact planar polygon effect. It uses mode 0Dh,
not plain chunky mode 13h. That gives a 320x200-ish EGA/VGA planar model where
each plane is selected with the Sequencer map mask and pixels are addressed by
bit inside a byte.
The entry at 0x2fd0 does:
shrink DOS memory block
set video mode 0dh
allocate/clear several work buffers
load two palettes through BIOS 1012h
run palette interpolation
enter transformed polygon loop
The buffer clear loop initializes eight blocks:
for block in 0..7:
clear 0x1668 dwords
segment += 0x059a
That layout is a good hint that the effect maintains several frame or edge buffers outside A000h and then flips/copies only what is needed.
Face Assembly And Culling
The face builder at 0x31a3 creates 36 polygon records from a vertex pointer
table. It copies x/y/z-like values from three referenced vertices and stores a
compact face record.
The culling test at 0x31ee..0x3236 is the classic signed-area test:
a = (x2 - x1) * (y3 - y1)
b = (x3 - x1) * (y2 - y1)
if a < b:
keep face
else:
reject face
Only visible faces are copied to the render list, and the visible count is
stored at 0x0adc. There is no z-buffer here. The effect depends on object
ordering, backface rejection, and simple filled spans.
Transform And Projection
0x3237..0x336a is the fixed-point transform/projection block. It uses 32-bit
matrix terms around 0x0d3c..0x0d50:
tx = (x * m00 + y * m01 + z * m02) >> 9
ty = (x * m10 + y * m11 + z * m12) >> 9
tz = (x * m20 + y * m21 + z * m22) >> 9
screen_x = center_x + perspective(tx, tz)
screen_y = center_y + perspective(ty, tz)
The actual code is register-tight: imul, 32-bit intermediates, arithmetic
shift by 9, then a divide-like projection by depth plus constants. It stores
projected (x,y,depth) values back into face records.
0x336b..0x3407 advances the phase/matrix values. It indexes sine tables in
wrapped windows around 0x11a0 and 0x181e. In other words, the object motion
is table-driven; the render loop is not evaluating trig functions live.
Triangle Sort And Span Fill
0x3408 sorts triangle vertices by Y. The next block,
0x3494..0x376b, is a dual-edge DDA/Bresenham scan converter. It builds left
and right x endpoints for each scanline:
sort vertices by y
walk long edge from top to bottom
walk top short edge, then bottom short edge
for each y:
edge_table[y].left = min(xa, xb)
edge_table[y].right = max(xa, xb)
The span drawer at 0x376b..0x37f4 writes into planar VGA memory. The byte
address is:
byte_offset = y * 40 + (x >> 3)
bit_mask = 0x80 >> (x & 7)
Start and end bytes need masks; the middle of a long span can be whole bytes:
mask start byte
if middle_count > 0:
rep stosb or rep stosw full bytes
mask end byte
The code uses OR writes into the selected plane. This is why the part can draw sharp planar filled polygons without multiplying by 320 or touching every pixel individually.
Page Flip And Dirty Clear
The flip state is a byte at 0x27c7. The code alternates between A000h and an
offset page:
if flip:
display base = A000h + 0200h-style offset
else:
display base = A000h
write CRTC start address
clear previous dirty y range with rep stosd
The part is careful about clearing only the previous working area rather than blindly clearing a whole 64 KB VGA aperture every frame.
Part 04: IFS Morpher By Wizard
The IFS part is the most mixed C/assembly image in the set. It contains the string:
IFS Morpher ver 1.5 by Wizard 1993 (Cver:1.3 ASMver 1.4)
The user-facing command text says:
ifs [frames] [detail]
The C startup enters real main through a far call to 0045:000c, which maps to
image offset 0x45c. The immediate startup and control code is C-like and uses
runtime helpers, but the important visual loops are handwritten.
Palette And Timing Helpers
The core support routines:
0x3b42 wait retrace, then write count*3 DAC bytes through 3c8h/3c9h
0x3ba8 BIOS AX=1012h bulk palette load
0x3bf4 BIOS AX=1010h set one DAC register
0x3c50 set video mode if not already in that mode
0x3dac wait for full retrace active/inactive cycle
0x3c6e reads the RTC seconds register through CMOS ports 70h/71h, converts
BCD to decimal, and returns a second value. That is used for frame pacing and
calibration, not for randomness.
0x3d94 wraps EXOS INT FF:
AX = 0003h
BX = query_argument
INT FFh
return CX
That is how the part asks the resident shell for settings.
Scaler / Copy Helper
0x3ca2..0x3d8f is a byte-repetition scaler. It fills a temporary line from a
source byte stream, then copies 320-byte rows to A000h:
for each output row:
for each source byte:
repeat byte horizontal_scale times into temp line
copy 320 bytes from temp line to video
This is a simple but effective way to show a lower-resolution image or generated field at full screen width without doing a multiply or divide for every output pixel.
Four-Plane Strip Helper
0x3dc6 draws a 40-byte wide strip into planar VGA:
for mask in 1, 2, 4, 8:
set Sequencer map mask to mask
copy one 40-byte row span into A000h
The 0x3e60 helper is the map-mask setter used by this and other code.
IFS Point Plotter
The handwritten point-cloud loop at 0x3f38..0x3fd1 is the core. It loads four
segment bases into DS, ES, FS, and GS, plus per-transform offsets from a
table. Then it plots 320 points per invocation:
bp = 0x0140
while bp != 0:
read coordinate/transform data from four segment banks
add/subtract terms into a new point position
choose next transform index using changing input/state
write one byte to the destination segment
bp--
The unusual part is the segment-register use. Instead of keeping all IFS state in one flat structure, the code uses separate real-mode segments as coordinate or transform banks. That lets address calculations stay short:
mov ax, ds:[si+offset]
add ax, fs:[di+offset]
sub ax, gs:[bx+offset]
...
mov es:[screen_offset], al
This style is very 386 DOS: segment registers are treated almost like extra base registers. It is fast once the tables are laid out, but brittle if a memory manager leaves FS/GS in an unexpected state.
Table Builder
0x3fd2..0x4126 builds the tables consumed by the point plotter. It has two
distinct phases:
build transform selection table:
for each transform weight:
emit repeated words
AX += 0x000c per transform slot
build coordinate tables:
for y/x domains:
use fixed-point accumulators
imul scale terms
shift down
store words for plotter
The first phase turns transform weights into a fast lookup table. The second phase precomputes coordinate products so the hot plotter can use additions and indexed loads instead of doing all multiplications per plotted point.
Fade / Mask / Page Maintenance
0x4127 combines vertical timing, palette upload, and screen decay:
wait retrace
write 0x300 DAC bytes
set graphics controller bit mask
for 0x3e80 dwords in A000h:
screen_dword &= inverse_repeated_byte_mask
restore graphics controller state
That gives a cheap fade/decay pass over the current screen. It is not blending source and destination; it is masking bits out of the planar image.
0x4185..0x41e8 performs a planar deinterleave copy. It copies every fourth
byte in four passes, then restores VGA chain/bit-mask settings. This turns a
linear prepared image into the four VGA planes.
0x41e9..0x424b installs and removes an INT 8 handler. The handler decrements a
counter at cs:0x3d7, reloads it when it reaches zero, and chains to the old
timer. This is the part's local pacing hook.
0x4256..0x42c2 is a stranger-looking CRTC wipe/clear:
unlock CRTC register 11h
for each column-like step:
wait retrace
write CRTC start address 0ch/0dh
clear one dword per scanline with DI += 0x13c
Because it changes the display start and clears a sparse pattern, it behaves like a vertical-column or rolling wipe rather than a simple full-screen clear.
Part 05: Many-Faced Glenz By Moleql
The glenz part is a smaller sibling of the interference renderer. It enters at
0x2d90, sets mode 0Dh, sets a palette, expands pointer tables, then runs a
planar double-buffered 3D loop.
The main frame setup alternates between two A000 pages:
page A base: A000:1f4h-ish
page B base: A000:5f4h-ish
set Sequencer map mask = 0x0f
clear 0x7d0 dwords
The script stream begins near ds:0x652. A value of 0x0190 acts as the end
marker.
The CRTC start address is computed as value * 40:
start = (value << 3) + (value << 5)
That is a multiplication by 8 plus 32, which equals 40 bytes per planar
scanline. One branch also adds 0x40, giving the alternate page/line phase.
Transform And Projection
0x2f7e..0x30c8 is the object transform:
load angles/phases
index sine tables around 0x1cd8
for each vertex:
rotate with 32-bit fixed-point products
perspective divide by (z - 0x150)
screen_x = 0x55 + projected_x + horizontal_phase
screen_y = 0x64 + projected_y
The constants center the object in the planar display area. The use of
z - 0x150 means the object is biased in front of the camera and then projected
with a reciprocal/divide-like step.
Face Records And Culling
0x2efa..0x2f7d builds 0x90 face records. Each face is tested with another
signed-area expression:
visible = ((x2-x1)*(y3-y1) - (x3-x1)*(y2-y1)) has desired sign
Visible records are kept for scan conversion. The glenz look comes from drawing many overlapping translucent-ish planar faces into the same bitplanes/palette, not from a z-buffer.
Span Filler
0x312d..0x34ea sorts triangle vertices and builds spans. The final writer at
0x349d..0x34ea is the tight planar span loop:
byte = y * 40 + (x >> 3)
left_mask = 0xff >> (x_left & 7)
right_mask = 0xff << (7 - (x_right & 7))
or first byte with left_mask
if whole bytes in the middle:
rep stosw for pairs
maybe stosb for odd byte
or last byte with right_mask
This is the classic reason mode 0Dh and Mode X style effects were still
attractive: spans can be wide, but the memory traffic is one byte per eight
horizontal pixels per plane, with only edge masks requiring special handling.
Retrace waits at 0x3507 and 0x3512 bracket the display update.
Part 06: Fractal Zoomer By Wizard
The fractal zoomer is the best recovered inner-loop specimen in the package. It is C startup plus a handwritten Mandelbrot renderer that self-patches for the current output pitch and resolution.
The real main is reached by a far call to 0127:000c, image offset 0x127c.
It initializes a default 320-wide view:
center-ish values: 0xa0, 0xc8
visible width: 0x0140
visible height: 0x00c8
destination segment: A000h
working pitch: 0x0140
default detail term: 0x0064
It then queries EXOS settings through the wrapper at 0x2bb8 (AX=0003h,
INT FFh) and chooses detail/resolution variants. The code contains setups
matching:
320 x 200 style: width 0x140, height 0x0c8, pitch 0x140, detail 0x64
320 x 100 style: height 0x064, work height 0x0c8, detail 0x32
224 x 152 style: width 0x0e0, height 0x098, dest A000:01e3, detail 0x4c
wide/doubled work: work width 0x280 for duplicated output rows/pixels
The /DOTWEAK flag exists for these lower/tweaked modes. The VGA setup helpers
at 0x2a09 and 0x2ae7 program mode 13h and then rewrite CRTC/Sequencer
registers:
CRTC[00h] = 2dh
CRTC[01h] = 27h
CRTC[02h] = 28h
CRTC[03h] = 90h
CRTC[04h] = 2bh
CRTC[05h] = a0h
CRTC[09h] = c1h
Sequencer[01h] = 09h
One setup writes seven CRTC records, the other six. Both unlock CRTC register
11h first. The intent is to adjust timing/scanline behavior for the fractal
output, not just enter vanilla BIOS mode 13h.
Renderer Self-Patching
The renderer segment starts at 02d4:0000, image offset 0x2d40. At startup
it patches many immediates in its own code:
patch offsets: 0x033b, 0x0380, 0x03b2, ...
patch values: pitch, 2*pitch, 3*pitch, 4*pitch-like row deltas
scratch terms: cs:06e8, cs:06ec, cs:06f0, cs:06f6, cs:06ee
That is a deliberate 386 trick. A normal resolution-independent loop would do:
dest = y * pitch + x
or add a variable pitch loaded from memory. This renderer instead rewrites the instruction constants so the hot path can use immediate displacements:
mov es:[di + patched_row_delta], ax
The result is uglier to disassemble but faster in the actual inner loop.
Coordinate Table Builder
The setup at 02d4:019b, image offset 0x2edb, saves the destination/source
segments and fixed-point rectangle coordinates, clears a dirty/visited map with
rep stosd, then builds horizontal and vertical coordinate tables:
horizontal table: cs:68e0
vertical table: cs:6de0
x_acc += x_step
y_acc += y_step
adc/carry handles the fractional side
store 32-bit fixed-point coordinate components
The renderer is therefore not recomputing complex-plane coordinates from screen positions with division. It walks precomputed fixed-point rows and columns.
Sparse Line Renderer
0x2fc7..0x33dd is the main line renderer. For each row it selects source and
destination segments according to row * width. Outside the active fractal
rectangle it simply duplicates source bytes:
al = source_byte
ah = al
dest[current_line] = ax
dest[lower_line] = ax
Inside the fractal rectangle it uses FS as a dirty/visited bitmap. The key
test is:
bt fs:[bx], cx ; has this pixel/cell already been computed?
if carry set:
reuse/skip
btc fs:[bx], cx ; mark this cell
call Mandelbrot core
The output writes the same color into pairs and neighboring rows:
al = mandelbrot_color
ah = al
es:[di] = ax
es:[di + patched_delta] = ax
...
Several unrolled blocks compute or fill neighboring pixels around the current cell. This is why the zoomer can cover a large area without calling the Mandelbrot core for every final screen pixel.
Mandelbrot Core
The escape-time kernel is at 0x35cf:
input:
EAX = c_x
EBX = c_y
CX = 0x00fa ; max iterations, 250
state:
x in ESI/EAX-style temporaries
y in EBX-style temporaries
loop:
x2 = fixed_mul(x, x)
y2 = fixed_mul(y, y)
if x2 + y2 > 0x08000000:
break
new_x = x2 - y2 + c_x
new_y = 2*x*y + c_y
x = new_x
y = new_y
CX--
return:
color = 0xfa - CX
The fixed multiply uses 32-bit imul and shld to keep the desired middle bits
of the product:
imul operand
shld edx, eax, 8 ; for square terms
shld edx, eax, 9 ; for doubled x*y term
The escape threshold 0x08000000 is the scaled radius-squared test. Returning
0xfa - CX gives a direct color index based on the iteration that escaped.
Interpolation / Hole-Fill Pass
0x365e..0x37cb is an important second pass. It scans the coarse/even grid and
fills missing pixels by comparing neighbors:
if left == right:
fill horizontal gap with same color
else:
middle = (left + right) / 2
if top == bottom:
fill vertical gap with same color
else:
middle = (top + bottom) / 2
center = (left + right + top + bottom) / 4
There are also short rep stosb runs when a region can be extended. The visual
goal is to hide the sparse sampling grid. The speed goal is more important:
many pixels become cheap interpolated colors instead of full 250-iteration
Mandelbrot calls.
EXOS File Wrappers
0x37ef..0x382c contains small INT FF wrappers with AX=0100h, 0101h, and
0102h. Those are likely open/read/close-style EXOS file services used for the
palette or image assets around the fractal part.
Part 07: Texture Cubes By Moleql
The texture cube image is by far the largest child. The restored image is about
271 KB because it includes substantial embedded texture/data blocks. The code
entry at 0x41570 sets DS/ES to 0x0080, waits retrace, copies prepared
buffers, expands point lists, and enters the cube loop.
The top-level frame loop at 0x415db..0x41639 is:
while frame < 0x04e2 and Esc not pressed:
update transforms ; 0x41e7a, 0x41d43, 0x41647
render into offscreen 09dfh ; 0x416b9
wait retrace ; 0x422be
copy offscreen to A000h ; 0x4184c
frame++
Visibility
0x41647 culls faces before drawing. It reads projected vertex pairs and uses
the same signed-area idea as the other Moleql parts:
area = (x2-x1)*(y3-y1) - (x3-x1)*(y2-y1)
if area has visible sign:
copy 16-byte face record to visible list
visible_count++
The visible count is stored around 0x95cd.
Offscreen Buffer
0x416b9 clears the render target:
segment 09dfh
clear 0x2710 dwords
0x2710 dwords is 40000 bytes, exactly a 200x200 chunky work buffer. This is
one of the most useful clues in the whole part: it renders the cube into a
square chunky buffer, not directly into 320x200 A000h.
The copy-to-screen routine at 0x4184c confirms it:
DS = 09dfh
ES = A000h
for y in 0..199:
copy 0x32 dwords ; 200 bytes
destination += 0x78 ; skip 120 bytes
The 200-byte line is centered inside a 320-byte mode-13h row by starting at an
offset around 0x3c and skipping 120 bytes after every line.
Textured Line Inner Loop
The strongest draw loop is 0x4172c..0x41849. It draws textured lines/spans
into the 200x200 offscreen buffer. The destination address is computed from
y*200 + x. The multiplication is shift/add based:
y * 200 = y * (128 + 64 + 8)
= (y << 7) + (y << 6) + (y << 3)
Then it enters one of the major-axis cases. In pseudocode:
dx = x2 - x1
dy = y2 - y1
if abs(dx) >= abs(dy):
walk x, update y/error occasionally
else:
walk y, update x/error occasionally
for each destination pixel:
texel = ds:[si]
es:[di] = texel
sometimes es:[di + 0x00c7] = texel
advance texture pointer/error terms
The +0x00c7 write is almost exactly one row minus one byte in the 200-wide
buffer (199). In practice it thickens or interpolates along diagonal/vertical
edges by touching a neighboring row/column. The code is tuned for the visual
texture-cube look, not for a general-purpose polygon API.
Transition / Slice Copy
0x41f4c..0x42052 alternates between buffers at 0x1ce7 and 0x5527, clears
the offscreen square, and reveals/scales lines based on a state byte at
ds:0x138. It ends with the same 200-byte-line copy to A000h. This is likely
the transition around the cube sequence rather than the cube mapper itself.
Edge List Polygon Filler
0x42055..0x42220 builds scanline edge lists at 0x01a0. The edge accumulator
at 0x42102..0x4221f is Bresenham-like:
for each edge:
y = y_start
error = initial_error
while y != y_end:
append x to edge_bucket[y]
error += dx
if error crosses threshold:
x += x_step
error -= dy
y++
0x42220..0x422bb fills spans from the bucket pairs:
for each scanline:
read x pairs
if pair count is special/singleton:
draw short case
else:
sort or choose left/right
count = abs(right - left)
rep stosb color_byte
The color byte comes from around 0x95e8. This block appears to handle flat
filled transition geometry or face masks rather than the main textured-line
inner loop.
The retrace wait is at 0x422be.
Part 08: End Scroller By Wizard
The end scroller enters at 0xab70. It sets DS to 0x06cb, ES to A000h,
calls setup at 0xae8a, and loads a BIOS palette with AX=1012h.
VGA Setup
0xae8a starts from BIOS mode 13h and then disables normal chunky chain
behavior:
set mode 13h
Sequencer[04h] = unchained/planar-oriented value
GraphicsController[05h/06h] adjusted
Sequencer[02h] = 0x0f
clear A000h
CRTC[14h] = 00h
CRTC[17h] = byte-mode/address value
CRTC[13h] = 40h
CRTC[13h] = 0x40 means the logical display width is 64 bytes per scanline in
the selected addressing mode. This gives the scroller enough virtual-screen
space for smooth rolling starts.
Frame Loop
The visible loop is:
DI = 0x6400
while active:
wait retrace ; 0xae11
frame_counter++
update CRTC start address ; 0xadf9
update rolling split/line compare ; 0xac80
draw one text line into line buffer ; 0xacbb
copy line through VGA planes ; 0xae23 / 0xae50
draw sine/raster strip ; 0xad67
Text Renderer
0xacbb..0xad66 is the font compositor. It reads script bytes from
0x0200 + scroll_pointer. Byte 0xfe resets the script.
Before drawing the glyphs, it computes the total text width:
width = 0
for each character:
glyph_index = xlat(character)
width += advance_table[glyph_index]
Then it clears a line buffer at 0x06b0:
clear 0x0960 dwords
For each character:
glyph_index = xlat(character)
glyph_base = glyph_index * 0x0261
for row in 0..0x1c:
copy 5 dwords from glyph bitmap row
destination += 0x012c
advance x by character spacing
0x261 bytes per glyph is not a power-of-two cell. The font is packed around
its actual row/width layout, and the multiplication chooses the glyph record.
Sine / Raster Strip
0xad67..0xadef builds a 320-byte strip from several waveform components:
clear 320-byte output line at 0x387c
for each component:
phase += speed
sine = table[0x2c30 + ((phase >> 15) & 0x7fe)]
contribution = sine * amplitude
add contribution into 32-bit accumulator line
for x in 0..319:
byte = high_byte(accumulator[x] + scroll_phase)
output[x] = byte
The sine values are word-sized, the accumulators are 32-bit, and the final byte uses the high part after adding a global phase. That produces a smooth rolling shade/strip with several independent wave components.
Planar Copies
The opaque planar copy at 0xae23 writes one fourth of the source bytes per
plane:
source_base = line_buffer
for mask in 1, 2, 4, 8:
Sequencer[02h] = mask
SI = source_base
CX = source_count / 4
copy every fourth byte to A000h
source_base++
The transparent version at 0xae50 is the same idea, but it skips zero source
bytes so the glyphs can overlay the background without clearing all pixels.
The scroll-start routine at 0xadf9 computes:
start = frame_counter << 7
CRTC[0dh] = low(start)
CRTC[0ch] = high(start)
The line-compare routine at 0xaef1 writes CRTC 0x18 and the overflow bits in
0x07 and 0x09, just like the intro helper. The end part therefore combines
a virtual screen scroll with a split/line-compare boundary.
The fade-out at 0xac53..0xac79 clears a buffer and runs about 0xc9 frames,
giving the end sequence a controlled exit rather than a hard mode reset.
Cross-Part Observations
The most important thing about Mentality is that it is a containerized trackmo made of small specialized executables, not one giant uniform engine. The parts share EXOS services and broad VGA idioms, but the inner loops are very different:
VTextMorpher: resampled glyph point lists, per-point fixed interpolation
Interference: mode-0Dh planar triangle spans with bit masks
IFS Morpher: C control layer plus segment-bank point plotter
Many-faced glenz: compact planar 3D face renderer
Fractal zoomer: self-patched sparse Mandelbrot renderer plus interpolation
Texture cubes: 200x200 chunky work buffer and centered copy to A000h
End scroller: unchained VGA text compositor, sine strip, CRTC scroll/split
That also explains why the code can feel uneven when disassembled. Wizard's parts often use C startup code and helper routines around very specific assembly kernels. Moleql's parts tend to be smaller and more direct: fixed tables, visible-face lists, and tight planar span loops.
The strongest single inner loop is the fractal zoomer's Mandelbrot path because it combines several optimizations at once:
precomputed complex-coordinate tables
self-patched pitch constants
dirty bitmap in FS
sparse sample grid
unrolled pair/row duplication
post interpolation for missing pixels
250-iteration fixed-point Mandelbrot core only where needed
The most characteristic VGA trick is in the end scroller and intro: CRTC start address plus line compare. That gives moving or split screen regions without copying the whole frame. The Moleql parts, by contrast, lean on the older planar span advantage: one byte can represent eight horizontal pixels in a selected plane, so filled polygons can be surprisingly cheap if the edge masks are handled carefully.
Mentality is therefore less about one reusable engine and more about a bundled set of effect-specific kernels held together by EXOS. That is exactly what the internal file table shows: named executables, named assets, named palettes, and two module files, all treated as resources by a small demo operating layer.