1 /*
2  * ROlib.h
3  *
4  * Defines Classes, variables and OS interface calls for Acorn RISC OS computers.
5  * (C) 1997 Andreas Dehmel
6  *
7  */
8 
9 
10 
11 #ifndef RO_CUSTOM_LIB
12 #define RO_CUSTOM_LIB
13 
14 #include <kernel.h>
15 
16 
17 #define TASKNAME   "Frodo"
18 #define TASK_WORD  0x4b534154
19 
20 /* Scrap-file for 1541fs directory function */
21 #define RO_TEMPFILE	"<Wimp$ScrapDir>.FrodoDIR"
22 
23 
24 
25 /* Icon Flags */
26 #define IFlg_Text	1
27 #define IFlg_Sprite	2
28 #define IFlg_Border	4
29 #define IFlg_HCenter	8
30 #define IFlg_VCenter	16
31 #define IFlg_Filled	32
32 #define IFlg_AntiA	64
33 #define IFlg_AutoRdrw	128
34 #define IFlg_Indir	256
35 #define IFlg_RAdjust	512
36 #define IFlg_Slct	(1<<21)
37 #define IFlg_Grey	(1<<22)
38 
39 /* Menu Flags */
40 #define MFlg_Tick	1
41 #define MFlg_Dotted	2
42 #define MFlg_Writable	4
43 #define MFlg_Warning	8
44 #define MFlg_LastItem	128
45 
46 /* Joystick stuff */
47 #define JoyDir_Thresh   32
48 #define JoyButton1	(1<<16)
49 #define JoyButton2	(1<<17)
50 
51 
52 
53 /* Size of WIMP data types */
54 #define RO_WINDOW_WORDS	23
55 #define RO_WINDOW_BYTES	92
56 #define RO_ICON_WORDS	8
57 #define RO_ICON_BYTES	32
58 #define RO_MHEAD_WORDS	7
59 #define RO_MHEAD_BYTES	28
60 #define RO_MITEM_WORDS	6
61 #define RO_MITEM_BYTES	24
62 
63 
64 
65 
66 /* Structures for directory scanning (mainly 1541fs) */
67 /* May hold entire pathname, so DON'T REDUCE!!! */
68 #define FILENAME_MAX_CHARS	256	/* must be >= NAMEBUF_LENGTH (256) */
69 
70 typedef struct {
71   unsigned int load, exec, length, attrib, otype;
72   char name[FILENAME_MAX_CHARS];
73 } dir_full_info;
74 
75 typedef struct {
76   int readno, offset, buffsize;
77   char *match;
78 } dir_env;
79 
80 
81 
82 /* WIMP structures: */
83 typedef struct {
84   int *tit, *val;
85   int len;
86 } WIdatI;
87 
88 /* data type for window / icon data */
89 typedef union {
90   char strg[12];
91   WIdatI ind;
92 } WIdata;
93 
94 
95 /* Window descriptor - 23 words = 92 bytes */
96 typedef struct {
97   int Handle;
98   int vminx,vminy,vmaxx,vmaxy;
99   int scrollx,scrolly;
100   int stackpos;
101   unsigned int wflags;
102   char col_tfg, col_tbg, col_wfg, col_wbg; /* title/work_area fore/background colour */
103   char col_sbo, col_sbi, col_tsl, reserved;/* scroll bar inner/outer, title if input focus */
104   int wminx, wminy, wmaxx, wmaxy;
105   unsigned int tflags, waflags;
106   int SpriteAreaPtr;
107   short min_width, min_height;
108   WIdata dat;
109   int icon_no;
110 } RO_Window;
111 
112 
113 /* Icon descriptor */
114 typedef struct {
115   int minx, miny, maxx, maxy;
116   int iflags;
117   WIdata dat;
118 } RO_Icon;
119 
120 
121 typedef struct {
122   int WindowHandle;
123   int minx, miny, maxx, maxy;
124   int iflags;
125   WIdata dat;
126 } RO_IconDesc;
127 
128 
129 typedef struct {
130   char title[12];
131   char col_tfg, col_tbg, col_wfg, col_wbg;
132   int width, height, vgap;
133 } RO_MenuHead;
134 
135 
136 typedef struct {
137   unsigned int mflags;
138   RO_MenuHead *submenu;
139   unsigned int iflags;
140   WIdata dat;
141 } RO_MenuItem;
142 
143 
144 /* Caret descriptor */
145 typedef struct {
146   int WHandle;
147   int IHandle;
148   int offx, offy;
149   int height, index;
150 } RO_Caret;
151 
152 
153 
154 /* Joystick key descriptor */
155 typedef struct {
156   unsigned char up, down, left, right, fire;
157 } Joy_Keys;
158 
159 
160 
161 
162 /* Declare classes that are needed in the following new classes */
163 class C64Display;
164 class C64;
165 
166 
167 
168 /* Very simple class to read the resolution and eigen values */
169 class RORes
170 {
171   public:
172   RORes(void);
173   ~RORes(void);
174 
175   int resx,resy,eigx,eigy;
176 };
177 
178 
179 /* Handle current screenmode */
180 class ROScreen
181 {
182   private:
183   _kernel_oserror ModeError;
184 
185   public:
186   ROScreen(void);
187   ~ROScreen(void);
188   int ReadMode(void);
189 
190   int resx, resy, ldbpp, eigx, eigy, ladd;
191   char *scrbase;
192 };
193 
194 
195 class Icon
196 {
197   private:
198   RO_IconDesc icon;
199 
200   public:
201   Icon(int IconHandle, const RO_IconDesc *IDesc);
202   ~Icon(void);
203   void setstate(unsigned int eor, unsigned int clear);
204   void getstate(void);
205 
206   int IHandle;
207 };
208 
209 
210 class Window
211 {
212   private:
213   RO_Window *wind;
214   bool isopen;
215 
216   public:
217   Window(const int *WDesc, const char *Title);
218   ~Window(void);
219   int  MyHandle(void);
220   void GetWorkArea(int *Dest);
221   void RedrawAWindow(int *Block, uint8 *Bitmap, C64Display *Disp);
222   RO_Window *Descriptor(void);
223   RO_Icon *GetIcon(unsigned int number);
224   void SetIconState(unsigned int number, unsigned int eor, unsigned int clear);
225   void GetIconState(unsigned int number, int *Block);
226   void WriteIconText(unsigned int number, const char *text);
227   void WriteIconTextU(unsigned int number, const char *text);	// update instead of force redrw
228   void WriteIconNumber(unsigned int number, int value);
229   void WriteIconNumberU(unsigned int number, int value);
230   char *ReadIconText(unsigned int number);
231   int  ReadIconNumber(unsigned int number);
232   void ForceIconRedraw(unsigned int number);
233   void UpdateIcon(unsigned int number);
234   void WriteTitle(const char *title);
235   char *ReadTitle(void);
236   void UpdateTitle(void);
237   bool HaveInput(void);
238   bool OpenStatus(void);
239   bool OpenStatus(int *Block);
240   void open(void);
241   void open(int *Block);
242   void close(void);
243   void forceredraw(int minx, int miny, int maxx, int maxy);
244   void update(uint8 *Bitmap, C64Display *Disp);
245   void update(int *Block, uint8 *Bitmap, C64Display *Disp);
246   void redraw(int *Block, uint8 *Bitmap, C64Display *Disp);
247   void extent(int minx, int miny, int maxx, int maxy);
248   void getstate(void);
249   void getstate(int *dest); // read window definition to external block
250 };
251 
252 
253 class WIMP
254 {
255   private:
256   _kernel_oserror WimpError;
257   int Block[64], AuxBlock[64];		// two WIMP blocks for convenience
258   int Mask;
259   int DragType, CMOS_DragType;
260   bool UseScrap;	// Scrap file used (data transfer protocol!)
261   bool EmuPaused;
262   int UseNULL;		// Number of clients that need NULL events
263   int RAMsize, RAMtransfered, RAMpartner;	// for RAM transfer
264   int LastMenu, LastClick, LastDrag, MenuType, LastIcon, SaveType;
265   int *SpriteArea;
266   RO_Caret LastCaret;
267   int EmuZoom;
268   Joy_Keys NewJoyKeys[2];
269   C64 *the_c64;
270 
271   public:
272   WIMP(C64 *my_c64);
273   ~WIMP(void);
274 
275   // On startup
276   bool LoadATemplate(char *Name, Window **Which);
277 
278   // To make window and pane work as a team
279   void OpenEmuWindow(void);
280   void OpenEmuWindow(int *Block);	// open at pos
281   void CloseEmuWindow(void);
282   void UpdateEmuWindow(void);		// update window and pane
283   void ThePrefsToWindow(void);		// write ThePrefs into the window
284   void WindowToThePrefs(void);		// update ThePrefs from window
285   void SysConfToWindow(void);
286   void WindowToSysConf(void);
287   void PollSysConfWindow(void);		// low-level koyboard scan
288   void DragIconSprite(Window *host, unsigned int number);
289   int  CalculateVolume(int *Block);
290   int  CheckFilename(char *name);
291   void SnapshotSaved(bool OK);
292   void IssueSnapshotRequest(void);
293   void SetLEDIcons(bool FloppyEmulation);
294   void SetEmuWindowSize(void);
295   void ToggleEmuWindowSize(void);
296   int  ReadEmuWindowSize(void);
297   void NewDriveImage(int DrNum, int *MsgBlock, bool SetNow);
298   void SetSpeedLimiter(bool LimitSpeed);
299 
300   // Standard WIMP functions
301   void Poll(bool Paused);
302   void Redraw(void);
303   void OpenWindow(void);
304   void CloseWindow(void);
305   void MouseClick(void);
306   void UserDrag(void);
307   void KeyPressed(void);
308   void MenuSelection(void);
309   void UserMessage(void);
310   void UserMessageAck(void);
311 
312   // WIMP's Windows and Icons
313   Icon *IBicon;
314   Window *EmuWindow, *EmuPane, *PrefsWindow, *ConfigWindow, *InfoWindow, *SoundWindow, *SaveBox;
315   char SnapFile[256], RAMFile[256];
316 };
317 
318 
319 
320 /* system-specific Variables */
321 
322 extern RO_IconDesc IBarIcon;
323 extern unsigned int TaskHandle;
324 extern int WimpMessages[];
325 
326 
327 /* Functions available via ROlib (not RISC OS Lib, mind you)
328    All SWIs are called in the X-Form! */
329 
330 extern "C"
331 {
332 
333 /* WIMP FUNCTIONS */
334 
335 /* returns handle or 0 if error */
336 extern int Wimp_Initialise(int Version, int tw, const char *TaskName, const int *Messages);
337 
338 extern _kernel_oserror *Wimp_CloseDown(int Handle, int tw);
339 
340 /* returns handle or 0 if error */
341 extern int Wimp_CreateWindow(const int *Window);
342 
343 extern int Wimp_CreateIcon(int Priority, const RO_IconDesc *Icon);
344 
345 extern _kernel_oserror *Wimp_DeleteWindow(const int *Window);
346 
347 extern _kernel_oserror *Wimp_DeleteIcon(int *Block);
348 
349 extern _kernel_oserror *Wimp_OpenWindow(const int *Window);
350 
351 extern _kernel_oserror *Wimp_CloseWindow(const int *Window);
352 
353 extern int Wimp_Poll(unsigned int Mask, int *Block, int *PollWord);
354 
355 /* returns 0 if no more to do or error */
356 extern int Wimp_RedrawWindow(int *Block);
357 
358 extern int Wimp_UpdateWindow(int *Block);
359 
360 extern int Wimp_GetRectangle(int *Block);
361 
362 extern _kernel_oserror *Wimp_GetWindowState(int *Block);
363 
364 extern _kernel_oserror *Wimp_GetWindowInfo(int *Block);
365 
366 extern _kernel_oserror *Wimp_SetIconState(int *Block);
367 
368 extern _kernel_oserror *Wimp_GetIconState(int *Block);
369 
370 extern _kernel_oserror *Wimp_GetPointerInfo(int *Block);
371 
372 extern _kernel_oserror *Wimp_DragBox(int *Block);
373 
374 extern _kernel_oserror *Wimp_ForceRedraw(int Handle, int minx, int miny, int maxx, int maxy);
375 
376 extern _kernel_oserror *Wimp_SetCaretPosition(int WHandle, int IHandle, int xoff, int yoff, int height, int index);
377 
378 extern _kernel_oserror *Wimp_GetCaretPosition(RO_Caret *Caret);
379 
380 extern _kernel_oserror *Wimp_CreateMenu(const int *Menu, int cx, int cy);
381 
382 extern _kernel_oserror *Wimp_SetExtent(int Handle, int *Block);
383 
384 extern _kernel_oserror *Wimp_OpenTemplate(char *Name);
385 
386 extern _kernel_oserror *Wimp_CloseTemplate(void);
387 
388 extern _kernel_oserror *Wimp_LoadTemplate(char **Template, char **Indirect, char *IndirLimit, char *Fonts, char *Name, int *Position);
389 
390 extern _kernel_oserror *Wimp_ProcessKey(int Key);
391 
392 extern int Wimp_StartTask(char *command);
393 
394 extern _kernel_oserror *Wimp_ReportError(const _kernel_oserror *Error, unsigned int Flags, const char *AppName);
395 
396 extern _kernel_oserror *Wimp_GetWindowOutline(int *Block);
397 
398 extern int Wimp_PollIdle(unsigned int Mask, int *Block, int MinTime, int *PollWord);
399 
400 extern _kernel_oserror *Wimp_PlotIcon(int *Block);
401 
402 extern _kernel_oserror *Wimp_SendMessage(int Event, int *Block, int THandle, int IHandle);
403 
404 extern _kernel_oserror *Wimp_CreateSubMenu(int *MenuBlock, int cx, int xy);
405 
406 extern _kernel_oserror *Wimp_SpriteOp(int, int, int, int, int, int, int, int);
407 
408 extern _kernel_oserror *Wimp_BaseOfSprites(int *ROM, int *RAM);
409 
410 extern _kernel_oserror *Wimp_CommandWindow(int Action);
411 
412 extern _kernel_oserror *Wimp_TransferBlock(int SHandle, char *SBuff, int DHandle, char *DBuff, int BuffSize);
413 
414 extern _kernel_oserror *Wimp_SpriteInfo(char *name, int *width, int *height, int *mode);
415 
416 extern _kernel_oserror *DragASprite_Start(unsigned int Flags, int SpriteArea, char *SpriteName, int *Box, int *BBox);
417 
418 extern _kernel_oserror *DragASprite_Stop(void);
419 
420 extern _kernel_oserror *ColourTrans_SelectTable(int SMode, int SPal, int DMode, int DPal, char **Buffer, unsigned int Flags, int *TransWork, int *TransFunc);
421 
422 extern _kernel_oserror *ColourTrans_SetFontColours(int Handle, int BPal, int FPal, int Offset);
423 
424 extern _kernel_oserror *ColourTrans_SetColour(int GCOL, unsigned int Flags, int Action);
425 
426 extern _kernel_oserror *ColourTrans_SetGCOL(int Palette, unsigned int Flags, int Action);
427 
428 
429 
430 /* OS FUNCTIONS */
431 
432 extern int OS_ReadModeVariable(int mode, int var);
433 
434 extern int OS_ReadDynamicArea(int area);
435 
436 extern int ScanKeys(int keys);
437 
438 extern int ReadKeyboardStatus(void);
439 
440 extern int ReadDragType(void);
441 
442 extern int SetMousePointer(int NewShape);
443 
444 
445 /* Generic sprite op call */
446 extern _kernel_oserror *OS_SpriteOp(int, int, int, int, int, int, int, int);
447 
448 extern _kernel_oserror *OS_Plot(int Command, int x, int y);
449 
450 extern _kernel_oserror *MouseBoundingBox(char Box[8]);
451 
452 extern int OS_ReadMonotonicTime(void);
453 
454 extern _kernel_oserror *OS_ReadC(char *Code);
455 
456 /* returns length of characters read; if length negative ==> terminated by escape */
457 extern int OS_ReadLine(char *Buffer, int BuffSize, int minasc, int maxasc, int Echo);
458 
459 /* TRUE ==> escape */
460 extern bool OS_ReadEscapeState(void);
461 
462 /* File related calls */
463 
464 /* Returns object type */
465 extern int ReadCatalogueInfo(char *Name, int Result[4]);
466 
467 /* Read the next name in the directory */
468 extern _kernel_oserror *ReadDirName(const char *dirname, char *buffer, dir_env *env);
469 
470 /* Read the next entry (name, length, type,...) in the directory */
471 extern _kernel_oserror *ReadDirNameInfo(const char *dirname,dir_full_info *buffer,dir_env *env);
472 
473 extern _kernel_oserror *DeleteFile(char *name);
474 
475 extern _kernel_oserror *OS_FlushBuffer(int BuffNum);
476 
477 /* These functions are more secure than using sprintf because they allow buffersize */
478 /* Return value is a pointer to the terminating null */
479 extern char *ConvertInteger1(int value, char *buffer, int buffsize);
480 extern char *ConvertInteger2(int value, char *buffer, int buffsize);
481 extern char *ConvertInteger3(int value, char *buffer, int buffsize);
482 extern char *ConvertInteger4(int value, char *buffer, int buffsize);
483 
484 
485 /* Misc */
486 
487 extern unsigned int ModeColourNumber(unsigned int pal_entry);
488 
489 /* Returns -1 if error in joystick module, -2 if SWI unknown, joystate otherwise */
490 extern int Joystick_Read(int joyno);
491 
492 
493 /* Sound stuff */
494 
495 #define DRState_Active		1
496 #define DRState_NeedData	2
497 #define DRState_Overflow	4
498 
499 /* Sound calls */
500 
501 extern int Sound_Volume(int volume);
502 
503 /* Digital Renderer SWI calls */
504 extern _kernel_oserror *DigitalRenderer_Activate(int Channels, int Length, int SamPeriod);
505 
506 extern _kernel_oserror *DigitalRenderer_Deactivate(void);
507 
508 extern _kernel_oserror *DigitalRenderer_Pause(void);
509 
510 extern _kernel_oserror *DigitalRenderer_Resume(void);
511 
512 extern _kernel_oserror *DigitalRenderer_GetTables(uint8 **LinToLog, uint8 **LogScale);
513 
514 extern int DigitalRenderer_ReadState(void);
515 
516 extern _kernel_oserror *DigitalRenderer_NewSample(uint8 *Sample);
517 
518 }
519 
520 #endif
521