;;;;;;;;;;;;;-------LICENSE NOTICE-----------;;;;;;;;;;;;;;;
;; MIT License

;; Copyright (c) 2021 DreamyZombies Studio 

;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:

;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.

;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;
;; Authors:
;;  Abderrahamane Guermat Benaouali (agb139@alu.ua.es)
;;  Jorge Angulo Espí (jae17@alu.ua.es)
;;  Sami Hadj-Djilani (sh101@alu.ua.es)


;;
;; MUSIC SYSTEM
;;

.include "../cpct_functions.h.s"

.globl _song_menu
.globl _song_world
.globl _soundfx
    
    ;; 0 -> Not plating music 1 - > Playing music
    playingMusic: .db 0
    
    set_music_world::
    
        ld a, #1
        ld (playingMusic), a
        ld de, #_song_world
        call cpct_akp_musicInit_asm
        
        ret
    
    set_music_menu::
    
        ld a, #1
        ld (playingMusic), a
        ld de, #_song_menu
        call cpct_akp_musicInit_asm
    
        ret
    
    update_music::
    
        ld a, (playingMusic)
        cp #0x00
        jp nz, playing
    
        ret
        
    pause_music::
    
        ld a, #0
        ld (playingMusic), a
    
        ret
    
    stop_music::
    
        
        ld a, #0
        ld (playingMusic), a
        call cpct_akp_stop_asm
    
        ret
    
    playing:
    
        call cpct_akp_musicPlay_asm
    
        ret

    set_music_fx::

        ld de, #_song_menu
        call cpct_akp_SFXInit_asm

        ret

    play_jump::

        ld l, #3
        ld h, #15  
        ld e, #45
        ld d, #0      
        ld bc, #0x2000   
        ld a, #2

        call cpct_akp_SFXPlay_asm

        ret

    play_dead::

        ld l, #4
        ld h, #15  
        ld e, #50
        ld d, #0      
        ld bc, #0x1000     
        ld a, #1

        call cpct_akp_SFXPlay_asm

        ret

    play_door::

        ld l, #5
        ld h, #15  
        ld e, #68
        ld d, #0      
        ld bc, #0   
        ld a, #0

        call cpct_akp_SFXPlay_asm

    ret

    