English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Tutorials

 
 
Thread Tools
Old 02 February 2010, 20:10   #1
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Plotter / Dot Flag

Watcha boys

I'm bored at the moment waiting for other guys to (hopefully sometime soon...) deliver music and code for the megademo so I've been doing other little small bits of code while I wait.

In case anyone can make use of it I made a little plotter routine today and then added a couple of sine waves to turn it into a dot flag.

I can't say it's the fastest or best way to do a dot flag but it works and, well, like I said - I was bored...

Last edited by pmc; 26 February 2010 at 12:23.
pmc is offline  
Old 02 February 2010, 20:48   #2
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Nice one, had a (very) quick look, my version of your innerloop looks like:

Code:
	move.w	d0,d1
	lsr.w	#3,d0
	not.b	d1
	bset	d1,(a1,d0.w)


	;move.w	d0,d1
	;andi.w	#%0000000111110000,d0
	;lsr.w	#3,d0
	;add.w	d0,a1
	;andi.w	#%0000000000001111,d1
	;subi.w	#15,d1
	;neg.w	d1
	;move.w	(a1),d2
	;bset.l	d1,d2
	;or.w	d2,(a1)
Think about it. =)
StingRay is offline  
Old 02 February 2010, 20:59   #3
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Nice one Sting

Yeah, like I just said to WayneK on PM - I literally *threw* this code together in a few minutes this afternoon so I'm 100% sure it can be made much much better.

I'll tweak it into something nicer code wise at some point.
pmc is offline  
Old 03 February 2010, 11:05   #4
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Quote:
Originally Posted by StingRay
...my version of your innerloop looks like...


...Think about it....
I looked at this a bit more closely, and concluded:
pmc is offline  
Old 03 February 2010, 13:22   #5
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Check the new version attached.

A couple of very small optimisations have been made but the main optimisation is Sting's much (much!) better plot code - now credited in the source to him.

Accordingly, the flag now has an additional 60 dots per frame.

All hail StingRay!

Last edited by pmc; 26 February 2010 at 12:23.
pmc is offline  
Old 16 February 2010, 17:43   #6
victim
Registered User
 
Join Date: Mar 2009
Location: N/A
Posts: 23
Post

Quote:
Originally Posted by pmc View Post
Check the new version attached.

A couple of very small optimisations have been made but the main optimisation is Sting's much (much!) better plot code - now credited in the source to him.

Accordingly, the flag now has an additional 60 dots per frame.

All hail StingRay!
Hi pmc !

I did a little experimenting and I think the routines produce good results.
I have the X and Y position and the individual bits precomputed.

try it....

Code:
;*******        
;****        Date: 16.02.2010        Prog: Dot calculation 
;****        
;****        Done by Victim of Savage (Sascha Mueller)
;*******
          
;example call
                bsr    InitYCalc
                bsr    InitXCalc
                bsr    InitBit

                move #320/2,d0
                move #256/2,d1
                bsr    TurboDot
                rts
       
;*** d0.l=xpos , d1.l=ypos  

TurboDot:
            move.l    PlaneBufferWork(pc),a0
            lea         MulTabX(pc),a1
            lea         bittab(pc),a2
            add        d0,d0
            add        d1,d1
            add        MulTabY(pc,d1.w),a0 ;y-cr*screenwidth
            add        (a1,d0.w),a0
            move      (a2,d0.w),d1
            bset       d1,(a0)
            rts

InitYCalc:    lea         MulTabY(pc),a0
                 move      #255,d1
                 moveq     #0,d0
loop:          move       d0,(a0)+
                 add        #40,d0
                 dbf         d1,loop
                 rts
            
MulTabY:    blk.w    256,0

InitXCalc:
            lea        MulTabX(pc),a0
            moveq    #0,d0
            move     #319,d2
loop2:    move     d0,d1
            asr        #3,d1
            move     d1,(a0)+
            addq     #1,d0
            dbf        d2,loop2
            rts        

MulTabX:    blk.w    320,0

InitBit:    lea        BitTab(pc),a0
            moveq    #0,d0
            move    #320-1,d7
Bit:        move    d0,d1
            and        #7,d1        ;Which Bit
            move    #7,d2        ;substract from $7
            sub        d1,d2        ;want pixel nul is bit 7
            move    d2,(a0)+
            addq    #1,d0
            dbf        d7,bit
            rts

BitTab:        blk.w    320,0
another version, here is only the Y position of precomputed

Code:
CalcDot:	move.l	PlaneBufferWork(pc),a0
		lea	        MulTabY(pc),a1
		move	        d0,d2
		asr	        #3,d0
		add	        d1,d1
		add	        (a1,d1),d0
		not	        d2
		bset	        d2,(a0,d0)
		rts

InitYCalc:
            lea        MulTabY(pc),a0
            move      #255,d1
            moveq    #0,d0
loop:     move      d0,(a0)+
            add        #40,d0
            dbf        d1,loop
            rts
            
MulTabY:    blk.w    256,0
and here is a special routine for the 68020+

Code:
;*** for 68020+
;*** d0.l=xpos , d1.l=ypos 

CalcDot:    move.l    PlaneBufferWork(pc),a0
            move    MulTabY(pc,d1.w*2),d1
            bfset    (a0,d1.w){d0:1}
            rts

InitYCalc:
            lea        MulTabY(pc),a0
            move      #255,d1
            moveq    #0,d0
loop:     move      d0,(a0)+
            add        #40,d0
            dbf        d1,loop
            rts
            
MulTabY:    blk.w    256,0
and the same version with a little clipping routine


Code:
;*** for 68020+
;*** d0.l=xpos , d1.l=ypos + Punkte Clipping

CalcDot: 
            move.l    PlaneBufferWork(pc),a0
ClipXmax:
            cmp    #319,d0            ; is xd0 < or = xmax 319
            ble.s    ClipXmin    ; YES 
            bra.s    PointEnd    ; NO    
        
ClipXmin: 
            tst        d0                ; is xd0 > or = xmin 0
            bge.s    ClipYmax
            bra.s    PointEnd

ClipYmax:    
            cmp    #255,d1            ; is yd1 < or = ymax 255 
            ble.s    ClipYmin
            bra.s    PointEnd

ClipYmin:
            tst    d1                ; IS yd1 > or = ymin 0
            bge.s    ClipSetPoint
            bra.s    PointEnd
        
ClipSetPoint:    
            move    MulTabY(pc,d1.w*2),d1
            bfset    (a0,d1.w){d0:1}
PointEnd: 
            rts


InitYCalc: 
            lea        MulTabY(pc),a0
            move    #255,d1
            moveq    #0,d0
loop:     move    d0,(a0)+
            add        #40,d0
            dbf        d1,loop
            rts
            
MulTabY:    blk.w    256,0
I hope they use it to

so long....
victim

Last edited by victim; 17 February 2010 at 00:23.
victim is offline  
Old 16 February 2010, 18:36   #7
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Quote:
Originally Posted by victim View Post
I did a little experimenting and I think the routines produce good results.
I see you edited your post and removed the "my routines here are the fastest" bit... Good move because this:

Quote:
Originally Posted by victim View Post
Code:
;*** for 68020+
;*** d0.l=xpos , d1.l=ypos + Punkte Clipping

CalcDot: 
            move.l    PlaneBufferWork(pc),a0
            lea        MulTabY(pc),a1

ClipXmax:
            cmp    #319,d0            ; is xd0 < or = xmax 319
            ble.s    ClipXmin    ; YES 
            bra.s    PointEnd    ; NO    
        
ClipXmin: 
            tst        d0                ; is xd0 > or = xmin 0
            bge.s    ClipYmax
            bra.s    PointEnd

ClipYmax:    
            cmp    #255,d1            ; is yd1 < or = ymax 255 
            ble.s    ClipYmin
            bra.s    PointEnd

ClipYmin:
            tst    d1                ; IS yd1 > or = ymin 0
            bge.s    ClipSetPoint
            bra.s    PointEnd
        
ClipSetPoint:    
            move    (a1,d1.w*2),d1
            bfset    (a0,d1.w){d0:1}
PointEnd: 
            rts
is anything but fast. Here's my version:
Code:
; d0.w: x
; d1.w: y
clip    cmp.w    #255,d1
    bhi.b    .clip

    ; calc y-pos
    ; ...
    nop
    
    cmp.w    #319,d0
    bhi.b    .clip

    ; point is inside clipping boundary, draw
    ; ...
    nop

.clip    rts
StingRay is offline  
Old 16 February 2010, 20:22   #8
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Why are the nop's in there, out of interest?
korruptor is offline  
Old 16 February 2010, 20:34   #9
StingRay
move.l #$c0ff33,throat
 
StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
Because I didn't feel like posting trivial "calc y-offset/draw a dot" code. The nops are just placeholders.
StingRay is offline  
Old 16 February 2010, 22:10   #10
korruptor
TDI
 
korruptor's Avatar
 
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
Hahaha, fair enough, for some reason I thought there was going to be a hidden piece of cunning
korruptor is offline  
Old 16 February 2010, 23:09   #11
victim
Registered User
 
Join Date: Mar 2009
Location: N/A
Posts: 23
Quote:
Originally Posted by StingRay View Post
I see you edited your post and removed the "my routines here are the fastest" bit... Good move because this:



is anything but fast. Here's my version:
Code:
; d0.w: x
; d1.w: y
clip    cmp.w    #255,d1
    bhi.b    .clip

    ; calc y-pos
    ; ...
    nop
    
    cmp.w    #319,d0
    bhi.b    .clip

    ; point is inside clipping boundary, draw
    ; ...
    nop

.clip    rts

Good man StingRay, because you've got me almost. But one must be careful what one writes. Above all, if you want to write that it should be on one of the fastest routine, it becomes dangerous.
There are simply too many tricks.
For this reason, I have changed my post a precaution

I think this routine produced very good results.

Code:
;*** for 68020+
;*** d0.l=xpos , d1.l=ypos 

CalcDot:    move.l    PlaneBufferWork(pc),a0
               move    MulTabY(pc,d1.w*2),d1
               bfset    (a0,d1.w){d0:1}
               rts

InitYCalc:
            lea        MulTabY(pc),a0
            move      #255,d1
            moveq    #0,d0
loop:     move      d0,(a0)+
            add        #40,d0
            dbf        d1,loop
            rts
            
MulTabY:    blk.w    256,0
so long...
victim

Last edited by victim; 17 February 2010 at 00:21.
victim is offline  
Old 16 February 2010, 23:22   #12
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Just use 64 bytes wide bitplanes (or 32 even if you don't need a wide screen) and do a shift instead, it's simple and fast.
Leffmann is offline  
Old 16 February 2010, 23:53   #13
hitchhikr
Registered User
 
Join Date: Jun 2008
Location: somewhere else
Posts: 511
Yes, using a single shift whenever possible will always be faster than with a pre-calculated table, if you can't use that for whatever reason then make sure the table is located at less than 128 bytes from the accessing instruction and use something like :

Code:
            move.w   MulTabY(pc,d1.w*2),d1
sparing you a register.

Notice that it will probably be faster to use a series of shifts on 68020+ processors and faster to use precalc tables on plain 68000.
hitchhikr is offline  
Old 17 February 2010, 00:25   #14
victim
Registered User
 
Join Date: Mar 2009
Location: N/A
Posts: 23
Quote:
Originally Posted by hitchhikr View Post
Yes, using a single shift whenever possible will always be faster than with a pre-calculated table, if you can't use that for whatever reason then make sure the table is located at less than 128 bytes from the accessing instruction and use something like :

Code:
            move.w   MulTabY(pc,d1.w*2),d1
sparing you a register.

Notice that it will probably be faster to use a series of shifts on 68020+ processors and faster to use precalc tables on plain 68000.

Correct, small but nice. I have changed the top

so long...
victim
victim is offline  
Old 21 October 2010, 21:40   #15
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Watcha chaps

It's a long time since I messed around with any plotting but today I made a new plotter and I've been testing it out.

I'm going for all out speed with this one so I've used shifts and tables and gotten the main plotting loop down to 8 instructions.

Doing a rough speed test by just plotting a pixel to the screen over and over I can do 1134 iterations of the plotting loop in one frame.

Now, this is a vast improvement over the circa maximum 300 or so plots per frame that my very first plotting routine could do but obviously the total won't really be as high as that once I add in required things like clearing the screen, double buffering and some kind of nice method of deciding where to plot the pixels so they make pretty patterns.

So, two questions:

1. Are there any other tricks or cheats (other than using lookup tables) to get even more plots per frame...?

2. If not, how are there oldskool demos out there where the coder claims things like 3000 or 10,000 () or whatever plots per frame...?
pmc is offline  
Old 22 October 2010, 10:53   #16
WayneK
Registered User
 
Join Date: May 2004
Location: Somewhere secret
Age: 50
Posts: 364
I guess they're cheating in various ways like taking advantage of symetry/mirroring, only doing one of X/Y calcs per frame (X even, Y odd VBLs), or triple-buffering and using a previous frames 'dots' as a trail/'blur' etc... (since it's already been calced/plotted) - there must be other cheats but it's early and I haven't had coffee yet
WayneK is offline  
Old 22 October 2010, 12:58   #17
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
Nice one WayneK

I'll add these to my ever growing "things to do coding experiments with" list.
pmc is offline  
Old 24 October 2010, 03:05   #18
Plagueis/KRX
coder
 
Plagueis/KRX's Avatar
 
Join Date: Jul 2009
Location: a galaxy far far away
Age: 49
Posts: 84
Wow, so this is where the cool stuff is going on, on EAB....I don't know how I've been missing it all. Hey Paul! Could you send me an exe of that dot plotter flag to my email address? Thanks.
Plagueis/KRX is offline  
Old 24 October 2010, 19:29   #19
pmc
gone
 
pmc's Avatar
 
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
I will do Brett, as soon as we're finished at the hospital - just waiting to leave - our little son was born yesterday! \o/
pmc is offline  
Old 24 October 2010, 19:37   #20
TCD
HOL/FTP busy bee
 
TCD's Avatar
 
Join Date: Sep 2006
Location: Germany
Age: 46
Posts: 31,522
Quote:
Originally Posted by pmc View Post
little son was born yesterday! \o/
Congratulations pmc Hope your wife and son are fine.
TCD is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Flag by Gremlin BippyM project.aGTW 43 22 December 2010 22:24
ASCII and Experimental Epson Dot Matrix Printer Emulation AmigaBoingBall support.WinUAE 1 27 May 2009 18:39
save flag Marcuz HOL suggestions and feedback 1 08 September 2006 01:18
Almost Free Color Dot Matrix Printer IBM/AMIGA le geek MarketPlace 0 06 May 2004 00:48

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 04:15.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09625 seconds with 13 queries