Skip to content

Commit b08b1b6

Browse files
committed
Fixed some comment capitalizations; Improved README aesthetics
1 parent 02bde17 commit b08b1b6

File tree

12 files changed

+24
-17
lines changed

12 files changed

+24
-17
lines changed

Chip8/vm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ def __init__(self, program_data: bytes):
6767
# Index Register
6868
self.i = 0
6969
# Program Counter
70-
# starts at 0x200 because addresses below that were
70+
# Starts at 0x200 because addresses below that were
7171
# used for the VM itself in the original CHIP-8 machines
7272
self.pc = 0x200
7373
# Memory - the standard 4k on the original CHIP-8 machines
7474
self.ram = array('B', [0] * RAM_SIZE)
75-
# load the font set into the first 80 bytes
75+
# Load the font set into the first 80 bytes
7676
self.ram[0:len(FONT_SET)] = array('B', FONT_SET)
77-
# copy program into ram starting at byte 512 by convention
77+
# Copy program into ram starting at byte 512 by convention
7878
self.ram[512:(512 + len(program_data))] = array('B', program_data)
7979
# Stack - in real hardware this is typically limited to
8080
# 12 or 16 PC addresses for jumps, but since we're on modern hardware,

KNN/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def run():
5858
elif key_name == "p": # predict what the digit should look like
5959
pixels = digit_pixels.transpose((1, 0, 2))[:, :, 0].flatten() * P_TO_D
6060
predicted_pixels = digits_knn.predict_array(K, Digit("", pixels), "pixels")
61-
predicted_pixels = predicted_pixels.reshape((PIXEL_HEIGHT, PIXEL_WIDTH)).transpose((1, 0)) * D_TO_P
61+
predicted_pixels = predicted_pixels.reshape((
62+
PIXEL_HEIGHT, PIXEL_WIDTH)).transpose((1, 0)) * D_TO_P
6263
digit_pixels = np.stack((predicted_pixels, predicted_pixels,
6364
predicted_pixels), axis=2)
6465
# Handle mouse events

NESEmulator/cpu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,15 +432,15 @@ def BPL(self, instruction: Instruction, data: int):
432432
# Force break
433433
def BRK(self, instruction: Instruction, data: int):
434434
self.PC += 2
435-
# push PC to stack
435+
# Push PC to stack
436436
self.stack_push((self.PC >> 8) & 0xFF)
437437
self.stack_push(self.PC & 0xFF)
438-
# push status to stack
438+
# Push status to stack
439439
self.B = True
440440
self.stack_push(self.status)
441441
self.B = False
442442
self.I = True
443-
# set PC to reset vector
443+
# Set PC to reset vector
444444
self.PC = (self.read_memory(IRQ_BRK_VECTOR, MemMode.ABSOLUTE)) | \
445445
(self.read_memory(IRQ_BRK_VECTOR + 1, MemMode.ABSOLUTE) << 8)
446446
self.jumped = True
@@ -585,7 +585,7 @@ def ORA(self, instruction: Instruction, data: int):
585585
def PHA(self, instruction: Instruction, data: int):
586586
self.stack_push(self.A)
587587

588-
# push status
588+
# Push status
589589
def PHP(self, instruction: Instruction, data: int):
590590
# https://nesdev.org/the%20'B'%20flag%20&%20BRK%20instruction.txt
591591
self.B = True

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
# Computer Science from Scratch
22

3-
This repository contains all of the source code for the book *[Computer Science from Scratch: Building Interpreters, Art, Emulators and ML in Python](https://nostarch.com/computer-science-from-scratch)* by [David Kopec](https://davekopec.com) and published by No Starch Press. The book, intended for intermediate to advanced Python programmers, features 7 projects of varying complexity from the realm of interpreters, emulators, computer art, and simple machine learning. In the table below is a description of the 7 projects and further down in this README there are directions for running (and testing) each of them. The projects are compatible with Python 3.12 and above.
3+
<img align="left" src="README_images/ComputerScienceFromScratchCover.jpg" alt="Computer Science from Scratch Cover" height="200">
4+
5+
This repository contains all of the source code for the book *[Computer Science from Scratch: Building Interpreters, Art, Emulators and ML in Python](https://nostarch.com/computer-science-from-scratch)* by [David Kopec](https://davekopec.com) and published by No Starch Press. The book, intended for intermediate to advanced Python programmers, features 7 projects of varying complexity from the realm of interpreters, emulators, computer art, and simple machine learning.
6+
7+
The projects are compatible with Python 3.12 and above. You can find out more about the book at [computersciencefromscratch.com](https://computersciencefromscratch.com)
8+
9+
In the table below is a description of the 7 projects and further down in this README there are directions for running (and testing) each of them.
410

511
| Project | Chapter | Section | Description |
612
|---------------|---------|-------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
7-
| [Brainfuck](#brainfuck-chapter-1) | 1 | Interpreters | An interpreter for the one of the simplest possible programming languages, Brainfuck. |
8-
| [NanoBASIC](#nanobasic-chapter-2) | 2 | Interpreters | An interpreter for Nano BASIC, a dialect of Tiny BASIC—a programming language that was used during the personal computer revolution. |
9-
| [RetroDither](#retrodither-chapter-3) | 3 | Computer Art | A program that converts modern photos for display on a classic 1980s Mac by performing 1-bit (black & white) Atkinson dithering and converting them to MacPaint format. |
10-
| [Impressionist](#impressionist-chapter-4) | 4 | Computer Art | Impressionist uses a simple stochastic hill climbing algorithm to create abstract art from photographs that (sometimes) looks like the work of an impressionist painter. |
11-
| [Chip8](#chip8-chapter-5) | 5 | Emulators | An implementation of the CHIP-8 virtual machine that can play all of the 1970s games that were released for CHIP-8. |
12-
| [NESEmulator](#nesemulator-chapter-6) | 6 | Emulators | The simplest possible NES emulator with support for playing real games but lacking sound, performance, compatibility with most mappers, and several other features. |
13-
| [KNN](#knn-chapters-7--8) | 7 & 8 | Super Simple Machine Learning | You draw a digit and the program can interpret your drawing (KNN classification) and/or complete it (KNN regression). |
13+
| [Brainfuck](#brainfuck-chapter-1) <img src="README_images/brainfuck.png" alt="Brainfuck Image" height="60"> | 1 | Interpreters | An interpreter for the one of the simplest possible programming languages, Brainfuck. |
14+
| [NanoBASIC](#nanobasic-chapter-2) <img src="README_images/nanobasic.png" alt="NanoBASIC Image" height="60"> | 2 | Interpreters | An interpreter for Nano BASIC, a dialect of Tiny BASIC—a programming language that was used during the personal computer revolution. |
15+
| [RetroDither](#retrodither-chapter-3) <img src="README_images/retrodither.png" alt="Retro Dither Image" height="60"> | 3 | Computer Art | A program that converts modern photos for display on a classic 1980s Mac by performing 1-bit (black & white) Atkinson dithering and converting them to MacPaint format. |
16+
| [Impressionist](#impressionist-chapter-4) <img src="README_images/impressionist.png" alt="Impressionist Image" height="60"> | 4 | Computer Art | Impressionist uses a simple stochastic hill climbing algorithm to create abstract art from photographs that (sometimes) looks like the work of an impressionist painter. |
17+
| [Chip8](#chip8-chapter-5) <img src="README_images/chip8.png" alt="Chip8 Image" height="60"> | 5 | Emulators | An implementation of the CHIP-8 virtual machine that can play all of the 1970s games that were released for CHIP-8. |
18+
| [NESEmulator](#nesemulator-chapter-6) <img src="README_images/nes.png" alt="NES Image" height="100"> | 6 | Emulators | The simplest possible NES emulator with support for playing real games but lacking sound, performance, compatibility with most mappers, and several other features. |
19+
| [KNN](#knn-chapters-7--8) <img src="README_images/knn.png" alt="KNN Image" height="100"> | 7 & 8 | Super Simple Machine Learning | You draw a digit and the program can interpret your drawing (KNN classification) and/or complete it (KNN regression). |
1420

1521
## Get the Book
1622

@@ -197,4 +203,4 @@ The code in this repository uses the latest type hinting features in Python 3.12
197203

198204
## Authorship and License
199205

200-
The code in this repository is Copyright 2024 David Kopec and released under the terms of the Apache License 2.0. That means you can reuse the code, but you must give credit to David Kopec. Please read the license for details and other requirements.
206+
The code in this repository is Copyright 2021-2025 David Kopec and released under the terms of the Apache License 2.0. That means you can reuse the code, but you must give credit to David Kopec. Please read the license for details and other requirements.
159 KB
Loading

README_images/brainfuck.png

46.3 KB
Loading

README_images/chip8.png

65.5 KB
Loading

README_images/impressionist.png

501 KB
Loading

README_images/knn.png

135 KB
Loading

README_images/nanobasic.png

126 KB
Loading

0 commit comments

Comments
 (0)