SimpleSoundInit:
	; Sets up all sound channels so they are ready to play square waves.

	; Set main volume to max
	?mov 0xFF, $10
	out.b $10, 0x102[$0]

	; For all channels:
	mov 6, $11
.channelLoop:
	; Select the channel
	out.b $11, 0x100[$0]

	; Set volume to 0 (this also selects to write the waveform)
	out.b $0, 0x108[$0]

	; Set balance to max on both
	out.b $10, 0x10A[$0]

	; Write a square wave (16 samples high, 16 low)
	?mov 16, $12
	?mov 0x1F, $13
.squareWaveHigh:
	out.b $13, 0x10C[$0]
	add -1, $12
	bnz .squareWaveHigh
	?mov 16, $12
.squareWaveLow:
	out.b $0, 0x10C[$0]
	add -1, $12
	bnz .squareWaveLow

	add -1, $11
	bnz .channelLoop

	; Disable the LFO (is this necessary?)
	?mov 0x80, $10
	out.b $10, 0x112[$0]

	jmp $LP

PlayNote:
	; Sets the frequency and volume of a sound channel.
	; To silence a channel, just set its volume to 0.

	; IN:
	; $6 = channel (0 to 5?)
	; $7 = frequency (must be calculated appropriately, not in Hz)
	; $8 = volume (0 to 0x1F)

	out.b $6, 0x100[$0]	; Channel select
	out.b $7, 0x104[$0]	; Frequency low
	shr 8, $7
	out.b $7, 0x106[$0]	; Frequency high
	ori 0x80, $8, $8	; "Output freqs are read from waveform buffer"
	out.b $8, 0x108[$0]	; Volume

	jmp $LP