-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.s
101 lines (81 loc) · 2.14 KB
/
render.s
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
93
94
95
96
97
98
99
100
101
## This file defines the routine that draws rectangle on the screen
## depending on the screen state in the virtual machine
.intel_syntax
.set PIXEL_SIZE , 10
.globl render_screen
.text
render_screen:
## RDI contains a pointer to the renderer
push %rbp
mov %rbp, %rsp
## Loop on the screen info
xor %rsi, %rsi # i
line: cmp %rsi, 32 # 32 lines
je return
xor %rdx, %rdx # j
col: cmp %rdx, 64 # 64 columns
je nextline
## Get index of the current cell
mov %rcx, %rsi # cell = i*64 + j
imul %rcx, 64
add %rcx, %rdx
mov %cl, BYTE PTR [screen+%rcx]
cmp %cl, 1
jne nodraw
mov %rcx, %rdx
imul %rcx, PIXEL_SIZE # X = j*10
mov DWORD PTR [x], %ecx
mov %rcx, %rsi
imul %rcx, PIXEL_SIZE # Y = i*10
mov DWORD PTR [y], %ecx
push %rdi
push %rsi
push %rdx
lea %rsi, x # Load rectangle address
call fill_rect
pop %rdx
pop %rsi
pop %rdi
nodraw:
inc %rdx
jmp col
nextline:
inc %rsi
jmp line
return: pop %rbp
ret
fill_rect:
push %rbp
mov %rbp, %rsp
xor %rsi, %rsi # i
rline: cmp %rsi, PIXEL_SIZE # 10 lines
je return_pixel
xor %rdx, %rdx # j
rcol: cmp %rdx, PIXEL_SIZE # 10 columns
je nextline_pixel
push %rdi
push %rsi
push %rdx
## X in rsi
## Y in rdx
push %rsi
mov %esi, DWORD PTR [x]
add %rsi, %rdx
pop %rdx
add %edx, DWORD PTR [y]
call SDL_RenderDrawPoint
pop %rdx
pop %rsi
pop %rdi
nodraw_pixel:
inc %rdx
jmp rcol
nextline_pixel:
inc %rsi
jmp rline
return_pixel:
pop %rbp
ret
.data
x: .int 0 # x
y: .int 0 # y