-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot2.asm
193 lines (162 loc) · 2.73 KB
/
boot2.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
[bits 16] ;16
[org 0x7c00]
start:
; Set video mode (320x200, 256 colors)
mov ax, 0x13
int 0x10
; Draw circle
mov cx, 169 ; Center X (screen middle)
mov dx, 121 ; Center Y (screen middle)
mov bx, 60 ; Radius
mov al, 13 ; Color (white)
call draw_circle
; Wait for key
mov ah, 0
int 0x16
; Return to text mode
mov ax, 0x3
int 0x10
; Halt
jmp $
; Draw circle using midpoint circle algorithm
; Parameters:
; CX = center X
; DX = center Y
; BX = radius
; AL = color
draw_circle:
push bp
mov bp, sp
sub sp, 6
mov [bp-2], cx ; Store center X
mov [bp-4], dx ; Store center Y
mov [bp-6], bx ; Store radius
xor si, si ; x = 0
mov di, bx ; y = radius
mov bx, 1
sub bx, di ; d = 1 - radius
.loop:
cmp si, di
jg .done
; Plot 8 points
call plot_circle_points
inc si ; x++
; Update decision variable
cmp bx, 0
jl .skip_y
dec di ; y--
add bx, si
add bx, si
sub bx, di
sub bx, di
add bx, 1
jmp .continue
.skip_y:
add bx, si
add bx, si
add bx, 1
.continue:
jmp .loop
.done:
mov sp, bp
pop bp
ret
; Plot 8 symmetrical points of the circle
; Parameters same as draw_circle
plot_circle_points:
push ax
push cx
push dx
mov cx, [bp-2] ; center X
mov dx, [bp-4] ; center Y
; Plot (x,y)
push cx
push dx
add cx, si
add dx, di
call plot_pixel
pop dx
pop cx
; Plot (x,-y)
push cx
push dx
add cx, si
sub dx, di
call plot_pixel
pop dx
pop cx
; Plot (-x,y)
push cx
push dx
sub cx, si
add dx, di
call plot_pixel
pop dx
pop cx
; Plot (-x,-y)
push cx
push dx
sub cx, si
sub dx, di
call plot_pixel
pop dx
pop cx
; Plot (y,x)
push cx
push dx
add cx, di
add dx, si
call plot_pixel
pop dx
pop cx
; Plot (y,-x)
push cx
push dx
add cx, di
sub dx, si
call plot_pixel
pop dx
pop cx
; Plot (-y,x)
push cx
push dx
sub cx, di
add dx, si
call plot_pixel
pop dx
pop cx
; Plot (-y,-x)
push cx
push dx
sub cx, di
sub dx, si
call plot_pixel
pop dx
pop cx
pop dx
pop cx
pop ax
ret
; Plot a single pixel
; Parameters:
; CX = X coordinate
; DX = Y coordinate
; AL = color
plot_pixel:
push es
push bx
mov bx, 0xa000
mov es, bx
; Calculate pixel offset (y * 320 + x)
push ax
mov ax, 320
mul dx
add ax, cx
mov bx, ax
pop ax
mov [es:bx], al
pop bx
pop es
ret
times 510-($-$$) db 0
dw 0xaa55