From 97494bc1f3cc413754acdabf681aa57f2406d559 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 21 Dec 2003 18:43:25 +0000 Subject: [PATCH] Design change: Do keyboard polling internally without calling the kernal in the system bank. For one this performs better (several %), second it allows to handle the function keys in conformance with other platforms. Without the custom keyboard routine, we would have to apply some more magic to the function keys to make them work as with other cc65 targets. git-svn-id: svn://svn.cc65.org/cc65/trunk@2811 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/cbm610/Makefile | 3 + libsrc/cbm610/cgetc.s | 69 +++++++------------ libsrc/cbm610/cputc.s | 13 ++++ libsrc/cbm610/crt0.s | 101 ++++++++++++++++++---------- libsrc/cbm610/extzp.inc | 6 +- libsrc/cbm610/extzp.s | 15 ++++- libsrc/cbm610/kbhit.s | 13 +--- libsrc/cbm610/kclose.s | 21 ++++++ libsrc/cbm610/kernal.s | 3 +- libsrc/cbm610/kscnkey.s | 145 ++++++++++++++++++++++++++++++++++++++++ libsrc/cbm610/kudtim.s | 23 +++++++ 11 files changed, 313 insertions(+), 99 deletions(-) create mode 100644 libsrc/cbm610/kclose.s create mode 100644 libsrc/cbm610/kscnkey.s create mode 100644 libsrc/cbm610/kudtim.s diff --git a/libsrc/cbm610/Makefile b/libsrc/cbm610/Makefile index 0af438ab0..3e6fc71cd 100644 --- a/libsrc/cbm610/Makefile +++ b/libsrc/cbm610/Makefile @@ -37,14 +37,17 @@ OBJS = _scrsize.o \ 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 \ diff --git a/libsrc/cbm610/cgetc.s b/libsrc/cbm610/cgetc.s index 8da00c66f..8a017b4f5 100644 --- a/libsrc/cbm610/cgetc.s +++ b/libsrc/cbm610/cgetc.s @@ -5,69 +5,46 @@ ; .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 +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 - pla - sta IndReg ; Restore old segment - - ldx #$00 ; High byte - lda c ; First char from buffer + ldx #$00 ; High byte + tya ; First char from buffer rts -.bss -c: .byte 0 diff --git a/libsrc/cbm610/cputc.s b/libsrc/cbm610/cputc.s index c464c8d2b..f34bcad22 100644 --- a/libsrc/cbm610/cputc.s +++ b/libsrc/cbm610/cputc.s @@ -7,9 +7,11 @@ .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 @@ -132,6 +134,17 @@ plot: ldx CURS_Y 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 diff --git a/libsrc/cbm610/crt0.s b/libsrc/cbm610/crt0.s index e14596d32..4b3491baf 100644 --- a/libsrc/cbm610/crt0.s +++ b/libsrc/cbm610/crt0.s @@ -4,13 +4,13 @@ ; 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" @@ -54,6 +54,24 @@ .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 @@ -67,7 +85,6 @@ Back: sei 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: @@ -130,6 +147,11 @@ Origin: tsx 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 @@ -138,23 +160,32 @@ L1: lda extzp,x dex bpl L1 +; Copy stuff from the system zeropage to ours + + 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 + ; Set the interrupt, NMI and other vectors - ldy #.sizeof(vectors)-1 -L2: lda vectors,y - sta $10000 - .sizeof(vectors),y - dey - bpl L2 - -; Switch the indirect segment to the system bank - - 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 @@ -207,7 +238,7 @@ L4: lda (sysp1),y ; 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 @@ -229,7 +260,7 @@ Z1: sta (ptr1),y iny bne Z1 inc ptr1+1 ; Next page - dex + dex bne Z1 ; Clear the remaining page @@ -269,11 +300,27 @@ _exit: lda #$00 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 @@ -345,7 +392,7 @@ irqskip:lda #$0F cmp #%00000001 ; ticker irq? bne irqend - jsr SCNKEY ; Poll the keyboard + jsr scnkey ; Poll the keyboard jsr UDTIM ; Bump the time ; Done @@ -364,24 +411,6 @@ nmi: rti 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 diff --git a/libsrc/cbm610/extzp.inc b/libsrc/cbm610/extzp.inc index 43e8697bf..af769e32e 100644 --- a/libsrc/cbm610/extzp.inc +++ b/libsrc/cbm610/extzp.inc @@ -9,6 +9,8 @@ .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 + diff --git a/libsrc/cbm610/extzp.s b/libsrc/cbm610/extzp.s index 7417d6447..be7e096df 100644 --- a/libsrc/cbm610/extzp.s +++ b/libsrc/cbm610/extzp.s @@ -33,14 +33,23 @@ ktab4: .word $0000 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 diff --git a/libsrc/cbm610/kbhit.s b/libsrc/cbm610/kbhit.s index 0a5fcc197..b9f32ed0a 100644 --- a/libsrc/cbm610/kbhit.s +++ b/libsrc/cbm610/kbhit.s @@ -1,23 +1,16 @@ ; -; 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 diff --git a/libsrc/cbm610/kclose.s b/libsrc/cbm610/kclose.s new file mode 100644 index 000000000..4ffde096d --- /dev/null +++ b/libsrc/cbm610/kclose.s @@ -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 withthe C64, set the carry before jumping to the +; kernal. + + .export CLOSE + +.proc CLOSE + + sec + jmp $FFC3 + +.endproc + + + diff --git a/libsrc/cbm610/kernal.s b/libsrc/cbm610/kernal.s index 0bb556b5b..db9d852eb 100644 --- a/libsrc/cbm610/kernal.s +++ b/libsrc/cbm610/kernal.s @@ -23,7 +23,6 @@ .export LISTEN .export TALK .export SETLFS - .export CLOSE .export CHKIN .export CKOUT .export CLRCH @@ -64,7 +63,7 @@ TALK = $FFB4 SETLFS = $FFBA ;SETNAM = $FFBD ;OPEN = $FFC0 -CLOSE = $FFC3 +;CLOSE = $FFC3 CHKIN = $FFC6 CKOUT = $FFC9 CLRCH = $FFCC diff --git a/libsrc/cbm610/kscnkey.s b/libsrc/cbm610/kscnkey.s new file mode 100644 index 000000000..7e637540e --- /dev/null +++ b/libsrc/cbm610/kscnkey.s @@ -0,0 +1,145 @@ +; +; 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 + + + + diff --git a/libsrc/cbm610/kudtim.s b/libsrc/cbm610/kudtim.s new file mode 100644 index 000000000..4653d8148 --- /dev/null +++ b/libsrc/cbm610/kudtim.s @@ -0,0 +1,23 @@ +; +; 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 +