Skip to content

Instantly share code, notes, and snippets.

@markjenkins
Last active January 12, 2024 04: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 markjenkins/46165b17d21460740aaf2b39b29cf6e1 to your computer and use it in GitHub Desktop.
Save markjenkins/46165b17d21460740aaf2b39b29cf6e1 to your computer and use it in GitHub Desktop.
A VIC20 BASIC tone generator using the user port for morse code practice
rem VIC-20 basic program to act as a tone
rem generator for morse code practice
rem author Mark Jenkins <mark@parit.ca>
rem checks portB pin 0 e.g. pin "C"
rem hardware connected to user-port
rem should short that pin to ground when a
rem switch is closed.
rem
rem the VIC-20 includes a pull up resistor
rem so the value is 1 when the switch is
rem open and 0 when the switch closes to
rem complete the circuit
rem registers:
rem - 37138 is the port b data direction
rem 8-bit. for each bit, 0 for input,
rem 1 for output
rem defaults to 0x00 but we set anyway
rem - 36878 is sound volume 0-15
rem - 36876 is the highest pitch
rem tone generator, 0-255
rem - 37136 is the 8 bit portb
rem we are only interested in the least
rem significant bit, PB0
rem the wait routine is built-in polling I/O
rem which waits for a non-zero value
rem we supply 36876 as the address to watch
rem first argument
rem 2nd argument is an AND mask
rem 3rd argument is an XOR mask for flipping
rem bits
rem first the XOR mask is applied,
rem then AND mask, and then remaining value
rem is checked as zero/non-zero
rem redundant init data direction default
poke 37138,0
rem volume
poke 36878,10
rem make tone until portB pin 0 is 0
goto 200
50 poke 36876,190
wait 37136,1
poke 36876,0
return
200 wait 37136,1,1
gosub 50
goto 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment