-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.s
81 lines (61 loc) · 2.8 KB
/
rectangle.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
.ifndef RECTANGLE_S
RECTANGLE_S:
.include "./constants.s"
/*
* Params:
* x0: bottom left x coordinate (left) 0 <= x < SCREEN_WIDTH (right)
* x1: bottom left y coordinate (bottom) 0 <= y < SCREEN_HEIGHT (top)
* x2: top right x coordinate (left) 0 <= x < SCREEN_WIDTH (right)
* x3: top right y coordinate (bottom) 0 <= y < SCREEN_HEIGHT (top)
* x4: beginning of framebuffer
* w5: color
*/
draw_filled_rectangle:
stp lr, x19, [sp, -32]!
stp x20, x21, [sp, 16]
// TODO: check bounds?
// We need to move the framebuffer pointer to the initial position
mov x19, (SCREEN_HEIGH - 1)
sub x19, x19, x3 // x19 = first row from top
mov x20, SCREEN_WIDTH
mul x19, x19, x20 // x19 = initial vertical offset
add x19, x19, x0 // x19 = initial vertical offset + initial horizontal offset
lsl x19, x19, BYTES_PER_PIXEL_SHIFT // x19 = total offset
add x4, x4, x19 // x4 = &framebuffer['rectangle's top left pixel']
sub x19, x2, x0 // x19 = rectangle width - 1
add x19, x19, 1 // x19 = rectangle width
sub x20, x20, x19 // x20 = pixels between the end of a row and the beginning of the next row
lsl x20, x20, BYTES_PER_PIXEL_SHIFT // x20 = bytes between the end of a row and the beginning of the next row
draw_filled_rectangle__next_row:
mov x21, x19 // x19 = rectangle width
draw_filled_rectangle__next_col:
str w5, [x4] // Paint pixel
add x4, x4, BYTES_PER_PIXEL // Advance to next pixel
subs x21, x21, 1 // Check if we finished current row
b.gt draw_filled_rectangle__next_col // If not, then draw next column
add x4, x4, x20 // Advance to beginning of next row
add x1, x1, 1
cmp x1, x3
b.le draw_filled_rectangle__next_row
ldp x20, x21, [sp, 16]
ldp lr, x19, [sp], 32
ret
/*
* Params:
* x0: bottom left x coordinate (left) 0 <= x < SCREEN_WIDTH (right)
* x1: bottom left y coordinate (bottom) 0 <= y < SCREEN_HEIGHT (top)
* x2: size
* x3: beginning of framebuffer
* w4: color
*/
draw_filled_square:
stp lr, x19, [sp, -16]!
mov w5, w4
mov x4, x3
sub x2, x2, 1 // Top right (x', y') = (x + size - 1, y + size - 1)
add x3, x1, x2
add x2, x0, x2
bl draw_filled_rectangle
ldp lr, x19, [sp], 16
ret
.endif