# HG changeset patch # User John Tsiombikas # Date 1496872881 -10800 # Node ID 48755f08211ac81d562fb7d0112e87ca63d324ca # Parent 81facff3a8ae7a4b84db8c146a4cdcb903cb9b51 move a block around diff -r 81facff3a8ae -r 48755f08211a boot.asm --- a/boot.asm Wed Jun 07 08:56:42 2017 +0300 +++ b/boot.asm Thu Jun 08 01:01:21 2017 +0300 @@ -1,16 +1,122 @@ + xcells equ 40 + ycells equ 25 + poffs equ xcells * ycells + doffs equ poffs + 2 + ticks_offs equ doffs + 2 + + key_w equ 17 + key_a equ 30 + key_s equ 31 + key_d equ 32 + + org 0x7c00 start: mov ax, 0x13 int 0x10 + + push word 0x7e00 + pop es + xor ax, ax + xor di, di + mov cx, 0xfffe + rep stosw + push es + pop ds ; cells table segment -> ds + + ; init position + mov [si + poffs + 1], byte xcells / 2 + mov [si + poffs], byte ycells / 2 + push word 0xa000 pop es mainloop: + ; keyboard input + push si + add si, doffs + in al, 0x60 + cmp al, key_s + jnz .not_s + mov [si], word 1 +.not_s: cmp al, key_w + jnz .not_w + mov [si], word 0x00ff +.not_w: + cmp al, key_d + jnz .not_d + mov [si], word 0x100 +.not_d: cmp al, key_a + jnz .endkey + mov [si], word 0xff00 +.endkey: + pop si + + ; clear screen + xor ax, ax xor di, di - mov ax, 0x0202 mov cx, 32000 rep stosw + mov ax, [si + poffs] ; grab position + + mov cx, [si + ticks_offs] + inc cx + and cx, 0x3ff + jnz .skip_move ; only move every 64 vsyncs + + ; move + add ah, [si + doffs + 1] + jnz .xnot0 + neg byte [si + doffs + 1] +.xnot0: cmp ah, xcells - 1 + jnz .xnotmax + neg byte [si + doffs + 1] +.xnotmax: + add al, [si + doffs] + jnz .ynot0 + neg byte [si + doffs] +.ynot0: cmp al, ycells + jnz .ynotmax + neg byte [si + doffs] +.ynotmax: + mov [si + poffs], ax +.skip_move: + mov [si + ticks_offs], cx + + call draw_block + + + ; wait vsync + mov dx, 0x3da +.vbwait:in al, dx + and al, 8 + jz .vbwait jmp mainloop +; ah: x, al: y +draw_block: + push ax + xor al, al + shr ax, 5 + mov di, ax + + pop ax + xor ah, ah + shl ax, 3 + mov bx, 320 + mul bx + add di, ax + mov cx, 6 +.sline: + add di, 320 + mov eax, 0x0f0f0f00 + stosd + shr eax, 8 + stosd + sub di, 8 + dec cx + jnz .sline + ret + resb 510 - ($ - start) db 0x55, 0xaa