Thursday, December 17, 2020

SmileBASIC 3DS DIALOG Instruction: Undocumented DIALOG Types

I don't know if these are documented anywhere and I'm too lazy to do the most cursory of research, so here I am posting the results of my independent discovery.  Gather 'round, because it's time for everyone's favorite thing in the world: Storytime with XT!

I was poking around the Smile tool when I noticed that the graphics editor presents a strange-looking dialog when you press Y.  It lets you press A, X, or Y to achieve various goals, or B to return to what you were doing without modifying anything.  This dialog is presented in the same graphical style as those produced by the DIALOG instruction, but it doesn't have the buttons at the bottom of the touchscreen that are normally there.  The built-in documentation for the DIALOG instruction only covers six types:
0: OK (default) 1: No/Yes 2: Back/Next 3: Cancel/Confirm 4: Cancel/Execute 5: Next
This piqued my interest, so I looked into the code.  If you also wish to do so, a simple LOAD "PRG0:SYS/SBGED" from direct mode will load the code into slot 0.  I searched through for a DIALOG instruction and came across a procedure definition on line 1228 called DLG that uses it and parameterizes the text (to a label representing DATA instructions to read), type, and caption for calling code.  Searching for code that calls it, I found that the line of code on line 1141 produces this strange dialog by calling DLG() with the type -1.

Yeah, negative one.  Interest fully attained, what other valid values are there?  I explored the negative dimension and here are the results:
-1: A/B/X/Y (A: 128, B: 129, X: 130, Y: 131) -2: D-pad (Up: 132, Down: 133, Left: 134, Right: 135) -3: A/B/X/Y and D-pad -4: L/R (L: 136, R: 137) -5: L/R and A/B/X/Y -6: L/R and D-pad -7: L/R, A/B/X/Y, and D-Pad -8: Touchscreen (Tap: 140) -9: Touchscreen and A/B/X/Y -10: Touchscreen and D-pad -11: Touchscreen, A/B/X/Y, and D-pad -12: Touchscreen and L/R -13: Touchscreen, L/R, and A/B/X/Y -14: Touchscreen, L/R, and D-pad -15: Touchscreen, L/R, A/B/X/Y, and D-pad
The numbers in parentheses are the return values from the DIALOG instruction.  These don't make it into RESULT, you have to assign it to a variable.  If it looks confusing to you, I can explain it.

Ignore all of them except for -1, -2, -4, and -8.  Notice how they only enable one distinct set of inputs to dismiss the dialog?  This is a bit field.  You can compute any of the other values by adding some or all of these four together.  Should you want to do this more easily, you can just stick this in your program:
VAR ABXY=-1 VAR DPAD=-2 VAR LR=-4 VAR TOUCHSCREEN=-8
After that, you can just add together your desired combination using the variable names and it will be self-documenting.  You may also find it cromulent to have similar variable names for the return values:
VAR DLGA=128 VAR DLGB=129 VAR DLGX=130 VAR DLGY=131 VAR DLGUP=132 VAR DLGDOWN=133 VAR DLGLEFT=134 VAR DLGRIGHT=135 VAR DLGL=136 VAR DLGR=137 VAR DLGTOUCH=140
Yes, I am beginning to hate the 3DS version of SmileBASIC for lacking user-defined constants.  All the more reason I should get SmileBASIC 4 on my Switch, I guess.

I have observed that ZL and ZR are nowhere to be found, and the return values 138 and 139 are also missing.  I tested all fifteen DIALOG types with XON EXPAD enabled on my New 3DS XL, and ZL and ZR did nothing with any of them.

I tested a handful of other values for the type parameter but came up empty.  Any value I tried that was less than -15 or greater than 5 produced an out of range error.

For the sake of completeness: If you want to inspect RESULT after showing a dialog using one of these types, it works as you'd expect for the DIALOG instruction, except that RESULT will never be -1.  Confirmation and timeout are the only values RESULT will indicate.

I hope that anyone still using SmileBASIC on the 3DS finds this useful.  I'm not sure how applicable this is to SmileBASIC 4, or the Japan-exclusive SmileBASIC BIG on the Wii U.  If this behavior was already documented elsewhere, now it's documented here as well.