Over the last couple of months I've developed an 8-bit CPU and 256-byte RAM chip. Together I believe they represent the fastest and most versatile computer made in LBP to date. I call this system the Lodestar.
A Lodestar system drawing a bunny. Why? Because bunnies.
1 INTRODUCTIONCode:1 INTRODUCTION 1.1 SPECIFICATION 1.2 DESIGN AND INTERFACE 1.3 INSTRUCTION SET 2 PROGRAMMING 2.1 YOUR FIRST PROGRAM 2.2 ADDITION 2.3 MULTIPLICATION 2.4 INPUT AND OUTPUT 2.5 GRAPHICS 2.6 SOUND 3 WHERE TO GET IT
The Lodestar is an 8-bit microcomputer that supports arithmetic, logic, conditional jumps, a stack, subroutines, serial I/O and interrupts. It can also generate music.
The most challenging part of developing the CPU were signal timing issues. To make the best use of each frame the system runs unclocked at 30 Hz, resulting in speeds of around 3 instructions per second.
One of the problems with past computers in LBP is how poorly documented they were by their authors. With this post I hope to provide a comprehensive guide to the system.
1.1 SPECIFICATION
- Accumulator architecture
- 256 bytes of memory
- 2 addressing modes
- Serial I/O ports
- 3 bars of thermo
Internally the system is split into 2 chips: the CPU and RAM. Together they use 4000 components total.
These chips are mounted on a board above the switch assembly.
1.2 DESIGN AND INTERFACE
The Lodestar's front panel has 20 lights and 12 flip switches. Since I'm a fan of vintage computers the front panel is inspired by machines like the PDP-8 and Altair 8800.
There are 4 control switches: RUN starts and stops a program, EXA examines a memory address, DEP deposits a value into memory, DAT toggles display of the accumulator or data bus.
The address lights show the current memory address. The data lights show either the contents of memory or the accumulator depending on the position of the DAT switch. The status lights indicate the internal state of the machine, such as overflow and I/O port activity.
On the right side of the machine are the serial input and output ports.
1.3 INSTRUCTION SET
The Lodestar instruction set features 36 documented instructions.
There are two addressing modes for the LDA, STA, ADD, SUB and bitwise instructions: immediate and absolute. This is determined by the 1th bit of the instruction as demonstrated below.Code:HEX MNEMONIC DESCRIPTION 00 HLT halt 01 NOP no operation 49 LDA load accumulator 8C STA store accumulator 2D ADD add D5 SUB subtract 44 INC increment accumulator 84 DEC decrement accumulator 20 SHL shift left 40 SHR shift right 30 ROL rotate left 50 ROR rotate right 79 NOT bitwise not 09 OR bitwise or 71 NOR bitwise nor 41 AND bitwise and 79 NAND bitwise nand 29 XOR bitwise xor 51 XNOR bitwise xnor 14 PUSH push to stack 24 PULL pull from stack 55 CG compare greater than D5 CL compare less than D5 CGE compare greater than or equal to 55 CLE compare less than or equal to 28 JG jump if greater than 18 JL jump if less than 28 JGE jump if greater than or equal 18 JLE jump if less than or equal 48 JNZ jump if not zero 88 JMP unconditional jump 1C JSR jump to subroutine 2C RET return from subroutine 2E RTI return from interrupt 80 OUT serial out 4C SPK accumulator to speaker
These addressing modes allow the use of variables in programs.Code:HEX MNEMONIC COMMENT 49 08 LDA 8 ;load 8 4B 08 LDA @8 ;load the contents of memory address 8
2 PROGRAMMING
A Lodestar program is a series of instructions. When you flip the RUN switch the program will begin executing from the current memory address.
Programs are entered byte by byte. To input a byte into memory:
- Set input switches to desired address and examine
- Set input switches to desired value and deposit
To input the value 44 at address 08 for instance you would first examine 08 and then deposit 44.
What follows is a tutorial that introduces the instruction set through 6 programs. All the programs begin from address 0.
2.1 YOUR FIRST PROGRAM
A program can be as simple as a single instruction.
This program uses the jump instruction to jump to itself, creating an infinite loop.Code:88 00 JMP 0 ;jump to memory address 0
2.2 ADDITION
Performing arithmetic is just as simple.
This program loads 5 into the accumulator, then adds 3 to it.Code:49 05 LDA 5 ;load 5 2D 03 ADD 3 ;add 3 00 HLT ;halt the program
As the name implies the accumulator accumulates the result of all operations. To see the result of this program displayed on the data lights flip the DAT switch up.
2.3 MULTIPLICATION
There's no multiply instruction. Instead, repeated addition can be used.
This program performs 5 x 4. There are two variables used: x and i. The variable x is initially set to zero and accumulates the result with each iteration of the loop. The variable i is decremented once per iteration and acts as a counter, when it reaches zero the program halts.Code:4B 05 loop: LDA @x ;load x variable 2D 05 ADD 5 ;add 5 to x 8C 00 STA x ;store x 4B 0A LDA @i ;load i variable 84 DEC ;decrement i 8C 04 STA i ;store i 48 00 JNZ loop ;if i is not zero jump to loop 00 HLT ;halt the program
2.4 INPUT AND OUTPUT
Located on the right side of the Lodestar are both the serial input port and serial output port. These can be used to connect peripherals or to create networks of Lodestar systems.
On receiving a byte via the input port an interrupt is triggered. An interrupt pushes the current memory address to the stack and the CPU jumps to address 0. After an interrupt has been handled a RTI instruction can be used to return the CPU to the prior address.
This is a powerful program that listens to the input port, copying whatever it receives to memory. This means we can hook up a keyboard to the system, so programs can be entered easier and faster. In fact, all the programs in this tutorial were written using this program and a keyboard.Code:14 PUSH ;push interrupt to stack 4B 08 LDA @p ;load pointer variable 44 INC ;increment pointer 8E 08 STA @p ;store pointer 24 PULL ;pull interrupt back from stack 8E 0B STA @p ;store interrupt where the pointer points 2E RTI ;return from interrupt 88 0A loop: JMP loop ;wait for another interrupt
Although not necessary, this program uses the stack to temporarily store the interrupt. The stack starts at address FF and decrements down. This is a handy way to pass data around without using lots of LDA and STA instructions.
2.5 GRAPHICS
Using the serial output port it's possible to communicate with peripherals such as a monitor.
This program sends a region of memory to the serial output port, byte by byte. The monitor treats these bytes as pixel coordinates and updates the screen. In this case, the pixel data is 3 bytes long and draws a triangle.Code:4B 0D loop: LDA @i ;load pixel 80 OUT ;send to monitor 4B 01 LDA @i ;load pixel address 44 INC ;increment 8E 01 STA @i ;store new address 55 0F CG 0F ;if last pixel address is greater than new address, 28 00 JG loop ;jump to loop, 00 HLT ;else halt 80 0F FF ;pixel data
By combining this program with the program in the previous section it's possible to copy programs and data from one Lodestar system to another.
2.6 SOUND
Lastly, the Lodestar is also capable of generating music. The lowest 4 bits of the accumulator determine the pitch when the SPK instruction is used.
This program plays a spooky song.Code:4B 04 loop: LDA @x ;load, increment and store x 44 INC 8C 00 STA x 41 0D AND 0D ;discard the 1th bit 4C SPK ;send x to speaker 88 00 JMP loop ;jump to loop
3 WHERE TO GET IT
The level, which features a running system, can be found here:
Simply complete the level to collect the Lodestar, monitor and keyboard as shareable prizes.
- Forum
- LBP Showcase / Reviews / Recommendations
- Object Showcase
- 8-bit CPU with 256 bytes of RAM (Lodestar microcomputer)
Results 1 to 13 of 13
-
03-07-2015 #1
8-bit CPU with 256 bytes of RAM (Lodestar microcomputer)
-
-
03-07-2015 #2
How... When... Where!? *Head explodes*
-
Thanks!
-
03-07-2015 #3Sackperson Sergeant
- PSN
- fumetsusozo
- Join Date
- Jul 2010
- Location
- ~Across Nowhere~
- Posts
- 4,170
- Blog Entries
- 15
But Ayneh can it love.. CAN IT LOVE? ... Also can it fix me a can of soup? =D
BTW nice to see you finally got your tech-toy done! :>~Lets go on a fantastic ADVENTURE!~
-
Thanks!
-
03-08-2015 #4
That's so awesome. I don't understand how it is possible. Bravo!
-
Thanks!
-
07-29-2015 #5
I think you just won LBP sir.
It's-a-me
-
Thanks!
-
07-29-2015 #6Sackperson
- PSN
- LOOKaUsername
- Join Date
- Mar 2013
- Location
- Polar Ice Caps of Craftworld
- Posts
- 673
- Blog Entries
- 2
Insane... and I think comishguy67 is right, here
Figured since reporting this on multiple occasions didn't work, I'll just spread it like the plague
-
Thanks!
-
08-03-2015 #7
Well. I just saw this, but my my, it's incredibly impressive. Will you keep trying to make computers in LBP 3?
And the world...is electricity! And there's a lot inside of you! And there's a lot inside of me!
-
Thanks!
-
10-17-2015 #8
-
Thanks!
-
01-10-2017 #9
Tried it, couldn't get it to work. It needs a manual of some kind to know what to do with the buttons. All it said was "HI" which then faded away into nothingness. Good idea, I have something that might work.
-
Thanks!
-
01-13-2017 #10Talentless Hack
- PSN
- sir_monacle
- Join Date
- Oct 2015
- Location
- In another dimension - Mars
- Posts
- 521
My head hurts. Good job, however!
signature 2016: "2016 yet I'm still using a PlayStation 3...." --sir monacle
signature 2017: "The more you struggle with something, the more rewarding it feels to finish it." --sir monacle
-
Thanks!
-
01-03-2018 #11
This heading towards Black Mirror levels of freakiness - sackthing simulating other sackthings in a spiraling simulation infinity
I'm both impressed and bewildered - wow! Great work! I bow before you!
-
Thanks!
-
01-04-2018 #12
-
Thanks!
-
01-07-2018 #13
-
Thanks!
«
Previous Thread
|
Next Thread
»
All times are GMT. The time now is 01:13 AM.
Powered by vBulletin® Version 4.2.2
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.
Extra Tabs by vBulletin Hispano
Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.
Image resizer by SevenSkins
Extra Tabs by vBulletin Hispano