…Show last 151 lines
61}
62
63
64void PutPixel(int dst, int x, int y, byte color){
65 asm mov ax, dst
66 asm mov es, ax
67 asm mov ax, y
68 asm shl ax, 6
69 asm mov bx, ax
70 asm shl ax, 2
71 asm add ax, bx
72 asm add ax, x
73 asm mov di, ax
74 asm mov al, color
75 asm mov [es:di], al
76}
77
78void WaitVerticalRefresh() {
79 asm mov dx, 0x3DA
80 lp1:
81 asm in al, dx
82 asm and al, 0x08
83 asm jnz lp1
84 lp2:
85 asm in al, dx
86 asm and al, 0x08
87 asm jz lp2
88}
89
90void SetRGB(byte color, byte r, byte g, byte b){
91 asm mov dx, 0x3c8
92 asm mov al, color
93 asm out dx, al
94 asm inc dx
95 asm mov al, r
96 asm out dx, al
97 asm mov al, g
98 asm out dx, al
99 asm mov al, b
100 asm out dx, al
101}
102
103void GetRGB(byte color, byte r, byte g, byte b){
104 asm mov dx, 0x3c7
105 asm mov al, color
106 asm out dx, al
107 asm inc dx
108 asm mov al, r
109 asm out dx, al
110 asm mov al, g
111 asm out dx, al
112 asm mov al, b
113 asm out dx, al
114}
115
116void DrawHLine(int dst, int x1,int x2,int y1, byte color){
117 asm mov ax, dst
118 asm mov es, ax
119 asm mov ax, y1
120 asm mov di, ax
121 asm shl di, 1
122 asm shl di, 1
123 asm add di, ax
124 asm mov cl, 6
125 asm shl di, cl
126 asm mov bx, x1
127 asm mov dx, x2
128 asm cmp bx, dx
129 asm jl lp1
130 asm xchg bx, dx
131lp1:
132 asm inc dx
133 asm add di, bx
134 asm mov cx, dx
135 asm sub cx, bx
136 asm shr cx, 1
137 asm mov al, color
138 asm mov ah, al
139 asm ror bx, 1
140 asm jnb lp2
141 asm stosb
142 asm ror dx, 1
143 asm jnb lp3
144 asm dec cx
145lp3:
146 asm rol dx, 1
147lp2:
148 asm rep
149 asm stosw
150 asm ror dx, 1
151 asm jnb lp4
152 asm stosb
153lp4:
154}
155
156void DrawVLine(int dst, int x1,int y1, int y2, byte color){
157 asm mov ax, x1
158 asm mov bx, y1
159 asm mov dx, y2
160 asm cmp bx, dx
161 asm jl lp1
162 asm xchg bx, dx
163lp1:
164 asm mov di, bx
165 asm shl di, 1
166 asm shl di, 1
167 asm add di, bx
168 asm mov cl, 6
169 asm shl di, cl
170 asm add di, ax
171 asm mov cx, dst
172 asm mov es, cx
173 asm mov cx, dx
174 asm sub cx, bx
175 asm inc cx
176 asm mov al, color
177 asm mov bx, 0x13f
178lp2:
179 asm stosb
180 asm add di, bx
181 asm loop lp2
182}
183
184
185void DrawLine(int dst, int x1, int y1, int x2,int y2, byte color){
186 int dx,dy,sx,sy,k;
187 sx = 1;
188 sy = 1;
189 dx = x2-x1;
190 if (dx<0) {dx=-dx; sx=-1;}
191 dy= y2-y1;
192 if (dy<0) {dy=-dy; sy=-1;}
193// k= -(dx shr 1);
194 k = -(dx / 2);
195 PutPixel(dst, x1,y1, color);
196 while ((x1 != x2) || (y1 != y2)){
197 if ((k >= 0) && (y1 != y2)){
198 y1 =y1+sy;
199 k = k - dx;
200 PutPixel(dst, x1,y1, color);
201 }
202 else {
203 x1 = x1 + sx;
204 k = k+dy;
205 PutPixel(dst, x1,y1, color);
206 }
207 }
208}
209
210#endif