Go to file
n loewen b9ce6bb787 Rename file with logging utils 2023-08-02 13:58:11 +01:00
test-programs Track tests 2023-08-01 15:51:59 +01:00
assemble-and-run.js Tidy up and de-duplicate setup for switching between running for debug output vs. display output 2023-08-02 11:21:14 +01:00
assemble.js Turn print-memory.js into a more general-purpose 'printing utils' library -- export num2hex + rename function that prints a table of memory 2023-08-02 13:56:10 +01:00
assembler.js Turn print-memory.js into a more general-purpose 'printing utils' library -- export num2hex + rename function that prints a table of memory 2023-08-02 13:56:10 +01:00
bibliography.md Add some games 2023-08-02 13:15:21 +01:00
display.js Move config constants to a config file 2023-08-02 10:52:47 +01:00
logging.js Rename file with logging utils 2023-08-02 13:58:11 +01:00
machine.config.js Update + comment CYCLE_LIMIT 2023-08-02 11:22:57 +01:00
package-lock.json Start tracking package*.json 2023-08-01 15:47:37 +01:00
package.json Add 'debug' flag when calling assembler 2023-08-02 13:54:04 +01:00
readme.md Change capitalization of todo heading + bullet points 2023-08-02 12:09:26 +01:00
simulator-sketch-v1.js Move files out of 'sketch' directory 2023-08-01 15:46:09 +01:00
simulator-sketch-v2.js Move files out of 'sketch' directory 2023-08-01 15:46:09 +01:00
simulator.js Remove unused comments, table-printing function 2023-08-02 13:15:38 +01:00

readme.md

Paper computer simulator experiment

To do

Computer:

  • Implement carry flag on SUB

Misc:

  • Write some more complex test programs
    • Display (hex) numbers
  • Do a proper binary version... (or lose the typed arrays?)
  • Extract debugging to its own module

Run the assembler/simulator

Assemble source code:
npm run assemble source_code.asm

Assemble and run, with animated display of screen memory:
npm run display source_code.asm

Assemble and run, with debug output:
npm run debug source_code.asm

Instruction set

0   END
1   STO lit#   ; store ... mem[lit#] <- A
2   STO addr   ; store ... mem[mem[addr]] <- A
3   LDA lit#   ; load  ... A <- lit#
4   LDA addr   ; load  ... A <- mem[addr]
5   ADD lit#   ; add   ... A <- A + lit#      ... and un/set carry flag
6   ADD addr   ; add   ... A <- A + mem[addr] ... and un/set carry flag
7   SUB lit#   ; sub   ... A <- A - lit#      ... and un/set carry flag
8   SUB addr   ; sub   ... A <- A - mem[addr] ... and un/set carry flag
9   HOP lit#   ; hop   ... skip next instruction if A == lit# ... when true: IP <- PC + 2
A   HOP addr   ; hop   ... skip next instruction if A == addr ... when true: IP <- PC + 2
B   JMP lit#   ; jump  ... IP <- lit#
C   JMP addr   ; jump  ... IP <- addr
D   CCF ————   ; clear Carry Flag ... CF = 0
E   CHP ————   ; carry hop ... skip next instruction if Carry Flag is set ... when true: IP <- PC + 2
F
  • Instructions are two bytes long: one byte for the opcode, one for the argument

Nice features that didn't fit

  • Hop IF< and hop IF>
  • MUL and DIV
  • Rotates and shifts

Registers and Flags

  • A - accumulator
  • IP - instruction pointer (aka program counter)
  • CF - carry flag

Memory map / Peripherals

  • 00 - pointer to screen memory
  • 01 - pointer to keypad memory
  • 02-0F - reserved for future use
  • 10-1F - display (4x4)
  • 20-2F - keypad? (details TBD)
  • 30 - initial value for IP
  • 30-FF - free

Maybe someday

  • Timer (for a version in software/electronic-hardware)

Assembly language

ADD $01         ; comments follow a `;`

ADD $FF         ; this is direct addressing
ADD ($CC)       ; this is indirect addressing

END             ; END, CFC, and CHP don't require arguments
                ; (a default value of 0 will be used as their operand)

@subroutine     ; create a label
    ADD $01     ; (it must be on the line before the code it names)
    ADD $02

JMP @subroutine ; use a label as an argument
                ; the label will be replaced with
                ; the address of the label
  • Hexadecimal numbers are preceded by a $
  • Whitespace is ignored