]> git.sur5r.net Git - cc65/blob - doc/grc65.sgml
Support for "virtual operands" of subroutines like this:
[cc65] / doc / grc65.sgml
1 <!doctype linuxdoc system>
2 <article>
3
4 <!-- Title information -->
5
6 <title>grc65 -- GEOS Resource Compiler
7 <author>
8 <url url="mailto:ytm@elysium.pl" name="Maciej 'YTM/Elysium' Witkowiak">,<newline>
9 <url url="mailto:greg.king5@verizon.net" name="Greg King">
10 <date>2014-04-24
11 <abstract>
12 This document describes a compiler that can create GEOS headers and menues for
13 cc65-compiled programs.
14 </abstract>
15
16 <!-- Table of contents -->
17 <toc>
18
19 <!-- Begin the document -->
20
21 <sect>Overview
22 <p><bf/grc65/ is a part of cc65's GEOS support.  The tool is necessary to
23 generate required and optional resources.  A required resource for every GEOS
24 application is the header, that is:  an icon, some strings, and some addresses.
25 Optional resources might be menu definitions, other headers (e.g., for data
26 files of an app.), dialog definitions, etc.  Without an application's header,
27 GEOS is unable to load and start it.
28
29 Currently, <bf/grc65/ supports only menues and the required header definition,
30 along with support for building applications with VLIR-structured overlays.
31
32 <bf/grc65/ generates output in two formats: C header and <bf/ca65/ source (.s).
33 That is because the application header data must be in assembly format, while
34 the menu definitions can be translated easily into C.  The purpose of the C
35 file is to include it as a header in only one project file.  The assembly source
36 should be processed by <bf/ca65/ and linked to the application (read about
37 <ref name="the building process" id="building-seq">).
38
39
40
41 <sect>Usage
42 <p>grc65 accepts the following options:
43
44 <tscreen><verb>
45 ---------------------------------------------------------------------------
46 Usage: grc65 [options] file
47 Short options:
48   -V                    Print the version number
49   -h                    Help (this text)
50   -o name               Name the C output file
51   -s name               Name the asm output file
52   -t sys                Set the target system
53
54 Long options:
55   --help                Help (this text)
56   --target sys          Set the target system
57   --version             Print the version number
58 ---------------------------------------------------------------------------
59 </verb></tscreen>
60 Default output names are made from input names with extensions replaced by
61 <tt/.h/ and <tt/.s/.
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/grc65/'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 situation.
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 comes 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     icon      "sprite.raw"
117 }</verb></tscreen>
118 The header definition describes the GEOS header sector which is unique to
119 each file.  The definition starts with the keyword <tt/HEADER/, then goes the
120 GEOS file-type.  You can use only <tt/APPLICATION/ here at the moment.  Then,
121 there are (each one in quotes) the DOS file-name (up to 16 characters), the GEOS
122 Class name (up to 12 characters), and the version info (up to 4 characters).
123 The version should be written as &dquot;<tt/V/x.y&dquot;, where <em/x/ is the
124 major, and <em/y/ is the minor, version number.  Those fields, along with both
125 braces, are required.  The lines between braces are optional, and will be replaced
126 by default and current values.  The keyword <tt/author/ and its value in quotes name
127 the programmer, and can be up to 63 bytes long.  <tt/info/ (in the same format) can
128 have up to 95 characters.  If the <tt/date/ field is omitted, then the time of
129 that compilation will be placed into the header.  Note that, if you do specify
130 the date, you have to write all 5 numbers.  The <tt/dostype/ can be <tt/SEQ/,
131 <tt/PRG/, or <tt/USR/.  <tt/USR/ is used by default; GEOS usually doesn't care.
132 The <tt/mode/ can be <tt/any/, <tt/40only/, <tt/80only/, or <tt/c64only/; and,
133 it describes system requirements.  <tt/any/ will work on both 64-GEOS and
134 128-GEOS, in 40- and 80-column modes.  <tt/40only/ will work on 128-GEOS in
135 40-column mode only.  <tt/80only/ will work on only 128-GEOS in 80-column mode,
136 and <tt/c64only/ will work on only 64-GEOS.  The default value for
137 <tt/structure/ is <tt/SEQ/ (sequential).  You can put <tt/VLIR/ there, too; but
138 then, you also have to put in a third type of resource -- a memory definition.
139 The value of <tt/icon/ is a quoted file-name.  The first 63 bytes of this file
140 are expected to represent a standard monochrome VIC sprite.  The file gets accessed
141 when the generated assembly source is being processed by <bf/ca65/.  Examples for
142 programs generating such files are <em/Sprite Painter/, <em/SpritePad/ and the
143 <url name="sp65 sprite and bitmap utility" url="sp65.html">.  The default <tt/icon/
144 is an empty frame internally represented in the generated assembly file.
145
146
147 <sect1>Memory definition
148 <p><tscreen><verb>
149 MEMORY {
150     stacksize   0x0800
151     overlaysize 0x2000
152     overlaynums 0 1 2 4 5
153 }</verb></tscreen>
154 The memory definition is unique to each file and describes several attributes related
155 to the memory layout.  It consists of the keyword <tt/MEMORY/ followed by braces which
156 contain optional lines.  The value of <tt/stacksize/ can be either decimal (e.g.
157 <tt/4096/) or hexadecimal with a <tt/0x/ prefix (e.g. <tt/0x1000/).  The default value
158 of 0x400 comes from the linker configuration file. The value of <tt/backbuffer/ can be
159 either <tt/yes/ or <tt/no/. The further means that the application uses the system-supplied
160 background screen buffer while the latter means that the program uses the memory of the
161 background screen buffer for own purposes.  The default value of <tt/yes/ comes from the
162 linker configuration file.  If the <tt/structure/ in the header definition is set to the
163 value <tt/VLIR/ then it is possible and necessary to provide here the attributes of the
164 VLIR overlays. <tt/overlaysize/ defines the maximal size for all VLIR records but number
165 0.  It can be either decimal (e.g. <tt/4096/) or hexadecimal with a <tt/0x/ prefix (e.g.
166 <tt/0x1000/).  <tt/overlaynums/ defines the VLIR record numbers used by the application.
167 Skipped numbers denote empty records.  In the example, record number 3 is missing.  Read
168 <ref name="this description" id="building-vlir"> for details.
169
170
171
172 <sect>Building a GEOS sequential application<label id="building-seq">
173 <p>Before proceeding, please read the <url name="compiler" url="cc65.html">,
174 <url name="assembler" url="ca65.html">, and <url name="linker" url="ld65.html">
175 documentation, and find the appropriate sections about building programs, in
176 general.
177
178 GEOS support in cc65 is based on the <em/Convert v2.5/ format, well-known in
179 the GEOS world.  It means that each file built with the cc65 package has to be
180 deconverted in GEOS, before it can be run.  You can read a step-by-step
181 description of that in the <url name="GEOS section of the cc65 Compiler Intro"
182 url="intro.html#ss6.5">.
183
184 Each project consists of four parts, two are provided by cc65.  Those parts
185 are:<enum>
186 <item>application header
187 <item>start-up object
188 <item>application objects
189 <item>system library
190 </enum>
191 <bf/2./ and <bf/4./ come with cc65; however you have to write the application
192 yourself ;-)
193
194 The application header is defined in the <tt/HEADER/ section of the <tt/.grc/
195 file and is processed into an assembly <tt/.s/ file.  You must assemble it, with
196 <bf/ca65/, into the object <tt/.o/ format.
197
198 Assume that there are three input files:  &dquot;<tt/test.c/&dquot; (a C
199 source), &dquot;<tt/test.h/&dquot; (a header file), and
200 &dquot;<tt/testres.grc/&dquot; (with menu and header definitions).  Note the
201 fact that I <em/don't recommend/ naming that file &dquot;<tt/test.grc/&dquot;
202 because you will have to be very careful with names (<bf/grc65/ will make
203 &dquot;<tt/test.s/&dquot; and &dquot;<tt/test.h/&dquot; out of
204 &dquot;<tt/test.grc/&dquot; by default; and you don't want that because
205 &dquot;<tt/test.s/&dquot; is compiled from &dquot;<tt/test.c/&dquot;, and
206 &dquot;<tt/test.h/&dquot; is something completely different)!
207
208 <bf/One important thing/ -- the top of &dquot;<tt/test.c/&dquot; looks like:
209 <tscreen><verb>
210 #include <geos.h>
211 #include "testres.h"
212 </verb></tscreen>
213 There are no other includes.
214
215
216 <sect1>Building the GEOS application using cl65
217 <p>This is a simple one step process:
218 <tscreen><verb>
219 cl65 -t geos-cbm -O -o test.cvt testres.grc test.c
220 </verb></tscreen>
221 Always place the <tt/.grc/ file as first input file on the command-line in order
222 to make sure that the generated <tt/.h/ file is available when it is needed for
223 inclusion by a <tt/.c/ file.
224
225
226 <sect1>Building the GEOS application without cl65
227 <sect2>First step -- compiling the resources
228 <p>
229 <tscreen><verb>
230 grc65 -t geos-cbm testres.grc
231 </verb></tscreen>
232 will produce two output files:  &dquot;<tt/testres.h/&dquot; and
233 &dquot;<tt/testres.s/&dquot;.
234
235 Note that &dquot;<tt/testres.h/&dquot; is included at the top of
236 &dquot;<tt/test.c/&dquot;.  So, resource compiling <em/must be/ the first step.
237
238 <sect2>Second step -- assembling the application header
239 <p>
240 <tscreen><verb>
241 ca65 -t geos-cbm testres.s
242 </verb></tscreen>
243 And, voil&aacute; -- &dquot;<tt/testres.o/&dquot; is ready.
244
245 <sect2>Third step -- compiling the code
246 <p>
247 <tscreen><verb>
248 cc65 -t geos-cbm -O test.c
249 ca65 -t geos-cbm test.s
250 </verb></tscreen>
251 That way, you have a &dquot;<tt/test.o/&dquot; object file which
252 contains all of the executable code.
253
254 <sect2>Fourth and last step -- linking the application
255 <p>
256 <tscreen><verb>
257 ld65 -t geos-cbm -o test.cvt testres.o test.o geos-cbm.lib
258 </verb></tscreen>
259 The last file is the GEOS system library.
260
261 The resulting file &dquot;<tt/test.cvt/&dquot; is an executable that's
262 contained in the well-known GEOS <em/Convert/ format.  Note that its name
263 (<tt/test.cvt/) isn't important; the real name, after deconverting, is the DOS name
264 that was given in the header definition.
265
266 At each step, a <tt/-t geos-cbm/ was present on the command-line.  That switch is
267 required for the correct process of GEOS sequential application building.
268
269
270
271 <sect>Building a GEOS VLIR overlay application<label id="building-vlir">
272 <p>Large GEOS applications typically don't fit in one piece in their designated
273 memory area.  They are therefore split into overlays which are loaded into memory
274 on demand.  The individual overlays are stored as records of a VLIR (Variable
275 Length Index Record) file.  When GEOS starts a VLIR overlay appliation it loads
276 record number 0 which is supposed to contain the main program.  The record numbers
277 starting with 1 are to be used for the actual overlays.
278
279 In "<tt>cc65/samples/geos</tt>" there's a VLIR overlay demo application consisting
280 of the files "<tt/overlay-demo.c/" and "<tt/overlay-demores.grc/".
281
282
283 <sect1>Building the GEOS overlay application using cl65
284 <p>This is a simple one step process:
285 <tscreen><verb>
286 cl65 -t geos-cbm -O -o overlay-demo.cvt -m overlay-demo.map overlay-demores.grc overlay-demo.c
287 </verb></tscreen>
288 Always place the <tt/.grc/ file as first input file on the command-line in order
289 to make sure that the generated <tt/.h/ file is available when it is needed for
290 inclusion by a <tt/.c/ file.
291
292 You will almost certainly want to generate a map file that shows (beside a lot of
293 other infos) how large your individual overlays are.  This info is necessary to tune
294 the distribution of code into the overlays and to optimize the memory area reserved
295 for the overlays.
296
297
298 <sect1>Building the GEOS overlay application without cl65
299 <sect2>First step -- compiling the overlay resources
300 <p>
301 <tscreen><verb>
302 grc65 -t geos-cbm overlay-demores.grc
303 </verb></tscreen>
304
305 <sect2>Second step -- assembling the overlay application header
306 <p>
307 <tscreen><verb>
308 ca65 -t geos-cbm overlay-demores.s
309 </verb></tscreen>
310
311 <sect2>Third step -- compiling the overlay code
312 <p>
313 <tscreen><verb>
314 cc65 -t geos-cbm -O overlay-demo.c
315 ca65 -t geos-cbm overlay-demo.s
316 </verb></tscreen>
317
318 <sect2>Fourth and last step -- linking the overlay application
319 <p>
320 <tscreen><verb>
321 ld65 -t geos-cbm -o overlay-demo.cvt -m overlay-demo.map overlay-demores.o overlay-demo.o geos-cbm.lib
322 </verb></tscreen>
323
324
325
326 <sect>Bugs and feedback
327 <p>This is the first release of <bf/grc65/, and it contains bugs, for sure!  I
328 am aware of them; I know that the parser is weak, and if you don't follow the
329 grammar rules strictly, then everything will crash.  However, if you find an
330 interesting bug, mail me. :-) Mail me also for help with writing your
331 <tt/.grc/ file correctly if you have problems with it.  I would appreciate
332 comments also, and help on this file because I am sure that it can be written
333 better.
334
335
336
337 <sect>Legal stuff
338 <p><bf/grc65/ is covered by the same license as the whole cc65 package, so you
339 should see its documentation for more info.  Anyway, if you like it, and want
340 to encourage me to work more on it, send me a postcard with a sight of your
341 neighbourhood, city, region, etc.  Or, just e-mail me with info that you
342 actually used it.  See <url name="the GEOSLib documentation" url="geos.html">
343 for addresses.
344
345
346
347 <!-- <appendix> -->
348 <sect>Appendix A -- example.grc<label id="example-grc">
349 <p><tscreen><verb>
350 ; Note that MENU can define both menues and submenues.
351 ; If you want to use any C operators (such as "|", "&", etc.), do it WITHOUT
352 ; any spaces between the arguments (the parser is simple and weak).
353
354 MENU subMenu1 15,0 VERTICAL
355 ; This is a vertical menu, placed at (15,0).
356 {
357 ; There are three items, all of them will call functions.
358 ; The first and third ones are normal functions, see GEOSLib documentation for
359 ; information about what the second function should return (it's a dynamic one).
360     "subitem1" MENU_ACTION smenu1
361     "subitem2" MENU_ACTION|DYN_SUB_MENU smenu2
362     "subitem3" MENU_ACTION smenu3
363 }
364
365 ;; Format:  MENU "name" left,top ALIGN { "itemname" TYPE pointer ... }
366
367 MENU mainMenu 0,0 HORIZONTAL
368 ; Here, we have our main menu, placed at (0,0), and it is a horizontal menu.
369 ; Because it is a top-level menu, you would register it in your C source by
370 ; using:  DoMenu(&ero;mainMenu);
371 {
372 ; There are two items -- a submenu and an action.
373 ; This calls a submenu named subMenu1 (see previous definition).
374     "first sub-menu" SUB_MENU subMenu1
375 ; This will work the same as an EnterDeskTop() call in C source code.
376     "quit" MENU_ACTION EnterDeskTop
377 }
378
379 ;; Format:  HEADER <GEOS_TYPE> "dosname" "classname" "version"
380
381 HEADER APPLICATION "MyFirstApp" "Class Name" "V1.0"
382 ; This is a header for an APPLICATION which will be seen in the directory as a
383 ; file named MyFirstApp with the Class-string "Class Name V1.0"
384 {
385 ; Not all fields are required, default and current values will be used.
386     author "Maciej Witkowiak"   ; always in quotes!
387     info "Information text"     ; always in quotes!
388 ;    date yy mm dd hh ss        ; always 5 fields!
389 ;    dostype seq                ; can be:  PRG, SEQ, USR (only all UPPER- or lower-case)
390 ;    structure seq              ; can be:  SEQ, VLIR (only UPPER- or lower-case)
391     mode c64only                ; can be:  any, 40only, 80only, c64only
392 }</verb></tscreen>
393 </article>