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