Mini-tutorial: adding CPU ports - 8 ports
Doing this is pretty simple. First, you spawn the Data Port STOOL from Wire - Advanced category:

You might notice it has 8 ports... but how do we connect it?

Look up IOBus input. This one links our CPU to our ports.

Thing to know: CPU can address up to 1024 different I/O ports (1337 CPU h4xx0rs will find a way to use even more than 1024 though). But right now we have only 8, let's connect em. Click on IOBus input, go to dataport, and click on it. A selection of ports pops up - which one to choose? Answer: any of them. This does not matter, you can select any port you like. For now, select output Port0.
Good job, you've set the ports up! They are ready for use now.
Mini-tutorial: adding more than 8 ports - for example 32 ports
As you might already know, there is special wire gate/chip called Address Bus. Address Bus is used to join several address spaces together. Address space means memory (usually virtual memory, RAM inside some SENT) where each value can be found by using some address, for example there is address space of ports (where each port is a value, and they can be addressed using port index, address), or CPU address space (where each byte of CPU memory can be addressed using some address). Think of address space as "interface", where each your request to each memory cell in it will be re-routed elsewhere, where you want it to be routed.
Address bus joins several address spaces together into one address space. What is the practical use? Because of the fact that each data port has own address space (which is 8 bytes in size by the way, exactly matches number of ports) we can join several data ports together, and our address bus will act as one big data port with 4 data ports (well, maximum of 4 per address bus, but you can connect address busses in the same way as you do with data ports, making up to 1024 ports available).
Now, lets see example with 32 ports.
First, configure your address bus like this:

What this means? For those who don't understand, these are configurations for our 4 address spaces. Offset means offset of this address space in our big address space. Size means uh.. new size. You can set it smaller, or bigger (in second case "missing" variables will return 0). These can overlap with special rules (when byte is read, its read from the address space with least number, if written it writes to all address spaces).
Now, spawn 4 data ports. Connect 4 memory inputs of address bus to data ports (they are called Memory1, Memory2, and so on). Remember what memory input each data port is linked to.
Now, connect address bus to IOBus of CPU.
Hurray, now you can access 32 ports. When you access first 8 ports they are redirected to data port connected to memory1, when you access next 8 ports (ports #8 to #15) they redirect to memory2, and so on.
Code snippet: using CPU ports
CPU ports is the way to interact with "outside" world. Each port can be used just like any other wire input/output. Thing to know: input ports ARE NOT output ports. These are completly different objects, and, in fact, you have 16 different ports in a single data port object.
Using ports is simple. In ZASM you can either use ports just as you were using registers, or access them via special command.
Example:
Code:
mov port0,1234; //Output 1234 to port0
mov eax,port1; //Input a value into register EAX from port1. NOTICE: if make port0, it WILL NOT read the previous value. It will read value that is connected to output of data port
OR same code, but with asm operations:
Code:
out 0,1234;
in eax,1;
Which way to favor? First one is more human readable, while last one allows changing output port via register, and some more stuff.
Bookmarks