CircuitVerse – Femto-4v2.6 (Laptop)
A 16-bit pc/possibly console impressed factor, the Femto-4. This would be the primary department and backups will likely be forks from it. This challenge was began round November 2020.
At the moment runs:
- Cart A: Flappy Hen
- Cart B: Some Pixel Artwork
- Cart C: Screensaver
- Cart D: Snake
- Cart E: Phemton Demonstrations
- Cart F: Aggressive Snake
- Cart G: Tic Tac Toe
- Cart H: Join 4
- Cart I: NIM
- Cart J: Unhealthy Apple
- Bundle Cart: All carts in a single
- Cart 2A: 32×32 Snake
- Cart 2B: 32×32 Aggressive Snake
- Cart 2C: 32×32 Pixel Artwork
- Cart 2D: 32×32 Unhealthy Apple
- Bundle Cart 2: All 32×32 carts in a single
Assembler:
Compiler:
The 256-Collection:
Cart Notes:
Cart A:
- The primary cart written for the Femto-4.
Cart B:
- The sprites within the cart are:
- A: Femto-4 Emblem.
- B: Madeline from Celeste.
- C: Madeline from Celeste (once more).
- D: A part of you aka Badeline from Celeste.
- E: A strawberry from Celeste.
- F: Standing Mario from Tremendous Mario Bros.
- G: Leaping Mario from Tremendous Mario Bros.
- H: Standing Mario from Tremendous Mario Bros 3.
- I: Operating Mario from Tremendous Mario Bros 3.
- J: Sanderokian (my very own character).
Cart C:
- Enter something into the keyboard to randomise the colors.
- Enter r into the keyboard to reset the colors.
Cart D:
- WASD Pad is advisable.
- Sport settings (enter the letter earlier than beginning the sport to make use of the setting):
- e: toggle whether or not crashing into the perimeters ends in a recreation over.
- The 2 modes (with/with out edge collisions) have two separate excessive scores.
- w: change the snake’s color scheme to white.
- r: change the snake’s color scheme to crimson.
- y: change the snake’s color scheme to yellow.
- o: change the snake’s color scheme to orange.
- p: change the snake’s color scheme to purple.
- a: change the snake’s color scheme to aqua.
- g: change the snake’s color scheme to inexperienced.
- b: change the snake’s color scheme to blue.
- m: change the snake’s color scheme to magenta.
- 1: change the snake’s color scheme to pink.
- 2: change the snake’s color scheme to gentle blue.
- 3: change the snake’s color scheme to the problem color scheme with an invisible physique.
- 0: randomise the snake’s color scheme.
Cart E:
- The check codes within the cart are:
- 1: Hey World.
- 2: Single Operator Calculator.
- 3: Exponentiation Calculator.
- 4: Fibonacci Calculator.
- 5: Keyboard to TTY Take a look at.
- 6: Keyboard to TTY LDI LID Take a look at.
- 7: Keyboard to TTY LII Take a look at.
- 8: Keyboard to TTY LIA Take a look at.
Cart F:
- WASD Pad is actually required.
- Sport settings (enter the letter earlier than beginning the sport to make use of the setting):
- e: toggle whether or not crashing into the perimeters ends in a recreation over.
- w: toggle whether or not the variety of wins every participant has is tracked.
- s: toggle whether or not the overall rating every participant has scored is tracked.
- d: show the overall wins and whole scored.
- r: reset the tracked statistics.
Cart G:
- The small gentle within the nook signifies which participant’s flip it’s.
- When it’s dimmed, it signifies that the pc is processing that participant’s flip.
- Sport settings (enter the letter earlier than beginning the sport to make use of the setting):
- w: toggle whether or not the variety of wins every participant has is tracked.
- s: toggle automated begin participant swapping. d: show the wins every participant has.
- r: reset the wins every participant has.
Cart H:
- The bar on the prime signifies which participant’s flip it’s.
- When it’s dimmed, it signifies that the pc is processing that participant’s flip.
- Sport settings (enter the letter earlier than beginning the sport to make use of the setting):
- w: toggle whether or not the variety of wins every participant has is tracked.
- s: toggle automated begin participant swapping.
- d: show the wins every participant has.
- r: reset the wins every participant has.
Cart I:
- Sport settings (enter the letter earlier than beginning the sport to make use of the setting):
- w: toggle whether or not the variety of wins every participant has is tracked.
- s: toggle automated begin participant swapping.
- d: show the wins every participant has.
- r: reset the wins every participant has.
- i: show the sport directions.
- c: toggle the whether or not participant 2 is performed by the pc.
Cart J:
- Performs Unhealthy Apple
- There aren’t any additional controls
Cart 2A:
- The choices are the identical as Cart D.
Cart 2B:
- The choices are the identical as Cart F.
Cart 2C:
- The sprites within the cart are:
- A: Femto-4 Emblem.
- B: Sanderokian (my very own character).
- C: Alstran (my very own character).
Cart 2D:
- Performs Unhealthy Apple on the bigger display
- There aren’t any additional controls
Options:
- Instant, direct, & oblique reminiscence entry.
- Jumps & conditional jumps.
- 16-bit tackle area.
- Switchable reminiscence banks, permitting for the standard cart to carry as much as 1MB of information.
- An ALU able to logical operators, addition, subtraction, shift left, shift proper, multiplying, dividing, & different specialised features.
- Quick execution – can run multiple instruction per clock cycle.
- 16×16 pixel show with 32 sprites and 15-bit direct color.
- 32×32 pixel show with 32 sprites which might have as much as 18-bit direct color.
- Two controllers, a keyboard mapping for the controllers, & a keyboard for textual content inputs.
- RNG, TTY, stack, & save reminiscence.
- Von Neumann Structure.
- Assembler & compiler (written in Python).
- Twelve pre-written carts to play with.
Updates:
v1.0:
- Completed the challenge and added Cart A.
v1.1:
- Added Cart B, some Pixel Artwork.
- Mounted GRF, & AXR directions.
- Made Bootloader clear TTY, Keyboard, & Controller Pushed.
- Up to date Cart A & Cart B to utilize AXR directions.
v1.2:
- Added Cart C, a Screensaver.
- Up to date Cart B to answer the beginning button on each controllers.
v1.3:
- Added Cart D, Snake.
- Moved to new challenge to repair points round trying to find initiatives branched from personal initiatives.
- Eliminated pointless EEPROM banks and write strains from all carts.
- Made Reset clear WRAM and the Common Registers.
v1.4:
- Mounted Keyboard.
- Added a Bundle Cart that means that you can view all of the carts with out altering carts (it’s essential to reset the console to view one other cart).
- Mounted bug in the usual financial institution design which wrote knowledge to incorrect addresses.
- Mounted competition difficulty in Mult.
- Added Annotations to the In Debug.
v1.5:
- Added Snake Participant.
- Added Reset & Energy labels to the related buttons.
v2.0:
- Additional optimisation to scale back lag/improve execution velocity.
- Added extra reminiscence entry choices.
v2.1:
- Additional optimisation of the CU.
- Added a keyboard to controller mapping.
v2.2:
- Continued optimisation and overhaul of the CU.
- Eliminated previous CU & examine circuits.
- Added further stack entry directions.
- Up to date the debug variations with the adjustments, in addition to fixing bugs within the debug variations.
- Designed a Emblem for the Femto-4.
- Rewrote Cart C to permit the sprites to be seen in any order, and added the emblem to it.
v2.3:
- Introducing Phemton Lite, the primary model of the Femto-4’s excessive stage languages.
- Added a hyperlink to Phemton Lite’s compiler.
- Added Cart E to exhibit code written in Phemton Lite.
- Mixed SpecialD & ROMD1, and eliminated SpecialD & ROMDB.
- Up to date Snake code & Bundle code to match the brand new addresses.
- Added Cart F, a aggressive model of Snake.
- Added an extra sprite into Cart B.
- Mounted points with LII, LXA & LXP directions.
v2.4:
- Mounted alignment of the higher carts.
- Added Cart G & Cart H, Tic Tac Toe & Join 4 written in Phemton Lite.
- Added progress lights to Cart G & Cart H.
- Reworked bundle cart to make the code shorter and extra environment friendly for giant numbers of carts.
- Made Cart G & Cart H sooner.
- Reshuffled Cart E check codes and added 2 Cart E check codes, exponentiation & Fibonacci calculation.
- Added recreation choices to Cart D, Cart F, Cart G, & Cart H.
- Up to date Cart C to permit the colors to be randomised.
- Added non-obligatory color schemes for Cart D.
- Mounted Snake Participant.
- Remade the multiply and divide circuits to make the most of the inbuilt adders.
- Eliminated previous MultM and DivM circuits.
v2.5:
- Additional optimisation of the CU.
- Optimisation of the quick execution clocks for the pc, the graphics, & the WASD Pad.
- Mounted debug variations’ points with Phemton conditionals and added optimisations to the debug variations.
- Added 32×32 display PPU.
- Added Cart 2A, Cart 2B, & Cart 2C, 32×32 variations of Snake, Aggressive Snake, & Pixel Artwork.
- Added Cart I, NIM written in Phemton Lite.
v2.6
- Added the flexibility to straight write sprites to the PPU throughout execution.
- Considerably optimised the CU by eradicating pointless subcircuits.
- Launched vital portions of lazy analysis to additional enhance efficiency.
- Added Cart J, and Cart 2D, which each play Unhealthy Apple.
- The Femto-4 can now be added to the set of issues that performs Unhealthy Apple.
Future Updates:
- Extra pre-written carts.
- Bug fixes.
- Including an optimiser to the compiler.
- Phemton Full.
- Phemton Plus.
Do fork the challenge and write your individual code for it! In order for you extra info on how to take action learn the Developer Information within the assembler.
Be aware: The Flappy Hen excessive rating and the Snake excessive rating are mine. If you wish to save your individual scores completely you’ll have to fork the challenge.
The Femto-4
Common Structure: The Femto-4 is a 16-bit, Von Neumann structure pc with variable size directions which can be comprised of a number of 16-bit phrases. It has many options related to CISCs, resembling variable size directions, and multicycle oblique hundreds, nonetheless operates like a RISC, with every instruction taking precisely 1 clock cycle. This was performed to provide the Femto-4 energy while maintaining its building easy. First the OP code of the instruction is learn, after which relying on the OP code, further items of information could also be learn for the operands. This enables execution to develop into incorrectly offset, which might result in the execution of rubbish if the PC is jumped to an incorrect tackle. That is often wonderful, because the OP code area is so empty that the info will seemingly be handed one after the other till the following legitimate instruction. Directions are learn from primary reminiscence, making this structure a Von Neumann structure versus a Harvard structure. The MAR all the time specifies the tackle being learn to or written from, while the MDR all the time holds the info being written. Knowledge from the info out bus might be written to most particular registers throughout the instruction. OP codes and operands are all 16-bits. The big OP code dimension was chosen as a result of excessive variety of ALU directions. There are roughly 500 interpretable OP codes that the pc can deal with.
Reminiscence Mapping: The 16-bit tackle area of the Femto-4 is reminiscence mapped, with all knowledge being saved someplace within the tackle area. The final 48kx16b of reminiscence (all addresses beginning with 0b01, 0b10, or 0b11) are devoted to the cart reminiscence. That is the place the interchangeable program can be saved, permitting packages to be simply modified by altering carts. The carts have 32 16kx16b EEPROM/RAM chips, which might be switched between throughout execution by writing to deal with 0x00cc. This provides every cart 512kx16b of reminiscence to play with. In concept, further reminiscence might be added in a cart by creating an identical system on the within of the cart, which might permit it to swap between much more EEPROM/RAM chips. The preliminary 16kx16b are due to this fact mapped to all the pieces else, together with a set WRAM chip that can not be switched out, the bootloader, the PPU knowledge, common registers, the stack, inputs, outputs, and some particular registers, such because the defend, mode, and flag registers.
Quick Execution: Execution on the quickest clock velocity (one pulse each 100ms, or 10Hz, which is outlined because the clock altering state each 50ms, or at a fee of 20Hz) is extremely gradual, and would make cheap graphics successfully unimaginable. Attributable to this, the Femto-4 consists of a number of execution modes that permit the pc to run a lot sooner. There are two registers concerned on this, tackle 0x00ca, the mode register, and tackle 0x00cb, the defend register. When the 2 least vital bits of the mode register are low, the pc runs usually, executing 1 instruction per clock pulse. When bit 0 is ready excessive, the pc enters quick execution on the rising edge, the place it executes a number of directions per clock pulse. That is achieved by looping an inverter into itself, producing a loop that may pulse indefinitely till the looping line is stopped by some exterior issue. Stopping the loop is vital since leaving the loop working will cease CircuitVerse’s execution, as a result of it going over the stack restrict of the execution. Quick execution is all the time paused by a 0x0000 and 0x0001 OP Code. Bit 2 permits falling edge quick execution, which might be performed with rising edge quick execution producing twin edge quick execution. Setting the third little bit of the mode register excessive will allow safety. It will be certain that pc solely executes as many directions as the worth within the defend register. This protects execution by making certain that the loop will all the time pause earlier than the cycle restrict is reached. Since some operations are much more complicated than different operations, the utmost variety of directions per clock pulse is variable, and testing ought to all the time be carried out to make sure that the restrict is just not reached. Attributable to this, for video games that want common graphics updates, it is strongly recommended that safety is just not used, and as an alternative the pauses are absolutely code managed. On the opposite finish of the mode register are the graphics mode. The best two bits give the graphics replace mode, 0b00 for falling edge solely (regular velocity), 0b01 for twin edge (double velocity), 0b10 for each different clock pulse (half velocity), and 0b11 for code managed, the place the 0x0001OP Code is required to replace the graphics. The third most vital bit is the graphics disable bit. Setting it excessive stops updating the graphics, lowering lag by stop the graphics quick execution loop from working. The mode and safety values are solely up to date on the rising fringe of the clock pulse, and due to this fact there ought to all the time be pauses earlier than and after any execution mode or safety change. By default, the Femto-4 executes with a safety worth of 16, to permit the carts to run easily, nonetheless, relying on the directions getting used, that quantity might be raised to 64.
Graphics (16×16): The Femto-4 is able to driving a 16×16 15-bit direct color display. It has area for 32 sprites that are rectangles with an assigned color. All of the sprites are drawn to the display each time a graphics replace happens, relying on the graphics mode. When utilizing dual-edge quick execution, the falling edge ought to solely be used to execute recreation code, since writing graphics knowledge because the display is being drawn might mess up the graphics. These 32 sprites have their knowledge saved within the PPU RAM within the following format: The primary 16 bits are the corners of the rectangle, with every coordinate being 4 bits. The coordinates are ordered x coordinate 1 (4), x coordinate 2 (4), y coordinate 1 (4), y coordinate 2 (4). The second coordinates are offset up by 1, to permit the total display to be drawn to, such that the scale of the rectangle are (x2 – x1) + 1 and (y2 – y1) + 1. The following 16 bits are the sprites color, with the primary 15 bits getting used for 15-bit direct color, and the final bit getting used to allow or disable drawing the sprite. The final bit is essential to make sure that clean sprites are usually not drawn to the display. For the reason that display is just not wiped each time it’s refreshed, the background should be a sprite to make sure that the display is absolutely wiped earlier than the remainder of the sprites are drawn on. Management of this enables carts to attract a single body over a number of updates, permitting the 32-sprite restrict to be bypassed (see how Snake works). The sprites are drawn in reminiscence order, with the sprite with the biggest tackle all the time being drawn final and due to this fact on prime, of all different sprites. That is achieved through the use of the very same system as quick execution, which reads off all of the sprite knowledge and attracts them to the display in a single clock pulse. This may loop extra instances safely than the primary CPU because it has much less dependencies which dramatically decreases the simulation’s stack utilization.
Graphics (32×32): The Femto-4 may also drive a 32×32 display, with sprites in a position to be drawn by 3 totally different modes. The 32×32 display PPU treats the addresses as one mixed 32-bit worth, with the worth with the smaller tackle going first. The primary 3 bits of the 32 bits outline the mode. Solely the values 1, 2, 3, correspond to precise sprites, while the remainder are usually not drawn to the display. Mode 1 splits the remaining 29-bit area as the next: unused (1), x coordinate (5), y coordinate (5), crimson (6), inexperienced (6), blue (6). Mode 2 splits the 29-bit area within the following method: x coordinate 1 (5), x coordinate 2 (5), y coordinate 1 (5), y coordinate 2 (5), crimson (3), inexperienced (3), blue (3). Mode 3 splits the 29-bit area within the following method: unused (3), x coordinate (5), y coordinate (5), crimson (5), inexperienced (5), blue (5), alpha/transparency (1). As with the 16×16 display, Mode 2’s second coordinates are offset by 1 leading to rectangles having the scale of (x1 – x2) + 1 and (y1 – y2) + 1. Mode 3 is designed to permit the colors used within the 16×16 display to be the identical, making changing code between the 2 variations simpler. The replace mechanism is similar as 16×16 display.
ALU: The essential ALU was impressed by the ALU-74LS181. It was designed to flexibly change between numerous operations by altering an extra piece of information which is bundled within the OP code. This enables a single ALU to deal with all of the required processes, resembling the fundamental binary logic operations, shift left, including, and subtracting, lowering the variety of circuits required, in addition to the logic required to determine which instruction to make use of. The Femto-4 can also multiply, divide, shift proper, shift left/proper by a specified variety of bits, and carry out operations designed to work with the pc’s graphics knowledge.
Conditional Jumps: The Femto-4 can carry out instant and direct jumps relying on the flags, a specified little bit of the accumulator, and the clock. The flag jumps permit for comparisons to be made. There are three flags, the carry, probably the most vital bit within the accumulator, and if the accumulator worth is 0, the equals flag. By performing A-B, we will examine A and B by trying on the flags. If the equals flag is true, then A=B, since A-B = 0. If probably the most vital bit is 0, then the quantity is optimistic or 0 (by two’s complement) and due to this fact A>=B. The comparability is just not solely right for numbers in two’s complement (a big optimistic quantity and a big unfavourable quantity when subtracted can yield a optimistic quantity), however for small values it really works effectively. While we can not straight examine A<=B utilizing A-B on this design, we will merely flip the subtraction to B-A to take action. The accumulator bit testing is especially used to examine for controller inputs. Since every button within the controller is mapped to at least one bit, bit testing that bit successfully permits us to examine if a button has been pressed. An identical check might be carried out utilizing an AND instruction, and checking if the consequence is the same as 0 or not. Bit testing is most helpful for testing an enter from each controllers, since it could possibly minimize out an extra instruction. The soar on clock is there to make sure that we will soar execution on the suitable clock pulse, which ensures that graphics might be up to date on the sting of execution.
Timing: The pc is timed utilizing a number of normal delay chips. The heartbeat size working in to the pc is about 10k models lengthy. Due to this fact, totally different elements an instruction are separated by 20k unit delays. Additional management of timings inside these intervals is achieved by 1k “On Delays”, which have a 1k delay turning on, however a 0k delay turning off, making certain that pulses don’t bleed into the following pulse. These pulses can inform registers to write down and what supply to write down from, allow the learn and write strains, replace the ALU, and replace the stack Every instruction is separate by 600k of delay in quick execution. For extra info on how delay works see right here: https://circuitverse.org/users/4699/projects/circuitverse-delay-introduction.
Keyboard Mapping: The Femto-4’s keyboard controller mapping was created utilizing a specialised chip. This chip used the quick execution loop to take 15 inputs from a keyboard and map the inputs to button presses on the controllers. For the reason that buttons are up to date a number of instances in a clock pulse, the keyboard controller can not deal with held buttons. The keyboard mapping is designed to work with each controllers, permitting two participant video games to be possible on the pc.
Meeting: The Femto-4 has an assembler that converts meeting written in a .txt into hex values in a .txt that may be copied and loaded into the EEPROM banks for storage. The assembler can deal with image project, in addition to assigning addresses within the code symbols to make dealing with jumps simpler. For full particulars on the Femto-4’s meeting language view the meeting developer information.
Phemton: Phemton is the Femto-4’s excessive stage language, with a compiler to compile it is code into Femto-4 meeting. Phemton handles variable reminiscence project, primary array project, if, elif, else statments, whereas loops, for loops, and features. Phemton Lite is the one compiler full, and lacks an optimiser. Phemton Lite has the idea of native scope solely when compiling. All uniquely recognized variables are given a worldwide tackle. This reduces the runtime load because the pc doesn’t have to determine the place the variables have to go throughout run time. Future deliberate additions embrace generated code optimisations and optimisers, Phemton Full, which has dynamic reminiscence project, and Phemton Plus, which provides further varieties for floats and longs. For extra particulars view Phemton’s developer information.
Different Notes: The reminiscence wrappers permit exterior chips to work together with the primary knowledge management system, on this case used for RNG, controllers, the keyboard, and driving the textual content output. This makes it simple to further chips to the pc. All meeting and Phemton code might be discovered within the challenge for the Femto-4’s assembler and compiler respectively. The save knowledge cart should be positioned exterior of the Femto-4 circuit to make sure that its contents are routinely saved. The GitHub hyperlinks usually tend to be updated than the Replit hyperlinks, nonetheless the Replit hyperlinks permit the code to be ran within the browser. Sorry about all of the copies of this pc clogging up the highest of the search outcomes.
For extra info, please learn the developer information discovered within the Femto-4’s Assembler, or simply submit a remark and ask me.
It is a secret to everyone, except you discovered it.