- SEPTiC DEMO'S COLLEGE -- 

                                 Lesson 10 
                                 ?????????? 
                         Written by Vicious / Septic 

                                  3 Dec 93 



                                  Introduction 
                                  ????????? 
Hello again! Another exciting programming lesson ready to read! The 
This time, I thought to go through the blitterns very interesting line - 
Drawing feature works and also view it with a program example (which 
I usually do, of course ...) where a few lines plotted. 
   Okay, we started running well! 


                                    Theory 
                                    ????? 
A line is as familiar a series of consecutive points. It has a start - 
point and end point and the two coordinates, you can count up 
line slope of X and Y-point, plus how many pixels as needed to 
represent the line. 
   This is exactly what we should do to draw a line with the processor, 
and there will be a lot of Strul of back and forth with calculations and 
pixel-plus settlement that requires a lot rastertid at only a few 
lines. PC coders and C64-coders are forced to do in this way, but 
Amiga coders are fortunate through the amazing little as blittern 
capable of linjeritandet very smoothly. 
   To draw a line with blittern may seem a bit cryptic and difficult, but 
it is actually quite simple when you can (that is not the case with everything, 
really?) As usual, when it comes blittern, can processor 
continue to work while blittern draw the line. 

Blittern need a OCTANT to begin with, describing the line 
direction. Here is a picture of the different directions that can occur: 

           \ 3 | 1 / 
            \ | / 
           7 \ | / 6 
           ___ \ |/___ 
              / | \ 
           5 / | \ 4 
            / | \ 
           / 2 | 0 \ 

Numbers are in the various fields indicates OCTANT number to be given to 
blittern later. (The diagonal lines to form the 45  angle with both the 
vertical and the horizontal line, of course. It is just not so easy 
to write it in text mode.) 
   Then we must figure out a couple of variables, DX and DY, which can be said to be 
Line coordinates converted to OCTANT 6 (which is box 0, if we passed 
after a standard 360  unit circle). 

   DX is the maximum value of (X2-X1) and (Y1-Y2). 
   RI is minvardet of (X2-X1) and (Y1-Y2). 

X1 and Y1 is the starting line-coordinate, and X2 and Y2 is the end - 
coordinate. 

It was all theory ... Let us go forward with what the various registers 
will contain! 


                                  Register 
                                  ???????? 
At the line drawings used basically the same record as at regular dubbing 
with blittern. The difference is that by putting a special DRAW LINE-bit in 
BLTCON1 ($ DFF042) then most of the registers an entirely different meaning. 
   To begin with, you should always bring BLTADAT ($ DFF074) to $ 8000. I 
BLTBDAT ($ DFF072) should I enter the line mask. This mask is 16 bits 
large, thus a word, and it indicates how the line should look like. If all the pieces are 
contested and wordet is $ FFFF so we'll have a solid line without holes, and it is 
usually what you want. 
   Furthermore, they must meet BLTAxWM ($ DFF044) to $ FFFFFFFF for not 
skulk away something on the line. 
   Then you should use the DX and DY and bring in 4 * (DX-RI) in BLTAMOD 
($ DFF064), 4 * RI in BLTBMOD ($ DFF062) and finally (4 * RI) - (2 * DX) in BLTAPT 
($ DFF074). 
   In BLTCMOD ($ DFF060) and BLTDMOD ($ DFF066), the width of the screen in 
bytes entered. 
   BLTCPT ($ DFF048) and BLTDPT ($ DFF054) will contain lines only pixels 
position in a word. This means only the lowest four pieces of 
X-coordinate. For example, if X is 134,% 10000110 binary, gives the number 6 is the 
four lowest bits% 0110. 

   BLTCON0 will look follows: 

BIT # BLTCON0 Description 
---- ------- ----------- 
  15 START3 I bit 12-15, the four lowest bits in the first 
  14 start2 X-coordinate entered. 
  13 START1 
  12 START0 
  11 1 This piece is SRCA bit, actually. It will always 
                  be 1 when drawing lines. 
  10 0 SRCB will always be 0 
  09 1 SRCC should always be 1 
  08 1 DEST will also always be 1! 
  07 LF7 Minterm bit 
  06 LF6 "" 
  05 LF5 "" 
  04 LF4 "" 
  03 LF3 "" 
  02 LF2 "" 
  01 LF1 "" 
  00 LF0 "" 

Mintermen usually be AB + aC, namely A and B, or non-A and C. This 
makes an ordinary line plotted without any modifications. If 
mintermen ABC + aC elected, then A and B and non-C or non A and C, 
, an EOR-line plotted. EOR means that the line be inverted when the 
overwriting existing pixels. This can be useful if you want 
eliminate lines quickly. Then you need is just drawing out the line yet 
once in the same place and then picked the line is automatically deleted. 
   EOR method should we use when we are filled vectors. Where required for EOR 
that the surfaces should be the right color, but it will in no lesson beyond. 

Okay, in BLTCON1 we must enter the following things: 

BIT # BLTCON1 Description 
---- ------- ----------- 
  15 FIBER 3 Start bit in a word for the line mask. 
  14 FIBER 2 
  13 FIBER 1 
  12 FIBER 0 
  11 0 Reserved for new features 
  10 0 
  09 0 
  08 0 
  07 0 
  06 SIGN Character flag. To be put on BLTAPT is negative 
  05 0 
  04 SUD These three pieces (SUD, SUL and AUL) indicates OCTANT code 
  03 SUL 
  02 AUL 
  01 SING Only one pixel per line. Used in the filling area. 
  00 LINE Shall set to 1 at line drawing. 

Finally (as usual) you should enter the line size of BLTSIZE 
($ DFF058) and it works so that blithojden (bits 6-15) is the route 
and blitbredden is always 2. 
   There, now, let's look at how the sample application is built! 


                               Program example 
                               ??????????????? 
The program I have done this time shows how a consistent routine work, and 
it draws up two simple figures to demonstrate that the routine works. 
   If we look at the source, we see that it does not offer any direct 
news until the subroutine DRAW. 
   Which I add the values required by linjeritnings routine, ie 
screen's top, its width in bytes and the line mesh or texture. Late 
I write in the starting line X, Y start and end X, Y end of the D0, D1, D2 and 
D3. After the jumps I to the routine Draw Line, which draws out the line. 
   This, I repeat three times to draw the triangle. 
   Then, draw out QUADRANGLE I sides in a smarter way, which is 
that I read from a table and instead draw any line so that the 
associated with the former. 
   I did the different objects in these ways just because you would understand 
the line routine work, and then to see a simpler way to draw 
lines. 
   If we walk further down the source, we soon routine Draw Line. 
   At the beginning of the routine check so that we do not line begins and ends at 
the same point, for if we can not draw it out, and then we jump 
instead out. 
   Then we calculate, just as in ordinary blitteranvandning, was the first 
Y-coordinate ports for the switching-series when multiplied by 
the screen width. We also produce a delta Y value and a delta X value 
then used both to produce the right OCTANT and the variables DX and 
RI. 
   OCTANT be developed in a rather clever way by making use of 
SUB-instruction set of X-flag when the result is negative. On 
That way we could through three subtraction and three ROXL instructions (which 
shifts in X-flag in the registry lowest bit) get a trebitars 
OCTANT combination pointing to a specific value in a OCTANT-table right 
OCTANT value is positioned as a replacement. 
   This is much smoother than comparing participate values and jump here and 
where to put different values on OCTANT. 

After that, we'll find out which part of our values is greatest, 
because the DX will contain the largest number. 
   Then I put all the resulting values in blitter records. Note that 
I use mintermen AB + aC to draw a plain, OR-line without 
modifications. 
   It was probably everything, I think. If you do not understand you can always 
ask me, and I'll explain as best I can. 
   The next lesson, I will explain how three-dimensional vector-rotation goes 
to! But until then, keep assimilate with line drawings!