Skip to content

Instantly share code, notes, and snippets.

@BalorPrice
Last active May 29, 2017 09:10
Show Gist options
  • Save BalorPrice/196907fce52e3b3b5a2976760735b8cb to your computer and use it in GitHub Desktop.
Save BalorPrice/196907fce52e3b3b5a2976760735b8cb to your computer and use it in GitHub Desktop.
SAM coupé conversion of SID test in C64 user manual
; +++++++++++++++++++++
; SID TEST 2: 24-May-17
; +++++++++++++++++++++
; Straight conversion of the C64 user manual example of playing a single-channel tune.
; Original program from http://www.lemon64.com/manual/manual/8_1.html
; Compiled with PYZ80
dump 1,0
autoexec
org 32768
di
auto.main:
@set_sid_base: ; s=54272
ld bc,&00d4 ; SID base port set on C, B is used to select registers
@reset_sid: ; for l=s to s+24
ld e,0
@reset_loop: ; poke l,0
out (c),e
; next l
ld a,b
inc b
cp 25 ; Skip 4 read-only registers
jr nz,@-reset_loop
@set_AD_vals: ; set Attack/Decay vals for voice 1
; poke s+5,9
ld b,5
ld a,9
out (c),a
; poke s+6,0
inc b
xor a
out (c),a
@set_main_volume:
; poke s+24,15 ; set main volume to max (0-15)
ld b,24
ld a,15
out (c),a
@set_data_start:
ld hl,auto.music.data
; @loop:
@notes_loop:
; read hf,lf,dr ; read high frequency, low frequency, duration
ld e,(hl)
inc hl
ld d,(hl)
inc hl
@test_end_token:
; if hf<0 then end
ld a,e
cp -1
ret z
@set_freq: ; set frequency (NB not split into octaves)
; poke s+1,hf
ld b,1
ld a,e
out (c),a
; poke s,lf
dec b
ld a,d
out (c),a
@set_waveform: ; Sawtooth waveform for voice 1
; poke s+4,33
ld b,4
ld a,%00100001 ; Set bit 0 for gate (ie play attack/delay/sustain element of ADSR)
out (c),a
call border_up ; Added as test: confirm routine playing with border colour change
@attack_wait_loop: ; Wait for note to play
; for t=1 to dr
ld e,(hl)
inc hl
@on_loop:
for 2048,nop ; !! Complete guess at timings.
; next t
dec e
jp nz,@-on_loop
@set_waveform_release:
; poke s+4,32
ld b,4
ld a,%00100000 ; Reset bit 0 to play release element of ADSR
out (c),a
@release_wait_loop: ; Wait for release to complete
; for t=t to 50
ld e,50
@off_loop:
for 2048,nop
; next t
dec e
jp nz,@-off_loop
call border_up
; goto @-loop ; Next note
jp @-notes_loop
auto.music.data:
db 25,177,250 ; Data, frequency (2 bytes), duration
db 28,214,250
db 25,177,250
db 25,177,250
db 25,177,125
db 28,214,125
db 32, 94,250
db 25,177,250
db 28,214,250
db 19, 63,250
db 19, 63,250
db 19, 63,250
db 21,154, 63
db 24, 63, 63
db 25,177,250
db 24, 63,125
db 19, 63,250
db -1, -1, -1
border_up: ; Simple check to show program is outputting data
push af
@border: ld a,0
out (254),a
inc a
and %00000111
ld (@-border+1),a
pop af
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment