-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGRAPH.CPP
264 lines (209 loc) · 3.37 KB
/
GRAPH.CPP
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <alloc.h>
#include <mem.h>
#include <math.h>
#include <time.h>
#include <string.h>
#define set_vga() { asm { mov ax,13h; int 10h } }
#define set_text() { asm { mov ax,03h; int 10h } }
#define MAX_POINTS 8
//int x,x2,y,col;
int k=1,i;
unsigned char *frame_buffer,palette[768],*background;
int object_translated[320];
void clear_buffer(void)
{
asm {
push es
les di,frame_buffer
db 66h
xor ax,ax
mov cx,16000
cld
db 66h
rep stosw
pop es }
}
void copy_buffer(void)
{
asm {
push ds
push es
lds si,frame_buffer
mov ax,0a000h
mov es,ax
xor di,di
mov cx,16000
cld
db 66h
rep movsw
pop es
pop ds }
}
void retrace(void)
{
while(!(inp(0x03da)&8));
while((inp(0x03da)&8));
}
void set_palette(void)
{
int i;
outp(0x03c8,0);
for(i=0;i<768;i++) outp(0x03c9,palette[i]);
}
void get_palette(void)
{
int i;
outp(0x03c7,0);
for(i=0;i<768;i++) palette[i]=inp(0x03c9);
}
void line(int x1,int x2,int y,
unsigned char color1,unsigned char color2)
{
asm {
mov ax,x1
cmp ax,x2
je quit
jb ok
xchg ax,x2
mov x1,ax
mov al,color1
xchg al,color2
mov color1,al }
ok:
asm {
push es
les di,frame_buffer
mov ax,y
mov bx,ax
shl ax,6
shl bx,8
add ax,bx
add ax,x1
add di,ax
xor ah,ah
mov al,color2
xor bh,bh
mov bl,color1
sub ax,bx
shl ax,7
cwd
mov cx,x2
sub cx,x1
idiv cx
mov dx,ax
xor bh,bh
mov bl,color1
shl bx,7
inc cx
cld }
draw:
asm {
mov ax,bx
shr ax,7
stosb
add bx,dx
dec cx
jnz draw
pop es }
quit:
}
void draw_object_points(int tim,int sz,int sk)
{
int x,y,col;
sz++;
// sk++;
tim=tim+1;
y=((tan(sk)*sin(x))*sz-120);
x=((tan(sk))*cos(x)*sz)+220;
frame_buffer[(y<<6)+(y<<8)+x]=sz;
}
void init_background()
{
asm {
les di,background
mov dx,200 }
ver:
asm {
mov cx,320 }
hor:
asm {
mov ax,cx
or ax,dx
and ax,61
add al,128+64
stosb
dec cx
jnz hor
inc dx
jnz ver
}
}
void recover_background(void)
{
asm {
push ds
push es
les di,frame_buffer
lds si,background
mov cx,16000
cld
db 66h
rep movsw
pop es
pop ds }
}
void set_palette2(void)
{
int i;
outp(0x03c8,128);
for(i=0;i<128;i++)
{
outp(0x03c9,i>>1);
outp(0x03c9,i>>1);
outp(0x03c9,i>>1);
}
}
int main(void){
int color,color2;
clrscr();
if((frame_buffer=(unsigned char *)malloc(64000))==NULL ||
(background=(unsigned char *)malloc(64000))==NULL)
{
free(frame_buffer);
printf(
"%s","Not enough memory!\n\n");
return 1;
}
int x,x2,y,tme,rot;
set_vga();
set_palette2();
init_background();
while (k==1){
// line(1,319,y,color,color2);
x2=x2+1;
if (x2>1000){x2=0;}
// tme++;
// tme++;
x=x+1;
for (i=0;i<x2;i++){
// if (y>199){color++;color2=color+50;y=0;}
// x++;
draw_object_points(y,(rot)/50,y/rot);
if (rot>x){rot=0;}
rot++;
// rot++;
y=y+1;
}
retrace();
copy_buffer();
// recover_background();
clear_buffer();
if (kbhit()){
return 0;
}
}
return 0;
}