soundbuffer.fs 770 B

123456789101112131415161718192021222324252627282930313233
  1. start-microcode soundbuffer
  2. \ Interface:
  3. \ COMM+0 sound read pointer
  4. \ 3F00-3FFF sound buffer
  5. \ This microprogram provides a simple sound sample buffer.
  6. \ It reads 8-bit samples from the buffer at 3F00-3FFF and
  7. \ writes them to the audio sample registers SAMPLE_L and
  8. \ SAMPLE_R.
  9. \ The current buffer read pointer is COMM+0.
  10. h# 3f00 constant BUFFER
  11. [ 125 50 * ] constant CYCLE \ one cycle of 8KHz in clocks
  12. : 1+ d# 1 + ;
  13. : - invert 1+ + ;
  14. : main
  15. d# 0 ( when )
  16. begin
  17. CLOCK c@ over - \ positive means CLOCK has passed `when`
  18. d# 0 < invert if
  19. COMM+0 c@ dup
  20. h# 3f00 + c@
  21. dup SAMPLE_Lhi c! SAMPLE_Rhi c!
  22. 1+ COMM+0 c!
  23. CYCLE +
  24. then
  25. again
  26. ;
  27. end-microcode