org 100h
section .text

;        cli                             ;no interrupts
        mov     al,0B6h            ;get ready byte
        out     43h,al

; Switch speaker on
        in      al,61h                  ;get port 61h contents
        or      al,00000011b            ;enable speaker
        out     61h,al

another:
; write count to timer
        mov     al,[LB]                  ;frequency divisor low byte
        out     42h,al
        mov     al,[HB]                  ;frequncy divisor high byte
        out     42h,al

; Wait CX clock ticks
;        sti                             ;must allow clock interrupt

;        mov     cx,19                   ;About 1 second (1/18.2*t=num) t=time num=number of clock ticks
;        mov     ax,040h                 ;point DS to BIOS
;        mov     es,ax
;        mov     si,06ch
;        mov     ds,ax
;waitout:   mov     ax,[es:si]              ;get low word of tick counter
;waitin:  cmp     ax,[es:si]              ;wait for it to change
;        je      waitin
;        loop    waitout                    ;count CX changes



MOV DX,[LB]
ADD DX,10
MOV [LB],DX

;wait for any key press:
MOV AH,10h
INT 16h

CMP AL,'q'
JNE another

; Switch speaker off
        in      al,61h                   ;get port contents
        and     al,11111100b            ;disable speaker
        out     61h,al

;wait for any key press:
;MOV AH,10h
;INT 16h


;exit to DOS
MOV AH,4Ch
INT 21h



section .data
LB: DB 0
HB: DB 5h

