        ideal

        model tiny
        codeseg
        p386

scrolliptr      dw 0
yrow            dw 0

proc    scrolli far
public  scrolli
        mov     dx, 3dah
        in      al, dx
        test    al, 8
        jnz     $-3
        in      al, dx
        test    al, 8
        jz      $-3

        cld
        mov     ax, 0a000h
        mov     es, ax
        xor     di, di
        mov     cx, 64000/4
        xor     eax, eax
        rep     stosd

        mov     dx, 3dah
        in      al, dx
        test    al, 8
        jnz     $-3
        in      al, dx
        test    al, 8
        jz      $-3
        mov     ax, 3
        int     10h

        mov     dx, 3dah
        in      al, dx
        mov     dx, 3c0h
        mov     al, 10h
        out     dx, al
        inc     dx
        in      al, dx
        dec     dx
        and     al, not 8
;        mov     al, 00000110b
        out     dx, al

        mov     dx, 3c0h
        mov     al, 20h
        out     dx, al

        mov     dx, 3d4h
        mov     ax, 0ff0eh
        out     dx, ax

;        mov     dx, 3d4h
;        mov     ax, 00309h
;        out     dx, ax

        cld
        mov     ax, 0b800h
        mov     ds, ax
        mov     es, ax

        xor     di, di
        mov     cx, 8000h/4
        xor     eax, eax
        rep     stosd

@@kelaa:
        mov     di, 160*25
        mov     ax, [cs:yrow]
        imul    ax, 160
        add     di, ax

;
;        mov     dx, 3dah
;        in      al, dx
;        test    al, 8
;        jz      $-3
;        in      al, dx
;        test    al, 8
;        jnz     $-3
;
        mov     bx, [cs:yrow]
        add     bx, 25+1
        imul    bx, 80
        mov     dx, 3d4h
        mov     al, 0ch
        mov     ah, bh
        out     dx, ax
        inc     al
        mov     ah, bl
        out     dx, ax
        mov     dx, 3d4h
        mov     ax, 0f08h
        out     dx, ax

        mov     cx, 16
@@doing:
        mov     dx, 3dah
        in      al, dx
        test    al, 8
        jnz     $-3
        in      al, dx
        test    al, 8
        jz      $-3
        in      al, 60h
        and     al, 7fh
        cmp     al, 1
        jz      loppu
        mov     dx, 3d4h
        mov     al, 8
        mov     ah, 16
        sub     ah, cl
        out     dx, ax
        mov     dx, 3dah
        in      al, dx
        test    al, 8
        jnz     $-3
        in      al, dx
        test    al, 8
        jz      $-3
        loop    @@doing

;        mov     si, 160
;        mov     di, 0
;        mov     cx, 40*25
;        rep     movsd


        mov     si, [cs:scrolliptr]
        add     si, offset texti
        mov     ah, [cs:si]
        inc     si
        or      ah, ah
        jz      loppu
        mov     cx, 80
@@rivi:
        mov     al, [cs:si]
        inc     si
        mov     [es:di+160*27], ax
        stosw
        loop    @@rivi
        add     [cs:scrolliptr], 81
        inc     [cs:yrow]
        cmp     [cs:yrow], 27
        jb      @@bonk
        sub     [cs:yrow], 27
@@bonk:
        in      al, 60h
        cmp     al, 1
        jz      loppu
        jmp     @@kelaa

loppu:
;        mov     ax, 3
;        int     10h
;        mov     ah, 4ch
;        int     21h
        retf
endp

texti:
include "scroller.txt"
rept 25
db 7,"                                                                                "
endm
db 00h

end     scrolli
