Log In  

Cart #22458 | 2016-06-07 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
22

Hello, I'm back with more punch cards ;)
This time it's a simulated punch card computer (sort of)

If you're not a programmer, you may want to read this:
https://en.wikipedia.org/wiki/Computer#Programs

This isn't a game, it's not fun, and I don't even think it has much educational value, but it might entertain those interested in computer science for literally 5 seconds.

The point is that you can actually program the computer in machine code (a very limited instruction set with 8 instructions). I wouldn't recommend doing so yourself though, there are severe limitations that mean it can pretty much only do HELLO WORLD.

Features:







scroll left to view the computer gubbins: press X to play/stop, use up/down to change the simulation fequency, or step the simulation with z.
Memory - 96 bytes of memory, displayed as hex. The blue line indicates bytes that are mapped to the screen. Player 2 controls are mapped to the bytes indicated by the red line.
Registers - 8 single byte registers, displayed in decimal
Info - information about the next instruction to execute. (program counter, opcode, parameter 1, parameter 2)
Screen - displays the first 48 bytes in memory, encoded in the latin-1 character set. It can also display box drawing characters starting from 160.
scroll right to edit cards: up/down to add/delete cards (at last index), left/right to go next/previous card, x to select a card. Once you've selected a card you can use up/down/left/right to change the instruction opcode and parameters. As you can see, the whole instruction is encoded as binary onto the punch card (though this is purely cosmetic). Cards are saved once you press Z to go back out of edit mode.

So it seems like it might be useful for learning about programming, but there are a few problems:





The card punching interface is very awkward. You can't swap, copy, or delete cards. I do actually like that there's no typing though.
You can only have 48 cards. That's because I'm saving the cards to userdata.
The instruction set is too limited. There's no branch instruction.
Also, I don't think it even represents how punch cards were actually used. Apparently the 'binary format' was not the most commonly used. And besides, the visuals suggest that it's set in the personal computer era, so people would have been using FORTRAN or something by then, not machine code.

The instruction set (mnemonics are actually wrong in the cartridge, but they are correct here. sorry):










opcodemnemonicdescriptionparameter 1parameter 2
0NOPdo nothing
1ADDadd register a and b, and put result in register 7register aregister b
2SUBsubtract a and b, and put result in register 7register aregister b
3RL(read literal) read a into register bvalue aregister b
4Rread into register a from memory at bregister aaddress b
5WL(write literal) write a to memory at bvalue aaddress b
6Wwrite value from register a to memory at address in register bregister aregister b
7JAL(jump and link) write PC to register b and jump to card in regster aregister aregister b

EDIT: totally forgot you won't have my userdata! The hello world program is in my userdata. now how should I share it... guess I'll just paste it here. sorry

jeff_punchcards.p8d.txt:
0020000003010000010300000502000003080000030700000305000006040000
0701000001070000070600000503000048040000070200000603000045040000
07020000060300004c04000007020000060300004c0400000702000006030000
4f04000007020000060300002004000007020000060300005704000007020000
060300004f04000007020000060300005204000007020000060300004c040000
0702000006030000440400000702000006030000200400000702000006000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000

the hello world program:
-- initialization
3 1 1 -- set r1 as '1' (used to 'add 1' to things)
3 5 2 -- set r2 as '5' (the location of our 'function')
3 8 3 -- set r3 as 8 (the end of the 'function')
7 3 5 -- jump over the function, leave litter in r5
-- 'print' function
6 4 7 -- print r4 at r7
1 1 7 -- increment r7
7 6 5 -- jump back, leave litter in r5
-- print the characters...
3 72 4 -- 'H'
7 2 6 -- jump to function, leave link in r6
3 69 4 -- 'E'
7 2 6
3 76 4 -- 'L'
7 2 6
3 76 4 -- 'L'
7 2 6
3 79 4 -- 'O'
7 2 6
3 32 4 -- ' '
7 2 6
3 87 4 -- 'W'
7 2 6
3 79 4 -- 'O'
7 2 6
3 82 4 -- 'R'
7 2 6
3 76 4 -- 'L'
7 2 6
3 68 4 -- 'D'
7 2 6

P#22462 2016-06-07 15:21 ( Edited 2016-06-09 21:16)

Very charming! I'm happy to have a personal computer programmed by punch cards with a non-standard binary format. I like parts of the quirky interface, especially having to walk from the cards to the display.

P#22463 2016-06-07 15:32 ( Edited 2016-06-07 19:32)

Very cool idea and realisation!

P#22465 2016-06-07 15:35 ( Edited 2016-06-07 19:35)

Very nice pixel art, for a virtual machine. <3

P#22480 2016-06-07 23:42 ( Edited 2016-06-08 03:42)

Thanks for the lovely comments :)
Also, this would make a super cute project if you had an inordinate amount of free time
Arduino punched card reader
Maybe using a PocketChip instead of arduino? So you could run your physical punch cards in my game.

P#22510 2016-06-08 09:02 ( Edited 2016-06-08 13:02)

Too bad it's only 8 instructions. I'd love it to be turing-complete (conditional jumps, etc.)

Also you could increase cart capacity by saving these via cstore() to some unused space in the cart and perhaps mapdata

P#22566 2016-06-09 17:16 ( Edited 2016-06-09 21:16)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 11:10:38 | 0.012s | Q:20