1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-09 13:25:06 +00:00

Merge pull request #148 from smuehlst/c1p

kbhit() implementation, fixed C data stack pointer initialization
This commit is contained in:
Oliver Schmidt
2015-03-02 13:02:17 +01:00
12 changed files with 104 additions and 22 deletions

View File

@@ -7,7 +7,7 @@ SYMBOLS {
} }
MEMORY { MEMORY {
# for size of ZP see runtime/zeropage.s and c1p/extzp.s # for size of ZP see runtime/zeropage.s and c1p/extzp.s
ZP: file = "", define = yes, start = $0002, size = $001A + $0004; ZP: file = "", define = yes, start = $0002, size = $001A + $0005;
RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S; RAM: file = %O, define = yes, start = %S, size = __HIMEM__ - __STACKSIZE__ - %S;
} }
SEGMENTS { SEGMENTS {

View File

@@ -137,10 +137,6 @@ There are no loadable drivers available.
<sect>Limitations<p> <sect>Limitations<p>
<sect1>conio implementation<p>
The conio implementation is complete except for a kbhit() function.
<sect1>stdio implementation<p> <sect1>stdio implementation<p>
There is no support for stdio at the moment. There is no support for stdio at the moment.

View File

@@ -13,7 +13,7 @@
.include "osic1p.inc" .include "osic1p.inc"
.proc screensize .proc screensize
ldx #(SCR_LINELEN + 1) ldx #SCR_WIDTH
ldy #(SCR_HEIGHT + 1) ldy #SCR_HEIGHT
rts rts
.endproc .endproc

View File

@@ -22,7 +22,7 @@ _cclear:
cmp #0 ; Is the length zero? cmp #0 ; Is the length zero?
beq L9 ; Jump if done beq L9 ; Jump if done
sta tmp1 sta tmp1
L1: lda #$20 ; Blank - screen code L1: lda #' '
jsr cputdirect ; Direct output jsr cputdirect ; Direct output
dec tmp1 dec tmp1
bne L1 bne L1

View File

@@ -1,6 +1,8 @@
; ;
; char cgetc (void); ; char cgetc (void);
; ;
.constructor initcgetc
.export _cgetc .export _cgetc
.import cursor .import cursor
@@ -8,8 +10,21 @@
.include "extzp.inc" .include "extzp.inc"
.include "zeropage.inc" .include "zeropage.inc"
; Initialize one-character buffer that is filled by kbhit()
initcgetc:
lda #$00
sta CHARBUF ; No character in buffer initially
rts
; Input routine from 65V PROM MONITOR, show cursor if enabled ; Input routine from 65V PROM MONITOR, show cursor if enabled
_cgetc: _cgetc:
lda CHARBUF ; character in buffer available?
beq nobuffer
tax ; save character in X
lda #$00
sta CHARBUF ; empty buffer
beq restorex ; restore X and return
nobuffer:
lda cursor ; show cursor? lda cursor ; show cursor?
beq nocursor beq nocursor
ldy CURS_X ldy CURS_X
@@ -25,7 +40,9 @@ nocursor:
lda tmp1 ; fetch saved character lda tmp1 ; fetch saved character
ldy CURS_X ldy CURS_X
sta (SCREEN_PTR),y ; store at cursor position sta (SCREEN_PTR),y ; store at cursor position
restorex:
txa ; restore saved character from X txa ; restore saved character from X
ldx #$00 ; high byte of int return value
done: done:
ldx #$00 ; high byte of int return value
rts rts

View File

@@ -12,7 +12,7 @@
BANKS = VIDEORAMSIZE / $100 BANKS = VIDEORAMSIZE / $100
_clrscr: _clrscr:
lda #$20 ; ' ' lda #' '
ldy #BANKS ldy #BANKS
ldx #$00 ldx #$00
staloc: staloc:

View File

@@ -12,6 +12,10 @@
.include "osic1p.inc" .include "osic1p.inc"
.include "extzp.inc" .include "extzp.inc"
FIRSTVISC = $85 ; Offset of first visible character in video RAM
LINEDIST = $20 ; Offset in video RAM between two lines
BLOCKSIZE = $100 ; Size of block to scroll
_cputcxy: _cputcxy:
pha ; Save C pha ; Save C
jsr popa ; Get Y jsr popa ; Get Y
@@ -35,9 +39,9 @@ cputdirect:
; Advance cursor position ; Advance cursor position
advance: advance:
cpy #SCR_LINELEN ; xsize-1 cpy #(SCR_WIDTH - 1)
bne L3 bne L3
jsr newline ; new line jsr newline ; New line
ldy #$FF ; + cr ldy #$FF ; + cr
L3: iny L3: iny
sty CURS_X sty CURS_X
@@ -46,10 +50,25 @@ L3: iny
newline: newline:
inc CURS_Y inc CURS_Y
lda CURS_Y lda CURS_Y
cmp #SCR_HEIGHT ; screen height cmp #SCR_HEIGHT ; Screen height
bne plot bne plot
lda #0 ; wrap around to line 0 dec CURS_Y ; Bottom of screen reached, scroll
sta CURS_Y ldx #0
scroll:
.repeat 3, I ; Scroll screen in three blocks of size
; BLOCKSIZE
lda SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC+LINEDIST,x
sta SCRNBASE+(I*BLOCKSIZE)+FIRSTVISC,x
.endrepeat
inx
bne scroll
lda #' ' ; Clear bottom line of screen
bottom:
sta SCRNBASE+(3*BLOCKSIZE)+FIRSTVISC,x
inx
cpx #SCR_WIDTH
bne bottom
plot: ldy CURS_Y plot: ldy CURS_Y
lda ScrLo,y lda ScrLo,y

View File

@@ -9,6 +9,7 @@
.export __STARTUP__ : absolute = 1 ; Mark as startup .export __STARTUP__ : absolute = 1 ; Mark as startup
.import __RAM_START__, __RAM_SIZE__ ; Linker generated .import __RAM_START__, __RAM_SIZE__ ; Linker generated
.import __STACKSIZE__
.import zerobss, initlib, donelib .import zerobss, initlib, donelib
@@ -31,9 +32,9 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; Set cc65 argument stack pointer ; Set cc65 argument stack pointer
lda #<(__RAM_START__ + __RAM_SIZE__) lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp sta sp
lda #>(__RAM_START__ + __RAM_SIZE__) lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 sta sp+1
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------

View File

@@ -4,4 +4,4 @@
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
.globalzp CURS_X, CURS_Y, SCREEN_PTR .globalzp CURS_X, CURS_Y, SCREEN_PTR, CHARBUF

View File

@@ -14,6 +14,7 @@
CURS_X: .res 1 CURS_X: .res 1
CURS_Y: .res 1 CURS_Y: .res 1
SCREEN_PTR: .res 2 SCREEN_PTR: .res 2
CHARBUF: .res 1
; size 4 ; size 5
; Adjust size of this segment in osic1p.cfg if the size changes ; Adjust size of the ZP segment in osic1p.cfg if the size changes

47
libsrc/osic1p/kbhit.s Normal file
View File

@@ -0,0 +1,47 @@
;
; unsigned char kbhit (void);
;
; The method to detect a pressed key is based on the documentation in
; "Section 3 Programmed Key Functions" in "The Challenger Character Graphics
; Reference Manual"
; We only want to return true for characters that can be returned by cgetc(),
; but not for keys like <Shift> or <Ctrl>. Therefore a special handling is
; needed for the first row. This is implemented by a bit mask that is stored
; in tmp1 and that is set to zero after the first round.
;
.export _kbhit
.include "osic1p.inc"
.include "extzp.inc"
.include "zeropage.inc"
_kbhit:
lda #%11011111 ; Mask for only checking the column for the
sta tmp1 ; ESC key in the first keyboard row.
lda #%11111110 ; Mask for first keyboard row
scan:
sta KBD ; Select keyboard row
tax ; Save A
lda KBD ; Read keyboard columns
ora tmp1 ; Mask out uninteresting keys (only relevant in
; first row)
cmp #$FF ; No keys pressed?
bne keypressed
lda #$00 ; For remaining rows no keys masked
sta tmp1
txa ; Restore A
sec ; Want to shift in ones
rol a ; Rotate row select to next bit position
cmp #$FF ; Done?
bne scan ; If not, continue
lda #$00 ; Return false
tax ; High byte of return is also zero
sta CHARBUF ; No character in buffer
rts
keypressed:
jsr INPUTC ; Get input character in A
sta CHARBUF ; Save in buffer
ldx #$00 ; High byte of return is always zero
lda #$01 ; Return true
rts

View File

@@ -2,8 +2,9 @@
SCRNBASE := $D000 ; Base of video RAM SCRNBASE := $D000 ; Base of video RAM
INPUTC := $FD00 ; Input character from keyboard INPUTC := $FD00 ; Input character from keyboard
RESET := $FF00 ; Reset address, show boot prompt RESET := $FF00 ; Reset address, show boot prompt
KBD := $DF00 ; Polled keyboard register
; Other definitions ; Other definitions
VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB) VIDEORAMSIZE = $0400 ; Size of C1P video RAM (1 kB)
SCR_LINELEN = $18 ; screen width - 1 SCR_WIDTH = $18 ; Screen width
SCR_HEIGHT = $18 ; screen height - 1 SCR_HEIGHT = $18 ; Screen height