bootgame1

view boot.asm @ 1:48755f08211a

move a block around
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 Jun 2017 01:01:21 +0300
parents 81facff3a8ae
children
line source
1 xcells equ 40
2 ycells equ 25
3 poffs equ xcells * ycells
4 doffs equ poffs + 2
5 ticks_offs equ doffs + 2
7 key_w equ 17
8 key_a equ 30
9 key_s equ 31
10 key_d equ 32
12 org 0x7c00
13 start:
14 mov ax, 0x13
15 int 0x10
17 push word 0x7e00
18 pop es
19 xor ax, ax
20 xor di, di
21 mov cx, 0xfffe
22 rep stosw
23 push es
24 pop ds ; cells table segment -> ds
26 ; init position
27 mov [si + poffs + 1], byte xcells / 2
28 mov [si + poffs], byte ycells / 2
30 push word 0xa000
31 pop es
33 mainloop:
34 ; keyboard input
35 push si
36 add si, doffs
37 in al, 0x60
38 cmp al, key_s
39 jnz .not_s
40 mov [si], word 1
41 .not_s: cmp al, key_w
42 jnz .not_w
43 mov [si], word 0x00ff
44 .not_w:
45 cmp al, key_d
46 jnz .not_d
47 mov [si], word 0x100
48 .not_d: cmp al, key_a
49 jnz .endkey
50 mov [si], word 0xff00
51 .endkey:
52 pop si
54 ; clear screen
55 xor ax, ax
56 xor di, di
57 mov cx, 32000
58 rep stosw
60 mov ax, [si + poffs] ; grab position
62 mov cx, [si + ticks_offs]
63 inc cx
64 and cx, 0x3ff
65 jnz .skip_move ; only move every 64 vsyncs
67 ; move
68 add ah, [si + doffs + 1]
69 jnz .xnot0
70 neg byte [si + doffs + 1]
71 .xnot0: cmp ah, xcells - 1
72 jnz .xnotmax
73 neg byte [si + doffs + 1]
74 .xnotmax:
75 add al, [si + doffs]
76 jnz .ynot0
77 neg byte [si + doffs]
78 .ynot0: cmp al, ycells
79 jnz .ynotmax
80 neg byte [si + doffs]
81 .ynotmax:
82 mov [si + poffs], ax
83 .skip_move:
84 mov [si + ticks_offs], cx
86 call draw_block
89 ; wait vsync
90 mov dx, 0x3da
91 .vbwait:in al, dx
92 and al, 8
93 jz .vbwait
94 jmp mainloop
96 ; ah: x, al: y
97 draw_block:
98 push ax
99 xor al, al
100 shr ax, 5
101 mov di, ax
103 pop ax
104 xor ah, ah
105 shl ax, 3
106 mov bx, 320
107 mul bx
108 add di, ax
109 mov cx, 6
110 .sline:
111 add di, 320
112 mov eax, 0x0f0f0f00
113 stosd
114 shr eax, 8
115 stosd
116 sub di, 8
117 dec cx
118 jnz .sline
119 ret
121 resb 510 - ($ - start)
122 db 0x55, 0xaa