ADVANCED TECHNIQUES
Updated: Mar 26, 2005

ASM + statement

  Inserts assembler language statement directly into your executable.

  Dim MyVar As Long
  ASM mov MyVar,1: ASM shl MyVar,5
  PRINT MyVar '=32
  ASM mov MyVar,esp
  PRINT "Stack pointer is "; HEX$(MyVar)
  ASM mov eax,[esp+4]: ASM mov MyVar,eax
  PRINT "Stack contains   "; HEX$(MyVar)

  Note: Assembler code can use any CPU registers but must not change esp.
  Assembler code may reference any variables dimensioned in the main 
  HotBasic code.  Assembler code may create new labels, variables and
  procedures, but these will be "unknown" (not in symbol table) to the
  HotBasic source code.  Assembler code may be inserted in any $APPTYPE.

  ASM is convenient to insert one or more assembler statements.
  BEGIN/END ASM is convenient for long assembler code insertions.
  Assembler code must be compatible with Microsoft assembler language.

BEGIN ASM +
  $INCLUDE MyCode.asm  'file contains pure assembler code
END ASM  

  BEGIN/END ASM must be used for assembler code $INCLUDE files which must
  contain only assembler code.

BYREF + statement stores a value at the location specified by its address.

  BYREF(address) = value  

  Please see the related BYREF numeric function (hotnum)

CALLFUNC(pointer,param_n,...,param_2,param_1)

  Note: the *last* parameter is listed *first*.  Cannot be used to call
  Declared SUBs or FUNCTIONs if arguments were declared.

  pointer must be dimensioned variable = CODEPTR(label) or CODEPTR(sub)

  DEFDWORD MyProcAddr,FirstParam,LastParam,RetAddr,FirstArg,LastArg
  MyProcAddr = CODEPTR(MyProc)
  'FirstParam is last pushed on to the stack below
  CALLFUNC MyProcAddr,LastParam,FirstParam
  'code
  END

  MyProc:
  POP RetAddr: POP FirstArg: POP LastArg: PUSH RetAddr 'now stack is OK
  'code
  RETURN

  Another example:
  CALLFUNC WinProcAddr,lParam,wParam,uMsg,hWnd 'hWnd is *first* argument.

  Note: please see hotobj.bas or hotdll.bas for other examples of how a
  procedure in HotBasic would handle the stack if the CALLFUNC is *not*
  in an external module. 

EXTERNAL symbol_1[, symbol_2, ... symbol_n]

  Used with multiple .obj modules each containing an EXTERNAL statement,
  where the 4-byte value or address is defined with DIM in only one
  module.  Thus, more than one module can access the same user symbol.

  EXTERNAL i, j, k  'placed in each linked .obj module
  DEFINT i, j, k    'defined in only one .obj module

MEMCPY addr1, addr2, nbytes

  where addr1 is destination, addr2 is source and nbytes is number of
  bytes to copy; all arguments are non-float values.

  MEMCPY(@M1, @M2, 8)  'or with () omitted MEMCOPY @M1, @M2, 8 

MEMSET addr, byte, count; where byte and count are integer values.

  MEMSET(@M,46,80)  'fills M with 80 dot (ASCII 46) characters.

  Caution: Improper use of MEMCPY or MEMSET will likely cause fatal error.

POP MyVar; pops application stack to MyVar; e.g., POP i: POP j

PUSH MyVar; pushes value of MyVar on to application stack.

  Caution: Improper use of POP and PUSH will likely cause fatal error.

RETVAL integer; sets SUB/FUNCTION return value; e.g., RETVAL MyVar

  Used to set return value in CallBack procedures, .obj and .dll modules.
  Use RESULT = in user-defined FUNCTIONs called from the user program.

WINDOW + statement implements FORM object property assignments or methods
  by object handle.

  WINDOW(handle).Left = 10  'set property
  WINDOW(handle).Repaint    'do method

  Syntax:  WINDOW(handle[,qualified_type]).member

  The optional qualified_type argument is needed in special cases where
  the compiler needs this information to generate special code in your
  application.  If handle alone does not work, add the qualified type.

  WINDOW(handle, TRACKBAR).color = 255 'red

  Similar WINDOW syntax applies to WINDOW in String and Numeric Funtions.


+ Penthouse (registered) version

Copyright 2003-2005 James J Keene PhD
Original Publication: Oct 8, 2003
