home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 11 / labnotes / mk_cv.asm < prev    next >
Assembly Source File  |  1992-02-24  |  6KB  |  171 lines

  1. ;MK_CV.ASM
  2. ;Copyright (c) 1991 Jay Munro
  3. ;First Published in PC Magazine June 16, 1992
  4. ;----------------------------------------------------------------------------
  5. ;MKx and CVx are replacement routines for Visual Basic, working identically
  6. ;as their QuickBasic counterparts.  The only requirement is that they be
  7. ;declared to be recognized.
  8.  
  9. ;Syntax:  (same for all except appropriate types inserted)
  10. ;Declare Function MKI$ Lib "LabNotes.DLL" (Byval IntValue%)
  11. ;Declare Function CVI% Lib "LabNotes.DLL" (Byval IntString$)
  12. ;
  13. ;   A$ = MKI$(I%)       ;integer to string (long,single,double,currancy)
  14. ;   I% = CVI%(A$)       ;string to integer (long,single,double,currancy)
  15. ;----------------------------------------------------------------------------
  16.  
  17. .286
  18. .Model Medium
  19.     Include LabNotes.Inc
  20.     Extrn VBDerefHLStr:Proc
  21.     Extrn VBGetHLStrLen:Proc
  22.     Extrn VBCreateHLStr:Proc
  23.     Public MKI,MKL,MKS,MKD,MKC
  24.     Public CVI,CVL,CVS,CVD,CVC
  25.  
  26. .Code
  27.  
  28. ;----- Integers
  29. MKI Proc Far                    ;Export
  30.     WinProlog                   ;set up header
  31.     Lea  BX,[BP+6]              ;get address of variable on stack
  32.     Push SS                     ;push segment and offset of integer
  33.     Push BX                     ;
  34.     Push 2                      ;2 bytes long
  35.     Call VBCreateHLStr          ;create a string descriptor
  36.     WinEpilog
  37.     Ret 2
  38. MKI  EndP
  39.  
  40. ;----- Singles and Longs
  41. MKS Proc Far                    ;Export
  42. MKL Proc Far                    ;Export
  43.     WinProlog
  44.     Lea  BX,[BP+6]              ;get address of variable on stack
  45.     Push SS                     ;push segment and offset of long
  46.     Push BX
  47.     Push 4                      ;4 bytes long
  48.     Call VBCreateHLStr          ;create a string descriptor
  49.     WinEpilog
  50.     Ret 4
  51. MKL EndP
  52. MKS EndP
  53.  
  54. ;----- Currency and Doubles
  55. MKC Proc Far                    ;Export
  56. MKD Proc Far                    ;Export
  57.     WinProlog
  58.     Lea  BX,[BP+6]              ;get address of variable on stack
  59.     Push SS                     ;push segment and offset of variable
  60.     Push BX
  61.     Push 8                      ;8 bytes long
  62.     Call VBCreateHLStr          ;create a string descriptor to pass back
  63.     WinEpilog
  64.     Ret 8
  65. MKD  EndP
  66. MKC  EndP
  67.  
  68. ;----- Integers
  69. CVI  Proc Far                   ;Export
  70.      WinProlog
  71.      Lds  SI,[BP+6]             ;get address of variable on stack
  72.      Push DS                    ;push segment and offset of variable
  73.      Push SI
  74.      Call VBGetHLStrLen         ;get length of incoming string
  75.      Cmp  AX,2                  ;is it an integer length ?
  76.      Jnz  @F                    ;no, exit now
  77.      Push DS                    ;otherwise push seg & offset to get data
  78.      Push SI
  79.      Call VBDeRefHLStr          ;get data address (DX:AX)
  80.      Mov  DS,DX                 ;transfer it to DS:SI
  81.      Mov  SI,AX
  82.      LodSw                      ;get a word
  83. @@:
  84.      WinEpilog                  ;and leave with word in AX
  85.      Ret 4
  86. CVI  EndP
  87.  
  88. ;----- Longs
  89. CVL  Proc Far                   ;Export
  90.      WinProlog
  91.      Lds  SI,[BP+6]             ;get address of variable on stack
  92.      Push DS                    ;push segment and offset of variable
  93.      Push SI
  94.      Call VBGetHLStrLen         ;get length of incoming string
  95.      Mov  DX,AX                 ;is it a long int in length ?
  96.      Cmp  AX,4                  ;no, exit now
  97.      Jnz  @F                    ;otherwise push seg & offset to get data
  98.      Push DS
  99.      Push SI
  100.      Call VBDeRefHLStr          ;get data address (DX:AX)
  101.      Mov  DS,DX                 ;transfer it to DS:SI
  102.      Mov  SI,AX
  103.      Mov  AX,[SI]               ;move the data into DX:AX
  104.      Mov  DX,[SI+2]             ;and leave with data in DX:AX
  105. @@:
  106.      WinEpilog
  107.      Ret 4
  108. CVL  EndP
  109.  
  110. ;----- Single - 4 bytes
  111. CVS  Proc Far                   ;Export
  112.      WinProlog
  113.      SaveESDISI                 ;save ES,DI,SI macro
  114.      Lds  SI,[BP+8]             ;get address of string into DS:SI
  115.      Push DS                    ;push it to get length
  116.      Push SI
  117.      Call VBGetHLStrLen         ;check the length
  118.      Mov  CX,AX                 ;save it in case it's ok
  119.      Cmp  AX,4                  ;well, is it a single's length?
  120.      Jnz  @F                    ;no exit now
  121.      Push DS                    ;ok, now push DS:SI to get address of data
  122.      Push SI
  123.      Call VBDeRefHLStr          ;get string data
  124.      Mov  DS,DX                 ;transfer address to DS:SI
  125.      Mov  SI,AX
  126.      Mov  DI,[BP+6]             ;get dummy address from VB--phantom paramater
  127.      Cld                        ;forward direction on move below
  128.      Push SS                    ;point ES at SS for move DS:SI -> ES:DI
  129.      Pop  ES
  130.      Rep  MovSb                 ;move 4 bytes
  131. @@:
  132.      Mov  DX,SS                 ;send seg and address back to VB
  133.      Mov  AX,[BP+6]             ;get dummy address from VB
  134.      RestESDISI                 ;restore variables
  135.      WinEpilog
  136.      Ret 6
  137. CVS  EndP
  138.  
  139. ;----- Currency and Doubles
  140. CVC  Proc Far                   ;Export
  141. CVD  Proc Far                   ;Export
  142.      WinProlog
  143.      SaveESDISI                 ;save ES,DI,SI macro
  144.      Lds  SI,[BP+8]             ;get address of string into DS:SI
  145.      Push DS                    ;push it to get length
  146.      Push SI
  147.      Call VBGetHLStrLen         ;check the length
  148.      Mov  CX,AX                 ;save it in case it's ok
  149.      Cmp  AX,8                  ;well, is it a double's length?
  150.      Jnz  @F                    ;no exit now
  151.      Push DS                    ;ok, now push DS:SI to get address of data
  152.      Push SI
  153.      Call VBDeRefHLStr          ;get string data
  154.      Mov  DS,DX                 ;transfer address to DS:SI
  155.      Mov  SI,AX
  156.      Mov  DI,[BP+6]             ;get dummy address from VB--phantom paramater
  157.      Cld                        ;forward direction on move below
  158.      Push SS                    ;point ES at SS for move DS:SI -> ES:DI
  159.      Pop  ES
  160.      Rep  MovSb                 ;move 8 bytes
  161. @@:
  162.      Mov  DX,SS                 ;send seg and address back to VB
  163.      Mov  AX,[BP+6]             ;get dummy address from VB
  164.      RestESDISI                 ;restore variables
  165.      WinEpilog
  166.      Ret 6
  167. CVD  EndP
  168. CVC  EndP
  169.  
  170. End
  171.