Coders - Reflections on 3D.

ZX Time #11
Coders                                 
---------------------------------------
                                        
 Reflections on 3D           
 ------------------          
 Nikolay Dvornik /KilleRam/      
                                        
   In this short article I want
tell me about my idea to create
universal 3D engine on SPECCY for
writing games in the appropriate direction
nia. It seems to me that 3D is most successful
implemented in the following programs: DOOM
Ly Digital Reality, Awaken Ly Rage, Wolf
3D Ly AlCo/i8, Stellar Game Ly Brain-
wave. The implementations are, of course, excellent, but
not before Delta Force and before Medal of Honor
pull :).  I mean the full realization
landscape, and not stupid running around the labyrinth
Rintu (Awaken is not within the style).       
                                        
   I propose to create an editor on SPECCY
torus on which it will be possible to write practical
virtually any 3d ActiOn. Or rather, clean
edit zones (load textures,
create plane-objects and “paint-
we add textures to them).The first thing I want to start with is this
height table. This table stores data
about the height (z-coordinate) at which
children will imprint this or that photo
(see below). The length of this table is 255 bytes,
whereby level 0 belongs to the plane
XY, and the quantization of levels proceeds in accordance with
according to the lowest plane height
(see below).                             
                                        
 EXAMPLE:                 
                                        
1 byte: level of the lowest image (XY)  
2byte: higher level            
 ...  
192 bytes: level of the highest image, hour-
The first case of which is the sky.             
Image - orthogonal, horizontal
height level projection.                 
                                        
 The image format is as follows:          
                                        
Image size (16x16 bits)              
1 line of the image array corresponds toy=0
and stores data about the printed planes
tah (see below), the minimum width of the flat
4pix dice (see below).                  
                                        
 For example:               
                                        
 X | 0 |  4 |  8 | 12 | 16 | 20 | 24 | 
 ---+---+----+----+----+----+----+----+ 
  N | 1 |  2 |  3 |  4 |  1 |  3 |  4 | 
                                        
This corresponds to this representation: 
                                        
 X  
 +---------------------------------->  
 | +---------------------------------+  
 | |1234134, etc. up to X(max)/4 |  
 | |                                 |  
 | |                                 |  
 | |                                 |  
 | |                                 | 
 | |                                 |  
 | |                                 |  
 | +---------------------------------+  
US  
                                        
   And so on for each line up to Y (max)
I want to say that the maximum number
in planes 111, and the maximum number,
recognizable by program 255, while
codes from 0 to 31 are control codes (for example,
notify the program about imprinting
sprite instead of a plane, etc.) Codes from
32 to 143 tell the program that
plane with the corresponding forward number
runs parallel to the X axis, and if
dy are in the range from 144 to 255,
then parallel to the Y axis.                   
                                        
   That is, the plane with number 32 corresponds to
corresponds to plane number 144. Code
31 corresponds to emptiness (nothing forward)
chatting). Plane - an array containing
information about imprinted textures and
their color.   Maximum quantity
textures 222 (codes from 0 to 31 - control
schies). The texture size is 8x4pix to make it convenient
It would have been better to paint. Format example             
                                        
1 byte - length (width)                  
2bytes - height                          
3                                      
 |- size in bytes                   
4/                                      
further comes  
Sbyte - texture number                  
bbyte - color                         
 etc.                                 
                                        
   Everything is stored in order in memory. B
in the process of preparing the landscape, he
is easily converted into a coordinate form
mu (it is easier to carry out transformations on it)
vania), and then in accordance with the half-
The text coordinates are imprinted
tours.                                   
                                        
 - - -                  
                                        
   Your thoughtsabout this idea
send it either to the editor or to me personally at
address:                                 
                                        
 Suvorova str. 22, Yenakievo-19,     
Donetsk region, Ukraine, 86486     
                                        
 * * *                  
                                        
 Simple sprite output          
 -----------------------         
 Denis Tokarczuk /DWT/          
                                        
   I don’t know, maybe in some sources
kah and it was written about a similar technique
sprite output, but I got to it by
experiments.                          
                                        
   As you know, a sprite in the computer’s memory
yutera is located in series -
line by line. However, Spectrum
The screen has its own characteristics, about which
which everyone knows very well. Investigator-
but, the difficulty of displaying a sprite on the spectrum is
The mov screen consists of recalculating the following
tion line along the Y axis in the screen memory.
Existsmany ways to withdraw
sprite on the screen - from "roughly calculated-
our" (but universal) to tabular and
stacked  I propose some kind of hybrid
table-stack sprite output.    
                                        
   The design of such programs is extremely
incredibly simple. Let's say somewhere in memory
from the address TABL there is a table approximately
as follows: #4000, #4100, #4200,
#4300 . . . #4020, #4120, #4220, etc.
That is, the addresses of each subsequent line
screen in memory. And at the address SPR_V on-
there is a program for direct output
sprite:                                
                                        
SPR_V LD (STACK),SP                  
 LD HL, sprite address             
 LD SP,TABL                      
 DUP height in pixels          
 POP DE                          
 DUP width in familiar spaces       
 LDI                             
 EDUP                           
 EDUP                           
 LD SP,0                         
STACK EQU $-2                         
 RET                             
                                        
   I hope that the comments to this fox-
tingu are unnecessary, since everything is clear: the
we push into the DE register from the stack (which is
located on our screen address table)
value of the current screen line, then
using LDI commands we transfer one line
sprite on the screen (HL)->(DE), then "remove-
draw the next line from the stack, and so on until
end. Elementary, isn't it?..     
                                        
   However, in terms of execution speed this
design (I call it POP DE-LDI) is not
is the most optimal, although also
pretty nimble.  For example, a sprite in
It displays 10x20 acquaintances in approximately
27250 clock cycles. Not bad in my opinion.        
                                        
   Another question is how to generate it,
so that a rather hefty piece of code does not
store it as a kind of ballast in the program.   
                                        
   First of all, it is necessary to generate
Create a screen address table (named
us TABL) thatquite simple. A
then use a simple program to create your own
definitely the hatch.                       
                                        
 Well, here's an example:                  
                                        
TABL EQU #6000 ;address where
                       ;move table
                       ;screen addresses  
                                        
SPR_V EQU #8000 ;address where it will be
                       ;be prog-
                       ;output frame sp-
                       ;ayta           
                                        
ADR_SCR EQU #4000 ;screen address, ku-
 ;yes print
                       ;ight             
                                        
SPR_НТ EQU 64 ;sprite height in
                       ;pixels       
                                        
SPR_WT EQU 8 ;sprite width in
                       ;familiar places     
                                        
 ORG #6200                     
;формируем таблицу адресов экрана:      
МАКТАВ    LD DE,TABL                    
          PUSH DE                       
          LD HL,ADR_SCR                 
          LD В,SPR_НТ                   
МТ1       LD А,L                        
          LD (DE),А                     
          INC DE                        
          LD А,Н                        
          LD (DE),А                     
          INC DE                        
          INC Н                         
          LD А,Н                        
          AND 7                         
          JR NZ,МТ2                     
          LD А,L                        
          ADD А,#20                     
          LD L,А                        
          JR С,МТ2                      
          LD А,Н                        
          SUB 8                         
          LD Н,А                        
МТ2       DJNZ МТ1                      
                                        
;а вот и сама генерилка программы вывода
;спрайта:                               
                                        
МАКЕ_SV                                 
;----------------------                 
          LD HL,SPR_V  ;Записываем    по
          LD (HL),#ED  ;адресу SPR_V ко-
          INC HL       ;манду LD (..),SP
          LD (HL),#73  ;Адрес,  куда  SP
          INC HL,HL,HL;sign up - you-
                       ;we'll explain later     
;---------------------                 
 LD (HL),#31 ;Write by
          INC HL ;next address-
 POP DE ;su LD SP,TABL,
          LD (HL), E; that is, we place
          INC HL ;stack to address
          LD (HL),D ;address tables 
          INC HL;                
;---------------------                 
 LD С,SPR_НТ                  
MSV0 LD (HL),#D1 ;as follows
                       ;we place the address
                       ;POP DE          
 INC HL                       
;---------------------               
 LD В,SPR_WT ;Write LDI
MSV1 LD (HL),#ED ;SPR_WT times (then
          INC HL ;there is a width of sp-
          LD (HL),#A0 ;raita defines
          INC HL ;quantity
          DJNZ MSV1 ;LDI)           
;---------------------                 
 DEC C ;Repeat all
          JR NZ,MSV0 ;design (POP
                       ;DE-LDI) SPR_НТ
                       ;times             
                                        
 LD (HL),#31 ;Write in
                       ;next address
                       ;LD SP,..       
                                        
 INC HL ;And save the following
          LD (SPR_V+2),HL ;current address
                       ;to the beginning of the program
                       ;mmm (where to save-
                       ;remove stack)      
 INC HL,HL                     
 LD (HL),#С9 ;And in the end -
                       ;RET             
 RET                          
                                        
   After generating the output program
sprite, you can run it without forgetting
before CALL SPR_V write the HL address
sprite. That's all I wanted to say :)
                                        
                 - - - 

Share your thoughts about the article