DRUID Development Docs: gsound.inc

Gadget Sourcecode: gsound.inc

; Justice Unlimited Gadget Microcode
; (C) 2004 Nathan (Acorn) Pooley 
;
; gsound.inc
;
;@DOC@ code make noise
;

;############################################
;############### SOUND ######################
;############################################

    ;
    ; IMPORTANT NOTE: SOUNDS MUST BE SHORTER THAN 1 SEC OR
    ;                 TIME CAN BE LOST!!!
    ;
    ; CALLING SOUND TURNS OFF SPINNER & LIGHT!!!
    ;
snd_begin:
    call    input_disable
    LIGHT_OFF
    call    reset_sleep_time
    DISABLE_INTR
    return

snd_end:
    SOUND_OFF
    ENABLE_INTR
    goto    reset_sleep_time
    call    input_enable



    ; N = v_snd_val
    ; A = v_snd_duration1
    ; B = v_snd_duration2
    ; P = period (cycles)
    ; E = delay
    ; D = duration
    ;
    ; P = 3N + 4
    ; E = P(A-1)+11
    ; D = BE
snd_n:
    rcall   snd_begin           ; BEGIN SOUND

snd_n_c:
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    movwf   v_tmp               ;
snd_n_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
    movf    v_snd_val,w         ; ;
snd_n_a:                        ; ;
    decfsz  WREG,w              ; ; ; LOOP A - v_snd_val
    bra     snd_n_a             ; ; ;
    decfsz  v_tmp               ; ; ;
    bra     snd_n_b             ; ;
    decfsz  v_snd_duration1,f   ;
    bra     snd_n_c             ;

    bra     snd_end             ; END SOUND



    ; P = 6
    ; E = P(A-1)+12
    ; D = BE
snd_6:
    rcall   snd_begin           ; BEGIN SOUND

snd_6_c:
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    movwf   v_tmp               ;
snd_6_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
    movf    v_snd_val,w         ; ;
snd_6_a:                        ; ;
    nop
    decfsz  v_tmp,f             ; ; ;
    bra     snd_6_b             ; ;
    nop
    SOUND_CLICK
    decfsz  v_snd_duration1,f   ;
    bra     snd_6_c             ;

    bra     snd_end             ; END SOUND

    ; P = 5
    ; E = P(A-1)+15
    ; D = BE
snd_5:
    rcall   snd_begin           ; BEGIN SOUND

snd_5_c:
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    SOUND_CLICK
    movwf   v_tmp               ;
    nop
    nop
    nop
snd_5_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
    movf    v_snd_val,w         ; ;
snd_5_a:                        ; ;
    decfsz  v_tmp,f             ; ; ;
    bra     snd_5_b             ; ;
    nop
    SOUND_CLICK
    decfsz  v_snd_duration1,f   ;
    bra     snd_5_c             ;

    bra     snd_end             ; END SOUND

    ; P = 4
    ; E = P(A-1)+12
    ; D = BE
snd_4:
    rcall   snd_begin           ; BEGIN SOUND

snd_4_c:
    SOUND_CLICK
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    movwf   v_tmp               ;
    nop
snd_4_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
snd_4_a:                        ; ;
    decfsz  v_tmp,f             ; ; ;
    bra     snd_4_b             ; ;
    nop
    SOUND_CLICK
    decfsz  v_snd_duration1,f   ;
    bra     snd_4_c             ;

    bra     snd_end             ; END SOUND

    ; P = 3
    ; E = 6(A-1)+12
    ; D = BE
snd_3:
    rcall   snd_begin           ; BEGIN SOUND

snd_3_c:
    SOUND_CLICK
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    movwf   v_tmp               ;
snd_3_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
snd_3_a:                        ; ;
    decf    v_tmp,f             ; ; ;
    nop
    SOUND_CLICK
    bnz     snd_3_b             ; ;
    decf    v_snd_duration1,f   ;
    SOUND_CLICK
    bnz     snd_3_c             ;

    bra     snd_end             ; END SOUND

    ; P = 2
    ; E = 17(A-1)+25
    ; D = BE
snd_2:
    rcall   snd_begin           ; BEGIN SOUND

snd_2_c:
    SOUND_CLICK
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    SOUND_CLICK
    movwf   v_tmp               ;
snd_2_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
    nop
    SOUND_CLICK
snd_2_a:                        ; ;
    decf    v_tmp,f             ; ; ;
    SOUND_CLICK
    bnz     snd_2_b             ; ;
    SOUND_CLICK
    decf    v_snd_duration1,f   ;
    SOUND_CLICK
    bnz     snd_2_c             ;

    bra     snd_end             ; END SOUND

    ; P = 1
    ; E = 19(A-1)+55
    ; D = BE
snd_1:
    rcall   snd_begin           ; BEGIN SOUND

snd_1_c:
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    movf    v_snd_duration2,w   ; LOOP C - v_snd_duration2
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    movwf   v_tmp               ;
snd_1_b:                        ;
    SOUND_CLICK                 ; ; LOOP B - v_snd_duration1
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
snd_1_a:                        ; ;
    decf    v_tmp,f             ; ; ;
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    bnz     snd_1_b             ; ;
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    decf    v_snd_duration1,f   ;
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    SOUND_CLICK
    bnz     snd_1_c             ;

    bra     snd_end             ; END SOUND






PLAY_SOUND  macro   val,d1,d2,sfunc
    call    putc_clr
    movlw   val
    call    putnum_w

    movlw   val
    movwf   v_snd_val
    movlw   d1
    movwf   v_snd_duration1
    movlw   d2
    movwf   v_snd_duration2
    rcall   sfunc
    endm

PLAY_SOUND2 macro   val,d1,d2,sfunc
    movlw   val
    movwf   v_snd_val
    movlw   d1
    movwf   v_snd_duration1
    movlw   d2
    movwf   v_snd_duration2
    rcall   sfunc
    endm

    

snd_hi_l:
snd_many:
    PLAY_SOUND  0x1c,0x03,0x16,snd_n
    PLAY_SOUND  0x1b,0x31,0x01,snd_n
    PLAY_SOUND  0x1a,0x08,0x07,snd_n
    PLAY_SOUND  0x19,0x35,0x01,snd_n
    PLAY_SOUND  0x18,0x05,0x0d,snd_n
    PLAY_SOUND  0x17,0x39,0x01,snd_n
    PLAY_SOUND  0x16,0x1e,0x02,snd_n
    PLAY_SOUND  0x15,0x3e,0x01,snd_n
    PLAY_SOUND  0x14,0x41,0x01,snd_n
    PLAY_SOUND  0x13,0x44,0x01,snd_n
    PLAY_SOUND  0x12,0x24,0x02,snd_n
    PLAY_SOUND  0x11,0x26,0x02,snd_n
    PLAY_SOUND  0x10,0x02,0x41,snd_n
    PLAY_SOUND  0x0f,0x06,0x10,snd_n
    PLAY_SOUND  0x0e,0x06,0x11,snd_n
    PLAY_SOUND  0x0d,0x60,0x01,snd_n
    PLAY_SOUND  0x0c,0x03,0x2d,snd_n
    PLAY_SOUND  0x0b,0x0d,0x09,snd_n
    PLAY_SOUND  0x0a,0x02,0x5b,snd_n
    PLAY_SOUND  0x09,0x85,0x01,snd_n
    PLAY_SOUND  0x08,0x02,0x69,snd_n
    PLAY_SOUND  0x07,0x08,0x16,snd_n
    PLAY_SOUND  0x06,0x2f,0x04,snd_n
    PLAY_SOUND  0x05,0xd8,0x01,snd_n
    PLAY_SOUND  0x04,0x14,0x0d,snd_n
    PLAY_SOUND  0x03,0x0a,0x20,snd_n
    PLAY_SOUND  0x02,0x18,0x11,snd_n
    PLAY_SOUND  0x01,0x24,0x10,snd_n
    PLAY_SOUND  0x00,0x3d,0x0b,snd_6
    PLAY_SOUND  0x00,0x73,0x07,snd_5
    PLAY_SOUND  0x00,0xfe,0x04,snd_4
    PLAY_SOUND  0x00,0x3d,0x0b,snd_3
    PLAY_SOUND  0x00,0x78,0x02,snd_2
    PLAY_SOUND  0x00,0x34,0x04,snd_1

    bra     snd_done


snd_med_l:
    movlw   mode_snd_med_msg
    call    set_mode

    call    reset_sleep_time
    movlw   32                  ; approx 5 sec
    movwf   v_tmp2

snd_med_loop1:
    btg     disab_sound     ; outer loop = 1280+7=1287 cycles
    clrf    v_tmp
snd_med_loop2:
    btg     disab_sound     ; inner loop: 5*256 = 1280 cycles
    decf    v_tmp,f
    btg     disab_sound
    bnz     snd_med_loop2

    btg     disab_sound
    decf    v_tmp2
    btg     disab_sound
    bnz     snd_med_loop1

    bra     snd_done

snd_lo_l:
    movlw   mode_snd_lo_msg
    call    set_mode

    call    reset_sleep_time
    movlw   27                  ; approx 5 sec
    movwf   v_tmp2

snd_lo_loop1:
    btg     disab_sound     ; outer loop = 1536+7=1543 cycles
    clrf    v_tmp
    nop
    nop
snd_lo_loop2:
    nop
    nop
    btg     disab_sound     ; inner loop: 6*256 = 1536 cycles
    decf    v_tmp,f
    bnz     snd_lo_loop2

    decf    v_tmp2
    bnz     snd_lo_loop1

    ;bra    snd_done



snd_done:
    SOUND_OFF
    call    reset_sleep_time
    goto    pop_mode


snd_click:
    movlw   20          ; duration
    movwf   v_tmp               ;
    DISABLE_INTR

snd_click_b:                        ;
    SOUND_CLICK 
snd_click_a:                        ; ;
    decfsz  v_tmp,f             ; ; ;
    bra     snd_4_b             ; ;

    SOUND_OFF
    ENABLE_INTR
    return

snd_err1:
    PLAY_SOUND2 0x11,0x26,0x01,snd_n
    bra     snd_done

snd_good:
    PLAY_SOUND  0x00,0x73,0x04,snd_5
    bra     snd_done

This file Copyright (C) 2004 by Nathan (Acorn) Pooley
Go to DRUID Development page
Go to DRUID page
Go to JU Gadgets page
Go to Justice Unlimited homepage
Go to Acorn's personal webpage
Contact Acorn
See comments from others
Post your own comments
File created by do_doc at Wed Aug 4 17:56:21 2004