-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdl.asm
92 lines (74 loc) · 1.24 KB
/
sdl.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;
;; Title: Wanna be sokoban
;; Copyright: 2013 Damian Ziemba
;; Authors: Damian Ziemba <[email protected]>
;; License: GPL
;;
[bits 64]
; exports
global initSDL
global handleEvent
; imports - program
extern screenWidth
extern screenHeight
extern gameTitle
extern keys
; imports - sdl
extern SDL_Init
extern SDL_SetVideoMode
extern SDL_EnableKeyRepeat
extern SDL_WM_SetCaption
extern SDL_PollEvent
; imports - libc
extern printf
section .text
[bits 64]
initSDL:
;SDL_Init
mov RDI, 0x20 ; InitVideo
call SDL_Init
;SDL_SetVideoMode
mov RCX, 0x2 ; openGL
mov RDX, 24 ; 24bpp
mov RSI, screenHeight
mov RDI, screenWidth
call SDL_SetVideoMode
;SDL_EnableKeyRepeat
mov RSI, 30
mov RDI, 500
call SDL_EnableKeyRepeat
;SDL_SetCaption
mov RSI, 0
mov RDI, gameTitle
call SDL_WM_SetCaption
ret
quitSDL:
handleEvent:
mov RBP, RSP
sub RSP, 0x20 ; SDL_Event [ RBP + 24 ]
loop:
lea RAX, [RBP-0x20]
mov RDI, RAX
call SDL_PollEvent
and RAX, RAX
jz true
movzx RAX, byte [RBP-0x20]
cmp RAX, 0x2
je handleKeyDown
jmp loop
false:
add RSP, 0x20
xor RAX, RAX
ret
true:
add RSP, 0x20
mov RAX, 1
ret
handleKeyDown:
add RSP, 0x20
mov RDI, fmt
call printf
ret
section .data
;event: dq 0
fmt: db "Key down", 0xA, 0