1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-26 05:29:30 +00:00

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
This commit is contained in:
izydorst 2001-07-15 16:09:50 +00:00
parent 66bcf9ac4e
commit 8e97e1f4b7
14 changed files with 160 additions and 26 deletions

View File

@ -6,7 +6,7 @@
<title>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>

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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);
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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));
}

20
libsrc/geos/common/rand.s Normal file
View File

@ -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

View File

@ -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

View File

@ -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