From: Chris Wahlen <nc@earthling.net>
Newsgroups: comp.sys.hp48
Subject: Re: line.s
Date: Wed, 18 Nov 1998 22:18:42 -0600
Organization: Fastlane Communications (using Airnews.net!)
Lines: 214
Message-ID: <A664C64BE2EAE0CA.7E3FED7668917649.0922CE52E1FC0090@library-proxy.airnews.net>
X-Orig-Message-ID: <36539C22.528923D7@earthling.net>
References: <slrn7565jd.ko.mozgy@danielle.mozgy.hr> <qrgyrscebivqr.f2ngyh1.pminews@news.hamburg.pop.de> <36537b8e.0@isoit370.bbn.hp.com>
Abuse-Reports-To: abuse at fastlane.net to report improper postings
NNTP-Proxy-Relay: library.airnews.net
NNTP-Posting-Time: Wed Nov 18 22:19:05 1998
NNTP-Posting-Host: dD`pF+<VdtBe1BFCh,,>Bl.F%+TMKB (Encoded at Airnews!)
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.5 [en] (WinNT; I)
X-Accept-Language: en
Xref: republic.btigate.com comp.sys.hp48:18751

Ok, here's my Line routine.  It uses the current graphics grob, x2 must be
greater than x1.  Its roughly 4x faster than the internal LINEON.
It's commented too!  ooh! =)

* Takes 4 arguments, x1, y1, x2, y2 from the stack

CODE
 GOSBVL =SAVPTR
 GOSBVL =D0->Row1   * D0 is our graphics grob

 A=DAT1 A
 AD1EX
 D1=D1+ 5
 C=DAT1 A
 D=C A           * D = y2
 AD1EX

 D1=D1+ 5
 C=DAT1 A
 CD1EX
 D1=D1+ 5
 A=DAT1 A
 B=A A           * B = x2
 CD1EX

 D1=D1+ 5
 A=DAT1 A
 AD1EX
 D1=D1+ 5
 C=DAT1 A        * C = x2
 AD1EX

 D1=D1+ 5
 A=DAT1 A
 AD1EX
 D1=D1+ 5
 A=DAT1 A        * A = x1

 B=B-A B         * B = delta x (we're using B because the grobsize is
131x128, fitting within 0xFF (B))
 AR2EX
 ?C>D B         * is our x1 greater than our x2?
 GOYES MakeYNeg
 D=D-C B         * D = delta y
 A=0 A
 A=A+1 A         * a 1 in R2 indicates a positive Y
 AR2EX
 GOTO DoneWithY

MakeYNeg
 D=C-D B         * D = delta y
 A=0 A           * a 0 indicates a negative Y
 AR2EX

DoneWithY
 R0=A.F A
 C=C+C A         * we're going to multiply C by 32 (we use A here because
we're calculating an address)
 A=C A
 CSL A
 C=C+A A         * done.
 A=R0.F A
 ASRB.F A        * shift right ( divide by two )
 ASRB.F A        * a is now divided by four
 C=C+A A         * add this value to X - this is the X value - next we must
calculate how many bits over it is....
 AD0EX           * swap the graphics grob into A
 A=A+C A         * add the value we just calculated
 AD0EX
 A=R0.F A        * and this requires that we restore our x1 back to normal.
 C=0 A           * C go bye-bye
 LC(1) #3        * use three to MOD with A
 A=A&C A         * this is the same as A MOD C
 LC(1) #1        * initial bit
beginbitloop
 ?A=0 B          * if a is zero, then exit this loop
 GOYES endbitloop
 C=C+C B         * shift C over a bit......
 A=A-1 B         * subtract 1 from A until its 0
 GOTO beginbitloop
endbitloop
 P=C 0           * Set P to be the first nibble of C.  This is our bit to OR
with the screen.
 ASL A
 A=DAT0 1        * get the nibble pointed to by the GROB
 A=A!C A         * or the nibble with ours
 DAT0=A 1        * output it to the grob

 A=0 A           * A is our amount error
 D1=A            * D1 is our counter

 C=B B
 ?D<C B          * DeltaY < DeltaX?
 GOYES OtherLine

 C=D B           * C is our Length (DeltaY + 1)
* C=C+1 B

beginlineloop
 AD1EX

 GOSUB IncrementY
 A=A+B B         * Error = Error + DeltaX
 R1=C.F B        * Swap A and C
 C=A B
 A=R1.F B
 ?C<D B          * Is Error (now C) less than DeltaY (D)?
 GOYES ErrorNotLess
 GOSUB IncrementX
 C=C-D B         * Error = Error - DeltaY

ErrorNotLess
 R1=C.F B        * back up A and C
 R0=A.F B
 GOSUB PutPixel
 C=R0.F B        * and return them swapped
 A=R1.F B

 AD1EX
 A=A+1 B
 ?A<C B          * is our counter (D1) < Length (C)?
 GOYES beginlineloop
 GOTO EndLine

* This is the inner loop for increasing along delta X

OtherLine
 A=B B           * A is our Length (DeltaX + 1)
* A=A+1 B
 C=0 A
 D1=C

beginlineloop2
 CD1EX           * C is our Error

 GOSUB IncrementX
 C=C+D B         * Error = Error + DeltaY
 ?C<B B          * Is Error (C) less than DeltaX (B)?
 GOYES ErrorNotLess2
 GOSUB IncrementY
 C=C-B B         * Error = Error - DeltaX

ErrorNotLess2
 R1=C.F B        * back up A and C
 R0=A.F B
 GOSUB PutPixel
 C=R1.F B        * and return them swapped
 A=R0.F B

 CD1EX
 C=C+1 B
 ?C<A B          * is our counter (D1) < Length (A)?
 GOYES beginlineloop2
 GOTO EndLine

PutPixel
 A=0 B           * Reset these vars...
 C=0 B
 A=DAT0 1        * grab the pixel
 C=P 0
 C=C!A B         * or it with our mask
 DAT0=C 1        * draw the pixel
 RTN

IncrementY
 R0=A.F A        * Back up A
 A=R2.F A        * Get the Y increment
 ?A=0 A          * Is a negative?
 GOYES YIsNegative
 A=R0.F A        * Restore A
 D0=D0+ 34       * Add one line
 RTN
YIsNegative
 A=R0.F A        * Restore A
 D0=D0- 34       * Go back one line
 RTN

IncrementX
  R1=C.F B       * back up C
  C=0 B
  C=P 0          * set the first nibble of C to P (P is our mask)
  C=C+C B        * shift C over one
  P=C 0          * put C back into P
  ?P# 0          * P <> 0?
  GOYES PNotOverflowed
  D0=D0+ 1       * increment D0 to point to next set of 4 pixels
  P= 1           * first pixel
PNotOverflowed
  C=R1.F B       * restore C
 RTN

EndLine
 P= 0
 GOSBVL =GETPTR
 GOSBVL =4DropLoop
ENDCODE


> hello
>
> >Hey Mozgy -- here's my version. Competition is open, which one is
> >faster ? Anyone w/ an even faster/shorter version ?
>
> It would be a good idee to time the core routine on a 131*64 screen with
> this type of program
> (in assembly of course, we want to test the core of the line, not the not
> critical things around)
>
> for x := 0 to 130
>   for y := 0 to 63
>     line (0, 0, x, y)
>
> A+ cyrille
