trs80music.asm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ; playmusic
  2. ; parameters:
  3. ; hl = list of notes to play
  4. ; destroys: a,bc,hl
  5. ; preserves: de,ix
  6. spt_playmusic:
  7. pop hl
  8. ; fall through to playmusic
  9. playmusic: ;music routine
  10. .getnote:
  11. ld c,(hl)
  12. ld a,c
  13. or a
  14. jr z,.end ; zero duration: we are done
  15. inc hl
  16. ld a,(hl)
  17. or a
  18. jr z,.rest ; zero frequency: rest
  19. ld a,2
  20. .cycle: ; tone cycle. First low part of square wave
  21. ld b,(hl)
  22. out ($FF),a
  23. .loophalf:
  24. nop12
  25. djnz .loophalf
  26. xor 3 ; invert the cassette bits
  27. ld b,(hl)
  28. out ($FF),a
  29. .loophalf2:
  30. nop12
  31. djnz .loophalf2
  32. xor 3 ; invert the cassette bits
  33. ld b,(hl)
  34. out ($FF),a
  35. .loophalf3:
  36. nop12
  37. djnz .loophalf3
  38. xor 3 ; invert the cassette bits
  39. bit 1,a
  40. jr nz,.cycle
  41. dec c
  42. jr nz,.cycle
  43. ; ld b,80
  44. ; .between_inner: ; delay between notes
  45. ; nop12
  46. ; djnz .between_inner
  47. jr .nextnote
  48. .rest:
  49. ld b,0
  50. .restloop:
  51. nop12
  52. nop12
  53. djnz .restloop
  54. dec c
  55. jr nz,.rest
  56. .nextnote:
  57. ld a,(hl)
  58. inc hl
  59. jr .getnote
  60. .end:
  61. ld a,0
  62. out ($FF),a
  63. ret
  64. tones_welcome:
  65. db $60,$40
  66. db $00,$00 ;end
  67. tones_vram: db $10,$50 ;each note is first byte duration
  68. db $10,$90 ;then next byte frequency -- the higher the second byte, the lower the frequency
  69. db $10,$50
  70. db $10,$90
  71. db $10,$50
  72. db $10,$90
  73. db $10,$50
  74. db $60,$c0
  75. ; db $40,$00 ;rest
  76. db $00,$00 ;end
  77. ; tones_vram: db $30,$60
  78. ; db $10,$90 ;each note is first byte duration
  79. ; db $20,$40 ;then next byte frequency -- the higher the second byte, the lower the frequency
  80. ; db $10,$90
  81. ; db $20,$40
  82. ; db $30,$60
  83. ; ; db $30,$50
  84. ; ; db $f0,$c0
  85. ; db $60,$00 ;rest
  86. ; db $00,$00 ;end
  87. ; tones_sad: db $30,$50 ;each note is first byte duration
  88. ; db $30,$60 ;then next byte frequency -- the higher the second byte, the lower the frequency
  89. ; db $30,$70
  90. ; db $30,$80
  91. ; db $30,$90
  92. ; db $30,$a0
  93. ; db $30,$b0
  94. ; db $f0,$c0
  95. ; db $00,$00 ;end
  96. tones_vramgood: db $03,$c0 ;each note is first byte duration
  97. db $03,$b0 ;then next byte frequency -- the higher the second byte, the lower the frequency
  98. db $04,$a0
  99. db $04,$90
  100. db $04,$80
  101. db $05,$70
  102. db $05,$60
  103. db $40,$50
  104. ; db $40,$00 ;rest
  105. db $00,$00 ;end
  106. tones_bitgood: db $40,$30
  107. db $20,$00 ;rest
  108. db $00,$00 ;end
  109. tones_bitbad: db $10,$C0
  110. db $20,$00 ;rest
  111. db $00,$00 ;end
  112. tones_bytegood: db $FF,$30
  113. db $00,$00 ;end
  114. tones_bytebad: db $44,$C0
  115. db $80,$00 ;rest
  116. db $00,$00 ;end
  117. tones_id1: db $40,$60
  118. db $60,$00 ;rest
  119. db $00,$00 ;end
  120. tones_id2: db $40,$60
  121. db $10,$00 ;rest
  122. db $40,$60
  123. db $60,$00 ;rest
  124. db $00,$00 ;end
  125. tones_id3: db $40,$60
  126. db $10,$00 ;rest
  127. db $40,$60
  128. db $10,$00 ;rest
  129. db $40,$60
  130. db $60,$00 ;rest
  131. db $00,$00 ;end