;       Static Name Aliases
;
;       $S116_buffrecs  EQU     buffrecs
        TITLE   pscreen
;       NAME    pscreen.C

        .287
_TEXT   SEGMENT  BYTE PUBLIC 'CODE'
_TEXT   ENDS
_DATA   SEGMENT  WORD PUBLIC 'DATA'
_DATA   ENDS
CONST   SEGMENT  WORD PUBLIC 'CONST'
CONST   ENDS
_BSS    SEGMENT  WORD PUBLIC 'BSS'
_BSS    ENDS
DGROUP  GROUP   CONST,  _BSS,   _DATA
        ASSUME  CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
EXTRN   __chkstk:NEAR
EXTRN   __fmalloc:NEAR
_DATA      SEGMENT
$S116_buffrecs  DD      20 dup(0)
_DATA      ENDS
_TEXT      SEGMENT

        PUBLIC  _pushscreen
_pushscreen     PROC NEAR
        push    bp
        mov     bp,sp
        mov     ax,12
        call    __chkstk
        push    di
        push    si
; Line 20
;       buff = 4
;       retrace = 6
;       scr_ofs = -10
;       bp = -6
;       i = -12
;       register si = c
; Line 26
        mov     di,[bp+4]       ;buff
        mov     cl,2
        shl     di,cl
        add     di,OFFSET DGROUP:$S116_buffrecs
        mov     ax,[di]
        or      ax,[di+2]
        jne     $I126

        mov     ax,4000
        push    ax
        call    __fmalloc
        add     sp,2
        mov     [di],ax
        mov     [di+2],dx
        or      ax,dx
        jne     $I126

        sub     ax,ax
        jmp     $EX120
$I126:
        mov     bx,[bp+4]       ;buff
        shl     bx,1
        shl     bx,1
        mov     ax,WORD PTR $S116_buffrecs[bx]
        mov     dx,WORD PTR $S116_buffrecs[bx+2]
        mov     [bp-6],ax       ;bp
        mov     [bp-4],dx

        mov     ah,15
        int     10h
        cmp     ah,7
        jne     $I128


        mov     WORD PTR [bp-10],0      ;scr_ofs
        mov     WORD PTR [bp-8],0b000h

        mov     WORD PTR [bp+6],0       ;retrace


        jmp     SHORT $I129
$I128:

        mov     WORD PTR [bp-10],0      ;scr_ofs
        mov     WORD PTR [bp-8],0b800h
$I129:

        mov     WORD PTR [bp-12],0      ;i
$F130:


        les     bx,[bp-10]      ;scr_ofs
        add     WORD PTR [bp-10],2      ;scr_ofs
        mov     si,es:[bx]

        cmp     WORD PTR [bp+6],0       ;retrace
        je      $I134


$WC136:
        mov     dx,3dah
        in      al,dx
        test    al,1
        jne     $WC136
$WB137:

        in      al,dx
        test    al,1
        je      $WB137


$I134:
        les     bx,[bp-6]       ;bp
        add     WORD PTR [bp-6],2       ;bp
        mov     es:[bx],si

        inc     WORD PTR [bp-12]        ;i
        cmp     WORD PTR [bp-12],2000   ;i
        jl      $F130

        mov     ax,1
$EX120:
        pop     si
        pop     di
        mov     sp,bp
        pop     bp
        ret

_pushscreen     ENDP

        PUBLIC  _popscreen
_popscreen      PROC NEAR
        push    bp
        mov     bp,sp
        mov     ax,12
        call    __chkstk
        push    si

;       buff = 4
;       retrace = 6
;       scr_ofs = -10
;       bp = -6
;       i = -12
;       register si = c

        mov     bx,[bp+4]       ;buff
        shl     bx,1
        shl     bx,1
        mov     ax,WORD PTR $S116_buffrecs[bx]
        or      ax,WORD PTR $S116_buffrecs[bx+2]
        jne     $I148

        sub     ax,ax
        jmp     SHORT $EX143
$I148:
        mov     bx,[bp+4]       ;buff
        shl     bx,1
        shl     bx,1
        mov     ax,WORD PTR $S116_buffrecs[bx]
        mov     dx,WORD PTR $S116_buffrecs[bx+2]
        mov     [bp-6],ax       ;bp
        mov     [bp-4],dx

        mov     ah,15
        int     10h
        cmp     ah,7
        jne     $I149


        mov     WORD PTR [bp-10],0      ;scr_ofs
        mov     WORD PTR [bp-8],-20480

        mov     WORD PTR [bp+6],0       ;retrace


$I149:
        mov     WORD PTR [bp-10],0      ;scr_ofs
        mov     WORD PTR [bp-8],-18432

        mov     WORD PTR [bp-12],0      ;i
$F150:


        les     bx,[bp-6]       ;bp
        add     WORD PTR [bp-6],2       ;bp
        mov     si,es:[bx]

        cmp     WORD PTR [bp+6],0       ;retrace
        je      $I154


$WC155:
        mov     dx,3dah
        in      al,dx
        test    al,1
        jne     $WC155
$WB156:

        in      al,dx
        test    al,1
        je      $WB156


$I154:
        les     bx,[bp-10]      ;scr_ofs
        add     WORD PTR [bp-10],2      ;scr_ofs
        mov     es:[bx],si

        inc     WORD PTR [bp-12]        ;i
        cmp     WORD PTR [bp-12],2000   ;i
        jl      $F150

        mov     ax,1
$EX143:
        pop     si
        mov     sp,bp
        pop     bp
        ret

_popscreen      ENDP
_TEXT   ENDS
END
