; compile command line: dasm sampler.asm -osampler.prg
; DASM: http://dasm-dillon.sourceforge.net

		processor 6502
		org $0801
		hex 0f 08 dd 07 9e 20 bd 28 37 2e 36 34 29 00 00
		hex 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
samples = $57
count = $59

start
		sei
		
		; disable ROM and enable RAM
		lda #$35
		sta 1
		
		; screen off
		ldx #0
		stx $d011

initLoop
		; load sample start address
		lda #<(end + 2)
		sta samples
		lda #>(end + 2)
		sta samples + 1
		
		; clear count
		stx count
		stx count + 1

loop
		; check for samples end
		lda count
		cmp end
		bne loop2
		lda count + 1
		cmp end + 1
		beq initLoop
loop2
		; load next sample
		lda (samples),x
		pha

		; play low nibble and delay
		and #15
		sta $D418
		ldy #20
delay1		dey
		bne delay1

		; play high nibble and delay
		pla
		ror
		ror
		ror
		ror
		and #15
		sta $d418
		ldy #18
delay2		dey
		bne delay2

		; increment sample count
		inc count
		bne inc1
		inc count + 1
inc1
		; increment samples pointer
		inc samples
		bne loop
		inc samples + 1
		jmp loop

end
