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

Fix line endings (CRLF -> LF) on all affected files.

This commit is contained in:
Christian Groessler 2017-03-10 11:21:14 +01:00
parent b332064cb5
commit 8a81f9c0c8
14 changed files with 2379 additions and 2379 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,267 +1,267 @@
; smc.mac ; smc.mac
; ca65 Macro-Pack for Self Modifying Code (SMC) ; ca65 Macro-Pack for Self Modifying Code (SMC)
; ;
; (c) Christian Krüger, latest change: 17-Jul-2016 ; (c) Christian Krüger, latest change: 17-Jul-2016
; ;
; This software is provided 'as-is', without any expressed or implied ; This software is provided 'as-is', without any expressed or implied
; warranty. In no event will the authors be held liable for any damages ; warranty. In no event will the authors be held liable for any damages
; arising from the use of this software. ; arising from the use of this software.
; ;
; Permission is granted to anyone to use this software for any purpose, ; Permission is granted to anyone to use this software for any purpose,
; including commercial applications, and to alter it and redistribute it ; including commercial applications, and to alter it and redistribute it
; freely, subject to the following restrictions: ; freely, subject to the following restrictions:
; ;
; 1. The origin of this software must not be misrepresented; you must not ; 1. The origin of this software must not be misrepresented; you must not
; claim that you wrote the original software. If you use this software ; claim that you wrote the original software. If you use this software
; in a product, an acknowledgment in the product documentation would be ; in a product, an acknowledgment in the product documentation would be
; appreciated but is not required. ; appreciated but is not required.
; 2. Altered source versions must be plainly marked as such, and must not ; 2. Altered source versions must be plainly marked as such, and must not
; be misrepresented as being the original software. ; be misrepresented as being the original software.
; 3. This notice may not be removed or altered from any source ; 3. This notice may not be removed or altered from any source
; distribution. ; distribution.
; ;
.define _SMCDesignator .mid(0, .tcount(label) - 1, label) .ident(.concat(.string(.right(1, label)), "_SMC")) .define _SMCDesignator .mid(0, .tcount(label) - 1, label) .ident(.concat(.string(.right(1, label)), "_SMC"))
.define _SMCAlias .mid(0, .tcount(alias) - 1, alias) .ident(.concat(.string(.right(1, alias)), "_SMC")) .define _SMCAlias .mid(0, .tcount(alias) - 1, alias) .ident(.concat(.string(.right(1, alias)), "_SMC"))
.define SMC_AbsAdr $FADE .define SMC_AbsAdr $FADE
.define SMC_ZpAdr $00 .define SMC_ZpAdr $00
.define SMC_Opcode nop .define SMC_Opcode nop
.define SMC_Value $42 .define SMC_Value $42
.macro SMC_OperateOnValue opcode, label .macro SMC_OperateOnValue opcode, label
opcode _SMCDesignator+1 opcode _SMCDesignator+1
.endmacro .endmacro
.macro SMC_OperateOnLowByte opcode, label .macro SMC_OperateOnLowByte opcode, label
SMC_OperateOnValue opcode, label SMC_OperateOnValue opcode, label
.endmacro .endmacro
.macro SMC_OperateOnHighByte opcode, label .macro SMC_OperateOnHighByte opcode, label
opcode _SMCDesignator + 2 opcode _SMCDesignator + 2
.endmacro .endmacro
.macro SMC_Import alias .macro SMC_Import alias
.import _SMCAlias .import _SMCAlias
.endmacro .endmacro
.macro SMC_Export alias, label .macro SMC_Export alias, label
.export _SMCAlias := _SMCDesignator .export _SMCAlias := _SMCDesignator
.endmacro .endmacro
.macro SMC label, statement .macro SMC label, statement
_SMCDesignator: statement _SMCDesignator: statement
.endmacro .endmacro
.macro SMC_TransferOpcode label, opcode, register .macro SMC_TransferOpcode label, opcode, register
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
lda #opcode lda #opcode
sta _SMCDesignator sta _SMCDesignator
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx #opcode ldx #opcode
stx _SMCDesignator stx _SMCDesignator
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy #opcode ldy #opcode
sty _SMCDesignator sty _SMCDesignator
.else .else
.error "Invalid usage of macro 'SMC_TransferOpcode'" .error "Invalid usage of macro 'SMC_TransferOpcode'"
.endif .endif
.endmacro .endmacro
.macro SMC_LoadOpcode label, register .macro SMC_LoadOpcode label, register
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
lda _SMCDesignator lda _SMCDesignator
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx _SMCDesignator ldx _SMCDesignator
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy _SMCDesignator ldy _SMCDesignator
.else .else
.error "Invalid usage of macro 'SMC_LoadOpcode'" .error "Invalid usage of macro 'SMC_LoadOpcode'"
.endif .endif
.endmacro .endmacro
.macro SMC_StoreOpcode label, register .macro SMC_StoreOpcode label, register
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
sta _SMCDesignator sta _SMCDesignator
.elseif .match ({register}, x) .elseif .match ({register}, x)
stx _SMCDesignator stx _SMCDesignator
.elseif .match ({register}, y) .elseif .match ({register}, y)
sty _SMCDesignator sty _SMCDesignator
.else .else
.error "Invalid usage of macro 'SMC_StoreOpcode'" .error "Invalid usage of macro 'SMC_StoreOpcode'"
.endif .endif
.endmacro .endmacro
.macro SMC_ChangeBranch label, destination, register .macro SMC_ChangeBranch label, destination, register
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
lda #(<(destination - _SMCDesignator -2)) lda #(<(destination - _SMCDesignator -2))
sta _SMCDesignator+1 sta _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx #(<(destination - _SMCDesignator - 2)) ldx #(<(destination - _SMCDesignator - 2))
stx _SMCDesignator+1 stx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy #(<(destination - _SMCDesignator - 2)) ldy #(<(destination - _SMCDesignator - 2))
sty _SMCDesignator+1 sty _SMCDesignator+1
.else .else
.error "Invalid usage of macro 'SMC_ChangeBranch'" .error "Invalid usage of macro 'SMC_ChangeBranch'"
.endif .endif
.endmacro .endmacro
.macro SMC_TransferValue label, value, register .macro SMC_TransferValue label, value, register
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
lda value lda value
sta _SMCDesignator+1 sta _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx value ldx value
stx _SMCDesignator+1 stx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy value ldy value
sty _SMCDesignator+1 sty _SMCDesignator+1
.else .else
.error "Invalid usage of macro 'SMC_TransferValue'" .error "Invalid usage of macro 'SMC_TransferValue'"
.endif .endif
.endmacro .endmacro
.macro SMC_LoadValue label, register .macro SMC_LoadValue label, register
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
lda _SMCDesignator+1 lda _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx _SMCDesignator+1 ldx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy _SMCDesignator+1 ldy _SMCDesignator+1
.else .else
.error "Invalid usage of macro 'SMC_LoadValue'" .error "Invalid usage of macro 'SMC_LoadValue'"
.endif .endif
.endmacro .endmacro
.macro SMC_StoreValue label, register .macro SMC_StoreValue label, register
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
sta _SMCDesignator+1 sta _SMCDesignator+1
.elseif .match ({register}, x) .elseif .match ({register}, x)
stx _SMCDesignator+1 stx _SMCDesignator+1
.elseif .match ({register}, y) .elseif .match ({register}, y)
sty _SMCDesignator+1 sty _SMCDesignator+1
.else .else
.error "Invalid usage of macro 'SMC_StoreValue'" .error "Invalid usage of macro 'SMC_StoreValue'"
.endif .endif
.endmacro .endmacro
.macro SMC_TransferLowByte label, value, register .macro SMC_TransferLowByte label, value, register
SMC_TransferValue label, value, register SMC_TransferValue label, value, register
.endmacro .endmacro
.macro SMC_LoadLowByte label, register .macro SMC_LoadLowByte label, register
SMC_LoadValue label, register SMC_LoadValue label, register
.endmacro .endmacro
.macro SMC_StoreLowByte label, register .macro SMC_StoreLowByte label, register
SMC_StoreValue label, register SMC_StoreValue label, register
.endmacro .endmacro
.macro SMC_TransferHighByte label, value, register .macro SMC_TransferHighByte label, value, register
.if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 2 .or .match ({register}, a) .or .match ({register}, )
lda value lda value
sta _SMCDesignator+2 sta _SMCDesignator+2
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx value ldx value
stx _SMCDesignator+2 stx _SMCDesignator+2
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy value ldy value
sty _SMCDesignator+2 sty _SMCDesignator+2
.else .else
.error "Invalid usage of macro 'SMC_TransferHighByte'" .error "Invalid usage of macro 'SMC_TransferHighByte'"
.endif .endif
.endmacro .endmacro
.macro SMC_LoadHighByte label, register .macro SMC_LoadHighByte label, register
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
lda _SMCDesignator+2 lda _SMCDesignator+2
.elseif .match ({register}, x) .elseif .match ({register}, x)
ldx _SMCDesignator+2 ldx _SMCDesignator+2
.elseif .match ({register}, y) .elseif .match ({register}, y)
ldy _SMCDesignator+2 ldy _SMCDesignator+2
.else .else
.error "Invalid usage of macro 'SMC_LoadHighByte'" .error "Invalid usage of macro 'SMC_LoadHighByte'"
.endif .endif
.endmacro .endmacro
.macro SMC_StoreHighByte label, register .macro SMC_StoreHighByte label, register
.if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, ) .if .paramcount = 1 .or .match ({register}, a) .or .match ({register}, )
sta _SMCDesignator+2 sta _SMCDesignator+2
.elseif .match ({register}, x) .elseif .match ({register}, x)
stx _SMCDesignator+2 stx _SMCDesignator+2
.elseif .match ({register}, y) .elseif .match ({register}, y)
sty _SMCDesignator+2 sty _SMCDesignator+2
.else .else
.error "Invalid usage of macro 'SMC_StoreHighByte'" .error "Invalid usage of macro 'SMC_StoreHighByte'"
.endif .endif
.endmacro .endmacro
.macro SMC_TransferAddressSingle label, address, register .macro SMC_TransferAddressSingle label, address, register
.if .paramcount = 2 .or .match ((register), a) .or .match ({register}, ) .if .paramcount = 2 .or .match ((register), a) .or .match ({register}, )
.if (.match (.left (1, {address}), #)) .if (.match (.left (1, {address}), #))
; immediate mode ; immediate mode
lda #<(.right (.tcount ({address})-1, {address})) lda #<(.right (.tcount ({address})-1, {address}))
sta _SMCDesignator+1 sta _SMCDesignator+1
lda #>(.right (.tcount ({address})-1, {address})) lda #>(.right (.tcount ({address})-1, {address}))
sta _SMCDesignator+2 sta _SMCDesignator+2
.else .else
; assume absolute or zero page ; assume absolute or zero page
lda address lda address
sta _SMCDesignator+1 sta _SMCDesignator+1
lda 1+(address) lda 1+(address)
sta _SMCDesignator+2 sta _SMCDesignator+2
.endif .endif
.elseif .match ((register), x) .elseif .match ((register), x)
.if (.match (.left (1, {address}), #)) .if (.match (.left (1, {address}), #))
; immediate mode ; immediate mode
ldx #<(.right (.tcount ({address})-1, {address})) ldx #<(.right (.tcount ({address})-1, {address}))
stx _SMCDesignator+1 stx _SMCDesignator+1
ldx #>(.right (.tcount ({address})-1, {address})) ldx #>(.right (.tcount ({address})-1, {address}))
stx _SMCDesignator+2 stx _SMCDesignator+2
.else .else
; assume absolute or zero page ; assume absolute or zero page
ldx address ldx address
stx _SMCDesignator+1 stx _SMCDesignator+1
ldx 1+(address) ldx 1+(address)
stx _SMCDesignator+2 stx _SMCDesignator+2
.endif .endif
.elseif .match ((register), y) .elseif .match ((register), y)
.if (.match (.left (1, {address}), #)) .if (.match (.left (1, {address}), #))
; immediate mode ; immediate mode
ldy #<(.right (.tcount ({address})-1, {address})) ldy #<(.right (.tcount ({address})-1, {address}))
sty _SMCDesignator+1 sty _SMCDesignator+1
ldy #>(.right (.tcount ({address})-1, {address})) ldy #>(.right (.tcount ({address})-1, {address}))
sty _SMCDesignator+2 sty _SMCDesignator+2
.else .else
; assume absolute or zero page ; assume absolute or zero page
ldy address ldy address
sty _SMCDesignator+1 sty _SMCDesignator+1
ldy 1+(address) ldy 1+(address)
sty _SMCDesignator+2 sty _SMCDesignator+2
.endif .endif
.else .else
.error "Invalid usage of macro 'SMC_TransferAddressSingle'" .error "Invalid usage of macro 'SMC_TransferAddressSingle'"
.endif .endif
.endmacro .endmacro
.macro SMC_TransferAddress label, address .macro SMC_TransferAddress label, address
.if (.match (.left (1, {address}), #)) .if (.match (.left (1, {address}), #))
; immediate mode ; immediate mode
lda #<(.right (.tcount ({address})-1, {address})) lda #<(.right (.tcount ({address})-1, {address}))
sta _SMCDesignator+1 sta _SMCDesignator+1
ldx #>(.right (.tcount ({address})-1, {address})) ldx #>(.right (.tcount ({address})-1, {address}))
stx _SMCDesignator+2 stx _SMCDesignator+2
.else .else
; assume absolute or zero page ; assume absolute or zero page
lda {address} lda {address}
sta _SMCDesignator+1 sta _SMCDesignator+1
ldx 1+{address} ldx 1+{address}
stx _SMCDesignator)+2 stx _SMCDesignator)+2
.endif .endif
.endmacro .endmacro
.macro SMC_StoreAddress label .macro SMC_StoreAddress label
sta _SMCDesignator+1 sta _SMCDesignator+1
stx _SMCDesignator+2 stx _SMCDesignator+2
.endmacro .endmacro

View File

@ -1,47 +1,47 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* osic1p.h */ /* osic1p.h */
/* */ /* */
/* Challenger 1P system specific definitions */ /* Challenger 1P system specific definitions */
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2015 Stephan Muehlstrasser */ /* (C) 2015 Stephan Muehlstrasser */
/* */ /* */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */ /* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */ /* arising from the use of this software. */
/* */ /* */
/* Permission is granted to anyone to use this software for any purpose, */ /* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */ /* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */ /* freely, subject to the following restrictions: */
/* */ /* */
/* 1. The origin of this software must not be misrepresented; you must not */ /* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */ /* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */ /* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */ /* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */ /* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */ /* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */ /* 3. This notice may not be removed or altered from any source */
/* distribution. */ /* distribution. */
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#ifndef _OSIC1P_H #ifndef _OSIC1P_H
#define _OSIC1P_H #define _OSIC1P_H
/* Check for errors */ /* Check for errors */
#if !defined(__OSIC1P__) #if !defined(__OSIC1P__)
# error "This module may only be used when compiling for the Challenger 1P!" # error "This module may only be used when compiling for the Challenger 1P!"
#endif #endif
/* The following #defines will cause the matching functions calls in conio.h /* The following #defines will cause the matching functions calls in conio.h
** to be overlaid by macros with the same names, saving the function call ** to be overlaid by macros with the same names, saving the function call
** overhead. ** overhead.
*/ */
#define _textcolor(color) COLOR_WHITE #define _textcolor(color) COLOR_WHITE
#define _bgcolor(color) COLOR_BLACK #define _bgcolor(color) COLOR_BLACK
#define _bordercolor(color) COLOR_BLACK #define _bordercolor(color) COLOR_BLACK
#endif #endif

View File

@ -1,172 +1,172 @@
/*****************************************************************************/ /*****************************************************************************/
/* */ /* */
/* zlib.h */ /* zlib.h */
/* */ /* */
/* Decompression routines for the 'deflate' format */ /* Decompression routines for the 'deflate' format */
/* */ /* */
/* */ /* */
/* */ /* */
/* (C) 2000-2015 Piotr Fusik <fox@scene.pl> */ /* (C) 2000-2015 Piotr Fusik <fox@scene.pl> */
/* */ /* */
/* This file is based on the zlib.h from 'zlib' general purpose compression */ /* This file is based on the zlib.h from 'zlib' general purpose compression */
/* library, version 1.1.3, (C) 1995-1998 Jean-loup Gailly and Mark Adler. */ /* library, version 1.1.3, (C) 1995-1998 Jean-loup Gailly and Mark Adler. */
/* */ /* */
/* Jean-loup Gailly Mark Adler */ /* Jean-loup Gailly Mark Adler */
/* jloup@gzip.org madler@alumni.caltech.edu */ /* jloup@gzip.org madler@alumni.caltech.edu */
/* */ /* */
/* This software is provided 'as-is', without any expressed or implied */ /* This software is provided 'as-is', without any expressed or implied */
/* warranty. In no event will the authors be held liable for any damages */ /* warranty. In no event will the authors be held liable for any damages */
/* arising from the use of this software. */ /* arising from the use of this software. */
/* */ /* */
/* Permission is granted to anyone to use this software for any purpose, */ /* Permission is granted to anyone to use this software for any purpose, */
/* including commercial applications, and to alter it and redistribute it */ /* including commercial applications, and to alter it and redistribute it */
/* freely, subject to the following restrictions: */ /* freely, subject to the following restrictions: */
/* */ /* */
/* 1. The origin of this software must not be misrepresented; you must not */ /* 1. The origin of this software must not be misrepresented; you must not */
/* claim that you wrote the original software. If you use this software */ /* claim that you wrote the original software. If you use this software */
/* in a product, an acknowledgment in the product documentation would be */ /* in a product, an acknowledgment in the product documentation would be */
/* appreciated but is not required. */ /* appreciated but is not required. */
/* 2. Altered source versions must be plainly marked as such, and must not */ /* 2. Altered source versions must be plainly marked as such, and must not */
/* be misrepresented as being the original software. */ /* be misrepresented as being the original software. */
/* 3. This notice may not be removed or altered from any source */ /* 3. This notice may not be removed or altered from any source */
/* distribution. */ /* distribution. */
/* */ /* */
/*****************************************************************************/ /*****************************************************************************/
#ifndef _ZLIB_H #ifndef _ZLIB_H
#define _ZLIB_H #define _ZLIB_H
#define Z_OK 0 #define Z_OK 0
#define Z_DATA_ERROR (-3) #define Z_DATA_ERROR (-3)
/* Return codes for uncompress() */ /* Return codes for uncompress() */
#define Z_DEFLATED 8 #define Z_DEFLATED 8
/* The deflate compression method (the only one supported) */ /* The deflate compression method (the only one supported) */
#define Z_NULL 0 #define Z_NULL 0
unsigned __fastcall__ inflatemem (char* dest, const char* source); unsigned __fastcall__ inflatemem (char* dest, const char* source);
/* /*
Decompresses the source buffer into the destination buffer. Decompresses the source buffer into the destination buffer.
Returns the size of the uncompressed data (number of bytes written starting Returns the size of the uncompressed data (number of bytes written starting
from dest). from dest).
This function expects data in the DEFLATE format, described in RFC This function expects data in the DEFLATE format, described in RFC
(Request for Comments) 1951 in the file (Request for Comments) 1951 in the file
ftp://ds.internic.net/rfc/rfc1951.txt. ftp://ds.internic.net/rfc/rfc1951.txt.
This function does not exist in the original zlib. Its implementation This function does not exist in the original zlib. Its implementation
using original zlib might be following: using original zlib might be following:
unsigned inflatemem (char* dest, const char* source) unsigned inflatemem (char* dest, const char* source)
{ {
z_stream stream; z_stream stream;
stream.next_in = (Bytef*) source; stream.next_in = (Bytef*) source;
stream.avail_in = 65535; stream.avail_in = 65535;
stream.next_out = dest; stream.next_out = dest;
stream.avail_out = 65535; stream.avail_out = 65535;
stream.zalloc = (alloc_func) 0; stream.zalloc = (alloc_func) 0;
stream.zfree = (free_func) 0; stream.zfree = (free_func) 0;
inflateInit2(&stream, -MAX_WBITS); inflateInit2(&stream, -MAX_WBITS);
inflate(&stream, Z_FINISH); inflate(&stream, Z_FINISH);
inflateEnd(&stream); inflateEnd(&stream);
return stream.total_out; return stream.total_out;
} }
*/ */
int __fastcall__ uncompress (char* dest, unsigned* destLen, int __fastcall__ uncompress (char* dest, unsigned* destLen,
const char* source, unsigned sourceLen); const char* source, unsigned sourceLen);
/* /*
Original zlib description: Original zlib description:
Decompresses the source buffer into the destination buffer. sourceLen is Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.) by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer. Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the This function can be used to decompress a whole file at once if the
input file is mmap'ed. input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted. buffer, or Z_DATA_ERROR if the input data was corrupted.
Implementation notes: Implementation notes:
This function expects data in the ZLIB format, described in RFC 1950 This function expects data in the ZLIB format, described in RFC 1950
in the file ftp://ds.internic.net/rfc/rfc1950.txt. The ZLIB format is in the file ftp://ds.internic.net/rfc/rfc1950.txt. The ZLIB format is
essentially the DEFLATE format plus a very small header and Adler-32 essentially the DEFLATE format plus a very small header and Adler-32
checksum. checksum.
Z_MEM_ERROR and Z_BUF_ERROR are never returned in this implementation. Z_MEM_ERROR and Z_BUF_ERROR are never returned in this implementation.
*/ */
unsigned long __fastcall__ adler32 (unsigned long adler, const char* buf, unsigned long __fastcall__ adler32 (unsigned long adler, const char* buf,
unsigned len); unsigned len);
/* /*
Original zlib description: Original zlib description:
Update a running Adler-32 checksum with the bytes buf[0..len-1] and Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum. the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example: much faster. Usage example:
unsigned long adler = adler32(0L, Z_NULL, 0); unsigned long adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) { while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length); adler = adler32(adler, buffer, length);
} }
if (adler != original_adler) error(); if (adler != original_adler) error();
Implementation notes: Implementation notes:
This function isn't actually much faster than crc32(), but it is smaller This function isn't actually much faster than crc32(), but it is smaller
and does not use any lookup tables. and does not use any lookup tables.
*/ */
unsigned long __fastcall__ crc32 (unsigned long crc, const char* buf, unsigned long __fastcall__ crc32 (unsigned long crc, const char* buf,
unsigned len); unsigned len);
/* /*
Original zlib description: Original zlib description:
Update a running crc with the bytes buf[0..len-1] and return the updated Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application. within this function so it shouldn't be done by the application.
Usage example: Usage example:
unsigned long crc = crc32(0L, Z_NULL, 0); unsigned long crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) { while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length); crc = crc32(crc, buffer, length);
} }
if (crc != original_crc) error(); if (crc != original_crc) error();
Implementation notes: Implementation notes:
This function uses statically allocated 1 KB lookup table. The table is This function uses statically allocated 1 KB lookup table. The table is
initialised before it is used for the first time (that is, if buffer is initialised before it is used for the first time (that is, if buffer is
NULL or length is zero, then the lookup table isn't initialised). NULL or length is zero, then the lookup table isn't initialised).
*/ */
/* end of zlib.h */ /* end of zlib.h */
#endif #endif

View File

@ -1,376 +1,376 @@
; ;
; Extended memory driver for 65816 based extra RAM. Driver works without ; Extended memory driver for 65816 based extra RAM. Driver works without
; problems when statically linked. ; problems when statically linked.
; ;
; Marco van den Heuvel, 2015-12-01 ; Marco van den Heuvel, 2015-12-01
; ;
.include "zeropage.inc" .include "zeropage.inc"
.include "em-kernel.inc" .include "em-kernel.inc"
.include "em-error.inc" .include "em-error.inc"
.macpack generic .macpack generic
.macpack module .macpack module
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Header. Includes jump table ; Header. Includes jump table
module_header _c64_65816_emd module_header _c64_65816_emd
; Driver signature ; Driver signature
.byte $65, $6d, $64 ; "emd" .byte $65, $6d, $64 ; "emd"
.byte EMD_API_VERSION ; EM API version number .byte EMD_API_VERSION ; EM API version number
; Library reference ; Library reference
.addr $0000 .addr $0000
; Jump table ; Jump table
.addr INSTALL .addr INSTALL
.addr UNINSTALL .addr UNINSTALL
.addr PAGECOUNT .addr PAGECOUNT
.addr MAP .addr MAP
.addr USE .addr USE
.addr COMMIT .addr COMMIT
.addr COPYFROM .addr COPYFROM
.addr COPYTO .addr COPYTO
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Data. ; Data.
.bss .bss
isnotscpu: .res 1 ; SuperCPU not present isnotscpu: .res 1 ; SuperCPU not present
curpage: .res 1 ; Current page number curpage: .res 1 ; Current page number
curbank: .res 1 ; Current bank number (+1) curbank: .res 1 ; Current bank number (+1)
bankcount: .res 1 ; Number of available banks (pages = banks * 256) bankcount: .res 1 ; Number of available banks (pages = banks * 256)
window: .res 256 ; Memory "window" window: .res 256 ; Memory "window"
.code .code
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If ; INSTALL routine. Is called after the driver is loaded into memory. If
; possible, check if the hardware is present and determine the amount of ; possible, check if the hardware is present and determine the amount of
; memory available. ; memory available.
; Must return an EM_ERR_xx code in a/x. ; Must return an EM_ERR_xx code in a/x.
; ;
INSTALL: INSTALL:
sei sei
clc clc
sed sed
lda #$99 lda #$99
adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly
cld cld
bne @not_present bne @not_present
clc clc
.P816 .P816
sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02 sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02
.P02 .P02
bcc @not_present bcc @not_present
lda $d0bc lda $d0bc
and #$80 and #$80
sta isnotscpu sta isnotscpu
lda $07e8 lda $07e8
pha ; save value incase it was used somewhere else pha ; save value incase it was used somewhere else
ldx #$ff ldx #$ff
@fillloop: ; fill from top (bank 255) to bottom @fillloop: ; fill from top (bank 255) to bottom
txa txa
pha pha
.P816 .P816
plb ; pull dbr plb ; pull dbr
.P02 .P02
stx $07e8 stx $07e8
dex dex
cpx #$ff cpx #$ff
bne @fillloop bne @fillloop
inx inx
@compareloop: ; check from bottom to top @compareloop: ; check from bottom to top
txa txa
pha pha
.P816 .P816
plb plb
.P02 .P02
cmp $07e8 cmp $07e8
bne @found_pages bne @found_pages
.P816 .P816
inc inc
.P02 .P02
sta $07e8 sta $07e8
cmp $07e8 cmp $07e8
bne @found_pages bne @found_pages
inx inx
bne @compareloop bne @compareloop
@found_pages: @found_pages:
dex dex
lda #$00 lda #$00
pha pha
.P816 .P816
plb plb
.P02 .P02
pla pla
sta $07e8 sta $07e8
cli cli
lda isnotscpu lda isnotscpu
bne @noextradex bne @noextradex
dex dex
@noextradex: @noextradex:
stx bankcount stx bankcount
lda #<EM_ERR_OK lda #<EM_ERR_OK
ldx #>EM_ERR_OK ldx #>EM_ERR_OK
rts rts
@not_present: @not_present:
cli cli
lda #<EM_ERR_NO_DEVICE lda #<EM_ERR_NO_DEVICE
ldx #>EM_ERR_NO_DEVICE ldx #>EM_ERR_NO_DEVICE
; rts ; Run into UNINSTALL instead ; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory. ; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything. ; Can do cleanup or whatever. Must not return anything.
; ;
UNINSTALL: UNINSTALL:
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: Return the total number of available pages in a/x.
; ;
PAGECOUNT: PAGECOUNT:
lda #$00 ; a whole bank is either usable or not lda #$00 ; a whole bank is either usable or not
ldx bankcount ldx bankcount
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; MAP: Map the page in a/x into memory and return a pointer to the page in ; MAP: Map the page in a/x into memory and return a pointer to the page in
; a/x. The contents of the currently mapped page (if any) may be discarded ; a/x. The contents of the currently mapped page (if any) may be discarded
; by the driver. ; by the driver.
; ;
MAP: sta curpage ; Remember the new page MAP: sta curpage ; Remember the new page
stx curbank ; Remember the new bank stx curbank ; Remember the new bank
sta ptr2+1 ; src address low sta ptr2+1 ; src address low
lda #$00 lda #$00
sta ptr2 ; src address high sta ptr2 ; src address high
inx inx
ldy isnotscpu ; check if not scpu ldy isnotscpu ; check if not scpu
bne @notscpu bne @notscpu
inx inx
@notscpu: @notscpu:
stx tmp2 ; src bank stx tmp2 ; src bank
sta tmp1 ; dst bank sta tmp1 ; dst bank
sta ptr3+1 ; length high sta ptr3+1 ; length high
lda #$ff lda #$ff
sta ptr3 ; length low sta ptr3 ; length low
lda #<window lda #<window
sta ptr1 ; dst address low sta ptr1 ; dst address low
ldx #>window ldx #>window
stx ptr1+1 ; dst address high stx ptr1+1 ; dst address high
jsr transfer jsr transfer
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; USE: Tell the driver that the window is now associated with a given page. ; USE: Tell the driver that the window is now associated with a given page.
USE: sta curpage ; Remember the page USE: sta curpage ; Remember the page
stx curbank ; Remember the bank stx curbank ; Remember the bank
lda #<window lda #<window
ldx #>window ; Return the window ldx #>window ; Return the window
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; COMMIT: Commit changes in the memory window to extended storage. ; COMMIT: Commit changes in the memory window to extended storage.
COMMIT: lda curpage ; Get the current page COMMIT: lda curpage ; Get the current page
sta ptr1+1 ; dst high sta ptr1+1 ; dst high
ldx #$00 ldx #$00
stx ptr1 ; dst low stx ptr1 ; dst low
lda #<window lda #<window
sta ptr2 ; src low sta ptr2 ; src low
lda #>window lda #>window
sta ptr2+1 ; src high sta ptr2+1 ; src high
stx ptr3+1 ; length high stx ptr3+1 ; length high
lda #$ff lda #$ff
sta ptr3 ; length low sta ptr3 ; length low
stx tmp2 ; src bank stx tmp2 ; src bank
ldy curbank ; Get the current bank ldy curbank ; Get the current bank
iny iny
ldx isnotscpu ldx isnotscpu
bne @notascpu bne @notascpu
iny iny
@notascpu: @notascpu:
sty tmp1 ; dst bank sty tmp1 ; dst bank
jsr transfer jsr transfer
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; COPYFROM: Copy from extended into linear memory. A pointer to a structure ; COPYFROM: Copy from extended into linear memory. A pointer to a structure
; describing the request is passed in a/x. ; describing the request is passed in a/x.
; The function must not return anything. ; The function must not return anything.
; ;
COPYFROM: COPYFROM:
sta ptr4 sta ptr4
stx ptr4+1 ; Save the passed em_copy pointer stx ptr4+1 ; Save the passed em_copy pointer
ldy #EM_COPY::COUNT+1 ; start at the end of the struct ldy #EM_COPY::COUNT+1 ; start at the end of the struct
lda (ptr4),y ; get high byte of count lda (ptr4),y ; get high byte of count
tax tax
dey dey
lda (ptr4),y ; get low byte of count lda (ptr4),y ; get low byte of count
bne @nodex bne @nodex
dex dex
@nodex: @nodex:
.P816 .P816
dec dec
.P02 .P02
sta ptr3 ; length low sta ptr3 ; length low
stx ptr3+1 ; length high stx ptr3+1 ; length high
dey dey
lda (ptr4),y ; get bank lda (ptr4),y ; get bank
.P816 .P816
inc inc
.P02 .P02
ldx isnotscpu ldx isnotscpu
bne @notscpu64 bne @notscpu64
.P816 .P816
inc inc
.P02 .P02
@notscpu64: @notscpu64:
sta tmp2 ; src bank sta tmp2 ; src bank
dey dey
lda (ptr4),y ; get page lda (ptr4),y ; get page
sta ptr2+1 ; src high sta ptr2+1 ; src high
dey dey
lda (ptr4),y ; get offset in page lda (ptr4),y ; get offset in page
sta ptr2 ; src low sta ptr2 ; src low
dey dey
lda (ptr4),y ; get memory buffer high lda (ptr4),y ; get memory buffer high
sta ptr1+1 ; dst high sta ptr1+1 ; dst high
dey dey
lda (ptr4),y ; get memory buffer low lda (ptr4),y ; get memory buffer low
sta ptr1 ; dst low sta ptr1 ; dst low
lda #$00 lda #$00
sta tmp1 ; dst bank sta tmp1 ; dst bank
jsr transfer jsr transfer
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; COPYTO: Copy from linear into extended memory. A pointer to a structure ; COPYTO: Copy from linear into extended memory. A pointer to a structure
; describing the request is passed in a/x. ; describing the request is passed in a/x.
; The function must not return anything. ; The function must not return anything.
; ;
COPYTO: sta ptr4 COPYTO: sta ptr4
stx ptr4+1 ; Save the passed em_copy pointer stx ptr4+1 ; Save the passed em_copy pointer
ldy #EM_COPY::COUNT+1 ; start at the end of the struct ldy #EM_COPY::COUNT+1 ; start at the end of the struct
lda (ptr4),y ; get high byte of count lda (ptr4),y ; get high byte of count
tax tax
dey dey
lda (ptr4),y ; get low byte of count lda (ptr4),y ; get low byte of count
bne @nodex2 bne @nodex2
dex dex
@nodex2: @nodex2:
.P816 .P816
dec dec
.P02 .P02
sta ptr3 ; length low sta ptr3 ; length low
txa txa
sta ptr3+1 ; length high sta ptr3+1 ; length high
dey dey
lda (ptr4),y ; get bank lda (ptr4),y ; get bank
.P816 .P816
inc inc
.P02 .P02
ldx isnotscpu ldx isnotscpu
bne @notascpu64 bne @notascpu64
.P816 .P816
inc inc
.P02 .P02
@notascpu64: @notascpu64:
sta tmp1 ; dst bank sta tmp1 ; dst bank
dey dey
lda (ptr4),y ; get page lda (ptr4),y ; get page
sta ptr1+1 ; dst high sta ptr1+1 ; dst high
dey dey
lda (ptr4),y ; get page offset lda (ptr4),y ; get page offset
sta ptr1 ; dst low sta ptr1 ; dst low
dey dey
lda (ptr4),y ; get memory buffer high lda (ptr4),y ; get memory buffer high
sta ptr2+1 ; src low sta ptr2+1 ; src low
dey dey
lda (ptr4),y ; get memory buffer low lda (ptr4),y ; get memory buffer low
sta ptr2 ; src high sta ptr2 ; src high
lda #$00 lda #$00
sta tmp2 ; src bank sta tmp2 ; src bank
jsr transfer jsr transfer
rts rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Helper function for moving a block, the following is used: ; Helper function for moving a block, the following is used:
; ptr1: dst ; ptr1: dst
; ptr2: src ; ptr2: src
; ptr3: length ; ptr3: length
; tmp1: dst bank ; tmp1: dst bank
; tmp2: src bank ; tmp2: src bank
transfer: transfer:
.P816 .P816
.A8 .A8
.I8 .I8
sei sei
pha pha
phx phx
phy phy
ldx tmp1 ; load srcbank ldx tmp1 ; load srcbank
stx @move+1 ; store srcbank in move + 1 stx @move+1 ; store srcbank in move + 1
ldy tmp2 ; load dstbank ldy tmp2 ; load dstbank
sty @move+2 ; store dstbank in move + 2 sty @move+2 ; store dstbank in move + 2
clc ; switch to native mode clc ; switch to native mode
xce xce
php ; save status bits php ; save status bits
rep #%00110000 ; set A and index to 16bit rep #%00110000 ; set A and index to 16bit
.A16 .A16
.I16 .I16
ldy ptr1 ldy ptr1
ldx ptr2 ldx ptr2
lda ptr3 lda ptr3
@move: @move:
mvn 0,0 mvn 0,0
plp ; restore status bits plp ; restore status bits
.A8 .A8
.I8 .I8
lda #$00 lda #$00
pha pha
plb ; restore dbr plb ; restore dbr
sec sec
xce ; switch to emul mode xce ; switch to emul mode
ply ply
plx plx
pla pla
cli cli
rts rts
.P02 .P02

View File

@ -1,50 +1,50 @@
; ;
; char cgetc (void); ; char cgetc (void);
; ;
.constructor initcgetc .constructor initcgetc
.export _cgetc .export _cgetc
.import cursor .import cursor
.include "osic1p.inc" .include "osic1p.inc"
.include "extzp.inc" .include "extzp.inc"
.include "zeropage.inc" .include "zeropage.inc"
; Initialize one-character buffer that is filled by kbhit() ; Initialize one-character buffer that is filled by kbhit()
.segment "ONCE" .segment "ONCE"
initcgetc: initcgetc:
lda #$00 lda #$00
sta CHARBUF ; No character in buffer initially sta CHARBUF ; No character in buffer initially
rts rts
; Input routine from 65V PROM MONITOR, show cursor if enabled ; Input routine from 65V PROM MONITOR, show cursor if enabled
.code .code
_cgetc: _cgetc:
lda CHARBUF ; character in buffer available? lda CHARBUF ; character in buffer available?
beq nobuffer beq nobuffer
tax ; save character in X tax ; save character in X
lda #$00 lda #$00
sta CHARBUF ; empty buffer sta CHARBUF ; empty buffer
beq restorex ; restore X and return beq restorex ; restore X and return
nobuffer: nobuffer:
lda cursor ; show cursor? lda cursor ; show cursor?
beq nocursor beq nocursor
ldy CURS_X ldy CURS_X
lda (SCREEN_PTR),y ; fetch current character lda (SCREEN_PTR),y ; fetch current character
sta tmp1 ; save it sta tmp1 ; save it
lda #$A1 ; full white square lda #$A1 ; full white square
sta (SCREEN_PTR),y ; store at cursor position sta (SCREEN_PTR),y ; store at cursor position
nocursor: nocursor:
jsr INPUTC ; get input character in A jsr INPUTC ; get input character in A
ldx cursor ldx cursor
beq done ; was cursor on? beq done ; was cursor on?
tax ; save A in X tax ; save A in X
lda tmp1 ; fetch saved character lda tmp1 ; fetch saved character
ldy CURS_X ldy CURS_X
sta (SCREEN_PTR),y ; store at cursor position sta (SCREEN_PTR),y ; store at cursor position
restorex: restorex:
txa ; restore saved character from X txa ; restore saved character from X
done: done:
ldx #$00 ; high byte of int return value ldx #$00 ; high byte of int return value
rts rts

View File

@ -1,4 +1,4 @@
; Addresses ; Addresses
INPUTC := $FD00 ; Input character from keyboard INPUTC := $FD00 ; Input character from keyboard
RESET := $FF00 ; Reset address, show boot prompt RESET := $FF00 ; Reset address, show boot prompt
KBD := $DF00 ; Polled keyboard register KBD := $DF00 ; Polled keyboard register

View File

@ -1,183 +1,183 @@
; ;
; Macro definitions for screen layout modules ; Macro definitions for screen layout modules
; ;
.include "extzp.inc" .include "extzp.inc"
.linecont + .linecont +
; ;
; Internal function for screensize() ; Internal function for screensize()
; ;
.macro osi_screensize ScrWidth, ScrHeight .macro osi_screensize ScrWidth, ScrHeight
; Macro implementation of internal screensize ; Macro implementation of internal screensize
; function for given width and height in ; function for given width and height in
; characters ; characters
.export screensize .export screensize
.proc screensize .proc screensize
ldx #ScrWidth ldx #ScrWidth
ldy #ScrHeight ldy #ScrHeight
rts rts
.endproc .endproc
.endmacro .endmacro
; ;
; void clrscr (void); ; void clrscr (void);
; ;
.macro osi_clrscr ScrBase, ScrRamSize .macro osi_clrscr ScrBase, ScrRamSize
.export _clrscr .export _clrscr
.proc _clrscr .proc _clrscr
lda #<ScrBase ; Fill whole video RAM with blanks by calling lda #<ScrBase ; Fill whole video RAM with blanks by calling
ldx #>ScrBase ; memset appropriately ldx #>ScrBase ; memset appropriately
jsr pushax jsr pushax
lda #' ' lda #' '
ldx #$00 ldx #$00
jsr pushax jsr pushax
lda #<ScrRamSize lda #<ScrRamSize
ldx #>ScrRamSize ldx #>ScrRamSize
jsr _memset jsr _memset
lda #$00 ; Cursor in upper left corner lda #$00 ; Cursor in upper left corner
sta CURS_X sta CURS_X
sta CURS_Y sta CURS_Y
jmp plot ; Set the cursor position jmp plot ; Set the cursor position
.endproc .endproc
.endmacro .endmacro
; ;
; cputc/cputcxy for Challenger 1P ; cputc/cputcxy for Challenger 1P
; Based on PET/CBM implementation ; Based on PET/CBM implementation
; ;
.macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ .macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \
ScrollDist, ScrLo, ScrHi ScrollDist, ScrLo, ScrHi
; Number of characters to move for scrolling ; Number of characters to move for scrolling
; by one line ; by one line
ScrollLength = (ScrHeight - 1) * ScrollDist ScrollLength = (ScrHeight - 1) * ScrollDist
; ;
; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c); ; void cputc (char c);
; ;
.export _cputcxy, _cputc, cputdirect, putchar .export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot .export newline, plot
_cputcxy: _cputcxy:
pha ; Save C pha ; Save C
jsr gotoxy ; Set cursor, drop x and y jsr gotoxy ; Set cursor, drop x and y
pla ; Restore C pla ; Restore C
; Plot a character - also used as internal function ; Plot a character - also used as internal function
_cputc: cmp #$0A ; CR? _cputc: cmp #$0A ; CR?
bne L1 bne L1
lda #0 lda #0
sta CURS_X sta CURS_X
beq plot ; Recalculate pointers beq plot ; Recalculate pointers
L1: cmp #$0D ; LF? L1: cmp #$0D ; LF?
beq newline ; Recalculate pointers beq newline ; Recalculate pointers
cputdirect: cputdirect:
jsr putchar ; Write the character to the screen jsr putchar ; Write the character to the screen
; Advance cursor position, register Y contains horizontal position after ; Advance cursor position, register Y contains horizontal position after
; putchar ; putchar
cpy #(ScrWidth - 1) ; Check whether line is full cpy #(ScrWidth - 1) ; Check whether line is full
bne L3 bne L3
jsr newline ; New line jsr newline ; New line
ldy #$FF ; + cr ldy #$FF ; + cr
L3: iny L3: iny
sty CURS_X sty CURS_X
rts rts
newline: newline:
inc CURS_Y inc CURS_Y
lda CURS_Y lda CURS_Y
cmp #ScrHeight ; Screen height cmp #ScrHeight ; Screen height
bne plot bne plot
dec CURS_Y ; Bottom of screen reached, scroll dec CURS_Y ; Bottom of screen reached, scroll
; Scroll destination address ; Scroll destination address
lda #<(ScrBase + ScrFirstChar) lda #<(ScrBase + ScrFirstChar)
ldx #>(ScrBase + ScrFirstChar) ldx #>(ScrBase + ScrFirstChar)
jsr pushax jsr pushax
; Scroll source address ; Scroll source address
lda #<(ScrBase + ScrFirstChar + ScrollDist) lda #<(ScrBase + ScrFirstChar + ScrollDist)
ldx #>(ScrBase + ScrFirstChar + ScrollDist) ldx #>(ScrBase + ScrFirstChar + ScrollDist)
jsr pushax jsr pushax
; Number of characters to move ; Number of characters to move
lda #<ScrollLength lda #<ScrollLength
ldx #>ScrollLength ldx #>ScrollLength
jsr _memmove jsr _memmove
; Address of first character in last line ; Address of first character in last line
; of screen ; of screen
lda #<(ScrBase + ScrFirstChar + ScrollLength) lda #<(ScrBase + ScrFirstChar + ScrollLength)
sta ptr1 sta ptr1
lda #>(ScrBase + ScrFirstChar + ScrollLength) lda #>(ScrBase + ScrFirstChar + ScrollLength)
sta ptr1+1 sta ptr1+1
ldy #ScrWidth ; Fill last line with blanks ldy #ScrWidth ; Fill last line with blanks
lda #' ' lda #' '
clrln: sta (ptr1),y clrln: sta (ptr1),y
dey dey
bpl clrln bpl clrln
plot: ldy CURS_Y plot: ldy CURS_Y
lda ScrLo,y lda ScrLo,y
sta SCREEN_PTR sta SCREEN_PTR
lda ScrHi,y lda ScrHi,y
sta SCREEN_PTR+1 sta SCREEN_PTR+1
rts rts
; Write one character to the screen without doing anything else, return X ; Write one character to the screen without doing anything else, return X
; position in register Y ; position in register Y
putchar: putchar:
ldy CURS_X ldy CURS_X
sta (SCREEN_PTR),y ; Set char sta (SCREEN_PTR),y ; Set char
rts rts
.endmacro .endmacro
.macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \ .macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \
ScrWidth, ScrHeight, ScrollDist ScrWidth, ScrHeight, ScrollDist
.import gotoxy .import gotoxy
.import _memmove, _memset, pushax .import _memmove, _memset, pushax
.importzp ptr1 .importzp ptr1
.rodata .rodata
; Screen address tables - offset to real screen ; Screen address tables - offset to real screen
ScrTabLo: ScrTabLo:
.repeat ScrHeight, I .repeat ScrHeight, I
.byte <(ScrBase + ScrFirstChar + I * ScrollDist) .byte <(ScrBase + ScrFirstChar + I * ScrollDist)
.endrep .endrep
ScrTabHi: ScrTabHi:
.repeat ScrHeight, I .repeat ScrHeight, I
.byte >(ScrBase + ScrFirstChar + I * ScrollDist) .byte >(ScrBase + ScrFirstChar + I * ScrollDist)
.endrep .endrep
.code .code
osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \
ScrollDist, ScrTabLo, ScrTabHi ScrollDist, ScrTabLo, ScrTabHi
osi_screensize ScrWidth, ScrHeight osi_screensize ScrWidth, ScrHeight
osi_clrscr ScrBase, ScrRamSize osi_clrscr ScrBase, ScrRamSize
.endmacro .endmacro

View File

@ -1,38 +1,38 @@
/* /*
!!DESCRIPTION!! div/mod test !!DESCRIPTION!! div/mod test
!!ORIGIN!! !!ORIGIN!!
!!LICENCE!! public domain !!LICENCE!! public domain
*/ */
#include <stdio.h> #include <stdio.h>
void printc(signed char a,signed char b){ void printc(signed char a,signed char b){
signed char x=a/b,y=a%b,z=a*b; signed char x=a/b,y=a%b,z=a*b;
printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z); printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z);
} }
void prints(short a,short b){ void prints(short a,short b){
short x=a/b,y=a%b,z=a*b; short x=a/b,y=a%b,z=a*b;
printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z); printf("%3d,%3d is %3d,%3d,%3d\n",a,b,x,y,z);
} }
void printl(long a,long b){ void printl(long a,long b){
long x=a/b,y=a%b,z=a*b; long x=a/b,y=a%b,z=a*b;
printf("%3ld,%3ld is %3ld,%3ld,%3ld\n",a,b,x,y,z); printf("%3ld,%3ld is %3ld,%3ld,%3ld\n",a,b,x,y,z);
} }
int main(void) { int main(void) {
printl( 3,-2); printl( 3,-2);
printl(-3,-2); printl(-3,-2);
printl(-3, 2); printl(-3, 2);
printl( 3, 2); printl( 3, 2);
printf("-\n"); printf("-\n");
prints( 3,-2); prints( 3,-2);
prints(-3,-2); prints(-3,-2);
prints(-3, 2); prints(-3, 2);
prints( 3, 2); prints( 3, 2);
printf("-\n"); printf("-\n");
printc( 3,-2); printc( 3,-2);
printc(-3,-2); printc(-3,-2);
printc(-3, 2); printc(-3, 2);
printc( 3, 2); printc( 3, 2);
return 0; return 0;
} }

View File

@ -1,95 +1,95 @@
/* /*
!!DESCRIPTION!! variable initialization !!DESCRIPTION!! variable initialization
!!ORIGIN!! LCC 4.1 Testsuite !!ORIGIN!! LCC 4.1 Testsuite
!!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC !!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
*/ */
#include "common.h" #include "common.h"
/* todo: add back conditional stuff here ! */ /* todo: add back conditional stuff here ! */
typedef struct { int codes[3]; char name[6]; } Word; typedef struct { int codes[3]; char name[6]; } Word;
#ifdef NO_IMPLICIT_FUNC_PROTOTYPES #ifdef NO_IMPLICIT_FUNC_PROTOTYPES
#ifdef NO_OLD_FUNC_DECL #ifdef NO_OLD_FUNC_DECL
f(); f();
void g(Word *p); void g(Word *p);
h(); h();
#else #else
f(); f();
g(); g();
h(); h();
#endif #endif
#endif #endif
/* /*
Word words[] = { Word words[] = {
1, 2, 3,"if", 1, 2, 3,"if",
{ { 4, 5 }, { 'f', 'o', 'r' } }, { { 4, 5 }, { 'f', 'o', 'r' } },
6, 7, 8, {"else"}, 6, 7, 8, {"else"},
{ { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', }, { { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', },
{ 0 }, { 0 },
}, *wordlist = words; }, *wordlist = words;
*/ */
Word words[] = { Word words[] = {
{{1, 2, 3},"if"}, {{1, 2, 3},"if"},
{ { 4, 5 }, { 'f', 'o', 'r' } }, { { 4, 5 }, { 'f', 'o', 'r' } },
{{6, 7, 8}, "else"}, {{6, 7, 8}, "else"},
{ { 9, 10, 11}, {'w', 'h', 'i', 'l', 'e', }}, { { 9, 10, 11}, {'w', 'h', 'i', 'l', 'e', }},
{{ 0 }}, {{ 0 }},
}, *wordlist = words; }, *wordlist = words;
/*int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };*/ /*int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };*/
int x[][5] = { {1, 2, 3, 4, 0 }, { 5, 6 }, { 7 } }; int x[][5] = { {1, 2, 3, 4, 0 }, { 5, 6 }, { 7 } };
int *y[] = { x[0], x[1], x[2], 0 }; int *y[] = { x[0], x[1], x[2], 0 };
main() main()
{ {
int i, j; int i, j;
for (i = 0; y[i]; i++) { for (i = 0; y[i]; i++) {
for (j = 0; y[i][j]; j++) for (j = 0; y[i][j]; j++)
printf(" %d", y[i][j]); printf(" %d", y[i][j]);
printf("\n"); printf("\n");
} }
f(); f();
g(wordlist); g(wordlist);
return 0; return 0;
} }
f() { f() {
static char *keywords[] = {"if", "for", "else", "while", 0, }; static char *keywords[] = {"if", "for", "else", "while", 0, };
char **p; char **p;
for (p = keywords; *p; p++) for (p = keywords; *p; p++)
printf("%s\n", *p); printf("%s\n", *p);
} }
#ifdef NO_OLD_FUNC_DECL #ifdef NO_OLD_FUNC_DECL
void g(Word *p) void g(Word *p)
#else #else
g(p) g(p)
Word *p; Word *p;
#endif #endif
{ {
int i; int i;
for ( ; p->codes[0]; p++) { for ( ; p->codes[0]; p++) {
for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++) for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++)
printf("%d ", p->codes[i]); printf("%d ", p->codes[i]);
printf("%s\n", p->name); printf("%s\n", p->name);
} }
h(); h();
} }
h() h()
{ {
int i; int i;
for (i = 0; i < sizeof(words)/sizeof(Word); i++) for (i = 0; i < sizeof(words)/sizeof(Word); i++)
printf("%d %d %d %s\n", words[i].codes[0], printf("%d %d %d %s\n", words[i].codes[0],
words[i].codes[1], words[i].codes[2], words[i].codes[1], words[i].codes[2],
&words[i].name[0]); &words[i].name[0]);
} }

View File

@ -1,112 +1,112 @@
/* /*
!!DESCRIPTION!! pointer test !!DESCRIPTION!! pointer test
!!ORIGIN!! !!ORIGIN!!
!!LICENCE!! public domain !!LICENCE!! public domain
*/ */
#include "common.h" #include "common.h"
#include <stdio.h> #include <stdio.h>
/* /*
check behaviour on incompletely declared arrays check behaviour on incompletely declared arrays
*/ */
char i1[]; char i1[];
void test1(void) { void test1(void) {
int a; int a;
a=sizeof(i1[0]); a=sizeof(i1[0]);
printf("%04x - ",a); printf("%04x - ",a);
if(sizeof(i1[0])==sizeof(char)) { if(sizeof(i1[0])==sizeof(char)) {
/* gcc gives size of element */ /* gcc gives size of element */
printf("sizeof(i1[0]) gives size of element\n"); printf("sizeof(i1[0]) gives size of element\n");
} }
if(sizeof(i1[0])==sizeof(char*)) { if(sizeof(i1[0])==sizeof(char*)) {
printf("sizeof(i1[0]) gives size of pointer to element\n"); printf("sizeof(i1[0]) gives size of pointer to element\n");
} }
} }
/* /*
check behaviour on string init check behaviour on string init
*/ */
char t1[]="abcde"; char t1[]="abcde";
char t2[]={"abcde"}; char t2[]={"abcde"};
char *t3="abcde"; char *t3="abcde";
char *t4={"abcde"}; char *t4={"abcde"};
void test2(void) { void test2(void) {
char c1,c2,c3,c4; char c1,c2,c3,c4;
int i,e=0; int i,e=0;
for(i=0;i<5;i++){ for(i=0;i<5;i++){
c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i]; c1=t1[i];c2=t2[i];c3=t3[i];c4=t4[i];
/* printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */ /* printf("%02x %02x %02x %02x\n",c1,c2,c3,c4); */
printf("%c %c %c %c\n",c1,c2,c3,c4); printf("%c %c %c %c\n",c1,c2,c3,c4);
if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1; if(!((c1==c2)&(c1==c3)&(c1==c4))) e=1;
} }
if(e) printf("test2 failed.\n"); if(e) printf("test2 failed.\n");
else printf("test2 ok.\n"); else printf("test2 ok.\n");
} }
/* /*
check behaviour on extern-declarations inside functions check behaviour on extern-declarations inside functions
*/ */
typedef struct { typedef struct {
char *name; char *name;
void *func; void *func;
} A3; } A3;
#ifdef NO_SLOPPY_STRUCT_INIT #ifdef NO_SLOPPY_STRUCT_INIT
A3 a3[] = { A3 a3[] = {
{ "test3", (void*) NULL }, { "test3", (void*) NULL },
{ "test3", (void*) NULL }, { "test3", (void*) NULL },
}; };
#else #else
/*gcc warning: missing braces around initializer (near initialization for `a3[0]') /*gcc warning: missing braces around initializer (near initialization for `a3[0]')
this type of struct-initialization seems to be kinda common */ this type of struct-initialization seems to be kinda common */
A3 a3[] = { A3 a3[] = {
"test3", (void*) NULL , "test3", (void*) NULL ,
"test3", (void*) NULL , "test3", (void*) NULL ,
}; };
#endif #endif
void test3a(A3 *list, int number){ void test3a(A3 *list, int number){
printf("%s %d\n",list->name,number); printf("%s %d\n",list->name,number);
} }
static void test31(void) static void test31(void)
{ {
extern A3 a3[]; extern A3 a3[];
test3a(a3, -1); test3a(a3, -1);
} }
#if 0 #if 0
/* this variation compiles and works with cc65, but gives an error with gcc :=P */ /* this variation compiles and works with cc65, but gives an error with gcc :=P */
static void test32(void) static void test32(void)
{ {
extern A3 *a3; extern A3 *a3;
test3a(a3, -1); test3a(a3, -1);
} }
#endif #endif
static void test30(void) static void test30(void)
{ {
test3a(a3, -1); test3a(a3, -1);
} }
/* /*
todo: add test on function pointers in the form of (*func)(arg) ... todo: add test on function pointers in the form of (*func)(arg) ...
cc65 seems to have problems here aswell ;/ cc65 seems to have problems here aswell ;/
*/ */
int main(void) { int main(void) {
test1(); test1();
test2(); test2();
test30(); test30();
test31(); test31();
/* test32(); */ /* test32(); */
return 0; return 0;
} }

View File

@ -1,262 +1,262 @@
/* /*
!!DESCRIPTION!! switch test !!DESCRIPTION!! switch test
!!ORIGIN!! !!ORIGIN!!
!!LICENCE!! public domain !!LICENCE!! public domain
*/ */
/*#define STANDALONE*/ /*#define STANDALONE*/
#include <stdio.h> #include <stdio.h>
void testlimits(int i) { void testlimits(int i) {
printf("%d:",i); printf("%d:",i);
switch(i) { switch(i) {
case -1: /* works */ case -1: /* works */
/* case 0xffff: */ /* 'range error' (-1) */ /* case 0xffff: */ /* 'range error' (-1) */
printf("-1\n"); printf("-1\n");
break; break;
/* max int */ /* max int */
/* case 0x7fff: */ /* works */ /* case 0x7fff: */ /* works */
case 32767: /* works */ case 32767: /* works */
/* case 32768: */ /* 'range error' (correct for that one!) */ /* case 32768: */ /* 'range error' (correct for that one!) */
printf("max\n"); printf("max\n");
break; break;
/* min int */ /* min int */
case -32768: /* 'warning. constant is long' */ case -32768: /* 'warning. constant is long' */
/* case 0x8000: */ /* 'range error' */ /* case 0x8000: */ /* 'range error' */
/* case -32769: */ /* 'range error' (correct for that one!) */ /* case -32769: */ /* 'range error' (correct for that one!) */
printf("min\n"); printf("min\n");
break; break;
} }
printf("\n"); printf("\n");
} }
void testdefault1(unsigned char i) { void testdefault1(unsigned char i) {
/* we want a signed char */ /* we want a signed char */
#ifdef REFCC #ifdef REFCC
#ifdef REFCC_UNSIGNED_CHARS #ifdef REFCC_UNSIGNED_CHARS
signed char k; signed char k;
#else #else
char k; char k;
#endif #endif
#else #else
#ifdef UNSIGNED_CHARS #ifdef UNSIGNED_CHARS
signed char k; signed char k;
#else #else
char k; char k;
#endif #endif
#endif #endif
for(;i<254;) { for(;i<254;) {
k = i; k = i;
printf(">%d\n",i);i++; printf(">%d\n",i);i++;
switch(k) { switch(k) {
case 1: case 1:
break; break;
case 2: case 2:
break; break;
case 3: case 3:
break; break;
case 4: case 4:
break; break;
case 5: case 5:
break; break;
case 6: case 6:
break; break;
case 7: case 7:
break; break;
case 8: case 8:
break; break;
case 9: case 9:
break; break;
case 10: case 10:
break; break;
case 11: case 11:
break; break;
case 12: case 12:
break; break;
case 13: case 13:
break; break;
case 14: case 14:
break; break;
case 15: case 15:
break; break;
case 17: case 17:
break; break;
/* triggers bug ? */ /* triggers bug ? */
/* gcc warning: case label value exceeds maximum value for type */ /* gcc warning: case label value exceeds maximum value for type */
/* cc65 error: range error */ /* cc65 error: range error */
/* /*
case 170: case 170:
break; break;
*/ */
case 18: case 18:
break; break;
case 19: case 19:
break; break;
case 20: case 20:
break; break;
case 21: case 21:
break; break;
case 22: case 22:
break; break;
case 23: case 23:
break; break;
case 24: case 24:
switch(k) { switch(k) {
case 1: case 1:
break; break;
case 2: case 2:
break; break;
case 3: case 3:
break; break;
case 4: case 4:
case 5: case 5:
break; break;
case 6: case 6:
case 7: case 7:
break; break;
case 8: case 8:
case 9: case 9:
break; break;
} }
break; break;
case 100: case 100:
break; break;
default: default:
printf(">>>default\n"); printf(">>>default\n");
/* triggers bug if this break; is missing? */ /* triggers bug if this break; is missing? */
/* break; */ /* break; */
} }
} }
} }
void testdefault2(unsigned char i) { void testdefault2(unsigned char i) {
/* we want a unsigned char */ /* we want a unsigned char */
#ifdef REFCC #ifdef REFCC
#ifdef REFCC_UNSIGNED_CHARS #ifdef REFCC_UNSIGNED_CHARS
char k; char k;
#else #else
unsigned char k; unsigned char k;
#endif #endif
#else #else
#ifdef UNSIGNED_CHARS #ifdef UNSIGNED_CHARS
char k; char k;
#else #else
unsigned char k; unsigned char k;
#endif #endif
#endif #endif
for(;i<254;) { for(;i<254;) {
k = i; k = i;
printf(">%d\n",i);i++; printf(">%d\n",i);i++;
switch(k) { switch(k) {
case 1: case 1:
break; break;
case 2: case 2:
break; break;
case 3: case 3:
break; break;
case 4: case 4:
break; break;
case 5: case 5:
break; break;
case 6: case 6:
break; break;
case 7: case 7:
break; break;
case 8: case 8:
break; break;
case 9: case 9:
break; break;
case 10: case 10:
break; break;
case 11: case 11:
break; break;
case 12: case 12:
break; break;
case 13: case 13:
break; break;
case 14: case 14:
break; break;
case 15: case 15:
break; break;
case 17: case 17:
break; break;
/* triggers bug ? */ /* triggers bug ? */
case 170: case 170:
break; break;
case 18: case 18:
break; break;
case 19: case 19:
break; break;
case 20: case 20:
break; break;
case 21: case 21:
break; break;
case 22: case 22:
break; break;
case 23: case 23:
break; break;
case 24: case 24:
switch(k) { switch(k) {
case 1: case 1:
break; break;
case 2: case 2:
break; break;
case 3: case 3:
break; break;
case 4: case 4:
case 5: case 5:
break; break;
case 6: case 6:
case 7: case 7:
break; break;
case 8: case 8:
case 9: case 9:
break; break;
} }
break; break;
case 100: case 100:
break; break;
default: default:
printf(">>>default\n"); printf(">>>default\n");
/* triggers bug if this break; is missing? */ /* triggers bug if this break; is missing? */
/* break; */ /* break; */
} }
} }
} }
int main(void) { int main(void) {
testlimits(32767); testlimits(32767);
testlimits(-32768); testlimits(-32768);
testlimits(-1); testlimits(-1);
testdefault1(1); testdefault1(1);
testdefault1(2); testdefault1(2);
testdefault1(3); testdefault1(3);
testdefault1(4); testdefault1(4);
testdefault2(1); testdefault2(1);
testdefault2(2); testdefault2(2);
testdefault2(3); testdefault2(3);
testdefault2(4); testdefault2(4);
return 0; return 0;
} }

View File

@ -1,105 +1,105 @@
/* /*
!!DESCRIPTION!! varargs test !!DESCRIPTION!! varargs test
!!ORIGIN!! !!ORIGIN!!
!!LICENCE!! public domain !!LICENCE!! public domain
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
void chk0(char *format,...); void chk0(char *format,...);
void chk1(int fd,char *format,...); void chk1(int fd,char *format,...);
#if 0 #if 0
// old workaround for broken varargs // old workaround for broken varargs
void chk0(char *format,...){ void chk0(char *format,...){
__asm__ ("pha"); // save argument size __asm__ ("pha"); // save argument size
{ {
//va_list ap; //va_list ap;
char *ap; char *ap;
char *_format; char *_format;
static char string[0x100]; static char string[0x100];
// va_start(ap,format); // va_start(ap,format);
__asm__ ("pla"); // restore argument size __asm__ ("pla"); // restore argument size
__asm__ ("ldx #$00"); // clear hibyte of AX __asm__ ("ldx #$00"); // clear hibyte of AX
ap=__AX__; ap=__AX__;
ap+=(char*)&format; ap+=(char*)&format;
// get value of format // get value of format
ap-=2; ap-=2;
_format=*((char**)ap); _format=*((char**)ap);
// vsprintf(string,format,ap); // vsprintf(string,format,ap);
vsprintf(&string[0],_format,ap); vsprintf(&string[0],_format,ap);
printf("format:%s,string:%s\n",_format,string); printf("format:%s,string:%s\n",_format,string);
// va_end(ap); // va_end(ap);
} }
}
void chk1(int fd,char *format,...){
__asm__ ("pha"); // save argument size
{
//va_list ap;
char *ap;
char *_format;
int _fd;
static char string[0x100];
// va_start(ap,format);
__asm__ ("pla"); // restore argument size
__asm__ ("ldx #$00"); // clear hibyte of AX
ap=__AX__;
ap+=(char*)&format;
// get value of fd
ap-=2;
_fd=*((int*)ap);
// get value of format
ap-=2;
_format=*((char**)ap);
// vsprintf(string,format,ap);
vsprintf(&string[0],_format,ap);
printf("fd:%d,format:%s,string:%s\n",_fd,_format,string);
// va_end(ap);
}
}
#endif
void chk0(char *format,...){
va_list ap;
static char string[0x100];
va_start(ap,format);
vsprintf(string,format,ap);
printf("format:%s,string:%s\n",format,string);
va_end(ap);
}
void chk1(int fd,char *format,...){
va_list ap;
static char string[0x100];
va_start(ap,format);
vsprintf(string,format,ap);
printf("fd:%d,format:%s,string:%s\n",fd,format,string);
va_end(ap);
} }
int main(int argc,char **argv) { void chk1(int fd,char *format,...){
printf("varargs test\n"); __asm__ ("pha"); // save argument size
{
printf("\nchk0/0:\n");chk0("chk0 %s","arg0"); //va_list ap;
printf("\nchk0/1:\n");chk0("chk0 %s %s","arg0","arg1"); char *ap;
printf("\nchk0/2:\n");chk0("chk0 %s %s %s","arg0","arg1","arg2"); char *_format;
int _fd;
printf("\nchk1/0:\n");chk1(0xfd,"chk1 %s","arg0"); static char string[0x100];
printf("\nchk1/1:\n");chk1(0xfd,"chk1 %s %s","arg0","arg1");
printf("\nchk1/2:\n");chk1(0xfd,"chk1 %s %s %s","arg0","arg1","arg2"); // va_start(ap,format);
__asm__ ("pla"); // restore argument size
__asm__ ("ldx #$00"); // clear hibyte of AX
ap=__AX__;
ap+=(char*)&format;
// get value of fd
ap-=2;
_fd=*((int*)ap);
// get value of format
ap-=2;
_format=*((char**)ap);
// vsprintf(string,format,ap);
vsprintf(&string[0],_format,ap);
printf("fd:%d,format:%s,string:%s\n",_fd,_format,string);
// va_end(ap);
}
}
#endif
void chk0(char *format,...){
va_list ap;
static char string[0x100];
va_start(ap,format);
vsprintf(string,format,ap);
printf("format:%s,string:%s\n",format,string);
va_end(ap);
}
void chk1(int fd,char *format,...){
va_list ap;
static char string[0x100];
va_start(ap,format);
vsprintf(string,format,ap);
printf("fd:%d,format:%s,string:%s\n",fd,format,string);
va_end(ap);
}
int main(int argc,char **argv) {
printf("varargs test\n");
printf("\nchk0/0:\n");chk0("chk0 %s","arg0");
printf("\nchk0/1:\n");chk0("chk0 %s %s","arg0","arg1");
printf("\nchk0/2:\n");chk0("chk0 %s %s %s","arg0","arg1","arg2");
printf("\nchk1/0:\n");chk1(0xfd,"chk1 %s","arg0");
printf("\nchk1/1:\n");chk1(0xfd,"chk1 %s %s","arg0","arg1");
printf("\nchk1/2:\n");chk1(0xfd,"chk1 %s %s %s","arg0","arg1","arg2");
return 0; return 0;
} }

View File

@ -1,170 +1,170 @@
/* mul-test.c -- Test the multiplication operator. */ /* mul-test.c -- Test the multiplication operator. */
#include <time.h> #include <time.h>
#include <conio.h> #include <conio.h>
#include <ctype.h> #include <ctype.h>
/* Number of elements in the progress bar. Use a power of 2, to avoid the /* Number of elements in the progress bar. Use a power of 2, to avoid the
** multiplication (which is about to be tested). ** multiplication (which is about to be tested).
*/ */
#define BAR_ELEMENTS 32U #define BAR_ELEMENTS 32U
#if defined(__CBM__) #if defined(__CBM__)
static const unsigned char revers_bar[8] = { static const unsigned char revers_bar[8] = {
0, 0, 0, 0, 0, 1, 1, 1 0, 0, 0, 0, 0, 1, 1, 1
}; };
static const unsigned char small_bar[8] = { static const unsigned char small_bar[8] = {
' ', 0xa5, 0xb4, 0xb5, 0xa1, 0xb6, 0xaa, 0xa7 ' ', 0xa5, 0xb4, 0xb5, 0xa1, 0xb6, 0xaa, 0xa7
}; };
#elif defined(__ATARI__) #elif defined(__ATARI__)
#endif #endif
/* Screen co-ordinates for the progress meter */ /* Screen co-ordinates for the progress meter */
static unsigned char Width, Height; static unsigned char Width, Height;
static unsigned char X, Y; static unsigned char X, Y;
static void ProgressMeter (unsigned Val) static void ProgressMeter (unsigned Val)
/* Print the progress bar. */ /* Print the progress bar. */
{ {
gotoxy (X, Y); gotoxy (X, Y);
cprintf (" %5lu/65536\r\n", (unsigned long) Val); cprintf (" %5lu/65536\r\n", (unsigned long) Val);
revers (1); revers (1);
cclear (Val / (unsigned)(65536U / BAR_ELEMENTS)); cclear (Val / (unsigned)(65536U / BAR_ELEMENTS));
/* Commodore and Atari computers can show eight times greater precision. */ /* Commodore and Atari computers can show eight times greater precision. */
#if defined(__CBM__) #if defined(__CBM__)
Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8; Val = (Val / (unsigned)(65536U / BAR_ELEMENTS / 8)) % 8;
revers (revers_bar[Val]); revers (revers_bar[Val]);
cputc (small_bar[Val]); cputc (small_bar[Val]);
#elif defined(__ATARI__) #elif defined(__ATARI__)
#endif #endif
revers (0); revers (0);
} }
int main(void) int main(void)
{ {
char C; char C;
/* Clock variables */ /* Clock variables */
clock_t Ticks; clock_t Ticks;
clock_t Wait; clock_t Wait;
unsigned Days; unsigned Days;
unsigned Hours; unsigned Hours;
unsigned Minu; unsigned Minu;
unsigned Sec; unsigned Sec;
unsigned Milli; unsigned Milli;
/* Actual test variables */ /* Actual test variables */
register unsigned lhs = 0; register unsigned lhs = 0;
register unsigned rhs = 0; register unsigned rhs = 0;
register unsigned res; register unsigned res;
/* Clear the screen, and output an informational message. */ /* Clear the screen, and output an informational message. */
clrscr (); clrscr ();
screensize (&Width, &Height); screensize (&Width, &Height);
cprintf ("This program does an exhaustive test of\r\n" cprintf ("This program does an exhaustive test of\r\n"
"the multiplication routine. It runs for\r\n" "the multiplication routine. It runs for\r\n"
"several days; so, please wait very\r\n" "several days; so, please wait very\r\n"
"patiently (or, speed up your emulator).\r\n" "patiently (or, speed up your emulator).\r\n"
"\n" "\n"
"Progress: "); "Progress: ");
/* Remember the current position for the progress bar */ /* Remember the current position for the progress bar */
X = wherex (); X = wherex ();
Y = wherey (); Y = wherey ();
/* Mark the maximum limit of the bar. */ /* Mark the maximum limit of the bar. */
revers (1); revers (1);
cputcxy (BAR_ELEMENTS, Y, ' '); cputcxy (BAR_ELEMENTS, Y, ' ');
cputcxy (BAR_ELEMENTS, Y + 1, ' '); cputcxy (BAR_ELEMENTS, Y + 1, ' ');
revers (0); revers (0);
/* [Targets that have clock() will define CLOCKS_PER_SEC.] */ /* [Targets that have clock() will define CLOCKS_PER_SEC.] */
#ifdef CLOCKS_PER_SEC #ifdef CLOCKS_PER_SEC
/* Start timing the test. */ /* Start timing the test. */
Ticks = clock(); Ticks = clock();
#endif #endif
do { do {
/* Update the progress bar */ /* Update the progress bar */
ProgressMeter (lhs); ProgressMeter (lhs);
/* Enable this to test the progress-meter code. /* Enable this to test the progress-meter code.
** (And, run emulators at their maximun speed.) ** (And, run emulators at their maximun speed.)
*/ */
#if 0 #if 0
continue; continue;
#endif #endif
/* Do one row of tests */ /* Do one row of tests */
res = 0; res = 0;
do { do {
if (lhs * rhs != res) { if (lhs * rhs != res) {
#ifdef CLOCKS_PER_SEC #ifdef CLOCKS_PER_SEC
Wait = clock (); Wait = clock ();
#endif #endif
gotoxy (0, Y+3); gotoxy (0, Y+3);
cprintf ("Error on %u * %u: %u != %u\r\n", lhs, rhs, lhs * rhs, res); cprintf ("Error on %u * %u: %u != %u\r\n", lhs, rhs, lhs * rhs, res);
cprintf ("Press a key -- 'Q' to quit. "); cprintf ("Press a key -- 'Q' to quit. ");
cursor (1); cursor (1);
C = toupper (cgetc ()); C = toupper (cgetc ());
cclearxy (0, Y+3, Width); cclearxy (0, Y+3, Width);
cclearxy (0, Y+4, Width); cclearxy (0, Y+4, Width);
#ifdef CLOCKS_PER_SEC #ifdef CLOCKS_PER_SEC
/* Don't time the user's interaction. */ /* Don't time the user's interaction. */
Ticks += clock () - Wait; Ticks += clock () - Wait;
#endif #endif
if (C == 'Q') { if (C == 'Q') {
goto Done; goto Done;
} }
} }
if (kbhit () && toupper (cgetc ()) == 'Q') { if (kbhit () && toupper (cgetc ()) == 'Q') {
goto Done; goto Done;
} }
res += lhs; res += lhs;
} while (++rhs != 0); } while (++rhs != 0);
} while (++lhs != 0); } while (++lhs != 0);
Done: Done:
#ifdef CLOCKS_PER_SEC #ifdef CLOCKS_PER_SEC
/* Calculate the time used */ /* Calculate the time used */
Ticks = clock() - Ticks; Ticks = clock() - Ticks;
Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC; Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
Sec = (unsigned) (Ticks / CLOCKS_PER_SEC); Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
Minu = Sec / 60; Minu = Sec / 60;
Hours = Minu / 60; Hours = Minu / 60;
Days = Hours / 24; Days = Hours / 24;
Hours %= 24; Hours %= 24;
Minu %= 60; Minu %= 60;
Sec %= 60; Sec %= 60;
/* Print the time used */ /* Print the time used */
gotoxy (0, Y+3); gotoxy (0, Y+3);
cprintf ("Time used:\r\n" cprintf ("Time used:\r\n"
" %u days,\r\n" " %u days,\r\n"
" %u hours,\r\n" " %u hours,\r\n"
" %u minutes,\r\n" " %u minutes,\r\n"
" %u.%03u seconds.\n", Days, Hours, Minu, Sec, Milli); " %u.%03u seconds.\n", Days, Hours, Minu, Sec, Milli);
#endif #endif
cprintf ("\rTap a key, to exit. "); cprintf ("\rTap a key, to exit. ");
cgetc(); cgetc();
return 0; return 0;
} }