;And here it comes! The source code of smallest and heaviest piece of
;information in my life. No comments at all... have phun! ;)))
;Written for Netwide Assembler
;compile with:
;nasm -f bin rbbg.asm -o rbbg.com
;                                                       Trance/ARS
        BITS 16
        ORG 0x100

        mov  ch, 1
        mov  bx, tablica
fala:
        finit
        fldpi
        fimul word [_angle]
        fidiv word [_100]
        fsin
        fimul word [_63]
        fistp word [bx]
        add byte [bx], 64
        inc bx
        inc word [_angle]
        loop fala

        mov al, 13h
        int 0x10

        mov   dx, 03c8h
;        xor   al, al
        out   dx, al
        inc   dx
        or    cl, 0x80
pallop:
        out   dx, al
        out   dx, al
        out   dx, al
        inc   al
        loop  pallop


        push  word 0a000h
        pop   es

do_slime
        mov  di, 96


        mov  cl, 200

petla:  push cx

        mov  bx, cx
        mov  al, [tablica+bx]
        mov  cl, [zmienna5]

        mul  cx
        shr  ax, 6

        and  ax, 0x3f

        mov  si, tablica
        add  si, ax
        mov  ah, al
        or   ah, 64
        mov  [zmienna], ax
        not  ax
        and  ax, 0x7f7f
        mov  [zmienna3], ax


        cmp  al, 31+64
        jng  wi32


mn32:

        mov  bl, [si+128]
        mov  bh, [si+128+64]
        mov  ah, [zmienna3]
        mov  ch, [zmienna4]
        call  optimal
        jmp  nextan

wi32:
        mov  bl, [si]
        mov  bh, [si+64]
        mov  ah, [zmienna]
        mov  ch, [zmienna2]
        inc  bl
        call optimal

nextan:
        add  di, 320

        pop  cx
        loop  petla


        mov  dx, 03dah
waitr:
        in al, dx
        test al, 8
        jz waitr

        inc  byte [zmienna6]
        mov  bl, [zmienna6]
        add  bx, tablica
        mov  al, [bx]
        mov  [zmienna5], al


escloop2 in    al, 0x60
         cmp   al, 1
         jne   do_slime

koniec   mov   al, 03h
         int   0x10
         int   0x20

dziel   xor  bh, bh
        cwd
        idiv  bx

        xor  dh, dh
        xchg bl, cl
        xchg dh, ch
ptl2:   mov  byte [es:di+bx], dh
        add  dx, ax
        inc  bx
        loop ptl2
        xor  ah, ah
        ret

optimal
        sub  ah, ch
        sub  bl, bh
        mov  cl, bh
        call dziel

        mov  bl, [si+64]
        mov  bh, [si+128]
        sub  bl, bh
        mov  cl, bh
        mov  ah, [zmienna2]
        mov  ch, [zmienna3]
        sub  ah, ch

        call dziel
        ret

_angle dw 0
_100 dw 128
_63 dw 63
zmienna6 db 1
         SECTION .bss
tablica resb 256
zmienna resb 1
zmienna2 resb 1
zmienna3 resb 1
zmienna4 resb 1
zmienna5 resb 1
