From 2fcd8b934ac4cbc577a02a83cc4c83f9f90d7561 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 24 Oct 2020 13:55:10 +0200 Subject: [PATCH 001/122] Made HGR segment obligatory. Requiring the HGR segment makes the configs a little less flexible, but for the intended use case the HGR segment actually is necessary. And as we learned now, making the HGR segment obligatory helps users to not shoot themselves in the foot. --- cfg/apple2-hgr.cfg | 4 ++-- cfg/apple2enh-hgr.cfg | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cfg/apple2-hgr.cfg b/cfg/apple2-hgr.cfg index 3ccf7b6f3..cfe577e00 100644 --- a/cfg/apple2-hgr.cfg +++ b/cfg/apple2-hgr.cfg @@ -23,8 +23,8 @@ SEGMENTS { EXEHDR: load = HEADER, type = ro, optional = yes; STARTUP: load = MAIN, type = ro; LOWCODE: load = MAIN, type = ro, optional = yes; - HGR: load = MAIN, type = rw, optional = yes, start = $2000; - CODE: load = MAIN, type = ro start = $4000; + HGR: load = MAIN, type = rw, start = $2000; + CODE: load = MAIN, type = ro start = $4000; RODATA: load = MAIN, type = ro; DATA: load = MAIN, type = rw; INIT: load = MAIN, type = rw; diff --git a/cfg/apple2enh-hgr.cfg b/cfg/apple2enh-hgr.cfg index 3ccf7b6f3..cfe577e00 100644 --- a/cfg/apple2enh-hgr.cfg +++ b/cfg/apple2enh-hgr.cfg @@ -23,8 +23,8 @@ SEGMENTS { EXEHDR: load = HEADER, type = ro, optional = yes; STARTUP: load = MAIN, type = ro; LOWCODE: load = MAIN, type = ro, optional = yes; - HGR: load = MAIN, type = rw, optional = yes, start = $2000; - CODE: load = MAIN, type = ro start = $4000; + HGR: load = MAIN, type = rw, start = $2000; + CODE: load = MAIN, type = ro start = $4000; RODATA: load = MAIN, type = ro; DATA: load = MAIN, type = rw; INIT: load = MAIN, type = rw; From 07cc6a3d208b28ba6bcb42f9a02b8cb765c61bd8 Mon Sep 17 00:00:00 2001 From: acqn Date: Fri, 18 Sep 2020 20:23:02 +0800 Subject: [PATCH 002/122] Made optimization steps aware of long branches better. --- src/cc65/coptcmp.c | 4 +++- src/cc65/coptptrload.c | 2 +- src/cc65/coptshift.c | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cc65/coptcmp.c b/src/cc65/coptcmp.c index a4a8c6a9b..fda23ae0a 100644 --- a/src/cc65/coptcmp.c +++ b/src/cc65/coptcmp.c @@ -944,7 +944,9 @@ unsigned OptCmp9 (CodeSeg* S) if (L[0]->OPC == OP65_SBC && CS_GetEntries (S, L+1, I+1, 4) && (L[1]->OPC == OP65_BVC || - L[1]->OPC == OP65_BVS) && + L[1]->OPC == OP65_BVS || + L[1]->OPC == OP65_JVC || + L[1]->OPC == OP65_JVS) && L[1]->JumpTo != 0 && L[1]->JumpTo->Owner == L[3] && L[2]->OPC == OP65_EOR && diff --git a/src/cc65/coptptrload.c b/src/cc65/coptptrload.c index 0534a1fa2..046e65d79 100644 --- a/src/cc65/coptptrload.c +++ b/src/cc65/coptptrload.c @@ -988,7 +988,7 @@ unsigned OptPtrLoad12 (CodeSeg* S) L[4]->OPC == OP65_CLC && L[5]->OPC == OP65_ADC && CE_IsKnownImm (L[5], 1) && - L[6]->OPC == OP65_BCC && + (L[6]->OPC == OP65_BCC || L[6]->OPC == OP65_JCC) && L[6]->JumpTo != 0 && L[6]->JumpTo->Owner == L[8] && L[7]->OPC == OP65_INX && diff --git a/src/cc65/coptshift.c b/src/cc65/coptshift.c index 92210ebb5..aef3f64bc 100644 --- a/src/cc65/coptshift.c +++ b/src/cc65/coptshift.c @@ -341,7 +341,10 @@ unsigned OptShift2 (CodeSeg* S) L[0] = CS_GetEntry (S, I); /* Check for the sequence */ - if ((L[0]->OPC == OP65_BPL || L[0]->OPC == OP65_BCC) && + if ((L[0]->OPC == OP65_BPL || + L[0]->OPC == OP65_BCC || + L[0]->OPC == OP65_JPL || + L[0]->OPC == OP65_JCC) && L[0]->JumpTo != 0 && CS_GetEntries (S, L+1, I+1, 3) && L[1]->OPC == OP65_DEX && From f723147f04f19ddc7e39bad9211a6f26082ffbc5 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 25 Oct 2020 14:06:44 +0100 Subject: [PATCH 003/122] Streamlined clock rate handling. * Docs say that CLK_TCK is an obsolete alias of CLOCKS_PER_SEC so there's no point in individual definitions. * All targets determining the clock rate at runtime can use a common handling. --- include/time.h | 46 ++++++++++++---------------------------- libsrc/atari/clock.s | 8 ++++--- libsrc/atari5200/clock.s | 1 - libsrc/lynx/clock.s | 14 +++++------- 4 files changed, 24 insertions(+), 45 deletions(-) diff --git a/include/time.h b/include/time.h index 4ee658da9..49d7e6870 100644 --- a/include/time.h +++ b/include/time.h @@ -83,46 +83,31 @@ extern struct _timezone { -#if defined(__ATARI__) -/* The clock depends on the video standard, so read it at runtime */ -unsigned _clocks_per_sec (void); -# define CLK_TCK _clocks_per_sec() -# define CLOCKS_PER_SEC _clocks_per_sec() -#elif defined(__ATARI5200__) -# define CLK_TCK 60 /* POSIX */ -# define CLOCKS_PER_SEC 60 /* ANSI */ +#if defined(__ATARI5200__) +# define CLOCKS_PER_SEC 60 #elif defined(__ATMOS__) -# define CLK_TCK 100 /* POSIX */ -# define CLOCKS_PER_SEC 100 /* ANSI */ +# define CLOCKS_PER_SEC 100 #elif defined(__CBM__) # if defined(__CBM510__) || defined(__CBM610__) /* The 510/610 gets its clock from the AC current */ -# define CLK_TCK 50 /* POSIX */ -# define CLOCKS_PER_SEC 50 /* ANSI */ +# define CLOCKS_PER_SEC 50 # else -# define CLK_TCK 60 /* POSIX */ -# define CLOCKS_PER_SEC 60 /* ANSI */ +# define CLOCKS_PER_SEC 60 # endif #elif defined(__NES__) -# define CLK_TCK 50 /* POSIX */ -# define CLOCKS_PER_SEC 50 /* ANSI */ +# define CLOCKS_PER_SEC 50 #elif defined(__PCE__) -# define CLK_TCK 60 /* POSIX */ -# define CLOCKS_PER_SEC 60 /* ANSI */ +# define CLOCKS_PER_SEC 60 #elif defined(__GAMATE__) -# define CLK_TCK 135 /* POSIX */ /* FIXME */ -# define CLOCKS_PER_SEC 135 /* ANSI */ /* FIXME */ +# define CLOCKS_PER_SEC 135 /* FIXME */ #elif defined(__GEOS__) -# define CLK_TCK 1 /* POSIX */ -# define CLOCKS_PER_SEC 1 /* ANSI */ -#elif defined(__LYNX__) -/* The clock-rate depends on the video scan-rate; -** so, read it at run-time. -*/ -extern clock_t _clk_tck (void); -# define CLK_TCK _clk_tck() -# define CLOCKS_PER_SEC _clk_tck() +# define CLOCKS_PER_SEC 1 +#else +/* Read the clock rate at runtime */ +clock_t _clocks_per_sec (void); +# define CLOCKS_PER_SEC _clocks_per_sec() #endif +#define CLK_TCK CLOCKS_PER_SEC #define CLOCK_REALTIME 0 @@ -149,6 +134,3 @@ int __fastcall__ clock_settime (clockid_t clock_id, const struct timespec *tp); /* End of time.h */ #endif - - - diff --git a/libsrc/atari/clock.s b/libsrc/atari/clock.s index e04416c18..853870520 100644 --- a/libsrc/atari/clock.s +++ b/libsrc/atari/clock.s @@ -3,7 +3,7 @@ ; originally by Ullrich von Bassewitz and Sidney Cadot ; ; clock_t clock (void); -; unsigned _clocks_per_sec (void); +; clock_t _clocks_per_sec (void); ; .export _clock, __clocks_per_sec @@ -30,8 +30,10 @@ .proc __clocks_per_sec - ldx #$00 ; Clear high byte of return value - lda PAL ; use hw register, PALNTS is only supported on XL/XE ROM + ldx #$00 ; Clear byte 1 of return value + stx sreg ; Clear byte 2 of return value + stx sreg+1 ; Clear byte 3 of return value + lda PAL ; Use hw register, PALNTS is only supported on XL/XE ROM and #$0e bne @NTSC lda #50 diff --git a/libsrc/atari5200/clock.s b/libsrc/atari5200/clock.s index f2ef85b0b..fff766093 100644 --- a/libsrc/atari5200/clock.s +++ b/libsrc/atari5200/clock.s @@ -2,7 +2,6 @@ ; from Atari computer version by Christian Groessler, 2014 ; ; clock_t clock (void); -; unsigned _clocks_per_sec (void); ; .export _clock diff --git a/libsrc/lynx/clock.s b/libsrc/lynx/clock.s index dbccb32cb..e29799df6 100644 --- a/libsrc/lynx/clock.s +++ b/libsrc/lynx/clock.s @@ -2,18 +2,14 @@ ; 2003-04-13, Ullrich von Bassewitz ; 2012-02-06, Greg King ; -; #include +; clock_t clock (void); +; clock_t _clocks_per_sec (void); ; -; typedef unsigned long int clock_t; -; clock_t _clk_tck(void); -; #define CLOCKS_PER_SEC _clk_tck() -; clock_t clock(void); -; -; clk_tck()'s test-values are based on the numbers in "set_tv.s". +; clocks_per_sec()'s test-values are based on the numbers in "set_tv.s". ; If you change the numbers there, then change them here, too. ; - .export _clock, __clk_tck, clock_count + .export _clock, __clocks_per_sec, clock_count .interruptor update_clock, 2 ; (low priority) .constructor init_clock @@ -42,7 +38,7 @@ ;----------------------------------------------------------------------------- ; Return the number of clock ticks in one second. ; -__clk_tck: +__clocks_per_sec: ldx #$00 ; >50, >60, >75 ldy PBKUP lda #<75 From 79cf1e13a7afe1f2bf9e3a0010e9caca776cf347 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sun, 25 Oct 2020 21:33:08 +0100 Subject: [PATCH 004/122] Adjusted to recent change in time.h --- samples/mandelbrot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/mandelbrot.c b/samples/mandelbrot.c index 595bcfbbb..519f3d823 100644 --- a/samples/mandelbrot.c +++ b/samples/mandelbrot.c @@ -31,6 +31,7 @@ /* Workaround missing clock stuff */ #ifdef __APPLE2__ # define clock() 0 +# undef CLK_TCK # define CLK_TCK 1 #endif From 353721067470fa1671a0413944dd38b744e9f0bb Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 27 Oct 2020 22:25:58 +0100 Subject: [PATCH 005/122] add waitvsync() for atari and atari5200 --- doc/atari.sgml | 1 + doc/atari5200.sgml | 2 +- include/atari.h | 1 + include/atari5200.h | 3 +++ libsrc/atari/waitvsync.s | 15 +++++++++++++++ libsrc/atari5200/waitvsync.s | 15 +++++++++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 libsrc/atari/waitvsync.s create mode 100644 libsrc/atari5200/waitvsync.s diff --git a/doc/atari.sgml b/doc/atari.sgml index eecd1b803..7fc929f42 100644 --- a/doc/atari.sgml +++ b/doc/atari.sgml @@ -332,6 +332,7 @@ See the for declaration and u _scroll _setcolor _setcolor_low +waitvsync diff --git a/doc/atari5200.sgml b/doc/atari5200.sgml index 00d3dfbd2..032b0ef6c 100644 --- a/doc/atari5200.sgml +++ b/doc/atari5200.sgml @@ -77,7 +77,7 @@ Programs containing Atari 5200 specific code may use the Atari 5200 specific functions

-TBD. +waitvsync diff --git a/include/atari.h b/include/atari.h index 1a00a4c67..b2fca0b0e 100644 --- a/include/atari.h +++ b/include/atari.h @@ -227,6 +227,7 @@ extern unsigned char __fastcall__ _getcolor (unsigned char color_reg); /* Other screen functions */ /*****************************************************************************/ +extern void waitvsync (void); /* Wait for start of next frame */ extern int __fastcall__ _graphics (unsigned char mode); /* mode value same as in BASIC */ extern void __fastcall__ _scroll (signed char numlines); /* numlines > 0 scrolls up */ diff --git a/include/atari5200.h b/include/atari5200.h index d6c2561b2..9662fe98e 100644 --- a/include/atari5200.h +++ b/include/atari5200.h @@ -89,5 +89,8 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ */ #define _bordercolor(color) 0 +extern void waitvsync (void); +/* Wait for start of next frame */ + /* End of atari5200.h */ #endif diff --git a/libsrc/atari/waitvsync.s b/libsrc/atari/waitvsync.s new file mode 100644 index 000000000..a19b2375d --- /dev/null +++ b/libsrc/atari/waitvsync.s @@ -0,0 +1,15 @@ +; +; Written by Christian Groessler +; +; void waitvsync (void); +; + + .include "atari.inc" + .export _waitvsync + +.proc _waitvsync + lda RTCLOK+2 +@lp: cmp RTCLOK+2 + beq @lp + rts +.endproc diff --git a/libsrc/atari5200/waitvsync.s b/libsrc/atari5200/waitvsync.s new file mode 100644 index 000000000..9a67c6429 --- /dev/null +++ b/libsrc/atari5200/waitvsync.s @@ -0,0 +1,15 @@ +; +; Written by Christian Groessler +; +; void waitvsync (void); +; + + .include "atari5200.inc" + .export _waitvsync + +.proc _waitvsync + lda RTCLOK+1 +@lp: cmp RTCLOK+1 + beq @lp + rts +.endproc From 262631039dca1c7440457586d3a64d10ae9248db Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 28 Oct 2020 17:37:50 +0100 Subject: [PATCH 006/122] atari.h, atari5200.h: style fixes --- include/atari.h | 2 +- include/atari5200.h | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/atari.h b/include/atari.h index b2fca0b0e..f5916a284 100644 --- a/include/atari.h +++ b/include/atari.h @@ -227,7 +227,7 @@ extern unsigned char __fastcall__ _getcolor (unsigned char color_reg); /* Other screen functions */ /*****************************************************************************/ -extern void waitvsync (void); /* Wait for start of next frame */ +extern void waitvsync (void); /* wait for start of next frame */ extern int __fastcall__ _graphics (unsigned char mode); /* mode value same as in BASIC */ extern void __fastcall__ _scroll (signed char numlines); /* numlines > 0 scrolls up */ diff --git a/include/atari5200.h b/include/atari5200.h index 9662fe98e..a18360c61 100644 --- a/include/atari5200.h +++ b/include/atari5200.h @@ -35,7 +35,7 @@ -/* Check for errors */ +/* check for errors */ #if !defined(__ATARI5200__) # error This module may only be used when compiling for the Atari 5200! #endif @@ -46,14 +46,14 @@ /* the addresses of the static drivers */ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ -/* Masks for joy_read */ +/* masks for joy_read */ #define JOY_UP_MASK 0x01 #define JOY_DOWN_MASK 0x02 #define JOY_LEFT_MASK 0x04 #define JOY_RIGHT_MASK 0x08 #define JOY_BTN_1_MASK 0x10 -/* Character codes */ +/* character codes */ #define CH_ULCORNER 0x0B /* '+' sign */ #define CH_URCORNER 0x0B #define CH_LLCORNER 0x0B @@ -65,7 +65,7 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ #define AT_NTSC 0 #define AT_PAL 1 -/* Define hardware */ +/* define hardware */ #include <_gtia.h> #define GTIA_READ (*(struct __gtia_read*)0xC000) #define GTIA_WRITE (*(struct __gtia_write*)0xC000) @@ -89,8 +89,8 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ */ #define _bordercolor(color) 0 +/* wait for start of next frame */ extern void waitvsync (void); -/* Wait for start of next frame */ -/* End of atari5200.h */ +/* end of atari5200.h */ #endif From a686988d0ebb0b42d965ed006b9d3a78b78d947c Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Wed, 28 Oct 2020 09:35:49 +0100 Subject: [PATCH 007/122] Add test cases for integral promotion of chars Both signed and unsigned chars are promoted to int by C's evaluation rules. It is more efficient to use unsigned operations when possible, however. These tests will help test the correctness of optimizations doing that. See #1308. --- test/val/char-promote.c | 127 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 test/val/char-promote.c diff --git a/test/val/char-promote.c b/test/val/char-promote.c new file mode 100644 index 000000000..1d6360d45 --- /dev/null +++ b/test/val/char-promote.c @@ -0,0 +1,127 @@ +/* + Copyright 2020 The cc65 Authors + + 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. + + 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. +*/ + +/* + Tests of promotions of character types. +*/ + +#include + +typedef unsigned char u8; + +static unsigned char failures = 0; + +void test_sub (void) +{ + const u8 one = 1, two = 2; + + /* For any unsigned type other than unsigned char, (T) 1 - (T) 2 > 0. */ + if (1U - 2U < 0) { + fprintf (stderr, "Expected 1U - 2U > 0\n"); + failures++; + } + + /* The unsigned chars get promoted to int, so this is negative. */ + if (one - two > 0) { + fprintf (stderr, "Expected one - two < 0\n"); + failures++; + } + + /* Test the constant expression code paths. */ + if ((u8) 1 - (u8) 2 > 0) { + fprintf (stderr, "Expected (u8) 1 - (u8) 2 < 0\n"); + failures++; + } +} + +void test_mul (void) +{ + const u8 two_fifty_five = 255; + + if (255U * 255U != 65025U) { + fprintf (stderr, "Expected 255U * 255U == 65025U\n"); + failures++; + } +#if 0 + /* Disabled pending fix of #1310. */ + if (255 * 255 != -511) { + fprintf (stderr, "Expected 255 * 255 == -511, got: %d\n", 255 * 255); + failures++; + } +#endif + + /* The unsigned chars get promoted to int, so this is -511. + ** We should also be able to observe that the generated code uses mul, not umul. + */ + if (two_fifty_five * two_fifty_five != -511) { + fprintf (stderr, "Expected two_fifty_five * two_fifty_five == -511\n"); + failures++; + } +#if 0 + /* Disabled pending fix of #1310. */ + if ((u8) 255 * (u8) 255 != -511) { + fprintf (stderr, "Expected (u8) 255 * (u8) 255 == -511, got: %d\n", + (u8) 255 * (u8) 255); + failures++; + } +#endif +} + +void test_div (void) +{ + const u8 seventeen = 17; + const u8 three = 3; + + /* We should also be able to observe that the generated code uses div, not udiv. */ + if (seventeen / three != 5) { + fprintf (stderr, "Expected seventeen / three == 5, got: %d\n", seventeen / three); + failures++; + } + if ((u8) 17 / (u8) 3 != 5) { + fprintf (stderr, "Expected (u8) 17 / (u8) 3 == 5, got: %d\n", (u8) 17 / (u8) 3); + failures++; + } +} + +void test_shr (void) +{ + const unsigned int forty_two = 42; + const unsigned int two = 2; + + /* We should also be able to observe that the generated code uses asr, not shr. */ + if (forty_two >> two != 10) { + fprintf (stderr, "Expected forty_two / two == 10, got: %d\n", forty_two >> two); + failures++; + } + if ((u8) 42 >> (u8) 2 != 10) { + fprintf (stderr, "Expected (u8) 42 >> (u8) 2 == 10, got: %d\n", (u8) 42 >> (u8) 3); + failures++; + } +} + +int main (void) +{ + test_sub (); + test_mul (); + test_div (); + test_shr (); + printf ("failures: %u\n", failures); + return failures; +} From 944ebbc23cf6d74ffe1f5f1d5a9ca001066d7d23 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Thu, 29 Oct 2020 16:19:38 +0100 Subject: [PATCH 008/122] atarixl configs: make size of CHARGEN configurable If text mode is not used, its space can be reclaimed by setting __CHARGENSIZE__ to 0. Following a suggestion from issue #1314. --- cfg/atarixl-largehimem.cfg | 33 +++++++++++++++++---------------- cfg/atarixl-overlay.cfg | 37 +++++++++++++++++++------------------ cfg/atarixl-xex.cfg | 21 +++++++++++---------- cfg/atarixl.cfg | 29 +++++++++++++++-------------- 4 files changed, 62 insertions(+), 58 deletions(-) diff --git a/cfg/atarixl-largehimem.cfg b/cfg/atarixl-largehimem.cfg index 56d2af15b..5e60f32bd 100644 --- a/cfg/atarixl-largehimem.cfg +++ b/cfg/atarixl-largehimem.cfg @@ -8,39 +8,40 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __AUTOSTART__: type = import; # force inclusion of autostart "trailer" - __STACKSIZE__: type = weak, value = $0800; # 2k stack + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __CHARGENSIZE__: type = weak, value = $0400; __STARTADDRESS__: type = export, value = %S; } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; + ZP: file = "", define = yes, start = $0082, size = $007E; # just $FFFF - HEADER: file = %O, start = $0000, size = $0002; + HEADER: file = %O, start = $0000, size = $0002; # "system check" load chunk - SYSCHKHDR: file = %O, start = $0000, size = $0004; - SYSCHKCHNK: file = %O, start = $2E00, size = $0300; - SYSCHKTRL: file = %O, start = $0000, size = $0006; + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; # "shadow RAM preparation" load chunk - SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned - SRPREPTRL: file = %O, start = $0000, size = $0006; + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk - MAINHDR: file = %O, start = $0000, size = $0004; - MAIN: file = %O, define = yes, start = %S + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __LOWBSS_SIZE__; + MAINHDR: file = %O, start = $0000, size = $0004; + MAIN: file = %O, define = yes, start = %S + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __LOWBSS_SIZE__; # defines entry point into program - TRAILER: file = %O, start = $0000, size = $0006; + TRAILER: file = %O, start = $0000, size = $0006; # address of relocated character generator - CHARGEN: file = "", define = yes, start = $D800, size = $0400; + CHARGEN: file = "", define = yes, start = $D800, size = __CHARGENSIZE__; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $DC00, size = $FFFA - $DC00; + HIDDEN_RAM: file = "", define = yes, start = $D800 + __CHARGENSIZE__, size = $FFFA - $D800 - __CHARGENSIZE__; } SEGMENTS { ZEROPAGE: load = ZP, type = zp; diff --git a/cfg/atarixl-overlay.cfg b/cfg/atarixl-overlay.cfg index 923436497..2bb4105cd 100644 --- a/cfg/atarixl-overlay.cfg +++ b/cfg/atarixl-overlay.cfg @@ -3,44 +3,45 @@ FEATURES { } SYMBOLS { __EXEHDR__: type = import; - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __AUTOSTART__: type = import; # force inclusion of autostart "trailer" - __STACKSIZE__: type = weak, value = $0800; # 2k stack - __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __AUTOSTART__: type = import; # force inclusion of autostart "trailer" + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __CHARGENSIZE__: type = weak, value = $0400; + __OVERLAYSIZE__: type = weak, value = $1000; # 4k overlay __STARTADDRESS__: type = export, value = %S; } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; + ZP: file = "", define = yes, start = $0082, size = $007E; # just $FFFF - HEADER: file = %O, start = $0000, size = $0002; + HEADER: file = %O, start = $0000, size = $0002; # "system check" load chunk - SYSCHKHDR: file = %O, start = $0000, size = $0004; - SYSCHKCHNK: file = %O, start = $2E00, size = $0300; - SYSCHKTRL: file = %O, start = $0000, size = $0006; + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; # "shadow RAM preparation" load chunk - SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREPCHNK: file = %O, define = yes, start = %S + __OVERLAYSIZE__, size = $7C20 - %S - __OVERLAYSIZE__ - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned - SRPREPTRL: file = %O, start = $0000, size = $0006; + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREPCHNK: file = %O, define = yes, start = %S + __OVERLAYSIZE__, size = $7C20 - %S - __OVERLAYSIZE__ - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk - MAINHDR: file = %O, start = $0000, size = $0004; + MAINHDR: file = %O, start = $0000, size = $0004; MAIN: file = %O, define = yes, start = %S + __OVERLAYSIZE__ + - __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __OVERLAYSIZE__ - __LOWBSS_SIZE__; + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __OVERLAYSIZE__ - __LOWBSS_SIZE__; # defines entry point into program - TRAILER: file = %O, start = $0000, size = $0006; + TRAILER: file = %O, start = $0000, size = $0006; # memory beneath the ROM preceeding the character generator - HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; + HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; # address of relocated character generator (same addess as ROM version) - CHARGEN: file = "", define = yes, start = $E000, size = $0400; + CHARGEN: file = "", define = yes, start = $E000, size = __CHARGENSIZE__; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFFA - $E400; + HIDDEN_RAM: file = "", define = yes, start = $E000 + __CHARGENSIZE__, size = $FFFA - $E000 - __CHARGENSIZE__; # overlays OVL1: file = "%O.1", start = %S, size = __OVERLAYSIZE__; diff --git a/cfg/atarixl-xex.cfg b/cfg/atarixl-xex.cfg index 0b1fe9ca1..6b6601c59 100644 --- a/cfg/atarixl-xex.cfg +++ b/cfg/atarixl-xex.cfg @@ -4,35 +4,36 @@ FEATURES { STARTADDRESS: default = $2400; } SYMBOLS { - __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk - __STACKSIZE__: type = weak, value = $0800; # 2k stack + __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk + __STACKSIZE__: type = weak, value = $0800; # 2k stack __STARTADDRESS__: type = export, value = %S; + __CHARGENSIZE__: type = weak, value = $0400; __SYSCHKHDR__: type = export, value = 0; # Disable system check header __SYSCHKTRL__: type = export, value = 0; # Disable system check trailer } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; + ZP: file = "", define = yes, start = $0082, size = $007E; # "system check" load chunk - SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; # "shadow RAM preparation" load chunk - SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned # "main program" load chunk - MAIN: file = %O, define = yes, start = %S + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __LOWBSS_SIZE__; + MAIN: file = %O, define = yes, start = %S + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __LOWBSS_SIZE__; # memory beneath the ROM preceeding the character generator - HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; + HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; # address of relocated character generator (same addess as ROM version) - CHARGEN: file = "", define = yes, start = $E000, size = $0400; + CHARGEN: file = "", define = yes, start = $E000, size = __CHARGENSIZE__; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFFA - $E400; + HIDDEN_RAM: file = "", define = yes, start = $E000 + __CHARGENSIZE__, size = $FFFA - $E000 - __CHARGENSIZE__; # UNUSED - hide - UNUSED: file = "", start = $0, size = $10; + UNUSED: file = "", start = $0, size = $10; } FILES { %O: format = atari; diff --git a/cfg/atarixl.cfg b/cfg/atarixl.cfg index 197daace6..d4e466ae1 100644 --- a/cfg/atarixl.cfg +++ b/cfg/atarixl.cfg @@ -6,39 +6,40 @@ SYMBOLS { __SYSTEM_CHECK__: type = import; # force inclusion of "system check" load chunk __AUTOSTART__: type = import; # force inclusion of autostart "trailer" __STACKSIZE__: type = weak, value = $0800; # 2k stack + __CHARGENSIZE__: type = weak, value = $0400; __STARTADDRESS__: type = export, value = %S; } MEMORY { - ZP: file = "", define = yes, start = $0082, size = $007E; + ZP: file = "", define = yes, start = $0082, size = $007E; # just $FFFF - HEADER: file = %O, start = $0000, size = $0002; + HEADER: file = %O, start = $0000, size = $0002; # "system check" load chunk - SYSCHKHDR: file = %O, start = $0000, size = $0004; - SYSCHKCHNK: file = %O, start = $2E00, size = $0300; - SYSCHKTRL: file = %O, start = $0000, size = $0006; + SYSCHKHDR: file = %O, start = $0000, size = $0004; + SYSCHKCHNK: file = %O, start = $2E00, size = $0300; + SYSCHKTRL: file = %O, start = $0000, size = $0006; # "shadow RAM preparation" load chunk - SRPREPHDR: file = %O, start = $0000, size = $0004; - SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned - SRPREPTRL: file = %O, start = $0000, size = $0006; + SRPREPHDR: file = %O, start = $0000, size = $0004; + SRPREPCHNK: file = %O, define = yes, start = %S, size = $7C20 - %S - $07FF; # $07FF: space for temp. chargen buffer, 1K aligned + SRPREPTRL: file = %O, start = $0000, size = $0006; # "main program" load chunk - MAINHDR: file = %O, start = $0000, size = $0004; - MAIN: file = %O, define = yes, start = %S + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __LOWBSS_SIZE__; + MAINHDR: file = %O, start = $0000, size = $0004; + MAIN: file = %O, define = yes, start = %S + __LOWBSS_SIZE__, size = $D000 - __STACKSIZE__ - %S - __LOWBSS_SIZE__; # defines entry point into program - TRAILER: file = %O, start = $0000, size = $0006; + TRAILER: file = %O, start = $0000, size = $0006; # memory beneath the ROM preceeding the character generator - HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; + HIDDEN_RAM2: file = "", define = yes, start = $D800, size = $0800; # address of relocated character generator (same addess as ROM version) - CHARGEN: file = "", define = yes, start = $E000, size = $0400; + CHARGEN: file = "", define = yes, start = $E000, size = __CHARGENSIZE__; # memory beneath the ROM - HIDDEN_RAM: file = "", define = yes, start = $E400, size = $FFFA - $E400; + HIDDEN_RAM: file = "", define = yes, start = $E000 + __CHARGENSIZE__, size = $FFFA - $E000 - __CHARGENSIZE__; } SEGMENTS { ZEROPAGE: load = ZP, type = zp; From d8e6fa61bbcbb86c7bcf287a988f42246f22376f Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Thu, 29 Oct 2020 17:42:36 +0100 Subject: [PATCH 009/122] Return NULL on error (or end of directory). --- libsrc/geos-common/file/get1stdirentry.s | 8 ++++++-- libsrc/geos-common/file/getnxtdirentry.s | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libsrc/geos-common/file/get1stdirentry.s b/libsrc/geos-common/file/get1stdirentry.s index 3b99554eb..381a35c6d 100644 --- a/libsrc/geos-common/file/get1stdirentry.s +++ b/libsrc/geos-common/file/get1stdirentry.s @@ -5,7 +5,7 @@ ; struct filehandle* Get1stDirEntry (void); - .import __oserror + .import __oserror, return0 .export _Get1stDirEntry .include "diskdrv.inc" @@ -14,6 +14,10 @@ _Get1stDirEntry: jsr Get1stDirEntry stx __oserror - lda r5L + txa + beq L0 ; error? + jmp return0 ; return NULL + +L0: lda r5L ldx r5H rts diff --git a/libsrc/geos-common/file/getnxtdirentry.s b/libsrc/geos-common/file/getnxtdirentry.s index 912f48ca4..16a31edcf 100644 --- a/libsrc/geos-common/file/getnxtdirentry.s +++ b/libsrc/geos-common/file/getnxtdirentry.s @@ -5,7 +5,7 @@ ; struct filehandle* GetNxtDirEntry (void); - .import __oserror + .import __oserror, return0 .export _GetNxtDirEntry .include "diskdrv.inc" @@ -14,6 +14,12 @@ _GetNxtDirEntry: jsr GetNxtDirEntry stx __oserror - lda r5L + txa + beq L0 ; error? + tya + beq L0 ; end of dir? + jmp return0 ; return NULL + +L0: lda r5L ldx r5H rts From aad17a6f057dc57424c010c0d832e1f49592f044 Mon Sep 17 00:00:00 2001 From: Greg King Date: Thu, 29 Oct 2020 17:54:56 -0400 Subject: [PATCH 010/122] Made two GEOS directory functions return NULL if they can't give a valid entry. --- doc/geos.sgml | 19 ++++++++++--------- libsrc/geos-common/file/get1stdirentry.s | 12 ++++++------ libsrc/geos-common/file/getnxtdirentry.s | 14 +++++++------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/doc/geos.sgml b/doc/geos.sgml index a10ade5d5..11ff9c534 100644 --- a/doc/geos.sgml +++ b/doc/geos.sgml @@ -858,20 +858,21 @@ The functions described here are common for SEQ and VLIR structures.

-These two functions are best suited for scanning the whole directory for particular files. Note that -the returned filehandles describe all file slots in the directory - even those with deleted files. -The return value can be obtained by casting both sides to geos/gdisk.h). The current +directory track and sector numbers are in FindFile

-This function scans the whole directory for the given filename. It returns either 0 (success) or 5 -(FILE_NOT_FOUND, defined in geos/gdisk.h), or any other fatal disk read error. After a successful +FindFTypes

diff --git a/libsrc/geos-common/file/get1stdirentry.s b/libsrc/geos-common/file/get1stdirentry.s index 381a35c6d..f0ad59388 100644 --- a/libsrc/geos-common/file/get1stdirentry.s +++ b/libsrc/geos-common/file/get1stdirentry.s @@ -1,7 +1,7 @@ ; -; Maciej 'YTM/Alliance' Witkowiak +; 1999-10-26, Maciej 'YTM/Alliance' Witkowiak +; 2020-10-29, Greg King ; -; 26.10.99 ; struct filehandle* Get1stDirEntry (void); @@ -15,9 +15,9 @@ _Get1stDirEntry: jsr Get1stDirEntry stx __oserror txa - beq L0 ; error? - jmp return0 ; return NULL - -L0: lda r5L + bne L1 ; jump if disk error + lda r5L ldx r5H rts + +L1: jmp return0 ; return NULL if not valid entry diff --git a/libsrc/geos-common/file/getnxtdirentry.s b/libsrc/geos-common/file/getnxtdirentry.s index 16a31edcf..e8ccbf3a2 100644 --- a/libsrc/geos-common/file/getnxtdirentry.s +++ b/libsrc/geos-common/file/getnxtdirentry.s @@ -1,7 +1,7 @@ ; -; Maciej 'YTM/Alliance' Witkowiak +; 1999-10-26, Maciej 'YTM/Alliance' Witkowiak +; 2020-10-29, Greg King ; -; 26.10.99 ; struct filehandle* GetNxtDirEntry (void); @@ -15,11 +15,11 @@ _GetNxtDirEntry: jsr GetNxtDirEntry stx __oserror txa - beq L0 ; error? + bne L1 ; jump if disk error tya - beq L0 ; end of dir? - jmp return0 ; return NULL - -L0: lda r5L + bne L1 ; jump when no more entries + lda r5L ldx r5H rts + +L1: jmp return0 ; return NULL if not valid entry From 39c0abed549708a127a0211d94aab204dde681c2 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 30 Oct 2020 15:01:47 +0100 Subject: [PATCH 011/122] atarixl: fix compilation problem when CHARGEN_RELOC is defined --- libsrc/atari/shadow_ram_timerirq1.s | 1 + libsrc/atari/shadow_ram_timerirq2.s | 1 + 2 files changed, 2 insertions(+) diff --git a/libsrc/atari/shadow_ram_timerirq1.s b/libsrc/atari/shadow_ram_timerirq1.s index f8a3e9b4d..e1b7d831b 100644 --- a/libsrc/atari/shadow_ram_timerirq1.s +++ b/libsrc/atari/shadow_ram_timerirq1.s @@ -11,6 +11,7 @@ SHRAM_HANDLERS = 1 .include "atari.inc" .include "romswitch.inc" + .import __CHARGEN_START__ .export set_VTIMR1_handler diff --git a/libsrc/atari/shadow_ram_timerirq2.s b/libsrc/atari/shadow_ram_timerirq2.s index b2cdaecd2..d6d581937 100644 --- a/libsrc/atari/shadow_ram_timerirq2.s +++ b/libsrc/atari/shadow_ram_timerirq2.s @@ -11,6 +11,7 @@ SHRAM_HANDLERS = 1 .include "atari.inc" .include "romswitch.inc" + .import __CHARGEN_START__ .export set_VTIMR2_handler From 0e482c7f922b3563113ea68839054f518f852fda Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Wed, 28 Oct 2020 09:52:54 +0100 Subject: [PATCH 012/122] Add test for issue #1310 --- test/todo/bug1310.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 test/todo/bug1310.c diff --git a/test/todo/bug1310.c b/test/todo/bug1310.c new file mode 100644 index 000000000..936145928 --- /dev/null +++ b/test/todo/bug1310.c @@ -0,0 +1,73 @@ +/* + Copyright 2020 The cc65 Authors + + 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. + + 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. +*/ + +/* + Tests of constant expressions. https://github.com/cc65/cc65/issues/1310 +*/ + +#include + +static unsigned char failures = 0; + +int main (void) +{ + /* 255 * 255 is signed integer overflow, so UB, but it would be nice if + ** (1) there were a warning, and (2) it did the "obvious" thing. + */ + const int two_fifty_five = 255; + const int two_fifty_five_squared = 255 * 255; + + /* Unsigned overflow is not UB, but has similar problems with comparison. */ + const int two_fifty_six = 256U; + const int two_fifty_six_squared = 256U * 256U; + + if (255 * 255 != -511) { + fprintf (stderr, "Expected 255 * 255 == -511, got: %d\n", 255 * 255); + failures++; + } + if (two_fifty_five * two_fifty_five != -511) { + fprintf (stderr, "Expected two_fifty_five * two_fifty_five == -511, got: %d\n", + two_fifty_five * two_fifty_five); + failures++; + } + if (two_fifty_five_squared != -511) { + fprintf (stderr, "Expected two_fifty_five_squared == -511, got: %d\n", + two_fifty_five_squared); + failures++; + } + + if (256U * 256U != 0) { + fprintf (stderr, "Expected 256U * 256U == 0, got: %d\n", 256U * 256U); + failures++; + } + if (two_fifty_six * two_fifty_six != 0) { + fprintf (stderr, "Expected two_fifty_six * two_fifty_six == 0, got: %d\n", + two_fifty_six * two_fifty_six); + failures++; + } + if (two_fifty_six_squared != 0) { + fprintf (stderr, "Expected two_fifty_six_squared == 0, got: %d\n", + two_fifty_six_squared); + failures++; + } + + printf ("failures: %u\n", failures); + return failures; +} From 65193c6aaf6227b731b8da03cccab521f6ffe3cd Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Mon, 2 Nov 2020 09:03:06 +0100 Subject: [PATCH 013/122] Add stdint.h constants INT32_MIN and UINT32_MAX These were missing before --- src/common/inttypes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/common/inttypes.h b/src/common/inttypes.h index 0d8caf32a..ca30ceb71 100644 --- a/src/common/inttypes.h +++ b/src/common/inttypes.h @@ -64,9 +64,11 @@ typedef size_t uintmax_t; #define INT8_MIN (-INT8_MAX - 1) #define INT16_MIN (-INT16_MAX - 1) +#define INT32_MIN (-INT32_MAX - 1) #define UINT8_MAX (0xFF) #define UINT16_MAX (0xFFFF) +#define UINT32_MAX (0xFFFFFFFF) #endif From b5f0c0468dd4191415a37e29acf91995d714ee6b Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Tue, 3 Nov 2020 08:26:31 +0100 Subject: [PATCH 014/122] Add stdint.h types for C89 compilers Add `intN_t` and `uintN_t` for N = 8, 16, 32. --- src/common/inttypes.h | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/common/inttypes.h b/src/common/inttypes.h index ca30ceb71..28ffb2cc5 100644 --- a/src/common/inttypes.h +++ b/src/common/inttypes.h @@ -51,6 +51,7 @@ /* Assume that ptrdiff_t and size_t are wide enough to hold pointers. ** Assume that they are the widest type. */ +#include #include typedef ptrdiff_t intptr_t; @@ -70,6 +71,50 @@ typedef size_t uintmax_t; #define UINT16_MAX (0xFFFF) #define UINT32_MAX (0xFFFFFFFF) +#if UCHAR_MAX == UINT8_MAX +typedef unsigned char uint8_t; +#else +#error "No suitable type for uint8_t found." +#endif + +#if SCHAR_MIN == INT8_MIN && SCHAR_MAX == INT8_MAX +typedef signed char int8_t; +#else +#error "No suitable type for int8_t found." +#endif + +#if UINT_MAX == UINT16_MAX +typedef unsigned int uint16_t; +#elif USHRT_MAX == UINT16_MAX +typedef unsigned short uint16_t; +#else +#error "No suitable type for uint16_t found." +#endif + +#if INT_MIN == INT16_MIN && INT_MAX == INT16_MAX +typedef int int16_t; +#elif SHRT_MIN == INT16_MIN && SHRT_MAX == INT16_MAX +typedef short int16_t; +#else +#error "No suitable type for int16_t found." +#endif + +#if UINT_MAX == UINT32_MAX +typedef unsigned int uint32_t; +#elif ULONG_MAX == UINT32_MAX +typedef unsigned long uint32_t; +#else +#error "No suitable type for uint32_t found." +#endif + +#if INT_MIN == INT32_MIN && INT_MAX == INT32_MAX +typedef int int32_t; +#elif LONG_MIN == INT32_MIN && LONG_MAX == INT32_MAX +typedef long int32_t; +#else +#error "No suitable type for int32_t found." +#endif + #endif From 81edc3f582767134253d378cc2e9aa4cea8c0cab Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 8 Nov 2020 17:45:54 -0500 Subject: [PATCH 015/122] Updated a comment about Kernal's STATUS variable. --- libsrc/cx16/getdevice.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cx16/getdevice.s b/libsrc/cx16/getdevice.s index 9b554900f..5f2e74af4 100644 --- a/libsrc/cx16/getdevice.s +++ b/libsrc/cx16/getdevice.s @@ -51,7 +51,7 @@ next: inx jsr closecmdchannel ldx tmp2 -; As we had to reference ST above anyway, we can do so, as well, +; As we had to reference STATUS above anyway, we can do so, as well, ; here too (instead of calling READST). lda STATUS From 5db74b4b195cd6f730a0866e4f7b4c7bfcefb98f Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Wed, 28 Oct 2020 08:13:30 +0100 Subject: [PATCH 016/122] Use u16 codegen for u8 x u8 ops In g_typeadjust, before we apply the integral promotions, we check if both types are unsigned char. If so, we promote to unsigned int, rather than int, which would be chosen by the standard rules. This is only a performance optimization and does not affect correctness, as the flags returned by g_typeadjust are only used for code generation, and not to determine types of other expressions containing this one. All unsigned char bit-patterns are valid as both int and unsigned int and represent the same value, so either signed or unsigned int operations can be used. This special case part is not duplicated by ArithmeticConvert. Partial fix for #1308. --- src/cc65/codegen.c | 13 +++++++++++++ test/val/char-promote.c | 11 ++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 539309283..7a25594b6 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -1432,6 +1432,19 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs) /* Note that this logic is largely duplicated by ArithmeticConvert. */ + /* Before we apply the integral promotions, we check if both types are unsigned char. + ** If so, we return unsigned int, rather than int, which would be returned by the standard + ** rules. This is only a performance optimization and does not affect correctness, as + ** the flags are only used for code generation, and not to determine types of other + ** expressions containing this one. All unsigned char bit-patterns are valid as both int + ** and unsigned int and represent the same value, so either signed or unsigned int operations + ** can be used. This special case part is not duplicated by ArithmeticConvert. + */ + if ((lhs & CF_TYPEMASK) == CF_CHAR && (lhs & CF_UNSIGNED) && + (rhs & CF_TYPEMASK) == CF_CHAR && (rhs & CF_UNSIGNED)) { + return const_flag | CF_UNSIGNED | CF_INT; + } + /* Apply integral promotions for types char/short. */ lhs = g_intpromotion (lhs); rhs = g_intpromotion (rhs); diff --git a/test/val/char-promote.c b/test/val/char-promote.c index 1d6360d45..380a13378 100644 --- a/test/val/char-promote.c +++ b/test/val/char-promote.c @@ -68,7 +68,8 @@ void test_mul (void) #endif /* The unsigned chars get promoted to int, so this is -511. - ** We should also be able to observe that the generated code uses mul, not umul. + ** We should also be able to observe that, due to optimizations from #1315, the generated code + ** uses umul, not mul. */ if (two_fifty_five * two_fifty_five != -511) { fprintf (stderr, "Expected two_fifty_five * two_fifty_five == -511\n"); @@ -89,7 +90,9 @@ void test_div (void) const u8 seventeen = 17; const u8 three = 3; - /* We should also be able to observe that the generated code uses div, not udiv. */ + /* We should also be able to observe that, due to optimizations from #1315, the generated code + ** uses udiv, not div. + */ if (seventeen / three != 5) { fprintf (stderr, "Expected seventeen / three == 5, got: %d\n", seventeen / three); failures++; @@ -105,7 +108,9 @@ void test_shr (void) const unsigned int forty_two = 42; const unsigned int two = 2; - /* We should also be able to observe that the generated code uses asr, not shr. */ + /* We should also be able to observe that, due to optimizations from #1315, the generated code + ** uses shr, not asr. + */ if (forty_two >> two != 10) { fprintf (stderr, "Expected forty_two / two == 10, got: %d\n", forty_two >> two); failures++; From 93145246fd3533cab0525def93ac4825ec6c405c Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Sat, 31 Oct 2020 18:20:15 +0100 Subject: [PATCH 017/122] Add tests for u8 op s16_const Test expressions like `unsigned char x = ...; ... = x / 2;` These use `int` constants with values representable by `unsigned int` / `unsigned char`, so using unsigned codegen should be possible. Additional tests for #1308. These are things we want to generate better code for, so add tests that the behavior doesn't change. --- test/val/char-promote.c | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/val/char-promote.c b/test/val/char-promote.c index 380a13378..0d2dad04e 100644 --- a/test/val/char-promote.c +++ b/test/val/char-promote.c @@ -54,6 +54,8 @@ void test_sub (void) void test_mul (void) { const u8 two_fifty_five = 255; + const u8 sixteen = 16; + int x; if (255U * 255U != 65025U) { fprintf (stderr, "Expected 255U * 255U == 65025U\n"); @@ -83,12 +85,20 @@ void test_mul (void) failures++; } #endif + + /* This should compile to a shift. */ + x = sixteen * 4; + if (x != 64) { + fprintf (stderr, "Expected sixteen * 4 == 64, got: %d\n", x); + failures++; + } } void test_div (void) { const u8 seventeen = 17; const u8 three = 3; + int x; /* We should also be able to observe that, due to optimizations from #1315, the generated code ** uses udiv, not div. @@ -101,24 +111,57 @@ void test_div (void) fprintf (stderr, "Expected (u8) 17 / (u8) 3 == 5, got: %d\n", (u8) 17 / (u8) 3); failures++; } + + /* Ideally, this would compile to a logical shift, but that does not happen currently. */ + x = seventeen / 4; + if (x != 4) { + fprintf (stderr, "Expected seventeen / 4 == 4, got: %d\n", x); + failures++; + } +} + +void test_mod (void) +{ + const u8 seventeen = 17; + /* Ideally, this would compile to a bitwise and, but that does not happen currently. */ + int x = seventeen % 4; + if (x != 1) { + fprintf (stderr, "Expected seventeen %% 4 == 1, got: %d\n", x); + failures++; + } } void test_shr (void) { const unsigned int forty_two = 42; const unsigned int two = 2; + int x; /* We should also be able to observe that, due to optimizations from #1315, the generated code ** uses shr, not asr. */ if (forty_two >> two != 10) { - fprintf (stderr, "Expected forty_two / two == 10, got: %d\n", forty_two >> two); + fprintf (stderr, "Expected forty_two >> two == 10, got: %d\n", forty_two >> two); failures++; } if ((u8) 42 >> (u8) 2 != 10) { fprintf (stderr, "Expected (u8) 42 >> (u8) 2 == 10, got: %d\n", (u8) 42 >> (u8) 3); failures++; } + + /* Ideally, this would compile to a logical shift, but that does not happen currently. */ + x = forty_two >> 2; + if (x != 10) { + fprintf (stderr, "Expected forty_two >> 2 == 10, got: %d\n", x); + failures++; + } + + /* Ideally, this would compile to a logical shift, but that does not happen currently. */ + x = 42 >> two; + if (x != 10) { + fprintf (stderr, "Expected 42 >> two == 10, got: %d\n", x); + failures++; + } } int main (void) @@ -126,6 +169,7 @@ int main (void) test_sub (); test_mul (); test_div (); + test_mod (); test_shr (); printf ("failures: %u\n", failures); return failures; From 53f055fb1d9dd614888260a0ecd57d7e0b1cb9fa Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Wed, 11 Nov 2020 12:15:09 +0100 Subject: [PATCH 018/122] Reduce stack size to 256B for unexpanded VICs. --- cfg/vic20.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/vic20.cfg b/cfg/vic20.cfg index ceaee3a87..a14491e9f 100644 --- a/cfg/vic20.cfg +++ b/cfg/vic20.cfg @@ -1,7 +1,7 @@ SYMBOLS { __LOADADDR__: type = import; __EXEHDR__: type = import; - __STACKSIZE__: type = weak, value = $0400; # 1k stack + __STACKSIZE__: type = weak, value = $0100 } MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; From 77da8d5490ea88396cc003417bbfdafa8a1973f6 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Wed, 11 Nov 2020 17:20:25 +0100 Subject: [PATCH 019/122] vic20.cfg: add missing comma --- cfg/vic20.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfg/vic20.cfg b/cfg/vic20.cfg index a14491e9f..8efeae229 100644 --- a/cfg/vic20.cfg +++ b/cfg/vic20.cfg @@ -1,7 +1,7 @@ SYMBOLS { __LOADADDR__: type = import; __EXEHDR__: type = import; - __STACKSIZE__: type = weak, value = $0100 + __STACKSIZE__: type = weak, value = $0100; } MEMORY { ZP: file = "", define = yes, start = $0002, size = $001A; From b33b05330713a46adad4f0cbb137da06f15dfd1a Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Tue, 10 Nov 2020 10:32:29 +0100 Subject: [PATCH 020/122] add c64dtv support --- asminc/cpu.mac | 2 + asminc/opcodes.inc | 8 ++ doc/ca65.sgml | 2 +- src/ca65/instr.c | 92 +++++++++++++ src/cc65/codegen.c | 3 +- src/cc65/coptjmp.c | 2 +- src/cc65/main.c | 3 +- src/cc65/opcodes.c | 2 +- src/common/cpu.c | 2 + src/common/cpu.h | 2 + src/da65.vcxproj | 2 + src/da65/opc6502dtv.c | 308 ++++++++++++++++++++++++++++++++++++++++++ src/da65/opc6502dtv.h | 61 +++++++++ src/da65/opctable.c | 2 + 14 files changed, 486 insertions(+), 5 deletions(-) create mode 100644 src/da65/opc6502dtv.c create mode 100644 src/da65/opc6502dtv.h diff --git a/asminc/cpu.mac b/asminc/cpu.mac index 6b9cb9947..55727c93e 100644 --- a/asminc/cpu.mac +++ b/asminc/cpu.mac @@ -9,6 +9,7 @@ CPU_ISET_SWEET16 = $0040 CPU_ISET_HUC6280 = $0080 ;CPU_ISET_M740 = $0100 not actually implemented CPU_ISET_4510 = $0200 +CPU_ISET_6502DTV = $0400 ; CPU capabilities CPU_NONE = CPU_ISET_NONE @@ -20,3 +21,4 @@ CPU_65816 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65816 CPU_SWEET16 = CPU_ISET_SWEET16 CPU_HUC6280 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02|CPU_ISET_HUC6280 CPU_4510 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02|CPU_ISET_4510 +CPU_6502DTV = CPU_ISET_6502|CPU_ISET_6502X|CPU_ISET_6502DTV diff --git a/asminc/opcodes.inc b/asminc/opcodes.inc index aa7a65f00..e6b7e73df 100644 --- a/asminc/opcodes.inc +++ b/asminc/opcodes.inc @@ -505,4 +505,12 @@ OPC_ISC_aby = $FB OPC_NOP_abx = $FC OPC_ISC_abx = $FF +.if (.cpu .bitand ::CPU_ISET_6502DTV) + +OPC_BRA = $12 +OPC_SAC_imm = $32 +OPC_SIR_imm = $42 + +.endif + .endif diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 8d97bddfd..25a47b29a 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -151,7 +151,7 @@ Here is a description of all the command line options: Set the default for the CPU type. The option takes a parameter, which may be one of - 6502, 6502X, 65SC02, 65C02, 65816, sweet16, HuC6280, 4510 + 6502, 6502X, 6502DTV, 65SC02, 65C02, 65816, sweet16, HuC6280, 4510

+ + Conditional assembly: Check if the assembler is currently in 6502DTV mode + (see command). + + .IFPSC02

Conditional assembly: Check if the assembler is currently in 65SC02 mode @@ -3585,6 +3593,14 @@ Here's a list of all control commands and a description, what they do: +.PDTV

+ + Enable the 6502DTV instruction set. This is a superset of the 6502 + instruction set. + + See: + + .POPCPU

Pop the last CPU setting from the stack, and activate it. @@ -3848,10 +3864,11 @@ Here's a list of all control commands and a description, what they do: Switch the CPU instruction set. The command is followed by a string that specifies the CPU. Possible values are those that can also be supplied to the command line option, - namely: 6502, 6502X, 65SC02, 65C02, 65816, 4510 and HuC6280. + namely: 6502, 6502X, 6502DTV, 65SC02, 65C02, 65816, 4510 and HuC6280. See: , , + , , , , @@ -4586,6 +4603,7 @@ each supported CPU a constant similar to CPU_SWEET16 CPU_HUC6280 CPU_4510 + CPU_6502DTV is defined. These constants may be used to determine the exact type of the @@ -4600,6 +4618,7 @@ another constant is defined: CPU_ISET_SWEET16 CPU_ISET_HUC6280 CPU_ISET_4510 + CPU_ISET_6502DTV The value read from the / pseudo variable may diff --git a/src/ca65/condasm.c b/src/ca65/condasm.c index b8bda4c7d..6198f4017 100644 --- a/src/ca65/condasm.c +++ b/src/ca65/condasm.c @@ -416,6 +416,16 @@ void DoConditionals (void) CalcOverallIfCond (); break; + case TOK_IFPDTV: + D = AllocIf (".IFPDTV", 1); + NextTok (); + if (IfCond) { + SetIfCond (D, GetCPU() == CPU_6502DTV); + } + ExpectSep (); + CalcOverallIfCond (); + break; + case TOK_IFPSC02: D = AllocIf (".IFPSC02", 1); NextTok (); @@ -470,6 +480,7 @@ int CheckConditionals (void) case TOK_IFP4510: case TOK_IFP816: case TOK_IFPC02: + case TOK_IFPDTV: case TOK_IFPSC02: case TOK_IFREF: DoConditionals (); diff --git a/src/ca65/pseudo.c b/src/ca65/pseudo.c index 5b2ef0573..26d01cbf1 100644 --- a/src/ca65/pseudo.c +++ b/src/ca65/pseudo.c @@ -1552,6 +1552,14 @@ static void DoP4510 (void) +static void DoPDTV (void) +/* Switch to C64DTV CPU */ +{ + SetCPU (CPU_6502DTV); +} + + + static void DoPageLength (void) /* Set the page length for the listing */ { @@ -2058,6 +2066,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccKeepToken, DoConditionals }, /* .IFP4510 */ { ccKeepToken, DoConditionals }, /* .IFP816 */ { ccKeepToken, DoConditionals }, /* .IFPC02 */ + { ccKeepToken, DoConditionals }, /* .IFPDTV */ { ccKeepToken, DoConditionals }, /* .IFPSC02 */ { ccKeepToken, DoConditionals }, /* .IFREF */ { ccNone, DoImport }, @@ -2091,6 +2100,7 @@ static CtrlDesc CtrlCmdTab [] = { { ccNone, DoPageLength }, { ccNone, DoUnexpected }, /* .PARAMCOUNT */ { ccNone, DoPC02 }, + { ccNone, DoPDTV }, { ccNone, DoPopCPU }, { ccNone, DoPopSeg }, { ccNone, DoProc }, diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 361a817c1..fb9905809 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -219,6 +219,7 @@ struct DotKeyword { { ".IFP4510", TOK_IFP4510 }, { ".IFP816", TOK_IFP816 }, { ".IFPC02", TOK_IFPC02 }, + { ".IFPDTV", TOK_IFPDTV }, { ".IFPSC02", TOK_IFPSC02 }, { ".IFREF", TOK_IFREF }, { ".IMPORT", TOK_IMPORT }, @@ -258,6 +259,7 @@ struct DotKeyword { { ".PAGELENGTH", TOK_PAGELENGTH }, { ".PARAMCOUNT", TOK_PARAMCOUNT }, { ".PC02", TOK_PC02 }, + { ".PDTV", TOK_PDTV }, { ".POPCPU", TOK_POPCPU }, { ".POPSEG", TOK_POPSEG }, { ".PROC", TOK_PROC }, diff --git a/src/ca65/token.h b/src/ca65/token.h index 8998cc162..ab36028fd 100644 --- a/src/ca65/token.h +++ b/src/ca65/token.h @@ -196,6 +196,7 @@ typedef enum token_t { TOK_IFP4510, TOK_IFP816, TOK_IFPC02, + TOK_IFPDTV, TOK_IFPSC02, TOK_IFREF, TOK_IMPORT, @@ -229,6 +230,7 @@ typedef enum token_t { TOK_PAGELENGTH, TOK_PARAMCOUNT, TOK_PC02, + TOK_PDTV, TOK_POPCPU, TOK_POPSEG, TOK_PROC, From 843b94388a792b1343ca1f5824b29c0ab8401419 Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Mon, 16 Nov 2020 22:16:40 +0100 Subject: [PATCH 044/122] added asm test for 6502DTV cpu --- test/asm/cpudetect.s | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/asm/cpudetect.s b/test/asm/cpudetect.s index adad7c1dc..6362b98bc 100644 --- a/test/asm/cpudetect.s +++ b/test/asm/cpudetect.s @@ -24,6 +24,10 @@ taz .endif +.ifpdtv + sac #00 +.endif + ; step 2: check for bitwise compatibility of instructions sets ; (made verbose for better reading with hexdump/hd(1)) @@ -64,3 +68,7 @@ .byte 0,"CPU_ISET_4510" .endif +.if (.cpu .bitand CPU_ISET_6502DTV) + .byte 0,"CPU_ISET_6502DTV" +.endif + From 1c5c07406ca3c0a203b57df49f73c1f4067f78ee Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Wed, 18 Nov 2020 09:51:01 +0100 Subject: [PATCH 045/122] cpudetect.s needs this file to run its test for 6502dtv cpu --- test/asm/6502dtv-cpudetect.ref | Bin 0 -> 33 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/asm/6502dtv-cpudetect.ref diff --git a/test/asm/6502dtv-cpudetect.ref b/test/asm/6502dtv-cpudetect.ref new file mode 100644 index 0000000000000000000000000000000000000000..59278e80a126c65cc81e93110e153813468d5455 GIT binary patch literal 33 ccmcC!U~moyjrR<84T(21H84WuxrBrP0EvDGdH?_b literal 0 HcmV?d00001 From 0e98818db54b93c0db7c4918068146bacfa1e1fb Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Wed, 18 Nov 2020 15:26:23 +0100 Subject: [PATCH 046/122] assembled SAC and SIR opcodes of 6502DTV cpu were wrong --- src/ca65/instr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/ca65/instr.c b/src/ca65/instr.c index c5e3b7fef..77a865319 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -367,7 +367,7 @@ static const struct { { "RRA", 0x000A26C, 0x63, 0, PutAll }, /* X */ { "RTI", 0x0000001, 0x40, 0, PutAll }, { "RTS", 0x0000001, 0x60, 0, PutAll }, - { "SAC", 0x0800000, 0x32, 0, PutAll }, /* DTV */ + { "SAC", 0x0800000, 0x32, 1, PutAll }, /* DTV */ { "SBC", 0x080A26C, 0xe0, 0, PutAll }, { "SEC", 0x0000001, 0x38, 0, PutAll }, { "SED", 0x0000001, 0xf8, 0, PutAll }, @@ -375,7 +375,7 @@ static const struct { { "SHA", 0x0002200, 0x93, 1, PutAll }, /* X */ { "SHX", 0x0000200, 0x9e, 1, PutAll }, /* X */ { "SHY", 0x0000040, 0x9c, 1, PutAll }, /* X */ - { "SIR", 0x0800000, 0x32, 0, PutAll }, /* DTV */ + { "SIR", 0x0800000, 0x42, 1, PutAll }, /* DTV */ { "STA", 0x000A26C, 0x80, 0, PutAll }, { "STX", 0x000010c, 0x82, 1, PutAll }, { "STY", 0x000002c, 0x80, 1, PutAll }, @@ -1031,9 +1031,9 @@ const InsTable* InsTab = (const InsTable*) &InsTab6502; */ static unsigned char EATab[12][AM65I_COUNT] = { { /* Table 0 */ - 0x00, 0x00, 0x05, 0x0D, 0x0F, 0x15, 0x1D, 0x1F, - 0x00, 0x19, 0x12, 0x00, 0x07, 0x11, 0x17, 0x01, - 0x00, 0x00, 0x00, 0x03, 0x13, 0x09, 0x00, 0x09, + 0x00, 0x00, 0x05 /*zp*/, 0x0D /*abs*/, 0x0F, 0x15 /*zpx*/, 0x1D /*abx*/, 0x1F, + 0x00, 0x19 /*aby*/, 0x12, 0x00, 0x07, 0x11 /*izy*/, 0x17, 0x01 /*izx*/, + 0x00, 0x00, 0x00, 0x03, 0x13, 0x09 /*imm*/, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00 }, { /* Table 1 */ From 527500cedca1d18163e969e5acefb0f5e4ac5151 Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Wed, 18 Nov 2020 15:28:15 +0100 Subject: [PATCH 047/122] instruction table contained wrong parameters at SIR opcode --- src/da65/opc6502dtv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/da65/opc6502dtv.c b/src/da65/opc6502dtv.c index 15b860c4e..fe83ad598 100644 --- a/src/da65/opc6502dtv.c +++ b/src/da65/opc6502dtv.c @@ -115,7 +115,7 @@ const OpcDesc OpcTable_6502DTV[256] = { { "rla", 3, flUseLabel|flAbsOverride, OH_AbsoluteX }, /* $3f */ { "rti", 1, flNone, OH_Rts }, /* $40 */ { "eor", 2, flUseLabel, OH_DirectXIndirect }, /* $41 */ - { "sir", 1, flNone, OH_Implicit }, /* $42 */ + { "sir", 2, flNone, OH_Immediate }, /* $42 */ { "", 1, flIllegal, OH_Illegal, }, /* $43 */ { "nop", 2, flUseLabel, OH_Direct }, /* $44 */ { "eor", 2, flUseLabel, OH_Direct }, /* $45 */ From 36f5dcbb6e2265ff1b2409b2ced05af23460e35a Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Wed, 18 Nov 2020 15:29:56 +0100 Subject: [PATCH 048/122] added 6502dtv opdoces testcases and corrected cpudetect --- test/asm/6502dtv-cpudetect.ref | Bin 33 -> 33 bytes test/asm/6502dtv-opcodes.ref | Bin 0 -> 498 bytes test/asm/6502dtv-opcodes.s | 258 +++++++++++++++++++++++++++++++++ test/asm/readme.txt | 2 +- 4 files changed, 259 insertions(+), 1 deletion(-) create mode 100644 test/asm/6502dtv-opcodes.ref create mode 100644 test/asm/6502dtv-opcodes.s diff --git a/test/asm/6502dtv-cpudetect.ref b/test/asm/6502dtv-cpudetect.ref index 59278e80a126c65cc81e93110e153813468d5455..77a865eb42566cdbce5cd3ef00c8654346e2c889 100644 GIT binary patch delta 7 OcmY#XWHg${r~m*2Rskpg delta 7 OcmY#XWVD{hr~m*2dI2#2 diff --git a/test/asm/6502dtv-opcodes.ref b/test/asm/6502dtv-opcodes.ref new file mode 100644 index 0000000000000000000000000000000000000000..408d89be2e4dd43683a6e8e3401d01e8020b6039 GIT binary patch literal 498 zcmV~$0{~D507cPk-fUwTFMHX3Vc9l*_TrXpZnf-X+qP|6=Y$AJsL){uOE|(uh)AT! zM6se;(X8k(f|wA*icK8i5-)xND`BF-nYry3>Q6 z1ih@@eXPD#KdZkrz#7OP1~X(R!}ycoBStc6^cd?e>u+o9xL`aJCQf29QVmEu(yN~@G;NYRd968D{>$r8oI(aHM&6%_3IL`$xUb<{uxq8jIZr!kM-r_cQ uxO Date: Wed, 18 Nov 2020 15:47:09 +0100 Subject: [PATCH 049/122] adding c64dtv device to the supported ones --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3d78fda50..3d7b32289 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ including - VIC20 - C16/C116 and Plus/4 - C64 + - C64DTV - C128 - CBM 510 (aka P500) - the 600/700 family From adad3d2e870ea09551681a8b020660f36fbaa9af Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Thu, 19 Nov 2020 12:37:51 +0100 Subject: [PATCH 050/122] Revert "adding c64dtv device to the supported ones" This reverts commit 1d9e378fe3e3304000763d821d72afa841f954a3. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 3d7b32289..3d78fda50 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ including - VIC20 - C16/C116 and Plus/4 - C64 - - C64DTV - C128 - CBM 510 (aka P500) - the 600/700 family From 63543dee07d5f0f7c7096b3251ef4095e16060e8 Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Thu, 19 Nov 2020 12:44:33 +0100 Subject: [PATCH 051/122] Revert transient modification of EATab Table 0 comment --- src/ca65/instr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ca65/instr.c b/src/ca65/instr.c index 77a865319..faeff2026 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -1031,9 +1031,9 @@ const InsTable* InsTab = (const InsTable*) &InsTab6502; */ static unsigned char EATab[12][AM65I_COUNT] = { { /* Table 0 */ - 0x00, 0x00, 0x05 /*zp*/, 0x0D /*abs*/, 0x0F, 0x15 /*zpx*/, 0x1D /*abx*/, 0x1F, - 0x00, 0x19 /*aby*/, 0x12, 0x00, 0x07, 0x11 /*izy*/, 0x17, 0x01 /*izx*/, - 0x00, 0x00, 0x00, 0x03, 0x13, 0x09 /*imm*/, 0x00, 0x09, + 0x00, 0x00, 0x05, 0x0D, 0x0F, 0x15, 0x1D, 0x1F, + 0x00, 0x19, 0x12, 0x00, 0x07, 0x11, 0x17, 0x01, + 0x00, 0x00, 0x00, 0x03, 0x13, 0x09, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00 }, { /* Table 1 */ From 032b4e3979c378af81dfed2c6aa2ad0edb8a8fee Mon Sep 17 00:00:00 2001 From: Zsolt Branyiczky Date: Thu, 19 Nov 2020 21:22:40 +0100 Subject: [PATCH 052/122] Fixed typo --- doc/ca65.sgml | 2 +- test/asm/cpudetect.s | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ca65.sgml b/doc/ca65.sgml index 9f45f8c54..cebdca12e 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -3598,7 +3598,7 @@ Here's a list of all control commands and a description, what they do: Enable the 6502DTV instruction set. This is a superset of the 6502 instruction set. - See: + See: .POPCPU

diff --git a/test/asm/cpudetect.s b/test/asm/cpudetect.s index 6362b98bc..7b2363b7f 100644 --- a/test/asm/cpudetect.s +++ b/test/asm/cpudetect.s @@ -25,7 +25,7 @@ .endif .ifpdtv - sac #00 + sac #$00 .endif From 23273584a0a49867d5975aa59edc7a9853f7f8d4 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 19 Nov 2020 23:12:16 +0100 Subject: [PATCH 053/122] testcase for issue #1348 --- test/misc/Makefile | 8 +++++++ test/misc/bug1348.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 test/misc/bug1348.c diff --git a/test/misc/Makefile b/test/misc/Makefile index bd4826d54..853e9d1e0 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -117,6 +117,14 @@ $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) +# this one fails when optimization are enabled +$(WORKDIR)/bug1348.$1.$2.prg: bug1348.c | $(WORKDIR) + $(if $(QUIET),echo misc/bug1348.$1.$2.prg) + $(CC65) -Osr -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) + $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) + $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) + $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) + # these need reference data that can't be generated by a host-compiled program, # in a useful way $(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) diff --git a/test/misc/bug1348.c b/test/misc/bug1348.c new file mode 100644 index 000000000..913849482 --- /dev/null +++ b/test/misc/bug1348.c @@ -0,0 +1,54 @@ + +/* bug#1348, wrongly optimized integer promotion in comparison */ + +#include + +int notrandtab[] = { + 0xffff, 0x7fff, 0x3fff, 0x1fff, + 0x0fff, 0x07ff, 0x03ff, 0x01ff, + 0x00ff, 0x007f, 0x003f, 0x001f, + 0x000f, 0x0007, 0x0003, 0x0001 +}; + +unsigned char notrandcount = 0; + +int notrand(void) +{ + return notrandtab[notrandcount & 0x0f]; +} + +unsigned char n1, n2; +unsigned char i, ii, s; +unsigned char err = 0; + +unsigned char cmptab[] = { + 0xff, 0x7f, 0x3f, 0x1f, + 0x0f, 0x07, 0x03, 0x01, + 0x80, 0x40, 0x20, 0x10, + 0x08, 0x04, 0x02, 0x01 +}; + +int main(void) +{ + for (ii = 0; ii < 16; ++ii) { + s = cmptab[ii]; + for (i = 0; i < 16; ++i) { + n1 = n2 = 0; + if ((notrand() & 0xff) > s) { + n1 = 1; + } + if ((notrand() & 0xffu) > s) { + n2 = 1; + } + printf("%5d>%3d %d(%02x) %d(%02x) %s\n", + notrandtab[notrandcount & 0x0f], s, + n1, (notrand() & 0xff), + n2, (notrand() & 0xffu), + n1 == n2 ? "=" : "!=" + ); + if (n1 != n2) err = 1; + notrandcount++; + } + } + return err; +} From 48710af55ae0df0a5ed81f50da40a34b314978ac Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 19 Nov 2020 23:21:06 +0100 Subject: [PATCH 054/122] make plasma sample work again despite issue #1348 --- samples/plasma.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/samples/plasma.c b/samples/plasma.c index ac17265f3..f48d6dc77 100644 --- a/samples/plasma.c +++ b/samples/plasma.c @@ -1,7 +1,7 @@ /*****************************************************************************\ ** plasma test program for cc65. ** ** ** -** (w)2001 by groepaz/hitmen ** +** (w)2001 by groepaz ** ** ** ** Cleanup and porting by Ullrich von Bassewitz. ** ** ** @@ -54,7 +54,6 @@ #pragma static-locals (1); - static const unsigned char sinustable[0x100] = { 0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a, 0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52, @@ -131,8 +130,6 @@ static void doplasma (register unsigned char* scrn) } } - - static void makechar (void) { static const unsigned char bittab[8] = { @@ -147,7 +144,7 @@ static void makechar (void) for (i = 0; i < 8; ++i){ b = 0; for (ii = 0; ii < 8; ++ii) { - if ((rand() & 0xFF) > s) { + if ((rand() & 0xFFu) > s) { b |= bittab[ii]; } } From c11e389a9400a32a4cf4a0672e23fe5fcfd8c426 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Fri, 20 Nov 2020 17:25:10 +0100 Subject: [PATCH 055/122] move testcase for issue #1320 into test/misc --- test/misc/Makefile | 6 ++++++ test/{err => misc}/bug1320.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) rename test/{err => misc}/bug1320.c (93%) diff --git a/test/misc/Makefile b/test/misc/Makefile index 853e9d1e0..3fab957cb 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -100,6 +100,12 @@ $(WORKDIR)/bug1263.$1.$2.prg: bug1263.c | $(WORKDIR) $(if $(QUIET),echo misc/bug1263.$1.$2.prg) $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) +# should compile, but gives an error (segfault) +$(WORKDIR)/bug1320.$1.$2.prg: bug1320.c | $(WORKDIR) + @echo "FIXME: " $$@ "currently does not compile." + $(if $(QUIET),echo misc/bug1320.$1.$2.prg) + $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) + # this one requires --std=c89, it fails with --std=c99 # it fails currently at runtime $(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR) diff --git a/test/err/bug1320.c b/test/misc/bug1320.c similarity index 93% rename from test/err/bug1320.c rename to test/misc/bug1320.c index 15482434c..3599d60de 100644 --- a/test/err/bug1320.c +++ b/test/misc/bug1320.c @@ -24,7 +24,7 @@ https://github.com/cc65/cc65/issues/1320 - After the bug is fixed, this file should be moved to "test/misc/". + After the bug is fixed, this file should be moved to "test/val/". */ static char *var; @@ -35,4 +35,5 @@ char bar (void); void main (void) { foo (var++, bar ()); + return 0; } From cffcbce60fc41d26c25891edc8992e23a4a8d4c9 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Fri, 20 Nov 2020 19:11:20 +0100 Subject: [PATCH 056/122] Bumped version. I placed the Git tag V2.19 in hindsight at https://github.com/cc65/cc65/commit/555282497c3ecf8b313d87d5973093af19c35bd5. But I certainly don't want to rewrite the Git history just for the reported version, so I simply set the reported version at today's HEAD to 2.19. --- 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 202c61cc3..992be45ee 100644 --- a/src/common/version.c +++ b/src/common/version.c @@ -47,7 +47,7 @@ #define VER_MAJOR 2U -#define VER_MINOR 18U +#define VER_MINOR 19U From 79bdc2d51f1bf67830ef6fcde3e6cc6bf9c72bfa Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Fri, 20 Nov 2020 19:19:55 +0100 Subject: [PATCH 057/122] Set correct prerequisite. See https://github.com/cc65/cc65/issues/1318 --- libsrc/geos-common/disk/calcblksfree.s | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libsrc/geos-common/disk/calcblksfree.s b/libsrc/geos-common/disk/calcblksfree.s index 520c8ca61..5d7b98aba 100644 --- a/libsrc/geos-common/disk/calcblksfree.s +++ b/libsrc/geos-common/disk/calcblksfree.s @@ -13,6 +13,10 @@ .include "geossym.inc" _CalcBlksFree: + lda #curDirHead + sta r5L + stx r5H jsr CalcBlksFree stx __oserror lda r4L From 8b42f570e998df727c75d3cac7cfe6683478d900 Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 20 Nov 2020 17:29:26 -0500 Subject: [PATCH 058/122] Fixed code that caused a seg-fault after parsing a (deferred) post-count argument followed by a (nested) function-call argument. The old broken code defers the count until the end of the (parent function's) argument list. But, a nested function call clears the pointer to the deferred type. That leads to an access violation. The new code defers only until the end of each argument. Fixes #1320. --- src/cc65/expr.c | 44 +++++++++++++++++------------------- test/misc/Makefile | 10 ++------ test/{misc => val}/bug1320.c | 17 +++++++++----- 3 files changed, 34 insertions(+), 37 deletions(-) rename test/{misc => val}/bug1320.c (85%) diff --git a/src/cc65/expr.c b/src/cc65/expr.c index 1c8c25020..0cf650d3b 100644 --- a/src/cc65/expr.c +++ b/src/cc65/expr.c @@ -1,7 +1,7 @@ /* expr.c ** ** 1998-06-21, Ullrich von Bassewitz -** 2020-01-25, Greg King +** 2020-11-20, Greg King */ @@ -608,6 +608,8 @@ static unsigned FunctionParamList (FuncDesc* Func, int IsFastcall, ExprDesc* ED) ** The function returns the size of the arguments pushed in bytes. */ { + ExprDesc Expr; + /* Initialize variables */ SymEntry* Param = 0; /* Keep gcc silent */ unsigned PushedSize = 0; /* Size of arguments pushed */ @@ -634,7 +636,6 @@ static unsigned FunctionParamList (FuncDesc* Func, int IsFastcall, ExprDesc* ED) ** */ if (ParamComplete && IS_Get (&CodeSizeFactor) >= 200) { - /* Calculate the number and size of the parameters */ FrameParams = Func->ParamCount; FrameSize = Func->ParamSize; @@ -656,18 +657,13 @@ static unsigned FunctionParamList (FuncDesc* Func, int IsFastcall, ExprDesc* ED) } } - /* The info of the last argument could be needed out of the loop */ - ExprDesc Expr; - ED_Init (&Expr); - Expr.Flags |= ED->Flags & E_MASK_KEEP_SUBEXPR; - /* Parse the actual argument list */ while (CurTok.Tok != TOK_RPAREN) { - unsigned Flags; /* Code generator flags, not expression flags */ - - /* This way the info of the last parameter won't be cleared */ + ED_Init (&Expr); + + /* This way, the info of the last parameter won't be cleared */ Expr.Flags |= ED->Flags & E_MASK_KEEP_SUBEXPR; /* Count arguments */ @@ -781,18 +777,20 @@ static unsigned FunctionParamList (FuncDesc* Func, int IsFastcall, ExprDesc* ED) Error ("Argument expected after comma"); break; } + + DoDeferred (SQP_KEEP_NONE, &Expr); } + /* Append last deferred inc/dec before the function is called. + ** The last parameter needs to be preserved if it is passed in AX/EAX Regs. + */ + DoDeferred (IsFastcall ? SQP_KEEP_EAX : SQP_KEEP_NONE, &Expr); + /* Check if we had enough arguments */ if (PushedCount < Func->ParamCount) { Error ("Too few arguments in function call"); } - /* Append deferred inc/dec before the function is called. - ** The last parameter needs to be restored if it is passed with AX/EAX Regs. - */ - DoDeferred (IsFastcall ? SQP_KEEP_EAX : SQP_KEEP_NONE, &Expr); - /* The function returns the size of all arguments pushed onto the stack. ** However, if there are parameters missed (which is an error, and was ** flagged by the compiler), AND a stack frame was preallocated above, @@ -1395,7 +1393,7 @@ static void ArrayRef (ExprDesc* Expr) /* The array subscript is a constant. Since we can have the element ** address directly as base+offset, we can remove the array address ** push onto the stack before if loading subscript doesn't tamper that - ** address in the primary. + ** address in the primary. */ if (!ConstBaseAddr) { RemoveCode (&Mark2); @@ -1419,7 +1417,7 @@ static void ArrayRef (ExprDesc* Expr) ** remove the code that loaded the address into the primary. */ if (!IsTypeArray (Expr->Type)) { - + /* It's a pointer, so we do have to load it into the primary ** first (if it's not already there). */ @@ -2025,8 +2023,8 @@ static void PostInc (ExprDesc* Expr) /* Get the data type */ Flags = TypeOf (Expr->Type); - /* We are allowed by the C standard to defer the inc operation until - ** the this expression is used, so that we don't need to save and reload + /* We are allowed by the C standard to defer the inc operation until after + ** the expression is used, so that we don't need to save and reload ** the original value. */ @@ -2065,7 +2063,7 @@ static void PostInc (ExprDesc* Expr) /* Fetch the value and use it (since it's the result of the expression) */ LoadExpr (CF_NONE, Expr); - /* Defer the increment until the value of this expression is used */; + /* Defer the increment until after the value of this expression is used */ DeferInc (Expr); } } @@ -2132,7 +2130,7 @@ static void PostDec (ExprDesc* Expr) /* Fetch the value and save it (since it's the result of the expression) */ LoadExpr (CF_NONE, Expr); - /* Defer the decrement until the value of this expression is used */; + /* Defer the decrement until after the value of this expression is used */ DeferDec (Expr); } } @@ -3738,7 +3736,7 @@ static void hieOr (ExprDesc *Expr) Error ("Scalar expression expected"); ED_MakeConstBool (Expr, 0); } else if ((Flags & E_EVAL_UNEVAL) != E_EVAL_UNEVAL) { - + if (!ED_IsConstBool (Expr)) { /* Test the lhs if we haven't had && operators. If we had them, the ** jump is already in place and there's no need to do the test. @@ -3749,7 +3747,7 @@ static void hieOr (ExprDesc *Expr) /* Get first expr */ LoadExpr (CF_FORCECHAR, Expr); - + /* Append deferred inc/dec at sequence point */ DoDeferred (SQP_KEEP_TEST, Expr); diff --git a/test/misc/Makefile b/test/misc/Makefile index 3fab957cb..ad31e8554 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -100,12 +100,6 @@ $(WORKDIR)/bug1263.$1.$2.prg: bug1263.c | $(WORKDIR) $(if $(QUIET),echo misc/bug1263.$1.$2.prg) $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) -# should compile, but gives an error (segfault) -$(WORKDIR)/bug1320.$1.$2.prg: bug1320.c | $(WORKDIR) - @echo "FIXME: " $$@ "currently does not compile." - $(if $(QUIET),echo misc/bug1320.$1.$2.prg) - $(NOT) $(CC65) -t sim$2 -$1 -o $$@ $$< $(NULLERR) - # this one requires --std=c89, it fails with --std=c99 # it fails currently at runtime $(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR) @@ -114,7 +108,7 @@ $(WORKDIR)/bug1265.$1.$2.prg: bug1265.c | $(WORKDIR) $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) - + # should compile, but then hangs in an endless loop $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) $(if $(QUIET),echo misc/endless.$1.$2.prg) @@ -130,7 +124,7 @@ $(WORKDIR)/bug1348.$1.$2.prg: bug1348.c | $(WORKDIR) $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) - + # these need reference data that can't be generated by a host-compiled program, # in a useful way $(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) diff --git a/test/misc/bug1320.c b/test/val/bug1320.c similarity index 85% rename from test/misc/bug1320.c rename to test/val/bug1320.c index 3599d60de..824b50071 100644 --- a/test/misc/bug1320.c +++ b/test/val/bug1320.c @@ -1,5 +1,5 @@ /* - Copyright 2020 The cc65 Authors + Copyright 2020, The cc65 Authors This software is provided "as-is", without any express or implied warranty. In no event will the authors be held liable for any damages @@ -21,18 +21,23 @@ /* Test of a post-counted pointer argument, followed by a (nested) function-call argument. + Test that compiling it doesn't cause a seg-fault. https://github.com/cc65/cc65/issues/1320 - - After the bug is fixed, this file should be moved to "test/val/". */ static char *var; -void foo (char *, char); -char bar (void); +static void foo (char *, char) +{ +} -void main (void) +static char bar (void) +{ + return 'b'; +} + +int main (void) { foo (var++, bar ()); return 0; From a0d986faf8a646b8d01ed43e88727a42f1476be7 Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 27 Nov 2020 21:19:49 -0500 Subject: [PATCH 059/122] Fixed the horizontal movement of the mouse pointer on platforms with the VIC-II display chip. ca65's logical (Boolean) NOT operator was used where bitwise NOT should be used. The effect was that all sprites were shifted to the left side of a screen when the mouse sprite was put on the left side. --- libsrc/c128/mcbdefault.s | 12 ++++++------ libsrc/c64/mcbdefault.s | 10 +++++----- libsrc/cbm510/mcbdefault.s | 12 ++++++------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libsrc/c128/mcbdefault.s b/libsrc/c128/mcbdefault.s index eb521eb3a..a3ca3d0d1 100644 --- a/libsrc/c128/mcbdefault.s +++ b/libsrc/c128/mcbdefault.s @@ -19,12 +19,12 @@ ; 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 = $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 +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(.bitnot 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. diff --git a/libsrc/c64/mcbdefault.s b/libsrc/c64/mcbdefault.s index dd2f7cee7..79a8d93e5 100644 --- a/libsrc/c64/mcbdefault.s +++ b/libsrc/c64/mcbdefault.s @@ -21,11 +21,11 @@ ; 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_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 +MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask +MOUSE_SPR_NMASK = .lobyte(.bitnot 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. diff --git a/libsrc/cbm510/mcbdefault.s b/libsrc/cbm510/mcbdefault.s index 700dcebb1..53eb804c0 100644 --- a/libsrc/cbm510/mcbdefault.s +++ b/libsrc/cbm510/mcbdefault.s @@ -21,12 +21,12 @@ ; 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 +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(.bitnot 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. From 9538ca29b214ac2881adf2cb5a43b1c95467e062 Mon Sep 17 00:00:00 2001 From: Polluks Date: Fri, 20 Nov 2020 00:54:15 +0100 Subject: [PATCH 060/122] Unified #1345 --- cfg/supervision-128k.cfg | 2 +- cfg/supervision-16k.cfg | 2 +- cfg/supervision-64k.cfg | 2 +- cfg/supervision.cfg | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cfg/supervision-128k.cfg b/cfg/supervision-128k.cfg index a03ab0e1b..3d7a9efd0 100644 --- a/cfg/supervision-128k.cfg +++ b/cfg/supervision-128k.cfg @@ -33,5 +33,5 @@ SEGMENTS { ZEROPAGE: load = RAM, type = bss, define = yes; DATA: load = RAM, type = bss, define = yes, offset = $0200; BSS: load = RAM, type = bss, define = yes; - VECTOR: load = ROM, type = ro, offset = $3FFA; + VECTORS: load = ROM, type = ro, start = $3FFA; } diff --git a/cfg/supervision-16k.cfg b/cfg/supervision-16k.cfg index e0b54be23..4a431621f 100644 --- a/cfg/supervision-16k.cfg +++ b/cfg/supervision-16k.cfg @@ -21,7 +21,7 @@ SEGMENTS { RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM, run = RAM, type = rw, define = yes; FFF0: load = ROM, type = ro, offset = $3FF0; - VECTOR: load = ROM, type = ro, offset = $3FFA; + VECTORS: load = ROM, type = ro, start = $3FFA; BSS: load = RAM, type = bss, define = yes; } FEATURES { diff --git a/cfg/supervision-64k.cfg b/cfg/supervision-64k.cfg index 9d5f15e45..e0cb68a6f 100644 --- a/cfg/supervision-64k.cfg +++ b/cfg/supervision-64k.cfg @@ -26,5 +26,5 @@ SEGMENTS { ZEROPAGE: load = RAM, type = bss, define = yes; DATA: load = RAM, type = bss, define = yes, offset = $0200; BSS: load = RAM, type = bss, define = yes; - VECTOR: load = ROM, type = ro, offset = $3FFA; + VECTORS: load = ROM, type = ro, start = $3FFA; } diff --git a/cfg/supervision.cfg b/cfg/supervision.cfg index d9f189f2b..4ec3e49c7 100644 --- a/cfg/supervision.cfg +++ b/cfg/supervision.cfg @@ -20,7 +20,7 @@ SEGMENTS { RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM, run = RAM, type = rw, define = yes; FFF0: load = ROM, type = ro, offset = $7FF0; - VECTOR: load = ROM, type = ro, offset = $7FFA; + VECTORS: load = ROM, type = ro, start = $7FFA; BSS: load = RAM, type = bss, define = yes; } FEATURES { From a538188d90239235600e76ceb62bd55343a114d0 Mon Sep 17 00:00:00 2001 From: Polluks Date: Thu, 26 Nov 2020 12:48:58 +0100 Subject: [PATCH 061/122] Fixed some config mistakes --- cfg/supervision-128k.cfg | 6 +++--- cfg/supervision-16k.cfg | 2 +- cfg/supervision-64k.cfg | 6 +++--- cfg/supervision.cfg | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cfg/supervision-128k.cfg b/cfg/supervision-128k.cfg index 3d7a9efd0..535e93c1d 100644 --- a/cfg/supervision-128k.cfg +++ b/cfg/supervision-128k.cfg @@ -30,8 +30,8 @@ SEGMENTS { BANK5: load = BANKROM5, type = ro; BANK6: load = BANKROM6, type = ro; BANK7: load = BANKROM7, type = ro; - ZEROPAGE: load = RAM, type = bss, define = yes; - DATA: load = RAM, type = bss, define = yes, offset = $0200; + ZEROPAGE: load = RAM, type = zp, define = yes; + DATA: load = RAM, type = rw, define = yes, offset = $0200; BSS: load = RAM, type = bss, define = yes; - VECTORS: load = ROM, type = ro, start = $3FFA; + VECTORS: load = ROM, type = ro, start = $FFFA; } diff --git a/cfg/supervision-16k.cfg b/cfg/supervision-16k.cfg index 4a431621f..0a9bdf0f9 100644 --- a/cfg/supervision-16k.cfg +++ b/cfg/supervision-16k.cfg @@ -21,7 +21,7 @@ SEGMENTS { RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM, run = RAM, type = rw, define = yes; FFF0: load = ROM, type = ro, offset = $3FF0; - VECTORS: load = ROM, type = ro, start = $3FFA; + VECTORS: load = ROM, type = ro, start = $FFFA; BSS: load = RAM, type = bss, define = yes; } FEATURES { diff --git a/cfg/supervision-64k.cfg b/cfg/supervision-64k.cfg index e0cb68a6f..404ece6fc 100644 --- a/cfg/supervision-64k.cfg +++ b/cfg/supervision-64k.cfg @@ -23,8 +23,8 @@ SEGMENTS { BANK1: load = BANKROM1, type = ro; BANK2: load = BANKROM2, type = ro; BANK3: load = BANKROM3, type = ro; - ZEROPAGE: load = RAM, type = bss, define = yes; - DATA: load = RAM, type = bss, define = yes, offset = $0200; + ZEROPAGE: load = RAM, type = zp, define = yes; + DATA: load = RAM, type = rw, define = yes, offset = $0200; BSS: load = RAM, type = bss, define = yes; - VECTORS: load = ROM, type = ro, start = $3FFA; + VECTORS: load = ROM, type = ro, start = $FFFA; } diff --git a/cfg/supervision.cfg b/cfg/supervision.cfg index 4ec3e49c7..1a745234f 100644 --- a/cfg/supervision.cfg +++ b/cfg/supervision.cfg @@ -20,7 +20,7 @@ SEGMENTS { RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM, run = RAM, type = rw, define = yes; FFF0: load = ROM, type = ro, offset = $7FF0; - VECTORS: load = ROM, type = ro, start = $7FFA; + VECTORS: load = ROM, type = ro, start = $FFFA; BSS: load = RAM, type = bss, define = yes; } FEATURES { From c663f64542d49cd5000aa01c41cc151b442f065a Mon Sep 17 00:00:00 2001 From: Polluks Date: Fri, 27 Nov 2020 15:05:07 +0100 Subject: [PATCH 062/122] Added features; changed FFF0 segments --- cfg/supervision-128k.cfg | 17 ++++++++++++++++- cfg/supervision-16k.cfg | 2 +- cfg/supervision-64k.cfg | 15 +++++++++++++++ cfg/supervision.cfg | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/cfg/supervision-128k.cfg b/cfg/supervision-128k.cfg index 535e93c1d..c90367aa1 100644 --- a/cfg/supervision-128k.cfg +++ b/cfg/supervision-128k.cfg @@ -1,4 +1,4 @@ -# supervision 1284kbyte cartridge with bankswitching +# supervision 128kbyte cartridge with bankswitching # for assembler # ld65 config file @@ -35,3 +35,18 @@ SEGMENTS { BSS: load = RAM, type = bss, define = yes; VECTORS: load = ROM, type = ro, start = $FFFA; } +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} diff --git a/cfg/supervision-16k.cfg b/cfg/supervision-16k.cfg index 0a9bdf0f9..dc6130b33 100644 --- a/cfg/supervision-16k.cfg +++ b/cfg/supervision-16k.cfg @@ -20,7 +20,7 @@ SEGMENTS { CODE: load = ROM, type = ro, define = yes; RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM, run = RAM, type = rw, define = yes; - FFF0: load = ROM, type = ro, offset = $3FF0; + FFF0: load = ROM, type = ro, start = $FFF0; VECTORS: load = ROM, type = ro, start = $FFFA; BSS: load = RAM, type = bss, define = yes; } diff --git a/cfg/supervision-64k.cfg b/cfg/supervision-64k.cfg index 404ece6fc..d252c5d25 100644 --- a/cfg/supervision-64k.cfg +++ b/cfg/supervision-64k.cfg @@ -28,3 +28,18 @@ SEGMENTS { BSS: load = RAM, type = bss, define = yes; VECTORS: load = ROM, type = ro, start = $FFFA; } +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} diff --git a/cfg/supervision.cfg b/cfg/supervision.cfg index 1a745234f..1177660b8 100644 --- a/cfg/supervision.cfg +++ b/cfg/supervision.cfg @@ -19,7 +19,7 @@ SEGMENTS { CODE: load = ROM, type = ro, define = yes; RODATA: load = ROM, type = ro, define = yes; DATA: load = ROM, run = RAM, type = rw, define = yes; - FFF0: load = ROM, type = ro, offset = $7FF0; + FFF0: load = ROM, type = ro, start = $FFF0; VECTORS: load = ROM, type = ro, start = $FFFA; BSS: load = RAM, type = bss, define = yes; } From 2646c06f61b46ed142bbefc723acb8c2113a23f9 Mon Sep 17 00:00:00 2001 From: Tim Gates Date: Sun, 29 Nov 2020 18:23:52 +1100 Subject: [PATCH 063/122] docs: fix simple typo, paramater -> parameter There is a small typo in src/cc65/pragma.c. Should read `parameter` rather than `paramater`. --- src/cc65/pragma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index cf463a832..1ea86545d 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -677,7 +677,7 @@ static void WarnPragma (StrBuf* B) static void FlagPragma (StrBuf* B, IntStack* Stack) -/* Handle a pragma that expects a boolean paramater */ +/* Handle a pragma that expects a boolean parameter */ { StrBuf Ident = AUTO_STRBUF_INITIALIZER; long Val; @@ -727,7 +727,7 @@ ExitPoint: static void IntPragma (StrBuf* B, IntStack* Stack, long Low, long High) -/* Handle a pragma that expects an int paramater */ +/* Handle a pragma that expects an int parameter */ { long Val; int Push; From 95635418707e5a6ed270a341c02a743751631099 Mon Sep 17 00:00:00 2001 From: Polluks Date: Sun, 29 Nov 2020 17:10:34 +0100 Subject: [PATCH 064/122] crt0 clean-up --- libsrc/atari5200/crt0.s | 1 - libsrc/c16/crt0.s | 1 - libsrc/c64/crt0.s | 1 - libsrc/pet/crt0.s | 1 - libsrc/plus4/crt0.s | 2 -- libsrc/supervision/crt0.s | 2 -- libsrc/telestrat/crt0.s | 1 - libsrc/vic20/crt0.s | 1 - 8 files changed, 10 deletions(-) diff --git a/libsrc/atari5200/crt0.s b/libsrc/atari5200/crt0.s index ee3d0de4f..9538d3bb4 100644 --- a/libsrc/atari5200/crt0.s +++ b/libsrc/atari5200/crt0.s @@ -13,7 +13,6 @@ .import zerobss, copydata .include "zeropage.inc" - .include "atari5200.inc" start: diff --git a/libsrc/c16/crt0.s b/libsrc/c16/crt0.s index bee81a113..1df1e5c62 100644 --- a/libsrc/c16/crt0.s +++ b/libsrc/c16/crt0.s @@ -13,7 +13,6 @@ .importzp ST .include "zeropage.inc" - .include "plus4.inc" ; ------------------------------------------------------------------------ ; Startup code diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 7bd294ca7..4e5c7c9d4 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -13,7 +13,6 @@ .importzp ST .include "zeropage.inc" - .include "c64.inc" ; ------------------------------------------------------------------------ diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index 520a147f7..e56a7eca4 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -12,7 +12,6 @@ .include "zeropage.inc" .include "pet.inc" - .include "../cbm/cbm.inc" ; ------------------------------------------------------------------------ ; Startup code diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index 2262b4c42..6b44a2b7e 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -198,5 +198,3 @@ irqcount: .byte 0 .segment "INIT" zpsave: .res zpspace - - diff --git a/libsrc/supervision/crt0.s b/libsrc/supervision/crt0.s index ac61c8215..203c681b8 100644 --- a/libsrc/supervision/crt0.s +++ b/libsrc/supervision/crt0.s @@ -78,5 +78,3 @@ not_dma: .word nmi .word reset32kcode .word irq - - diff --git a/libsrc/telestrat/crt0.s b/libsrc/telestrat/crt0.s index 59b1ea642..df75520ce 100644 --- a/libsrc/telestrat/crt0.s +++ b/libsrc/telestrat/crt0.s @@ -12,7 +12,6 @@ .import __MAIN_START__, __MAIN_SIZE__ .include "zeropage.inc" - .include "telestrat.inc" ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. diff --git a/libsrc/vic20/crt0.s b/libsrc/vic20/crt0.s index 68ab3ed12..c5486063b 100644 --- a/libsrc/vic20/crt0.s +++ b/libsrc/vic20/crt0.s @@ -13,7 +13,6 @@ .importzp ST .include "zeropage.inc" - .include "vic20.inc" ; ------------------------------------------------------------------------ ; Startup code From b22d8c7441d29657fa772cd4da08b2ca5dd61946 Mon Sep 17 00:00:00 2001 From: Olli Savia Date: Sat, 28 Nov 2020 13:03:48 +0200 Subject: [PATCH 065/122] Added STATUS (0) definition --- asminc/c128.inc | 1 + asminc/c64.inc | 1 + asminc/plus4.inc | 1 + asminc/vic20.inc | 1 + 4 files changed, 4 insertions(+) diff --git a/asminc/c128.inc b/asminc/c128.inc index 2852631f3..749b4168c 100644 --- a/asminc/c128.inc +++ b/asminc/c128.inc @@ -7,6 +7,7 @@ ; Zero page, Commodore stuff TXTPTR := $3D ; Pointer into BASIC source code +STATUS := $90 ; Kernal I/O completion status TIME := $A0 ; 60HZ clock FNAM_LEN := $B7 ; Length of filename SECADR := $B9 ; Secondary address diff --git a/asminc/c64.inc b/asminc/c64.inc index 1d10f673d..2cfc50db4 100644 --- a/asminc/c64.inc +++ b/asminc/c64.inc @@ -9,6 +9,7 @@ VARTAB := $2D ; Pointer to start of BASIC variables MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $7A ; Pointer into BASIC source code +STATUS := $90 ; Kernal I/O completion status TIME := $A0 ; 60 HZ clock FNAM_LEN := $B7 ; Length of filename SECADR := $B9 ; Secondary address diff --git a/asminc/plus4.inc b/asminc/plus4.inc index 774722e93..6c6017a78 100644 --- a/asminc/plus4.inc +++ b/asminc/plus4.inc @@ -10,6 +10,7 @@ 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 +STATUS := $90 ; Kernal I/O completion status TIME := $A3 ; 60HZ clock FNAM_LEN := $AB ; Length of filename LFN := $AC ; Logical file number diff --git a/asminc/vic20.inc b/asminc/vic20.inc index b82874f56..fa9fdfa8d 100644 --- a/asminc/vic20.inc +++ b/asminc/vic20.inc @@ -9,6 +9,7 @@ VARTAB := $2D ; Pointer to start of BASIC variables MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $7A ; Pointer into BASIC source code +STATUS := $90 ; Kernal I/O completion status TIME := $A0 ; 60HZ clock FNAM_LEN := $B7 ; Length of filename SECADR := $B9 ; Secondary address From 59c58acbe3229a4e860981e97d3d5f3a23adf2bc Mon Sep 17 00:00:00 2001 From: Greg King Date: Sat, 5 Dec 2020 23:04:48 -0500 Subject: [PATCH 066/122] Documented the address size argument of the bss-name, code-name, data-name, and rodata-name pragmas. --- doc/cc65.sgml | 143 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 47 deletions(-) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index 115f0a30c..e273ced9c 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -6,8 +6,9 @@ -cc65 is a C compiler for 6502 targets. It supports several 6502 based home -computers like the Commodore and Atari machines, but it is easily retargetable. +cc65 is a C compiler for 6502 targets. It supports several 6502-based home +computers such as the Commodore and Atari machines, but it easily is +retargetable. @@ -1011,7 +1012,7 @@ The compiler defines several macros at startup: __TELESTRAT__ This macro is defined if the target is the Telestrat (-t telestrat). - + __TIME__ This macro expands to the time of translation of the preprocessing @@ -1045,26 +1046,39 @@ parameter with the #pragma bss-name ([push,] <name>)

+#pragma bss-name ([push, ]<name>[ ,<addrsize>])

- This pragma changes the name used for the BSS segment (the BSS segment - is used to store variables with static storage duration and no explicit - initializer). The argument is a string enclosed in double quotes. + This pragma changes the name used for the BSS segment (the BSS segment is + used to store variables with static storage duration and no explicit + initializers). The + "zp", "zeropage", "direct" + "abs", "absolute", "near", "default" + "far" + "long", "dword" + - Beware: The startup code will zero only the default BSS segment. If you - use another BSS segment, you have to do that yourself, otherwise - variables with static storage duration and no explicit initializer will - not have the value zero. + Note: The default linker configuration file maps only the standard segments. + If you use other segments, you must create a new linker configuration file. - The - #pragma bss-name ("MyBSS") + #pragma bss-name ("MyBSS") + #pragma bss-name (push, "MyBSS") + #pragma bss-name ("MyBSS", "zp") @@ -1120,21 +1134,33 @@ parameter with the #pragma code-name ([push,] <name>)

+#pragma code-name ([push, ]<name>[ ,<addrsize>])

- This pragma changes the name used for the CODE segment (the CODE segment - is used to store executable code). The argument is a string enclosed in - double quotes. + This pragma changes the name used for the CODE segment (the CODE segment is + used to store executable code). The + "zp", "zeropage", "direct" + "abs", "absolute", "near", "default" + "far" + "long", "dword" + - The - #pragma code-name ("MyCODE") + #pragma code-name ("MyCODE") + #pragma code-name (push, "MyCODE") + #pragma code-name (push, "MyCODE", "far") @@ -1148,21 +1174,33 @@ parameter with the #pragma data-name ([push,] <name>)

+#pragma data-name ([push, ]<name>[ ,<addrsize>])

- This pragma changes the name used for the DATA segment (the DATA segment - is used to store initialized data). The argument is a string enclosed in - double quotes. + This pragma changes the name used for the DATA segment (the DATA segment is + used to store initialized data). The + "zp", "zeropage", "direct" + "abs", "absolute", "near", "default" + "far" + "long", "dword" + - The - #pragma data-name ("MyDATA") + #pragma data-name ("MyDATA") + #pragma data-name (push, "MyDATA") + #pragma data-name ("MyDATA", "zeropage") @@ -1224,21 +1262,32 @@ parameter with the #pragma rodata-name ([push,] <name>)

+#pragma rodata-name ([push, ]<name>[ ,<addrsize>])

- This pragma changes the name used for the RODATA segment (the RODATA - segment is used to store readonly data). The argument is a string - enclosed in double quotes. + This pragma changes the name used for the RODATA segment (the RODATA segment + is used to store read-only data). The + "zp", "zeropage", "direct" + "abs", "absolute", "near", "default" + "far" + "long", "dword" + - The - #pragma rodata-name ("MyRODATA") + #pragma rodata-name ("MyRODATA") + #pragma rodata-name (push, "MyRODATA") From 0f4cb443b4d34dfceef35c0f9b31abcf69d00c67 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 19 Dec 2020 19:54:12 +0100 Subject: [PATCH 067/122] Improved device I/O under DOS 3.3 Certain scenarios (e.g. not running any Applesoft program at all since booting DOS 3.3) can make DOS 3.3 consider cc65 device input (e.g. getchar()) that reads a CR interpreting the command in the keyboard buffer. Setting the hibyte of the Applesoft currently executed line number to some value <> $FF (beside setting the input prompt to some value <> ']') makes DOS 3.3 understand that we're not in intermediate mode and that therefore I/O not preceded with ctrl-d mustn't be fiddled with (see DOS 3.3 routine at $A65E). --- asminc/apple2.inc | 1 + libsrc/apple2/read.s | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/asminc/apple2.inc b/asminc/apple2.inc index 5ebf73164..528c463a1 100644 --- a/asminc/apple2.inc +++ b/asminc/apple2.inc @@ -15,6 +15,7 @@ PROMPT := $33 ; Used by GETLN RNDL := $4E ; Random counter low RNDH := $4F ; Random counter high HIMEM := $73 ; Highest available memory address+1 +CURLIN := $75 ; Current line number being executed ;----------------------------------------------------------------------------- ; Vectors diff --git a/libsrc/apple2/read.s b/libsrc/apple2/read.s index 14c80b7e2..99c189cbd 100644 --- a/libsrc/apple2/read.s +++ b/libsrc/apple2/read.s @@ -19,11 +19,14 @@ .segment "ONCE" initprompt: - ; Set prompt <> ']' to let DOS 3.3 know that we're - ; not in Applesoft immediate mode and thus keep it - ; from scanning our device I/O for DOS commands. + ; Set prompt <> ']' and currently executed Applesoft + ; line number hibyte <> $FF to let DOS 3.3 (at $A65E) + ; know that we're not in Applesoft immediate mode and + ; thus keep it from scanning our device I/O for DOS + ; commands. lda #$80 ; Same value used at $D52C sta PROMPT + sta CURLIN+1 ; Any value <> $FF will do rts .code From b2c1a77bb389bf20b5043f796f2dee496c07fdbd Mon Sep 17 00:00:00 2001 From: Greg King Date: Thu, 24 Dec 2020 12:27:09 -0500 Subject: [PATCH 068/122] Fixed the cc65 code that optimizes 16-bit compares when the high bytes are known to be equal. Only the low bytes are compared. Originally, signed 16-bit compares were optimized into signed 8-bit compares. But, the sign bits are in the high bytes; and, they're equal. Therefore, the low bytes always must be compared as unsigned numbers. Fixes #1348. --- src/cc65/coptstop.c | 78 +++++++++++------------------------- test/misc/Makefile | 8 ---- test/{misc => val}/bug1348.c | 28 ++++++------- 3 files changed, 37 insertions(+), 77 deletions(-) rename test/{misc => val}/bug1348.c (61%) diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index 59bbe6dc9..77b79281b 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -287,7 +287,7 @@ static unsigned Opt_tosshift (StackOpData* D, const char* Name) /* ldx */ X = NewCodeEntry (OP65_LDX, LoadX->AM, LoadX->Arg, 0, D->OpEntry->LI); InsertEntry (D, X, D->IP++); - + /* Lhs load entries can be removed if not used later */ D->Lhs.X.Flags |= LI_REMOVE; D->Lhs.A.Flags |= LI_REMOVE; @@ -1100,7 +1100,7 @@ static unsigned Opt_tosxorax (StackOpData* D) static unsigned Opt_a_toscmpbool (StackOpData* D, const char* BoolTransformer) -/* Optimize the tos compare sequence with a bool transformer */ +/* Optimize the TOS compare sequence with a bool transformer */ { CodeEntry* X; cmp_t Cond; @@ -1119,9 +1119,8 @@ static unsigned Opt_a_toscmpbool (StackOpData* D, const char* BoolTransformer) D->Rhs.A.Flags |= LI_REMOVE; } else if ((D->Lhs.A.Flags & LI_DIRECT) != 0) { - - /* If the lhs is direct (but not stack relative), encode compares with lhs - ** effectively reverting the order (which doesn't matter for ==). + /* If the lhs is direct (but not stack relative), encode compares with lhs, + ** effectively reversing the order (which doesn't matter for == and !=). */ Cond = FindBoolCmpCond (BoolTransformer); Cond = GetRevertedCond (Cond); @@ -1138,7 +1137,6 @@ static unsigned Opt_a_toscmpbool (StackOpData* D, const char* BoolTransformer) D->Lhs.A.Flags |= LI_REMOVE; } else { - /* We'll do reverse-compare */ Cond = FindBoolCmpCond (BoolTransformer); Cond = GetRevertedCond (Cond); @@ -1162,7 +1160,7 @@ static unsigned Opt_a_toscmpbool (StackOpData* D, const char* BoolTransformer) X = NewCodeEntry (OP65_JSR, AM65_ABS, BoolTransformer, 0, D->OpEntry->LI); InsertEntry (D, X, D->IP++); - /* Remove the push and the call to the tosgeax function */ + /* Remove the push and the call to the TOS function */ RemoveRemainders (D); /* We changed the sequence */ @@ -1179,22 +1177,6 @@ static unsigned Opt_a_toseq (StackOpData* D) -static unsigned Opt_a_tosge (StackOpData* D) -/* Optimize the tosgeax sequence */ -{ - return Opt_a_toscmpbool (D, "boolge"); -} - - - -static unsigned Opt_a_tosgt (StackOpData* D) -/* Optimize the tosgtax sequence */ -{ - return Opt_a_toscmpbool (D, "boolgt"); -} - - - static unsigned Opt_a_tosicmp (StackOpData* D) /* Replace tosicmp with CMP */ { @@ -1236,7 +1218,7 @@ static unsigned Opt_a_tosicmp (StackOpData* D) } InsertEntry (D, X, D->IP++); - /* cmp src,y OR cmp (sp),y*/ + /* cmp src,y OR cmp (sp),y */ if (D->Rhs.A.LoadEntry->OPC == OP65_JSR) { /* opc (sp),y */ X = NewCodeEntry (OP65_CMP, AM65_ZP_INDY, "sp", 0, D->OpEntry->LI); @@ -1268,18 +1250,18 @@ static unsigned Opt_a_tosicmp (StackOpData* D) InsertEntry (D, X, D->IP-3); } else { - /* Just clear A,Z,N and set C */ + /* Just clear A,Z,N; and set C */ + Arg = MakeHexArg (0); if ((RI = GetLastChangedRegInfo (D, &D->Lhs.A)) != 0 && RegValIsKnown (RI->Out.RegA) && (RI->Out.RegA & 0xFF) == 0) { - Arg = MakeHexArg (0); - X = NewCodeEntry (OP65_CMP, AM65_IMM, Arg, 0, D->OpEntry->LI); + + X = NewCodeEntry (OP65_CMP, AM65_IMM, Arg, 0, D->OpEntry->LI); InsertEntry (D, X, D->OpIndex + 1); } else { - Arg = MakeHexArg (0); - X = NewCodeEntry (OP65_LDA, AM65_IMM, Arg, 0, D->OpEntry->LI); + X = NewCodeEntry (OP65_LDA, AM65_IMM, Arg, 0, D->OpEntry->LI); InsertEntry (D, X, D->OpIndex + 1); - X = NewCodeEntry (OP65_CMP, AM65_IMM, Arg, 0, D->OpEntry->LI); + X = NewCodeEntry (OP65_CMP, AM65_IMM, Arg, 0, D->OpEntry->LI); InsertEntry (D, X, D->OpIndex + 2); } } @@ -1292,24 +1274,8 @@ static unsigned Opt_a_tosicmp (StackOpData* D) -static unsigned Opt_a_tosle (StackOpData* D) -/* Optimize the tosleax sequence */ -{ - return Opt_a_toscmpbool (D, "boolle"); -} - - - -static unsigned Opt_a_toslt (StackOpData* D) -/* Optimize the tosltax sequence */ -{ - return Opt_a_toscmpbool (D, "boollt"); -} - - - static unsigned Opt_a_tosne (StackOpData* D) -/* Optimize the toseqax sequence */ +/* Optimize the tosneax sequence */ { return Opt_a_toscmpbool (D, "boolne"); } @@ -1317,7 +1283,7 @@ static unsigned Opt_a_tosne (StackOpData* D) static unsigned Opt_a_tosuge (StackOpData* D) -/* Optimize the tosugeax sequence */ +/* Optimize the tosgeax and tosugeax sequences */ { return Opt_a_toscmpbool (D, "booluge"); } @@ -1325,7 +1291,7 @@ static unsigned Opt_a_tosuge (StackOpData* D) static unsigned Opt_a_tosugt (StackOpData* D) -/* Optimize the tosugtax sequence */ +/* Optimize the tosgtax and tosugtax sequences */ { return Opt_a_toscmpbool (D, "boolugt"); } @@ -1333,7 +1299,7 @@ static unsigned Opt_a_tosugt (StackOpData* D) static unsigned Opt_a_tosule (StackOpData* D) -/* Optimize the tosuleax sequence */ +/* Optimize the tosleax and tosuleax sequences */ { return Opt_a_toscmpbool (D, "boolule"); } @@ -1341,7 +1307,7 @@ static unsigned Opt_a_tosule (StackOpData* D) static unsigned Opt_a_tosult (StackOpData* D) -/* Optimize the tosultax sequence */ +/* Optimize the tosltax and tosultax sequences */ { return Opt_a_toscmpbool (D, "boolult"); } @@ -1354,6 +1320,8 @@ static unsigned Opt_a_tosult (StackOpData* D) +/* The first column of these two tables must be sorted in lexical order */ + static const OptFuncDesc FuncTable[] = { { "__bzero", Opt___bzero, REG_NONE, OP_X_ZERO | OP_A_KNOWN }, { "staspidx", Opt_staspidx, REG_NONE, OP_NONE }, @@ -1379,11 +1347,11 @@ static const OptFuncDesc FuncTable[] = { static const OptFuncDesc FuncRegATable[] = { { "toseqax", Opt_a_toseq, REG_NONE, OP_NONE }, - { "tosgeax", Opt_a_tosge, REG_NONE, OP_NONE }, - { "tosgtax", Opt_a_tosgt, REG_NONE, OP_NONE }, + { "tosgeax", Opt_a_tosuge, REG_NONE, OP_NONE }, + { "tosgtax", Opt_a_tosugt, REG_NONE, OP_NONE }, { "tosicmp", Opt_a_tosicmp, REG_NONE, OP_NONE }, - { "tosleax", Opt_a_tosle, REG_NONE, OP_NONE }, - { "tosltax", Opt_a_toslt, REG_NONE, OP_NONE }, + { "tosleax", Opt_a_tosule, REG_NONE, OP_NONE }, + { "tosltax", Opt_a_tosult, REG_NONE, OP_NONE }, { "tosneax", Opt_a_tosne, REG_NONE, OP_NONE }, { "tosugeax", Opt_a_tosuge, REG_NONE, OP_NONE }, { "tosugtax", Opt_a_tosugt, REG_NONE, OP_NONE }, diff --git a/test/misc/Makefile b/test/misc/Makefile index ad31e8554..81a09c693 100644 --- a/test/misc/Makefile +++ b/test/misc/Makefile @@ -117,14 +117,6 @@ $(WORKDIR)/endless.$1.$2.prg: endless.c | $(WORKDIR) $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) -# this one fails when optimization are enabled -$(WORKDIR)/bug1348.$1.$2.prg: bug1348.c | $(WORKDIR) - $(if $(QUIET),echo misc/bug1348.$1.$2.prg) - $(CC65) -Osr -t sim$2 -$1 -o $$(@:.prg=.s) $$< $(NULLERR) - $(CA65) -t sim$2 -o $$(@:.prg=.o) $$(@:.prg=.s) $(NULLERR) - $(LD65) -t sim$2 -o $$@ $$(@:.prg=.o) sim$2.lib $(NULLERR) - $(NOT) $(SIM65) $(SIM65FLAGS) $$@ $(NULLOUT) $(NULLERR) - # these need reference data that can't be generated by a host-compiled program, # in a useful way $(WORKDIR)/limits.$1.$2.prg: limits.c $(ISEQUAL) | $(WORKDIR) diff --git a/test/misc/bug1348.c b/test/val/bug1348.c similarity index 61% rename from test/misc/bug1348.c rename to test/val/bug1348.c index 913849482..c40d9ac84 100644 --- a/test/misc/bug1348.c +++ b/test/val/bug1348.c @@ -1,27 +1,26 @@ - -/* bug#1348, wrongly optimized integer promotion in comparison */ +/* bug #1348, wrongly optimized integer promotion in comparison */ #include -int notrandtab[] = { +static const int notrandtab[] = { 0xffff, 0x7fff, 0x3fff, 0x1fff, 0x0fff, 0x07ff, 0x03ff, 0x01ff, 0x00ff, 0x007f, 0x003f, 0x001f, 0x000f, 0x0007, 0x0003, 0x0001 }; -unsigned char notrandcount = 0; +static unsigned char notrandcount = 0; -int notrand(void) +static int notrand(void) { return notrandtab[notrandcount & 0x0f]; } -unsigned char n1, n2; -unsigned char i, ii, s; -unsigned char err = 0; +static unsigned char n1, n2; +static unsigned char i, ii, s; +static unsigned char err = 0; -unsigned char cmptab[] = { +static const unsigned char cmptab[] = { 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x80, 0x40, 0x20, 0x10, @@ -40,13 +39,14 @@ int main(void) if ((notrand() & 0xffu) > s) { n2 = 1; } - printf("%5d>%3d %d(%02x) %d(%02x) %s\n", - notrandtab[notrandcount & 0x0f], s, + printf("%5d > %3d %u(%02x) %u(%02x) %s\n", + notrandtab[i], s, n1, (notrand() & 0xff), n2, (notrand() & 0xffu), - n1 == n2 ? "=" : "!=" - ); - if (n1 != n2) err = 1; + n1 == n2 ? "=" : "!="); + if (n1 != n2) { + err = 1; + } notrandcount++; } } From dfd047ce6a693a2bc32a8778b06bd08c3d39aa0b Mon Sep 17 00:00:00 2001 From: Jesse Rosenstock Date: Fri, 13 Nov 2020 09:01:26 +0100 Subject: [PATCH 069/122] g_typeadjust: Use CF_CHAR for char args If lhs and rhs are either both signed char or both unsigned char, return flags for that type instead of (unsigned) int. The flags are used only for codegen. Currently, this does nothing, since codegen treats chars as ints unless CF_FORCECHAR is set, but it allows more efficient char x char -> int codegen to be added in the future. --- src/cc65/codegen.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index f56abcd95..a58484cf1 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -1433,17 +1433,20 @@ unsigned g_typeadjust (unsigned lhs, unsigned rhs) /* Note that this logic is largely duplicated by ArithmeticConvert. */ - /* Before we apply the integral promotions, we check if both types are unsigned char. - ** If so, we return unsigned int, rather than int, which would be returned by the standard - ** rules. This is only a performance optimization and does not affect correctness, as - ** the flags are only used for code generation, and not to determine types of other - ** expressions containing this one. All unsigned char bit-patterns are valid as both int - ** and unsigned int and represent the same value, so either signed or unsigned int operations - ** can be used. This special case part is not duplicated by ArithmeticConvert. + /* Before we apply the integral promotions, we check if both types are the same character type. + ** If so, we return that type, rather than int, which would be returned by the standard + ** rules. This is only a performance optimization allowing the use of unsigned and/or char + ** operations; it does not affect correctness, as the flags are only used for code generation, + ** and not to determine types of other expressions containing this one. For codgen, CF_CHAR + ** means the operands are char and the result is int (unless CF_FORCECHAR is also set, in + ** which case the result is char). This special case part is not duplicated by + ** ArithmeticConvert. */ - if ((lhs & CF_TYPEMASK) == CF_CHAR && (lhs & CF_UNSIGNED) && - (rhs & CF_TYPEMASK) == CF_CHAR && (rhs & CF_UNSIGNED)) { - return const_flag | CF_UNSIGNED | CF_INT; + if ((lhs & CF_TYPEMASK) == CF_CHAR && (rhs & CF_TYPEMASK) == CF_CHAR && + (lhs & CF_UNSIGNED) == (rhs & CF_UNSIGNED)) { + /* Signedness flags are the same, so just use one of them. */ + const unsigned unsigned_flag = lhs & CF_UNSIGNED; + return const_flag | unsigned_flag | CF_CHAR; } /* Apply integral promotions for types char/short. */ From 1c72da490479b6876557c3cf75577e7ed55f5e15 Mon Sep 17 00:00:00 2001 From: baktrasf Date: Mon, 21 Dec 2020 21:31:53 +0100 Subject: [PATCH 070/122] Add operating system symbols for the Atari 5200 target --- include/_atari5200os.h | 80 ++++++++++++++++++++++++++++++++++++++++++ include/atari5200.h | 4 +++ 2 files changed, 84 insertions(+) create mode 100644 include/_atari5200os.h diff --git a/include/_atari5200os.h b/include/_atari5200os.h new file mode 100644 index 000000000..77ccf14ed --- /dev/null +++ b/include/_atari5200os.h @@ -0,0 +1,80 @@ +/*****************************************************************************/ +/* */ +/* _atari5200os.h */ +/* */ +/* Internal include file, do not use directly */ +/* */ +/* */ +/* 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 __ATARI5200OS_H +#define __ATARI5200OS_H + + +struct __os { + + /*Page zero*/ + unsigned char pokmsk; // = $00 System mask for POKEY IRQ enable + unsigned char rtclok[2]; // = $01,$02 Real time clock + unsigned char critic; // = $03 Critical section flag + unsigned char atract; // = $04 Attract mode counter + + union { + struct { + unsigned char sdlstl; // = $05 Save display list LO + unsigned char sdlsth; // = $06 Save display list HI + }; + void* sdlst; // = $05,$06 Display list shadow + }; + + unsigned char sdmctl; // = $07 DMACTL shadow + unsigned char pcolr0; // = $08 PM color 0 + unsigned char pcolr1; // = $09 PM color 1 + unsigned char pcolr2; // = $0A PM color 2 + unsigned char pcolr3; // = $0B PM color 3 + unsigned char color0; // = $0C PF Color 0 + unsigned char color1; // = $0D PF Color 1 + unsigned char color2; // = $0E PF Color 2 + unsigned char color3; // = $0F PF Color 3 + unsigned char color4; // = $10 PF Color 4 + unsigned char __filler[0xEF]; // = $11-$FF Filler + + /*Stack*/ + unsigned char stack[0x100]; // = $100-$1FF Stack + + /*Page 2 OS variables*/ + void (*vinter)(void); // = $200 Immediate IRQ vector + void (*vvblki)(void); // = $202 Immediate VBI vector + void (*vvblkd)(void); // = $204 Deferred VBI vector + void (*vdslst)(void); // = $206 DLI vector + void (*vkeybd)(void); // = $208 Keyboard IRQ vector + void (*vkeypd)(void); // = $20A Keypad continue vector + void (*vbrkky)(void); // = $20C Break key interrupt vector + void (*vbreak)(void); // = $20E Break instruction interrupt vector + void (*vserin)(void); // = $210 Serial input ready vector + void (*vseror)(void); // = $212 Serial output data needed vector + void (*vseroc)(void); // = $214 Serial output completed vector + void (*vtimr1)(void); // = $216 POKEY timer 1 IRQ vector + void (*vtimr2)(void); // = $218 POKEY timer 2 IRQ vector + void (*vtimr4)(void); // = $21A POKEY timer 4 IRQ vector + +}; + +#endif \ No newline at end of file diff --git a/include/atari5200.h b/include/atari5200.h index a18360c61..ff176c15b 100644 --- a/include/atari5200.h +++ b/include/atari5200.h @@ -65,6 +65,10 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ #define AT_NTSC 0 #define AT_PAL 1 +/* Define variables used by the OS*/ +#include <_atari5200os.h> +#define OS (*(struct __os*)0x0000) + /* define hardware */ #include <_gtia.h> #define GTIA_READ (*(struct __gtia_read*)0xC000) From 2e9bada1f20b645ea94343adaf03d85da15a1d45 Mon Sep 17 00:00:00 2001 From: baktrasf Date: Wed, 23 Dec 2020 23:35:09 +0100 Subject: [PATCH 071/122] Atari 5200 OS header refinements --- doc/atari5200.sgml | 10 ++++++++++ include/_atari5200os.h | 18 +++++++++--------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/doc/atari5200.sgml b/doc/atari5200.sgml index 032b0ef6c..2ec3d08f0 100644 --- a/doc/atari5200.sgml +++ b/doc/atari5200.sgml @@ -73,7 +73,17 @@ Special locations: Programs containing Atari 5200 specific code may use the +... + OS.sdmctl = 0x00; // screen off + OS.color4 = 14; // white frame +... tics = OS.rtclok[1] // get ticks + + Atari 5200 specific functions

diff --git a/include/_atari5200os.h b/include/_atari5200os.h index 77ccf14ed..db0f7f0c9 100644 --- a/include/_atari5200os.h +++ b/include/_atari5200os.h @@ -49,12 +49,12 @@ struct __os { unsigned char pcolr1; // = $09 PM color 1 unsigned char pcolr2; // = $0A PM color 2 unsigned char pcolr3; // = $0B PM color 3 - unsigned char color0; // = $0C PF Color 0 - unsigned char color1; // = $0D PF Color 1 - unsigned char color2; // = $0E PF Color 2 - unsigned char color3; // = $0F PF Color 3 - unsigned char color4; // = $10 PF Color 4 - unsigned char __filler[0xEF]; // = $11-$FF Filler + unsigned char color0; // = $0C PF color 0 + unsigned char color1; // = $0D PF color 1 + unsigned char color2; // = $0E PF color 2 + unsigned char color3; // = $0F PF color 3 + unsigned char color4; // = $10 PF color 4 + unsigned char _free_1[0xEF]; // = $11-$FF User space /*Stack*/ unsigned char stack[0x100]; // = $100-$1FF Stack @@ -65,9 +65,9 @@ struct __os { void (*vvblkd)(void); // = $204 Deferred VBI vector void (*vdslst)(void); // = $206 DLI vector void (*vkeybd)(void); // = $208 Keyboard IRQ vector - void (*vkeypd)(void); // = $20A Keypad continue vector + void (*vkeypd)(void); // = $20A Keyboard continuation vector void (*vbrkky)(void); // = $20C Break key interrupt vector - void (*vbreak)(void); // = $20E Break instruction interrupt vector + void (*vbreak)(void); // = $20E BRK instruction interrupt vector void (*vserin)(void); // = $210 Serial input ready vector void (*vseror)(void); // = $212 Serial output data needed vector void (*vseroc)(void); // = $214 Serial output completed vector @@ -77,4 +77,4 @@ struct __os { }; -#endif \ No newline at end of file +#endif From d67b955e528d032d287b1bdec450643b0d5a8a6c Mon Sep 17 00:00:00 2001 From: michael Date: Wed, 23 Dec 2020 23:50:10 +0100 Subject: [PATCH 072/122] Fixed example of the OS struct usage for Atari 5200 --- doc/atari5200.sgml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/atari5200.sgml b/doc/atari5200.sgml index 2ec3d08f0..aff212b15 100644 --- a/doc/atari5200.sgml +++ b/doc/atari5200.sgml @@ -81,7 +81,8 @@ The names are the usual ones you can find in system reference manuals. Example: ... OS.sdmctl = 0x00; // screen off OS.color4 = 14; // white frame -... tics = OS.rtclok[1] // get ticks + tics = OS.rtclok[1] // get ticks +... Atari 5200 specific functions

From ef258bdc1913b2bc97011e64affb7925b80c1e5a Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Fri, 25 Dec 2020 07:16:26 +0100 Subject: [PATCH 073/122] remove TABs which again slipped in.... --- src/cc65/expr.h | 8 +- test/val/binlit.c | 1044 ++++++++++++++++++++++---------------------- test/val/bug1071.c | 40 +- test/val/rand.c | 134 +++--- 4 files changed, 613 insertions(+), 613 deletions(-) diff --git a/src/cc65/expr.h b/src/cc65/expr.h index d0a9988af..71dbe8e0d 100644 --- a/src/cc65/expr.h +++ b/src/cc65/expr.h @@ -23,10 +23,10 @@ -#define SQP_KEEP_NONE 0x00 -#define SQP_KEEP_TEST 0x01U -#define SQP_KEEP_EAX 0x02U -#define SQP_KEEP_EXPR 0x03U /* SQP_KEEP_TEST | SQP_KEEP_EAX */ +#define SQP_KEEP_NONE 0x00 +#define SQP_KEEP_TEST 0x01U +#define SQP_KEEP_EAX 0x02U +#define SQP_KEEP_EXPR 0x03U /* SQP_KEEP_TEST | SQP_KEEP_EAX */ diff --git a/test/val/binlit.c b/test/val/binlit.c index 47e7a196e..f89ca60fc 100644 --- a/test/val/binlit.c +++ b/test/val/binlit.c @@ -3,531 +3,531 @@ static unsigned big[256]; int main() { - unsigned i; + unsigned i; - small[0] = 0b0; - small[1] = 0b1; - small[2] = 0b10; - small[3] = 0b11; - small[4] = 0b100; - small[5] = 0b101; - small[6] = 0b110; - small[7] = 0b000111; - small[8] = 0b1000; - small[9] = 0b1001; - small[10] = 0b0001010; - small[11] = 0b0001011; - small[12] = 0b1100; - small[13] = 0b1101; - small[14] = 0b1110; - small[15] = 0b1111; - small[16] = 0b10000; - small[17] = 0b10001; - small[18] = 0b00010010; - small[19] = 0b00010011; - small[20] = 0b00010100; - small[21] = 0b00010101; - small[22] = 0b10110; - small[23] = 0b10111; - small[24] = 0b11000; - small[25] = 0b11001; - small[26] = 0b11010; - small[27] = 0b11011; - small[28] = 0b11100; - small[29] = 0b11101; - small[30] = 0b11110; - small[31] = 0b11111; - small[32] = 0b00000000100000; - small[33] = 0b00000000100001; - small[34] = 0b100010; - small[35] = 0b100011; - small[36] = 0b100100; - small[37] = 0b100101; - small[38] = 0b100110; - small[39] = 0b100111; - small[40] = 0b101000; - small[41] = 0b101001; - small[42] = 0b101010; - small[43] = 0b101011; - small[44] = 0b101100; - small[45] = 0b101101; - small[46] = 0b101110; - small[47] = 0b101111; - small[48] = 0b110000; - small[49] = 0b110001; - small[50] = 0b110010; - small[51] = 0b110011; - small[52] = 0b110100; - small[53] = 0b110101; - small[54] = 0b110110; - small[55] = 0b110111; - small[56] = 0b111000; - small[57] = 0b111001; - small[58] = 0b111010; - small[59] = 0b111011; - small[60] = 0b111100; - small[61] = 0b111101; - small[62] = 0b111110; - small[63] = 0b111111; - small[64] = 0b1000000; - small[65] = 0b1000001; - small[66] = 0b1000010; - small[67] = 0b1000011; - small[68] = 0b1000100; - small[69] = 0b1000101; - small[70] = 0b1000110; - small[71] = 0b1000111; - small[72] = 0b1001000; - small[73] = 0b1001001; - small[74] = 0b1001010; - small[75] = 0b1001011; - small[76] = 0b1001100; - small[77] = 0b1001101; - small[78] = 0b1001110; - small[79] = 0b1001111; - small[80] = 0b1010000; - small[81] = 0b1010001; - small[82] = 0b1010010; - small[83] = 0b1010011; - small[84] = 0b1010100; - small[85] = 0b1010101; - small[86] = 0b1010110; - small[87] = 0b1010111; - small[88] = 0b1011000; - small[89] = 0b1011001; - small[90] = 0b1011010; - small[91] = 0b1011011; - small[92] = 0b1011100; - small[93] = 0b1011101; - small[94] = 0b1011110; - small[95] = 0b1011111; - small[96] = 0b1100000; - small[97] = 0b1100001; - small[98] = 0b1100010; - small[99] = 0b1100011; - small[100] = 0b1100100; - small[101] = 0b1100101; - small[102] = 0b1100110; - small[103] = 0b1100111; - small[104] = 0b1101000; - small[105] = 0b1101001; - small[106] = 0b1101010; - small[107] = 0b1101011; - small[108] = 0b1101100; - small[109] = 0b1101101; - small[110] = 0b1101110; - small[111] = 0b1101111; - small[112] = 0b1110000; - small[113] = 0b1110001; - small[114] = 0b1110010; - small[115] = 0b1110011; - small[116] = 0b1110100; - small[117] = 0b1110101; - small[118] = 0b1110110; - small[119] = 0b1110111; - small[120] = 0b1111000; - small[121] = 0b1111001; - small[122] = 0b1111010; - small[123] = 0b1111011; - small[124] = 0b1111100; - small[125] = 0b1111101; - small[126] = 0b1111110; - small[127] = 0b1111111; - small[128] = 0b10000000; - small[129] = 0b10000001; - small[130] = 0b10000010; - small[131] = 0b10000011; - small[132] = 0b10000100; - small[133] = 0b10000101; - small[134] = 0b10000110; - small[135] = 0b10000111; - small[136] = 0b10001000; - small[137] = 0b10001001; - small[138] = 0b10001010; - small[139] = 0b10001011; - small[140] = 0b10001100; - small[141] = 0b10001101; - small[142] = 0b10001110; - small[143] = 0b10001111; - small[144] = 0b10010000; - small[145] = 0b10010001; - small[146] = 0b10010010; - small[147] = 0b10010011; - small[148] = 0b10010100; - small[149] = 0b10010101; - small[150] = 0b10010110; - small[151] = 0b10010111; - small[152] = 0b10011000; - small[153] = 0b10011001; - small[154] = 0b10011010; - small[155] = 0b10011011; - small[156] = 0b10011100; - small[157] = 0b10011101; - small[158] = 0b10011110; - small[159] = 0b10011111; - small[160] = 0b10100000; - small[161] = 0b10100001; - small[162] = 0b10100010; - small[163] = 0b10100011; - small[164] = 0b10100100; - small[165] = 0b10100101; - small[166] = 0b10100110; - small[167] = 0b10100111; - small[168] = 0b10101000; - small[169] = 0b10101001; - small[170] = 0b10101010; - small[171] = 0b10101011; - small[172] = 0b10101100; - small[173] = 0b10101101; - small[174] = 0b10101110; - small[175] = 0b10101111; - small[176] = 0b10110000; - small[177] = 0b10110001; - small[178] = 0b10110010; - small[179] = 0b10110011; - small[180] = 0b10110100; - small[181] = 0b10110101; - small[182] = 0b10110110; - small[183] = 0b10110111; - small[184] = 0b10111000; - small[185] = 0b10111001; - small[186] = 0b10111010; - small[187] = 0b10111011; - small[188] = 0b10111100; - small[189] = 0b10111101; - small[190] = 0b10111110; - small[191] = 0b10111111; - small[192] = 0b11000000; - small[193] = 0b11000001; - small[194] = 0b11000010; - small[195] = 0b11000011; - small[196] = 0b11000100; - small[197] = 0b11000101; - small[198] = 0b11000110; - small[199] = 0b11000111; - small[200] = 0b11001000; - small[201] = 0b11001001; - small[202] = 0b11001010; - small[203] = 0b11001011; - small[204] = 0b11001100; - small[205] = 0b11001101; - small[206] = 0b11001110; - small[207] = 0b11001111; - small[208] = 0b11010000; - small[209] = 0b11010001; - small[210] = 0b11010010; - small[211] = 0b11010011; - small[212] = 0b11010100; - small[213] = 0b11010101; - small[214] = 0b11010110; - small[215] = 0b11010111; - small[216] = 0b11011000; - small[217] = 0b11011001; - small[218] = 0b11011010; - small[219] = 0b11011011; - small[220] = 0b11011100; - small[221] = 0b11011101; - small[222] = 0b11011110; - small[223] = 0b11011111; - small[224] = 0b11100000; - small[225] = 0b11100001; - small[226] = 0b11100010; - small[227] = 0b11100011; - small[228] = 0b11100100; - small[229] = 0b11100101; - small[230] = 0b11100110; - small[231] = 0b11100111; - small[232] = 0b11101000; - small[233] = 0b11101001; - small[234] = 0b11101010; - small[235] = 0b11101011; - small[236] = 0b11101100; - small[237] = 0b11101101; - small[238] = 0b11101110; - small[239] = 0b11101111; - small[240] = 0b11110000; - small[241] = 0b11110001; - small[242] = 0b11110010; - small[243] = 0b11110011; - small[244] = 0b11110100; - small[245] = 0b11110101; - small[246] = 0b11110110; - small[247] = 0b11110111; - small[248] = 0b11111000; - small[249] = 0b11111001; - small[250] = 0b11111010; - small[251] = 0b11111011; - small[252] = 0b11111100; - small[253] = 0b11111101; - small[254] = 0b11111110; - small[255] = 0b11111111; + small[0] = 0b0; + small[1] = 0b1; + small[2] = 0b10; + small[3] = 0b11; + small[4] = 0b100; + small[5] = 0b101; + small[6] = 0b110; + small[7] = 0b000111; + small[8] = 0b1000; + small[9] = 0b1001; + small[10] = 0b0001010; + small[11] = 0b0001011; + small[12] = 0b1100; + small[13] = 0b1101; + small[14] = 0b1110; + small[15] = 0b1111; + small[16] = 0b10000; + small[17] = 0b10001; + small[18] = 0b00010010; + small[19] = 0b00010011; + small[20] = 0b00010100; + small[21] = 0b00010101; + small[22] = 0b10110; + small[23] = 0b10111; + small[24] = 0b11000; + small[25] = 0b11001; + small[26] = 0b11010; + small[27] = 0b11011; + small[28] = 0b11100; + small[29] = 0b11101; + small[30] = 0b11110; + small[31] = 0b11111; + small[32] = 0b00000000100000; + small[33] = 0b00000000100001; + small[34] = 0b100010; + small[35] = 0b100011; + small[36] = 0b100100; + small[37] = 0b100101; + small[38] = 0b100110; + small[39] = 0b100111; + small[40] = 0b101000; + small[41] = 0b101001; + small[42] = 0b101010; + small[43] = 0b101011; + small[44] = 0b101100; + small[45] = 0b101101; + small[46] = 0b101110; + small[47] = 0b101111; + small[48] = 0b110000; + small[49] = 0b110001; + small[50] = 0b110010; + small[51] = 0b110011; + small[52] = 0b110100; + small[53] = 0b110101; + small[54] = 0b110110; + small[55] = 0b110111; + small[56] = 0b111000; + small[57] = 0b111001; + small[58] = 0b111010; + small[59] = 0b111011; + small[60] = 0b111100; + small[61] = 0b111101; + small[62] = 0b111110; + small[63] = 0b111111; + small[64] = 0b1000000; + small[65] = 0b1000001; + small[66] = 0b1000010; + small[67] = 0b1000011; + small[68] = 0b1000100; + small[69] = 0b1000101; + small[70] = 0b1000110; + small[71] = 0b1000111; + small[72] = 0b1001000; + small[73] = 0b1001001; + small[74] = 0b1001010; + small[75] = 0b1001011; + small[76] = 0b1001100; + small[77] = 0b1001101; + small[78] = 0b1001110; + small[79] = 0b1001111; + small[80] = 0b1010000; + small[81] = 0b1010001; + small[82] = 0b1010010; + small[83] = 0b1010011; + small[84] = 0b1010100; + small[85] = 0b1010101; + small[86] = 0b1010110; + small[87] = 0b1010111; + small[88] = 0b1011000; + small[89] = 0b1011001; + small[90] = 0b1011010; + small[91] = 0b1011011; + small[92] = 0b1011100; + small[93] = 0b1011101; + small[94] = 0b1011110; + small[95] = 0b1011111; + small[96] = 0b1100000; + small[97] = 0b1100001; + small[98] = 0b1100010; + small[99] = 0b1100011; + small[100] = 0b1100100; + small[101] = 0b1100101; + small[102] = 0b1100110; + small[103] = 0b1100111; + small[104] = 0b1101000; + small[105] = 0b1101001; + small[106] = 0b1101010; + small[107] = 0b1101011; + small[108] = 0b1101100; + small[109] = 0b1101101; + small[110] = 0b1101110; + small[111] = 0b1101111; + small[112] = 0b1110000; + small[113] = 0b1110001; + small[114] = 0b1110010; + small[115] = 0b1110011; + small[116] = 0b1110100; + small[117] = 0b1110101; + small[118] = 0b1110110; + small[119] = 0b1110111; + small[120] = 0b1111000; + small[121] = 0b1111001; + small[122] = 0b1111010; + small[123] = 0b1111011; + small[124] = 0b1111100; + small[125] = 0b1111101; + small[126] = 0b1111110; + small[127] = 0b1111111; + small[128] = 0b10000000; + small[129] = 0b10000001; + small[130] = 0b10000010; + small[131] = 0b10000011; + small[132] = 0b10000100; + small[133] = 0b10000101; + small[134] = 0b10000110; + small[135] = 0b10000111; + small[136] = 0b10001000; + small[137] = 0b10001001; + small[138] = 0b10001010; + small[139] = 0b10001011; + small[140] = 0b10001100; + small[141] = 0b10001101; + small[142] = 0b10001110; + small[143] = 0b10001111; + small[144] = 0b10010000; + small[145] = 0b10010001; + small[146] = 0b10010010; + small[147] = 0b10010011; + small[148] = 0b10010100; + small[149] = 0b10010101; + small[150] = 0b10010110; + small[151] = 0b10010111; + small[152] = 0b10011000; + small[153] = 0b10011001; + small[154] = 0b10011010; + small[155] = 0b10011011; + small[156] = 0b10011100; + small[157] = 0b10011101; + small[158] = 0b10011110; + small[159] = 0b10011111; + small[160] = 0b10100000; + small[161] = 0b10100001; + small[162] = 0b10100010; + small[163] = 0b10100011; + small[164] = 0b10100100; + small[165] = 0b10100101; + small[166] = 0b10100110; + small[167] = 0b10100111; + small[168] = 0b10101000; + small[169] = 0b10101001; + small[170] = 0b10101010; + small[171] = 0b10101011; + small[172] = 0b10101100; + small[173] = 0b10101101; + small[174] = 0b10101110; + small[175] = 0b10101111; + small[176] = 0b10110000; + small[177] = 0b10110001; + small[178] = 0b10110010; + small[179] = 0b10110011; + small[180] = 0b10110100; + small[181] = 0b10110101; + small[182] = 0b10110110; + small[183] = 0b10110111; + small[184] = 0b10111000; + small[185] = 0b10111001; + small[186] = 0b10111010; + small[187] = 0b10111011; + small[188] = 0b10111100; + small[189] = 0b10111101; + small[190] = 0b10111110; + small[191] = 0b10111111; + small[192] = 0b11000000; + small[193] = 0b11000001; + small[194] = 0b11000010; + small[195] = 0b11000011; + small[196] = 0b11000100; + small[197] = 0b11000101; + small[198] = 0b11000110; + small[199] = 0b11000111; + small[200] = 0b11001000; + small[201] = 0b11001001; + small[202] = 0b11001010; + small[203] = 0b11001011; + small[204] = 0b11001100; + small[205] = 0b11001101; + small[206] = 0b11001110; + small[207] = 0b11001111; + small[208] = 0b11010000; + small[209] = 0b11010001; + small[210] = 0b11010010; + small[211] = 0b11010011; + small[212] = 0b11010100; + small[213] = 0b11010101; + small[214] = 0b11010110; + small[215] = 0b11010111; + small[216] = 0b11011000; + small[217] = 0b11011001; + small[218] = 0b11011010; + small[219] = 0b11011011; + small[220] = 0b11011100; + small[221] = 0b11011101; + small[222] = 0b11011110; + small[223] = 0b11011111; + small[224] = 0b11100000; + small[225] = 0b11100001; + small[226] = 0b11100010; + small[227] = 0b11100011; + small[228] = 0b11100100; + small[229] = 0b11100101; + small[230] = 0b11100110; + small[231] = 0b11100111; + small[232] = 0b11101000; + small[233] = 0b11101001; + small[234] = 0b11101010; + small[235] = 0b11101011; + small[236] = 0b11101100; + small[237] = 0b11101101; + small[238] = 0b11101110; + small[239] = 0b11101111; + small[240] = 0b11110000; + small[241] = 0b11110001; + small[242] = 0b11110010; + small[243] = 0b11110011; + small[244] = 0b11110100; + small[245] = 0b11110101; + small[246] = 0b11110110; + small[247] = 0b11110111; + small[248] = 0b11111000; + small[249] = 0b11111001; + small[250] = 0b11111010; + small[251] = 0b11111011; + small[252] = 0b11111100; + small[253] = 0b11111101; + small[254] = 0b11111110; + small[255] = 0b11111111; - for (i = 0; i < 256; i++) { - if (small[i] != i) - return 1; - } + for (i = 0; i < 256; i++) { + if (small[i] != i) + return 1; + } - big[0] = 0b1111111100000000; - big[1] = 0b1111111100000001; - big[2] = 0b1111111100000010; - big[3] = 0b1111111100000011; - big[4] = 0b1111111100000100; - big[5] = 0b1111111100000101; - big[6] = 0b1111111100000110; - big[7] = 0b1111111100000111; - big[8] = 0b1111111100001000; - big[9] = 0b1111111100001001; - big[10] = 0b1111111100001010; - big[11] = 0b1111111100001011; - big[12] = 0b1111111100001100; - big[13] = 0b1111111100001101; - big[14] = 0b1111111100001110; - big[15] = 0b1111111100001111; - big[16] = 0b1111111100010000; - big[17] = 0b1111111100010001; - big[18] = 0b1111111100010010; - big[19] = 0b1111111100010011; - big[20] = 0b1111111100010100; - big[21] = 0b1111111100010101; - big[22] = 0b1111111100010110; - big[23] = 0b1111111100010111; - big[24] = 0b1111111100011000; - big[25] = 0b1111111100011001; - big[26] = 0b1111111100011010; - big[27] = 0b1111111100011011; - big[28] = 0b1111111100011100; - big[29] = 0b1111111100011101; - big[30] = 0b1111111100011110; - big[31] = 0b1111111100011111; - big[32] = 0b1111111100100000; - big[33] = 0b1111111100100001; - big[34] = 0b1111111100100010; - big[35] = 0b1111111100100011; - big[36] = 0b1111111100100100; - big[37] = 0b1111111100100101; - big[38] = 0b1111111100100110; - big[39] = 0b1111111100100111; - big[40] = 0b1111111100101000; - big[41] = 0b1111111100101001; - big[42] = 0b1111111100101010; - big[43] = 0b1111111100101011; - big[44] = 0b1111111100101100; - big[45] = 0b1111111100101101; - big[46] = 0b1111111100101110; - big[47] = 0b1111111100101111; - big[48] = 0b1111111100110000; - big[49] = 0b1111111100110001; - big[50] = 0b1111111100110010; - big[51] = 0b1111111100110011; - big[52] = 0b1111111100110100; - big[53] = 0b1111111100110101; - big[54] = 0b1111111100110110; - big[55] = 0b1111111100110111; - big[56] = 0b1111111100111000; - big[57] = 0b1111111100111001; - big[58] = 0b1111111100111010; - big[59] = 0b1111111100111011; - big[60] = 0b1111111100111100; - big[61] = 0b1111111100111101; - big[62] = 0b1111111100111110; - big[63] = 0b1111111100111111; - big[64] = 0b1111111101000000; - big[65] = 0b1111111101000001; - big[66] = 0b1111111101000010; - big[67] = 0b1111111101000011; - big[68] = 0b1111111101000100; - big[69] = 0b1111111101000101; - big[70] = 0b1111111101000110; - big[71] = 0b1111111101000111; - big[72] = 0b1111111101001000; - big[73] = 0b1111111101001001; - big[74] = 0b1111111101001010; - big[75] = 0b1111111101001011; - big[76] = 0b1111111101001100; - big[77] = 0b1111111101001101; - big[78] = 0b1111111101001110; - big[79] = 0b1111111101001111; - big[80] = 0b1111111101010000; - big[81] = 0b1111111101010001; - big[82] = 0b1111111101010010; - big[83] = 0b1111111101010011; - big[84] = 0b1111111101010100; - big[85] = 0b1111111101010101; - big[86] = 0b1111111101010110; - big[87] = 0b1111111101010111; - big[88] = 0b1111111101011000; - big[89] = 0b1111111101011001; - big[90] = 0b1111111101011010; - big[91] = 0b1111111101011011; - big[92] = 0b1111111101011100; - big[93] = 0b1111111101011101; - big[94] = 0b1111111101011110; - big[95] = 0b1111111101011111; - big[96] = 0b1111111101100000; - big[97] = 0b1111111101100001; - big[98] = 0b1111111101100010; - big[99] = 0b1111111101100011; - big[100] = 0b1111111101100100; - big[101] = 0b1111111101100101; - big[102] = 0b1111111101100110; - big[103] = 0b1111111101100111; - big[104] = 0b1111111101101000; - big[105] = 0b1111111101101001; - big[106] = 0b1111111101101010; - big[107] = 0b1111111101101011; - big[108] = 0b1111111101101100; - big[109] = 0b1111111101101101; - big[110] = 0b1111111101101110; - big[111] = 0b1111111101101111; - big[112] = 0b1111111101110000; - big[113] = 0b1111111101110001; - big[114] = 0b1111111101110010; - big[115] = 0b1111111101110011; - big[116] = 0b1111111101110100; - big[117] = 0b1111111101110101; - big[118] = 0b1111111101110110; - big[119] = 0b1111111101110111; - big[120] = 0b1111111101111000; - big[121] = 0b1111111101111001; - big[122] = 0b1111111101111010; - big[123] = 0b1111111101111011; - big[124] = 0b1111111101111100; - big[125] = 0b1111111101111101; - big[126] = 0b1111111101111110; - big[127] = 0b1111111101111111; - big[128] = 0b1111111110000000; - big[129] = 0b1111111110000001; - big[130] = 0b1111111110000010; - big[131] = 0b1111111110000011; - big[132] = 0b1111111110000100; - big[133] = 0b1111111110000101; - big[134] = 0b1111111110000110; - big[135] = 0b1111111110000111; - big[136] = 0b1111111110001000; - big[137] = 0b1111111110001001; - big[138] = 0b1111111110001010; - big[139] = 0b1111111110001011; - big[140] = 0b1111111110001100; - big[141] = 0b1111111110001101; - big[142] = 0b1111111110001110; - big[143] = 0b1111111110001111; - big[144] = 0b1111111110010000; - big[145] = 0b1111111110010001; - big[146] = 0b1111111110010010; - big[147] = 0b1111111110010011; - big[148] = 0b1111111110010100; - big[149] = 0b1111111110010101; - big[150] = 0b1111111110010110; - big[151] = 0b1111111110010111; - big[152] = 0b1111111110011000; - big[153] = 0b1111111110011001; - big[154] = 0b1111111110011010; - big[155] = 0b1111111110011011; - big[156] = 0b1111111110011100; - big[157] = 0b1111111110011101; - big[158] = 0b1111111110011110; - big[159] = 0b1111111110011111; - big[160] = 0b1111111110100000; - big[161] = 0b1111111110100001; - big[162] = 0b1111111110100010; - big[163] = 0b1111111110100011; - big[164] = 0b1111111110100100; - big[165] = 0b1111111110100101; - big[166] = 0b1111111110100110; - big[167] = 0b1111111110100111; - big[168] = 0b1111111110101000; - big[169] = 0b1111111110101001; - big[170] = 0b1111111110101010; - big[171] = 0b1111111110101011; - big[172] = 0b1111111110101100; - big[173] = 0b1111111110101101; - big[174] = 0b1111111110101110; - big[175] = 0b1111111110101111; - big[176] = 0b1111111110110000; - big[177] = 0b1111111110110001; - big[178] = 0b1111111110110010; - big[179] = 0b1111111110110011; - big[180] = 0b1111111110110100; - big[181] = 0b1111111110110101; - big[182] = 0b1111111110110110; - big[183] = 0b1111111110110111; - big[184] = 0b1111111110111000; - big[185] = 0b1111111110111001; - big[186] = 0b1111111110111010; - big[187] = 0b1111111110111011; - big[188] = 0b1111111110111100; - big[189] = 0b1111111110111101; - big[190] = 0b1111111110111110; - big[191] = 0b1111111110111111; - big[192] = 0b1111111111000000; - big[193] = 0b1111111111000001; - big[194] = 0b1111111111000010; - big[195] = 0b1111111111000011; - big[196] = 0b1111111111000100; - big[197] = 0b1111111111000101; - big[198] = 0b1111111111000110; - big[199] = 0b1111111111000111; - big[200] = 0b1111111111001000; - big[201] = 0b1111111111001001; - big[202] = 0b1111111111001010; - big[203] = 0b1111111111001011; - big[204] = 0b1111111111001100; - big[205] = 0b1111111111001101; - big[206] = 0b1111111111001110; - big[207] = 0b1111111111001111; - big[208] = 0b1111111111010000; - big[209] = 0b1111111111010001; - big[210] = 0b1111111111010010; - big[211] = 0b1111111111010011; - big[212] = 0b1111111111010100; - big[213] = 0b1111111111010101; - big[214] = 0b1111111111010110; - big[215] = 0b1111111111010111; - big[216] = 0b1111111111011000; - big[217] = 0b1111111111011001; - big[218] = 0b1111111111011010; - big[219] = 0b1111111111011011; - big[220] = 0b1111111111011100; - big[221] = 0b1111111111011101; - big[222] = 0b1111111111011110; - big[223] = 0b1111111111011111; - big[224] = 0b1111111111100000; - big[225] = 0b1111111111100001; - big[226] = 0b1111111111100010; - big[227] = 0b1111111111100011; - big[228] = 0b1111111111100100; - big[229] = 0b1111111111100101; - big[230] = 0b1111111111100110; - big[231] = 0b1111111111100111; - big[232] = 0b1111111111101000; - big[233] = 0b1111111111101001; - big[234] = 0b1111111111101010; - big[235] = 0b1111111111101011; - big[236] = 0b1111111111101100; - big[237] = 0b1111111111101101; - big[238] = 0b1111111111101110; - big[239] = 0b1111111111101111; - big[240] = 0b1111111111110000; - big[241] = 0b1111111111110001; - big[242] = 0b1111111111110010; - big[243] = 0b1111111111110011; - big[244] = 0b1111111111110100; - big[245] = 0b1111111111110101; - big[246] = 0b1111111111110110; - big[247] = 0b1111111111110111; - big[248] = 0b1111111111111000; - big[249] = 0b1111111111111001; - big[250] = 0b1111111111111010; - big[251] = 0b1111111111111011; - big[252] = 0b1111111111111100; - big[253] = 0b1111111111111101; - big[254] = 0b1111111111111110; - big[255] = 0b1111111111111111; + big[0] = 0b1111111100000000; + big[1] = 0b1111111100000001; + big[2] = 0b1111111100000010; + big[3] = 0b1111111100000011; + big[4] = 0b1111111100000100; + big[5] = 0b1111111100000101; + big[6] = 0b1111111100000110; + big[7] = 0b1111111100000111; + big[8] = 0b1111111100001000; + big[9] = 0b1111111100001001; + big[10] = 0b1111111100001010; + big[11] = 0b1111111100001011; + big[12] = 0b1111111100001100; + big[13] = 0b1111111100001101; + big[14] = 0b1111111100001110; + big[15] = 0b1111111100001111; + big[16] = 0b1111111100010000; + big[17] = 0b1111111100010001; + big[18] = 0b1111111100010010; + big[19] = 0b1111111100010011; + big[20] = 0b1111111100010100; + big[21] = 0b1111111100010101; + big[22] = 0b1111111100010110; + big[23] = 0b1111111100010111; + big[24] = 0b1111111100011000; + big[25] = 0b1111111100011001; + big[26] = 0b1111111100011010; + big[27] = 0b1111111100011011; + big[28] = 0b1111111100011100; + big[29] = 0b1111111100011101; + big[30] = 0b1111111100011110; + big[31] = 0b1111111100011111; + big[32] = 0b1111111100100000; + big[33] = 0b1111111100100001; + big[34] = 0b1111111100100010; + big[35] = 0b1111111100100011; + big[36] = 0b1111111100100100; + big[37] = 0b1111111100100101; + big[38] = 0b1111111100100110; + big[39] = 0b1111111100100111; + big[40] = 0b1111111100101000; + big[41] = 0b1111111100101001; + big[42] = 0b1111111100101010; + big[43] = 0b1111111100101011; + big[44] = 0b1111111100101100; + big[45] = 0b1111111100101101; + big[46] = 0b1111111100101110; + big[47] = 0b1111111100101111; + big[48] = 0b1111111100110000; + big[49] = 0b1111111100110001; + big[50] = 0b1111111100110010; + big[51] = 0b1111111100110011; + big[52] = 0b1111111100110100; + big[53] = 0b1111111100110101; + big[54] = 0b1111111100110110; + big[55] = 0b1111111100110111; + big[56] = 0b1111111100111000; + big[57] = 0b1111111100111001; + big[58] = 0b1111111100111010; + big[59] = 0b1111111100111011; + big[60] = 0b1111111100111100; + big[61] = 0b1111111100111101; + big[62] = 0b1111111100111110; + big[63] = 0b1111111100111111; + big[64] = 0b1111111101000000; + big[65] = 0b1111111101000001; + big[66] = 0b1111111101000010; + big[67] = 0b1111111101000011; + big[68] = 0b1111111101000100; + big[69] = 0b1111111101000101; + big[70] = 0b1111111101000110; + big[71] = 0b1111111101000111; + big[72] = 0b1111111101001000; + big[73] = 0b1111111101001001; + big[74] = 0b1111111101001010; + big[75] = 0b1111111101001011; + big[76] = 0b1111111101001100; + big[77] = 0b1111111101001101; + big[78] = 0b1111111101001110; + big[79] = 0b1111111101001111; + big[80] = 0b1111111101010000; + big[81] = 0b1111111101010001; + big[82] = 0b1111111101010010; + big[83] = 0b1111111101010011; + big[84] = 0b1111111101010100; + big[85] = 0b1111111101010101; + big[86] = 0b1111111101010110; + big[87] = 0b1111111101010111; + big[88] = 0b1111111101011000; + big[89] = 0b1111111101011001; + big[90] = 0b1111111101011010; + big[91] = 0b1111111101011011; + big[92] = 0b1111111101011100; + big[93] = 0b1111111101011101; + big[94] = 0b1111111101011110; + big[95] = 0b1111111101011111; + big[96] = 0b1111111101100000; + big[97] = 0b1111111101100001; + big[98] = 0b1111111101100010; + big[99] = 0b1111111101100011; + big[100] = 0b1111111101100100; + big[101] = 0b1111111101100101; + big[102] = 0b1111111101100110; + big[103] = 0b1111111101100111; + big[104] = 0b1111111101101000; + big[105] = 0b1111111101101001; + big[106] = 0b1111111101101010; + big[107] = 0b1111111101101011; + big[108] = 0b1111111101101100; + big[109] = 0b1111111101101101; + big[110] = 0b1111111101101110; + big[111] = 0b1111111101101111; + big[112] = 0b1111111101110000; + big[113] = 0b1111111101110001; + big[114] = 0b1111111101110010; + big[115] = 0b1111111101110011; + big[116] = 0b1111111101110100; + big[117] = 0b1111111101110101; + big[118] = 0b1111111101110110; + big[119] = 0b1111111101110111; + big[120] = 0b1111111101111000; + big[121] = 0b1111111101111001; + big[122] = 0b1111111101111010; + big[123] = 0b1111111101111011; + big[124] = 0b1111111101111100; + big[125] = 0b1111111101111101; + big[126] = 0b1111111101111110; + big[127] = 0b1111111101111111; + big[128] = 0b1111111110000000; + big[129] = 0b1111111110000001; + big[130] = 0b1111111110000010; + big[131] = 0b1111111110000011; + big[132] = 0b1111111110000100; + big[133] = 0b1111111110000101; + big[134] = 0b1111111110000110; + big[135] = 0b1111111110000111; + big[136] = 0b1111111110001000; + big[137] = 0b1111111110001001; + big[138] = 0b1111111110001010; + big[139] = 0b1111111110001011; + big[140] = 0b1111111110001100; + big[141] = 0b1111111110001101; + big[142] = 0b1111111110001110; + big[143] = 0b1111111110001111; + big[144] = 0b1111111110010000; + big[145] = 0b1111111110010001; + big[146] = 0b1111111110010010; + big[147] = 0b1111111110010011; + big[148] = 0b1111111110010100; + big[149] = 0b1111111110010101; + big[150] = 0b1111111110010110; + big[151] = 0b1111111110010111; + big[152] = 0b1111111110011000; + big[153] = 0b1111111110011001; + big[154] = 0b1111111110011010; + big[155] = 0b1111111110011011; + big[156] = 0b1111111110011100; + big[157] = 0b1111111110011101; + big[158] = 0b1111111110011110; + big[159] = 0b1111111110011111; + big[160] = 0b1111111110100000; + big[161] = 0b1111111110100001; + big[162] = 0b1111111110100010; + big[163] = 0b1111111110100011; + big[164] = 0b1111111110100100; + big[165] = 0b1111111110100101; + big[166] = 0b1111111110100110; + big[167] = 0b1111111110100111; + big[168] = 0b1111111110101000; + big[169] = 0b1111111110101001; + big[170] = 0b1111111110101010; + big[171] = 0b1111111110101011; + big[172] = 0b1111111110101100; + big[173] = 0b1111111110101101; + big[174] = 0b1111111110101110; + big[175] = 0b1111111110101111; + big[176] = 0b1111111110110000; + big[177] = 0b1111111110110001; + big[178] = 0b1111111110110010; + big[179] = 0b1111111110110011; + big[180] = 0b1111111110110100; + big[181] = 0b1111111110110101; + big[182] = 0b1111111110110110; + big[183] = 0b1111111110110111; + big[184] = 0b1111111110111000; + big[185] = 0b1111111110111001; + big[186] = 0b1111111110111010; + big[187] = 0b1111111110111011; + big[188] = 0b1111111110111100; + big[189] = 0b1111111110111101; + big[190] = 0b1111111110111110; + big[191] = 0b1111111110111111; + big[192] = 0b1111111111000000; + big[193] = 0b1111111111000001; + big[194] = 0b1111111111000010; + big[195] = 0b1111111111000011; + big[196] = 0b1111111111000100; + big[197] = 0b1111111111000101; + big[198] = 0b1111111111000110; + big[199] = 0b1111111111000111; + big[200] = 0b1111111111001000; + big[201] = 0b1111111111001001; + big[202] = 0b1111111111001010; + big[203] = 0b1111111111001011; + big[204] = 0b1111111111001100; + big[205] = 0b1111111111001101; + big[206] = 0b1111111111001110; + big[207] = 0b1111111111001111; + big[208] = 0b1111111111010000; + big[209] = 0b1111111111010001; + big[210] = 0b1111111111010010; + big[211] = 0b1111111111010011; + big[212] = 0b1111111111010100; + big[213] = 0b1111111111010101; + big[214] = 0b1111111111010110; + big[215] = 0b1111111111010111; + big[216] = 0b1111111111011000; + big[217] = 0b1111111111011001; + big[218] = 0b1111111111011010; + big[219] = 0b1111111111011011; + big[220] = 0b1111111111011100; + big[221] = 0b1111111111011101; + big[222] = 0b1111111111011110; + big[223] = 0b1111111111011111; + big[224] = 0b1111111111100000; + big[225] = 0b1111111111100001; + big[226] = 0b1111111111100010; + big[227] = 0b1111111111100011; + big[228] = 0b1111111111100100; + big[229] = 0b1111111111100101; + big[230] = 0b1111111111100110; + big[231] = 0b1111111111100111; + big[232] = 0b1111111111101000; + big[233] = 0b1111111111101001; + big[234] = 0b1111111111101010; + big[235] = 0b1111111111101011; + big[236] = 0b1111111111101100; + big[237] = 0b1111111111101101; + big[238] = 0b1111111111101110; + big[239] = 0b1111111111101111; + big[240] = 0b1111111111110000; + big[241] = 0b1111111111110001; + big[242] = 0b1111111111110010; + big[243] = 0b1111111111110011; + big[244] = 0b1111111111110100; + big[245] = 0b1111111111110101; + big[246] = 0b1111111111110110; + big[247] = 0b1111111111110111; + big[248] = 0b1111111111111000; + big[249] = 0b1111111111111001; + big[250] = 0b1111111111111010; + big[251] = 0b1111111111111011; + big[252] = 0b1111111111111100; + big[253] = 0b1111111111111101; + big[254] = 0b1111111111111110; + big[255] = 0b1111111111111111; - for (i = 0; i < 256; i++) { - if (big[i] != i + 65280U) - return 1; - } + for (i = 0; i < 256; i++) { + if (big[i] != i + 65280U) + return 1; + } - return 0; + return 0; } diff --git a/test/val/bug1071.c b/test/val/bug1071.c index 02b069de0..66e298b25 100644 --- a/test/val/bug1071.c +++ b/test/val/bug1071.c @@ -7,24 +7,24 @@ struct ImageStruct { - uint8_t _imageData; - #if !defined(NO_COLOR) - uint8_t _color; - #endif + uint8_t _imageData; + #if !defined(NO_COLOR) + uint8_t _color; + #endif }; typedef struct ImageStruct Image; struct CharacterStruct { - // character coordinates - uint8_t _x; - uint8_t _y; + // character coordinates + uint8_t _x; + uint8_t _y; - // _status decides whether the character is active - uint8_t _status; + // _status decides whether the character is active + uint8_t _status; - Image* _imagePtr; + Image* _imagePtr; }; typedef struct CharacterStruct Character; @@ -53,20 +53,20 @@ Character bombs[BOMBS_NUMBER]; uint16_t test1(void) { - if((loop> 0) & 0xFF; - uint16_t s1 = (seed >> 8) & 0xFF; - uint16_t s2 = (seed >> 16) & 0xFF; - uint16_t s3 = (seed >> 24) & 0xFF; - uint16_t o0 = s3 ^ s1; - uint16_t o1 = s2 ^ s0; - output = o0 | (o1 << 8); - } - return (int)(output & 0x7FFF); + uint16_t output; + /* seed follows the LCG sequence * 0x01010101 + 0xB3B3B3B3 */ + seed = seed * 0x01010101UL + 0xB3B3B3B3UL; + /* output uses the top two bytes (reversed) XOR with bottom two bytes */ + { + uint16_t s0 = (seed >> 0) & 0xFF; + uint16_t s1 = (seed >> 8) & 0xFF; + uint16_t s2 = (seed >> 16) & 0xFF; + uint16_t s3 = (seed >> 24) & 0xFF; + uint16_t o0 = s3 ^ s1; + uint16_t o1 = s2 ^ s0; + output = o0 | (o1 << 8); + } + return (int)(output & 0x7FFF); } void ref_srand(int ax) { - uint32_t s = (unsigned int)ax; - seed = s | (s << 16); /* low 16 bits is convenient filler for high 16 bits */ - ref_rand(); /* one pre-call "shuffles" the first rand() result so it isn't too predictable */ + uint32_t s = (unsigned int)ax; + seed = s | (s << 16); /* low 16 bits is convenient filler for high 16 bits */ + ref_rand(); /* one pre-call "shuffles" the first rand() result so it isn't too predictable */ } int main(void) { - unsigned int i,j; - int a,b; + unsigned int i,j; + int a,b; - /* test that startup state is equivalent to srand(1) */ - { - //srand(1); // implied - ref_srand(1); - for (j=0; j Date: Sun, 15 Nov 2020 23:03:01 +0100 Subject: [PATCH 074/122] g_asr, g_asl: Use ROL/ROR for char shifts by >= 6 Instead of `val` right (left) shifts, we can also do `9 - val` left (right) rotates and a mask. This saves 3 bytes and 8 cycles for `val == 7` and 1 byte and 4 cycles for `val == 6`. --- src/cc65/codegen.c | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index a58484cf1..3ca9d81e6 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -3114,9 +3114,26 @@ void g_asr (unsigned flags, unsigned long val) switch (flags & CF_TYPEMASK) { case CF_CHAR: if (flags & CF_FORCECHAR) { - if ((flags & CF_UNSIGNED) != 0 && val < 8) { - while (val--) { - AddCodeLine ("lsr a"); + val &= 7; + if ((flags & CF_UNSIGNED) != 0) { + /* Instead of `val` right shifts, we can also do `9 - val` left rotates + ** and a mask. This saves 3 bytes and 8 cycles for `val == 7` and + ** 1 byte and 4 cycles for `val == 6`. + */ + if (val < 6) { + while (val--) { + AddCodeLine ("lsr a"); /* 1 byte, 2 cycles */ + } + } else { + unsigned i; + /* The first ROL shifts in garbage and sets carry to the high bit. + ** The garbage is cleaned up by the mask. + */ + for (i = val; i < 9; ++i) { + AddCodeLine ("rol a"); /* 1 byte, 2 cycles */ + } + /* 2 bytes, 2 cycles */ + AddCodeLine ("and #$%02X", 0xFF >> val); } return; } else if (val <= 2) { @@ -3270,9 +3287,21 @@ void g_asl (unsigned flags, unsigned long val) if (flags & CF_CONST) { switch (flags & CF_TYPEMASK) { case CF_CHAR: - if ((flags & CF_FORCECHAR) != 0 && val <= 6) { - while (val--) { - AddCodeLine ("asl a"); + if ((flags & CF_FORCECHAR) != 0) { + val &= 7; + /* Large shifts are faster and smaller with ROR. See g_asr for detailed + ** byte and cycle counts. + */ + if (val < 6) { + while (val--) { + AddCodeLine ("asl a"); + } + } else { + unsigned i; + for (i = val; i < 9; ++i) { + AddCodeLine ("ror a"); + } + AddCodeLine ("and #$%02X", (~0U << val) & 0xFF); } return; } From 39573109500d06b415026af2d07de4b3c8b52a47 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 25 Oct 2020 14:27:26 +0100 Subject: [PATCH 075/122] Knock off two bytes from getcwd(), cbm_read() and cbm_write(). --- libsrc/cbm/cbm_read.s | 14 +++++++------- libsrc/cbm/cbm_write.s | 14 +++++++------- libsrc/common/getcwd.s | 16 ++++++++-------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/libsrc/cbm/cbm_read.s b/libsrc/cbm/cbm_read.s index b010966a3..a30983302 100644 --- a/libsrc/cbm/cbm_read.s +++ b/libsrc/cbm/cbm_read.s @@ -45,11 +45,11 @@ _cbm_read: - eor #$FF - sta ptr1 - txa - eor #$FF - sta ptr1+1 ; Save -size-1 + inx + stx ptr1+1 + tax + inx + stx ptr1 ; Save size with each byte incremented. jsr popax sta ptr2 @@ -92,9 +92,9 @@ _cbm_read: bne @L3 inc ptr3+1 ; ++bytesread; -@L3: inc ptr1 +@L3: dec ptr1 bne @L1 - inc ptr1+1 + dec ptr1+1 bne @L1 @L4: jsr CLRCH diff --git a/libsrc/cbm/cbm_write.s b/libsrc/cbm/cbm_write.s index 2d932d04a..a199c1d90 100644 --- a/libsrc/cbm/cbm_write.s +++ b/libsrc/cbm/cbm_write.s @@ -39,11 +39,11 @@ _cbm_write: sta ptr3 stx ptr3+1 ; Save size - eor #$FF - sta ptr1 - txa - eor #$FF - sta ptr1+1 ; Save -size-1 + inx + stx ptr1+1 + tax + inx + stx ptr1 ; Save size with each byte incremented jsr popax sta ptr2 @@ -69,9 +69,9 @@ _cbm_write: @L2: jsr BSOUT ; cbm_k_bsout (A); -@L3: inc ptr1 ; --size; +@L3: dec ptr1 ; --size; bne @L1 - inc ptr1+1 + dec ptr1+1 bne @L1 jsr CLRCH diff --git a/libsrc/common/getcwd.s b/libsrc/common/getcwd.s index 22b6ceded..c0a1c3634 100644 --- a/libsrc/common/getcwd.s +++ b/libsrc/common/getcwd.s @@ -17,22 +17,22 @@ .proc _getcwd -; Remember -size-1 because this simplifies the following loop +; Remember size with each byte incremented because this simplifies the following loop - eor #$FF - sta ptr2 - txa - eor #$FF - sta ptr2+1 + inx + stx ptr2+1 + tax + inx + stx ptr2 jsr popptr1 ; Get buf to ptr1 ; Copy __cwd to the given buffer checking the length ; ldy #$00 is guaranteed by popptr1 -loop: inc ptr2 +loop: dec ptr2 bne @L1 - inc ptr2+1 + dec ptr2+1 beq overflow ; Copy one character, end the loop if the zero terminator is reached. We From 99c0815cdb6b55ee89a1945e58674a5eefbb8126 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Tue, 27 Oct 2020 06:08:04 +0100 Subject: [PATCH 076/122] Clear up comments a bit. --- libsrc/cbm/cbm_read.s | 2 +- libsrc/cbm/cbm_write.s | 2 +- libsrc/common/getcwd.s | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libsrc/cbm/cbm_read.s b/libsrc/cbm/cbm_read.s index a30983302..29e0e1f19 100644 --- a/libsrc/cbm/cbm_read.s +++ b/libsrc/cbm/cbm_read.s @@ -49,7 +49,7 @@ _cbm_read: stx ptr1+1 tax inx - stx ptr1 ; Save size with each byte incremented. + stx ptr1 ; Save size with both bytes incremented separately. jsr popax sta ptr2 diff --git a/libsrc/cbm/cbm_write.s b/libsrc/cbm/cbm_write.s index a199c1d90..5ac07209c 100644 --- a/libsrc/cbm/cbm_write.s +++ b/libsrc/cbm/cbm_write.s @@ -43,7 +43,7 @@ _cbm_write: stx ptr1+1 tax inx - stx ptr1 ; Save size with each byte incremented + stx ptr1 ; Save size with both bytes incremented separately jsr popax sta ptr2 diff --git a/libsrc/common/getcwd.s b/libsrc/common/getcwd.s index c0a1c3634..4bfc0a5b6 100644 --- a/libsrc/common/getcwd.s +++ b/libsrc/common/getcwd.s @@ -23,7 +23,7 @@ stx ptr2+1 tax inx - stx ptr2 + stx ptr2 ; Save size with each byte incremented separately jsr popptr1 ; Get buf to ptr1 From f59cb9af0660e5401f18fe9e86329b2d0fd6b739 Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Sun, 1 Nov 2020 22:59:07 +0100 Subject: [PATCH 077/122] Use more compact loops. --- libsrc/atmos/read.s | 15 ++++++++------- libsrc/atmos/write.s | 14 +++++++------- libsrc/cbm/read.s | 4 ++-- libsrc/cbm/rwcommon.s | 10 +++++----- libsrc/cbm/write.s | 4 ++-- libsrc/common/memcmp.s | 15 +++++++-------- libsrc/common/strncat.s | 22 +++++++++++----------- libsrc/common/strncpy.s | 18 +++++++++--------- libsrc/common/strnicmp.s | 20 +++++++------------- libsrc/conio/vcprintf.s | 16 ++++++++-------- libsrc/geos-common/drivers/fio_module.s | 15 ++++++++------- libsrc/osic1p/bootstrap.s | 17 +++++++++-------- libsrc/telestrat/write.s | 14 +++++++------- 13 files changed, 90 insertions(+), 94 deletions(-) diff --git a/libsrc/atmos/read.s b/libsrc/atmos/read.s index 83aa8024e..3f22d8d0e 100644 --- a/libsrc/atmos/read.s +++ b/libsrc/atmos/read.s @@ -20,18 +20,19 @@ sta ptr3 stx ptr3+1 ; save count as result - eor #$FF - sta ptr2 - txa - eor #$FF - sta ptr2+1 ; Remember -count-1 + + inx + stx ptr2+1 + tax + inx + stx ptr2 ; save count with each byte incremented separately jsr popptr1 ; get buf jsr popax ; get fd and discard -L1: inc ptr2 +L1: dec ptr2 bnz L2 - inc ptr2+1 + dec ptr2+1 bze L9 ; no more room in buf ; If there are no more characters in BASIC's input buffer, then get a line from diff --git a/libsrc/atmos/write.s b/libsrc/atmos/write.s index 7865b5698..4a68994ec 100644 --- a/libsrc/atmos/write.s +++ b/libsrc/atmos/write.s @@ -17,17 +17,17 @@ sta ptr3 stx ptr3+1 ; save count as result - eor #$FF - sta ptr2 - txa - eor #$FF - sta ptr2+1 ; Remember -count-1 + inx + stx ptr2+1 + tax + inx + stx ptr2 ; save count with each byte incremented separately jsr popptr1 ; get buf jsr popax ; get fd and discard -L1: inc ptr2 +L1: dec ptr2 bne L2 - inc ptr2+1 + dec ptr2+1 beq L9 L2: ldy #0 lda (ptr1),y diff --git a/libsrc/cbm/read.s b/libsrc/cbm/read.s index ee01596aa..fb0bb3171 100644 --- a/libsrc/cbm/read.s +++ b/libsrc/cbm/read.s @@ -106,9 +106,9 @@ ; Decrement the count -@L3: inc ptr2 +@L3: dec ptr2 bne @L0 - inc ptr2+1 + dec ptr2+1 bne @L0 beq done ; Branch always diff --git a/libsrc/cbm/rwcommon.s b/libsrc/cbm/rwcommon.s index a1f92be8c..d13c478b5 100644 --- a/libsrc/cbm/rwcommon.s +++ b/libsrc/cbm/rwcommon.s @@ -21,11 +21,11 @@ .proc rwcommon - eor #$FF - sta ptr2 - txa - eor #$FF - sta ptr2+1 ; Remember -count-1 + inx + stx ptr2+1 + tax + inx + stx ptr2 ; Save count with each byte incremented separately jsr popptr1 ; Get buf to ptr1, Y=0 by call diff --git a/libsrc/cbm/write.s b/libsrc/cbm/write.s index 7a27f0044..ebc44a0ac 100644 --- a/libsrc/cbm/write.s +++ b/libsrc/cbm/write.s @@ -83,9 +83,9 @@ ; Decrement count -@L2: inc ptr2 +@L2: dec ptr2 bne @L0 - inc ptr2+1 + dec ptr2+1 bne @L0 ; Wrote all chars or disk full. Close the output channel diff --git a/libsrc/common/memcmp.s b/libsrc/common/memcmp.s index 93a2c28dc..5879a433d 100644 --- a/libsrc/common/memcmp.s +++ b/libsrc/common/memcmp.s @@ -13,11 +13,11 @@ _memcmp: ; Calculate (-count-1) and store it into ptr3. This is some overhead here but ; saves time in the compare loop - eor #$FF - sta ptr3 - txa - eor #$FF - sta ptr3+1 + inx + stx ptr3+1 + tax + inx + stx ptr3 ; Save count with each byte incremented separately ; Get the pointer parameters @@ -33,7 +33,7 @@ _memcmp: ; Head of compare loop: Test for the end condition -Loop: inx ; Bump low byte of (-count-1) +Loop: dex ; Bump low byte of (-count-1) beq BumpHiCnt ; Jump on overflow ; Do the compare @@ -53,7 +53,7 @@ Comp: lda (ptr1),y ; Entry on low counter byte overflow BumpHiCnt: - inc ptr3+1 ; Bump high byte of (-count-1) + dec ptr3+1 ; Bump high byte of (-count-1) bne Comp ; Jump if not done jmp return0 ; Count is zero, areas are identical @@ -67,4 +67,3 @@ NotEqual: Greater: ldx #$01 ; Make result positive rts - diff --git a/libsrc/common/strncat.s b/libsrc/common/strncat.s index caa6804fc..060378442 100644 --- a/libsrc/common/strncat.s +++ b/libsrc/common/strncat.s @@ -5,17 +5,17 @@ ; char* strncat (char* dest, const char* src, size_t n); ; - .export _strncat - .import popax, popptr1 - .importzp ptr1, ptr2, ptr3, tmp1, tmp2 - .macpack cpu +.export _strncat +.import popax, popptr1 +.importzp ptr1, ptr2, ptr3, tmp1, tmp2 +.macpack cpu _strncat: - eor #$FF ; one's complement to count upwards - sta tmp1 - txa - eor #$FF - sta tmp2 + inx + stx tmp2 + tax + inx + stx tmp1 ; save count with each byte incremented separately jsr popptr1 ; get src @@ -49,9 +49,9 @@ L2: sty ptr2 L3: ldy #0 ldx tmp1 ; low counter byte -L4: inx +L4: dex bne L5 - inc tmp2 + dec tmp2 beq L6 ; jump if done L5: lda (ptr1),y sta (ptr2),y diff --git a/libsrc/common/strncpy.s b/libsrc/common/strncpy.s index 56387f880..49bd90b32 100644 --- a/libsrc/common/strncpy.s +++ b/libsrc/common/strncpy.s @@ -10,11 +10,11 @@ .proc _strncpy - eor #$FF - sta tmp1 - txa - eor #$FF - sta tmp2 ; Store -size - 1 + inx + stx tmp2 + tax + inx + stx tmp1 ; save count with each byte incremented separately jsr popptr1 ; get src jsr popax ; get dest @@ -26,9 +26,9 @@ ldx tmp1 ; Load low byte of ones complement of size ldy #$00 -L1: inx +L1: dex bne L2 - inc tmp2 + dec tmp2 beq L9 L2: lda (ptr1),y ; Copy one character @@ -42,7 +42,7 @@ L2: lda (ptr1),y ; Copy one character ; Fill the remaining bytes. -L3: inx ; Counter low byte +L3: dex ; Counter low byte beq L6 ; Branch on overflow L4: sta (ptr2),y ; Clear one byte L5: iny ; Bump pointer @@ -52,7 +52,7 @@ L5: iny ; Bump pointer ; Bump the counter high byte -L6: inc tmp2 +L6: dec tmp2 bne L4 ; Done, return dest diff --git a/libsrc/common/strnicmp.s b/libsrc/common/strnicmp.s index 43d6d0d50..f447b9683 100644 --- a/libsrc/common/strnicmp.s +++ b/libsrc/common/strnicmp.s @@ -15,17 +15,11 @@ _strnicmp: _strncasecmp: -; Convert the given counter value in a/x from a downward counter into an -; upward counter, so we can increment the counter in the loop below instead -; of decrementing it. This adds some overhead now, but is cheaper than -; executing a more complex test in each iteration of the loop. We do also -; correct the value by one, so we can do the test on top of the loop. - - eor #$FF - sta ptr3 - txa - eor #$FF - sta ptr3+1 + inx + stx ptr3+1 + tax + inx + stx ptr3 ; save count with each byte incremented separately ; Get the remaining arguments @@ -40,7 +34,7 @@ _strncasecmp: ; Start of compare loop. Check the counter. -Loop: inc ptr3 +Loop: dec ptr3 beq IncHi ; increment high byte ; Compare a byte from the strings @@ -79,7 +73,7 @@ L2: ldx tmp1 ; Increment hi byte -IncHi: inc ptr3+1 +IncHi: dec ptr3+1 bne Comp ; jump if counter not zero ; Exit code if strings are equal. a/x not set diff --git a/libsrc/conio/vcprintf.s b/libsrc/conio/vcprintf.s index 3a9ddf9d7..084efe089 100644 --- a/libsrc/conio/vcprintf.s +++ b/libsrc/conio/vcprintf.s @@ -47,12 +47,12 @@ outdesc: ; Static outdesc structure out: jsr popax ; count sta ptr2 - eor #$FF - sta outdesc+6 - txa - sta ptr2+1 - eor #$FF - sta outdesc+7 + stx ptr2+1 + inx + stx outdesc+7 + tax + inx + stx outdesc+6 jsr popptr1 ; buf @@ -74,7 +74,7 @@ out: jsr popax ; count ; Loop outputting characters -@L1: inc outdesc+6 +@L1: dec outdesc+6 beq @L4 @L2: ldy tmp1 lda (ptr1),y @@ -85,7 +85,7 @@ out: jsr popax ; count jsr _cputc jmp @L1 -@L4: inc outdesc+7 +@L4: dec outdesc+7 bne @L2 rts diff --git a/libsrc/geos-common/drivers/fio_module.s b/libsrc/geos-common/drivers/fio_module.s index 0be5015a7..937ef292e 100644 --- a/libsrc/geos-common/drivers/fio_module.s +++ b/libsrc/geos-common/drivers/fio_module.s @@ -94,11 +94,12 @@ _read: ; popax - fd, must be == to the above one ; return -1+__oserror or number of bytes read - eor #$ff - sta ptr1 - txa - eor #$ff - sta ptr1+1 ; -(# of bytes to read)-1 + inx + stx ptr1+1 + tax + inx + stx ptr1 ; save count with each byte incremented separately + jsr popax sta ptr2 stx ptr2+1 ; buffer ptr @@ -152,9 +153,9 @@ _read: beq @done ; yes, we're done jmp __mappederrno ; no, we're screwed -@L3: inc ptr1 ; decrement the count +@L3: dec ptr1 ; decrement the count bne @L0 - inc ptr1+1 + dec ptr1+1 bne @L0 @done: diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index ed2ade222..efb480cb8 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -50,16 +50,17 @@ LINEDIST = $20 ; Offset in video RAM between two lines ldx #>load_addr sta load stx load+1 - lda #load_size - eor #$FF - sta count+1 -L1: inc count ; pre-count one's-complement upwards + ldx #load_size + inx + stx count+1 ; save size with each byte incremented separately + +L1: dec count ; pre-count one's-complement upwards bnz L2 - inc count+1 + dec count+1 bze L3 L2: jsr GETCHAR ; (doesn't change .Y) sta (load),y diff --git a/libsrc/telestrat/write.s b/libsrc/telestrat/write.s index 68aef42d6..215db3e52 100644 --- a/libsrc/telestrat/write.s +++ b/libsrc/telestrat/write.s @@ -13,11 +13,11 @@ sta ptr3 stx ptr3+1 ; save count as result - eor #$FF - sta ptr2 - txa - eor #$FF - sta ptr2+1 ; remember -count-1 + inx + stx ptr2+1 + tax + inx + stx ptr2 ; save count with each byte incremented separately jsr popptr1 ; get buf jsr popax ; get fd and discard @@ -51,9 +51,9 @@ next: rts -L1: inc ptr2 +L1: dec ptr2 bne L2 - inc ptr2+1 + dec ptr2+1 beq L9 L2: ldy #0 lda (ptr1),y From 6201300816b3c6bcd9cd688f40c0f34b10d3584e Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Tue, 3 Nov 2020 11:52:58 +0100 Subject: [PATCH 078/122] Fold constant calculation. --- libsrc/osic1p/bootstrap.s | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index efb480cb8..031c4f651 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -51,11 +51,9 @@ LINEDIST = $20 ; Offset in video RAM between two lines sta load stx load+1 - ldx #load_size - inx + ldx #(>load_size) + 1 stx count+1 ; save size with each byte incremented separately L1: dec count ; pre-count one's-complement upwards From db312049503dc0effa872d66467b4f36de11831b Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Tue, 3 Nov 2020 11:53:56 +0100 Subject: [PATCH 079/122] Remove stale comment. --- libsrc/osic1p/bootstrap.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/osic1p/bootstrap.s b/libsrc/osic1p/bootstrap.s index 031c4f651..e88e257fd 100644 --- a/libsrc/osic1p/bootstrap.s +++ b/libsrc/osic1p/bootstrap.s @@ -56,7 +56,7 @@ LINEDIST = $20 ; Offset in video RAM between two lines ldx #(>load_size) + 1 stx count+1 ; save size with each byte incremented separately -L1: dec count ; pre-count one's-complement upwards +L1: dec count bnz L2 dec count+1 bze L3 From 9d62abb7ac19e2e117d7d162cb4d73482bca06ca Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Tue, 3 Nov 2020 11:54:50 +0100 Subject: [PATCH 080/122] Fix comment. --- libsrc/common/strnicmp.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/common/strnicmp.s b/libsrc/common/strnicmp.s index f447b9683..477aa3d66 100644 --- a/libsrc/common/strnicmp.s +++ b/libsrc/common/strnicmp.s @@ -34,8 +34,8 @@ _strncasecmp: ; Start of compare loop. Check the counter. -Loop: dec ptr3 - beq IncHi ; increment high byte +Loop: dec ptr3 ; decrement high byte + beq IncHi ; Compare a byte from the strings From 9800555bbb399decb5aaf50260a831076517332d Mon Sep 17 00:00:00 2001 From: Sven Michael Klose Date: Fri, 20 Nov 2020 03:50:19 +0100 Subject: [PATCH 081/122] Remove stale comments. --- libsrc/common/strncpy.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/common/strncpy.s b/libsrc/common/strncpy.s index 49bd90b32..138413ecb 100644 --- a/libsrc/common/strncpy.s +++ b/libsrc/common/strncpy.s @@ -24,7 +24,7 @@ ; Copy src -> dest up to size bytes - ldx tmp1 ; Load low byte of ones complement of size + ldx tmp1 ldy #$00 L1: dex bne L2 @@ -43,7 +43,7 @@ L2: lda (ptr1),y ; Copy one character ; Fill the remaining bytes. L3: dex ; Counter low byte - beq L6 ; Branch on overflow + beq L6 L4: sta (ptr2),y ; Clear one byte L5: iny ; Bump pointer bne L3 From d90cd112125a0a51c286b019c4e76f2131499683 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 27 Dec 2020 18:22:12 -0500 Subject: [PATCH 082/122] Fixed outdated comments. --- libsrc/common/memcmp.s | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libsrc/common/memcmp.s b/libsrc/common/memcmp.s index 5879a433d..d651a3cfc 100644 --- a/libsrc/common/memcmp.s +++ b/libsrc/common/memcmp.s @@ -10,8 +10,8 @@ _memcmp: -; Calculate (-count-1) and store it into ptr3. This is some overhead here but -; saves time in the compare loop +; Calculate a special count, and store it into ptr3. That is some overhead here, +; but saves time in the compare loop inx stx ptr3+1 @@ -29,12 +29,12 @@ _memcmp: ; Loop initialization ;ldy #$00 ; Initialize pointer (Y=0 guaranteed by popptr1) - ldx ptr3 ; Load low counter byte into X + ldx ptr3 ; Load inner counter byte into .X ; Head of compare loop: Test for the end condition -Loop: dex ; Bump low byte of (-count-1) - beq BumpHiCnt ; Jump on overflow +Loop: dex + beq BumpHiCnt ; Jump on end of inner count ; Do the compare @@ -50,10 +50,10 @@ Comp: lda (ptr1),y inc ptr2+1 bne Loop ; Branch always (pointer wrap is illegal) -; Entry on low counter byte overflow +; Entry on inner loop end BumpHiCnt: - dec ptr3+1 ; Bump high byte of (-count-1) + dec ptr3+1 bne Comp ; Jump if not done jmp return0 ; Count is zero, areas are identical From a9b71b6207c837833aacda2e5252dac4fd8fa8e5 Mon Sep 17 00:00:00 2001 From: Rocky Date: Fri, 1 Jan 2021 15:39:23 +0100 Subject: [PATCH 083/122] return-type - new warning suppression type added --- src/cc65/error.c | 2 ++ src/cc65/error.h | 1 + src/cc65/function.c | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cc65/error.c b/src/cc65/error.c index 132bf331d..feb43565d 100644 --- a/src/cc65/error.c +++ b/src/cc65/error.c @@ -74,6 +74,7 @@ IntStack WarnUnknownPragma = INTSTACK(1); /* - unknown #pragmas */ IntStack WarnUnusedLabel = INTSTACK(1); /* - unused labels */ IntStack WarnUnusedParam = INTSTACK(1); /* - unused parameters */ IntStack WarnUnusedVar = INTSTACK(1); /* - unused variables */ +IntStack WarnReturnType = INTSTACK(1); /* - control reaches end of non-void function */ /* Map the name of a warning to the intstack that holds its state */ typedef struct WarnMapEntry WarnMapEntry; @@ -92,6 +93,7 @@ static WarnMapEntry WarnMap[] = { { &WarnUnusedLabel, "unused-label" }, { &WarnUnusedParam, "unused-param" }, { &WarnUnusedVar, "unused-var" }, + { &WarnReturnType, "return-type" }, }; Collection DiagnosticStrBufs; diff --git a/src/cc65/error.h b/src/cc65/error.h index a443aeff8..898793651 100644 --- a/src/cc65/error.h +++ b/src/cc65/error.h @@ -71,6 +71,7 @@ extern IntStack WarnUnknownPragma; /* - unknown #pragmas */ extern IntStack WarnUnusedLabel; /* - unused labels */ extern IntStack WarnUnusedParam; /* - unused parameters */ extern IntStack WarnUnusedVar; /* - unused variables */ +extern IntStack WarnReturnType; /* - control reaches end of non-void function */ /* Forward */ struct StrBuf; diff --git a/src/cc65/function.c b/src/cc65/function.c index 00755ae65..9269d4c62 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -654,8 +654,8 @@ void NewFunc (SymEntry* Func, FuncDesc* D) ** environment returning int, output a warning if we didn't see a return ** statement. */ - if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc) && !C99MainFunc) { - Warning ("Control reaches end of non-void function"); + if (!F_HasVoidReturn (CurrentFunc) && !F_HasReturn (CurrentFunc) && !C99MainFunc && IS_Get (&WarnReturnType)) { + Warning ("Control reaches end of non-void function [-Wreturn-type]"); } /* If this is the main function in a C99 environment returning an int, let From 96624699577c7497fda3592088f3928867dff381 Mon Sep 17 00:00:00 2001 From: Piotr Kaczorowski Date: Mon, 4 Jan 2021 22:05:55 +0100 Subject: [PATCH 084/122] Return-type warning and pseudo variable __A__ documentation added. --- doc/cc65.sgml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/cc65.sgml b/doc/cc65.sgml index e273ced9c..211aa21b3 100644 --- a/doc/cc65.sgml +++ b/doc/cc65.sgml @@ -549,6 +549,8 @@ Here is a description of all the command line options: Warn about a / that changes a character's code number from/to 0x00. + + Warn about no return statement in function returning non-void.. Warn when passing structs by value. @@ -726,6 +728,29 @@ This cc65 version has some extensions to the ISO C standard. will give the high byte of any unsigned value.

+ There is pseudo variable named