From b3b3578f0888c1f224708dc23f2d8dc7878ef807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 14 Jul 2013 22:50:38 +0200 Subject: [PATCH 001/351] Nominal support for target Ohio Scientific Challenger 1P --- cfg/c1p.cfg | 30 +++++++++++++++++++++++++ libsrc/Makefile | 1 + libsrc/c1p/crt0.s | 54 +++++++++++++++++++++++++++++++++++++++++++++ src/ca65/main.c | 4 ++++ src/cc65/main.c | 4 ++++ src/common/target.c | 4 +++- src/common/target.h | 1 + 7 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 cfg/c1p.cfg create mode 100644 libsrc/c1p/crt0.s diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg new file mode 100644 index 000000000..752e81533 --- /dev/null +++ b/cfg/c1p.cfg @@ -0,0 +1,30 @@ +SYMBOLS { + __STACKSIZE__: type = weak, value = $0400; # 1k stack +} +MEMORY { + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = $0FFF, size = $0002; + HEADER: file = %O, start = $1001, size = $000C; + RAM: file = %O, define = yes, start = $100D, size = $0DF3 - __STACKSIZE__; +} +SEGMENTS { + STARTUP: load = RAM, type = ro; + LOWCODE: load = RAM, type = ro, optional = yes; + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = ro; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + ZPSAVE: load = RAM, type = bss; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; +} +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; +} diff --git a/libsrc/Makefile b/libsrc/Makefile index d855d1580..9955d6d77 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -15,6 +15,7 @@ TARGETS = apple2 \ atari \ atarixl \ atmos \ + c1p \ $(CBMS) \ $(GEOS) \ lynx \ diff --git a/libsrc/c1p/crt0.s b/libsrc/c1p/crt0.s new file mode 100644 index 000000000..f8005b6dd --- /dev/null +++ b/libsrc/c1p/crt0.s @@ -0,0 +1,54 @@ +; --------------------------------------------------------------------------- +; crt0.s +; --------------------------------------------------------------------------- +; +; Startup code for Ohio Scientific Challenger 1P + +.export _init, _exit +.import _main + +.export __STARTUP__ : absolute = 1 ; Mark as startup +.import __RAM_START__, __RAM_SIZE__ ; Linker generated + +.import copydata, zerobss, initlib, donelib + +.include "zeropage.inc" + +; --------------------------------------------------------------------------- +; Place the startup code in a special segment + +.segment "STARTUP" + +; --------------------------------------------------------------------------- +; A little light 6502 housekeeping + +_init: LDX #$FF ; Initialize stack pointer to $01FF + TXS + CLD ; Clear decimal mode + +; --------------------------------------------------------------------------- +; Set cc65 argument stack pointer + + LDA #<(__RAM_START__ + __RAM_SIZE__) + STA sp + LDA #>(__RAM_START__ + __RAM_SIZE__) + STA sp+1 + +; --------------------------------------------------------------------------- +; Initialize memory storage + + ; JSR zerobss ; Clear BSS segment + ; JSR copydata ; Initialize DATA segment + ; JSR initlib ; Run constructors + +; --------------------------------------------------------------------------- +; Call main() + + JSR _main + +; --------------------------------------------------------------------------- +; Back from main (this is also the _exit entry): force a software break + +_exit: JSR donelib ; Run destructors + BRK + diff --git a/src/ca65/main.c b/src/ca65/main.c index 4b2f9d178..5a9bf7083 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -298,6 +298,10 @@ static void SetSys (const char* Sys) NewSymbol ("__SIM65C02__", 1); break; + case TGT_C1P: + NewSymbol ("__OSIC1P__", 1); + break; + default: AbEnd ("Invalid target name: `%s'", Sys); diff --git a/src/cc65/main.c b/src/cc65/main.c index a27822ed8..6882d56a3 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -254,6 +254,10 @@ static void SetSys (const char* Sys) DefineNumericMacro ("__SIM65C02__", 1); break; + case TGT_C1P: + DefineNumericMacro ("__OSIC1P__", 1); + break; + default: AbEnd ("Unknown target system type %d", Target); } diff --git a/src/common/target.c b/src/common/target.c index a4287ee56..d8d3f9c54 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -119,7 +119,7 @@ struct TargetEntry { }; /* Table that maps target names to ids. Sorted alphabetically for bsearch. - * Allows mupltiple entries for one target id (target name aliases). + * Allows multiple entries for one target id (target name aliases). */ static const TargetEntry TargetMap[] = { { "apple2", TGT_APPLE2 }, @@ -130,6 +130,7 @@ static const TargetEntry TargetMap[] = { { "bbc", TGT_BBC }, { "c128", TGT_C128 }, { "c16", TGT_C16 }, + { "c1p", TGT_C1P }, { "c64", TGT_C64 }, { "cbm510", TGT_CBM510 }, { "cbm610", TGT_CBM610 }, @@ -160,6 +161,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "atarixl", CPU_6502, BINFMT_BINARY, CTAtari }, { "vic20", CPU_6502, BINFMT_BINARY, CTPET }, { "c16", CPU_6502, BINFMT_BINARY, CTPET }, + { "c1p", CPU_6502, BINFMT_BINARY, CTNone }, { "c64", CPU_6502, BINFMT_BINARY, CTPET }, { "c128", CPU_6502, BINFMT_BINARY, CTPET }, { "plus4", CPU_6502, BINFMT_BINARY, CTPET }, diff --git a/src/common/target.h b/src/common/target.h index e1675ad65..47946a309 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -58,6 +58,7 @@ typedef enum { TGT_ATARIXL, TGT_VIC20, TGT_C16, + TGT_C1P, TGT_C64, TGT_C128, TGT_PLUS4, From 0303b0cc6c29115cb4fbc819f574c9073dc6c643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Mon, 15 Jul 2013 22:24:10 +0200 Subject: [PATCH 002/351] Adapt to memory size of C1P. --- cfg/c1p.cfg | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index 752e81533..f1d739215 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -3,20 +3,17 @@ SYMBOLS { } MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; - LOADADDR: file = %O, start = $0FFF, size = $0002; - HEADER: file = %O, start = $1001, size = $000C; - RAM: file = %O, define = yes, start = $100D, size = $0DF3 - __STACKSIZE__; + RAM: file = %O, define = yes, start = $0400, size = $2000 - __STACKSIZE__; } SEGMENTS { - STARTUP: load = RAM, type = ro; - LOWCODE: load = RAM, type = ro, optional = yes; - INIT: load = RAM, type = ro, define = yes, optional = yes; - CODE: load = RAM, type = ro; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; + STARTUP: load = RAM, type = ro; + LOWCODE: load = RAM, type = ro, optional = yes; + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = rw; + RODATA: load = RAM, type = rw; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; } FEATURES { CONDES: type = constructor, From 608e9875fb37c094f312ca2ac05e3abe10ab034f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Mon, 15 Jul 2013 22:45:09 +0200 Subject: [PATCH 003/351] Suppress call to copydata routine, which seems to be necessary only in very special cases that are unclear at the moment. --- libsrc/c1p/crt0.s | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libsrc/c1p/crt0.s b/libsrc/c1p/crt0.s index f8005b6dd..fcbb82e64 100644 --- a/libsrc/c1p/crt0.s +++ b/libsrc/c1p/crt0.s @@ -36,10 +36,11 @@ _init: LDX #$FF ; Initialize stack pointer to $01FF ; --------------------------------------------------------------------------- ; Initialize memory storage +; copydata seems to be only necessary for special systems - ; JSR zerobss ; Clear BSS segment - ; JSR copydata ; Initialize DATA segment - ; JSR initlib ; Run constructors + JSR zerobss ; Clear BSS segment + ; JSR copydata ; Initialize DATA segment + JSR initlib ; Run constructors ; --------------------------------------------------------------------------- ; Call main() From 9b505d7b6513e0082df17661674862f72393aee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Tue, 16 Jul 2013 22:29:14 +0200 Subject: [PATCH 004/351] Created C1P object file generator. --- src/Makefile | 1 + src/c1p65.vcxproj | 94 ++++++++++++++++++++ src/c1p65/main.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+) create mode 100644 src/c1p65.vcxproj create mode 100644 src/c1p65/main.c diff --git a/src/Makefile b/src/Makefile index 3d0463147..4a80a78fb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,7 @@ ifeq ($(shell echo),) PROGS = ar65 \ + c1p65 \ ca65 \ cc65 \ cl65 \ diff --git a/src/c1p65.vcxproj b/src/c1p65.vcxproj new file mode 100644 index 000000000..2f4ff02fb --- /dev/null +++ b/src/c1p65.vcxproj @@ -0,0 +1,94 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + {4E031DE0-82B4-4204-8529-536626F7E0DF} + Win32Proj + c1p65 + + + + Application + true + v110 + + + + + Application + false + v110 + true + + + + + + + + + + + + + + + true + $(SolutionDir)..\bin\ + $(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\ + + + false + $(SolutionDir)..\bin\ + $(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\ + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + common + + + Console + true + $(IntDir)..\..\common\$(Configuration)\common.lib + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + common + + + Console + true + true + true + $(IntDir)..\..\common\$(Configuration)\common.lib + + + + + + \ No newline at end of file diff --git a/src/c1p65/main.c b/src/c1p65/main.c new file mode 100644 index 000000000..c15c77a88 --- /dev/null +++ b/src/c1p65/main.c @@ -0,0 +1,219 @@ +/* Object file conversion utility for Challenger 1P + + by Stephan Muehlstrasser +*/ + + +#include +#include +#include +#include +#include +#include + +/* common stuff */ +#include "abend.h" +#include "cmdline.h" +#include "fname.h" +#include "chartype.h" +#include "target.h" +#include "version.h" +#include "xmalloc.h" + +static void Usage (void) +{ + printf ( + "Usage: %s [options] file\n" + "Short options:\n" + " -V\t\t\tPrint the version number\n" + " -h\t\t\tHelp (this text)\n" + " -o name\t\tName the C1P output file (default: )\n" + " -S addr\t\tLoad address (default 0x400)\n" + "\n" + "Long options:\n" + " --help\t\tHelp (this text)\n" + " --version\t\tPrint the version number\n", + ProgName); +} + +static void OptHelp (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Print usage information and exit */ +{ + Usage (); + exit (EXIT_SUCCESS); +} + + +static void OptVersion (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Print the program version */ +{ + fprintf (stderr, "grc65 V%s\n", GetVersionAsString ()); +} + + +static unsigned long CvtNumber (const char* Arg, const char* Number) +/* Convert a number from a string. Allow '$' and '0x' prefixes for hex + * numbers. Duplicated from ld65's main.c. + */ +{ + unsigned long Val; + int Converted; + + /* Convert */ + if (*Number == '$') { + ++Number; + Converted = sscanf (Number, "%lx", &Val); + } else { + Converted = sscanf (Number, "%li", (long*)&Val); + } + + /* Check if we do really have a number */ + if (Converted != 1) { + AbEnd ("Invalid number given in argument: %s\n", Arg); + } + + /* Return the result */ + return Val; +} + +/* Commands of C1P PROM monitor */ +#define ADDRESS_MODE_CMD '.' +#define DATA_MODE_CMD '/' +#define EXECUTE_CMD 'G' + +/* Transform the cc65 executable binary into a series of + commands that make the C1P PROM monitor load the bytes + into memory. +*/ +static void Transform (unsigned long StartAddress, FILE *In, FILE *Out) +{ + int c; + unsigned long CurrentAddress; + + /* Loop over all input bytes, position to current address, + switch to data mod, output input byte + */ + for (CurrentAddress = StartAddress, c = getc(In); + c != EOF; + c = getc(In), CurrentAddress += 1) { + fprintf (Out, "%c%04.4X%c%02.2X", + ADDRESS_MODE_CMD, (unsigned int) CurrentAddress & 0xFFFF, + DATA_MODE_CMD, (unsigned int) c & 0xFF); + } + + /* And execute + fprintf (Out, "%c%04.4x%c", + ADDRESS_MODE_CMD, (unsigned int) StartAddress & 0xFFFF, + EXECUTE_CMD); + */ +} + +/* Default suffix for C1P object file */ +#define C1P_SUFFIX ".c1p" + +int main (int argc, char *argv[]) +{ + /* Program long options */ + static const LongOpt OptTab[] = { + { "--help", 0, OptHelp}, + { "--version", 0, OptVersion}, + }; + + /* Initialize input and output file name */ + const char* InputFile = 0; + const char* OutputFile = 0; + char *GeneratedOutputFile = 0; + + /* Initialize file pointers */ + FILE *InputFileFp = 0; + FILE *OutputFileFp = 0; + + /* Initialize with default start address defined in c1p.cfg */ + unsigned long StartAddr = 0x400; + + unsigned int I; + + /* Initialize the cmdline module */ + InitCmdLine (&argc, &argv, "c1p65"); + + /* Check the parameters */ + I = 1; + while (I < ArgCount) { + + /* Get the argument */ + const char* Arg = ArgVec [I]; + + /* Check for an option */ + if (Arg[0] == '-') { + switch (Arg[1]) { + + case '-': + LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); + break; + + case 'o': + OutputFile = GetArg (&I, 2); + break; + + case 'S': + StartAddr = CvtNumber (Arg, GetArg (&I, 2)); + break; + + case 'h': + case '?': + OptHelp (Arg, 0); + break; + + case 'V': + OptVersion (Arg, 0); + break; + + default: + UnknownOption (Arg); + } + + } else { + if (InputFile) { + fprintf (stderr, "additional file specs ignored\n"); + } else { + InputFile = Arg; + } + } + + /* Next argument */ + ++I; + } + + if (!InputFile) AbEnd ("No input file"); + + if (!OutputFile) { + const size_t len = strlen(InputFile) + sizeof(C1P_SUFFIX); + + GeneratedOutputFile = (char *) xmalloc(len); + sprintf(GeneratedOutputFile, "%s%s", InputFile, C1P_SUFFIX); + OutputFile = GeneratedOutputFile; + } + + /* Open input and output files */ + InputFileFp = fopen(InputFile, "rb"); + if (!InputFileFp) AbEnd ("Unable to open input file"); + + OutputFileFp = fopen(OutputFile, "wb"); + if (!OutputFileFp) AbEnd ("Unable to open output file"); + + /* Generate object file */ + Transform (StartAddr, InputFileFp, OutputFileFp); + + /* Cleanup */ + if (fclose(InputFileFp) == EOF) AbEnd ("Error closing input file"); + + if (fclose(OutputFileFp) == EOF) AbEnd ("Error closing output file"); + + if (GeneratedOutputFile) { + xfree(GeneratedOutputFile); + } + + return EXIT_SUCCESS; +} From 0b8c742bfcc5c03cba5b0c9d55d3897d66cf1f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Wed, 24 Jul 2013 22:35:58 +0200 Subject: [PATCH 005/351] Remove unneeded import --- libsrc/c1p/crt0.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/c1p/crt0.s b/libsrc/c1p/crt0.s index fcbb82e64..97d572608 100644 --- a/libsrc/c1p/crt0.s +++ b/libsrc/c1p/crt0.s @@ -10,7 +10,7 @@ .export __STARTUP__ : absolute = 1 ; Mark as startup .import __RAM_START__, __RAM_SIZE__ ; Linker generated -.import copydata, zerobss, initlib, donelib +.import zerobss, initlib, donelib .include "zeropage.inc" From 57a422d064251c6f27fe1306db0e8077492adada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 2 Nov 2014 19:39:39 +0100 Subject: [PATCH 006/351] Adapt c1p65 project to Visual Studio 2013 --- src/c1p65.vcxproj | 186 +++++++++++++++++++++++----------------------- 1 file changed, 93 insertions(+), 93 deletions(-) diff --git a/src/c1p65.vcxproj b/src/c1p65.vcxproj index 2f4ff02fb..dcc8f9926 100644 --- a/src/c1p65.vcxproj +++ b/src/c1p65.vcxproj @@ -1,94 +1,94 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - - - - {4E031DE0-82B4-4204-8529-536626F7E0DF} - Win32Proj - c1p65 - - - - Application - true - v110 - - - - - Application - false - v110 - true - - - - - - - - - - - - - - - true - $(SolutionDir)..\bin\ - $(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\ - - - false - $(SolutionDir)..\bin\ - $(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\ - - - - - - Level3 - Disabled - _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - common - - - Console - true - $(IntDir)..\..\common\$(Configuration)\common.lib - - - - - Level3 - - - MaxSpeed - true - true - _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - common - - - Console - true - true - true - $(IntDir)..\..\common\$(Configuration)\common.lib - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + + + + {4E031DE0-82B4-4204-8529-536626F7E0DF} + Win32Proj + c1p65 + + + + Application + true + v120 + + + + + Application + false + v120 + true + + + + + + + + + + + + + + + true + $(SolutionDir)..\bin\ + $(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\ + + + false + $(SolutionDir)..\bin\ + $(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\ + + + + + + Level3 + Disabled + _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + common + + + Console + true + $(IntDir)..\..\common\$(Configuration)\common.lib + + + + + Level3 + + + MaxSpeed + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + common + + + Console + true + true + true + $(IntDir)..\..\common\$(Configuration)\common.lib + + + + + \ No newline at end of file From 29801cd45f4733389c4506195614095c87825df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 2 Nov 2014 23:22:41 +0100 Subject: [PATCH 007/351] Enter bytes in a loop in data mode --- src/c1p65/main.c | 440 ++++++++++++++++++++++++----------------------- 1 file changed, 221 insertions(+), 219 deletions(-) diff --git a/src/c1p65/main.c b/src/c1p65/main.c index c15c77a88..467953c57 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -1,219 +1,221 @@ -/* Object file conversion utility for Challenger 1P - - by Stephan Muehlstrasser -*/ - - -#include -#include -#include -#include -#include -#include - -/* common stuff */ -#include "abend.h" -#include "cmdline.h" -#include "fname.h" -#include "chartype.h" -#include "target.h" -#include "version.h" -#include "xmalloc.h" - -static void Usage (void) -{ - printf ( - "Usage: %s [options] file\n" - "Short options:\n" - " -V\t\t\tPrint the version number\n" - " -h\t\t\tHelp (this text)\n" - " -o name\t\tName the C1P output file (default: )\n" - " -S addr\t\tLoad address (default 0x400)\n" - "\n" - "Long options:\n" - " --help\t\tHelp (this text)\n" - " --version\t\tPrint the version number\n", - ProgName); -} - -static void OptHelp (const char* Opt attribute ((unused)), - const char* Arg attribute ((unused))) -/* Print usage information and exit */ -{ - Usage (); - exit (EXIT_SUCCESS); -} - - -static void OptVersion (const char* Opt attribute ((unused)), - const char* Arg attribute ((unused))) -/* Print the program version */ -{ - fprintf (stderr, "grc65 V%s\n", GetVersionAsString ()); -} - - -static unsigned long CvtNumber (const char* Arg, const char* Number) -/* Convert a number from a string. Allow '$' and '0x' prefixes for hex - * numbers. Duplicated from ld65's main.c. - */ -{ - unsigned long Val; - int Converted; - - /* Convert */ - if (*Number == '$') { - ++Number; - Converted = sscanf (Number, "%lx", &Val); - } else { - Converted = sscanf (Number, "%li", (long*)&Val); - } - - /* Check if we do really have a number */ - if (Converted != 1) { - AbEnd ("Invalid number given in argument: %s\n", Arg); - } - - /* Return the result */ - return Val; -} - -/* Commands of C1P PROM monitor */ -#define ADDRESS_MODE_CMD '.' -#define DATA_MODE_CMD '/' -#define EXECUTE_CMD 'G' - -/* Transform the cc65 executable binary into a series of - commands that make the C1P PROM monitor load the bytes - into memory. -*/ -static void Transform (unsigned long StartAddress, FILE *In, FILE *Out) -{ - int c; - unsigned long CurrentAddress; - - /* Loop over all input bytes, position to current address, - switch to data mod, output input byte - */ - for (CurrentAddress = StartAddress, c = getc(In); - c != EOF; - c = getc(In), CurrentAddress += 1) { - fprintf (Out, "%c%04.4X%c%02.2X", - ADDRESS_MODE_CMD, (unsigned int) CurrentAddress & 0xFFFF, - DATA_MODE_CMD, (unsigned int) c & 0xFF); - } - - /* And execute - fprintf (Out, "%c%04.4x%c", - ADDRESS_MODE_CMD, (unsigned int) StartAddress & 0xFFFF, - EXECUTE_CMD); - */ -} - -/* Default suffix for C1P object file */ -#define C1P_SUFFIX ".c1p" - -int main (int argc, char *argv[]) -{ - /* Program long options */ - static const LongOpt OptTab[] = { - { "--help", 0, OptHelp}, - { "--version", 0, OptVersion}, - }; - - /* Initialize input and output file name */ - const char* InputFile = 0; - const char* OutputFile = 0; - char *GeneratedOutputFile = 0; - - /* Initialize file pointers */ - FILE *InputFileFp = 0; - FILE *OutputFileFp = 0; - - /* Initialize with default start address defined in c1p.cfg */ - unsigned long StartAddr = 0x400; - - unsigned int I; - - /* Initialize the cmdline module */ - InitCmdLine (&argc, &argv, "c1p65"); - - /* Check the parameters */ - I = 1; - while (I < ArgCount) { - - /* Get the argument */ - const char* Arg = ArgVec [I]; - - /* Check for an option */ - if (Arg[0] == '-') { - switch (Arg[1]) { - - case '-': - LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); - break; - - case 'o': - OutputFile = GetArg (&I, 2); - break; - - case 'S': - StartAddr = CvtNumber (Arg, GetArg (&I, 2)); - break; - - case 'h': - case '?': - OptHelp (Arg, 0); - break; - - case 'V': - OptVersion (Arg, 0); - break; - - default: - UnknownOption (Arg); - } - - } else { - if (InputFile) { - fprintf (stderr, "additional file specs ignored\n"); - } else { - InputFile = Arg; - } - } - - /* Next argument */ - ++I; - } - - if (!InputFile) AbEnd ("No input file"); - - if (!OutputFile) { - const size_t len = strlen(InputFile) + sizeof(C1P_SUFFIX); - - GeneratedOutputFile = (char *) xmalloc(len); - sprintf(GeneratedOutputFile, "%s%s", InputFile, C1P_SUFFIX); - OutputFile = GeneratedOutputFile; - } - - /* Open input and output files */ - InputFileFp = fopen(InputFile, "rb"); - if (!InputFileFp) AbEnd ("Unable to open input file"); - - OutputFileFp = fopen(OutputFile, "wb"); - if (!OutputFileFp) AbEnd ("Unable to open output file"); - - /* Generate object file */ - Transform (StartAddr, InputFileFp, OutputFileFp); - - /* Cleanup */ - if (fclose(InputFileFp) == EOF) AbEnd ("Error closing input file"); - - if (fclose(OutputFileFp) == EOF) AbEnd ("Error closing output file"); - - if (GeneratedOutputFile) { - xfree(GeneratedOutputFile); - } - - return EXIT_SUCCESS; -} +/* Object file conversion utility for Challenger 1P + + by Stephan Muehlstrasser +*/ + + +#include +#include +#include +#include +#include +#include + +/* common stuff */ +#include "abend.h" +#include "cmdline.h" +#include "fname.h" +#include "chartype.h" +#include "target.h" +#include "version.h" +#include "xmalloc.h" + +static void Usage (void) +{ + printf ( + "Usage: %s [options] file\n" + "Short options:\n" + " -V\t\t\tPrint the version number\n" + " -h\t\t\tHelp (this text)\n" + " -o name\t\tName the C1P output file (default: )\n" + " -S addr\t\tLoad address (default 0x400)\n" + "\n" + "Long options:\n" + " --help\t\tHelp (this text)\n" + " --version\t\tPrint the version number\n", + ProgName); +} + +static void OptHelp (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Print usage information and exit */ +{ + Usage (); + exit (EXIT_SUCCESS); +} + + +static void OptVersion (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Print the program version */ +{ + fprintf (stderr, "grc65 V%s\n", GetVersionAsString ()); +} + + +static unsigned long CvtNumber (const char* Arg, const char* Number) +/* Convert a number from a string. Allow '$' and '0x' prefixes for hex + * numbers. Duplicated from ld65's main.c. + */ +{ + unsigned long Val; + int Converted; + + /* Convert */ + if (*Number == '$') { + ++Number; + Converted = sscanf (Number, "%lx", &Val); + } else { + Converted = sscanf (Number, "%li", (long*)&Val); + } + + /* Check if we do really have a number */ + if (Converted != 1) { + AbEnd ("Invalid number given in argument: %s\n", Arg); + } + + /* Return the result */ + return Val; +} + +/* Commands of C1P PROM monitor */ +#define ADDRESS_MODE_CMD '.' +#define DATA_MODE_CMD '/' +#define EXECUTE_CMD 'G' +#define DATA_MODE_ADDRESS 0x00FB + +/* Transform the cc65 executable binary into a series of + commands that make the C1P PROM monitor load the bytes + into memory. +*/ +static void Transform (unsigned long StartAddress, FILE *In, FILE *Out) +{ + int c; + + /* Position to the start address */ + fprintf(Out, "%c%04.4X%c", ADDRESS_MODE_CMD, + StartAddress & 0xFFFF, DATA_MODE_CMD); + + /* Loop over all input bytes and enter them one by one */ + for (c = getc(In); c != EOF; c = getc(In)) { + fprintf(Out, "%02.2X\n", (unsigned int) c & 0xFF); + } + + /* Store 00 to 0x00FB to enable keyboard input at the end */ + fprintf(Out, "%c%04.4X%c%02.2X\n", ADDRESS_MODE_CMD, + 0x00FB, DATA_MODE_CMD, 0x00); + + /* And execute + fprintf (Out, "%c%04.4x%c", + ADDRESS_MODE_CMD, (unsigned int) StartAddress & 0xFFFF, + EXECUTE_CMD); + */ +} + +/* Default suffix for C1P object file */ +#define C1P_SUFFIX ".c1p" + +int main (int argc, char *argv[]) +{ + /* Program long options */ + static const LongOpt OptTab[] = { + { "--help", 0, OptHelp}, + { "--version", 0, OptVersion}, + }; + + /* Initialize input and output file name */ + const char* InputFile = 0; + const char* OutputFile = 0; + char *GeneratedOutputFile = 0; + + /* Initialize file pointers */ + FILE *InputFileFp = 0; + FILE *OutputFileFp = 0; + + /* Initialize with default start address defined in c1p.cfg */ + unsigned long StartAddr = 0x400; + + unsigned int I; + + /* Initialize the cmdline module */ + InitCmdLine (&argc, &argv, "c1p65"); + + /* Check the parameters */ + I = 1; + while (I < ArgCount) { + + /* Get the argument */ + const char* Arg = ArgVec [I]; + + /* Check for an option */ + if (Arg[0] == '-') { + switch (Arg[1]) { + + case '-': + LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); + break; + + case 'o': + OutputFile = GetArg (&I, 2); + break; + + case 'S': + StartAddr = CvtNumber (Arg, GetArg (&I, 2)); + break; + + case 'h': + case '?': + OptHelp (Arg, 0); + break; + + case 'V': + OptVersion (Arg, 0); + break; + + default: + UnknownOption (Arg); + } + + } else { + if (InputFile) { + fprintf (stderr, "additional file specs ignored\n"); + } else { + InputFile = Arg; + } + } + + /* Next argument */ + ++I; + } + + if (!InputFile) AbEnd ("No input file"); + + if (!OutputFile) { + const size_t len = strlen(InputFile) + sizeof(C1P_SUFFIX); + + GeneratedOutputFile = (char *) xmalloc(len); + sprintf(GeneratedOutputFile, "%s%s", InputFile, C1P_SUFFIX); + OutputFile = GeneratedOutputFile; + } + + /* Open input and output files */ + InputFileFp = fopen(InputFile, "rb"); + if (!InputFileFp) AbEnd ("Unable to open input file"); + + OutputFileFp = fopen(OutputFile, "wb"); + if (!OutputFileFp) AbEnd ("Unable to open output file"); + + /* Generate object file */ + Transform (StartAddr, InputFileFp, OutputFileFp); + + /* Cleanup */ + if (fclose(InputFileFp) == EOF) AbEnd ("Error closing input file"); + + if (fclose(OutputFileFp) == EOF) AbEnd ("Error closing output file"); + + if (GeneratedOutputFile) { + xfree(GeneratedOutputFile); + } + + return EXIT_SUCCESS; +} From 1f85c48fb218e711d1ab1e273ac512d57ac0db34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Thu, 6 Nov 2014 20:46:16 +0100 Subject: [PATCH 008/351] Added the c1p65 project. --- src/cc65.sln | 246 ++++++++++++++++++++++++++------------------------- 1 file changed, 127 insertions(+), 119 deletions(-) diff --git a/src/cc65.sln b/src/cc65.sln index 9d0f2cc2e..3fb7e2a61 100644 --- a/src/cc65.sln +++ b/src/cc65.sln @@ -1,119 +1,127 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual C++ Express 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common.vcxproj", "{71DC1F68-BFC4-478C-8655-C8E9C9654D2B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cc65", "cc65.vcxproj", "{B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ca65", "ca65.vcxproj", "{D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ar65", "ar65.vcxproj", "{5E8C19C6-B167-440C-8BEF-3CBF109CDB49}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ld65", "ld65.vcxproj", "{26C749A0-814C-47A2-9D36-AE92AE932FE4}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cl65", "cl65.vcxproj", "{F657912F-050A-488B-B203-50ED5715CDD7}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "da65", "da65.vcxproj", "{0BCFB793-2B25-40E2-B265-75848824AC4C}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "co65", "co65.vcxproj", "{F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grc65", "grc65.vcxproj", "{E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "od65", "od65.vcxproj", "{FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sp65", "sp65.vcxproj", "{4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sim65", "sim65.vcxproj", "{002A366E-2863-46A8-BDDE-DDF534AAEC73}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.ActiveCfg = Debug|Win32 - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.Build.0 = Debug|Win32 - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.ActiveCfg = Release|Win32 - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.Build.0 = Release|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.ActiveCfg = Debug|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.Build.0 = Debug|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.ActiveCfg = Release|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.Build.0 = Release|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.ActiveCfg = Debug|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.Build.0 = Debug|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.ActiveCfg = Release|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.Build.0 = Release|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.ActiveCfg = Debug|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.Build.0 = Debug|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.ActiveCfg = Release|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.Build.0 = Release|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.ActiveCfg = Debug|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.Build.0 = Debug|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.ActiveCfg = Release|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.Build.0 = Release|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.ActiveCfg = Debug|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.Build.0 = Debug|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.ActiveCfg = Release|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.Build.0 = Release|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.ActiveCfg = Debug|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.Build.0 = Debug|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.ActiveCfg = Release|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.Build.0 = Release|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.ActiveCfg = Debug|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.Build.0 = Debug|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.ActiveCfg = Release|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.Build.0 = Release|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.ActiveCfg = Debug|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.Build.0 = Debug|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.ActiveCfg = Release|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.Build.0 = Release|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.ActiveCfg = Debug|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.Build.0 = Debug|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.ActiveCfg = Release|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.Build.0 = Release|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.ActiveCfg = Debug|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.Build.0 = Debug|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.ActiveCfg = Release|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.Build.0 = Release|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.ActiveCfg = Debug|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.Build.0 = Debug|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.ActiveCfg = Release|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Express 2013 for Windows Desktop +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common.vcxproj", "{71DC1F68-BFC4-478C-8655-C8E9C9654D2B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cc65", "cc65.vcxproj", "{B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ca65", "ca65.vcxproj", "{D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ar65", "ar65.vcxproj", "{5E8C19C6-B167-440C-8BEF-3CBF109CDB49}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ld65", "ld65.vcxproj", "{26C749A0-814C-47A2-9D36-AE92AE932FE4}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cl65", "cl65.vcxproj", "{F657912F-050A-488B-B203-50ED5715CDD7}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "da65", "da65.vcxproj", "{0BCFB793-2B25-40E2-B265-75848824AC4C}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "co65", "co65.vcxproj", "{F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grc65", "grc65.vcxproj", "{E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "od65", "od65.vcxproj", "{FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sp65", "sp65.vcxproj", "{4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sim65", "sim65.vcxproj", "{002A366E-2863-46A8-BDDE-DDF534AAEC73}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c1p65", "c1p65.vcxproj", "{4E031DE0-82B4-4204-8529-536626F7E0DF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.ActiveCfg = Debug|Win32 + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.Build.0 = Debug|Win32 + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.ActiveCfg = Release|Win32 + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.Build.0 = Release|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.ActiveCfg = Debug|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.Build.0 = Debug|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.ActiveCfg = Release|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.Build.0 = Release|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.ActiveCfg = Debug|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.Build.0 = Debug|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.ActiveCfg = Release|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.Build.0 = Release|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.ActiveCfg = Debug|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.Build.0 = Debug|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.ActiveCfg = Release|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.Build.0 = Release|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.ActiveCfg = Debug|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.Build.0 = Debug|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.ActiveCfg = Release|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.Build.0 = Release|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.ActiveCfg = Debug|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.Build.0 = Debug|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.ActiveCfg = Release|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.Build.0 = Release|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.ActiveCfg = Debug|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.Build.0 = Debug|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.ActiveCfg = Release|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.Build.0 = Release|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.Build.0 = Debug|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.ActiveCfg = Release|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.Build.0 = Release|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.Build.0 = Debug|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.ActiveCfg = Release|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.Build.0 = Release|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.ActiveCfg = Debug|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.Build.0 = Debug|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.ActiveCfg = Release|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.Build.0 = Release|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.ActiveCfg = Debug|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.Build.0 = Debug|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.ActiveCfg = Release|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.Build.0 = Release|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.ActiveCfg = Debug|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.Build.0 = Debug|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.ActiveCfg = Release|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.Build.0 = Release|Win32 + {4E031DE0-82B4-4204-8529-536626F7E0DF}.Debug|Win32.ActiveCfg = Debug|Win32 + {4E031DE0-82B4-4204-8529-536626F7E0DF}.Debug|Win32.Build.0 = Debug|Win32 + {4E031DE0-82B4-4204-8529-536626F7E0DF}.Release|Win32.ActiveCfg = Release|Win32 + {4E031DE0-82B4-4204-8529-536626F7E0DF}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From 5d7a24241cee19434f1ac8352c7f74eac7b410de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sat, 8 Nov 2014 01:14:46 +0100 Subject: [PATCH 009/351] Implemented clrscr routine for C1P --- libsrc/c1p/c1p.inc | 3 +++ libsrc/c1p/clrscr.s | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 libsrc/c1p/c1p.inc create mode 100644 libsrc/c1p/clrscr.s diff --git a/libsrc/c1p/c1p.inc b/libsrc/c1p/c1p.inc new file mode 100644 index 000000000..525a8e9ee --- /dev/null +++ b/libsrc/c1p/c1p.inc @@ -0,0 +1,3 @@ + +SCRNBASE := $D000 ; Base of video RAM +VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) diff --git a/libsrc/c1p/clrscr.s b/libsrc/c1p/clrscr.s new file mode 100644 index 000000000..f219a4550 --- /dev/null +++ b/libsrc/c1p/clrscr.s @@ -0,0 +1,23 @@ +; +; void clrscr (void); +; + .export _clrscr + .include "c1p.inc" + +; Adapted from the Challenger Character Graphics +; Reference Manual, "2.3.3 MACHINE LANGUAGE SCREEN CLEAR" +; This is self-modifying code! +BANKS = VIDEORAMSIZE / $100 + +_clrscr: LDA #$20 ;' ' + LDY #BANKS + LDX #$00 +STALOC: STA SCRNBASE,X + INX + BNE STALOC + INC STALOC+2 + DEY + BNE STALOC + LDA #>(SCRNBASE) ; load high byte + STA STALOC+2 ; restore base address + RTS From 4c462879286bb8cf1deb46f7868324ee43b505c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 9 Nov 2014 00:58:32 +0100 Subject: [PATCH 010/351] Begin to implement C1P conio features. --- include/c1p.h | 41 +++++++++++++++++++++++++++++++++++++++++ include/conio.h | 2 ++ libsrc/c1p/cgetc.s | 11 +++++++++++ 3 files changed, 54 insertions(+) create mode 100644 include/c1p.h create mode 100644 libsrc/c1p/cgetc.s diff --git a/include/c1p.h b/include/c1p.h new file mode 100644 index 000000000..cea31b0f3 --- /dev/null +++ b/include/c1p.h @@ -0,0 +1,41 @@ +/*****************************************************************************/ +/* */ +/* c1p.h */ +/* */ +/* Challenger 1P system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 2014 Stephan Muehlstrasser */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 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 */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + +#ifndef _C1P_H +#define _C1P_H + +/* Check for errors */ +#if !defined(__OSIC1P__) +# error "This module may only be used when compiling for the Challenger 1P!" +#endif + +/* empty for now */ + +#endif diff --git a/include/conio.h b/include/conio.h index 54667a3ca..f59375a63 100644 --- a/include/conio.h +++ b/include/conio.h @@ -77,6 +77,8 @@ # include #elif defined(__NES__) # include +#elif defined(__OSIC1P__) +# include #endif diff --git a/libsrc/c1p/cgetc.s b/libsrc/c1p/cgetc.s new file mode 100644 index 000000000..483c2f2c1 --- /dev/null +++ b/libsrc/c1p/cgetc.s @@ -0,0 +1,11 @@ +; +; char cgetc (void); +; + + .export _cgetc + .include "c1p.inc" + +; Use INPUT routine from 65V PROM MONITOR +_cgetc: + jsr $FEED + rts From 09e50d433da2354b91fab27b4eb1ddaee69c87dc Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 9 Nov 2014 06:32:11 -0500 Subject: [PATCH 011/351] * Changed the way that Atmos programs are started. - Put a BASIC-language stub at the beginning. - Removed the Autostart flag. Those changes make it easy to give command-line arguments to a program. * Made the Atmos configure file accept a special symbol definition on ld65's command line. We can use "__RAMEND__" to increase the amount of RAM that's available to programs. --- cfg/atmos.cfg | 20 +++++++++++----- doc/atmos.sgml | 52 +++++++++++++++++++++++++++++------------- libsrc/atmos/bashdr.s | 24 +++++++++++++++++++ libsrc/atmos/crt0.s | 37 ++++++++++-------------------- libsrc/atmos/tapehdr.s | 30 ++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 47 deletions(-) create mode 100644 libsrc/atmos/bashdr.s create mode 100644 libsrc/atmos/tapehdr.s diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg index 137c0e9a9..062711b96 100644 --- a/cfg/atmos.cfg +++ b/cfg/atmos.cfg @@ -1,22 +1,30 @@ SYMBOLS { - __STACKSIZE__: type = weak, value = $0800; # 2k stack + __TAPEHDR__: type = import; + __BASHDR__: type = import; + __PROGFLAG__: type = weak, value = $00; # $00=BASIC, $80=machine code + __AUTORUN__: type = weak, value = $00; # $C7=run, $00=only load + __STACKSIZE__: type = weak, value = $0800; # 2K stack + __RAMEND__: type = weak, value = $9800; # graphics RAM not grabbed +# __RAMEND__: type = weak, value = $B400; # graphics RAM grabbed } MEMORY { ZP: file = "", define = yes, start = $00E2, size = $001A; - TAPEHDR: file = %O, type = ro, start = $0000, size = $0011; - RAM: file = %O, define = yes, start = $0500, size = $9300 - __STACKSIZE__; + TAPEHDR: file = %O, type = ro, start = $0000, size = $001F; + BASHEAD: file = %O, define = yes, start = $0501, size = $000D; + RAM: file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __RAM_START__ - __STACKSIZE__; } SEGMENTS { + ZEROPAGE: load = ZP, type = zp; TAPEHDR: load = TAPEHDR, type = ro; + BASHDR: load = BASHEAD, type = ro, define = yes, optional = yes; STARTUP: load = RAM, type = ro; LOWCODE: load = RAM, type = ro, optional = yes; - INIT: load = RAM, type = ro, define = yes, optional = yes; CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; + INIT: load = RAM, type = ro, define = yes, optional = yes; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + ZPSAVE: load = RAM, type = rw, define = yes; BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; } FEATURES { CONDES: type = constructor, diff --git a/doc/atmos.sgml b/doc/atmos.sgml index 805fc7a03..ab63c667b 100644 --- a/doc/atmos.sgml +++ b/doc/atmos.sgml @@ -7,7 +7,7 @@ , , -2014-03-27 +2014-09-23 An overview over the Atmos runtime system as it is implemented for the cc65 C @@ -32,27 +32,37 @@ more than one platform. Please see the function reference for more information. + Binary format

The standard binary output format generated by the linker for the Atmos target -is a machine language program with a 17 byte tape header including a cc65 tag. -The standard load and autostart address is $500. +is a machine language program with a one-line BASIC stub that jumps to the +machine-language part through Memory layout

-In the standard setup, cc65 generated programs use the memory from -$500 to $9800, so nearly 37K of memory (including the stack) is +In the standard setup, cc65-generated programs use the memory from +$0501 to $9800; so, nearly 37K of memory (including the stack) is available. ROM calls are possible without further precautions. +If your program needs more memory, and it won't use TGI graphics, then you can +use the ld65 command-line option,

@@ -117,7 +127,8 @@ The names in the parentheses denote the symbols to be used for static linking of Graphics drivers

-The default drivers, @@ -175,13 +186,14 @@ No mouse drivers are currently available for the Atmos. Disk I/O

-The existing library for the Atmos doesn't implement C file -I/O. There are hacks for the @@ -202,7 +214,13 @@ following functions (and a few others): Function keys

-These are defined to be FUNCT + number key. +They are defined to be FUNCT + a number key. + + +Capitals Lock

+ +The "CAPS Lock" mode is turned off while the program is running. The previous +mode (usually turned on) is restored when the program stops. Passing arguments to the program

@@ -211,10 +229,12 @@ Command-line arguments can be passed to - CALL#500:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5 + RUN:REM arg1 " ARG2 IS QUOTED" ARG3 "" ARG5 +You must turn Arguments are separated by spaces. Arguments may be quoted. Leading and trailing spaces around an argument are ignored. Spaces within diff --git a/libsrc/atmos/bashdr.s b/libsrc/atmos/bashdr.s new file mode 100644 index 000000000..e09bc9fec --- /dev/null +++ b/libsrc/atmos/bashdr.s @@ -0,0 +1,24 @@ +; +; 2010-11-14, Ullrich von Bassewitz +; 2014-09-06, Greg King +; +; This module supplies a small BASIC stub program that uses CALL +; to jump to the machine-language code that follows it. +; + + ; The following symbol is used by the linker config. file + ; to force this module to be included into the output file. + .export __BASHDR__:abs = 1 + + +.segment "BASHDR" + + .addr Next + .word .version ; Line number + .byte $BF,'#' ; CALL token, mark number as hexadecimal + .byte <(Start >> 8 ) + '0' + (Start >> 8 > $09) * $07 + .byte <(Start >> 4 & $0F) + '0' + (Start >> 4 & $0F > $09) * $07 + .byte <(Start & $0F) + '0' + (Start & $0F > $09) * $07 + .byte $00 ; End of BASIC line +Next: .addr $0000 ; BASIC program end marker +Start: diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s index 1d919f348..63961bfe8 100644 --- a/libsrc/atmos/crt0.s +++ b/libsrc/atmos/crt0.s @@ -2,39 +2,18 @@ ; Startup code for cc65 (Oric version) ; ; By Debrune Jérôme and Ullrich von Bassewitz -; 2014-08-22, Greg King +; 2014-11-09, Greg King ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib .import callmain, zerobss - .import __RAM_START__, __RAM_SIZE__ - .import __ZPSAVE_LOAD__, __STACKSIZE__ + .import __RAM_START__, __RAM_SIZE__, __STACKSIZE__ .include "zeropage.inc" .include "atmos.inc" -; ------------------------------------------------------------------------ -; Oric tape header - -.segment "TAPEHDR" - - .byte $16, $16, $16 ; Sync bytes - .byte $24 ; End of header marker - - .byte $00 ; $2B0 - .byte $00 ; $2AF - .byte $80 ; $2AE Machine code flag - .byte $C7 ; $2AD Autoload flag - .dbyt __ZPSAVE_LOAD__ - 1 ; $2AB - .dbyt __RAM_START__ ; $2A9 - .byte $00 ; $2A8 - .byte ((.VERSION >> 8) & $0F) + '0' - .byte ((.VERSION >> 4) & $0F) + '0' - .byte (.VERSION & $0F) + '0' - .byte $00 ; Zero terminated compiler version - ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. @@ -79,7 +58,7 @@ L1: lda sp,x ; Call the module destructors. This is also the exit() entry. -_exit: jsr donelib ; Run module destructors +_exit: jsr donelib ; Restore the system stuff. @@ -104,7 +83,15 @@ L2: lda zpsave,x .segment "ZPSAVE" -zpsave: .res zpspace +zpsave: + +; This padding is needed by a bug in the ROM. +; (The CLOAD command starts BASIC's variables table on top of the last byte +; that was loaded [instead of at the next address].) + + .byte 0 + + .res zpspace - 1 ; ------------------------------------------------------------------------ diff --git a/libsrc/atmos/tapehdr.s b/libsrc/atmos/tapehdr.s new file mode 100644 index 000000000..b8562eb02 --- /dev/null +++ b/libsrc/atmos/tapehdr.s @@ -0,0 +1,30 @@ +; +; Based on code by Debrune Jérôme +; 2013-08-15, Greg King +; + + ; The following symbol is used by the linker config. file + ; to force this module to be included into the output file. + .export __TAPEHDR__:abs = 1 + + .import __BASHDR_LOAD__, __ZPSAVE_LOAD__, __AUTORUN__, __PROGFLAG__ + + +; ------------------------------------------------------------------------ +; Oric cassette-tape header + +.segment "TAPEHDR" + + .byte $16, $16, $16 ; Sync bytes + .byte $24 ; Beginning-of-header marker + + .byte $00 ; $2B0 + .byte $00 ; $2AF + .byte <__PROGFLAG__ ; $2AE Language flag ($00=BASIC, $80=machine code) + .byte <__AUTORUN__ ; $2AD Auto-run flag ($C7=run, $00=only load) + .dbyt __ZPSAVE_LOAD__ ; $2AB Address of end of file + .dbyt __BASHDR_LOAD__ ; $2A9 Address of start of file + .byte $00 ; $2A8 + + ; File name (a maximum of 17 characters), zero-terminated + .asciiz .sprintf("%u", .time) From 3b379c10e4d0e2ba2dd779adaca2328aa702d5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sat, 15 Nov 2014 20:37:45 +0100 Subject: [PATCH 012/351] Added missing dependency from c1p65 to common --- src/cc65.sln | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc65.sln b/src/cc65.sln index 3fb7e2a61..543038755 100644 --- a/src/cc65.sln +++ b/src/cc65.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Express 2013 for Windows Desktop -VisualStudioVersion = 12.0.30723.0 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common.vcxproj", "{71DC1F68-BFC4-478C-8655-C8E9C9654D2B}" EndProject @@ -61,6 +61,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sim65", "sim65.vcxproj", "{ EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c1p65", "c1p65.vcxproj", "{4E031DE0-82B4-4204-8529-536626F7E0DF}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 6edf57324e4e233fa350c74d98263ef1cb4f4309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 16 Nov 2014 20:07:59 +0100 Subject: [PATCH 013/351] Set default start address to 0x300. Make start address configurable via --start-addr. --- cfg/c1p.cfg | 24 +++++++++++++----------- src/c1p65/main.c | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index f1d739215..d4c248c4f 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -1,9 +1,21 @@ +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + STARTADDRESS: default = $0300; +} SYMBOLS { __STACKSIZE__: type = weak, value = $0400; # 1k stack + __HIMEM__: type = weak, value = $2000; # Presumed RAM end } MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; - RAM: file = %O, define = yes, start = $0400, size = $2000 - __STACKSIZE__; + RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { STARTUP: load = RAM, type = ro; @@ -15,13 +27,3 @@ SEGMENTS { BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } -FEATURES { - CONDES: type = constructor, - label = __CONSTRUCTOR_TABLE__, - count = __CONSTRUCTOR_COUNT__, - segment = INIT; - CONDES: type = destructor, - label = __DESTRUCTOR_TABLE__, - count = __DESTRUCTOR_COUNT__, - segment = RODATA; -} diff --git a/src/c1p65/main.c b/src/c1p65/main.c index 467953c57..e4358ddcd 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -133,7 +133,7 @@ int main (int argc, char *argv[]) FILE *OutputFileFp = 0; /* Initialize with default start address defined in c1p.cfg */ - unsigned long StartAddr = 0x400; + unsigned long StartAddr = 0x300; unsigned int I; From 14958949c27d38dc69e5e228298d9ad5d9f906e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 16 Nov 2014 21:13:18 +0100 Subject: [PATCH 014/351] Direct use of monitor function instead of subroutine call. --- libsrc/c1p/c1p.inc | 9 +++++++-- libsrc/c1p/cgetc.s | 7 ++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/libsrc/c1p/c1p.inc b/libsrc/c1p/c1p.inc index 525a8e9ee..60ea6eaaa 100644 --- a/libsrc/c1p/c1p.inc +++ b/libsrc/c1p/c1p.inc @@ -1,3 +1,8 @@ -SCRNBASE := $D000 ; Base of video RAM -VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) +SCRNBASE := $D000 ; Base of video RAM +VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) + +CURSORPOS := $0200 ; Cursor position for OUTPUTC routine + +OUTPUTC := $BF2D ; Output character at cursor position +INPUTC := $FD00 ; Input character from keyboard diff --git a/libsrc/c1p/cgetc.s b/libsrc/c1p/cgetc.s index 483c2f2c1..a73866a56 100644 --- a/libsrc/c1p/cgetc.s +++ b/libsrc/c1p/cgetc.s @@ -1,11 +1,8 @@ ; ; char cgetc (void); ; - .export _cgetc .include "c1p.inc" -; Use INPUT routine from 65V PROM MONITOR -_cgetc: - jsr $FEED - rts +; Direct use of input routine from 65V PROM MONITOR +_cgetc = INPUTC From a20bba0f1e2abd23b79e920bb1504dfdc44a873c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 16 Nov 2014 21:57:59 +0100 Subject: [PATCH 015/351] Adapt to assembler coding conventions. --- libsrc/c1p/clrscr.s | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/libsrc/c1p/clrscr.s b/libsrc/c1p/clrscr.s index f219a4550..5550d1d75 100644 --- a/libsrc/c1p/clrscr.s +++ b/libsrc/c1p/clrscr.s @@ -9,15 +9,17 @@ ; This is self-modifying code! BANKS = VIDEORAMSIZE / $100 -_clrscr: LDA #$20 ;' ' - LDY #BANKS - LDX #$00 -STALOC: STA SCRNBASE,X - INX - BNE STALOC - INC STALOC+2 - DEY - BNE STALOC - LDA #>(SCRNBASE) ; load high byte - STA STALOC+2 ; restore base address - RTS +_clrscr: + lda #$20 ;' ' + ldy #BANKS + ldx #$00 +staloc: + sta SCRNBASE,X + inx + bne staloc + inc staloc+2 + dey + bne staloc + lda #>(SCRNBASE) ; load high byte + sta staloc+2 ; restore base address + rts From d9f764aa07692442ee1d9c92f0e2acd398429be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Tue, 18 Nov 2014 23:05:50 +0100 Subject: [PATCH 016/351] Implement macros that shortcut color function calls. --- include/c1p.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/c1p.h b/include/c1p.h index cea31b0f3..5789d7156 100644 --- a/include/c1p.h +++ b/include/c1p.h @@ -36,6 +36,12 @@ # error "This module may only be used when compiling for the Challenger 1P!" #endif -/* empty for now */ +/* 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 +** overhead. +*/ +#define _textcolor(color) COLOR_WHITE +#define _bgcolor(color) COLOR_BLACK +#define _bordercolor(color) COLOR_BLACK #endif From 5c8cd00dd53bec4ce837991704c0a455b4908153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Tue, 18 Nov 2014 23:06:28 +0100 Subject: [PATCH 017/351] Started cputc and related functions implementation. --- libsrc/c1p/cputc.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 libsrc/c1p/cputc.c diff --git a/libsrc/c1p/cputc.c b/libsrc/c1p/cputc.c new file mode 100644 index 000000000..0c001cf58 --- /dev/null +++ b/libsrc/c1p/cputc.c @@ -0,0 +1,71 @@ +/* + * cputc.c + * + * void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); + * void __fastcall__ cputc (char c); + */ + +#include + +/* Implements a 25 by 25 screen in the 1024 bytes video ram (32 by 32) */ +#define LINEWIDTH 0x20 +#define SCREENBASE ((char *) 0xd000) +#define TOP_OFFSET 4 +#define LEFT_OFFSET 3 +#define SCREENVISBASE (SCREENBASE + 4 * LINEWIDTH + LEFT_OFFSET) +#define WIDTH 25 +#define HEIGHT 25 + +static unsigned char xpos = 0; +static unsigned char ypos = 0; + +void __fastcall__ cputc(char c) +{ + char * const cp = SCREENVISBASE + ypos * LINEWIDTH + xpos; + + *cp = c; + + xpos += 1; + if (xpos > WIDTH - 1) { + xpos = 0; + ypos += 1; + + if (ypos > HEIGHT - 1) { + ypos = 0; + } + } +} + +void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c) +{ + xpos = x > WIDTH - 1 ? WIDTH - 1 : x; + ypos = y > HEIGHT - 1 ? HEIGHT - 1 : y; + + cputc(c); +} + +unsigned char wherex (void) +{ + return xpos; +} + +unsigned char wherey (void) +{ + return ypos; +} + +void __fastcall__ gotox (unsigned char x) +{ + xpos = x; +} + +void __fastcall__ gotoy (unsigned char y) +{ + ypos = y; +} + +void __fastcall__ gotoxy (unsigned char x, unsigned char y) +{ + xpos = x; + ypos = y; +} From 0a6afb59c08828f64168c1e22c08619d0fbb68ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sat, 22 Nov 2014 01:07:55 +0100 Subject: [PATCH 018/351] Switch to assembler for cputc implementation. --- cfg/c1p.cfg | 3 +- libsrc/c1p/cputc.c | 71 -------------------------- libsrc/c1p/cputc.s | 117 +++++++++++++++++++++++++++++++++++++++++++ libsrc/c1p/extzp.inc | 7 +++ libsrc/c1p/extzp.s | 23 +++++++++ libsrc/c1p/gotoxy.s | 17 +++++++ 6 files changed, 166 insertions(+), 72 deletions(-) delete mode 100644 libsrc/c1p/cputc.c create mode 100644 libsrc/c1p/cputc.s create mode 100644 libsrc/c1p/extzp.inc create mode 100644 libsrc/c1p/extzp.s create mode 100644 libsrc/c1p/gotoxy.s diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index d4c248c4f..46015017b 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -14,7 +14,7 @@ SYMBOLS { __HIMEM__: type = weak, value = $2000; # Presumed RAM end } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; + ZP: file = "", define = yes, start = $0002, size = $001A + $0005; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { @@ -26,4 +26,5 @@ SEGMENTS { DATA: load = RAM, type = rw; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = rw, define = yes; } diff --git a/libsrc/c1p/cputc.c b/libsrc/c1p/cputc.c deleted file mode 100644 index 0c001cf58..000000000 --- a/libsrc/c1p/cputc.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * cputc.c - * - * void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); - * void __fastcall__ cputc (char c); - */ - -#include - -/* Implements a 25 by 25 screen in the 1024 bytes video ram (32 by 32) */ -#define LINEWIDTH 0x20 -#define SCREENBASE ((char *) 0xd000) -#define TOP_OFFSET 4 -#define LEFT_OFFSET 3 -#define SCREENVISBASE (SCREENBASE + 4 * LINEWIDTH + LEFT_OFFSET) -#define WIDTH 25 -#define HEIGHT 25 - -static unsigned char xpos = 0; -static unsigned char ypos = 0; - -void __fastcall__ cputc(char c) -{ - char * const cp = SCREENVISBASE + ypos * LINEWIDTH + xpos; - - *cp = c; - - xpos += 1; - if (xpos > WIDTH - 1) { - xpos = 0; - ypos += 1; - - if (ypos > HEIGHT - 1) { - ypos = 0; - } - } -} - -void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c) -{ - xpos = x > WIDTH - 1 ? WIDTH - 1 : x; - ypos = y > HEIGHT - 1 ? HEIGHT - 1 : y; - - cputc(c); -} - -unsigned char wherex (void) -{ - return xpos; -} - -unsigned char wherey (void) -{ - return ypos; -} - -void __fastcall__ gotox (unsigned char x) -{ - xpos = x; -} - -void __fastcall__ gotoy (unsigned char y) -{ - ypos = y; -} - -void __fastcall__ gotoxy (unsigned char x, unsigned char y) -{ - xpos = x; - ypos = y; -} diff --git a/libsrc/c1p/cputc.s b/libsrc/c1p/cputc.s new file mode 100644 index 000000000..192aec097 --- /dev/null +++ b/libsrc/c1p/cputc.s @@ -0,0 +1,117 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + + .include "c1p.inc" + .include "extzp.inc" + +_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + +; cmp #' ' +; bcc cputdirect ; Other control char < 0x20 +; tay +; bmi L10 +; cmp #$60 +; bcc L2 +; and #$DF +; bne cputdirect ; Branch always +;L2: and #$3F + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + cpy SCR_LINELEN ; xsize-1 + bne L3 + jsr newline ; new line + ldy #$FF ; + cr +L3: iny + sty CURS_X + rts + +newline: + lda SCR_LINELEN ; xsize-1 + sec ; Account for -1 above + adc SCREEN_PTR + sta SCREEN_PTR + bcc L4 + inc SCREEN_PTR+1 +L4: inc CURS_Y + rts + +; Handle character if high bit set + +; L10: and #$7F +; cmp #$7E ; PI? +; bne L11 +; lda #$5E ; Load screen code for PI +; bne cputdirect +; L11: ora #$40 +; bne cputdirect + + + +; Set cursor position, calculate RAM pointers + +plot: ldy CURS_Y + lda ScrLo,y + sta SCREEN_PTR + lda ScrHi,y +; ldy SCR_LINELEN +; cpy #40+1 +; bcc @L1 +; asl SCREEN_PTR ; 80 column mode +; rol a +;@L1: ora #$80 ; Screen at $8000 + sta SCREEN_PTR+1 + rts + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: +; ora RVS ; Set revers bit + ldy CURS_X + sta (SCREEN_PTR),y ; Set char + rts + +; Screen address tables - offset to real screen + +.rodata + +ScrLo: .byte $83, $A3, $C3, $E3, $03, $23, $43, $63 + .byte $83, $A3, $C3, $E3, $03, $23, $43, $63 + .byte $83, $A3, $C3, $E3, $03, $23, $43, $63 + .byte $83 + +ScrHi: .byte $D0, $D0, $D0, $D0, $D1, $D1, $D1, $D1 + .byte $D1, $D1, $D1, $D1, $D2, $D2, $D2, $D2 + .byte $D2, $D2, $D2, $D2, $D3, $D3, $D3, $D3 + .byte $D3 diff --git a/libsrc/c1p/extzp.inc b/libsrc/c1p/extzp.inc new file mode 100644 index 000000000..0f9632df2 --- /dev/null +++ b/libsrc/c1p/extzp.inc @@ -0,0 +1,7 @@ +; +; Additional zero page locations for the Challenger 1P. +; + +; ------------------------------------------------------------------------ + + .globalzp CURS_X, CURS_Y, SCR_LINELEN, SCREEN_PTR diff --git a/libsrc/c1p/extzp.s b/libsrc/c1p/extzp.s new file mode 100644 index 000000000..139feffde --- /dev/null +++ b/libsrc/c1p/extzp.s @@ -0,0 +1,23 @@ +; +; Additional zero page locations for the Challenger 1P. +; NOTE: The zeropage locations contained in this file get initialized +; in the startup code, so if you change anything here, be sure to check +; not only the linker config, but also the startup file. +; + +; ------------------------------------------------------------------------ + + .include "extzp.inc" + +.segment "EXTZP" : zeropage + +; The following values get initialized from a table in the startup code. +; While this sounds crazy, it has reasons that have to do with modules (and +; we have the space anyway). So when changing anything, be sure to adjust the +; initializer table +CURS_X: .byte 0 +CURS_Y: .byte 0 +SCR_LINELEN: .byte 24 +SCREEN_PTR: .res 2 + +; size 5 diff --git a/libsrc/c1p/gotoxy.s b/libsrc/c1p/gotoxy.s new file mode 100644 index 000000000..64c6bd21d --- /dev/null +++ b/libsrc/c1p/gotoxy.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void gotoxy (unsigned char x, unsigned char y); +; + + .export _gotoxy + .import popa, plot + .importzp CURS_X, CURS_Y + +_gotoxy: + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position + + From 12ca22c2654ee5070e699cc15f77bb7888d1dee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sat, 22 Nov 2014 18:14:52 +0100 Subject: [PATCH 019/351] Remove unnecessary commented code. --- libsrc/c1p/cputc.s | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) diff --git a/libsrc/c1p/cputc.s b/libsrc/c1p/cputc.s index 192aec097..35326d04b 100644 --- a/libsrc/c1p/cputc.s +++ b/libsrc/c1p/cputc.s @@ -1,10 +1,10 @@ ; -; Ullrich von Bassewitz, 06.08.1998 +; cputc/cputcxy for Challenger 1P +; Based on PET/CBM implementation ; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; - .export _cputcxy, _cputc, cputdirect, putchar .export newline, plot .import popa, _gotoxy @@ -29,18 +29,6 @@ _cputc: cmp #$0A ; CR? L1: cmp #$0D ; LF? beq newline ; Recalculate pointers -; Printable char of some sort - -; cmp #' ' -; bcc cputdirect ; Other control char < 0x20 -; tay -; bmi L10 -; cmp #$60 -; bcc L2 -; and #$DF -; bne cputdirect ; Branch always -;L2: and #$3F - cputdirect: jsr putchar ; Write the character to the screen @@ -65,39 +53,17 @@ newline: L4: inc CURS_Y rts -; Handle character if high bit set - -; L10: and #$7F -; cmp #$7E ; PI? -; bne L11 -; lda #$5E ; Load screen code for PI -; bne cputdirect -; L11: ora #$40 -; bne cputdirect - - - -; Set cursor position, calculate RAM pointers - plot: ldy CURS_Y lda ScrLo,y sta SCREEN_PTR lda ScrHi,y -; ldy SCR_LINELEN -; cpy #40+1 -; bcc @L1 -; asl SCREEN_PTR ; 80 column mode -; rol a -;@L1: ora #$80 ; Screen at $8000 sta SCREEN_PTR+1 rts - ; Write one character to the screen without doing anything else, return X ; position in Y putchar: -; ora RVS ; Set revers bit ldy CURS_X sta (SCREEN_PTR),y ; Set char rts From 0c62ddf123179f49bddff29e87b161278e76afb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 23 Nov 2014 15:32:48 +0100 Subject: [PATCH 020/351] Enhancements for cursor calculation Fix handling of newlines. Wrap around to top of screen when newline occurs in last line. Initialize screen width in crt0.s. --- libsrc/c1p/cputc.s | 14 ++++++-------- libsrc/c1p/crt0.s | 8 ++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libsrc/c1p/cputc.s b/libsrc/c1p/cputc.s index 35326d04b..ca9152aa7 100644 --- a/libsrc/c1p/cputc.s +++ b/libsrc/c1p/cputc.s @@ -44,14 +44,12 @@ L3: iny rts newline: - lda SCR_LINELEN ; xsize-1 - sec ; Account for -1 above - adc SCREEN_PTR - sta SCREEN_PTR - bcc L4 - inc SCREEN_PTR+1 -L4: inc CURS_Y - rts + inc CURS_Y + lda CURS_Y + cmp #24 ; screen height 25 lines hardcoded + bne plot + lda #0 ; wrap around to line 0 + sta CURS_Y plot: ldy CURS_Y lda ScrLo,y diff --git a/libsrc/c1p/crt0.s b/libsrc/c1p/crt0.s index 97d572608..8f25c2a8d 100644 --- a/libsrc/c1p/crt0.s +++ b/libsrc/c1p/crt0.s @@ -13,6 +13,7 @@ .import zerobss, initlib, donelib .include "zeropage.inc" +.include "extzp.inc" ; --------------------------------------------------------------------------- ; Place the startup code in a special segment @@ -26,6 +27,13 @@ _init: LDX #$FF ; Initialize stack pointer to $01FF TXS CLD ; Clear decimal mode +; --------------------------------------------------------------------------- +; Initialize screen width +; TODO: Can initialization be done in a more idiomatic way? +; TODO: Create function for changing screen width + LDA #$18 + STA SCR_LINELEN + ; --------------------------------------------------------------------------- ; Set cc65 argument stack pointer From 1e88032608d5a7da421f1722acbc842a38d132ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 23 Nov 2014 15:56:38 +0100 Subject: [PATCH 021/351] Copied wherex, wherey and ctype implementations from CBM --- libsrc/c1p/ctype.s | 290 ++++++++++++++++++++++++++++++++++++++++++++ libsrc/c1p/wherex.s | 14 +++ libsrc/c1p/wherey.s | 14 +++ 3 files changed, 318 insertions(+) create mode 100644 libsrc/c1p/ctype.s create mode 100644 libsrc/c1p/wherex.s create mode 100644 libsrc/c1p/wherey.s diff --git a/libsrc/c1p/ctype.s b/libsrc/c1p/ctype.s new file mode 100644 index 000000000..dd7ac62c3 --- /dev/null +++ b/libsrc/c1p/ctype.s @@ -0,0 +1,290 @@ +; +; Character specification table. +; +; Ullrich von Bassewitz, 02.06.1998 +; 2003-05-02, Greg King +; +; Copied from cbm/ctype.s + +; The following 256-byte-wide table specifies attributes for the isxxx type +; of functions. Doing it by a table means some overhead in space, but it +; has major advantages: +; +; * It is fast. If it weren't for the slow parameter-passing of cc65, +; one even could define C-language macroes for the isxxx functions +; (as it usually is done, on other platforms). +; +; * It is highly portable. The only unportable part is the table itself; +; all real code goes into the common library. +; +; * We save some code in the isxxx functions. + +; This table is taken from Craig S. Bruce's technical docs. for the ACE OS. + + .include "ctype.inc" + +; The table is read-only, put it into the RODATA segment. + + .rodata + +__ctype: + .byte CT_CTRL ; 0/00 ___rvs_@___ + .byte CT_CTRL ; 1/01 ___rvs_a___ + .byte CT_CTRL ; 2/02 ___rvs_b___ + .byte CT_CTRL ; 3/03 ___rvs_c___ + .byte CT_CTRL ; 4/04 ___rvs_d___ + .byte CT_CTRL ; 5/05 ___rvs_e___ + .byte CT_CTRL ; 6/06 ___rvs_f___ + .byte CT_CTRL ; 7/07 _BEL/rvs_g_ + .byte CT_CTRL ; 8/08 ___rvs_h___ + .byte CT_CTRL | CT_OTHER_WS | CT_SPACE_TAB ; 9/09 _TAB/rvs_i_ + .byte CT_CTRL | CT_OTHER_WS ; 10/0a _BOL/rvs_j_ + .byte CT_CTRL ; 11/0b ___rvs_k___ + .byte CT_CTRL ; 12/0c ___rvs_l___ + .byte CT_CTRL | CT_OTHER_WS ; 13/0d _CR_/rvs_m_ + .byte CT_CTRL ; 14/0e ___rvs_n___ + .byte CT_CTRL ; 15/0f ___rvs_o___ + .byte CT_CTRL ; 16/10 ___rvs_p___ + .byte CT_CTRL | CT_OTHER_WS ; 17/11 _VT_/rvs_q_ + .byte CT_CTRL ; 18/12 ___rvs_r___ + .byte CT_CTRL | CT_OTHER_WS ; 19/13 HOME/rvs_s_ + .byte CT_CTRL | CT_OTHER_WS ; 20/14 _BS_/rvs_t_ + .byte CT_CTRL ; 21/15 ___rvs_u___ + .byte CT_CTRL ; 22/16 ___rvs_v___ + .byte CT_CTRL ; 23/17 ___rvs_w___ + .byte CT_CTRL ; 24/18 ___rvs_x___ + .byte CT_CTRL ; 25/19 ___rvs_y___ + .byte CT_CTRL ; 26/1a ___rvs_z___ + .byte CT_CTRL ; 27/1b ___rvs_[___ + .byte CT_CTRL ; 28/1c ___rvs_\___ + .byte CT_CTRL | CT_OTHER_WS ; 29/1d cursr-right + .byte CT_CTRL ; 30/1e ___rvs_^___ + .byte CT_CTRL ; 31/1f _rvs_under_ + .byte CT_SPACE | CT_SPACE_TAB ; 32/20 ___SPACE___ + .byte $00 ; 33/21 _____!_____ + .byte $00 ; 34/22 _____"_____ + .byte $00 ; 35/23 _____#_____ + .byte $00 ; 36/24 _____$_____ + .byte $00 ; 37/25 _____%_____ + .byte $00 ; 38/26 _____&_____ + .byte $00 ; 39/27 _____'_____ + .byte $00 ; 40/28 _____(_____ + .byte $00 ; 41/29 _____)_____ + .byte $00 ; 42/2a _____*_____ + .byte $00 ; 43/2b _____+_____ + .byte $00 ; 44/2c _____,_____ + .byte $00 ; 45/2d _____-_____ + .byte $00 ; 46/2e _____._____ + .byte $00 ; 47/2f _____/_____ + .byte CT_DIGIT | CT_XDIGIT ; 48/30 _____0_____ + .byte CT_DIGIT | CT_XDIGIT ; 49/31 _____1_____ + .byte CT_DIGIT | CT_XDIGIT ; 50/32 _____2_____ + .byte CT_DIGIT | CT_XDIGIT ; 51/33 _____3_____ + .byte CT_DIGIT | CT_XDIGIT ; 52/34 _____4_____ + .byte CT_DIGIT | CT_XDIGIT ; 53/35 _____5_____ + .byte CT_DIGIT | CT_XDIGIT ; 54/36 _____6_____ + .byte CT_DIGIT | CT_XDIGIT ; 55/37 _____7_____ + .byte CT_DIGIT | CT_XDIGIT ; 56/38 _____8_____ + .byte CT_DIGIT | CT_XDIGIT ; 57/39 _____9_____ + .byte $00 ; 58/3a _____:_____ + .byte $00 ; 59/3b _____;_____ + .byte $00 ; 60/3c _____<_____ + .byte $00 ; 61/3d _____=_____ + .byte $00 ; 62/3e _____>_____ + .byte $00 ; 63/3f _____?_____ + + .byte $00 ; 64/40 _____@_____ + .byte CT_LOWER | CT_XDIGIT ; 65/41 _____a_____ + .byte CT_LOWER | CT_XDIGIT ; 66/42 _____b_____ + .byte CT_LOWER | CT_XDIGIT ; 67/43 _____c_____ + .byte CT_LOWER | CT_XDIGIT ; 68/44 _____d_____ + .byte CT_LOWER | CT_XDIGIT ; 69/45 _____e_____ + .byte CT_LOWER | CT_XDIGIT ; 70/46 _____f_____ + .byte CT_LOWER ; 71/47 _____g_____ + .byte CT_LOWER ; 72/48 _____h_____ + .byte CT_LOWER ; 73/49 _____i_____ + .byte CT_LOWER ; 74/4a _____j_____ + .byte CT_LOWER ; 75/4b _____k_____ + .byte CT_LOWER ; 76/4c _____l_____ + .byte CT_LOWER ; 77/4d _____m_____ + .byte CT_LOWER ; 78/4e _____n_____ + .byte CT_LOWER ; 79/4f _____o_____ + .byte CT_LOWER ; 80/50 _____p_____ + .byte CT_LOWER ; 81/51 _____q_____ + .byte CT_LOWER ; 82/52 _____r_____ + .byte CT_LOWER ; 83/53 _____s_____ + .byte CT_LOWER ; 84/54 _____t_____ + .byte CT_LOWER ; 85/55 _____u_____ + .byte CT_LOWER ; 86/56 _____v_____ + .byte CT_LOWER ; 87/57 _____w_____ + .byte CT_LOWER ; 88/58 _____x_____ + .byte CT_LOWER ; 89/59 _____y_____ + .byte CT_LOWER ; 90/5a _____z_____ + .byte $00 ; 91/5b _____[_____ + .byte $00 ; 92/5c _____\_____ + .byte $00 ; 93/5d _____]_____ + .byte $00 ; 94/5e _____^_____ + .byte $00 ; 95/5f _UNDERLINE_ + .byte $00 ; 96/60 _A`_grave__ + .byte $00 ; 97/61 _A'_acute__ + .byte $00 ; 98/62 _A^_circum_ + .byte $00 ; 99/63 _A~_tilde__ + .byte $00 ; 100/64 _A"_dieres_ + .byte $00 ; 101/65 _A__ring___ + .byte $00 ; 102/66 _AE________ + .byte $00 ; 103/67 _C,cedilla_ + .byte $00 ; 104/68 _E`_grave__ + .byte $00 ; 105/69 _E'_acute__ + .byte $00 ; 106/6a _E^_circum_ + .byte $00 ; 107/6b _E"_dieres_ + .byte $00 ; 108/6c _I`_grave__ + .byte $00 ; 109/6d _I'_acute__ + .byte $00 ; 110/6e _I^_circum_ + .byte $00 ; 111/6f _I"_dieres_ + .byte $00 ; 112/70 _D-_Eth_lr_ + .byte $00 ; 113/71 _N~_tilde__ + .byte $00 ; 114/72 _O`_grave__ + .byte $00 ; 115/73 _O'_acute__ + .byte $00 ; 116/74 _O^_circum_ + .byte $00 ; 117/75 _O~_tilde__ + .byte $00 ; 118/76 _O"_dieres_ + .byte $00 ; 119/77 __multiply_ + .byte $00 ; 120/78 _O/_slash__ + .byte $00 ; 121/79 _U`_grave__ + .byte $00 ; 122/7a _U'_acute__ + .byte $00 ; 123/7b _U^_circum_ + .byte $00 ; 124/7c _U"_dieres_ + .byte $00 ; 125/7d _Y'_acute__ + .byte $00 ; 126/7e _cap_thorn_ + .byte $00 ; 127/7f _Es-sed_B__ + + .byte CT_CTRL ; 128/80 __bullet___ + .byte CT_CTRL ; 129/81 __v_line___ + .byte CT_CTRL ; 130/82 __h_line___ + .byte CT_CTRL ; 131/83 ___cross___ + .byte CT_CTRL ; 132/84 _tl_corner_ + .byte CT_CTRL ; 133/85 _tr_corner_ + .byte CT_CTRL ; 134/86 _bl_corner_ + .byte CT_CTRL ; 135/87 _br_corner_ + .byte CT_CTRL ; 136/88 ___l_tee___ + .byte CT_CTRL ; 137/89 ___r_tee___ + .byte CT_CTRL ; 138/8a ___t_tee___ + .byte CT_CTRL ; 139/8b ___b_tee___ + .byte CT_CTRL ; 140/8c ___heart___ + .byte CT_CTRL | CT_OTHER_WS ; 141/8d _CR/diamond + .byte CT_CTRL ; 142/8e ___club____ + .byte CT_CTRL ; 143/8f ___spade___ + .byte CT_CTRL ; 144/90 _s_circle__ + .byte CT_CTRL | CT_OTHER_WS ; 145/91 _cursor-up_ + .byte CT_CTRL ; 146/92 ___pound___ + .byte CT_CTRL | CT_OTHER_WS ; 147/93 _CLS/check_ + .byte CT_CTRL | CT_OTHER_WS ; 148/94 __INSert___ + .byte CT_CTRL ; 149/95 ____+/-____ + .byte CT_CTRL ; 150/96 __divide___ + .byte CT_CTRL ; 151/97 __degree___ + .byte CT_CTRL ; 152/98 _c_checker_ + .byte CT_CTRL ; 153/99 _f_checker_ + .byte CT_CTRL ; 154/9a _solid_sq__ + .byte CT_CTRL ; 155/9b __cr_char__ + .byte CT_CTRL ; 156/9c _up_arrow__ + .byte CT_CTRL | CT_OTHER_WS ; 157/9d cursor-left + .byte CT_CTRL ; 158/9e _left_arro_ + .byte CT_CTRL ; 159/9f _right_arr_ + .byte CT_SPACE | CT_SPACE_TAB ; 160/a0 _req space_ + .byte $00 ; 161/a1 _!_invertd_ + .byte $00 ; 162/a2 ___cent____ + .byte $00 ; 163/a3 ___pound___ + .byte $00 ; 164/a4 __currency_ + .byte $00 ; 165/a5 ____yen____ + .byte $00 ; 166/a6 _|_broken__ + .byte $00 ; 167/a7 __section__ + .byte $00 ; 168/a8 __umulaut__ + .byte $00 ; 169/a9 _copyright_ + .byte $00 ; 170/aa __fem_ord__ + .byte $00 ; 171/ab _l_ang_quo_ + .byte $00 ; 172/ac ____not____ + .byte $00 ; 173/ad _syl_hyphn_ + .byte $00 ; 174/ae _registerd_ + .byte $00 ; 175/af _overline__ + .byte $00 ; 176/b0 __degrees__ + .byte $00 ; 177/b1 ____+/-____ + .byte $00 ; 178/b2 _2_supersc_ + .byte $00 ; 179/b3 _3_supersc_ + .byte $00 ; 180/b4 ___acute___ + .byte $00 ; 181/b5 ____mu_____ + .byte $00 ; 182/b6 _paragraph_ + .byte $00 ; 183/b7 __mid_dot__ + .byte $00 ; 184/b8 __cedilla__ + .byte $00 ; 185/b9 _1_supersc_ + .byte $00 ; 186/ba __mas_ord__ + .byte $00 ; 187/bb _r_ang_quo_ + .byte $00 ; 188/bc ____1/4____ + .byte $00 ; 189/bd ____1/2____ + .byte $00 ; 190/be ____3/4____ + .byte $00 ; 191/bf _?_invertd_ + + .byte $00 ; 192/c0 _____`_____ + .byte CT_UPPER | CT_XDIGIT ; 193/c1 _____A_____ + .byte CT_UPPER | CT_XDIGIT ; 194/c2 _____B_____ + .byte CT_UPPER | CT_XDIGIT ; 195/c3 _____C_____ + .byte CT_UPPER | CT_XDIGIT ; 196/c4 _____D_____ + .byte CT_UPPER | CT_XDIGIT ; 197/c5 _____E_____ + .byte CT_UPPER | CT_XDIGIT ; 198/c6 _____F_____ + .byte CT_UPPER ; 199/c7 _____G_____ + .byte CT_UPPER ; 200/c8 _____H_____ + .byte CT_UPPER ; 201/c9 _____I_____ + .byte CT_UPPER ; 202/ca _____J_____ + .byte CT_UPPER ; 203/cb _____K_____ + .byte CT_UPPER ; 204/cc _____L_____ + .byte CT_UPPER ; 205/cd _____M_____ + .byte CT_UPPER ; 206/ce _____N_____ + .byte CT_UPPER ; 207/cf _____O_____ + .byte CT_UPPER ; 208/d0 _____P_____ + .byte CT_UPPER ; 209/d1 _____Q_____ + .byte CT_UPPER ; 210/d2 _____R_____ + .byte CT_UPPER ; 211/d3 _____S_____ + .byte CT_UPPER ; 212/d4 _____T_____ + .byte CT_UPPER ; 213/d5 _____U_____ + .byte CT_UPPER ; 214/d6 _____V_____ + .byte CT_UPPER ; 215/d7 _____W_____ + .byte CT_UPPER ; 216/d8 _____X_____ + .byte CT_UPPER ; 217/d9 _____Y_____ + .byte CT_UPPER ; 218/da _____Z_____ + .byte $00 ; 219/db _____{_____ + .byte $00 ; 220/dc _____|_____ + .byte $00 ; 221/dd _____}_____ + .byte $00 ; 222/de _____~_____ + .byte $00 ; 223/df ___HOUSE___ + .byte $00 ; 224/e0 _a`_grave__ + .byte $00 ; 225/e1 _a'_acute__ + .byte $00 ; 226/e2 _a^_circum_ + .byte $00 ; 227/e3 _a~_tilde__ + .byte $00 ; 228/e4 _a"_dieres_ + .byte $00 ; 229/e5 _a__ring___ + .byte $00 ; 230/e6 _ae________ + .byte $00 ; 231/e7 _c,cedilla_ + .byte $00 ; 232/e8 _e`_grave__ + .byte $00 ; 233/e9 _e'_acute__ + .byte $00 ; 234/ea _e^_circum_ + .byte $00 ; 235/eb _e"_dieres_ + .byte $00 ; 236/ec _i`_grave__ + .byte $00 ; 237/ed _i'_acute__ + .byte $00 ; 238/ee _i^_circum_ + .byte $00 ; 239/ef _i"_dieres_ + .byte $00 ; 240/f0 _o^x_Eth_s_ + .byte $00 ; 241/f1 _n~_tilda__ + .byte $00 ; 242/f2 _o`_grave__ + .byte $00 ; 243/f3 _o'_acute__ + .byte $00 ; 244/f4 _o^_circum_ + .byte $00 ; 245/f5 _o~_tilde__ + .byte $00 ; 246/f6 _o"_dieres_ + .byte $00 ; 247/f7 __divide___ + .byte $00 ; 248/f8 _o/_slash__ + .byte $00 ; 249/f9 _u`_grave__ + .byte $00 ; 250/fa _u'_acute__ + .byte $00 ; 251/fb _u^_circum_ + .byte $00 ; 252/fc _u"_dieres_ + .byte $00 ; 253/fd _y'_acute__ + .byte $00 ; 254/fe _sm_thorn__ + .byte $00 ; 255/ff _y"_dieres_ + diff --git a/libsrc/c1p/wherex.s b/libsrc/c1p/wherex.s new file mode 100644 index 000000000..7c772a5a2 --- /dev/null +++ b/libsrc/c1p/wherex.s @@ -0,0 +1,14 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; Copied from cbm/wherex.s + +; unsigned char wherex (void); +; + .export _wherex + .import CURS_X: zp + +.proc _wherex + lda CURS_X + ldx #$00 + rts +.endproc diff --git a/libsrc/c1p/wherey.s b/libsrc/c1p/wherey.s new file mode 100644 index 000000000..7449c1ceb --- /dev/null +++ b/libsrc/c1p/wherey.s @@ -0,0 +1,14 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; Copied from cbm/wherey.s +; +; unsigned char wherey (void); +; + .export _wherey + .import CURS_Y: zp + +.proc _wherey + lda CURS_Y + ldx #$00 + rts +.endproc From 1c028c794a86116e9b0a740eaca11fdfb9e5602f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 23 Nov 2014 19:43:24 +0100 Subject: [PATCH 022/351] Clarify help for -o option --- src/c1p65/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c1p65/main.c b/src/c1p65/main.c index e4358ddcd..d5e813a3f 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -27,7 +27,7 @@ static void Usage (void) "Short options:\n" " -V\t\t\tPrint the version number\n" " -h\t\t\tHelp (this text)\n" - " -o name\t\tName the C1P output file (default: )\n" + " -o name\t\tName the C1P output file (default: .c1p)\n" " -S addr\t\tLoad address (default 0x400)\n" "\n" "Long options:\n" From dfbd2912ccf6cb56c361470d9b7ef7724790c0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 23 Nov 2014 19:44:45 +0100 Subject: [PATCH 023/351] Fix help text for default start address --- src/c1p65/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c1p65/main.c b/src/c1p65/main.c index d5e813a3f..50edcde88 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -28,7 +28,7 @@ static void Usage (void) " -V\t\t\tPrint the version number\n" " -h\t\t\tHelp (this text)\n" " -o name\t\tName the C1P output file (default: .c1p)\n" - " -S addr\t\tLoad address (default 0x400)\n" + " -S addr\t\tLoad address (default 0x300)\n" "\n" "Long options:\n" " --help\t\tHelp (this text)\n" From 16bdb10bfe57f3d9d887e0203f0b514636b035d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= Date: Sun, 23 Nov 2014 20:05:38 +0100 Subject: [PATCH 024/351] Default is now automatic execution of program after loading --- src/c1p65/main.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/c1p65/main.c b/src/c1p65/main.c index 50edcde88..5edc525eb 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -27,6 +27,7 @@ static void Usage (void) "Short options:\n" " -V\t\t\tPrint the version number\n" " -h\t\t\tHelp (this text)\n" + " -n\t\tNo automatic start after loading program\n" " -o name\t\tName the C1P output file (default: .c1p)\n" " -S addr\t\tLoad address (default 0x300)\n" "\n" @@ -79,16 +80,17 @@ static unsigned long CvtNumber (const char* Arg, const char* Number) } /* Commands of C1P PROM monitor */ -#define ADDRESS_MODE_CMD '.' -#define DATA_MODE_CMD '/' -#define EXECUTE_CMD 'G' +#define ADDRESS_MODE_CMD '.' +#define DATA_MODE_CMD '/' +#define EXECUTE_CMD 'G' #define DATA_MODE_ADDRESS 0x00FB /* Transform the cc65 executable binary into a series of commands that make the C1P PROM monitor load the bytes into memory. */ -static void Transform (unsigned long StartAddress, FILE *In, FILE *Out) +static void Transform (unsigned long StartAddress, FILE *In, FILE *Out, + unsigned AutoStart) { int c; @@ -101,15 +103,17 @@ static void Transform (unsigned long StartAddress, FILE *In, FILE *Out) fprintf(Out, "%02.2X\n", (unsigned int) c & 0xFF); } - /* Store 00 to 0x00FB to enable keyboard input at the end */ - fprintf(Out, "%c%04.4X%c%02.2X\n", ADDRESS_MODE_CMD, - 0x00FB, DATA_MODE_CMD, 0x00); - - /* And execute - fprintf (Out, "%c%04.4x%c", + if (AutoStart) { + /* Execute */ + fprintf (Out, "%c%04.4x%c", ADDRESS_MODE_CMD, (unsigned int) StartAddress & 0xFFFF, EXECUTE_CMD); - */ + } + else { + /* Store 00 to 0x00FB to enable keyboard input at the end */ + fprintf(Out, "%c%04.4X%c%02.2X\n", ADDRESS_MODE_CMD, + 0x00FB, DATA_MODE_CMD, 0x00); + } } /* Default suffix for C1P object file */ @@ -135,6 +139,9 @@ int main (int argc, char *argv[]) /* Initialize with default start address defined in c1p.cfg */ unsigned long StartAddr = 0x300; + /* Start program automatically after loading */ + unsigned AutoStart = 1; + unsigned int I; /* Initialize the cmdline module */ @@ -155,11 +162,15 @@ int main (int argc, char *argv[]) LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); break; - case 'o': - OutputFile = GetArg (&I, 2); - break; + case 'n': + AutoStart = 0; + break; - case 'S': + case 'o': + OutputFile = GetArg(&I, 2); + break; + + case 'S': StartAddr = CvtNumber (Arg, GetArg (&I, 2)); break; @@ -206,7 +217,7 @@ int main (int argc, char *argv[]) if (!OutputFileFp) AbEnd ("Unable to open output file"); /* Generate object file */ - Transform (StartAddr, InputFileFp, OutputFileFp); + Transform (StartAddr, InputFileFp, OutputFileFp, AutoStart); /* Cleanup */ if (fclose(InputFileFp) == EOF) AbEnd ("Error closing input file"); From 0ee891c1068aaf4538ae4a2a555a4dc43d8ad413 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 23 Nov 2014 15:29:16 -0500 Subject: [PATCH 025/351] Completed the coding of da65's SEGMENT feature. Before this commit, we could define segment ranges; but, the disassembler wouldn't do anything with those definitions. Now, da65 will put ".segment" directives into its output. Fixed da65's document. --- doc/da65.sgml | 122 ++++++++++++++++++++++---------------------- src/da65/attrtab.c | 56 ++++++++++++-------- src/da65/attrtab.h | 66 +++++++++++++----------- src/da65/data.c | 12 ++--- src/da65/infofile.c | 3 -- src/da65/main.c | 26 ++++++++-- src/da65/output.c | 54 +++++++++++++------- src/da65/output.h | 21 ++++---- src/da65/segment.c | 60 ++++++++++++++++------ src/da65/segment.h | 15 ++++-- 10 files changed, 261 insertions(+), 174 deletions(-) diff --git a/doc/da65.sgml b/doc/da65.sgml index 2b8cdb2a3..df8cd7772 100644 --- a/doc/da65.sgml +++ b/doc/da65.sgml @@ -2,12 +2,14 @@

da65 Users Guide -<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2003-08-08 +<author> +<url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> +<url url="mailto:greg.king5@verizon.net" name="Greg King"> +<date>2014-11-23 <abstract> -da65 is a 6502/65C02 disassembler that is able to read user supplied -information about its input data for better results. The output is ready for +da65 is a 6502/65C02 disassembler that is able to read user-supplied +information about its input data, for better results. The output is ready for feeding into ca65, the macro assembler supplied with the cc65 C compiler. </abstract> @@ -23,7 +25,7 @@ the cc65 C compiler and generates output that is suitable for the ca65 macro assembler. Besides generating output for ca65, one of the design goals was that the user -is able to feed additional information about the code into the disassembler +is able to feed additional information about the code into the disassembler, for improved results. This information may include the location and size of tables, and their format. @@ -106,11 +108,16 @@ Here is a description of all the command line options: <tag><tt>--cpu type</tt></tag> Set the CPU type. The option takes a parameter, which may be one of + <itemize> + <item>6502 + <item>6502x + <item>65sc02 + <item>65c02 + <item>huc6280 + </itemize> - 6502, 6502x, 65sc02, 65c02, huc6280 - - 6502x is the NMOS 6502 with illegal opcodes. huc6280 is the CPU of the PC - engine. Support for the 65816 is currently not available. + 6502x is for the NMOS 6502 with unofficial opcodes. huc6280 is the CPU of + the PC engine. Support for the 65816 currently is not available. <label id="option--formfeeds"> @@ -125,7 +132,7 @@ Here is a description of all the command line options: <tag><tt>-g, --debug-info</tt></tag> This option adds the <tt/.DEBUGINFO/ command to the output file, so the - assembler will generate debug information when reassembling the generated + assembler will generate debug information when re-assembling the generated output. @@ -241,7 +248,7 @@ unsupported. The disassembler works by creating an attribute map for the whole address space ($0000 - $FFFF). Initially, all attributes are cleared. Then, an external info file (if given) is read. Disassembly is done in several passes. -In all passes with the exception of the last one, information about the +In all passes, with the exception of the last one, information about the disassembled code is gathered and added to the symbol and attribute maps. The last pass generates output using the information from the maps. @@ -275,19 +282,19 @@ braces. Attributes have a name followed by a value. The syntax of the value depends on the type of the attribute. String attributes are places in double quotes, numeric attributes may be specified as decimal numbers or hexadecimal with a leading dollar sign. There are also attributes where the attribute -value is a keyword, in this case the keyword is given as is (without quotes or +value is a keyword; in this case, the keyword is given as-is (without quotes or anything). Each attribute is terminated by a semicolon. <tscreen><verb> - group-name { attribute1 attribute-value; attribute2 attribute-value; } + group-name { attribute1 attribute-value; attribute2 attribute-value; } </verb></tscreen> <sect1>Comments<p> -Comments start with a hash mark (<tt/#/) and extend from the position of +Comments start with a hash mark (<tt/#/); and, extend from the position of the mark to the end of the current line. Hash marks inside of strings will -of course <em/not/ start a comment. +<em/not/ start a comment, of course. <sect1>Specifying global options<label id="global-options"><p> @@ -543,18 +550,17 @@ disassembled code. The following attributes are recognized: <tag><tt>END</tt></tag> Followed by a numerical value. Specifies the end address of the segment. The - end address is last the address that is part of the segment. + end address is the last address that is a part of the segment. <tag><tt>NAME</tt></tag> The attribute is followed by a string value which gives the name of the segment. </descrip> -All attributes are mandatory. Segments may not overlap. Since there is no -explicit "end this segment" pseudo op, the disassembler cannot notify the -assembler that one segment has ended. This may lead to errors if you don't -define your segments carefully. As a rule of thumb, if you're using segments, -your should define segments for all disassembled code. +All attributes are mandatory. Segments must not overlap. The disassembler will +change back to the (default) <tt/.code/ segment after the end of each defined +segment. That might not be what you want. As a rule of thumb, if you're using +segments, you should define segments for all disassembled code. <sect1>Specifying Assembler Includes<label id="infofile-asminc"><p> @@ -563,8 +569,8 @@ The <tt/ASMINC/ directive is used to give the names of input files containing symbol assignments in assembler syntax: <tscreen><verb> - Name = value - Name := value + Name = value + Name := value </verb></tscreen> The usual conventions apply for symbol names. Values may be specified as hex @@ -613,48 +619,46 @@ directives explained above: }; # One segment for the whole stuff - SEGMENT { START $E000; END $FFFF; NAME kernal; }; + SEGMENT { START $E000; END $FFFF; NAME "kernal"; }; - RANGE { START $E612; END $E631; TYPE Code; }; - RANGE { START $E632; END $E640; TYPE ByteTable; }; - RANGE { START $EA51; END $EA84; TYPE RtsTable; }; - RANGE { START $EC6C; END $ECAB; TYPE RtsTable; }; - RANGE { START $ED08; END $ED11; TYPE AddrTable; }; + RANGE { START $E612; END $E631; TYPE Code; }; + RANGE { START $E632; END $E640; TYPE ByteTable; }; + RANGE { START $EA51; END $EA84; TYPE RtsTable; }; + RANGE { START $EC6C; END $ECAB; TYPE RtsTable; }; + RANGE { START $ED08; END $ED11; TYPE AddrTable; }; - # Zero page variables - LABEL { NAME "fnadr"; ADDR $90; SIZE 3; }; - LABEL { NAME "sal"; ADDR $93; }; - LABEL { NAME "sah"; ADDR $94; }; - LABEL { NAME "sas"; ADDR $95; }; + # Zero-page variables + LABEL { NAME "fnadr"; ADDR $90; SIZE 3; }; + LABEL { NAME "sal"; ADDR $93; }; + LABEL { NAME "sah"; ADDR $94; }; + LABEL { NAME "sas"; ADDR $95; }; # Stack - LABEL { NAME "stack"; ADDR $100; SIZE 255; }; + LABEL { NAME "stack"; ADDR $100; SIZE 255; }; # Indirect vectors - LABEL { NAME "cinv"; ADDR $300; SIZE 2; }; # IRQ - LABEL { NAME "cbinv"; ADDR $302; SIZE 2; }; # BRK - LABEL { NAME "nminv"; ADDR $304; SIZE 2; }; # NMI + LABEL { NAME "cinv"; ADDR $300; SIZE 2; }; # IRQ + LABEL { NAME "cbinv"; ADDR $302; SIZE 2; }; # BRK + LABEL { NAME "nminv"; ADDR $304; SIZE 2; }; # NMI # Jump table at end of kernal ROM - LABEL { NAME "kscrorg"; ADDR $FFED; }; - LABEL { NAME "kplot"; ADDR $FFF0; }; - LABEL { NAME "kiobase"; ADDR $FFF3; }; - LABEL { NAME "kgbye"; ADDR $FFF6; }; + LABEL { NAME "kscrorg"; ADDR $FFED; }; + LABEL { NAME "kplot"; ADDR $FFF0; }; + LABEL { NAME "kiobase"; ADDR $FFF3; }; + LABEL { NAME "kgbye"; ADDR $FFF6; }; # Hardware vectors - LABEL { NAME "hanmi"; ADDR $FFFA; }; - LABEL { NAME "hares"; ADDR $FFFC; }; - LABEL { NAME "hairq"; ADDR $FFFE; }; + LABEL { NAME "hanmi"; ADDR $FFFA; }; + LABEL { NAME "hares"; ADDR $FFFC; }; + LABEL { NAME "hairq"; ADDR $FFFE; }; </verb></tscreen> - - <sect>Copyright<p> -da65 (and all cc65 binutils) are (C) Copyright 1998-2007 Ullrich von -Bassewitz. For usage of the binaries and/or sources the following +da65 (and all cc65 binutils) is (C) Copyright 1998-2011, Ullrich von +Bassewitz. For usage of the binaries and/or sources, the following conditions do apply: This software is provided 'as-is', without any expressed or implied @@ -666,20 +670,16 @@ including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: <enum> -<item> The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. -<item> Altered source versions must be plainly marked as such, and must not - be misrepresented as being the original software. -<item> This notice may not be removed or altered from any source - distribution. +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. </enum> </article> - - - - diff --git a/src/da65/attrtab.c b/src/da65/attrtab.c index 1cfb5ba45..d288d1298 100644 --- a/src/da65/attrtab.c +++ b/src/da65/attrtab.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2006 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -66,6 +66,18 @@ void AddrCheck (unsigned Addr) +attr_t GetAttr (unsigned Addr) +/* Return the attribute for the given address */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Return the attribute */ + return AttrTab[Addr]; +} + + + int SegmentDefined (unsigned Start, unsigned End) /* Return true if the atSegment bit is set somewhere in the given range */ { @@ -79,14 +91,26 @@ int SegmentDefined (unsigned Start, unsigned End) -int HaveSegmentChange (unsigned Addr) -/* Return true if the segment change attribute is set for the given address */ +int IsSegmentEnd (unsigned Addr) +/* Return true if a segment ends at the given address */ { - /* Check the given address */ - AddrCheck (Addr); + return (GetAttr (Addr) & atSegmentEnd) != 0x0000; +} - /* Return the attribute */ - return (AttrTab[Addr] & atSegmentChange) != 0; + + +int IsSegmentStart (unsigned Addr) +/* Return true if a segment starts at the given address */ +{ + return (GetAttr (Addr) & atSegmentStart) != 0x0000; +} + + + +int HaveSegmentChange (unsigned Addr) +/* Return true if the segment change attributes are set for the given address */ +{ + return (GetAttr (Addr) & (atSegmentStart | atSegmentEnd)) != 0x0000; } @@ -145,18 +169,6 @@ void MarkAddr (unsigned Addr, attr_t Attr) -attr_t GetAttr (unsigned Addr) -/* Return the attribute for the given address */ -{ - /* Check the given address */ - AddrCheck (Addr); - - /* Return the attribute */ - return AttrTab[Addr]; -} - - - attr_t GetStyleAttr (unsigned Addr) /* Return the style attribute for the given address */ { diff --git a/src/da65/attrtab.h b/src/da65/attrtab.h index c9fb9c35f..b2dc6c455 100644 --- a/src/da65/attrtab.h +++ b/src/da65/attrtab.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2006 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -47,33 +47,34 @@ typedef enum attr_t { /* Styles */ - atDefault = 0x0000, /* Default style */ - atCode = 0x0001, - atIllegal = 0x0002, - atByteTab = 0x0003, /* Same as illegal */ - atDByteTab = 0x0004, - atWordTab = 0x0005, - atDWordTab = 0x0006, - atAddrTab = 0x0007, - atRtsTab = 0x0008, - atTextTab = 0x0009, - atSkip = 0x000A, /* Skip code completely */ + atDefault = 0x0000, /* Default style */ + atCode = 0x0001, + atIllegal = 0x0002, + atByteTab = 0x0003, /* Same as illegal */ + atDByteTab = 0x0004, + atWordTab = 0x0005, + atDWordTab = 0x0006, + atAddrTab = 0x0007, + atRtsTab = 0x0008, + atTextTab = 0x0009, + atSkip = 0x000A, /* Skip code completely */ /* Label flags */ - atNoLabel = 0x0000, /* No label for this address */ - atExtLabel = 0x0010, /* External label */ - atIntLabel = 0x0020, /* Internally generated label */ - atDepLabel = 0x0040, /* Dependent label */ - atUnnamedLabel = 0x0080, /* Unnamed label */ + atNoLabel = 0x0000, /* No label for this address */ + atExtLabel = 0x0010, /* External label */ + atIntLabel = 0x0020, /* Internally generated label */ + atDepLabel = 0x0040, /* Dependent label */ + atUnnamedLabel = 0x0080, /* Unnamed label */ - atLabelDefined = 0x0100, /* True if we defined the label */ + atLabelDefined = 0x0100, /* True if we defined the label */ - atStyleMask = 0x000F, /* Output style */ - atLabelMask = 0x00F0, /* Label information */ + atStyleMask = 0x000F, /* Output style */ + atLabelMask = 0x00F0, /* Label information */ /* Segment */ - atSegment = 0x0100, /* Code is in a segment */ - atSegmentChange = 0x0200, /* Either segment start or segment end */ + atSegment = 0x0100, /* Code is in a segment */ + atSegmentEnd = 0x0200, /* Segment end */ + atSegmentStart = 0x0400, /* Segment start */ } attr_t; @@ -87,11 +88,20 @@ typedef enum attr_t { void AddrCheck (unsigned Addr); /* Check if the given address has a valid range */ +attr_t GetAttr (unsigned Addr); +/* Return the attribute for the given address */ + int SegmentDefined (unsigned Start, unsigned End); /* Return true if the atSegment bit is set somewhere in the given range */ +int IsSegmentEnd (unsigned Addr); +/* Return true if a segment ends at the given address */ + +int IsSegmentStart (unsigned Addr); +/* Return true if a segment starts at the given address */ + int HaveSegmentChange (unsigned Addr); -/* Return true if the segment change attribute is set for the given address */ +/* Return true if the segment change attributes are set for the given address */ unsigned GetGranularity (attr_t Style); /* Get the granularity for the given style */ @@ -102,9 +112,6 @@ void MarkRange (unsigned Start, unsigned End, attr_t Attr); void MarkAddr (unsigned Addr, attr_t Attr); /* Mark an address with an attribute */ -attr_t GetAttr (unsigned Addr); -/* Return the attribute for the given address */ - attr_t GetStyleAttr (unsigned Addr); /* Return the style attribute for the given address */ @@ -114,5 +121,4 @@ attr_t GetLabelAttr (unsigned Addr); /* End of attrtab.h */ - #endif diff --git a/src/da65/data.c b/src/da65/data.c index f4c37818f..7355e60d1 100644 --- a/src/da65/data.c +++ b/src/da65/data.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2007 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -65,12 +65,12 @@ static unsigned GetSpan (attr_t Style) attr_t Attr; if (MustDefLabel(PC+Count)) { break; - } + } Attr = GetAttr (PC+Count); if ((Attr & atStyleMask) != Style) { break; } - if ((Attr & atSegmentChange)) { + if ((Attr & (atSegmentStart | atSegmentEnd))) { break; } ++Count; diff --git a/src/da65/infofile.c b/src/da65/infofile.c index 4ee1ffd79..7d8e69384 100644 --- a/src/da65/infofile.c +++ b/src/da65/infofile.c @@ -748,9 +748,6 @@ static void SegmentSection (void) if (Start < 0) { InfoError ("Start address is missing"); } - if (Start == End) { - InfoError ("Segment is empty"); - } if (Start > End) { InfoError ("Start address of segment is greater than end address"); } diff --git a/src/da65/main.c b/src/da65/main.c index a819f9771..05c4a7bfd 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2011, Ullrich von Bassewitz */ +/* (C) 1998-2014, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -60,6 +60,7 @@ #include "opctable.h" #include "output.h" #include "scanner.h" +#include "segment.h" @@ -356,6 +357,14 @@ static void OneOpcode (unsigned RemainingBytes) /* Get the output style for the current PC */ attr_t Style = GetStyleAttr (PC); + /* If a segment begins here, then name that segment. + ** Note that the segment is named even if its code is being skipped, + ** because some of its later code might not be skipped. + */ + if (IsSegmentStart (PC)) { + StartSegment (GetSegmentStartName (PC), GetSegmentAddrSize (PC)); + } + /* If we have a label at this address, output the label and an attached ** comment, provided that we aren't in a skip area. */ @@ -371,7 +380,7 @@ static void OneOpcode (unsigned RemainingBytes) ** - ...if we have enough bytes remaining for the code at this address. ** - ...if the current instruction is valid for the given CPU. ** - ...if there is no label somewhere between the instruction bytes. - ** If any of these conditions is false, switch to data mode. + ** If any of those conditions is false, switch to data mode. */ if (Style == atDefault) { if (D->Size > RemainingBytes) { @@ -383,7 +392,14 @@ static void OneOpcode (unsigned RemainingBytes) } else { unsigned I; for (I = 1; I < D->Size; ++I) { - if (HaveLabel (PC+I) || HaveSegmentChange (PC+I)) { + if (HaveLabel (PC+I)) { + Style = atIllegal; + MarkAddr (PC, Style); + break; + } + } + for (I = 1; I < D->Size - 1u; ++I) { + if (HaveSegmentChange (PC+I)) { Style = atIllegal; MarkAddr (PC, Style); break; @@ -455,6 +471,10 @@ static void OneOpcode (unsigned RemainingBytes) break; } + + if (IsSegmentEnd (PC - 1)) { + EndSegment (); + } } diff --git a/src/da65/output.c b/src/da65/output.c index 9098d7d37..4daacb1ee 100644 --- a/src/da65/output.c +++ b/src/da65/output.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2009, Ullrich von Bassewitz */ +/* (C) 2000-2014, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -63,6 +63,8 @@ static unsigned Col = 1; /* Current column */ static unsigned Line = 0; /* Current line on page */ static unsigned Page = 1; /* Current output page */ +static const char* SegmentName = 0; /* Name of current segment */ + /*****************************************************************************/ @@ -223,23 +225,6 @@ void DefConst (const char* Name, const char* Comment, unsigned Addr) -void StartSegment (const char* Name, unsigned AddrSize) -/* Start a segment */ -{ - if (Pass == PassCount) { - Output (".segment"); - Indent (ACol); - if (AddrSize == ADDR_SIZE_DEFAULT) { - Output ("\"%s\"", Name); - } else { - Output ("\"%s\": %s", Name, AddrSizeToStr (AddrSize)); - } - LineFeed (); - } -} - - - void DataByteLine (unsigned ByteCount) /* Output a line with bytes */ { @@ -335,6 +320,39 @@ void SeparatorLine (void) +void StartSegment (const char* Name, unsigned AddrSize) +/* Start a segment */ +{ + if (Pass == PassCount) { + LineFeed (); + Output (".segment"); + Indent (ACol); + SegmentName = Name; + Output ("\"%s\"", Name); + if (AddrSize != ADDR_SIZE_DEFAULT) { + Output (": %s", AddrSizeToStr (AddrSize)); + } + LineFeed (); + LineFeed (); + } +} + + + +void EndSegment (void) +/* End a segment */ +{ + LineFeed (); + Output ("; End of \"%s\" segment", SegmentName); + LineFeed (); + SeparatorLine (); + Output (".code"); + LineFeed (); + LineFeed (); +} + + + void UserComment (const char* Comment) /* Output a comment line */ { diff --git a/src/da65/output.h b/src/da65/output.h index ad5f8d34e..13ea0cc85 100644 --- a/src/da65/output.h +++ b/src/da65/output.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2000-2007 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2000-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -74,12 +74,6 @@ void DefForward (const char* Name, const char* Comment, unsigned Offs); void DefConst (const char* Name, const char* Comment, unsigned Addr); /* Define an address constant */ - -void StartSegment (const char* Name, unsigned AddrSize); -/* Start a segment */ - -void EndSegment (void); -/* End a segment */ void OneDataByte (void); /* Output a .byte line with the current code byte */ @@ -99,6 +93,12 @@ void DataDWordLine (unsigned ByteCount); void SeparatorLine (void); /* Print a separator line */ +void StartSegment (const char* Name, unsigned AddrSize); +/* Start a segment */ + +void EndSegment (void); +/* End a segment */ + void UserComment (const char* Comment); /* Output a comment line */ @@ -111,5 +111,4 @@ void OutputSettings (void); /* End of output.h */ - #endif diff --git a/src/da65/segment.c b/src/da65/segment.c index cad2096ff..12d4cf656 100644 --- a/src/da65/segment.c +++ b/src/da65/segment.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2007 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2007-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -58,18 +58,15 @@ typedef struct Segment Segment; struct Segment { Segment* NextStart; /* Pointer to next segment */ - Segment* NextEnd; /* Pointer to next segment */ unsigned long Start; - unsigned long End; unsigned AddrSize; char Name[1]; /* Name, dynamically allocated */ }; -/* Tables containing the segments. A segment is inserted using it's hash -** value. Collision is done by single linked lists. +/* Table containing the segments. A segment is inserted using its hash +** value. Collisions are handled by single-linked lists. */ static Segment* StartTab[HASH_SIZE]; /* Table containing segment starts */ -static Segment* EndTab[HASH_SIZE]; /* Table containing segment ends */ @@ -90,20 +87,53 @@ void AddAbsSegment (unsigned Start, unsigned End, const char* Name) /* Fill in the data */ S->Start = Start; - S->End = End; S->AddrSize = ADDR_SIZE_ABS; memcpy (S->Name, Name, Len + 1); - /* Insert the segment into the hash tables */ + /* Insert the segment into the hash table */ S->NextStart = StartTab[Start % HASH_SIZE]; StartTab[Start % HASH_SIZE] = S; - S->NextEnd = EndTab[End % HASH_SIZE]; - EndTab[End % HASH_SIZE] = S; /* Mark start and end of the segment */ - MarkAddr (Start, atSegmentChange); - MarkAddr (End, atSegmentChange); + MarkAddr (Start, atSegmentStart); + MarkAddr (End, atSegmentEnd); /* Mark the addresses within the segment */ MarkRange (Start, End, atSegment); } + + + +char* GetSegmentStartName (unsigned Addr) +/* Return the name of the segment which starts at the given address */ +{ + Segment* S = StartTab[Addr % HASH_SIZE]; + + /* Search the collision list for the exact address */ + while (S != 0) { + if (S->Start == Addr) { + return S->Name; + } + S = S->NextStart; + } + + return 0; +} + + + +unsigned GetSegmentAddrSize (unsigned Addr) +/* Return the address size of the segment which starts at the given address */ +{ + Segment* S = StartTab[Addr % HASH_SIZE]; + + /* Search the collision list for the exact address */ + while (S != 0) { + if (S->Start == Addr) { + return S->AddrSize; + } + S = S->NextStart; + } + + return 0; +} diff --git a/src/da65/segment.h b/src/da65/segment.h index 14700ba99..b1423bb41 100644 --- a/src/da65/segment.h +++ b/src/da65/segment.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 2007 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 2007-2014, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -47,8 +47,13 @@ void AddAbsSegment (unsigned Start, unsigned End, const char* Name); /* Add an absolute segment to the segment table */ +char* GetSegmentStartName (unsigned Addr); +/* Return the name of the segment which starts at the given address */ + +unsigned GetSegmentAddrSize (unsigned Addr); +/* Return the address size of the segment which starts at the given address */ + /* End of segment.h */ - #endif From a66c93c55bbe60bb43513ecf5ddbfa8eee5b8a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Wed, 26 Nov 2014 19:01:15 +0100 Subject: [PATCH 026/351] Use CR instead of LF, because this works better over the serial port of a real C1P. --- src/c1p65/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c1p65/main.c b/src/c1p65/main.c index 5edc525eb..3d6cdbe8b 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -100,7 +100,7 @@ static void Transform (unsigned long StartAddress, FILE *In, FILE *Out, /* Loop over all input bytes and enter them one by one */ for (c = getc(In); c != EOF; c = getc(In)) { - fprintf(Out, "%02.2X\n", (unsigned int) c & 0xFF); + fprintf(Out, "%02.2X\r", (unsigned int) c & 0xFF); } if (AutoStart) { @@ -111,7 +111,7 @@ static void Transform (unsigned long StartAddress, FILE *In, FILE *Out, } else { /* Store 00 to 0x00FB to enable keyboard input at the end */ - fprintf(Out, "%c%04.4X%c%02.2X\n", ADDRESS_MODE_CMD, + fprintf(Out, "%c%04.4X%c%02.2X", ADDRESS_MODE_CMD, 0x00FB, DATA_MODE_CMD, 0x00); } } From faccc5a3d640a111ac5b2e8a8f25debd77cc91b7 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 29 Nov 2014 14:18:48 +0100 Subject: [PATCH 027/351] initial import, completely untested, does not compile yet --- libsrc/Makefile | 1 + libsrc/pcengine/_heap.s | 67 +++++++++ libsrc/pcengine/_scrsize.s | 17 +++ libsrc/pcengine/call.s | 19 +++ libsrc/pcengine/clock.s | 23 +++ libsrc/pcengine/clrscr.s | 27 ++++ libsrc/pcengine/color.s | 59 ++++++++ libsrc/pcengine/condes.s | 102 +++++++++++++ libsrc/pcengine/conio.s | 122 ++++++++++++++++ libsrc/pcengine/cputc.s | 117 +++++++++++++++ libsrc/pcengine/crt0.s | 233 +++++++++++++++++++++++++++++ libsrc/pcengine/huc6280.inc | 238 ++++++++++++++++++++++++++++++ libsrc/pcengine/joytokbd.s | 275 +++++++++++++++++++++++++++++++++++ libsrc/pcengine/kplot.s | 41 ++++++ libsrc/pcengine/pce-stdjoy.s | 191 ++++++++++++++++++++++++ libsrc/pcengine/pcengine.h | 74 ++++++++++ libsrc/pcengine/pcengine.inc | 75 ++++++++++ libsrc/pcengine/pcengine.x | 68 +++++++++ libsrc/pcengine/psg.s | 29 ++++ libsrc/pcengine/revers.s | 5 + libsrc/pcengine/vce.s | 16 ++ libsrc/pcengine/vdc.s | 46 ++++++ libsrc/pcengine/vga.inc | 129 ++++++++++++++++ 23 files changed, 1974 insertions(+) create mode 100644 libsrc/pcengine/_heap.s create mode 100644 libsrc/pcengine/_scrsize.s create mode 100644 libsrc/pcengine/call.s create mode 100644 libsrc/pcengine/clock.s create mode 100644 libsrc/pcengine/clrscr.s create mode 100644 libsrc/pcengine/color.s create mode 100644 libsrc/pcengine/condes.s create mode 100644 libsrc/pcengine/conio.s create mode 100644 libsrc/pcengine/cputc.s create mode 100644 libsrc/pcengine/crt0.s create mode 100644 libsrc/pcengine/huc6280.inc create mode 100644 libsrc/pcengine/joytokbd.s create mode 100644 libsrc/pcengine/kplot.s create mode 100644 libsrc/pcengine/pce-stdjoy.s create mode 100644 libsrc/pcengine/pcengine.h create mode 100644 libsrc/pcengine/pcengine.inc create mode 100644 libsrc/pcengine/pcengine.x create mode 100644 libsrc/pcengine/psg.s create mode 100644 libsrc/pcengine/revers.s create mode 100644 libsrc/pcengine/vce.s create mode 100644 libsrc/pcengine/vdc.s create mode 100644 libsrc/pcengine/vga.inc diff --git a/libsrc/Makefile b/libsrc/Makefile index 6a801695a..051e5cf3a 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -24,6 +24,7 @@ TARGETS = apple2 \ $(GEOS) \ lynx \ nes \ + pcengine \ sim6502 \ sim65c02 \ supervision diff --git a/libsrc/pcengine/_heap.s b/libsrc/pcengine/_heap.s new file mode 100644 index 000000000..71fa13e78 --- /dev/null +++ b/libsrc/pcengine/_heap.s @@ -0,0 +1,67 @@ +; +; Ullrich von Bassewitz, 03.06.1998 +; +; Heap variables and initialization. +; + +; FIXME: there should be a way to configure heap from linkerscript! + + .constructor initheap, 24 + + .import __RAM_START__, __RAM_SIZE__, __STACKSIZE__ ; Linker generated + .import __BSS_SIZE__ + .importzp sp + +.data + +;; old - remove + .export __horg, __hptr, __hend, __hfirst, __hlast +__horg: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol +__hptr: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Dito +__hend: + .word __RAM_START__+__RAM_SIZE__ +__hfirst: + .word 0 +__hlast: + .word 0 + + .export __heaporg + .export __heapptr + .export __heapend + .export __heapfirst + .export __heaplast + +__heaporg: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol +__heapptr: + .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol +__heapend: + .word __RAM_START__+__RAM_SIZE__ +__heapfirst: + .word 0 +__heaplast: + .word 0 + + +; Initialization. Will be called from startup! + +.code + +initheap: + ;sec + ;lda sp +; lda #<(__STACKSIZE__) +; lda #<(__RAM_START__+__RAM_SIZE__) + lda #<(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) + sta __heapend + sta __hend ; old +; lda sp+1 +; lda #>(__STACKSIZE__) +; lda #>(__RAM_START__+__RAM_SIZE__) + lda #>(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) + sta __heapend+1 + sta __hend+1 ; old + rts + diff --git a/libsrc/pcengine/_scrsize.s b/libsrc/pcengine/_scrsize.s new file mode 100644 index 000000000..17b23b709 --- /dev/null +++ b/libsrc/pcengine/_scrsize.s @@ -0,0 +1,17 @@ +; +; Screen size variables +; + + + +.export _screensize +_screensize: + ldx xsize + ldy ysize + rts + +.rodata + .export xsize, ysize + +xsize: .byte 64 +ysize: .byte 28 diff --git a/libsrc/pcengine/call.s b/libsrc/pcengine/call.s new file mode 100644 index 000000000..34fbac08b --- /dev/null +++ b/libsrc/pcengine/call.s @@ -0,0 +1,19 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; CC65 runtime: call function via pointer in ax +; + + .export callax + +.code + +callax: + sta vec + stx vec+1 + jmp (vec) ; jump there + +.bss + +vec: + .res 2 \ No newline at end of file diff --git a/libsrc/pcengine/clock.s b/libsrc/pcengine/clock.s new file mode 100644 index 000000000..d344814ad --- /dev/null +++ b/libsrc/pcengine/clock.s @@ -0,0 +1,23 @@ +; +; Ullrich von Bassewitz, 21.09.1998 +; +; clock_t clock (void); +; + + .include "pcengine.inc" + + .export _clock + .importzp sreg + +.proc _clock + + ldy #0 ; Byte 3 is always zero + sty sreg+1 + sty sreg + + ldx _tickcount+1 + lda _tickcount + rts + +.endproc + diff --git a/libsrc/pcengine/clrscr.s b/libsrc/pcengine/clrscr.s new file mode 100644 index 000000000..c2c5dcbcb --- /dev/null +++ b/libsrc/pcengine/clrscr.s @@ -0,0 +1,27 @@ + + .include "pcengine.inc" + + + .export _clrscr +_clrscr: + + st0 #VDC_MAWR + st1 #<$0000 + st2 #>$0000 + + st0 #VDC_VWR + ldy #$40 +rowloop: ldx #$80 +colloop: + lda #' ' + staio VDC_DATA_LO + lda #$02 + staio VDC_DATA_HI + + dex + bne colloop + dey + bne rowloop + + rts + diff --git a/libsrc/pcengine/color.s b/libsrc/pcengine/color.s new file mode 100644 index 000000000..8d80114fc --- /dev/null +++ b/libsrc/pcengine/color.s @@ -0,0 +1,59 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _textcolor, _bgcolor, _bordercolor + + .include "pcengine.inc" + +_textcolor: + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts + +_bgcolor: + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI + + txa + rts + +_bordercolor: + lda #0 + txa + rts + + .export colors + +colors: ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray diff --git a/libsrc/pcengine/condes.s b/libsrc/pcengine/condes.s new file mode 100644 index 000000000..dd7bd30b3 --- /dev/null +++ b/libsrc/pcengine/condes.s @@ -0,0 +1,102 @@ +; +; Ullrich von Bassewitz, 20.11.2000 +; +; CC65 runtime: Support for calling module constructors/destructors +; +; The condes routine must be called with the table address in a/x and the +; size of the table in y. The current implementation limits the table size +; to 254 bytes (127 vectors) but this shouldn't be problem for now and may +; be changed later. +; +; libinit and libdone call condes with the predefined module constructor and +; destructor tables, they must be called from the platform specific startup +; code. + + + .export initlib, donelib, condes + + .import callax + .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ + .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ + + + +.code + +; -------------------------------------------------------------------------- +; Initialize library modules + +.proc initlib + + lda #<__CONSTRUCTOR_TABLE__ + ldx #>__CONSTRUCTOR_TABLE__ + ldy #<(__CONSTRUCTOR_COUNT__*2) + bne condes + rts + +.endproc + + +; -------------------------------------------------------------------------- +; Cleanup library modules + +.proc donelib + + lda #<__DESTRUCTOR_TABLE__ + ldx #>__DESTRUCTOR_TABLE__ + ldy #<(__DESTRUCTOR_COUNT__*2) + bne condes + rts + +.endproc + + +; -------------------------------------------------------------------------- +; Generic table call handler + +.proc condes + + sta getbyt+1 + stx getbyt+2 + sty index + +loop: ldy index + beq done + dey + jsr getbyt + tax + dey + jsr getbyt + sty index + jsr callax +.ifpc02 + bra loop +.else + jmp loop +.endif + +done: rts + +.endproc + + +; -------------------------------------------------------------------------- +; Data. The getbyte routine is placed in the data segment cause it's patched +; at runtime. + +.bss + +index: .byte 0 + +.data + +getbyt: +;;getbyt_: + lda $FFFF,y + rts + +;; callax doesnt work? why?! +;_callax: +; sta @l+1 +; stx @l+2 +;@l: jmp $dead diff --git a/libsrc/pcengine/conio.s b/libsrc/pcengine/conio.s new file mode 100644 index 000000000..3c4919e64 --- /dev/null +++ b/libsrc/pcengine/conio.s @@ -0,0 +1,122 @@ + .include "pcengine.inc" + .import vce_init + .import psg_init + .import vdc_init + + .export initconio + .export _conio_init + + .constructor initconio, 24 + + .macpack longbranch +initconio: + ;; jsr vdc_init + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette + + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts + + .import colors +set_palette: + + ; Make palette (use VGA palette?) + ; stz VCE_ADDR_LO + ; stz VCE_ADDR_HI + ; clx + ; cly + vce_loop: ;; stx VCE_DATA_LO + ;; sty VCE_DATA_HI + ; inx + ; cpx #$00 + ; bne vce_loop + ; iny + ; cpy #$02 + ; bne vce_loop + + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + + ldx #0 +@lp: + .repeat 16 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + .endrepeat + + inx + inx + cpx #16*2;*5 + jne @lp + + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI + +; so it will get linked in +_conio_init: + rts + +;---------------------------------------------------------------------------- +; +;---------------------------------------------------------------------------- + + .importzp ptr1 + +conio_init: + + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 + + ; ptr to font data + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 + + st0 #VDC_VWR ; VWR + ldy #$80 ; 128 chars + charloop: ldx #$08 ; 8 bytes/char + lineloop: + ;;lda [$00] ; read font byte + ldaind ptr1 + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 + + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 + fillloop: st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character + + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR + + + rts + + .rodata +font: .include "vga.inc" diff --git a/libsrc/pcengine/cputc.s b/libsrc/pcengine/cputc.s new file mode 100644 index 000000000..8a02a3499 --- /dev/null +++ b/libsrc/pcengine/cputc.s @@ -0,0 +1,117 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + + .importzp tmp3,tmp4 + + .include "pcengine.inc" + + +_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + ldy CURS_X + iny + cpy #xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot + ;rts + +newline: +; lda #xsize +; clc +; adc SCREEN_PTR +; sta SCREEN_PTR +; bcc L4 +; inc SCREEN_PTR+1 +;; clc +;L4:; lda #xsize + ; adc CRAM_PTR + ; sta CRAM_PTR + ; bcc L5 + ; inc CRAM_PTR+1 +;L5: + + inc CURS_Y + +; jmp plot +; rts + +; Set cursor position, calculate RAM pointers + +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor + + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: + + ora RVS ; Set revers bit + + tax + + st0 #VDC_MAWR ; Memory Adress Write + + lda SCREEN_PTR + staio VDC_DATA_LO + + lda SCREEN_PTR+1 + staio VDC_DATA_HI + + st0 #VDC_VWR ; VWR + + txa + staio VDC_DATA_LO ; character + + ;;st2 #$32 ; attrib ?! + lda CHARCOLOR + + ;;lda #2 + asl a + asl a + asl a + asl a + + and #$f0 + ora #$02 + staio VDC_DATA_HI + + rts diff --git a/libsrc/pcengine/crt0.s b/libsrc/pcengine/crt0.s new file mode 100644 index 000000000..d9c5a2ccb --- /dev/null +++ b/libsrc/pcengine/crt0.s @@ -0,0 +1,233 @@ +; +; Startup code for cc65 (PCEngine version) +; +; by Groepaz/Hitmen <groepaz@gmx.net> +; based on code by Ullrich von Bassewitz <uz@cc65.org> +; +; This must be the *first* file on the linker command line +; + + .export _exit + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 + + .import __RAM_START__, __RAM_SIZE__ ; Linker generated +;; .import __SRAM_START__, __SRAM_SIZE__ ; Linker generated + .import __ROM0_START__, __ROM0_SIZE__ ; Linker generated + .import __ROM_START__, __ROM_SIZE__ ; Linker generated + .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ ; Linker generated + .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ ; Linker generated + .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ ; Linker generated + .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated + .import __BSS_SIZE__ + + .include "pcengine.inc" + + .importzp sp + .importzp ptr1,ptr2 + +; ------------------------------------------------------------------------ +; Create an empty LOWCODE segment to avoid linker warnings + +.segment "LOWCODE" + +; ------------------------------------------------------------------------ +; Place the startup code in a special segment. + +.segment "STARTUP" + +start: + +; setup the CPU and System-IRQ + + ; Initialize CPU + + sei + nop + csh + nop + cld + nop + + ; Setup stack and memory mapping + ldx #$FF ; Stack top ($21FF) + txs + txa + tam #0 ; 0000-1FFF = Hardware page + + lda #$F8 + tam #1 ; 2000-3FFF = Work RAM + + lda #$F7 + tam #2 ; 4000-5FFF = Save RAM + + lda #1 + tam #3 ; 6000-7FFF Page 2 + lda #2 + tam #4 ; 8000-9FFF Page 3 + lda #3 + tam #5 ; A000-BFFF Page 4 + lda #4 + tam #6 ; C000-DFFF Page 5 + + ; Initialize hardware + stz TIMER_COUNT ; Timer off + lda #$07 + sta IRQ_MASK ; Interrupts off + stz IRQ_STATUS ; Acknowledge timer + + ; Clear work RAM + stz <$00 + tii $2000, $2001, $1FFF + + ;; i dont know why the heck this one doesnt + ;; work when called from a constructor :/ + .import vdc_init + jsr vdc_init +;; jsr joy_init + + ; Turn on background and VD interrupt/IRQ1 + lda #$05 + sta IRQ_MASK ; IRQ1=on + cli + +; Clear the BSS data + + jsr zerobss + +; Copy the .data segment to RAM + + lda #<(__DATA_LOAD__) + ;;lda #<(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__) + ;;lda #<(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) + sta ptr1 + lda #>(__DATA_LOAD__) + ;;lda #>(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) + sta ptr1+1 + lda #<(__DATA_RUN__) + ;;lda #<(__SRAM_START__) + sta ptr2 + lda #>(__DATA_RUN__) + ;;lda #>(__SRAM_START__) + sta ptr2+1 + + ldx #>(__DATA_SIZE__) + +@l2: + beq @s1 ; no more full pages + + ; copy one page + ldy #0 +@l1: + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 + + inc ptr1+1 + inc ptr2+1 + + dex + bne @l2 + + ; copy remaining bytes +@s1: + + ; copy one page + ldy #0 +@l3: + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 + +; setup the stack + +; lda #<(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp +; lda #>(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 ; Set argument stack ptr + +; Init the Heap + jsr initheap + +;jmp * + +; Call module constructors + + jsr initlib +; .import initconio +; jsr initconio +; Pass an empty command line + + +;jmp * + + jsr push0 ; argc + jsr push0 ; argv +go: + ldy #4 ; Argument size + jsr _main ; call the users code + +; Call module destructors. This is also the _exit entry. + +_exit: + jsr donelib ; Run module destructors + +; reset the PCEngine + + jmp start + +; ------------------------------------------------------------------------ +; System V-Blank Interupt +; ------------------------------------------------------------------------ + +_irq1: + pha + phx + phy + + + inc _tickcount + bne @s + inc _tickcount+1 +@s: + + ; Acknowlege interrupt + ldaio VDC_CTRL + + ply + plx + pla + rti +_irq2: + rti +_nmi: + rti +_timer: + stz IRQ_STATUS + rti + + .export initmainargs +initmainargs: + rts + +; ------------------------------------------------------------------------ +; hardware vectors +; ------------------------------------------------------------------------ + .segment "VECTORS" + ;;.org $fff6 + + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset + + + diff --git a/libsrc/pcengine/huc6280.inc b/libsrc/pcengine/huc6280.inc new file mode 100644 index 000000000..ab634a855 --- /dev/null +++ b/libsrc/pcengine/huc6280.inc @@ -0,0 +1,238 @@ + +; +; HuC6280 additional opcodes (use with --cpu 65C02) +; +; WARNING: THIS IS __NOT__ COMPLETE !!! +; + +;; lda abs +.macro ldaio arg1 + .byte $ad + .word arg1 +.endmacro +;; sta abs +.macro staio arg1 + .byte $8d + .word arg1 +.endmacro +.macro stzio arg1 + .byte $9c + .word arg1 +.endmacro + +.macro cla + .byte $62 +.endmacro +.macro clx + .byte $82 +.endmacro + +;; lda (zp) +.macro ldaind arg1 + .byte $b2 + .byte arg1 +.endmacro + +.macro cly + .byte $c2 +.endmacro + +.macro st0 arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $03 + .byte (.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro +.macro st1 arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $13 + .byte (.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro +.macro st2 arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $23 + .byte (.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro + +; tam #$xx +.macro tam arg1 + .if (.match (.left (1, arg1), #)) + ; called with immidiate operand + .byte $53 + .byte 1<<(.right (.tcount (arg1)-1, arg1)) + .else + .error "illegal address mode" + .endif +.endmacro + +; tii x,y,z +.macro tii arg1,arg2,arg3 + .byte $73 + .word arg1,arg2,arg3 +.endmacro + +.macro csh + .byte $d4 +.endmacro +.macro set + .byte $f4 +.endmacro +.macro _rmb0 arg1 + .byte $07 + .byte arg1 +.endmacro +.macro _rmb1 arg1 + .byte $17 + .byte arg1 +.endmacro +.macro _rmb2 arg1 + .byte $27 + .byte arg1 +.endmacro +.macro _rmb3 arg1 + .byte $37 + .byte arg1 +.endmacro +.macro _rmb4 arg1 + .byte $47 + .byte arg1 +.endmacro +.macro _rmb5 arg1 + .byte $57 + .byte arg1 +.endmacro +.macro _rmb6 arg1 + .byte $67 + .byte arg1 +.endmacro +.macro _rmb7 arg1 + .byte $77 + .byte arg1 +.endmacro + +.macro _smb0 arg1 + .byte $87 + .byte arg1 +.endmacro +.macro _smb1 arg1 + .byte $97 + .byte arg1 +.endmacro +.macro _smb2 arg1 + .byte $a7 + .byte arg1 +.endmacro +.macro _smb3 arg1 + .byte $b7 + .byte arg1 +.endmacro +.macro _smb4 arg1 + .byte $c7 + .byte arg1 +.endmacro +.macro _smb5 arg1 + .byte $d7 + .byte arg1 +.endmacro +.macro _smb6 arg1 + .byte $e7 + .byte arg1 +.endmacro +.macro _smb7 arg1 + .byte $f7 + .byte arg1 +.endmacro + +.macro _bbr0 arg1,arg2 + .byte $0f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs0 arg1,arg2 + .byte $8f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr1 arg1,arg2 + .byte $1f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs1 arg1,arg2 + .byte $9f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr2 arg1,arg2 + .byte $2f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs2 arg1,arg2 + .byte $af ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr3 arg1,arg2 + .byte $3f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs3 arg1,arg2 + .byte $bf ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr4 arg1,arg2 + .byte $4f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs4 arg1,arg2 + .byte $cf ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr5 arg1,arg2 + .byte $5f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs5 arg1,arg2 + .byte $df ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr6 arg1,arg2 + .byte $6f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs6 arg1,arg2 + .byte $ef ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbr7 arg1,arg2 + .byte $7f ;;,arg1 + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro +.macro _bbs7 arg1,arg2 + .byte $ff + .byte arg1 + .byte <((arg2)-(*+1)) +.endmacro + + diff --git a/libsrc/pcengine/joytokbd.s b/libsrc/pcengine/joytokbd.s new file mode 100644 index 000000000..1e8258e08 --- /dev/null +++ b/libsrc/pcengine/joytokbd.s @@ -0,0 +1,275 @@ +; +; File generated by cc65 v 2.9.5 +; + .fopt compiler,"cc65 v 2.9.5" + .autoimport on + .case on + .debuginfo off + .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 + .macpack longbranch + .import _joy_masks + .import _joy_read + .import _clock + .export _kbhit + .export _cgetc + +.segment "DATA" + +__lastkey: + .byte $00 +__chardelay: + .dword $00000000 +_rptkey: + .byte $00 + +; --------------------------------------------------------------- +; void _getkey (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc __getkey + +.segment "CODE" + + jsr decsp2 + ldx #$00 + lda __lastkey + cmp #$00 + jsr booleq + jeq L003F + lda #$00 + jsr _joy_read + ldy #$01 + sta (sp),y + ldx #$00 + lda #$00 + ldy #$00 + sta (sp),y + ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+4 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0010 + ldx #$00 + lda #$0A + ldy #$00 + sta (sp),y + jmp L003A +L0010: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0016 + ldx #$00 + lda #$01 + ldy #$00 + sta (sp),y + jmp L003A +L0016: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+2 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L001C + ldx #$00 + lda #$03 + ldy #$00 + sta (sp),y + jmp L003A +L001C: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+3 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0022 + ldx #$00 + lda #$04 + ldy #$00 + sta (sp),y + jmp L003A +L0022: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+1 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0028 + ldx #$00 + lda #$02 + ldy #$00 + sta (sp),y + jmp L003A +L0028: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+7 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L002E + ldx #$00 + lda #$14 + ldy #$00 + sta (sp),y + jmp L003A +L002E: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+5 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L0034 + ldx #$00 + lda #$15 + ldy #$00 + sta (sp),y + jmp L003A +L0034: ldy #$01 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _joy_masks+6 + jsr tosandax + stx tmp1 + ora tmp1 + jeq L003A + ldx #$00 + lda #$16 + ldy #$00 + sta (sp),y +L003A: ldy #$00 + ldx #$00 + lda (sp),y + cmp #$00 + jsr boolne + jeq L003F + ldy #$00 + ldx #$00 + lda (sp),y + jsr pushax + ldx #$00 + lda _rptkey + jsr toseqax + jeq L0043 + lda __chardelay+3 + sta sreg+1 + lda __chardelay+2 + sta sreg + ldx __chardelay+1 + lda __chardelay + jsr pusheax + jsr _clock + jsr tosugteax + jeq L0043 + jmp L003F +L0043: ldy #$00 + ldx #$00 + lda (sp),y + sta _rptkey + jsr _clock + ldy #$06 + jsr inceaxy + sta __chardelay + stx __chardelay+1 + ldy sreg + sty __chardelay+2 + ldy sreg+1 + sty __chardelay+3 + ldy #$00 + ldx #$00 + lda (sp),y + sta __lastkey +L003F: jsr incsp2 + rts + +.endproc + +; --------------------------------------------------------------- +; unsigned char __fastcall__ kbhit (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _kbhit + +.segment "CODE" + + jsr __getkey + ldx #$00 + lda __lastkey + cmp #$00 + jsr booleq + jeq L004E + ldx #$00 + lda #$00 + jmp L0052 + jmp L0052 +L004E: ldx #$00 + lda #$01 + jmp L0052 +L0052: rts + +.endproc + +; --------------------------------------------------------------- +; unsigned char __fastcall__ cgetc (void) +; --------------------------------------------------------------- + +.segment "CODE" + +.proc _cgetc + +.segment "CODE" + + jsr decsp1 +L0056: ldx #$00 + lda __lastkey + cmp #$00 + jsr booleq + jeq L0057 + jsr __getkey + jmp L0056 +L0057: ldx #$00 + lda __lastkey + ldy #$00 + sta (sp),y + ldx #$00 + lda #$00 + sta __lastkey + ldy #$00 + ldx #$00 + lda (sp),y + jmp L0055 +L0055: jsr incsp1 + rts + +.endproc + diff --git a/libsrc/pcengine/kplot.s b/libsrc/pcengine/kplot.s new file mode 100644 index 000000000..f050d78ef --- /dev/null +++ b/libsrc/pcengine/kplot.s @@ -0,0 +1,41 @@ + + .export PLOT + + .include "pcengine.inc" + +PLOT: + + bcs @getpos + + tya + clc + adc _plotlo,x + sta SCREEN_PTR + + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 + + ;clc + ;adc _colplot,x + ;sta CRAM_PTR + + ;lda #$23 + ;sta CRAM_PTR+1 + +@getpos: + ldx CURS_Y + ldy CURS_X + rts + +_plotlo: + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat + +_plothi: + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat + + diff --git a/libsrc/pcengine/pce-stdjoy.s b/libsrc/pcengine/pce-stdjoy.s new file mode 100644 index 000000000..60c77db1e --- /dev/null +++ b/libsrc/pcengine/pce-stdjoy.s @@ -0,0 +1,191 @@ + +; +; Standard joystick driver for the PCEngine +; +; Ullrich von Bassewitz, 2002-12-20 +; + + ;;.include "zeropage.inc" + + ;;.include "joy-kernel.inc" + + ;;.include "joy-error.inc" + JOY_ERR_OK=0; + .include "pcengine.inc" + + .macpack generic + +; ------------------------------------------------------------------------ +; Header. Includes jump table + +.segment "CODE" + +; Driver signature + +;; .byte $6A, $6F, $79 ; "joy" +;; .byte $00 ; Driver API version number + +; Button state masks (8 values) + +;extern const unsigned char joy_masks[8]; + + .export _joy_masks + +_joy_masks: + .byte $10 ; JOY_UP + .byte $40 ; JOY_DOWN + .byte $80 ; JOY_LEFT + .byte $20 ; JOY_RIGHT + .byte $04 ; ? JOY_FIRE + .byte $02 ; ? Future expansion + .byte $01 ; ? Future expansion + .byte $08 ; ? Future expansion + +; Jump table. + +;; .word INSTALL +;; .word DEINSTALL +;; .word COUNT +;; .word READ + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 4 ; Number of joysticks we support + + +; ------------------------------------------------------------------------ +; Data. + + +.code + + +;extern const char joy_stddrv[]; + + .export _joy_stddrv +_joy_stddrv: + .byte 0 + + + .export _joy_load_driver + .export _joy_unload + +;unsigned char __fastcall__ joy_unload (void); +;unsigned char __fastcall__ joy_load_driver (const char* driver); +_joy_load_driver: +_joy_unload: + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #<JOY_ERR_OK + ldx #>JOY_ERR_OK + +; rts ; Run into DEINSTALL instead + +; ------------------------------------------------------------------------ +; DEINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +DEINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; +;unsigned char __fastcall__ joy_count (void); + + .export _joy_count + +_joy_count: +COUNT: + lda #<JOY_COUNT + ldx #>JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; +;unsigned char __fastcall__ joy_read (unsigned char joystick); + + .export _joy_read + +_joy_read: +READ: + pha + jsr read_joy + pla + tax ; Joystick number into X + + ; return value from buffer + +joy1: + lda padbuffer,x + ldx #0 + rts + +.code + +read_joy: + ; reset multitap counter + lda #$01 + sta $1000 + pha + pla + nop + nop + + lda #$03 + sta $1000 + pha + pla + nop + nop + + cly +nextpad: + lda #$01 + sta $1000 ; sel = 1 + pha + pla + nop + nop + + lda $1000 + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value + + stz $1000 + pha + pla + nop + nop + + lda $1000 + and #$0F + ora padbuffer, y ; second half of new value + + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts + +.bss + +padbuffer: + .res 4 + diff --git a/libsrc/pcengine/pcengine.h b/libsrc/pcengine/pcengine.h new file mode 100644 index 000000000..8135679a2 --- /dev/null +++ b/libsrc/pcengine/pcengine.h @@ -0,0 +1,74 @@ +#define CH_CROSS 0x10 + +#define CH_RTEE 0x17 +#define CH_LTEE 0x0f + +#define CH_ULCORNER 0x10 +#define CH_URCORNER 0x10 +#define CH_LLCORNER 0x10 +#define CH_LRCORNER 0x10 + + +#define TV_NTSC 0 +#define TV_PAL 1 +#define get_tv() 0 + +#define CLOCKS_PER_SEC 50 // ??? +#define CLK_TCK 50 // ?!? + +//#ifndef CH_ENTER +#define CH_ENTER '\n' +//#endif + +#define CH_STOP 0x08 + +#define CH_F1 0x14 +#define CH_F3 0x15 +#define CH_F5 0x16 +#define CH_F7 0x17 + +#define CH_CURS_UP 0x01 +#define CH_CURS_DOWN 0x02 + +#ifndef CH_CURS_LEFT +#define CH_CURS_LEFT 0x03 +#endif + +#ifndef CH_CURS_RIGHT +#define CH_CURS_RIGHT 0x04 +#endif + +#define CH_ESC 8 + +#define CH_DEL 20 + +/* Color defines */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_VIOLET 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +#define JOY_FIRE_B 5 +#define JOY_START 6 +#define JOY_SELECT 7 + +/* +void __fastcall__ waitvblank(void); + +unsigned char __fastcall__ cpeekcharxy(unsigned char x,unsigned char y); +unsigned char __fastcall__ cpeekchar(void); +unsigned char __fastcall__ cpeekcolxy(unsigned char x,unsigned char y); +unsigned char __fastcall__ cpeekcol(void); +*/ diff --git a/libsrc/pcengine/pcengine.inc b/libsrc/pcengine/pcengine.inc new file mode 100644 index 000000000..ec61d9153 --- /dev/null +++ b/libsrc/pcengine/pcengine.inc @@ -0,0 +1,75 @@ + + .include "huc6280.inc" + +; Write VDC register + .macro VREG arg1,arg2 + st0 #arg1 + st1 #<(arg2) + st2 #>(arg2) + .endmacro + +_tickcount= $20 + +screenrows = (224/8) +charsperline = (512/8) +xsize = charsperline + +CH_HLINE = 7 +CH_VLINE = 7 + +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 +CRAM_PTR = $34 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR=$38 + +; huc6270 - Video Display Controller (vdc) + +VDC_MAWR = 0 ; Memory Address Write Register +VDC_MARR = 1 ; Memory Address Read Register +VDC_VWR = 2 ; VRAM Write Register +VDC_VRR = 3 ; VRAM Read Register +VDC_CR = 4 ; Control Register +VDC_RCR = 5 ; Raster Counter Register +VDC_BXR = 6 ; Background X-Scroll Register +VDC_BYR = 7 ; Background Y-Scroll Register +VDC_MWR = 8 ; Memory-access Width Register +VDC_HSR = 9 ; Horizontal Sync Register (?) +VDC_HDR =10 ; Horizontal Display Register (?) +VDC_VPR =11 ; (unknown) +VDC_VDW =12 ; (unknown use) +VDC_VCR =13 ; (unknown use) +VDC_DCR =14 ; (DMA) Control Register +VDC_SOUR =15 ; (DMA) Source Register +VDC_DESR =16 ; (DMA) Destination Register +VDC_LENR =17 ; (DMA) Length Register +VDC_SATB =18 ; Sprite Attribute Table + +VDC_CTRL = $0000 +VDC_DATA_LO = $0002 +VDC_DATA_HI = $0003 + +; huc6260 - Video Color Encoder (vce) + +; The DAC has a palette of 512 colours. +; bitmap of the palette data is this: 0000000gggrrrbbb. +; You can read and write the DAC-registers. + +VCE_CTRL = $0400 ; write$00 to reset +VCE_ADDR_LO = $0402 ; LSB of byte offset into palette +VCE_ADDR_HI = $0403 ; MSB of byte offset into palette +VCE_DATA_LO = $0404 ; LSB of 16-bit palette data +VCE_DATA_HI = $0405 ; MSB of 16-bit palette data + +TIMER_COUNT = $0c00 +TIMER_CTRL = $0c01 + +JOY_CTRL = $1000 + +IRQ_MASK = $1402 +IRQ_STATUS = $1403 + +CDR_MEM_DISABLE = $1803 +CDR_MEM_ENABLE = $1807 \ No newline at end of file diff --git a/libsrc/pcengine/pcengine.x b/libsrc/pcengine/pcengine.x new file mode 100644 index 000000000..276f3b3b6 --- /dev/null +++ b/libsrc/pcengine/pcengine.x @@ -0,0 +1,68 @@ +MEMORY { + + ZP: start = $00, size = $1A, type = rw, define = yes; + + # INES Cartridge Header + #HEADER: start = $0, size = $10, file = %O ,fill = yes; + + # 2 16K ROM Banks + # - startup + # - code + # - rodata + # - data (load) + # 1 8k CHR Bank + ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; + # Hardware Vectors at End of 2nd 8K ROM + ROMV: start = $fff6, size = $a, file = %O,fill = yes; + + ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; + + + # standard 2k SRAM (-zeropage) + # $0100-$0200 cpu stack + # $0200-$0500 3 pages for ppu memory write buffer + # $0500-$0800 3 pages for cc65 parameter stack + #SRAM: start = $0500, size = $0300, define = yes; + + # additional 8K SRAM Bank + # - data (run) + # - bss + # - heap +# RAM: start = $2200, size = $1000, define = yes; +# RAM2: start = $3200, size = $0e00, define = yes; + RAM: start = $2200, size = $1e00, define = yes; + +} +SEGMENTS { + #HEADER: load = HEADER, type = wprot; + + #aSTARTUP: load = ROM0, type = wprot, define = yes; + STARTUP: load = ROM0, type = wprot, define = yes; + + CODE: load = ROM, type = wprot, define = yes; + RODATA: load = ROM, type = wprot, define = yes; + + DATA: load = ROM0, run= RAM, type = rw, define = yes; +# BSS: load = RAM2, type = bss, define = yes; + BSS: load = RAM, type = bss, define = yes; + + VECTORS: load = ROMV, type = rw, define = yes; + #CHARS: load = ROM2, type = rw; + + + ZEROPAGE: load = ZP, type = zp, define = yes; + +} +FEATURES { + CONDES: segment = STARTUP, + type=constructor, + label=__CONSTRUCTOR_TABLE__, + count=__CONSTRUCTOR_COUNT__; + CONDES: segment = STARTUP, + type=destructor, + label=__DESTRUCTOR_TABLE__, + count=__DESTRUCTOR_COUNT__; +} +SYMBOLS { + __STACKSIZE__ = $0300; # 3 pages stack +} diff --git a/libsrc/pcengine/psg.s b/libsrc/pcengine/psg.s new file mode 100644 index 000000000..ebf35d952 --- /dev/null +++ b/libsrc/pcengine/psg.s @@ -0,0 +1,29 @@ + + .include "pcengine.inc" + + .export psg_init + +psg_init: + clx + stx $0800 ; Select channel +psg_clear_loop: + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control + + cly +psg_clear_waveform: stz $0806 ; Clear waveform byte + iny + cpy #$20 + bne psg_clear_waveform + + inx + cpx #$06 + bne psg_clear_loop + rts + diff --git a/libsrc/pcengine/revers.s b/libsrc/pcengine/revers.s new file mode 100644 index 000000000..d1358a52b --- /dev/null +++ b/libsrc/pcengine/revers.s @@ -0,0 +1,5 @@ + + .export _revers +_revers: + lda #0 + rts diff --git a/libsrc/pcengine/vce.s b/libsrc/pcengine/vce.s new file mode 100644 index 000000000..a5c919970 --- /dev/null +++ b/libsrc/pcengine/vce.s @@ -0,0 +1,16 @@ + + .include "pcengine.inc" + .export vce_init + +vce_init: + stz VCE_ADDR_LO ; + stz VCE_ADDR_HI ; Set CTA to zero + ldy #$01 +vce_clear_bank: ldx #$00 +vce_clear_color: stz VCE_DATA_LO ; Clear color (LSB) + stz VCE_DATA_HI ; Clear color (MSB) + dex + bne vce_clear_color + dey + bne vce_clear_bank + rts diff --git a/libsrc/pcengine/vdc.s b/libsrc/pcengine/vdc.s new file mode 100644 index 000000000..a203cb058 --- /dev/null +++ b/libsrc/pcengine/vdc.s @@ -0,0 +1,46 @@ + + .include "pcengine.inc" + +HIRES = 1 + + .export vdc_init + +vdc_init: + ;;lda $0000 + ;;.byte $ad,0,0 + + ldaio VDC_CTRL + + VREG $00, $0000 ; MAWR + VREG $01, $0000 ; MARR + VREG $05, $0000 ; CR + VREG $06, $0000 ; RCR + VREG $07, $0000 ; BXR + VREG $08, $0000 ; BYR + VREG $09, $0070 ; MAWR + VREG $0C, $1702 ; CRTC - VSR + VREG $0D, $00DF ; CRTC - VDS + VREG $0E, $000C ; CRTC - VDE + VREG $0F, $0000 ; DCR + + .if HIRES + + VREG $0A, $0C02 ; CRTC - HSR + VREG $0B, $043C ; CRTC - HDS + lda #$06 + sta VCE_CTRL + + .else + + VREG $0A, $0202 ; CRTC - HSR + VREG $0B, $041F ; CRTC - HDS + lda #$04 + sta VCE_CTRL + + .endif + + ;;lda $0000 + ;;.byte $ad,0,0 + + ldaio VDC_CTRL + rts diff --git a/libsrc/pcengine/vga.inc b/libsrc/pcengine/vga.inc new file mode 100644 index 000000000..6cbdd010c --- /dev/null +++ b/libsrc/pcengine/vga.inc @@ -0,0 +1,129 @@ + + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte $7E, $81, $A5, $81, $BD, $99, $81, $7E + .byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E + .byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 + .byte $10, $38, $7C, $FE, $7C, $38, $10, $00 + .byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C + .byte $10, $10, $38, $7C, $FE, $7C, $38, $7C + .byte $00, $00, $18, $3C, $3C, $18, $00, $00 + .byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF + .byte $00, $3C, $66, $42, $42, $66, $3C, $00 + .byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF + .byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 + .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 + .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 + .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 + .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 + .byte $80, $E0, $F8, $FE, $F8, $E0, $80, $00 + .byte $02, $0E, $3E, $FE, $3E, $0E, $02, $00 + .byte $18, $3C, $7E, $18, $18, $7E, $3C, $18 + .byte $66, $66, $66, $66, $66, $00, $66, $00 + .byte $7F, $DB, $DB, $7B, $1B, $1B, $1B, $00 + .byte $3E, $63, $38, $6C, $6C, $38, $CC, $78 + .byte $00, $00, $00, $00, $7E, $7E, $7E, $00 + .byte $18, $3C, $7E, $18, $7E, $3C, $18, $FF + .byte $18, $3C, $7E, $18, $18, $18, $18, $00 + .byte $18, $18, $18, $18, $7E, $3C, $18, $00 + .byte $00, $18, $0C, $FE, $0C, $18, $00, $00 + .byte $00, $30, $60, $FE, $60, $30, $00, $00 + .byte $00, $00, $C0, $C0, $C0, $FE, $00, $00 + .byte $00, $24, $66, $FF, $66, $24, $00, $00 + .byte $00, $18, $3C, $7E, $FF, $FF, $00, $00 + .byte $00, $FF, $FF, $7E, $3C, $18, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte $30, $78, $78, $78, $30, $00, $30, $00 + .byte $6C, $6C, $6C, $00, $00, $00, $00, $00 + .byte $6C, $6C, $FE, $6C, $FE, $6C, $6C, $00 + .byte $30, $7C, $C0, $78, $0C, $F8, $30, $00 + .byte $00, $C6, $CC, $18, $30, $66, $C6, $00 + .byte $38, $6C, $38, $76, $DC, $CC, $76, $00 + .byte $60, $60, $C0, $00, $00, $00, $00, $00 + .byte $18, $30, $60, $60, $60, $30, $18, $00 + .byte $60, $30, $18, $18, $18, $30, $60, $00 + .byte $00, $66, $3C, $FF, $3C, $66, $00, $00 + .byte $00, $30, $30, $FC, $30, $30, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $60 + .byte $00, $00, $00, $FC, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $00 + .byte $06, $0C, $18, $30, $60, $C0, $80, $00 + .byte $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 + .byte $30, $70, $30, $30, $30, $30, $FC, $00 + .byte $78, $CC, $0C, $38, $60, $CC, $FC, $00 + .byte $78, $CC, $0C, $38, $0C, $CC, $78, $00 + .byte $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 + .byte $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 + .byte $38, $60, $C0, $F8, $CC, $CC, $78, $00 + .byte $FC, $CC, $0C, $18, $30, $30, $30, $00 + .byte $78, $CC, $CC, $78, $CC, $CC, $78, $00 + .byte $78, $CC, $CC, $7C, $0C, $18, $70, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $60 + .byte $18, $30, $60, $C0, $60, $30, $18, $00 + .byte $00, $00, $FC, $00, $00, $FC, $00, $00 + .byte $60, $30, $18, $0C, $18, $30, $60, $00 + .byte $78, $CC, $0C, $18, $30, $00, $30, $00 + .byte $7C, $C6, $DE, $DE, $DE, $C0, $78, $00 + .byte $30, $78, $CC, $CC, $FC, $CC, $CC, $00 + .byte $FC, $66, $66, $7C, $66, $66, $FC, $00 + .byte $3C, $66, $C0, $C0, $C0, $66, $3C, $00 + .byte $F8, $6C, $66, $66, $66, $6C, $F8, $00 + .byte $7E, $60, $60, $78, $60, $60, $7E, $00 + .byte $7E, $60, $60, $78, $60, $60, $60, $00 + .byte $3C, $66, $C0, $C0, $CE, $66, $3E, $00 + .byte $CC, $CC, $CC, $FC, $CC, $CC, $CC, $00 + .byte $78, $30, $30, $30, $30, $30, $78, $00 + .byte $1E, $0C, $0C, $0C, $CC, $CC, $78, $00 + .byte $E6, $66, $6C, $78, $6C, $66, $E6, $00 + .byte $60, $60, $60, $60, $60, $60, $7E, $00 + .byte $C6, $EE, $FE, $FE, $D6, $C6, $C6, $00 + .byte $C6, $E6, $F6, $DE, $CE, $C6, $C6, $00 + .byte $38, $6C, $C6, $C6, $C6, $6C, $38, $00 + .byte $FC, $66, $66, $7C, $60, $60, $F0, $00 + .byte $78, $CC, $CC, $CC, $DC, $78, $1C, $00 + .byte $FC, $66, $66, $7C, $6C, $66, $E6, $00 + .byte $78, $CC, $E0, $70, $1C, $CC, $78, $00 + .byte $FC, $30, $30, $30, $30, $30, $30, $00 + .byte $CC, $CC, $CC, $CC, $CC, $CC, $FC, $00 + .byte $CC, $CC, $CC, $CC, $CC, $78, $30, $00 + .byte $C6, $C6, $C6, $D6, $FE, $EE, $C6, $00 + .byte $C6, $C6, $6C, $38, $38, $6C, $C6, $00 + .byte $CC, $CC, $CC, $78, $30, $30, $78, $00 + .byte $FE, $06, $0C, $18, $30, $60, $FE, $00 + .byte $78, $60, $60, $60, $60, $60, $78, $00 + .byte $C0, $60, $30, $18, $0C, $06, $02, $00 + .byte $78, $18, $18, $18, $18, $18, $78, $00 + .byte $10, $38, $6C, $C6, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $FF + .byte $30, $30, $18, $00, $00, $00, $00, $00 + .byte $00, $00, $78, $0C, $7C, $CC, $76, $00 + .byte $E0, $60, $60, $7C, $66, $66, $DC, $00 + .byte $00, $00, $78, $CC, $C0, $CC, $78, $00 + .byte $1C, $0C, $0C, $7C, $CC, $CC, $76, $00 + .byte $00, $00, $78, $CC, $FC, $C0, $78, $00 + .byte $38, $6C, $60, $F0, $60, $60, $F0, $00 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $F8 + .byte $E0, $60, $6C, $76, $66, $66, $E6, $00 + .byte $30, $00, $70, $30, $30, $30, $78, $00 + .byte $0C, $00, $0C, $0C, $0C, $CC, $CC, $78 + .byte $E0, $60, $66, $6C, $78, $6C, $E6, $00 + .byte $70, $30, $30, $30, $30, $30, $78, $00 + .byte $00, $00, $CC, $FE, $FE, $D6, $C6, $00 + .byte $00, $00, $F8, $CC, $CC, $CC, $CC, $00 + .byte $00, $00, $78, $CC, $CC, $CC, $78, $00 + .byte $00, $00, $DC, $66, $66, $7C, $60, $F0 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $1E + .byte $00, $00, $DC, $76, $66, $60, $F0, $00 + .byte $00, $00, $7C, $C0, $78, $0C, $F8, $00 + .byte $10, $30, $7C, $30, $30, $34, $18, $00 + .byte $00, $00, $CC, $CC, $CC, $CC, $76, $00 + .byte $00, $00, $CC, $CC, $CC, $78, $30, $00 + .byte $00, $00, $C6, $D6, $FE, $FE, $6C, $00 + .byte $00, $00, $C6, $6C, $38, $6C, $C6, $00 + .byte $00, $00, $CC, $CC, $CC, $7C, $0C, $F8 + .byte $00, $00, $FC, $98, $30, $64, $FC, $00 + .byte $1C, $30, $30, $E0, $30, $30, $1C, $00 + .byte $18, $18, $18, $00, $18, $18, $18, $00 + .byte $E0, $30, $30, $1C, $30, $30, $E0, $00 + .byte $76, $DC, $00, $00, $00, $00, $00, $00 + .byte $00, $10, $38, $6C, $C6, $C6, $FE, $00 From 86e6abfcd946ec5bf19879f3d8a48e2a4807e506 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 29 Nov 2014 15:13:40 +0100 Subject: [PATCH 028/351] added compiler/assembler target, lib compiles --- libsrc/{pcengine => pce}/_heap.s | 0 libsrc/{pcengine => pce}/_scrsize.s | 0 libsrc/{pcengine => pce}/call.s | 0 libsrc/{pcengine => pce}/clock.s | 0 libsrc/{pcengine => pce}/clrscr.s | 0 libsrc/{pcengine => pce}/color.s | 0 libsrc/{pcengine => pce}/condes.s | 0 libsrc/{pcengine => pce}/conio.s | 0 libsrc/{pcengine => pce}/cputc.s | 0 libsrc/{pcengine => pce}/crt0.s | 0 libsrc/{pcengine => pce}/huc6280.inc | 0 libsrc/{pcengine => pce}/joytokbd.s | 0 libsrc/{pcengine => pce}/kplot.s | 0 libsrc/{pcengine => pce}/pce-stdjoy.s | 0 libsrc/{pcengine => pce}/pcengine.h | 0 libsrc/{pcengine => pce}/pcengine.inc | 0 libsrc/{pcengine => pce}/pcengine.x | 0 libsrc/{pcengine => pce}/psg.s | 0 libsrc/{pcengine => pce}/revers.s | 0 libsrc/{pcengine => pce}/vce.s | 0 libsrc/{pcengine => pce}/vdc.s | 0 libsrc/{pcengine => pce}/vga.inc | 0 22 files changed, 0 insertions(+), 0 deletions(-) rename libsrc/{pcengine => pce}/_heap.s (100%) rename libsrc/{pcengine => pce}/_scrsize.s (100%) rename libsrc/{pcengine => pce}/call.s (100%) rename libsrc/{pcengine => pce}/clock.s (100%) rename libsrc/{pcengine => pce}/clrscr.s (100%) rename libsrc/{pcengine => pce}/color.s (100%) rename libsrc/{pcengine => pce}/condes.s (100%) rename libsrc/{pcengine => pce}/conio.s (100%) rename libsrc/{pcengine => pce}/cputc.s (100%) rename libsrc/{pcengine => pce}/crt0.s (100%) rename libsrc/{pcengine => pce}/huc6280.inc (100%) rename libsrc/{pcengine => pce}/joytokbd.s (100%) rename libsrc/{pcengine => pce}/kplot.s (100%) rename libsrc/{pcengine => pce}/pce-stdjoy.s (100%) rename libsrc/{pcengine => pce}/pcengine.h (100%) rename libsrc/{pcengine => pce}/pcengine.inc (100%) rename libsrc/{pcengine => pce}/pcengine.x (100%) rename libsrc/{pcengine => pce}/psg.s (100%) rename libsrc/{pcengine => pce}/revers.s (100%) rename libsrc/{pcengine => pce}/vce.s (100%) rename libsrc/{pcengine => pce}/vdc.s (100%) rename libsrc/{pcengine => pce}/vga.inc (100%) diff --git a/libsrc/pcengine/_heap.s b/libsrc/pce/_heap.s similarity index 100% rename from libsrc/pcengine/_heap.s rename to libsrc/pce/_heap.s diff --git a/libsrc/pcengine/_scrsize.s b/libsrc/pce/_scrsize.s similarity index 100% rename from libsrc/pcengine/_scrsize.s rename to libsrc/pce/_scrsize.s diff --git a/libsrc/pcengine/call.s b/libsrc/pce/call.s similarity index 100% rename from libsrc/pcengine/call.s rename to libsrc/pce/call.s diff --git a/libsrc/pcengine/clock.s b/libsrc/pce/clock.s similarity index 100% rename from libsrc/pcengine/clock.s rename to libsrc/pce/clock.s diff --git a/libsrc/pcengine/clrscr.s b/libsrc/pce/clrscr.s similarity index 100% rename from libsrc/pcengine/clrscr.s rename to libsrc/pce/clrscr.s diff --git a/libsrc/pcengine/color.s b/libsrc/pce/color.s similarity index 100% rename from libsrc/pcengine/color.s rename to libsrc/pce/color.s diff --git a/libsrc/pcengine/condes.s b/libsrc/pce/condes.s similarity index 100% rename from libsrc/pcengine/condes.s rename to libsrc/pce/condes.s diff --git a/libsrc/pcengine/conio.s b/libsrc/pce/conio.s similarity index 100% rename from libsrc/pcengine/conio.s rename to libsrc/pce/conio.s diff --git a/libsrc/pcengine/cputc.s b/libsrc/pce/cputc.s similarity index 100% rename from libsrc/pcengine/cputc.s rename to libsrc/pce/cputc.s diff --git a/libsrc/pcengine/crt0.s b/libsrc/pce/crt0.s similarity index 100% rename from libsrc/pcengine/crt0.s rename to libsrc/pce/crt0.s diff --git a/libsrc/pcengine/huc6280.inc b/libsrc/pce/huc6280.inc similarity index 100% rename from libsrc/pcengine/huc6280.inc rename to libsrc/pce/huc6280.inc diff --git a/libsrc/pcengine/joytokbd.s b/libsrc/pce/joytokbd.s similarity index 100% rename from libsrc/pcengine/joytokbd.s rename to libsrc/pce/joytokbd.s diff --git a/libsrc/pcengine/kplot.s b/libsrc/pce/kplot.s similarity index 100% rename from libsrc/pcengine/kplot.s rename to libsrc/pce/kplot.s diff --git a/libsrc/pcengine/pce-stdjoy.s b/libsrc/pce/pce-stdjoy.s similarity index 100% rename from libsrc/pcengine/pce-stdjoy.s rename to libsrc/pce/pce-stdjoy.s diff --git a/libsrc/pcengine/pcengine.h b/libsrc/pce/pcengine.h similarity index 100% rename from libsrc/pcengine/pcengine.h rename to libsrc/pce/pcengine.h diff --git a/libsrc/pcengine/pcengine.inc b/libsrc/pce/pcengine.inc similarity index 100% rename from libsrc/pcengine/pcengine.inc rename to libsrc/pce/pcengine.inc diff --git a/libsrc/pcengine/pcengine.x b/libsrc/pce/pcengine.x similarity index 100% rename from libsrc/pcengine/pcengine.x rename to libsrc/pce/pcengine.x diff --git a/libsrc/pcengine/psg.s b/libsrc/pce/psg.s similarity index 100% rename from libsrc/pcengine/psg.s rename to libsrc/pce/psg.s diff --git a/libsrc/pcengine/revers.s b/libsrc/pce/revers.s similarity index 100% rename from libsrc/pcengine/revers.s rename to libsrc/pce/revers.s diff --git a/libsrc/pcengine/vce.s b/libsrc/pce/vce.s similarity index 100% rename from libsrc/pcengine/vce.s rename to libsrc/pce/vce.s diff --git a/libsrc/pcengine/vdc.s b/libsrc/pce/vdc.s similarity index 100% rename from libsrc/pcengine/vdc.s rename to libsrc/pce/vdc.s diff --git a/libsrc/pcengine/vga.inc b/libsrc/pce/vga.inc similarity index 100% rename from libsrc/pcengine/vga.inc rename to libsrc/pce/vga.inc From 4275b82117599db211e813c1adef7c941bceed20 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 29 Nov 2014 15:35:20 +0100 Subject: [PATCH 029/351] added compiler/assembler target, lib compiles --- libsrc/pce/pcengine.x => cfg/pce.cfg | 0 libsrc/Makefile | 2 +- libsrc/joystick/joy-kernel.s | 2 +- libsrc/pce/_heap.s | 67 -------- libsrc/pce/clrscr.s | 36 ++-- libsrc/pce/conio.s | 24 +-- libsrc/pce/huc6280.inc | 238 --------------------------- libsrc/pce/pcengine.inc | 21 ++- src/ca65/main.c | 4 + src/cc65/main.c | 4 + src/common/target.c | 2 + src/common/target.h | 1 + 12 files changed, 60 insertions(+), 341 deletions(-) rename libsrc/pce/pcengine.x => cfg/pce.cfg (100%) delete mode 100644 libsrc/pce/_heap.s delete mode 100644 libsrc/pce/huc6280.inc diff --git a/libsrc/pce/pcengine.x b/cfg/pce.cfg similarity index 100% rename from libsrc/pce/pcengine.x rename to cfg/pce.cfg diff --git a/libsrc/Makefile b/libsrc/Makefile index 051e5cf3a..dc944ee05 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -24,7 +24,7 @@ TARGETS = apple2 \ $(GEOS) \ lynx \ nes \ - pcengine \ + pce \ sim6502 \ sim65c02 \ supervision diff --git a/libsrc/joystick/joy-kernel.s b/libsrc/joystick/joy-kernel.s index 1ba3056d8..2b1dcf884 100644 --- a/libsrc/joystick/joy-kernel.s +++ b/libsrc/joystick/joy-kernel.s @@ -109,7 +109,7 @@ inv_drv: copy: lda (ptr1),y iny -set: sta joy_vectors,x + sta joy_vectors,x inx rts diff --git a/libsrc/pce/_heap.s b/libsrc/pce/_heap.s deleted file mode 100644 index 71fa13e78..000000000 --- a/libsrc/pce/_heap.s +++ /dev/null @@ -1,67 +0,0 @@ -; -; Ullrich von Bassewitz, 03.06.1998 -; -; Heap variables and initialization. -; - -; FIXME: there should be a way to configure heap from linkerscript! - - .constructor initheap, 24 - - .import __RAM_START__, __RAM_SIZE__, __STACKSIZE__ ; Linker generated - .import __BSS_SIZE__ - .importzp sp - -.data - -;; old - remove - .export __horg, __hptr, __hend, __hfirst, __hlast -__horg: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol -__hptr: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Dito -__hend: - .word __RAM_START__+__RAM_SIZE__ -__hfirst: - .word 0 -__hlast: - .word 0 - - .export __heaporg - .export __heapptr - .export __heapend - .export __heapfirst - .export __heaplast - -__heaporg: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol -__heapptr: - .word __RAM_START__+__BSS_SIZE__+__DATA_SIZE__ ; Linker calculates this symbol -__heapend: - .word __RAM_START__+__RAM_SIZE__ -__heapfirst: - .word 0 -__heaplast: - .word 0 - - -; Initialization. Will be called from startup! - -.code - -initheap: - ;sec - ;lda sp -; lda #<(__STACKSIZE__) -; lda #<(__RAM_START__+__RAM_SIZE__) - lda #<(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) - sta __heapend - sta __hend ; old -; lda sp+1 -; lda #>(__STACKSIZE__) -; lda #>(__RAM_START__+__RAM_SIZE__) - lda #>(__RAM_START__+__BSS_SIZE__+__DATA_SIZE__) - sta __heapend+1 - sta __hend+1 ; old - rts - diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index c2c5dcbcb..0a2b8b62d 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,27 +1,25 @@ - .include "pcengine.inc" + .include "pcengine.inc" - - .export _clrscr + .export _clrscr _clrscr: - st0 #VDC_MAWR - st1 #<$0000 - st2 #>$0000 + st0 #VDC_MAWR + st1 #<$0000 + st2 #>$0000 - st0 #VDC_VWR - ldy #$40 -rowloop: ldx #$80 -colloop: - lda #' ' - staio VDC_DATA_LO - lda #$02 - staio VDC_DATA_HI + st0 #VDC_VWR + ldy #$40 +rowloop: ldx #$80 +colloop: lda #' ' + staio VDC_DATA_LO + lda #$02 + staio VDC_DATA_HI - dex - bne colloop - dey - bne rowloop + dex + bne colloop + dey + bne rowloop - rts + rts diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 3c4919e64..0a66cf454 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -69,27 +69,27 @@ _conio_init: ; ;---------------------------------------------------------------------------- - .importzp ptr1 + .importzp ptr1 conio_init: ; Load font - st0 #VDC_MAWR + st0 #VDC_MAWR st1 #<$2000 st2 #>$2000 ; ptr to font data - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 st0 #VDC_VWR ; VWR ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: ;;lda [$00] ; read font byte - ldaind ptr1 + lda (ptr1) staio VDC_DATA_LO ; bitplane 0 stzio VDC_DATA_HI ; bitplane 1 @@ -110,13 +110,13 @@ conio_init: dey bne charloop ; next character - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR rts - .rodata + .rodata font: .include "vga.inc" diff --git a/libsrc/pce/huc6280.inc b/libsrc/pce/huc6280.inc deleted file mode 100644 index ab634a855..000000000 --- a/libsrc/pce/huc6280.inc +++ /dev/null @@ -1,238 +0,0 @@ - -; -; HuC6280 additional opcodes (use with --cpu 65C02) -; -; WARNING: THIS IS __NOT__ COMPLETE !!! -; - -;; lda abs -.macro ldaio arg1 - .byte $ad - .word arg1 -.endmacro -;; sta abs -.macro staio arg1 - .byte $8d - .word arg1 -.endmacro -.macro stzio arg1 - .byte $9c - .word arg1 -.endmacro - -.macro cla - .byte $62 -.endmacro -.macro clx - .byte $82 -.endmacro - -;; lda (zp) -.macro ldaind arg1 - .byte $b2 - .byte arg1 -.endmacro - -.macro cly - .byte $c2 -.endmacro - -.macro st0 arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $03 - .byte (.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro -.macro st1 arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $13 - .byte (.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro -.macro st2 arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $23 - .byte (.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro - -; tam #$xx -.macro tam arg1 - .if (.match (.left (1, arg1), #)) - ; called with immidiate operand - .byte $53 - .byte 1<<(.right (.tcount (arg1)-1, arg1)) - .else - .error "illegal address mode" - .endif -.endmacro - -; tii x,y,z -.macro tii arg1,arg2,arg3 - .byte $73 - .word arg1,arg2,arg3 -.endmacro - -.macro csh - .byte $d4 -.endmacro -.macro set - .byte $f4 -.endmacro -.macro _rmb0 arg1 - .byte $07 - .byte arg1 -.endmacro -.macro _rmb1 arg1 - .byte $17 - .byte arg1 -.endmacro -.macro _rmb2 arg1 - .byte $27 - .byte arg1 -.endmacro -.macro _rmb3 arg1 - .byte $37 - .byte arg1 -.endmacro -.macro _rmb4 arg1 - .byte $47 - .byte arg1 -.endmacro -.macro _rmb5 arg1 - .byte $57 - .byte arg1 -.endmacro -.macro _rmb6 arg1 - .byte $67 - .byte arg1 -.endmacro -.macro _rmb7 arg1 - .byte $77 - .byte arg1 -.endmacro - -.macro _smb0 arg1 - .byte $87 - .byte arg1 -.endmacro -.macro _smb1 arg1 - .byte $97 - .byte arg1 -.endmacro -.macro _smb2 arg1 - .byte $a7 - .byte arg1 -.endmacro -.macro _smb3 arg1 - .byte $b7 - .byte arg1 -.endmacro -.macro _smb4 arg1 - .byte $c7 - .byte arg1 -.endmacro -.macro _smb5 arg1 - .byte $d7 - .byte arg1 -.endmacro -.macro _smb6 arg1 - .byte $e7 - .byte arg1 -.endmacro -.macro _smb7 arg1 - .byte $f7 - .byte arg1 -.endmacro - -.macro _bbr0 arg1,arg2 - .byte $0f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs0 arg1,arg2 - .byte $8f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr1 arg1,arg2 - .byte $1f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs1 arg1,arg2 - .byte $9f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr2 arg1,arg2 - .byte $2f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs2 arg1,arg2 - .byte $af ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr3 arg1,arg2 - .byte $3f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs3 arg1,arg2 - .byte $bf ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr4 arg1,arg2 - .byte $4f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs4 arg1,arg2 - .byte $cf ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr5 arg1,arg2 - .byte $5f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs5 arg1,arg2 - .byte $df ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr6 arg1,arg2 - .byte $6f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs6 arg1,arg2 - .byte $ef ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbr7 arg1,arg2 - .byte $7f ;;,arg1 - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro -.macro _bbs7 arg1,arg2 - .byte $ff - .byte arg1 - .byte <((arg2)-(*+1)) -.endmacro - - diff --git a/libsrc/pce/pcengine.inc b/libsrc/pce/pcengine.inc index ec61d9153..a0ef03f6a 100644 --- a/libsrc/pce/pcengine.inc +++ b/libsrc/pce/pcengine.inc @@ -1,6 +1,4 @@ - .include "huc6280.inc" - ; Write VDC register .macro VREG arg1,arg2 st0 #arg1 @@ -72,4 +70,21 @@ IRQ_MASK = $1402 IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 -CDR_MEM_ENABLE = $1807 \ No newline at end of file +CDR_MEM_ENABLE = $1807 + + +;; lda abs +.macro ldaio arg1 + .byte $ad + .word arg1 +.endmacro +;; sta abs +.macro staio arg1 + .byte $8d + .word arg1 +.endmacro +;; stz abs +.macro stzio arg1 + .byte $9c + .word arg1 +.endmacro diff --git a/src/ca65/main.c b/src/ca65/main.c index 3f31a2b88..4f39eb286 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -303,6 +303,10 @@ static void SetSys (const char* Sys) NewSymbol ("__SIM65C02__", 1); break; + case TGT_PCENGINE: + NewSymbol ("__PCE__", 1); + break; + default: AbEnd ("Invalid target name: `%s'", Sys); diff --git a/src/cc65/main.c b/src/cc65/main.c index 34688e97e..13fe76db4 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -258,6 +258,10 @@ static void SetSys (const char* Sys) DefineNumericMacro ("__SIM65C02__", 1); break; + case TGT_PCENGINE: + DefineNumericMacro ("__PCE__", 1); + break; + default: AbEnd ("Unknown target system type %d", Target); } diff --git a/src/common/target.c b/src/common/target.c index ffb342e25..013afe8ba 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -142,6 +142,7 @@ static const TargetEntry TargetMap[] = { { "module", TGT_MODULE }, { "nes", TGT_NES }, { "none", TGT_NONE }, + { "pce", TGT_PCENGINE }, { "pet", TGT_PET }, { "plus4", TGT_PLUS4 }, { "sim6502", TGT_SIM6502 }, @@ -180,6 +181,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "lynx", CPU_65C02, BINFMT_BINARY, CTNone }, { "sim6502", CPU_6502, BINFMT_BINARY, CTNone }, { "sim65c02", CPU_65C02, BINFMT_BINARY, CTNone }, + { "pce", CPU_HUC6280, BINFMT_BINARY, CTNone }, }; /* Target system */ diff --git a/src/common/target.h b/src/common/target.h index 72dffe382..ae9f931c4 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -77,6 +77,7 @@ typedef enum { TGT_LYNX, TGT_SIM6502, TGT_SIM65C02, + TGT_PCENGINE, TGT_COUNT /* Number of target systems */ } target_t; From 7dac57f60d46a06c8cb26f4e6fb625880ab44a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 29 Nov 2014 15:52:42 +0100 Subject: [PATCH 030/351] Added gotox() and gotoy() implementations. --- libsrc/c1p/gotox.s | 17 +++++++++++++++++ libsrc/c1p/gotoy.s | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 libsrc/c1p/gotox.s create mode 100644 libsrc/c1p/gotoy.s diff --git a/libsrc/c1p/gotox.s b/libsrc/c1p/gotox.s new file mode 100644 index 000000000..315e1b5ee --- /dev/null +++ b/libsrc/c1p/gotox.s @@ -0,0 +1,17 @@ +; +; copied from CBM implementation +; originally by: +; Ullrich von Bassewitz, 07.08.1998 +; +; void gotox (unsigned char x); +; + + .export _gotox + .import plot + .importzp CURS_X + +_gotox: sta CURS_X ; Set new position + jmp plot ; And activate it + + + diff --git a/libsrc/c1p/gotoy.s b/libsrc/c1p/gotoy.s new file mode 100644 index 000000000..e9e81451a --- /dev/null +++ b/libsrc/c1p/gotoy.s @@ -0,0 +1,15 @@ +; +; copied from CBM implementation +; originally by: +; Ullrich von Bassewitz, 0.08.1998 +; +; void gotoy (unsigned char y); +; + + .export _gotoy + .import plot + .importzp CURS_Y + +_gotoy: sta CURS_Y ; Set the new position + jmp plot ; And activate it + From ac88639f4a9bdcb40388d6afd04dae032f74b951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 29 Nov 2014 20:07:30 +0100 Subject: [PATCH 031/351] Implemented cursor functionality. --- cfg/c1p.cfg | 3 ++- libsrc/c1p/cgetc.s | 27 ++++++++++++++++++++++++--- libsrc/c1p/extzp.inc | 2 +- libsrc/c1p/extzp.s | 8 +++----- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index 46015017b..2f48dd084 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -14,7 +14,8 @@ SYMBOLS { __HIMEM__: type = weak, value = $2000; # Presumed RAM end } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A + $0005; + # for size of ZP see runtime/zeropage.s and c1p/extzp.s + ZP: file = "", define = yes, start = $0002, size = $001A + $0006; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { diff --git a/libsrc/c1p/cgetc.s b/libsrc/c1p/cgetc.s index a73866a56..b17e76572 100644 --- a/libsrc/c1p/cgetc.s +++ b/libsrc/c1p/cgetc.s @@ -2,7 +2,28 @@ ; char cgetc (void); ; .export _cgetc - .include "c1p.inc" + .import cursor -; Direct use of input routine from 65V PROM MONITOR -_cgetc = INPUTC + .include "c1p.inc" + .include "extzp.inc" + +; Input routine from 65V PROM MONITOR, show cursor if enabled +_cgetc: + lda cursor ; show cursor? + beq nocursor + ldy CURS_X + lda (SCREEN_PTR),y ; fetch current character + sta CURS_SAV ; save it + lda #$A1 ; full white square + sta (SCREEN_PTR),y ; store at cursor position +nocursor: + jsr INPUTC + pha ; save retrieved character + lda cursor ; was cursor on? + beq nocursor2 + lda CURS_SAV ; fetch saved character + ldy CURS_X + sta (SCREEN_PTR),y ; store at cursor position +nocursor2: + pla ; restore retrieved character + rts diff --git a/libsrc/c1p/extzp.inc b/libsrc/c1p/extzp.inc index 0f9632df2..c5bb2b585 100644 --- a/libsrc/c1p/extzp.inc +++ b/libsrc/c1p/extzp.inc @@ -4,4 +4,4 @@ ; ------------------------------------------------------------------------ - .globalzp CURS_X, CURS_Y, SCR_LINELEN, SCREEN_PTR + .globalzp CURS_X, CURS_Y, CURS_SAV, SCR_LINELEN, SCREEN_PTR diff --git a/libsrc/c1p/extzp.s b/libsrc/c1p/extzp.s index 139feffde..c55156f82 100644 --- a/libsrc/c1p/extzp.s +++ b/libsrc/c1p/extzp.s @@ -11,13 +11,11 @@ .segment "EXTZP" : zeropage -; The following values get initialized from a table in the startup code. -; While this sounds crazy, it has reasons that have to do with modules (and -; we have the space anyway). So when changing anything, be sure to adjust the -; initializer table CURS_X: .byte 0 CURS_Y: .byte 0 +CURS_SAV: .byte 0 SCR_LINELEN: .byte 24 SCREEN_PTR: .res 2 -; size 5 +; size 6 +; Adjust size of this segment in c1p.cfg if the size changes From 6dc8621fa537901bc9b19731ab3cb70780ff71b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 29 Nov 2014 20:50:48 +0100 Subject: [PATCH 032/351] Set cursor in top left corner in clrscr() as documented in conio.h --- libsrc/c1p/clrscr.s | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/libsrc/c1p/clrscr.s b/libsrc/c1p/clrscr.s index 5550d1d75..ce221f31e 100644 --- a/libsrc/c1p/clrscr.s +++ b/libsrc/c1p/clrscr.s @@ -2,6 +2,8 @@ ; void clrscr (void); ; .export _clrscr + .import plot + .importzp CURS_X, CURS_Y .include "c1p.inc" ; Adapted from the Challenger Character Graphics @@ -10,16 +12,20 @@ BANKS = VIDEORAMSIZE / $100 _clrscr: - lda #$20 ;' ' - ldy #BANKS - ldx #$00 + lda #$20 ;' ' + ldy #BANKS + ldx #$00 staloc: - sta SCRNBASE,X + sta SCRNBASE,X inx - bne staloc - inc staloc+2 + bne staloc + inc staloc+2 dey - bne staloc - lda #>(SCRNBASE) ; load high byte - sta staloc+2 ; restore base address - rts + bne staloc + lda #>(SCRNBASE); load high byte + sta staloc+2 ; restore base address + + lda #$00 ; cursor in upper left corner + sta CURS_X + sta CURS_Y + jmp plot ; Set the cursor position From 67707f342df65cdf0c03d6b24169a80430dcb53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 29 Nov 2014 20:56:49 +0100 Subject: [PATCH 033/351] Set default start address to 0x200 --- cfg/c1p.cfg | 2 +- src/c1p65/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index 2f48dd084..32be486d5 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -7,7 +7,7 @@ FEATURES { label = __DESTRUCTOR_TABLE__, count = __DESTRUCTOR_COUNT__, segment = RODATA; - STARTADDRESS: default = $0300; + STARTADDRESS: default = $0200; } SYMBOLS { __STACKSIZE__: type = weak, value = $0400; # 1k stack diff --git a/src/c1p65/main.c b/src/c1p65/main.c index 3d6cdbe8b..bf74f73c1 100644 --- a/src/c1p65/main.c +++ b/src/c1p65/main.c @@ -137,7 +137,7 @@ int main (int argc, char *argv[]) FILE *OutputFileFp = 0; /* Initialize with default start address defined in c1p.cfg */ - unsigned long StartAddr = 0x300; + unsigned long StartAddr = 0x200; /* Start program automatically after loading */ unsigned AutoStart = 1; From 9b9622d09a081aabe0dfd5a8414a7f3bfa799def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 29 Nov 2014 22:13:07 +0100 Subject: [PATCH 034/351] Added chline and cvline implementation from CBM implementation. --- libsrc/c1p/chline.s | 29 +++++++++++++++++++++++++++++ libsrc/c1p/cvline.s | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 libsrc/c1p/chline.s create mode 100644 libsrc/c1p/cvline.s diff --git a/libsrc/c1p/chline.s b/libsrc/c1p/chline.s new file mode 100644 index 000000000..da07e83be --- /dev/null +++ b/libsrc/c1p/chline.s @@ -0,0 +1,29 @@ +; +; based on CBM implementation +; +; originally by: +; Ullrich von Bassewitz, 08.08.1998 +; +; void chlinexy (unsigned char x, unsigned char y, unsigned char length); +; void chline (unsigned char length); +; + + .export _chlinexy, _chline + .import popa, _gotoxy, cputdirect + .importzp tmp1 + +_chlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length + +_chline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #$94 ; Horizontal line, screen code + jsr cputdirect ; Direct output + dec tmp1 + bne L1 +L9: rts diff --git a/libsrc/c1p/cvline.s b/libsrc/c1p/cvline.s new file mode 100644 index 000000000..607a4c691 --- /dev/null +++ b/libsrc/c1p/cvline.s @@ -0,0 +1,32 @@ +; +; based on CBM version +; originally by: +; Ullrich von Bassewitz, 08.08.1998 +; +; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); +; void cvline (unsigned char length); +; + + .export _cvlinexy, _cvline + .import popa, _gotoxy, putchar, newline + .importzp tmp1 + +_cvlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _cvline + +_cvline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #$95 ; Vertical bar + jsr putchar ; Write, no cursor advance + jsr newline ; Advance cursor to next line + dec tmp1 + bne L1 +L9: rts + + + From 155f00f25e7d484cf136dbbc397cf2ed3080b740 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 30 Nov 2014 00:40:45 -0500 Subject: [PATCH 035/351] Fixed the detection of where to start and stop segments. --- src/da65/attrtab.c | 8 -------- src/da65/attrtab.h | 3 --- src/da65/main.c | 26 ++++++++++++++++---------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/da65/attrtab.c b/src/da65/attrtab.c index d288d1298..a9143584a 100644 --- a/src/da65/attrtab.c +++ b/src/da65/attrtab.c @@ -107,14 +107,6 @@ int IsSegmentStart (unsigned Addr) -int HaveSegmentChange (unsigned Addr) -/* Return true if the segment change attributes are set for the given address */ -{ - return (GetAttr (Addr) & (atSegmentStart | atSegmentEnd)) != 0x0000; -} - - - unsigned GetGranularity (attr_t Style) /* Get the granularity for the given style */ { diff --git a/src/da65/attrtab.h b/src/da65/attrtab.h index b2dc6c455..18515ce49 100644 --- a/src/da65/attrtab.h +++ b/src/da65/attrtab.h @@ -100,9 +100,6 @@ int IsSegmentEnd (unsigned Addr); int IsSegmentStart (unsigned Addr); /* Return true if a segment starts at the given address */ -int HaveSegmentChange (unsigned Addr); -/* Return true if the segment change attributes are set for the given address */ - unsigned GetGranularity (attr_t Style); /* Get the granularity for the given style */ diff --git a/src/da65/main.c b/src/da65/main.c index 05c4a7bfd..8c37e1ae2 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -348,6 +348,8 @@ static void OptVersion (const char* Opt attribute ((unused)), static void OneOpcode (unsigned RemainingBytes) /* Disassemble one opcode */ { + unsigned I; + /* Get the opcode from the current address */ unsigned char OPC = GetCodeByte (PC); @@ -380,7 +382,8 @@ static void OneOpcode (unsigned RemainingBytes) ** - ...if we have enough bytes remaining for the code at this address. ** - ...if the current instruction is valid for the given CPU. ** - ...if there is no label somewhere between the instruction bytes. - ** If any of those conditions is false, switch to data mode. + ** - ...if there is no segment change between the instruction bytes. + ** If any one of those conditions is false, switch to data mode. */ if (Style == atDefault) { if (D->Size > RemainingBytes) { @@ -390,16 +393,15 @@ static void OneOpcode (unsigned RemainingBytes) Style = atIllegal; MarkAddr (PC, Style); } else { - unsigned I; - for (I = 1; I < D->Size; ++I) { - if (HaveLabel (PC+I)) { + for (I = PC + D->Size; --I > PC; ) { + if (HaveLabel (I) || IsSegmentStart (I)) { Style = atIllegal; MarkAddr (PC, Style); break; } } - for (I = 1; I < D->Size - 1u; ++I) { - if (HaveSegmentChange (PC+I)) { + for (I = 0; I < D->Size - 1u; ++I) { + if (IsSegmentEnd (PC + I)) { Style = atIllegal; MarkAddr (PC, Style); break; @@ -422,7 +424,6 @@ static void OneOpcode (unsigned RemainingBytes) */ if (D->Size <= RemainingBytes) { /* Output labels within the next insn */ - unsigned I; for (I = 1; I < D->Size; ++I) { ForwardLabel (I); } @@ -469,11 +470,16 @@ static void OneOpcode (unsigned RemainingBytes) DataByteLine (1); ++PC; break; - } - if (IsSegmentEnd (PC - 1)) { - EndSegment (); + /* Change back to the default CODE segment if + ** a named segment stops at the current address. + */ + for (I = D->Size; I >= 1; --I) { + if (IsSegmentEnd (PC - I)) { + EndSegment (); + break; + } } } From 1446d99b14a45a4b1f7899a81926f381a442f240 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 30 Nov 2014 00:51:09 -0500 Subject: [PATCH 036/351] Clarified a segment error message. --- src/da65/infofile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/da65/infofile.c b/src/da65/infofile.c index 7d8e69384..e8ce66cf7 100644 --- a/src/da65/infofile.c +++ b/src/da65/infofile.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2011, Ullrich von Bassewitz */ +/* (C) 2000-2014, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -754,7 +754,7 @@ static void SegmentSection (void) /* Check that segments do not overlap */ if (SegmentDefined ((unsigned) Start, (unsigned) End)) { - InfoError ("Segments cannot overlap"); + InfoError ("Segments must not overlap"); } /* Remember the segment data */ From 1365afa845117e44dec57e33b682abe59a3d3090 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 30 Nov 2014 11:20:57 +0100 Subject: [PATCH 037/351] more hacking --- cfg/pce.cfg | 13 +++++++------ include/conio.h | 2 ++ libsrc/pce/pcengine.h => include/pce.h | 0 libsrc/pce/clock.s | 20 ++++++++++---------- libsrc/pce/crt0.s | 1 + libsrc/pce/gotoxy.s | 19 +++++++++++++++++++ testcode/lib/conio.c | 10 ++++++++++ 7 files changed, 49 insertions(+), 16 deletions(-) rename libsrc/pce/pcengine.h => include/pce.h (100%) create mode 100644 libsrc/pce/gotoxy.s create mode 100644 testcode/lib/conio.c diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 276f3b3b6..b08e63814 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,3 +1,6 @@ +SYMBOLS { + __STACKSIZE__: type = weak, value = $0300; # 3 pages stack +} MEMORY { ZP: start = $00, size = $1A, type = rw, define = yes; @@ -37,10 +40,11 @@ SEGMENTS { #HEADER: load = HEADER, type = wprot; #aSTARTUP: load = ROM0, type = wprot, define = yes; - STARTUP: load = ROM0, type = wprot, define = yes; + STARTUP: load = ROM0, type = ro, define = yes; - CODE: load = ROM, type = wprot, define = yes; - RODATA: load = ROM, type = wprot, define = yes; + INIT: load = ROM0, type = ro, define = yes, optional = yes; + CODE: load = ROM, type = ro, define = yes; + RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM0, run= RAM, type = rw, define = yes; # BSS: load = RAM2, type = bss, define = yes; @@ -63,6 +67,3 @@ FEATURES { label=__DESTRUCTOR_TABLE__, count=__DESTRUCTOR_COUNT__; } -SYMBOLS { - __STACKSIZE__ = $0300; # 3 pages stack -} diff --git a/include/conio.h b/include/conio.h index 54667a3ca..f8a880c77 100644 --- a/include/conio.h +++ b/include/conio.h @@ -77,6 +77,8 @@ # include <lynx.h> #elif defined(__NES__) # include <nes.h> +#elif defined(__PCE__) +# include <pce.h> #endif diff --git a/libsrc/pce/pcengine.h b/include/pce.h similarity index 100% rename from libsrc/pce/pcengine.h rename to include/pce.h diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index d344814ad..60096c81d 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -3,21 +3,21 @@ ; ; clock_t clock (void); ; - - .include "pcengine.inc" - .export _clock - .importzp sreg + .include "pcengine.inc" + + .export _clock + .importzp sreg .proc _clock - ldy #0 ; Byte 3 is always zero - sty sreg+1 - sty sreg + ldy #0 ; Byte 3 is always zero + sty sreg+1 + sty sreg - ldx _tickcount+1 - lda _tickcount - rts + ldx _tickcount+1 + lda _tickcount + rts .endproc diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index d9c5a2ccb..43ca5d602 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -8,6 +8,7 @@ ; .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib .import push0, _main, zerobss .import initheap diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s new file mode 100644 index 000000000..cfb59efe2 --- /dev/null +++ b/libsrc/pce/gotoxy.s @@ -0,0 +1,19 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void gotoxy (unsigned char x, unsigned char y); +; + + .export _gotoxy + .import popa, plot + + .include "pcengine.inc" + +_gotoxy: + + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position + + diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c new file mode 100644 index 000000000..6a7bb2341 --- /dev/null +++ b/testcode/lib/conio.c @@ -0,0 +1,10 @@ + +#include <conio.h> + +void main(void) +{ + clrscr(); +// cprintf("hello world"); + cputs("hello world"); + for(;;); +} \ No newline at end of file From 3867be716647021a4a3eac6f9a723ad5de131c56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 30 Nov 2014 14:25:16 +0100 Subject: [PATCH 038/351] Added cclear() and cclearxy() implementations. --- libsrc/c1p/cclear.s | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 libsrc/c1p/cclear.s diff --git a/libsrc/c1p/cclear.s b/libsrc/c1p/cclear.s new file mode 100644 index 000000000..4412f0bba --- /dev/null +++ b/libsrc/c1p/cclear.s @@ -0,0 +1,33 @@ +; +; Copied from CBM implementation +; +; originally by: +; Ullrich von Bassewitz, 08.08.1998 +; +; void cclearxy (unsigned char x, unsigned char y, unsigned char length); +; void cclear (unsigned char length); +; + + .export _cclearxy, _cclear + .import popa, _gotoxy, cputdirect + .importzp tmp1 + +_cclearxy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _cclear + +_cclear: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #$20 ; Blank - screen code + jsr cputdirect ; Direct output + dec tmp1 + bne L1 +L9: rts + + + + From fa770bada8bd88fcae0ef9cbd8494b23a9debd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 30 Nov 2014 15:58:59 +0100 Subject: [PATCH 039/351] Added scrsize() function. --- libsrc/conio/{scrsize.s => _scrsize.s} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libsrc/conio/{scrsize.s => _scrsize.s} (100%) diff --git a/libsrc/conio/scrsize.s b/libsrc/conio/_scrsize.s similarity index 100% rename from libsrc/conio/scrsize.s rename to libsrc/conio/_scrsize.s From 945ad167dfa5d4714e235cdff1458a12e43384af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 30 Nov 2014 16:00:55 +0100 Subject: [PATCH 040/351] Undo accidental rename of wrong scrsize.s file. --- libsrc/conio/{_scrsize.s => scrsize.s} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename libsrc/conio/{_scrsize.s => scrsize.s} (100%) diff --git a/libsrc/conio/_scrsize.s b/libsrc/conio/scrsize.s similarity index 100% rename from libsrc/conio/_scrsize.s rename to libsrc/conio/scrsize.s From b47a1d99ece5bb7ff5322f69cd6befed6c657057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 30 Nov 2014 16:01:43 +0100 Subject: [PATCH 041/351] Added scrsize() function. --- libsrc/c1p/_scrsize.s | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 libsrc/c1p/_scrsize.s diff --git a/libsrc/c1p/_scrsize.s b/libsrc/c1p/_scrsize.s new file mode 100644 index 000000000..75de2b349 --- /dev/null +++ b/libsrc/c1p/_scrsize.s @@ -0,0 +1,22 @@ +; +; based on PET implementation +; +; originally by: +; Ullrich von Bassewitz, 26.10.2000 +; +; Screen size variables +; + + .export screensize + + .include "extzp.inc" + +.proc screensize + + ldx SCR_LINELEN + inx ; Variable is one less + ldy #25 + rts + +.endproc + From e9a90940b18f97af5ca6b0db131982019f1c70a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 30 Nov 2014 21:05:36 +0100 Subject: [PATCH 042/351] Dummy implementation for osmapperrno Copied from atmos implementation --- libsrc/c1p/oserror.s | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 libsrc/c1p/oserror.s diff --git a/libsrc/c1p/oserror.s b/libsrc/c1p/oserror.s new file mode 100644 index 000000000..073691a06 --- /dev/null +++ b/libsrc/c1p/oserror.s @@ -0,0 +1,20 @@ +; +; dummy implementation for Challenger 1P based on atmos implementation +; +; original by +; Stefan Haubenthal, 2011-04-18 +; +; int __fastcall__ _osmaperrno (unsigned char oserror); +; /* Map a system specific error into a system independent code */ +; + + .include "errno.inc" + .export __osmaperrno + +.proc __osmaperrno + + lda #<EUNKNOWN + ldx #>EUNKNOWN + rts + +.endproc From fd5dca08fb3e3db974075f7932f822b687499f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Tue, 2 Dec 2014 18:20:54 +0100 Subject: [PATCH 043/351] Removed unused constants They were left-overs from early attempts to implement character output. --- libsrc/c1p/c1p.inc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libsrc/c1p/c1p.inc b/libsrc/c1p/c1p.inc index 60ea6eaaa..ad058373a 100644 --- a/libsrc/c1p/c1p.inc +++ b/libsrc/c1p/c1p.inc @@ -1,8 +1,4 @@ SCRNBASE := $D000 ; Base of video RAM VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) - -CURSORPOS := $0200 ; Cursor position for OUTPUTC routine - -OUTPUTC := $BF2D ; Output character at cursor position INPUTC := $FD00 ; Input character from keyboard From 8d5bb552818ec7b52426be223e1c1ab837021147 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 3 Dec 2014 12:02:48 -0500 Subject: [PATCH 044/351] Made some descriptions less ambiguous. --- doc/atmos.sgml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/atmos.sgml b/doc/atmos.sgml index ab63c667b..a9d59a407 100644 --- a/doc/atmos.sgml +++ b/doc/atmos.sgml @@ -7,7 +7,7 @@ <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline> <url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2014-09-23 +<date>2014-12-03 <abstract> An overview over the Atmos runtime system as it is implemented for the cc65 C @@ -219,8 +219,9 @@ They are defined to be FUNCT + a number key. <sect1>Capitals Lock<p> -The "CAPS Lock" mode is turned off while the program is running. The previous -mode (usually turned on) is restored when the program stops. +The keyboard's "CAPS Lock" mode is turned off while the program is running. +The previous mode (usually, CAPS Lock turned on [because Oric BASIC keywords +must be UPPER-case]) is restored when the program stops. <sect1>Passing arguments to the program<p> @@ -234,7 +235,7 @@ supported directly by BASIC, the following syntax was chosen: <enum> <item>You must turn <tt/CAPS/ lock off (tap CTRL-T) when you want to type - lower-case arguments. + lower-case arguments (but, <tt/RUN/ and <tt/REM/ must be UPPER-case). <item>Arguments are separated by spaces. <item>Arguments may be quoted. <item>Leading and trailing spaces around an argument are ignored. Spaces within From d9df576fa6e894a2d6321084dd5423549b5176ba Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 13 Dec 2014 09:52:39 -0500 Subject: [PATCH 045/351] Used an easier-to-remember way of creating a program that uses graphics RAM for other purposes. --- cfg/atmos.cfg | 6 +++--- doc/atmos.sgml | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg index 062711b96..691bd467d 100644 --- a/cfg/atmos.cfg +++ b/cfg/atmos.cfg @@ -2,10 +2,10 @@ SYMBOLS { __TAPEHDR__: type = import; __BASHDR__: type = import; __PROGFLAG__: type = weak, value = $00; # $00=BASIC, $80=machine code - __AUTORUN__: type = weak, value = $00; # $C7=run, $00=only load + __AUTORUN__: type = weak, value = $00; # $00=only load, $C7=run __STACKSIZE__: type = weak, value = $0800; # 2K stack - __RAMEND__: type = weak, value = $9800; # graphics RAM not grabbed -# __RAMEND__: type = weak, value = $B400; # graphics RAM grabbed + __GRAB__: type = weak, value = 0; # 0=don't grab graphics RAM, 1=grab graphics RAM + __RAMEND__: type = weak, value = $9800 + $1C00 * __GRAB__; } MEMORY { ZP: file = "", define = yes, start = $00E2, size = $001A; diff --git a/doc/atmos.sgml b/doc/atmos.sgml index a9d59a407..913e50ed7 100644 --- a/doc/atmos.sgml +++ b/doc/atmos.sgml @@ -7,7 +7,7 @@ <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline> <url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2014-12-03 +<date>2014-12-05 <abstract> An overview over the Atmos runtime system as it is implemented for the cc65 C @@ -50,9 +50,9 @@ In the standard setup, cc65-generated programs use the memory from available. ROM calls are possible without further precautions. If your program needs more memory, and it won't use TGI graphics, then you can -use the ld65 command-line option, <tt/-D __RAMEND__=$B400/, when building the -program, to "grab" the graphics screen RAM. Then, nearly 44K of memory is -available. +use the ld65 command-line option, <tt/-D __GRAB__=1/, when building the +program, to include the graphics screen RAM. Then, nearly 44K of memory +($0501 to $B400) is available. Special locations: @@ -100,7 +100,7 @@ structures; accessing the struct fields will access the chip registers. <descrip> <tag><tt/VIA/</tag> - Access to the VIA (versatile interface adapter) chip is available via the + Access to the VIA (Versatile Interface Adapter) chip is available via the <tt/VIA/ variable. The structure behind this variable is explained in <tt/_6522.h/. </descrip><p> @@ -217,7 +217,7 @@ following functions (and a few others): They are defined to be FUNCT + a number key. -<sect1>Capitals Lock<p> +<sect1>Capitals lock<p> The keyboard's "CAPS Lock" mode is turned off while the program is running. The previous mode (usually, CAPS Lock turned on [because Oric BASIC keywords @@ -246,6 +246,15 @@ supported directly by BASIC, the following syntax was chosen: </enum> +<sect1>Automatic starting<p> + +Usually, a cc65-built program just will sit quietly in memory, after it is +CLOADed. It waits for you to start it (by typing BASIC's <tt/RUN/ command). +But, if you want to create a program that will start running immediately after +it is loaded, then you can use the linker command-line option +<tt/-D __AUTORUN__=$C7/. + + <sect1>Interrupts<p> The runtime for the Atmos uses routines marked as <tt/.INTERRUPTOR/ for From b9c1087cc2febf5789f7bc59dc9ff52f50ce3b3b Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 17 Dec 2014 11:57:45 -0500 Subject: [PATCH 046/351] Added make code to build the optimized versions. --- test/misc/Makefile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/misc/Makefile b/test/misc/Makefile index b18d9165e..bb9fa404b 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -33,30 +33,28 @@ TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oi.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oir.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.or.prg) -# FIXME: actually use/build differently optimized programs here - all: $(TESTS) # should compile, but then hangs in an endless loop $(WORKDIR)/endless%prg: endless.c - $(CL65) $(CC65FLAGS) $< -o $@ + $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ ! $(SIM65) $(SIM65FLAGS) $@ # these need reference data that cant be generated by a host compiled program # in a useful way $(WORKDIR)/limits%prg: limits.c - $(CL65) $(CC65FLAGS) $< -o $@ + $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/limits.out $(DIFF) $(WORKDIR)/limits.out limits.ref # the rest are tests that fail currently for one reason or another $(WORKDIR)/fields%prg: fields.c @echo "FIXME: " $@ "will currently fail" - $(CL65) $(CC65FLAGS) $< -o $@ + $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ -$(SIM65) $(SIM65FLAGS) $@ $(WORKDIR)/sitest%prg: sitest.c @echo "FIXME: " $@ "will currently fail" - -$(CL65) $(CC65FLAGS) $< -o $@ + -$(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ -$(SIM65) $(SIM65FLAGS) $@ clean: From ad56b6abe94129d014f62eab5a51d6e3e61bb5d5 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 17 Dec 2014 15:59:29 -0500 Subject: [PATCH 047/351] Made the makefiles' clean target remove the object files from the source directory. --- test/err/Makefile | 2 +- test/misc/Makefile | 2 +- test/ref/Makefile | 2 +- test/val/Makefile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/err/Makefile b/test/err/Makefile index 40ccfcb59..a6d590515 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -49,4 +49,4 @@ $(WORKDIR)/%.or.prg: %.c ! $(CL65) -Or $(CC65FLAGS) $< -o $@ clean: @$(RM) $(TESTS) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.o) + @$(RM) $(SOURCES:.c=.o) diff --git a/test/misc/Makefile b/test/misc/Makefile index bb9fa404b..7af8c0cb1 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -59,7 +59,7 @@ $(WORKDIR)/sitest%prg: sitest.c clean: @$(RM) $(TESTS) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.o) + @$(RM) $(SOURCES:.c=.o) @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.out) diff --git a/test/ref/Makefile b/test/ref/Makefile index b752adc1d..39336aa52 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -86,7 +86,7 @@ $(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref clean: @$(RM) $(TESTS) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.o) + @$(RM) $(SOURCES:.c=.o) @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.out) @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.ref) @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.host) diff --git a/test/val/Makefile b/test/val/Makefile index 2e0aca278..c9afbbd86 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -67,4 +67,4 @@ $(WORKDIR)/%.or.prg: %.c clean: @$(RM) $(TESTS) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.o) + @$(RM) $(SOURCES:.c=.o) From d9c8c1de457e2b8964c2828fbf2fdd0988e17de2 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 17 Dec 2014 16:30:09 -0500 Subject: [PATCH 048/351] Create the makefile variable REFS in the same way that TESTS is made. --- test/err/Makefile | 1 + test/misc/Makefile | 3 +-- test/ref/Makefile | 5 +++-- test/val/Makefile | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/test/err/Makefile b/test/err/Makefile index a6d590515..46ce4c9cc 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -20,6 +20,7 @@ WORKDIR := ./../../testwrk .PHONY: all clean SOURCES := $(wildcard *.c) + TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) diff --git a/test/misc/Makefile b/test/misc/Makefile index 7af8c0cb1..64fcc8759 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -24,6 +24,7 @@ DIFF := $(WORKDIR)/bdiff .PHONY: all clean SOURCES := $(wildcard *.c) + TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) @@ -61,5 +62,3 @@ clean: @$(RM) $(TESTS) @$(RM) $(SOURCES:.c=.o) @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.out) - - diff --git a/test/ref/Makefile b/test/ref/Makefile index 39336aa52..df13a28cc 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -26,9 +26,10 @@ CFLAGS := -O2 -Wall -W -Wextra -fwrapv -fno-strict-overflow .PHONY: all clean -REFS := $(patsubst %.c,$(WORKDIR)/%.ref,$(wildcard *.c)) - SOURCES := $(wildcard *.c) + +REFS := $(SOURCES:%.c=$(WORKDIR)/%.ref) + TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) diff --git a/test/val/Makefile b/test/val/Makefile index c9afbbd86..f4e0d28b2 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -22,6 +22,7 @@ WORKDIR := ./../../testwrk .PHONY: all clean SOURCES := $(wildcard *.c) + TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) From 15a22bd1c819f6f82dca15bee379741561ba6389 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 17 Dec 2014 17:35:18 -0500 Subject: [PATCH 049/351] All regression-tests subdirectories are cleaned before the first test starts, so that 'make continue' won't see debris when it moves to the next directory. --- test/Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/Makefile b/test/Makefile index b942cbcdf..579fc8b92 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,7 +1,9 @@ # toplevel makefile for the regression tests -MAKE := make --no-print-dir +# You can comment this special target when you debug the regression tests. +# Then, make will give you more progress reports. +.SILENT: ifneq ($(shell echo),) CMD_EXE = 1 @@ -21,21 +23,17 @@ endif WORKDIR := ../testwrk -.PHONY: dotests clean +.PHONY: all dotests continue mostly-clean clean all: dotests $(WORKDIR): - @$(MKDIR) $(WORKDIR) + $(MKDIR) $(WORKDIR) -$(WORKDIR)/bdiff$(EXE): $(WORKDIR) - @$(CC) -o $(WORKDIR)/bdiff$(EXE) bdiff.c +$(WORKDIR)/bdiff$(EXE): bdiff.c | $(WORKDIR) + $(CC) -O2 -o $@ $< -dotests: $(WORKDIR)/bdiff$(EXE) - @$(MAKE) -C val clean all - @$(MAKE) -C ref clean all - @$(MAKE) -C err clean all - @$(MAKE) -C misc clean all +dotests: mostly-clean continue continue: $(WORKDIR)/bdiff$(EXE) @$(MAKE) -C val all @@ -43,10 +41,12 @@ continue: $(WORKDIR)/bdiff$(EXE) @$(MAKE) -C err all @$(MAKE) -C misc all -clean: +mostly-clean: @$(MAKE) -C val clean @$(MAKE) -C ref clean @$(MAKE) -C err clean @$(MAKE) -C misc clean - @$(RM) $(WORKDIR)/bdiff$(EXE) - @$(RMDIR) $(WORKDIR) + +clean: mostly-clean + $(RM) $(WORKDIR)/bdiff$(EXE) + $(RMDIR) $(WORKDIR) From e414e89b64e4e9318d6b4588bdeeaa8d8c722d22 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 17 Dec 2014 17:44:39 -0500 Subject: [PATCH 050/351] Use simply-defined make variables. --- test/Makefile | 12 ++++++------ test/err/Makefile | 7 ++++--- test/misc/Makefile | 16 ++++++++-------- test/ref/Makefile | 8 ++++---- test/val/Makefile | 8 ++++---- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/test/Makefile b/test/Makefile index 579fc8b92..0f96a38f8 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,24 +1,24 @@ -# toplevel makefile for the regression tests +# top-level makefile for the regression tests # You can comment this special target when you debug the regression tests. # Then, make will give you more progress reports. .SILENT: ifneq ($(shell echo),) - CMD_EXE = 1 + CMD_EXE := 1 endif ifdef CMD_EXE RM := del /f EXE := .exe - MKDIR = mkdir - RMDIR = rmdir + MKDIR := mkdir + RMDIR := rmdir else RM := rm -f EXE := - MKDIR = mkdir -p - RMDIR = rmdir + MKDIR := mkdir -p + RMDIR := rmdir endif WORKDIR := ../testwrk diff --git a/test/err/Makefile b/test/err/Makefile index 46ce4c9cc..29c47ef3e 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -2,10 +2,10 @@ # makefile for the tests that MUST NOT compile ifneq ($(shell echo),) - CMD_EXE = 1 + CMD_EXE := 1 endif -CC65FLAGS = -t sim6502 +CC65FLAGS := -t sim6502 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) @@ -15,7 +15,7 @@ else RM := rm -f endif -WORKDIR := ./../../testwrk +WORKDIR := ../../testwrk .PHONY: all clean @@ -48,6 +48,7 @@ $(WORKDIR)/%.oir.prg: %.c ! $(CL65) -Oir $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.or.prg: %.c ! $(CL65) -Or $(CC65FLAGS) $< -o $@ + clean: @$(RM) $(TESTS) @$(RM) $(SOURCES:.c=.o) diff --git a/test/misc/Makefile b/test/misc/Makefile index 64fcc8759..c473f5f85 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -2,11 +2,11 @@ # makefile for the remaining tests that need special care in one way or another ifneq ($(shell echo),) - CMD_EXE = 1 + CMD_EXE := 1 endif -CC65FLAGS = -t sim6502 -SIM65FLAGS = -x 200000000 +CC65FLAGS := -t sim6502 +SIM65FLAGS := -x 200000000 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) @@ -17,7 +17,7 @@ else RM := rm -f endif -WORKDIR := ./../../testwrk +WORKDIR := ../../testwrk DIFF := $(WORKDIR)/bdiff @@ -41,7 +41,7 @@ $(WORKDIR)/endless%prg: endless.c $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ ! $(SIM65) $(SIM65FLAGS) $@ -# these need reference data that cant be generated by a host compiled program +# these need reference data that can't be generated by a host-compiled program, # in a useful way $(WORKDIR)/limits%prg: limits.c $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ @@ -50,13 +50,13 @@ $(WORKDIR)/limits%prg: limits.c # the rest are tests that fail currently for one reason or another $(WORKDIR)/fields%prg: fields.c - @echo "FIXME: " $@ "will currently fail" + @echo "FIXME: " $@ "currently will fail." $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ -$(SIM65) $(SIM65FLAGS) $@ $(WORKDIR)/sitest%prg: sitest.c - @echo "FIXME: " $@ "will currently fail" + @echo "FIXME: " $@ "currently will fail." -$(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ - -$(SIM65) $(SIM65FLAGS) $@ +# -$(SIM65) $(SIM65FLAGS) $@ clean: @$(RM) $(TESTS) diff --git a/test/ref/Makefile b/test/ref/Makefile index df13a28cc..66ff94e28 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -3,11 +3,11 @@ # compared with reference output ifneq ($(shell echo),) - CMD_EXE = 1 + CMD_EXE := 1 endif -CC65FLAGS = -t sim6502 -SIM65FLAGS = -x 200000000 +CC65FLAGS := -t sim6502 +SIM65FLAGS := -x 200000000 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) @@ -18,7 +18,7 @@ else RM := rm -f endif -WORKDIR := ./../../testwrk +WORKDIR := ../../testwrk DIFF := $(WORKDIR)/bdiff diff --git a/test/val/Makefile b/test/val/Makefile index f4e0d28b2..bd88797e5 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -2,11 +2,11 @@ # makefile for the regression tests that return an error code on failure ifneq ($(shell echo),) - CMD_EXE = 1 + CMD_EXE := 1 endif -CC65FLAGS = -t sim6502 -SIM65FLAGS = -x 200000000 +CC65FLAGS := -t sim6502 +SIM65FLAGS := -x 200000000 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) @@ -17,7 +17,7 @@ else RM := rm -f endif -WORKDIR := ./../../testwrk +WORKDIR := ../../testwrk .PHONY: all clean From 244eeedcfc82c2582e057a46c61d58a5e9b6e631 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 18 Dec 2014 14:15:24 -0500 Subject: [PATCH 051/351] Shortenned the code that creates the TESTS make variable. And, fixed the variable-substitution that creates the CC65 optimization option. --- test/err/Makefile | 10 +--------- test/misc/Makefile | 18 +++++------------- test/ref/Makefile | 11 +---------- test/val/Makefile | 10 +--------- 4 files changed, 8 insertions(+), 41 deletions(-) diff --git a/test/err/Makefile b/test/err/Makefile index 29c47ef3e..4e12323fd 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -20,15 +20,7 @@ WORKDIR := ../../testwrk .PHONY: all clean SOURCES := $(wildcard *.c) - -TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.or.prg) +TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) all: $(TESTS) diff --git a/test/misc/Makefile b/test/misc/Makefile index c473f5f85..b04321c33 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -24,38 +24,30 @@ DIFF := $(WORKDIR)/bdiff .PHONY: all clean SOURCES := $(wildcard *.c) - -TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.or.prg) +TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) all: $(TESTS) # should compile, but then hangs in an endless loop $(WORKDIR)/endless%prg: endless.c - $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ + $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ ! $(SIM65) $(SIM65FLAGS) $@ # these need reference data that can't be generated by a host-compiled program, # in a useful way $(WORKDIR)/limits%prg: limits.c - $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ + $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/limits.out $(DIFF) $(WORKDIR)/limits.out limits.ref # the rest are tests that fail currently for one reason or another $(WORKDIR)/fields%prg: fields.c @echo "FIXME: " $@ "currently will fail." - $(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ + $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ -$(SIM65) $(SIM65FLAGS) $@ $(WORKDIR)/sitest%prg: sitest.c @echo "FIXME: " $@ "currently will fail." - -$(CL65) $(subst .,,($*:.o%=-O%)) $(CC65FLAGS) $< -o $@ + -$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ # -$(SIM65) $(SIM65FLAGS) $@ clean: diff --git a/test/ref/Makefile b/test/ref/Makefile index 66ff94e28..3e7a5ad6c 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -27,17 +27,8 @@ CFLAGS := -O2 -Wall -W -Wextra -fwrapv -fno-strict-overflow .PHONY: all clean SOURCES := $(wildcard *.c) - REFS := $(SOURCES:%.c=$(WORKDIR)/%.ref) - -TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.or.prg) +TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) all: $(REFS) $(TESTS) diff --git a/test/val/Makefile b/test/val/Makefile index bd88797e5..2efcbd0de 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -22,15 +22,7 @@ WORKDIR := ../../testwrk .PHONY: all clean SOURCES := $(wildcard *.c) - -TESTS := $(SOURCES:%.c=$(WORKDIR)/%.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.o.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.os.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.osir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oi.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.oir.prg) -TESTS += $(SOURCES:%.c=$(WORKDIR)/%.or.prg) +TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) all: $(TESTS) From 1a0a872bd6a6ac19b5e14231696bf6a8f14944cf Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 18 Dec 2014 14:30:35 -0500 Subject: [PATCH 052/351] Made sure that parallel-building the regression-tests doesn't start a test before all of the directories are clean. --- test/Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Makefile b/test/Makefile index 0f96a38f8..27f7ff456 100644 --- a/test/Makefile +++ b/test/Makefile @@ -33,6 +33,8 @@ $(WORKDIR): $(WORKDIR)/bdiff$(EXE): bdiff.c | $(WORKDIR) $(CC) -O2 -o $@ $< +.NOTPARALLEL: + dotests: mostly-clean continue continue: $(WORKDIR)/bdiff$(EXE) From 8fa5fc61086a8d736b431b8562ec64a2318cec0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Fri, 2 Jan 2015 20:28:36 +0100 Subject: [PATCH 053/351] Restructured according to coding conventions. --- cfg/c1p.cfg | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index 32be486d5..62adcd820 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -1,14 +1,7 @@ FEATURES { - CONDES: type = constructor, - label = __CONSTRUCTOR_TABLE__, - count = __CONSTRUCTOR_COUNT__, - segment = INIT; - CONDES: type = destructor, - label = __DESTRUCTOR_TABLE__, - count = __DESTRUCTOR_COUNT__, - segment = RODATA; STARTADDRESS: default = $0200; } + SYMBOLS { __STACKSIZE__: type = weak, value = $0400; # 1k stack __HIMEM__: type = weak, value = $2000; # Presumed RAM end @@ -29,3 +22,13 @@ SEGMENTS { ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = rw, define = yes; } +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; +} From 073b4c264aa4bd22deeaed7b97b990bd51fbd8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 5 Jan 2015 20:37:23 +0100 Subject: [PATCH 054/351] Set default RAM size to 32 kB. 8 kB RAM are very small for "interesting" programs compiled with cc65. Therefore set the default RAM size to 32 kB. --- cfg/c1p.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index 62adcd820..633298270 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -3,8 +3,8 @@ FEATURES { } SYMBOLS { - __STACKSIZE__: type = weak, value = $0400; # 1k stack - __HIMEM__: type = weak, value = $2000; # Presumed RAM end + __STACKSIZE__: type = weak, value = $0400; # 1 kB stack + __HIMEM__: type = weak, value = $8000; # 32 kB RAM } MEMORY { # for size of ZP see runtime/zeropage.s and c1p/extzp.s From 50164a9d68d67bac475460c54c633cc61a4515f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 5 Jan 2015 20:55:45 +0100 Subject: [PATCH 055/351] Removed c1p65 object file converter. Now using srec_cat from the srecord package. --- src/Makefile | 1 - src/c1p65/main.c | 232 ------------------------------------------- src/cc65.sln | 249 ++++++++++++++++++++++------------------------- 3 files changed, 119 insertions(+), 363 deletions(-) delete mode 100644 src/c1p65/main.c diff --git a/src/Makefile b/src/Makefile index 34706fab5..5aafc4bb8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,6 @@ ifneq ($(shell echo),) endif PROGS = ar65 \ - c1p65 \ ca65 \ cc65 \ cl65 \ diff --git a/src/c1p65/main.c b/src/c1p65/main.c deleted file mode 100644 index bf74f73c1..000000000 --- a/src/c1p65/main.c +++ /dev/null @@ -1,232 +0,0 @@ -/* Object file conversion utility for Challenger 1P - - by Stephan Muehlstrasser -*/ - - -#include <stdio.h> -#include <stdlib.h> -#include <stdarg.h> -#include <string.h> -#include <errno.h> -#include <time.h> - -/* common stuff */ -#include "abend.h" -#include "cmdline.h" -#include "fname.h" -#include "chartype.h" -#include "target.h" -#include "version.h" -#include "xmalloc.h" - -static void Usage (void) -{ - printf ( - "Usage: %s [options] file\n" - "Short options:\n" - " -V\t\t\tPrint the version number\n" - " -h\t\t\tHelp (this text)\n" - " -n\t\tNo automatic start after loading program\n" - " -o name\t\tName the C1P output file (default: <input>.c1p)\n" - " -S addr\t\tLoad address (default 0x300)\n" - "\n" - "Long options:\n" - " --help\t\tHelp (this text)\n" - " --version\t\tPrint the version number\n", - ProgName); -} - -static void OptHelp (const char* Opt attribute ((unused)), - const char* Arg attribute ((unused))) -/* Print usage information and exit */ -{ - Usage (); - exit (EXIT_SUCCESS); -} - - -static void OptVersion (const char* Opt attribute ((unused)), - const char* Arg attribute ((unused))) -/* Print the program version */ -{ - fprintf (stderr, "grc65 V%s\n", GetVersionAsString ()); -} - - -static unsigned long CvtNumber (const char* Arg, const char* Number) -/* Convert a number from a string. Allow '$' and '0x' prefixes for hex - * numbers. Duplicated from ld65's main.c. - */ -{ - unsigned long Val; - int Converted; - - /* Convert */ - if (*Number == '$') { - ++Number; - Converted = sscanf (Number, "%lx", &Val); - } else { - Converted = sscanf (Number, "%li", (long*)&Val); - } - - /* Check if we do really have a number */ - if (Converted != 1) { - AbEnd ("Invalid number given in argument: %s\n", Arg); - } - - /* Return the result */ - return Val; -} - -/* Commands of C1P PROM monitor */ -#define ADDRESS_MODE_CMD '.' -#define DATA_MODE_CMD '/' -#define EXECUTE_CMD 'G' -#define DATA_MODE_ADDRESS 0x00FB - -/* Transform the cc65 executable binary into a series of - commands that make the C1P PROM monitor load the bytes - into memory. -*/ -static void Transform (unsigned long StartAddress, FILE *In, FILE *Out, - unsigned AutoStart) -{ - int c; - - /* Position to the start address */ - fprintf(Out, "%c%04.4X%c", ADDRESS_MODE_CMD, - StartAddress & 0xFFFF, DATA_MODE_CMD); - - /* Loop over all input bytes and enter them one by one */ - for (c = getc(In); c != EOF; c = getc(In)) { - fprintf(Out, "%02.2X\r", (unsigned int) c & 0xFF); - } - - if (AutoStart) { - /* Execute */ - fprintf (Out, "%c%04.4x%c", - ADDRESS_MODE_CMD, (unsigned int) StartAddress & 0xFFFF, - EXECUTE_CMD); - } - else { - /* Store 00 to 0x00FB to enable keyboard input at the end */ - fprintf(Out, "%c%04.4X%c%02.2X", ADDRESS_MODE_CMD, - 0x00FB, DATA_MODE_CMD, 0x00); - } -} - -/* Default suffix for C1P object file */ -#define C1P_SUFFIX ".c1p" - -int main (int argc, char *argv[]) -{ - /* Program long options */ - static const LongOpt OptTab[] = { - { "--help", 0, OptHelp}, - { "--version", 0, OptVersion}, - }; - - /* Initialize input and output file name */ - const char* InputFile = 0; - const char* OutputFile = 0; - char *GeneratedOutputFile = 0; - - /* Initialize file pointers */ - FILE *InputFileFp = 0; - FILE *OutputFileFp = 0; - - /* Initialize with default start address defined in c1p.cfg */ - unsigned long StartAddr = 0x200; - - /* Start program automatically after loading */ - unsigned AutoStart = 1; - - unsigned int I; - - /* Initialize the cmdline module */ - InitCmdLine (&argc, &argv, "c1p65"); - - /* Check the parameters */ - I = 1; - while (I < ArgCount) { - - /* Get the argument */ - const char* Arg = ArgVec [I]; - - /* Check for an option */ - if (Arg[0] == '-') { - switch (Arg[1]) { - - case '-': - LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); - break; - - case 'n': - AutoStart = 0; - break; - - case 'o': - OutputFile = GetArg(&I, 2); - break; - - case 'S': - StartAddr = CvtNumber (Arg, GetArg (&I, 2)); - break; - - case 'h': - case '?': - OptHelp (Arg, 0); - break; - - case 'V': - OptVersion (Arg, 0); - break; - - default: - UnknownOption (Arg); - } - - } else { - if (InputFile) { - fprintf (stderr, "additional file specs ignored\n"); - } else { - InputFile = Arg; - } - } - - /* Next argument */ - ++I; - } - - if (!InputFile) AbEnd ("No input file"); - - if (!OutputFile) { - const size_t len = strlen(InputFile) + sizeof(C1P_SUFFIX); - - GeneratedOutputFile = (char *) xmalloc(len); - sprintf(GeneratedOutputFile, "%s%s", InputFile, C1P_SUFFIX); - OutputFile = GeneratedOutputFile; - } - - /* Open input and output files */ - InputFileFp = fopen(InputFile, "rb"); - if (!InputFileFp) AbEnd ("Unable to open input file"); - - OutputFileFp = fopen(OutputFile, "wb"); - if (!OutputFileFp) AbEnd ("Unable to open output file"); - - /* Generate object file */ - Transform (StartAddr, InputFileFp, OutputFileFp, AutoStart); - - /* Cleanup */ - if (fclose(InputFileFp) == EOF) AbEnd ("Error closing input file"); - - if (fclose(OutputFileFp) == EOF) AbEnd ("Error closing output file"); - - if (GeneratedOutputFile) { - xfree(GeneratedOutputFile); - } - - return EXIT_SUCCESS; -} diff --git a/src/cc65.sln b/src/cc65.sln index 543038755..9d0f2cc2e 100644 --- a/src/cc65.sln +++ b/src/cc65.sln @@ -1,130 +1,119 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common.vcxproj", "{71DC1F68-BFC4-478C-8655-C8E9C9654D2B}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cc65", "cc65.vcxproj", "{B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ca65", "ca65.vcxproj", "{D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ar65", "ar65.vcxproj", "{5E8C19C6-B167-440C-8BEF-3CBF109CDB49}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ld65", "ld65.vcxproj", "{26C749A0-814C-47A2-9D36-AE92AE932FE4}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cl65", "cl65.vcxproj", "{F657912F-050A-488B-B203-50ED5715CDD7}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "da65", "da65.vcxproj", "{0BCFB793-2B25-40E2-B265-75848824AC4C}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "co65", "co65.vcxproj", "{F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grc65", "grc65.vcxproj", "{E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "od65", "od65.vcxproj", "{FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sp65", "sp65.vcxproj", "{4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sim65", "sim65.vcxproj", "{002A366E-2863-46A8-BDDE-DDF534AAEC73}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c1p65", "c1p65.vcxproj", "{4E031DE0-82B4-4204-8529-536626F7E0DF}" - ProjectSection(ProjectDependencies) = postProject - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} - EndProjectSection -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.ActiveCfg = Debug|Win32 - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.Build.0 = Debug|Win32 - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.ActiveCfg = Release|Win32 - {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.Build.0 = Release|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.ActiveCfg = Debug|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.Build.0 = Debug|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.ActiveCfg = Release|Win32 - {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.Build.0 = Release|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.ActiveCfg = Debug|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.Build.0 = Debug|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.ActiveCfg = Release|Win32 - {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.Build.0 = Release|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.ActiveCfg = Debug|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.Build.0 = Debug|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.ActiveCfg = Release|Win32 - {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.Build.0 = Release|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.ActiveCfg = Debug|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.Build.0 = Debug|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.ActiveCfg = Release|Win32 - {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.Build.0 = Release|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.ActiveCfg = Debug|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.Build.0 = Debug|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.ActiveCfg = Release|Win32 - {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.Build.0 = Release|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.ActiveCfg = Debug|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.Build.0 = Debug|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.ActiveCfg = Release|Win32 - {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.Build.0 = Release|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.ActiveCfg = Debug|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.Build.0 = Debug|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.ActiveCfg = Release|Win32 - {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.Build.0 = Release|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.ActiveCfg = Debug|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.Build.0 = Debug|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.ActiveCfg = Release|Win32 - {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.Build.0 = Release|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.ActiveCfg = Debug|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.Build.0 = Debug|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.ActiveCfg = Release|Win32 - {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.Build.0 = Release|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.ActiveCfg = Debug|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.Build.0 = Debug|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.ActiveCfg = Release|Win32 - {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.Build.0 = Release|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.ActiveCfg = Debug|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.Build.0 = Debug|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.ActiveCfg = Release|Win32 - {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.Build.0 = Release|Win32 - {4E031DE0-82B4-4204-8529-536626F7E0DF}.Debug|Win32.ActiveCfg = Debug|Win32 - {4E031DE0-82B4-4204-8529-536626F7E0DF}.Debug|Win32.Build.0 = Debug|Win32 - {4E031DE0-82B4-4204-8529-536626F7E0DF}.Release|Win32.ActiveCfg = Release|Win32 - {4E031DE0-82B4-4204-8529-536626F7E0DF}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "common", "common.vcxproj", "{71DC1F68-BFC4-478C-8655-C8E9C9654D2B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cc65", "cc65.vcxproj", "{B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ca65", "ca65.vcxproj", "{D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ar65", "ar65.vcxproj", "{5E8C19C6-B167-440C-8BEF-3CBF109CDB49}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ld65", "ld65.vcxproj", "{26C749A0-814C-47A2-9D36-AE92AE932FE4}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cl65", "cl65.vcxproj", "{F657912F-050A-488B-B203-50ED5715CDD7}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "da65", "da65.vcxproj", "{0BCFB793-2B25-40E2-B265-75848824AC4C}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "co65", "co65.vcxproj", "{F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "grc65", "grc65.vcxproj", "{E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "od65", "od65.vcxproj", "{FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sp65", "sp65.vcxproj", "{4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sim65", "sim65.vcxproj", "{002A366E-2863-46A8-BDDE-DDF534AAEC73}" + ProjectSection(ProjectDependencies) = postProject + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} = {71DC1F68-BFC4-478C-8655-C8E9C9654D2B} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.ActiveCfg = Debug|Win32 + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Debug|Win32.Build.0 = Debug|Win32 + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.ActiveCfg = Release|Win32 + {71DC1F68-BFC4-478C-8655-C8E9C9654D2B}.Release|Win32.Build.0 = Release|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.ActiveCfg = Debug|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Debug|Win32.Build.0 = Debug|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.ActiveCfg = Release|Win32 + {B17EDBD5-DC04-4970-9CBD-56A98B6A3FCA}.Release|Win32.Build.0 = Release|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.ActiveCfg = Debug|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Debug|Win32.Build.0 = Debug|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.ActiveCfg = Release|Win32 + {D28CB737-E6CA-49C4-8CE9-FF05F86DD4EC}.Release|Win32.Build.0 = Release|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.ActiveCfg = Debug|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Debug|Win32.Build.0 = Debug|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.ActiveCfg = Release|Win32 + {5E8C19C6-B167-440C-8BEF-3CBF109CDB49}.Release|Win32.Build.0 = Release|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.ActiveCfg = Debug|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Debug|Win32.Build.0 = Debug|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.ActiveCfg = Release|Win32 + {26C749A0-814C-47A2-9D36-AE92AE932FE4}.Release|Win32.Build.0 = Release|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.ActiveCfg = Debug|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Debug|Win32.Build.0 = Debug|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.ActiveCfg = Release|Win32 + {F657912F-050A-488B-B203-50ED5715CDD7}.Release|Win32.Build.0 = Release|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.ActiveCfg = Debug|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Debug|Win32.Build.0 = Debug|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.ActiveCfg = Release|Win32 + {0BCFB793-2B25-40E2-B265-75848824AC4C}.Release|Win32.Build.0 = Release|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.ActiveCfg = Debug|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Debug|Win32.Build.0 = Debug|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.ActiveCfg = Release|Win32 + {F5DB5D1A-05BC-48FE-B346-4E96DD522AA2}.Release|Win32.Build.0 = Release|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.ActiveCfg = Debug|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Debug|Win32.Build.0 = Debug|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.ActiveCfg = Release|Win32 + {E0FD0AB3-3BEE-496F-8108-A8E0F8933F39}.Release|Win32.Build.0 = Release|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.ActiveCfg = Debug|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Debug|Win32.Build.0 = Debug|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.ActiveCfg = Release|Win32 + {FF8576C2-1253-44FE-A51B-D9AE35F3CEAD}.Release|Win32.Build.0 = Release|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.ActiveCfg = Debug|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Debug|Win32.Build.0 = Debug|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.ActiveCfg = Release|Win32 + {4388D1AF-C7EA-4AD4-8E80-CA1FB7BF76BF}.Release|Win32.Build.0 = Release|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.ActiveCfg = Debug|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Debug|Win32.Build.0 = Debug|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.ActiveCfg = Release|Win32 + {002A366E-2863-46A8-BDDE-DDF534AAEC73}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal From aedefb81ec7b10d3d77522bb45e2145a79078cde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 5 Jan 2015 21:28:39 +0100 Subject: [PATCH 056/351] Adapted to cc65 assembler coding conventions Assembler statements are written in lowercase. --- libsrc/c1p/crt0.s | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/libsrc/c1p/crt0.s b/libsrc/c1p/crt0.s index 8f25c2a8d..dde348ee8 100644 --- a/libsrc/c1p/crt0.s +++ b/libsrc/c1p/crt0.s @@ -23,41 +23,41 @@ ; --------------------------------------------------------------------------- ; A little light 6502 housekeeping -_init: LDX #$FF ; Initialize stack pointer to $01FF - TXS - CLD ; Clear decimal mode +_init: ldx #$FF ; Initialize stack pointer to $01FF + txs + cld ; Clear decimal mode ; --------------------------------------------------------------------------- ; Initialize screen width ; TODO: Can initialization be done in a more idiomatic way? ; TODO: Create function for changing screen width - LDA #$18 - STA SCR_LINELEN + lda #$18 + sta SCR_LINELEN ; --------------------------------------------------------------------------- ; Set cc65 argument stack pointer - LDA #<(__RAM_START__ + __RAM_SIZE__) - STA sp - LDA #>(__RAM_START__ + __RAM_SIZE__) - STA sp+1 + lda #<(__RAM_START__ + __RAM_SIZE__) + sta sp + lda #>(__RAM_START__ + __RAM_SIZE__) + sta sp+1 ; --------------------------------------------------------------------------- ; Initialize memory storage ; copydata seems to be only necessary for special systems - JSR zerobss ; Clear BSS segment - ; JSR copydata ; Initialize DATA segment - JSR initlib ; Run constructors + jsr zerobss ; Clear BSS segment + ; jsr copydata ; Initialize DATA segment + jsr initlib ; Run constructors ; --------------------------------------------------------------------------- ; Call main() - JSR _main + jsr _main ; --------------------------------------------------------------------------- ; Back from main (this is also the _exit entry): force a software break -_exit: JSR donelib ; Run destructors - BRK +_exit: jsr donelib ; Run destructors + brk From d61feae7f8e61d02297c1b48ea93bf68bfdb31ef Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 7 Jan 2015 10:51:48 -0500 Subject: [PATCH 057/351] Added a comment. --- libsrc/atmos/tapehdr.s | 1 + 1 file changed, 1 insertion(+) diff --git a/libsrc/atmos/tapehdr.s b/libsrc/atmos/tapehdr.s index b8562eb02..b67f69d81 100644 --- a/libsrc/atmos/tapehdr.s +++ b/libsrc/atmos/tapehdr.s @@ -7,6 +7,7 @@ ; to force this module to be included into the output file. .export __TAPEHDR__:abs = 1 + ; These symbols, also, come from the configuration file. .import __BASHDR_LOAD__, __ZPSAVE_LOAD__, __AUTORUN__, __PROGFLAG__ From 22e06c41d1608ee1b4f79353b7f2b21b831de29c Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 8 Jan 2015 03:51:20 -0500 Subject: [PATCH 058/351] Fixed a bug that had padded Atmos binaries with 25 bytes too many. --- cfg/atmos.cfg | 3 ++- libsrc/atmos/crt0.s | 9 ++++++--- libsrc/atmos/tapehdr.s | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg index 691bd467d..5bb61bb26 100644 --- a/cfg/atmos.cfg +++ b/cfg/atmos.cfg @@ -23,7 +23,8 @@ SEGMENTS { RODATA: load = RAM, type = ro; INIT: load = RAM, type = ro, define = yes, optional = yes; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = rw, define = yes; + ZPSAVE1: load = RAM, type = rw, define = yes; + ZPSAVE2: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; } FEATURES { diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s index 63961bfe8..ecbc00391 100644 --- a/libsrc/atmos/crt0.s +++ b/libsrc/atmos/crt0.s @@ -2,7 +2,7 @@ ; Startup code for cc65 (Oric version) ; ; By Debrune Jérôme <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org> -; 2014-11-09, Greg King +; 2015-01-08, Greg King ; .export _exit @@ -31,7 +31,8 @@ L1: lda sp,x jsr zerobss -; Unprotect screen columns 0 and 1. +; Currently, color isn't supported on the text screen. +; Unprotect screen columns 0 and 1 (where each line's color codes would sit). lda STATUS sta stsave @@ -81,7 +82,7 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ -.segment "ZPSAVE" +.segment "ZPSAVE1" zpsave: @@ -91,6 +92,8 @@ zpsave: .byte 0 +.segment "ZPSAVE2" + .res zpspace - 1 ; ------------------------------------------------------------------------ diff --git a/libsrc/atmos/tapehdr.s b/libsrc/atmos/tapehdr.s index b67f69d81..d90c908eb 100644 --- a/libsrc/atmos/tapehdr.s +++ b/libsrc/atmos/tapehdr.s @@ -1,6 +1,6 @@ ; ; Based on code by Debrune Jérôme <jede@oric.org> -; 2013-08-15, Greg King +; 2015-01-08, Greg King ; ; The following symbol is used by the linker config. file @@ -8,7 +8,7 @@ .export __TAPEHDR__:abs = 1 ; These symbols, also, come from the configuration file. - .import __BASHDR_LOAD__, __ZPSAVE_LOAD__, __AUTORUN__, __PROGFLAG__ + .import __BASHDR_LOAD__, __ZPSAVE1_LOAD__, __AUTORUN__, __PROGFLAG__ ; ------------------------------------------------------------------------ @@ -23,7 +23,7 @@ .byte $00 ; $2AF .byte <__PROGFLAG__ ; $2AE Language flag ($00=BASIC, $80=machine code) .byte <__AUTORUN__ ; $2AD Auto-run flag ($C7=run, $00=only load) - .dbyt __ZPSAVE_LOAD__ ; $2AB Address of end of file + .dbyt __ZPSAVE1_LOAD__ ;$2AB Address of end of file .dbyt __BASHDR_LOAD__ ; $2A9 Address of start of file .byte $00 ; $2A8 From 43342366ed1bc365f9dd6918bd160b8e60dcd073 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 8 Jan 2015 17:07:28 -0500 Subject: [PATCH 059/351] Added comments that say why the ZPSAVE1 and ZPSAVE2 segments must be together. --- cfg/atmos.cfg | 4 ++-- libsrc/atmos/crt0.s | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cfg/atmos.cfg b/cfg/atmos.cfg index 5bb61bb26..a1f935efa 100644 --- a/cfg/atmos.cfg +++ b/cfg/atmos.cfg @@ -23,8 +23,8 @@ SEGMENTS { RODATA: load = RAM, type = ro; INIT: load = RAM, type = ro, define = yes, optional = yes; DATA: load = RAM, type = rw; - ZPSAVE1: load = RAM, type = rw, define = yes; - ZPSAVE2: load = RAM, type = bss; + ZPSAVE1: load = RAM, type = rw, define = yes; # ZPSAVE1, ZPSAVE2 must be together + ZPSAVE2: load = RAM, type = bss; # see "libsrc/atmos/crt0.s" BSS: load = RAM, type = bss, define = yes; } FEATURES { diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s index ecbc00391..61f40cc9a 100644 --- a/libsrc/atmos/crt0.s +++ b/libsrc/atmos/crt0.s @@ -92,6 +92,9 @@ zpsave: .byte 0 +; The segments "ZPSAVE1" and "ZPSAVE2" always must be together. +; They create a single object (the zpsave buffer). + .segment "ZPSAVE2" .res zpspace - 1 From 2ef83bd66ceb7947a79c08e1cee213de03ec96cb Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 9 Jan 2015 13:55:16 -0500 Subject: [PATCH 060/351] Mentioned, in the Atmos document, the extra byte at the end of program binaries. --- doc/atmos.sgml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/atmos.sgml b/doc/atmos.sgml index 913e50ed7..68f7f9d65 100644 --- a/doc/atmos.sgml +++ b/doc/atmos.sgml @@ -7,7 +7,7 @@ <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal">,<newline> <url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2014-12-05 +<date>2015-01-09 <abstract> An overview over the Atmos runtime system as it is implemented for the cc65 C @@ -37,9 +37,11 @@ information. The standard binary output format generated by the linker for the Atmos target is a machine language program with a one-line BASIC stub that jumps to the -machine-language part through <tt/CALL/. It has a 24-byte tape header. -It means that a file can be loaded as a BASIC program, and started with RUN. -The standard load address is $501. +machine-language part through <tt/CALL/. It has one sacrificial byte attached +to the end (a bug in the Oric ROM means that BASIC can put a variable on top +of the last byte that was loaded). It has a 24-byte tape header. A file can +be CLOADed as a BASIC program, and started by typing <tt/RUN/. The standard +load address is $501. From fccd2bf66a834bd8682720705a4b56bdfe9df001 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 9 Jan 2015 22:19:35 -0500 Subject: [PATCH 061/351] Added more info to a comment. --- libsrc/atmos/crt0.s | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s index 61f40cc9a..e789b28c2 100644 --- a/libsrc/atmos/crt0.s +++ b/libsrc/atmos/crt0.s @@ -2,7 +2,7 @@ ; Startup code for cc65 (Oric version) ; ; By Debrune Jérôme <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org> -; 2015-01-08, Greg King +; 2015-01-09, Greg King ; .export _exit @@ -89,6 +89,7 @@ zpsave: ; This padding is needed by a bug in the ROM. ; (The CLOAD command starts BASIC's variables table on top of the last byte ; that was loaded [instead of at the next address].) +; This is overlaid on a buffer, so that it doesn't use extra space in RAM. .byte 0 From b1f764bdc90d7be9a0e2f74c6aab4b0e8fdb8181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 11 Jan 2015 18:22:36 +0100 Subject: [PATCH 062/351] Minor cleanup of unnecessary newlines. --- cfg/c1p.cfg | 1 - libsrc/c1p/_scrsize.s | 1 - libsrc/c1p/cclear.s | 4 ---- libsrc/c1p/crt0.s | 1 - libsrc/c1p/ctype.s | 1 - libsrc/c1p/cvline.s | 3 --- libsrc/c1p/gotox.s | 4 ---- libsrc/c1p/gotoxy.s | 6 +++--- libsrc/c1p/gotoy.s | 2 -- 9 files changed, 3 insertions(+), 20 deletions(-) diff --git a/cfg/c1p.cfg b/cfg/c1p.cfg index 633298270..59fdd34d8 100644 --- a/cfg/c1p.cfg +++ b/cfg/c1p.cfg @@ -1,7 +1,6 @@ FEATURES { STARTADDRESS: default = $0200; } - SYMBOLS { __STACKSIZE__: type = weak, value = $0400; # 1 kB stack __HIMEM__: type = weak, value = $8000; # 32 kB RAM diff --git a/libsrc/c1p/_scrsize.s b/libsrc/c1p/_scrsize.s index 75de2b349..3b0d71c2f 100644 --- a/libsrc/c1p/_scrsize.s +++ b/libsrc/c1p/_scrsize.s @@ -19,4 +19,3 @@ rts .endproc - diff --git a/libsrc/c1p/cclear.s b/libsrc/c1p/cclear.s index 4412f0bba..4e18c70a3 100644 --- a/libsrc/c1p/cclear.s +++ b/libsrc/c1p/cclear.s @@ -27,7 +27,3 @@ L1: lda #$20 ; Blank - screen code dec tmp1 bne L1 L9: rts - - - - diff --git a/libsrc/c1p/crt0.s b/libsrc/c1p/crt0.s index dde348ee8..908943e91 100644 --- a/libsrc/c1p/crt0.s +++ b/libsrc/c1p/crt0.s @@ -60,4 +60,3 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF _exit: jsr donelib ; Run destructors brk - diff --git a/libsrc/c1p/ctype.s b/libsrc/c1p/ctype.s index dd7ac62c3..fa901c189 100644 --- a/libsrc/c1p/ctype.s +++ b/libsrc/c1p/ctype.s @@ -287,4 +287,3 @@ __ctype: .byte $00 ; 253/fd _y'_acute__ .byte $00 ; 254/fe _sm_thorn__ .byte $00 ; 255/ff _y"_dieres_ - diff --git a/libsrc/c1p/cvline.s b/libsrc/c1p/cvline.s index 607a4c691..c485918ee 100644 --- a/libsrc/c1p/cvline.s +++ b/libsrc/c1p/cvline.s @@ -27,6 +27,3 @@ L1: lda #$95 ; Vertical bar dec tmp1 bne L1 L9: rts - - - diff --git a/libsrc/c1p/gotox.s b/libsrc/c1p/gotox.s index 315e1b5ee..fb84975d1 100644 --- a/libsrc/c1p/gotox.s +++ b/libsrc/c1p/gotox.s @@ -5,13 +5,9 @@ ; ; void gotox (unsigned char x); ; - .export _gotox .import plot .importzp CURS_X _gotox: sta CURS_X ; Set new position jmp plot ; And activate it - - - diff --git a/libsrc/c1p/gotoxy.s b/libsrc/c1p/gotoxy.s index 64c6bd21d..32d1f1df2 100644 --- a/libsrc/c1p/gotoxy.s +++ b/libsrc/c1p/gotoxy.s @@ -1,9 +1,11 @@ ; +; copied from CBM implementation +; +; originally by: ; Ullrich von Bassewitz, 06.08.1998 ; ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy .import popa, plot .importzp CURS_X, CURS_Y @@ -13,5 +15,3 @@ _gotoxy: jsr popa ; Get X sta CURS_X ; Set X jmp plot ; Set the cursor position - - diff --git a/libsrc/c1p/gotoy.s b/libsrc/c1p/gotoy.s index e9e81451a..fcd60dd31 100644 --- a/libsrc/c1p/gotoy.s +++ b/libsrc/c1p/gotoy.s @@ -5,11 +5,9 @@ ; ; void gotoy (unsigned char y); ; - .export _gotoy .import plot .importzp CURS_Y _gotoy: sta CURS_Y ; Set the new position jmp plot ; And activate it - From d3b2b3df6b9fc37d62d8138b5b9a5af251030227 Mon Sep 17 00:00:00 2001 From: Wayne LaBelle <wylab@wylab.com> Date: Sun, 11 Jan 2015 16:10:34 -0500 Subject: [PATCH 063/351] Move SBC to correct location in 6280 instruction table --- src/ca65/instr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ca65/instr.c b/src/ca65/instr.c index 6acf8c94f..500db1985 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -713,9 +713,9 @@ static const struct { { "ROR", 0x000006F, 0x62, 1, PutAll }, { "RTI", 0x0000001, 0x40, 0, PutAll }, { "RTS", 0x0000001, 0x60, 0, PutAll }, - { "SBC", 0x080A66C, 0xe0, 0, PutAll }, { "SAX", 0x0000001, 0x22, 0, PutAll }, { "SAY", 0x0000001, 0x42, 0, PutAll }, + { "SBC", 0x080A66C, 0xe0, 0, PutAll }, { "SEC", 0x0000001, 0x38, 0, PutAll }, { "SED", 0x0000001, 0xf8, 0, PutAll }, { "SEI", 0x0000001, 0x78, 0, PutAll }, From a0c4ca9bd76c6c2b35863c5cbe846436a58f06c3 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Tue, 20 Jan 2015 21:00:44 +0100 Subject: [PATCH 064/351] Fixed file name of Windows binary snapshot. Although we're using Mingw-w64 to build the Windows binaries they are in fact 32-bit binaries - which is just fine. However the file name should reflect that. --- Makefile.travis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.travis b/Makefile.travis index 78ded63e6..4c0f688f8 100644 --- a/Makefile.travis +++ b/Makefile.travis @@ -24,7 +24,7 @@ endif SF_USER = oliverschmidt SF_HOST = frs.sourceforge.net -SF_FILE = /home/frs/project/cc65/cc65-snapshot-win64.zip +SF_FILE = /home/frs/project/cc65/cc65-snapshot-win32.zip SCPFLAGS = -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -q From 19b3c1b32bc8a3f5a17d8b389192afbc73e35143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 31 Jan 2015 22:45:18 +0100 Subject: [PATCH 065/351] Configuration file for assembler-only build. --- cfg/c1p-asm.cfg | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 cfg/c1p-asm.cfg diff --git a/cfg/c1p-asm.cfg b/cfg/c1p-asm.cfg new file mode 100644 index 000000000..57689b96d --- /dev/null +++ b/cfg/c1p-asm.cfg @@ -0,0 +1,20 @@ +FEATURES { + STARTADDRESS: default = $0200; +} +SYMBOLS { + __STACKSIZE__: type = weak, value = $0400; # 1 kB stack + __HIMEM__: type = weak, value = $8000; # 32 kB RAM +} +MEMORY { + # for size of ZP see runtime/zeropage.s and c1p/extzp.s + ZP: file = "", define = yes, start = $0002, size = $001A + $0006; + RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; +} +SEGMENTS { + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = rw; + RODATA: load = RAM, type = rw; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; +} \ No newline at end of file From 14c7e9fd1646ca07ee9c5abe1c23a85abba1df4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Tue, 3 Feb 2015 22:42:35 +0100 Subject: [PATCH 066/351] Rename c1p target to osic1p --- cfg/{c1p-asm.cfg => osic1p-asm.cfg} | 0 cfg/{c1p.cfg => osic1p.cfg} | 0 include/conio.h | 2 +- include/{c1p.h => osic1p.h} | 8 +- libsrc/Makefile | 2 +- libsrc/{c1p => osic1p}/_scrsize.s | 0 libsrc/{c1p => osic1p}/cclear.s | 0 libsrc/{c1p => osic1p}/cgetc.s | 2 +- libsrc/{c1p => osic1p}/chline.s | 0 libsrc/{c1p => osic1p}/clrscr.s | 2 +- libsrc/{c1p => osic1p}/cputc.s | 2 +- libsrc/{c1p => osic1p}/crt0.s | 0 libsrc/{c1p => osic1p}/ctype.s | 0 libsrc/{c1p => osic1p}/cvline.s | 0 libsrc/{c1p => osic1p}/extzp.inc | 0 libsrc/{c1p => osic1p}/extzp.s | 2 +- libsrc/{c1p => osic1p}/gotox.s | 0 libsrc/{c1p => osic1p}/gotoxy.s | 0 libsrc/{c1p => osic1p}/gotoy.s | 0 libsrc/{c1p => osic1p}/oserror.s | 0 libsrc/{c1p/c1p.inc => osic1p/osic1p.inc} | 0 libsrc/{c1p => osic1p}/wherex.s | 0 libsrc/{c1p => osic1p}/wherey.s | 0 src/c1p65.vcxproj | 94 ----------------------- src/ca65/main.c | 2 +- src/cc65/main.c | 2 +- src/common/target.c | 6 +- src/common/target.h | 6 +- 28 files changed, 18 insertions(+), 112 deletions(-) rename cfg/{c1p-asm.cfg => osic1p-asm.cfg} (100%) rename cfg/{c1p.cfg => osic1p.cfg} (100%) rename include/{c1p.h => osic1p.h} (92%) rename libsrc/{c1p => osic1p}/_scrsize.s (100%) rename libsrc/{c1p => osic1p}/cclear.s (100%) rename libsrc/{c1p => osic1p}/cgetc.s (93%) rename libsrc/{c1p => osic1p}/chline.s (100%) rename libsrc/{c1p => osic1p}/clrscr.s (91%) rename libsrc/{c1p => osic1p}/cputc.s (98%) rename libsrc/{c1p => osic1p}/crt0.s (100%) rename libsrc/{c1p => osic1p}/ctype.s (100%) rename libsrc/{c1p => osic1p}/cvline.s (100%) rename libsrc/{c1p => osic1p}/extzp.inc (100%) rename libsrc/{c1p => osic1p}/extzp.s (89%) rename libsrc/{c1p => osic1p}/gotox.s (100%) rename libsrc/{c1p => osic1p}/gotoxy.s (100%) rename libsrc/{c1p => osic1p}/gotoy.s (100%) rename libsrc/{c1p => osic1p}/oserror.s (100%) rename libsrc/{c1p/c1p.inc => osic1p/osic1p.inc} (100%) rename libsrc/{c1p => osic1p}/wherex.s (100%) rename libsrc/{c1p => osic1p}/wherey.s (100%) delete mode 100644 src/c1p65.vcxproj diff --git a/cfg/c1p-asm.cfg b/cfg/osic1p-asm.cfg similarity index 100% rename from cfg/c1p-asm.cfg rename to cfg/osic1p-asm.cfg diff --git a/cfg/c1p.cfg b/cfg/osic1p.cfg similarity index 100% rename from cfg/c1p.cfg rename to cfg/osic1p.cfg diff --git a/include/conio.h b/include/conio.h index f59375a63..10806785c 100644 --- a/include/conio.h +++ b/include/conio.h @@ -78,7 +78,7 @@ #elif defined(__NES__) # include <nes.h> #elif defined(__OSIC1P__) -# include <c1p.h> +# include <osic1p.h> #endif diff --git a/include/c1p.h b/include/osic1p.h similarity index 92% rename from include/c1p.h rename to include/osic1p.h index 5789d7156..57fe0cd24 100644 --- a/include/c1p.h +++ b/include/osic1p.h @@ -1,12 +1,12 @@ /*****************************************************************************/ /* */ -/* c1p.h */ +/* osic1p.h */ /* */ /* Challenger 1P system specific definitions */ /* */ /* */ /* */ -/* (C) 2014 Stephan Muehlstrasser */ +/* (C) 2015 Stephan Muehlstrasser */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -28,8 +28,8 @@ /* */ /*****************************************************************************/ -#ifndef _C1P_H -#define _C1P_H +#ifndef _OSIC1P_H +#define _OSIC1P_H /* Check for errors */ #if !defined(__OSIC1P__) diff --git a/libsrc/Makefile b/libsrc/Makefile index b35ae1e38..42aaf078b 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -20,11 +20,11 @@ TARGETS = apple2 \ atarixl \ atari5200 \ atmos \ - c1p \ $(CBMS) \ $(GEOS) \ lynx \ nes \ + osic1p \ sim6502 \ sim65c02 \ supervision diff --git a/libsrc/c1p/_scrsize.s b/libsrc/osic1p/_scrsize.s similarity index 100% rename from libsrc/c1p/_scrsize.s rename to libsrc/osic1p/_scrsize.s diff --git a/libsrc/c1p/cclear.s b/libsrc/osic1p/cclear.s similarity index 100% rename from libsrc/c1p/cclear.s rename to libsrc/osic1p/cclear.s diff --git a/libsrc/c1p/cgetc.s b/libsrc/osic1p/cgetc.s similarity index 93% rename from libsrc/c1p/cgetc.s rename to libsrc/osic1p/cgetc.s index b17e76572..b5a519667 100644 --- a/libsrc/c1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -4,7 +4,7 @@ .export _cgetc .import cursor - .include "c1p.inc" + .include "osic1p.inc" .include "extzp.inc" ; Input routine from 65V PROM MONITOR, show cursor if enabled diff --git a/libsrc/c1p/chline.s b/libsrc/osic1p/chline.s similarity index 100% rename from libsrc/c1p/chline.s rename to libsrc/osic1p/chline.s diff --git a/libsrc/c1p/clrscr.s b/libsrc/osic1p/clrscr.s similarity index 91% rename from libsrc/c1p/clrscr.s rename to libsrc/osic1p/clrscr.s index ce221f31e..32975526f 100644 --- a/libsrc/c1p/clrscr.s +++ b/libsrc/osic1p/clrscr.s @@ -4,7 +4,7 @@ .export _clrscr .import plot .importzp CURS_X, CURS_Y - .include "c1p.inc" + .include "osic1p.inc" ; Adapted from the Challenger Character Graphics ; Reference Manual, "2.3.3 MACHINE LANGUAGE SCREEN CLEAR" diff --git a/libsrc/c1p/cputc.s b/libsrc/osic1p/cputc.s similarity index 98% rename from libsrc/c1p/cputc.s rename to libsrc/osic1p/cputc.s index ca9152aa7..d343da951 100644 --- a/libsrc/c1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -9,7 +9,7 @@ .export newline, plot .import popa, _gotoxy - .include "c1p.inc" + .include "osic1p.inc" .include "extzp.inc" _cputcxy: diff --git a/libsrc/c1p/crt0.s b/libsrc/osic1p/crt0.s similarity index 100% rename from libsrc/c1p/crt0.s rename to libsrc/osic1p/crt0.s diff --git a/libsrc/c1p/ctype.s b/libsrc/osic1p/ctype.s similarity index 100% rename from libsrc/c1p/ctype.s rename to libsrc/osic1p/ctype.s diff --git a/libsrc/c1p/cvline.s b/libsrc/osic1p/cvline.s similarity index 100% rename from libsrc/c1p/cvline.s rename to libsrc/osic1p/cvline.s diff --git a/libsrc/c1p/extzp.inc b/libsrc/osic1p/extzp.inc similarity index 100% rename from libsrc/c1p/extzp.inc rename to libsrc/osic1p/extzp.inc diff --git a/libsrc/c1p/extzp.s b/libsrc/osic1p/extzp.s similarity index 89% rename from libsrc/c1p/extzp.s rename to libsrc/osic1p/extzp.s index c55156f82..dfa84a61c 100644 --- a/libsrc/c1p/extzp.s +++ b/libsrc/osic1p/extzp.s @@ -18,4 +18,4 @@ SCR_LINELEN: .byte 24 SCREEN_PTR: .res 2 ; size 6 -; Adjust size of this segment in c1p.cfg if the size changes +; Adjust size of this segment in osic1p.cfg if the size changes diff --git a/libsrc/c1p/gotox.s b/libsrc/osic1p/gotox.s similarity index 100% rename from libsrc/c1p/gotox.s rename to libsrc/osic1p/gotox.s diff --git a/libsrc/c1p/gotoxy.s b/libsrc/osic1p/gotoxy.s similarity index 100% rename from libsrc/c1p/gotoxy.s rename to libsrc/osic1p/gotoxy.s diff --git a/libsrc/c1p/gotoy.s b/libsrc/osic1p/gotoy.s similarity index 100% rename from libsrc/c1p/gotoy.s rename to libsrc/osic1p/gotoy.s diff --git a/libsrc/c1p/oserror.s b/libsrc/osic1p/oserror.s similarity index 100% rename from libsrc/c1p/oserror.s rename to libsrc/osic1p/oserror.s diff --git a/libsrc/c1p/c1p.inc b/libsrc/osic1p/osic1p.inc similarity index 100% rename from libsrc/c1p/c1p.inc rename to libsrc/osic1p/osic1p.inc diff --git a/libsrc/c1p/wherex.s b/libsrc/osic1p/wherex.s similarity index 100% rename from libsrc/c1p/wherex.s rename to libsrc/osic1p/wherex.s diff --git a/libsrc/c1p/wherey.s b/libsrc/osic1p/wherey.s similarity index 100% rename from libsrc/c1p/wherey.s rename to libsrc/osic1p/wherey.s diff --git a/src/c1p65.vcxproj b/src/c1p65.vcxproj deleted file mode 100644 index dcc8f9926..000000000 --- a/src/c1p65.vcxproj +++ /dev/null @@ -1,94 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|Win32"> - <Configuration>Debug</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|Win32"> - <Configuration>Release</Configuration> - <Platform>Win32</Platform> - </ProjectConfiguration> - </ItemGroup> - <ItemGroup> - <ClCompile Include="c1p65\main.c" /> - </ItemGroup> - <PropertyGroup Label="Globals"> - <ProjectGuid>{4E031DE0-82B4-4204-8529-536626F7E0DF}</ProjectGuid> - <Keyword>Win32Proj</Keyword> - <RootNamespace>c1p65</RootNamespace> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v120</PlatformToolset> - <CharacterSet> - </CharacterSet> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <PlatformToolset>v120</PlatformToolset> - <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet> - </CharacterSet> - </PropertyGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <ImportGroup Label="ExtensionSettings"> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <PropertyGroup Label="UserMacros" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <LinkIncremental>true</LinkIncremental> - <OutDir>$(SolutionDir)..\bin\</OutDir> - <IntDir>$(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\</IntDir> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <LinkIncremental>false</LinkIncremental> - <OutDir>$(SolutionDir)..\bin\</OutDir> - <IntDir>$(SolutionDir)..\wrk\$(ProjectName)\$(Configuration)\</IntDir> - </PropertyGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> - <ClCompile> - <PrecompiledHeader> - </PrecompiledHeader> - <WarningLevel>Level3</WarningLevel> - <Optimization>Disabled</Optimization> - <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>common</AdditionalIncludeDirectories> - </ClCompile> - <Link> - <SubSystem>Console</SubSystem> - <GenerateDebugInformation>true</GenerateDebugInformation> - <AdditionalDependencies>$(IntDir)..\..\common\$(Configuration)\common.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <ClCompile> - <WarningLevel>Level3</WarningLevel> - <PrecompiledHeader> - </PrecompiledHeader> - <Optimization>MaxSpeed</Optimization> - <FunctionLevelLinking>true</FunctionLevelLinking> - <IntrinsicFunctions>true</IntrinsicFunctions> - <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>common</AdditionalIncludeDirectories> - </ClCompile> - <Link> - <SubSystem>Console</SubSystem> - <GenerateDebugInformation>true</GenerateDebugInformation> - <EnableCOMDATFolding>true</EnableCOMDATFolding> - <OptimizeReferences>true</OptimizeReferences> - <AdditionalDependencies>$(IntDir)..\..\common\$(Configuration)\common.lib</AdditionalDependencies> - </Link> - </ItemDefinitionGroup> - <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> - <ImportGroup Label="ExtensionTargets"> - </ImportGroup> -</Project> \ No newline at end of file diff --git a/src/ca65/main.c b/src/ca65/main.c index 50878f47a..508f49603 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -303,7 +303,7 @@ static void SetSys (const char* Sys) NewSymbol ("__SIM65C02__", 1); break; - case TGT_C1P: + case TGT_OSIC1P: NewSymbol ("__OSIC1P__", 1); break; diff --git a/src/cc65/main.c b/src/cc65/main.c index b8963258d..ece22041a 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -258,7 +258,7 @@ static void SetSys (const char* Sys) DefineNumericMacro ("__SIM65C02__", 1); break; - case TGT_C1P: + case TGT_OSIC1P: DefineNumericMacro ("__OSIC1P__", 1); break; diff --git a/src/common/target.c b/src/common/target.c index b909e4d70..0b44ffa30 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -131,7 +131,6 @@ static const TargetEntry TargetMap[] = { { "bbc", TGT_BBC }, { "c128", TGT_C128 }, { "c16", TGT_C16 }, - { "c1p", TGT_C1P }, { "c64", TGT_C64 }, { "cbm510", TGT_CBM510 }, { "cbm610", TGT_CBM610 }, @@ -143,6 +142,7 @@ static const TargetEntry TargetMap[] = { { "module", TGT_MODULE }, { "nes", TGT_NES }, { "none", TGT_NONE }, + { "osic1p", TGT_OSIC1P }, { "pet", TGT_PET }, { "plus4", TGT_PLUS4 }, { "sim6502", TGT_SIM6502 }, @@ -163,12 +163,12 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "atarixl", CPU_6502, BINFMT_BINARY, CTAtari }, { "vic20", CPU_6502, BINFMT_BINARY, CTPET }, { "c16", CPU_6502, BINFMT_BINARY, CTPET }, - { "c1p", CPU_6502, BINFMT_BINARY, CTNone }, { "c64", CPU_6502, BINFMT_BINARY, CTPET }, { "c128", CPU_6502, BINFMT_BINARY, CTPET }, { "plus4", CPU_6502, BINFMT_BINARY, CTPET }, { "cbm510", CPU_6502, BINFMT_BINARY, CTPET }, { "cbm610", CPU_6502, BINFMT_BINARY, CTPET }, + { "osic1p", CPU_6502, BINFMT_BINARY, CTNone }, { "pet", CPU_6502, BINFMT_BINARY, CTPET }, { "bbc", CPU_6502, BINFMT_BINARY, CTNone }, { "apple2", CPU_6502, BINFMT_BINARY, CTNone }, @@ -201,7 +201,7 @@ static int Compare (const void* Key, const void* Entry) return strcmp ((const char*) Key, ((const TargetEntry*)Entry)->Name); } - +#include <stdio.h> target_t FindTarget (const char* Name) /* Find a target by name and return the target id. TGT_UNKNOWN is returned if diff --git a/src/common/target.h b/src/common/target.h index 067352deb..edce36fa5 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -59,13 +59,13 @@ typedef enum { TGT_ATARIXL, TGT_VIC20, TGT_C16, - TGT_C1P, TGT_C64, TGT_C128, TGT_PLUS4, TGT_CBM510, TGT_CBM610, - TGT_PET, + TGT_OSIC1P, + TGT_PET, TGT_BBC, TGT_APPLE2, TGT_APPLE2ENH, @@ -76,7 +76,7 @@ typedef enum { TGT_NES, TGT_SUPERVISION, TGT_LYNX, - TGT_SIM6502, + TGT_SIM6502, TGT_SIM65C02, TGT_COUNT /* Number of target systems */ } target_t; From 01b0e10fc35e66e170791c2525f93c7b20dd8cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Tue, 3 Feb 2015 22:56:04 +0100 Subject: [PATCH 067/351] Remove tab character. --- src/common/target.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/target.c b/src/common/target.c index 0b44ffa30..24734f196 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -168,7 +168,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "plus4", CPU_6502, BINFMT_BINARY, CTPET }, { "cbm510", CPU_6502, BINFMT_BINARY, CTPET }, { "cbm610", CPU_6502, BINFMT_BINARY, CTPET }, - { "osic1p", CPU_6502, BINFMT_BINARY, CTNone }, + { "osic1p", CPU_6502, BINFMT_BINARY, CTNone }, { "pet", CPU_6502, BINFMT_BINARY, CTPET }, { "bbc", CPU_6502, BINFMT_BINARY, CTNone }, { "apple2", CPU_6502, BINFMT_BINARY, CTNone }, From 072e5e71c2ce377ef448f138b1a03737dfe83f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 5 Feb 2015 23:01:19 +0100 Subject: [PATCH 068/351] Video RAM mapping table was off by two bytes. Fix contributed by Jeff Tranter. --- libsrc/osic1p/cputc.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index d343da951..9cea78789 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -70,10 +70,10 @@ putchar: .rodata -ScrLo: .byte $83, $A3, $C3, $E3, $03, $23, $43, $63 - .byte $83, $A3, $C3, $E3, $03, $23, $43, $63 - .byte $83, $A3, $C3, $E3, $03, $23, $43, $63 - .byte $83 +ScrLo: .byte $85, $A5, $C5, $E5, $05, $25, $45, $65 + .byte $85, $A5, $C5, $E5, $05, $25, $45, $65 + .byte $85, $A5, $C5, $E5, $05, $25, $45, $65 + .byte $85 ScrHi: .byte $D0, $D0, $D0, $D0, $D1, $D1, $D1, $D1 .byte $D1, $D1, $D1, $D1, $D2, $D2, $D2, $D2 From 7754c573d8b901f5b904a50dc848edd58e4ff4a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 5 Feb 2015 23:21:59 +0100 Subject: [PATCH 069/351] Jump to boot prompt after main program exits. --- libsrc/osic1p/crt0.s | 3 ++- libsrc/osic1p/osic1p.inc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/osic1p/crt0.s b/libsrc/osic1p/crt0.s index 908943e91..447b65c56 100644 --- a/libsrc/osic1p/crt0.s +++ b/libsrc/osic1p/crt0.s @@ -14,6 +14,7 @@ .include "zeropage.inc" .include "extzp.inc" +.include "osic1p.inc" ; --------------------------------------------------------------------------- ; Place the startup code in a special segment @@ -59,4 +60,4 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF ; Back from main (this is also the _exit entry): force a software break _exit: jsr donelib ; Run destructors - brk + jmp RESET ; Display boot menu after program exit diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index ad058373a..4ad0e038b 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -2,3 +2,4 @@ SCRNBASE := $D000 ; Base of video RAM VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) INPUTC := $FD00 ; Input character from keyboard +RESET := $FF00 ; Reset address, show boot prompt \ No newline at end of file From 680c62d589932bb342cd5fe9d0969501133d2efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Fri, 6 Feb 2015 22:53:36 +0100 Subject: [PATCH 070/351] Start documentation for Ohio Scientific targets. --- doc/index.sgml | 3 + doc/osi.sgml | 154 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 doc/osi.sgml diff --git a/doc/index.sgml b/doc/index.sgml index 7de8b26ce..921b8c03d 100644 --- a/doc/index.sgml +++ b/doc/index.sgml @@ -134,6 +134,9 @@ <tag><htmlurl url="nes.html" name="nes.html"></tag> Topics specific to the Nintendo Entertainment System. + <tag><htmlurl url="osi.html" name="osi.html"></tag> + Topics specific to the Ohio Scientific machines. + <tag><htmlurl url="pet.html" name="pet.html"></tag> Topics specific to the Commodore PET machines. diff --git a/doc/osi.sgml b/doc/osi.sgml new file mode 100644 index 000000000..c46a2a742 --- /dev/null +++ b/doc/osi.sgml @@ -0,0 +1,154 @@ +<!doctype linuxdoc system> + +<article> + +<title>Ohio Scientific-specific information for cc65 +<author> +<url url="mailto:stephan.muehlstrasser@web.de" name="Stephan Mühlstrasser"><newline> +<date>2015-02-04 + +<abstract> +An overview over the Ohio Scientific runtime system as it is implemented for the cc65 C +compiler. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + +<sect>Overview<p> + +This file contains an overview of the Ohio Scientific runtime system as it comes with the +cc65 C compiler. It describes the memory layout, Ohio Scientific-specific header files, +and any pitfalls specific to that platform. + +Please note that Ohio Scientific-specific functions are just mentioned here, they are +described in detail in the separate <url url="funcref.html" name="function +reference">. Even functions marked as "platform dependent" may be available on +more than one platform. Please see the function reference for more +information. + +<sect>Targets<p> + +Currently the target "osic1p" is implemented. This works for the Ohio Scientific +Challenger 1P machine. + +<sect>Binary format<p> + +The standard binary output format generated by the linker for the osic1p target +is a machine language program.<p> + +For uploading into a real machine over the serial port or into an emulator a +program must be converted to a text file that is understood by the 65V PROM +monitor. For this purpose the srec_cat program from the +<url url="http://srecord.sourceforge.net/" name="SRecord"> tool collection can be used. + +Care must be taken that the -offset and -execution-start-address options for the srec_cat +program correspond to the start address of the executable. + +Example for converting an executable "hello" that was built for the default +start address $0200 to an uploadable file "hello.c1p": + +<tscreen> +srec_cat hello -binary -offset 0x200 -o hello.c1p -Ohio_Scientific -execution-start-address=0x200 +</tscreen> + +<sect>Memory layout<p> + +By default programs compiled for the osic1p target are configured for 32 kB RAM. +The RAM size can be configured via the symbol __HIMEM__. + +Special locations: + +<descrip> + <tag/Program start address/ + The default start address is $0200. The start address is configurable + via the compiler option --start-addr. + + <tag/Stack/ + The C runtime stack is located at the top of RAM and growing downwards. + The size is configurable via the symbol __STACKSIZE__. The default + stack size is $0400. + + <tag/Heap/ + The C heap is located at the end of the program and grows towards the C + runtime stack. + + <tag/Video RAM/ + The 1 kB video RAM is located at $D000. On the monitor only a subset + of the available video RAM is visible. The address of the upper left corner + of the visible area is $dollar;D085 and corresponds to conio cursor + position (0, 0). + +</descrip><p> + +Example for building a program with start address $0300, stack size +$0200 and RAM size $0200: + +<tscreen> +cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0300 -t osic1p hello.c +</tscreen> + +<sect>Platform-specific header files<p> + +Programs containing PET-specific code may use the <tt/pet.h/ or <tt/cbm.h/ +header files. + + +<sect1>PET-specific functions<p> + +There are currently no special Ohio Scientific functions. + +<sect1>Hardware access<p> + +There is no specific support for direct hardware access. + +<sect>Loadable drivers<p> + +There are no loadable drivers available. + +<sect>Limitations<p> + +<sect1>conio implementation<p> + +The conio implementation is complete except for the kbhit() function. A +call to cgetc() always blocks until a character is entered. + +<sect1>stdio implementation<p> + +There is no support for stdio at the moment. + +<sect>Other hints<p> + +<sect1>Passing arguments to the program<p> + +There is currently no support for passing arguments to a program. + +<sect1>Program return code<p> + +The program return code currently has no effect. When the main() function +finishes, the boot prompt is shown again. + +<sect>License<p> + +This software is provided 'as-is', without any expressed or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +<enum> +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> From 04469be331b754f91af7e0d3e46f569a2009b194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 7 Feb 2015 00:20:38 +0100 Subject: [PATCH 071/351] Minor corrections to documentation. --- doc/osi.sgml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/osi.sgml b/doc/osi.sgml index c46a2a742..7f6920489 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -42,7 +42,7 @@ is a machine language program.<p> For uploading into a real machine over the serial port or into an emulator a program must be converted to a text file that is understood by the 65V PROM monitor. For this purpose the srec_cat program from the -<url url="http://srecord.sourceforge.net/" name="SRecord"> tool collection can be used. +SRecord (http://srecord.sourceforge.net/) tool collection can be used. Care must be taken that the -offset and -execution-start-address options for the srec_cat program correspond to the start address of the executable. @@ -92,11 +92,11 @@ cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0300 -t osic1p <sect>Platform-specific header files<p> -Programs containing PET-specific code may use the <tt/pet.h/ or <tt/cbm.h/ -header files. +Programs containing Ohio Scientific-specific code may use the <tt/osic1p.h/ +header file. -<sect1>PET-specific functions<p> +<sect1>Ohio Scientific-specific functions<p> There are currently no special Ohio Scientific functions. From 88249a2125ca07353740337266a4155ca241c39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 7 Feb 2015 01:19:03 +0100 Subject: [PATCH 072/351] Fixed URL for SRecord. --- doc/osi.sgml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/osi.sgml b/doc/osi.sgml index 7f6920489..85d4dca44 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -42,7 +42,8 @@ is a machine language program.<p> For uploading into a real machine over the serial port or into an emulator a program must be converted to a text file that is understood by the 65V PROM monitor. For this purpose the srec_cat program from the -SRecord (http://srecord.sourceforge.net/) tool collection can be used. +<url url="http://srecord.sourceforge.net/" name="SRecord"> +tool collection can be used. Care must be taken that the -offset and -execution-start-address options for the srec_cat program correspond to the start address of the executable. From da8ec4f7b1c295bc112f75b246d4432fff0d1b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 8 Feb 2015 15:06:55 +0100 Subject: [PATCH 073/351] Completing OSI documentation. --- doc/intro.sgml | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ doc/osi.sgml | 30 ++++++++++++++++++++-- 2 files changed, 97 insertions(+), 2 deletions(-) diff --git a/doc/intro.sgml b/doc/intro.sgml index 02c5c83d5..5ffef7e69 100644 --- a/doc/intro.sgml +++ b/doc/intro.sgml @@ -513,6 +513,75 @@ directory notePad. Look at the eight file-positions on each page until you see The output is shown in a GEOS dialog box; click <bf/OK/ when you have finished reading it. +<sect1>Ohio Scientific Challenger 1P<p> +Available at <url url="http://www.pcjs.org/docs/c1pjs/" name="C1Pjs">: + +Emulates the Ohio Scientific Challenger 1P computer in different configurations. +The 32 kb RAM machine that must be used with the default compiler settings is +<url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="here">. + +In addition the srec_cat program from the +<url url="http://srecord.sourceforge.net/" name="SRecord"> +tool collection must be installed. Some Linux distributions also provide the +srecord package that can be installed directly from the distribution's +repository. + +The osic1p runtime library directly returns to the boot prompt when the +main() program exits. Therefore the C file in the tutorial must be slightly +modified in order to see the results on the screen. Otherwise the program +would print the text string and then jump to the boot prompt, making it +impossible to see the results of running the tutorial program. + +In addition to that the cc65 target does not yet have support for stdio +functions. Only the functions from the conio library are available. + +Therefore modify the main() function in hello.c as follows: + +<tscreen> +#include <conio.h> +#include <stdlib.h> + +extern const char text[]; /* In text.s */ + +int main (void) +{ + clrscr(); + cprintf ("%s\r\nPress <RETURN>\r\n", text); + cgetc(); + return EXIT_SUCCESS; +} +</tscreen> + +Compile the tutorial with + +<tscreen><verb> +cl65 -O -t osic1p hello.c text.s +</verb></tscreen> + +Convert the executable file into a text file that can be loaded via +the Ohio Scientific 65V PROM monitor at start address 0x200: + +<tscreen><verb> +srec_cat hello -binary -offset 0x200 -o hello.c1p -Ohio_Scientific -execution-start-address=0x200 +</verb></tscreen> + +Open the URL <url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="http://www.pcjs.org/devices/c1p/machine/32kb/"> +in your browser and wait until the emulator is loaded. Click on the BREAK +button to display the boot prompt, then press the M key to enter the +65V PROM monitor. Press the "Choose File" button and select the hello.c1p +that was created as the output of the above invocation of the srec_cat +command. Press the "Load" button. You should see the following text on the +screen: + +<tscreen><verb> +Hello world! +Press <RETURN> +</verb></tscreen> + +After hitting the RETURN key you should see the boot prompt again. + +The program can also be uploaded over the serial port to a real Challenger 1P +computer. <sect1>Contributions wanted<p> diff --git a/doc/osi.sgml b/doc/osi.sgml index 85d4dca44..7152f2815 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -79,7 +79,7 @@ Special locations: <tag/Video RAM/ The 1 kB video RAM is located at $D000. On the monitor only a subset of the available video RAM is visible. The address of the upper left corner - of the visible area is $dollar;D085 and corresponds to conio cursor + of the visible area is $D085 and corresponds to conio cursor position (0, 0). </descrip><p> @@ -91,12 +91,38 @@ Example for building a program with start address $0300, stack size cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0300 -t osic1p hello.c </tscreen> +<sect>Linker configurations<p> + +The ld65 linker comes with a default config file "osic1p.cfg" for the Ohio Scientific +Challenger 1P, which is implicitly used via <tt/-t osic1p/. The +osic1p package comes with additional secondary linker config files, which are +used via <tt/-t osic1p -C <configfile>/. + +<sect1>default config file (<tt/osic1p.cfg/)<p> + +The default configuration is tailored to C programs. + +<sect1><tt/osic1p-asm.cfg/<p> + +This configuration is made for assembler programmers who don't need a special +setup. + +To use this config file, assemble with <tt/-t osic1p/ and link with +<tt/-C osic1p-asm.cfg/. The former will make sure that correct runtime library +is used, while the latter supplies the actual config. When using <tt/cl65/, +use both command line options. + +Sample command line for <tt/cl65/: + +<tscreen><verb> +cl65 -o program -t osic1p -C osic1p-asm.cfg source.s +</verb></tscreen> + <sect>Platform-specific header files<p> Programs containing Ohio Scientific-specific code may use the <tt/osic1p.h/ header file. - <sect1>Ohio Scientific-specific functions<p> There are currently no special Ohio Scientific functions. From a1cc85768e95cb6d775cb9003e30d5e027277946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 8 Feb 2015 15:46:33 +0100 Subject: [PATCH 074/351] Minor corrections. --- doc/intro.sgml | 30 +++++++++++++++--------------- doc/osi.sgml | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/doc/intro.sgml b/doc/intro.sgml index 5ffef7e69..41f359278 100644 --- a/doc/intro.sgml +++ b/doc/intro.sgml @@ -520,24 +520,23 @@ Emulates the Ohio Scientific Challenger 1P computer in different configurations. The 32 kb RAM machine that must be used with the default compiler settings is <url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="here">. -In addition the srec_cat program from the +In addition to cc65 the srec_cat program from the <url url="http://srecord.sourceforge.net/" name="SRecord"> tool collection must be installed. Some Linux distributions also provide the -srecord package that can be installed directly from the distribution's -repository. +srecord package directly as an installable package. -The osic1p runtime library directly returns to the boot prompt when the +The osic1p runtime library returns to the boot prompt when the main() program exits. Therefore the C file in the tutorial must be slightly modified in order to see the results on the screen. Otherwise the program would print the text string and then jump to the boot prompt, making it impossible to see the results of running the tutorial program. -In addition to that the cc65 target does not yet have support for stdio +In addition to that the osic1p target does not yet have support for stdio functions. Only the functions from the conio library are available. -Therefore modify the main() function in hello.c as follows: +Therefore modify the hello.c source file as follows: -<tscreen> +<tscreen><code> #include <conio.h> #include <stdlib.h> @@ -545,12 +544,12 @@ extern const char text[]; /* In text.s */ int main (void) { - clrscr(); + clrscr (); cprintf ("%s\r\nPress <RETURN>\r\n", text); - cgetc(); + cgetc (); return EXIT_SUCCESS; } -</tscreen> +</code></tscreen> Compile the tutorial with @@ -566,10 +565,10 @@ srec_cat hello -binary -offset 0x200 -o hello.c1p -Ohio_Scientific -execution-st </verb></tscreen> Open the URL <url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="http://www.pcjs.org/devices/c1p/machine/32kb/"> -in your browser and wait until the emulator is loaded. Click on the BREAK -button to display the boot prompt, then press the M key to enter the -65V PROM monitor. Press the "Choose File" button and select the hello.c1p -that was created as the output of the above invocation of the srec_cat +and wait until the emulator has been loaded. Click on the "BREAK" +button to display the boot prompt, then press the "M" key to enter the +65V PROM monitor. Click the "Choose File" button and select the file "hello.c1p" +that was created as the output of the above invocation of the "srec_cat" command. Press the "Load" button. You should see the following text on the screen: @@ -581,7 +580,8 @@ Press <RETURN> After hitting the RETURN key you should see the boot prompt again. The program can also be uploaded over the serial port to a real Challenger 1P -computer. +computer with 32 kB RAM. See the <url url="osi.html" name="Ohio Scientifc-specific documentation"> for instructions how to +compile for other RAM sizes. <sect1>Contributions wanted<p> diff --git a/doc/osi.sgml b/doc/osi.sgml index 7152f2815..76c56fac7 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -85,10 +85,10 @@ Special locations: </descrip><p> Example for building a program with start address $0300, stack size -$0200 and RAM size $0200: +$0200 and RAM size $2000: <tscreen> -cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0300 -t osic1p hello.c +cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p hello.c </tscreen> <sect>Linker configurations<p> From fc237faba7182c26faf3e727ddbdde716e813af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 8 Feb 2015 17:12:54 +0100 Subject: [PATCH 075/351] Add missing newline --- libsrc/osic1p/osic1p.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index 4ad0e038b..62178822b 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -2,4 +2,4 @@ SCRNBASE := $D000 ; Base of video RAM VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) INPUTC := $FD00 ; Input character from keyboard -RESET := $FF00 ; Reset address, show boot prompt \ No newline at end of file +RESET := $FF00 ; Reset address, show boot prompt From de3df033d38436a7d780b5d7bec87ab0377d72e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 8 Feb 2015 17:21:23 +0100 Subject: [PATCH 076/351] Remove tabs, fixed accidental insertion of stdio.h. --- src/common/target.c | 2 +- src/common/target.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/target.c b/src/common/target.c index 24734f196..6139c4a39 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -201,7 +201,7 @@ static int Compare (const void* Key, const void* Entry) return strcmp ((const char*) Key, ((const TargetEntry*)Entry)->Name); } -#include <stdio.h> + target_t FindTarget (const char* Name) /* Find a target by name and return the target id. TGT_UNKNOWN is returned if diff --git a/src/common/target.h b/src/common/target.h index edce36fa5..0b50e5060 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -64,8 +64,8 @@ typedef enum { TGT_PLUS4, TGT_CBM510, TGT_CBM610, - TGT_OSIC1P, - TGT_PET, + TGT_OSIC1P, + TGT_PET, TGT_BBC, TGT_APPLE2, TGT_APPLE2ENH, @@ -76,7 +76,7 @@ typedef enum { TGT_NES, TGT_SUPERVISION, TGT_LYNX, - TGT_SIM6502, + TGT_SIM6502, TGT_SIM65C02, TGT_COUNT /* Number of target systems */ } target_t; From 498fbb7ed729c58478c27068d021006471917487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 8 Feb 2015 17:35:40 +0100 Subject: [PATCH 077/351] Fix formatting, replace tabs with spaces. --- libsrc/osic1p/clrscr.s | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libsrc/osic1p/clrscr.s b/libsrc/osic1p/clrscr.s index 32975526f..48fb5d4f2 100644 --- a/libsrc/osic1p/clrscr.s +++ b/libsrc/osic1p/clrscr.s @@ -13,19 +13,19 @@ BANKS = VIDEORAMSIZE / $100 _clrscr: lda #$20 ;' ' - ldy #BANKS - ldx #$00 + ldy #BANKS + ldx #$00 staloc: - sta SCRNBASE,X - inx - bne staloc - inc staloc+2 - dey - bne staloc - lda #>(SCRNBASE); load high byte - sta staloc+2 ; restore base address + sta SCRNBASE,X + inx + bne staloc + inc staloc+2 + dey + bne staloc + lda #>(SCRNBASE); load high byte + sta staloc+2 ; restore base address - lda #$00 ; cursor in upper left corner + lda #$00 ; cursor in upper left corner sta CURS_X sta CURS_Y - jmp plot ; Set the cursor position + jmp plot ; Set the cursor position From d6a714a0d287b9625e4576a9eb495ac28ab1a8cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Wed, 11 Feb 2015 19:14:13 +0100 Subject: [PATCH 078/351] Added Challenger 1P to list of supported machines. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bf7d6dcde..660798128 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ including - the Supervision console. - the Oric Atmos. - the Lynx console. +- the Ohio Scientific Challenger 1P The libraries are fairly portable, so creating a version for other 6502s shouldn't be too much work. From 5063e0eccab745e232c0091cf9d31ca43913ba73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Wed, 11 Feb 2015 19:18:24 +0100 Subject: [PATCH 079/351] Incorporated feedback for initial pull request. --- cfg/osic1p-asm.cfg | 2 +- libsrc/osic1p/osic1p.inc | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cfg/osic1p-asm.cfg b/cfg/osic1p-asm.cfg index 57689b96d..d37f17f88 100644 --- a/cfg/osic1p-asm.cfg +++ b/cfg/osic1p-asm.cfg @@ -17,4 +17,4 @@ SEGMENTS { DATA: load = RAM, type = rw; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; -} \ No newline at end of file +} diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index 62178822b..e364277e0 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -1,5 +1,7 @@ - +; Addresses SCRNBASE := $D000 ; Base of video RAM -VIDEORAMSIZE := $0400 ; Size of C1P video RAM (1 kB) INPUTC := $FD00 ; Input character from keyboard RESET := $FF00 ; Reset address, show boot prompt + +; Other definitions +VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) From 679f5aa6756a5036e72259aa46fafbe2488610bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 12 Feb 2015 20:54:47 +0100 Subject: [PATCH 080/351] Use constants for screen width and height. --- cfg/osic1p.cfg | 2 +- libsrc/osic1p/_scrsize.s | 8 +++----- libsrc/osic1p/cputc.s | 4 ++-- libsrc/osic1p/crt0.s | 7 ------- libsrc/osic1p/extzp.inc | 2 +- libsrc/osic1p/extzp.s | 3 +-- libsrc/osic1p/osic1p.inc | 2 ++ 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index 59fdd34d8..4771639a6 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -7,7 +7,7 @@ SYMBOLS { } MEMORY { # for size of ZP see runtime/zeropage.s and c1p/extzp.s - ZP: file = "", define = yes, start = $0002, size = $001A + $0006; + ZP: file = "", define = yes, start = $0002, size = $001A + $0005; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { diff --git a/libsrc/osic1p/_scrsize.s b/libsrc/osic1p/_scrsize.s index 3b0d71c2f..337fe1ee7 100644 --- a/libsrc/osic1p/_scrsize.s +++ b/libsrc/osic1p/_scrsize.s @@ -10,12 +10,10 @@ .export screensize .include "extzp.inc" + .include "osic1p.inc" .proc screensize - - ldx SCR_LINELEN - inx ; Variable is one less - ldy #25 + ldx #(SCR_LINELEN + 1) + ldy #(SCR_HEIGHT + 1) rts - .endproc diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index 9cea78789..f6f285301 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -35,7 +35,7 @@ cputdirect: ; Advance cursor position advance: - cpy SCR_LINELEN ; xsize-1 + cpy #SCR_LINELEN ; xsize-1 bne L3 jsr newline ; new line ldy #$FF ; + cr @@ -46,7 +46,7 @@ L3: iny newline: inc CURS_Y lda CURS_Y - cmp #24 ; screen height 25 lines hardcoded + cmp #SCR_HEIGHT ; screen height bne plot lda #0 ; wrap around to line 0 sta CURS_Y diff --git a/libsrc/osic1p/crt0.s b/libsrc/osic1p/crt0.s index 447b65c56..0db447bb0 100644 --- a/libsrc/osic1p/crt0.s +++ b/libsrc/osic1p/crt0.s @@ -28,13 +28,6 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF txs cld ; Clear decimal mode -; --------------------------------------------------------------------------- -; Initialize screen width -; TODO: Can initialization be done in a more idiomatic way? -; TODO: Create function for changing screen width - lda #$18 - sta SCR_LINELEN - ; --------------------------------------------------------------------------- ; Set cc65 argument stack pointer diff --git a/libsrc/osic1p/extzp.inc b/libsrc/osic1p/extzp.inc index c5bb2b585..4aab34ff9 100644 --- a/libsrc/osic1p/extzp.inc +++ b/libsrc/osic1p/extzp.inc @@ -4,4 +4,4 @@ ; ------------------------------------------------------------------------ - .globalzp CURS_X, CURS_Y, CURS_SAV, SCR_LINELEN, SCREEN_PTR + .globalzp CURS_X, CURS_Y, CURS_SAV, SCREEN_PTR diff --git a/libsrc/osic1p/extzp.s b/libsrc/osic1p/extzp.s index dfa84a61c..95f9394dc 100644 --- a/libsrc/osic1p/extzp.s +++ b/libsrc/osic1p/extzp.s @@ -14,8 +14,7 @@ CURS_X: .byte 0 CURS_Y: .byte 0 CURS_SAV: .byte 0 -SCR_LINELEN: .byte 24 SCREEN_PTR: .res 2 -; size 6 +; size 5 ; Adjust size of this segment in osic1p.cfg if the size changes diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index e364277e0..58d63632f 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -5,3 +5,5 @@ RESET := $FF00 ; Reset address, show boot prompt ; Other definitions VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) +SCR_LINELEN = $18 ; screen width - 1 +SCR_HEIGHT = $18 ; screen height - 1 From b1169cbb23030997c87d9abb2d8afb6a2bdc86d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 12 Feb 2015 21:12:24 +0100 Subject: [PATCH 081/351] Remove unneeded commented code. --- libsrc/osic1p/crt0.s | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/osic1p/crt0.s b/libsrc/osic1p/crt0.s index 0db447bb0..07bdc3689 100644 --- a/libsrc/osic1p/crt0.s +++ b/libsrc/osic1p/crt0.s @@ -38,10 +38,8 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF ; --------------------------------------------------------------------------- ; Initialize memory storage -; copydata seems to be only necessary for special systems jsr zerobss ; Clear BSS segment - ; jsr copydata ; Initialize DATA segment jsr initlib ; Run constructors ; --------------------------------------------------------------------------- From 94f83ea43930ead4e5dab95e0b0a930d3722972a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 12 Feb 2015 21:29:19 +0100 Subject: [PATCH 082/351] Replace zeropage variable with standard tmp variable. --- cfg/osic1p.cfg | 2 +- libsrc/osic1p/cgetc.s | 5 +++-- libsrc/osic1p/extzp.inc | 2 +- libsrc/osic1p/extzp.s | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index 4771639a6..10ce827fd 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -7,7 +7,7 @@ SYMBOLS { } MEMORY { # for size of ZP see runtime/zeropage.s and c1p/extzp.s - ZP: file = "", define = yes, start = $0002, size = $001A + $0005; + ZP: file = "", define = yes, start = $0002, size = $001A + $0004; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index b5a519667..ecd53b8d7 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -6,6 +6,7 @@ .include "osic1p.inc" .include "extzp.inc" + .include "zeropage.inc" ; Input routine from 65V PROM MONITOR, show cursor if enabled _cgetc: @@ -13,7 +14,7 @@ _cgetc: beq nocursor ldy CURS_X lda (SCREEN_PTR),y ; fetch current character - sta CURS_SAV ; save it + sta tmp1 ; save it lda #$A1 ; full white square sta (SCREEN_PTR),y ; store at cursor position nocursor: @@ -21,7 +22,7 @@ nocursor: pha ; save retrieved character lda cursor ; was cursor on? beq nocursor2 - lda CURS_SAV ; fetch saved character + lda tmp1 ; fetch saved character ldy CURS_X sta (SCREEN_PTR),y ; store at cursor position nocursor2: diff --git a/libsrc/osic1p/extzp.inc b/libsrc/osic1p/extzp.inc index 4aab34ff9..06498d1a6 100644 --- a/libsrc/osic1p/extzp.inc +++ b/libsrc/osic1p/extzp.inc @@ -4,4 +4,4 @@ ; ------------------------------------------------------------------------ - .globalzp CURS_X, CURS_Y, CURS_SAV, SCREEN_PTR + .globalzp CURS_X, CURS_Y, SCREEN_PTR diff --git a/libsrc/osic1p/extzp.s b/libsrc/osic1p/extzp.s index 95f9394dc..e54e2b306 100644 --- a/libsrc/osic1p/extzp.s +++ b/libsrc/osic1p/extzp.s @@ -13,8 +13,7 @@ CURS_X: .byte 0 CURS_Y: .byte 0 -CURS_SAV: .byte 0 SCREEN_PTR: .res 2 -; size 5 +; size 4 ; Adjust size of this segment in osic1p.cfg if the size changes From 5d2e748bd4b7cc7d14b915001f34a43e902c38ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 12 Feb 2015 21:44:00 +0100 Subject: [PATCH 083/351] Don't use .byte in BSS segments, as value is lost anyway. --- libsrc/osic1p/extzp.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/osic1p/extzp.s b/libsrc/osic1p/extzp.s index e54e2b306..7dc8e3a53 100644 --- a/libsrc/osic1p/extzp.s +++ b/libsrc/osic1p/extzp.s @@ -11,8 +11,8 @@ .segment "EXTZP" : zeropage -CURS_X: .byte 0 -CURS_Y: .byte 0 +CURS_X: .res 1 +CURS_Y: .res 1 SCREEN_PTR: .res 2 ; size 4 From 3601c3fb9b9d62ea0357700d366f168f0b0967be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 12 Feb 2015 22:12:51 +0100 Subject: [PATCH 084/351] Include "extzp.inc" instead of using direct imports of symbols. --- libsrc/osic1p/clrscr.s | 2 +- libsrc/osic1p/gotox.s | 4 ++-- libsrc/osic1p/gotoxy.s | 2 +- libsrc/osic1p/gotoy.s | 2 +- libsrc/osic1p/wherex.s | 2 +- libsrc/osic1p/wherey.s | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libsrc/osic1p/clrscr.s b/libsrc/osic1p/clrscr.s index 48fb5d4f2..d2346659b 100644 --- a/libsrc/osic1p/clrscr.s +++ b/libsrc/osic1p/clrscr.s @@ -3,7 +3,7 @@ ; .export _clrscr .import plot - .importzp CURS_X, CURS_Y + .include "extzp.inc" .include "osic1p.inc" ; Adapted from the Challenger Character Graphics diff --git a/libsrc/osic1p/gotox.s b/libsrc/osic1p/gotox.s index fb84975d1..0dea72b9a 100644 --- a/libsrc/osic1p/gotox.s +++ b/libsrc/osic1p/gotox.s @@ -6,8 +6,8 @@ ; void gotox (unsigned char x); ; .export _gotox - .import plot - .importzp CURS_X + .import plot + .include "extzp.inc" _gotox: sta CURS_X ; Set new position jmp plot ; And activate it diff --git a/libsrc/osic1p/gotoxy.s b/libsrc/osic1p/gotoxy.s index 32d1f1df2..f76537349 100644 --- a/libsrc/osic1p/gotoxy.s +++ b/libsrc/osic1p/gotoxy.s @@ -8,7 +8,7 @@ ; .export _gotoxy .import popa, plot - .importzp CURS_X, CURS_Y + .include "extzp.inc" _gotoxy: sta CURS_Y ; Set Y diff --git a/libsrc/osic1p/gotoy.s b/libsrc/osic1p/gotoy.s index fcd60dd31..693863d94 100644 --- a/libsrc/osic1p/gotoy.s +++ b/libsrc/osic1p/gotoy.s @@ -7,7 +7,7 @@ ; .export _gotoy .import plot - .importzp CURS_Y + .include "extzp.inc" _gotoy: sta CURS_Y ; Set the new position jmp plot ; And activate it diff --git a/libsrc/osic1p/wherex.s b/libsrc/osic1p/wherex.s index 7c772a5a2..1155a8abd 100644 --- a/libsrc/osic1p/wherex.s +++ b/libsrc/osic1p/wherex.s @@ -5,7 +5,7 @@ ; unsigned char wherex (void); ; .export _wherex - .import CURS_X: zp + .include "extzp.inc" .proc _wherex lda CURS_X diff --git a/libsrc/osic1p/wherey.s b/libsrc/osic1p/wherey.s index 7449c1ceb..632cf4a15 100644 --- a/libsrc/osic1p/wherey.s +++ b/libsrc/osic1p/wherey.s @@ -5,7 +5,7 @@ ; unsigned char wherey (void); ; .export _wherey - .import CURS_Y: zp + .include "extzp.inc" .proc _wherey lda CURS_Y From 88df129215e27233d63afce837b4955ef0a90c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 12 Feb 2015 22:54:21 +0100 Subject: [PATCH 085/351] Add dummy kbhit(), remove redundant documentation for cgetc(). --- doc/osi.sgml | 4 ++-- libsrc/osic1p/kbhit.s | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 libsrc/osic1p/kbhit.s diff --git a/doc/osi.sgml b/doc/osi.sgml index 76c56fac7..514ef622e 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -139,8 +139,8 @@ There are no loadable drivers available. <sect1>conio implementation<p> -The conio implementation is complete except for the kbhit() function. A -call to cgetc() always blocks until a character is entered. +The conio implementation is complete except for a working kbhit() function. +kbhit() currently returns true unconditionally. <sect1>stdio implementation<p> diff --git a/libsrc/osic1p/kbhit.s b/libsrc/osic1p/kbhit.s new file mode 100644 index 000000000..42db7a5e6 --- /dev/null +++ b/libsrc/osic1p/kbhit.s @@ -0,0 +1,11 @@ +; +; int kbhit (void); +; +; Currently a dummy function that returns always true + + .export _kbhit + +_kbhit: + lda #$01 ; load low byte with true value + ldx #$00 ; load high byte + rts From e178a33d2916ba33fd141c482c77dfef88deafff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Fri, 13 Feb 2015 19:53:02 +0100 Subject: [PATCH 086/351] Fix high byte of return value, optimized. --- libsrc/osic1p/cgetc.s | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index ecd53b8d7..3c9dd4381 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -18,13 +18,14 @@ _cgetc: lda #$A1 ; full white square sta (SCREEN_PTR),y ; store at cursor position nocursor: - jsr INPUTC - pha ; save retrieved character - lda cursor ; was cursor on? - beq nocursor2 + jsr INPUTC ; get input character in A + ldx cursor + beq done ; was cursor on? + tax ; save A in X lda tmp1 ; fetch saved character ldy CURS_X sta (SCREEN_PTR),y ; store at cursor position -nocursor2: - pla ; restore retrieved character + txa ; restore saved character from X + ldx #$00 ; high byte of int return value +done: rts From 3ed3e98ec735c0fc8bebf28e4afebcac1d628fca Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Mon, 16 Feb 2015 15:43:08 +0100 Subject: [PATCH 087/351] Moved interrupt enabling to the interrupt constructor. --- libsrc/apple2/crt0.s | 4 ---- libsrc/apple2/irq.s | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index 4a7463b27..0f134202e 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -164,10 +164,6 @@ basic: lda HIMEM : sta sp stx sp+1 - ; Enable interrupts, as old ProDOS versions (i.e. 1.1.1) - ; jump to SYS and BIN programs with interrupts disabled. - cli - ; Call the module constructors. jsr initlib diff --git a/libsrc/apple2/irq.s b/libsrc/apple2/irq.s index c81fa7108..0b0555695 100644 --- a/libsrc/apple2/irq.s +++ b/libsrc/apple2/irq.s @@ -21,6 +21,10 @@ initirq: .byte $40 ; Alloc interrupt .addr i_param bcs prterr + + ; Enable interrupts, as old ProDOS versions (i.e. 1.1.1) + ; jump to SYS and BIN programs with interrupts disabled. + cli rts ; Print error message and exit From 92e75e9df81bde3830b3fc777490177a6c7f1709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Wed, 18 Feb 2015 18:38:42 +0100 Subject: [PATCH 088/351] Incorporated another round of feedback for pull request. Adjusted comment formatting in several assembler files. Removed dummy kbhit() function, as it's better to get a linker error than an implementation that does the wrong thing. --- doc/osi.sgml | 3 +-- libsrc/osic1p/chline.s | 2 +- libsrc/osic1p/clrscr.s | 10 +++++----- libsrc/osic1p/crt0.s | 18 +++++++++--------- libsrc/osic1p/cvline.s | 2 +- libsrc/osic1p/kbhit.s | 11 ----------- libsrc/osic1p/osic1p.inc | 12 ++++++------ 7 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 libsrc/osic1p/kbhit.s diff --git a/doc/osi.sgml b/doc/osi.sgml index 514ef622e..ce2ee4836 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -139,8 +139,7 @@ There are no loadable drivers available. <sect1>conio implementation<p> -The conio implementation is complete except for a working kbhit() function. -kbhit() currently returns true unconditionally. +The conio implementation is complete except for a kbhit() function. <sect1>stdio implementation<p> diff --git a/libsrc/osic1p/chline.s b/libsrc/osic1p/chline.s index da07e83be..be40d40af 100644 --- a/libsrc/osic1p/chline.s +++ b/libsrc/osic1p/chline.s @@ -22,7 +22,7 @@ _chline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #$94 ; Horizontal line, screen code +L1: lda #$94 ; Horizontal line, screen code jsr cputdirect ; Direct output dec tmp1 bne L1 diff --git a/libsrc/osic1p/clrscr.s b/libsrc/osic1p/clrscr.s index d2346659b..ee32bf969 100644 --- a/libsrc/osic1p/clrscr.s +++ b/libsrc/osic1p/clrscr.s @@ -12,7 +12,7 @@ BANKS = VIDEORAMSIZE / $100 _clrscr: - lda #$20 ;' ' + lda #$20 ; ' ' ldy #BANKS ldx #$00 staloc: @@ -22,10 +22,10 @@ staloc: inc staloc+2 dey bne staloc - lda #>(SCRNBASE); load high byte - sta staloc+2 ; restore base address + lda #>(SCRNBASE) ; Load high byte + sta staloc+2 ; Restore base address - lda #$00 ; cursor in upper left corner + lda #$00 ; Cursor in upper left corner sta CURS_X sta CURS_Y - jmp plot ; Set the cursor position + jmp plot ; Set the cursor position diff --git a/libsrc/osic1p/crt0.s b/libsrc/osic1p/crt0.s index 07bdc3689..657ee2743 100644 --- a/libsrc/osic1p/crt0.s +++ b/libsrc/osic1p/crt0.s @@ -7,8 +7,8 @@ .export _init, _exit .import _main -.export __STARTUP__ : absolute = 1 ; Mark as startup -.import __RAM_START__, __RAM_SIZE__ ; Linker generated +.export __STARTUP__ : absolute = 1 ; Mark as startup +.import __RAM_START__, __RAM_SIZE__ ; Linker generated .import zerobss, initlib, donelib @@ -24,9 +24,9 @@ ; --------------------------------------------------------------------------- ; A little light 6502 housekeeping -_init: ldx #$FF ; Initialize stack pointer to $01FF +_init: ldx #$FF ; Initialize stack pointer to $01FF txs - cld ; Clear decimal mode + cld ; Clear decimal mode ; --------------------------------------------------------------------------- ; Set cc65 argument stack pointer @@ -39,8 +39,8 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF ; --------------------------------------------------------------------------- ; Initialize memory storage - jsr zerobss ; Clear BSS segment - jsr initlib ; Run constructors + jsr zerobss ; Clear BSS segment + jsr initlib ; Run constructors ; --------------------------------------------------------------------------- ; Call main() @@ -48,7 +48,7 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF jsr _main ; --------------------------------------------------------------------------- -; Back from main (this is also the _exit entry): force a software break +; Back from main (this is also the _exit entry): -_exit: jsr donelib ; Run destructors - jmp RESET ; Display boot menu after program exit +_exit: jsr donelib ; Run destructors + jmp RESET ; Display boot menu after program exit diff --git a/libsrc/osic1p/cvline.s b/libsrc/osic1p/cvline.s index c485918ee..84e5a45bf 100644 --- a/libsrc/osic1p/cvline.s +++ b/libsrc/osic1p/cvline.s @@ -21,7 +21,7 @@ _cvline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #$95 ; Vertical bar +L1: lda #$95 ; Vertical bar jsr putchar ; Write, no cursor advance jsr newline ; Advance cursor to next line dec tmp1 diff --git a/libsrc/osic1p/kbhit.s b/libsrc/osic1p/kbhit.s deleted file mode 100644 index 42db7a5e6..000000000 --- a/libsrc/osic1p/kbhit.s +++ /dev/null @@ -1,11 +0,0 @@ -; -; int kbhit (void); -; -; Currently a dummy function that returns always true - - .export _kbhit - -_kbhit: - lda #$01 ; load low byte with true value - ldx #$00 ; load high byte - rts diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index 58d63632f..9a0c346b6 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -1,9 +1,9 @@ ; Addresses -SCRNBASE := $D000 ; Base of video RAM -INPUTC := $FD00 ; Input character from keyboard -RESET := $FF00 ; Reset address, show boot prompt +SCRNBASE := $D000 ; Base of video RAM +INPUTC := $FD00 ; Input character from keyboard +RESET := $FF00 ; Reset address, show boot prompt ; Other definitions -VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) -SCR_LINELEN = $18 ; screen width - 1 -SCR_HEIGHT = $18 ; screen height - 1 +VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) +SCR_LINELEN = $18 ; screen width - 1 +SCR_HEIGHT = $18 ; screen height - 1 From b1969ac16a656d9cd18e755b9e0e6b07085befe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Thu, 19 Feb 2015 22:19:21 +0100 Subject: [PATCH 089/351] kbhit() function and scrolling. Patch provided by Jeff Tranter. --- libsrc/osic1p/cputc.s | 12 ++++++++++-- libsrc/osic1p/kbhit.s | 28 ++++++++++++++++++++++++++++ libsrc/osic1p/osic1p.inc | 1 + 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 libsrc/osic1p/kbhit.s diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index f6f285301..47969df15 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -48,8 +48,16 @@ newline: lda CURS_Y cmp #SCR_HEIGHT ; screen height bne plot - lda #0 ; wrap around to line 0 - sta CURS_Y + dec CURS_Y ; bottom of screen reached, scroll + ldx #0 +scroll: lda SCRNBASE+$00A5,x + sta SCRNBASE+$0085,x + lda SCRNBASE+$01A5,x + sta SCRNBASE+$0185,x + lda SCRNBASE+$02A5,x + sta SCRNBASE+$0285,x + inx + bne scroll plot: ldy CURS_Y lda ScrLo,y diff --git a/libsrc/osic1p/kbhit.s b/libsrc/osic1p/kbhit.s new file mode 100644 index 000000000..c064fec47 --- /dev/null +++ b/libsrc/osic1p/kbhit.s @@ -0,0 +1,28 @@ +; +; unsigned char kbhit (void); +; + + .export _kbhit + .include "osic1p.inc" + +_kbhit: + lda #%11111110 ; Select first keyboard row +scan: + sta KBD ; Select keyboard row + tax ; Save A + lda KBD ; Read keyboard columns + ora #$01 ; Mask out lsb (Shift Lock), since we ignore it + cmp #$FF ; No keys pressed? + bne keypressed + txa ; Restore A + sec ; Want to shift in ones + rol a ; Rotate row select to next bit position + cmp #$FF ; Done? + bne scan ; If not, continue + ldx #$00 ; High byte of return is always zero + lda #$00 ; Return false + rts +keypressed: + ldx #$00 ; High byte of return is always zero + lda #$01 ; Return true + rts diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index 9a0c346b6..e95db637e 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -2,6 +2,7 @@ SCRNBASE := $D000 ; Base of video RAM INPUTC := $FD00 ; Input character from keyboard RESET := $FF00 ; Reset address, show boot prompt +KBD := $DF00 ; Polled keyboard register ; Other definitions VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) From 222668c016897eea23df781ec619bc288be83502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 21 Feb 2015 20:24:58 +0100 Subject: [PATCH 090/351] Implemented a one-character buffer for kbhit() and cgetc(). If kbhit() detects that a key is pressed, it fetches and buffers the character. If cgetc() detects a buffered character, this one is returned instead of fetching one with the PROM routine. --- cfg/osic1p.cfg | 2 +- libsrc/osic1p/cgetc.s | 19 ++++++++++++++++++- libsrc/osic1p/extzp.inc | 2 +- libsrc/osic1p/extzp.s | 5 +++-- libsrc/osic1p/kbhit.s | 5 ++++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index 10ce827fd..4771639a6 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -7,7 +7,7 @@ SYMBOLS { } MEMORY { # for size of ZP see runtime/zeropage.s and c1p/extzp.s - ZP: file = "", define = yes, start = $0002, size = $001A + $0004; + ZP: file = "", define = yes, start = $0002, size = $001A + $0005; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index 3c9dd4381..82857f4c6 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -1,6 +1,8 @@ ; ; char cgetc (void); ; + + .constructor initcgetc .export _cgetc .import cursor @@ -8,8 +10,21 @@ .include "extzp.inc" .include "zeropage.inc" +; Initialize one-character buffer that is filled by kbhit() +initcgetc: + lda #$00 + sta CHARBUF ; No character in buffer initially + rts + ; Input routine from 65V PROM MONITOR, show cursor if enabled _cgetc: + lda CHARBUF ; character in buffer available? + beq nobuffer + tax ; save character in X + lda #$00 + sta CHARBUF ; empty buffer + jmp restorex ; restore X and return +nobuffer: lda cursor ; show cursor? beq nocursor ldy CURS_X @@ -25,7 +40,9 @@ nocursor: lda tmp1 ; fetch saved character ldy CURS_X sta (SCREEN_PTR),y ; store at cursor position + +restorex: txa ; restore saved character from X - ldx #$00 ; high byte of int return value done: + ldx #$00 ; high byte of int return value rts diff --git a/libsrc/osic1p/extzp.inc b/libsrc/osic1p/extzp.inc index 06498d1a6..5e85e0b74 100644 --- a/libsrc/osic1p/extzp.inc +++ b/libsrc/osic1p/extzp.inc @@ -4,4 +4,4 @@ ; ------------------------------------------------------------------------ - .globalzp CURS_X, CURS_Y, SCREEN_PTR + .globalzp CURS_X, CURS_Y, SCREEN_PTR, CHARBUF diff --git a/libsrc/osic1p/extzp.s b/libsrc/osic1p/extzp.s index 7dc8e3a53..b3bdaa0b7 100644 --- a/libsrc/osic1p/extzp.s +++ b/libsrc/osic1p/extzp.s @@ -14,6 +14,7 @@ CURS_X: .res 1 CURS_Y: .res 1 SCREEN_PTR: .res 2 +CHARBUF: .res 1 -; size 4 -; Adjust size of this segment in osic1p.cfg if the size changes +; size 5 +; Adjust size of the ZP segment in osic1p.cfg if the size changes diff --git a/libsrc/osic1p/kbhit.s b/libsrc/osic1p/kbhit.s index c064fec47..67f3c86ed 100644 --- a/libsrc/osic1p/kbhit.s +++ b/libsrc/osic1p/kbhit.s @@ -19,10 +19,13 @@ scan: rol a ; Rotate row select to next bit position cmp #$FF ; Done? bne scan ; If not, continue - ldx #$00 ; High byte of return is always zero lda #$00 ; Return false + tax ; High byte of return is also zero + sta CHARBUF ; No character in buffer rts keypressed: + jsr INPUTC ; Get input character in A + sta CHARBUF ; Save in buffer ldx #$00 ; High byte of return is always zero lda #$01 ; Return true rts From 1b9aa7c6f3d7cb253d5f28a8ba68b924d796e7e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 21 Feb 2015 20:53:16 +0100 Subject: [PATCH 091/351] Use character constants where appropriate. --- libsrc/osic1p/cclear.s | 2 +- libsrc/osic1p/clrscr.s | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/osic1p/cclear.s b/libsrc/osic1p/cclear.s index 4e18c70a3..2036c38e0 100644 --- a/libsrc/osic1p/cclear.s +++ b/libsrc/osic1p/cclear.s @@ -22,7 +22,7 @@ _cclear: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #$20 ; Blank - screen code +L1: lda #' ' jsr cputdirect ; Direct output dec tmp1 bne L1 diff --git a/libsrc/osic1p/clrscr.s b/libsrc/osic1p/clrscr.s index ee32bf969..db8da6912 100644 --- a/libsrc/osic1p/clrscr.s +++ b/libsrc/osic1p/clrscr.s @@ -12,7 +12,7 @@ BANKS = VIDEORAMSIZE / $100 _clrscr: - lda #$20 ; ' ' + lda #' ' ldy #BANKS ldx #$00 staloc: From 7a975fa182134b7f1c1bb026cae4900e458bce8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 21 Feb 2015 22:52:01 +0100 Subject: [PATCH 092/351] Mask control keys from first keyboard scan row. --- libsrc/osic1p/kbhit.s | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libsrc/osic1p/kbhit.s b/libsrc/osic1p/kbhit.s index 67f3c86ed..b616b4a3f 100644 --- a/libsrc/osic1p/kbhit.s +++ b/libsrc/osic1p/kbhit.s @@ -1,19 +1,35 @@ ; ; unsigned char kbhit (void); +; +; The method to detect a pressed key is based on the documentation in +; "Section 3 Programmed Key Functions" in "The Challenger Character Graphics +; Reference Manual" +; We only want to return true for characters that can be returned by cgetc(), +; but not for keys like <Shift> or <Ctrl>. Therefore a special handling is +; needed for the first row. This is implemented by a bit mask that is stored +; in tmp1 and that is set to zero after the first round. ; .export _kbhit .include "osic1p.inc" + .include "extzp.inc" + .include "zeropage.inc" _kbhit: - lda #%11111110 ; Select first keyboard row + lda #%11011111 ; Mask for only checking the column for the + sta tmp1 ; ESC key in the first keyboard row. + + lda #%11111110 ; Mask for first keyboard row scan: sta KBD ; Select keyboard row tax ; Save A lda KBD ; Read keyboard columns - ora #$01 ; Mask out lsb (Shift Lock), since we ignore it + ora tmp1 ; Mask out uninteresting keys (only relevant in + ; first row) cmp #$FF ; No keys pressed? bne keypressed + lda #$00 ; For remaining rows no keys masked + sta tmp1 txa ; Restore A sec ; Want to shift in ones rol a ; Rotate row select to next bit position From a7dabcda4786bc8db44a7d47b4702ed55ea92fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 22 Feb 2015 16:27:13 +0100 Subject: [PATCH 093/351] Define the screen dimension defines in a more meaningful way. --- libsrc/osic1p/_scrsize.s | 4 ++-- libsrc/osic1p/cputc.s | 2 +- libsrc/osic1p/osic1p.inc | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/osic1p/_scrsize.s b/libsrc/osic1p/_scrsize.s index 337fe1ee7..b0241c547 100644 --- a/libsrc/osic1p/_scrsize.s +++ b/libsrc/osic1p/_scrsize.s @@ -13,7 +13,7 @@ .include "osic1p.inc" .proc screensize - ldx #(SCR_LINELEN + 1) - ldy #(SCR_HEIGHT + 1) + ldx #SCR_LINELEN + ldy #SCR_HEIGHT rts .endproc diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index 47969df15..9e6ae3253 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -35,7 +35,7 @@ cputdirect: ; Advance cursor position advance: - cpy #SCR_LINELEN ; xsize-1 + cpy #(SCR_LINELEN - 1) bne L3 jsr newline ; new line ldy #$FF ; + cr diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index e95db637e..f49bc122b 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -6,5 +6,5 @@ KBD := $DF00 ; Polled keyboard register ; Other definitions VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) -SCR_LINELEN = $18 ; screen width - 1 -SCR_HEIGHT = $18 ; screen height - 1 +SCR_LINELEN = $19 ; screen width +SCR_HEIGHT = $19 ; screen height From c3b014560eb291a18b28a70e9516abb49dae34eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 22 Feb 2015 19:55:19 +0100 Subject: [PATCH 094/351] Consistent naming for screen dimension constants. --- libsrc/osic1p/_scrsize.s | 2 +- libsrc/osic1p/cputc.s | 2 +- libsrc/osic1p/osic1p.inc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/osic1p/_scrsize.s b/libsrc/osic1p/_scrsize.s index b0241c547..be07234b4 100644 --- a/libsrc/osic1p/_scrsize.s +++ b/libsrc/osic1p/_scrsize.s @@ -13,7 +13,7 @@ .include "osic1p.inc" .proc screensize - ldx #SCR_LINELEN + ldx #SCR_WIDTH ldy #SCR_HEIGHT rts .endproc diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index 9e6ae3253..e986daad1 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -35,7 +35,7 @@ cputdirect: ; Advance cursor position advance: - cpy #(SCR_LINELEN - 1) + cpy #(SCR_WIDTH - 1) bne L3 jsr newline ; new line ldy #$FF ; + cr diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index f49bc122b..b5d48f32e 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -6,5 +6,5 @@ KBD := $DF00 ; Polled keyboard register ; Other definitions VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) -SCR_LINELEN = $19 ; screen width -SCR_HEIGHT = $19 ; screen height +SCR_WIDTH = $19 ; Screen width +SCR_HEIGHT = $19 ; Screen height From 73ae95bd1c11ccfca9f98d6941ee2600d901c033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 23 Feb 2015 19:06:22 +0100 Subject: [PATCH 095/351] Clear bottom line when scrolling. Fix provided by Jeff Tranter. --- libsrc/osic1p/cputc.s | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index 47969df15..058964573 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -58,6 +58,12 @@ scroll: lda SCRNBASE+$00A5,x sta SCRNBASE+$0285,x inx bne scroll +bottom: + lda #' ' ; Clear bottom line of screen + sta SCRNBASE+$0385,x + inx + cpx #SCR_LINELEN+1 + bne bottom plot: ldy CURS_Y lda ScrLo,y From 83f16425c9d2dd2d84b4f6932826538e8b7bd01a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 23 Feb 2015 19:17:27 +0100 Subject: [PATCH 096/351] Loading A once before the loop is sufficient. --- libsrc/osic1p/cputc.s | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index 058964573..4e16e92df 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -58,8 +58,9 @@ scroll: lda SCRNBASE+$00A5,x sta SCRNBASE+$0285,x inx bne scroll -bottom: + lda #' ' ; Clear bottom line of screen +bottom: sta SCRNBASE+$0385,x inx cpx #SCR_LINELEN+1 From 7c4f96de817d2c63dbb41d6a72c12db1e1d2c5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 23 Feb 2015 20:28:05 +0100 Subject: [PATCH 097/351] kbhit implemented, note about limitation removed. --- doc/osi.sgml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/osi.sgml b/doc/osi.sgml index ce2ee4836..e360daf7a 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -137,10 +137,6 @@ There are no loadable drivers available. <sect>Limitations<p> -<sect1>conio implementation<p> - -The conio implementation is complete except for a kbhit() function. - <sect1>stdio implementation<p> There is no support for stdio at the moment. From 8deeb2c59e50c4221dcf588e9670b63f4e26e729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 23 Feb 2015 23:07:00 +0100 Subject: [PATCH 098/351] Match screen dimensions as in BASIC. Experiments show that under BASIC by default 25 rows by 24 columns are used. 24 columns is also the width that is fully displayed on a real C1P on the monitor. conio now matches that now. --- libsrc/osic1p/osic1p.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index b5d48f32e..d209b258d 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -6,5 +6,5 @@ KBD := $DF00 ; Polled keyboard register ; Other definitions VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) -SCR_WIDTH = $19 ; Screen width +SCR_WIDTH = $18 ; Screen width SCR_HEIGHT = $19 ; Screen height From 52865410d2269e074bb7c41683d023f875b69f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Wed, 25 Feb 2015 23:48:57 +0100 Subject: [PATCH 099/351] Fix wrong expression for top of C stack. Thanks to Greg King for this fix. --- libsrc/osic1p/crt0.s | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libsrc/osic1p/crt0.s b/libsrc/osic1p/crt0.s index 657ee2743..62342c206 100644 --- a/libsrc/osic1p/crt0.s +++ b/libsrc/osic1p/crt0.s @@ -9,6 +9,7 @@ .export __STARTUP__ : absolute = 1 ; Mark as startup .import __RAM_START__, __RAM_SIZE__ ; Linker generated +.import __STACKSIZE__ .import zerobss, initlib, donelib @@ -31,9 +32,9 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF ; --------------------------------------------------------------------------- ; Set cc65 argument stack pointer - lda #<(__RAM_START__ + __RAM_SIZE__) + lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) sta sp - lda #>(__RAM_START__ + __RAM_SIZE__) + lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) sta sp+1 ; --------------------------------------------------------------------------- From 4737ad93d5cc8882675eaa12533937b88763ed29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Wed, 25 Feb 2015 23:50:02 +0100 Subject: [PATCH 100/351] Temporarily undo the 25 line change. This is not yet consistent with the first visible character on the screen. --- libsrc/osic1p/osic1p.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index d209b258d..232c471aa 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -7,4 +7,4 @@ KBD := $DF00 ; Polled keyboard register ; Other definitions VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) SCR_WIDTH = $18 ; Screen width -SCR_HEIGHT = $19 ; Screen height +SCR_HEIGHT = $18 ; Screen height From f5ac6b0dbfd12dfbae2266b17502974da2fff252 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 28 Feb 2015 00:17:07 -0500 Subject: [PATCH 101/351] Updated the introduction to the Atmos target because I changed how its programs are started. --- doc/intro.sgml | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/doc/intro.sgml b/doc/intro.sgml index 41f359278..10693aa4a 100644 --- a/doc/intro.sgml +++ b/doc/intro.sgml @@ -7,7 +7,7 @@ <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:cbmnut@hushmail.com" name="CbmNut">,<newline> <url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2014-4-24 +<date>2015-2-27 <abstract> How to use the cc65 C language system -- an introduction. @@ -342,8 +342,8 @@ Available at <url url="http://code.google.com/p/oriculator/">: Emulates Oric-1 and Atmos computers, with sound, disk images, -scanline-exact NTSC/PAL video, and movie export. Includes monitor. -Fortunately for all SDL platforms. You will just need the emulator, all +scanline-exact NTSC/PAL video, and movie export. Includes a monitor. +Fortunately, for all SDL platforms. You will need just the emulator; all ROMs are supplied. Compile the tutorial with @@ -353,8 +353,11 @@ cl65 -O -t atmos hello.c text.s -o hello.tap </verb></tscreen> Start the emulator, choose <bf/F1/ and <bf/Insert tape.../, and point to -the "<bf/hello.tap/" executable. The file has an auto start header meant to -be loaded directly from tape. +the "<bf/hello.tap/" executable. After it has finished loading, type + +<tscreen><verb> +RUN +</verb></tscreen> On a real Atmos, you would need a tape drive. Turn on the computer, type @@ -363,7 +366,11 @@ Turn on the computer, type CLOAD"" </verb></tscreen> -at the BASIC prompt. +at the BASIC prompt. After it has finished loading, type + +<tscreen><verb> +RUN +</verb></tscreen> The emulation, also, supports that method. From 1d6aa84d9a8521757c4c067feb059fc2d38109d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 28 Feb 2015 20:29:08 +0100 Subject: [PATCH 102/351] Optimization by replacing absolute with relative jump. --- libsrc/osic1p/cgetc.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index 82857f4c6..0c7c69488 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -23,7 +23,7 @@ _cgetc: tax ; save character in X lda #$00 sta CHARBUF ; empty buffer - jmp restorex ; restore X and return + beq restorex ; restore X and return nobuffer: lda cursor ; show cursor? beq nocursor From 981ab10fac12c7f4ba18d8a08eb1b949eea7894a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 1 Mar 2015 20:53:57 +0100 Subject: [PATCH 103/351] Replaced magic numbers with symbolic constants. --- libsrc/osic1p/cputc.s | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s index e4416682a..2baada465 100644 --- a/libsrc/osic1p/cputc.s +++ b/libsrc/osic1p/cputc.s @@ -12,6 +12,10 @@ .include "osic1p.inc" .include "extzp.inc" +FIRSTVISC = $85 ; Offset of first visible character in video RAM +LINEDIST = $20 ; Offset in video RAM between two lines +BLOCKSIZE = $100 ; Size of block to scroll + _cputcxy: pha ; Save C jsr popa ; Get Y @@ -37,7 +41,7 @@ cputdirect: advance: cpy #(SCR_WIDTH - 1) bne L3 - jsr newline ; new line + jsr newline ; New line ldy #$FF ; + cr L3: iny sty CURS_X @@ -46,22 +50,22 @@ L3: iny newline: inc CURS_Y lda CURS_Y - cmp #SCR_HEIGHT ; screen height + cmp #SCR_HEIGHT ; Screen height bne plot - dec CURS_Y ; bottom of screen reached, scroll + dec CURS_Y ; Bottom of screen reached, scroll ldx #0 -scroll: lda SCRNBASE+$00A5,x - sta SCRNBASE+$0085,x - lda SCRNBASE+$01A5,x - sta SCRNBASE+$0185,x - lda SCRNBASE+$02A5,x - sta SCRNBASE+$0285,x +scroll: +.repeat 3, I ; Scroll screen in three blocks of size + ; BLOCKSIZE + lda SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC+LINEDIST,x + sta SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC,x +.endrepeat inx bne scroll lda #' ' ; Clear bottom line of screen bottom: - sta SCRNBASE+$0385,x + sta SCRNBASE+(3*BLOCKSIZE)+FIRSTVISC,x inx cpx #SCR_WIDTH bne bottom From ba871635de2ac2bbd7ad9eaa6d08003fc6d4a26d Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 5 Mar 2015 12:44:08 -0500 Subject: [PATCH 104/351] Added a font translation table because Ohio Scientific machines have three misplaced characters. --- src/common/target.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/common/target.c b/src/common/target.c index 6139c4a39..7e152fe94 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2011, Ullrich von Bassewitz */ +/* (C) 2000-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -50,7 +50,7 @@ /* Translation table with direct (no) translation */ -static unsigned char CTNone[256] = { +static const unsigned char CTNone[256] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, @@ -69,8 +69,8 @@ static unsigned char CTNone[256] = { 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, }; -/* Translation table ISO-8859-1 -> ATASCII */ -static const unsigned char CTAtari [256] = { +/* Translation table ISO-8859-1 -> AtASCII */ +static const unsigned char CTAtari[256] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0xFD,0x08,0x7F,0x9B,0x0B,0x7D,0x0D,0x0E,0x0F, 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, @@ -89,8 +89,28 @@ static const unsigned char CTAtari [256] = { 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, }; -/* Translation table ISO-8859-1 -> PETSCII */ -static const unsigned char CTPET [256] = { +/* Translation table ISO-8859-1 -> OSASCII */ +static const unsigned char CTOSI[256] = { + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, + 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, + 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, + 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F, + 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C,0x4D,0x4E,0x4F, + 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F, + 0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A,0x6B,0x6C,0x6D,0x6E,0x6F, + 0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A,0x7B,0x7D,0x7C,0x7F,0x7E, + 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8A,0x8B,0x8C,0x8D,0x8E,0x8F, + 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, + 0xA0,0xA1,0xA2,0xA3,0xA4,0xA5,0xA6,0xA7,0xA8,0xA9,0xAA,0xAB,0xAC,0xAD,0xAE,0xAF, + 0xB0,0xB1,0xB2,0xB3,0xB4,0xB5,0xB6,0xB7,0xB8,0xB9,0xBA,0xBB,0xBC,0xBD,0xBE,0xBF, + 0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF, + 0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF, + 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF, + 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, +}; + +/* Translation table ISO-8859-1 -> PetSCII */ +static const unsigned char CTPET[256] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x14,0x09,0x0D,0x11,0x93,0x0A,0x0E,0x0F, 0x10,0x0B,0x12,0x13,0x08,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F, @@ -168,7 +188,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "plus4", CPU_6502, BINFMT_BINARY, CTPET }, { "cbm510", CPU_6502, BINFMT_BINARY, CTPET }, { "cbm610", CPU_6502, BINFMT_BINARY, CTPET }, - { "osic1p", CPU_6502, BINFMT_BINARY, CTNone }, + { "osic1p", CPU_6502, BINFMT_BINARY, CTOSI }, { "pet", CPU_6502, BINFMT_BINARY, CTPET }, { "bbc", CPU_6502, BINFMT_BINARY, CTNone }, { "apple2", CPU_6502, BINFMT_BINARY, CTNone }, From 2d50267bd87a1b616f8985b10242f69f71897357 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 7 Mar 2015 16:37:58 -0500 Subject: [PATCH 105/351] Added a second OSI C1P program file format. Unlike the first format, the new format is already loadable; it doesn't need to be converted. --- cfg/osic1p-asm.cfg | 18 +++-- cfg/osic1p.cfg | 26 ++++--- doc/intro.sgml | 121 +++++++++++++++++++++++---------- doc/osi.sgml | 77 +++++++++++++-------- libsrc/osic1p/bootstrap.s | 138 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 301 insertions(+), 79 deletions(-) create mode 100644 libsrc/osic1p/bootstrap.s diff --git a/cfg/osic1p-asm.cfg b/cfg/osic1p-asm.cfg index d37f17f88..d9f128f8a 100644 --- a/cfg/osic1p-asm.cfg +++ b/cfg/osic1p-asm.cfg @@ -2,19 +2,23 @@ FEATURES { STARTADDRESS: default = $0200; } SYMBOLS { +# Add "-u __BOOT__" to a command line if you want a file that can be loaded directly. +# __BOOT__: type = import; __STACKSIZE__: type = weak, value = $0400; # 1 kB stack __HIMEM__: type = weak, value = $8000; # 32 kB RAM } MEMORY { - # for size of ZP see runtime/zeropage.s and c1p/extzp.s + # for size of ZP, see runtime/zeropage.s and c1p/extzp.s ZP: file = "", define = yes, start = $0002, size = $001A + $0006; + HEAD: file = %O, start = $0000, size = $00AA; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { - INIT: load = RAM, type = ro, define = yes, optional = yes; - CODE: load = RAM, type = rw; - RODATA: load = RAM, type = rw; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; + BOOT: load = HEAD, type = ro, optional = yes; + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = rw; + RODATA: load = RAM, type = rw; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; } diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index 4771639a6..0ad2f8939 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -2,24 +2,28 @@ FEATURES { STARTADDRESS: default = $0200; } SYMBOLS { +# Add "-u __BOOT__" to a command line if you want a file that can be loaded directly. +# __BOOT__: type = import; __STACKSIZE__: type = weak, value = $0400; # 1 kB stack __HIMEM__: type = weak, value = $8000; # 32 kB RAM } MEMORY { - # for size of ZP see runtime/zeropage.s and c1p/extzp.s - ZP: file = "", define = yes, start = $0002, size = $001A + $0005; + # for size of ZP, see runtime/zeropage.s and c1p/extzp.s + ZP: file = "", define = yes, start = $0002, size = $001A + $0006; + HEAD: file = %O, start = $0000, size = $00AA; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { - STARTUP: load = RAM, type = ro; - LOWCODE: load = RAM, type = ro, optional = yes; - INIT: load = RAM, type = ro, define = yes, optional = yes; - CODE: load = RAM, type = rw; - RODATA: load = RAM, type = rw; - DATA: load = RAM, type = rw; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - EXTZP: load = ZP, type = rw, define = yes; + BOOT: load = HEAD, type = ro, optional = yes; + STARTUP: load = RAM, type = ro; + LOWCODE: load = RAM, type = ro, optional = yes; + INIT: load = RAM, type = ro, define = yes, optional = yes; + CODE: load = RAM, type = rw; + RODATA: load = RAM, type = rw; + DATA: load = RAM, type = rw; + BSS: load = RAM, type = bss, define = yes; + ZEROPAGE: load = ZP, type = zp; + EXTZP: load = ZP, type = zp, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/doc/intro.sgml b/doc/intro.sgml index 10693aa4a..d92fd1d20 100644 --- a/doc/intro.sgml +++ b/doc/intro.sgml @@ -6,8 +6,9 @@ <author> <url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> <url url="mailto:cbmnut@hushmail.com" name="CbmNut">,<newline> -<url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2015-2-27 +<url url="mailto:greg.king5@verizon.net" name="Greg King">,<newline> +<url url="mailto:stephan.muehlstrasser@web.de" name="Stephan Mühlstrasser"> +<date>2015-03-07 <abstract> How to use the cc65 C language system -- an introduction. @@ -520,28 +521,18 @@ directory notePad. Look at the eight file-positions on each page until you see The output is shown in a GEOS dialog box; click <bf/OK/ when you have finished reading it. + <sect1>Ohio Scientific Challenger 1P<p> -Available at <url url="http://www.pcjs.org/docs/c1pjs/" name="C1Pjs">: - -Emulates the Ohio Scientific Challenger 1P computer in different configurations. -The 32 kb RAM machine that must be used with the default compiler settings is -<url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="here">. - -In addition to cc65 the srec_cat program from the -<url url="http://srecord.sourceforge.net/" name="SRecord"> -tool collection must be installed. Some Linux distributions also provide the -srecord package directly as an installable package. - -The osic1p runtime library returns to the boot prompt when the -main() program exits. Therefore the C file in the tutorial must be slightly -modified in order to see the results on the screen. Otherwise the program -would print the text string and then jump to the boot prompt, making it +The <tt/osic1p/ runtime library returns to the boot prompt when the main() +program exits. Therefore, the C file in the tutorial must be modified +slightly, in order to see the results on the screen. Otherwise, the program +would print the text string, and then jump to the boot prompt, making it impossible to see the results of running the tutorial program. -In addition to that the osic1p target does not yet have support for stdio +In addition to that, the <tt/osic1p/ target does not yet have support for stdio functions. Only the functions from the conio library are available. -Therefore modify the hello.c source file as follows: +Therefore, modify the "<tt/hello.c/" source file, as follows: <tscreen><code> #include <conio.h> @@ -552,7 +543,7 @@ extern const char text[]; /* In text.s */ int main (void) { clrscr (); - cprintf ("%s\r\nPress <RETURN>\r\n", text); + cprintf ("%s\r\nPress <RETURN>.\r\n", text); cgetc (); return EXIT_SUCCESS; } @@ -560,35 +551,97 @@ int main (void) Compile the tutorial with +<tscreen><verb> +cl65 -O -t osic1p -u __BOOT__ -o hello.lod hello.c text.s +</verb></tscreen> + +The program is configured for a Challenger 1P computer with, at least, 32 kB +of RAM. See the <url url="osi.html" +name="Ohio Scientifc-specific documentation"> for instructions about how to +compile for other RAM sizes. + +Plug a cassette player into your C1P computer; or, connect an RS-232 cable +between your C1P and a PC (set the PC's serial port to 300 Bits Per Second, +8 data bits, No parity, and 2 stop bits). (Turn on the computers.) + +Tap the "<bf/BREAK/" key, to display the boot prompt; then, tap the "<tt/M/" +key, to enter the 65V PROM monitor. Tap the "<tt/L/" key. Either start the +cassette player (with a tape of the program), or start a transfer of the +program file "<tt/hello.lod/" from the PC. After a while, you should see the +following text on the screen: + +<tscreen><verb> +Hello world! +Press <RETURN>. +</verb></tscreen> + +(Stop the cassette player.) After hitting the RETURN key, you should see the +boot prompt again. + +<sect2>WinOSI<p> +Available at <url +url="http://osi.marks-lab.com/#Emulator">: + +Emulates the Ohio Scientific Challenger computers in different configurations. +Configure it to emulate a C1P (model 600 board) with 32 kB of RAM. + +Compile the tutorial with the same command that is used to make the program +for a real machine. + +Start the emulator. Tap the "<tt/M/" key, to enter the 65V PROM monitor; then, +tap the "<tt/L/" key. If you had configured WinOSI to ask for a file when it +starts to read data from the serial port, then you will see a file dialog box; +otherwise, you must tap your host keyboard's F10 function key. Select the file +"<tt/hello.lod/". After a moment, you should see the following text on the +screen: + +<tscreen><verb> +Hello world! +Press <RETURN>. +</verb></tscreen> + +After hitting the RETURN key, you should see the boot prompt again. + +<sect2>C1Pjs<p> +Available at <url +url="http://www.pcjs.org/docs/c1pjs/">: + +Emulates the Ohio Scientific Challenger 1P computer in different configurations. +The 32 kB RAM machine that must be used with the default compiler settings is +<url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="here">. + +In addition to cc65, the <bf/srec_cat/ program from <url +url="http://srecord.sourceforge.net/" name="the SRecord tool collection"> +must be installed. Some Linux distributions also provide srecord directly as +an installable package. + +Compile the tutorial with this command line: + <tscreen><verb> cl65 -O -t osic1p hello.c text.s </verb></tscreen> -Convert the executable file into a text file that can be loaded via -the Ohio Scientific 65V PROM monitor at start address 0x200: +Convert the binary file into a text file that can be loaded via +the Ohio Scientific 65V PROM monitor, at start address 0x200: <tscreen><verb> srec_cat hello -binary -offset 0x200 -o hello.c1p -Ohio_Scientific -execution-start-address=0x200 </verb></tscreen> -Open the URL <url url="http://www.pcjs.org/devices/c1p/machine/32kb/" name="http://www.pcjs.org/devices/c1p/machine/32kb/"> -and wait until the emulator has been loaded. Click on the "BREAK" -button to display the boot prompt, then press the "M" key to enter the -65V PROM monitor. Click the "Choose File" button and select the file "hello.c1p" -that was created as the output of the above invocation of the "srec_cat" -command. Press the "Load" button. You should see the following text on the -screen: +Open the URL that points to the 32 kB machine; and, wait until the emulator +has been loaded. Click on the "<bf/BREAK/" button to display the boot prompt; +then, press the "<tt/M/" key to enter the 65V PROM monitor. Click the +"<bf/Browse.../" button; and, select the file "<tt/hello.c1p/" that was +created as the output of the above invocation of the "<tt/srec_cat/" command. +Press the "<bf/Load/" button. You should see the following text on the screen: <tscreen><verb> Hello world! -Press <RETURN> +Press <RETURN>. </verb></tscreen> -After hitting the RETURN key you should see the boot prompt again. +After hitting the RETURN key, you should see the boot prompt again. -The program can also be uploaded over the serial port to a real Challenger 1P -computer with 32 kB RAM. See the <url url="osi.html" name="Ohio Scientifc-specific documentation"> for instructions how to -compile for other RAM sizes. <sect1>Contributions wanted<p> diff --git a/doc/osi.sgml b/doc/osi.sgml index e360daf7a..0167b2bd1 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -4,8 +4,9 @@ <title>Ohio Scientific-specific information for cc65 <author> -<url url="mailto:stephan.muehlstrasser@web.de" name="Stephan Mühlstrasser"><newline> -<date>2015-02-04 +<url url="mailto:stephan.muehlstrasser@web.de" name="Stephan Mühlstrasser">,<newline> +<url url="mailto:greg.king5@verizon.net" name="Greg King"> +<date>2015-03-07 <abstract> An overview over the Ohio Scientific runtime system as it is implemented for the cc65 C @@ -34,42 +35,63 @@ information. Currently the target "osic1p" is implemented. This works for the Ohio Scientific Challenger 1P machine. -<sect>Binary format<p> +<sect>Program file formats<p> -The standard binary output format generated by the linker for the osic1p target -is a machine language program.<p> +<descrip> + <tag/Binary, then text/ + The standard binary output format generated by the linker for the osic1p + target is a pure machine language program. -For uploading into a real machine over the serial port or into an emulator a -program must be converted to a text file that is understood by the 65V PROM -monitor. For this purpose the srec_cat program from the -<url url="http://srecord.sourceforge.net/" name="SRecord"> -tool collection can be used. + For uploading into a real machine over its serial port or into an emulator, + that program must be converted into a text file that can be understood by + the 65V PROM monitor. For that purpose, the <bf/srec_cat/ program from <url + url="http://srecord.sourceforge.net/" name="the SRecord tool collection"> + can be used. -Care must be taken that the -offset and -execution-start-address options for the srec_cat -program correspond to the start address of the executable. + Care must be taken that the <tt/-offset/ and <tt/-execution-start-address/ + options for the <bf/srec_cat/ program correspond to the start address + of the executable. -Example for converting an executable "hello" that was built for the default -start address $0200 to an uploadable file "hello.c1p": + Example for converting an executable "hello" file that was built for the + default start address $0200 to an uploadable file "hello.c1p": -<tscreen> -srec_cat hello -binary -offset 0x200 -o hello.c1p -Ohio_Scientific -execution-start-address=0x200 -</tscreen> + <tscreen><verb> + srec_cat hello -bin -of 0x200 -o hello.c1p -os -esa=0x200 + </verb></tscreen> + + <tag/Hybrid/ + The linker can create an alternate format that contains two parts: + <enum> + <item>A text header that is understood by the 65V PROM monitor. + It is a boot loader that reads the second part. + <item>The default binary code that is described above. + </enum> + + You can make the alternate format by adding the option <tt/-u __BOOT__/ to + <tt/cl65/'s or <tt/ld65/'s command lines. + + This format doesn't need to be converted. It is smaller than the text-only + format. But, it cannot be loaded by <url + url="http://www.pcjs.org/docs/c1pjs/" name="C1Pjs">; you must use the + SRecord-produced text-only format with that emulator. + +</descrip> <sect>Memory layout<p> By default programs compiled for the osic1p target are configured for 32 kB RAM. -The RAM size can be configured via the symbol __HIMEM__. +The RAM size can be configured via the symbol <tt/__HIMEM__/. Special locations: <descrip> <tag/Program start address/ The default start address is $0200. The start address is configurable - via the compiler option --start-addr. + via the linker option <tt/--start-addr/. <tag/Stack/ The C runtime stack is located at the top of RAM and growing downwards. - The size is configurable via the symbol __STACKSIZE__. The default + The size is configurable via the symbol <tt/__STACKSIZE__/. The default stack size is $0400. <tag/Heap/ @@ -77,7 +99,7 @@ Special locations: runtime stack. <tag/Video RAM/ - The 1 kB video RAM is located at $D000. On the monitor only a subset + The 1 kB video RAM is located at $D000. On the monitor, only a subset of the available video RAM is visible. The address of the upper left corner of the visible area is $D085 and corresponds to conio cursor position (0, 0). @@ -87,9 +109,9 @@ Special locations: Example for building a program with start address $0300, stack size $0200 and RAM size $2000: -<tscreen> +<tscreen><verb> cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p hello.c -</tscreen> +</verb></tscreen> <sect>Linker configurations<p> @@ -112,16 +134,17 @@ To use this config file, assemble with <tt/-t osic1p/ and link with is used, while the latter supplies the actual config. When using <tt/cl65/, use both command line options. -Sample command line for <tt/cl65/: +Sample command lines for <tt/cl65/: <tscreen><verb> -cl65 -o program -t osic1p -C osic1p-asm.cfg source.s +cl65 -t osic1p -C osic1p-asm.cfg -o program source.s +cl65 -t osic1p -C osic1p-asm.cfg -u __BOOT__ -o program.lod source.s </verb></tscreen> <sect>Platform-specific header files<p> -Programs containing Ohio Scientific-specific code may use the <tt/osic1p.h/ -header file. +Programs containing Ohio Scientific-specific code may use the <tt/osic1p.h/ +header file. <sect1>Ohio Scientific-specific functions<p> diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s new file mode 100644 index 000000000..298de8f73 --- /dev/null +++ b/libsrc/osic1p/bootstrap.s @@ -0,0 +1,138 @@ +; +; 2015-03-06, Greg King +; + +; When you want to create a program with the alternate file format, +; add "-u __BOOT__" to the cl65/ld65 command line. Then, the linker +; will import this symbol name; and, link this module at the front +; of your program file. +; + .export __BOOT__:abs = 1 + + .import __RAM_START__, __RAM_SIZE__, __BSS_RUN__ + +; ------------------------------------------------------------------------ + +load_addr := __RAM_START__ +load_size = __BSS_RUN__ - __RAM_START__ +ram_top := __RAM_START__ + __RAM_SIZE__ + + .segment "BOOT" + +.ifdef ASM + + .include "osic1p.inc" + .macpack generic + +load := $08 ; private variables +count := $0A + +GETCHAR := $FFBF ; gets one character from ACIA + +FIRSTVISC = $85 ; Offset of first visible character in video RAM +LINEDIST = $20 ; Offset in video RAM between two lines + + lda #<load_addr + ldx #>load_addr + tay + stx load+1 + lda #<load_size + eor #$FF + sta count ; store (-size - 1) + lda #>load_size + eor #$FF + sta count+1 + +L1: inc count ; pre-count one's-complement upwards + bnz L2 + inc count+1 + bze L3 +L2: jsr GETCHAR ; (doesn't change .Y) + sta (load),y + +; Show that the file is being loaded by rotating an arrow on the screen. +; + tya + lsr a + lsr a + and #8 - 1 + ora #$10 ; eight arrow characters + sta SCRNBASE + FIRSTVISC + 2 * LINEDIST + 11 + + iny + bnz L1 + inc load+1 + bnz L1 ; branch always + +L3: jmp load_addr + +.else + +.mac hex1 h + .lobytes ((h) & $0F) + (((h) & $0F) > 9) * 7 + '0' +.endmac + +.mac hex2 h + hex1 (h) >> 4 + hex1 (h) >> 0 +.endmac + +.mac hex4 h + hex2 >(h) + hex2 <(h) +.endmac + +CR = $0D + + .byte CR, CR + .byte "." ; set an address + hex4 ram_top ; put loader where stack will sit + .byte "/" ; write bytes into RAM + +; ASCII-coded hexadecimal translation of the above assembly code. +; It was copied from the assembler listing. + + .byte "A9", CR + hex2 <load_addr + .byte CR, "A2", CR + hex2 >load_addr + .byte CR, "A8", CR + .byte "86", CR, "09", CR + .byte "A9", CR + hex2 <load_size + .byte CR, "49", CR, "FF", CR + .byte "85", CR, "0A", CR + .byte "A9", CR + hex2 >load_size + .byte CR, "49", CR, "FF", CR + .byte "85", CR, "0B", CR + + .byte "E6", CR, "0A", CR + .byte "D0", CR, "04", CR + .byte "E6", CR, "0B", CR + .byte "F0", CR, "16", CR + .byte "20", CR, "BF", CR, "FF", CR + .byte "91", CR, "08", CR + + .byte "98", CR + .byte "4A", CR + .byte "4A", CR + .byte "29", CR, "07", CR + .byte "09", CR, "10", CR + .byte "8D", CR, "D0", CR, "D0", CR + + .byte "C8", CR + .byte "D0", CR, "E6", CR + .byte "E6", CR, "09", CR + .byte "D0", CR, "E2", CR + + .byte "4C", CR + hex2 <load_addr + .byte CR + hex2 >load_addr + + .byte CR, "." + hex4 ram_top + .byte "G" ; go to address + +.endif From 9dbce378fed55a03a2ec3a912333b9f20acaac68 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 8 Mar 2015 10:06:00 -0400 Subject: [PATCH 106/351] Described how to change the boot loader's actions. --- libsrc/osic1p/bootstrap.s | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index 298de8f73..5116cc15a 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -1,5 +1,5 @@ ; -; 2015-03-06, Greg King +; 2015-03-08, Greg King ; ; When you want to create a program with the alternate file format, @@ -19,6 +19,19 @@ ram_top := __RAM_START__ + __RAM_SIZE__ .segment "BOOT" +; If you want to change how this bootstrap loader works, then: +; 1. edit this assembly source code, +; 2. define the constant ASM (uncomment the line below), +; 3. assemble this file (and, make a listing of that assembly), +; 4. copy the listing's hex codes into the .byte lines below (notice that most +; of the strings are followed by CR; it's required by the OS65V monitor) +; (be sure to match the listing's lines against the .byte lines), +; 5. undefine ASM (recomment the line), +; 6. assemble this file, again, +; 7. and, add the object file to "osic1p.lib". + +;ASM = 1 + .ifdef ASM .include "osic1p.inc" From 2ac615e27ec2075c306e644518c7709a340be596 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 8 Mar 2015 10:43:03 -0400 Subject: [PATCH 107/351] Mentioned in the documentation how we can make the new format be the default. --- doc/osi.sgml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/osi.sgml b/doc/osi.sgml index 0167b2bd1..1ceaec359 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -6,7 +6,7 @@ <author> <url url="mailto:stephan.muehlstrasser@web.de" name="Stephan Mühlstrasser">,<newline> <url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2015-03-07 +<date>2015-03-08 <abstract> An overview over the Ohio Scientific runtime system as it is implemented for the cc65 C @@ -73,7 +73,10 @@ Challenger 1P machine. This format doesn't need to be converted. It is smaller than the text-only format. But, it cannot be loaded by <url url="http://www.pcjs.org/docs/c1pjs/" name="C1Pjs">; you must use the - SRecord-produced text-only format with that emulator. + SRecord-produced text-only format with that emulator. (However, if you know + that you never will use C1Pjs, then you can edit the + <tt>cfg/osic1p*.cfg</tt> files; uncomment the lines that import <tt/__BOOT__/. + Then, you won't need to use <tt/-u __BOOT__/ on your command lines.) </descrip> From 87bce0d56bcc3f002cf20d179d49ce76b303138f Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 9 Mar 2015 06:17:28 -0400 Subject: [PATCH 108/351] Changed a comment in the osic1p configure files. --- cfg/osic1p-asm.cfg | 3 ++- cfg/osic1p.cfg | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cfg/osic1p-asm.cfg b/cfg/osic1p-asm.cfg index d9f128f8a..d8a2626f1 100644 --- a/cfg/osic1p-asm.cfg +++ b/cfg/osic1p-asm.cfg @@ -2,7 +2,8 @@ FEATURES { STARTADDRESS: default = $0200; } SYMBOLS { -# Add "-u __BOOT__" to a command line if you want a file that can be loaded directly. +# If you want ld65 to output a loadable-format file by default, then uncomment +# the next line. (Then, "-u __BOOT__" wouldn't be needed on the command line.) # __BOOT__: type = import; __STACKSIZE__: type = weak, value = $0400; # 1 kB stack __HIMEM__: type = weak, value = $8000; # 32 kB RAM diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index 0ad2f8939..17109adf0 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -2,7 +2,8 @@ FEATURES { STARTADDRESS: default = $0200; } SYMBOLS { -# Add "-u __BOOT__" to a command line if you want a file that can be loaded directly. +# If you want ld65 to output a loadable-format file by default, then uncomment +# the next line. (Then, "-u __BOOT__" wouldn't be needed on the command line.) # __BOOT__: type = import; __STACKSIZE__: type = weak, value = $0400; # 1 kB stack __HIMEM__: type = weak, value = $8000; # 32 kB RAM From 6230b6a81397ce9e9b1fa67f8da5adc7fa9fbc5a Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 9 Mar 2015 18:53:45 -0400 Subject: [PATCH 109/351] Completed the cc65 code that recognizes __CDECL__ as a calling convention qualifier. --- src/cc65/datatype.c | 16 ++++++------ src/cc65/datatype.h | 12 ++++++++- src/cc65/declare.c | 59 +++++++++++++++++++++++++++------------------ 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 053810b50..8d17d2851 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -290,18 +290,18 @@ void PrintType (FILE* F, const Type* T) fprintf (F, "union %s", ((SymEntry*) T->A.P)->Name); break; case T_TYPE_ARRAY: + if (T->A.L == UNSPECIFIED) { + fprintf (F, "[] "); + } else { + fprintf (F, "[%ld] ", T->A.L); + } /* Recursive call */ PrintType (F, T + 1); - if (T->A.L == UNSPECIFIED) { - fprintf (F, "[]"); - } else { - fprintf (F, "[%ld]", T->A.L); - } return; case T_TYPE_PTR: + fprintf (F, "* "); /* Recursive call */ PrintType (F, T + 1); - fprintf (F, "*"); return; case T_TYPE_FUNC: fprintf (F, "function returning "); @@ -659,7 +659,7 @@ Type* GetBaseElementType (Type* T) ** will return. Otherwise it will return the base element type, which means ** the element type that is not an array. */ -{ +{ while (IsTypeArray (T)) { ++T; } diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 598d0a228..92b3d0122 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -603,6 +603,16 @@ INLINE int IsQualCDecl (const Type* T) # define IsQualCDecl(T) (((T)->C & T_QUAL_CDECL) != 0) #endif +#if defined(HAVE_INLINE) +INLINE int IsQualCConv (const Type* T) +/* Return true if the given type has a calling convention qualifier */ +{ + return (T->C & T_QUAL_CCONV) != 0; +} +#else +# define IsQualCConv(T) (((T)->C & T_QUAL_CCONV) != 0) +#endif + int IsVariadicFunc (const Type* T) attribute ((const)); /* Return true if this is a function type or pointer to function type with ** variable parameter list diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 693c2116e..e6417c6a8 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2013, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -85,7 +85,7 @@ struct StructInitData { static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers); -/* Parse a type specificier */ +/* Parse a type specifier */ static unsigned ParseInitInternal (Type* T, int AllowFlexibleMembers); /* Parse initialization of variables. Return the number of data bytes. */ @@ -336,17 +336,28 @@ static void FixQualifiers (Type* DataType) while (T->C != T_END) { if (IsTypePtr (T)) { - /* Fastcall qualifier on the pointer? */ - if (IsQualFastcall (T)) { - /* Pointer to function which is not fastcall? */ - if (IsTypeFunc (T+1) && !IsQualFastcall (T+1)) { - /* Move the fastcall qualifier from the pointer to - ** the function. - */ - T[0].C &= ~T_QUAL_FASTCALL; - T[1].C |= T_QUAL_FASTCALL; + /* Calling convention qualifier on the pointer? */ + if (IsQualCConv (T)) { + /* Pull the convention off of the pointer */ + Q = T[0].C & T_QUAL_CCONV; + T[0].C &= ~T_QUAL_CCONV; + /* Pointer to a function which doesn't have an explicit convention? */ + if (IsTypeFunc (T + 1)) { + if (IsQualCConv (T + 1)) { + if (T[1].C == Q) { + /* TODO: The end of Declarator() catches this error. + ** Try to make it let the error be caught here, instead. + */ + Warning ("Pointer duplicates function's calling convention"); + } else { + Error ("Mismatch between pointer's and function's calling conventions"); + } + } else { + /* Move the qualifier from the pointer to the function. */ + T[1].C |= Q; + } } else { - Error ("Invalid `_fastcall__' qualifier for pointer"); + Error ("Not pointer to a function; can't use a calling convention"); } } @@ -355,8 +366,8 @@ static void FixQualifiers (Type* DataType) if (Q == T_QUAL_NONE) { /* No address size qualifiers specified */ if (IsTypeFunc (T+1)) { - /* Pointer to function. Use the qualifier from the function - ** or the default if the function don't has one. + /* Pointer to function. Use the qualifier from the function, + ** or the default if the function doesn't have one. */ Q = (T[1].C & T_QUAL_ADDRSIZE); if (Q == T_QUAL_NONE) { @@ -368,7 +379,7 @@ static void FixQualifiers (Type* DataType) T[0].C |= Q; } else { /* We have address size qualifiers. If followed by a function, - ** apply these also to the function. + ** apply them to the function also. */ if (IsTypeFunc (T+1)) { TypeCode FQ = (T[1].C & T_QUAL_ADDRSIZE); @@ -489,7 +500,7 @@ static void ParseEnumDecl (void) static int ParseFieldWidth (Declaration* Decl) -/* Parse an optional field width. Returns -1 if no field width is speficied, +/* Parse an optional field width. Returns -1 if no field width is specified, ** otherwise the width of the field. */ { @@ -862,7 +873,7 @@ NextMember: if (CurTok.Tok != TOK_COMMA) { static void ParseTypeSpec (DeclSpec* D, long Default, TypeCode Qualifiers) -/* Parse a type specificier */ +/* Parse a type specifier */ { ident Ident; SymEntry* Entry; @@ -1376,13 +1387,13 @@ static FuncDesc* ParseFuncDecl (void) static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) /* Recursively process declarators. Build a type array in reverse order. */ { - /* Read optional function or pointer qualifiers. These modify the - ** identifier or token to the right. For convenience, we allow the fastcall - ** qualifier also for pointers here. If it is a pointer-to-function, the - ** qualifier will later be transfered to the function itself. If it's a + /* Read optional function or pointer qualifiers. They modify the + ** identifier or token to the right. For convenience, we allow a calling + ** convention also for pointers here. If it's a pointer-to-function, the + ** qualifier later will be transfered to the function itself. If it's a ** pointer to something else, it will be flagged as an error. */ - TypeCode Qualifiers = OptionalQualifiers (T_QUAL_ADDRSIZE | T_QUAL_FASTCALL); + TypeCode Qualifiers = OptionalQualifiers (T_QUAL_ADDRSIZE | T_QUAL_CCONV); /* Pointer to something */ if (CurTok.Tok == TOK_STAR) { @@ -1390,10 +1401,10 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) /* Skip the star */ NextToken (); - /* Allow const, restrict and volatile qualifiers */ + /* Allow const, restrict, and volatile qualifiers */ Qualifiers |= OptionalQualifiers (T_QUAL_CONST | T_QUAL_VOLATILE | T_QUAL_RESTRICT); - /* Parse the type, the pointer points to */ + /* Parse the type that the pointer points to */ Declarator (Spec, D, Mode); /* Add the type */ From a798b1d6487c38345cf136617543671e4c85adbf Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 10 Mar 2015 05:53:52 -0400 Subject: [PATCH 110/351] Made __fastcall__ be the default calling convention for non-variadic functions. --- include/ace.h | 38 +++++++++++++++++++------------------- include/assert.h | 10 +++++----- include/cbm.h | 4 ++-- include/dbg.h | 10 +++++----- include/lynx.h | 12 ++++++------ include/zlib.h | 4 ++-- libsrc/cbm/cbm_load.c | 8 ++++---- src/cc65/codeinfo.c | 39 +++++++++++++++++++-------------------- src/cc65/expr.c | 9 +++++---- src/cc65/function.c | 11 +++++------ 10 files changed, 72 insertions(+), 73 deletions(-) diff --git a/include/ace.h b/include/ace.h index 8d9130085..fba672227 100644 --- a/include/ace.h +++ b/include/ace.h @@ -2,14 +2,14 @@ /* */ /* ace.h */ /* */ -/* ACE system specific definitions */ +/* ACE system-specific definitions */ /* */ /* */ /* */ -/* (C) 1998-2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2015, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -61,9 +61,9 @@ struct aceDirentBuf { char ad_name [17]; /* Name itself, ASCIIZ */ }; -int aceDirOpen (char* dir); -int aceDirClose (int handle); -int aceDirRead (int handle, struct aceDirentBuf* buf); +int __cdecl__ aceDirOpen (char* dir); +int __cdecl__ aceDirClose (int handle); +int __cdecl__ aceDirRead (int handle, struct aceDirentBuf* buf); /* Type of an ACE key. Key in low byte, shift mask in high byte */ typedef unsigned int aceKey; @@ -92,23 +92,23 @@ typedef unsigned int aceKey; #define aceOP_RPTRATE 11 /* Key repeat rate */ /* Console functions */ -void aceConWrite (char* buf, size_t count); -void aceConPutLit (int c); -void aceConPos (unsigned x, unsigned y); -void aceConGetPos (unsigned* x, unsigned* y); +void __cdecl__ aceConWrite (char* buf, size_t count); +void __cdecl__ aceConPutLit (int c); +void __cdecl__ aceConPos (unsigned x, unsigned y); +void __cdecl__ aceConGetPos (unsigned* x, unsigned* y); unsigned aceConGetX (void); unsigned aceConGetY (void); -char* aceConInput (char* buf, unsigned initial); +char __cdecl__* aceConInput (char* buf, unsigned initial); int aceConStopKey (void); aceKey aceConGetKey (void); -int aceConKeyAvail (aceKey* key); -void aceConKeyMat (char* matrix); -void aceConSetOpt (unsigned char opt, unsigned char val); -int aceConGetOpt (unsigned char opt); +int __cdecl__ aceConKeyAvail (aceKey* key); +void __cdecl__ aceConKeyMat (char* matrix); +void __cdecl__ aceConSetOpt (unsigned char opt, unsigned char val); +int __cdecl__ aceConGetOpt (unsigned char opt); /* Misc stuff */ -int aceMiscIoPeek (unsigned addr); -void aceMiscIoPoke (unsigned addr, unsigned char val); +int __cdecl__ aceMiscIoPeek (unsigned addr); +void __cdecl__ aceMiscIoPoke (unsigned addr, unsigned char val); diff --git a/include/assert.h b/include/assert.h index 87bc4ff02..ceabd2482 100644 --- a/include/assert.h +++ b/include/assert.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2000, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -42,7 +42,7 @@ #ifdef NDEBUG # define assert(expr) #else -extern void _afailed (const char*, unsigned); +extern void __cdecl__ _afailed (const char*, unsigned); # define assert(expr) ((expr)? (void)0 : _afailed(__FILE__, __LINE__)) #endif diff --git a/include/cbm.h b/include/cbm.h index 730b0b49e..1bc29bf4c 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -222,7 +222,7 @@ void cbm_k_unlsn (void); -unsigned int cbm_load (const char* name, unsigned char device, void* data); +unsigned int __cdecl__ cbm_load (const char* name, unsigned char device, void* data); /* Loads file "name", from given device, to given address -- or, to the load ** address of the file if "data" is the null pointer (like load"name",8,1 ** in BASIC). diff --git a/include/dbg.h b/include/dbg.h index 734ca06b8..7b4f67e31 100644 --- a/include/dbg.h +++ b/include/dbg.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2000, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -88,7 +88,7 @@ unsigned __fastcall__ DbgDisAsmLen (unsigned Addr); int __fastcall__ DbgIsRAM (unsigned Addr); /* Return true if we can read and write the given address */ -char* DbgMemDump (unsigned Addr, char* Buf, unsigned char Len); +char* __cdecl__ DbgMemDump (unsigned Addr, char* Buf, unsigned char Len); /* Create a line of a memory dump in the given buffer. The buffer contains ** the starting address (4 digits hex), then Len bytes in this format: ** "AAAA__XX_YY_ZZ_...". The passed char buffer must hold Len*3+5 bytes diff --git a/include/lynx.h b/include/lynx.h index e9c702994..72f3d5bfd 100644 --- a/include/lynx.h +++ b/include/lynx.h @@ -2,7 +2,7 @@ /* */ /* lynx.h */ /* */ -/* Lynx system specific definitions */ +/* Lynx system-specific definitions */ /* */ /* */ /* */ @@ -109,25 +109,25 @@ extern void lynx_160_102_16_tgi[]; /* Referred to by tgi_static_stddrv[] */ /* Sound support */ /*****************************************************************************/ -void lynx_snd_init (); +void lynx_snd_init (void); /* Initialize the sound driver */ -void lynx_snd_pause (); +void lynx_snd_pause (void); /* Pause sound */ -void lynx_snd_continue (); +void lynx_snd_continue (void); /* Continue sound after pause */ void __fastcall__ lynx_snd_play (unsigned char channel, unsigned char *music); /* Play tune on channel */ -void lynx_snd_stop (); +void lynx_snd_stop (void); /* Stop sound on all channels */ void __fastcall__ lynx_snd_stop_channel (unsigned char channel); /* Stop sound on all channels */ -unsigned char lynx_snd_active(); +unsigned char lynx_snd_active(void); /* Show which channels are active */ /*****************************************************************************/ diff --git a/include/zlib.h b/include/zlib.h index 9bc5dcb27..971095cd3 100644 --- a/include/zlib.h +++ b/include/zlib.h @@ -83,8 +83,8 @@ unsigned __fastcall__ inflatemem (char* dest, const char* source); */ -int uncompress (char* dest, unsigned* destLen, - const char* source, unsigned sourceLen); +int __cdecl__ uncompress (char* dest, unsigned* destLen, + const char* source, unsigned sourceLen); /* Original zlib description: diff --git a/libsrc/cbm/cbm_load.c b/libsrc/cbm/cbm_load.c index 695af504b..7d4a5086b 100644 --- a/libsrc/cbm/cbm_load.c +++ b/libsrc/cbm/cbm_load.c @@ -1,9 +1,9 @@ /* ** Marc 'BlackJack' Rintsch, 06.03.2001 ** -** unsigned int cbm_load(const char* name, -** unsigned char device, -** const unsigned char* data); +** unsigned int __cdecl__ cbm_load(const char* name, +** unsigned char device, +** const unsigned char* data); */ #include <cbm.h> @@ -11,7 +11,7 @@ /* loads file "name" from given device to given address or to the load address ** of the file if "data" is 0 */ -unsigned int cbm_load(const char* name, unsigned char device, void* data) +unsigned int __cdecl__ cbm_load(const char* name, unsigned char device, void* data) { /* LFN is set to 0; but, it's not needed for loading ** (BASIC V2 sets it to the value of the SA for LOAD). diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index be80319e7..ae264dce4 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2001-2012, Ullrich von Bassewitz */ +/* (C) 2001-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -386,33 +386,32 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg) ** Search for it in the list of builtin functions. */ if (Name[0] == '_') { - /* Search in the symbol table, skip the leading underscore */ SymEntry* E = FindGlobalSym (Name+1); - /* Did we find it in the top level table? */ + /* Did we find it in the top-level table? */ if (E && IsTypeFunc (E->Type)) { - FuncDesc* D = E->V.F.Func; - /* A function may use the A or A/X registers if it is a fastcall - ** function. If it is not a fastcall function but a variadic one, - ** it will use the Y register (the parameter size is passed here). - ** In all other cases, no registers are used. However, we assume - ** that any function will destroy all registers. + /* A variadic function will use the Y register (the parameter list + ** size is passed there). A fastcall function will use the A or A/X + ** registers. In all other cases, no registers are used. However, + ** we assume that any function will destroy all registers. */ - if (IsQualFastcall (E->Type) && D->ParamCount > 0) { - /* Will use registers depending on the last param */ - unsigned LastParamSize = CheckedSizeOf (D->LastParam->Type); - if (LastParamSize == 1) { - *Use = REG_A; - } else if (LastParamSize == 2) { - *Use = REG_AX; - } else { - *Use = REG_EAX; - } - } else if ((D->Flags & FD_VARIADIC) != 0) { + if ((D->Flags & FD_VARIADIC) != 0) { *Use = REG_Y; + } else if (!IsQualCDecl (E->Type) && D->ParamCount > 0) { + /* Will use registers depending on the last param. */ + switch (CheckedSizeOf (D->LastParam->Type)) { + case 1u: + *Use = REG_A; + break; + case 2u: + *Use = REG_AX; + break; + default: + *Use = REG_EAX; + } } else { /* Will not use any registers */ *Use = REG_NONE; diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 03374a521..c8c47f6aa 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1,6 +1,7 @@ /* expr.c ** -** Ullrich von Bassewitz, 21.06.1998 +** 1998-06-21, Ullrich von Bassewitz +** 2015-03-10, Greg King */ @@ -471,8 +472,8 @@ static void FunctionCall (ExprDesc* Expr) IsFuncPtr = IsTypeFuncPtr (Expr->Type); if (IsFuncPtr) { - /* Check wether it's a fastcall function that has parameters */ - IsFastcall = IsQualFastcall (Expr->Type + 1) && (Func->ParamCount > 0); + /* Check whether it's a fastcall function that has parameters */ + IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type + 1) && (Func->ParamCount > 0); /* Things may be difficult, depending on where the function pointer ** resides. If the function pointer is an expression of some sort @@ -517,7 +518,7 @@ static void FunctionCall (ExprDesc* Expr) } /* If we didn't inline the function, get fastcall info */ - IsFastcall = IsQualFastcall (Expr->Type); + IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type); } /* Parse the parameter list */ diff --git a/src/cc65/function.c b/src/cc65/function.c index d9f1eeac3..d80ba916a 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2012, Ullrich von Bassewitz */ +/* (C) 2000-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -460,6 +460,9 @@ void NewFunc (SymEntry* Func) */ if (D->ParamCount > 0 || (D->Flags & FD_VARIADIC) != 0) { g_importmainargs (); + + /* The start-up code doesn't fast-call main(). */ + Func->Type->C |= T_QUAL_CDECL; } /* Determine if this is a main function in a C99 environment that @@ -478,13 +481,9 @@ void NewFunc (SymEntry* Func) PushLiteralPool (Func); /* If this is a fastcall function, push the last parameter onto the stack */ - if (IsQualFastcall (Func->Type) && D->ParamCount > 0) { - + if ((D->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Func->Type) && D->ParamCount > 0) { unsigned Flags; - /* Fastcall functions may never have an ellipsis or the compiler is buggy */ - CHECK ((D->Flags & FD_VARIADIC) == 0); - /* Generate the push */ if (IsTypeFunc (D->LastParam->Type)) { /* Pointer to function */ From 604a5b4447d7a8c17411380fdf03c024a05587f5 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 13 Mar 2015 05:40:55 -0400 Subject: [PATCH 111/351] Changed the documentation to reflect the new fastcall/cdecl reality. --- doc/cc65.sgml | 75 +++++++++++++++++++++++++++++--------------- doc/customizing.sgml | 19 +++++------ 2 files changed, 60 insertions(+), 34 deletions(-) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index a6b4a07ee..bf7b1e336 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -3,7 +3,7 @@ <article> <title>cc65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2000-09-03, 2001-10-02, 2005-08-01 +<date>2015-03-13 <abstract> cc65 is a C compiler for 6502 targets. It supports several 6502 based home @@ -549,9 +549,9 @@ and the one defined by the ISO standard: be passed as parameters by value. However, struct assignment *is* possible. <p> -<item> Part of the C library is available only with fastcall calling - conventions (see below). It means that you must not mix pointers to - those functions with pointers to user-written, not-fastcall functions. +<item> Most of the C library is available only with the fastcall calling + convention (see below). It means that you must not mix pointers to + those functions with pointers to user-written, cdecl functions. <p> <item> The <tt/volatile/ keyword doesn't have an effect. This is not as bad as it sounds, since the 6502 has so few registers that it isn't @@ -589,29 +589,54 @@ This cc65 version has some extensions to the ISO C standard. <ref id="inline-asm" name="see there">. <p> -<item> There is a special calling convention named "fastcall". - The syntax for a function declaration using fastcall is +<item> The normal calling convention -- for non-variadic functions -- is + named "fastcall". The syntax for a function declaration that + <em/explicitly/ uses fastcall is - <tscreen><verb> - <return type> fastcall <function name> (<parameter list>) - </verb></tscreen> - or - <tscreen><verb> - <return type> __fastcall__ <function name> (<parameter list>) - </verb></tscreen> - An example would be - <tscreen><verb> - void __fastcall__ f (unsigned char c) - </verb></tscreen> - The first form of the fastcall keyword is in the user namespace and can - therefore be disabled with the <tt><ref id="option--standard" + <tscreen><verb> + <return type> fastcall <function name> (<parameter list>) + </verb></tscreen> + or + <tscreen><verb> + <return type> __fastcall__ <function name> (<parameter list>) + </verb></tscreen> + An example would be + <tscreen><verb> + void __fastcall__ f (unsigned char c) + </verb></tscreen> + The first form of the fastcall keyword is in the user namespace and can + therefore be disabled with the <tt><ref id="option--standard" name="--standard"></tt> command line option. - For functions declared as <tt/fastcall/, the rightmost parameter is not - pushed on the stack but left in the primary register when the function - is called. This will reduce the cost when calling assembler functions - significantly, especially when the function itself is rather small. - <p> + For functions that are <tt/fastcall/, the rightmost parameter is not + pushed on the stack but left in the primary register when the function + is called. That significantly reduces the cost of calling functions. + <p> + +<item> There is another calling convention named "cdecl". Variadic functions + (their prototypes have an ellipsis [<tt/.../]) always use this + convention. The syntax for a function declaration using cdecl is + + <tscreen><verb> + <return type> cdecl <function name> (<parameter list>) + </verb></tscreen> + or + <tscreen><verb> + <return type> __cdecl__ <function name> (<parameter list>) + </verb></tscreen> + An example would be + <tscreen><verb> + void __cdecl__ f (unsigned char c) + </verb></tscreen> + The first form of the cdecl keyword is in the user namespace and can + therefore be disabled with the <tt><ref id="option--standard" + name="--standard"></tt> command line option. + + For functions that are <tt/cdecl/, the rightmost parameter is pushed + onto the stack before the function is called. That increases the cost + of calling those functions, especially when they are called from many + places. + <p> <item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/. Both refer to the primary register that is used by the compiler to @@ -663,7 +688,7 @@ This cc65 version has some extensions to the ISO C standard. </verb></tscreen> Since the variable is of type <tt/void/ you may not use it as is. - However, taking the address of the variable results in a <tt/void*/ + However, taking the address of the variable results in a <tt/void */ which may be passed to any function expecting a pointer. See the <url url="geos.html" name="GEOS library document"> for examples diff --git a/doc/customizing.sgml b/doc/customizing.sgml index 23cf8c5e8..a54821c34 100644 --- a/doc/customizing.sgml +++ b/doc/customizing.sgml @@ -3,7 +3,7 @@ <article> <title>Defining a Custom cc65 Target <author>Bruce Reidenbach -<date>2010-02-22 +<date>2015-03-13 <abstract> This section provides step-by-step instructions on how to use the cc65 @@ -525,15 +525,16 @@ The first step in creating the assembly language code for the driver is to determine how to pass the C arguments to the assembly language routine. The cc65 toolset allows the user to specify whether the data is passed to a subroutine via the stack or by the processor registers by -using the <tt>__fastcall__</tt> function declaration (note that there -are two underscore characters in front of and two behind the -<tt>fastcall</tt> declaration). When <tt>__fastcall__</tt> is -specified, the rightmost argument in the function call is passed to the +using the <tt/__fastcall__/ and <tt/__cdecl__/ function qualifiers (note that +there are two underscore characters in front of and two behind each +qualifier). <tt/__fastcall__/ is the default. When <tt/__cdecl__/ <em/isn't/ +specified, and the function isn't variadic (i.e., its prototype doesn't have +an ellipsis), the rightmost argument in the function call is passed to the subroutine using the 6502 registers instead of the stack. Note that if there is only one argument in the function call, the execution overhead required by the stack interface routines is completely avoided. -Without <tt>__fastcall__</tt>, the argument is loaded in the A and X +With <tt/__cdecl__</tt>, the last argument is loaded into the A and X registers and then pushed onto the stack via a call to <tt>pushax</tt>. The first thing the subroutine does is retrieve the argument from the stack via a call to <tt>ldax0sp</tt>, which copies the values into the A @@ -561,7 +562,7 @@ _foo: jsr ldax0sp ; Retrieve A and X from the stack jmp incsp2 ; Pop A and X from the stack (includes return) </verb></tscreen> -If <tt>__fastcall__</tt> is specified, the argument is loaded into the A +If <tt/__cdecl__/ isn't specified, then the argument is loaded into the A and X registers as before, but the subroutine is then called immediately. The subroutine does not need to retrieve the argument since the value is already available in the A and X registers. @@ -596,7 +597,7 @@ variable which is stored in the zero page memory space in order to allow for retrieval of each character in the string via the indirect indexed addressing mode. -The assembly language routine is stored in a file names +The assembly language routine is stored in a file named "rs232_tx.s" and is shown below: <tscreen><code> @@ -680,7 +681,7 @@ all of the behind-the-scene work is transparent to the user. #define TX_FIFO_FULL (FIFO_STATUS & 0x01) #define RX_FIFO_EMPTY (FIFO_STATUS & 0x02) -extern void wait (); +extern void wait (void); extern void __fastcall__ rs232_tx (char *str); int main () { From 66d79da3c2d96d5eafa879776971085c13f9ab01 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 13 Mar 2015 05:46:40 -0400 Subject: [PATCH 112/351] Made cbm_load() be a fastcall function. --- include/cbm.h | 2 +- libsrc/cbm/cbm_load.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/cbm.h b/include/cbm.h index 1bc29bf4c..701924d57 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -222,7 +222,7 @@ void cbm_k_unlsn (void); -unsigned int __cdecl__ cbm_load (const char* name, unsigned char device, void* data); +unsigned int __fastcall__ cbm_load (const char* name, unsigned char device, void* data); /* Loads file "name", from given device, to given address -- or, to the load ** address of the file if "data" is the null pointer (like load"name",8,1 ** in BASIC). diff --git a/libsrc/cbm/cbm_load.c b/libsrc/cbm/cbm_load.c index 7d4a5086b..eba864fcc 100644 --- a/libsrc/cbm/cbm_load.c +++ b/libsrc/cbm/cbm_load.c @@ -11,7 +11,7 @@ /* loads file "name" from given device to given address or to the load address ** of the file if "data" is 0 */ -unsigned int __cdecl__ cbm_load(const char* name, unsigned char device, void* data) +unsigned int __fastcall__ cbm_load(const char* name, unsigned char device, void* data) { /* LFN is set to 0; but, it's not needed for loading ** (BASIC V2 sets it to the value of the SA for LOAD). From 38231a5cc69a8d31e0fabc7e3bf47b685a107548 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 13 Mar 2015 07:35:47 -0400 Subject: [PATCH 113/351] Made _afailed() and uncompress() be fastcall functions. --- include/assert.h | 4 ++-- include/zlib.h | 6 +++--- libsrc/cbm/cbm_load.c | 6 +++--- libsrc/common/_afailed.c | 5 +++-- libsrc/dbg/dbgdump.s | 2 +- libsrc/zlib/uncompress.c | 4 ++-- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/assert.h b/include/assert.h index ceabd2482..504964dc2 100644 --- a/include/assert.h +++ b/include/assert.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2000, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -42,7 +42,7 @@ #ifdef NDEBUG # define assert(expr) #else -extern void __cdecl__ _afailed (const char*, unsigned); +extern void __fastcall__ _afailed (const char*, unsigned); # define assert(expr) ((expr)? (void)0 : _afailed(__FILE__, __LINE__)) #endif diff --git a/include/zlib.h b/include/zlib.h index 971095cd3..8fa6a2bd1 100644 --- a/include/zlib.h +++ b/include/zlib.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2001 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 */ /* library, version 1.1.3, (C) 1995-1998 Jean-loup Gailly and Mark Adler. */ @@ -83,8 +83,8 @@ unsigned __fastcall__ inflatemem (char* dest, const char* source); */ -int __cdecl__ uncompress (char* dest, unsigned* destLen, - const char* source, unsigned sourceLen); +int __fastcall__ uncompress (char* dest, unsigned* destLen, + const char* source, unsigned sourceLen); /* Original zlib description: diff --git a/libsrc/cbm/cbm_load.c b/libsrc/cbm/cbm_load.c index eba864fcc..c1c6f568a 100644 --- a/libsrc/cbm/cbm_load.c +++ b/libsrc/cbm/cbm_load.c @@ -1,9 +1,9 @@ /* ** Marc 'BlackJack' Rintsch, 06.03.2001 ** -** unsigned int __cdecl__ cbm_load(const char* name, -** unsigned char device, -** const unsigned char* data); +** unsigned int __fastcall__ cbm_load(const char* name, +** unsigned char device, +** const unsigned char* data); */ #include <cbm.h> diff --git a/libsrc/common/_afailed.c b/libsrc/common/_afailed.c index 4e56b93f2..7c6df4a2c 100644 --- a/libsrc/common/_afailed.c +++ b/libsrc/common/_afailed.c @@ -1,7 +1,8 @@ /* ** _afailed.c ** -** Ullrich von Bassewitz, 06.06.1998 +** 1998-06-06, Ullrich von Bassewitz +** 2015-03-13, Greg King */ @@ -11,7 +12,7 @@ -void _afailed (char* file, unsigned line) +void __fastcall__ _afailed (char* file, unsigned line) { fprintf (stderr, "ASSERTION FAILED IN %s(%u)\n", file, line); exit (2); diff --git a/libsrc/dbg/dbgdump.s b/libsrc/dbg/dbgdump.s index b2045872f..8ab646d21 100644 --- a/libsrc/dbg/dbgdump.s +++ b/libsrc/dbg/dbgdump.s @@ -1,7 +1,7 @@ ; ; Ullrich von Bassewitz, 11.08.1998 ; -; char* DbgMemDump (unsigend Addr, char* Buf, unsigned char Length); +; char* __cdecl__ DbgMemDump (unsigend Addr, char* Buf, unsigned char Length); ; .export _DbgMemDump diff --git a/libsrc/zlib/uncompress.c b/libsrc/zlib/uncompress.c index 7810eb4f8..4e449a3ef 100644 --- a/libsrc/zlib/uncompress.c +++ b/libsrc/zlib/uncompress.c @@ -6,8 +6,8 @@ #include <zlib.h> -int uncompress (char* dest, unsigned* destLen, - const char* source, unsigned sourceLen) +int __fastcall__ uncompress (char* dest, unsigned* destLen, + const char* source, unsigned sourceLen) { unsigned len; unsigned char* ptr; From b452bdc5e46ce6626293ba8ac1f8a4a9f37f73b6 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 13 Mar 2015 12:18:43 -0400 Subject: [PATCH 114/351] Catch fastcall pointers to variadic functions. --- src/cc65/declare.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index e6417c6a8..4fab3ea0a 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -353,8 +353,12 @@ static void FixQualifiers (Type* DataType) Error ("Mismatch between pointer's and function's calling conventions"); } } else { - /* Move the qualifier from the pointer to the function. */ - T[1].C |= Q; + if (Q == T_QUAL_FASTCALL && IsVariadicFunc (T + 1)) { + Error ("Variadic-function pointers cannot be `__fastcall__'"); + } else { + /* Move the qualifier from the pointer to the function. */ + T[1].C |= Q; + } } } else { Error ("Not pointer to a function; can't use a calling convention"); From 72a9e331e3d4f741c7be8ee2f12be283ca48b373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 14 Mar 2015 00:01:12 +0100 Subject: [PATCH 115/351] Fixed uninitialized use of low byte of address "load". --- cfg/osic1p-asm.cfg | 2 +- cfg/osic1p.cfg | 2 +- libsrc/osic1p/bootstrap.s | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cfg/osic1p-asm.cfg b/cfg/osic1p-asm.cfg index d8a2626f1..4000890be 100644 --- a/cfg/osic1p-asm.cfg +++ b/cfg/osic1p-asm.cfg @@ -11,7 +11,7 @@ SYMBOLS { MEMORY { # for size of ZP, see runtime/zeropage.s and c1p/extzp.s ZP: file = "", define = yes, start = $0002, size = $001A + $0006; - HEAD: file = %O, start = $0000, size = $00AA; + HEAD: file = %O, start = $0000, size = $00B6; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index 17109adf0..b05eeb3d5 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -11,7 +11,7 @@ SYMBOLS { MEMORY { # for size of ZP, see runtime/zeropage.s and c1p/extzp.s ZP: file = "", define = yes, start = $0002, size = $001A + $0006; - HEAD: file = %O, start = $0000, size = $00AA; + HEAD: file = %O, start = $0000, size = $00B6; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } SEGMENTS { diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index 5116cc15a..b7c10a525 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -45,6 +45,8 @@ GETCHAR := $FFBF ; gets one character from ACIA FIRSTVISC = $85 ; Offset of first visible character in video RAM LINEDIST = $20 ; Offset in video RAM between two lines + lda #0 + sta load lda #<load_addr ldx #>load_addr tay @@ -105,6 +107,8 @@ CR = $0D ; ASCII-coded hexadecimal translation of the above assembly code. ; It was copied from the assembler listing. + .byte "A9", CR, "00", CR + .byte "85", CR, "08", CR .byte "A9", CR hex2 <load_addr .byte CR, "A2", CR From 4836cf9842722bde1d5ac760ef91b80c6fe8fd15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sat, 14 Mar 2015 00:06:00 +0100 Subject: [PATCH 116/351] Fix bad tabbing --- libsrc/osic1p/bootstrap.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index b7c10a525..806532791 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -45,8 +45,8 @@ GETCHAR := $FFBF ; gets one character from ACIA FIRSTVISC = $85 ; Offset of first visible character in video RAM LINEDIST = $20 ; Offset in video RAM between two lines - lda #0 - sta load + lda #0 + sta load lda #<load_addr ldx #>load_addr tay From 15c64c39268a24e4470096cf3bee85bf3ef1e027 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 14 Mar 2015 18:41:57 +0100 Subject: [PATCH 117/351] Replaced 'Limits' with 'Notes'. Quite some items in the 'Limits' sections aren't actual limitations so it seems appropriate to just use a more neutral term. --- doc/funcref.sgml | 507 ++++++++++++++++++++++------------------------- 1 file changed, 236 insertions(+), 271 deletions(-) diff --git a/doc/funcref.sgml b/doc/funcref.sgml index 60b8360ed..cc45d9037 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -744,8 +744,7 @@ communication. <tag/Description/The function is called with the type of a directory entry taken from a <tt/struct dirent/ and returns true if the entry designates a directory. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. </itemize> <tag/Availability/cc65 @@ -768,8 +767,7 @@ a directory. <tag/Description/The function is called with the type of a directory entry taken from a <tt/struct dirent/ and returns true if the entry designates a disk label. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. </itemize> <tag/Availability/cc65 @@ -792,8 +790,7 @@ a disk label. <tag/Description/The function is called with the type of a directory entry taken from a <tt/struct dirent/ and returns true if the entry designates a link. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. </itemize> <tag/Availability/cc65 @@ -816,8 +813,7 @@ a link. <tag/Description/The function is called with the type of a directory entry taken from a <tt/struct dirent/ and returns true if the entry designates a regular file. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>A "regular file" means anything with data in it. This might still mean that special processing is needed, when accessing the file. Relative files of @@ -841,8 +837,7 @@ the CBM systems are classified as being "regular" files, for example. <tag/Header/<tt/<ref id="stdlib.h" name="stdlib.h">/ <tag/Declaration/<tt/void __fastcall__ _heapadd (void* mem, size_t size);/ <tag/Description/The function adds a block of raw memory to the heap. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The minimum blocksize that can be added is 6 bytes; the function will ignore smaller blocks. </itemize> @@ -870,8 +865,7 @@ ignore smaller blocks. <tag/Description/The function returns the size of a block that must have previously been allocated by <tt/<ref id="malloc" name="malloc">/, <tt/<ref id="calloc" name="calloc">/ or <tt/<ref id="realloc" name="realloc">/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>Passing a pointer to a block that was is not the result of one of the allocation functions, or that has been free'd will give unpredicable results. </itemize> @@ -921,8 +915,7 @@ be allocated from the heap using <tt/<ref id="malloc" name="malloc">/. <tag/Declaration/<tt/size_t __fastcall__ _heapmemavail (void);/ <tag/Description/The function returns the total number of bytes available on the heap. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>This function is of less use than usually assumed, since the returned heap space may be available but not in one block. So even if this function says that several times more heap space is available than needed, <ref @@ -955,8 +948,7 @@ a colon and a blank. Then the error message for the current contents of <tt/_oserror/ are printed followed by a newline. The message output is the same as returned by <tt/<ref id="_stroserror" name="_stroserror">/ with an argument of <tt/_oserror/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>Since operating system specific error code are - you guessed it - operating system specific, the value in <tt/_oserror/ and the message that is printed depends on the cc65 target. @@ -982,7 +974,7 @@ be used in presence of a prototype. <tag/Description/The function initializes the random number generator with a seed derived from fast changing hardware events, so the seed itself can be considered random to a certain degree. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The randomness of the seed depends on the machine hardware. </itemize> <tag/Availability/cc65 @@ -1003,7 +995,7 @@ considered random to a certain degree. <tag/Declaration/<tt/const char* __fastcall__ _stroserror (unsigned char errcode);/ <tag/Description/<tt/_stroserror/ will return a string describing the given operating system specific error code. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Since operating system specific error code are - you guessed it - operating system specific, the parameter and the string returned depend on the cc65 target. @@ -1028,7 +1020,7 @@ used in presence of a prototype. <tag/Description/<tt/_swap/ will swap (exchange) the contents of the two memory areas pointed to by <tt/p/ and <tt/q/. Both memory areas are assumed to be <tt/size/ bytes in size. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The memory areas may not overlap, otherwise the results are undefined. <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. @@ -1054,7 +1046,7 @@ specified in the <tt/pc/ member of the passed <tt/regs/ structure. All registers and the CPU flags are set to the values given in the <tt/regs/ structure. On return from the subroutine, the new values of the registers and flags are stored back overwriting the old values. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Bits 4 and 5 of the flags value in the <tt/regs/ structure are ignored when calling the subroutine (they are unchanged from their current values). <item>The function is only available as fastcall function, so it may only be @@ -1075,7 +1067,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void BRK (void);/ <tag/Description/The function will insert a 6502 BRK instruction into the code which may be used to trigger a debugger. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>The inserted instruction may lead to unexpected results if no debugger is present. @@ -1099,7 +1091,7 @@ is present. <tag/Description/The function will insert a 6502 CLI instruction into the code, so interrupts are enabled. Enabling interrupts has no effects if they are already enabled (the default). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>Disabling interrupts may lead to unexpected results. </itemize> @@ -1121,7 +1113,7 @@ already enabled (the default). <tag/Declaration/<tt/unsigned char PEEK (unsigned addr);/ <tag/Description/The function will read the absolute memory given by <tt/addr/ and return the value read. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>This function depends highly on the platform and environment. </itemize> @@ -1144,7 +1136,7 @@ and return the value read. <tag/Description/The function will read the absolute memory given by <tt/addr/ and return the value read. The byte read from the higher address is the high byte of the return value. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>This function depends highly on the platform and environment. <item>The order in which the two bytes are read is unspecified and may @@ -1168,7 +1160,7 @@ depend of the address expression used. <tag/Declaration/<tt/void POKE (unsigned addr, unsigned char val);/ <tag/Description/The function writes the value <tt/val/ to the absolute memory address given by <tt/addr/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>This function depends highly on the platform and environment. <item>Careless use will cause the program to act strange or may crash the @@ -1193,7 +1185,7 @@ machine. <tag/Description/The function writes the value <tt/val/ to the absolute memory address given by <tt/addr/. The low byte of <tt/val/ is written to the <tt/addr/, the high byte is written to <tt/addr+1/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>This function depends highly on the platform and environment. <item>Careless use will cause the program to act strange or may crash the @@ -1220,7 +1212,7 @@ depend of the address expression used. <tag/Description/The function will insert a 6502 SEI instruction into the code, so interrupts are disabled. Note that non maskable interrupts cannot be disabled. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. <item>Disabling interrupts may lead to unexpected results. </itemize> @@ -1261,7 +1253,7 @@ on stderr, then terminates the program with an exit code of 3. <tag/Declaration/<tt/int __fastcall__ abs (int v);/ <tag/Description/<tt/abs/ returns the absolute value of the argument passed to the function. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The return value is undefined if <tt/INT_MIN/ is passed to the function. <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. @@ -1284,7 +1276,7 @@ used in presence of a prototype. <tag/Description/<tt/assert/ is a macro that expands to a <tt/id/ statement. If the condition evaluates t zero (false), assert prints a message on stderr and aborts the program. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. </itemize> <tag/Availability/ISO 9899 @@ -1308,7 +1300,7 @@ on stderr and aborts the program. terminates, they are called in LIFO order (the last function registered is called first). <tt/atexit/ returns zero on success and a nonzero value on failure. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>A maximum of 5 exit functions can be registered. <item>There is no way to unregister an exit function. <item>The function is only available as fastcall function, so it may only be @@ -1366,7 +1358,7 @@ atmos_save("hires", 0xa000, 0xc000); <tag/Declaration/<tt/int __fastcall__ atoi (const char* s);/ <tag/Description/<tt/atoi/ converts the given string into an integer. Conversion stops as soon as any invalid character is encountered. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>There is no way to detect any conversion errors. <item>The function does not check for an numerical overflow when converting. <item>The function is only available as fastcall function, so it may only be @@ -1393,7 +1385,7 @@ used in presence of a prototype. <tag/Declaration/<tt/long __fastcall__ atol (const char* s);/ <tag/Description/<tt/atol/ converts the given string into a long integer. Conversion stops as soon as any invalid character is encountered. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>There is no way to detect any conversion errors. <item>The function does not check for an numerical overflow when converting. <item>The function is only available as fastcall function, so it may only be @@ -1421,7 +1413,7 @@ used in presence of a prototype. <tag/Description/The function will set a new background color and return the old (current) one. The background color is valid for the whole text output area of the screen, not just for new text. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Background colors are system dependent. The function may have no effect on systems where the background color cannot be changed. <item>The function is only available as fastcall function, so it may only be @@ -1445,7 +1437,7 @@ used in presence of a prototype. <tag/Declaration/<tt/unsigned char __fastcall__ bordercolor (unsigned char color);/ <tag/Description/The function will set a new border color. It returns the old (current) border color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Border colors are system dependent. The function may have no effect on systems where the border color cannot be changed. <item>The function is only available as fastcall function, so it may only @@ -1474,8 +1466,7 @@ matches the one pointed to by <tt/key/. <tt/base/ is the address of the array, <tt/n/ is the number of elements, <tt/size/ the size of an element and <tt/cmp/ the function used to compare the members against the key. The function returns a pointer to the member found, or <tt/NULL/ if there was no match. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The contents of the array must be sorted in ascending order according to the compare function given. <item>If there are multiple members that match the key, the function will @@ -1500,8 +1491,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ bzero (void* p, size_t count);/ <tag/Description/<tt/bzero/ fills the memory area pointed to by <tt/p/ with zero. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is non standard and therefore only available in non ANSI mode. You should use <tt/<ref id="memset" name="memset">/ instead. <item>The function is only available as fastcall function, so it may only @@ -1526,7 +1516,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="c128.h" name="c128.h">/ <tag/Declaration/<tt/void c64mode (void);/ <tag/Description/The function will cause the machine to reboot into C64 mode. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is specific to the C128. <item>The function will not return to the caller. </itemize> @@ -1547,8 +1537,7 @@ be used in presence of a prototype. of size <tt/size/, clears the whole block with binary zeroes and returns a pointer to it. On error (not enough memory available), <tt/calloc/ returns <tt/NULL/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>Clearing the memory may not have the expected effect on all platforms: pointers in the block may not be <tt/NULL/ and floating point variables may not be zero (0.0). In other words: The "clearing" effect of this function @@ -1581,7 +1570,7 @@ be used in presence of a prototype. gets from the current TALKer on the serial bus. In order to receive the data, the device must have previously been sent a command to TALK and a secondary address if it needs one. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1603,7 +1592,7 @@ sent a command to TALK and a secondary address if it needs one. Device must first have been OPENed and then designated as the input channel by the CHKIN routine. When this function is called, the next byte of data available from the device is returned. Exception is the routine for the keyboard device (which is the default input device). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1629,7 +1618,7 @@ printed to the screen, which is the default output device. If the cassette is the current device, outputting a byte will only add it to the buffer. No actual transmission of data will occur until the 192-byte buffer is full. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1659,7 +1648,7 @@ address as the current secondary address. If the device on the channel is a serial device, which requires a TALK command and sometimes a secondary address, function will send them over the serial bus. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1687,7 +1676,7 @@ secondary address if necessary. This routine always buffers the current character, and defers sending it until the next byte is buffered. When the UNLISTEN command is sent, the last byte will be sent with an End or Identify (EOI). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1716,7 +1705,7 @@ file, its device as the current device, and its secondary address as the current secondary address. If the device on the channel uses the serial bus, and therefore requires a LISTEN command and possibly a secondary address, this information will be sent on the bus. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1739,7 +1728,7 @@ only be used in presence of a prototype. <tag/Description/It closes all open files, by resetting the index into open files to zero and restores the default I/O devices. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1761,7 +1750,7 @@ zero and restores the default I/O devices. <tag/Description/It is used to close a logical file after all I/O operations involving that file have been completed. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1787,7 +1776,7 @@ the screen. Also, if the current input device was formerly a serial device, the routine sends it an UNTALK command on the serial bus, and if a serial device was formerly the current output device, the routine sends it an UNLISTEN command. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1807,7 +1796,7 @@ sends it an UNLISTEN command. <tag/Header/<tt/<ref id="cbm.h" name="cbm.h">/ <tag/Declaration/<tt/unsigned char cbm_k_getin (void);/ <tag/Description/Function gets a character from the current input device. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1835,7 +1824,7 @@ VIC-20, and future models of the Commodore 64. If the I/O locations for a program are set by a call to this function, they should still remain compatible with future versions of the Commodore 64, the KERNAL and BASIC. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1858,7 +1847,7 @@ receive data. The KERNAL routine will OR the supplied device number bit by bit to convert it to a listen address, then transmits this data as a command on the serial bus. The specified device will then go into listen mode, and be ready to accept information. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1888,7 +1877,7 @@ loaded into memory starting at the location specified by the header. Function returns the address of the highest RAM location loaded. Before this function can be called, the KERNAL SETLFS, and SETNAM routines must be called. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1914,7 +1903,7 @@ Input/Output operations. In order to specify the logical file number, the device number, and the secondary address if any, the cbm_k_setlfs() function must first be called. Likewise, in order to designate the filename, the cbm_k_setnam() function must be used first. After these two functions are called, cbm_k_open() is then called. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1935,7 +1924,7 @@ functions are called, cbm_k_open() is then called. <tag/Header/<tt/<ref id="cbm.h" name="cbm.h">/ <tag/Declaration/<tt/unsigned char cbm_k_readst (void);/ <tag/Description/This function returns the current status of the I/O devices. It is usually called after new communication to an I/O device and gives information about device status, or errors that have occurred during the I/O operation. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -1957,7 +1946,7 @@ functions are called, cbm_k_open() is then called. used before calling this function. However, a file name is not required to SAVE to device 1 (the Datassette(TM) recorder). Any attempt to save to other devices without using a file name results in an error. NOTE: Device 0 (the keyboard), device 2 (RS-232), and device 3 (the screen) cannot be SAVEd to. If the attempt is made, an error occurs, and the SAVE is stopped. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -1980,7 +1969,7 @@ only be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV, unsigned char SA);/ <tag/Description/This functions sets up the logical file by setting its number, device address, and secondary address. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2001,7 +1990,7 @@ only be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cbm_k_setnam (const char* Name);/ <tag/Description/This function is used to set up the file name for the OPEN, SAVE, or LOAD operations. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2024,7 +2013,7 @@ only be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cbm_k_talk (unsigned char dev);/ <tag/Description/When called, it ORs the device number with the TALK code (64, $40) and sends it on the serial bus. This commands the device to TALK. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2050,7 +2039,7 @@ bus. Only devices previously commanded to LISTEN are affected. This function is normally used after the host computer is finished sending data to external devices. Sending the UNLISTEN commands the listening devices to get off the serial bus so it can be used for other purposes. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item> </itemize> <tag/Availability/cc65 @@ -2070,7 +2059,7 @@ to get off the serial bus so it can be used for other purposes. <tag/Declaration/<tt/void __fastcall__ cclear (unsigned char length);/ <tag/Description/The function clears part of a line by writing <tt/length/ spaces in the current text color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2094,7 +2083,7 @@ at a specific screen position. <tag/Description/The function moves the cursor to a specific position, and will then clear part of the line by writing <tt/length/ spaces in the current text color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2118,7 +2107,7 @@ only be used in presence of a prototype. no character available, <tt/cgetc/ waits until the user presses a key. If the cursor is enabled by use of the <tt/cursor/ function, a blinking cursor is displayed while waiting. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>If the system supports a keyboard buffer, <tt/cgetc/ will fetch a key from this buffer and wait only if the buffer is empty. </itemize> @@ -2140,7 +2129,7 @@ from this buffer and wait only if the buffer is empty. <tag/Declaration/<tt/void __fastcall__ chline (unsigned char length);/ <tag/Description/The function outputs a horizontal line with the given length starting at the current cursor position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The character used to draw the horizontal line is system dependent. If available, a line drawing character is used. Drawing a line that is partially off screen leads to undefined behaviour. @@ -2166,7 +2155,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ chlinexy (unsigned char x, unsigned char y, unsigned char length);/ <tag/Description/The function outputs a horizontal line with the given length starting at a given position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The character used to draw the horizontal line is system dependent. If available, a line drawing character is used. Drawing a line that is partially off screen leads to undefined behaviour. @@ -2192,7 +2181,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ clearerr (FILE* f);/ <tag/Description/<tt/clearerr/ clears the error and end-of-file status indicators for the stream <tt/f/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2216,7 +2205,7 @@ used in presence of a prototype. time used by the program. The time is returned in implementation defined units. It can be converted to seconds by dividing by the value of the macro <tt/CLOCKS_PER_SEC/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Since the machines, cc65 generated programs run on, cannot run multiple processes, the function will actually return the time since some implementation defined point in the past. @@ -2257,7 +2246,7 @@ the upper left corner. <tag/Description/The function closes the given file descriptor. It returns zero on success and -1 on error. If an error occurs, the cause can be determined by reading the <tt/errno/ variable. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2280,7 +2269,7 @@ be used in presence of a prototype. <tag/Description/The function closes the given directory descriptor. It returns zero on success and -1 on error. If an error occurs, the cause can be determined by reading the <tt/errno/ variable. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2303,7 +2292,7 @@ be used in presence of a prototype. <tag/Description/<tt/creat/ creates a new file and returns the file descriptor associated with it. On error, -1 is returned and an error code is stored in <tt/errno/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item><tt/creat/ is identical to calling <tt/<ref id="open" name="open">/ with <tt/flags/ equal to <tt/O_WRONLY | O_CREAT | O_TRUNC/. <item>The function is only available as fastcall function, so it may only @@ -2329,7 +2318,7 @@ be used in presence of a prototype. formatted according to the format string given. The resulting string is output to the console. <tt/cprintf/ supports the same format specifiers as <tt/printf/. <!-- <tt/<ref id="printf" name="printf">/. --> -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Like all other <tt/conio/ output functions, <tt/cprintf/ distinguishes between <tt/\r/ and <tt/\n/. </itemize> @@ -2354,7 +2343,7 @@ between <tt/\r/ and <tt/\n/. <tag/Declaration/<tt/void __fastcall__ cputc (char c);/ <tag/Description/Output one character to the console at the current cursor position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Like all other <tt/conio/ output functions, <tt/cputc/ distinguishes between <tt/\r/ and <tt/\n/. <item>The function is only available as fastcall function, so it may only @@ -2381,7 +2370,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);/ <tag/Description/<tt/cputcxy/ moves the cursor to the given x/y position on the screen and outputs one character. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Like all other <tt/conio/ output functions, <tt/cputcxy/ distinguishes between <tt/\r/ and <tt/\n/. <item>The function is only available as fastcall function, so it may only @@ -2408,7 +2397,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cputs (const char* s);/ <tag/Description/The function outputs the given string on the console at the current cursor position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Like all other <tt/conio/ output functions, <tt/cputs/ distinguishes between <tt/\r/ and <tt/\n/. <item>The function is only available as fastcall function, so it may only @@ -2435,7 +2424,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cputsxy (unsigned char x, unsigned char y, const char* s);/ <tag/Description/<tt/cputsxy/ moves the cursor to the given x/y position, and outputs the string <tt/s/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Like all other <tt/conio/ output functions, <tt/cputsxy/ distinguishes between <tt/\r/ and <tt/\n/. <item>The function is only available as fastcall function, so it may only @@ -2463,7 +2452,7 @@ be used in presence of a prototype. <tag/Description/If the argument to the function is non zero, a blinking cursor will be enabled when the <tt/cgetc/ function waits for input from the keyboard. If the argument is zero, <tt/cgetc/ will wait without a blinking cursor. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2485,7 +2474,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cvline (unsigned char length);/ <tag/Description/The function outputs a vertical line with the given length starting at the current cursor position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The character used to draw the vertical line is system dependent. If available, a line drawing character is used. Drawing a line that is partially off screen leads to undefined behaviour. @@ -2511,7 +2500,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ cvlinexy (unsigned char x, unsigned char y, unsigned char length);/ <tag/Description/The function outputs a vertical line with the given length starting at a given position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The character used to draw the vertical line is system dependent. If available, a line drawing character is used. Drawing a line that is partially off screen leads to undefined behaviour. @@ -2537,8 +2526,7 @@ used in presence of a prototype. <tag/Declaration/<tt/div_t __fastcall__ div (int numer, int denom);/ <tag/Description/<tt/div/ divides <tt/numer/ by <tt/denom/ and returns the quotient and remainder in a <tt/div_t/ structure. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2562,7 +2550,7 @@ the contents of the memory window have been changed, these changes may be lost if <tt/<ref id="em_map" name="em_map">/, <tt/<ref id="em_use" name="em_use">/, <tt/<ref id="em_copyfrom" name="em_copyfrom">/ or <tt/<ref id="em_copyto" name="em_copyto">/ are called without calling <tt/em_commit/ first. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Calling <tt/em_commit/ does not necessarily mean that changes to the memory window are discarded, it does just mean that the drivers is allowed to discard it. @@ -2591,7 +2579,7 @@ loaded. <tag/Description/Copy data from extended memory into linear memory. Source and target addresses as well as the number of bytes to transfer are specified in the <tt/em_copy/ structure that is passed as a parameter. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Calling <tt/em_copyfrom/ will invalidate the memory window, so if you made any changes to the data in the window, call <tt/<ref id="em_commit" name="em_commit">/ first, or the changes are lost. @@ -2620,7 +2608,7 @@ loaded. <tag/Description/Copy data from linear into extended memory. Source and target addresses as well as the number of bytes to transfer are specified in the <tt/em_copy/ structure that is passed as a parameter. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Calling <tt/em_copyto/ will invalidate the memory window, so if you made any changes to the data in the window, call <tt/<ref id="em_commit" name="em_commit">/ first, or the changes are lost. @@ -2649,7 +2637,7 @@ loaded. <tag/Description/The function installs an already loaded extended memory driver and returns an error code. The function may be used to install a driver linked statically to the program. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Not all drivers are able to detect if the supported hardware is really present. <item>The function is only available as fastcall function, so it may only be @@ -2675,7 +2663,7 @@ used in presence of a prototype. <tag/Description/Load an extended memory driver into memory and initialize it. The function returns an error code that tells if all this has been successful. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Not all drivers are able to detect if the supported hardware is really present. <item>The function is only available as fastcall function, so it may only be @@ -2705,7 +2693,7 @@ into a buffer. If you don't need the actual contents of the page (for example because you're going to overwrite it completely), it is better to call <tt/<ref id="em_use" name="em_use">/ instead. <tt/em_use/ will not transfer the data if it is possible to avoid that. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Calling <tt/em_map/ will invalidate the memory window, so if you made any changes to the data in the window, call <tt/<ref id="em_commit" name="em_commit">/ first, or the changes are lost. @@ -2733,7 +2721,7 @@ loaded. <tag/Declaration/<tt/unsigned em_pagecount (void);/ <tag/Description/The function returns the size of the extended memory supported by the driver in 256 byte pages. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function returns zero if no extended memory driver is loaded. <item>The function may return zero if the supported hardware was not detected. </itemize> @@ -2754,7 +2742,7 @@ by the driver in 256 byte pages. <tag/Declaration/<tt/unsigned char em_uninstall (void);/ <tag/Description/The function uninstalls an already loaded extended memory driver but doesn't remove it from memory. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>If the driver has been loaded using <tt/<ref id="em_load_driver" name="em_load_driver">/, <tt/<ref id="em_unload" name="em_unload">/ should be used instead of <tt/em_uninstall/ so the driver is also removed @@ -2779,7 +2767,7 @@ from memory. <tag/Declaration/<tt/unsigned char em_unload (void);/ <tag/Description/The function unloads a loaded extended memory driver and frees all memory allocated for the driver. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function does nothing if no driver is loaded. </itemize> <tag/Availability/cc65 @@ -2802,7 +2790,7 @@ memory and returns a pointer to the page frame. This function is similar to <tt/<ref id="em_map" name="em_map">/, but will not transfer data into the actual memory window in the assumption that the existing data is wrong or will get overwritten. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Calling <tt/em_use/ will invalidate the memory window, so if you made any changes to the data in the window, call <tt/<ref id="em_commit" name="em_commit">/ first, or the changes are lost. @@ -2834,7 +2822,7 @@ output is written and any functions registered with <tt/<ref id="atexit" name="atexit">/ are called. Common values for status are <tt/EXIT_SUCCESS/ and <tt/EXIT_FAILURE/ which are also defined in <tt/<ref id="stdlib.h" name="stdlib.h">/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>It depends on the host machine if the program return code can be @@ -2863,7 +2851,7 @@ the command line specified as second argument. Instead of an empty string, a <tt/NULL/ pointer may be passed as second parameter. On success, the function does not return. On failure, -1 is returned and <tt/errno/ contains an error code. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>On most platforms, the function needs to copy a small stub loader to @@ -2893,7 +2881,7 @@ program, it may not be able to read it. <tag/Declaration/<tt/void fast (void);/ <tag/Description/The function will switch the clock of the C128 to 2MHz. This will nearly double the speed compared to slow mode. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is specific to the C128. <item>2MHz clock will not work in 40 column mode. </itemize> @@ -2916,7 +2904,7 @@ will nearly double the speed compared to slow mode. <tag/Declaration/<tt/int __fastcall__ feof (FILE* f);/ <tag/Description/<tt/feof/ tests the end-of-file indicator ofthe stream <tt/f/, and returns a non zero value if it is set. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The indicator is set only after a read past the end of a file is attempted. <item>The function is only available as fastcall function, so it may only be @@ -2940,7 +2928,7 @@ used in presence of a prototype. <tag/Declaration/<tt/int __fastcall__ ferror (FILE* f);/ <tag/Description/<tt/ferror/ tests the error indicator of the stream <tt/f/, and returns a non zero value if it is set. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -2963,7 +2951,7 @@ used in presence of a prototype. <tag/Description/The <tt/fileno/ function returns the file handle used internally by a C stream. This file handle (an integer) can be used as a handle for the POSIX input/output functions. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>Mixing C file I/O functions and POSIX file I/O functions for the same @@ -2991,8 +2979,7 @@ file may have unpredictable results. <tt/<ref id="malloc" name="malloc">/, <tt/<ref id="calloc" name="calloc">/ or <tt/<ref id="realloc" name="realloc">/. As an exception, if the passed pointer is <tt/NULL/, no action is performed. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>Passing an already free'd block to <tt/free/ again will cause undefined behaviour and may crash your program. <item>The function is only available as fastcall function, so it may only @@ -3024,7 +3011,7 @@ be used in presence of a prototype. all supported targets. If it exists, it returns a number that identifies the operating system or machine type, the program runs on. The machine dependent header files define constants that can be used to check the return code. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function does not exist on all platforms. <item>The return codes are platform dependent. </itemize> @@ -3047,7 +3034,7 @@ returns one of the constants<itemize> <item><tt/CPU_65C02/ <item><tt/CPU_65816/ </itemize> -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Other, more exotic CPU types are not disinguished. </itemize> <tag/Availability/cc65 @@ -3067,7 +3054,7 @@ returns one of the constants<itemize> matches <tt/name/ and returns its value. The environment consists of a list of strings in the form <tt/name=value/. If there is no match, <tt/getenv/ returns <tt/NULL/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>What exactly is stored in the environment depends on the machine the program is running on. <item>The function is only available as fastcall function, so it may only @@ -3097,7 +3084,7 @@ preceeded by a '-'. found on the command line and <tt/EOF/ (-1) if there is no other option. An option argument is placed in <tt/optarg/, the index of the next element on the command line to be processed is placed in <tt/optind/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The implementation will not reorder options. A non option on the command line will terminate option processing. All remaining arguments are not recognized as options, even if the start with a '-' character. @@ -3120,7 +3107,7 @@ be used in presence of a prototype. <tag/Description/The function moves the text mode cursor to the specified X position while leaving the Y position untouched. The leftmost position on the screen has the coordinate 0. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>Invalid values for the X position (out of screen coordinates) may @@ -3147,7 +3134,7 @@ lead to undefined behaviour. <tag/Description/The function moves the text mode cursor to the specified position. The leftmost position on the screen has the X coordinate 0, the topmost line has the Y coordinate 0. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>Invalid values for any of both coordinates (out of screen positions) may @@ -3174,7 +3161,7 @@ lead to undefined behaviour. <tag/Description/The function moves the text mode cursor to the specified Y position while leaving the X position untouched. The uppermost position on the screen has the coordinate 0. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>Invalid values for the Y position (out of screen coordinates) may lead @@ -3201,7 +3188,7 @@ to undefined behaviour. <tag/Description/The function returns a non zero value if the given argument is a letter or digit. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3238,7 +3225,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Declaration/<tt/int __fastcall__ isalpha (int c);/ <tag/Description/The function returns a non zero value if the given argument is a letter. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3275,7 +3262,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Declaration/<tt/int __fastcall__ isascii (int c);/ <tag/Description/The function returns a non zero value if the given argument is in the range 0..127 (the range of valid ASCII characters) and zero if not. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3313,7 +3300,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Description/The function returns a non zero value if the given argument is a space or tab character. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3351,7 +3338,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Description/The function returns a non zero value if the given argument is a control character. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3388,7 +3375,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Declaration/<tt/int __fastcall__ isdigit (int c);/ <tag/Description/The function returns a non zero value if the given argument is a digit. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3427,7 +3414,7 @@ space). <tag/Description/The function returns a non zero value if the given argument is a printable character with the exception of space. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3465,7 +3452,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Description/The function returns a non zero value if the given argument is a lower case letter. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3503,7 +3490,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Description/The function returns a non zero value if the given argument is a printable character (this includes the space character). The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3542,7 +3529,7 @@ space or an alphanumeric character. <tag/Description/The function returns a non zero value if the given argument is a printable character, but not a space or anything alphanumeric. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3582,7 +3569,7 @@ is a white space character. The return value is zero if the character is anything else. The standard white space characters are: space, formfeed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v'). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3620,7 +3607,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Description/The function returns a non zero value if the given argument is an upper case letter. The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3658,7 +3645,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Description/The function returns a non zero value if the given argument is a hexadecimal digit (0..9, a..f and A..F). The return value is zero if the character is anything else. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>When compiling with <tt/-Os/ the function is actually a macro. The inline sequence generated by the macro will not work correctly for values outside the range 0..255. <em/Note:/ The constant <tt/EOF/ is not part of @@ -3695,7 +3682,7 @@ fastcall function, so it may only be used in presence of a prototype. <tag/Declaration/<tt/char* __fastcall__ itoa (int val, char* buf, int radix);/ <tag/Description/<tt/itoa/ converts the integer <tt/val/ into a string using <tt/radix/ as the base. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>There are no provisions to prevent a buffer overflow. <item>If <tt/val/ contains <tt/INT_MIN/, the behaviour is undefined. <item>The function is non standard, so it is not available in strict ANSI mode. @@ -3724,7 +3711,7 @@ used in presence of a prototype. <tag/Declaration/<tt/unsigned char joy_count (void);/ <tag/Description/The function returns a the number of joysticks supported by the current joystick driver. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>A joystick driver must be loaded using <ref id="joy_load_driver" name="joy_load_driver"> before calling this function. <item>The function returns the number of joysticks supported by the driver. @@ -3749,7 +3736,7 @@ There's no way to check for the number of actually connected joysticks. <tag/Description/The function installs a driver that was already loaded into memory (or linked statically to the program). It returns an error code (<tt/JOY_ERR_OK/ in case of success). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -3773,7 +3760,7 @@ used in presence of a prototype. <tag/Description/The function loads a driver with the given name from disk and installs it. An error code is returned, which is <tt/JOY_ERR_OK/ if the driver was successfully loaded and installed. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -3797,7 +3784,7 @@ used in presence of a prototype. <tag/Description/The function reads the status bits for a joystick. The number of the joystick is passed as parameter. The result may be examined by using one of the <tt/JOY_xxx/ macros from <ref id="joystick.h" name="joystick.h">. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>A joystick driver must be loaded using <ref id="joy_load_driver" name="joy_load_driver"> before calling this function. <item>The function is only available as fastcall function, so it may only be @@ -3823,7 +3810,7 @@ used in presence of a prototype. <tag/Description/The function uninstalls the currently installed joystick driver. It does not remove the driver from memory. The function returns an error code, which is <tt/JOY_ERR_OK/ if the driver was successfully uninstalled. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>A joystick driver must be installed using <ref id="joy_install" name="joy_install"> before calling this function. </itemize> @@ -3847,7 +3834,7 @@ name="joy_install"> before calling this function. <tag/Description/The function uninstalls the currently installed joystick driver and removes it from memory. An error code is returned, which is <tt/JOY_ERR_OK/ if the driver was successfully uninstalled. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>A joystick driver must be loaded using <ref id="joy_load_driver" name="joy_load_driver"> before calling this function. </itemize> @@ -3868,7 +3855,7 @@ name="joy_load_driver"> before calling this function. <tag/Declaration/<tt/unsigned char kbhit (void);/ <tag/Description/The function returns a value of zero if there is no character waiting to be read from the keyboard. It returns non zero otherwise. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>If the system does not support a keyboard buffer (most systems do), the function is rather useless. </itemize> @@ -3890,7 +3877,7 @@ do), the function is rather useless. <tag/Declaration/<tt/long __fastcall__ labs (long v);/ <tag/Description/<tt/labs/ returns the absolute value of the argument passed to the function. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The return value is undefined if <tt/LONG_MIN/ is passed to the function. <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. @@ -3912,7 +3899,7 @@ used in presence of a prototype. <tag/Declaration/<tt/char* __fastcall__ ltoa (long val, char* buf, int radix);/ <tag/Description/<tt/itoa/ converts the long integer <tt/val/ into a string using <tt/radix/ as the base. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>There are no provisions to prevent a buffer overflow. <item>If <tt/val/ contains <tt/LONG_MIN/, the behaviour is undefined. <item>The function is non standard, so it is not available in strict ANSI mode. @@ -3941,7 +3928,7 @@ used in presence of a prototype. <tag/Declaration/<tt/struct lconv* localeconv (void);/ <tag/Description/<tt/localeconv/ returns a pointer to the current locale structure. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>cc65 supports only the "C" locale, so even after setting a new locale using <tt/<ref id="setlocale" name="setlocale">/, the structure returned will always be the same. @@ -3966,8 +3953,7 @@ data in <tt/buf/, which must have been set by a preceeding call to <tt/<ref id="setjmp" name="setjmp">/. Program execution continues as if the call to <tt/<ref id="setjmp" name="setjmp">/ has just returned the value <tt/retval/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>If the parameter <tt/retval/ is zero, the function will behave as if it was called with a value of one. <item>The function is only available as fastcall function, so it may only @@ -3991,8 +3977,7 @@ be used in presence of a prototype. <tag/Description/<tt/malloc/ allocates size bytes on the heap and returns a pointer to the allocated memory block. On error (not enough memory available), <tt/malloc/ returns <tt/NULL/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4022,7 +4007,7 @@ be used in presence of a prototype. (converted to a char) in the block of raw memory string pointed to by <tt/mem/ that is of size <tt/count/. Upon completion, the function returns a pointer to the character found, or a null pointer if the character was not found. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4045,8 +4030,7 @@ be used in presence of a prototype. pointed to by <tt/p1/ into the memory area pointed to by <tt/p2/. It returns a value that is less than zero if <tt/p1/ is less than <tt/p2/, zero if <tt/p1/ is the same as <tt/p2/, and a value greater than zero if <tt/p1/ is greater than <tt/p2/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4070,8 +4054,7 @@ be used in presence of a prototype. <tag/Description/<tt/memcpy/ copies <tt/count/ bytes from the memory area pointed to by <tt/src/ into the memory area pointed to by <tt/dest/. It returns <tt/dest/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The result is undefined if the memory areas do overlap. Use <tt/<ref id="memmove" name="memmove">/ to copy overlapping memory areas. <item>The function is only available as fastcall function, so it may only @@ -4097,8 +4080,7 @@ be used in presence of a prototype. <tag/Description/<tt/memmove/ copies <tt/count/ bytes from the memory area pointed to by <tt/src/ into the memory area pointed to by <tt/dest/. It returns <tt/dest/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>While <tt/memmove/ allows the memory areas to overlap, it has some additional overhead compared to <tt/<ref id="memcpy" name="memcpy">/. <item>The function is only available as fastcall function, so it may only @@ -4123,8 +4105,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void* __fastcall__ memset (void* p, int val, size_t count);/ <tag/Description/<tt/memset/ fills the memory area pointed to by <tt/p/ with the value <tt/val/. The function returns <tt/p/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4148,7 +4129,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ mod_free (void* module);/ <tag/Description/The function will free a module loaded into memory by use of the <tt/<ref id="mod_load" name="mod_load">/ function. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The pointer passed as parameter is the pointer to the module memory, not the pointer to the control structure. </itemize> @@ -4179,7 +4160,7 @@ the module just loaded. Possible error codes are: <item><tt/MLOAD_ERR_FMT/ - Data format error <item><tt/MLOAD_ERR_MEM/ - Not enough memory </itemize> -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The <htmlurl url="ld65.html" name="ld65"> linker is needed to create relocatable o65 modules for use with this function. </itemize> @@ -4199,7 +4180,7 @@ relocatable o65 modules for use with this function. <tag/Header/<tt/<ref id="mouse.h" name="mouse.h">/ <tag/Declaration/<tt/void __fastcall__ mouse_setbox (const struct mouse_box* box);/ <tag/Description/The function allows to set a bounding box for mouse movement. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function does not check if the mouse cursor is currently within the given rectangle. Placing the mouse cursor within the bounding box is the responsibility of the programmer. @@ -4228,7 +4209,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ mouse_getbox (struct mouse_box* box);/ <tag/Description/The function queries the current bounding box for mouse movement. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4270,7 +4251,7 @@ return value. code);/ <tag/Description/The function returns an error message (in english) for the error code passed parameter. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function will return "Unknown error" for invalid error codes. <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. @@ -4315,7 +4296,7 @@ mouse. <tag/Declaration/<tt/void __fastcall__ mouse_info (struct mouse_info* info);/ <tag/Description/The function returns the state of the mouse buttons and the position of the mouse in the <tt/mouse_info/ structure passed as parameter. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The <tt/mouse_info/ struct is a superset of the <tt/mouse_pos/ struct, so if you just need the mouse position, call <tt/<ref id="mouse_pos" name="mouse_pos">/ instead. @@ -4346,7 +4327,7 @@ pointer. Defaults for these routines are supplied by the library, so if you can live with these defaults (which are platform specific), just pass a pointer to <tt/mouse_def_callbacks/. The function may be used to install a driver linked statically to the program. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Not all drivers are able to detect if the supported hardware is really present. <item>After installing a driver, the mouse cursor is hidden. @@ -4376,7 +4357,7 @@ different IOCTL functions, and the <tt/data/ depends on code. The function returns an error code. The purpose of this function is to allow for driver specific extensions. See the documentation for a specific mouse driver for supported ioctl calls. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Calling this function is non portable, because each driver may implement different ioctl calls (or none at all). <item>The function is only available as fastcall function, so it may only be @@ -4402,7 +4383,7 @@ function returns an error code that tells if the call has been successful. The routines needed to move or hide/show the mouse pointer. Defaults for these routines are supplied by the library, so if you can live with these defaults (which are platform specific), just pass a pointer to <tt/mouse_def_callbacks/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The driver is loaded by name, so currently you must know the type of mouse that should be supported. There is no autodetect capability. <item>Not all drivers are able to detect if the supported hardware is really @@ -4430,7 +4411,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ mouse_move (int x, int y);/ <tag/Description/The function updates the mouse position. If the mouse cursor is visible, it is shown at the new position. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function does not check if the new position is within the bounding box specified with <tt/<ref id="mouse_setbox" name="mouse_setbox">/. <item>The function is only available as fastcall function, so it may only be @@ -4454,7 +4435,7 @@ used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ mouse_pos (struct mouse_pos* pos);/ <tag/Description/The function returns the position of the mouse in the <tt/mouse_pos/ structure passed as parameter. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The <tt/mouse_pos/ struct is a subset of the <tt/mouse_info/ struct, so if you do also need the mouse buttons, call <tt/<ref id="mouse_info" name="mouse_info">/ instead. @@ -4498,7 +4479,7 @@ that is shared between <tt/<ref id="mouse_hide" name="mouse_hide">/ and <tag/Declaration/<tt/unsigned char mouse_uninstall (void);/ <tag/Description/The function uninstalls an already loaded mouse driver but don't removes it from memory. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>If the driver has been loaded using <tt/<ref id="mouse_load_driver" name="mouse_load_driver">/, <tt/<ref id="mouse_unload" name="mouse_unload">/ should be used instead of <tt/mouse_uninstall/ so the driver is also removed @@ -4523,7 +4504,7 @@ from memory. <tag/Declaration/<tt/unsigned char __fastcall__ mouse_unload (void);/ <tag/Description/The function unloads a loaded mouse driver and frees all memory allocated for the driver. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function does nothing if no driver is loaded. </itemize> <tag/Availability/cc65 @@ -4545,7 +4526,7 @@ memory allocated for the driver. <tag/Declaration/<tt/size_t offsetof (type, member);/ <tag/Description/<tt/offsetof/ calculates the address offset of a <tt/struct/ or <tt/union/ member. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is actually a macro. </itemize> <tag/Availability/ISO 9899 @@ -4564,7 +4545,7 @@ or <tt/union/ member. <tag/Description/<tt/open/ opens a file and returns the file descriptor associated with it. On error, -1 is returned and an error code is stored in <tt/errno/. Several flags may be passed to <tt/open/ that change the behaviour. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>POSIX specifies an additional <tt/mode/ argument that may be passed to open, which is used as the permission mask when a new file is created. While cc65 allows to pass this argument, it is ignored. @@ -4588,7 +4569,7 @@ cc65 allows to pass this argument, it is ignored. <tag/Description/<tt/opendir/ opens a directory and returns the direcory descriptor associated with it. On error, NULL is returned and an error code is stored in <tt/errno/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4611,8 +4592,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/unsigned char __fastcall__ peekbsys (unsigned addr);/ <tag/Description/<tt/peekbsys/ reads one byte from the given address in the system bank (bank 15) of the CBM PET-II machines and returns it. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>This function may be a macro depending on the compiler options. The @@ -4642,8 +4622,7 @@ actual function is accessible by #undef'ing the macro. system bank (bank 15) of the CBM PET-II machines and returns it. Following the usual 6502 conventions, the low byte is read from <tt/addr/, and the high byte is read from <tt/addr+1/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The order in which the two bytes are read is undefined. @@ -4672,8 +4651,7 @@ is not <tt/NULL/ and not an empty string, it is printed followed by a colon and a blank. Then the error message for the current contents of <tt/errno/ is printed followed by a newline. The message output is the same as returned by <tt/<ref id="strerror" name="strerror">/ with an argument of <tt/errno/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4696,8 +4674,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ pokebsys (unsigned addr, unsigned char val);/ <tag/Description/<tt/pokebsys/ writes one byte to the given address in the system bank (bank 15) of the CBM PET-II machines. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4725,8 +4702,7 @@ be used in presence of a prototype. system bank (bank 15) of the CBM PET-II machines. Following the usual 6502 conventions, the low byte of <tt/val/ is written to <tt/addr/, and the high byte is written to <tt/addr+1/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The order in which the two bytes are written is undefined. @@ -4755,8 +4731,7 @@ size_t size, int (*compare) (const void*, const void*));/ function <tt/compare/. <tt/base/ is the address of the array, <tt/count/ is the number of elements, <tt/size/ the size of an element and <tt/compare/ the function used to compare the members. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>If there are multiple members with the same key, the order after calling the function is undefined. <item>The function is only available as fastcall function, so it may only @@ -4782,7 +4757,7 @@ program has installed a signal handler for the signal, this signal handler will be executed. If no handler has been installed, the default action for the raised signal will be taken. The function returns zero on success, nonzero otherwise. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -4804,7 +4779,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/int rand (void);/ <tag/Description/The function returns a pseudo random number between 0 and <tt/RAND_MAX/ (exclusive). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Without using <tt><ref id="srand" name="srand"></tt>, always the same flow of numbers is generated. <item>On startup, the function behaves as if <ref id="srand" name="srand"> @@ -4831,7 +4806,7 @@ stream pointed to by <tt/dir/. It stores the data in a <tt/dirent/ structure and returns a pointer to it. If the end of directory is reached, or an error occurs, NULL is returned. In case of errors, an error code is stored into <tt/errno/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The returned pointer may point to a statically allocated instance of @@ -4870,8 +4845,7 @@ by <tt/block/ to <tt/size/ bytes. If <tt/block/ is <tt/NULL/, <tt/realloc/ behaves as if <tt/malloc/ had been called. If <tt/size/ is zero, <tt/realloc/ behaves as if <tt/free/ had been called. On error (not enough memory available), <tt/realloc/ returns <tt/NULL/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The part of the memory block that is returned will have its contents unchanged. <item>This function is somewhat dangerous to use. Be careful to save the @@ -4907,8 +4881,7 @@ be used in presence of a prototype. <tag/Description/<tt/remove/ deletes the file with the given name. On success, zero is returned. On error, -1 is returned and <tt/errno/ is set to an error code describing the reason for the failure. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>This function is not available on all cc65 targets (depends on the availability of file I/O). <item>The function is only available as fastcall function, so it may only @@ -4944,8 +4917,7 @@ if (remove (FILENAME) == 0) { <tag/Description/<tt/rename/ renames a file (gives it a new name). On success, zero is returned. On error, -1 is returned and <tt/errno/ is set to an error code describing the reason for the failure. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>This function is not available on all cc65 targets (depends on the capabilities of the storage devices). <item>The function is only available as fastcall function, so it may only @@ -4980,8 +4952,7 @@ if (rename (OLDNAME, NEWNAME) == 0) { <tag/Declaration/<tt/void reset_brk (void);/ <tag/Description/<tt/reset_brk/ resets the break vector to the value it had before a call to <tt/set_brk/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>Since <tt/<ref id="set_brk" name="set_brk">/ installs an exit handler, it is not strictly necessary to call this function as part of the cleanup when the program ends. @@ -5004,8 +4975,7 @@ the program ends. <tag/Header/<tt/<ref id="6502.h" name="6502.h">/ <tag/Declaration/<tt/void reset_irq (void);/ <tag/Description/<tt/reset_irq/ resets the C level interrupt request vector. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The original IRQ vector is restored on program termination even without calling this function. </itemize> @@ -5029,7 +4999,7 @@ calling this function. <tag/Description/If the argument is non zero, the function enables reverse character display. If the argument is zero, reverse character display is switched off. The old value of the setting is returned. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function may not be supported by the hardware, in which case the call is ignored. <item>The function is only available as fastcall function, so it may only @@ -5052,7 +5022,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ rewinddir (DIR* dir);/ <tag/Description/<tt/rewinddir/ sets the position of the directory stream pointed to by <tt/dir/ to the start of the directory. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5073,7 +5043,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="conio.h" name="conio.h">/ <tag/Declaration/<tt/void __fastcall__ screensize (unsigned char* x, unsigned char* y);/ <tag/Description/The function returns the dimensions of the text mode screen. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5099,7 +5069,7 @@ be used in presence of a prototype. <tag/Description/<tt/seekdir/ sets the position of the directory stream pointed to by <tt/dir/ to the value given in <tt/offset/, which should be a value returned by <tt/<ref id="telldir" name="telldir">/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5153,7 +5123,7 @@ static void initialize(){ <tag/Description/Get a character from the serial port. If no characters are available, the function will return SER_ERR_NO_DATA, so this is not a fatal error. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5180,7 +5150,7 @@ while (ser_get(&ch) == SER_ERR_NO_DATA) <tag/Description/The function installs a driver that was already loaded into memory (or linked statically to the program). It returns an error code (<tt/SER_ERR_OK/ in case of success). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5206,7 +5176,7 @@ ser_install(lynx_comlynx); //Include the driver statically instead of loading it <tag/Description/Some platforms have extra serial functions that are not supported by standard serial driver functions. You can extend the driver to support this extra functionality bt using ser_ioctl functions. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>These functions are not easily portable to other cc65 platforms. @@ -5226,7 +5196,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/unsigned char __fastcall__ ser_load_driver (const char *name);/ <tag/Description/Load and install the driver by name. Will just load the driver and check if loading was successful. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5245,7 +5215,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="serial.h" name="serial.h">/ <tag/Declaration/<tt/unsigned char __fastcall__ ser_open (const struct ser_params* params);/ <tag/Description/Open the port by setting the port parameters and enable interrupts. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5282,7 +5252,7 @@ static void initialize(){ <tag/Description/Send a character via the serial port. There is a transmit buffer, but transmitting is not done via interrupt. The function returns SER_ERR_OVERFLOW if there is no space left in the transmit buffer. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5304,7 +5274,7 @@ ser_put('A'); <tag/Header/<tt/<ref id="serial.h" name="serial.h">/ <tag/Declaration/<tt/unsigned char __fastcall__ ser_status (unsigned char* status);/ <tag/Description/Return the serial port status. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5355,8 +5325,7 @@ be used in presence of a prototype. program code by letting the vector point to a user written C function. The runtime library installs a small stub that saves the registers into global variables that may be accessed (and changed) by the break handler. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The stub saves the zero page registers used by the C runtime and switches @@ -5396,8 +5365,7 @@ was set up to handle a "private", "exclusive" interrupt request source it must return the value <tt/IRQ_HANDLED/ if and only if it has verified that the current interrupt request actually stems from that source. In all other cases it must return the value <tt/IRQ_NOT_HANDLED/. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The stub saves the registers and zero page locations used by the C runtime @@ -5430,8 +5398,7 @@ of the cleanup when the program terminates. <tag/Description/The <tt/setjmp/ function saves the current context in <tt/buf/ for subsequent use by the <tt/<ref id="longjmp" name="longjmp">/ function and returns zero. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item><tt/setjmp/ is actually a macro as required by the ISO standard. @@ -5453,8 +5420,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="locale.h" name="locale.h">/ <tag/Declaration/<tt/char* __fastcall__ setlocale (int category, const char* locale);/ <tag/Description/<tt/setlocale/ sets or queries the program's locale. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>cc65 supports only the "C" locale, so calling this function to set a @@ -5482,7 +5448,7 @@ handler may either be a user supplied function, or one of the predefined signal handlers <tt/SIG_IGN/ or <tt/SIG_DFL/. The function returns the previous value if the signal , or the special function vector SIG_ERR in case of an error. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5504,7 +5470,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void __fastcall__ sleep (unsigned seconds);/ <tag/Description/The function will return after the specified number of seconds have elapsed. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5523,7 +5489,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void slow (void);/ <tag/Description/The function will switch the clock of the C128 to 1MHz. This will halve the speed compared to fast mode. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is specific to the C128. </itemize> <tag/Availability/C128 @@ -5546,7 +5512,7 @@ will halve the speed compared to fast mode. <tag/Description/The function initializes the random number generator using the given seed. On program startup, the generator behaves as if <tt/srand/ has been called with an argument of 1. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5570,7 +5536,7 @@ be used in presence of a prototype. as parameters without case sensitivity. It returns a value that is less than zero if <tt/s1/ is less than <tt/s2/, zero if <tt/s1/ is the same as <tt/s2/, and a value greater than zero if <tt/s1/ is greater than <tt/s2/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The function is not available in strict ANSI mode. @@ -5598,7 +5564,7 @@ be used in presence of a prototype. pointed to by s2 (including the terminating null byte) to the end of the string pointed to by s1. The initial byte of s2 overwrites the null byte at the end of s1. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>If copying takes place between objects that overlap, the behaviour @@ -5625,7 +5591,7 @@ is undefined. (converted to a char) in the string pointed to by <tt/s/. The terminating null byte is considered to be part of the string. Upon completion, the function returns a pointer to the byte, or a null pointer if the byte was not found. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5649,7 +5615,7 @@ be used in presence of a prototype. parameters. It returns a value that is less than zero if <tt/s1/ is less than <tt/s2/, zero if <tt/s1/ is the same as <tt/s2/, and a value greater than zero if <tt/s1/ is greater than <tt/s2/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5677,7 +5643,7 @@ parameters, according to the collating sequence set by <tt/<ref id="setlocale" name="setlocale">/. It returns a value that is less than zero if <tt/s1/ is less than <tt/s2/, zero if <tt/s1/ is the same as <tt/s2/, and a value greater than zero if <tt/s1/ is greater than <tt/s2/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5704,7 +5670,7 @@ be used in presence of a prototype. <tag/Description/The <tt/strcpy/ function copies the string pointed to by <tt/s2/ (including the terminating null byte) into the array pointed to by <tt/s1/. The function will always return <tt/s1/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>If copying takes place between objects that overlap, the behaviour @@ -5737,7 +5703,7 @@ strcpy (hello, "Hello world!\n"); <tag/Description/The <tt/strcspn/ function computes and returns the length of the substring pointed to by <tt/s/ which does <em>not</em> consist of characters contained in the string <tt/set/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5763,7 +5729,7 @@ be used in presence of a prototype. to hold a copy of <tt/s/ including the terminating zero. If the allocation fails, <tt/NULL/ is returned, otherwise <tt/s/ is copied into the allocated memory block, and a pointer to the block is returned. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>It is up to the caller to free the allocated memory block. @@ -5788,7 +5754,7 @@ be used in presence of a prototype. given error code. If an invalid error code is passed, the string "Unknown error" is returned, and <tt/errno/ is set to <tt/EINVAL/. In all other cases, <tt/errno/ is left untouched. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>While the return type of the function is a <tt/char*/, the returned @@ -5813,7 +5779,7 @@ string must not be modified by the caller! parameters without case sensitivity. It returns a value that is less than zero if <tt/s1/ is less than <tt/s2/, zero if <tt/s1/ is the same as <tt/s2/, and a value greater than zero if <tt/s1/ is greater than <tt/s2/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The function is not available in strict ANSI mode. @@ -5839,7 +5805,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/size_t __fastcall__ strlen (const char* s);/ <tag/Description/The <tt/strlen/ function computes the number of bytes in the string to which s points, not including the terminating null byte. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>When compiling with <tt/-Os/ (inline known standard functions), the @@ -5862,7 +5828,7 @@ function does not work correctly for strings with more than 255 characters. <tag/Declaration/<tt/char* __fastcall__ strlower (char* s);/ <tag/Description/The <tt/strlower/ function will apply the <tt/tolower/ function to each character of a string. The function will always return <tt/s/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The function prototype is unavailable when compiling in strict ANSI mode. @@ -5895,7 +5861,7 @@ See <tt/strlower/. of the string pointed to by s2 to the end of the string pointed to by s1. The terminating null character at the end of s1 is overwritten. A terminating null character is appended to the result, even if not all of s2 is appended to s1. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>If copying takes place between objects that overlap, the behaviour @@ -5923,7 +5889,7 @@ characters of the two strings passed as parameters. It returns a value that is less than zero if the first <tt/count/ characters of <tt/s1/ are less than <tt/s2/, zero if they are identical, and a value greater than zero they are greater. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -5951,7 +5917,7 @@ the array pointed to by <tt/s2/ to the array pointed to by <tt/s1/. If the array pointed to by <tt/s2/ is a string that is shorter than <tt/n/ bytes, null bytes are appended to the copy in the array pointed to by <tt/s1/, until <tt/n/ bytes are written. The function always will return <tt/s1/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is available only as a fastcall function; so, it may be used only in the presence of a prototype. <item>If there is no null byte in the first <tt/n/ bytes of the array pointed @@ -5991,7 +5957,7 @@ string <tt/s2/. Tokens inside quotation marks may contain characters from <tt/s2 pointer to the first token in the string <tt/s1/. The following calls must pass a <tt/NULL/ pointer as <tt/s1/, in order to get the next token in the string. Different sets of delimiters may be used for the subsequent calls to <tt/strqtok()/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is available only as a fastcall function; so, it may be used only in the presence of a prototype. <item><tt/strqtok()/ will modify the string <tt/s1/. @@ -6020,7 +5986,7 @@ a second <tt/s1/ string before it finishes the first one. (converted to a char) in the string pointed to by <tt/s/. The terminating null byte is considered to be part of the string. Upon completion, the function returns a pointer to the byte, or a null pointer if the byte was not found. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6042,7 +6008,7 @@ be used in presence of a prototype. <tag/Description/The <tt/strspn/ function computes and returns the length of the substring pointed to by <tt/s/ which does consist only of characters contained in the string <tt/set/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6065,7 +6031,7 @@ be used in presence of a prototype. <tag/Description/<tt/strstr/ searches for the first occurance of the string <tt/substr/ within <tt/str/. If found, it returns a pointer to the copy, otherwise it returns <tt/NULL/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6091,7 +6057,7 @@ to <tt/strtok()/ will return a pointer to the first token in the string <tt/s1/. The following calls must pass a <tt/NULL/ pointer as <tt/s1/, in order to get the next token in the string. Different sets of delimiters may be used for the subsequent calls to <tt/strtok()/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item><tt/strtok()/ will modify the string <tt/s1/. @@ -6123,7 +6089,7 @@ transformed strings, it returns a value greater than, equal to, or less than zero, corresponding to the result of the <tt/strcoll/ function applied to the same two original strings. No more than n characters are placed into the resulting array pointed to by s1, including the terminating null character. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item><tt/s1/ and <tt/s2/ must not point to the same memory area, otherwise the behaviour is undefined. <item>If <tt/n/ is zero, <tt/s1/ may be a NULL pointer. @@ -6151,7 +6117,7 @@ just copy s2 to s1 using <tt><ref id="strncpy" name="strncpy"></tt>. <tag/Declaration/<tt/char* __fastcall__ strupper (char* s);/ <tag/Description/The <tt/strupper/ function will apply the <tt/toupper/ function to each character of a string. The function will always return <tt/s/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The function prototype is unavailable when compiling in strict ANSI mode. @@ -6183,7 +6149,7 @@ See <tt/strupper/. <tag/Description/<tt/telldir/ returns the current position of a directory stream. The return value may be used in subsequent calls to <tt/<ref id="seekdir" name="seekdir">/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6206,7 +6172,7 @@ be used in presence of a prototype. <tag/Description/The function will set a new text color. It returns the old (current) text color. Text output using any <tt/conio.h/ function will use the color set by this function. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Text colors are system dependent. The function may have no effect on systems where the text color cannot be changed. <item>The function is only available as fastcall function, so it may only @@ -6233,7 +6199,7 @@ unsigned char rx, unsigned char ry, unsigned sa, unsigned ea);/ radii rx/ry using the current drawing color. The arc covers the angle between sa and ea (startangle and endangle), which must be in the range 0..360. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The function behaves unexpectedly or may crash if the angles are out @@ -6265,7 +6231,7 @@ color. <tag/Declaration/<tt/void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2);/ <tag/Description/The function fills a rectangle on the drawpage with the current color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6287,7 +6253,7 @@ tgi_bar(10, 10, 100, 60); <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/void __fastcall__ tgi_circle (int x, int y, unsigned char radius);/ <tag/Description/The function draws a circle in the current color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6347,7 +6313,7 @@ Will NOT uninstall or unload the driver! <tag/Declaration/<tt/void __fastcall__ tgi_ellipse (int x, int y, unsigned char rx, unsigned char ry);/ <tag/Description/The function draws an ellipse at position x/y with radii rx and ry, using the current drawing color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6374,7 +6340,7 @@ tgi_ellipse (50, 40, 40, 20); <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/void __fastcall__ tgi_free_vectorfont (const tgi_vectorfont* font);/ <tag/Description/Free a vector font that was previously loaded into memory. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6397,7 +6363,7 @@ driver and display as an 8.8 fixed point value. It may be used to correct geometric shapes so they look correct on the display. As an example, a circle with a radius of 100 pixels may look elliptic on some driver/display combinations if the aspect ratio is not 1.00. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The aspect ratio is encoded in the TGI driver which assumes a "standard" monitor for the given platform. The aspect ratio may be wrong if another monitor is used. @@ -6501,7 +6467,7 @@ This will also clear the error. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/const char* __fastcall__ tgi_geterrormsg (unsigned char code);/ <tag/Description/Get an error message describing the error. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6597,7 +6563,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/unsigned char __fastcall__ tgi_getpixel (int x, int y);/ <tag/Description/Get the color of a pixel from the viewpage. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6648,7 +6614,7 @@ This is same as tgi_maxy()+1. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/void __fastcall__ tgi_gotoxy (int x, int y);/ <tag/Description/Set graphics cursor at x, y. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6668,7 +6634,7 @@ be used in presence of a prototype. <tag/Declaration/<tt/void tgi_init (void);/ <tag/Description/The tgi_init function will set the default palette to the hardware. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item><tt/tgi_init/ will not clear the screen. This allows switching between text and graphics mode on platforms that have separate memory areas for the screens. If you want the screen cleared, call <tt/<ref id="tgi_clear" @@ -6694,7 +6660,7 @@ tgi_init(); //Set up the default palette and clear the screen. <tag/Description/The function installs a driver that was already loaded into memory (or linked statically to the program). It returns an error code (<tt/TGI_ERR_OK/ in case of success). -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6722,7 +6688,7 @@ tgi_init(); //Set up the default palette and clear the screen. Install a vector font for use. More than one vector font can be loaded, but only one can be active. This function is used to tell which one. Call with a NULL pointer to uninstall the currently installed font. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6745,7 +6711,7 @@ used in presence of a prototype. <tag/Description/Some platforms have extra display hardware that is not supported by standard tgi functions. You can extend the driver to support this extra hardware using tgi_ioctl functions. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>These functions are not easily portable to other cc65 platforms. @@ -6780,7 +6746,7 @@ The graphics cursor will be set to x2/y2 by this call. <tag/Declaration/<tt/void __fastcall__ tgi_line (int x1, int y1, int x2, int y2);/ <tag/Description/Draw a line in the current drawing color. The graphics cursor will be set to x2/y2 by this call. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6801,7 +6767,7 @@ cursor to the new end point. The graphics cursor will be updated to x2/y2. <tag/Declaration/<tt/void __fastcall__ tgi_lineto (int x2, int y2);/ <tag/Description/Draw a line in the current drawing color from the graphics cursor to the new end point. The graphics cursor will be updated to x2/y2. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6822,7 +6788,7 @@ be used in presence of a prototype. <tag/Description/Load and install the driver by name. Will just load the driver and check if loading was successful. Will not switch to graphics mode. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6844,7 +6810,7 @@ be used in presence of a prototype. Load a vector font into memory and return it. In case of errors, NULL is returned and an error is set, which can be retrieved using tgi_geterror. To use the font, it has to be installed using tgi_install_vectorfont. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6867,7 +6833,7 @@ The graphics cursor is moved to the end of the text. <tag/Declaration/<tt/void __fastcall__ tgi_outtext (const char* s);/ <tag/Description/Output text at the current graphics cursor position. The graphics cursor is moved to the end of the text. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6888,7 +6854,7 @@ The graphics cursor is moved to the end of the text. <tag/Declaration/<tt/void __fastcall__ tgi_outtextxy (int x, int y, const char* s);/ <tag/Description/Output text at the given cursor position. The graphics cursor is moved to the end of the text. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6911,7 +6877,7 @@ unsigned char rx, unsigned char ry, unsigned sa, unsigned ea);/ and radii rx/ry using the current drawing color. The pie slice covers the angle between sa and ea (startangle and endangle), which must be in the range 0..360. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>The function behaves unexpectedly or may crash if the angles are out @@ -6943,7 +6909,7 @@ driver and display. The argument is an 8.8 fixed point value. The aspect ratio may be used to correct geometric shapes so they look correct on a given display. As an example, a circle with a radius of 100 pixels may look elliptic on some driver/display combinations if the aspect ratio is not 1.00. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The aspect ratio is encoded in the TGI driver which assumes a "standard" monitor for the given platform. The aspect ratio may be wrong if another monitor is used. @@ -6971,7 +6937,7 @@ ratio. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/void __fastcall__ tgi_setcolor (unsigned char color);/ <tag/Description/Set color to be used in future draw operations. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -6997,7 +6963,7 @@ tgi_bar(10,10,20,20); is seen immediately as it is drawn. For double buffered games you can set the drawpage to a different page than the viewpage. This lets you draw the next screen in the background and when the screen is ready you display it. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7025,7 +6991,7 @@ Palette is a pointer to as many entries as there are colors. <tag/Declaration/<tt/void __fastcall__ tgi_setpalette (const unsigned char* palette);/ <tag/Description/Set the palette (not available with all drivers/hardware). Palette is a pointer to as many entries as there are colors. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7043,7 +7009,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/void __fastcall__ tgi_setpixel (int x, int y);/ <tag/Description/Plot a pixel on the drawpage with the current color. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7064,7 +7030,7 @@ be used in presence of a prototype. is seen immediately as it is drawn. For double buffered games you can set the drawpage to a different page than the viewpage. This lets you draw the next screen in the background and when the screen is ready you display it. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7092,7 +7058,7 @@ the current text style. <tag/Declaration/<tt/unsigned __fastcall__ tgi_gettextheight (const char* s);/ <tag/Description/Calculate the height of the text in pixels according to the current text style. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7112,7 +7078,7 @@ be used in presence of a prototype. <tag/Description/ Set the scaling for text output. The scaling factors for width and height are 8.8 fixed point values. This means that $100 = 1 $200 = 2 etc. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7131,7 +7097,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/void __fastcall__ tgi_settextstyle (unsigned char magx, unsigned char magy, unsigned char dir, unsigned char font);/ <tag/Description/Set the style for text output. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7150,7 +7116,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="tgi.h" name="tgi.h">/ <tag/Declaration/<tt/unsigned __fastcall__ tgi_gettextwidth (const char* s);/ <tag/Description/Calculate the width of the text in pixels according to the current text style. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7203,7 +7169,7 @@ Will call tgi_done if necessary. measured in seconds. If the pointer <tt/t/ is not <tt/NULL/, the function result will also be stored there. If no time is available, <tt/(time_t)-1/ is returned and <tt/errno/ is set to <tt/ENOSYS/. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. <item>Many platforms supported by cc65 do not have a realtime clock, so the @@ -7227,7 +7193,7 @@ returned value may not be valid. <tag/Description/Toggle between 40 and 80 column mode. The settings for the old mode (cursor position, color and so on) are saved and restored together with the mode. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is specific to the C128. <item>This function is deprecated. Please use <ref id="videomode" name="videomode"> instead! @@ -7251,7 +7217,7 @@ name="videomode"> instead! <tag/Declaration/<tt/int __fastcall__ tolower (int c);/ <tag/Description/The function returns the given character converted to lower case. If the given character is not a letter, it is returned unchanged. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7274,7 +7240,7 @@ only be used in presence of a prototype. <tag/Declaration/<tt/int __fastcall__ toupper (int c);/ <tag/Description/The function returns the given character converted to upper case. If the given character is not a letter, it is returned unchanged. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> @@ -7297,7 +7263,7 @@ only be used in presence of a prototype. <tag/Declaration/<tt/char* __fastcall__ ultoa (unsigned long val, char* buf, int radix);/ <tag/Description/<tt/itoa/ converts the unsigned long integer <tt/val/ into a string using <tt/radix/ as the base. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>There are no provisions to prevent a buffer overflow. <item>The function is non standard, so it is not available in strict ANSI mode. You should probably use <tt/sprintf/ instead. @@ -7326,8 +7292,7 @@ used in presence of a prototype. <tag/Description/<tt/unlink/ deletes the file with the given name. On success, zero is returned. On error, -1 is returned and <tt/errno/ is set to an error code describing the reason for the failure. -<tag/Limits/ -<itemize> +<tag/Notes/<itemize> <item>The use of this function is discouraged. Please use <tt/<ref id="remove" name="remove">/ instead, which is a native ANSI C function and does the same. <item>This function is not available on all cc65 targets (depends on the @@ -7367,7 +7332,7 @@ if (unlink (FILENAME) == 0) { <tag/Declaration/<tt/char* __fastcall__ utoa (unsigned val, char* buf, int radix);/ <tag/Description/<tt/itoa/ converts the unsigned integer <tt/val/ into a string using <tt/radix/ as the base. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>There are no provisions to prevent a buffer overflow. <item>The function is non standard, so it is not available in strict ANSI mode. You should probably use <tt/sprintf/ instead. @@ -7397,7 +7362,7 @@ used in presence of a prototype. text where necessary and formatted according to the format string given. The resulting string is output to the console. <tt/vcprintf/ supports the same format specifiers as <tt/vprintf/. <!-- <tt/<ref id="vprintf" name="vprintf">/. --> -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>Like all other <tt/conio/ output functions, <tt/vcprintf/ distinguishes between <tt/\r/ and <tt/\n/. <item>The function is only available as fastcall function, so it may only be @@ -7426,7 +7391,7 @@ used in presence of a prototype. <tag/Description/Switch to 40 or 80 column mode depending on the argument. If the requested mode is already active, nothing happens. The old mode is returned from the call. -<tag/Limits/<itemize> +<tag/Notes/<itemize> <item>The function is specific to the C128 and enhanced Apple //e. <item>This function replaces <ref id="toggle_videomode" name="toggle_videomode">. From a7ecab38bd1e7d5ce5516d9614b9a007a8a5aa22 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 14 Mar 2015 18:53:56 +0100 Subject: [PATCH 118/351] Improved vector (re)setting function docs. --- doc/funcref.sgml | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/doc/funcref.sgml b/doc/funcref.sgml index cc45d9037..9c60483aa 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -39,7 +39,7 @@ Each entry for a function contains a detailed description <tag/Declaration/Describes the needed header files and declaration of the function. <tag/Description/Description of the function. -<tag/Limits/Limits. +<tag/Notes/Notes on the function. <tag/Availability/The availability of the function. <tag/See also/Other related functions. <tag/Example/A piece of actual code using the function. @@ -4953,9 +4953,8 @@ if (rename (OLDNAME, NEWNAME) == 0) { <tag/Description/<tt/reset_brk/ resets the break vector to the value it had before a call to <tt/set_brk/. <tag/Notes/<itemize> -<item>Since <tt/<ref id="set_brk" name="set_brk">/ installs an exit handler, -it is not strictly necessary to call this function as part of the cleanup when -the program ends. +<item>The break vector is reset on program termination, so it's not strictly +necessary to call this function as a part of your clean-up when exitting the program. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -4976,8 +4975,8 @@ the program ends. <tag/Declaration/<tt/void reset_irq (void);/ <tag/Description/<tt/reset_irq/ resets the C level interrupt request vector. <tag/Notes/<itemize> -<item>The original IRQ vector is restored on program termination even without -calling this function. +<item>The interrupt vector is reset on program termination, so it's not strictly +necessary to call this function as a part of your clean-up when exitting the program. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -5336,9 +5335,9 @@ function called from it. <item>The <tt/brk_pc/ variable points to the <tt/BRK/ instruction. If you want the continue with the interrupted code, you have to adjust <tt/brk_pc/, otherwise the <tt/BRK/ instruction will get executed over and over again. -<item>Since <tt/set_brk/ installs an exit handler, it is not strictly necessary -to call <tt/<ref id="reset_brk" name="reset_brk">/ as part of the cleanup when -the program terminates. +<item>The break vector is reset on program termination, so it's not strictly +necessary to call <tt/<ref id="reset_brk" name="reset_brk">/ as a part of your +clean-up when exitting the program. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -5374,9 +5373,9 @@ runtime overhead, but it it is safe to execute C code, even if other C code was interrupted. Be careful however not to call C library functions, and do not enable stack checks for the handler function or any other function called from it. -<item>The interrupt vector is reset on function termination, so it's not -strictly necessary to call <tt/<ref id="reset_irq" name="reset_irq">/ as part -of the cleanup when the program terminates. +<item>The interrupt vector is reset on program termination, so it's not strictly +necessary to call <tt/<ref id="reset_irq" name="reset_irq">/ as a part of your +clean-up when exitting the program. </itemize> <tag/Availability/cc65 <tag/See also/ From 52f5854813697246e58e3f3b6c234248984e5521 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 14 Mar 2015 16:50:08 -0400 Subject: [PATCH 119/351] Fixed a typo. --- doc/cc65.sgml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index bf7b1e336..842ba061a 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -3,7 +3,7 @@ <article> <title>cc65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2015-03-13 +<date>2015-03-14 <abstract> cc65 is a C compiler for 6502 targets. It supports several 6502 based home @@ -614,7 +614,7 @@ This cc65 version has some extensions to the ISO C standard. <p> <item> There is another calling convention named "cdecl". Variadic functions - (their prototypes have an ellipsis [<tt/.../]) always use this + (their prototypes have an ellipsis [<tt/.../]) always use this convention. The syntax for a function declaration using cdecl is <tscreen><verb> From 8b10534429a769a64a03e021d0d86a59bc98954b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 15 Mar 2015 00:40:42 +0100 Subject: [PATCH 120/351] Improved fix with suggestions by Greg King. --- libsrc/osic1p/bootstrap.s | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index 806532791..2a501b980 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -45,11 +45,10 @@ GETCHAR := $FFBF ; gets one character from ACIA FIRSTVISC = $85 ; Offset of first visible character in video RAM LINEDIST = $20 ; Offset in video RAM between two lines - lda #0 - sta load + ldy #<$0000 lda #<load_addr ldx #>load_addr - tay + sta load stx load+1 lda #<load_size eor #$FF @@ -107,13 +106,12 @@ CR = $0D ; ASCII-coded hexadecimal translation of the above assembly code. ; It was copied from the assembler listing. - .byte "A9", CR, "00", CR - .byte "85", CR, "08", CR + .byte "A0", CR, "00", CR .byte "A9", CR hex2 <load_addr .byte CR, "A2", CR hex2 >load_addr - .byte CR, "A8", CR + .byte CR, "85", CR, "08", CR .byte "86", CR, "09", CR .byte "A9", CR hex2 <load_size From 2842b68a04c024c479baacfafa3752bd78f0c675 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 19 Mar 2015 06:27:25 -0400 Subject: [PATCH 121/351] Reverted one of the changes in how function prototypes look, in cc65's assembly output. --- src/cc65/datatype.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 8d17d2851..9971a9569 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -290,18 +290,18 @@ void PrintType (FILE* F, const Type* T) fprintf (F, "union %s", ((SymEntry*) T->A.P)->Name); break; case T_TYPE_ARRAY: - if (T->A.L == UNSPECIFIED) { - fprintf (F, "[] "); - } else { - fprintf (F, "[%ld] ", T->A.L); - } /* Recursive call */ PrintType (F, T + 1); + if (T->A.L == UNSPECIFIED) { + fprintf (F, " []"); + } else { + fprintf (F, " [%ld]", T->A.L); + } return; case T_TYPE_PTR: - fprintf (F, "* "); /* Recursive call */ PrintType (F, T + 1); + fprintf (F, " *"); return; case T_TYPE_FUNC: fprintf (F, "function returning "); From b4bab018ac31a909e0864b0a2c20ddcd8fd652f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 22 Mar 2015 12:10:58 +0100 Subject: [PATCH 122/351] More room by default for zero-page data. --- cfg/osic1p.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/osic1p.cfg b/cfg/osic1p.cfg index b05eeb3d5..fd9aa604e 100644 --- a/cfg/osic1p.cfg +++ b/cfg/osic1p.cfg @@ -10,7 +10,7 @@ SYMBOLS { } MEMORY { # for size of ZP, see runtime/zeropage.s and c1p/extzp.s - ZP: file = "", define = yes, start = $0002, size = $001A + $0006; + ZP: file = "", define = yes, start = $0002, size = $001A + $0020; HEAD: file = %O, start = $0000, size = $00B6; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; } From 7fb206e38162886bec5109480b84254ef31797cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Sun, 22 Mar 2015 22:45:53 +0100 Subject: [PATCH 123/351] Macro-based implementation of screen layout configuration modules. --- doc/osi.sgml | 37 +++++- libsrc/osic1p/_scrsize.s | 19 --- libsrc/osic1p/clrscr.s | 31 ----- libsrc/osic1p/cputc.s | 100 -------------- libsrc/osic1p/extra/screen-s3-32x28.s | 16 +++ libsrc/osic1p/osic1p.inc | 6 - libsrc/osic1p/osiscreen.inc | 184 ++++++++++++++++++++++++++ libsrc/osic1p/screen-c1p-24x24.s | 16 +++ 8 files changed, 250 insertions(+), 159 deletions(-) delete mode 100644 libsrc/osic1p/_scrsize.s delete mode 100644 libsrc/osic1p/clrscr.s delete mode 100644 libsrc/osic1p/cputc.s create mode 100644 libsrc/osic1p/extra/screen-s3-32x28.s create mode 100644 libsrc/osic1p/osiscreen.inc create mode 100644 libsrc/osic1p/screen-c1p-24x24.s diff --git a/doc/osi.sgml b/doc/osi.sgml index 1ceaec359..ab1b4cee5 100644 --- a/doc/osi.sgml +++ b/doc/osi.sgml @@ -6,7 +6,7 @@ <author> <url url="mailto:stephan.muehlstrasser@web.de" name="Stephan Mühlstrasser">,<newline> <url url="mailto:greg.king5@verizon.net" name="Greg King"> -<date>2015-03-08 +<date>2015-03-17 <abstract> An overview over the Ohio Scientific runtime system as it is implemented for the cc65 C @@ -33,7 +33,7 @@ information. <sect>Targets<p> Currently the target "osic1p" is implemented. This works for the Ohio Scientific -Challenger 1P machine. +Challenger 1P machine and for the Briel Superboard /// replica. <sect>Program file formats<p> @@ -123,7 +123,7 @@ Challenger 1P, which is implicitly used via <tt/-t osic1p/. The osic1p package comes with additional secondary linker config files, which are used via <tt/-t osic1p -C <configfile>/. -<sect1>default config file (<tt/osic1p.cfg/)<p> +<sect1>Default config file (<tt/osic1p.cfg/)<p> The default configuration is tailored to C programs. @@ -161,6 +161,36 @@ There is no specific support for direct hardware access. There are no loadable drivers available. +<sect>Support for different screen layouts<p> + +By default the conio library uses a 24 columns by 24 lines screen layout +for the Challenger 1P, like under BASIC. In addition to that there is support +for other screen layouts with extra modules. + +There is a module <tt/screen-c1p-24x24.o/ in the OSI-specific +cc65 runtime library that contains all conio functions that depend +on the screen layout. No further configuration is needed for using the +default screen layout of the Challenger 1P. + +For other screen layouts additional versions of the screen module are +available. The linker finds these modules without further configuration +if they are specified on the compiler or linker command line. The +extra module then overrides the default module. + +Sample <tt/cl65/ command line to override the default screen +module with the module <tt/osic1p-screen-s3-32x28.o/: + +<tscreen><verb> +cl65 -o hello -t osic1p osic1p-screen-s3-32x28.o hello.c +</verb></tscreen> + +Currently the following extra screen configuration modules are implemented: + +<itemize> +<item><tt>osic1p-screen-s3-32x28.o</tt>: 32 columns by 28 lines mode +for Briel Superboard ///</item> +</itemize> + <sect>Limitations<p> <sect1>stdio implementation<p> @@ -200,3 +230,4 @@ freely, subject to the following restrictions: </enum> </article> + diff --git a/libsrc/osic1p/_scrsize.s b/libsrc/osic1p/_scrsize.s deleted file mode 100644 index be07234b4..000000000 --- a/libsrc/osic1p/_scrsize.s +++ /dev/null @@ -1,19 +0,0 @@ -; -; based on PET implementation -; -; originally by: -; Ullrich von Bassewitz, 26.10.2000 -; -; Screen size variables -; - - .export screensize - - .include "extzp.inc" - .include "osic1p.inc" - -.proc screensize - ldx #SCR_WIDTH - ldy #SCR_HEIGHT - rts -.endproc diff --git a/libsrc/osic1p/clrscr.s b/libsrc/osic1p/clrscr.s deleted file mode 100644 index db8da6912..000000000 --- a/libsrc/osic1p/clrscr.s +++ /dev/null @@ -1,31 +0,0 @@ -; -; void clrscr (void); -; - .export _clrscr - .import plot - .include "extzp.inc" - .include "osic1p.inc" - -; Adapted from the Challenger Character Graphics -; Reference Manual, "2.3.3 MACHINE LANGUAGE SCREEN CLEAR" -; This is self-modifying code! -BANKS = VIDEORAMSIZE / $100 - -_clrscr: - lda #' ' - ldy #BANKS - ldx #$00 -staloc: - sta SCRNBASE,X - inx - bne staloc - inc staloc+2 - dey - bne staloc - lda #>(SCRNBASE) ; Load high byte - sta staloc+2 ; Restore base address - - lda #$00 ; Cursor in upper left corner - sta CURS_X - sta CURS_Y - jmp plot ; Set the cursor position diff --git a/libsrc/osic1p/cputc.s b/libsrc/osic1p/cputc.s deleted file mode 100644 index 2baada465..000000000 --- a/libsrc/osic1p/cputc.s +++ /dev/null @@ -1,100 +0,0 @@ -; -; cputc/cputcxy for Challenger 1P -; Based on PET/CBM implementation -; -; void cputcxy (unsigned char x, unsigned char y, char c); -; void cputc (char c); -; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - .import popa, _gotoxy - - .include "osic1p.inc" - .include "extzp.inc" - -FIRSTVISC = $85 ; Offset of first visible character in video RAM -LINEDIST = $20 ; Offset in video RAM between two lines -BLOCKSIZE = $100 ; Size of block to scroll - -_cputcxy: - pha ; Save C - jsr popa ; Get Y - jsr _gotoxy ; Set cursor, drop x - pla ; Restore C - -; Plot a character - also used as internal function - -_cputc: cmp #$0A ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers - -L1: cmp #$0D ; LF? - beq newline ; Recalculate pointers - -cputdirect: - jsr putchar ; Write the character to the screen - -; Advance cursor position - -advance: - cpy #(SCR_WIDTH - 1) - bne L3 - jsr newline ; New line - ldy #$FF ; + cr -L3: iny - sty CURS_X - rts - -newline: - inc CURS_Y - lda CURS_Y - cmp #SCR_HEIGHT ; Screen height - bne plot - dec CURS_Y ; Bottom of screen reached, scroll - ldx #0 -scroll: -.repeat 3, I ; Scroll screen in three blocks of size - ; BLOCKSIZE - lda SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC+LINEDIST,x - sta SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC,x -.endrepeat - inx - bne scroll - - lda #' ' ; Clear bottom line of screen -bottom: - sta SCRNBASE+(3*BLOCKSIZE)+FIRSTVISC,x - inx - cpx #SCR_WIDTH - bne bottom - -plot: ldy CURS_Y - lda ScrLo,y - sta SCREEN_PTR - lda ScrHi,y - sta SCREEN_PTR+1 - rts - -; Write one character to the screen without doing anything else, return X -; position in Y - -putchar: - ldy CURS_X - sta (SCREEN_PTR),y ; Set char - rts - -; Screen address tables - offset to real screen - -.rodata - -ScrLo: .byte $85, $A5, $C5, $E5, $05, $25, $45, $65 - .byte $85, $A5, $C5, $E5, $05, $25, $45, $65 - .byte $85, $A5, $C5, $E5, $05, $25, $45, $65 - .byte $85 - -ScrHi: .byte $D0, $D0, $D0, $D0, $D1, $D1, $D1, $D1 - .byte $D1, $D1, $D1, $D1, $D2, $D2, $D2, $D2 - .byte $D2, $D2, $D2, $D2, $D3, $D3, $D3, $D3 - .byte $D3 diff --git a/libsrc/osic1p/extra/screen-s3-32x28.s b/libsrc/osic1p/extra/screen-s3-32x28.s new file mode 100644 index 000000000..40ed24203 --- /dev/null +++ b/libsrc/osic1p/extra/screen-s3-32x28.s @@ -0,0 +1,16 @@ +; +; Implementation of screen-layout related functions for Superboard /// +; + + .include "../osiscreen.inc" + +S3_SCR_BASE := $D000 ; Base of Superboard /// video RAM +S3_VRAM_SIZE = $0400 ; Size of Superboard /// video RAM (1 kB) +S3_SCR_WIDTH = $20 ; Screen width +S3_SCR_HEIGHT = $1C ; Screen height +S3_SCR_FIRSTCHAR = $80 ; Offset of cursor position (0, 0) from base + ; of video RAM +S3_SCROLL_DIST = $20 ; Memory distance for scrolling by one line + +osi_screen_funcs S3_SCR_BASE, S3_VRAM_SIZE, S3_SCR_FIRSTCHAR, \ + S3_SCR_WIDTH, S3_SCR_HEIGHT, S3_SCROLL_DIST diff --git a/libsrc/osic1p/osic1p.inc b/libsrc/osic1p/osic1p.inc index 232c471aa..eabeaf79e 100644 --- a/libsrc/osic1p/osic1p.inc +++ b/libsrc/osic1p/osic1p.inc @@ -1,10 +1,4 @@ ; Addresses -SCRNBASE := $D000 ; Base of video RAM INPUTC := $FD00 ; Input character from keyboard RESET := $FF00 ; Reset address, show boot prompt KBD := $DF00 ; Polled keyboard register - -; Other definitions -VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) -SCR_WIDTH = $18 ; Screen width -SCR_HEIGHT = $18 ; Screen height diff --git a/libsrc/osic1p/osiscreen.inc b/libsrc/osic1p/osiscreen.inc new file mode 100644 index 000000000..66c5e9fb0 --- /dev/null +++ b/libsrc/osic1p/osiscreen.inc @@ -0,0 +1,184 @@ +; +; Macro definitions for screen layout modules +; + + .include "extzp.inc" + +.linecont + + +; +; Internal function for screensize() +; +.macro osi_screensize ScrWidth, ScrHeight + ; Macro implementation of internal screensize + ; function for given width and height in + ; characters + + .export screensize + +.proc screensize + ldx #ScrWidth + ldy #ScrHeight + rts +.endproc +.endmacro + +; +; void clrscr (void); +; +.macro osi_clrscr ScrBase, ScrRamSize + + .export _clrscr + +.proc _clrscr + lda #<ScrBase ; Fill whole video RAM with blanks by calling + ldx #>ScrBase ; memset appropriately + jsr pushax + + lda #' ' + ldx #$00 + jsr pushax + + lda #<ScrRamSize + ldx #>ScrRamSize + jsr _memset + + lda #$00 ; Cursor in upper left corner + sta CURS_X + sta CURS_Y + + jmp plot ; Set the cursor position +.endproc + +.endmacro + +; +; cputc/cputcxy for Challenger 1P +; Based on PET/CBM implementation +; + +.macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ + ScrollDist, ScrLo, ScrHi + + ; Number of characters to move for scrolling + ; by one line +ScrollLength = (ScrHeight - 1) * ScrollDist + +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + +_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position, register Y contains horizontal position after +; putchar + + cpy #(ScrWidth - 1) ; Check whether line is full + bne L3 + jsr newline ; New line + ldy #$FF ; + cr +L3: iny + sty CURS_X + rts + +newline: + inc CURS_Y + lda CURS_Y + cmp #ScrHeight ; Screen height + bne plot + dec CURS_Y ; Bottom of screen reached, scroll + + ; Scroll destination address + lda #<(ScrBase + ScrFirstChar) + ldx #>(ScrBase + ScrFirstChar) + jsr pushax + + ; Scroll source address + lda #<(ScrBase + ScrFirstChar + ScrollDist) + ldx #>(ScrBase + ScrFirstChar + ScrollDist) + jsr pushax + + ; Number of characters to move + lda #<ScrollLength + ldx #>ScrollLength + jsr _memmove + + ; Address of first character in last line + ; of screen + lda #<(ScrBase + ScrFirstChar + ScrollLength) + sta ptr1 + lda #>(ScrBase + ScrFirstChar + ScrollLength) + sta ptr1+1 + + ldy #ScrWidth ; Fill last line with blanks + lda #' ' +clrln: sta (ptr1),y + dey + bpl clrln + +plot: ldy CURS_Y + lda ScrLo,y + sta SCREEN_PTR + lda ScrHi,y + sta SCREEN_PTR+1 + rts + +; Write one character to the screen without doing anything else, return X +; position in register Y + +putchar: + ldy CURS_X + sta (SCREEN_PTR),y ; Set char + rts + +.endmacro + +.macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \ + ScrWidth, ScrHeight, ScrollDist + + .import popa, _gotoxy + .import _memmove, _memset, pushax + .importzp ptr1 + +.rodata + +; Screen address tables - offset to real screen +ScrTabLo: + .repeat ScrHeight, I + .byte <(ScrBase + ScrFirstChar + I * ScrollDist) + .endrep + +ScrTabHi: + .repeat ScrHeight, I + .byte >(ScrBase + ScrFirstChar + I * ScrollDist) + .endrep + +.code + +osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \ + ScrollDist, ScrTabLo, ScrTabHi +osi_screensize ScrWidth, ScrHeight +osi_clrscr ScrBase, ScrRamSize + +.endmacro \ No newline at end of file diff --git a/libsrc/osic1p/screen-c1p-24x24.s b/libsrc/osic1p/screen-c1p-24x24.s new file mode 100644 index 000000000..e691c2f1f --- /dev/null +++ b/libsrc/osic1p/screen-c1p-24x24.s @@ -0,0 +1,16 @@ +; +; Implementation of screen-layout related functions for Challenger 1P +; + + .include "osiscreen.inc" + +C1P_SCR_BASE := $D000 ; Base of C1P video RAM +C1P_VRAM_SIZE = $0400 ; Size of C1P video RAM (1 kB) +C1P_SCR_WIDTH = $18 ; Screen width +C1P_SCR_HEIGHT = $18 ; Screen height +C1P_SCR_FIRSTCHAR = $85 ; Offset of cursor position (0, 0) from base + ; of video RAM +C1P_SCROLL_DIST = $20 ; Memory distance for scrolling by one line + +osi_screen_funcs C1P_SCR_BASE, C1P_VRAM_SIZE, C1P_SCR_FIRSTCHAR, \ + C1P_SCR_WIDTH, C1P_SCR_HEIGHT, C1P_SCROLL_DIST From 810fe229e94d3259a712b688f048598c155a9536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20M=C3=BChlstrasser?= <stephan.muehlstrasser@web.de> Date: Mon, 23 Mar 2015 19:31:46 +0100 Subject: [PATCH 124/351] Document osic1p-specific constants. --- doc/ca65.sgml | 1 + doc/cc65.sgml | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 32cf0b80b..fa3258562 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -4418,6 +4418,7 @@ compiler, depending on the target system selected: <item><tt/__LUNIX__/ - Target system is <tt/lunix/ <item><tt/__LYNX__/ - Target system is <tt/lynx/ <item><tt/__NES__/ - Target system is <tt/nes/ +<item><tt/__OSIC1P__/ - Target system is <tt/osic1p/ <item><tt/__PET__/ - Target system is <tt/pet/ <item><tt/__PLUS4__/ - Target system is <tt/plus4/ <item><tt/__SIM6502__/ - Target system is <tt/sim6502/ diff --git a/doc/cc65.sgml b/doc/cc65.sgml index a6b4a07ee..aa8a75aef 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -348,6 +348,7 @@ Here is a description of all the command line options: <item>lunix <item>lynx <item>nes + <item>osic1p <item>pet (all CBM PET systems except the 2001) <item>plus4 <item>sim6502 @@ -819,6 +820,11 @@ The compiler defines several macros at startup: Is defined if the compiler was called with the <tt/-Os/ command line option. + <tag><tt>__OSIC1P__</tt></tag> + + This macro is defined if the target is the Ohio Scientific Challenger 1P + (-t osic1p). + <tag><tt>__PET__</tt></tag> This macro is defined if the target is the PET family of computers (-t pet). From 24e902059cfaf2aa56cee6a611f86d70f0fe045d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sun, 19 Apr 2015 21:16:43 +0200 Subject: [PATCH 125/351] Allow up 127 chars of cmdline for programs started by the loader. --- libsrc/apple2/mainargs.s | 12 ++++++------ libsrc/apple2/targetutil/loader.s | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libsrc/apple2/mainargs.s b/libsrc/apple2/mainargs.s index 6b0df4ded..af29637a7 100644 --- a/libsrc/apple2/mainargs.s +++ b/libsrc/apple2/mainargs.s @@ -34,12 +34,12 @@ MAXARGS = 10 ; ProDOS stores the filename in the second half of BASIC's input buffer, so -; there are 128 characters left. At least 7 characters are necessary for the -; CALLxxxx:REM so 121 characters may be used before overwriting the ProDOS -; filename. As we don't want to put further restrictions on the command-line -; length we reserve those 121 characters terminated by a zero. +; there are 128 characters left. At least 1 characters is necessary for the +; REM so 127 characters may be used before overwriting the ProDOS filename. +; As we don't want to put further restrictions on the command-line length +; we reserve those 127 characters terminated by a zero. -BUF_LEN = 122 +BUF_LEN = 128 BASIC_BUF = $200 FNAM_LEN = $280 @@ -176,4 +176,4 @@ argv: .addr FNAM .bss -buffer: .res BUF_LEN \ No newline at end of file +buffer: .res BUF_LEN diff --git a/libsrc/apple2/targetutil/loader.s b/libsrc/apple2/targetutil/loader.s index 0173f6105..2872de1da 100644 --- a/libsrc/apple2/targetutil/loader.s +++ b/libsrc/apple2/targetutil/loader.s @@ -95,8 +95,8 @@ PRESS_ANY_KEY: jmp :+ .byte $EE .byte $EE - .byte 65 -STARTUP:.res 65 + .byte $80 +STARTUP:.res $80 ; Reset stack : ldx #$FF @@ -127,7 +127,7 @@ STARTUP:.res 65 : lda STARTUP + 1,x : sta STACK,x dex - bpl :-- + bpl :-- ; Provide some user feedback lda #<LOADING From ae4f9336b37d0474bb6168713bb99ca387d7b59e Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sun, 19 Apr 2015 21:59:05 +0200 Subject: [PATCH 126/351] Behave more like BASIC.SYSTEM and allow for argv[0]. --- libsrc/apple2/exec.s | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libsrc/apple2/exec.s b/libsrc/apple2/exec.s index c486306bb..2f6d29802 100644 --- a/libsrc/apple2/exec.s +++ b/libsrc/apple2/exec.s @@ -28,6 +28,20 @@ _exec: jsr pushname bne oserr + ; ProDOS TechRefMan, chapter 5.1.5.1: + ; "The complete or partial pathname of the system program + ; is stored at $280, starting with a length byte." + ; In fact BASIC.SYSTEM does the same for BLOAD and BRUN of + ; binary programs so we should do the same too in any case + ; especially as _we_ rely on it in mainargs.s for argv[0]. + ldy #$00 + lda (sp),y + tay +: lda (sp),y + sta $0280,y + dey + bpl :- + ; Set pushed name lda sp ldx sp+1 @@ -53,17 +67,6 @@ _exec: cmp #$FF ; SYS file? bne binary ; No, check for BIN file - ; ProDOS TechRefMan, chapter 5.1.5.1: - ; "The complete or partial pathname of the system program - ; is stored at $280, starting with a length byte." - ldy #$00 - lda (sp),y - tay -: lda (sp),y - sta $0280,y - dey - bpl :- - ; SYS programs replace BASIC.SYSTEM so set in the ProDOS system bit map ; protection for pages $80 - $BF just in case BASIC.SYSTEM is there now ldx #$0F ; Start with protection for pages $B8 - $BF From c6f45a338c18f43c588789fdac751d8014f32c59 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Sun, 19 Apr 2015 23:21:56 -0400 Subject: [PATCH 127/351] Added function .ADDRSIZE to ca65 --- src/ca65/expr.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++ src/ca65/feature.c | 2 ++ src/ca65/feature.h | 1 + src/ca65/global.c | 1 + src/ca65/global.h | 2 ++ src/ca65/pseudo.c | 1 + src/ca65/scanner.c | 19 +++++++++- src/ca65/token.h | 1 + 8 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index e4d6f7363..ad1a0b155 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -629,6 +629,92 @@ static ExprNode* FuncReferenced (void) +static ExprNode* FuncAddrSize(void) +/* Handle the .ADDRSIZE function */ +{ + StrBuf ScopeName = STATIC_STRBUF_INITIALIZER; + StrBuf Name = STATIC_STRBUF_INITIALIZER; + SymEntry* Sym; + int AddrSize; + int NoScope; + + + /* Assume we don't know the size */ + AddrSize = 0; + + /* Check for a cheap local which needs special handling */ + if (CurTok.Tok == TOK_LOCAL_IDENT) { + + /* Cheap local symbol */ + Sym = SymFindLocal(SymLast, &CurTok.SVal, SYM_FIND_EXISTING); + if (Sym == 0) { + Error("Unknown symbol or scope: `%m%p'", &CurTok.SVal); + } + else { + AddrSize = Sym->AddrSize; + } + + /* Remember and skip SVal, terminate ScopeName so it is empty */ + SB_Copy(&Name, &CurTok.SVal); + NextTok(); + SB_Terminate(&ScopeName); + + } + else { + + /* Parse the scope and the name */ + SymTable* ParentScope = ParseScopedIdent(&Name, &ScopeName); + + /* Check if the parent scope is valid */ + if (ParentScope == 0) { + /* No such scope */ + SB_Done(&ScopeName); + SB_Done(&Name); + return GenLiteral0(); + } + + /* If ScopeName is empty, no explicit scope was specified. We have to + * search upper scope levels in this case. + */ + NoScope = SB_IsEmpty(&ScopeName); + + /* If we did find a scope with the name, read the symbol defining the + * size, otherwise search for a symbol entry with the name and scope. + */ + if (NoScope) { + Sym = SymFindAny(ParentScope, &Name); + } + else { + Sym = SymFind(ParentScope, &Name, SYM_FIND_EXISTING); + } + /* If we found the symbol retrieve the size, otherwise complain */ + if (Sym) { + AddrSize = Sym->AddrSize; + } + else { + Error("Unknown symbol or scope: `%m%p%m%p'", + &ScopeName, &Name); + } + + } + + /* Check if we have a size */ + /* if we don't know, return it anyway, zero can mean unknown, or uncomment this code for an error + if (AddrSize == 0 ) { + Error ("Address size of `%m%p%m%p' is unknown", &ScopeName, &Name); + } + */ + + /* Free the string buffers */ + SB_Done(&ScopeName); + SB_Done(&Name); + + /* Return the size */ + return GenLiteralExpr(AddrSize); +} + + + static ExprNode* FuncSizeOf (void) /* Handle the .SIZEOF function */ { @@ -965,6 +1051,10 @@ static ExprNode* Factor (void) N = Function (FuncBankByte); break; + case TOK_ADDRSIZE: + N = Function(FuncAddrSize); + break; + case TOK_BLANK: N = Function (FuncBlank); break; diff --git a/src/ca65/feature.c b/src/ca65/feature.c index c398d2b37..3462d5501 100644 --- a/src/ca65/feature.c +++ b/src/ca65/feature.c @@ -63,6 +63,7 @@ static const char* FeatureKeys[FEAT_COUNT] = { "c_comments", "force_range", "underline_in_numbers", + "addrsize", }; @@ -119,6 +120,7 @@ feature_t SetFeature (const StrBuf* Key) case FEAT_C_COMMENTS: CComments = 1; break; case FEAT_FORCE_RANGE: ForceRange = 1; break; case FEAT_UNDERLINE_IN_NUMBERS: UnderlineInNumbers= 1; break; + case FEAT_ADDRSIZE: AddrSize = 1; break; default: /* Keep gcc silent */ break; } diff --git a/src/ca65/feature.h b/src/ca65/feature.h index 9682ad9b9..3a520a54a 100644 --- a/src/ca65/feature.h +++ b/src/ca65/feature.h @@ -65,6 +65,7 @@ typedef enum { FEAT_C_COMMENTS, FEAT_FORCE_RANGE, FEAT_UNDERLINE_IN_NUMBERS, + FEAT_ADDRSIZE, /* Special value: Number of features available */ FEAT_COUNT diff --git a/src/ca65/global.c b/src/ca65/global.c index b3d6d6c6e..77ed66e7f 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -82,3 +82,4 @@ unsigned char OrgPerSeg = 0; /* Make .org local to current seg */ unsigned char CComments = 0; /* Allow C like comments */ unsigned char ForceRange = 0; /* Force values into expected range */ unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */ +unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */ diff --git a/src/ca65/global.h b/src/ca65/global.h index 378a776e6..fb254f835 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -84,6 +84,8 @@ extern unsigned char OrgPerSeg; /* Make .org local to current seg */ extern unsigned char CComments; /* Allow C like comments */ extern unsigned char ForceRange; /* Force values into expected range */ extern unsigned char UnderlineInNumbers; /* Allow underlines in numbers */ +extern unsigned char AddrSize; /* Allow .ADDRSIZE function */ + diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 0b066c7bd..2e8a473a5 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1964,6 +1964,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoA16 }, { ccNone, DoA8 }, { ccNone, DoAddr }, /* .ADDR */ + { ccNone, DoUnexpected }, /* .ADDRSIZE */ { ccNone, DoAlign }, { ccNone, DoASCIIZ }, { ccNone, DoAssert }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 890e1c7a3..9543c9872 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -135,6 +135,7 @@ struct DotKeyword { { ".A16", TOK_A16 }, { ".A8", TOK_A8 }, { ".ADDR", TOK_ADDR }, + { ".ADDRSIZE", TOK_ADDRSIZE }, { ".ALIGN", TOK_ALIGN }, { ".AND", TOK_BOOLAND }, { ".ASCIIZ", TOK_ASCIIZ }, @@ -723,8 +724,24 @@ static token_t FindDotKeyword (void) R = bsearch (&K, DotKeywords, sizeof (DotKeywords) / sizeof (DotKeywords [0]), sizeof (DotKeywords [0]), CmpDotKeyword); if (R != 0) { + + /* By default, disable any somewhat experiemental DotKeyword. */ + + switch (R->Tok) { + + case TOK_ADDRSIZE: + /* Disallow .ADDRSIZE function by default */ + if (AddrSize == 0) { + return TOK_NONE; + } + break; + + default: + break; + } return R->Tok; - } else { + } + else { return TOK_NONE; } } diff --git a/src/ca65/token.h b/src/ca65/token.h index 803b12785..7aaba34c3 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -123,6 +123,7 @@ typedef enum token_t { TOK_A16 = TOK_FIRSTPSEUDO, TOK_A8, TOK_ADDR, + TOK_ADDRSIZE, TOK_ALIGN, TOK_ASCIIZ, TOK_ASSERT, From dfddf8f9d25ed29ee8e26715b018ba60a7fb06a0 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Apr 2015 17:20:54 -0400 Subject: [PATCH 128/351] Improved on funciton .ADDRSIZE. Conform to coding style. --- src/ca65/expr.c | 63 +++++++++++++++++++++------------------------- src/ca65/scanner.c | 5 ++-- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index ad1a0b155..8fdc37421 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -629,7 +629,7 @@ static ExprNode* FuncReferenced (void) -static ExprNode* FuncAddrSize(void) +static ExprNode* FuncAddrSize (void) /* Handle the .ADDRSIZE function */ { StrBuf ScopeName = STATIC_STRBUF_INITIALIZER; @@ -646,71 +646,66 @@ static ExprNode* FuncAddrSize(void) if (CurTok.Tok == TOK_LOCAL_IDENT) { /* Cheap local symbol */ - Sym = SymFindLocal(SymLast, &CurTok.SVal, SYM_FIND_EXISTING); + Sym = SymFindLocal (SymLast, &CurTok.SVal, SYM_FIND_EXISTING); if (Sym == 0) { - Error("Unknown symbol or scope: `%m%p'", &CurTok.SVal); - } - else { + Error ("Unknown symbol or scope: `%m%p'", &CurTok.SVal); + } else { AddrSize = Sym->AddrSize; } /* Remember and skip SVal, terminate ScopeName so it is empty */ - SB_Copy(&Name, &CurTok.SVal); - NextTok(); - SB_Terminate(&ScopeName); + SB_Copy (&Name, &CurTok.SVal); + NextTok (); + SB_Terminate (&ScopeName); - } - else { + } else { /* Parse the scope and the name */ - SymTable* ParentScope = ParseScopedIdent(&Name, &ScopeName); + SymTable* ParentScope = ParseScopedIdent (&Name, &ScopeName); /* Check if the parent scope is valid */ if (ParentScope == 0) { /* No such scope */ - SB_Done(&ScopeName); - SB_Done(&Name); - return GenLiteral0(); + SB_Done (&ScopeName); + SB_Done (&Name); + return GenLiteral0 (); } /* If ScopeName is empty, no explicit scope was specified. We have to - * search upper scope levels in this case. + ** search upper scope levels in this case. */ - NoScope = SB_IsEmpty(&ScopeName); + NoScope = SB_IsEmpty (&ScopeName); /* If we did find a scope with the name, read the symbol defining the - * size, otherwise search for a symbol entry with the name and scope. + ** size, otherwise search for a symbol entry with the name and scope. */ if (NoScope) { - Sym = SymFindAny(ParentScope, &Name); - } - else { - Sym = SymFind(ParentScope, &Name, SYM_FIND_EXISTING); + Sym = SymFindAny (ParentScope, &Name); + } else { + Sym = SymFind (ParentScope, &Name, SYM_FIND_EXISTING); } /* If we found the symbol retrieve the size, otherwise complain */ if (Sym) { AddrSize = Sym->AddrSize; - } - else { - Error("Unknown symbol or scope: `%m%p%m%p'", + } else { + Error ("Unknown symbol or scope: `%m%p%m%p'", &ScopeName, &Name); } } - /* Check if we have a size */ - /* if we don't know, return it anyway, zero can mean unknown, or uncomment this code for an error - if (AddrSize == 0 ) { - Error ("Address size of `%m%p%m%p' is unknown", &ScopeName, &Name); + if (AddrSize == 0) { + Warning(1, "Unknown address size: `%m%p%m%p'", + &ScopeName, &Name); } - */ /* Free the string buffers */ - SB_Done(&ScopeName); - SB_Done(&Name); + SB_Done (&ScopeName); + SB_Done (&Name); - /* Return the size */ - return GenLiteralExpr(AddrSize); + /* Return the size. */ + + return GenLiteralExpr (AddrSize); } @@ -1052,7 +1047,7 @@ static ExprNode* Factor (void) break; case TOK_ADDRSIZE: - N = Function(FuncAddrSize); + N = Function (FuncAddrSize); break; case TOK_BLANK: diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 9543c9872..db747cf70 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -739,9 +739,10 @@ static token_t FindDotKeyword (void) default: break; } + return R->Tok; - } - else { + + } else { return TOK_NONE; } } From 499eab65f1d31b8e2e3cb00cb88f5c51c8d7585c Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Apr 2015 18:56:34 -0400 Subject: [PATCH 129/351] Updated documentation for .ADDRSIZE and .FEATURE addrsize --- doc/ca65.sgml | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index fa3258562..0dc6e902d 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1278,6 +1278,36 @@ writable. Pseudo functions expect their arguments in parenthesis, and they have a result, either a string or an expression. +<sect1><tt>.ADDRSIZE</tt><label id=".ADDRSIZE"><p> + + The <tt/.ADDRSIZE/ function is used to return the interal address size + associated with a symbol. This can be helpful in macros when knowing address + size of symbol can allow for custom instructions. + + Example: + + <tscreen><verb> + + .macro myLDA foo + + .if .ADDRSIZE(foo) = 1 + ;do custom command based on zeropage addressing: + .byte .A5h, foo + .elseif .ADDRSIZE(foo) = 2 + ;do custom command based on absolute addressing: + .byte .ADh, foo + .elseif .ADDRSIZE(foo) = 0 + ; no address size define for this symbol: + .out .sprinft("Error, address size unknown for symbol %s", .string(foo)) + .endif + .endmacro + </verb></tscreen> + + This command is new and must be enabled with the <tt/.FEATURE addrsize/ command. + + See: <tt><ref id=".FEATURE" name=".FEATURE"></tt> + + <sect1><tt>.BANK</tt><label id=".BANK"><p> @@ -2596,6 +2626,12 @@ Here's a list of all control commands and a description, what they do: <descrip> + <tag><tt>addrsize</tt><label id="addrsize"></tag> + + Enables the .ADDRSIZE pseudo function. This function is experimental and not enabled by default. + + See also: <tt><ref id=".ADDRSIZE" name=".ADDRSIZE"></tt> + <tag><tt>at_in_identifiers</tt><label id="at_in_identifiers"></tag> Accept the at character (`@') as a valid character in identifiers. The @@ -2648,11 +2684,6 @@ Here's a list of all control commands and a description, what they do: overridden. When using this feature, you may also get into trouble if later versions of the assembler define new keywords starting with a dot. - <tag><tt>loose_char_term</tt><label id="loose_char_term"></tag> - - Accept single quotes as well as double quotes as terminators for char - constants. - <tag><tt>loose_string_term</tt><label id="loose_string_term"></tag> Accept single quotes as well as double quotes as terminators for string From 9e9884764e502e6660ee70e73eec089d37cd8cc3 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Apr 2015 19:09:18 -0400 Subject: [PATCH 130/351] Small change to .ADDRSIZE documentation --- doc/ca65.sgml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 0dc6e902d..0ff0df0fd 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1281,13 +1281,12 @@ either a string or an expression. <sect1><tt>.ADDRSIZE</tt><label id=".ADDRSIZE"><p> The <tt/.ADDRSIZE/ function is used to return the interal address size - associated with a symbol. This can be helpful in macros when knowing address + associated with a symbol. This can be helpful in macros when knowing the address size of symbol can allow for custom instructions. Example: <tscreen><verb> - .macro myLDA foo .if .ADDRSIZE(foo) = 1 From 2d3cf98bc8ac30bc6c3a5aee7f2b93ed5dadbcc6 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Apr 2015 19:40:41 -0400 Subject: [PATCH 131/351] 2nd Small change to .ADDRSIZE documentation --- doc/ca65.sgml | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 0ff0df0fd..9f802af40 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1288,7 +1288,6 @@ either a string or an expression. <tscreen><verb> .macro myLDA foo - .if .ADDRSIZE(foo) = 1 ;do custom command based on zeropage addressing: .byte .A5h, foo From ffa52863b3ad83fbf27b63b829a2196d4acac095 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Tue, 21 Apr 2015 16:09:01 -0400 Subject: [PATCH 132/351] Small changes to coding style and to ca65 documentation for .ADDRSIZE --- doc/ca65.sgml | 30 ++++++++++++++++++------------ src/ca65/expr.c | 6 ++---- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 9f802af40..e3057915d 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1278,26 +1278,28 @@ writable. Pseudo functions expect their arguments in parenthesis, and they have a result, either a string or an expression. + <sect1><tt>.ADDRSIZE</tt><label id=".ADDRSIZE"><p> The <tt/.ADDRSIZE/ function is used to return the interal address size associated with a symbol. This can be helpful in macros when knowing the address - size of symbol can allow for custom instructions. + size of symbol can help with custom instructions. Example: <tscreen><verb> .macro myLDA foo - .if .ADDRSIZE(foo) = 1 - ;do custom command based on zeropage addressing: - .byte .A5h, foo - .elseif .ADDRSIZE(foo) = 2 - ;do custom command based on absolute addressing: - .byte .ADh, foo - .elseif .ADDRSIZE(foo) = 0 - ; no address size define for this symbol: - .out .sprinft("Error, address size unknown for symbol %s", .string(foo)) - .endif + .if .ADDRSIZE(foo) = 1 + ;do custom command based on zeropage addressing: + .byte 0A5h, foo + .elseif .ADDRSIZE(foo) = 2 + ;do custom command based on absolute addressing: + .byte 0ADh + .word foo + .elseif .ADDRSIZE(foo) = 0 + ; no address size define for this symbol: + .out .sprintf("Error, address size unknown for symbol %s", .string(foo)) + .endif .endmacro </verb></tscreen> @@ -1306,7 +1308,6 @@ either a string or an expression. See: <tt><ref id=".FEATURE" name=".FEATURE"></tt> - <sect1><tt>.BANK</tt><label id=".BANK"><p> The <tt/.BANK/ function is used to support systems with banked memory. The @@ -2682,6 +2683,11 @@ Here's a list of all control commands and a description, what they do: overridden. When using this feature, you may also get into trouble if later versions of the assembler define new keywords starting with a dot. + <tag><tt>loose_char_term</tt><label id="loose_char_term"></tag> + + Accept single quotes as well as double quotes as terminators for char + constants. + <tag><tt>loose_string_term</tt><label id="loose_string_term"></tag> Accept single quotes as well as double quotes as terminators for string diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 8fdc37421..8b87d0860 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -688,15 +688,13 @@ static ExprNode* FuncAddrSize (void) if (Sym) { AddrSize = Sym->AddrSize; } else { - Error ("Unknown symbol or scope: `%m%p%m%p'", - &ScopeName, &Name); + Error ("Unknown symbol or scope: `%m%p%m%p'", &ScopeName, &Name); } } if (AddrSize == 0) { - Warning(1, "Unknown address size: `%m%p%m%p'", - &ScopeName, &Name); + Warning (1, "Unknown address size: `%m%p%m%p'", &ScopeName, &Name); } /* Free the string buffers */ From 0d765abd6c8f5c3c1d685436bfdb722a7142a830 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Tue, 21 Apr 2015 16:21:27 -0400 Subject: [PATCH 133/351] Fix typo in documentation for .ADDRSIZE --- doc/ca65.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index e3057915d..03aa72097 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1297,7 +1297,7 @@ either a string or an expression. .byte 0ADh .word foo .elseif .ADDRSIZE(foo) = 0 - ; no address size define for this symbol: + ; no address size defined for this symbol: .out .sprintf("Error, address size unknown for symbol %s", .string(foo)) .endif .endmacro From 8743e9911d33ca6aa01f8dcb2424644e6e06721e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 22 Apr 2015 09:59:23 -0400 Subject: [PATCH 134/351] Added a command-line option to compile a program, with __cdecl__ as the default calling convention. --- doc/cc65.sgml | 31 ++++++++++++++++++++++--------- src/cc65/codeinfo.c | 6 +++++- src/cc65/expr.c | 13 +++++++++---- src/cc65/function.c | 5 ++++- src/cc65/global.c | 3 ++- src/cc65/global.h | 3 ++- src/cc65/main.c | 13 ++++++++++++- 7 files changed, 56 insertions(+), 18 deletions(-) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index 842ba061a..fa6b824c6 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -3,7 +3,7 @@ <article> <title>cc65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2015-03-14 +<date>2015-04-21 <abstract> cc65 is a C compiler for 6502 targets. It supports several 6502 based home @@ -74,6 +74,7 @@ Short options: Long options: --add-source Include source as comment + --all-cdecl Make functions default to __cdecl__ --bss-name seg Set the name of the BSS segment --check-stack Generate stack overflow checks --code-name seg Set the name of the CODE segment @@ -114,6 +115,14 @@ Here is a description of all the command line options: <descrip> + <tag><tt>--all-cdecl</tt></tag> + + Tells the compiler that functions which aren't declared explicitly with + either the <tt/__cdecl__/ or <tt/__fastcall__/ calling conventions should + have the cdecl convention. (Normally, functions that aren't variadic are + fast-called.) + + <label id="option-bss-name"> <tag><tt>--bss-name seg</tt></tag> @@ -550,8 +559,9 @@ and the one defined by the ISO standard: possible. <p> <item> Most of the C library is available only with the fastcall calling - convention (see below). It means that you must not mix pointers to - those functions with pointers to user-written, cdecl functions. + convention (<ref id="extension-fastcall" name="see below">). It means + that you must not mix pointers to those functions with pointers to + user-written, cdecl functions. <p> <item> The <tt/volatile/ keyword doesn't have an effect. This is not as bad as it sounds, since the 6502 has so few registers that it isn't @@ -589,6 +599,7 @@ This cc65 version has some extensions to the ISO C standard. <ref id="inline-asm" name="see there">. <p> +<label id="extension-fastcall"> <item> The normal calling convention -- for non-variadic functions -- is named "fastcall". The syntax for a function declaration that <em/explicitly/ uses fastcall is @@ -611,10 +622,11 @@ This cc65 version has some extensions to the ISO C standard. For functions that are <tt/fastcall/, the rightmost parameter is not pushed on the stack but left in the primary register when the function is called. That significantly reduces the cost of calling functions. + <newline><newline> <p> <item> There is another calling convention named "cdecl". Variadic functions - (their prototypes have an ellipsis [<tt/.../]) always use this + (their prototypes have an ellipsis [<tt/.../]) always use that convention. The syntax for a function declaration using cdecl is <tscreen><verb> @@ -626,16 +638,17 @@ This cc65 version has some extensions to the ISO C standard. </verb></tscreen> An example would be <tscreen><verb> - void __cdecl__ f (unsigned char c) + int * __cdecl__ f (unsigned char c) </verb></tscreen> - The first form of the cdecl keyword is in the user namespace and can - therefore be disabled with the <tt><ref id="option--standard" - name="--standard"></tt> command line option. + + The first form of the cdecl keyword is in the user namespace; + and therefore, can be disabled with the <tt><ref id="option--standard" + name="--standard"></tt> command-line option. For functions that are <tt/cdecl/, the rightmost parameter is pushed onto the stack before the function is called. That increases the cost of calling those functions, especially when they are called from many - places. + places.<newline><newline> <p> <item> There are two pseudo variables named <tt/__AX__/ and <tt/__EAX__/. diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index ae264dce4..de51781a6 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -46,6 +46,7 @@ #include "codeseg.h" #include "datatype.h" #include "error.h" +#include "global.h" #include "reginfo.h" #include "symtab.h" #include "codeinfo.h" @@ -400,7 +401,10 @@ void GetFuncInfo (const char* Name, unsigned short* Use, unsigned short* Chg) */ if ((D->Flags & FD_VARIADIC) != 0) { *Use = REG_Y; - } else if (!IsQualCDecl (E->Type) && D->ParamCount > 0) { + } else if (D->ParamCount > 0 && + (AutoCDecl ? + IsQualFastcall (E->Type) : + !IsQualCDecl (E->Type))) { /* Will use registers depending on the last param. */ switch (CheckedSizeOf (D->LastParam->Type)) { case 1u: diff --git a/src/cc65/expr.c b/src/cc65/expr.c index c8c47f6aa..d615993c4 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1,7 +1,7 @@ /* expr.c ** ** 1998-06-21, Ullrich von Bassewitz -** 2015-03-10, Greg King +** 2015-04-19, Greg King */ @@ -471,9 +471,11 @@ static void FunctionCall (ExprDesc* Expr) /* Handle function pointers transparently */ IsFuncPtr = IsTypeFuncPtr (Expr->Type); if (IsFuncPtr) { - /* Check whether it's a fastcall function that has parameters */ - IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type + 1) && (Func->ParamCount > 0); + IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && Func->ParamCount > 0 && + (AutoCDecl ? + IsQualFastcall (Expr->Type + 1) : + !IsQualCDecl (Expr->Type + 1)); /* Things may be difficult, depending on where the function pointer ** resides. If the function pointer is an expression of some sort @@ -518,7 +520,10 @@ static void FunctionCall (ExprDesc* Expr) } /* If we didn't inline the function, get fastcall info */ - IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Expr->Type); + IsFastcall = (Func->Flags & FD_VARIADIC) == 0 && + (AutoCDecl ? + IsQualFastcall (Expr->Type) : + !IsQualCDecl (Expr->Type)); } /* Parse the parameter list */ diff --git a/src/cc65/function.c b/src/cc65/function.c index d80ba916a..22b305739 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -481,7 +481,10 @@ void NewFunc (SymEntry* Func) PushLiteralPool (Func); /* If this is a fastcall function, push the last parameter onto the stack */ - if ((D->Flags & FD_VARIADIC) == 0 && !IsQualCDecl (Func->Type) && D->ParamCount > 0) { + if ((D->Flags & FD_VARIADIC) == 0 && D->ParamCount > 0 && + (AutoCDecl ? + IsQualFastcall (Func->Type) : + !IsQualCDecl (Func->Type))) { unsigned Flags; /* Generate the push */ diff --git a/src/cc65/global.c b/src/cc65/global.c index e2800a65e..dbdd72f3c 100644 --- a/src/cc65/global.c +++ b/src/cc65/global.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -44,6 +44,7 @@ unsigned char AddSource = 0; /* Add source lines as comments */ +unsigned char AutoCDecl = 0; /* Make functions default to __cdecl__ */ unsigned char DebugInfo = 0; /* Add debug info to the obj */ unsigned char PreprocessOnly = 0; /* Just preprocess the input */ unsigned char DebugOptOutput = 0; /* Output debug stuff */ diff --git a/src/cc65/global.h b/src/cc65/global.h index 2abd78601..8b0af5a83 100644 --- a/src/cc65/global.h +++ b/src/cc65/global.h @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 1998-2012, Ullrich von Bassewitz */ +/* (C) 1998-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -52,6 +52,7 @@ /* Options */ extern unsigned char AddSource; /* Add source lines as comments */ +extern unsigned char AutoCDecl; /* Make functions default to __cdecl__ */ extern unsigned char DebugInfo; /* Add debug info to the obj */ extern unsigned char PreprocessOnly; /* Just preprocess the input */ extern unsigned char DebugOptOutput; /* Output debug stuff */ diff --git a/src/cc65/main.c b/src/cc65/main.c index ece22041a..6b42c4db1 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -6,7 +6,7 @@ /* */ /* */ /* */ -/* (C) 2000-2013, Ullrich von Bassewitz */ +/* (C) 2000-2015, Ullrich von Bassewitz */ /* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ @@ -104,6 +104,7 @@ static void Usage (void) "\n" "Long options:\n" " --add-source\t\t\tInclude source as comment\n" + " --all-cdecl\t\t\tMake functions default to __cdecl__\n" " --bss-name seg\t\tSet the name of the BSS segment\n" " --check-stack\t\t\tGenerate stack overflow checks\n" " --code-name seg\t\tSet the name of the CODE segment\n" @@ -350,6 +351,15 @@ static void OptAddSource (const char* Opt attribute ((unused)), +static void OptAllCDecl (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) +/* Make functions default to cdecl instead of fastcall. */ +{ + AutoCDecl = 1; +} + + + static void OptBssName (const char* Opt attribute ((unused)), const char* Arg) /* Handle the --bss-name option */ { @@ -790,6 +800,7 @@ int main (int argc, char* argv[]) /* Program long options */ static const LongOpt OptTab[] = { { "--add-source", 0, OptAddSource }, + { "--all-cdecl", 0, OptAllCDecl }, { "--bss-name", 1, OptBssName }, { "--check-stack", 0, OptCheckStack }, { "--code-name", 1, OptCodeName }, From b24c87e61fd2c625ecb0b8db357cc04d631f5633 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 22 Apr 2015 10:05:07 -0400 Subject: [PATCH 135/351] Changed the compiler test-suite to work with the fastcall-default version of cc65. --- test/ref/otccex.c | 2 +- test/val/Makefile | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/ref/otccex.c b/test/ref/otccex.c index f3d6c71ec..aa5df158f 100644 --- a/test/ref/otccex.c +++ b/test/ref/otccex.c @@ -126,7 +126,7 @@ mymain(int argc,char **argv) } else { /* why not using a function pointer ? */ f = &fact; - print_num((*(long (*)())f)(n), base); + print_num((*(long (*)(int))f)(n), base); } printf("\n"); return 0; diff --git a/test/val/Makefile b/test/val/Makefile index 2efcbd0de..cb954a307 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -26,6 +26,13 @@ TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c= all: $(TESTS) +# cq71.c and cq84.c have "K & R"-style syntax. And, some local forward +# function-declarations don't match the later global function definitions. +# Those programs fail when fastcall is used; but, the cdecl calling convention +# tolerates those conflicts. Therefore, make their functions default to cdecl. +# +$(WORKDIR)/cq71%prg $(WORKDIR)/cq84%prg: CC65FLAGS += -Wc --all-cdecl + $(WORKDIR)/%.prg: %.c $(CL65) $(CC65FLAGS) $< -o $@ $(SIM65) $(SIM65FLAGS) $@ From 3c1cd0d86778d3365dfb125db595ead31f201d16 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sun, 26 Apr 2015 14:01:36 +0200 Subject: [PATCH 136/351] Added cmdline support to exec(). The starting point is the CALL2051:REM <cmdline> approach. It uses the BASIC input buffer at $200. ProDOS stores the name of the loaded program at $280 (which we want for argv[0]) leaving us with 128 char buffer. If we run the program via exec() we don't need the CALL2051 but only the REM token (which is just one char). So have a maximum cmdline length of 126 (plus a terminating zero). There's no specification for ProDOS BIN file cmdline parameters so exec() just supports the CALL2051:REM <cmdline> approach. In contrast ProDOS SYS files allow for a 'startup filename'. A ProDOS filename is short than 126 chars so having exec() general cut the cmdline after 126 chars seems reasonable. If the SYS file we exec() allows for less we cut the cmdline further. Our 'loader.system' SYS file however allows for an unusually 126 char long "startup filename" as it is targeted towards cc65 BIN porgrams with their 126 cmdline length. --- libsrc/apple2/exec.s | 84 +++++++++++++++++++++++++++---- libsrc/apple2/mainargs.s | 10 ++-- libsrc/apple2/targetutil/loader.s | 58 +++++++++++---------- 3 files changed, 108 insertions(+), 44 deletions(-) diff --git a/libsrc/apple2/exec.s b/libsrc/apple2/exec.s index 2f6d29802..f589bd41a 100644 --- a/libsrc/apple2/exec.s +++ b/libsrc/apple2/exec.s @@ -23,6 +23,10 @@ oserr: jsr popname ; Preserves A jmp __mappederrno _exec: + ; Save cmdline + sta ptr4 + stx ptr4+1 + ; Get and push name jsr popax jsr pushname @@ -33,7 +37,7 @@ _exec: ; is stored at $280, starting with a length byte." ; In fact BASIC.SYSTEM does the same for BLOAD and BRUN of ; binary programs so we should do the same too in any case - ; especially as _we_ rely on it in mainargs.s for argv[0]. + ; especially as _we_ rely on it in mainargs.s for argv[0] ldy #$00 lda (sp),y tay @@ -66,13 +70,14 @@ _exec: lda mliparam + MLI::INFO::FILE_TYPE cmp #$FF ; SYS file? bne binary ; No, check for BIN file + sta file_type ; Save file type for cmdline handling ; SYS programs replace BASIC.SYSTEM so set in the ProDOS system bit map ; protection for pages $80 - $BF just in case BASIC.SYSTEM is there now ldx #$0F ; Start with protection for pages $B8 - $BF lda #%00000001 ; Protect only system global page : sta $BF60,x ; Set protection for 8 pages - lda #$00 ; Protect no page + lda #%00000000 ; Protect no page dex bpl :- bmi prodos ; Branch always @@ -115,7 +120,7 @@ setbuf: lda #$00 ; Low byte dex dex dex - + ; Set I/O buffer sta mliparam + MLI::OPEN::IO_BUFFER stx mliparam + MLI::OPEN::IO_BUFFER+1 @@ -129,7 +134,7 @@ setbuf: lda #$00 ; Low byte stx level beq :+ dec LEVEL - + ; Open file : lda #OPEN_CALL ldx #OPEN_COUNT @@ -161,8 +166,27 @@ setbuf: lda #$00 ; Low byte bit $C080 .endif + ; Reset stack we already passed + ; the point of no return anyway + ldx #$FF + txs + + ; Store up to 127 chars of cmdline (if any) + ; including terminating zero in stack page + ldy #$00 + lda ptr4+1 ; NULL? + beq :++ ; Yes, store as '\0' +: lda (ptr4),y +: sta $0100,y + beq :+ ; '\0' stored, done + iny + cpy #$7E + bcc :-- + lda #$00 ; '\0' + beq :- ; Branch always + ; Call loader stub after C libary shutdown - lda #<target +: lda #<target ldx #>target sta done+1 stx done+2 @@ -180,16 +204,58 @@ level : .res 1 source: jsr $BF00 .byte READ_CALL .word read_param - bcs :+ + bcs error ; Close program file jsr $BF00 .byte CLOSE_CALL .word close_param - bcs :+ + bcs error + + ; Check for cmdline handling + lda $0100 ; Valid cmdline? + beq jump ; No, jump to program right away + ldx file_type ; SYS file? + bne system ; Yes, check for startup filename + + ; Store REM and cmdline in BASIC input buffer + lda #$B2 ; REM token + bne :++ ; Branch always +: inx + lda a:$0100-1,x +: sta $0200,x + bne :-- + beq jump ; Branch always + + ; Check for startup filename support + ; ProDOS TechRefMan, chapter 5.1.5.1: + ; "$2000 is a jump instruction. $2003 and $2004 are $EE." +system: lda $2000 + cmp #$4C + bne jump + lda $2003 + cmp #$EE + bne jump + lda $2004 + cmp #$EE + bne jump + + ; Store cmdline in startup filename buffer + ldx #$01 +: lda a:$0100-1,x + beq :+ + sta $2006,x + inx + cpx $2005 ; Buffer full? + bcc :- ; No, continue +: dex + stx $2006 ; Store cmdline length ; Go for it ... - jmp (data_buffer) +jump: jmp (data_buffer) + +file_type = * - source + target + .byte $00 read_param = * - source + target .byte $04 ; PARAM_COUNT @@ -207,7 +273,7 @@ close_ref = * - source + target ; Quit to ProDOS dispatcher quit = * - source + target -: jsr $BF00 +error: jsr $BF00 .byte $65 ; QUIT .word quit_param diff --git a/libsrc/apple2/mainargs.s b/libsrc/apple2/mainargs.s index af29637a7..2e809dc56 100644 --- a/libsrc/apple2/mainargs.s +++ b/libsrc/apple2/mainargs.s @@ -34,12 +34,12 @@ MAXARGS = 10 ; ProDOS stores the filename in the second half of BASIC's input buffer, so -; there are 128 characters left. At least 1 characters is necessary for the -; REM so 127 characters may be used before overwriting the ProDOS filename. -; As we don't want to put further restrictions on the command-line length -; we reserve those 127 characters terminated by a zero. +; there are 128 characters left. At least 1 character is necessary for the +; REM so 127 characters (including the terminating zero) may be used before +; overwriting the ProDOS filename. As we don't want to further restrict the +; command-line length we reserve those 127 characters. -BUF_LEN = 128 +BUF_LEN = 127 BASIC_BUF = $200 FNAM_LEN = $280 diff --git a/libsrc/apple2/targetutil/loader.s b/libsrc/apple2/targetutil/loader.s index 2872de1da..a6cc13cef 100644 --- a/libsrc/apple2/targetutil/loader.s +++ b/libsrc/apple2/targetutil/loader.s @@ -22,14 +22,14 @@ READ_CALL = $CA CLOSE_CALL = $CC FILE_NOT_FOUND_ERR = $46 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ------------------------------------------------------------------------ .import __CODE_0300_SIZE__, __DATA_0300_SIZE__ .import __CODE_0300_LOAD__, __CODE_0300_RUN__ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ------------------------------------------------------------------------ -.segment "DATA_2000" + .segment "DATA_2000" GET_FILE_INFO_PARAM: .byte $0A ;PARAM_COUNT @@ -57,9 +57,9 @@ LOADING: ELLIPSES: .byte " ...", $0D, $0D, $00 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ------------------------------------------------------------------------ -.segment "DATA_0300" + .segment "DATA_0300" READ_PARAM: .byte $04 ;PARAM_COUNT @@ -81,22 +81,22 @@ QUIT_PARAM: FILE_NOT_FOUND: .asciiz "... File Not Found" - + ERROR_NUMBER: .asciiz "... Error $" PRESS_ANY_KEY: .asciiz " - Press Any Key " -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ------------------------------------------------------------------------ -.segment "CODE_2000" + .segment "CODE_2000" jmp :+ .byte $EE .byte $EE - .byte $80 -STARTUP:.res $80 + .byte $7F +STARTUP:.res $7F ; Reset stack : ldx #$FF @@ -104,8 +104,8 @@ STARTUP:.res $80 ; Relocate CODE_0300 and DATA_0300 ldx #<(__CODE_0300_SIZE__ + __DATA_0300_SIZE__) -: lda __CODE_0300_LOAD__ - 1,x - sta __CODE_0300_RUN__ - 1,x +: lda __CODE_0300_LOAD__-1,x + sta __CODE_0300_RUN__-1,x dex bne :- @@ -118,13 +118,13 @@ STARTUP:.res $80 ; Add trailing '\0' to pathname tax lda #$00 - sta PATHNAME + 1,x + sta PATHNAME+1,x ; Copy ProDOS startup filename and trailing '\0' to stack ldx STARTUP lda #$00 - beq :++ ; bra -: lda STARTUP + 1,x + beq :++ ; Branch always +: lda STARTUP+1,x : sta STACK,x dex bpl :-- @@ -133,8 +133,8 @@ STARTUP:.res $80 lda #<LOADING ldx #>LOADING jsr PRINT - lda #<(PATHNAME + 1) - ldx #>(PATHNAME + 1) + lda #<(PATHNAME+1) + ldx #>(PATHNAME+1) jsr PRINT lda #<ELLIPSES ldx #>ELLIPSES @@ -159,16 +159,16 @@ STARTUP:.res $80 ; Get load address from aux-type lda FILE_INFO_ADDR - ldx FILE_INFO_ADDR + 1 + ldx FILE_INFO_ADDR+1 sta READ_ADDR - stx READ_ADDR + 1 + stx READ_ADDR+1 ; It's high time to leave this place jmp __CODE_0300_RUN__ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; ------------------------------------------------------------------------ -.segment "CODE_0300" + .segment "CODE_0300" jsr MLI .byte READ_CALL @@ -180,15 +180,15 @@ STARTUP:.res $80 .word CLOSE_PARAM bcs ERROR - ; Copy REM token and startup filename to BASIC input buffer + ; Copy REM and startup filename to BASIC input buffer ldx #$00 - lda #$B2 - bne :++ ; bra + lda #$B2 ; REM token + bne :++ ; Branch always : inx - lda a:STACK - 1,x + lda a:STACK-1,x : sta BUF,x bne :-- - + ; Go for it ... jmp (READ_ADDR) @@ -207,7 +207,7 @@ PRINT: : ora #$80 jsr COUT iny - bne :-- ; bra + bne :-- ; Branch always : rts ERROR: @@ -216,7 +216,7 @@ ERROR: lda #<FILE_NOT_FOUND ldx #>FILE_NOT_FOUND jsr PRINT - beq :++ ; bra + beq :++ ; Branch always : pha lda #<ERROR_NUMBER ldx #>ERROR_NUMBER @@ -230,5 +230,3 @@ ERROR: jsr MLI .byte QUIT_CALL .word QUIT_PARAM - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; From 1748bb1ab60f5b9c1e7e6885a972121fdb66d64a Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sun, 26 Apr 2015 14:08:46 +0200 Subject: [PATCH 137/351] Use well-known location BLTU2 for "memmove()". --- libsrc/apple2/crt0.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index 0f134202e..445039b1e 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -46,9 +46,9 @@ sta $94 sty $95 - ; Call into the Applesoft Block Transfer Utility -- which handles zero- + ; Call into Applesoft Block Transfer Up -- which handles zero- ; sized blocks well -- to move the content of the LC memory area. - jsr $D396 ; BLTU + 3 + jsr $D39A ; BLTU2 ; Set the source start address. lda #<__ZPSAVE_RUN__ @@ -68,9 +68,9 @@ sta $94 sty $95 - ; Call into the Applesoft Block Transfer Utility -- which handles moving + ; Call into Applesoft Block Transfer Up -- which handles moving ; overlapping blocks upwards well -- to move the INIT segment. - jsr $D396 ; BLTU + 3 + jsr $D39A ; BLTU2 ; Delegate all further processing, to keep the STARTUP segment small. jsr init From 0f1c3b01814993b3285cab4d19021e4e00410e70 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Mon, 27 Apr 2015 09:39:50 +0200 Subject: [PATCH 138/351] Fixed comment. --- libsrc/apple2/exec.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/apple2/exec.s b/libsrc/apple2/exec.s index f589bd41a..d24de604c 100644 --- a/libsrc/apple2/exec.s +++ b/libsrc/apple2/exec.s @@ -166,7 +166,7 @@ setbuf: lda #$00 ; Low byte bit $C080 .endif - ; Reset stack we already passed + ; Reset stack as we already passed ; the point of no return anyway ldx #$FF txs From 1e6629de8de5c4f7b03f9322a514992884cb8ce2 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Tue, 5 May 2015 13:46:26 +0200 Subject: [PATCH 139/351] Removed 'gh-pages'. The 'gh-pages' goal has been moved to another Makefile. This reference was just a leftover. --- doc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Makefile b/doc/Makefile index 02ed6b1d3..967443ef0 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -2,7 +2,7 @@ ifneq ($(shell echo),) CMD_EXE = 1 endif -.PHONY: all mostlyclean clean install zip doc html info gh-pages +.PHONY: all mostlyclean clean install zip doc html info .SUFFIXES: From aeb849257277a6b98542de8579697b81c6dd70e6 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Tue, 5 May 2015 21:56:23 +0200 Subject: [PATCH 140/351] Simplified license. In https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=714058#55 John Dunning writes on 4/May/2015: "Hi all. I gather that the preference is to license CC65 and associated technologies under the zlib license. I hereby give my approval for any software written by me as part of CC65 and associated technologies under the zlib license." The above together with the fact that all subsequent work on cc65 was already licensed under the zlib license means that cc65 can now be licensed altogether under the zlib license. --- LICENSE | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/LICENSE b/LICENSE index 03eefac67..88cacf148 100644 --- a/LICENSE +++ b/LICENSE @@ -1,44 +1,3 @@ -This is the original cc65 compiler copyright: - - -*- Mode: Text -*- - - This is the copyright notice for RA65, LINK65, LIBR65, and other - Atari 8-bit programs. Said programs are Copyright 1989, by John R. - Dunning. All rights reserved, with the following exceptions: - - Anyone may copy or redistribute these programs, provided that: - - 1: You don't charge anything for the copy. It is permissable to - charge a nominal fee for media, etc. - - 2: All source code and documentation for the programs is made - available as part of the distribution. - - 3: This copyright notice is preserved verbatim, and included in - the distribution. - - You are allowed to modify these programs, and redistribute the - modified versions, provided that the modifications are clearly noted. - - There is NO WARRANTY with this software, it comes as is, and is - distributed in the hope that it may be useful. - - This copyright notice applies to any program which contains - this text, or the refers to this file. - - This copyright notice is based on the one published by the Free - Software Foundation, sometimes known as the GNU project. The idea - is the same as theirs, ie the software is free, and is intended to - stay that way. Everybody has the right to copy, modify, and re- - distribute this software. Nobody has the right to prevent anyone - else from copying, modifying or redistributing it. - -In acknowledgment of this copyright, I (Ullrich von Bassewitz) will place -my own changes to the compiler under the same copyright. - -The library and the binary utils are a complete rewrite done by me and -covered by the following license: - This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. From 0bb3bafb3edaf9f86510e145b99352dd1801a042 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 12 May 2015 04:15:00 -0400 Subject: [PATCH 141/351] Made cc65 catch an assignment of a function pointer to a pointer with a different calling convention. --- src/cc65/typecmp.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/cc65/typecmp.c b/src/cc65/typecmp.c index 67941026b..b01cd3f51 100644 --- a/src/cc65/typecmp.c +++ b/src/cc65/typecmp.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2008 Ullrich von Bassewitz */ -/* Roemerstrasse 52 */ -/* D-70794 Filderstadt */ -/* EMail: uz@cc65.org */ +/* (C) 1998-2015, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -37,6 +37,7 @@ /* cc65 */ #include "funcdesc.h" +#include "global.h" #include "symtab.h" #include "typecmp.h" @@ -247,21 +248,21 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) } if (LeftQual != RightQual) { /* On the first indirection level, different qualifiers mean - ** that the types are still compatible. On the second level, - ** this is a (maybe minor) error, so we create a special - ** return code, since a qualifier is dropped from a pointer. - ** Starting from the next level, the types are incompatible - ** if the qualifiers differ. + ** that the types still are compatible. On the second level, + ** that is a (maybe minor) error. We create a special return code + ** if a qualifier is dropped from a pointer. But, different calling + ** conventions are incompatible. Starting from the next level, + ** the types are incompatible if the qualifiers differ. */ + /* (Debugging statement) */ /* printf ("Ind = %d %06X != %06X\n", Indirections, LeftQual, RightQual); */ switch (Indirections) { - case 0: SetResult (Result, TC_STRICT_COMPATIBLE); break; case 1: - /* A non const value on the right is compatible to a + /* A non-const value on the right is compatible to a ** const one to the left, same for volatile. */ if ((LeftQual & T_QUAL_CONST) < (RightQual & T_QUAL_CONST) || @@ -270,7 +271,27 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) } else { SetResult (Result, TC_STRICT_COMPATIBLE); } - break; + + /* If a calling convention wasn't set explicitly, + ** then assume the default one. + */ + LeftQual &= T_QUAL_CCONV; + if (LeftQual == 0) { + LeftQual = AutoCDecl ? T_QUAL_CDECL : T_QUAL_FASTCALL; + } + RightQual &= T_QUAL_CCONV; + if (RightQual == 0) { + RightQual = AutoCDecl ? T_QUAL_CDECL : T_QUAL_FASTCALL; + } + + /* (If the objects actually aren't pointers to functions, + ** then this test will pass anyway; and, more appropriate + ** tests will be performed.) + */ + if (LeftQual == RightQual) { + break; + } + /* else fall through */ default: SetResult (Result, TC_INCOMPATIBLE); @@ -280,7 +301,6 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) /* Check for special type elements */ switch (LeftType) { - case T_TYPE_PTR: ++Indirections; break; From 5ed3a1a6dc4da3bfab799883917426141888c3ac Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Tue, 12 May 2015 19:28:57 -0400 Subject: [PATCH 142/351] Added pseudo function .DEFINEDINSTR --- src/ca65/expr.c | 32 +++++ src/ca65/feature.c | 2 + src/ca65/feature.h | 1 + src/ca65/global.c | 1 + src/ca65/global.h | 1 + src/ca65/pseudo.c | 1 + src/ca65/scanner.c | 322 +++++++++++++++++++++++---------------------- src/ca65/token.h | 1 + 8 files changed, 204 insertions(+), 157 deletions(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 8b87d0860..969028f10 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -62,6 +62,7 @@ #include "symtab.h" #include "toklist.h" #include "ulabel.h" +#include "macro.h" @@ -417,6 +418,33 @@ static ExprNode* FuncDefined (void) +static ExprNode* FuncDefinedInstr (void) +/* Handle the .DEFINEDINSTR builtin function */ +{ + int Instr = 0; + + /* Check for a macro or an instruction depending on UbiquitousIdents */ + + if (CurTok.Tok == TOK_IDENT) { + if (UbiquitousIdents) { + /* Macros CAN be instructions, so check for them first */ + if (FindMacro(&CurTok.SVal) == 0) { + Instr = FindInstruction (&CurTok.SVal); + } + } else { + /* Macros and symbols may NOT use the names of instructions, so just check for the instruction */ + Instr = FindInstruction(&CurTok.SVal); + } + NextTok(); + } else { + Error("Idenitifier expected."); + } + + return GenLiteralExpr(Instr > 0); +} + + + ExprNode* FuncHiByte (void) /* Handle the .HIBYTE builtin function */ { @@ -1065,6 +1093,10 @@ static ExprNode* Factor (void) N = Function (FuncDefined); break; + case TOK_DEFINEDINSTR: + N = Function (FuncDefinedInstr); + break; + case TOK_HIBYTE: N = Function (FuncHiByte); break; diff --git a/src/ca65/feature.c b/src/ca65/feature.c index 3462d5501..2a29b5e8f 100644 --- a/src/ca65/feature.c +++ b/src/ca65/feature.c @@ -64,6 +64,7 @@ static const char* FeatureKeys[FEAT_COUNT] = { "force_range", "underline_in_numbers", "addrsize", + "definedinstr", }; @@ -121,6 +122,7 @@ feature_t SetFeature (const StrBuf* Key) case FEAT_FORCE_RANGE: ForceRange = 1; break; case FEAT_UNDERLINE_IN_NUMBERS: UnderlineInNumbers= 1; break; case FEAT_ADDRSIZE: AddrSize = 1; break; + case FEAT_DEFINEDINSTR: DefinedInstr = 1; break; default: /* Keep gcc silent */ break; } diff --git a/src/ca65/feature.h b/src/ca65/feature.h index 3a520a54a..d5d4d9d23 100644 --- a/src/ca65/feature.h +++ b/src/ca65/feature.h @@ -66,6 +66,7 @@ typedef enum { FEAT_FORCE_RANGE, FEAT_UNDERLINE_IN_NUMBERS, FEAT_ADDRSIZE, + FEAT_DEFINEDINSTR, /* Special value: Number of features available */ FEAT_COUNT diff --git a/src/ca65/global.c b/src/ca65/global.c index 77ed66e7f..a1f29bc38 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -83,3 +83,4 @@ unsigned char CComments = 0; /* Allow C like comments */ unsigned char ForceRange = 0; /* Force values into expected range */ unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */ unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */ +unsigned char DefinedInstr = 0; /* Allow .DEFINEDINSTR function */ diff --git a/src/ca65/global.h b/src/ca65/global.h index fb254f835..4939f8edf 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -85,6 +85,7 @@ extern unsigned char CComments; /* Allow C like comments */ extern unsigned char ForceRange; /* Force values into expected range */ extern unsigned char UnderlineInNumbers; /* Allow underlines in numbers */ extern unsigned char AddrSize; /* Allow .ADDRSIZE function */ +extern unsigned char DefinedInstr; /* Allow .DEFINEDINSTR function */ diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 2e8a473a5..d99bd29a4 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1989,6 +1989,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoDebugInfo }, { ccNone, DoDefine }, { ccNone, DoUnexpected }, /* .DEFINED */ + { ccNone, DoUnexpected }, /* .DEFINEDINSTR */ { ccNone, DoDelMac }, { ccNone, DoDestructor }, { ccNone, DoDWord }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index db747cf70..801790fa0 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -132,163 +132,164 @@ struct DotKeyword { const char* Key; /* MUST be first field */ token_t Tok; } DotKeywords [] = { - { ".A16", TOK_A16 }, - { ".A8", TOK_A8 }, - { ".ADDR", TOK_ADDR }, - { ".ADDRSIZE", TOK_ADDRSIZE }, - { ".ALIGN", TOK_ALIGN }, - { ".AND", TOK_BOOLAND }, - { ".ASCIIZ", TOK_ASCIIZ }, - { ".ASSERT", TOK_ASSERT }, - { ".AUTOIMPORT", TOK_AUTOIMPORT }, - { ".BANK", TOK_BANK }, - { ".BANKBYTE", TOK_BANKBYTE }, - { ".BANKBYTES", TOK_BANKBYTES }, - { ".BITAND", TOK_AND }, - { ".BITNOT", TOK_NOT }, - { ".BITOR", TOK_OR }, - { ".BITXOR", TOK_XOR }, - { ".BLANK", TOK_BLANK }, - { ".BSS", TOK_BSS }, - { ".BYT", TOK_BYTE }, - { ".BYTE", TOK_BYTE }, - { ".CASE", TOK_CASE }, - { ".CHARMAP", TOK_CHARMAP }, - { ".CODE", TOK_CODE }, - { ".CONCAT", TOK_CONCAT }, - { ".CONDES", TOK_CONDES }, - { ".CONST", TOK_CONST }, - { ".CONSTRUCTOR", TOK_CONSTRUCTOR }, - { ".CPU", TOK_CPU }, - { ".DATA", TOK_DATA }, - { ".DBG", TOK_DBG }, - { ".DBYT", TOK_DBYT }, - { ".DEBUGINFO", TOK_DEBUGINFO }, - { ".DEF", TOK_DEFINED }, - { ".DEFINE", TOK_DEFINE }, - { ".DEFINED", TOK_DEFINED }, - { ".DELMAC", TOK_DELMAC }, - { ".DELMACRO", TOK_DELMAC }, - { ".DESTRUCTOR", TOK_DESTRUCTOR }, - { ".DWORD", TOK_DWORD }, - { ".ELSE", TOK_ELSE }, - { ".ELSEIF", TOK_ELSEIF }, - { ".END", TOK_END }, - { ".ENDENUM", TOK_ENDENUM }, - { ".ENDIF", TOK_ENDIF }, - { ".ENDMAC", TOK_ENDMACRO }, - { ".ENDMACRO", TOK_ENDMACRO }, - { ".ENDPROC", TOK_ENDPROC }, - { ".ENDREP", TOK_ENDREP }, - { ".ENDREPEAT", TOK_ENDREP }, - { ".ENDSCOPE", TOK_ENDSCOPE }, - { ".ENDSTRUCT", TOK_ENDSTRUCT }, - { ".ENDUNION", TOK_ENDUNION }, - { ".ENUM", TOK_ENUM }, - { ".ERROR", TOK_ERROR }, - { ".EXITMAC", TOK_EXITMACRO }, - { ".EXITMACRO", TOK_EXITMACRO }, - { ".EXPORT", TOK_EXPORT }, - { ".EXPORTZP", TOK_EXPORTZP }, - { ".FARADDR", TOK_FARADDR }, - { ".FATAL", TOK_FATAL }, - { ".FEATURE", TOK_FEATURE }, - { ".FILEOPT", TOK_FILEOPT }, - { ".FOPT", TOK_FILEOPT }, - { ".FORCEIMPORT", TOK_FORCEIMPORT }, - { ".FORCEWORD", TOK_FORCEWORD }, - { ".GLOBAL", TOK_GLOBAL }, - { ".GLOBALZP", TOK_GLOBALZP }, - { ".HIBYTE", TOK_HIBYTE }, - { ".HIBYTES", TOK_HIBYTES }, - { ".HIWORD", TOK_HIWORD }, - { ".I16", TOK_I16 }, - { ".I8", TOK_I8 }, - { ".IDENT", TOK_MAKEIDENT }, - { ".IF", TOK_IF }, - { ".IFBLANK", TOK_IFBLANK }, - { ".IFCONST", TOK_IFCONST }, - { ".IFDEF", TOK_IFDEF }, - { ".IFNBLANK", TOK_IFNBLANK }, - { ".IFNCONST", TOK_IFNCONST }, - { ".IFNDEF", TOK_IFNDEF }, - { ".IFNREF", TOK_IFNREF }, - { ".IFP02", TOK_IFP02 }, - { ".IFP816", TOK_IFP816 }, - { ".IFPC02", TOK_IFPC02 }, - { ".IFPSC02", TOK_IFPSC02 }, - { ".IFREF", TOK_IFREF }, - { ".IMPORT", TOK_IMPORT }, - { ".IMPORTZP", TOK_IMPORTZP }, - { ".INCBIN", TOK_INCBIN }, - { ".INCLUDE", TOK_INCLUDE }, - { ".INTERRUPTOR", TOK_INTERRUPTOR }, - { ".LEFT", TOK_LEFT }, - { ".LINECONT", TOK_LINECONT }, - { ".LIST", TOK_LIST }, - { ".LISTBYTES", TOK_LISTBYTES }, - { ".LOBYTE", TOK_LOBYTE }, - { ".LOBYTES", TOK_LOBYTES }, - { ".LOCAL", TOK_LOCAL }, - { ".LOCALCHAR", TOK_LOCALCHAR }, - { ".LOWORD", TOK_LOWORD }, - { ".MAC", TOK_MACRO }, - { ".MACPACK", TOK_MACPACK }, - { ".MACRO", TOK_MACRO }, - { ".MATCH", TOK_MATCH }, - { ".MAX", TOK_MAX }, - { ".MID", TOK_MID }, - { ".MIN", TOK_MIN }, - { ".MOD", TOK_MOD }, - { ".NOT", TOK_BOOLNOT }, - { ".NULL", TOK_NULL }, - { ".OR", TOK_BOOLOR }, - { ".ORG", TOK_ORG }, - { ".OUT", TOK_OUT }, - { ".P02", TOK_P02 }, - { ".P816", TOK_P816 }, - { ".PAGELEN", TOK_PAGELENGTH }, - { ".PAGELENGTH", TOK_PAGELENGTH }, - { ".PARAMCOUNT", TOK_PARAMCOUNT }, - { ".PC02", TOK_PC02 }, - { ".POPCPU", TOK_POPCPU }, - { ".POPSEG", TOK_POPSEG }, - { ".PROC", TOK_PROC }, - { ".PSC02", TOK_PSC02 }, - { ".PUSHCPU", TOK_PUSHCPU }, - { ".PUSHSEG", TOK_PUSHSEG }, - { ".REF", TOK_REFERENCED }, - { ".REFERENCED", TOK_REFERENCED }, - { ".RELOC", TOK_RELOC }, - { ".REPEAT", TOK_REPEAT }, - { ".RES", TOK_RES }, - { ".RIGHT", TOK_RIGHT }, - { ".RODATA", TOK_RODATA }, - { ".SCOPE", TOK_SCOPE }, - { ".SEGMENT", TOK_SEGMENT }, - { ".SET", TOK_SET }, - { ".SETCPU", TOK_SETCPU }, - { ".SHL", TOK_SHL }, - { ".SHR", TOK_SHR }, - { ".SIZEOF", TOK_SIZEOF }, - { ".SMART", TOK_SMART }, - { ".SPRINTF", TOK_SPRINTF }, - { ".STRAT", TOK_STRAT }, - { ".STRING", TOK_STRING }, - { ".STRLEN", TOK_STRLEN }, - { ".STRUCT", TOK_STRUCT }, - { ".TAG", TOK_TAG }, - { ".TCOUNT", TOK_TCOUNT }, - { ".TIME", TOK_TIME }, - { ".UNDEF", TOK_UNDEF }, - { ".UNDEFINE", TOK_UNDEF }, - { ".UNION", TOK_UNION }, - { ".VERSION", TOK_VERSION }, - { ".WARNING", TOK_WARNING }, - { ".WORD", TOK_WORD }, - { ".XMATCH", TOK_XMATCH }, - { ".XOR", TOK_BOOLXOR }, - { ".ZEROPAGE", TOK_ZEROPAGE }, + { ".A16", TOK_A16 }, + { ".A8", TOK_A8 }, + { ".ADDR", TOK_ADDR }, + { ".ADDRSIZE", TOK_ADDRSIZE }, + { ".ALIGN", TOK_ALIGN }, + { ".AND", TOK_BOOLAND }, + { ".ASCIIZ", TOK_ASCIIZ }, + { ".ASSERT", TOK_ASSERT }, + { ".AUTOIMPORT", TOK_AUTOIMPORT }, + { ".BANK", TOK_BANK }, + { ".BANKBYTE", TOK_BANKBYTE }, + { ".BANKBYTES", TOK_BANKBYTES }, + { ".BITAND", TOK_AND }, + { ".BITNOT", TOK_NOT }, + { ".BITOR", TOK_OR }, + { ".BITXOR", TOK_XOR }, + { ".BLANK", TOK_BLANK }, + { ".BSS", TOK_BSS }, + { ".BYT", TOK_BYTE }, + { ".BYTE", TOK_BYTE }, + { ".CASE", TOK_CASE }, + { ".CHARMAP", TOK_CHARMAP }, + { ".CODE", TOK_CODE }, + { ".CONCAT", TOK_CONCAT }, + { ".CONDES", TOK_CONDES }, + { ".CONST", TOK_CONST }, + { ".CONSTRUCTOR", TOK_CONSTRUCTOR }, + { ".CPU", TOK_CPU }, + { ".DATA", TOK_DATA }, + { ".DBG", TOK_DBG }, + { ".DBYT", TOK_DBYT }, + { ".DEBUGINFO", TOK_DEBUGINFO }, + { ".DEF", TOK_DEFINED }, + { ".DEFINE", TOK_DEFINE }, + { ".DEFINED", TOK_DEFINED }, + { ".DEFINEDINSTR", TOK_DEFINEDINSTR }, + { ".DELMAC", TOK_DELMAC }, + { ".DELMACRO", TOK_DELMAC }, + { ".DESTRUCTOR", TOK_DESTRUCTOR }, + { ".DWORD", TOK_DWORD }, + { ".ELSE", TOK_ELSE }, + { ".ELSEIF", TOK_ELSEIF }, + { ".END", TOK_END }, + { ".ENDENUM", TOK_ENDENUM }, + { ".ENDIF", TOK_ENDIF }, + { ".ENDMAC", TOK_ENDMACRO }, + { ".ENDMACRO", TOK_ENDMACRO }, + { ".ENDPROC", TOK_ENDPROC }, + { ".ENDREP", TOK_ENDREP }, + { ".ENDREPEAT", TOK_ENDREP }, + { ".ENDSCOPE", TOK_ENDSCOPE }, + { ".ENDSTRUCT", TOK_ENDSTRUCT }, + { ".ENDUNION", TOK_ENDUNION }, + { ".ENUM", TOK_ENUM }, + { ".ERROR", TOK_ERROR }, + { ".EXITMAC", TOK_EXITMACRO }, + { ".EXITMACRO", TOK_EXITMACRO }, + { ".EXPORT", TOK_EXPORT }, + { ".EXPORTZP", TOK_EXPORTZP }, + { ".FARADDR", TOK_FARADDR }, + { ".FATAL", TOK_FATAL }, + { ".FEATURE", TOK_FEATURE }, + { ".FILEOPT", TOK_FILEOPT }, + { ".FOPT", TOK_FILEOPT }, + { ".FORCEIMPORT", TOK_FORCEIMPORT }, + { ".FORCEWORD", TOK_FORCEWORD }, + { ".GLOBAL", TOK_GLOBAL }, + { ".GLOBALZP", TOK_GLOBALZP }, + { ".HIBYTE", TOK_HIBYTE }, + { ".HIBYTES", TOK_HIBYTES }, + { ".HIWORD", TOK_HIWORD }, + { ".I16", TOK_I16 }, + { ".I8", TOK_I8 }, + { ".IDENT", TOK_MAKEIDENT }, + { ".IF", TOK_IF }, + { ".IFBLANK", TOK_IFBLANK }, + { ".IFCONST", TOK_IFCONST }, + { ".IFDEF", TOK_IFDEF }, + { ".IFNBLANK", TOK_IFNBLANK }, + { ".IFNCONST", TOK_IFNCONST }, + { ".IFNDEF", TOK_IFNDEF }, + { ".IFNREF", TOK_IFNREF }, + { ".IFP02", TOK_IFP02 }, + { ".IFP816", TOK_IFP816 }, + { ".IFPC02", TOK_IFPC02 }, + { ".IFPSC02", TOK_IFPSC02 }, + { ".IFREF", TOK_IFREF }, + { ".IMPORT", TOK_IMPORT }, + { ".IMPORTZP", TOK_IMPORTZP }, + { ".INCBIN", TOK_INCBIN }, + { ".INCLUDE", TOK_INCLUDE }, + { ".INTERRUPTOR", TOK_INTERRUPTOR }, + { ".LEFT", TOK_LEFT }, + { ".LINECONT", TOK_LINECONT }, + { ".LIST", TOK_LIST }, + { ".LISTBYTES", TOK_LISTBYTES }, + { ".LOBYTE", TOK_LOBYTE }, + { ".LOBYTES", TOK_LOBYTES }, + { ".LOCAL", TOK_LOCAL }, + { ".LOCALCHAR", TOK_LOCALCHAR }, + { ".LOWORD", TOK_LOWORD }, + { ".MAC", TOK_MACRO }, + { ".MACPACK", TOK_MACPACK }, + { ".MACRO", TOK_MACRO }, + { ".MATCH", TOK_MATCH }, + { ".MAX", TOK_MAX }, + { ".MID", TOK_MID }, + { ".MIN", TOK_MIN }, + { ".MOD", TOK_MOD }, + { ".NOT", TOK_BOOLNOT }, + { ".NULL", TOK_NULL }, + { ".OR", TOK_BOOLOR }, + { ".ORG", TOK_ORG }, + { ".OUT", TOK_OUT }, + { ".P02", TOK_P02 }, + { ".P816", TOK_P816 }, + { ".PAGELEN", TOK_PAGELENGTH }, + { ".PAGELENGTH", TOK_PAGELENGTH }, + { ".PARAMCOUNT", TOK_PARAMCOUNT }, + { ".PC02", TOK_PC02 }, + { ".POPCPU", TOK_POPCPU }, + { ".POPSEG", TOK_POPSEG }, + { ".PROC", TOK_PROC }, + { ".PSC02", TOK_PSC02 }, + { ".PUSHCPU", TOK_PUSHCPU }, + { ".PUSHSEG", TOK_PUSHSEG }, + { ".REF", TOK_REFERENCED }, + { ".REFERENCED", TOK_REFERENCED }, + { ".RELOC", TOK_RELOC }, + { ".REPEAT", TOK_REPEAT }, + { ".RES", TOK_RES }, + { ".RIGHT", TOK_RIGHT }, + { ".RODATA", TOK_RODATA }, + { ".SCOPE", TOK_SCOPE }, + { ".SEGMENT", TOK_SEGMENT }, + { ".SET", TOK_SET }, + { ".SETCPU", TOK_SETCPU }, + { ".SHL", TOK_SHL }, + { ".SHR", TOK_SHR }, + { ".SIZEOF", TOK_SIZEOF }, + { ".SMART", TOK_SMART }, + { ".SPRINTF", TOK_SPRINTF }, + { ".STRAT", TOK_STRAT }, + { ".STRING", TOK_STRING }, + { ".STRLEN", TOK_STRLEN }, + { ".STRUCT", TOK_STRUCT }, + { ".TAG", TOK_TAG }, + { ".TCOUNT", TOK_TCOUNT }, + { ".TIME", TOK_TIME }, + { ".UNDEF", TOK_UNDEF }, + { ".UNDEFINE", TOK_UNDEF }, + { ".UNION", TOK_UNION }, + { ".VERSION", TOK_VERSION }, + { ".WARNING", TOK_WARNING }, + { ".WORD", TOK_WORD }, + { ".XMATCH", TOK_XMATCH }, + { ".XOR", TOK_BOOLXOR }, + { ".ZEROPAGE", TOK_ZEROPAGE }, }; @@ -736,6 +737,13 @@ static token_t FindDotKeyword (void) } break; + case TOK_DEFINEDINSTR: + /* Disallow .DEFINEDINSTR function by default */ + if (DefinedInstr == 0) { + return TOK_NONE; + } + break; + default: break; } diff --git a/src/ca65/token.h b/src/ca65/token.h index 7aaba34c3..102fde806 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -148,6 +148,7 @@ typedef enum token_t { TOK_DEBUGINFO, TOK_DEFINE, TOK_DEFINED, + TOK_DEFINEDINSTR, TOK_DELMAC, TOK_DESTRUCTOR, TOK_DWORD, From 893af97ccd47fdbe0a2b8f2e6a05d9efd07fe391 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Wed, 13 May 2015 14:54:12 +0200 Subject: [PATCH 143/351] Fixed isblank() availability atttribute. --- doc/funcref.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/funcref.sgml b/doc/funcref.sgml index 9c60483aa..ebe63be45 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -3309,7 +3309,7 @@ macro. <item>When compiling without <tt/-Os/, the function is only available as fastcall function, so it may only be used in presence of a prototype. </itemize> -<tag/Availability/cc65 +<tag/Availability/ISO 9899 <tag/See also/ <ref id="isalnum" name="isalnum">, <ref id="isalpha" name="isalpha">, From 41d19074e745234ccc0837ec0a2ae812c613d682 Mon Sep 17 00:00:00 2001 From: Christian Groessler <chris@groessler.org> Date: Sat, 16 May 2015 05:20:15 +0200 Subject: [PATCH 144/351] Fix verbose symbol dumping in ca65. --- src/ca65/symtab.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ca65/symtab.c b/src/ca65/symtab.c index 7e21dd309..35d5a8066 100644 --- a/src/ca65/symtab.c +++ b/src/ca65/symtab.c @@ -696,10 +696,10 @@ void SymDump (FILE* F) while (S) { /* Ignore unused symbols */ - if ((S->Flags & SF_UNUSED) != 0) { + if ((S->Flags & SF_UNUSED) == 0) { fprintf (F, - "%m%-24p %s %s %s %s %s\n", - GetSymName (S), + "%-24s %s %s %s %s %s\n", + SB_GetConstBuf (GetSymName (S)), (S->Flags & SF_DEFINED)? "DEF" : "---", (S->Flags & SF_REFERENCED)? "REF" : "---", (S->Flags & SF_IMPORT)? "IMP" : "---", From 9ee5adc190668a5b0657114c46ff7ed277447fd5 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Tue, 19 May 2015 00:06:12 -0400 Subject: [PATCH 145/351] Remove .FEATURE requirement and add documentation --- doc/ca65.sgml | 18 ++++++++++++++++++ src/ca65/expr.c | 13 +++++++------ src/ca65/feature.c | 2 -- src/ca65/feature.h | 1 - src/ca65/global.c | 1 - src/ca65/global.h | 1 - src/ca65/scanner.c | 7 ------- 7 files changed, 25 insertions(+), 18 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 03aa72097..52dcccc6b 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -2316,6 +2316,24 @@ Here's a list of all control commands and a description, what they do: </verb></tscreen> +<sect1><tt>.DEFINEDINSTR</tt><label id=".DEFINEDINSTR"><p> + + Builtin function. The function expects an identifier as argument in braces. + The argument is evaluated, and the function yields "true" if the identifier + is defined as an instruction mnemonic that is recognized by the assembler. + Example: + + <tscreen><verb> + .if .not .definedinstr(ina) + .macro ina + clc + adc #$01 + .endmacro + .endif + + </verb></tscreen> + + <sect1><tt>.DESTRUCTOR</tt><label id=".DESTRUCTOR"><p> Export a symbol and mark it as a module destructor. This may be used diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 969028f10..9bccc62f2 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -421,26 +421,27 @@ static ExprNode* FuncDefined (void) static ExprNode* FuncDefinedInstr (void) /* Handle the .DEFINEDINSTR builtin function */ { - int Instr = 0; + int Instr = 0; /* Check for a macro or an instruction depending on UbiquitousIdents */ if (CurTok.Tok == TOK_IDENT) { if (UbiquitousIdents) { /* Macros CAN be instructions, so check for them first */ - if (FindMacro(&CurTok.SVal) == 0) { + if (FindMacro (&CurTok.SVal) == 0) { Instr = FindInstruction (&CurTok.SVal); } } else { /* Macros and symbols may NOT use the names of instructions, so just check for the instruction */ - Instr = FindInstruction(&CurTok.SVal); + Instr = FindInstruction (&CurTok.SVal); } - NextTok(); } else { - Error("Idenitifier expected."); + Error ("Idenitifier expected."); } + /* Skip the name */ + NextTok (); - return GenLiteralExpr(Instr > 0); + return GenLiteralExpr (Instr > 0); } diff --git a/src/ca65/feature.c b/src/ca65/feature.c index 2a29b5e8f..3462d5501 100644 --- a/src/ca65/feature.c +++ b/src/ca65/feature.c @@ -64,7 +64,6 @@ static const char* FeatureKeys[FEAT_COUNT] = { "force_range", "underline_in_numbers", "addrsize", - "definedinstr", }; @@ -122,7 +121,6 @@ feature_t SetFeature (const StrBuf* Key) case FEAT_FORCE_RANGE: ForceRange = 1; break; case FEAT_UNDERLINE_IN_NUMBERS: UnderlineInNumbers= 1; break; case FEAT_ADDRSIZE: AddrSize = 1; break; - case FEAT_DEFINEDINSTR: DefinedInstr = 1; break; default: /* Keep gcc silent */ break; } diff --git a/src/ca65/feature.h b/src/ca65/feature.h index d5d4d9d23..3a520a54a 100644 --- a/src/ca65/feature.h +++ b/src/ca65/feature.h @@ -66,7 +66,6 @@ typedef enum { FEAT_FORCE_RANGE, FEAT_UNDERLINE_IN_NUMBERS, FEAT_ADDRSIZE, - FEAT_DEFINEDINSTR, /* Special value: Number of features available */ FEAT_COUNT diff --git a/src/ca65/global.c b/src/ca65/global.c index a1f29bc38..77ed66e7f 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -83,4 +83,3 @@ unsigned char CComments = 0; /* Allow C like comments */ unsigned char ForceRange = 0; /* Force values into expected range */ unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */ unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */ -unsigned char DefinedInstr = 0; /* Allow .DEFINEDINSTR function */ diff --git a/src/ca65/global.h b/src/ca65/global.h index 4939f8edf..fb254f835 100644 --- a/src/ca65/global.h +++ b/src/ca65/global.h @@ -85,7 +85,6 @@ extern unsigned char CComments; /* Allow C like comments */ extern unsigned char ForceRange; /* Force values into expected range */ extern unsigned char UnderlineInNumbers; /* Allow underlines in numbers */ extern unsigned char AddrSize; /* Allow .ADDRSIZE function */ -extern unsigned char DefinedInstr; /* Allow .DEFINEDINSTR function */ diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 801790fa0..4d7927c1c 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -737,13 +737,6 @@ static token_t FindDotKeyword (void) } break; - case TOK_DEFINEDINSTR: - /* Disallow .DEFINEDINSTR function by default */ - if (DefinedInstr == 0) { - return TOK_NONE; - } - break; - default: break; } From 1e3234f370bf88a4471e8978a8ba4c489619c748 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Tue, 19 May 2015 19:50:51 -0400 Subject: [PATCH 146/351] changed name of function to .ISMNEMONIC, small fixes --- src/ca65/expr.c | 12 +- src/ca65/scanner.c | 317 +++++++++++++++++++++++---------------------- src/ca65/token.h | 2 +- 3 files changed, 166 insertions(+), 165 deletions(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 9bccc62f2..c4da32824 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -418,10 +418,10 @@ static ExprNode* FuncDefined (void) -static ExprNode* FuncDefinedInstr (void) -/* Handle the .DEFINEDINSTR builtin function */ +static ExprNode* FuncIsMnemonic (void) +/* Handle the .ISMNEMONIC, .ISMNEM builtin function */ { - int Instr = 0; + int Instr = -1; /* Check for a macro or an instruction depending on UbiquitousIdents */ @@ -436,7 +436,7 @@ static ExprNode* FuncDefinedInstr (void) Instr = FindInstruction (&CurTok.SVal); } } else { - Error ("Idenitifier expected."); + Error ("Identifier expected."); } /* Skip the name */ NextTok (); @@ -1094,8 +1094,8 @@ static ExprNode* Factor (void) N = Function (FuncDefined); break; - case TOK_DEFINEDINSTR: - N = Function (FuncDefinedInstr); + case TOK_ISMNEMONIC: + N = Function (FuncIsMnemonic); break; case TOK_HIBYTE: diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 4d7927c1c..30494b365 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -132,164 +132,165 @@ struct DotKeyword { const char* Key; /* MUST be first field */ token_t Tok; } DotKeywords [] = { - { ".A16", TOK_A16 }, - { ".A8", TOK_A8 }, - { ".ADDR", TOK_ADDR }, - { ".ADDRSIZE", TOK_ADDRSIZE }, - { ".ALIGN", TOK_ALIGN }, - { ".AND", TOK_BOOLAND }, - { ".ASCIIZ", TOK_ASCIIZ }, - { ".ASSERT", TOK_ASSERT }, - { ".AUTOIMPORT", TOK_AUTOIMPORT }, - { ".BANK", TOK_BANK }, - { ".BANKBYTE", TOK_BANKBYTE }, - { ".BANKBYTES", TOK_BANKBYTES }, - { ".BITAND", TOK_AND }, - { ".BITNOT", TOK_NOT }, - { ".BITOR", TOK_OR }, - { ".BITXOR", TOK_XOR }, - { ".BLANK", TOK_BLANK }, - { ".BSS", TOK_BSS }, - { ".BYT", TOK_BYTE }, - { ".BYTE", TOK_BYTE }, - { ".CASE", TOK_CASE }, - { ".CHARMAP", TOK_CHARMAP }, - { ".CODE", TOK_CODE }, - { ".CONCAT", TOK_CONCAT }, - { ".CONDES", TOK_CONDES }, - { ".CONST", TOK_CONST }, - { ".CONSTRUCTOR", TOK_CONSTRUCTOR }, - { ".CPU", TOK_CPU }, - { ".DATA", TOK_DATA }, - { ".DBG", TOK_DBG }, - { ".DBYT", TOK_DBYT }, - { ".DEBUGINFO", TOK_DEBUGINFO }, - { ".DEF", TOK_DEFINED }, - { ".DEFINE", TOK_DEFINE }, - { ".DEFINED", TOK_DEFINED }, - { ".DEFINEDINSTR", TOK_DEFINEDINSTR }, - { ".DELMAC", TOK_DELMAC }, - { ".DELMACRO", TOK_DELMAC }, - { ".DESTRUCTOR", TOK_DESTRUCTOR }, - { ".DWORD", TOK_DWORD }, - { ".ELSE", TOK_ELSE }, - { ".ELSEIF", TOK_ELSEIF }, - { ".END", TOK_END }, - { ".ENDENUM", TOK_ENDENUM }, - { ".ENDIF", TOK_ENDIF }, - { ".ENDMAC", TOK_ENDMACRO }, - { ".ENDMACRO", TOK_ENDMACRO }, - { ".ENDPROC", TOK_ENDPROC }, - { ".ENDREP", TOK_ENDREP }, - { ".ENDREPEAT", TOK_ENDREP }, - { ".ENDSCOPE", TOK_ENDSCOPE }, - { ".ENDSTRUCT", TOK_ENDSTRUCT }, - { ".ENDUNION", TOK_ENDUNION }, - { ".ENUM", TOK_ENUM }, - { ".ERROR", TOK_ERROR }, - { ".EXITMAC", TOK_EXITMACRO }, - { ".EXITMACRO", TOK_EXITMACRO }, - { ".EXPORT", TOK_EXPORT }, - { ".EXPORTZP", TOK_EXPORTZP }, - { ".FARADDR", TOK_FARADDR }, - { ".FATAL", TOK_FATAL }, - { ".FEATURE", TOK_FEATURE }, - { ".FILEOPT", TOK_FILEOPT }, - { ".FOPT", TOK_FILEOPT }, - { ".FORCEIMPORT", TOK_FORCEIMPORT }, - { ".FORCEWORD", TOK_FORCEWORD }, - { ".GLOBAL", TOK_GLOBAL }, - { ".GLOBALZP", TOK_GLOBALZP }, - { ".HIBYTE", TOK_HIBYTE }, - { ".HIBYTES", TOK_HIBYTES }, - { ".HIWORD", TOK_HIWORD }, - { ".I16", TOK_I16 }, - { ".I8", TOK_I8 }, - { ".IDENT", TOK_MAKEIDENT }, - { ".IF", TOK_IF }, - { ".IFBLANK", TOK_IFBLANK }, - { ".IFCONST", TOK_IFCONST }, - { ".IFDEF", TOK_IFDEF }, - { ".IFNBLANK", TOK_IFNBLANK }, - { ".IFNCONST", TOK_IFNCONST }, - { ".IFNDEF", TOK_IFNDEF }, - { ".IFNREF", TOK_IFNREF }, - { ".IFP02", TOK_IFP02 }, - { ".IFP816", TOK_IFP816 }, - { ".IFPC02", TOK_IFPC02 }, - { ".IFPSC02", TOK_IFPSC02 }, - { ".IFREF", TOK_IFREF }, - { ".IMPORT", TOK_IMPORT }, - { ".IMPORTZP", TOK_IMPORTZP }, - { ".INCBIN", TOK_INCBIN }, - { ".INCLUDE", TOK_INCLUDE }, - { ".INTERRUPTOR", TOK_INTERRUPTOR }, - { ".LEFT", TOK_LEFT }, - { ".LINECONT", TOK_LINECONT }, - { ".LIST", TOK_LIST }, - { ".LISTBYTES", TOK_LISTBYTES }, - { ".LOBYTE", TOK_LOBYTE }, - { ".LOBYTES", TOK_LOBYTES }, - { ".LOCAL", TOK_LOCAL }, - { ".LOCALCHAR", TOK_LOCALCHAR }, - { ".LOWORD", TOK_LOWORD }, - { ".MAC", TOK_MACRO }, - { ".MACPACK", TOK_MACPACK }, - { ".MACRO", TOK_MACRO }, - { ".MATCH", TOK_MATCH }, - { ".MAX", TOK_MAX }, - { ".MID", TOK_MID }, - { ".MIN", TOK_MIN }, - { ".MOD", TOK_MOD }, - { ".NOT", TOK_BOOLNOT }, - { ".NULL", TOK_NULL }, - { ".OR", TOK_BOOLOR }, - { ".ORG", TOK_ORG }, - { ".OUT", TOK_OUT }, - { ".P02", TOK_P02 }, - { ".P816", TOK_P816 }, - { ".PAGELEN", TOK_PAGELENGTH }, - { ".PAGELENGTH", TOK_PAGELENGTH }, - { ".PARAMCOUNT", TOK_PARAMCOUNT }, - { ".PC02", TOK_PC02 }, - { ".POPCPU", TOK_POPCPU }, - { ".POPSEG", TOK_POPSEG }, - { ".PROC", TOK_PROC }, - { ".PSC02", TOK_PSC02 }, - { ".PUSHCPU", TOK_PUSHCPU }, - { ".PUSHSEG", TOK_PUSHSEG }, - { ".REF", TOK_REFERENCED }, - { ".REFERENCED", TOK_REFERENCED }, - { ".RELOC", TOK_RELOC }, - { ".REPEAT", TOK_REPEAT }, - { ".RES", TOK_RES }, - { ".RIGHT", TOK_RIGHT }, - { ".RODATA", TOK_RODATA }, - { ".SCOPE", TOK_SCOPE }, - { ".SEGMENT", TOK_SEGMENT }, - { ".SET", TOK_SET }, - { ".SETCPU", TOK_SETCPU }, - { ".SHL", TOK_SHL }, - { ".SHR", TOK_SHR }, - { ".SIZEOF", TOK_SIZEOF }, - { ".SMART", TOK_SMART }, - { ".SPRINTF", TOK_SPRINTF }, - { ".STRAT", TOK_STRAT }, - { ".STRING", TOK_STRING }, - { ".STRLEN", TOK_STRLEN }, - { ".STRUCT", TOK_STRUCT }, - { ".TAG", TOK_TAG }, - { ".TCOUNT", TOK_TCOUNT }, - { ".TIME", TOK_TIME }, - { ".UNDEF", TOK_UNDEF }, - { ".UNDEFINE", TOK_UNDEF }, - { ".UNION", TOK_UNION }, - { ".VERSION", TOK_VERSION }, - { ".WARNING", TOK_WARNING }, - { ".WORD", TOK_WORD }, - { ".XMATCH", TOK_XMATCH }, - { ".XOR", TOK_BOOLXOR }, - { ".ZEROPAGE", TOK_ZEROPAGE }, + { ".A16", TOK_A16 }, + { ".A8", TOK_A8 }, + { ".ADDR", TOK_ADDR }, + { ".ADDRSIZE", TOK_ADDRSIZE }, + { ".ALIGN", TOK_ALIGN }, + { ".AND", TOK_BOOLAND }, + { ".ASCIIZ", TOK_ASCIIZ }, + { ".ASSERT", TOK_ASSERT }, + { ".AUTOIMPORT", TOK_AUTOIMPORT }, + { ".BANK", TOK_BANK }, + { ".BANKBYTE", TOK_BANKBYTE }, + { ".BANKBYTES", TOK_BANKBYTES }, + { ".BITAND", TOK_AND }, + { ".BITNOT", TOK_NOT }, + { ".BITOR", TOK_OR }, + { ".BITXOR", TOK_XOR }, + { ".BLANK", TOK_BLANK }, + { ".BSS", TOK_BSS }, + { ".BYT", TOK_BYTE }, + { ".BYTE", TOK_BYTE }, + { ".CASE", TOK_CASE }, + { ".CHARMAP", TOK_CHARMAP }, + { ".CODE", TOK_CODE }, + { ".CONCAT", TOK_CONCAT }, + { ".CONDES", TOK_CONDES }, + { ".CONST", TOK_CONST }, + { ".CONSTRUCTOR", TOK_CONSTRUCTOR }, + { ".CPU", TOK_CPU }, + { ".DATA", TOK_DATA }, + { ".DBG", TOK_DBG }, + { ".DBYT", TOK_DBYT }, + { ".DEBUGINFO", TOK_DEBUGINFO }, + { ".DEF", TOK_DEFINED }, + { ".DEFINE", TOK_DEFINE }, + { ".DEFINED", TOK_DEFINED }, + { ".DELMAC", TOK_DELMAC }, + { ".DELMACRO", TOK_DELMAC }, + { ".DESTRUCTOR", TOK_DESTRUCTOR }, + { ".DWORD", TOK_DWORD }, + { ".ELSE", TOK_ELSE }, + { ".ELSEIF", TOK_ELSEIF }, + { ".END", TOK_END }, + { ".ENDENUM", TOK_ENDENUM }, + { ".ENDIF", TOK_ENDIF }, + { ".ENDMAC", TOK_ENDMACRO }, + { ".ENDMACRO", TOK_ENDMACRO }, + { ".ENDPROC", TOK_ENDPROC }, + { ".ENDREP", TOK_ENDREP }, + { ".ENDREPEAT", TOK_ENDREP }, + { ".ENDSCOPE", TOK_ENDSCOPE }, + { ".ENDSTRUCT", TOK_ENDSTRUCT }, + { ".ENDUNION", TOK_ENDUNION }, + { ".ENUM", TOK_ENUM }, + { ".ERROR", TOK_ERROR }, + { ".EXITMAC", TOK_EXITMACRO }, + { ".EXITMACRO", TOK_EXITMACRO }, + { ".EXPORT", TOK_EXPORT }, + { ".EXPORTZP", TOK_EXPORTZP }, + { ".FARADDR", TOK_FARADDR }, + { ".FATAL", TOK_FATAL }, + { ".FEATURE", TOK_FEATURE }, + { ".FILEOPT", TOK_FILEOPT }, + { ".FOPT", TOK_FILEOPT }, + { ".FORCEIMPORT", TOK_FORCEIMPORT }, + { ".FORCEWORD", TOK_FORCEWORD }, + { ".GLOBAL", TOK_GLOBAL }, + { ".GLOBALZP", TOK_GLOBALZP }, + { ".HIBYTE", TOK_HIBYTE }, + { ".HIBYTES", TOK_HIBYTES }, + { ".HIWORD", TOK_HIWORD }, + { ".I16", TOK_I16 }, + { ".I8", TOK_I8 }, + { ".IDENT", TOK_MAKEIDENT }, + { ".IF", TOK_IF }, + { ".IFBLANK", TOK_IFBLANK }, + { ".IFCONST", TOK_IFCONST }, + { ".IFDEF", TOK_IFDEF }, + { ".IFNBLANK", TOK_IFNBLANK }, + { ".IFNCONST", TOK_IFNCONST }, + { ".IFNDEF", TOK_IFNDEF }, + { ".IFNREF", TOK_IFNREF }, + { ".IFP02", TOK_IFP02 }, + { ".IFP816", TOK_IFP816 }, + { ".IFPC02", TOK_IFPC02 }, + { ".IFPSC02", TOK_IFPSC02 }, + { ".IFREF", TOK_IFREF }, + { ".IMPORT", TOK_IMPORT }, + { ".IMPORTZP", TOK_IMPORTZP }, + { ".INCBIN", TOK_INCBIN }, + { ".INCLUDE", TOK_INCLUDE }, + { ".INTERRUPTOR", TOK_INTERRUPTOR }, + { ".ISMNEM", TOK_ISMNEMONIC }, + { ".ISMNEMONIC", TOK_ISMNEMONIC }, + { ".LEFT", TOK_LEFT }, + { ".LINECONT", TOK_LINECONT }, + { ".LIST", TOK_LIST }, + { ".LISTBYTES", TOK_LISTBYTES }, + { ".LOBYTE", TOK_LOBYTE }, + { ".LOBYTES", TOK_LOBYTES }, + { ".LOCAL", TOK_LOCAL }, + { ".LOCALCHAR", TOK_LOCALCHAR }, + { ".LOWORD", TOK_LOWORD }, + { ".MAC", TOK_MACRO }, + { ".MACPACK", TOK_MACPACK }, + { ".MACRO", TOK_MACRO }, + { ".MATCH", TOK_MATCH }, + { ".MAX", TOK_MAX }, + { ".MID", TOK_MID }, + { ".MIN", TOK_MIN }, + { ".MOD", TOK_MOD }, + { ".NOT", TOK_BOOLNOT }, + { ".NULL", TOK_NULL }, + { ".OR", TOK_BOOLOR }, + { ".ORG", TOK_ORG }, + { ".OUT", TOK_OUT }, + { ".P02", TOK_P02 }, + { ".P816", TOK_P816 }, + { ".PAGELEN", TOK_PAGELENGTH }, + { ".PAGELENGTH", TOK_PAGELENGTH }, + { ".PARAMCOUNT", TOK_PARAMCOUNT }, + { ".PC02", TOK_PC02 }, + { ".POPCPU", TOK_POPCPU }, + { ".POPSEG", TOK_POPSEG }, + { ".PROC", TOK_PROC }, + { ".PSC02", TOK_PSC02 }, + { ".PUSHCPU", TOK_PUSHCPU }, + { ".PUSHSEG", TOK_PUSHSEG }, + { ".REF", TOK_REFERENCED }, + { ".REFERENCED", TOK_REFERENCED }, + { ".RELOC", TOK_RELOC }, + { ".REPEAT", TOK_REPEAT }, + { ".RES", TOK_RES }, + { ".RIGHT", TOK_RIGHT }, + { ".RODATA", TOK_RODATA }, + { ".SCOPE", TOK_SCOPE }, + { ".SEGMENT", TOK_SEGMENT }, + { ".SET", TOK_SET }, + { ".SETCPU", TOK_SETCPU }, + { ".SHL", TOK_SHL }, + { ".SHR", TOK_SHR }, + { ".SIZEOF", TOK_SIZEOF }, + { ".SMART", TOK_SMART }, + { ".SPRINTF", TOK_SPRINTF }, + { ".STRAT", TOK_STRAT }, + { ".STRING", TOK_STRING }, + { ".STRLEN", TOK_STRLEN }, + { ".STRUCT", TOK_STRUCT }, + { ".TAG", TOK_TAG }, + { ".TCOUNT", TOK_TCOUNT }, + { ".TIME", TOK_TIME }, + { ".UNDEF", TOK_UNDEF }, + { ".UNDEFINE", TOK_UNDEF }, + { ".UNION", TOK_UNION }, + { ".VERSION", TOK_VERSION }, + { ".WARNING", TOK_WARNING }, + { ".WORD", TOK_WORD }, + { ".XMATCH", TOK_XMATCH }, + { ".XOR", TOK_BOOLXOR }, + { ".ZEROPAGE", TOK_ZEROPAGE }, }; diff --git a/src/ca65/token.h b/src/ca65/token.h index 102fde806..5ffe42466 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -148,7 +148,6 @@ typedef enum token_t { TOK_DEBUGINFO, TOK_DEFINE, TOK_DEFINED, - TOK_DEFINEDINSTR, TOK_DELMAC, TOK_DESTRUCTOR, TOK_DWORD, @@ -200,6 +199,7 @@ typedef enum token_t { TOK_INCBIN, TOK_INCLUDE, TOK_INTERRUPTOR, + TOK_ISMNEMONIC, TOK_LEFT, TOK_LINECONT, TOK_LIST, From 63325a90d1551343aad9ce4c63c3108ac994c9dc Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Tue, 19 May 2015 20:45:49 -0400 Subject: [PATCH 147/351] Added needed changes to pseudo.c --- src/ca65/pseudo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index d99bd29a4..6d27c05c4 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1989,7 +1989,6 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoDebugInfo }, { ccNone, DoDefine }, { ccNone, DoUnexpected }, /* .DEFINED */ - { ccNone, DoUnexpected }, /* .DEFINEDINSTR */ { ccNone, DoDelMac }, { ccNone, DoDestructor }, { ccNone, DoDWord }, @@ -2041,6 +2040,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoIncBin }, { ccNone, DoInclude }, { ccNone, DoInterruptor }, + { ccNone, DoUnexpected }, /* .ISMNEMONIC */ { ccNone, DoInvalid }, /* .LEFT */ { ccNone, DoLineCont }, { ccNone, DoList }, From c30d87f0b7938ff3887dac2417324359b3fe8e12 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Fri, 22 May 2015 20:33:42 -0400 Subject: [PATCH 148/351] Update documentation to .ISMNEMONIC --- doc/ca65.sgml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 52dcccc6b..a40bcddff 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -2316,7 +2316,7 @@ Here's a list of all control commands and a description, what they do: </verb></tscreen> -<sect1><tt>.DEFINEDINSTR</tt><label id=".DEFINEDINSTR"><p> +<sect1><tt>.ISMNEM, .ISMNEMONIC</tt><label id=".ISMNEMONIC"><p> Builtin function. The function expects an identifier as argument in braces. The argument is evaluated, and the function yields "true" if the identifier @@ -2324,7 +2324,7 @@ Here's a list of all control commands and a description, what they do: Example: <tscreen><verb> - .if .not .definedinstr(ina) + .if .not .ismnemonic(ina) .macro ina clc adc #$01 From e72132c8ae54c543a0ede95fe486d6f4cbf33bfc Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 24 May 2015 08:32:15 -0400 Subject: [PATCH 149/351] Made cc65 properly test variadic-function pointer assignments. Improved some error messages. --- src/cc65/declare.c | 11 ++++------- src/cc65/typecmp.c | 18 +++++++++--------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 4fab3ea0a..060a6756d 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -335,26 +335,23 @@ static void FixQualifiers (Type* DataType) T = DataType; while (T->C != T_END) { if (IsTypePtr (T)) { - /* Calling convention qualifier on the pointer? */ if (IsQualCConv (T)) { /* Pull the convention off of the pointer */ Q = T[0].C & T_QUAL_CCONV; T[0].C &= ~T_QUAL_CCONV; + /* Pointer to a function which doesn't have an explicit convention? */ if (IsTypeFunc (T + 1)) { if (IsQualCConv (T + 1)) { - if (T[1].C == Q) { - /* TODO: The end of Declarator() catches this error. - ** Try to make it let the error be caught here, instead. - */ + if ((T[1].C & T_QUAL_CCONV) == Q) { Warning ("Pointer duplicates function's calling convention"); } else { - Error ("Mismatch between pointer's and function's calling conventions"); + Error ("Function's and pointer's calling conventions are different"); } } else { if (Q == T_QUAL_FASTCALL && IsVariadicFunc (T + 1)) { - Error ("Variadic-function pointers cannot be `__fastcall__'"); + Error ("Variadic-function pointers cannot be __fastcall__"); } else { /* Move the qualifier from the pointer to the function. */ T[1].C |= Q; diff --git a/src/cc65/typecmp.c b/src/cc65/typecmp.c index b01cd3f51..8025f4efe 100644 --- a/src/cc65/typecmp.c +++ b/src/cc65/typecmp.c @@ -249,7 +249,7 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) if (LeftQual != RightQual) { /* On the first indirection level, different qualifiers mean ** that the types still are compatible. On the second level, - ** that is a (maybe minor) error. We create a special return code + ** that is a (maybe minor) error. We create a special return-code ** if a qualifier is dropped from a pointer. But, different calling ** conventions are incompatible. Starting from the next level, ** the types are incompatible if the qualifiers differ. @@ -272,22 +272,22 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) SetResult (Result, TC_STRICT_COMPATIBLE); } + if (LeftType != T_TYPE_FUNC) { + break; + } + /* If a calling convention wasn't set explicitly, ** then assume the default one. */ LeftQual &= T_QUAL_CCONV; - if (LeftQual == 0) { - LeftQual = AutoCDecl ? T_QUAL_CDECL : T_QUAL_FASTCALL; + if (LeftQual == T_QUAL_NONE) { + LeftQual = (AutoCDecl || IsVariadicFunc (lhs)) ? T_QUAL_CDECL : T_QUAL_FASTCALL; } RightQual &= T_QUAL_CCONV; - if (RightQual == 0) { - RightQual = AutoCDecl ? T_QUAL_CDECL : T_QUAL_FASTCALL; + if (RightQual == T_QUAL_NONE) { + RightQual = (AutoCDecl || IsVariadicFunc (rhs)) ? T_QUAL_CDECL : T_QUAL_FASTCALL; } - /* (If the objects actually aren't pointers to functions, - ** then this test will pass anyway; and, more appropriate - ** tests will be performed.) - */ if (LeftQual == RightQual) { break; } From bbb6f89731ccc54bffcc811e9405192f16cbbd89 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 24 May 2015 18:31:50 -0400 Subject: [PATCH 150/351] Made cc65 properly test calling conventions when it compares forward declarations to function definitions. --- src/cc65/declare.c | 2 +- src/cc65/typecmp.c | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 060a6756d..163084835 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -1455,7 +1455,7 @@ static void Declarator (const DeclSpec* Spec, Declaration* D, declmode_t Mode) /* We cannot specify fastcall for variadic functions */ if ((F->Flags & FD_VARIADIC) && (Qualifiers & T_QUAL_FASTCALL)) { - Error ("Variadic functions cannot be `__fastcall__'"); + Error ("Variadic functions cannot be __fastcall__"); Qualifiers &= ~T_QUAL_FASTCALL; } diff --git a/src/cc65/typecmp.c b/src/cc65/typecmp.c index 8025f4efe..673dfa163 100644 --- a/src/cc65/typecmp.c +++ b/src/cc65/typecmp.c @@ -246,6 +246,19 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) return; } } + + if (LeftType == T_TYPE_FUNC) { + /* If a calling convention wasn't set explicitly, + ** then assume the default one. + */ + if ((LeftQual & T_QUAL_CCONV) == T_QUAL_NONE) { + LeftQual |= (AutoCDecl || IsVariadicFunc (lhs)) ? T_QUAL_CDECL : T_QUAL_FASTCALL; + } + if ((RightQual & T_QUAL_CCONV) == T_QUAL_NONE) { + RightQual |= (AutoCDecl || IsVariadicFunc (rhs)) ? T_QUAL_CDECL : T_QUAL_FASTCALL; + } + } + if (LeftQual != RightQual) { /* On the first indirection level, different qualifiers mean ** that the types still are compatible. On the second level, @@ -272,23 +285,7 @@ static void DoCompare (const Type* lhs, const Type* rhs, typecmp_t* Result) SetResult (Result, TC_STRICT_COMPATIBLE); } - if (LeftType != T_TYPE_FUNC) { - break; - } - - /* If a calling convention wasn't set explicitly, - ** then assume the default one. - */ - LeftQual &= T_QUAL_CCONV; - if (LeftQual == T_QUAL_NONE) { - LeftQual = (AutoCDecl || IsVariadicFunc (lhs)) ? T_QUAL_CDECL : T_QUAL_FASTCALL; - } - RightQual &= T_QUAL_CCONV; - if (RightQual == T_QUAL_NONE) { - RightQual = (AutoCDecl || IsVariadicFunc (rhs)) ? T_QUAL_CDECL : T_QUAL_FASTCALL; - } - - if (LeftQual == RightQual) { + if (LeftType != T_TYPE_FUNC || (LeftQual & T_QUAL_CCONV) == (RightQual & T_QUAL_CCONV)) { break; } /* else fall through */ From b49fd26d1683df6cfc669faa853b44f08ccf6cac Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 26 May 2015 11:23:54 -0400 Subject: [PATCH 151/351] Improved the compiler documentation, a little bit. --- doc/cc65.sgml | 62 ++++++++++++++++++++++---------------------- doc/customizing.sgml | 4 +-- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index fa6b824c6..ac03c53b2 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -3,7 +3,7 @@ <article> <title>cc65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2015-04-21 +<date>2015-05-26 <abstract> cc65 is a C compiler for 6502 targets. It supports several 6502 based home @@ -558,10 +558,10 @@ and the one defined by the ISO standard: be passed as parameters by value. However, struct assignment *is* possible. <p> -<item> Most of the C library is available only with the fastcall calling - convention (<ref id="extension-fastcall" name="see below">). It means - that you must not mix pointers to those functions with pointers to - user-written, cdecl functions. +<item> Most of the C library is available with only the fastcall calling + convention (<ref id="extension-fastcall" name="see below">). It means + that you must not mix pointers to those functions with pointers to + user-written, cdecl functions (the calling conventions are incompatible). <p> <item> The <tt/volatile/ keyword doesn't have an effect. This is not as bad as it sounds, since the 6502 has so few registers that it isn't @@ -600,30 +600,30 @@ This cc65 version has some extensions to the ISO C standard. <p> <label id="extension-fastcall"> -<item> The normal calling convention -- for non-variadic functions -- is - named "fastcall". The syntax for a function declaration that - <em/explicitly/ uses fastcall is +<item> The normal calling convention -- for non-variadic functions -- is + named "fastcall". The syntax for a function declaration that + <em/explicitly/ uses fastcall is - <tscreen><verb> - <return type> fastcall <function name> (<parameter list>) - </verb></tscreen> - or - <tscreen><verb> - <return type> __fastcall__ <function name> (<parameter list>) - </verb></tscreen> - An example would be - <tscreen><verb> - void __fastcall__ f (unsigned char c) - </verb></tscreen> - The first form of the fastcall keyword is in the user namespace and can - therefore be disabled with the <tt><ref id="option--standard" + <tscreen><verb> + <return type> fastcall <function name> (<parameter list>) + </verb></tscreen> + or + <tscreen><verb> + <return type> __fastcall__ <function name> (<parameter list>) + </verb></tscreen> + An example is + <tscreen><verb> + void __fastcall__ f (unsigned char c) + </verb></tscreen> + The first form of the fastcall keyword is in the user namespace and can + therefore be disabled with the <tt><ref id="option--standard" name="--standard"></tt> command line option. - For functions that are <tt/fastcall/, the rightmost parameter is not - pushed on the stack but left in the primary register when the function - is called. That significantly reduces the cost of calling functions. - <newline><newline> - <p> + For functions that are <tt/fastcall/, the rightmost parameter is not + pushed on the stack but left in the primary register when the function + is called. That significantly reduces the cost of calling those functions. + <newline><newline> + <p> <item> There is another calling convention named "cdecl". Variadic functions (their prototypes have an ellipsis [<tt/.../]) always use that @@ -636,14 +636,14 @@ This cc65 version has some extensions to the ISO C standard. <tscreen><verb> <return type> __cdecl__ <function name> (<parameter list>) </verb></tscreen> - An example would be + An example is <tscreen><verb> - int * __cdecl__ f (unsigned char c) + int* __cdecl__ f (unsigned char c) </verb></tscreen> The first form of the cdecl keyword is in the user namespace; - and therefore, can be disabled with the <tt><ref id="option--standard" - name="--standard"></tt> command-line option. + and therefore, can be disabled with the <tt/<ref id="option--standard" + name="--standard">/ command-line option. For functions that are <tt/cdecl/, the rightmost parameter is pushed onto the stack before the function is called. That increases the cost @@ -701,7 +701,7 @@ This cc65 version has some extensions to the ISO C standard. </verb></tscreen> Since the variable is of type <tt/void/ you may not use it as is. - However, taking the address of the variable results in a <tt/void */ + However, taking the address of the variable results in a <tt/void*/ which may be passed to any function expecting a pointer. See the <url url="geos.html" name="GEOS library document"> for examples diff --git a/doc/customizing.sgml b/doc/customizing.sgml index a54821c34..0a0b8c87e 100644 --- a/doc/customizing.sgml +++ b/doc/customizing.sgml @@ -597,7 +597,7 @@ variable which is stored in the zero page memory space in order to allow for retrieval of each character in the string via the indirect indexed addressing mode. -The assembly language routine is stored in a file named +The assembly language routine is stored in a file names "rs232_tx.s" and is shown below: <tscreen><code> @@ -681,7 +681,7 @@ all of the behind-the-scene work is transparent to the user. #define TX_FIFO_FULL (FIFO_STATUS & 0x01) #define RX_FIFO_EMPTY (FIFO_STATUS & 0x02) -extern void wait (void); +extern void wait (); extern void __fastcall__ rs232_tx (char *str); int main () { From 08e18c93c5f257260b9739d6209c020caeba024c Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 22 Jun 2015 00:15:48 -0400 Subject: [PATCH 152/351] Added explicit settings of calling conventions in pointer-to-function declarations in system and library headers. --- include/stdlib.h | 4 ++-- libsrc/common/_printf.h | 2 +- libsrc/common/bsearch.c | 5 +++-- libsrc/common/qsort.c | 7 ++++--- libsrc/common/vfprintf.s | 4 ++-- libsrc/common/vsnprintf.s | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/stdlib.h b/include/stdlib.h index eac5629a8..3103172d8 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -107,12 +107,12 @@ int __fastcall__ atoi (const char* s); long __fastcall__ atol (const char* s); int __fastcall__ atexit (void (*exitfunc) (void)); void* __fastcall__ bsearch (const void* key, const void* base, size_t n, - size_t size, int (*cmp) (const void*, const void*)); + size_t size, int __fastcall__ (* cmp) (const void*, const void*)); div_t __fastcall__ div (int numer, int denom); void __fastcall__ exit (int ret) __attribute__ ((noreturn)); char* __fastcall__ getenv (const char* name); void __fastcall__ qsort (void* base, size_t count, size_t size, - int (*compare) (const void*, const void*)); + int __fastcall__ (* compare) (const void*, const void*)); long __fastcall__ strtol (const char* nptr, char** endptr, int base); unsigned long __fastcall__ strtoul (const char* nptr, char** endptr, int base); int __fastcall__ system (const char* s); diff --git a/libsrc/common/_printf.h b/libsrc/common/_printf.h index ffb2443bd..7914fa870 100644 --- a/libsrc/common/_printf.h +++ b/libsrc/common/_printf.h @@ -16,7 +16,7 @@ struct outdesc; /* Type of the function that is called to output data */ -typedef void (*outfunc) (struct outdesc* desc, const char* buf, unsigned count); +typedef void __cdecl__ (* outfunc) (struct outdesc* desc, const char* buf, unsigned count); diff --git a/libsrc/common/bsearch.c b/libsrc/common/bsearch.c index f6d32a5b5..aafd28592 100644 --- a/libsrc/common/bsearch.c +++ b/libsrc/common/bsearch.c @@ -1,7 +1,8 @@ /* ** bsearch.c ** -** Ullrich von Bassewitz, 17.06.1998 +** 1998-06-17, Ullrich von Bassewitz +** 2015-06-21, Greg King */ @@ -11,7 +12,7 @@ void* __fastcall__ bsearch (const void* key, const void* base, size_t n, - size_t size, int (*cmp) (const void*, const void*)) + size_t size, int __fastcall__ (* cmp) (const void*, const void*)) { int current; int result; diff --git a/libsrc/common/qsort.c b/libsrc/common/qsort.c index df02095ed..991db3ba1 100644 --- a/libsrc/common/qsort.c +++ b/libsrc/common/qsort.c @@ -1,7 +1,8 @@ /* ** qsort.c ** -** Ullrich von Bassewitz, 09.12.1998 +** 1998.12.09, Ullrich von Bassewitz +** 2015-06-21, Greg King */ @@ -12,7 +13,7 @@ static void QuickSort (register unsigned char* Base, int Lo, int Hi, register size_t Size, - int (*Compare)(const void*, const void*)) + int __fastcall__ (* Compare) (const void*, const void*)) /* Internal recursive function. Works with ints, but this shouldn't be ** a problem. */ @@ -52,7 +53,7 @@ static void QuickSort (register unsigned char* Base, int Lo, int Hi, void __fastcall__ qsort (void* base, size_t nmemb, size_t size, - int (*compare)(const void*, const void*)) + int __fastcall__ (* compare) (const void*, const void*)) /* Quicksort implementation */ { if (nmemb > 1) { diff --git a/libsrc/common/vfprintf.s b/libsrc/common/vfprintf.s index 9812f661b..1225bcc47 100644 --- a/libsrc/common/vfprintf.s +++ b/libsrc/common/vfprintf.s @@ -33,7 +33,7 @@ ptr: .res 2 ; Points to output file ; can ignore the passed pointer d, and access the data directly. While this ; is not very clean, it gives better and shorter code. ; -; static void out (struct outdesc* d, const char* buf, unsigned count) +; static void cdecl out (struct outdesc* d, const char* buf, unsigned count) ; /* Routine used for writing */ ; { ; register size_t cnt; @@ -56,7 +56,7 @@ out: ldy #5 ldy #7 jsr pushwysp ; Push count lda ptr - ldx ptr+1 + ldx ptr+1 jsr _fwrite sta ptr1 ; Save function result stx ptr1+1 diff --git a/libsrc/common/vsnprintf.s b/libsrc/common/vsnprintf.s index db82bdaf3..a8ed50e06 100644 --- a/libsrc/common/vsnprintf.s +++ b/libsrc/common/vsnprintf.s @@ -1,5 +1,5 @@ ; -; int vsnprintf (char* Buf, size_t size, const char* Format, va_list ap); +; int __fastcall__ vsnprintf (char* Buf, size_t size, const char* Format, va_list ap); ; ; Ullrich von Bassewitz, 2009-09-26 ; @@ -130,7 +130,7 @@ L9: pla ; ---------------------------------------------------------------------------- ; Callback routine used for the actual output. ; -; static void out (struct outdesc* d, const char* buf, unsigned count) +; static void __cdecl__ out (struct outdesc* d, const char* buf, unsigned count) ; /* Routine used for writing */ ; ; Since we know, we're called with a pointer to our static outdesc structure, From 8bdbc00ba3019760bb6aba1122611478329fa1dd Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 25 Jun 2015 09:19:35 +0200 Subject: [PATCH 153/351] Bumped version. As suggested the incompatibility resulting form changing the default calling convention makes a new version appropriate - from user perspective. --- src/common/version.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/version.c b/src/common/version.c index d2fcf4f40..4e61a5f83 100644 --- a/src/common/version.c +++ b/src/common/version.c @@ -47,7 +47,7 @@ #define VER_MAJOR 2U -#define VER_MINOR 14U +#define VER_MINOR 15U From f6d123457646f3ae6bca4cd2dcdebc9b40217b5e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 25 Jun 2015 13:57:17 -0400 Subject: [PATCH 154/351] Added some names to the list of test-suite programs that need the --all-cdecl work-around. Added a work-around for a cc65 bug that made the yacc tests fail. --- test/ref/Makefile | 14 ++++++++++++++ test/val/Makefile | 6 +++--- test/val/ptrfunc.c | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/test/ref/Makefile b/test/ref/Makefile index 3e7a5ad6c..dbe0b0f75 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -36,6 +36,20 @@ $(WORKDIR)/%.ref: %.c $(CC) $(CFLAGS) $< -o $(WORKDIR)/$*.host $(WORKDIR)/$*.host > $@ +# Some files have "K & R"-style syntax. Therefore, some forward +# function-declarations don't match the later function definitions. +# Those programs fail when fastcall is used; but, the cdecl calling convention +# tolerates those conflicts. Therefore, make their functions default to cdecl. +# +$(WORKDIR)/init%prg: CC65FLAGS += -Wc --all-cdecl +$(WORKDIR)/switch.%rg: CC65FLAGS += -Wc --all-cdecl + +# Also, yacc.c does some things that fail when stack operations are optimized. +# Therefore, don't optimize them. +# +$(WORKDIR)/yacc.%rg: CC65FLAGS += -Wc --all-cdecl,--disable-opt,OptStackOps +$(WORKDIR)/yaccdbg%prg: CC65FLAGS += -Wc --all-cdecl,--disable-opt,OptStackOps + $(WORKDIR)/%.prg: %.c $(WORKDIR)/%.ref $(CL65) $(CC65FLAGS) $< -o $@ $(SIM65) $(SIM65FLAGS) $@ > $(WORKDIR)/$*.out diff --git a/test/val/Makefile b/test/val/Makefile index cb954a307..b2a2481b4 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -26,12 +26,12 @@ TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c= all: $(TESTS) -# cq71.c and cq84.c have "K & R"-style syntax. And, some local forward -# function-declarations don't match the later global function definitions. +# Some files have "K & R"-style syntax. Therefore, some forward +# function-declarations don't match the later function definitions. # Those programs fail when fastcall is used; but, the cdecl calling convention # tolerates those conflicts. Therefore, make their functions default to cdecl. # -$(WORKDIR)/cq71%prg $(WORKDIR)/cq84%prg: CC65FLAGS += -Wc --all-cdecl +$(WORKDIR)/cq4%prg $(WORKDIR)/cq71.%rg $(WORKDIR)/cq81%prg $(WORKDIR)/cq84%prg: CC65FLAGS += -Wc --all-cdecl $(WORKDIR)/%.prg: %.c $(CL65) $(CC65FLAGS) $< -o $@ diff --git a/test/val/ptrfunc.c b/test/val/ptrfunc.c index e1682507a..55503e176 100644 --- a/test/val/ptrfunc.c +++ b/test/val/ptrfunc.c @@ -5,7 +5,8 @@ */ #include <stdio.h> -#include <limits.h> + +#define NO_IMPLICIT_FUNCPTR_CONV unsigned char success=0; unsigned char failures=0; From 54cfd2e2a139cb8c5ea80373afdf023dd6e1dca1 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 26 Jun 2015 23:36:14 +0200 Subject: [PATCH 155/351] Avoid wrong error. --- test/err/cc65091001.c | 1 + 1 file changed, 1 insertion(+) diff --git a/test/err/cc65091001.c b/test/err/cc65091001.c index 265df0aac..65ce6ec83 100644 --- a/test/err/cc65091001.c +++ b/test/err/cc65091001.c @@ -9,6 +9,7 @@ #include <assert.h> #include <string.h> +#include <stdio.h> typedef unsigned char U8; char var = 0xf0; char fn(char bar) From 9bd11f161f2ebcf5e65690489a6f26ef27beb3bb Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 27 Jun 2015 00:03:45 +0200 Subject: [PATCH 156/351] Made test Makefiles work with CMD.EXE --- test/Makefile | 20 +++++++++++--------- test/err/Makefile | 34 ++++++++++++++++++---------------- test/misc/Makefile | 29 ++++++++++++++++------------- test/ref/Makefile | 32 +++++++++++++++++--------------- test/val/Makefile | 16 ++++++++-------- 5 files changed, 70 insertions(+), 61 deletions(-) diff --git a/test/Makefile b/test/Makefile index 27f7ff456..ddeccc5ee 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,25 +10,27 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - RM := del /f EXE := .exe - MKDIR := mkdir - RMDIR := rmdir + RM = del /f $(subst /,\,$1) + MKDIR = mkdir $(subst /,\,$1) + RMDIR = rmdir /s /q $(subst /,\,$1) else - RM := rm -f EXE := - MKDIR := mkdir -p - RMDIR := rmdir + RM = $(RM) $1 + MKDIR = mkdir $1 + RMDIR = rmdir $1 endif WORKDIR := ../testwrk +CC := gcc + .PHONY: all dotests continue mostly-clean clean all: dotests $(WORKDIR): - $(MKDIR) $(WORKDIR) + $(call MKDIR,$(WORKDIR)) $(WORKDIR)/bdiff$(EXE): bdiff.c | $(WORKDIR) $(CC) -O2 -o $@ $< @@ -50,5 +52,5 @@ mostly-clean: @$(MAKE) -C misc clean clean: mostly-clean - $(RM) $(WORKDIR)/bdiff$(EXE) - $(RMDIR) $(WORKDIR) + -@$(call RM,$(WORKDIR)/bdiff$(EXE)) + -$(call RMDIR,$(WORKDIR)) diff --git a/test/err/Makefile b/test/err/Makefile index 4e12323fd..d72978427 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -5,16 +5,18 @@ ifneq ($(shell echo),) CMD_EXE := 1 endif +ifdef CMD_EXE + NOT := - # Hack + RM = del /f $(subst /,\,$1) +else + NOT := ! + RM = $(RM) $1 +endif + CC65FLAGS := -t sim6502 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) -ifdef CMD_EXE -RM := del /f -else -RM := rm -f -endif - WORKDIR := ../../testwrk .PHONY: all clean @@ -25,22 +27,22 @@ TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c= all: $(TESTS) $(WORKDIR)/%.prg: %.c - ! $(CL65) $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.o.prg: %.c - ! $(CL65) -O $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -O $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.os.prg: %.c - ! $(CL65) -Os $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -Os $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.osi.prg: %.c - ! $(CL65) -Osi $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -Osi $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.osir.prg: %.c - ! $(CL65) -Osir $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -Osir $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.oi.prg: %.c - ! $(CL65) -Oi $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -Oi $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.oir.prg: %.c - ! $(CL65) -Oir $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -Oir $(CC65FLAGS) $< -o $@ $(WORKDIR)/%.or.prg: %.c - ! $(CL65) -Or $(CC65FLAGS) $< -o $@ + $(NOT) $(CL65) -Or $(CC65FLAGS) $< -o $@ clean: - @$(RM) $(TESTS) - @$(RM) $(SOURCES:.c=.o) + -@$(call RM,$(TESTS)) + -@$(call RM,$(SOURCES:.c=.o)) diff --git a/test/misc/Makefile b/test/misc/Makefile index b04321c33..a1b1d72ca 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -5,20 +5,23 @@ ifneq ($(shell echo),) CMD_EXE := 1 endif +ifdef CMD_EXE + S := $(subst /,\,/) + NOT := - # Hack + RM = del /f $(subst /,\,$1) +else + S := / + NOT := ! + RM = $(RM) $1 +endif + CC65FLAGS := -t sim6502 SIM65FLAGS := -x 200000000 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) -SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) - -ifdef CMD_EXE -RM := del /f -else -RM := rm -f -endif - -WORKDIR := ../../testwrk +SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) +WORKDIR := ..$S..$Stestwrk DIFF := $(WORKDIR)/bdiff .PHONY: all clean @@ -31,7 +34,7 @@ all: $(TESTS) # should compile, but then hangs in an endless loop $(WORKDIR)/endless%prg: endless.c $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ - ! $(SIM65) $(SIM65FLAGS) $@ + $(NOT) $(SIM65) $(SIM65FLAGS) $@ # these need reference data that can't be generated by a host-compiled program, # in a useful way @@ -51,6 +54,6 @@ $(WORKDIR)/sitest%prg: sitest.c # -$(SIM65) $(SIM65FLAGS) $@ clean: - @$(RM) $(TESTS) - @$(RM) $(SOURCES:.c=.o) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.out) + -@$(call RM,$(TESTS)) + -@$(call RM,$(SOURCES:.c=.o)) + -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.out)) diff --git a/test/ref/Makefile b/test/ref/Makefile index dbe0b0f75..4d6735099 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -6,22 +6,24 @@ ifneq ($(shell echo),) CMD_EXE := 1 endif +ifdef CMD_EXE + S := $(subst /,\,/) + RM = del /f $(subst /,\,$1) +else + S := / + RM = $(RM) $1 +endif + CC65FLAGS := -t sim6502 SIM65FLAGS := -x 200000000 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) -SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) - -ifdef CMD_EXE -RM := del /f -else -RM := rm -f -endif - -WORKDIR := ../../testwrk +SIM65 := $(if $(wildcard ../../bin/sim65*),..$S..$Sbin$Ssim65,sim65) +WORKDIR := ..$S..$Stestwrk DIFF := $(WORKDIR)/bdiff +CC := gcc CFLAGS := -O2 -Wall -W -Wextra -fwrapv -fno-strict-overflow .PHONY: all clean @@ -34,7 +36,7 @@ all: $(REFS) $(TESTS) $(WORKDIR)/%.ref: %.c $(CC) $(CFLAGS) $< -o $(WORKDIR)/$*.host - $(WORKDIR)/$*.host > $@ + $(WORKDIR)$S$*.host > $@ # Some files have "K & R"-style syntax. Therefore, some forward # function-declarations don't match the later function definitions. @@ -91,8 +93,8 @@ $(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref clean: - @$(RM) $(TESTS) - @$(RM) $(SOURCES:.c=.o) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.out) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.ref) - @$(RM) $(SOURCES:%.c=$(WORKDIR)/%.host) + -@$(call RM,$(TESTS)) + -@$(call RM,$(SOURCES:.c=.o)) + -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.out)) + -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.ref)) + -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.host)) diff --git a/test/val/Makefile b/test/val/Makefile index b2a2481b4..4392fa323 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -5,18 +5,18 @@ ifneq ($(shell echo),) CMD_EXE := 1 endif +ifdef CMD_EXE + RM = del /f $(subst /,\,$1) +else + RM = $(RM) $1 +endif + CC65FLAGS := -t sim6502 SIM65FLAGS := -x 200000000 CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) SIM65 := $(if $(wildcard ../../bin/sim65*),../../bin/sim65,sim65) -ifdef CMD_EXE -RM := del /f -else -RM := rm -f -endif - WORKDIR := ../../testwrk .PHONY: all clean @@ -66,5 +66,5 @@ $(WORKDIR)/%.or.prg: %.c $(SIM65) $(SIM65FLAGS) $@ clean: - @$(RM) $(TESTS) - @$(RM) $(SOURCES:.c=.o) + -@$(call RM,$(TESTS)) + -@$(call RM,$(SOURCES:.c=.o)) From 9c3c886da390980ecf49f275ced0dd0b7b300c9d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 27 Jun 2015 00:04:51 +0200 Subject: [PATCH 157/351] Added regression tests to Travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a11412230..5e7a76ee6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ script: - make -C src clean - make bin USER_CFLAGS=-Werror CROSS_COMPILE=i686-w64-mingw32- - make doc zip + - make -C test after_success: - make -f Makefile.travis env: From 5a7ba692f53f8bb633eff78f0965f53b19dfd1aa Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 27 Jun 2015 00:33:24 +0200 Subject: [PATCH 158/351] Avoid "*** Recursive variable `RM' references itself (eventually)." --- test/Makefile | 8 ++++---- test/err/Makefile | 8 ++++---- test/misc/Makefile | 10 +++++----- test/ref/Makefile | 14 +++++++------- test/val/Makefile | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/test/Makefile b/test/Makefile index ddeccc5ee..8c005a957 100644 --- a/test/Makefile +++ b/test/Makefile @@ -11,12 +11,12 @@ endif ifdef CMD_EXE EXE := .exe - RM = del /f $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) MKDIR = mkdir $(subst /,\,$1) RMDIR = rmdir /s /q $(subst /,\,$1) else EXE := - RM = $(RM) $1 + DEL = $(RM) $1 MKDIR = mkdir $1 RMDIR = rmdir $1 endif @@ -52,5 +52,5 @@ mostly-clean: @$(MAKE) -C misc clean clean: mostly-clean - -@$(call RM,$(WORKDIR)/bdiff$(EXE)) - -$(call RMDIR,$(WORKDIR)) + -@$(call DEL,$(WORKDIR)/bdiff$(EXE)) + -@$(call RMDIR,$(WORKDIR)) diff --git a/test/err/Makefile b/test/err/Makefile index d72978427..ff927ada0 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -7,10 +7,10 @@ endif ifdef CMD_EXE NOT := - # Hack - RM = del /f $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else NOT := ! - RM = $(RM) $1 + DEL = $(RM) $1 endif CC65FLAGS := -t sim6502 @@ -44,5 +44,5 @@ $(WORKDIR)/%.or.prg: %.c $(NOT) $(CL65) -Or $(CC65FLAGS) $< -o $@ clean: - -@$(call RM,$(TESTS)) - -@$(call RM,$(SOURCES:.c=.o)) + -@$(call DEL,$(TESTS)) + -@$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/misc/Makefile b/test/misc/Makefile index a1b1d72ca..e5fd6d2b8 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -8,11 +8,11 @@ endif ifdef CMD_EXE S := $(subst /,\,/) NOT := - # Hack - RM = del /f $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else S := / NOT := ! - RM = $(RM) $1 + DEL = $(RM) $1 endif CC65FLAGS := -t sim6502 @@ -54,6 +54,6 @@ $(WORKDIR)/sitest%prg: sitest.c # -$(SIM65) $(SIM65FLAGS) $@ clean: - -@$(call RM,$(TESTS)) - -@$(call RM,$(SOURCES:.c=.o)) - -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.out)) + -@$(call DEL,$(TESTS)) + -@$(call DEL,$(SOURCES:.c=.o)) + -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) diff --git a/test/ref/Makefile b/test/ref/Makefile index 4d6735099..de9248ac7 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -8,10 +8,10 @@ endif ifdef CMD_EXE S := $(subst /,\,/) - RM = del /f $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else S := / - RM = $(RM) $1 + DEL = $(RM) $1 endif CC65FLAGS := -t sim6502 @@ -93,8 +93,8 @@ $(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref clean: - -@$(call RM,$(TESTS)) - -@$(call RM,$(SOURCES:.c=.o)) - -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.out)) - -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.ref)) - -@$(call RM,$(SOURCES:%.c=$(WORKDIR)/%.host)) + -@$(call DEL,$(TESTS)) + -@$(call DEL,$(SOURCES:.c=.o)) + -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) + -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref)) + -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host)) diff --git a/test/val/Makefile b/test/val/Makefile index 4392fa323..4de47c6b5 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -6,9 +6,9 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - RM = del /f $(subst /,\,$1) + DEL = del /f $(subst /,\,$1) else - RM = $(RM) $1 + DEL = $(RM) $1 endif CC65FLAGS := -t sim6502 @@ -66,5 +66,5 @@ $(WORKDIR)/%.or.prg: %.c $(SIM65) $(SIM65FLAGS) $@ clean: - -@$(call RM,$(TESTS)) - -@$(call RM,$(SOURCES:.c=.o)) + -@$(call DEL,$(TESTS)) + -@$(call DEL,$(SOURCES:.c=.o)) From 7bb09e916c72727649d2dbb47aabc79dead8c631 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 27 Jun 2015 00:43:41 +0200 Subject: [PATCH 159/351] Run the regression tests _before_ replacing the built binaries with Win32 cross-builds. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5e7a76ee6..6c6a428e6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,10 +5,10 @@ install: script: - make bin USER_CFLAGS=-Werror - make lib QUIET=1 + - make -C test - make -C src clean - make bin USER_CFLAGS=-Werror CROSS_COMPILE=i686-w64-mingw32- - make doc zip - - make -C test after_success: - make -f Makefile.travis env: From d0e0b98b4372e80c37005199c23d8b425bf763d7 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 27 Jun 2015 01:09:20 +0200 Subject: [PATCH 160/351] Revert "Equality problem (Ullrich von Bassewitz)". Uz classifies his own fix as broken: http://www.cc65.org/mailarchive/2015-01/11721.html Although the original issue fixed seemed rather significant looking back now the regression caused by the (broken) fix seems even more significant :-( (reverted from commit 55815ea10cfa3a779b44399f99dd0cf1cb4956f2) ====================================================================== Equality problem (Ullrich von Bassewitz) Neil Stockbridge reported a problem with equality comparisons on cc65.org's mailing list: http://www.cc65.org/mailarchive/2014-10/11680.html Uz provided a fix for it: http://www.cc65.org/mailarchive/2014-10/11683.html This pull request ask to add the fix to cc65 on github. --- src/cc65/coptstop.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index 427d0bd13..cf6392bd3 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -766,12 +766,8 @@ static unsigned Opt_toseqax_tosneax (StackOpData* D, const char* BoolTransformer InsertEntry (D, X, D->IP++); /* Lhs load entries can be removed */ - if (LoadX->AM != AM65_IMM) { - D->Lhs.X.Flags |= LI_REMOVE; - } - if (LoadA->AM != AM65_IMM) { - D->Lhs.A.Flags |= LI_REMOVE; - } + D->Lhs.X.Flags |= LI_REMOVE; + D->Lhs.A.Flags |= LI_REMOVE; } else if ((D->Rhs.A.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT && (D->Rhs.X.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT) { @@ -794,12 +790,8 @@ static unsigned Opt_toseqax_tosneax (StackOpData* D, const char* BoolTransformer InsertEntry (D, X, D->IP++); /* Rhs load entries can be removed */ - if (LoadX->AM != AM65_IMM) { - D->Rhs.X.Flags |= LI_REMOVE; - } - if (LoadA->AM != AM65_IMM) { - D->Rhs.A.Flags |= LI_REMOVE; - } + D->Rhs.X.Flags |= LI_REMOVE; + D->Rhs.A.Flags |= LI_REMOVE; } else if ((D->Rhs.A.Flags & LI_DIRECT) != 0 && (D->Rhs.X.Flags & LI_DIRECT) != 0) { From e7fca18798e2fb1e64a5e0f50ae9cf35f80bb578 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Sun, 10 May 2015 20:25:40 -0400 Subject: [PATCH 161/351] Added .DEFINEDMACRO psuedo function Fixed typo/fomatting Formatting fix Refactor the code to test for a macro Remove .FEATURE requirement for .DEFINEDMACRO --- doc/ca65.sgml | 43 ++++-- src/ca65/expr.c | 31 ++++- src/ca65/global.c | 1 + src/ca65/pseudo.c | 1 + src/ca65/scanner.c | 319 +++++++++++++++++++++++---------------------- src/ca65/token.h | 1 + 6 files changed, 223 insertions(+), 173 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index a40bcddff..4beb4e913 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -2316,21 +2316,25 @@ Here's a list of all control commands and a description, what they do: </verb></tscreen> -<sect1><tt>.ISMNEM, .ISMNEMONIC</tt><label id=".ISMNEMONIC"><p> +<sect1><tt>.DEFINEDMACRO</tt><label id=".DEFINEDMACRO"><p> Builtin function. The function expects an identifier as argument in braces. - The argument is evaluated, and the function yields "true" if the identifier - is defined as an instruction mnemonic that is recognized by the assembler. - Example: + The argument is evaluated, and the function yields "true" if the identifier + has already been defined as the name of a macro. Otherwise the function yields + false. Example: <tscreen><verb> - .if .not .ismnemonic(ina) - .macro ina - clc - adc #$01 - .endmacro - .endif - + .macro add foo + clc + adc foo + .endmacro + + .if .definedmacro(add) + add #$01 + .else + clc + adc #$01 + .endif </verb></tscreen> @@ -3158,6 +3162,23 @@ Here's a list of all control commands and a description, what they do: the feature in more detail. +<sect1><tt>.ISMNEM, .ISMNEMONIC</tt><label id=".ISMNEMONIC"><p> + + Builtin function. The function expects an identifier as argument in braces. + The argument is evaluated, and the function yields "true" if the identifier + is defined as an instruction mnemonic that is recognized by the assembler. + Example: + + <tscreen><verb> + .if .not .ismnemonic(ina) + .macro ina + clc + adc #$01 + .endmacro + .endif + </verb></tscreen> + + <sect1><tt>.LINECONT</tt><label id=".LINECONT"><p> Switch on or off line continuations using the backslash character diff --git a/src/ca65/expr.c b/src/ca65/expr.c index c4da32824..32653e980 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -435,13 +435,34 @@ static ExprNode* FuncIsMnemonic (void) /* Macros and symbols may NOT use the names of instructions, so just check for the instruction */ Instr = FindInstruction (&CurTok.SVal); } + } + else { + Error ("Identifier expected."); + } + /* Skip the name */ + NextTok(); + + return GenLiteralExpr (Instr > 0); +} + + + +static ExprNode* FuncDefinedMacro (void) +/* Handle the .DEFINEDMACRO builtin function */ +{ + Macro* Mac = 0; + + /* Check if the identifier is a macro */ + + if (CurTok.Tok == TOK_IDENT) { + Mac = FindMacro (&CurTok.SVal); } else { Error ("Identifier expected."); } /* Skip the name */ NextTok (); - return GenLiteralExpr (Instr > 0); + return GenLiteralExpr (Mac != 0); } @@ -1094,8 +1115,8 @@ static ExprNode* Factor (void) N = Function (FuncDefined); break; - case TOK_ISMNEMONIC: - N = Function (FuncIsMnemonic); + case TOK_DEFINEDMACRO: + N = Function (FuncDefinedMacro); break; case TOK_HIBYTE: @@ -1106,6 +1127,10 @@ static ExprNode* Factor (void) N = Function (FuncHiWord); break; + case TOK_ISMNEMONIC: + N = Function (FuncIsMnemonic); + break; + case TOK_LOBYTE: N = Function (FuncLoByte); break; diff --git a/src/ca65/global.c b/src/ca65/global.c index 77ed66e7f..e77b9201c 100644 --- a/src/ca65/global.c +++ b/src/ca65/global.c @@ -83,3 +83,4 @@ unsigned char CComments = 0; /* Allow C like comments */ unsigned char ForceRange = 0; /* Force values into expected range */ unsigned char UnderlineInNumbers = 0; /* Allow underlines in numbers */ unsigned char AddrSize = 0; /* Allow .ADDRSIZE function */ + diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 6d27c05c4..4484e3c26 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1989,6 +1989,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoDebugInfo }, { ccNone, DoDefine }, { ccNone, DoUnexpected }, /* .DEFINED */ + { ccNone, DoUnexpected }, /* .DEFINEDMACRO */ { ccNone, DoDelMac }, { ccNone, DoDestructor }, { ccNone, DoDWord }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 30494b365..97ed2c9d9 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -132,165 +132,166 @@ struct DotKeyword { const char* Key; /* MUST be first field */ token_t Tok; } DotKeywords [] = { - { ".A16", TOK_A16 }, - { ".A8", TOK_A8 }, - { ".ADDR", TOK_ADDR }, - { ".ADDRSIZE", TOK_ADDRSIZE }, - { ".ALIGN", TOK_ALIGN }, - { ".AND", TOK_BOOLAND }, - { ".ASCIIZ", TOK_ASCIIZ }, - { ".ASSERT", TOK_ASSERT }, - { ".AUTOIMPORT", TOK_AUTOIMPORT }, - { ".BANK", TOK_BANK }, - { ".BANKBYTE", TOK_BANKBYTE }, - { ".BANKBYTES", TOK_BANKBYTES }, - { ".BITAND", TOK_AND }, - { ".BITNOT", TOK_NOT }, - { ".BITOR", TOK_OR }, - { ".BITXOR", TOK_XOR }, - { ".BLANK", TOK_BLANK }, - { ".BSS", TOK_BSS }, - { ".BYT", TOK_BYTE }, - { ".BYTE", TOK_BYTE }, - { ".CASE", TOK_CASE }, - { ".CHARMAP", TOK_CHARMAP }, - { ".CODE", TOK_CODE }, - { ".CONCAT", TOK_CONCAT }, - { ".CONDES", TOK_CONDES }, - { ".CONST", TOK_CONST }, - { ".CONSTRUCTOR", TOK_CONSTRUCTOR }, - { ".CPU", TOK_CPU }, - { ".DATA", TOK_DATA }, - { ".DBG", TOK_DBG }, - { ".DBYT", TOK_DBYT }, - { ".DEBUGINFO", TOK_DEBUGINFO }, - { ".DEF", TOK_DEFINED }, - { ".DEFINE", TOK_DEFINE }, - { ".DEFINED", TOK_DEFINED }, - { ".DELMAC", TOK_DELMAC }, - { ".DELMACRO", TOK_DELMAC }, - { ".DESTRUCTOR", TOK_DESTRUCTOR }, - { ".DWORD", TOK_DWORD }, - { ".ELSE", TOK_ELSE }, - { ".ELSEIF", TOK_ELSEIF }, - { ".END", TOK_END }, - { ".ENDENUM", TOK_ENDENUM }, - { ".ENDIF", TOK_ENDIF }, - { ".ENDMAC", TOK_ENDMACRO }, - { ".ENDMACRO", TOK_ENDMACRO }, - { ".ENDPROC", TOK_ENDPROC }, - { ".ENDREP", TOK_ENDREP }, - { ".ENDREPEAT", TOK_ENDREP }, - { ".ENDSCOPE", TOK_ENDSCOPE }, - { ".ENDSTRUCT", TOK_ENDSTRUCT }, - { ".ENDUNION", TOK_ENDUNION }, - { ".ENUM", TOK_ENUM }, - { ".ERROR", TOK_ERROR }, - { ".EXITMAC", TOK_EXITMACRO }, - { ".EXITMACRO", TOK_EXITMACRO }, - { ".EXPORT", TOK_EXPORT }, - { ".EXPORTZP", TOK_EXPORTZP }, - { ".FARADDR", TOK_FARADDR }, - { ".FATAL", TOK_FATAL }, - { ".FEATURE", TOK_FEATURE }, - { ".FILEOPT", TOK_FILEOPT }, - { ".FOPT", TOK_FILEOPT }, - { ".FORCEIMPORT", TOK_FORCEIMPORT }, - { ".FORCEWORD", TOK_FORCEWORD }, - { ".GLOBAL", TOK_GLOBAL }, - { ".GLOBALZP", TOK_GLOBALZP }, - { ".HIBYTE", TOK_HIBYTE }, - { ".HIBYTES", TOK_HIBYTES }, - { ".HIWORD", TOK_HIWORD }, - { ".I16", TOK_I16 }, - { ".I8", TOK_I8 }, - { ".IDENT", TOK_MAKEIDENT }, - { ".IF", TOK_IF }, - { ".IFBLANK", TOK_IFBLANK }, - { ".IFCONST", TOK_IFCONST }, - { ".IFDEF", TOK_IFDEF }, - { ".IFNBLANK", TOK_IFNBLANK }, - { ".IFNCONST", TOK_IFNCONST }, - { ".IFNDEF", TOK_IFNDEF }, - { ".IFNREF", TOK_IFNREF }, - { ".IFP02", TOK_IFP02 }, - { ".IFP816", TOK_IFP816 }, - { ".IFPC02", TOK_IFPC02 }, - { ".IFPSC02", TOK_IFPSC02 }, - { ".IFREF", TOK_IFREF }, - { ".IMPORT", TOK_IMPORT }, - { ".IMPORTZP", TOK_IMPORTZP }, - { ".INCBIN", TOK_INCBIN }, - { ".INCLUDE", TOK_INCLUDE }, - { ".INTERRUPTOR", TOK_INTERRUPTOR }, - { ".ISMNEM", TOK_ISMNEMONIC }, - { ".ISMNEMONIC", TOK_ISMNEMONIC }, - { ".LEFT", TOK_LEFT }, - { ".LINECONT", TOK_LINECONT }, - { ".LIST", TOK_LIST }, - { ".LISTBYTES", TOK_LISTBYTES }, - { ".LOBYTE", TOK_LOBYTE }, - { ".LOBYTES", TOK_LOBYTES }, - { ".LOCAL", TOK_LOCAL }, - { ".LOCALCHAR", TOK_LOCALCHAR }, - { ".LOWORD", TOK_LOWORD }, - { ".MAC", TOK_MACRO }, - { ".MACPACK", TOK_MACPACK }, - { ".MACRO", TOK_MACRO }, - { ".MATCH", TOK_MATCH }, - { ".MAX", TOK_MAX }, - { ".MID", TOK_MID }, - { ".MIN", TOK_MIN }, - { ".MOD", TOK_MOD }, - { ".NOT", TOK_BOOLNOT }, - { ".NULL", TOK_NULL }, - { ".OR", TOK_BOOLOR }, - { ".ORG", TOK_ORG }, - { ".OUT", TOK_OUT }, - { ".P02", TOK_P02 }, - { ".P816", TOK_P816 }, - { ".PAGELEN", TOK_PAGELENGTH }, - { ".PAGELENGTH", TOK_PAGELENGTH }, - { ".PARAMCOUNT", TOK_PARAMCOUNT }, - { ".PC02", TOK_PC02 }, - { ".POPCPU", TOK_POPCPU }, - { ".POPSEG", TOK_POPSEG }, - { ".PROC", TOK_PROC }, - { ".PSC02", TOK_PSC02 }, - { ".PUSHCPU", TOK_PUSHCPU }, - { ".PUSHSEG", TOK_PUSHSEG }, - { ".REF", TOK_REFERENCED }, - { ".REFERENCED", TOK_REFERENCED }, - { ".RELOC", TOK_RELOC }, - { ".REPEAT", TOK_REPEAT }, - { ".RES", TOK_RES }, - { ".RIGHT", TOK_RIGHT }, - { ".RODATA", TOK_RODATA }, - { ".SCOPE", TOK_SCOPE }, - { ".SEGMENT", TOK_SEGMENT }, - { ".SET", TOK_SET }, - { ".SETCPU", TOK_SETCPU }, - { ".SHL", TOK_SHL }, - { ".SHR", TOK_SHR }, - { ".SIZEOF", TOK_SIZEOF }, - { ".SMART", TOK_SMART }, - { ".SPRINTF", TOK_SPRINTF }, - { ".STRAT", TOK_STRAT }, - { ".STRING", TOK_STRING }, - { ".STRLEN", TOK_STRLEN }, - { ".STRUCT", TOK_STRUCT }, - { ".TAG", TOK_TAG }, - { ".TCOUNT", TOK_TCOUNT }, - { ".TIME", TOK_TIME }, - { ".UNDEF", TOK_UNDEF }, - { ".UNDEFINE", TOK_UNDEF }, - { ".UNION", TOK_UNION }, - { ".VERSION", TOK_VERSION }, - { ".WARNING", TOK_WARNING }, - { ".WORD", TOK_WORD }, - { ".XMATCH", TOK_XMATCH }, - { ".XOR", TOK_BOOLXOR }, - { ".ZEROPAGE", TOK_ZEROPAGE }, + { ".A16", TOK_A16 }, + { ".A8", TOK_A8 }, + { ".ADDR", TOK_ADDR }, + { ".ADDRSIZE", TOK_ADDRSIZE }, + { ".ALIGN", TOK_ALIGN }, + { ".AND", TOK_BOOLAND }, + { ".ASCIIZ", TOK_ASCIIZ }, + { ".ASSERT", TOK_ASSERT }, + { ".AUTOIMPORT", TOK_AUTOIMPORT }, + { ".BANK", TOK_BANK }, + { ".BANKBYTE", TOK_BANKBYTE }, + { ".BANKBYTES", TOK_BANKBYTES }, + { ".BITAND", TOK_AND }, + { ".BITNOT", TOK_NOT }, + { ".BITOR", TOK_OR }, + { ".BITXOR", TOK_XOR }, + { ".BLANK", TOK_BLANK }, + { ".BSS", TOK_BSS }, + { ".BYT", TOK_BYTE }, + { ".BYTE", TOK_BYTE }, + { ".CASE", TOK_CASE }, + { ".CHARMAP", TOK_CHARMAP }, + { ".CODE", TOK_CODE }, + { ".CONCAT", TOK_CONCAT }, + { ".CONDES", TOK_CONDES }, + { ".CONST", TOK_CONST }, + { ".CONSTRUCTOR", TOK_CONSTRUCTOR }, + { ".CPU", TOK_CPU }, + { ".DATA", TOK_DATA }, + { ".DBG", TOK_DBG }, + { ".DBYT", TOK_DBYT }, + { ".DEBUGINFO", TOK_DEBUGINFO }, + { ".DEF", TOK_DEFINED }, + { ".DEFINE", TOK_DEFINE }, + { ".DEFINED", TOK_DEFINED }, + { ".DEFINEDMACRO", TOK_DEFINEDMACRO }, + { ".DELMAC", TOK_DELMAC }, + { ".DELMACRO", TOK_DELMAC }, + { ".DESTRUCTOR", TOK_DESTRUCTOR }, + { ".DWORD", TOK_DWORD }, + { ".ELSE", TOK_ELSE }, + { ".ELSEIF", TOK_ELSEIF }, + { ".END", TOK_END }, + { ".ENDENUM", TOK_ENDENUM }, + { ".ENDIF", TOK_ENDIF }, + { ".ENDMAC", TOK_ENDMACRO }, + { ".ENDMACRO", TOK_ENDMACRO }, + { ".ENDPROC", TOK_ENDPROC }, + { ".ENDREP", TOK_ENDREP }, + { ".ENDREPEAT", TOK_ENDREP }, + { ".ENDSCOPE", TOK_ENDSCOPE }, + { ".ENDSTRUCT", TOK_ENDSTRUCT }, + { ".ENDUNION", TOK_ENDUNION }, + { ".ENUM", TOK_ENUM }, + { ".ERROR", TOK_ERROR }, + { ".EXITMAC", TOK_EXITMACRO }, + { ".EXITMACRO", TOK_EXITMACRO }, + { ".EXPORT", TOK_EXPORT }, + { ".EXPORTZP", TOK_EXPORTZP }, + { ".FARADDR", TOK_FARADDR }, + { ".FATAL", TOK_FATAL }, + { ".FEATURE", TOK_FEATURE }, + { ".FILEOPT", TOK_FILEOPT }, + { ".FOPT", TOK_FILEOPT }, + { ".FORCEIMPORT", TOK_FORCEIMPORT }, + { ".FORCEWORD", TOK_FORCEWORD }, + { ".GLOBAL", TOK_GLOBAL }, + { ".GLOBALZP", TOK_GLOBALZP }, + { ".HIBYTE", TOK_HIBYTE }, + { ".HIBYTES", TOK_HIBYTES }, + { ".HIWORD", TOK_HIWORD }, + { ".I16", TOK_I16 }, + { ".I8", TOK_I8 }, + { ".IDENT", TOK_MAKEIDENT }, + { ".IF", TOK_IF }, + { ".IFBLANK", TOK_IFBLANK }, + { ".IFCONST", TOK_IFCONST }, + { ".IFDEF", TOK_IFDEF }, + { ".IFNBLANK", TOK_IFNBLANK }, + { ".IFNCONST", TOK_IFNCONST }, + { ".IFNDEF", TOK_IFNDEF }, + { ".IFNREF", TOK_IFNREF }, + { ".IFP02", TOK_IFP02 }, + { ".IFP816", TOK_IFP816 }, + { ".IFPC02", TOK_IFPC02 }, + { ".IFPSC02", TOK_IFPSC02 }, + { ".IFREF", TOK_IFREF }, + { ".IMPORT", TOK_IMPORT }, + { ".IMPORTZP", TOK_IMPORTZP }, + { ".INCBIN", TOK_INCBIN }, + { ".INCLUDE", TOK_INCLUDE }, + { ".INTERRUPTOR", TOK_INTERRUPTOR }, + { ".ISMNEM", TOK_ISMNEMONIC }, + { ".ISMNEMONIC", TOK_ISMNEMONIC }, + { ".LEFT", TOK_LEFT }, + { ".LINECONT", TOK_LINECONT }, + { ".LIST", TOK_LIST }, + { ".LISTBYTES", TOK_LISTBYTES }, + { ".LOBYTE", TOK_LOBYTE }, + { ".LOBYTES", TOK_LOBYTES }, + { ".LOCAL", TOK_LOCAL }, + { ".LOCALCHAR", TOK_LOCALCHAR }, + { ".LOWORD", TOK_LOWORD }, + { ".MAC", TOK_MACRO }, + { ".MACPACK", TOK_MACPACK }, + { ".MACRO", TOK_MACRO }, + { ".MATCH", TOK_MATCH }, + { ".MAX", TOK_MAX }, + { ".MID", TOK_MID }, + { ".MIN", TOK_MIN }, + { ".MOD", TOK_MOD }, + { ".NOT", TOK_BOOLNOT }, + { ".NULL", TOK_NULL }, + { ".OR", TOK_BOOLOR }, + { ".ORG", TOK_ORG }, + { ".OUT", TOK_OUT }, + { ".P02", TOK_P02 }, + { ".P816", TOK_P816 }, + { ".PAGELEN", TOK_PAGELENGTH }, + { ".PAGELENGTH", TOK_PAGELENGTH }, + { ".PARAMCOUNT", TOK_PARAMCOUNT }, + { ".PC02", TOK_PC02 }, + { ".POPCPU", TOK_POPCPU }, + { ".POPSEG", TOK_POPSEG }, + { ".PROC", TOK_PROC }, + { ".PSC02", TOK_PSC02 }, + { ".PUSHCPU", TOK_PUSHCPU }, + { ".PUSHSEG", TOK_PUSHSEG }, + { ".REF", TOK_REFERENCED }, + { ".REFERENCED", TOK_REFERENCED }, + { ".RELOC", TOK_RELOC }, + { ".REPEAT", TOK_REPEAT }, + { ".RES", TOK_RES }, + { ".RIGHT", TOK_RIGHT }, + { ".RODATA", TOK_RODATA }, + { ".SCOPE", TOK_SCOPE }, + { ".SEGMENT", TOK_SEGMENT }, + { ".SET", TOK_SET }, + { ".SETCPU", TOK_SETCPU }, + { ".SHL", TOK_SHL }, + { ".SHR", TOK_SHR }, + { ".SIZEOF", TOK_SIZEOF }, + { ".SMART", TOK_SMART }, + { ".SPRINTF", TOK_SPRINTF }, + { ".STRAT", TOK_STRAT }, + { ".STRING", TOK_STRING }, + { ".STRLEN", TOK_STRLEN }, + { ".STRUCT", TOK_STRUCT }, + { ".TAG", TOK_TAG }, + { ".TCOUNT", TOK_TCOUNT }, + { ".TIME", TOK_TIME }, + { ".UNDEF", TOK_UNDEF }, + { ".UNDEFINE", TOK_UNDEF }, + { ".UNION", TOK_UNION }, + { ".VERSION", TOK_VERSION }, + { ".WARNING", TOK_WARNING }, + { ".WORD", TOK_WORD }, + { ".XMATCH", TOK_XMATCH }, + { ".XOR", TOK_BOOLXOR }, + { ".ZEROPAGE", TOK_ZEROPAGE }, }; diff --git a/src/ca65/token.h b/src/ca65/token.h index 5ffe42466..b0264f154 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -148,6 +148,7 @@ typedef enum token_t { TOK_DEBUGINFO, TOK_DEFINE, TOK_DEFINED, + TOK_DEFINEDMACRO, TOK_DELMAC, TOK_DESTRUCTOR, TOK_DWORD, From 72e4c10772fe7bf008ff6ed9c34d17b8935f593a Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 29 Jun 2015 01:57:39 +0200 Subject: [PATCH 162/351] added 3 more test --- test/misc/Makefile | 4 +++ test/misc/cc65141011.c | 52 ++++++++++++++++++++++++++++++++++++++ test/val/cc65141002.c | 45 +++++++++++++++++++++++++++++++++ test/val/cc65141022.c | 57 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+) create mode 100755 test/misc/cc65141011.c create mode 100755 test/val/cc65141002.c create mode 100755 test/val/cc65141022.c diff --git a/test/misc/Makefile b/test/misc/Makefile index e5fd6d2b8..db643b44c 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -52,6 +52,10 @@ $(WORKDIR)/sitest%prg: sitest.c @echo "FIXME: " $@ "currently will fail." -$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ # -$(SIM65) $(SIM65FLAGS) $@ +$(WORKDIR)/cc65141011%prg: cc65141011.c + @echo "FIXME: " $@ "currently will fail." + $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ + -$(SIM65) $(SIM65FLAGS) $@ clean: -@$(call DEL,$(TESTS)) diff --git a/test/misc/cc65141011.c b/test/misc/cc65141011.c new file mode 100755 index 000000000..0ee35dc09 --- /dev/null +++ b/test/misc/cc65141011.c @@ -0,0 +1,52 @@ + +/* + !!DESCRIPTION!! equality problem + !!ORIGIN!! Testsuite + !!LICENCE!! Public Domain +*/ + +/* + different result depending on whether constant is on left or right side + + http://www.cc65.org/mailarchive/2014-10/11680.html + http://www.cc65.org/mailarchive/2014-10/11683.html +*/ + +#include <stdlib.h> +#include <stdio.h> + +static unsigned char fails = 4; +static unsigned char bad[3], good[3]; + +int main(int n, char **args) +{ + unsigned char joy_state = 0x7e; + unsigned a, b; + + /* NOTE: somehow it only fails in the printf statement, the other stuff + below works! */ + printf("bad: %u\n", 0 == (joy_state & 1) ); + printf("good: %u\n", (joy_state & 1) == 0 ); + + sprintf(bad, "%u", 0 == (joy_state & 1) ); + sprintf(good, "%u", (joy_state & 1) == 0 ); + + printf("bad: %u\n", bad[0] - '0' ); + printf("good: %u\n", good[0] - '0' ); + + fails -= bad[0] - '0'; + fails -= good[0] - '0'; + + if (0 == (joy_state & 1)) fails--; + if ((joy_state & 1) == 0) fails--; + + printf("fails: %u\n", fails ); + + a = 0 == (joy_state & 1); + b = (joy_state & 1) == 0; + + printf("a: %u\n", a ); + printf("b: %u\n", b ); + + return fails; +} diff --git a/test/val/cc65141002.c b/test/val/cc65141002.c new file mode 100755 index 000000000..ae5cd3d5f --- /dev/null +++ b/test/val/cc65141002.c @@ -0,0 +1,45 @@ + +/* + !!DESCRIPTION!! forgetting to emit labels + !!ORIGIN!! Testsuite + !!LICENCE!! Public Domain +*/ + +/* + http://www.cc65.org/mailarchive/2014-10/11673.html + http://www.cc65.org/mailarchive/2014-10/11675.html +*/ + +#include <stdlib.h> +#include <stdio.h> + +struct udata { + int (*u_sigvec[16])(); + int u_argn; + int u_argn1; +}; + +struct udata udata; + +#define sig (int)udata.u_argn +#define func (int (*)())udata.u_argn1 + +int _signal(void) +{ + if (func != 0) { + goto nogood; + } + udata.u_sigvec[sig] = func; + return 0; + +nogood: + return (-1); +} + +int main(int n,char **args) +{ + _signal(); + printf("it works\n"); + + return 0; +} diff --git a/test/val/cc65141022.c b/test/val/cc65141022.c new file mode 100755 index 000000000..d5aadd240 --- /dev/null +++ b/test/val/cc65141022.c @@ -0,0 +1,57 @@ + +/* + !!DESCRIPTION!! struct base address dereferencing bug + !!ORIGIN!! Testsuite + !!LICENCE!! Public Domain +*/ + +#include <stdlib.h> +#include <stdio.h> + +struct yywork +{ + char verify, advance; +} yycrank[] = +{ + {0,0} +}; + +struct yysvf +{ + struct yywork *yystoff; +}; + +unsigned char fails = 0; + +int main(int n, char **args) +{ + struct yysvf *yystate; + struct yywork *yyt; + + yystate->yystoff = yycrank; + yyt = yystate->yystoff; + + if(yyt == yycrank) { + printf("yyt == yycrank (ok)\n"); + } else { + printf("yyt != yycrank (fail)\n"); + ++fails; + } + + if(yyt == yystate->yystoff) { + printf("yyt == yystate->yystoff (ok)\n"); + } else { + printf("yyt != yystate->yystoff (fail)\n"); + ++fails; + } + + if(yycrank == yystate->yystoff) { + printf("yycrank == yystate->yystoff (ok)\n"); + } else { + printf("yycrank != yystate->yystoff (fail)\n"); + ++fails; + } + + printf("fails: %d\n", fails); + return fails; +} From 5b1917d23f12ced98a019ccaf65c323760663c89 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 29 Jun 2015 02:34:12 +0200 Subject: [PATCH 163/351] remove workaround for optimizer bug --- test/ref/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/ref/Makefile b/test/ref/Makefile index de9248ac7..2e7675b95 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -49,8 +49,8 @@ $(WORKDIR)/switch.%rg: CC65FLAGS += -Wc --all-cdecl # Also, yacc.c does some things that fail when stack operations are optimized. # Therefore, don't optimize them. # -$(WORKDIR)/yacc.%rg: CC65FLAGS += -Wc --all-cdecl,--disable-opt,OptStackOps -$(WORKDIR)/yaccdbg%prg: CC65FLAGS += -Wc --all-cdecl,--disable-opt,OptStackOps +$(WORKDIR)/yacc.%rg: CC65FLAGS += -Wc --all-cdecl +$(WORKDIR)/yaccdbg%prg: CC65FLAGS += -Wc --all-cdecl $(WORKDIR)/%.prg: %.c $(WORKDIR)/%.ref $(CL65) $(CC65FLAGS) $< -o $@ From 18b2de16242e563b07a8bebc830d8387c4e6aff2 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 29 Jun 2015 11:18:24 +0200 Subject: [PATCH 164/351] remove comment --- test/ref/Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/ref/Makefile b/test/ref/Makefile index 2e7675b95..14d78c37c 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -45,10 +45,6 @@ $(WORKDIR)/%.ref: %.c # $(WORKDIR)/init%prg: CC65FLAGS += -Wc --all-cdecl $(WORKDIR)/switch.%rg: CC65FLAGS += -Wc --all-cdecl - -# Also, yacc.c does some things that fail when stack operations are optimized. -# Therefore, don't optimize them. -# $(WORKDIR)/yacc.%rg: CC65FLAGS += -Wc --all-cdecl $(WORKDIR)/yaccdbg%prg: CC65FLAGS += -Wc --all-cdecl From cd5935deb77951521ed88aae52933f9a94f94830 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 30 Jun 2015 08:54:13 -0400 Subject: [PATCH 165/351] Fixed an uninitiated pointer. --- test/val/cc65141022.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/val/cc65141022.c b/test/val/cc65141022.c index d5aadd240..1d7792cf2 100755 --- a/test/val/cc65141022.c +++ b/test/val/cc65141022.c @@ -19,13 +19,13 @@ struct yywork struct yysvf { struct yywork *yystoff; -}; +} yysvec[1]; unsigned char fails = 0; int main(int n, char **args) { - struct yysvf *yystate; + struct yysvf *yystate = yysvec; struct yywork *yyt; yystate->yystoff = yycrank; From 5d4900e1790db541d5c312c2fa68029649a0fd86 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 30 Jun 2015 09:00:28 -0400 Subject: [PATCH 166/351] Added comments that explain the unstable behavior of a test program. --- test/misc/Makefile | 2 +- test/misc/cc65141011.c | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/test/misc/Makefile b/test/misc/Makefile index db643b44c..ca4870663 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -53,7 +53,7 @@ $(WORKDIR)/sitest%prg: sitest.c -$(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ # -$(SIM65) $(SIM65FLAGS) $@ $(WORKDIR)/cc65141011%prg: cc65141011.c - @echo "FIXME: " $@ "currently will fail." + @echo "FIXME: " $@ "currently can fail." $(CL65) $(subst .,,$(*:.o%=-O%)) $(CC65FLAGS) $< -o $@ -$(SIM65) $(SIM65FLAGS) $@ diff --git a/test/misc/cc65141011.c b/test/misc/cc65141011.c index 0ee35dc09..26cef7099 100755 --- a/test/misc/cc65141011.c +++ b/test/misc/cc65141011.c @@ -1,4 +1,3 @@ - /* !!DESCRIPTION!! equality problem !!ORIGIN!! Testsuite @@ -6,32 +5,37 @@ */ /* - different result depending on whether constant is on left or right side + Different results, depending on whether constant is on left or right side. + + The optimizer sometimes makes code that executes the right-side expression + as eight bits; but then, tests it against the left-side zero as 16 bits. + The high-byte is garbage; therefore, that test might, or might not, work. + It depends on the platform and the amount of optimization. http://www.cc65.org/mailarchive/2014-10/11680.html + http://www.cc65.org/mailarchive/2014-10/11682.html http://www.cc65.org/mailarchive/2014-10/11683.html */ -#include <stdlib.h> #include <stdio.h> static unsigned char fails = 4; static unsigned char bad[3], good[3]; -int main(int n, char **args) +int main(void) { unsigned char joy_state = 0x7e; unsigned a, b; - /* NOTE: somehow it only fails in the printf statement, the other stuff + /* NOTE: It fails in only the printf() statements, the other stuff below works! */ - printf("bad: %u\n", 0 == (joy_state & 1) ); + printf("bad: %u, ", 0 == (joy_state & 1) ); printf("good: %u\n", (joy_state & 1) == 0 ); sprintf(bad, "%u", 0 == (joy_state & 1) ); sprintf(good, "%u", (joy_state & 1) == 0 ); - printf("bad: %u\n", bad[0] - '0' ); + printf("bad: %u, ", bad[0] - '0' ); printf("good: %u\n", good[0] - '0' ); fails -= bad[0] - '0'; @@ -40,12 +44,15 @@ int main(int n, char **args) if (0 == (joy_state & 1)) fails--; if ((joy_state & 1) == 0) fails--; - printf("fails: %u\n", fails ); + printf("failures: %u\n", fails ); + /* The above printf() returns a value with a zero high-byte. + ** Therefore, the next (broken) statement works (by accident). + */ a = 0 == (joy_state & 1); b = (joy_state & 1) == 0; - printf("a: %u\n", a ); + printf("a: %u, ", a ); printf("b: %u\n", b ); return fails; From 0e6008e9e6dfd312dd6c8f6e4b514728943b6e35 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 1 Jul 2015 06:54:05 -0400 Subject: [PATCH 167/351] Added a regression test for pointer-to-array dereferences. --- test/val/pointed-array.c | 91 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 test/val/pointed-array.c diff --git a/test/val/pointed-array.c b/test/val/pointed-array.c new file mode 100644 index 000000000..ddbc1a502 --- /dev/null +++ b/test/val/pointed-array.c @@ -0,0 +1,91 @@ +/* +** !!DESCRIPTION!! Simple tests of pointer-to-array dereferences +** !!ORIGIN!! cc65 regression tests +** !!LICENCE!! Public Domain +** !!AUTHOR!! 2015-06-29, Greg King +*/ + +#include <stdio.h> + +static unsigned char failures = 0; +static size_t Size; + +typedef unsigned char array_t[4][4]; + +static array_t table = { + {12, 13, 14, 15}, + { 8, 9, 10, 11}, + { 4, 5, 6, 7}, + { 0, 1, 2, 3} +}; +static array_t *tablePtr = &table; + +static unsigned (*vector)[2]; + +static unsigned char y = 0, x; + +int main(void) +{ + /* The indirection must convert the expression-type (from Pointer into + ** Array); but, it must not convert the value, because it already points + ** to the start of the array. + */ + /* (Note: I reduce output clutter by using a variable to prevent + ** compiler warnings about constant comparisons and unreachable code. + */ + if ((Size = sizeof *tablePtr) != sizeof table) { + ++failures; + } + if (*tablePtr != table) { + ++failures; + } + + /* Test fetching. */ + do { + x = 0; + do { + if ((*tablePtr)[y][x] != table[y][x]) { + ++failures; + printf("(*tableptr)[%u][%u] (%u) != table[%u][%u] (%u).\n", + y, x, (*tablePtr)[y][x], + y, x, table[y][x]); + } + } while (++x < sizeof table[0]); + } while (++y < sizeof table / sizeof table[0]); + + vector = (unsigned (*)[])table[1]; + if ((*vector)[1] != 0x0B0A) { + ++failures; + } + + /* Test storing. */ + (*tablePtr)[2][1] = 42; + if (table[2][1] != 42) { + ++failures; + printf("table[2][1] == %u (should have changed from 5 to 42).\n", + table[2][1]); + } + x = 3; + y = 1; + (*tablePtr)[y][x] = 83; + if (table[1][3] != 83) { + ++failures; + printf("table[y][x] == %u (should have changed from 11 to 83).\n", + table[1][3]); + } + + /* Test triple indirection. It should compile to two indirection + ** operations. + */ + --***tablePtr; + if (**table != 11) { + ++failures; + printf("**table == %u (should have changed from 12 to 11).\n", + table[0][0]); + } + + if (failures != 0) { + printf("failures: %u\n", failures); + } + return failures; +} From 8189339e7d132f388fed6e5ba2265ae0ff789671 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 1 Jul 2015 06:55:57 -0400 Subject: [PATCH 168/351] Added special-case compiler code that handles a pointer-to-array dereference. The type needs to change (to array); but, the address shouldn't be changed -- it already points to the first element. Based on a bug analysis by Daniel Serpell. --- src/cc65/expr.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index d615993c4..7563645ff 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1,7 +1,7 @@ /* expr.c ** ** 1998-06-21, Ullrich von Bassewitz -** 2015-04-19, Greg King +** 2015-06-26, Greg King */ @@ -1713,8 +1713,13 @@ void hie10 (ExprDesc* Expr) } else { Error ("Illegal indirection"); } - /* The * operator yields an lvalue */ - ED_MakeLVal (Expr); + /* If the expression points to an array, then don't convert the + ** address -- it already is the location of the first element. + */ + if (!IsTypeArray (Expr->Type)) { + /* The * operator yields an lvalue */ + ED_MakeLVal (Expr); + } } break; From ba03d2873139ac93b081afb5b687cb20efa5b218 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 1 Jul 2015 10:07:40 -0400 Subject: [PATCH 169/351] Removed some trailing whitespace; and, expanded a tab. --- test/val/pointed-array.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/val/pointed-array.c b/test/val/pointed-array.c index ddbc1a502..3390ac94b 100644 --- a/test/val/pointed-array.c +++ b/test/val/pointed-array.c @@ -52,10 +52,10 @@ int main(void) } } while (++x < sizeof table[0]); } while (++y < sizeof table / sizeof table[0]); - + vector = (unsigned (*)[])table[1]; if ((*vector)[1] != 0x0B0A) { - ++failures; + ++failures; } /* Test storing. */ From 219905c6bcecfda2ae9724a44653831ccb6f6271 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 9 Jul 2015 10:28:38 -0400 Subject: [PATCH 170/351] Fix two string output functions' handling of their buffer-size parameter. That parameter's type is unsigned; but, the functions return an int. If the size is too big for a signed integer, then return an error code. If the size is zero, then don't write anything into a buffer (the buffer pointer may be NULL). But, do format and count the arguments. --- libsrc/common/vsnprintf.s | 47 +++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/libsrc/common/vsnprintf.s b/libsrc/common/vsnprintf.s index a8ed50e06..94ad072ca 100644 --- a/libsrc/common/vsnprintf.s +++ b/libsrc/common/vsnprintf.s @@ -1,7 +1,8 @@ ; ; int __fastcall__ vsnprintf (char* Buf, size_t size, const char* Format, va_list ap); ; -; Ullrich von Bassewitz, 2009-09-26 +; 2009-09-26, Ullrich von Bassewitz +; 2015-07-09, Greg King ; .export _vsnprintf, vsnprintf @@ -9,6 +10,8 @@ .import _memcpy, __printf .importzp sp, ptr1 + .include "errno.inc" + .macpack generic .data @@ -46,8 +49,10 @@ vsnprintf: sta ccount+1 ; Clear ccount ; Get the size parameter and replace it by a pointer to outdesc. This is to -; build a stack frame for the call to _printf. -; If size is zero, there's nothing to do. +; build a stack frame for the call to _printf. The size must not be greater +; than INT_MAX because the return type is int. If the size is zero, +; then nothing will be written into the buffer; but, the arguments still will +; be formatted and counted. ldy #2 lda (sp),y @@ -58,15 +63,13 @@ vsnprintf: iny lda (sp),y + bmi L9 ; More than $7FFF sta ptr1+1 - ora ptr1 - beq L9 - lda #>outdesc sta (sp),y -; Write size-1 to outdesc.uns +; Write size-1 to outdesc.uns. It will be -1 if there is no buffer. ldy ptr1+1 ldx ptr1 @@ -90,17 +93,18 @@ L1: dex pla jsr __printf -; Terminate the string. The last char is either at bufptr+ccount or -; bufptr+bufsize, whichever is smaller. +; Terminate the string if there is a buffer. The last char. is at either +; bufptr+bufsize or bufptr+ccount, whichever is smaller. + ldx bufsize+1 + bmi L4 ; -1 -- No buffer + lda bufsize+0 + cpx ccount+1 + bne L2 + cmp ccount+0 +L2: bcc L3 lda ccount+0 ldx ccount+1 - cpx bufsize+1 - bne L2 - cmp bufsize+0 -L2: bcc L3 - lda bufsize+0 - ldx bufsize+1 clc L3: adc bufptr+0 sta ptr1 @@ -114,16 +118,14 @@ L3: adc bufptr+0 ; Return the number of bytes written and drop buf - lda ccount+0 +L4: lda ccount+0 ldx ccount+1 jmp incsp2 -; Bail out if size is zero. +; Bail out if size is too high. -L9: pla - pla ; Discard ap - lda #0 - tax +L9: lda #ERANGE + jsr __directerrno ; Return -1 jmp incsp6 ; Drop parameters @@ -146,10 +148,11 @@ out: sbc ccount+0 ; Low byte of bytes already written sta ptr1 lda bufsize+1 + bmi @L9 ; -1 -- No buffer sbc ccount+1 sta ptr1+1 bcs @L0 ; Branch if space left - lda #$00 +@L9: lda #$0000 sta ptr1 sta ptr1+1 ; No space left From 28d65d595da1a7774e60e5d9b574f31bdcd2b0ed Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 9 Jul 2015 17:36:12 +0200 Subject: [PATCH 171/351] two more tests --- test/val/add3a.c | 73 +++++++++++++++++++++++++++++++++++++++++++ test/val/casttochar.c | 49 +++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100755 test/val/add3a.c create mode 100755 test/val/casttochar.c diff --git a/test/val/add3a.c b/test/val/add3a.c new file mode 100755 index 000000000..4ca32d06b --- /dev/null +++ b/test/val/add3a.c @@ -0,0 +1,73 @@ + +/* + !!DESCRIPTION!! Addition tests - mostly int's + !!ORIGIN!! SDCC regression tests + !!LICENCE!! GPL, read COPYING.GPL +*/ + +#include <stdio.h> +#include <stdlib.h> + +static unsigned int failures = 0; + +/* + this test assumes: + sizeof(long) == 4 + + CAUTION: the wraparound behaviour is actually undefined, to get the "expected" + behaviour with GCC, use -fwrapv or -fno-strict-overflow + + see: https://gcc.gnu.org/wiki/FAQ#signed_overflow +*/ + +#ifdef REFERENCE + +/* + make sure the reference output uses types with + proper size +*/ + +#include <stdint.h> + +int32_t long0 = 0; + +#else + +long long0 = 0; + +#endif + +void print(void) +{ +#if defined(REFERENCE) && defined(REFCC_SIZEOF_LONG_64BIT) + printf("long0: %d\n", long0); +#else + printf("long0: %ld\n", long0); +#endif +} + +int main(void) +{ + long0 = 0x7f000000L; + /* wrap around zero */ + print(); + long0 = long0 + 0x2000000L; + if(long0 != -0x7f000000L) { + printf("failed!\n"); + failures++; + } + print(); + + long0 = 0x7f000000L; + /* wrap around zero */ + print(); + long0 = long0 + 0x2000000L; + print(); + if(long0 != -0x7f000000L) { + printf("failed!\n"); + failures++; + } + print(); + + return failures; +} diff --git a/test/val/casttochar.c b/test/val/casttochar.c new file mode 100755 index 000000000..d492f6bb8 --- /dev/null +++ b/test/val/casttochar.c @@ -0,0 +1,49 @@ + +/* + !!DESCRIPTION!! Cast to char + !!ORIGIN!! Piotr Fusik + !!LICENCE!! PD +*/ + +#include <stdio.h> +#include <stdlib.h> + +static unsigned int failures = 0; + +int f1(int i, int j) { + return (signed char) (i + 1) == j; +} + +int f2(int i, int j) { + return (unsigned char) (i + 1) == j; +} + +int f3(int i, int j) { + return (char) (i + 1) == j; +} + +int main(void) +{ + printf("f1: got :%04x ", f1(0x1234, 0x35)); + if(f1(0x1234, 0x35) == 0) { + printf("- failed"); + failures++; + } + printf("\n"); + + printf("f2: got :%04x ", f2(0x1234, 0x35)); + if(f2(0x1234, 0x35) == 0) { + printf("- failed"); + failures++; + } + printf("\n"); + + printf("f3: got :%04x ", f3(0x1234, 0x35)); + if(f3(0x1234, 0x35) == 0) { + printf("- failed"); + failures++; + } + printf("\n"); + + return failures; +} From 146daa1d0a43883bfa22ddfbb571b3d649c6465e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 9 Jul 2015 14:46:28 -0400 Subject: [PATCH 172/351] Made some string output functions reject an invalid NULL buffer pointer. --- libsrc/common/vsnprintf.s | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libsrc/common/vsnprintf.s b/libsrc/common/vsnprintf.s index 94ad072ca..01bcd6406 100644 --- a/libsrc/common/vsnprintf.s +++ b/libsrc/common/vsnprintf.s @@ -86,9 +86,16 @@ L1: dex sta bufptr+0 stx bufptr+1 +; There must be a buffer if its size is non-zero. + + bit bufsize+1 + bmi L5 + ora bufptr+1 + bze L0 ; The pointer shouldn't be NULL + ; Restore ap and call _printf - pla +L5: pla tax pla jsr __printf @@ -125,6 +132,11 @@ L4: lda ccount+0 ; Bail out if size is too high. L9: lda #ERANGE + .byte $2C ;(bit $xxxx) + +; NULL buffer pointers usually are invalid. + +L0: lda #EINVAL jsr __directerrno ; Return -1 jmp incsp6 ; Drop parameters From 6970053023524caf75ad9b9873acbd320c1c3c87 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 10 Jul 2015 10:43:00 +0200 Subject: [PATCH 173/351] use rm -r instead of rmdir, and use -f for rm, that makes subsequent runs of "make clean" not fail --- test/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Makefile b/test/Makefile index 8c005a957..d2ad2ee94 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,9 +16,9 @@ ifdef CMD_EXE RMDIR = rmdir /s /q $(subst /,\,$1) else EXE := - DEL = $(RM) $1 + DEL = $(RM) -f $1 MKDIR = mkdir $1 - RMDIR = rmdir $1 + RMDIR = $(RM) -rf $1 endif WORKDIR := ../testwrk From ad97b1b08e0e389a12bdb998afc1402bac7f0aa6 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 10 Jul 2015 11:11:41 +0200 Subject: [PATCH 174/351] removed -f again, as that is the default. also removed "-" before the actual comments, which were the workaround previously --- test/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Makefile b/test/Makefile index d2ad2ee94..eb968095a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,9 +16,9 @@ ifdef CMD_EXE RMDIR = rmdir /s /q $(subst /,\,$1) else EXE := - DEL = $(RM) -f $1 + DEL = $(RM) $1 MKDIR = mkdir $1 - RMDIR = $(RM) -rf $1 + RMDIR = $(RM) -r $1 endif WORKDIR := ../testwrk @@ -52,5 +52,5 @@ mostly-clean: @$(MAKE) -C misc clean clean: mostly-clean - -@$(call DEL,$(WORKDIR)/bdiff$(EXE)) - -@$(call RMDIR,$(WORKDIR)) + @$(call DEL,$(WORKDIR)/bdiff$(EXE)) + @$(call RMDIR,$(WORKDIR)) From 6ab197f364571f370604bb10b68e54dc5ecdd208 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 10 Jul 2015 14:27:49 +0200 Subject: [PATCH 175/351] patch from Uz that makes some illegal operations on pointers error out --- src/cc65/datatype.c | 7 ++++++- src/cc65/expr.c | 49 +++++++++++++++++++++++++++++++++++++++---- test/val/cc65150311.c | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 test/val/cc65150311.c diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 9971a9569..8c9d6dcb0 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -391,6 +391,12 @@ unsigned SizeOf (const Type* T) case T_VOID: return 0; /* Assume voids have size zero */ + /* Beware: There's a chance that this triggers problems in other parts + of the compiler. The solution is to fix the callers, because calling + SizeOf() with a function type as argument is bad. */ + case T_FUNC: + return 0; /* Size of function is unknown */ + case T_SCHAR: case T_UCHAR: return SIZEOF_CHAR; @@ -404,7 +410,6 @@ unsigned SizeOf (const Type* T) return SIZEOF_INT; case T_PTR: - case T_FUNC: /* Maybe pointer to function */ return SIZEOF_PTR; case T_LONG: diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 7563645ff..b82dff10d 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -50,6 +50,7 @@ /* Generator attributes */ #define GEN_NOPUSH 0x01 /* Don't push lhs */ #define GEN_COMM 0x02 /* Operator is commutative */ +#define GEN_NOFUNC 0x04 /* Not allowed for function pointers */ /* Map a generator function and its attributes to a token */ typedef struct { @@ -2042,6 +2043,11 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */ Tok = CurTok.Tok; NextToken (); + /* If lhs is a function, convert it to pointer to function */ + if (IsTypeFunc (Expr->Type)) { + Expr->Type = PointerTo (Expr->Type); + } + /* Get the lhs on stack */ GetCodePos (&Mark1); ltype = TypeOf (Expr->Type); @@ -2059,6 +2065,11 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */ /* Get the right hand side */ MarkedExprWithCheck (hienext, &Expr2); + /* If rhs is a function, convert it to pointer to function */ + if (IsTypeFunc (Expr2.Type)) { + Expr2.Type = PointerTo (Expr2.Type); + } + /* Check for a constant expression */ rconst = (ED_IsConstAbs (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)); if (!rconst) { @@ -2066,6 +2077,22 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */ LoadExpr (CF_NONE, &Expr2); } + /* Some operations aren't allowed on function pointers */ + if ((Gen->Flags & GEN_NOFUNC) != 0) { + /* Output only one message even if both sides are wrong */ + if (IsTypeFuncPtr (Expr->Type)) { + Error ("Invalid left operand for relational operator"); + /* Avoid further errors */ + ED_MakeConstAbsInt (Expr, 0); + ED_MakeConstAbsInt (&Expr2, 0); + } else if (IsTypeFuncPtr (Expr2.Type)) { + Error ("Invalid right operand for relational operator"); + /* Avoid further errors */ + ED_MakeConstAbsInt (Expr, 0); + ED_MakeConstAbsInt (&Expr2, 0); + } + } + /* Make sure, the types are compatible */ if (IsClassInt (Expr->Type)) { if (!IsClassInt (Expr2.Type) && !(IsClassPtr(Expr2.Type) && ED_IsNullPtr(Expr))) { @@ -2600,6 +2627,13 @@ static void parsesub (ExprDesc* Expr) int rscale; /* Scale factor for the result */ + /* lhs cannot be function or pointer to function */ + if (IsTypeFunc (Expr->Type) || IsTypeFuncPtr (Expr->Type)) { + Error ("Invalid left operand for binary operator `-'"); + /* Make it pointer to char to avoid further errors */ + Expr->Type = type_uchar; + } + /* Skip the MINUS token */ NextToken (); @@ -2616,6 +2650,13 @@ static void parsesub (ExprDesc* Expr) /* Parse the right hand side */ MarkedExprWithCheck (hie9, &Expr2); + /* rhs cannot be function or pointer to function */ + if (IsTypeFunc (Expr2.Type) || IsTypeFuncPtr (Expr2.Type)) { + Error ("Invalid right operand for binary operator `-'"); + /* Make it pointer to char to avoid further errors */ + Expr2.Type = type_uchar; + } + /* Check for a constant rhs expression */ if (ED_IsConstAbs (&Expr2) && ED_CodeRangeIsEmpty (&Expr2)) { @@ -2775,10 +2816,10 @@ static void hie6 (ExprDesc* Expr) /* Handle greater-than type comparators */ { static const GenDesc hie6_ops [] = { - { TOK_LT, GEN_NOPUSH, g_lt }, - { TOK_LE, GEN_NOPUSH, g_le }, - { TOK_GE, GEN_NOPUSH, g_ge }, - { TOK_GT, GEN_NOPUSH, g_gt }, + { TOK_LT, GEN_NOPUSH | GEN_NOFUNC, g_lt }, + { TOK_LE, GEN_NOPUSH | GEN_NOFUNC, g_le }, + { TOK_GE, GEN_NOPUSH | GEN_NOFUNC, g_ge }, + { TOK_GT, GEN_NOPUSH | GEN_NOFUNC, g_gt }, { TOK_INVALID, 0, 0 } }; hie_compare (hie6_ops, Expr, ShiftExpr); diff --git a/test/val/cc65150311.c b/test/val/cc65150311.c new file mode 100644 index 000000000..cd644f491 --- /dev/null +++ b/test/val/cc65150311.c @@ -0,0 +1,38 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + +/* the following are not valid C and should go into seperate tests that MUST fail */ +/* + ++p; + n = (p > &func); + n = (p > func); + n = func - func; + n = func - &func; + n = &func - func; + n = &func - &func; + n = p - &func; + n = p - func; + n = &func - p; + n = func - p; +*/ + return 0; +} From 12a3e6841c258faa66c269007f92529e742e23e0 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 10 Jul 2015 18:38:54 +0200 Subject: [PATCH 176/351] tests for illegal pointer operations that must always fail --- test/err/cc65150311-1.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-10.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-11.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-2.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-3.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-4.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-5.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-6.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-7.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-8.c | 26 ++++++++++++++++++++++++++ test/err/cc65150311-9.c | 26 ++++++++++++++++++++++++++ 11 files changed, 286 insertions(+) create mode 100644 test/err/cc65150311-1.c create mode 100644 test/err/cc65150311-10.c create mode 100644 test/err/cc65150311-11.c create mode 100644 test/err/cc65150311-2.c create mode 100644 test/err/cc65150311-3.c create mode 100644 test/err/cc65150311-4.c create mode 100644 test/err/cc65150311-5.c create mode 100644 test/err/cc65150311-6.c create mode 100644 test/err/cc65150311-7.c create mode 100644 test/err/cc65150311-8.c create mode 100644 test/err/cc65150311-9.c diff --git a/test/err/cc65150311-1.c b/test/err/cc65150311-1.c new file mode 100644 index 000000000..c4a836e39 --- /dev/null +++ b/test/err/cc65150311-1.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + ++p; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-10.c b/test/err/cc65150311-10.c new file mode 100644 index 000000000..14e14d4fd --- /dev/null +++ b/test/err/cc65150311-10.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = &func - p; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-11.c b/test/err/cc65150311-11.c new file mode 100644 index 000000000..ffc8c9a02 --- /dev/null +++ b/test/err/cc65150311-11.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = func - p; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-2.c b/test/err/cc65150311-2.c new file mode 100644 index 000000000..34c862ad8 --- /dev/null +++ b/test/err/cc65150311-2.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = (p > &func); /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-3.c b/test/err/cc65150311-3.c new file mode 100644 index 000000000..2bf8267a5 --- /dev/null +++ b/test/err/cc65150311-3.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = (p > func); /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-4.c b/test/err/cc65150311-4.c new file mode 100644 index 000000000..0a7f44ec0 --- /dev/null +++ b/test/err/cc65150311-4.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = func - func; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-5.c b/test/err/cc65150311-5.c new file mode 100644 index 000000000..41229ad67 --- /dev/null +++ b/test/err/cc65150311-5.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = func - &func; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-6.c b/test/err/cc65150311-6.c new file mode 100644 index 000000000..a08ab11d3 --- /dev/null +++ b/test/err/cc65150311-6.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = &func - func; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-7.c b/test/err/cc65150311-7.c new file mode 100644 index 000000000..71e6368f7 --- /dev/null +++ b/test/err/cc65150311-7.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = &func - &func; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-8.c b/test/err/cc65150311-8.c new file mode 100644 index 000000000..d18dc0b2d --- /dev/null +++ b/test/err/cc65150311-8.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = p - &func; /* invalid C */ + + return 0; +} diff --git a/test/err/cc65150311-9.c b/test/err/cc65150311-9.c new file mode 100644 index 000000000..8cf805b07 --- /dev/null +++ b/test/err/cc65150311-9.c @@ -0,0 +1,26 @@ +/* + !!DESCRIPTION!! function pointer bugs + !!ORIGIN!! testsuite + !!LICENCE!! Public Domain + !!AUTHOR!! Greg +*/ + +/* + see: http://www.cc65.org/mailarchive/2015-03/11726.html + and: http://www.cc65.org/mailarchive/2015-03/11734.html +*/ + +static int func(void) {return 0;} +static int (*p)(void); +static int n; + +int main(void) { + + p = func; + n = (p == &func); + n = (p == func); + + n = p - func; /* invalid C */ + + return 0; +} From 1380c68cf3e9a59677c53cec057fcbbf4c580b2a Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 10 Jul 2015 20:04:31 +0200 Subject: [PATCH 177/351] workaround for cmd.exe rmdir --- test/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index eb968095a..c13f2212d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -13,7 +13,8 @@ ifdef CMD_EXE EXE := .exe DEL = del /f $(subst /,\,$1) MKDIR = mkdir $(subst /,\,$1) - RMDIR = rmdir /s /q $(subst /,\,$1) + DIRLIST = $(strip $(foreach dir,$1,$(wildcard $(dir)))) + RMDIR = $(if $(DIRLIST),rmdir /s /q $(subst /,\,$(DIRLIST))) else EXE := DEL = $(RM) $1 From 992f0f03c5706fb91e60a8ebbcf5de2c79af68e9 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 10 Jul 2015 22:39:33 +0200 Subject: [PATCH 178/351] Ignore return values only with CMD.EXE. CMD.EXE considers file deletion commands not able to delete anything as there's nothing to delete as failed. Of course we don't want to bail out of the Makefile because of missing files to delete. Therefore we ignore the return values with '-'. This change limits this workaround to CMD.EXE. --- test/Makefile | 6 ++++-- test/err/Makefile | 6 ++++-- test/misc/Makefile | 8 +++++--- test/ref/Makefile | 12 +++++++----- test/val/Makefile | 6 ++++-- 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/test/Makefile b/test/Makefile index 8c005a957..95c9a9194 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,11 +10,13 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE + M := - EXE := .exe DEL = del /f $(subst /,\,$1) MKDIR = mkdir $(subst /,\,$1) RMDIR = rmdir /s /q $(subst /,\,$1) else + M := EXE := DEL = $(RM) $1 MKDIR = mkdir $1 @@ -52,5 +54,5 @@ mostly-clean: @$(MAKE) -C misc clean clean: mostly-clean - -@$(call DEL,$(WORKDIR)/bdiff$(EXE)) - -@$(call RMDIR,$(WORKDIR)) + $M@$(call DEL,$(WORKDIR)/bdiff$(EXE)) + $M@$(call RMDIR,$(WORKDIR)) diff --git a/test/err/Makefile b/test/err/Makefile index ff927ada0..6ac457114 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -6,9 +6,11 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE + M := - NOT := - # Hack DEL = del /f $(subst /,\,$1) else + M := NOT := ! DEL = $(RM) $1 endif @@ -44,5 +46,5 @@ $(WORKDIR)/%.or.prg: %.c $(NOT) $(CL65) -Or $(CC65FLAGS) $< -o $@ clean: - -@$(call DEL,$(TESTS)) - -@$(call DEL,$(SOURCES:.c=.o)) + $M@$(call DEL,$(TESTS)) + $M@$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/misc/Makefile b/test/misc/Makefile index ca4870663..dfd937ad3 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -6,10 +6,12 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE + M := - S := $(subst /,\,/) NOT := - # Hack DEL = del /f $(subst /,\,$1) else + M := S := / NOT := ! DEL = $(RM) $1 @@ -58,6 +60,6 @@ $(WORKDIR)/cc65141011%prg: cc65141011.c -$(SIM65) $(SIM65FLAGS) $@ clean: - -@$(call DEL,$(TESTS)) - -@$(call DEL,$(SOURCES:.c=.o)) - -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) + $M@$(call DEL,$(TESTS)) + $M@$(call DEL,$(SOURCES:.c=.o)) + $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) diff --git a/test/ref/Makefile b/test/ref/Makefile index 14d78c37c..83b81f9cc 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -7,9 +7,11 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE + M := - S := $(subst /,\,/) DEL = del /f $(subst /,\,$1) else + M := S := / DEL = $(RM) $1 endif @@ -89,8 +91,8 @@ $(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref clean: - -@$(call DEL,$(TESTS)) - -@$(call DEL,$(SOURCES:.c=.o)) - -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) - -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref)) - -@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host)) + $M@$(call DEL,$(TESTS)) + $M@$(call DEL,$(SOURCES:.c=.o)) + $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) + $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref)) + $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host)) diff --git a/test/val/Makefile b/test/val/Makefile index 4de47c6b5..b82d8fb51 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -6,8 +6,10 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE + M := - DEL = del /f $(subst /,\,$1) else + M := DEL = $(RM) $1 endif @@ -66,5 +68,5 @@ $(WORKDIR)/%.or.prg: %.c $(SIM65) $(SIM65FLAGS) $@ clean: - -@$(call DEL,$(TESTS)) - -@$(call DEL,$(SOURCES:.c=.o)) + $M@$(call DEL,$(TESTS)) + $M@$(call DEL,$(SOURCES:.c=.o)) From 50b0536222ee8cc417fdd7cb2bc2edb669a4a70b Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 11 Jul 2015 00:01:39 +0200 Subject: [PATCH 179/351] Ignore return values only with CMD.EXE MkII. CMD.EXE considers file deletion commands not able to delete anything as there's nothing to delete as failed. Of course we don't want to bail out of the Makefile because of missing files to delete. Therefore we ignore the return values with '-'. This change limits this workaround to CMD.EXE. --- test/Makefile | 10 ++++------ test/err/Makefile | 8 +++----- test/misc/Makefile | 10 ++++------ test/ref/Makefile | 14 ++++++-------- test/val/Makefile | 8 +++----- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/test/Makefile b/test/Makefile index 95c9a9194..702b332d5 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,13 +10,11 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - M := - EXE := .exe - DEL = del /f $(subst /,\,$1) + DEL = -del /f $(subst /,\,$1) MKDIR = mkdir $(subst /,\,$1) - RMDIR = rmdir /s /q $(subst /,\,$1) + RMDIR = -rmdir /s /q $(subst /,\,$1) else - M := EXE := DEL = $(RM) $1 MKDIR = mkdir $1 @@ -54,5 +52,5 @@ mostly-clean: @$(MAKE) -C misc clean clean: mostly-clean - $M@$(call DEL,$(WORKDIR)/bdiff$(EXE)) - $M@$(call RMDIR,$(WORKDIR)) + @$(call DEL,$(WORKDIR)/bdiff$(EXE)) + @$(call RMDIR,$(WORKDIR)) diff --git a/test/err/Makefile b/test/err/Makefile index 6ac457114..454a560ce 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -6,11 +6,9 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - M := - NOT := - # Hack - DEL = del /f $(subst /,\,$1) + DEL = -del /f $(subst /,\,$1) else - M := NOT := ! DEL = $(RM) $1 endif @@ -46,5 +44,5 @@ $(WORKDIR)/%.or.prg: %.c $(NOT) $(CL65) -Or $(CC65FLAGS) $< -o $@ clean: - $M@$(call DEL,$(TESTS)) - $M@$(call DEL,$(SOURCES:.c=.o)) + @$(call DEL,$(TESTS)) + @$(call DEL,$(SOURCES:.c=.o)) diff --git a/test/misc/Makefile b/test/misc/Makefile index dfd937ad3..918316c6c 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -6,12 +6,10 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - M := - S := $(subst /,\,/) NOT := - # Hack - DEL = del /f $(subst /,\,$1) + DEL = -del /f $(subst /,\,$1) else - M := S := / NOT := ! DEL = $(RM) $1 @@ -60,6 +58,6 @@ $(WORKDIR)/cc65141011%prg: cc65141011.c -$(SIM65) $(SIM65FLAGS) $@ clean: - $M@$(call DEL,$(TESTS)) - $M@$(call DEL,$(SOURCES:.c=.o)) - $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) + @$(call DEL,$(TESTS)) + @$(call DEL,$(SOURCES:.c=.o)) + @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) diff --git a/test/ref/Makefile b/test/ref/Makefile index 83b81f9cc..09dd96d44 100644 --- a/test/ref/Makefile +++ b/test/ref/Makefile @@ -7,11 +7,9 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - M := - S := $(subst /,\,/) - DEL = del /f $(subst /,\,$1) + DEL = -del /f $(subst /,\,$1) else - M := S := / DEL = $(RM) $1 endif @@ -91,8 +89,8 @@ $(WORKDIR)/%.or.prg: %.c $(WORKDIR)/%.ref $(DIFF) $(WORKDIR)/$*.out $(WORKDIR)/$*.ref clean: - $M@$(call DEL,$(TESTS)) - $M@$(call DEL,$(SOURCES:.c=.o)) - $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) - $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref)) - $M@$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host)) + @$(call DEL,$(TESTS)) + @$(call DEL,$(SOURCES:.c=.o)) + @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.out)) + @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.ref)) + @$(call DEL,$(SOURCES:%.c=$(WORKDIR)/%.host)) diff --git a/test/val/Makefile b/test/val/Makefile index b82d8fb51..4ad8160ef 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -6,10 +6,8 @@ ifneq ($(shell echo),) endif ifdef CMD_EXE - M := - - DEL = del /f $(subst /,\,$1) + DEL = -del /f $(subst /,\,$1) else - M := DEL = $(RM) $1 endif @@ -68,5 +66,5 @@ $(WORKDIR)/%.or.prg: %.c $(SIM65) $(SIM65FLAGS) $@ clean: - $M@$(call DEL,$(TESTS)) - $M@$(call DEL,$(SOURCES:.c=.o)) + @$(call DEL,$(TESTS)) + @$(call DEL,$(SOURCES:.c=.o)) From 55adf03bdf2ec3b3dbf654e98e84a5701eb7482d Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Sat, 11 Jul 2015 19:09:42 -0400 Subject: [PATCH 180/351] Move FuncIsMnemonic --- src/ca65/expr.c | 59 +++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 32653e980..0352b3c80 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -418,35 +418,6 @@ static ExprNode* FuncDefined (void) -static ExprNode* FuncIsMnemonic (void) -/* Handle the .ISMNEMONIC, .ISMNEM builtin function */ -{ - int Instr = -1; - - /* Check for a macro or an instruction depending on UbiquitousIdents */ - - if (CurTok.Tok == TOK_IDENT) { - if (UbiquitousIdents) { - /* Macros CAN be instructions, so check for them first */ - if (FindMacro (&CurTok.SVal) == 0) { - Instr = FindInstruction (&CurTok.SVal); - } - } else { - /* Macros and symbols may NOT use the names of instructions, so just check for the instruction */ - Instr = FindInstruction (&CurTok.SVal); - } - } - else { - Error ("Identifier expected."); - } - /* Skip the name */ - NextTok(); - - return GenLiteralExpr (Instr > 0); -} - - - static ExprNode* FuncDefinedMacro (void) /* Handle the .DEFINEDMACRO builtin function */ { @@ -483,6 +454,36 @@ static ExprNode* FuncHiWord (void) +static ExprNode* FuncIsMnemonic (void) +/* Handle the .ISMNEMONIC, .ISMNEM builtin function */ +{ + int Instr = -1; + + /* Check for a macro or an instruction depending on UbiquitousIdents */ + + if (CurTok.Tok == TOK_IDENT) { + if (UbiquitousIdents) { + /* Macros CAN be instructions, so check for them first */ + if (FindMacro (&CurTok.SVal) == 0) { + Instr = FindInstruction (&CurTok.SVal); + } + } + else { + /* Macros and symbols may NOT use the names of instructions, so just check for the instruction */ + Instr = FindInstruction (&CurTok.SVal); + } + } + else { + Error ("Identifier expected."); + } + /* Skip the name */ + NextTok (); + + return GenLiteralExpr (Instr > 0); +} + + + ExprNode* FuncLoByte (void) /* Handle the .LOBYTE builtin function */ { From 21999b081fb3b5e58266c01838de584a01819ce5 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 12 Jul 2015 10:32:55 +0200 Subject: [PATCH 181/351] simple conio test works again --- cfg/pce.cfg | 25 +++++---- libsrc/pce/_scrsize.s | 16 +++--- libsrc/pce/crt0.s | 128 ++++++++++++++++++++++-------------------- libsrc/pce/vce.s | 5 +- libsrc/pce/vdc.s | 14 ++--- libsrc/pce/vga.inc | 2 + 6 files changed, 96 insertions(+), 94 deletions(-) diff --git a/cfg/pce.cfg b/cfg/pce.cfg index b08e63814..f848fd737 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,5 +1,5 @@ SYMBOLS { - __STACKSIZE__: type = weak, value = $0300; # 3 pages stack + __STACKSIZE__: type = weak, value = $0300; # 3 pages stack } MEMORY { @@ -18,7 +18,7 @@ MEMORY { # Hardware Vectors at End of 2nd 8K ROM ROMV: start = $fff6, size = $a, file = %O,fill = yes; - ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; +# ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; # standard 2k SRAM (-zeropage) @@ -43,8 +43,8 @@ SEGMENTS { STARTUP: load = ROM0, type = ro, define = yes; INIT: load = ROM0, type = ro, define = yes, optional = yes; - CODE: load = ROM, type = ro, define = yes; - RODATA: load = ROM, type = ro, define = yes; + CODE: load = ROM0, type = ro, define = yes; + RODATA: load = ROM0, type = ro, define = yes; DATA: load = ROM0, run= RAM, type = rw, define = yes; # BSS: load = RAM2, type = bss, define = yes; @@ -58,12 +58,13 @@ SEGMENTS { } FEATURES { - CONDES: segment = STARTUP, - type=constructor, - label=__CONSTRUCTOR_TABLE__, - count=__CONSTRUCTOR_COUNT__; - CONDES: segment = STARTUP, - type=destructor, - label=__DESTRUCTOR_TABLE__, - count=__DESTRUCTOR_COUNT__; + CONDES: segment = STARTUP, + type=constructor, + label=__CONSTRUCTOR_TABLE__, + count=__CONSTRUCTOR_COUNT__; + + CONDES: segment = STARTUP, + type=destructor, + label=__DESTRUCTOR_TABLE__, + count=__DESTRUCTOR_COUNT__; } diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/_scrsize.s index 17b23b709..6e2b84a41 100644 --- a/libsrc/pce/_scrsize.s +++ b/libsrc/pce/_scrsize.s @@ -2,16 +2,14 @@ ; Screen size variables ; - - -.export _screensize + .export _screensize _screensize: - ldx xsize - ldy ysize - rts + ldx xsize + ldy ysize + rts .rodata - .export xsize, ysize + .export xsize, ysize -xsize: .byte 64 -ysize: .byte 28 +xsize: .byte 64 +ysize: .byte 28 diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 43ca5d602..c6c0dabb8 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -43,56 +43,60 @@ start: ; setup the CPU and System-IRQ - ; Initialize CPU + ; Initialize CPU - sei - nop - csh - nop - cld - nop + sei + nop + csh ; set high speed CPU mode + nop + cld + nop - ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) - txs - txa - tam #0 ; 0000-1FFF = Hardware page + ; Setup stack and memory mapping + ldx #$FF ; Stack top ($21FF) + txs - lda #$F8 - tam #1 ; 2000-3FFF = Work RAM + ; at startup all MPRs are set to 0, so init them + lda #$ff + tam #1 ; 0000-1FFF = Hardware page + lda #$F8 + tam #2 ; 2000-3FFF = Work RAM + ;lda #$F7 + ;tam #2 ; 4000-5FFF = Save RAM + ;lda #1 + ;tam #3 ; 6000-7FFF Page 2 + ;lda #2 + ;tam #4 ; 8000-9FFF Page 3 + ;lda #3 + ;tam #5 ; A000-BFFF Page 4 + ;lda #4 + ;tam #6 ; C000-DFFF Page 5 + ;lda #0 + ;tam #7 ; e000-fFFF hucard/syscard bank 0 - lda #$F7 - tam #2 ; 4000-5FFF = Save RAM + ; Clear work RAM (2000-3FFF) + stz <$00 + tii $2000, $2001, $1FFF - lda #1 - tam #3 ; 6000-7FFF Page 2 - lda #2 - tam #4 ; 8000-9FFF Page 3 - lda #3 - tam #5 ; A000-BFFF Page 4 - lda #4 - tam #6 ; C000-DFFF Page 5 + ; Initialize hardware + stz TIMER_COUNT ; Timer off + lda #$07 + sta IRQ_MASK ; Interrupts off + stz IRQ_STATUS ; Acknowledge timer - ; Initialize hardware - stz TIMER_COUNT ; Timer off - lda #$07 - sta IRQ_MASK ; Interrupts off - stz IRQ_STATUS ; Acknowledge timer + ;; i dont know why the heck this one doesnt + ;; work when called from a constructor :/ + .import vdc_init + jsr vdc_init - ; Clear work RAM - stz <$00 - tii $2000, $2001, $1FFF - - ;; i dont know why the heck this one doesnt - ;; work when called from a constructor :/ - .import vdc_init - jsr vdc_init ;; jsr joy_init - ; Turn on background and VD interrupt/IRQ1 - lda #$05 - sta IRQ_MASK ; IRQ1=on - cli + ; Turn on background and VD interrupt/IRQ1 + + lda #$05 + sta IRQ_MASK ; IRQ1=on + + cli ; Clear the BSS data @@ -162,8 +166,10 @@ start: ; Call module constructors jsr initlib -; .import initconio -; jsr initconio + + .import initconio + jsr initconio + ; Pass an empty command line @@ -189,34 +195,34 @@ _exit: ; ------------------------------------------------------------------------ _irq1: - pha - phx - phy + pha + phx + phy - inc _tickcount - bne @s - inc _tickcount+1 + inc _tickcount + bne @s + inc _tickcount+1 @s: - ; Acknowlege interrupt - ldaio VDC_CTRL + ; Acknowlege interrupt + ldaio VDC_CTRL - ply - plx - pla - rti + ply + plx + pla + rti _irq2: - rti + rti _nmi: - rti + rti _timer: - stz IRQ_STATUS - rti + stz IRQ_STATUS + rti - .export initmainargs + .export initmainargs initmainargs: - rts + rts ; ------------------------------------------------------------------------ ; hardware vectors diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index a5c919970..1f96c062c 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,6 +1,7 @@ - .include "pcengine.inc" - .export vce_init + .include "pcengine.inc" + + .export vce_init vce_init: stz VCE_ADDR_LO ; diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index a203cb058..47efdff55 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,15 +1,12 @@ - .include "pcengine.inc" + .include "pcengine.inc" HIRES = 1 - .export vdc_init + .export vdc_init vdc_init: - ;;lda $0000 - ;;.byte $ad,0,0 - - ldaio VDC_CTRL + ldaio VDC_CTRL VREG $00, $0000 ; MAWR VREG $01, $0000 ; MARR @@ -39,8 +36,5 @@ vdc_init: .endif - ;;lda $0000 - ;;.byte $ad,0,0 - - ldaio VDC_CTRL + ldaio VDC_CTRL rts diff --git a/libsrc/pce/vga.inc b/libsrc/pce/vga.inc index 6cbdd010c..2f9408f9a 100644 --- a/libsrc/pce/vga.inc +++ b/libsrc/pce/vga.inc @@ -1,4 +1,6 @@ +; VGA charset for the PC-Engine conio implementation + .byte $00, $00, $00, $00, $00, $00, $00, $00 .byte $7E, $81, $A5, $81, $BD, $99, $81, $7E .byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E From 891cb97b2f0c0e6816b63ab7cb167ec17e67603d Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 12 Jul 2015 14:27:24 +0200 Subject: [PATCH 182/351] more cleanup, joystick works again --- libsrc/pce/pcengine.inc => asminc/pce.inc | 51 ++-- cfg/pce.cfg | 70 ++---- include/pce.h | 155 +++++++----- libsrc/pce/call.s | 12 +- libsrc/pce/clock.s | 13 +- libsrc/pce/clrscr.s | 2 +- libsrc/pce/color.s | 80 +++---- libsrc/pce/condes.s | 6 - libsrc/pce/conio.s | 175 +++++++------- libsrc/pce/cputc.s | 126 ++++------ libsrc/pce/crt0.s | 10 +- libsrc/pce/ctype.s | 161 +++++++++++++ libsrc/pce/gotoxy.s | 17 +- libsrc/pce/joy/pce-stdjoy.s | 162 +++++++++++++ libsrc/pce/joy_stat_stddrv.s | 14 ++ libsrc/pce/joy_stddrv.s | 13 + libsrc/pce/joytokbd.s | 275 ---------------------- libsrc/pce/kplot.s | 47 ++-- libsrc/pce/libref.s | 8 + libsrc/pce/pce-stdjoy.s | 191 --------------- libsrc/pce/psg.s | 44 ++-- libsrc/pce/readme.txt | 31 +++ libsrc/pce/revers.s | 6 +- libsrc/pce/vce.s | 2 +- libsrc/pce/vdc.s | 2 +- testcode/lib/conio.c | 10 - testcode/lib/pce/conio.c | 58 +++++ 27 files changed, 822 insertions(+), 919 deletions(-) rename libsrc/pce/pcengine.inc => asminc/pce.inc (74%) create mode 100644 libsrc/pce/ctype.s create mode 100644 libsrc/pce/joy/pce-stdjoy.s create mode 100644 libsrc/pce/joy_stat_stddrv.s create mode 100644 libsrc/pce/joy_stddrv.s delete mode 100644 libsrc/pce/joytokbd.s create mode 100644 libsrc/pce/libref.s delete mode 100644 libsrc/pce/pce-stdjoy.s create mode 100644 libsrc/pce/readme.txt delete mode 100644 testcode/lib/conio.c create mode 100644 testcode/lib/pce/conio.c diff --git a/libsrc/pce/pcengine.inc b/asminc/pce.inc similarity index 74% rename from libsrc/pce/pcengine.inc rename to asminc/pce.inc index a0ef03f6a..40e356cae 100644 --- a/libsrc/pce/pcengine.inc +++ b/asminc/pce.inc @@ -1,12 +1,17 @@ +; +; PCE definitions. By Groepaz/Hitmem. +; -; Write VDC register - .macro VREG arg1,arg2 - st0 #arg1 - st1 #<(arg2) - st2 #>(arg2) - .endmacro +;; FIXME: optimize zeropage usage -_tickcount= $20 +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 ;2 +CRAM_PTR = $34 ;2 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR = $38 +_tickcount = $39 ;2 screenrows = (224/8) charsperline = (512/8) @@ -15,14 +20,6 @@ xsize = charsperline CH_HLINE = 7 CH_VLINE = 7 -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 -CRAM_PTR = $34 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR=$38 - ; huc6270 - Video Display Controller (vdc) VDC_MAWR = 0 ; Memory Address Write Register @@ -45,9 +42,9 @@ VDC_DESR =16 ; (DMA) Destination Register VDC_LENR =17 ; (DMA) Length Register VDC_SATB =18 ; Sprite Attribute Table -VDC_CTRL = $0000 -VDC_DATA_LO = $0002 -VDC_DATA_HI = $0003 +VDC_CTRL = $0000 +VDC_DATA_LO = $0002 +VDC_DATA_HI = $0003 ; huc6260 - Video Color Encoder (vce) @@ -61,18 +58,17 @@ VCE_ADDR_HI = $0403 ; MSB of byte offset into palette VCE_DATA_LO = $0404 ; LSB of 16-bit palette data VCE_DATA_HI = $0405 ; MSB of 16-bit palette data -TIMER_COUNT = $0c00 -TIMER_CTRL = $0c01 +TIMER_COUNT = $0c00 +TIMER_CTRL = $0c01 -JOY_CTRL = $1000 +JOY_CTRL = $1000 -IRQ_MASK = $1402 -IRQ_STATUS = $1403 +IRQ_MASK = $1402 +IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 CDR_MEM_ENABLE = $1807 - ;; lda abs .macro ldaio arg1 .byte $ad @@ -88,3 +84,10 @@ CDR_MEM_ENABLE = $1807 .byte $9c .word arg1 .endmacro + +; Write VDC register +.macro VREG arg1,arg2 + st0 #arg1 + st1 #<(arg2) + st2 #>(arg2) +.endmacro diff --git a/cfg/pce.cfg b/cfg/pce.cfg index f848fd737..566554b2e 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -1,62 +1,32 @@ +# linker config to produce simple NEC PC-Engine cartridge (.pce) + SYMBOLS { __STACKSIZE__: type = weak, value = $0300; # 3 pages stack } + MEMORY { + # FIXME: is this correct? the first 3? bytes cant be used? + ZP: start = $03, size = $1A, type = rw, define = yes; - ZP: start = $00, size = $1A, type = rw, define = yes; - - # INES Cartridge Header - #HEADER: start = $0, size = $10, file = %O ,fill = yes; - - # 2 16K ROM Banks - # - startup - # - code - # - rodata - # - data (load) - # 1 8k CHR Bank - ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; - # Hardware Vectors at End of 2nd 8K ROM - ROMV: start = $fff6, size = $a, file = %O,fill = yes; - -# ROM: start = $6000, size = $8000, file = %O, fill = yes,define=yes; - - - # standard 2k SRAM (-zeropage) - # $0100-$0200 cpu stack - # $0200-$0500 3 pages for ppu memory write buffer - # $0500-$0800 3 pages for cc65 parameter stack - #SRAM: start = $0500, size = $0300, define = yes; - - # additional 8K SRAM Bank - # - data (run) - # - bss - # - heap -# RAM: start = $2200, size = $1000, define = yes; -# RAM2: start = $3200, size = $0e00, define = yes; - RAM: start = $2200, size = $1e00, define = yes; + # reset-bank and hardware vectors + ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; + ROMV: start = $fff6, size = $a, file = %O,fill = yes; + # first RAM page (also contains stack and zeropage) + RAM: start = $2200, size = $1e00, define = yes; } + SEGMENTS { - #HEADER: load = HEADER, type = wprot; - - #aSTARTUP: load = ROM0, type = wprot, define = yes; - STARTUP: load = ROM0, type = ro, define = yes; - - INIT: load = ROM0, type = ro, define = yes, optional = yes; - CODE: load = ROM0, type = ro, define = yes; - RODATA: load = ROM0, type = ro, define = yes; - - DATA: load = ROM0, run= RAM, type = rw, define = yes; -# BSS: load = RAM2, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - - VECTORS: load = ROMV, type = rw, define = yes; - #CHARS: load = ROM2, type = rw; - - - ZEROPAGE: load = ZP, type = zp, define = yes; - + STARTUP: load = ROM0, type = ro, define = yes; + INIT: load = ROM0, type = ro, define = yes, optional = yes; + CODE: load = ROM0, type = ro, define = yes; + RODATA: load = ROM0, type = ro, define = yes; + DATA: load = ROM0, run= RAM, type = rw, define = yes; + BSS: load = RAM, type = bss, define = yes; + VECTORS: load = ROMV, type = rw, define = yes; + ZEROPAGE: load = ZP, type = zp, define = yes; } + FEATURES { CONDES: segment = STARTUP, type=constructor, diff --git a/include/pce.h b/include/pce.h index 8135679a2..70d5800d0 100644 --- a/include/pce.h +++ b/include/pce.h @@ -1,74 +1,99 @@ -#define CH_CROSS 0x10 - -#define CH_RTEE 0x17 -#define CH_LTEE 0x0f - -#define CH_ULCORNER 0x10 -#define CH_URCORNER 0x10 -#define CH_LLCORNER 0x10 -#define CH_LRCORNER 0x10 +/*****************************************************************************/ +/* */ +/* pce.h */ +/* */ +/* PC-Engine system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 2015 Groepaz/Hitmen */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 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 */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ -#define TV_NTSC 0 -#define TV_PAL 1 -#define get_tv() 0 -#define CLOCKS_PER_SEC 50 // ??? -#define CLK_TCK 50 // ?!? +#ifndef _PCE_H +#define _PCE_H -//#ifndef CH_ENTER -#define CH_ENTER '\n' -//#endif -#define CH_STOP 0x08 -#define CH_F1 0x14 -#define CH_F3 0x15 -#define CH_F5 0x16 -#define CH_F7 0x17 - -#define CH_CURS_UP 0x01 -#define CH_CURS_DOWN 0x02 - -#ifndef CH_CURS_LEFT -#define CH_CURS_LEFT 0x03 +/* Check for errors */ +#if !defined(__PCE__) +# error This module may only be used when compiling for the PCE! #endif -#ifndef CH_CURS_RIGHT -#define CH_CURS_RIGHT 0x04 +/* FIXME: the respective characters are not present in the VGA charset (yet) */ +#define CH_CROSS 0x10 + +#define CH_RTEE 0x17 +#define CH_LTEE 0x0f + +#define CH_ULCORNER 0x10 +#define CH_URCORNER 0x10 +#define CH_LLCORNER 0x10 +#define CH_LRCORNER 0x10 + +/* Color defines (CBM compatible, for conio) */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_VIOLET 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +#define CLOCKS_PER_SEC 50 // ??? +#define CLK_TCK 50 // ?!? + +#define TV_NTSC 0 +#define TV_PAL 1 +#define TV_OTHER 2 + +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 + +/* The addresses of the static drivers */ +extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ + +#define JOY_FIRE_B 5 +#define JOY_START 6 +#define JOY_SELECT 7 + +/* FIXME: not implemented */ +void waitvblank (void); +/* Wait for the vertical blanking */ + +/* FIXME: not implemented */ +unsigned char get_tv (void); +/* Return the video mode the machine is using. */ + + +/* End of pce.h */ #endif - -#define CH_ESC 8 - -#define CH_DEL 20 - -/* Color defines */ -#define COLOR_BLACK 0x00 -#define COLOR_WHITE 0x01 -#define COLOR_RED 0x02 -#define COLOR_CYAN 0x03 -#define COLOR_VIOLET 0x04 -#define COLOR_GREEN 0x05 -#define COLOR_BLUE 0x06 -#define COLOR_YELLOW 0x07 -#define COLOR_ORANGE 0x08 -#define COLOR_BROWN 0x09 -#define COLOR_LIGHTRED 0x0A -#define COLOR_GRAY1 0x0B -#define COLOR_GRAY2 0x0C -#define COLOR_LIGHTGREEN 0x0D -#define COLOR_LIGHTBLUE 0x0E -#define COLOR_GRAY3 0x0F - -#define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 - -/* -void __fastcall__ waitvblank(void); - -unsigned char __fastcall__ cpeekcharxy(unsigned char x,unsigned char y); -unsigned char __fastcall__ cpeekchar(void); -unsigned char __fastcall__ cpeekcolxy(unsigned char x,unsigned char y); -unsigned char __fastcall__ cpeekcol(void); -*/ diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s index 34fbac08b..db120a72f 100644 --- a/libsrc/pce/call.s +++ b/libsrc/pce/call.s @@ -1,19 +1,17 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; CC65 runtime: call function via pointer in ax ; - .export callax + .export callax .code callax: - sta vec - stx vec+1 - jmp (vec) ; jump there + sta vec + stx vec+1 + jmp (vec) ; jump there .bss vec: - .res 2 \ No newline at end of file + .res 2 \ No newline at end of file diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 60096c81d..5f360916c 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -1,17 +1,15 @@ ; -; Ullrich von Bassewitz, 21.09.1998 -; ; clock_t clock (void); ; - .include "pcengine.inc" + .include "pce.inc" - .export _clock + .export _clock .importzp sreg - -.proc _clock - ldy #0 ; Byte 3 is always zero +.proc _clock + + ldy #0 ; Byte 3 is always zero sty sreg+1 sty sreg @@ -20,4 +18,3 @@ rts .endproc - diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 0a2b8b62d..93628ddd8 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" .export _clrscr _clrscr: diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 8d80114fc..0ec35f5b3 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -1,59 +1,57 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); ; unsigned char __fastcall__ bordercolor (unsigned char color); ; - .export _textcolor, _bgcolor, _bordercolor + .export _textcolor, _bgcolor, _bordercolor - .include "pcengine.inc" + .include "pce.inc" _textcolor: - ldx CHARCOLOR ; get old value - sta CHARCOLOR ; set new value - txa - rts + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts _bgcolor: - ldx BGCOLOR ; get old value - sta BGCOLOR ; set new value - asl a - tay + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay - stz VCE_ADDR_LO - stz VCE_ADDR_HI - lda colors,y - sta VCE_DATA_LO - lda colors+1,y - sta VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI - txa - rts + txa + rts _bordercolor: - lda #0 - txa - rts + lda #0 + txa + rts - .export colors + .export colors -colors: ; G R B - .word ((0<<6)+(0<<3)+(0)) ; 0 black - .word ((7<<6)+(7<<3)+(7)) ; 1 white - .word ((0<<6)+(7<<3)+(0)) ; 2 red - .word ((7<<6)+(0<<3)+(7)) ; 3 cyan - .word ((0<<6)+(5<<3)+(7)) ; 4 violett - .word ((7<<6)+(0<<3)+(0)) ; 5 green - .word ((0<<6)+(0<<3)+(7)) ; 6 blue - .word ((7<<6)+(7<<3)+(0)) ; 7 yellow - .word ((5<<6)+(7<<3)+(0)) ; 8 orange - .word ((3<<6)+(4<<3)+(3)) ; 9 brown - .word ((4<<6)+(7<<3)+(4)) ; a light red - .word ((3<<6)+(3<<3)+(3)) ; b dark grey - .word ((4<<6)+(4<<3)+(4)) ; c middle grey - .word ((7<<6)+(4<<3)+(4)) ; d light green - .word ((4<<6)+(4<<3)+(7)) ; e light blue - .word ((6<<6)+(6<<3)+(6)) ; f light gray +colors: ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray diff --git a/libsrc/pce/condes.s b/libsrc/pce/condes.s index dd7bd30b3..aa28833c2 100644 --- a/libsrc/pce/condes.s +++ b/libsrc/pce/condes.s @@ -94,9 +94,3 @@ getbyt: ;;getbyt_: lda $FFFF,y rts - -;; callax doesnt work? why?! -;_callax: -; sta @l+1 -; stx @l+2 -;@l: jmp $dead diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 0a66cf454..60801e172 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,122 +1,105 @@ - .include "pcengine.inc" - .import vce_init - .import psg_init - .import vdc_init + .include "pce.inc" - .export initconio - .export _conio_init + .import vce_init + .import psg_init + .import vdc_init - .constructor initconio, 24 + .export initconio + .export _conio_init - .macpack longbranch + .constructor initconio, 24 + + .macpack longbranch initconio: - ;; jsr vdc_init - jsr vce_init - jsr psg_init - jsr conio_init - jsr set_palette +;; jsr vdc_init + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette - st0 #VDC_RCR - st1 #<$0088 - st2 #>$0088 - rts + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts - .import colors + .import colors set_palette: + stz VCE_ADDR_LO + stz VCE_ADDR_HI - ; Make palette (use VGA palette?) - ; stz VCE_ADDR_LO - ; stz VCE_ADDR_HI - ; clx - ; cly - vce_loop: ;; stx VCE_DATA_LO - ;; sty VCE_DATA_HI - ; inx - ; cpx #$00 - ; bne vce_loop - ; iny - ; cpy #$02 - ; bne vce_loop - - - stz VCE_ADDR_LO - stz VCE_ADDR_HI - - ldx #0 + ldx #0 @lp: - .repeat 16 - lda colors,x - sta VCE_DATA_LO - lda colors+1,x - sta VCE_DATA_HI - .endrepeat + .repeat 16 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + .endrepeat - inx - inx - cpx #16*2;*5 - jne @lp + inx + inx + cpx #16*2 + jne @lp - stz VCE_ADDR_LO - stz VCE_ADDR_HI - stz VCE_DATA_LO - stz VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI -; so it will get linked in + ; so it will get linked in _conio_init: - rts + rts ;---------------------------------------------------------------------------- ; ;---------------------------------------------------------------------------- - .importzp ptr1 - + .importzp ptr1 conio_init: + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 - ; Load font - st0 #VDC_MAWR - st1 #<$2000 - st2 #>$2000 + ; ptr to font data + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - ; ptr to font data - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + st0 #VDC_VWR ; VWR + ldy #$80 ; 128 chars +charloop: ldx #$08 ; 8 bytes/char +lineloop: + lda (ptr1) + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 - st0 #VDC_VWR ; VWR - ldy #$80 ; 128 chars - charloop: ldx #$08 ; 8 bytes/char - lineloop: - ;;lda [$00] ; read font byte - lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 +fillloop: st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character - clc ; increment font pointer - lda ptr1 - adc #$01 - sta ptr1 - lda ptr1+1 - adc #$00 - sta ptr1+1 - dex - bne lineloop ; next bitplane 0 byte - ldx #$08 ; fill bitplane 2/3 with 0 - fillloop: st1 #$00 - st2 #$00 - dex - bne fillloop ; next byte - dey - bne charloop ; next character - - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR - rts + rts - .rodata -font: .include "vga.inc" + .rodata +font: + .include "vga.inc" diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index 8a02a3499..ec63b7565 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -1,81 +1,59 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - .import popa, _gotoxy - .import PLOT - - .importzp tmp3,tmp4 - - .include "pcengine.inc" + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + .importzp tmp3,tmp4 + .include "pce.inc" _cputcxy: - pha ; Save C - jsr popa ; Get Y - jsr _gotoxy ; Set cursor, drop x - pla ; Restore C + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C ; Plot a character - also used as internal function -_cputc: cmp #$0d ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers -L1: cmp #$0a ; LF? - beq newline ; Recalculate pointers +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers ; Printable char of some sort cputdirect: - jsr putchar ; Write the character to the screen + jsr putchar ; Write the character to the screen ; Advance cursor position advance: - ldy CURS_X - iny - cpy #xsize - bne L3 - jsr newline ; new line - ldy #0 ; + cr -L3: sty CURS_X - jmp plot - ;rts + ldy CURS_X + iny + cpy #xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot newline: -; lda #xsize -; clc -; adc SCREEN_PTR -; sta SCREEN_PTR -; bcc L4 -; inc SCREEN_PTR+1 -;; clc -;L4:; lda #xsize - ; adc CRAM_PTR - ; sta CRAM_PTR - ; bcc L5 - ; inc CRAM_PTR+1 -;L5: - - inc CURS_Y - -; jmp plot -; rts + inc CURS_Y ; Set cursor position, calculate RAM pointers -plot: ldy CURS_X - ldx CURS_Y - clc - jmp PLOT ; Set the new cursor +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor @@ -84,34 +62,32 @@ plot: ldy CURS_X putchar: - ora RVS ; Set revers bit + ora RVS ; Set revers bit - tax + tax - st0 #VDC_MAWR ; Memory Adress Write + st0 #VDC_MAWR ; Memory Adress Write - lda SCREEN_PTR - staio VDC_DATA_LO + lda SCREEN_PTR + staio VDC_DATA_LO - lda SCREEN_PTR+1 - staio VDC_DATA_HI + lda SCREEN_PTR+1 + staio VDC_DATA_HI - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR - txa - staio VDC_DATA_LO ; character + txa + staio VDC_DATA_LO ; character - ;;st2 #$32 ; attrib ?! - lda CHARCOLOR - - ;;lda #2 - asl a - asl a - asl a - asl a + lda CHARCOLOR - and #$f0 - ora #$02 - staio VDC_DATA_HI + asl a + asl a + asl a + asl a - rts + and #$f0 + ora #$02 + staio VDC_DATA_HI + + rts diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index c6c0dabb8..06454998b 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -24,7 +24,7 @@ .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated .import __BSS_SIZE__ - .include "pcengine.inc" + .include "pce.inc" .importzp sp .importzp ptr1,ptr2 @@ -84,10 +84,9 @@ start: sta IRQ_MASK ; Interrupts off stz IRQ_STATUS ; Acknowledge timer - ;; i dont know why the heck this one doesnt - ;; work when called from a constructor :/ - .import vdc_init - jsr vdc_init + ;; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ + .import vdc_init + jsr vdc_init ;; jsr joy_init @@ -167,6 +166,7 @@ start: jsr initlib + ;; FIXME: this should be called from a constructor instead .import initconio jsr initconio diff --git a/libsrc/pce/ctype.s b/libsrc/pce/ctype.s new file mode 100644 index 000000000..fa9a65c8b --- /dev/null +++ b/libsrc/pce/ctype.s @@ -0,0 +1,161 @@ +; +; Stefan Haubenthal with minor changes from Ullrich von Bassewitz, 2003-05-02 +; +; Character specification table. +; + + .include "ctype.inc" + +; The tables are readonly, put them into the rodata segment + +.rodata + +; The following 256 byte wide table specifies attributes for the isxxx type +; of functions. Doing it by a table means some overhead in space, but it +; has major advantages: +; +; * It is fast. If it were'nt for the slow parameter passing of cc65, one +; could even define macros for the isxxx functions (this is usually +; done on other platforms). +; +; * It is highly portable. The only unportable part is the table itself, +; all real code goes into the common library. +; +; * We save some code in the isxxx functions. + + +__ctype: + .repeat 2 + .byte CT_CTRL ; 0/00 ___ctrl_@___ + .byte CT_CTRL ; 1/01 ___ctrl_A___ + .byte CT_CTRL ; 2/02 ___ctrl_B___ + .byte CT_CTRL ; 3/03 ___ctrl_C___ + .byte CT_CTRL ; 4/04 ___ctrl_D___ + .byte CT_CTRL ; 5/05 ___ctrl_E___ + .byte CT_CTRL ; 6/06 ___ctrl_F___ + .byte CT_CTRL ; 7/07 ___ctrl_G___ + .byte CT_CTRL ; 8/08 ___ctrl_H___ + .byte CT_CTRL | CT_OTHER_WS | CT_SPACE_TAB + ; 9/09 ___ctrl_I___ + .byte CT_CTRL | CT_OTHER_WS ; 10/0a ___ctrl_J___ + .byte CT_CTRL | CT_OTHER_WS ; 11/0b ___ctrl_K___ + .byte CT_CTRL | CT_OTHER_WS ; 12/0c ___ctrl_L___ + .byte CT_CTRL | CT_OTHER_WS ; 13/0d ___ctrl_M___ + .byte CT_CTRL ; 14/0e ___ctrl_N___ + .byte CT_CTRL ; 15/0f ___ctrl_O___ + .byte CT_CTRL ; 16/10 ___ctrl_P___ + .byte CT_CTRL ; 17/11 ___ctrl_Q___ + .byte CT_CTRL ; 18/12 ___ctrl_R___ + .byte CT_CTRL ; 19/13 ___ctrl_S___ + .byte CT_CTRL ; 20/14 ___ctrl_T___ + .byte CT_CTRL ; 21/15 ___ctrl_U___ + .byte CT_CTRL ; 22/16 ___ctrl_V___ + .byte CT_CTRL ; 23/17 ___ctrl_W___ + .byte CT_CTRL ; 24/18 ___ctrl_X___ + .byte CT_CTRL ; 25/19 ___ctrl_Y___ + .byte CT_CTRL ; 26/1a ___ctrl_Z___ + .byte CT_CTRL ; 27/1b ___ctrl_[___ + .byte CT_CTRL ; 28/1c ___ctrl_\___ + .byte CT_CTRL ; 29/1d ___ctrl_]___ + .byte CT_CTRL ; 30/1e ___ctrl_^___ + .byte CT_CTRL ; 31/1f ___ctrl_____ + .byte CT_SPACE | CT_SPACE_TAB ; 32/20 ___SPACE___ + .byte CT_NONE ; 33/21 _____!_____ + .byte CT_NONE ; 34/22 _____"_____ + .byte CT_NONE ; 35/23 _____#_____ + .byte CT_NONE ; 36/24 _____$_____ + .byte CT_NONE ; 37/25 _____%_____ + .byte CT_NONE ; 38/26 _____&_____ + .byte CT_NONE ; 39/27 _____'_____ + .byte CT_NONE ; 40/28 _____(_____ + .byte CT_NONE ; 41/29 _____)_____ + .byte CT_NONE ; 42/2a _____*_____ + .byte CT_NONE ; 43/2b _____+_____ + .byte CT_NONE ; 44/2c _____,_____ + .byte CT_NONE ; 45/2d _____-_____ + .byte CT_NONE ; 46/2e _____._____ + .byte CT_NONE ; 47/2f _____/_____ + .byte CT_DIGIT | CT_XDIGIT ; 48/30 _____0_____ + .byte CT_DIGIT | CT_XDIGIT ; 49/31 _____1_____ + .byte CT_DIGIT | CT_XDIGIT ; 50/32 _____2_____ + .byte CT_DIGIT | CT_XDIGIT ; 51/33 _____3_____ + .byte CT_DIGIT | CT_XDIGIT ; 52/34 _____4_____ + .byte CT_DIGIT | CT_XDIGIT ; 53/35 _____5_____ + .byte CT_DIGIT | CT_XDIGIT ; 54/36 _____6_____ + .byte CT_DIGIT | CT_XDIGIT ; 55/37 _____7_____ + .byte CT_DIGIT | CT_XDIGIT ; 56/38 _____8_____ + .byte CT_DIGIT | CT_XDIGIT ; 57/39 _____9_____ + .byte CT_NONE ; 58/3a _____:_____ + .byte CT_NONE ; 59/3b _____;_____ + .byte CT_NONE ; 60/3c _____<_____ + .byte CT_NONE ; 61/3d _____=_____ + .byte CT_NONE ; 62/3e _____>_____ + .byte CT_NONE ; 63/3f _____?_____ + + .byte CT_NONE ; 64/40 _____@_____ + .byte CT_UPPER | CT_XDIGIT ; 65/41 _____A_____ + .byte CT_UPPER | CT_XDIGIT ; 66/42 _____B_____ + .byte CT_UPPER | CT_XDIGIT ; 67/43 _____C_____ + .byte CT_UPPER | CT_XDIGIT ; 68/44 _____D_____ + .byte CT_UPPER | CT_XDIGIT ; 69/45 _____E_____ + .byte CT_UPPER | CT_XDIGIT ; 70/46 _____F_____ + .byte CT_UPPER ; 71/47 _____G_____ + .byte CT_UPPER ; 72/48 _____H_____ + .byte CT_UPPER ; 73/49 _____I_____ + .byte CT_UPPER ; 74/4a _____J_____ + .byte CT_UPPER ; 75/4b _____K_____ + .byte CT_UPPER ; 76/4c _____L_____ + .byte CT_UPPER ; 77/4d _____M_____ + .byte CT_UPPER ; 78/4e _____N_____ + .byte CT_UPPER ; 79/4f _____O_____ + .byte CT_UPPER ; 80/50 _____P_____ + .byte CT_UPPER ; 81/51 _____Q_____ + .byte CT_UPPER ; 82/52 _____R_____ + .byte CT_UPPER ; 83/53 _____S_____ + .byte CT_UPPER ; 84/54 _____T_____ + .byte CT_UPPER ; 85/55 _____U_____ + .byte CT_UPPER ; 86/56 _____V_____ + .byte CT_UPPER ; 87/57 _____W_____ + .byte CT_UPPER ; 88/58 _____X_____ + .byte CT_UPPER ; 89/59 _____Y_____ + .byte CT_UPPER ; 90/5a _____Z_____ + .byte CT_NONE ; 91/5b _____[_____ + .byte CT_NONE ; 92/5c _____\_____ + .byte CT_NONE ; 93/5d _____]_____ + .byte CT_NONE ; 94/5e _____^_____ + .byte CT_NONE ; 95/5f _UNDERLINE_ + .byte CT_NONE ; 96/60 ___grave___ + .byte CT_LOWER | CT_XDIGIT ; 97/61 _____a_____ + .byte CT_LOWER | CT_XDIGIT ; 98/62 _____b_____ + .byte CT_LOWER | CT_XDIGIT ; 99/63 _____c_____ + .byte CT_LOWER | CT_XDIGIT ; 100/64 _____d_____ + .byte CT_LOWER | CT_XDIGIT ; 101/65 _____e_____ + .byte CT_LOWER | CT_XDIGIT ; 102/66 _____f_____ + .byte CT_LOWER ; 103/67 _____g_____ + .byte CT_LOWER ; 104/68 _____h_____ + .byte CT_LOWER ; 105/69 _____i_____ + .byte CT_LOWER ; 106/6a _____j_____ + .byte CT_LOWER ; 107/6b _____k_____ + .byte CT_LOWER ; 108/6c _____l_____ + .byte CT_LOWER ; 109/6d _____m_____ + .byte CT_LOWER ; 110/6e _____n_____ + .byte CT_LOWER ; 111/6f _____o_____ + .byte CT_LOWER ; 112/70 _____p_____ + .byte CT_LOWER ; 113/71 _____q_____ + .byte CT_LOWER ; 114/72 _____r_____ + .byte CT_LOWER ; 115/73 _____s_____ + .byte CT_LOWER ; 116/74 _____t_____ + .byte CT_LOWER ; 117/75 _____u_____ + .byte CT_LOWER ; 118/76 _____v_____ + .byte CT_LOWER ; 119/77 _____w_____ + .byte CT_LOWER ; 120/78 _____x_____ + .byte CT_LOWER ; 121/79 _____y_____ + .byte CT_LOWER ; 122/7a _____z_____ + .byte CT_NONE ; 123/7b _____{_____ + .byte CT_NONE ; 124/7c _____|_____ + .byte CT_NONE ; 125/7d _____}_____ + .byte CT_NONE ; 126/7e _____~_____ + .byte CT_OTHER_WS ; 127/7f ____DEL____ + .endrepeat + + diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index cfb59efe2..24f917cd6 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -1,19 +1,16 @@ ; -; Ullrich von Bassewitz, 06.08.1998 -; ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy - .import popa, plot + .export _gotoxy + .import popa, plot - .include "pcengine.inc" + .include "pce.inc" _gotoxy: - - sta CURS_Y ; Set Y - jsr popa ; Get X - sta CURS_X ; Set X - jmp plot ; Set the cursor position + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s new file mode 100644 index 000000000..6bc6bdf57 --- /dev/null +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -0,0 +1,162 @@ + +; +; Standard joystick driver for the PCEngine +; + + .include "joy-kernel.inc" + .include "joy-error.inc" + + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _pce_stdjoy_joy + +; Driver signature + + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number + +; Library reference + + .addr $0000 + +; Button state masks (8 values) + +;extern const unsigned char joy_masks[8]; + + .export _joy_masks + +_joy_masks: + .byte $10 ; JOY_UP + .byte $40 ; JOY_DOWN + .byte $80 ; JOY_LEFT + .byte $20 ; JOY_RIGHT + .byte $02 ; JOY_FIRE A ; FIXME: is this correct? + .byte $01 ; JOY_FIRE B ; FIXME: is this correct? + .byte $04 ; JOY_START ; FIXME: is this correct? + .byte $08 ; JOY_SELECT ; FIXME: is this correct? + +; Jump table. + + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READJOY + .addr 0 ; IRQ entry unused + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 4 ; Number of joysticks we support + + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #<JOY_ERR_OK + ldx #>JOY_ERR_OK + +; rts ; Run into DEINSTALL instead + +; ------------------------------------------------------------------------ +; DEINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; +;unsigned char __fastcall__ joy_count (void); + +COUNT: + lda #<JOY_COUNT + ldx #>JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; +;unsigned char __fastcall__ joy_read (unsigned char joystick); + +READJOY: + pha + jsr read_joy + pla + tax ; Joystick number into X + + ; return value from buffer + +joy1: + lda padbuffer,x + ldx #0 + rts + +read_joy: + ; reset multitap counter + lda #$01 + sta $1000 + pha + pla + nop + nop + + lda #$03 + sta $1000 + pha + pla + nop + nop + + cly +nextpad: + lda #$01 + sta $1000 ; sel = 1 + pha + pla + nop + nop + + lda $1000 + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value + + stz $1000 + pha + pla + nop + nop + + lda $1000 + and #$0F + ora padbuffer, y ; second half of new value + + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts + +.bss + +padbuffer: + .res 4 + diff --git a/libsrc/pce/joy_stat_stddrv.s b/libsrc/pce/joy_stat_stddrv.s new file mode 100644 index 000000000..3972569ed --- /dev/null +++ b/libsrc/pce/joy_stat_stddrv.s @@ -0,0 +1,14 @@ +; +; Address of the static standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const void joy_static_stddrv[]; +; + + .export _joy_static_stddrv + .import _pce_stdjoy_joy + +.rodata + +_joy_static_stddrv := _pce_stdjoy_joy diff --git a/libsrc/pce/joy_stddrv.s b/libsrc/pce/joy_stddrv.s new file mode 100644 index 000000000..e0ed6957e --- /dev/null +++ b/libsrc/pce/joy_stddrv.s @@ -0,0 +1,13 @@ +; +; Name of the standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const char joy_stddrv[]; +; + + .export _joy_stddrv + +.rodata + +_joy_stddrv: .asciiz "pce-stdjoy.joy" diff --git a/libsrc/pce/joytokbd.s b/libsrc/pce/joytokbd.s deleted file mode 100644 index 1e8258e08..000000000 --- a/libsrc/pce/joytokbd.s +++ /dev/null @@ -1,275 +0,0 @@ -; -; File generated by cc65 v 2.9.5 -; - .fopt compiler,"cc65 v 2.9.5" - .autoimport on - .case on - .debuginfo off - .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 - .macpack longbranch - .import _joy_masks - .import _joy_read - .import _clock - .export _kbhit - .export _cgetc - -.segment "DATA" - -__lastkey: - .byte $00 -__chardelay: - .dword $00000000 -_rptkey: - .byte $00 - -; --------------------------------------------------------------- -; void _getkey (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc __getkey - -.segment "CODE" - - jsr decsp2 - ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L003F - lda #$00 - jsr _joy_read - ldy #$01 - sta (sp),y - ldx #$00 - lda #$00 - ldy #$00 - sta (sp),y - ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+4 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0010 - ldx #$00 - lda #$0A - ldy #$00 - sta (sp),y - jmp L003A -L0010: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0016 - ldx #$00 - lda #$01 - ldy #$00 - sta (sp),y - jmp L003A -L0016: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+2 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L001C - ldx #$00 - lda #$03 - ldy #$00 - sta (sp),y - jmp L003A -L001C: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+3 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0022 - ldx #$00 - lda #$04 - ldy #$00 - sta (sp),y - jmp L003A -L0022: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+1 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0028 - ldx #$00 - lda #$02 - ldy #$00 - sta (sp),y - jmp L003A -L0028: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+7 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L002E - ldx #$00 - lda #$14 - ldy #$00 - sta (sp),y - jmp L003A -L002E: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+5 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L0034 - ldx #$00 - lda #$15 - ldy #$00 - sta (sp),y - jmp L003A -L0034: ldy #$01 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _joy_masks+6 - jsr tosandax - stx tmp1 - ora tmp1 - jeq L003A - ldx #$00 - lda #$16 - ldy #$00 - sta (sp),y -L003A: ldy #$00 - ldx #$00 - lda (sp),y - cmp #$00 - jsr boolne - jeq L003F - ldy #$00 - ldx #$00 - lda (sp),y - jsr pushax - ldx #$00 - lda _rptkey - jsr toseqax - jeq L0043 - lda __chardelay+3 - sta sreg+1 - lda __chardelay+2 - sta sreg - ldx __chardelay+1 - lda __chardelay - jsr pusheax - jsr _clock - jsr tosugteax - jeq L0043 - jmp L003F -L0043: ldy #$00 - ldx #$00 - lda (sp),y - sta _rptkey - jsr _clock - ldy #$06 - jsr inceaxy - sta __chardelay - stx __chardelay+1 - ldy sreg - sty __chardelay+2 - ldy sreg+1 - sty __chardelay+3 - ldy #$00 - ldx #$00 - lda (sp),y - sta __lastkey -L003F: jsr incsp2 - rts - -.endproc - -; --------------------------------------------------------------- -; unsigned char __fastcall__ kbhit (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _kbhit - -.segment "CODE" - - jsr __getkey - ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L004E - ldx #$00 - lda #$00 - jmp L0052 - jmp L0052 -L004E: ldx #$00 - lda #$01 - jmp L0052 -L0052: rts - -.endproc - -; --------------------------------------------------------------- -; unsigned char __fastcall__ cgetc (void) -; --------------------------------------------------------------- - -.segment "CODE" - -.proc _cgetc - -.segment "CODE" - - jsr decsp1 -L0056: ldx #$00 - lda __lastkey - cmp #$00 - jsr booleq - jeq L0057 - jsr __getkey - jmp L0056 -L0057: ldx #$00 - lda __lastkey - ldy #$00 - sta (sp),y - ldx #$00 - lda #$00 - sta __lastkey - ldy #$00 - ldx #$00 - lda (sp),y - jmp L0055 -L0055: jsr incsp1 - rts - -.endproc - diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index f050d78ef..beb151a7b 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -1,41 +1,32 @@ - .export PLOT + .export PLOT - .include "pcengine.inc" + .include "pce.inc" PLOT: + bcs @getpos - bcs @getpos - - tya - clc - adc _plotlo,x - sta SCREEN_PTR - - lda _plothi,x - adc #0 - sta SCREEN_PTR+1 - - ;clc - ;adc _colplot,x - ;sta CRAM_PTR - - ;lda #$23 - ;sta CRAM_PTR+1 + tya + clc + adc _plotlo,x + sta SCREEN_PTR + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 @getpos: - ldx CURS_Y - ldy CURS_X - rts + ldx CURS_Y + ldy CURS_X + rts _plotlo: - .repeat screenrows,line - .byte <($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat _plothi: - .repeat screenrows,line - .byte >($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat diff --git a/libsrc/pce/libref.s b/libsrc/pce/libref.s new file mode 100644 index 000000000..e4afa7eb1 --- /dev/null +++ b/libsrc/pce/libref.s @@ -0,0 +1,8 @@ +; +; Oliver Schmidt, 2013-05-31 +; + + .export joy_libref + .import _exit + +joy_libref := _exit diff --git a/libsrc/pce/pce-stdjoy.s b/libsrc/pce/pce-stdjoy.s deleted file mode 100644 index 60c77db1e..000000000 --- a/libsrc/pce/pce-stdjoy.s +++ /dev/null @@ -1,191 +0,0 @@ - -; -; Standard joystick driver for the PCEngine -; -; Ullrich von Bassewitz, 2002-12-20 -; - - ;;.include "zeropage.inc" - - ;;.include "joy-kernel.inc" - - ;;.include "joy-error.inc" - JOY_ERR_OK=0; - .include "pcengine.inc" - - .macpack generic - -; ------------------------------------------------------------------------ -; Header. Includes jump table - -.segment "CODE" - -; Driver signature - -;; .byte $6A, $6F, $79 ; "joy" -;; .byte $00 ; Driver API version number - -; Button state masks (8 values) - -;extern const unsigned char joy_masks[8]; - - .export _joy_masks - -_joy_masks: - .byte $10 ; JOY_UP - .byte $40 ; JOY_DOWN - .byte $80 ; JOY_LEFT - .byte $20 ; JOY_RIGHT - .byte $04 ; ? JOY_FIRE - .byte $02 ; ? Future expansion - .byte $01 ; ? Future expansion - .byte $08 ; ? Future expansion - -; Jump table. - -;; .word INSTALL -;; .word DEINSTALL -;; .word COUNT -;; .word READ - -; ------------------------------------------------------------------------ -; Constants - -JOY_COUNT = 4 ; Number of joysticks we support - - -; ------------------------------------------------------------------------ -; Data. - - -.code - - -;extern const char joy_stddrv[]; - - .export _joy_stddrv -_joy_stddrv: - .byte 0 - - - .export _joy_load_driver - .export _joy_unload - -;unsigned char __fastcall__ joy_unload (void); -;unsigned char __fastcall__ joy_load_driver (const char* driver); -_joy_load_driver: -_joy_unload: - -; ------------------------------------------------------------------------ -; INSTALL routine. Is called after the driver is loaded into memory. If -; possible, check if the hardware is present and determine the amount of -; memory available. -; Must return an JOY_ERR_xx code in a/x. -; - -INSTALL: - lda #<JOY_ERR_OK - ldx #>JOY_ERR_OK - -; rts ; Run into DEINSTALL instead - -; ------------------------------------------------------------------------ -; DEINSTALL routine. Is called before the driver is removed from memory. -; Can do cleanup or whatever. Must not return anything. -; - -DEINSTALL: - rts - - -; ------------------------------------------------------------------------ -; COUNT: Return the total number of available joysticks in a/x. -; -;unsigned char __fastcall__ joy_count (void); - - .export _joy_count - -_joy_count: -COUNT: - lda #<JOY_COUNT - ldx #>JOY_COUNT - rts - -; ------------------------------------------------------------------------ -; READ: Read a particular joystick passed in A. -; -;unsigned char __fastcall__ joy_read (unsigned char joystick); - - .export _joy_read - -_joy_read: -READ: - pha - jsr read_joy - pla - tax ; Joystick number into X - - ; return value from buffer - -joy1: - lda padbuffer,x - ldx #0 - rts - -.code - -read_joy: - ; reset multitap counter - lda #$01 - sta $1000 - pha - pla - nop - nop - - lda #$03 - sta $1000 - pha - pla - nop - nop - - cly -nextpad: - lda #$01 - sta $1000 ; sel = 1 - pha - pla - nop - nop - - lda $1000 - asl a - asl a - asl a - asl a - sta padbuffer, y ; store new value - - stz $1000 - pha - pla - nop - nop - - lda $1000 - and #$0F - ora padbuffer, y ; second half of new value - - eor #$FF - sta padbuffer, y ; store new value - - iny - cpy #$05 - bcc nextpad - rts - -.bss - -padbuffer: - .res 4 - diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index ebf35d952..431f58834 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,29 +1,29 @@ - - .include "pcengine.inc" - .export psg_init + .include "pce.inc" + + .export psg_init psg_init: - clx - stx $0800 ; Select channel + clx + stx $0800 ; Select channel psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control - cly + cly psg_clear_waveform: stz $0806 ; Clear waveform byte - iny - cpy #$20 - bne psg_clear_waveform + iny + cpy #$20 + bne psg_clear_waveform + + inx + cpx #$06 + bne psg_clear_loop + rts - inx - cpx #$06 - bne psg_clear_loop - rts - diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt new file mode 100644 index 000000000..e99b55122 --- /dev/null +++ b/libsrc/pce/readme.txt @@ -0,0 +1,31 @@ + +joystick support should get verified on real hw, the masks for buttons may be +wrong. + +clock() does not work for unknown reasons + +get_tv() is a dummy function and always returns 0 + +revers() is a dummy function, actual reverse output is not supported yet + +waitvblank() is missing + +some graphical petscii chars should get added to the charset + +conio-init should get initialized from a constructor rather than always get +called from crt0 + +-------------------------------------------------------------------------------- + +a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) + +run the compiled binary like this: + +> mednafen -force_module pce <yourprogram.pce> + +joypad keys are mapped like this: + +w/s/a/d up/down/left/right +numpad 2 (?) button +numpad 3 (?) button +enter (start) button diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index d1358a52b..c39a9f843 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,5 @@ - .export _revers + .export _revers _revers: - lda #0 - rts + lda #0 + rts diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 1f96c062c..461fd1e75 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" .export vce_init diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index 47efdff55..d1ead937e 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,5 +1,5 @@ - .include "pcengine.inc" + .include "pce.inc" HIRES = 1 diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c deleted file mode 100644 index 6a7bb2341..000000000 --- a/testcode/lib/conio.c +++ /dev/null @@ -1,10 +0,0 @@ - -#include <conio.h> - -void main(void) -{ - clrscr(); -// cprintf("hello world"); - cputs("hello world"); - for(;;); -} \ No newline at end of file diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c new file mode 100644 index 000000000..306eb1ebb --- /dev/null +++ b/testcode/lib/pce/conio.c @@ -0,0 +1,58 @@ + +#include <conio.h> +#include <time.h> +#include <joystick.h> + +static int datavar = 10; + +void main(void) +{ + int stackvar = 42; + int i, j; + + joy_install(&joy_static_stddrv); + + clrscr(); + + cputs("hello world"); + cputsxy(0, 2, "colors:" ); + for (i = 0; i < 16; ++i) { + textcolor(i); + cputc('X'); + } + textcolor(1); + + gotoxy(0,4); + cprintf("datavar: %02x\n\r", datavar); + cprintf("stackvar: %02x\n\r", stackvar); + + j = joy_count(); + gotoxy(0,10); + cprintf("Found %d Joysticks.", j); + + for(;;) + { + gotoxy(13,4); + cprintf("%02x", datavar); + gotoxy(13,5); + cprintf("%02x", stackvar); + ++datavar; ++stackvar; + + gotoxy(0,8); + cprintf("clock: %08x", clock()); + for (i = 0; i < 4; ++i) + { + gotoxy(0, 12 + i); + j = joy_read (i); + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s", + i, j, + (j & joy_masks[JOY_UP])? " up " : " ---- ", + (j & joy_masks[JOY_DOWN])? " down " : " ---- ", + (j & joy_masks[JOY_LEFT])? " left " : " ---- ", + (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", + (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); + } + } + for(;;); +} \ No newline at end of file From 9e1d39a409b02cba9277ec1231863a2c7f99b100 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 12 Jul 2015 16:40:52 +0200 Subject: [PATCH 183/351] more cleanup and fixing --- asminc/pce.inc | 4 +- cfg/pce.cfg | 23 +-- include/pce.h | 8 +- libsrc/pce/call.s | 17 --- libsrc/pce/clock.s | 8 +- libsrc/pce/condes.s | 96 ------------ libsrc/pce/conio.s | 3 - libsrc/pce/crt0.s | 215 ++++++++++++--------------- libsrc/pce/joy/pce-stdjoy.s | 5 - libsrc/pce/readme.txt | 31 +++- libsrc/pce/{_scrsize.s => scrsize.s} | 0 testcode/lib/pce/Makefile | 12 ++ testcode/lib/pce/conio.c | 5 +- 13 files changed, 159 insertions(+), 268 deletions(-) delete mode 100644 libsrc/pce/call.s delete mode 100644 libsrc/pce/condes.s rename libsrc/pce/{_scrsize.s => scrsize.s} (100%) create mode 100644 testcode/lib/pce/Makefile diff --git a/asminc/pce.inc b/asminc/pce.inc index 40e356cae..6d1541d64 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -11,7 +11,7 @@ CRAM_PTR = $34 ;2 CHARCOLOR = $36 RVS = $37 BGCOLOR = $38 -_tickcount = $39 ;2 +_tickcount = $39 ;4 screenrows = (224/8) charsperline = (512/8) @@ -74,11 +74,13 @@ CDR_MEM_ENABLE = $1807 .byte $ad .word arg1 .endmacro + ;; sta abs .macro staio arg1 .byte $8d .word arg1 .endmacro + ;; stz abs .macro stzio arg1 .byte $9c diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 566554b2e..adb420f32 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -28,13 +28,18 @@ SEGMENTS { } FEATURES { - CONDES: segment = STARTUP, - type=constructor, - label=__CONSTRUCTOR_TABLE__, - count=__CONSTRUCTOR_COUNT__; - - CONDES: segment = STARTUP, - type=destructor, - label=__DESTRUCTOR_TABLE__, - count=__DESTRUCTOR_COUNT__; + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = INIT; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; +# FIXME: interruptor support is missing +# CONDES: type = interruptor, +# label = __INTERRUPTOR_TABLE__, +# count = __INTERRUPTOR_COUNT__, +# segment = RODATA, +# import = __CALLIRQ__; } diff --git a/include/pce.h b/include/pce.h index 70d5800d0..912e0157b 100644 --- a/include/pce.h +++ b/include/pce.h @@ -28,13 +28,9 @@ /* */ /*****************************************************************************/ - - #ifndef _PCE_H #define _PCE_H - - /* Check for errors */ #if !defined(__PCE__) # error This module may only be used when compiling for the PCE! @@ -69,8 +65,8 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F -#define CLOCKS_PER_SEC 50 // ??? -#define CLK_TCK 50 // ?!? +#define CLOCKS_PER_SEC 50 // FIXME: is this correct? +#define CLK_TCK 50 // FIXME: is this correct? #define TV_NTSC 0 #define TV_PAL 1 diff --git a/libsrc/pce/call.s b/libsrc/pce/call.s deleted file mode 100644 index db120a72f..000000000 --- a/libsrc/pce/call.s +++ /dev/null @@ -1,17 +0,0 @@ -; -; CC65 runtime: call function via pointer in ax -; - - .export callax - -.code - -callax: - sta vec - stx vec+1 - jmp (vec) ; jump there - -.bss - -vec: - .res 2 \ No newline at end of file diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 5f360916c..4271fdc61 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -9,10 +9,10 @@ .proc _clock - ldy #0 ; Byte 3 is always zero - sty sreg+1 - sty sreg - + lda _tickcount+3 + sta sreg+1 + lda _tickcount+2 + sta sreg ldx _tickcount+1 lda _tickcount rts diff --git a/libsrc/pce/condes.s b/libsrc/pce/condes.s deleted file mode 100644 index aa28833c2..000000000 --- a/libsrc/pce/condes.s +++ /dev/null @@ -1,96 +0,0 @@ -; -; Ullrich von Bassewitz, 20.11.2000 -; -; CC65 runtime: Support for calling module constructors/destructors -; -; The condes routine must be called with the table address in a/x and the -; size of the table in y. The current implementation limits the table size -; to 254 bytes (127 vectors) but this shouldn't be problem for now and may -; be changed later. -; -; libinit and libdone call condes with the predefined module constructor and -; destructor tables, they must be called from the platform specific startup -; code. - - - .export initlib, donelib, condes - - .import callax - .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ - .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ - - - -.code - -; -------------------------------------------------------------------------- -; Initialize library modules - -.proc initlib - - lda #<__CONSTRUCTOR_TABLE__ - ldx #>__CONSTRUCTOR_TABLE__ - ldy #<(__CONSTRUCTOR_COUNT__*2) - bne condes - rts - -.endproc - - -; -------------------------------------------------------------------------- -; Cleanup library modules - -.proc donelib - - lda #<__DESTRUCTOR_TABLE__ - ldx #>__DESTRUCTOR_TABLE__ - ldy #<(__DESTRUCTOR_COUNT__*2) - bne condes - rts - -.endproc - - -; -------------------------------------------------------------------------- -; Generic table call handler - -.proc condes - - sta getbyt+1 - stx getbyt+2 - sty index - -loop: ldy index - beq done - dey - jsr getbyt - tax - dey - jsr getbyt - sty index - jsr callax -.ifpc02 - bra loop -.else - jmp loop -.endif - -done: rts - -.endproc - - -; -------------------------------------------------------------------------- -; Data. The getbyte routine is placed in the data segment cause it's patched -; at runtime. - -.bss - -index: .byte 0 - -.data - -getbyt: -;;getbyt_: - lda $FFFF,y - rts diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 60801e172..9f113f515 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -5,7 +5,6 @@ .import vdc_init .export initconio - .export _conio_init .constructor initconio, 24 @@ -46,8 +45,6 @@ set_palette: stz VCE_DATA_LO stz VCE_DATA_HI - ; so it will get linked in -_conio_init: rts ;---------------------------------------------------------------------------- diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 06454998b..eab27ba5c 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -7,37 +7,38 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .export __STARTUP__ : absolute = 1 ; Mark as startup - .import initlib, donelib - .import push0, _main, zerobss - .import initheap - .import tmp1,tmp2,tmp3 + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup - .import __RAM_START__, __RAM_SIZE__ ; Linker generated -;; .import __SRAM_START__, __SRAM_SIZE__ ; Linker generated - .import __ROM0_START__, __ROM0_SIZE__ ; Linker generated - .import __ROM_START__, __ROM_SIZE__ ; Linker generated - .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ ; Linker generated - .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ ; Linker generated - .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ ; Linker generated - .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ ; Linker generated - .import __BSS_SIZE__ + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 - .include "pce.inc" + ; Linker generated + .import __RAM_START__, __RAM_SIZE__ + .import __ROM0_START__, __ROM0_SIZE__ + .import __ROM_START__, __ROM_SIZE__ + .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ + .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ + .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ + .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ + .import __BSS_SIZE__ - .importzp sp - .importzp ptr1,ptr2 + .include "pce.inc" + + .importzp sp + .importzp ptr1,ptr2 ; ------------------------------------------------------------------------ ; Create an empty LOWCODE segment to avoid linker warnings -.segment "LOWCODE" + .segment "LOWCODE" ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. -.segment "STARTUP" + .segment "STARTUP" start: @@ -47,32 +48,32 @@ start: sei nop - csh ; set high speed CPU mode + csh ; set high speed CPU mode nop cld nop ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) + ldx #$FF ; Stack top ($21FF) txs ; at startup all MPRs are set to 0, so init them lda #$ff - tam #1 ; 0000-1FFF = Hardware page + tam #%00000001 ; 0000-1FFF = Hardware page lda #$F8 - tam #2 ; 2000-3FFF = Work RAM + tam #%00000010 ; 2000-3FFF = Work RAM ;lda #$F7 - ;tam #2 ; 4000-5FFF = Save RAM + ;tam #%00000100 ; 4000-5FFF = Save RAM ;lda #1 - ;tam #3 ; 6000-7FFF Page 2 + ;tam #%00001000 ; 6000-7FFF Page 2 ;lda #2 - ;tam #4 ; 8000-9FFF Page 3 + ;tam #%00010000 ; 8000-9FFF Page 3 ;lda #3 - ;tam #5 ; A000-BFFF Page 4 + ;tam #%00100000 ; A000-BFFF Page 4 ;lda #4 - ;tam #6 ; C000-DFFF Page 5 + ;tam #%01000000 ; C000-DFFF Page 5 ;lda #0 - ;tam #7 ; e000-fFFF hucard/syscard bank 0 + ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 ; Clear work RAM (2000-3FFF) stz <$00 @@ -88,110 +89,87 @@ start: .import vdc_init jsr vdc_init -;; jsr joy_init - ; Turn on background and VD interrupt/IRQ1 - lda #$05 sta IRQ_MASK ; IRQ1=on cli -; Clear the BSS data + ; Clear the BSS data + jsr zerobss - jsr zerobss - -; Copy the .data segment to RAM - - lda #<(__DATA_LOAD__) - ;;lda #<(__ROM0_START__ + __STARTUP_SIZE__+ __CODE_SIZE__+ __RODATA_SIZE__) - ;;lda #<(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) - sta ptr1 - lda #>(__DATA_LOAD__) - ;;lda #>(__ROM_START__ + __CODE_SIZE__+ __RODATA_SIZE__) - sta ptr1+1 - lda #<(__DATA_RUN__) - ;;lda #<(__SRAM_START__) - sta ptr2 - lda #>(__DATA_RUN__) - ;;lda #>(__SRAM_START__) - sta ptr2+1 - - ldx #>(__DATA_SIZE__) + ; Copy the .data segment to RAM + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y - iny - bne @l1 + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 - dex - bne @l2 + dex + bne @l2 - ; copy remaining bytes + ; copy remaining bytes @s1: - - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y - iny - cpy #<(__DATA_SIZE__) - bne @l3 + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 -; setup the stack + ; setup the stack + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 -; lda #<(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp -; lda #>(__RAM_START__ + __DATA_SIZE__ + __BSS_SIZE__) - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 ; Set argument stack ptr + ; Init the Heap + jsr initheap -; Init the Heap - jsr initheap + ; Call module constructors + jsr initlib -;jmp * + ;; FIXME: this should be called from a constructor instead + .import initconio + jsr initconio -; Call module constructors + ; Pass an empty command line + jsr push0 ; argc + jsr push0 ; argv - jsr initlib - - ;; FIXME: this should be called from a constructor instead - .import initconio - jsr initconio - -; Pass an empty command line - - -;jmp * - - jsr push0 ; argc - jsr push0 ; argv -go: - ldy #4 ; Argument size - jsr _main ; call the users code - -; Call module destructors. This is also the _exit entry. + ldy #4 ; Argument size + jsr _main ; call the users code + ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors + jsr donelib ; Run module destructors -; reset the PCEngine - - jmp start + ; reset the PCEngine (start over) + jmp start ; ------------------------------------------------------------------------ ; System V-Blank Interupt +; FIXME: hooks should be provided so the user can abuse the IRQ ; ------------------------------------------------------------------------ _irq1: @@ -201,10 +179,13 @@ _irq1: inc _tickcount - bne @s + bne @s1 inc _tickcount+1 -@s: - + bne @s1 + inc _tickcount+2 + bne @s1 + inc _tickcount+3 +@s1: ; Acknowlege interrupt ldaio VDC_CTRL @@ -227,14 +208,10 @@ initmainargs: ; ------------------------------------------------------------------------ ; hardware vectors ; ------------------------------------------------------------------------ - .segment "VECTORS" - ;;.org $fff6 - - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer - .word _nmi ; $fffc NMI - .word start ; $fffe reset - - + .segment "VECTORS" + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 6bc6bdf57..1aa98e16d 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -25,11 +25,6 @@ ; Button state masks (8 values) -;extern const unsigned char joy_masks[8]; - - .export _joy_masks - -_joy_masks: .byte $10 ; JOY_UP .byte $40 ; JOY_DOWN .byte $80 ; JOY_LEFT diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index e99b55122..cd91de97a 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -1,19 +1,23 @@ +PC-Engine (PCE) target support for cc65. this is still work in progress and +a couple of things need to be fixed: +-------------------------------------------------------------------------------- -joystick support should get verified on real hw, the masks for buttons may be -wrong. - -clock() does not work for unknown reasons - -get_tv() is a dummy function and always returns 0 +joystick support should get verified on real hw + - the masks for buttons may be wrong. + - 6 button gamepads are different and need slightly different code revers() is a dummy function, actual reverse output is not supported yet waitvblank() is missing +get_tv() is missing some graphical petscii chars should get added to the charset conio-init should get initialized from a constructor rather than always get -called from crt0 +called from crt0 (which for some reason doesnt work) -> see conio.s, it should +get linked if _any_ of the conio function is used + +interruptor support in crt0 (and cfg) is missing -------------------------------------------------------------------------------- @@ -29,3 +33,16 @@ w/s/a/d up/down/left/right numpad 2 (?) button numpad 3 (?) button enter (start) button + +-------------------------------------------------------------------------------- +some useful resources on PCE coding: + +http://blog.blockos.org/?tag=pc-engine +http://pcedev.blockos.org/viewforum.php?f=5 +http://www.romhacking.net/?page=documents&category=&platform=4&game=&author=&perpage=20&level=&title=&desc=&docsearch=Go +http://archaicpixels.com/Main_Page + +http://www.magicengine.com/mkit/doc.html + +https://github.com/uli/huc +http://www.zeograd.com/parse.php?src=hucf \ No newline at end of file diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/scrsize.s similarity index 100% rename from libsrc/pce/_scrsize.s rename to libsrc/pce/scrsize.s diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile new file mode 100644 index 000000000..364074180 --- /dev/null +++ b/testcode/lib/pce/Makefile @@ -0,0 +1,12 @@ + +all: conio.pce + +conio.pce: conio.c + ../../../bin/cl65 -t pce conio.c ../../../joy/pce-stdjoy.joy --mapfile conio.map -o conio.pce + +clean: + $(RM) conio.pce + +test: conio.pce + mednafen -force_module pce conio.pce + diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 306eb1ebb..0c5c89c57 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -9,6 +9,7 @@ void main(void) { int stackvar = 42; int i, j; + clock_t clk; joy_install(&joy_static_stddrv); @@ -39,7 +40,9 @@ void main(void) ++datavar; ++stackvar; gotoxy(0,8); - cprintf("clock: %08x", clock()); + clk = clock(); + cprintf("clock: %08lx", clk); + for (i = 0; i < 4; ++i) { gotoxy(0, 12 + i); From 515a61a302a1923de5816c8418f0af56bb4dc77e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 13 Jul 2015 12:10:09 +0200 Subject: [PATCH 184/351] added imports for conio init to conio functions, so the constructor will get linked and called automatically --- libsrc/pce/clrscr.s | 5 +++++ libsrc/pce/color.s | 6 ++++++ libsrc/pce/cputc.s | 6 ++++++ libsrc/pce/crt0.s | 4 ---- libsrc/pce/gotoxy.s | 5 +++++ libsrc/pce/kplot.s | 5 +++++ libsrc/pce/readme.txt | 7 +++---- libsrc/pce/revers.s | 8 ++++++++ libsrc/pce/scrsize.s | 2 ++ testcode/lib/pce/conio.c | 4 ++-- 10 files changed, 42 insertions(+), 10 deletions(-) diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 93628ddd8..59fda4f2e 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -23,3 +23,8 @@ colloop: lda #' ' rts +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 0ec35f5b3..03d93b186 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -55,3 +55,9 @@ colors: ; G R B .word ((7<<6)+(4<<3)+(4)) ; d light green .word ((4<<6)+(4<<3)+(7)) ; e light blue .word ((6<<6)+(6<<3)+(6)) ; f light gray + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index ec63b7565..e503ee6f2 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -91,3 +91,9 @@ putchar: staio VDC_DATA_HI rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index eab27ba5c..e67039d43 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -149,10 +149,6 @@ start: ; Call module constructors jsr initlib - ;; FIXME: this should be called from a constructor instead - .import initconio - jsr initconio - ; Pass an empty command line jsr push0 ; argc jsr push0 ; argv diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index 24f917cd6..c6b937177 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -13,4 +13,9 @@ _gotoxy: sta CURS_X ; Set X jmp plot ; Set the cursor position +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index beb151a7b..eb4e79e04 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -29,4 +29,9 @@ _plothi: .byte >($0000+(line*$80)) .endrepeat +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index cd91de97a..c7b3aed3d 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -13,12 +13,11 @@ get_tv() is missing some graphical petscii chars should get added to the charset -conio-init should get initialized from a constructor rather than always get -called from crt0 (which for some reason doesnt work) -> see conio.s, it should -get linked if _any_ of the conio function is used - interruptor support in crt0 (and cfg) is missing +conio lacks support for different screen sizes, which could be used with +different video modes + -------------------------------------------------------------------------------- a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index c39a9f843..d3e6f8930 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,13 @@ +; FIXME: actual revers output is not supported yet + .export _revers _revers: lda #0 rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import initconio +conio_init = initconio diff --git a/libsrc/pce/scrsize.s b/libsrc/pce/scrsize.s index 6e2b84a41..254676aae 100644 --- a/libsrc/pce/scrsize.s +++ b/libsrc/pce/scrsize.s @@ -8,6 +8,8 @@ _screensize: ldy ysize rts +; FIXME: changing the video mode allows for different screen sizes + .rodata .export xsize, ysize diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 0c5c89c57..993d93597 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -42,7 +42,7 @@ void main(void) gotoxy(0,8); clk = clock(); cprintf("clock: %08lx", clk); - + for (i = 0; i < 4; ++i) { gotoxy(0, 12 + i); @@ -58,4 +58,4 @@ void main(void) } } for(;;); -} \ No newline at end of file +} From 83391ab67c8aacf260b32888849dc01f0ae8fe8d Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 14 Jul 2015 17:22:47 +0200 Subject: [PATCH 185/351] some more tweaking, added docs page --- asminc/pce.inc | 12 ++- doc/index.sgml | 3 + doc/pce.sgml | 198 +++++++++++++++++++++++++++++++++++++++ libsrc/pce/conio.s | 18 ++-- libsrc/pce/readme.txt | 2 +- testcode/lib/pce/conio.c | 12 +++ 6 files changed, 234 insertions(+), 11 deletions(-) create mode 100644 doc/pce.sgml diff --git a/asminc/pce.inc b/asminc/pce.inc index 6d1541d64..767f1a529 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -52,12 +52,22 @@ VDC_DATA_HI = $0003 ; bitmap of the palette data is this: 0000000gggrrrbbb. ; You can read and write the DAC-registers. -VCE_CTRL = $0400 ; write$00 to reset +VCE = $0400 ; base + +VCE_CTRL = $0400 ; write$00 to reset VCE_ADDR_LO = $0402 ; LSB of byte offset into palette VCE_ADDR_HI = $0403 ; MSB of byte offset into palette VCE_DATA_LO = $0404 ; LSB of 16-bit palette data VCE_DATA_HI = $0405 ; MSB of 16-bit palette data +; programmable sound generator (PSG) + +PSG = $0800 ; base + +; timer + +TIMER = $0c00 ; base + TIMER_COUNT = $0c00 TIMER_CTRL = $0c01 diff --git a/doc/index.sgml b/doc/index.sgml index 921b8c03d..eb13c9af5 100644 --- a/doc/index.sgml +++ b/doc/index.sgml @@ -137,6 +137,9 @@ <tag><htmlurl url="osi.html" name="osi.html"></tag> Topics specific to the Ohio Scientific machines. + <tag><htmlurl url="pce.html" name="pce.html"></tag> + Topics specific to NEC PC-Engine (TurboGrafx) Console. + <tag><htmlurl url="pet.html" name="pet.html"></tag> Topics specific to the Commodore PET machines. diff --git a/doc/pce.sgml b/doc/pce.sgml new file mode 100644 index 000000000..4c395ae43 --- /dev/null +++ b/doc/pce.sgml @@ -0,0 +1,198 @@ +<!doctype linuxdoc system> + +<article> + +<title>PC-Engine (TurboGrafx) System specific information for cc65 +<author> +<url url="mailto:groepaz@gmx.net" name="Groepaz/Hitmen"> +<date>2015-07-14 + +<abstract> +An overview over the PCE runtime system as it is implemented for the +cc65 C compiler. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + +<sect>Overview<p> + +This file contains an overview of the PCE runtime system as it comes +with the cc65 C compiler. It describes the memory layout, PCE specific header +files, available drivers, and any pitfalls specific to that platform. + +Please note that PCE specific functions are just mentioned here, they are +described in detail in the separate <url url="funcref.html" name="function +reference">. Even functions marked as "platform dependent" may be available on +more than one platform. Please see the function reference for more +information. + + +<sect>Binary format<p> + +The standard binary output format generated by the linker for the PCE target +is a cartridge image with no header. It is of course possible to change this +behaviour by using a modified startup file and linker config. + +<sect>Memory layout<p> + +cc65 generated programs with the default setup run with the I/O area and a +CHR bank enabled, which gives a usable memory range of $8000 - $FFF3. +All boot ROM entry points may be called directly without additional code. + +Special locations: + +<descrip> + <tag/Text screen and Font/ + The text screen is located at VRAM $0000, + the Font is located at VRAM $2000. + + <tag/Stack/ + The C runtime stack is located in system RAM at $3FFF and growing downwards. + + <tag/BSS and Data/ + + The BSS (uninitialized variables) and Data (initialized variables) sections are + placed one after the other into system RAM at $2000. + + <tag/Heap/ + The C heap is located after the end of the Data section and grows towards the C + runtime stack. + + <tag/Code/ + The startup code is located at $E000 in the System/Hardware bank. Further + code can be placed in other ROM banks, this must be done manually however. + +</descrip><p> + + + +<sect>Platform specific header files<p> + +Programs containing PCE specific code may use the <tt/pce.h/ header file. + + +<sect1>PCE specific functions<p> + +<itemize> +<item>waitvblank +<item>get_tv +</itemize> + + + +<sect1>Hardware access<p> + +The following pseudo variables declared in the <tt/pce.inc/ include file do +allow access to hardware located in the address space. + +<descrip> + + <tag><tt/PSG/</tag> + The <tt/PSG/ defines allow access to the PSG chip (Programmable Sound Generator). + + <tag><tt/VCE/</tag> + The <tt/VCE/ defines allow access to the VCE chip (Video Color Encoder). + + <tag><tt/VDC/</tag> + The <tt/VDC/ defines allow access to the VDC chip (Video Display Controller). + +</descrip><p> + + + +<sect>Loadable drivers<p> + +All drivers must be statically linked because no file I/O is available. +The names in the parentheses denote the symbols to be used for static linking of the drivers. + + +<sect1>Graphics drivers<p> + +<descrip> + +No TGI graphics drivers are currently available for the PCE. + +</descrip><p> + + +<sect1>Extended memory drivers<p> + +No extended memory drivers are currently available for the PCE. + + +<sect1>Joystick drivers<p> + +<descrip> + + <tag><tt/pce-stdjoy.joy (pce_stdjoy)/</tag> + A joystick driver for the standard two buttons joypad is available. + +</descrip><p> + + +<sect1>Mouse drivers<p> + +No mouse drivers are currently available for the PCE. + + +<sect1>RS232 device drivers<p> + +No serial drivers are currently available for the PCE. + + + +<sect>Limitations<p> + +<sect1>Disk I/O<p> + +The existing library for the PCE doesn't implement C file +I/O. There are no hacks for the <tt/read()/ and <tt/write()/ routines. + +To be more concrete, this limitation means that you cannot use any of the +following functions (and a few others): + +<itemize> +<item>fclose +<item>fopen +<item>fread +<item>fprintf +<item>fputc +<item>fscanf +<item>fwrite +<item>... +</itemize> + + + +<sect>Other hints<p> + + + +<sect>License<p> + +This software is provided 'as-is', without any expressed or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +<enum> +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> + + + diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 9f113f515..2556833b0 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -59,18 +59,18 @@ conio_init: st2 #>$2000 ; ptr to font data - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 + staio VDC_DATA_LO ; bitplane 0 + stzio VDC_DATA_HI ; bitplane 1 clc ; increment font pointer lda ptr1 @@ -90,9 +90,9 @@ fillloop: st1 #$00 bne charloop ; next character ldx #0 - stx BGCOLOR + stx BGCOLOR inx - stx CHARCOLOR + stx CHARCOLOR rts diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index c7b3aed3d..5b170b7f7 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -44,4 +44,4 @@ http://archaicpixels.com/Main_Page http://www.magicengine.com/mkit/doc.html https://github.com/uli/huc -http://www.zeograd.com/parse.php?src=hucf \ No newline at end of file +http://www.zeograd.com/parse.php?src=hucf diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 993d93597..88c343af2 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -2,6 +2,8 @@ #include <conio.h> #include <time.h> #include <joystick.h> +#include <string.h> +#include <stdlib.h> static int datavar = 10; @@ -10,6 +12,7 @@ void main(void) int stackvar = 42; int i, j; clock_t clk; + char *p; joy_install(&joy_static_stddrv); @@ -31,6 +34,15 @@ void main(void) gotoxy(0,10); cprintf("Found %d Joysticks.", j); + for (i = 0; i < 4; ++i) { + gotoxy(0, 17 + i); + p = malloc(16); + memcpy(p, "01234567890abcdef", 16); + cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, + p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] + ); + } + for(;;) { gotoxy(13,4); From ac27ed301aa36183825b98dc5c22635ad1e1bc9f Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 14 Jul 2015 19:55:41 +0200 Subject: [PATCH 186/351] _tickcount -> tickcount --- asminc/pce.inc | 2 +- libsrc/pce/clock.s | 9 +++++---- libsrc/pce/crt0.s | 8 ++++---- libsrc/pce/readme.txt | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 767f1a529..424dd8c36 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -11,7 +11,7 @@ CRAM_PTR = $34 ;2 CHARCOLOR = $36 RVS = $37 BGCOLOR = $38 -_tickcount = $39 ;4 +tickcount = $39 ;4 screenrows = (224/8) charsperline = (512/8) diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 4271fdc61..6f939f078 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -6,15 +6,16 @@ .export _clock .importzp sreg +;; .importzp tickcount .proc _clock - lda _tickcount+3 + lda tickcount+3 sta sreg+1 - lda _tickcount+2 + lda tickcount+2 sta sreg - ldx _tickcount+1 - lda _tickcount + ldx tickcount+1 + lda tickcount rts .endproc diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index e67039d43..1a7a04e0b 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -174,13 +174,13 @@ _irq1: phy - inc _tickcount + inc tickcount bne @s1 - inc _tickcount+1 + inc tickcount+1 bne @s1 - inc _tickcount+2 + inc tickcount+2 bne @s1 - inc _tickcount+3 + inc tickcount+3 @s1: ; Acknowlege interrupt ldaio VDC_CTRL diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index 5b170b7f7..d07150913 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -14,6 +14,7 @@ get_tv() is missing some graphical petscii chars should get added to the charset interruptor support in crt0 (and cfg) is missing +- clock() should be hooked to a VBL interrupt conio lacks support for different screen sizes, which could be used with different video modes From c3d45e4c4767be66388ab719b3428fc4bcbd7b84 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 15 Jul 2015 13:18:12 +0200 Subject: [PATCH 187/351] fixed issues found by gregg --- asminc/pce.inc | 21 ++---------- include/pce.h | 3 -- include/time.h | 4 +++ libsrc/pce/clrscr.s | 8 ++--- libsrc/pce/conio.s | 24 ++++++------- libsrc/pce/cputc.s | 21 ++++++------ libsrc/pce/crt0.s | 84 ++++++++++++++++++++------------------------- libsrc/pce/vdc.s | 10 +++--- 8 files changed, 76 insertions(+), 99 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 424dd8c36..98364815b 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -42,6 +42,9 @@ VDC_DESR =16 ; (DMA) Destination Register VDC_LENR =17 ; (DMA) Length Register VDC_SATB =18 ; Sprite Attribute Table +; VDC port +; Note: absolute addressing mode must be used when writing to this port + VDC_CTRL = $0000 VDC_DATA_LO = $0002 VDC_DATA_HI = $0003 @@ -79,24 +82,6 @@ IRQ_STATUS = $1403 CDR_MEM_DISABLE = $1803 CDR_MEM_ENABLE = $1807 -;; lda abs -.macro ldaio arg1 - .byte $ad - .word arg1 -.endmacro - -;; sta abs -.macro staio arg1 - .byte $8d - .word arg1 -.endmacro - -;; stz abs -.macro stzio arg1 - .byte $9c - .word arg1 -.endmacro - ; Write VDC register .macro VREG arg1,arg2 st0 #arg1 diff --git a/include/pce.h b/include/pce.h index 912e0157b..613da2b0d 100644 --- a/include/pce.h +++ b/include/pce.h @@ -65,9 +65,6 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F -#define CLOCKS_PER_SEC 50 // FIXME: is this correct? -#define CLK_TCK 50 // FIXME: is this correct? - #define TV_NTSC 0 #define TV_PAL 1 #define TV_OTHER 2 diff --git a/include/time.h b/include/time.h index c70ffa718..8fc787228 100644 --- a/include/time.h +++ b/include/time.h @@ -99,6 +99,10 @@ unsigned _clocks_per_sec (void); #elif defined(__NES__) # define CLK_TCK 50 /* POSIX */ # define CLOCKS_PER_SEC 50 /* ANSI */ +#elif defined(__PCE__) +/* FIXME: we likely need to read it at runtime */ +# define CLK_TCK 50 /* POSIX */ +# define CLOCKS_PER_SEC 50 /* ANSI */ #elif defined(__GEOS__) # define CLK_TCK 1 /* POSIX */ # define CLOCKS_PER_SEC 1 /* ANSI */ diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 59fda4f2e..9279f1e25 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -11,10 +11,10 @@ _clrscr: st0 #VDC_VWR ldy #$40 rowloop: ldx #$80 -colloop: lda #' ' - staio VDC_DATA_LO - lda #$02 - staio VDC_DATA_HI +colloop: lda #' ' + sta a:VDC_DATA_LO + lda #$02 + sta a:VDC_DATA_HI dex bne colloop diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 2556833b0..a8a9da244 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -4,8 +4,6 @@ .import psg_init .import vdc_init - .export initconio - .constructor initconio, 24 .macpack longbranch @@ -28,17 +26,19 @@ set_palette: ldx #0 @lp: - .repeat 16 - lda colors,x + ldy #16 +@lp1: + lda colors,x sta VCE_DATA_LO - lda colors+1,x + lda colors+1,x sta VCE_DATA_HI - .endrepeat + dey + bne @lp1 inx inx - cpx #16*2 - jne @lp + cpx #16*2 + jne @lp stz VCE_ADDR_LO stz VCE_ADDR_HI @@ -68,9 +68,9 @@ conio_init: ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: - lda (ptr1) - staio VDC_DATA_LO ; bitplane 0 - stzio VDC_DATA_HI ; bitplane 1 + lda (ptr1) + sta a:VDC_DATA_LO ; bitplane 0 + stz a:VDC_DATA_HI ; bitplane 1 clc ; increment font pointer lda ptr1 @@ -89,7 +89,7 @@ fillloop: st1 #$00 dey bne charloop ; next character - ldx #0 + ldx #0 stx BGCOLOR inx stx CHARCOLOR diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index e503ee6f2..e2e345ac2 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -69,26 +69,25 @@ putchar: st0 #VDC_MAWR ; Memory Adress Write lda SCREEN_PTR - staio VDC_DATA_LO + sta a:VDC_DATA_LO lda SCREEN_PTR+1 - staio VDC_DATA_HI + sta a:VDC_DATA_HI st0 #VDC_VWR ; VWR txa - staio VDC_DATA_LO ; character + sta a:VDC_DATA_LO ; character - lda CHARCOLOR + lda CHARCOLOR - asl a - asl a - asl a - asl a + asl a + asl a + asl a + asl a - and #$f0 - ora #$02 - staio VDC_DATA_HI + ora #$02 + sta a:VDC_DATA_HI rts diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 1a7a04e0b..e456bdeac 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -30,11 +30,6 @@ .importzp sp .importzp ptr1,ptr2 -; ------------------------------------------------------------------------ -; Create an empty LOWCODE segment to avoid linker warnings - - .segment "LOWCODE" - ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. @@ -42,7 +37,7 @@ start: -; setup the CPU and System-IRQ + ; setup the CPU and System-IRQ ; Initialize CPU @@ -96,58 +91,55 @@ start: cli ; Clear the BSS data - jsr zerobss + jsr zerobss ; Copy the .data segment to RAM - lda #<(__DATA_LOAD__) - sta ptr1 - lda #>(__DATA_LOAD__) - sta ptr1+1 - lda #<(__DATA_RUN__) - sta ptr2 - lda #>(__DATA_RUN__) - sta ptr2+1 + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 - ldx #>(__DATA_SIZE__) + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages ; copy one page - ldy #0 + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y + lda (ptr1),y + sta (ptr2),y iny - bne @l1 + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 dex - bne @l2 + bne @l2 ; copy remaining bytes @s1: ; copy one page - ldy #0 + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y + lda (ptr1),y + sta (ptr2),y iny - cpy #<(__DATA_SIZE__) - bne @l3 + cpy #<(__DATA_SIZE__) + bne @l3 ; setup the stack - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 - - ; Init the Heap - jsr initheap + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp+1 ; Call module constructors - jsr initlib + jsr initlib ; Pass an empty command line jsr push0 ; argc @@ -158,7 +150,7 @@ start: ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors + jsr donelib ; Run module destructors ; reset the PCEngine (start over) jmp start @@ -174,16 +166,16 @@ _irq1: phy - inc tickcount - bne @s1 - inc tickcount+1 - bne @s1 - inc tickcount+2 - bne @s1 - inc tickcount+3 + inc tickcount + bne @s1 + inc tickcount+1 + bne @s1 + inc tickcount+2 + bne @s1 + inc tickcount+3 @s1: ; Acknowlege interrupt - ldaio VDC_CTRL + lda a:VDC_CTRL ply plx diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index d1ead937e..0f42fe1b0 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -6,7 +6,7 @@ HIRES = 1 .export vdc_init vdc_init: - ldaio VDC_CTRL + lda a:VDC_CTRL VREG $00, $0000 ; MAWR VREG $01, $0000 ; MARR @@ -20,21 +20,21 @@ vdc_init: VREG $0E, $000C ; CRTC - VDE VREG $0F, $0000 ; DCR - .if HIRES +.if HIRES VREG $0A, $0C02 ; CRTC - HSR VREG $0B, $043C ; CRTC - HDS lda #$06 sta VCE_CTRL - .else +.else VREG $0A, $0202 ; CRTC - HSR VREG $0B, $041F ; CRTC - HDS lda #$04 sta VCE_CTRL - .endif +.endif - ldaio VDC_CTRL + lda a:VDC_CTRL rts From 1414411bba07a7c15c75dbf46fbb7b227d82161e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 15 Jul 2015 19:46:26 +0200 Subject: [PATCH 188/351] added waitvblank and fixed get_tv --- doc/pce.sgml | 4 ++-- include/pce.h | 4 ++-- libsrc/pce/readme.txt | 3 --- libsrc/pce/waitvblank.s | 18 ++++++++++++++++++ testcode/lib/pce/conio.c | 19 +++++++++++++++++-- 5 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 libsrc/pce/waitvblank.s diff --git a/doc/pce.sgml b/doc/pce.sgml index 4c395ae43..2d14e8361 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -77,8 +77,8 @@ Programs containing PCE specific code may use the <tt/pce.h/ header file. <sect1>PCE specific functions<p> <itemize> -<item>waitvblank -<item>get_tv +<item>waitvblank</item> +<item>get_tv</item> (since all PCE systems are NTSC, this always returns TV_NTSC) </itemize> diff --git a/include/pce.h b/include/pce.h index 613da2b0d..74b6409e1 100644 --- a/include/pce.h +++ b/include/pce.h @@ -83,8 +83,8 @@ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ void waitvblank (void); /* Wait for the vertical blanking */ -/* FIXME: not implemented */ -unsigned char get_tv (void); +/* all PCE are NTSC */ +#define get_tv() TV_NTSC /* Return the video mode the machine is using. */ diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index d07150913..b201893d1 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -8,9 +8,6 @@ joystick support should get verified on real hw revers() is a dummy function, actual reverse output is not supported yet -waitvblank() is missing -get_tv() is missing - some graphical petscii chars should get added to the charset interruptor support in crt0 (and cfg) is missing diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s new file mode 100644 index 000000000..2ded2835e --- /dev/null +++ b/libsrc/pce/waitvblank.s @@ -0,0 +1,18 @@ +; +; void waitvblank (void); +; + + .include "pce.inc" + + .export _waitvblank +;; .importzp tickcount + +.proc _waitvblank + + lda tickcount +@lp: cmp tickcount + beq @lp + rts + +.endproc + diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 88c343af2..92431d142 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -43,8 +43,22 @@ void main(void) ); } - for(;;) - { + i = get_tv(); + gotoxy(30,0); + cputs("TV Mode: "); + switch(i) { + case TV_NTSC: + cputs("NTSC"); + break; + case TV_PAL: + cputs("PAL"); + break; + case TV_OTHER: + cputs("OTHER"); + break; + } + + for(;;) { gotoxy(13,4); cprintf("%02x", datavar); gotoxy(13,5); @@ -68,6 +82,7 @@ void main(void) (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); } + waitvblank(); } for(;;); } From 21ef6b8510ccd640b9099966424c174747de1524 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 16:00:32 +0200 Subject: [PATCH 189/351] fixed screensize, timertick, revers mode --- asminc/pce.inc | 3 +-- include/time.h | 5 ++--- libsrc/pce/{scrsize.s => _scrsize.s} | 9 ++++---- libsrc/pce/conio.s | 33 ++++++++++++++++++++++------ libsrc/pce/cputc.s | 3 ++- libsrc/pce/readme.txt | 5 ----- libsrc/pce/revers.s | 24 +++++++++++++++----- testcode/lib/pce/conio.c | 31 ++++++++++++++++++++++++++ 8 files changed, 86 insertions(+), 27 deletions(-) rename libsrc/pce/{scrsize.s => _scrsize.s} (59%) diff --git a/asminc/pce.inc b/asminc/pce.inc index 98364815b..851b2f32a 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -14,8 +14,7 @@ BGCOLOR = $38 tickcount = $39 ;4 screenrows = (224/8) -charsperline = (512/8) -xsize = charsperline +charsperline = 61 CH_HLINE = 7 CH_VLINE = 7 diff --git a/include/time.h b/include/time.h index 8fc787228..12f130f52 100644 --- a/include/time.h +++ b/include/time.h @@ -100,9 +100,8 @@ unsigned _clocks_per_sec (void); # define CLK_TCK 50 /* POSIX */ # define CLOCKS_PER_SEC 50 /* ANSI */ #elif defined(__PCE__) -/* FIXME: we likely need to read it at runtime */ -# define CLK_TCK 50 /* POSIX */ -# define CLOCKS_PER_SEC 50 /* ANSI */ +# define CLK_TCK 60 /* POSIX */ +# define CLOCKS_PER_SEC 60 /* ANSI */ #elif defined(__GEOS__) # define CLK_TCK 1 /* POSIX */ # define CLOCKS_PER_SEC 1 /* ANSI */ diff --git a/libsrc/pce/scrsize.s b/libsrc/pce/_scrsize.s similarity index 59% rename from libsrc/pce/scrsize.s rename to libsrc/pce/_scrsize.s index 254676aae..8dab2cf7b 100644 --- a/libsrc/pce/scrsize.s +++ b/libsrc/pce/_scrsize.s @@ -1,9 +1,10 @@ ; ; Screen size variables ; + .include "pce.inc" - .export _screensize -_screensize: + .export screensize +screensize: ldx xsize ldy ysize rts @@ -13,5 +14,5 @@ _screensize: .rodata .export xsize, ysize -xsize: .byte 64 -ysize: .byte 28 +xsize: .byte charsperline +ysize: .byte screenrows diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index a8a9da244..4fb3b1394 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -51,7 +51,7 @@ set_palette: ; ;---------------------------------------------------------------------------- - .importzp ptr1 + .importzp ptr1, tmp1 conio_init: ; Load font st0 #VDC_MAWR @@ -65,10 +65,35 @@ conio_init: sta ptr1+1 st0 #VDC_VWR ; VWR + + lda #0 + sta tmp1 + jsr copy + + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 + + lda #$ff + sta tmp1 + jsr copy + + + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR + + + rts + +copy: ldy #$80 ; 128 chars charloop: ldx #$08 ; 8 bytes/char lineloop: lda (ptr1) + eor tmp1 sta a:VDC_DATA_LO ; bitplane 0 stz a:VDC_DATA_HI ; bitplane 1 @@ -89,12 +114,6 @@ fillloop: st1 #$00 dey bne charloop ; next character - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR - - rts .rodata diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index e2e345ac2..918f39e29 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -7,6 +7,7 @@ .export newline, plot .import popa, _gotoxy .import PLOT + .import xsize .importzp tmp3,tmp4 @@ -38,7 +39,7 @@ cputdirect: advance: ldy CURS_X iny - cpy #xsize + cpy xsize bne L3 jsr newline ; new line ldy #0 ; + cr diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index b201893d1..7dd857f21 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -6,16 +6,11 @@ joystick support should get verified on real hw - the masks for buttons may be wrong. - 6 button gamepads are different and need slightly different code -revers() is a dummy function, actual reverse output is not supported yet - some graphical petscii chars should get added to the charset interruptor support in crt0 (and cfg) is missing - clock() should be hooked to a VBL interrupt -conio lacks support for different screen sizes, which could be used with -different video modes - -------------------------------------------------------------------------------- a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index d3e6f8930..061023d09 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,10 +1,24 @@ -; FIXME: actual revers output is not supported yet + .include "pce.inc" - .export _revers -_revers: - lda #0 - rts + .export _revers + +.proc _revers + + ldx #$00 ; Assume revers off + tay ; Test onoff + beq L1 ; Jump if off + ldx #$80 ; Load on value + ldy #$00 ; Assume old value is zero +L1: lda RVS ; Load old value + stx RVS ; Set new value + beq L2 ; Jump if old value zero + iny ; Make old value = 1 +L2: ldx #$00 ; Load high byte of result + tya ; Load low byte, set CC + rts + +.endproc ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 92431d142..b94c91877 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -13,10 +13,12 @@ void main(void) int i, j; clock_t clk; char *p; + unsigned char xsize, ysize, n; joy_install(&joy_static_stddrv); clrscr(); + screensize(&xsize, &ysize); cputs("hello world"); cputsxy(0, 2, "colors:" ); @@ -43,6 +45,25 @@ void main(void) ); } + gotoxy(0,ysize - 1); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + + gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + for (i = 0; i < (xsize * 5); ++i) { + cputc('#'); + } + gotoxy(0,ysize - 1 - ((256 + xsize) / xsize)); + for (i = 0; i < 256; ++i) { + if ((i != '\n') && (i != '\r')) { + cputc(i); + } + } + i = get_tv(); gotoxy(30,0); cputs("TV Mode: "); @@ -57,6 +78,7 @@ void main(void) cputs("OTHER"); break; } + cprintf(" %dx%d", xsize, ysize); for(;;) { gotoxy(13,4); @@ -82,7 +104,16 @@ void main(void) (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); } + + gotoxy(xsize - 10, 3); + j = (n >> 5) & 1; + revers(j); + cputc(j ? 'R' : ' '); + cputs(" revers"); + revers(0); + waitvblank(); + ++n; } for(;;); } From d229d51be5901d7b57ea831c663c130d83a9f8e9 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 16:54:40 +0200 Subject: [PATCH 190/351] make sure clocktick starts at zero --- libsrc/pce/clock.s | 32 +++++++++++++++++++++----------- libsrc/pce/crt0.s | 4 ++-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 6f939f078..5d0aa78f4 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -2,20 +2,30 @@ ; clock_t clock (void); ; - .include "pce.inc" + .include "pce.inc" - .export _clock - .importzp sreg -;; .importzp tickcount + .export _clock + .importzp sreg +;; .importzp tickcount .proc _clock - lda tickcount+3 - sta sreg+1 - lda tickcount+2 - sta sreg - ldx tickcount+1 - lda tickcount - rts + lda tickcount+3 + sta sreg+1 + lda tickcount+2 + sta sreg + ldx tickcount+1 + lda tickcount + rts .endproc + + .constructor initclock, 24 + +initclock: + lda #0 + ldx #3 +@lp: sta tickcount,x + dex + bpl @lp + rts \ No newline at end of file diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index e456bdeac..2b8455a59 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -88,8 +88,6 @@ start: lda #$05 sta IRQ_MASK ; IRQ1=on - cli - ; Clear the BSS data jsr zerobss @@ -141,6 +139,8 @@ start: ; Call module constructors jsr initlib + cli ; allow IRQ only after constructors have run + ; Pass an empty command line jsr push0 ; argc jsr push0 ; argv From 3119be2a1e0d174b7ff4ee7bf485bab3122d26a6 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 17:33:00 +0200 Subject: [PATCH 191/351] added some cbm-like gfx chars to draw lines and boxes --- include/pce.h | 26 +++++----- libsrc/pce/readme.txt | 2 - libsrc/pce/vga.inc | 112 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 114 insertions(+), 26 deletions(-) diff --git a/include/pce.h b/include/pce.h index 74b6409e1..27f70de0f 100644 --- a/include/pce.h +++ b/include/pce.h @@ -36,16 +36,20 @@ # error This module may only be used when compiling for the PCE! #endif -/* FIXME: the respective characters are not present in the VGA charset (yet) */ -#define CH_CROSS 0x10 +#define CH_HLINE 1 +#define CH_VLINE 2 +#define CH_CROSS 3 +#define CH_ULCORNER 4 +#define CH_URCORNER 5 +#define CH_LLCORNER 6 +#define CH_LRCORNER 7 +#define CH_TTEE 8 +#define CH_BTEE 9 +#define CH_LTEE 10 +#define CH_RTEE 11 -#define CH_RTEE 0x17 -#define CH_LTEE 0x0f - -#define CH_ULCORNER 0x10 -#define CH_URCORNER 0x10 -#define CH_LLCORNER 0x10 -#define CH_LRCORNER 0x10 +#define CH_ENTER 13 +#define CH_PI 18 /* Color defines (CBM compatible, for conio) */ #define COLOR_BLACK 0x00 @@ -79,14 +83,12 @@ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ #define JOY_START 6 #define JOY_SELECT 7 -/* FIXME: not implemented */ void waitvblank (void); /* Wait for the vertical blanking */ -/* all PCE are NTSC */ +/* NOTE: all PCE are NTSC */ #define get_tv() TV_NTSC /* Return the video mode the machine is using. */ - /* End of pce.h */ #endif diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index 7dd857f21..243a07417 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -6,8 +6,6 @@ joystick support should get verified on real hw - the masks for buttons may be wrong. - 6 button gamepads are different and need slightly different code -some graphical petscii chars should get added to the charset - interruptor support in crt0 (and cfg) is missing - clock() should be hooked to a VBL interrupt diff --git a/libsrc/pce/vga.inc b/libsrc/pce/vga.inc index 2f9408f9a..b5c4b27fd 100644 --- a/libsrc/pce/vga.inc +++ b/libsrc/pce/vga.inc @@ -2,18 +2,106 @@ ; VGA charset for the PC-Engine conio implementation .byte $00, $00, $00, $00, $00, $00, $00, $00 - .byte $7E, $81, $A5, $81, $BD, $99, $81, $7E - .byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E - .byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 - .byte $10, $38, $7C, $FE, $7C, $38, $10, $00 - .byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C - .byte $10, $10, $38, $7C, $FE, $7C, $38, $7C - .byte $00, $00, $18, $3C, $3C, $18, $00, $00 - .byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF - .byte $00, $3C, $66, $42, $42, $66, $3C, $00 - .byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF - .byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 - .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 + ;;.byte $7E, $81, $A5, $81, $BD, $99, $81, $7E + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %11111111 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11111111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $10, $38, $7C, $FE, $7C, $38, $10, $00 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00011111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %11110000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $10, $10, $38, $7C, $FE, $7C, $38, $7C + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00011111 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $00, $00, $18, $3C, $3C, $18, $00, $00 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11110000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %11111111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $00, $3C, $66, $42, $42, $66, $3C, $00 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11111111 + .byte %00000000 + .byte %00000000 + .byte %00000000 + .byte %00000000 + ;;.byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00011111 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + ;;.byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %11110000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte %00010000 + .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 From e77060458a3517baba44d0ce2efa0b3a6756c07c Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 20:15:05 +0200 Subject: [PATCH 192/351] fixed joypad bits --- include/pce.h | 4 ++-- libsrc/pce/joy/pce-stdjoy.s | 8 ++++---- libsrc/pce/readme.txt | 4 +--- testcode/lib/pce/conio.c | 6 ++++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/pce.h b/include/pce.h index 27f70de0f..6f18ba501 100644 --- a/include/pce.h +++ b/include/pce.h @@ -80,8 +80,8 @@ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ #define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 +#define JOY_SELECT 6 +#define JOY_RUN 7 void waitvblank (void); /* Wait for the vertical blanking */ diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 1aa98e16d..592793250 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -29,10 +29,10 @@ .byte $40 ; JOY_DOWN .byte $80 ; JOY_LEFT .byte $20 ; JOY_RIGHT - .byte $02 ; JOY_FIRE A ; FIXME: is this correct? - .byte $01 ; JOY_FIRE B ; FIXME: is this correct? - .byte $04 ; JOY_START ; FIXME: is this correct? - .byte $08 ; JOY_SELECT ; FIXME: is this correct? + .byte $01 ; JOY_FIRE_A + .byte $02 ; JOY_FIRE_B + .byte $04 ; JOY_SELECT + .byte $08 ; JOY_RUN ; Jump table. diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt index 243a07417..a822205d4 100644 --- a/libsrc/pce/readme.txt +++ b/libsrc/pce/readme.txt @@ -2,9 +2,7 @@ PC-Engine (PCE) target support for cc65. this is still work in progress and a couple of things need to be fixed: -------------------------------------------------------------------------------- -joystick support should get verified on real hw - - the masks for buttons may be wrong. - - 6 button gamepads are different and need slightly different code +- 6 button gamepads are different and need slightly different code interruptor support in crt0 (and cfg) is missing - clock() should be hooked to a VBL interrupt diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index b94c91877..f5231dba6 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -95,14 +95,16 @@ void main(void) { gotoxy(0, 12 + i); j = joy_read (i); - cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s", + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", i, j, (j & joy_masks[JOY_UP])? " up " : " ---- ", (j & joy_masks[JOY_DOWN])? " down " : " ---- ", (j & joy_masks[JOY_LEFT])? " left " : " ---- ", (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", - (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- "); + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", + (j & joy_masks[JOY_SELECT])? "select" : " ---- ", + (j & joy_masks[JOY_RUN])? " run " : " ---- "); } gotoxy(xsize - 10, 3); From 25cf239d806efaa92ef5b3ef218f1c4ec4e101b1 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 16 Jul 2015 15:31:35 -0400 Subject: [PATCH 193/351] Added make rules that build the overlay sample programs. Fixes half of bug issue 178 (on GitHub). --- samples/Makefile | 23 +++++++++++++++++------ samples/README | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/samples/Makefile b/samples/Makefile index 79988ea70..951706ce6 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -44,7 +44,7 @@ endif C1541 = c1541 # -------------------------------------------------------------------------- -# System dependent settings +# System-dependent settings # The Apple machines need the start address adjusted when using TGI LDFLAGS_mandelbrot_apple2 = --start-addr 0x4000 @@ -81,10 +81,10 @@ LDFLAGS_tgidemo_atari = -D __RESERVED_MEMORY__=0x2000 .PRECIOUS: %.o .o: - @$(LD) $(LDFLAGS_$(basename $@)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(CLIB) + @$(LD) $(LDFLAGS_$(@F)_$(SYS)) -o $@ -t $(SYS) -m $@.map $^ $(CLIB) # -------------------------------------------------------------------------- -# List of executables. This list could be made target dependent by checking +# List of executables. This list could be made target-dependent by checking # $(SYS). EXELIST = ascii \ @@ -103,13 +103,23 @@ EXELIST = ascii \ tgidemo # -------------------------------------------------------------------------- -# Rules how to make each one of the binaries +# Rules to make the binaries .PHONY: all all: $(EXELIST) # -------------------------------------------------------------------------- -# Rule to make a disk with all samples. Needs the c1541 program that comes +# Overlay rules. Overlays need special ld65 configuration files. Also, the +# overlay file-names are shortenned to fit the Atari's 8.3-character limit. + +multdemo: multidemo.o + @$(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB) + +ovrldemo: overlaydemo.o + @$(LD) -o $@ -C $(SYS)-overlay.cfg -m $@.map $^ $(CLIB) + +# -------------------------------------------------------------------------- +# Rule to make a CBM disk with all samples. Needs the c1541 program that comes # with the VICE emulator. .PHONY: disk @@ -125,7 +135,7 @@ samples.d64: all done # -------------------------------------------------------------------------- -# Cleanup rules +# Clean-up rules .PHONY: clean clean: @@ -134,3 +144,4 @@ clean: .PHONY: zap zap: clean $(RM) $(EXELIST) samples.d64 + $(RM) multdemo.? ovrldemo.? diff --git a/samples/README b/samples/README index 5997fc8d0..edd06ff02 100644 --- a/samples/README +++ b/samples/README @@ -11,6 +11,7 @@ Please note: the programs manually. * The makefile specifies the C64 as the default target platform, because all + but one of the programs run on this platform. When compiling for another platform, you will have to change the line that specifies the target system at the top of the makefile. From 996c7b493e6111533b8c919b98b49cf7ce29bc45 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 16 Jul 2015 21:39:13 +0200 Subject: [PATCH 194/351] moved all notes into regular documentation --- doc/pce.sgml | 25 +++++++++++++++++++++++-- libsrc/pce/readme.txt | 36 ------------------------------------ 2 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 libsrc/pce/readme.txt diff --git a/doc/pce.sgml b/doc/pce.sgml index 2d14e8361..74692ce16 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -130,6 +130,8 @@ No extended memory drivers are currently available for the PCE. <tag><tt/pce-stdjoy.joy (pce_stdjoy)/</tag> A joystick driver for the standard two buttons joypad is available. + Note that the japanese 6-button pad is currently not supported. + </descrip><p> @@ -146,6 +148,10 @@ No serial drivers are currently available for the PCE. <sect>Limitations<p> +<itemize> +<item>interruptor support in crt0 (and cfg) is missing +</itemize> + <sect1>Disk I/O<p> The existing library for the PCE doesn't implement C file @@ -155,6 +161,7 @@ To be more concrete, this limitation means that you cannot use any of the following functions (and a few others): <itemize> +<item>printf <item>fclose <item>fopen <item>fread @@ -165,11 +172,25 @@ following functions (and a few others): <item>... </itemize> - - <sect>Other hints<p> +<itemize> +<item>a good emulator to use for PC-Engine is "mednafen" (<url url="http://mednafen.sourceforge.net">) +</itemize> +some useful resources on PCE coding: + +<itemize> +<item><url url="http://blog.blockos.org/?tag=pc-engine"> +<item><url url="http://pcedev.blockos.org/viewforum.php?f=5"> +<item><url url="http://www.romhacking.net/?page=documents&category=&platform=4&:game=&author=&perpage=20&level=&title=&desc=&docsearch=Go"> +<item><url url="http://archaicpixels.com/Main_Page"> + +<item><url url="http://www.magicengine.com/mkit/doc.html"> + +<item><url url="https://github.com/uli/huc"> +<item><url url="http://www.zeograd.com/parse.php?src=hucf"> +</itemize> <sect>License<p> diff --git a/libsrc/pce/readme.txt b/libsrc/pce/readme.txt deleted file mode 100644 index a822205d4..000000000 --- a/libsrc/pce/readme.txt +++ /dev/null @@ -1,36 +0,0 @@ -PC-Engine (PCE) target support for cc65. this is still work in progress and -a couple of things need to be fixed: --------------------------------------------------------------------------------- - -- 6 button gamepads are different and need slightly different code - -interruptor support in crt0 (and cfg) is missing -- clock() should be hooked to a VBL interrupt - --------------------------------------------------------------------------------- - -a good emulator to use for PC-Engine is "mednafen" (mednafen.sourceforge.net) - -run the compiled binary like this: - -> mednafen -force_module pce <yourprogram.pce> - -joypad keys are mapped like this: - -w/s/a/d up/down/left/right -numpad 2 (?) button -numpad 3 (?) button -enter (start) button - --------------------------------------------------------------------------------- -some useful resources on PCE coding: - -http://blog.blockos.org/?tag=pc-engine -http://pcedev.blockos.org/viewforum.php?f=5 -http://www.romhacking.net/?page=documents&category=&platform=4&game=&author=&perpage=20&level=&title=&desc=&docsearch=Go -http://archaicpixels.com/Main_Page - -http://www.magicengine.com/mkit/doc.html - -https://github.com/uli/huc -http://www.zeograd.com/parse.php?src=hucf From dd7e55820cfcdfa33ae113412d899df8ba0727aa Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 17 Jul 2015 20:33:17 -0400 Subject: [PATCH 195/351] Added a test program for the special features of snprintf(). --- testcode/lib/snprintf-test.c | 144 +++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 testcode/lib/snprintf-test.c diff --git a/testcode/lib/snprintf-test.c b/testcode/lib/snprintf-test.c new file mode 100644 index 000000000..d3af47d78 --- /dev/null +++ b/testcode/lib/snprintf-test.c @@ -0,0 +1,144 @@ +/* +** Test a function that formats and writes characters into a string buffer. +** This program does not test formatting. It tests some behaviors that are +** specific to the buffer. It tests that certain conditions are handled +** properly. +** +** 2015-07-17, Greg King +*/ + +#include <conio.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> + +static const char format[] = "1234567890\nabcdefghijklmnopqrstuvwxyz\n%u\n%s\n\n"; +#define FORMAT_SIZE (sizeof format - 2u - 2u - 1u) + +#define arg1 12345u +#define ARG1_SIZE (5u) + +static const char arg2[] = "!@#$%^&*()-+"; +#define ARG2_SIZE (sizeof arg2 - 1u) + +#define STRING_SIZE (FORMAT_SIZE + ARG1_SIZE + ARG2_SIZE) + +static char buf[256]; +static int size; + + +static void fillbuf(void) +{ + memset(buf, 0xFF, sizeof buf - 1u); + buf[sizeof buf - 1u] = '\0'; +} + + +unsigned char main(void) +{ + static unsigned char failures = 0; + + /* Show what sprintf() should create. */ + + if ((size = printf(format, arg1, arg2)) != STRING_SIZE) { + ++failures; + printf("printf() gave the wrong size: %d.\n", size); + } + + /* Test the normal behavior of sprintf(). */ + + fillbuf(); + size = sprintf(buf, format, arg1, arg2); + fputs(buf, stdout); + if (size != STRING_SIZE) { + ++failures; + printf("sprintf() gave the wrong size: %d.\n", size); + } + + /* Test the normal behavior of snprintf(). */ + + fillbuf(); + size = snprintf(buf, sizeof buf, format, arg1, arg2); + fputs(buf, stdout); + if (size != STRING_SIZE) { + ++failures; + printf("snprintf(sizeof buf) gave the wrong size:\n %d.\n", size); + } + + /* Does snprintf() return the full-formatted size even when the buffer + ** is short? Does it write beyond the end of that buffer? + */ + + fillbuf(); + size = snprintf(buf, STRING_SIZE - 5u, format, arg1, arg2); + if (size != STRING_SIZE) { + ++failures; + printf("snprintf(STRING_SIZE-5) gave the wrong size:\n %d.\n", size); + } + if (buf[STRING_SIZE - 5u - 1u] != '\0' || buf[STRING_SIZE - 5u] != 0xFF) { + ++failures; + printf("snprintf(STRING_SIZE-5) wrote beyond\n the end of the buffer.\n"); + } + + /* Does snprintf() detect a buffer size that is too big? */ + + fillbuf(); + errno = 0; + size = snprintf(buf, 0x8000, format, arg1, arg2); + if (size >= 0) { + ++failures; + printf("snprintf(0x8000) didn't give an error:\n %d; errno=%d.\n", size, errno); + } else { + printf("snprintf(0x8000) did give an error:\n errno=%d.\n", errno); + } + if (buf[0] != 0xFF) { + ++failures; + printf("snprintf(0x8000) wrote into the buffer.\n"); + } + + /* snprintf() must measure the length of the formatted output even when the + ** buffer size is zero. But, it must not touch the buffer. + */ + + fillbuf(); + size = snprintf(buf, 0, format, arg1, arg2); + if (size != STRING_SIZE) { + ++failures; + printf("snprintf(0) gave the wrong size:\n %d.\n", size); + } + if (buf[0] != 0xFF) { + ++failures; + printf("snprintf(0) wrote into the buffer.\n"); + } + + /* Does sprintf() detect a zero buffer-pointer? */ + + errno = 0; + size = sprintf(NULL, format, arg1, arg2); + if (size >= 0) { + ++failures; + printf("sprintf(NULL) didn't give an error:\n %d; errno=%d.\n", size, errno); + } else { + printf("sprintf(NULL) did give an error:\n errno=%d.\n", errno); + } + + /* snprintf() must measure the length of the formatted output even when the + ** buffer size is zero. A zero pointer is not an error, in that case. + */ + + size = snprintf(NULL, 0, format, arg1, arg2); + if (size != STRING_SIZE) { + ++failures; + printf("snprintf(NULL,0) gave the wrong size:\n %d.\n", size); + } + + if (failures != 0) { + printf("There were %u", failures); + } else { + printf("There were no"); + } + printf(" failures.\nTap a key. "); + cgetc(); + + return failures; +} From 0b6bcb565e7f514c09bcd1c7b44d3e1bc8791e32 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 17 Jul 2015 20:36:56 -0400 Subject: [PATCH 196/351] Fixed a hardware-stack leak. --- libsrc/common/vsnprintf.s | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libsrc/common/vsnprintf.s b/libsrc/common/vsnprintf.s index 01bcd6406..228e531d0 100644 --- a/libsrc/common/vsnprintf.s +++ b/libsrc/common/vsnprintf.s @@ -2,7 +2,7 @@ ; int __fastcall__ vsnprintf (char* Buf, size_t size, const char* Format, va_list ap); ; ; 2009-09-26, Ullrich von Bassewitz -; 2015-07-09, Greg King +; 2015-07-17, Greg King ; .export _vsnprintf, vsnprintf @@ -131,12 +131,15 @@ L4: lda ccount+0 ; Bail out if size is too high. -L9: lda #ERANGE +L9: ldy #ERANGE .byte $2C ;(bit $xxxx) ; NULL buffer pointers usually are invalid. -L0: lda #EINVAL +L0: ldy #EINVAL + pla ; Drop ap + pla + tya jsr __directerrno ; Return -1 jmp incsp6 ; Drop parameters From a9982de475a04568542683b197539a075dee9384 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 18 Jul 2015 18:23:08 -0400 Subject: [PATCH 197/351] Added _directerrno() to the sim6502/sim65c02 libraries. --- libsrc/sim6502/errno.s | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libsrc/sim6502/errno.s b/libsrc/sim6502/errno.s index e6c2422c1..d9f7e397e 100644 --- a/libsrc/sim6502/errno.s +++ b/libsrc/sim6502/errno.s @@ -1,11 +1,29 @@ ; -; Oliver Schmidt, 2013-05-16 +; 2013-05-16, Oliver Schmidt +; 2015-07-18, Greg King ; -; extern int errno; +; Helper functions for several high-level functions. ; .include "errno.inc" +; ---------------------------------------------------------------------------- +; int __fastcall__ _directerrno (unsigned char code); +; /* Set errno to a specific error code; and, return -1. Used +; ** by the library. +; */ + +__directerrno: + jsr __seterrno ; Save in errno +fail: lda #$FF ; Return -1 + tax +ok: rts + + +; ---------------------------------------------------------------------------- +; +; extern int _errno; +; .bss __errno: From 1e2d9f1796ba024a6c123b9fa5611dd48047798b Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 19 Jul 2015 13:36:27 +0200 Subject: [PATCH 198/351] fixed hline/vline --- asminc/pce.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 851b2f32a..4680ba826 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -16,8 +16,8 @@ tickcount = $39 ;4 screenrows = (224/8) charsperline = 61 -CH_HLINE = 7 -CH_VLINE = 7 +CH_HLINE = 1 +CH_VLINE = 2 ; huc6270 - Video Display Controller (vdc) From 313d2dd2104dd6f905ca3745fe1b9ea8e1259715 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 19 Jul 2015 18:06:16 +0200 Subject: [PATCH 199/351] added missing chline, cvline --- libsrc/pce/chline.s | 32 ++++++++++++++++++++++++++++++++ libsrc/pce/cvline.s | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 libsrc/pce/chline.s create mode 100644 libsrc/pce/cvline.s diff --git a/libsrc/pce/chline.s b/libsrc/pce/chline.s new file mode 100644 index 000000000..8bf8f1626 --- /dev/null +++ b/libsrc/pce/chline.s @@ -0,0 +1,32 @@ +; +; Ullrich von Bassewitz, 08.08.1998 +; +; void chlinexy (unsigned char x, unsigned char y, unsigned char length); +; void chline (unsigned char length); +; + + .export _chlinexy, _chline + .import popa, _gotoxy, cputdirect + .importzp tmp1 + + .include "pce.inc" + +_chlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length + +_chline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #CH_HLINE ; Horizontal line, screen code + jsr cputdirect ; Direct output + dec tmp1 + bne L1 +L9: rts + + + + diff --git a/libsrc/pce/cvline.s b/libsrc/pce/cvline.s new file mode 100644 index 000000000..abd74a5c7 --- /dev/null +++ b/libsrc/pce/cvline.s @@ -0,0 +1,32 @@ +; +; Ullrich von Bassewitz, 08.08.1998 +; +; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); +; void cvline (unsigned char length); +; + + .export _cvlinexy, _cvline + .import popa, _gotoxy, putchar, newline + .importzp tmp1 + + .include "pce.inc" + +_cvlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _cvline + +_cvline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #CH_VLINE ; Vertical bar + jsr putchar ; Write, no cursor advance + jsr newline ; Advance cursor to next line + dec tmp1 + bne L1 +L9: rts + + + From b79687da2b85d4759651ec8fbb024ee96b4e77ca Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Sun, 19 Jul 2015 18:56:42 -0400 Subject: [PATCH 200/351] Fix base 10 bug (ca65 allows 'a' or 'A' in base10 value) --- src/ca65/scanner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 97ed2c9d9..20053e7e6 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -1012,7 +1012,7 @@ Again: break; } DVal = DigitVal (Buf[I]); - if (DVal > Base) { + if (DVal >= Base) { Error ("Invalid digits in number"); CurTok.IVal = 0; break; From 1072f7d6f7f343b4dcc48739d482f01a2abc24fb Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Mon, 20 Jul 2015 07:46:18 +0200 Subject: [PATCH 201/351] Made hello program compatible with joystick-only target(s). --- samples/hello.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/samples/hello.c b/samples/hello.c index 90a1d4bdc..749a9d859 100644 --- a/samples/hello.c +++ b/samples/hello.c @@ -10,7 +10,7 @@ #include <stdlib.h> #include <string.h> #include <conio.h> -#include <dbg.h> +#include <joystick.h> @@ -68,15 +68,23 @@ int main (void) gotoxy ((XSize - strlen (Text)) / 2, YSize / 2); cprintf ("%s", Text); +#if defined(__NES__) + + /* Wait for the user to press a button */ + joy_install (joy_static_stddrv); + while (!joy_read (JOY_1)) ; + joy_uninstall (); + +#else + /* Wait for the user to press a key */ (void) cgetc (); +#endif + /* Clear the screen again */ clrscr (); /* Done */ return EXIT_SUCCESS; } - - - From 4afcfb34982fbd3ed817fb29997c14b799a21ed2 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 20 Jul 2015 16:03:03 +0200 Subject: [PATCH 202/351] fixed hello.c for pce --- samples/hello.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/hello.c b/samples/hello.c index 749a9d859..78c28af89 100644 --- a/samples/hello.c +++ b/samples/hello.c @@ -68,7 +68,7 @@ int main (void) gotoxy ((XSize - strlen (Text)) / 2, YSize / 2); cprintf ("%s", Text); -#if defined(__NES__) +#if defined(__NES__) || defined(__PCE__) /* Wait for the user to press a button */ joy_install (joy_static_stddrv); From c3d083fe334d59ae18b874c626881477551d0c5d Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Jul 2015 18:55:25 -0400 Subject: [PATCH 203/351] Fix bug #182 --- src/ca65/scanner.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 20053e7e6..9df28a8af 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -1417,13 +1417,17 @@ CharAgain: case '\\': /* Line continuation? */ if (LineCont) { - NextChar (); + NextChar(); + /* Next char should be a LF, if not, will result in an error later */ if (C == '\n') { - /* Handle as white space */ - NextChar (); - C = ' '; + /* Ignore the '\n' */ + NextChar(); goto Again; } + else { + /* Make it clear what the problem is: */ + Error("EOL expected."); + } } break; From 10579d04213be5d3360d1f713aab22272f287175 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Jul 2015 19:12:30 -0400 Subject: [PATCH 204/351] Fix style --- src/ca65/scanner.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 9df28a8af..16e67ee8a 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -1417,16 +1417,16 @@ CharAgain: case '\\': /* Line continuation? */ if (LineCont) { - NextChar(); + NextChar (); /* Next char should be a LF, if not, will result in an error later */ if (C == '\n') { /* Ignore the '\n' */ - NextChar(); + NextChar (); goto Again; } else { /* Make it clear what the problem is: */ - Error("EOL expected."); + Error ("EOL expected."); } } break; From cacc5e2acee7672932aeb98092f5e2942e13aeb8 Mon Sep 17 00:00:00 2001 From: JT <jeremiah.turner@gmail.com> Date: Mon, 20 Jul 2015 19:16:48 -0400 Subject: [PATCH 205/351] Style again --- src/ca65/scanner.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 16e67ee8a..aaba56764 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -1423,8 +1423,7 @@ CharAgain: /* Ignore the '\n' */ NextChar (); goto Again; - } - else { + } else { /* Make it clear what the problem is: */ Error ("EOL expected."); } From 673b27cc1b8fa0d7a7004ab715f03c229826cbd9 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Wed, 22 Jul 2015 11:36:39 +0200 Subject: [PATCH 206/351] Added empty IRQ backend. The driver kernels all require IRQ handling even if the actual drivers don't make use of it. So in order to successfully link a NES program using the joystick and/or TGI driver there has to be at least a "dummy" IRQ backend. --- libsrc/nes/irq.s | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 libsrc/nes/irq.s diff --git a/libsrc/nes/irq.s b/libsrc/nes/irq.s new file mode 100644 index 000000000..9c026f0ed --- /dev/null +++ b/libsrc/nes/irq.s @@ -0,0 +1,19 @@ +; +; IRQ handling (NES version) +; + + .export initirq, doneirq + +; ------------------------------------------------------------------------ + +.segment "INIT" + +initirq: + rts + +; ------------------------------------------------------------------------ + +.code + +doneirq: + rts From 52eec1f23666ee336203d18a0d6d1165393222d7 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 22 Jul 2015 12:56:34 -0400 Subject: [PATCH 207/351] Updated the fastcall information in a document and two Assembly files. --- doc/funcref.sgml | 34 ++++++++++++++++++++++++++++------ libsrc/conio/vcprintf.s | 13 +++---------- libsrc/conio/vcscanf.s | 3 +-- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/doc/funcref.sgml b/doc/funcref.sgml index ebe63be45..a2ccf6c73 100644 --- a/doc/funcref.sgml +++ b/doc/funcref.sgml @@ -3,7 +3,7 @@ <article> <title>cc65 function reference <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2014-05-26 +<date>2015-07-21 <abstract> cc65 is a C compiler for 6502 based systems. This function reference describes @@ -840,6 +840,8 @@ the CBM systems are classified as being "regular" files, for example. <tag/Notes/<itemize> <item>The minimum blocksize that can be added is 6 bytes; the function will ignore smaller blocks. +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -868,6 +870,8 @@ id="calloc" name="calloc">/ or <tt/<ref id="realloc" name="realloc">/. <tag/Notes/<itemize> <item>Passing a pointer to a block that was is not the result of one of the allocation functions, or that has been free'd will give unpredicable results. +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -912,7 +916,7 @@ be allocated from the heap using <tt/<ref id="malloc" name="malloc">/. <descrip> <tag/Function/Return the total available space on the heap. <tag/Header/<tt/<ref id="stdlib.h" name="stdlib.h">/ -<tag/Declaration/<tt/size_t __fastcall__ _heapmemavail (void);/ +<tag/Declaration/<tt/size_t _heapmemavail (void);/ <tag/Description/The function returns the total number of bytes available on the heap. <tag/Notes/<itemize> @@ -1323,6 +1327,10 @@ used in presence of a prototype. <tag/Header/<tt/<ref id="atmos.h" name="atmos.h">/ <tag/Declaration/<tt/void __fastcall__ atmos_load(const char* name);/ <tag/Description/<tt/atmos_load/ reads a memory block from tape. +<tag/Notes/<itemize> +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. +</itemize> <tag/Availability/cc65 <tag/See also/ <ref id="atmos_save" name="atmos_save"> @@ -1339,6 +1347,10 @@ used in presence of a prototype. <tag/Header/<tt/<ref id="atmos.h" name="atmos.h">/ <tag/Declaration/<tt/void __fastcall__ atmos_save(const char* name, const void* start, const void* end);/ <tag/Description/<tt/atmos_save/ writes a memory block to tape. +<tag/Notes/<itemize> +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. +</itemize> <tag/Availability/cc65 <tag/See also/ <ref id="atmos_load" name="atmos_load"> @@ -1460,7 +1472,7 @@ be used in presence of a prototype. <tag/Header/<tt/<ref id="stdlib.h" name="stdlib.h">/ <tag/Declaration/<tt/void* __fastcall__ bsearch (const void* key, const void* base, size_t n, size_t size, -int (*cmp) (const void*, const void*));/ +int __fastcall__ (* cmp) (const void*, const void*));/ <tag/Description/<tt/bsearch/ searches a sorted array for a member that matches the one pointed to by <tt/key/. <tt/base/ is the address of the array, <tt/n/ is the number of elements, <tt/size/ the size of an element and <tt/cmp/ @@ -1473,6 +1485,8 @@ the compare function given. return one of the members. <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. +<item>The function to which <tt/cmp/ points must have the <tt/fastcall/ calling +convention. </itemize> <tag/Availability/ISO 9899 <tag/See also/ @@ -4132,6 +4146,8 @@ the <tt/<ref id="mod_load" name="mod_load">/ function. <tag/Notes/<itemize> <item>The pointer passed as parameter is the pointer to the module memory, not the pointer to the control structure. +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -4147,7 +4163,7 @@ not the pointer to the control structure. <descrip> <tag/Function/Load a relocatable module. <tag/Header/<tt/<ref id="modload.h" name="modload.h">/ -<tag/Declaration/<tt/unsigned char mod_load (struct mod_ctrl* ctrl);/ +<tag/Declaration/<tt/unsigned char __fastcall__ mod_load (struct mod_ctrl* ctrl);/ <tag/Description/The function will load a code module into memory and relocate it. The function will return an error code. If <tt/MLOAD_OK/ is returned, the outgoing fields in the passed <tt/mod_ctrl/ struct contain information about @@ -4163,6 +4179,8 @@ the module just loaded. Possible error codes are: <tag/Notes/<itemize> <item>The <htmlurl url="ld65.html" name="ld65"> linker is needed to create relocatable o65 modules for use with this function. +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. </itemize> <tag/Availability/cc65 <tag/See also/ @@ -4501,7 +4519,7 @@ from memory. <descrip> <tag/Function/Unload a mouse driver. <tag/Header/<tt/<ref id="mouse.h" name="mouse.h">/ -<tag/Declaration/<tt/unsigned char __fastcall__ mouse_unload (void);/ +<tag/Declaration/<tt/unsigned char mouse_unload (void);/ <tag/Description/The function unloads a loaded mouse driver and frees all memory allocated for the driver. <tag/Notes/<itemize> @@ -4726,7 +4744,7 @@ be used in presence of a prototype. <tag/Function/Sort an array. <tag/Header/<tt/<ref id="stdlib.h" name="stdlib.h">/ <tag/Declaration/<tt/void __fastcall__ qsort (void* base, size_t count, -size_t size, int (*compare) (const void*, const void*));/ +size_t size, int __fastcall__ (* compare) (const void*, const void*));/ <tag/Description/<tt/qsort/ sorts an array according to a given compare function <tt/compare/. <tt/base/ is the address of the array, <tt/count/ is the number of elements, <tt/size/ the size of an element and <tt/compare/ @@ -4736,6 +4754,8 @@ the function used to compare the members. the function is undefined. <item>The function is only available as fastcall function, so it may only be used in presence of a prototype. +<item>The function to which <tt/compare/ points must have the <tt/fastcall/ +calling convention. </itemize> <tag/Availability/ISO 9899 <tag/See also/ @@ -6919,6 +6939,8 @@ ratio for a loaded driver. The value is not reset by <ref id="tgi_init" name="tgi_init">, so if a driver is linked statically to an application, switching into and out of graphics mode will not restore the original aspect ratio. +<item>The function is available only as a fastcall function; so, it may be used +only in the presence of a prototype. </itemize> <tag/Availability/cc65 <tag/See also/ diff --git a/libsrc/conio/vcprintf.s b/libsrc/conio/vcprintf.s index 5dbbc051d..06eab4421 100644 --- a/libsrc/conio/vcprintf.s +++ b/libsrc/conio/vcprintf.s @@ -1,5 +1,5 @@ ; -; int vcprintf (const char* Format, va_list ap); +; int __fastcall__ vcprintf (const char* Format, va_list ap); ; ; Ullrich von Bassewitz, 2.12.2000 ; @@ -30,7 +30,7 @@ outdesc: ; Static outdesc structure ; ---------------------------------------------------------------------------- ; Callback routine used for the actual output. ; -; static void out (struct outdesc* d, const char* buf, unsigned count) +; static void __cdecl__ out (struct outdesc* d, const char* buf, unsigned count) ; /* Routine used for writing */ ; { ; /* Fast screen output */ @@ -94,7 +94,7 @@ out: jsr popax ; count ; ---------------------------------------------------------------------------- ; vcprintf - formatted console i/o ; -; int vcprintf (const char* format, va_list ap) +; int __fastcall__ vcprintf (const char* format, va_list ap) ; { ; struct outdesc d; ; @@ -107,10 +107,6 @@ out: jsr popax ; count ; /* Return bytes written */ ; return d.ccount; ; } -; -; It is intentional that this function does not have __fastcall__ calling -; conventions - we need the space on the stack anyway, so there's nothing -; gained by using __fastcall__. _vcprintf: sta ptr1 ; Save ap @@ -153,6 +149,3 @@ _vcprintf: lda outdesc ; ccount ldx outdesc+1 rts - - - diff --git a/libsrc/conio/vcscanf.s b/libsrc/conio/vcscanf.s index 67d5f664f..6893da4ef 100644 --- a/libsrc/conio/vcscanf.s +++ b/libsrc/conio/vcscanf.s @@ -63,7 +63,7 @@ L1: jsr _cgetc ; ---------------------------------------------------------------------------- -; static int unget(int c) { +; static int cdecl unget(int c) { ; pushed = true; ; return back = c; ; } @@ -127,4 +127,3 @@ d: .addr get ; SCANFDATA::GET pla jmp __scanf .endproc - From a55b6ef3db4457e8e3b7754d5680b254dedc7213 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 29 Jul 2015 06:55:50 -0400 Subject: [PATCH 208/351] Removed obsolete lines from a list of 65816 mnemonic aliases. Described what the macroes in macro package "generic" do. --- doc/ca65.sgml | 50 +++++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 4beb4e913..7e9d27b7c 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -3,10 +3,10 @@ <article> <title>ca65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2014-04-24 +<date>2015-07-29 <abstract> -ca65 is a powerful macro assembler for the 6502, 65C02 and 65816 CPUs. It is +ca65 is a powerful macro assembler for the 6502, 65C02, and 65816 CPUs. It is used as a companion assembler for the cc65 crosscompiler, but it may also be used as a standalone product. </abstract> @@ -430,24 +430,21 @@ The assembler accepts <sect1>65816 mode<p> -In 65816 mode several aliases are accepted in addition to the official +In 65816 mode, several aliases are accepted, in addition to the official mnemonics: <tscreen><verb> - BGE is an alias for BCS - BLT is an alias for BCC - CPA is an alias for CMP - DEA is an alias for DEC A - INA is an alias for INC A - SWA is an alias for XBA - TAD is an alias for TCD - TAS is an alias for TCS - TDA is an alias for TDC - TSA is an alias for TSC +CPA is an alias for CMP +DEA is an alias for DEC A +INA is an alias for INC A +SWA is an alias for XBA +TAD is an alias for TCD +TAS is an alias for TCS +TDA is an alias for TDC +TSA is an alias for TSC </verb></tscreen> - <sect1>6502X mode<label id="6502X-mode"><p> 6502X mode is an extension to the normal 6502 mode. In this mode, several @@ -3330,8 +3327,8 @@ Here's a list of all control commands and a description, what they do: atari Defines the scrcode macro. cbm Defines the scrcode macro. cpu Defines constants for the .CPU variable. - generic Defines generic macros like add and sub. - longbranch Defines conditional long jump macros. + generic Defines generic macroes like add, sub, and blt. + longbranch Defines conditional long-jump macroes. </verb></tscreen> Including a macro package twice, or including a macro package that @@ -4317,48 +4314,47 @@ are: <sect1><tt>.MACPACK generic</tt><p> -This macro package defines macros that are useful in almost any program. -Currently defined macros are: +This macro package defines macroes that are useful in almost any program. +Currently defined macroes are: <tscreen><verb> - .macro add Arg + .macro add Arg ; add without carry clc adc Arg .endmacro - .macro sub Arg + .macro sub Arg ; subtract without borrow sec sbc Arg .endmacro - .macro bge Arg + .macro bge Arg ; branch on greater-than or equal bcs Arg .endmacro - .macro blt Arg + .macro blt Arg ; branch on less-than bcc Arg .endmacro - .macro bgt Arg + .macro bgt Arg ; branch on greater-than .local L beq L bcs Arg L: .endmacro - .macro ble Arg + .macro ble Arg ; branch on less-than or equal beq Arg bcc Arg .endmacro - .macro bnz Arg + .macro bnz Arg ; branch on not zero bne Arg .endmacro - .macro bze Arg + .macro bze Arg ; branch on zero beq Arg .endmacro - </verb></tscreen> From 05df90711469a14e311a9517c2e13e0c01ad6bf0 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 1 Aug 2015 05:50:13 -0400 Subject: [PATCH 209/351] Fixed the syntax in the shortcut expansion of ".ZEROPAGE". Added a reference from ".SEGMENT" to ".ZEROPAGE". --- doc/ca65.sgml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 7e9d27b7c..19c09b85d 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -3,7 +3,7 @@ <article> <title>ca65 Users Guide <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2015-07-29 +<date>2015-08-01 <abstract> ca65 is a powerful macro assembler for the 6502, 65C02, and 65816 CPUs. It is @@ -3667,7 +3667,7 @@ Here's a list of all control commands and a description, what they do: segment, that is, a named section of data. The default segment is "CODE". There may be up to 254 different segments per object file (and up to 65534 per executable). There are shortcut commands for - the most common segments ("CODE", "DATA" and "BSS"). + the most common segments ("ZEROPAGE", "CODE", "RODATA", "DATA", and "BSS"). The command is followed by a string containing the segment name (there are some constraints for the name - as a rule of thumb use only those segment @@ -3701,8 +3701,9 @@ Here's a list of all control commands and a description, what they do: </verb></tscreen> See: <tt><ref id=".BSS" name=".BSS"></tt>, <tt><ref id=".CODE" - name=".CODE"></tt>, <tt><ref id=".DATA" name=".DATA"></tt> and <tt><ref - id=".RODATA" name=".RODATA"></tt> + name=".CODE"></tt>, <tt><ref id=".DATA" name=".DATA"></tt>, <tt><ref + id=".RODATA" name=".RODATA"></tt>, and <tt><ref id=".ZEROPAGE" + name=".ZEROPAGE"></tt> <sect1><tt>.SET</tt><label id=".SET"><p> @@ -3863,7 +3864,7 @@ Here's a list of all control commands and a description, what they do: shortcut for <tscreen><verb> - .segment "ZEROPAGE", zeropage + .segment "ZEROPAGE": zeropage </verb></tscreen> Because of the "zeropage" attribute, labels declared in this segment are From d36f31dcff21f84c5f1f65ae8b0e07e989a6cee3 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 8 Aug 2015 22:04:38 -0400 Subject: [PATCH 210/351] Improved the format of the global symbols' lists of flags, in cc65's debugging output. --- src/cc65/symentry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc65/symentry.c b/src/cc65/symentry.c index aa5949f97..980ee27f2 100644 --- a/src/cc65/symentry.c +++ b/src/cc65/symentry.c @@ -126,19 +126,19 @@ void DumpSymEntry (FILE* F, const SymEntry* E) /* Print the assembler name if we have one */ if (E->AsmName) { fprintf (F, " AsmName: %s\n", E->AsmName); - } + } /* Print the flags */ SymFlags = E->Flags; - fprintf (F, " Flags: "); + fprintf (F, " Flags:"); for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) { if ((SymFlags & Flags[I].Val) == Flags[I].Val) { SymFlags &= ~Flags[I].Val; - fprintf (F, "%s ", Flags[I].Name); + fprintf (F, " %s", Flags[I].Name); } } if (SymFlags != 0) { - fprintf (F, "%04X", SymFlags); + fprintf (F, " 0x%05X", SymFlags); } fprintf (F, "\n"); From 4e9842ef33789dae702302509d6c6b8d0acccb13 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 9 Aug 2015 06:27:05 -0400 Subject: [PATCH 211/351] Stopped extern declarations from changing previous static, but otherwise identical, declarations. --- src/cc65/symtab.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 1f63e9430..0e4de4ea2 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -813,6 +813,11 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } } + /* An extern declaration must not change the current linkage. */ + if (IsFunc || (Flags & (SC_EXTERN | SC_DEF)) == SC_EXTERN) { + Flags &= ~SC_EXTERN; + } + /* Add the new flags */ Entry->Flags |= Flags; From 6032849e60dfa51ab1f39f99845d75a07c6e4e10 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 10 Aug 2015 13:39:17 -0400 Subject: [PATCH 212/351] Added warning diagnostics for conflicts between extern/public and static declarations. --- src/cc65/symtab.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 0e4de4ea2..fdf459873 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -813,11 +813,25 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } } + /* If a static declaration follows a non-static declaration, then + ** warn about the conflict. (It will compile a public declaration.) + */ + if ((Flags & SC_EXTERN) == 0 && (Entry->Flags & SC_EXTERN) != 0) { + Warning ("static declaration follows non-static declaration of `%s'.", Name); + } + /* An extern declaration must not change the current linkage. */ if (IsFunc || (Flags & (SC_EXTERN | SC_DEF)) == SC_EXTERN) { Flags &= ~SC_EXTERN; } + /* If a public declaration follows a static declaration, then + ** warn about the conflict. (It will compile a public declaration.) + */ + if ((Flags & SC_EXTERN) != 0 && (Entry->Flags & SC_EXTERN) == 0) { + Warning ("public declaration follows static declaration of `%s'.", Name); + } + /* Add the new flags */ Entry->Flags |= Flags; From 1baecf4a155842defd64d406de5b56f19a99859b Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 13 Aug 2015 03:39:35 -0400 Subject: [PATCH 213/351] Added regression tests of diagnostics for conflicts between extern/public and static declarations. --- test/err/static-2.c | 20 ++++++++++++++++++++ test/err/static-3.c | 20 ++++++++++++++++++++ test/err/static-4.c | 20 ++++++++++++++++++++ test/val/static-1.c | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 test/err/static-2.c create mode 100644 test/err/static-3.c create mode 100644 test/err/static-4.c create mode 100644 test/val/static-1.c diff --git a/test/err/static-2.c b/test/err/static-2.c new file mode 100644 index 000000000..c89097825 --- /dev/null +++ b/test/err/static-2.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +int n; +static int n; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/static-3.c b/test/err/static-3.c new file mode 100644 index 000000000..5b6839a6a --- /dev/null +++ b/test/err/static-3.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +extern int n; +static int n; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/static-4.c b/test/err/static-4.c new file mode 100644 index 000000000..a2cdeb78a --- /dev/null +++ b/test/err/static-4.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +static int n; +int n; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/val/static-1.c b/test/val/static-1.c new file mode 100644 index 000000000..ae2ba6289 --- /dev/null +++ b/test/val/static-1.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +static int n = 0; +extern int n; /* should not give an error */ + +int main(void) +{ + return n; +} From 6ed3d055cb3a5e79e02b8817f8f606155e82930c Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 13 Aug 2015 17:25:52 -0400 Subject: [PATCH 214/351] Removed redundant attempts to build uncompilable files. --- test/err/Makefile | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/test/err/Makefile b/test/err/Makefile index 454a560ce..bc4226acb 100644 --- a/test/err/Makefile +++ b/test/err/Makefile @@ -1,4 +1,3 @@ - # makefile for the tests that MUST NOT compile ifneq ($(shell echo),) @@ -13,36 +12,18 @@ else DEL = $(RM) $1 endif -CC65FLAGS := -t sim6502 - -CL65 := $(if $(wildcard ../../bin/cl65*),../../bin/cl65,cl65) +CC65 := $(if $(wildcard ../../bin/cc65*),../../bin/cc65,cc65) WORKDIR := ../../testwrk .PHONY: all clean -SOURCES := $(wildcard *.c) -TESTS := $(foreach option,. .o. .os. .osi. .osir. .oi. .oir. .or.,$(SOURCES:%.c=$(WORKDIR)/%$(option)prg)) +TESTS := $(patsubst %.c,$(WORKDIR)/%.s,$(wildcard *.c)) all: $(TESTS) -$(WORKDIR)/%.prg: %.c - $(NOT) $(CL65) $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.o.prg: %.c - $(NOT) $(CL65) -O $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.os.prg: %.c - $(NOT) $(CL65) -Os $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.osi.prg: %.c - $(NOT) $(CL65) -Osi $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.osir.prg: %.c - $(NOT) $(CL65) -Osir $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.oi.prg: %.c - $(NOT) $(CL65) -Oi $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.oir.prg: %.c - $(NOT) $(CL65) -Oir $(CC65FLAGS) $< -o $@ -$(WORKDIR)/%.or.prg: %.c - $(NOT) $(CL65) -Or $(CC65FLAGS) $< -o $@ +$(WORKDIR)/%.s: %.c + $(NOT) $(CC65) -o $@ $< clean: @$(call DEL,$(TESTS)) - @$(call DEL,$(SOURCES:.c=.o)) From dd75d3f8841b5828e173de5fe7f4a7fc8dfe7c47 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Tue, 25 Aug 2015 13:57:21 +0200 Subject: [PATCH 215/351] Don't show (potentially failing) pull request builds. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 660798128..31eb1c0ef 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [wiki](http://github.com/cc65/wiki/wiki) -[![build status](http://travis-ci.org/cc65/cc65.png)](http://travis-ci.org/cc65/cc65/builds) +[![build status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) cc65 is a complete cross development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, librarian and several From 9c55bd1c96e1910d0d46e66abd4fa2fe7fdadf4a Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 26 Aug 2015 19:29:39 -0400 Subject: [PATCH 216/351] Fixed bugs in the interface for C-level interrupt handlers. * Added an important ".code" directive. * Import a linker-created zero-page symbol as an absolute address; then, convert it to zero-page when it is used. Fixes bug report #198. --- libsrc/common/interrupt.s | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libsrc/common/interrupt.s b/libsrc/common/interrupt.s index e1d53d6dc..950d3d787 100644 --- a/libsrc/common/interrupt.s +++ b/libsrc/common/interrupt.s @@ -1,5 +1,6 @@ ; -; Oliver Schmidt, 2012-01-18 +; 2012-01-18, Oliver Schmidt +; 2015-08-22, Greg King ; ; void __fastcall__ set_irq (irq_handler f, void *stack_addr, size_t stack_size); ; void reset_irq (void); @@ -7,8 +8,7 @@ .export _set_irq, _reset_irq .interruptor clevel_irq, 1 ; Export as low priority IRQ handler - .import popax - .importzp __ZP_START__ + .import popax, __ZP_START__ .include "zeropage.inc" @@ -31,6 +31,8 @@ zpsave: .res zpsavespace ; --------------------------------------------------------------------------- +.code + .proc _set_irq ; Keep clevel_irq from being called right now @@ -77,7 +79,7 @@ zpsave: .res zpsavespace ; Save our zero page locations @L1: ldx #.sizeof(::zpsave)-1 -@L2: lda __ZP_START__,x +@L2: lda <__ZP_START__,x sta zpsave,x dex bpl @L2 @@ -94,7 +96,7 @@ zpsave: .res zpsavespace ; Copy back our zero page content ldx #.sizeof(::zpsave)-1 @L3: ldy zpsave,x - sty __ZP_START__,x + sty <__ZP_START__,x dex bpl @L3 @@ -103,4 +105,3 @@ zpsave: .res zpsavespace rts .endproc - From 57b8af1adc21f5c9215559af16f134957743baf6 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 29 Aug 2015 15:58:57 +0200 Subject: [PATCH 217/351] style fixes --- README.md | 3 + asminc/pce.inc | 82 +++++------ include/pce.h | 30 ++-- libsrc/pce/_scrsize.s | 16 +- libsrc/pce/clock.s | 35 +++-- libsrc/pce/clrscr.s | 38 ++--- libsrc/pce/color.s | 83 +++++------ libsrc/pce/conio.s | 174 +++++++++++----------- libsrc/pce/cputc.s | 107 +++++++------- libsrc/pce/crt0.s | 276 ++++++++++++++++++----------------- libsrc/pce/gotoxy.s | 18 +-- libsrc/pce/joy/pce-stdjoy.s | 114 ++++++++------- libsrc/pce/joy_stat_stddrv.s | 6 +- libsrc/pce/joy_stddrv.s | 2 +- libsrc/pce/kplot.s | 43 +++--- libsrc/pce/psg.s | 44 +++--- libsrc/pce/revers.s | 32 ++-- libsrc/pce/vce.s | 29 ++-- libsrc/pce/vdc.s | 51 +++---- libsrc/pce/vga.inc | 257 ++++++++++++++++---------------- libsrc/pce/waitvblank.s | 10 +- testcode/lib/pce/conio.c | 198 ++++++++++++------------- 22 files changed, 830 insertions(+), 818 deletions(-) diff --git a/README.md b/README.md index 660798128..c93a6f920 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ [![build status](http://travis-ci.org/cc65/cc65.png)](http://travis-ci.org/cc65/cc65/builds) +Binary snapshot for [Windows](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) + cc65 is a complete cross development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, librarian and several other tools. @@ -23,6 +25,7 @@ including - the Atari 8 bit machines. - the Atari 5200 console. - GEOS for the C64, C128 and Apple //e. +- the NEC PC-Engine - the Nintendo Entertainment System (NES) console. - the Supervision console. - the Oric Atmos. diff --git a/asminc/pce.inc b/asminc/pce.inc index 4680ba826..2d2843143 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -2,44 +2,44 @@ ; PCE definitions. By Groepaz/Hitmem. ; -;; FIXME: optimize zeropage usage +; FIXME: optimize zeropage usage +CURS_X = $30 +CURS_Y = $31 +SCREEN_PTR = $32 ;2 +CRAM_PTR = $34 ;2 +CHARCOLOR = $36 +RVS = $37 +BGCOLOR = $38 +tickcount = $39 ;4 -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 ;2 -CRAM_PTR = $34 ;2 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR = $38 -tickcount = $39 ;4 +; FIXME: screen dimensions my change according to selected video mode +screenrows = (224/8) +charsperline = 61 -screenrows = (224/8) -charsperline = 61 - -CH_HLINE = 1 -CH_VLINE = 2 +CH_HLINE = 1 +CH_VLINE = 2 ; huc6270 - Video Display Controller (vdc) -VDC_MAWR = 0 ; Memory Address Write Register -VDC_MARR = 1 ; Memory Address Read Register -VDC_VWR = 2 ; VRAM Write Register -VDC_VRR = 3 ; VRAM Read Register -VDC_CR = 4 ; Control Register -VDC_RCR = 5 ; Raster Counter Register -VDC_BXR = 6 ; Background X-Scroll Register -VDC_BYR = 7 ; Background Y-Scroll Register -VDC_MWR = 8 ; Memory-access Width Register -VDC_HSR = 9 ; Horizontal Sync Register (?) -VDC_HDR =10 ; Horizontal Display Register (?) -VDC_VPR =11 ; (unknown) -VDC_VDW =12 ; (unknown use) -VDC_VCR =13 ; (unknown use) -VDC_DCR =14 ; (DMA) Control Register -VDC_SOUR =15 ; (DMA) Source Register -VDC_DESR =16 ; (DMA) Destination Register -VDC_LENR =17 ; (DMA) Length Register -VDC_SATB =18 ; Sprite Attribute Table +VDC_MAWR = 0 ; Memory Address Write Register +VDC_MARR = 1 ; Memory Address Read Register +VDC_VWR = 2 ; VRAM Write Register +VDC_VRR = 3 ; VRAM Read Register +VDC_CR = 4 ; Control Register +VDC_RCR = 5 ; Raster Counter Register +VDC_BXR = 6 ; Background X-Scroll Register +VDC_BYR = 7 ; Background Y-Scroll Register +VDC_MWR = 8 ; Memory-access Width Register +VDC_HSR = 9 ; Horizontal Sync Register (?) +VDC_HDR = 10 ; Horizontal Display Register (?) +VDC_VPR = 11 ; (unknown) +VDC_VDW = 12 ; (unknown use) +VDC_VCR = 13 ; (unknown use) +VDC_DCR = 14 ; (DMA) Control Register +VDC_SOUR = 15 ; (DMA) Source Register +VDC_DESR = 16 ; (DMA) Destination Register +VDC_LENR = 17 ; (DMA) Length Register +VDC_SATB = 18 ; Sprite Attribute Table ; VDC port ; Note: absolute addressing mode must be used when writing to this port @@ -54,21 +54,21 @@ VDC_DATA_HI = $0003 ; bitmap of the palette data is this: 0000000gggrrrbbb. ; You can read and write the DAC-registers. -VCE = $0400 ; base +VCE = $0400 ; base -VCE_CTRL = $0400 ; write$00 to reset -VCE_ADDR_LO = $0402 ; LSB of byte offset into palette -VCE_ADDR_HI = $0403 ; MSB of byte offset into palette -VCE_DATA_LO = $0404 ; LSB of 16-bit palette data -VCE_DATA_HI = $0405 ; MSB of 16-bit palette data +VCE_CTRL = $0400 ; write$00 to reset +VCE_ADDR_LO = $0402 ; LSB of byte offset into palette +VCE_ADDR_HI = $0403 ; MSB of byte offset into palette +VCE_DATA_LO = $0404 ; LSB of 16-bit palette data +VCE_DATA_HI = $0405 ; MSB of 16-bit palette data ; programmable sound generator (PSG) -PSG = $0800 ; base +PSG = $0800 ; base ; timer -TIMER = $0c00 ; base +TIMER = $0c00 ; base TIMER_COUNT = $0c00 TIMER_CTRL = $0c01 diff --git a/include/pce.h b/include/pce.h index 6f18ba501..7700654c8 100644 --- a/include/pce.h +++ b/include/pce.h @@ -36,20 +36,20 @@ # error This module may only be used when compiling for the PCE! #endif -#define CH_HLINE 1 -#define CH_VLINE 2 -#define CH_CROSS 3 -#define CH_ULCORNER 4 -#define CH_URCORNER 5 -#define CH_LLCORNER 6 -#define CH_LRCORNER 7 -#define CH_TTEE 8 -#define CH_BTEE 9 -#define CH_LTEE 10 -#define CH_RTEE 11 +#define CH_HLINE 1 +#define CH_VLINE 2 +#define CH_CROSS 3 +#define CH_ULCORNER 4 +#define CH_URCORNER 5 +#define CH_LLCORNER 6 +#define CH_LRCORNER 7 +#define CH_TTEE 8 +#define CH_BTEE 9 +#define CH_LTEE 10 +#define CH_RTEE 11 -#define CH_ENTER 13 -#define CH_PI 18 +#define CH_ENTER 13 +#define CH_PI 18 /* Color defines (CBM compatible, for conio) */ #define COLOR_BLACK 0x00 @@ -77,7 +77,7 @@ #define DYN_DRV 0 /* The addresses of the static drivers */ -extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ +extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ #define JOY_FIRE_B 5 #define JOY_SELECT 6 @@ -87,7 +87,7 @@ void waitvblank (void); /* Wait for the vertical blanking */ /* NOTE: all PCE are NTSC */ -#define get_tv() TV_NTSC +#define get_tv() TV_NTSC /* Return the video mode the machine is using. */ /* End of pce.h */ diff --git a/libsrc/pce/_scrsize.s b/libsrc/pce/_scrsize.s index 8dab2cf7b..038622a6f 100644 --- a/libsrc/pce/_scrsize.s +++ b/libsrc/pce/_scrsize.s @@ -1,18 +1,18 @@ ; ; Screen size variables ; - .include "pce.inc" + .include "pce.inc" - .export screensize + .export screensize screensize: - ldx xsize - ldy ysize - rts + ldx xsize + ldy ysize + rts ; FIXME: changing the video mode allows for different screen sizes .rodata - .export xsize, ysize + .export xsize, ysize -xsize: .byte charsperline -ysize: .byte screenrows +xsize: .byte charsperline +ysize: .byte screenrows diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 5d0aa78f4..6b14232fe 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -2,30 +2,29 @@ ; clock_t clock (void); ; - .include "pce.inc" + .include "pce.inc" - .export _clock - .importzp sreg -;; .importzp tickcount + .export _clock + .importzp sreg .proc _clock - lda tickcount+3 - sta sreg+1 - lda tickcount+2 - sta sreg - ldx tickcount+1 - lda tickcount - rts + lda tickcount+3 + sta sreg+1 + lda tickcount+2 + sta sreg + ldx tickcount+1 + lda tickcount + rts .endproc - .constructor initclock, 24 + .constructor initclock, 24 initclock: - lda #0 - ldx #3 -@lp: sta tickcount,x - dex - bpl @lp - rts \ No newline at end of file + lda #0 + ldx #3 +@lp: sta tickcount,x + dex + bpl @lp + rts diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index 9279f1e25..eae2b27a2 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,30 +1,32 @@ - .include "pce.inc" + .include "pce.inc" - .export _clrscr + .export _clrscr _clrscr: - st0 #VDC_MAWR - st1 #<$0000 - st2 #>$0000 + st0 #VDC_MAWR + st1 #<$0000 + st2 #>$0000 - st0 #VDC_VWR - ldy #$40 -rowloop: ldx #$80 -colloop: lda #' ' - sta a:VDC_DATA_LO - lda #$02 - sta a:VDC_DATA_HI + st0 #VDC_VWR + ldy #$40 +rowloop: + ldx #$80 +colloop: + lda #' ' + sta a:VDC_DATA_LO + lda #$02 + sta a:VDC_DATA_HI - dex - bne colloop - dey - bne rowloop + dex + bne colloop + dey + bne rowloop - rts + rts ;------------------------------------------------------------------------------- ; force the init constructor to be imported .import initconio -conio_init = initconio +conio_init = initconio diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 03d93b186..36c85b6b5 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -5,59 +5,60 @@ ; - .export _textcolor, _bgcolor, _bordercolor + .export _textcolor, _bgcolor, _bordercolor - .include "pce.inc" + .include "pce.inc" _textcolor: - ldx CHARCOLOR ; get old value - sta CHARCOLOR ; set new value - txa - rts + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts _bgcolor: - ldx BGCOLOR ; get old value - sta BGCOLOR ; set new value - asl a - tay + ldx BGCOLOR ; get old value + sta BGCOLOR ; set new value + asl a + tay - stz VCE_ADDR_LO - stz VCE_ADDR_HI - lda colors,y - sta VCE_DATA_LO - lda colors+1,y - sta VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + lda colors,y + sta VCE_DATA_LO + lda colors+1,y + sta VCE_DATA_HI - txa - rts + txa + rts _bordercolor: - lda #0 - txa - rts + lda #0 + txa + rts - .export colors + .export colors -colors: ; G R B - .word ((0<<6)+(0<<3)+(0)) ; 0 black - .word ((7<<6)+(7<<3)+(7)) ; 1 white - .word ((0<<6)+(7<<3)+(0)) ; 2 red - .word ((7<<6)+(0<<3)+(7)) ; 3 cyan - .word ((0<<6)+(5<<3)+(7)) ; 4 violett - .word ((7<<6)+(0<<3)+(0)) ; 5 green - .word ((0<<6)+(0<<3)+(7)) ; 6 blue - .word ((7<<6)+(7<<3)+(0)) ; 7 yellow - .word ((5<<6)+(7<<3)+(0)) ; 8 orange - .word ((3<<6)+(4<<3)+(3)) ; 9 brown - .word ((4<<6)+(7<<3)+(4)) ; a light red - .word ((3<<6)+(3<<3)+(3)) ; b dark grey - .word ((4<<6)+(4<<3)+(4)) ; c middle grey - .word ((7<<6)+(4<<3)+(4)) ; d light green - .word ((4<<6)+(4<<3)+(7)) ; e light blue - .word ((6<<6)+(6<<3)+(6)) ; f light gray +colors: + ; G R B + .word ((0<<6)+(0<<3)+(0)) ; 0 black + .word ((7<<6)+(7<<3)+(7)) ; 1 white + .word ((0<<6)+(7<<3)+(0)) ; 2 red + .word ((7<<6)+(0<<3)+(7)) ; 3 cyan + .word ((0<<6)+(5<<3)+(7)) ; 4 violett + .word ((7<<6)+(0<<3)+(0)) ; 5 green + .word ((0<<6)+(0<<3)+(7)) ; 6 blue + .word ((7<<6)+(7<<3)+(0)) ; 7 yellow + .word ((5<<6)+(7<<3)+(0)) ; 8 orange + .word ((3<<6)+(4<<3)+(3)) ; 9 brown + .word ((4<<6)+(7<<3)+(4)) ; a light red + .word ((3<<6)+(3<<3)+(3)) ; b dark grey + .word ((4<<6)+(4<<3)+(4)) ; c middle grey + .word ((7<<6)+(4<<3)+(4)) ; d light green + .word ((4<<6)+(4<<3)+(7)) ; e light blue + .word ((6<<6)+(6<<3)+(6)) ; f light gray ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 4fb3b1394..b9333e1fa 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,121 +1,123 @@ - .include "pce.inc" + .include "pce.inc" - .import vce_init - .import psg_init - .import vdc_init + .import vce_init + .import psg_init + .import vdc_init - .constructor initconio, 24 + .constructor initconio, 24 + + .macpack longbranch - .macpack longbranch initconio: -;; jsr vdc_init - jsr vce_init - jsr psg_init - jsr conio_init - jsr set_palette + jsr vce_init + jsr psg_init + jsr conio_init + jsr set_palette - st0 #VDC_RCR - st1 #<$0088 - st2 #>$0088 - rts + st0 #VDC_RCR + st1 #<$0088 + st2 #>$0088 + rts - .import colors + .import colors set_palette: - stz VCE_ADDR_LO - stz VCE_ADDR_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI - ldx #0 + ldx #0 @lp: - ldy #16 + ldy #16 @lp1: - lda colors,x - sta VCE_DATA_LO - lda colors+1,x - sta VCE_DATA_HI - dey - bne @lp1 + lda colors,x + sta VCE_DATA_LO + lda colors+1,x + sta VCE_DATA_HI + dey + bne @lp1 - inx - inx - cpx #16*2 - jne @lp + inx + inx + cpx #16*2 + jne @lp - stz VCE_ADDR_LO - stz VCE_ADDR_HI - stz VCE_DATA_LO - stz VCE_DATA_HI + stz VCE_ADDR_LO + stz VCE_ADDR_HI + stz VCE_DATA_LO + stz VCE_DATA_HI - rts + rts ;---------------------------------------------------------------------------- ; ;---------------------------------------------------------------------------- - .importzp ptr1, tmp1 + .importzp ptr1, tmp1 conio_init: - ; Load font - st0 #VDC_MAWR - st1 #<$2000 - st2 #>$2000 + ; Load font + st0 #VDC_MAWR + st1 #<$2000 + st2 #>$2000 - ; ptr to font data - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + ; ptr to font data + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR - lda #0 - sta tmp1 - jsr copy + lda #0 + sta tmp1 + jsr copy - lda #<font - sta ptr1 - lda #>font - sta ptr1+1 + lda #<font + sta ptr1 + lda #>font + sta ptr1+1 - lda #$ff - sta tmp1 - jsr copy + lda #$ff + sta tmp1 + jsr copy - ldx #0 - stx BGCOLOR - inx - stx CHARCOLOR + ldx #0 + stx BGCOLOR + inx + stx CHARCOLOR - rts + rts copy: - ldy #$80 ; 128 chars -charloop: ldx #$08 ; 8 bytes/char + ldy #$80 ; 128 chars +charloop: + ldx #$08 ; 8 bytes/char lineloop: - lda (ptr1) - eor tmp1 - sta a:VDC_DATA_LO ; bitplane 0 - stz a:VDC_DATA_HI ; bitplane 1 + lda (ptr1) + eor tmp1 + sta a:VDC_DATA_LO ; bitplane 0 + stz a:VDC_DATA_HI ; bitplane 1 - clc ; increment font pointer - lda ptr1 - adc #$01 - sta ptr1 - lda ptr1+1 - adc #$00 - sta ptr1+1 - dex - bne lineloop ; next bitplane 0 byte - ldx #$08 ; fill bitplane 2/3 with 0 -fillloop: st1 #$00 - st2 #$00 - dex - bne fillloop ; next byte - dey - bne charloop ; next character + clc ; increment font pointer + lda ptr1 + adc #$01 + sta ptr1 + lda ptr1+1 + adc #$00 + sta ptr1+1 + dex + bne lineloop ; next bitplane 0 byte + ldx #$08 ; fill bitplane 2/3 with 0 +fillloop: + st1 #$00 + st2 #$00 + dex + bne fillloop ; next byte + dey + bne charloop ; next character - rts + rts - .rodata + .rodata font: - .include "vga.inc" + .include "vga.inc" diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index 918f39e29..d31e13769 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -3,97 +3,96 @@ ; void cputc (char c); ; - .export _cputcxy, _cputc, cputdirect, putchar - .export newline, plot - .import popa, _gotoxy - .import PLOT - .import xsize + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import popa, _gotoxy + .import PLOT + .import xsize - .importzp tmp3,tmp4 + .importzp tmp3,tmp4 + + .include "pce.inc" - .include "pce.inc" _cputcxy: - pha ; Save C - jsr popa ; Get Y - jsr _gotoxy ; Set cursor, drop x - pla ; Restore C + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C ; Plot a character - also used as internal function -_cputc: cmp #$0d ; CR? - bne L1 - lda #0 - sta CURS_X - beq plot ; Recalculate pointers +_cputc: cmp #$0d ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers -L1: cmp #$0a ; LF? - beq newline ; Recalculate pointers +L1: cmp #$0a ; LF? + beq newline ; Recalculate pointers ; Printable char of some sort cputdirect: - jsr putchar ; Write the character to the screen + jsr putchar ; Write the character to the screen ; Advance cursor position advance: - ldy CURS_X - iny - cpy xsize - bne L3 - jsr newline ; new line - ldy #0 ; + cr -L3: sty CURS_X - jmp plot + ldy CURS_X + iny + cpy xsize + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + jmp plot newline: - inc CURS_Y + inc CURS_Y ; Set cursor position, calculate RAM pointers -plot: ldy CURS_X - ldx CURS_Y - clc - jmp PLOT ; Set the new cursor - - +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor ; Write one character to the screen without doing anything else, return X ; position in Y putchar: - ora RVS ; Set revers bit + ora RVS ; Set revers bit - tax + tax - st0 #VDC_MAWR ; Memory Adress Write + st0 #VDC_MAWR ; Memory Adress Write - lda SCREEN_PTR - sta a:VDC_DATA_LO + lda SCREEN_PTR + sta a:VDC_DATA_LO - lda SCREEN_PTR+1 - sta a:VDC_DATA_HI + lda SCREEN_PTR + 1 + sta a:VDC_DATA_HI - st0 #VDC_VWR ; VWR + st0 #VDC_VWR ; VWR - txa - sta a:VDC_DATA_LO ; character + txa + sta a:VDC_DATA_LO ; character - lda CHARCOLOR + lda CHARCOLOR - asl a - asl a - asl a - asl a + asl a + asl a + asl a + asl a - ora #$02 - sta a:VDC_DATA_HI + ora #$02 + sta a:VDC_DATA_HI - rts + rts ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 2b8455a59..f89119c46 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -7,153 +7,155 @@ ; This must be the *first* file on the linker command line ; - .export _exit - .export __STARTUP__ : absolute = 1 ; Mark as startup + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup - .import initlib, donelib - .import push0, _main, zerobss - .import initheap - .import tmp1,tmp2,tmp3 + .import initlib, donelib + .import push0, _main, zerobss + .import initheap + .import tmp1,tmp2,tmp3 ; Linker generated - .import __RAM_START__, __RAM_SIZE__ - .import __ROM0_START__, __ROM0_SIZE__ - .import __ROM_START__, __ROM_SIZE__ - .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ - .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ - .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ - .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ - .import __BSS_SIZE__ + .import __RAM_START__, __RAM_SIZE__ + .import __ROM0_START__, __ROM0_SIZE__ + .import __ROM_START__, __ROM_SIZE__ + .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ + .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ + .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ + .import __DATA_LOAD__,__DATA_RUN__, __DATA_SIZE__ + .import __BSS_SIZE__ - .include "pce.inc" + .include "pce.inc" - .importzp sp - .importzp ptr1,ptr2 + .importzp sp + .importzp ptr1,ptr2 ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. - .segment "STARTUP" + .segment "STARTUP" start: - ; setup the CPU and System-IRQ + ; setup the CPU and System-IRQ - ; Initialize CPU + ; Initialize CPU - sei - nop - csh ; set high speed CPU mode - nop - cld - nop + sei + nop + csh ; set high speed CPU mode + nop + cld + nop - ; Setup stack and memory mapping - ldx #$FF ; Stack top ($21FF) - txs + ; Setup stack and memory mapping + ldx #$FF ; Stack top ($21FF) + txs - ; at startup all MPRs are set to 0, so init them - lda #$ff - tam #%00000001 ; 0000-1FFF = Hardware page - lda #$F8 - tam #%00000010 ; 2000-3FFF = Work RAM - ;lda #$F7 - ;tam #%00000100 ; 4000-5FFF = Save RAM - ;lda #1 - ;tam #%00001000 ; 6000-7FFF Page 2 - ;lda #2 - ;tam #%00010000 ; 8000-9FFF Page 3 - ;lda #3 - ;tam #%00100000 ; A000-BFFF Page 4 - ;lda #4 - ;tam #%01000000 ; C000-DFFF Page 5 - ;lda #0 - ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 + ; at startup all MPRs are set to 0, so init them + lda #$ff + tam #%00000001 ; 0000-1FFF = Hardware page + lda #$F8 + tam #%00000010 ; 2000-3FFF = Work RAM - ; Clear work RAM (2000-3FFF) - stz <$00 - tii $2000, $2001, $1FFF + ; FIXME: setup a larger block of memory to use with C-code + ;lda #$F7 + ;tam #%00000100 ; 4000-5FFF = Save RAM + ;lda #1 + ;tam #%00001000 ; 6000-7FFF Page 2 + ;lda #2 + ;tam #%00010000 ; 8000-9FFF Page 3 + ;lda #3 + ;tam #%00100000 ; A000-BFFF Page 4 + ;lda #4 + ;tam #%01000000 ; C000-DFFF Page 5 + ;lda #0 + ;tam #%10000000 ; e000-fFFF hucard/syscard bank 0 - ; Initialize hardware - stz TIMER_COUNT ; Timer off - lda #$07 - sta IRQ_MASK ; Interrupts off - stz IRQ_STATUS ; Acknowledge timer + ; Clear work RAM (2000-3FFF) + stz <$00 + tii $2000, $2001, $1FFF - ;; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ - .import vdc_init - jsr vdc_init + ; Initialize hardware + stz TIMER_COUNT ; Timer off + lda #$07 + sta IRQ_MASK ; Interrupts off + stz IRQ_STATUS ; Acknowledge timer - ; Turn on background and VD interrupt/IRQ1 - lda #$05 - sta IRQ_MASK ; IRQ1=on + ; FIXME; i dont know why the heck this one doesnt work when called from a constructor :/ + .import vdc_init + jsr vdc_init - ; Clear the BSS data - jsr zerobss + ; Turn on background and VD interrupt/IRQ1 + lda #$05 + sta IRQ_MASK ; IRQ1=on - ; Copy the .data segment to RAM - lda #<(__DATA_LOAD__) - sta ptr1 - lda #>(__DATA_LOAD__) - sta ptr1+1 - lda #<(__DATA_RUN__) - sta ptr2 - lda #>(__DATA_RUN__) - sta ptr2+1 + ; Clear the BSS data + jsr zerobss - ldx #>(__DATA_SIZE__) + ; Copy the .data segment to RAM + lda #<(__DATA_LOAD__) + sta ptr1 + lda #>(__DATA_LOAD__) + sta ptr1+1 + lda #<(__DATA_RUN__) + sta ptr2 + lda #>(__DATA_RUN__) + sta ptr2+1 + + ldx #>(__DATA_SIZE__) @l2: - beq @s1 ; no more full pages + beq @s1 ; no more full pages - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l1: - lda (ptr1),y - sta (ptr2),y - iny - bne @l1 + lda (ptr1),y + sta (ptr2),y + iny + bne @l1 - inc ptr1+1 - inc ptr2+1 + inc ptr1+1 + inc ptr2+1 - dex - bne @l2 + dex + bne @l2 - ; copy remaining bytes + ; copy remaining bytes @s1: - ; copy one page - ldy #0 + ; copy one page + ldy #0 @l3: - lda (ptr1),y - sta (ptr2),y - iny - cpy #<(__DATA_SIZE__) - bne @l3 + lda (ptr1),y + sta (ptr2),y + iny + cpy #<(__DATA_SIZE__) + bne @l3 - ; setup the stack - lda #<(__RAM_START__+__RAM_SIZE__) - sta sp - lda #>(__RAM_START__+__RAM_SIZE__) - sta sp+1 + ; setup the stack + lda #<(__RAM_START__+__RAM_SIZE__) + sta sp + lda #>(__RAM_START__+__RAM_SIZE__) + sta sp + 1 - ; Call module constructors - jsr initlib + ; Call module constructors + jsr initlib - cli ; allow IRQ only after constructors have run + cli ; allow IRQ only after constructors have run - ; Pass an empty command line - jsr push0 ; argc - jsr push0 ; argv + ; Pass an empty command line + jsr push0 ; argc + jsr push0 ; argv - ldy #4 ; Argument size - jsr _main ; call the users code + ldy #4 ; Argument size + jsr _main ; call the users code - ; Call module destructors. This is also the _exit entry. + ; Call module destructors. This is also the _exit entry. _exit: - jsr donelib ; Run module destructors + jsr donelib ; Run module destructors - ; reset the PCEngine (start over) - jmp start + ; reset the PCEngine (start over) + jmp start ; ------------------------------------------------------------------------ ; System V-Blank Interupt @@ -161,45 +163,45 @@ _exit: ; ------------------------------------------------------------------------ _irq1: - pha - phx - phy + pha + phx + phy - - inc tickcount - bne @s1 - inc tickcount+1 - bne @s1 - inc tickcount+2 - bne @s1 - inc tickcount+3 + ; increment the system tick counter + inc tickcount + bne @s1 + inc tickcount + 1 + bne @s1 + inc tickcount + 2 + bne @s1 + inc tickcount + 3 @s1: - ; Acknowlege interrupt - lda a:VDC_CTRL + ; Acknowlege interrupt + lda a:VDC_CTRL - ply - plx - pla - rti + ply + plx + pla + rti _irq2: - rti + rti _nmi: - rti + rti _timer: - stz IRQ_STATUS - rti + stz IRQ_STATUS + rti - .export initmainargs + .export initmainargs initmainargs: - rts + rts ; ------------------------------------------------------------------------ ; hardware vectors ; ------------------------------------------------------------------------ - .segment "VECTORS" + .segment "VECTORS" - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer - .word _nmi ; $fffc NMI - .word start ; $fffe reset + .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) + .word _irq1 ; $fff8 IRQ1 (VDC) + .word _timer ; $fffa Timer + .word _nmi ; $fffc NMI + .word start ; $fffe reset diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index c6b937177..c7cda83f3 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -2,20 +2,20 @@ ; void gotoxy (unsigned char x, unsigned char y); ; - .export _gotoxy - .import popa, plot + .export _gotoxy + .import popa, plot - .include "pce.inc" + .include "pce.inc" _gotoxy: - sta CURS_Y ; Set Y - jsr popa ; Get X - sta CURS_X ; Set X - jmp plot ; Set the cursor position + sta CURS_Y ; Set Y + jsr popa ; Get X + sta CURS_X ; Set X + jmp plot ; Set the cursor position ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 592793250..746929dd2 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -5,6 +5,7 @@ .include "joy-kernel.inc" .include "joy-error.inc" + .include "pce.inc" .macpack module @@ -58,10 +59,10 @@ JOY_COUNT = 4 ; Number of joysticks we support ; INSTALL: - lda #<JOY_ERR_OK - ldx #>JOY_ERR_OK + lda #<JOY_ERR_OK + ldx #>JOY_ERR_OK -; rts ; Run into DEINSTALL instead +; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ ; DEINSTALL routine. Is called before the driver is removed from memory. @@ -69,7 +70,7 @@ INSTALL: ; UNINSTALL: - rts + rts ; ------------------------------------------------------------------------ @@ -78,9 +79,9 @@ UNINSTALL: ;unsigned char __fastcall__ joy_count (void); COUNT: - lda #<JOY_COUNT - ldx #>JOY_COUNT - rts + lda #<JOY_COUNT + ldx #>JOY_COUNT + rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. @@ -88,70 +89,71 @@ COUNT: ;unsigned char __fastcall__ joy_read (unsigned char joystick); READJOY: - pha - jsr read_joy - pla - tax ; Joystick number into X + pha + jsr read_joy + pla + tax ; Joystick number into X - ; return value from buffer + ; return value from buffer joy1: - lda padbuffer,x - ldx #0 - rts + lda padbuffer,x + ldx #0 + rts read_joy: - ; reset multitap counter - lda #$01 - sta $1000 - pha - pla - nop - nop + ; reset multitap counter + lda #$01 + sta JOY_CTRL + pha + pla + nop + nop - lda #$03 - sta $1000 - pha - pla - nop - nop + lda #$03 + sta JOY_CTRL + pha + pla + nop + nop - cly + cly nextpad: - lda #$01 - sta $1000 ; sel = 1 - pha - pla - nop - nop + lda #$01 + sta JOY_CTRL ; sel = 1 + pha + pla + nop ; some delay is required + nop - lda $1000 - asl a - asl a - asl a - asl a - sta padbuffer, y ; store new value + lda JOY_CTRL + asl a + asl a + asl a + asl a + sta padbuffer, y ; store new value - stz $1000 - pha - pla - nop - nop + stz JOY_CTRL + pha + pla - lda $1000 - and #$0F - ora padbuffer, y ; second half of new value + nop ; some delay is required + nop - eor #$FF - sta padbuffer, y ; store new value + lda JOY_CTRL + and #$0F + ora padbuffer, y ; second half of new value - iny - cpy #$05 - bcc nextpad - rts + eor #$FF + sta padbuffer, y ; store new value + + iny + cpy #$05 + bcc nextpad + rts .bss padbuffer: - .res 4 + .res 4 diff --git a/libsrc/pce/joy_stat_stddrv.s b/libsrc/pce/joy_stat_stddrv.s index 3972569ed..2424c456b 100644 --- a/libsrc/pce/joy_stat_stddrv.s +++ b/libsrc/pce/joy_stat_stddrv.s @@ -6,9 +6,9 @@ ; const void joy_static_stddrv[]; ; - .export _joy_static_stddrv - .import _pce_stdjoy_joy + .export _joy_static_stddrv + .import _pce_stdjoy_joy .rodata -_joy_static_stddrv := _pce_stdjoy_joy +_joy_static_stddrv := _pce_stdjoy_joy diff --git a/libsrc/pce/joy_stddrv.s b/libsrc/pce/joy_stddrv.s index e0ed6957e..ba397409a 100644 --- a/libsrc/pce/joy_stddrv.s +++ b/libsrc/pce/joy_stddrv.s @@ -6,7 +6,7 @@ ; const char joy_stddrv[]; ; - .export _joy_stddrv + .export _joy_stddrv .rodata diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index eb4e79e04..b580f8473 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -1,37 +1,36 @@ - .export PLOT + .export PLOT - .include "pce.inc" + .include "pce.inc" PLOT: - bcs @getpos + bcs @getpos - tya - clc - adc _plotlo,x - sta SCREEN_PTR + tya + clc + adc _plotlo,x + sta SCREEN_PTR - lda _plothi,x - adc #0 - sta SCREEN_PTR+1 + lda _plothi,x + adc #0 + sta SCREEN_PTR+1 @getpos: - ldx CURS_Y - ldy CURS_X - rts + ldx CURS_Y + ldy CURS_X + rts _plotlo: - .repeat screenrows,line - .byte <($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte <($0000+(line*$80)) + .endrepeat _plothi: - .repeat screenrows,line - .byte >($0000+(line*$80)) - .endrepeat + .repeat screenrows,line + .byte >($0000+(line*$80)) + .endrepeat ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio - + .import initconio +conio_init = initconio diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index 431f58834..645c02615 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,29 +1,29 @@ - .include "pce.inc" + .include "pce.inc" - .export psg_init + .export psg_init psg_init: - clx - stx $0800 ; Select channel + clx + stx $0800 ; Select channel psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stz $0801 ; Clear global balance + stz $0802 ; Clear frequency LSB + stz $0803 ; Clear frequency MSB + stz $0804 ; Clear volume + stz $0805 ; Clear balance + stz $0807 ; Clear noise control + stz $0808 ; Clear LFO frequency + stz $0809 ; Clear LFO control - cly -psg_clear_waveform: stz $0806 ; Clear waveform byte - iny - cpy #$20 - bne psg_clear_waveform - - inx - cpx #$06 - bne psg_clear_loop - rts + cly +psg_clear_waveform: + stz $0806 ; Clear waveform byte + iny + cpy #$20 + bne psg_clear_waveform + inx + cpx #$06 + bne psg_clear_loop + rts diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index 061023d09..1773de2b0 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,27 +1,27 @@ - .include "pce.inc" + .include "pce.inc" - .export _revers + .export _revers .proc _revers - ldx #$00 ; Assume revers off - tay ; Test onoff - beq L1 ; Jump if off - ldx #$80 ; Load on value - ldy #$00 ; Assume old value is zero -L1: lda RVS ; Load old value - stx RVS ; Set new value - beq L2 ; Jump if old value zero - iny ; Make old value = 1 -L2: ldx #$00 ; Load high byte of result - tya ; Load low byte, set CC - rts + ldx #$00 ; Assume revers off + tay ; Test onoff + beq L1 ; Jump if off + ldx #$80 ; Load on value + ldy #$00 ; Assume old value is zero +L1: lda RVS ; Load old value + stx RVS ; Set new value + beq L2 ; Jump if old value zero + iny ; Make old value = 1 +L2: ldx #$00 ; Load high byte of result + tya ; Load low byte, set CC + rts .endproc ;------------------------------------------------------------------------------- ; force the init constructor to be imported - .import initconio -conio_init = initconio + .import initconio +conio_init = initconio diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 461fd1e75..3c19fd55b 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,17 +1,20 @@ - .include "pce.inc" + .include "pce.inc" - .export vce_init + .export vce_init vce_init: - stz VCE_ADDR_LO ; - stz VCE_ADDR_HI ; Set CTA to zero - ldy #$01 -vce_clear_bank: ldx #$00 -vce_clear_color: stz VCE_DATA_LO ; Clear color (LSB) - stz VCE_DATA_HI ; Clear color (MSB) - dex - bne vce_clear_color - dey - bne vce_clear_bank - rts + ; Set CTA to zero + stz VCE_ADDR_LO + stz VCE_ADDR_HI + ldy #$01 +vce_clear_bank: + ldx #$00 +vce_clear_color: + stz VCE_DATA_LO ; Clear color (LSB) + stz VCE_DATA_HI ; Clear color (MSB) + dex + bne vce_clear_color + dey + bne vce_clear_bank + rts diff --git a/libsrc/pce/vdc.s b/libsrc/pce/vdc.s index 0f42fe1b0..878c79321 100644 --- a/libsrc/pce/vdc.s +++ b/libsrc/pce/vdc.s @@ -1,40 +1,41 @@ - .include "pce.inc" + .include "pce.inc" -HIRES = 1 +; FIXME: implement selection of different video modes at runtime +HIRES = 1 - .export vdc_init + .export vdc_init vdc_init: - lda a:VDC_CTRL + lda a:VDC_CTRL - VREG $00, $0000 ; MAWR - VREG $01, $0000 ; MARR - VREG $05, $0000 ; CR - VREG $06, $0000 ; RCR - VREG $07, $0000 ; BXR - VREG $08, $0000 ; BYR - VREG $09, $0070 ; MAWR - VREG $0C, $1702 ; CRTC - VSR - VREG $0D, $00DF ; CRTC - VDS - VREG $0E, $000C ; CRTC - VDE - VREG $0F, $0000 ; DCR + VREG $00, $0000 ; MAWR + VREG $01, $0000 ; MARR + VREG $05, $0000 ; CR + VREG $06, $0000 ; RCR + VREG $07, $0000 ; BXR + VREG $08, $0000 ; BYR + VREG $09, $0070 ; MAWR + VREG $0C, $1702 ; CRTC - VSR + VREG $0D, $00DF ; CRTC - VDS + VREG $0E, $000C ; CRTC - VDE + VREG $0F, $0000 ; DCR .if HIRES - VREG $0A, $0C02 ; CRTC - HSR - VREG $0B, $043C ; CRTC - HDS - lda #$06 - sta VCE_CTRL + VREG $0A, $0C02 ; CRTC - HSR + VREG $0B, $043C ; CRTC - HDS + lda #$06 + sta VCE_CTRL .else - VREG $0A, $0202 ; CRTC - HSR - VREG $0B, $041F ; CRTC - HDS - lda #$04 - sta VCE_CTRL + VREG $0A, $0202 ; CRTC - HSR + VREG $0B, $041F ; CRTC - HDS + lda #$04 + sta VCE_CTRL .endif - lda a:VDC_CTRL - rts + lda a:VDC_CTRL + rts diff --git a/libsrc/pce/vga.inc b/libsrc/pce/vga.inc index b5c4b27fd..9317d6ce4 100644 --- a/libsrc/pce/vga.inc +++ b/libsrc/pce/vga.inc @@ -1,8 +1,8 @@ ; VGA charset for the PC-Engine conio implementation - .byte $00, $00, $00, $00, $00, $00, $00, $00 - ;;.byte $7E, $81, $A5, $81, $BD, $99, $81, $7E + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte %00000000 .byte %00000000 .byte %00000000 @@ -11,7 +11,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $7E, $FF, $DB, $FF, $C3, $E7, $FF, $7E + .byte %00010000 .byte %00010000 .byte %00010000 @@ -20,7 +20,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $6C, $FE, $FE, $FE, $7C, $38, $10, $00 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -29,7 +29,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $10, $38, $7C, $FE, $7C, $38, $10, $00 + .byte %00000000 .byte %00000000 .byte %00000000 @@ -38,7 +38,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $38, $7C, $38, $FE, $FE, $7C, $38, $7C + .byte %00000000 .byte %00000000 .byte %00000000 @@ -47,7 +47,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $10, $10, $38, $7C, $FE, $7C, $38, $7C + .byte %00010000 .byte %00010000 .byte %00010000 @@ -56,7 +56,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $00, $00, $18, $3C, $3C, $18, $00, $00 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -65,7 +65,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $FF, $FF, $E7, $C3, $C3, $E7, $FF, $FF + .byte %00000000 .byte %00000000 .byte %00000000 @@ -74,7 +74,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $00, $3C, $66, $42, $42, $66, $3C, $00 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -83,7 +83,7 @@ .byte %00000000 .byte %00000000 .byte %00000000 - ;;.byte $FF, $C3, $99, $BD, $BD, $99, $C3, $FF + .byte %00010000 .byte %00010000 .byte %00010000 @@ -92,7 +92,7 @@ .byte %00010000 .byte %00010000 .byte %00010000 - ;;.byte $0F, $07, $0F, $7D, $CC, $CC, $CC, $78 + .byte %00010000 .byte %00010000 .byte %00010000 @@ -101,119 +101,120 @@ .byte %00010000 .byte %00010000 .byte %00010000 - .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 - .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 - .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 - .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 - .byte $80, $E0, $F8, $FE, $F8, $E0, $80, $00 - .byte $02, $0E, $3E, $FE, $3E, $0E, $02, $00 - .byte $18, $3C, $7E, $18, $18, $7E, $3C, $18 - .byte $66, $66, $66, $66, $66, $00, $66, $00 - .byte $7F, $DB, $DB, $7B, $1B, $1B, $1B, $00 - .byte $3E, $63, $38, $6C, $6C, $38, $CC, $78 - .byte $00, $00, $00, $00, $7E, $7E, $7E, $00 - .byte $18, $3C, $7E, $18, $7E, $3C, $18, $FF - .byte $18, $3C, $7E, $18, $18, $18, $18, $00 - .byte $18, $18, $18, $18, $7E, $3C, $18, $00 - .byte $00, $18, $0C, $FE, $0C, $18, $00, $00 - .byte $00, $30, $60, $FE, $60, $30, $00, $00 - .byte $00, $00, $C0, $C0, $C0, $FE, $00, $00 - .byte $00, $24, $66, $FF, $66, $24, $00, $00 - .byte $00, $18, $3C, $7E, $FF, $FF, $00, $00 - .byte $00, $FF, $FF, $7E, $3C, $18, $00, $00 - .byte $00, $00, $00, $00, $00, $00, $00, $00 - .byte $30, $78, $78, $78, $30, $00, $30, $00 - .byte $6C, $6C, $6C, $00, $00, $00, $00, $00 - .byte $6C, $6C, $FE, $6C, $FE, $6C, $6C, $00 - .byte $30, $7C, $C0, $78, $0C, $F8, $30, $00 - .byte $00, $C6, $CC, $18, $30, $66, $C6, $00 - .byte $38, $6C, $38, $76, $DC, $CC, $76, $00 - .byte $60, $60, $C0, $00, $00, $00, $00, $00 - .byte $18, $30, $60, $60, $60, $30, $18, $00 - .byte $60, $30, $18, $18, $18, $30, $60, $00 - .byte $00, $66, $3C, $FF, $3C, $66, $00, $00 - .byte $00, $30, $30, $FC, $30, $30, $00, $00 - .byte $00, $00, $00, $00, $00, $30, $30, $60 - .byte $00, $00, $00, $FC, $00, $00, $00, $00 - .byte $00, $00, $00, $00, $00, $30, $30, $00 - .byte $06, $0C, $18, $30, $60, $C0, $80, $00 - .byte $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 - .byte $30, $70, $30, $30, $30, $30, $FC, $00 - .byte $78, $CC, $0C, $38, $60, $CC, $FC, $00 - .byte $78, $CC, $0C, $38, $0C, $CC, $78, $00 - .byte $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 - .byte $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 - .byte $38, $60, $C0, $F8, $CC, $CC, $78, $00 - .byte $FC, $CC, $0C, $18, $30, $30, $30, $00 - .byte $78, $CC, $CC, $78, $CC, $CC, $78, $00 - .byte $78, $CC, $CC, $7C, $0C, $18, $70, $00 - .byte $00, $30, $30, $00, $00, $30, $30, $00 - .byte $00, $30, $30, $00, $00, $30, $30, $60 - .byte $18, $30, $60, $C0, $60, $30, $18, $00 - .byte $00, $00, $FC, $00, $00, $FC, $00, $00 - .byte $60, $30, $18, $0C, $18, $30, $60, $00 - .byte $78, $CC, $0C, $18, $30, $00, $30, $00 - .byte $7C, $C6, $DE, $DE, $DE, $C0, $78, $00 - .byte $30, $78, $CC, $CC, $FC, $CC, $CC, $00 - .byte $FC, $66, $66, $7C, $66, $66, $FC, $00 - .byte $3C, $66, $C0, $C0, $C0, $66, $3C, $00 - .byte $F8, $6C, $66, $66, $66, $6C, $F8, $00 - .byte $7E, $60, $60, $78, $60, $60, $7E, $00 - .byte $7E, $60, $60, $78, $60, $60, $60, $00 - .byte $3C, $66, $C0, $C0, $CE, $66, $3E, $00 - .byte $CC, $CC, $CC, $FC, $CC, $CC, $CC, $00 - .byte $78, $30, $30, $30, $30, $30, $78, $00 - .byte $1E, $0C, $0C, $0C, $CC, $CC, $78, $00 - .byte $E6, $66, $6C, $78, $6C, $66, $E6, $00 - .byte $60, $60, $60, $60, $60, $60, $7E, $00 - .byte $C6, $EE, $FE, $FE, $D6, $C6, $C6, $00 - .byte $C6, $E6, $F6, $DE, $CE, $C6, $C6, $00 - .byte $38, $6C, $C6, $C6, $C6, $6C, $38, $00 - .byte $FC, $66, $66, $7C, $60, $60, $F0, $00 - .byte $78, $CC, $CC, $CC, $DC, $78, $1C, $00 - .byte $FC, $66, $66, $7C, $6C, $66, $E6, $00 - .byte $78, $CC, $E0, $70, $1C, $CC, $78, $00 - .byte $FC, $30, $30, $30, $30, $30, $30, $00 - .byte $CC, $CC, $CC, $CC, $CC, $CC, $FC, $00 - .byte $CC, $CC, $CC, $CC, $CC, $78, $30, $00 - .byte $C6, $C6, $C6, $D6, $FE, $EE, $C6, $00 - .byte $C6, $C6, $6C, $38, $38, $6C, $C6, $00 - .byte $CC, $CC, $CC, $78, $30, $30, $78, $00 - .byte $FE, $06, $0C, $18, $30, $60, $FE, $00 - .byte $78, $60, $60, $60, $60, $60, $78, $00 - .byte $C0, $60, $30, $18, $0C, $06, $02, $00 - .byte $78, $18, $18, $18, $18, $18, $78, $00 - .byte $10, $38, $6C, $C6, $00, $00, $00, $00 - .byte $00, $00, $00, $00, $00, $00, $00, $FF - .byte $30, $30, $18, $00, $00, $00, $00, $00 - .byte $00, $00, $78, $0C, $7C, $CC, $76, $00 - .byte $E0, $60, $60, $7C, $66, $66, $DC, $00 - .byte $00, $00, $78, $CC, $C0, $CC, $78, $00 - .byte $1C, $0C, $0C, $7C, $CC, $CC, $76, $00 - .byte $00, $00, $78, $CC, $FC, $C0, $78, $00 - .byte $38, $6C, $60, $F0, $60, $60, $F0, $00 - .byte $00, $00, $76, $CC, $CC, $7C, $0C, $F8 - .byte $E0, $60, $6C, $76, $66, $66, $E6, $00 - .byte $30, $00, $70, $30, $30, $30, $78, $00 - .byte $0C, $00, $0C, $0C, $0C, $CC, $CC, $78 - .byte $E0, $60, $66, $6C, $78, $6C, $E6, $00 - .byte $70, $30, $30, $30, $30, $30, $78, $00 - .byte $00, $00, $CC, $FE, $FE, $D6, $C6, $00 - .byte $00, $00, $F8, $CC, $CC, $CC, $CC, $00 - .byte $00, $00, $78, $CC, $CC, $CC, $78, $00 - .byte $00, $00, $DC, $66, $66, $7C, $60, $F0 - .byte $00, $00, $76, $CC, $CC, $7C, $0C, $1E - .byte $00, $00, $DC, $76, $66, $60, $F0, $00 - .byte $00, $00, $7C, $C0, $78, $0C, $F8, $00 - .byte $10, $30, $7C, $30, $30, $34, $18, $00 - .byte $00, $00, $CC, $CC, $CC, $CC, $76, $00 - .byte $00, $00, $CC, $CC, $CC, $78, $30, $00 - .byte $00, $00, $C6, $D6, $FE, $FE, $6C, $00 - .byte $00, $00, $C6, $6C, $38, $6C, $C6, $00 - .byte $00, $00, $CC, $CC, $CC, $7C, $0C, $F8 - .byte $00, $00, $FC, $98, $30, $64, $FC, $00 - .byte $1C, $30, $30, $E0, $30, $30, $1C, $00 - .byte $18, $18, $18, $00, $18, $18, $18, $00 - .byte $E0, $30, $30, $1C, $30, $30, $E0, $00 - .byte $76, $DC, $00, $00, $00, $00, $00, $00 - .byte $00, $10, $38, $6C, $C6, $C6, $FE, $00 + + .byte $3C, $66, $66, $66, $3C, $18, $7E, $18 + .byte $3F, $33, $3F, $30, $30, $70, $F0, $E0 + .byte $7F, $63, $7F, $63, $63, $67, $E6, $C0 + .byte $99, $5A, $3C, $E7, $E7, $3C, $5A, $99 + .byte $80, $E0, $F8, $FE, $F8, $E0, $80, $00 + .byte $02, $0E, $3E, $FE, $3E, $0E, $02, $00 + .byte $18, $3C, $7E, $18, $18, $7E, $3C, $18 + .byte $66, $66, $66, $66, $66, $00, $66, $00 + .byte $7F, $DB, $DB, $7B, $1B, $1B, $1B, $00 + .byte $3E, $63, $38, $6C, $6C, $38, $CC, $78 + .byte $00, $00, $00, $00, $7E, $7E, $7E, $00 + .byte $18, $3C, $7E, $18, $7E, $3C, $18, $FF + .byte $18, $3C, $7E, $18, $18, $18, $18, $00 + .byte $18, $18, $18, $18, $7E, $3C, $18, $00 + .byte $00, $18, $0C, $FE, $0C, $18, $00, $00 + .byte $00, $30, $60, $FE, $60, $30, $00, $00 + .byte $00, $00, $C0, $C0, $C0, $FE, $00, $00 + .byte $00, $24, $66, $FF, $66, $24, $00, $00 + .byte $00, $18, $3C, $7E, $FF, $FF, $00, $00 + .byte $00, $FF, $FF, $7E, $3C, $18, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $00 + .byte $30, $78, $78, $78, $30, $00, $30, $00 + .byte $6C, $6C, $6C, $00, $00, $00, $00, $00 + .byte $6C, $6C, $FE, $6C, $FE, $6C, $6C, $00 + .byte $30, $7C, $C0, $78, $0C, $F8, $30, $00 + .byte $00, $C6, $CC, $18, $30, $66, $C6, $00 + .byte $38, $6C, $38, $76, $DC, $CC, $76, $00 + .byte $60, $60, $C0, $00, $00, $00, $00, $00 + .byte $18, $30, $60, $60, $60, $30, $18, $00 + .byte $60, $30, $18, $18, $18, $30, $60, $00 + .byte $00, $66, $3C, $FF, $3C, $66, $00, $00 + .byte $00, $30, $30, $FC, $30, $30, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $60 + .byte $00, $00, $00, $FC, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $30, $30, $00 + .byte $06, $0C, $18, $30, $60, $C0, $80, $00 + .byte $7C, $C6, $CE, $DE, $F6, $E6, $7C, $00 + .byte $30, $70, $30, $30, $30, $30, $FC, $00 + .byte $78, $CC, $0C, $38, $60, $CC, $FC, $00 + .byte $78, $CC, $0C, $38, $0C, $CC, $78, $00 + .byte $1C, $3C, $6C, $CC, $FE, $0C, $1E, $00 + .byte $FC, $C0, $F8, $0C, $0C, $CC, $78, $00 + .byte $38, $60, $C0, $F8, $CC, $CC, $78, $00 + .byte $FC, $CC, $0C, $18, $30, $30, $30, $00 + .byte $78, $CC, $CC, $78, $CC, $CC, $78, $00 + .byte $78, $CC, $CC, $7C, $0C, $18, $70, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $00 + .byte $00, $30, $30, $00, $00, $30, $30, $60 + .byte $18, $30, $60, $C0, $60, $30, $18, $00 + .byte $00, $00, $FC, $00, $00, $FC, $00, $00 + .byte $60, $30, $18, $0C, $18, $30, $60, $00 + .byte $78, $CC, $0C, $18, $30, $00, $30, $00 + .byte $7C, $C6, $DE, $DE, $DE, $C0, $78, $00 + .byte $30, $78, $CC, $CC, $FC, $CC, $CC, $00 + .byte $FC, $66, $66, $7C, $66, $66, $FC, $00 + .byte $3C, $66, $C0, $C0, $C0, $66, $3C, $00 + .byte $F8, $6C, $66, $66, $66, $6C, $F8, $00 + .byte $7E, $60, $60, $78, $60, $60, $7E, $00 + .byte $7E, $60, $60, $78, $60, $60, $60, $00 + .byte $3C, $66, $C0, $C0, $CE, $66, $3E, $00 + .byte $CC, $CC, $CC, $FC, $CC, $CC, $CC, $00 + .byte $78, $30, $30, $30, $30, $30, $78, $00 + .byte $1E, $0C, $0C, $0C, $CC, $CC, $78, $00 + .byte $E6, $66, $6C, $78, $6C, $66, $E6, $00 + .byte $60, $60, $60, $60, $60, $60, $7E, $00 + .byte $C6, $EE, $FE, $FE, $D6, $C6, $C6, $00 + .byte $C6, $E6, $F6, $DE, $CE, $C6, $C6, $00 + .byte $38, $6C, $C6, $C6, $C6, $6C, $38, $00 + .byte $FC, $66, $66, $7C, $60, $60, $F0, $00 + .byte $78, $CC, $CC, $CC, $DC, $78, $1C, $00 + .byte $FC, $66, $66, $7C, $6C, $66, $E6, $00 + .byte $78, $CC, $E0, $70, $1C, $CC, $78, $00 + .byte $FC, $30, $30, $30, $30, $30, $30, $00 + .byte $CC, $CC, $CC, $CC, $CC, $CC, $FC, $00 + .byte $CC, $CC, $CC, $CC, $CC, $78, $30, $00 + .byte $C6, $C6, $C6, $D6, $FE, $EE, $C6, $00 + .byte $C6, $C6, $6C, $38, $38, $6C, $C6, $00 + .byte $CC, $CC, $CC, $78, $30, $30, $78, $00 + .byte $FE, $06, $0C, $18, $30, $60, $FE, $00 + .byte $78, $60, $60, $60, $60, $60, $78, $00 + .byte $C0, $60, $30, $18, $0C, $06, $02, $00 + .byte $78, $18, $18, $18, $18, $18, $78, $00 + .byte $10, $38, $6C, $C6, $00, $00, $00, $00 + .byte $00, $00, $00, $00, $00, $00, $00, $FF + .byte $30, $30, $18, $00, $00, $00, $00, $00 + .byte $00, $00, $78, $0C, $7C, $CC, $76, $00 + .byte $E0, $60, $60, $7C, $66, $66, $DC, $00 + .byte $00, $00, $78, $CC, $C0, $CC, $78, $00 + .byte $1C, $0C, $0C, $7C, $CC, $CC, $76, $00 + .byte $00, $00, $78, $CC, $FC, $C0, $78, $00 + .byte $38, $6C, $60, $F0, $60, $60, $F0, $00 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $F8 + .byte $E0, $60, $6C, $76, $66, $66, $E6, $00 + .byte $30, $00, $70, $30, $30, $30, $78, $00 + .byte $0C, $00, $0C, $0C, $0C, $CC, $CC, $78 + .byte $E0, $60, $66, $6C, $78, $6C, $E6, $00 + .byte $70, $30, $30, $30, $30, $30, $78, $00 + .byte $00, $00, $CC, $FE, $FE, $D6, $C6, $00 + .byte $00, $00, $F8, $CC, $CC, $CC, $CC, $00 + .byte $00, $00, $78, $CC, $CC, $CC, $78, $00 + .byte $00, $00, $DC, $66, $66, $7C, $60, $F0 + .byte $00, $00, $76, $CC, $CC, $7C, $0C, $1E + .byte $00, $00, $DC, $76, $66, $60, $F0, $00 + .byte $00, $00, $7C, $C0, $78, $0C, $F8, $00 + .byte $10, $30, $7C, $30, $30, $34, $18, $00 + .byte $00, $00, $CC, $CC, $CC, $CC, $76, $00 + .byte $00, $00, $CC, $CC, $CC, $78, $30, $00 + .byte $00, $00, $C6, $D6, $FE, $FE, $6C, $00 + .byte $00, $00, $C6, $6C, $38, $6C, $C6, $00 + .byte $00, $00, $CC, $CC, $CC, $7C, $0C, $F8 + .byte $00, $00, $FC, $98, $30, $64, $FC, $00 + .byte $1C, $30, $30, $E0, $30, $30, $1C, $00 + .byte $18, $18, $18, $00, $18, $18, $18, $00 + .byte $E0, $30, $30, $1C, $30, $30, $E0, $00 + .byte $76, $DC, $00, $00, $00, $00, $00, $00 + .byte $00, $10, $38, $6C, $C6, $C6, $FE, $00 diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s index 2ded2835e..b4e31f45a 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvblank.s @@ -2,17 +2,15 @@ ; void waitvblank (void); ; - .include "pce.inc" + .include "pce.inc" .export _waitvblank -;; .importzp tickcount .proc _waitvblank - lda tickcount -@lp: cmp tickcount - beq @lp + lda tickcount +@lp: cmp tickcount + beq @lp rts .endproc - diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index f5231dba6..44da30a2a 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -9,113 +9,113 @@ static int datavar = 10; void main(void) { - int stackvar = 42; - int i, j; - clock_t clk; - char *p; - unsigned char xsize, ysize, n; + int stackvar = 42; + int i, j; + clock_t clk; + char* p; + unsigned char xsize, ysize, n; - joy_install(&joy_static_stddrv); + joy_install(&joy_static_stddrv); - clrscr(); - screensize(&xsize, &ysize); + clrscr(); + screensize(&xsize, &ysize); - cputs("hello world"); - cputsxy(0, 2, "colors:" ); - for (i = 0; i < 16; ++i) { - textcolor(i); - cputc('X'); - } - textcolor(1); - - gotoxy(0,4); - cprintf("datavar: %02x\n\r", datavar); - cprintf("stackvar: %02x\n\r", stackvar); - - j = joy_count(); - gotoxy(0,10); - cprintf("Found %d Joysticks.", j); - - for (i = 0; i < 4; ++i) { - gotoxy(0, 17 + i); - p = malloc(16); - memcpy(p, "01234567890abcdef", 16); - cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, - p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] - ); - } - - gotoxy(0,ysize - 1); - for (i = 0; i < xsize; ++i) { - cputc('0' + i % 10); - } - - gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); - for (i = 0; i < xsize; ++i) { - cputc('0' + i % 10); - } - for (i = 0; i < (xsize * 5); ++i) { - cputc('#'); - } - gotoxy(0,ysize - 1 - ((256 + xsize) / xsize)); - for (i = 0; i < 256; ++i) { - if ((i != '\n') && (i != '\r')) { - cputc(i); + cputs("hello world"); + cputsxy(0, 2, "colors:" ); + for (i = 0; i < 16; ++i) { + textcolor(i); + cputc('X'); } - } + textcolor(1); - i = get_tv(); - gotoxy(30,0); - cputs("TV Mode: "); - switch(i) { - case TV_NTSC: - cputs("NTSC"); - break; - case TV_PAL: - cputs("PAL"); - break; - case TV_OTHER: - cputs("OTHER"); - break; - } - cprintf(" %dx%d", xsize, ysize); + gotoxy(0,4); + cprintf("datavar: %02x\n\r", datavar); + cprintf("stackvar: %02x\n\r", stackvar); - for(;;) { - gotoxy(13,4); - cprintf("%02x", datavar); - gotoxy(13,5); - cprintf("%02x", stackvar); - ++datavar; ++stackvar; + j = joy_count(); + gotoxy(0,10); + cprintf("Found %d Joysticks.", j); - gotoxy(0,8); - clk = clock(); - cprintf("clock: %08lx", clk); - - for (i = 0; i < 4; ++i) - { - gotoxy(0, 12 + i); - j = joy_read (i); - cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", - i, j, - (j & joy_masks[JOY_UP])? " up " : " ---- ", - (j & joy_masks[JOY_DOWN])? " down " : " ---- ", - (j & joy_masks[JOY_LEFT])? " left " : " ---- ", - (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", - (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", - (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", - (j & joy_masks[JOY_SELECT])? "select" : " ---- ", - (j & joy_masks[JOY_RUN])? " run " : " ---- "); + for (i = 0; i < 4; ++i) { + gotoxy(0, 17 + i); + p = malloc(16); + memcpy(p, "01234567890abcdef", 16); + cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, + p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], + p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] + ); } - gotoxy(xsize - 10, 3); - j = (n >> 5) & 1; - revers(j); - cputc(j ? 'R' : ' '); - cputs(" revers"); - revers(0); + gotoxy(0,ysize - 1); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } - waitvblank(); - ++n; - } - for(;;); + gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + for (i = 0; i < (xsize * 5); ++i) { + cputc('#'); + } + gotoxy(0,ysize - 1 - ((256 + xsize) / xsize)); + for (i = 0; i < 256; ++i) { + if ((i != '\n') && (i != '\r')) { + cputc(i); + } + } + + i = get_tv(); + gotoxy(30,0); + cputs("TV Mode: "); + switch(i) { + case TV_NTSC: + cputs("NTSC"); + break; + case TV_PAL: + cputs("PAL"); + break; + case TV_OTHER: + cputs("OTHER"); + break; + } + cprintf(" %dx%d", xsize, ysize); + + for(;;) { + gotoxy(13,4); + cprintf("%02x", datavar); + gotoxy(13,5); + cprintf("%02x", stackvar); + ++datavar; ++stackvar; + + gotoxy(0,8); + clk = clock(); + cprintf("clock: %08lx", clk); + + for (i = 0; i < 4; ++i) { + gotoxy(0, 12 + i); + j = joy_read (i); + cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", + i, j, + (j & joy_masks[JOY_UP])? " up " : " ---- ", + (j & joy_masks[JOY_DOWN])? " down " : " ---- ", + (j & joy_masks[JOY_LEFT])? " left " : " ---- ", + (j & joy_masks[JOY_RIGHT])? "right " : " ---- ", + (j & joy_masks[JOY_FIRE])? " fire " : " ---- ", + (j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ", + (j & joy_masks[JOY_SELECT])? "select" : " ---- ", + (j & joy_masks[JOY_RUN])? " run " : " ---- "); + } + + gotoxy(xsize - 10, 3); + j = (n >> 5) & 1; + revers(j); + cputc(j ? 'R' : ' '); + cputs(" revers"); + revers(0); + + waitvblank(); + ++n; + } + for(;;); } From a132bc4b28cc3ed3474586735dd2d8ad53a2caeb Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 30 Aug 2015 05:16:38 -0400 Subject: [PATCH 218/351] Fixed a comparison operator; so that the NULL at the end of argv[] is copied by InitCmdLine(). Most POSIX function libraries hid that long-time bug by putting zeroes in their dynamic RAM; but, MinGW's library doesn't do it. Therefore, a command like cl65 foo.c -l would crash with a "Segmentation fault" -- it should give a nice error message about "-l"; and, quit neatly. --- src/common/cmdline.c | 6 +++--- src/common/cmdline.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/cmdline.c b/src/common/cmdline.c index 716df1efb..ce2962780 100644 --- a/src/common/cmdline.c +++ b/src/common/cmdline.c @@ -161,7 +161,7 @@ static void ExpandFile (CmdLine* L, const char* Name) -void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName) +void InitCmdLine (int* aArgCount, char*** aArgVec, const char* aProgName) /* Initialize command line parsing. aArgVec is the argument array terminated by ** a NULL pointer (as usual), ArgCount is the number of valid arguments in the ** array. Both arguments are remembered in static storage. @@ -171,7 +171,7 @@ void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName) int I; /* Get the program name from argv[0] but strip a path */ - if (*(aArgVec)[0] == 0) { + if ((*aArgVec)[0] == 0) { /* Use the default name given */ ProgName = aProgName; } else { @@ -190,7 +190,7 @@ void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName) ** special handling for arguments preceeded by the '@' sign - these are ** actually files containing arguments. */ - for (I = 0; I < *aArgCount; ++I) { + for (I = 0; I <= *aArgCount; ++I) { /* Get the next argument */ char* Arg = (*aArgVec)[I]; diff --git a/src/common/cmdline.h b/src/common/cmdline.h index b18906c7a..1caf0cfb6 100644 --- a/src/common/cmdline.h +++ b/src/common/cmdline.h @@ -71,7 +71,7 @@ struct LongOpt { -void InitCmdLine (int* aArgCount, char** aArgVec[], const char* aProgName); +void InitCmdLine (int* aArgCount, char*** aArgVec, const char* aProgName); /* Initialize command line parsing. aArgVec is the argument array terminated by ** a NULL pointer (as usual), ArgCount is the number of valid arguments in the ** array. Both arguments are remembered in static storage. From d280d2610e585b884b376705f40f721c76ca97af Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 30 Aug 2015 07:55:07 -0400 Subject: [PATCH 219/351] Don't count the NULL (doh!). --- src/common/cmdline.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/cmdline.c b/src/common/cmdline.c index ce2962780..0f6622934 100644 --- a/src/common/cmdline.c +++ b/src/common/cmdline.c @@ -210,11 +210,11 @@ void InitCmdLine (int* aArgCount, char*** aArgVec, const char* aProgName) } /* Store the new argument list in a safe place... */ - ArgCount = L.Count; + ArgCount = L.Count - 1; ArgVec = L.Vec; /* ...and pass back the changed data also */ - *aArgCount = L.Count; + *aArgCount = L.Count - 1; *aArgVec = L.Vec; } From 58e56ba24deb6d63d068a9655217358fbe795b26 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 30 Aug 2015 08:43:54 -0400 Subject: [PATCH 220/351] Changed multi-line C comments in files that I missed in commit 0390c34e88e9512b81ce35a9ba36d137d1c80c44. --- src/cl65/spawn-amiga.inc | 12 ++++++------ src/cl65/spawn-unix.inc | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cl65/spawn-amiga.inc b/src/cl65/spawn-amiga.inc index 5d1b60ea3..443f42c1f 100644 --- a/src/cl65/spawn-amiga.inc +++ b/src/cl65/spawn-amiga.inc @@ -38,8 +38,8 @@ /* Mode argument for spawn. This value is ignored by the function and only - * provided for DOS/Windows compatibility. - */ +** provided for DOS/Windows compatibility. +*/ #ifndef P_WAIT #define P_WAIT 0 #endif @@ -56,10 +56,10 @@ int spawnvp (int Mode attribute ((unused)), const char* File attribute ((unused)), char* const argv []) /* Execute the given program searching and wait til it terminates. The Mode - * argument is ignored (compatibility only). The result of the function is - * the return code of the program. The function will terminate the program - * on errors. - */ +** argument is ignored (compatibility only). The result of the function is +** the return code of the program. The function will terminate the program +** on errors. +*/ { int Status; StrBuf Command = AUTO_STRBUF_INITIALIZER; diff --git a/src/cl65/spawn-unix.inc b/src/cl65/spawn-unix.inc index fc5125c34..1045f7759 100644 --- a/src/cl65/spawn-unix.inc +++ b/src/cl65/spawn-unix.inc @@ -48,8 +48,8 @@ /* Mode argument for spawn. This value is ignored by the function and only - * provided for DOS/Windows compatibility. - */ +** provided for DOS/Windows compatibility. +*/ #ifndef P_WAIT #define P_WAIT 0 #endif @@ -64,10 +64,10 @@ int spawnvp (int Mode attribute ((unused)), const char* File, char* const argv []) /* Execute the given program searching and wait til it terminates. The Mode - * argument is ignored (compatibility only). The result of the function is - * the return code of the program. The function will terminate the program - * on errors. - */ +** argument is ignored (compatibility only). The result of the function is +** the return code of the program. The function will terminate the program +** on errors. +*/ { int Status = 0; @@ -99,7 +99,7 @@ int spawnvp (int Mode attribute ((unused)), const char* File, char* const argv [ } /* Only the father goes here, we place a return here regardless of that - * to avoid compiler warnings. - */ + ** to avoid compiler warnings. + */ return WEXITSTATUS (Status); } From 01baf36fa841174ec9b6a7be30b489672cb0917e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 3 Sep 2015 13:09:18 +0200 Subject: [PATCH 221/351] fixed style issues --- doc/pce.sgml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/pce.sgml b/doc/pce.sgml index 74692ce16..ba59c31a7 100644 --- a/doc/pce.sgml +++ b/doc/pce.sgml @@ -78,7 +78,7 @@ Programs containing PCE specific code may use the <tt/pce.h/ header file. <itemize> <item>waitvblank</item> -<item>get_tv</item> (since all PCE systems are NTSC, this always returns TV_NTSC) +<item>get_tv (since all PCE systems are NTSC, this always returns TV_NTSC)</item> </itemize> @@ -111,12 +111,8 @@ The names in the parentheses denote the symbols to be used for static linking of <sect1>Graphics drivers<p> -<descrip> - No TGI graphics drivers are currently available for the PCE. -</descrip><p> - <sect1>Extended memory drivers<p> @@ -175,7 +171,7 @@ following functions (and a few others): <sect>Other hints<p> <itemize> -<item>a good emulator to use for PC-Engine is "mednafen" (<url url="http://mednafen.sourceforge.net">) +<item>a good emulator to use for PC-Engine is "mednafen" (<url url="http://mednafen.fobby.net/">) </itemize> some useful resources on PCE coding: From 9fe0c34fe6ea7aa7a6e5f6bb7fbca75c572c7c21 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 4 Sep 2015 13:38:17 +0200 Subject: [PATCH 222/351] updated --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c93a6f920..4a0a50bed 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [wiki](http://github.com/cc65/wiki/wiki) -[![build status](http://travis-ci.org/cc65/cc65.png)](http://travis-ci.org/cc65/cc65/builds) +[![build status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) Binary snapshot for [Windows](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) @@ -25,7 +25,7 @@ including - the Atari 8 bit machines. - the Atari 5200 console. - GEOS for the C64, C128 and Apple //e. -- the NEC PC-Engine +- the NEC PC-Engine (aka TurboGrafx-16). - the Nintendo Entertainment System (NES) console. - the Supervision console. - the Oric Atmos. From af2ba26c626735787b8513237397c371719f832c Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 4 Sep 2015 14:14:17 +0200 Subject: [PATCH 223/351] fix gregs complaints :) --- asminc/pce.inc | 20 +++++++++++++++----- libsrc/pce/kplot.s | 2 ++ libsrc/pce/psg.s | 21 +++++++++++---------- testcode/lib/pce/Makefile | 3 ++- testcode/lib/pce/conio.c | 10 +++++----- 5 files changed, 35 insertions(+), 21 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 2d2843143..9a77bcc4e 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -6,11 +6,10 @@ CURS_X = $30 CURS_Y = $31 SCREEN_PTR = $32 ;2 -CRAM_PTR = $34 ;2 -CHARCOLOR = $36 -RVS = $37 -BGCOLOR = $38 -tickcount = $39 ;4 +CHARCOLOR = $34 +RVS = $35 +BGCOLOR = $36 +tickcount = $37 ;4 ; FIXME: screen dimensions my change according to selected video mode screenrows = (224/8) @@ -66,6 +65,17 @@ VCE_DATA_HI = $0405 ; MSB of 16-bit palette data PSG = $0800 ; base +PSG_CHAN_SELECT = $0800 +PSG_GLOBAL_PAN = $0801 +PSG_FREQ_LO = $0802 +PSG_FREQ_HI = $0803 +PSG_CHAN_CTRL = $0804 +PSG_CHAN_PAN = $0805 +PSG_CHAN_DATA = $0806 +PSG_NOISE = $0807 +PSG_LFO_FREQ = $0808 +PSG_LFO_CTRL = $0809 + ; timer TIMER = $0c00 ; base diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index b580f8473..24ae8fab7 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -19,6 +19,8 @@ PLOT: ldy CURS_X rts + .rodata + _plotlo: .repeat screenrows,line .byte <($0000+(line*$80)) diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index 645c02615..17d26b941 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -5,20 +5,21 @@ psg_init: clx - stx $0800 ; Select channel + stz PSG_GLOBAL_PAN ; Clear global balance + psg_clear_loop: - stz $0801 ; Clear global balance - stz $0802 ; Clear frequency LSB - stz $0803 ; Clear frequency MSB - stz $0804 ; Clear volume - stz $0805 ; Clear balance - stz $0807 ; Clear noise control - stz $0808 ; Clear LFO frequency - stz $0809 ; Clear LFO control + stx PSG_CHAN_SELECT ; Select channel + stz PSG_FREQ_LO ; Clear frequency LSB + stz PSG_FREQ_HI ; Clear frequency MSB + stz PSG_CHAN_CTRL ; Clear volume + stz PSG_CHAN_PAN ; Clear balance + stz PSG_NOISE ; Clear noise control + stz PSG_LFO_FREQ ; Clear LFO frequency + stz PSG_LFO_CTRL ; Clear LFO control cly psg_clear_waveform: - stz $0806 ; Clear waveform byte + stz PSG_CHAN_DATA ; Clear waveform byte iny cpy #$20 bne psg_clear_waveform diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile index 364074180..1fee199fd 100644 --- a/testcode/lib/pce/Makefile +++ b/testcode/lib/pce/Makefile @@ -2,10 +2,11 @@ all: conio.pce conio.pce: conio.c - ../../../bin/cl65 -t pce conio.c ../../../joy/pce-stdjoy.joy --mapfile conio.map -o conio.pce + ../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce clean: $(RM) conio.pce + $(RM) conio.map test: conio.pce mednafen -force_module pce conio.pce diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 44da30a2a..d22fe58ee 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -33,13 +33,13 @@ void main(void) cprintf("stackvar: %02x\n\r", stackvar); j = joy_count(); - gotoxy(0,10); + gotoxy(0,9); cprintf("Found %d Joysticks.", j); for (i = 0; i < 4; ++i) { - gotoxy(0, 17 + i); + gotoxy(0, 16 + i); p = malloc(16); - memcpy(p, "01234567890abcdef", 16); + memcpy(p, "0123456789abcdef", 16); cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] @@ -88,12 +88,12 @@ void main(void) cprintf("%02x", stackvar); ++datavar; ++stackvar; - gotoxy(0,8); + gotoxy(0,7); clk = clock(); cprintf("clock: %08lx", clk); for (i = 0; i < 4; ++i) { - gotoxy(0, 12 + i); + gotoxy(0, 11 + i); j = joy_read (i); cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s", i, j, From a555f121fde555b80bb60ff9bc05759b46a6a67e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 6 Sep 2015 12:23:58 -0400 Subject: [PATCH 224/351] Fixed the " til " typos. --- src/cc65/preproc.c | 2 +- src/cl65/spawn-amiga.inc | 2 +- src/cl65/spawn-unix.inc | 2 +- src/dbginfo/dbgsh.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc65/preproc.c b/src/cc65/preproc.c index a5ab4897e..99ce6acc1 100644 --- a/src/cc65/preproc.c +++ b/src/cc65/preproc.c @@ -321,7 +321,7 @@ static void NewStyleComment (void) /* Remove a new style C comment from line. */ { /* Beware: Because line continuation chars are handled when reading - ** lines, we may only skip til the end of the source line, which + ** lines, we may only skip until the end of the source line, which ** may not be the same as the end of the input line. The end of the ** source line is denoted by a lf (\n) character. */ diff --git a/src/cl65/spawn-amiga.inc b/src/cl65/spawn-amiga.inc index 443f42c1f..ce13ae132 100644 --- a/src/cl65/spawn-amiga.inc +++ b/src/cl65/spawn-amiga.inc @@ -55,7 +55,7 @@ int spawnvp (int Mode attribute ((unused)), const char* File attribute ((unused)), char* const argv []) -/* Execute the given program searching and wait til it terminates. The Mode +/* Execute the given program searching and wait until it terminates. The Mode ** argument is ignored (compatibility only). The result of the function is ** the return code of the program. The function will terminate the program ** on errors. diff --git a/src/cl65/spawn-unix.inc b/src/cl65/spawn-unix.inc index 1045f7759..283285c76 100644 --- a/src/cl65/spawn-unix.inc +++ b/src/cl65/spawn-unix.inc @@ -63,7 +63,7 @@ int spawnvp (int Mode attribute ((unused)), const char* File, char* const argv []) -/* Execute the given program searching and wait til it terminates. The Mode +/* Execute the given program searching and wait until it terminates. The Mode ** argument is ignored (compatibility only). The result of the function is ** the return code of the program. The function will terminate the program ** on errors. diff --git a/src/dbginfo/dbgsh.c b/src/dbginfo/dbgsh.c index 41200e86a..ba5d83849 100644 --- a/src/dbginfo/dbgsh.c +++ b/src/dbginfo/dbgsh.c @@ -1885,7 +1885,7 @@ int main (int argc, char* argv[]) ExecCmd (&Args, MainCmds, sizeof (MainCmds) / sizeof (MainCmds[0])); } - /* Loop til program end */ + /* Loop until program end */ while (!Terminate) { /* Output a prompt, then read the input */ From 088a25437dfff9717c1a554530967a96bcaab127 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 7 Sep 2015 12:55:36 +0200 Subject: [PATCH 225/351] fixed VDC register assignments --- asminc/pce.inc | 38 ++++++++++++++++++++------------------ libsrc/pce/conio.s | 2 +- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/asminc/pce.inc b/asminc/pce.inc index 9a77bcc4e..3e82c38cc 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -18,27 +18,29 @@ charsperline = 61 CH_HLINE = 1 CH_VLINE = 2 -; huc6270 - Video Display Controller (vdc) +; huc6270 - Video Display Controller (VDC) VDC_MAWR = 0 ; Memory Address Write Register VDC_MARR = 1 ; Memory Address Read Register -VDC_VWR = 2 ; VRAM Write Register -VDC_VRR = 3 ; VRAM Read Register -VDC_CR = 4 ; Control Register -VDC_RCR = 5 ; Raster Counter Register -VDC_BXR = 6 ; Background X-Scroll Register -VDC_BYR = 7 ; Background Y-Scroll Register -VDC_MWR = 8 ; Memory-access Width Register -VDC_HSR = 9 ; Horizontal Sync Register (?) -VDC_HDR = 10 ; Horizontal Display Register (?) -VDC_VPR = 11 ; (unknown) -VDC_VDW = 12 ; (unknown use) -VDC_VCR = 13 ; (unknown use) -VDC_DCR = 14 ; (DMA) Control Register -VDC_SOUR = 15 ; (DMA) Source Register -VDC_DESR = 16 ; (DMA) Destination Register -VDC_LENR = 17 ; (DMA) Length Register -VDC_SATB = 18 ; Sprite Attribute Table +VDC_VWR = 2 ; VRAM Write Register (write only) +VDC_VRR = 2 ; VRAM Read Register (read only) +VDC_UNK03 = 3 ; (unknown) +VDC_UNK04 = 4 ; (unknown) +VDC_CR = 5 ; Control Register +VDC_RCR = 6 ; Raster Counter Register +VDC_BXR = 7 ; Background X-Scroll Register +VDC_BYR = 8 ; Background Y-Scroll Register +VDC_MWR = 9 ; Memory-access Width Register +VDC_HSR = 10 ; Horizontal Sync Register +VDC_HDR = 11 ; Horizontal Display Register +VDC_VPR = 12 ; Vertical synchronous register +VDC_VDW = 13 ; Vertical display register +VDC_VCR = 14 ; Vertical display END position register +VDC_DCR = 15 ; (DMA) Control Register +VDC_SOUR = 16 ; (DMA) Source Register +VDC_DESR = 17 ; (DMA) Destination Register +VDC_LENR = 18 ; (DMA) Length Register +VDC_SATB = 19 ; Sprite Attribute Table ; VDC port ; Note: absolute addressing mode must be used when writing to this port diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index b9333e1fa..a8565a6ae 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -14,7 +14,7 @@ initconio: jsr conio_init jsr set_palette - st0 #VDC_RCR + st0 #VDC_CR st1 #<$0088 st2 #>$0088 rts From 031bd2ebf0b1fc1afec8bcd18d12d58a2512d3c6 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 11 Sep 2015 10:03:07 -0400 Subject: [PATCH 226/351] Fixed the random-seed generators for the Commodore targets. They use a byte from the time counter; but, it is stored in big-endian order. --- libsrc/c128/randomize.s | 5 +++-- libsrc/c16/randomize.s | 5 +++-- libsrc/c64/randomize.s | 5 +++-- libsrc/cbm510/randomize.s | 5 +++-- libsrc/cbm610/randomize.s | 5 +++-- libsrc/pet/randomize.s | 5 +++-- libsrc/plus4/randomize.s | 5 +++-- libsrc/vic20/randomize.s | 5 +++-- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/libsrc/c128/randomize.s b/libsrc/c128/randomize.s index 5c57e04be..ae63184a4 100644 --- a/libsrc/c128/randomize.s +++ b/libsrc/c128/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -12,6 +13,6 @@ __randomize: ldx VIC_HLINE ; Use VIC rasterline as high byte - lda TIME ; Use 60HZ clock as low byte + lda TIME+2 ; Use 60HZ clock as low byte jmp _srand ; Initialize generator diff --git a/libsrc/c16/randomize.s b/libsrc/c16/randomize.s index 903a0809a..796ad118b 100644 --- a/libsrc/c16/randomize.s +++ b/libsrc/c16/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -12,6 +13,6 @@ __randomize: ldx TED_VLINELO ; Use TED rasterline as high byte - lda TIME ; Use 60HZ clock as low byte + lda TIME+2 ; Use 60HZ clock as low byte jmp _srand ; Initialize generator diff --git a/libsrc/c64/randomize.s b/libsrc/c64/randomize.s index c77d6b411..d74bae91e 100644 --- a/libsrc/c64/randomize.s +++ b/libsrc/c64/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -12,6 +13,6 @@ __randomize: ldx VIC_HLINE ; Use VIC rasterline as high byte - lda TIME ; Use 60HZ clock as low byte + lda TIME+2 ; Use 60HZ clock as low byte jmp _srand ; Initialize generator diff --git a/libsrc/cbm510/randomize.s b/libsrc/cbm510/randomize.s index d5420165c..75c419ccb 100644 --- a/libsrc/cbm510/randomize.s +++ b/libsrc/cbm510/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -10,7 +11,7 @@ .importzp time __randomize: - ldx time ; Use 50/60HZ clock + ldx time+2 ; Use 50/60HZ clock lda time+1 jmp _srand ; Initialize generator diff --git a/libsrc/cbm610/randomize.s b/libsrc/cbm610/randomize.s index a936f8a2f..d313baa1b 100644 --- a/libsrc/cbm610/randomize.s +++ b/libsrc/cbm610/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -10,7 +11,7 @@ .importzp time __randomize: - ldx time ; Use 50/60HZ clock + ldx time+2 ; Use 50/60HZ clock lda time+1 jmp _srand ; Initialize generator diff --git a/libsrc/pet/randomize.s b/libsrc/pet/randomize.s index fc5f621af..2c0fe722a 100644 --- a/libsrc/pet/randomize.s +++ b/libsrc/pet/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -11,7 +12,7 @@ .include "pet.inc" __randomize: - ldx TIME + ldx TIME+2 lda TIME+1 ; Use 60HZ clock jmp _srand ; Initialize generator diff --git a/libsrc/plus4/randomize.s b/libsrc/plus4/randomize.s index 6c7b86353..2a7f6a44b 100644 --- a/libsrc/plus4/randomize.s +++ b/libsrc/plus4/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -12,6 +13,6 @@ __randomize: ldx TED_VLINELO ; Use TED rasterline as high byte - lda TIME ; Use 60HZ clock as low byte + lda TIME+2 ; Use 60HZ clock as low byte jmp _srand ; Initialize generator diff --git a/libsrc/vic20/randomize.s b/libsrc/vic20/randomize.s index 8a1c4eee7..69cf07bb3 100644 --- a/libsrc/vic20/randomize.s +++ b/libsrc/vic20/randomize.s @@ -1,5 +1,6 @@ ; -; Ullrich von Bassewitz, 05.11.2002 +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King ; ; void _randomize (void); ; /* Initialize the random number generator */ @@ -16,6 +17,6 @@ __randomize: lda VIC_HLINE ; Get bit 1-8 of rasterline rol a ; Use bit 0-7 tax ; Use VIC rasterline as high byte - lda TIME ; Use 60HZ clock as low byte + lda TIME+2 ; Use 60HZ clock as low byte jmp _srand ; Initialize generator From dbf0adcec962c35d2ba7c31b8ba91ded8b7e709a Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 11 Sep 2015 14:18:22 -0400 Subject: [PATCH 227/351] Improved longjmp() and setjmp(). --- libsrc/common/longjmp.s | 10 +++++----- libsrc/common/setjmp.s | 14 ++++++-------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/libsrc/common/longjmp.s b/libsrc/common/longjmp.s index a89f97fa0..e9bac42e6 100644 --- a/libsrc/common/longjmp.s +++ b/libsrc/common/longjmp.s @@ -1,7 +1,8 @@ ; -; Ullrich von Bassewitz, 06.06.1998 +; 1998-06-06, Ullrich von Bassewitz +; 2015-09-11, Greg King ; -; void longjmp (jmp_buf buf, int retval); +; void __fastcall__ longjmp (jmp_buf buf, int retval); ; .export _longjmp @@ -13,8 +14,8 @@ _longjmp: stx ptr2+1 ora ptr2+1 ; Check for 0 bne @L1 - lda #1 ; 0 is illegal according to the standard... - sta ptr2 ; ... and must be replaced by 1 + inc ptr2 ; 0 is illegal, according to the standard ... + ; ... and, must be replaced by 1 @L1: jsr popax ; get buf sta ptr1 stx ptr1+1 @@ -49,4 +50,3 @@ _longjmp: lda ptr2 ldx ptr2+1 rts - diff --git a/libsrc/common/setjmp.s b/libsrc/common/setjmp.s index a6448b29f..a763ac3ec 100644 --- a/libsrc/common/setjmp.s +++ b/libsrc/common/setjmp.s @@ -1,10 +1,13 @@ ; -; Ullrich von Bassewitz, 06.06.1998 +; 1998-06-06, Ullrich von Bassewitz +; 2015-09-11, Greg King ; -; int setjmp (jmp_buf buf); +; int __fastcall__ setjmp (jmp_buf buf); ; .export __setjmp + + .import return0 .importzp sp, ptr1 __setjmp: @@ -44,9 +47,4 @@ __setjmp: ; Return zero - lda #0 - tax - rts - - - + jmp return0 From 859604407b76364c129e106833fda674ab44ef92 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 19 Sep 2015 15:37:39 +0200 Subject: [PATCH 228/351] fixed more flaws found by greg :) --- asminc/pce.inc | 9 --------- cfg/pce.cfg | 4 +++- libsrc/pce/clock.s | 1 + libsrc/pce/clrscr.s | 8 +++++++- libsrc/pce/color.s | 6 ++++-- libsrc/pce/conio.s | 1 + libsrc/pce/cputc.s | 1 + libsrc/pce/crt0.s | 3 ++- libsrc/pce/extzp.inc | 17 +++++++++++++++++ libsrc/pce/extzp.s | 17 +++++++++++++++++ libsrc/pce/gotoxy.s | 1 + libsrc/pce/kplot.s | 1 + libsrc/pce/revers.s | 3 ++- libsrc/pce/waitvblank.s | 1 + 14 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 libsrc/pce/extzp.inc create mode 100644 libsrc/pce/extzp.s diff --git a/asminc/pce.inc b/asminc/pce.inc index 3e82c38cc..623ab4da8 100644 --- a/asminc/pce.inc +++ b/asminc/pce.inc @@ -2,15 +2,6 @@ ; PCE definitions. By Groepaz/Hitmem. ; -; FIXME: optimize zeropage usage -CURS_X = $30 -CURS_Y = $31 -SCREEN_PTR = $32 ;2 -CHARCOLOR = $34 -RVS = $35 -BGCOLOR = $36 -tickcount = $37 ;4 - ; FIXME: screen dimensions my change according to selected video mode screenrows = (224/8) charsperline = 61 diff --git a/cfg/pce.cfg b/cfg/pce.cfg index adb420f32..2c660435a 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -6,7 +6,7 @@ SYMBOLS { MEMORY { # FIXME: is this correct? the first 3? bytes cant be used? - ZP: start = $03, size = $1A, type = rw, define = yes; + ZP: start = $03, size = $fd, type = rw, define = yes; # reset-bank and hardware vectors ROM0: start = $e000, size = $1ff6, file = %O ,fill = yes, define = yes; @@ -25,6 +25,8 @@ SEGMENTS { BSS: load = RAM, type = bss, define = yes; VECTORS: load = ROMV, type = rw, define = yes; ZEROPAGE: load = ZP, type = zp, define = yes; + EXTZP: load = ZP, type = zp, define = yes, optional = yes; + APPZP: load = ZP, type = zp, define = yes, optional = yes; } FEATURES { diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 6b14232fe..d92ebe89f 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -3,6 +3,7 @@ ; .include "pce.inc" + .include "extzp.inc" .export _clock .importzp sreg diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index eae2b27a2..f198be714 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -1,6 +1,8 @@ .include "pce.inc" + .include "extzp.inc" + .import PLOT .export _clrscr _clrscr: @@ -23,7 +25,11 @@ colloop: dey bne rowloop - rts +; Go to the home position. + + stz CURS_X + stz CURS_Y + jmp PLOT ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/libsrc/pce/color.s b/libsrc/pce/color.s index 36c85b6b5..0ff991a2e 100644 --- a/libsrc/pce/color.s +++ b/libsrc/pce/color.s @@ -7,7 +7,8 @@ .export _textcolor, _bgcolor, _bordercolor - .include "pce.inc" + .include "pce.inc" + .include "extzp.inc" _textcolor: ldx CHARCOLOR ; get old value @@ -33,9 +34,10 @@ _bgcolor: _bordercolor: lda #0 - txa + tax rts + .rodata .export colors colors: diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index a8565a6ae..bcfc600a7 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,4 +1,5 @@ .include "pce.inc" + .include "extzp.inc" .import vce_init .import psg_init diff --git a/libsrc/pce/cputc.s b/libsrc/pce/cputc.s index d31e13769..8d1cec8eb 100644 --- a/libsrc/pce/cputc.s +++ b/libsrc/pce/cputc.s @@ -12,6 +12,7 @@ .importzp tmp3,tmp4 .include "pce.inc" + .include "extzp.inc" _cputcxy: pha ; Save C diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index f89119c46..4f886ca5a 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -26,6 +26,7 @@ .import __BSS_SIZE__ .include "pce.inc" + .include "extzp.inc" .importzp sp .importzp ptr1,ptr2 @@ -77,7 +78,7 @@ start: tii $2000, $2001, $1FFF ; Initialize hardware - stz TIMER_COUNT ; Timer off + stz TIMER_CTRL ; Timer off lda #$07 sta IRQ_MASK ; Interrupts off stz IRQ_STATUS ; Acknowledge timer diff --git a/libsrc/pce/extzp.inc b/libsrc/pce/extzp.inc new file mode 100644 index 000000000..2869c3a06 --- /dev/null +++ b/libsrc/pce/extzp.inc @@ -0,0 +1,17 @@ +; +; extzp.inc for the PC-Engine +; +; Groepaz/Hitmen, 2015-11-19 +; +; Assembler include file that imports the runtime zero page locations used +; by the PC-Engine runtime, ready for usage in asm code. +; + + + .global CURS_X: zp + .global CURS_Y: zp + .global SCREEN_PTR: zp + .global CHARCOLOR: zp + .global RVS: zp + .global BGCOLOR: zp + .global tickcount: zp diff --git a/libsrc/pce/extzp.s b/libsrc/pce/extzp.s new file mode 100644 index 000000000..516c30954 --- /dev/null +++ b/libsrc/pce/extzp.s @@ -0,0 +1,17 @@ +; +; Groepaz/Hitmen, 2015-11-19 +; +; zeropage locations for exclusive use by the library +; + + .include "extzp.inc" + + .segment "EXTZP" : zeropage + +CURS_X: .res 1 +CURS_Y: .res 1 +SCREEN_PTR: .res 2 +CHARCOLOR: .res 1 +RVS: .res 1 +BGCOLOR: .res 1 +tickcount: .res 4 diff --git a/libsrc/pce/gotoxy.s b/libsrc/pce/gotoxy.s index c7cda83f3..fb61646d1 100644 --- a/libsrc/pce/gotoxy.s +++ b/libsrc/pce/gotoxy.s @@ -6,6 +6,7 @@ .import popa, plot .include "pce.inc" + .include "extzp.inc" _gotoxy: sta CURS_Y ; Set Y diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index 24ae8fab7..6c81e4152 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -2,6 +2,7 @@ .export PLOT .include "pce.inc" + .include "extzp.inc" PLOT: bcs @getpos diff --git a/libsrc/pce/revers.s b/libsrc/pce/revers.s index 1773de2b0..17a74508c 100644 --- a/libsrc/pce/revers.s +++ b/libsrc/pce/revers.s @@ -1,5 +1,6 @@ - .include "pce.inc" + .include "pce.inc" + .include "extzp.inc" .export _revers diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s index b4e31f45a..d60a9ddea 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvblank.s @@ -3,6 +3,7 @@ ; .include "pce.inc" + .include "extzp.inc" .export _waitvblank From 296489ba6cf76c38e242bd601e18f31495cf65f1 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 19 Sep 2015 15:55:43 +0200 Subject: [PATCH 229/351] added interruptor support --- cfg/pce.cfg | 11 +++++----- libsrc/pce/clock.s | 1 + libsrc/pce/crt0.s | 40 +++++----------------------------- libsrc/pce/extzp.inc | 1 + libsrc/pce/extzp.s | 1 + libsrc/pce/irq.s | 48 +++++++++++++++++++++++++++++++++++++++++ libsrc/pce/ticktock.s | 18 ++++++++++++++++ libsrc/pce/waitvblank.s | 1 + 8 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 libsrc/pce/irq.s create mode 100644 libsrc/pce/ticktock.s diff --git a/cfg/pce.cfg b/cfg/pce.cfg index 2c660435a..9128eb727 100644 --- a/cfg/pce.cfg +++ b/cfg/pce.cfg @@ -38,10 +38,9 @@ FEATURES { label = __DESTRUCTOR_TABLE__, count = __DESTRUCTOR_COUNT__, segment = RODATA; -# FIXME: interruptor support is missing -# CONDES: type = interruptor, -# label = __INTERRUPTOR_TABLE__, -# count = __INTERRUPTOR_COUNT__, -# segment = RODATA, -# import = __CALLIRQ__; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; } diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index d92ebe89f..c6d6fb7fb 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -5,6 +5,7 @@ .include "pce.inc" .include "extzp.inc" + .forceimport ticktock .export _clock .importzp sreg diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 4f886ca5a..77872f32f 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -13,7 +13,7 @@ .import initlib, donelib .import push0, _main, zerobss .import initheap - .import tmp1,tmp2,tmp3 + .import IRQStub ; Linker generated .import __RAM_START__, __RAM_SIZE__ @@ -30,6 +30,7 @@ .importzp sp .importzp ptr1,ptr2 + .importzp tmp1,tmp2,tmp3 ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. @@ -158,39 +159,8 @@ _exit: ; reset the PCEngine (start over) jmp start -; ------------------------------------------------------------------------ -; System V-Blank Interupt -; FIXME: hooks should be provided so the user can abuse the IRQ -; ------------------------------------------------------------------------ - -_irq1: - pha - phx - phy - - ; increment the system tick counter - inc tickcount - bne @s1 - inc tickcount + 1 - bne @s1 - inc tickcount + 2 - bne @s1 - inc tickcount + 3 -@s1: - ; Acknowlege interrupt - lda a:VDC_CTRL - - ply - plx - pla - rti -_irq2: - rti _nmi: rti -_timer: - stz IRQ_STATUS - rti .export initmainargs initmainargs: @@ -201,8 +171,8 @@ initmainargs: ; ------------------------------------------------------------------------ .segment "VECTORS" - .word _irq2 ; $fff6 IRQ2 (External IRQ, BRK) - .word _irq1 ; $fff8 IRQ1 (VDC) - .word _timer ; $fffa Timer + .word IRQStub ; $fff6 IRQ2 (External IRQ, BRK) + .word IRQStub ; $fff8 IRQ1 (VDC) + .word IRQStub ; $fffa Timer .word _nmi ; $fffc NMI .word start ; $fffe reset diff --git a/libsrc/pce/extzp.inc b/libsrc/pce/extzp.inc index 2869c3a06..dce91558f 100644 --- a/libsrc/pce/extzp.inc +++ b/libsrc/pce/extzp.inc @@ -15,3 +15,4 @@ .global RVS: zp .global BGCOLOR: zp .global tickcount: zp + .global vdc_flags: zp diff --git a/libsrc/pce/extzp.s b/libsrc/pce/extzp.s index 516c30954..26dc589b1 100644 --- a/libsrc/pce/extzp.s +++ b/libsrc/pce/extzp.s @@ -15,3 +15,4 @@ CHARCOLOR: .res 1 RVS: .res 1 BGCOLOR: .res 1 tickcount: .res 4 +vdc_flags: .res 1 diff --git a/libsrc/pce/irq.s b/libsrc/pce/irq.s new file mode 100644 index 000000000..f34303d07 --- /dev/null +++ b/libsrc/pce/irq.s @@ -0,0 +1,48 @@ +; +; IRQ handling (PCE version) +; + + .export initirq, doneirq, IRQStub + + .import __INTERRUPTOR_COUNT__, callirq_y + + .include "pce.inc" + .include "extzp.inc" + +; ------------------------------------------------------------------------ +.segment "INIT" + +; a constructor +; +initirq: + rts + +; ------------------------------------------------------------------------ +.code + +; a destructor +; +doneirq: + rts + +; ------------------------------------------------------------------------ + +IRQStub: + phy + +; Save the display-source flags (and, release the interrupt). +; + ldy a:VDC_CTRL + sty vdc_flags + + ldy #<(__INTERRUPTOR_COUNT__ * 2) + beq @L1 + phx + pha + + jsr callirq_y + + pla + plx +@L1: ply + rti diff --git a/libsrc/pce/ticktock.s b/libsrc/pce/ticktock.s new file mode 100644 index 000000000..4e4d44d9a --- /dev/null +++ b/libsrc/pce/ticktock.s @@ -0,0 +1,18 @@ + .interruptor ticktock, 24 + + .include "pce.inc" + .include "extzp.inc" + +ticktock: + bbr5 vdc_flags,@s1 ; not vertical-blank interrupt + + ; Increment the system tick counter. + inc tickcount + bne @s1 + inc tickcount+1 + bne @s1 + inc tickcount+2 + bne @s1 + inc tickcount+3 + +@s1: rts diff --git a/libsrc/pce/waitvblank.s b/libsrc/pce/waitvblank.s index d60a9ddea..b9f0f902f 100644 --- a/libsrc/pce/waitvblank.s +++ b/libsrc/pce/waitvblank.s @@ -5,6 +5,7 @@ .include "pce.inc" .include "extzp.inc" + .forceimport ticktock .export _waitvblank .proc _waitvblank From 7d453a72fb16f8a26a8a0443ccb34fe3927a98f8 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 20 Sep 2015 12:18:41 +0200 Subject: [PATCH 230/351] use 'plot' instead of 'PLOT' --- libsrc/pce/clrscr.s | 4 ++-- libsrc/pce/kplot.s | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/pce/clrscr.s b/libsrc/pce/clrscr.s index f198be714..e3f40bb8b 100644 --- a/libsrc/pce/clrscr.s +++ b/libsrc/pce/clrscr.s @@ -2,7 +2,7 @@ .include "pce.inc" .include "extzp.inc" - .import PLOT + .import plot .export _clrscr _clrscr: @@ -29,7 +29,7 @@ colloop: stz CURS_X stz CURS_Y - jmp PLOT + jmp plot ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/libsrc/pce/kplot.s b/libsrc/pce/kplot.s index 6c81e4152..e4426d005 100644 --- a/libsrc/pce/kplot.s +++ b/libsrc/pce/kplot.s @@ -8,7 +8,7 @@ PLOT: bcs @getpos tya - clc + ;clc ; already cleared adc _plotlo,x sta SCREEN_PTR From 68a4f34b3d6ab3f4547287e743a36b8b6c366648 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 24 Sep 2015 10:06:24 +0200 Subject: [PATCH 231/351] Use title case. --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4a0a50bed..b04ae72c2 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -[documentation](http://cc65.github.io/doc) +[Documentation](http://cc65.github.io/doc) -[wiki](http://github.com/cc65/wiki/wiki) +[Wiki](http://github.com/cc65/wiki/wiki) -[![build status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) +[![Build Status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) -Binary snapshot for [Windows](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) +[Windows Binary](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) cc65 is a complete cross development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, librarian and several From 74f8de9ab6477426482d6b6625879a0dc093199c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 24 Sep 2015 10:14:30 +0200 Subject: [PATCH 232/351] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b04ae72c2..53be727c7 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Build Status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) -[Windows Binary](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) +[Windows Snapshot](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) cc65 is a complete cross development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, librarian and several From 9704b1d11b83f4e451bff98a70d950d610e50f75 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 24 Sep 2015 10:16:46 +0200 Subject: [PATCH 233/351] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53be727c7..688b38029 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ +[Windows Snapshot](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) + [Documentation](http://cc65.github.io/doc) [Wiki](http://github.com/cc65/wiki/wiki) [![Build Status](https://api.travis-ci.org/cc65/cc65.svg?branch=master)](https://travis-ci.org/cc65/cc65/builds) -[Windows Snapshot](http://sourceforge.net/projects/cc65/files/cc65-snapshot-win32.zip) - cc65 is a complete cross development package for 65(C)02 systems, including a powerful macro assembler, a C compiler, linker, librarian and several other tools. From ed2b8a16098850793c16c8fd616bd576c08103af Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 25 Sep 2015 02:31:17 -0400 Subject: [PATCH 234/351] Fixed a warning message. --- src/ar65/exports.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ar65/exports.c b/src/ar65/exports.c index af176d019..b3bb4cebe 100644 --- a/src/ar65/exports.c +++ b/src/ar65/exports.c @@ -113,9 +113,9 @@ void ExpInsert (const char* Name, const ObjData* Module) while (1) { if (strcmp (L->Name, Name) == 0) { /* Duplicate entry */ - Warning ("External symbol `%s' in module `%s', library `%s' " + Warning ("External symbol `%s' in module `%s', library `%s', " "is duplicated in module `%s'", - Name, L->Name, LibName, Module->Name); + Name, L->Module->Name, LibName, Module->Name); } if (L->Next == 0) { break; From b82bb4f5ba31ea0b1954b36608eba32556c6645e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 25 Sep 2015 14:06:58 -0400 Subject: [PATCH 235/351] Moved two errno helper functions into separate files. Only the function that actually is needed will be linked. It is very useful for targets that do not have file-system I/O. --- libsrc/common/_directerrno.s | 27 ++++++++++++++++++++++++ libsrc/common/_mappederrno.s | 33 +++++++++++++++++++++++++++++ libsrc/common/errno.s | 41 ++++-------------------------------- libsrc/sim6502/errno.s | 30 -------------------------- 4 files changed, 64 insertions(+), 67 deletions(-) create mode 100644 libsrc/common/_directerrno.s create mode 100644 libsrc/common/_mappederrno.s delete mode 100644 libsrc/sim6502/errno.s diff --git a/libsrc/common/_directerrno.s b/libsrc/common/_directerrno.s new file mode 100644 index 000000000..794247148 --- /dev/null +++ b/libsrc/common/_directerrno.s @@ -0,0 +1,27 @@ +; +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King +; +; Helper function for several high-level file functions. +; + + .include "errno.inc" + + .macpack cpu + +; ---------------------------------------------------------------------------- +; int __fastcall__ _directerrno (unsigned char code); +; /* Set errno to a specific error code, clear _oserror, and return -1. Used +; ** by the library. +; */ + +__directerrno: + jsr __seterrno ; Set errno (returns with .A = 0) + sta __oserror ; Clear __oserror +.if (.cpu .bitand CPU_ISET_65SC02) + dec a +.else + lda #$FF ; Return -1 +.endif + tax + rts diff --git a/libsrc/common/_mappederrno.s b/libsrc/common/_mappederrno.s new file mode 100644 index 000000000..33f654c29 --- /dev/null +++ b/libsrc/common/_mappederrno.s @@ -0,0 +1,33 @@ +; +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King +; +; Helper function for several high-level file functions. +; + + .include "errno.inc" + + .macpack generic + .macpack cpu + +; ---------------------------------------------------------------------------- +; int __fastcall__ _mappederrno (unsigned char code); +; /* Set _oserror to the given platform-specific error code. If it is a real +; ** error code (not zero), set errno to the corresponding system error code, +; ** and return -1. Otherwise, return zero. +; ** Used by the library. +; */ + +__mappederrno: + sta __oserror ; Store the error code + tax ; Did we have an error? + bze ok ; Branch if no + jsr __osmaperrno ; Map OS error into errno code + jsr __seterrno ; Save in errno (returns with .A = 0) +.if (.cpu .bitand CPU_ISET_65SC02) + dec a +.else + lda #$FF ; Return -1 if error +.endif + tax +ok: rts diff --git a/libsrc/common/errno.s b/libsrc/common/errno.s index 3a1f1b6c8..f448c3c14 100644 --- a/libsrc/common/errno.s +++ b/libsrc/common/errno.s @@ -1,47 +1,14 @@ ; -; Ullrich von Bassewitz, 2003-08-12 +; 2003-08-12, Ullrich von Bassewitz +; 2015-09-24, Greg King ; -; Helper functions for several high level file functions. +; extern int _errno; +; /* Library errors go here. */ ; - .include "errno.inc" -.code - -; ---------------------------------------------------------------------------- -; int __fastcall__ _directerrno (unsigned char code); -; /* Set errno to a specific error code, clear _oserror and return -1. Used -; ** by the library. -; */ - -__directerrno: - jsr __seterrno ; Set errno, returns with A = 0 - sta __oserror ; Clear __oserror - beq fail ; Branch always - -; ---------------------------------------------------------------------------- -; int __fastcall__ _mappederrno (unsigned char code); -; /* Set _oserror to the given platform specific error code. If it is a real -; ** error code (not zero) set errno to the corresponding system error code -; ** and return -1. Otherwise return zero. -; ** Used by the library. -; */ - -__mappederrno: - sta __oserror ; Store the error code - tax ; Did we have an error? - beq ok ; Branch if no - jsr __osmaperrno ; Map os error into errno code - jsr __seterrno ; Save in errno -fail: lda #$FF ; Return -1 - tax -ok: rts - - -; ---------------------------------------------------------------------------- .bss __errno: .word 0 - diff --git a/libsrc/sim6502/errno.s b/libsrc/sim6502/errno.s deleted file mode 100644 index d9f7e397e..000000000 --- a/libsrc/sim6502/errno.s +++ /dev/null @@ -1,30 +0,0 @@ -; -; 2013-05-16, Oliver Schmidt -; 2015-07-18, Greg King -; -; Helper functions for several high-level functions. -; - - .include "errno.inc" - -; ---------------------------------------------------------------------------- -; int __fastcall__ _directerrno (unsigned char code); -; /* Set errno to a specific error code; and, return -1. Used -; ** by the library. -; */ - -__directerrno: - jsr __seterrno ; Save in errno -fail: lda #$FF ; Return -1 - tax -ok: rts - - -; ---------------------------------------------------------------------------- -; -; extern int _errno; -; - .bss - -__errno: - .word 0 From 9e08c53b01436c22095ce9d7b35cf9d38d4c1c39 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 27 Sep 2015 18:12:25 +0200 Subject: [PATCH 236/351] initial commit of soft80 implementation --- libsrc/c64/extra/soft80.s | 58 +++++ libsrc/c64/soft80.inc | 29 +++ libsrc/c64/soft80_cgetc.s | 90 ++++++++ libsrc/c64/soft80_charset.s | 290 +++++++++++++++++++++++++ libsrc/c64/soft80_chline.s | 28 +++ libsrc/c64/soft80_color.s | 100 +++++++++ libsrc/c64/soft80_conio.s | 74 +++++++ libsrc/c64/soft80_cputc.s | 419 ++++++++++++++++++++++++++++++++++++ libsrc/c64/soft80_cvline.s | 28 +++ libsrc/c64/soft80_kclrscr.s | 60 ++++++ libsrc/c64/soft80_kplot.s | 101 +++++++++ libsrc/c64/soft80_kscreen.s | 9 + testcode/lib/conio.c | 65 ++++++ 13 files changed, 1351 insertions(+) create mode 100644 libsrc/c64/extra/soft80.s create mode 100644 libsrc/c64/soft80.inc create mode 100644 libsrc/c64/soft80_cgetc.s create mode 100644 libsrc/c64/soft80_charset.s create mode 100644 libsrc/c64/soft80_chline.s create mode 100644 libsrc/c64/soft80_color.s create mode 100644 libsrc/c64/soft80_conio.s create mode 100644 libsrc/c64/soft80_cputc.s create mode 100644 libsrc/c64/soft80_cvline.s create mode 100644 libsrc/c64/soft80_kclrscr.s create mode 100644 libsrc/c64/soft80_kplot.s create mode 100644 libsrc/c64/soft80_kscreen.s create mode 100644 testcode/lib/conio.c diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s new file mode 100644 index 000000000..baf61f635 --- /dev/null +++ b/libsrc/c64/extra/soft80.s @@ -0,0 +1,58 @@ + + + ; soft80_cgetc.s + .import soft80_cgetc + .export _cgetc := soft80_cgetc + + ; soft80_chline.s + .import soft80_chlinexy + .import soft80_chline + .export _chlinexy := soft80_chlinexy + .export _chline := soft80_chline + + ; soft80_color.s + .import soft80_textcolor + .import soft80_bgcolor + .import soft80_bordercolor + .export _textcolor := soft80_textcolor + .export _bgcolor := soft80_bgcolor + .export _bordercolor := soft80_bordercolor + + ; soft80_cputc.s + .import soft80_cputc + .import soft80_cputcxy + .import soft80_cputdirect + .import soft80_putchar + .import soft80_newline + .import soft80_plot + .export _cputc := soft80_cputc + .export _cputcxy := soft80_cputcxy + .export cputdirect := soft80_cputdirect + .export putchar := soft80_putchar + .export newline := soft80_newline + .export plot := soft80_plot + + ; soft80_cvline.s + .import soft80_cvlinexy + .import soft80_cvline + .export _cvlinexy := soft80_cvlinexy + .export _cvline := soft80_cvline + + ; soft80_kclrscr.s + .import soft80_kclrscr + .export _clrscr := soft80_kclrscr + .export CLRSCR := soft80_kclrscr + + ; soft80_kplot.s + .import soft80_kplot + .export PLOT := soft80_kplot + + ; soft80_kscreen.s + .import soft80_kscreen + .export SCREEN := soft80_kscreen + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80_init +conio_init = soft80_init diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc new file mode 100644 index 000000000..d67011b4a --- /dev/null +++ b/libsrc/c64/soft80.inc @@ -0,0 +1,29 @@ + +; ram under i/o +soft80_lo_charset = $d000 +soft80_hi_charset = $d400 +soft80_vram = $d800 +soft80_colram = $d800 ; color ram (used for temp. storage) +; ram under kernel +soft80_bitmap = $e000 + +charsperline = 80 +screenrows = 25 + +CH_ESC = 95 +CH_HLINE = 96 +CH_CROSS = 123 +CH_VLINE = 125 +CH_PI = 126 + +; FIXME: these are defined in cbm.h normally, the putchar stuff should accept +; the regular codes instead of the following ones: + +CH_LTEE = 171-160 +CH_URCORNER = 174-160 +CH_LLCORNER = 173-160 +CH_ULCORNER = 176-160 +CH_BTEE = 177-160 +CH_TTEE = 178-160 +CH_RTEE = 179-160 +CH_LRCORNER = 189-160 diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s new file mode 100644 index 000000000..7b8a260f1 --- /dev/null +++ b/libsrc/c64/soft80_cgetc.s @@ -0,0 +1,90 @@ +; +; char cgetc (void); +; + + .export soft80_cgetc + .import cursor ; FIX/CHECK + .import putcolor ; FIX/CHECK + + .include "c64.inc" + .include "soft80.inc" + +soft80_cgetc: + lda KEY_COUNT ; Get number of characters + bne L3 ; Jump if there are already chars waiting + +; Switch on the cursor if needed + + lda cursor + jsr setcursor ; set cursor on or off accordingly + +L1: lda KEY_COUNT ; wait for key + beq L1 + + ldx #0 + lda CURS_FLAG + bne L2 + inx +L2: txa + jsr setcursor + +L3: jsr KBDREAD ; Read char and return in A + ldx #0 + rts + +; Switch the cursor on or off + +; A= 0: cursor off +; 1: cursor on + + .proc setcursor + + ; On or off? + cmp CURS_STATE + bne @set + rts +@set: + sta CURS_STATE + + sei + lda $01 + pha + lda #$34 + sta $01 + + jsr putcolor + + ldy #$00 + + lda CURS_X + and #$01 + bne @l1 + + .repeat 8,line + lda (SCREEN_PTR),y + eor #$f0 + sta (SCREEN_PTR),y + .if (line < 7) + iny + .endif + .endrepeat + +@back: + pla + sta $01 + cli + rts + +@l1: + .repeat 8,line + lda (SCREEN_PTR),y + eor #$0f + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + + jmp @back + + .endproc diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s new file mode 100644 index 000000000..5a180e233 --- /dev/null +++ b/libsrc/c64/soft80_charset.s @@ -0,0 +1,290 @@ +; FIXME: generate charset at runtime + +soft80_lo_charset0: +.byte $0f,$03,$0f,$00,$0f,$07,$05,$0e +.byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f +.byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 +.byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 +.byte $0f,$0b,$05,$05,$0b,$05,$0b,$0b +.byte $0d,$07,$0f,$0f,$0f,$0f,$0f,$0d +.byte $0b,$0b,$0b,$0b,$05,$01,$0b,$01 +.byte $0b,$0b,$0f,$0f,$0d,$0f,$07,$0b +.byte $0b,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$09,$07,$03,$0b,$0f +.byte $0f,$0b,$03,$0b,$03,$01,$01,$0b +.byte $05,$01,$09,$05,$07,$05,$05,$0b +.byte $03,$0b,$03,$0b,$01,$05,$05,$05 +.byte $05,$05,$01,$0b,$07,$0b,$0f,$0a + +soft80_lo_charset1: +.byte $0f,$03,$0f,$0f,$0f,$07,$05,$0e +.byte $0f,$0a,$0e,$0b,$0f,$0b,$0f,$0f +.byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 +.byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 +.byte $0f,$0b,$05,$05,$09,$05,$05,$0b +.byte $0b,$0b,$05,$0b,$0f,$0f,$0f,$0d +.byte $05,$0b,$05,$05,$05,$07,$05,$05 +.byte $05,$05,$0f,$0f,$0b,$0f,$0b,$05 +.byte $05,$0f,$07,$0f,$0d,$0f,$09,$0f +.byte $07,$0b,$0d,$07,$03,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0b,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0b,$07,$0b,$0b,$0b +.byte $0f,$0b,$05,$05,$05,$07,$07,$05 +.byte $05,$0b,$0d,$05,$07,$01,$01,$05 +.byte $05,$05,$05,$05,$0b,$05,$05,$05 +.byte $05,$05,$0d,$0b,$07,$0b,$0f,$0a + +soft80_lo_charset2: +.byte $0f,$03,$0f,$0f,$0f,$07,$0a,$0e +.byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f +.byte $0f,$0b,$0f,$0b,$07,$07,$0e,$0f +.byte $00,$0f,$0d,$0f,$0c,$0b,$03,$03 +.byte $0f,$0b,$05,$00,$07,$0d,$0b,$07 +.byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b +.byte $01,$03,$0d,$0d,$05,$03,$07,$0d +.byte $05,$05,$0b,$0b,$0b,$08,$0b,$0d +.byte $01,$0b,$07,$09,$0d,$0b,$0b,$09 +.byte $07,$0f,$0f,$07,$0b,$05,$03,$0b +.byte $03,$09,$03,$09,$01,$05,$05,$05 +.byte $05,$05,$01,$0b,$0b,$0b,$05,$0b +.byte $0f,$05,$05,$07,$05,$07,$07,$07 +.byte $05,$0b,$0d,$03,$07,$01,$01,$05 +.byte $05,$05,$05,$07,$0b,$05,$05,$05 +.byte $0b,$05,$0b,$0b,$0b,$0b,$0a,$05 + +soft80_lo_charset3: +.byte $09,$03,$0f,$0f,$0f,$07,$0a,$0e +.byte $0f,$0a,$0e,$08,$0f,$08,$03,$0f +.byte $08,$00,$00,$03,$07,$07,$0e,$0f +.byte $0f,$0f,$05,$0f,$0c,$03,$03,$03 +.byte $0f,$0b,$0f,$05,$0b,$0b,$0b,$0f +.byte $0b,$0b,$01,$01,$0f,$01,$0f,$0b +.byte $05,$0b,$0b,$0b,$01,$0d,$03,$0b +.byte $0b,$09,$0f,$0f,$07,$0f,$0d,$0b +.byte $01,$0d,$03,$07,$09,$05,$01,$05 +.byte $03,$03,$0d,$05,$0b,$01,$05,$05 +.byte $05,$05,$05,$07,$0b,$05,$05,$05 +.byte $05,$05,$0d,$0b,$0b,$0b,$05,$00 +.byte $00,$01,$03,$07,$05,$03,$03,$01 +.byte $01,$0b,$0d,$03,$07,$05,$01,$05 +.byte $03,$05,$03,$0b,$0b,$05,$05,$01 +.byte $0b,$0b,$0b,$00,$0b,$0b,$05,$05 + +soft80_lo_charset4: +.byte $09,$03,$00,$0f,$0f,$07,$05,$0e +.byte $05,$05,$0e,$08,$0c,$08,$03,$0f +.byte $08,$00,$00,$03,$07,$07,$0e,$0f +.byte $0f,$0f,$03,$03,$0f,$03,$0f,$0c +.byte $0f,$0f,$0f,$00,$0d,$07,$04,$0f +.byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b +.byte $05,$0b,$07,$0d,$0d,$0d,$05,$0b +.byte $05,$0d,$0f,$0f,$0b,$08,$0b,$0b +.byte $07,$09,$05,$07,$05,$01,$0b,$05 +.byte $05,$0b,$0d,$03,$0b,$01,$05,$05 +.byte $05,$05,$07,$0b,$0b,$05,$05,$01 +.byte $0b,$05,$0b,$0b,$0b,$0b,$0f,$00 +.byte $00,$05,$05,$07,$05,$07,$07,$05 +.byte $05,$0b,$0d,$03,$07,$05,$01,$05 +.byte $07,$05,$03,$0d,$0b,$05,$05,$01 +.byte $0b,$0b,$0b,$00,$07,$0b,$05,$0a + +soft80_lo_charset5: +.byte $0f,$03,$00,$0f,$0f,$07,$05,$0e +.byte $05,$0a,$0e,$0b,$0c,$0f,$0b,$0f +.byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f +.byte $0f,$00,$03,$03,$0f,$0f,$0f,$0c +.byte $0f,$0f,$0f,$05,$03,$05,$05,$0f +.byte $0b,$0b,$05,$0b,$0b,$0f,$0b,$07 +.byte $05,$0b,$07,$05,$0d,$05,$05,$0b +.byte $05,$05,$0b,$0b,$0b,$0f,$0b,$0f +.byte $05,$05,$05,$07,$05,$07,$0b,$09 +.byte $05,$0b,$0d,$05,$0b,$05,$05,$05 +.byte $03,$09,$07,$0d,$0b,$05,$0b,$01 +.byte $05,$09,$07,$0b,$0d,$0b,$0f,$0b +.byte $0f,$05,$05,$05,$05,$07,$07,$05 +.byte $05,$0b,$05,$05,$07,$05,$05,$05 +.byte $07,$0b,$05,$05,$0b,$05,$0b,$05 +.byte $05,$0b,$07,$0b,$07,$0b,$05,$0a + +soft80_lo_charset6: +.byte $0f,$03,$00,$0f,$0f,$07,$0a,$0e +.byte $0a,$05,$0e,$0b,$0c,$0f,$0b,$00 +.byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f +.byte $0f,$00,$07,$03,$0f,$0f,$0f,$0c +.byte $0f,$0b,$0f,$05,$0b,$05,$08,$0f +.byte $0d,$07,$0f,$0f,$0b,$0f,$0b,$07 +.byte $0b,$01,$01,$0b,$0d,$0b,$0b,$0b +.byte $0b,$0b,$0f,$0b,$0d,$0f,$07,$0b +.byte $0b,$09,$03,$09,$09,$09,$0b,$0d +.byte $05,$01,$0d,$05,$01,$05,$05,$0b +.byte $07,$0d,$07,$03,$0d,$09,$0b,$05 +.byte $05,$0d,$01,$09,$0d,$03,$0f,$0b +.byte $0f,$05,$03,$0b,$03,$01,$07,$0b +.byte $05,$01,$0b,$05,$01,$05,$05,$0b +.byte $07,$0d,$05,$0b,$0b,$0b,$0b,$05 +.byte $05,$0b,$01,$0b,$0b,$0b,$05,$05 + +soft80_lo_charset7: +.byte $0f,$03,$00,$0f,$00,$07,$0a,$0e +.byte $0a,$0a,$0e,$0b,$0c,$0f,$0b,$00 +.byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f +.byte $0f,$00,$0f,$03,$0f,$0f,$0f,$0c +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$07,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$07,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$03 +.byte $0f,$0f,$03,$0f,$0f,$0f,$0f,$0f +.byte $07,$0d,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$03,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f +.byte $0f,$0f,$0f,$0b,$0b,$0b,$0f,$05 + +soft80_hi_charset0: +.byte $f0,$30,$f0,$00,$f0,$70,$50,$e0 +.byte $f0,$50,$e0,$b0,$f0,$b0,$f0,$f0 +.byte $f0,$b0,$f0,$b0,$70,$70,$e0,$00 +.byte $00,$f0,$e0,$f0,$c0,$b0,$30,$30 +.byte $f0,$b0,$50,$50,$b0,$50,$b0,$b0 +.byte $d0,$70,$f0,$f0,$f0,$f0,$f0,$d0 +.byte $b0,$b0,$b0,$b0,$50,$10,$b0,$10 +.byte $b0,$b0,$f0,$f0,$d0,$f0,$70,$b0 +.byte $b0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$90,$70,$30,$b0,$f0 +.byte $f0,$b0,$30,$b0,$30,$10,$10,$b0 +.byte $50,$10,$90,$50,$70,$50,$50,$b0 +.byte $30,$b0,$30,$b0,$10,$50,$50,$50 +.byte $50,$50,$10,$b0,$70,$b0,$f0,$a0 + +soft80_hi_charset1: +.byte $f0,$30,$f0,$f0,$f0,$70,$50,$e0 +.byte $f0,$a0,$e0,$b0,$f0,$b0,$f0,$f0 +.byte $f0,$b0,$f0,$b0,$70,$70,$e0,$00 +.byte $00,$f0,$e0,$f0,$c0,$b0,$30,$30 +.byte $f0,$b0,$50,$50,$90,$50,$50,$b0 +.byte $b0,$b0,$50,$b0,$f0,$f0,$f0,$d0 +.byte $50,$b0,$50,$50,$50,$70,$50,$50 +.byte $50,$50,$f0,$f0,$b0,$f0,$b0,$50 +.byte $50,$f0,$70,$f0,$d0,$f0,$90,$f0 +.byte $70,$b0,$d0,$70,$30,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$b0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$b0,$70,$b0,$b0,$b0 +.byte $f0,$b0,$50,$50,$50,$70,$70,$50 +.byte $50,$b0,$d0,$50,$70,$10,$10,$50 +.byte $50,$50,$50,$50,$b0,$50,$50,$50 +.byte $50,$50,$d0,$b0,$70,$b0,$f0,$a0 + +soft80_hi_charset2: +.byte $f0,$30,$f0,$f0,$f0,$70,$a0,$e0 +.byte $f0,$50,$e0,$b0,$f0,$b0,$f0,$f0 +.byte $f0,$b0,$f0,$b0,$70,$70,$e0,$f0 +.byte $00,$f0,$d0,$f0,$c0,$b0,$30,$30 +.byte $f0,$b0,$50,$00,$70,$d0,$b0,$70 +.byte $b0,$b0,$b0,$b0,$f0,$f0,$f0,$b0 +.byte $10,$30,$d0,$d0,$50,$30,$70,$d0 +.byte $50,$50,$b0,$b0,$b0,$80,$b0,$d0 +.byte $10,$b0,$70,$90,$d0,$b0,$b0,$90 +.byte $70,$f0,$f0,$70,$b0,$50,$30,$b0 +.byte $30,$90,$30,$90,$10,$50,$50,$50 +.byte $50,$50,$10,$b0,$b0,$b0,$50,$b0 +.byte $f0,$50,$50,$70,$50,$70,$70,$70 +.byte $50,$b0,$d0,$30,$70,$10,$10,$50 +.byte $50,$50,$50,$70,$b0,$50,$50,$50 +.byte $b0,$50,$b0,$b0,$b0,$b0,$a0,$50 + +soft80_hi_charset3: +.byte $90,$30,$f0,$f0,$f0,$70,$a0,$e0 +.byte $f0,$a0,$e0,$80,$f0,$80,$30,$f0 +.byte $80,$00,$00,$30,$70,$70,$e0,$f0 +.byte $f0,$f0,$50,$f0,$c0,$30,$30,$30 +.byte $f0,$b0,$f0,$50,$b0,$b0,$b0,$f0 +.byte $b0,$b0,$10,$10,$f0,$10,$f0,$b0 +.byte $50,$b0,$b0,$b0,$10,$d0,$30,$b0 +.byte $b0,$90,$f0,$f0,$70,$f0,$d0,$b0 +.byte $10,$d0,$30,$70,$90,$50,$10,$50 +.byte $30,$30,$d0,$50,$b0,$10,$50,$50 +.byte $50,$50,$50,$70,$b0,$50,$50,$50 +.byte $50,$50,$d0,$b0,$b0,$b0,$50,$00 +.byte $00,$10,$30,$70,$50,$30,$30,$10 +.byte $10,$b0,$d0,$30,$70,$50,$10,$50 +.byte $30,$50,$30,$b0,$b0,$50,$50,$10 +.byte $b0,$b0,$b0,$00,$b0,$b0,$50,$50 + +soft80_hi_charset4: +.byte $90,$30,$00,$f0,$f0,$70,$50,$e0 +.byte $50,$50,$e0,$80,$c0,$80,$30,$f0 +.byte $80,$00,$00,$30,$70,$70,$e0,$f0 +.byte $f0,$f0,$30,$30,$f0,$30,$f0,$c0 +.byte $f0,$f0,$f0,$00,$d0,$70,$40,$f0 +.byte $b0,$b0,$b0,$b0,$f0,$f0,$f0,$b0 +.byte $50,$b0,$70,$d0,$d0,$d0,$50,$b0 +.byte $50,$d0,$f0,$f0,$b0,$80,$b0,$b0 +.byte $70,$90,$50,$70,$50,$10,$b0,$50 +.byte $50,$b0,$d0,$30,$b0,$10,$50,$50 +.byte $50,$50,$70,$b0,$b0,$50,$50,$10 +.byte $b0,$50,$b0,$b0,$b0,$b0,$f0,$00 +.byte $00,$50,$50,$70,$50,$70,$70,$50 +.byte $50,$b0,$d0,$30,$70,$50,$10,$50 +.byte $70,$50,$30,$d0,$b0,$50,$50,$10 +.byte $b0,$b0,$b0,$00,$70,$b0,$50,$a0 + +soft80_hi_charset5: +.byte $f0,$30,$00,$f0,$f0,$70,$50,$e0 +.byte $50,$a0,$e0,$b0,$c0,$f0,$b0,$f0 +.byte $b0,$f0,$b0,$b0,$70,$70,$e0,$f0 +.byte $f0,$00,$30,$30,$f0,$f0,$f0,$c0 +.byte $f0,$f0,$f0,$50,$30,$50,$50,$f0 +.byte $b0,$b0,$50,$b0,$b0,$f0,$b0,$70 +.byte $50,$b0,$70,$50,$d0,$50,$50,$b0 +.byte $50,$50,$b0,$b0,$b0,$f0,$b0,$f0 +.byte $50,$50,$50,$70,$50,$70,$b0,$90 +.byte $50,$b0,$d0,$50,$b0,$50,$50,$50 +.byte $30,$90,$70,$d0,$b0,$50,$b0,$10 +.byte $50,$90,$70,$b0,$d0,$b0,$f0,$b0 +.byte $f0,$50,$50,$50,$50,$70,$70,$50 +.byte $50,$b0,$50,$50,$70,$50,$50,$50 +.byte $70,$b0,$50,$50,$b0,$50,$b0,$50 +.byte $50,$b0,$70,$b0,$70,$b0,$50,$a0 + +soft80_hi_charset6: +.byte $f0,$30,$00,$f0,$f0,$70,$a0,$e0 +.byte $a0,$50,$e0,$b0,$c0,$f0,$b0,$00 +.byte $b0,$f0,$b0,$b0,$70,$70,$e0,$f0 +.byte $f0,$00,$70,$30,$f0,$f0,$f0,$c0 +.byte $f0,$b0,$f0,$50,$b0,$50,$80,$f0 +.byte $d0,$70,$f0,$f0,$b0,$f0,$b0,$70 +.byte $b0,$10,$10,$b0,$d0,$b0,$b0,$b0 +.byte $b0,$b0,$f0,$b0,$d0,$f0,$70,$b0 +.byte $b0,$90,$30,$90,$90,$90,$b0,$d0 +.byte $50,$10,$d0,$50,$10,$50,$50,$b0 +.byte $70,$d0,$70,$30,$d0,$90,$b0,$50 +.byte $50,$d0,$10,$90,$d0,$30,$f0,$b0 +.byte $f0,$50,$30,$b0,$30,$10,$70,$b0 +.byte $50,$10,$b0,$50,$10,$50,$50,$b0 +.byte $70,$d0,$50,$b0,$b0,$b0,$b0,$50 +.byte $50,$b0,$10,$b0,$b0,$b0,$50,$50 + +soft80_hi_charset7: +.byte $f0,$30,$00,$f0,$00,$70,$a0,$e0 +.byte $a0,$a0,$e0,$b0,$c0,$f0,$b0,$00 +.byte $b0,$f0,$b0,$b0,$70,$70,$e0,$f0 +.byte $f0,$00,$f0,$30,$f0,$f0,$f0,$c0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$70,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$70,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$30 +.byte $f0,$f0,$30,$f0,$f0,$f0,$f0,$f0 +.byte $70,$d0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$30,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 +.byte $f0,$f0,$f0,$b0,$b0,$b0,$f0,$50 + diff --git a/libsrc/c64/soft80_chline.s b/libsrc/c64/soft80_chline.s new file mode 100644 index 000000000..0fc711870 --- /dev/null +++ b/libsrc/c64/soft80_chline.s @@ -0,0 +1,28 @@ +; +; void chlinexy (unsigned char x, unsigned char y, unsigned char length); +; void chline (unsigned char length); +; + + .export soft80_chlinexy, soft80_chline + .import popa, _gotoxy, cputdirect ; FIX/CHECK + .importzp tmp1 + +soft80_chlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length + +soft80_chline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #96 ; Horizontal line, screen code + jsr cputdirect ; Direct output + dec tmp1 + bne L1 +L9: rts + + + + diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s new file mode 100644 index 000000000..553bc7f29 --- /dev/null +++ b/libsrc/c64/soft80_color.s @@ -0,0 +1,100 @@ +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + .export soft80_textcolor, soft80_bgcolor, soft80_bordercolor + .export __textcolor,__bgcolor ; CHECK/FIX + + .importzp tmp1,tmp2 + + .import soft80_checkchar + + .include "c64.inc" + .include "soft80.inc" + +soft80_textcolor: + + ldx __textcolor ; get old value + sta __textcolor ; set new value + + lda __bgcolor + asl a + asl a + asl a + asl a + ora __textcolor + sta CHARCOLOR + + txa ; get old value + rts + + +soft80_bgcolor: + cmp __bgcolor + beq _donothing + ldx __bgcolor ; get old value + sta __bgcolor ; set new value + asl a + asl a + asl a + asl a + sta tmp2 ; shifted new value + ora __textcolor + sta CHARCOLOR ; text/bg combo for new chars + txa + pha ; save old value + sta tmp1 + + sei + lda $01 + pha + + lda #$34 + sta $01 + + ldx #$00 + +lp2: + .repeat $4,page + + .scope + lda soft80_vram+(page*$100),x + and #$0f + cmp tmp1 ; old bg color + bne as + ; is old bg color + ; is space + ;lda __bgcolor +as: + ora tmp2 ; new bg color + sta soft80_vram+(page*$100),x + .endscope + + .endrepeat + + inx + bne lp2 + + pla + sta $01 + cli + + pla ; get old value +_donothing: + rts + + +soft80_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts + + ; FIXME: shouldnt they be in zeropage? + .bss +__textcolor: + .res 1 +__bgcolor: + .res 1 diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s new file mode 100644 index 000000000..20d9926de --- /dev/null +++ b/libsrc/c64/soft80_conio.s @@ -0,0 +1,74 @@ +; +; Low level stuff for screen output/console input +; + + .constructor soft80_init, 24 + .destructor soft80_shutdown + + .import soft80_kclrscr, soft80_plotinit + .import __textcolor, __bgcolor ; CHECK/FIX + + .include "c64.inc" + .include "soft80.inc" + +soft80_init: + lda #$3b + sta VIC_CTRL1 + lda #$00 + sta CIA2_PRA + lda #$68 + sta VIC_VIDEO_ADR + lda #$c8 + sta VIC_CTRL2 + +; copy charset to RAM under I/O -> FIXME: generate at runtime + sei + lda $01 + pha + lda #$34 + sta $01 + + lda #>soft80_lo_charset0 + sta @hi1+2 + lda #>$d000 + sta @hi2+2 + + ldy #8 +@l2: + ldx #0 +@l1: +@hi1: lda soft80_lo_charset0,x +@hi2: sta $d000,x + inx + bne @l1 + inc @hi1+2 + inc @hi2+2 + dey + bne @l2 + + pla + sta $01 + cli + + jsr soft80_plotinit + + lda #1 + sta __textcolor + lda #0 + sta __bgcolor + + jmp soft80_kclrscr + +soft80_shutdown: + lda #$1b + sta VIC_CTRL1 + lda #$03 + sta CIA2_PRA + lda #$15 + sta VIC_VIDEO_ADR + rts + +; FIXME: generate the charset at init time, and put it into RAM under I/O + + .include "soft80_charset.s" + diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s new file mode 100644 index 000000000..2e75aa541 --- /dev/null +++ b/libsrc/c64/soft80_cputc.s @@ -0,0 +1,419 @@ +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + + .export soft80_cputcxy, soft80_cputc + .export soft80_cputdirect, soft80_putchar + .export putcolor ; FIX/CHECK + + .export soft80_newline, soft80_plot + .import popa, _gotoxy + .import xsize + .import PLOT ; FIX/CHECK + .importzp tmp4,tmp3 + .import __bgcolor ; FIX/CHECK + + .macpack longbranch + + .include "c64.inc" + .include "soft80.inc" + +soft80_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +soft80_cputc: + cmp #$0A ; CR? + bne L1 + + lda #0 + sta CURS_X + + ; Set cursor position, calculate RAM pointers +soft80_plot: + ldx CURS_Y + ldy CURS_X + clc + jmp PLOT ; Set the new cursor + +L1: cmp #$0D ; LF? + beq soft80_newline ; Recalculate pointers + + ; Printable char of some sort + + tay + bpl L10 + + clc + adc #$20 + and #$7F +L10: + +soft80_cputdirect: + jsr soft80_putchar ; Write the character to the screen + +; Advance cursor position + +advance: + iny + cpy #charsperline + beq L3 + + sty CURS_X + tya + and #$01 + bne @L5 + + lda SCREEN_PTR + clc + adc #8 + sta SCREEN_PTR + bcc @L4 + inc SCREEN_PTR+1 +@L4: + inc CRAM_PTR + bne @L5 + inc CRAM_PTR+1 +@L5: + rts +L3: + inc CURS_Y ; new line + ldy #0 ; + cr + sty CURS_X + jmp soft80_plot + +soft80_newline: + + lda SCREEN_PTR + clc + adc #<(40*8) + sta SCREEN_PTR + + lda SCREEN_PTR+1 + adc #>(40*8) + sta SCREEN_PTR+1 + + lda CRAM_PTR + clc + adc #40 + sta CRAM_PTR + bcc L5 + inc CRAM_PTR+1 +L5: + inc CURS_Y + rts + +; Write one character to the screen without doing anything else +; in: A: character +; returns: Y: cursor X position +; this function is going to be used a lot so we unroll it a bit for speed + +;--- start color vodoo + +; remove color from cell +; y unmodified +remcolor: + + ;ldy #$00 ; is still $00 + + lda (CRAM_PTR),y ; vram + and #$0f + cmp __bgcolor + jeq @l2b ; vram==bgcolor + + inc $01 + lda (CRAM_PTR),y ; colram + stx $01 ;$34 + and #$0f + cmp __bgcolor + beq @l2s ; colram==bgcolor + + ; vram = colram + ;inc $01 + ;lda (CRAM_PTR),y ; colram + ;stx $01 ;$34 + ;and #$0f + + sta tmp3 + lda (CRAM_PTR),y ; vram + and #$f0 + ora tmp3 + sta (CRAM_PTR),y ; vram + + ; colram = bgcolor + lda __bgcolor + inc $01 + sta (CRAM_PTR),y ; colram + stx $01 ;$34 + + jmp @l2b + +@l2s: + ; colram is bgcolor + ; => only one char in cell used + + jsr soft80_checkchar + bcc @l2b ; space at current position + + ; vram = bgcolor + lda (CRAM_PTR),y ; vram + and #$f0 + ora __bgcolor + sta (CRAM_PTR),y ; vram +@l2b: + rts + +; put color to cell +; y unmodified +putcolor: + + ;ldy #$00 ; is still $00 + + lda (CRAM_PTR),y ; vram + and #$0f + cmp __bgcolor + beq @l2s ; vram==bgcolor => first char in cell + + ; vram!=bgcolor => second char in cell + + inc $01 ;$35 + lda (CRAM_PTR),y ; colram + stx $01 ;$34 + and #$0f + cmp __bgcolor + bne @l2s ; colram!=bgcolor + + ; colram==bgcolor => second char in cell or overwrite 1st char + + jsr soft80_checkchar + bcs @l2a ; char at current position => overwrite 1st + + ; colram=vram + lda (CRAM_PTR),y ; vram + inc $01 + sta (CRAM_PTR),y ; colram + stx $01 ;$34 + + ;jmp @l2a + +@l2s: + ; colram!=bgcolor => alread 2 chars in cell +@l2a: + + ; Set color + lda CHARCOLOR + sta (CRAM_PTR),y ; vram + + rts + + +;--- end color vodoo + + .export soft80_checkchar + +; test if there is a space or a character at current position +; CLC: space SEC: character +soft80_checkchar: + + ;ldy #$00 ; is still $00 + + lda CURS_X + and #$01 + jne @l1a + + .repeat 8,line + lda (SCREEN_PTR),y + and #$f0 + cmp #$f0 + bne @l2b + .if (line < 7) + iny + .endif + .endrepeat + + ldy #$00 + clc + rts +@l2b: + ldy #$00 + sec + rts +@l1a: + .repeat 8,line + lda (SCREEN_PTR),y + and #$0f + cmp #$0f + bne @l2bb + .if line < 7 + iny + .endif + .endrepeat + ldy #$00 + clc + rts +@l2bb: + ldy #$00 + sec + rts + +; output space + +_space: + + lda RVS + jne _spaceinvers + + jsr remcolor + + ;ldy #$00 ; is still $00 + + lda CURS_X + and #$01 + bne @l1 + + .repeat 8,line + lda (SCREEN_PTR),y + ora #$f0 + sta (SCREEN_PTR),y + .if (line < 7) + iny + .endif + .endrepeat + jmp _back +@l1: + .repeat 8,line + lda (SCREEN_PTR),y + ora #$0f + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat +@l2: + jmp _back + +; output inverted space + +_spaceinvers: + + jsr putcolor + + lda CURS_X + and #$01 + bne @l1 + + .repeat 8,line + lda (SCREEN_PTR),y + and #$0f + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + jmp _back +@l1: + .repeat 8,line + lda (SCREEN_PTR),y + and #$f0 + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + + jmp _back + +; output a character + +soft80_putchar: + sta tmp3 + + sei + ldx $01 + stx tmp4 + ldx #$34 + + stx $01 ; will stay $34 for space + ldy #$00 ; will be $00 from now on + + cmp #' ' ; space is a special (optimized) case + jeq _space + + jsr putcolor + +; output character +char: + ldx tmp3 + + lda RVS + jne _invers + + lda CURS_X + and #$01 + bne @l1 + + .repeat 8,line + lda (SCREEN_PTR),y + and #$0f + ora soft80_hi_charset+(line*$80),x + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + jmp @l2 +@l1: + + .repeat 8,line + lda (SCREEN_PTR),y + and #$f0 + ora soft80_lo_charset+(line*$80),x + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + +@l2: + +_back: + lda tmp4 + sta $01 + cli + + ldy CURS_X + rts + +; output inverted character +_invers: + + lda CURS_X + and #$01 + bne @l1 + + .repeat 8,line + lda (SCREEN_PTR),y + ora #$f0 + eor soft80_hi_charset+(line*$80),x + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + jmp _back +@l1: + .repeat 8,line + lda (SCREEN_PTR),y + ora #$0f + eor soft80_lo_charset+(line*$80),x + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + jmp _back diff --git a/libsrc/c64/soft80_cvline.s b/libsrc/c64/soft80_cvline.s new file mode 100644 index 000000000..78f92278d --- /dev/null +++ b/libsrc/c64/soft80_cvline.s @@ -0,0 +1,28 @@ +; +; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); +; void cvline (unsigned char length); +; + + .export soft80_cvline, soft80_cvlinexy + .import popa, _gotoxy, putchar, newline ; CHECK/FIX + .importzp tmp1 + +soft80_cvlinexy: + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length and run into soft80_cvlinexy + +soft80_cvline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #125 ; Vertical bar + jsr putchar ; Write, no cursor advance + jsr newline ; Advance cursor to next line + dec tmp1 + bne L1 +L9: rts + + + diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s new file mode 100644 index 000000000..e801c9398 --- /dev/null +++ b/libsrc/c64/soft80_kclrscr.s @@ -0,0 +1,60 @@ + + .export soft80_kclrscr + .import soft80_kplot + .import __bgcolor ; FIX/CHECK + + .include "c64.inc" + .include "soft80.inc" + +soft80_kclrscr: + + lda #$ff + + ldx #$00 +lp1: + .repeat $20,page + sta soft80_bitmap+(page*$100),x + .endrepeat + inx + bne lp1 + + sei + ldy $01 + lda #$34 + sta $01 + + lda CHARCOLOR + and #$f0 + ora __bgcolor + + ;ldx #$00 +lp2: + .repeat $4,page + sta soft80_vram+(page*$100),x + .endrepeat + inx + bne lp2 + + inc $01 + + lda __bgcolor + ;ldx #$00 +lp3: + .repeat $4,page + sta soft80_colram+(page*$100),x + .endrepeat + inx + bne lp3 + + + sty $01 + cli + + ldx #0 + ldy #0 + clc + jmp soft80_kplot + + + + diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s new file mode 100644 index 000000000..c6c6b94cc --- /dev/null +++ b/libsrc/c64/soft80_kplot.s @@ -0,0 +1,101 @@ + + .export soft80_kplot + .export soft80_plotinit + + .include "c64.inc" + .include "soft80.inc" + +soft80_kplot: + bcs @getpos + + ; calc pointer to bitmap + lda _bitmaplo,x + clc + adc _bitmapxlo,y + sta SCREEN_PTR + lda _bitmaphi,x + adc _bitmapxhi,y + sta SCREEN_PTR+1 + + ; calc pointer to vram + tya + lsr a + clc + adc _vramlo,x + sta CRAM_PTR + lda #0 + adc _vramhi,x + sta CRAM_PTR+1 + +@getpos: + ldx CURS_Y + ldy CURS_X + rts + + ; FIXME: perhaps just include the respective tables directly? +soft80_plotinit: + ; create screen-rows base tables (bitmap) + lda #<soft80_bitmap + sta SCREEN_PTR + lda #>soft80_bitmap + sta SCREEN_PTR+1 + + ldx #$00 +l1: + lda SCREEN_PTR + sta _bitmaplo,x + clc + adc #<(40*8) + sta SCREEN_PTR + lda SCREEN_PTR+1 + sta _bitmaphi,x + adc #>(40*8) + sta SCREEN_PTR+1 + inx + cpx #25 + bne l1 + + ; create screen-rows base tables (colorram) + + lda #<soft80_vram + sta CRAM_PTR + lda #>soft80_vram + sta CRAM_PTR+1 + + ldx #$00 +l1b: + lda CRAM_PTR + sta _vramlo,x + clc + adc #<(40) + sta CRAM_PTR + lda CRAM_PTR+1 + sta _vramhi,x + adc #>(40) + sta CRAM_PTR+1 + inx + cpx #25 + bne l1b + + rts + +_bitmapxlo: + .repeat 80,col1 + .byte <((col1/2)*8) + .endrepeat + +_bitmapxhi: + .repeat 80,col + .byte >((col/2)*8) + .endrepeat + + .bss +_vramlo: + .res 25 +_vramhi: + .res 25 +_bitmaplo: + .res 25 +_bitmaphi: + .res 25 + diff --git a/libsrc/c64/soft80_kscreen.s b/libsrc/c64/soft80_kscreen.s new file mode 100644 index 000000000..22c7b6788 --- /dev/null +++ b/libsrc/c64/soft80_kscreen.s @@ -0,0 +1,9 @@ + + .export soft80_kscreen + + .include "soft80.inc" + +soft80_kscreen: + ldy #screenrows + ldx #charsperline + rts diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c new file mode 100644 index 000000000..6ec17eb1f --- /dev/null +++ b/testcode/lib/conio.c @@ -0,0 +1,65 @@ + +#include <conio.h> +#include <string.h> +#include <stdlib.h> + +void main(void) +{ + int i, j; + unsigned char xsize, ysize, n; + + clrscr(); + screensize(&xsize, &ysize); + + cputs("cc65 conio test"); + cputsxy(0, 2, "colors:" ); + for (i = 3; i < 6; ++i) { + gotoxy(i,i); + for (j = 0; j < 16; ++j) { + textcolor(j); + cputc('X'); + } + } + textcolor(1); + + cprintf("\n\n\rscreensize is: %dx%d", xsize, ysize ); + + chlinexy(0,10,xsize); + cvlinexy(0,10,3); + chlinexy(0,12,xsize); + cvlinexy(xsize-1,10,3); + cputcxy(0,10,CH_ULCORNER); + cputcxy(xsize-1,10,CH_URCORNER); + cputcxy(0,12,CH_LLCORNER); + cputcxy(xsize-1,12,CH_LRCORNER); + + gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + for (i = 0; i < 256; ++i) { + if ((i != '\n') && (i != '\r')) { + cputc(i); + } + } + while(wherex() > 0) { + cputc('#'); + } + for (i = 0; i < xsize; ++i) { + cputc('0' + i % 10); + } + + for(;;) { + + gotoxy(xsize - 10, 3); + j = (n >> 5) & 1; + revers(j); + cputc(j ? 'R' : ' '); + cputs(" revers"); + revers(0); + + ++n; + } + + for(;;); +} From fba28f46f6b71b1861db902291251d50facdb0de Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 27 Sep 2015 18:36:53 +0200 Subject: [PATCH 237/351] fix initial text- and background colors --- libsrc/c64/soft80_color.s | 9 +++------ libsrc/c64/soft80_conio.s | 12 +++++++----- testcode/lib/conio.c | 9 +++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index 553bc7f29..c176eca7f 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -25,15 +25,13 @@ soft80_textcolor: asl a asl a ora __textcolor - sta CHARCOLOR + sta CHARCOLOR ; text/bg combo for new chars txa ; get old value rts soft80_bgcolor: - cmp __bgcolor - beq _donothing ldx __bgcolor ; get old value sta __bgcolor ; set new value asl a @@ -62,8 +60,8 @@ lp2: .scope lda soft80_vram+(page*$100),x and #$0f - cmp tmp1 ; old bg color - bne as + ;cmp tmp1 ; old bg color + ;bne as ; is old bg color ; is space ;lda __bgcolor @@ -82,7 +80,6 @@ as: cli pla ; get old value -_donothing: rts diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 20d9926de..eb05e4e8b 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -6,7 +6,7 @@ .destructor soft80_shutdown .import soft80_kclrscr, soft80_plotinit - .import __textcolor, __bgcolor ; CHECK/FIX + .import soft80_textcolor, soft80_bgcolor .include "c64.inc" .include "soft80.inc" @@ -52,10 +52,12 @@ soft80_init: jsr soft80_plotinit - lda #1 - sta __textcolor - lda #0 - sta __bgcolor + lda 646 ; use current textcolor + jsr soft80_textcolor + + lda VIC_BG_COLOR0 ; use current bgcolor + and #$0f + jsr soft80_bgcolor jmp soft80_kclrscr diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index 6ec17eb1f..752687f34 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -5,13 +5,14 @@ void main(void) { - int i, j; - unsigned char xsize, ysize, n; + int i, j, n; + unsigned char xsize, ysize, tcol; clrscr(); screensize(&xsize, &ysize); - cputs("cc65 conio test"); + + tcol = textcolor(1); cputsxy(0, 2, "colors:" ); for (i = 3; i < 6; ++i) { gotoxy(i,i); @@ -20,7 +21,7 @@ void main(void) cputc('X'); } } - textcolor(1); + textcolor(tcol); cprintf("\n\n\rscreensize is: %dx%d", xsize, ysize ); From b5a6578dcab61be7f34fe19d959c7bac3dac2f4d Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 27 Sep 2015 18:49:30 +0200 Subject: [PATCH 238/351] include bitmap and vram row tables directly rather than generating them (saves space) --- libsrc/c64/soft80_conio.s | 4 +-- libsrc/c64/soft80_kplot.s | 71 +++++++++------------------------------ 2 files changed, 16 insertions(+), 59 deletions(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index eb05e4e8b..199ac3584 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -5,7 +5,7 @@ .constructor soft80_init, 24 .destructor soft80_shutdown - .import soft80_kclrscr, soft80_plotinit + .import soft80_kclrscr .import soft80_textcolor, soft80_bgcolor .include "c64.inc" @@ -50,8 +50,6 @@ soft80_init: sta $01 cli - jsr soft80_plotinit - lda 646 ; use current textcolor jsr soft80_textcolor diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index c6c6b94cc..a813fd679 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -1,6 +1,5 @@ .export soft80_kplot - .export soft80_plotinit .include "c64.inc" .include "soft80.inc" @@ -32,70 +31,30 @@ soft80_kplot: ldy CURS_X rts - ; FIXME: perhaps just include the respective tables directly? -soft80_plotinit: - ; create screen-rows base tables (bitmap) - lda #<soft80_bitmap - sta SCREEN_PTR - lda #>soft80_bitmap - sta SCREEN_PTR+1 - - ldx #$00 -l1: - lda SCREEN_PTR - sta _bitmaplo,x - clc - adc #<(40*8) - sta SCREEN_PTR - lda SCREEN_PTR+1 - sta _bitmaphi,x - adc #>(40*8) - sta SCREEN_PTR+1 - inx - cpx #25 - bne l1 - - ; create screen-rows base tables (colorram) - - lda #<soft80_vram - sta CRAM_PTR - lda #>soft80_vram - sta CRAM_PTR+1 - - ldx #$00 -l1b: - lda CRAM_PTR - sta _vramlo,x - clc - adc #<(40) - sta CRAM_PTR - lda CRAM_PTR+1 - sta _vramhi,x - adc #>(40) - sta CRAM_PTR+1 - inx - cpx #25 - bne l1b - - rts - + .rodata _bitmapxlo: - .repeat 80,col1 - .byte <((col1/2)*8) + .repeat 80,col + .byte <((col/2)*8) .endrepeat _bitmapxhi: .repeat 80,col .byte >((col/2)*8) .endrepeat - - .bss _vramlo: - .res 25 + .repeat 25,row + .byte <(soft80_vram+(row*40)) + .endrepeat _vramhi: - .res 25 + .repeat 25,row + .byte >(soft80_vram+(row*40)) + .endrepeat _bitmaplo: - .res 25 + .repeat 25,row + .byte <(soft80_bitmap+(row*40*8)) + .endrepeat _bitmaphi: - .res 25 + .repeat 25,row + .byte >(soft80_bitmap+(row*40*8)) + .endrepeat From c221fe22f66dd0371097c9eb1a23685d77eb3fa6 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 27 Sep 2015 19:10:06 +0200 Subject: [PATCH 239/351] prepend soft80_ to some more internally used functions --- libsrc/c64/soft80_cgetc.s | 4 ++-- libsrc/c64/soft80_chline.s | 18 +++++++++--------- libsrc/c64/soft80_cputc.s | 17 +++++++++-------- libsrc/c64/soft80_cvline.s | 6 +++--- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 7b8a260f1..12b2071a2 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -4,7 +4,7 @@ .export soft80_cgetc .import cursor ; FIX/CHECK - .import putcolor ; FIX/CHECK + .import soft80_putcolor .include "c64.inc" .include "soft80.inc" @@ -52,7 +52,7 @@ L3: jsr KBDREAD ; Read char and return in A lda #$34 sta $01 - jsr putcolor + jsr soft80_putcolor ldy #$00 diff --git a/libsrc/c64/soft80_chline.s b/libsrc/c64/soft80_chline.s index 0fc711870..de6ab7637 100644 --- a/libsrc/c64/soft80_chline.s +++ b/libsrc/c64/soft80_chline.s @@ -4,21 +4,21 @@ ; .export soft80_chlinexy, soft80_chline - .import popa, _gotoxy, cputdirect ; FIX/CHECK + .import popa, _gotoxy, soft80_cputdirect .importzp tmp1 soft80_chlinexy: - pha ; Save the length - jsr popa ; Get y - jsr _gotoxy ; Call this one, will pop params - pla ; Restore the length + pha ; Save the length + jsr popa ; Get y + jsr _gotoxy ; Call this one, will pop params + pla ; Restore the length soft80_chline: - cmp #0 ; Is the length zero? - beq L9 ; Jump if done + cmp #0 ; Is the length zero? + beq L9 ; Jump if done sta tmp1 -L1: lda #96 ; Horizontal line, screen code - jsr cputdirect ; Direct output +L1: lda #96 ; Horizontal line, screen code + jsr soft80_cputdirect ; Direct output dec tmp1 bne L1 L9: rts diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 2e75aa541..c81913476 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -5,15 +5,16 @@ .export soft80_cputcxy, soft80_cputc .export soft80_cputdirect, soft80_putchar - .export putcolor ; FIX/CHECK - + .export soft80_putcolor .export soft80_newline, soft80_plot + .import popa, _gotoxy .import xsize - .import PLOT ; FIX/CHECK - .importzp tmp4,tmp3 + .import soft80_kplot .import __bgcolor ; FIX/CHECK + .importzp tmp4,tmp3 + .macpack longbranch .include "c64.inc" @@ -39,7 +40,7 @@ soft80_plot: ldx CURS_Y ldy CURS_X clc - jmp PLOT ; Set the new cursor + jmp soft80_kplot ; Set the new cursor L1: cmp #$0D ; LF? beq soft80_newline ; Recalculate pointers @@ -170,7 +171,7 @@ remcolor: ; put color to cell ; y unmodified -putcolor: +soft80_putcolor: ;ldy #$00 ; is still $00 @@ -301,7 +302,7 @@ _space: _spaceinvers: - jsr putcolor + jsr soft80_putcolor lda CURS_X and #$01 @@ -344,7 +345,7 @@ soft80_putchar: cmp #' ' ; space is a special (optimized) case jeq _space - jsr putcolor + jsr soft80_putcolor ; output character char: diff --git a/libsrc/c64/soft80_cvline.s b/libsrc/c64/soft80_cvline.s index 78f92278d..a24d17c79 100644 --- a/libsrc/c64/soft80_cvline.s +++ b/libsrc/c64/soft80_cvline.s @@ -4,7 +4,7 @@ ; .export soft80_cvline, soft80_cvlinexy - .import popa, _gotoxy, putchar, newline ; CHECK/FIX + .import popa, _gotoxy, soft80_putchar, soft80_newline .importzp tmp1 soft80_cvlinexy: @@ -18,8 +18,8 @@ soft80_cvline: beq L9 ; Jump if done sta tmp1 L1: lda #125 ; Vertical bar - jsr putchar ; Write, no cursor advance - jsr newline ; Advance cursor to next line + jsr soft80_putchar ; Write, no cursor advance + jsr soft80_newline ; Advance cursor to next line dec tmp1 bne L1 L9: rts From 257183fa551bc628874913b8a89b28b3b8b4b6b8 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 27 Sep 2015 19:34:43 +0200 Subject: [PATCH 240/351] removed duplicate copy of charset and shift it at init time, saves 1k --- libsrc/c64/soft80_charset.s | 153 ------------------------------------ libsrc/c64/soft80_chline.s | 2 +- libsrc/c64/soft80_conio.s | 43 ++++++---- libsrc/c64/soft80_cvline.s | 2 +- 4 files changed, 31 insertions(+), 169 deletions(-) diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s index 5a180e233..999d199f0 100644 --- a/libsrc/c64/soft80_charset.s +++ b/libsrc/c64/soft80_charset.s @@ -1,6 +1,4 @@ -; FIXME: generate charset at runtime -soft80_lo_charset0: .byte $0f,$03,$0f,$00,$0f,$07,$05,$0e .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 @@ -18,7 +16,6 @@ soft80_lo_charset0: .byte $03,$0b,$03,$0b,$01,$05,$05,$05 .byte $05,$05,$01,$0b,$07,$0b,$0f,$0a -soft80_lo_charset1: .byte $0f,$03,$0f,$0f,$0f,$07,$05,$0e .byte $0f,$0a,$0e,$0b,$0f,$0b,$0f,$0f .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 @@ -36,7 +33,6 @@ soft80_lo_charset1: .byte $05,$05,$05,$05,$0b,$05,$05,$05 .byte $05,$05,$0d,$0b,$07,$0b,$0f,$0a -soft80_lo_charset2: .byte $0f,$03,$0f,$0f,$0f,$07,$0a,$0e .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$0f @@ -54,7 +50,6 @@ soft80_lo_charset2: .byte $05,$05,$05,$07,$0b,$05,$05,$05 .byte $0b,$05,$0b,$0b,$0b,$0b,$0a,$05 -soft80_lo_charset3: .byte $09,$03,$0f,$0f,$0f,$07,$0a,$0e .byte $0f,$0a,$0e,$08,$0f,$08,$03,$0f .byte $08,$00,$00,$03,$07,$07,$0e,$0f @@ -72,7 +67,6 @@ soft80_lo_charset3: .byte $03,$05,$03,$0b,$0b,$05,$05,$01 .byte $0b,$0b,$0b,$00,$0b,$0b,$05,$05 -soft80_lo_charset4: .byte $09,$03,$00,$0f,$0f,$07,$05,$0e .byte $05,$05,$0e,$08,$0c,$08,$03,$0f .byte $08,$00,$00,$03,$07,$07,$0e,$0f @@ -90,7 +84,6 @@ soft80_lo_charset4: .byte $07,$05,$03,$0d,$0b,$05,$05,$01 .byte $0b,$0b,$0b,$00,$07,$0b,$05,$0a -soft80_lo_charset5: .byte $0f,$03,$00,$0f,$0f,$07,$05,$0e .byte $05,$0a,$0e,$0b,$0c,$0f,$0b,$0f .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f @@ -108,7 +101,6 @@ soft80_lo_charset5: .byte $07,$0b,$05,$05,$0b,$05,$0b,$05 .byte $05,$0b,$07,$0b,$07,$0b,$05,$0a -soft80_lo_charset6: .byte $0f,$03,$00,$0f,$0f,$07,$0a,$0e .byte $0a,$05,$0e,$0b,$0c,$0f,$0b,$00 .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f @@ -126,7 +118,6 @@ soft80_lo_charset6: .byte $07,$0d,$05,$0b,$0b,$0b,$0b,$05 .byte $05,$0b,$01,$0b,$0b,$0b,$05,$05 -soft80_lo_charset7: .byte $0f,$03,$00,$0f,$00,$07,$0a,$0e .byte $0a,$0a,$0e,$0b,$0c,$0f,$0b,$00 .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f @@ -144,147 +135,3 @@ soft80_lo_charset7: .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f .byte $0f,$0f,$0f,$0b,$0b,$0b,$0f,$05 -soft80_hi_charset0: -.byte $f0,$30,$f0,$00,$f0,$70,$50,$e0 -.byte $f0,$50,$e0,$b0,$f0,$b0,$f0,$f0 -.byte $f0,$b0,$f0,$b0,$70,$70,$e0,$00 -.byte $00,$f0,$e0,$f0,$c0,$b0,$30,$30 -.byte $f0,$b0,$50,$50,$b0,$50,$b0,$b0 -.byte $d0,$70,$f0,$f0,$f0,$f0,$f0,$d0 -.byte $b0,$b0,$b0,$b0,$50,$10,$b0,$10 -.byte $b0,$b0,$f0,$f0,$d0,$f0,$70,$b0 -.byte $b0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$90,$70,$30,$b0,$f0 -.byte $f0,$b0,$30,$b0,$30,$10,$10,$b0 -.byte $50,$10,$90,$50,$70,$50,$50,$b0 -.byte $30,$b0,$30,$b0,$10,$50,$50,$50 -.byte $50,$50,$10,$b0,$70,$b0,$f0,$a0 - -soft80_hi_charset1: -.byte $f0,$30,$f0,$f0,$f0,$70,$50,$e0 -.byte $f0,$a0,$e0,$b0,$f0,$b0,$f0,$f0 -.byte $f0,$b0,$f0,$b0,$70,$70,$e0,$00 -.byte $00,$f0,$e0,$f0,$c0,$b0,$30,$30 -.byte $f0,$b0,$50,$50,$90,$50,$50,$b0 -.byte $b0,$b0,$50,$b0,$f0,$f0,$f0,$d0 -.byte $50,$b0,$50,$50,$50,$70,$50,$50 -.byte $50,$50,$f0,$f0,$b0,$f0,$b0,$50 -.byte $50,$f0,$70,$f0,$d0,$f0,$90,$f0 -.byte $70,$b0,$d0,$70,$30,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$b0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$b0,$70,$b0,$b0,$b0 -.byte $f0,$b0,$50,$50,$50,$70,$70,$50 -.byte $50,$b0,$d0,$50,$70,$10,$10,$50 -.byte $50,$50,$50,$50,$b0,$50,$50,$50 -.byte $50,$50,$d0,$b0,$70,$b0,$f0,$a0 - -soft80_hi_charset2: -.byte $f0,$30,$f0,$f0,$f0,$70,$a0,$e0 -.byte $f0,$50,$e0,$b0,$f0,$b0,$f0,$f0 -.byte $f0,$b0,$f0,$b0,$70,$70,$e0,$f0 -.byte $00,$f0,$d0,$f0,$c0,$b0,$30,$30 -.byte $f0,$b0,$50,$00,$70,$d0,$b0,$70 -.byte $b0,$b0,$b0,$b0,$f0,$f0,$f0,$b0 -.byte $10,$30,$d0,$d0,$50,$30,$70,$d0 -.byte $50,$50,$b0,$b0,$b0,$80,$b0,$d0 -.byte $10,$b0,$70,$90,$d0,$b0,$b0,$90 -.byte $70,$f0,$f0,$70,$b0,$50,$30,$b0 -.byte $30,$90,$30,$90,$10,$50,$50,$50 -.byte $50,$50,$10,$b0,$b0,$b0,$50,$b0 -.byte $f0,$50,$50,$70,$50,$70,$70,$70 -.byte $50,$b0,$d0,$30,$70,$10,$10,$50 -.byte $50,$50,$50,$70,$b0,$50,$50,$50 -.byte $b0,$50,$b0,$b0,$b0,$b0,$a0,$50 - -soft80_hi_charset3: -.byte $90,$30,$f0,$f0,$f0,$70,$a0,$e0 -.byte $f0,$a0,$e0,$80,$f0,$80,$30,$f0 -.byte $80,$00,$00,$30,$70,$70,$e0,$f0 -.byte $f0,$f0,$50,$f0,$c0,$30,$30,$30 -.byte $f0,$b0,$f0,$50,$b0,$b0,$b0,$f0 -.byte $b0,$b0,$10,$10,$f0,$10,$f0,$b0 -.byte $50,$b0,$b0,$b0,$10,$d0,$30,$b0 -.byte $b0,$90,$f0,$f0,$70,$f0,$d0,$b0 -.byte $10,$d0,$30,$70,$90,$50,$10,$50 -.byte $30,$30,$d0,$50,$b0,$10,$50,$50 -.byte $50,$50,$50,$70,$b0,$50,$50,$50 -.byte $50,$50,$d0,$b0,$b0,$b0,$50,$00 -.byte $00,$10,$30,$70,$50,$30,$30,$10 -.byte $10,$b0,$d0,$30,$70,$50,$10,$50 -.byte $30,$50,$30,$b0,$b0,$50,$50,$10 -.byte $b0,$b0,$b0,$00,$b0,$b0,$50,$50 - -soft80_hi_charset4: -.byte $90,$30,$00,$f0,$f0,$70,$50,$e0 -.byte $50,$50,$e0,$80,$c0,$80,$30,$f0 -.byte $80,$00,$00,$30,$70,$70,$e0,$f0 -.byte $f0,$f0,$30,$30,$f0,$30,$f0,$c0 -.byte $f0,$f0,$f0,$00,$d0,$70,$40,$f0 -.byte $b0,$b0,$b0,$b0,$f0,$f0,$f0,$b0 -.byte $50,$b0,$70,$d0,$d0,$d0,$50,$b0 -.byte $50,$d0,$f0,$f0,$b0,$80,$b0,$b0 -.byte $70,$90,$50,$70,$50,$10,$b0,$50 -.byte $50,$b0,$d0,$30,$b0,$10,$50,$50 -.byte $50,$50,$70,$b0,$b0,$50,$50,$10 -.byte $b0,$50,$b0,$b0,$b0,$b0,$f0,$00 -.byte $00,$50,$50,$70,$50,$70,$70,$50 -.byte $50,$b0,$d0,$30,$70,$50,$10,$50 -.byte $70,$50,$30,$d0,$b0,$50,$50,$10 -.byte $b0,$b0,$b0,$00,$70,$b0,$50,$a0 - -soft80_hi_charset5: -.byte $f0,$30,$00,$f0,$f0,$70,$50,$e0 -.byte $50,$a0,$e0,$b0,$c0,$f0,$b0,$f0 -.byte $b0,$f0,$b0,$b0,$70,$70,$e0,$f0 -.byte $f0,$00,$30,$30,$f0,$f0,$f0,$c0 -.byte $f0,$f0,$f0,$50,$30,$50,$50,$f0 -.byte $b0,$b0,$50,$b0,$b0,$f0,$b0,$70 -.byte $50,$b0,$70,$50,$d0,$50,$50,$b0 -.byte $50,$50,$b0,$b0,$b0,$f0,$b0,$f0 -.byte $50,$50,$50,$70,$50,$70,$b0,$90 -.byte $50,$b0,$d0,$50,$b0,$50,$50,$50 -.byte $30,$90,$70,$d0,$b0,$50,$b0,$10 -.byte $50,$90,$70,$b0,$d0,$b0,$f0,$b0 -.byte $f0,$50,$50,$50,$50,$70,$70,$50 -.byte $50,$b0,$50,$50,$70,$50,$50,$50 -.byte $70,$b0,$50,$50,$b0,$50,$b0,$50 -.byte $50,$b0,$70,$b0,$70,$b0,$50,$a0 - -soft80_hi_charset6: -.byte $f0,$30,$00,$f0,$f0,$70,$a0,$e0 -.byte $a0,$50,$e0,$b0,$c0,$f0,$b0,$00 -.byte $b0,$f0,$b0,$b0,$70,$70,$e0,$f0 -.byte $f0,$00,$70,$30,$f0,$f0,$f0,$c0 -.byte $f0,$b0,$f0,$50,$b0,$50,$80,$f0 -.byte $d0,$70,$f0,$f0,$b0,$f0,$b0,$70 -.byte $b0,$10,$10,$b0,$d0,$b0,$b0,$b0 -.byte $b0,$b0,$f0,$b0,$d0,$f0,$70,$b0 -.byte $b0,$90,$30,$90,$90,$90,$b0,$d0 -.byte $50,$10,$d0,$50,$10,$50,$50,$b0 -.byte $70,$d0,$70,$30,$d0,$90,$b0,$50 -.byte $50,$d0,$10,$90,$d0,$30,$f0,$b0 -.byte $f0,$50,$30,$b0,$30,$10,$70,$b0 -.byte $50,$10,$b0,$50,$10,$50,$50,$b0 -.byte $70,$d0,$50,$b0,$b0,$b0,$b0,$50 -.byte $50,$b0,$10,$b0,$b0,$b0,$50,$50 - -soft80_hi_charset7: -.byte $f0,$30,$00,$f0,$00,$70,$a0,$e0 -.byte $a0,$a0,$e0,$b0,$c0,$f0,$b0,$00 -.byte $b0,$f0,$b0,$b0,$70,$70,$e0,$f0 -.byte $f0,$00,$f0,$30,$f0,$f0,$f0,$c0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$70,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$70,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$30 -.byte $f0,$f0,$30,$f0,$f0,$f0,$f0,$f0 -.byte $70,$d0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$30,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$f0,$f0,$f0,$f0,$f0 -.byte $f0,$f0,$f0,$b0,$b0,$b0,$f0,$50 - diff --git a/libsrc/c64/soft80_chline.s b/libsrc/c64/soft80_chline.s index de6ab7637..ac9d123d3 100644 --- a/libsrc/c64/soft80_chline.s +++ b/libsrc/c64/soft80_chline.s @@ -17,7 +17,7 @@ soft80_chline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #96 ; Horizontal line, screen code +L1: lda #96 ; Horizontal line, petscii code jsr soft80_cputdirect ; Direct output dec tmp1 bne L1 diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 199ac3584..fd2d7fd4d 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -8,6 +8,8 @@ .import soft80_kclrscr .import soft80_textcolor, soft80_bgcolor + .importzp ptr1, ptr2, ptr3 + .include "c64.inc" .include "soft80.inc" @@ -28,22 +30,36 @@ soft80_init: lda #$34 sta $01 - lda #>soft80_lo_charset0 - sta @hi1+2 - lda #>$d000 - sta @hi2+2 + lda #>soft80_charset + sta ptr1+1 + lda #<soft80_charset + sta ptr1 + lda #>soft80_lo_charset + sta ptr2+1 + lda #<soft80_lo_charset + sta ptr2 + lda #>soft80_hi_charset + sta ptr3+1 + lda #<soft80_hi_charset + sta ptr3 - ldy #8 + ldx #4 @l2: - ldx #0 + ldy #0 @l1: -@hi1: lda soft80_lo_charset0,x -@hi2: sta $d000,x - inx + lda (ptr1),y + sta (ptr2),y + asl a + asl a + asl a + asl a + sta (ptr3),y + iny bne @l1 - inc @hi1+2 - inc @hi2+2 - dey + inc ptr1+1 + inc ptr2+1 + inc ptr3+1 + dex bne @l2 pla @@ -68,7 +84,6 @@ soft80_shutdown: sta VIC_VIDEO_ADR rts -; FIXME: generate the charset at init time, and put it into RAM under I/O - +soft80_charset: .include "soft80_charset.s" diff --git a/libsrc/c64/soft80_cvline.s b/libsrc/c64/soft80_cvline.s index a24d17c79..847186a3b 100644 --- a/libsrc/c64/soft80_cvline.s +++ b/libsrc/c64/soft80_cvline.s @@ -17,7 +17,7 @@ soft80_cvline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #125 ; Vertical bar +L1: lda #125 ; Vertical bar, petscii code jsr soft80_putchar ; Write, no cursor advance jsr soft80_newline ; Advance cursor to next line dec tmp1 From 6cc654cca84b58671ab7ec0adeb8bdecaca5acfb Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 28 Sep 2015 15:10:57 +0200 Subject: [PATCH 241/351] added extra check for graphical chars --- libsrc/c64/soft80.inc | 24 +++++++++--------------- libsrc/c64/soft80_chline.s | 5 ++++- libsrc/c64/soft80_cputc.s | 19 +++++++++++++++---- libsrc/c64/soft80_cvline.s | 5 ++++- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc index d67011b4a..d534cac69 100644 --- a/libsrc/c64/soft80.inc +++ b/libsrc/c64/soft80.inc @@ -1,10 +1,8 @@ -; ram under i/o soft80_lo_charset = $d000 soft80_hi_charset = $d400 -soft80_vram = $d800 +soft80_vram = $d800 ; ram under i/o soft80_colram = $d800 ; color ram (used for temp. storage) -; ram under kernel soft80_bitmap = $e000 charsperline = 80 @@ -15,15 +13,11 @@ CH_HLINE = 96 CH_CROSS = 123 CH_VLINE = 125 CH_PI = 126 - -; FIXME: these are defined in cbm.h normally, the putchar stuff should accept -; the regular codes instead of the following ones: - -CH_LTEE = 171-160 -CH_URCORNER = 174-160 -CH_LLCORNER = 173-160 -CH_ULCORNER = 176-160 -CH_BTEE = 177-160 -CH_TTEE = 178-160 -CH_RTEE = 179-160 -CH_LRCORNER = 189-160 +CH_LTEE = 171 +CH_URCORNER = 174 +CH_LLCORNER = 173 +CH_ULCORNER = 176 +CH_BTEE = 177 +CH_TTEE = 178 +CH_RTEE = 179 +CH_LRCORNER = 189 diff --git a/libsrc/c64/soft80_chline.s b/libsrc/c64/soft80_chline.s index ac9d123d3..e15d0c483 100644 --- a/libsrc/c64/soft80_chline.s +++ b/libsrc/c64/soft80_chline.s @@ -7,6 +7,9 @@ .import popa, _gotoxy, soft80_cputdirect .importzp tmp1 + .include "c64.inc" + .include "soft80.inc" + soft80_chlinexy: pha ; Save the length jsr popa ; Get y @@ -17,7 +20,7 @@ soft80_chline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #96 ; Horizontal line, petscii code +L1: lda #CH_HLINE ; Horizontal line, petscii code jsr soft80_cputdirect ; Direct output dec tmp1 bne L1 diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index c81913476..d4c7e3050 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -40,28 +40,39 @@ soft80_plot: ldx CURS_Y ldy CURS_X clc - jmp soft80_kplot ; Set the new cursor + jmp soft80_kplot ; Set the new cursor L1: cmp #$0D ; LF? - beq soft80_newline ; Recalculate pointers + beq soft80_newline ; Recalculate pointers ; Printable char of some sort tay bpl L10 + ; extra check for petscii codes 160-191, these have been moved to + ; 0-31 in the charset + and #%11100000 + cmp #%10100000 + bne @sk + + tya + and #%00011111 + bpl L10 ; branch always +@sk: + tya clc adc #$20 and #$7F L10: soft80_cputdirect: - jsr soft80_putchar ; Write the character to the screen + jsr soft80_putchar ; Write the character to the screen ; Advance cursor position advance: - iny + iny ; contains CURS_X cpy #charsperline beq L3 diff --git a/libsrc/c64/soft80_cvline.s b/libsrc/c64/soft80_cvline.s index 847186a3b..eaa850118 100644 --- a/libsrc/c64/soft80_cvline.s +++ b/libsrc/c64/soft80_cvline.s @@ -7,6 +7,9 @@ .import popa, _gotoxy, soft80_putchar, soft80_newline .importzp tmp1 + .include "c64.inc" + .include "soft80.inc" + soft80_cvlinexy: pha ; Save the length jsr popa ; Get y @@ -17,7 +20,7 @@ soft80_cvline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #125 ; Vertical bar, petscii code +L1: lda #CH_VLINE ; Vertical bar, petscii code jsr soft80_putchar ; Write, no cursor advance jsr soft80_newline ; Advance cursor to next line dec tmp1 From d211eeaa4136dce489c036556d4bc43614cfb728 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 28 Sep 2015 15:29:14 +0200 Subject: [PATCH 242/351] fix conio test to work on vic20 screen --- testcode/lib/conio.c | 48 +++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index 752687f34..f1b21e7a5 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -3,6 +3,15 @@ #include <string.h> #include <stdlib.h> + +static char grid[5][5] = { + { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER }, + { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE }, + { CH_LTEE, CH_HLINE, CH_CROSS, CH_HLINE, CH_RTEE }, + { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE }, + { CH_LLCORNER, CH_HLINE, CH_BTEE, CH_HLINE, CH_LRCORNER }, +}; + void main(void) { int i, j, n; @@ -12,10 +21,10 @@ void main(void) screensize(&xsize, &ysize); cputs("cc65 conio test"); - tcol = textcolor(1); - cputsxy(0, 2, "colors:" ); - for (i = 3; i < 6; ++i) { - gotoxy(i,i); + cputsxy(0, 2, "Colors:" ); + tcol = textcolor(0); /* remember original textcolor */ + for (i = 0; i < 3; ++i) { + gotoxy(i,3 + i); for (j = 0; j < 16; ++j) { textcolor(j); cputc('X'); @@ -23,21 +32,30 @@ void main(void) } textcolor(tcol); - cprintf("\n\n\rscreensize is: %dx%d", xsize, ysize ); + cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize ); - chlinexy(0,10,xsize); - cvlinexy(0,10,3); - chlinexy(0,12,xsize); - cvlinexy(xsize-1,10,3); - cputcxy(0,10,CH_ULCORNER); - cputcxy(xsize-1,10,CH_URCORNER); - cputcxy(0,12,CH_LLCORNER); - cputcxy(xsize-1,12,CH_LRCORNER); + chlinexy(0,6,xsize); + cvlinexy(0,6,3); + chlinexy(0,8,xsize); + cvlinexy(xsize-1,6,3); + cputcxy(0,6,CH_ULCORNER); + cputcxy(xsize-1,6,CH_URCORNER); + cputcxy(0,8,CH_LLCORNER); + cputcxy(xsize-1,8,CH_LRCORNER); + + for (i = 0; i < 5; ++i) { + gotoxy(xsize - 5,i); + for (j = 0; j < 5; ++j) { + cputc(grid[i][j]); + } + } gotoxy(0,ysize - 2 - ((256 + xsize) / xsize)); + revers(1); for (i = 0; i < xsize; ++i) { cputc('0' + i % 10); } + revers(0); for (i = 0; i < 256; ++i) { if ((i != '\n') && (i != '\r')) { cputc(i); @@ -46,13 +64,15 @@ void main(void) while(wherex() > 0) { cputc('#'); } + revers(1); for (i = 0; i < xsize; ++i) { cputc('0' + i % 10); } + revers(0); for(;;) { - gotoxy(xsize - 10, 3); + gotoxy(8, 2); j = (n >> 5) & 1; revers(j); cputc(j ? 'R' : ' '); From 7486923c1786b6c64e8d0bad52217ed54c8eed3f Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 28 Sep 2015 15:57:16 +0200 Subject: [PATCH 243/351] dont use seperate file for charset data --- libsrc/c64/soft80_charset.s | 137 ------------------------------------ libsrc/c64/soft80_conio.s | 136 ++++++++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 138 deletions(-) delete mode 100644 libsrc/c64/soft80_charset.s diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s deleted file mode 100644 index 999d199f0..000000000 --- a/libsrc/c64/soft80_charset.s +++ /dev/null @@ -1,137 +0,0 @@ - -.byte $0f,$03,$0f,$00,$0f,$07,$05,$0e -.byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f -.byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 -.byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 -.byte $0f,$0b,$05,$05,$0b,$05,$0b,$0b -.byte $0d,$07,$0f,$0f,$0f,$0f,$0f,$0d -.byte $0b,$0b,$0b,$0b,$05,$01,$0b,$01 -.byte $0b,$0b,$0f,$0f,$0d,$0f,$07,$0b -.byte $0b,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$09,$07,$03,$0b,$0f -.byte $0f,$0b,$03,$0b,$03,$01,$01,$0b -.byte $05,$01,$09,$05,$07,$05,$05,$0b -.byte $03,$0b,$03,$0b,$01,$05,$05,$05 -.byte $05,$05,$01,$0b,$07,$0b,$0f,$0a - -.byte $0f,$03,$0f,$0f,$0f,$07,$05,$0e -.byte $0f,$0a,$0e,$0b,$0f,$0b,$0f,$0f -.byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 -.byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 -.byte $0f,$0b,$05,$05,$09,$05,$05,$0b -.byte $0b,$0b,$05,$0b,$0f,$0f,$0f,$0d -.byte $05,$0b,$05,$05,$05,$07,$05,$05 -.byte $05,$05,$0f,$0f,$0b,$0f,$0b,$05 -.byte $05,$0f,$07,$0f,$0d,$0f,$09,$0f -.byte $07,$0b,$0d,$07,$03,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0b,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0b,$07,$0b,$0b,$0b -.byte $0f,$0b,$05,$05,$05,$07,$07,$05 -.byte $05,$0b,$0d,$05,$07,$01,$01,$05 -.byte $05,$05,$05,$05,$0b,$05,$05,$05 -.byte $05,$05,$0d,$0b,$07,$0b,$0f,$0a - -.byte $0f,$03,$0f,$0f,$0f,$07,$0a,$0e -.byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f -.byte $0f,$0b,$0f,$0b,$07,$07,$0e,$0f -.byte $00,$0f,$0d,$0f,$0c,$0b,$03,$03 -.byte $0f,$0b,$05,$00,$07,$0d,$0b,$07 -.byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b -.byte $01,$03,$0d,$0d,$05,$03,$07,$0d -.byte $05,$05,$0b,$0b,$0b,$08,$0b,$0d -.byte $01,$0b,$07,$09,$0d,$0b,$0b,$09 -.byte $07,$0f,$0f,$07,$0b,$05,$03,$0b -.byte $03,$09,$03,$09,$01,$05,$05,$05 -.byte $05,$05,$01,$0b,$0b,$0b,$05,$0b -.byte $0f,$05,$05,$07,$05,$07,$07,$07 -.byte $05,$0b,$0d,$03,$07,$01,$01,$05 -.byte $05,$05,$05,$07,$0b,$05,$05,$05 -.byte $0b,$05,$0b,$0b,$0b,$0b,$0a,$05 - -.byte $09,$03,$0f,$0f,$0f,$07,$0a,$0e -.byte $0f,$0a,$0e,$08,$0f,$08,$03,$0f -.byte $08,$00,$00,$03,$07,$07,$0e,$0f -.byte $0f,$0f,$05,$0f,$0c,$03,$03,$03 -.byte $0f,$0b,$0f,$05,$0b,$0b,$0b,$0f -.byte $0b,$0b,$01,$01,$0f,$01,$0f,$0b -.byte $05,$0b,$0b,$0b,$01,$0d,$03,$0b -.byte $0b,$09,$0f,$0f,$07,$0f,$0d,$0b -.byte $01,$0d,$03,$07,$09,$05,$01,$05 -.byte $03,$03,$0d,$05,$0b,$01,$05,$05 -.byte $05,$05,$05,$07,$0b,$05,$05,$05 -.byte $05,$05,$0d,$0b,$0b,$0b,$05,$00 -.byte $00,$01,$03,$07,$05,$03,$03,$01 -.byte $01,$0b,$0d,$03,$07,$05,$01,$05 -.byte $03,$05,$03,$0b,$0b,$05,$05,$01 -.byte $0b,$0b,$0b,$00,$0b,$0b,$05,$05 - -.byte $09,$03,$00,$0f,$0f,$07,$05,$0e -.byte $05,$05,$0e,$08,$0c,$08,$03,$0f -.byte $08,$00,$00,$03,$07,$07,$0e,$0f -.byte $0f,$0f,$03,$03,$0f,$03,$0f,$0c -.byte $0f,$0f,$0f,$00,$0d,$07,$04,$0f -.byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b -.byte $05,$0b,$07,$0d,$0d,$0d,$05,$0b -.byte $05,$0d,$0f,$0f,$0b,$08,$0b,$0b -.byte $07,$09,$05,$07,$05,$01,$0b,$05 -.byte $05,$0b,$0d,$03,$0b,$01,$05,$05 -.byte $05,$05,$07,$0b,$0b,$05,$05,$01 -.byte $0b,$05,$0b,$0b,$0b,$0b,$0f,$00 -.byte $00,$05,$05,$07,$05,$07,$07,$05 -.byte $05,$0b,$0d,$03,$07,$05,$01,$05 -.byte $07,$05,$03,$0d,$0b,$05,$05,$01 -.byte $0b,$0b,$0b,$00,$07,$0b,$05,$0a - -.byte $0f,$03,$00,$0f,$0f,$07,$05,$0e -.byte $05,$0a,$0e,$0b,$0c,$0f,$0b,$0f -.byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f -.byte $0f,$00,$03,$03,$0f,$0f,$0f,$0c -.byte $0f,$0f,$0f,$05,$03,$05,$05,$0f -.byte $0b,$0b,$05,$0b,$0b,$0f,$0b,$07 -.byte $05,$0b,$07,$05,$0d,$05,$05,$0b -.byte $05,$05,$0b,$0b,$0b,$0f,$0b,$0f -.byte $05,$05,$05,$07,$05,$07,$0b,$09 -.byte $05,$0b,$0d,$05,$0b,$05,$05,$05 -.byte $03,$09,$07,$0d,$0b,$05,$0b,$01 -.byte $05,$09,$07,$0b,$0d,$0b,$0f,$0b -.byte $0f,$05,$05,$05,$05,$07,$07,$05 -.byte $05,$0b,$05,$05,$07,$05,$05,$05 -.byte $07,$0b,$05,$05,$0b,$05,$0b,$05 -.byte $05,$0b,$07,$0b,$07,$0b,$05,$0a - -.byte $0f,$03,$00,$0f,$0f,$07,$0a,$0e -.byte $0a,$05,$0e,$0b,$0c,$0f,$0b,$00 -.byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f -.byte $0f,$00,$07,$03,$0f,$0f,$0f,$0c -.byte $0f,$0b,$0f,$05,$0b,$05,$08,$0f -.byte $0d,$07,$0f,$0f,$0b,$0f,$0b,$07 -.byte $0b,$01,$01,$0b,$0d,$0b,$0b,$0b -.byte $0b,$0b,$0f,$0b,$0d,$0f,$07,$0b -.byte $0b,$09,$03,$09,$09,$09,$0b,$0d -.byte $05,$01,$0d,$05,$01,$05,$05,$0b -.byte $07,$0d,$07,$03,$0d,$09,$0b,$05 -.byte $05,$0d,$01,$09,$0d,$03,$0f,$0b -.byte $0f,$05,$03,$0b,$03,$01,$07,$0b -.byte $05,$01,$0b,$05,$01,$05,$05,$0b -.byte $07,$0d,$05,$0b,$0b,$0b,$0b,$05 -.byte $05,$0b,$01,$0b,$0b,$0b,$05,$05 - -.byte $0f,$03,$00,$0f,$00,$07,$0a,$0e -.byte $0a,$0a,$0e,$0b,$0c,$0f,$0b,$00 -.byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f -.byte $0f,$00,$0f,$03,$0f,$0f,$0f,$0c -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$07,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$07,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$03 -.byte $0f,$0f,$03,$0f,$0f,$0f,$0f,$0f -.byte $07,$0d,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$03,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f -.byte $0f,$0f,$0f,$0b,$0b,$0b,$0f,$05 - diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index fd2d7fd4d..84e5157c8 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -84,6 +84,140 @@ soft80_shutdown: sta VIC_VIDEO_ADR rts + .rodata soft80_charset: - .include "soft80_charset.s" + .byte $0f,$03,$0f,$00,$0f,$07,$05,$0e + .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f + .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 + .byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 + .byte $0f,$0b,$05,$05,$0b,$05,$0b,$0b + .byte $0d,$07,$0f,$0f,$0f,$0f,$0f,$0d + .byte $0b,$0b,$0b,$0b,$05,$01,$0b,$01 + .byte $0b,$0b,$0f,$0f,$0d,$0f,$07,$0b + .byte $0b,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$09,$07,$03,$0b,$0f + .byte $0f,$0b,$03,$0b,$03,$01,$01,$0b + .byte $05,$01,$09,$05,$07,$05,$05,$0b + .byte $03,$0b,$03,$0b,$01,$05,$05,$05 + .byte $05,$05,$01,$0b,$07,$0b,$0f,$0a + .byte $0f,$03,$0f,$0f,$0f,$07,$05,$0e + .byte $0f,$0a,$0e,$0b,$0f,$0b,$0f,$0f + .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 + .byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 + .byte $0f,$0b,$05,$05,$09,$05,$05,$0b + .byte $0b,$0b,$05,$0b,$0f,$0f,$0f,$0d + .byte $05,$0b,$05,$05,$05,$07,$05,$05 + .byte $05,$05,$0f,$0f,$0b,$0f,$0b,$05 + .byte $05,$0f,$07,$0f,$0d,$0f,$09,$0f + .byte $07,$0b,$0d,$07,$03,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0b,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0b,$07,$0b,$0b,$0b + .byte $0f,$0b,$05,$05,$05,$07,$07,$05 + .byte $05,$0b,$0d,$05,$07,$01,$01,$05 + .byte $05,$05,$05,$05,$0b,$05,$05,$05 + .byte $05,$05,$0d,$0b,$07,$0b,$0f,$0a + + .byte $0f,$03,$0f,$0f,$0f,$07,$0a,$0e + .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f + .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$0f + .byte $00,$0f,$0d,$0f,$0c,$0b,$03,$03 + .byte $0f,$0b,$05,$00,$07,$0d,$0b,$07 + .byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b + .byte $01,$03,$0d,$0d,$05,$03,$07,$0d + .byte $05,$05,$0b,$0b,$0b,$08,$0b,$0d + .byte $01,$0b,$07,$09,$0d,$0b,$0b,$09 + .byte $07,$0f,$0f,$07,$0b,$05,$03,$0b + .byte $03,$09,$03,$09,$01,$05,$05,$05 + .byte $05,$05,$01,$0b,$0b,$0b,$05,$0b + .byte $0f,$05,$05,$07,$05,$07,$07,$07 + .byte $05,$0b,$0d,$03,$07,$01,$01,$05 + .byte $05,$05,$05,$07,$0b,$05,$05,$05 + .byte $0b,$05,$0b,$0b,$0b,$0b,$0a,$05 + + .byte $09,$03,$0f,$0f,$0f,$07,$0a,$0e + .byte $0f,$0a,$0e,$08,$0f,$08,$03,$0f + .byte $08,$00,$00,$03,$07,$07,$0e,$0f + .byte $0f,$0f,$05,$0f,$0c,$03,$03,$03 + .byte $0f,$0b,$0f,$05,$0b,$0b,$0b,$0f + .byte $0b,$0b,$01,$01,$0f,$01,$0f,$0b + .byte $05,$0b,$0b,$0b,$01,$0d,$03,$0b + .byte $0b,$09,$0f,$0f,$07,$0f,$0d,$0b + .byte $01,$0d,$03,$07,$09,$05,$01,$05 + .byte $03,$03,$0d,$05,$0b,$01,$05,$05 + .byte $05,$05,$05,$07,$0b,$05,$05,$05 + .byte $05,$05,$0d,$0b,$0b,$0b,$05,$00 + .byte $00,$01,$03,$07,$05,$03,$03,$01 + .byte $01,$0b,$0d,$03,$07,$05,$01,$05 + .byte $03,$05,$03,$0b,$0b,$05,$05,$01 + .byte $0b,$0b,$0b,$00,$0b,$0b,$05,$05 + + .byte $09,$03,$00,$0f,$0f,$07,$05,$0e + .byte $05,$05,$0e,$08,$0c,$08,$03,$0f + .byte $08,$00,$00,$03,$07,$07,$0e,$0f + .byte $0f,$0f,$03,$03,$0f,$03,$0f,$0c + .byte $0f,$0f,$0f,$00,$0d,$07,$04,$0f + .byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b + .byte $05,$0b,$07,$0d,$0d,$0d,$05,$0b + .byte $05,$0d,$0f,$0f,$0b,$08,$0b,$0b + .byte $07,$09,$05,$07,$05,$01,$0b,$05 + .byte $05,$0b,$0d,$03,$0b,$01,$05,$05 + .byte $05,$05,$07,$0b,$0b,$05,$05,$01 + .byte $0b,$05,$0b,$0b,$0b,$0b,$0f,$00 + .byte $00,$05,$05,$07,$05,$07,$07,$05 + .byte $05,$0b,$0d,$03,$07,$05,$01,$05 + .byte $07,$05,$03,$0d,$0b,$05,$05,$01 + .byte $0b,$0b,$0b,$00,$07,$0b,$05,$0a + + .byte $0f,$03,$00,$0f,$0f,$07,$05,$0e + .byte $05,$0a,$0e,$0b,$0c,$0f,$0b,$0f + .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f + .byte $0f,$00,$03,$03,$0f,$0f,$0f,$0c + .byte $0f,$0f,$0f,$05,$03,$05,$05,$0f + .byte $0b,$0b,$05,$0b,$0b,$0f,$0b,$07 + .byte $05,$0b,$07,$05,$0d,$05,$05,$0b + .byte $05,$05,$0b,$0b,$0b,$0f,$0b,$0f + .byte $05,$05,$05,$07,$05,$07,$0b,$09 + .byte $05,$0b,$0d,$05,$0b,$05,$05,$05 + .byte $03,$09,$07,$0d,$0b,$05,$0b,$01 + .byte $05,$09,$07,$0b,$0d,$0b,$0f,$0b + .byte $0f,$05,$05,$05,$05,$07,$07,$05 + .byte $05,$0b,$05,$05,$07,$05,$05,$05 + .byte $07,$0b,$05,$05,$0b,$05,$0b,$05 + .byte $05,$0b,$07,$0b,$07,$0b,$05,$0a + + .byte $0f,$03,$00,$0f,$0f,$07,$0a,$0e + .byte $0a,$05,$0e,$0b,$0c,$0f,$0b,$00 + .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f + .byte $0f,$00,$07,$03,$0f,$0f,$0f,$0c + .byte $0f,$0b,$0f,$05,$0b,$05,$08,$0f + .byte $0d,$07,$0f,$0f,$0b,$0f,$0b,$07 + .byte $0b,$01,$01,$0b,$0d,$0b,$0b,$0b + .byte $0b,$0b,$0f,$0b,$0d,$0f,$07,$0b + .byte $0b,$09,$03,$09,$09,$09,$0b,$0d + .byte $05,$01,$0d,$05,$01,$05,$05,$0b + .byte $07,$0d,$07,$03,$0d,$09,$0b,$05 + .byte $05,$0d,$01,$09,$0d,$03,$0f,$0b + .byte $0f,$05,$03,$0b,$03,$01,$07,$0b + .byte $05,$01,$0b,$05,$01,$05,$05,$0b + .byte $07,$0d,$05,$0b,$0b,$0b,$0b,$05 + .byte $05,$0b,$01,$0b,$0b,$0b,$05,$05 + + .byte $0f,$03,$00,$0f,$00,$07,$0a,$0e + .byte $0a,$0a,$0e,$0b,$0c,$0f,$0b,$00 + .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f + .byte $0f,$00,$0f,$03,$0f,$0f,$0f,$0c + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$07,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$07,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$03 + .byte $0f,$0f,$03,$0f,$0f,$0f,$0f,$0f + .byte $07,$0d,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$03,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0b,$0b,$0b,$0f,$05 From 841d764a83a8d517654ff6a26d3b0eb5ee2dc369 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 28 Sep 2015 16:10:11 +0200 Subject: [PATCH 244/351] some cleanup, checked usage of __bgcolor and __textcolor --- libsrc/c64/soft80_cgetc.s | 2 +- libsrc/c64/soft80_color.s | 3 +-- libsrc/c64/soft80_cputc.s | 2 +- libsrc/c64/soft80_kclrscr.s | 2 +- libsrc/c64/soft80_kplot.s | 3 ++- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 12b2071a2..a8c52c1a2 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -3,7 +3,7 @@ ; .export soft80_cgetc - .import cursor ; FIX/CHECK + .import cursor .import soft80_putcolor .include "c64.inc" diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index c176eca7f..8475cc05c 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -5,7 +5,7 @@ ; .export soft80_textcolor, soft80_bgcolor, soft80_bordercolor - .export __textcolor,__bgcolor ; CHECK/FIX + .export __textcolor, __bgcolor .importzp tmp1,tmp2 @@ -89,7 +89,6 @@ soft80_bordercolor: txa rts - ; FIXME: shouldnt they be in zeropage? .bss __textcolor: .res 1 diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index d4c7e3050..590e16740 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -11,7 +11,7 @@ .import popa, _gotoxy .import xsize .import soft80_kplot - .import __bgcolor ; FIX/CHECK + .import __bgcolor .importzp tmp4,tmp3 diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index e801c9398..ff1a14a07 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -1,7 +1,7 @@ .export soft80_kclrscr .import soft80_kplot - .import __bgcolor ; FIX/CHECK + .import __bgcolor .include "c64.inc" .include "soft80.inc" diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index a813fd679..884404b5f 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -18,7 +18,8 @@ soft80_kplot: ; calc pointer to vram tya - lsr a + lsr a ; NOTE: we can save 2 cycles here at the expense of + ; making the tables twice as big (+50 bytes) clc adc _vramlo,x sta CRAM_PTR From 4949836d1692a88c1ebbb71a1b6c7936f9c28e63 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 28 Sep 2015 17:12:20 +0200 Subject: [PATCH 245/351] fixed kplot --- libsrc/c64/soft80_kplot.s | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index 884404b5f..eaaed7596 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -7,6 +7,9 @@ soft80_kplot: bcs @getpos + stx CURS_Y + sty CURS_X + ; calc pointer to bitmap lda _bitmaplo,x clc From f39337a6ec6483f16ed109b7deb0030269ec403c Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 28 Sep 2015 17:12:33 +0200 Subject: [PATCH 246/351] added input test --- testcode/lib/conio.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index f1b21e7a5..f998abeae 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -3,7 +3,6 @@ #include <string.h> #include <stdlib.h> - static char grid[5][5] = { { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER }, { CH_VLINE, ' ', CH_VLINE, ' ', CH_VLINE }, @@ -15,11 +14,11 @@ static char grid[5][5] = { void main(void) { int i, j, n; - unsigned char xsize, ysize, tcol; + unsigned char xsize, ysize, tcol, inpos = 0; clrscr(); screensize(&xsize, &ysize); - cputs("cc65 conio test"); + cputs("cc65 conio test\n\rInput:[ ]"); cputsxy(0, 2, "Colors:" ); tcol = textcolor(0); /* remember original textcolor */ @@ -70,15 +69,21 @@ void main(void) } revers(0); + cursor(1); for(;;) { gotoxy(8, 2); - j = (n >> 5) & 1; + j = n & 1; revers(j); cputc(j ? 'R' : ' '); + revers(j ^ 1); cputs(" revers"); revers(0); + gotoxy(7 + inpos,1); + cputc(cgetc()); + inpos = (inpos + 1) & 7; + ++n; } From 6217f8fa3ae57bfcb29abb6ea2b4d118384d3e06 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 28 Sep 2015 11:27:39 -0400 Subject: [PATCH 247/351] Made the Commodore version of exec() work in programs that are so big that they load into all of BASIC RAM. The function won't cause an "out of memory" error. --- asminc/c64.inc | 2 ++ asminc/pet.inc | 1 + asminc/plus4.inc | 2 ++ asminc/vic20.inc | 2 ++ libsrc/cbm/exec.c | 69 ++++++++++++++++++++++++++++--------------- libsrc/cbm/execvars.s | 14 ++++++--- 6 files changed, 63 insertions(+), 27 deletions(-) diff --git a/asminc/c64.inc b/asminc/c64.inc index f450fcc0b..5815bebf9 100644 --- a/asminc/c64.inc +++ b/asminc/c64.inc @@ -6,6 +6,8 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +VARTAB := $2D ; Pointer to start of BASIC variables +MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $7A ; Pointer into BASIC source code TIME := $A0 ; 60 HZ clock FNAM_LEN := $B7 ; Length of filename diff --git a/asminc/pet.inc b/asminc/pet.inc index 1ebf391f9..a745a89c8 100644 --- a/asminc/pet.inc +++ b/asminc/pet.inc @@ -6,6 +6,7 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +VARTAB := $2A ; Pointer to start of BASIC variables MEMSIZE := $34 ; Size of memory installed TXTPTR := $77 ; Pointer into BASIC source code TIME := $8D ; 60HZ clock diff --git a/asminc/plus4.inc b/asminc/plus4.inc index 17e250508..69b2298a3 100644 --- a/asminc/plus4.inc +++ b/asminc/plus4.inc @@ -7,6 +7,8 @@ ; Zero page, Commodore stuff TMPPTR := $22 ; Temporary ptr used by BASIC +VARTAB := $2D ; Pointer to start of BASIC variables +MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $3B ; Pointer into BASIC source code TIME := $A3 ; 60HZ clock FNAM_LEN := $AB ; Length of filename diff --git a/asminc/vic20.inc b/asminc/vic20.inc index c42db4258..12424dc11 100644 --- a/asminc/vic20.inc +++ b/asminc/vic20.inc @@ -6,6 +6,8 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +VARTAB := $2D ; Pointer to start of BASIC variables +MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $7A ; Pointer into BASIC source code TIME := $A0 ; 60HZ clock FNAM_LEN := $B7 ; Length of filename diff --git a/libsrc/cbm/exec.c b/libsrc/cbm/exec.c index 36c3afe00..b9c1bdc96 100644 --- a/libsrc/cbm/exec.c +++ b/libsrc/cbm/exec.c @@ -1,7 +1,7 @@ /* ** Program-chaining function for Commodore platforms. ** -** 2013-09-04, Greg King +** 2015-09-27, Greg King ** ** This function exploits the program-chaining feature in CBM BASIC's ROM. ** @@ -32,42 +32,46 @@ /* The struct below is a line of BASIC code. It sits in the LOWCODE segment ** to make sure that it won't be hidden by a ROM when BASIC is re-enabled. ** The line is: -** 0 LOAD""+"" ,01 +** 0 CLR:LOAD""+"" ,01 ** After this function has written into the line, it might look like this: -** 0 LOAD""+"program name" ,08 +** 0 CLR:LOAD""+"program name" ,08 ** ** When BASIC's LOAD command asks the Kernal to load a file, it gives the ** Kernal a pointer to a file-name string. CC65's CBM programs use that ** pointer to give a copy of the program's name to main()'s argv[0] parameter. -** But, when BASIC uses a string literal that's in a program, it points +** But, when BASIC uses a string literal that is in a program, it points ** directly to that literal -- in the models that don't use banked RAM ** (Pet/CBM, VIC-20, and 64). The literal is overwritten by the next program -** that's loaded. So, argv[0] would point to machine code. String operations +** that is loaded. So, argv[0] would point to machine code. String operations ** create a new result string -- even when that operation changes nothing. The ** result is put in the string space at the top of BASIC's memory. So, the ""+ ** in this BASIC line guarantees that argv[0] will get a name from a safe place. */ #pragma data-name(push, "LOWCODE") static struct line { - const char end_of_line; - const struct line *const next; + const char end_of_line; /* fake previous line */ + const struct line* const next; const unsigned line_num; - const char load_token, quotes[2], add_token, quote; + const char CLR_token, colon, LOAD_token, quotes[2], add_token, quote; char name[21]; const char comma; char unit[3]; } basic = { - '\0', &basic + 1, /* high byte of link must be non-zero */ - 0, 0x93, "\"\"", 0xaa, '\"', - "\" ", /* format: "123:1234567890123456\"" */ + '\0', &basic + 1, /* high byte of link must be non-zero */ + 0, 0x9C, ':', 0x93, "\"\"", 0xAA, '\"', + "\" ", /* format: "123:1234567890123456\"" */ ',', "01" }; #pragma data-name(pop) /* These values are platform-specific. */ -extern const struct line *txtptr; +extern const void* vartab; /* points to BASIC program variables */ +#pragma zpsym("vartab") +extern const void* memsize; /* points to top of BASIC RAM */ +#pragma zpsym("memsize") +extern const struct line* txtptr; /* points to BASIC code */ #pragma zpsym("txtptr") -extern char basbuf[]; /* BASIC's input buffer */ +extern char basbuf[]; /* BASIC's input buffer */ extern void basbuf_len[]; #pragma zpsym("basbuf_len") @@ -75,43 +79,62 @@ extern void basbuf_len[]; int __fastcall__ exec (const char* progname, const char* cmdline) { static int fd; - static unsigned char dv, n = 0; + static unsigned char dv, n; /* Exclude devices that can't load files. */ + /* (Use hand optimization, to make smaller code.) */ dv = getcurrentdevice (); - if (dv < 8 && dv != 1 || dv > 30) { + if (dv < 8 && __AX__ != 1 || __AX__ > 30) { return _mappederrno (9); /* illegal device number */ } utoa (dv, basic.unit, 10); - /* Don't try to run a program that can't be found. */ - fd = open (progname, O_RDONLY); - if (fd < 0) { - return fd; + /* Tape files can be openned only once; skip this test for the Datasette. */ + if (dv != 1) { + /* Don't try to run a program that can't be found. */ + fd = open (progname, O_RDONLY); + if (fd < 0) { + return -1; + } + close (fd); } - close (fd); + n = 0; do { if ((basic.name[n] = progname[n]) == '\0') { break; } - } while (++n < 20); /* truncate long names */ + } while (++n < 20); /* truncate long names */ basic.name[n] = '\"'; +/* This next part isn't needed by machines that put +** BASIC source and variables in different RAM banks. +*/ +#if !defined(__CBM510__) && !defined(__CBM610__) && !defined(__C128__) + /* cc65 program loads might extend beyond the end of the RAM that is allowed + ** for BASIC. Then, the LOAD statement would complain that it is "out of + ** memory". Some pointers that say where to put BASIC program variables + ** must be changed, so that we do not get that error. One pointer is + ** changed here; a BASIC CLR statement changes the others. + */ + vartab = (char*)memsize - 256; +#endif + /* Build the next program's argument list. */ - basbuf[0] = 0x8f; /* REM token */ + basbuf[0] = 0x8F; /* REM token */ basbuf[1] = '\0'; if (cmdline != NULL) { strncat (basbuf, cmdline, (size_t)basbuf_len - 2); } + /* Tell the ROM where to find that BASIC program. */ #if defined(__CBM510__) || defined(__CBM610__) pokewsys ((unsigned)&txtptr, (unsigned)&basic); #else txtptr = &basic; #endif - /* (The return code, in ST, will be destroyed by LOAD. + /* (The return code, in ST [status], will be destroyed by LOAD. ** So, don't bother to set it here.) */ exit (__AX__); diff --git a/libsrc/cbm/execvars.s b/libsrc/cbm/execvars.s index 02eabc12e..68f8a5d64 100644 --- a/libsrc/cbm/execvars.s +++ b/libsrc/cbm/execvars.s @@ -20,9 +20,15 @@ .include "vic20.inc" .endif - .export _txtptr:zp, _basbuf, _basbuf_len:zp +; exec() is written in C. +; Provide the spellings that the C compiler wants to use. -_txtptr := TXTPTR +.ifdef VARTAB +.exportzp _vartab := VARTAB +.exportzp _memsize := MEMSIZE +.endif -_basbuf := BASIC_BUF -_basbuf_len = BASIC_BUF_LEN +.exportzp _txtptr := TXTPTR + +.export _basbuf := BASIC_BUF +.exportzp _basbuf_len = BASIC_BUF_LEN From 5ea842b88b7e799826f33ec9b8c80d4a0091bebe Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 1 Oct 2015 15:03:11 +0200 Subject: [PATCH 248/351] SCREEN->screensize --- libsrc/c64/extra/soft80.s | 4 ++-- libsrc/c64/{soft80_kscreen.s => soft80_scrsize.s} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename libsrc/c64/{soft80_kscreen.s => soft80_scrsize.s} (64%) diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index baf61f635..e6b373b64 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -48,8 +48,8 @@ .export PLOT := soft80_kplot ; soft80_kscreen.s - .import soft80_kscreen - .export SCREEN := soft80_kscreen + .import soft80_screensize + .export screensize := soft80_screensize ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/libsrc/c64/soft80_kscreen.s b/libsrc/c64/soft80_scrsize.s similarity index 64% rename from libsrc/c64/soft80_kscreen.s rename to libsrc/c64/soft80_scrsize.s index 22c7b6788..caaeb4791 100644 --- a/libsrc/c64/soft80_kscreen.s +++ b/libsrc/c64/soft80_scrsize.s @@ -1,9 +1,9 @@ - .export soft80_kscreen + .export soft80_screensize .include "soft80.inc" -soft80_kscreen: +soft80_screensize: ldy #screenrows ldx #charsperline rts From 23473641f474e33f2062b0aa4c93b66b8187ab25 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 1 Oct 2015 17:16:02 +0200 Subject: [PATCH 249/351] fix clrscr so it doesnt wipe sprite pointers --- libsrc/c64/soft80_kclrscr.s | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index ff1a14a07..c2f09f76e 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -12,9 +12,10 @@ soft80_kclrscr: ldx #$00 lp1: - .repeat $20,page + .repeat $1f,page sta soft80_bitmap+(page*$100),x .endrepeat + sta soft80_bitmap+$1e40,x inx bne lp1 @@ -29,9 +30,10 @@ lp1: ;ldx #$00 lp2: - .repeat $4,page - sta soft80_vram+(page*$100),x - .endrepeat + sta soft80_vram,x + sta soft80_vram+$100,x + sta soft80_vram+$200,x + sta soft80_vram+$2e8,x inx bne lp2 @@ -40,9 +42,10 @@ lp2: lda __bgcolor ;ldx #$00 lp3: - .repeat $4,page - sta soft80_colram+(page*$100),x - .endrepeat + sta soft80_colram,x + sta soft80_colram+$100,x + sta soft80_colram+$200,x + sta soft80_colram+$2e8,x inx bne lp3 From 074e10d28877647862d2dc94c2a8ce93e07585a1 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 5 Oct 2015 05:47:43 -0400 Subject: [PATCH 250/351] Adapted, to the c64 target, the INIT-segment overlay scheme from the apple2 targets. When a program starts running, INIT is moved from one place to another place. Then, INIT's code is executed; and, the first place is re-used for variables. After the INIT code has finished, the second place can be re-used by the heap and the C stack. That means that initiation code and data won't waste any RAM space after they stop being needed. --- asminc/c64.inc | 2 +- cfg/c64-overlay.cfg | 112 +++++++++++++++++++++------------------ cfg/c64.cfg | 35 ++++++------ libsrc/c64/crt0.s | 101 +++++++++++++++++++++++------------ libsrc/common/moveinit.s | 54 +++++++++++++++++++ 5 files changed, 200 insertions(+), 104 deletions(-) create mode 100644 libsrc/common/moveinit.s diff --git a/asminc/c64.inc b/asminc/c64.inc index 5815bebf9..ababb1ea0 100644 --- a/asminc/c64.inc +++ b/asminc/c64.inc @@ -24,6 +24,7 @@ SCREEN_PTR := $D1 ; Pointer to current char in text screen CURS_X := $D3 ; Cursor column CURS_Y := $D6 ; Cursor row CRAM_PTR := $F3 ; Pointer to current char in color RAM +FREKZP := $FB ; Five unused bytes BASIC_BUF := $200 ; Location of command-line BASIC_BUF_LEN = 89 ; Maximum length of command-line @@ -212,4 +213,3 @@ CASSMOT = $20 ; Cassette motor on TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF - diff --git a/cfg/c64-overlay.cfg b/cfg/c64-overlay.cfg index 2f7693e6e..58612e18e 100644 --- a/cfg/c64-overlay.cfg +++ b/cfg/c64-overlay.cfg @@ -1,64 +1,70 @@ +FEATURES { + STARTADDRESS: default = $0801; +} SYMBOLS { __LOADADDR__: type = import; __EXEHDR__: type = import; __OVERLAYADDR__: type = import; - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay + __HIMEM__: type = weak, value = $D000; + __HIMEM2__: type = export, value = __HIMEM__ - 2; } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; - LOADADDR: file = %O, start = $07FF, size = $0002; - HEADER: file = %O, start = $0801, size = $000C; - RAM: file = %O, define = yes, start = $080D, size = $C7F3 - __OVERLAYSIZE__ - __STACKSIZE__; - OVL1ADDR: file = "%O.1", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL1: file = "%O.1", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL2ADDR: file = "%O.2", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL2: file = "%O.2", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL3ADDR: file = "%O.3", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL3: file = "%O.3", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL4ADDR: file = "%O.4", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL4: file = "%O.4", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL5ADDR: file = "%O.5", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL5: file = "%O.5", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL6ADDR: file = "%O.6", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL6: file = "%O.6", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL7ADDR: file = "%O.7", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL7: file = "%O.7", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL8ADDR: file = "%O.8", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL8: file = "%O.8", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL9ADDR: file = "%O.9", start = $CFFE - __OVERLAYSIZE__, size = $0002; - OVL9: file = "%O.9", start = $D000 - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $000D; + RAM: file = %O, start = __HEADER_LAST__, size = __HIMEM__ - __OVERLAYSIZE__ - __STACKSIZE__ - __HEADER_LAST__; + MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; + OVL1ADDR: file = "%O.1", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL1: file = "%O.1", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL2ADDR: file = "%O.2", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL2: file = "%O.2", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL3ADDR: file = "%O.3", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL3: file = "%O.3", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL4ADDR: file = "%O.4", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL4: file = "%O.4", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL5ADDR: file = "%O.5", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL5: file = "%O.5", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL6ADDR: file = "%O.6", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL6: file = "%O.6", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL7ADDR: file = "%O.7", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL7: file = "%O.7", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL8ADDR: file = "%O.8", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL8: file = "%O.8", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + OVL9ADDR: file = "%O.9", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; + OVL9: file = "%O.9", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; } SEGMENTS { - LOADADDR: load = LOADADDR, type = ro; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro; - LOWCODE: load = RAM, type = ro, optional = yes; - INIT: load = RAM, type = ro, define = yes, optional = yes; - CODE: load = RAM, type = ro; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; - OVL1ADDR: load = OVL1ADDR, type = ro; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVL2ADDR: load = OVL2ADDR, type = ro; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVL3ADDR: load = OVL3ADDR, type = ro; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVL4ADDR: load = OVL4ADDR, type = ro; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVL5ADDR: load = OVL5ADDR, type = ro; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVL6ADDR: load = OVL6ADDR, type = ro; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVL7ADDR: load = OVL7ADDR, type = ro; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVL8ADDR: load = OVL8ADDR, type = ro; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVL9ADDR: load = OVL9ADDR, type = ro; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = RAM, type = ro; + LOWCODE: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + ZPSAVE: load = RAM, type = bss, define = yes; + BSS: load = RAM, type = bss, define = yes; + INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; + OVL1ADDR: load = OVL1ADDR, type = ro; + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVL2ADDR: load = OVL2ADDR, type = ro; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVL3ADDR: load = OVL3ADDR, type = ro; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVL4ADDR: load = OVL4ADDR, type = ro; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVL5ADDR: load = OVL5ADDR, type = ro; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVL6ADDR: load = OVL6ADDR, type = ro; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVL7ADDR: load = OVL7ADDR, type = ro; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVL8ADDR: load = OVL8ADDR, type = ro; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVL9ADDR: load = OVL9ADDR, type = ro; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/c64.cfg b/cfg/c64.cfg index 5d8befd02..861e19faf 100644 --- a/cfg/c64.cfg +++ b/cfg/c64.cfg @@ -1,26 +1,31 @@ +FEATURES { + STARTADDRESS: default = $0801; +} SYMBOLS { __LOADADDR__: type = import; __EXEHDR__: type = import; __STACKSIZE__: type = weak, value = $0800; # 2k stack + __HIMEM__: type = weak, value = $D000; } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; - LOADADDR: file = %O, start = $07FF, size = $0002; - HEADER: file = %O, start = $0801, size = $000C; - RAM: file = %O, define = yes, start = $080D, size = $C7F3 - __STACKSIZE__; + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $000D; + RAM: file = %O, start = __HEADER_LAST__, size = __HIMEM__ - __STACKSIZE__ - __HEADER_LAST__; + MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; } SEGMENTS { - LOADADDR: load = LOADADDR, type = ro; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro; - LOWCODE: load = RAM, type = ro, optional = yes; - INIT: load = RAM, type = ro, define = yes, optional = yes; - CODE: load = RAM, type = ro; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; - BSS: load = RAM, type = bss, define = yes; - ZEROPAGE: load = ZP, type = zp; + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = RAM, type = ro; + LOWCODE: load = RAM, type = ro, optional = yes; + CODE: load = RAM, type = ro; + RODATA: load = RAM, type = ro; + DATA: load = RAM, type = rw; + ZPSAVE: load = RAM, type = bss, define = yes; + BSS: load = RAM, type = bss, define = yes; + INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 24fe4376b..5a69f1584 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -3,13 +3,13 @@ ; .export _exit + .exportzp init_load_, init_run_ .export __STARTUP__ : absolute = 1 ; Mark as startup + .import initlib, donelib - .import zerobss - .import callmain + .import move_init, zerobss, callmain .import RESTOR, BSOUT, CLRCH - .import __RAM_START__, __RAM_SIZE__ ; Linker generated - .import __STACKSIZE__ ; Linker generated + .import __HIMEM__ ; from configure file .importzp ST .include "zeropage.inc" @@ -19,18 +19,17 @@ ; ------------------------------------------------------------------------ ; Startup code +; Two zero-page pointers are needed before any zero-page stuff is saved. +; Choose locations that are not used by anything. + +init_load_ := FREKZP +init_run_ := FREKZP+2 + + .segment "STARTUP" Start: -; Save the zero-page locations that we need. - - ldx #zpspace-1 -L1: lda sp,x - sta zpsave,x - dex - bpl L1 - ; Switch to the second charset. lda #14 @@ -39,35 +38,30 @@ L1: lda sp,x ; Switch off the BASIC ROM. lda $01 - pha ; Remember the value + sta mmusave ; Save the memory configuration and #$F8 ora #$06 ; Enable Kernal+I/O, disable BASIC sta $01 -; Clear the BSS data. - - jsr zerobss - -; Save some system settings; and, set up the stack. - - pla - sta mmusave ; Save the memory configuration - tsx stx spsave ; Save the system stack ptr - lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) - sta sp - lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) - sta sp+1 ; Set argument stack ptr +; Allow some re-entrancy by skipping the next task if it already was done. +; This often can let us rerun the program without reloading it. -; Call the module constructors. + ldx moveinit + beq L0 - jsr initlib +; Move the INIT segment from where it was loaded (over ZPSAVE and BSS) +; into where it must be run (in the heap). -; Push the command-line arguments; and, call main(). + jsr move_init + dec moveinit ; set to false - jsr callmain +; Save space by putting the rest of the start-up code in the INIT segment, +; which can be re-used by the heap. + +L0: jsr initstart ; Back from main() [this is also the exit() entry]. Run the module destructors. @@ -98,14 +92,51 @@ L2: lda zpsave,x rts + +; ------------------------------------------------------------------------ + +.segment "INIT" + +initstart: + +; Save the zero-page locations that we need. + + ldx #zpspace-1 +L1: lda sp,x + sta zpsave,x + dex + bpl L1 + +; Clear the BSS data. + + jsr zerobss + +; Set up the stack. + + lda #<__HIMEM__ + ldx #>__HIMEM__ + sta sp + stx sp+1 ; Set argument stack ptr + +; Call the module constructors. + + jsr initlib + +; Push the command-line arguments; and, call main(). + + jmp callmain + + ; ------------------------------------------------------------------------ ; Data +.data + +mmusave:.res 1 +spsave: .res 1 +moveinit: + .byte 1 + .segment "ZPSAVE" zpsave: .res zpspace - -.bss - -spsave: .res 1 -mmusave:.res 1 diff --git a/libsrc/common/moveinit.s b/libsrc/common/moveinit.s new file mode 100644 index 000000000..e9cd5fb64 --- /dev/null +++ b/libsrc/common/moveinit.s @@ -0,0 +1,54 @@ +; +; 2015-10-04, Greg King +; + + .export move_init + + .import __INIT_LOAD__, __INIT_RUN__, __INIT_SIZE__ ; Linker-generated + .importzp init_load_, init_run_ + + .macpack cpu + .macpack generic + + +; Move the INIT segment from where it was loaded (over the bss segments) +; into where it must be run (in the heap). The two areas might overlap; and, +; the segment is moved upwards. Therefore, this code starts at the highest +; address, and decrements to the lowest address. The low bytes of the starting +; pointers are not sums. The high bytes are sums; but, they do not include the +; carry. Both the low-byte sums and the carries will be done when the pointers +; are indexed by the .Y register. + +move_init: + lda #<__INIT_LOAD__ + ldx #>__INIT_LOAD__ + >__INIT_SIZE__ + sta init_load_ + stx init_load_+1 + lda #<__INIT_RUN__ + ldx #>__INIT_RUN__ + >__INIT_SIZE__ + sta init_run_ + stx init_run_+1 + +; First, move the last, partial page. +; Then, move all of the full pages. + + ldx #>__INIT_SIZE__ + 1 ; number of pages, including partial + ldy #<__INIT_SIZE__ ; size of partial page +.if .cpu & CPU_ISET_65SC02 + bra L3 +.else + jmp L3 +.endif + +L1: dec init_load_+1 + dec init_run_+1 + +L2: dey + lda (init_load_),y + sta (init_run_),y + tya +L3: bnz L2 ; page not finished + + dex + bnz L1 ; move next page + rts From 04be8020b60783c0a161de04333d9e39d7de0bff Mon Sep 17 00:00:00 2001 From: Lauri Kasanen <curaga@operamail.com> Date: Mon, 5 Oct 2015 17:18:53 +0300 Subject: [PATCH 251/351] nes: Document whether waitvblank waits for the start or end of vblank --- doc/nes.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/nes.sgml b/doc/nes.sgml index ca9ce72b3..ae8e4a971 100644 --- a/doc/nes.sgml +++ b/doc/nes.sgml @@ -69,7 +69,7 @@ Programs containing NES specific code may use the <tt/nes.h/ header file. <sect1>NES specific functions<p> <itemize> -<item>waitvblank +<item>waitvblank - wait until the start of vblank <item>get_tv </itemize> From 7f409c3edb3155fe2bd6d6c9ee40f8353598ea86 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen <curaga@operamail.com> Date: Mon, 5 Oct 2015 17:19:36 +0300 Subject: [PATCH 252/351] nes: Expose and document all joypad keys --- doc/nes.sgml | 8 ++++++++ include/nes.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/doc/nes.sgml b/doc/nes.sgml index ae8e4a971..98c25b6af 100644 --- a/doc/nes.sgml +++ b/doc/nes.sgml @@ -123,6 +123,14 @@ No extended memory drivers are currently available for the NES. </descrip><p> +The generic interface doesn't export the start and select buttons. To +test for those, use the defines in nes.h instead of the generic masks. + +Example: +<tscreen><verb> +if (joy_read(0) & KEY_A) +</verb></tscreen> + <sect1>Mouse drivers<p> diff --git a/include/nes.h b/include/nes.h index 3ad442280..fd762a09a 100644 --- a/include/nes.h +++ b/include/nes.h @@ -90,6 +90,15 @@ /* No support for dynamically loadable drivers */ #define DYN_DRV 0 +/* The joystick keys - all keys are supported */ +#define KEY_UP 0x10 +#define KEY_DOWN 0x20 +#define KEY_LEFT 0x40 +#define KEY_RIGHT 0x80 +#define KEY_A 0x1 +#define KEY_B 0x2 +#define KEY_SELECT 0x4 +#define KEY_START 0x8 /* The addresses of the static drivers */ From e6008026aacea4d7ea409f518f06ca7a7c91380c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Mon, 5 Oct 2015 16:28:16 +0200 Subject: [PATCH 253/351] Fixed bogus formatting of recent contribution. I wasn't in the mood for discussion ;-) --- include/nes.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/include/nes.h b/include/nes.h index fd762a09a..7bf56c995 100644 --- a/include/nes.h +++ b/include/nes.h @@ -91,15 +91,14 @@ #define DYN_DRV 0 /* The joystick keys - all keys are supported */ -#define KEY_UP 0x10 -#define KEY_DOWN 0x20 -#define KEY_LEFT 0x40 -#define KEY_RIGHT 0x80 -#define KEY_A 0x1 -#define KEY_B 0x2 -#define KEY_SELECT 0x4 -#define KEY_START 0x8 - +#define KEY_A 0x01 +#define KEY_B 0x02 +#define KEY_SELECT 0x04 +#define KEY_START 0x08 +#define KEY_UP 0x10 +#define KEY_DOWN 0x20 +#define KEY_LEFT 0x40 +#define KEY_RIGHT 0x80 /* The addresses of the static drivers */ extern void nes_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ From ee54f7f40c7a89d78683eb79c709748922d98fd4 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 6 Oct 2015 19:33:43 +0200 Subject: [PATCH 254/351] optimized clrscr for size --- libsrc/c64/soft80_kclrscr.s | 60 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index c2f09f76e..2e7457679 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -2,22 +2,36 @@ .export soft80_kclrscr .import soft80_kplot .import __bgcolor + .importzp ptr1 .include "c64.inc" .include "soft80.inc" soft80_kclrscr: + lda #<soft80_bitmap + sta ptr1 + lda #>soft80_bitmap + sta ptr1+1 + lda #$ff - ldx #$00 -lp1: - .repeat $1f,page - sta soft80_bitmap+(page*$100),x - .endrepeat + ldx #$1f +@lp2: + ldy #0 +@lp1: + sta (ptr1),y + iny + bne @lp1 + inc ptr1+1 + dex + bne @lp2 + + ;ldx #$00 +@lp3: sta soft80_bitmap+$1e40,x inx - bne lp1 + bne @lp3 sei ldy $01 @@ -27,28 +41,12 @@ lp1: lda CHARCOLOR and #$f0 ora __bgcolor + jsr clear ; clear vram - ;ldx #$00 -lp2: - sta soft80_vram,x - sta soft80_vram+$100,x - sta soft80_vram+$200,x - sta soft80_vram+$2e8,x - inx - bne lp2 - - inc $01 + inc $01 ; -> $35 lda __bgcolor - ;ldx #$00 -lp3: - sta soft80_colram,x - sta soft80_colram+$100,x - sta soft80_colram+$200,x - sta soft80_colram+$2e8,x - inx - bne lp3 - + jsr clear ; clear color ram sty $01 cli @@ -58,6 +56,16 @@ lp3: clc jmp soft80_kplot - + ; clear loop for colram and vram +clear: + ;ldx #$00 +@lp1: + sta soft80_colram,x + sta soft80_colram+$100,x + sta soft80_colram+$200,x + sta soft80_colram+$2e8,x + inx + bne @lp1 + rts From 67dabb8489759a789e1b778dfa313441e8fe16bf Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 6 Oct 2015 20:18:40 +0200 Subject: [PATCH 255/351] attempted fix for the color problem noticed by oliver --- libsrc/c64/soft80_color.s | 130 +++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 57 deletions(-) diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index 8475cc05c..ee226633a 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -7,7 +7,7 @@ .export soft80_textcolor, soft80_bgcolor, soft80_bordercolor .export __textcolor, __bgcolor - .importzp tmp1,tmp2 + .importzp tmp1, tmp2 .import soft80_checkchar @@ -15,74 +15,90 @@ .include "soft80.inc" soft80_textcolor: - ldx __textcolor ; get old value sta __textcolor ; set new value + jsr mkcharcolor + + txa ; get old value + rts + +soft80_bgcolor: + ldx __bgcolor ; get old value + stx tmp2 ; save old value + sta __bgcolor ; set new value + + jsr mkcharcolor + + ; if the old bg color is equal to color ram of that cell, then also + ; update the color ram to the new value. + ; FIXME: perhaps we must also check if the non visible character is not + ; a space, and NOT update the color ram in that case. + ldx #$00 +lp1: + .repeat $3,page + .scope + lda soft80_colram+(page*$100),x + and #$0f + cmp tmp2 ; old bg color + bne @sk1 + lda __bgcolor + sta soft80_colram+(page*$100),x +@sk1: + .endscope + .endrepeat + + .scope + lda soft80_colram+$2e8,x + and #$0f + cmp tmp2 ; old bg color + bne @sk1 + lda __bgcolor + sta soft80_colram+$2e8,x +@sk1: + .endscope + + inx + bne lp1 + + sei + ldy $01 + lda #$34 ; disable I/O + sta $01 + + ldx #$00 +@lp2: + .repeat $3,page + lda soft80_vram+(page*$100),x + and #$0f + ora tmp1 ; new bg color (high nibble) + sta soft80_vram+(page*$100),x + .endrepeat + lda soft80_vram+$2e8,x + and #$0f + ora tmp1 ; new bg color (high nibble) + sta soft80_vram+$2e8,x + + inx + bne @lp2 + + sty $01 ; enable I/O + cli + + lda tmp2 ; get old value + rts + +mkcharcolor: lda __bgcolor asl a asl a asl a asl a + sta tmp1 ; remember new bg color (high nibble) ora __textcolor sta CHARCOLOR ; text/bg combo for new chars - - txa ; get old value rts - -soft80_bgcolor: - ldx __bgcolor ; get old value - sta __bgcolor ; set new value - asl a - asl a - asl a - asl a - sta tmp2 ; shifted new value - ora __textcolor - sta CHARCOLOR ; text/bg combo for new chars - txa - pha ; save old value - sta tmp1 - - sei - lda $01 - pha - - lda #$34 - sta $01 - - ldx #$00 - -lp2: - .repeat $4,page - - .scope - lda soft80_vram+(page*$100),x - and #$0f - ;cmp tmp1 ; old bg color - ;bne as - ; is old bg color - ; is space - ;lda __bgcolor -as: - ora tmp2 ; new bg color - sta soft80_vram+(page*$100),x - .endscope - - .endrepeat - - inx - bne lp2 - - pla - sta $01 - cli - - pla ; get old value - rts - - soft80_bordercolor: ldx VIC_BORDERCOLOR ; get old value sta VIC_BORDERCOLOR ; set new value From 8a880580dc08238fd4f05e18e27c23316d47a167 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Wed, 7 Oct 2015 14:56:14 -0400 Subject: [PATCH 256/351] Reduced the size of the moveinit subroutine. Made other changes that were recommended by Oliver. * Changed its name from move_init to moveinit. * Used self-modifying code in the subroutine. * The INIT segment doesn't need to be optional (it's used by the start-up file). --- cfg/c64-overlay.cfg | 2 +- cfg/c64.cfg | 2 +- libsrc/c64/crt0.s | 22 +++++++-------------- libsrc/common/moveinit.s | 41 ++++++++++++++++------------------------ 4 files changed, 25 insertions(+), 42 deletions(-) diff --git a/cfg/c64-overlay.cfg b/cfg/c64-overlay.cfg index 58612e18e..5d0f611cb 100644 --- a/cfg/c64-overlay.cfg +++ b/cfg/c64-overlay.cfg @@ -46,7 +46,7 @@ SEGMENTS { DATA: load = RAM, type = rw; ZPSAVE: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; - INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; + INIT: load = MOVE, run = RAM, type = ro, define = yes; OVL1ADDR: load = OVL1ADDR, type = ro; OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; OVL2ADDR: load = OVL2ADDR, type = ro; diff --git a/cfg/c64.cfg b/cfg/c64.cfg index 861e19faf..e4e275f2e 100644 --- a/cfg/c64.cfg +++ b/cfg/c64.cfg @@ -25,7 +25,7 @@ SEGMENTS { DATA: load = RAM, type = rw; ZPSAVE: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; - INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; + INIT: load = MOVE, run = RAM, type = ro, define = yes; } FEATURES { CONDES: type = constructor, diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 5a69f1584..4953d4ade 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -3,12 +3,11 @@ ; .export _exit - .exportzp init_load_, init_run_ .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib - .import move_init, zerobss, callmain - .import RESTOR, BSOUT, CLRCH + .import moveinit, zerobss, callmain + .import BSOUT .import __HIMEM__ ; from configure file .importzp ST @@ -19,13 +18,6 @@ ; ------------------------------------------------------------------------ ; Startup code -; Two zero-page pointers are needed before any zero-page stuff is saved. -; Choose locations that are not used by anything. - -init_load_ := FREKZP -init_run_ := FREKZP+2 - - .segment "STARTUP" Start: @@ -49,17 +41,17 @@ Start: ; Allow some re-entrancy by skipping the next task if it already was done. ; This often can let us rerun the program without reloading it. - ldx moveinit + ldx move_init beq L0 ; Move the INIT segment from where it was loaded (over ZPSAVE and BSS) ; into where it must be run (in the heap). - jsr move_init - dec moveinit ; set to false + jsr moveinit + dec move_init ; set to false ; Save space by putting the rest of the start-up code in the INIT segment, -; which can be re-used by the heap. +; which can be re-used by the heap and the C stack. L0: jsr initstart @@ -134,7 +126,7 @@ L1: lda sp,x mmusave:.res 1 spsave: .res 1 -moveinit: +move_init: .byte 1 .segment "ZPSAVE" diff --git a/libsrc/common/moveinit.s b/libsrc/common/moveinit.s index e9cd5fb64..2186adf0e 100644 --- a/libsrc/common/moveinit.s +++ b/libsrc/common/moveinit.s @@ -1,16 +1,19 @@ ; -; 2015-10-04, Greg King +; 2015-10-07, Greg King ; - .export move_init + .export moveinit .import __INIT_LOAD__, __INIT_RUN__, __INIT_SIZE__ ; Linker-generated - .importzp init_load_, init_run_ .macpack cpu .macpack generic +; Put this in the DATA segment because it is self-modifying code. + +.data + ; Move the INIT segment from where it was loaded (over the bss segments) ; into where it must be run (in the heap). The two areas might overlap; and, ; the segment is moved upwards. Therefore, this code starts at the highest @@ -19,36 +22,24 @@ ; carry. Both the low-byte sums and the carries will be done when the pointers ; are indexed by the .Y register. -move_init: - lda #<__INIT_LOAD__ - ldx #>__INIT_LOAD__ + >__INIT_SIZE__ - sta init_load_ - stx init_load_+1 - lda #<__INIT_RUN__ - ldx #>__INIT_RUN__ + >__INIT_SIZE__ - sta init_run_ - stx init_run_+1 +moveinit: ; First, move the last, partial page. ; Then, move all of the full pages. - ldx #>__INIT_SIZE__ + 1 ; number of pages, including partial ldy #<__INIT_SIZE__ ; size of partial page -.if .cpu & CPU_ISET_65SC02 - bra L3 -.else - jmp L3 -.endif + ldx #>__INIT_SIZE__ + (<__INIT_SIZE__ <> 0) ; number of pages, including partial -L1: dec init_load_+1 - dec init_run_+1 - -L2: dey - lda (init_load_),y - sta (init_run_),y +L1: dey +init_load: + lda __INIT_LOAD__ + (__INIT_SIZE__ & $FF00) - $0100 * (<__INIT_SIZE__ = 0),y +init_run: + sta __INIT_RUN__ + (__INIT_SIZE__ & $FF00) - $0100 * (<__INIT_SIZE__ = 0),y tya -L3: bnz L2 ; page not finished + bnz L1 ; page not finished + dec init_load+2 + dec init_run+2 dex bnz L1 ; move next page rts From ca70700a0b730ca546c715f159a32d86b5cd0165 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 8 Oct 2015 05:05:48 -0400 Subject: [PATCH 257/351] Restored the old C-stack initiation code. I had forgotten that the stack must be put below the CBM overlays. --- cfg/c64-overlay.cfg | 2 +- cfg/c64.cfg | 2 +- libsrc/c64/crt0.s | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cfg/c64-overlay.cfg b/cfg/c64-overlay.cfg index 5d0f611cb..a95c1f6ef 100644 --- a/cfg/c64-overlay.cfg +++ b/cfg/c64-overlay.cfg @@ -14,7 +14,7 @@ MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; LOADADDR: file = %O, start = %S - 2, size = $0002; HEADER: file = %O, define = yes, start = %S, size = $000D; - RAM: file = %O, start = __HEADER_LAST__, size = __HIMEM__ - __OVERLAYSIZE__ - __STACKSIZE__ - __HEADER_LAST__; + RAM: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __OVERLAYSIZE__ - __STACKSIZE__ - __HEADER_LAST__; MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; OVL1ADDR: file = "%O.1", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; OVL1: file = "%O.1", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; diff --git a/cfg/c64.cfg b/cfg/c64.cfg index e4e275f2e..8fe1c0c6f 100644 --- a/cfg/c64.cfg +++ b/cfg/c64.cfg @@ -11,7 +11,7 @@ MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; LOADADDR: file = %O, start = %S - 2, size = $0002; HEADER: file = %O, define = yes, start = %S, size = $000D; - RAM: file = %O, start = __HEADER_LAST__, size = __HIMEM__ - __STACKSIZE__ - __HEADER_LAST__; + RAM: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __STACKSIZE__ - __HEADER_LAST__; MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; } SEGMENTS { diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 4953d4ade..a846897fe 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -8,7 +8,8 @@ .import initlib, donelib .import moveinit, zerobss, callmain .import BSOUT - .import __HIMEM__ ; from configure file + .import __RAM_START__, __RAM_SIZE__ ; Linker generated + .import __STACKSIZE__ ; from configure file .importzp ST .include "zeropage.inc" @@ -105,8 +106,8 @@ L1: lda sp,x ; Set up the stack. - lda #<__HIMEM__ - ldx #>__HIMEM__ + lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) + ldx #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) sta sp stx sp+1 ; Set argument stack ptr From 8b89f4f5a6f58763826f378da8cbf20e4a74d999 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 8 Oct 2015 06:11:37 -0400 Subject: [PATCH 258/351] Reduced c64-overlay.cfg's size by factoring out a different common expression. --- cfg/c64-overlay.cfg | 62 ++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/cfg/c64-overlay.cfg b/cfg/c64-overlay.cfg index a95c1f6ef..07ce9e4b6 100644 --- a/cfg/c64-overlay.cfg +++ b/cfg/c64-overlay.cfg @@ -1,39 +1,39 @@ FEATURES { - STARTADDRESS: default = $0801; + STARTADDRESS: default = $0801; } SYMBOLS { - __LOADADDR__: type = import; - __EXEHDR__: type = import; - __OVERLAYADDR__: type = import; - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay - __HIMEM__: type = weak, value = $D000; - __HIMEM2__: type = export, value = __HIMEM__ - 2; + __LOADADDR__: type = import; + __EXEHDR__: type = import; + __OVERLAYADDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay + __HIMEM__: type = weak, value = $D000; + __OVERLAYSTART__: type = export, value = __HIMEM__ - __OVERLAYSIZE__; } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; - LOADADDR: file = %O, start = %S - 2, size = $0002; - HEADER: file = %O, define = yes, start = %S, size = $000D; - RAM: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __OVERLAYSIZE__ - __STACKSIZE__ - __HEADER_LAST__; - MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; - OVL1ADDR: file = "%O.1", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL1: file = "%O.1", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL2ADDR: file = "%O.2", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL2: file = "%O.2", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL3ADDR: file = "%O.3", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL3: file = "%O.3", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL4ADDR: file = "%O.4", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL4: file = "%O.4", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL5ADDR: file = "%O.5", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL5: file = "%O.5", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL6ADDR: file = "%O.6", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL6: file = "%O.6", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL7ADDR: file = "%O.7", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL7: file = "%O.7", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL8ADDR: file = "%O.8", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL8: file = "%O.8", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; - OVL9ADDR: file = "%O.9", start = __HIMEM2__ - __OVERLAYSIZE__, size = $0002; - OVL9: file = "%O.9", start = __HIMEM__ - __OVERLAYSIZE__, size = __OVERLAYSIZE__; + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $000D; + RAM: file = %O, define = yes, start = __HEADER_LAST__, size = __OVERLAYSTART__ - __STACKSIZE__ - __HEADER_LAST__; + MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; + OVL1ADDR: file = "%O.1", start = __OVERLAYSTART__ - 2, size = $0002; + OVL1: file = "%O.1", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL2ADDR: file = "%O.2", start = __OVERLAYSTART__ - 2, size = $0002; + OVL2: file = "%O.2", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL3ADDR: file = "%O.3", start = __OVERLAYSTART__ - 2, size = $0002; + OVL3: file = "%O.3", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL4ADDR: file = "%O.4", start = __OVERLAYSTART__ - 2, size = $0002; + OVL4: file = "%O.4", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL5ADDR: file = "%O.5", start = __OVERLAYSTART__ - 2, size = $0002; + OVL5: file = "%O.5", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL6ADDR: file = "%O.6", start = __OVERLAYSTART__ - 2, size = $0002; + OVL6: file = "%O.6", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL7ADDR: file = "%O.7", start = __OVERLAYSTART__ - 2, size = $0002; + OVL7: file = "%O.7", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL8ADDR: file = "%O.8", start = __OVERLAYSTART__ - 2, size = $0002; + OVL8: file = "%O.8", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; + OVL9ADDR: file = "%O.9", start = __OVERLAYSTART__ - 2, size = $0002; + OVL9: file = "%O.9", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; } SEGMENTS { ZEROPAGE: load = ZP, type = zp; From e54ad81ce8f796f89ea72f029d2be4d82d6aad75 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 8 Oct 2015 20:43:25 +0200 Subject: [PATCH 259/351] some more rework, second attempt on fixing the color issues. added ifdefs to disable the color voodoo alltogether for debugging purposes. --- libsrc/c64/soft80.inc | 7 + libsrc/c64/soft80_cgetc.s | 71 +++----- libsrc/c64/soft80_color.s | 43 +++-- libsrc/c64/soft80_conio.s | 13 +- libsrc/c64/soft80_cputc.s | 344 ++++++++++++++++++++---------------- libsrc/c64/soft80_kclrscr.s | 12 +- 6 files changed, 256 insertions(+), 234 deletions(-) diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc index d534cac69..f2058f91d 100644 --- a/libsrc/c64/soft80.inc +++ b/libsrc/c64/soft80.inc @@ -21,3 +21,10 @@ CH_BTEE = 177 CH_TTEE = 178 CH_RTEE = 179 CH_LRCORNER = 189 + +;------------------------------------------------------------------------------- +; set to 0 to disable the color-ram "voodoo" for debugging purposes +.define SOFT80COLORVOODOO 1 +; set to 0 to disable special case optimization for the "space" character +.define SOFT80FASTSPACE 1 + diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index a8c52c1a2..723c5ade8 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -4,87 +4,66 @@ .export soft80_cgetc .import cursor - .import soft80_putcolor .include "c64.inc" .include "soft80.inc" +.if SOFT80COLORVOODOO = 1 + .import soft80_putcolor +.endif + soft80_cgetc: lda KEY_COUNT ; Get number of characters bne L3 ; Jump if there are already chars waiting -; Switch on the cursor if needed - - lda cursor - jsr setcursor ; set cursor on or off accordingly + jsr invertcursor ; set cursor on or off accordingly L1: lda KEY_COUNT ; wait for key beq L1 - ldx #0 - lda CURS_FLAG - bne L2 - inx -L2: txa - jsr setcursor + jsr invertcursor ; set cursor on or off accordingly L3: jsr KBDREAD ; Read char and return in A ldx #0 rts -; Switch the cursor on or off +; Switch the cursor on or off (invert) -; A= 0: cursor off -; 1: cursor on - - .proc setcursor - - ; On or off? - cmp CURS_STATE - bne @set +invertcursor: + lda cursor + bne @invert rts -@set: - sta CURS_STATE +@invert: sei lda $01 pha - lda #$34 + lda #$34 ; enable RAM under I/O sta $01 - jsr soft80_putcolor - ldy #$00 +.if SOFT80COLORVOODOO = 1 + jsr soft80_putcolor +.else + lda CHARCOLOR + sta (CRAM_PTR),y ; vram +.endif lda CURS_X and #$01 - bne @l1 - - .repeat 8,line + tax +@lp1: lda (SCREEN_PTR),y - eor #$f0 + eor nibble,x sta (SCREEN_PTR),y - .if (line < 7) iny - .endif - .endrepeat + cpy #8 + bne @lp1 -@back: pla sta $01 cli rts -@l1: - .repeat 8,line - lda (SCREEN_PTR),y - eor #$0f - sta (SCREEN_PTR),y - .if line < 7 - iny - .endif - .endrepeat - - jmp @back - - .endproc + .rodata +nibble: .byte $f0, $0f diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index ee226633a..f537f8d84 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -30,57 +30,54 @@ soft80_bgcolor: jsr mkcharcolor +.if SOFT80COLORVOODOO = 1 ; if the old bg color is equal to color ram of that cell, then also ; update the color ram to the new value. ; FIXME: perhaps we must also check if the non visible character is not ; a space, and NOT update the color ram in that case. ldx #$00 lp1: - .repeat $3,page + .repeat $4,page .scope - lda soft80_colram+(page*$100),x + lda soft80_colram+(page*250),x and #$0f cmp tmp2 ; old bg color bne @sk1 - lda __bgcolor - sta soft80_colram+(page*$100),x + lda __bgcolor ; new bg color + sta soft80_colram+(page*250),x @sk1: .endscope .endrepeat - .scope - lda soft80_colram+$2e8,x - and #$0f - cmp tmp2 ; old bg color - bne @sk1 - lda __bgcolor - sta soft80_colram+$2e8,x -@sk1: - .endscope - inx bne lp1 +.endif sei ldy $01 lda #$34 ; disable I/O sta $01 + ; if the old bg color is equal to text color in this cell, then also + ; update the text color to the new value. + ; FIXME: perhaps we need to check for space, see note above ldx #$00 -@lp2: - .repeat $3,page - lda soft80_vram+(page*$100),x +lp2: + .repeat $4,page + .scope + lda soft80_vram+(page*250),x and #$0f + cmp tmp2 ; old bg color + bne @sk2 + lda __bgcolor ; new bg color +@sk2: ora tmp1 ; new bg color (high nibble) - sta soft80_vram+(page*$100),x + sta soft80_vram+(page*250),x + .endscope .endrepeat - lda soft80_vram+$2e8,x - and #$0f - ora tmp1 ; new bg color (high nibble) - sta soft80_vram+$2e8,x inx - bne @lp2 + bne lp2 sty $01 ; enable I/O cli diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 84e5157c8..5fbeaadc1 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -6,7 +6,7 @@ .destructor soft80_shutdown .import soft80_kclrscr - .import soft80_textcolor, soft80_bgcolor + .import __textcolor, __bgcolor .importzp ptr1, ptr2, ptr3 @@ -67,11 +67,18 @@ soft80_init: cli lda 646 ; use current textcolor - jsr soft80_textcolor + and #$0f + sta __textcolor lda VIC_BG_COLOR0 ; use current bgcolor and #$0f - jsr soft80_bgcolor + sta __bgcolor + asl a + asl a + asl a + asl a + ora __textcolor + sta CHARCOLOR jmp soft80_kclrscr diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 590e16740..41132a346 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -5,7 +5,6 @@ .export soft80_cputcxy, soft80_cputc .export soft80_cputdirect, soft80_putchar - .export soft80_putcolor .export soft80_newline, soft80_plot .import popa, _gotoxy @@ -20,6 +19,10 @@ .include "c64.inc" .include "soft80.inc" +.if SOFT80COLORVOODOO = 1 + .export soft80_putcolor +.endif + soft80_cputcxy: pha ; Save C jsr popa ; Get Y @@ -125,163 +128,17 @@ L5: ; returns: Y: cursor X position ; this function is going to be used a lot so we unroll it a bit for speed -;--- start color vodoo - -; remove color from cell -; y unmodified -remcolor: - - ;ldy #$00 ; is still $00 - - lda (CRAM_PTR),y ; vram - and #$0f - cmp __bgcolor - jeq @l2b ; vram==bgcolor - - inc $01 - lda (CRAM_PTR),y ; colram - stx $01 ;$34 - and #$0f - cmp __bgcolor - beq @l2s ; colram==bgcolor - - ; vram = colram - ;inc $01 - ;lda (CRAM_PTR),y ; colram - ;stx $01 ;$34 - ;and #$0f - - sta tmp3 - lda (CRAM_PTR),y ; vram - and #$f0 - ora tmp3 - sta (CRAM_PTR),y ; vram - - ; colram = bgcolor - lda __bgcolor - inc $01 - sta (CRAM_PTR),y ; colram - stx $01 ;$34 - - jmp @l2b - -@l2s: - ; colram is bgcolor - ; => only one char in cell used - - jsr soft80_checkchar - bcc @l2b ; space at current position - - ; vram = bgcolor - lda (CRAM_PTR),y ; vram - and #$f0 - ora __bgcolor - sta (CRAM_PTR),y ; vram -@l2b: - rts - -; put color to cell -; y unmodified -soft80_putcolor: - - ;ldy #$00 ; is still $00 - - lda (CRAM_PTR),y ; vram - and #$0f - cmp __bgcolor - beq @l2s ; vram==bgcolor => first char in cell - - ; vram!=bgcolor => second char in cell - - inc $01 ;$35 - lda (CRAM_PTR),y ; colram - stx $01 ;$34 - and #$0f - cmp __bgcolor - bne @l2s ; colram!=bgcolor - - ; colram==bgcolor => second char in cell or overwrite 1st char - - jsr soft80_checkchar - bcs @l2a ; char at current position => overwrite 1st - - ; colram=vram - lda (CRAM_PTR),y ; vram - inc $01 - sta (CRAM_PTR),y ; colram - stx $01 ;$34 - - ;jmp @l2a - -@l2s: - ; colram!=bgcolor => alread 2 chars in cell -@l2a: - - ; Set color - lda CHARCOLOR - sta (CRAM_PTR),y ; vram - - rts - - -;--- end color vodoo - - .export soft80_checkchar - -; test if there is a space or a character at current position -; CLC: space SEC: character -soft80_checkchar: - - ;ldy #$00 ; is still $00 - - lda CURS_X - and #$01 - jne @l1a - - .repeat 8,line - lda (SCREEN_PTR),y - and #$f0 - cmp #$f0 - bne @l2b - .if (line < 7) - iny - .endif - .endrepeat - - ldy #$00 - clc - rts -@l2b: - ldy #$00 - sec - rts -@l1a: - .repeat 8,line - lda (SCREEN_PTR),y - and #$0f - cmp #$0f - bne @l2bb - .if line < 7 - iny - .endif - .endrepeat - ldy #$00 - clc - rts -@l2bb: - ldy #$00 - sec - rts - +.if SOFT80FASTSPACE = 1 ; output space - +; in: y must be $00 _space: lda RVS jne _spaceinvers +.if SOFT80COLORVOODOO = 1 jsr remcolor - +.endif ;ldy #$00 ; is still $00 lda CURS_X @@ -310,10 +167,15 @@ _space: jmp _back ; output inverted space - +; in: y must be $00 _spaceinvers: +.if SOFT80COLORVOODOO = 1 jsr soft80_putcolor +.else + lda CHARCOLOR + sta (CRAM_PTR),y ; vram +.endif lda CURS_X and #$01 @@ -339,11 +201,12 @@ _spaceinvers: .endrepeat jmp _back +.endif ; output a character soft80_putchar: - sta tmp3 + sta tmp3 ; remember charcode sei ldx $01 @@ -353,14 +216,20 @@ soft80_putchar: stx $01 ; will stay $34 for space ldy #$00 ; will be $00 from now on +.if SOFT80FASTSPACE = 1 cmp #' ' ; space is a special (optimized) case jeq _space +.endif +.if SOFT80COLORVOODOO = 1 jsr soft80_putcolor +.else + lda CHARCOLOR + sta (CRAM_PTR),y ; vram +.endif + ; output character -; output character -char: - ldx tmp3 + ldx tmp3 ; get charcode lda RVS jne _invers @@ -429,3 +298,166 @@ _invers: .endif .endrepeat jmp _back + +;------------------------------------------------------------------------------- + +.if SOFT80COLORVOODOO = 1 +;--- start color vodoo + +; remove color from cell, called before putting a "space" character to the bitmap +; y unmodified +remcolor: + + ;ldy #$00 ; is still $00 + + ; if the textcolor in vram is equal to the background color, then + ; no (visible) character is in the current cell and we can exit + ; immediately. + lda (CRAM_PTR),y ; vram (textcolor) + and #$0f + cmp __bgcolor + jeq @l2b ; yes, vram==bgcolor + + ; now check if the textcolor in color ram is equal the background color, + ; if yes then there is only one (visible) character in the current cell + inc $01 + lda (CRAM_PTR),y ; colram (2nd textcolor) + stx $01 ;$34 + and #$0f + cmp __bgcolor + beq @l2s ; yes, colram==bgcolor + + ; two characters in the current cell, of which one will get removed + + ; vram = colram + ;inc $01 + ;lda (CRAM_PTR),y ; colram + ;stx $01 ;$34 + ;and #$0f + + ; move 2nd text color to vram + sta tmp3 + lda (CRAM_PTR),y ; vram + and #$f0 + ora tmp3 + sta (CRAM_PTR),y ; vram + + ; colram = bgcolor + lda __bgcolor + inc $01 + sta (CRAM_PTR),y ; colram + stx $01 ;$34 + + jmp @l2b + +@l2s: + ; colram is bgcolor + ; => only one char in cell used + + jsr soft80_checkchar + bcc @l2b ; space at current position + + ; vram (textcolor) = bgcolor + lda (CRAM_PTR),y ; vram + and #$f0 + ora __bgcolor + sta (CRAM_PTR),y ; vram +@l2b: + rts + +; put color to cell +; in: $01 is $34 (RAM under I/O) when entering +; y must be $00 +; out: y = $00 +soft80_putcolor: + + ;ldy #$00 ; is still $00 + + lda (CRAM_PTR),y ; vram + and #$0f + cmp __bgcolor + beq @l2s ; vram==bgcolor => first char in cell + + ; vram!=bgcolor => second char in cell + + inc $01 ;$35 + lda (CRAM_PTR),y ; colram + stx $01 ;$34 + and #$0f + cmp __bgcolor + bne @l2s ; colram!=bgcolor + + ; colram==bgcolor => second char in cell or overwrite 1st char + + jsr soft80_checkchar + bcs @l2a ; char at current position => overwrite 1st + + ; colram=vram + lda (CRAM_PTR),y ; vram + inc $01 + sta (CRAM_PTR),y ; colram + stx $01 ;$34 + + ;jmp @l2a + +@l2s: + ; colram!=bgcolor => alread 2 chars in cell +@l2a: + + ; Set color + lda CHARCOLOR + sta (CRAM_PTR),y ; vram + + rts + + ;.export soft80_checkchar + +; test if there is a space or a character at current position +; in: y must be $00 +; out: CLC: space SEC: character +; y = $00 +soft80_checkchar: + + ;ldy #$00 ; is still $00 + + lda CURS_X + and #$01 + jne @l1a + + .repeat 8,line + lda (SCREEN_PTR),y + and #$f0 + cmp #$f0 + bne @l2b + .if (line < 7) + iny + .endif + .endrepeat + + ldy #$00 + clc + rts +@l2b: + ldy #$00 + sec + rts +@l1a: + .repeat 8,line + lda (SCREEN_PTR),y + and #$0f + cmp #$0f + bne @l2bb + .if line < 7 + iny + .endif + .endrepeat + ldy #$00 + clc + rts +@l2bb: + ldy #$00 + sec + rts + +;--- end color vodoo +.endif diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index 2e7457679..790aa2749 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -33,9 +33,14 @@ soft80_kclrscr: inx bne @lp3 +.if SOFT80COLORVOODOO = 1 + lda __bgcolor + jsr clear ; clear color ram +.endif + sei ldy $01 - lda #$34 + lda #$34 ; enable RAM under I/O sta $01 lda CHARCOLOR @@ -43,11 +48,6 @@ soft80_kclrscr: ora __bgcolor jsr clear ; clear vram - inc $01 ; -> $35 - - lda __bgcolor - jsr clear ; clear color ram - sty $01 cli From f712e9448ade899d57ed993c8ce6351214d1c3e1 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 9 Oct 2015 13:34:23 +0200 Subject: [PATCH 260/351] some cleanup/rework --- libsrc/c64/extra/soft80.s | 5 ----- libsrc/c64/soft80_cgetc.s | 6 ++++++ libsrc/c64/soft80_color.s | 8 ++++++-- libsrc/c64/soft80_cputc.s | 2 -- libsrc/c64/soft80_kplot.s | 5 +++++ libsrc/c64/soft80_scrsize.s | 6 ++++++ 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index e6b373b64..80ef338b6 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -51,8 +51,3 @@ .import soft80_screensize .export screensize := soft80_screensize -;------------------------------------------------------------------------------- -; force the init constructor to be imported - - .import soft80_init -conio_init = soft80_init diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 723c5ade8..c68035dc5 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -67,3 +67,9 @@ invertcursor: .rodata nibble: .byte $f0, $0f + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80_init +conio_init = soft80_init diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index f537f8d84..3d9cca56c 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -9,8 +9,6 @@ .importzp tmp1, tmp2 - .import soft80_checkchar - .include "c64.inc" .include "soft80.inc" @@ -107,3 +105,9 @@ __textcolor: .res 1 __bgcolor: .res 1 + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80_init +conio_init = soft80_init diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 41132a346..233132dca 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -410,8 +410,6 @@ soft80_putcolor: rts - ;.export soft80_checkchar - ; test if there is a space or a character at current position ; in: y must be $00 ; out: CLC: space SEC: character diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index eaaed7596..6df33c008 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -62,3 +62,8 @@ _bitmaphi: .byte >(soft80_bitmap+(row*40*8)) .endrepeat +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80_init +conio_init = soft80_init diff --git a/libsrc/c64/soft80_scrsize.s b/libsrc/c64/soft80_scrsize.s index caaeb4791..1873f7327 100644 --- a/libsrc/c64/soft80_scrsize.s +++ b/libsrc/c64/soft80_scrsize.s @@ -7,3 +7,9 @@ soft80_screensize: ldy #screenrows ldx #charsperline rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80_init +conio_init = soft80_init From 0b9d67d8a864d02631881b7cdc2e0e720d8bd2b9 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 9 Oct 2015 13:40:10 +0200 Subject: [PATCH 261/351] use default prio for the constructor --- libsrc/c64/soft80_conio.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 5fbeaadc1..6b909822a 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -2,7 +2,7 @@ ; Low level stuff for screen output/console input ; - .constructor soft80_init, 24 + .constructor soft80_init .destructor soft80_shutdown .import soft80_kclrscr From f21e3ae895322bf3d74bc90f63b0a75872a1799a Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 9 Oct 2015 13:42:25 +0200 Subject: [PATCH 262/351] According to the contributor the prio wasn't intentionally set. --- libsrc/pce/clock.s | 2 +- libsrc/pce/conio.s | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index c6d6fb7fb..8fda58adc 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -21,7 +21,7 @@ .endproc - .constructor initclock, 24 + .constructor initclock initclock: lda #0 diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index bcfc600a7..1428ef59f 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -5,7 +5,7 @@ .import psg_init .import vdc_init - .constructor initconio, 24 + .constructor initconio .macpack longbranch From 8c609dd931106e73ccc5ee576d0a5ee832a1072e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 9 Oct 2015 12:00:41 -0400 Subject: [PATCH 263/351] Explained why two variables were moved out of the BSS segment. --- libsrc/c64/crt0.s | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index a846897fe..a2abe91af 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -40,7 +40,7 @@ Start: stx spsave ; Save the system stack ptr ; Allow some re-entrancy by skipping the next task if it already was done. -; This often can let us rerun the program without reloading it. +; This sometimes can let us rerun the program without reloading it. ldx move_init beq L0 @@ -125,8 +125,12 @@ L1: lda sp,x .data +; These two variables were moved out of the BSS segment, and into DATA, because +; we need to use them before INIT is moved off of BSS, and before BSS is zeroed. + mmusave:.res 1 spsave: .res 1 + move_init: .byte 1 From 575f859a030262b60fce9a0a136c54f4b198ca89 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 9 Oct 2015 18:33:35 +0200 Subject: [PATCH 264/351] Keep low level VIC sprite stuff out of user code. --- include/mouse.h | 13 ++++++-- libsrc/c128/mcbdefault.s | 34 ++++++++++++++++++++- libsrc/c64/mcbdefault.s | 32 ++++++++++++++++++++ libsrc/cbm/mcbpointercolor.s | 10 +++++++ libsrc/cbm/mcbpointershape.s | 30 +++++++++++++++++++ libsrc/cbm510/mcbdefault.s | 39 ++++++++++++++++++++++++ samples/mousetest.c | 58 ++---------------------------------- 7 files changed, 157 insertions(+), 59 deletions(-) create mode 100644 libsrc/cbm/mcbpointercolor.s create mode 100644 libsrc/cbm/mcbpointershape.s diff --git a/include/mouse.h b/include/mouse.h index ac75956c0..8bd9a00ff 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -122,6 +122,16 @@ struct mouse_callbacks { /* The default mouse callbacks */ extern const struct mouse_callbacks mouse_def_callbacks; +#if defined(__CBM__) + +/* The default mouse pointer shape used by the default mouse callbacks */ +extern const unsigned char mouse_def_pointershape[63]; + +/* The default mouse pointer color used by the default mouse callbacks */ +extern const unsigned char mouse_def_pointercolor; + +#endif + /* The name of the standard mouse driver for a platform */ extern const char mouse_stddrv[]; @@ -208,6 +218,3 @@ unsigned char __fastcall__ mouse_ioctl (unsigned char code, void* data); /* End of mouse.h */ #endif - - - diff --git a/libsrc/c128/mcbdefault.s b/libsrc/c128/mcbdefault.s index 01c54efca..1951129a6 100644 --- a/libsrc/c128/mcbdefault.s +++ b/libsrc/c128/mcbdefault.s @@ -7,7 +7,10 @@ ; be called from an interrupt handler ; + .constructor initmcb .export _mouse_def_callbacks + .import _mouse_def_pointershape + .import _mouse_def_pointercolor .include "mouse-kernel.inc" .include "c128.inc" @@ -15,16 +18,45 @@ .macpack generic ; Sprite definitions. The first value can be changed to adjust the number -; of the sprite used for the mouse. +; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MEM = $0E00 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register +; -------------------------------------------------------------------------- +; Initialize the mouse sprite. + +.segment "INIT" + +initmcb: + +; Copy the mouse sprite data + + ldx #64 - 1 +@L0: lda _mouse_def_pointershape,x + sta MOUSE_SPR_MEM,x + dex + bpl @L0 + +; Set the mouse sprite pointer + + lda #<(MOUSE_SPR_MEM / 64) + sta $07F8 + MOUSE_SPR + +; Set the mouse sprite color + + lda _mouse_def_pointercolor + sta VIC_SPR0_COLOR + MOUSE_SPR + rts + ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. +.code + hide: lda #MOUSE_SPR_NMASK and VIC_SPR_ENA diff --git a/libsrc/c64/mcbdefault.s b/libsrc/c64/mcbdefault.s index ffeed45b3..c4feddfea 100644 --- a/libsrc/c64/mcbdefault.s +++ b/libsrc/c64/mcbdefault.s @@ -7,7 +7,10 @@ ; be called from an interrupt handler ; + .constructor initmcb .export _mouse_def_callbacks + .import _mouse_def_pointershape + .import _mouse_def_pointercolor .include "mouse-kernel.inc" .include "c64.inc" @@ -17,14 +20,43 @@ ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MEM = $0340 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register +; -------------------------------------------------------------------------- +; Initialize the mouse sprite. + +.segment "INIT" + +initmcb: + +; Copy the mouse sprite data + + ldx #64 - 1 +@L0: lda _mouse_def_pointershape,x + sta MOUSE_SPR_MEM,x + dex + bpl @L0 + +; Set the mouse sprite pointer + + lda #<(MOUSE_SPR_MEM / 64) + sta $07F8 + MOUSE_SPR + +; Set the mouse sprite color + + lda _mouse_def_pointercolor + sta VIC_SPR0_COLOR + MOUSE_SPR + rts + ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. +.code + hide: lda #MOUSE_SPR_NMASK and VIC_SPR_ENA diff --git a/libsrc/cbm/mcbpointercolor.s b/libsrc/cbm/mcbpointercolor.s new file mode 100644 index 000000000..c9cb6330e --- /dev/null +++ b/libsrc/cbm/mcbpointercolor.s @@ -0,0 +1,10 @@ +; VIC sprite color for the mouse pointer + + .export _mouse_def_pointercolor + + +.segment "INIT" + +_mouse_def_pointercolor: + + .byte $01 ; White diff --git a/libsrc/cbm/mcbpointershape.s b/libsrc/cbm/mcbpointershape.s new file mode 100644 index 000000000..7364201b1 --- /dev/null +++ b/libsrc/cbm/mcbpointershape.s @@ -0,0 +1,30 @@ +; VIC sprite data for the mouse pointer (an arrow) + + .export _mouse_def_pointershape + + +.segment "INIT" + +_mouse_def_pointershape: + + .byte %11111110, %00000000, %00000000 + .byte %11111100, %00000000, %00000000 + .byte %11111000, %00000000, %00000000 + .byte %11111100, %00000000, %00000000 + .byte %11011110, %00000000, %00000000 + .byte %10001111, %00000000, %00000000 + .byte %00000111, %10000000, %00000000 + .byte %00000011, %11000000, %00000000 + .byte %00000001, %11100000, %00000000 + .byte %00000000, %11110000, %00000000 + .byte %00000000, %01111000, %00000000 + .byte %00000000, %00111000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 diff --git a/libsrc/cbm510/mcbdefault.s b/libsrc/cbm510/mcbdefault.s index 028fb4ec1..7542d776d 100644 --- a/libsrc/cbm510/mcbdefault.s +++ b/libsrc/cbm510/mcbdefault.s @@ -8,7 +8,10 @@ ; be called from an interrupt handler. ; + .constructor initmcb .export _mouse_def_callbacks + .import _mouse_def_pointershape + .import _mouse_def_pointercolor .import vic:zp .include "mouse-kernel.inc" @@ -19,14 +22,50 @@ ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on that value. MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MEM = $F400 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register +; -------------------------------------------------------------------------- +; Initialize the mouse sprite. + +.segment "INIT" + +initmcb: + +; Copy the mouse sprite data + + ldx #64 - 1 +@L0: lda _mouse_def_pointershape,x + sta MOUSE_SPR_MEM,x + dex + bpl @L0 + +; Set the mouse sprite pointer + + lda #<(MOUSE_SPR_MEM / 64) + sta $F3F8 + MOUSE_SPR + +; Set the mouse sprite color + + ldx IndReg + lda #15 + sta IndReg + + lda _mouse_def_pointercolor + ldy VIC_SPR0_COLOR + MOUSE_SPR + sta (vic),y + + stx IndReg + rts + ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. +.code + hide: ldy #15 sty IndReg diff --git a/samples/mousetest.c b/samples/mousetest.c index 7d9409659..4a849cb98 100644 --- a/samples/mousetest.c +++ b/samples/mousetest.c @@ -40,44 +40,11 @@ -#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) +#ifdef __CBM__ -/* Addresses of data for sprite 0 */ -#if defined(__C64__) -# define SPRITE0_DATA ((unsigned char[64])0x0340) -# define SPRITE0_PTR ((unsigned char *)0x07F8) -#elif defined(__C128__) -# define SPRITE0_DATA ((unsigned char[64])0x0E00) -# define SPRITE0_PTR ((unsigned char *)0x07F8) -#elif defined(__CBM510__) -# define SPRITE0_DATA ((unsigned char[64])0xF400) -# define SPRITE0_PTR ((unsigned char *)0xF3F8) -#endif +/* Set dark-on-light colors. */ +const unsigned char mouse_def_pointercolor = COLOR_BLACK; -/* The mouse sprite (an arrow) */ -static const unsigned char MouseSprite[64] = { - 0xFE, 0x00, 0x00, - 0xFC, 0x00, 0x00, - 0xF8, 0x00, 0x00, - 0xFC, 0x00, 0x00, - 0xDE, 0x00, 0x00, - 0x8F, 0x00, 0x00, - 0x07, 0x80, 0x00, - 0x03, 0xC0, 0x00, - 0x01, 0xE0, 0x00, - 0x00, 0xF0, 0x00, - 0x00, 0x78, 0x00, - 0x00, 0x38, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00 -}; #endif @@ -159,25 +126,6 @@ int main (void) cursor (0); clrscr (); - /* The pointer should be created before the driver is installed, - ** in case a lightpen driver needs it during calibration. - */ - -#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) - /* Copy the sprite data */ - memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite)); - - /* Set the VIC-II sprite pointer. */ - *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA; - - /* Set the color of sprite 0 */ -# ifdef __CBM510__ - pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK); -# else - VIC.spr0_color = COLOR_BLACK; -# endif -#endif - /* If a lightpen driver is installed, then it can get a calibration value ** from this file (if it exists). Or, the user can adjust the pen; and, ** the value will be put into this file, for the next time. From 326da8514549afb72cafef5142690feada29170d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 9 Oct 2015 21:44:20 +0200 Subject: [PATCH 265/351] Consistently place constructors (and their exclusive subroutines) in "INIT". --- libsrc/atari5200/conioscreen.s | 4 ++-- libsrc/c128/systime.s | 3 +-- libsrc/c64/systime.s | 3 +-- libsrc/osic1p/cgetc.s | 2 ++ libsrc/pce/clock.s | 7 ++++--- libsrc/pce/conio.s | 16 +++++----------- libsrc/pce/psg.s | 2 +- libsrc/pce/vce.s | 2 +- 8 files changed, 17 insertions(+), 22 deletions(-) diff --git a/libsrc/atari5200/conioscreen.s b/libsrc/atari5200/conioscreen.s index 412dd582d..660276675 100644 --- a/libsrc/atari5200/conioscreen.s +++ b/libsrc/atari5200/conioscreen.s @@ -7,9 +7,10 @@ SCREEN_BUF_SIZE = 20 * 24 SCREEN_BUF = $4000 - SCREEN_BUF_SIZE - .code .export screen_setup_20x24 + .segment "INIT" + screen_setup_20x24: ; initialize SAVMSC @@ -79,5 +80,4 @@ dlist: .repeat 3 .assert ((* >> 10) = (dlist >> 10)), error, "Display list crosses 1K boundary" - .end diff --git a/libsrc/c128/systime.s b/libsrc/c128/systime.s index 0a7f8f367..e12d016b8 100644 --- a/libsrc/c128/systime.s +++ b/libsrc/c128/systime.s @@ -63,6 +63,7 @@ BCD2dec:tax ; Constructor that writes to the 1/10 sec register of the TOD to kick it ; into action. If this is not done, the clock hangs. We will read the register ; and write it again, ignoring a possible change in between. +.segment "INIT" .proc initsystime @@ -78,7 +79,6 @@ BCD2dec:tax .endproc - ;---------------------------------------------------------------------------- ; TM struct with date set to 1970-01-01 .data @@ -92,4 +92,3 @@ TM: .word 0 ; tm_sec .word 0 ; tm_wday .word 0 ; tm_yday .word 0 ; tm_isdst - diff --git a/libsrc/c64/systime.s b/libsrc/c64/systime.s index a00df1397..f8cd1b714 100644 --- a/libsrc/c64/systime.s +++ b/libsrc/c64/systime.s @@ -63,6 +63,7 @@ BCD2dec:tax ; Constructor that writes to the 1/10 sec register of the TOD to kick it ; into action. If this is not done, the clock hangs. We will read the register ; and write it again, ignoring a possible change in between. +.segment "INIT" .proc initsystime @@ -81,7 +82,6 @@ BCD2dec:tax .endproc - ;---------------------------------------------------------------------------- ; TM struct with date set to 1970-01-01 .data @@ -95,4 +95,3 @@ TM: .word 0 ; tm_sec .word 0 ; tm_wday .word 0 ; tm_yday .word 0 ; tm_isdst - diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index 0c7c69488..5ddca2870 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -11,12 +11,14 @@ .include "zeropage.inc" ; Initialize one-character buffer that is filled by kbhit() + .segment "INIT" initcgetc: lda #$00 sta CHARBUF ; No character in buffer initially rts ; Input routine from 65V PROM MONITOR, show cursor if enabled + .code _cgetc: lda CHARBUF ; character in buffer available? beq nobuffer diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 8fda58adc..261739df8 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -5,9 +5,11 @@ .include "pce.inc" .include "extzp.inc" - .forceimport ticktock .export _clock + .forceimport ticktock .importzp sreg + .constructor initclock + .proc _clock @@ -21,8 +23,7 @@ .endproc - .constructor initclock - + .segment "INIT" initclock: lda #0 ldx #3 diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 1428ef59f..64df87018 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,14 +1,16 @@ .include "pce.inc" .include "extzp.inc" - .import vce_init - .import psg_init - .import vdc_init + .import vce_init + .import psg_init + .import colors + .importzp ptr1, tmp1 .constructor initconio .macpack longbranch + .segment "INIT" initconio: jsr vce_init jsr psg_init @@ -20,7 +22,6 @@ initconio: st2 #>$0088 rts - .import colors set_palette: stz VCE_ADDR_LO stz VCE_ADDR_HI @@ -48,11 +49,6 @@ set_palette: rts -;---------------------------------------------------------------------------- -; -;---------------------------------------------------------------------------- - - .importzp ptr1, tmp1 conio_init: ; Load font st0 #VDC_MAWR @@ -80,13 +76,11 @@ conio_init: sta tmp1 jsr copy - ldx #0 stx BGCOLOR inx stx CHARCOLOR - rts copy: diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index 17d26b941..b1d610fa1 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,8 +1,8 @@ - .include "pce.inc" .export psg_init + .segment "INIT" psg_init: clx stz PSG_GLOBAL_PAN ; Clear global balance diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 3c19fd55b..af69c5ed1 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,8 +1,8 @@ - .include "pce.inc" .export vce_init + .segment "INIT" vce_init: ; Set CTA to zero stz VCE_ADDR_LO From ccc7c2b1f9787e8f6cab7309132ef878082d9d4f Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 9 Oct 2015 22:18:51 +0200 Subject: [PATCH 266/351] Minor style adjustment. --- libsrc/atari/dosdetect.s | 2 +- libsrc/atari/getargs.s | 2 +- libsrc/atari/getdefdev.s | 2 +- libsrc/atari/mcbpm.s | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/atari/dosdetect.s b/libsrc/atari/dosdetect.s index c60ac479b..654da55b5 100644 --- a/libsrc/atari/dosdetect.s +++ b/libsrc/atari/dosdetect.s @@ -5,7 +5,7 @@ ; .include "atari.inc" - .constructor detect,26 + .constructor detect, 26 .export __dos_type ; ------------------------------------------------------------------------ diff --git a/libsrc/atari/getargs.s b/libsrc/atari/getargs.s index fdae55364..fb3b7bc03 100644 --- a/libsrc/atari/getargs.s +++ b/libsrc/atari/getargs.s @@ -15,7 +15,7 @@ SPACE = 32 ; SPACE char. .import __argc, __argv .importzp ptr1 .import __dos_type - .constructor initmainargs,25 + .constructor initmainargs, 25 ; -------------------------------------------------------------------------- ; Get command line diff --git a/libsrc/atari/getdefdev.s b/libsrc/atari/getdefdev.s index 13aa12e04..47d8714e6 100644 --- a/libsrc/atari/getdefdev.s +++ b/libsrc/atari/getdefdev.s @@ -19,7 +19,7 @@ .export __getdefdev ; get default device .export __defdev ; this is the default device string (e.g. "D1:") .ifdef DYNAMIC_DD - .constructor __getdefdev,24 + .constructor __getdefdev, 24 .endif ; Get default device (LBUF will be destroyed!!) diff --git a/libsrc/atari/mcbpm.s b/libsrc/atari/mcbpm.s index b546faced..c5c5dd433 100644 --- a/libsrc/atari/mcbpm.s +++ b/libsrc/atari/mcbpm.s @@ -10,8 +10,8 @@ .include "atari.inc" .importzp sp .export _mouse_pm_callbacks - .constructor pm_init,27 - .destructor pm_down,7 + .constructor pm_init, 27 + .destructor pm_down ; get mouse shape data .import mouse_pm_bits From 03c6af3e15168eabaf9527814f561ba7670b0bf8 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 9 Oct 2015 23:39:37 +0200 Subject: [PATCH 267/351] rewrote color voodoo --- libsrc/c64/soft80_cgetc.s | 36 ++++++---- libsrc/c64/soft80_cputc.s | 136 +++++++++++++++++++++++++++----------- 2 files changed, 120 insertions(+), 52 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index c68035dc5..130aca7c5 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -4,23 +4,22 @@ .export soft80_cgetc .import cursor + .importzp tmp1 .include "c64.inc" .include "soft80.inc" -.if SOFT80COLORVOODOO = 1 - .import soft80_putcolor -.endif - soft80_cgetc: lda KEY_COUNT ; Get number of characters bne L3 ; Jump if there are already chars waiting + ldx #1 jsr invertcursor ; set cursor on or off accordingly L1: lda KEY_COUNT ; wait for key beq L1 + ldx #0 jsr invertcursor ; set cursor on or off accordingly L3: jsr KBDREAD ; Read char and return in A @@ -36,18 +35,13 @@ invertcursor: @invert: sei - lda $01 + lda $01 ; enable RAM under I/O pha - lda #$34 ; enable RAM under I/O + lda #$34 sta $01 ldy #$00 -.if SOFT80COLORVOODOO = 1 - jsr soft80_putcolor -.else - lda CHARCOLOR - sta (CRAM_PTR),y ; vram -.endif + jsr setcolor lda CURS_X and #$01 @@ -65,6 +59,24 @@ invertcursor: cli rts + ; do not use soft80_putcolor here to make sure the cursor is always + ; shown using the current textcolor without disturbing the "color voodoo" + ; in soft80_cputc +setcolor: + ;ldy #0 ; is 0 + txa + bne @set + ; restore old value + lda tmp1 + sta (CRAM_PTR),y ; vram + rts +@set: + lda (CRAM_PTR),y ; vram + sta tmp1 + lda CHARCOLOR + sta (CRAM_PTR),y ; vram + rts + .rodata nibble: .byte $f0, $0f diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 233132dca..3ef982aaa 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -10,7 +10,7 @@ .import popa, _gotoxy .import xsize .import soft80_kplot - .import __bgcolor + .import __bgcolor, __textcolor .importzp tmp4,tmp3 @@ -300,12 +300,36 @@ _invers: jmp _back ;------------------------------------------------------------------------------- +; optional "color voodoo". the problem is that each 8x8 cell can only contain +; two colors, one of which is used for the background color, so two characters +; have to share the same text color. +; +; - in a cell that contains two spaces, both the color ram and the text color +; in vram contain the background color +; +; - in a cell that contains one character, its text color goes into vram. the +; color ram contains the background color. +; +; - in a cell that contains two characters, the color of the left character goes +; to vram (and is shared by both for display). the "would be" color of the +; right character goes to color ram as a reminder and can be restored when one +; of the two characters is cleared by a space. .if SOFT80COLORVOODOO = 1 -;--- start color vodoo ; remove color from cell, called before putting a "space" character to the bitmap -; y unmodified +; +; __ -> __ - +; _A -> _A - +; B_ -> B_ - +; _A -> __ vram = bgcol +; B_ -> __ vram = bgcol +; BA -> _A vram = colram, colram = bgcol +; BA -> B_ colram = bgcol +; +; in: x must be $34 +; y must be $00 +; out: y = $00 remcolor: ;ldy #$00 ; is still $00 @@ -316,16 +340,16 @@ remcolor: lda (CRAM_PTR),y ; vram (textcolor) and #$0f cmp __bgcolor - jeq @l2b ; yes, vram==bgcolor + beq @sk1 ; yes, vram==bgcolor ; now check if the textcolor in color ram is equal the background color, ; if yes then there is only one (visible) character in the current cell - inc $01 + inc $01 ; $35 lda (CRAM_PTR),y ; colram (2nd textcolor) - stx $01 ;$34 + stx $01 ; $34 and #$0f cmp __bgcolor - beq @l2s ; yes, colram==bgcolor + beq @sk2 ; yes, colram==bgcolor ; two characters in the current cell, of which one will get removed @@ -334,41 +358,58 @@ remcolor: ;lda (CRAM_PTR),y ; colram ;stx $01 ;$34 ;and #$0f + sta tmp3 ; A contains colram - ; move 2nd text color to vram - sta tmp3 + lda CURS_X + and #$01 + bne @sk3 + + ; vram = colram lda (CRAM_PTR),y ; vram and #$f0 ora tmp3 sta (CRAM_PTR),y ; vram - +@sk3: ; colram = bgcolor lda __bgcolor - inc $01 + inc $01 ; $35 sta (CRAM_PTR),y ; colram - stx $01 ;$34 + stx $01 ; $34 - jmp @l2b + rts -@l2s: +@sk2: ; colram is bgcolor ; => only one char in cell used jsr soft80_checkchar - bcc @l2b ; space at current position + bcc @sk1 ; space at current position ; vram (textcolor) = bgcolor lda (CRAM_PTR),y ; vram and #$f0 ora __bgcolor sta (CRAM_PTR),y ; vram -@l2b: +@sk1: rts ; put color to cell -; in: $01 is $34 (RAM under I/O) when entering -; y must be $00 -; out: y = $00 +; +; __ -> _A vram = textcol +; __ -> B_ vram = textcol +; _A -> BA colram = vram, vram = textcol +; B_ -> BA colram = textcol +; +; _A -> _C vram = textcol +; B_ -> C_ vram = textcol +; BA -> BC colram = textcol +; BA -> CA vram = textcol +; +; in: $01 is $34 (RAM under I/O) when entering +; x must be $34 +; y must be $00 +; out: x = $34 +; y = $00 soft80_putcolor: ;ldy #$00 ; is still $00 @@ -376,38 +417,54 @@ soft80_putcolor: lda (CRAM_PTR),y ; vram and #$0f cmp __bgcolor - beq @l2s ; vram==bgcolor => first char in cell + beq @sk1 ; vram==bgcolor => first char in cell ; vram!=bgcolor => second char in cell - inc $01 ;$35 + inc $01 ; $35 lda (CRAM_PTR),y ; colram - stx $01 ;$34 + stx $01 ; $34 and #$0f cmp __bgcolor - bne @l2s ; colram!=bgcolor + beq @l2s ; colram==bgcolor -> second char in cell - ; colram==bgcolor => second char in cell or overwrite 1st char + ; botch characters in the cell are used - jsr soft80_checkchar - bcs @l2a ; char at current position => overwrite 1st + lda CURS_X + and #$01 + bne @sk2 ; jump if odd xpos - ; colram=vram - lda (CRAM_PTR),y ; vram - inc $01 - sta (CRAM_PTR),y ; colram - stx $01 ;$34 - - ;jmp @l2a - -@l2s: - ; colram!=bgcolor => alread 2 chars in cell -@l2a: - - ; Set color + ; vram = textcol lda CHARCOLOR sta (CRAM_PTR),y ; vram + rts +@l2s: + ; one character in cell is already used + jsr soft80_checkchar + bcs @sk1 ; char at current position => overwrite 1st + + lda CURS_X + and #$01 + beq @sk3 ; jump if even xpos +@sk2: + ; colram = textcol + lda __textcolor + inc $01 ; $35 + sta (CRAM_PTR),y ; colram + stx $01 ; $34 + rts + +@sk3: + ; colram=vram + lda (CRAM_PTR),y ; vram + inc $01 ; $35 + sta (CRAM_PTR),y ; colram + stx $01 ; $34 +@sk1: + ; vram = textcol + lda CHARCOLOR + sta (CRAM_PTR),y ; vram rts ; test if there is a space or a character at current position @@ -457,5 +514,4 @@ soft80_checkchar: sec rts -;--- end color vodoo .endif From 70ed96d06d948f0732f0379b8df9f9934c44ec3a Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Fri, 9 Oct 2015 23:39:55 +0200 Subject: [PATCH 268/351] updated conio test --- testcode/lib/conio.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index f998abeae..3e4b4539f 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -18,7 +18,7 @@ void main(void) clrscr(); screensize(&xsize, &ysize); - cputs("cc65 conio test\n\rInput:[ ]"); + cputs("cc65 conio test\n\rInput: [ ]"); cputsxy(0, 2, "Colors:" ); tcol = textcolor(0); /* remember original textcolor */ @@ -80,9 +80,18 @@ void main(void) cputs(" revers"); revers(0); - gotoxy(7 + inpos,1); - cputc(cgetc()); - inpos = (inpos + 1) & 7; + gotoxy(8 + inpos,1); + i = cgetc(); + if ((i >= '0') && (i<='9')) { + textcolor(i - '0'); + } else if (i == CH_CURS_LEFT) { + inpos = (inpos - 1) & 7; + } else if (i == CH_CURS_RIGHT) { + inpos = (inpos + 1) & 7; + } else { + cputc(i); + inpos = (inpos + 1) & 7; + } ++n; } From c4966ac6a63d148bd524a378cf81bb8617c9e40c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 10 Oct 2015 11:15:43 +0200 Subject: [PATCH 269/351] Fixed stupid adressing mode bug. Thanks Greg for pointing out :-) --- libsrc/cbm510/mcbdefault.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cbm510/mcbdefault.s b/libsrc/cbm510/mcbdefault.s index 7542d776d..0db753e92 100644 --- a/libsrc/cbm510/mcbdefault.s +++ b/libsrc/cbm510/mcbdefault.s @@ -55,7 +55,7 @@ initmcb: sta IndReg lda _mouse_def_pointercolor - ldy VIC_SPR0_COLOR + MOUSE_SPR + ldy #VIC_SPR0_COLOR + MOUSE_SPR sta (vic),y stx IndReg From 32397b9a2b7363c10ff9c46897a27c4e818137dc Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 11 Oct 2015 17:07:48 +0200 Subject: [PATCH 270/351] print a space for 0x0a and 0x0d in the char matrix --- testcode/lib/conio.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index 3e4b4539f..a7a83594e 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -58,6 +58,8 @@ void main(void) for (i = 0; i < 256; ++i) { if ((i != '\n') && (i != '\r')) { cputc(i); + } else { + cputc(' '); } } while(wherex() > 0) { From d8d7f53d1b2187d2ba44a00d7002e49a592b8da2 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 11 Oct 2015 17:13:28 +0200 Subject: [PATCH 271/351] move charset to seperate file again, added comments on charset layout --- libsrc/c64/soft80_cgetc.s | 2 + libsrc/c64/soft80_charset.s | 171 ++++++++++++++++++++++++++++++++++++ libsrc/c64/soft80_conio.s | 143 +----------------------------- libsrc/c64/soft80_cputc.s | 3 +- 4 files changed, 179 insertions(+), 140 deletions(-) create mode 100644 libsrc/c64/soft80_charset.s diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 130aca7c5..7d8a1d88f 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -1,4 +1,6 @@ ; +; Groepaz/Hitmen, 11.10.2015 +; ; char cgetc (void); ; diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s new file mode 100644 index 000000000..f44fdaf77 --- /dev/null +++ b/libsrc/c64/soft80_charset.s @@ -0,0 +1,171 @@ +; +; Groepaz/Hitmen, 10.10.2015 +; +; character set for use with the soft80 implementation +; + +; the format of the data follows the following layout: +; +; - to avoid unnecessary petscii->screencode conversions, the order of the +; individual characters is different to the C64 ROM charset: +; - $00 - $1f screencodes $60 - $7f (petscii codes $a0 - $bf) +; - $20 - $3f screencodes $20 - $3f (petscii codes $20 - $3f) +; - $40 - $5f screencodes $00 - $1f (petscii codes $40 - $5f) +; - $60 - $7f screencodes $40 - $5f (petscii codes $60 - $7f) +; - only 128 characters are defined here, the soft80 implementation will invert +; the graphics data for inverted display on the fly. +; - finally the lower 4bits are "inverted", ie a space character is represented +; as $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f +; +; the graphics data is arranged differently to normal C64 charsets for speed, +; first comes the first row of all characters, then the second row in the next +; block, etc. like this: +; +; +000 ....xxxx ......xx ....xxxx ........ +; +080 ....xxxx ......xx ....xxxx ....xxxx +; +100 ....xxxx ......xx ....xxxx ....xxxx +; +180 ....x..x ......xx ....xxxx ....xxxx +; +200 ....x..x ......xx ........ ....xxxx +; +280 ....xxxx ......xx ........ ....xxxx +; +300 ....xxxx ......xx ........ ....xxxx +; +380 ....xxxx ......xx ........ ....xxxx + + .export soft80_charset + + .rodata +soft80_charset: + .byte $0f,$03,$0f,$00,$0f,$07,$05,$0e + .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f + .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 + .byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 + .byte $0f,$0b,$05,$05,$0b,$05,$0b,$0b + .byte $0d,$07,$0f,$0f,$0f,$0f,$0f,$0d + .byte $0b,$0b,$0b,$0b,$05,$01,$0b,$01 + .byte $0b,$0b,$0f,$0f,$0d,$0f,$07,$0b + .byte $0b,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$09,$07,$03,$0b,$0f + .byte $0f,$0b,$03,$0b,$03,$01,$01,$0b + .byte $05,$01,$09,$05,$07,$05,$05,$0b + .byte $03,$0b,$03,$0b,$01,$05,$05,$05 + .byte $05,$05,$01,$0b,$07,$0b,$0f,$0a + + .byte $0f,$03,$0f,$0f,$0f,$07,$05,$0e + .byte $0f,$0a,$0e,$0b,$0f,$0b,$0f,$0f + .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 + .byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 + .byte $0f,$0b,$05,$05,$09,$05,$05,$0b + .byte $0b,$0b,$05,$0b,$0f,$0f,$0f,$0d + .byte $05,$0b,$05,$05,$05,$07,$05,$05 + .byte $05,$05,$0f,$0f,$0b,$0f,$0b,$05 + .byte $05,$0f,$07,$0f,$0d,$0f,$09,$0f + .byte $07,$0b,$0d,$07,$03,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0b,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0b,$07,$0b,$0b,$0b + .byte $0f,$0b,$05,$05,$05,$07,$07,$05 + .byte $05,$0b,$0d,$05,$07,$01,$01,$05 + .byte $05,$05,$05,$05,$0b,$05,$05,$05 + .byte $05,$05,$0d,$0b,$07,$0b,$0f,$0a + + .byte $0f,$03,$0f,$0f,$0f,$07,$0a,$0e + .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f + .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$0f + .byte $00,$0f,$0d,$0f,$0c,$0b,$03,$03 + .byte $0f,$0b,$05,$00,$07,$0d,$0b,$07 + .byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b + .byte $01,$03,$0d,$0d,$05,$03,$07,$0d + .byte $05,$05,$0b,$0b,$0b,$08,$0b,$0d + .byte $01,$0b,$07,$09,$0d,$0b,$0b,$09 + .byte $07,$0f,$0f,$07,$0b,$05,$03,$0b + .byte $03,$09,$03,$09,$01,$05,$05,$05 + .byte $05,$05,$01,$0b,$0b,$0b,$05,$0b + .byte $0f,$05,$05,$07,$05,$07,$07,$07 + .byte $05,$0b,$0d,$03,$07,$01,$01,$05 + .byte $05,$05,$05,$07,$0b,$05,$05,$05 + .byte $0b,$05,$0b,$0b,$0b,$0b,$0a,$05 + + .byte $09,$03,$0f,$0f,$0f,$07,$0a,$0e + .byte $0f,$0a,$0e,$08,$0f,$08,$03,$0f + .byte $08,$00,$00,$03,$07,$07,$0e,$0f + .byte $0f,$0f,$05,$0f,$0c,$03,$03,$03 + .byte $0f,$0b,$0f,$05,$0b,$0b,$0b,$0f + .byte $0b,$0b,$01,$01,$0f,$01,$0f,$0b + .byte $05,$0b,$0b,$0b,$01,$0d,$03,$0b + .byte $0b,$09,$0f,$0f,$07,$0f,$0d,$0b + .byte $01,$0d,$03,$07,$09,$05,$01,$05 + .byte $03,$03,$0d,$05,$0b,$01,$05,$05 + .byte $05,$05,$05,$07,$0b,$05,$05,$05 + .byte $05,$05,$0d,$0b,$0b,$0b,$05,$00 + .byte $00,$01,$03,$07,$05,$03,$03,$01 + .byte $01,$0b,$0d,$03,$07,$05,$01,$05 + .byte $03,$05,$03,$0b,$0b,$05,$05,$01 + .byte $0b,$0b,$0b,$00,$0b,$0b,$05,$05 + + .byte $09,$03,$00,$0f,$0f,$07,$05,$0e + .byte $05,$05,$0e,$08,$0c,$08,$03,$0f + .byte $08,$00,$00,$03,$07,$07,$0e,$0f + .byte $0f,$0f,$03,$03,$0f,$03,$0f,$0c + .byte $0f,$0f,$0f,$00,$0d,$07,$04,$0f + .byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b + .byte $05,$0b,$07,$0d,$0d,$0d,$05,$0b + .byte $05,$0d,$0f,$0f,$0b,$08,$0b,$0b + .byte $07,$09,$05,$07,$05,$01,$0b,$05 + .byte $05,$0b,$0d,$03,$0b,$01,$05,$05 + .byte $05,$05,$07,$0b,$0b,$05,$05,$01 + .byte $0b,$05,$0b,$0b,$0b,$0b,$0f,$00 + .byte $00,$05,$05,$07,$05,$07,$07,$05 + .byte $05,$0b,$0d,$03,$07,$05,$01,$05 + .byte $07,$05,$03,$0d,$0b,$05,$05,$01 + .byte $0b,$0b,$0b,$00,$07,$0b,$05,$0a + + .byte $0f,$03,$00,$0f,$0f,$07,$05,$0e + .byte $05,$0a,$0e,$0b,$0c,$0f,$0b,$0f + .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f + .byte $0f,$00,$03,$03,$0f,$0f,$0f,$0c + .byte $0f,$0f,$0f,$05,$03,$05,$05,$0f + .byte $0b,$0b,$05,$0b,$0b,$0f,$0b,$07 + .byte $05,$0b,$07,$05,$0d,$05,$05,$0b + .byte $05,$05,$0b,$0b,$0b,$0f,$0b,$0f + .byte $05,$05,$05,$07,$05,$07,$0b,$09 + .byte $05,$0b,$0d,$05,$0b,$05,$05,$05 + .byte $03,$09,$07,$0d,$0b,$05,$0b,$01 + .byte $05,$09,$07,$0b,$0d,$0b,$0f,$0b + .byte $0f,$05,$05,$05,$05,$07,$07,$05 + .byte $05,$0b,$05,$05,$07,$05,$05,$05 + .byte $07,$0b,$05,$05,$0b,$05,$0b,$05 + .byte $05,$0b,$07,$0b,$07,$0b,$05,$0a + + .byte $0f,$03,$00,$0f,$0f,$07,$0a,$0e + .byte $0a,$05,$0e,$0b,$0c,$0f,$0b,$00 + .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f + .byte $0f,$00,$07,$03,$0f,$0f,$0f,$0c + .byte $0f,$0b,$0f,$05,$0b,$05,$08,$0f + .byte $0d,$07,$0f,$0f,$0b,$0f,$0b,$07 + .byte $0b,$01,$01,$0b,$0d,$0b,$0b,$0b + .byte $0b,$0b,$0f,$0b,$0d,$0f,$07,$0b + .byte $0b,$09,$03,$09,$09,$09,$0b,$0d + .byte $05,$01,$0d,$05,$01,$05,$05,$0b + .byte $07,$0d,$07,$03,$0d,$09,$0b,$05 + .byte $05,$0d,$01,$09,$0d,$03,$0f,$0b + .byte $0f,$05,$03,$0b,$03,$01,$07,$0b + .byte $05,$01,$0b,$05,$01,$05,$05,$0b + .byte $07,$0d,$05,$0b,$0b,$0b,$0b,$05 + .byte $05,$0b,$01,$0b,$0b,$0b,$05,$05 + + .byte $0f,$03,$00,$0f,$00,$07,$0a,$0e + .byte $0a,$0a,$0e,$0b,$0c,$0f,$0b,$00 + .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f + .byte $0f,$00,$0f,$03,$0f,$0f,$0f,$0c + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$07,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$07,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$03 + .byte $0f,$0f,$03,$0f,$0f,$0f,$0f,$0f + .byte $07,$0d,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$03,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f + .byte $0f,$0f,$0f,$0b,$0b,$0b,$0f,$05 diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 6b909822a..333251854 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -1,11 +1,13 @@ ; -; Low level stuff for screen output/console input +; Groepaz/Hitmen, 11.10.2015 +; +; Low level init code for soft80 screen output/console input ; .constructor soft80_init .destructor soft80_shutdown - .import soft80_kclrscr + .import soft80_kclrscr, soft80_charset .import __textcolor, __bgcolor .importzp ptr1, ptr2, ptr3 @@ -91,140 +93,3 @@ soft80_shutdown: sta VIC_VIDEO_ADR rts - .rodata -soft80_charset: - .byte $0f,$03,$0f,$00,$0f,$07,$05,$0e - .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f - .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 - .byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 - .byte $0f,$0b,$05,$05,$0b,$05,$0b,$0b - .byte $0d,$07,$0f,$0f,$0f,$0f,$0f,$0d - .byte $0b,$0b,$0b,$0b,$05,$01,$0b,$01 - .byte $0b,$0b,$0f,$0f,$0d,$0f,$07,$0b - .byte $0b,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$09,$07,$03,$0b,$0f - .byte $0f,$0b,$03,$0b,$03,$01,$01,$0b - .byte $05,$01,$09,$05,$07,$05,$05,$0b - .byte $03,$0b,$03,$0b,$01,$05,$05,$05 - .byte $05,$05,$01,$0b,$07,$0b,$0f,$0a - - .byte $0f,$03,$0f,$0f,$0f,$07,$05,$0e - .byte $0f,$0a,$0e,$0b,$0f,$0b,$0f,$0f - .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$00 - .byte $00,$0f,$0e,$0f,$0c,$0b,$03,$03 - .byte $0f,$0b,$05,$05,$09,$05,$05,$0b - .byte $0b,$0b,$05,$0b,$0f,$0f,$0f,$0d - .byte $05,$0b,$05,$05,$05,$07,$05,$05 - .byte $05,$05,$0f,$0f,$0b,$0f,$0b,$05 - .byte $05,$0f,$07,$0f,$0d,$0f,$09,$0f - .byte $07,$0b,$0d,$07,$03,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0b,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0b,$07,$0b,$0b,$0b - .byte $0f,$0b,$05,$05,$05,$07,$07,$05 - .byte $05,$0b,$0d,$05,$07,$01,$01,$05 - .byte $05,$05,$05,$05,$0b,$05,$05,$05 - .byte $05,$05,$0d,$0b,$07,$0b,$0f,$0a - - .byte $0f,$03,$0f,$0f,$0f,$07,$0a,$0e - .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f - .byte $0f,$0b,$0f,$0b,$07,$07,$0e,$0f - .byte $00,$0f,$0d,$0f,$0c,$0b,$03,$03 - .byte $0f,$0b,$05,$00,$07,$0d,$0b,$07 - .byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b - .byte $01,$03,$0d,$0d,$05,$03,$07,$0d - .byte $05,$05,$0b,$0b,$0b,$08,$0b,$0d - .byte $01,$0b,$07,$09,$0d,$0b,$0b,$09 - .byte $07,$0f,$0f,$07,$0b,$05,$03,$0b - .byte $03,$09,$03,$09,$01,$05,$05,$05 - .byte $05,$05,$01,$0b,$0b,$0b,$05,$0b - .byte $0f,$05,$05,$07,$05,$07,$07,$07 - .byte $05,$0b,$0d,$03,$07,$01,$01,$05 - .byte $05,$05,$05,$07,$0b,$05,$05,$05 - .byte $0b,$05,$0b,$0b,$0b,$0b,$0a,$05 - - .byte $09,$03,$0f,$0f,$0f,$07,$0a,$0e - .byte $0f,$0a,$0e,$08,$0f,$08,$03,$0f - .byte $08,$00,$00,$03,$07,$07,$0e,$0f - .byte $0f,$0f,$05,$0f,$0c,$03,$03,$03 - .byte $0f,$0b,$0f,$05,$0b,$0b,$0b,$0f - .byte $0b,$0b,$01,$01,$0f,$01,$0f,$0b - .byte $05,$0b,$0b,$0b,$01,$0d,$03,$0b - .byte $0b,$09,$0f,$0f,$07,$0f,$0d,$0b - .byte $01,$0d,$03,$07,$09,$05,$01,$05 - .byte $03,$03,$0d,$05,$0b,$01,$05,$05 - .byte $05,$05,$05,$07,$0b,$05,$05,$05 - .byte $05,$05,$0d,$0b,$0b,$0b,$05,$00 - .byte $00,$01,$03,$07,$05,$03,$03,$01 - .byte $01,$0b,$0d,$03,$07,$05,$01,$05 - .byte $03,$05,$03,$0b,$0b,$05,$05,$01 - .byte $0b,$0b,$0b,$00,$0b,$0b,$05,$05 - - .byte $09,$03,$00,$0f,$0f,$07,$05,$0e - .byte $05,$05,$0e,$08,$0c,$08,$03,$0f - .byte $08,$00,$00,$03,$07,$07,$0e,$0f - .byte $0f,$0f,$03,$03,$0f,$03,$0f,$0c - .byte $0f,$0f,$0f,$00,$0d,$07,$04,$0f - .byte $0b,$0b,$0b,$0b,$0f,$0f,$0f,$0b - .byte $05,$0b,$07,$0d,$0d,$0d,$05,$0b - .byte $05,$0d,$0f,$0f,$0b,$08,$0b,$0b - .byte $07,$09,$05,$07,$05,$01,$0b,$05 - .byte $05,$0b,$0d,$03,$0b,$01,$05,$05 - .byte $05,$05,$07,$0b,$0b,$05,$05,$01 - .byte $0b,$05,$0b,$0b,$0b,$0b,$0f,$00 - .byte $00,$05,$05,$07,$05,$07,$07,$05 - .byte $05,$0b,$0d,$03,$07,$05,$01,$05 - .byte $07,$05,$03,$0d,$0b,$05,$05,$01 - .byte $0b,$0b,$0b,$00,$07,$0b,$05,$0a - - .byte $0f,$03,$00,$0f,$0f,$07,$05,$0e - .byte $05,$0a,$0e,$0b,$0c,$0f,$0b,$0f - .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f - .byte $0f,$00,$03,$03,$0f,$0f,$0f,$0c - .byte $0f,$0f,$0f,$05,$03,$05,$05,$0f - .byte $0b,$0b,$05,$0b,$0b,$0f,$0b,$07 - .byte $05,$0b,$07,$05,$0d,$05,$05,$0b - .byte $05,$05,$0b,$0b,$0b,$0f,$0b,$0f - .byte $05,$05,$05,$07,$05,$07,$0b,$09 - .byte $05,$0b,$0d,$05,$0b,$05,$05,$05 - .byte $03,$09,$07,$0d,$0b,$05,$0b,$01 - .byte $05,$09,$07,$0b,$0d,$0b,$0f,$0b - .byte $0f,$05,$05,$05,$05,$07,$07,$05 - .byte $05,$0b,$05,$05,$07,$05,$05,$05 - .byte $07,$0b,$05,$05,$0b,$05,$0b,$05 - .byte $05,$0b,$07,$0b,$07,$0b,$05,$0a - - .byte $0f,$03,$00,$0f,$0f,$07,$0a,$0e - .byte $0a,$05,$0e,$0b,$0c,$0f,$0b,$00 - .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f - .byte $0f,$00,$07,$03,$0f,$0f,$0f,$0c - .byte $0f,$0b,$0f,$05,$0b,$05,$08,$0f - .byte $0d,$07,$0f,$0f,$0b,$0f,$0b,$07 - .byte $0b,$01,$01,$0b,$0d,$0b,$0b,$0b - .byte $0b,$0b,$0f,$0b,$0d,$0f,$07,$0b - .byte $0b,$09,$03,$09,$09,$09,$0b,$0d - .byte $05,$01,$0d,$05,$01,$05,$05,$0b - .byte $07,$0d,$07,$03,$0d,$09,$0b,$05 - .byte $05,$0d,$01,$09,$0d,$03,$0f,$0b - .byte $0f,$05,$03,$0b,$03,$01,$07,$0b - .byte $05,$01,$0b,$05,$01,$05,$05,$0b - .byte $07,$0d,$05,$0b,$0b,$0b,$0b,$05 - .byte $05,$0b,$01,$0b,$0b,$0b,$05,$05 - - .byte $0f,$03,$00,$0f,$00,$07,$0a,$0e - .byte $0a,$0a,$0e,$0b,$0c,$0f,$0b,$00 - .byte $0b,$0f,$0b,$0b,$07,$07,$0e,$0f - .byte $0f,$00,$0f,$03,$0f,$0f,$0f,$0c - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$07,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$07,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$03 - .byte $0f,$0f,$03,$0f,$0f,$0f,$0f,$0f - .byte $07,$0d,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$03,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0f,$0f,$0f,$0f,$0f - .byte $0f,$0f,$0f,$0b,$0b,$0b,$0f,$05 diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 3ef982aaa..a7662f1ad 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -1,4 +1,6 @@ ; +; Groepaz/Hitmen, 11.10.2015 +; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; @@ -49,7 +51,6 @@ L1: cmp #$0D ; LF? beq soft80_newline ; Recalculate pointers ; Printable char of some sort - tay bpl L10 From 07f1879f85f7cbb1f61f483c14e2ced159062e1f Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 14:40:12 +0200 Subject: [PATCH 272/351] added some more comments and -headers --- libsrc/c64/extra/soft80.s | 4 ++++ libsrc/c64/soft80.inc | 5 +++++ libsrc/c64/soft80_charset.s | 13 ++++++++++++- libsrc/c64/soft80_chline.s | 2 ++ libsrc/c64/soft80_color.s | 2 ++ libsrc/c64/soft80_conio.s | 3 ++- libsrc/c64/soft80_cvline.s | 2 ++ libsrc/c64/soft80_kclrscr.s | 5 +++++ libsrc/c64/soft80_kplot.s | 9 +++++++++ libsrc/c64/soft80_scrsize.s | 5 +++++ 10 files changed, 48 insertions(+), 2 deletions(-) diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index 80ef338b6..d43443fc8 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -1,3 +1,7 @@ +; +; Groepaz/Hitmen, 12.10.2015 +; +; import/overload stubs for the soft80 implementation ; soft80_cgetc.s diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc index f2058f91d..a4bee337a 100644 --- a/libsrc/c64/soft80.inc +++ b/libsrc/c64/soft80.inc @@ -1,3 +1,7 @@ +; +; Groepaz/Hitmen, 12.10.2015 +; +; internal constants for the soft80 implementation soft80_lo_charset = $d000 soft80_hi_charset = $d400 @@ -8,6 +12,7 @@ soft80_bitmap = $e000 charsperline = 80 screenrows = 25 +; FIXME: these should match petscii and perhaps come from a common cbm.inc? CH_ESC = 95 CH_HLINE = 96 CH_CROSS = 123 diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s index f44fdaf77..7a4e10968 100644 --- a/libsrc/c64/soft80_charset.s +++ b/libsrc/c64/soft80_charset.s @@ -1,5 +1,5 @@ ; -; Groepaz/Hitmen, 10.10.2015 +; Groepaz/Hitmen, 12.10.2015 ; ; character set for use with the soft80 implementation ; @@ -14,6 +14,8 @@ ; - $60 - $7f screencodes $40 - $5f (petscii codes $60 - $7f) ; - only 128 characters are defined here, the soft80 implementation will invert ; the graphics data for inverted display on the fly. +; - since the charset is 4 by 8 pixels, only the lower 4bit of each byte is +; used. the upper bits have to be 0. ; - finally the lower 4bits are "inverted", ie a space character is represented ; as $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f ; @@ -29,6 +31,15 @@ ; +280 ....xxxx ......xx ........ ....xxxx ; +300 ....xxxx ......xx ........ ....xxxx ; +380 ....xxxx ......xx ........ ....xxxx +; [...] +; +040 ....x.xx ....xxxx ....xxxx ....xxxx +; +0c0 .....x.x ....xxxx .....xxx ....xxxx +; +140 .......x ....x.xx .....xxx ....x..x +; +1c0 .......x ....xx.x ......xx .....xxx +; +240 .....xxx ....x..x .....x.x .....xxx +; +2c0 .....x.x .....x.x .....x.x .....xxx +; +340 ....x.xx ....x..x ......xx ....x..x +; +3c0 ....xxxx ....xxxx ....xxxx ....xxxx .export soft80_charset diff --git a/libsrc/c64/soft80_chline.s b/libsrc/c64/soft80_chline.s index e15d0c483..73c8c1e26 100644 --- a/libsrc/c64/soft80_chline.s +++ b/libsrc/c64/soft80_chline.s @@ -1,4 +1,6 @@ ; +; Groepaz/Hitmen, 12.10.2015 +; ; void chlinexy (unsigned char x, unsigned char y, unsigned char length); ; void chline (unsigned char length); ; diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index 3d9cca56c..925b161ed 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -1,4 +1,6 @@ ; +; Groepaz/Hitmen, 12.10.2015 +; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); ; unsigned char __fastcall__ bordercolor (unsigned char color); diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 333251854..6691158d7 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -25,7 +25,8 @@ soft80_init: lda #$c8 sta VIC_CTRL2 -; copy charset to RAM under I/O -> FIXME: generate at runtime + ; copy charset to RAM under I/O + ; FIXME: move charset and this constructor into init segment sei lda $01 pha diff --git a/libsrc/c64/soft80_cvline.s b/libsrc/c64/soft80_cvline.s index eaa850118..e2c6e947c 100644 --- a/libsrc/c64/soft80_cvline.s +++ b/libsrc/c64/soft80_cvline.s @@ -1,4 +1,6 @@ ; +; Groepaz/Hitmen, 12.10.2015 +; ; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); ; void cvline (unsigned char length); ; diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index 790aa2749..95633de79 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -1,3 +1,8 @@ +; +; Groepaz/Hitmen, 12.10.2015 +; +; lowlevel kclrscr for soft80 implementation +; .export soft80_kclrscr .import soft80_kplot diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index 6df33c008..e359e9f58 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -1,4 +1,10 @@ +; +; Groepaz/Hitmen, 12.10.2015 +; +; lowlevel kplot function for the soft80 implementation +; + .export soft80_kplot .include "c64.inc" @@ -35,6 +41,9 @@ soft80_kplot: ldy CURS_X rts + ; FIXME: the following tables take up 260 bytes, perhaps move them + ; to 0xdc00... area in ram under i/o + .rodata _bitmapxlo: .repeat 80,col diff --git a/libsrc/c64/soft80_scrsize.s b/libsrc/c64/soft80_scrsize.s index 1873f7327..b0f4f71e7 100644 --- a/libsrc/c64/soft80_scrsize.s +++ b/libsrc/c64/soft80_scrsize.s @@ -1,3 +1,8 @@ +; +; Groepaz/Hitmen, 12.10.2015 +; +; lowlevel screensize function for the soft80 implementation +; .export soft80_screensize From 7f2df8e8e684fc7cfd481327e69939dc39b25b59 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 15:04:55 +0200 Subject: [PATCH 273/351] move internal text/bgcolor variables into the file that also contains the init code for them. also rename them to avoid namespace pollution --- libsrc/c64/soft80_color.s | 24 +++++++++--------------- libsrc/c64/soft80_conio.s | 19 +++++++++++++++---- libsrc/c64/soft80_cputc.s | 25 +++++++++++++++---------- libsrc/c64/soft80_kclrscr.s | 6 +++--- 4 files changed, 42 insertions(+), 32 deletions(-) diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index 925b161ed..51a19f26e 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -7,7 +7,7 @@ ; .export soft80_textcolor, soft80_bgcolor, soft80_bordercolor - .export __textcolor, __bgcolor + .import soft80_internal_textcolor, soft80_internal_bgcolor .importzp tmp1, tmp2 @@ -15,8 +15,8 @@ .include "soft80.inc" soft80_textcolor: - ldx __textcolor ; get old value - sta __textcolor ; set new value + ldx soft80_internal_textcolor ; get old value + sta soft80_internal_textcolor ; set new value jsr mkcharcolor @@ -24,9 +24,9 @@ soft80_textcolor: rts soft80_bgcolor: - ldx __bgcolor ; get old value + ldx soft80_internal_bgcolor ; get old value stx tmp2 ; save old value - sta __bgcolor ; set new value + sta soft80_internal_bgcolor ; set new value jsr mkcharcolor @@ -43,7 +43,7 @@ lp1: and #$0f cmp tmp2 ; old bg color bne @sk1 - lda __bgcolor ; new bg color + lda soft80_internal_bgcolor ; new bg color sta soft80_colram+(page*250),x @sk1: .endscope @@ -69,7 +69,7 @@ lp2: and #$0f cmp tmp2 ; old bg color bne @sk2 - lda __bgcolor ; new bg color + lda soft80_internal_bgcolor ; new bg color @sk2: ora tmp1 ; new bg color (high nibble) sta soft80_vram+(page*250),x @@ -86,13 +86,13 @@ lp2: rts mkcharcolor: - lda __bgcolor + lda soft80_internal_bgcolor asl a asl a asl a asl a sta tmp1 ; remember new bg color (high nibble) - ora __textcolor + ora soft80_internal_textcolor sta CHARCOLOR ; text/bg combo for new chars rts @@ -102,12 +102,6 @@ soft80_bordercolor: txa rts - .bss -__textcolor: - .res 1 -__bgcolor: - .res 1 - ;------------------------------------------------------------------------------- ; force the init constructor to be imported diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 6691158d7..d63f01045 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -8,7 +8,7 @@ .destructor soft80_shutdown .import soft80_kclrscr, soft80_charset - .import __textcolor, __bgcolor + .export soft80_internal_textcolor, soft80_internal_bgcolor .importzp ptr1, ptr2, ptr3 @@ -71,16 +71,16 @@ soft80_init: lda 646 ; use current textcolor and #$0f - sta __textcolor + sta soft80_internal_textcolor lda VIC_BG_COLOR0 ; use current bgcolor and #$0f - sta __bgcolor + sta soft80_internal_bgcolor asl a asl a asl a asl a - ora __textcolor + ora soft80_internal_textcolor sta CHARCOLOR jmp soft80_kclrscr @@ -94,3 +94,14 @@ soft80_shutdown: sta VIC_VIDEO_ADR rts +;------------------------------------------------------------------------------- +; FIXME: when the code is fixed to use the "init" segment, these variables must +; be moved into a section other than .bss so they survive after the init +; code has been run. + + .bss +soft80_internal_textcolor: + .res 1 +soft80_internal_bgcolor: + .res 1 + diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index a7662f1ad..466b25057 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -12,7 +12,7 @@ .import popa, _gotoxy .import xsize .import soft80_kplot - .import __bgcolor, __textcolor + .import soft80_internal_bgcolor, soft80_internal_textcolor .importzp tmp4,tmp3 @@ -70,6 +70,9 @@ L1: cmp #$0D ; LF? and #$7F L10: + ; entry point for direct output of a character. the value passed in + ; akku must match the offset in the charset. + ; - the following may not modify tmp1 soft80_cputdirect: jsr soft80_putchar ; Write the character to the screen @@ -103,6 +106,7 @@ L3: sty CURS_X jmp soft80_plot + ; - the following may not modify tmp1 soft80_newline: lda SCREEN_PTR @@ -204,8 +208,9 @@ _spaceinvers: jmp _back .endif -; output a character - + ; entry point for outputting one character in internal encoding + ; without advancing cursor position + ; - the following may not modify tmp1 soft80_putchar: sta tmp3 ; remember charcode @@ -340,7 +345,7 @@ remcolor: ; immediately. lda (CRAM_PTR),y ; vram (textcolor) and #$0f - cmp __bgcolor + cmp soft80_internal_bgcolor beq @sk1 ; yes, vram==bgcolor ; now check if the textcolor in color ram is equal the background color, @@ -349,7 +354,7 @@ remcolor: lda (CRAM_PTR),y ; colram (2nd textcolor) stx $01 ; $34 and #$0f - cmp __bgcolor + cmp soft80_internal_bgcolor beq @sk2 ; yes, colram==bgcolor ; two characters in the current cell, of which one will get removed @@ -372,7 +377,7 @@ remcolor: sta (CRAM_PTR),y ; vram @sk3: ; colram = bgcolor - lda __bgcolor + lda soft80_internal_bgcolor inc $01 ; $35 sta (CRAM_PTR),y ; colram stx $01 ; $34 @@ -389,7 +394,7 @@ remcolor: ; vram (textcolor) = bgcolor lda (CRAM_PTR),y ; vram and #$f0 - ora __bgcolor + ora soft80_internal_bgcolor sta (CRAM_PTR),y ; vram @sk1: rts @@ -417,7 +422,7 @@ soft80_putcolor: lda (CRAM_PTR),y ; vram and #$0f - cmp __bgcolor + cmp soft80_internal_bgcolor beq @sk1 ; vram==bgcolor => first char in cell ; vram!=bgcolor => second char in cell @@ -426,7 +431,7 @@ soft80_putcolor: lda (CRAM_PTR),y ; colram stx $01 ; $34 and #$0f - cmp __bgcolor + cmp soft80_internal_bgcolor beq @l2s ; colram==bgcolor -> second char in cell ; botch characters in the cell are used @@ -450,7 +455,7 @@ soft80_putcolor: beq @sk3 ; jump if even xpos @sk2: ; colram = textcol - lda __textcolor + lda soft80_internal_textcolor inc $01 ; $35 sta (CRAM_PTR),y ; colram stx $01 ; $34 diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index 95633de79..0b438be6b 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -6,7 +6,7 @@ .export soft80_kclrscr .import soft80_kplot - .import __bgcolor + .import soft80_internal_bgcolor .importzp ptr1 .include "c64.inc" @@ -39,7 +39,7 @@ soft80_kclrscr: bne @lp3 .if SOFT80COLORVOODOO = 1 - lda __bgcolor + lda soft80_internal_bgcolor jsr clear ; clear color ram .endif @@ -50,7 +50,7 @@ soft80_kclrscr: lda CHARCOLOR and #$f0 - ora __bgcolor + ora soft80_internal_bgcolor jsr clear ; clear vram sty $01 From 2a0f6c420b37c0ae6d14f8a6b91e95fc67682b74 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 15:18:36 +0200 Subject: [PATCH 274/351] moved bordercolor function into a seperate file --- libsrc/c64/extra/soft80.s | 4 +++- libsrc/c64/soft80_bordercolor.s | 17 +++++++++++++++++ libsrc/c64/soft80_color.s | 9 +-------- 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 libsrc/c64/soft80_bordercolor.s diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index d43443fc8..162abb132 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -17,9 +17,11 @@ ; soft80_color.s .import soft80_textcolor .import soft80_bgcolor - .import soft80_bordercolor .export _textcolor := soft80_textcolor .export _bgcolor := soft80_bgcolor + + ; soft80_bordercolor.s + .import soft80_bordercolor .export _bordercolor := soft80_bordercolor ; soft80_cputc.s diff --git a/libsrc/c64/soft80_bordercolor.s b/libsrc/c64/soft80_bordercolor.s new file mode 100644 index 000000000..057cc410a --- /dev/null +++ b/libsrc/c64/soft80_bordercolor.s @@ -0,0 +1,17 @@ +; +; Groepaz/Hitmen, 12.10.2015 +; +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + .export soft80_bordercolor + + .include "c64.inc" + + ; FIXME: if we'd move this function into a seperate file in the regular + ; conio lib, then we dont need this override at all. +soft80_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index 51a19f26e..2d856508c 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -3,10 +3,9 @@ ; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); -; unsigned char __fastcall__ bordercolor (unsigned char color); ; - .export soft80_textcolor, soft80_bgcolor, soft80_bordercolor + .export soft80_textcolor, soft80_bgcolor .import soft80_internal_textcolor, soft80_internal_bgcolor .importzp tmp1, tmp2 @@ -96,12 +95,6 @@ mkcharcolor: sta CHARCOLOR ; text/bg combo for new chars rts -soft80_bordercolor: - ldx VIC_BORDERCOLOR ; get old value - sta VIC_BORDERCOLOR ; set new value - txa - rts - ;------------------------------------------------------------------------------- ; force the init constructor to be imported From 21732e3c5bf540126278848fa1f4d4a60f32013b Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 15:44:41 +0200 Subject: [PATCH 275/351] maintain lsb of cursor x position internally, saves some bytes and some cycles too :) --- libsrc/c64/soft80_cgetc.s | 8 ++++--- libsrc/c64/soft80_conio.s | 3 +++ libsrc/c64/soft80_cputc.s | 42 +++++++++++++++++++++++-------------- libsrc/c64/soft80_kplot.s | 5 +++++ libsrc/c64/soft80_scrsize.s | 6 ------ 5 files changed, 39 insertions(+), 25 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 7d8a1d88f..7bb67f0ae 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -5,6 +5,7 @@ ; .export soft80_cgetc + .import soft80_internal_cursorxlsb .import cursor .importzp tmp1 @@ -45,9 +46,10 @@ invertcursor: ldy #$00 jsr setcolor - lda CURS_X - and #$01 - tax + ;lda CURS_X + ;and #$01 + ;tax + ldx soft80_internal_cursorxlsb @lp1: lda (SCREEN_PTR),y eor nibble,x diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index d63f01045..344831447 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -9,6 +9,7 @@ .import soft80_kclrscr, soft80_charset .export soft80_internal_textcolor, soft80_internal_bgcolor + .export soft80_internal_cursorxlsb .importzp ptr1, ptr2, ptr3 @@ -104,4 +105,6 @@ soft80_internal_textcolor: .res 1 soft80_internal_bgcolor: .res 1 +soft80_internal_cursorxlsb: + .res 1 diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 466b25057..4f2eb7ada 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -13,6 +13,7 @@ .import xsize .import soft80_kplot .import soft80_internal_bgcolor, soft80_internal_textcolor + .import soft80_internal_cursorxlsb .importzp tmp4,tmp3 @@ -86,6 +87,7 @@ advance: sty CURS_X tya and #$01 + sta soft80_internal_cursorxlsb bne @L5 lda SCREEN_PTR @@ -146,8 +148,9 @@ _space: .endif ;ldy #$00 ; is still $00 - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb bne @l1 .repeat 8,line @@ -182,8 +185,9 @@ _spaceinvers: sta (CRAM_PTR),y ; vram .endif - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb bne @l1 .repeat 8,line @@ -240,8 +244,9 @@ soft80_putchar: lda RVS jne _invers - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb bne @l1 .repeat 8,line @@ -279,8 +284,9 @@ _back: ; output inverted character _invers: - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb bne @l1 .repeat 8,line @@ -366,8 +372,9 @@ remcolor: ;and #$0f sta tmp3 ; A contains colram - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb bne @sk3 ; vram = colram @@ -436,8 +443,9 @@ soft80_putcolor: ; botch characters in the cell are used - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb bne @sk2 ; jump if odd xpos ; vram = textcol @@ -450,8 +458,9 @@ soft80_putcolor: jsr soft80_checkchar bcs @sk1 ; char at current position => overwrite 1st - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb beq @sk3 ; jump if even xpos @sk2: ; colram = textcol @@ -481,8 +490,9 @@ soft80_checkchar: ;ldy #$00 ; is still $00 - lda CURS_X - and #$01 + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb jne @l1a .repeat 8,line diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index e359e9f58..8d8c77c5c 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -6,6 +6,7 @@ ; .export soft80_kplot + .import soft80_internal_cursorxlsb .include "c64.inc" .include "soft80.inc" @@ -25,6 +26,10 @@ soft80_kplot: adc _bitmapxhi,y sta SCREEN_PTR+1 + tya + and #1 + sta soft80_internal_cursorxlsb + ; calc pointer to vram tya lsr a ; NOTE: we can save 2 cycles here at the expense of diff --git a/libsrc/c64/soft80_scrsize.s b/libsrc/c64/soft80_scrsize.s index b0f4f71e7..9f1701a9a 100644 --- a/libsrc/c64/soft80_scrsize.s +++ b/libsrc/c64/soft80_scrsize.s @@ -12,9 +12,3 @@ soft80_screensize: ldy #screenrows ldx #charsperline rts - -;------------------------------------------------------------------------------- -; force the init constructor to be imported - - .import soft80_init -conio_init = soft80_init From a2b514a7cff1512ecce4dd4074440324044b3c0d Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 15:54:08 +0200 Subject: [PATCH 276/351] fix some style issues --- libsrc/c64/soft80_color.s | 32 ++++++++++++++++---------------- libsrc/c64/soft80_conio.s | 4 ++-- libsrc/c64/soft80_kclrscr.s | 6 +++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index 2d856508c..fe2be71d5 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -14,18 +14,18 @@ .include "soft80.inc" soft80_textcolor: - ldx soft80_internal_textcolor ; get old value - sta soft80_internal_textcolor ; set new value + ldx soft80_internal_textcolor ; get old value + sta soft80_internal_textcolor ; set new value jsr mkcharcolor - txa ; get old value + txa ; get old value rts soft80_bgcolor: - ldx soft80_internal_bgcolor ; get old value - stx tmp2 ; save old value - sta soft80_internal_bgcolor ; set new value + ldx soft80_internal_bgcolor ; get old value + stx tmp2 ; save old value + sta soft80_internal_bgcolor ; set new value jsr mkcharcolor @@ -40,9 +40,9 @@ lp1: .scope lda soft80_colram+(page*250),x and #$0f - cmp tmp2 ; old bg color + cmp tmp2 ; old bg color bne @sk1 - lda soft80_internal_bgcolor ; new bg color + lda soft80_internal_bgcolor ; new bg color sta soft80_colram+(page*250),x @sk1: .endscope @@ -54,7 +54,7 @@ lp1: sei ldy $01 - lda #$34 ; disable I/O + lda #$34 ; disable I/O sta $01 ; if the old bg color is equal to text color in this cell, then also @@ -66,11 +66,11 @@ lp2: .scope lda soft80_vram+(page*250),x and #$0f - cmp tmp2 ; old bg color + cmp tmp2 ; old bg color bne @sk2 - lda soft80_internal_bgcolor ; new bg color + lda soft80_internal_bgcolor ; new bg color @sk2: - ora tmp1 ; new bg color (high nibble) + ora tmp1 ; new bg color (high nibble) sta soft80_vram+(page*250),x .endscope .endrepeat @@ -78,10 +78,10 @@ lp2: inx bne lp2 - sty $01 ; enable I/O + sty $01 ; enable I/O cli - lda tmp2 ; get old value + lda tmp2 ; get old value rts mkcharcolor: @@ -90,9 +90,9 @@ mkcharcolor: asl a asl a asl a - sta tmp1 ; remember new bg color (high nibble) + sta tmp1 ; remember new bg color (high nibble) ora soft80_internal_textcolor - sta CHARCOLOR ; text/bg combo for new chars + sta CHARCOLOR ; text/bg combo for new chars rts ;------------------------------------------------------------------------------- diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 344831447..bc4d5c0ab 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -70,11 +70,11 @@ soft80_init: sta $01 cli - lda 646 ; use current textcolor + lda 646 ; use current textcolor and #$0f sta soft80_internal_textcolor - lda VIC_BG_COLOR0 ; use current bgcolor + lda VIC_BG_COLOR0 ; use current bgcolor and #$0f sta soft80_internal_bgcolor asl a diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index 0b438be6b..811ea665f 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -40,18 +40,18 @@ soft80_kclrscr: .if SOFT80COLORVOODOO = 1 lda soft80_internal_bgcolor - jsr clear ; clear color ram + jsr clear ; clear color ram .endif sei ldy $01 - lda #$34 ; enable RAM under I/O + lda #$34 ; enable RAM under I/O sta $01 lda CHARCOLOR and #$f0 ora soft80_internal_bgcolor - jsr clear ; clear vram + jsr clear ; clear vram sty $01 cli From bc85d90468f6375d8ee426c9645940f07f8da241 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 16:15:40 +0200 Subject: [PATCH 277/351] check for space bottom up, which is faster for the average case --- libsrc/c64/soft80_cputc.s | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 4f2eb7ada..9f27f64d7 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -482,30 +482,39 @@ soft80_putcolor: sta (CRAM_PTR),y ; vram rts +; ; test if there is a space or a character at current position -; in: y must be $00 +; +; in: x = $34 +; y must be $00 ; out: CLC: space SEC: character +; x = $34 ; y = $00 soft80_checkchar: - ;ldy #$00 ; is still $00 + ;ldy #$00 ; is still $00 ;lda CURS_X ;and #$01 lda soft80_internal_cursorxlsb - jne @l1a + bne @l1a + ; check charset data from bottom up, since a lot of eg lowercase chars + ; have no data in the top rows, but all of the DO have data in the + ; second to bottom row, this will likely be faster in average. + + ldy #7 .repeat 8,line lda (SCREEN_PTR),y and #$f0 cmp #$f0 bne @l2b .if (line < 7) - iny + dey .endif .endrepeat - ldy #$00 + ;ldy #$00 ; is 0 clc rts @l2b: @@ -513,16 +522,17 @@ soft80_checkchar: sec rts @l1a: + ldy #$07 .repeat 8,line lda (SCREEN_PTR),y and #$0f cmp #$0f bne @l2bb .if line < 7 - iny + dey .endif .endrepeat - ldy #$00 + ;ldy #$00 ; is 0 clc rts @l2bb: From cf8b21b27ef84f35a14407f724df66a6c23f2406 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 17:12:44 +0200 Subject: [PATCH 278/351] size optimization --- libsrc/c64/soft80_cgetc.s | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 7bb67f0ae..e578111ea 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -16,13 +16,13 @@ soft80_cgetc: lda KEY_COUNT ; Get number of characters bne L3 ; Jump if there are already chars waiting - ldx #1 + sec jsr invertcursor ; set cursor on or off accordingly L1: lda KEY_COUNT ; wait for key beq L1 - ldx #0 + clc jsr invertcursor ; set cursor on or off accordingly L3: jsr KBDREAD ; Read char and return in A @@ -59,7 +59,7 @@ invertcursor: bne @lp1 pla - sta $01 + sta $01 ; enable I/O cli rts @@ -68,8 +68,7 @@ invertcursor: ; in soft80_cputc setcolor: ;ldy #0 ; is 0 - txa - bne @set + bcs @set ; restore old value lda tmp1 sta (CRAM_PTR),y ; vram From ead9950044034660f20e1fea8c7efd0558c2a750 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 18:01:48 +0200 Subject: [PATCH 279/351] some code shuffling to get rid of long branches --- libsrc/c64/soft80_conio.s | 4 + libsrc/c64/soft80_cputc.s | 188 ++++++++++++++++++++------------------ 2 files changed, 102 insertions(+), 90 deletions(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index bc4d5c0ab..388f53023 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -70,6 +70,10 @@ soft80_init: sta $01 cli + ; the "color voodoo" in other parts of the code relies on the vram and + ; colorram being set up as expected, which is why we cant use the + ; _bgcolor and _textcolor functions here. + lda 646 ; use current textcolor and #$0f sta soft80_internal_textcolor diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 9f27f64d7..fa6a2574f 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -10,22 +10,16 @@ .export soft80_newline, soft80_plot .import popa, _gotoxy - .import xsize + .import soft80_kplot .import soft80_internal_bgcolor, soft80_internal_textcolor .import soft80_internal_cursorxlsb .importzp tmp4,tmp3 - .macpack longbranch - .include "c64.inc" .include "soft80.inc" -.if SOFT80COLORVOODOO = 1 - .export soft80_putcolor -.endif - soft80_cputcxy: pha ; Save C jsr popa ; Get Y @@ -51,10 +45,18 @@ soft80_plot: L1: cmp #$0D ; LF? beq soft80_newline ; Recalculate pointers - ; Printable char of some sort + ; shortcut for codes < $80 ... codes $20-$7f can be printed directly, + ; codes $00-$1f are control codes which are not printable and thus may + ; give undefined result. tay bpl L10 + ; codes $80-$ff must get converted like this: + ; $80-$9f -> dont care (control codes) + ; $a0-$bf -> $00-$1f + ; $c0-$df -> $60-$7f + ; $e0-$ff -> $00-$1f + ; extra check for petscii codes 160-191, these have been moved to ; 0-31 in the charset and #%11100000 @@ -77,9 +79,7 @@ L10: soft80_cputdirect: jsr soft80_putchar ; Write the character to the screen -; Advance cursor position - -advance: + ; Advance cursor position iny ; contains CURS_X cpy #charsperline beq L3 @@ -130,53 +130,29 @@ L5: inc CURS_Y rts -; Write one character to the screen without doing anything else -; in: A: character -; returns: Y: cursor X position -; this function is going to be used a lot so we unroll it a bit for speed +;------------------------------------------------------------------------------- +; All following code belongs to the character output to bitmap +; +; this stuff is going to be used a lot so we unroll it a bit for speed +;------------------------------------------------------------------------------- .if SOFT80FASTSPACE = 1 -; output space -; in: y must be $00 -_space: - - lda RVS - jne _spaceinvers - -.if SOFT80COLORVOODOO = 1 - jsr remcolor -.endif - ;ldy #$00 ; is still $00 - - ;lda CURS_X - ;and #$01 - lda soft80_internal_cursorxlsb - bne @l1 +; output inverted space (odd) +draw_spaceinvers_odd: .repeat 8,line lda (SCREEN_PTR),y - ora #$f0 - sta (SCREEN_PTR),y - .if (line < 7) - iny - .endif - .endrepeat - jmp _back -@l1: - .repeat 8,line - lda (SCREEN_PTR),y - ora #$0f + and #$f0 sta (SCREEN_PTR),y .if line < 7 iny .endif .endrepeat -@l2: - jmp _back + jmp draw_back -; output inverted space +; output inverted space (general entry point) ; in: y must be $00 -_spaceinvers: +draw_spaceinvers: .if SOFT80COLORVOODOO = 1 jsr soft80_putcolor @@ -188,8 +164,9 @@ _spaceinvers: ;lda CURS_X ;and #$01 lda soft80_internal_cursorxlsb - bne @l1 + bne draw_spaceinvers_odd +; output inverted space (even) .repeat 8,line lda (SCREEN_PTR),y and #$0f @@ -198,23 +175,57 @@ _spaceinvers: iny .endif .endrepeat - jmp _back -@l1: + jmp draw_back + +; output space (odd) +draw_space_odd: .repeat 8,line lda (SCREEN_PTR),y - and #$f0 + ora #$0f sta (SCREEN_PTR),y .if line < 7 iny .endif .endrepeat + jmp draw_back - jmp _back +; output space (general entry point) +; in: y must be $00 +draw_space: + + lda RVS + bne draw_spaceinvers + +.if SOFT80COLORVOODOO = 1 + jsr remcolor +.endif + ;ldy #$00 ; is still $00 + + ;lda CURS_X + ;and #$01 + lda soft80_internal_cursorxlsb + bne draw_space_odd + +; output space (even) + .repeat 8,line + lda (SCREEN_PTR),y + ora #$f0 + sta (SCREEN_PTR),y + .if (line < 7) + iny + .endif + .endrepeat + jmp draw_back .endif - ; entry point for outputting one character in internal encoding - ; without advancing cursor position - ; - the following may not modify tmp1 +;------------------------------------------------------------------------------- +; output one character in internal encoding without advancing cursor position +; generic entry point +; +; - the following may not modify tmp1 +; in: A: charcode +; out: Y: CURS_X +; soft80_putchar: sta tmp3 ; remember charcode @@ -228,7 +239,7 @@ soft80_putchar: .if SOFT80FASTSPACE = 1 cmp #' ' ; space is a special (optimized) case - jeq _space + beq draw_space .endif .if SOFT80COLORVOODOO = 1 @@ -237,18 +248,18 @@ soft80_putchar: lda CHARCOLOR sta (CRAM_PTR),y ; vram .endif - ; output character +; output character ldx tmp3 ; get charcode lda RVS - jne _invers - - ;lda CURS_X - ;and #$01 + beq @skp + jmp draw_charinvers +@skp: lda soft80_internal_cursorxlsb - bne @l1 + bne draw_char_even +; output character (odd) .repeat 8,line lda (SCREEN_PTR),y and #$0f @@ -258,9 +269,10 @@ soft80_putchar: iny .endif .endrepeat - jmp @l2 -@l1: + jmp draw_back +; output character (even) +draw_char_even: .repeat 8,line lda (SCREEN_PTR),y and #$f0 @@ -271,9 +283,7 @@ soft80_putchar: .endif .endrepeat -@l2: - -_back: +draw_back: lda tmp4 sta $01 cli @@ -281,13 +291,23 @@ _back: ldy CURS_X rts -; output inverted character -_invers: +; output inverted character (odd) +draw_charinvers_odd: + .repeat 8,line + lda (SCREEN_PTR),y + ora #$0f + eor soft80_lo_charset+(line*$80),x + sta (SCREEN_PTR),y + .if line < 7 + iny + .endif + .endrepeat + jmp draw_back - ;lda CURS_X - ;and #$01 +; output inverted character (generic) +draw_charinvers: lda soft80_internal_cursorxlsb - bne @l1 + bne draw_charinvers_odd .repeat 8,line lda (SCREEN_PTR),y @@ -298,18 +318,7 @@ _invers: iny .endif .endrepeat - jmp _back -@l1: - .repeat 8,line - lda (SCREEN_PTR),y - ora #$0f - eor soft80_lo_charset+(line*$80),x - sta (SCREEN_PTR),y - .if line < 7 - iny - .endif - .endrepeat - jmp _back + jmp draw_back ;------------------------------------------------------------------------------- ; optional "color voodoo". the problem is that each 8x8 cell can only contain @@ -500,7 +509,7 @@ soft80_checkchar: bne @l1a ; check charset data from bottom up, since a lot of eg lowercase chars - ; have no data in the top rows, but all of the DO have data in the + ; have no data in the top rows, but all of them DO have data in the ; second to bottom row, this will likely be faster in average. ldy #7 @@ -513,7 +522,6 @@ soft80_checkchar: dey .endif .endrepeat - ;ldy #$00 ; is 0 clc rts @@ -527,7 +535,7 @@ soft80_checkchar: lda (SCREEN_PTR),y and #$0f cmp #$0f - bne @l2bb + bne @l2b .if line < 7 dey .endif @@ -535,9 +543,9 @@ soft80_checkchar: ;ldy #$00 ; is 0 clc rts -@l2bb: - ldy #$00 - sec - rts +;@l2bb: +; ldy #$00 +; sec +; rts .endif From aed0549760322d20afb27d99b50659e972498d2c Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 18:09:50 +0200 Subject: [PATCH 280/351] remove some commented out code --- libsrc/c64/soft80_cgetc.s | 4 +--- libsrc/c64/soft80_color.s | 3 ++- libsrc/c64/soft80_cputc.s | 23 +++-------------------- 3 files changed, 6 insertions(+), 24 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index e578111ea..849af753a 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -46,9 +46,6 @@ invertcursor: ldy #$00 jsr setcolor - ;lda CURS_X - ;and #$01 - ;tax ldx soft80_internal_cursorxlsb @lp1: lda (SCREEN_PTR),y @@ -74,6 +71,7 @@ setcolor: sta (CRAM_PTR),y ; vram rts @set: + ; save old value lda (CRAM_PTR),y ; vram sta tmp1 lda CHARCOLOR diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index fe2be71d5..ab4b4a01f 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -24,11 +24,12 @@ soft80_textcolor: soft80_bgcolor: ldx soft80_internal_bgcolor ; get old value - stx tmp2 ; save old value sta soft80_internal_bgcolor ; set new value jsr mkcharcolor + stx tmp2 ; save old value + .if SOFT80COLORVOODOO = 1 ; if the old bg color is equal to color ram of that cell, then also ; update the color ram to the new value. diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index fa6a2574f..0d450d27b 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -161,8 +161,6 @@ draw_spaceinvers: sta (CRAM_PTR),y ; vram .endif - ;lda CURS_X - ;and #$01 lda soft80_internal_cursorxlsb bne draw_spaceinvers_odd @@ -201,8 +199,6 @@ draw_space: .endif ;ldy #$00 ; is still $00 - ;lda CURS_X - ;and #$01 lda soft80_internal_cursorxlsb bne draw_space_odd @@ -381,8 +377,6 @@ remcolor: ;and #$0f sta tmp3 ; A contains colram - ;lda CURS_X - ;and #$01 lda soft80_internal_cursorxlsb bne @sk3 @@ -452,8 +446,6 @@ soft80_putcolor: ; botch characters in the cell are used - ;lda CURS_X - ;and #$01 lda soft80_internal_cursorxlsb bne @sk2 ; jump if odd xpos @@ -467,8 +459,6 @@ soft80_putcolor: jsr soft80_checkchar bcs @sk1 ; char at current position => overwrite 1st - ;lda CURS_X - ;and #$01 lda soft80_internal_cursorxlsb beq @sk3 ; jump if even xpos @sk2: @@ -503,8 +493,6 @@ soft80_checkchar: ;ldy #$00 ; is still $00 - ;lda CURS_X - ;and #$01 lda soft80_internal_cursorxlsb bne @l1a @@ -517,7 +505,7 @@ soft80_checkchar: lda (SCREEN_PTR),y and #$f0 cmp #$f0 - bne @l2b + bne @ischar .if (line < 7) dey .endif @@ -525,7 +513,7 @@ soft80_checkchar: ;ldy #$00 ; is 0 clc rts -@l2b: +@ischar: ldy #$00 sec rts @@ -535,7 +523,7 @@ soft80_checkchar: lda (SCREEN_PTR),y and #$0f cmp #$0f - bne @l2b + bne @ischar .if line < 7 dey .endif @@ -543,9 +531,4 @@ soft80_checkchar: ;ldy #$00 ; is 0 clc rts -;@l2bb: -; ldy #$00 -; sec -; rts - .endif From 4557e8d004844dd8c24ec3587d1f9c54851d6ba7 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 18:53:55 +0200 Subject: [PATCH 281/351] optimize charcode conversion, shorter and faster now :) --- libsrc/c64/soft80_cputc.s | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 0d450d27b..e336e1c7c 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -49,7 +49,7 @@ L1: cmp #$0D ; LF? ; codes $00-$1f are control codes which are not printable and thus may ; give undefined result. tay - bpl L10 + bpl @L10 ; codes $80-$ff must get converted like this: ; $80-$9f -> dont care (control codes) @@ -57,21 +57,11 @@ L1: cmp #$0D ; LF? ; $c0-$df -> $60-$7f ; $e0-$ff -> $00-$1f - ; extra check for petscii codes 160-191, these have been moved to - ; 0-31 in the charset - and #%11100000 - cmp #%10100000 - bne @sk - - tya - and #%00011111 - bpl L10 ; branch always -@sk: - tya + ora #%01000000 ; $40 clc - adc #$20 - and #$7F -L10: + adc #%00100000 ; $20 + and #%01111111 ; $7f +@L10: ; entry point for direct output of a character. the value passed in ; akku must match the offset in the charset. From bf3ea5328f13ced74f497efdf680dec0eb9d7781 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 19:03:50 +0200 Subject: [PATCH 282/351] inverted result for checkchar, saving some bytes and cycles --- libsrc/c64/soft80_cputc.s | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index e336e1c7c..c7ba6e096 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -389,7 +389,7 @@ remcolor: ; => only one char in cell used jsr soft80_checkchar - bcc @sk1 ; space at current position + bcs @sk1 ; space at current position ; vram (textcolor) = bgcolor lda (CRAM_PTR),y ; vram @@ -447,7 +447,7 @@ soft80_putcolor: @l2s: ; one character in cell is already used jsr soft80_checkchar - bcs @sk1 ; char at current position => overwrite 1st + bcc @sk1 ; char at current position => overwrite 1st lda soft80_internal_cursorxlsb beq @sk3 ; jump if even xpos @@ -476,7 +476,8 @@ soft80_putcolor: ; ; in: x = $34 ; y must be $00 -; out: CLC: space SEC: character +; out: SEC: space +; CLC: character ; x = $34 ; y = $00 soft80_checkchar: @@ -501,11 +502,11 @@ soft80_checkchar: .endif .endrepeat ;ldy #$00 ; is 0 - clc + ;sec ; is set rts @ischar: ldy #$00 - sec + ;clc ; is cleared rts @l1a: ldy #$07 @@ -519,6 +520,6 @@ soft80_checkchar: .endif .endrepeat ;ldy #$00 ; is 0 - clc + ;sec ; is set rts .endif From e9f0b7943eed63fc533c24976abd7e9ecc66be44 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 19:57:33 +0200 Subject: [PATCH 283/351] some renaming, preparing plot table names --- libsrc/c64/soft80_cputc.s | 21 ++++++++------------- libsrc/c64/soft80_kplot.s | 29 ++++++++++++++--------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index c7ba6e096..0e8cb0bd8 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -72,7 +72,7 @@ soft80_cputdirect: ; Advance cursor position iny ; contains CURS_X cpy #charsperline - beq L3 + beq @L3 sty CURS_X tya @@ -92,7 +92,7 @@ soft80_cputdirect: inc CRAM_PTR+1 @L5: rts -L3: +@L3: inc CURS_Y ; new line ldy #0 ; + cr sty CURS_X @@ -114,9 +114,9 @@ soft80_newline: clc adc #40 sta CRAM_PTR - bcc L5 + bcc @L5 inc CRAM_PTR+1 -L5: +@L5: inc CURS_Y rts @@ -336,7 +336,8 @@ draw_charinvers: ; ; in: x must be $34 ; y must be $00 -; out: y = $00 +; out: x = $34 +; y = $00 remcolor: ;ldy #$00 ; is still $00 @@ -357,23 +358,17 @@ remcolor: and #$0f cmp soft80_internal_bgcolor beq @sk2 ; yes, colram==bgcolor + sta tmp3 ; A contains colram ; two characters in the current cell, of which one will get removed - ; vram = colram - ;inc $01 - ;lda (CRAM_PTR),y ; colram - ;stx $01 ;$34 - ;and #$0f - sta tmp3 ; A contains colram - lda soft80_internal_cursorxlsb bne @sk3 ; vram = colram lda (CRAM_PTR),y ; vram and #$f0 - ora tmp3 + ora tmp3 ; colram value sta (CRAM_PTR),y ; vram @sk3: ; colram = bgcolor diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index 8d8c77c5c..79a14cbcb 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -18,12 +18,12 @@ soft80_kplot: sty CURS_X ; calc pointer to bitmap - lda _bitmaplo,x + lda soft80_bitmapylo,x clc - adc _bitmapxlo,y + adc soft80_bitmapxlo,y sta SCREEN_PTR - lda _bitmaphi,x - adc _bitmapxhi,y + lda soft80_bitmapyhi,x + adc soft80_bitmapxhi,y sta SCREEN_PTR+1 tya @@ -32,13 +32,13 @@ soft80_kplot: ; calc pointer to vram tya - lsr a ; NOTE: we can save 2 cycles here at the expense of - ; making the tables twice as big (+50 bytes) + lsr a + clc - adc _vramlo,x + adc soft80_vramlo,x sta CRAM_PTR lda #0 - adc _vramhi,x + adc soft80_vramhi,x sta CRAM_PTR+1 @getpos: @@ -50,28 +50,27 @@ soft80_kplot: ; to 0xdc00... area in ram under i/o .rodata -_bitmapxlo: +soft80_bitmapxlo: .repeat 80,col .byte <((col/2)*8) .endrepeat - -_bitmapxhi: +soft80_bitmapxhi: .repeat 80,col .byte >((col/2)*8) .endrepeat -_vramlo: +soft80_vramlo: .repeat 25,row .byte <(soft80_vram+(row*40)) .endrepeat -_vramhi: +soft80_vramhi: .repeat 25,row .byte >(soft80_vram+(row*40)) .endrepeat -_bitmaplo: +soft80_bitmapylo: .repeat 25,row .byte <(soft80_bitmap+(row*40*8)) .endrepeat -_bitmaphi: +soft80_bitmapyhi: .repeat 25,row .byte >(soft80_bitmap+(row*40*8)) .endrepeat From 08efc299ffacac0e13296a33e50ef64be99358e3 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Mon, 12 Oct 2015 20:18:13 +0200 Subject: [PATCH 284/351] Allow to override mouse sprite location data. --- libsrc/c64/mcbdefault.s | 21 +++++++++++++++++---- libsrc/c64/mcbspritedata.s | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 libsrc/c64/mcbspritedata.s diff --git a/libsrc/c64/mcbdefault.s b/libsrc/c64/mcbdefault.s index c4feddfea..cd36d8515 100644 --- a/libsrc/c64/mcbdefault.s +++ b/libsrc/c64/mcbdefault.s @@ -11,6 +11,8 @@ .export _mouse_def_callbacks .import _mouse_def_pointershape .import _mouse_def_pointercolor + .import mcb_spritememory + .import mcb_spritepointer .include "mouse-kernel.inc" .include "c64.inc" @@ -20,7 +22,6 @@ ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse -MOUSE_SPR_MEM = $0340 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register @@ -33,18 +34,30 @@ VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register initmcb: +; Make all RAM accessible + + lda #$30 + ldy $01 + sei + sta $01 + ; Copy the mouse sprite data ldx #64 - 1 @L0: lda _mouse_def_pointershape,x - sta MOUSE_SPR_MEM,x + sta mcb_spritememory,x dex bpl @L0 ; Set the mouse sprite pointer - lda #<(MOUSE_SPR_MEM / 64) - sta $07F8 + MOUSE_SPR + lda #<(mcb_spritememory / 64) + sta mcb_spritepointer + MOUSE_SPR + +; Restore memory configuration + + sty $01 + cli ; Set the mouse sprite color diff --git a/libsrc/c64/mcbspritedata.s b/libsrc/c64/mcbspritedata.s new file mode 100644 index 000000000..2c7aa1491 --- /dev/null +++ b/libsrc/c64/mcbspritedata.s @@ -0,0 +1,4 @@ +; VIC sprite data for the mouse pointer + + .export mcb_spritememory := $0340 + .export mcb_spritepointer := $07F8 From 57a43b673587fe25b9ca741e9247c5da8d7af8a1 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 20:38:06 +0200 Subject: [PATCH 285/351] style issues --- libsrc/c64/soft80_cgetc.s | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 849af753a..ba16614af 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -14,18 +14,18 @@ soft80_cgetc: lda KEY_COUNT ; Get number of characters - bne L3 ; Jump if there are already chars waiting + bne @L3 ; Jump if there are already chars waiting sec jsr invertcursor ; set cursor on or off accordingly -L1: lda KEY_COUNT ; wait for key - beq L1 +@L1: lda KEY_COUNT ; wait for key + beq @L1 clc jsr invertcursor ; set cursor on or off accordingly -L3: jsr KBDREAD ; Read char and return in A +@L3: jsr KBDREAD ; Read char and return in A ldx #0 rts From 5840d1c08c6e1f1ba16c821c1ecb9ab93f24e176 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 20:46:53 +0200 Subject: [PATCH 286/351] increase conio constructor priority --- libsrc/c64/soft80_conio.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 388f53023..f6efe3382 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -4,7 +4,7 @@ ; Low level init code for soft80 screen output/console input ; - .constructor soft80_init + .constructor soft80_init, 8 .destructor soft80_shutdown .import soft80_kclrscr, soft80_charset From d6f48629ad22803dc260e9c659c81b357a82c70e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 21:02:48 +0200 Subject: [PATCH 287/351] export mouse driver related symbols --- libsrc/c64/extra/soft80.s | 3 +++ libsrc/c64/soft80.inc | 1 + 2 files changed, 4 insertions(+) diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index 162abb132..5490a3790 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -3,6 +3,7 @@ ; ; import/overload stubs for the soft80 implementation + .include "../soft80.inc" ; soft80_cgetc.s .import soft80_cgetc @@ -57,3 +58,5 @@ .import soft80_screensize .export screensize := soft80_screensize + .export mcb_spritememory := soft80_spriteblock + .export mcb_spritepointer := (soft80_vram + $03F8) diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc index a4bee337a..678000967 100644 --- a/libsrc/c64/soft80.inc +++ b/libsrc/c64/soft80.inc @@ -7,6 +7,7 @@ soft80_lo_charset = $d000 soft80_hi_charset = $d400 soft80_vram = $d800 ; ram under i/o soft80_colram = $d800 ; color ram (used for temp. storage) +soft80_spriteblock = $dc00 soft80_bitmap = $e000 charsperline = 80 From 5e960d106e050abe01616618907a95dbe8bf7dd0 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Mon, 12 Oct 2015 21:04:06 +0200 Subject: [PATCH 288/351] Allow to override chars used for horizontal and vertical lines. --- libsrc/cbm/chline.s | 4 ++-- libsrc/cbm/clinechars.s | 6 ++++++ libsrc/cbm/cvline.s | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 libsrc/cbm/clinechars.s diff --git a/libsrc/cbm/chline.s b/libsrc/cbm/chline.s index 26603b2fe..fe7e7255d 100644 --- a/libsrc/cbm/chline.s +++ b/libsrc/cbm/chline.s @@ -7,7 +7,7 @@ .export _chlinexy, _chline .import popa, _gotoxy, cputdirect - .importzp tmp1 + .importzp tmp1, chlinechar _chlinexy: pha ; Save the length @@ -19,7 +19,7 @@ _chline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #64 ; Horizontal line, screen code +L1: lda #chlinechar ; Horizontal line, screen code jsr cputdirect ; Direct output dec tmp1 bne L1 diff --git a/libsrc/cbm/clinechars.s b/libsrc/cbm/clinechars.s new file mode 100644 index 000000000..54896574b --- /dev/null +++ b/libsrc/cbm/clinechars.s @@ -0,0 +1,6 @@ +; +; Chars used by chline () and cvline () +; + + .exportzp chlinechar = 64 + .exportzp cvlinechar = 93 diff --git a/libsrc/cbm/cvline.s b/libsrc/cbm/cvline.s index f310e4322..2cf231e98 100644 --- a/libsrc/cbm/cvline.s +++ b/libsrc/cbm/cvline.s @@ -7,7 +7,7 @@ .export _cvlinexy, _cvline .import popa, _gotoxy, putchar, newline - .importzp tmp1 + .importzp tmp1, cvlinechar _cvlinexy: pha ; Save the length @@ -19,7 +19,7 @@ _cvline: cmp #0 ; Is the length zero? beq L9 ; Jump if done sta tmp1 -L1: lda #93 ; Vertical bar +L1: lda #cvlinechar ; Vertical bar jsr putchar ; Write, no cursor advance jsr newline ; Advance cursor to next line dec tmp1 From 362a1724776e569c1c8dbb96dd477cfb4182b334 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 21:23:27 +0200 Subject: [PATCH 289/351] remove chline/cvline dupes --- libsrc/c64/extra/soft80.s | 21 +++++++-------------- libsrc/c64/soft80_chline.s | 33 --------------------------------- libsrc/c64/soft80_cvline.s | 33 --------------------------------- 3 files changed, 7 insertions(+), 80 deletions(-) delete mode 100644 libsrc/c64/soft80_chline.s delete mode 100644 libsrc/c64/soft80_cvline.s diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index 5490a3790..9efb8d577 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -9,12 +9,6 @@ .import soft80_cgetc .export _cgetc := soft80_cgetc - ; soft80_chline.s - .import soft80_chlinexy - .import soft80_chline - .export _chlinexy := soft80_chlinexy - .export _chline := soft80_chline - ; soft80_color.s .import soft80_textcolor .import soft80_bgcolor @@ -39,12 +33,6 @@ .export newline := soft80_newline .export plot := soft80_plot - ; soft80_cvline.s - .import soft80_cvlinexy - .import soft80_cvline - .export _cvlinexy := soft80_cvlinexy - .export _cvline := soft80_cvline - ; soft80_kclrscr.s .import soft80_kclrscr .export _clrscr := soft80_kclrscr @@ -58,5 +46,10 @@ .import soft80_screensize .export screensize := soft80_screensize - .export mcb_spritememory := soft80_spriteblock - .export mcb_spritepointer := (soft80_vram + $03F8) + ; VIC sprite data for the mouse pointer + .export mcb_spritememory := soft80_spriteblock + .export mcb_spritepointer := (soft80_vram + $03F8) + + ; Chars used by chline () and cvline () + .exportzp chlinechar = CH_HLINE + .exportzp cvlinechar = CH_VLINE diff --git a/libsrc/c64/soft80_chline.s b/libsrc/c64/soft80_chline.s deleted file mode 100644 index 73c8c1e26..000000000 --- a/libsrc/c64/soft80_chline.s +++ /dev/null @@ -1,33 +0,0 @@ -; -; Groepaz/Hitmen, 12.10.2015 -; -; void chlinexy (unsigned char x, unsigned char y, unsigned char length); -; void chline (unsigned char length); -; - - .export soft80_chlinexy, soft80_chline - .import popa, _gotoxy, soft80_cputdirect - .importzp tmp1 - - .include "c64.inc" - .include "soft80.inc" - -soft80_chlinexy: - pha ; Save the length - jsr popa ; Get y - jsr _gotoxy ; Call this one, will pop params - pla ; Restore the length - -soft80_chline: - cmp #0 ; Is the length zero? - beq L9 ; Jump if done - sta tmp1 -L1: lda #CH_HLINE ; Horizontal line, petscii code - jsr soft80_cputdirect ; Direct output - dec tmp1 - bne L1 -L9: rts - - - - diff --git a/libsrc/c64/soft80_cvline.s b/libsrc/c64/soft80_cvline.s deleted file mode 100644 index e2c6e947c..000000000 --- a/libsrc/c64/soft80_cvline.s +++ /dev/null @@ -1,33 +0,0 @@ -; -; Groepaz/Hitmen, 12.10.2015 -; -; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); -; void cvline (unsigned char length); -; - - .export soft80_cvline, soft80_cvlinexy - .import popa, _gotoxy, soft80_putchar, soft80_newline - .importzp tmp1 - - .include "c64.inc" - .include "soft80.inc" - -soft80_cvlinexy: - pha ; Save the length - jsr popa ; Get y - jsr _gotoxy ; Call this one, will pop params - pla ; Restore the length and run into soft80_cvlinexy - -soft80_cvline: - cmp #0 ; Is the length zero? - beq L9 ; Jump if done - sta tmp1 -L1: lda #CH_VLINE ; Vertical bar, petscii code - jsr soft80_putchar ; Write, no cursor advance - jsr soft80_newline ; Advance cursor to next line - dec tmp1 - bne L1 -L9: rts - - - From f462c173fbdafba1eb2b5070a77265002d397dcf Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 12 Oct 2015 23:39:47 +0200 Subject: [PATCH 290/351] move some stuff to init segment, saves roughly 1480 bytes :) --- libsrc/c64/soft80.inc | 12 +++- libsrc/c64/soft80_charset.s | 2 +- libsrc/c64/soft80_conio.s | 112 ++++++++++++++++++++++++++---------- libsrc/c64/soft80_kplot.s | 39 ++++--------- 4 files changed, 104 insertions(+), 61 deletions(-) diff --git a/libsrc/c64/soft80.inc b/libsrc/c64/soft80.inc index 678000967..ca5c713ce 100644 --- a/libsrc/c64/soft80.inc +++ b/libsrc/c64/soft80.inc @@ -7,7 +7,17 @@ soft80_lo_charset = $d000 soft80_hi_charset = $d400 soft80_vram = $d800 ; ram under i/o soft80_colram = $d800 ; color ram (used for temp. storage) -soft80_spriteblock = $dc00 +soft80_spriteblock = $dc00 ; 64 bytes reserved for pointer sprite data + +; tables for kplot +soft80_bitmapxlo = $dc40 ; (80 bytes) +soft80_bitmapxhi = $dc40 + 80 ; (80 bytes) +soft80_vramlo = $dc40 + 160 ; (25 bytes) +; align to next page for speed +soft80_vramhi = $dd00 ; (25 bytes) +soft80_bitmapylo = $dd00 + 25 ; (25 bytes) +soft80_bitmapyhi = $dd00 + 50 ; (25 bytes) + soft80_bitmap = $e000 charsperline = 80 diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s index 7a4e10968..678439a30 100644 --- a/libsrc/c64/soft80_charset.s +++ b/libsrc/c64/soft80_charset.s @@ -43,7 +43,7 @@ .export soft80_charset - .rodata + .segment "INIT" soft80_charset: .byte $0f,$03,$0f,$00,$0f,$07,$05,$0e .byte $0f,$05,$0e,$0b,$0f,$0b,$0f,$0f diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index f6efe3382..06bebc907 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -17,6 +17,28 @@ .include "soft80.inc" soft80_init: + lda soft80_first_init + bne @skp + jsr firstinit +@skp: + ; the "color voodoo" in other parts of the code relies on the vram and + ; colorram being set up as expected, which is why we cant use the + ; _bgcolor and _textcolor functions here. + + lda 646 ; use current textcolor + and #$0f + sta soft80_internal_textcolor + + lda VIC_BG_COLOR0 ; use current bgcolor + and #$0f + sta soft80_internal_bgcolor + asl a + asl a + asl a + asl a + ora soft80_internal_textcolor + sta CHARCOLOR + lda #$3b sta VIC_CTRL1 lda #$00 @@ -26,14 +48,28 @@ soft80_init: lda #$c8 sta VIC_CTRL2 + jmp soft80_kclrscr + +soft80_shutdown: + lda #$1b + sta VIC_CTRL1 + lda #$03 + sta CIA2_PRA + lda #$15 + sta VIC_VIDEO_ADR + rts + + .segment "INIT" +firstinit: ; copy charset to RAM under I/O - ; FIXME: move charset and this constructor into init segment sei lda $01 pha lda #$34 sta $01 + inc soft80_first_init + lda #>soft80_charset sta ptr1+1 lda #<soft80_charset @@ -66,45 +102,58 @@ soft80_init: dex bne @l2 + ; copy the kplot tables to ram under I/O + ;ldx #0 ; is 0 +@l3: + lda soft80_tables_data_start,x + sta soft80_bitmapxlo,x + lda soft80_tables_data_start + (soft80_tables_data_end - soft80_tables_data_start - $100) ,x + sta soft80_bitmapxlo + (soft80_tables_data_end - soft80_tables_data_start - $100),x + inx + bne @l3 + pla sta $01 cli - - ; the "color voodoo" in other parts of the code relies on the vram and - ; colorram being set up as expected, which is why we cant use the - ; _bgcolor and _textcolor functions here. - - lda 646 ; use current textcolor - and #$0f - sta soft80_internal_textcolor - - lda VIC_BG_COLOR0 ; use current bgcolor - and #$0f - sta soft80_internal_bgcolor - asl a - asl a - asl a - asl a - ora soft80_internal_textcolor - sta CHARCOLOR - - jmp soft80_kclrscr - -soft80_shutdown: - lda #$1b - sta VIC_CTRL1 - lda #$03 - sta CIA2_PRA - lda #$15 - sta VIC_VIDEO_ADR rts +; the following tables take up 267 bytes, used by kplot +soft80_tables_data_start: + +soft80_bitmapxlo_data: + .repeat 80,col + .byte <((col/2)*8) + .endrepeat +soft80_bitmapxhi_data: + .repeat 80,col + .byte >((col/2)*8) + .endrepeat +soft80_vramlo_data: + .repeat 25,row + .byte <(soft80_vram+(row*40)) + .endrepeat + .byte 0,0,0,0,0,0,0 ; padding to next page +soft80_vramhi_data: + .repeat 25,row + .byte >(soft80_vram+(row*40)) + .endrepeat +soft80_bitmapylo_data: + .repeat 25,row + .byte <(soft80_bitmap+(row*40*8)) + .endrepeat +soft80_bitmapyhi_data: + .repeat 25,row + .byte >(soft80_bitmap+(row*40*8)) + .endrepeat + +soft80_tables_data_end: + ;------------------------------------------------------------------------------- ; FIXME: when the code is fixed to use the "init" segment, these variables must ; be moved into a section other than .bss so they survive after the init ; code has been run. - .bss + .data ; FIXME soft80_internal_textcolor: .res 1 soft80_internal_bgcolor: @@ -112,3 +161,6 @@ soft80_internal_bgcolor: soft80_internal_cursorxlsb: .res 1 + .data +soft80_first_init: + .byte 0 ; flag to check first init, this really must be in .data diff --git a/libsrc/c64/soft80_kplot.s b/libsrc/c64/soft80_kplot.s index 79a14cbcb..bd52ee6d3 100644 --- a/libsrc/c64/soft80_kplot.s +++ b/libsrc/c64/soft80_kplot.s @@ -17,6 +17,12 @@ soft80_kplot: stx CURS_Y sty CURS_X + sei + lda $01 + pha + lda #$34 ; enable RAM under I/O + sta $01 + ; calc pointer to bitmap lda soft80_bitmapylo,x clc @@ -41,40 +47,15 @@ soft80_kplot: adc soft80_vramhi,x sta CRAM_PTR+1 + pla + sta $01 + cli + @getpos: ldx CURS_Y ldy CURS_X rts - ; FIXME: the following tables take up 260 bytes, perhaps move them - ; to 0xdc00... area in ram under i/o - - .rodata -soft80_bitmapxlo: - .repeat 80,col - .byte <((col/2)*8) - .endrepeat -soft80_bitmapxhi: - .repeat 80,col - .byte >((col/2)*8) - .endrepeat -soft80_vramlo: - .repeat 25,row - .byte <(soft80_vram+(row*40)) - .endrepeat -soft80_vramhi: - .repeat 25,row - .byte >(soft80_vram+(row*40)) - .endrepeat -soft80_bitmapylo: - .repeat 25,row - .byte <(soft80_bitmap+(row*40*8)) - .endrepeat -soft80_bitmapyhi: - .repeat 25,row - .byte >(soft80_bitmap+(row*40*8)) - .endrepeat - ;------------------------------------------------------------------------------- ; force the init constructor to be imported From 08d7eefdd7178705628f3d8ad28e9f9041f2e511 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 13 Oct 2015 04:14:04 +0200 Subject: [PATCH 291/351] another size optimization, make bgcolor() much more robust --- libsrc/c64/soft80_color.s | 190 ++++++++++++++++++++++++-------------- libsrc/c64/soft80_cputc.s | 6 +- 2 files changed, 125 insertions(+), 71 deletions(-) diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index ab4b4a01f..e84b6fa60 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -7,6 +7,8 @@ .export soft80_textcolor, soft80_bgcolor .import soft80_internal_textcolor, soft80_internal_bgcolor + .import soft80_internal_cursorxlsb + .import soft80_kplot, soft80_checkchar .importzp tmp1, tmp2 @@ -17,74 +19,6 @@ soft80_textcolor: ldx soft80_internal_textcolor ; get old value sta soft80_internal_textcolor ; set new value - jsr mkcharcolor - - txa ; get old value - rts - -soft80_bgcolor: - ldx soft80_internal_bgcolor ; get old value - sta soft80_internal_bgcolor ; set new value - - jsr mkcharcolor - - stx tmp2 ; save old value - -.if SOFT80COLORVOODOO = 1 - ; if the old bg color is equal to color ram of that cell, then also - ; update the color ram to the new value. - ; FIXME: perhaps we must also check if the non visible character is not - ; a space, and NOT update the color ram in that case. - ldx #$00 -lp1: - .repeat $4,page - .scope - lda soft80_colram+(page*250),x - and #$0f - cmp tmp2 ; old bg color - bne @sk1 - lda soft80_internal_bgcolor ; new bg color - sta soft80_colram+(page*250),x -@sk1: - .endscope - .endrepeat - - inx - bne lp1 -.endif - - sei - ldy $01 - lda #$34 ; disable I/O - sta $01 - - ; if the old bg color is equal to text color in this cell, then also - ; update the text color to the new value. - ; FIXME: perhaps we need to check for space, see note above - ldx #$00 -lp2: - .repeat $4,page - .scope - lda soft80_vram+(page*250),x - and #$0f - cmp tmp2 ; old bg color - bne @sk2 - lda soft80_internal_bgcolor ; new bg color -@sk2: - ora tmp1 ; new bg color (high nibble) - sta soft80_vram+(page*250),x - .endscope - .endrepeat - - inx - bne lp2 - - sty $01 ; enable I/O - cli - - lda tmp2 ; get old value - rts - mkcharcolor: lda soft80_internal_bgcolor asl a @@ -94,6 +28,126 @@ mkcharcolor: sta tmp1 ; remember new bg color (high nibble) ora soft80_internal_textcolor sta CHARCOLOR ; text/bg combo for new chars + + txa ; get old value + rts + +soft80_bgcolor: + ldx soft80_internal_bgcolor ; get old value + stx tmp2 ; save old value + sta soft80_internal_bgcolor ; set new value + + jsr mkcharcolor + + lda CURS_X + pha + lda CURS_Y + pha + + ldy #0 + ldx #0 + clc + jsr soft80_kplot + + sei + lda $01 + pha + ldx #$34 + stx $01 ; $34 + + ;ldy #0 ; is still 0 + + lda #24 + sta CURS_Y +lpy: + lda #39 + sta CURS_X +lpx: + +.if SOFT80COLORVOODOO = 1 + ; if the old bg color is equal to color ram of that cell, then also + ; update the color ram to the new value. + + inc $01 ; $35 + lda (CRAM_PTR),y ; colram + stx $01 ; $34 + + and #$0f + cmp tmp2 ; old bg color + bne @sk1 + + ; if the left character in the cell is not a space, then dont update + ; the color ram + lda #1 + sta soft80_internal_cursorxlsb + jsr soft80_checkchar + bcc @sk1 + lda soft80_internal_bgcolor ; new bg color + + inc $01 ; $35 + sta (CRAM_PTR),y ; colram + stx $01 ; $34 +@sk1: +.endif + ; if the old bg color is equal to text color in this cell, then also + ; update the text color to the new value. + + lda (CRAM_PTR),y ; vram + and #$0f + cmp tmp2 ; old bg color + bne @sk2 + + ; if there are non space characters in the cell, do not update the + ; color ram + pha + lda #0 + sta soft80_internal_cursorxlsb + jsr soft80_checkchar + pla + bcc @sk2 + + pha + inc soft80_internal_cursorxlsb + jsr soft80_checkchar + pla + bcc @sk2 + + lda soft80_internal_bgcolor ; new bg color +@sk2: + ora tmp1 ; new bg color (high nibble) + sta (CRAM_PTR),y ; vram + + inc CRAM_PTR + bne @sk3 + inc CRAM_PTR+1 +@sk3: + + lda SCREEN_PTR + clc + adc #8 + sta SCREEN_PTR + bcc @sk4 + inc SCREEN_PTR+1 +@sk4: + + dec CURS_X + bpl lpx + + dec CURS_Y + bpl lpy + + pla + sta $01 ; enable I/O + cli + + pla ; CURS_Y + tax + pla ; CURS_X + tay + clc + jsr soft80_kplot + + lda tmp2 ; get old value rts ;------------------------------------------------------------------------------- diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 0e8cb0bd8..92aa728de 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -8,6 +8,7 @@ .export soft80_cputcxy, soft80_cputc .export soft80_cputdirect, soft80_putchar .export soft80_newline, soft80_plot + .export soft80_checkchar .import popa, _gotoxy @@ -470,15 +471,14 @@ soft80_putcolor: ; test if there is a space or a character at current position ; ; in: x = $34 -; y must be $00 +; $01 must be $34 +; ; out: SEC: space ; CLC: character ; x = $34 ; y = $00 soft80_checkchar: - ;ldy #$00 ; is still $00 - lda soft80_internal_cursorxlsb bne @l1a From ffda2a36031a163ec74a54ac87a0fd3210111c60 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Tue, 13 Oct 2015 04:14:23 +0200 Subject: [PATCH 292/351] updated conio test --- testcode/lib/conio.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index a7a83594e..eebcd195e 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -14,7 +14,7 @@ static char grid[5][5] = { void main(void) { int i, j, n; - unsigned char xsize, ysize, tcol, inpos = 0; + unsigned char xsize, ysize, tcol, bgcol, inpos = 0; clrscr(); screensize(&xsize, &ysize); @@ -22,6 +22,7 @@ void main(void) cputsxy(0, 2, "Colors:" ); tcol = textcolor(0); /* remember original textcolor */ + bgcol = bgcolor(0); /* remember original background color */ for (i = 0; i < 3; ++i) { gotoxy(i,3 + i); for (j = 0; j < 16; ++j) { @@ -30,6 +31,7 @@ void main(void) } } textcolor(tcol); + bgcolor(bgcol); cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize ); @@ -90,6 +92,12 @@ void main(void) inpos = (inpos - 1) & 7; } else if (i == CH_CURS_RIGHT) { inpos = (inpos + 1) & 7; + } else if (i == CH_F7) { + bgcol = (bgcol + 1) & 0x0f; + bgcolor(bgcol); + } else if (i == CH_F8) { + bgcol = (bgcol - 1) & 0x0f; + bgcolor(bgcol); } else { cputc(i); inpos = (inpos + 1) & 7; From 023b461bb8a9ad86c22d3c8624d48895d38b1dd1 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Wed, 14 Oct 2015 11:50:54 +0200 Subject: [PATCH 293/351] According to the contributor the VGA data is accessed only by the constructor. --- libsrc/pce/conio.s | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 64df87018..b2bb0f9d5 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -113,6 +113,5 @@ fillloop: rts - .rodata font: .include "vga.inc" From c7080313746fafb082e29ffa65355030bf8f4aaa Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:24:16 +0200 Subject: [PATCH 294/351] use 'soft80_internal_cellcolor' for the current cell color, and CHARCOLOR for the actual textcolor --- libsrc/c64/soft80_cgetc.s | 4 ++-- libsrc/c64/soft80_color.s | 10 +++++----- libsrc/c64/soft80_conio.s | 14 +++++++------- libsrc/c64/soft80_cputc.s | 12 ++++++------ libsrc/c64/soft80_kclrscr.s | 4 ++-- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index ba16614af..5343027bb 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -5,7 +5,7 @@ ; .export soft80_cgetc - .import soft80_internal_cursorxlsb + .import soft80_internal_cellcolor, soft80_internal_cursorxlsb .import cursor .importzp tmp1 @@ -74,7 +74,7 @@ setcolor: ; save old value lda (CRAM_PTR),y ; vram sta tmp1 - lda CHARCOLOR + lda soft80_internal_cellcolor sta (CRAM_PTR),y ; vram rts diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index e84b6fa60..bbd666af7 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -6,7 +6,7 @@ ; .export soft80_textcolor, soft80_bgcolor - .import soft80_internal_textcolor, soft80_internal_bgcolor + .import soft80_internal_cellcolor, soft80_internal_bgcolor .import soft80_internal_cursorxlsb .import soft80_kplot, soft80_checkchar @@ -16,8 +16,8 @@ .include "soft80.inc" soft80_textcolor: - ldx soft80_internal_textcolor ; get old value - sta soft80_internal_textcolor ; set new value + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value mkcharcolor: lda soft80_internal_bgcolor @@ -26,8 +26,8 @@ mkcharcolor: asl a asl a sta tmp1 ; remember new bg color (high nibble) - ora soft80_internal_textcolor - sta CHARCOLOR ; text/bg combo for new chars + ora CHARCOLOR + sta soft80_internal_cellcolor ; text/bg combo for new chars txa ; get old value rts diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 06bebc907..d2dfb913e 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -8,7 +8,7 @@ .destructor soft80_shutdown .import soft80_kclrscr, soft80_charset - .export soft80_internal_textcolor, soft80_internal_bgcolor + .export soft80_internal_bgcolor, soft80_internal_cellcolor .export soft80_internal_cursorxlsb .importzp ptr1, ptr2, ptr3 @@ -25,9 +25,9 @@ soft80_init: ; colorram being set up as expected, which is why we cant use the ; _bgcolor and _textcolor functions here. - lda 646 ; use current textcolor - and #$0f - sta soft80_internal_textcolor + lda CHARCOLOR ; use current textcolor + and #$0f ; make sure the upper nibble is 0s + sta CHARCOLOR lda VIC_BG_COLOR0 ; use current bgcolor and #$0f @@ -36,8 +36,8 @@ soft80_init: asl a asl a asl a - ora soft80_internal_textcolor - sta CHARCOLOR + ora CHARCOLOR + sta soft80_internal_cellcolor lda #$3b sta VIC_CTRL1 @@ -154,7 +154,7 @@ soft80_tables_data_end: ; code has been run. .data ; FIXME -soft80_internal_textcolor: +soft80_internal_cellcolor: .res 1 soft80_internal_bgcolor: .res 1 diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 92aa728de..1ded7ef6a 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -13,7 +13,7 @@ .import popa, _gotoxy .import soft80_kplot - .import soft80_internal_bgcolor, soft80_internal_textcolor + .import soft80_internal_bgcolor, soft80_internal_cellcolor .import soft80_internal_cursorxlsb .importzp tmp4,tmp3 @@ -148,7 +148,7 @@ draw_spaceinvers: .if SOFT80COLORVOODOO = 1 jsr soft80_putcolor .else - lda CHARCOLOR + lda soft80_internal_cellcolor sta (CRAM_PTR),y ; vram .endif @@ -232,7 +232,7 @@ soft80_putchar: .if SOFT80COLORVOODOO = 1 jsr soft80_putcolor .else - lda CHARCOLOR + lda soft80_internal_cellcolor sta (CRAM_PTR),y ; vram .endif @@ -436,7 +436,7 @@ soft80_putcolor: bne @sk2 ; jump if odd xpos ; vram = textcol - lda CHARCOLOR + lda soft80_internal_cellcolor sta (CRAM_PTR),y ; vram rts @@ -449,7 +449,7 @@ soft80_putcolor: beq @sk3 ; jump if even xpos @sk2: ; colram = textcol - lda soft80_internal_textcolor + lda CHARCOLOR inc $01 ; $35 sta (CRAM_PTR),y ; colram stx $01 ; $34 @@ -463,7 +463,7 @@ soft80_putcolor: stx $01 ; $34 @sk1: ; vram = textcol - lda CHARCOLOR + lda soft80_internal_cellcolor sta (CRAM_PTR),y ; vram rts diff --git a/libsrc/c64/soft80_kclrscr.s b/libsrc/c64/soft80_kclrscr.s index 811ea665f..7c313afcf 100644 --- a/libsrc/c64/soft80_kclrscr.s +++ b/libsrc/c64/soft80_kclrscr.s @@ -6,7 +6,7 @@ .export soft80_kclrscr .import soft80_kplot - .import soft80_internal_bgcolor + .import soft80_internal_bgcolor, soft80_internal_cellcolor .importzp ptr1 .include "c64.inc" @@ -48,7 +48,7 @@ soft80_kclrscr: lda #$34 ; enable RAM under I/O sta $01 - lda CHARCOLOR + lda soft80_internal_cellcolor and #$f0 ora soft80_internal_bgcolor jsr clear ; clear vram From d4f88c8f7141119b6efd1869ff247515a7c09601 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:24:42 +0200 Subject: [PATCH 295/351] update conio test --- testcode/lib/conio.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index eebcd195e..0dddacfdf 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -1,3 +1,14 @@ +/* + * conio api test program + * + * keys: + * + * 1...0 change text color + * F5/F6 change border color + * F7/F8 change background color + * + */ + #include <conio.h> #include <string.h> @@ -14,7 +25,7 @@ static char grid[5][5] = { void main(void) { int i, j, n; - unsigned char xsize, ysize, tcol, bgcol, inpos = 0; + unsigned char xsize, ysize, tcol, bgcol, bcol, inpos = 0; clrscr(); screensize(&xsize, &ysize); @@ -23,6 +34,7 @@ void main(void) cputsxy(0, 2, "Colors:" ); tcol = textcolor(0); /* remember original textcolor */ bgcol = bgcolor(0); /* remember original background color */ + bcol = bordercolor(0); /* remember original border color */ for (i = 0; i < 3; ++i) { gotoxy(i,3 + i); for (j = 0; j < 16; ++j) { @@ -92,6 +104,12 @@ void main(void) inpos = (inpos - 1) & 7; } else if (i == CH_CURS_RIGHT) { inpos = (inpos + 1) & 7; + } else if (i == CH_F5) { + bgcol = (bgcol + 1) & 0x0f; + bordercolor(bgcol); + } else if (i == CH_F6) { + bgcol = (bgcol - 1) & 0x0f; + bordercolor(bgcol); } else if (i == CH_F7) { bgcol = (bgcol + 1) & 0x0f; bgcolor(bgcol); From 59dd15aa55341264776a9515e43e42c9b03c4f05 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:25:35 +0200 Subject: [PATCH 296/351] split regular color.s into color.s and bordercolor.s --- libsrc/c64/bordercolor.s | 17 +++++++++++++++++ libsrc/c64/color.s | 10 +--------- 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 libsrc/c64/bordercolor.s diff --git a/libsrc/c64/bordercolor.s b/libsrc/c64/bordercolor.s new file mode 100644 index 000000000..73dfc0a99 --- /dev/null +++ b/libsrc/c64/bordercolor.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _bordercolor + + .include "c64.inc" + +_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts + diff --git a/libsrc/c64/color.s b/libsrc/c64/color.s index bfc371931..de9a973e7 100644 --- a/libsrc/c64/color.s +++ b/libsrc/c64/color.s @@ -7,7 +7,7 @@ ; - .export _textcolor, _bgcolor, _bordercolor + .export _textcolor, _bgcolor .include "c64.inc" @@ -23,11 +23,3 @@ _bgcolor: sta VIC_BG_COLOR0 ; set new value txa rts - - -_bordercolor: - ldx VIC_BORDERCOLOR ; get old value - sta VIC_BORDERCOLOR ; set new value - txa - rts - From f391c1c3d5f12b0fbfd1a9152efc69fe1b4fc8b9 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:33:58 +0200 Subject: [PATCH 297/351] remove soft80_bordercolor override --- libsrc/c64/extra/soft80.s | 4 ---- libsrc/c64/soft80_bordercolor.s | 17 ----------------- 2 files changed, 21 deletions(-) delete mode 100644 libsrc/c64/soft80_bordercolor.s diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index 9efb8d577..c1e74d66a 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -15,10 +15,6 @@ .export _textcolor := soft80_textcolor .export _bgcolor := soft80_bgcolor - ; soft80_bordercolor.s - .import soft80_bordercolor - .export _bordercolor := soft80_bordercolor - ; soft80_cputc.s .import soft80_cputc .import soft80_cputcxy diff --git a/libsrc/c64/soft80_bordercolor.s b/libsrc/c64/soft80_bordercolor.s deleted file mode 100644 index 057cc410a..000000000 --- a/libsrc/c64/soft80_bordercolor.s +++ /dev/null @@ -1,17 +0,0 @@ -; -; Groepaz/Hitmen, 12.10.2015 -; -; unsigned char __fastcall__ bordercolor (unsigned char color); -; - - .export soft80_bordercolor - - .include "c64.inc" - - ; FIXME: if we'd move this function into a seperate file in the regular - ; conio lib, then we dont need this override at all. -soft80_bordercolor: - ldx VIC_BORDERCOLOR ; get old value - sta VIC_BORDERCOLOR ; set new value - txa - rts From 795a1a1b87a35d6d04e62d6416bc3e2794046d6a Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:34:29 +0200 Subject: [PATCH 298/351] fix bordercolor in test --- testcode/lib/conio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index 0dddacfdf..3a8048632 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -35,6 +35,7 @@ void main(void) tcol = textcolor(0); /* remember original textcolor */ bgcol = bgcolor(0); /* remember original background color */ bcol = bordercolor(0); /* remember original border color */ + bgcolor(bgcol);bordercolor(bcol); for (i = 0; i < 3; ++i) { gotoxy(i,3 + i); for (j = 0; j < 16; ++j) { @@ -43,7 +44,6 @@ void main(void) } } textcolor(tcol); - bgcolor(bgcol); cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize ); From e6f5c7d8da65d1d249fc6a636ed668a4c229eac0 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:50:44 +0200 Subject: [PATCH 299/351] some comments --- libsrc/c64/extra/soft80.s | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index c1e74d66a..4ee030c81 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -7,13 +7,13 @@ ; soft80_cgetc.s .import soft80_cgetc - .export _cgetc := soft80_cgetc + .export _cgetc := soft80_cgetc ; cgetc.s ; soft80_color.s .import soft80_textcolor .import soft80_bgcolor - .export _textcolor := soft80_textcolor - .export _bgcolor := soft80_bgcolor + .export _textcolor := soft80_textcolor ; color.s + .export _bgcolor := soft80_bgcolor ; color.s ; soft80_cputc.s .import soft80_cputc @@ -22,25 +22,26 @@ .import soft80_putchar .import soft80_newline .import soft80_plot - .export _cputc := soft80_cputc - .export _cputcxy := soft80_cputcxy - .export cputdirect := soft80_cputdirect - .export putchar := soft80_putchar - .export newline := soft80_newline - .export plot := soft80_plot + .export _cputc := soft80_cputc ; cputc.s + .export _cputcxy := soft80_cputcxy ; cputc.s + .export cputdirect := soft80_cputdirect ; cputc.s + .export putchar := soft80_putchar ; cputc.s + .export newline := soft80_newline ; cputc.s + .export plot := soft80_plot ; cputc.s ; soft80_kclrscr.s .import soft80_kclrscr - .export _clrscr := soft80_kclrscr - .export CLRSCR := soft80_kclrscr + .export _clrscr := soft80_kclrscr ; clrscr.s + .export CLRSCR := soft80_kclrscr ; kernal func (c64.inc) ; soft80_kplot.s .import soft80_kplot - .export PLOT := soft80_kplot + .export PLOT := soft80_kplot ; kplot.s ; soft80_kscreen.s .import soft80_screensize - .export screensize := soft80_screensize + .export screensize := soft80_screensize ; _scrsize.s + .export SCREEN := soft80_screensize ; kernal func (kernal.s) ; VIC sprite data for the mouse pointer .export mcb_spritememory := soft80_spriteblock From b9c688d997a3c0cdce096f3a8d225026bb736a45 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Wed, 14 Oct 2015 17:52:14 +0200 Subject: [PATCH 300/351] remove deleted function from comment --- libsrc/c64/color.s | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/c64/color.s b/libsrc/c64/color.s index de9a973e7..86d6aefe8 100644 --- a/libsrc/c64/color.s +++ b/libsrc/c64/color.s @@ -3,7 +3,6 @@ ; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); -; unsigned char __fastcall__ bordercolor (unsigned char color); ; From 0ee9b2e446198746c3a05b142ecd00784becf727 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Wed, 14 Oct 2015 22:52:09 +0200 Subject: [PATCH 301/351] Changed run location of INIT segment. So far the INIT segment was run from the later heap+stack. Now the INIT segment is run from the later BSS. The background is that so far the INIT segment was pretty small (from $80 to $180 bytes). But upcoming changes will increase the INIT segment in certain scenarios up to ~ $1000 bytes. So programs with very limited heap+stack might just not been able to move the INIT segment to its run location. But moving the INIT segment to the later BSS allows it to occupy the later BSS+heap+stack. In order to allow that the constructors are _NOT_ allowed anymore to access the BSS. Rather they must use the DATA segment or the new INITBSS segment. The latter isn't cleared at any point so the constructors may use it to expose values to the main program. However they must make sure to always write the values as they are not pre-initialized. --- cfg/c128-overlay.cfg | 2 +- cfg/c128.cfg | 2 +- cfg/c16.cfg | 2 +- cfg/c64-overlay.cfg | 63 ++++++++++++++++++++------------------- cfg/c64.cfg | 33 ++++++++++---------- cfg/cbm510.cfg | 1 + cfg/cbm610.cfg | 1 + cfg/pet.cfg | 2 +- cfg/plus4.cfg | 2 +- cfg/vic20-32k.cfg | 2 +- cfg/vic20.cfg | 2 +- libsrc/atari/initcwd.s | 2 ++ libsrc/c128/crt0.s | 2 +- libsrc/c128/mainargs.s | 31 +++++++++---------- libsrc/c16/crt0.s | 2 +- libsrc/c16/mainargs.s | 31 +++++++++---------- libsrc/c64/crt0.s | 40 ++++++++++++------------- libsrc/c64/mainargs.s | 31 +++++++++---------- libsrc/cbm/filedes.s | 14 ++++++--- libsrc/cbm/filevars.s | 2 +- libsrc/cbm/read.s | 5 ---- libsrc/cbm/write.s | 10 ------- libsrc/cbm510/mainargs.s | 40 ++++++++++++------------- libsrc/cbm610/mainargs.s | 46 ++++++++++++++-------------- libsrc/common/_cwd.s | 5 ++-- libsrc/common/moveinit.s | 4 +-- libsrc/common/zerobss.s | 5 +--- libsrc/pet/crt0.s | 2 +- libsrc/pet/mainargs.s | 29 +++++++++--------- libsrc/plus4/crt0.s | 2 +- libsrc/plus4/mainargs.s | 34 ++++++++++----------- libsrc/runtime/callmain.s | 6 ++-- libsrc/runtime/stkchk.s | 6 ++-- libsrc/vic20/crt0.s | 2 +- libsrc/vic20/mainargs.s | 31 +++++++++---------- 35 files changed, 234 insertions(+), 260 deletions(-) diff --git a/cfg/c128-overlay.cfg b/cfg/c128-overlay.cfg index e16ad4b2e..f2cc3c40c 100644 --- a/cfg/c128-overlay.cfg +++ b/cfg/c128-overlay.cfg @@ -38,7 +38,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; OVL1ADDR: load = OVL1ADDR, type = ro; diff --git a/cfg/c128.cfg b/cfg/c128.cfg index 0e1259111..ef2aa4184 100644 --- a/cfg/c128.cfg +++ b/cfg/c128.cfg @@ -18,7 +18,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } diff --git a/cfg/c16.cfg b/cfg/c16.cfg index 78c1739d3..efb42991f 100644 --- a/cfg/c16.cfg +++ b/cfg/c16.cfg @@ -18,7 +18,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } diff --git a/cfg/c64-overlay.cfg b/cfg/c64-overlay.cfg index 07ce9e4b6..1c3b19c09 100644 --- a/cfg/c64-overlay.cfg +++ b/cfg/c64-overlay.cfg @@ -14,8 +14,9 @@ MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; LOADADDR: file = %O, start = %S - 2, size = $0002; HEADER: file = %O, define = yes, start = %S, size = $000D; - RAM: file = %O, define = yes, start = __HEADER_LAST__, size = __OVERLAYSTART__ - __STACKSIZE__ - __HEADER_LAST__; - MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; + MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __OVERLAYSTART__ - __STACKSIZE__ - __HEADER_LAST__; + MOVE: file = %O, start = __INITBSS_LOAD__, size = __HIMEM__ - __BSS_RUN__; + INIT: file = "", start = __BSS_RUN__, size = __HIMEM__ - __BSS_RUN__; OVL1ADDR: file = "%O.1", start = __OVERLAYSTART__ - 2, size = $0002; OVL1: file = "%O.1", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; OVL2ADDR: file = "%O.2", start = __OVERLAYSTART__ - 2, size = $0002; @@ -36,35 +37,35 @@ MEMORY { OVL9: file = "%O.9", start = __OVERLAYSTART__, size = __OVERLAYSIZE__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - LOADADDR: load = LOADADDR, type = ro; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro; - LOWCODE: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - INIT: load = MOVE, run = RAM, type = ro, define = yes; - OVL1ADDR: load = OVL1ADDR, type = ro; - OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; - OVL2ADDR: load = OVL2ADDR, type = ro; - OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; - OVL3ADDR: load = OVL3ADDR, type = ro; - OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; - OVL4ADDR: load = OVL4ADDR, type = ro; - OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; - OVL5ADDR: load = OVL5ADDR, type = ro; - OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; - OVL6ADDR: load = OVL6ADDR, type = ro; - OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; - OVL7ADDR: load = OVL7ADDR, type = ro; - OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; - OVL8ADDR: load = OVL8ADDR, type = ro; - OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; - OVL9ADDR: load = OVL9ADDR, type = ro; - OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INITBSS: load = MAIN, type = bss, define = yes; + BSS: load = MAIN, type = bss, define = yes; + INIT: load = MOVE, run = INIT, type = ro, define = yes; + OVL1ADDR: load = OVL1ADDR, type = ro; + OVERLAY1: load = OVL1, type = ro, define = yes, optional = yes; + OVL2ADDR: load = OVL2ADDR, type = ro; + OVERLAY2: load = OVL2, type = ro, define = yes, optional = yes; + OVL3ADDR: load = OVL3ADDR, type = ro; + OVERLAY3: load = OVL3, type = ro, define = yes, optional = yes; + OVL4ADDR: load = OVL4ADDR, type = ro; + OVERLAY4: load = OVL4, type = ro, define = yes, optional = yes; + OVL5ADDR: load = OVL5ADDR, type = ro; + OVERLAY5: load = OVL5, type = ro, define = yes, optional = yes; + OVL6ADDR: load = OVL6ADDR, type = ro; + OVERLAY6: load = OVL6, type = ro, define = yes, optional = yes; + OVL7ADDR: load = OVL7ADDR, type = ro; + OVERLAY7: load = OVL7, type = ro, define = yes, optional = yes; + OVL8ADDR: load = OVL8ADDR, type = ro; + OVERLAY8: load = OVL8, type = ro, define = yes, optional = yes; + OVL9ADDR: load = OVL9ADDR, type = ro; + OVERLAY9: load = OVL9, type = ro, define = yes, optional = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/c64.cfg b/cfg/c64.cfg index 8fe1c0c6f..2a105c7f1 100644 --- a/cfg/c64.cfg +++ b/cfg/c64.cfg @@ -8,24 +8,25 @@ SYMBOLS { __HIMEM__: type = weak, value = $D000; } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; - LOADADDR: file = %O, start = %S - 2, size = $0002; - HEADER: file = %O, define = yes, start = %S, size = $000D; - RAM: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __STACKSIZE__ - __HEADER_LAST__; - MOVE: file = %O, start = __ZPSAVE_LOAD__, size = __HIMEM__ - __INIT_RUN__; + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $000D; + MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __STACKSIZE__ - __HEADER_LAST__; + MOVE: file = %O, start = __INITBSS_LOAD__, size = __HIMEM__ - __BSS_RUN__; + INIT: file = "", start = __BSS_RUN__, size = __HIMEM__ - __BSS_RUN__; } SEGMENTS { - ZEROPAGE: load = ZP, type = zp; - LOADADDR: load = LOADADDR, type = ro; - EXEHDR: load = HEADER, type = ro; - STARTUP: load = RAM, type = ro; - LOWCODE: load = RAM, type = ro, optional = yes; - CODE: load = RAM, type = ro; - RODATA: load = RAM, type = ro; - DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; - BSS: load = RAM, type = bss, define = yes; - INIT: load = MOVE, run = RAM, type = ro, define = yes; + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INITBSS: load = MAIN, type = bss, define = yes; + BSS: load = MAIN, type = bss, define = yes; + INIT: load = MOVE, run = INIT, type = ro, define = yes; } FEATURES { CONDES: type = constructor, diff --git a/cfg/cbm510.cfg b/cfg/cbm510.cfg index 7635c6eeb..d0775b6f2 100644 --- a/cfg/cbm510.cfg +++ b/cfg/cbm510.cfg @@ -22,6 +22,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = rw, define = yes; diff --git a/cfg/cbm610.cfg b/cfg/cbm610.cfg index 48b5eba0c..ae66f4c4a 100644 --- a/cfg/cbm610.cfg +++ b/cfg/cbm610.cfg @@ -19,6 +19,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = rw, define = yes; diff --git a/cfg/pet.cfg b/cfg/pet.cfg index ef8b82e54..80d89ee50 100644 --- a/cfg/pet.cfg +++ b/cfg/pet.cfg @@ -18,7 +18,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } diff --git a/cfg/plus4.cfg b/cfg/plus4.cfg index c756f45a1..6eeddf12e 100644 --- a/cfg/plus4.cfg +++ b/cfg/plus4.cfg @@ -18,7 +18,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } diff --git a/cfg/vic20-32k.cfg b/cfg/vic20-32k.cfg index c66b35247..23cd718df 100644 --- a/cfg/vic20-32k.cfg +++ b/cfg/vic20-32k.cfg @@ -20,7 +20,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } diff --git a/cfg/vic20.cfg b/cfg/vic20.cfg index f356eb61e..9a5ce9a63 100644 --- a/cfg/vic20.cfg +++ b/cfg/vic20.cfg @@ -18,7 +18,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss; + INITBSS: load = RAM, type = bss; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; } diff --git a/libsrc/atari/initcwd.s b/libsrc/atari/initcwd.s index d7b574314..074b9476f 100644 --- a/libsrc/atari/initcwd.s +++ b/libsrc/atari/initcwd.s @@ -9,6 +9,8 @@ .proc initcwd + lda #0 + sta __cwd jsr findfreeiocb bne oserr lda #GETCWD diff --git a/libsrc/c128/crt0.s b/libsrc/c128/crt0.s index 9bfdca49f..4c6a0f7d9 100644 --- a/libsrc/c128/crt0.s +++ b/libsrc/c128/crt0.s @@ -108,7 +108,7 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ ; Data -.segment "ZPSAVE" +.segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/c128/mainargs.s b/libsrc/c128/mainargs.s index fb5fd1554..dcd5a11bd 100644 --- a/libsrc/c128/mainargs.s +++ b/libsrc/c128/mainargs.s @@ -30,8 +30,7 @@ MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name - +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run @@ -42,26 +41,26 @@ initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + + lda #0 ; The terminating NUL character ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda #FNAM ; Load vector address for FETCH routine ldx FNAM_BANK ; Load bank for FETCH routine jsr INDFET ; Load byte from (FETVEC),y - sta name,y ; Save byte from filename -L1: dey +L1: sta name,y ; Save byte from filename + dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - beq done ; no "rem," no args. + beq done ; No "rem," no args. inx cmp #REM bne L2 @@ -73,7 +72,7 @@ next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we @@ -128,15 +127,13 @@ done: lda #<argv stx __argv + 1 rts -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name .res MAXARGS * 2 - diff --git a/libsrc/c16/crt0.s b/libsrc/c16/crt0.s index 0180ad671..c4d179529 100644 --- a/libsrc/c16/crt0.s +++ b/libsrc/c16/crt0.s @@ -90,7 +90,7 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ -.segment "ZPSAVE" +.segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/c16/mainargs.s b/libsrc/c16/mainargs.s index 0a402d27d..db93ae2e6 100644 --- a/libsrc/c16/mainargs.s +++ b/libsrc/c16/mainargs.s @@ -28,10 +28,9 @@ .include "plus4.inc" - MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run @@ -42,25 +41,25 @@ initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + + lda #0 ; The terminating NUL character ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda #FNAM ; Vector address jsr FETCH ; Load byte from RAM - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - beq done ; no "rem," no args. + beq done ; No "rem," no args. inx cmp #REM bne L2 @@ -72,7 +71,7 @@ next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we @@ -127,15 +126,13 @@ done: lda #<argv stx __argv + 1 rts -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name .res MAXARGS * 2 - diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index a2abe91af..78268422b 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -8,7 +8,7 @@ .import initlib, donelib .import moveinit, zerobss, callmain .import BSOUT - .import __RAM_START__, __RAM_SIZE__ ; Linker generated + .import __MAIN_START__, __MAIN_SIZE__ ; Linker generated .import __STACKSIZE__ ; from configure file .importzp ST @@ -45,16 +45,24 @@ Start: ldx move_init beq L0 -; Move the INIT segment from where it was loaded (over ZPSAVE and BSS) -; into where it must be run (in the heap). +; Move the INIT segment from where it was loaded (over the bss segments) +; into where it must be run (over the BSS segment). jsr moveinit - dec move_init ; set to false + dec move_init ; Set to false -; Save space by putting the rest of the start-up code in the INIT segment, -; which can be re-used by the heap and the C stack. +; Save space by putting some of the start-up code in the INIT segment, +; which can be re-used by the BSS segment, the heap and the C stack. -L0: jsr initstart +L0: jsr runinit + +; Clear the BSS data. + + jsr zerobss + +; Push the command-line arguments; and, call main(). + + jsr callmain ; Back from main() [this is also the exit() entry]. Run the module destructors. @@ -90,7 +98,7 @@ L2: lda zpsave,x .segment "INIT" -initstart: +runinit: ; Save the zero-page locations that we need. @@ -100,24 +108,16 @@ L1: lda sp,x dex bpl L1 -; Clear the BSS data. - - jsr zerobss - ; Set up the stack. - lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) - ldx #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) + lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) + ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) sta sp stx sp+1 ; Set argument stack ptr ; Call the module constructors. - jsr initlib - -; Push the command-line arguments; and, call main(). - - jmp callmain + jmp initlib ; ------------------------------------------------------------------------ @@ -134,6 +134,6 @@ spsave: .res 1 move_init: .byte 1 -.segment "ZPSAVE" +.segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/c64/mainargs.s b/libsrc/c64/mainargs.s index 1c9031eb0..a31c1b54f 100644 --- a/libsrc/c64/mainargs.s +++ b/libsrc/c64/mainargs.s @@ -28,10 +28,9 @@ .include "c64.inc" - MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run @@ -42,24 +41,24 @@ initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + + lda #0 ; The terminating NUL character ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda (FNAM),y - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - beq done ; no "rem," no args. + beq done ; No "rem," no args. inx cmp #REM bne L2 @@ -71,7 +70,7 @@ next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we @@ -126,15 +125,13 @@ done: lda #<argv stx __argv + 1 rts -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name .res MAXARGS * 2 - diff --git a/libsrc/cbm/filedes.s b/libsrc/cbm/filedes.s index 384313b94..ddce1be4d 100644 --- a/libsrc/cbm/filedes.s +++ b/libsrc/cbm/filedes.s @@ -5,6 +5,7 @@ ; + .include "cbm.inc" .include "filedes.inc" .code @@ -29,9 +30,14 @@ found: rts ;-------------------------------------------------------------------------- ; Data -.bss -fdtab: .res MAX_FDS -unittab:.res MAX_FDS - +.data +fdtab: .byte LFN_READ + .byte LFN_WRITE + .byte LFN_WRITE + .res MAX_FDS-3 +unittab:.byte CBMDEV_KBD + .byte CBMDEV_SCREEN + .byte CBMDEV_SCREEN + .res MAX_FDS-3 diff --git a/libsrc/cbm/filevars.s b/libsrc/cbm/filevars.s index 316cf2762..db2dec7b3 100644 --- a/libsrc/cbm/filevars.s +++ b/libsrc/cbm/filevars.s @@ -9,7 +9,7 @@ .importzp devnum -.bss +.segment "INITBSS" curunit: .res 1 diff --git a/libsrc/cbm/read.s b/libsrc/cbm/read.s index aa692a34a..e0fd8d51b 100644 --- a/libsrc/cbm/read.s +++ b/libsrc/cbm/read.s @@ -26,11 +26,8 @@ .proc initstdin - lda #LFN_READ - sta fdtab+STDIN_FILENO lda #STDIN_FILENO + LFN_OFFS ldx #CBMDEV_KBD - stx unittab+STDIN_FILENO ldy #$FF jsr SETLFS jmp OPEN ; Will always succeed @@ -155,5 +152,3 @@ invalidfd: .bss unit: .res 1 - - diff --git a/libsrc/cbm/write.s b/libsrc/cbm/write.s index fdf7cfbc1..e6da59c0f 100644 --- a/libsrc/cbm/write.s +++ b/libsrc/cbm/write.s @@ -24,12 +24,6 @@ .proc initstdout - lda #LFN_WRITE - sta fdtab+STDOUT_FILENO - sta fdtab+STDERR_FILENO - lda #CBMDEV_SCREEN - sta unittab+STDOUT_FILENO - sta unittab+STDERR_FILENO lda #STDOUT_FILENO + LFN_OFFS jsr @L1 lda #STDERR_FILENO + LFN_OFFS @@ -122,7 +116,3 @@ invalidfd: jmp __directerrno ; Sets _errno, clears _oserror, returns -1 .endproc - - - - diff --git a/libsrc/cbm510/mainargs.s b/libsrc/cbm510/mainargs.s index 7eebccbb3..0ec7d0c4c 100644 --- a/libsrc/cbm510/mainargs.s +++ b/libsrc/cbm510/mainargs.s @@ -31,10 +31,9 @@ .macpack generic - MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run. @@ -61,40 +60,42 @@ initmainargs: ldy #FNAM_LEN lda (sysp0),y tay + lda #0 ; The terminating NUL character stx IndReg ; Look for name in correct bank cpy #NAME_LEN + 1 blt L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda (ptr1),y - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 jsr restore_bank inc __argc ; argc always is equal to at least 1 ; Find a "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - bze done ; no "rem," no args. + bze done ; No "rem," no args. inx cmp #REM bne L2 ldy #1 * 2 ; Find the next argument. -; + next: lda BASIC_BUF,x bze done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. That is useful because we ; will check now for a quoted argument; in which case, we will have to skip that ; first character. -; + found: cmp #'"' ; Is the argument quoted? beq setterm ; Jump if so dex ; Reset pointer to first argument character @@ -102,7 +103,7 @@ found: cmp #'"' ; Is the argument quoted? setterm:sta term ; Set end-of-argument marker ; Now, store a pointer to the argument into the next slot. -; + txa ; Get low byte add #<BASIC_BUF sta argv,y ; argv[y]= &arg @@ -114,7 +115,7 @@ setterm:sta term ; Set end-of-argument marker inc __argc ; Found another arg ; Search for the end of the argument. -; + argloop:lda BASIC_BUF,x bze done inx @@ -124,7 +125,7 @@ argloop:lda BASIC_BUF,x ; We've found the end of the argument. X points one character behind it, and ; A contains the terminating character. To make the argument a valid C string, ; replace the terminating character by a zero. -; + lda #$00 sta BASIC_BUF-1,x @@ -136,21 +137,20 @@ argloop:lda BASIC_BUF,x blt next ; Parse next one if not ; (The last vector in argv[] already is NULL.) -; + done: lda #<argv ldx #>argv sta __argv stx __argv + 1 rts -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name - .res MAXARGS * 2, $00 + .res MAXARGS * 2 diff --git a/libsrc/cbm610/mainargs.s b/libsrc/cbm610/mainargs.s index 9388eac81..02461ac26 100644 --- a/libsrc/cbm610/mainargs.s +++ b/libsrc/cbm610/mainargs.s @@ -31,10 +31,9 @@ .macpack generic - MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run. @@ -45,9 +44,7 @@ initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + jsr sys_bank ldy #FNAM lda (sysp0),y ; Get file-name pointer from system bank @@ -61,40 +58,42 @@ initmainargs: ldy #FNAM_LEN lda (sysp0),y tay + lda #0 ; The terminating NUL character stx IndReg ; Look for name in correct bank cpy #NAME_LEN + 1 blt L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda (ptr1),y - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 jsr restore_bank inc __argc ; argc always is equal to at least 1 ; Find a "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - bze done ; no "rem," no args. + bze done ; No "rem," no args. inx cmp #REM bne L2 ldy #1 * 2 ; Find the next argument. -; + next: lda BASIC_BUF,x bze done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. That is useful because we ; will check now for a quoted argument; in which case, we will have to skip that ; first character. -; + found: cmp #'"' ; Is the argument quoted? beq setterm ; Jump if so dex ; Reset pointer to first argument character @@ -102,7 +101,7 @@ found: cmp #'"' ; Is the argument quoted? setterm:sta term ; Set end-of-argument marker ; Now, store a pointer to the argument into the next slot. -; + txa ; Get low byte add #<BASIC_BUF sta argv,y ; argv[y]= &arg @@ -114,7 +113,7 @@ setterm:sta term ; Set end-of-argument marker inc __argc ; Found another arg ; Search for the end of the argument. -; + argloop:lda BASIC_BUF,x bze done inx @@ -124,33 +123,32 @@ argloop:lda BASIC_BUF,x ; We've found the end of the argument. X points one character behind it, and ; A contains the terminating character. To make the argument a valid C string, ; replace the terminating character by a zero. -; + lda #$00 sta BASIC_BUF-1,x ; Check if the maximum number of command-line arguments is reached. If not, ; parse the next one. -; + lda __argc ; Get low byte of argument count cmp #MAXARGS ; Maximum number of arguments reached? blt next ; Parse next one if not ; (The last vector in argv[] already is NULL.) -; + done: lda #<argv ldx #>argv sta __argv stx __argv + 1 rts -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name - .res MAXARGS * 2, $00 + .res MAXARGS * 2 diff --git a/libsrc/common/_cwd.s b/libsrc/common/_cwd.s index eeda10f1d..7b4031f52 100644 --- a/libsrc/common/_cwd.s +++ b/libsrc/common/_cwd.s @@ -14,12 +14,12 @@ .import initcwd .include "stdio.inc" - + __cwd_buf_size = FILENAME_MAX cwd_init := initcwd -.bss +.segment "INITBSS" __cwd: .res __cwd_buf_size @@ -29,4 +29,3 @@ __cwd: .res __cwd_buf_size ; checking the other sources. .assert __cwd_buf_size < 256, error, "__cwd_buf_size must not be > 255" - diff --git a/libsrc/common/moveinit.s b/libsrc/common/moveinit.s index 2186adf0e..2b22be02d 100644 --- a/libsrc/common/moveinit.s +++ b/libsrc/common/moveinit.s @@ -15,8 +15,8 @@ .data ; Move the INIT segment from where it was loaded (over the bss segments) -; into where it must be run (in the heap). The two areas might overlap; and, -; the segment is moved upwards. Therefore, this code starts at the highest +; into where it must be run (over the BSS segment). The two areas might overlap; +; and, the segment is moved upwards. Therefore, this code starts at the highest ; address, and decrements to the lowest address. The low bytes of the starting ; pointers are not sums. The high bytes are sums; but, they do not include the ; carry. Both the low-byte sums and the carries will be done when the pointers diff --git a/libsrc/common/zerobss.s b/libsrc/common/zerobss.s index de160aeef..2c500f773 100644 --- a/libsrc/common/zerobss.s +++ b/libsrc/common/zerobss.s @@ -9,7 +9,7 @@ .importzp ptr1 -.segment "INIT" +.code zerobss: lda #<__BSS_RUN__ @@ -41,6 +41,3 @@ L3: cpy #<__BSS_SIZE__ ; Done L4: rts - - - diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index 66aed0366..c1c805308 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -94,7 +94,7 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ -.segment "ZPSAVE" +.segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/pet/mainargs.s b/libsrc/pet/mainargs.s index 0d5b18987..8ba6e3117 100644 --- a/libsrc/pet/mainargs.s +++ b/libsrc/pet/mainargs.s @@ -12,7 +12,7 @@ MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ;--------------------------------------------------------------------------- @@ -25,24 +25,24 @@ NAME_LEN = 16 ; maximum length of command-name ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + + lda #0 ; The terminating NUL character ldy FNLEN cpy #NAME_LEN + 1 bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda (FNADR),y - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - beq done ; no "rem," no args. + beq done ; No "rem," no args. inx cmp #REM bne L2 @@ -54,7 +54,7 @@ next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we @@ -111,14 +111,13 @@ done: lda #<argv .endproc -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name .res MAXARGS * 2 diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index b732459e0..ae3297562 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -195,7 +195,7 @@ spsave: .res 1 irqcount: .byte 0 -.segment "ZPSAVE" +.segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/plus4/mainargs.s b/libsrc/plus4/mainargs.s index 7df8402fe..59879978e 100644 --- a/libsrc/plus4/mainargs.s +++ b/libsrc/plus4/mainargs.s @@ -26,12 +26,11 @@ .import __argc, __argv .include "plus4.inc" - MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run @@ -42,24 +41,24 @@ initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + + lda #0 ; The terminating NUL character ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda (FNAM),y - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - beq done ; no "rem," no args. + beq done ; No "rem," no args. inx cmp #REM bne L2 @@ -71,7 +70,7 @@ next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we @@ -125,17 +124,14 @@ done: lda #<argv sta __argv stx __argv + 1 rts - -; -------------------------------------------------------------------------- -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss + +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name .res MAXARGS * 2 - diff --git a/libsrc/runtime/callmain.s b/libsrc/runtime/callmain.s index 83cd74482..0e6a84ebb 100644 --- a/libsrc/runtime/callmain.s +++ b/libsrc/runtime/callmain.s @@ -31,9 +31,9 @@ ;--------------------------------------------------------------------------- ; Data -.bss -__argc: .res 2 -__argv: .res 2 +.data +__argc: .word 0 +__argv: .addr 0 diff --git a/libsrc/runtime/stkchk.s b/libsrc/runtime/stkchk.s index 73df09917..6186fe4e2 100644 --- a/libsrc/runtime/stkchk.s +++ b/libsrc/runtime/stkchk.s @@ -101,14 +101,14 @@ Fail: lda #4 ; ---------------------------------------------------------------------------- ; Data -.bss +.segment "INITBSS" ; Initial stack pointer value. Stack is reset to this in case of overflows to ; allow program exit processing. -initialsp: .word 0 +initialsp: .res 2 ; Stack low water mark. -lowwater: .word 0 +lowwater: .res 2 diff --git a/libsrc/vic20/crt0.s b/libsrc/vic20/crt0.s index e04881987..6a0f94a03 100644 --- a/libsrc/vic20/crt0.s +++ b/libsrc/vic20/crt0.s @@ -86,7 +86,7 @@ L2: lda zpsave,x ; ------------------------------------------------------------------------ -.segment "ZPSAVE" +.segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/vic20/mainargs.s b/libsrc/vic20/mainargs.s index eda8f4f85..a41a1c495 100644 --- a/libsrc/vic20/mainargs.s +++ b/libsrc/vic20/mainargs.s @@ -28,10 +28,9 @@ .include "vic20.inc" - MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +NAME_LEN = 16 ; Maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run @@ -42,24 +41,24 @@ initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. -; Because the buffer, that we're copying into, was zeroed out, -; we don't need to add a NUL character. -; + + lda #0 ; The terminating NUL character ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 - ldy #NAME_LEN - 1 ; limit the length + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always L0: lda (FNAM),y - sta name,y -L1: dey +L1: sta name,y + dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. -; + ldx #0 L2: lda BASIC_BUF,x - beq done ; no "rem," no args. + beq done ; No "rem," no args. inx cmp #REM bne L2 @@ -71,7 +70,7 @@ next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces - beq next ; + beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we @@ -126,15 +125,13 @@ done: lda #<argv stx __argv + 1 rts -; These arrays are zeroed before initmainargs is called. -; char name[16+1]; -; char* argv[MAXARGS+1]={name}; -; -.bss +.segment "INITBSS" + term: .res 1 name: .res NAME_LEN + 1 .data + +; char* argv[MAXARGS+1]={name}; argv: .addr name .res MAXARGS * 2 - From 76a5a72403266b923b9bdc9ccd5f4de2a352459a Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 15 Oct 2015 00:15:38 +0200 Subject: [PATCH 302/351] Adjusted current working directory initialization on Apple and Atari. Moving __cwd from BSS into INITBSS does of course ;-) not only impact the CBM targets but all targets with disk I/O support. Note: Code using `__cwd-1` may trigger an ld65 range error because __cwd may end up at the very begining of a segment. As far as I see this is an ld65 bug which I'm not try to fix - at least here. --- cfg/apple2-overlay.cfg | 4 ++-- cfg/apple2-system.cfg | 4 ++-- cfg/apple2.cfg | 4 ++-- cfg/apple2enh-overlay.cfg | 4 ++-- cfg/apple2enh-system.cfg | 4 ++-- cfg/apple2enh.cfg | 4 ++-- cfg/atari-cart.cfg | 1 + cfg/atari-cassette.cfg | 1 + cfg/atari-overlay.cfg | 1 + cfg/atari.cfg | 1 + cfg/atarixl-largehimem.cfg | 1 + cfg/atarixl-overlay.cfg | 1 + cfg/atarixl.cfg | 1 + libsrc/apple2/crt0.s | 20 ++++++++++---------- libsrc/apple2/initcwd.s | 13 +++++++------ libsrc/atari/initcwd.s | 8 ++++---- 16 files changed, 40 insertions(+), 32 deletions(-) diff --git a/cfg/apple2-overlay.cfg b/cfg/apple2-overlay.cfg index d0b34692f..244e4582f 100644 --- a/cfg/apple2-overlay.cfg +++ b/cfg/apple2-overlay.cfg @@ -18,7 +18,7 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ + + __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ + __MOVE_LAST__ - __MOVE_START__; } MEMORY { @@ -45,7 +45,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + INITBSS: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; LC: load = MOVE, run = LC, type = ro, optional = yes; diff --git a/cfg/apple2-system.cfg b/cfg/apple2-system.cfg index 33ab04f5e..f07208e45 100644 --- a/cfg/apple2-system.cfg +++ b/cfg/apple2-system.cfg @@ -5,7 +5,7 @@ SYMBOLS { __LCSIZE__: type = weak, value = $0C00; # Rest of bank two __STACKSIZE__: type = weak, value = $0800; # 2k stack __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ + + __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ + __MOVE_LAST__ - __MOVE_START__; } MEMORY { @@ -21,7 +21,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + INITBSS: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; LC: load = MOVE, run = LC, type = ro, optional = yes; diff --git a/cfg/apple2.cfg b/cfg/apple2.cfg index 5673302d1..27eb706c4 100644 --- a/cfg/apple2.cfg +++ b/cfg/apple2.cfg @@ -10,7 +10,7 @@ SYMBOLS { __LCSIZE__: type = weak, value = $0C00; # Rest of bank two __STACKSIZE__: type = weak, value = $0800; # 2k stack __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ + + __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ + __MOVE_LAST__ - __MOVE_START__; } MEMORY { @@ -28,7 +28,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + INITBSS: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; LC: load = MOVE, run = LC, type = ro, optional = yes; diff --git a/cfg/apple2enh-overlay.cfg b/cfg/apple2enh-overlay.cfg index d0b34692f..244e4582f 100644 --- a/cfg/apple2enh-overlay.cfg +++ b/cfg/apple2enh-overlay.cfg @@ -18,7 +18,7 @@ SYMBOLS { __STACKSIZE__: type = weak, value = $0800; # 2k stack __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ + + __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ + __MOVE_LAST__ - __MOVE_START__; } MEMORY { @@ -45,7 +45,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + INITBSS: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; LC: load = MOVE, run = LC, type = ro, optional = yes; diff --git a/cfg/apple2enh-system.cfg b/cfg/apple2enh-system.cfg index 33ab04f5e..f07208e45 100644 --- a/cfg/apple2enh-system.cfg +++ b/cfg/apple2enh-system.cfg @@ -5,7 +5,7 @@ SYMBOLS { __LCSIZE__: type = weak, value = $0C00; # Rest of bank two __STACKSIZE__: type = weak, value = $0800; # 2k stack __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ + + __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ + __MOVE_LAST__ - __MOVE_START__; } MEMORY { @@ -21,7 +21,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + INITBSS: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; LC: load = MOVE, run = LC, type = ro, optional = yes; diff --git a/cfg/apple2enh.cfg b/cfg/apple2enh.cfg index 5673302d1..27eb706c4 100644 --- a/cfg/apple2enh.cfg +++ b/cfg/apple2enh.cfg @@ -10,7 +10,7 @@ SYMBOLS { __LCSIZE__: type = weak, value = $0C00; # Rest of bank two __STACKSIZE__: type = weak, value = $0800; # 2k stack __LOADADDR__: type = weak, value = __STARTUP_RUN__; - __LOADSIZE__: type = weak, value = __ZPSAVE_RUN__ - __STARTUP_RUN__ + + __LOADSIZE__: type = weak, value = __INITBSS_RUN__ - __STARTUP_RUN__ + __MOVE_LAST__ - __MOVE_START__; } MEMORY { @@ -28,7 +28,7 @@ SEGMENTS { CODE: load = RAM, type = ro; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; - ZPSAVE: load = RAM, type = bss, define = yes; + INITBSS: load = RAM, type = bss, define = yes; BSS: load = RAM, type = bss, define = yes; INIT: load = MOVE, run = RAM, type = ro, define = yes, optional = yes; LC: load = MOVE, run = LC, type = ro, optional = yes; diff --git a/cfg/atari-cart.cfg b/cfg/atari-cart.cfg index db9486a9f..58457c606 100644 --- a/cfg/atari-cart.cfg +++ b/cfg/atari-cart.cfg @@ -22,6 +22,7 @@ SEGMENTS { CODE: load = ROM, type = ro, define = yes; RODATA: load = ROM, type = ro, optional = yes; DATA: load = ROM, run = RAM, type = rw, define = yes, optional = yes; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes, optional = yes; CARTHDR: load = CARTID, type = ro; ZEROPAGE: load = ZP, type = zp, optional = yes; diff --git a/cfg/atari-cassette.cfg b/cfg/atari-cassette.cfg index 2116aecd0..80b5c695f 100644 --- a/cfg/atari-cassette.cfg +++ b/cfg/atari-cassette.cfg @@ -19,6 +19,7 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro, optional = yes; DATA: load = RAM, type = rw, optional = yes; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes, optional = yes; ZEROPAGE: load = ZP, type = zp, optional = yes; EXTZP: load = ZP, type = zp, optional = yes; diff --git a/cfg/atari-overlay.cfg b/cfg/atari-overlay.cfg index 1d339b208..b3abad988 100644 --- a/cfg/atari-overlay.cfg +++ b/cfg/atari-overlay.cfg @@ -49,6 +49,7 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; diff --git a/cfg/atari.cfg b/cfg/atari.cfg index dce593f05..97b289d7e 100644 --- a/cfg/atari.cfg +++ b/cfg/atari.cfg @@ -37,6 +37,7 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 01fc76a26..f96096995 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -70,6 +70,7 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 68d0f524e..7356fc03e 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -82,6 +82,7 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index aad3ce613..84992a205 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -68,6 +68,7 @@ SEGMENTS { CODE: load = RAM, type = ro, define = yes; RODATA: load = RAM, type = ro; DATA: load = RAM, type = rw; + INITBSS: load = RAM, type = bss, optional = yes; BSS: load = RAM, type = bss, define = yes; ZEROPAGE: load = ZP, type = zp; EXTZP: load = ZP, type = zp, optional = yes; diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index 445039b1e..f061b212b 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -11,7 +11,7 @@ .import callmain .import __LC_START__, __LC_LAST__ ; Linker generated .import __INIT_RUN__, __INIT_SIZE__ ; Linker generated - .import __ZPSAVE_RUN__ ; Linker generated + .import __INITBSS_RUN__ ; Linker generated .include "zeropage.inc" .include "apple2.inc" @@ -29,14 +29,14 @@ bit $C081 ; Set the source start address. - lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__) - ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__) + lda #<(__INITBSS_RUN__ + __INIT_SIZE__) + ldy #>(__INITBSS_RUN__ + __INIT_SIZE__) sta $9B sty $9C ; Set the source last address. - lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) - ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) + lda #<(__INITBSS_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) + ldy #>(__INITBSS_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) sta $96 sty $97 @@ -51,14 +51,14 @@ jsr $D39A ; BLTU2 ; Set the source start address. - lda #<__ZPSAVE_RUN__ - ldy #>__ZPSAVE_RUN__ + lda #<__INITBSS_RUN__ + ldy #>__INITBSS_RUN__ sta $9B sty $9C ; Set the source last address. - lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__) - ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__) + lda #<(__INITBSS_RUN__ + __INIT_SIZE__) + ldy #>(__INITBSS_RUN__ + __INIT_SIZE__) sta $96 sty $97 @@ -201,7 +201,7 @@ q_param:.byte $04 ; param_count ; Final jump when we're done done: jmp DOSWARM ; Potentially patched at runtime - .segment "ZPSAVE" + .segment "INITBSS" zpsave: .res zpspace diff --git a/libsrc/apple2/initcwd.s b/libsrc/apple2/initcwd.s index 044076e3f..7af29c75e 100644 --- a/libsrc/apple2/initcwd.s +++ b/libsrc/apple2/initcwd.s @@ -21,20 +21,21 @@ initcwd: jsr callmli ; Check for null prefix - lda __cwd + ldx __cwd beq done ; Remove length byte and trailing slash - sta tmp1 - ldx #$01 -: lda __cwd,x - sta __cwd - 1,x + dex + stx tmp1 + ldx #$00 +: lda __cwd + 1,x + sta __cwd,x inx cpx tmp1 bcc :- ; Add terminating zero lda #$00 - sta __cwd - 1,x + sta __cwd,x done: rts diff --git a/libsrc/atari/initcwd.s b/libsrc/atari/initcwd.s index 074b9476f..c292e72c3 100644 --- a/libsrc/atari/initcwd.s +++ b/libsrc/atari/initcwd.s @@ -21,13 +21,13 @@ sta ICBLH,x jsr CIOV bmi oserr - ldx #0 ; ATEOL -> \0 -: lda __cwd,x - inx + ldx #$FF ; ATEOL -> \0 +: inx + lda __cwd,x cmp #ATEOL bne :- lda #0 - sta __cwd-1,x + sta __cwd,x oserr: rts .endproc From 8263083506e54b5f97cb6373d172877219565ac0 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 15 Oct 2015 15:11:05 +0200 Subject: [PATCH 303/351] move variables into INITBSS --- libsrc/c64/soft80_conio.s | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index d2dfb913e..4e24a0341 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -149,11 +149,7 @@ soft80_bitmapyhi_data: soft80_tables_data_end: ;------------------------------------------------------------------------------- -; FIXME: when the code is fixed to use the "init" segment, these variables must -; be moved into a section other than .bss so they survive after the init -; code has been run. - - .data ; FIXME + .segment "INITBSS" soft80_internal_cellcolor: .res 1 soft80_internal_bgcolor: From f94945308fac8af7cfce8aebe159783eb8d8bd9e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 17 Oct 2015 11:53:16 -0400 Subject: [PATCH 304/351] Added missing parentheses. A function call had looked like a function pointer (which caused an incompatible comparison). --- samples/sieve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/sieve.c b/samples/sieve.c index 9f110ec98..8d0619888 100644 --- a/samples/sieve.c +++ b/samples/sieve.c @@ -110,7 +110,7 @@ int main (void) J = 0; } } - if (kbhit() && ReadUpperKey == 'Q') { + if (kbhit() && ReadUpperKey () == 'Q') { break; } } From 5099910b18c9ed9bb6603d3f9b4622e2039020a2 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 18 Oct 2015 23:57:58 +0200 Subject: [PATCH 305/351] updated docs --- doc/c64.sgml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/c64.sgml b/doc/c64.sgml index ca99e0061..f22eca3e1 100644 --- a/doc/c64.sgml +++ b/doc/c64.sgml @@ -116,6 +116,30 @@ cl65 -o file.prg -u __EXEHDR__ -t c64 -C c64-asm.cfg source.s Please note that in this case a changed start address doesn't make sense, since the program must be loaded to the BASIC start address. +<sect>Extras<p> + +<sect1>80 Columns conio driver<p> + +The C64 package comes with an alternative software driven 80 columns +module <tt/c64-soft80.o/ which uses the memory under I/O between $d000 +and $ffff. + +In memory constrained situations the memory from $400 to $7FF +can be made available to a program by calling <tt/_heapadd ((void *) 0x400, 0x400);/ +at the beginning of <tt/main()/. Doing so is beneficial even if the program +doesn't use the the heap explicitly because loading a driver (and in fact +already opening a driver file) uses the heap implicitly. + +Using <tt/c64-soft80.o/ is as simple as placing it on the linker command +line like this: + +<tscreen><verb> +cl65 -t c64 myprog.c c64-soft80.o +</verb></tscreen> + +Note that the soft80 conio driver is incompatible with the +<tt/c64-ram.emd (c64_ram_emd)/ extended memory driver and the + <tt/c64-hi.tgi (c64_hi_tgi)/ graphics driver. <sect>Platform-specific header files<p> @@ -216,6 +240,9 @@ configuration. palette of the 16 C64 colors). </descrip><p> +Note that the graphics drivers are incompatible with the +<tt/c64-ram.emd (c64_ram_emd)/ extended memory driver and the + <tt/c64-soft80.o/ software 80 columns conio driver. <sect1>Extended memory drivers<p> @@ -241,7 +268,7 @@ configuration. <tag><tt/c64-ram.emd (c64_ram_emd)/</tag> A driver for the hidden RAM below the I/O area and kernal ROM. Supports 48 256 byte pages. Please note that this driver is incompatible with any of the - graphics drivers! + graphics drivers, or the soft80 conio driver! <tag><tt/c64-ramcart.emd (c64_ramcart_emd)/</tag> A driver for the RamCart 64/128 written and contributed by Maciej Witkowiak. From d6d016bb80bcfd3b40c218b16e7dc31425fa7792 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 19 Oct 2015 02:47:40 +0200 Subject: [PATCH 306/351] updated comments --- libsrc/c64/soft80_cgetc.s | 2 ++ libsrc/c64/soft80_charset.s | 2 +- libsrc/c64/soft80_color.s | 2 ++ libsrc/c64/soft80_cputc.s | 2 ++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libsrc/c64/soft80_cgetc.s b/libsrc/c64/soft80_cgetc.s index 5343027bb..ae0e23857 100644 --- a/libsrc/c64/soft80_cgetc.s +++ b/libsrc/c64/soft80_cgetc.s @@ -1,6 +1,8 @@ ; ; Groepaz/Hitmen, 11.10.2015 ; +; high level implementation for the soft80 implementation +; ; char cgetc (void); ; diff --git a/libsrc/c64/soft80_charset.s b/libsrc/c64/soft80_charset.s index 678439a30..69fd3527f 100644 --- a/libsrc/c64/soft80_charset.s +++ b/libsrc/c64/soft80_charset.s @@ -1,7 +1,7 @@ ; ; Groepaz/Hitmen, 12.10.2015 ; -; character set for use with the soft80 implementation +; character set for use with the soft80 implementations ; ; the format of the data follows the following layout: diff --git a/libsrc/c64/soft80_color.s b/libsrc/c64/soft80_color.s index bbd666af7..8c1d113ac 100644 --- a/libsrc/c64/soft80_color.s +++ b/libsrc/c64/soft80_color.s @@ -1,6 +1,8 @@ ; ; Groepaz/Hitmen, 12.10.2015 ; +; high level implementation for the soft80 implementation +; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); ; diff --git a/libsrc/c64/soft80_cputc.s b/libsrc/c64/soft80_cputc.s index 1ded7ef6a..acbe5b560 100644 --- a/libsrc/c64/soft80_cputc.s +++ b/libsrc/c64/soft80_cputc.s @@ -1,6 +1,8 @@ ; ; Groepaz/Hitmen, 11.10.2015 ; +; high level implementation for the soft80 implementation +; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; From 60334c40e6191d48b540d26e3ec79e091886c0c4 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 19 Oct 2015 02:49:32 +0200 Subject: [PATCH 307/351] added size optimized monochrom soft80 driver --- libsrc/c64/extra/soft80mono.s | 55 +++++++++ libsrc/c64/soft80mono_cgetc.s | 66 ++++++++++ libsrc/c64/soft80mono_color.s | 65 ++++++++++ libsrc/c64/soft80mono_conio.s | 168 ++++++++++++++++++++++++++ libsrc/c64/soft80mono_cputc.s | 205 ++++++++++++++++++++++++++++++++ libsrc/c64/soft80mono_kclrscr.s | 63 ++++++++++ libsrc/c64/soft80mono_kplot.s | 52 ++++++++ 7 files changed, 674 insertions(+) create mode 100644 libsrc/c64/extra/soft80mono.s create mode 100644 libsrc/c64/soft80mono_cgetc.s create mode 100644 libsrc/c64/soft80mono_color.s create mode 100644 libsrc/c64/soft80mono_conio.s create mode 100644 libsrc/c64/soft80mono_cputc.s create mode 100644 libsrc/c64/soft80mono_kclrscr.s create mode 100644 libsrc/c64/soft80mono_kplot.s diff --git a/libsrc/c64/extra/soft80mono.s b/libsrc/c64/extra/soft80mono.s new file mode 100644 index 000000000..f91f4a76a --- /dev/null +++ b/libsrc/c64/extra/soft80mono.s @@ -0,0 +1,55 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; import/overload stubs for the monochrome soft80 implementation +; +; - optimized for size, almost 1k smaller footprint than the full color version +; - textcolor() sets one common text color for the whole screen +; + .include "../soft80.inc" + + ; soft80mono_cgetc.s + .import soft80mono_cgetc + .export _cgetc := soft80mono_cgetc ; cgetc.s + + ; soft80mono_color.s + .import soft80mono_textcolor + .import soft80mono_bgcolor + .export _textcolor := soft80mono_textcolor ; color.s + .export _bgcolor := soft80mono_bgcolor ; color.s + + ; soft80mono_cputc.s + .import soft80mono_cputc + .import soft80mono_cputcxy + .import soft80mono_cputdirect + .import soft80mono_putchar + .import soft80mono_newline + .import soft80mono_plot + .export _cputc := soft80mono_cputc ; cputc.s + .export _cputcxy := soft80mono_cputcxy ; cputc.s + .export cputdirect := soft80mono_cputdirect ; cputc.s + .export putchar := soft80mono_putchar ; cputc.s + .export newline := soft80mono_newline ; cputc.s + .export plot := soft80mono_plot ; cputc.s + + ; soft80mono_kclrscr.s + .import soft80mono_kclrscr + .export _clrscr := soft80mono_kclrscr ; clrscr.s + .export CLRSCR := soft80mono_kclrscr ; kernal func (c64.inc) + + ; soft80mono_kplot.s + .import soft80mono_kplot + .export PLOT := soft80mono_kplot ; kplot.s + + ; soft80_kscreen.s + .import soft80_screensize + .export screensize := soft80_screensize ; _scrsize.s + .export SCREEN := soft80_screensize ; kernal func (kernal.s) + + ; VIC sprite data for the mouse pointer + .export mcb_spritememory := soft80_spriteblock + .export mcb_spritepointer := (soft80_vram + $03F8) + + ; Chars used by chline () and cvline () + .exportzp chlinechar = CH_HLINE + .exportzp cvlinechar = CH_VLINE diff --git a/libsrc/c64/soft80mono_cgetc.s b/libsrc/c64/soft80mono_cgetc.s new file mode 100644 index 000000000..d99dc7775 --- /dev/null +++ b/libsrc/c64/soft80mono_cgetc.s @@ -0,0 +1,66 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; high level implementation for the monochrome soft80 implementation +; +; char cgetc (void); +; + + .export soft80mono_cgetc + .import soft80mono_internal_cellcolor, soft80mono_internal_cursorxlsb + .import soft80mono_internal_nibble + .import cursor + .importzp tmp1 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_cgetc: + lda KEY_COUNT ; Get number of characters + bne @L3 ; Jump if there are already chars waiting + + jsr invertcursor ; set cursor on or off accordingly + +@L1: lda KEY_COUNT ; wait for key + beq @L1 + + jsr invertcursor ; set cursor on or off accordingly + +@L3: jsr KBDREAD ; Read char and return in A + ldx #0 + rts + +; Switch the cursor on or off (invert) + +invertcursor: + lda cursor + bne @invert + rts +@invert: + + sei + lda $01 ; enable RAM under I/O + pha + lda #$34 + sta $01 + + ldy #$00 + ldx soft80mono_internal_cursorxlsb +@lp1: + lda (SCREEN_PTR),y + eor soft80mono_internal_nibble,x + sta (SCREEN_PTR),y + iny + cpy #8 + bne @lp1 + + pla + sta $01 ; enable I/O + cli + rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80mono_init +conio_init = soft80mono_init diff --git a/libsrc/c64/soft80mono_color.s b/libsrc/c64/soft80mono_color.s new file mode 100644 index 000000000..aa24957d5 --- /dev/null +++ b/libsrc/c64/soft80mono_color.s @@ -0,0 +1,65 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; high level implementation for the monochrome soft80 implementation +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; + + .export soft80mono_textcolor, soft80mono_bgcolor + .import soft80mono_internal_cellcolor, soft80mono_internal_bgcolor + + .importzp tmp1 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_textcolor: + ldx CHARCOLOR ; get old value + stx tmp1 ; save old value + sta CHARCOLOR ; set new value + +mkcharcolor: + lda soft80mono_internal_bgcolor + asl a + asl a + asl a + asl a + ora CHARCOLOR + sta soft80mono_internal_cellcolor ; text/bg combo for new chars + + sei + ldy $01 + lda #$34 ; enable RAM under I/O + sta $01 + + lda soft80mono_internal_cellcolor + ; clear loop for vram + ldx #$00 +@lp1: + sta soft80_vram,x + sta soft80_vram+$100,x + sta soft80_vram+$200,x + sta soft80_vram+$2e8,x + inx + bne @lp1 + + sty $01 + cli + + lda tmp1 ; get old value + rts + +soft80mono_bgcolor: + ldx soft80mono_internal_bgcolor ; get old value + stx tmp1 ; save old value + sta soft80mono_internal_bgcolor ; set new value + + jmp mkcharcolor + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80mono_init +conio_init = soft80mono_init diff --git a/libsrc/c64/soft80mono_conio.s b/libsrc/c64/soft80mono_conio.s new file mode 100644 index 000000000..759b280c6 --- /dev/null +++ b/libsrc/c64/soft80mono_conio.s @@ -0,0 +1,168 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; Low level init code for the monochrome soft80 screen output/console input +; + + .constructor soft80mono_init, 8 + .destructor soft80mono_shutdown + + .import soft80mono_kclrscr, soft80_charset + .export soft80mono_internal_bgcolor, soft80mono_internal_cellcolor + .export soft80mono_internal_cursorxlsb + .export soft80mono_internal_nibble + + .importzp ptr1, ptr2, ptr3 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_init: + lda soft80mono_first_init + bne @skp + jsr firstinit +@skp: + ; the "color voodoo" in other parts of the code relies on the vram and + ; colorram being set up as expected, which is why we cant use the + ; _bgcolor and _textcolor functions here. + + lda CHARCOLOR ; use current textcolor + and #$0f ; make sure the upper nibble is 0s + sta CHARCOLOR + + lda VIC_BG_COLOR0 ; use current bgcolor + and #$0f + sta soft80mono_internal_bgcolor + asl a + asl a + asl a + asl a + ora CHARCOLOR + sta soft80mono_internal_cellcolor + + lda #$3b + sta VIC_CTRL1 + lda #$00 + sta CIA2_PRA + lda #$68 + sta VIC_VIDEO_ADR + lda #$c8 + sta VIC_CTRL2 + + jmp soft80mono_kclrscr + +soft80mono_shutdown: + lda #$1b + sta VIC_CTRL1 + lda #$03 + sta CIA2_PRA + lda #$15 + sta VIC_VIDEO_ADR + rts + + .segment "INIT" +firstinit: + ; copy charset to RAM under I/O + sei + lda $01 + pha + lda #$34 + sta $01 + + inc soft80mono_first_init + + lda #>soft80_charset + sta ptr1+1 + lda #<soft80_charset + sta ptr1 + lda #>soft80_lo_charset + sta ptr2+1 + lda #<soft80_lo_charset + sta ptr2 + lda #>soft80_hi_charset + sta ptr3+1 + lda #<soft80_hi_charset + sta ptr3 + + ldx #4 +@l2: + ldy #0 +@l1: + lda (ptr1),y + sta (ptr2),y + asl a + asl a + asl a + asl a + sta (ptr3),y + iny + bne @l1 + inc ptr1+1 + inc ptr2+1 + inc ptr3+1 + dex + bne @l2 + + ; copy the kplot tables to ram under I/O + ;ldx #0 ; is 0 +@l3: + lda soft80_tables_data_start,x + sta soft80_bitmapxlo,x + lda soft80_tables_data_start + (soft80_tables_data_end - soft80_tables_data_start - $100) ,x + sta soft80_bitmapxlo + (soft80_tables_data_end - soft80_tables_data_start - $100),x + inx + bne @l3 + + pla + sta $01 + cli + rts + +; the following tables take up 267 bytes, used by kplot +soft80_tables_data_start: + +soft80_bitmapxlo_data: + .repeat 80,col + .byte <((col/2)*8) + .endrepeat +soft80_bitmapxhi_data: + .repeat 80,col + .byte >((col/2)*8) + .endrepeat +soft80_vramlo_data: + .repeat 25,row + .byte <(soft80_vram+(row*40)) + .endrepeat + .byte 0,0,0,0,0,0,0 ; padding to next page +soft80_vramhi_data: + .repeat 25,row + .byte >(soft80_vram+(row*40)) + .endrepeat +soft80_bitmapylo_data: + .repeat 25,row + .byte <(soft80_bitmap+(row*40*8)) + .endrepeat +soft80_bitmapyhi_data: + .repeat 25,row + .byte >(soft80_bitmap+(row*40*8)) + .endrepeat + +soft80_tables_data_end: + +;------------------------------------------------------------------------------- + .segment "INITBSS" +soft80mono_internal_cellcolor: + .res 1 +soft80mono_internal_bgcolor: + .res 1 +soft80mono_internal_cursorxlsb: + .res 1 + + .data +soft80mono_first_init: + .byte 0 ; flag to check first init, this really must be in .data + + .rodata +soft80mono_internal_nibble: + .byte $f0, $0f + diff --git a/libsrc/c64/soft80mono_cputc.s b/libsrc/c64/soft80mono_cputc.s new file mode 100644 index 000000000..c89362cb5 --- /dev/null +++ b/libsrc/c64/soft80mono_cputc.s @@ -0,0 +1,205 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; high level implementation for the monochrome soft80 implementation +; +; void cputcxy (unsigned char x, unsigned char y, char c); +; void cputc (char c); +; + + .export soft80mono_cputcxy, soft80mono_cputc + .export soft80mono_cputdirect, soft80mono_putchar + .export soft80mono_newline, soft80mono_plot + + .import popa, _gotoxy + + .import soft80mono_kplot + .import soft80mono_internal_bgcolor, soft80mono_internal_cellcolor + .import soft80mono_internal_cursorxlsb, soft80mono_internal_nibble + + .importzp tmp4, tmp3, ptr2 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_cputcxy: + pha ; Save C + jsr popa ; Get Y + jsr _gotoxy ; Set cursor, drop x + pla ; Restore C + +; Plot a character - also used as internal function + +soft80mono_cputc: + cmp #$0A ; CR? + bne L1 + + lda #0 + sta CURS_X + + ; Set cursor position, calculate RAM pointers +soft80mono_plot: + ldx CURS_Y + ldy CURS_X + clc + jmp soft80mono_kplot ; Set the new cursor + +L1: cmp #$0D ; LF? + beq soft80mono_newline ; Recalculate pointers + + ; shortcut for codes < $80 ... codes $20-$7f can be printed directly, + ; codes $00-$1f are control codes which are not printable and thus may + ; give undefined result. + tay + bpl @L10 + + ; codes $80-$ff must get converted like this: + ; $80-$9f -> dont care (control codes) + ; $a0-$bf -> $00-$1f + ; $c0-$df -> $60-$7f + ; $e0-$ff -> $00-$1f + + ora #%01000000 ; $40 + clc + adc #%00100000 ; $20 + and #%01111111 ; $7f +@L10: + + ; entry point for direct output of a character. the value passed in + ; akku must match the offset in the charset. + ; - the following may not modify tmp1 +soft80mono_cputdirect: + jsr soft80mono_putchar ; Write the character to the screen + + ; Advance cursor position + iny ; contains CURS_X + cpy #charsperline + beq @L3 + + sty CURS_X + tya + and #$01 + sta soft80mono_internal_cursorxlsb + bne @L4 + + lda SCREEN_PTR + clc + adc #8 + sta SCREEN_PTR + bcc @L4 + inc SCREEN_PTR+1 +@L4: + rts +@L3: + inc CURS_Y ; new line + ldy #0 ; + cr + sty CURS_X + jmp soft80mono_plot + + ; - the following may not modify tmp1 +soft80mono_newline: + + lda SCREEN_PTR + clc + adc #<(40*8) + sta SCREEN_PTR + + lda SCREEN_PTR+1 + adc #>(40*8) + sta SCREEN_PTR+1 + + inc CURS_Y + rts + +;------------------------------------------------------------------------------- +; output one character in internal encoding without advancing cursor position +; generic entry point +; +; - the following may not modify tmp1 +; in: A: charcode +; out: Y: CURS_X +; +soft80mono_putchar: + sta tmp3 ; save charcode + + sei + lda $01 + pha + lda #$34 + sta $01 ; enable RAM under I/O + + ldy #$00 ; will be $00 from now on + + ldx soft80mono_internal_cursorxlsb + lda chardatal,x + clc + adc tmp3 + sta ptr2 + lda chardatah,x + adc #0 + sta ptr2+1 + + lda RVS + bne draw_charinvers + + lda nibble,x + sta tmp3 + + ;ldy #0 ; is still $00 +@lp1: + lda (SCREEN_PTR),y + and tmp3 + ora (ptr2),y + sta (SCREEN_PTR),y + clc + lda ptr2 + adc #$7f + sta ptr2 + bcc @sk1 + inc ptr2+1 +@sk1: + iny + cpy #8 + bne @lp1 + +draw_back: + pla + sta $01 + cli + + ldy CURS_X + rts + +; output inverted character +draw_charinvers: + lda soft80mono_internal_nibble,x + sta tmp3 + + ;ldy #0 ; is still $00 +@lp1: + lda (SCREEN_PTR),y + ora tmp3 + eor (ptr2),y + sta (SCREEN_PTR),y + clc + lda ptr2 + adc #$7f + sta ptr2 + bcc @sk1 + inc ptr2+1 +@sk1: + iny + cpy #8 + bne @lp1 + jmp draw_back + + .rodata +chardatal: + .byte <soft80_hi_charset + .byte <soft80_lo_charset +chardatah: + .byte >soft80_hi_charset + .byte >soft80_lo_charset +nibble: + .byte $0f, $f0 + diff --git a/libsrc/c64/soft80mono_kclrscr.s b/libsrc/c64/soft80mono_kclrscr.s new file mode 100644 index 000000000..99243c699 --- /dev/null +++ b/libsrc/c64/soft80mono_kclrscr.s @@ -0,0 +1,63 @@ +; +; Groepaz/Hitmen, 19.10.2015 +; +; lowlevel kclrscr for the monochrome soft80 implementation +; + + .export soft80mono_kclrscr + .import soft80mono_kplot + .import soft80mono_internal_bgcolor, soft80mono_internal_cellcolor + .importzp ptr1 + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_kclrscr: + + lda #<soft80_bitmap + sta ptr1 + lda #>soft80_bitmap + sta ptr1+1 + + lda #$ff + + ldx #$1f +@lp2: + ldy #0 +@lp1: + sta (ptr1),y + iny + bne @lp1 + inc ptr1+1 + dex + bne @lp2 + + ;ldx #$00 +@lp3: + sta soft80_bitmap+$1e40,x + inx + bne @lp3 + + sei + ldy $01 + lda #$34 ; enable RAM under I/O + sta $01 + + lda soft80mono_internal_cellcolor + ; clear loop for vram + ;ldx #$00 +@lp4: + sta soft80_vram,x + sta soft80_vram+$100,x + sta soft80_vram+$200,x + sta soft80_vram+$2e8,x + inx + bne @lp4 + + sty $01 + cli + + ldx #0 + ldy #0 + clc + jmp soft80mono_kplot diff --git a/libsrc/c64/soft80mono_kplot.s b/libsrc/c64/soft80mono_kplot.s new file mode 100644 index 000000000..b987924f3 --- /dev/null +++ b/libsrc/c64/soft80mono_kplot.s @@ -0,0 +1,52 @@ + +; +; Groepaz/Hitmen, 19.10.2015 +; +; lowlevel kplot function for the monochrome soft80 implementation +; + + .export soft80mono_kplot + .import soft80mono_internal_cursorxlsb + + .include "c64.inc" + .include "soft80.inc" + +soft80mono_kplot: + bcs @getpos + + stx CURS_Y + sty CURS_X + + sei + lda $01 + pha + lda #$34 ; enable RAM under I/O + sta $01 + + ; calc pointer to bitmap + lda soft80_bitmapylo,x + clc + adc soft80_bitmapxlo,y + sta SCREEN_PTR + lda soft80_bitmapyhi,x + adc soft80_bitmapxhi,y + sta SCREEN_PTR+1 + + tya + and #1 + sta soft80mono_internal_cursorxlsb + + pla + sta $01 + cli + +@getpos: + ldx CURS_Y + ldy CURS_X + rts + +;------------------------------------------------------------------------------- +; force the init constructor to be imported + + .import soft80mono_init +conio_init = soft80mono_init From 07a77d1259087e683f48033d5f6cde9596c36cdf Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Mon, 19 Oct 2015 03:12:19 +0200 Subject: [PATCH 308/351] updated docs --- doc/c64.sgml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/c64.sgml b/doc/c64.sgml index f22eca3e1..80f0334d0 100644 --- a/doc/c64.sgml +++ b/doc/c64.sgml @@ -141,6 +141,16 @@ Note that the soft80 conio driver is incompatible with the <tt/c64-ram.emd (c64_ram_emd)/ extended memory driver and the <tt/c64-hi.tgi (c64_hi_tgi)/ graphics driver. +<sect2>80 Columns conio driver (monochrome)<p> + +In an (even more) memory constrained situation, a size optimized version of the +software driven 80 columns module may be used, which only supports one common +text color for the whole screen. + +<tscreen><verb> +cl65 -t c64 myprog.c c64-soft80mono.o +</verb></tscreen> + <sect>Platform-specific header files<p> Programs containing C64-specific code may use the <tt/c64.h/ or <tt/cbm.h/ From 67cd0c219726b8d6ef5fc5e980cc197fbfb257d7 Mon Sep 17 00:00:00 2001 From: Marcus Rowe <undisbeliever@gmail.com> Date: Tue, 20 Oct 2015 09:30:25 +1000 Subject: [PATCH 309/351] Added .asize and .isize pseudo variables These pseudo variables will return the size of the accumulator/index in bits. For the 65816 instruction set .ASIZE/.ISIZE will return either 8 or 16, depending on the current size of the operand in immediate addressing mode. For all other CPU instruction sets, .ASIZE/.ISIZE will always return 8. For example: ; Reverse Subtract with Accumulator ; A = memory - A .macro rsb param .if .asize = 8 eor #$ff .else eor #$ffff .endif sec adc param .endmacro --- doc/ca65.sgml | 42 ++++++++++++++++++++++++++++++++++++++++++ src/ca65/expr.c | 18 ++++++++++++++++++ src/ca65/pseudo.c | 2 ++ src/ca65/scanner.c | 2 ++ src/ca65/token.h | 2 ++ 5 files changed, 66 insertions(+) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 19c09b85d..278a81d1b 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -1191,6 +1191,35 @@ writable. assignments to <tt/*/, use <tt/<ref id=".ORG" name=".ORG">/ instead. +<sect1><tt>.ASIZE</tt><label id=".ASIZE"><p> + + Reading this pseudo variable will return the current size of the + Accumulator in bits. + + For the 65816 instruction set .ASIZE will return either 8 or 16, depending + on the current size of the operand in immediate accu addressing mode. + + For all other CPU instruction sets, .ASIZE will always return 8. + + Example: + + <tscreen><verb> + ; Reverse Subtract with Accumulator + ; A = memory - A + .macro rsb param + .if .asize = 8 + eor #$ff + .else + eor #$ffff + .endif + sec + adc param + .endmacro + </verb></tscreen> + + See also: <tt><ref id=".ISIZE" name=".ISIZE"></tt> + + <sect1><tt>.CPU</tt><label id=".CPU"><p> Reading this pseudo variable will give a constant integer value that @@ -1218,6 +1247,19 @@ writable. </verb></tscreen> +<sect1><tt>.ISIZE</tt><label id=".ISIZE"><p> + + Reading this pseudo variable will return the current size of the Index + register in bits. + + For the 65816 instruction set .ISIZE will return either 8 or 16, depending + on the current size of the operand in immediate index addressing mode. + + For all other CPU instruction sets, .ISIZE will always return 8. + + See also: <tt><ref id=".ASIZE" name=".ASIZE"></tt> + + <sect1><tt>.PARAMCOUNT</tt><label id=".PARAMCOUNT"><p> This builtin pseudo variable is only available in macros. It is replaced by diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 0352b3c80..307772a5a 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -1099,6 +1099,15 @@ static ExprNode* Factor (void) N = Function (FuncAddrSize); break; + case TOK_ASIZE: + if (GetCPU() != CPU_65816) { + N = GenLiteralExpr (8); + } else { + N = GenLiteralExpr (ExtBytes [AM65I_IMM_ACCU] * 8); + } + NextTok (); + break; + case TOK_BLANK: N = Function (FuncBlank); break; @@ -1132,6 +1141,15 @@ static ExprNode* Factor (void) N = Function (FuncIsMnemonic); break; + case TOK_ISIZE: + if (GetCPU() != CPU_65816) { + N = GenLiteralExpr (8); + } else { + N = GenLiteralExpr (ExtBytes [AM65I_IMM_INDEX] * 8); + } + NextTok (); + break; + case TOK_LOBYTE: N = Function (FuncLoByte); break; diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 4484e3c26..4db780318 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1967,6 +1967,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoUnexpected }, /* .ADDRSIZE */ { ccNone, DoAlign }, { ccNone, DoASCIIZ }, + { ccNone, DoUnexpected }, /* .ASIZE */ { ccNone, DoAssert }, { ccNone, DoAutoImport }, { ccNone, DoUnexpected }, /* .BANK */ @@ -2041,6 +2042,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoIncBin }, { ccNone, DoInclude }, { ccNone, DoInterruptor }, + { ccNone, DoUnexpected }, /* .ISIZE */ { ccNone, DoUnexpected }, /* .ISMNEMONIC */ { ccNone, DoInvalid }, /* .LEFT */ { ccNone, DoLineCont }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index aaba56764..799321066 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -139,6 +139,7 @@ struct DotKeyword { { ".ALIGN", TOK_ALIGN }, { ".AND", TOK_BOOLAND }, { ".ASCIIZ", TOK_ASCIIZ }, + { ".ASIZE", TOK_ASIZE }, { ".ASSERT", TOK_ASSERT }, { ".AUTOIMPORT", TOK_AUTOIMPORT }, { ".BANK", TOK_BANK }, @@ -224,6 +225,7 @@ struct DotKeyword { { ".INCBIN", TOK_INCBIN }, { ".INCLUDE", TOK_INCLUDE }, { ".INTERRUPTOR", TOK_INTERRUPTOR }, + { ".ISIZE", TOK_ISIZE }, { ".ISMNEM", TOK_ISMNEMONIC }, { ".ISMNEMONIC", TOK_ISMNEMONIC }, { ".LEFT", TOK_LEFT }, diff --git a/src/ca65/token.h b/src/ca65/token.h index b0264f154..bfc013a3d 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -126,6 +126,7 @@ typedef enum token_t { TOK_ADDRSIZE, TOK_ALIGN, TOK_ASCIIZ, + TOK_ASIZE, TOK_ASSERT, TOK_AUTOIMPORT, TOK_BANK, @@ -200,6 +201,7 @@ typedef enum token_t { TOK_INCBIN, TOK_INCLUDE, TOK_INTERRUPTOR, + TOK_ISIZE, TOK_ISMNEMONIC, TOK_LEFT, TOK_LINECONT, From ba901d2de79b1bcd0d2baa279f6602840699d481 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 22 Oct 2015 17:33:01 +0200 Subject: [PATCH 310/351] removed apple2 specific note --- doc/c64.sgml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/c64.sgml b/doc/c64.sgml index 80f0334d0..a3e9e1291 100644 --- a/doc/c64.sgml +++ b/doc/c64.sgml @@ -127,8 +127,7 @@ and $ffff. In memory constrained situations the memory from $400 to $7FF can be made available to a program by calling <tt/_heapadd ((void *) 0x400, 0x400);/ at the beginning of <tt/main()/. Doing so is beneficial even if the program -doesn't use the the heap explicitly because loading a driver (and in fact -already opening a driver file) uses the heap implicitly. +doesn't use the the heap explicitly because loading a driver uses the heap implicitly. Using <tt/c64-soft80.o/ is as simple as placing it on the linker command line like this: From 8f8f12ceabffee441bec5241c3d3d54329c53b72 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Thu, 22 Oct 2015 19:48:21 +0200 Subject: [PATCH 311/351] use tii instead of copy loop to copy data section to ram --- libsrc/pce/crt0.s | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index 77872f32f..e92e9eca3 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -96,43 +96,7 @@ start: jsr zerobss ; Copy the .data segment to RAM - lda #<(__DATA_LOAD__) - sta ptr1 - lda #>(__DATA_LOAD__) - sta ptr1+1 - lda #<(__DATA_RUN__) - sta ptr2 - lda #>(__DATA_RUN__) - sta ptr2+1 - - ldx #>(__DATA_SIZE__) -@l2: - beq @s1 ; no more full pages - - ; copy one page - ldy #0 -@l1: - lda (ptr1),y - sta (ptr2),y - iny - bne @l1 - - inc ptr1+1 - inc ptr2+1 - - dex - bne @l2 - - ; copy remaining bytes -@s1: - ; copy one page - ldy #0 -@l3: - lda (ptr1),y - sta (ptr2),y - iny - cpy #<(__DATA_SIZE__) - bne @l3 + tii __DATA_LOAD__, __DATA_RUN__, __DATA_SIZE__ ; setup the stack lda #<(__RAM_START__+__RAM_SIZE__) From 8e9bf4d41930f11eaf3ac4d1bf774b30ffa92c3b Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 22 Oct 2015 19:24:08 -0400 Subject: [PATCH 312/351] Changed the way that ld65 handles bad offset/start segment attributes, and reports memory area overflows. 1. Offset/start attributes within a memory area are ignored after an overflow. 2. If a previous segment ends past an offset/start address, then that address is not used. 3. Short map files were generated for memory overflows; now, they are generated for bad offset/start addresses, too. --- src/ld65/config.c | 72 +++++++++++++++++++++++------------------------ src/ld65/main.c | 4 +-- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/ld65/config.c b/src/ld65/config.c index 46e9a48fb..8e7a049c7 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -1769,12 +1769,12 @@ static void CreateLoadDefines (SegDesc* S, unsigned long SegAddr) unsigned CfgProcess (void) -/* Process the config file after reading in object files and libraries. This -** includes postprocessing of the config file data but also assigning segments -** and defining segment/memory area related symbols. The function will return -** the number of memory area overflows (so zero means anything went ok). +/* Process the config file, after reading in object files and libraries. This +** includes postprocessing of the config file data; but also assigning segments, +** and defining segment/memory-area related symbols. The function will return +** the number of memory area overflows (so, zero means everything went OK). ** In case of overflows, a short mapfile can be generated later, to ease the -** task of rearranging segments for the user. +** user's task of re-arranging segments. */ { unsigned Overflows = 0; @@ -1788,12 +1788,11 @@ unsigned CfgProcess (void) /* Postprocess segments */ ProcessSegments (); - /* Walk through each of the memory sections. Add up the sizes and check + /* Walk through each of the memory sections. Add up the sizes; and, check ** for an overflow of the section. Assign the start addresses of the - ** segments while doing this. + ** segments while doing that. */ for (I = 0; I < CollCount (&MemoryAreas); ++I) { - unsigned J; unsigned long Addr; @@ -1806,7 +1805,7 @@ unsigned CfgProcess (void) /* Remember if this is a relocatable memory area */ M->Relocatable = RelocatableBinFmt (M->F->Format); - /* Resolve the start address expression, remember the start address + /* Resolve the start address expression, remember the start address, ** and mark the memory area as placed. */ if (!IsConstExpr (M->StartExpr)) { @@ -1843,18 +1842,16 @@ unsigned CfgProcess (void) /* Walk through the segments in this memory area */ for (J = 0; J < CollCount (&M->SegList); ++J) { - /* Get the segment */ SegDesc* S = CollAtUnchecked (&M->SegList, J); /* Remember the start address before handling this segment */ unsigned long StartAddr = Addr; - /* Some actions depend on wether this is the load or run memory + /* Some actions depend on whether this is the load or run memory ** area. */ if (S->Run == M) { - /* This is the run (and maybe load) memory area. Handle ** alignment and explict start address and offset. */ @@ -1864,7 +1861,7 @@ unsigned CfgProcess (void) /* If the first segment placed in the memory area needs ** fill bytes for the alignment, emit a warning, since - ** this is somewhat suspicious. + ** that is somewhat suspicious. */ if (M->FillLevel == 0 && NewAddr > Addr) { CfgWarning (GetSourcePos (S->LI), @@ -1876,32 +1873,36 @@ unsigned CfgProcess (void) /* Use the aligned address */ Addr = NewAddr; - } else if (S->Flags & (SF_OFFSET | SF_START)) { + } else if ((S->Flags & (SF_OFFSET | SF_START)) != 0 && + (M->Flags & MF_OVERFLOW) == 0) { /* Give the segment a fixed starting address */ unsigned long NewAddr = S->Addr; + if (S->Flags & SF_OFFSET) { /* An offset was given, no address, make an address */ NewAddr += M->Start; } - if (Addr > NewAddr) { + if (NewAddr < Addr) { /* Offset already too large */ + ++Overflows; if (S->Flags & SF_OFFSET) { - CfgError (GetSourcePos (M->LI), - "Offset too small in `%s', segment `%s'", - GetString (M->Name), - GetString (S->Name)); + CfgWarning (GetSourcePos (S->LI), + "Segment `%s' offset is too small in `%s' by %lu byte%c", + GetString (S->Name), GetString (M->Name), + Addr - NewAddr, (Addr - NewAddr == 1) ? ' ' : 's'); } else { - CfgError (GetSourcePos (M->LI), - "Start address too low in `%s', segment `%s'", - GetString (M->Name), - GetString (S->Name)); + CfgWarning (GetSourcePos (S->LI), + "Segment `%s' start address is too low in `%s' by %lu byte%c", + GetString (S->Name), GetString (M->Name), + Addr - NewAddr, (Addr - NewAddr == 1) ? ' ' : 's'); } + } else { + Addr = NewAddr; } - Addr = NewAddr; } /* Set the start address of this segment, set the readonly flag - ** in the segment and and remember if the segment is in a + ** in the segment, and remember if the segment is in a ** relocatable file or not. */ S->Seg->PC = Addr; @@ -1913,25 +1914,23 @@ unsigned CfgProcess (void) S->Seg->MemArea = M; } else if (S->Load == M) { - - /* This is the load memory area, *and* run and load are + /* This is the load memory area; *and*, run and load are ** different (because of the "else" above). Handle alignment. */ if (S->Flags & SF_ALIGN_LOAD) { /* Align the address */ Addr = AlignAddr (Addr, S->LoadAlignment); } - } - /* If this is the load memory area and the segment doesn't have a + /* If this is the load memory area, and the segment doesn't have a ** fill value defined, use the one from the memory area. */ if (S->Load == M && (S->Flags & SF_FILLVAL) == 0) { S->Seg->FillVal = M->FillVal; } - /* Increment the fill level of the memory area and check for an + /* Increment the fill level of the memory area; and, check for an ** overflow. */ M->FillLevel = Addr + S->Seg->Size - M->Start; @@ -1939,9 +1938,9 @@ unsigned CfgProcess (void) ++Overflows; M->Flags |= MF_OVERFLOW; CfgWarning (GetSourcePos (M->LI), - "Memory area overflow in `%s', segment `%s' (%lu bytes)", - GetString (M->Name), GetString (S->Name), - M->FillLevel - M->Size); + "Segment `%s' overflows memory area `%s' by %lu byte%c", + GetString (S->Name), GetString (M->Name), + M->FillLevel - M->Size, (M->FillLevel - M->Size == 1) ? ' ' : 's'); } /* If requested, define symbols for the start and size of the @@ -1966,10 +1965,9 @@ unsigned CfgProcess (void) ((S->Flags & SF_BSS) == 0 || (M->Flags & MF_FILL) != 0)) { M->F->Size += Addr - StartAddr; } - } - /* If requested, define symbols for start, size and offset of the + /* If requested, define symbols for start, size, and offset of the ** memory area */ if (M->Flags & MF_DEFINE) { @@ -1999,8 +1997,8 @@ unsigned CfgProcess (void) SB_Done (&Buf); } - /* If we didn't have an overflow and are requested to fill the memory - ** area, acount for that in the file size. + /* If we didn't have an overflow, and are requested to fill the memory + ** area, account for that in the file size. */ if ((M->Flags & MF_OVERFLOW) == 0 && (M->Flags & MF_FILL) != 0) { M->F->Size += (M->Size - M->FillLevel); diff --git a/src/ld65/main.c b/src/ld65/main.c index 5030b1dc3..95ed14396 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -819,8 +819,8 @@ int main (int argc, char* argv []) if (MapFileName) { CreateMapFile (SHORT_MAPFILE); } - Error ("Cannot generate output due to memory area overflow%s", - (MemoryAreaOverflows > 1)? "s" : ""); + Error ("Cannot generate most of the files due to memory area overflow%c", + (MemoryAreaOverflows > 1) ? 's' : ' '); } /* Create the output file */ From 25e0b157be225fbeed8abef1998e542abb65470f Mon Sep 17 00:00:00 2001 From: Marcus Rowe <undisbeliever@gmail.com> Date: Sat, 24 Oct 2015 01:07:47 +1000 Subject: [PATCH 313/351] Fixed code style --- src/ca65/expr.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ca65/expr.c b/src/ca65/expr.c index 307772a5a..ff4232c00 100644 --- a/src/ca65/expr.c +++ b/src/ca65/expr.c @@ -1099,14 +1099,14 @@ static ExprNode* Factor (void) N = Function (FuncAddrSize); break; - case TOK_ASIZE: - if (GetCPU() != CPU_65816) { + case TOK_ASIZE: + if (GetCPU () != CPU_65816) { N = GenLiteralExpr (8); } else { - N = GenLiteralExpr (ExtBytes [AM65I_IMM_ACCU] * 8); + N = GenLiteralExpr (ExtBytes[AM65I_IMM_ACCU] * 8); } - NextTok (); - break; + NextTok (); + break; case TOK_BLANK: N = Function (FuncBlank); @@ -1141,14 +1141,14 @@ static ExprNode* Factor (void) N = Function (FuncIsMnemonic); break; - case TOK_ISIZE: - if (GetCPU() != CPU_65816) { + case TOK_ISIZE: + if (GetCPU () != CPU_65816) { N = GenLiteralExpr (8); } else { - N = GenLiteralExpr (ExtBytes [AM65I_IMM_INDEX] * 8); + N = GenLiteralExpr (ExtBytes[AM65I_IMM_INDEX] * 8); } NextTok (); - break; + break; case TOK_LOBYTE: N = Function (FuncLoByte); From 8e8d1120290c743ea97d8e8889c039341f3f514d Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 23 Oct 2015 18:02:21 -0400 Subject: [PATCH 314/351] Added pce-specific substitutes for memcpy() and memmove(). They are smaller and faster because they take advantage of the pce CPU's block-copy instructions. Also, made a small improvement to the common memmove(), so that it is similar to the pce version. --- libsrc/common/memmove.s | 10 ++--- libsrc/pce/memcpy.s | 94 +++++++++++++++++++++++++++++++++++++++++ libsrc/pce/memmove.s | 63 +++++++++++++++++++++++++++ 3 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 libsrc/pce/memcpy.s create mode 100644 libsrc/pce/memmove.s diff --git a/libsrc/common/memmove.s b/libsrc/common/memmove.s index 94ad7d102..9c33124f1 100644 --- a/libsrc/common/memmove.s +++ b/libsrc/common/memmove.s @@ -1,7 +1,7 @@ ; -; Ullrich von Bassewitz, 2003-08-20 -; Performance increase (about 20%) by -; Christian Krueger, 2009-09-13 +; 2003-08-20, Ullrich von Bassewitz +; 2009-09-13, Christian Krueger -- performance increase (about 20%) +; 2015-10-23, Greg King ; ; void* __fastcall__ memmove (void* dest, const void* src, size_t size); ; @@ -23,8 +23,7 @@ _memmove: ; low addresses and increase pointers), otherwise we must copy downwards ; (start at high addresses and decrease pointers). - sec - sbc ptr1 + cmp ptr1 txa sbc ptr1+1 jcc memcpy_upwards ; Branch if dest < src (upwards copy) @@ -81,4 +80,3 @@ PageSizeCopy: ; assert Y = 0 ; Done, return dest done: jmp popax ; Pop ptr and return as result - diff --git a/libsrc/pce/memcpy.s b/libsrc/pce/memcpy.s new file mode 100644 index 000000000..b06dad645 --- /dev/null +++ b/libsrc/pce/memcpy.s @@ -0,0 +1,94 @@ +; +; This file, instead of "common/memcpy.s", will be assembled for the pce +; target. This version is smaller and faster because it uses the HuC6280's +; block-copy instructions. +; +; 2003-08-20, Ullrich von Bassewitz +; 2015-10-11, Greg King +; +; void* __fastcall__ memcpy (void* dest, const void* src, size_t size); +; +; NOTE: This function contains entry points for memmove, which will resort +; to memcpy for an incrementing copy. Don't change this module without looking +; at "pce/memmove.s"! +; + + .export _memcpy + .export memcpy_increment, memcpy_transfer, memcpy_getparams + + .import popax + .importzp sp, ptr1, ptr2, ptr3 + + +; The structure of the transfer instructions + + .struct +opcode .byte +source .addr +destination .addr +length .word + .endstruct + +; ---------------------------------------------------------------------- +_memcpy: + jsr memcpy_getparams + +memcpy_increment: + ldy #$73 ; TII + +memcpy_transfer: + sty transfer+opcode + + lda ptr1 + ldx ptr1+1 + sta transfer+source + stx transfer+source+1 + + lda ptr2 + ldx ptr2+1 + sta transfer+destination + stx transfer+destination+1 + + lda ptr3 + ldx ptr3+1 + sta transfer+length + stx transfer+length+1 + + jmp transfer + +; ---------------------------------------------------------------------- +; Get the parameters from the stack, as follows: +; +; size --> ptr3 +; src --> ptr1 +; dest --> ptr2 +; +; The first argument (dest) will remain on the stack; and, is returned in .XA! + +memcpy_getparams: + sta ptr3 + stx ptr3+1 ; save size + + jsr popax + sta ptr1 + stx ptr1+1 ; save src + +; (Direct stack access is four cycles faster [total cycle count].) + + ldy #1 ; save dest + lda (sp),y ; get high byte + tax + lda (sp) ; get low byte + sta ptr2 + stx ptr2+1 + rts ; return dest address (for memmove) + +; ---------------------------------------------------------------------- +; The transfer instructions use inline arguments. +; Therefore, we must build the instruction in the DATA segment. + +.data + +transfer: + tii $FFFF, $FFFF, $0001 + jmp popax ; get pointer; and, return it as result diff --git a/libsrc/pce/memmove.s b/libsrc/pce/memmove.s new file mode 100644 index 000000000..9a7feebf5 --- /dev/null +++ b/libsrc/pce/memmove.s @@ -0,0 +1,63 @@ +; +; This file, instead of "common/memmove.s", will be assembled for the pce +; target. This version is smaller and faster because it uses the HuC6280's +; block-copy instructions. +; +; 2003-08-20, Ullrich von Bassewitz +; 2015-10-23, Greg King +; +; void* __fastcall__ memmove (void* dest, const void* src, size_t size); +; +; NOTE: This function uses entry points from "pce/memcpy.s"! +; + + .export _memmove + + .import memcpy_getparams, memcpy_increment, memcpy_transfer + .importzp ptr1, ptr2, ptr3 + + .macpack generic + .macpack longbranch + + +; ---------------------------------------------------------------------- +_memmove: + jsr memcpy_getparams + +; Check for the copy direction. If dest < src, we must copy downwards (start +; at low addresses, and increase pointers); otherwise, we must copy upwards +; (start at high addresses, and decrease pointers). + + cmp ptr1 + txa + sbc ptr1+1 + jcc memcpy_increment ; Branch if dest < src + +; Copy decrementing; adjust the pointers to the end of the memory regions. + + lda ptr1 + add ptr3 + sta ptr1 + lda ptr1+1 + adc ptr3+1 + sta ptr1+1 + + lda ptr1 ; point to last byte of source + bne @L1 + dec ptr1+1 +@L1: dec ptr1 + + lda ptr2 + add ptr3 + sta ptr2 + lda ptr2+1 + adc ptr3+1 + sta ptr2+1 + + lda ptr2 ; point to last byte of target + bne @L2 + dec ptr2+1 +@L2: dec ptr2 + + ldy #$C3 ; TDD + jmp memcpy_transfer From 281dc33e5a981324df4872cad06efbe5689abc72 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Fri, 30 Oct 2015 17:18:55 +0100 Subject: [PATCH 315/351] Made addr/size hex consts 4 digits wide. --- doc/c64.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/c64.sgml b/doc/c64.sgml index a3e9e1291..8767d212d 100644 --- a/doc/c64.sgml +++ b/doc/c64.sgml @@ -125,7 +125,7 @@ module <tt/c64-soft80.o/ which uses the memory under I/O between $d000 and $ffff. In memory constrained situations the memory from $400 to $7FF -can be made available to a program by calling <tt/_heapadd ((void *) 0x400, 0x400);/ +can be made available to a program by calling <tt/_heapadd ((void *) 0x0400, 0x0400);/ at the beginning of <tt/main()/. Doing so is beneficial even if the program doesn't use the the heap explicitly because loading a driver uses the heap implicitly. From 8180ac20d3043e9dc54cc639b29f993e6c79d5b8 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 2 Nov 2015 17:04:46 -0500 Subject: [PATCH 316/351] Added code to handle the special case of a zero-length move. Added more tests of memcpy() and memmove(). --- libsrc/pce/memcpy.s | 23 +++++++++++++++++------ testcode/lib/pce/Makefile | 5 ++--- testcode/lib/pce/conio.c | 22 +++++++++++++++------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/libsrc/pce/memcpy.s b/libsrc/pce/memcpy.s index b06dad645..e3b7bde34 100644 --- a/libsrc/pce/memcpy.s +++ b/libsrc/pce/memcpy.s @@ -4,7 +4,7 @@ ; block-copy instructions. ; ; 2003-08-20, Ullrich von Bassewitz -; 2015-10-11, Greg King +; 2015-11-02, Greg King ; ; void* __fastcall__ memcpy (void* dest, const void* src, size_t size); ; @@ -16,7 +16,7 @@ .export _memcpy .export memcpy_increment, memcpy_transfer, memcpy_getparams - .import popax + .import incsp2, popax .importzp sp, ptr1, ptr2, ptr3 @@ -68,12 +68,23 @@ memcpy_transfer: memcpy_getparams: sta ptr3 stx ptr3+1 ; save size + ora ptr3+1 + bne @L1 - jsr popax +; The size is zero; copy nothing; just return the dest address. +; (The HuC6280's transfer instructions can't copy $0000 bytes; +; they would copy $10000 [64K] bytes instead.) + + ply ; drop return address + plx + jsr incsp2 ; drop src address + jmp popax ; get pointer; return it as result + +@L1: jsr popax sta ptr1 stx ptr1+1 ; save src -; (Direct stack access is four cycles faster [total cycle count].) +; (Direct stack access is six cycles faster [total cycle count].) ldy #1 ; save dest lda (sp),y ; get high byte @@ -85,10 +96,10 @@ memcpy_getparams: ; ---------------------------------------------------------------------- ; The transfer instructions use inline arguments. -; Therefore, we must build the instruction in the DATA segment. +; Therefore, we must build the instruction, in the DATA segment. .data transfer: tii $FFFF, $FFFF, $0001 - jmp popax ; get pointer; and, return it as result + jmp popax ; get pointer; return it as result diff --git a/testcode/lib/pce/Makefile b/testcode/lib/pce/Makefile index 1fee199fd..9a4dd7506 100644 --- a/testcode/lib/pce/Makefile +++ b/testcode/lib/pce/Makefile @@ -1,3 +1,4 @@ +.PHONY: all clean test all: conio.pce @@ -5,9 +6,7 @@ conio.pce: conio.c ../../../bin/cl65 -t pce conio.c --mapfile conio.map -o conio.pce clean: - $(RM) conio.pce - $(RM) conio.map + $(RM) conio.o conio.pce conio.map test: conio.pce mednafen -force_module pce conio.pce - diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index d22fe58ee..a4bd63b15 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -1,4 +1,3 @@ - #include <conio.h> #include <time.h> #include <joystick.h> @@ -13,7 +12,7 @@ void main(void) int i, j; clock_t clk; char* p; - unsigned char xsize, ysize, n; + unsigned char xsize, ysize, n, nn; joy_install(&joy_static_stddrv); @@ -40,11 +39,12 @@ void main(void) gotoxy(0, 16 + i); p = malloc(16); memcpy(p, "0123456789abcdef", 16); - cprintf("alloced at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, + cprintf("alloc'ed at: %04p - %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", p, p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7], p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15] ); } + memcpy(p, main, 0); /* test that a zero length doesn't copy 64K */ gotoxy(0,ysize - 1); for (i = 0; i < xsize; ++i) { @@ -108,14 +108,22 @@ void main(void) } gotoxy(xsize - 10, 3); - j = (n >> 5) & 1; - revers(j); - cputc(j ? 'R' : ' '); + nn = (n >> 5) & 1; + revers(nn); + cputc(nn ? 'R' : ' '); cputs(" revers"); revers(0); + if ((n & 0x1f) == 0x00) { + nn = p[15]; + ((char*)memmove(p + 1, p, 15))[-1] = nn; + gotoxy(22, 19); + cprintf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", + p[0],p[1],p[ 2],p[ 3],p[ 4],p[ 5],p[ 6],p[ 7], + p[8],p[9],p[10],p[11],p[12],p[13],p[14],p[15]); + } + waitvblank(); ++n; } - for(;;); } From 999d57401c657169c6694e33255cb3c3c81fe66c Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 6 Nov 2015 23:59:19 -0500 Subject: [PATCH 317/351] Added a version of memset() that uses the HuC6280's TII instruction to get more speed. --- libsrc/pce/memcpy.s | 7 +++-- libsrc/pce/memset.s | 67 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 libsrc/pce/memset.s diff --git a/libsrc/pce/memcpy.s b/libsrc/pce/memcpy.s index e3b7bde34..1743912ea 100644 --- a/libsrc/pce/memcpy.s +++ b/libsrc/pce/memcpy.s @@ -8,9 +8,10 @@ ; ; void* __fastcall__ memcpy (void* dest, const void* src, size_t size); ; -; NOTE: This function contains entry points for memmove, which will resort -; to memcpy for an incrementing copy. Don't change this module without looking -; at "pce/memmove.s"! +; NOTE: This function contains entry points for memmove(), which resorts to +; memcpy() for incrementing copies. The PC-Engine memset() uses this memcpy() +; to fill memory quickly. Don't change this module without looking at +; "pce/memmove.s" and "pce/memset.s"! ; .export _memcpy diff --git a/libsrc/pce/memset.s b/libsrc/pce/memset.s new file mode 100644 index 000000000..45a78d533 --- /dev/null +++ b/libsrc/pce/memset.s @@ -0,0 +1,67 @@ +; +; This file, instead of "common/memset.s", will be assembled for the pce +; target. This version is smaller and faster because it uses a HuC6280 +; block-copy instruction. +; +; 1998-05-29, Ullrich von Bassewitz +; 2015-11-06, Greg King +; +; void* __fastcall__ _bzero (void* ptr, size_t n); +; void __fastcall__ bzero (void* ptr, size_t n); +; void* __fastcall__ memset (void* ptr, int c, size_t n); +; +; NOTE: bzero() will return its first argument, as memset() does. It is no +; problem to declare the return value as void, because it can be ignored. +; _bzero() (note the leading underscore) is declared with the proper +; return type because the compiler will replace memset() by _bzero() if +; the fill value is zero; and, the optimizer looks at the return type +; to see if the value in .XA is of any use. +; +; NOTE: This function uses entry points from "pce/memcpy.s"! +; + + .export __bzero, _bzero, _memset + + .import memcpy_getparams, memcpy_increment + .import pushax, popax + .importzp ptr1, ptr2, ptr3 + + .macpack longbranch + + +; ---------------------------------------------------------------------- +__bzero: +_bzero: pha + cla ; fill with zeros + jsr pushax ; (high byte isn't important) + pla + +_memset: + jsr memcpy_getparams + +; The fill byte is put at the beginning of the buffer; then, the buffer is +; copied to a second buffer that starts one byte above the start of the first +; buffer. Normally, we would use memmove() to avoid trouble; but here, we +; exploit that overlap, by using memcpy(). Therefore, the fill value is copied +; from each byte to the next byte, all the way to the end of the buffer. + + lda ptr1 ; get fill value + sta (ptr2) + + lda ptr3 ; count first byte + bne @L3 + dec ptr3+1 +@L3: dec a + sta ptr3 + ora ptr3+1 + jeq popax ; return ptr. if no more bytes + + lda ptr2 ; point to first buffer + ldx ptr2+1 + sta ptr1 + stx ptr1+1 + inc ptr2 ; point to second buffer + bne @L2 + inc ptr2+1 + +@L2: jmp memcpy_increment From 5e36315d057fe8a8a6698f07f525ec7a677a4f2e Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sat, 7 Nov 2015 00:29:07 -0500 Subject: [PATCH 318/351] Style changes. --- libsrc/pce/memcpy.s | 16 ++++++++-------- libsrc/pce/memmove.s | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libsrc/pce/memcpy.s b/libsrc/pce/memcpy.s index 1743912ea..40f831e30 100644 --- a/libsrc/pce/memcpy.s +++ b/libsrc/pce/memcpy.s @@ -35,25 +35,25 @@ _memcpy: jsr memcpy_getparams memcpy_increment: - ldy #$73 ; TII + ldy #$73 ; TII opcode memcpy_transfer: - sty transfer+opcode + sty transfer + opcode lda ptr1 ldx ptr1+1 - sta transfer+source - stx transfer+source+1 + sta transfer + source + stx transfer + source+1 lda ptr2 ldx ptr2+1 - sta transfer+destination - stx transfer+destination+1 + sta transfer + destination + stx transfer + destination+1 lda ptr3 ldx ptr3+1 - sta transfer+length - stx transfer+length+1 + sta transfer + length + stx transfer + length+1 jmp transfer diff --git a/libsrc/pce/memmove.s b/libsrc/pce/memmove.s index 9a7feebf5..4b80da2af 100644 --- a/libsrc/pce/memmove.s +++ b/libsrc/pce/memmove.s @@ -59,5 +59,5 @@ _memmove: dec ptr2+1 @L2: dec ptr2 - ldy #$C3 ; TDD + ldy #$C3 ; TDD opcode jmp memcpy_transfer From 54de8ac031dd6430345c3fd31bcd1590f48c1c5e Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sat, 7 Nov 2015 11:45:38 +0100 Subject: [PATCH 319/351] remove unneeded exports --- libsrc/c64/extra/soft80.s | 4 ++-- libsrc/c64/extra/soft80mono.s | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/c64/extra/soft80.s b/libsrc/c64/extra/soft80.s index 4ee030c81..d445c85c0 100644 --- a/libsrc/c64/extra/soft80.s +++ b/libsrc/c64/extra/soft80.s @@ -32,7 +32,6 @@ ; soft80_kclrscr.s .import soft80_kclrscr .export _clrscr := soft80_kclrscr ; clrscr.s - .export CLRSCR := soft80_kclrscr ; kernal func (c64.inc) ; soft80_kplot.s .import soft80_kplot @@ -41,7 +40,8 @@ ; soft80_kscreen.s .import soft80_screensize .export screensize := soft80_screensize ; _scrsize.s - .export SCREEN := soft80_screensize ; kernal func (kernal.s) + ; FIXME: use _scrsize.s/remove soft80_scrsize.s + ;.export SCREEN := soft80_screensize ; kernal func (kernal.s) ; VIC sprite data for the mouse pointer .export mcb_spritememory := soft80_spriteblock diff --git a/libsrc/c64/extra/soft80mono.s b/libsrc/c64/extra/soft80mono.s index f91f4a76a..6fd2c687c 100644 --- a/libsrc/c64/extra/soft80mono.s +++ b/libsrc/c64/extra/soft80mono.s @@ -35,7 +35,6 @@ ; soft80mono_kclrscr.s .import soft80mono_kclrscr .export _clrscr := soft80mono_kclrscr ; clrscr.s - .export CLRSCR := soft80mono_kclrscr ; kernal func (c64.inc) ; soft80mono_kplot.s .import soft80mono_kplot @@ -44,7 +43,8 @@ ; soft80_kscreen.s .import soft80_screensize .export screensize := soft80_screensize ; _scrsize.s - .export SCREEN := soft80_screensize ; kernal func (kernal.s) + ; FIXME: use _scrsize.s/remove soft80_scrsize.s + ;.export SCREEN := soft80_screensize ; kernal func (kernal.s) ; VIC sprite data for the mouse pointer .export mcb_spritememory := soft80_spriteblock From c5d624c941944da9ea5dd74a162fefcd9e0ea068 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 12 Nov 2015 05:40:47 -0500 Subject: [PATCH 320/351] Added C declarations of the NES's I/O registers to <nes.h>. --- include/nes.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/include/nes.h b/include/nes.h index 7bf56c995..934b8a802 100644 --- a/include/nes.h +++ b/include/nes.h @@ -100,6 +100,63 @@ #define KEY_LEFT 0x40 #define KEY_RIGHT 0x80 +/* Define hardware */ + +/* Picture Processing Unit */ +struct __ppu { + unsigned char control; + unsigned char mask; /* color; show sprites, background */ + signed char volatile const status; + struct { + unsigned char address; + unsigned char data; + } sprite; + unsigned char scroll; + struct { + unsigned char address; + unsigned char data; + } vram; +}; +#define PPU (*(struct __ppu*)0x2000) +#define SPRITE_DMA (APU.sprite.dma) + +/* Audio Processing Unit */ +struct __apu { + struct { + unsigned char control; /* duty, counter halt, volume/envelope */ + unsigned char ramp; + unsigned char period_low; /* timing */ + unsigned char len_period_high; /* length, timing */ + } pulse[2]; + struct { + unsigned char counter; /* counter halt, linear counter */ + unsigned char unused; + unsigned char period_low; /* timing */ + unsigned char len_period_high; /* length, timing */ + } triangle; + struct { + unsigned char control; /* counter halt, volume/envelope */ + unsigned char unused; + unsigned char period; /* loop, timing */ + unsigned char len; /* length */ + } noise; + struct { + unsigned char control; /* IRQ, loop, rate */ + unsigned char output; /* output value */ + unsigned char address; + unsigned char length; + } delta_mod; /* delta pulse-code modulation */ + struct { + unsigned char dma; + } sprite; + signed char volatile status; + unsigned char unused; + unsigned char fcontrol; +}; +#define APU (*(struct __apu*)0x4000) + +#define JOYPAD ((unsigned char volatile const[2])0x4016) + /* The addresses of the static drivers */ extern void nes_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ extern void nes_64_56_2_tgi[]; /* Referred to by tgi_static_stddrv[] */ From 3c8c62c6abd8b7576468855bfc4cec8bba4849e0 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 17 Nov 2015 14:11:30 -0500 Subject: [PATCH 321/351] Fixed the ca65 Assembly-code variable ".paramcount". Fixed how it's described in the ca65 document. --- doc/ca65.sgml | 321 ++++++++++++++++---------------- src/ca65/macro.c | 158 ++++++++-------- testcode/assembler/paramcount.s | 20 ++ 3 files changed, 259 insertions(+), 240 deletions(-) create mode 100644 testcode/assembler/paramcount.s diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 278a81d1b..213033cd4 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -2,8 +2,9 @@ <article> <title>ca65 Users Guide -<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz"> -<date>2015-08-01 +<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">,<newline> +<url url="mailto:greg.king5@verizon.net" name="Greg King"> +<date>2015-11-17 <abstract> ca65 is a powerful macro assembler for the 6502, 65C02, and 65816 CPUs. It is @@ -1320,8 +1321,8 @@ either a string or an expression. <sect1><tt>.ADDRSIZE</tt><label id=".ADDRSIZE"><p> - The <tt/.ADDRSIZE/ function is used to return the interal address size - associated with a symbol. This can be helpful in macros when knowing the address + The <tt/.ADDRSIZE/ function is used to return the interal address size + associated with a symbol. This can be helpful in macros when knowing the address size of symbol can help with custom instructions. Example: @@ -2358,8 +2359,8 @@ Here's a list of all control commands and a description, what they do: <sect1><tt>.DEFINEDMACRO</tt><label id=".DEFINEDMACRO"><p> Builtin function. The function expects an identifier as argument in braces. - The argument is evaluated, and the function yields "true" if the identifier - has already been defined as the name of a macro. Otherwise the function yields + The argument is evaluated, and the function yields "true" if the identifier + has already been defined as the name of a macro. Otherwise the function yields false. Example: <tscreen><verb> @@ -2367,7 +2368,7 @@ Here's a list of all control commands and a description, what they do: clc adc foo .endmacro - + .if .definedmacro(add) add #$01 .else @@ -3935,10 +3936,10 @@ In its simplest form, a macro does not have parameters. Here's an example: <tscreen><verb> - .macro asr ; Arithmetic shift right - cmp #$80 ; Put bit 7 into carry - ror ; Rotate right with carry - .endmacro +.macro asr ; Arithmetic shift right + cmp #$80 ; Put bit 7 into carry + ror ; Rotate right with carry +.endmacro </verb></tscreen> The macro above consists of two real instructions, that are inserted into @@ -3946,9 +3947,9 @@ the code, whenever the macro is expanded. Macro expansion is simply done by using the name, like this: <tscreen><verb> - lda $2010 - asr - sta $2010 + lda $2010 + asr + sta $2010 </verb></tscreen> @@ -3957,15 +3958,15 @@ by using the name, like this: When using macro parameters, macros can be even more useful: <tscreen><verb> - .macro inc16 addr - clc - lda addr - adc #$01 - sta addr - lda addr+1 - adc #$00 - sta addr+1 - .endmacro +.macro inc16 addr + clc + lda addr + adc #<$0001 + sta addr + lda addr+1 + adc #>$0001 + sta addr+1 +.endmacro </verb></tscreen> When calling the macro, you may give a parameter, and each occurrence of @@ -3973,19 +3974,19 @@ the name "addr" in the macro definition will be replaced by the given parameter. So <tscreen><verb> - inc16 $1000 + inc16 $1000 </verb></tscreen> will be expanded to <tscreen><verb> - clc - lda $1000 - adc #$01 - sta $1000 - lda $1000+1 - adc #$00 - sta $1000+1 + clc + lda $1000 + adc #<$0001 + sta $1000 + lda $1000+1 + adc #>$0001 + sta $1000+1 </verb></tscreen> A macro may have more than one parameter, in this case, the parameters @@ -4006,40 +4007,40 @@ opposite. Look at this example: <tscreen><verb> - .macro ldaxy a, x, y - .ifnblank a - lda #a - .endif - .ifnblank x - ldx #x - .endif - .ifnblank y - ldy #y - .endif - .endmacro +.macro ldaxy a, x, y +.ifnblank a + lda #a +.endif +.ifnblank x + ldx #x +.endif +.ifnblank y + ldy #y +.endif +.endmacro </verb></tscreen> -This macro may be called as follows: +That macro may be called as follows: <tscreen><verb> - ldaxy 1, 2, 3 ; Load all three registers + ldaxy 1, 2, 3 ; Load all three registers - ldaxy 1, , 3 ; Load only a and y + ldaxy 1, , 3 ; Load only a and y - ldaxy , , 3 ; Load y only + ldaxy , , 3 ; Load y only </verb></tscreen> -There's another helper command for determining, which macro parameters are -valid: <tt><ref id=".PARAMCOUNT" name=".PARAMCOUNT"></tt> This command is -replaced by the parameter count given, <em/including/ intermediate empty macro +There's another helper command for determining which macro parameters are +valid: <tt><ref id=".PARAMCOUNT" name=".PARAMCOUNT"></tt>. That command is +replaced by the parameter count given, <em/including/ explicitly empty parameters: <tscreen><verb> - ldaxy 1 ; .PARAMCOUNT = 1 - ldaxy 1,,3 ; .PARAMCOUNT = 3 - ldaxy 1,2 ; .PARAMCOUNT = 2 - ldaxy 1, ; .PARAMCOUNT = 2 - ldaxy 1,2,3 ; .PARAMCOUNT = 3 + ldaxy 1 ; .PARAMCOUNT = 1 + ldaxy 1,,3 ; .PARAMCOUNT = 3 + ldaxy 1,2 ; .PARAMCOUNT = 2 + ldaxy 1, ; .PARAMCOUNT = 2 + ldaxy 1,2,3 ; .PARAMCOUNT = 3 </verb></tscreen> Macro parameters may optionally be enclosed into curly braces. This allows the @@ -4047,19 +4048,19 @@ inclusion of tokens that would otherwise terminate the parameter (the comma in case of a macro parameter). <tscreen><verb> - .macro foo arg1, arg2 - ... - .endmacro +.macro foo arg1, arg2 + ... +.endmacro - foo ($00,x) ; Two parameters passed - foo {($00,x)} ; One parameter passed + foo ($00,x) ; Two parameters passed + foo {($00,x)} ; One parameter passed </verb></tscreen> In the first case, the macro is called with two parameters: '<tt/($00/' -and 'x)'. The comma is not passed to the macro, since it is part of the +and '<tt/x)/'. The comma is not passed to the macro, because it is part of the calling sequence, not the parameters. -In the second case, '($00,x)' is passed to the macro, this time +In the second case, '<tt/($00,x)/' is passed to the macro; this time, including the comma. @@ -4072,17 +4073,17 @@ id=".MATCH" name=".MATCH">/ and <tt/<ref id=".XMATCH" name=".XMATCH">/ functions will allow you to do exactly this: <tscreen><verb> - .macro ldax arg - .if (.match (.left (1, {arg}), #)) - ; immediate mode - lda #<(.right (.tcount ({arg})-1, {arg})) - ldx #>(.right (.tcount ({arg})-1, {arg})) - .else - ; assume absolute or zero page - lda arg - ldx 1+(arg) - .endif - .endmacro +.macro ldax arg + .if (.match (.left (1, {arg}), #)) + ; immediate mode + lda #<(.right (.tcount ({arg})-1, {arg})) + ldx #>(.right (.tcount ({arg})-1, {arg})) + .else + ; assume absolute or zero page + lda arg + ldx 1+(arg) + .endif +.endmacro </verb></tscreen> Using the <tt/<ref id=".MATCH" name=".MATCH">/ function, the macro is able to @@ -4096,11 +4097,11 @@ as end-of-list. The macro can be used as <tscreen><verb> - foo: .word $5678 - ... - ldax #$1234 ; X=$12, A=$34 - ... - ldax foo ; X=$56, A=$78 +foo: .word $5678 +... + ldax #$1234 ; X=$12, A=$34 +... + ldax foo ; X=$56, A=$78 </verb></tscreen> @@ -4109,38 +4110,38 @@ The macro can be used as Macros may be used recursively: <tscreen><verb> - .macro push r1, r2, r3 - lda r1 - pha - .if .paramcount > 1 - push r2, r3 - .endif - .endmacro +.macro push r1, r2, r3 + lda r1 + pha +.ifnblank r2 + push r2, r3 +.endif +.endmacro </verb></tscreen> -There's also a special macro to help writing recursive macros: <tt><ref -id=".EXITMACRO" name=".EXITMACRO"></tt> This command will stop macro expansion -immediately: +There's also a special macro command to help with writing recursive macros: +<tt><ref id=".EXITMACRO" name=".EXITMACRO"></tt>. That command will stop macro +expansion immediately: <tscreen><verb> - .macro push r1, r2, r3, r4, r5, r6, r7 - .ifblank r1 - ; First parameter is empty - .exitmacro - .else - lda r1 - pha - .endif - push r2, r3, r4, r5, r6, r7 - .endmacro +.macro push r1, r2, r3, r4, r5, r6, r7 +.ifblank r1 + ; First parameter is empty + .exitmacro +.else + lda r1 + pha +.endif + push r2, r3, r4, r5, r6, r7 +.endmacro </verb></tscreen> -When expanding this macro, the expansion will push all given parameters +When expanding that macro, the expansion will push all given parameters until an empty one is encountered. The macro may be called like this: <tscreen><verb> - push $20, $21, $32 ; Push 3 ZP locations - push $21 ; Push one ZP location + push $20, $21, $32 ; Push 3 ZP locations + push $21 ; Push one ZP location </verb></tscreen> @@ -4151,27 +4152,27 @@ Now, with recursive macros, <tt><ref id=".IFBLANK" name=".IFBLANK"></tt> and Have a look at the inc16 macro above. Here is it again: <tscreen><verb> - .macro inc16 addr - clc - lda addr - adc #$01 - sta addr - lda addr+1 - adc #$00 - sta addr+1 - .endmacro +.macro inc16 addr + clc + lda addr + adc #<$0001 + sta addr + lda addr+1 + adc #>$0001 + sta addr+1 +.endmacro </verb></tscreen> If you have a closer look at the code, you will notice, that it could be written more efficiently, like this: <tscreen><verb> - .macro inc16 addr - inc addr - bne Skip - inc addr+1 - Skip: - .endmacro +.macro inc16 addr + inc addr + bne Skip + inc addr+1 +Skip: +.endmacro </verb></tscreen> But imagine what happens, if you use this macro twice? Since the label "Skip" @@ -4183,27 +4184,27 @@ local variables are replaced by a unique name in each separate macro expansion. So we can solve the problem above by using <tt/.LOCAL/: <tscreen><verb> - .macro inc16 addr - .local Skip ; Make Skip a local symbol - inc addr - bne Skip - inc addr+1 - Skip: ; Not visible outside - .endmacro +.macro inc16 addr + .local Skip ; Make Skip a local symbol + inc addr + bne Skip + inc addr+1 +Skip: ; Not visible outside +.endmacro </verb></tscreen> Another solution is of course to start a new lexical block inside the macro that hides any labels: <tscreen><verb> - .macro inc16 addr - .proc - inc addr - bne Skip - inc addr+1 - Skip: - .endproc - .endmacro +.macro inc16 addr +.proc + inc addr + bne Skip + inc addr+1 +Skip: +.endproc +.endmacro </verb></tscreen> @@ -4240,7 +4241,7 @@ different: be omitted. <item> Since <tt><ref id=".DEFINE" name=".DEFINE"></tt> style macros may not - contain end-of-line tokens, there are things that cannot be done. They + contain end-of-line tokens, there are things that cannot be done. They may not contain several processor instructions for example. So, while some things may be done with both macro types, each type has special usages. The types complement each other. @@ -4254,27 +4255,27 @@ To emulate assemblers that use "<tt/EQU/" instead of "<tt/=/" you may use the following <tt/.DEFINE/: <tscreen><verb> - .define EQU = +.define EQU = - foo EQU $1234 ; This is accepted now +foo EQU $1234 ; This is accepted now </verb></tscreen> You may use the directive to define string constants used elsewhere: <tscreen><verb> - ; Define the version number - .define VERSION "12.3a" +; Define the version number +.define VERSION "12.3a" - ; ... and use it - .asciiz VERSION + ; ... and use it + .asciiz VERSION </verb></tscreen> Macros with parameters may also be useful: <tscreen><verb> - .define DEBUG(message) .out message +.define DEBUG(message) .out message - DEBUG "Assembling include file #3" + DEBUG "Assembling include file #3" </verb></tscreen> Note that, while formal parameters have to be placed in braces, this is @@ -4283,12 +4284,12 @@ detect the end of one parameter, only the first token is used. If you don't like that, use classic macros instead: <tscreen><verb> - .macro DEBUG message - .out message - .endmacro +.macro DEBUG message + .out message +.endmacro </verb></tscreen> -(This is an example where a problem can be solved with both macro types). +(That is an example where a problem can be solved with both macro types). <sect1>Characters in macros<p> @@ -4308,12 +4309,12 @@ be sure to take the translation into account. <sect1>Deleting macros<p> Macros can be deleted. This will not work if the macro that should be deleted -is currently expanded as in the following non working example: +is currently expanded as in the following non-working example: <tscreen><verb> - .macro notworking - .delmacro notworking - .endmacro +.macro notworking + .delmacro notworking +.endmacro notworking ; Will not work </verb></tscreen> @@ -4324,19 +4325,19 @@ for <tt><ref id=".DEFINE" name=".DEFINE"></tt> style macros, <tt><ref id=".UNDEFINE" name=".UNDEFINE"></tt> must be used. Example: <tscreen><verb> - .define value 1 - .macro mac - .byte 2 - .endmacro +.define value 1 +.macro mac + .byte 2 +.endmacro - .byte value ; Emit one byte with value 1 - mac ; Emit another byte with value 2 + .byte value ; Emit one byte with value 1 + mac ; Emit another byte with value 2 - .undefine value - .delmacro mac +.undefine value +.delmacro mac - .byte value ; Error: Unknown identifier - mac ; Error: Missing ":" + .byte value ; Error: Unknown identifier + mac ; Error: Missing ":" </verb></tscreen> A separate command for <tt>.DEFINE</tt> style macros was necessary, because @@ -4348,6 +4349,7 @@ argument to <tt>.UNDEFINE</tt> is not allowed to come from another different commands increases flexibility. + <sect>Macro packages<label id="macropackages"><p> Using the <tt><ref id=".MACPACK" name=".MACPACK"></tt> directive, predefined @@ -4497,7 +4499,7 @@ it is possible to determine if the instruction is supported, which is the case for the 65SC02, 65C02 and 65816 CPUs (the latter two are upwards compatible to the 65SC02). - + <sect1><tt>.MACPACK module</tt><p> This macro package defines a macro named <tt/module_header/. It takes an @@ -4862,6 +4864,3 @@ freely, subject to the following restrictions: </article> - - - diff --git a/src/ca65/macro.c b/src/ca65/macro.c index 634f2107e..1f6812ce0 100644 --- a/src/ca65/macro.c +++ b/src/ca65/macro.c @@ -147,7 +147,7 @@ static int DoMacAbort = 0; /* Counter to create local names for symbols */ static unsigned LocalName = 0; -/* Define style macros disabled if != 0 */ +/* Define-style macros disabled if != 0 */ static unsigned DisableDefines = 0; @@ -422,8 +422,8 @@ void MacDef (unsigned Style) EnterRawTokenMode (); NextTok (); - /* If we have a DEFINE style macro, we may have parameters in braces, - ** otherwise we may have parameters without braces. + /* If we have a DEFINE-style macro, we may have parameters in parentheses; + ** otherwise, we may have parameters without parentheses. */ if (Style == MAC_STYLE_CLASSIC) { HaveParams = 1; @@ -475,7 +475,7 @@ void MacDef (unsigned Style) } } - /* For class macros, we expect a separator token, for define style macros, + /* For classic macros, we expect a separator token, for define-style macros, ** we expect the closing paren. */ if (Style == MAC_STYLE_CLASSIC) { @@ -485,9 +485,9 @@ void MacDef (unsigned Style) } /* Preparse the macro body. We will read the tokens until we reach end of - ** file, or a .endmacro (or end of line for DEFINE style macros) and store - ** them into an token list internal to the macro. For classic macros, there - ** the .LOCAL command is detected and removed at this time. + ** file, or a .endmacro (or end of line for DEFINE-style macros) and store + ** them into a token list internal to the macro. For classic macros, + ** the .LOCAL command is detected and removed, at this time. */ while (1) { @@ -752,11 +752,11 @@ ExpandParam: FreeTokNode (Mac->Final); Mac->Final = 0; - /* Problem: When a .define style macro is expanded within the call + /* Problem: When a .define-style macro is expanded within the call ** of a classic one, the latter may be terminated and removed while - ** the expansion of the .define style macro is still active. Because + ** the expansion of the .define-style macro is still active. Because ** line info slots are "stacked", this runs into a CHECK FAILED. For - ** now, we will fix that by removing the .define style macro expansion + ** now, we will fix that by removing the .define-style macro expansion ** immediately, once the final token is placed. The better solution ** would probably be to not require AllocLineInfoSlot/FreeLineInfoSlot ** to be called in FIFO order, but this is a bigger change. @@ -785,72 +785,74 @@ MacEnd: static void StartExpClassic (MacExp* E) /* Start expanding a classic macro */ { - token_t Term; + token_t Term; /* Skip the macro name */ NextTok (); - /* Read the actual parameters */ - while (!TokIsSep (CurTok.Tok)) { + /* Does this invocation have any arguments? */ + if (!TokIsSep (CurTok.Tok)) { - TokNode* Last; + /* Read the actual parameters */ + while (1) { + TokNode* Last; - /* Check for maximum parameter count */ - if (E->ParamCount >= E->M->ParamCount) { - ErrorSkip ("Too many macro parameters"); - break; - } - - /* The macro may optionally be enclosed in curly braces */ - Term = GetTokListTerm (TOK_COMMA); - - /* Read tokens for one parameter, accept empty params */ - Last = 0; - while (CurTok.Tok != Term && CurTok.Tok != TOK_SEP) { - - TokNode* T; - - /* Check for end of file */ - if (CurTok.Tok == TOK_EOF) { - Error ("Unexpected end of file"); - FreeMacExp (E); - return; - } - - /* Get the next token in a node */ - T = NewTokNode (); - - /* Insert it into the list */ - if (Last == 0) { - E->Params [E->ParamCount] = T; - } else { - Last->Next = T; - } - Last = T; - - /* And skip it... */ - NextTok (); - } - - /* One parameter more */ - ++E->ParamCount; - - /* If the macro argument was enclosed in curly braces, end-of-line - ** is an error. Skip the closing curly brace. - */ - if (Term == TOK_RCURLY) { - if (CurTok.Tok == TOK_SEP) { - Error ("End of line encountered within macro argument"); + /* Check for maximum parameter count */ + if (E->ParamCount >= E->M->ParamCount) { + ErrorSkip ("Too many macro parameters"); break; } - NextTok (); - } - /* Check for a comma */ - if (CurTok.Tok == TOK_COMMA) { - NextTok (); - } else { - break; + /* The macro argument optionally may be enclosed in curly braces */ + Term = GetTokListTerm (TOK_COMMA); + + /* Read tokens for one parameter, accept empty params */ + Last = 0; + while (CurTok.Tok != Term && CurTok.Tok != TOK_SEP) { + TokNode* T; + + /* Check for end of file */ + if (CurTok.Tok == TOK_EOF) { + Error ("Unexpected end of file"); + FreeMacExp (E); + return; + } + + /* Get the next token in a node */ + T = NewTokNode (); + + /* Insert it into the list */ + if (Last == 0) { + E->Params [E->ParamCount] = T; + } else { + Last->Next = T; + } + Last = T; + + /* And skip it... */ + NextTok (); + } + + /* One parameter more */ + ++E->ParamCount; + + /* If the macro argument was enclosed in curly braces, end-of-line + ** is an error. Skip the closing curly brace. + */ + if (Term == TOK_RCURLY) { + if (CurTok.Tok == TOK_SEP) { + Error ("End of line encountered within macro argument"); + break; + } + NextTok (); + } + + /* Check for a comma */ + if (CurTok.Tok == TOK_COMMA) { + NextTok (); + } else { + break; + } } } @@ -864,9 +866,9 @@ static void StartExpClassic (MacExp* E) static void StartExpDefine (MacExp* E) -/* Start expanding a DEFINE style macro */ +/* Start expanding a DEFINE-style macro */ { - /* A define style macro must be called with as many actual parameters + /* A define-style macro must be called with as many actual parameters ** as there are formal ones. Get the parameter count. */ unsigned Count = E->M->ParamCount; @@ -876,10 +878,9 @@ static void StartExpDefine (MacExp* E) /* Read the actual parameters */ while (Count--) { + TokNode* Last; - TokNode* Last; - - /* The macro may optionally be enclosed in curly braces */ + /* The macro argument optionally may be enclosed in curly braces */ token_t Term = GetTokListTerm (TOK_COMMA); /* Check if there is really a parameter */ @@ -892,7 +893,6 @@ static void StartExpDefine (MacExp* E) /* Read tokens for one parameter */ Last = 0; do { - TokNode* T; /* Get the next token in a node */ @@ -936,7 +936,7 @@ static void StartExpDefine (MacExp* E) } /* Macro expansion will overwrite the current token. This is a problem - ** for define style macros since these are called from the scanner level. + ** for define-style macros since these are called from the scanner level. ** To avoid it, remember the current token and re-insert it, once macro ** expansion is done. */ @@ -1007,8 +1007,8 @@ Macro* FindMacro (const StrBuf* Name) Macro* FindDefine (const StrBuf* Name) -/* Try to find the define style macro with the given name and return it. If no -** such macro was found, return NULL. +/* Try to find the define-style macro with the given name; and, return it. +** If no such macro was found, return NULL. */ { Macro* M; @@ -1034,7 +1034,7 @@ int InMacExpansion (void) void DisableDefineStyleMacros (void) -/* Disable define style macros until EnableDefineStyleMacros is called */ +/* Disable define-style macros until EnableDefineStyleMacros() is called */ { ++DisableDefines; } @@ -1042,8 +1042,8 @@ void DisableDefineStyleMacros (void) void EnableDefineStyleMacros (void) -/* Re-enable define style macros previously disabled with -** DisableDefineStyleMacros. +/* Re-enable define-style macros previously disabled with +** DisableDefineStyleMacros(). */ { PRECONDITION (DisableDefines > 0); diff --git a/testcode/assembler/paramcount.s b/testcode/assembler/paramcount.s new file mode 100644 index 000000000..4e9190df6 --- /dev/null +++ b/testcode/assembler/paramcount.s @@ -0,0 +1,20 @@ +; Test ca65's handling of the .paramcount read-only variable. +; .paramcount should see all given arguments, even when they are empty. + +.macro push r1, r2, r3, r4, r5, r6 + .out .sprintf(" .paramcount = %u", .paramcount) +.if .paramcount <> 0 +.ifblank r1 + .warning "r1 is blank!" +.exitmacro +.endif + lda r1 + pha + + push r2, r3, r4, r5, r6 +.endif +.endmacro + + push 1, , {} + push 1, , + push 1 From 4a49b0c8f88e33b52a62c25623173ddb360988b2 Mon Sep 17 00:00:00 2001 From: mrdudz <mrdudz@users.noreply.github.com> Date: Sun, 22 Nov 2015 19:20:58 +0100 Subject: [PATCH 322/351] reset screen editor at shutdown --- libsrc/c64/soft80_conio.s | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 4e24a0341..23e292301 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -51,13 +51,9 @@ soft80_init: jmp soft80_kclrscr soft80_shutdown: - lda #$1b - sta VIC_CTRL1 - lda #$03 - sta CIA2_PRA - lda #$15 - sta VIC_VIDEO_ADR - rts + + jsr $fda3 ; Initialise I/O + jmp $ff5b ; Initialize screen editor .segment "INIT" firstinit: From 4dc4ea60eed898841e7d64cf60cebcb68ec62105 Mon Sep 17 00:00:00 2001 From: f <f@aspekt.fi> Date: Thu, 26 Nov 2015 19:00:47 +0200 Subject: [PATCH 323/351] Implemented escaping of spaces in ca65 dependency files. Largely based on input.c from cc65 (WriteEscaped was copied verbatim). --- src/ca65/filetab.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ca65/filetab.c b/src/ca65/filetab.c index fbe163f51..ce4b15c03 100644 --- a/src/ca65/filetab.c +++ b/src/ca65/filetab.c @@ -262,6 +262,21 @@ void WriteFiles (void) +static void WriteEscaped (FILE* F, const char* Name) +/* Write a file name to a dependency file escaping spaces */ +{ + while (*Name) { + if (*Name == ' ') { + /* Escape spaces */ + fputc ('\\', F); + } + fputc (*Name, F); + ++Name; + } +} + + + static void WriteDep (FILE* F, FileType Types) /* Helper function. Writes all file names that match Types to the output */ { @@ -285,9 +300,9 @@ static void WriteDep (FILE* F, FileType Types) fputc (' ', F); } - /* Print the dependency */ + /* Print the dependency escaping spaces */ Filename = GetStrBuf (E->Name); - fprintf (F, "%*s", SB_GetLen (Filename), SB_GetConstBuf (Filename)); + WriteEscaped (F, SB_GetConstBuf (Filename)); } } @@ -305,7 +320,8 @@ static void CreateDepFile (const char* Name, FileType Types) } /* Print the output file followed by a tab char */ - fprintf (F, "%s:\t", OutFile); + WriteEscaped (F, OutFile); + fputs (":\t", F); /* Write out the dependencies for the output file */ WriteDep (F, Types); From 25ab2c60d5f6da7b98c4eabd63023557410afffd Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel <blackystardust68@yahoo.com> Date: Sat, 28 Nov 2015 22:06:32 -0800 Subject: [PATCH 324/351] Added a menu to em-test.c and a struct that holds the available emd's, this way the user that wants to test an emd can use the menu to select which one to test. --- testcode/lib/em-test.c | 104 ++++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 27 deletions(-) diff --git a/testcode/lib/em-test.c b/testcode/lib/em-test.c index bd4eddc6a..6877eb352 100644 --- a/testcode/lib/em-test.c +++ b/testcode/lib/em-test.c @@ -5,35 +5,9 @@ #include <conio.h> #include <em.h> - -#if defined(__C64__) -#define DRIVERNAME "c64-ram.emd" -#elif defined(__C128__) -#define DRIVERNAME "c128-ram.emd" -#elif defined(__C16__) -#define DRIVERNAME "c16-ram.emd" -#elif defined(__CBM510__) -#define DRIVERNAME "cbm510-ram.emd" -#elif defined(__CBM610__) -#define DRIVERNAME "cbm610-ram.emd" -#elif defined(__APPLE2ENH__) -#define DRIVERNAME "a2e.auxmem.emd" -#elif defined(__APPLE2__) -#define DRIVERNAME "a2.auxmem.emd" -#elif defined(__ATARIXL__) -#define DRIVERNAME "atrx130.emd" -#elif defined(__ATARI__) -#define DRIVERNAME "atr130.emd" -#else -#define DRIVERNAME "unknown" -#error "Unknown target system" -#endif - - #define FORCE_ERROR1 0 #define FORCE_ERROR2 0 - #define PAGE_SIZE 128 /* Size in words */ #define BUF_SIZE (PAGE_SIZE + PAGE_SIZE/2) static unsigned buf[BUF_SIZE]; @@ -75,7 +49,65 @@ static void cmp (unsigned page, register const unsigned* buf, } } +typedef struct emd_test_s { + char key; + char *displayname; + char *drivername; +} emd_test_t; +static emd_test_t drivers[] = { + +#if defined(__APPLE2__) + { '0', "Apple II auxiliary memory", "a2e.auxmem.emd" }, +#endif + +#if defined(__APPLE2ENH__) + { '0', "Apple II auxiliary memory", "a2e.auxmem.emd" }, +#endif + +#if defined(__ATARI__) + { '0', "Atari 130XE memory", "atr130.emd" }, +#endif + +#if defined(__ATARIXL__) + { '0', "Atari 130XE memory", "atr130.emd" }, +#endif + +#if defined(__C16__) + { '0', "C16 RAM above $8000", "c16-ram.emd" }, +#endif + +#if defined(__C64__) + { '0', "C64 RAM above $D000", "c64-ram.emd" }, + { '1', "C64 256K", "c64-c256k.emd" }, + { '2', "Double Quick Brown Box", "c64-dqbb.emd" }, + { '3', "GEORAM", "c64-georam.emd" }, + { '4', "Isepic", "c64-isepic.emd" }, + { '5', "RamCart", "c64-ramcart.emd" }, + { '6', "REU", "c64-reu.emd" }, + { '7', "C128 VDC (in C64 mode)", "c64-vdc.emd" }, + { '8', "C64DTV himem", "dtv-himem.emd" }, +#endif + +#if defined(__C128__) + { '0', "C128 RAM in bank 1", "c128-ram.emd" }, + { '1', "C128 RAM in banks 1, 2 & 3", "c128-ram2.emd" }, + { '2', "GEORAM", "c128-georam.emd" }, + { '3', "RamCart", "c128-ramcart.emd" }, + { '4', "REU", "c128-reu.emd" }, + { '5', "VDC", "c128-vdc.emd" }, +#endif + +#if defined(__CBM510__) + { '0', "CBM5x0 RAM in bank 2", "cbm510-ram.emd" }, +#endif + +#if defined(__CBM610__) + { '0', "CBM6x0/7x0 RAM in bank 2", "cbm610-ram.emd" }, +#endif + + { NULL, NULL } +}; int main (void) { @@ -85,9 +117,27 @@ int main (void) unsigned PageCount; unsigned char X, Y; struct em_copy c; + unsigned index; + signed char valid_key = -1; + char key; clrscr (); - Res = em_load_driver (DRIVERNAME); + cputs ("Which RAM exp to test?\r\n\r\n"); + for (index = 0; drivers[index].displayname; ++index) { + cprintf("%c: %s\r\n", drivers[index].key, drivers[index].displayname); + } + + while (valid_key == -1) { + key = cgetc(); + for (index = 0; drivers[index].displayname && valid_key == -1; ++index) { + if (key == drivers[index].key) { + valid_key = index; + } + } + } + + clrscr (); + Res = em_load_driver (drivers[valid_key].drivername); if (Res != EM_ERR_OK) { cprintf ("Error in em_load_driver: %u\r\n", Res); cprintf ("os: %u, %s\r\n", _oserror, _stroserror (_oserror)); From 97c9ed327387fd07c7161801aed07505ff21dacd Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel <blackystardust68@yahoo.com> Date: Sun, 29 Nov 2015 10:50:22 -0800 Subject: [PATCH 325/351] Changed according to suggestions. --- testcode/lib/em-test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testcode/lib/em-test.c b/testcode/lib/em-test.c index 6877eb352..4a08d57c4 100644 --- a/testcode/lib/em-test.c +++ b/testcode/lib/em-test.c @@ -106,7 +106,7 @@ static emd_test_t drivers[] = { { '0', "CBM6x0/7x0 RAM in bank 2", "cbm610-ram.emd" }, #endif - { NULL, NULL } + { 0, NULL, NULL } }; int main (void) @@ -123,13 +123,13 @@ int main (void) clrscr (); cputs ("Which RAM exp to test?\r\n\r\n"); - for (index = 0; drivers[index].displayname; ++index) { + for (index = 0; drivers[index].key; ++index) { cprintf("%c: %s\r\n", drivers[index].key, drivers[index].displayname); } - while (valid_key == -1) { + while (valid_key < 0) { key = cgetc(); - for (index = 0; drivers[index].displayname && valid_key == -1; ++index) { + for (index = 0; drivers[index].key && valid_key < 0; ++index) { if (key == drivers[index].key) { valid_key = index; } From cf9e7856cf5895c18f3094ca53889429e6657d7f Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel <blackystardust68@yahoo.com> Date: Sun, 29 Nov 2015 11:35:25 -0800 Subject: [PATCH 326/351] Removed an 'rts'. --- libsrc/c128/emd/c128-ram.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/c128/emd/c128-ram.s b/libsrc/c128/emd/c128-ram.s index bef0a15ee..ab99d7aa3 100644 --- a/libsrc/c128/emd/c128-ram.s +++ b/libsrc/c128/emd/c128-ram.s @@ -70,7 +70,7 @@ INSTALL: stx curpage+1 ; Invalidate the current page inx txa ; A = X = EM_ERR_OK - rts +; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ ; UNINSTALL routine. Is called before the driver is removed from memory. From 18208f4d2e9ebb582803a8fac77ec97e57944ca5 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel <blackystardust68@yahoo.com> Date: Sun, 29 Nov 2015 23:04:23 -0800 Subject: [PATCH 327/351] Fixed the c128 ram (bank 1) emd. --- libsrc/c128/emd/c128-ram.s | 23 +++++++++++++++-------- testcode/lib/.gitignore | 2 ++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 testcode/lib/.gitignore diff --git a/libsrc/c128/emd/c128-ram.s b/libsrc/c128/emd/c128-ram.s index ab99d7aa3..8c958a540 100644 --- a/libsrc/c128/emd/c128-ram.s +++ b/libsrc/c128/emd/c128-ram.s @@ -51,7 +51,7 @@ PAGES = (TOPMEM - BASE) / 256 ; Data. .bss -curpage: .res 1 ; Current page number +curpage: .res 2 ; Current page number window: .res 256 ; Memory "window" @@ -96,7 +96,8 @@ PAGECOUNT: ; by the driver. ; -MAP: sta curpage +MAP: sei + sta curpage stx curpage+1 ; Remember the new page clc @@ -120,6 +121,7 @@ MAP: sta curpage lda #<window ldx #>window ; Return the window address + cli rts ; ------------------------------------------------------------------------ @@ -134,7 +136,8 @@ USE: sta curpage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. -COMMIT: lda curpage ; Get the current page +COMMIT: sei + lda curpage ; Get the current page ldx curpage+1 bmi done ; Jump if no page mapped @@ -157,7 +160,8 @@ COMMIT: lda curpage ; Get the current page ; Done -done: rts +done: cli + rts ; ------------------------------------------------------------------------ ; COPYFROM: Copy from extended into linear memory. A pointer to a structure @@ -166,6 +170,7 @@ done: rts ; COPYFROM: + sei sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer @@ -223,7 +228,8 @@ COPYFROM: ; Done -@L4: rts +@L4: cli + rts ; ------------------------------------------------------------------------ ; COPYTO: Copy from linear into extended memory. A pointer to a structure @@ -231,7 +237,8 @@ COPYFROM: ; The function must not return anything. ; -COPYTO: sta ptr3 +COPYTO: sei + sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS @@ -288,5 +295,5 @@ COPYTO: sta ptr3 ; Done -@L4: rts - +@L4: cli + rts diff --git a/testcode/lib/.gitignore b/testcode/lib/.gitignore new file mode 100644 index 000000000..9bb8eaa3e --- /dev/null +++ b/testcode/lib/.gitignore @@ -0,0 +1,2 @@ +*.o +em-test-* From 3a01ba95097b2de0be3108441816423d6fcdea1d Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel <blackystardust68@yahoo.com> Date: Mon, 30 Nov 2015 10:15:28 -0800 Subject: [PATCH 328/351] Fixed emd driver names for atari-xl and apple2e. --- testcode/lib/em-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testcode/lib/em-test.c b/testcode/lib/em-test.c index 4a08d57c4..f4a56029a 100644 --- a/testcode/lib/em-test.c +++ b/testcode/lib/em-test.c @@ -58,7 +58,7 @@ typedef struct emd_test_s { static emd_test_t drivers[] = { #if defined(__APPLE2__) - { '0', "Apple II auxiliary memory", "a2e.auxmem.emd" }, + { '0', "Apple II auxiliary memory", "a2.auxmem.emd" }, #endif #if defined(__APPLE2ENH__) @@ -70,7 +70,7 @@ static emd_test_t drivers[] = { #endif #if defined(__ATARIXL__) - { '0', "Atari 130XE memory", "atr130.emd" }, + { '0', "Atari 130XE memory", "atrx130.emd" }, #endif #if defined(__C16__) From 22f10b14598abac86a4b5a87bf4b93487f225174 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Tue, 1 Dec 2015 23:06:51 +0100 Subject: [PATCH 329/351] Made conio program compatible with joystick-only target(s). --- testcode/lib/conio.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/testcode/lib/conio.c b/testcode/lib/conio.c index 3a8048632..bdee12262 100644 --- a/testcode/lib/conio.c +++ b/testcode/lib/conio.c @@ -13,6 +13,7 @@ #include <conio.h> #include <string.h> #include <stdlib.h> +#include <joystick.h> static char grid[5][5] = { { CH_ULCORNER, CH_HLINE, CH_TTEE, CH_HLINE, CH_URCORNER }, @@ -45,7 +46,7 @@ void main(void) } textcolor(tcol); - cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize ); + cprintf("\n\n\r Screensize is: %dx%d", xsize, ysize); chlinexy(0,6,xsize); cvlinexy(0,6,3); @@ -86,7 +87,7 @@ void main(void) revers(0); cursor(1); - for(;;) { + for (;;) { gotoxy(8, 2); j = n & 1; @@ -96,6 +97,14 @@ void main(void) cputs(" revers"); revers(0); +#if defined(__NES__) || defined(__PCE__) + + joy_install(joy_static_stddrv); + while (!joy_read(JOY_1)) ; + joy_uninstall(); + +#else + gotoxy(8 + inpos,1); i = cgetc(); if ((i >= '0') && (i<='9')) { @@ -121,8 +130,8 @@ void main(void) inpos = (inpos + 1) & 7; } +#endif + ++n; } - - for(;;); } From 7cd80e7450f3eea7e8a7b7851ba63dec6d9f8f24 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel <blackystardust68@yahoo.com> Date: Wed, 2 Dec 2015 00:21:55 -0800 Subject: [PATCH 330/351] optimized the sei/cli pairing a bit. --- libsrc/c128/emd/c128-ram.s | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libsrc/c128/emd/c128-ram.s b/libsrc/c128/emd/c128-ram.s index 8c958a540..3fc52c9cc 100644 --- a/libsrc/c128/emd/c128-ram.s +++ b/libsrc/c128/emd/c128-ram.s @@ -96,8 +96,7 @@ PAGECOUNT: ; by the driver. ; -MAP: sei - sta curpage +MAP: sta curpage stx curpage+1 ; Remember the new page clc @@ -108,6 +107,7 @@ MAP: sei lda #<ptr1 sta FETVEC + sei ; Transfer one page @@ -116,12 +116,12 @@ MAP: sei sta window,y iny bne @L1 + cli ; Return the memory window lda #<window ldx #>window ; Return the window address - cli rts ; ------------------------------------------------------------------------ @@ -136,8 +136,7 @@ USE: sta curpage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. -COMMIT: sei - lda curpage ; Get the current page +COMMIT: lda curpage ; Get the current page ldx curpage+1 bmi done ; Jump if no page mapped @@ -149,6 +148,7 @@ COMMIT: sei lda #<ptr1 sta STAVEC + sei ; Transfer one page. Y must be zero on entry @@ -157,11 +157,11 @@ COMMIT: sei jsr STASH iny bne @L1 + cli ; Done -done: cli - rts +done: rts ; ------------------------------------------------------------------------ ; COPYFROM: Copy from extended into linear memory. A pointer to a structure @@ -170,7 +170,6 @@ done: cli ; COPYFROM: - sei sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer @@ -201,6 +200,7 @@ COPYFROM: ; Copy full pages ldy #$00 + sei @L1: ldx #MMU_CFG_RAM1 jsr FETCH sta (ptr2),y @@ -237,8 +237,7 @@ COPYFROM: ; The function must not return anything. ; -COPYTO: sei - sta ptr3 +COPYTO: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS @@ -268,6 +267,7 @@ COPYTO: sei ; Copy full pages ldy #$00 + sei @L1: lda (ptr2),y ldx #MMU_CFG_RAM1 jsr STASH From 377f31d08527060d9e2ef6efff6e4c7a058f5dd4 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Wed, 2 Dec 2015 21:34:08 +0100 Subject: [PATCH 331/351] Fixed soft80 shutdown. A call to $FDA3 cannot be used because it re-enables the BASIC ROM. If a large program (such as Contiki's webbrowser80) has destructor code or data "behind" that ROM, then the program might crash when it tries to quit gracefully. Changing that code to set CIA2_PRA works well enough. --- libsrc/c64/soft80_conio.s | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/libsrc/c64/soft80_conio.s b/libsrc/c64/soft80_conio.s index 23e292301..874d41a53 100644 --- a/libsrc/c64/soft80_conio.s +++ b/libsrc/c64/soft80_conio.s @@ -25,12 +25,12 @@ soft80_init: ; colorram being set up as expected, which is why we cant use the ; _bgcolor and _textcolor functions here. - lda CHARCOLOR ; use current textcolor - and #$0f ; make sure the upper nibble is 0s + lda CHARCOLOR ; use current textcolor + and #$0F ; make sure the upper nibble is 0s sta CHARCOLOR - lda VIC_BG_COLOR0 ; use current bgcolor - and #$0f + lda VIC_BG_COLOR0 ; use current bgcolor + and #$0F sta soft80_internal_bgcolor asl a asl a @@ -39,21 +39,22 @@ soft80_init: ora CHARCOLOR sta soft80_internal_cellcolor - lda #$3b + lda #$3B sta VIC_CTRL1 lda #$00 sta CIA2_PRA lda #$68 sta VIC_VIDEO_ADR - lda #$c8 + lda #$C8 sta VIC_CTRL2 jmp soft80_kclrscr soft80_shutdown: - jsr $fda3 ; Initialise I/O - jmp $ff5b ; Initialize screen editor + lda #$07 + sta CIA2_PRA + jmp $FF5B ; Initialize video I/O .segment "INIT" firstinit: @@ -66,18 +67,18 @@ firstinit: inc soft80_first_init - lda #>soft80_charset - sta ptr1+1 lda #<soft80_charset + ldx #>soft80_charset sta ptr1 - lda #>soft80_lo_charset - sta ptr2+1 + stx ptr1+1 lda #<soft80_lo_charset + ldx #>soft80_lo_charset sta ptr2 - lda #>soft80_hi_charset - sta ptr3+1 + stx ptr2+1 lda #<soft80_hi_charset + ldx #>soft80_hi_charset sta ptr3 + stx ptr3+1 ldx #4 @l2: @@ -99,12 +100,12 @@ firstinit: bne @l2 ; copy the kplot tables to ram under I/O - ;ldx #0 ; is 0 + ;ldx #0 ; is 0 @l3: lda soft80_tables_data_start,x sta soft80_bitmapxlo,x - lda soft80_tables_data_start + (soft80_tables_data_end - soft80_tables_data_start - $100) ,x - sta soft80_bitmapxlo + (soft80_tables_data_end - soft80_tables_data_start - $100),x + lda soft80_tables_data_start + (soft80_tables_data_end - soft80_tables_data_start - $0100),x + sta soft80_bitmapxlo + (soft80_tables_data_end - soft80_tables_data_start - $0100),x inx bne @l3 @@ -155,4 +156,4 @@ soft80_internal_cursorxlsb: .data soft80_first_init: - .byte 0 ; flag to check first init, this really must be in .data + .byte 0 ; flag to check first init, this really must be in .data From 4716083f3f2ac66db2d1457daae252000adf7c60 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 13 Dec 2015 07:17:41 -0500 Subject: [PATCH 332/351] Fixed a signed char shift optimization so that it won't be used on signed int also. (It would lose significant bits from the high byte.) --- src/cc65/coptshift.c | 54 +++++++++++++++++++++++++++----------------- src/cc65/coptshift.h | 13 ++++++++--- 2 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/cc65/coptshift.c b/src/cc65/coptshift.c index a4b993073..2f8c2f833 100644 --- a/src/cc65/coptshift.c +++ b/src/cc65/coptshift.c @@ -307,51 +307,63 @@ NextEntry: -unsigned OptShift2(CodeSeg* S) -/* A call to the asrax1 routines may get replaced by something simpler, if -** X is not used later: +unsigned OptShift2 (CodeSeg* S) +/* The sequence +** +** bpl L +** dex +** L: jsr asraxN +** +** might be replaced by N copies of ** ** cmp #$80 ** ror a +** +** if X is not used later (X is assumed to be zero on entry). */ { unsigned Changes = 0; - unsigned I; + unsigned I = 0; /* Walk over the entries */ - I = 0; while (I < CS_GetEntryCount (S)) { unsigned Shift; unsigned Count; + CodeEntry* L[3]; /* Get next entry */ - CodeEntry* E = CS_GetEntry (S, I); + L[0] = CS_GetEntry (S, I); /* Check for the sequence */ - if (E->OPC == OP65_JSR && - (Shift = GetShift (E->Arg)) != SHIFT_NONE && - SHIFT_TYPE (Shift) == SHIFT_TYPE_ASR && - (Count = SHIFT_COUNT (Shift)) > 0 && - Count * 100 <= S->CodeSizeFactor && - !RegXUsed (S, I+1)) { + if (L[0]->OPC == OP65_BPL && + L[0]->JumpTo != 0 && + CS_GetEntries (S, L+1, I+1, 2) && + L[1]->OPC == OP65_DEX && + L[0]->JumpTo->Owner == L[2] && + !CS_RangeHasLabel (S, I, 2) && + L[2]->OPC == OP65_JSR && + SHIFT_TYPE (Shift = GetShift (L[2]->Arg)) == SHIFT_TYPE_ASR && + (Count = SHIFT_COUNT (Shift)) > 0 && + Count * 100 <= S->CodeSizeFactor && + !RegXUsed (S, I+3)) { CodeEntry* X; - unsigned J = I+1; + unsigned J = I+2; /* Generate the replacement sequence */ while (Count--) { /* cmp #$80 */ - X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, E->LI); - CS_InsertEntry (S, X, J++); + X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, L[2]->LI); + CS_InsertEntry (S, X, ++J); /* ror a */ - X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, E->LI); - CS_InsertEntry (S, X, J++); + X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); + CS_InsertEntry (S, X, ++J); } - /* Delete the call to asrax */ - CS_DelEntry (S, I); + /* Remove the bpl/dex/jsr */ + CS_DelEntries (S, I, 3); /* Remember, we had changes */ ++Changes; @@ -412,7 +424,7 @@ unsigned OptShift3 (CodeSeg* S) (Shift = GetShift (L[2]->Arg)) != SHIFT_NONE && SHIFT_DIR (Shift) == SHIFT_DIR_RIGHT && (Count = SHIFT_COUNT (Shift)) > 0) { - + /* Add the replacement insn instead */ CodeEntry* X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+3); @@ -421,7 +433,7 @@ unsigned OptShift3 (CodeSeg* S) CS_InsertEntry (S, X, I+4); } - /* Remove the bcs/dex/jsr */ + /* Remove the bcc/inx/jsr */ CS_DelEntries (S, I, 3); /* Remember, we had changes */ diff --git a/src/cc65/coptshift.h b/src/cc65/coptshift.h index 0410652a1..e7f9cc359 100644 --- a/src/cc65/coptshift.h +++ b/src/cc65/coptshift.h @@ -60,12 +60,19 @@ unsigned OptShift1 (CodeSeg* S); ** L1: */ -unsigned OptShift2(CodeSeg* S); -/* A call to the asrax1 routines may get replaced by something simpler, if -** X is not used later: +unsigned OptShift2 (CodeSeg* S); +/* The sequence +** +** bpl L +** dex +** L: jsr asraxN +** +** might be replaced by N copies of ** ** cmp #$80 ** ror a +** +** if X is not used later (X is assumed to be zero on entry). */ unsigned OptShift3 (CodeSeg* S); From 651b1b40ec03342a874fccc8dd5abfb13b0508ad Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Sun, 13 Dec 2015 17:10:31 -0500 Subject: [PATCH 333/351] Extended a signed char shift optimization, to handle shifts that are longer than 4 bits. --- src/cc65/coptshift.c | 62 ++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/src/cc65/coptshift.c b/src/cc65/coptshift.c index 2f8c2f833..d6af13b76 100644 --- a/src/cc65/coptshift.c +++ b/src/cc65/coptshift.c @@ -320,6 +320,11 @@ unsigned OptShift2 (CodeSeg* S) ** ror a ** ** if X is not used later (X is assumed to be zero on entry). +** If the sequence is followed immediately by another +** +** jsr asraxN +** +** then their shifts are combined. */ { unsigned Changes = 0; @@ -327,10 +332,10 @@ unsigned OptShift2 (CodeSeg* S) /* Walk over the entries */ while (I < CS_GetEntryCount (S)) { - unsigned Shift; - unsigned Count; - CodeEntry* L[3]; + unsigned Count, Count2; + unsigned K; + CodeEntry* L[4]; /* Get next entry */ L[0] = CS_GetEntry (S, I); @@ -338,40 +343,51 @@ unsigned OptShift2 (CodeSeg* S) /* Check for the sequence */ if (L[0]->OPC == OP65_BPL && L[0]->JumpTo != 0 && - CS_GetEntries (S, L+1, I+1, 2) && + CS_GetEntries (S, L+1, I+1, 3) && L[1]->OPC == OP65_DEX && L[0]->JumpTo->Owner == L[2] && !CS_RangeHasLabel (S, I, 2) && L[2]->OPC == OP65_JSR && SHIFT_TYPE (Shift = GetShift (L[2]->Arg)) == SHIFT_TYPE_ASR && - (Count = SHIFT_COUNT (Shift)) > 0 && - Count * 100 <= S->CodeSizeFactor && - !RegXUsed (S, I+3)) { + (Count = SHIFT_COUNT (Shift)) > 0) { - CodeEntry* X; - unsigned J = I+2; + if (L[3]->OPC == OP65_JSR && + SHIFT_TYPE (Shift = GetShift (L[3]->Arg)) == SHIFT_TYPE_ASR && + (Count2 = SHIFT_COUNT (Shift)) > 0) { - /* Generate the replacement sequence */ - while (Count--) { - /* cmp #$80 */ - X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, L[2]->LI); - CS_InsertEntry (S, X, ++J); - - /* ror a */ - X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); - CS_InsertEntry (S, X, ++J); + /* Found a second jsr asraxN */ + Count += Count2; + K = 4; + } else { + K = 3; } + if (Count * 100 <= S->CodeSizeFactor && + !RegXUsed (S, I+K)) { - /* Remove the bpl/dex/jsr */ - CS_DelEntries (S, I, 3); + CodeEntry* X; + unsigned J = I+K; - /* Remember, we had changes */ - ++Changes; + /* Generate the replacement sequence */ + do { + /* cmp #$80 */ + X = NewCodeEntry (OP65_CMP, AM65_IMM, "$80", 0, L[2]->LI); + CS_InsertEntry (S, X, J++); + + /* ror a */ + X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); + CS_InsertEntry (S, X, J++); + } while (--Count); + + /* Remove the bpl/dex/jsr */ + CS_DelEntries (S, I, K); + + /* Remember, we had changes */ + ++Changes; + } } /* Next entry */ ++I; - } /* Return the number of changes made */ From 5e7c7d78fc61ae4da9267551fcb9abf92ea243d6 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 14 Dec 2015 11:46:30 -0500 Subject: [PATCH 334/351] Added a regression test program for the changes in the right-shift optimizer. --- test/val/rotate8.c | 156 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 test/val/rotate8.c diff --git a/test/val/rotate8.c b/test/val/rotate8.c new file mode 100644 index 000000000..0cd691c08 --- /dev/null +++ b/test/val/rotate8.c @@ -0,0 +1,156 @@ +/* + !!DESCRIPTION!! Optimized-shift signed ints right by a constant; and, assign to chars. + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +#include <stdio.h> + +static unsigned char failures = 0; +static unsigned char n = 0; + +/* This number must be read from a variable because +** we want this program, not cc65, to do the shift. +*/ +static const signed int aint0 = 0xAAC0; + +static signed char achar0, achar1; + +static void check(void) +{ + if ((unsigned char)achar0 != (unsigned char)achar1) + ++failures; +} + +static void shift_right_0(void) +{ + achar0 = aint0 >> 0; + check(); +} + +static void shift_right_1(void) +{ + achar0 = aint0 >> 1; + check(); +} + +static void shift_right_2(void) +{ + achar0 = aint0 >> 2; + check(); +} + +static void shift_right_3(void) +{ + achar0 = aint0 >> 3; + check(); +} + +static void shift_right_4(void) +{ + achar0 = aint0 >> 4; + check(); +} + +static void shift_right_5(void) +{ + achar0 = aint0 >> 5; + check(); +} + +static void shift_right_6(void) +{ + achar0 = aint0 >> 6; + check(); +} + +static void shift_right_7(void) +{ + achar0 = aint0 >> 7; + check(); +} + +static void shift_right_8(void) +{ + achar0 = aint0 >> 8; + check(); +} + +static void shift_right_9(void) +{ + achar0 = aint0 >> 9; + check(); +} + +static void shift_right_10(void) +{ + achar0 = aint0 >> 10; + check(); +} + +static void shift_right_11(void) +{ + achar0 = aint0 >> 11; + check(); +} + +static void shift_right_12(void) +{ + achar0 = aint0 >> 12; + check(); +} + +static void shift_right_13(void) +{ + achar0 = aint0 >> 13; + check(); +} + +static void shift_right_14(void) +{ + achar0 = aint0 >> 14; + check(); +} + +static void shift_right_15(void) +{ + achar0 = aint0 >> 15; + check(); +} + +const struct { + signed char achar; + void (*func)(void); +} tests[] = { + {0xC0, shift_right_0}, + {0x60, shift_right_1}, + {0xB0, shift_right_2}, + {0x58, shift_right_3}, + {0xAC, shift_right_4}, + {0x56, shift_right_5}, + {0xAB, shift_right_6}, + {0x55, shift_right_7}, + {0xAA, shift_right_8}, + {0xD5, shift_right_9}, + {0xEA, shift_right_10}, + {0xF5, shift_right_11}, + {0xFA, shift_right_12}, + {0xFD, shift_right_13}, + {0xFE, shift_right_14}, + {0xFF, shift_right_15} +}; + +int main(void) +{ + do { + achar1 = tests[n].achar; + tests[n].func(); + } while (++n < sizeof tests / sizeof tests[0]); + + if (failures) { + printf("rotate8: failures: %u (of %u).\n", + failures, sizeof tests / sizeof tests[0]); + } + return failures; +} From bdbf75372c9ca027ceb6d75da22c7d37b7e7ced9 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Mon, 14 Dec 2015 11:50:43 -0500 Subject: [PATCH 335/351] Added another op-code to the test pattern for a right-shift optimizer in cc65. --- src/cc65/coptshift.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc65/coptshift.c b/src/cc65/coptshift.c index d6af13b76..92210ebb5 100644 --- a/src/cc65/coptshift.c +++ b/src/cc65/coptshift.c @@ -341,7 +341,7 @@ unsigned OptShift2 (CodeSeg* S) L[0] = CS_GetEntry (S, I); /* Check for the sequence */ - if (L[0]->OPC == OP65_BPL && + if ((L[0]->OPC == OP65_BPL || L[0]->OPC == OP65_BCC) && L[0]->JumpTo != 0 && CS_GetEntries (S, L+1, I+1, 3) && L[1]->OPC == OP65_DEX && From a954e713ad096080b284e78dcc5ad2e9c154e938 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen <curaga@operamail.com> Date: Mon, 14 Dec 2015 19:23:27 +0200 Subject: [PATCH 336/351] nes: Fix reading the second controller See http://wiki.nesdev.com/w/index.php/Controller_port_registers --- libsrc/nes/joy/nes-stdjoy.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/nes/joy/nes-stdjoy.s b/libsrc/nes/joy/nes-stdjoy.s index b50c2124d..b5e653c16 100644 --- a/libsrc/nes/joy/nes-stdjoy.s +++ b/libsrc/nes/joy/nes-stdjoy.s @@ -95,9 +95,9 @@ READJOY: tay ; Joystick number (0,1) into Y lda #1 - sta APU_PAD1,y + sta APU_PAD1 lda #0 - sta APU_PAD1,y + sta APU_PAD1 ; Read joystick From abfc36ec9cb528ade2caf342ba902af9d4a86258 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 15 Dec 2015 11:26:04 -0500 Subject: [PATCH 337/351] Programs need to reset NES input controllers by writing to them. --- include/nes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nes.h b/include/nes.h index 934b8a802..a472a0f3c 100644 --- a/include/nes.h +++ b/include/nes.h @@ -155,7 +155,7 @@ struct __apu { }; #define APU (*(struct __apu*)0x4000) -#define JOYPAD ((unsigned char volatile const[2])0x4016) +#define JOYPAD ((unsigned char volatile[2])0x4016) /* The addresses of the static drivers */ extern void nes_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ From 51bcf28a87a95756ff1583626fa4771a83f6acd5 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Wed, 16 Dec 2015 12:24:47 +0100 Subject: [PATCH 338/351] Update package index (as recommended by Travis CI). --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6c6a428e6..10ea789cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: - c install: + - sudo apt-get update - sudo apt-get install linuxdoc-tools linuxdoc-tools-info binutils-mingw-w64-i686 gcc-mingw-w64-i686 sshpass script: - make bin USER_CFLAGS=-Werror From 11786b198e3479b3fd279adc1bb4b780e0bcd388 Mon Sep 17 00:00:00 2001 From: polluks <stefan.haubenthal@gmail.com> Date: Sun, 27 Dec 2015 01:26:28 +0100 Subject: [PATCH 339/351] Amiga support #192 --- src/cl65/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cl65/main.c b/src/cl65/main.c index e704d985c..0a9dd5773 100644 --- a/src/cl65/main.c +++ b/src/cl65/main.c @@ -136,7 +136,7 @@ static char* TargetLib = 0; #if defined(NEED_SPAWN) -# if defined(SPAWN_AMIGA) +# if defined(_AMIGA) # include "spawn-amiga.inc" # else # include "spawn-unix.inc" From a8a6e9df5bb94042fc1d32b12db50db8bcfff6e4 Mon Sep 17 00:00:00 2001 From: polluks <stefan.haubenthal@gmail.com> Date: Sun, 27 Dec 2015 02:09:12 +0100 Subject: [PATCH 340/351] Added chrcvt documentation --- doc/chrcvt.sgml | 116 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100755 doc/chrcvt.sgml diff --git a/doc/chrcvt.sgml b/doc/chrcvt.sgml new file mode 100755 index 000000000..848fb529d --- /dev/null +++ b/doc/chrcvt.sgml @@ -0,0 +1,116 @@ +<!doctype linuxdoc system> <!-- -*- text-mode -*- --> + +<article> +<title>chrcvt Users Guide +<author><url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal"> +<date>2013-02-10 + +<abstract> +chrcvt is the vector font converter. It is able to convert a foreign font into +the native format. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + + +<sect>Overview<p> + +chrcvt is a vector font converter. It is able to convert a "BGI Stroked +Font" to a compact TGI native vector font. See the function <url +url="funcref.html#tgi_load_vectorfont" name="tgi_load_vectorfont"> for usage. + + + +<sect>Usage<p> + +The chrcvt utility converts the font of one Borland file to its cc65 equivalent. + + +<sect1>Command line option overview<p> + +The program may be called as follows: + +<tscreen><verb> +--------------------------------------------------------------------------- +Usage: chrcvt [options] file [options] [file] +Short options: + -h Help (this text) + -v Be more verbose + -V Print the version number and exit + +Long options: + --help Help (this text) + --verbose Be more verbose + --version Print the version number and exit +--------------------------------------------------------------------------- +</verb></tscreen> + + +<sect1>Command line options in detail<p> + +Here is a description of all the command line options: + +<descrip> + + <tag><tt>-v, --verbose</tt></tag> + + Increase the converter verbosity. + + + <tag><tt>-h, --help</tt></tag> + + Print the short option summary shown above. + + + <tag><tt>-V, --version</tt></tag> + + Print the version number of the utility. When submitting a bug report, + please include the operating system you're using, and the compiler + version. +</descrip> + + +<sect>Input and output<p> + +The converter will read one CHR file per invocation and write the font +in TCH format to a new file. + +Example output for the command +<tscreen><verb> +chrcvt --verbose LITT.CHR +</verb></tscreen> +<tscreen><verb> +BGI Stroked Font V1.1 - Aug 12, 1991 +Copyright (c) 1987,1988 Borland International +</verb></tscreen> + + + +<sect>Copyright<p> + +chrcvt is (C) Copyright 2009, Ullrich von Bassewitz. For usage of the +binaries and/or sources the following conditions apply: + +This software is provided 'as-is', without any expressed or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +<enum> +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> From 3b303396bf3b5670e76a53e4dffd01c610b07c82 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Tue, 29 Dec 2015 04:18:17 -0500 Subject: [PATCH 341/351] Made cc65 accept comparisons between pointers with different qualifiers (similarly to subtractions between pointers). --- src/cc65/expr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 64fc17e3f..29e5771d4 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -2105,8 +2105,8 @@ static void hie_compare (const GenDesc* Ops, /* List of generators */ */ Type* left = Indirect (Expr->Type); Type* right = Indirect (Expr2.Type); - if (TypeCmp (left, right) < TC_EQUAL && left->C != T_VOID && right->C != T_VOID) { - /* Incomatible pointers */ + if (TypeCmp (left, right) < TC_QUAL_DIFF && left->C != T_VOID && right->C != T_VOID) { + /* Incompatible pointers */ Error ("Incompatible types"); } } else if (!ED_IsNullPtr (&Expr2)) { From 7e14dde07b5fb5749b5f58fde3f24069682b3cc6 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Thu, 31 Dec 2015 17:41:48 -0500 Subject: [PATCH 342/351] Fixed the cc65 code that handled an addition of a pointer to a 32-bit offset. It didn't demote the offset to int because it looked at the pointer (instead of the offset) which already was 16 bits. --- src/cc65/expr.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 29e5771d4..34cf550a2 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -2390,7 +2390,6 @@ static void parseadd (ExprDesc* Expr) Type* lhst; /* Type of left hand side */ Type* rhst; /* Type of right hand side */ - /* Skip the PLUS token */ NextToken (); @@ -2573,7 +2572,7 @@ static void parseadd (ExprDesc* Expr) flags = CF_PTR; } else if (IsClassInt (lhst) && IsClassPtr (rhst)) { /* Left is int, right is pointer, must scale lhs */ - g_tosint (TypeOf (rhst)); /* Make sure, TOS is int */ + g_tosint (TypeOf (lhst)); /* Make sure TOS is int */ g_swap (CF_INT); /* Swap TOS and primary */ g_scale (CF_INT, CheckedPSizeOf (rhst)); /* Operate on pointers, result type is a pointer */ @@ -2607,7 +2606,6 @@ static void parseadd (ExprDesc* Expr) /* Condition codes not set */ ED_MarkAsUntested (Expr); - } From e0506557577bd26226bd5ef6fc1f9d5315207a99 Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 1 Jan 2016 11:39:55 -0500 Subject: [PATCH 343/351] Added a cc65 regression test for pointer and offset addition operations. --- test/val/add5.c | 250 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 test/val/add5.c diff --git a/test/val/add5.c b/test/val/add5.c new file mode 100644 index 000000000..f8b7d669c --- /dev/null +++ b/test/val/add5.c @@ -0,0 +1,250 @@ +/* +** !!DESCRIPTION!! Simple tests about adding pointers and offsets +** !!ORIGIN!! cc65 regression tests +** !!LICENCE!! Public Domain +** !!AUTHOR!! 2016-01-01, Greg King +*/ + +#include <stdio.h> + +static unsigned char failures = 0; + +static char array[16]; + +static char *cPtr; +static int *iPtr; +static long *lPtr; + +/* These functions test: adding an offset variable to a pointer variable. */ + +static void cPointer_char(void) +{ + char *cP = array; + char offset = 3; + + cPtr = cP + offset; + if (cPtr != (void *)&array[3]) { + ++failures; + } +} + +static void cPointer_int(void) +{ + char *cP = array; + int offset = 3; + + cPtr = cP + offset; + if (cPtr != (void *)&array[3]) { + ++failures; + } +} + +static void cPointer_long(void) +{ + char *cP = array; + long offset = 3; + + cPtr = cP + offset; + if (cPtr != (void *)&array[3]) { + ++failures; + } +} + +static void iPointer_char(void) +{ + int *iP = (int *)array; + char offset = 3; + + iPtr = iP + offset; + if (iPtr != (void *)&array[6]) { + ++failures; + } +} + +static void iPointer_int(void) +{ + int *iP = (int *)array; + int offset = 3; + + iPtr = iP + offset; + if (iPtr != (void *)&array[6]) { + ++failures; + } +} + +static void iPointer_long(void) +{ + int *iP = (int *)array; + long offset = 3; + + iPtr = iP + offset; + if (iPtr != (void *)&array[6]) { + ++failures; + } +} + +static void lPointer_char(void) +{ + long *lP = (long *)array; + char offset = 3; + + lPtr = lP + offset; + if (lPtr != (void *)&array[12]) { + ++failures; + } +} + +static void lPointer_int(void) +{ + long *lP = (long *)array; + int offset = 3; + + lPtr = lP + offset; + if (lPtr != (void *)&array[12]) { + ++failures; + } +} + +static void lPointer_long(void) +{ + long *lP = (long *)array; + long offset = 3; + + lPtr = lP + offset; + if (lPtr != (void *)&array[12]) { + ++failures; + } +} + +/* These functions test: adding a pointer variable to an offset variable. */ + +static void char_cPointer(void) +{ + char *cP = array; + char offset = 3; + + cPtr = offset + cP; + if (cPtr != (void *)&array[3]) { + ++failures; + } +} + +static void int_cPointer(void) +{ + char *cP = array; + int offset = 3; + + cPtr = offset + cP; + if (cPtr != (void *)&array[3]) { + ++failures; + } +} + +static void long_cPointer(void) +{ + char *cP = array; + long offset = 3; + + cPtr = (offset + cP); + if (cPtr != (void *)&array[3]) { + ++failures; + } +} + +static void char_iPointer(void) +{ + int *iP = (int *)array; + char offset = 3; + + iPtr = offset + iP; + if (iPtr != (void *)&array[6]) { + ++failures; + } +} + +static void int_iPointer(void) +{ + int *iP = (int *)array; + int offset = 3; + + iPtr = offset + iP; + if (iPtr != (void *)&array[6]) { + ++failures; + } +} + +static void long_iPointer(void) +{ + int *iP = (int *)array; + long offset = 3; + + iPtr = (offset + iP); + if (iPtr != (void *)&array[6]) { + ++failures; + } +} + +static void char_lPointer(void) +{ + long *lP = (long *)array; + char offset = 3; + + lPtr = offset + lP; + if (lPtr != (void *)&array[12]) { + ++failures; + } +} + +static void int_lPointer(void) +{ + long *lP = (long *)array; + int offset = 3; + + lPtr = offset + lP; + if (lPtr != (void *)&array[12]) { + ++failures; + } +} + +static void long_lPointer(void) +{ + long *lP = (long *)array; + long offset = 3; + + lPtr = (offset + lP); + if (lPtr != (void *)&array[12]) { + ++failures; + } +} + +int main(void) +{ + cPointer_char(); + cPointer_int(); + cPointer_long(); + + iPointer_char(); + iPointer_int(); + iPointer_long(); + + lPointer_char(); + lPointer_int(); + lPointer_long(); + + char_cPointer(); + int_cPointer(); + long_cPointer(); + + char_iPointer(); + int_iPointer(); + long_iPointer(); + + char_lPointer(); + int_lPointer(); + long_lPointer(); + + if (failures != 0) { + printf("add5: failures: %u\n", failures); + } + return failures; +} From 804f1fded655186e20a6be1f9a1bf82908af9ce6 Mon Sep 17 00:00:00 2001 From: polluks <stefan.haubenthal@gmail.com> Date: Tue, 5 Jan 2016 15:38:05 +0100 Subject: [PATCH 344/351] Fixed typos. --- doc/chrcvt.sgml | 0 doc/smc.sgml | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) mode change 100755 => 100644 doc/chrcvt.sgml diff --git a/doc/chrcvt.sgml b/doc/chrcvt.sgml old mode 100755 new mode 100644 diff --git a/doc/smc.sgml b/doc/smc.sgml index 240c78e7b..4f3e2ace4 100644 --- a/doc/smc.sgml +++ b/doc/smc.sgml @@ -224,7 +224,7 @@ These marcos are determined to get, set and change arguments of instructions: <label id="Change branch"> <tag><tt>SMC_ChangeBranch label, destination (, register)</tt></tag> - Used to modify the destination of a branch instruction. If the adress offset + Used to modify the destination of a branch instruction. If the address offset exceeds the supported range of 8-bit of the 6502, a error will be thrown. Example: @@ -296,7 +296,7 @@ SMC GetK, { LDX #SMC_Value } <tag><tt>SMC_TransferLowByte label, value (, register)</tt></tag> Does the same as '<tt>SMC_TransferValue</tt>' but should be used for - low-bytes of adresses for better readability. + low-bytes of addresses for better readability. Example: <tscreen><verb> @@ -312,7 +312,7 @@ SMC LoadData, { LDA $2000 } <tag><tt>SMC_LoadLowByte label (, register)</tt></tag> Does the same as '<tt>SMC_LoadValue</tt>' but should be used for low-bytes - of adresses for better readability. + of addresses for better readability. Example: <tscreen><verb> @@ -329,7 +329,7 @@ SMC LoadData, { LDA $2000 } <tag><tt>SMC_StoreLowByte label (, register)</tt></tag> Does the same as '<tt>SMC_StoreValue</tt>' but should be used for low-bytes - of adresses for better readability. + of addresses for better readability. Example: <tscreen><verb> @@ -352,7 +352,7 @@ SMC StoreCollisionData, { STY $2200 } <tag><tt>SMC_TransferHighByte label, value (, register)</tt></tag> Loads and stores the given value via the named register to the high-byte - adress portion of an SMC-instruction. + address portion of an SMC-instruction. Example: <tscreen><verb> @@ -370,7 +370,7 @@ PlayOtherSound: <label id="Load high-byte"> <tag><tt>SMC_LoadHighByte label (, register)</tt></tag> - Loads the high-byte part of an SMC-instruction adress to the given register. + Loads the high-byte part of an SMC-instruction address to the given register. Example: <tscreen><verb> @@ -387,7 +387,7 @@ SMC GetVolume { LDA $3200,x } <label id="Store high-byte"> <tag><tt>SMC_StoreHighByte label (, register)</tt></tag> - Stores the high-byte adress part of an SMC-instruction from the given + Stores the high-byte address part of an SMC-instruction from the given register. Example: @@ -407,7 +407,7 @@ SMC GetSoundData, { LDA Level1Base+Sound, y } </verb></tscreen> - <label id="Transfer single adress"> + <label id="Transfer single address"> <tag><tt>SMC_TransferAddressSingle label, address (, register)</tt></tag> Transfers the contents of the given address via the given register to the @@ -428,7 +428,7 @@ SMC GetChar, { LDA SMC_AbsAdr, x } </verb></tscreen> - <label id="Transfer adress"> + <label id="Transfer address"> <tag><tt>SMC_TransferAddress label, address</tt></tag> Loads contents of given address to A/X and stores the result to SMC @@ -559,11 +559,11 @@ allowing reuse of some instructions. 8: SMC FirstIncHighByte, { SMC_OperateOnHighByte inc, StoreAccuFirstSection } ; code will be overwritten to 'beq RestoreCode' (*) 9: ... 10: SMC_TransferOpcode FirstIncHighByte, OPC_BEQ , x ; change code marked above with (*) -11: SMC_TransferValue FirstIncHighByte, #(restoreCode - RestoreCodeBranchBaseAdr-2), x ; set relative adress to 'RestoreCode' +11: SMC_TransferValue FirstIncHighByte, #(restoreCode - RestoreCodeBranchBaseAdr-2), x ; set relative address to 'RestoreCode' 12: ... 13: restoreCode: 14: SMC_TransferOpcode FirstIncHighByte, OPC_INC_abs , x ; restore original code... -15: SMC_TransferValue FirstIncHighByte, #(<(StoreToFirstSection+2)), x ; (second byte of inc contained low-byte of adress) +15: SMC_TransferValue FirstIncHighByte, #(<(StoreToFirstSection+2)), x ; (second byte of inc contained low-byte of address) 16: ... </verb></tscreen> From 231150bc3cd66929261c652554c30be1475f8322 Mon Sep 17 00:00:00 2001 From: polluks <stefan.haubenthal@gmail.com> Date: Tue, 5 Jan 2016 15:45:51 +0100 Subject: [PATCH 345/351] Added sim65 documentation. --- doc/sim65.sgml | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 doc/sim65.sgml diff --git a/doc/sim65.sgml b/doc/sim65.sgml new file mode 100644 index 000000000..f80f17c92 --- /dev/null +++ b/doc/sim65.sgml @@ -0,0 +1,125 @@ +<!doctype linuxdoc system> <!-- -*- text-mode -*- --> + +<article> + +<title>sim65 Users Guide +<author><url url="mailto:polluks@sdf.lonestar.org" name="Stefan A. Haubenthal"> +<date>2016-01-05 + +<abstract> +sim65 is a simulator for 6502 and 65C02 CPUs. It allows to test target +independed code. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + +<sect>Overview<p> + + +sim65 is the only solution as part of the toolchain to execute code. The +binary needs to be compiled with <tt/--target sim6502/ or <tt/--target sim65c02/. + + +<sect>Usage<p> + +The simulator is called as follows: + +<tscreen><verb> + Usage: sim65 [options] file [arguments] + Short options: + -h Help (this text) + -v Increase verbosity + -V Print the simulator version number + -x <num> Exit simulator after <num> cycles + + Long options: + --help Help (this text) + --verbose Increase verbosity + --version Print the simulator version number +</verb></tscreen> + + +<sect1>Command line options in detail<p> + +Here is a description of all the command line options: + +<descrip> + + <tag><tt>-h, --help</tt></tag> + + Print the short option summary shown above. + + + <tag><tt>-v, --verbose</tt></tag> + + Increase the simulator verbosity. + + + <tag><tt>-V, --version</tt></tag> + + Print the version number of the utility. When submitting a bug report, + please include the operating system you're using, and the compiler + version. + + + <tag><tt>-x num</tt></tag> + + Exit simulator after num cycles. +</descrip> + + +<sect>Input and output<p> + +The simulator will read one binary file per invocation and can log some +library calls. + +Example output for the command +<tscreen><verb> +sim65 --verbose --verbose samples/gunzip65 +</verb></tscreen> +<tscreen><verb> +Loaded `samples/gunzip65' at $0200-$151F +PVWrite ($0001, $13C9, $000F) +GZIP file name:PVWrite ($0001, $151F, $0001) + +PVRead ($0000, $FFD7, $0001) +PVOpen ("", $0001) +PVRead ($0003, $1520, $6590) +PVClose ($0003) +PVWrite ($0001, $13D9, $000F) +Not GZIP formatPVWrite ($0001, $151F, $0001) + +PVExit ($01) +</verb></tscreen> + + + +<sect>Copyright<p> + +sim65 (and all cc65 binutils) are (C) Copyright 1998-2000 Ullrich von +Bassewitz. For usage of the binaries and/or sources the following conditions +do apply: + +This software is provided 'as-is', without any expressed or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +<enum> +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> From f69f8add175719c2aad9b03849682205f6c928a1 Mon Sep 17 00:00:00 2001 From: polluks <stefan.haubenthal@gmail.com> Date: Tue, 5 Jan 2016 15:57:18 +0100 Subject: [PATCH 346/351] Updated index. --- doc/index.sgml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/index.sgml b/doc/index.sgml index eb13c9af5..c78426f2a 100644 --- a/doc/index.sgml +++ b/doc/index.sgml @@ -18,6 +18,9 @@ <tag><htmlurl url="cc65.html" name="cc65.html"></tag> Describes the cc65 C compiler. + <tag><htmlurl url="chrcvt.html" name="chrcvt.html"></tag> + Describes the vector font converter. + <tag><htmlurl url="cl65.html" name="cl65.html"></tag> Describes the cl65 compile & link utility. @@ -36,6 +39,9 @@ <tag><htmlurl url="od65.html" name="od65.html"></tag> Describes the od65 object-file analyzer. + <tag><htmlurl url="sim65.html" name="sim65.html"></tag> + Describes the 6502 and 65C02 simulator. + <tag><htmlurl url="sp65.html" name="sp65.html"></tag> Describes the sprite and bitmap utility. @@ -147,7 +153,7 @@ Topics specific to the Commodore Plus/4. <tag><htmlurl url="supervision.html" name="supervision.html"></tag> - Topics specific to the Supervision Console. + Topics specific to the Watara Supervision Console. <tag><htmlurl url="vic20.html" name="vic20.html"></tag> Topics specific to the Commodore VIC20. @@ -156,4 +162,3 @@ </article> - From cb3700ef665b7d59c18cfc82456bb64448cc3def Mon Sep 17 00:00:00 2001 From: polluks <stefan.haubenthal@gmail.com> Date: Tue, 5 Jan 2016 17:45:18 +0100 Subject: [PATCH 347/351] Changed stdout to stderr to separate sim65's output streams. Suggested doc edit. --- doc/index.sgml | 2 +- doc/sim65.sgml | 4 ++-- src/sim65/main.c | 4 ++-- src/sim65/paravirt.c | 12 ++++++------ 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/index.sgml b/doc/index.sgml index c78426f2a..b6ef06ef9 100644 --- a/doc/index.sgml +++ b/doc/index.sgml @@ -89,7 +89,7 @@ An overview over the cc65 runtime and C libraries. <tag><htmlurl url="smc.html" name="smc.html"></tag> - Describes Christian Krügers macro package for writing self modifying + Describes Christian Krüger's macro package for writing self modifying assembler code. <tag><url name="6502 Binary Relocation Format document" diff --git a/doc/sim65.sgml b/doc/sim65.sgml index f80f17c92..24b43831c 100644 --- a/doc/sim65.sgml +++ b/doc/sim65.sgml @@ -73,8 +73,8 @@ Here is a description of all the command line options: <sect>Input and output<p> -The simulator will read one binary file per invocation and can log some -library calls. +The simulator will read one binary file per invocation and can log the +program loading and paravirtualization calls to stderr. Example output for the command <tscreen><verb> diff --git a/src/sim65/main.c b/src/sim65/main.c index 22f6831e4..dab9b0be8 100644 --- a/src/sim65/main.c +++ b/src/sim65/main.c @@ -156,7 +156,7 @@ static void ReadProgramFile (void) /* Close the file */ fclose (F); - Print (stdout, 1, "Loaded `%s' at $0200-$%04X\n", ProgramFile, Addr - 1); + Print (stderr, 1, "Loaded `%s' at $0200-$%04X\n", ProgramFile, Addr - 1); } @@ -238,7 +238,7 @@ int main (int argc, char* argv[]) ExecuteInsn (); if (MaxCycles && (GetCycles () >= MaxCycles)) { Error ("Maximum number of cycles reached."); - exit (-99); /* do not ues EXIT_FAILURE to avoid conflicts with the + exit (-99); /* do not use EXIT_FAILURE to avoid conflicts with the same value being used in a test program */ } } diff --git a/src/sim65/paravirt.c b/src/sim65/paravirt.c index 0deb59a5f..56211b5c1 100644 --- a/src/sim65/paravirt.c +++ b/src/sim65/paravirt.c @@ -128,7 +128,7 @@ static void PVArgs (CPURegs* Regs) unsigned SP = MemReadZPWord (0x00); unsigned Args = SP - (ArgC + 1) * 2; - Print (stdout, 2, "PVArgs ($%04X)\n", ArgV); + Print (stderr, 2, "PVArgs ($%04X)\n", ArgV); MemWriteWord (ArgV, Args); @@ -155,7 +155,7 @@ static void PVArgs (CPURegs* Regs) static void PVExit (CPURegs* Regs) { - Print (stdout, 1, "PVExit ($%02X)\n", Regs->AC); + Print (stderr, 1, "PVExit ($%02X)\n", Regs->AC); exit (Regs->AC); } @@ -177,7 +177,7 @@ static void PVOpen (CPURegs* Regs) } while (Path[I++]); - Print (stdout, 2, "PVOpen (\"%s\", $%04X)\n", Path, Flags); + Print (stderr, 2, "PVOpen (\"%s\", $%04X)\n", Path, Flags); switch (Flags & 0x03) { case 0x01: @@ -219,7 +219,7 @@ static void PVClose (CPURegs* Regs) unsigned FD = GetAX (Regs); - Print (stdout, 2, "PVClose ($%04X)\n", FD); + Print (stderr, 2, "PVClose ($%04X)\n", FD); RetVal = close (FD); @@ -237,7 +237,7 @@ static void PVRead (CPURegs* Regs) unsigned Buf = PopParam (2); unsigned FD = PopParam (2); - Print (stdout, 2, "PVRead ($%04X, $%04X, $%04X)\n", FD, Buf, Count); + Print (stderr, 2, "PVRead ($%04X, $%04X, $%04X)\n", FD, Buf, Count); Data = xmalloc (Count); @@ -264,7 +264,7 @@ static void PVWrite (CPURegs* Regs) unsigned Buf = PopParam (2); unsigned FD = PopParam (2); - Print (stdout, 2, "PVWrite ($%04X, $%04X, $%04X)\n", FD, Buf, Count); + Print (stderr, 2, "PVWrite ($%04X, $%04X, $%04X)\n", FD, Buf, Count); Data = xmalloc (Count); while (I < Count) { From 7a39b85e30e7246f48c627981c02d0d6d977fb2f Mon Sep 17 00:00:00 2001 From: Greg King <gregdk@users.sf.net> Date: Fri, 15 Jan 2016 17:18:09 -0500 Subject: [PATCH 348/351] Fixed how ca65's CONDES-type pseudo-instructions save line numbers (for error messages). --- src/ca65/symentry.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ca65/symentry.c b/src/ca65/symentry.c index f1459dca0..06c537cf6 100644 --- a/src/ca65/symentry.c +++ b/src/ca65/symentry.c @@ -570,8 +570,8 @@ void SymConDes (SymEntry* S, unsigned char AddrSize, unsigned Type, unsigned Pri } } - /* If the symbol was already declared as a condes, check if the new - ** priority value is the same as the old one. + /* If the symbol already was declared as a condes of this type, + ** check if the new priority value is the same as the old one. */ if (S->ConDesPrio[Type] != CD_PRIO_NONE) { if (S->ConDesPrio[Type] != Prio) { @@ -583,10 +583,8 @@ void SymConDes (SymEntry* S, unsigned char AddrSize, unsigned Type, unsigned Pri /* Set the symbol data */ S->Flags |= (SF_EXPORT | SF_REFERENCED); - /* In case we have no line info for the definition, record it now */ - if (CollCount (&S->DefLines) == 0) { - GetFullLineInfo (&S->DefLines); - } + /* Remember the line info for this reference */ + CollAppend (&S->RefLines, GetAsmLineInfo ()); } From 0535075856b0081193c9492fa506cc0846326a33 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Sat, 16 Jan 2016 22:41:14 +0100 Subject: [PATCH 349/351] Fixed #258. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 688b38029..1507f4de0 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ including - CBM 510 (aka P500) - the 600/700 family - newer PET machines (not 2001). -- the Apple ][+ and successors. +- the Apple ]\[+ and successors. - the Atari 8 bit machines. - the Atari 5200 console. - GEOS for the C64, C128 and Apple //e. From 5c3e09685fb79d5e7f2df72f3f5e0d8623da6fbe Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 21 Jan 2016 20:49:21 +0100 Subject: [PATCH 350/351] Added Watara. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1507f4de0..5e907f27b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ including - GEOS for the C64, C128 and Apple //e. - the NEC PC-Engine (aka TurboGrafx-16). - the Nintendo Entertainment System (NES) console. -- the Supervision console. +- the Watara Supervision console. - the Oric Atmos. - the Lynx console. - the Ohio Scientific Challenger 1P From f7cdfbf5cba463c4db75cb8e3c4aebd75355df26 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt <ol.sc@web.de> Date: Thu, 21 Jan 2016 20:51:17 +0100 Subject: [PATCH 351/351] Minor fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5e907f27b..a0455cbe6 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ including - the Watara Supervision console. - the Oric Atmos. - the Lynx console. -- the Ohio Scientific Challenger 1P +- the Ohio Scientific Challenger 1P. The libraries are fairly portable, so creating a version for other 6502s shouldn't be too much work.