String Input routine
Inputs:
I : Input prompt
MAX : The maximum length of user input
BGC : Background color
TAC : Text color
TBC : Overtype/Cursor color
Outputs:
STR : user input string
Destroys:
K, X, Y, S, IX
Uses the text draw point for the position for display.
put these two lines near the beginning of your program
will fill from the draw point to (320,Y+9), where Y is the current Y draw position
Code:
"202377726D6820203D3D76716C6720203A7A75706B6663202079746F6A6562202078736E69646120202757524D4820203F2156514C4720203B5A55504B4643205F59544F4A4542202058534E49444120202B2D2A2F5E20203F333639292440202E32353828262020303134372C5D5B20203E203C7D7B20202020->SMAP
"aA1X->OVRTYPE
The actual routine (in SC3 ICE notation)
Code:
Lbl INPUT
GetTextX->X
GetTextY->Y
0->IX->S
Alloc(MAX+1->STR
SetTextTransparentColor(BGC
SetTextBGColor(BGC
SetColor(BGC
FillRectangle(X,Y,320-X,9
While 1
SetTextFGColor(TAC
SetTextXY(X,Y
PrintString(I
If *{STR
PrintString(STR
End
SetTextFGColor(TBC
PrintChar(*{OVRTYPE+S
Call K
S+(K=54 or K=48->S
If S=3
0->S
End
If K>9 and K<=47 and K!=15 and IX<MAX
*{SMAP+40*S+K-9->*{STR+IX
IX+1->IX
End
IX+(IX>~2->IX
If K=56 and IX
0->*{STR+IX
IX-1->IX
End
If K=15
0->*{STR
SetTextFGColor(TAC
Return
End
ReturnIf K=9 and *{STR
End
To use the routine:
Code:
Call INPUT
Make sure that BGC, TAC, and TBC are set before the routine is called (unless you replace them inside the actual routine), also that I is set to a string (the input prompt), and MAX is set to the longest string that you want the user to input.
This routine does all of its drawing from the current draw point to (320,Y+9) where Y is the current Y draw point.
Display hexadecimal (0 to 255):
Inputs: C - character to display
put this line near the beginning of your program:
Code:
'0123456789ABCDEF->HEX
the actual routine:
Code:
PrintChar(*{HEX+C/16
PrintChar(*{HEX+remainder(C,16
Number Input routine using arrow keys
Inputs:
I : Input prompt
N : minimum input value. Also the initial input value.
MAX : Maximum input value.
STEP: amount to go up/down for each arrow press.
Outputs:
N : Inputted value
Destroys:
K, X, Y
Uses the text draw point for the position for display.
will fill from the draw point to (320,Y+9), where Y is the current Y draw position.
Code:
Lbl NUMI
GetTextX->X
GetTextY->Y
N->MIN
Repeat K=9 or K=15
FillRectangle(X,Y,320-X,9
SetTextXY(X,Y
PrintString(I
PrintUInt(N
Call K
min(MAX,~STEP+max(MIN+STEP,STEP+N+STEP*((K=3)-(K=2->N
End
Return
This routine does all of its drawing from the current draw point to (320,Y+9) where Y is the current Y draw point.
Any of the variable names any of these routines can easily be modified (obviously), but make sure that you don't forget to not use any of the variables destroyed by the routine if you need them to retain their value before and after the routine.