1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-26 02:30:17 +00:00

Added CONIO cursor support.

For quite some time I deliberately didn't add cursor support to the Apple II CONIO imöplementation. I consider it inappropriate to increase the size of cgetc() unduly for a rather seldom used feature.

There's no hardware cursor on the Apple II so displaying a cursor during keyboard input means reading the character stored at the cursor location, writing the cursor character, reading the keyboard and finally writing back the character read initially.

The naive approach is to reuse the part of cputc() that determines the memory location of the character at the cursor position in order to read the character stored there. However that means to add at least one additional JSR / RTS pair to cputc() adding 4 bytes and 12 cycles :-( Apart from that this approach means still a "too" large cgetc().

The approach implemented instead is to include all functionality required by cgetc() into cputc() - which is to read the current character before writing a new one. This may seem surprising at first glance but an LDA(),Y / TAX sequence adds only 3 bytes and 7 cycles so it cheaper than the JSR / RTS pair and allows to brings down the code increase in cgetc() down to a reasonable value.

However so far the internal cputc() code in question saved the X register. Now it uses the X register to return the old character present before writing the new character for cgetc(). This requires some rather small adjustments in other functions using that internal cputc() code.
This commit is contained in:
Oliver Schmidt 2016-06-19 15:03:20 +02:00
parent 2ef43e425a
commit e47485f925
7 changed files with 60 additions and 38 deletions

View File

@ -449,10 +449,6 @@ BASIC.SYSTEM) there are some limitations for DOS 3.3:
The Apple ][ has no color text mode. Therefore the functions textcolor(), The Apple ][ has no color text mode. Therefore the functions textcolor(),
bgcolor() and bordercolor() have no effect. bgcolor() and bordercolor() have no effect.
<tag/Cursor/
The Apple&nbsp;&rsqb;&lsqb; has no hardware cursor. Therefore the function cursor() has
no effect.
</descrip><p> </descrip><p>

View File

@ -450,10 +450,6 @@ BASIC.SYSTEM) there are some limitations for DOS 3.3:
The enhanced&nbsp;Apple&nbsp;//e has no color text mode. Therefore the functions The enhanced&nbsp;Apple&nbsp;//e has no color text mode. Therefore the functions
textcolor(), bgcolor() and bordercolor() have no effect. textcolor(), bgcolor() and bordercolor() have no effect.
<tag/Cursor/
The enhanced&nbsp;Apple&nbsp;//e has no hardware cursor. Therefore the function
cursor() has no effect.
</descrip><p> </descrip><p>

View File

@ -6,20 +6,44 @@
; If open_apple key is pressed then the high-bit of the key is set. ; If open_apple key is pressed then the high-bit of the key is set.
; ;
.export _cgetc .export _cgetc
.import cursor, putchardirect
.include "apple2.inc" .include "apple2.inc"
_cgetc: _cgetc:
lda KBD ; Cursor on ?
bpl _cgetc ; If < 128, no key pressed lda cursor
beq :+
; At this time, the high bit of the key pressed is set ; Show caret.
bit KBDSTRB ; Clear keyboard strobe .ifdef __APPLE2ENH__
lda #$7F | $80 ; Checkerboard, screen code
.else
lda #' ' | $40 ; Blank, flashing
.endif
jsr putchardirect ; Returns old character in X
; Wait for keyboard strobe.
: lda KBD
bpl :- ; If < 128, no key pressed
; Cursor on ?
ldy cursor
beq :+
; Restore old character.
pha
txa
jsr putchardirect
pla
; At this time, the high bit of the key pressed is set.
: bit KBDSTRB ; Clear keyboard strobe
.ifdef __APPLE2ENH__ .ifdef __APPLE2ENH__
bit BUTN0 ; Check if OpenApple is down bit BUTN0 ; Check if OpenApple is down
bmi done bmi done
.endif .endif
and #$7F ; If not down, then clear high bit and #$7F ; If not down, then clear high bit
done: ldx #$00 done: ldx #>$0000
rts rts

View File

@ -26,11 +26,12 @@ _chline:
ldx #'-' | $80 ; Horizontal line, screen code ldx #'-' | $80 ; Horizontal line, screen code
chlinedirect: chlinedirect:
stx tmp1
cmp #$00 ; Is the length zero? cmp #$00 ; Is the length zero?
beq done ; Jump if done beq done ; Jump if done
sta tmp1 sta tmp2
: txa ; Screen code : lda tmp1 ; Screen code
jsr cputdirect ; Direct output jsr cputdirect ; Direct output
dec tmp1 dec tmp2
bne :- bne :-
done: rts done: rts

View File

@ -9,7 +9,7 @@
.constructor initconio .constructor initconio
.endif .endif
.export _cputcxy, _cputc .export _cputcxy, _cputc
.export cputdirect, newline, putchar .export cputdirect, newline, putchar, putchardirect
.import gotoxy, VTABZ .import gotoxy, VTABZ
.include "apple2.inc" .include "apple2.inc"
@ -62,32 +62,36 @@ newline:
lda WNDTOP ; Goto top of screen lda WNDTOP ; Goto top of screen
sta CV sta CV
: jmp VTABZ : jmp VTABZ
putchar: putchar:
.ifdef __APPLE2ENH__ .ifdef __APPLE2ENH__
ldy INVFLG ldy INVFLG
cpy #$FF ; Normal character display mode? cpy #$FF ; Normal character display mode?
beq put beq putchardirect
cmp #$E0 ; Lowercase? cmp #$E0 ; Lowercase?
bcc mask bcc mask
and #$7F ; Inverse lowercase and #$7F ; Inverse lowercase
bra put bra putchardirect
.endif .endif
mask: and INVFLG ; Apply normal, inverse, flash mask: and INVFLG ; Apply normal, inverse, flash
put: ldy CH
putchardirect:
pha
ldy CH
.ifdef __APPLE2ENH__ .ifdef __APPLE2ENH__
bit RD80VID ; In 80 column mode? bit RD80VID ; In 80 column mode?
bpl col40 ; No, in 40 cols bpl put ; No, just go ahead
pha
tya tya
lsr ; Div by 2 lsr ; Div by 2
tay tay
pla bcs put ; Odd cols go in main memory
bcs col40 ; Odd cols go in 40 col memory
bit HISCR ; Assume SET80COL bit HISCR ; Assume SET80COL
sta (BASL),Y
bit LOWSCR ; Assume SET80COL
rts
.endif .endif
col40: sta (BASL),Y put: lda (BASL),Y ; Get current character
tax ; Return old character for _cgetc
pla
sta (BASL),Y
.ifdef __APPLE2ENH__
bit LOWSCR ; Doesn't hurt in 40 column mode
.endif
rts rts

View File

@ -23,12 +23,13 @@ _cvline:
.endif .endif
cvlinedirect: cvlinedirect:
stx tmp1
cmp #$00 ; Is the length zero? cmp #$00 ; Is the length zero?
beq done ; Jump if done beq done ; Jump if done
sta tmp1 sta tmp2
: txa ; Screen code : lda tmp1 ; Screen code
jsr putchar ; Write, no cursor advance jsr putchar ; Write, no cursor advance
jsr newline ; Advance cursor to next line jsr newline ; Advance cursor to next line
dec tmp1 dec tmp2
bne :- bne :-
done: rts done: rts

View File

@ -16,10 +16,10 @@
.include "zeropage.inc" .include "zeropage.inc"
.include "apple2.inc" .include "apple2.inc"
WIDTH = tmp2 WIDTH = ptr1
HEIGHT = tmp3 HEIGHT = ptr1+1
XORIGIN = tmp4 XORIGIN = ptr2
YORIGIN = ptr1 YORIGIN = ptr2+1
_textframexy: _textframexy:
sec sec