From ca2ba14bbe1da347591a6eccbe8277d82ac55a5a Mon Sep 17 00:00:00 2001 From: "ol.sc" Date: Sun, 4 Nov 2012 22:01:51 +0000 Subject: [PATCH] Added option to build samples with statically linked drivers - and have the targets use it by default which don't support dynamically loaded drivers. git-svn-id: svn://svn.cc65.org/cc65/trunk@5913 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- include/atmos.h | 46 ++++++++++++---------- include/lynx.h | 16 ++++---- include/nes.h | 57 ++++++++++++++------------- samples/mandelbrot.c | 91 ++++++++++++++++++++++++-------------------- samples/mousedemo.c | 25 ++++++++++-- samples/tgidemo.c | 34 ++++++++++++----- 6 files changed, 156 insertions(+), 113 deletions(-) diff --git a/include/atmos.h b/include/atmos.h index 8155ee8b2..90bc17f86 100644 --- a/include/atmos.h +++ b/include/atmos.h @@ -47,20 +47,20 @@ /* Color defines */ -#define COLOR_BLACK 0x00 -#define COLOR_RED 0x01 -#define COLOR_GREEN 0x02 -#define COLOR_YELLOW 0x03 -#define COLOR_BLUE 0x04 -#define COLOR_MAGENTA 0x05 -#define COLOR_CYAN 0x06 -#define COLOR_WHITE 0x07 +#define COLOR_BLACK 0x00 +#define COLOR_RED 0x01 +#define COLOR_GREEN 0x02 +#define COLOR_YELLOW 0x03 +#define COLOR_BLUE 0x04 +#define COLOR_MAGENTA 0x05 +#define COLOR_CYAN 0x06 +#define COLOR_WHITE 0x07 /* Define hardware */ #include <_6522.h> -#define VIA (*(struct __6522*)0x300) +#define VIA (*(struct __6522*)0x300) @@ -79,15 +79,15 @@ /* Character codes */ -#define CH_ULCORNER '+' -#define CH_URCORNER '+' -#define CH_LLCORNER '+' -#define CH_LRCORNER '+' -#define CH_TTEE '+' -#define CH_BTEE '+' -#define CH_LTEE '+' -#define CH_RTEE '+' -#define CH_CROSS '+' +#define CH_ULCORNER '+' +#define CH_URCORNER '+' +#define CH_LLCORNER '+' +#define CH_LRCORNER '+' +#define CH_TTEE '+' +#define CH_BTEE '+' +#define CH_LTEE '+' +#define CH_RTEE '+' +#define CH_CROSS '+' #define CH_CURS_UP 11 #define CH_CURS_DOWN 10 #define CH_CURS_LEFT 8 @@ -98,6 +98,13 @@ #define CH_LIRA 95 #define CH_ESC 27 + + +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 + + + void __fastcall__ atmos_load(const char* name); /* Load Atmos tape. */ @@ -108,6 +115,3 @@ void __fastcall__ atmos_save(const char* name, const void* start, const void* en /* End of atmos.h */ #endif - - - diff --git a/include/lynx.h b/include/lynx.h index 6bb993284..a99971cc4 100644 --- a/include/lynx.h +++ b/include/lynx.h @@ -87,7 +87,8 @@ #define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE #define TGI_COLOR_WHITE COLOR_WHITE - +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 @@ -182,11 +183,11 @@ unsigned __fastcall__ lynx_eewrite (unsigned cell, unsigned val); #include <_mikey.h> #define MIKEY (*(struct __mikey *)0xFD00) -#define _MIKEY_TIMERS (*(struct _mikey_all_timers *) 0xFD00) // mikey_timers[8] -#define _HBL_TIMER (*(struct _mikey_timer *) 0xFD00) // timer0 (HBL) -#define _VBL_TIMER (*(struct _mikey_timer *) 0xFD08) // timer2 (VBL) -#define _UART_TIMER (*(struct _mikey_timer *) 0xFD14) // timer4 (UART) -#define _VIDDMA (*(unsigned int *) 0xFD92) // dispctl/viddma +#define _MIKEY_TIMERS (*(struct _mikey_all_timers *) 0xFD00) // mikey_timers[8] +#define _HBL_TIMER (*(struct _mikey_timer *) 0xFD00) // timer0 (HBL) +#define _VBL_TIMER (*(struct _mikey_timer *) 0xFD08) // timer2 (VBL) +#define _UART_TIMER (*(struct _mikey_timer *) 0xFD14) // timer4 (UART) +#define _VIDDMA (*(unsigned int *) 0xFD92) // dispctl/viddma #include <_suzy.h> #define SUZY (*(struct __suzy*)0xFC00) @@ -194,6 +195,3 @@ unsigned __fastcall__ lynx_eewrite (unsigned cell, unsigned val); /* End of lynx.h */ #endif - - - diff --git a/include/nes.h b/include/nes.h index f93d7d62e..5e1853b2b 100644 --- a/include/nes.h +++ b/include/nes.h @@ -43,15 +43,15 @@ /* Key and character defines */ -#define CH_ENTER '\n' -#define CH_CURS_UP 0x01 -#define CH_CURS_DOWN 0x02 -#define CH_CURS_LEFT 0x03 -#define CH_CURS_RIGHT 0x04 -#define CH_ESC 8 -#define CH_DEL 20 - -#define CH_CROSS 0x10 +#define CH_ENTER '\n' +#define CH_CURS_UP 0x01 +#define CH_CURS_DOWN 0x02 +#define CH_CURS_LEFT 0x03 +#define CH_CURS_RIGHT 0x04 +#define CH_ESC 8 +#define CH_DEL 20 + +#define CH_CROSS 0x10 #define CH_RTEE 0x17 #define CH_LTEE 0x0f #define CH_TTEE 0x16 @@ -64,30 +64,32 @@ #define CH_LRCORNER 0x08 #define CH_PI 0x05 - /* Color defines */ -#define COLOR_BLACK 0x00 -#define COLOR_WHITE 0x01 -#define COLOR_RED 0x02 -#define COLOR_CYAN 0x03 -#define COLOR_VIOLET 0x04 -#define COLOR_GREEN 0x05 -#define COLOR_BLUE 0x06 -#define COLOR_YELLOW 0x07 -#define COLOR_ORANGE 0x08 -#define COLOR_BROWN 0x09 -#define COLOR_LIGHTRED 0x0A -#define COLOR_GRAY1 0x0B -#define COLOR_GRAY2 0x0C -#define COLOR_LIGHTGREEN 0x0D -#define COLOR_LIGHTBLUE 0x0E -#define COLOR_GRAY3 0x0F +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_VIOLET 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F /* Return codes of get_tv */ #define TV_NTSC 0 #define TV_PAL 1 #define TV_OTHER 2 +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 + void waitvblank (void); @@ -100,6 +102,3 @@ unsigned char get_tv (void); /* End of nes.h */ #endif - - - diff --git a/samples/mandelbrot.c b/samples/mandelbrot.c index 23eda0cf1..69035f4ed 100644 --- a/samples/mandelbrot.c +++ b/samples/mandelbrot.c @@ -14,18 +14,18 @@ /* Graphics definitions */ -#define SCREEN_X (tgi_getxres()) -#define SCREEN_Y (tgi_getyres()) -#define MAXCOL (tgi_getcolorcount()) +#define SCREEN_X (tgi_getxres()) +#define SCREEN_Y (tgi_getyres()) +#define MAXCOL (tgi_getcolorcount()) -#define maxiterations 32 -#define fpshift (10) -#define tofp(_x) ((_x)<>fpshift) -#define fpabs(_x) (abs(_x)) +#define maxiterations 32 +#define fpshift (10) +#define tofp(_x) ((_x)<>fpshift) +#define fpabs(_x) (abs(_x)) -#define mulfp(_a,_b) ((((signed long)_a)*(_b))>>fpshift) -#define divfp(_a,_b) ((((signed long)_a)<>fpshift) +#define divfp(_a,_b) ((((signed long)_a)<> (fpshift - 1)) + yy; - r = r1; - } - if (count == maxiterations) { - tgi_setcolor (0); - } else { - if (MAXCOL == 2) - tgi_setcolor (1); - else - tgi_setcolor (count % MAXCOL); - } - /* set pixel */ - tgi_setpixel (x, y); - } + yy += ys; + xx = x1; + for (x = 0; x < (SCREEN_X); x++) { + xx += xs; + /* do iterations */ + r = 0; + i = 0; + for (count = 0; (count < maxiterations) && + (fpabs (r) < tofp (2)) && (fpabs (i) < tofp (2)); + ++count) { + r1 = (mulfp (r, r) - mulfp (i, i)) + xx; + /* i = (mulfp(mulfp(r,i),tofp(2)))+yy; */ + i = (((signed long) r * i) >> (fpshift - 1)) + yy; + r = r1; + } + if (count == maxiterations) { + tgi_setcolor (0); + } else { + if (MAXCOL == 2) + tgi_setcolor (1); + else + tgi_setcolor (count % MAXCOL); + } + /* set pixel */ + tgi_setpixel (x, y); + } } } @@ -90,14 +95,19 @@ int main (void) clrscr (); +#if DYN_DRV /* Load the graphics driver */ cprintf ("initializing... mompls\r\n"); tgi_load_driver (tgi_stddrv); +#else + /* Install the graphics driver */ + tgi_install (tgi_static_stddrv); +#endif err = tgi_geterror (); if (err != TGI_ERR_OK) { - cprintf ("Error #%d initializing graphics.\r\n%s\r\n", - err, tgi_geterrormsg (err)); - exit (EXIT_FAILURE); + cprintf ("Error #%d initializing graphics.\r\n%s\r\n", + err, tgi_geterrormsg (err)); + exit (EXIT_FAILURE); }; cprintf ("ok.\n\r"); @@ -132,5 +142,4 @@ int main (void) /* Done */ return EXIT_SUCCESS; - } diff --git a/samples/mousedemo.c b/samples/mousedemo.c index 6f0825e6a..80937c3b5 100644 --- a/samples/mousedemo.c +++ b/samples/mousedemo.c @@ -20,11 +20,11 @@ /* Address of data for sprite 0 */ #if defined(__C64__) -# define SPRITE0_DATA 0x0340 -# define SPRITE0_PTR 0x07F8 +# define SPRITE0_DATA 0x0340 +# define SPRITE0_PTR 0x07F8 #elif defined(__C128__) -# define SPRITE0_DATA 0x0E00 -# define SPRITE0_PTR 0x07F8 +# define SPRITE0_DATA 0x0E00 +# define SPRITE0_PTR 0x07F8 #endif /* The mouse sprite (an arrow) */ @@ -56,6 +56,12 @@ static const unsigned char MouseSprite[64] = { #endif /* __C64__ or __C128__ */ +/* Dynamically loaded driver by default */ +#ifndef DYN_DRV +# define DYN_DRV 1 +#endif + + #define max(a,b) (((a) > (b)) ? (a) : (b)) #define min(a,b) (((a) < (b)) ? (a) : (b)) @@ -133,12 +139,18 @@ int main (void) #endif +#if DYN_DRV /* Output a warning about the driver that is needed */ DoWarning (); /* Load and install the mouse driver */ CheckError ("mouse_load_driver", mouse_load_driver (&mouse_def_callbacks, mouse_stddrv)); +#else + /* Install the mouse driver */ + CheckError ("mouse_install", + mouse_install (&mouse_def_callbacks, mouse_static_stddrv)); +#endif /* Get the initial mouse bounding box */ mouse_getbox (&full_box); @@ -210,8 +222,13 @@ int main (void) } +#if DYN_DRV /* Uninstall and unload the mouse driver */ CheckError ("mouse_unload", mouse_unload ()); +#else + /* Uninstall the mouse driver */ + CheckError ("mouse_uninstall", mouse_uninstall ()); +#endif /* Say goodbye */ clrscr (); diff --git a/samples/tgidemo.c b/samples/tgidemo.c index ccefdb5c1..3329dd3ca 100644 --- a/samples/tgidemo.c +++ b/samples/tgidemo.c @@ -9,6 +9,10 @@ +#ifndef DYN_DRV +# define DYN_DRV 1 +#endif + #define COLOR_BACK TGI_COLOR_BLACK #define COLOR_FORE TGI_COLOR_WHITE @@ -74,7 +78,7 @@ static void DoCircles (void) for (I = 10; I < 240; I += 10) { tgi_ellipse (X, Y, I, tgi_imulround (I, AspectRatio)); } - Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; + Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; } cgetc (); @@ -96,16 +100,16 @@ static void DoCheckerboard (void) for (X = 0; X <= MaxX; X += 10) { tgi_setcolor (Color); tgi_bar (X, Y, X+9, Y+9); - Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; + Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; if (kbhit ()) { cgetc (); tgi_clear (); return; } } - Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; + Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; } - Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; + Color = Color == COLOR_FORE ? COLOR_BACK : COLOR_FORE; } } @@ -163,11 +167,11 @@ static void DoLines (void) tgi_setpalette (Palette); tgi_setcolor (COLOR_FORE); - for (X = 0; X <= MaxY; X += 10) { - tgi_line (0, 0, MaxY, X); - tgi_line (0, 0, X, MaxY); - tgi_line (MaxY, MaxY, 0, MaxY-X); - tgi_line (MaxY, MaxY, MaxY-X, 0); + for (X = 0; X <= MaxY; X += 10) { + tgi_line (0, 0, MaxY, X); + tgi_line (0, 0, X, MaxY); + tgi_line (MaxY, MaxY, 0, MaxY-X); + tgi_line (MaxY, MaxY, MaxY-X, 0); } cgetc (); @@ -180,12 +184,19 @@ int main (void) { unsigned char Border; +#if DYN_DRV /* Warn the user that the tgi driver is needed */ DoWarning (); /* Load and initialize the driver */ tgi_load_driver (tgi_stddrv); CheckError ("tgi_load_driver"); +#else + /* Install the driver */ + tgi_install (tgi_static_stddrv); + CheckError ("tgi_install"); +#endif + tgi_init (); CheckError ("tgi_init"); tgi_clear (); @@ -204,8 +215,13 @@ int main (void) DoDiagram (); DoLines (); +#if DYN_DRV /* Unload the driver */ tgi_unload (); +#else + /* Uninstall the driver */ + tgi_uninstall (); +#endif /* Reset the border */ (void) bordercolor (Border); -- 2.39.5