    org 0x8000

start:
   
    db %01000000, %01100100, %01001001, %01101101

    ld e,a
; --- BORDER COLOR ---
    inc a
    out (254),a

; --- SIN TABLE ---
	inc b
sinloop:
    ld c,e
    rrc c
    sbc a,a
    ld d,a
    xor h
    ld (bc),a
    add hl,de
    dec e
    jr nz,sinloop

; --- SET TILE ---
    ld h,0x57
loop3:
    ld de,tiledata
    ld b,8
loop2:
    ld a,(de)
loop1:
    ld (hl),a
    inc l
    jr nz,loop1
    dec h
    inc e
    djnz loop2
    bit 6,h
    jr nz,loop3

; --- EFFECT ---
frameloop:
    ld de,0x5800

    ld c,24
yloop:
    ld b,32 
xloop:
    push de

;sinprep:
    ld h,0x81
    ld a,ixl
    add b
    ld l,a
    ld a,(hl)
    ld iyl,a
    rra
    rra
    add c
    ld e,a

;rotate45:
    ld a,b
    sub ixl
    add e
    ld d,a
    sub e
    sub e

;and1:
    and d
    ld e,a
    rra
    rra
    and %00000111
    cp 4
    jr c,and2
    and %00000011
    jr nz,fish
    
and2:
    ld a,e
    rra
    and %00000111
    cp 4
    jr c,ocean
    add e
    and %00000010
    jr z,ocean

fish:
    dec h
    ld l,a
    ld a,(hl)
    jr done

ocean:
    ld a,c
    add a,iyl
    sub ixl
    rra
    rra
    or d
    and 1

done:
    pop de
    ld (de),a
    inc de

    djnz xloop
    dec c
    jr nz, yloop

    inc ix
    jr frameloop

tiledata:
    db %001100
    db %010010
    db %100001
    db %101001
    db %010010
    db %001100

end
  