-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecgrap.c
executable file
·690 lines (690 loc) · 14.4 KB
/
execgrap.c
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
#include <DOS.H>
#include <STDIO.H>
#include <STDLIB.H>
#include <STRING.H>
#include "SOUREXEC/EXECGRAP.H"
#define NB_BOB 43
void CopyBuf2Plane (OCTET*,OCTET,short,short,OCTET,OCTET,OCTET);
void CopyPlane2Buf (OCTET*,OCTET,short,short,OCTET,OCTET);
OCTET page_active;
struct bob_infos
{
OCTET presence;
OCTET *pointeurbitplan [4];
OCTET nombrepoint [4];
OCTET largeur;
OCTET nombreligne;
};
struct bob_infos bob [NB_BOB];
OCTET Lire_Page (void)
{
return (page_active);
}
void Activer_Ecran (void)
{
asm
{
mov ax,0x0013;
int 0x10;
mov dx,0x3CE;
mov al,5;
out dx,al;
inc dx;
in al,dx;
and al,239;
out dx,al;
dec dx;
mov al,6;
out dx,al;
inc dx;
in al,dx;
and al,253;
out dx,al;
mov dx,0x3C4;
mov al,4;
out dx,al;
inc dx;
in al,dx;
and al,247;
or al,4;
out dx,al;
mov ax,0xA000;
mov es,ax;
xor di,di;
mov ax,di;
mov cx,0x8000;
rep stosw;
mov dx,0x3D4;
mov al,9;
out dx,al;
inc dx;
in al,dx;
and al,112;
out dx,al;
dec dx;
mov al,0x14;
out dx,al;
inc dx;
in al,dx;
and al,191;
out dx,al;
dec dx;
mov al,0x17;
out dx,al;
inc dx;
in al,dx;
or al,64;
out dx,al;
}
}
void Desactiver_Ecran (void)
{
union REGS regs;
regs.x.ax = 0x0003;
int86(0x10,®s,®s);
}
void Afficher_Point (OCTET page,short xpoint,short ypoint,OCTET coul)
{
short adrpage;
asm
{
push es;
push di;
mov adrpage,0xA000;
mov al,page;
mov bl,0x0A0;
or al,al;
je sauter_page;
mov bl,0x0A8;
}
sauter_page:
asm
{
mov byte ptr adrpage + 1,bl;
mov ax,80;
mul ypoint;
mov cx,xpoint;
mov bx,cx;
shr bx,1;
shr bx,1;
add ax,bx;
mov di,ax;
and cl,3;
mov ah,1;
shl ah,cl;
mov al,2;
mov dx,0x03C4;
out dx,ax;
mov ax,adrpage;
mov es,ax;
mov al,coul;
stosb;
pop di;
pop es;
}
}
OCTET Lire_Point (OCTET page,short xpoint,short ypoint)
{
OCTET couleur_retour;
short adrpage;
asm
{
push es;
push di;
push ds;
push si;
mov adrpage,0xA000;
mov al,page;
mov bl,0x0A0;
or al,al;
je sauter_page;
mov bl,0x0A8;
}
sauter_page:
asm
{
mov byte ptr adrpage + 1,bl;
mov ax,80;
mul ypoint;
mov si,xpoint;
mov cx,si;
shr si,1;
shr si,1;
add si,ax;
and cl,3;
mov ah,cl;
mov al,4;
mov dx,0x03CE;
out dx,ax;
mov ax,adrpage;
mov es,ax;
mov al,es:[si];
mov couleur_retour,al;
pop si;
pop ds;
pop di;
pop es;
}
return (couleur_retour);
}
void Afficher_Page (OCTET page)
{
page_active = page;
asm
{
mov al,page;
or al,al;
je sauter_page;
mov al,0x80;
}
sauter_page:
asm
{
mov dx,0x3D4;
mov ah,al;
mov al,0x0C;
out dx,ax;
mov dx,0x3DA;
}
boucle_balayage:
asm
{
in al,dx;
test al,8;
jne boucle_balayage;
}
boucle_faisceau:
asm
{
in al,dx;
test al,8;
je boucle_faisceau;
}
}
void Tracer_Droite (OCTET page,short x,short y,short x2,short y2,OCTET c)
{
int i, steep = 0, sx, sy, dx, dy, e;
dx = abs(x2 - x);
sx = ((x2 - x) > 0) ? 1 : -1;
dy = abs(y2 - y);
sy = ((y2 - y) > 0) ? 1 : -1;
if(dy > dx)
{
steep = 1;
x ^= y;
y ^= x;
x ^= y;
dx ^= dy;
dy ^= dx;
dx ^= dy;
sx ^= sy;
sy ^= sx;
sx ^= sy;
}
e = 2 * dy - dx;
for(i = 0; i < dx; i++)
{
if(steep)
Afficher_Point (page,y,x,c);
else Afficher_Point (page,x,y,c);
while(e >= 0)
{
y += sy;
e -= 2 * dx;
}
x += sx;
e += 2 * dy;
}
Afficher_Point (page,x2,y2,c);
}
void Tracer_Carre_Plein (OCTET page,short x,short y,short x2,short y2,OCTET c)
{
short hauteur;
for (hauteur = y;
hauteur <= y2;
hauteur ++)
Tracer_Droite (page,x,hauteur,x2,hauteur,c);
}
void Tracer_Rectangle (OCTET page,short x,short y,short x2,short y2,OCTET c)
{
Tracer_Droite (page,x,y,x2,y,c);
Tracer_Droite (page,x,y2,x2,y2,c);
Tracer_Droite (page,x,y,x,y2,c);
Tracer_Droite (page,x2,y,x2,y2,c);
}
void Cls (OCTET page,OCTET bloc)
{
char cpty,cptx;
for (cpty = 0;
cpty < 40;
cpty ++)
{
for (cptx = 0;
cptx < 32;
cptx ++)
Afficher_Bob (page,bloc,cptx * 10,cpty * 10,MASK_OFF);
}
}
BOOL Lire_Image_Pcx (char *nomfichier,
OCTET np,
short xec,short yec,
OCTET masq,
short xfichiermin,short yfichiermin,
short xfichiermax,short yfichiermax)
{
FILE *flux;
char extension;
char bufnomfic [13];
OCTET sortie;
OCTET octet;
short j;
short coul;
short compteur;
short xecran = 0;
short yecran = 0;
short xfichier = 0;
short yfichier = 0;
short largeurfichier;
short hauteurfichier;
short largeurfenetre;
short hauteurfenetre;
strcpy (bufnomfic,nomfichier);
strcat (bufnomfic,".PCX");
flux = fopen (bufnomfic,"rb");
if (flux == NULL)
{
strcpy (bufnomfic,nomfichier);
strcat (bufnomfic,".SPR");
flux = fopen (bufnomfic,"rb");
if (flux == NULL)
return (FAUX);
else
extension = SPR;
}
else
extension = PCX;
sortie = FAUX;
largeurfichier = LIMITE_X_ECRAN-1;
hauteurfichier = LIMITE_Y_ECRAN-1;
largeurfenetre = xfichiermax;
hauteurfenetre = yfichiermax;
xfichiermax += xfichiermin;
yfichiermax += yfichiermin;
if (extension == PCX)
fseek(flux,128,SEEK_SET);
do
{
octet = getc(flux);
if (octet>191)
{
compteur = octet-192;
octet = getc(flux);
coul = octet;
}
else
{
coul = octet;
compteur = 1;
}
for (j=0; j<compteur; j++)
{
if ( (xfichier>=xfichiermin) & (xfichier<=xfichiermax) )
if ( (yfichier>=yfichiermin) & (yfichier<=yfichiermax) )
{
if (xecran+xec<LIMITE_X_ECRAN)
if (yecran+yec<LIMITE_Y_ECRAN)
if (!( (coul == 255) & (masq == MASK_ON) ))
Afficher_Point(np,xecran+xec,yecran+yec,coul);
if (xecran>=largeurfenetre)
{
xecran=-1;
yecran++;
}
if (yecran>hauteurfenetre )
{
sortie=VRAI;
break;
}
xecran++;
}
if (xfichier>=largeurfichier)
{
xfichier=-1;
yfichier++;
}
if (yfichier>hauteurfichier )
{
sortie=VRAI;
break;
}
xfichier++;
}
}
while (sortie!=VRAI);
fclose (flux);
return (VRAI);
}
void Lire_Palette (char *nomfichier)
{
FILE *flux;
union REGS reg;
struct SREGS regs;
OCTET pal[256][3];
flux = fopen (nomfichier,"rb");
if (flux == NULL)
return;
fread (&pal[0][0],sizeof(pal),1,flux);
fclose (flux);
reg.x.ax = 0x1012;
regs.es = FP_SEG(pal);
reg.x.dx = FP_OFF(pal);
reg.x.bx = 0x0;
reg.x.cx = 256;
int86x(0x10, ®, ®, ®s);
}
void CopyBuf2Plane (OCTET *bufptr,OCTET verspage,short versx,short versy,
OCTET largeur,OCTET hauteur, OCTET bg)
{
unsigned long buffer;
buffer = (long)(bufptr);
asm
{
push es;
push di;
push ds;
push si;
mov ah,0xA0;
cmp verspage,0;
je cv0;
mov ah,0xA8;
}
cv0:
asm
{
xor al,al;
mov es,ax;
mov ax,80;
mul versy;
mov di,versx;
mov cx,di;
shr di,1;
shr di,1;
add di,ax;
mov ah,1;
and cl,3;
shl ah,cl;
mov dx,0x03c4;
mov al,0x02;
out dx,ax;
mov dh,hauteur;
mov dl,largeur;
mov bx,80;
sub bl,dl;
xor ch,ch;
lds si,buffer;
cmp bg,0;
jne cv2;
}
cv1:
asm
{
mov cl,dl;
rep movsb;
add di,bx;
dec dh;
jne cv1;
jmp cvend;
}
cv2:
asm
{
mov cl,dl;
}
cv3:
asm
{
lodsb;
cmp al,255;
je cv5;
stosb;
loop cv3;
}
cv4:
asm
{
add di,bx;
dec dh;
jne cv2;
jmp cvend;
}
cv5:
asm
{
inc di;
loop cv3;
jmp cv4;
}
cvend:
asm
{
pop si;
pop ds;
pop di;
pop es;
}
}
void CopyPlane2Buf (OCTET *bufptr,OCTET depage,short dex,short dey,
OCTET largeur,OCTET hauteur)
{
unsigned long buffer;
buffer = (long)(bufptr);
asm
{
push es;
push di;
push ds;
push si;
mov ah,0xA0;
cmp depage,0;
je cc0;
mov ah,0xA8;
}
cc0:
asm
{
xor al,al;
mov ds,ax;
mov ax,80;
mul dey;
mov si,dex;
mov cx,si;
shr si,1;
shr si,1;
add si,ax;
and cl,3;
mov ah,cl;
mov al,0x04;
mov dx,0x03ce;
out dx,ax;
mov dh,hauteur;
mov dl,largeur;
mov bx,80;
sub bl,dl;
xor ch,ch;
les di,buffer;
}
cc1:
asm
{
mov cl,dl;
rep movsb;
add si,bx;
dec dh;
jne cc1;
pop si;
pop ds;
pop di;
pop es;
}
}
BOOL Creer_Bob (short num_bob,short largeur,short hauteur)
{
short taille_bob;
OCTET *buffer;
if (bob[num_bob].presence != 1)
{
taille_bob = largeur * hauteur;
buffer = malloc (taille_bob);
if (buffer == NULL)
return (FAUX);
bob[num_bob].presence = 1;
bob[num_bob].pointeurbitplan[0] = buffer;
bob[num_bob].largeur = largeur;
bob[num_bob].nombreligne = hauteur;
}
else
return (FAUX);
return (VRAI);
}
BOOL Lire_Bob (short num_bob,OCTET page,short x,short y)
{
OCTET cpt_bitplan;
OCTET plancour;
OCTET sb;
OCTET eb;
OCTET b;
OCTET am;
OCTET largeur;
OCTET hauteur;
OCTET *buffer;
if (bob[num_bob].presence == 1)
{
buffer = bob[num_bob].pointeurbitplan[0];
largeur = bob[num_bob].largeur;
hauteur = bob[num_bob].nombreligne;
am = (OCTET)(((x+largeur-1)&~3)-((x+4)&~3)) >>2;
sb = (OCTET)(x%4);
eb = (OCTET)((x+largeur-1)%4);
for (cpt_bitplan = 0;
cpt_bitplan < 4;
cpt_bitplan ++)
{
plancour = (sb+cpt_bitplan) % 4;
b = am;
if (plancour >= sb) ++b;
if (plancour <= eb) ++b;
bob[num_bob].pointeurbitplan[cpt_bitplan] = buffer;
bob[num_bob].nombrepoint [cpt_bitplan] = b;
CopyPlane2Buf (buffer,
page,
x+cpt_bitplan,
y,
b,
hauteur);
buffer += b * hauteur;
}
}
else
return (FAUX);
return (VRAI);
}
BOOL Afficher_Bob (OCTET page,short num_bob,short x1,short y1,OCTET masq)
{
OCTET cpt_plan;
if (bob[num_bob].presence == 1)
{
for (cpt_plan = 0;
cpt_plan < 4;
cpt_plan ++)
CopyBuf2Plane (bob[num_bob].pointeurbitplan[cpt_plan],
page,
x1 + cpt_plan,
y1,
bob[num_bob].nombrepoint [cpt_plan],
bob[num_bob].nombreligne,
masq);
}
else
return (FAUX);
return (VRAI);
}
BOOL Detruire_Bob (short num_bob)
{
OCTET *buffer;
if (bob[num_bob].presence == 1)
{
buffer = bob[num_bob].pointeurbitplan[0];
free (buffer);
bob[num_bob].presence = 0;
}
else
return (FAUX);
return (VRAI);
}
void Afficher_Nombre (OCTET pg,OCTET nm,OCTET nu,ULONG nb,short x,short y,
OCTET ms)
{
short largeur;
char buffer[6];
char cptnb;
char unite;
for (cptnb = 0;
cptnb < nu;
cptnb ++)
{
unite = nb - ( (nb/10)*10 );
buffer [cptnb] = unite;
nb /= 10;
}
for (cptnb = nu-1;
cptnb >= 0;
cptnb --)
{
Afficher_Bob (pg,nm + buffer [cptnb],x,y,ms);
largeur = bob[nm+unite].largeur;
x += largeur;
}
}
void Definir_Bobs (void)
{
short cpt;
Creer_Bob (0,10,10);
Creer_Bob (1,7,11);
Creer_Bob (2,7,11);
Creer_Bob (3,7,11);
Creer_Bob (4,7,11);
Creer_Bob (5,7,11);
Creer_Bob (6,7,11);
for (cpt = 0;
cpt <= 35;
cpt ++)
Creer_Bob (7 + cpt,7,11);
Afficher_Page (PAGE0);
Lire_Image_Pcx ("SPRFILES/DATA",PAGE1,0,0,MASK_OFF,0,0,319,399);
Lire_Bob (0,PAGE1,117,16);
Lire_Bob (1,PAGE1,117,16);
Lire_Bob (2,PAGE1,79,96);
Lire_Bob (3,PAGE1,44,96);
Lire_Bob (4,PAGE1,37,96);
Lire_Bob (5,PAGE1,2,96);
Lire_Bob (6,PAGE1,51,96);
for (cpt = 0;
cpt <= 35;
cpt ++)
Lire_Bob (7 + cpt,PAGE1,16 + (cpt * 7),2);
}
void Supprimer_Bobs (void)
{
short cpt;
Detruire_Bob (0);
Detruire_Bob (1);
Detruire_Bob (2);
Detruire_Bob (3);
Detruire_Bob (4);
Detruire_Bob (5);
Detruire_Bob (6);
for (cpt = 0;
cpt <= 35;
cpt ++)
Detruire_Bob (7 + cpt);
}