www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

demo.c (6439B)


      1 #include <module.h>
      2 #include <types.h>
      3 #include <math.h>
      4 #include <interfaceUtilisateur/demo/demo.h>
      5 #include <interfaceUtilisateur/console/console.h>
      6 #include <pc/vesaGraphique/vesaGraphique.h>
      7 #include <interfaceUtilisateur/police/police.h>
      8 
      9 MODULE(Demo);
     10 
     11 DEPENDANCE_MODULE(Demo, Police);
     12 DEPENDANCE_MODULE(Demo, VesaGraphique);
     13 DEPENDANCE_MODULE(Demo, VgaTexte);
     14 DEPENDANCE_MODULE(Demo, Clavier);
     15 
     16 void demoAffiche(uint32 x1, uint32 y1) {
     17 	uint32 fg1 = 0x00880044;
     18 	uint32 fg2 = 0x00770055;
     19 	uint32 fg3 = 0x00550077;
     20 	uint32 fg4 = 0x00440088;
     21 	uint32 bg  = 0x00ffcccc;
     22 	uint32 ctr = 0x00886666;
     23 	
     24 	policeAfficherCaractereCouleurPosition('L', fg1, bg, x1, y1);
     25 	policeAfficherCaractereCouleurPosition('y', fg2, bg, x1 + 8, y1);
     26 	policeAfficherCaractereCouleurPosition('r', fg3, bg, x1 + 2*8, y1);
     27 	policeAfficherCaractereCouleurPosition('a', fg4, bg, x1 + 3*8, y1);
     28 	
     29 	rectangleContour (x1 - 1, y1 - 2, x1+(4*8) + 2, y1+15 + 1, ctr);
     30 }
     31 
     32 void faireDemo () {
     33 	int32 x1 = 1024/2-8*2;
     34 	int32 y1 = 768/2-15/2;
     35 	
     36 	int32 ac1 = 0x00ff0000;
     37 	int32 ac2 = 0x000000ff;
     38 	int32 dc1 = 50;
     39 	int32 dc2 = 50;
     40 	int32 c = ac1;
     41 	int32 x2 = 0;
     42 	int32 y2 = 768 / 2;
     43 	int32 x3 = x2;
     44 	int32 y3 = y2;
     45 	int32 dx = 3;
     46 	int32 dy = 7;
     47 	int32 ddx = 1;
     48 	int32 ddy = 1;
     49 	
     50 	while (FALSE) {
     51 		demoAffiche(x1, y1);
     52 		asm volatile ("hlt");
     53 		asm volatile ("hlt");
     54 		rectanglePlein (x1 - 1, y1 - 2, x1+(4*8) + 2, y1+15 + 1, 0);
     55 		
     56 		x1 = ((x1 + x1*x1*y1 + y1*3 + 7) % (1024 - 4*8 + 3)) + 1;
     57 		y1 = ((y1 + y1*y1*x1 + x1*3 + 42) % (768 - 15 + 3)) + 2;
     58 		
     59 		dc1 = dc1 + dy / 10;
     60 		dc2 = dc1 + dx / 5;
     61 		c = dc1 * ac1 + dc2 * ac2;
     62 		x3 = x2 + dx;
     63 		y3 = y2 + dy;
     64 		dx += abs(ddx - 3) - 1;
     65 		dy += abs(ddy - 5) - 2;
     66 		ddx = (ddx + 1) % 6;
     67 		ddy = (ddy + 1) % 10;
     68 		
     69 		if (x3 >= 1024) {
     70 			x3 = 1024 - (x3 % 1024);
     71 			dx = -dx;
     72 		}
     73 		if (y3 >= 768) {
     74 			y3 = 768 - (y3 % 768);
     75 			dy = -dy;
     76 		}
     77 
     78 		if (x3 < 0) {
     79 			x3 = abs(x3) % 1024;
     80 			dx = -dx;
     81 		}
     82 		if (y3 < 0) {
     83 			y3 = abs(y3) % 768;
     84 			dy = -dy;
     85 		}
     86 		
     87 		ligne(x2, y2, x3, y3, c);
     88 		
     89 		x2 = x3;
     90 		y2 = y3;
     91 	}
     92 	
     93 	{
     94 		int32 alx1 = 1024/2-8*2;
     95 		int32 aly1 = 768/2-15/2;
     96 		int32 lx1 = alx1;
     97 		int32 ly1 = aly1;
     98 		int32 lx2 = lx1;
     99 		int32 ly2 = ly1;
    100 		
    101 		uint32 i, compteur = 0, compteur2 = 0;
    102 		int32 angle=0;
    103 		int32 dangle=3;
    104 		int32 ddangle=0;
    105 		int32 x1 = 100;
    106 		int32 y1 = 768/2;
    107 		int32 x2 = x1;
    108 		int32 y2 = y1;
    109 		int32 ax = lx2; // 1024-100;
    110 		int32 ay = ly2; // 768/2;
    111 		int32 v = 15;
    112 		int32 dx, dy, adx1, ady1, adx2, ady2;
    113 		int32 cx1 = 9;
    114 		int32 cy1 = 9;
    115 		int32 colmod;
    116 		
    117 		
    118 		
    119 		int32 noiralx1 = 1024/2-8*2;
    120 		int32 noiraly1 = 768/2-15/2;
    121 		int32 noirlx1 = noiralx1;
    122 		int32 noirly1 = noiraly1;
    123 		int32 noirlx2 = noirlx1;
    124 		int32 noirly2 = noirly1;
    125 		
    126 		uint32 noiri, noircompteur = 0, noirprecompteur = 0, noircompteur2 = 0;
    127 		int32 noirangle=0;
    128 		int32 noirdangle=3;
    129 		int32 noirddangle=0;
    130 		int32 noirx1 = 100;
    131 		int32 noiry1 = 768/2;
    132 		int32 noirx2 = noirx1;
    133 		int32 noiry2 = noiry1;
    134 		int32 noirax = noirlx2; // 1024-100;
    135 		int32 noiray = noirly2; // 768/2;
    136 		int32 noirv = 15;
    137 		int32 noirdx, noirdy, noiradx1, noirady1, noiradx2, noirady2;
    138 		int32 noircx1 = 9;
    139 		int32 noircy1 = 9;
    140 		
    141 		while (TRUE) {
    142 			// demoAffiche(lx2, ly2);
    143 			compteur2++;
    144 			compteur = compteur2 / 4;
    145 			
    146 			// if (compteur2 % 4 == 0)
    147 			// 	asm volatile ("hlt");
    148 			// else
    149 				{ int t; for (t = 0; t < 1000000; t++) asm volatile ("nop"); }
    150 			
    151 			// lx2 += sign(alx1-lx2);
    152 			// ly2 += sign(aly1-ly2);
    153 			lx2 = alx1;
    154 			ly2 = aly1;
    155 			
    156 			rectanglePlein (lx1 - 1, ly1 - 2, lx1+(4*8) + 2, ly1+15 + 1, 0);
    157 			demoAffiche(lx2, ly2);
    158 			
    159 			lx1 = lx2;
    160 			ly1 = ly2;
    161 			
    162 			alx1 = (1024 - 96)/2 + 32 + (1024 - 64) * sinRapide(compteur2 * (2<<7)  ) / (2<<15);
    163 			aly1 = (768 - 80)/2  + 32 + (768 - 48)  * cosRapide(compteur2 * (2<<4)*3) / (2<<15);
    164 			
    165 			
    166 			for (i = 0; i < 2000; i += dx*dx + dy*dy) {
    167 				ax = alx1;
    168 				ay = aly1;
    169 				
    170 				adx1 = v * cosRapide(angle) / (2<<15);
    171 				ady1 = v * sinRapide(angle) / (2<<15);
    172 				
    173 				adx2 = (ax-x2) / 100;
    174 				ady2 = (ay-y2) / 100;
    175 				
    176 				dx = (cx1*adx1 + (10-cx1)*adx2) / 10;
    177 				dy = (cy1*ady1 + (10-cy1)*ady2) / 10;
    178 				
    179 				x2 += dx;
    180 				y2 += dy;
    181 
    182 				dangle += abs(ddangle - 4) - 2;
    183 				// dangle++;
    184 				angle += dangle*16;
    185 				
    186 				colmod = 0xcc / 2 + (0xcc * sinRapide(compteur * (2<<4)*15) / (2<<15));
    187 				if ((x1 > 0) && (x1 < 1024) &&
    188 				    (x2 > 0) && (x2 < 1024) &&
    189 				    (y1 > 0) && (y1 < 768) &&
    190 				    (y2 > 0) && (y2 < 768))
    191 				ligne(x1,y1,x2,y2,0x00ff0000 | (colmod << 8) | colmod);
    192 				
    193 				x1 = x2;
    194 				y1 = y2;
    195 			}
    196 			if (compteur2 % 4 == 0)
    197 				ddangle = (ddangle + 1) % 8;
    198 			
    199 			
    200 			
    201 			
    202 			
    203 			if (noirprecompteur <= 15) {
    204 				noirprecompteur++;
    205 			} else {
    206 			
    207 			noircompteur2++;
    208 			noircompteur = noircompteur2 / 4;
    209 			
    210 			// noirlx2 += sign(noiralx1-noirlx2);
    211 			// noirly2 += sign(noiraly1-noirly2);
    212 			noirlx2 = noiralx1;
    213 			noirly2 = noiraly1;
    214 			
    215 			//// rectanglePlein (noirlx1 - 1, noirly1 - 2, noirlx1+(4*8) + 2, noirly1+15 + 1, 0);
    216 			//// demoAffiche(noirlx2, noirly2);
    217 			
    218 			noirlx1 = noirlx2;
    219 			noirly1 = noirly2;
    220 			
    221 			noiralx1 = (1024 - 96)/2 + 32 + (1024 - 64) * sinRapide(noircompteur2 * (2<<7)  ) / (2<<15);
    222 			noiraly1 = (768 - 80)/2  + 32 + (768 - 48)  * cosRapide(noircompteur2 * (2<<4)*3) / (2<<15);
    223 			
    224 			
    225 			for (noiri = 0; noiri < 2000; noiri += noirdx*noirdx + noirdy*noirdy) {
    226 				noirax = noiralx1;
    227 				noiray = noiraly1;
    228 				
    229 				noiradx1 = noirv * cosRapide(noirangle) / (2<<15);
    230 				noirady1 = noirv * sinRapide(noirangle) / (2<<15);
    231 				
    232 				noiradx2 = (noirax-noirx2) / 100;
    233 				noirady2 = (noiray-noiry2) / 100;
    234 				
    235 				noirdx = (noircx1*noiradx1 + (10-noircx1)*noiradx2) / 10;
    236 				noirdy = (noircy1*noirady1 + (10-noircy1)*noirady2) / 10;
    237 				
    238 				noirx2 += noirdx;
    239 				noiry2 += noirdy;
    240 
    241 				noirdangle += abs(noirddangle - 4) - 2;
    242 				// dangle++;
    243 				noirangle += noirdangle*16;
    244 				
    245 				if ((noirx1 > 0) && (noirx1 < 1024) &&
    246 				    (noirx2 > 0) && (noirx2 < 1024) &&
    247 				    (noiry1 > 0) && (noiry1 < 768) &&
    248 				    (noiry2 > 0) && (noiry2 < 768))
    249 				ligne(noirx1,noiry1,noirx2,noiry2,0);
    250 				
    251 				noirx1 = noirx2;
    252 				noiry1 = noiry2;
    253 			}
    254 			if (noircompteur2 % 4 == 0)
    255 				noirddangle = (noirddangle + 1) % 8;
    256 			
    257 			} // if noirprecompteur <= 10
    258 		}
    259 	}
    260 }
    261 
    262 void demoNombres() {
    263 	int i;
    264 	for (i = 0; i <= 10; i++) {
    265 		afficherEntierEnDecimal(i);
    266 		afficherChaineZ(" ");
    267 	}
    268 	afficherChaineZ("\n");
    269 }
    270 
    271 
    272 void initDemo(void** etat) {
    273 	*etat = NULL;
    274 }
    275 
    276 void deinitDemo(void** etat) {
    277 	*etat = NULL;
    278 }