Upgraded the cx16 library to the Commander X16 Kernal ROM's prerelease 39.

This commit is contained in:
Greg King 2022-04-02 09:39:35 -04:00
parent 75ee10478e
commit a5e69e7ea6
18 changed files with 208 additions and 172 deletions

View File

@ -7,8 +7,13 @@
.if .def(__CX16__) .if .def(__CX16__)
; CX16 extended jump table ; CX16 extended jump table
KBDBUF_PEEK := $FEBD
KBDBUF_GET_MODIFIERS := $FEC0
KBDBUF_PUT := $FEC3
I2C_READ_BYTE := $FEC6
I2C_WRITE_BYTE := $FEC9
CX_MONITOR := $FECC
ENTROPY_GET := $FECF ENTROPY_GET := $FECF
KEYBRD_BUF_PUT := $FED2
CONSOLE_SET_PAGE_MSG := $FED5 CONSOLE_SET_PAGE_MSG := $FED5
CONSOLE_PUT_IMAGE := $FED8 CONSOLE_PUT_IMAGE := $FED8
CONSOLE_INIT := $FEDB CONSOLE_INIT := $FEDB
@ -52,7 +57,7 @@
CLOCK_GET_DATE_TIME := $FF50 CLOCK_GET_DATE_TIME := $FF50
JOYSTICK_SCAN := $FF53 JOYSTICK_SCAN := $FF53
JOYSTICK_GET := $FF56 JOYSTICK_GET := $FF56
SCREEN_SET_MODE := $FF5F SCREEN_MODE := $FF5F
SCREEN_SET_CHARSET := $FF62 SCREEN_SET_CHARSET := $FF62
MOUSE_CONFIG := $FF68 MOUSE_CONFIG := $FF68
MOUSE_GET := $FF6B MOUSE_GET := $FF6B

View File

@ -1,5 +1,5 @@
; ;
; CX16 r38 definitions ; CX16 r39 definitions
; ;
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
@ -106,6 +106,10 @@ PI
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; Zero page ; Zero page
; Banking registers
RAM_BANK := $00
ROM_BANK := $01
; GEOS and graphics pseudo-registers ; GEOS and graphics pseudo-registers
.struct gREG .struct gREG
.org $02 .org $02
@ -226,7 +230,7 @@ PI
; Kernal ; Kernal
KTEMP2 := $80 ; 2 bytes for temporary storage KTEMP2 := $80 ; 2 bytes for temporary storage
IMPARM := $82 ; Pointer for PRIMM function IMPARM := $82 ; Pointer for PRIMM function
FNAM := $8C ; Pointer to filename FNAM := $8A ; Pointer to filename
; BASIC ; BASIC
TXTPTR := $EE ; Pointer into BASIC source code TXTPTR := $EE ; Pointer into BASIC source code
@ -236,14 +240,13 @@ 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 := $0261 ; Current screen mode (set by SCREEN_SET_MODE)
SCREEN_PTR := $0262 ; 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 := $0289 ; Status from previous I/O operation
IN_DEV := $028A ; Current input device number IN_DEV := $028D ; Current input device number
OUT_DEV := $028B ; Current output device number OUT_DEV := $028E ; Current output device number
FNAM_LEN := $028E ; Length of filename FNAM_LEN := $0291 ; Length of filename
SECADR := $0290 ; Secondary address SECADR := $0293 ; Secondary address
DEVNUM := $0291 ; Device number DEVNUM := $0294 ; Device number
CURS_COLOR := $0373 ; Color under the cursor CURS_COLOR := $0373 ; Color under the cursor
CHARCOLOR := $0376 ; Cursor's color nybbles (high: background, low: foreground) CHARCOLOR := $0376 ; Cursor's color nybbles (high: background, low: foreground)
RVS := $0377 ; Reverse flag RVS := $0377 ; Reverse flag
@ -270,6 +273,42 @@ NMIVec := $0318
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; I/O locations ; I/O locations
; 65C22 Versatile Interface Adapter
.struct VIA1 ; Versatile Interface Adapter
.org $9F00
PRB .byte ; mouse, LED, VIC bus (Port Register B)
PRA .byte ; keyboard, controllers (Port Register A)
DDRB .byte ; (Data Direction Register B)
DDRA .byte ; (Data Direction Register A)
T1 .word ; (Timer 1)
T1L .word ; (Timer 1 Latch)
T2 .word ; (Timer 2)
SR .byte ; (Shift Register)
ACR .byte ; (Auxiliary Control Register)
PCR .byte ; (Peripheral Control Register)
IFR .byte ; (Interrupt Flags Register)
IER .byte ; (Interrupt Enable Register)
PRA2 .byte ; keyboard, controllers (PRA without handshake)
.endstruct
; 65C22 Versatile Interface Adapter
.struct VIA2
.org $9F10
PRB .byte
PRA .byte
DDRB .byte
DDRA .byte
T1 .word
T1L .word
T2 .word
SR .byte
ACR .byte
PCR .byte
IFR .byte
IER .byte
PRA2 .byte
.endstruct
; Video Enhanced Retro Adapter ; Video Enhanced Retro Adapter
; Has audio and SPI. ; Has audio and SPI.
.scope VERA .scope VERA
@ -498,44 +537,16 @@ NMIVec := $0318
.endstruct .endstruct
.endscope .endscope
; 65C22 ; YM2151 audio chip
.struct VIA1 ; Versatile Interface Adapter .struct YM2151
.org $9F60 .org $9F40
PRB .byte ; ROM bank, IEC (Port Register B) .union
PRA .byte ; RAM bank (Port Register A) STATUS .byte
DDRB .byte ; (Data Direction Register B) ADDR .byte
DDRA .byte ; (Data Direction Register A) .endunion
T1 .word ; (Timer 1) DATA .byte
T1L .word ; (Timer 1 Latch)
T2 .word ; (Timer 2)
SR .byte ; (Shift Register)
ACR .byte ; (Auxiliary Control Register)
PCR .byte ; (Peripheral Control Register)
IFR .byte ; (Interrupt Flags Register)
IER .byte ; (Interrupt Enable Register)
PRA2 .byte ; RAM bank (Port Register A without handshaking)
.endstruct .endstruct
; 65C22
.struct VIA2
.org $9F70
PRB .byte ; Mouse communication ?
PRA .byte ; NES controller communication
DDRB .byte
DDRA .byte
T1 .word
T1L .word
T2 .word
SR .byte
ACR .byte
PCR .byte
IFR .byte
IER .byte
PRA2 .byte
.endstruct
; Real-Time Clock
; X16 Emulator device ; X16 Emulator device
; This device doesn't exist on the real machine. ; This device doesn't exist on the real machine.
.struct EMULATOR .struct EMULATOR
@ -556,8 +567,7 @@ NMIVec := $0318
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; Banked RAM and ROM ; Banked RAM and ROM
KEY_COUNT := $A00A ; (bank 0) Number of keys in input buffer TIMER := $A03B ; (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

@ -1,5 +1,3 @@
# Assembly configuration for R38
FEATURES { FEATURES {
STARTADDRESS: default = $0801; STARTADDRESS: default = $0801;
} }

View File

@ -200,15 +200,23 @@ access to hardware located in the address space. Some variables are
structures, accessing the struct fields will access the chip registers. structures, accessing the struct fields will access the chip registers.
<descrip> <descrip>
<tag><tt/VERA/</tag>
The <tt/VERA/ structure allows access <tag><tt/RAM_BANK/</tag>
to the Video Enhanced Retro Adapter chip. A register that controls which bank of high RAM is visible in the
<tt/BANK_RAM/ window.
<tag><tt/ROM_BANK/</tag>
A register that controls which bank of ROM is active at the moment.
<tag><tt/VIA1, VIA2/</tag> <tag><tt/VIA1, VIA2/</tag>
Access to the two VIA (Versatile Interface Adapter) chips is available via Access to the two VIA (Versatile Interface Adapter) chips is available via
the <tt/VIA1/ and <tt/VIA2/ variables. The structure behind those variables the <tt/VIA1/ and <tt/VIA2/ variables. The structure behind those variables
is explained in <tt/_6522.h/. is explained in <tt/_6522.h/.
<tag><tt/VERA/</tag>
The <tt/VERA/ structure allows access
to the Video Enhanced Retro Adapter chip.
<tag><tt/BANK_RAM/</tag> <tag><tt/BANK_RAM/</tag>
A character array that mirrors the eight-Kibibyte window, at &dollar;A000, A character array that mirrors the eight-Kibibyte window, at &dollar;A000,
into banked RAM. into banked RAM.
@ -219,7 +227,7 @@ structures, accessing the struct fields will access the chip registers.
<sect>Loadable drivers<p> <sect>Loadable drivers<p>
The names in the parentheses denote the symbols to be used for static linking The names in the parentheses denote the symbols to be used for static linking
of the drivers. The names fit into the 8.3 character limit of the SD-Card's of the drivers. The names fit into the old 8.3-character limit of the SD-Card's
FAT32 file-system. FAT32 file-system.
@ -230,7 +238,7 @@ point to <tt/cx320p1.tgi (cx320p1_tgi)/.
<descrip> <descrip>
<tag><tt/cx320p1.tgi (cx320p1_tgi)/</tag> <tag><tt/cx320p1.tgi (cx320p1_tgi)/</tag>
This driver features a resolution of 320 across and 200 down with 256 colors, This driver features a resolution of 320 across and 240 down with 256 colors,
and a slightly adjustable palette (the order of the colors can be changed in and a slightly adjustable palette (the order of the colors can be changed in
a way that's compatible with some of the other color drivers). a way that's compatible with some of the other color drivers).
</descrip><p> </descrip><p>
@ -248,10 +256,10 @@ point to <tt/cx16-std.joy (cx16_std_joy)/.
<descrip> <descrip>
<tag><tt/cx16-std.joy (cx16_std_joy)/</tag> <tag><tt/cx16-std.joy (cx16_std_joy)/</tag>
Supports up to two NES (and SNES) controllers connected to the joystick ports Supports the keyboard emulation of a controller and up to four SNES (and NES)
of the CX16. It reads the four directions, and the <bf/A/, <bf/B/, controllers connected to the joystick ports of the CX16. It reads the four
<bf/Select/, and <bf/Start/ buttons. Buttons <bf/A/ and <bf/B/ are directions, and the <bf/A/, <bf/B/, <bf/Select/, and <bf/Start/ buttons.
the first and second fire buttons. Buttons <bf/A/ and <bf/B/ are the first and second fire buttons.
</descrip><p> </descrip><p>

View File

@ -3,7 +3,7 @@
/* cx16.h */ /* cx16.h */
/* */ /* */
/* CX16 system-specific definitions */ /* CX16 system-specific definitions */
/* For prerelease 38 */ /* For prerelease 39 */
/* */ /* */
/* */ /* */
/* This software is provided "as-is", without any expressed or implied */ /* This software is provided "as-is", without any expressed or implied */
@ -172,11 +172,16 @@ enum {
}; };
/* Video modes for videomode() */ /* Video modes for videomode() */
#define VIDEOMODE_40x30 0x00 #define VIDEOMODE_80x60 0x00
#define VIDEOMODE_80x60 0x02 #define VIDEOMODE_80x30 0x01
#define VIDEOMODE_40COL VIDEOMODE_40x30 #define VIDEOMODE_40x60 0x02
#define VIDEOMODE_40x30 0x03
#define VIDEOMODE_40x15 0x04
#define VIDEOMODE_20x30 0x05
#define VIDEOMODE_20x15 0x06
#define VIDEOMODE_80COL VIDEOMODE_80x60 #define VIDEOMODE_80COL VIDEOMODE_80x60
#define VIDEOMODE_320x200 0x80 #define VIDEOMODE_40COL VIDEOMODE_40x30
#define VIDEOMODE_320x240 0x80
#define VIDEOMODE_SWAP (-1) #define VIDEOMODE_SWAP (-1)
/* VERA's address increment/decrement numbers */ /* VERA's address increment/decrement numbers */
@ -224,6 +229,13 @@ enum {
/* Define hardware. */ /* Define hardware. */
#define RAM_BANK (*(unsigned char *)0x00)
#define ROM_BANK (*(unsigned char *)0x01)
#include <_6522.h>
#define VIA1 (*(volatile struct __6522 *)0x9F00)
#define VIA2 (*(volatile struct __6522 *)0x9F10)
/* A structure with the Video Enhanced Retro Adapter's external registers */ /* A structure with the Video Enhanced Retro Adapter's external registers */
struct __vera { struct __vera {
unsigned short address; /* Address for data ports */ unsigned short address; /* Address for data ports */
@ -274,12 +286,15 @@ struct __vera {
}; };
#define VERA (*(volatile struct __vera *)0x9F20) #define VERA (*(volatile struct __vera *)0x9F20)
#include <_6522.h> /* Audio chip */
#define VIA1 (*(volatile struct __6522 *)0x9F60) struct __ym2151 {
#define VIA2 (*(volatile struct __6522 *)0x9F70) union {
unsigned char reg; /* Register number for data */
#define RAM_BANK (VIA1.pra) unsigned char status; /* Busy flag */
#define ROM_BANK (VIA1.prb) };
unsigned char data;
};
#define YM2151 (*(volatile struct __ym2151 *)0x9F40)
/* A structure with the x16emu's settings registers */ /* A structure with the x16emu's settings registers */
struct __emul { struct __emul {

View File

@ -1,5 +1,5 @@
; ;
; 2019-12-22, Greg King ; 2022-03-29, Greg King
; ;
; char cgetc (void); ; char cgetc (void);
; /* Return a character from the keyboard. */ ; /* Return a character from the keyboard. */
@ -13,6 +13,8 @@
.macpack generic .macpack generic
screen_addr := $1B000 ; VRAM address of text screen
_cgetc: jsr _kbhit _cgetc: jsr _kbhit
bnz L3 ; Jump if there are already chars waiting bnz L3 ; Jump if there are already chars waiting
@ -57,8 +59,9 @@ setcursor:
stz VERA::CTRL ; Use port 0 stz VERA::CTRL ; Use port 0
lda CURS_Y lda CURS_Y
add #<(>screen_addr)
sta VERA::ADDR+1 ; Set row number sta VERA::ADDR+1 ; Set row number
lda #VERA::INC1 ; Increment address by one lda #VERA::INC1 | ^screen_addr ; Increment address by one
sta VERA::ADDR+2 sta VERA::ADDR+2
lda CURS_X ; Get character column lda CURS_X ; Get character column
asl a asl a

View File

@ -1,6 +1,6 @@
; ;
; 2016-02-28, Groepaz ; 2016-02-28, Groepaz
; 2020-04-29, Greg King ; 2022-03-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. */
@ -9,13 +9,18 @@
.export _cpeekc .export _cpeekc
.include "cx16.inc" .include "cx16.inc"
.macpack generic
screen_addr := $1B000 ; VRAM address of text screen
_cpeekc: _cpeekc:
stz VERA::CTRL ; use port 0 stz VERA::CTRL ; use port 0
lda CURS_Y lda CURS_Y
add #<(>screen_addr)
sta VERA::ADDR+1 ; set row number sta VERA::ADDR+1 ; set row number
stz VERA::ADDR+2 lda #^screen_addr
sta VERA::ADDR+2
lda CURS_X ; get character column lda CURS_X ; get character column
asl a ; each character has two bytes asl a ; each character has two bytes
sta VERA::ADDR sta VERA::ADDR

View File

@ -1,5 +1,5 @@
; ;
; 2020-04-30, Greg King ; 2022-03-29, 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. */
@ -8,8 +8,11 @@
.export _cpeekcolor .export _cpeekcolor
.include "cx16.inc" .include "cx16.inc"
.macpack generic
screen_addr := $1B000 ; VRAM address of text screen
_cpeekcolor: _cpeekcolor:
php php
lda CURS_FLAG ; is the cursor currently off? lda CURS_FLAG ; is the cursor currently off?
@ -22,8 +25,10 @@ _cpeekcolor:
@L1: stz VERA::CTRL ; use port 0 @L1: stz VERA::CTRL ; use port 0
lda CURS_Y lda CURS_Y
add #<(>screen_addr)
sta VERA::ADDR+1 ; set row number sta VERA::ADDR+1 ; set row number
stz VERA::ADDR+2 lda #^screen_addr
sta VERA::ADDR+2
lda CURS_X ; get character column lda CURS_X ; get character column
sec ; color attribute is second byte sec ; color attribute is second byte
rol a rol a

View File

@ -1,6 +1,6 @@
; ;
; 2016-02-28, Groepaz ; 2016-02-28, Groepaz
; 2020-04-30, Greg King ; 2022-03-29, 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.
@ -11,8 +11,11 @@
.export _cpeekrevers .export _cpeekrevers
.include "cx16.inc" .include "cx16.inc"
.macpack generic
screen_addr := $1B000 ; VRAM address of text screen
_cpeekrevers: _cpeekrevers:
php php
lda CURS_FLAG ; is the cursor currently off? lda CURS_FLAG ; is the cursor currently off?
@ -25,8 +28,10 @@ _cpeekrevers:
@L1: stz VERA::CTRL ; use port 0 @L1: stz VERA::CTRL ; use port 0
lda CURS_Y lda CURS_Y
add #<(>screen_addr)
sta VERA::ADDR+1 ; set row number sta VERA::ADDR+1 ; set row number
stz VERA::ADDR+2 lda #^screen_addr
sta VERA::ADDR+2
lda CURS_X ; get character column lda CURS_X ; get character column
asl a ; each character has two bytes asl a ; each character has two bytes
sta VERA::ADDR sta VERA::ADDR

View File

@ -11,8 +11,11 @@
.import gotoxy, PLOT .import gotoxy, PLOT
.include "cx16.inc" .include "cx16.inc"
.macpack generic
screen_addr := $1B000 ; VRAM address of text screen
; Move to a cursor position, then print a character. ; Move to a cursor position, then print a character.
_cputcxy: _cputcxy:
@ -79,16 +82,17 @@ putchar:
tax tax
stz VERA::CTRL ; Use port 0 stz VERA::CTRL ; Use port 0
lda CURS_Y lda CURS_Y
add #<(>screen_addr)
sta VERA::ADDR+1 ; Set row number sta VERA::ADDR+1 ; Set row number
lda #VERA::INC1 ; Address increments by one lda #VERA::INC1 | ^screen_addr ; Address increments by one
sta VERA::ADDR+2 sta VERA::ADDR+2
ldy CURS_X ; Get character column into .Y 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
stx VERA::DATA0 stx VERA::DATA0 ; Put the character
lda CHARCOLOR lda CHARCOLOR
sta VERA::DATA0 sta VERA::DATA0 ; Put its colors
rts rts

View File

@ -1,5 +1,5 @@
; ;
; Start-up code for cc65 (CX16 r35 version) ; Start-up code for cc65 (CX16 r39 version)
; ;
.export _exit .export _exit
@ -20,7 +20,7 @@
.segment "STARTUP" .segment "STARTUP"
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.
@ -46,26 +46,14 @@ _exit:
jsr donelib jsr donelib
.if 0 ; (We don't need to preserve zero-page space for cc65's variables.)
; Copy back the zero-page stuff.
ldx #zpspace-1
L2: lda zpsave,x
sta sp,x
dex
bpl L2
.endif
; Restore the system stuff. ; Restore the system stuff.
ldx spsave ldx spsave
txs ; Restore stack pointer txs ; Restore stack pointer
ldx ramsave ldx ramsave
stx VIA1::PRA ; Restore former RAM bank stx RAM_BANK ; Restore former RAM bank
lda VIA1::PRB lda #$04
and #<~$07 sta ROM_BANK ; Change back to BASIC ROM
ora #$04
sta VIA1::PRB ; Change back to BASIC ROM
; Back to BASIC. ; Back to BASIC.
@ -79,26 +67,14 @@ L2: lda zpsave,x
init: init:
; Change from BASIC's ROM to Kernal's ROM. ; Change from BASIC's ROM to Kernal's ROM.
lda VIA1::PRB stz ROM_BANK
and #<~$07
sta VIA1::PRB
; Change to the second RAM bank. ; Change to the second RAM bank.
lda VIA1::PRA lda RAM_BANK
sta ramsave ; Save the current RAM bank number sta ramsave ; Save the current RAM bank number
lda #$01 lda #$01
sta VIA1::PRA sta RAM_BANK
.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
L1: lda sp,x
sta zpsave,x
dex
bpl L1
.endif
; Set up the stack. ; Set up the stack.
@ -125,6 +101,3 @@ L1: lda sp,x
ramsave: ramsave:
.res 1 .res 1
spsave: .res 1 spsave: .res 1
.if 0
zpsave: .res zpspace
.endif

View File

@ -2,7 +2,7 @@
; Standard joystick driver for the CX16. ; Standard joystick driver for the CX16.
; May be installed multiple times when statically linked to an application. ; May be installed multiple times when statically linked to an application.
; ;
; 2019-12-24, Greg King ; 2021-04-07, Greg King
; ;
.include "joy-kernel.inc" .include "joy-kernel.inc"
@ -41,7 +41,7 @@
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Constant ; Constant
JOY_COUNT = 2 ; Number of joysticks we support JOY_COUNT = $05 ; Number of joysticks we support
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Data. ; Data.
@ -51,8 +51,7 @@ JOY_COUNT = 2 ; Number of joysticks we support
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; INSTALL routine -- is called after the driver is loaded into memory. ; INSTALL routine -- is called after the driver is loaded into memory.
; If possible, check if the hardware is present, and determine the amount ; If possible, check if the hardware is present.
; of memory available.
; Must return a JOY_ERR_xx code in .XA . ; Must return a JOY_ERR_xx code in .XA .
INSTALL: INSTALL:
@ -77,8 +76,10 @@ COUNT: lda #<JOY_COUNT
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in .A . ; READ: Read a particular joystick passed in .A .
READ: and #%00000001 READ: cmp #JOY_COUNT
jsr JOYSTICK_GET blt :+
lda #$00
: jsr JOYSTICK_GET
sta tmp1 sta tmp1
txa txa
bit #%00001110 ; Is it NES or SNES controller? bit #%00001110 ; Is it NES or SNES controller?

View File

@ -1,5 +1,5 @@
; ;
; 2020-01-08, Greg King ; 2022-03-28, Greg King
; ;
; unsigned char kbhit (void); ; unsigned char kbhit (void);
; /* Returns non-zero (true) if a typed character is waiting. */ ; /* Returns non-zero (true) if a typed character is waiting. */
@ -7,14 +7,11 @@
.export _kbhit .export _kbhit
.include "cx16.inc" .import KBDBUF_PEEK
.proc _kbhit .proc _kbhit
ldy VIA1::PRA ; (KEY_COUNT is in RAM bank 0) jsr KBDBUF_PEEK
stz VIA1::PRA txa ; Low byte of return (only its zero/nonzero ...
lda KEY_COUNT ; Get number of characters
sty VIA1::PRA
tax ; High byte of return (only its zero/nonzero ...
rts ; ... state matters) rts ; ... state matters)
.endproc .endproc

View File

@ -1,13 +1,18 @@
; ;
; 2020-04-27, Greg King ; 2022-03-28, Greg King
; ;
; CX16 Kernal functions ; CX16 Kernal functions
; ;
.include "cbm_kernal.inc" .include "cbm_kernal.inc"
.export KBDBUF_PEEK
.export KBDBUF_GET_MODIFIERS
.export KBDBUF_PUT
.export I2C_READ_BYTE
.export I2C_WRITE_BYTE
.export CX_MONITOR
.export ENTROPY_GET .export ENTROPY_GET
.export KEYBRD_BUF_PUT
.export CONSOLE_SET_PAGE_MSG .export CONSOLE_SET_PAGE_MSG
.export CONSOLE_PUT_IMAGE .export CONSOLE_PUT_IMAGE
.export CONSOLE_INIT .export CONSOLE_INIT
@ -50,7 +55,7 @@
.export CLOCK_GET_DATE_TIME .export CLOCK_GET_DATE_TIME
.export JOYSTICK_SCAN .export JOYSTICK_SCAN
.export JOYSTICK_GET .export JOYSTICK_GET
.export SCREEN_SET_MODE .export SCREEN_MODE
.export SCREEN_SET_CHARSET .export SCREEN_SET_CHARSET
.export MOUSE_CONFIG .export MOUSE_CONFIG
.export MOUSE_GET .export MOUSE_GET

View File

@ -1,7 +1,7 @@
; ;
; Driver for the Commander X16 Kernal's mouse driver. ; Driver for the Commander X16 Kernal's mouse driver.
; ;
; 2019-12-25, Greg King ; 2022-03-28, Greg King
; ;
.include "zeropage.inc" .include "zeropage.inc"
@ -118,7 +118,8 @@ INSTALL:
dex dex
bpl @L1 bpl @L1
ldx #$00 ; Don't change sprite's scale sec ; Get screen geometry
jsr SCREEN_MODE
lda #$01 ; Create sprite lda #$01 ; Create sprite
jsr MOUSE_CONFIG jsr MOUSE_CONFIG

View File

@ -1,8 +1,8 @@
; ;
; Graphics driver for the 320 pixels across, 200 pixels down, 256 colors mode ; Graphics driver for the 320 pixels across, 240 pixels down, 256 colors mode
; on the Commander X16 ; on the Commander X16
; ;
; 2020-07-02, Greg King <gregdk@users.sf.net> ; 2022-03-30, Greg King <gregdk@users.sf.net>
; ;
.include "zeropage.inc" .include "zeropage.inc"
@ -39,7 +39,7 @@
.byte TGI_API_VERSION ; TGI API version number .byte TGI_API_VERSION ; TGI API version number
.addr $0000 ; Library reference .addr $0000 ; Library reference
.word 320 ; X resolution .word 320 ; X resolution
.word 200 ; Y resolution .word 240 ; Y resolution
.byte <$0100 ; Number of drawing colors .byte <$0100 ; Number of drawing colors
.byte 1 ; Number of screens available .byte 1 ; Number of screens available
.byte 8 ; System font X size .byte 8 ; System font X size
@ -100,7 +100,7 @@ palette: .res $0100
bcolor := palette + 0 ; Background color bcolor := palette + 0 ; Background color
color: .res 1 ; Stroke and fill index color: .res 1 ; Stroke and fill index
mode: .res 1 ; Old text mode text_mode: .res 1 ; Old text mode
.data .data
@ -152,13 +152,15 @@ INIT: stz error ; #TGI_ERR_OK
; Save the current text mode. ; Save the current text mode.
lda SCREEN_MODE sec
sta mode jsr SCREEN_MODE
sta text_mode
; Switch into (320 x 200 x 256) graphics mode. ; Switch into (320 x 240 x 256) graphics mode.
lda #GRAPH320 lda #GRAPH320
jmp SCREEN_SET_MODE clc
jmp SCREEN_MODE
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; DONE: Will be called to switch the graphics device back into text mode. ; DONE: Will be called to switch the graphics device back into text mode.
@ -168,16 +170,9 @@ INIT: stz error ; #TGI_ERR_OK
; Must set an error code: NO ; Must set an error code: NO
DONE: DONE:
; Work around a prerelease 37 Kernal bug. lda text_mode
; VERA (graphics) layer 0 isn't disabled by SCREEN_SET_MODE. clc
jmp SCREEN_MODE
stz VERA::CTRL
lda VERA::DISP::VIDEO
and #<~VERA::DISP::ENABLE::LAYER0
sta VERA::DISP::VIDEO
lda mode
jmp SCREEN_SET_MODE
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; GETERROR: Return the error code in .A, and clear it. ; GETERROR: Return the error code in .A, and clear it.

View File

@ -1,10 +1,15 @@
; ;
; 2020-01-06, Greg King ; 2022-03-28, Greg King
; ;
; /* Video mode defines */ ; /* Video mode defines */
; #define VIDEOMODE_40x30 0x00 ; #define VIDEOMODE_80x60 0x00
; #define VIDEOMODE_80x60 0x02 ; #define VIDEOMODE_80x30 0x01
; #define VIDEOMODE_320x200 0x80 ; #define VIDEOMODE_40x60 0x02
; #define VIDEOMODE_40x30 0x03
; #define VIDEOMODE_40x15 0x04
; #define VIDEOMODE_20x30 0x05
; #define VIDEOMODE_20x15 0x06
; #define VIDEOMODE_320x240 0x80
; #define VIDEOMODE_SWAP (-1) ; #define VIDEOMODE_SWAP (-1)
; ;
; signed char __fastcall__ videomode (signed char Mode); ; signed char __fastcall__ videomode (signed char Mode);
@ -16,25 +21,26 @@
.export _videomode .export _videomode
.import SCREEN_SET_MODE .import SCREEN_MODE
.include "cx16.inc"
.proc _videomode .proc _videomode
ldx SCREEN_MODE ; Get old mode sec ; Get old mode
phx pha
jsr SCREEN_MODE
jsr SCREEN_SET_MODE plx
pha ; Save old mode
txa
clc ; Set new mode
jsr SCREEN_MODE
pla ; Get back old mode pla ; Get back old mode
ldx #>$0000 ; Clear high byte ldx #>$0000 ; Clear high byte
bcs @L1 bcc @L1
rts
; The new mode is invalid. Go back to the old one. Return -1. ; The new mode is invalid. Return -1.
@L1: sta SCREEN_MODE
dex dex
txa txa
rts @L1: rts
.endproc .endproc

View File

@ -1,5 +1,5 @@
; ;
; 2020-01-08, Greg King ; 2021-04-01, Greg King
; ;
; void waitvsync (void); ; void waitvsync (void);
; /* Wait for the start of the next video field. */ ; /* Wait for the start of the next video field. */
@ -12,10 +12,10 @@
.include "cx16.inc" .include "cx16.inc"
_waitvsync: _waitvsync:
ldx VIA1::PRA ; (TIMER is in RAM bank 0) ldx RAM_BANK ; (TIMER is in RAM bank 0)
stz VIA1::PRA stz RAM_BANK
lda TIMER + 2 lda TIMER + 2
: cmp TIMER + 2 : cmp TIMER + 2
beq :- ; Wait for next jiffy beq :- ; Wait for next jiffy
stx VIA1::PRA stx RAM_BANK
rts rts