Skip to content

Commit

Permalink
Use DEC Rainbow font and add blinking cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthecheung committed Jan 13, 2022
1 parent 9a93583 commit 3b030cd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36,664 deletions.
Binary file added BmPlus_Rainbow100_re_80.otb
Binary file not shown.
12 changes: 6 additions & 6 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ know.
[1]: https://simondlevy.academic.wlu.edu/files/software/kbhit.py
[2]: https://www.gnu.org/licenses/lgpl-3.0.html

## Terminus
## Rainbow100 font

```
ter-u20n.bdf
BmPlus_Rainbow100_re_80.otb
```

The [Terminus][3] font is copyright its creators and used under the terms of
the [SIL Open Font License][4].
The [Rainbow100][3] font is by VileR and used under the terms of the Creative
Commons [Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)][4] license.

[3]: http://terminus-font.sourceforge.net/
[4]: http://scripts.sil.org/OFL
[3]: https://int10h.org/oldschool-pc-fonts/fontlist/font?rainbow100_re_80
[4]: https://creativecommons.org/licenses/by-sa/4.0/

## 8080/8085 CPU Exerciser

Expand Down
72 changes: 54 additions & 18 deletions cpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@

import argparse
import os
import time
from typing import Dict, List, Optional, Tuple

os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
from pygame.constants import KEYDOWN, KMOD_CTRL, KMOD_SHIFT, QUIT
from pygame.font import Font
from pygame.freetype import Font
from pygame.rect import Rect
from pygame.surface import Surface

Expand Down Expand Up @@ -204,9 +205,13 @@ def __init__(self, disk_images: List[str] = []):
self.esc_sequence: bytes = b''

pygame.init()
pygame.display.set_caption('8080 Emulator')
self.screen: Surface = pygame.display.set_mode((80 * 10 + 10, 24 * 20 + 10))
self.font: Font = pygame.font.Font('ter-u20n.bdf', 20)
pygame.display.set_caption('CP/M')
pygame.key.set_repeat(1000, 100)

self.screen: Surface = pygame.display.set_mode(
(80 * 10 + 2 * self.margin, 24 * 20 + 2 * self.margin))
self.font: Font = Font('BmPlus_Rainbow100_re_80.otb', 24)
self.blink_rate: int = 750


def putch(self, ch: int) -> None:
Expand Down Expand Up @@ -253,20 +258,50 @@ def putch(self, ch: int) -> None:


def render_buffer(self) -> List[Tuple[Surface, Rect]]:
img = self.font.render('█', False, self.foreground)
col = self.cursor % 80
row = self.cursor // 80
rect = img.get_rect()
rect.topleft = (col * 10 + self.margin, row * 20 + self.margin)
rect.size = img.get_size()
blits = [(img, rect)]

for row in range(24):
img = self.font.render(bytes(self.buffer[80*row:80*row+80]), False, self.foreground)
rect = img.get_rect()
cursor_on = (time.time_ns() // 1000000 // self.blink_rate) % 2 == 0
curs_col = self.cursor % 80
curs_row = self.cursor // 80

# Render the cursor
if cursor_on:
surface, rect = self.font.render(bytes([self.buffer[80*curs_row+curs_col]]),
fgcolor=self.background,
bgcolor=self.foreground)
else:
surface, rect = self.font.render(bytes([self.buffer[80*curs_row+curs_col]]),
fgcolor=self.foreground,
bgcolor=self.background)
rect.topleft = (curs_col * 10 + self.margin, curs_row * 20 + self.margin)
rect.size = surface.get_size()
blits = [(surface, rect)]

# Render rows up to the cursor row
for row in range(0, curs_row):
surface, rect = self.font.render(bytes(self.buffer[80*row:80*row+80]),
fgcolor=self.foreground)
rect.topleft = (self.margin, row * 20 + self.margin)
rect.size = surface.get_size()
blits += [(surface, rect)]

# Render the cursor row, but not the cursor
surface, rect = self.font.render(bytes(self.buffer[80*curs_row:80*curs_row+curs_col]),
fgcolor=self.foreground)
rect.topleft = (self.margin, curs_row * 20 + self.margin)
rect.size = surface.get_size()
blits += [(surface, rect)]
surface, rect = self.font.render(bytes(self.buffer[80*curs_row+curs_col+1:80*curs_row+80]),
fgcolor=self.foreground)
rect.topleft = ((curs_col + 1) * 10 + self.margin, curs_row * 20 + self.margin)
rect.size = surface.get_size()
blits += [(surface, rect)]

# Render rows after the cursor row
for row in range(curs_row+1, 24):
surface, rect = self.font.render(bytes(self.buffer[80*row:80*row+80]),
fgcolor=self.foreground)
rect.topleft = (self.margin, row * 20 + self.margin)
rect.size = img.get_size()
blits += [(img, rect)]
rect.size = surface.get_size()
blits += [(surface, rect)]
return blits


Expand Down Expand Up @@ -296,7 +331,8 @@ def run(self) -> None:
if 97 <= key <= 122 and event.mod & KMOD_SHIFT: # A-Z
key -= 32
elif event.mod & KMOD_SHIFT: # Other
key = self.shift_keymap[key]
if key in self.shift_keymap.keys():
key = self.shift_keymap[key]
elif 97 <= key <= 122 and event.mod & KMOD_CTRL: # ^A - ^Z
key -= 96
vm.io.input_buffer += bytes([key])
Expand Down

0 comments on commit 3b030cd

Please sign in to comment.