/[projet1]/public/oric/routines/rasterization/polybench/Main.c
Defence Force logotype

Contents of /public/oric/routines/rasterization/polybench/Main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1246 - (show annotations)
Sat Dec 13 15:59:17 2014 UTC (5 years, 3 months ago) by dbug
File MIME type: text/plain
File size: 5128 byte(s)
Used the direction test to compute the width        | 76.9%|2977 2577 2708 2706 2856 2878 2806
1 #include "lib.h"
2
3 // --------------------------------------
4 // PolyBench
5 // --------------------------------------
6 // (c) 2003-2014 Mickael Pointier.
7 // This code is provided as-is.
8 // I do not assume any responsability
9 // concerning the fact this is a bug-free
10 // software !!!
11 // Except that, you can use this example
12 // without any limitation !
13 // If you manage to do something with that
14 // please, contact me :)
15 // --------------------------------------
16 // --------------------------------------
17 // For more information, please contact me
18 // on internet:
19 // e-mail: mike@defence-force.org
20 // URL: http://www.defence-force.org
21 // --------------------------------------
22 // Note: This text was typed with a Win32
23 // editor. So perhaps the text will not be
24 // displayed correctly with other OS.
25
26 // Bench Results:
27 // Date |Comment Size | Ratio|Performance
28 // 2008-04-19|PolyBench1: |100.0%|3871 3407 3546 <- PolyBench 1
29 // 2008-04-19|Moving X0,Y0,X1,Y1 to zero page: | 99.5%|3852 3389 3527 3557 3693 3747 3639
30 // 2008-04-19|Moving FlagFirst, OddEvenFlag to zero page: | 99.3%|3844 3382 3519 3550 3684 3739 3630
31 // 2008-04-20|Optimized the clearing of scanlines: | 83.4%|3230 2769 2906 2937 3071 3127 3017 <- PolyBench 2
32 // 2008-04-20|Cleaned the C part, removing useless things: | 83.3%|3228 2767 2904 2936 3069 3125 3015
33 // 2008-04-20|Fixed some 16 bits adds using bcc 7502| 82.4%|3193 2738 2871 2906 3034 3092 2980
34 // 2008-04-20|Used a unrolled drawing loop plus jump table | 81.6%|3160 2729 2873 2867 3032 3051 2974
35 // 2008-04-21|Used a 8 bit offset table and self modified jmp 7758| 80.8%|3131 2706 2848 2841 3004 3024 2949
36 // 2008-04-21|Improved the main loop - odd/even test is faster | 80.0%|3100 2681
37 // 2008-04-21|Change ddetection code for single/multiple byte | 79.9%|3095 2678 2814
38 // 2008-04-21|Inner loop fits in the BCC jump range :D | 79.5%|3079 2665 2801 2798 2953
39 // 2008-04-21|Removed useless register reloading | 79.2%|3067 2655 2789 2788 2941 2965 2885
40 // 2008-04-21|Replaced LDA $xxxx,y/TAX by LDX $xxxx,y | 78.7%|3050 2641 2775 2775 2925 2950 2868
41 // 2008-04-21|Improved pattern management | 78.7%|3049 2640 2774 2774 2924 2949 2868 <- PolyBench 3
42 // 2014-12-13|Testing again... after 6 years :) | 78.7%|3048 2638 2771 2771 2921 2947 2866
43 // 2014-12-13|Avoided some pointless clc and sec | 78.4%|3038 2631 2762 2763 2910 2939 2858
44 // 2014-12-13|Used DX as an unsigned 8bit value | 78.3%|3031 2623 2754 2758 2902 2928 2846
45 // 2014-12-13|Used the direction test to compute the width | 76.9%|2977 2577 2708 2706 2856 2878 2806
46
47
48 // ---- Externs
49 extern unsigned char RandomValue;
50 extern void GetRand();
51 extern void _InitTables();
52
53 extern unsigned char X0;
54 extern unsigned char Y0;
55 extern unsigned char X1;
56 extern unsigned char Y1;
57
58 extern void AddLineASM();
59 extern void FillTablesASM();
60 extern void ClearAndSwapFlag();
61 extern void ComputeDivMod();
62
63
64
65 #define RAND_MAX 255
66 #define NB_TRI 3
67 #define SPEED 4
68
69
70 unsigned char x[3*NB_TRI];
71 unsigned char y[3*NB_TRI];
72 char ix[3*NB_TRI];
73 char iy[3*NB_TRI];
74
75 unsigned int CurrentPattern=0;
76
77
78
79
80 int random(unsigned int value)
81 {
82 GetRand();
83 return RandomValue&3;
84 }
85
86
87 void AddTriangle(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1,unsigned char x2,unsigned char y2,unsigned char pattern)
88 {
89 X0=x0;
90 Y0=y0;
91 X1=x1;
92 Y1=y1;
93 AddLineASM();
94 X0=x0;
95 Y0=y0;
96 X1=x2;
97 Y1=y2;
98 AddLineASM();
99 X0=x2;
100 Y0=y2;
101 X1=x1;
102 Y1=y1;
103 AddLineASM();
104
105 CurrentPattern=pattern<<3;
106 FillTablesASM();
107 }
108
109
110 void main()
111 {
112 int delay;
113 unsigned char pattern;
114 unsigned char i,j;
115
116 char flag=1;
117
118 paper(1);
119 ink(4);
120 hires();
121 paper(4);
122 ink(3);
123
124 printf("PolyBench\n");
125
126 ComputeDivMod();
127 InitTables();
128
129
130 //
131 // Initialise triangles
132 //
133 j=0;
134 for (i=0;i<NB_TRI;i++)
135 {
136 x[0+j]=120;
137 y[0+j]=80;
138 x[1+j]=80;
139 y[1+j]=140;
140 x[2+j]=200;
141 y[2+j]=120;
142
143 ix[0+j]=2;
144 iy[0+j]=1;
145 ix[1+j]=-1;
146 iy[1+j]=+3;
147 ix[2+j]=+1;
148 iy[2+j]=-2;
149
150 j+=3;
151 }
152
153
154 //
155 // Move the triangles around the screen
156 //
157 while (1)
158 {
159 *(unsigned int*)0x276=0;
160
161 delay=200;
162
163 while (delay--)
164 {
165 ClearAndSwapFlag();
166
167 j=0;
168 for (i=0;i<NB_TRI;i++)
169 {
170 AddTriangle(x[0+j],y[0+j],x[1+j],y[1+j],x[2+j],y[2+j],(i&3));
171 j+=3;
172 }
173
174 for (i=0;i<3*NB_TRI;i++)
175 {
176 x[i]+=ix[i];
177 y[i]+=iy[i];
178 if (x[i]>220) ix[i]=-random(SPEED);
179 if (x[i]<20) ix[i]=random(SPEED);
180 if (y[i]>195) iy[i]=-random(SPEED);
181 if (y[i]<4) iy[i]=random(SPEED);
182 }
183 }
184
185 delay=65536-(*(unsigned int*)0x276);
186 printf(" %d",delay);
187
188 }
189 }
190
191
192

  ViewVC Help
Powered by ViewVC 1.1.26