Your Spectrum
Issue 15, June 1985 - Snap, Crackle & Pop!
Home Contents KwikPik

NOTE: The IN commands in the SCANKEYS procedure use the old values, and will not work with Issue 3 Spectrums.

title If you thought all had gone quiet on YS MegaBasic, keep listening 'cos we're about to break the sound barrier. Prepare to have your ears pierced by L A Privett's program on the MegaBasic PLAY command.
1000 REM PLAY EXPLORER
1010 REM BY L A PRIVETT
1020 REM MARCH 1985
1030 :
1040 PCLEAR
1050 SETSCREEN
1060 SETDISPLAY
1070 SETVALUE
1080 BOXIN
1090 SCANKEYS
1100 STOP
1110 :
1120 :
1130 :
Lines 1040-1100 These lines call the main procedures in the program.
2000 @SETSCREEN
2010 WINDOW_0, 0,22,64
2020 PAPER 0
2030 INK 6
2040 BRIGHT 1
2050 OVER 0
2060 INVERSE 0
2070 MODE_2
2080 CLS
2090 DRAW 255,0
2100 DRAW 0,175
2110 DRAW -255,0
2120 DRAW 0,-175
2130 FONT_1
2140 LET A$="PLAY_ EXPLORER"
2150 SPRINT_20, 10,1,2,A$
2160 INK 3
2170 ENDPROC_SETSCREEN
2180 :
2190 :
2200 :
Lines 2000-2170 This is the SetScreen procedure which draws the screen display.
3000 @SETDISPLAY
3010 LET A$="A B C D E"
3020 LET B$="= = = = ="
3030 INK 5
3040 DOWN_5,8,A$
3050 DOWN_5,12,B$
3060 FONT_2
3070 SPRINT_10, 150,2,2,"PLAY"
3080 PRINT AT 2,40;"USE CURSOR"
3090 PRINT AT 3,40;" KEYS TO "
3100 PRINT AT 4,40;"SELECT AND"
3110 PRINT AT 5,40;" CHANGE "
3120 INK 6
3130 PLOT 0,36
3140 DRAW 255,0
3150 INK 6
3160 PRINT AT 8,40;"SPACE FOR"
3170 PRINT AT 9,40;" PLAY "
3180 BEEP .1,0
3200 ENDPROC_SETDISPLAY
3210 :
3220 :
3230 :
Lines 3000-3200 This is the SetDisplay procedure that draws the information windows.
4000 @SETVALUE
4010 DIM M(5)
4020 DIM V(5)
4030 DIM P(5)
4040 FOR F=1 TO 5
4050 LET P(F)=3+F*2
4060 LET V(F)=0
4070 NEXT F
4080 RESTORE 4180
4090 FOR F=1 TO 5
4100 READ Q
4110 LET M(F)=Q
4120 PRINT AT 3+F*2,16;V(F)
4130 PRINT AT 3+F*2,24;M(F)
4140 NEXT F
4150 LET PRE=1
4160 LET POS=1
4180 DATA 1, 255, 255, 255, 255
4200 ENDPROC_SETVALUE
4210 :
4220 :
4230 :
Lines 4000-4200 The SetValue procedure initialises the main variables in the program.
5000 @BOXIN
5010 PLOT 20,60: DRAW 111,0
5020 DRAW 0,79: DRAW -111,0
5030 DRAW 0,-79
By now you're probably a pretty efficient MegaBasic programmer. You've mastered Procedures, you're magic with the Sprite Handling commands and no window is closed to you. What d'you mean, no! Keep watching and all will be revealed in future issues. But this month it's the turn of the PLAY command. Do all the megaprograms you've created still lack a mega backing track? Up till now it's been hard work to PLAY.
   The reason's clear - it can start to sound a bit silly trying to convey in words the sort of sounds your Spectrum's now capable of. What would you think if you read this in the manual? "If you put the value 12 in the last parameter, you'll get a PHUTT sound - on the other hand a number 9 will make the sound PHIZZ ..." Get the picture?
   To get round the problem, here's a small program that'll demonstrate the possibilities of YS MegaBasic's PLAY
command in the privacy of your own home - and save the sub-editor from any untoward embarrassment!
   Type the listing into your MegaBasic system, RUN the program and up will come a display showing the current parameters of the PLAY command. Use the up/down cursor keys to choose which value you wish to change and then increase or decrease it with the left and right cursor keys. When you're ready to play back the sound you've created, press the space bar and wait for the assault on your ear 'oles. The parameters you choose will also be displayed on screen.
   If you want to use the sound again in one of your own programs, then jot down the figures and keep them safe for later use. The trick is to find a way of remembering exactly what sort of sound your Speccy produced - which could mean going back to the phutts and the phizzes. Oh well!
SPRITE MAGIC
For all of you who haven't got megasprites sussed yet, here's a demo from Mike Leaman.
1 POKE 56894,255
Line 1 This line marks the end of the 'Sprite Info area'. You should use this at the start of every program that uses sprites.
10 CLEAR 44855: LET P=44856
Line 10 This line clears the space above ramtop for the image info.
20 FOR S=0 TO 3
30 READ A,B,C,D
40 POKE P,A: POKE P+1,B: LET P=P+2
50 FOR Z=1 TO 14: POKE P,C: POKE P+1,D: LET P=P+2: NEXT Z
60 POKE P,A: POKE P+1,B: LET P=P+2
65 FOR Z=0 TO 3: POKE P+Z,6: NEXT Z: LET P=P+4
70 NEXT S
Lines 20-70 Set up the image info.
75 POKE 56750,255
Line 75 Turns all sprites off.
80 FOR Y=0 TO 7
Line 80 Use eight sprites.
90 LET S=56750+18*Y
Line 90 Gets address of individual sprite info.
95 IF Y=0 THEN GO TO 100
Line 95 Checks that first sprite isn't turned on.
100 POKE S,1
Line 100 'OR' sprite onto screen and sets the printing mode.
110 POKE S+1,115: POKE S+2,80
Line 110 Sets x and y start positions.
120 POKE S+3,5-RND*10: POKE S+4,5-RND*10
Line 120 Sets random x and y movement.
130 POKE S+5,1: POKE S+7,4
Line 130 This line moves the sprite every interrupt, then tells the sprite routine that there are four images.
140 POKE S+9,4: POKE S+15,6
Line 140 Changes the image every four interrupts, then sets rub-out to yellow ink and black paper.
145 POKE S+8,RND*3
Line 145 Starts each sprite at a random image.
150 POKE S+11,56: POKE S+12,175
Line 150 Defines beginning of image data for each sprite.
160 NEXT Y
Line 160 Loops back eight times.
165 POKE 56750,1
Line 165 Turns all sprites on.
170 LET S=56750+18*INT (RND*8)
Line 170 Alters direction randomly.
180 POKE S+3,5-RND*10: POKE S+4,5-RND*10
190 GO TO 170
Line 180 Loops back and repeat again.
200 DATA 255, 255,129, 129, 63, 252, 33, 132, 15, 240, 9, 144, 1, 128, 1, 128
Line 200 This is the data for image info.

5040 PLOT 95,0: DRAW 0,36
5050 PLOT 95,19: DRAW 160,0
5060 MODE_1
5070 PRINT AT 18,26;"A B";
5080 PRINT " C D";
5090 PRINT " E"
5100 INK 4
5110 PRINT AT 15,25;"MAX"
5120 PRINT AT 15,14;"ACTUAL"
5130 MODE_2
5140 INK 2
5150 PRINT AT 12,40;"Q TO QUIT"
5160 INK 6
5170 PRINT AT 15,40;"L.PRIVETT"
5200 ENDPROC_BOXIN
5210 :
5220 :
5230 :
Lines 5000-5200 The BoxIn procedure draws the display of the current parameters.
6100 @SCANKEYS
6010 LET Z$=" "
6020 OVER 1
6030 PAPER 1
6040 INVERSE 1
6050 PRINT AT P(1),6;Z$
6060 REPEAT
6070 LET FINISH=0
6080 IF IN 63486=239 THEN LEFT
6090 IN IN 61438=251 THEN RIGHT
6100 IF IN 61438=247 THEN UP
6110 IF IN 61438=239 THEN DON
6120 IF IN 64510=254 THEN QUIT
6130 IF IN 32766=254 THEN NOISE
6150 BEEP .005,-16
6160 UNTIL FINISH
6200 ENDPROC_SCANKEYS
6210 :
6220 :
6230 :
Lines 6000-6200 The ScanKeys procedure reads the keyboard and then sends the program to other procedures in the program.
7000 @DON
7010 LET POS=POS+1
7020 IF POS>5 THEN LET POS=5
7030 POSITION
7040 ENDPROC_DON
7070 :
7080 :
7090 :
7100 @UP
7110 LET POS=POS-1
7120 IF POS<1 THEN LET POS=1
7130 POSITION
7140 ENDPROC_UP
7170 :
7180 :
7190 :
7200 @POSITION
7210 PRINT AT P(PRE),6;Z$
7220 PRINT AT P(POS),6;Z$
7230 LET PRE=POS
7240 ENDPROC_POSITION
7250 :
7260 :
7270 :
7300 @LEFT
7310 LET S=POS
7320 LET V(S)=V(S)-1
7330 IF V(S)<0 THEN LET V(S)=0
7340 OVER 0
7350 PRINT AT P(S),16;V(S);" "
7360 OVER 1
7370 ENDPROC_LEFT
7380 :
7390 :
7400 @RIGHT
7410 LET S=POS
7420 LET K=M(POS)
7430 LET V(S)=V(S)+1
7440 IF V(S)>K THEN LET V(S)=K
7450 OVER 0
7460 PRINT AT P(S),16;V(S);" "
7470 OVER 1
7480 ENDPROC_RIGHT
7490 :
7500 :
7510 :
8000 @QUIT
8010 LET FINISH=200
8020 PAPER 0
8030 INK 7
8040 OVER 0
8050 CLS
8060 ENDPROC_QUIT
8070 :
8080 :
8090 :
8100 @NOISE
8110 LET A=V(1): LET B=V(2)
8120 LET C=V(3): LET D=V(4)
8130 LET E=V(5): MODE_1
8140 OVER 0
8150 INK 7
8160 PAPER 0
8170 PRINT AT 20,26;A
8180 PRINT AT 20,32;B
8190 PRINT AT 20,38;C;" "
8200 PRINT AT 20,46;D;" "
8210 PRINT AT 20,54;E;" ";
8220 MODE_2
8250 PAPER 1
8260 OVER 1
8270 INK 6
8280 PLAY_A,B,C,D,E
8310 ENDPROC_NOISE
Lines 7000-8310 The remaining procedures move the cursor around and then play back the sound you've created.
Play_ Explorer screen
Use the cursor keys to change the parameters shown on the screen - then press the Space bar to PLAY.
Home Contents KwikPik