New target c16
git-svn-id: svn://svn.cc65.org/cc65/trunk@1563 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
31
libsrc/c16/Makefile
Normal file
31
libsrc/c16/Makefile
Normal file
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# makefile for CC65 runtime library (C16)
|
||||
#
|
||||
|
||||
.SUFFIXES: .o .s .c
|
||||
|
||||
%.o: %.c
|
||||
@$(CC) $(CFLAGS) $<
|
||||
@$(AS) -o $@ $(AFLAGS) $(*).s
|
||||
|
||||
%.o: %.s
|
||||
@$(AS) -g -o $@ $(AFLAGS) $<
|
||||
|
||||
OBJS = _scrsize.o \
|
||||
break.o \
|
||||
cgetc.o \
|
||||
clrscr.o \
|
||||
color.o \
|
||||
conio.o \
|
||||
cputc.o \
|
||||
crt0.o \
|
||||
kbhit.o \
|
||||
kernal.o \
|
||||
randomize.o \
|
||||
readjoy.o
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
clean:
|
||||
@rm -f $(OBJS)
|
||||
|
||||
25
libsrc/c16/_scrsize.s
Normal file
25
libsrc/c16/_scrsize.s
Normal file
@@ -0,0 +1,25 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 26.10.2000
|
||||
;
|
||||
; Screen size variables
|
||||
;
|
||||
|
||||
.export xsize, ysize
|
||||
.import SCREEN
|
||||
.constructor initscrsize
|
||||
|
||||
|
||||
.code
|
||||
|
||||
initscrsize:
|
||||
jsr SCREEN
|
||||
stx xsize
|
||||
sty ysize
|
||||
rts
|
||||
|
||||
.bss
|
||||
|
||||
xsize: .res 1
|
||||
ysize: .res 1
|
||||
|
||||
|
||||
108
libsrc/c16/break.s
Normal file
108
libsrc/c16/break.s
Normal file
@@ -0,0 +1,108 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 27.09.1998
|
||||
;
|
||||
; void 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 "../plus4/plus4.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
|
||||
|
||||
|
||||
88
libsrc/c16/cgetc.s
Normal file
88
libsrc/c16/cgetc.s
Normal file
@@ -0,0 +1,88 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 06.08.1998
|
||||
;
|
||||
; char cgetc (void);
|
||||
;
|
||||
|
||||
.export _cgetc
|
||||
.import cursor
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
|
||||
; --------------------------------------------------------------------------
|
||||
|
||||
_cgetc: lda KEY_COUNT ; Get number of characters
|
||||
ora FKEY_COUNT ; Or with number of function key chars
|
||||
bne L2 ; Jump if there are already chars waiting
|
||||
|
||||
; Switch on the cursor if needed
|
||||
|
||||
ldy CURS_X
|
||||
lda (CRAM_PTR),y ; Get current char
|
||||
pha ; And save it
|
||||
lda CHARCOLOR
|
||||
sta (CRAM_PTR),y
|
||||
|
||||
lda cursor
|
||||
beq L1 ; Jump if no cursor
|
||||
tya
|
||||
clc
|
||||
adc SCREEN_PTR
|
||||
sta TED_CURSLO
|
||||
lda SCREEN_PTR+1
|
||||
adc #$00
|
||||
sbc #$0B ; + carry = $C00 (screen address)
|
||||
sta TED_CURSHI
|
||||
|
||||
L1: lda KEY_COUNT
|
||||
ora FKEY_COUNT
|
||||
beq L1
|
||||
pla
|
||||
sta (CRAM_PTR),y
|
||||
lda #$ff
|
||||
sta TED_CURSLO ; Cursor off
|
||||
sta TED_CURSHI
|
||||
|
||||
L2: jsr KBDREAD ; Read char and return in A
|
||||
ldx #0
|
||||
rts
|
||||
|
||||
; --------------------------------------------------------------------------
|
||||
; Make the function keys return function key codes instead of the current
|
||||
; strings so the program will see and may handle them.
|
||||
; Undo this change when the program ends
|
||||
|
||||
.constructor initkbd
|
||||
.destructor donekbd
|
||||
|
||||
.proc initkbd
|
||||
|
||||
ldy #15
|
||||
@L1: lda fnkeys,y
|
||||
sta FKEY_SPACE,y
|
||||
dey
|
||||
bpl @L1
|
||||
rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
.proc donekbd
|
||||
|
||||
ldx #$39 ; Copy the original function keys
|
||||
@L1: lda FKEY_ORIG,x
|
||||
sta FKEY_SPACE,x
|
||||
dex
|
||||
bpl @L1
|
||||
rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
; Function key table, readonly
|
||||
|
||||
.rodata
|
||||
fnkeys: .byte $01, $01, $01, $01, $01, $01, $01, $01
|
||||
.byte 133, 137, 134, 138, 135, 139, 136, 140
|
||||
|
||||
15
libsrc/c16/clrscr.s
Normal file
15
libsrc/c16/clrscr.s
Normal file
@@ -0,0 +1,15 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 06.08.1998
|
||||
;
|
||||
; void clrscr (void);
|
||||
;
|
||||
|
||||
.export _clrscr
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
_clrscr = CLRSCR
|
||||
|
||||
|
||||
|
||||
|
||||
33
libsrc/c16/color.s
Normal file
33
libsrc/c16/color.s
Normal file
@@ -0,0 +1,33 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 06.08.1998
|
||||
;
|
||||
; unsigned char __fastcall__ textcolor (unsigned char color);
|
||||
; unsigned char __fastcall__ bgcolor (unsigned char color);
|
||||
; unsigned char __fastcall__ bordercolor (unsigned char color);
|
||||
;
|
||||
|
||||
.export _textcolor, _bgcolor, _bordercolor
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
_textcolor:
|
||||
ldx CHARCOLOR ; get old value
|
||||
sta CHARCOLOR ; set new value
|
||||
txa
|
||||
rts
|
||||
|
||||
|
||||
_bgcolor:
|
||||
ldx TED_BGCOLOR ; get old value
|
||||
sta TED_BGCOLOR ; set new value
|
||||
txa
|
||||
rts
|
||||
|
||||
|
||||
_bordercolor:
|
||||
ldx TED_BORDERCOLOR ; get old value
|
||||
sta TED_BORDERCOLOR ; set new value
|
||||
txa
|
||||
rts
|
||||
|
||||
|
||||
10
libsrc/c16/conio.s
Normal file
10
libsrc/c16/conio.s
Normal file
@@ -0,0 +1,10 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 06.08.1998
|
||||
;
|
||||
; Low level stuff for screen output/console input
|
||||
;
|
||||
|
||||
.exportzp CURS_X, CURS_Y
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
106
libsrc/c16/cputc.s
Normal file
106
libsrc/c16/cputc.s
Normal file
@@ -0,0 +1,106 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 06.08.1998
|
||||
;
|
||||
; void cputcxy (unsigned char x, unsigned char y, char c);
|
||||
; void cputc (char c);
|
||||
;
|
||||
|
||||
.export _cputcxy, _cputc, cputdirect, putchar
|
||||
.export newline, plot
|
||||
.import popa, _gotoxy
|
||||
.import xsize, revers
|
||||
.import PLOT
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
|
||||
_cputcxy:
|
||||
pha ; Save C
|
||||
jsr popa ; Get Y
|
||||
jsr _gotoxy ; Set cursor, drop x
|
||||
pla ; Restore C
|
||||
|
||||
; Plot a character - also used as internal function
|
||||
|
||||
_cputc: cmp #$0A ; CR?
|
||||
bne L1
|
||||
lda #0
|
||||
sta CURS_X
|
||||
beq plot ; Recalculate pointers
|
||||
|
||||
L1: cmp #$0D ; LF?
|
||||
beq newline ; Recalculate pointers
|
||||
|
||||
; Printable char of some sort
|
||||
|
||||
cmp #' '
|
||||
bcc cputdirect ; Other control char
|
||||
tay
|
||||
bmi L10
|
||||
cmp #$60
|
||||
bcc L2
|
||||
and #$DF
|
||||
bne cputdirect ; Branch always
|
||||
L2: and #$3F
|
||||
|
||||
cputdirect:
|
||||
jsr putchar ; Write the character to the screen
|
||||
|
||||
; Advance cursor position
|
||||
|
||||
advance:
|
||||
iny
|
||||
cpy xsize
|
||||
bne L3
|
||||
jsr newline ; new line
|
||||
ldy #0 ; + cr
|
||||
L3: sty CURS_X
|
||||
rts
|
||||
|
||||
newline:
|
||||
clc
|
||||
lda xsize
|
||||
adc SCREEN_PTR
|
||||
sta SCREEN_PTR
|
||||
bcc L4
|
||||
inc SCREEN_PTR+1
|
||||
clc
|
||||
L4: lda xsize
|
||||
adc CRAM_PTR
|
||||
sta CRAM_PTR
|
||||
bcc L5
|
||||
inc CRAM_PTR+1
|
||||
L5: inc CURS_Y
|
||||
rts
|
||||
|
||||
; Handle character if high bit set
|
||||
|
||||
L10: and #$7F
|
||||
cmp #$7E ; PI?
|
||||
bne L11
|
||||
lda #$5E ; Load screen code for PI
|
||||
bne cputdirect
|
||||
L11: ora #$40
|
||||
bne cputdirect
|
||||
|
||||
|
||||
|
||||
; Set cursor position, calculate RAM pointers
|
||||
|
||||
plot: ldy CURS_X
|
||||
ldx CURS_Y
|
||||
clc
|
||||
jmp PLOT ; Set the new cursor
|
||||
|
||||
|
||||
|
||||
; Write one character to the screen without doing anything else, return X
|
||||
; position in Y
|
||||
|
||||
putchar:
|
||||
ora revers ; Set revers bit
|
||||
ldy CURS_X
|
||||
sta (SCREEN_PTR),y ; Set char
|
||||
lda CHARCOLOR
|
||||
sta (CRAM_PTR),y ; Set color
|
||||
rts
|
||||
109
libsrc/c16/crt0.s
Normal file
109
libsrc/c16/crt0.s
Normal file
@@ -0,0 +1,109 @@
|
||||
;
|
||||
; Startup code for cc65 (C16 version)
|
||||
;
|
||||
; This must be the *first* file on the linker command line
|
||||
;
|
||||
; Note: The C16 is actually the Plus/4 with just 16KB of memory. So many
|
||||
; things are similar here, and we even use the plus4.inc include file.
|
||||
;
|
||||
|
||||
.export _exit
|
||||
.import initlib, donelib
|
||||
.import push0, _main, zerobss
|
||||
.import MEMTOP, RESTOR, BSOUT, CLRCH
|
||||
|
||||
.include "zeropage.inc"
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; BASIC header with a SYS call
|
||||
|
||||
.code
|
||||
|
||||
.org $0FFF
|
||||
.word Head ; Load address
|
||||
Head: .word @Next
|
||||
.word 1000 ; Line number
|
||||
.byte $9E,"4109" ; SYS 4109
|
||||
.byte $00 ; End of BASIC line
|
||||
@Next: .word 0 ; BASIC end marker
|
||||
.reloc
|
||||
|
||||
; ------------------------------------------------------------------------
|
||||
; Actual code
|
||||
|
||||
ldx #zpspace-1
|
||||
L1: lda sp,x
|
||||
sta zpsave,x ; save the zero page locations we need
|
||||
dex
|
||||
bpl L1
|
||||
|
||||
; Close open files
|
||||
|
||||
jsr CLRCH
|
||||
|
||||
; Switch to second charset
|
||||
|
||||
lda #14
|
||||
jsr BSOUT
|
||||
|
||||
; Clear the BSS data
|
||||
|
||||
jsr zerobss
|
||||
|
||||
; Save system stuff and setup the stack
|
||||
|
||||
tsx
|
||||
stx spsave ; save system stk ptr
|
||||
|
||||
sec
|
||||
jsr MEMTOP ; Get top memory
|
||||
cpy #$80 ; We can only use the low 32K :-(
|
||||
bcc MemOk
|
||||
ldy #$80
|
||||
ldx #$00
|
||||
MemOk: stx sp
|
||||
sty sp+1 ; set argument stack ptr
|
||||
|
||||
; Call module constructors
|
||||
|
||||
jsr initlib
|
||||
|
||||
; Pass an empty command line
|
||||
|
||||
jsr push0 ; argc
|
||||
jsr push0 ; argv
|
||||
|
||||
ldy #4 ; Argument size
|
||||
jsr _main ; call the users code
|
||||
|
||||
; Call module destructors. This is also the _exit entry.
|
||||
|
||||
_exit: jsr donelib ; Run module destructors
|
||||
|
||||
; Restore system stuff
|
||||
|
||||
ldx spsave
|
||||
txs
|
||||
|
||||
; Copy back the zero page stuff
|
||||
|
||||
ldx #zpspace-1
|
||||
L2: lda zpsave,x
|
||||
sta sp,x
|
||||
dex
|
||||
bpl L2
|
||||
|
||||
; Reset changed vectors
|
||||
|
||||
jmp RESTOR
|
||||
|
||||
|
||||
.data
|
||||
zpsave: .res zpspace
|
||||
|
||||
.bss
|
||||
spsave: .res 1
|
||||
|
||||
|
||||
21
libsrc/c16/kbhit.s
Normal file
21
libsrc/c16/kbhit.s
Normal file
@@ -0,0 +1,21 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 06.08.1998
|
||||
;
|
||||
; int kbhit (void);
|
||||
;
|
||||
|
||||
.export _kbhit
|
||||
.import return0, return1
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
_kbhit:
|
||||
lda KEY_COUNT ; Get number of characters
|
||||
ora FKEY_COUNT ; Or with number of chars from function keys
|
||||
bne L1
|
||||
jmp return0
|
||||
L1: jmp return1
|
||||
|
||||
|
||||
|
||||
|
||||
90
libsrc/c16/kernal.s
Normal file
90
libsrc/c16/kernal.s
Normal file
@@ -0,0 +1,90 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 19.11.2002
|
||||
;
|
||||
; C16 kernal functions
|
||||
;
|
||||
|
||||
.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 BSOUT
|
||||
.export LOAD
|
||||
.export SAVE
|
||||
.export SETTIM
|
||||
.export RDTIM
|
||||
.export STOP
|
||||
.export GETIN
|
||||
.export CLALL
|
||||
.export UDTIM
|
||||
.export SCREEN
|
||||
.export PLOT
|
||||
.export IOBASE
|
||||
|
||||
|
||||
;-----------------------------------------------------------------------------
|
||||
; All functions are available in the kernal jump table
|
||||
|
||||
CINT = $FF81
|
||||
IOINIT = $FF84
|
||||
RAMTAS = $FF87
|
||||
RESTOR = $FF8A
|
||||
VECTOR = $FF8D
|
||||
SETMSG = $FF90
|
||||
SECOND = $FF93
|
||||
TKSA = $FF96
|
||||
MEMTOP = $FF99
|
||||
MEMBOT = $FF9C
|
||||
SCNKEY = $FF9F
|
||||
SETTMO = $FFA2
|
||||
ACPTR = $FFA5
|
||||
CIOUT = $FFA8
|
||||
UNTLK = $FFAB
|
||||
UNLSN = $FFAE
|
||||
LISTEN = $FFB1
|
||||
TALK = $FFB4
|
||||
READST = $FFB7
|
||||
SETLFS = $FFBA
|
||||
SETNAM = $FFBD
|
||||
OPEN = $FFC0
|
||||
CLOSE = $FFC3
|
||||
CHKIN = $FFC6
|
||||
CKOUT = $FFC9
|
||||
CLRCH = $FFCC
|
||||
BASIN = $FFCF
|
||||
BSOUT = $FFD2
|
||||
LOAD = $FFD5
|
||||
SAVE = $FFD8
|
||||
SETTIM = $FFDB
|
||||
RDTIM = $FFDE
|
||||
STOP = $FFE1
|
||||
GETIN = $FFE4
|
||||
CLALL = $FFE7
|
||||
UDTIM = $FFEA
|
||||
SCREEN = $FFED
|
||||
PLOT = $FFF0
|
||||
IOBASE = $FFF3
|
||||
|
||||
17
libsrc/c16/randomize.s
Normal file
17
libsrc/c16/randomize.s
Normal file
@@ -0,0 +1,17 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 05.11.2002
|
||||
;
|
||||
; void _randomize (void);
|
||||
; /* Initialize the random number generator */
|
||||
;
|
||||
|
||||
.export __randomize
|
||||
.import _srand
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
__randomize:
|
||||
ldx TED_VLINELO ; Use TED rasterline as high byte
|
||||
lda TIME ; Use 60HZ clock as low byte
|
||||
jmp _srand ; Initialize generator
|
||||
|
||||
29
libsrc/c16/readjoy.s
Normal file
29
libsrc/c16/readjoy.s
Normal file
@@ -0,0 +1,29 @@
|
||||
;
|
||||
; Ullrich von Bassewitz, 23.09.1998
|
||||
;
|
||||
; unsigned readjoy (unsigned char joy);
|
||||
;
|
||||
|
||||
.export _readjoy
|
||||
|
||||
.include "../plus4/plus4.inc"
|
||||
|
||||
|
||||
.proc _readjoy
|
||||
|
||||
ldy #$FA ; Load index for joystick #1
|
||||
tax ; Test joystick number
|
||||
beq L1
|
||||
ldy #$FB ; Load index for joystick #2
|
||||
L1: sei
|
||||
sty TED_KBD
|
||||
lda TED_KBD
|
||||
cli
|
||||
ldx #$00 ; Clear high byte
|
||||
and #$1F
|
||||
eor #$1F
|
||||
rts
|
||||
|
||||
.endproc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user