* remove "\r" nonsense
[mascara-docs.git] / amd64 / bareMetalOS-0.5.3 / programs / nibbles.asm
blobb5b5d462cb8ea323ef3c1956f9ca6a9e83937b84
1 ; The classic game of Nibbles
2 ; Written by Ian Seyler
4 ; BareMetal compile:
5 ; nasm argtest.asm -o argtest.app
7 ; Game field is surrounded by a border. Play area is 38 x 23
9 [BITS 64]
10 [ORG 0x0000000000200000]
12 %INCLUDE "bmdev.asm"
14 start: ; Start of program label
15 call b_hide_statusbar
16 call b_hide_cursor
17 call b_screen_clear
19 mov rdi, os_screen ; Screen framebuffer
21 mov eax, 0x15DB15DB
22 mov rcx, 41
23 rep stosd ; Draw the top wall
25 mov rcx, 23
26 nextside: ; Draw the side walls
27 add rdi, 152
28 stosd
29 stosd
30 sub rcx, 1
31 cmp rcx, 0
32 jne nextside
34 mov rcx, 39
35 rep stosd ; Draw the bottom wall
37 call b_screen_update ; Copy the screen buffer to video memory
41 gameloop:
42 cmp byte [direction], 1
43 je move_up
44 cmp byte [direction], 2
45 je move_right
46 cmp byte [direction], 3
47 je move_down
48 cmp byte [direction], 4
49 je move_left
50 jmp fin ; Fatal error
52 move_up:
53 sub byte [head_x], 1
54 jmp drawworm
55 move_right:
56 add byte [head_y], 1
57 jmp drawworm
58 move_down:
59 add byte [head_x], 1
60 jmp drawworm
61 move_left:
62 sub byte [head_y], 1
63 jmp drawworm
65 drawworm:
66 mov rax, 1
67 call b_delay
68 mov ah, byte [head_y]
69 shl ah, 1
70 mov al, byte [head_x]
71 call b_move_cursor
72 mov al, 219
73 call b_print_char
74 call b_print_char
75 call b_input_key_check
76 cmp al, 'w'
77 je go_up
78 cmp al, 'a'
79 je go_left
80 cmp al, 's'
81 je go_down
82 cmp al, 'd'
83 je go_right
84 cmp al, 'q'
85 je fin
86 jmp gameloop
88 go_up:
89 mov byte [direction], 1
90 jmp gameloop
92 go_left:
93 mov byte [direction], 4
94 jmp gameloop
96 go_down:
97 mov byte [direction], 3
98 jmp gameloop
100 go_right:
101 mov byte [direction], 2
102 jmp gameloop
104 fin:
105 call b_screen_clear
106 mov ax, 0x0018 ; Set the hardware cursor to the bottom left-hand corner
107 call b_move_cursor
108 call b_show_cursor
109 call b_show_statusbar
110 ret ; Return to OS
112 head_x: db 5
113 head_y: db 5
114 direction: db 2 ; 1 up, 2 right, 3 down, 4 left
116 os_screen: equ 0x0000000000180000 ; This is the address for the text screen frame buffer. It gets copied to video memory via b_update_screen