Make terminal ui binaries work well everywhere

Here's some screenshots of an emulator tui program that was compiled on
Linux, then scp'd it to Windows, Mac, and FreeBSD.

https://justine.storage.googleapis.com/blinkenlights-cmdexe.png
https://justine.storage.googleapis.com/blinkenlights-imac.png
https://justine.storage.googleapis.com/blinkenlights-freebsd.png
https://justine.storage.googleapis.com/blinkenlights-lisp.png

How is this even possible that we have a nontrivial ui binary that just
works on Mac, Windows, Linux, and BSD? Surely a first ever achievement.

Fixed many bugs. Bootstrapped John McCarthy's metacircular evaluator on
bare metal in half the size of Altair BASIC (about 2.5kb) and ran it in
emulator for fun and profit.
This commit is contained in:
Justine Tunney 2020-10-10 21:18:53 -07:00
parent 680daf1210
commit 9e3e985ae5
276 changed files with 7026 additions and 3790 deletions

33
third_party/dtoa/divmax.S vendored Normal file
View file

@ -0,0 +1,33 @@
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program 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; version 2 of the License. │
This program 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 this program; if not, write to the Free Software │
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macros.h"
.source __FILE__
/ Avoid dtoa needing .data section.
.bss
.align 4
dtoa_divmax:
.zero 4
.endobj dtoa_divmax,globl
.previous
.init.start 202,_init_dtoa_divmax
movb $2,dtoa_divmax(%rip)
.init.end 202,_init_dtoa_divmax

View file

@ -400,10 +400,11 @@ Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
#ifdef SET_INEXACT
#define dtoa_divmax 27
#else
int dtoa_divmax = 2; /* Permit experimenting: on some systems, 64-bit integer */
/* division is slow enough that we may sometimes want to */
/* avoid using it. We assume (but do not check) that */
/* dtoa_divmax <= 27.*/
/* Permit experimenting: on some systems, 64-bit integer */
/* division is slow enough that we may sometimes want to */
/* avoid using it. We assume (but do not check) that */
/* dtoa_divmax <= 27.*/
extern int dtoa_divmax;
#endif
typedef struct BF96 { /* Normalized 96-bit software floating point numbers */

View file

@ -32,7 +32,7 @@ THIRD_PARTY_DUKTAPE_A_DIRECTDEPS = \
LIBC_FMT \
LIBC_TIME \
LIBC_MEM \
LIBC_MATH \
LIBC_TINYMATH \
LIBC_UNICODE \
LIBC_NEXGEN32E

View file

@ -26,7 +26,7 @@
/* this is a reduced-precision calculation of YCbCr-to-RGB introduced
to make sure the code produces the same results in both SIMD and scalar */
#define FLOAT2FIXED(x) (((int)((x)*4096.0f + 0.5f)) << 8)
#define FLOAT2FIXED(x) (((int)((x)*4096.0f + .5f)) << 8)
void stbi__YCbCr_to_RGB_row(unsigned char *out, const unsigned char *y,
const unsigned char *pcb, const unsigned char *pcr,
@ -45,9 +45,9 @@ void stbi__YCbCr_to_RGB_row(unsigned char *out, const unsigned char *y,
g = y_fixed + (cr * -FLOAT2FIXED(0.71414f)) +
((cb * -FLOAT2FIXED(0.34414f)) & 0xffff0000);
b = y_fixed + cb * FLOAT2FIXED(1.77200f);
r /= 1048576;
g /= 1048576;
b /= 1048576;
r >>= 20;
g >>= 20;
b >>= 20;
b4[0] = MIN(255, MAX(0, r));
b4[1] = MIN(255, MAX(0, g));
b4[2] = MIN(255, MAX(0, b));