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

27
libsrc/pet/Makefile Normal file
View File

@@ -0,0 +1,27 @@
#
# 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 break.o color.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

109
libsrc/pet/break.s Normal file
View File

@@ -0,0 +1,109 @@
;
; Ullrich von Bassewitz, 26.11.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 "pet.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

68
libsrc/pet/cgetc.s Normal file
View File

@@ -0,0 +1,68 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; char cgetc (void);
;
.export _cgetc
.import cursor
.include "pet.inc"
_cgetc: lda KEY_COUNT ; Get number of characters
bne L3 ; Jump if there are already chars waiting
; Switch on the cursor if needed
lda CURS_FLAG
pha
lda cursor
jsr setcursor
L1: lda KEY_COUNT
beq L1
ldx #0
pla
bne L2
inx
L2: txa
jsr setcursor
; Fetch the character from the keyboard buffer
L3: sei
ldy KEY_BUF
ldx #$00
L4: lda KEY_BUF+1,x
sta KEY_BUF,x
inx
cpx KEY_COUNT
bne L4
dec KEY_COUNT
cli
ldx #$00 ; Clear high byte
tya
rts
; Switch the cursor on or off
setcursor:
tax ; On or off?
bne seton ; Go set it on
lda CURS_FLAG ; Is the cursor currently off?
bne crs9 ; Jump if yes
lda #1
sta CURS_FLAG ; Mark it as off
lda CURS_STATE ; Cursor currently displayed?
beq crs8 ; Jump if no
ldy CURS_X ; Get the character column
lda (SCREEN_PTR),y ; Get character
eor #$80
sta (SCREEN_PTR),y ; Store character back
crs8: lda #0
sta CURS_STATE ; Cursor not displayed
crs9: rts
seton: lda #0
sta CURS_FLAG
rts

50
libsrc/pet/clrscr.s Normal file
View File

@@ -0,0 +1,50 @@
;
; Ullrich von Bassewitz, 26.11.1998
;
; void clrscr (void);
;
.export _clrscr
.import plot
.importzp ptr1
.import xsize
.include "pet.inc"
_clrscr:
; Set the screen base address
lda #$00
sta ptr1
lda #$80
sta ptr1+1
; Determine, how many pages to fill
ldx #4
lda xsize
cmp #40
beq L1
ldx #8
; Clear the screen
L1: lda #$20 ; Screen code for blank
ldy #$00
L2: sta (ptr1),y
iny
bne L2
inc ptr1+1
dex
bne L2
; Set the cursor to 0/0
lda #0
sta CURS_X
sta CURS_Y
jmp plot
rts

18
libsrc/pet/color.s Normal file
View File

@@ -0,0 +1,18 @@
;
; 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
.import return0, return1
_textcolor = return1
_bgcolor = return0
_bordercolor = return0

24
libsrc/pet/conio.s Normal file
View File

@@ -0,0 +1,24 @@
;
; Ullrich von Bassewitz, 26.11.1998
;
; Low level stuff for screen output/console input
;
.export initconio
.import xsize, ysize
.exportzp CURS_X, CURS_Y
.include "pet.inc"
.code
initconio:
ldx SCR_LINELEN
inx ; Variable is one less
stx xsize
lda #25
sta ysize
rts

120
libsrc/pet/cputc.s Normal file
View File

@@ -0,0 +1,120 @@
;
; 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 "pet.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: 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_Y
lda ScrLo,y
sta SCREEN_PTR
lda ScrHi,y
ldy xsize
cpy #40
beq @L1
asl SCREEN_PTR ; 80 column mode
rol a
@L1: ora #$80 ; Screen at $8000
sta SCREEN_PTR+1
rts
; 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
rts
; Screen address tables - offset to real screen
.rodata
ScrLo: .byte $00, $28, $50, $78, $A0, $C8, $F0, $18
.byte $40, $68, $90, $B8, $E0, $08, $30, $58
.byte $80, $A8, $D0, $F8, $20, $48, $70, $98
.byte $C0
ScrHi: .byte $00, $00, $00, $00, $00, $00, $00, $01
.byte $01, $01, $01, $01, $01, $02, $02, $02
.byte $02, $02, $02, $02, $03, $03, $03, $03
.byte $03

125
libsrc/pet/crt0.s Normal file
View File

@@ -0,0 +1,125 @@
;
; Startup code for cc65 (PET version)
;
; This must be the *first* file on the linker command line
;
.export _exit
.import __hinit, initconio, zerobss, push0, doatexit
.import _main
.include "pet.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 $3FF
.word Head ; Load address
Head: .word @Next
.word 1000 ; Line number
.byte $9E,"1037" ; SYS 1037
.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
; sta $E84C ; See PET FAQ
jsr BSOUT
; Clear the BSS data
jsr zerobss
; Save system stuff and setup the stack
tsx
stx spsave ; Save the system stack ptr
lda MEMSIZE
sta sp
lda MEMSIZE+1
sta 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 ; Restore stack pointer
; Copy back the zero page stuff
ldy #zpspace-1
L2: lda zpsave,y
sta sp,y
dey
bpl L2
; Back to basic
rts
.data
zpsave: .res zpspace
.bss
spsave: .res 1
mmusave:.res 1

20
libsrc/pet/kbhit.s Normal file
View File

@@ -0,0 +1,20 @@
;
; Ullrich von Bassewitz, 26.11.1998
;
; int kbhit (void);
;
.export _kbhit
.import return0, return1
.include "pet.inc"
_kbhit:
lda KEY_COUNT ; Get number of characters
bne L1
jmp return0
L1: jmp return1

32
libsrc/pet/pet.inc Normal file
View File

@@ -0,0 +1,32 @@
;
; C64 generic definitions. Stolen from Elite128
;
; ---------------------------------------------------------------------------
; Zero page, Commodore stuff
MEMSIZE = $34 ; Size of memory installed
ST = $96 ; IEC status byte
SECADR = $D3 ; Secondary address
DEVNUM = $D4 ; Device number
KEY_COUNT = $9E ; Number of keys in input buffer
CURS_FLAG = $A7 ; 1 = cursor off
CURS_BLINK = $A8 ; Blink counter
CURS_CHAR = $A9 ; Character under the cursor
CURS_STATE = $AA ; Cursor blink state
SCREEN_PTR = $C4 ; Pointer to current char in text screen
CURS_X = $C6 ; Cursor column
CURS_Y = $D8 ; Cursor row
SCR_LINELEN = $D5 ; Screen line length
KEY_BUF = $26F ; Keyboard buffer
; ---------------------------------------------------------------------------
; Vector and other locations
IRQVec = $0090
BRKVec = $0092
NMIVec = $0094