Port the SB128 code to AROS.
[AROS.git] / workbench / c / GfxControl.c
blobcf5cd3d2607d8ae85e5e41c1696709209efd166c
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Change some internal options of cybergraphics.library.
6 Lang: English
7 */
8 /*****************************************************************************
10 NAME
12 GfxControl
14 SYNOPSIS
16 PREVENT_DIRECT_BITMAP_ACCESS=PDBA/S,
17 ALLOW_DIRECT_BITMAP_ACCESS=ADBA/S,
18 DUMP/S
20 LOCATION
24 FUNCTION
26 Change some internal options of cybergraphics.library
28 INPUTS
30 PREVENT_DIRECT_BITMAP_ACCESS -- Causes LockBitMapTagList() calls to
31 always fail
33 ALLOW_DIRECT_BITMAP_ACCESS -- Allow LocKBitMapTagList() to go to
34 gfx driver which may or may not
35 support it. (default)
37 DUMP -- Show current settings
39 RESULT
41 Standard DOS return codes.
43 NOTES
44 By default
45 BUGS
47 INTERNALS
49 ******************************************************************************/
51 #include <dos/dosextens.h>
52 #include <proto/alib.h>
53 #include <proto/exec.h>
54 #include <proto/dos.h>
56 /****************************************************************************************/
58 #define PORT_NAME "GfxControl"
60 #define ARG_TEMPLATE "PREVENT_DIRECT_BITMAP_ACCESS=PDBA/S,ALLOW_DIRECT_BITMAP_ACCESS=ADBA/S,DUMP/S"
61 #define ARG_PDBA 0
62 #define ARG_ADBA 1
63 #define ARG_DUMP 2
64 #define NUM_ARGS 3
66 /****************************************************************************************/
68 AROS_UFH3(APTR, MyLockBitMapTagList,
69 AROS_UFHA(struct BitMap *, bitmap, A0),
70 AROS_UFHA(struct TagItem *, tags, A1),
71 AROS_UFHA(struct Library *, CyberGfxBase, A6))
73 AROS_USERFUNC_INIT
75 return NULL;
77 AROS_USERFUNC_EXIT
80 /****************************************************************************************/
82 AROS_ENTRY(LONG, PatchTask,
83 AROS_UFHA(char *, argstr, A0),
84 AROS_UFHA(ULONG, argsize, D0),
85 struct ExecBase *, SysBase)
87 AROS_USERFUNC_INIT
89 struct Library *CyberGfxBase;
90 struct MsgPort *port;
91 APTR orig_func;
93 /* Our process opens the library by itself in order to prevent it from being expunged */
94 CyberGfxBase = OpenLibrary("cybergraphics.library", 0);
95 if (!CyberGfxBase)
96 return 0;
98 port = CreateMsgPort();
99 if (port) {
100 port->mp_Node.ln_Name = PORT_NAME;
101 AddPort(port);
102 orig_func = SetFunction(CyberGfxBase, -28 * (WORD)LIB_VECTSIZE, MyLockBitMapTagList);
104 /* Just wait for a signal from the port. There's no need to look at message contents */
105 WaitPort(port);
106 SetFunction(CyberGfxBase, -28 * (WORD)LIB_VECTSIZE, orig_func);
107 RemPort(port);
108 DeleteMsgPort(port);
111 CloseLibrary(CyberGfxBase);
112 return 0;
114 AROS_USERFUNC_EXIT
117 /****************************************************************************************/
119 __startup static AROS_ENTRY(int, Start,
120 AROS_UFHA(char *, argstr, A0),
121 AROS_UFHA(ULONG, argsize, D0),
122 struct ExecBase *, SysBase)
124 AROS_USERFUNC_INIT
126 struct RDArgs *myargs;
127 IPTR args[NUM_ARGS] = {0};
128 int rc = RETURN_OK;
129 struct MsgPort *port;
130 struct CommandLineInterface *cli;
131 struct DosLibrary *DOSBase;
133 DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 36);
134 if (!DOSBase)
135 return RETURN_FAIL;
137 cli = Cli();
139 /* TODO: Is it possible to run without CLI? For example
140 if we were started via "Run command..."? */
141 if (!cli) {
142 PutStr("This program must be run from CLI\n");
143 CloseLibrary((struct Library *)DOSBase);
144 return RETURN_FAIL;
147 myargs = ReadArgs(ARG_TEMPLATE, args, 0);
148 if (myargs) {
149 port = FindPort(PORT_NAME);
151 if (args[ARG_PDBA]) {
152 if (port)
153 PutStr("Direct bitmap access already disabled\n");
154 else {
155 if (CreateNewProcTags(NP_Seglist, cli->cli_Module, NP_Entry, PatchTask, NP_Name, "GfxControl patch", TAG_DONE))
156 cli->cli_Module = BNULL;
157 else {
158 PrintFault(IoErr(), "GfxControl");
159 rc = RETURN_FAIL;
164 if (args[ARG_ADBA]) {
165 if (port) {
166 /* We do a very basic thing: just send a message. The message has no additional data
167 and therefore does not need to be freed. We even don't look at its contents in the
168 patch process */
169 struct Message msg;
171 PutMsg(port, &msg);
172 } else
173 PutStr("Direct bitmap access already enabled\n");
176 if (args[ARG_DUMP])
177 Printf("Prevent Direct BitMap Access: %s\n", port ? "YES" : "NO");
179 FreeArgs(myargs);
180 } else {
181 PrintFault(IoErr(), "GfxControl");
182 rc = RETURN_FAIL;
185 CloseLibrary((struct Library *)DOSBase);
186 return rc;
188 AROS_USERFUNC_EXIT