crtc.o \
extzp.o \
kbhit.o \
+ kclose.o \
kernal.o \
kiobase.o \
kopen.o \
krdtim.o \
kreadst.o \
+ kscnkey.o \
kscreen.o \
ksetnam.o \
ksettim.o \
+ kudtim.o \
mainargs.o \
peeksys.o \
pokesys.o \
;
.export _cgetc
- .import plot, write_crtc, sys_bank, restore_bank
+ .import plot, write_crtc
.import cursor
- .import sysp0: zp, sysp3: zp
- .include "cbm610.inc"
+ .import keyidx: zp, keybuf: zp, config: zp
-_cgetc: lda IndReg
- pha
- lda #$0F
- sta IndReg ; Switch to the system bank
- ldy #$D1
- lda (sysp0),y ; Get number of keys in keyboard buffer
- bne L2 ; Jump if there are already chars waiting
+_cgetc: lda keyidx ; Get number of characters
+ bne L2 ; Jump if there are already chars waiting
; Switch on the cursor if needed
lda cursor
- beq L0 ; Jump if no cursor
+ beq L1 ; Jump if no cursor
- jsr plot ; Set the current cursor position
- ldy #$D4
- lda (sysp0),y ; Get the cursor format
+ jsr plot ; Set the current cursor position
ldy #10
- jsr write_crtc ; Set the cursor format
+ lda config ; Cursor format
+ jsr write_crtc ; Set the cursor formar
-L0: ldy #$D1
-L1: lda (sysp0),y ; Get the number of keys in the buffer
- beq L1 ; Wait until we have some keys
+L1: lda keyidx
+ beq L1
ldy #10
- lda #$20 ; Cursor off
+ lda #$20 ; Cursor off
jsr write_crtc
-L2: ldy #$D1
- lda (sysp0),y ; Get number of chars in buffer
- tax
- ldy #$AB
- lda (sysp3),y ; Get first char from keyboard buffer
- sta c ; Save for return
- dex
- txa
- ldy #$D1
- sta (sysp0),y
- sei
- jmp L4
-L3: iny
- lda (sysp3),y
- dey
- sta (sysp3),y
- iny
-L4: dex
- bpl L3
- cli
-
- pla
- sta IndReg ; Restore old segment
-
- ldx #$00 ; High byte
- lda c ; First char from buffer
+L2: ldx #$00 ; Get index
+ ldy keybuf ; Get first character in the buffer
+ sei
+L3: lda keybuf+1,x ; Move up the remaining chars
+ sta keybuf,x
+ inx
+ cpx keyidx
+ bne L3
+ dec keyidx
+ cli
+
+ ldx #$00 ; High byte
+ tya ; First char from buffer
rts
-.bss
-c: .byte 0
.export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot
+ .destructor setsyscursor
.import _gotoxy
.import popa
+ .import PLOT
.import ktmp: zp, crtc: zp, CURS_X: zp, CURS_Y: zp, RVS: zp
.import CharPtr: zp
sta IndReg
rts
+; -------------------------------------------------------------------------
+; Cleanup routine that sets the kernal cursor position to ours
+
+.segment "PAGE2"
+
+setsyscursor:
+ ldy CURS_X
+ ldx CURS_Y
+ clc
+ jmp PLOT ; Set the new cursor
+
; -------------------------------------------------------------------------
; Low bytes of the start address of the screen lines
; This must be the *first* file on the linker command line
;
- .export _exit, BRKVec, UDTIM
+ .export _exit, BRKVec
.import condes, initlib, donelib
.import push0, callmain
.import __BSS_RUN__, __BSS_SIZE__, __EXTZP_RUN__
.import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__
- .import SCNKEY
+ .import scnkey, UDTIM
.include "zeropage.inc"
.include "extzp.inc"
.byte $32,$00,$9e,$20,$32,$35,$36,$00,$4f,$00,$3c,$00,$83,$20,$31,$32
.byte $30,$2c,$31,$36,$39,$2c,$31,$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 $CC, graphmode
+ .byte $D4, config
+
+.endproc
+
+
;------------------------------------------------------------------------------
; 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
lda IndReg
sta ExecReg
-;------------------------------------------------------------------------------
; We are at $100 now. The following snippet is a copy of the code that is poked
; in the system bank memory by the basic header program, it's only for
; documentation and not actually used here:
ldx #$FE ; Leave $1FF untouched for cross bank calls
txs ; Set up our own stack
+; Switch the indirect segment to the system bank
+
+ lda #$0F
+ sta IndReg
+
; Initialize the extended zeropage
ldx #.sizeof(extzp)-1
dex
bpl L1
-; Set the interrupt, NMI and other vectors
+; Copy stuff from the system zeropage to ours
- ldy #.sizeof(vectors)-1
-L2: lda vectors,y
- sta $10000 - .sizeof(vectors),y
- dey
- bpl L2
+ lda #.sizeof(transfer_table)
+ sta ktmp
+L2: ldx ktmp
+ ldy transfer_table-2,x
+ lda transfer_table-1,x
+ tax
+ lda (sysp0),y
+ sta $00,x
+ dec ktmp
+ dec ktmp
+ bne L2
-; Switch the indirect segment to the system bank
+; Set the interrupt, NMI and other vectors
- lda #$0F
- sta IndReg
+ ldx #.sizeof(vectors)-1
+L3: lda vectors,x
+ sta $10000 - .sizeof(vectors),x
+ dex
+ bpl L3
; Setup the C stack
lda #.lobyte($FEB5 - .sizeof(callsysbank_15))
- sta sp
+ sta sp
lda #.hibyte($FEB5 - .sizeof(callsysbank_15))
sta sp+1
; Set the indirect segment to bank we're executing in
- lda ExecReg
+ lda ExecReg
sta IndReg
; Zero the BSS segment. We will do that here instead calling the routine
iny
bne Z1
inc ptr1+1 ; Next page
- dex
+ dex
bne Z1
; Clear the remaining page
sta irqcount ; Disable custom irq handlers
jsr donelib ; Run module destructors
-; Adress the system bank
+; Address the system bank
lda #$0F
sta IndReg
+; Copy stuff back from our zeropage to the systems
+
+.if 0
+ lda #.sizeof(transfer_table)
+ sta ktmp
+@L0: ldx ktmp
+ ldy transfer_table-2,x
+ lda transfer_table-1,x
+ tax
+ lda $00,x
+ sta (sysp0),y
+ dec ktmp
+ dec ktmp
+ bne @L0
+.endif
+
; Copy back the old system bank stack contents
ldy #$FF
cmp #%00000001 ; ticker irq?
bne irqend
- jsr SCNKEY ; Poll the keyboard
+ jsr scnkey ; Poll the keyboard
jsr UDTIM ; Bump the time
; Done
dobrk: jmp (BRKVec)
-; -------------------------------------------------------------------------
-; udtim routine for the 610. We will not check for the stop key here, since
-; C programs will not use it.
-;
-
-.proc UDTIM
-
- inc time
- bne L9
- inc time+1
- bne L9
- inc time+2
- bne L9
- inc time+3
-L9: rts
-
-.endproc
-
; -------------------------------------------------------------------------
; Page 3
.globalzp sysp1, sysp3, crtc, sid, ipccia, cia, acia, tpi1, tpi2
.globalzp ktab1, ktab2, ktab3, ktab4
- .globalzp sysp0, time, segsave, ktmp, CURS_X, CURS_Y, RVS
- .globalzp CharPtr
+ .globalzp sysp0, time, segsave, ktmp, CURS_X, CURS_Y, RVS, config
+ .globalzp CharPtr, keyidx, keybuf, keyscanbuf, keysave, modkey
+ .globalzp norkey, graphmode, lastidx, rptdelay, rptcount
+
sysp0: .word $0000
time: .dword $0000
segsave: .byte 0
-scanbuf: .byte 0
ktmp: .byte 0
CURS_X: .byte 0
CURS_Y: .byte 0
RVS: .byte 0
+config: .byte 0
CharPtr: .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
;
-; Ullrich von Bassewitz, 2003-12-20
+; Ullrich von Bassewitz, 06.08.1998
;
; int kbhit (void);
;
.export _kbhit
-
- .importzp sysp0
.import return0, return1
+ .import keyidx: zp
- .include "cbm610.inc"
.proc _kbhit
- ldx IndReg
- lda #$0F
- sta IndReg
- ldy #$D1 ; Number of keys in kbd buffer
- lda (sysp0),y
- stx IndReg
+ lda keyidx ; Get number of characters
bne L1
jmp return0
L1: jmp return1
--- /dev/null
+;
+; 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 withthe C64, set the carry before jumping to the
+; kernal.
+
+ .export CLOSE
+
+.proc CLOSE
+
+ sec
+ jmp $FFC3
+
+.endproc
+
+
+
.export LISTEN
.export TALK
.export SETLFS
- .export CLOSE
.export CHKIN
.export CKOUT
.export CLRCH
SETLFS = $FFBA
;SETNAM = $FFBD
;OPEN = $FFC0
-CLOSE = $FFC3
+;CLOSE = $FFC3
CHKIN = $FFC6
CKOUT = $FFC9
CLRCH = $FFCC
--- /dev/null
+;
+; Ullrich von Bassewitz, 28.09.1998
+;
+; Keyboard polling stuff for the 610.
+;
+
+ .export scnkey
+ .importzp tpi2, ktab1, ktab2, ktab3, ktab4
+ .importzp keyidx, keybuf, keyscanbuf, keysave, modkey, norkey
+ .importzp graphmode, lastidx, rptdelay, rptcount
+
+ .include "cbm610.inc"
+
+.proc scnkey
+
+ lda #$FF
+ sta modkey
+ sta norkey
+ lda #$00
+ sta keyscanbuf
+ ldy #TPI::PRB
+ sta (tpi2),y
+ ldy #TPI::PRA
+ sta (tpi2),y
+ jsr Poll
+ and #$3F
+ eor #$3F
+ bne L1
+ jmp NoKey
+
+L1: lda #$FF
+ ldy #TPI::PRA
+ sta (tpi2),y
+ asl a
+ ldy #TPI::PRB
+ sta (tpi2),y
+ jsr Poll
+ pha
+ sta modkey
+ ora #$30
+ bne L3 ; Branch always
+
+L2: jsr Poll
+L3: ldx #$05
+ ldy #$00
+L4: lsr a
+ bcc L5
+ inc keyscanbuf
+ dex
+ bpl L4
+ sec
+ ldy #TPI::PRB
+ lda (tpi2),y
+ rol a
+ sta (tpi2),y
+ ldy #TPI::PRA
+ lda (tpi2),y
+ rol a
+ sta (tpi2),y
+ bcs L2
+ pla
+ bcc NoKey ; Branch always
+
+L5: ldy keyscanbuf
+ sty norkey
+ pla
+ asl a
+ asl a
+ asl a
+ bcc L6
+ bmi L7
+ lda (ktab2),y ; Shifted normal key
+ ldx graphmode
+ beq L8
+ lda (ktab3),y ; Shifted key in graph mode
+ bne L8
+
+L6: lda (ktab4),y ; Key with ctrl pressed
+ bne L8
+L7: lda (ktab1),y ; Normal key
+L8: tax
+ cpx #$FF ; Valid key?
+ beq Done
+ cpy lastidx
+ beq Repeat
+ ldx #$13
+ stx rptdelay
+ ldx keyidx
+ cpx #$09
+ beq NoKey
+ cpy #$59
+ bne PutKey
+ cpx #$08
+ beq NoKey
+ sta keybuf,x
+ inx
+ bne PutKey
+
+NoKey: ldy #$FF
+Done: sty lastidx
+End: lda #$7F
+ ldy #TPI::PRA
+ sta (tpi2),y
+ ldy #TPI::PRB
+ lda #$FF
+ sta (tpi2),y
+ rts
+
+Repeat: dec rptdelay
+ bpl End
+ inc rptdelay
+ dec rptcount
+ bpl End
+ inc rptcount
+ ldx keyidx
+ bne End
+
+PutKey: sta keybuf,x
+ inx
+ stx keyidx
+ ldx #$03
+ stx rptcount
+ bne Done
+
+.endproc
+
+; Poll the keyboard port until it's stable
+; This code goes into page 2, since it is included in every program and
+; there's space left in p2
+
+.segment "PAGE2"
+
+.proc Poll
+ ldy #TPI::PRC
+L1: lda (tpi2),y
+ sta keysave
+ lda (tpi2),y
+ cmp keysave
+ bne L1
+ rts
+.endproc
+
+
+
+
--- /dev/null
+;
+; Ullrich von Bassewitz, 2003-12-21
+;
+; udtim routine for the 610. We will not check for the stop key here, since
+; C programs will not use it.
+;
+
+ .export UDTIM
+ .import time: zp
+
+.proc UDTIM
+
+ inc time
+ bne L9
+ inc time+1
+ bne L9
+ inc time+2
+ bne L9
+ inc time+3
+L9: rts
+
+.endproc
+