From 1bd6a9d4fa1b4801fd646cf37453fb2c5da58b04 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 24 Jun 2019 20:52:56 +0200 Subject: [PATCH 1/2] Add an itoa() function, following the most common prototype I can find. --- lang/cem/libcc.ansi/core/printf/itoa.c | 13 +++++++++++++ lang/cem/libcc.ansi/headers/stdio.h | 1 + 2 files changed, 14 insertions(+) create mode 100644 lang/cem/libcc.ansi/core/printf/itoa.c diff --git a/lang/cem/libcc.ansi/core/printf/itoa.c b/lang/cem/libcc.ansi/core/printf/itoa.c new file mode 100644 index 000000000..64104f50a --- /dev/null +++ b/lang/cem/libcc.ansi/core/printf/itoa.c @@ -0,0 +1,13 @@ +#include + +void itoa(long value, char* buffer, int radix) +{ + if (value < 0) + { + *buffer++ = '-'; + value = -value; + } + buffer = _i_compute(value, 10, buffer, 0); + *buffer++ = '\0'; +} + diff --git a/lang/cem/libcc.ansi/headers/stdio.h b/lang/cem/libcc.ansi/headers/stdio.h index c6ddb8808..45495d632 100644 --- a/lang/cem/libcc.ansi/headers/stdio.h +++ b/lang/cem/libcc.ansi/headers/stdio.h @@ -75,6 +75,7 @@ extern void perror(const char *_s); /* Internal function used in several places which is approximately itoa(). */ extern char *_i_compute(unsigned long val, int base, char *s, int nrdigits); +extern void itoa(long val, char* buffer, int radix); #if ACKCONF_WANT_EMULATED_FILE #include From 97d22973ee4149df372481dfa3961cda3bc5e5ee Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 24 Jun 2019 23:07:17 +0200 Subject: [PATCH 2/2] Add some BIOS bindings, and a zero-terminated print string routine. --- plat/cpm/descr | 2 +- plat/cpm/include/cpm.h | 7 +++++++ plat/cpm/libsys/bios_conin.s | 15 +++++++++++++++ plat/cpm/libsys/bios_conout.s | 21 +++++++++++++++++++++ plat/cpm/libsys/bios_const.s | 16 ++++++++++++++++ plat/cpm/libsys/close.c | 1 + plat/cpm/libsys/cpm_printstring0.s | 27 +++++++++++++++++++++++++++ 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 plat/cpm/libsys/bios_conin.s create mode 100644 plat/cpm/libsys/bios_conout.s create mode 100644 plat/cpm/libsys/bios_const.s create mode 100644 plat/cpm/libsys/cpm_printstring0.s diff --git a/plat/cpm/descr b/plat/cpm/descr index c023fc45c..1b2b43777 100644 --- a/plat/cpm/descr +++ b/plat/cpm/descr @@ -77,8 +77,8 @@ name led (.e:{TAIL}={PLATFORMDIR}/libem.a \ {PLATFORMDIR}/libsys.a \ {PLATFORMDIR}/libc.a \ - {PLATFORMDIR}/libsys.a \ {PLATFORMDIR}/libem.a \ + {PLATFORMDIR}/libsys.a \ {PLATFORMDIR}/libend.a) linker end diff --git a/plat/cpm/include/cpm.h b/plat/cpm/include/cpm.h index 3ad97b183..d9e370993 100644 --- a/plat/cpm/include/cpm.h +++ b/plat/cpm/include/cpm.h @@ -83,6 +83,9 @@ extern uint8_t cpm_read_random_safe(FCB* fcb); /* Extends cpm_ramtop over the CCP, for a little extra space. */ extern void cpm_overwrite_ccp(void); +/* Like cpm_printstring, but uses C-style strings terminated with a \0. */ +extern void cpm_printstring0(const char* s); + /* 0 */ extern void cpm_warmboot(void); /* 1 */ extern uint8_t cpm_conin(void); /* 2 */ extern void cpm_conout(uint8_t b); @@ -126,4 +129,8 @@ extern void cpm_overwrite_ccp(void); #define cpm_get_user() cpm_get_set_user(0xff) #define cpm_set_user(u) cpm_get_set_user(u) +extern uint8_t bios_conin(void); +extern uint8_t bios_const(void); +extern void bios_conout(uint8_t c); + #endif diff --git a/plat/cpm/libsys/bios_conin.s b/plat/cpm/libsys/bios_conin.s new file mode 100644 index 000000000..98ba4d67c --- /dev/null +++ b/plat/cpm/libsys/bios_conin.s @@ -0,0 +1,15 @@ +# +#include "asm.h" + +.define _bios_conin +_bios_conin: + lhld 1 + lxi d, 6 + dad d + push b + call .pchl + pop b + mov e, a + mvi d, 0 + ret + diff --git a/plat/cpm/libsys/bios_conout.s b/plat/cpm/libsys/bios_conout.s new file mode 100644 index 000000000..6562d3aa6 --- /dev/null +++ b/plat/cpm/libsys/bios_conout.s @@ -0,0 +1,21 @@ +# +#include "asm.h" + +.define _bios_conout +_bios_conout: + pop h ! pop return address + pop d ! pop parameter into DE + push d + push h + + push b + mov c, e + + lhld 1 + lxi d, 9 + dad d + call .pchl + + pop b + ret + diff --git a/plat/cpm/libsys/bios_const.s b/plat/cpm/libsys/bios_const.s new file mode 100644 index 000000000..c8036be33 --- /dev/null +++ b/plat/cpm/libsys/bios_const.s @@ -0,0 +1,16 @@ +# +#include "asm.h" + +.define _bios_const +_bios_const: + lhld 1 + lxi d, 3 + dad d + push b + call .pchl + pop b + mov e, a + mvi d, 0 + ret + + diff --git a/plat/cpm/libsys/close.c b/plat/cpm/libsys/close.c index be5ae0ec4..81d2d5135 100644 --- a/plat/cpm/libsys/close.c +++ b/plat/cpm/libsys/close.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "cpmsys.h" diff --git a/plat/cpm/libsys/cpm_printstring0.s b/plat/cpm/libsys/cpm_printstring0.s new file mode 100644 index 000000000..96d358123 --- /dev/null +++ b/plat/cpm/libsys/cpm_printstring0.s @@ -0,0 +1,27 @@ +# +#include "asm.h" + +! Prints a \0-terminated string. + +.define _cpm_printstring0 +_cpm_printstring0: + pop h ! pop return address + pop d ! pop parameter (possibly junk) + push d + push h + +.1: + ldax d ! fetch byte + ora a + rz ! exit if zero + inx d + + push b ! save FP as the BDOS will corrupt it + push d + mov e, a + mvi c, 2 ! conout + call 0x0005 + pop d + pop b + + jmp .1