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