-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- fixed MAT INPUT so typing in fewer values than needed doesn't raise an error - MAT INPUT now allows string input - separated out io routines
- Loading branch information
1 parent
6d1c399
commit 827d1b3
Showing
12 changed files
with
239 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* io (implementation) for RetroBASIC | ||
Copyright (C) 2024 Maury Markowitz | ||
This file is part of RetroBASIC. | ||
RetroBASIC is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2, or (at your option) | ||
any later version. | ||
RetroBASIC is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with RetroBASIC; see the file COPYING. If not, write to | ||
the Free Software Foundation, 59 Temple Place - Suite 330, | ||
Boston, MA 02111-1307, USA. */ | ||
|
||
#include "io.h" | ||
|
||
/* | ||
* Waits for a single character. Used for GET. | ||
*/ | ||
int getbyte(int fd) | ||
{ | ||
int ch; | ||
struct termios old_attrs, new_attrs; | ||
tcgetattr(STDIN_FILENO, &old_attrs); | ||
new_attrs = old_attrs; | ||
new_attrs.c_lflag &= ~(ICANON | ECHO); | ||
tcsetattr(STDIN_FILENO, TCSANOW, &new_attrs); | ||
system("stty -echo"); //shell out to kill echo | ||
ch = getchar(); | ||
system("stty echo"); | ||
tcsetattr(STDIN_FILENO, TCSANOW, &old_attrs); | ||
return ch; | ||
} | ||
|
||
/* | ||
* Gets a single keystroke, or null if no key is pressed. Used for INKEY$. | ||
*/ | ||
int getkey(int fd) | ||
{ | ||
#if _WIN32 | ||
if (kbhit) { | ||
return getch(); | ||
} else { | ||
return 0; | ||
} | ||
#else | ||
int ch; | ||
unsigned char buf[1]; | ||
struct termios old_attrs, new_attrs; | ||
tcgetattr(STDIN_FILENO, &old_attrs); | ||
new_attrs = old_attrs; | ||
cfmakeraw(&new_attrs); | ||
new_attrs.c_cc[VMIN] = 0; | ||
new_attrs.c_cc[VTIME] = 0; | ||
new_attrs.c_lflag &= ~(ICANON | ECHO); | ||
// newt.c_cc[VMIN] = 0; | ||
tcsetattr(STDIN_FILENO, TCSANOW, &new_attrs); | ||
ch = (int)read(STDIN_FILENO, buf, 1); | ||
if (ch > 0) | ||
ch = buf[0]; | ||
tcsetattr(STDIN_FILENO, TCSANOW, &old_attrs); | ||
return ch; | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* io (header) for RetroBASIC | ||
Copyright (C) 2024 Maury Markowitz | ||
This file is part of RetroBASIC. | ||
RetroBASIC is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2, or (at your option) | ||
any later version. | ||
RetroBASIC is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with RetroBASIC; see the file COPYING. If not, write to | ||
the Free Software Foundation, 59 Temple Place - Suite 330, | ||
Boston, MA 02111-1307, USA. */ | ||
|
||
#ifndef io_h | ||
#define io_h | ||
|
||
#include "stdhdr.h" | ||
|
||
#if _WIN32 | ||
#include <conio.h> | ||
#else | ||
#include <sys/termios.h> | ||
#endif | ||
|
||
#include <unistd.h> | ||
|
||
/** | ||
* @file io.h | ||
* @author Maury Markowitz | ||
* @date 31 December 2024 | ||
* @brief Input/output and file handling routines. | ||
* | ||
* | ||
*/ | ||
|
||
/** | ||
* Waits for a single character. Used for GET. | ||
* | ||
* @param fd, the file descriptor, typically STDIN_FILENO. | ||
* @return the keycode, NULL if an error occurred. | ||
*/ | ||
int getbyte(int fd); | ||
|
||
/** | ||
* Gets a single keystroke, or null if no key is pressed. Used for INKEY$. | ||
* | ||
* @param fd, the file descriptor, typically STDIN_FILENO. | ||
* @return the keycode, NULL if no key is pressed or an error occurred. | ||
* | ||
* See: https://stackoverflow.com/questions/1798511/how-to-avoid-pressing-enter-with-getchar-for-reading-a-single-character-only | ||
*/ | ||
int getkey(int fd); | ||
|
||
|
||
#endif /* io_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.