Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user ediman ! (Registered 2019-07-15) You are not logged in 
CSDb User Forums


Forums > CSDb Entries > Release id #178956 : Plant
2019-06-23 05:55
Moloch

Registered: Jan 2002
Posts: 2052
Release id #178956 : Plant

Submitted by Compyx [PM] on 23 June 2019
Probably this (from Lemon64 of all places):

There is an even better way to do it - let's abuse the DIM-command!!

Since DIM normally clears an array, why not use it for clearing a bitmap as well?

Try this:
POKE 88,0:POKE 89,63:POKE 113,64:POKE 114,31:POKE 12,1:SYS 45760

This will fill memory from 8192-16191 ($2000-$3F3F) will nullbytes.

- Catboy


Fucking BASIC weirdos :)

User Comment
Submitted by Oswald [PM] on 22 June 2019
IIRC you can clear memory faster with declaring a large array :)

User Comment
Submitted by Oswald [PM] on 22 June 2019
80 mem=8192+int(v/8)*320+int(u/8)*8+(vand7):pokemem,peek(mem)or2^(7-(uand7))

lol :D
2019-06-23 21:11
bugjam

Registered: Apr 2003
Posts: 1709
<3 for BASIC weidos! :-)
2019-06-26 09:02
ChristopherJam

Registered: Aug 2004
Posts: 941
More basic weirdoing:


Plot is faster by taking advantage of AND casting operands to integers, and avoiding some of the shifting and masking thusly:
mem=8192+(vand248)*39+v+(uand504):pokemem,peek(mem)or2^(7-(uand7))


That said, it's faster still to replace the calculations with table lookups (the 2^(7-(uand7)) alone takes 30ms longer than an array lookup), so you can get a further speed increase with
mem=b(y)+(xand504):pokemem,peek(mem)orm(x)


Some of the coordinate transform math can be avoided by working directly in screen coordinates.

The code as writ performs
(1) X' = M * X (with X' = [x,y,1], and M containing one of the four transforms)
then
(2) U' = T * X' (determining screen coordinates U from current state X)
having previously performed
(3) U = T * X (hence, X = inv(T) * U )
hence
(4) X = inv(T) * U

substitute (1) into (2):
(5) U' = T * M * X

and (4) into (5):
(6) U' = T * M * inv(T) * U

So, replace each M with T * M * inv(T) and the 'next point' calculation becomes
w=f0(i)*x+f1(i)*y+f4(i):y=f2(i)*x+f3(i)*y+f5(i):x=w


(oh, I also replaced f(i,j) with fj(i), it's a little quicker to parse).

The transform index i can be calculated with an expression instead of a sequence of if statements if we take advantage of conditionals evaluating to -1 for true, zero for false:
r=rnd(0):i=-(r>c)-(r>b)-(r>a)


Filling colour memory can be done quickly by printing a few strings; if we print 37 strings of length 27 that covers the first 999 chars without scrolling in a new line at the end. Hence,
print"{clr}";:fori=1to27:print"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP";:nex t:poke2023,80


We do the DIM clearing for the bitmap just by making one of the plotting tables much bigger than required.


Move the main loop to the start so the goto is faster, and strength reduce the initialisation loops for the plotting tables, and we get this:
10 gosub 100
20 r=rnd(0):i=-(r>c)-(r>b)-(r>a)
30 w=f0(i)*x+f1(i)*y+f4(i):y=f2(i)*x+f3(i)*y+f5(i):x=w
40 mem=b(y)+(xand504):pokemem,peek(mem)orm(x)
50 goto 20
100 rem *** Plant by Rudi - 22.06.2019 ***
102 rem *** optimised by cjam (2.4x faster) ***
105 rem *** takes approx 200 million years to compute ***
110 dimf0(3),f1(3),f2(3),f3(3),f4(3),f5(3),p(3),m(4000),b(200)
120 poke 53265,11
122 print"{clr}";:fori=1to27:print"PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP";:next:poke 2023,80
125 fori=0to3:readp(i):next:fore=0to3:readf0(e),f1(e),f2(e),f3(e),f4(e),f5(e):next
130 t=1:forx=0to7:m(7-x)=t:t=t+t:b(x)=8192+x:next
135 fory=8to199:b(y)=b(y-8)+320:next
140 forx=8to319:m(x)=m(x-8):next
155 x=14.54:y=112.5:a=p(0):b=p(1)+a:c=p(2)+b
157 poke53272,29:poke53265,59:poke53280,0
160 return
200 data 0.01, 0.85, 0.07, 0.07 : rem probabilities
210 data 0.16, 0.00, 0.00, 0.00, 0.00, 100.00 :rem transforms
220 data 0.85, -0.05, -0.02, 0.83, 51.20, 17.00
230 data 0.22, 0.27, -0.22, 0.20, 19.78, 80.00
240 data 0.24, 0.30, 0.24, -0.15, -17.45, 115.00


Initialisation now takes a shade under nine seconds, and the number of iterations per second has been increased from 5.7 to 13.6 \o/
2019-06-27 00:35
bugjam

Registered: Apr 2003
Posts: 1709
@CJ: That's the spirit! :)
2019-06-27 05:48
Oswald

Registered: Apr 2002
Posts: 4414
CJ, nerdgasm. release it please :)
2019-06-27 09:52
ChristopherJam

Registered: Aug 2004
Posts: 941
Done!
Plant 2.4x
2019-06-27 12:44
Broti

Registered: Aug 2004
Posts: 14
Maybe some further improvements:

- remove REMs and Whitespaces
- replace MEM (line 40) with sth. like MM (since only the first two letters are relevant for BASIC)
- replace 0 with . (slightly faster iirc)
- Use line limit if possible
2019-06-27 13:30
Trash

Registered: Jan 2002
Posts: 117
Further optimization may be to dim more frequently used variables later (or earlier), not sure but I am pretty sure the order affects the speed IIRC
2019-06-27 15:00
ChristopherJam

Registered: Aug 2004
Posts: 941
The REMs are all after the mainloop so I suspect they wouldn't things change much, but I was indeed wondering about dropping all the active variables down to a single letter.

I forgot about the fast parsing of "." as 0; think I saw that somewhere too.

Trash, that's an excellent point about predeclaring variables; probably applies to the scalars as much as the arrays.

Anyone want to measure the effect of any of these?

(I was initially benchmarking by checking TI before and after a thousand iterations, but counting iterations affects the timing, so at some point I switched to setting a watch in VICE on writes to 2000-3fff, then counting ten iterations and calculating the difference in the cycle counter you get in the monitor)
2019-06-28 21:00
Rastah Bar

Registered: Oct 2012
Posts: 172
Turning off interrupts?
2019-07-05 03:10
Rudi

Registered: May 2010
Posts: 108
how is
x and 504
different than
x and 248
? (in that code specifically?)
 
... 6 posts hidden. Click here to view all posts....
 
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
E$G/HoKuTo FOrCE
60Force
Dymo/G★P
zscs
JCH/Vibrants
Pantaloon/Fairlight
Perff/No Name
Exploding Fi../Techn..
ZeSmasher/F4CG
the pro/excess
aNdy/AL/Cosine
emarti
sailor/Triad
Guests online: 24
Top Demos
1 Unboxed  (9.7)
2 Uncensored  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 The Shores of Reflec..  (9.6)
7 Lunatico  (9.6)
8 Wonderland XII  (9.5)
9 C=Bit 18  (9.5)
10 X Marks the Spot  (9.5)
Top onefile Demos
1 Smile to the Sky  (9.5)
2 Dawnfall V1.1  (9.5)
3 Crystal Gazer  (9.5)
4 Daah, Those Acid Pil..  (9.5)
5 Rewind  (9.5)
6 Instinct  (9.5)
7 Pandemoniac Part 5 o..  (9.5)
8 Innervasion  (9.4)
9 Bad Boy  (9.4)
10 Arok 20 Invitation  (9.4)
Top Groups
1 Fossil  (9.8)
2 PriorArt  (9.7)
3 Performers  (9.6)
4 Oxyron  (9.4)
5 Booze Design  (9.4)
Top Crackers
1 Mr. Z  (10)
2 OTD  (9.9)
3 Mr Zero Page  (9.9)
4 S!R  (9.8)
5 Gollum  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2019
Page generated in: 0.063 sec.