?login_element?

Subversion Repositories NedoOS

Rev

Rev 1107 | 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.  
  27.         ; TODO need test on real computer. On XPECCY emulator beeper is absent !
  28.  
  29.         module SOUND_PLAYER
  30.  
  31.         module SET_SOUND
  32. mute:
  33.         ld hl,SOUND_PLAYER.DATA.mute
  34.         jr SOUND_PLAYER.init
  35. coin:
  36.         ld hl,SOUND_PLAYER.DATA.coin
  37.         jr SOUND_PLAYER.init
  38. explosion:
  39.         ld hl,SOUND_PLAYER.DATA.explosion
  40.         jr SOUND_PLAYER.init
  41. impact:
  42.         ld hl,SOUND_PLAYER.DATA.impact
  43.         jr SOUND_PLAYER.init
  44. eat:
  45.         ld hl,SOUND_PLAYER.DATA.eat
  46.         jr SOUND_PLAYER.init
  47. key:
  48.         ld hl,SOUND_PLAYER.DATA.key
  49.         jr SOUND_PLAYER.init
  50. ice:
  51.         ld hl,SOUND_PLAYER.DATA.ice
  52.         jr SOUND_PLAYER.init
  53. done:
  54.         ld hl,SOUND_PLAYER.DATA.done
  55.         jr SOUND_PLAYER.init
  56. dead:
  57.         ld hl,SOUND_PLAYER.DATA.dead
  58.         jr SOUND_PLAYER.init
  59.         endmodule
  60.  
  61. init:
  62.         di
  63.         ld (sfx_data), hl
  64.         ld a,1
  65.         ld (sfx_type), a
  66.         ld de,sfx_type
  67.         ld bc,5
  68.         ldir
  69.         ei
  70.         ret
  71.  
  72. ; beeper_queue::
  73. ;         di
  74. ;         ld a, l
  75. ;         call queue_next
  76. ;         ei
  77. ;         ret
  78.  
  79. queue_next:
  80.         ld (sfx_type), a
  81.         or a
  82.         ret z
  83.  
  84.         dec a
  85.  
  86.         ld hl, (sfx_data)
  87.         ld c, l
  88.         ld b, h
  89.  
  90.         ld h, #0
  91.         ld l, a
  92.         ld d, h
  93.         ld e, l
  94.         add hl, hl
  95.         add hl, hl
  96.         add hl, de
  97.         add hl, bc
  98.  
  99.         ld de, sfx_type
  100.         ld bc, #5
  101.         ldir
  102.         ret
  103.  
  104. play:
  105.         ld a, (sfx_type)
  106.         or a
  107.         ret z
  108.  
  109.         dec a
  110.         jr z, tone
  111.  
  112.         dec a
  113.         ; shouldn't happen!
  114.         ret nz
  115.  
  116.        if EGA
  117.         ld a,(curgfxmode)
  118.         or 8
  119.         ld e,a;0+0x80+8 ;EGA+keep+noturbo
  120.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  121.        endif
  122.         ; noise
  123.         ld a, (sfx_freq)
  124.         ld d, a
  125.  
  126.         ld b, #0
  127.  
  128. noise_loop:
  129.         call rnd
  130.         and 0x10
  131.         ; FIXME: border ?
  132.         out (0xfe), a
  133.  
  134.         ld c, d
  135. noise_freq_loop:
  136.         dec b
  137.         jr z, noise_done
  138.         dec c
  139.         jr nz, noise_freq_loop
  140.         jr noise_loop
  141.  
  142. tone:
  143.        if EGA
  144.         ld a,(curgfxmode)
  145.         or 8
  146.         ld e,a;0+0x80+8 ;EGA+keep+noturbo
  147.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  148.        endif
  149.         ld a, (sfx_freq)
  150.         ld d, a
  151.  
  152.         xor a
  153.         ld b, a
  154.  
  155. tone_loop:
  156.         ; FIXME: border ?
  157.         and 0x10
  158.         out (0xfe), a
  159.         xor 0x10
  160.  
  161.         ld c, d
  162. freq_loop:
  163.         dec b
  164.         jr z, tone_done
  165.         dec c
  166.         jr nz, freq_loop
  167.         jr tone_loop
  168.  
  169. tone_done:
  170. noise_done:
  171.         ld a, (sfx_next)
  172.         ld hl, sfx_frames
  173.         dec (hl)
  174.         jr z, queue_next
  175.  
  176.         ; freq change (slide)
  177.         ld a, (sfx_freq_chg)
  178.         add d
  179.         ld (sfx_freq), a
  180.        if EGA
  181.         ld a,(curgfxmode)
  182.         ld e,a;0+0x80 ;EGA+keep
  183.         OS_SETGFX ;e=0:EGA, e=2:MC, e=3:6912, e=6:text ;+SET FOCUS ;e=-1: disable gfx (out: e=old gfxmode)
  184.        endif
  185.  
  186.         ret
  187.  
  188. rnd:
  189.         ld hl, 0xf3a1
  190.         ld a, h
  191.         rra
  192.         ld a, l
  193.         rra
  194.         xor h
  195.         ld h, a
  196.         ld a, l
  197.         rra
  198.         ld a, h
  199.         rra
  200.         xor l
  201.         ld l, a
  202.         xor h
  203.         ld h, a
  204.         ld (rnd + 1), hl
  205.         ret
  206.  
  207. sfx_type:       db 0
  208. sfx_frames:     db 0
  209. sfx_freq:       db 0
  210. sfx_freq_chg:   db 0
  211. sfx_next:       db 0
  212.  
  213. sfx_data:       block 2
  214.  
  215.         module DATA
  216. mute:  
  217.         db 0,0,0,0,0
  218. coin:
  219.         db 1,6,32,-8,2, 1,6,48,-12,0
  220. explosion:
  221.         db 2,32,1,-1,0
  222. impact:
  223.         db 2,2,5,-33,0
  224. eat:
  225.         db 1,8,33,78,0
  226. key:
  227.         db 1,1,4,0,0
  228. ice:
  229.         db 2,6,22,66,0
  230. done:
  231.         db 1,32,99,-3,0
  232. dead:
  233.         db 1,32,1,-64,0
  234.         endmodule
  235.  
  236.         endmodule
  237.