3 * A nice blinky caret routine for your progs
5 * v. 1.00 (23 July 1993)
7 * © 1993-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 extern void _dllEntry(blink__exit)(void);
41 extern void _dllEntry(blink__doBlink)(int at,void *handle);
45 * A handle thing for alarm. It's not used by the routine, but it helps
46 * identify the alarm routine to be removed.
48 #define blink__MYHANDLE (void *)&blink__onAlready
51 * The SWI number for Wimp_SendMessage.
53 #define Wimp_SendMessage 0x600E7
56 * Due to circular definitions, I am forced to add in a prototype for this
59 static void blink__setupAlarm(void);
62 * A flag to say whether we are on already or not.
64 static BOOL blink__onAlready;
67 * A flag to say whether the caret is visible or not.
69 static BOOL blink__caretVisible;
72 * void blink__onCaret(void)
75 * Makes the caret visible.
78 static void blink__onCaret(void)
81 wimpt_noerr(wimp_get_caret_pos(&c));
83 wimpt_noerr(wimp_set_caret_pos(&c));
84 blink__caretVisible=TRUE;
88 * void blink__offCaret(void)
91 * Makes the caret invisible.
94 static void blink__offCaret(void)
97 wimpt_noerr(wimp_get_caret_pos(&c));
99 wimpt_noerr(wimp_set_caret_pos(&c));
100 blink__caretVisible=FALSE;
104 * BOOL blink__ownCaret(void)
107 * Returns whether the task owns the caret or not!
113 static BOOL blink__ownCaret(void)
118 wimpt_noerr(wimp_get_caret_pos(&c));
123 _swix(Wimp_SendMessage, _inr(0,2)+_out(2), 19,&m,c.w, &task);
124 return (task==wimpt_task());
127 _dll_static void blink__doBlink(int at,void *handle)
131 if (blink__ownCaret())
133 switch (blink__caretVisible)
147 * void blink__setupAlarm(void)
150 * Sets up next alarm ready.
153 static void blink__setupAlarm(void)
155 int nextTime=((alarm_timenow()/25)*25)+25;
156 alarm_set(nextTime,_dllEntry(blink__doBlink),blink__MYHANDLE);
160 * void blinkCursor(BOOL onOrOff)
163 * Turns the blinkingness of the cursor on or off. You must call
164 * alarm_init() before this function, or all hell breaks loose.
167 * BOOL onOrOff == whether you want to turn blinking cursor on or off
170 void blinkCursor(BOOL onOrOff)
172 if (onOrOff==blink__onAlready)
178 blink__onAlready=TRUE;
181 if (blink__ownCaret())
183 alarm_removeall(blink__MYHANDLE);
184 blink__onAlready=FALSE;
190 * void blink__exit(void)
193 * Turns off the caret blinking.
196 _dll_static void blink__exit(void)
202 * void blink_init(void)
205 * Sets everything up nicely.
208 void blink_init(void)
210 atexit(_dllEntry(blink__exit));