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

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

View File

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

View File

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

View File

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

View File

@@ -11,8 +11,11 @@
.import gotoxy, PLOT
.include "cx16.inc"
.macpack generic
screen_addr := $1B000 ; VRAM address of text screen
; Move to a cursor position, then print a character.
_cputcxy:
@@ -79,16 +82,17 @@ putchar:
tax
stz VERA::CTRL ; Use port 0
lda CURS_Y
add #<(>screen_addr)
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
ldy CURS_X ; Get character column into .Y
tya
asl a ; Each character has two bytes
sta VERA::ADDR
stx VERA::DATA0
stx VERA::DATA0 ; Put the character
lda CHARCOLOR
sta VERA::DATA0
sta VERA::DATA0 ; Put its colors
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
@@ -20,7 +20,7 @@
.segment "STARTUP"
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
; which will be re-used by the BSS segment, the heap, and the C stack.
@@ -46,26 +46,14 @@ _exit:
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.
ldx spsave
txs ; Restore stack pointer
ldx ramsave
stx VIA1::PRA ; Restore former RAM bank
lda VIA1::PRB
and #<~$07
ora #$04
sta VIA1::PRB ; Change back to BASIC ROM
stx RAM_BANK ; Restore former RAM bank
lda #$04
sta ROM_BANK ; Change back to BASIC ROM
; Back to BASIC.
@@ -79,26 +67,14 @@ L2: lda zpsave,x
init:
; Change from BASIC's ROM to Kernal's ROM.
lda VIA1::PRB
and #<~$07
sta VIA1::PRB
stz ROM_BANK
; Change to the second RAM bank.
lda VIA1::PRA
lda RAM_BANK
sta ramsave ; Save the current RAM bank number
lda #$01
sta VIA1::PRA
.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
sta RAM_BANK
; Set up the stack.
@@ -125,6 +101,3 @@ L1: lda sp,x
ramsave:
.res 1
spsave: .res 1
.if 0
zpsave: .res zpspace
.endif

View File

@@ -2,7 +2,7 @@
; Standard joystick driver for the CX16.
; 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"
@@ -41,7 +41,7 @@
; ------------------------------------------------------------------------
; Constant
JOY_COUNT = 2 ; Number of joysticks we support
JOY_COUNT = $05 ; Number of joysticks we support
; ------------------------------------------------------------------------
; Data.
@@ -51,8 +51,7 @@ JOY_COUNT = 2 ; Number of joysticks we support
; ------------------------------------------------------------------------
; INSTALL routine -- is called after the driver is loaded into memory.
; If possible, check if the hardware is present, and determine the amount
; of memory available.
; If possible, check if the hardware is present.
; Must return a JOY_ERR_xx code in .XA .
INSTALL:
@@ -77,8 +76,10 @@ COUNT: lda #<JOY_COUNT
; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in .A .
READ: and #%00000001
jsr JOYSTICK_GET
READ: cmp #JOY_COUNT
blt :+
lda #$00
: jsr JOYSTICK_GET
sta tmp1
txa
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);
; /* Returns non-zero (true) if a typed character is waiting. */
@@ -7,14 +7,11 @@
.export _kbhit
.include "cx16.inc"
.import KBDBUF_PEEK
.proc _kbhit
ldy VIA1::PRA ; (KEY_COUNT is in RAM bank 0)
stz VIA1::PRA
lda KEY_COUNT ; Get number of characters
sty VIA1::PRA
tax ; High byte of return (only its zero/nonzero ...
jsr KBDBUF_PEEK
txa ; Low byte of return (only its zero/nonzero ...
rts ; ... state matters)
.endproc

View File

@@ -1,13 +1,18 @@
;
; 2020-04-27, Greg King
; 2022-03-28, Greg King
;
; CX16 Kernal functions
;
.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 KEYBRD_BUF_PUT
.export CONSOLE_SET_PAGE_MSG
.export CONSOLE_PUT_IMAGE
.export CONSOLE_INIT
@@ -50,7 +55,7 @@
.export CLOCK_GET_DATE_TIME
.export JOYSTICK_SCAN
.export JOYSTICK_GET
.export SCREEN_SET_MODE
.export SCREEN_MODE
.export SCREEN_SET_CHARSET
.export MOUSE_CONFIG
.export MOUSE_GET

View File

@@ -1,7 +1,7 @@
;
; Driver for the Commander X16 Kernal's mouse driver.
;
; 2019-12-25, Greg King
; 2022-03-28, Greg King
;
.include "zeropage.inc"
@@ -118,7 +118,8 @@ INSTALL:
dex
bpl @L1
ldx #$00 ; Don't change sprite's scale
sec ; Get screen geometry
jsr SCREEN_MODE
lda #$01 ; Create sprite
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
;
; 2020-07-02, Greg King <gregdk@users.sf.net>
; 2022-03-30, Greg King <gregdk@users.sf.net>
;
.include "zeropage.inc"
@@ -39,7 +39,7 @@
.byte TGI_API_VERSION ; TGI API version number
.addr $0000 ; Library reference
.word 320 ; X resolution
.word 200 ; Y resolution
.word 240 ; Y resolution
.byte <$0100 ; Number of drawing colors
.byte 1 ; Number of screens available
.byte 8 ; System font X size
@@ -100,7 +100,7 @@ palette: .res $0100
bcolor := palette + 0 ; Background color
color: .res 1 ; Stroke and fill index
mode: .res 1 ; Old text mode
text_mode: .res 1 ; Old text mode
.data
@@ -152,13 +152,15 @@ INIT: stz error ; #TGI_ERR_OK
; Save the current text mode.
lda SCREEN_MODE
sta mode
sec
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
jmp SCREEN_SET_MODE
clc
jmp SCREEN_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
DONE:
; Work around a prerelease 37 Kernal bug.
; VERA (graphics) layer 0 isn't disabled by SCREEN_SET_MODE.
stz VERA::CTRL
lda VERA::DISP::VIDEO
and #<~VERA::DISP::ENABLE::LAYER0
sta VERA::DISP::VIDEO
lda mode
jmp SCREEN_SET_MODE
lda text_mode
clc
jmp SCREEN_MODE
; ------------------------------------------------------------------------
; 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 */
; #define VIDEOMODE_40x30 0x00
; #define VIDEOMODE_80x60 0x02
; #define VIDEOMODE_320x200 0x80
; #define VIDEOMODE_80x60 0x00
; #define VIDEOMODE_80x30 0x01
; #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)
;
; signed char __fastcall__ videomode (signed char Mode);
@@ -16,25 +21,26 @@
.export _videomode
.import SCREEN_SET_MODE
.include "cx16.inc"
.import SCREEN_MODE
.proc _videomode
ldx SCREEN_MODE ; Get old mode
phx
jsr SCREEN_SET_MODE
sec ; Get old mode
pha
jsr SCREEN_MODE
plx
pha ; Save old mode
txa
clc ; Set new mode
jsr SCREEN_MODE
pla ; Get back old mode
ldx #>$0000 ; Clear high byte
bcs @L1
rts
bcc @L1
; 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
txa
rts
@L1: rts
.endproc

View File

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