added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / intuition / displaybeep.c
blobc2351ef81fe0f0026e33c88f02c83573e06b4c30
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <proto/graphics.h>
8 #include "intuition_intern.h"
10 #define BEEPTICKS 3 /* in 1/10th sec units */
12 static inline ULONG beepcolor(ULONG x)
14 return x < 0x88888888 ? 0xCCCCCCCC : 0x55555555;
18 /*****************************************************************************
20 NAME */
21 #include <proto/intuition.h>
23 AROS_LH1(void, DisplayBeep,
25 /* SYNOPSIS */
26 AROS_LHA(struct Screen *, screen, A0),
28 /* LOCATION */
29 struct IntuitionBase *, IntuitionBase, 16, Intuition)
31 /* FUNCTION
32 The Amiga has no internal speaker, so it flashes the background
33 color of the specified screen as a signal. If the argument is
34 NULL all screens will be flashed.
36 INPUTS
37 screen - The Screen that will be flashed.
38 If NULL all screens will flash.
40 RESULT
42 NOTES
44 EXAMPLE
46 BUGS
48 SEE ALSO
50 INTERNALS
51 Hardware with a speaker should make an audible beep, too.
52 Maybe even leave out the flashing on those architectures.
54 HISTORY
56 *****************************************************************************/
58 AROS_LIBFUNC_INIT
60 #if USE_NEWDISPLAYBEEP
62 BOOL AllScreens = FALSE;
63 ULONG lock;
65 //dprintf("INT_DisplayBeep: entry, screen 0x%lx\n", (ULONG) screen);
67 #ifdef USEWINDOWLOCK
68 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->WindowLock);
69 #else
70 return; //RenderScreenBar NOT safe without this
71 #endif
72 //jDc: screenlist will NOT be modified while we hold WINDOWLOCK!
73 //lock = LockIBase(0);
75 /* Start Beep */
76 if (screen == (struct Screen *) -1 || screen == NULL)
78 screen = IntuitionBase->FirstScreen;
79 AllScreens = TRUE;
82 while (screen)
84 //dprintf("INT_DisplayBeep: screen 0x%lx\n", (ULONG) screen);
86 if (screen->Flags & BEEPING)
88 GetPrivScreen(screen)->BeepingCounter = BEEPTICKS;
90 else
92 screen->Flags |= BEEPING;
94 RenderScreenBar(screen, FALSE, IntuitionBase);
95 //dprintf("INT_DisplayBeep: RenderScreenBar done for screen 0x%lx\n", (ULONG) screen);
97 GetPrivIBase(IntuitionBase)->BeepingScreens++;
98 GetPrivScreen(screen)->BeepingCounter = BEEPTICKS;
101 screen = AllScreens ? screen->NextScreen : NULL;
104 //UnlockIBase(lock);
106 #ifdef USEWINDOWLOCK
107 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->WindowLock);
108 #endif
109 //dprintf("INT_DisplayBeep: done\n");
111 #else /* USE_NEWDISPLAYBEEP */
113 struct MsgPort *TimerMsgPort;
114 struct timerequest *BeepTimerIO;
115 BOOL VisualBeep = TRUE;
116 BOOL AllScreens = FALSE;
117 LONG NumBeeped = 0;
119 TimerMsgPort = CreateMsgPort();
120 if (!TimerMsgPort)
122 return;
125 BeepTimerIO = (struct timerequest *) CreateIORequest (TimerMsgPort, sizeof (struct timerequest));
126 if (!BeepTimerIO)
128 DeleteMsgPort(TimerMsgPort);
129 return;
132 if (OpenDevice ("timer.device", UNIT_VBLANK, (struct IORequest *) BeepTimerIO, 0) != 0)
134 DeleteIORequest((struct IORequest *) BeepTimerIO);
135 DeleteMsgPort(TimerMsgPort);
136 return;
139 BeepTimerIO->tr_node.io_Command = TR_ADDREQUEST;
140 BeepTimerIO->tr_time.tv_secs = 0;
141 BeepTimerIO->tr_time.tv_micro = 200000; // 250000
144 /* Start Beep */
145 if (VisualBeep)
147 if (screen == (struct Screen *) -1 || screen == NULL)
149 //LockIBase();
150 screen = IntuitionBase->FirstScreen;
151 //UnlockIBase();
152 AllScreens = TRUE;
157 Forbid();
158 if (!(screen->Flags & BEEPING))
160 screen->Flags |= BEEPING;
161 Permit();
163 if (GetBitMapAttr(screen->RastPort.BitMap, BMA_DEPTH) <= 8)
164 // visual beep on CLUT-screen
167 struct DrawInfo *DInfo = NULL;
168 UWORD BGPen;
169 ULONG color[3];
171 DInfo = GetScreenDrawInfo (screen);
172 BGPen = DInfo->dri_Pens[BACKGROUNDPEN];
175 GetRGB32 (screen->ViewPort.ColorMap, 0, 1, GetPrivScreen(screen)->DisplayBeepColor0);
176 screen->SaveColor0 = GetRGB4 (screen->ViewPort.ColorMap, 0);
178 SetRGB32 (&screen->ViewPort, 0,
179 beepcolor(GetPrivScreen(screen)->DisplayBeepColor0[0]),
180 beepcolor(GetPrivScreen(screen)->DisplayBeepColor0[1]),
181 beepcolor(GetPrivScreen(screen)->DisplayBeepColor0[2])
184 // FreeScreenDrawInfo (screen, DInfo);
187 else
188 // visual beep on hi- and truecolor screens
190 // struct Window *BeepWindow;
191 struct TagItem window_tags[] =
193 {WA_Left , 0 },
194 {WA_Top , 0 },
195 {WA_Width , -1 },
196 {WA_Height , -1 },
197 {WA_Flags , WFLG_SIMPLE_REFRESH | WFLG_BORDERLESS },
198 {WA_CustomScreen, (IPTR) screen },
199 //{WA_Priority , 50 }, // Place in front of all other windows!
200 {TAG_DONE }
203 GetPrivScreen(screen)->DisplayBeepWindow = (struct Window *) OpenWindowTagList (NULL, window_tags);
204 screen->Flags |= BEEPING;
206 NumBeeped++;
208 //LockIBase();
209 if (AllScreens) screen = screen->NextScreen;
210 //UnlockIBase();
212 else
213 Permit();
216 while (AllScreens && screen);
219 if (NumBeeped)
221 /* Wait */
222 DoIO ((struct IORequest *) BeepTimerIO);
225 /* Stop Beep */
226 if (VisualBeep)
228 if (AllScreens)
230 //LockIBase();
231 screen = IntuitionBase->FirstScreen;
232 //UnlockIBase();
238 Forbid();
239 if (screen->Flags & BEEPING)
241 Permit();
243 if (GetBitMapAttr(screen->RastPort.BitMap, BMA_DEPTH) <= 8)
244 // visual beep on CLUT-screen
246 // SetRGB4 (&screen->ViewPort, 0, screen->SaveColor0 & 0x000F, (screen->SaveColor0 & 0x00F0) >> 4, (screen->SaveColor0 & 0x0F00) >> 8);
247 SetRGB32 (&screen->ViewPort, 0,
248 GetPrivScreen(screen)->DisplayBeepColor0[0],
249 GetPrivScreen(screen)->DisplayBeepColor0[1],
250 GetPrivScreen(screen)->DisplayBeepColor0[2]
253 else
254 // visual beep on hi- and truecolor screens
256 if (GetPrivScreen(screen)->DisplayBeepWindow)
258 CloseWindow (GetPrivScreen(screen)->DisplayBeepWindow);
259 GetPrivScreen(screen)->DisplayBeepWindow = NULL;
263 screen->Flags &= (UWORD) ~BEEPING;
265 else
266 Permit();
268 //LockIBase();
269 if (AllScreens) screen = screen->NextScreen;
270 //UnlockIBase();
273 while (AllScreens && screen);
276 CloseDevice((struct IORequest *) BeepTimerIO);
277 DeleteIORequest((struct IORequest *) BeepTimerIO);
278 DeleteMsgPort(TimerMsgPort);
280 #warning TODO: Make this "multitasking proof"!
281 #warning TODO: Produce beep according to prefs
282 #warning TODO: Check if BEEPING flag is handled correctly
283 #warning TODO: Make BeepWindow 50% transparent! :-)
284 #warning TODO: Use TimerIO (IntuitionBase->TimerIO) instead of self-made BeepTimerIO?
286 #endif /* USE_NEWDISPLAYBEEP */
288 AROS_LIBFUNC_EXIT
289 } /* DisplayBeep */