From c604e166302d214753cc9794083a51d507c0dae2 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 12 Apr 2020 23:52:23 +0200 Subject: [PATCH] Added first conio implementation compatible with cc65 and included a conio example from cc65. --- .../mos6502-common/vwum1=vbuaa_plus_vbuyy.asm | 7 + src/main/kc/include/conio.h | 77 + src/main/kc/include/keyboard.h | 4 + src/main/kc/lib/conio.c | 182 + src/main/kc/lib/keyboard.c | 8 + .../dk/camelot64/kickc/test/TestPrograms.java | 5 + src/test/kc/examples/conio/nacht-screen.c | 92 + src/test/ref/c64dtv-gfxexplorer.log | 149 +- src/test/ref/c64dtv-gfxmodes.log | 81 +- src/test/ref/complex/prebob/grid-bobs.log | 89 +- src/test/ref/complex/prebob/vogel-bobs.log | 95 +- src/test/ref/complex/prebob/vogel-sprites.log | 31 +- src/test/ref/complex/tetris/tetris.log | 321 +- .../ref/examples/chargen/chargen-analysis.log | 31 +- src/test/ref/examples/conio/nacht-screen.asm | 639 ++ src/test/ref/examples/conio/nacht-screen.cfg | 422 + src/test/ref/examples/conio/nacht-screen.log | 8232 +++++++++++++++++ src/test/ref/examples/conio/nacht-screen.sym | 293 + src/test/ref/keyboard-glitch.log | 29 +- src/test/ref/scan-desire-problem.log | 29 +- src/test/ref/semi-struct-2.log | 39 +- src/test/ref/test-keyboard-space.log | 25 +- src/test/ref/test-keyboard.log | 27 +- 23 files changed, 10440 insertions(+), 467 deletions(-) create mode 100644 src/main/fragment/mos6502-common/vwum1=vbuaa_plus_vbuyy.asm create mode 100644 src/main/kc/include/conio.h create mode 100644 src/main/kc/lib/conio.c create mode 100644 src/test/kc/examples/conio/nacht-screen.c create mode 100644 src/test/ref/examples/conio/nacht-screen.asm create mode 100644 src/test/ref/examples/conio/nacht-screen.cfg create mode 100644 src/test/ref/examples/conio/nacht-screen.log create mode 100644 src/test/ref/examples/conio/nacht-screen.sym diff --git a/src/main/fragment/mos6502-common/vwum1=vbuaa_plus_vbuyy.asm b/src/main/fragment/mos6502-common/vwum1=vbuaa_plus_vbuyy.asm new file mode 100644 index 000000000..b7f7bec8c --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1=vbuaa_plus_vbuyy.asm @@ -0,0 +1,7 @@ +sty $ff +clc +adc $ff +sta {m1} +lda #0 +adc #0 +sta {m1}+1 \ No newline at end of file diff --git a/src/main/kc/include/conio.h b/src/main/kc/include/conio.h new file mode 100644 index 000000000..caf43c900 --- /dev/null +++ b/src/main/kc/include/conio.h @@ -0,0 +1,77 @@ +// Provides provide console input/output +// Implements similar functions as conio.h from CC65 for compatibility +// See https://github.com/cc65/cc65/blob/master/include/conio.h + +// clears the screen and moves the cursor to the upper left-hand corner of the screen. +void clrscr(void); + +// Set the cursor to the specified position +void gotoxy(unsigned char x, unsigned char y); + +// Return the X position of the cursor +unsigned char wherex(void); + +// Return the Y position of the cursor +unsigned char wherey(void); + +// Return the current screen size. +void screensize(unsigned char* x, unsigned char* y); + +// Output one character at the current cursor position +void cputc(char c); + +// Move cursor and output one character +// Same as "gotoxy (x, y); cputc (c);" +void cputcxy (unsigned char x, unsigned char y, char c); + +// Output a NUL-terminated string at the current cursor position +void cputs(const char* s); + +// Move cursor and output a NUL-terminated string +// Same as "gotoxy (x, y); puts (s);" +void cputsxy(unsigned char x, unsigned char y, const char* s); + +// Output a horizontal line with the given length starting at the current cursor position. +void chline(unsigned char length); + +// Output a vertical line with the given length at the current cursor position. +void cvline (unsigned char length); + +// Move cursor and output a vertical line with the given length +// Same as "gotoxy (x, y); cvline (length);" +void cvlinexy(unsigned char x, unsigned char y, unsigned char length); + +// Set the color for text output. The old color setting is returned. +unsigned char textcolor(unsigned char color); + +// Set the color for the background. The old color setting is returned. +unsigned char bgcolor(unsigned char color); + +// Set the color for the border. The old color setting is returned. +unsigned char bordercolor(unsigned char color); + +// Return true if there's a key waiting, return false if not +unsigned char kbhit (void); + +// If onoff is 1, a cursor is displayed when waiting for keyboard input. +// If onoff is 0, the cursor is hidden when waiting for keyboard input. +// The function returns the old cursor setting. +unsigned char cursor(unsigned char onoff); + + +// The horizontal line character +const char CH_HLINE = 0x40; +// The vertical line character +const char CH_VLINE = 0x5d; +// The upper left corner character +const char CH_ULCORNER = 0x70; +// The upper right corner character +const char CH_URCORNER = 0x6e; +// The lower left corner character +const char CH_LLCORNER = 0x6d; +// The lower right corner character +const char CH_LRCORNER = 0x7d; +// The left T character +const char CH_LTEE = 0x6b; +// The right T character +const char CH_RTEE = 0x73; diff --git a/src/main/kc/include/keyboard.h b/src/main/kc/include/keyboard.h index 312d4700a..ed3d85f9e 100644 --- a/src/main/kc/include/keyboard.h +++ b/src/main/kc/include/keyboard.h @@ -87,6 +87,10 @@ const byte KEY_RUNSTOP = $3f; // Initialize keyboard reading by setting CIA#$ Data Direction Registers void keyboard_init(); +// Check if any key is currently pressed on the keyboard matrix +// Return 0 if no key is pressed and not 0 if any key is pressed +byte keyboard_matrix_any(void); + // Read a single row of the keyboard matrix // The row ID (0-7) of the keyboard matrix row to read. See the C64 key matrix for row IDs. // Returns the keys pressed on the row as bits according to the C64 key matrix. diff --git a/src/main/kc/lib/conio.c b/src/main/kc/lib/conio.c new file mode 100644 index 000000000..07f98c5ab --- /dev/null +++ b/src/main/kc/lib/conio.c @@ -0,0 +1,182 @@ +// Provides provide console input/output +// Implements similar functions as conio.h from CC65 for compatibility +// See https://github.com/cc65/cc65/blob/master/include/conio.h +#include + +// The text screen address +char * const CONIO_SCREEN_TEXT = 0x0400; +// The color screen address +char * const CONIO_SCREEN_COLORS = 0xd800; +// The background color register address +char * const CONIO_BGCOLOR = 0xd021; +// The border color register address +char * const CONIO_BORDERCOLOR = 0xd020; +// CIA#1 Port A: keyboard matrix columns and joystick #2 +char* const CONIO_CIA1_PORT_A = 0xdc00; +// CIA#1 Port B: keyboard matrix rows and joystick #1. +char* const CONIO_CIA1_PORT_B = 0xdc01; +// The screen width +const char CONIO_WIDTH = 40; +// The screen height +const char CONIO_HEIGHT = 25; + +// The default text color +const char CONIO_TEXTCOLOR_DEFAULT = 0xe; + +// The current cursor x-position +char conio_cursor_x = 0; +// The current cursor y-position +char conio_cursor_y = 0; +// The current cursor address +char *conio_cursor_text = CONIO_SCREEN_TEXT; +// The current cursor address +char *conio_cursor_color = CONIO_SCREEN_COLORS; +// The current text color +char conio_textcolor = CONIO_TEXTCOLOR_DEFAULT; +// Is a cursor whown when waiting for input (0: no, other: yes) +char conio_display_cursor = 0; + +// clears the screen and moves the cursor to the upper left-hand corner of the screen. +void clrscr(void) { + char* line_text = CONIO_SCREEN_TEXT; + char* line_cols = CONIO_SCREEN_COLORS; + for( char l=0;l=CONIO_WIDTH) x = 0; + if(y>=CONIO_HEIGHT) y = 0; + conio_cursor_x = x; + conio_cursor_y = y; + unsigned int offset = (unsigned int)y*CONIO_WIDTH + x; + conio_cursor_text = CONIO_SCREEN_TEXT + offset; + conio_cursor_color = CONIO_SCREEN_COLORS + offset; +} + +// Return the current screen size. +void screensize(unsigned char* x, unsigned char* y) { + *x = CONIO_WIDTH; + *y = CONIO_HEIGHT; +} + +// Return the X position of the cursor +inline unsigned char wherex(void) { + return conio_cursor_x; +} + +// Return the Y position of the cursor +inline unsigned char wherey(void) { + return conio_cursor_y; +} + +// Output one character at the current cursor position +// Moves the cursor forward +void cputc(char c) { + if(c=='\n') { + gotoxy(0, conio_cursor_y+1); + } else { + *conio_cursor_text++ = c; + *conio_cursor_color++ = conio_textcolor; + if(++conio_cursor_x==CONIO_WIDTH) { + conio_cursor_x = 0; + if(++conio_cursor_y==CONIO_HEIGHT) { + gotoxy(0,0); + } + } + } +} + +// Move cursor and output one character +// Same as "gotoxy (x, y); cputc (c);" +void cputcxy(unsigned char x, unsigned char y, char c) { + gotoxy(x, y); + cputc(c); +} + + +// Output a NUL-terminated string at the current cursor position +void cputs(const char* s) { + char c; + while(c=*s++) + cputc(c); +} + +// Move cursor and output a NUL-terminated string +// Same as "gotoxy (x, y); puts (s);" +void cputsxy(unsigned char x, unsigned char y, const char* s) { + gotoxy(x, y); + cputs(s); +} + +// Output a horizontal line with the given length starting at the current cursor position. +void chline(unsigned char length) { + for(char i=0;i