From 404855226cd0aa201bf887654af358436827248a Mon Sep 17 00:00:00 2001 From: izydorst Date: Sat, 15 Mar 2003 22:39:16 +0000 Subject: [PATCH] fixes for GEOS structures, initialized menu/icontabs finally are possible git-svn-id: svn://svn.cc65.org/cc65/trunk@2022 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- include/geos/gstruct.h | 24 +++++++++++++----------- samples/geos/menu.c | 21 +++++++++++++++++++-- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/include/geos/gstruct.h b/include/geos/gstruct.h index ad32290fd..e410ec3a5 100644 --- a/include/geos/gstruct.h +++ b/include/geos/gstruct.h @@ -5,6 +5,15 @@ 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 @@ -110,33 +119,26 @@ struct icondef { /* icon definition for DoIcons */ 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 diff --git a/samples/geos/menu.c b/samples/geos/menu.c index a6a6efd44..78751f8b2 100644 --- a/samples/geos/menu.c +++ b/samples/geos/menu.c @@ -15,6 +15,8 @@ void smenu3 (void); 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, @@ -22,9 +24,24 @@ static const menuString subMenu1 = { "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); + +}