66fe14e7c6defed166bef4ae35eb6b34a436ec72
[tpg/acess2.git] / Usermode / Applications / axwin3_src / WM / main.c
1 /*
2  * Acess2 GUI (AxWin) Version 3
3  * - By John Hodge (thePowersGang)
4  *
5  * main.c
6  * - Entrypoint
7  */
8 #include <common.h>
9 #include <acess/sys.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12
13 // === IMPORTS ===
14 extern void     Video_Setup(void);
15 extern void     WM_Initialise(void);
16 extern int      Renderer_Menu_Init(void);
17 extern int      Renderer_Widget_Init(void);
18 extern int      Renderer_Background_Init(void);
19 extern int      Renderer_Framebuffer_Init(void);
20 extern void     WM_Update(void);
21
22 // === PROTOTYPES ===
23 void    ParseCommandline(int argc, char **argv);
24
25 // === GLOBALS ===
26 const char      *gsTerminalDevice = NULL;
27 const char      *gsMouseDevice = NULL;
28
29  int    giScreenWidth = 640;
30  int    giScreenHeight = 480;
31
32  int    giTerminalFD = -1;
33  int    giMouseFD = -1;
34
35 #define __INSTALL_ROOT  "/Acess/Apps/AxWin/3.0"
36
37 const char      *gsInstallRoot = __INSTALL_ROOT;
38
39 // === CODE ===
40 /**
41  * \brief Program Entrypoint
42  */
43 int main(int argc, char *argv[])
44 {
45          int    server_tid = gettid();
46         
47         ParseCommandline(argc, argv);
48         
49         if( gsTerminalDevice == NULL ) {
50                 gsTerminalDevice = "/Devices/VTerm/6";
51         }
52         if( gsMouseDevice == NULL ) {
53                 gsMouseDevice = "/Devices/Mouse/system";
54         }
55         
56         Video_Setup();
57         IPC_Init();
58         Input_Init();
59         
60         Renderer_Menu_Init();
61         Renderer_Widget_Init();
62         Renderer_Background_Init();
63         Renderer_Framebuffer_Init();
64         WM_Initialise();
65         
66         // Spawn interface root
67         if( clone(CLONE_VM, 0) == 0 )
68         {
69                 static char csInterfaceApp[] = __INSTALL_ROOT"/AxWinUI";
70                 char    server_info[] = "AXWIN3_SERVER=00000";
71                 char    *envp[] = {server_info, NULL};
72                 char    *argv[] = {csInterfaceApp, NULL};
73                 _SysDebug("server_tid = %i, &server_tid = %p", server_tid, &server_tid);
74                 sprintf(server_info, "AXWIN3_SERVER=%i", server_tid);
75                 execve(csInterfaceApp, argv, envp);
76                 exit(1);
77         }
78
79         // Main Loop
80         for(;;)
81         {
82                 fd_set  fds;
83                  int    nfds = 0;
84                 FD_ZERO(&fds);
85         
86                 WM_Update();
87
88                 Input_FillSelect(&nfds, &fds);
89                 IPC_FillSelect(&nfds, &fds);
90                 
91                 nfds ++;
92                 if( _SysSelect(nfds, &fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG) == -1 ) {
93                         _SysDebug("ERROR: select() returned -1");
94                         return -1;
95                 }
96
97                 Input_HandleSelect(&fds);
98                 IPC_HandleSelect(&fds);
99         }
100         return 0;
101 }
102
103 void ParseCommandline(int argc, char **argv)
104 {
105         
106 }
107

UCC git Repository :: git.ucc.asn.au