File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from os import path
2+ def plot8bitpatternastext (
3+ bitpattern : list [int ],
4+ onechar : str ,
5+ zerochar : str ):
6+ """Outputs the bits of a list
7+ of bytes to console
8+
9+ Args:
10+ bitpattern: list of bytes
11+ onechar : char to display
12+ if bit is 1
13+ zerochar : char to display
14+ if bit is 0
15+
16+ Returns:
17+ console output
18+ """
19+ s = ""
20+ for bits in bitpattern :
21+ mask = 128
22+ while mask > 0 :
23+ s += onechar if mask & bits > 0 else zerochar
24+ mask >>= 1
25+ s += '\n '
26+ return s
27+
28+ def getcharbmp (filename : str , ch : str ):
29+ a = ""
30+ with open (filename , 'rb' ) as f :
31+ f .seek (1626 + 8 * ord (ch ))
32+ a = f .read (8 )
33+ return a
34+
35+ def main ():
36+ scriptdir = path .dirname (__file__ )
37+ filename = scriptdir + "/Bm437_IBM_CGA.FON"
38+ ch = ">"
39+ a = getcharbmp (filename , ch )
40+ print (a )
41+ print (plot8bitpatternastext (a ,"*" ," " ))
42+
43+
44+ if __name__ == "__main__" :
45+ main ()
You can’t perform that action at this time.
0 commit comments