Updated the cx16 library to the Commander X16 Kernal's prerelease 35.

This commit is contained in:
Greg King
2019-12-25 10:56:32 -05:00
parent cab4910a7d
commit 3fa253d31f
31 changed files with 508 additions and 271 deletions

View File

@@ -1,19 +1,28 @@
;
; Ullrich von Bassewitz, 21.09.1998
; 1998-09-21, Ullrich von Bassewitz
; 2019-12-25, Greg King
;
; clock_t clock (void);
;
.include "cbm.inc"
.export _clock
.importzp sreg
.include "cbm.inc"
.macpack cpu
.proc _clock
lda #0 ; Byte 3 is always zero
sta sreg+1
; Some accelerator adaptors have CMOS ICs.
.if (.cpu & ::CPU_ISET_65SC02)
stz sreg + 1
.else
lda #$00 ; Byte 3 always is zero
sta sreg + 1
.endif
jsr RDTIM
sty sreg
rts

View File

@@ -1,10 +1,6 @@
;
; Ullrich von Bassewitz, 26.10.2000
;
; Screen size variables
;
.export screensize
.import SCREEN
screensize := SCREEN
.export screensize := SCREEN

View File

@@ -1,7 +1,7 @@
;
; 2019-09-16, Greg King
; 2019-12-21, Greg King
;
; This module supplies the load addresses that are expected
; This module supplies some load addresses that are expected
; by a Commander X16 in the first two bytes of banked RAM load files.
;
@@ -9,9 +9,11 @@
; this module to get included into the output files.
.export __BANKRAMADDR__: abs = 1
.if 0 ; bank 0 is used by Kernal
.segment "BRAM00ADDR"
.addr *+2
.endif
.segment "BRAM01ADDR"

View File

@@ -1,5 +1,5 @@
;
; 2019-10-01, Greg King
; 2019-12-22, Greg King
;
; char cgetc (void);
; /* Return a character from the keyboard. */
@@ -7,13 +7,13 @@
.export _cgetc
.import cursor, GETIN
.import _kbhit, cursor, GETIN
.include "cx16.inc"
.macpack generic
_cgetc: ldx KEY_COUNT ; Get number of characters
_cgetc: jsr _kbhit
bnz L3 ; Jump if there are already chars waiting
; Switch the cursor on if wanted.
@@ -22,7 +22,7 @@ _cgetc: ldx KEY_COUNT ; Get number of characters
tay
lda cursor
jsr setcursor
L1: lda KEY_COUNT
L1: jsr _kbhit
bze L1 ; Wait for key
tya
eor #%00000001 ; (Cursor flag uses negative logic)

36
libsrc/cx16/clock.s Normal file
View File

@@ -0,0 +1,36 @@
;
; 1998-09-21, Ullrich von Bassewitz
; 2019-12-25, Greg King
;
; clock_t clock (void);
;
.constructor initclock
.export _clock
.import SETTIM, RDTIM
.importzp sreg
; clock() counts the amount of time that the process has run.
; Therefore, reset it when the program begins.
.proc initclock
lda #$00
tax
tay
jmp SETTIM
.endproc
.proc _clock
stz sreg + 1 ; Byte 3 always is zero
jsr RDTIM
sty sreg
rts
.endproc

View File

@@ -1,5 +1,5 @@
;
; Start-up code for cc65 (CX16 version)
; Start-up code for cc65 (CX16 r35 version)
;
.export _exit
@@ -46,7 +46,7 @@ _exit:
jsr donelib
.if 0 ; We no longer 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
@@ -83,14 +83,14 @@ init:
and #<~$07
sta VIA1::PRB
; Change to the first RAM bank.
; Change to the second RAM bank.
lda VIA1::PRA2
sta ramsave ; Save the current RAM bank number
lda #$00 ; Choose RAM bank zero
lda #$01
sta VIA1::PRA2
.if 0 ; We no longer 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
@@ -107,7 +107,7 @@ L1: lda sp,x
sta sp
stx sp+1 ; Set argument stack ptr
; Switch to the second charset.
; Switch to the lower/UPPER PetSCII charset.
lda #$0E
jsr CHROUT

View File

@@ -1,5 +1,5 @@
;
; 2019-09-20, Greg King
; 2019-12-22, Greg King
;
; unsigned char get_tv (void);
; /* Return the video mode the machine is using. */
@@ -11,9 +11,6 @@
.proc _get_tv
php
sei ; Don't let interrupts interfere
; Point to the video output register.
stz VERA::CTRL ; Use port 0
@@ -25,7 +22,6 @@
sty VERA::ADDR+2
lda VERA::DATA0
plp ; Re-enable interrupts
and #$07 ; Get the type of output signal
rts
.endproc

View File

@@ -1,8 +1,8 @@
;
; Standard joystick driver for the CX16.
; May be installed multiple times when statically linked to the application.
; May be installed multiple times when statically linked to an application.
;
; 2019-11-15 Greg King
; 2019-12-24, Greg King
;
.include "joy-kernel.inc"
@@ -14,6 +14,8 @@
.macpack generic
.macpack module
.importzp tmp1
; ------------------------------------------------------------------------
; Header. Includes jump table
@@ -75,51 +77,21 @@ COUNT: lda #<JOY_COUNT
; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in .A .
READ: php
bit #JOY_COUNT - $01
sei
bnz pad2
READ: and #%00000001
jsr JOYSTICK_GET
sta tmp1
txa
bit #%00001110 ; Is it NES or SNES controller?
bze nes
; Read game pad 1
pad1: ldy JOY1 ; Allow JOY1 to be reread between interrupts
sty JOY1 + 2
lda JOY1 + 1
bit #%00001110
bze nes1
asl JOY1 + 2 ; Get SNES's B button
asl tmp1 ; Get SNES's B button
ror a ; Put it next to the A button
asl JOY1 + 2 ; Drop SNES's Y button
asl tmp1 ; Drop SNES's Y button
asl a ; Get back the B button
ror JOY1 + 2
ror tmp1
asl a ; Get SNES's A button
ror JOY1 + 2 ; Make byte look like NES pad
ror tmp1 ; Make byte look like NES pad
nes1: lda JOY1 + 2
plp
eor #%11111111 ; (The controllers use negative logic)
rts
; Read game pad 2
pad2: ldy JOY2
sty JOY2 + 2
lda JOY2 + 1
bit #%00001110
bze nes2
asl JOY2 + 2
ror a
asl JOY2 + 2
asl a
ror JOY2 + 2
asl a
ror JOY2 + 2
nes2: lda JOY2 + 2
plp
eor #%11111111
nes: lda tmp1 ; The controllers give zeroes for "pressed"
eor #%11111111 ; We want ones for "pressed"
rts

View File

@@ -1,5 +1,5 @@
;
; 2019-11-14, Greg King
; 2019-12-22, Greg King
;
; Link an interrupt handler if joysticks are used by a program.
;
@@ -14,7 +14,7 @@ joy_libref:
lda VERA::IRQ_FLAGS
lsr a
bcc not_vsync
jsr GETJOY ; Bit-bang game controllers
jsr JOYSTICK_SCAN ; Bit-bang game controllers
clc ; Let other Jiffy handlers run
not_vsync:
rts

View File

@@ -1,5 +1,5 @@
;
; 2019-11-06, Greg King
; 2019-12-22, Greg King
;
; unsigned char kbhit (void);
; /* Returns non-zero (true) if a typed character is waiting. */
@@ -11,7 +11,10 @@
.proc _kbhit
ldy VIA1::PRA2 ; (KEY_COUNT is in RAM bank 0)
stz VIA1::PRA2
lda KEY_COUNT ; Get number of characters
sty VIA1::PRA2
tax ; High byte of return (only its zero/nonzero ...
rts ; ... state matters)
rts ; ... state matters)
.endproc

View File

@@ -1,60 +1,94 @@
;
; 2019-11-05, Greg King
; 2019-12-22, Greg King
;
; CX16 Kernal functions
;
.include "cbm_kernal.inc"
.export GETJOY
.export MOUSE
.export SCRMOD
.export FB_INIT
.export FB_GET_INFO
.export FB_SET_PALETTE
.export FB_CURSOR_POSITION
.export FB_CURSOR_NEXT_LINE
.export FB_GET_PIXEL
.export FB_GET_PIXELS
.export FB_SET_PIXEL
.export FB_SET_PIXELS
.export FB_SET_8_PIXELS
.export FB_SET_8_PIXELS_OPAQUE
.export FB_FILL_PIXELS
.export FB_FILTER_PIXELS
.export FB_MOVE_PIXELS
.export GRAPH_INIT
.export GRAPH_CLEAR
.export GRAPH_SET_WINDOW
.export GRAPH_SET_COLORS
.export GRAPH_DRAW_LINE
.export GRAPH_DRAW_RECT
.export GRAPH_MOVE_RECT
.export GRAPH_DRAW_OVAL
.export GRAPH_DRAW_IMAGE
.export GRAPH_SET_FONT
.export GRAPH_GET_CHAR_SIZE
.export GRAPH_PUT_CHAR
.export RESTORE_BASIC
.export CLOCK_SET_DATE_TIME
.export CLOCK_GET_DATE_TIME
.export JOYSTICK_SCAN
.export JOYSTICK_GET
.export SCRMOD
.export MOUSE_CONFIG
.export MOUSE_GET
.export CLSALL
.export JSRFAR
.export INDFET
.export INDSTA
.export INDCMP
.export PRIMM
.export CLSALL
.export LKUPLA
.export LKUPSA
.export PFKEY
.export JSRFAR
.export INDFET
.export INDSTA
.export INDCMP
.export PRIMM
.export CINT
.export IOINIT
.export RAMTAS
.export RESTOR
.export VECTOR
.export SETMSG
.export SECOND
.export TKSA
.export MEMTOP
.export MEMBOT
.export SCNKEY
.export SETTMO
.export ACPTR
.export CIOUT
.export UNTLK
.export UNLSN
.export LISTEN
.export TALK
.export READST
.export SETLFS
.export SETNAM
.export OPEN
.export CLOSE
.export CHKIN
.export CKOUT
.export CLRCH
.export BASIN
.export CHRIN
.export BSOUT
.export CHROUT
.export LOAD
.export SAVE
.export SETTIM
.export RDTIM
.export STOP
.export GETIN
.export CLALL
.export UDTIM
.export SCREEN
.export PLOT
.export IOBASE
.export CINT
.export IOINIT
.export RAMTAS
.export RESTOR
.export VECTOR
.export SETMSG
.export SECOND
.export TKSA
.export MEMTOP
.export MEMBOT
.export SCNKEY
.export SETTMO
.export ACPTR
.export CIOUT
.export UNTLK
.export UNLSN
.export LISTEN
.export TALK
.export READST
.export SETLFS
.export SETNAM
.export OPEN
.export CLOSE
.export CHKIN
.export CKOUT
.export CLRCH
.export BASIN
.export CHRIN
.export BSOUT
.export CHROUT
.export LOAD
.export SAVE
.export SETTIM
.export RDTIM
.export STOP
.export GETIN
.export CLALL
.export UDTIM
.export SCREEN
.export PLOT
.export IOBASE

View File

@@ -1,53 +1,63 @@
;
; Default mouse callbacks for the CX16
;
; 2019-11-09, Greg King
; 2019-12-25, Greg King
;
; All functions in this module should be interrupt safe
; All functions in this module should be interrupt-safe
; because they might be called from an interrupt handler.
;
.export _mouse_def_callbacks
.include "cbm_kernal.inc"
.include "cx16.inc"
; --------------------------------------------------------------------------
; Hide the mouse pointer. Always called with interrupts disabled.
.code
hide: ldx #$00 ; Don't change sprite's scale
lda #$00 ; Disable sprite
jmp MOUSE
msprite:
stz VERA::CTRL ; set address for VERA's data port zero
lda #<(VERA::SPRITE::ATTRIB::Z_FLIP + 0 * 8)
ldx #>(VERA::SPRITE::ATTRIB::Z_FLIP + 0 * 8)
ldy #^(VERA::SPRITE::ATTRIB::Z_FLIP + 0 * 8) | VERA::INC0
sta VERA::ADDR
stx VERA::ADDR+1
sty VERA::ADDR+2
rts
; --------------------------------------------------------------------------
; Show the mouse pointer. Always called with interrupts disabled.
; Hide the mouse pointer.
show: ldx #$00
lda #<-$01 ; Enable sprite
jmp MOUSE
hide: jsr msprite
lda VERA::DATA0
and #<~VERA::SPRITE::DEPTH::LAYER1
sta VERA::DATA0
rts
; --------------------------------------------------------------------------
; Prepare to move the mouse pointer. Always called with interrupts disabled.
; Show the mouse pointer.
show: jsr msprite
lda VERA::DATA0
ora #VERA::SPRITE::DEPTH::LAYER1
sta VERA::DATA0
rts
; --------------------------------------------------------------------------
; Prepare to move the mouse pointer.
prep: ; Fall through
; --------------------------------------------------------------------------
; Draw the mouse pointer. Always called with interrupts disabled.
; Draw the mouse pointer.
draw: ; Fall through
; --------------------------------------------------------------------------
; Move the mouse pointer X position to the value in .XA . Always called with
; interrupts disabled.
; Move the mouse pointer X position to the value in .XA .
movex: ; Already set by drivers
; Fall through
; --------------------------------------------------------------------------
; Move the mouse pointer Y position to the value in .XA . Always called with
; interrupts disabled.
; Move the mouse pointer Y position to the value in .XA .
movey: rts ; Already set by drivers

View File

@@ -1,7 +1,7 @@
;
; Driver for the Commander X16 Kernal's mouse driver.
;
; 2019-11-16, Greg King
; 2019-12-25, Greg King
;
.include "zeropage.inc"
@@ -66,18 +66,16 @@ SCREEN_HEIGHT = 480 - 1
;----------------------------------------------------------------------------
; Global variables.
XPos := ptr3 ; Current mouse position, X
YPos := ptr4 ; Current mouse position, Y
.bss
XPos := MOUSEX ; Current mouse position, X
YPos := MOUSEY ; Current mouse position, Y
XMin := MOUSEL ; X1 value of bounding box
XMax := MOUSER ; X2 value of bounding box
YMin := MOUSET ; Y1 value of bounding box
YMax := MOUSEB ; Y2 value of bounding box
Box := XMin
Buttons := MOUSEBT ; button status bits
Box:
XMin: .res 2 ; X1 value of bounding box
XMax: .res 2 ; X2 value of bounding box
YMin: .res 2 ; Y1 value of bounding box
YMax: .res 2 ; Y2 value of bounding box
.rodata
@@ -121,22 +119,22 @@ INSTALL:
bpl @L1
ldx #$00 ; Don't change sprite's scale
lda #$01 ; Initiate and show sprite
jsr MOUSE
lda #$01 ; Create sprite
jsr MOUSE_CONFIG
; Be sure the mouse cursor is invisible, and at the default location. We
; need to do that here, because the mouse interrupt handler might not set
; the mouse position if it hasn't changed.
sei
jsr CHIDE
.if 0
lda XPos
ldx XPos+1
jsr CMOVEX
lda YPos
ldx YPos+1
jsr CMOVEY
cli
.endif
; Done, return zero
@@ -148,7 +146,10 @@ INSTALL:
; UNINSTALL routine -- is called before the driver is removed from memory.
; No return code required (the driver is removed from memory on return).
UNINSTALL := HIDE ; Hide cursor on exit
UNINSTALL: ; Disable mouse on exit
lda #$00
tax
jmp MOUSE_CONFIG
;----------------------------------------------------------------------------
; HIDE routine -- is called to hide the mouse pointer. The mouse kernel manages
@@ -181,6 +182,7 @@ SETBOX: sta ptr1
lda (ptr1)
ldy #$01
php
sei
sta XMin
lda (ptr1),y
@@ -191,10 +193,12 @@ SETBOX: sta ptr1
iny
lda (ptr1),y
sta YMax
cli
plp
rts
;; Note: SETBOX and GETBOX currently have no effect!
;----------------------------------------------------------------------------
; GETBOX: Return the mouse bounding box. The parameters are passed as they
; come from the C program, that is, a pointer to a mouse_box struct in .XA .
@@ -222,7 +226,10 @@ GETBOX: sta ptr1
; No checks are done to see if the new position is valid (within
; the bounding box or the screen). No return code required.
MOVE: sei ; No interrupts
;; Note: This function currently has no effect!
MOVE: php
sei ; No interrupts
sta YPos
stx YPos+1 ; New Y position
@@ -237,14 +244,16 @@ MOVE: sei ; No interrupts
sta XPos ; New X position
jsr CMOVEX ; Move the cursor
cli ; Allow interrupts
plp ; Allow interrupts
rts
;----------------------------------------------------------------------------
; BUTTONS: Return the CBM 1351 button mask in .XA .
BUTTONS:
lda Buttons
ldx #XPos
jsr MOUSE_GET
and #%00000111
tax
lda ButtMask,x
@@ -255,9 +264,9 @@ BUTTONS:
; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
; No return code required.
POS: ldy #MOUSE_POS::XCOORD ; Structure offset
POS: jsr BUTTONS
sei ; Disable interrupts
POS1: ldy #MOUSE_POS::XCOORD ; Structure offset
lda XPos ; Transfer the position
sta (ptr1),y
lda XPos+1
@@ -267,8 +276,6 @@ POS: ldy #MOUSE_POS::XCOORD ; Structure offset
iny
sta (ptr1),y
lda YPos+1
cli ; Enable interrupts
iny
sta (ptr1),y ; Store last byte
rts ; Done
@@ -282,20 +289,15 @@ POS: ldy #MOUSE_POS::XCOORD ; Structure offset
; call mouse_pos to initialize the struct pointer, and fill the position
; fields.
INFO: jsr POS
; Fill in the button state
jsr BUTTONS ; Will not touch ptr1
INFO: jsr BUTTONS ; Will not touch ptr1
ldy #MOUSE_INFO::BUTTONS
sta (ptr1),y
rts
jmp POS1
;----------------------------------------------------------------------------
; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
; specific data in ptr1, and the ioctl code in A.
; Must return an error code in .XA .
;
IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioctls, for now
ldx #>MOUSE_ERR_INV_IOCTL

View File

@@ -1,7 +1,7 @@
;
; Address of the static standard mouse driver
;
; 2019-11-08,Greg King
; 2019-11-08, Greg King
;
; const void mouse_static_stddrv[];
;

View File

@@ -1,5 +1,5 @@
;
; 2019-11-06, Greg King
; 2019-12-22, Greg King
;
; void __fastcall__ set_tv (unsigned char);
; /* Set the video mode the machine will use. */
@@ -11,9 +11,6 @@
.proc _set_tv
php
sei ; Don't let interrupts interfere
; Point to the video output register.
stz VERA::CTRL ; Use port 0
@@ -25,6 +22,5 @@
stx VERA::ADDR+2
sta VERA::DATA0
plp ; Re-enable interrupts
rts
.endproc

View File

@@ -9,7 +9,7 @@
.import utscopy
__sysuname := utscopy
__sysuname := utscopy
;--------------------------------------------------------------------------
; Data. We define a fixed utsname struct here, and just copy it.

View File

@@ -1,11 +1,10 @@
;
; Address of the static standard TGI driver
;
; 2019-11-06, Greg King
; 2019-12-22, Greg King
;
; const void tgi_static_stddrv[];
;
.import _cx16_640x4c_tgi
.export _tgi_static_stddrv := _cx16_640x4c_tgi
.import _cx16_320x8b_tgi
.export _tgi_static_stddrv := _cx16_320x8b_tgi

View File

@@ -1,7 +1,7 @@
;
; Name of the standard TGI driver
;
; 2019-11-06, Greg King
; 2019-12-22, Greg King
;
; const char tgi_stddrv[];
;
@@ -9,5 +9,4 @@
.export _tgi_stddrv
.rodata
_tgi_stddrv: .asciiz "cx16-640x4c.tgi"
_tgi_stddrv: .asciiz "cx16-320x8b.tgi"

View File

@@ -1,19 +1,18 @@
;
; 2019-10-22, Greg King
; 2019-12-22, Greg King
;
; Set the __far__ address that VERA will use for data access.
; This is a support function for the fastcall functions vpeek() and vpoke().
;
.export vset
.export vaddr0
.importzp sreg
.include "cx16.inc"
vset: ldy sreg
sei ; don't let interrupt handlers interfere
stz VERA::CTRL ; set address for VERA's data port zero
vaddr0: stz VERA::CTRL ; set address for VERA's data port zero
ldy sreg
sta VERA::ADDR
stx VERA::ADDR+1
sty VERA::ADDR+2

View File

@@ -1,5 +1,5 @@
;
; 2019-10-22, Greg King
; 2019-12-22, Greg King
;
; unsigned char fastcall vpeek (unsigned long addr);
; /* Get a byte from a location in VERA's internal address space. */
@@ -7,13 +7,11 @@
.export _vpeek
.import vset
.import vaddr0
.include "cx16.inc"
_vpeek: php ; (vset blocks interrupts)
jsr vset ; put VERA's address
_vpeek: jsr vaddr0 ; put VERA's address
ldx #>$0000
lda VERA::DATA0 ; read VERA port zero
plp
rts

View File

@@ -1,5 +1,5 @@
;
; 2019-10-22, Greg King
; 2019-12-22, Greg King
;
; void fastcall vpoke (unsigned char data, unsigned long addr);
; /* Put a byte into a location in VERA's internal address space.
@@ -9,13 +9,11 @@
.export _vpoke
.import vset, popa
.import vaddr0, popa
.include "cx16.inc"
_vpoke: php ; (vset blocks interrupts)
jsr vset ; put VERA's address
_vpoke: jsr vaddr0 ; put VERA's address
jsr popa
sta VERA::DATA0 ; write data to VERA port zero
plp
rts

View File

@@ -1,9 +1,10 @@
;
; 2019-09-26, Greg King
; 2019-12-23, Greg King
;
; void waitvsync (void);
; /* Wait for the start of the next video field. */
;
; VERA's vertical sync causes IRQs which increment the jiffy clock.
; VERA's vertical sync causes IRQs which increment the jiffy timer.
;
.export _waitvsync
@@ -11,7 +12,10 @@
.include "cx16.inc"
_waitvsync:
lda TIME + 2
: cmp TIME + 2
ldx VIA1::PRA2 ; (TIMER is in RAM bank 0)
stz VIA1::PRA2
lda TIMER + 2
: cmp TIMER + 2
beq :- ; Wait for next jiffy
stx VIA1::PRA2
rts