Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


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

Registered: Jan 2002
Posts: 2929
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: 2594
<3 for BASIC weidos! :-)
2019-06-26 09:02
ChristopherJam

Registered: Aug 2004
Posts: 1409
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: 2594
@CJ: That's the spirit! :)
2019-06-27 05:48
Oswald

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

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

Registered: Aug 2004
Posts: 15
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: 122
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: 1409
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
Account closed

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

Registered: May 2010
Posts: 126
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
Freeze/Blazon
Malmix/Fatzone
Docster/Megastyle
E$G/HF ⭐ 7
2bt
Didi/Laxity
Magic/Nah-Kolor
Guests online: 134
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.6)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 Uncensored  (9.6)
7 The Demo Coder  (9.6)
8 Comaland 100%  (9.6)
9 What Is The Matrix 2  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.7)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Dawnfall V1.1  (9.5)
6 Rainbow Connection  (9.5)
7 Morph  (9.5)
8 Libertongo  (9.5)
9 Onscreen 5k  (9.5)
10 It's More Fun to Com..  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Oxyron  (9.3)
3 Performers  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Stormbringer  (10)
3 Booze  (9.7)
4 Fungus  (9.7)
5 Grim Reaper  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.053 sec.