Browse Source

added KERNAL_C128_03

master
Michael Steil 4 months ago
parent
commit
5856785bc9

+ 234
- 0
KERNAL_C128_03/channelio.src View File

@@ -0,0 +1,234 @@
.page
.subttl channel I/O (09/17/84): c/128

; ***********************************************
; * getin -- get a character from open channel *
; * *
; * channel is determined by dfltn. *
; * *
; * the keyboard and rs-232 (dfltn= 0 or 2) *
; * are serviced here by taking a character *
; * from the appropriate buffer. if nothing *
; * is available then = is returned. *
; * *
; * all other devices advance to 'basin'. *
; ***********************************************

ngetin
lda dfltn ;check default input device
bne 1$ ;...branch if not keyboard

lda ndx ;keyboard queue index
ora kyndx ;function key index
beq getrts ;...branch if nothing to get
sei ;freeze buffer
jmp lp2 ;goto editor to remove a character

1$ cmp #2
bne bn10 ;...branch if not rs-232

get232 sty xsav ;preserve .y
jsr bsi232 ;remove a character from rs-232 buffer
ldy xsav
getrts
clc ;signal a good return
rts

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; ***********************************************
; * basin - input a character from open channel *
; * *
; * channel is determined by dfltn. *
; * *
; * input from the keyboard or rs-232 is *
; * different than an get. input requires *
; * buffering an entire line which is then *
; * passed to 'basin' a character at a time *
; * up to the <cr>. *
; * *
; * the device assignments are: *
; * *
; * 0 = keyboard *
; * 1 = cassette *
; * 2 = rs-232 *
; * 3 = video display *
; * 4-31 = serial bus *
; ***********************************************

nbasin
lda dfltn ;check default input device
bne bn10 ;...branch if not the keyboard

; input from keyboard

lda pntr ;save current cursor position
sta lstp ;column
lda tblx
sta lsxp ;row
jmp loop5 ;goto screen editor, which will pass chr & rts

bn10
cmp #3 ;input from screen?
bne bn20 ;no...

sta crsw ;fake a carriage return for editor
lda scrt
sta indx ;point to right window margin as eol
jmp loop5 ;goto screen editor to pick up characters

bn20
bcs bn30 ;...branch if serial bus (device >3)
cmp #2
beq bn50 ;...branch if rs-232

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; input from cassette buffer

stx xsav ;preserve .x
jsr jtget
bcs 3$ ;...branch if <stop> or error
pha ;save character
jsr jtget
bcs 2$ ;...branch if <stop> or error
bne 1$ ;not an end of file

lda #64
jsr udst ;eof: update status

1$ dec bufpt ;one less chr in buffer
ldx xsav ;restore .x
pla ;restore character (.c=0 from 'jtget')
rts

2$ tax ;save error info
pla ;toss data
txa ;restore error
3$ ldx xsav ;restore .x (.c=1 from 'jtget')
rts


; routine to get a character from cassette buffer

jtget
jsr jtp20 ;buffer pointer wrap?
bne 1$ ;...branch if not
jsr rblk ;read next block from tape into buffer
bcs 2$ ;...branch if <stop> or error (.c=1)
lda #0
sta bufpt ;reset buffer index to beginning
beq jtget ;always

1$ lda (tape1),y ;get a character from cassette buffer
clc ;signal a good return
2$ rts

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; input from serial bus

bn30
lda status ;recall status from last serial operation
bne bn40 ;...branch if bad
jmp acptr ;ok...read a character off serial bus

bn40 lda #cr ;bad prior...fake null input
bn41 clc ; ...fake valid data
bn42 rts



; input from rs-232

bn50
jsr get232 ;get a character from rs-232 buffer
bcs bn41 ;...branch if error (.c=1, rts)
cmp #0
bne bn42 ;...branch if valid data (.c=0, rts)

lda rsstat ;null input?
and #$60 ;check for 'dsr' or 'dcd' error
bne bn40 ;...branch if error, fake a <cr>
beq bn50 ;loop until character received

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; ***********************************************
; * basout - output a character to open channel *
; * *
; * channel is determined by dflto: *
; * *
; * 0 = keyboard <invalid> *
; * 1 = cassette *
; * 2 = rs-232 *
; * 3 = video display *
; * 4-31 = serial bus *
; ***********************************************

nbsout
pha ;preserve .a (character to output)
lda dflto ;check default output device
cmp #3
bne 1$ ;...branch if not the screen

; print to video display device

pla ;restore data
jmp print ;goto editor to print to display

1$
bcc 2$ ;...branch if not serial

; output to serial bus

pla ;restore character to output
jmp ciout ;send chr out serial bus


2$
lsr a ;flag: .c=0=rs232, .c=1=cassette
pla ;restore character to output

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
casout ;////// entry from 'close' for cassette eot mark (.c=1)

sta t1 ;pass character in 't1'
txa
pha ;preserve x & y
tya
pha
bcc out232 ;...branch if rs-232 output

jsr jtp20 ;check cassette buffer index
bne 3$ ;...branch if not at end
jsr wblk ;write full buffer
bcs rstor ;...abort on <stop> key

lda #bdf ;output buffer type byte
ldy #0
sta (tape1),y

iny ;reset cassette buffer index
sty bufpt ; (.y=1)

3$
lda t1
sta (tape1),y ;put character into cassette buffer

rstoa clc ;signal good return
rstor
pla ;restore x & y
tay
pla
tax
lda t1 ;restore character for return
bcc 4$ ;...branch if no error
lda #0 ;return .a=0 & .c=1 if <stop> or error
4$ rts



; output to rs232 buffer

out232
jsr bso232 ;character to output is in 't1'
jmp rstoa ;always good

;.end

+ 94
- 0
KERNAL_C128_03/clall.src View File

@@ -0,0 +1,94 @@
.page
.subttl close all files (04/04/85)

; **********************************************
; * clall -- clear all logical files *
; * *
; * > deletes all table entries *
; * > clears serial port channels *
; * > restores default i/o channels *
; * *
; * ***WARNING: this call DOES NOT CLOSE *
; * open files!!! *
; * *
; **********************************************

nclall
lda #0
sta ldtnd ;reset table index, fall into 'clrch'






; **********************************************
; * clrch -- clear I/O channels *
; * *
; * > unlisten or untalk serial devices *
; * > restore default I/O channels *
; * *
; **********************************************

nclrch
ldx #3
cpx dflto ;check default output channel
bcs 1$ ;...branch if not serial

jsr unlsn ;unlisten serial device

1$ cpx dfltn ;check default input channel
bcs 2$ ;...branch if not serial

jsr untlk ;untalk serial device

; restore default i/o devices

2$ stx dflto ;default output channel = 3 (screen)
lda #0
sta dfltn ;default input channel = 0 (keyboard)
rts

.page
; **********************************************
; * close_all - closes all files on a *
; * given device. *
; * *
; * > search tables for given fa & do a *
; * proper close for all matches. *
; * *
; * > IF one of the closed entries is the *
; * current I/O channel THEN the default *
; * channel will be restored. *
; * *
; * entry: .a = device (fa) to close *
; * *
; **********************************************

close_all
sta fa ;save device to shut down
cmp dflto
bne 10$ ;...branch if not current output device
lda #3
sta dflto ;restore screen output
.byte $2c

10$ cmp dfltn
bne 20$ ;...branch if not current input device
lda #0
sta dfltn ;restore keyboard input

20$ lda fa
ldx ldtnd ;lat, fat, sat table index
30$ dex
bmi 40$ ;...branch if end of table
cmp fat,x
bne 30$ ;...loop until match

lda lat,x ;a match- extract logical channel data
jsr close ;close it via indirect
bcc 20$ ;always

40$ rts
;.end

+ 144
- 0
KERNAL_C128_03/close.src View File

@@ -0,0 +1,144 @@
.page
.subttl close file (03/15/85)

; ***********************************************
; * close function *
; * *
; * closes the file whose la is in .a and *
; * updates the logical file tables. *
; * *
; * the keyboard, screen and any unopened files *
; * pass thru. cassette files opened for writes *
; * are closed by writing the last buffer and *
; * (optionally) an eot mark. serial files are *
; * closed by sending a 'close' cmd if a sa was *
; * specified when it was opened. *
; * *
; * special handling for basic's dos routines: *
; * *
; * IF .c=1 AND fa=serial disk AND sa=15 *
; * THEN don't do a real close, just *
; * remove the table entry. this *
; * allows the disk cmd chnl to come *
; * and go without the disk closing *
; * ALL files on its end. *
; * *
; ***********************************************

nclose
ror svxt ;save .c for serial close
jsr jltlk ;look file up
bne clrts ;...branch if file not open (simply clc / rts)

1$ jsr getlfs ;extract table data
txa ;save table index
pha

lda fa ;check device number
beq jx150 ;...branch if keyboard (done)
cmp #3
beq jx150 ;...branch if screen (done)
bcs jx120 ;...branch if serial
cmp #2
bne jx115 ;...branch if cassette

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; close rs-232 file

pla ;restore table index
jsr jxrmv ;remove from table
jmp cln232 ;clean up rs232 for close, rts



; close cassette file

jx115 lda sa
and #$0f
beq jx150 ;...branch if tape read

jsr tapadr ;close tape write file
lda #0 ;end of file character
sec ;.c=1 for 'casout' to specify tape (not rs-232)
jsr casout ;put eof into buffer
jsr wblk ;output last tape block
bcc 1$ ;...branch if no errors

pla ;clean stack for error
lda #0 ;break key error
rts ; (.c=1)

1$ lda sa
cmp #$62
bne jx150 ;...branch if no eot mark to be written

lda #eot
jsr tapeh ;write end of tape block
jmp jx150


; close serial file

jx120 bit svxt ;special close for basic dos?
bpl jx130 ;...branch if not & do a real close
lda fa
cmp #8
bcc jx130 ;...branch if device not a serial disk
lda sa
and #$0f
cmp #$0f
beq jx150 ;...branch if sa=disk cmd chnl & skip real close

jx130
jsr clsei ;close a serial file, fall into 'jx150'

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; enter here to remove a given logical file entry from
; the table of logical, primary and secondary addresses.

jx150
pla ;restore table index

jxrmv ;////// entry for rs-232 file close
tax
dec ldtnd ;one less entry in table
cpx ldtnd
beq 1$ ;...branch if entry is last one in table (easy)

ldy ldtnd ;swap last entry with one to be closed
lda lat,y
sta lat,x
lda fat,y
sta fat,x
lda sat,y
sta sat,x

1$ clc ;signal good close
rts



lookup ;lookup logical file in table
lda #0
sta status ;clear previous i/o status
txa
jltlk
ldx ldtnd
1$ dex
bmi 2$ ;...branch if entry not found
cmp lat,x
bne 1$
2$ rts



getlfs
lda lat,x ;routine to fetch table entries
sta la
lda sat,x
sta sa
lda fat,x
sta fa ; (return with .p status of fa!)
rts

;.end

+ 690
- 0
KERNAL_C128_03/declare.src View File

@@ -0,0 +1,690 @@
.page
.subttl C/128 KERNAL & EDITOR DECLARATIONS (05/14/85)

* = $0000

d6510 *=*+1 ;6510 data direction register
r6510 *=*+1 ;6510 data register

bank *=*+1 ;monitor & long call/jump registers
pc_hi *=*+1
pc_lo *=*+1
s_reg *=*+1
a_reg *=*+1
x_reg *=*+1
y_reg *=*+1
stkptr *=*+1

* = $0090 ;kernal/editor allocations start here

status *=*+1 ;i/o operation status byte
stkey *=*+1 ;stop key flag
svxt *=*+1 ;tape temporary
verck *=*+1 ;load or verify flag
c3p0 *=*+1 ;serial buffered char flag
bsour *=*+1 ;char buffer for serial
syno *=*+1 ;cassette sync #
xsav *=*+1 ;temp for basin
ldtnd *=*+1 ;index to logical file
dfltn *=*+1 ;default input device #
dflto *=*+1 ;default output device #
prty *=*+1 ;cassette parity
dpsw *=*+1 ;cassette dipole switch
msgflg *=*+1 ;os message flag
ptr1 ;cassette error pass1
t1 *=*+1 ;temporary 1
ptr2 ;cassette error pass2
t2 *=*+1 ;temporary 2
time *=*+3 ;24 hour clock in 1/60th seconds
r2d2 ;serial bus usage
pcntr *=*+1 ;cassette stuff
bsour1 ;temp used by serial routine
firt *=*+1
count ;temp used by serial routine
cntdn *=*+1 ;cassette sync countdown
bufpt *=*+1 ;cassette buffer pointer
inbit ;rs-232 rcvr input bit storage
shcnl *=*+1 ;cassette short count
bitci ;rs-232 rcvr bit count in
rer *=*+1 ;cassette read error
rinone ;rs-232 rcvr flag for start bit check
rez *=*+1 ;cassete reading zeroes
ridata ;rs-232 rcvr byte buffer
rdflg *=*+1 ;cassette read mode
riprty ;rs-232 rcvr parity storage
shcnh *=*+1 ;cassette short cnt
sal *=*+1
sah *=*+1
eal *=*+1
eah *=*+1
cmp0 *=*+1
temp *=*+1
tape1 *=*+2 ;address of tape buffer
bitts ;rs-232 trns bit count
snsw1 *=*+1
nxtbit ;rs-232 trns next bit to be sent
diff *=*+1
rodata ;rs-232 trns byte buffer
prp *=*+1
fnlen *=*+1 ;length current file n str
la *=*+1 ;current file logical addr
sa *=*+1 ;current file 2nd addr
fa *=*+1 ;current file primary addr
fnadr *=*+2 ;addr current file name str
roprty ;rs-232 trns parity buffer
ochar *=*+1
fsblk *=*+1 ;cassette read block count
drive
mych *=*+1
cas1 *=*+1 ;cassette manual/controlled switch (updated during irq)
track
stal *=*+1
sector
stah *=*+1
memuss ;cassette load temps (2 bytes)
tmp2 *=*+2
data *=*+1 ;tape read/write data

ba *=*+1 ;bank for current load/save/verify operation
fnbank *=*+1 ;bank where current filename is found (at 'fnadr')

ribuf *=*+2 ;rs-232 input buffer pointer
robuf *=*+2 ;rs-232 output buffer pointer

.page
; 40/80 column S C R E E N E D I T O R declarations
;
; GLOBAL screen editor variables

keytab *=*+2 ;keyscan table pointer
imparm *=*+2 ;PRIMM utility string pointer

ndx *=*+1 ;index to keyboard queue
kyndx *=*+1 ;pending function key flag
keyidx *=*+1 ;index into pending function key string
shflag *=*+1 ;keyscan shift key status
sfdx *=*+1 ;keyscan current key index
lstx *=*+1 ;keyscan last key index
crsw *=*+1 ;<cr> input flag

mode *=*+1 ;40/80 column mode flag
graphm *=*+1 ;text/graphic mode flag

charen *=*+1 ;ram/rom vic character character fetch flag (bit-2)



; the following locations are shared by several editor routines

.share
sedsal *=*+2 ;pointers for MOVLIN
sedeal *=*+2 ;
sedt1 *=*+1 ;SAVPOS
sedt2 *=*+1 ;
.unshare

*=.share
keysiz *=*+1 ;programmable key variables
keylen *=*+1 ;
keynum *=*+1 ;
keynxt *=*+1 ;
keybnk *=*+1 ;
keytmp *=*+1 ;

*=.share
bitmsk *=*+1 ;temporary for TAB & line wrap routines
saver *=*+1 ;yet another temporary place to save a register

*=.unshare

.page
; LOCAL screen editor variables (swapped-out when 40/80 MODE changes)

.swapbeg
pnt *=*+2 ;pointer to current line (text)
user *=*+2 ;pointer to current line (attribute)

scbot *=*+1 ;window lower limit
sctop *=*+1 ;window upper limit
sclf *=*+1 ;window left margin
scrt *=*+1 ;window right margin

lsxp *=*+1 ;current input column start
lstp *=*+1 ;current input line start
indx *=*+1 ;current input line end

tblx *=*+1 ;current cursor line
pntr *=*+1 ;current cursor column

lines *=*+1 ;maximum number of screen lines
columns *=*+1 ;maximum number of screen columns

datax *=*+1 ;current character to print
lstchr *=*+1 ;previous character printed (for <esc> test)
color *=*+1 ;current attribute to print (default fgnd color)
tcolor *=*+1 ;saved attribute to print ('insert' & 'delete')

rvs *=*+1 ;reverse mode flag
qtsw *=*+1 ;quote mode flag
insrt *=*+1 ;insert mode flag
insflg *=*+1 ;auto-insert mode flag

locks *=*+1 ;disables <c=><shift>, <ctrl>-S
scroll *=*+1 ;disables screen scroll, line linker
beeper *=*+1 ;disables <ctrl>-G
.swapend


; remaining ZERO PAGE to be reserved for application software


.applications_zp



* = $ff

.basic_reserved_zp

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; PAGE ONE declarations (processor STACK)
;


* = $0100

bad *=*+1 ;tape read errors (this area also used by basic)









; PAGE TWO declarations (input buffer & kernal RAM code)
;


* = $0200

buf *=*+161 ;input buffer (used by basic & monitor)


* = $02a2

fetch *=*+13 ;LDA(-),y from any bank
fetvec = fetch+8

stash *=*+15 ;STA(-),y to any bank
stavec = stash+10

cmpare *=*+15 ;CMP(-),y to any bank
cmpvec = cmpare+10

jsrfar *=*+22 ;JSR xxxx to any bank & return

jmpfar *=*+25 ;JMP xxxx to any bank


; NOTE: basic indirect vectors start at $2fc !!



; ***** ALL UNUSED RAM LOCATIONS BELOW $1300 ARE RESERVED *****
; ***** FOR SYSTEM USE AND MUST NOT BE USED BY APPLICATIONS *****

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; PAGE THREE declarations (indirect vectors, kernal tables, basic RAM code)

* = $02fc ;basic indirect vectors

* = $0314 ;kernal indirect vectors

iirq *=*+2 ;irq
ibrk *=*+2 ;brk
inmi *=*+2 ;nmi
iopen *=*+2 ;
iclose *=*+2 ; conforms to kernal spec 8/19/80
ichkin *=*+2
ickout *=*+2
iclrch *=*+2
ibasin *=*+2
ibsout *=*+2
istop *=*+2
igetin *=*+2
iclall *=*+2
exmon *=*+2 ;monitor command indirect
iload *=*+2
isave *=*+2

;editor indirect vectors

ctlvec *=*+2 ;editor: print 'contrl' indirect
shfvec *=*+2 ;editor: print 'shiftd' indirect
escvec *=*+2 ;editor: print 'escape' indirect
keyvec *=*+2 ;editor: keyscan logic indirect
keychk *=*+2 ;editor: store key indirect

decode *=*+12 ;vectors to keyboard matrix decode tables




* = $34a

keyd *=*+10 ;irq keyboard buffer

tabmap *=*+10 ;bitmap of tab stops
bitabl *=*+4 ;bitmap of line wraps

lat *=*+10 ;logical file numbers
fat *=*+10 ;primary device numbers
sat *=*+10 ;secondary addresses



* = $0380 ;basic ram code here

* = $03f0 ;basic/kernal dma request ram code
do_dma
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; PAGE FOUR & HIGHER declarations (****** beginning of bankable ram ******)
;

* = $0400 ;video matrix #1: vic 40-column text screen

vicscn *=*+1024

* = $0800 ;basic run-time stack (512 bytes)



; ABSOLUTE kernal variables
;

* = $0a00

system_vector *=*+2 ;vector to restart system (usually BASIC warm start)
dejavu *=*+1 ;kernal warm/cold initialization status byte
palnts *=*+1 ;pal/ntsc system flag
init_status *=*+1 ;flags reset vs. nmi status for initialization routines

memstr *=*+2 ;pointer to bottom of available memory in system bank
memsiz *=*+2 ;pointer to top of available memory in system bank

irqtmp *=*+2 ;tape handler preserves irq indirect here
caston *=*+1 ;tod sense during tape operations
kika26 *=*+1 ;tape read temporary
stupid *=*+1 ;tape read d1irq indicator

timout *=*+1 ;fast serial timeout flag

enabl *=*+1 ;rs-232 enables
m51ctr *=*+1 ;rs-232 control register
m51cdr *=*+1 ;rs-232 command register
m51ajb *=*+2 ;rs-232 user baud rate
rsstat *=*+1 ;rs-232 status register
bitnum *=*+1 ;rs-232 number of bits to send
baudof *=*+2 ;rs-232 baud rate full bit time (created by OPEN)

ridbe *=*+1 ;rs-232 input buffer index to end
ridbs *=*+1 ;rs-232 input buffer index to start

rodbs *=*+1 ;rs-232 output buffer index to start
rodbe *=*+1 ;rs-232 output buffer index to end

serial *=*+1 ;fast serial internal/external flag

timer *=*+3 ;decrementing jiffie register

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; GLOBAL ABSOLUTE screen editor declarations

xmax *=*+1 ;keyboard queue maximum size
pause *=*+1 ;<ctrl>-S flag
rptflg *=*+1 ;enable key repeats
kount *=*+1 ;delay between key repeats
delay *=*+1 ;delay before a key starts repeating
lstshf *=*+1 ;delay between <C=><shft> toggles

blnon *=*+1 ;vic cursor mode (blinking, solid)
blnsw *=*+1 ;vic cursor disable
blnct *=*+1 ;vic cursor blink counter
gdbln *=*+1 ;vic cursor character before blink
gdcol *=*+1 ;vic cursor color before blink

curmod *=*+1 ;vdc cursor mode (when enabled)

vm1 *=*+1 ;vic text screen/character base pointer
vm2 *=*+1 ;vic bit-map base pointer
vm3 *=*+1 ;vdc text screen base
vm4 *=*+1 ;vdc attribute base

lintmp *=*+1 ;temporary pointer to last line for LOOP4
sav80a *=*+1 ;temporary for 80-col routines
sav80b *=*+1 ;temporary for 80-col routines
curcol *=*+1 ;vdc cursor color before blink
split *=*+1 ;vic split screen raster value

fnadrx *=*+1 ;save .x during bank operations
palcnt *=*+1 ;counter for pal systems (jiffie adjustment)
speed *=*+1 ;save system speed during tape & serial bus ops
sprites *=*+1 ;save sprite enables during tape & serial bus ops
blanking *=*+1 ;save blanking status during tape ops
hold_off *=*+1 ;flag set by user wanting full control of vic reserved

ldtb1_sa *=*+1 ;high byte of sa of vic screen (use with vm1 to move screen)

clr_ea_lo *=*+1 ;????? 8563 block fill kludge
clr_ea_hi *=*+1 ;????? 8563 block fill kludge

.page
; LOCAL screen editor variable swap area
;
* = $0a40
.swapout ;local variables

* = $0a60
.swapmap ;local tab map & wrap tables


; MONITOR absolute declarations
;
* = $0a80
.monitor_abs


; FUNCTION KEY ROM CARD tables
;
* = $0ac0

curbnk *=*+1 ;current function key rom bank being polled
pat *=*+4 ;physical address table (id's of logged-in cards)
dk_flag *=*+1 ;reserved for foreign screen editors


; ***** ALL UNUSED RAM LOCATIONS BELOW $1300 ARE RESERVED *****
; ***** FOR SYSTEM USE AND MUST NOT BE USED BY APPLICATIONS *****

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
* = $0b00

bufsz =192 ;tape buffer size

tbuffr *=*+bufsz ;cassette buffer

* = $0c00 ;rs-232 input buffer
rs232i

* = $0d00 ;rs-232 output buffer
rs232o

* = $0e00 ;sprite definition area (must be below $1000 !!)

* = $1000 ;programmable function key definitions

pkynum =10 ;number of definable keys (f1-f8, <shft>run, help)
pkybuf *=*+pkynum ;programmable function key lengths table
pkydef *=*+256-pkynum ;programmable function key strings

* = $1100 ;cp/m reset code, basic dos & vsp variables

* = $1200 ;basic absolute variables

* = $1300 ;unallocated absolute ram

.applications_abs

* = $1800 ;reserved for function key software applications

* = $1c00 ;video matrix #2 (1KB, bitmap color, if allocated)

rambot ;basic text starts here (kernal sets 'membot' here)

* = $2000 ;vic bitmap (8KB, if allocated)

* = $4000 ;************** beginning of rom over ram *************

* = $fc80 ;foreign language reserved rom (thru $feff)

.foreign_rom

* = $ff05 ;kernal interrupt ram code here (all ram banks)

* = $ffd0 ;cp/m transfer-processor-control ram code here (first ram bank only)

.cpm_ram_code

* = $fff5 ;'CBM' key goes here in ram1

locker

* = $fffa ;kernal hardware interrupt ram vectors here (all ram banks)
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
;//////////////////// I / O D E V I C E M A P S \\\\\\\\\\\\\\\\\\\


vicchr = $d000 ;vic character rom

vicreg = $d000 ;vic registers

sidreg = $d400 ;sid registers

mmu_lo = $d500 ;mmu primary registers

vdc = $d600 ;8563 registers

viccol = $d800 ;vic color nybbles

cia1 = $dc00 ;6526 #1

cia2 = $dd00 ;6526 #2

io1 = $de00 ;expansion i/o slot (reserved)

io2 = $df00 ;expansion i/o slot (reserved: optional DMA ctlr for expansion ram)

mmu_hi = $ff00 ;mmu secondary registers (*** not in i/o block! ***)

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; c/128 memory management unit
; implements c/128, c/64, & cp/m 3.0 modes
;

* = mmu_lo

mmucrl *=*+1 ;configuration register (primary)
pcra *=*+1 ;preconfiguration register a
pcrb *=*+1 ;preconfiguration register b
pcrc *=*+1 ;preconfiguration register c
pcrd *=*+1 ;preconfiguration register d
mmumcr *=*+1 ;mode configuration register
mmurcr *=*+1 ;ram configuration register
mmup0l *=*+1 ;page 0 pointer low
mmup0h *=*+1 ;page 0 pointer high
mmup1l *=*+1 ;page 1 pointer low
mmup1h *=*+1 ;page 1 pointer high
mmuver *=*+1 ;mmu version number (*** prototype: reset latch ***)

* = mmu_hi

mmucr *=*+1 ;configuration register (secondary)
lcra *=*+1 ;load configuration register a
lcrb *=*+1 ;load configuration register b
lcrc *=*+1 ;load configuration register c
lcrd *=*+1 ;load configuration register d






; c/128 80-column video display controller
;

* = vdc

vdcadr *=*+1 ;8563 address register
vdcdat *=*+1 ;8563 data register

vdcscn = $0000 ;8563 80-column screen (2KB)
vdccol = $0800 ;8563 attribute area (2KB)
vdcchr = $2000 ;8563 character ram (4KB: 256 chrs, 8x16)

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; 6526 cia complex interface adapter #1
; keyboard / joystick / paddles / lightpen / fast disk
;
; pra0 : keybd output c0 / joystick #1 direction
; pra1 : keybd output c1 / joystick #1 direction
; pra2 : keybd output c2 / joystick #1 direction / paddle fire button
; pra3 : keybd output c3 / joystick #1 direction / paddle fire button
; pra4 : keybd output c4 / joystick #1 fire button
; pra5 : keybd output c5 /
; pra6 : keybd output c6 / / select port #1 paddles
; pra7 : keybd output c7 / / select port #2 paddles
;
; prb0 : keybd input r0 / joystick #2 direction /
; prb1 : keybd input r1 / joystick #2 direction / paddle fire button
; prb2 : keybd input r2 / joystick #2 direction / paddle fire button
; prb3 : keybd input r3 / joystick #2 direction /
; prb4 : keybd input r4 / joystick #2 fire button
; prb5 : keybd input r5 /
; prb6 : keybd input r6 / timer b: toggle/pulse output
; prb7 : keybd input r7 / timer a: toggle/pulse output
;
; timer 1 & cra : fast disk
; timer 2 & crb : cassette
;
; tod :
; sdr :
; icr :

* = cia1 ;device #1: 6526

colm
d1pra *=*+1 ;keyboard outputs / joystick / paddles / lightpen
rows
d1prb *=*+1 ;keyboard inputs / joystick / paddles
d1ddra *=*+1
d1ddrb *=*+1
d1t1l *=*+1
d1t1h *=*+1
d1t2l *=*+1
d1t2h *=*+1
d1tod1 *=*+1
d1tods *=*+1
d1todm *=*+1
d1todh *=*+1
d1sdr *=*+1
d1icr *=*+1
d1cra *=*+1
d1crb *=*+1

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; 6526 cia complex interface adapter #2
; user port / rs232 / serial bus / vic memory / nmi
;
; pra0 : va14
; pra1 : va15
; pra2 : rs232 DATA output
; pra3 : serial ATN output
; pra4 : serial CLK output
; pra5 : serial DATA output
; pra6 : serial CLK input
; pra7 : serial DATA input
;
; prb0 : user port / rs232 received data
; prb1 : user port / rs232 request to send
; prb2 : user port / rs232 data terminal ready
; prb3 : user port / rs232 ring indicator
; prb4 : user port / rs232 carrier detect
; prb5 : user port
; prb6 : user port / rs232 clear to send
; prb7 : user port / rs232 data set ready
;
; timer 1 & cra : rs232 baud rate
; timer 2 & crb : rs232 bit check
;
; tod :
; sdr :
; icr : nmi (/irq)

* = cia2 ;device #2: 6526

d2pra *=*+1 ;serial bus / rs232 / va14,15
d2prb *=*+1 ;user port / rs232
d2ddra *=*+1
d2ddrb *=*+1
d2t1l *=*+1
d2t1h *=*+1
d2t2l *=*+1
d2t2h *=*+1
d2tod1 *=*+1
d2tods *=*+1
d2todm *=*+1
d2todh *=*+1
d2sdr *=*+1
d2icr *=*+1 ;nmi's
d2cra *=*+1
d2crb *=*+1

timrb = $19 ;6526 crb enable one-shot tb
.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; c/128 DMA controller for expansion RAM access (***PRELIMINARY***)
;
; (optional device mapped into IO2 block via system Expansion Port)
;


* = io2


dma_st *=*+1 ;DMA controller status register
dma_cmd *=*+1 ;DMA controller command register
dma_adl *=*+1 ;lsb of internal (c128) address to access
dma_adh *=*+1 ;msb of internal (c128) address to access
dma_lo *=*+1 ;lsb of external expansion ram to access
dma_hi *=*+1 ;msb of external expansion ram to access
dma_bnk *=*+1 ;64K external ram bank
dma_dal *=*+1 ;lsb of byte count
dma_dah *=*+1 ;msb of byte count (block count)
dma_sum *=*+1 ;checksum of last data transfer ????????????
dma_ver *=*+1 ;DMA version & memory limits

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; MISCELLANEOUS KERNAL & EDITOR EQUATES

eot =5 ;end of tape
blf =1 ;basic load file
bdf =2 ;basic data file
plf =3 ;fixed program type
bdfh =4 ;basic data file header



bakcol =11 ;VIC background screen color
forcol =13 ;VIC foreground screen color
bodcol =13 ;VIC screen border color



lf =10 ;line feed
cr =13 ;carriage return
esc =27 ;escape
space =32 ;space
quote =34 ;dbl quote


sysbnk = %00000000 ;mmu configuration: ram0, system roms, i/o


; configurations per 'config' table:

ram0 = 0 ;ram0, no roms, no i/o
ram1 = 1 ;ram1, no roms, no i/o
romram0 = 15 ;ram0, system roms, i/o (corresponds to 'sysbnk')

;.end

+ 47
- 0
KERNAL_C128_03/disclaim.src View File

@@ -0,0 +1,47 @@
.subttl *** COPYRIGHT (C) 1985 by COMMODORE BUSINESS MACHINES, INC. ***

; ******************************************************************
; * // *
; * CCCCCCC // 111 2222222 8888888 *
; * CCC CCC // 1111 222 222 888 888 *
; * CCC // 111 222 888 888 *
; * CCC // 111 222 88888 *
; * CCC // 111 222 888 888 *
; * CCC CCC // 111 222 222 888 888 *
; * CCCCCCC // 1111111 222222222 8888888 *
; * // *
; * *
; * KKK KKK EEEEEEEEE RRRRRRRR NNN NN AAA LLL *
; * KKK KKK EEE RRR RRR NNNN NN AA AA LLL *
; * KKK KKK EEE RRR RRR NNNNN NN AAA AAA LLL *
; * KKKKK EEEEEE RRRRRRRR NNN NN NN AAAAAAAAA LLL *
; * KKK KKK EEE RRR RRR NNN NNNN AAA AAA LLL *
; * KKK KKK EEE RRR RRR NNN NNN AAA AAA LLL *
; * KKK KKK EEEEEEEEE RRR RRR NNN NN AAA AAA LLLLLLL *
; * *
; * *
; * COPYRIGHT (C)1985 BY COMMODORE BUSINESS MACHINES, INC. *
; * *
; ******************************************************************
; ******************************************************************
; * *
; * THIS LISTING CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION *
; * OF CBM, INC. REPRODUCTION, DISSEMINATION OR DISCLOSURE TO *
; * OTHERS WITHOUT EXPRESS WRITTEN PERMISSION IS PROHIBITED. THIS *
; * SOFTWARE IS INTENDED FOR USE IN COMMODORE C/128 SYSTEMS ONLY. *
; * *
; * THE INFORMATION IN THIS DOCUMENT IS SUBJECT TO CHANGE *
; * WITHOUT NOTICE. *
; * *
; * NO RESPONSIBILITY IS ASSUMED FOR THE RELIABILITY OF THIS *
; * SOFTWARE. *
; * *
; ******************************************************************


;.end


+ 34
- 0
KERNAL_C128_03/entries.src View File

@@ -0,0 +1,34 @@
.page
.subttl C/128 KERNAL & EDITOR ENTRIES (12/18/84)

; entry definitions for c/128 EDITOR

cint = $c000 ;editor: initialization
display = $c003 ;editor: display chr in .a, color in .x
lp2 = $c006 ;editor: get a key from irq buffer
loop5 = $c009 ;editor: get a chr from screen
print = $c00c ;editor: print a chr to screen
scrorg = $c00f ;editor: return screen size of local display device
key = $c012 ;editor: general key scan
repeat = $c015 :editor: repeat key logic & 'ckit2' to store decoded key
plot = $c018 ;editor: read or set cursor position
cursor = $c01b ;editor: move 8563 hardware cursor
escape = $c01e ;editor: escape sequence handler, chr in .a
pfkey = $c021 ;editor: program function key
edirq = $c024 ;editor: irq entry
dlchr = $c027 ;editor: download 80-col character ram
swapper = $c02a ;editor: swap to alternate display device

; entry definitions for c/128 MONITOR

monitr = $b000 ;monitor: call entry
monbrk = $b003 ;monitor: brk entry
moncmd = $b006 ;monitor: monitor command parser

; entry definitions for c/128 BASIC

basic = $4000 ;basic: cold entry
basicw = $4003 ;basic: warm entry
basirq = $4006 ;basic: irq entry

;.end

+ 68
- 0
KERNAL_C128_03/errors.src View File

@@ -0,0 +1,68 @@
.page
.subttl error handler (09/17/84): c/128

; *******************************************************
; * stop *
; * *
; * >check stop key flag and return = if true. if true *
; * then close active channels & flush keyboard queue *
; * *
; * >note: returns scan from last keyboard row in .a *
; *******************************************************

nstop
lda stkey ;value of last row
cmp #$7f ;check stop key position
bne 1$ ;not down
php
jsr clrch ;clear channels
sta ndx ;flush queue
plp
1$ rts

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; *******************************************************
; * error handler *
; * *
; * > prints kernal error message if display enabled. *
; * > returns with error # in .a and .c=1 *
; *******************************************************

error1 lda #1 ;too many files
.byte $2c
error2 lda #2 ;file open
.byte $2c
error3 lda #3 ;file not open
.byte $2c
error4 lda #4 ;file not found
.byte $2c
error5 lda #5 ;device not present
.byte $2c
error6 lda #6 ;not input file
.byte $2c
error7 lda #7 ;not output file
.byte $2c
error8 lda #8 ;missing file name
.byte $2c
error9 lda #9 ;bad device #
.byte $2c
error16 lda #16 ;out of memory

pha ;error number on stack
jsr clrch ;restore i/o channels

ldy #ms1-ms1
bit msgflg
bvc 1$ ;...branch if display disabled

jsr msg ;print 'i/o error #'
pla
pha
ora #$30 ;make error # ascii
jsr bsout ;print it

1$ pla ;restore error code
sec ;signal error
rts

;.end

+ 516
- 0
KERNAL_C128_03/init.src View File

@@ -0,0 +1,516 @@
.page
.subttl C/128 KERNAL INITIALIZATION (04/29/85)

;//////////// S Y S T E M I N I T I A L I Z A T I O N \\\\\\\\\\\\

start ldx #$ff ;normal /reset entry
sei
txs
cld

lda #0
sta mmucr ;configure system map: c/128 mode, i/o in, ram0
ldx #10
10$ lda mmutbl,x
sta mmu_lo,x ;reset all mmu registers
dex
bpl 10$
sta init_status ;flags a reset (vs. nmi) for initialization routines

jsr install ;download kernal ram code
jsr secure ;an ounce of protection for ram-based software
jsr poll ;examine cartridge slots (& go if autostart)
jsr ioinit ;initialize I/O devices, determine NTSC or PAL

jsr ud60 ;test for <run/stop> AND cold reset
pha ; (save for 'jmp to monitor/c64 mode' test later)
bmi 20$ ;...branch to full init if <run/stop> not down
lda #$a5
cmp dejavu ;test for 'cold' or 'warm' reset
beq 30$ ;...branch to partial init if 'warm'

20$ jsr ramtas ;determine ram size, init system ram & ram code
30$ jsr restor ;initialize kernal indirect vectors

jsr cint ;initialize video displays (40 & 80)
pla
cli ;start system
bmi 40$ ;...branch if no <run/stop> key at <reset>

jmp monitr ;...start MONITOR

40$ cmp #$df
beq 50$ ;...branch if <C=> key at <reset>

jmp (system_vector) ;...start BASIC (usually)
50$ jmp c64mode ;...start C/64 mode



mmutbl .byte $00,$00,$00,$00,$00,$bf,$04,$00,$00,$01,$00

.page
;////////////////////// R E S T O R E \\\\\\\\\\\\\\\\\\\\\\\\\\

restor ;initialize kernal system indirect vectors
ldx #<vectss
ldy #>vectss
clc

; vector - set kernal indirect and vectors (user)
;
; enter with .c=0 to init, .c=1 to copy

vector
stx tmp2 ;x & y specify address low & high
sty tmp2+1
ldy #vectse-vectss-1

1$ lda iirq,y ;get from storage
bcs 2$ ;...c=1, want storage to user
lda (tmp2),y ;...c=0, want user to storage

2$ sta iirq,y ;put in storage
bcc 3$
sta (tmp2),y ;put in user

3$ dey
bpl 1$
rts

vectss
.word nirq ;irq handler
.word monbrk ;brk handler
.word nnmi ;nmi handler
.word nopen ;open
.word nclose ;close
.word nchkin ;chkin
.word nckout ;ckout
.word nclrch ;clrch
.word nbasin ;basin
.word nbsout ;bsout
.word nstop ;stop key scan
.word ngetin ;getin
.word nclall ;clall
.word moncmd ;monitor command parser
.word nload ;load
.word nsave ;save
vectse

.page
;/////////////////////// R A M T A S \\\\\\\\\\\\\\\\\\\\\\\\\\\

ramtas ;ram test and system ram initialization
lda #0
tay
1$ sta $0002,y ;clear all page 0 ram
iny
bne 1$

ldy #>tbuffr
sty tape1+1 ;allocate cassette & rs-232 buffers
sta tape1
ldy #>rs232i
sty ribuf+1
sta ribuf
ldy #>rs232o
sty robuf+1
sta robuf

clc ;set top of memory
ldy #>mmucr
ldx #<mmucr
jsr settop

ldy #>rambot ;set bottom of memory
ldx #<rambot
jsr setbot

ldy #>basic ;init system vector to basic cold start
ldx #<basic
sty system_vector+1
stx system_vector

lda #$a5 ;system ram now initialize, set 'warm' flag
sta dejavu
rts

.page
;/////////////////////// I N S T A L L \\\\\\\\\\\\\\\\\\\\\\\\\\

; initialize top of ram in each bank (assumes maximum of 4-64k ram banks)

install
ldy #3 ;for banks 0 to 3

1$ lda 10$,y ;get configuration for current bank
sta mmucr ;configure & copy kernal rom code (assumes bleed-thru)

ldx #.interrupt_end-.interrupt_code-1
2$ lda .interrupt_code,x
sta .interrupt_code,x
dex
bpl 2$

ldx #5 ;also copy nmi, reset, irq hardware vectors
3$ lda $fffa,x
sta $fffa,x
dex
bpl 3$

dey
bpl 1$ ;loop until done all banks (last bank must be ram0)


; initialize common ram code area in bottom of ram bank 0


ldx #dl_end-dl_beg-1
4$ lda dl_beg,x
sta fetch,x ;download 'FETCH, STASH, CMPARE, JSRFAR, JMPFAR' ram code
dex
bpl 4$

ldx #dl_dma-dl_end-1
5$ lda dl_end,x
sta do_dma,x ;download 'DO_DMA' ram code (***preliminary***)
dex
bpl 5$


rts



10$ .byte $00,$40,$80,$c0 ;configurations for system roms & ram0/1/2/3

.page
;//////////////////////// I O I N I T \\\\\\\\\\\\\\\\\\\\\\\\\\\

ioinit
lda #$7f ;kill timer interrupts
sta d1icr
sta d2icr
sta d1pra ;turn on stop key

lda #%00001000 ;shut off timers
sta d1cra
sta d2cra
sta d1crb
sta d2crb

ldx #0
stx d1ddrb ;set up keyboard inputs
stx d2ddrb ;set up user port (no rs-232)
dex ;($ff)
stx d1ddra ;set up keyboard outputs

lda #%00000111 ;set serial/va14/15 (clkhi)
sta d2pra
lda #%00111111 ;set serial in/out, va14/15out
sta d2ddra
lda #%11100011 ;initialize 6510 port: kybd, cassette, vic control
sta r6510
lda #%00101111 ;6510 ddr
sta d6510

ldx #$ff ;setup for PAL/NTSC test
10$ lda vicreg+17
bpl 10$ ;...branch until raster at bottom
20$ lda #$08
cmp vicreg+18
bcc 30$ ;...branch if >264: PAL system
lda vicreg+17
bmi 20$ ;...branch until raster wraps to top
inx ;NTSC system
30$ stx palnts

lda #0
sta speed ;init 1/2MHz flag
sta blanking ;clear vic blanking bit used by tape ops
sta irqtmp+1 ;clear irq redirection flag used by tape ops
sta hold_off ;clear user vic control flag
sta palcnt ;init counter for pal adjustment
sta dfltn ;set default input device (keyboard)
lda #3
sta dflto ;set default output device (screen)

.page
ldx #48
40$ lda victbl,x ;initialize vic
sta vicreg,x
dex
bpl 40$


ldx #0 ;initialize 8563 (NTSC)
jsr vdc_init
lda vdcadr
and #$07
beq 50$ ;...branch if old 8563R7

ldx #vdcpat-vdctbl
jsr vdc_init ;...else apply -R8 patches

50$ bit palnts
bpl 60$ ;...branch if NTSC

ldx #vdcpal-vdctbl
jsr vdc_init ;...else apply PAL patches


60$ lda init_status
bmi 70$ ;...branch if character set installed (this is an nmi or user call)
jsr dlchr ;initialize 8563 character definitions
lda #$80
ora init_status
sta init_status ;flag installation

ldx #$ff
ldy #$ff
65$ dey ;kludge to provide delay for vic-1541 reset to finish (only during reset)
bne 65$ ; (delay >300ms)
dex
bne 65$

70$ lda #0
ldx #24
80$ sta sidreg,x ;initialize sid
dex
bpl 80$

.page
iokeys ;////// entry from 'tape write' to restore normal irq's
ldx #$01
stx vicreg+26 ;enable vic raster irq (60HZ keyscan)

dex
stx serial ;reset fast serial flags to slow
stx enabl ;reset rs232 enable flag

dex
stx d1t2l ;unleash one timer for basic (random # generator)
stx d1t2h

ldx #%00010001
stx d1crb

jsr spinp ;toggle serial i/o (for fast drives)
jsr spout ;...out
jsr spinp ;...in
jmp clklo ;release the clock line & rts








vdc_init
ldy vdctbl,x ;get 8563 register #
bmi 10$ ;...branch if end-of-table
inx
lda vdctbl,x ;get data for this register
inx
sty vdcadr
sta vdcdat
bpl vdc_init ;always

10$ inx
rts

.page
;//////////////////////// S E C U R E \\\\\\\\\\\\\\\\\\\\\\\\\\\
;
; 1/ IF the system has just powered up, install a key & init vector.
; This is recognized by the missing 'CBM' key planted in 2nd RAM bank.
;
; 2/ IF a RESET entry (i.e., key was found) JMP indirectly
; through the SYSTEM vector in the 2nd RAM bank.
; a/ At power-up the Kernal will initialize this vector to
; affect a return to the normal INIT mechanisms.
; b/ All normal system paths to C64 mode redirect this vector
; to cause a return to C64 mode upon RESET, thus protecting
; most existing C64 software and necessitating a power-down
; sequence, destroying RAM contents, to escape.
; c/ C128 users may aim this vector much the same way the NMI
; indirect is manipulated, thus providing C128 software with
; RESET control and the means to protect themselves.
;
; Note that the jump thru the SYSTEM vector occurs from within a
; Kernal ROM subroutine. An RTS will continue normal initialization.
;

secure
ldx #<locker
ldy #>locker
stx tmp2
sty tmp2+1
lda #tmp2
sta fetvec
ldy #2
1$ ldx #$7f ;the key is in ram1
jsr fetch ;look for key
cmp cbmkey,y
bne c128mode ;not there, can only assume this is power-up
dey
bpl 1$

ldx #<system ;the vector is in ram1- move it to common ram
ldy #>system
stx tmp2
sty tmp2+1
ldy #1
2$ ldx #$7f
jsr fetch
sta bank,y
dey
bpl 2$
jmp (bank) ;got the key, take 'er out for a spin!

.page

c128mode
lda #$40 ;want ram1
sta mmucr

lda #<c128mode ;default 'system' /reset vector points to here!
ldy #>c128mode
sta system ; (still bleeding thru)
sty system+1

ldx #3 ;plant 'CBM' key in ram1
1$ lda cbmkey-1,x
sta locker-1,x ; (bleeds thru)
dex
bne 1$

stx mmucr ;restore system configuration (.x=0) & continue initialization
rts

.page
;//////////////////////// P O L L \\\\\\\\\\\\\\\\\\\\\\\\\\\
;
; 1/ IF any C64 cards installed GOTO C64 mode now. They are
; recognized by either /game or /exrom lines pulled low.
;
; 2/ IF any C128 cards installed THEN:
; a/ log its ID into the Physical Address Table (PAT).
; b/ IF its ID=1 CALL its cold_start vector (it may RTS).
;
; note: there are 4 slots (2 internal, 2 external, 16k each).
; the signature must match the following format:
;
; $x000 --> cold_start vector
; $x003 --> warm_start vector
; $x006 --> ID. (any ID=1 indicates an auto-start card)
; $x007 --> CBM
;
; where x= $8000 and $C000 16k blocks.
;
; non-autostart cards & any autostarters RTSing to POLL
; will be called by PHOENIX routine after kernal inits.


poll lda mmumcr ;(port sensitized prior to call!)
and #$30 ;examine /game & /exrom lines for c/64 cartridges
cmp #$30
beq poll_128 ;...branch if none


c64mode
lda #%11100011 ;initialize 6510 port
sta r6510
lda #%00101111 ;6510 ddr
sta d6510

ldx #c64end-c64beg

1$ lda c64beg-1,x ;download 'go_to_64_mode_code'
sta bank-1,x
dex
bne 1$
stx vicreg+48 ;force 1MHz mode
jmp bank ;abracadabra, we're a 64!



c64beg
lda #$f7 ;be sure /fsdir bit clear!
sta mmumcr ;tell mmu to configure system like a c/64
jmp ($fffc) ;simulate a reset
c64end

.page
poll_128
ldx #3 ;poll for c128 function key roms, in following order:
stx curbnk ; 1/ext-lo 2/ext-hi 3/int-lo 4/int-hi
lda #0
1$ sta pat,x ;initialize 'Physical Address Table'
dex
bpl 1$

sta ptr1 ;addr lo ($00 always)

2$ ldy #9
ldx curbnk
lda fkaddr,x
sta ptr1+1 ;addr hi (function rom high or low)
lda fkbank,x
sta bank ;bank (function rom internal or external)

3$ ldx bank
lda #ptr1
jsr indfet ; LDA (ptr1),Y from bank BA
cmp cbmkey-7,y
bne 4$ ;...branch if no key found here
dey
cpy #7
bcs 3$ ;...loop until entire key matches

ldx bank ;key found, log it in
lda #ptr1
jsr indfet ;id
ldx curbnk
sta pat,x
cmp #1
bne 4$ ;...branch if not an auto-start function rom

lda ptr1
ldy ptr1+1
sta pc_lo
sty pc_hi
jsr jsrfar ;call its cold-start routine

4$ dec curbnk
bpl 2$ ;...loop until all function roms polled
rts


fkaddr .byte $c0,$80,$c0,$80 ;function rom lo/hi table
fkbank .byte 4, 4, 8, 8 ;function rom banks (see 'config')
cbmkey .byte 'CBM' ;key

.page

victbl .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;reg 0-16 (sprite pos)
.byte $1b,$ff,0,0,0,$08,0,$14,$ff,1,0,0,0,0,0 ;reg 17-31 (control)
.byte bodcol,bakcol,1,2,3,1,2,0,1,2,3,4,5,6,7 ;reg 32-46 (colors)
.byte $ff,$fc ;reg 47-48 (keylines & 2MHz)



vdctbl .byte 0,$7e, 1,$50, 2,$66, 3,$49, 4,$20, 5,$00, 6,$19, 7,$1d ;8563 NTSC
.byte 8,$00, 9,$07,10,$20,11,$07,12,$00,13,$00,14,$00,15,$00
.byte 20,$08,21,$00,23,$08,24,$20,25,$40,26,$f0,27,$00,28,$20
.byte 29,$07,34,$7d,35,$64,36,$05,22,$78,$ff

vdcpat .byte 25,$47, $ff ;8563 patches

vdcpal .byte 4,$27, 7,$20,$ff ;8563 PAL

;.end

+ 124
- 0
KERNAL_C128_03/interrupt.src View File

@@ -0,0 +1,124 @@
.page
.subttl interrupt handler (03/11/85)

;///////////////// N M I I N T E R R U P T C O D E \\\\\\\\\\\\\\\\\\\\

nnmi
cld ;just in case there's a nerd out there
lda #$7f
sta d2icr ;disable nmi's by clearing mask register
ldy d2icr ; (must save icr in .y!)
bmi 1$ ;...branch if interrupt came from here (not <restore>)

jsr ud60 ;sets up keyports to last row (preserve .y!)
jsr stop ;scan for <stop> key (preserve .y!)
bne 1$ ;...branch if no <stop> key

jsr restor ;restore system indirects
jsr ioinit ;restore default i/o parameters
jsr cint ;restore default screen parameters

jmp (system_vector) ;<stop><restore> key convention- warm start BASIC

1$ jsr nmi232 ;go handle an rs-232 interrupt
jmp prend ;rti




;///////////// I R Q & B R K I N T E R R U P T C O D E \\\\\\\\\\\\

nirq ;////// kernal irq handler
cld ;just in case there's a nerd out there
jsr edirq ;blink cursor, scan keyboard, split screen stuff
bcc 1$ ;...branch if irq was only for split screen handler

jsr udtim ;update jiffie clock & scan stop key (ud60)
jsr tapeirq ;check cassette switches
lda d1icr ;clear alien irqs?

lda init_status
lsr a
bcc 1$ ;...branch if basic not installed
jsr basirq ;do basic's irq stuff

1$ jmp prend ;rti


.kernal_mid_check

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

;////////////// I N T E R R U P T D I S P A T C H C O D E \\\\\\\\\\\\\

* = $ff05

.interrupt_code ;this code is copied into each ram bank at this address

nmi
sei ;disable irq's (could interfere with cassette ops)
pha ;save registers
txa
pha
tya
pha
lda mmucr ;save current memory configuration
pha
lda #sysbnk ;configure memory for system
sta mmucr
jmp (inmi) ;nmi indirect




irq ;////// hardware irq always comes here!
pha
txa
pha
tya
pha
lda mmucr ;save current memory configuration
pha
lda #sysbnk ;configure memory for system
sta mmucr

tsx ;determine if interrupt was an irq or brk
lda $105,x ;get processor status at interrupt time
and #$10 ;test break flag
beq 1$
jmp (ibrk) ;...taken if brk (goto monitor)

1$ jmp (iirq) ;...taken if irq

.page
prend ;////// entry from other kernal routines
pla
sta mmucr ;restore memory configuration
pla
tay ;restore registers
pla
tax
pla
rti





reset
lda #sysbnk ;force system configuration
sta mmucr
jmp start ;a new beginning...



.interrupt_end
.kernal_top_check



; * = $ffd0
;
;.cpm_ram ;cp/m puts its transfer-processor-control code here in first ram bank

;.end

+ 40
- 0
KERNAL_C128_03/kernal.src View File

@@ -0,0 +1,40 @@
.nam C/128 KERNAL (318020_03 RELEASE: 05/14/85)
.forml 60

.include disclaim
.include sysdoc
.include relnotes
.include declare
.include entries

*=$e000

.kernal_beg_check

.include init
.include serial
.include rs232xmit
.include rs232rcvr
.include rs232io
.include rs232nmi
.include tapefile
.include tapectlr
.include taperead
.include tapewrite
.include tapeirq
.include channelio
.include open
.include openchnl
.include close
.include clall
.include load
.include save
.include time
.include errors
.include messages
.include routines
.include interrupt ;contains an ORG $ff05 (& upper limit @ $fc80)
.include vectors

.subttl KERNAL CROSS REFERENCE
.end

+ 496
- 0
KERNAL_C128_03/load.src View File

@@ -0,0 +1,496 @@
.page
.subttl load (03/29/85)

; **********************************************
; * load memory from mass storage *
; * *
; * fa: 0= keyboard <invalid> *
; * 1= cassette *
; * 2= screen <invalid> *
; * 3= rs-232 <invalid> *
; * 4-31= serial *
; * *
; * sa: 0= alternate load *
; * (x,y= starting addr) *
; * 1= normal load *
; * (load starting addr) *
; * *
; * ba: 0-15= destination bank *
; * *
; * .a: 0= load memory *
; * >0= verify only *
; * *
; * ending address returned in x,y *
; **********************************************

loadsp ;////////// jump table entry: x & y have load address
stx memuss
sty memuss+1
load ;////////// old monitor entry (not c/128 monitor)
jmp (iload)
nload
sta verck ;preserve load/verify flag (load if = 0)
lda #0
sta status ;clear status

lda fa ;dispatch per device number
cmp #4
bcs lddisk ;load from serial device
jmp ldtape ;load from cassette tape

.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; load memory from serial device (disk)

lddisk
lda serial ;assume slow disk, but attempt burst first
and #%10111110 ;clear external fast flag & burst load flag
sta serial

ldx sa
stx t1 ;save sa: flags normal/alternate load
ldy fnlen ;must have filename
bne 1$ ;...branch if so
jmp err8

1$ sty t2 ;save fnlen too
jsr luking ;'searching for...'
jsr burst ;try a burst load
bcs 2$ ;...branch if failed- retry as normal load
jmp lddone ;burst done

2$ ldy t2
sty fnlen ;restore fnlen
lda #$60
sta sa ;pass 'load' command to disk in sa
jsr openi ;open the file

lda fa
jsr talk ;establish the channel
lda sa
jsr tksa ;send 'load' command

jsr acptr ;get first byte (load adr lo)
sta eal
jsr acptr ;get second byte (load adr hi)
sta eah

lda status ;test status for error
lsr a
lsr a
bcs err4 ;...branch if 'file not found' error

lda t1 ;restore user sa (normal/alt load adr)
bne 10$ ;...branch if load address read from disk (normal)
lda memuss
sta eal ;load address given by user (alternate)
lda memuss+1
sta eah

10$ jsr loding ;'loading...'


20$ lda #$fd ;mask out timeout status bit
and status
sta status

jsr stop ;scan for keyboard <stop> key
beq brkerr ;...abort load operation

jsr acptr ;read a byte from serial bus
tax ;save data byte
lda status ;check status for timeout
lsr a
lsr a
bcs 20$ ;...branch if timeout occurred: try again

txa ;restore data byte
ldy verck
beq 30$ ;...branch if loading memory

sta ochar
ldy #0
jsr eally ;lda (eal),y ;verify memory
cmp ochar
beq 40$ ;...branch if good compare

lda #sperr ;set 'read error' bit to flag 'verify error'
jsr udst ;update i/o status byte
bne 40$ ;always

30$ jsr ealsy ;sta (eal),y

40$ inc eal ;increment load address for next data byte
bne 50$
inc eah
lda eah
cmp #$ff ;check for 'out of memory'
beq err16

50$ bit status
bvc 20$ ;...branch if not end_of_file


jsr untlk ;close channel
jsr clsei ;close the file
jmp lddone ;load operation done







err4 jmp error4 ;file not found
err8 jmp error8 ;missing filename
err9 jmp error9 ;illegal device
err16 jmp error16 ;out of memory
brkerr jmp break ;abort


.page \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
; load memory from cassette

ldtape
cmp #1
bne err9 ;...branch if 'illegal device' error

jsr tapadr ;setup pointers to cassette buffer
bcc err9 ;...branch if deallocated (error)

jsr cste1 ;prompt user 'press play...' & wait for it
bcs ldrts ;...branch if aborted by <stop> key
jsr luking ;'searching...'



1$ lda fnlen ;filename is optional for tape
beq 2$ ;...branch if none given (load any file)

jsr faf ;find a specified file on tape
bcc 3$ ;...branch if found
beq ldrts ;...branch if aborted by <stop> key
bcs err4 ;...branch if file not found (eot)

2$ jsr fah ;find next file on tape
beq ldrts ;...branch if aborted by <stop> key
bcs err4 ;...branch if file not found (eot)

3$ sec
lda status ;check i/o status of header read
and #sperr
bne ldrts ;...branch if read error (.c=1)

cpx #blf ;check file type read from header
beq 5$ ;...branch if relocatable load file (eg: basic pgm)

cpx #plf
bne 1$ ;...branch if not a load type file (eg: data file)