From 667897b31aade092ea3227ca847b4550ef217798 Mon Sep 17 00:00:00 2001 From: n loewen Date: Fri, 25 Aug 2023 11:56:12 +0100 Subject: [PATCH] First commit - Create punch-card encoding script --- .gitignore | 2 + examples/draw-xy-binary.txt | 1 + examples/draw-xy-punchcard.txt | 10 +++++ examples/draw-xy.asm | 69 ++++++++++++++++++++++++++++++++++ punch-a-card.js | 49 ++++++++++++++++++++++++ readme.md | 28 ++++++++++++++ 6 files changed, 159 insertions(+) create mode 100644 .gitignore create mode 100644 examples/draw-xy-binary.txt create mode 100644 examples/draw-xy-punchcard.txt create mode 100644 examples/draw-xy.asm create mode 100755 punch-a-card.js create mode 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6d0ee45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode +.DS_Store \ No newline at end of file diff --git a/examples/draw-xy-binary.txt b/examples/draw-xy-binary.txt new file mode 100644 index 0000000..23fd076 --- /dev/null +++ b/examples/draw-xy-binary.txt @@ -0,0 +1 @@ +0000001100000010000000011111101000000011000000100000000111111011000000110010101100000001111111100000101100110001000000111111111100000010111111010000000000000000000001001111101000000001111111010000010011111011000011100000000100001011001111010000110011111110000001001111110100000101000001010000000111111101000001001111101100000111000000010000000111111011000011100000000100001011001111010000110011111110 \ No newline at end of file diff --git a/examples/draw-xy-punchcard.txt b/examples/draw-xy-punchcard.txt new file mode 100644 index 0000000..f9f7d45 --- /dev/null +++ b/examples/draw-xy-punchcard.txt @@ -0,0 +1,10 @@ +01234567 01234567 01234567 01234567 01234567 01234567 01 +▮▯▮▯▮▯▮▮ ▮▮▮▯▮▮▮▮ ▯▮▯▯▯▯▮▮ ▯▮▯▮▮▮▯▯ ▯▮▮▮▮▮▯▮ ▮▮▮▮▯▮▮▮ ▯▯ +▮▮▯▮▮▮▯▮ ▮▮▯▮▮▯▮▮ ▮▯▯▯▯▮▯▯ ▯▮▮▯▮▯▯▮ ▯▯▯▯▯▯▯▮ ▮▯▯▮▮▯▮▯ ▯▮ +▯▯▯▯▯▯▯▯ ▯▯▯▮▯▯▯▮ ▯▮▯▯▮▯▯▮ ▮▯▮▯▯▮▮▮ ▮▮▮▮▯▮▮▯ ▮▯▯▯▮▯▯▮ ▮▮ +▯▯▯▮▯▯▯▮ ▯▮▯▮▮▯▯▮ ▯▮▯▯▯▮▯▮ ▯▮▮▯▮▮▮▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▮▯▮▮ ▮▮ +▯▯▯▮▯▯▯▮ ▯▯▯▮▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▮ ▯▮ +▯▯▯▮▯▯▯▮ ▯▮▯▮▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▮ ▯▮ +▯▯▯▮▯▯▯▮ ▯▯▯▮▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▯ ▯▮ +▯▯▯▮▯▯▯▮ ▯▯▯▮▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▯ ▯▮ +01234567 01234567 01234567 01234567 01234567 01234567 01 \ No newline at end of file diff --git a/examples/draw-xy.asm b/examples/draw-xy.asm new file mode 100644 index 0000000..8db87f3 --- /dev/null +++ b/examples/draw-xy.asm @@ -0,0 +1,69 @@ +; Routine for drawing at (x, y) coordinates + +#zeroflag 1 + +; *** Set your desired (x, y) here: *** +#input_x 2 +#input_y 2 + +; Set up some handy shortcuts +#x $FA +#y $FB +#return_addr_ptr $FE + + +; Main: + +LDA #input_x +STO #x +LDA #input_y +STO #y +LDA * 6 ; acc = current address + 6 (LDA, STO, JMP = 6) +STO #return_addr_ptr +JMP @getxy + +LDA $FF +STO ($FD) +END + +;; Convert a pair of (x, y) coords +;; to the address of a pixel on the display +;; +;; Call with: +;; - x in #x +;; - y in #y +;; - return address in #return_addr_ptr +;; +;; Returns: pixel address in $FD +@getxy + #gxy_px $FD + + ; stash x... + LDA (#x) + STO #gxy_px + + ; check if this is row 0... + LDA (#y) + FHP #zeroflag + JMP @getxy_loop + JMP (#return_addr_ptr) ; if row 0, we're done + + @getxy_loop + LDA (#gxy_px) + ADD 5 ; add 5 to get to the next row + STO #gxy_px + LDA (#y) ; decrement y (it's acting as a loop counter)... + SUB 1 + STO #y + FHP #zeroflag + JMP @getxy_loop + JMP (#return_addr_ptr) + +;; Main variables: +;; F8 +;; F9 +;; FA - x coord +;; FB - y coord +;; FC - gxy temp +;; FD - gxy temp +;; FE - Return address for subroutine \ No newline at end of file diff --git a/punch-a-card.js b/punch-a-card.js new file mode 100755 index 0000000..dd59f43 --- /dev/null +++ b/punch-a-card.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node + +// Input file must contain a binary string with no spaces, linebreaks, etc. + +const fs = require('fs'); +const filename = process.argv[2]; +const inputFile_str = fs.readFileSync(filename, 'utf8'); + +const create_square_wave_string = (s) => { + s = s.replace(/1/g, '▮'); + return s = s.replace(/0/g, '▯'); +} + +const number_hex_string = (quantity) => { + let output = ''; + let current_digit = 0; + for (let i = 0; i < quantity; i++) { + current_digit = i % 8; + output = output + current_digit; + } + return output; +} + +const binary_string_to_bus_strings = (input) => { + let output = ['','','','','','','','']; + let input_bytes = input.match(/.{1,8}/g); + + input_bytes.forEach( (byte) => { + let byte_array = byte.split(''); + for (let i = 0; i < 8; i++) { + output[i] = output[i] + byte_array[i]; + } + }); + + // Print output + let nums = number_hex_string(output[0].length); + let spaced_nums = nums.match(/.{1,8}/g).join(' '); + console.log(); + console.log(spaced_nums); + + output.reverse().forEach( (s) => { + let spaced = s.match(/.{1,8}/g).join(' '); + console.log(create_square_wave_string(spaced)); + }); + console.log(spaced_nums); + console.log(); +} + +binary_string_to_bus_strings(inputFile_str); \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..912ab13 --- /dev/null +++ b/readme.md @@ -0,0 +1,28 @@ +# Create punch card patterns from binary strings + +This script turns a binary string into a pattern formatted for copying to an IBM-style 80-column punch card. + +It is intended for creating drawings patterns based on programs for my imaginary computer. + +## Use + +``` +./punch-a-card.js bin.txt +``` + +The input must be a text file containing nothing but 0s and 1s (no spaces, newlines, etc). It must be an even number of 8-bit bytes in length. + +## Example output + +``` +01234567 01234567 01234567 01234567 01234567 01234567 01 +▮▯▮▯▮▯▮▮ ▮▮▮▯▮▮▮▮ ▯▮▯▯▯▯▮▮ ▯▮▯▮▮▮▯▯ ▯▮▮▮▮▮▯▮ ▮▮▮▮▯▮▮▮ ▯▯ +▮▮▯▮▮▮▯▮ ▮▮▯▮▮▯▮▮ ▮▯▯▯▯▮▯▯ ▯▮▮▯▮▯▯▮ ▯▯▯▯▯▯▯▮ ▮▯▯▮▮▯▮▯ ▯▮ +▯▯▯▯▯▯▯▯ ▯▯▯▮▯▯▯▮ ▯▮▯▯▮▯▯▮ ▮▯▮▯▯▮▮▮ ▮▮▮▮▯▮▮▯ ▮▯▯▯▮▯▯▮ ▮▮ +▯▯▯▮▯▯▯▮ ▯▮▯▮▮▯▯▮ ▯▮▯▯▯▮▯▮ ▯▮▮▯▮▮▮▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▮▯▮▮ ▮▮ +▯▯▯▮▯▯▯▮ ▯▯▯▮▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▮ ▯▮ +▯▯▯▮▯▯▯▮ ▯▮▯▮▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▮ ▯▮ +▯▯▯▮▯▯▯▮ ▯▯▯▮▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▯ ▯▮ +▯▯▯▮▯▯▯▮ ▯▯▯▮▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▮▯▯▯▯▯▮ ▯▮▯▯▯▮▯▮ ▯▯▯▮▯▯▯▯ ▯▮ +01234567 01234567 01234567 01234567 01234567 01234567 01 +``` \ No newline at end of file