Advertisement
mcleod_ideafix

Simple beeper piano for ZX Spectrum 48K

Apr 10th, 2022
2,995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                         ;Simple piano keyboard. (c)2022 Miguel A. Rodriguez Jodar. mcleod_ideafix
  2.  
  3.                         org 40000
  4.  
  5.                         di
  6.                         ld bc,00feh
  7. WaitKeyPress            in a,(c)
  8.                         cpl
  9.                         and 1fh
  10.                         jp z,WaitKeyPress
  11.  
  12.                         ld b,0fbh   ;Q-T
  13.                         in a,(c)
  14.                         cpl
  15.                         and 1fh
  16.                         jp z,NotQT
  17.  
  18.                         ld hl,ToneTableQT
  19. SeekToneParQT           bit 0,a
  20.                         jp nz,ToneFound
  21.                         inc hl
  22.                         inc hl
  23.                         sra a
  24.                         jp SeekToneParQT
  25.  
  26. NotQT                   ld b,0dfh   ;Y-P
  27.                         in a,(c)
  28.                         cpl
  29.                         and 1fh
  30.                         jp z,NotYP
  31.  
  32.                         ld hl,ToneTableYP
  33. SeekToneParYP           bit 4,a
  34.                         jp nz,ToneFound
  35.                         inc hl
  36.                         inc hl
  37.                         sla a
  38.                         jp SeekToneParYP
  39.  
  40. NotYP                   jp WaitKeyPress
  41.  
  42. ToneFound               ld e,(hl)
  43.                         inc hl
  44.                         ld d,(hl)
  45.                         ld b,0
  46.                         ld a,(23624)
  47.                         sra a
  48.                         sra a
  49.                         sra a
  50.                         and 7
  51. DoHalfPeriod            ld h,d
  52.                         ld l,e
  53.                         xor 10h
  54.                         out (c),a
  55. WaitHalfPeriod          dec hl               ;6T
  56.                         dec h                ;4T
  57.                         inc h                ;4T
  58.                         jp p,WaitHalfPeriod  ;10T  Total: 24T  -> 6.85714286 us per HL count
  59.                         ld l,a
  60.                         in a,(c)
  61.                         cpl
  62.                         and 1fh
  63.                         jp z,WaitKeyPress
  64.                         ld a,l
  65.                         jp DoHalfPeriod
  66.  
  67. ToneTableQT             dw 557         ; Key Q. C0 (semitone 0) . Value is 145833.33333333 / (261.63*2^(semitone/12)).
  68.                         dw 496         ; Key W. D0 (semitone 2)
  69.                         dw 442         ; Key E. E0 (semitone 4)
  70.                         dw 418         ; Key R. F0 (semitone 5)
  71.                         dw 372         ; Key T. G0 (semitone 7)
  72.  
  73. ToneTableYP             dw 331         ; Key Y. A0 (semitone 9)
  74.                         dw 295         ; Key U. B0 (semitone 11)
  75.                         dw 279         ; Key I. C1 (semitone 12)
  76.                         dw 248         ; Key O. D1 (semitone 14)
  77.                         dw 221         ; Key P. E1 (semitone 16)
  78.  
  79.                         end 40000
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement