bootgame1

changeset 1:48755f08211a tip

move a block around
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 Jun 2017 01:01:21 +0300
parents 81facff3a8ae
children
files boot.asm
diffstat 1 files changed, 107 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/boot.asm	Wed Jun 07 08:56:42 2017 +0300
     1.2 +++ b/boot.asm	Thu Jun 08 01:01:21 2017 +0300
     1.3 @@ -1,16 +1,122 @@
     1.4 +	xcells equ 40
     1.5 +	ycells equ 25
     1.6 +	poffs equ xcells * ycells
     1.7 +	doffs equ poffs + 2
     1.8 +	ticks_offs equ doffs + 2
     1.9 +
    1.10 +	key_w equ 17
    1.11 +	key_a equ 30
    1.12 +	key_s equ 31
    1.13 +	key_d equ 32
    1.14 +
    1.15 +	org 0x7c00
    1.16  start:
    1.17  	mov ax, 0x13
    1.18  	int 0x10
    1.19 +
    1.20 +	push word 0x7e00
    1.21 +	pop es
    1.22 +	xor ax, ax
    1.23 +	xor di, di
    1.24 +	mov cx, 0xfffe
    1.25 +	rep stosw
    1.26 +	push es
    1.27 +	pop ds   ; cells table segment -> ds
    1.28 +
    1.29 +	; init position
    1.30 +	mov [si + poffs + 1], byte xcells / 2
    1.31 +	mov [si + poffs], byte ycells / 2
    1.32 +
    1.33  	push word 0xa000
    1.34  	pop es
    1.35  
    1.36  mainloop:
    1.37 +	; keyboard input
    1.38 +	push si
    1.39 +	add si, doffs
    1.40 +	in al, 0x60
    1.41 +	cmp al, key_s
    1.42 +	jnz .not_s
    1.43 +	mov [si], word 1
    1.44 +.not_s: cmp al, key_w
    1.45 +	jnz .not_w
    1.46 +	mov [si], word 0x00ff
    1.47 +.not_w:
    1.48 +	cmp al, key_d
    1.49 +	jnz .not_d
    1.50 +	mov [si], word 0x100
    1.51 +.not_d: cmp al, key_a
    1.52 +	jnz .endkey
    1.53 +	mov [si], word 0xff00
    1.54 +.endkey:
    1.55 +	pop si
    1.56 +
    1.57 +	; clear screen
    1.58 +	xor ax, ax
    1.59  	xor di, di
    1.60 -	mov ax, 0x0202
    1.61  	mov cx, 32000
    1.62  	rep stosw
    1.63  
    1.64 +	mov ax, [si + poffs]	; grab position
    1.65 +
    1.66 +	mov cx, [si + ticks_offs]
    1.67 +	inc cx
    1.68 +	and cx, 0x3ff
    1.69 +	jnz .skip_move		; only move every 64 vsyncs
    1.70 +
    1.71 +	; move
    1.72 +	add ah, [si + doffs + 1]
    1.73 +	jnz .xnot0
    1.74 +	neg byte [si + doffs + 1]
    1.75 +.xnot0:	cmp ah, xcells - 1
    1.76 +	jnz .xnotmax
    1.77 +	neg byte [si + doffs + 1]
    1.78 +.xnotmax:
    1.79 +	add al, [si + doffs]
    1.80 +	jnz .ynot0
    1.81 +	neg byte [si + doffs]
    1.82 +.ynot0:	cmp al, ycells
    1.83 +	jnz .ynotmax
    1.84 +	neg byte [si + doffs]
    1.85 +.ynotmax:
    1.86 +	mov [si + poffs], ax
    1.87 +.skip_move:
    1.88 +	mov [si + ticks_offs], cx
    1.89 +
    1.90 +	call draw_block
    1.91 +
    1.92 +
    1.93 +	; wait vsync
    1.94 +	mov dx, 0x3da
    1.95 +.vbwait:in al, dx
    1.96 +	and al, 8
    1.97 +	jz .vbwait
    1.98  	jmp mainloop
    1.99  
   1.100 +; ah: x, al: y
   1.101 +draw_block:
   1.102 +	push ax
   1.103 +	xor al, al
   1.104 +	shr ax, 5
   1.105 +	mov di, ax
   1.106 +
   1.107 +	pop ax
   1.108 +	xor ah, ah
   1.109 +	shl ax, 3
   1.110 +	mov bx, 320
   1.111 +	mul bx
   1.112 +	add di, ax
   1.113 +	mov cx, 6
   1.114 +.sline:
   1.115 +	add di, 320
   1.116 +	mov eax, 0x0f0f0f00
   1.117 +	stosd
   1.118 +	shr eax, 8
   1.119 +	stosd
   1.120 +	sub di, 8
   1.121 +	dec cx
   1.122 +	jnz .sline
   1.123 +	ret
   1.124 +
   1.125  	resb 510 - ($ - start)
   1.126  	db 0x55, 0xaa