Skip to content

Instantly share code, notes, and snippets.

@Frank-Buss
Created September 25, 2019 05:09
Show Gist options
  • Save Frank-Buss/1066eaaf8b0e2a718fcf38bf64a6ce2e to your computer and use it in GitHub Desktop.
Save Frank-Buss/1066eaaf8b0e2a718fcf38bf64a6ce2e to your computer and use it in GitHub Desktop.
4 tone gong on the Commander X16
100 REM RESET SOUND CHIP
110 FOR I = 0 TO 255 : POKE $9FE0, I : POKE $9FE1, 0 : NEXT
120 REM GONG
130 O=5:N=0:C=0:GOSUB 1000
140 O=5:N=9:C=1:GOSUB 1000
150 O=6:N=0:C=2:GOSUB 1000
160 O=6:N=9:C=3:GOSUB 1000
170 REM NOTE OFF FOR ALL 4 CHANNELS
180 FOR I = 1 TO 4000:NEXT
190 POKE $9FE0, $08 : POKE $9FE1, $00
200 POKE $9FE0, $08 : POKE $9FE1, $01
210 POKE $9FE0, $08 : POKE $9FE1, $02
220 POKE $9FE0, $08 : POKE $9FE1, $03
900 END
1000 REM N = NOTE, O = OCTAVE, C = CHANNEL, F = FRACTION
1010 REM ENABLE L/R, SET CONNECTION 7, FEEDBACK 2
1020 POKE $9FE0, $20+C : POKE $9FE1, $C7 + 2*8
1030 REM SET FREQUENCY
1040 POKE $9FE0, $28+C : POKE $9FE1, O*16+N
1050 REM VOLUME
1060 POKE $9FE0, $60+C : POKE $9FE1, $07
1070 REM ATTACK
1080 POKE $9FE0, $80+C : POKE $9FE1, $18
1090 REM RELEASE
1100 POKE $9FE0, $E0+C : POKE $9FE1, $05
1110 REM NOTE ON
1120 POKE $9FE0, $08 : POKE $9FE1, $08 + C
1130 FOR I = 1 TO 3000:NEXT
1140 RETURN
@MiklosPathy
Copy link

I only wrote a player so far. Nothing special, just refactoring your code.
The data lines contains the song. Only key on/off and note/delay data.
Data line format:
channel, octave, note, keyon/keyoff/nothing, delay
keyon=1, keyoff=0, nothing=2 (or any other number)
The last data line must be:
DATA 8,0,0,0,0

10 CH=0 : OC=0 : NO=0 : FR=0
100 GOSUB 10000
110 FOR CH=0 TO 7:GOSUB 14000:NEXT
120 REM GONG
130 READ CH,OC,NO,KO,WA
135 IF CH=8 GOTO 180
140 GOSUB 15000
145 IF KO=1 THEN GOSUB 11000
146 IF KO=0 THEN GOSUB 12000
150 FOR I = 0 TO WA:NEXT
170 GOTO 120
180 GOSUB 13000
900 END
10000 REM RESET SOUND CHIP
10100 FOR I = 0 TO 255 : POKE $9FE0, I : POKE $9FE1, 0 : NEXT
10200 RETURN
11000 REM NOTE ON FOR CHANNEL CH
11100 POKE $9FE0,$08:POKE $9FE1,$08+CH
11200 RETURN
12000 REM NOTE OFF FOR CHANNEL CH
12100 POKE $9FE0,$08:POKE $9FE1,CH
12200 RETURN
13000 REM NOTE OFF FOR ALL CHANNELS
13100 FOR CH=0 TO 7:GOSUB 12000:NEXT
13200 RETURN
14000 REM SETUP TIMBRE FOR CHANNEL CH
14100 REM ENABLE L/R, SET CONNECTION 7, FEEDBACK 2
14200 POKE $9FE0, $20+CH : POKE $9FE1, $C7 + 28
14300 REM VOLUME
14400 POKE $9FE0, $60+CH : POKE $9FE1, $07
14500 REM ATTACK
14600 POKE $9FE0, $80+CH : POKE $9FE1, $18
14700 REM RELEASE
14800 POKE $9FE0, $E0+CH : POKE $9FE1, $05
14900 RETURN
15000 REM SETUP NOTE FREQUENCY FOR CHANNEL CH
15100 REM NO = NOTE, OC = OCTAVE, FR = FRACTION
15200 REM SET FREQUENCY
15300 POKE $9FE0, $28+CH : POKE $9FE1, OC
16+NO
15400 RETURN
30000 DATA 0,5,0,1,1000
30010 DATA 0,5,1,2,1000
30020 DATA 0,5,2,2,1000
30030 DATA 0,5,3,2,1000
30040 DATA 0,5,4,2,1000
30050 DATA 0,5,5,0,1000
30100 DATA 1,5,9,1,1000
30150 DATA 0,5,0,0,1000
30160 DATA 0,5,9,0,3000
30200 DATA 2,6,0,1,1000
30300 DATA 3,6,9,1,1000
30350 DATA 2,6,0,0,1000
30360 DATA 3,6,9,0,3000
40000 DATA 8,0,0,0,0

@Frank-Buss
Copy link
Author

The multipliers got scrambled in your comment, but looks and sounds good! But I think would be better to use C for a more complex player, it just gets messy as usual with this old Commodore BASIC dialect :-)

@MiklosPathy
Copy link

For now, figuring out the basics, it is enough for me. Also, C would be to easy. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment