sound.z80 715 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. NoteLoop:
  2. ;If the CPU is exactly 6MHz, then we are .000004666... seconds short for every .950272 seconds.
  3. dec de
  4. NoteLoop_begin:
  5. push de
  6. call freqout
  7. pop de
  8. ld a,d
  9. or e
  10. dec hl
  11. jr nz,NoteLoop
  12. ret
  13. freqout:
  14. ;HL*87-11cc
  15. ld d,b
  16. ld e,c
  17. jr freqoutEntry
  18. freqoutLoop:
  19. ;add 46cc
  20. ex (sp),hl
  21. ex (sp),hl
  22. nop
  23. nop
  24. freqoutLoop1:
  25. ld a,h
  26. or l
  27. jr z,+_
  28. cpd
  29. jp pe,freqoutLoop
  30. freqoutEntry:
  31. in a,(0)
  32. scf
  33. _:
  34. ld b,d
  35. ld c,e
  36. out (0),a
  37. jr c,freqoutLoop
  38. ret
  39. ;HL points to the data:
  40. ;DE is the time
  41. ;BC is the number of elements
  42. SoundLoop:
  43. push de \ push bc
  44. ld c,(hl) \ inc hl
  45. ld b,(hl) \ push hl
  46. ex de,hl
  47. call freqout
  48. pop hl \ pop bc \ pop de
  49. cpi
  50. jp pe,SoundLoop
  51. ret