From 6217f8fa3ae57bfcb29abb6ea2b4d118384d3e06 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 28 Sep 2015 11:27:39 -0400 Subject: [PATCH 01/10] Made the Commodore version of exec() work in programs that are so big that they load into all of BASIC RAM. The function won't cause an "out of memory" error. --- asminc/c64.inc | 2 ++ asminc/pet.inc | 1 + asminc/plus4.inc | 2 ++ asminc/vic20.inc | 2 ++ libsrc/cbm/exec.c | 69 ++++++++++++++++++++++++++++--------------- libsrc/cbm/execvars.s | 14 ++++++--- 6 files changed, 63 insertions(+), 27 deletions(-) diff --git a/asminc/c64.inc b/asminc/c64.inc index f450fcc0b..5815bebf9 100644 --- a/asminc/c64.inc +++ b/asminc/c64.inc @@ -6,6 +6,8 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +VARTAB := $2D ; Pointer to start of BASIC variables +MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $7A ; Pointer into BASIC source code TIME := $A0 ; 60 HZ clock FNAM_LEN := $B7 ; Length of filename diff --git a/asminc/pet.inc b/asminc/pet.inc index 1ebf391f9..a745a89c8 100644 --- a/asminc/pet.inc +++ b/asminc/pet.inc @@ -6,6 +6,7 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +VARTAB := $2A ; Pointer to start of BASIC variables MEMSIZE := $34 ; Size of memory installed TXTPTR := $77 ; Pointer into BASIC source code TIME := $8D ; 60HZ clock diff --git a/asminc/plus4.inc b/asminc/plus4.inc index 17e250508..69b2298a3 100644 --- a/asminc/plus4.inc +++ b/asminc/plus4.inc @@ -7,6 +7,8 @@ ; Zero page, Commodore stuff TMPPTR := $22 ; Temporary ptr used by BASIC +VARTAB := $2D ; Pointer to start of BASIC variables +MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $3B ; Pointer into BASIC source code TIME := $A3 ; 60HZ clock FNAM_LEN := $AB ; Length of filename diff --git a/asminc/vic20.inc b/asminc/vic20.inc index c42db4258..12424dc11 100644 --- a/asminc/vic20.inc +++ b/asminc/vic20.inc @@ -6,6 +6,8 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +VARTAB := $2D ; Pointer to start of BASIC variables +MEMSIZE := $37 ; Pointer to highest BASIC RAM location (+1) TXTPTR := $7A ; Pointer into BASIC source code TIME := $A0 ; 60HZ clock FNAM_LEN := $B7 ; Length of filename diff --git a/libsrc/cbm/exec.c b/libsrc/cbm/exec.c index 36c3afe00..b9c1bdc96 100644 --- a/libsrc/cbm/exec.c +++ b/libsrc/cbm/exec.c @@ -1,7 +1,7 @@ /* ** Program-chaining function for Commodore platforms. ** -** 2013-09-04, Greg King +** 2015-09-27, Greg King ** ** This function exploits the program-chaining feature in CBM BASIC's ROM. ** @@ -32,42 +32,46 @@ /* The struct below is a line of BASIC code. It sits in the LOWCODE segment ** to make sure that it won't be hidden by a ROM when BASIC is re-enabled. ** The line is: -** 0 LOAD""+"" ,01 +** 0 CLR:LOAD""+"" ,01 ** After this function has written into the line, it might look like this: -** 0 LOAD""+"program name" ,08 +** 0 CLR:LOAD""+"program name" ,08 ** ** When BASIC's LOAD command asks the Kernal to load a file, it gives the ** Kernal a pointer to a file-name string. CC65's CBM programs use that ** pointer to give a copy of the program's name to main()'s argv[0] parameter. -** But, when BASIC uses a string literal that's in a program, it points +** But, when BASIC uses a string literal that is in a program, it points ** directly to that literal -- in the models that don't use banked RAM ** (Pet/CBM, VIC-20, and 64). The literal is overwritten by the next program -** that's loaded. So, argv[0] would point to machine code. String operations +** that is loaded. So, argv[0] would point to machine code. String operations ** create a new result string -- even when that operation changes nothing. The ** result is put in the string space at the top of BASIC's memory. So, the ""+ ** in this BASIC line guarantees that argv[0] will get a name from a safe place. */ #pragma data-name(push, "LOWCODE") static struct line { - const char end_of_line; - const struct line *const next; + const char end_of_line; /* fake previous line */ + const struct line* const next; const unsigned line_num; - const char load_token, quotes[2], add_token, quote; + const char CLR_token, colon, LOAD_token, quotes[2], add_token, quote; char name[21]; const char comma; char unit[3]; } basic = { - '\0', &basic + 1, /* high byte of link must be non-zero */ - 0, 0x93, "\"\"", 0xaa, '\"', - "\" ", /* format: "123:1234567890123456\"" */ + '\0', &basic + 1, /* high byte of link must be non-zero */ + 0, 0x9C, ':', 0x93, "\"\"", 0xAA, '\"', + "\" ", /* format: "123:1234567890123456\"" */ ',', "01" }; #pragma data-name(pop) /* These values are platform-specific. */ -extern const struct line *txtptr; +extern const void* vartab; /* points to BASIC program variables */ +#pragma zpsym("vartab") +extern const void* memsize; /* points to top of BASIC RAM */ +#pragma zpsym("memsize") +extern const struct line* txtptr; /* points to BASIC code */ #pragma zpsym("txtptr") -extern char basbuf[]; /* BASIC's input buffer */ +extern char basbuf[]; /* BASIC's input buffer */ extern void basbuf_len[]; #pragma zpsym("basbuf_len") @@ -75,43 +79,62 @@ extern void basbuf_len[]; int __fastcall__ exec (const char* progname, const char* cmdline) { static int fd; - static unsigned char dv, n = 0; + static unsigned char dv, n; /* Exclude devices that can't load files. */ + /* (Use hand optimization, to make smaller code.) */ dv = getcurrentdevice (); - if (dv < 8 && dv != 1 || dv > 30) { + if (dv < 8 && __AX__ != 1 || __AX__ > 30) { return _mappederrno (9); /* illegal device number */ } utoa (dv, basic.unit, 10); - /* Don't try to run a program that can't be found. */ - fd = open (progname, O_RDONLY); - if (fd < 0) { - return fd; + /* Tape files can be openned only once; skip this test for the Datasette. */ + if (dv != 1) { + /* Don't try to run a program that can't be found. */ + fd = open (progname, O_RDONLY); + if (fd < 0) { + return -1; + } + close (fd); } - close (fd); + n = 0; do { if ((basic.name[n] = progname[n]) == '\0') { break; } - } while (++n < 20); /* truncate long names */ + } while (++n < 20); /* truncate long names */ basic.name[n] = '\"'; +/* This next part isn't needed by machines that put +** BASIC source and variables in different RAM banks. +*/ +#if !defined(__CBM510__) && !defined(__CBM610__) && !defined(__C128__) + /* cc65 program loads might extend beyond the end of the RAM that is allowed + ** for BASIC. Then, the LOAD statement would complain that it is "out of + ** memory". Some pointers that say where to put BASIC program variables + ** must be changed, so that we do not get that error. One pointer is + ** changed here; a BASIC CLR statement changes the others. + */ + vartab = (char*)memsize - 256; +#endif + /* Build the next program's argument list. */ - basbuf[0] = 0x8f; /* REM token */ + basbuf[0] = 0x8F; /* REM token */ basbuf[1] = '\0'; if (cmdline != NULL) { strncat (basbuf, cmdline, (size_t)basbuf_len - 2); } + /* Tell the ROM where to find that BASIC program. */ #if defined(__CBM510__) || defined(__CBM610__) pokewsys ((unsigned)&txtptr, (unsigned)&basic); #else txtptr = &basic; #endif - /* (The return code, in ST, will be destroyed by LOAD. + /* (The return code, in ST [status], will be destroyed by LOAD. ** So, don't bother to set it here.) */ exit (__AX__); diff --git a/libsrc/cbm/execvars.s b/libsrc/cbm/execvars.s index 02eabc12e..68f8a5d64 100644 --- a/libsrc/cbm/execvars.s +++ b/libsrc/cbm/execvars.s @@ -20,9 +20,15 @@ .include "vic20.inc" .endif - .export _txtptr:zp, _basbuf, _basbuf_len:zp +; exec() is written in C. +; Provide the spellings that the C compiler wants to use. -_txtptr := TXTPTR +.ifdef VARTAB +.exportzp _vartab := VARTAB +.exportzp _memsize := MEMSIZE +.endif -_basbuf := BASIC_BUF -_basbuf_len = BASIC_BUF_LEN +.exportzp _txtptr := TXTPTR + +.export _basbuf := BASIC_BUF +.exportzp _basbuf_len = BASIC_BUF_LEN From 04be8020b60783c0a161de04333d9e39d7de0bff Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 5 Oct 2015 17:18:53 +0300 Subject: [PATCH 02/10] nes: Document whether waitvblank waits for the start or end of vblank --- doc/nes.sgml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/nes.sgml b/doc/nes.sgml index ca9ce72b3..ae8e4a971 100644 --- a/doc/nes.sgml +++ b/doc/nes.sgml @@ -69,7 +69,7 @@ Programs containing NES specific code may use the NES specific functions

-waitvblank +waitvblank - wait until the start of vblank get_tv From 7f409c3edb3155fe2bd6d6c9ee40f8353598ea86 Mon Sep 17 00:00:00 2001 From: Lauri Kasanen Date: Mon, 5 Oct 2015 17:19:36 +0300 Subject: [PATCH 03/10] nes: Expose and document all joypad keys --- doc/nes.sgml | 8 ++++++++ include/nes.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/doc/nes.sgml b/doc/nes.sgml index ae8e4a971..98c25b6af 100644 --- a/doc/nes.sgml +++ b/doc/nes.sgml @@ -123,6 +123,14 @@ No extended memory drivers are currently available for the NES.

+The generic interface doesn't export the start and select buttons. To +test for those, use the defines in nes.h instead of the generic masks. + +Example: + +if (joy_read(0) & KEY_A) + + Mouse drivers

diff --git a/include/nes.h b/include/nes.h index 3ad442280..fd762a09a 100644 --- a/include/nes.h +++ b/include/nes.h @@ -90,6 +90,15 @@ /* No support for dynamically loadable drivers */ #define DYN_DRV 0 +/* The joystick keys - all keys are supported */ +#define KEY_UP 0x10 +#define KEY_DOWN 0x20 +#define KEY_LEFT 0x40 +#define KEY_RIGHT 0x80 +#define KEY_A 0x1 +#define KEY_B 0x2 +#define KEY_SELECT 0x4 +#define KEY_START 0x8 /* The addresses of the static drivers */ From e6008026aacea4d7ea409f518f06ca7a7c91380c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 5 Oct 2015 16:28:16 +0200 Subject: [PATCH 04/10] Fixed bogus formatting of recent contribution. I wasn't in the mood for discussion ;-) --- include/nes.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/include/nes.h b/include/nes.h index fd762a09a..7bf56c995 100644 --- a/include/nes.h +++ b/include/nes.h @@ -91,15 +91,14 @@ #define DYN_DRV 0 /* The joystick keys - all keys are supported */ -#define KEY_UP 0x10 -#define KEY_DOWN 0x20 -#define KEY_LEFT 0x40 -#define KEY_RIGHT 0x80 -#define KEY_A 0x1 -#define KEY_B 0x2 -#define KEY_SELECT 0x4 -#define KEY_START 0x8 - +#define KEY_A 0x01 +#define KEY_B 0x02 +#define KEY_SELECT 0x04 +#define KEY_START 0x08 +#define KEY_UP 0x10 +#define KEY_DOWN 0x20 +#define KEY_LEFT 0x40 +#define KEY_RIGHT 0x80 /* The addresses of the static drivers */ extern void nes_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ From f21e3ae895322bf3d74bc90f63b0a75872a1799a Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Fri, 9 Oct 2015 13:42:25 +0200 Subject: [PATCH 05/10] According to the contributor the prio wasn't intentionally set. --- libsrc/pce/clock.s | 2 +- libsrc/pce/conio.s | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index c6d6fb7fb..8fda58adc 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -21,7 +21,7 @@ .endproc - .constructor initclock, 24 + .constructor initclock initclock: lda #0 diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index bcfc600a7..1428ef59f 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -5,7 +5,7 @@ .import psg_init .import vdc_init - .constructor initconio, 24 + .constructor initconio .macpack longbranch From 575f859a030262b60fce9a0a136c54f4b198ca89 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Fri, 9 Oct 2015 18:33:35 +0200 Subject: [PATCH 06/10] Keep low level VIC sprite stuff out of user code. --- include/mouse.h | 13 ++++++-- libsrc/c128/mcbdefault.s | 34 ++++++++++++++++++++- libsrc/c64/mcbdefault.s | 32 ++++++++++++++++++++ libsrc/cbm/mcbpointercolor.s | 10 +++++++ libsrc/cbm/mcbpointershape.s | 30 +++++++++++++++++++ libsrc/cbm510/mcbdefault.s | 39 ++++++++++++++++++++++++ samples/mousetest.c | 58 ++---------------------------------- 7 files changed, 157 insertions(+), 59 deletions(-) create mode 100644 libsrc/cbm/mcbpointercolor.s create mode 100644 libsrc/cbm/mcbpointershape.s diff --git a/include/mouse.h b/include/mouse.h index ac75956c0..8bd9a00ff 100644 --- a/include/mouse.h +++ b/include/mouse.h @@ -122,6 +122,16 @@ struct mouse_callbacks { /* The default mouse callbacks */ extern const struct mouse_callbacks mouse_def_callbacks; +#if defined(__CBM__) + +/* The default mouse pointer shape used by the default mouse callbacks */ +extern const unsigned char mouse_def_pointershape[63]; + +/* The default mouse pointer color used by the default mouse callbacks */ +extern const unsigned char mouse_def_pointercolor; + +#endif + /* The name of the standard mouse driver for a platform */ extern const char mouse_stddrv[]; @@ -208,6 +218,3 @@ unsigned char __fastcall__ mouse_ioctl (unsigned char code, void* data); /* End of mouse.h */ #endif - - - diff --git a/libsrc/c128/mcbdefault.s b/libsrc/c128/mcbdefault.s index 01c54efca..1951129a6 100644 --- a/libsrc/c128/mcbdefault.s +++ b/libsrc/c128/mcbdefault.s @@ -7,7 +7,10 @@ ; be called from an interrupt handler ; + .constructor initmcb .export _mouse_def_callbacks + .import _mouse_def_pointershape + .import _mouse_def_pointercolor .include "mouse-kernel.inc" .include "c128.inc" @@ -15,16 +18,45 @@ .macpack generic ; Sprite definitions. The first value can be changed to adjust the number -; of the sprite used for the mouse. +; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MEM = $0E00 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register +; -------------------------------------------------------------------------- +; Initialize the mouse sprite. + +.segment "INIT" + +initmcb: + +; Copy the mouse sprite data + + ldx #64 - 1 +@L0: lda _mouse_def_pointershape,x + sta MOUSE_SPR_MEM,x + dex + bpl @L0 + +; Set the mouse sprite pointer + + lda #<(MOUSE_SPR_MEM / 64) + sta $07F8 + MOUSE_SPR + +; Set the mouse sprite color + + lda _mouse_def_pointercolor + sta VIC_SPR0_COLOR + MOUSE_SPR + rts + ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. +.code + hide: lda #MOUSE_SPR_NMASK and VIC_SPR_ENA diff --git a/libsrc/c64/mcbdefault.s b/libsrc/c64/mcbdefault.s index ffeed45b3..c4feddfea 100644 --- a/libsrc/c64/mcbdefault.s +++ b/libsrc/c64/mcbdefault.s @@ -7,7 +7,10 @@ ; be called from an interrupt handler ; + .constructor initmcb .export _mouse_def_callbacks + .import _mouse_def_pointershape + .import _mouse_def_pointercolor .include "mouse-kernel.inc" .include "c64.inc" @@ -17,14 +20,43 @@ ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MEM = $0340 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register +; -------------------------------------------------------------------------- +; Initialize the mouse sprite. + +.segment "INIT" + +initmcb: + +; Copy the mouse sprite data + + ldx #64 - 1 +@L0: lda _mouse_def_pointershape,x + sta MOUSE_SPR_MEM,x + dex + bpl @L0 + +; Set the mouse sprite pointer + + lda #<(MOUSE_SPR_MEM / 64) + sta $07F8 + MOUSE_SPR + +; Set the mouse sprite color + + lda _mouse_def_pointercolor + sta VIC_SPR0_COLOR + MOUSE_SPR + rts + ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. +.code + hide: lda #MOUSE_SPR_NMASK and VIC_SPR_ENA diff --git a/libsrc/cbm/mcbpointercolor.s b/libsrc/cbm/mcbpointercolor.s new file mode 100644 index 000000000..c9cb6330e --- /dev/null +++ b/libsrc/cbm/mcbpointercolor.s @@ -0,0 +1,10 @@ +; VIC sprite color for the mouse pointer + + .export _mouse_def_pointercolor + + +.segment "INIT" + +_mouse_def_pointercolor: + + .byte $01 ; White diff --git a/libsrc/cbm/mcbpointershape.s b/libsrc/cbm/mcbpointershape.s new file mode 100644 index 000000000..7364201b1 --- /dev/null +++ b/libsrc/cbm/mcbpointershape.s @@ -0,0 +1,30 @@ +; VIC sprite data for the mouse pointer (an arrow) + + .export _mouse_def_pointershape + + +.segment "INIT" + +_mouse_def_pointershape: + + .byte %11111110, %00000000, %00000000 + .byte %11111100, %00000000, %00000000 + .byte %11111000, %00000000, %00000000 + .byte %11111100, %00000000, %00000000 + .byte %11011110, %00000000, %00000000 + .byte %10001111, %00000000, %00000000 + .byte %00000111, %10000000, %00000000 + .byte %00000011, %11000000, %00000000 + .byte %00000001, %11100000, %00000000 + .byte %00000000, %11110000, %00000000 + .byte %00000000, %01111000, %00000000 + .byte %00000000, %00111000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 + .byte %00000000, %00000000, %00000000 diff --git a/libsrc/cbm510/mcbdefault.s b/libsrc/cbm510/mcbdefault.s index 028fb4ec1..7542d776d 100644 --- a/libsrc/cbm510/mcbdefault.s +++ b/libsrc/cbm510/mcbdefault.s @@ -8,7 +8,10 @@ ; be called from an interrupt handler. ; + .constructor initmcb .export _mouse_def_callbacks + .import _mouse_def_pointershape + .import _mouse_def_pointercolor .import vic:zp .include "mouse-kernel.inc" @@ -19,14 +22,50 @@ ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on that value. MOUSE_SPR = 0 ; Sprite used for the mouse +MOUSE_SPR_MEM = $F400 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register +; -------------------------------------------------------------------------- +; Initialize the mouse sprite. + +.segment "INIT" + +initmcb: + +; Copy the mouse sprite data + + ldx #64 - 1 +@L0: lda _mouse_def_pointershape,x + sta MOUSE_SPR_MEM,x + dex + bpl @L0 + +; Set the mouse sprite pointer + + lda #<(MOUSE_SPR_MEM / 64) + sta $F3F8 + MOUSE_SPR + +; Set the mouse sprite color + + ldx IndReg + lda #15 + sta IndReg + + lda _mouse_def_pointercolor + ldy VIC_SPR0_COLOR + MOUSE_SPR + sta (vic),y + + stx IndReg + rts + ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. +.code + hide: ldy #15 sty IndReg diff --git a/samples/mousetest.c b/samples/mousetest.c index 7d9409659..4a849cb98 100644 --- a/samples/mousetest.c +++ b/samples/mousetest.c @@ -40,44 +40,11 @@ -#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) +#ifdef __CBM__ -/* Addresses of data for sprite 0 */ -#if defined(__C64__) -# define SPRITE0_DATA ((unsigned char[64])0x0340) -# define SPRITE0_PTR ((unsigned char *)0x07F8) -#elif defined(__C128__) -# define SPRITE0_DATA ((unsigned char[64])0x0E00) -# define SPRITE0_PTR ((unsigned char *)0x07F8) -#elif defined(__CBM510__) -# define SPRITE0_DATA ((unsigned char[64])0xF400) -# define SPRITE0_PTR ((unsigned char *)0xF3F8) -#endif +/* Set dark-on-light colors. */ +const unsigned char mouse_def_pointercolor = COLOR_BLACK; -/* The mouse sprite (an arrow) */ -static const unsigned char MouseSprite[64] = { - 0xFE, 0x00, 0x00, - 0xFC, 0x00, 0x00, - 0xF8, 0x00, 0x00, - 0xFC, 0x00, 0x00, - 0xDE, 0x00, 0x00, - 0x8F, 0x00, 0x00, - 0x07, 0x80, 0x00, - 0x03, 0xC0, 0x00, - 0x01, 0xE0, 0x00, - 0x00, 0xF0, 0x00, - 0x00, 0x78, 0x00, - 0x00, 0x38, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00 -}; #endif @@ -159,25 +126,6 @@ int main (void) cursor (0); clrscr (); - /* The pointer should be created before the driver is installed, - ** in case a lightpen driver needs it during calibration. - */ - -#if defined(__C64__) || defined(__C128__) || defined(__CBM510__) - /* Copy the sprite data */ - memcpy ((void*) SPRITE0_DATA, MouseSprite, sizeof (MouseSprite)); - - /* Set the VIC-II sprite pointer. */ - *SPRITE0_PTR = ((unsigned) SPRITE0_DATA & 0x3FFF) / sizeof SPRITE0_DATA; - - /* Set the color of sprite 0 */ -# ifdef __CBM510__ - pokebsys ((unsigned) &VIC.spr0_color, COLOR_BLACK); -# else - VIC.spr0_color = COLOR_BLACK; -# endif -#endif - /* If a lightpen driver is installed, then it can get a calibration value ** from this file (if it exists). Or, the user can adjust the pen; and, ** the value will be put into this file, for the next time. From 326da8514549afb72cafef5142690feada29170d Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Fri, 9 Oct 2015 21:44:20 +0200 Subject: [PATCH 07/10] Consistently place constructors (and their exclusive subroutines) in "INIT". --- libsrc/atari5200/conioscreen.s | 4 ++-- libsrc/c128/systime.s | 3 +-- libsrc/c64/systime.s | 3 +-- libsrc/osic1p/cgetc.s | 2 ++ libsrc/pce/clock.s | 7 ++++--- libsrc/pce/conio.s | 16 +++++----------- libsrc/pce/psg.s | 2 +- libsrc/pce/vce.s | 2 +- 8 files changed, 17 insertions(+), 22 deletions(-) diff --git a/libsrc/atari5200/conioscreen.s b/libsrc/atari5200/conioscreen.s index 412dd582d..660276675 100644 --- a/libsrc/atari5200/conioscreen.s +++ b/libsrc/atari5200/conioscreen.s @@ -7,9 +7,10 @@ SCREEN_BUF_SIZE = 20 * 24 SCREEN_BUF = $4000 - SCREEN_BUF_SIZE - .code .export screen_setup_20x24 + .segment "INIT" + screen_setup_20x24: ; initialize SAVMSC @@ -79,5 +80,4 @@ dlist: .repeat 3 .assert ((* >> 10) = (dlist >> 10)), error, "Display list crosses 1K boundary" - .end diff --git a/libsrc/c128/systime.s b/libsrc/c128/systime.s index 0a7f8f367..e12d016b8 100644 --- a/libsrc/c128/systime.s +++ b/libsrc/c128/systime.s @@ -63,6 +63,7 @@ BCD2dec:tax ; Constructor that writes to the 1/10 sec register of the TOD to kick it ; into action. If this is not done, the clock hangs. We will read the register ; and write it again, ignoring a possible change in between. +.segment "INIT" .proc initsystime @@ -78,7 +79,6 @@ BCD2dec:tax .endproc - ;---------------------------------------------------------------------------- ; TM struct with date set to 1970-01-01 .data @@ -92,4 +92,3 @@ TM: .word 0 ; tm_sec .word 0 ; tm_wday .word 0 ; tm_yday .word 0 ; tm_isdst - diff --git a/libsrc/c64/systime.s b/libsrc/c64/systime.s index a00df1397..f8cd1b714 100644 --- a/libsrc/c64/systime.s +++ b/libsrc/c64/systime.s @@ -63,6 +63,7 @@ BCD2dec:tax ; Constructor that writes to the 1/10 sec register of the TOD to kick it ; into action. If this is not done, the clock hangs. We will read the register ; and write it again, ignoring a possible change in between. +.segment "INIT" .proc initsystime @@ -81,7 +82,6 @@ BCD2dec:tax .endproc - ;---------------------------------------------------------------------------- ; TM struct with date set to 1970-01-01 .data @@ -95,4 +95,3 @@ TM: .word 0 ; tm_sec .word 0 ; tm_wday .word 0 ; tm_yday .word 0 ; tm_isdst - diff --git a/libsrc/osic1p/cgetc.s b/libsrc/osic1p/cgetc.s index 0c7c69488..5ddca2870 100644 --- a/libsrc/osic1p/cgetc.s +++ b/libsrc/osic1p/cgetc.s @@ -11,12 +11,14 @@ .include "zeropage.inc" ; Initialize one-character buffer that is filled by kbhit() + .segment "INIT" initcgetc: lda #$00 sta CHARBUF ; No character in buffer initially rts ; Input routine from 65V PROM MONITOR, show cursor if enabled + .code _cgetc: lda CHARBUF ; character in buffer available? beq nobuffer diff --git a/libsrc/pce/clock.s b/libsrc/pce/clock.s index 8fda58adc..261739df8 100644 --- a/libsrc/pce/clock.s +++ b/libsrc/pce/clock.s @@ -5,9 +5,11 @@ .include "pce.inc" .include "extzp.inc" - .forceimport ticktock .export _clock + .forceimport ticktock .importzp sreg + .constructor initclock + .proc _clock @@ -21,8 +23,7 @@ .endproc - .constructor initclock - + .segment "INIT" initclock: lda #0 ldx #3 diff --git a/libsrc/pce/conio.s b/libsrc/pce/conio.s index 1428ef59f..64df87018 100644 --- a/libsrc/pce/conio.s +++ b/libsrc/pce/conio.s @@ -1,14 +1,16 @@ .include "pce.inc" .include "extzp.inc" - .import vce_init - .import psg_init - .import vdc_init + .import vce_init + .import psg_init + .import colors + .importzp ptr1, tmp1 .constructor initconio .macpack longbranch + .segment "INIT" initconio: jsr vce_init jsr psg_init @@ -20,7 +22,6 @@ initconio: st2 #>$0088 rts - .import colors set_palette: stz VCE_ADDR_LO stz VCE_ADDR_HI @@ -48,11 +49,6 @@ set_palette: rts -;---------------------------------------------------------------------------- -; -;---------------------------------------------------------------------------- - - .importzp ptr1, tmp1 conio_init: ; Load font st0 #VDC_MAWR @@ -80,13 +76,11 @@ conio_init: sta tmp1 jsr copy - ldx #0 stx BGCOLOR inx stx CHARCOLOR - rts copy: diff --git a/libsrc/pce/psg.s b/libsrc/pce/psg.s index 17d26b941..b1d610fa1 100644 --- a/libsrc/pce/psg.s +++ b/libsrc/pce/psg.s @@ -1,8 +1,8 @@ - .include "pce.inc" .export psg_init + .segment "INIT" psg_init: clx stz PSG_GLOBAL_PAN ; Clear global balance diff --git a/libsrc/pce/vce.s b/libsrc/pce/vce.s index 3c19fd55b..af69c5ed1 100644 --- a/libsrc/pce/vce.s +++ b/libsrc/pce/vce.s @@ -1,8 +1,8 @@ - .include "pce.inc" .export vce_init + .segment "INIT" vce_init: ; Set CTA to zero stz VCE_ADDR_LO From ccc7c2b1f9787e8f6cab7309132ef878082d9d4f Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Fri, 9 Oct 2015 22:18:51 +0200 Subject: [PATCH 08/10] Minor style adjustment. --- libsrc/atari/dosdetect.s | 2 +- libsrc/atari/getargs.s | 2 +- libsrc/atari/getdefdev.s | 2 +- libsrc/atari/mcbpm.s | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/atari/dosdetect.s b/libsrc/atari/dosdetect.s index c60ac479b..654da55b5 100644 --- a/libsrc/atari/dosdetect.s +++ b/libsrc/atari/dosdetect.s @@ -5,7 +5,7 @@ ; .include "atari.inc" - .constructor detect,26 + .constructor detect, 26 .export __dos_type ; ------------------------------------------------------------------------ diff --git a/libsrc/atari/getargs.s b/libsrc/atari/getargs.s index fdae55364..fb3b7bc03 100644 --- a/libsrc/atari/getargs.s +++ b/libsrc/atari/getargs.s @@ -15,7 +15,7 @@ SPACE = 32 ; SPACE char. .import __argc, __argv .importzp ptr1 .import __dos_type - .constructor initmainargs,25 + .constructor initmainargs, 25 ; -------------------------------------------------------------------------- ; Get command line diff --git a/libsrc/atari/getdefdev.s b/libsrc/atari/getdefdev.s index 13aa12e04..47d8714e6 100644 --- a/libsrc/atari/getdefdev.s +++ b/libsrc/atari/getdefdev.s @@ -19,7 +19,7 @@ .export __getdefdev ; get default device .export __defdev ; this is the default device string (e.g. "D1:") .ifdef DYNAMIC_DD - .constructor __getdefdev,24 + .constructor __getdefdev, 24 .endif ; Get default device (LBUF will be destroyed!!) diff --git a/libsrc/atari/mcbpm.s b/libsrc/atari/mcbpm.s index b546faced..c5c5dd433 100644 --- a/libsrc/atari/mcbpm.s +++ b/libsrc/atari/mcbpm.s @@ -10,8 +10,8 @@ .include "atari.inc" .importzp sp .export _mouse_pm_callbacks - .constructor pm_init,27 - .destructor pm_down,7 + .constructor pm_init, 27 + .destructor pm_down ; get mouse shape data .import mouse_pm_bits From c4966ac6a63d148bd524a378cf81bb8617c9e40c Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 10 Oct 2015 11:15:43 +0200 Subject: [PATCH 09/10] Fixed stupid adressing mode bug. Thanks Greg for pointing out :-) --- libsrc/cbm510/mcbdefault.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/cbm510/mcbdefault.s b/libsrc/cbm510/mcbdefault.s index 7542d776d..0db753e92 100644 --- a/libsrc/cbm510/mcbdefault.s +++ b/libsrc/cbm510/mcbdefault.s @@ -55,7 +55,7 @@ initmcb: sta IndReg lda _mouse_def_pointercolor - ldy VIC_SPR0_COLOR + MOUSE_SPR + ldy #VIC_SPR0_COLOR + MOUSE_SPR sta (vic),y stx IndReg From 08efc299ffacac0e13296a33e50ef64be99358e3 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Mon, 12 Oct 2015 20:18:13 +0200 Subject: [PATCH 10/10] Allow to override mouse sprite location data. --- libsrc/c64/mcbdefault.s | 21 +++++++++++++++++---- libsrc/c64/mcbspritedata.s | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 libsrc/c64/mcbspritedata.s diff --git a/libsrc/c64/mcbdefault.s b/libsrc/c64/mcbdefault.s index c4feddfea..cd36d8515 100644 --- a/libsrc/c64/mcbdefault.s +++ b/libsrc/c64/mcbdefault.s @@ -11,6 +11,8 @@ .export _mouse_def_callbacks .import _mouse_def_pointershape .import _mouse_def_pointercolor + .import mcb_spritememory + .import mcb_spritepointer .include "mouse-kernel.inc" .include "c64.inc" @@ -20,7 +22,6 @@ ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse -MOUSE_SPR_MEM = $0340 ; Memory location MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register @@ -33,18 +34,30 @@ VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register initmcb: +; Make all RAM accessible + + lda #$30 + ldy $01 + sei + sta $01 + ; Copy the mouse sprite data ldx #64 - 1 @L0: lda _mouse_def_pointershape,x - sta MOUSE_SPR_MEM,x + sta mcb_spritememory,x dex bpl @L0 ; Set the mouse sprite pointer - lda #<(MOUSE_SPR_MEM / 64) - sta $07F8 + MOUSE_SPR + lda #<(mcb_spritememory / 64) + sta mcb_spritepointer + MOUSE_SPR + +; Restore memory configuration + + sty $01 + cli ; Set the mouse sprite color diff --git a/libsrc/c64/mcbspritedata.s b/libsrc/c64/mcbspritedata.s new file mode 100644 index 000000000..2c7aa1491 --- /dev/null +++ b/libsrc/c64/mcbspritedata.s @@ -0,0 +1,4 @@ +; VIC sprite data for the mouse pointer + + .export mcb_spritememory := $0340 + .export mcb_spritepointer := $07F8