This commit was generated by cvs2svn to compensate for changes in r2,

which included commits to RCS files with non-trunk default branches.


git-svn-id: svn://svn.cc65.org/cc65/trunk@3 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2000-05-28 13:40:48 +00:00
parent 579491e8a4
commit 53dd513176
847 changed files with 91345 additions and 0 deletions

28
libsrc/plus4/Makefile Normal file
View File

@@ -0,0 +1,28 @@
#
# makefile for CC65 runtime library
#
.SUFFIXES: .o .s .c
%.o: %.c
@echo $<
@$(CC) $(CFLAGS) $<
@$(AS) -o $@ $(AFLAGS) $(*).s
%.o: %.s
@echo $<
@$(AS) -g -o $@ $(AFLAGS) $<
C_OBJS =
S_OBJS = crt0.o kbhit.o conio.o clrscr.o cputc.o cgetc.o\
color.o readjoy.o break.o
all: $(C_OBJS) $(S_OBJS)
clean:
@rm -f $(C_OBJS:.c=.s)
@rm -f $(C_OBJS)
@rm -f $(S_OBJS)
@rm -f crt0.o

108
libsrc/plus4/break.s Normal file
View 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
.export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc
.import _atexit
.include "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
lda #<_reset_brk
ldx #>_reset_brk
jsr _atexit ; Install an exit handler
L1: lda #<brk_handler ; Set the break vector to our routine
sta BRKVec
lda #>brk_handler
sta BRKVec+1
rts
.endproc
; Reset the break vector
.proc _reset_brk
lda oldvec
sta BRKVec
lda oldvec+1
sta BRKVec+1
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

48
libsrc/plus4/cgetc.s Normal file
View File

@@ -0,0 +1,48 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; char cgetc (void);
;
.export _cgetc
.import cursor
.include "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

15
libsrc/plus4/clrscr.s Normal file
View File

@@ -0,0 +1,15 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; void clrscr (void);
;
.export _clrscr
.include "plus4.inc"
_clrscr = CLRSCR

33
libsrc/plus4/color.s Normal file
View 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.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

41
libsrc/plus4/conio.s Normal file
View File

@@ -0,0 +1,41 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; Low level stuff for screen output/console input
;
.export initconio, doneconio
.exportzp CURS_X, CURS_Y
.import xsize, ysize
.include "plus4.inc"
.include "../cbm/cbm.inc"
.code
initconio:
jsr SCREEN
stx xsize
sty ysize
ldy #15
L1: lda fnkeys,y
sta FKEY_SPACE,y
dey
bpl L1
rts
doneconio:
ldx #$39 ; Copy the original function keys
L2: lda FKEY_ORIG,x
sta FKEY_SPACE,x
dex
bpl L2
rts
; Function key table, readonly
.rodata
fnkeys: .byte $01, $01, $01, $01, $01, $01, $01, $01
.byte 133, 137, 134, 138, 135, 139, 136, 140

105
libsrc/plus4/cputc.s Normal file
View File

@@ -0,0 +1,105 @@
;
; 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 advance, newline, plot
.import popa, _gotoxy
.import xsize, revers
.include "plus4.inc"
.include "../cbm/cbm.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 #$0D ; CR?
bne L1
lda #0
sta CURS_X
beq plot ; Recalculate pointers
L1: cmp #$0A ; LF?
bne L2
ldy CURS_Y
iny
bne newline ; Recalculate pointers
; Printable char of some sort
L2: cmp #' '
bcc cputdirect ; Other control char
tay
bmi L10
cmp #$60
bcc L3
and #$DF
bne cputdirect ; Branch always
L3: and #$3F
cputdirect:
jsr putchar ; Write the character to the screen
; Advance cursor position
advance:
iny
cpy xsize
bne L9
ldy #0 ; new line
newline:
clc
lda xsize
adc SCREEN_PTR
sta SCREEN_PTR
bcc L4
inc SCREEN_PTR+1
L4: clc
lda xsize
adc CRAM_PTR
sta CRAM_PTR
bcc L5
inc CRAM_PTR+1
L5: inc CURS_Y
L9: sty CURS_X
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

129
libsrc/plus4/crt0.s Normal file
View File

@@ -0,0 +1,129 @@
;
; Startup code for cc65 (Plus/4 version)
;
; This must be the *first* file on the linker command line
;
.export _exit
.import __hinit, push0, doatexit, _main
.import initconio, doneconio, zerobss
.include "plus4.inc"
.include "../cbm/cbm.inc"
; ------------------------------------------------------------------------
; Define and export the ZP variables for the C64 runtime
.exportzp sp, sreg, regsave
.exportzp ptr1, ptr2, ptr3, ptr4
.exportzp tmp1, tmp2, tmp3, tmp4
.exportzp regbank, zpspace
sp = $02 ; stack pointer
sreg = $04 ; secondary register/high 16 bit for longs
regsave = $06 ; slot to save/restore (E)AX into
ptr1 = $0A ;
ptr2 = $0C
ptr3 = $0E
ptr4 = $10
tmp1 = $12
tmp2 = $13
tmp3 = $14
tmp4 = $15
regbank = $16 ; 6 byte register bank
zpspace = $1A ; Zero page space allocated
; ------------------------------------------------------------------------
; BASIC header with a SYS call
.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
ldy #zpspace-1
L1: lda sp,y
sta zpsave,y ; save the zero page locations we need
dey
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
; Initialize the heap
jsr __hinit
; Initialize conio stuff
jsr initconio
; Pass an empty command line
jsr push0 ; argc
jsr push0 ; argv
ldy #4 ; Argument size
jsr _main ; call the users code
; fall thru to exit...
_exit: jsr doatexit ; call exit functions
ldx spsave
txs
; Reset the conio stuff
jsr doneconio
; Copy back the zero page stuff
ldy #zpspace-1
L2: lda zpsave,y
sta sp,y
dey
bpl L2
; Reset changed vectors
jmp RESTOR
.data
zpsave: .res zpspace
.bss
spsave: .res 1

21
libsrc/plus4/kbhit.s Normal file
View File

@@ -0,0 +1,21 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; int kbhit (void);
;
.export _kbhit
.import return0, return1
.include "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

66
libsrc/plus4/plus4.inc Normal file
View File

@@ -0,0 +1,66 @@
;
; Plus/4 generic definitions.
;
; ---------------------------------------------------------------------------
; Zero page, Commodore stuff
ST = $90 ; IEC status byte
FNAM_LEN = $AB ; Length of filename
SECADR = $AD ; Secondary address
DEVNUM = $AE ; Device number
KEY_COUNT = $EF ; Number of keys in input buffer
CURS_X = $CA ; Cursor column
CURS_Y = $CD ; Cursor row
SCREEN_PTR = $C8 ; Pointer to current char in text screen
CRAM_PTR = $EA ; Pointer to current char in color RAM
CHARCOLOR = $53B
FKEY_COUNT = $55D ; Characters for function key
FKEY_SPACE = $55F ; Function key definitions
FKEY_ORIG = $F3D2 ; Original definitions
; ---------------------------------------------------------------------------
; Kernal routines
; Direct entries
CLRSCR = $D88B
KBDREAD = $D8C1
; ---------------------------------------------------------------------------
; Vector and other locations
IRQVec = $0314
BRKVec = $0316
NMIVec = $0318
; ---------------------------------------------------------------------------
; I/O
TED_T1LO = $FF00
TED_T1HI = $FF01
TED_T2LO = $FF02
TED_T2HI = $FF03
TED_T3LO = $FF04
TED_T4HI = $FF05
TED_KBD = $FF08
TED_CURSHI = $FF0C
TED_CURSLO = $FF0D
TED_V1FRQLO = $FF0E
TED_V2FRQLO = $FF0F
TED_V2FRQHI = $FF10
TED_BGCOLOR = $FF15
TED_COLOR1 = $FF16
TED_COLOR2 = $FF17
TED_COLOR3 = $FF18
TED_BORDERCOLOR = $FF19
TED_VLINEHI = $FF1C
TED_VLINELO = $FF1D
TED_HPOS = $FF1E
TED_ROMSEL = $FF3E
TED_RAMSEL = $FF3F

29
libsrc/plus4/readjoy.s Normal file
View File

@@ -0,0 +1,29 @@
;
; Ullrich von Bassewitz, 23.09.1998
;
; unsigned readjoy (unsigned char joy);
;
.export _readjoy
.include "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