Foenix A2650 OS/f Library
 
Loading...
Searching...
No Matches
sys.h
Go to the documentation of this file.
1
2
3/*
4 * sys.h
5 *
6* Created on: Mar 22, 2022
7 * Author: micahbly
8 */
9
10#ifndef LIB_SYS_H_
11#define LIB_SYS_H_
12
13
14/* about this library: System
15 *
16 * This provides overall system level functionality
17 *
18 *** things this library needs to be able to do
19 * Manage global system resources such as fonts, screens, mouse pointer, etc.
20 * Provide event handling
21 *
22 * STRETCH GOALS
23 *
24 *
25 * SUPER STRETCH GOALS
26 *
27 *
28 */
29
30
31/*****************************************************************************/
32/* Includes */
33/*****************************************************************************/
34
35// project includes
36#include "list.h"
37#include "theme.h"
38#include "control_template.h"
39#include "font.h"
40
41
42// C includes
43#include <stdbool.h>
44
45
46// A2560 includes
47#include <mcp/syscalls.h>
48#include "a2560k.h"
49#include "general.h"
50#include "text.h"
51#include "bitmap.h"
52#include "window.h"
53
54
55/*****************************************************************************/
56/* Macro Definitions */
57/*****************************************************************************/
58
59#define SYS_MAX_WINDOWS 32
60#define SYS_WIN_Z_ORDER_BACKDROP -127
61#define SYS_WIN_Z_ORDER_NEWLY_ACTIVE SYS_MAX_WINDOWS + 1
62
63#define PARAM_SPRITES_ON true // parameter for Sys_SetGraphicMode
64#define PARAM_SPRITES_OFF false // parameter for Sys_SetGraphicMode
65#define PARAM_BITMAP_ON true // parameter for Sys_SetGraphicMode
66#define PARAM_BITMAP_OFF false // parameter for Sys_SetGraphicMode
67#define PARAM_TILES_ON true // parameter for Sys_SetGraphicMode
68#define PARAM_TILES_OFF false // parameter for Sys_SetGraphicMode
69#define PARAM_TEXT_OVERLAY_ON true // parameter for Sys_SetGraphicMode
70#define PARAM_TEXT_OVERLAY_OFF false // parameter for Sys_SetGraphicMode
71#define PARAM_TEXT_ON true // parameter for Sys_SetGraphicMode
72#define PARAM_TEXT_OFF false // parameter for Sys_SetGraphicMode
73
74#define PARAM_DOUBLE_SIZE_TEXT true // parameter for Sys_SetTextPixelHeight
75#define PARAM_NORMAL_SIZE_TEXT false // parameter for Sys_SetTextPixelHeight
76
77#define PARAM_EXIT_ON_ERROR true // parameter for Sys_Exit
78#define PARAM_EXIT_NO_ERROR false // parameter for Sys_Exit
79
80/*****************************************************************************/
81/* Enumerations */
82/*****************************************************************************/
83
84
85
86/*****************************************************************************/
87/* Structs */
88/*****************************************************************************/
89
90struct System
91{
92 EventManager* event_manager_;
93 Font* system_font_;
94 Font* app_font_;
95 Screen* screen_[2];
96 Theme* theme_;
97 uint8_t num_screens_;
98 List** list_windows_;
99 Window* active_window_;
100 uint8_t window_count_;
101 uint16_t model_number_;
102 Menu* menu_manager_;
103 char* text_temp_buffer_; // general use temp buffer big enough for full screen word wrap; do NOT use for real storage. Any utility function clobber it
104};
105
106
107
108
109
110/*****************************************************************************/
111/* Global Variables */
112/*****************************************************************************/
113
114
115/*****************************************************************************/
116/* Public Function Prototypes */
117/*****************************************************************************/
118
119
120// **** CONSTRUCTOR AND DESTRUCTOR *****
121
122// constructor
124System* Sys_New(void);
125
126// destructor
127// frees all allocated memory associated with the passed object, and the object itself
129bool Sys_Destroy(System** the_system);
130
131
136void Sys_Exit(System** the_system, bool error_condition);
137
138
139
140// **** System Initialization functions *****
141
144bool Sys_InitSystem(System* the_system);
145
146
147
148// **** Event-handling functions *****
149
150
151
152
153// **** Screen mode/resolution/size functions *****
154
159bool Sys_SetVideoMode(Screen* the_screen, screen_resolution new_mode);
160
165bool Sys_SetModeText(System* the_system, bool as_overlay);
166
170bool Sys_SetGraphicMode(System* the_system, bool enable_sprites, bool enable_bitmaps, bool enable_tiles, bool enable_text_overlay, bool enable_text);
171
177bool Sys_EnableTextModeCursor(System* the_system, Screen* the_screen, bool enable_it);
178
185bool Sys_SetBorderSize(System* the_system, Screen* the_screen, uint8_t border_width, uint8_t border_height);
186
187
188
189// **** Window management functions *****
190
194bool Sys_AddToWindowList(System* the_system, Window* the_new_window);
195
196// create the backdrop window for the system
198bool Sys_CreateBackdropWindow(System* the_system);
199
200// return the active window
202Window* Sys_GetActiveWindow(System* the_system);
203
204// return the backdrop window
207
208// return a reference to the next window in the system's list, excluding backdrop windows
210Window* Sys_GetNextWindow(System* the_system);
211
212// return a reference to the previous window in the system's list, excluding backdrop windows
215
216// Find the Window under the mouse -- accounts for z depth (topmost window will be found)
220Window* Sys_GetWindowAtXY(System* the_system, int16_t x, int16_t y);
221
226bool Sys_SetActiveWindow(System* the_system, Window* the_window);
227
228// List-sort compatible function for sorting windows by their display order property
229bool Window_CompareDisplayOrder(void* first_payload, void* second_payload);
230
231// remove one window from system's list of windows, and close it
232void Sys_CloseOneWindow(System* the_system, Window* the_window);
233
236void Sys_IssueDamageRects(System* the_system);
237
240void Sys_IssueMenuDamageRects(System* the_system);
241
244void Sys_CollectDamageRects(System* the_system, Window* the_future_active_window);
245
246
247
248
249// **** Other GET functions *****
250
252Font* Sys_GetSystemFont(System* the_system);
253
255Font* Sys_GetAppFont(System* the_system);
256
258Screen* Sys_GetScreen(System* the_system, int16_t channel_id);
259
261Menu* Sys_GetMenu(System* the_system);
262
264Theme* Sys_GetTheme(System* the_system);
265
268Bitmap* Sys_GetScreenBitmap(System* the_system, bitmap_layer the_layer);
269
272
273
274
275// **** Other SET functions *****
276
278void Sys_SetSystemFont(System* the_system, Font* the_font);
279
281void Sys_SetAppFont(System* the_system, Font* the_font);
282
284void Sys_SetScreen(System* the_system, int16_t channel_id, Screen* the_screen);
285
288void Sys_SetScreenBitmap(System* the_system, Bitmap* the_bitmap, bitmap_layer the_layer);
289
294bool Sys_SetTheme(System* the_system, Theme* the_theme);
295
296
297
298// **** xxx functions *****
299
304bool Sys_SetVRAMAddr(System* the_system, uint8_t the_bitmap_layer, unsigned char* the_address);
305
306
307
308// **** xxx functions *****
309
310
311
312
313
314
315
316//
317// Discord, 3022/03/10
318//
319// PJW
320// Generally speaking (the order does not really matter on this):
321// 1. Set the mode bits in the master control register (GRAPHICS + BITMAP), as well as the resolution.
322// 2. Load the color table for the bitmap into one of the graphics LUTs (start at $B4:2000 on the A2560U, $FEC8:2000 on the A2560K)
323// 3. Load the bitmap pixel data into video RAM (starts at $C0:0000 on the A2560U, $0080:0000 on the A2560K)
324// 4. Set the enable bit and LUT # in the bitmap control register for the layer you want
325// 5. Set the address of the pixel data in video RAM in the VRAM address pointer for the layer you want. This must be set relative to the beginning of VRAM, so if you're using the A2560U and the pixel data starts at $C2:0000, you'd store $02:0000 in the address register.
326// Paul Scott Robson — Today at 12:45 PM
327// TextInitialise:
328// clr.l d0
329// lea vicky3,a0 ; start register writes
330// move.l #$0000000C,(a0) ; graphics mode & bitmap on.
331// move.l d0,$4(a0) ; zero border size/scroll/colour
332// move.l d0,$8(a0) ; clear border colour
333// move.l d0,$C(a0)
334// move.l d0,$10(a0) ; cursor off
335// move.l d0,$14(a0) ; no line interrupts
336// move.l d0,$18(a0)
337//
338// move.l #$00000001,$100(a0) ; LUT 0, BMP 1 on
339// move.l d0,$104(a0) ; BMP 1 address
340// move.l d0,$108(a0) ; BMP 2 off
341//
342// move.l #$0000FF00,$2004(a0) ; colour 1 red
343// move.l #$00FF00FF,$2008(a0) ; colour 2 green
344// move.l #$00FFFFFF,$200C(a0) ; colour 3 yellow
345// move.l #$FF0000FF,$2010(a0) ; colour 4 blue
346// move.l #$FF00FFFF,$2014(a0) ; colour 5 magenta
347// move.l #$FFFF00FF,$2018(a0) ; colour 6 cyan
348// move.l #$FFFFFFFF,$201C(a0) ; colour 7 white
349//
350// rts
351// Bit Q&D but I think it's right
352
353
354// **** TEMP font loading *****
355
356// create a font object and populate with modified chicago 14 pt regular
357// this is a temporary function until we get file handling and can load from disk
358Font* Sys_LoadSystemFont(void);
359
360// create a font object and populate with helvetica 9 pt regular
361// this is a temporary function until we get file handling and can load from disk
362Font* Sys_LoadAppFont(void);
363
364
365
366// **** Render functions *****
367
368
372void Sys_Render(System* the_system);
373
374
375
376// **** Debug functions *****
377
378void Sys_Print(System* the_system);
379
380void Sys_PrintScreen(Screen* the_screen);
381
382
383
384#endif /* LIB_SYS_H_ */
385
386
Definition: bitmap.h:97
Definition: event.h:225
This Font object is essentially the Mac "fontRecord" struct, with added pointers for the data tables.
Definition: font.h:71
Definition: list.h:67
Definition: menu.h:120
Definition: a2560k.h:1375
Definition: sys.h:91
Definition: theme.h:106
Definition: window.h:135
void Sys_SetSystemFont(System *the_system, Font *the_font)
Definition: sys.c:2235
System * Sys_New(void)
Allocate a System object.
Definition: sys.c:642
bool Sys_EnableTextModeCursor(System *the_system, Screen *the_screen, bool enable_it)
Enable or disable the hardware cursor in text mode, for the specified screen.
Definition: sys.c:1298
EventManager * Sys_GetEventManager(System *the_system)
Definition: sys.c:2213
void Sys_CollectDamageRects(System *the_system, Window *the_future_active_window)
Collect damage rects for a window that is about to be made the active (foremost) window,...
Definition: sys.c:2025
bool Sys_SetVRAMAddr(System *the_system, uint8_t the_bitmap_layer, unsigned char *the_address)
Tell the VICKY to use a different address for the specified bitmap layer.
Definition: sys.c:2394
bool Sys_AddToWindowList(System *the_system, Window *the_new_window)
Add this window to the list of windows and make it the currently active window.
Definition: sys.c:1364
bool Sys_SetTheme(System *the_system, Theme *the_theme)
Set the passed theme as the System's current theme Note: this will dispose of the current theme after...
Definition: sys.c:2337
bool Sys_SetVideoMode(Screen *the_screen, screen_resolution new_mode)
Change video mode to the one passed.
Definition: sys.c:1111
void Sys_IssueMenuDamageRects(System *the_system)
Issue damage rects from the menu down to every other window in the system so that they can redraw por...
Definition: sys.c:1977
void Sys_SetAppFont(System *the_system, Font *the_font)
Definition: sys.c:2254
bool Sys_Destroy(System **the_system)
Definition: sys.c:667
Window * Sys_GetNextWindow(System *the_system)
Definition: sys.c:1534
Font * Sys_GetAppFont(System *the_system)
Definition: sys.c:2132
bool Sys_SetBorderSize(System *the_system, Screen *the_screen, uint8_t border_width, uint8_t border_height)
Set the left/right and top/bottom borders This will reset the visible text columns as a side effect G...
Definition: sys.c:1329
bool Sys_InitSystem(System *the_system)
Initialize the system (primary entry point for all system initialization activity) Starts up the memo...
Definition: sys.c:754
Window * Sys_GetWindowAtXY(System *the_system, int16_t x, int16_t y)
Definition: sys.c:1703
void Sys_Render(System *the_system)
Render all visible windows NOTE: this will move to a private Sys function later, once event handling ...
Definition: sys.c:2452
Screen * Sys_GetScreen(System *the_system, int16_t channel_id)
Definition: sys.c:2149
bool Sys_CreateBackdropWindow(System *the_system)
Definition: sys.c:1429
Window * Sys_GetBackdropWindow(System *the_system)
Definition: sys.c:1500
void Sys_SetScreen(System *the_system, int16_t channel_id, Screen *the_screen)
Definition: sys.c:2273
Window * Sys_GetPreviousWindow(System *the_system)
Definition: sys.c:1627
bool Sys_SetActiveWindow(System *the_system, Window *the_window)
Set the passed window to the active window, and marks the previously active window as inactive NOTE: ...
Definition: sys.c:1762
bool Sys_SetModeText(System *the_system, bool as_overlay)
Switch machine into text mode.
Definition: sys.c:1067
void Sys_IssueDamageRects(System *the_system)
Issue damage rects from the Active Window down to each other window in the system so that they can re...
Definition: sys.c:1915
Bitmap * Sys_GetScreenBitmap(System *the_system, bitmap_layer the_layer)
NOTE: Foenix systems only have 1 screen with bitmap graphics, even if the system has 2 screens overal...
Definition: sys.c:2190
Theme * Sys_GetTheme(System *the_system)
Definition: sys.c:2099
Menu * Sys_GetMenu(System *the_system)
Definition: sys.c:2172
bool Sys_SetGraphicMode(System *the_system, bool enable_sprites, bool enable_bitmaps, bool enable_tiles, bool enable_text_overlay, bool enable_text)
Switch machine into graphics mode, text mode, sprite mode, etc.
Definition: sys.c:976
void Sys_Exit(System **the_system, bool error_condition)
Exit to MCP Destroys the system on the way out.
Definition: sys.c:727
Font * Sys_GetSystemFont(System *the_system)
Definition: sys.c:2115
Window * Sys_GetActiveWindow(System *the_system)
Definition: sys.c:1482
void Sys_SetScreenBitmap(System *the_system, Bitmap *the_bitmap, bitmap_layer the_layer)
NOTE: Foenix systems only have 1 screen with bitmap graphics, even if the system has 2 screens overal...
Definition: sys.c:2299