From ae74057353389ae8cbf25330ade3e56112dc6547 Mon Sep 17 00:00:00 2001
From: izydorst <izydorst@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Date: Fri, 8 Mar 2002 16:47:34 +0000
Subject: [PATCH] conio with fixed width and proportional font support

git-svn-id: svn://svn.cc65.org/cc65/trunk@1178 b7a2c559-68d2-44c3-8de9-860c34a00d81
---
 libsrc/geos/conio/Makefile     |  5 ++--
 libsrc/geos/conio/cgetc.s      | 14 ++++------
 libsrc/geos/conio/cputc.s      | 44 +++++++++++++++++++++--------
 libsrc/geos/conio/cputs.s      | 51 +++++++++++++++-------------------
 libsrc/geos/conio/cursor.s     | 21 +++++---------
 libsrc/geos/conio/gotoxy.s     | 21 ++++++++++----
 libsrc/geos/conio/revers.s     |  2 +-
 libsrc/geos/conio/screensize.s | 11 +++-----
 libsrc/geos/conio/where.s      | 17 +++---------
 libsrc/geos/system/Makefile    |  2 +-
 10 files changed, 96 insertions(+), 92 deletions(-)

diff --git a/libsrc/geos/conio/Makefile b/libsrc/geos/conio/Makefile
index 6d3abd9ab..9dc6ff387 100644
--- a/libsrc/geos/conio/Makefile
+++ b/libsrc/geos/conio/Makefile
@@ -7,8 +7,9 @@
 	@$(AS) -o $@ $(AFLAGS) $<
 
 
-S_OBJS	= cchvline.o cgetc.o clrscr.o color.o cputc.o cputs.o cursor.o gotoxy.o kbhit.o\
-	revers.o screensize.o where.o
+S_OBJS	= cclear.o chline.o cvline.o cgetc.o clrscr.o color.o\
+	cputc.o cpputs.o cputs.o cursor.o gotoxy.o kbhit.o revers.o\
+	screensize.o where.o _scrsize.o
 
 all: $(S_OBJS)
 
diff --git a/libsrc/geos/conio/cgetc.s b/libsrc/geos/conio/cgetc.s
index 8212675bc..974a37f56 100644
--- a/libsrc/geos/conio/cgetc.s
+++ b/libsrc/geos/conio/cgetc.s
@@ -3,32 +3,28 @@
 ; Maciej 'YTM/Elysium' Witkowiak
 ;
 ; 27.10.2001
+; 06.03.2002
 
 ; unsigned char cgetc (void);
 
 	    .export _cgetc
+	    .import update_cursor
 
 	    .include "../inc/jumptab.inc"
 	    .include "../inc/geossym.inc"
-	    .include "cursor.inc"
+	    .include "../inc/cursor.inc"
 
 _cgetc:
 ; show cursor if needed
 	    lda cursor_flag
 	    beq L0
 
-	    lda #1
-	    sta r3L
+	    jsr update_cursor
 	    lda cursor_x
 	    ldx cursor_x+1
-	    sta r4L
 	    sta stringX
-	    stx r4H
 	    stx stringX+1
-	    lda cursor_y
-	    sec
-	    sbc curHeight
-	    sta r5L
+	    lda	cursor_y
 	    sta stringY
 	    jsr PosSprite
 	    jsr PromptOn
diff --git a/libsrc/geos/conio/cputc.s b/libsrc/geos/conio/cputc.s
index 4120abf70..aa0c92155 100644
--- a/libsrc/geos/conio/cputc.s
+++ b/libsrc/geos/conio/cputc.s
@@ -3,19 +3,21 @@
 ; Maciej 'YTM/Elysium' Witkowiak
 ;
 ; 27.10.2001
+; 06.03.2002
 
 ; void cputcxy (unsigned char x, unsigned char y, char c);
 ; void cputc (char c);
 
 	    .export _cputcxy, _cputc, update_cursor
 
-	    .import _gotoxy
+	    .import _gotoxy, fixcursor
 	    .import popa
+	    .import xsize,ysize
 
 	    .include "../inc/const.inc"
 	    .include "../inc/geossym.inc"
 	    .include "../inc/jumptab.inc"
-	    .include "cursor.inc"
+	    .include "../inc/cursor.inc"
 
 _cputcxy:
 	pha	    		; Save C
@@ -30,10 +32,15 @@ _cputc:
 ; some characters are not safe for PutChar
 	cmp	#$20
 	bcs	L1
+	cmp	#CR
+	beq	echo_crlf
+	cmp	#LF
+	beq	do_lf
 	cmp	#$1d
 	bne	L00
 	ldx	#BACKSPACE
-	bne	L1
+	sec
+	bcs	L2
 L00:	cmp	#ESC_GRAPHICS
 	beq	L0
 	cmp	#ESC_RULER
@@ -50,7 +57,9 @@ L00:	cmp	#ESC_GRAPHICS
 	bne	L1
 L0:	rts
 
-L1:	lda	cursor_x
+L1:	clc
+L2:	php
+	lda	cursor_x
 	sta 	r11L
 	lda	cursor_x+1
 	sta	r11H
@@ -58,18 +67,31 @@ L1:	lda	cursor_x
 	sta	r1H
 	txa
 	jsr	PutChar
+	plp
+	bcs	update_cursor
+
+	inc	cursor_c
+	lda	cursor_c
+	cmp	xsize
+	bne	update_cursor
+echo_crlf:
+	lda	#0
+	sta	cursor_c
+do_lf:	inc	cursor_r
+	lda	cursor_r
+	cmp	ysize
+	bne	update_cursor
+	dec	cursor_r
 
 update_cursor:
-	lda	r11L
-	sta	cursor_x
+	jsr 	fixcursor
+	lda	cursor_x
 	sta	r4L
-	lda	r11H
-	sta	cursor_x+1
+	lda	cursor_x+1
 	sta	r4H
-	lda	r1H
-	sta	cursor_y
+	lda	cursor_y
 	sec
-	sbc 	curHeight
+	sbc	curHeight
 	sta	r5L
 	lda	#1		; update cursor prompt position
 	sta	r3L
diff --git a/libsrc/geos/conio/cputs.s b/libsrc/geos/conio/cputs.s
index 2f5276ac6..a05f2bad7 100644
--- a/libsrc/geos/conio/cputs.s
+++ b/libsrc/geos/conio/cputs.s
@@ -1,41 +1,36 @@
-
 ;
-; Maciej 'YTM/Elysium' Witkowiak
+; Ullrich von Bassewitz, 06.08.1998
 ;
-; 27.10.2001
-
 ; void cputsxy (unsigned char x, unsigned char y, char* s);
 ; void cputs (char* s);
+;
 
-	    .export _cputsxy, _cputs
-
-	    .import update_cursor, _gotoxy
-	    .import popa
-
-	    .include "../inc/const.inc"
-	    .include "../inc/geossym.inc"
-	    .include "../inc/jumptab.inc"
-	    .include "cursor.inc"
+	.export		_cputsxy, _cputs
+	.import		popa, _gotoxy, _cputc
+	.importzp	ptr1, tmp1
 
 _cputsxy:
-	sta	r0L		; Save s for later
-	stx	r0H
+	sta	ptr1		; Save s for later
+	stx	ptr1+1
 	jsr	popa		; Get Y
 	jsr	_gotoxy		; Set cursor, pop x
    	jmp	L0		; Same as cputs...
 
-_cputs:	sta	r0L		; Save s
-   	stx	r0H
+_cputs:	sta	ptr1		; Save s
+   	stx	ptr1+1
 L0:	ldy	#0
-	lda	(r0),y
-   	bne	L1		; Jump if there's something
-	rts
+L1:	lda	(ptr1),y
+   	beq	L9		; Jump if done
+   	iny
+   	sty	tmp1		; Save offset
+   	jsr	_cputc		; Output char, advance cursor
+   	ldy	tmp1		; Get offset
+   	bne	L1		; Next char
+   	inc	ptr1+1 		; Bump high byte
+	bne	L1
+
+; Done
+
+L9:	rts
+
 
-L1:	lda	cursor_x
-	sta 	r11L
-	lda	cursor_x+1
-	sta	r11H
-	lda	cursor_y
-	sta	r1H
-	jsr	PutString
-	jmp	update_cursor
diff --git a/libsrc/geos/conio/cursor.s b/libsrc/geos/conio/cursor.s
index d2ec60579..55f89c61b 100644
--- a/libsrc/geos/conio/cursor.s
+++ b/libsrc/geos/conio/cursor.s
@@ -7,29 +7,22 @@
 ; unsigned char cursor (unsigned char onoff);
 
 	    .export _cursor
+	    .import update_cursor
 	    .include "../inc/jumptab.inc"
 	    .include "../inc/geossym.inc"
-	    .include "cursor.inc"
+	    .include "../inc/cursor.inc"
 
 _cursor:
 
 	tay			; onoff into Y
 	ldx	#0		; High byte of result
-	ldx	cursor_flag	; Get old value
+	lda	cursor_flag	; Get old value
+	pha
 	sty	cursor_flag	; Set new value
 	tya
 	beq	L1
 	lda	curHeight	; prepare cursor
 	jsr	InitTextPrompt
-	lda	cursor_x	; position it on screen
-	sta	r4L
-	lda	cursor_x+1
-	sta	r4H
-	lda	cursor_y
-	sec
-	sbc	curHeight
-	sta	r5L
-	lda	#1
-	sta	r3L
-	jsr	PosSprite
-L1:	rts
+	jsr	update_cursor	; place it on screen
+L1:	pla
+	rts
diff --git a/libsrc/geos/conio/gotoxy.s b/libsrc/geos/conio/gotoxy.s
index 58ba858d4..d3da47db9 100644
--- a/libsrc/geos/conio/gotoxy.s
+++ b/libsrc/geos/conio/gotoxy.s
@@ -3,29 +3,38 @@
 ; Maciej 'YTM/Elysium' Witkowiak
 ;
 ; 27.10.2001
+; 06.03.2002
 
 ; void gotox (unsigned char x);
 ; void gotoy (unsigned char y);
 ; void gotoxy (unsigned char x, unsigned char y);
 
-	    .export _gotox, _gotoy, _gotoxy
+	    .export _gotox, _gotoy, _gotoxy, fixcursor
 	    .import popa
 
 	    .include "../inc/jumptab.inc"
-	    .include "cursor.inc"
+	    .include "../inc/cursor.inc"
 
-_gotox:	    sta cursor_x
+_gotox:	    sta cursor_c
 	    jmp fixcursor
 
-_gotoy:	    sta cursor_y
+_gotoy:	    sta cursor_r
+	    inc cursor_r
 	    jmp fixcursor
 
-_gotoxy:    sta cursor_y
+_gotoxy:    sta cursor_r
+	    inc cursor_r
 	    jsr popa
-	    sta cursor_x
+	    sta cursor_c
 
 ; convert 8x8 x/y coordinates to GEOS hires
 fixcursor:
+	    lda cursor_c
+	    sta cursor_x
+	    lda #0
+	    sta cursor_x+1
+	    lda cursor_r
+	    sta cursor_y
 	    ldx #cursor_x
 	    ldy #3
 	    jsr DShiftLeft
diff --git a/libsrc/geos/conio/revers.s b/libsrc/geos/conio/revers.s
index b2d208838..cd5ea66bb 100644
--- a/libsrc/geos/conio/revers.s
+++ b/libsrc/geos/conio/revers.s
@@ -7,7 +7,7 @@
 ; unsigned char revers (unsigned char onoff);
 
 	    .export _revers
-	    .import tmp1
+	    .importzp tmp1
 
 	    .include "../inc/geossym.inc"
 	    .include "../inc/const.inc"
diff --git a/libsrc/geos/conio/screensize.s b/libsrc/geos/conio/screensize.s
index c04fc92ae..00524c1b8 100644
--- a/libsrc/geos/conio/screensize.s
+++ b/libsrc/geos/conio/screensize.s
@@ -3,6 +3,7 @@
 ; Maciej 'YTM/Elysium' Witkowiak
 ;
 ; 27.10.2001
+; 06.03.2002
 
 ; void screensize (unsigned char* x, unsigned char* y);
 ;
@@ -11,6 +12,7 @@
 
 	.import	 	popax
 	.importzp	ptr1, ptr2
+	.import		xsize, ysize
 	
 	.include 	"../inc/geossym.inc"
 
@@ -23,13 +25,8 @@ _screensize:
 	sta	ptr2
 	stx	ptr2+1
 
-	ldy	#0
-	lda	graphMode
-	bpl	L1
-	lda	#80		; 80 columns (more or less)
-	.byte	$2c
-L1:	lda	#40		; 40 columns (more or less)
+	lda	xsize
 	sta	(ptr2),y
-	lda	#24		; something like that for Y size
+	lda	ysize
 	sta	(ptr1),y
    	rts
diff --git a/libsrc/geos/conio/where.s b/libsrc/geos/conio/where.s
index 8ba44e94e..14cd07981 100644
--- a/libsrc/geos/conio/where.s
+++ b/libsrc/geos/conio/where.s
@@ -3,6 +3,7 @@
 ; Maciej 'YTM/Elysium' Witkowiak
 ;
 ; 27.10.2001
+; 06.03.2002
 
 ; unsigned char wherex (void);
 ; unsigned char wherey (void);
@@ -11,20 +12,10 @@
 	    .importzp tmp1, tmp2
 
 	    .include "../inc/jumptab.inc"
-	    .include "cursor.inc"
+	    .include "../inc/cursor.inc"
 
-_wherex:    lda cursor_x
-	    sta tmp1
-	    lda cursor_x+1
-	    sta tmp2
-	    ldx #tmp1
-	    ldy #3
-	    jsr DShiftRight
-	    lda tmp1
+_wherex:    lda cursor_c
 	    rts
 
-_wherey:    lda cursor_y
-	    lsr
-	    lsr
-	    lsr
+_wherey:    lda cursor_r
 	    rts
diff --git a/libsrc/geos/system/Makefile b/libsrc/geos/system/Makefile
index 4b117ab66..e3508b4de 100644
--- a/libsrc/geos/system/Makefile
+++ b/libsrc/geos/system/Makefile
@@ -8,7 +8,7 @@
 	@$(AS) -o $@ $(AFLAGS) $<
 
 
-S_OBJS	= callroutine.o enterdesktop.o firstinit.o getrandom.o getserialnumber.o\
+S_OBJS	= ctype.o callroutine.o enterdesktop.o firstinit.o getrandom.o getserialnumber.o\
 	  initdoneio.o mainloop.o panic.o tobasic.o setdevice.o get_ostype.o
 
 all: $(S_OBJS)