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: 2884
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: 2467
<3 for BASIC weidos! :-)
2019-06-26 09:02
ChristopherJam

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

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

Registered: Aug 2004
Posts: 1359
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: 1359
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: 336
Turning off interrupts?
2019-07-05 03:10
Rudi
Account closed

Registered: May 2010
Posts: 125
how is
x and 504
different than
x and 248
? (in that code specifically?)
2019-07-05 16:47
ChristopherJam

Registered: Aug 2004
Posts: 1359
Rudi - you need 504 ($01f8) to support X values greater than 255

That said, -8 also works to clear the low three bits, and a quick test shows it's considerably faster! I guess it avoids a couple of multiply-by-10s in the parser.

I just compared
a=ti:fori=1to1000:j=iand-8:next:?ti-a
to
a=ti:fori=1to1000:j=iand504:next:?ti-a

The latter is around 420 ticks, compared to 320 for the former.
2019-07-07 06:06
Rudi
Account closed

Registered: May 2010
Posts: 125
ok neat
2019-07-07 21:54
bugjam

Registered: Apr 2003
Posts: 2467
*waitingfornewversion* :-)
2019-07-08 04:24
Rudi
Account closed

Registered: May 2010
Posts: 125
bugjam: ChristopherJam is the Master of size and speed optimizing Basic programs so let him do it :) I can come up with wrong ideas that will lead to some lesser ticks perhaps, but.
2019-07-08 22:36
bugjam

Registered: Apr 2003
Posts: 2467
Don't be too modest, you triggered the whole thing, which is an achievement as well. :-)
2019-07-09 02:41
Rudi
Account closed

Registered: May 2010
Posts: 125
Thanks bugjam.
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
Derision/Longshot
ϵʟʞ/ₐтₐ
Yugorin/Samar Produc..
Low Spirit
Inge/HVSC
McMeatLoaf
bugjam
TMA/Abyss-Connection
Laurikka
Krill/Plush
Holy Moses/Role
celticdesign/G★P/M..
t0m3000/ibex-crew
Shogoon/Elysium/MSL
Guests online: 321
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 No Bounds  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 The Ghost  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 Party Elk 2  (9.7)
2 Cubic Dream  (9.6)
3 Copper Booze  (9.5)
4 Rainbow Connection  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Onscreen 5k  (9.5)
7 Dawnfall V1.1  (9.5)
8 Quadrants  (9.5)
9 Daah, Those Acid Pil..  (9.5)
10 Birth of a Flower  (9.5)
Top Groups
1 Booze Design  (9.3)
2 Nostalgia  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Crackers
1 Mr. Z  (9.9)
2 S!R  (9.9)
3 Mr Zero Page  (9.8)
4 Antitrack  (9.8)
5 OTD  (9.8)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.056 sec.