| | 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 |
|
| | bugjam
Registered: Apr 2003 Posts: 2594 |
<3 for BASIC weidos! :-) |
| | 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/ |
| | bugjam
Registered: Apr 2003 Posts: 2594 |
@CJ: That's the spirit! :) |
| | Oswald
Registered: Apr 2002 Posts: 5095 |
CJ, nerdgasm. release it please :) |
| | ChristopherJam
Registered: Aug 2004 Posts: 1409 |
Done!
Plant 2.4x |
| | 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 |
| | 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 |
| | 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) |
| | Rastah Bar Account closed
Registered: Oct 2012 Posts: 336 |
Turning off interrupts? |
| | Rudi
Registered: May 2010 Posts: 126 |
how is
x and 504 different thanx and 248 ? (in that code specifically?) |
... 6 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 - Next | |