sortof bounds-check while moving
[ld45_start_nothing] / src / main.asm
1 ; vi:filetype=nasm ts=8 sts=8 sw=8:
2         bits 32
3 %include "gfx.inc"
4 %include "keyb.inc"
5 %include "intr.inc"
6 %include "dbglog.inc"
7
8 PLAYER_MOVE_SPEED equ 5
9
10         ; this is placed at the beginning of our binary at 1mb (see game.ld)
11         ; and it's what gets executed directly by the boot loader
12         section .startup
13         jmp main
14
15         ; start of main
16         section .text
17 main:
18         call init_intr
19         call kb_init
20         call init_gfx
21
22         dbglog `hello\n`
23
24         sti
25 main_loop:
26         call update
27
28         call clear
29
30         push dword 0
31         mov eax, [ship_y]
32         shr eax, 8
33         push eax
34         mov eax, [ship_x]
35         shr eax, 8
36         push eax
37         push dword FRAMEBUF_ADDR
38         call sprsheet
39         add esp, 16
40
41         call wait_vsync
42         call swap_buffers
43         jmp main_loop
44
45 update:
46         mov eax, [ship_y]
47
48         check_key SC_W
49         jnc .not_w
50         sub eax, PLAYER_MOVE_SPEED
51         jns .not_w
52         xor eax, eax
53 .not_w: check_key SC_S
54         jnc .not_s
55         add eax, PLAYER_MOVE_SPEED
56         cmp eax, 200 << 8
57         jb .not_s
58         mov eax, 200 << 8
59 .not_s:
60         mov [ship_y], eax
61         mov eax, [ship_x]
62
63         check_key SC_A
64         jnc .not_a
65         sub eax, PLAYER_MOVE_SPEED
66         jns .not_a
67         xor eax, eax
68 .not_a: check_key SC_D
69         jnc .not_d
70         add eax, PLAYER_MOVE_SPEED
71         cmp eax, 320 << 8
72         jb .not_d
73         mov eax, 320 << 8
74 .not_d:
75         mov [ship_x], eax
76         ret
77
78         section .data
79         align 4
80 ship_x: dd 160 << 8
81 ship_y: dd 100 << 8