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/c128/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 conio.o kbhit.o clrscr.o cgetc.o readjoy.o\
color.o cputc.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

127
libsrc/c128/break.s Normal file
View File

@@ -0,0 +1,127 @@
;
; 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
.importzp ptr1
.include "c128.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
; Where will we put the break stub?
stub_addr = $0E00 ; BASIC sprite area
; 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 L2 ; Jump if we installed the handler already
lda BRKVec
sta oldvec
lda BRKVec+1
sta oldvec+1 ; Save the old vector
ldy #stub_size-1 ; Copy our stub into the low mem area
L1: lda brk_stub,y
sta stub_addr,y
dey
bpl L1
lda #<_reset_brk
ldx #>_reset_brk
jsr _atexit ; Install an exit handler
L2: lda #<stub_addr ; Set the break vector to our stub
sta BRKVec
lda #>stub_addr
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
brk_stub:
.org stub_addr
pla ; Get original MMU value
sta MMU_CR ; Re-enable our config
jmp brk_handler ; Jump to the user handler
.reloc
stub_size = * - brk_stub

185
libsrc/c128/c128.inc Normal file
View File

@@ -0,0 +1,185 @@
;
; C64 generic definitions. Stolen from Elite128
;
; ---------------------------------------------------------------------------
; Zero page, Commodore stuff
ST = $90 ; IEC status byte
FNAM_LEN = $B7 ; Length of filename
SECADR = $B9 ; Secondary address
DEVNUM = $BA ; Device number
FNAM_BANK = $C7 ; Bank for filename
FNAM_LO = $BB ; Address of filename
FNAM_HI = $BC
KEY_COUNT = $D0 ; Number of keys in input buffer
MODE = $D7 ; 40/80 column mode flag
CURS_X = $EC ; Cursor column
CURS_Y = $EB ; Cursor row
SCREEN_PTR = $E0 ; Pointer to current char in text screen
CRAM_PTR = $E2 ; Pointer to current char in color RAM
CHARCOLOR = $F1
FKEY_COUNT = $D1 ; Characters for function key
FKEY_LEN = $1000 ; Function key lengths
FKEY_TEXT = $100A ; Function key texts
; ---------------------------------------------------------------------------
; Kernal routines
; Direct entries
CURS_ON = $CD6F
CURS_OFF = $CD9F
CLRSCR = $C142
KBDREAD = $C006
; ---------------------------------------------------------------------------
; Vectors
IRQVec = $0314
BRKVec = $0316
NMIVec = $0318
KeyStoreVec = $033C
; ---------------------------------------------------------------------------
; I/O: VIC
VIC = $D000
VIC_SPR0_X = $D000
VIC_SPR0_Y = $D001
VIC_SPR1_X = $D002
VIC_SPR1_Y = $D003
VIC_SPR2_X = $D004
VIC_SPR2_Y = $D005
VIC_SPR3_X = $D006
VIC_SPR3_Y = $D007
VIC_SPR4_X = $D008
VIC_SPR4_Y = $D009
VIC_SPR5_X = $D00A
VIC_SPR5_Y = $D00B
VIC_SPR6_X = $D00C
VIC_SPR6_Y = $D00D
VIC_SPR7_X = $D00E
VIC_SPR7_Y = $D00F
VIC_SPR_HI_X = $D010
VIC_SPR_ENA = $D015
VIC_SPR_EXP_X = $D017
VIC_SPR_EXP_Y = $D01D
VIC_SPR_MCOLOR = $D01C
VIC_SPR_BG_PRIO = $D01B
VIC_SPR_MCOLOR0 = $D025
VIC_SPR_MCOLOR1 = $D026
VIC_SPR0_COLOR = $D027
VIC_SPR1_COLOR = $D028
VIC_SPR2_COLOR = $D029
VIC_SPR3_COLOR = $D02A
VIC_SPR4_COLOR = $D02B
VIC_SPR5_COLOR = $D02C
VIC_SPR6_COLOR = $D02D
VIC_SPR7_COLOR = $D02E
VIC_CTRL1 = $D011
VIC_CTRL2 = $D016
VIC_HLINE = $D012
VIC_VIDEO_ADR = $D018
VIC_IRR = $D019 ; Interrupt request register
VIC_IMR = $D01A ; Interrupt mask register
VIC_BORDERCOLOR = $D020
VIC_BG_COLOR0 = $D021
VIC_BG_COLOR1 = $D022
VIC_BG_COLOR2 = $D023
VIC_BG_COLOR3 = $D024
; 128 stuff:
VIC_KBD_128 = $D02F ; Extended kbd bits (visible in 64 mode)
VIC_CLK_128 = $D030 ; Clock rate register (visible in 64 mode)
; ---------------------------------------------------------------------------
; I/O: SID
SID = $D400
SID_S1Lo = $D400
SID_S1Hi = $D401
SID_PB1Lo = $D402
SID_PB1Hi = $D403
SID_Ctl1 = $D404
SID_AD1 = $D405
SID_SUR1 = $D406
SID_S2Lo = $D407
SID_S2Hi = $D408
SID_PB2Lo = $D409
SID_PB2Hi = $D40A
SID_Ctl2 = $D40B
SID_AD2 = $D40C
SID_SUR2 = $D40D
SID_S3Lo = $D40E
SID_S3Hi = $D40F
SID_PB3Lo = $D410
SID_PB3Hi = $D411
SID_Ctl3 = $D412
SID_AD3 = $D413
SID_SUR3 = $D414
SID_FltLo = $D415
SID_FltHi = $D416
SID_FltCtl = $D417
SID_Amp = $D418
SID_ADConv1 = $D419
SID_ADConv2 = $D41A
SID_Noise = $D41B
SID_Read3 = $D41C
; ---------------------------------------------------------------------------
; I/O: VDC (128 only)
VDC_INDEX = $D600
VDC_DATA = $D601
; ---------------------------------------------------------------------------
; I/O: CIAs
CIA1 = $DC00
CIA1_PRA = $DC00
CIA1_PRB = $DC01
CIA1_DDRA = $DC02
CIA1_DDRB = $DC03
CIA1_ICR = $DC0D
CIA1_CRA = $DC0E
CIA1_CRB = $DC0F
CIA2 = $DD00
CIA2_PRA = $DD00
CIA2_PRB = $DD01
CIA2_DDRA = $DD02
CIA2_DDRB = $DD03
CIA2_ICR = $DD0D
CIA2_CRA = $DD0E
CIA2_CRB = $DD0F
; ---------------------------------------------------------------------------
; I/O: MMU
MMU_CR = $FF00
; ---------------------------------------------------------------------------
; Super CPU
SCPU_VIC_Bank1 = $D075
SCPU_Slow = $D07A
SCPU_Fast = $D07B
SCPU_EnableRegs = $D07E
SCPU_DisableRegs= $D07F
SCPU_Detect = $D0BC

31
libsrc/c128/cgetc.s Normal file
View File

@@ -0,0 +1,31 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; char cgetc (void);
;
.export _cgetc
.import cursor
.include "c128.inc"
_cgetc: lda KEY_COUNT ; Get number of characters
bne L2 ; Jump if there are already chars waiting
; Switch on the cursor if needed
lda cursor
beq L1
jsr CURS_ON
jmp L2
L1: lda #$01
jsr CURS_OFF
L2: lda KEY_COUNT ; Check characters again
beq L2
jsr CURS_OFF ; Switch cursor off, if characters available
jsr KBDREAD ; Read char and return in A
ldx #0
rts

14
libsrc/c128/clrscr.s Normal file
View File

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

33
libsrc/c128/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 "c128.inc"
_textcolor:
ldx CHARCOLOR ; get old value
sta CHARCOLOR ; set new value
txa
rts
_bgcolor:
ldx VIC_BG_COLOR0 ; get old value
sta VIC_BG_COLOR0 ; set new value
txa
rts
_bordercolor:
ldx VIC_BG_COLOR0 ; get old value
sta VIC_BORDERCOLOR ; set new value
txa
rts

50
libsrc/c128/conio.s Normal file
View File

@@ -0,0 +1,50 @@
;
; 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 "c128.inc"
.include "../cbm/cbm.inc"
.bss
keyvec: .res 2
.code
initconio:
jsr SCREEN
inx
stx xsize
iny
sty ysize
; Save the old vector
lda KeyStoreVec
sta keyvec
lda KeyStoreVec+1
sta keyvec+1
; Set the new vector. I can only hope that this works for other C128
; versions...
lda #<$C6B7
ldx #>$C6B7
SetVec: sei
sta KeyStoreVec
stx KeyStoreVec+1
cli
rts
doneconio:
lda keyvec
ldx keyvec+1
bne SetVec

105
libsrc/c128/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 "c128.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

141
libsrc/c128/crt0.s Normal file
View File

@@ -0,0 +1,141 @@
;
; Startup code for cc65 (C128 version)
;
; This must be the *first* file on the linker command line
;
.export _exit
.import __hinit, initconio, doneconio, zerobss
.import push0, doatexit, _main
.include "c128.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 $1BFF
.word Head ; Load address
Head: .word @Next
.word 1000 ; Line number
.byte $9E,"7181" ; SYS 7181
.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
; Get the current MMU setting and save it. Set new memory config.
lda MMU_CR ; Get current memory configuration...
pha ; ...and save it for later
lda #$0E ; Bank0 with kernal ROM
sta MMU_CR
; Clear the BSS data
jsr zerobss
; Save system stuff and setup the stack
pla ; Get MMU setting
sta mmusave
tsx
stx spsave ; save system stk ptr
lda #<$C000
sta sp
lda #>$C000
sta sp+1
; 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
; Reset the conio stuff
jsr doneconio
; Reset stack and the MMU
ldx spsave ; Patched at runtime
txs
lda mmusave ; Patched at runtime
sta MMU_CR
; Copy back the zero page stuff
ldy #zpspace-1
L2: lda zpsave,y
sta sp,y
dey
bpl L2
; Done
jmp RESTOR
.data
zpsave: .res zpspace
.bss
spsave: .res 1
mmusave:.res 1

24
libsrc/c128/dbgbreak.s Normal file
View File

@@ -0,0 +1,24 @@
;
; Ullrich von Bassewitz, 10.08.1998
;
; unsigned DbgSetBreakVec (unsigned Addr);
;
.export _DbgSetBreakVec
.import popax, utstax
.include "../cbm/cbm.inc"
_DbgSetBreakVec:
jsr popax ; Get the new address
ldy BRKVec
sta BRKVec
lda BRKVec+1
stx BRKVec+1
tax
tya
jmp utstax

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

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

41
libsrc/c128/readjoy.s Normal file
View File

@@ -0,0 +1,41 @@
;
; Ullrich von Bassewitz, 23.09.1998
;
; unsigned readjoy (unsigned char joy);
;
.export _readjoy
.include "c128.inc"
.proc _readjoy
tax ; Joystick number into X
bne joy2
; Read joystick 1
joy1: lda #$7F
sei
sta CIA1_PRA
lda CIA1_PRB
cli
and #$1F
eor #$1F
rts
; Read joystick 2
joy2: ldx #0
lda #$E0
ldy #$FF
sta CIA1_DDRA
lda CIA1_PRA
sty CIA1_DDRA
and #$1F
eor #$1F
rts
.endproc