Reaperman Posted March 3, 2014 Share Posted March 3, 2014 (edited) I'm learning basic and I've made a small paint program to teach myself more about how it works. As I add complexity, I seem to be encountering more and more 'oddities.' I'm hoping that somebody here can have a look at what I'm doing and correct me on it. I'm using turbobasic xl 1.5 with altirra and the 600xl/800xl firmware rom. Below is the code: 100 GRAPHICS 7+16 150 C=2:X=80:Y=48:OT=1:FR=1 300 S=STICK(0):COLOR C 450 X=X+(X<159)*(S=7 OR S=6 OR S=5)-(X>0)*(S=11 OR S=9 OR S=10) 500 Y=Y-(Y>0)*(S=10 OR S=14 OR S=6)+(Y<95)*(S=13 OR S=9 OR S=5) 650 IF STRIG(0)=0 AND OT=1 THEN C=C+1 660 IF STRIG(0)=0 AND OT=1 THEN SOUND 0,250,10,1:FR=1 670 IF FR>=10 THEN SOUND 700 OT=STRIG(0) 750 IF C=4 THEN C=1 800 PLOT X,Y:FR=FR+1 850 IF INKEY$=" " THEN 100 860 IF INKEY$="Q" THEN 1000 900 GOTO 300 1000 END list of issues: lines 850&860 the spacebar to clear the image works great every time. The 'q' to quit very rarely (but occasionally) works. for a while I thought that inkey$ might be cleared at the first access so for a while I dumped it into a string with exactly the same result. What gives? lines 650&660 these should trigger on the same loop, and do *most* of the time. Their goal is to change the color of the line drawn as well as play a sound. The 'ot' variable is my attempt to track and compare with the trigger on the last loop so the color doesn't constantly change when held down. I could put them on the same line (they used to be) however that doesn't really solve the problem as some trigger presses do nothing. lines 660&670 The atari examples for playing sounds with a loop for delay are beyond useless. Tracking the number of loops in the 'fr' variable was the best I could think up, but there has to be a better way. How do you guys play sounds for more than a single loop and less than forever? Edited March 3, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted March 3, 2014 Share Posted March 3, 2014 Firstly, make sure you do a POKE 764,255 before reading INKEY$. This clears out the keyboard buffer. Another thing to try is using peek(19) or dpeek(19) to read the system timer, and use that to time your sound duration. I would also add an OT=0 after the two if - then lines in 650 and 660, this should get the triggers to work properly. 1 Quote Link to comment Share on other sites More sharing options...
Kyle22 Posted March 3, 2014 Share Posted March 3, 2014 Very interesting... If I put 355 if peek($D01f)<>7 then 1000 in there, then it stops immediately when I press a console key. Even if I poke 764,255, and then if peek(764)<>255 then 1000, it takes a while before it stops. fascinating.... 1 Quote Link to comment Share on other sites More sharing options...
Kyle22 Posted March 3, 2014 Share Posted March 3, 2014 Upon further examination, it seems that the TB INKEY$ may cause a problem with reading the keys quickly. The HELP key at $02DC (732) reads immediately, as does CONSOL $D01F (53279). If you do away with the INKEY$ statements, and just peek the CH $2FC (764) or KBCODE $D209 (53769), you may have better luck. Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 3, 2014 Author Share Posted March 3, 2014 (edited) I would also add an OT=0 after the two if - then lines in 650 and 660, this should get the triggers to work properly. same thing, but I now think that I must be hitting the trigger in the instant between the two strig tests (because I occasionally hear a beep but no color change). combining them into one line really would help that. (or dumping to a string and testing that instead) There are still times I feel I've hit the button and neither of them happens--but this may be emulation, I'll have to try it on the real thing. Upon further examination, it seems that the TB INKEY$ may cause a problem with reading the keys quickly. The HELP key at $02DC (732) reads immediately, as does CONSOL $D01F (53279). If you do away with the INKEY$ statements, and just peek the CH $2FC (764) or KBCODE $D209 (53769), you may have better luck. I'm going to have to look into these peek/poke statements--I had hoped to avoid the learning curve associated with them for at least a few weeks, but it doesn't seem like that can be helped. That line 355 does the trick, though. I'll have to go look up exactly what it's doing now. Edited March 3, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 3, 2014 Author Share Posted March 3, 2014 (edited) Well, I tried moving the trigger into a variable and that made it about a million times worse, for some reason. (lines 300 and 650) Are there times in my loop where input from the controller might be totally ignored? I bet it's also not great that I have a stick variable... edit: nevermind the above, I missed line 700. Trigger works much better as a variable. I think I've been staring at this too long, I'm making stupid mistakes. 50 REM JOYSTICK PAINTER V1.3 100 GRAPHICS 7+16 150 C=2:X=80:Y=48:OT=1:FR=1 300 S=STICK(0):TR=STRIG(0):COLOR C 355 IF PEEK($D01F)<>7 THEN 1000 450 X=X+(X<159)*(S=7 OR S=6 OR S=5)-(X>0)*(S=11 OR S=9 OR S=10) 500 Y=Y-(Y>0)*(S=10 OR S=14 OR S=6)+(Y<95)*(S=13 OR S=9 OR S=5) 650 IF TR=0 AND OT=1 THEN C=C+1:SOUND 0,250,10,1:FR=1 670 IF FR>=10 THEN SOUND 700 OT=TR 750 IF C=4 THEN C=1 800 PLOT X,Y:FR=FR+1 850 IF INKEY$=" " THEN 100 900 GOTO 300 1000 END Edited March 3, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted March 3, 2014 Share Posted March 3, 2014 Try this: Remove line 700, change 650 to this: 650 IF TR=0 AND OT=1 THEN C=C+1:SOUND 0,250,10,1:FR=1:OT=0 Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 3, 2014 Author Share Posted March 3, 2014 (edited) Try this: Remove line 700, change 650 to this: 650 IF TR=0 AND OT=1 THEN C=C+1:SOUND 0,250,10,1:FR=1:OT=0 It needs something to tie TR and OT together, or OT will get stuck at 0 and the 'if' at 650 never gets triggered a second time (it's set to 1 on initialize, which gets it there the first time). After my edit above (which tied line 700 to tr vs strig(0)), I really think it's now working about as well as can be expected as far as the trigger goes. Switching to a variable made quite a lot of difference. My trigger doesn't seem to get ignored at any point now. Wow is this fiddly. Edited March 3, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
+therealbountybob Posted March 3, 2014 Share Posted March 3, 2014 To delay sounds or make them last longer while maintaining your loop you can use a variable and incremement it by a fraction such as NOTE=NOTE+0.05 Stupid Mistakes = valuable learning Do we have another candidate for the 10 Liner Contest? Hope so 1 Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 4, 2014 Author Share Posted March 4, 2014 (edited) Do we have another candidate for the 10 Liner Contest? Hope so It's funny you should mention that, because I'm back with two more problems...that happen to be on an extremely short game... first one's got to be super easy: what do I do to keep the screen from changing colors after a while? I've got something that's a reasonably active stick/trigger game, but that doesn't seem to be enough to keep the system from thinking that it's idle. there must be a poke for this. is there a handy online list of these? second question. also probably easy. On lines 200 and 700, I poke 752,1 which should hide my cursor. It works great when I just type the poke in without a line number. Not so well in game. on my first pass through, it prints the line 200 stuff with a cursor at the bottom (bad), then it hits line 700 and prints out that text with a cursor at the bottom (also bad) but then what gets me, is that after the first game ends it loops back and prints out the line 200 stuff beautiful and cursor-free but the line 700 stuff still has that cursor. Experimenting with it--it's actually the line 700 poke that seems to be doing the deed for line 200's second+ pass. What am I doing wrong here? Is it the wrong poke. I "borrowed" it from some solid code... Code below seems to play great outside of those two issues. I've even got a whole line that I haven't even used yet, and I've started wasting space putting my name in it. 100 GR.7:X=80:Y=66:OX=80:OY=66:D=1:W=0:F=1:P=0:H=0:DIM G$(24):G$="DODGE RACER":DIM N$(17):DIM J$(7):J$="SCORE: " 150 CO.1:PL.3,70:DR.155,70:DR.155,33:DR.112,33:DR.112,4:DR.3,4:DR.3,70:PL.18,55:DR.140,55:DR.140,48:DR.97,48 200 DR.97,19:DR.18,19:DR.18,55:CO.2:PAI.0,0:SOUND 0,0,0,0:PAI.19,20:? G$ J$;P:? " HIGH: ";H:POKE 752,1 250 N$="GAME BY REAPERMAN":T=STRIG(0):IF T=0:SO.0,60,2,2:GOTO 300:ENDIF:GOTO 250 300 S=STICK(0):IF S=7:D=1:ENDIF:IF S=11:D=2:ENDIF:IF S=14:D=3:ENDIF:IF S=13:D=4:ENDIF:A=RAND(155) 310 B=RAND(70):IF D=1:X=X+1:ENDIF:IF D=2:X=X-1:ENDIF:IF D=3:Y=Y-1:ENDIF:IF D=4:Y=Y+1:ENDIF 400 LOCATE A,B,L:IF L=0 AND F>10:CO.1:PLOT A,B:SO.1,50,4,4:F=1:P=P+10:CLS:IF P>=H:H=P:ENDIF:SO.1,0,0,0:ENDIF 500 LOCATE X,Y,W:IF W=1:GOTO 700:ENDIF:IF F=0:P=0:ENDIF:CO.2:PL.X,Y:CO.0:PL.OX,OY:OX=X:OY=Y:F=F+1:GOTO 300 700 GR.7:? N$:SO.0,20,0,6:X=80:Y=66:OX=80:OY=66:D=1:W=0:F=0:G$="GAME OVER":POKE 752,1:GOTO 150 variable decoder key: X = X POSITION Y = Y POSITION OX = 'OLD' X POSITION OY = 'OLD' Y POSITION D = DIRECTION (1=RIGHT, 2=LEFT, 3=UP, 4=DOWN) W = COLOR VARIABLE FOR CRASH LOCATOR L = COLOR VARIABLE FOR JUNK PLACEMENT S = STICK 0 T = TRIG 0 P = POINTS H = HIGH SCORE F = FRAME DELAY A = RANDOM X VALUE B = RANDOM Y VALUE G$ = "DODGE RACER" J$ = "SCORE: " U = SOUND LOOP N$ = "GAME BY REAPERMAN" Edited March 4, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
Kyle22 Posted March 4, 2014 Share Posted March 4, 2014 (edited) Attract mode off is poke 77,0. You must put it somewhere in your main loop. This does not turn off attract mode, it simply resets the timer. As for the cursor, poke 752,1 before the ? command, not after. Mapping the Atari is a useful reference: http://www.atariarchives.org/mapping/memorymap.php Edited March 4, 2014 by Kyle22 1 Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 4, 2014 Author Share Posted March 4, 2014 (edited) Attract mode off is poke 77,0. You must put it somewhere in your main loop. This does not turn off attract mode, it simply resets the timer. As for the cursor, poke 752,1 before the ? command, not after. Mapping the Atari is a useful reference: http://www.atariarchives.org/mapping/memorymap.php Awesome! It's searchable. Totally bookmarked. Edited March 4, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
+therealbountybob Posted March 4, 2014 Share Posted March 4, 2014 There's still a bit more space saving open to you (if needed) - use lines 0 to 9, you don't need the space after the line number. DIms can be joined: DIM str1(3),str2(3) LOC.=Locate END.=ENDIF PL.=PLOT G.=GOTO TurboBasic can use SOUND [sO.] on it's own to mute all sounds You can usually miss out all the spaces, though sometimes in a FOR/NEXT it might get confused and cause an error. That should be enough to double your game up; and there's more, but it then gets ugly 2 Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 10, 2014 Author Share Posted March 10, 2014 (edited) This has to be one of the stupidest questions ever asked, but I've done hours of searching without much luck. I'm trying to draw a semi-random obstacle in the middle of my screen (graphics 7+16). On many maze-games, I've noticed that 1/4 or 1/2 of the screen is mirrored/flipped/rotated to create the rest. I'd like in on that with basic--is there a super easy way? It's so commonly done that there just *must* be a super easy way to do this. Maybe draw 1/4 and hit a few pokes? I'm searching, but I must be using the wrong keyword. Edited March 10, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
kenjennings Posted March 10, 2014 Share Posted March 10, 2014 Maze games... like on the 2600? Mirrored and reflected playfields are common on the 2600, because it is a hardware feature for the background graphics. On the 8-bit computers/5200 video game, it's all your memory to play with. You draw what you want to see on screen... everything. 1 Quote Link to comment Share on other sites More sharing options...
+Stephen Posted March 10, 2014 Share Posted March 10, 2014 Horizontal mirroring is done easily via a custom display list, but there is no easy way to split or mirror the screen vertically. 1 Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted March 11, 2014 Share Posted March 11, 2014 You can change CHACT to flip characters on the bottom of the screen upside down, then use LMS commands to reference the screen in reverse order from the top half. Or if you REALLY wanna be cool ... make the top half Antic 4 (or 6) and the bottom Antic 5 (or 7) and you get a 3-d reflection effect. Especially if you shade the BG a blue color, and get a water effect. 1 Quote Link to comment Share on other sites More sharing options...
Reaperman Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) Maze games... like on the 2600? Mirrored and reflected playfields are common on the 2600, because it is a hardware feature for the background graphics. On the 8-bit computers/5200 video game, it's all your memory to play with. You draw what you want to see on screen... everything. You're right--more 2600 than A8. I was hoping the a8 had the same feature so I could save space in another ten-liner. Other ideas seem neat, but also a bit too tricky and space-intensive so they're for another day. I will probably just have to give up some variety on my random playfields. Edited March 11, 2014 by Reaperman Quote Link to comment Share on other sites More sharing options...
+therealbountybob Posted March 15, 2014 Share Posted March 15, 2014 Not sure what you're planning, but you might do something like this to duplicate screen items... color 1:plot x+xz,y+yz:drawto a+xz,b+yz:drawto c+xz,d+yz etc etc. and put this inside a loop to vary the offsets xz/yz or manually adjust them 1 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.