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