bootgame1

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