]> git.sur5r.net Git - cc65/blob - doc/grc.sgml
Since we have now builtin search paths, we need to be able to forget them,
[cc65] / doc / grc.sgml
1 <!doctype linuxdoc system>
2 <article>
3
4 <!-- Title information -->
5
6 <title>grc -- GEOS Resource Compiler
7 <author><url name="Maciej 'YTM/Elysium' Witkowiak" url="mailto:ytm@elysium.pl">
8 <and><url name="Greg King" url="mailto:gngking@erols.com">
9 <date>VII 2000; VI,VII 2002; 2005-8-3
10 <abstract>
11 This document describes a compiler that can create GEOS headers and menues for,
12 and VLIR files from, cc65-compiled programs.
13 </abstract>
14
15 <!-- Table of contents -->
16 <toc>
17
18 <!-- Begin the document -->
19
20 <sect>Overview
21 <p><bf/grc/ is a part of cc65's GEOS support.  The tool is necessary to
22 generate required and optional resources.  A required resource for every GEOS
23 application is the header, that is:  an icon, some strings, and some addresses.
24 Optional resources might be menu definitions, other headers (e.g., for data
25 files of an app.), dialog definitions, etc.  Without an application's header,
26 GEOS is unable to load and start it.
27
28 Currently, <bf/grc/ supports only menues and the required header definition,
29 along with support for building VLIR-structured files.
30
31 <bf/grc/ generates output in three formats:  C header, <bf/ca65/ source (.s),
32 and, for linking VLIR, <bf/ld65/ configuration script.  That is because
33 application header data must be in assembly format, while menu definitions can
34 be translated easily into C.  The purpose of the C file is to include it as a
35 header in only one project file.  The assembly source should be processed by
36 <bf/ca65/, and linked as the first object (read about <ref
37 name="the building process" id="building-seq">).  The VLIR structure currently
38 is supported for only projects that are written entirely in assembly code.
39
40 <bf/grc/ can be used also as a handy VLIR linker -- used to build
41 VLIR-structured <tt/.cvt/ files out of prepared binary chains.
42
43
44
45 <sect>Usage
46 <p>grc accepts the following options:<tscreen><verb>
47 -f         force the writing of the output files
48 -o name    name the .c output file
49 -s name    name the .s output file
50 -l name    name the ld65 output file
51 -h         show this help
52 </verb></tscreen>
53 When used as a VLIR linker, the correct syntax is:<tscreen><verb>
54  grc -vlir output.cvt header.bin vlir0.bin vlir1.bin ...
55 </verb></tscreen>
56 Default output names are made from input names with extensions replaced by
57 <tt/.h/ and <tt/.s/.  <bf/grc/ will not overwrite existing files unless forced
58 to do so.  That is done to avoid situations where you have <tt/test.c/ and
59 <tt/test.grc/ files.  Both would put their output into <tt/test.s/.  For that
60 reason, you should name your resource-files differently than sources, e.g.,
61 <tt/resource.grc/ or <tt/apphead.grc/.
62
63
64
65 <sect>Resource file format
66 <p>A resource file has the name extension <tt/.grc/.  That is not required, but
67 it will make for an easier recognition of the file's purpose.  Also, <bf/cl65/
68 recognizes those files.  <bf/grc/'s parser is very weak, at the moment; so,
69 read the comments carefully, and write resources exactly as they are written
70 here.  Look out for CAPS. and small letters.  Everything after a '<tt/;/',
71 until the end of the line, is considered as a comment, and ignored.  See the
72 included <ref name="commented example .grc file" id="example-grc"> for a
73 better view of the problem.
74
75
76 <sect1>Menu definition
77 <p><tscreen><verb>
78 MENU menuName leftx,topy <ORIENTATION> {
79     "item name 1" <MENU_TYPE> pointer
80     ...
81     "item name x" <MENU_TYPE> pointer
82 }</verb></tscreen>
83 The definition starts with the keyword <tt/MENU/, then goes the menu's name,
84 which will be represented in C as <tt/const void/.  Then are the co-ordinates
85 of the top left corner of the menu box.  The position of the bottom right
86 corner is estimated, based on the length of item names and the menu's
87 orientation.  It means that the menu box always will be as large as it should
88 be.  Then, there's the orientation keyword; it can be either <tt/HORIZONTAL/ or
89 <tt/VERTICAL/.  Between <tt/&lcub;/ and <tt/&rcub;/, there's the menu's
90 content.  It consists of item definitions.  First is an item name -- it has to
91 be in quotes.  Next is a menu-type bit.  It can be <tt/MENU_ACTION/ or
92 <tt/SUB_MENU/; either of them can be combined with the <tt/DYN_SUB_MENU/ bit
93 (see <url name="the GEOSLib documentation" url="geos.html"> for descriptions of
94 them).  You can use C logical operators in expressions, but you have to do it
95 without spaces.  So, a dynamically created submenu will be something like:
96 <tscreen><verb>
97 "dynamic" SUB_MENU|DYN_SUB_MENU create_dynamic</verb></tscreen>
98 The last part of the item definition is a pointer which can be any name that is
99 present in the C source code that includes the generated header.  It can point
100 to a function or to another menu definition.
101
102 If you are doing sub(sub)menu definitions, remember to place the lowest level
103 definition first, and the top-level menu as the last one.  That way, the C
104 compiler won't complain about unknown names.
105
106
107 <sect1>Header definition
108 <p><tscreen><verb>
109 HEADER <GEOS_TYPE> "dosname" "classname" "version" {
110     author    "Joe Schmoe"
111     info      "This is my killer-app!"
112     date      yy mm dd hh ss
113     dostype   SEQ
114     mode      any
115     structure SEQ
116 }</verb></tscreen>
117 The header definition describes the GEOS header sector which is unique to
118 each file.  Currently, there's no way to change the default <bf/grc/ icon
119 (an empty frame).  It will be possible in the next version.  The definition
120 starts with the keyword <tt/HEADER/, then goes the GEOS file-type.  You can use
121 only <tt/APPLICATION/ here at the moment.  Then, there are (each one in quotes)
122 the DOS file-name (up to 16 characters), the GEOS Class name (up to 12
123 characters), and the version info (up to 4 characters).  The version should be
124 written as &dquot;<tt/V/x.y&dquot;, where <em/x/ is the major, and <em/y/ is
125 the minor, version number.  Those fields, along with both braces, are required.
126 The lines between braces are optional, and will be replaced by default and
127 current values.  The keyword <tt/author/ and its value in quotes name the
128 programmer, and can be up to 63 bytes long.  <tt/info/ (in the same format) can
129 have up to 95 characters.  If the <tt/date/ field is omitted, then the time of
130 that compilation will be placed into the header.  Note that, if you do specify
131 the date, you have to write all 5 numbers.  The <tt/dostype/ can be <tt/SEQ/,
132 <tt/PRG/, or <tt/USR/.  <tt/USR/ is used by default; GEOS usually doesn't care.
133 The <tt/mode/ can be <tt/any/, <tt/40only/, <tt/80only/, or <tt/c64only/; and,
134 it describes system requirements.  <tt/any/ will work on both 64-GEOS and
135 128-GEOS, in 40- and 80-column modes.  <tt/40only/ will work on 128-GEOS in
136 40-column mode only.  <tt/80only/ will work on only 128-GEOS in 80-column mode,
137 and <tt/c64only/ will work on only 64-GEOS.  The default value for
138 <tt/structure/ is <tt/SEQ/ (sequential).  You can put <tt/VLIR/ there, too; but
139 then, you also have to put in a third type of resource -- a VLIR-table
140 description.
141
142
143 <sect1>VLIR table description
144 <p><tscreen><verb>
145 VLIR headname address {
146     vlir0
147     blank
148     vlir2
149     blank
150     vlir4
151 }</verb></tscreen>
152 The first element is the keyword <tt/VLIR/, then goes the name for the header
153 binary file (read below), and the base address for all VLIR chains that are
154 different from 0.  It can be either decimal (e.g., <tt/4096/) or hexadecimal
155 with a <tt/0x/ prefix (e.g., <tt/0x1000/).  Then, between braces are the names
156 of VLIR chain binaries or the keyword <tt/blank/ which denotes empty chains.
157 In the example, chains #1 and #3 are missing.  The names between braces are
158 the names of binaries that contain code for each VLIR part.  They matter only
159 for the generated <bf/ld65/ configuration file, and will be the names of the
160 resulting binary files after linking.  Each one will contain one VLIR chain;
161 and, they will have to be put together, in the correct order, into a VLIR
162 <tt/.cvt/ file, by <bf/grc/ in its VLIR linker mode.
163
164 The <tt/headname/ will be the name for the binary file which will contain only
165 a GEOS <tt/.cvt/ header made out of compiling the <tt/.s/ header file that also
166 was generated by <bf/grc/.  At the end of the resulting <bf/ld65/ config. file
167 (<tt/.cfg/), in comments, there will be information about what commands are
168 required for putting the stuff together.  Read <ref name="this description"
169 id="building-vlir"> for details.
170
171
172
173 <sect>Building a GEOS sequential application<label id="building-seq">
174 <p>Before proceeding, please read the <url name="compiler" url="cc65.html">,
175 <url name="assembler" url="ca65.html">, and <url name="linker" url="ld65.html">
176 documentation, and find the appropriate sections about building programs, in
177 general.
178
179 GEOS support in cc65 is based on the <em/Convert v2.5/ format, well-known in
180 the GEOS world.  It means that each file built with the cc65 package has to be
181 deconverted, in GEOS, before it can be run.  You can read a step-by-step
182 description of that in the GEOS section of the <url name="cc65 Compiler Intro"
183 url="intro.html">.
184
185 Each project consists of four parts, two are provided by cc65.  Those parts
186 are:<enum>
187 <item>application header
188 <item>start-up object
189 <item>application objects
190 <item>system library
191 </enum>
192 <bf/2./ and <bf/4./ are with cc65; you have to write the application,
193 yourself. ;-)
194
195 The application header is defined in the <tt/HEADER/ section of the <tt/.grc/
196 file, and processed into an assembly <tt/.s/ file.  You must assemble it, with
197 <bf/ca65/, into the object <tt/.o/ format.
198
199
200 <sect1>Building a GEOS application without cl65
201 <p>Assume that there are three input files:  &dquot;<tt/test.c/&dquot; (a C
202 source), &dquot;<tt/test.h/&dquot; (a header file), and
203 &dquot;<tt/resource.grc/&dquot; (with menu and header definitions).  Note the
204 fact that I <em/don't recommend/ naming that file &dquot;<tt/test.grc/&dquot;,
205 because you will have to be very careful with names (<bf/grc/ will make
206 &dquot;<tt/test.s/&dquot; and &dquot;<tt/test.h/&dquot; out of
207 &dquot;<tt/test.grc/&dquot;, by default; and, you don't want that because
208 &dquot;<tt/test.s/&dquot; is compiled from &dquot;<tt/test.c/&dquot;, and
209 &dquot;<tt/test.h/&dquot; is something completely different)!
210
211 <bf/One important thing/ -- the top of &dquot;<tt/test.c/&dquot; looks like:
212 <tscreen><verb>
213 #include <geos.h>
214 #include "resource.h"
215 </verb></tscreen>
216 There are no other includes.
217
218 <sect2>First step -- compiling the resources
219 <p><verb>
220 $ grc resource.grc
221 </verb>
222 will produce two output files:  &dquot;<tt/resource.h/&dquot; and
223 &dquot;<tt/resource.s/&dquot;.
224
225 Note that &dquot;<tt/resource.h/&dquot; is included at the top of
226 &dquot;<tt/test.c/&dquot;.  So, resource compiling <em/must be/ the first step.
227
228 <sect2>Second step -- assembling the application header
229 <p><verb>
230 $ ca65 -t geos resource.s
231 </verb>
232 And, voil&aacute; -- &dquot;<tt/resource.o/&dquot; is ready.
233
234 <sect2>Third step -- compiling the code
235 <p><verb>
236 $ cc65 -t geos -O test.c
237 $ ca65 -t geos test.s
238 </verb>
239 That way, you have a &dquot;<tt/test.o/&dquot; object file which
240 contains all of the executable code.
241
242 <sect2>Fourth and last step -- linking it together
243 <p><verb>
244 $ ld65 -t geos -o test.cvt resource.o geos.o test.o geos.lib
245 </verb>
246 &dquot;<tt/resource.o/&dquot; comes first because it contains the
247 header.  The next one is &dquot;<tt/geos.o/&dquot;, a required starter-code
248 file; then, the actual application code in &dquot;<tt/test.o/&dquot;, and the
249 last is the GEOS system library.
250
251 The resulting file &dquot;<tt/test.cvt/&dquot; is an executable that's
252 contained in the well-known GEOS <em/Convert/ format.  Note that it's name
253 (<tt/test/) isn't important; the real name, after deconverting, is the DOS name
254 that was given in the header definition.
255
256 At each step, a <tt/-t geos/ was present on the command-line.  That switch is
257 required for the correct process of GEOS sequential app. building.
258
259
260
261 <sect>Building a GEOS VLIR application<label id="building-vlir">
262 <p>Currently, you can build VLIR applications only if your code is written in
263 assembly -- no C code allowed.
264
265 In your sources, only the command <tt/.segment &dquot;/<em/NAME/<tt/&dquot;/
266 will decide which code/data goes where.  File-names don't matter.  Segments
267 <tt/CODE/, <tt/RODATA/, <tt/DATA/, and <tt/BSS/ go into VLIR part #0.  Segment
268 <tt/VLIR1/ goes into VLIR part #1, <tt/VLIR2/ goes into VLIR part #2, and so
269 on.
270
271 The GEOS resource file's contents are similar to <ref
272 name="the sequential-file example" id="building-seq">, but there also is a
273 <tt/VLIR/ section and a <tt/structure VLIR/ tag.  Here is that part:<tscreen>
274 <verb>
275 VLIR vlir-head.bin 0x3000 {
276   vlir-0.bin    ; CODE, RODATA, DATA, BSS
277   vlir-1.bin    ; VLIR1
278   vlir-2.bin    ; VLIR2
279 }</verb></tscreen>
280 (Source files are only <tt/.s/.)
281
282 OK, we have &dquot;<tt/cvthead.grc/&dquot;, so let's allow <bf/grc/ to compile
283 it:<verb>
284 $ grc cvthead.grc
285 </verb>
286 Now, there are two new files:  &dquot;<tt/cvthead.cfg/&dquot; and
287 &dquot;<tt/cvthead.s/&dquot; -- the first one is a config. file for <bf/ld65/,
288 and the second one contains the GEOS <tt/.cvt/ header.  It can be assembled:
289 <verb>
290 $ ca65 -t geos cvthead.s
291 </verb>
292 Now, we have &dquot;<tt/cvthead.o/&dquot;.  The rest of the assembly
293 sources can be assembled:<verb>
294 $ ca65 -t geos vlir0.s
295 $ ca65 -t geos vlir1.s
296 $ ca65 -t geos vlir2.s
297 </verb>
298 Note that the file-names here, although similar to those from the
299 <tt/VLIR/ section of the <tt/.grc/ file, are not significant.  The only thing
300 that matters is which code will go into which segment.
301
302 Now, we can generate binaries.  This time, the order of the arguments on the
303 command-line is not important.<verb>
304 $ ld65 -C cvthead.cfg vlir1.o cvthead.o vlir0.o vlir2.o
305 </verb>
306 As defined in the <tt/.grc/ file, we now have the binary parts of the
307 VLIR file:  &dquot;<tt/vlir-head.bin/&dquot;, &dquot;<tt/vlir-0.bin/&dquot;,
308 &dquot;<tt/vlir-1.bin/&dquot;, and &dquot;<tt/vlir-2.bin/&dquot;.
309
310 The last step is to put them together in the right order -- the order of the
311 arguments <em/is important/ this time!  As suggested in the comments at the end
312 of &dquot;<tt/cvthead.cfg/&dquot;, we do:<verb>
313 $ grc -vlir output.cvt vlir-head.bin vlir-0.bin vlir-1.bin vlir-2.bin
314 </verb>
315 That is the end.  The file &dquot;<tt/output.cvt/&dquot; can be
316 deconverted under GEOS.  Note that <tt/-C cvthead.cfg/ was used on the
317 <bf/ld65/ command-line instead of the switch <tt/-t geos/.
318
319
320
321 <sect>Bugs and feedback
322 <p>This is the first release of <bf/grc/, and it contains bugs, for sure!  I am
323 aware of them; I know that the parser is weak, and if you don't follow the
324 grammar rules strictly, then everything will crash.  However, if you find an
325 interesting bug, mail me. :-)  Mail me also for help with writing your
326 <tt/.grc/ file correctly if you have problems with it.  I would appreciate
327 comments also, and help on this file because I am sure that it can be written
328 better.
329
330
331
332 <sect>Legal stuff
333 <p><bf/grc/ is covered by the same license as the whole cc65 package, so you
334 should see its documentation for more info.  Anyway, if you like it, and want
335 to encourage me to work more on it, send me a postcard with a sight of your
336 neighbourhood, city, region, etc.  Or, just e-mail me with info that you
337 actually used it.  See <url name="the GEOSLib documentation" url="geos.html">
338 for addresses.
339
340
341
342 <appendix>
343 <sect>Appendix A -- example.grc<label id="example-grc">
344 <p><tscreen><verb>
345 ; Note that MENU can define both menues and submenues.
346 ; If you want to use any C operators (such as "|", "&", etc.), do it WITHOUT
347 ; any spaces between the arguments (the parser is simple and weak).
348
349 MENU subMenu1 15,0 VERTICAL
350 ; This is a vertical menu, placed at (15,0).
351 {
352 ; There are three items, all of them will call functions.
353 ; The first and third ones are normal functions, see GEOSLib documentation for
354 ; information about what the second function should return (it's a dynamic one).
355     "subitem1" MENU_ACTION smenu1
356     "subitem2" MENU_ACTION|DYN_SUB_MENU smenu2
357     "subitem3" MENU_ACTION smenu3
358 }
359
360 ;; Format:  MENU "name" left,top ALIGN { "itemname" TYPE pointer ... }
361
362 MENU mainMenu 0,0 HORIZONTAL
363 ; Here, we have our main menu, placed at (0,0), and it is a horizontal menu.
364 ; Because it is a top-level menu, you would register it in your C source by
365 ; using:  DoMenu(&ero;mainMenu);
366 {
367 ; There are two items -- a submenu and an action.
368 ; This calls a submenu named subMenu1 (see previous definition).
369     "first sub-menu" SUB_MENU subMenu1
370 ; This will work the same as an EnterDeskTop() call in C source code.
371     "quit" MENU_ACTION EnterDeskTop
372 }
373
374 ;; Format:  HEADER <GEOS_TYPE> "dosname" "classname" "version"
375
376 HEADER APPLICATION "MyFirstApp" "Class Name" "V1.0"
377 ; This is a header for an APPLICATION which will be seen in the directory as a
378 ; file named MyFirstApp with the Class-string "Class Name V1.0"
379 {
380 ; Not all fields are required, default and current values will be used.
381     author "Maciej Witkowiak"   ; always in quotes!
382     info "Information text"     ; always in quotes!
383 ;    date yy mm dd hh ss        ; always 5 fields!
384 ;    dostype seq                ; can be:  PRG, SEQ, USR (only all UPPER- or lower-case)
385 ;    structure seq              ; can be:  SEQ, VLIR (only UPPER- or lower-case)
386     mode c64only                ; can be:  any, 40only, 80only, c64only
387 }</verb></tscreen>
388 </article>