Bugs in my code

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
mysteriouswiggler
Posts: 24
Joined: Tue Nov 27, 2018 8:59 am
Contact:

Bugs in my code

Post by mysteriouswiggler » Tue Dec 04, 2018 2:36 pm

So I have been going through the book "making music
on the BBC computer" By ian waugh and a big part of the book is this large program that graphs sound envelopes. There appears to be a bug in the program listing. I can't seem to get it to work. I figure one of the PROC's is mislabelled but when I relabel it to what you would expect, the program still does not run.

5.1 ran fine, however when I tried to extend it to the combined 5.1+5.2 it seems to not function.

Additionally Line 810 - BasicEmulator seems not to want to enter in the extra long line on P. statements. It seems to default to converting it to a PRINT token and then truncating the line.

I will include a disk with the program code as well as the listing here.

Code: Select all

   10 REM PROGRAM 5.1
   11 REM PROGRAM 5.2 (COMBINED)
   12 REM ADSR & PITCH Graph Generator
   20 REM ADSR GRAPH GENERATOR
   30
   40*TV255,1
   50MODE1
   60PROCSetUp
   70PROCAxis
   75 PROCAxis2
   80Input$="":PROCReset:PROCPrintEnv
   90
  100REPEAT
  110*FX15,1
  120Input$=GET$
  130IF Input$=" " PROCSound
  140IF Input$>="1" AND Input$<="8" PROCEnv
  145 IF Input$>="!" AND Input$<="'" Input=ASC(Input$):PROCPitEnv
  150IF Input$="C" PROCAxis
  160UNTIL Input$="Q"
  170END
  180
  190DEF PROCSetUp
  200REM Set Text Window
  210VDU28,0,4,39,0
  220REM Set Graphics Window
  230VDU24,0;0;1279;860;
  240REM Background=Yellow
  250GCOL0,130:CLG
  260REM Foreground=Black
  270GCOL0,0
  280REM Set COLOUR 1 to Flashing
  290VDU19,1,9,0,0,0
  300
  310REM Set Initial Parameters
  320PI1=0:PI2=0:PI3=0
  330PN1=0:PN2=0:PN3=0
  340T=20:T1=T:Pitch=10:Pit1=Pitch
  350AA=126:AD=-4:AS=-1:AR=-6
  360ALA=126:ALD=80:Duration=80
  370REM Marker for X Axis
  380VDU23,224,128,128,128,128,128,128,128,128
  390ENDPROC
  400
  410DEF PROCAxis
  420YScale=6
  430CLG
  440VDU29,0;0;
  450MOVE50,0:DRAW50,860
  460MOVE0,50:DRAW1279,50
  470VDU5
  480FOR Mark%=0 TO 780 STEP YScale*10
  490MOVE20,Mark%+YScale*10:PRINT"-"
  500NEXT Mark%
  510FOR Mark%=50 TO 1250 STEP 100
  520MOVEMark%,50:PRINTCHR$224
  530NEXT Mark%
  540VDU 4
  550REM Set Graphics Origin
  560VDU29,50;50;
  570ENDPROC
  580
  590DEF PROCEnv
  600PROCReset
  610IF Input$="1" t=1
  620IF Input$="2" aa=1
  630IF Input$="3" ad=1
  640IF Input$="4" as=1
  650IF Input$="5" ar=1
  660IF Input$="6" ala=1
  670IF Input$="7" ald=1
  680IF Input$="8" dur=1
  690PROCPrintEnv
  700PROCAlter
  710PROCPrintEnv
  720ENDPROC
  730
  740DEF PROCReset
  750b=3:t=3:aa=3:ad=3:as=3:ar=3
  760ala=3:ald=3:dur=3
  762 pi1=3:pi2=3:pi3=3
  764 pn1=3:pn2=3:pn3=3:p=3
  770ENDPROC
  780
  790DEF PROCPrintEnv
  800COLOURb:PRINTTAB(0,0)"ENV1,";:COLOURt:PRINT;T;
  810 COLOURb:PRINT;",";:COLOURpi1:PRINT;PI1;:COLOURb:PRINT;",";:COLOURpi2:PRINT;PI2;:COLOURb:PRINT;",";:COLOURpi3:PRINT;PI3;:COLOURb:PRINT;",";:COLOURpn1:PRINT;PN1;:COLOURb:PRINT;",";:COLOURpn2:PRINT;PN2;:COLOURb:PRINT;",";:COLOURpn3:PRINT;PN3;:COLOURb:
  811
  820COLOURaa:PRINT;AA;:COLOURb:PRINT;",";
  830COLOURas:PRINT;AS;:COLOURb:PRINT;",";:COLOURar:PRINT;AR;:COLOURb:PRINT",";
  840COLOURala:PRINT;ALA;:COLOURb:PRINT;",";:COLOURald:PRINT;ALD:COLOURb
  850COLOURdur:PRINTTAB(14,1)SPC(4)TAB(10,1)"Dur=";Duration:COLOURb
  855 COLOURp:PRINTTAB(23,1)SPC(6)TAB(18,1)"Pitch=";Pit1:COLOURb
  860ENDPROC
  870
  880DEF PROCAlter
  890INPUT NewVal$:PRINTTAB(0,2)SPC(6)
  900IF NewVal$="" PROCReset:PROCPrintEnv:ENDPROC
  910NewVal=EVAL(NewVal$)
  920PRINTTAB(30,0)SPC(20)
  930ON EVAL(Input$) GOTO 940,950,960,970,980,990,1000,1010
  940T=NewVal:T1=T:ENDPROC
  950AA=NewVal:ENDPROC
  960AD=NewVal:ENDPROC
  970AS=NewVal:ENDPROC
  980AR=NewVal:ENDPROC
  990ALA=NewVal:ENDPROC
 1000ALD=NewVal:ENDPROC
 1010Duration=NewVal:ENDPROC
 1020
 1030DEF PROCSound
 1040ENVELOPE1,T,PI1,PI2,PI3,PN1,PN2,PN3,AA,AD,AS,AR,ALA,ALD
 1050SOUND1,1,Pit1,Duration
 1060REM Clear Last Timing Results
 1070PRINTTAB(0,4)SPC(39);:PRINTTAB(0,4);
 1080IF T=0 T1=1
 1090IF T=128 MT1=129
 1100Time=0:Amp=0
 1110MOVE0,0
 1120YScale=6
 1130PROCAttack
 1140PROCPrint("A",8,32)
 1150IF OverTime GOTO 1210
 1160PROCDelay
 1170PROCPrint("D",8,32)
 1180IF OverTime GOTO 1210
 1190PROCSustain
 1200PROCPrint("S",8,32)
 1210PROCPrint("r",40,16)
 1220PROCRelease
 1230PROCPrint("R",0,0)
 1240PRINT;"Secs";
 1242FinalTime=Time
 1244PROCPitchEnv
 1250ENDPROC
 1260
 1270DEF PROCAttack
 1280REPEAT
 1290Amp=Amp+AA
 1300IF Amp>ALA Amp=ALA
 1310DRAW Time,Amp*YScale
 1320Time=Time+T1 MOD128
 1330PROCTimeCheck:IF OverTime GOTO1350
 1340DRAW Time,Amp*YScale
 1350UNTIL OverTime OR Amp=ALA
 1360ENDPROC
 1370
 1380DEF PROCDelay
 1390REPEAT
 1400Amp=Amp+AD
 1410IF ALD<ALA:IF Amp<ALD Amp=ALD
 1420IF ALD>ALA:IF Amp>ALD Amp=ALD
 1430IF ALD=ALA Amp=ALD
 1440DRAW Time,Amp*YScale
 1450Time=Time+T1 MOD128
 1460PROCTimeCheck:IF OverTime GOTO1480
 1470DRAW Time,Amp*YScale
 1480UNTIL OverTime OR Amp=ALD
 1490ENDPROC
 1500
 1510DEF PROCSustain
 1520REPEAT
 1530Amp=Amp+AS
 1540IF Amp<0 Amp=0
 1550DRAW Time,Amp*YScale
 1560Time=Time+T1 MOD128
 1570PROCTimeCheck:IF OverTime GOTO1590
 1580DRAW Time,Amp*YScale
 1590UNTIL OverTime OR Amp=0
 1600ENDPROC
 1610
 1620DEF PROCRelease
 1630REPEAT
 1640Amp=Amp+AR
 1650IF Amp<0 Amp=0
 1660DRAW Time,Amp*YScale
 1670IF Amp=0 GOTO1700
 1680Time=Time+T1 MOD128
 1690DRAW Time,Amp*YScale
 1700UNTIL Amp=0
 1710ENDPROC
 1720
 1730DEF PROCTimeCheck
 1740OverTime=FALSE
 1750IF Time>Duration*5 Time=Duration*5:OverTime=TRUE
 1760ENDPROC
 1770
 1780DEF PROCPrint(Phase$,Oset1,Oset2)
 1790IF Phase$="R" GOTO1860
 1800VDU5
 1810MOVE Time+Oset1,Amp*YScale+Oset2
 1820PRINTPhase$
 1830MOVE Time,Amp*YScale
 1840VDU4
 1850IF Phase$="r" ENDPROC
 1860PRINTPhase$;"=";Time/100;"  ";
 1870ENDPROC
 1880
 2000 DEF PROCAxis2
 2010 YScale=3
 2020 VDU29,0;0;
 2030 VDU5
 2040 FOR Mark%=60 TO 780 STEP YScale*10
 2050 MOVE40,Mark%+YScale*10:PRINT"-"
 2060 NEXT Mark%
 2070 VDU4
 2080 VDU29,50;50;
 2090 ENDPROC
 2110 DEF PROCP(pi,pn)
 2120 FOR P%=1 TO pn
 2130 Pitch=Pitch+pi
 2140 IF Pitch>255 Pitch=Pitch MOD256
 2150 IF Pitch<0 Pitch=Pitch+256
 2160 DRAW Time,Pitch*YScale
 2170 Time=Time+T1 MOD128
 2180 PROCFinalTimeCheck:IF FTime P%=pn
 2190 DRAW Time,Pitch*YScale
 2200 NEXT P%
 2210 ENDPROC
 2230 DEF PROCPitchEnv
 2240 PROCReset
 2250 IF Input=33 pi1=1
 2260 IF Input=34 pi2=1
 2270 IF Input=35 pi3=1
 2280 IF Input=36 pn1=1
 2290 IF Input=37 pn2=1
 2300 IF Input=38 pn3=1
 2310 IF Input=39 pn3=1
 2320 PROCPrintEnv
 2330 PROCAlterPit
 2340 PROCPrintEnv
 2350 ENDPROC
Attachments
DAM3.dsd
(7.5 KiB) Not downloaded yet

User avatar
jgharston
Posts: 3289
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Bugs in my code

Post by jgharston » Tue Dec 04, 2018 3:05 pm

Try these changes:

Code: Select all

  120   Input$=GET$:Input=ASC(Input$)
  145   IF Input$>="!" AND Input$<="'" PROCPitchEnv
 2330 PROCAlter
  800 COLOURb:PRINTTAB(0,0)"ENV 1,";:COLOURt:PRINT;T;
  810 COLOURb:PRINT;",";:COLOURpi1:PRINT;PI1;:COLOURb:PRINT;",";:COLOURpi2:PRINT;PI2;
  811 COLOURb:PRINT;",";:COLOURpi3:PRINT;PI3;:COLOURb:PRINT;",";:COLOURpn1:PRINT;PN1;
  812 COLOURb:PRINT;",";:COLOURpn2:PRINT;PN2;:COLOURb:PRINT;",";:COLOURpn3:PRINT;PN3;
  813 COLOURb:PRINT;",";
Last edited by jgharston on Tue Dec 04, 2018 3:06 pm, edited 1 time in total.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

mysteriouswiggler
Posts: 24
Joined: Tue Nov 27, 2018 8:59 am
Contact:

Re: Bugs in my code

Post by mysteriouswiggler » Fri Dec 07, 2018 11:37 am

Thank you for the help. Much appreciated.

Post Reply