From 23336420b16dc32a68dd4a97515a6493fb2e0178 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 00:23:58 +0200 Subject: [PATCH] a bunch of simple conio fixes, makes a few more samples work --- asminc/c65.inc | 4 ++ asminc/mega65.inc | 4 ++ libsrc/c65/_scrsize.s | 12 ++++ libsrc/c65/bordercolor.s | 17 ++++++ libsrc/c65/clrscr.s | 15 +++++ libsrc/c65/color.s | 24 ++++++++ libsrc/c65/conio.s | 10 +++ libsrc/c65/cputc.s | 118 ++++++++++++++++++++++++++++++++++++ libsrc/c65/devnum.s | 7 +++ libsrc/c65/kbhit.s | 24 ++++++++ libsrc/c65/status.s | 5 ++ libsrc/mega65/_scrsize.s | 12 ++++ libsrc/mega65/bordercolor.s | 17 ++++++ libsrc/mega65/clrscr.s | 15 +++++ libsrc/mega65/color.s | 24 ++++++++ libsrc/mega65/conio.s | 10 +++ libsrc/mega65/cputc.s | 118 ++++++++++++++++++++++++++++++++++++ libsrc/mega65/devnum.s | 7 +++ libsrc/mega65/kbhit.s | 24 ++++++++ libsrc/mega65/status.s | 5 ++ samples/Makefile | 14 ++++- 21 files changed, 484 insertions(+), 2 deletions(-) create mode 100644 libsrc/c65/_scrsize.s create mode 100644 libsrc/c65/bordercolor.s create mode 100644 libsrc/c65/clrscr.s create mode 100644 libsrc/c65/color.s create mode 100644 libsrc/c65/conio.s create mode 100644 libsrc/c65/cputc.s create mode 100644 libsrc/c65/devnum.s create mode 100644 libsrc/c65/kbhit.s create mode 100644 libsrc/c65/status.s create mode 100644 libsrc/mega65/_scrsize.s create mode 100644 libsrc/mega65/bordercolor.s create mode 100644 libsrc/mega65/clrscr.s create mode 100644 libsrc/mega65/color.s create mode 100644 libsrc/mega65/conio.s create mode 100644 libsrc/mega65/cputc.s create mode 100644 libsrc/mega65/devnum.s create mode 100644 libsrc/mega65/kbhit.s create mode 100644 libsrc/mega65/status.s diff --git a/asminc/c65.inc b/asminc/c65.inc index 4c10431ab..79a4e7b03 100644 --- a/asminc/c65.inc +++ b/asminc/c65.inc @@ -233,3 +233,7 @@ CASSMOT = $20 ; Cassette motor on TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF + +; temporary, to get conio working +XSIZE = 80 +YSIZE = 50 diff --git a/asminc/mega65.inc b/asminc/mega65.inc index 4c10431ab..79a4e7b03 100644 --- a/asminc/mega65.inc +++ b/asminc/mega65.inc @@ -233,3 +233,7 @@ CASSMOT = $20 ; Cassette motor on TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF + +; temporary, to get conio working +XSIZE = 80 +YSIZE = 50 diff --git a/libsrc/c65/_scrsize.s b/libsrc/c65/_scrsize.s new file mode 100644 index 000000000..57ad4f30f --- /dev/null +++ b/libsrc/c65/_scrsize.s @@ -0,0 +1,12 @@ +; +; Ullrich von Bassewitz, 26.10.2000 +; +; Screen size variables +; + + .export screensize + .import SCREEN + +screensize = SCREEN + + diff --git a/libsrc/c65/bordercolor.s b/libsrc/c65/bordercolor.s new file mode 100644 index 000000000..6b3c7f86c --- /dev/null +++ b/libsrc/c65/bordercolor.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _bordercolor + + .include "c65.inc" + +_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts + diff --git a/libsrc/c65/clrscr.s b/libsrc/c65/clrscr.s new file mode 100644 index 000000000..84fef5eac --- /dev/null +++ b/libsrc/c65/clrscr.s @@ -0,0 +1,15 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void clrscr (void); +; + + .export _clrscr + + .include "cbm_kernal.inc" + +;_clrscr = CLRSCR + +_clrscr: + lda #$93 + jmp CHROUT diff --git a/libsrc/c65/color.s b/libsrc/c65/color.s new file mode 100644 index 000000000..b80ba2367 --- /dev/null +++ b/libsrc/c65/color.s @@ -0,0 +1,24 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; + + + .export _textcolor, _bgcolor + + .include "c65.inc" + +_textcolor: + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts + + +_bgcolor: + ldx VIC_BG_COLOR0 ; get old value + sta VIC_BG_COLOR0 ; set new value + txa + rts diff --git a/libsrc/c65/conio.s b/libsrc/c65/conio.s new file mode 100644 index 000000000..6c90a6d2e --- /dev/null +++ b/libsrc/c65/conio.s @@ -0,0 +1,10 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; Low level stuff for screen output/console input +; + + .exportzp CURS_X, CURS_Y + + .include "c65.inc" + diff --git a/libsrc/c65/cputc.s b/libsrc/c65/cputc.s new file mode 100644 index 000000000..a34262437 --- /dev/null +++ b/libsrc/c65/cputc.s @@ -0,0 +1,118 @@ +; +; Ullrich von Bassewitz, 1998-08-06, 2009-09-26 +; +; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); +; void __fastcall__ cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import gotoxy + .import PLOT + + .include "c65.inc" + + +_cputcxy: + pha ; Save C + jsr gotoxy ; Set cursor, drop x and y + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + + cmp #' ' + bcc cputdirect ; Other control char + tay + bmi L10 + cmp #$60 + bcc L2 + and #$DF + bne cputdirect ; Branch always +L2: and #$3F + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + iny + cpy #XSIZE + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + rts + +newline: + clc + lda #XSIZE + adc SCREEN_PTR + sta SCREEN_PTR + bcc L4 + inc SCREEN_PTR+1 + clc +L4: lda #XSIZE + adc CRAM_PTR + sta CRAM_PTR + bcc L5 + inc CRAM_PTR+1 +L5: inc CURS_Y + rts + +; Handle character if high bit set + +L10: and #$7F + cmp #$7F ; PI? + bne L11 + lda #$5E ; Load screen code for PI +L11: ora #$40 + bne cputdirect + + + +; Set cursor position, calculate RAM pointers. + +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor + + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: + ora RVS ; Set revers bit + ldy CURS_X + + pha + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta SCREEN_PTR + 1 + pla + + sta (SCREEN_PTR),y ; Set char + + lda SCREEN_PTR + 1 + sec + sbc #>$0800 + sta SCREEN_PTR + 1 + + lda CHARCOLOR +; lda #$88 +; sta (CRAM_PTR),y ; Set color + rts diff --git a/libsrc/c65/devnum.s b/libsrc/c65/devnum.s new file mode 100644 index 000000000..412b63fd7 --- /dev/null +++ b/libsrc/c65/devnum.s @@ -0,0 +1,7 @@ +; +; Oliver Schmidt, 2010-02-14 +; + + .include "c65.inc" + + .exportzp devnum := DEVNUM diff --git a/libsrc/c65/kbhit.s b/libsrc/c65/kbhit.s new file mode 100644 index 000000000..63b34629b --- /dev/null +++ b/libsrc/c65/kbhit.s @@ -0,0 +1,24 @@ + + + ; FIXME: is $d610 mega65 specific? + ; FIXME: this should rather use the kernal (with keyboard buffer etc) + + .export _cgetc +_cgetc: + +: lda $d610 + beq :- + ldx #0 + stx $d610 + rts + + .export _kbhit +_kbhit: + lda $d610 + beq :+ + + lda #1 +: + ldx #0 + rts + diff --git a/libsrc/c65/status.s b/libsrc/c65/status.s new file mode 100644 index 000000000..c6f279230 --- /dev/null +++ b/libsrc/c65/status.s @@ -0,0 +1,5 @@ +; +; Oliver Schmidt, 2012-09-30 +; + + .exportzp ST := $90 ; IEC status byte diff --git a/libsrc/mega65/_scrsize.s b/libsrc/mega65/_scrsize.s new file mode 100644 index 000000000..57ad4f30f --- /dev/null +++ b/libsrc/mega65/_scrsize.s @@ -0,0 +1,12 @@ +; +; Ullrich von Bassewitz, 26.10.2000 +; +; Screen size variables +; + + .export screensize + .import SCREEN + +screensize = SCREEN + + diff --git a/libsrc/mega65/bordercolor.s b/libsrc/mega65/bordercolor.s new file mode 100644 index 000000000..2ebf83766 --- /dev/null +++ b/libsrc/mega65/bordercolor.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _bordercolor + + .include "mega65.inc" + +_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts + diff --git a/libsrc/mega65/clrscr.s b/libsrc/mega65/clrscr.s new file mode 100644 index 000000000..84fef5eac --- /dev/null +++ b/libsrc/mega65/clrscr.s @@ -0,0 +1,15 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void clrscr (void); +; + + .export _clrscr + + .include "cbm_kernal.inc" + +;_clrscr = CLRSCR + +_clrscr: + lda #$93 + jmp CHROUT diff --git a/libsrc/mega65/color.s b/libsrc/mega65/color.s new file mode 100644 index 000000000..094bf9ed8 --- /dev/null +++ b/libsrc/mega65/color.s @@ -0,0 +1,24 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; + + + .export _textcolor, _bgcolor + + .include "mega65.inc" + +_textcolor: + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts + + +_bgcolor: + ldx VIC_BG_COLOR0 ; get old value + sta VIC_BG_COLOR0 ; set new value + txa + rts diff --git a/libsrc/mega65/conio.s b/libsrc/mega65/conio.s new file mode 100644 index 000000000..14052c5a1 --- /dev/null +++ b/libsrc/mega65/conio.s @@ -0,0 +1,10 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; Low level stuff for screen output/console input +; + + .exportzp CURS_X, CURS_Y + + .include "mega65.inc" + diff --git a/libsrc/mega65/cputc.s b/libsrc/mega65/cputc.s new file mode 100644 index 000000000..ad93ba7e5 --- /dev/null +++ b/libsrc/mega65/cputc.s @@ -0,0 +1,118 @@ +; +; Ullrich von Bassewitz, 1998-08-06, 2009-09-26 +; +; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); +; void __fastcall__ cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import gotoxy + .import PLOT + + .include "mega65.inc" + + +_cputcxy: + pha ; Save C + jsr gotoxy ; Set cursor, drop x and y + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + + cmp #' ' + bcc cputdirect ; Other control char + tay + bmi L10 + cmp #$60 + bcc L2 + and #$DF + bne cputdirect ; Branch always +L2: and #$3F + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + iny + cpy #XSIZE + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + rts + +newline: + clc + lda #XSIZE + adc SCREEN_PTR + sta SCREEN_PTR + bcc L4 + inc SCREEN_PTR+1 + clc +L4: lda #XSIZE + adc CRAM_PTR + sta CRAM_PTR + bcc L5 + inc CRAM_PTR+1 +L5: inc CURS_Y + rts + +; Handle character if high bit set + +L10: and #$7F + cmp #$7F ; PI? + bne L11 + lda #$5E ; Load screen code for PI +L11: ora #$40 + bne cputdirect + + + +; Set cursor position, calculate RAM pointers. + +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor + + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: + ora RVS ; Set revers bit + ldy CURS_X + + pha + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta SCREEN_PTR + 1 + pla + + sta (SCREEN_PTR),y ; Set char + + lda SCREEN_PTR + 1 + sec + sbc #>$0800 + sta SCREEN_PTR + 1 + + lda CHARCOLOR +; lda #$88 +; sta (CRAM_PTR),y ; Set color + rts diff --git a/libsrc/mega65/devnum.s b/libsrc/mega65/devnum.s new file mode 100644 index 000000000..898989766 --- /dev/null +++ b/libsrc/mega65/devnum.s @@ -0,0 +1,7 @@ +; +; Oliver Schmidt, 2010-02-14 +; + + .include "mega65.inc" + + .exportzp devnum := DEVNUM diff --git a/libsrc/mega65/kbhit.s b/libsrc/mega65/kbhit.s new file mode 100644 index 000000000..63b34629b --- /dev/null +++ b/libsrc/mega65/kbhit.s @@ -0,0 +1,24 @@ + + + ; FIXME: is $d610 mega65 specific? + ; FIXME: this should rather use the kernal (with keyboard buffer etc) + + .export _cgetc +_cgetc: + +: lda $d610 + beq :- + ldx #0 + stx $d610 + rts + + .export _kbhit +_kbhit: + lda $d610 + beq :+ + + lda #1 +: + ldx #0 + rts + diff --git a/libsrc/mega65/status.s b/libsrc/mega65/status.s new file mode 100644 index 000000000..c6f279230 --- /dev/null +++ b/libsrc/mega65/status.s @@ -0,0 +1,5 @@ +; +; Oliver Schmidt, 2012-09-30 +; + + .exportzp ST := $90 ; IEC status byte diff --git a/samples/Makefile b/samples/Makefile index 8974ce1b6..7d506e135 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -241,7 +241,12 @@ EXELIST_c64 = \ tgidemo EXELIST_c65 = \ - checkversion + ascii \ + checkversion \ + enumdevdir \ + hello \ + sieve \ + tinyshell EXELIST_c128 = \ ascii \ @@ -316,7 +321,12 @@ EXELIST_lynx = \ notavailable EXELIST_mega65 = \ - checkversion + ascii \ + checkversion \ + enumdevdir \ + hello \ + sieve \ + tinyshell EXELIST_nes = \ hello