BG1, PRELOAD BG2, PRELOAD

Results 1 to 13 of 13
  1. #1

    Default 8-bit CPU with 256 bytes of RAM (Lodestar microcomputer)

    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.

    Code:
    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
    1 INTRODUCTION

    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.

    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
    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  COMMENT
    49 08    LDA 8     ;load 8
    4B 08    LDA @8    ;load the contents of memory address 8
    These addressing modes allow the use of variables in programs.

    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:

    1. Set input switches to desired address and examine
    2. 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.

    Code:
    88 00    JMP 0     ;jump to memory address 0
    This program uses the jump instruction to jump to itself, creating an infinite loop.

    2.2 ADDITION

    Performing arithmetic is just as simple.

    Code:
    49 05    LDA 5     ;load 5
    2D 03    ADD 3     ;add 3
    00       HLT       ;halt the program
    This program loads 5 into the accumulator, then adds 3 to it.

    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.

    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
    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.

    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.

    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
    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.

    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.

    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
    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.



    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.

    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
    This program plays a spooky song.

    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.


  2. #2

    Default

    How... When... Where!? *Head explodes*

  3. Thanks!


  4. #3
    Sackperson Sergeant Lord-Dreamerz's Avatar
    Points: 44,394, Level: 65
    Level completed: 12%, Points required for next Level: 1,156
    Overall activity: 99.9%
    7 days registered Created Album pictures 100 Experience Points 250 Experience Points 30 days registered
    PSN
    fumetsusozo
    Join Date
    Jul 2010
    Location
    ~Across Nowhere~
    Posts
    4,180
    Blog Entries
    15

    Default

    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!~


  5. #4

    Default

    That's so awesome. I don't understand how it is possible. Bravo!

  6. Thanks!


  7. #5

    Default

    I think you just won LBP sir.
    It's-a-me


  8. #6
    Sackperson amiel445566's Avatar
    Points: 12,752, Level: 34
    Level completed: 15%, Points required for next Level: 598
    Overall activity: 32.0%
    7 days registered 30 days registered 100 Experience Points 250 Experience Points 500 Experience Points
    PSN
    LOOKaUsername
    Join Date
    Mar 2013
    Location
    Polar Ice Caps of Craftworld
    Posts
    673
    Blog Entries
    2

    Default

    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

  9. Thanks!


  10. #7

    Default

    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!

  11. Thanks!


  12. #8

    Default

    My god that's insane! Does that mean you've mastered the LBP3 logic completely???

    Always so befuddled and awed by this type of logic. What do you like doing in real life?


  13. #9

    Default

    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.

  14. Thanks!


  15. #10
    Talentless Hack Sir monacle's Avatar
    Points: 11,086, Level: 31
    Level completed: 77%, Points required for next Level: 164
    Overall activity: 0%
    100 Experience Points 7 days registered 250 Experience Points 500 Experience Points 30 days registered
    PSN
    sir_monacle
    Join Date
    Oct 2015
    Location
    In another dimension - Mars
    Posts
    521

    Default

    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

  16. Thanks!


  17. #11

    Default

    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!
    Last edited by aratiatia; 01-03-2018 at 03:36 AM. Reason: editing because my silly slow internet posted twice.

  18. Thanks!


  19. #12

    Default

    My mind is blown. I just... I dont see how this is possible. I'd like to see the logic for each component on a smaller scale.

  20. Thanks!


  21. #13
    LBPC crew member mdkd99's Avatar
    Points: 27,674, Level: 51
    Level completed: 12%, Points required for next Level: 976
    Overall activity: 99.7%
    7 days registered 100 Experience Points 250 Experience Points 30 days registered 500 Experience Points
    PSN
    mdkd99
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    1,211
    Blog Entries
    33

    Default

    This is impressive, I agree.

    For me personally it's important that the logic works and not how it works. But this inspires me to learn more about logic.

  22. Thanks!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •