Skip to content

Instantly share code, notes, and snippets.

@davidgiven
Created April 27, 2025 23:46
Show Gist options
  • Save davidgiven/e4dda6f5a244a870e645104457517114 to your computer and use it in GitHub Desktop.
Save davidgiven/e4dda6f5a244a870e645104457517114 to your computer and use it in GitHub Desktop.
; An extremely shoddy 60kHz sound player for the Commodore PET. Should work on
; most PETs. Assemble with beebasm. sound.a2stream should be a 1-bit
; bitstream, MSB first. Everything here was written by me, David Given, and is
; CC0 licensed.
org &3ff
equw &401, _entry_string_end, 1
equb &9e, "1037", 0
._entry_string_end
equw 0
VIA_T1C_L = &e844
VIA_T1C_H = &e845
VIA_T1L_L = &e846
VIA_T1L_H = &e847
VIA_T2C_L = &e848
VIA_T2C_H = &e849
VIA_SR = &e84a
VIA_ACR = &e84b
VIA_PCR = &e84c
VIA_IFR = &e84d
CLOCK_RATE = 1000000
SAMPLE_RATE = 60000
TICKS = (CLOCK_RATE / SAMPLE_RATE) / 2
org 0
.sample_ptr equw 0
.current_sample equb 0
.bit_counter equb 0
org &40d
._entry
sei
lda #&14
sta VIA_ACR
lda #&ac
sta VIA_PCR
lda #lo(TICKS)
sta VIA_T2C_L
lda #lo(binary_data)
sta sample_ptr+0
lda #hi(binary_data)
sta sample_ptr+1
jmp loopentry
.loop
ldy #0
lda (sample_ptr), y
tax
.wait
lda #&04
bit VIA_IFR ; 4
beq wait ; 2
sta VIA_IFR ; 4
.loopentry
stx VIA_SR ; 4; total = 14
inc sample_ptr+0
bne loop
inc sample_ptr+1
jmp loop
.binary_data:
incbin "sound.a2stream"
._end
SAVE "prog.prg", &3ff, _end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment