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 phasor
message2 db     'press any other key to play$'        ;or to go again
;----------------------------------
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    phasor               ;no call phasor sound
        jmp     begin                ;go see if we do it again
done:   mov     ax,4c00h             ;no exit back to DOS
        int     21h                  ;DOS interrupt
start   endp
;-------------------------------------------
phasor  proc    near  
        cli                          ;no interrupts
        mov     dx,1800              ;repeat count
        mov     bx,1                 ;start the sound frequency high
        mov     al,10110110xb        ;the magic number
        out     43h,al               ;send it to the port
backx:  mov     ax,bx                ;place our starting frequency in (ax)
        out     42h,al               ;send LSB first
        mov     al,ah                ;place MSB in (al)
        out     42h,al               ;send it next
        in      al,61h               ;must turn speaker on
        or      al,00000011xb        ;with this number
        out     61h,al               ;send it
        inc     bx                   ;lower the frequency
        mov     cx,60               ;adjusted for best sound (for 8mhz clock)
loopx:  loop    loopx                ;delay loop so we can here sound
        dec     dx                   ;decrement repeat count
        cmp     dx,0                 ;is repeat count = to 0
        jnz     backx                ;if not do again
        in      al,61h               ;if = 0 turn speaker off
        and     al,11111100xb        ;number turns speaker off
        out     61h,al               ;send it
        sti                          ;allow interrupts
        ret                          ;go see if user wants to do again
phasor  endp
;----------------------------------
code_seg        ends

