-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrect.asm
163 lines (144 loc) · 3.85 KB
/
rect.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
;===================================================================================================
; Rectangle
;
; Written By: Oded Cnaan (oded.8bit@gmail.com)
; Site: http://odedc.net
; Licence: GPLv3 (see LICENSE file)
; Package: GrLib
;
; Description:
; Draw rectangles
;===================================================================================================
LOCALS @@
;----------------------------------------------------------
; Draws a rectangle
;
; push x
; push y
; push width
; push height
; call GR_DrawRect
;----------------------------------------------------------
PROC GR_DrawRect
store_sp_bp
sub sp, 8 ; 2 bytes * 4 local vars
pusha
; now the stack is
; bp-8 => x2
; bp-6 => y2
; bp-4 => x1 - not in use
; bp-2 => y1 - not in use
; bp+0 => old base pointer
; bp+2 => return address
; bp+4 => param4 (height)
; bp+6 => param3 (width)
; bp+8 => param2 (y)
; bp+10 => param1 (x)
; saved registers
mov ax, [word bp+10]
add ax, [word bp+6] ; x + width
mov [bp-8], ax ; x2 = x + width
mov ax, [word bp+8]
add ax, [word bp+4] ; y + height
mov [word bp-6], ax ; y2 = y + height
push [word bp+10] ; x - Horz top
push [word bp+8] ; y
push [word bp-8] ; x2
push [word bp+8] ; y
call GR_DrawLine
push [word bp+10] ; x - Horz bottom
push [word bp-6] ; y2
push [word bp-8] ; x2
push [word bp-6] ; y2
call GR_DrawLine
push [word bp-8] ; x2 - Vert right
push [word bp+8] ; y
push [word bp-8] ; x2
push [word bp-6] ; y2
call GR_DrawLine
push [word bp+10] ; x - Vert left
push [word bp+8] ; y
push [word bp+10] ; x
push [word bp-6] ; y2
call GR_DrawLine
popa
restore_sp_bp
ret 8
ENDP GR_DrawRect
;+-+-+-+-+-+-+-+-+-+- RECTANGLE +-+-+-+-+-+-+-+-++-+-+-+-+-+
;----------------------------------------------------------
; Fills a rectangle
;
; push x
; push y
; push width
; push height
; call GR_FillRect
;----------------------------------------------------------
PROC GR_FillRect
store_sp_bp
sub sp, 8 ; 2 bytes * 4 local vars
pusha
; now the stack is
; bp-8 => x2
; bp-6 => y2
; bp-4 => x1
; bp-2 => y1
; bp+0 => old base pointer
; bp+2 => return address
; bp+4 => param4 (height)
; bp+6 => param3 (width)
; bp+8 => param2 (y)
; bp+10 => param1 (x)
; saved registers
mov ax, [bp+10]
add ax, [bp+6] ; x + width
mov [bp-8], ax ; x2 = x + width
mov ax, [bp+8]
add ax, [bp+4] ; y + height
mov [bp-6], ax ; y2 = y + height
@@GR_draw_rect__rect:
push [word bp+8]
pop [word bp-2]
@@GR_draw_rect__v:
push [word bp+10]
pop [word bp-4]
@@GR_draw_rect__h:
gr_set_pixel [bp-4], [bp-2], [gr_pen_color] ; draw pixel at (x1,y1)
inc [word bp-4] ; x1++
cmpv [bp-4], [bp-8], ax
jl @@GR_draw_rect__h ; if (x1 < x2) goto GR_draw_rect__h
inc [word bp-2] ; y2++
cmpv [bp-2], [bp-6], ax
jl @@GR_draw_rect__v ; if (y1 < y2) goto GR_draw_rect__v
popa
restore_sp_bp
ret 8
ENDP GR_FillRect
;////////////////////////////////////////////////////////////////////////////
; FUNCTION LIKE MACROS
;////////////////////////////////////////////////////////////////////////////
;----------------------------------------------------------------------
; Draw Rect
;
; grm_DrawRect (x, y, width, height)
;----------------------------------------------------------------------
MACRO grm_DrawRect x, y, width, height
push x
push y
push width
push height
call GR_DrawRect
ENDM
;----------------------------------------------------------------------
; Fill Rect
;
; grm_FillRect (x, y, width, height)
;----------------------------------------------------------------------
MACRO grm_FillRect x, y, width, height
push x
push y
push width
push height
call GR_FillRect
ENDM