; so bla asked me to write a boot sector demo to go up on io... so here it is!
; baby's first 16-bit x86 demo. Ugh I hate sectors. So much. 
; This is not a generic plasma. There are no sines. or even fakey sines.
; or palette rotations or... 
; nasm -f bin -o ioripple.iso ioripple.asm
; dosbox: hit control-f12 10 to 20 times to get a higher clockspeed ;)
; mount y: /tmp ; y: ; boot ioripple.iso
; - Melissa <3 

; version 0.1 Aug 26 2011
; known bugs: the "io" bitmap is too darn flickery. TOO FLICKERY I SAY

BITS 16

jmp codestart
; this is 18x10px bitmap data for a really small and ugly "io"
; compression? what's that?
iotext:
db 0xff,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x55,0x0,0x0, 0x0,0x55,0x55,0x55,0x55,0x55,0x0,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x0,0x0,0x0,	0x55,0x0,0x0,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x55,0x0,0x0, 0x55,0x0,0x0,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x55,0x0,0x0,0x55,0x0,0x0,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x55,0x0,0x0,0x55,0x0,0x0,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x55,0x0,0x0,0x55,0x0,0x0,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x55,0x0,0x0,0x0,0x55,0x55,0x55,0x55,0x55,0x0,0x0,0x0,0x0,0xff
db 0xff,0x0,0x0,0x0,0x0,0x0,0x0,	0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xff


; set display mode
codestart:
mov ax,0x13
int 0x10
push 0xA000
pop ds

; noice steel blue generator 
xor ax,ax
mov cx, 0xff
mov dx, 0x3c8
palette:
	mov al, cl
	out dx, al
	inc dx
	shr al, 1
	or al, 8
	add al, 60
	out dx, al
	sub al, 60
	out dx, al
	;xor al, al
	out dx, al
	dec dx
	dec cx

jnz palette


; cool vertical stripes (can only really see it on a slow emu but we need it
; to init the screen with something for the ripples to ripple)
mov bx, 0xfa01
stripes:
	mov ax,bx
	dec ax
	xor ax,bx
	mov byte [bx],al
	dec bx
jnz stripes

MasterJump:
; slightly modified from bla's smoothing filter
mov dx, 8
smooth:
	mov bx, 0xfa00-0x140
	inner:
		dec bx
		xor cx, cx
		xor ax, ax
		mov al, byte [bx]
		mov cl, byte [bx-0x140]
		add ax, cx
		mov cl, byte [bx+0x140]
		add ax,cx
		mov cl, byte [bx-2]
		add ax,cx
		mov cl, byte [bx+1]
		add ax,cx
		shl ax, 3
		mov cl, 40 
		div cl
		mov byte [bx],al
		cmp bx, 0x140
	jne inner

; blitting the "io"
cld
mov cx,18
mov ax,10
push 0x07c0
pop ds
mov si,0x0003
push 0xa000
pop es
mov di, 80*320+150

blit:
	rep movsb
	dec ax
	mov cx,18
	add di,320-18
	cmp ax,0
jne blit

push 0xa000
pop ds

	dec dx
jnz smooth

;killing time
;	mov ah, 0x86
;	mov dx,20480
;	mov cx,0
;	int 0x15

; and here is my beautiful and elegant and lovely rippler
; a maximally clever person could probably find a way to do both filters in
; one pass but if I were maximally clever I would be doing something more useful

	mov bx, 0xfa00-0x140
ripple:
		dec bx
		mov al, byte [bx]
		mov dl, byte[bx]
		mov cl, byte[bx+1]
		add al, cl
		mov cl, byte[bx-1]
		add al, cl
		mov cl, byte[bx-320]
		add al, cl
		mov cl, byte[bx+320]
		add al, cl
		shr al, 5
		mov dl, byte[bx]
		sub al,dl
		mov dl, byte[bx]
		shr dl,1
		sub al,dl
		mov byte [bx],al
		cmp bx,0x140
jne ripple
	


	
push 0xa000
pop ds
	

jmp MasterJump

; the one true signature
db 0xab,0xad,0x1d,0xea
db 0xab,0xad,0x1d,0xea
db "written for io.smashthestack.org by Melissa"


padding: times 446 - ($-$$) db 0
partitiontable: times 64 db 0xff
signature: db 0x55, 0xaa