by Maciej 'YTM/Elysium' Witkowiak
*/
+/*
+ apart from initializing data, structures below can be used to
+ speed up access to data and let cc65 to generate better code
+ e.g. if you have menu defined as TopMenu and you want to change the number of
+ menu items use:
+ ((struct menu*)&TopMenu)->number=newNumber;
+ This will translate into single lda/sta pair
+*/
+
#ifndef _GSTRUCT_H
#define _GSTRUCT_H
struct icontab {
char number; /* number of declared icons */
struct pixel mousepos; /* position of mouse after DoIcons */
- struct icondef *tab; /* table of size declared by icontab.number */
+ struct icondef tab[]; /* table of size declared by icontab.number */
};
-/*
- structures below might be used to speed up access to own menus
- e.g. if you have menu defined as TopMenu and you want to change the number of
- menu items use:
- ((struct menu*)&TopMenu)->number=newNumber;
- This will allow cc65 to emit better code.
-*/
struct menuitem {
char *name;
char type;
- int rest; /* may be ptr to function, or if submenu ptr to struct menu */
+ void *rest; /* may be ptr to function, or ptr to struct menu (submenu) */
};
struct menu {
struct window size;
char number;
- struct menuitem *items;
+ struct menuitem items[];
};
struct inittab { /* use struct inittab mytab[n] for initram */
int ptr; /* ptr to 1st byte */
char number; /* number of following bytes */
- char *values; /* actual string of bytes */
+ char values[]; /* actual string of bytes */
};
#endif
typedef void menuString;
+/* you can declare a menu using cc65 non-ANSI extensions */
+
static const menuString subMenu1 = {
(char)0, (char)(3*15),
(unsigned)0, (unsigned)50,
"subitem1", (char)MENU_ACTION, (unsigned)smenu1,
"subitem2", (char)MENU_ACTION, (unsigned)smenu2,
"subitem3", (char)MENU_ACTION, (unsigned)smenu3
- };
+ };
+
+/* or by using initialized structures */
+
+static struct menu subMenu2 = {
+ { 0, 3*15, 0, 50 },
+ 3 | VERTICAL,
+ {
+ { "subitem1", MENU_ACTION, smenu1 },
+ { "subitem2", MENU_ACTION, smenu2 },
+ { "subitem3", MENU_ACTION, smenu3 },
+ }
+ };
void main (void)
{
+
DoMenu(&subMenu1);
- }
+ DoMenu(&subMenu2);
+
+}