summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2002-04-17 22:05:01 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:46 +0200
commit352e3b3230dfc6746be6d53325ffe1e33efc5289 (patch)
tree4c169beb4657a1ed3a046817db01cbe49b17017c /libc
parentdf538463687d768b6ee8247ff4412b78850e7404 (diff)
downloaddev86-352e3b3230dfc6746be6d53325ffe1e33efc5289.tar.gz
Import Dev86src-0.16.3.tar.gzv0.16.3
Diffstat (limited to 'libc')
-rw-r--r--libc/Makefile14
-rw-r--r--libc/bios/Makefile12
-rw-r--r--libc/bios/README3
-rw-r--r--libc/bios/ansi.c262
-rw-r--r--libc/bios/bios.c12
-rw-r--r--libc/bios/bios_min.c61
-rw-r--r--libc/bios/bios_vid.c431
-rw-r--r--libc/bios/vt52.c202
-rw-r--r--libc/conio/Makefile9
-rw-r--r--libc/conio/conio.c39
-rw-r--r--libc/conio/cprintf.c2
-rw-r--r--libc/include/conio.h1
-rw-r--r--libc/include/ctype.h24
-rw-r--r--libc/misc/ctype.c3
-rw-r--r--libc/misc/strtol.c15
15 files changed, 682 insertions, 408 deletions
diff --git a/libc/Makefile b/libc/Makefile
index 01e05d7..d5887b2 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -9,11 +9,6 @@ else
TOP=$(TOPDIR)/libc
endif
-VERMAJOR=0
-VERMINOR=16
-VERPATCH=2
-VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH)
-
CC=bcc
CCFLAGS=-I -I$(TOP)/include
DEFS=-D__LIBC__
@@ -38,13 +33,13 @@ $(LIBC): transfer .config.dir
done
crt3.o: crt0.c Makefile
- $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c
+ $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VERSION)"' -o $@ crt0.c
crt0.o: crt0.c Makefile
- $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c
+ $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VERSION)"' -o $@ crt0.c
crtg.o: crt0.c Makefile
- $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c
+ $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VERSION)"' -o $@ crt0.c
crtX.o:
@echo "You need to define the 'PLATFORM=...' variable,"
@@ -103,6 +98,3 @@ noconfig:
rm -f .config.dir .config.lst .config.tmp
############################################################################
-
-Libc_version:
- echo $(VER) > ../Libc_version
diff --git a/libc/bios/Makefile b/libc/bios/Makefile
index 3b01e77..cd97308 100644
--- a/libc/bios/Makefile
+++ b/libc/bios/Makefile
@@ -8,9 +8,13 @@ AOBJ=bios_start.o bios_isatty.o bios_nofiles.o \
bios_read.o bios_write.o bios_lseek.o bios_close.o
BSRC=bios_vid.c
-BOBJ=bios_putc.o bios_getc.o bios_getce.o bios_khit.o bios_rdline.o
+BOBJ=bios_putch.o bios_getch.o bios_getche.o bios_cputs.o bios_kbhit.o \
+ bios_rdline.o
-OBJ=$(AOBJ) $(BOBJ) time.o fileops.o fs_dos.o rawio.o
+CSRC=bios_min.c
+COBJ=bios_putc.o bios_getc.o
+
+OBJ=$(AOBJ) $(BOBJ) $(COBJ) time.o fileops.o fs_dos.o rawio.o vt52.o ansi.o
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
@@ -24,6 +28,10 @@ $(LIBC)($(AOBJ)): $(ASRC)
$(LIBC)($(BOBJ)): $(BSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
+
+$(LIBC)($(COBJ)): $(CSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
else
all:
@:
diff --git a/libc/bios/README b/libc/bios/README
index cc883e1..4a35d6e 100644
--- a/libc/bios/README
+++ b/libc/bios/README
@@ -5,6 +5,7 @@ under the GNU Library General Public License.
This is a very simple set of functions for standalone executables.
There is a choice as to which console type you want to use, I think
-the VT52 clone is best.
+the VT52 clone is best. To activate it you have to call 'vt52_putc'
+at least once.
-Robert
diff --git a/libc/bios/ansi.c b/libc/bios/ansi.c
new file mode 100644
index 0000000..d049cf8
--- /dev/null
+++ b/libc/bios/ansi.c
@@ -0,0 +1,262 @@
+/* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+
+#if !__FIRST_ARG_IN_AX__
+#ifdef __AS386_16__
+#ifdef __STANDALONE__
+
+#include <bios.h>
+#include <errno.h>
+int errno;
+
+extern void (*__smart_putch)();
+
+#define CTRL(x) ((x)&0x1F)
+static int last_attr = 0x07;
+static int con_mode;
+static unsigned char con_height = 24, con_width = 79;
+
+static int con_colour = 0;
+static unsigned char con_row, con_col;
+
+#ifdef ANSI_CON
+#define MAX_ARGS 8
+static int colconv[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
+static int vidcnt = 0;
+static int ansi_2 = 0;
+static int ansi_argc = 0;
+static int ansi_argv[MAX_ARGS];
+static void do_ansi();
+
+ansi_putch(c)
+int c;
+{
+ if( con_mode==0 ) asm_coninit();
+ __smart_putch = ansi_putch;
+
+ if( vidcnt == 0 || c < ' ' || c > '~' )
+ {
+ switch(c & 0xFF)
+ {
+ default:
+ asm_colour(last_attr);
+ asm_putc(c);
+ break;
+ case CTRL('I'):
+ asm_gpos();
+ con_col = ((con_col+8)& -8);
+ asm_cpos(con_row, con_col);
+ break;
+ case CTRL('L'):
+ asm_cpos(0,0);
+ asm_cls();
+ break;
+ case CTRL('['):
+ vidcnt=1;
+ break;
+ }
+ return;
+ }
+
+ /* ... ansi/vt100 interpretation, this collects _all_ ansi control strings */
+ switch(vidcnt)
+ {
+ case 1: for(ansi_argc=0; ansi_argc<MAX_ARGS; ansi_argc++)
+ ansi_argv[ansi_argc] = 0;
+ ansi_2 = 0;
+ ansi_argc = 0;
+ vidcnt++;
+
+ if( c != '[' )
+ {
+ do_ansi(c + 0x1B00, ansi_argc, ansi_argv);
+ vidcnt = 0;
+ }
+ break;
+
+ case 2: if( c == ';' )
+ {
+ if( ansi_argc < MAX_ARGS )
+ ansi_argc++;
+ }
+ else if( c >= '0' && c <= '9' )
+ ansi_argv[ansi_argc] = ansi_argv[ansi_argc] * 10 + c - '0';
+ else if( c >= '@' )
+ {
+ do_ansi(c+ansi_2, ++ansi_argc, ansi_argv);
+ vidcnt = 0;
+ }
+ else
+ ansi_2 = (c<<8);
+ break;
+
+ default: vidcnt = 0; /* This definitly won't happen ... definitly ... */
+ }
+}
+
+void
+do_ansi(ctrl, argc, argv)
+int ctrl, argc, *argv;
+{
+ switch(ctrl)
+ {
+ case 'A':
+ case 'B':
+ case 'C':
+ case 'D':
+ asm_gpos();
+ if( argv[0] < 1 ) argv[0] = 1;
+ switch(ctrl)
+ {
+ case 'A': if( argv[0]>con_row ) con_row=0; else con_row-=argv[0]; break;
+ case 'B': if( argv[0]+con_row>con_height )
+ con_row = con_height;
+ else
+ con_row += argv[0];
+ break;
+ case 'C': if( argv[0]+con_col>con_width )
+ con_col = con_width;
+ else
+ con_col += argv[0];
+ break;
+ case 'D': if( argv[0]>con_col ) con_col=0; else con_col-=argv[0]; break;
+ }
+ asm_cpos(con_row, con_col);
+ break;
+
+ case 'H':
+ if( --argv[0] < 0 ) argv[0] = 0;
+ if( --argv[1] < 0 ) argv[1] = 0;
+ asm_cpos(argv[0],argv[1]);
+ break;
+ case 'J': if( argv[0] == 2 ) asm_cls();
+ break;
+ case 'm':
+ {
+ int ar;
+ for(ar=0; ar<argc; ar++) switch(argv[ar])
+ {
+ case 0: last_attr = 0x07; break;
+ case 1: last_attr |= 0x08; break;
+ case 5: last_attr |= 0x80; break;
+ case 7: last_attr = 0x70; break;
+ case 30: case 31: case 32: case 33:
+ case 34: case 35: case 36: case 37:
+ if( con_colour )
+ last_attr = ((last_attr&0xF8)|(colconv[argv[ar]-30]));
+ break;
+ case 40: case 41: case 42: case 43:
+ case 44: case 45: case 46: case 47:
+ if( con_colour )
+ last_attr = ((last_attr&0x8F)|((colconv[argv[ar]-40])<<4));
+ break;
+ default: break;
+ }
+ }
+ }
+}
+#endif
+
+static asm_coninit()
+{
+#asm
+ mov ax,#$0F00
+ int $10
+ mov _con_mode,ax
+#endasm
+ if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8);
+ if( (con_mode&0xFF) != 0x7)
+ con_colour = 1;
+}
+
+static asm_putc(c)
+{
+#asm
+#if !__FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov ax,[bx+2]
+#endif
+ cmp al,#$0A
+ jne not_nl
+ mov ax,#$0E0D
+ mov bx,#7
+ int $10
+ mov al,#$0A
+not_nl:
+ mov ah,#$0E
+ mov bx,#7
+ int $10
+#endasm
+}
+
+static asm_cls()
+{
+#asm
+ push bp ! Bug in some old BIOS`s
+ !mov ax,#$0500
+ !int $10
+ mov ax,#$0600
+ mov bh,_last_attr
+ mov cx,#$0000
+ mov dl,_con_width
+ mov dh,_con_height
+ int $10
+ pop bp
+#endasm
+}
+
+static asm_cpos(r,c)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov dh,al
+ mov ax,[bx+2]
+ mov dl,al
+#else
+ mov bx,sp
+ mov ax,[bx+2]
+ mov dh,al
+ mov ax,[bx+4]
+ mov dl,al
+#endif
+ mov ah,#$02
+ mov bx,#7
+ int $10
+#endasm
+}
+
+static asm_colour(c)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,ax
+#else
+ mov bx,sp
+ mov bx,[bx+2]
+#endif
+ mov ah,#$08
+ int $10
+ mov ah,#$09
+ mov cx,#1
+ int $10
+#endasm
+}
+
+static asm_gpos()
+{
+#asm
+ mov ah,#$03
+ mov bx,#7
+ int $10
+ mov [_con_row],dh
+ mov [_con_col],dl
+ mov ax,cx
+#endasm
+}
+
+#endif
+#endif
+#endif
diff --git a/libc/bios/bios.c b/libc/bios/bios.c
index ab592a0..3e10686 100644
--- a/libc/bios/bios.c
+++ b/libc/bios/bios.c
@@ -82,8 +82,8 @@ not_dos:
sti
zap_bss: ! Clear the BSS
- mov ax,ds
- mov es,ax ! ES now data seg
+ push ds
+ pop es ! ES now data seg
mov di,#__edata
mov cx,#__end
sub cx,di
@@ -143,21 +143,19 @@ __exit:
seg cs
cmp [dos_flag],#0 ! Should we do a DOS exit
je do_reboot
- int #$20
+ mov ax,#$4c00
+ int $21
do_reboot:
#endif
xor ax,ax
- mov es,ax
+ mov ds,ax
mov ax,cs
- seg es
mov [$E6*4+2],ax
mov ax,#iret_ins
- seg es
mov [$E6*4],ax
mov ax,#$FFFF
int $E6 ! Try to exit DOSEMU
! If we get here we`re not in dosemu.
- seg es
mov [$472],#$1234 ! Warm reboot.
jmpi $0000,$FFFF
iret_ins:
diff --git a/libc/bios/bios_min.c b/libc/bios/bios_min.c
new file mode 100644
index 0000000..ef86c4a
--- /dev/null
+++ b/libc/bios/bios_min.c
@@ -0,0 +1,61 @@
+/* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+
+#ifdef __AS386_16__
+#ifdef __STANDALONE__
+
+#include <bios.h>
+
+#ifdef L_bios_putc
+bios_putc(c)
+{
+#asm
+#if !__FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov ax,[bx+2]
+#endif
+ mov ah,#$0E
+ mov bx,#7
+ int $10
+#endasm
+}
+#endif
+
+/****************************************************************************/
+
+#ifdef L_bios_getc
+bios_getc()
+{
+#asm
+ xor ax,ax
+ int $16
+#endasm
+}
+#endif
+
+/****************************************************************************/
+
+#ifdef L_bios_khit
+bios_khit()
+{
+#asm
+ mov ah,#1
+ int $16
+ jz nokey
+ cmp ax,#0
+ jnz dort
+ mov ax,#3
+dort:
+ ret
+nokey:
+ xor ax,ax
+#endasm
+}
+#endif
+
+/****************************************************************************/
+
+#endif
+#endif
diff --git a/libc/bios/bios_vid.c b/libc/bios/bios_vid.c
index bbe7545..8c55100 100644
--- a/libc/bios/bios_vid.c
+++ b/libc/bios/bios_vid.c
@@ -3,11 +3,6 @@
* under the GNU Library General Public License.
*/
-/* Various possible console types */
-#define VT52_CON /* IMO the best, no clear to EOS/EOL tho */
-#define XANSI_CON /* Largest but still not complete */
-#define XDUMB_CON /* Can't do much */
-
#if !__FIRST_ARG_IN_AX__
#ifdef __AS386_16__
#ifdef __STANDALONE__
@@ -16,352 +11,102 @@
#include <errno.h>
int errno;
-#ifdef L_bios_putc
-#define CTRL(x) ((x)&0x1F)
-static int last_attr = 0x07;
-static int con_mode;
-static unsigned char con_height = 24, con_width = 79;
-
-static int con_colour = 0;
-static unsigned char con_row, con_col;
-
-#ifdef VT52_CON
-putch(c)
-int c;
-{
-static int ctrl = 0;
- int new_attr;
- if( con_mode==0 ) asm_coninit();
-
- switch( ctrl )
- {
- case 1:
- ctrl=0;
- switch(c)
- {
- case 'A': if( con_row ) con_row--; asm_cpos(con_row, con_col); break;
- case 'B': if( con_row != con_height ) con_row++;
- asm_cpos(con_row, con_col); break;
- case 'C': if( con_col != con_height ) con_col++;
- asm_cpos(con_row, con_col); break;
- case 'D': if( con_col ) con_col--; asm_cpos(con_row, con_col); break;
- case 'E': last_attr = 0x07; asm_cls();
- case 'H': asm_cpos(0,0); break;
- case 'J': asm_cls(); break;
- case 'K': break;
- case 'R': ctrl = 2; break; /* Foreground */
- case 'S': ctrl = 3; break; /* Background */
- case 'Y': ctrl = 4; break; /* ttypos */
- }
- break;
- case 2: ctrl=0; new_attr = (last_attr & 0xF0) + (c&0xF);
- if(0) {
- case 3: ctrl=0; new_attr = (last_attr & 0x0F) + (c<<4);
- }
- switch(c)
- {
- case '_': if( !con_colour ) last_attr = (last_attr&0x88) + 1;
- break;
- case '!': last_attr = (last_attr&0x88) + 0x70; break;
- case ' ': last_attr = 0x07; break;
- case '+': last_attr |= 0x08; break;
- case '*': last_attr |= 0x80; break;
-
- default: if( con_colour )
- last_attr = new_attr;
- }
- break;
- case 4: ctrl=5; con_col = c-' '; break;
- case 5: ctrl=0; con_row = c-' '; asm_cpos(con_row, con_col); break;
- break;
-
- default:
- if( c & 0xE0 )
- { asm_colour(last_attr) ; asm_putc(c); }
- else switch(c)
- {
- default:
- asm_putc(c);
- break;
- case CTRL('I'):
- asm_gpos();
- con_col = ((con_col+8)& -8);
- asm_cpos(con_row, con_col);
- break;
- case CTRL('L'):
- asm_cpos(0,0);
- asm_cls();
- break;
- case CTRL('['):
- ctrl = 1;
- asm_gpos();
- break;
- }
- break;
- }
-}
-#endif
-
-#ifdef ANSI_CON
-#define MAX_ARGS 8
-static int colconv[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
-static int vidcnt = 0;
-static int ansi_2 = 0;
-static int ansi_argc = 0;
-static int ansi_argv[MAX_ARGS];
-static void do_ansi();
+#ifdef L_bios_putch
+void (*__smart_putch)() = 0;
putch(c)
int c;
{
- if( con_mode==0 ) asm_coninit();
-
- if( vidcnt == 0 || c < ' ' || c > '~' )
- {
- switch(c & 0xFF)
- {
- default:
- asm_colour(last_attr);
- asm_putc(c);
- break;
- case CTRL('I'):
- asm_gpos();
- con_col = ((con_col+8)& -8);
- asm_cpos(con_row, con_col);
- break;
- case CTRL('L'):
- asm_cpos(0,0);
- asm_cls();
- break;
- case CTRL('['):
- vidcnt=1;
- break;
- }
- return;
- }
-
- /* ... ansi/vt100 interpretation, this collects _all_ ansi control strings */
- switch(vidcnt)
- {
- case 1: for(ansi_argc=0; ansi_argc<MAX_ARGS; ansi_argc++)
- ansi_argv[ansi_argc] = 0;
- ansi_2 = 0;
- ansi_argc = 0;
- vidcnt++;
-
- if( c != '[' )
- {
- do_ansi(c + 0x1B00, ansi_argc, ansi_argv);
- vidcnt = 0;
- }
- break;
-
- case 2: if( c == ';' )
- {
- if( ansi_argc < MAX_ARGS )
- ansi_argc++;
- }
- else if( c >= '0' && c <= '9' )
- ansi_argv[ansi_argc] = ansi_argv[ansi_argc] * 10 + c - '0';
- else if( c >= '@' )
- {
- do_ansi(c+ansi_2, ++ansi_argc, ansi_argv);
- vidcnt = 0;
- }
- else
- ansi_2 = (c<<8);
- break;
-
- default: vidcnt = 0; /* This definitly won't happen ... definitly ... */
+static int col = 0;
+ if (__smart_putch)
+ (*__smart_putch)(c);
+ else if (c&0xE0) {
+ col++;
+ asm_putc(c);
}
-}
-
-void
-do_ansi(ctrl, argc, argv)
-int ctrl, argc, *argv;
-{
- switch(ctrl)
+ else switch(c)
{
- case 'A':
- case 'B':
- case 'C':
- case 'D':
- asm_gpos();
- if( argv[0] < 1 ) argv[0] = 1;
- switch(ctrl)
- {
- case 'A': if( argv[0]>con_row ) con_row=0; else con_row-=argv[0]; break;
- case 'B': if( argv[0]+con_row>con_height )
- con_row = con_height;
- else
- con_row += argv[0];
- break;
- case 'C': if( argv[0]+con_col>con_width )
- con_col = con_width;
- else
- con_col += argv[0];
- break;
- case 'D': if( argv[0]>con_col ) con_col=0; else con_col-=argv[0]; break;
- }
- asm_cpos(con_row, con_col);
+ case '\t':
+ do putch(' '); while(col&7);
break;
-
- case 'H':
- if( --argv[0] < 0 ) argv[0] = 0;
- if( --argv[1] < 0 ) argv[1] = 0;
- asm_cpos(argv[0],argv[1]);
- break;
- case 'J': if( argv[0] == 2 ) asm_cls();
- break;
- case 'm':
- {
- int ar;
- for(ar=0; ar<argc; ar++) switch(argv[ar])
- {
- case 0: last_attr = 0x07; break;
- case 1: last_attr |= 0x08; break;
- case 5: last_attr |= 0x80; break;
- case 7: last_attr = 0x70; break;
- case 30: case 31: case 32: case 33:
- case 34: case 35: case 36: case 37:
- if( con_colour )
- last_attr = ((last_attr&0xF8)|(colconv[argv[ar]-30]));
- break;
- case 40: case 41: case 42: case 43:
- case 44: case 45: case 46: case 47:
- if( con_colour )
- last_attr = ((last_attr&0x8F)|((colconv[argv[ar]-40])<<4));
- break;
- default: break;
- }
- }
- }
-}
-#endif
-
-#ifdef DUMB_CON
-putch(c)
-int c;
-{
- if( con_mode==0 ) asm_coninit();
- switch(c)
- {
- default:
+ case '\n':
+ asm_putc('\r');
+ case '\r':
+ col = 0;
asm_putc(c);
break;
- case CTRL('L'):
- asm_cls();
- case CTRL('^'):
- asm_cpos(0,0);
- break;
- }
-}
-#endif
-
-static asm_coninit()
-{
+ case '\f':
+ col = 0;
#asm
- mov ax,#$0F00
- int $10
- mov _con_mode,ax
+ mov ah,#$0F
+ int $10
+ mov ah,#$00
+ int $10
#endasm
- if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8);
- if( (con_mode&0xFF) != 0x7)
- con_colour = 1;
+ break;
+ }
}
static asm_putc(c)
{
#asm
#if !__FIRST_ARG_IN_AX__
- mov bx,sp
- mov ax,[bx+2]
+ mov bx,sp
+ mov ax,[bx+2]
#endif
- cmp al,#$0A
- jne not_nl
- mov ax,#$0E0D
- mov bx,#7
- int $10
- mov al,#$0A
-not_nl:
- mov ah,#$0E
- mov bx,#7
- int $10
+ mov ah,#$0E
+ mov bx,#7
+ int $10
#endasm
}
-static asm_cls()
-{
-#asm
- push bp ! Bug in some old BIOS`s
- !mov ax,#$0500
- !int $10
- mov ax,#$0600
- mov bh,_last_attr
- mov cx,#$0000
- mov dl,_con_width
- mov dh,_con_height
- int $10
- pop bp
-#endasm
-}
+#endif
-static asm_cpos(r,c)
+/****************************************************************************/
+
+#ifdef L_bios_getch
+getch()
{
#asm
-#if __FIRST_ARG_IN_AX__
- mov bx,sp
- mov dh,al
- mov ax,[bx+2]
- mov dl,al
-#else
- mov bx,sp
- mov ax,[bx+2]
- mov dh,al
- mov ax,[bx+4]
- mov dl,al
-#endif
- mov ah,#$02
- mov bx,#7
- int $10
+ xor ax,ax
+ int $16
#endasm
}
+#endif
+
+/****************************************************************************/
-#ifndef DUMB_CON
-static asm_colour(c)
+#ifdef L_bios_kbhit
+kbhit()
{
#asm
-#if __FIRST_ARG_IN_AX__
- mov bx,ax
-#else
- mov bx,sp
- mov bx,[bx+2]
-#endif
- mov ah,#$08
- int $10
- mov ah,#$09
- mov cx,#1
- int $10
+ mov ah,#1
+ int $16
+ jz nokey
+ cmp ax,#0
+ jnz dort
+ mov ax,#3
+dort:
+ ret
+nokey:
+ xor ax,ax
#endasm
}
+#endif
+
+/****************************************************************************/
-static asm_gpos()
+#ifdef L_bios_cputs
+cputs(str)
+ char * str;
{
-#asm
- mov ah,#$03
- mov bx,#7
- int $10
- mov [_con_row],dh
- mov [_con_col],dl
- mov ax,cx
-#endasm
+ while(*str) putch(*str++);
}
#endif
-#endif
/****************************************************************************/
-#ifdef L_bios_getce
+#ifdef L_bios_getche
getche()
{
static char linebuf[80];
@@ -380,6 +125,33 @@ getche()
}
#endif
+/****************************************************************************/
+
+#ifdef L_bios_gotoxy
+static gotoxy(x,y)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov dl,al
+ mov ax,[bx+2]
+ mov dh,al
+#else
+ mov bx,sp
+ mov ax,[bx+4]
+ mov dh,al
+ mov ax,[bx+2]
+ mov dl,al
+#endif
+ mov ah,#$02
+ mov bx,#7
+ int $10
+#endasm
+}
+#endif
+
+/****************************************************************************/
+
#ifdef L_bios_rdline
bios_rdline(buf, len)
char * buf;
@@ -436,38 +208,7 @@ int len;
/****************************************************************************/
-#ifdef L_bios_getc
-getch()
-{
-#asm
- xor ax,ax
- int $16
-#endasm
-}
-#endif
-
-/****************************************************************************/
-
-#ifdef L_bios_khit
-kbhit()
-{
-#asm
- mov ah,#1
- int $16
- jz nokey
- cmp ax,#0
- jnz dort
- mov ax,#3
-dort:
- ret
-nokey:
- xor ax,ax
-#endasm
-}
-#endif
-
-/****************************************************************************/
-
#endif
#endif
#endif
+
diff --git a/libc/bios/vt52.c b/libc/bios/vt52.c
new file mode 100644
index 0000000..4574c12
--- /dev/null
+++ b/libc/bios/vt52.c
@@ -0,0 +1,202 @@
+/* Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+
+#if !__FIRST_ARG_IN_AX__
+#ifdef __AS386_16__
+#ifdef __STANDALONE__
+
+#include <bios.h>
+#include <errno.h>
+int errno;
+
+extern void (*__smart_putch)();
+
+#define CTRL(x) ((x)&0x1F)
+static int last_attr = 0x07;
+static int con_mode;
+static unsigned char con_height = 24, con_width = 79;
+
+static int con_colour = 0;
+static unsigned char con_row, con_col;
+
+vt52_putch(c)
+int c;
+{
+static int ctrl = 0;
+ int new_attr;
+ __smart_putch = vt52_putch();
+
+ if( con_mode==0 ) asm_coninit();
+
+ switch( ctrl )
+ {
+ case 1:
+ ctrl=0;
+ switch(c)
+ {
+ case 'A': if( con_row ) con_row--; asm_cpos(con_row, con_col); break;
+ case 'B': if( con_row != con_height ) con_row++;
+ asm_cpos(con_row, con_col); break;
+ case 'C': if( con_col != con_height ) con_col++;
+ asm_cpos(con_row, con_col); break;
+ case 'D': if( con_col ) con_col--; asm_cpos(con_row, con_col); break;
+ case 'E': last_attr = 0x07; asm_cls();
+ case 'H': asm_cpos(0,0); break;
+ case 'J': asm_cls(); break;
+ case 'K': break;
+ case 'R': ctrl = 2; break; /* Foreground */
+ case 'S': ctrl = 3; break; /* Background */
+ case 'Y': ctrl = 4; break; /* ttypos */
+ }
+ break;
+ case 2: ctrl=0; new_attr = (last_attr & 0xF0) + (c&0xF);
+ if(0) {
+ case 3: ctrl=0; new_attr = (last_attr & 0x0F) + (c<<4);
+ }
+ switch(c)
+ {
+ case '_': if( !con_colour ) last_attr = (last_attr&0x88) + 1;
+ break;
+ case '!': last_attr = (last_attr&0x88) + 0x70; break;
+ case ' ': last_attr = 0x07; break;
+ case '+': last_attr |= 0x08; break;
+ case '*': last_attr |= 0x80; break;
+
+ default: if( con_colour )
+ last_attr = new_attr;
+ }
+ break;
+ case 4: ctrl=5; con_col = c-' '; break;
+ case 5: ctrl=0; con_row = c-' '; asm_cpos(con_row, con_col); break;
+ break;
+
+ default:
+ if( c & 0xE0 )
+ { asm_colour(last_attr) ; asm_putc(c); }
+ else switch(c)
+ {
+ default:
+ asm_putc(c);
+ break;
+ case CTRL('I'):
+ asm_gpos();
+ con_col = ((con_col+8)& -8);
+ asm_cpos(con_row, con_col);
+ break;
+ case CTRL('L'):
+ asm_cpos(0,0);
+ asm_cls();
+ break;
+ case CTRL('['):
+ ctrl = 1;
+ asm_gpos();
+ break;
+ }
+ break;
+ }
+}
+
+static asm_coninit()
+{
+#asm
+ mov ax,#$0F00
+ int $10
+ mov _con_mode,ax
+#endasm
+ if( (con_mode &0xFF) > 39 ) con_width = (con_mode>>8);
+ if( (con_mode&0xFF) != 0x7)
+ con_colour = 1;
+}
+
+static asm_putc(c)
+{
+#asm
+#if !__FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov ax,[bx+2]
+#endif
+ cmp al,#$0A
+ jne not_nl
+ mov ax,#$0E0D
+ mov bx,#7
+ int $10
+ mov al,#$0A
+not_nl:
+ mov ah,#$0E
+ mov bx,#7
+ int $10
+#endasm
+}
+
+static asm_cls()
+{
+#asm
+ push bp ! Bug in some old BIOS`s
+ !mov ax,#$0500
+ !int $10
+ mov ax,#$0600
+ mov bh,_last_attr
+ mov cx,#$0000
+ mov dl,_con_width
+ mov dh,_con_height
+ int $10
+ pop bp
+#endasm
+}
+
+static asm_cpos(r,c)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov dh,al
+ mov ax,[bx+2]
+ mov dl,al
+#else
+ mov bx,sp
+ mov ax,[bx+2]
+ mov dh,al
+ mov ax,[bx+4]
+ mov dl,al
+#endif
+ mov ah,#$02
+ mov bx,#7
+ int $10
+#endasm
+}
+
+static asm_colour(c)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,ax
+#else
+ mov bx,sp
+ mov bx,[bx+2]
+#endif
+ mov ah,#$08
+ int $10
+ mov ah,#$09
+ mov cx,#1
+ int $10
+#endasm
+}
+
+static asm_gpos()
+{
+#asm
+ mov ah,#$03
+ mov bx,#7
+ int $10
+ mov [_con_row],dh
+ mov [_con_col],dl
+ mov ax,cx
+#endasm
+}
+
+#endif
+#endif
+#endif
+
diff --git a/libc/conio/Makefile b/libc/conio/Makefile
index 662b0ec..21b0a4d 100644
--- a/libc/conio/Makefile
+++ b/libc/conio/Makefile
@@ -3,13 +3,10 @@
# under the GNU Library General Public License.
ASRC=conio.c
-AOBJ=getch.o getche.o kbhit.o putch.o
+AOBJ=getch.o getche.o kbhit.o putch.o cputs.o gotoxy.o
-BSRC=conio.c
-BOBJ=cputs.o
-
-BIOSOBJ=$(BOBJ) cprintf.o
-DOSOBJ=$(AOBJ) $(BOBJ) cprintf.o
+BIOSOBJ=cprintf.o
+DOSOBJ=$(AOBJ) cprintf.o
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
diff --git a/libc/conio/conio.c b/libc/conio/conio.c
index ee311a5..dfe30ee 100644
--- a/libc/conio/conio.c
+++ b/libc/conio/conio.c
@@ -9,8 +9,7 @@
* I'm not sure if these should be BIOS or dos calls, so I'll assume they're
* BIOS calls but I may have to do something about Ctrl-C.
*
- * These functions are also compiled for __STANDALONE__ so if ^C or DOS
- * versions are made this will have to be addressed.
+ * Not implemented: cgets() cscanf() getpass() ungetch()
*/
#ifdef L_getch
@@ -73,22 +72,26 @@ char * str;
}
#endif
-#if 0
-
-cgets()
-{
-}
-
-cscanf()
-{
-}
-
-getpass()
-{
-}
-
-gotoxy()
+#ifdef L_gotoxy
+static gotoxy(x,y)
{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov dl,al
+ mov ax,[bx+2]
+ mov dh,al
+#else
+ mov bx,sp
+ mov ax,[bx+4]
+ mov dh,al
+ mov ax,[bx+2]
+ mov dl,al
+#endif
+ mov ah,#$02
+ mov bx,#7
+ int $10
+#endasm
}
-
#endif
+
diff --git a/libc/conio/cprintf.c b/libc/conio/cprintf.c
index 5194376..5368c89 100644
--- a/libc/conio/cprintf.c
+++ b/libc/conio/cprintf.c
@@ -11,7 +11,7 @@ static unsigned char * __numout(long i, int base);
int cprintf(char * fmt, ...)
{
register int c;
- int count = 0;
+ register int count = 0;
int type, base;
long val;
char * cp;
diff --git a/libc/include/conio.h b/libc/include/conio.h
index 7219a8f..13532d3 100644
--- a/libc/include/conio.h
+++ b/libc/include/conio.h
@@ -9,6 +9,7 @@ int getch __P((void));
int getche __P((void));
int kbhit __P((void));
int putch __P((int));
+int gotoxy __P((int, int));
#if 0 /* Unimplemented as yet */
char * cgets __P((char *));
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index ed22ef7..a724a4c 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -21,18 +21,20 @@ extern unsigned char __ctype[];
#define _tolower(c) ((c)^0x20)
#define toascii(c) ((c)&0x7F)
+#define __CT(c) (__ctype[1+(unsigned char)c])
+
/* Note the '!!' is a cast to 'bool' and even BCC deletes it in an if() */
-#define isalnum(c) (!!(__ctype[(int) c]&(__CT_u|__CT_l|__CT_d)))
-#define isalpha(c) (!!(__ctype[(int) c]&(__CT_u|__CT_l)))
+#define isalnum(c) (!!(__CT(c)&(__CT_u|__CT_l|__CT_d)))
+#define isalpha(c) (!!(__CT(c)&(__CT_u|__CT_l)))
#define isascii(c) (!((c)&~0x7F))
-#define iscntrl(c) (!!(__ctype[(int) c]&__CT_c))
-#define isdigit(c) (!!(__ctype[(int) c]&__CT_d))
-#define isgraph(c) (!(__ctype[(int) c]&(__CT_c|__CT_s)))
-#define islower(c) (!!(__ctype[(int) c]&__CT_l))
-#define isprint(c) (!(__ctype[(int) c]&__CT_c))
-#define ispunct(c) (!!(__ctype[(int) c]&__CT_p))
-#define isspace(c) (!!(__ctype[(int) c]&__CT_s))
-#define isupper(c) (!!(__ctype[(int) c]&__CT_u))
-#define isxdigit(c) (!!(__ctype[(int) c]&__CT_x))
+#define iscntrl(c) (!!(__CT(c)&__CT_c))
+#define isdigit(c) (!!(__CT(c)&__CT_d))
+#define isgraph(c) (!(__CT(c)&(__CT_c|__CT_s)))
+#define islower(c) (!!(__CT(c)&__CT_l))
+#define isprint(c) (!(__CT(c)&__CT_c))
+#define ispunct(c) (!!(__CT(c)&__CT_p))
+#define isspace(c) (!!(__CT(c)&__CT_s))
+#define isupper(c) (!!(__CT(c)&__CT_u))
+#define isxdigit(c) (!!(__CT(c)&__CT_x))
#endif /* __CTYPE_H */
diff --git a/libc/misc/ctype.c b/libc/misc/ctype.c
index 6b6cd3d..0425f00 100644
--- a/libc/misc/ctype.c
+++ b/libc/misc/ctype.c
@@ -12,8 +12,9 @@
#undef toupper
#undef tolower
-unsigned char __ctype[128] =
+unsigned char __ctype[257] =
{
+ 0, /* -1 */
__CT_c, __CT_c, __CT_c, __CT_c, /* 0x00..0x03 */
__CT_c, __CT_c, __CT_c, __CT_c, /* 0x04..0x07 */
__CT_c, __CT_c|__CT_s, __CT_c|__CT_s, __CT_c|__CT_s, /* 0x08..0x0B */
diff --git a/libc/misc/strtol.c b/libc/misc/strtol.c
index bcd3334..d8d62ea 100644
--- a/libc/misc/strtol.c
+++ b/libc/misc/strtol.c
@@ -18,6 +18,8 @@
*
*/
+/* TODO: This needs range clamping and setting errno when it's done. */
+
#include <ctype.h>
#include <stdlib.h>
@@ -86,13 +88,16 @@ strtoul(const char *nptr, char **endptr, int base)
base=10;
number=0;
- while (isalnum(*nptr))
+ while (isascii(*nptr) && isalnum(*nptr))
{
- number= (number*base)+((isalpha(*nptr) ? toupper(*nptr) : *nptr)
- - (isdigit(*nptr) ? '0' : 'A' + 9));
- nptr++;
- if (*nptr>'0'+base)
+ int ch = *nptr;
+ if (islower(ch)) ch = toupper(ch);
+ ch -= (ch<='9' ? '0' : 'A'-10);
+ if (ch>base)
break;
+
+ number= (number*base)+ch;
+ nptr++;
}
/* Some code is simply _impossible_ to write with -Wcast-qual .. :-\ */