<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.sizecoding.org/index.php?action=history&amp;feed=atom&amp;title=Essence</id>
		<title>Essence - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.sizecoding.org/index.php?action=history&amp;feed=atom&amp;title=Essence"/>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Essence&amp;action=history"/>
		<updated>2026-05-03T23:25:25Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.27.0</generator>

	<entry>
		<id>http://www.sizecoding.org/index.php?title=Essence&amp;diff=369&amp;oldid=prev</id>
		<title>Trixter: Created page with &quot;Category:Case Study  Essence by Hellmood  {{#ev:youtube|https://youtu.be/JqQbv12Dp9g}}  As you might have guessed, real path tracing and lighting is (yet) impossible in 64...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.sizecoding.org/index.php?title=Essence&amp;diff=369&amp;oldid=prev"/>
				<updated>2019-11-03T05:18:36Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;a href=&quot;/wiki/Category:Case_Study&quot; title=&quot;Category:Case Study&quot;&gt;Category:Case Study&lt;/a&gt;  Essence by Hellmood  {{#ev:youtube|https://youtu.be/JqQbv12Dp9g}}  As you might have guessed, real path tracing and lighting is (yet) impossible in 64...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Case Study]]&lt;br /&gt;
&lt;br /&gt;
Essence by Hellmood&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|https://youtu.be/JqQbv12Dp9g}}&lt;br /&gt;
&lt;br /&gt;
As you might have guessed, real path tracing and lighting is (yet) impossible in 64 bytes of assembler ;) but still, it's at least possible to generate the impression of both.&lt;br /&gt;
&lt;br /&gt;
Code:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=nasm&amp;gt;&lt;br /&gt;
; &amp;quot;Essence&amp;quot; - by HellMood/DESiRE - 5th October 2019&lt;br /&gt;
; 64 bytes msdos intro, showing animated raycasted objects&lt;br /&gt;
; with fake pathtracing and fake lighting while playing&lt;br /&gt;
; ambient MIDI sound, which is coded for DosBox 0.74.&lt;br /&gt;
; On a real MsDos or FreeDos, the demo will work&lt;br /&gt;
; but no sound will be played unless a MIDI capable&lt;br /&gt;
; soundcard is present. On Dosbox, a custom configuration&lt;br /&gt;
; is needed, to provide sufficient emulation power and&lt;br /&gt;
; enable the MIDI UART mode, which saves a few bytes.&lt;br /&gt;
; --------------------------------------------------------------&lt;br /&gt;
; released at https://deadline.untergrund.net/2019/&lt;br /&gt;
; published at https://www.pouet.net/prod.php?which=83204&lt;br /&gt;
; see also : http://www.sizecoding.org/wiki/Main_Page&lt;br /&gt;
; assemble with &amp;quot;nasm.exe&amp;quot; &amp;lt;this&amp;gt; -fbin -o &amp;lt;this&amp;gt;.com&lt;br /&gt;
; --------------------------------------------------------------&lt;br /&gt;
; Set ES to the screen, to perform the &amp;quot;Rrrola Trick&amp;quot;, see&lt;br /&gt;
; http://www.sizecoding.org/wiki/General_Coding_Tricks&lt;br /&gt;
push 0x9FF6&lt;br /&gt;
pop es&lt;br /&gt;
; Set mode to 0x13, +0x80 means not deleting the screen content&lt;br /&gt;
; that is 320x200 pixels in 256 colors&lt;br /&gt;
mov al,93h&lt;br /&gt;
int 10h&lt;br /&gt;
; Setting port to MIDI data port, assuming it is in UART mode&lt;br /&gt;
; 0x3F has to be sent to 0x331 first, if UART mode is not on.&lt;br /&gt;
mov dx,0x330&lt;br /&gt;
; Effectively outputting all the code to the MIDI data port.&lt;br /&gt;
; CX=255 at start, DS=CS, SI=0x100, see MIDI section below.&lt;br /&gt;
rep outsb&lt;br /&gt;
; Setting DS to zero, top stack normally contains the return&lt;br /&gt;
; adress. DS is needed to be 0 to access a timer later on.&lt;br /&gt;
pop ds&lt;br /&gt;
; CL is the iteration count for a ray, CH is 0 all the time.&lt;br /&gt;
; The value is chosen to generate a blue background texture.&lt;br /&gt;
; Chosing 64 instead would lead to a totally black background &lt;br /&gt;
X: mov cl,63&lt;br /&gt;
; BL is the current depth of a ray, we start with minus(!) 64.&lt;br /&gt;
; We cast rays in negative direction to calculate the point&lt;br /&gt;
; in 3D and the texture color at the same time. if a ray hits&lt;br /&gt;
; an object from this side, the object function has a reasonable&lt;br /&gt;
; texture value, from the other side it would be always black.&lt;br /&gt;
; CL, BL are decoupled because decrementing -128 leads to 127&lt;br /&gt;
; and since we are using signed multiplication for keeping things&lt;br /&gt;
; centered, that would result in very buggy and ugly behaviour.&lt;br /&gt;
; They are also decoupled because of visual beauty: because of&lt;br /&gt;
; the usage of signed 8 bit coordinates, objects close to the&lt;br /&gt;
; projection center are way too coarse and move way too fast.&lt;br /&gt;
mov bl,-64&lt;br /&gt;
; At this point, AL contains the color of the previous pixel.&lt;br /&gt;
; By design of the object formula, the last 4 bits contain the&lt;br /&gt;
; texture value while the 5th bit is always set, which maps it&lt;br /&gt;
; to the 16 color gray scale subtable of the VGA default&lt;br /&gt;
; colors. Other bits may be set, too, so they are masked.&lt;br /&gt;
; https://www.fountainware.com/EXPL/vga_color_palettes.htm&lt;br /&gt;
; Simultaneously, the object function, in combination with the&lt;br /&gt;
; palette subset, creates the impression of lighting from the&lt;br /&gt;
; front top left. The right, bottom and back side appears to&lt;br /&gt;
; be black. Changing the object formula will result in&lt;br /&gt;
; changing the texture, visibility and lighting as well.&lt;br /&gt;
and al,31&lt;br /&gt;
; Outputting the pixel on the screen and increment pointer&lt;br /&gt;
stosb&lt;br /&gt;
; Instead of going pixel by pixel, the following jumps&lt;br /&gt;
; Pseudorandomly across the screen, this smoothes the&lt;br /&gt;
; animation a lot and looks a bit like pathtracing.&lt;br /&gt;
imul di,byte 117&lt;br /&gt;
; The inner loop for each ray, decrementing BX means&lt;br /&gt;
; advancing the ray in negative direction by 1&lt;br /&gt;
L: dec bx&lt;br /&gt;
; Assign the Rrrola constant to register AX&lt;br /&gt;
mov ax,0xcccd&lt;br /&gt;
; Place the signed coordinates X and Y into DL and DH&lt;br /&gt;
mul di&lt;br /&gt;
; Centering for X is implicitly done by offsetting the segment&lt;br /&gt;
; Centering Y has to be done &amp;quot;manually&amp;quot;. any value can be used&lt;br /&gt;
; as long as it doesn't show the signed overflow on screen.&lt;br /&gt;
mov al,dh&lt;br /&gt;
sbb al,73&lt;br /&gt;
; Multiply AL=Y by the current distance, to get a projection(1)&lt;br /&gt;
imul bl&lt;br /&gt;
; Get X into AL, while saving the result in DX (DH)&lt;br /&gt;
xchg ax,dx&lt;br /&gt;
; Multiply AL=X by the current distance, to get a projection(2)&lt;br /&gt;
imul bl&lt;br /&gt;
; Considering an implicit division by 256, the projected &lt;br /&gt;
; coordinates now reside in DH and AH, while the depth is in BL.&lt;br /&gt;
; the following sequence calculates whether the current 3D&lt;br /&gt;
; position belongs to an object. Objects are normal cubes&lt;br /&gt;
; defined by f(X,Y,Z) = (X &amp;amp; Y &amp;amp; Z &amp;amp; 16 != 0)&lt;br /&gt;
mov al,dh&lt;br /&gt;
; offset X by timer, effectively producing 18.2 FPS&lt;br /&gt;
; http://vitaly_filatov.tripod.com/ng/asm/asm_002.29.html&lt;br /&gt;
add ah,[0x46c]&lt;br /&gt;
and al,ah&lt;br /&gt;
and al,bl&lt;br /&gt;
test al,16&lt;br /&gt;
; the inner loop is done when either the iteration count has&lt;br /&gt;
; reached zero or the function f(X,Y,Z) is true (object hit)&lt;br /&gt;
loopz L&lt;br /&gt;
; the outer loop repeats endlessly&lt;br /&gt;
jmp short X&lt;br /&gt;
; MIDI Data Section, actually code above and memory below is&lt;br /&gt;
; sent to the MIDI data port as well, but it does not matter&lt;br /&gt;
db 0xc0 ; set instrument on channel 0 to the next value&lt;br /&gt;
db 89   ; instrument 89 = Pad2 of general MIDI&lt;br /&gt;
db 0x90 ; play notes on channel 0, minor chord over 4 octaves&lt;br /&gt;
db 28   ; note 1, very deep&lt;br /&gt;
db 127  ; volume 1, maximum value to let the subwoofers shake&lt;br /&gt;
db 59   ; note 2 fitting to note 1  &lt;br /&gt;
db 80   ; volume 2, a bit reduced to not overshadow the bass&lt;br /&gt;
db 67   ; note 3 fitting to notes 1 &amp;amp; 2&lt;br /&gt;
db 65   ; volume 3, even more reduced to fit the other notes&lt;br /&gt;
;      #                   ´                           #&lt;br /&gt;
;      #                   greetings                   #&lt;br /&gt;
;      #     sensenstahl,homecoded,rrrola,frag,T$      #&lt;br /&gt;
;      #     Optimus,Trixter,igor,gentleman,VileR      #&lt;br /&gt;
;      #     Whizart,g0blinish,Rudi,ryg,TomCat    .    #&lt;br /&gt;
;      #     orbitaldecay,wysiwtf,Kuemmel,p01,Lara     #&lt;br /&gt;
;      #     Oscar Toledo,Drift,maugli,Harekiet,etc    #&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Trixter</name></author>	</entry>

	</feed>