Keep low level VIC sprite stuff out of user code.

This commit is contained in:
Oliver Schmidt 2015-10-09 18:33:35 +02:00
parent f21e3ae895
commit 575f859a03
7 changed files with 157 additions and 59 deletions

View File

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

View File

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

View File

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

View File

@ -0,0 +1,10 @@
; VIC sprite color for the mouse pointer
.export _mouse_def_pointercolor
.segment "INIT"
_mouse_def_pointercolor:
.byte $01 ; White

View File

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

View File

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

View File

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