aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Serpell <daniel.serpell@gmail.com>2020-05-11 23:14:09 -0400
committerDaniel Serpell <daniel.serpell@gmail.com>2020-05-11 23:14:09 -0400
commitfd62639943ed9e092e88461f8da5d95f57aaad09 (patch)
treef9449e8418af0182ae097691235049a047da11d5
parentcaa49053f601df1dbb62194d62f69b533e003608 (diff)
downloademu2-fd62639943ed9e092e88461f8da5d95f57aaad09.tar.gz
Fixes line input after initializing video output.
-rw-r--r--src/dos.c86
-rw-r--r--src/video.c5
-rw-r--r--src/video.h2
3 files changed, 71 insertions, 22 deletions
diff --git a/src/dos.c b/src/dos.c
index eb55f87..84a6816 100644
--- a/src/dos.c
+++ b/src/dos.c
@@ -855,6 +855,69 @@ static void char_input(int brk)
last_key = 0;
}
+static int line_input(FILE *f, uint8_t *buf, int max)
+{
+ if(video_active())
+ {
+ int len = 0;
+ while(len < max - 1)
+ {
+ char key = getch(1);
+ if(key == '\r')
+ {
+ video_putch('\r');
+ video_putch('\n');
+ buf[len] = '\r';
+ buf[len+1] = '\n';
+ len += 2;
+ break;
+ }
+ else if(key == 8)
+ {
+ if(len)
+ {
+ len--;
+ video_putch(key);
+ video_putch(' ');
+ video_putch(key);
+ }
+ }
+ else if(len < max && video_get_col() < 79)
+ {
+ video_putch(key);
+ buf[len] = key;
+ len++;
+ }
+ }
+ return len;
+ }
+ else
+ {
+ int i, cr = 0;
+ for(i = 0; i < max; i++)
+ {
+ int c = fgetc(f);
+ if(c < 0)
+ break;
+ if(c == '\n' && !cr && i < max)
+ {
+ cr = 1;
+ buf[i] = '\r';
+ i++;
+ }
+ else if(c == '\r')
+ cr = 1;
+ buf[i] = c;
+ if(c == '\n')
+ {
+ i++;
+ break;
+ }
+ }
+ return i;
+ }
+}
+
static void int21_debug(void)
{
static const char *func_names[] =
@@ -1319,29 +1382,8 @@ void int21()
// If read from "CON", reads up to the first "CR":
if(devinfo[cpuGetBX()] == 0x80D3)
{
- int i, max = cpuGetCX(), cr = 0;
suspend_keyboard();
- for(i = 0; i < max; i++)
- {
- int c = fgetc(f);
- if(c < 0)
- break;
- if(c == '\n' && !cr && i < max)
- {
- cr = 1;
- buf[i] = '\r';
- i++;
- }
- else if(c == '\r')
- cr = 1;
- buf[i] = c;
- if(c == '\n')
- {
- i++;
- break;
- }
- }
- cpuSetAX(i);
+ cpuSetAX(line_input(f, buf, cpuGetCX()));
}
else
{
diff --git a/src/video.c b/src/video.c
index 703b159..1b1c45c 100644
--- a/src/video.c
+++ b/src/video.c
@@ -697,3 +697,8 @@ void video_crtc_write(int port, uint8_t value)
else
crtc_port = value;
}
+
+int video_get_col(void)
+{
+ return vid_posx;
+}
diff --git a/src/video.h b/src/video.h
index 7661223..aef252f 100644
--- a/src/video.h
+++ b/src/video.h
@@ -9,6 +9,8 @@ void check_screen(void);
int video_active(void);
// Writes a character to the video screen
void video_putch(char ch);
+// Get current column in current page
+int video_get_col(void);
// CRTC port read/write
uint8_t video_crtc_read(int port);
void video_crtc_write(int port, uint8_t value);
Un proyecto texto-plano.xyz