From cbf0c1d1dddc9d201ef3bf6ce9f3d5b54bc6e325 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sat, 2 May 2020 13:46:06 -0400 Subject: [PATCH] Updated the cx16 library to the Commander X16's ROM prerelease 37. --- asminc/cbm_kernal.inc | 4 + asminc/cx16.inc | 344 +++++++++++++++++++---------------- include/cx16.h | 110 +++++++++-- libsrc/cx16/bordercolor.s | 18 +- libsrc/cx16/cpeekc.s | 5 +- libsrc/cx16/cpeekcolor.s | 15 +- libsrc/cx16/cpeekrevers.s | 13 +- libsrc/cx16/cputc.s | 4 +- libsrc/cx16/crt0.s | 8 +- libsrc/cx16/exec.c | 20 +- libsrc/cx16/get_numbanks.s | 10 +- libsrc/cx16/get_tv.s | 18 +- libsrc/cx16/kernal.s | 6 +- libsrc/cx16/layer_enable.s | 39 ++++ libsrc/cx16/randomize.s | 14 ++ libsrc/cx16/set_tv.s | 18 +- libsrc/cx16/sprites_enable.s | 34 ++++ 17 files changed, 447 insertions(+), 233 deletions(-) create mode 100644 libsrc/cx16/layer_enable.s create mode 100644 libsrc/cx16/randomize.s create mode 100644 libsrc/cx16/sprites_enable.s diff --git a/asminc/cbm_kernal.inc b/asminc/cbm_kernal.inc index 7125f1253..981687206 100644 --- a/asminc/cbm_kernal.inc +++ b/asminc/cbm_kernal.inc @@ -7,6 +7,10 @@ .if .def(__CX16__) ; CX16 extended jump table + ENTROPY_GET := $FECF + KEYBRD_BUF_PUT := $FED2 + CONSOLE_SET_PAGE_MSG := $FED5 + CONSOLE_PUT_IMAGE := $FED8 CONSOLE_INIT := $FEDB CONSOLE_PUT_CHAR := $FEDE CONSOLE_GET_CHAR := $FEE1 diff --git a/asminc/cx16.inc b/asminc/cx16.inc index 06cc30199..8891c1761 100644 --- a/asminc/cx16.inc +++ b/asminc/cx16.inc @@ -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_LEN = 81 ; Maximum length of command-line -SCREEN_MODE := $0262 ; Current screen mode (set by SCREEN_SET_MODE) -SCREEN_PTR := $0263 ; Pointer to current row on text screen (16 bits) +SCREEN_MODE := $0261 ; Current screen mode (set by SCREEN_SET_MODE) +SCREEN_PTR := $0262 ; Pointer to current row on text screen (16 bits) STATUS := $0286 ; Status from previous I/O operation IN_DEV := $028A ; Current input device number OUT_DEV := $028B ; Current output device number @@ -257,8 +257,8 @@ LLEN := $0386 ; Line length NLINES := $0387 ; Number of screen lines ; BASIC -VARTAB := $03E3 ; Pointer to start of BASIC variables -MEMSIZE := $03EB ; Pointer to highest BASIC RAM location (+1) +VARTAB := $03E2 ; Pointer to start of BASIC variables +MEMSIZE := $03EA ; Pointer to highest BASIC RAM location (+1) ; --------------------------------------------------------------------------- ; Vector and other locations @@ -271,9 +271,11 @@ NMIVec := $0318 ; I/O locations ; Video Enhanced Retro Adapter -; Has audio, SPI, and UART. -.scope VERA +; Has audio and SPI. +.scope VERA + ; External registers + .struct .org $9F20 ADDR .faraddr ; Address for data port access @@ -282,31 +284,151 @@ NMIVec := $0318 CTRL .byte ; Control register IRQ_EN .byte ; Interrupt enable bits IRQ_FLAGS .byte ; Interrupt flags + IRQ_RASTER .byte ; Line where IRQ will occur .endstruct .enum ; Address automatic increment amounts - INC0 = 0 << 4 - INC1 = 1 << 4 - INC2 = 2 << 4 - INC4 = 3 << 4 - INC8 = 4 << 4 - INC16 = 5 << 4 - INC32 = 6 << 4 - INC64 = 7 << 4 - INC128 = 8 << 4 - INC256 = 9 << 4 - INC512 = 10 << 4 - INC1024 = 11 << 4 - INC2048 = 12 << 4 - INC4096 = 13 << 4 - INC8192 = 14 << 4 - INC16384 = 15 << 4 + DEC0 = (($00 << 1) | $01) << 3 + DEC1 = (($01 << 1) | $01) << 3 + DEC2 = (($02 << 1) | $01) << 3 + DEC4 = (($03 << 1) | $01) << 3 + DEC8 = (($04 << 1) | $01) << 3 + DEC16 = (($05 << 1) | $01) << 3 + DEC32 = (($06 << 1) | $01) << 3 + DEC64 = (($07 << 1) | $01) << 3 + DEC128 = (($08 << 1) | $01) << 3 + DEC256 = (($09 << 1) | $01) << 3 + DEC512 = (($0A << 1) | $01) << 3 + DEC40 = (($0B << 1) | $01) << 3 + DEC80 = (($0C << 1) | $01) << 3 + DEC160 = (($0D << 1) | $01) << 3 + DEC320 = (($0E << 1) | $01) << 3 + 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 .enum ; Interrupt request flags VERT_SYNC = %00000001 - RASTER = %00000010 + RASTER_IRQ = %00000010 SPR_COLLIDED = %00000100 - UART_IRQ = %00001000 + AUDIO_LOW = %00001000 .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 @@ -314,150 +436,66 @@ NMIVec := $0318 .org $000000 VRAM .res $020000 ; 128 Kibibytes .endstruct - .scope COMPOSER ; Display composer + .scope PSG ; Programmable Sound Generator .struct - .org $0F0000 - VIDEO .byte - HSCALE .byte - VSCALE .byte - FRAME .byte - HSTART_LO .byte - HSTOP_LO .byte - VSTART_LO .byte - VSTOP_LO .byte - STRTSTOP_HI .byte - IRQ_LINE .word + PITCH .word + VOL .byte ; Left, right channels; volume + WAVEFORM .byte ; Wave shape, pulse width .endstruct - .enum MODE ; Output mode - DISABLE = 0 - VGA - NTSC - RGB ; Interlaced, composite sync - .endenum + LEFT = %01 << 6 + RIGHT = %10 << 6 .enum - ENABLE_COLOR = 0 << 2 - DISABLE_COLOR = 1 << 2 ; NTSC monochrome + PULSE = $00 << 6 + SAWTOOTH = $01 << 6 + TRIANGLE = $02 << 6 + NOISE = $03 << 6 .endenum + .struct + .org $01F9C0 + VOICES .res $10 * 4 + .endstruct .endscope - PALETTE := $0F1000 - .struct L0 ; Layer 0 registers - .org $0F2000 - CTRL0 .byte ; Display mode control - CTRL1 .byte ; Geometry control - MAP_BASE .addr - TILE_BASE .addr - HSCROLL .word ; Horizontal scroll - VSCROLL .word ; Vertical scroll + .struct + .org $01FA00 + PALETTE .word $0100 .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 - .struct - .org $0F4000 - CTRL .byte ; Enables sprite engine - COLLISION .byte - .endstruct - .struct ATTRIB ; Sprite attributes - .org $0F5000 - ADDR .addr ; Address and color mode - XX .word - YY .word - Z_FLIP .byte - SIZE_PAL .byte + .struct ; Sprite attributes + ADDR .addr ; Address and color mode + XX .word ; Co-ordinates + YY .word + Z_FLIP .byte ; Collision mask, Z-depth, flip bits + SIZE_PAL .byte .endstruct .enum FLIP - NONE = 0 + NONE = %00000000 HORIZ VERT BOTH .endenum .enum DEPTH - DISABLE = 0 << 2 - CANVAS = 1 << 2 - LAYER0 = 2 << 2 - LAYER1 = 3 << 2 + DISABLE = $00 << 2 + CANVAS = $01 << 2 + LAYER0 = $02 << 2 + LAYER1 = $03 << 2 .endenum .enum ; Sprite geometry - WIDTH8 = 0 << 4 - WIDTH16 = 1 << 4 - WIDTH32 = 2 << 4 - WIDTH64 = 3 << 4 - HEIGHT8 = 0 << 6 - HEIGHT16 = 1 << 6 - HEIGHT32 = 2 << 6 - HEIGHT64 = 3 << 6 - COLORS16 = 0 << 7 - COLORS256 = 1 << 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 + WIDTH8 = $00 << 4 + WIDTH16 = $01 << 4 + WIDTH32 = $02 << 4 + WIDTH64 = $03 << 4 + HEIGHT8 = $00 << 6 + HEIGHT16 = $01 << 6 + HEIGHT32 = $02 << 6 + HEIGHT64 = $03 << 6 + COLORS16 = $00 << 7 + COLORS256 = $01 << 7 .endenum .endscope + .struct + .org $01FC00 + SPRITES .res 128 * 8 + .endstruct .endscope ; 65C22 @@ -516,8 +554,8 @@ NMIVec := $0318 ; --------------------------------------------------------------------------- ; Banked RAM and ROM -KEY_COUNT := $A00B ; (bank 0) Number of keys in input buffer -TIMER := $A03E ; (bank 0) 60 Hz. timer (3 bytes, big-endian) +KEY_COUNT := $A00A ; (bank 0) Number of keys in input buffer +TIMER := $A037 ; (bank 0) 60 Hz. timer (3 bytes, big-endian) .struct BANK .org $A000 diff --git a/include/cx16.h b/include/cx16.h index 6ceb605c9..253fa2482 100644 --- a/include/cx16.h +++ b/include/cx16.h @@ -2,7 +2,8 @@ /* */ /* cx16.h */ /* */ -/* CX16 system-specific definitions */ +/* CX16 system-specific definitions */ +/* For prerelease 37 */ /* */ /* */ /* This software is provided "as-is", without any expressed or implied */ @@ -140,14 +141,16 @@ /* get_tv() return codes ** set_tv() argument codes */ -#define TV_NONE 0 -#define TV_VGA 1 -#define TV_NTSC_COLOR 2 -#define TV_RGB 3 -#define TV_NONE2 4 -#define TV_VGA2 5 -#define TV_NTSC_MONO 6 -#define TV_RGB2 7 +enum { + TV_NONE = 0x00, + TV_VGA, + TV_NTSC_COLOR, + TV_RGB, + TV_NONE2, + TV_VGA2, + TV_NTSC_MONO, + TV_RGB2 +}; /* Video modes for videomode() */ #define VIDEOMODE_40x30 0x00 @@ -157,11 +160,47 @@ #define VIDEOMODE_320x200 0x80 #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 */ #define VERA_IRQ_VSYNC 0b00000001 #define VERA_IRQ_RASTER 0b00000010 #define VERA_IRQ_SPR_COLL 0b00000100 -#define VERA_IRQ_UART 0b00001000 +#define VERA_IRQ_AUDIO_LOW 0b00001000 /* Define hardware. */ @@ -175,6 +214,44 @@ struct __vera { unsigned char control; /* Control register */ unsigned char irq_enable; /* Interrupt enable bits */ 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) @@ -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. */ signed char get_ostype (void); @@ -234,6 +311,17 @@ void __fastcall__ set_tv (unsigned char type); ** 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); /* Set the video mode, return the old mode. ** Return -1 if Mode isn't valid. diff --git a/libsrc/cx16/bordercolor.s b/libsrc/cx16/bordercolor.s index 6691e2ec5..d152d1aa6 100644 --- a/libsrc/cx16/bordercolor.s +++ b/libsrc/cx16/bordercolor.s @@ -1,5 +1,5 @@ ; -; 2019-09-23, Greg King +; 2020-05-02, Greg King ; ; unsigned char __fastcall__ bordercolor (unsigned char color); ; /* Set the color for the border. The old color setting is returned. */ @@ -11,17 +11,7 @@ _bordercolor: tax - - ; Point to the border color register. - - stz VERA::CTRL ; Use port 0 - 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 + stz VERA::CTRL ; Use display register bank 0 + lda VERA::DISP::FRAME ; get old value + stx VERA::DISP::FRAME ; set new value rts diff --git a/libsrc/cx16/cpeekc.s b/libsrc/cx16/cpeekc.s index f7a7d2081..6756d995a 100644 --- a/libsrc/cx16/cpeekc.s +++ b/libsrc/cx16/cpeekc.s @@ -1,6 +1,6 @@ ; ; 2016-02-28, Groepaz -; 2019-09-25, Greg King +; 2020-04-29, Greg King ; ; char cpeekc (void); ; /* Return the character from the current cursor position. */ @@ -12,8 +12,6 @@ _cpeekc: - php - sei ; don't let cursor blinking interfere stz VERA::CTRL ; use port 0 lda CURS_Y sta VERA::ADDR+1 ; set row number @@ -22,7 +20,6 @@ _cpeekc: asl a ; each character has two bytes sta VERA::ADDR lda VERA::DATA0 ; get screen code - plp ldx #>$0000 and #<~%10000000 ; remove reverse bit diff --git a/libsrc/cx16/cpeekcolor.s b/libsrc/cx16/cpeekcolor.s index 4e3a39a2c..9c167b07a 100644 --- a/libsrc/cx16/cpeekcolor.s +++ b/libsrc/cx16/cpeekcolor.s @@ -1,5 +1,5 @@ ; -; 2019-09-25, Greg King +; 2020-04-30, Greg King ; ; unsigned char cpeekcolor (void); ; /* Return the colors from the current cursor position. */ @@ -12,8 +12,15 @@ _cpeekcolor: php + lda CURS_FLAG ; is the cursor currently off? + bne @L1 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 sta VERA::ADDR+1 ; set row number stz VERA::ADDR+2 @@ -21,7 +28,7 @@ _cpeekcolor: sec ; color attribute is second byte rol a sta VERA::ADDR - lda VERA::DATA0 ; get color - plp + lda VERA::DATA0 ; get color of character +@L2: plp ldx #>$0000 rts diff --git a/libsrc/cx16/cpeekrevers.s b/libsrc/cx16/cpeekrevers.s index 15131d348..fd7428779 100644 --- a/libsrc/cx16/cpeekrevers.s +++ b/libsrc/cx16/cpeekrevers.s @@ -1,6 +1,6 @@ ; ; 2016-02-28, Groepaz -; 2019-09-25, Greg King +; 2020-04-30, Greg King ; ; unsigned char cpeekrevers (void); ; /* Return the reverse attribute from the current cursor position. @@ -15,8 +15,15 @@ _cpeekrevers: php + lda CURS_FLAG ; is the cursor currently off? + bne @L1 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 sta VERA::ADDR+1 ; set row number stz VERA::ADDR+2 @@ -24,7 +31,7 @@ _cpeekrevers: asl a ; each character has two bytes sta VERA::ADDR lda VERA::DATA0 ; get screen code - plp +@L2: plp and #%10000000 ; get reverse bit asl a tax ; ldx #>$0000 diff --git a/libsrc/cx16/cputc.s b/libsrc/cx16/cputc.s index 11c4f5782..034c3e389 100644 --- a/libsrc/cx16/cputc.s +++ b/libsrc/cx16/cputc.s @@ -86,9 +86,9 @@ putchar: stz VERA::CTRL ; Use port 0 lda CURS_Y 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 - ldy CURS_X ; Get character column + ldy CURS_X ; Get character column into .Y tya asl a ; Each character has two bytes sta VERA::ADDR diff --git a/libsrc/cx16/crt0.s b/libsrc/cx16/crt0.s index d709ea96f..be83927fc 100644 --- a/libsrc/cx16/crt0.s +++ b/libsrc/cx16/crt0.s @@ -22,7 +22,7 @@ Start: tsx 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. jsr init @@ -31,7 +31,7 @@ Start: tsx jsr zerobss -; Push the command-line arguments; and, call main(). +; Push the command-line arguments, and call main(). jsr callmain @@ -46,7 +46,7 @@ _exit: 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. ldx #zpspace-1 @@ -90,7 +90,7 @@ init: lda #$01 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. ldx #zpspace-1 diff --git a/libsrc/cx16/exec.c b/libsrc/cx16/exec.c index 17a547e68..a6633a9c3 100644 --- a/libsrc/cx16/exec.c +++ b/libsrc/cx16/exec.c @@ -1,7 +1,7 @@ /* ** 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. ** @@ -71,26 +71,28 @@ extern void basbuf_len[]; int __fastcall__ exec (const char* progname, const char* cmdline) { +#if 0 static int fd; +#endif static unsigned char dv, n; /* Exclude devices that can't load files. */ /* (Use hand optimization, to make smaller code.) */ dv = getcurrentdevice (); - if (dv < 8 && __AX__ != 1 || __AX__ > 30) { + if (dv < 8 || __A__ > 30) { return _mappederrno (9); /* illegal device number */ } utoa (dv, basic.unit, 10); /* The emulator supports only loading and saving on its file-system. */ - if (dv != 1) { - /* Don't try to run a program that doesn't exist. */ - fd = open (progname, O_RDONLY); - if (fd < 0) { - return _mappederrno (4); /* file not found */ - } - close (fd); +#if 0 + /* Don't try to run a program that doesn't exist. */ + fd = open (progname, O_RDONLY); + if (fd < 0) { + return _mappederrno (4); /* file not found */ } + close (fd); +#endif n = 0; do { diff --git a/libsrc/cx16/get_numbanks.s b/libsrc/cx16/get_numbanks.s index 00490fb72..7654d3139 100644 --- a/libsrc/cx16/get_numbanks.s +++ b/libsrc/cx16/get_numbanks.s @@ -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. */ ; ; The Commander X16 version of MEMTOP returns with an extra value: ; 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 @@ -17,4 +18,7 @@ _get_numbanks: sec jsr MEMTOP ldx #>$0000 - rts + cmp #<$0100 ; are there 256 banks? + bne :+ + inx ; yes +: rts diff --git a/libsrc/cx16/get_tv.s b/libsrc/cx16/get_tv.s index 291a32cde..6c1cc6ad8 100644 --- a/libsrc/cx16/get_tv.s +++ b/libsrc/cx16/get_tv.s @@ -1,5 +1,5 @@ ; -; 2019-12-22, Greg King +; 2020-05-02, Greg King ; ; unsigned char get_tv (void); ; /* Return the video mode the machine is using. */ @@ -11,17 +11,9 @@ .proc _get_tv - ; Point to the video output register. - - stz VERA::CTRL ; Use port 0 - lda #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 + stz VERA::CTRL ; Use display register bank 0 + lda VERA::DISP::VIDEO + and #%00000111 ; Get the type of output signal + ldx #>$0000 ; Promote to unsigned int rts .endproc diff --git a/libsrc/cx16/kernal.s b/libsrc/cx16/kernal.s index a6b65ebbd..a252569e5 100644 --- a/libsrc/cx16/kernal.s +++ b/libsrc/cx16/kernal.s @@ -1,11 +1,15 @@ ; -; 2020-01-06, Greg King +; 2020-04-27, Greg King ; ; CX16 Kernal functions ; .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_PUT_CHAR .export CONSOLE_GET_CHAR diff --git a/libsrc/cx16/layer_enable.s b/libsrc/cx16/layer_enable.s new file mode 100644 index 000000000..2cbd6714f --- /dev/null +++ b/libsrc/cx16/layer_enable.s @@ -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 diff --git a/libsrc/cx16/randomize.s b/libsrc/cx16/randomize.s new file mode 100644 index 000000000..3d965c82a --- /dev/null +++ b/libsrc/cx16/randomize.s @@ -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 diff --git a/libsrc/cx16/set_tv.s b/libsrc/cx16/set_tv.s index c23568c67..1779e895e 100644 --- a/libsrc/cx16/set_tv.s +++ b/libsrc/cx16/set_tv.s @@ -1,5 +1,5 @@ ; -; 2019-12-22, Greg King +; 2020-05-02, Greg King ; ; void __fastcall__ set_tv (unsigned char); ; /* Set the video mode the machine will use. */ @@ -11,16 +11,10 @@ .proc _set_tv - ; Point to the video output register. - - stz VERA::CTRL ; Use port 0 - ldx #VERA::COMPOSER::VIDEO - stx VERA::ADDR - sty VERA::ADDR+1 - ldx #^VERA::COMPOSER::VIDEO - stx VERA::ADDR+2 - - sta VERA::DATA0 + stz VERA::CTRL ; Use display register bank 0 + eor VERA::DISP::VIDEO + and #%00000111 + eor VERA::DISP::VIDEO ; Replace old mode with new mode + sta VERA::DISP::VIDEO rts .endproc diff --git a/libsrc/cx16/sprites_enable.s b/libsrc/cx16/sprites_enable.s new file mode 100644 index 000000000..73924233c --- /dev/null +++ b/libsrc/cx16/sprites_enable.s @@ -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