Fixed Text In ASMDATA

  The purpose is to avoid making long string equates or literal strings. String equates are limited to 255 ANSI (8 bit) characters or 127 wide (UTF-16/16 bit) characters. For longer strings multiple equates are needed; which are then concatenated, or BUILD$, at run-time. Long literal text strings distract from the logical "flow" in source code. (e.g. imagine 6 or 7 lines of text between the ID and location in a CONTROL ADD ... logical code line.) And in either case, any characters other than ASCII or Latin 1 will require the use of CHR$$() to include in the program.

  Initially things like instructions, help and license statements in mind. There is certainly no restriction to those. For short things like button tops, I find string literals or equates more practical.

Method Operation

  Method 1 (thought of first ☺ ): Creates a pseudo-dynamic string.
{background - When a string variable is declared (LOCAL, DIM, etcetera) a head memory location is assigned for the variable (PB Help calls it a handle). The memory location can be obtained with VARPTR(). When content (like text) is placed in the string, the VARPTR() address is set to the address of the first byte of the content which can be obtained with STRPTR(). At address STRPTR() minus 4 the current size of the string in BYTES (even for STRINGW) is placed. As string size changes the location of the content (STRPTR()) may change. VARPTR() stays the same for the scope of the variable.}
back to pseudo - Make the the desired text in an ASMDATA block with the size of the string first in a DD, Then the string in as many DBs, or DWs for STRINGW, as it takes. Any wide characters with code points above 255 are put as decimal or hexadecimal text of code points because the compiler only works in ANSI. The contents at address VARPTR(variablename) are set to CODEPTR(asmdatablock) + 4, simulating a dynamic string.

  Method 2: Uses PEEK$(), or PEEK$$(), to pass the string contents to a procedure. It is:
PEEK$$(CODEPTR(asmdatablock + 4), PEEK(long, CODEPTR(asmdatablock)))


Put CODE The lines -
  txt.print peek$$(wstringz, codeptr(ExitHint) + 4, 100) 'change to less than 42 to
  'txt.print peek$$(wstringz, codeptr(ExitHint) + 4, 10) 'change to less than 42 to
and -
asmdata ExitHint
  dd 1 'Real count 42 (incorrect on purpose to demonstrate WSTRINGZ use).
  dw "any key to exit . . ."$$, $$nul 'cuz I could, and show multiples in one app
end asmdata '[/code]
show

Demo Source Code

(What it does, and code section "how" or "why" remarks stay in source code comments for now. Going to be busy using it myself.)

'Fixed text in ASMDATA block(s).
'
''
' but . . .
'
'
'Putting ASMDATA {label} code pointer plus 4 in the WSTRING VARPTR() puts the
'WSTRING's first character location there (what STRPTR() returns).
'
'Sometimes during tests I was getting asian characters instead of the Latin
'based ones. #ALIGN 2 fixed that. Had not noticed a problem with string size
'being mis-read, but changed to #ALIGN 4.
'
'It was ignoring string size in MSGBOX tests. "Ding", MessageBox API takes "Z"
'strings. Put a $$NUL at the end (not counted in string size); and switched to
'TXT.WINDOW. Allows this demo to run in PBCC too.
'
'Comments thread:
'
'My web page for this (may have extended comments/explanation (someday)):
' http://www.yarker-dsyc2023/D_Notebook/Programs/Ancillary/TextInASMDATA.html
'
'!!!!!!!!!!!!!! A STRING WITH POINTER SET TO ASMDATA IS READ ONLY !!!!!!!!!!!!!!
'                          DO NOT ATTEMPT TO CHANGE
'[code]
'demo - Text stored in ASMDATA
'(no loading into string variable to use)
#compile exe
#dim all
#if %def(%pb_cc32) 'will be ignored in PBWin
  #console off     'no uneeded console in PBCC
#endif
function pbmain () as long
  local MyStr as wstring
  local hTWin as dword
  txt.window "", 100, 100, 20, 80 to hTWin
  poke dword, varptr(MyStr), codeptr(LargeStr) + 4
  txt.print MyStr
  txt.print
  txt.print "CRLFs are ignored by TXT.WINDOW. They still count for two "
  txt.print "characters each in string length (and could be needed for "
  txt.print "formating elsewhere). "
  txt.print : txt.color = &h000000E0
  poke dword, varptr(MyStr), codeptr(ExitHint) + 4
  txt.print MyStr
  txt.waitkey$
  txt.end
end function
'Next lines are 100 characters (not counting the leading apostrophe).
'The quick brown fox jumps over the lazy dog's back. 0123456789 How now brown cow? Sule benim karim.[
'The quick brown fox jumps over the lazy dog's back. 0123456789 How now brown cow? Sule'yi seviyorum!
'The quick brown fox jumps over the lazy dog's back. 0123456789 How now brown cow? @#$%^&  is300 no304
  #align 4
asmdata LargeStr
  dd 610 '305 wide characters (8 bytes for two embedded CRLFs, two for a space)
  dw "The quick brown fox jumps over the lazy dog's back. 0123456789 How now "$$
  dw "brown cow? ", chr$$(&h015E, "ule benim kar"$$, &h0131, "m.["$$), $$crlf
  dw "The quick brown fox jumps over the lazy dog's back. 0123456789 How now "$$
  dw "brown cow? ", chr$$(&h015E, "ule'yi seviyorum!"$$), $$crlf, "The quick "$$
  dw "brown fox jumps over the lazy dog's back. 0123456789 How now brown "$$
  dw "cow? @#$%^&  is300 no304"$$ + $$nul
end asmdata
'((The "fox" is an early typing practice line. I first show it with the digits
'added as a teleprinter test. It has all letters of English alphabet, number
'characters, and multiple letters and figures shifts. The "brown cow" was very
'early slang for "does the beer barrel still have beer in it?"; later an
'elocution practice line. Slipped in about wife to get a couple characters
'above 255, and use CHR$$().))
'
asmdata ExitHint
  dd 42
  dw "any key to exit . . ." 'cuz I could, and show multiples in one app
end asmdata

Created on 17 October 2023

To Dale's Notebook
go to Dale's Notebook index
To Programs
go to Programs index