1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-13 03:29:36 +00:00

Updated the cx16 library to the Commander X16's ROM prerelease 37.

This commit is contained in:
Greg King 2020-05-02 13:46:06 -04:00
parent 31daa706b7
commit cbf0c1d1dd
17 changed files with 447 additions and 233 deletions

View File

@ -7,6 +7,10 @@
.if .def(__CX16__) .if .def(__CX16__)
; CX16 extended jump table ; CX16 extended jump table
ENTROPY_GET := $FECF
KEYBRD_BUF_PUT := $FED2
CONSOLE_SET_PAGE_MSG := $FED5
CONSOLE_PUT_IMAGE := $FED8
CONSOLE_INIT := $FEDB CONSOLE_INIT := $FEDB
CONSOLE_PUT_CHAR := $FEDE CONSOLE_PUT_CHAR := $FEDE
CONSOLE_GET_CHAR := $FEE1 CONSOLE_GET_CHAR := $FEE1

View File

@ -1,5 +1,5 @@
; ;
; CX16 r36 definitions ; CX16 r37 definitions
; ;
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -236,8 +236,8 @@ TXTPTR := $EE ; Pointer into BASIC source code
BASIC_BUF := $0200 ; Location of command-line BASIC_BUF := $0200 ; Location of command-line
BASIC_BUF_LEN = 81 ; Maximum length of command-line BASIC_BUF_LEN = 81 ; Maximum length of command-line
SCREEN_MODE := $0262 ; Current screen mode (set by SCREEN_SET_MODE) SCREEN_MODE := $0261 ; Current screen mode (set by SCREEN_SET_MODE)
SCREEN_PTR := $0263 ; Pointer to current row on text screen (16 bits) SCREEN_PTR := $0262 ; Pointer to current row on text screen (16 bits)
STATUS := $0286 ; Status from previous I/O operation STATUS := $0286 ; Status from previous I/O operation
IN_DEV := $028A ; Current input device number IN_DEV := $028A ; Current input device number
OUT_DEV := $028B ; Current output device number OUT_DEV := $028B ; Current output device number
@ -257,8 +257,8 @@ LLEN := $0386 ; Line length
NLINES := $0387 ; Number of screen lines NLINES := $0387 ; Number of screen lines
; BASIC ; BASIC
VARTAB := $03E3 ; Pointer to start of BASIC variables VARTAB := $03E2 ; Pointer to start of BASIC variables
MEMSIZE := $03EB ; Pointer to highest BASIC RAM location (+1) MEMSIZE := $03EA ; Pointer to highest BASIC RAM location (+1)
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; Vector and other locations ; Vector and other locations
@ -271,9 +271,11 @@ NMIVec := $0318
; I/O locations ; I/O locations
; Video Enhanced Retro Adapter ; Video Enhanced Retro Adapter
; Has audio, SPI, and UART. ; Has audio and SPI.
.scope VERA .scope VERA
; External registers ; External registers
.struct .struct
.org $9F20 .org $9F20
ADDR .faraddr ; Address for data port access ADDR .faraddr ; Address for data port access
@ -282,31 +284,151 @@ NMIVec := $0318
CTRL .byte ; Control register CTRL .byte ; Control register
IRQ_EN .byte ; Interrupt enable bits IRQ_EN .byte ; Interrupt enable bits
IRQ_FLAGS .byte ; Interrupt flags IRQ_FLAGS .byte ; Interrupt flags
IRQ_RASTER .byte ; Line where IRQ will occur
.endstruct .endstruct
.enum ; Address automatic increment amounts .enum ; Address automatic increment amounts
INC0 = 0 << 4 DEC0 = (($00 << 1) | $01) << 3
INC1 = 1 << 4 DEC1 = (($01 << 1) | $01) << 3
INC2 = 2 << 4 DEC2 = (($02 << 1) | $01) << 3
INC4 = 3 << 4 DEC4 = (($03 << 1) | $01) << 3
INC8 = 4 << 4 DEC8 = (($04 << 1) | $01) << 3
INC16 = 5 << 4 DEC16 = (($05 << 1) | $01) << 3
INC32 = 6 << 4 DEC32 = (($06 << 1) | $01) << 3
INC64 = 7 << 4 DEC64 = (($07 << 1) | $01) << 3
INC128 = 8 << 4 DEC128 = (($08 << 1) | $01) << 3
INC256 = 9 << 4 DEC256 = (($09 << 1) | $01) << 3
INC512 = 10 << 4 DEC512 = (($0A << 1) | $01) << 3
INC1024 = 11 << 4 DEC40 = (($0B << 1) | $01) << 3
INC2048 = 12 << 4 DEC80 = (($0C << 1) | $01) << 3
INC4096 = 13 << 4 DEC160 = (($0D << 1) | $01) << 3
INC8192 = 14 << 4 DEC320 = (($0E << 1) | $01) << 3
INC16384 = 15 << 4 DEC640 = (($0F << 1) | $01) << 3
INC0 = (($00 << 1) | $00) << 3
INC1 = (($01 << 1) | $00) << 3
INC2 = (($02 << 1) | $00) << 3
INC4 = (($03 << 1) | $00) << 3
INC8 = (($04 << 1) | $00) << 3
INC16 = (($05 << 1) | $00) << 3
INC32 = (($06 << 1) | $00) << 3
INC64 = (($07 << 1) | $00) << 3
INC128 = (($08 << 1) | $00) << 3
INC256 = (($09 << 1) | $00) << 3
INC512 = (($0A << 1) | $00) << 3
INC40 = (($0B << 1) | $00) << 3
INC80 = (($0C << 1) | $00) << 3
INC160 = (($0D << 1) | $00) << 3
INC320 = (($0E << 1) | $00) << 3
INC640 = (($0F << 1) | $00) << 3
.endenum .endenum
.enum ; Interrupt request flags .enum ; Interrupt request flags
VERT_SYNC = %00000001 VERT_SYNC = %00000001
RASTER = %00000010 RASTER_IRQ = %00000010
SPR_COLLIDED = %00000100 SPR_COLLIDED = %00000100
UART_IRQ = %00001000 AUDIO_LOW = %00001000
.endenum .endenum
.scope DISP ; Display controller
SELECT1 = %00000010
.union
.org $9F29
.struct
; These four registers are visible when the DCSEL flag = %0
VIDEO .byte
HSCALE .byte
VSCALE .byte
FRAME .byte
.endstruct
.struct
; These four registers are visible when the DCSEL flag = %1
HSTART .byte
HSTOP .byte
VSTART .byte
VSTOP .byte
.endstruct
.endunion
.enum MODE ; Output mode
DISABLE = $00
VGA
NTSC
RGB ; Interlaced, composite sync
.endenum
.enum DISABLE
COLOR = %00000100 ; NTSC monochrome
.endenum
.enum ENABLE
LAYER0 = %00010000
LAYER1 = %00100000
SPRITES = %01000000
.endenum
.endscope
.struct L0 ; Display layer 0
.org $9F2D
CONFIG .byte
MAP_BASE .byte
TILE_BASE .byte
HSCROLL .word
VSCROLL .word
.endstruct
.struct L1 ; Display layer 1
.org $9F34
CONFIG .byte
MAP_BASE .byte
TILE_BASE .byte
HSCROLL .word
VSCROLL .word
.endstruct
.enum ; Layer display modes
TILE1BPP = %00000000 | $00
TILE2BPP
TILE4BPP
TILE8BPP
T256C = %00001000
BITMAP1BPP = %00000100 | $00
BITMAP2BPP
BITMAP4BPP
BITMAP8BPP
.endenum
.enum MAP ; Map geometry
WIDTH32 = $00 << 4
WIDTH64 = $01 << 4
WIDTH128 = $02 << 4
WIDTH256 = $03 << 4
HEIGHT32 = $00 << 6
HEIGHT64 = $01 << 6
HEIGHT128 = $02 << 6
HEIGHT256 = $03 << 6
.endenum
.enum TILE ; Tile geometry
WIDTH8 = $00
WIDTH16 = $01
WIDTH320 = WIDTH8
WIDTH640 = WIDTH16
HEIGHT8 = $00 << 1
HEIGHT16 = $01 << 1
.endenum
.scope PCM ; Pulse-Code Modulator
.struct
.org $9F3B
CTRL .byte
RATE .byte
DATA .byte
.endstruct
.enum
STEREO = %00010000
BITS16 = %00100000
RESET = %10000000
.endenum
.endscope
.scope SPI
.struct
.org $9F3E
DATA .byte
CTRL .byte
.endstruct
.enum
SELECT = %00000001
SLOW = %00000010
.endenum
.endscope
; Internal RAM and registers ; Internal RAM and registers
@ -314,150 +436,66 @@ NMIVec := $0318
.org $000000 .org $000000
VRAM .res $020000 ; 128 Kibibytes VRAM .res $020000 ; 128 Kibibytes
.endstruct .endstruct
.scope COMPOSER ; Display composer .scope PSG ; Programmable Sound Generator
.struct .struct
.org $0F0000 PITCH .word
VIDEO .byte VOL .byte ; Left, right channels; volume
HSCALE .byte WAVEFORM .byte ; Wave shape, pulse width
VSCALE .byte
FRAME .byte
HSTART_LO .byte
HSTOP_LO .byte
VSTART_LO .byte
VSTOP_LO .byte
STRTSTOP_HI .byte
IRQ_LINE .word
.endstruct .endstruct
.enum MODE ; Output mode LEFT = %01 << 6
DISABLE = 0 RIGHT = %10 << 6
VGA
NTSC
RGB ; Interlaced, composite sync
.endenum
.enum .enum
ENABLE_COLOR = 0 << 2 PULSE = $00 << 6
DISABLE_COLOR = 1 << 2 ; NTSC monochrome SAWTOOTH = $01 << 6
TRIANGLE = $02 << 6
NOISE = $03 << 6
.endenum .endenum
.struct
.org $01F9C0
VOICES .res $10 * 4
.endstruct
.endscope .endscope
PALETTE := $0F1000 .struct
.struct L0 ; Layer 0 registers .org $01FA00
.org $0F2000 PALETTE .word $0100
CTRL0 .byte ; Display mode control
CTRL1 .byte ; Geometry control
MAP_BASE .addr
TILE_BASE .addr
HSCROLL .word ; Horizontal scroll
VSCROLL .word ; Vertical scroll
.endstruct .endstruct
.struct L1 ; Layer 1 registers (same as layer 0)
.org $0F3000
CTRL0 .byte
CTRL1 .byte
MAP_BASE .addr
TILE_BASE .addr
HSCROLL .word
VSCROLL .word
.endstruct
.enum MAP ; Map geometry
WIDTH32 = 0
WIDTH64
WIDTH128
WIDTH256
HEIGHT32 = 0 << 2
HEIGHT64 = 1 << 2
HEIGHT128 = 2 << 2
HEIGHT256 = 3 << 2
.endenum
.scope TILE ; Tile geometry
.enum
WIDTH8 = 0 << 4
WIDTH16 = 1 << 4
WIDTH320 = WIDTH8
WIDTH640 = WIDTH16
HEIGHT8 = 0 << 5
HEIGHT16 = 1 << 5
.endenum
.enum FLIP
NONE = 0 << 2
HORIZ = 1 << 2
VERT = 2 << 2
BOTH = 3 << 2
.endenum
.endscope
.enum DMODE ; Display modes
TEXT16 = 0 << 5
TEXT256 = 1 << 5
TILE4 = 2 << 5
TILE16 = 3 << 5
TILE256 = 4 << 5
BITMAP4 = 5 << 5
BITMAP16 = 6 << 5
BITMAP256 = 7 << 5
.endenum
.scope SPRITE .scope SPRITE
.struct .struct ; Sprite attributes
.org $0F4000 ADDR .addr ; Address and color mode
CTRL .byte ; Enables sprite engine XX .word ; Co-ordinates
COLLISION .byte YY .word
.endstruct Z_FLIP .byte ; Collision mask, Z-depth, flip bits
.struct ATTRIB ; Sprite attributes SIZE_PAL .byte
.org $0F5000
ADDR .addr ; Address and color mode
XX .word
YY .word
Z_FLIP .byte
SIZE_PAL .byte
.endstruct .endstruct
.enum FLIP .enum FLIP
NONE = 0 NONE = %00000000
HORIZ HORIZ
VERT VERT
BOTH BOTH
.endenum .endenum
.enum DEPTH .enum DEPTH
DISABLE = 0 << 2 DISABLE = $00 << 2
CANVAS = 1 << 2 CANVAS = $01 << 2
LAYER0 = 2 << 2 LAYER0 = $02 << 2
LAYER1 = 3 << 2 LAYER1 = $03 << 2
.endenum .endenum
.enum ; Sprite geometry .enum ; Sprite geometry
WIDTH8 = 0 << 4 WIDTH8 = $00 << 4
WIDTH16 = 1 << 4 WIDTH16 = $01 << 4
WIDTH32 = 2 << 4 WIDTH32 = $02 << 4
WIDTH64 = 3 << 4 WIDTH64 = $03 << 4
HEIGHT8 = 0 << 6 HEIGHT8 = $00 << 6
HEIGHT16 = 1 << 6 HEIGHT16 = $01 << 6
HEIGHT32 = 2 << 6 HEIGHT32 = $02 << 6
HEIGHT64 = 3 << 6 HEIGHT64 = $03 << 6
COLORS16 = 0 << 7 COLORS16 = $00 << 7
COLORS256 = 1 << 7 COLORS256 = $01 << 7
.endenum
.endscope
AUDIO := $0F6000
.scope SPI
.struct
.org $0F7000
DATA .byte
CONTROL .byte
.endstruct
.enum
DESELECT = 0
SELECT
BUSY_MASK = 1 << 1
.endenum
.endscope
.scope UART ; Universal Asyncronous Receiver Transmitter
.struct
.org $0F8000
DATA .byte
STATUS .byte
BPS_DIV .word
.endstruct
.enum MASK
RECEIVE = 1 << 0
TRANSMIT = 1 << 1
.endenum .endenum
.endscope .endscope
.struct
.org $01FC00
SPRITES .res 128 * 8
.endstruct
.endscope .endscope
; 65C22 ; 65C22
@ -516,8 +554,8 @@ NMIVec := $0318
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; Banked RAM and ROM ; Banked RAM and ROM
KEY_COUNT := $A00B ; (bank 0) Number of keys in input buffer KEY_COUNT := $A00A ; (bank 0) Number of keys in input buffer
TIMER := $A03E ; (bank 0) 60 Hz. timer (3 bytes, big-endian) TIMER := $A037 ; (bank 0) 60 Hz. timer (3 bytes, big-endian)
.struct BANK .struct BANK
.org $A000 .org $A000

View File

@ -2,7 +2,8 @@
/* */ /* */
/* cx16.h */ /* cx16.h */
/* */ /* */
/* CX16 system-specific definitions */ /* CX16 system-specific definitions */
/* For prerelease 37 */
/* */ /* */
/* */ /* */
/* This software is provided "as-is", without any expressed or implied */ /* This software is provided "as-is", without any expressed or implied */
@ -140,14 +141,16 @@
/* get_tv() return codes /* get_tv() return codes
** set_tv() argument codes ** set_tv() argument codes
*/ */
#define TV_NONE 0 enum {
#define TV_VGA 1 TV_NONE = 0x00,
#define TV_NTSC_COLOR 2 TV_VGA,
#define TV_RGB 3 TV_NTSC_COLOR,
#define TV_NONE2 4 TV_RGB,
#define TV_VGA2 5 TV_NONE2,
#define TV_NTSC_MONO 6 TV_VGA2,
#define TV_RGB2 7 TV_NTSC_MONO,
TV_RGB2
};
/* Video modes for videomode() */ /* Video modes for videomode() */
#define VIDEOMODE_40x30 0x00 #define VIDEOMODE_40x30 0x00
@ -157,11 +160,47 @@
#define VIDEOMODE_320x200 0x80 #define VIDEOMODE_320x200 0x80
#define VIDEOMODE_SWAP (-1) #define VIDEOMODE_SWAP (-1)
/* VERA's address increment/decrement numbers */
enum {
VERA_DEC_0 = ((0 << 1) | 1) << 3,
VERA_DEC_1 = ((1 << 1) | 1) << 3,
VERA_DEC_2 = ((2 << 1) | 1) << 3,
VERA_DEC_4 = ((3 << 1) | 1) << 3,
VERA_DEC_8 = ((4 << 1) | 1) << 3,
VERA_DEC_16 = ((5 << 1) | 1) << 3,
VERA_DEC_32 = ((6 << 1) | 1) << 3,
VERA_DEC_64 = ((7 << 1) | 1) << 3,
VERA_DEC_128 = ((8 << 1) | 1) << 3,
VERA_DEC_256 = ((9 << 1) | 1) << 3,
VERA_DEC_512 = ((10 << 1) | 1) << 3,
VERA_DEC_40 = ((11 << 1) | 1) << 3,
VERA_DEC_80 = ((12 << 1) | 1) << 3,
VERA_DEC_160 = ((13 << 1) | 1) << 3,
VERA_DEC_320 = ((14 << 1) | 1) << 3,
VERA_DEC_640 = ((15 << 1) | 1) << 3,
VERA_INC_0 = ((0 << 1) | 0) << 3,
VERA_INC_1 = ((1 << 1) | 0) << 3,
VERA_INC_2 = ((2 << 1) | 0) << 3,
VERA_INC_4 = ((3 << 1) | 0) << 3,
VERA_INC_8 = ((4 << 1) | 0) << 3,
VERA_INC_16 = ((5 << 1) | 0) << 3,
VERA_INC_32 = ((6 << 1) | 0) << 3,
VERA_INC_64 = ((7 << 1) | 0) << 3,
VERA_INC_128 = ((8 << 1) | 0) << 3,
VERA_INC_256 = ((9 << 1) | 0) << 3,
VERA_INC_512 = ((10 << 1) | 0) << 3,
VERA_INC_40 = ((11 << 1) | 0) << 3,
VERA_INC_80 = ((12 << 1) | 0) << 3,
VERA_INC_160 = ((13 << 1) | 0) << 3,
VERA_INC_320 = ((14 << 1) | 0) << 3,
VERA_INC_640 = ((15 << 1) | 0) << 3
};
/* VERA's interrupt flags */ /* VERA's interrupt flags */
#define VERA_IRQ_VSYNC 0b00000001 #define VERA_IRQ_VSYNC 0b00000001
#define VERA_IRQ_RASTER 0b00000010 #define VERA_IRQ_RASTER 0b00000010
#define VERA_IRQ_SPR_COLL 0b00000100 #define VERA_IRQ_SPR_COLL 0b00000100
#define VERA_IRQ_UART 0b00001000 #define VERA_IRQ_AUDIO_LOW 0b00001000
/* Define hardware. */ /* Define hardware. */
@ -175,6 +214,44 @@ struct __vera {
unsigned char control; /* Control register */ unsigned char control; /* Control register */
unsigned char irq_enable; /* Interrupt enable bits */ unsigned char irq_enable; /* Interrupt enable bits */
unsigned char irq_flags; /* Interrupt flags */ unsigned char irq_flags; /* Interrupt flags */
unsigned char irq_raster; /* Line where IRQ will occur */
union {
struct { /* Visible when DCSEL flag = 0 */
unsigned char video; /* Flags to enable video layers */
unsigned char hscale; /* Horizontal scale factor */
unsigned char vscale; /* Vertical scale factor */
unsigned char border; /* Border color (NTSC mode) */
};
struct { /* Visible when DCSEL flag = 1 */
unsigned char hstart; /* Horizontal start position */
unsigned char hstop; /* Horizontal stop position */
unsigned char vstart; /* Vertical start position */
unsigned char vstop; /* Vertical stop position */
};
} display;
struct {
unsigned char config; /* Layer map geometry */
unsigned char mapbase; /* Map data address */
unsigned char tilebase; /* Tile address and geometry */
unsigned int hscroll; /* Smooth scroll horizontal offset */
unsigned int vscroll; /* Smooth scroll vertical offset */
} layer0;
struct {
unsigned char config;
unsigned char mapbase;
unsigned char tilebase;
unsigned int hscroll;
unsigned int vscroll;
} layer1;
struct {
unsigned char control; /* PCM format */
unsigned char rate; /* Sample rate */
unsigned char data; /* PCM output queue */
} audio; /* Pulse-Code Modulation registers */
struct {
unsigned char data;
unsigned char control;
} spi; /* SD card interface */
}; };
#define VERA (*(volatile struct __vera *)0x9F20) #define VERA (*(volatile struct __vera *)0x9F20)
@ -214,7 +291,7 @@ extern void cx16_std_mou[]; /* Referred to by mouse_static_stddrv[]
unsigned char get_numbanks (void); unsigned short get_numbanks (void);
/* Return the number of RAM banks that the machine has. */ /* Return the number of RAM banks that the machine has. */
signed char get_ostype (void); signed char get_ostype (void);
@ -234,6 +311,17 @@ void __fastcall__ set_tv (unsigned char type);
** Call with a TV_xx constant. ** Call with a TV_xx constant.
*/ */
unsigned char __fastcall__ vera_layer_enable (unsigned char layers);
/* Display the layers that are "named" by the bit flags in layers.
** A value of 0b01 shows layer 0, a value of 0b10 shows layer 1,
** a value of 0b11 shows both layers. Return the previous value.
*/
unsigned char __fastcall__ vera_sprites_enable (unsigned char mode);
/* Enable the sprite engine when mode is non-zero (true);
** disable sprites when mode is zero. Return the previous mode.
*/
signed char __fastcall__ videomode (signed char mode); signed char __fastcall__ videomode (signed char mode);
/* Set the video mode, return the old mode. /* Set the video mode, return the old mode.
** Return -1 if Mode isn't valid. ** Return -1 if Mode isn't valid.

View File

@ -1,5 +1,5 @@
; ;
; 2019-09-23, Greg King ; 2020-05-02, Greg King
; ;
; unsigned char __fastcall__ bordercolor (unsigned char color); ; unsigned char __fastcall__ bordercolor (unsigned char color);
; /* Set the color for the border. The old color setting is returned. */ ; /* Set the color for the border. The old color setting is returned. */
@ -11,17 +11,7 @@
_bordercolor: _bordercolor:
tax tax
stz VERA::CTRL ; Use display register bank 0
; Point to the border color register. lda VERA::DISP::FRAME ; get old value
stx VERA::DISP::FRAME ; set new value
stz VERA::CTRL ; Use port 0
lda #<VERA::COMPOSER::FRAME
sta VERA::ADDR
lda #>VERA::COMPOSER::FRAME
sta VERA::ADDR+1
ldy #^VERA::COMPOSER::FRAME | VERA::INC0
sty VERA::ADDR+2
lda VERA::DATA0 ; get old value
stx VERA::DATA0 ; set new value
rts rts

View File

@ -1,6 +1,6 @@
; ;
; 2016-02-28, Groepaz ; 2016-02-28, Groepaz
; 2019-09-25, Greg King ; 2020-04-29, Greg King
; ;
; char cpeekc (void); ; char cpeekc (void);
; /* Return the character from the current cursor position. */ ; /* Return the character from the current cursor position. */
@ -12,8 +12,6 @@
_cpeekc: _cpeekc:
php
sei ; don't let cursor blinking interfere
stz VERA::CTRL ; use port 0 stz VERA::CTRL ; use port 0
lda CURS_Y lda CURS_Y
sta VERA::ADDR+1 ; set row number sta VERA::ADDR+1 ; set row number
@ -22,7 +20,6 @@ _cpeekc:
asl a ; each character has two bytes asl a ; each character has two bytes
sta VERA::ADDR sta VERA::ADDR
lda VERA::DATA0 ; get screen code lda VERA::DATA0 ; get screen code
plp
ldx #>$0000 ldx #>$0000
and #<~%10000000 ; remove reverse bit and #<~%10000000 ; remove reverse bit

View File

@ -1,5 +1,5 @@
; ;
; 2019-09-25, Greg King ; 2020-04-30, Greg King
; ;
; unsigned char cpeekcolor (void); ; unsigned char cpeekcolor (void);
; /* Return the colors from the current cursor position. */ ; /* Return the colors from the current cursor position. */
@ -12,8 +12,15 @@
_cpeekcolor: _cpeekcolor:
php php
lda CURS_FLAG ; is the cursor currently off?
bne @L1
sei ; don't let cursor blinking interfere sei ; don't let cursor blinking interfere
stz VERA::CTRL ; use port 0 ldx CURS_STATE ; is cursor currently displayed?
beq @L1 ; jump if not
lda CURS_COLOR ; get color under cursor
bra @L2
@L1: stz VERA::CTRL ; use port 0
lda CURS_Y lda CURS_Y
sta VERA::ADDR+1 ; set row number sta VERA::ADDR+1 ; set row number
stz VERA::ADDR+2 stz VERA::ADDR+2
@ -21,7 +28,7 @@ _cpeekcolor:
sec ; color attribute is second byte sec ; color attribute is second byte
rol a rol a
sta VERA::ADDR sta VERA::ADDR
lda VERA::DATA0 ; get color lda VERA::DATA0 ; get color of character
plp @L2: plp
ldx #>$0000 ldx #>$0000
rts rts

View File

@ -1,6 +1,6 @@
; ;
; 2016-02-28, Groepaz ; 2016-02-28, Groepaz
; 2019-09-25, Greg King ; 2020-04-30, Greg King
; ;
; unsigned char cpeekrevers (void); ; unsigned char cpeekrevers (void);
; /* Return the reverse attribute from the current cursor position. ; /* Return the reverse attribute from the current cursor position.
@ -15,8 +15,15 @@
_cpeekrevers: _cpeekrevers:
php php
lda CURS_FLAG ; is the cursor currently off?
bne @L1
sei ; don't let cursor blinking interfere sei ; don't let cursor blinking interfere
stz VERA::CTRL ; use port 0 ldx CURS_STATE ; is cursor currently displayed?
beq @L1 ; jump if not
lda CURS_CHAR ; get screen code under cursor
bra @L2
@L1: stz VERA::CTRL ; use port 0
lda CURS_Y lda CURS_Y
sta VERA::ADDR+1 ; set row number sta VERA::ADDR+1 ; set row number
stz VERA::ADDR+2 stz VERA::ADDR+2
@ -24,7 +31,7 @@ _cpeekrevers:
asl a ; each character has two bytes asl a ; each character has two bytes
sta VERA::ADDR sta VERA::ADDR
lda VERA::DATA0 ; get screen code lda VERA::DATA0 ; get screen code
plp @L2: plp
and #%10000000 ; get reverse bit and #%10000000 ; get reverse bit
asl a asl a
tax ; ldx #>$0000 tax ; ldx #>$0000

View File

@ -86,9 +86,9 @@ putchar:
stz VERA::CTRL ; Use port 0 stz VERA::CTRL ; Use port 0
lda CURS_Y lda CURS_Y
sta VERA::ADDR+1 ; Set row number sta VERA::ADDR+1 ; Set row number
lda #VERA::INC1 ; Increment address by one lda #VERA::INC1 ; Address increments by one
sta VERA::ADDR+2 sta VERA::ADDR+2
ldy CURS_X ; Get character column ldy CURS_X ; Get character column into .Y
tya tya
asl a ; Each character has two bytes asl a ; Each character has two bytes
sta VERA::ADDR sta VERA::ADDR

View File

@ -22,7 +22,7 @@
Start: tsx Start: tsx
stx spsave ; Save the system stack ptr stx spsave ; Save the system stack ptr
; Save space by putting some of the start-up code in the ONCE segment, ; Save space by putting some of the start-up code in the ONCE segment
; which will be re-used by the BSS segment, the heap, and the C stack. ; which will be re-used by the BSS segment, the heap, and the C stack.
jsr init jsr init
@ -31,7 +31,7 @@ Start: tsx
jsr zerobss jsr zerobss
; Push the command-line arguments; and, call main(). ; Push the command-line arguments, and call main().
jsr callmain jsr callmain
@ -46,7 +46,7 @@ _exit:
jsr donelib jsr donelib
.if 0 ; We don't need to preserve zero-page space for cc65's variables. .if 0 ; (We don't need to preserve zero-page space for cc65's variables.)
; Copy back the zero-page stuff. ; Copy back the zero-page stuff.
ldx #zpspace-1 ldx #zpspace-1
@ -90,7 +90,7 @@ init:
lda #$01 lda #$01
sta VIA1::PRA sta VIA1::PRA
.if 0 ; We don't need to preserve zero-page space for cc65's variables. .if 0 ; (We don't need to preserve zero-page space for cc65's variables.)
; Save the zero-page locations that we need. ; Save the zero-page locations that we need.
ldx #zpspace-1 ldx #zpspace-1

View File

@ -1,7 +1,7 @@
/* /*
** Program-chaining function for Commodore platforms. ** Program-chaining function for Commodore platforms.
** **
** 2019-12-25, Greg King ** 2020-04-27, Greg King
** **
** This function exploits the program-chaining feature in Commander X16 BASIC's ROM. ** This function exploits the program-chaining feature in Commander X16 BASIC's ROM.
** **
@ -71,26 +71,28 @@ extern void basbuf_len[];
int __fastcall__ exec (const char* progname, const char* cmdline) int __fastcall__ exec (const char* progname, const char* cmdline)
{ {
#if 0
static int fd; static int fd;
#endif
static unsigned char dv, n; static unsigned char dv, n;
/* Exclude devices that can't load files. */ /* Exclude devices that can't load files. */
/* (Use hand optimization, to make smaller code.) */ /* (Use hand optimization, to make smaller code.) */
dv = getcurrentdevice (); dv = getcurrentdevice ();
if (dv < 8 && __AX__ != 1 || __AX__ > 30) { if (dv < 8 || __A__ > 30) {
return _mappederrno (9); /* illegal device number */ return _mappederrno (9); /* illegal device number */
} }
utoa (dv, basic.unit, 10); utoa (dv, basic.unit, 10);
/* The emulator supports only loading and saving on its file-system. */ /* The emulator supports only loading and saving on its file-system. */
if (dv != 1) { #if 0
/* Don't try to run a program that doesn't exist. */ /* Don't try to run a program that doesn't exist. */
fd = open (progname, O_RDONLY); fd = open (progname, O_RDONLY);
if (fd < 0) { if (fd < 0) {
return _mappederrno (4); /* file not found */ return _mappederrno (4); /* file not found */
}
close (fd);
} }
close (fd);
#endif
n = 0; n = 0;
do { do {

View File

@ -1,11 +1,12 @@
; ;
; 2020-01-10, Greg King ; 2020-01-29, Greg King
; ;
; unsigned char get_numbanks (void); ; unsigned short get_numbanks (void);
; /* Return the number of RAM banks that the machine has. */ ; /* Return the number of RAM banks that the machine has. */
; ;
; The Commander X16 version of MEMTOP returns with an extra value: ; The Commander X16 version of MEMTOP returns with an extra value:
; The accumulator describes the number of RAM banks that exist on the hardware. ; The accumulator describes the number of RAM banks that exist on the hardware.
; A zero accumulator means that there are 256 RAM banks.
; ;
.export _get_numbanks .export _get_numbanks
@ -17,4 +18,7 @@ _get_numbanks:
sec sec
jsr MEMTOP jsr MEMTOP
ldx #>$0000 ldx #>$0000
rts cmp #<$0100 ; are there 256 banks?
bne :+
inx ; yes
: rts

View File

@ -1,5 +1,5 @@
; ;
; 2019-12-22, Greg King ; 2020-05-02, Greg King
; ;
; unsigned char get_tv (void); ; unsigned char get_tv (void);
; /* Return the video mode the machine is using. */ ; /* Return the video mode the machine is using. */
@ -11,17 +11,9 @@
.proc _get_tv .proc _get_tv
; Point to the video output register. stz VERA::CTRL ; Use display register bank 0
lda VERA::DISP::VIDEO
stz VERA::CTRL ; Use port 0 and #%00000111 ; Get the type of output signal
lda #<VERA::COMPOSER::VIDEO ldx #>$0000 ; Promote to unsigned int
ldx #>VERA::COMPOSER::VIDEO
ldy #^VERA::COMPOSER::VIDEO
sta VERA::ADDR
stx VERA::ADDR+1
sty VERA::ADDR+2
lda VERA::DATA0
and #$07 ; Get the type of output signal
rts rts
.endproc .endproc

View File

@ -1,11 +1,15 @@
; ;
; 2020-01-06, Greg King ; 2020-04-27, Greg King
; ;
; CX16 Kernal functions ; CX16 Kernal functions
; ;
.include "cbm_kernal.inc" .include "cbm_kernal.inc"
.export ENTROPY_GET
.export KEYBRD_BUF_PUT
.export CONSOLE_SET_PAGE_MSG
.export CONSOLE_PUT_IMAGE
.export CONSOLE_INIT .export CONSOLE_INIT
.export CONSOLE_PUT_CHAR .export CONSOLE_PUT_CHAR
.export CONSOLE_GET_CHAR .export CONSOLE_GET_CHAR

View File

@ -0,0 +1,39 @@
;
; 2020-05-02, Greg King
;
; unsigned char __fastcall__ vera_layer_enable (unsigned char layers);
; /* Display the layers that are "named" by the bit flags in layers.
; ** A value of 0b01 shows layer 0, a value of 0b10 shows layer 1,
; ** a value of 0b11 shows both layers. Return the previous value.
; */
;
.export _vera_layer_enable
.include "cx16.inc"
mask = VERA::DISP::ENABLE::LAYER1 | VERA::DISP::ENABLE::LAYER0
.proc _vera_layer_enable
stz VERA::CTRL ; Use display register bank 0
asl a
asl a ; Shift new flags into position
asl a
asl a
ldy VERA::DISP::VIDEO
eor VERA::DISP::VIDEO
and #mask
eor VERA::DISP::VIDEO ; Replace old flags with new flags
sta VERA::DISP::VIDEO
tya
and #mask ; Get old flags
lsr a
lsr a
lsr a
lsr a
ldx #>$0000
rts
.endproc

14
libsrc/cx16/randomize.s Normal file
View File

@ -0,0 +1,14 @@
;
; 2020-05-02, Greg King
;
; void _randomize (void);
; /* Initialize the random number generator */
;
.export __randomize
.import ENTROPY_GET, _srand
__randomize:
jsr ENTROPY_GET
jmp _srand ; Initialize generator

View File

@ -1,5 +1,5 @@
; ;
; 2019-12-22, Greg King ; 2020-05-02, Greg King
; ;
; void __fastcall__ set_tv (unsigned char); ; void __fastcall__ set_tv (unsigned char);
; /* Set the video mode the machine will use. */ ; /* Set the video mode the machine will use. */
@ -11,16 +11,10 @@
.proc _set_tv .proc _set_tv
; Point to the video output register. stz VERA::CTRL ; Use display register bank 0
eor VERA::DISP::VIDEO
stz VERA::CTRL ; Use port 0 and #%00000111
ldx #<VERA::COMPOSER::VIDEO eor VERA::DISP::VIDEO ; Replace old mode with new mode
ldy #>VERA::COMPOSER::VIDEO sta VERA::DISP::VIDEO
stx VERA::ADDR
sty VERA::ADDR+1
ldx #^VERA::COMPOSER::VIDEO
stx VERA::ADDR+2
sta VERA::DATA0
rts rts
.endproc .endproc

View File

@ -0,0 +1,34 @@
;
; 2020-05-02, Greg King
;
; unsigned char __fastcall__ vera_sprites_enable (unsigned char mode);
; /* Enable the sprite engine when mode is non-zero (true);
; ** disable sprites when mode is zero. Return the previous mode.
; */
;
.export _vera_sprites_enable
.include "cx16.inc"
.proc _vera_sprites_enable
stz VERA::CTRL ; Use display register bank 0
tax ; Is mode true?
beq :+
lda #VERA::DISP::ENABLE::SPRITES ; Yes
: ldy VERA::DISP::VIDEO
eor VERA::DISP::VIDEO
and #VERA::DISP::ENABLE::SPRITES
eor VERA::DISP::VIDEO ; Replace old flag with new flag
sta VERA::DISP::VIDEO
tya
and #VERA::DISP::ENABLE::SPRITES ; Get old value
asl a
asl a
rol a ; Make it boolean
ldx #>$0000
rts
.endproc