<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'tunnel' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'tunnel' posted on the 'Assembly Code Share' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 16:40:04 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 16:40:04 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/115289/tunnel/</link>
      <description>;	simple tunnel-effect in real mode. for tasm. (use tlink/t)&lt;br /&gt;
;	by brewski&lt;br /&gt;
;	(brewski@graffiti.net)&lt;br /&gt;
;&lt;br /&gt;
;     Will assemble below 256 bytes, don't remember&lt;br /&gt;
;     it's old stuff...perhaps fun for someone?-Make it smaller =)&lt;br /&gt;
;&lt;br /&gt;
;&lt;br /&gt;
&lt;br /&gt;
.MODEL TINY&lt;br /&gt;
.386&lt;br /&gt;
.CODE&lt;br /&gt;
IDEAL&lt;br /&gt;
ORG 0100h&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
START:&lt;br /&gt;
&lt;br /&gt;
mov al,13h	;		assume ah=0&lt;br /&gt;
int 10h&lt;br /&gt;
&lt;br /&gt;
mov ax,cs&lt;br /&gt;
mov ds,ax	;	codesegment is datasegment&lt;br /&gt;
add ah,10h&lt;br /&gt;
mov es,ax	;	ugly texture&lt;br /&gt;
add ah,10h&lt;br /&gt;
mov fs,ax	;	u tunnel coordinates&lt;br /&gt;
add ah,10h&lt;br /&gt;
mov gs,ax	; 	v tunnel coordinates&lt;br /&gt;
add ah,10h&lt;br /&gt;
mov [offscreen],ax	;	offscreen buffer for later use&lt;br /&gt;
&lt;br /&gt;
mov dx,3c8h&lt;br /&gt;
xor al,al&lt;br /&gt;
out dx,al&lt;br /&gt;
inc dx&lt;br /&gt;
mov cx,256&lt;br /&gt;
xor al,al&lt;br /&gt;
@@black:&lt;br /&gt;
out dx,al&lt;br /&gt;
out dx,al&lt;br /&gt;
out dx,al&lt;br /&gt;
inc al&lt;br /&gt;
loop SHORT @@black&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
xor di,di&lt;br /&gt;
xor bx,bx&lt;br /&gt;
@@texture:&lt;br /&gt;
mov al,bl&lt;br /&gt;
xor al,bh&lt;br /&gt;
stosb&lt;br /&gt;
dec bl&lt;br /&gt;
jne SHORT @@texture&lt;br /&gt;
dec bh&lt;br /&gt;
jne SHORT @@texture&lt;br /&gt;
&lt;br /&gt;
calcTunnel:&lt;br /&gt;
&lt;br /&gt;
mov di,64000-1&lt;br /&gt;
mov cx,100&lt;br /&gt;
@rX:&lt;br /&gt;
mov bx,160&lt;br /&gt;
@@capl:&lt;br /&gt;
;		u = lowByteOf: (int)( 8192/Math.sqrt(i*i+j*j) )&lt;br /&gt;
mov [i],bx&lt;br /&gt;
mov [j],cx&lt;br /&gt;
finit&lt;br /&gt;
fild [constant1]&lt;br /&gt;
fild [i]&lt;br /&gt;
fmul st(0),st(0)&lt;br /&gt;
fild [j]&lt;br /&gt;
fmul st(0),st(0)&lt;br /&gt;
faddp st(1),st&lt;br /&gt;
&lt;br /&gt;
fsqrt&lt;br /&gt;
fdivp st(1),st&lt;br /&gt;
fistp [word ptr temp]&lt;br /&gt;
mov ax,[temp]&lt;br /&gt;
mov [fs:di],al&lt;br /&gt;
;		v = lowByteOf: (int)( atan2(i,j)*128/Math.PI )&lt;br /&gt;
fild [i]&lt;br /&gt;
fild [j]&lt;br /&gt;
fpatan&lt;br /&gt;
fimul [constant2]&lt;br /&gt;
fldpi&lt;br /&gt;
fdivp st(1),st&lt;br /&gt;
fistp [temp]&lt;br /&gt;
mov ax,[temp]&lt;br /&gt;
mov [gs:di],al&lt;br /&gt;
&lt;br /&gt;
dec di&lt;br /&gt;
dec bx&lt;br /&gt;
cmp bx,-160&lt;br /&gt;
jne SHORT @@capl&lt;br /&gt;
dec cx&lt;br /&gt;
cmp cx,-100&lt;br /&gt;
jne @rX&lt;br /&gt;
&lt;br /&gt;
tAnimate:&lt;br /&gt;
&lt;br /&gt;
inc [displace]&lt;br /&gt;
mov dl,[displace]&lt;br /&gt;
&lt;br /&gt;
;			do Static Texture Mapping&lt;br /&gt;
;	uses four segment registers for a mean and lean little loop&lt;br /&gt;
;	ds=offscreen buffer segment&lt;br /&gt;
;	es=texture segment&lt;br /&gt;
;	fs=tunnel u's&lt;br /&gt;
;	gs=tunnel v's&lt;br /&gt;
;	registers:&lt;br /&gt;
;	dl=displacement for u and v&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
push ds&lt;br /&gt;
&lt;br /&gt;
mov ax,[offscreen]&lt;br /&gt;
mov ds,ax&lt;br /&gt;
&lt;br /&gt;
mov di,64000-1&lt;br /&gt;
xor ah,ah&lt;br /&gt;
@@static:&lt;br /&gt;
xor bh,bh&lt;br /&gt;
mov bl,[gs:di]&lt;br /&gt;
add bl,dl&lt;br /&gt;
sal bx,8&lt;br /&gt;
mov al,[fs:di];			index to texture is now in bx&lt;br /&gt;
add al,dl&lt;br /&gt;
add bx,ax&lt;br /&gt;
mov al,[es:bx]&lt;br /&gt;
mov [ds:di-1],al&lt;br /&gt;
dec di&lt;br /&gt;
jne SHORT @@static&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;			wait for vertical raster retrace&lt;br /&gt;
&lt;br /&gt;
;	mov dx,03dah&lt;br /&gt;
;	@@one:&lt;br /&gt;
;	in al,dx&lt;br /&gt;
;	and al,8&lt;br /&gt;
;	jz SHORT @@one&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
;		( offscreen segment is still in ds )&lt;br /&gt;
push es		; save&lt;br /&gt;
xor di,di&lt;br /&gt;
xor si,si&lt;br /&gt;
mov cx,64000&lt;br /&gt;
push 0a000h&lt;br /&gt;
pop es&lt;br /&gt;
rep movsb&lt;br /&gt;
pop es	;	restore texture segment&lt;br /&gt;
pop ds	;	restore data segment (value is cs)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
mov ah,11h&lt;br /&gt;
int 16h&lt;br /&gt;
jnz SHORT @@finish&lt;br /&gt;
jmp tAnimate&lt;br /&gt;
&lt;br /&gt;
@@finish:&lt;br /&gt;
&lt;br /&gt;
mov ax,0003h&lt;br /&gt;
int 10h&lt;br /&gt;
ret&lt;br /&gt;
&lt;br /&gt;
constant1 dw 8192&lt;br /&gt;
constant2 dw 128&lt;br /&gt;
i dw ?&lt;br /&gt;
j dw ?&lt;br /&gt;
z dw ?&lt;br /&gt;
temp dw ?&lt;br /&gt;
&lt;br /&gt;
mup db ?&lt;br /&gt;
&lt;br /&gt;
displace db ?&lt;br /&gt;
offscreen dw ?&lt;br /&gt;
&lt;br /&gt;
END START&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/115289/tunnel/</guid>
      <pubDate>Thu, 09 May 2002 12:06:53 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/115346/re-tunnel/#115346</link>
      <description>Thank you for being the first person to add some code. I'am hoping that this type of message board works. Any body with comments please feel free to post or send a message to me.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
         Thanks!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Blue;"&gt;&lt;span style="font-size: small;"&gt;Question &lt;strong&gt;&lt;em&gt;everything!&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
      Espydude&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/115346/re-tunnel/#115346</guid>
      <pubDate>Thu, 09 May 2002 16:52:40 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/115661/re-tunnel/#115661</link>
      <description>;Smaller code that also pipelines better:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;code segment byte public use16 'code'
assume cs:code,ds:Code,es:code,ss:code
org 100h
386p
ideal
start:
mov ax,13h ;Do NOT assume AH=0, it's 09h when I run my own proggies!
int 10h

mov ax,cs
mov ds,ax
add ah,10h
mov es,ax ;ugly texture
add ah,10h
mov fs,ax ;u tunnel coordinates
add ah,10h
mov gs,ax ;v tunnel coordinates
add ah,10h
mov [offscreen],ax ;offscreen buffer for later use

mov dx,3c8h ;Oh no!  A palette change! &lt;img src="http://www.programmersheaven.com/images/Community/twink.gif" width="15" height="15" alt="" /&gt;
xor al,al
out dx,al
inc dx
xor al,al
mov cx,256 ;By swapping this with XOR AL,AL a pipe stall was prevented.
@@black:
out dx,al
out dx,al
out dx,al
inc ax ;INC AX is smaller than INC AL.
loop SHORT @@black

xor di,di
xor bx,bx
@@texture:
mov al,bl
xor al,bh
stosb
dec bl
jne SHORT @@texture
dec bh
jne SHORT @@texture

calcTunnel:
mov di,64000-1
mov cx,100
@rX:
mov bx,160
@@capl:
;u = lowByteOf(int)( 8192/Math.sqrt(i*i+j*j) )
mov [i],bx
mov [j],cx
finit
fild [constant1]
fild [i]
fmul st(0),st(0)
fild [j]
fmul st(0),st(0)
faddp st(1),st

fsqrt
fdivp st(1),st
fistp [word ptr temp]
mov ax,[temp]
mov [fs:di],al
;		v = lowByteOf(int)( atan2(i,j)*128/Math.PI )
fild [i]
fild [j]
fpatan
fimul [constant2]
fldpi
fdivp st(1),st
fistp [temp]
mov ax,[temp]
mov [gs:di],al

dec di
dec bx
cmp bx,-160
jne SHORT @@capl
dec cx
cmp cx,-100
jne @rX

tAnimate:
inc [displace]
mov dl,[displace]

;			do Static Texture Mapping
;	uses four segment registers for a mean and lean little loop
;	ds=offscreen buffer segment
;	es=texture segment
;	fs=tunnel u's
;	gs=tunnel v's
;	registers:
;	dl=displacement for u and v


push ds
mov ds,[offscreen] ;This is better than MOV AX,[offscreen] / MOV DS,AX.

mov di,64000-1
xor ah,ah
@@static:
movzx bx,[gs:di] ;This is better than XOR BH,BH / MOV BL,[GS:DI]
add bl,dl
sal bx,8
mov al,[fs:di];			index to texture is now in bx
add al,dl
add bx,ax
mov al,[es:bx]
mov [ds:di-1],al
dec di
jne SHORT @@static


;			wait for vertical raster retrace

;	mov dx,03dah
;	@@one:
;	in al,dx
;	and al,8
;	jz SHORT @@one



;		( offscreen segment is still in ds )
push es		; save
mov cx,64000
push 0a000h
xor si,si ;Prevent some pipeline stalls by separating a PUSH and a POP.
xor di,di
pop es
rep movsb
pop es	;	restore texture segment
pop ds	;	restore data segment (value is cs)


mov ah,11h
int 16h
jz tAnimate ;This is better than JNZ SHORT @@finish / JMP tAnimate.

@@finish:

mov ax,0003h
int 10h
ret

constant1 dw 8192
constant2 dw 128
i dw ?
j dw ?
z dw ?
temp dw ?

mup db ?

displace db ?
offscreen dw ?

code ends
END START&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/115661/re-tunnel/#115661</guid>
      <pubDate>Sat, 11 May 2002 13:46:54 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/115781/re-tunnel/#115781</link>
      <description>Nice! =)&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/115781/re-tunnel/#115781</guid>
      <pubDate>Sun, 12 May 2002 13:57:08 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/121764/re-tunnel/#121764</link>
      <description>coud anyone explain the effect to me, please ????&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/121764/re-tunnel/#121764</guid>
      <pubDate>Sat, 15 Jun 2002 09:08:14 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/121806/re-tunnel/#121806</link>
      <description>I haven't compiled it, so I couldn't tell you but I do have two other great tunnel programs (I don't have the sources, though).&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/121806/re-tunnel/#121806</guid>
      <pubDate>Sat, 15 Jun 2002 17:05:38 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/123018/re-tunnel/#123018</link>
      <description>i mean source code sharing is a very good idea. but what do i need it&lt;br /&gt;
for if i cant undestand the source?&lt;br /&gt;
so if there is someone who can explain the effect to me, please reply.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: I haven't compiled it, so I couldn't tell you but I do have two other great tunnel programs (I don't have the sources, though).&lt;br /&gt;
: &lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/123018/re-tunnel/#123018</guid>
      <pubDate>Sat, 22 Jun 2002 02:18:03 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/123093/re-tunnel/#123093</link>
      <description>&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by the brewski at  2002-6-23 0:7:8&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by the brewski at  2002-6-23 0:4:59&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: Red;"&gt;This message was edited by the brewski at  2002-6-23 0:2:14&lt;/span&gt;&lt;/strong&gt;&lt;hr /&gt;&lt;br /&gt;
: i mean source code sharing is a very good idea. but what do i need it&lt;br /&gt;
: for if i cant undestand the source?&lt;br /&gt;
: so if there is someone who can explain the effect to me, please reply.&lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
: : I haven't compiled it, so I couldn't tell you but I do have two other great tunnel programs (I don't have the sources, though).&lt;br /&gt;
: : &lt;br /&gt;
: &lt;br /&gt;
: &lt;br /&gt;
Hi AngelusMortis!&lt;br /&gt;
&lt;br /&gt;
I can explain what I remember of how this kind of effect is working, with some c-code, hope&lt;br /&gt;
that's ok.&lt;br /&gt;
 Lots of look up tables:&lt;br /&gt;
&lt;br /&gt;
One that precalculates a texture which is 256x256 pixels large.&lt;br /&gt;
In this case, by xor'ing in a loop, produces an image with squares.&lt;br /&gt;
This texture is where pixels or texels will be fetched from later.&lt;br /&gt;
In c code would be:&lt;br /&gt;
&lt;br /&gt;
int index=0;&lt;br /&gt;
for(int y=0;y&amp;lt;256;y++){&lt;br /&gt;
	for(int x=0;x&amp;lt;256;x++){&lt;br /&gt;
		texture[y+x*256]=(char)(x^y);&lt;br /&gt;
			index++; &lt;br /&gt;
				}}&lt;br /&gt;
&lt;br /&gt;
Next, precalculate the u and v buffers.&lt;br /&gt;
In the source there's one 64k segment for the u's, and another one for the v's.&lt;br /&gt;
These buffers contains memory offsets which points to the texture-segment.&lt;br /&gt;
For every coordinate position on screen there's a corresponding offset where to &lt;br /&gt;
fetch the texel in the texture-buffer.&lt;br /&gt;
So these buffers equals the size of the screen, 320x200.&lt;br /&gt;
The u's contains offsets for the x-coordinates.&lt;br /&gt;
The v's contains offsets for the y-coordinates.&lt;br /&gt;
So in the render loop, ( tAnimate-label in the asm-source) something like:&lt;br /&gt;
&lt;br /&gt;
int index=0;&lt;br /&gt;
for(int y=0;y&amp;lt;200;y++){&lt;br /&gt;
for(int x=0;x&amp;lt;320;x++){&lt;br /&gt;
PixelOnScreen[index]=texture[ uvBuffer [x+(y *256 )] ];&lt;br /&gt;
index++;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
( But in the asm-src there's separate buffers for u and v so it's more like:&lt;br /&gt;
u=uBuffer[index];&lt;br /&gt;
v=vBuffer[index];&lt;br /&gt;
PixelOnScreen[index]=texture[u+v&amp;lt;&amp;lt;8]&lt;br /&gt;
&lt;br /&gt;
But this would produce a static picture, to get motion, add another dynamic variable and &lt;br /&gt;
add it to the offsets, and the tunnel will move:&lt;br /&gt;
&lt;br /&gt;
u=uBuffer[index]+displace;&lt;br /&gt;
v=vBuffer[index]+displace;&lt;br /&gt;
PixelOnScreen[index]=texture[u+v&amp;lt;&amp;lt;8]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
( And once every frame increase displace-variable )&lt;br /&gt;
&lt;br /&gt;
The 'calcTunnel' label in the source, is where these uv offsets are calculated, with &lt;br /&gt;
some trigonometry-function.&lt;br /&gt;
In c would be somewhat like:&lt;br /&gt;
&lt;br /&gt;
int index=0;&lt;br /&gt;
for(int y=0;y&amp;lt;200;y++){&lt;br /&gt;
for(int x=0;x&amp;lt;320;x++){&lt;br /&gt;
int i=x-160; // (SCREENWIDTH/2)&lt;br /&gt;
int j=y-100; // (SCREENHEIGHT/2)&lt;br /&gt;
v [index] = (int) ( atan2 (i,j) * 128/ 3.14159265 ); 	// the angle&lt;br /&gt;
u [index] = (int) ( 8192 / sqrt (i*i+j*j) );		// distance from origin&lt;br /&gt;
index++;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
(Varying the constant 8192 will produce different perspective.&lt;br /&gt;
Constant 128 is half of size of the textureBuffer width or height.)&lt;br /&gt;
&lt;br /&gt;
I just converted this to assembler, and tried optimize a bit for size.&lt;br /&gt;
So the asm-code is messier than these c-snippets.&lt;br /&gt;
&lt;br /&gt;
Hope this help.&lt;br /&gt;
(I wrote this off memory, so if someone spots error, please&lt;br /&gt;
forgive...)&lt;br /&gt;
&lt;br /&gt;
To Blip: Could you please explain about pipeline, what is it? and how to prevent bad pipelining! ) &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/123093/re-tunnel/#123093</guid>
      <pubDate>Sat, 22 Jun 2002 23:53:28 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
    <item>
      <title>Re: tunnel</title>
      <link>http://www.programmersheaven.com/mb/SourceShare/115289/123112/re-tunnel/#123112</link>
      <description>Pipelining is like having a few mini-processors in one that do jobs in parallel to speed up the whole machine considerably.  There is one catch, though: they must do jobs that don't require the result of another that's in another pipeline or else you'll have a pipeline stall and lose some speed in the process.  There are many ways to prevent pipeline stalls and they can differ between processors.  I'd rather not explain it because this guide does much better than I would be able to and more: &lt;a href="http://www.programmersheaven.com/file.asp?FileID=6344"&gt;http://www.programmersheaven.com/file.asp?FileID=6344&lt;/a&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/SourceShare/115289/123112/re-tunnel/#123112</guid>
      <pubDate>Sun, 23 Jun 2002 05:23:44 -0700</pubDate>
      <category>Assembly Code Share</category>
    </item>
  </channel>
</rss>