        .model medium
;    MIDWAIT.ASM - An assembled procedure to be linked to
; compiled BASIC programs [DECLARE SUB MIDWAIT ()].  MIDWAIT
; waits until midnight if called within the last four BIOS
; "ticks" before midnight.
;             Written by Murray L. Lesser, 7/11/92

.code
        public  midwait
midwait proc
        mov     bx,6ch
around: mov     ax,40h
        mov     es,ax
        les     dx,es:[bx]      ;Read BIOS timer count
        mov     ax,es
        cmp     ax,18h          ;   (Timer resets when the
        jne     done            ;     count would be 1800b0h)
        cmp     dx,0ach         ;Starting at "midnight" - 4
        jnb     around          ;Spin until midnight
done:   ret
midwait endp
        ret
        end
