[bits 16]
[org 0]

%define mode 13h




start:

	mov ax,cs
	mov ds,ax
	mov es,ax

        mov ah,03
        mov bh,0
        int 10h

        mov bx,[0x4049]
        mov dx,[0x4049+4]
        mov [oldmode],bx
        mov [oldmode+4],dx

        mov bp,sp           ; Set up stack pointer
        mov ax,mode         ; AX = video mode
        mov ah,0            ; AH = function number
        int 10h             ; Call video BIOS

        mov ax,0xA000
        mov es,ax
        mov ax,32010
        mov di,ax
        mov dl,7

	mov dx,0

.loop:
	push dx
	push dx
	push dx
	call putpixel
	add sp,4
	pop dx
	inc dx
	mov ax,dx
	cmp ax,200
	jne .loop

	call getch

	mov ax,3
	int 10h

	jmp 0x1000:0

putpixel:
	push bp
	mov bp,sp

        mov ax,[bp+4]   ; Y
        mov bx,[bp+6]   ; X
        mov cx,320
        mul cx
        add ax,bx
        mov di,ax
        mov dl,7
        mov [es:di],dl

	mov sp,bp
	pop bp
	ret

getch:
        push bp
        mov bp,sp
        push bx
        mov ah,0
        int 16h
        mov bx,sp
        sub sp,2
        mov [bx],word 0
        mov [bx],al
        mov ax,[bx]
        add sp,2
        pop bx
        mov sp,bp
        pop bp
        ret


section .bss
oldmode: resd 1
