Jump to content
IGNORED

A Little Fast Basic Help, Please...


Recommended Posts

...I suppose it is applicable across different versions of BASIC, but I'm working in the newest version of Fast Basic V4.5RC1 from @dmsc.

 

This is just a test, moving a character across a GR.12+16 screen. I am using PEEK(632), as it is ~30% faster and POKEing the character directly to the screen. All works as expected, except when moving right. Using the inbuilt POSITION works fine.  I'm a chronic insomniac and having a severe brain fart right now and can't see what is wrong. I know if it was a snake it would've bitten me by now.

 

Could someone point me to my error, please? :) 

 

' some variables are
' for later
' OX/OY are old X/y
' 
X=20:Y=12:OX=X:OY=Y
MF=0:XMF=0:YMF=0
XF=0:YF=0


GRAPHICS 12+16

SCR=DPEEK(88)

' set the char to the initial position
DPOKE SCR+(Y*40)+X,65

DO

ST=PEEK(632)

XF=-(ST=9 OR ST=10 OR ST=11)+(ST=5 OR ST=6 OR ST=7)
YF=-(ST=6 OR ST=10 OR ST=14)+(ST=5 OR ST=9 OR ST=13)

X=X+XF:Y=Y+YF
IF X<0 THEN X=39
IF X>39 THEN X=0
IF Y<0 THEN Y=23
IF Y>23 THEN Y=0


' * * * * * * * * * *
' NEW AND OLD
' POSITIONS

NP=SCR+(Y*40)+X
OP=SCR+(OY*40)+OX
IF OX<>X OR OY<> Y
  MF=1
 ELSE 
 MF=0

ENDIF


IF MF 
 PAUSE 0
 DPOKE NP,65
 DPOKE OP,0

'  * * * * * * * * * *
' THIS WORKS FINE
'POS.X,Y:?#6,"A";
'POS.OX,OY:?#6;" ";
ENDIF

OX=X:OY=Y

LOOP

 

 

Regards,

Mark

FBASIC4.5RC1.zip

Link to comment
Share on other sites

Nice to see that FastBasic is being used... Note that final version 4.5 was released.

 

The problem is that you are using DPOKE, which writes 2 bytes on screen, but you are moving just one byte at a time. When you DPOKE to OP, you are clearing both OP and NP when you move to the right. That does not happen if you move diagonally to the right because of the change on Y. Use POKE instead.

 

You can use DPOKE to write wide sprites in graphics modes like 13+16 as I did in Mini Bros

 

BTW, try using binary operations to test for joystick directions:

XF=(ST&8=0)-(ST&4=0)

 

 

Edited by vitoco
  • Like 1
Link to comment
Share on other sites

Just a little thing I spotted that bugs me :)

 

 

XF=-(ST=9 OR ST=10 OR ST=11)+(ST=5 OR ST=6 OR ST=7)
YF=-(ST=6 OR ST=10 OR ST=14)+(ST=5 OR ST=9 OR ST=13)

can be written 

 

 

XF=(ST=5 OR ST=6 OR ST=7)-(ST=9 OR ST=10 OR ST=11)
YF=(ST=5 OR ST=9 OR ST=13)-(ST=6 OR ST=10 OR ST=14)

 

  • Haha 1
  • Confused 1
Link to comment
Share on other sites

Can make screen vertical variable a multiple of 40 and avoid the ' *40 ' in the program.

Can make a table for delta x and delta y for the joystick.

JoyDeltaX

 00 00 00 00 00 -1 -1 -1 00 01 01 01 00 00 00 00

JoyDeltaY

 00 00 00 00 00 -40 40 00 00 -40 40 00 00 -40 40 00

 

If you cut down the multiplies and divides inside your program, things move faster.

 

 

  • Like 2
Link to comment
Share on other sites

3 hours ago, CuloMajia said:

Can make screen vertical variable a multiple of 40 and avoid the ' *40 ' in the program.

Can make a table for delta x and delta y for the joystick.

You are right, but it only works on closed playfields. If you need to warparound, X and Y are required, or you'd have to DIV and MOD (the opposite operations to *) the screen variable to check for playfield limits.

 

  • Like 1
Link to comment
Share on other sites

On 3/12/2021 at 5:00 AM, vitoco said:

Nice to see that FastBasic is being used... Note that final version 4.5 was released.

 

The problem is that you are using DPOKE, which writes 2 bytes on screen, but you are moving just one byte at a time. When you DPOKE to OP, you are clearing both OP and NP when you move to the right. That does not happen if you move diagonally to the right because of the change on Y. Use POKE instead.

 

You can use DPOKE to write wide sprites in graphics modes like 13+16 as I did in Mini Bros

 

BTW, try using binary operations to test for joystick directions:


XF=(ST&8=0)-(ST&4=0)

 

 

Ahh, I see now, thank you! Man, I hadn't slept in almost two days when I was working on that and it was driving me mad :)

 

I generally use binary operations, but hadn't stuck them in yet.

Link to comment
Share on other sites

12 hours ago, CuloMajia said:

Can make screen vertical variable a multiple of 40 and avoid the ' *40 ' in the program.

Can make a table for delta x and delta y for the joystick.

JoyDeltaX

 00 00 00 00 00 -1 -1 -1 00 01 01 01 00 00 00 00

JoyDeltaY

 00 00 00 00 00 -40 40 00 00 -40 40 00 00 -40 40 00

 

If you cut down the multiplies and divides inside your program, things move faster.

 

 

Great idea, Culo! I can do whatever needs to be done :) There are a couple of games that I've been working on a little bit here and there, but this isn't part of it except for..... this was just a quick exercise to see how much quicker it was to use PEEK(632) vs STICK(0), so as to have more time to other stuff in the main loop on one game. It is more than 30% faster to just read 632 than use STICK(0). Now that you guys have helped me, I will also try it on the cross compiler version later this evening and gain some more :)

 

As far as the different screen widths, the one thing I've working on is something like Cosmic Ark for the Atari 2600. It will use GR.1.

Link to comment
Share on other sites

Just in case someone comes across this thread in the future, some quick results testing the above (removing the synchronizing PAUSE above) and using a simple WHILE TIME<900 [15 seconds] WEND loop and moving the joystick for the entire time. Fast Basic V4.5...

 

Using binary operations for the flag variables XF/YF

XF=(ST&8=0)-(ST&4=0)
YF=(ST&2=0)-(ST&4=1)

 

averages 1,965 iterations in 15 seconds over three runs

 

using the code as listed in OP averages 1,598 iterations in 15 seconds over three runs

 

Using binary operations and the Windows cross compiler averages 2,296 iterations in 15 seconds over three runs

 

 

 

 

Link to comment
Share on other sites

On 3/12/2021 at 10:22 AM, Preppie said:

Just a little thing I spotted that bugs me :)

 

 


XF=-(ST=9 OR ST=10 OR ST=11)+(ST=5 OR ST=6 OR ST=7)
YF=-(ST=6 OR ST=10 OR ST=14)+(ST=5 OR ST=9 OR ST=13)

can be written 

 

 


XF=(ST=5 OR ST=6 OR ST=7)-(ST=9 OR ST=10 OR ST=11)
YF=(ST=5 OR ST=9 OR ST=13)-(ST=6 OR ST=10 OR ST=14)

 

I don't recall why I started doing it that way. Just three or four weeks ago I found some old code on a floppy from late 88 or early 89 (saved on an XF551, which I bought very soon after they were released in the U.S.A.) and it was similar back then.

 

Now I will always remember Preppie when working on this stuff :)

  • Like 1
Link to comment
Share on other sites

On 3/14/2021 at 7:36 AM, vitoco said:

should be


XF=(ST&8=0)-(ST&4=0)
YF=(ST&2=0)-(ST&1=0)

 

:) ..I just typed it incorrectly here, but had it correctly in my code, but thank you in any case, vitoco.

 

Now that I got a little sleep and are feeling a bit better health wise, time to play around with this little project some more and mess about with using the old TextPlot machine language code from Compute's First Book of Atari Graphics.

 

Have a great evening!

 

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...