program Space {
section module {
sdl,
std
}
section data {
int rax = 0
int rbx = 0
int rcx = 0
int rdx = 0
int rsi = 0
int rdi = 0
int r8 = 0
int r9 = 0
int r10 = 0
int r11 = 0
float xmm0 = 0.0
float xmm1 = 0.0
float xmm2 = 0.0
float xmm3 = 0.0
float xmm4 = 0.0
float xmm5 = 0.0
float xmm6 = 0.0
float xmm7 = 0.0
float xmm8 = 0.0
float xmm9 = 0.0
float xmm10 = 0.0
float xmm11 = 0.0
float xmm12 = 0.0
float xmm13 = 0.0
float xmm14 = 0.0
float xmm15 = 0.0
float xmm16 = 0.0
float xmm17 = 0.0
float xmm18 = 0.0
float xmm19 = 0.0
float xmm20 = 0.0
float xmm21 = 0.0
float xmm22 = 0.0
float xmm23 = 0.0
float xmm24 = 0.0
float xmm25 = 0.0
float xmm26 = 0.0
float xmm27 = 0.0
float xmm28 = 0.0
float xmm29 = 0.0
float xmm30 = 0.0
float xmm31 = 0.0
float xmm32 = 0.0
float xmm33 = 0.0
float xmm34 = 0.0
float xmm35 = 0.0
float xmm36 = 0.0
float xmm37 = 0.0
float xmm38 = 0.0
ptr arg0 = null
float real_const_5 = 0.995
float real_const_3 = 0.08
float real_const_2 = 180.000000
float real_const_1 = 320.000000
float real_const_4 = 0.14
string str_0 = "Space"
string str_1 = "font.ttf"
string str_2 = "failed to init SDL"
string str_3 = "Could not create window"
string str_4 = "could not create renderer"
string str_5 = "could not create render target"
string str_6 = "Font subsystem failed to load"
string str_7 = "failed to open: "
string fmt_str = "%s "
string newline = "\n"
ptr title = null
ptr filename = null
int running = 0
int event_type_result = 0
int window_id = 0
int renderer = 0
int target_id = 0
int font_id = 0
int key = 0
ptr the_ship = null
int keyLeft = 0
int keyRight = 0
int keyThrust = 0
float draw_ship_lx1 = 0.0
float draw_ship_ly1 = 0.0
float draw_ship_lx2 = 0.0
float draw_ship_ly2 = 0.0
float draw_ship_lx3 = 0.0
float draw_ship_ly3 = 0.0
int draw_ship_x1 = 0
int draw_ship_y1 = 0
int draw_ship_x2 = 0
int draw_ship_y2 = 0
int draw_ship_x3 = 0
int draw_ship_y3 = 0
float draw_ship_c = 0.0
float draw_ship_s = 0.0
float update_ship_accel = 0.0
float update_ship_drag = 0.0
ptr init_title = null
int init_xval = 0
int init_yval = 0
int init_wval = 0
int init_hval = 0
int init_result = 0
int __funcret_init = 0
}
section code {
start:
mov title, str_0
mov filename, str_1
alloc the_ship, 48, 1
mov arg0, title
mov rbx, 100
mov rcx, 100
mov rdx, 1280
mov rsi, 720
call PROC_init
mov running, 1
WHILE_0:
cmp running, 1
jne ENDWHILE_1
WHILE_4:
invoke poll_event
return rcx
cmp rcx, 0
je ENDWHILE_5
invoke get_event_type
return rsi
mov event_type_result, rsi
cmp event_type_result, 256
jne ELSE_8
mov running, 0
ELSE_8:
cmp event_type_result, 768
jne ELSE_12
invoke get_key_code
return r9
mov key, r9
cmp key, 27
jne ELSE_16
mov running, 0
ELSE_16:
cmp key, 1073741904
jne ELSE_20
mov keyLeft, 1
ELSE_20:
cmp key, 1073741903
jne ELSE_24
mov keyRight, 1
ELSE_24:
cmp key, 1073741906
jne ELSE_28
mov keyThrust, 1
ELSE_28:
ELSE_12:
cmp event_type_result, 769
jne ELSE_32
invoke get_key_code
return r9
mov key, r9
cmp key, 1073741904
jne ELSE_36
mov keyLeft, 0
ELSE_36:
cmp key, 1073741903
jne ELSE_40
mov keyRight, 0
ELSE_40:
cmp key, 1073741906
jne ELSE_44
mov keyThrust, 0
ELSE_44:
ELSE_32:
jmp WHILE_4
ENDWHILE_5:
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
call PROC_update_ship
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
call PROC_render
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
mov r9, 1280
mov r10, 720
invoke present_scaled, renderer, target_id, r9, r10
mov r9, 16
invoke delay, r9
jmp WHILE_0
ENDWHILE_1:
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
call PROC_cleanup
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
free the_ship
done
function PROC_init_space:
store real_const_1, the_ship, 0, 1
store real_const_2, the_ship, 8, 1
store 0, the_ship, 16, 1
store 0, the_ship, 24, 1
store 0, the_ship, 32, 1
store 3, the_ship, 40, 1
PROC_END_init_space:
ret
function PROC_draw_ship:
mov draw_ship_lx1, 0
mov draw_ship_ly1, 0
sub draw_ship_ly1, 12
mov draw_ship_lx2, 0
sub draw_ship_lx2, 8
mov draw_ship_ly2, 8
mov draw_ship_lx3, 8
mov draw_ship_ly3, 8
load xmm0, the_ship, 32, 1
invoke cos, xmm0
return xmm1
mov draw_ship_c, xmm1
load xmm0, the_ship, 32, 1
invoke sin, xmm0
return xmm2
mov draw_ship_s, xmm2
load xmm0, the_ship, 0, 1
mov xmm3, draw_ship_lx1
mul xmm3, draw_ship_c
mov xmm4, draw_ship_ly1
mul xmm4, draw_ship_s
sub xmm3, xmm4
add xmm0, xmm3
invoke trunc, xmm0
return xmm5
mov draw_ship_x1, xmm5
load xmm0, the_ship, 8, 1
mov xmm6, draw_ship_lx1
mul xmm6, draw_ship_s
mov xmm7, draw_ship_ly1
mul xmm7, draw_ship_c
add xmm6, xmm7
add xmm0, xmm6
invoke trunc, xmm0
return xmm8
mov draw_ship_y1, xmm8
load xmm0, the_ship, 0, 1
mov xmm9, draw_ship_lx2
mul xmm9, draw_ship_c
mov xmm10, draw_ship_ly2
mul xmm10, draw_ship_s
sub xmm9, xmm10
add xmm0, xmm9
invoke trunc, xmm0
return xmm11
mov draw_ship_x2, xmm11
load xmm0, the_ship, 8, 1
mov xmm12, draw_ship_lx2
mul xmm12, draw_ship_s
mov xmm13, draw_ship_ly2
mul xmm13, draw_ship_c
add xmm12, xmm13
add xmm0, xmm12
invoke trunc, xmm0
return xmm14
mov draw_ship_y2, xmm14
load xmm0, the_ship, 0, 1
mov xmm15, draw_ship_lx3
mul xmm15, draw_ship_c
mov xmm16, draw_ship_ly3
mul xmm16, draw_ship_s
sub xmm15, xmm16
add xmm0, xmm15
invoke trunc, xmm0
return xmm17
mov draw_ship_x3, xmm17
load xmm0, the_ship, 8, 1
mov xmm18, draw_ship_lx3
mul xmm18, draw_ship_s
mov xmm19, draw_ship_ly3
mul xmm19, draw_ship_c
add xmm18, xmm19
add xmm0, xmm18
invoke trunc, xmm0
return xmm20
mov draw_ship_y3, xmm20
mov rdx, 255
mov rsi, 255
mov rdi, 255
mov r8, 255
invoke set_draw_color, renderer, rdx, rsi, rdi, r8
invoke draw_line, renderer, draw_ship_x1, draw_ship_y1, draw_ship_x2, draw_ship_y2
invoke draw_line, renderer, draw_ship_x2, draw_ship_y2, draw_ship_x3, draw_ship_y3
invoke draw_line, renderer, draw_ship_x3, draw_ship_y3, draw_ship_x1, draw_ship_y1
cmp keyThrust, 0
je ELSE_48
mov rdx, 255
mov rsi, 160
mov rdi, 0
mov r8, 255
invoke set_draw_color, renderer, rdx, rsi, rdi, r8
load xmm0, the_ship, 0, 1
mov rdx, 0
sub rdx, 4
mov xmm21, rdx
mul xmm21, draw_ship_c
mov xmm22, 8
mul xmm22, draw_ship_s
sub xmm21, xmm22
add xmm0, xmm21
invoke trunc, xmm0
return xmm23
mov draw_ship_x1, xmm23
load xmm0, the_ship, 8, 1
mov rsi, 0
sub rsi, 4
mov xmm24, rsi
mul xmm24, draw_ship_s
mov xmm25, 8
mul xmm25, draw_ship_c
add xmm24, xmm25
add xmm0, xmm24
invoke trunc, xmm0
return xmm26
mov draw_ship_y1, xmm26
load xmm0, the_ship, 0, 1
mov xmm27, 0
mul xmm27, draw_ship_c
mov xmm28, 16
mul xmm28, draw_ship_s
sub xmm27, xmm28
add xmm0, xmm27
invoke trunc, xmm0
return xmm29
mov draw_ship_x2, xmm29
load xmm0, the_ship, 8, 1
mov xmm30, 0
mul xmm30, draw_ship_s
mov xmm31, 16
mul xmm31, draw_ship_c
add xmm30, xmm31
add xmm0, xmm30
invoke trunc, xmm0
return xmm32
mov draw_ship_y2, xmm32
load xmm0, the_ship, 0, 1
mov xmm33, 4
mul xmm33, draw_ship_c
mov xmm34, 8
mul xmm34, draw_ship_s
sub xmm33, xmm34
add xmm0, xmm33
invoke trunc, xmm0
return xmm35
mov draw_ship_x3, xmm35
load xmm0, the_ship, 8, 1
mov xmm36, 4
mul xmm36, draw_ship_s
mov xmm37, 8
mul xmm37, draw_ship_c
add xmm36, xmm37
add xmm0, xmm36
invoke trunc, xmm0
return xmm38
mov draw_ship_y3, xmm38
invoke draw_line, renderer, draw_ship_x1, draw_ship_y1, draw_ship_x2, draw_ship_y2
invoke draw_line, renderer, draw_ship_x2, draw_ship_y2, draw_ship_x3, draw_ship_y3
ELSE_48:
PROC_END_draw_ship:
ret
function PROC_update_ship:
cmp keyLeft, 0
je ELSE_50
load xmm0, the_ship, 32, 1
mov xmm1, real_const_3
sub xmm0, xmm1
store xmm0, the_ship, 32, 1
ELSE_50:
cmp keyRight, 0
je ELSE_52
load xmm2, the_ship, 32, 1
mov xmm3, real_const_3
add xmm2, xmm3
store xmm2, the_ship, 32, 1
ELSE_52:
mov xmm4, real_const_4
mov update_ship_accel, xmm4
cmp keyThrust, 0
je ELSE_54
load xmm5, the_ship, 16, 1
load xmm6, the_ship, 32, 1
invoke sin, xmm6
return xmm7
mul xmm7, update_ship_accel
add xmm5, xmm7
store xmm5, the_ship, 16, 1
load xmm6, the_ship, 24, 1
load xmm8, the_ship, 32, 1
invoke cos, xmm8
return xmm9
mul xmm9, update_ship_accel
sub xmm6, xmm9
store xmm6, the_ship, 24, 1
ELSE_54:
mov xmm8, real_const_5
mov update_ship_drag, xmm8
load xmm10, the_ship, 16, 1
mul xmm10, update_ship_drag
store xmm10, the_ship, 16, 1
load xmm11, the_ship, 24, 1
mul xmm11, update_ship_drag
store xmm11, the_ship, 24, 1
load xmm12, the_ship, 0, 1
load xmm13, the_ship, 16, 1
add xmm12, xmm13
store xmm12, the_ship, 0, 1
load xmm14, the_ship, 8, 1
load xmm15, the_ship, 24, 1
add xmm14, xmm15
store xmm14, the_ship, 8, 1
load xmm16, the_ship, 0, 1
cmp xmm16, 0
jge ELSE_56
load xmm17, the_ship, 0, 1
add xmm17, 640
store xmm17, the_ship, 0, 1
ELSE_56:
load xmm18, the_ship, 0, 1
cmp xmm18, 640
jl ELSE_60
load xmm19, the_ship, 0, 1
sub xmm19, 640
store xmm19, the_ship, 0, 1
ELSE_60:
load xmm20, the_ship, 8, 1
cmp xmm20, 0
jge ELSE_64
load xmm21, the_ship, 8, 1
add xmm21, 360
store xmm21, the_ship, 8, 1
ELSE_64:
load xmm22, the_ship, 8, 1
cmp xmm22, 360
jl ELSE_68
load xmm23, the_ship, 8, 1
sub xmm23, 360
store xmm23, the_ship, 8, 1
ELSE_68:
PROC_END_update_ship:
ret
function PROC_render:
invoke set_render_target, renderer, target_id
mov rbx, 0
mov rcx, 0
mov rdx, 0
mov rsi, 255
invoke set_draw_color, renderer, rbx, rcx, rdx, rsi
invoke clear, renderer
call PROC_draw_ship
PROC_END_render:
ret
function PROC_init:
mov init_title, arg0
mov init_xval, rbx
mov init_yval, rcx
mov init_wval, rdx
mov init_hval, rsi
invoke init
return rbx
mov __funcret_init, rbx
cmp __funcret_init, 0
je ELSE_72
print fmt_str, str_2
print newline
exit 1
ELSE_72:
mov rsi, 4
invoke create_window, title, init_xval, init_yval, init_wval, init_hval, rsi
return rdx
mov window_id, rdx
mov rsi, 0
sub rsi, 1
cmp window_id, rsi
jne ELSE_76
print fmt_str, str_3
print newline
invoke quit
exit 1
ELSE_76:
mov r8, 0
sub r8, 1
mov r10, 2
invoke create_renderer, window_id, r8, r10
return r9
mov renderer, r9
mov r8, 0
sub r8, 1
cmp renderer, r8
jne ELSE_80
print fmt_str, str_4
print newline
invoke destroy_window, window_id
invoke quit
exit 1
ELSE_80:
mov r10, 640
mov r11, 360
invoke create_render_target, renderer, r10, r11
return r9
mov target_id, r9
mov r9, 0
sub r9, 1
cmp target_id, r9
jne ELSE_84
print fmt_str, str_5
print newline
invoke destroy_renderer, renderer
invoke destroy_window, window_id
invoke quit
exit 1
ELSE_84:
invoke init_text
return r9
cmp r9, 1
je ELSE_88
print fmt_str, str_6
print newline
exit 1
ELSE_88:
mov r10, 16
invoke load_font, filename, r10
return r9
mov font_id, r9
mov r9, 0
sub r9, 1
cmp font_id, r9
jne ELSE_92
print fmt_str, str_7
print fmt_str, filename
print newline
exit 1
ELSE_92:
mov keyLeft, 0
mov keyRight, 0
mov keyThrust, 0
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
push init_title
push init_xval
push init_yval
push init_wval
push init_hval
push init_result
call PROC_init_space
pop init_result
pop init_hval
pop init_wval
pop init_yval
pop init_xval
pop init_title
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
PROC_END_init:
ret
function PROC_cleanup:
invoke destroy_render_target, target_id
invoke destroy_renderer, renderer
invoke destroy_window, window_id
invoke quit_text
invoke quit
PROC_END_cleanup:
ret
}
}