Basic operation:
All of the buttons in the program have tooltips that describe what they do but here's basic steps for running a program:
-Open the app (duh)
-Click the INSERT DISK button with whatever name you want, if it doesn't exist it will be created. If you have a .8DSK file you want to use instead, just drag and drop it!
-If you are running something that isn't the demo program, load your program by dragging and dropping it's code into the app. It will automatically load into the text editor.
-Click the WRITE TO DISK button (the floppy disk on the far left bottom row) and your program will be assembled and ready for execution
-Press play!
CHS-8's limits make it what it is.
It has 3 registers (A, X, and Y) that store one 8-bit integer each.
It has over 16000 lines of program memory (64 kb)
It has 16kb of ram
A 48x48 display @ 4 bits per pixel, using a color palette of 16 colors, shown below.
And it runs at over 1 mhz!
These are addressed as:
0000 - black
0001 - dark grey
0010 - grey
0011 - light grey
0100 - dark red
0101 - red
0110 - dark amber
0111 - amber
1000 - dark yellow
1001 - yellow
1010 - dark green
1011 - green
1100 - dark blue
1101 - blue
1110 - dark purple
1111 - purple
But whenever you draw a pixel you always put four zeroes behind it in the instruction, so to draw a purple pixel it'd be
PXL,00001111
which brings me to another thing. Every instruction either has 1 or 0 arguments, like this:
UDS
would have no arguments and be left as is. Every number argument is either 8 or 16 digits long.
PXL,00001111
would have a comma and NOTHING ELSE separating the instruction and the argument. also, every argument must be either 16 or 8 zeroes long, not including the dollar sign for addressing.
Now in order to do a comment, put a # anywhere in the line.
# this is a valid comment
so is # this
and this #
comments are very flexible.
Now, basic memory management. Use comands like LDA or LDX to load values into the respective registers (A and X in this case).
LDA,00000001
loads the value of 1 in the A register. The A register will be where most operations are done (such as comparing variables, doing math, etc), so this is really important. Now something like STA or STY would ST (store) the value currently in their registers into whatever address is given to them. So something like
STA,00000000
would store the value in A in memory at address 0. To load that back into a register, say X, you could do something like
LDX,$00000000
this dollar sign is the "addressing sign", and means that the program is addressing and not using that number specifically. This means this LDX isn't loading the number 0, it's loading the value at memory address 0. You can also do this with any storing command, though it's a bit hard to understand. Something like
LDA,00000001
STA,00000000
LDA,00000011
STA,$00000000
would store the value 3 at memory address 1. Confused? I know I am! How this works is it:
-Puts the value 1 into A
-Puts the value in A (1) at memory address 0
-Puts the value 3 into A (this doesn't change anything already written, 1 stays at memory 0)
-Puts that 3 into a memory address stored at 0. So, since the number 1 is stored at 0, this gets that 1, and puts the 3 from A into 1 in memory not 0.
And that's the basics of loading and storing to memory, addressing, comments, and instruction format.
Now for loops!
Generally, these are done with headers (HED command) so that is how I will teach it. Here is an example loop that prints every color onto the screen in a line at 0,0:
LDX,00000000
TXA
TXY
HED,00000000
INX
INA
PXL,A
CMP,00001111
HNE,00000000
UDS
BRK
I'll go through this step by step as it's a lot of new stuff all at once.
LDX,00000000 -This puts the value 0 into X as seen before
TXA -Anytime you see T and then the letters of two registers, it's a Transfer command. This is TXA so it is transferring (or copying) the value in X to the value in A
TXY -This is the same thing, but transferring to Y instead. After this, all three registers are holding the value 0.
HED,00000000 -This is our first header, as seen by being Header 0. Instructions can then jump to it later.
INX -IN usually increases a variable by one (INX, INY, and INA. DE would decrease by one (DEX, DEY, and DEA) so this increases X by one
INA -increments A
PXL,A -Surprise! Registers can be used in commands as well! since PXL draws a pixel at (X register, Y register) with a color of (argument), this will draw a color defined by A (so increasing as X increases)
CMP,00001111 -CMP ("COMPARE") is our main comparing instruction (besides CLT and CGT for less than/greater then). It sets the Z flag to 1 if A is equal to it's argument, and 0 otherwise. The Z flag is used for branching commands like BEQ, HNE, and SKP to determine what they do.
HNE,00000000 -HNE is "Header if Not Equal" so if the result of CMP was "not equal" (the Z flag is set to 0) it goes to Header (argument). In this case if A hasn't yet reached 15 (the number from CMP) it will jump back to HED,00000000 and start the loop again. If A is equal to 15, this gets skipped and does nothing
UDS -This will only happen after A=15 because HNE will send you back otherwise. UDS is UpDate Screen, so any pixels you drew will be drawn to the display. THIS IS REALLY IMPORTANT IF YOU DONT HAVE THIS NOTHING WILL EVER GET DRAWN TO THE SCREEN but it is also very slow, so call it a minimal amount of times.
BRK -This ends program execution, literally just BReaK. Stops the program counter (the thing that keeps track of where everything is) from just goofing off into the wilds of the rest of ram. If your program doesn't have a BRK, ENF, or UDS in it, it will never update and it will look like the program has crashed. Put an UDS (or ENF if ou arent displaying anything) somewhere in your loop to make sure it stays updated, and a BRK at the end to make sure it stops when it should.
Remember, performance of a program is determined more by the amount of frame breaks you have (UDS, ENF, BRK) than the amount of calculations you are doing.
And there you go! your first loop written and explained. Go to Instructions if you want to learn more about all the instructions, and to anything under "Tutorials and Explanations" for more in-depth explanations.