Skip to content

Instantly share code, notes, and snippets.

@id4ehsan
Last active March 7, 2019 20:32
Show Gist options
  • Save id4ehsan/33b57547c588f4406df1d1b16246812c to your computer and use it in GitHub Desktop.
Save id4ehsan/33b57547c588f4406df1d1b16246812c to your computer and use it in GitHub Desktop.
converted the 437 character set contained in the EGA.CPI file into a text file
A distinction is made between scalable vector fonts (e.g., TrueType, PostScript Type 1) and bitmap fonts (or matrix fonts). Bitmap fonts were (and are) available for both computer screens (monitors) and printers (dot matrix printers).
Ultimately, any font on the screen of a computer is composed of pixels, as can be easily checked with the magnifying glass, but at DOS times there were only bitmap fonts in which each character is placed in a rigid matrix with e.g. 8 × 8, 8 × 14 or 8 × 16 pixels (width × height, i.e. the width always comprised 8 pixels, the height, however, was variable), with each set bit (one-bit) corresponding to one visible pixel.
The bitmap font for the 437-CP character set was (and still is) in the ROM of the PC. This ROM character set is used at boot time (as long as Windows is not yet in memory) and when the hardware configuration menu is called. The 437-CP character set in 8x16 internal matrix is ​​shown at the bottom of pages 7-14.
In addition, formerly (and could still be today) CONFIG.SYS and AUTOEXEC.BAT were used to load the EGA.CPI bitmap font file (EGA = Enhanced Graphics Adapter, CPI = Code Page Information) into the PC's RAM memory to change from the 437 code page first given by the ROM to another code page. A description of various other code pages for Windows and Macintosh can be found in our manual http://www.sanskritweb.net/fonts/pahotman.pdf, pages 34-37.
The EGA.CPI file is still available under Windows XP today, and the bitmap fonts contained in it are used when old DOS programs are called up via the Windows DOS box. See, e.g. above Windows XP screen dump of the DOS Edit program, which was set here for demonstration purposes on the even with Windows XP still available extremely rough matrix with 8 x 8 pixels.
If, for example, earlier the 8 x 8 pixels A was displayed on the screen, this was done so that the 8 bytes were copied with the bit pattern of the A in the screen memory by machine-language command and were displayed in this way as a bright pixels on the screen.
Historical application example
In the old days, when there was no Windows, it was only possible to render rare diacritics if you modified one of the 437 codepage sets in the EGA.CPI file. When I was At the end of 1988, when I began to write the 1st edition of my Sanskrit Compendium (see http://www.sanskritweb.net/deutsch), I wrote Devanagari (see http://www.sanskritweb.net/ itrans) not to think. Even the representation of the 15 special characters for the transcription of Sanskrit, namely
æ æ æ æ. í í í í í í
was only possible on the screen after "patching" (i.e., modifying) the EGA.CPI file. For this purpose I wrote a program called EGA-KON1.BAS (see below page 3), which converted the 437 character set contained in the EGA.CPI file into a text file, which I then modified according to the above transliteration characters (see page 13 below) , blue matrix characters), and then with the program EGA-KON2.BAS back into a modified ("patched") EGA.CPI file.
230 - æ ........ ........ ........ ###### .. ........ ##. ###. ###. ##. . ## .. ##. . ## ...... ## ...... ## ..... #### .... ......... ## ...... # # ..... ........
230 - æ
Û Û Û Û
Û Û Û Û Û Û Û Û Û Û Û Û Û. Û Û Û Û Û Û Û Û Û Û
æ 230 - ÛÛ Û Û Û
8 x 16 matrix in text file 8 x 16 screen matrix ideal solution (vector font)
One has to look at the above screen matrix (and also the patterns at the bottom of pages 7 to 13) with a large reading distance to be able to recognize the characters at all.
Ulrich Stiehl, December 2006
REM Conversion of ega.cpi into Sanskrit-Transliteration/5.3.1989/us
REM ==============================================================
REM EGA-KON1.BAS
REM ============
REM
COLOR 7, 1: CLS
PRINT "EGA-KON1.BAS"
PRINT "============"
PRINT
PRINT "1st step: Conversion of EGA-ALT.CPI to EGA-ALT.ASC"
PRINT " Filter out the 256 8x16 characters"
REM Structure of original-EGA.CPI = EGA-ALT.CPI
REM ===========================================
REM 65 bytes header - see DOS Technical Reference, p. 7-17
REM 256 x 16 bytes for 8x16 Ega-font = 4096 bytes
REM Then more fonts - not changed here
REM Bin table for bytes
REM =====================
DIM bin%(7)
FOR x% = 0 TO 7: bin%(x%) = 2 ^ x%: NEXT x%
OPEN "ega-alt.cpi" FOR BINARY AS #1
OPEN "ega-alt.asc" FOR OUTPUT AS #2
REM 65-Byte header
REM ==============
buffer$ = "1": REM Length 1
FOR x = 1 TO 65: GET #1, , buffer$: NEXT x
REM 8x16-Byte characters
REM =================
buffer$ = "0123456789ABCDEF": REM Length 16
FOR character% = 0 TO 255
GET #1, , buffer$
header$ = STR$(character%)
IF character% > 31 AND (character% <> 127 AND character <> 255) THEN
header$ = header$ + " - " + CHR$(character%)
END IF
PRINT #2, MID$(header$, 2)
GOSUB hextobin
NEXT character%
CLOSE
PRINT
PRINT "a) Import ASCII file 'EGA-ALT.ASC' into F & A file 'EGA-NEU.FA'"
PRINT
PRINT "b) Change bitmap and cache EGA-NEU.FA"
PRINT
PRINT "c) Export F & A file 'EGA-NEU.FA' to ASCII file 'EGA-NEU.ASC'"
END
REM 16 bytes in 16 8-bit lines
REM ===========================
hextobin:
FOR h1% = 1 TO 16
hexstring$ = ""
h$ = MID$(buffer$, h1%, 1)
h$ = h$ + CHR$(0)
h% = CVI(h$)
FOR h2% = 7 TO 0 STEP -1
IF (h% AND bin%(h2%)) = 0 THEN
hexstring$ = hexstring$ + "."
ELSE
hexstring$ = hexstring$ + "#"
END IF
NEXT h2%
PRINT #2, hexstring$
NEXT h1%
RETURN
REM Conversion of ega.cpi into Sanskrit-Transliteration/5.3.1989/us
REM ==============================================================
COLOR 7, 1: CLS
PRINT "EGA-KON2.BAS"
PRINT "============"
PRINT
PRINT "2nd step: Conversion of EGA-NEU.ASC into EGA-NEU.BIN"
REM Structure of EGA-NEU.ASC
REM ========================
REM 256 x 17 lines: 1. line comment
REM 2.-17 Line ASCII bit pattern
REM Example bit parts: ".. ## .. ##"
REM # = Pixel set
REM , = Pixel not set
REM Binary table for byte backwards
REM ===============================
DIM bin%(7)
y% = 7
FOR x% = 0 TO 7
bin%(y%) = 2 ^ x%
y% = y% - 1
NEXT x%
REM Read the test way
REM ===============
OPEN "ega-neu.asc" FOR INPUT AS #1
counter% = 0
WHILE NOT EOF(1)
LINE INPUT #1, x$
x% = VAL(x$)
IF x% = 0 AND LEFT$(x$, 1) <> "0" THEN
PRINT "Wrong file"
CLOSE : END
END IF
FOR x% = 1 TO 16
LINE INPUT #1, x$
NEXT x%
counter% = counter% + 1
WEND
CLOSE
IF counter% <> 256 THEN
PRINT "Wrong file"
END
END IF
REM ega-neu.bin contains 4096 bytes = 256 * 16
REM =========================================
OPEN "ega-neu.asc" FOR INPUT AS #1
OPEN "ega-neu.bin" FOR BINARY AS #2
REM 8x16-byte characters: 16 lines of 8 pixels each
REM ===============================================
puffer$ = "0123456789ABCDEF": REM Length 16
FOR x% = 1 TO 256
LINE INPUT #1, x$: REM comment line
FOR y% = 1 TO 16
LINE INPUT #1, zeile$
GOSUB bintohex
MID$(puffer$, y%, 1) = byte$
NEXT y%
PUT #2, , puffer$
NEXT x%
CLOSE
REM Conversion of ega.cpi to Sanskrit-Transliteration/5.3.1989/us
REM ==============================================================
PRINT
PRINT "EGA-KON3.BAS"
PRINT "============"
PRINT
PRINT "3rd step: unification of EGA-ALT.CPI + EGA-NEU.BIN"
PRINT " to EGA-NEW.CPI"
REM structure
REM ========
REM EGA-ALT.CPI EGA-NEU.BIN EGA.NEU.CPI
REM -------------------------------------------------
REM 1. Header ----------------------------------->
REM (65 Bytes)
REM 2. character set------------->
REM (4096 Bytes)
REM 3. Rest ------------------------------------->
REM from alt.cpi
REM Files already have to exist!
REM Duplicate with COPY before!
OPEN "ega-alt.cpi" FOR INPUT AS #1
l1 = LOF(1): CLOSE #1
OPEN "ega-neu.cpi" FOR INPUT AS #2
l2 = LOF(2): CLOSE #2
IF l1 <> l2 THEN
PRINT "ega-neu.cpi must first be duplicated"
END
END IF
REM ega-neu.bin in ega-neu.cpi into it
REM =========================================
OPEN "ega-alt.cpi" FOR BINARY AS #1
OPEN "ega-neu.bin" FOR BINARY AS #2
OPEN "ega-neu.cpi" FOR BINARY AS #3
REM Skip header
REM -------------------
x$ = SPACE$(65)
GET #1, , x$
GET #3, , x$
REM New character set
REM -----------------
x$ = SPACE$(4096)
GET #2, , x$
PUT #3, , x$
CLOSE
END
REM 8-digit ASCII binary line "#### ...." = line $
REM convert to 1-digit string byte = byte $
bintohex:
byte% = 0
FOR b% = 0 TO 7
b$ = MID$(zeile$, b% + 1, 1)
IF b$ = "#" THEN
byte% = (byte% OR bin%(b%))
END IF
NEXT b%
byte$ = MKI$(byte%)
byte$ = LEFT$(byte$, 1)
RETURN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment