nathanielbabiak 2020-11-24 12:26 (Edited)
I thought someone might find these useful, figured I'd share my notes on how LowRes NX works (and common mistakes I keep making)...
The LowRes NX console performs operations in the order shown here:
() | ^ | - | */\ | MOD | +- | <>=<=> | NOT | AND | ORXOR | =
Global is overridden by (local) variables of the same name in subprogram arguments.
The manual includes the following text, but I've sorted it below a bit differently to emphasize the relations between the terms.
All graphics in LowRes NX are based on characters. A character is an 8x8-pixel image.
Sprites are independent objects, consisting of references to characters, which can be freely moved on the screen.
A background is a map of 32x32 characters, which is used for cell (i.e., text and tile) based maps or images. Each cell has the information of which character it references.
The display is composed of 3 layers, which are from back to front: Background 1, Background 0, and Sprites.
The manual's discussion of layers is incorrect (as compared to how the console behaves). The manual's text is corrected with the additions and
deletions marked here:
The display is composed of 3 layers, which are from back to front:
Each sprite and background cell has an attribute called "priority". By setting it, the cell or sprite will appear in front of the other 2 layers.
on a higher display layer. Actually there are 6 layers, from back to front:
These videos explain the graphics for the historic console that inspired this fantasy console:
INT(as stated in the manual)
SPRITE n, x, y,[c]
IFevaluates float=0 false, float<>0 true (does not typecast to int before operation).
NOTcan yield a negative value, and true evaluations return
X\2^N) predictably. They're signed!
X\2^N) or rightwards (
CHR$(10)prints/traces a new line
ROM(2), but not yet...
floatvariables (not 32 bit
intvariables), thus so-called integers are limited to 24 significant bits (i.e., avoid
SPRITE VIEW ON/OFFshows or hides the complete sprite layer without changing any of the sprites' settings (as stated in the manual). And, while hidden, both
SPRITEinstructions still work (the screen just doesn't show any sprites).
SPRITE OFF [n]and
SPRITE OFF a TO bhide sprite(s) (as stated in the manual). And, sprite settings are preserved. And, to show sprites again,
SPRITE n,x,y,[c]must be used (rather than
SPRITE n [attr ...]or
SPRITE VIEW ONas the manual might imply).
X=X+1is a valid initialization. (This is useful inside nested loops with complex program flow.) (Note the console's developer says here the behavior isn't intentional.)
COPYinstruction, the manual says: The source and the destination areas may overlap. The console copies the source area to a temporary, inaccessible buffer, then copies that buffer to the destination.
POKEWdoesn't count as memory modification, just one cc.
CALL subprogramis 1 cc.
CALL subprogram(0)is 2 cc (it's just a regular argument).
SUB SUBPROGRAMis 0 cc, even with arguments.
END SUBis 1 cc (counts towards raster interrupt subprogram's cc).
RESTORE [label]is 1 cc (including the label).
INSTRsearching doesn't count towards clock cycles.
For-next loops (
FOR X=LO TO HI STEP S) over n iterations count as:
( 2 + CC(HI) + CC(S) ) * n + ( CC(X=LO) + CC(HI) + CC(S) )
where CC(EXPRESSION) notation means clock-cycles of expression.
CC DESCRIPTION 3*N+4 FOR X=LO TO HI 3*N+6 FOR X=LO+1 TO HI 4*N+5 FOR X=LO TO HI STEP 1 6*N+7 FOR X=LO TO HI STEP 1+0 5*N+6 FOR X=LO TO HI-1 6*N+7 FOR X=LO TO HI-1 STEP 1 TRUE FALSE DESCRIPTION (INCLUDES ALL ASSEMBLY JUMPS, EXCLUDES ? EVALUATION) 1 1 IF ? THEN ... 2 1 IF ? THEN ... ELSE ... 2 T2 F2 IF ? THEN ... ELSE IF ? THEN ... 2 T3 F2 IF ? THEN ... ELSE IF ? THEN ... ELSE ... 2 1 IF ? THEN ... END IF 2 2 IF ? THEN ... ELSE ... END IF 2 T3 F2 IF ? THEN ... ELSE IF ? THEN ... END IF 3 T3 F3 IF ? THEN ... ELSE IF ? THEN ... ELSE ... END IF
WAIT 2instruction after scrolling and printing the first character on the bottom line
IF A THEN ... ELSE IF B THEN ... ELSE IF C THEN ... ELSE ...will execute the right-most
ELSE ...when any of
ASC( A$ )returns a signed value (rather than unsigned)
rilden 2020-11-24 16:40
Another thing I found out:
LowRes NX waits 2 frames when PRINT causes text to scroll up. So if you print a lot of lines, the text will scroll at 30 frames per second.
was8bit 2020-11-24 17:13
Unless you use PRINT TEXT$;
Then it only scrolls when it reaches the end of the screen
was8bit 2020-11-24 17:15
Plus, if you already use WAIT VBL in a DO LOOP, that will also add to the timing of things..
Timo 2020-11-26 18:39
"Boolean (AND/OR/NOT) operators treat any float as 0."
What do you mean? I believe both values are casted to integer and then the operator is applied. All logical operators are also binary operators by the way. That's why "true" is -1 (all bits set).
"VAL("0X"+NUMERALS$) converts hex."
This one is not on purpose. I just used the C function internally. I didn't know it does this :O
"Figure out display order of PRINT vs BG 0/1 and PRIO 0/1, but not yet..."
PRINT uses the current WINDOW. And the window command lets you set the BG.
nathanielbabiak 2020-11-27 00:23
Yep - my mistake. I only ever tested floats between 0 and 0.9999, never 1.0 or higher.
qwaffe 2020-11-27 05:28 (Edited)
this post can really benefit from some markdown formatting. i thought they were random numbers at first.
nathanielbabiak 2020-11-27 16:03 (Edited)
How do I add monospace? I tried double back-quotes (``) but it didn't work :-(
qwaffe 2020-11-28 02:36 (Edited)
put the text inside the back-quotes like normal quotes on single lines. (can be in-line.)
but code blocks are also possible. this can be quite helpful (:
nathanielbabiak 2020-11-28 03:34 (Edited)
Timo, I had to look up that emoji! Can you keep the hex conversion feature and the TRACE CHR$(10) feature? It'd be really nice to make them official...
was8bit 2020-11-28 05:28
I kinda would like to see VAL("%10") =2 and not 0... but its prolly not worth the effort to put it in...
Timo 2020-11-28 08:50 (Edited)
CHR$(10) is as expected so it’s official.
VAL(“0xFF”) doesn’t really make sense in the BASIC world as 0x is not the way here to indicate hex (it’s #).
I will probably not remove it, but I won’t add a binary version.
The only reason I see for it would be doing binary operations using strings instead of bit operators (AND OR XOR), but this is bad for performance and I won’t do this favor for was8bit ;)
was8bit 2020-11-28 09:12
oh my poor bit-brain 0o0 ;)
qwaffe 2020-11-28 11:19
isn't the way to indicate hex in nx "$" and not "#"?
was8bit 2020-11-28 12:25 (Edited)
Corerect, # and $ are side by side on the keyboard, i am sure that was just a typo... just for the record....
Hexadecimal and binary notation can be used for number values:
Timo 2020-11-28 12:59
Sorry, yes it's $. Wasn't a typo, I really don't know how my language works :O
was8bit 2020-11-28 15:08
You are busy with real life, its ok :)