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