Then in Forth only I implemented a lookup table for the Y offsets. This was actually a bit slower when I still used a Y*2 to index through the array (an array of 16bit values). When I did a left shift instead of multiplications it was much faster!
The closest comparison denoted in the comments below are the 'linear' test and the 'X,Y X+Y*40' tests. The 'start' and 'stop' functions in the code below are a Forth module that uses the C64 Jiffy timer to let you profile your code optimizing to execution time. The Forth code below is only the last test ( 0.766 X,Y luY w/Screen added to yoff ) but I'm guessing you know what the other code would have looked like.
Code: Select all
400 constant Screen
00 constant Minscr
3E8 constant Maxscr
91 constant Up
11 constant Down
9D constant Left
1D constant Right
variable scrn 400 scrn !
variable xpos 0 xpos !
variable ypos 0 ypos !
( creates array of screen Y offset values )
( i.e. 0400 0428 0450 )
create yoff 32 allot
: cfgyoff
19 0 do
I 28 * Screen + ( value )
I 2 * yoff + ! ( index address )
loop
;
( retrieves Y value from yoff array )
( adds in xpos and stores 'a' to screen )
: plotline3
28 0 do
I xpos !
1 ypos @ 1 lshift yoff + @
xpos @ + c!
loop
;
( Linear is loop 0-1000 )
( X,Y is loop Y, loop X )
( 9s BASIC linear )
( 15s Basic X,Y X+Y*40 )
( 0.283s Forth linear )
( 2.133s X,Y X+40*40
( 2.316s X,Y lookup Y w/Y*2 )
( 0.833s X,Y lookup Y w/Y<<1 )
( 0.766 X,Y luY w/Screen added to yoff )
: plotxy2
cfgyoff
page start
19 0 do
I ypos !
plotline3
loop
stop ." s" cr
;
Code: Select all
10 TIME$ = "000000":rem reset clock
20 rem 'linear' test
30 rem for i = 0 to 1000
40 rem poke 1024+i,1
50 rem next i
60 rem
70 rem X,Y test
80 for y = 0 to 25
90 for x = 0 to 40
100 poke 1024+y*40+x, 1
110 next x
120 next y
130 print TIME$