'edit [help.txt] savetext [helptext saved] pr stop Yet Another Postfix Interpreter All references to variables have a prefix, to show what to do with the variable: ------------------------------------------------ > take value from stack and create new var ex: 23 >z makes a new var z, and z is 23 if var exists, make a new var anyway < put var's value onstack, then delete var ex: s [bla] $s s is now foobla , the var is actually a subroutine; run it. ex: ,moo this runs a subroutine named moo ? Does such a variable even exist? ex: ?z if z exists, -1 is onstack (true) if it doesnt, a 0 (false) is left onstack ------------------------------------------------ Special variables: ------------------------------------------------ color: the color that will be used for drawing things like lines, ovals, etc. ex: [FFFFFF] hex =color edit: the text of this editbox red green blue: the 3 components of color ex: 94 =red 233 =green 0 =blue app.x app.y app.w app.h: the location and size of the YAPI window onscreen X Y (those are CAPITAL X and Y) the current graphics coordinates for the invisible "turtle" --------------------------------------------- Another special case: using a numeric value in place of a variable name is a reference to the STACK. example: '0 places onstack a copy of the top item (equivalent to "dup" in FORTH) ('1 would be equivalent to 2dup, since this postfix thing's stack starts with item(0).) ------------------------------------------------ Most commands deal with values onstack. They take their parameters FROM the stack, and leave their results ON it. Commands: cmd what it does ---------------------------------------- \ put a "separator" onto the stack. this is for use by commands like sum, ave, and sum$, which can take any number of parameters, and they just keep taking parameters until either they hit the separator, or until there's nothing onstack at all. Most commands don't need the "\", since they each use a set # of pars. abs gives absolute value Ex: -45 abs --> 45 acos arc cosine acot arc cotangent add adds 2 values numerically ex: 5 2 add pr --->7 add$ adds 2 strings (concatenate) ex: [foo] [bla] add$ pr --->foobla and ands 2 values (logical or bitwise) (since true is -1, which in binary has all its bits on, bitwise and logical ands can be done by the same function) app.ctr centers form onscreen app.gfx hides all but the graphics area. Useful for gfx-only .stk files Careful! Once you tell it app.gfx, you can't get to the cmd area to type app.norm, so be sure to have that in a subroutine. app.norm Normal appearance; gfx AND text. app.text squishes the gfx area down to just a sliver at bottom asc gives the ascii value of a char ex: [A] asc pr --->65 asec arc secant asin arc sine atan arc tangent ave average numbers until the stack runs out or hits a separator (\) back moves the invisible "turtle" back between finds offsets between 2 delimeters ex: [qwertyuiop] [er] [i] between ---> 3 5 between$ finds a string between 2 delimiters ex: [qwertyuiop] [er] [i] between$ pr --->tyu bin take string as a binary number ex: [1001] bin pr --->9 bin$ show number AS binary ex: 9 bin$ pr --->1001 block draw a filled rectangle (a block) ex: 0 0 XY move 10 10 XY block ---> draws block from (0,0)-(10,10) chr$ given ascii val, gives the char ex: 99 chr$ pr ---> c clr clears the stack completely clrto\ clears the stack down to the nearest stack separator. cls clear graphcs AND text cos cosine cosec co-secant cot co-tangent cut$ gives a portion cut out of a string ex: [qwertyuiop] 3 2 cut$ pr ---> er (& leaves qwtyuiop onstack) deg sets all trig functions to use degrees del$ deletes a portion from a string ex: [bleah] 3 2 del$ pr -->blh div divide one value by another do take an immediate string and run it as a subroutine dot puts a pixel on the gfx window ex: 84 2 XY dot eof is the open file at its end? eos returns true if the stack is empty or at a separator. (oh, and eos deletes a stack separator if it's sitting on one) eq see if 2 numbers are equal ex: 5 5.0 eq ---> yep, they're equal eq$ see if 2 strings are equal ex: 5 5.0 eq$ ---> Nope, they're not exp natural exponent of a number f do something if a condition is FALSE ex: 'a 3 eq [[blah] pr] f ---> prints "blah" if not(a=3) false just a constant ( = 0 ) find like instr, except it takes the pos and length of previously found string, and it leaves the pos and length of the next, and also it leaves onstack the original string, too. frac get the fractional part of a number ex: 5.93 frac pr --->.93 fwd move the "turtle" forward gcls clear only the graphics window ex: somebackcolor gcls where somebackcolor is a 24-bit number such as [F0C043] hex get get image (stores in temp memory) ex: 4 5 XY move 20 10 XY get gets the image between XY coordinates (4,5)-(20,10) grad use grads for trig (400 in a circle) gfx.all select the ENTIRE graphics area for the next graphics function gfx.pr print text in the graphics area ex: 5 5 [zoop] gfx.pr --> puts the string "zoop" at (5,5) gt see if one # is greater than another gte greater than or equal hex take string as a hexadecimal # ex: [D0] hex -->208 ex: [C0C0C0] hex (as a hexcolor, this is light-gray) (could have also put &hC0C0C0) hex$ show number as hexadecimal 255 hex$ pr ---> FF img.h the height of the image that has been loaded using "loadpic" or gotten using the gfx function "get" img.w width of same image incr a for/next loop with defined increment ex: ['j pr] [j] 1 10 1 incr same as (in basic) "for j=1 to 10 step 1:print j:next j" ins$ insert one string into another ex: [bleah] [c] 5 ins$ pr ---> bleach instr find 1 string in another like in BASIC [zooplankton] [k] instr -->8 int get only the integer part of a number interval sets the interval of the event timer in milliseconds. (0 disables it) inv invert a number (x = 1/x) irnd produce a random integer ex: 100 irnd --> random integer 0-100 killto remove all vars down to a specific one (use this when a subroutine is aborted) ex: [j] killto left turn turle to the left line draw a line ex: 0 0 XY move 89 20 XY line load load a program from disk (also, this sets default progname for save) ex: [someprog.stk] load (ought to clear current program first) loadpix loads a bitmap into the temp bmp memory loadtext load a file from disk, directly to a value onstack ex: [help.txt] loadtext =edit ln natural log loc where are we in the open file? lof how big is the open file? log log base(n) ex: 1000 10 log pr -->3 lt less than lte less than or equal MD move by abs magnitude, abs direction Md absolute magnitude, relative direction mD rel mag, abs dir md rel mag, rel dir these are for POLAR coordinates. look to sample programs for examples. move move without drawing anything mouse.b read the mouse button state mouse.x read the x pos of mouse mouse.y read the y pos of mouse msg show a message (in a box) ex: [bleah] msg mul multiply 2 values nand logical or bitwise nand of 2 values neg negate a number (x = -x) neq Not equal to (numeric) neq$ Not equal to (string) new delete ALL variables nor logical or bitwise nor of 2 values not logical or bitwise not of a value onstack how many values are on the stack (before a separator if there is one, otherwise onstack total) example: 3 onstack lt [[needs 3 parameters] pr] [...do the subroutine..] tf Note: "onstack 0 eq" would be equivalent to "eos" openread opens a file for reading openwrite opens a file for writing openrw open for either read OR write or logical or bitwise or of 2 values oval draws an oval ovalf draws a filled oval over$ typeover one string inside another ex: [zooplankton] [board] 4 over$ pr ---> zooboardton pi just a constant: 3.141592654 pow to the power of ex: 2 10 pow -->1024 pr print (in the text area) put put graphic image (stored in temp memory) onscreen at current XY coordinates ex: 40 90 XY put (after using loadpic to load img, or "get" to get img from screen) prompt show an input box prompt Ex: [How many cents?] prompt >amt put.stretch puts gfx image with user-defined area, not just user-selected pos. ex: 3 3 XY move 90 90 XY put.stretch rad use radians for all trig read$ read some bytes from a file ex: 'myfile 5 read$ pr -->5 bytes readln reads a line of text from a file readbyte one byte of numeric readreal reads a 4-byte real NOT YET: readshort, readlong, readdbl rect draw a rectangle replaceat$ replace a substring within a string ex: [qwerty] 3 2 [bbb] replaceat$ pr --> qwbbbty (it deletes, then inserts a string) replaceall$ repl. all occurrances of a substring ex: [this is a test] [is] [15] replaceall$ --> th15 15 a test reverse reverse the order of stuff onstack ex: [a] [b] [c] 2 reverse right turn turtle to the right rnd random real number ex: 9.2 rnd --> random 0-9.2 round round real# to the nearest integer ex: 5.6 round pr -->6 run run an external program. ex: [notepad] run save save program (all vars) to a file ex: [myprog.stk] save or: [] save (to save last file loaded) or: (if stack is empty) save savepic saves temp bmp memory to a file savetext save onstack value to a textfile ex: 'edit [mynotes.txt] savetext scale define user scale of the graphics area usage: left right top bottom scale ex: -120 120 100 -100 scale This will scale the gfx area with (-120,100) in the upper left corner, going to (120,-100) in the btm right. (See also: unscaled.) scale.x give it only the left and right, and it scales it to 1:1 aspect and figures out the top and bottom itself scale.y give it only the top and bottom (scale.x and scale.y need work) sec secant seek goes to some offset in an open file sgn the sign of a number shell same as run, except yapi gets greyed out until your external program ends sin sine split like in perl Ex: [3,4,5,6,7] [,] split that separates the numbers onstack sqr square a number (2 pow) sqrt square root steps a for/next loop in a certain # of steps ex: ['j pr] [j] 1 5 9 steps if there were a GW-BASIC equivalent, (which there isn't) it would look like: for j=1 to 5 in 9 steps:print j:next j stop stops even if in the middle of a routine strlen measure the length of a string [haha] strlen pr -->4 sub subtract 1 # from another ex: 9 4 sub pr -->5 sub$ get a substring from a string ex: [thetwocows] 4 3 sub$ pr -->two sum sum up numbers until the stack runs out or hits a separator (\) sum$ keep adding strings until the stack runs out or hits a separator (\) t do something if a condition is TRUE 'a 5 gt [[its enuf] pr] t (says its enuf if a is more than 5) tan tangent tcls clear only the text area tf do 1 thing if true, another if false ex: 'j 'k eq [[yeah they're equal] pr] [[nope they're not] pr] tf tfont sets font name for gfx area timer read the system timer. (Not to be confused with ",timer", the name of an optional user sub for use when time timer times out.) times do something however many times ex: [90 left 50 fwd line] 4 times (makes a square) time$ the time in the format hh:mm:ss time.y what YEAR is it? time.d Day of the month time.h Hour of the day time.m minute of the hour time.s second time.ms milliseconds time.ws day of the week trig user-defined trig scaling ex: 360 trig (same as deg) or: 2 pi mul trig (same as rad) or: 1 trig (1 count per fullcircle) or: 60 inv trig (time @ 60 hz) true just a constant ( = -1 ) tsize sets font size for gfx area unscaled declare the graphics area unscaled, which means it is 1:1 pixel-for-pixel to the window its in, and the XY coordinates start with (0,0) in the upper left corner with X coords going to the right, and Y coords going down. (Like most gfx coordinates do) until do something until it returns true [100 irnd '0 pr 97 gt] until keeps printing random numbers until one of them is more than 97 while do something while it returns true (the opposite of until) writeln write a line of text to a file write$ write some bytes to a file xor logical or bitwise XOR of 2 values xnor logical or bitwise XOR of 2 values XY move with absolute XY coordinates xy move with relative xy coordinates Xy abs X coords, rel y coords xY rel x, abs y these are for RECTANGULAR coordinates Note: you could also move by directly changing the X and Y variables ex: 34 =X 54 +Y xmin leftmost visible XY coordinate, in whatever scaling you have chosen. ymin topmost xmax rightmost ymax bottommost ------------------------------------------------ (oh, and numerical values like "&hf0" for hex and "&b1001" for binary can be used) ------------------------------------------------ User events: Name a subroutine one of these, and it will automatically run at the appropriate time autoexec -- runs when a file [.stk] is loaded. mouse -- runs when you click gfx area key -- runs when key is pressed. gfx must have focus for that to work timer -- each time the timer times out ------------------------------------------------ Known Bugs: before using the graphics area, you must either scale it, deciding on the range, OR declare it unscaled. you must do one of these things whenever you resize the graphics area. Otherwise, the scale will be inaccurate. If you've used loadpic to load a bitmap, it can cause the get/put commands to not process colors properly. ------------------------------------------------ Note the command at top: " 'edit [help.txt] savetext stop " Run this text, and it saves itself to disk. --- Need better STRING functions, not this stupid hodgepodge of disparate functions.