Skip to content

Instantly share code, notes, and snippets.

@remy
Created July 20, 2020 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remy/8dd68e03adfa023e9adf6c3c9dbee238 to your computer and use it in GitHub Desktop.
Save remy/8dd68e03adfa023e9adf6c3c9dbee238 to your computer and use it in GitHub Desktop.
Example of using OUT with AY chips in NextBASIC - main setup code by Dave Clarke
#autoline 10
RUN AT 3
PROC sfxsetup()
%i=0
DIM S$(4,20)
S$(1)="cccBccccCB"
S$(2)="baBA"
S$(3)="aAaAbBbBbB"
S$(4)="aaaaabbbbbbbcbbbbbABC"
REPEAT
IF INKEY$ ="c" THEN PROC sfxcon(): ELSE PROC sfxcoff()
IF INKEY$ ="1" THEN %M[3]=1
IF INKEY$ ="2" THEN %M[3]=2
IF INKEY$ ="3" THEN %M[3]=3
IF INKEY$ ="4" THEN %M[3]=4
IF %M[3] <> $ffff THEN PROC ticksfx()
j=%$80+(i MOD 16)
PRINT AT 0,%(i MOD 31); CHR$ j
%i=%i+1
REPEAT UNTIL INKEY$ ="q":
PROC sfxstop()
STOP
DEFPROC ticksfx()
i=%M[3]
i$=S$(i)
l= LEN (i$)
IF %M[4]=0 THEN %M[4]=l
i=%M[4]-1
PRINT AT 1,0;i
PROC playsfx(i$(l-i))
%M[4]=i
IF %M[4]=0 THEN %M[3]=%-1
ENDPROC
;
DEFPROC playsfx(i$)
PRINT AT 20,0;"PLAY: ";i$
IF i$="a" THEN PROC sfxaon(): ENDPROC
IF i$="A" THEN PROC sfxaoff(): ENDPROC
IF i$="b" THEN PROC sfxbon(): ENDPROC
IF i$="B" THEN PROC sfxboff(): ENDPROC
IF i$="c" THEN PROC sfxcon(): ENDPROC
IF i$="C" THEN PROC sfxcoff(): ENDPROC
ENDPROC
;
; Via Dave Clarke
DEFPROC sfxsetup()
%M[1]=65533:%M[2]=49149:%M[3]=%-1
OUT %M[1],0: OUT %M[2],65: ;fine tone a
OUT %M[1],1: OUT %M[2],0: ;corse tone a
OUT %M[1],2: OUT %M[2],50: ;fine tone b
OUT %M[1],3: OUT %M[2],0: ;corse tone b
OUT %M[1],8: OUT %M[2],0: ;volume a
OUT %M[1],9: OUT %M[2],0: ;volume b
OUT %M[1],10: OUT %M[2],0: ;volume c
OUT %M[1],6: OUT %M[2],0: ;noise c
OUT %M[1],7: OUT %M[2],% BIN 11011000: ;enable noise c and tone a,b,c
ENDPROC
;
DEFPROC sfxcon(): OUT %M[1],10: OUT %M[2],15: ENDPROC
DEFPROC sfxcoff(): OUT %M[1],10: OUT %M[2],0: ENDPROC
DEFPROC sfxaon(): OUT %M[1],8: OUT %M[2],15: ENDPROC
DEFPROC sfxaoff(): OUT %M[1],8: OUT %M[2],0: ENDPROC
DEFPROC sfxbon(): OUT %M[1],9: OUT %M[2],15: ENDPROC
DEFPROC sfxboff(): OUT %M[1],9: OUT %M[2],0: ENDPROC
DEFPROC sfxstop(): OUT %M[1],7: OUT %M[2],% BIN 11111111: ENDPROC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment