More cbm510 changes to make file I/O and kernal access work

git-svn-id: svn://svn.cc65.org/cc65/trunk@2846 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-12-27 16:11:14 +00:00
parent 40a48c59b8
commit dada43f570
27 changed files with 670 additions and 642 deletions

View File

@@ -157,7 +157,7 @@ cbm510lib:
done done
mv cbm510/crt0.o cbm510.o mv cbm510/crt0.o cbm510.o
cp cbm510/*.emd . cp cbm510/*.emd .
cp cbm510/*.joy . cp cbm510/cbm510-stdjoy.joy cbm510-std.joy
cp cbm510/cbm510-stdser.ser cbm510-std.ser cp cbm510/cbm510-stdser.ser cbm510-std.ser
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@@ -42,14 +42,17 @@ OBJS = _scrsize.o \
cgetc.o \ cgetc.o \
clrscr.o \ clrscr.o \
color.o \ color.o \
conio.o \
cputc.o \ cputc.o \
crt0.o \ crt0.o \
extzp.o \ extzp.o \
kbhit.o \ kbhit.o \
kirq.o \ kclose.o \
kplot.o \ kernal.o \
kiobase.o \
kopen.o \
kreadst.o \
kscnkey.o \ kscnkey.o \
ksetnam.o \
kudtim.o \ kudtim.o \
mainargs.o \ mainargs.o \
mouse.o \ mouse.o \

View File

@@ -1,19 +1,12 @@
; ;
; Ullrich von Bassewitz, 13.09.2000 ; Ullrich von Bassewitz, 26.10.2000
; ;
; Screen size variables ; Screen size variables
; ;
.export screensize .export screensize
.import SCREEN
.include "cbm510.inc"
screensize = SCREEN
.proc screensize
ldx #XSIZE
ldy #YSIZE
rts
.endproc

View File

@@ -1,20 +1,20 @@
; ;
; Ullrich von Bassewitz, 13.09.2001 ; Ullrich von Bassewitz, 28.09.1998
; ;
; Banking routines for the 510. ; Banking routines for the 610.
; ;
.export set_bank, sys_bank, restore_bank .export set_bank, sys_bank, restore_bank
.importzp ptr1 .importzp ptr1, segsave
.include "cbm510.inc" .include "cbm510.inc"
.code .code
.proc sys_bank .proc sys_bank
pha pha
lda IndReg lda IndReg
sta IndSegSave sta segsave
lda #$0F lda #$0F
sta IndReg sta IndReg
pla pla
@@ -24,7 +24,7 @@
.proc set_bank .proc set_bank
pha pha
lda IndReg lda IndReg
sta IndSegSave sta segsave
pla pla
sta IndReg sta IndReg
rts rts
@@ -32,7 +32,7 @@
.proc restore_bank .proc restore_bank
pha pha
lda IndSegSave lda segsave
sta IndReg sta IndReg
pla pla
rts rts

View File

@@ -7,9 +7,9 @@
.export _set_brk, _reset_brk .export _set_brk, _reset_brk
.export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc
.import _atexit .import _atexit, BRKVec
.include "cbm510.inc" .include "cbm510.inc"
.bss .bss
@@ -74,6 +74,8 @@ L1: lda #<brk_handler ; Set the break vector to our routine
.proc brk_handler .proc brk_handler
pla
sta _brk_01
pla pla
sta _brk_y sta _brk_y
pla pla
@@ -90,15 +92,11 @@ L1: lda #<brk_handler ; Set the break vector to our routine
pla ; PC high pla ; PC high
sbc #0 sbc #0
sta _brk_pc+1 sta _brk_pc+1
lda IndReg
sta _brk_01
lda ExecReg
sta IndReg
jsr uservec ; Call the user's routine jsr uservec ; Call the user's routine
lda _brk_01 lda _brk_01
sta IndReg sta IndReg
lda _brk_pc+1 lda _brk_pc+1
pha pha

View File

@@ -11,7 +11,8 @@
.include "joy-kernel.inc" .include "joy-kernel.inc"
.include "joy-error.inc" .include "joy-error.inc"
.include "cbm510.inc" .include "cbm510.inc"
.include "extzp.inc"
.macpack generic .macpack generic

View File

@@ -12,80 +12,6 @@
ExecReg = $0000 ExecReg = $0000
IndReg = $0001 IndReg = $0001
; Up to $20 and $60-8F used by runtime and fixed values
; -----------------------------------
KbdScanBuf = $20 ; Intermediate for keyboard scan
FileNameAdrLo = $90
FileNameAdrHi = $91
FileNameAdrSeg = $92
FileNameLen = $9D
LogicalAdr = $9E
FirstAdr = $9F
SecondAdr = $A0
IndSegSave = $B5
SCREEN_PTR = $C8
CURS_Y = $CA
CURS_X = $CB
GrafMode = $CC
LastIndex = $CD
LastLine = $CE
LastCol = $CF
crsw = $D0
KeyIndex = $D1
QuoteSw = $D2
Insrt = $D3
Config = $D4
LastLinePos = $D5
PgmKeyIndex = $D6
RepeatCount = $D7
RepeatDelay = $D8
ModKey = $E0
NorKey = $E1
CURS_FLAG = $E6 ; 1 = no cursor
CURS_BLINK = $E7 ; cursor blink counter
CRAM_PTR = $E8
CURS_STATE = $EB ; Cursor blink state
CHARCOLOR = $EC
CURS_COLOR = $ED ; Color behind cursor
;-----------------------------------------------------------------------------
; Page 3 variables
;
; system ram vectors
;
IRQVec = $0300
BRKVec = $0302
NMIVec = $0304
;
;
;
LogicalAdrTable = $0334
FirstAdrTable = $033E
SecondAdrTable = $0348
SysMemBot = $0352
SysMemTop = $0355
UsrMemBot = $0358
UsrMemTop = $035B
DevTabIndex = $0360
PgmKeyEnd = $0380
PgmKeySeg = $0382
RVS = $0383
LastPrtChar = $0399
InsertFlag = $039A
ScrollFlag = $039B
PgmKeyIdx = $039D
LogScrollFlag = $039E
BellMode = $039F ; Bell on/off 00 = an
SegSave = $03A0
TabStopTable = $03A1 ; 80 bits for tabstops
KeyBuf = $03AB ; Keyboard buffer
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; Screen size ; Screen size

View File

@@ -9,13 +9,14 @@
.import cursor .import cursor
.include "cbm510.inc" .include "cbm510.inc"
.include "extzp.inc"
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.proc _cgetc .proc _cgetc
lda KeyIndex ; Characters waiting? lda keyidx ; Characters waiting?
bne L3 ; Jump if so bne L3 ; Jump if so
; Switch on the cursor if needed ; Switch on the cursor if needed
@@ -24,7 +25,7 @@
pha pha
lda cursor lda cursor
jsr setcursor jsr setcursor
L1: lda KeyIndex L1: lda keyidx
beq L1 beq L1
ldx #0 ldx #0
pla pla
@@ -36,14 +37,14 @@ L2: txa
; Read the character from the keyboard buffer ; Read the character from the keyboard buffer
L3: ldx #$00 ; Get index L3: ldx #$00 ; Get index
ldy KeyBuf ; Get first character in the buffer ldy keybuf ; Get first character in the buffer
sei sei
L4: lda KeyBuf+1,x ; Move up the remaining chars L4: lda keybuf+1,x ; Move up the remaining chars
sta KeyBuf,x sta keybuf,x
inx inx
cpx KeyIndex cpx keyidx
bne L4 bne L4
dec KeyIndex dec keyidx
cli cli
ldx #$00 ; High byte ldx #$00 ; High byte
@@ -61,7 +62,7 @@ L4: lda KeyBuf+1,x ; Move up the remaining chars
tax ; On or off? tax ; On or off?
bne @L9 ; Go set it on bne @L9 ; Go set it on
lda CURS_FLAG ; Is the cursor currently off? lda CURS_FLAG ; Is the cursor currently off?
bne @L8 ; Jump if yes bne @L8 ; Jump if yes
lda #1 lda #1
sta CURS_FLAG ; Mark it as off sta CURS_FLAG ; Mark it as off
lda CURS_STATE ; Cursor currently displayed? lda CURS_STATE ; Cursor currently displayed?
@@ -148,3 +149,4 @@ curend: rts
.endproc .endproc

View File

@@ -6,6 +6,7 @@
.import plot .import plot
.include "cbm510.inc" .include "cbm510.inc"
.include "extzp.inc"
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; void __fastcall__ clrscr (void); ; void __fastcall__ clrscr (void);

View File

@@ -4,7 +4,7 @@
.export _textcolor, _bgcolor, _bordercolor .export _textcolor, _bgcolor, _bordercolor
.import sys_bank, restore_bank .import sys_bank, restore_bank
.importzp vic .import vic: zp, CHARCOLOR: zp
.include "cbm510.inc" .include "cbm510.inc"

View File

@@ -1,10 +0,0 @@
;
; Ullrich von Bassewitz, 14.09.2001
;
; Low level stuff for screen output/console input
;
.exportzp CURS_X, CURS_Y
.include "cbm510.inc"

View File

@@ -8,11 +8,15 @@
.export _cputcxy, _cputc, cputdirect, putchar .export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot .export newline, plot
.import PLOT
.import popa, _gotoxy .import popa, _gotoxy
.import __VIDRAM_START__
.import CURS_X: zp, CURS_Y: zp, CHARCOLOR: zp, RVS: zp
.import SCREEN_PTR: zp, CRAM_PTR: zp
.include "cbm510.inc" .include "cbm510.inc"
.macpack generic
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; ;
@@ -59,38 +63,32 @@ advance:
L3: sty CURS_X L3: sty CURS_X
rts 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 ; Handle character if high bit set
L10: and #$7F L10: and #$7F
cmp #$7E ; PI? cmp #$7E ; PI?
bne L11 bne L11
lda #$5E ; Load screen code for PI lda #$5E ; Load screen code for PI
bne cputdirect bne cputdirect
L11: ora #$40 L11: ora #$40
bne cputdirect bne cputdirect ; Branch always
; Move the cursor into the next line
newline:
inc CURS_Y
; Set cursor position, calculate RAM pointers ; Set cursor position, calculate RAM pointers
plot: ldy CURS_X plot: ldx CURS_Y
ldx CURS_Y lda LineLSBTab,x
clc sta SCREEN_PTR
jmp PLOT ; Set the new cursor sta CRAM_PTR
lda LineMSBTab,x
sta SCREEN_PTR+1
add #.hibyte(COLOR_RAM - __VIDRAM_START__)
sta CRAM_PTR+1
rts
; Write one character to the screen without doing anything else, return X ; Write one character to the screen without doing anything else, return X
; position in Y ; position in Y
@@ -107,3 +105,20 @@ putchar:
stx IndReg stx IndReg
rts rts
; -------------------------------------------------------------------------
; Low bytes of the start address of the screen lines
.rodata
LineLSBTab:
.repeat 25, I
.byte .lobyte(__VIDRAM_START__ + I * 40)
.endrep
; -------------------------------------------------------------------------
; High bytes of the start address of the screen lines
LineMSBTab:
.repeat 25, I
.byte .hibyte(__VIDRAM_START__ + I * 40)
.endrep

View File

@@ -6,13 +6,12 @@
.export _exit .export _exit
.import _clrscr, initlib, donelib .import _clrscr, initlib, donelib, condes
.import push0, callmain .import push0, callmain
.import __CHARRAM_START__, __CHARRAM_SIZE__, __VIDRAM_START__ .import __CHARRAM_START__, __CHARRAM_SIZE__, __VIDRAM_START__
.import __EXTZP_RUN__, __EXTZP_SIZE__ .import __BSS_RUN__, __BSS_SIZE__, __EXTZP_RUN__
.import __BSS_RUN__, __BSS_SIZE__ .import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
.import irq, nmi .import scnkey, UDTIM
.import k_irq, k_nmi, PLOT, UDTIM, SCNKEY
.include "zeropage.inc" .include "zeropage.inc"
.include "extzp.inc" .include "extzp.inc"
@@ -48,30 +47,48 @@
; that is overwritten later. ; that is overwritten later.
; ;
.code .segment "BASICHDR"
; To make things more simple, make the code of this module absolute. .byte $03,$00,$11,$00,$0a,$00,$81,$20,$49,$b2,$30,$20,$a4,$20,$34,$00
.org $0001
Head: .byte $03,$00,$11,$00,$0a,$00,$81,$20,$49,$b2,$30,$20,$a4,$20,$34,$00
.byte $19,$00,$14,$00,$87,$20,$4a,$00,$27,$00,$1e,$00,$97,$20,$32,$35 .byte $19,$00,$14,$00,$87,$20,$4a,$00,$27,$00,$1e,$00,$97,$20,$32,$35
.byte $36,$aa,$49,$2c,$4a,$00,$2f,$00,$28,$00,$82,$20,$49,$00,$39,$00 .byte $36,$aa,$49,$2c,$4a,$00,$2f,$00,$28,$00,$82,$20,$49,$00,$39,$00
.byte $32,$00,$9e,$20,$32,$35,$36,$00,$4f,$00,$3c,$00,$83,$20,$31,$32 .byte $32,$00,$9e,$20,$32,$35,$36,$00,$4f,$00,$3c,$00,$83,$20,$31,$32
.byte $30,$2c,$31,$36,$39,$2c,$30,$2c,$31,$33,$33,$2c,$30,$00,$00,$00 .byte $30,$2c,$31,$36,$39,$2c,$30,$2c,$31,$33,$33,$2c,$30,$00,$00,$00
;------------------------------------------------------------------------------
; A table that contains values that must be transfered from the system zero
; page into out zero page. Contains pairs of bytes, first one is the address
; in the system ZP, second one is our ZP address. The table goes into page 2,
; but is declared here, because it is needed earlier.
.SEGMENT "PAGE2"
.proc transfer_table
.byte $CA, CURS_Y
.byte $CB, CURS_X
.byte $EC, CHARCOLOR
.byte
.endproc
;------------------------------------------------------------------------------
; The code in the target bank when switching back will be put at the bottom ; The code in the target bank when switching back will be put at the bottom
; of the stack. We will jump here to switch segments. The range $F2..$FF is ; of the stack. We will jump here to switch segments. The range $F2..$FF is
; not used by any kernal routine. ; not used by any kernal routine.
.res $F8-* .segment "STARTUP"
Back: ldx spsave
Back: sei
ldx spsave
txs txs
lda IndReg lda IndReg
sta ExecReg sta ExecReg
; The following code is a copy of the code that is poked in the system bank ; We are at $100 now. The following snippet is a copy of the code that is poked
; memory by the basic header program, it's only for documentation and not ; in the system bank memory by the basic header program, it's only for
; actually used here: ; documentation and not actually used here:
sei sei
lda #$00 lda #$00
@@ -79,70 +96,151 @@ Back: ldx spsave
; This is the actual starting point of our code after switching banks for ; This is the actual starting point of our code after switching banks for
; startup. Beware: The following code will get overwritten as soon as we ; startup. Beware: The following code will get overwritten as soon as we
; use the stack (since it's in page 1)! ; use the stack (since it's in page 1)! We jump to another location, since
; we need some space for subroutines that aren't used later.
tsx jmp Origin
stx spsave ; Save the system stackpointer
ldx #$FF
txs ; Set up our own stack
; Set the interrupt, NMI and other vectors ; Hardware vectors, copied to $FFFA
ldy #vectable_size .proc vectors
L0: lda vectable-1,y sta ExecReg
sta $FF81-1,y rts
dey nop
bne L0 .word nmi ; NMI vector
.word 0 ; Reset - not used
.word irq ; IRQ vector
.endproc
; Initialize the extended zero page variables ; Initializers for the extended zeropage. See extzp.s
ldx #zptable_size .proc extzp
L1: lda zptable-1,x .word $0100 ; sysp1
sta <(__EXTZP_RUN__-1),x .word $0300 ; sysp3
dex .word $d800 ; vic
bne L1 .word $da00 ; sid
.word $db00 ; cia1
.word $dc00 ; cia2
.word $dd00 ; acia
.word $de00 ; tpi1
.word $df00 ; tpi2
.word $eab1 ; ktab1
.word $eb11 ; ktab2
.word $eb71 ; ktab3
.word $ebd1 ; ktab4
.endproc
; The following code is part of the kernal call subroutine. It is copied
; to $FFAE
.proc callsysbank_15
php
pha
lda #$0F ; Bank 15
sta IndReg
sei
.endproc
; Save the old stack pointer from the system bank and setup our hw sp
Origin: tsx
stx spsave ; Save the system stackpointer
ldx #$FE ; Leave $1FF untouched for cross bank calls
txs ; Set up our own stack
; Switch the indirect segment to the system bank ; Switch the indirect segment to the system bank
lda #$0F lda #$0F
sta IndReg sta IndReg
; Copy the kernal zero page ($90-$F2) from the system bank ; Initialize the extended zeropage
lda #$90 ldx #.sizeof(extzp)-1
sta ptr1 L1: lda extzp,x
lda #$00 sta <__EXTZP_RUN__,x
sta ptr1+1 dex
ldy #$62-1 bpl L1
L2: lda (ptr1),y
sta $90,y
dey
bpl L2
; Copy the page 3 vectors in place ; Copy stuff from the system zeropage to ours
ldy #$00 lda #.sizeof(transfer_table)
L3: lda p3vectable,y sta ktmp
sta $300,y L2: ldx ktmp
iny ldy transfer_table-2,x
cpy #p3vectable_size lda transfer_table-1,x
bne L3 tax
lda (sysp0),y
sta $00,x
dec ktmp
dec ktmp
bne L2
; Copy the rest of page 3 from the system bank ; Set the interrupt, NMI and other vectors
lda #$00 ldx #.sizeof(vectors)-1
sta ptr1 L3: lda vectors,x
lda #$03 sta $10000 - .sizeof(vectors),x
sta ptr1+1 dex
L4: lda (ptr1),y bpl L3
sta $300,y
iny ; Setup the C stack
bne L4
lda #.lobyte($FEAE - .sizeof(callsysbank_15))
sta sp
lda #.hibyte($FEAE - .sizeof(callsysbank_15))
sta sp+1
; Setup the subroutine and jump vector table that redirects kernal calls to
; the system bank. Copy the bank switch routines starting at $FEAE from the
; system bank into the current bank.
ldy #.sizeof(callsysbank_15)-1 ; Copy the modified part
@L1: lda callsysbank_15,y
sta $FEAE - .sizeof(callsysbank_15),y
dey
bpl @L1
lda #.lobyte($FEAE) ; Copy the ROM part
sta ptr1
lda #.hibyte($FEAE)
sta ptr1+1
ldy #$00
@L2: lda (ptr1),y
sta $FEAE,y
iny
cpy #<($FF6F-$FEAE)
bne @L2
; Setup the jump vector table
ldy #$00
ldx #45-1 ; Number of vectors
@L3: lda #$20 ; JSR opcode
sta $FF6F,y
iny
lda #.lobyte($FEAE - .sizeof(callsysbank_15))
sta $FF6F,y
iny
lda #.hibyte($FEAE - .sizeof(callsysbank_15))
sta $FF6F,y
iny
dex
bpl @L3
; Copy the stack from the system bank into page 3
ldy #$FF
L4: lda (sysp1),y
sta $300,y
dey
cpy spsave
bne L4
; Set the indirect segment to bank we're executing in ; Set the indirect segment to bank we're executing in
lda ExecReg lda ExecReg
sta IndReg sta IndReg
; Zero the BSS segment. We will do that here instead calling the routine ; Zero the BSS segment. We will do that here instead calling the routine
; in the common library, since we have the memory anyway, and this way, ; in the common library, since we have the memory anyway, and this way,
@@ -150,10 +248,10 @@ L4: lda (ptr1),y
lda #<__BSS_RUN__ lda #<__BSS_RUN__
sta ptr1 sta ptr1
lda #>__BSS_RUN__ lda #>__BSS_RUN__
sta ptr1+1 sta ptr1+1
lda #0 lda #0
tay tay
; Clear full pages ; Clear full pages
@@ -163,7 +261,7 @@ Z1: sta (ptr1),y
iny iny
bne Z1 bne Z1
inc ptr1+1 ; Next page inc ptr1+1 ; Next page
dex dex
bne Z1 bne Z1
; Clear the remaining page ; Clear the remaining page
@@ -174,34 +272,17 @@ Z3: sta (ptr1),y
iny iny
dex dex
bne Z3 bne Z3
Z4: Z4: jmp Init
; Setup the C stack ; ------------------------------------------------------------------------
; We are at $200 now. We may now start calling subroutines safely, since
; the code we execute is no longer in the stack page.
lda #<$FF81 .segment "PAGE2"
sta sp
lda #>$FF81
sta sp+1
; We expect to be in page 2 now
.if (* < $1FD)
jmp $200
.res $200-*
.endif
.if (* < $200)
.res $200-*,$EA
.endif
.if (* >= $2F0)
.error "Code range invalid"
.endif
; This code is in page 2, so we may now start calling subroutines safely,
; since the code we execute is no longer in the stack page.
; Copy the character rom from the system bank into the execution bank ; Copy the character rom from the system bank into the execution bank
lda #<$C000 Init: lda #<$C000
sta ptr1 sta ptr1
lda #>$C000 lda #>$C000
sta ptr1+1 sta ptr1+1
@@ -213,7 +294,7 @@ Z4:
sta tmp1 sta tmp1
ldy #$00 ldy #$00
ccopy: lda #$0F ccopy: lda #$0F
sta IndReg ; Access the system bank sta IndReg ; Access the system bank
ccopy1: lda (ptr1),y ccopy1: lda (ptr1),y
sta __VIDRAM_START__,y sta __VIDRAM_START__,y
iny iny
@@ -225,7 +306,7 @@ ccopy2: lda __VIDRAM_START__,y
iny iny
bne ccopy2 bne ccopy2
inc ptr1+1 inc ptr1+1
inc ptr2+1 ; Bump high pointer bytes inc ptr2+1 ; Bump high pointer bytes
dec tmp1 dec tmp1
bne ccopy bne ccopy
@@ -278,96 +359,11 @@ ccopy2: lda __VIDRAM_START__,y
lda ExecReg lda ExecReg
sta IndReg sta IndReg
; Call module constructors ; Call module constructors, enable chained IRQs afterwards.
jsr initlib jsr initlib
lda #.lobyte(__IRQFUNC_COUNT__*2)
; Execute the program code sta irqcount
jmp Start
; ------------------------------------------------------------------------
; Additional data that we need for initialization and that's overwritten
; later
zptable:
.word $d800 ; vic
.word $da00 ; sid
.word $db00 ; cia1
.word $dc00 ; cia2
.word $dd00 ; acia
.word $de00 ; tpi1
.word $df00 ; tpi2
.word $eab1 ; ktab1
.word $eb11 ; ktab2
.word $eb71 ; ktab3
.word $ebd1 ; ktab4
.dword $0000 ; time
.word $0100 ; RecvBuf
.word $0200 ; SendBuf
zptable_size = * - zptable
vectable:
jmp $0000 ; CINT
jmp $0000 ; IOINIT
jmp $0000 ; RAMTAS
jmp $0000 ; RESTOR
jmp $0000 ; VECTOR
jmp $0000 ; SETMSG
jmp $0000 ; SECOND
jmp $0000 ; TKSA
jmp $0000 ; MEMTOP
jmp $0000 ; MEMBOT
jmp SCNKEY
jmp $0000 ; SETTMO
jmp $0000 ; ACPTR
jmp $0000 ; CIOUT
jmp $0000 ; UNTLK
jmp $0000 ; UNLSN
jmp $0000 ; LISTEN
jmp $0000 ; TALK
jmp $0000 ; READST
jmp SETLFS
jmp SETNAM
jmp $0000 ; OPEN
jmp $0000 ; CLOSE
jmp $0000 ; CHKIN
jmp $0000 ; CKOUT
jmp $0000 ; CLRCH
jmp $0000 ; BASIN
jmp $0000 ; BSOUT
jmp $0000 ; LOAD
jmp $0000 ; SAVE
jmp SETTIM
jmp RDTIM
jmp $0000 ; STOP
jmp $0000 ; GETIN
jmp $0000 ; CLALL
jmp UDTIM
jmp SCREEN
jmp PLOT
jmp IOBASE
sta ExecReg
rts
.byte $01 ; Filler
.word nmi
.word 0 ; Reset - not used
.word irq
vectable_size = * - vectable
p3vectable:
.word k_irq ; IRQ user vector
.word k_brk ; BRK user vector
.word k_nmi ; NMI user vector
p3vectable_size = * - p3vectable
; ------------------------------------------------------------------------
; This is the program code after setup. It starts at $400
.res $400-*
Start:
; Enable interrupts ; Enable interrupts
@@ -377,14 +373,17 @@ Start:
jsr callmain jsr callmain
; Call module destructors. This is also the _exit entry. ; Call module destructors. This is also the _exit entry and the default entry
; point for the break vector.
_exit: jsr donelib ; Run module destructors _exit: lda #$00
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
; We need access to the system bank now ; Address the system bank
lda #$0F lda #$0F
sta IndReg sta IndReg
; Switch back the video to the system bank ; Switch back the video to the system bank
@@ -400,102 +399,128 @@ _exit: jsr donelib ; Run module destructors
lda vidsave+2 lda vidsave+2
sta (vic),y sta (vic),y
; Clear the start of the zero page, since it will be interpreted as a ; Copy stuff back from our zeropage to the systems
; (garbage) BASIC program otherwise. This is also the default entry for
; the break vector.
k_brk: sei .if 0
lda #$00 lda #.sizeof(transfer_table)
ldx #$3E sta ktmp
Clear: sta $02,x @L0: ldx ktmp
dex ldy transfer_table-2,x
bne Clear lda transfer_table-1,x
tax
; Setup the welcome code at the stack bottom in the system bank. Use
; the F4/F5 vector to access the system bank
ldy #$00
sty $F4
iny
sty $F5
ldy #reset_size-1
@L1: lda reset,y
sta ($F4),y
dey
bne @L1
jmp Back
; ------------------------------------------------------------------------
; Code that is copied into the system bank at $100 when switching back
reset: cli
jmp $8000 ; BASIC cold start
reset_size = * - reset
; ------------------------------------------------------------------------
; Code for a few simpler kernal calls goes here
.export IOBASE
.proc IOBASE
ldx cia2
ldy cia2+1
rts
.endproc
.export SCREEN
.proc SCREEN
ldx #40 ; Columns
ldy #25 ; Lines
rts
.endproc
.export SETLFS
.proc SETLFS
sta LogicalAdr
stx FirstAdr
sty SecondAdr
rts
.endproc
.export SETNAM
.proc SETNAM
sta FileNameLen
lda $00,x lda $00,x
sta FileNameAdrLo sta (sysp0),y
lda $01,x dec ktmp
sta FileNameAdrHi dec ktmp
lda $02,x bne @L0
sta FileNameAdrSeg .endif
rts
.endproc
.export RDTIM ; Copy back the old system bank stack contents
.proc RDTIM
sei
lda time+0
ldx time+1
ldy time+2
cli
rts
.endproc
.export SETTIM ldy #$FF
.proc SETTIM @L1: lda $300,y
sei sta (sysp1),y
sta time+0 dey
stx time+1 cpy spsave
sty time+2 bne @L1
cli
rts ; Setup the welcome code at the stack bottom in the system bank.
.endproc
ldy #$00
lda #$58 ; CLI opcode
sta (sysp1),y
iny
lda #$60 ; RTS opcode
sta (sysp1),y
jmp Back
; ------------------------------------------------------------------------- ; -------------------------------------------------------------------------
; Data area - switch back to relocatable mode ; The IRQ handler goes into PAGE2. For performance reasons, and to allow
; easier chaining, we do handle the IRQs in the execution bank (instead of
; passing them to the system bank).
.reloc ; This is the mapping of the active irq register of the 6525 (tpi1):
;
; Bit 7 6 5 4 3 2 1 0
; | | | | ^ 50 Hz
; | | | ^ SRQ IEEE 488
; | | ^ cia
; | ^ IRQB ext. Port
; ^ acia
irq: pha
txa
pha
tya
pha
lda IndReg
pha
lda ExecReg
sta IndReg ; Be sure to address our segment
tsx
lda $105,x ; Get the flags from the stack
and #$10 ; Test break flag
bne dobrk
; It's an IRQ
cld
; Call chained IRQ handlers
ldy irqcount
beq irqskip
lda #<__IRQFUNC_TABLE__
ldx #>__IRQFUNC_TABLE__
jsr condes ; Call the functions
; Done with chained IRQ handlers, check the TPI for IRQs and handle them
irqskip:lda #$0F
sta IndReg
ldy #TPI::AIR
lda (tpi1),y ; Interrupt Register 6525
beq noirq
; 50/60Hz interrupt
cmp #%00000001 ; ticker irq?
bne irqend
jsr scnkey ; Poll the keyboard
jsr UDTIM ; Bump the time
; Done
irqend: ldy #TPI::AIR
sta (tpi1),y ; Clear interrupt
noirq: pla
sta IndReg
pla
tay
pla
tax
pla
nmi: rti
dobrk: jmp (BRKVec)
; -------------------------------------------------------------------------
; Page 3
.segment "PAGE3"
BRKVec: .addr _exit ; BRK indirect vector
; -------------------------------------------------------------------------
; Data area
.data .data
spsave: .res 1 spsave: .res 1
vidsave:.res 3 vidsave:.res 3
.bss
irqcount: .byte 0

View File

@@ -1,11 +1,19 @@
; ;
; Ullrich von Bassewitz, 2003-02-16 ; Ullrich von Bassewitz, 2003-12-27
; ;
; Additional zero page locations for the CBM510. ; Additional zero page locations for the CBM510.
; ;
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.globalzp vic, sid, cia1, cia2, acia, tpi1, tpi2, ktab1 .globalzp sysp1, sysp3, vic, sid, ipccia, cia1, cia2, acia
.globalzp ktab2, ktab3, ktab4, time .globalzp tpi1, tpi2, ktab1, ktab2, ktab3, ktab4
.globalzp sysp0, time, segsave, ktmp, CURS_X, CURS_Y, CURS_FLAG
.globalzp CURS_STATE, CURS_BLINK, CURS_COLOR, CHARCOLOR, RVS
.globalzp SCREEN_PTR, CRAM_PTR
.globalzp keyidx, keybuf, keyscanbuf, keysave, modkey
.globalzp norkey, graphmode, lastidx, rptdelay, rptcount

View File

@@ -13,6 +13,12 @@
.segment "EXTZP" : zeropage .segment "EXTZP" : zeropage
; The following values get initialized from a table in the startup code.
; While this sounds crazy, it has reasons that have to do with modules (and
; we have the space anyway). So when changing anything, be sure to adjust the
; initializer table
sysp1: .res 2
sysp3: .res 2
vic: .res 2 vic: .res 2
sid: .res 2 sid: .res 2
cia1: .res 2 cia1: .res 2
@@ -24,5 +30,30 @@ ktab1: .res 2
ktab2: .res 2 ktab2: .res 2
ktab3: .res 2 ktab3: .res 2
ktab4: .res 2 ktab4: .res 2
time: .res 4
sysp0: .word $0000
time: .dword $0000
segsave: .byte 0
ktmp: .byte 0
CURS_X: .byte 0
CURS_Y: .byte 0
CURS_FLAG: .byte 0
CURS_STATE: .byte 0
CURS_BLINK: .byte 0
CURS_COLOR: .byte 0
CHARCOLOR: .byte 0
RVS: .byte 0
SCREEN_PTR: .word 0
CRAM_PTR: .word 0
; Stuff for our own kbd polling routine
keyidx: .byte 0 ; Number of keys in keyboard buffer
keybuf: .res 10 ; Keyboard buffer
keyscanbuf: .byte 0
keysave: .byte 0
modkey: .byte 0
norkey: .byte 0
graphmode: .byte 0
lastidx: .byte 0
rptdelay: .byte 0
rptcount: .byte 0

View File

@@ -6,11 +6,11 @@
.export _kbhit .export _kbhit
.import return0, return1 .import return0, return1
.import keyidx: zp
.include "cbm510.inc"
.proc _kbhit .proc _kbhit
lda KeyIndex ; Get number of characters lda keyidx ; Get number of characters
bne L1 bne L1
jmp return0 jmp return0
L1: jmp return1 L1: jmp return1

21
libsrc/cbm510/kclose.s Normal file
View File

@@ -0,0 +1,21 @@
;
; Ullrich von Bassewitz, 2003-12-21
;
; CLOSE kernal call.
;
; NOTE: The CLOSE system call in the CBM610 kernal will only remove the file
; entry and not close the file on IEC if the carry is clear on entry. To make
; this somewhat compatible with the C64, set the carry before jumping to the
; kernal.
.export CLOSE
.proc CLOSE
sec
jmp $FFC3
.endproc

83
libsrc/cbm510/kernal.s Normal file
View File

@@ -0,0 +1,83 @@
;
; Ullrich von Bassewitz, 2003-12-20
;
; CBM610 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 SETLFS
.export CHKIN
.export CKOUT
.export CLRCH
.export BASIN
.export BSOUT
.export LOAD
.export SAVE
.export STOP
.export GETIN
.export CLALL
.export PLOT
;-----------------------------------------------------------------------------
; All functions are available in the kernal jump table. Functions having
; replacements (usually short ones where the overhead of the cross bank call
; is not worth the trouble) are commented out.
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

19
libsrc/cbm510/kiobase.s Normal file
View File

@@ -0,0 +1,19 @@
;
; Ullrich von Bassewitz, 2003-12-19
;
; IOBASE kernal call
;
.export IOBASE
.import cia : zeropage
.proc IOBASE
ldx cia
ldy cia+1
rts
.endproc

View File

@@ -1,111 +0,0 @@
;
; Ullrich von Bassewitz, 28.09.1998
;
; IRQ routine for the 510.
;
.export irq, nmi, k_irq, k_nmi
.import SCNKEY, UDTIM, k_rs232
.import condes
.import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
.importzp tpi1
.include "cbm510.inc"
; -------------------------------------------------------------------------
; This is the mapping of the active irq register of the 6525 (tpi1):
;
; Bit 7 6 5 4 3 2 1 0
; | | | | ^ 50 Hz
; | | | ^ SRQ IEEE 488
; | | ^ cia2
; | ^ cia1 IRQB ext. Port
; ^ acia
; -------------------------------------------------------------------------
; IRQ entry point
.proc irq
pha
txa
pha
tya
pha
tsx
lda $104,x ; Get the flags from the stack
and #$10 ; Test break flag
bne L1
jmp (IRQVec)
L1: jmp (BRKVec)
.endproc
; -------------------------------------------------------------------------
; NMI entry point
.proc nmi
jmp (NMIVec)
.endproc
; -------------------------------------------------------------------------
; Kernal irq entry point. The IRQvec points here (usually).
k_irq:
lda IndReg ; Ind. Segment retten
pha
cld
lda #$0F
sta IndReg
ldy #TPI::AIR
lda (tpi1),y ; Interrupt Register 6525
beq noirq
; -------------------------------------------------------------------------
; 50/60Hz interrupt
cmp #%00000001 ; ticker irq?
bne irq1
; Call user IRQ handlers if we have any
ldy #<(__IRQFUNC_COUNT__*2)
beq @L1
lda #<__IRQFUNC_TABLE__
ldx #>__IRQFUNC_TABLE__
jsr condes ; Call the functions
; Call replacement kernal IRQ routines
@L1: jsr SCNKEY ; Poll the keyboard
jsr UDTIM ; Bump the time
; -------------------------------------------------------------------------
; UART interrupt
irq1: cmp #%00010000 ; interrupt from uart?
bne irqend
jsr k_rs232 ; Read character from uart
; -------------------------------------------------------------------------
; Done
irqend: ldy #TPI::AIR
sta (tpi1),y ; Clear interrupt
noirq: pla
sta IndReg
pla
tay
pla
tax
pla
k_nmi: rti

22
libsrc/cbm510/kopen.s Normal file
View File

@@ -0,0 +1,22 @@
;
; Ullrich von Bassewitz, 2003-12-20
;
; OPEN kernal call.
;
; NOTE: The OPEN system call in the CBM610 kernal is different from the
; standard. It evaluates the carry flag and does a normal open if carry clear
; and some strange things (output sa 15 + name on IEC) if carry set. To be
; compatible with our CBM file stuff, we have to clear the carry before
; calling the real OPEN.
.export OPEN
.proc OPEN
clc
jmp $FFC0
.endproc

View File

@@ -1,66 +0,0 @@
;
; Ullrich von Bassewitz, 13.09.2001
;
; PLOT routine for the 510.
;
.export PLOT
.import __VIDRAM_START__
.importzp crtc
.include "cbm510.inc"
.macpack generic
; ------------------------------------------------------------------------
;
.proc PLOT
bcs get
stx CURS_Y
sty CURS_X
lda LineLSBTab,x
sta SCREEN_PTR
sta CRAM_PTR
lda LineMSBTab,x
sta SCREEN_PTR+1
sub #>__VIDRAM_START__
add #>COLOR_RAM
sta CRAM_PTR+1
get: ldx CURS_Y
ldy CURS_X
rts
.endproc
; -------------------------------------------------------------------------
; Low bytes of the start address of the screen lines
.rodata
.macro LineLoTab
.repeat 25, I
.byte <(__VIDRAM_START__ + I * 40)
.endrep
.endmacro
LineLSBTab: LineLoTab
; -------------------------------------------------------------------------
; High bytes of the start address of the screen lines
.macro LineHiTab
.repeat 25, I
.byte >(__VIDRAM_START__ + I * 40)
.endrep
.endmacro
LineMSBTab: LineHiTab

26
libsrc/cbm510/kreadst.s Normal file
View File

@@ -0,0 +1,26 @@
;
; Ullrich von Bassewitz, 2003-12-19
;
; READST kernal call
;
.export READST
.import sys_bank, restore_bank
.import sysp0: zp, ktmp: zp
.include "cbm510.inc"
.proc READST
jsr sys_bank
sty ktmp ; Save Y register
ldy #$9C ; STATUS
lda (sysp0),y ; Load STATUS from system bank
ldy ktmp
jmp restore_bank ; Will set condition codes on A
.endproc

View File

@@ -4,19 +4,21 @@
; Keyboard polling stuff for the 510. ; Keyboard polling stuff for the 510.
; ;
.export SCNKEY .export scnkey
.importzp tpi2, ktab1, ktab2, ktab3, ktab4 .importzp tpi2, ktab1, ktab2, ktab3, ktab4
.importzp keyidx, keybuf, keyscanbuf, keysave, modkey, norkey
.importzp graphmode, lastidx, rptdelay, rptcount
.include "cbm510.inc" .include "cbm510.inc"
.proc SCNKEY .proc scnkey
lda #$FF lda #$FF
sta ModKey sta modkey
sta NorKey sta norkey
lda #$00 lda #$00
sta KbdScanBuf sta keyscanbuf
ldy #TPI::PRB ldy #TPI::PRB
sta (tpi2),y sta (tpi2),y
ldy #TPI::PRA ldy #TPI::PRA
@@ -35,7 +37,7 @@ L1: lda #$FF
sta (tpi2),y sta (tpi2),y
jsr Poll jsr Poll
pha pha
sta ModKey sta modkey
ora #$30 ora #$30
bne L3 ; Branch always bne L3 ; Branch always
@@ -44,11 +46,11 @@ L3: ldx #$05
ldy #$00 ldy #$00
L4: lsr a L4: lsr a
bcc L5 bcc L5
inc KbdScanBuf inc keyscanbuf
dex dex
bpl L4 bpl L4
sec sec
ldy TPI::PRB ldy #TPI::PRB
lda (tpi2),y lda (tpi2),y
rol a rol a
sta (tpi2),y sta (tpi2),y
@@ -60,8 +62,8 @@ L4: lsr a
pla pla
bcc NoKey ; Branch always bcc NoKey ; Branch always
L5: ldy KbdScanBuf L5: ldy keyscanbuf
sty NorKey sty norkey
pla pla
asl a asl a
asl a asl a
@@ -69,7 +71,7 @@ L5: ldy KbdScanBuf
bcc L6 bcc L6
bmi L7 bmi L7
lda (ktab2),y ; Shifted normal key lda (ktab2),y ; Shifted normal key
ldx GrafMode ldx graphmode
beq L8 beq L8
lda (ktab3),y ; Shifted key in graph mode lda (ktab3),y ; Shifted key in graph mode
bne L8 bne L8
@@ -80,23 +82,23 @@ L7: lda (ktab1),y ; Normal key
L8: tax L8: tax
cpx #$FF ; Valid key? cpx #$FF ; Valid key?
beq Done beq Done
cpy LastIndex cpy lastidx
beq Repeat beq Repeat
ldx #$13 ldx #$13
stx RepeatDelay stx rptdelay
ldx KeyIndex ldx keyidx
cpx #$09 cpx #$09
beq NoKey beq NoKey
cpy #$59 cpy #$59
bne PutKey bne PutKey
cpx #$08 cpx #$08
beq NoKey beq NoKey
sta KeyBuf,x sta keybuf,x
inx inx
bne PutKey bne PutKey
NoKey: ldy #$FF NoKey: ldy #$FF
Done: sty LastIndex Done: sty lastidx
End: lda #$7F End: lda #$7F
ldy #TPI::PRA ldy #TPI::PRA
sta (tpi2),y sta (tpi2),y
@@ -105,20 +107,20 @@ End: lda #$7F
sta (tpi2),y sta (tpi2),y
rts rts
Repeat: dec RepeatDelay Repeat: dec rptdelay
bpl End bpl End
inc RepeatDelay inc rptdelay
dec RepeatCount dec rptcount
bpl End bpl End
inc RepeatCount inc rptcount
ldx KeyIndex ldx keyidx
bne End bne End
PutKey: sta KeyBuf,x PutKey: sta keybuf,x
inx inx
stx KeyIndex stx keyidx
ldx #$03 ldx #$03
stx RepeatCount stx rptcount
bne Done bne Done
.endproc .endproc
@@ -127,18 +129,15 @@ PutKey: sta KeyBuf,x
; Poll the keyboard port until it's stable ; Poll the keyboard port until it's stable
.proc Poll .proc Poll
ldy TPI::PRC ldy #TPI::PRC
L1: lda (tpi2),y L1: lda (tpi2),y
sta KeySave sta keysave
lda (tpi2),y lda (tpi2),y
cmp KeySave cmp keysave
bne L1 bne L1
rts rts
.endproc .endproc
.bss
KeySave: .res 1

45
libsrc/cbm510/ksetnam.s Normal file
View File

@@ -0,0 +1,45 @@
;
; Ullrich von Bassewitz, 2003-12-18
;
; SETNAM kernal call.
;
; NOTE: The routine does not work like that in the CBM610 kernal (which works
; different than that on all other CBMs). Instead, it works like on all other
; Commodore machines. No segment has to be passed, the current segment is
; assumed.
.export SETNAM
.import sys_bank, restore_bank
.import sysp0: zp, ktmp: zp
.include "cbm510.inc"
.proc SETNAM
pha
jsr sys_bank
sty ktmp
txa
ldy #$90 ; FNAM
sta (sysp0),y
lda ktmp
iny
sta (sysp0),y
lda ExecReg ; Assume name is always in this segment
ldy #$92 ; FNAM_SEG
sta (sysp0),y
ldy #$9D ; FNAM_LEN
pla
sta (sysp0),y
ldy ktmp
jmp restore_bank
.endproc

View File

@@ -1,13 +1,12 @@
; ;
; Ullrich von Bassewitz, 13.09.2001 ; Ullrich von Bassewitz, 2003-12-21
; ;
; udtim routine for the 510. We will not check for the stop key here, since ; udtim routine for the 610. We will not check for the stop key here, since
; C programs will not use it. ; C programs will not use it.
; ;
.export UDTIM
.importzp time
.export UDTIM
.import time: zp
.proc UDTIM .proc UDTIM
@@ -22,5 +21,3 @@ L9: rts
.endproc .endproc

View File

@@ -5,8 +5,8 @@
; ;
.export _revers .export _revers
.import RVS: zp
.include "cbm510.inc"
.proc _revers .proc _revers