From 8e97e1f4b76c52bb46af715547b8217e83445ede Mon Sep 17 00:00:00 2001 From: izydorst Date: Sun, 15 Jul 2001 16:09:50 +0000 Subject: [PATCH] own versions of some common routines, fillram and movedata equal to memset and memcpy git-svn-id: svn://svn.cc65.org/cc65/trunk@789 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- doc/geos.sgml | 29 ++++++++++++++++++----------- include/geos/gdisk.h | 1 + include/geos/ggraph.h | 1 - include/geos/gmemory.h | 4 ++-- libsrc/geos/Makefile | 2 +- libsrc/geos/common/Makefile | 21 +++++++++++++++++++++ libsrc/geos/common/abort.c | 16 ++++++++++++++++ libsrc/geos/common/copydata.s | 27 +++++++++++++++++++++++++++ libsrc/geos/common/memcpy.s | 12 ++++++++++++ libsrc/geos/common/memset.s | 10 ++++++++++ libsrc/geos/common/perror.c | 17 +++++++++++++++++ libsrc/geos/common/rand.s | 20 ++++++++++++++++++++ libsrc/geos/memory/fillram.s | 14 +++++++++----- libsrc/geos/memory/movedata.s | 12 ++++++------ 14 files changed, 160 insertions(+), 26 deletions(-) create mode 100644 libsrc/geos/common/Makefile create mode 100644 libsrc/geos/common/abort.c create mode 100644 libsrc/geos/common/copydata.s create mode 100644 libsrc/geos/common/memcpy.s create mode 100644 libsrc/geos/common/memset.s create mode 100644 libsrc/geos/common/perror.c create mode 100644 libsrc/geos/common/rand.s diff --git a/doc/geos.sgml b/doc/geos.sgml index 31ede5f8a..019e3533a 100644 --- a/doc/geos.sgml +++ b/doc/geos.sgml @@ -6,7 +6,7 @@ GEOSLib docs <author>Maciej Witkowiak, <htmlurl url="mailto:ytm@elysium.pl" name="ytm@elysium.pl"> -<date>v1.2, 26.12.1999, 16.03.2000, 19-22.03.2000, 11,29.07.2000, 3-4.07.2001 +<date>v1.2, 26.12.1999, 16.03.2000, 19-22.03.2000, 11,29.07.2000, 3-4,15.07.2001 <abstract> This is the documentation of cc65's GEOSLib, but information contained here may be also useful for writting GEOS applications in general. @@ -27,10 +27,16 @@ is easy to use and program. Coding GEOS in C? That's something new. It is possible now - with Ulrich von Bassewitz's cc65 package and my GEOSLib you are able to create GEOS applications in no-time. <p> -GEOSLib supports a subset of standard cc65 libraries. Memory and string functions are included -but you should consider using native versions of these (e.g. <tt/FillRam/ instead of </ttmemset/) -at least in this version. <tt/dio/ - direct disk access is available, but you might have -problems with devices other than 1541, 1571 or 1581. RAM drives emulating these should work. +GEOSLib supports a subset of standard cc65 libraries. Whenever possible native Kernal functions +are used (e.g. <tt/memset/ is an alias for <tt/FillRam/), however not all are supported. E.g. +string functions like <tt/strcmp/, <tt/strcpy/ are doubled with native <tt/CmpString/, +<tt/CopyString/ because the latter can handle only 256 byte strings. Keep this in mind when +you will write your program. If you don't need long strings simply use functions from Kernal, +resulting code will be smaller. +<p> +<tt/dio/ - direct disk access is available, but you might have problems with devices other +than 1541, 1571 or 1581. RAM drives emulating these should work. +<p> It is safe to use these includes: <tt/dio.h, errno.h, geos.h, joystick.h, mouse.h, stdlib.h, string.h/ <p> @@ -992,8 +998,8 @@ Functions covered in this section are common for whole C world - copying memory strings is one of the main computer tasks. GEOS also has interface to do this. These functions are replacement for those like <tt/memset, memcpy, strcpy/ etc. from standard libraries. -However they have slighty different calling convention (order of arguments to be specific), so -please check their syntax here before direct replacing. +However some of them have slighty different calling convention (order of arguments to be specific), +so please check their syntax here before direct replacing. Please note that the memory described as <em/strings/ are up to 255 characters (without counting the terminating <tt/NULL/), and <em/regions/ cover whole 64K of memory. @@ -1031,21 +1037,21 @@ compatible with standard CRC routines. <sect2>FillRam and ClearRam <p> -<tt/void FillRam (char value, char *dest, int length)/ +<tt/void FillRam (char *dest, char value, int length)/ <p> <tt/void ClearRam (char *dest, int length)/ <p> Both functions are filling given memory range. <tt/ClearRam/ fills with <tt/NULLs/, while <tt/FillRam/ uses given <tt/value/. Be warned that these functions destroy <tt/r0, r1 and -r2L/ registers. +r2L/ registers. <tt/FillRam/ is an alias for <tt/memset/. <sect2>MoveData <p> -<tt/void MoveData (char *src, char *dest, int length)/ +<tt/void MoveData (char *dest, char *src, int length)/ <p> This functions copies one memory region to another. There are checks for overlap and the non-destructive method is chosen. Be warned that this function destroys contents of -<tt/r0, r1 and r2/ registers. +<tt/r0, r1 and r2/ registers. This is also alias for <tt/memcpy/ <sect2>InitRam <p> @@ -1066,6 +1072,7 @@ This is done with <tt/table/ where everything is defined. See structures chapter <tt/ char VerifyRAM (char bank, int length, char *reuAddress, char *cpuAddress)/ <p> These functions are interface to REU - Ram Expansion Unit. I think that they are self-explanatory. +You can check for REU presence by taking value of <tt/ramExpSize/. <sect1>Processes and Multitasking <p> diff --git a/include/geos/gdisk.h b/include/geos/gdisk.h index 9fac4640a..68eea97e6 100644 --- a/include/geos/gdisk.h +++ b/include/geos/gdisk.h @@ -53,6 +53,7 @@ char __fastcall__ ChangeDiskDevice(char newdev); #define OFF_GS_ID 173 /* disk errors */ #define ANY_FAULT 0xf0 +#define G_EOF 0 #define NO_BLOCKS 1 #define INV_TRACK 2 #define INSUFF_SPACE 3 diff --git a/include/geos/ggraph.h b/include/geos/ggraph.h index 51caad7ba..d59947157 100644 --- a/include/geos/ggraph.h +++ b/include/geos/ggraph.h @@ -83,7 +83,6 @@ void __fastcall__ GraphicsString(char *myGfxString); #define SCREENBYTEWIDTH 80 #define SCREENPIXELWIDTH 640 /* control characters for use as numbers, not chars */ -#define EOF 0 #define BACKSPACE 8 #define FORWARDSPACE 9 #define TAB 9 diff --git a/include/geos/gmemory.h b/include/geos/gmemory.h index 805728864..e9398d5ca 100644 --- a/include/geos/gmemory.h +++ b/include/geos/gmemory.h @@ -19,9 +19,9 @@ char __fastcall__ CmpFString(char len, char *dest, char *source); int __fastcall__ CRC(char *buffer, int len); void __fastcall__ ClearRam(char *dest, int len); -void __fastcall__ FillRam(char what, char *dest, int len); +void __fastcall__ FillRam(char *dest, char what, int len); -void __fastcall__ MoveData(char *source, char *dest, int len); +void __fastcall__ MoveData(char *dest, char *source, int len); void __fastcall__ InitRam(char *myInitTab); diff --git a/libsrc/geos/Makefile b/libsrc/geos/Makefile index 178c3d4f3..c38db30e4 100644 --- a/libsrc/geos/Makefile +++ b/libsrc/geos/Makefile @@ -4,7 +4,7 @@ # # Maciej 'YTM/Elysium' Witkowiak -OBJ_DIRS=devel disk dlgbox file graph menuicon memory mousesprite process system +OBJ_DIRS=common devel disk dlgbox file graph menuicon memory mousesprite process system all: @for i in $(OBJ_DIRS); do $(MAKE) -C $$i; done diff --git a/libsrc/geos/common/Makefile b/libsrc/geos/common/Makefile new file mode 100644 index 000000000..8bea80e58 --- /dev/null +++ b/libsrc/geos/common/Makefile @@ -0,0 +1,21 @@ +# +# Makefile for GEOS lib +# for cc65 +# + +%.o: %.c + @$(CC) $(CFLAGS) $< + @$(AS) -g -o $@ $(AFLAGS) $(*).s + +%.o: %.s + @$(AS) -o $@ $(AFLAGS) $< + +C_OBJS = abort.o perror.o +S_OBJS = copydata.o memcpy.o memset.o rand.o + +all: $(C_OBJS) $(S_OBJS) + +clean: + @rm -f *.~ $(S_OBJS) core + @rm -f $(C_OBJS:.o=.s) + @rm -f $(C_OBJS) diff --git a/libsrc/geos/common/abort.c b/libsrc/geos/common/abort.c new file mode 100644 index 000000000..fb52f88e1 --- /dev/null +++ b/libsrc/geos/common/abort.c @@ -0,0 +1,16 @@ +/* + * abort.c + * + * Maciej 'YTM/Elysium' Witkowiak 15.7.2001 + */ + + + +#include <stdlib.h> +#include <geos.h> + +void abort (void) +{ + DlgBoxOk(CBOLDON "ABNORMAL PROGRAM", "TERMINATION." CPLAINTEXT); + exit(3); +} diff --git a/libsrc/geos/common/copydata.s b/libsrc/geos/common/copydata.s new file mode 100644 index 000000000..2efd7c352 --- /dev/null +++ b/libsrc/geos/common/copydata.s @@ -0,0 +1,27 @@ +; +; Maciej 'YTM/Elysium' Witkowiak 15.07.2001 +; +; Copy the data segment from the LOAD to the RUN location +; + + .export copydata + .import __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__ + .include "../inc/geossym.inc" + .include "../inc/jumptab.inc" + +copydata: + lda #<__DATA_SIZE__ ; no need to check if it is == 0 + ldx #>__DATA_SIZE__ + sta r2L + stx r2H + + lda #<__DATA_RUN__ + ldx #>__DATA_RUN__ + sta r1L + stx r1H + + lda #<__DATA_LOAD__ + ldx #>__DATA_LOAD__ + sta r0L + stx r0H + jmp MoveData diff --git a/libsrc/geos/common/memcpy.s b/libsrc/geos/common/memcpy.s new file mode 100644 index 000000000..442837d7e --- /dev/null +++ b/libsrc/geos/common/memcpy.s @@ -0,0 +1,12 @@ +; +; void* memcpy (void* dest, const void* src, size_t n); +; void* memmove (void* dest, const void* src, size_t n); +; +; Maciej 'YTM/Elysium' Witkowiak, 15.07.2001 +; + + .export _memcpy, _memmove + .import _MoveData + +_memcpy = _MoveData +_memmove = _MoveData diff --git a/libsrc/geos/common/memset.s b/libsrc/geos/common/memset.s new file mode 100644 index 000000000..d4169c2b3 --- /dev/null +++ b/libsrc/geos/common/memset.s @@ -0,0 +1,10 @@ +; +; void* memset (void* ptr, int c, size_t n); +; +; Maciej 'YTM/Elysium' Witkowiak, 15.07.2001 +; + + .export _memset + .import _FillRam + +_memset = _FillRam diff --git a/libsrc/geos/common/perror.c b/libsrc/geos/common/perror.c new file mode 100644 index 000000000..6d64b25a2 --- /dev/null +++ b/libsrc/geos/common/perror.c @@ -0,0 +1,17 @@ +/* + * perror.c + * + * Maciej 'YTM/Elysium' Witkowiak, 15.07.2001 + */ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <geos.h> + +void perror(const char* msg) +{ + + DlgBoxOk((char*)msg,strerror(errno)); + +} diff --git a/libsrc/geos/common/rand.s b/libsrc/geos/common/rand.s new file mode 100644 index 000000000..ad2db1823 --- /dev/null +++ b/libsrc/geos/common/rand.s @@ -0,0 +1,20 @@ +; +; Maciej 'YTM/Elysium' Witkowiak, 15.07.2001 +; +; +; int rand (void); +; void srand (unsigned seed); +; + .export _rand, _srand + .include "../inc/jumptab.inc" + +.code + +_rand: + jsr GetRandom + pha + jsr GetRandom + tax + pla +_srand: + rts diff --git a/libsrc/geos/memory/fillram.s b/libsrc/geos/memory/fillram.s index c08b05e5c..72301c7fd 100644 --- a/libsrc/geos/memory/fillram.s +++ b/libsrc/geos/memory/fillram.s @@ -1,19 +1,23 @@ ; -; Maciej 'YTM/Alliance' Witkowiak +; Maciej 'YTM/Elysium' Witkowiak ; -; 30.10.99 +; 30.10.99, 15.07.2001 -; void FillRam (char what, char *dest, int length); +; void FillRam (char *dest, char what, int length); - .import DoublePop, popa + .import popa, popax .export _FillRam .include "../inc/jumptab.inc" .include "../inc/geossym.inc" _FillRam: - jsr DoublePop + sta r0L + stx r0H jsr popa sta r2L + jsr popax + sta r1L + stx r1H jmp FillRam diff --git a/libsrc/geos/memory/movedata.s b/libsrc/geos/memory/movedata.s index 79022593a..b16ef2392 100644 --- a/libsrc/geos/memory/movedata.s +++ b/libsrc/geos/memory/movedata.s @@ -1,10 +1,10 @@ ; -; Maciej 'YTM/Alliance' Witkowiak +; Maciej 'YTM/Elysium' Witkowiak ; -; 30.10.99 +; 30.10.99, 15.07.2001 -; void MoveData (char* source, char *dest, int length); +; void MoveData (char* dest, char *source, int length); .import popax .export _MoveData @@ -16,9 +16,9 @@ _MoveData: sta r2L stx r2H jsr popax - sta r1L - stx r1H - jsr popax sta r0L stx r0H + jsr popax + sta r1L + stx r1H jmp MoveData -- 2.39.5