Skip to content

Instantly share code, notes, and snippets.

@learosema
Last active November 30, 2016 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save learosema/5c9cf9316f0aed88cefd4d0957be6d03 to your computer and use it in GitHub Desktop.
Save learosema/5c9cf9316f0aed88cefd4d0957be6d03 to your computer and use it in GitHub Desktop.
16 bit DOS assembly animation

Made for DOS/DOSBox. Compile via NASM: nasm -f bin -o anim.com anim.asm

License

COFFEE PUBLIC LICENSE (CPL)

@terabaud made this. You can do whatever you want with it. If we meet some day, and you think this stuff is worth it, you can buy me a coffee in return.

org 100h
section .text
init_gfx: mov ax,13h
int 10h
mov di,0a000h
mov es,di
start: xor di,di ; pixel offset
xor bx,bx ; x position
xor cx,cx ; y position
call ticks ; dx=tick count (initially 0)
pixel: mov ax,dx
sub ax,bx
sub ax,cx
shr ax,1
imul ax,bx
imul ax,cx
shr ax,8
add ax,dx
mov [es:di+bx],al
inc bx ; increment x counter
cmp bx,320
jnz pixel
add di,bx
xor bx,bx ; reset x counter
inc cx ; increment y counter
cmp cx,200
jnz pixel
mov ah,01
int 16h
jz start
mov ah,0
int 16h
cmp al,27 ; unless escape pressed
jnz start ; go to next frame
quit: mov ax,3
int 10h
int 20h
ticks: ; returns DX=Tickcount
push es
push cx
mov cx,[initialTime]
push 40h
pop es
mov dx,[es:6ch]
cmp cx,0
jnz ticks_1
mov cx,dx
mov [initialTime],cx
ticks_1: sub dx,cx
pop cx
pop es
ret
section .data
initialTime: dw 0
section .bss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment