DEBRO Posted January 2, 2016 Share Posted January 2, 2016 Hi there, Why would some AtariBASIC programs use PEEK(632) to read the joystick instead of the built in command of STICK(0) Wouldn't the STICK(0) command save a byte? Quote Link to comment Share on other sites More sharing options...
phaeron Posted January 2, 2016 Share Posted January 2, 2016 I'm guessing by misconception more than anything else. PEEK(632) takes the same space as STICK(0) once the line is tokenized, 10 bytes. Atari BASIC doesn't put the function names in the program -- it stores a token byte for the function instead. You can save more space in the input line you type in with one over the other, but that only matters if you're cramming so much into a line you're up against the raw 3-line limit. Speed-wise, the difference is negligible. I found at least one reference that says that PEEK(632) is faster -- http://www.atariarchives.org/pmgraphics/chapter5.php-- but the actual difference in the interpreter is tiny. PEEK() is faster by about a dozen machine cycles when executing a single BASIC statement takes thousands. 2 Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 3, 2016 Share Posted January 3, 2016 My thought was that STICK was quicker due to less complex FP numbers converting to 16-bit binary slightly faster. I suppose the advantage is lost given that Basic then has to add the result to 632 before doing the lookup. One method that can be used to speed up Basic programs is using PTRIG to assist with horizontal movement. Since the paddle buttons are just stick left/right you can subtract one from the other to give the current direction delta - the result you end up with is -1, 0 or 1. 1 Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted January 3, 2016 Share Posted January 3, 2016 Another way to speed up programs, is to use constants. TurboBASIC has built in constants %0, %1, and %2, but if you are using Atari BASIC, you can do this: 0 K0=0: K1=1: K2=2 Then replace 0 with K0 everywhere you see it. e.g. STICK(K0) Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 3, 2016 Share Posted January 3, 2016 Variable access is slower than constants with Atari Basic at least. Not by a lot but enough to be an incentive to use constants in speed critical loops etc. The saving though is in memory, once a variable is referenced a few times the memory savings start to build up. Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted January 3, 2016 Share Posted January 3, 2016 Also, the advantage to using PTRIG for left-right movement, is you get to use nice things like this: IF PTRIG(0) THEN ... IF NOT PTRIG(0) THEN ... which is a huge memory and space saver. 1 Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 3, 2016 Share Posted January 3, 2016 Using boolean rather than IF/THEN can be a huge speedup too. e.g. rather than S=STICK(0) : IF S=14 THEN Y=Y-1 IF S=13 THEN Y=Y+1 you could have S=STICK(0) : Y=Y-(S=14)+(S=13) 4 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.