Kinda getting used to DOS programming But it is really quirky. For example, here is the code to print he amount of memory available to program:
#include <dos.h>
int main(int argc, char **argv) {
char buf[80];
dos_psp_t _seg *pPSP = (void _seg*)_psp;
int32_t avail = ((int32_t)(pPSP->himem - _psp) + 1) << 4;
printf("Memory available: %s\n", litoa10(buf, avail));
return 0;
}
The _seg is a special keyword to convert uint16_t segment value into a pointer.
litoa10 is basically a itoa(x,10), but for 32bit ints, since the library one works only with 16bit ones.
32bit integers are implemented in software, so the decompiled code is littered with calls like LXLSH@
The litoa10 code is just something....
char *litoa10(char *buf, int32_t n) {
bool sign;
size_t len;
char digit;
if ((0xffff < n) || ((-1 < n && (true)))) {
sign = false;
} else {
sign = true;
n = CONCAT22(-(n != 0)-_22(n),-n);
}
digit = n%10;
*buf = digit + '0';
buf[1] = 0;
while( true ) {
digit = n/10;
if (digit == 0) break;
len = strlen(buf);
if ((len & 3) == 3) {
len = strlen(buf);
memmove(buf + 1,buf,len + 1);
*buf = ',';
}
len = strlen(buf);
memmove(buf + 1,buf,len + 1);
n = n/10;
digit = n%10;
*buf = digit + '0';
}
if (sign) {
len = strlen(buf);
memmove(buf + 1,buf,len + 1);
*buf = '-';
}
return buf;
}
first time I see memmove in an integer printing routine.
Current Mood: amused