; For God so loved the world, that He gave His only begotten Son
; That all who belive in Him should not perish but have everlasting life

;codeseg
BITS 16

org 100h

section .text

start:

; Set mode13h
mov ax, 13h
int 10h


;Print message
mov dx, jil_aleluya
mov ah, 9
int 21h

mov [frame_aleluya], WORD 0

push 0a000h
pop  es


;Frame loop
wl_aleluya:
    mov dx, [frame_aleluya]
    inc dx
    mov [frame_aleluya], dx

	;mov dx,
	mov [ptr_aleluya], word 13*320
;Vertical loop
	mov dx, 13

yloop_aleluya:
	mov [y_aleluya], dx
	mov dx, 0

;Horizontal loop
xloop_aleluya:
    mov [x_aleluya], dx

	;e a=xD2+yD2, b=2xExD+2yEyD, and c=xE2+yE2-1. 


;ALELUYA Calc color for coordinate

	mov ax, [y_aleluya]
	add ax, 100
	mov bx, 90
	mul bx ;Aleluya 7bit cos 45deg
	mov cx, ax
	push ax
	mov ax, [x_aleluya]
	sub ax, 150
	mul bx
	pop bx
	mov dx, ax
	sub ax, cx
	add bx, dx
	neg ax
	shr ax, 7
	shr bx, 7 
	
	mov dx, [frame_aleluya]
	shl dx, 3
	add bx, dx
	sub ax, 45
	shr ax, 4
	shr bx, 4
	cmp ax, 0x7
	jge notinB_aleluya
	and ax, 0x7
	and bx, 0x7f
	mov cx, 320
	mul cx
	add bx, ax
	mov di, bx
	mov al, [es:di]
	
	cmp al,0
	je notin_aleluya
	mov dx, [x_aleluya]
	add al, dl	
    mov dx, [frame_aleluya]
    add al, dl
    and al,0xf
	add al,0x1f 

    ;mov [color_aleluya], al

	jmp hasgotcol_aleluya
notinB_aleluya:
    mov al, [y_aleluya]
    mov dx, [frame_aleluya]
    add al, dl
    and al,0x2
	add al,0x11 
	;mov [color_aleluya], al
	jmp hasgotcol_aleluya

notin_aleluya:
    mov al, [x_aleluya]
    mov dx, [frame_aleluya]
    sub al, dl
    and al,0xf
	add al,0xf 
	;mov [color_aleluya], al
hasgotcol_aleluya:
;ALELUYA draw the pixel

	mov di, WORD [ptr_aleluya]
	;inc WORD  ; increase pixel pointer	
	;mov al, [color_aleluya]
 
	mov [es:di], al ;Aleluya draw pixel
    inc di
    mov [ptr_aleluya], WORD di
; loop end counters
	
	mov dx, [x_aleluya]
	inc dx
	cmp dx, 320

jl xloop_aleluya ; end horizontal loop

	mov dx, [y_aleluya]
	inc dx
	cmp dx, 187
jl yloop_aleluya ; end vertical loop

;Check for keypress and exit if pressed aleluya
    mov ah, 1
	int 16h

jz wl_aleluya

;Return to mode 3 aleluya
mov al,3h
mov ah,0
int 10h
ret
;END START

noteoff_aleluya:
in      al, 61h         ; Turn off note (get value from
                        ;  port 61h).
and     al, 11111100b   ; Reset bits 1 and 0.
out     61h, al
ret

section .data
  jil_aleluya db 'JESUS IS LORD!$'
section .bss
  buf_aleluya resb 127*10
  ptr_aleluya resw 1
  color_aleluya resb 1
  y_aleluya resw 1
  x_aleluya resw 1
  frame_aleluya resw 1

  
