VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   4590
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7875
   LinkTopic       =   "Form1"
   ScaleHeight     =   4590
   ScaleWidth      =   7875
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton TestBtn 
      Caption         =   "Test"
      Height          =   375
      Left            =   3000
      TabIndex        =   1
      Top             =   4080
      Width           =   1575
   End
   Begin VB.ListBox List1 
      Height          =   3765
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   7575
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' ==========================================================================
' Demo: Double-precision Float Point Calculation
' Caution: no error check for the sake of briefness and understandability
' Tips:
' You can use Double-precision float data in dongle program. ROCKEY5 have complete
' support for it. It can give more security.
' ==========================================================================
' Calculation formula:
' x = x*cos@-y*sin@
' y = x*sin@+y*cos@
'
' Input 24 bytes(8 bytes for each double data):
' x in 0-7 bytes
' y in 8-15 bytes
' @ in 16-23 bytes, radian
' output:
' x in 0-7 bytes
' y in 8-15 bytes
' ==========================================================================
'void main()
'{
'unsigned char buf[24];
'unsigned char x[8],y[8],deta[8];
'unsigned char cosdeta[8],sindeta[8];
'unsigned char xcos[8],xsin[8],ycos[8],ysin[8];
 
 'get_input(buf,0,0,24);
' memcpy(x,buf,8);
' memcpy(y,buf+8,8);
' memcpy(deta,buf+16,8);
'double_cos(deta,cosdeta);
'double_sin(deta,sindeta);
'double_mul(x,cosdeta,xcos);
'double_mul(x,sindeta,xsin);
'double_mul(y,cosdeta,ycos);
'double_mul(y,sindeta,ysin);
'double_sub(xcos,ysin,x);
'double_add(xsin,ycos,y);
'memcpy(buf,x,8);
'memcpy(buf+8,y,8);
'set_response(16,buf);
'exit();
'}

Private Sub TestBtn_Click()
Dim errcode, num, hic, i As Long
Dim cmddata(0 To 1024) As Byte ' command buffer
Dim buffer(0 To 255) As Byte ' user buffer
Dim dbuf(0 To 7) As Byte
Dim x, y, x1, y1, delta As Double
Dim curline As Integer

' convert from double.bin 
Const DOUBLE_SIZE = 865
Dim g_progDouble(0 To DOUBLE_SIZE - 1) As Byte
Dim pos As Long
Dim varArray() As Variant

pos = 0
varArray = Array(&H2, &H3, &H51, &H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H8, &HE4, &HF5, &H6B, &HF5)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6C, &H75, &H6D, &H18, &H12, &H3, &H1B, &H78, &H20, &H7C, &H0, &H7D, &H0, &H7B, &H0, &H7A)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H0, &H79, &H8, &H7E, &H0, &H7F, &H8, &H12, &H2, &H36, &H78, &H28, &H7C, &H0, &H7D, &H0)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H7B, &H0, &H7A, &H0, &H79, &H10, &H7E, &H0, &H7F, &H8, &H12, &H2, &H36, &H78, &H30, &H7C)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H0, &H7D, &H0, &H7B, &H0, &H7A, &H0, &H79, &H18, &H7E, &H0, &H7F, &H8, &H12, &H2, &H36)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H30, &H75, &H6B, &H0, &H75, &H6C, &H0, &H75)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6D, &H38, &H12, &H2, &HDD, &H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H30, &H75, &H6B)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H0, &H75, &H6C, &H0, &H75, &H6D, &H40, &H12, &H2, &HFC, &H75, &H68, &H0, &H75, &H69, &H0)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H75, &H6A, &H20, &H75, &H6B, &H0, &H75, &H6C, &H0, &H75, &H6D, &H38, &H75, &H6E, &H0, &H75)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6F, &H0, &H75, &H70, &H48, &H12, &H2, &H87, &H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H20, &H75, &H6B, &H0, &H75, &H6C, &H0, &H75, &H6D, &H40, &H75, &H6E, &H0, &H75, &H6F, &H0)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H75, &H70, &H50, &H12, &H2, &H87, &H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H28, &H75)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6B, &H0, &H75, &H6C, &H0, &H75, &H6D, &H38, &H75, &H6E, &H0, &H75, &H6F, &H0, &H75, &H70)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H58, &H12, &H2, &H87, &H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H28, &H75, &H6B, &H0)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H75, &H6C, &H0, &H75, &H6D, &H40, &H75, &H6E, &H0, &H75, &H6F, &H0, &H75, &H70, &H60, &H12)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H2, &H87, &H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H48, &H75, &H6B, &H0, &H75, &H6C)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H0, &H75, &H6D, &H60, &H75, &H6E, &H0, &H75, &H6F, &H0, &H75, &H70, &H20, &H12, &H2, &HB2)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H75, &H68, &H0, &H75, &H69, &H0, &H75, &H6A, &H50, &H75, &H6B, &H0, &H75, &H6C, &H0, &H75)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6D, &H58, &H75, &H6E, &H0, &H75, &H6F, &H0, &H75, &H70, &H28, &H12, &H2, &H5C, &H78, &H8)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H7C, &H0, &H7D, &H0, &H7B, &H0, &H7A, &H0, &H79, &H20, &H7E, &H0, &H7F, &H8, &H12, &H2)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H36, &H78, &H10, &H7C, &H0, &H7D, &H0, &H7B, &H0, &H7A, &H0, &H79, &H28, &H7E, &H0, &H7F)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H8, &H12, &H2, &H36, &H75, &H68, &H10, &H75, &H69, &H0, &H75, &H6A, &H0, &H75, &H6B, &H8)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H12, &H3, &H3A, &H2, &H3, &H5D, &HE7, &H9, &HF6, &H8, &HDF, &HFA, &H80, &H46, &HE7, &H9)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HF2, &H8, &HDF, &HFA, &H80, &H3E, &H88, &H82, &H8C, &H83, &HE7, &H9, &HF0, &HA3, &HDF, &HFA)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H80, &H32, &HE3, &H9, &HF6, &H8, &HDF, &HFA, &H80, &H78, &HE3, &H9, &HF2, &H8, &HDF, &HFA)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H80, &H70, &H88, &H82, &H8C, &H83, &HE3, &H9, &HF0, &HA3, &HDF, &HFA, &H80, &H64, &H89, &H82)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H8A, &H83, &HE0, &HA3, &HF6, &H8, &HDF, &HFA, &H80, &H58, &H89, &H82, &H8A, &H83, &HE0, &HA3)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HF2, &H8, &HDF, &HFA, &H80, &H4C, &H80, &HD2, &H80, &HFA, &H80, &HC6, &H80, &HD4, &H80, &H69)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H80, &HF2, &H80, &H33, &H80, &H10, &H80, &HA6, &H80, &HEA, &H80, &H9A, &H80, &HA8, &H80, &HDA)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H80, &HE2, &H80, &HCA, &H80, &H33, &H89, &H82, &H8A, &H83, &HEC, &HFA, &HE4, &H93, &HA3, &HC8)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HC5, &H82, &HC8, &HCC, &HC5, &H83, &HCC, &HF0, &HA3, &HC8, &HC5, &H82, &HC8, &HCC, &HC5, &H83)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HCC, &HDF, &HE9, &HDE, &HE7, &H80, &HD, &H89, &H82, &H8A, &H83, &HE4, &H93, &HA3, &HF6, &H8)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HDF, &HF9, &HEC, &HFA, &HA9, &HF0, &HED, &HFB, &H22, &H89, &H82, &H8A, &H83, &HEC, &HFA, &HE0)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HA3, &HC8, &HC5, &H82, &HC8, &HCC, &HC5, &H83, &HCC, &HF0, &HA3, &HC8, &HC5, &H82, &HC8, &HCC)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HC5, &H83, &HCC, &HDF, &HEA, &HDE, &HE8, &H80, &HDB, &H89, &H82, &H8A, &H83, &HE4, &H93, &HA3)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HF2, &H8, &HDF, &HF9, &H80, &HCC, &H88, &HF0, &HEF, &H60, &H1, &HE, &H4E, &H60, &HC3, &H88)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HF0, &HED, &H24, &H2, &HB4, &H4, &H0, &H50, &HB9, &HF5, &H82, &HEB, &H24, &H2, &HB4, &H4)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H0, &H50, &HAF, &H23, &H23, &H45, &H82, &H23, &H90, &H1, &HB6, &H73, &H12, &HFF, &H0, &HE5)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H68, &H24, &H0, &HE5, &H69, &H24, &H1, &HE5, &H6A, &H24, &H2, &HE5, &H6B, &H24, &H3, &HE5)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6C, &H24, &H4, &HE5, &H6D, &H24, &H5, &HE5, &H6E, &H24, &H6, &HE5, &H6F, &H24, &H7, &HE5)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H70, &H24, &H8, &H12, &HFF, &H26, &H22, &H12, &HFF, &H0, &HE5, &H68, &H24, &H0, &HE5, &H69)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H24, &H1, &HE5, &H6A, &H24, &H2, &HE5, &H6B, &H24, &H3, &HE5, &H6C, &H24, &H4, &HE5, &H6D)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H24, &H5, &HE5, &H6E, &H24, &H6, &HE5, &H6F, &H24, &H7, &HE5, &H70, &H24, &H8, &H12, &HFF)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H28, &H22, &H12, &HFF, &H0, &HE5, &H68, &H24, &H0, &HE5, &H69, &H24, &H1, &HE5, &H6A, &H24)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H2, &HE5, &H6B, &H24, &H3, &HE5, &H6C, &H24, &H4, &HE5, &H6D, &H24, &H5, &HE5, &H6E, &H24)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6, &HE5, &H6F, &H24, &H7, &HE5, &H70, &H24, &H8, &H12, &HFF, &H27, &H22, &H12, &HFF, &H0)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HE5, &H68, &H24, &H0, &HE5, &H69, &H24, &H1, &HE5, &H6A, &H24, &H2, &HE5, &H6B, &H24, &H3)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&HE5, &H6C, &H24, &H4, &HE5, &H6D, &H24, &H5, &H12, &HFF, &H32, &H22, &H12, &HFF, &H0, &HE5)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H68, &H24, &H0, &HE5, &H69, &H24, &H1, &HE5, &H6A, &H24, &H2, &HE5, &H6B, &H24, &H3, &HE5)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H6C, &H24, &H4, &HE5, &H6D, &H24, &H5, &H12, &HFF, &H31, &H22, &H12, &HFF, &H0, &HE5, &H68)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H24, &H0, &HE5, &H69, &H24, &H1, &HE5, &H6A, &H24, &H2, &HE5, &H6B, &H24, &H3, &HE5, &H6C)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H24, &H4, &HE5, &H6D, &H24, &H5, &H12, &HFF, &HB, &H22, &H12, &HFF, &H0, &HE5, &H69, &H24)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H0, &HE5, &H6A, &H24, &H1, &HE5, &H6B, &H24, &H2, &HE5, &H68, &H24, &H3, &H12, &HFF, &HA)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H22, &H78, &H7F, &HE4, &HF6, &HD8, &HFD, &H75, &H81, &H70, &H2, &H0, &H3, &H12, &HFF, &HD)
pos = ArrayByte(varArray, pos, g_progDouble)
varArray = Array(&H22)
pos = ArrayByte(varArray, pos, g_progDouble)


num = DIC_Find()
For i = 0 To num - 1
    hic = DIC_Open(i, 0&)
    If (hic >= 0) Then
        Exit For
    End If
Next i
If (i = num) Then
    Exit Sub
End If

' a. Check supper password,it's required by writing process.
For i = 0 To 7
    cmddata(i) = 255
Next i
errcode = DIC_Command(hic, CHECK_SUPER_PASS, cmddata(0))

' b. Create exe-file.
errcode = DIC_Set(cmddata(0), FILL, 512, 0, 0&)   ' Clear buffer
errcode = DIC_Set(cmddata(0), FILE_ID, BY_VALUE, &H45, 0&)                    ' File ID
errcode = DIC_Set(cmddata(0), FILE_CLASS, BY_VALUE, &HFF, 0&)                 ' File class
errcode = DIC_Set(cmddata(0), FILE_ATTRIBUTE, BY_VALUE, FILEATTR_EXEC, 0&)    ' File attr
errcode = DIC_Set(cmddata(0), FILE_SIZE, BY_VALUE, DOUBLE_SIZE, 0&)             ' File size
Call Str2Array("7002", buffer)
errcode = DIC_Set(cmddata(0), FILE_NAME, BY_ARRAY, 0, buffer(0))
errcode = DIC_Command(hic, CREATE_FILE, cmddata(0))

' c. Write exe-file
errcode = DIC_Set(cmddata(0), WRITE_DATA, DOUBLE_SIZE, 0, g_progDOUBLE(0))
errcode = DIC_Command(hic, WRITE_FILE, cmddata(0))

' d. return to password not verified status
'    we cannot run program at super password verified status.

errcode = DIC_Close(hic)
errcode = DIC_Open(hic, 0&)

' e. Run
x = 2.4784
y = 3.59884
delta = 0.7853981634
Call Double2Array(x, dbuf)
errcode = DIC_Set(buffer(0), 0, BY_ARRAY + 8, 0, dbuf(0)) ' set x
Call Double2Array(y, dbuf)
errcode = DIC_Set(buffer(0), 8, BY_ARRAY + 8, 0, dbuf(0)) ' set y
Call Double2Array(delta, dbuf)
errcode = DIC_Set(buffer(0), 16, BY_ARRAY + 8, 0, dbuf(0)) ' set delta
errcode = DIC_Set(cmddata(0), RUN_DATA, 24, &H7002, buffer(0)) ' Set to buffer
errcode = DIC_Command(hic, RUN, cmddata(0))
errcode = DIC_Get(cmddata(0), RUN_DATA, BY_ARRAY, buffer(0))  'Get result
errcode = DIC_Get(buffer(0), 0, BY_ARRAY + 8, dbuf(0))   ' Get  x
x1 = Array2Double(dbuf)
errcode = DIC_Get(buffer(0), 8, BY_ARRAY + 8, dbuf(0))   ' Get  y
y1 = Array2Double(dbuf)

List1.List(curline) = str(x1) + str(y1)
curline = curline + 1
errcode = DIC_Close(hic)

' f. print result
x1 = x * Cos(delta) - y * Sin(delta)
y1 = x * Sin(delta) + y * Cos(delta)
List1.List(curline) = str(x1) + str(y1)
curline = curline + 1

End Sub

