/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8                                :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2020 Justine Alexandra Roberts Tunney                              â
â                                                                              â
â Permission to use, copy, modify, and/or distribute this software for         â
â any purpose with or without fee is hereby granted, provided that the         â
â above copyright notice and this permission notice appear in all copies.      â
â                                                                              â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             â
â PERFORMANCE OF THIS SOFTWARE.                                                â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/assert.h"
#include "libc/fmt/bing.internal.h"
#include "libc/str/tab.internal.h"

/**
 * Turns binary octet into unicode glyph representation.
 *
 * Cosmopolitan displays RADIX-256 numbers using these digits:
 *
 *      0123456789abcdef
 *     0Â âºâ»â¥â¦â£â â¢ââââââªâ«â¼
 *     1âºâââ¼Â¶Â§â¬â¨âââââââ²â¼
 *     2 !"#$%&'()*+,-./
 *     30123456789:;<=>?
 *     4@ABCDEFGHIJKLMNO
 *     5PQRSTUVWXYZ[\]^_
 *     6`abcdefghijklmno
 *     7pqrstuvwxyz{|}~â
 *     8ÃÃ¼Ã©Ã¢Ã¤Ã Ã¥Ã§ÃªÃ«Ã¨Ã¯Ã®Ã¬ÃÃ
 *     9ÃÃ¦ÃÃ´Ã¶Ã²Ã»Ã¹Ã¿ÃÃÂ¢Â£Â¥â¬Æ
 *     aÃ¡Ã­Ã³ÃºÃ±ÃÂªÂºÂ¿âÂ¬Â½Â¼Â¡Â«Â»
 *     bâââââ¤â¡â¢âââ£ââââââ
 *     cââ´â¬âââ¼âââââ©â¦â ââ¬â§
 *     dâ¨â¤â¥âââââ«âªâââââââ
 *     eÎ±ÃÎÏÎ£ÏÎ¼ÏÎ¦ÎÎ©Î´âÏÎµâ©
 *     fâ¡Â±â¥â¤â â¡Ã·âÂ°âÂ·ââ¿Â²â Î»
 *
 * IBM designed these glyphs for the PC to map onto the display bytes at
 * (char *)0xb8000. Because IBM authorized buyers of its PCs to inspect
 * and/or modify this region of memory, it became widely understood by
 * many developers as a quick way to visualize arbitrary data that's so
 * superior to hexdump -- a use-case that's lived on longer than the CGA
 * graphics card for which it was designed.
 *
 * @param b is binary octet to pictorally represent
 * @param intent controls canonical multimappings: ââÂ ,\nâ,Îµâââ¬,Â Î»,etc.
 * @see unbing() for inverse
 */
int bing(int b, int intent) {
  _unassert(0 <= b && b < 256);
  return kCp437[b & 0xff];
}
