?login_element?

Subversion Repositories NedoOS

Rev

Rev 1935 | Blame | Compare with Previous | Last modification | View Log | Download

  1. ; Beeper engine
  2. ; Copyright (C) 2021 by Juan J. Martinez <jjm@usebox.net>
  3. ;
  4. ; Permission is hereby granted, free of charge, to any person obtaining a copy
  5. ; of this software and associated documentation files (the "Software"), to deal
  6. ; in the Software without restriction, including without limitation the rights
  7. ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. ; copies of the Software, and to permit persons to whom the Software is
  9. ; furnished to do so, subject to the following conditions:
  10. ;
  11. ; The above copyright notice and this permission notice shall be included in
  12. ; all copies or substantial portions of the Software.
  13. ;
  14. ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. ; THE SOFTWARE.
  21. ;
  22. ;.globl _beeper_init
  23. ;.globl _beeper_queue
  24. ;.globl _beeper_play
  25.  
  26.         if 0
  27. _beeper_init::
  28.         di
  29.         ld (sfx_data), hl
  30.         xor a
  31.         ld (sfx_type), a
  32.         ei
  33.         ret
  34.  
  35. _beeper_queue::
  36.         di
  37.         ld a, l
  38.         call queue_next
  39.         ei
  40.         ret
  41.         endif
  42.  
  43. queue_next:
  44.         ld (sfx_type), a
  45.         or a
  46.         ret z
  47.  
  48.         dec a
  49.  
  50.         ;ld hl,(sfx_data)
  51.         ;ld c, l
  52.         ;ld b, h
  53.  
  54.         ld h, 0
  55.         ld l, a
  56.         ld d, h
  57.         ld e, l
  58.         add hl, hl
  59.         add hl, hl
  60.         add hl, de
  61.         ld bc,sfxdata
  62.         add hl, bc
  63.  
  64.         ld de, sfx_type
  65.         ld bc, 5
  66.         ldir
  67.         ret
  68.  
  69. _beeper_play::
  70.         ld a, (sfx_type)
  71.         or a
  72.         ret z
  73.  
  74.         dec a
  75.         jr z, tone
  76.  
  77.         dec a
  78.         ; shouldn't happen!
  79.         ret nz
  80.  
  81.         ; noise
  82.         ld a, (sfx_freq)
  83.         ld d, a
  84.  
  85.         ld b,0
  86.  
  87. noise_loop:
  88.         call rnd
  89.         and 0x10
  90.         ; FIXME: border ?
  91.         out (0xfe), a
  92.  
  93.         ld c, d
  94. noise_freq_loop:
  95.         dec b
  96.         jr z, noise_done
  97.         dec c
  98.         jr nz, noise_freq_loop
  99.         jr noise_loop
  100.  
  101. tone:
  102.         ld a, (sfx_freq)
  103.         ld d, a
  104.  
  105.         xor a
  106.         ld b, a
  107.  
  108. tone_loop:
  109.         ; FIXME: border ?
  110.         out (0xfe), a
  111.         xor 0x10
  112.  
  113.         ld c, d
  114. freq_loop:
  115.         dec b
  116.         jr z, tone_done
  117.         dec c
  118.         jr nz, freq_loop
  119.         jr tone_loop
  120.  
  121. tone_done:
  122. noise_done:
  123.         ld a, (sfx_next)
  124.         ld hl, sfx_frames
  125.         dec (hl)
  126.         jr z, queue_next
  127.  
  128.         ; freq change (slide)
  129.         ld a, (sfx_freq_chg)
  130.         add a,d
  131.         ld (sfx_freq), a
  132.  
  133.         ret
  134.  
  135. rnd:
  136.         ld hl,0xf3a1
  137.         ld a, h
  138.         rra
  139.         ld a, l
  140.         rra
  141.         xor h
  142.         ld h, a
  143.         ld a, l
  144.         rra
  145.         ld a, h
  146.         rra
  147.         xor l
  148.         ld l, a
  149.         xor h
  150.         ld h, a
  151.         ld (rnd + 1), hl
  152.         ret
  153.  
  154. sfx_type:       .ds 1
  155. sfx_frames:     .ds 1
  156. sfx_freq:       .ds 1
  157. sfx_freq_chg:   .ds 1
  158. sfx_next:       .ds 1
  159.  
  160. ;sfx_data: .ds 2
  161.  
  162.