Created a target and a library for the Commander X16 prototype computer.
This commit is contained in:
@@ -7,6 +7,7 @@ CBMS = c128 \
|
||||
c64 \
|
||||
cbm510 \
|
||||
cbm610 \
|
||||
cx16 \
|
||||
pet \
|
||||
plus4 \
|
||||
vic20
|
||||
|
||||
14
libsrc/cx16/_scrsize.s
Normal file
14
libsrc/cx16/_scrsize.s
Normal file
@@ -0,0 +1,14 @@
|
||||
;
|
||||
; 2019-09-16, Greg King
|
||||
;
|
||||
; Screen size info
|
||||
;
|
||||
|
||||
.export screensize
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
screensize:
|
||||
ldx LLEN
|
||||
ldy NLINES
|
||||
rts
|
||||
50
libsrc/cx16/bankramaddr.s
Normal file
50
libsrc/cx16/bankramaddr.s
Normal file
@@ -0,0 +1,50 @@
|
||||
;
|
||||
; 2019-09-16, Greg King
|
||||
;
|
||||
; This module supplies the load addresses that are expected
|
||||
; by a Commander X16 in the first two bytes of banked RAM load files.
|
||||
;
|
||||
|
||||
; The following symbol is used by a linker config. to force
|
||||
; this module to get included into the output files.
|
||||
.export __BANKRAMADDR__: abs = 1
|
||||
|
||||
.segment "BRAM00ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM01ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM02ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM03ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM04ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM05ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM06ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM07ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM08ADDR"
|
||||
|
||||
.addr *+2
|
||||
|
||||
.segment "BRAM09ADDR"
|
||||
|
||||
.addr *+2
|
||||
27
libsrc/cx16/bordercolor.s
Normal file
27
libsrc/cx16/bordercolor.s
Normal file
@@ -0,0 +1,27 @@
|
||||
;
|
||||
; 2019-09-23, Greg King
|
||||
;
|
||||
; unsigned char __fastcall__ bordercolor (unsigned char color);
|
||||
; /* Set the color for the border. The old color setting is returned. */
|
||||
;
|
||||
|
||||
.export _bordercolor
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
_bordercolor:
|
||||
tax
|
||||
|
||||
; Point to the border color register.
|
||||
|
||||
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
|
||||
109
libsrc/cx16/break.s
Normal file
109
libsrc/cx16/break.s
Normal file
@@ -0,0 +1,109 @@
|
||||
;
|
||||
; 1998-09-27, Ullrich von Bassewitz
|
||||
; 2019-09-08, Greg King
|
||||
;
|
||||
; void __fastcall__ set_brk (unsigned Addr);
|
||||
; void reset_brk (void);
|
||||
;
|
||||
|
||||
.export _set_brk, _reset_brk
|
||||
.destructor _reset_brk
|
||||
.export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
.bss
|
||||
_brk_a: .res 1
|
||||
_brk_x: .res 1
|
||||
_brk_y: .res 1
|
||||
_brk_sr: .res 1
|
||||
_brk_pc: .res 2
|
||||
|
||||
oldvec: .res 2 ; Old vector
|
||||
|
||||
|
||||
.data
|
||||
uservec: jmp $FFFF ; Patched at runtime
|
||||
|
||||
|
||||
.code
|
||||
|
||||
; Set the break vector
|
||||
.proc _set_brk
|
||||
|
||||
sta uservec+1
|
||||
stx uservec+2 ; Set the user vector
|
||||
|
||||
lda oldvec
|
||||
ora oldvec+1 ; Did we save the vector already?
|
||||
bne L1 ; Jump if we installed the handler already
|
||||
|
||||
lda BRKVec
|
||||
sta oldvec
|
||||
lda BRKVec+1
|
||||
sta oldvec+1 ; Save the old vector
|
||||
|
||||
L1: lda #<brk_handler ; Set the break vector to our routine
|
||||
ldx #>brk_handler
|
||||
sta BRKVec
|
||||
stx BRKVec+1
|
||||
rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
; Reset the break vector
|
||||
.proc _reset_brk
|
||||
|
||||
lda oldvec
|
||||
ldx oldvec+1
|
||||
beq @L9 ; Jump if vector not installed
|
||||
sta BRKVec
|
||||
stx BRKVec+1
|
||||
lda #$00
|
||||
sta oldvec ; Clear the old vector
|
||||
stx oldvec+1
|
||||
@L9: rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
|
||||
; Break handler, called if a break occurs
|
||||
|
||||
.proc brk_handler
|
||||
|
||||
pla
|
||||
sta _brk_y
|
||||
pla
|
||||
sta _brk_x
|
||||
pla
|
||||
sta _brk_a
|
||||
pla
|
||||
and #$EF ; Clear break bit
|
||||
sta _brk_sr
|
||||
pla ; PC low
|
||||
sec
|
||||
sbc #2 ; Point to start of brk
|
||||
sta _brk_pc
|
||||
pla ; PC high
|
||||
sbc #0
|
||||
sta _brk_pc+1
|
||||
|
||||
jsr uservec ; Call the user's routine
|
||||
|
||||
lda _brk_pc+1
|
||||
pha
|
||||
lda _brk_pc
|
||||
pha
|
||||
lda _brk_sr
|
||||
pha
|
||||
ldx _brk_x
|
||||
ldy _brk_y
|
||||
lda _brk_a
|
||||
rti ; Jump back...
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
72
libsrc/cx16/cgetc.s
Normal file
72
libsrc/cx16/cgetc.s
Normal file
@@ -0,0 +1,72 @@
|
||||
;
|
||||
; 2019-09-23, Greg King
|
||||
;
|
||||
; char cgetc (void);
|
||||
; /* Return a character from the keyboard. */
|
||||
;
|
||||
|
||||
.export _cgetc
|
||||
|
||||
.import cursor, GETIN
|
||||
|
||||
.include "cx16.inc"
|
||||
.macpack generic
|
||||
|
||||
|
||||
_cgetc: ldx KEY_COUNT ; Get number of characters
|
||||
bnz L3 ; Jump if there are already chars waiting
|
||||
|
||||
; Switch the cursor on if wanted.
|
||||
|
||||
lda CURS_FLAG ; Save cursor's current enable flag
|
||||
tay
|
||||
lda cursor
|
||||
jsr setcursor
|
||||
L1: lda KEY_COUNT
|
||||
bze L1 ; Wait for key
|
||||
tya
|
||||
eor #%00000001 ; (Cursor flag uses negative logic)
|
||||
jsr setcursor ; Restore previous cursor condition
|
||||
|
||||
; An internal Kernal function can't be used because it might be moved in future
|
||||
; revisions. Use an official function; but, make sure that it reads
|
||||
; the keyboard.
|
||||
|
||||
L3: ldy IN_DEV ; Save current input device
|
||||
stz IN_DEV ; Keyboard
|
||||
jsr GETIN ; Read char, and return in .A
|
||||
sty IN_DEV ; Restore input device
|
||||
ldx #>$0000
|
||||
rts
|
||||
|
||||
; Switch the cursor on or off.
|
||||
|
||||
setcursor:
|
||||
tax ; On or off?
|
||||
bnz seton ; Go set it on
|
||||
lda CURS_FLAG ; Is the cursor currently off?
|
||||
bnz crs9 ; Jump if yes
|
||||
inc CURS_FLAG ; Mark it as off
|
||||
ldx CURS_STATE ; Cursor currently displayed?
|
||||
bze crs9 ; Jump if not
|
||||
|
||||
; Restore the current character in video RAM.
|
||||
; Restore that character's colors.
|
||||
|
||||
stz VERA::CTRL ; Use port 0
|
||||
lda CURS_Y
|
||||
sta VERA::ADDR+1 ; Set row number
|
||||
lda #VERA::INC1 ; Increment address by one
|
||||
sta VERA::ADDR+2
|
||||
lda CURS_X ; Get character column
|
||||
asl a
|
||||
sta VERA::ADDR
|
||||
ldx CURS_CHAR
|
||||
stx VERA::DATA0
|
||||
ldx CURS_COLOR
|
||||
stx VERA::DATA0
|
||||
stz CURS_STATE ; Cursor not displayed
|
||||
crs9: rts
|
||||
|
||||
seton: stz CURS_FLAG
|
||||
rts
|
||||
26
libsrc/cx16/clrscr.s
Normal file
26
libsrc/cx16/clrscr.s
Normal file
@@ -0,0 +1,26 @@
|
||||
;
|
||||
; 2019-09-22, Greg King
|
||||
;
|
||||
; void clrscr (void);
|
||||
; /* Clear the screen. */
|
||||
;
|
||||
|
||||
.export _clrscr
|
||||
|
||||
.import CHROUT
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
; An internal Kernal function can't be used because it might be moved in future
|
||||
; revisions. Use an official function; but, make sure that it prints
|
||||
; to the screen.
|
||||
|
||||
_clrscr:
|
||||
ldy OUT_DEV ; Save current output device
|
||||
ldx #$03 ; Screen device
|
||||
stx OUT_DEV
|
||||
lda #$93
|
||||
jsr CHROUT ; Print clear-screen character
|
||||
sty OUT_DEV ; Restore output device
|
||||
rts
|
||||
43
libsrc/cx16/color.s
Normal file
43
libsrc/cx16/color.s
Normal file
@@ -0,0 +1,43 @@
|
||||
;
|
||||
; 2019-09-16, Greg King
|
||||
;
|
||||
; unsigned char __fastcall__ textcolor (unsigned char color);
|
||||
; unsigned char __fastcall__ bgcolor (unsigned char color);
|
||||
;
|
||||
|
||||
|
||||
.export _textcolor, _bgcolor
|
||||
|
||||
.importzp tmp1
|
||||
.include "cx16.inc"
|
||||
|
||||
_textcolor:
|
||||
and #$0F
|
||||
sta tmp1
|
||||
ldx CHARCOLOR ; get old values
|
||||
txa
|
||||
and #<~$0F ; keep screen color, remove text color
|
||||
ora tmp1
|
||||
sta CHARCOLOR ; set new values
|
||||
txa
|
||||
and #$0F
|
||||
rts
|
||||
|
||||
|
||||
_bgcolor:
|
||||
asl a ; move number to screen-color nybble
|
||||
asl a
|
||||
asl a
|
||||
asl a
|
||||
sta tmp1
|
||||
ldx CHARCOLOR ; get old values
|
||||
txa
|
||||
and #<~$F0 ; remove screen color, keep text color
|
||||
ora tmp1
|
||||
sta CHARCOLOR ; set new values
|
||||
txa
|
||||
lsr a ; get screen color
|
||||
lsr a
|
||||
lsr a
|
||||
lsr a
|
||||
rts
|
||||
9
libsrc/cx16/conio.s
Normal file
9
libsrc/cx16/conio.s
Normal file
@@ -0,0 +1,9 @@
|
||||
;
|
||||
; 2019-09-23, Greg King
|
||||
;
|
||||
; Low-level stuff for screen output/console input
|
||||
;
|
||||
|
||||
.exportzp CURS_X, CURS_Y
|
||||
|
||||
.include "cx16.inc"
|
||||
48
libsrc/cx16/cpeekc.s
Normal file
48
libsrc/cx16/cpeekc.s
Normal file
@@ -0,0 +1,48 @@
|
||||
;
|
||||
; 2016-02-28, Groepaz
|
||||
; 2019-09-25, Greg King
|
||||
;
|
||||
; char cpeekc (void);
|
||||
; /* Return the character from the current cursor position. */
|
||||
;
|
||||
|
||||
.export _cpeekc
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
_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
|
||||
stz VERA::ADDR+2
|
||||
lda CURS_X ; get character column
|
||||
asl a
|
||||
sta VERA::ADDR
|
||||
lda VERA::DATA0 ; get screen code
|
||||
plp
|
||||
ldx #>$0000
|
||||
and #<~%10000000 ; remove reverse bit
|
||||
|
||||
; Convert the screen code into a PetSCII code.
|
||||
; $00 - $1F: +$40
|
||||
; $20 - $3F
|
||||
; $40 - $5f: +$20
|
||||
; $60 - $7F: +$40
|
||||
|
||||
cmp #$20
|
||||
bcs @sk1 ;(bge)
|
||||
ora #$40
|
||||
rts
|
||||
|
||||
@sk1: cmp #$40
|
||||
bcc @end ;(blt)
|
||||
cmp #$60
|
||||
bcc @sk2 ;(blt)
|
||||
;sec
|
||||
adc #$20 - $01
|
||||
@sk2: ;clc ; both above cmp and adc clear carry flag
|
||||
adc #$20
|
||||
@end: rts
|
||||
27
libsrc/cx16/cpeekcolor.s
Normal file
27
libsrc/cx16/cpeekcolor.s
Normal file
@@ -0,0 +1,27 @@
|
||||
;
|
||||
; 2019-09-25, Greg King
|
||||
;
|
||||
; unsigned char cpeekcolor (void);
|
||||
; /* Return the colors from the current cursor position. */
|
||||
;
|
||||
|
||||
.export _cpeekcolor
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
_cpeekcolor:
|
||||
php
|
||||
sei ; don't let cursor blinking interfere
|
||||
stz VERA::CTRL ; use port 0
|
||||
lda CURS_Y
|
||||
sta VERA::ADDR+1 ; set row number
|
||||
stz VERA::ADDR+2
|
||||
lda CURS_X ; get character column
|
||||
sec ; color attribute is second byte
|
||||
rol a
|
||||
sta VERA::ADDR
|
||||
lda VERA::DATA0 ; get color
|
||||
plp
|
||||
ldx #>$0000
|
||||
rts
|
||||
32
libsrc/cx16/cpeekrevers.s
Normal file
32
libsrc/cx16/cpeekrevers.s
Normal file
@@ -0,0 +1,32 @@
|
||||
;
|
||||
; 2016-02-28, Groepaz
|
||||
; 2019-09-25, Greg King
|
||||
;
|
||||
; unsigned char cpeekrevers (void);
|
||||
; /* Return the reverse attribute from the current cursor position.
|
||||
; ** If the character is reversed, then return 1; return 0 otherwise.
|
||||
; */
|
||||
;
|
||||
|
||||
.export _cpeekrevers
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
_cpeekrevers:
|
||||
php
|
||||
sei ; don't let cursor blinking interfere
|
||||
stz VERA::CTRL ; use port 0
|
||||
lda CURS_Y
|
||||
sta VERA::ADDR+1 ; set row number
|
||||
stz VERA::ADDR+2
|
||||
lda CURS_X ; get character column
|
||||
asl a
|
||||
sta VERA::ADDR
|
||||
lda VERA::DATA0 ; get screen code
|
||||
plp
|
||||
and #%10000000 ; get reverse bit
|
||||
asl a
|
||||
tax ; ldx #>$0000
|
||||
rol a ; return boolean value
|
||||
rts
|
||||
0
libsrc/cx16/cpeeks.s
Normal file
0
libsrc/cx16/cpeeks.s
Normal file
98
libsrc/cx16/cputc.s
Normal file
98
libsrc/cx16/cputc.s
Normal file
@@ -0,0 +1,98 @@
|
||||
;
|
||||
; 2019-09-23, Greg King
|
||||
;
|
||||
; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c);
|
||||
; void __fastcall__ cputc (char c);
|
||||
;
|
||||
|
||||
.export _cputcxy, _cputc, cputdirect, putchar
|
||||
.export newline, plot
|
||||
|
||||
.import gotoxy, PLOT
|
||||
|
||||
.include "cx16.inc"
|
||||
.macpack generic
|
||||
|
||||
|
||||
; First, move to a new position.
|
||||
|
||||
_cputcxy:
|
||||
pha ; Save C
|
||||
jsr gotoxy ; Set cursor, drop x and y
|
||||
pla ; Restore C
|
||||
|
||||
; Print a character.
|
||||
|
||||
_cputc: cmp #$0D ; LF?
|
||||
beq newline
|
||||
cmp #$0A ; CR?
|
||||
beq plotx0
|
||||
|
||||
; Printable char of some sort
|
||||
|
||||
cmp #' '
|
||||
blt cputdirect ; Other control char
|
||||
tay
|
||||
bmi L10
|
||||
cmp #$60
|
||||
blt L2
|
||||
and #<~%00100000
|
||||
bra cputdirect
|
||||
|
||||
; Handle character if high bit set
|
||||
|
||||
L10: and #<~%10000000 ; Remove high bit
|
||||
ora #%01000000
|
||||
bra cputdirect
|
||||
|
||||
L2: and #<~%01000000
|
||||
|
||||
cputdirect:
|
||||
jsr putchar ; Write character to screen, return .Y
|
||||
|
||||
; Advance cursor position.
|
||||
|
||||
iny
|
||||
cpy LLEN ; Reached end of line?
|
||||
bne L3
|
||||
jsr newline ; Next line
|
||||
ldy #$00 ; + CR
|
||||
L3: sty CURS_X
|
||||
rts
|
||||
|
||||
; Move down.
|
||||
|
||||
newline:
|
||||
inc SCREEN_PTR+1
|
||||
inc CURS_Y
|
||||
rts
|
||||
|
||||
|
||||
; Set the cursor's position, calculate RAM pointer.
|
||||
|
||||
plotx0: stz CURS_X
|
||||
plot: ldy CURS_X
|
||||
ldx CURS_Y
|
||||
clc
|
||||
jmp PLOT ; Set the new cursor
|
||||
|
||||
|
||||
; Write one screen-code and color to the video RAM without doing anything else.
|
||||
; Return the x position in Y.
|
||||
|
||||
putchar:
|
||||
ora RVS ; Set revers bit
|
||||
tax
|
||||
stz VERA::CTRL ; Use port 0
|
||||
lda CURS_Y
|
||||
sta VERA::ADDR+1 ; Set row number
|
||||
lda #VERA::INC1 ; Increment address by one
|
||||
sta VERA::ADDR+2
|
||||
ldy CURS_X ; Get character column
|
||||
tya
|
||||
asl a
|
||||
sta VERA::ADDR
|
||||
stx VERA::DATA0
|
||||
lda CHARCOLOR
|
||||
sta VERA::DATA0
|
||||
rts
|
||||
115
libsrc/cx16/crt0.s
Normal file
115
libsrc/cx16/crt0.s
Normal file
@@ -0,0 +1,115 @@
|
||||
;
|
||||
; Start-up code for cc65 (CX16 version)
|
||||
;
|
||||
|
||||
.export _exit
|
||||
.export __STARTUP__ : absolute = 1 ; Mark as start-up
|
||||
|
||||
.import initlib, donelib
|
||||
.import zerobss, callmain
|
||||
.import BSOUT
|
||||
.import __MAIN_START__, __MAIN_SIZE__ ; Linker-generated
|
||||
.importzp ST
|
||||
|
||||
.include "zeropage.inc"
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Start-up code
|
||||
|
||||
.segment "STARTUP"
|
||||
|
||||
Start: tsx
|
||||
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.
|
||||
|
||||
jsr init
|
||||
|
||||
; Clear the BSS data.
|
||||
|
||||
jsr zerobss
|
||||
|
||||
; Push the command-line arguments; and, call main().
|
||||
|
||||
jsr callmain
|
||||
|
||||
; Back from main() [this is also the exit() entry]. Run the module destructors.
|
||||
|
||||
_exit: pha ; Save the return code on stack
|
||||
jsr donelib
|
||||
|
||||
; Copy back the zero-page stuff.
|
||||
|
||||
ldx #zpspace-1
|
||||
L2: lda zpsave,x
|
||||
sta sp,x
|
||||
dex
|
||||
bpl L2
|
||||
|
||||
; Place the program return code into BASIC's status variable.
|
||||
|
||||
pla
|
||||
sta ST
|
||||
|
||||
; Restore the system stuff.
|
||||
|
||||
ldx spsave
|
||||
txs ; Restore stack pointer
|
||||
ldx banksave
|
||||
stx VIA1::PRA2 ; Restore former RAM bank
|
||||
|
||||
; Back to BASIC.
|
||||
|
||||
rts
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "ONCE"
|
||||
|
||||
init:
|
||||
|
||||
; Change to the first RAM bank.
|
||||
|
||||
lda VIA1::PRA2
|
||||
sta banksave ; Save the current bank number
|
||||
lda #$00 ; Choose RAM bank zero
|
||||
sta VIA1::PRA2
|
||||
|
||||
; Save the zero-page locations that we need.
|
||||
|
||||
ldx #zpspace-1
|
||||
L1: lda sp,x
|
||||
sta zpsave,x
|
||||
dex
|
||||
bpl L1
|
||||
|
||||
; Set up the stack.
|
||||
|
||||
lda #<(__MAIN_START__ + __MAIN_SIZE__)
|
||||
ldx #>(__MAIN_START__ + __MAIN_SIZE__)
|
||||
sta sp
|
||||
stx sp+1 ; Set argument stack ptr
|
||||
|
||||
; Switch to the second charset.
|
||||
|
||||
lda #$0E
|
||||
jsr BSOUT
|
||||
|
||||
; Call the module constructors.
|
||||
|
||||
jmp initlib
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data
|
||||
|
||||
.segment "INIT"
|
||||
|
||||
banksave:
|
||||
.res 1
|
||||
spsave: .res 1
|
||||
zpsave: .res zpspace
|
||||
8
libsrc/cx16/devnum.s
Normal file
8
libsrc/cx16/devnum.s
Normal file
@@ -0,0 +1,8 @@
|
||||
;
|
||||
; 2010-02-14, Oliver Schmidt
|
||||
; 2019-09-08, Greg King
|
||||
;
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
.exportzp devnum := DEVNUM
|
||||
20
libsrc/cx16/get_ostype.s
Normal file
20
libsrc/cx16/get_ostype.s
Normal file
@@ -0,0 +1,20 @@
|
||||
;
|
||||
; 2019-09-09, Greg King
|
||||
;
|
||||
; signed char get_ostype(void)
|
||||
; /* Return a "build version". */
|
||||
;
|
||||
; Positive number -- release build
|
||||
; Negative number -- prerelease build
|
||||
; -1 -- custom build
|
||||
;
|
||||
|
||||
.export _get_ostype
|
||||
|
||||
.proc _get_ostype
|
||||
ldx #>$0000
|
||||
lda $ff80
|
||||
bpl :+
|
||||
dex ; negative
|
||||
: rts
|
||||
.endproc
|
||||
31
libsrc/cx16/get_tv.s
Normal file
31
libsrc/cx16/get_tv.s
Normal file
@@ -0,0 +1,31 @@
|
||||
;
|
||||
; 2019-09-20, Greg King
|
||||
;
|
||||
; unsigned char get_tv (void);
|
||||
; /* Return the video mode the machine is using. */
|
||||
;
|
||||
|
||||
.export _get_tv
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
.proc _get_tv
|
||||
php
|
||||
sei ; Don't let interrupts interfere
|
||||
|
||||
; Point to the video output register.
|
||||
|
||||
stz VERA::CTRL ; Use port 0
|
||||
lda #<VERA::COMPOSER::VIDEO
|
||||
ldx #>VERA::COMPOSER::VIDEO
|
||||
ldy #^VERA::COMPOSER::VIDEO
|
||||
sta VERA::ADDR
|
||||
stx VERA::ADDR+1
|
||||
sty VERA::ADDR+2
|
||||
|
||||
lda VERA::DATA0
|
||||
plp ; Re-enable interrupts
|
||||
and #$07 ; Get the type of output signal
|
||||
rts
|
||||
.endproc
|
||||
48
libsrc/cx16/irq.s
Normal file
48
libsrc/cx16/irq.s
Normal file
@@ -0,0 +1,48 @@
|
||||
;
|
||||
; IRQ handling (CX16 version)
|
||||
;
|
||||
|
||||
.export initirq, doneirq
|
||||
.import callirq
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "ONCE"
|
||||
|
||||
initirq:
|
||||
lda IRQVec
|
||||
ldx IRQVec+1
|
||||
sta IRQInd+1
|
||||
stx IRQInd+2
|
||||
lda #<IRQStub
|
||||
ldx #>IRQStub
|
||||
jmp setvec
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.code
|
||||
|
||||
doneirq:
|
||||
lda IRQInd+1
|
||||
ldx IRQInd+2
|
||||
setvec: sei
|
||||
sta IRQVec
|
||||
stx IRQVec+1
|
||||
cli
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.segment "LOWCODE"
|
||||
|
||||
IRQStub:
|
||||
jsr callirq ; Call the functions
|
||||
jmp IRQInd ; Jump to the saved IRQ vector
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
|
||||
.data
|
||||
|
||||
IRQInd: jmp $0000
|
||||
119
libsrc/cx16/joy/cx16-stdjoy.s
Normal file
119
libsrc/cx16/joy/cx16-stdjoy.s
Normal file
@@ -0,0 +1,119 @@
|
||||
;
|
||||
; Standard joystick driver for the CX16.
|
||||
; May be used multiple times when statically linked to the application.
|
||||
;
|
||||
; 2019-09-23, Greg King
|
||||
;
|
||||
|
||||
.include "joy-kernel.inc"
|
||||
.include "joy-error.inc"
|
||||
|
||||
.include "cbm_kernal.inc"
|
||||
.include "cx16.inc"
|
||||
|
||||
.macpack generic
|
||||
.macpack module
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Header. Includes jump table
|
||||
|
||||
module_header _cx16_stdjoy_joy
|
||||
|
||||
; Driver signature
|
||||
|
||||
.byte $6A, $6F, $79 ; ASCII "joy"
|
||||
.byte JOY_API_VERSION ; Driver API version number
|
||||
|
||||
; Library reference
|
||||
|
||||
.addr $0000
|
||||
|
||||
; Jump table.
|
||||
|
||||
.addr INSTALL
|
||||
.addr UNINSTALL
|
||||
.addr COUNT
|
||||
.addr READ
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Constant
|
||||
|
||||
JOY_COUNT = 2 ; Number of joysticks we support
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Data.
|
||||
|
||||
|
||||
.code
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; 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.
|
||||
; Must return a JOY_ERR_xx code in a/x.
|
||||
;
|
||||
|
||||
INSTALL:
|
||||
lda #<JOY_ERR_OK
|
||||
ldx #>JOY_ERR_OK
|
||||
; rts ; Run into UNINSTALL instead
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; UNINSTALL routine. Is called before the driver is removed from memory.
|
||||
; Can do clean-up or whatever. Must not return anything.
|
||||
;
|
||||
|
||||
UNINSTALL:
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; COUNT: Return the total number of possible joysticks in a/x.
|
||||
;
|
||||
|
||||
COUNT: lda #<JOY_COUNT
|
||||
ldx #>JOY_COUNT
|
||||
rts
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; READ: Read a particular joystick passed in A.
|
||||
;
|
||||
; TODO: Find a way to report the SNES controller's extra four lines.
|
||||
;
|
||||
|
||||
READ: pha
|
||||
jsr GETJOY
|
||||
pla
|
||||
bne pad2
|
||||
|
||||
; Read game pad 1
|
||||
|
||||
pad1: lda JOY1 + 1
|
||||
bit #%00001110
|
||||
beq nes1
|
||||
asl JOY1 ; Get SNES's B button
|
||||
ror a ; Put it next to the A button
|
||||
asl JOY1 ; Drop SNES's Y button
|
||||
asl a ; Get the B button
|
||||
ror JOY1
|
||||
asl a ; Get SNES's A button
|
||||
ror JOY1 ; Make byte look like NES pad
|
||||
nes1: lda JOY1
|
||||
eor #%11111111 ; We don't want the pad's negative logic
|
||||
rts
|
||||
|
||||
; Read game pad 2
|
||||
|
||||
pad2: lda JOY2 + 1
|
||||
bit #%00001110
|
||||
beq nes2
|
||||
asl JOY2
|
||||
ror a
|
||||
asl JOY2
|
||||
asl a
|
||||
ror JOY2
|
||||
asl a
|
||||
ror JOY2
|
||||
nes2: lda JOY2
|
||||
eor #%11111111
|
||||
rts
|
||||
10
libsrc/cx16/joy_stat_stddrv.s
Normal file
10
libsrc/cx16/joy_stat_stddrv.s
Normal file
@@ -0,0 +1,10 @@
|
||||
;
|
||||
; Address of the static standard joystick driver
|
||||
;
|
||||
; 2019-09-19, Greg King
|
||||
;
|
||||
; const void joy_static_stddrv[];
|
||||
;
|
||||
|
||||
.import _cx16_stdjoy_joy
|
||||
.export _joy_static_stddrv := _cx16_stdjoy_joy
|
||||
13
libsrc/cx16/joy_stddrv.s
Normal file
13
libsrc/cx16/joy_stddrv.s
Normal file
@@ -0,0 +1,13 @@
|
||||
;
|
||||
; Name of the standard joystick driver
|
||||
;
|
||||
; 2019-09-19, Greg King
|
||||
;
|
||||
; const char joy_stddrv[];
|
||||
;
|
||||
|
||||
.export _joy_stddrv
|
||||
|
||||
.rodata
|
||||
|
||||
_joy_stddrv: .asciiz "cx16-stdjoy.joy"
|
||||
17
libsrc/cx16/kbhit.s
Normal file
17
libsrc/cx16/kbhit.s
Normal file
@@ -0,0 +1,17 @@
|
||||
;
|
||||
; 2019-09-20, Greg King
|
||||
;
|
||||
; unsigned char kbhit (void);
|
||||
; /* Returns non-zero (true) if a typed character is waiting. */
|
||||
;
|
||||
|
||||
.export _kbhit
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
.proc _kbhit
|
||||
ldx #>$0000 ; High byte of return
|
||||
lda KEY_COUNT ; Get number of characters
|
||||
rts
|
||||
.endproc
|
||||
59
libsrc/cx16/kernal.s
Normal file
59
libsrc/cx16/kernal.s
Normal file
@@ -0,0 +1,59 @@
|
||||
;
|
||||
; 2019-09-22, Greg King
|
||||
;
|
||||
; CX16 Kernal functions
|
||||
;
|
||||
|
||||
.include "cbm_kernal.inc"
|
||||
|
||||
.export GETJOY
|
||||
|
||||
.export CLSALL
|
||||
.export SWAPPER
|
||||
.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
|
||||
18
libsrc/cx16/libref.s
Normal file
18
libsrc/cx16/libref.s
Normal file
@@ -0,0 +1,18 @@
|
||||
;
|
||||
; 2013-05-31, Oliver Schmidt
|
||||
; 2019-09-22, Greg King
|
||||
;
|
||||
|
||||
.export em_libref
|
||||
.export joy_libref
|
||||
.export mouse_libref
|
||||
.export ser_libref
|
||||
.export tgi_libref
|
||||
|
||||
.import _exit
|
||||
|
||||
em_libref := _exit
|
||||
joy_libref := _exit
|
||||
mouse_libref := _exit
|
||||
ser_libref := _exit
|
||||
tgi_libref := _exit
|
||||
137
libsrc/cx16/mainargs.s
Normal file
137
libsrc/cx16/mainargs.s
Normal file
@@ -0,0 +1,137 @@
|
||||
; mainargs.s
|
||||
;
|
||||
; Ullrich von Bassewitz, 2003-03-07
|
||||
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
|
||||
; 2005-02-26, Ullrich von Bassewitz
|
||||
; 2019-09-08, Greg King
|
||||
;
|
||||
; Scan a group of arguments that are in BASIC's input-buffer.
|
||||
; Build an array that points to the beginning of each argument.
|
||||
; Send, to main(), that array and the count of the arguments.
|
||||
;
|
||||
; Command-lines look like these lines:
|
||||
;
|
||||
; run
|
||||
; run : rem
|
||||
; run:rem arg1 " arg 2 is quoted " arg3 "" arg5
|
||||
;
|
||||
; "run" and "rem" are entokenned; the args. are not. Leading and trailing
|
||||
; spaces outside of quotes are ignored.
|
||||
;
|
||||
; TO-DO:
|
||||
; - The "file-name" might be a path-name; don't copy the directory-components.
|
||||
; - Add a control-character quoting mechanism.
|
||||
|
||||
.constructor initmainargs, 24
|
||||
.import __argc, __argv
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
MAXARGS = 10 ; Maximum number of arguments allowed
|
||||
REM = $8f ; BASIC token-code
|
||||
NAME_LEN = 16 ; Maximum length of command-name
|
||||
|
||||
; Get possible command-line arguments. Goes into the special ONCE segment,
|
||||
; which may be reused after the startup code is run
|
||||
|
||||
.segment "ONCE"
|
||||
|
||||
initmainargs:
|
||||
|
||||
; Assume that the program was loaded, a moment ago, by the traditional LOAD
|
||||
; statement. Save the "most-recent filename" as argument #0.
|
||||
|
||||
lda #0 ; The terminating NUL character
|
||||
ldy FNAM_LEN
|
||||
cpy #NAME_LEN + 1
|
||||
bcc L1
|
||||
ldy #NAME_LEN ; Limit the length
|
||||
bne L1 ; Branch always
|
||||
L0: lda (FNAM),y
|
||||
L1: sta name,y
|
||||
dey
|
||||
bpl L0
|
||||
inc __argc ; argc always is equal to, at least, 1
|
||||
|
||||
; Find the "rem" token.
|
||||
|
||||
ldx #0
|
||||
L2: lda BASIC_BUF,x
|
||||
beq done ; No "rem," no args.
|
||||
inx
|
||||
cmp #REM
|
||||
bne L2
|
||||
ldy #1 * 2
|
||||
|
||||
; Find the next argument
|
||||
|
||||
next: lda BASIC_BUF,x
|
||||
beq done ; End of line reached
|
||||
inx
|
||||
cmp #' ' ; Skip leading spaces
|
||||
beq next
|
||||
|
||||
; Found start of next argument. We've incremented the pointer in X already, so
|
||||
; it points to the second character of the argument. This is useful since we
|
||||
; will check now for a quoted argument, in which case we will have to skip this
|
||||
; first character.
|
||||
|
||||
found: cmp #'"' ; Is the argument quoted?
|
||||
beq setterm ; Jump if so
|
||||
dex ; Reset pointer to first argument character
|
||||
lda #' ' ; A space ends the argument
|
||||
setterm:sta term ; Set end of argument marker
|
||||
|
||||
; Now store a pointer to the argument into the next slot. Since the BASIC
|
||||
; input buffer is located at the start of a RAM page, no calculations are
|
||||
; necessary.
|
||||
|
||||
txa ; Get low byte
|
||||
sta argv,y ; argv[y]= &arg
|
||||
iny
|
||||
lda #>BASIC_BUF
|
||||
sta argv,y
|
||||
iny
|
||||
inc __argc ; Found another arg
|
||||
|
||||
; Search for the end of the argument
|
||||
|
||||
argloop:lda BASIC_BUF,x
|
||||
beq done
|
||||
inx
|
||||
cmp term
|
||||
bne argloop
|
||||
|
||||
; We've found the end of the argument. X points one character behind it, and
|
||||
; A contains the terminating character. To make the argument a valid C string,
|
||||
; replace the terminating character by a zero.
|
||||
|
||||
lda #0
|
||||
sta BASIC_BUF-1,x
|
||||
|
||||
; Check if the maximum number of command line arguments is reached. If not,
|
||||
; parse the next one.
|
||||
|
||||
lda __argc ; Get low byte of argument count
|
||||
cmp #MAXARGS ; Maximum number of arguments reached?
|
||||
bcc next ; Parse next one if not
|
||||
|
||||
; (The last vector in argv[] already is NULL.)
|
||||
|
||||
done: lda #<argv
|
||||
ldx #>argv
|
||||
sta __argv
|
||||
stx __argv + 1
|
||||
rts
|
||||
|
||||
.segment "INIT"
|
||||
|
||||
term: .res 1
|
||||
name: .res NAME_LEN + 1
|
||||
|
||||
.data
|
||||
|
||||
; char* argv[MAXARGS+1]={name};
|
||||
argv: .addr name
|
||||
.res MAXARGS * 2
|
||||
23
libsrc/cx16/revers.s
Normal file
23
libsrc/cx16/revers.s
Normal file
@@ -0,0 +1,23 @@
|
||||
;
|
||||
; 2019-09-16, Greg King
|
||||
;
|
||||
; unsigned char __fastcall__ revers (unsigned char onoff);
|
||||
;
|
||||
|
||||
.export _revers
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
.proc _revers
|
||||
ldy #$00 ; Assume revers off
|
||||
tax ; Test on/off
|
||||
beq :+ ; Jump if off
|
||||
ldy #$80 ; Load "on" value
|
||||
ldx #>$0000 ; Zero high byte of result
|
||||
: lda RVS ; Load old value
|
||||
sty RVS ; Set new value
|
||||
clc
|
||||
rol a ; Convert bit-mask into boolean
|
||||
rol a
|
||||
rts
|
||||
.endproc
|
||||
32
libsrc/cx16/set_tv.s
Normal file
32
libsrc/cx16/set_tv.s
Normal file
@@ -0,0 +1,32 @@
|
||||
;
|
||||
; 2019-09-20, Greg King
|
||||
;
|
||||
; void __fastcall__ set_tv (unsigned char);
|
||||
; /* Set the video mode the machine will use. */
|
||||
;
|
||||
|
||||
.export _set_tv
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
.proc _set_tv
|
||||
php
|
||||
pha
|
||||
sei ; Don't let interrupts interfere
|
||||
|
||||
; Point to the video output register.
|
||||
|
||||
stz VERA::CTRL ; Use port 0
|
||||
lda #<VERA::COMPOSER::VIDEO
|
||||
ldx #>VERA::COMPOSER::VIDEO
|
||||
ldy #^VERA::COMPOSER::VIDEO
|
||||
sta VERA::ADDR
|
||||
stx VERA::ADDR+1
|
||||
sty VERA::ADDR+2
|
||||
|
||||
pla
|
||||
sta VERA::DATA0
|
||||
plp ; Re-enable interrupts
|
||||
rts
|
||||
.endproc
|
||||
6
libsrc/cx16/status.s
Normal file
6
libsrc/cx16/status.s
Normal file
@@ -0,0 +1,6 @@
|
||||
;
|
||||
; 2012-09-30, Oliver Schmidt
|
||||
; 2019-09-08, Greg King
|
||||
;
|
||||
|
||||
.exportzp ST := $90 ; IEC status byte
|
||||
37
libsrc/cx16/sysuname.s
Normal file
37
libsrc/cx16/sysuname.s
Normal file
@@ -0,0 +1,37 @@
|
||||
;
|
||||
; 2003-08-12, Ullrich von Bassewitz
|
||||
; 2019-09-08, Greg King
|
||||
;
|
||||
; unsigned char __fastcall__ _sysuname (struct utsname* buf);
|
||||
;
|
||||
|
||||
.export __sysuname, utsdata
|
||||
|
||||
.import utscopy
|
||||
|
||||
__sysuname := utscopy
|
||||
|
||||
;--------------------------------------------------------------------------
|
||||
; Data. We define a fixed utsname struct here, and just copy it.
|
||||
|
||||
.rodata
|
||||
|
||||
utsdata:
|
||||
; sysname
|
||||
.asciiz "cc65"
|
||||
|
||||
; nodename
|
||||
.asciiz ""
|
||||
|
||||
; release
|
||||
.byte ((.VERSION >> 8) & $0F) + '0'
|
||||
.byte '.'
|
||||
.byte ((.VERSION >> 4) & $0F) + '0'
|
||||
.byte $00
|
||||
|
||||
; version
|
||||
.byte (.VERSION & $0F) + '0'
|
||||
.byte $00
|
||||
|
||||
; machine
|
||||
.asciiz "Commander X16"
|
||||
30
libsrc/cx16/videomode.s
Normal file
30
libsrc/cx16/videomode.s
Normal file
@@ -0,0 +1,30 @@
|
||||
;
|
||||
; 2009-09-07, Ullrich von Bassewitz
|
||||
; 2019-09-23, Greg King
|
||||
;
|
||||
; unsigned __fastcall__ videomode (unsigned Mode);
|
||||
; /* Set the video mode, return the old mode. */
|
||||
;
|
||||
|
||||
.export _videomode
|
||||
.import SWAPPER
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
|
||||
.proc _videomode
|
||||
cmp LLEN ; Do we have this mode already?
|
||||
beq @L9
|
||||
|
||||
lda LLEN ; Get current mode ...
|
||||
pha ; ... and save it
|
||||
|
||||
jsr SWAPPER ; Toggle the mode
|
||||
|
||||
pla ; Get old mode into A
|
||||
|
||||
; Done, old mode is in .A
|
||||
|
||||
@L9: ldx #>$0000 ; Clear high byte
|
||||
rts
|
||||
.endproc
|
||||
17
libsrc/cx16/waitvsync.s
Normal file
17
libsrc/cx16/waitvsync.s
Normal file
@@ -0,0 +1,17 @@
|
||||
;
|
||||
; 2019-09-26, Greg King
|
||||
;
|
||||
; void waitvsync (void);
|
||||
;
|
||||
; VERA's vertical sync. causes IRQs which increment the jiffy clock.
|
||||
;
|
||||
|
||||
.export _waitvsync
|
||||
|
||||
.include "cx16.inc"
|
||||
|
||||
_waitvsync:
|
||||
lda TIME + 2
|
||||
: cmp TIME + 2
|
||||
beq :- ; Wait for next jiffy
|
||||
rts
|
||||
Reference in New Issue
Block a user