Found and fixed long-standing random freeze issue. Sleep mode is not committed any...
[AROS.git] / test / writepixelarray.c
blob418b7242654b91a7119666b8460fdf95c63cd7c5
2 #include <dos/dos.h>
3 #include <intuition/intuition.h>
4 #include <graphics/gfx.h>
5 #include <cybergraphx/cybergraphics.h>
6 #include <proto/exec.h>
7 #include <proto/dos.h>
8 #include <proto/graphics.h>
9 #include <proto/cybergraphics.h>
10 #include <proto/intuition.h>
12 #include <math.h>
13 #include <stdio.h>
14 #include <stdlib.h>
16 #define SCREENWIDTH 300
17 #define SCREENHEIGHT 200
18 #define SCREENCY (SCREENHEIGHT / 2)
20 /***********************************************************************************/
22 struct IntuitionBase *IntuitionBase;
23 struct GfxBase *GfxBase;
24 struct Library *CyberGfxBase;
25 struct Screen *scr;
26 struct Window *win;
27 struct RastPort *rp;
29 ULONG cgfx_coltab[256];
30 UBYTE Keys[128];
32 /***********************************************************************************/
34 static void cleanup(char *msg)
36 if (msg)
38 printf("WritePixelArray: %s\n",msg);
41 if (win) CloseWindow(win);
43 if (scr) UnlockPubScreen(0, scr);
45 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
46 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
47 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
49 exit(0);
52 /***********************************************************************************/
54 static void openlibs(void)
56 if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)))
58 cleanup("Can't open intuition.library V39!");
61 if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)))
63 cleanup("Can't open graphics.library V39!");
66 if (!(CyberGfxBase = OpenLibrary("cybergraphics.library",0)))
68 cleanup("Can't open cybergraphics.library!");
72 /***********************************************************************************/
74 static void getvisual(void)
76 if (!(scr = LockPubScreen(NULL)))
78 cleanup("Can't lock pub screen!");
81 if (GetBitMapAttr(scr->RastPort.BitMap, BMA_DEPTH) <= 8)
83 cleanup("Need hi or true color screen!");
87 /***********************************************************************************/
89 static void makewin(void)
91 win = OpenWindowTags(NULL, WA_CustomScreen , (IPTR)scr,
92 WA_InnerWidth , SCREENWIDTH,
93 WA_InnerHeight , SCREENHEIGHT,
94 WA_Title , (IPTR)"WritePixelArray: Move mouse!",
95 WA_DragBar , TRUE,
96 WA_DepthGadget , TRUE,
97 WA_CloseGadget , TRUE,
98 WA_Activate , TRUE,
99 WA_IDCMP , IDCMP_CLOSEWINDOW |
100 IDCMP_RAWKEY,
101 TAG_DONE);
103 if (!win) cleanup("Can't open window");
105 rp = win->RPort;
108 /***********************************************************************************/
110 #define KC_LEFT 0x4F
111 #define KC_RIGHT 0x4E
112 #define KC_UP 0x4C
113 #define KC_DOWN 0x4D
114 #define KC_ESC 0x45
116 /***********************************************************************************/
118 static void getevents(void)
120 struct IntuiMessage *msg;
122 while ((msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
124 switch(msg->Class)
126 case IDCMP_CLOSEWINDOW:
127 Keys[KC_ESC] = 1;
128 break;
130 case IDCMP_RAWKEY:
132 WORD code = msg->Code & ~IECODE_UP_PREFIX;
134 Keys[code] = (code == msg->Code) ? 1 : 0;
137 break;
140 ReplyMsg((struct Message *)msg);
145 /***********************************************************************************/
147 static void action(void)
149 static LONG tab[SCREENWIDTH * SCREENHEIGHT];
150 LONG x, y;
151 LONG ar1, ar2, ar3, ar4;
152 LONG ag1, ag2, ag3, ag4;
153 LONG ab1, ab2, ab3, ab4;
154 LONG r1, r2, r3, r4;
155 LONG g1, g2, g3, g4;
156 LONG b1, b2, b3, b4;
157 LONG tr1, tg1, tb1;
158 LONG tr2, tg2, tb2;
159 LONG tr3, tg3, tb3;
160 LONG tr4, tg4, tb4;
161 LONG ttr1, ttg1, ttb1;
162 LONG ttr2, ttg2, ttb2;
163 LONG tttr, tttg, tttb;
165 LONG col;
167 ar1 = 0xFF; ag1 = 0xFF; ab1 = 0xFF;
168 ar2 = 0xFF; ag2 = 0x00; ab2 = 0x00;
169 ar3 = 0x00; ag3 = 0xFF; ab3 = 0x00;
170 ar4 = 0x00; ag4 = 0x00; ab4 = 0xFF;
172 r1 = 0xFF; g1 = 0xFF; b1 = 0xFF;
173 r2 = 0xFF; g2 = 0x00; b2 = 0x00;
174 r3 = 0x00; g3 = 0xFF; b3 = 0x00;
175 r4 = 0x00; g4 = 0x00; b4 = 0xFF;
177 while(!Keys[KC_ESC])
179 x = scr->MouseX;
180 if (x < 0) x = 0; else if (x >= scr->Width) x = scr->Width - 1;
182 r1 = ar1 + (ar2 - ar1) * x / (scr->Width - 1);
183 g1 = ag1 + (ag2 - ag1) * x / (scr->Width - 1);
184 b1 = ab1 + (ab2 - ab1) * x / (scr->Width - 1);
186 r2 = ar2 + (ar3 - ar2) * x / (scr->Width - 1);
187 g2 = ag2 + (ag3 - ag2) * x / (scr->Width - 1);
188 b2 = ab2 + (ab3 - ab2) * x / (scr->Width - 1);
190 r3 = ar3 + (ar4 - ar3) * x / (scr->Width - 1);
191 g3 = ag3 + (ag4 - ag3) * x / (scr->Width - 1);
192 b3 = ab3 + (ab4 - ab3) * x / (scr->Width - 1);
194 r4 = ar4 + (ar1 - ar4) * x / (scr->Width - 1);
195 g4 = ag4 + (ag1 - ag4) * x / (scr->Width - 1);
196 b4 = ab4 + (ab1 - ab4) * x / (scr->Width - 1);
199 for(y = 0; y < SCREENHEIGHT; y ++)
201 for(x = 0; x < SCREENWIDTH; x++)
203 tr1 = r1 + (r2 - r1) * x / (SCREENWIDTH - 1);
204 tg1 = g1 + (g2 - g1) * x / (SCREENWIDTH - 1);
205 tb1 = b1 + (b2 - b1) * x / (SCREENWIDTH - 1);
207 tr2 = r3 + (r4 - r3) * x / (SCREENWIDTH - 1);
208 tg2 = g3 + (g4 - g3) * x / (SCREENWIDTH - 1);
209 tb2 = b3 + (b4 - b3) * x / (SCREENWIDTH - 1);
211 tr3 = r1 + (r3 - r1) * y / (SCREENHEIGHT - 1);
212 tg3 = g1 + (g3 - g1) * y / (SCREENHEIGHT - 1);
213 tb3 = b1 + (b3 - b1) * y / (SCREENHEIGHT - 1);
215 tr4 = r2 + (r4 - r2) * y / (SCREENHEIGHT - 1);
216 tg4 = g2 + (g4 - g2) * y / (SCREENHEIGHT - 1);
217 tb4 = b2 + (b4 - b2) * y / (SCREENHEIGHT - 1);
219 ttr1 = tr1 + (tr2 - tr1) * y / (SCREENHEIGHT - 1);
220 ttg1 = tg1 + (tg2 - tg1) * y / (SCREENHEIGHT - 1);
221 ttb1 = tb1 + (tb2 - tb1) * y / (SCREENHEIGHT - 1);
223 ttr2 = tr3 + (tr4 - tr3) * x / (SCREENWIDTH - 1);
224 ttg2 = tg3 + (tg4 - tg3) * x / (SCREENWIDTH - 1);
225 ttb2 = tb3 + (tb4 - tb3) * x / (SCREENWIDTH - 1);
227 tttr = (ttr1 + ttr2) / 2;
228 tttg = (ttg1 + ttg2) / 2;
229 tttb = (ttb1 + ttb2) / 2;
231 #if AROS_BIG_ENDIAN
232 col = (tttr << 16) + (tttg << 8) + tttb;
233 #else
234 col = (tttb << 24) + (tttg << 16) + (tttr << 8);
235 #endif
236 //kprintf("col[%d,%d] = %08x\n", x,y,col);
237 tab[y * SCREENWIDTH + x] = col;
239 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
241 } /* for(y = 0; y < SCREENHEIGHT; y ++) */
243 WritePixelArray(tab, 0, 0, SCREENWIDTH * sizeof(LONG),
244 win->RPort, win->BorderLeft, win->BorderTop, SCREENWIDTH, SCREENHEIGHT,
245 RECTFMT_ARGB);
247 getevents();
249 } /* while(!Keys[KC_ESC]) */
252 /***********************************************************************************/
254 int main(void)
256 openlibs();
257 getvisual();
258 makewin();
259 action();
260 cleanup(0);
262 return 0; /* keep compiler happy */
265 /***********************************************************************************/