code_seg        segment
        assume  cs:code_seg
        org     100h
        jmp     start
;----------------------------------
;B/C Software                        ;Author
;520 North Stateline Rd
;Sharon, Pa 16146
;----------------------------------
message1 db     'press Esc to Quit',0dh,0ah,'$'   ;Esc to end cheer
message2 db     'press any other key to play$'    ;or to go again
;-----------------------------------------------------------------------------
                     ;note + delay count
muzic_notes  dw      2031,0008, 1809,0008, 1612,0008, 1355,0015,
             dw      1612,0006, 1355,0024, 0ffffh     ;team cheer
;-----------------------------------------------------------------------------
start   proc    near
        mov     ah,9                 ;DOS function number to print string
        mov     dx,offset message1   ;the message
        int     21h                  ;DOS interrupt
        mov     ah,9                 ;DOS function number to print string
        mov     dx,offset message2   ;the message
        int     21h                  ;DOS interrupt
begin:  mov     ah,0                 ;BIOS function wait for key press
        int     16h                  ;BIOS interrupt
        cmp     ah,1                 ;Esc scan code 
        jz      done                 ;do we stop ?
        call    play                 ;no call play
        jmp     begin                ;go see if we do it again
done:   mov     ax,4c00h             ;no exit back to DOS
        int     21h                  ;DOS interrupt
start   endp
;-------------------------------------------
play    proc    near
        cli                          ;interrupts off
        lea     si,muzic_notes       ;point (si) to our note table
play2:  cld                          ;must increment forward
        lodsw                        ;load word into ax and increment (si)
        cmp     ax,0ffffh            ;is it ffff - if so end of table
        jz      x_muzic2             ;time to quit
        push    ax                   ;push our note value on the stack
        mov     al,10110110xb        ;the magic number
        out     43h,al               ;send it
        pop     ax                   ;pop our note value off the stack
        out     42h,al               ;send LSB first
        mov     al,ah                ;place MSB in al
        out     42h,al               ;send it next
        in      al,61h               ;get value to turn on speaker
        or      al,00000011xb        ;OR the gotten value
        out     61h,al               ;now we turn on speaker
        lodsw                        ;load the repeat loop count into (ax)
loop6:  mov     cx,10000             ;first delay count
loop7:  loop    loop7                ;do the delay
        dec     ax                   ;decrement repeat count
        jnz     loop6                ;if not = 0 loop back
        in      al,61h               ;all done
        and     al,11111100xb        ;number turns speaker off
        out     61h,al               ;send it
        mov     cx,5000              ;second delay count
loop8:  loop    loop8                ;wait a bit before next note
        jmp     short play2          ;now go do next note
x_muzic2:
        sti                          ;enable interrupts
        ret
play    ends
;-------------------------------------------
code_seg        ends
