It is currently Wed Jan 27, 2021 1:28 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Help converting from Visual Basic
PostPosted: Fri Aug 07, 2015 4:33 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Hey all, I just need some help porting the following code from good old VB. Trying to create a front end for TightVNC, this came from ZenControl.

Original Code:
Code:
    Public Function PasswordHash()

        'Declarations
        Dim strInputString, strCode As String
        Dim intNameLength, intRnd As Integer

        strInputString = "abcdef0123456789" 'Characters to choose from to generate random string
        intNameLength = 16 'Define length of random string

        Randomize()

        'Generate the random string
        For intStep = 1 To intNameLength
            intRnd = Int((strInputString.Length * Rnd()) + 1)
            strCode = strCode & Mid(strInputString, intRnd, 1)
        Next

        'Return the string
        PasswordHash = strCode

    End Function

    Public Function ConvertBinary(ByVal strCode As String)

        'Declarations
        Dim arrBinary(8) As String
        Dim strStep As String
        Dim intCount As Integer

        'Step through the randomly generated string of hex pairs by two and convert to binary
        'while placing those binary values into an array
        For p = 0 To (strCode.Length - 2) Step 2
            strStep = strCode.Substring(p, 2)
            Dim b As Integer = Convert.ToInt32(strStep, 16)
            arrBinary(intCount) = b
            intCount = intCount + 1
        Next

        'Return the populated array
        ConvertBinary = arrBinary

    End Function


Here's what I came up with for the Password Hash function:
Code:
Procedure CreatePassword()
strInputString.s
strCode.s
intNameLength.i
intRnd.i

strInputString = "ABCDEF0123456789" ;Characters To choose from To generate random string
intNameLength = 16 ;Define length of random string

;Generate the random string
For intStep = 1 To intNameLength
   intRnd = Random(8)
   strCode = strCode + Mid(strInputString, intRnd, 1)
Next
;Return the string
PasswordHash.s = strCode
Debug PasswordHash

EndProcedure


Here's what I have for the ConvertBinary:
Code:
Procedure ConvertBinary(strCode.s)

  Dim arrBinary.s(8)
   strStep.s
   intCount.i

;Step through the randomly generated string of hex pairs by two And convert To binary
;while placing those binary values into an Array
  For p = 1 To (Len(strCode)) Step 2
     strStep = Mid(strCode,p,2)
     b.s = RSet(Bin(Val("$"+strStep)),8,"0")
     arrBinary(intCount) = b
     intCount = intCount + 1
  Next

;Return the populated array
ConvertBinary = arrBinary
EndProcedure


Last edited by OldSkoolGamer on Wed Aug 12, 2015 8:27 pm, edited 3 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Fri Aug 07, 2015 4:40 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Removed the full code for now. Edited the first post with my convertbinary function, but still not working properly...


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Thu Aug 13, 2015 3:19 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
So, got the random Hex password generation working OK as well as being able to split it into two parts or convert to binary, but still getting "authentication failure" when it tries to connect. From what it looks like the Droopy Libraries Registry function write directly to binary with the #REG_BINARY key so conversion shouldn't be necessary I don't believe, here's what I have for the password gen and the Registry functions, but I cannot get it to work so I assume there's something else I'm missing, maybe a change in VNC authentication, I dunno, feeling dumb at this point though...

The registry functions are from Droopy's lib

Code:
Procedure.s CreatePassword()
strInputString.s
strCode.s
intNameLength.i
intRnd.i

strInputString = "ADCDEF0123456789" ;Hex characters to choose from to generate random string
intNameLength = 16 ;Define length of random string

;Generate the random string
For intStep = 1 To intNameLength
   intRnd = Random(16)
    strCode = strCode + Mid(strInputString, intRnd, 1)
Next
;Return the string
PasswordHash.s = strCode
Debug PasswordHash
ProcedureReturn PasswordHash
EndProcedure


The password I had was echo123 which works with this key:

RegSetValue("HKEY_LOCAL_MACHINE\Software\TightVNC\Server","Password","CDE13BD91F2653DD",#REG_BINARY,pcname);<----password: echo123

Anyone have any idea what I'm missing or what I need to do? Maybe somehow using the built-in DESFingerprint function, or maybe I have to create a VNC connection file, write the password to that & specify the connection file upon trying to connect?

I edited the CreatePassword() procedure to return the created PasswordHash, still no go.


Last edited by OldSkoolGamer on Thu Aug 13, 2015 1:52 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Thu Aug 13, 2015 10:49 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Jan 08, 2010 11:04 pm
Posts: 105
Location: Hampshire, UK
From a quick look only.

ConvertBinary function...
You can't return an array from a function in PB. You have to pass the array to the function and fill it in.
You can't return anything in PB by assigning to the function name, use ProcedureReturn instead.

CreatePassword function...
You're not returning anything. I guess the assignment PasswordHash = strCode is lifted from the original VB.
Again, a ProcedureReturn strCode is needed.

EnableExplicit at the start of the program would have revealed both of these return issues.
I may be able to have another look later.


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Fri Aug 14, 2015 2:50 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
OK,

I finally got it figured out and working perfectly, even works in Windows 10!!! Now to clean up and optimize where I can.

Didn't need the convertbinary function as Droopy's library is able to write as #REG_BINARY, but to get the random password working you have to create a vnc config file, write the following to the file:

[connection]
host='hostname'
port=5900
password='random password'

I'll post up the code when I'm done going over it and cleaning it up, etc, but using COMate+ and WMI I think would be a better way, but I have no idea how to do that.... still a novice as it shows

To recap, here's the code I was needing help with:

Code:
Procedure.s CreatePassword()
strInputString.s
strCode.s
intNameLength.i
intRnd.i

strInputString = "ABCDEF0123456789" ;Characters To choose from To generate random string
intNameLength = 16 ;Define length of random string

;Generate the random string
For intStep = 1 To intNameLength
   intRnd = Random(16)
   strCode = strCode + Mid(strInputString, intRnd, 1)
Next
;Return the string
PasswordHash.s = strCode
EndProcedure



Here's the file creation code for the config.vnc file:

Code:
Procedure CreateConfigFile(hostname.s)
OpenFile(5,"Viewer\config.vnc")
 WriteStringN(5,"[connection]")
  WriteStringN(5,"host="+hostname)
   WriteStringN(5,"port=5900")
    WriteString(5,"password="+PasswordHash)
CloseFile(5)
EndProcedure

I made the PasswordHash a global variable for now, but will fix that.

Here's the code that runs the TightVNC Viewer:

Code:
Procedure RunViewer()
RunProgram("Viewer\tvnviewer.exe","-optionsfile=Viewer\config.vnc","",#PB_Program_Wait)
EndProcedure


Thanks to bosker for his thoughts as it got me thinking to look over the ZenControl code again, without which this would have been much harder.


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Fri Aug 14, 2015 11:47 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
Here's a link to the full program including source. Please help to improve if you can. I still need to figure out whose libraries I used besides srod & Droopy and give proper credit. Apologies in advance if you're one I forgot to credit.

Code:
;***************************************************
;*             Created with the following libraries and code                *
;*                                                                                        *
;*                           COMate+ by srod                                      *
;*                         Droopylib by Droopy                                     *
;*         ListIcon search by FloHimself (updated by blbltheworm)      *
;*          ListIcon Sort by (Unknown) (Rewritten by netmaestro)      *
;*        Based on the original ZenControl code for VB by (Unknown)  *
;*                       Services code by TeddyLM                               *
;*                                 with                                                  *
;*               other code pulled from the PureBasic forums               *
;***************************************************


https://app.box.com/s/rl3vn6uqkv91qivz4imh8jq74t46baoi


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Sat Aug 15, 2015 9:33 am 
Offline
Always Here
Always Here

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 5219
Location: Germany
Hi,

your CreatePassword() procedure is buggy:
Random(16) can also return 0, but Mid() needs at minimum 1 as Startpos.

Than you declare that the procedure returns a string, but you return nothing.

In your CreateConfigFile() you use OpenFile().
That's also wrong in this case, since if the last file is larger than the new one, the rest of the old file
is not deleted. Use CreateFile() instead.
Also use #PB_Ascii, to be sure the file is always in the right format.

I don't know if ASCII - Unicode is a further problem in your programm.


It should look like this:
Code:
Procedure.i CreateConfigFile(hostname$, PasswordHash$)
 
  Protected.i File, Result
 
  File = CreateFile(#PB_Any, "Viewer\config.vnc")
  If File
    WriteStringN(File, "[connection]", #PB_Ascii)
    WriteStringN(File, "host=" + hostname$, #PB_Ascii)
    WriteStringN(File, "port=5900", #PB_Ascii)
    WriteString(File, "password=" + PasswordHash$, #PB_Ascii)
    CloseFile(File)
    Result = #True
  EndIf
 
  ProcedureReturn Result
 
EndProcedure




Procedure.s CreatePassword()
 
  Protected intStep.i, strCode$
 
  ;Generate the random string
  For intStep = 1 To 16
    strCode$ + Mid("ABCDEF0123456789", Random(16, 1), 1)
  Next
 
  ;Return the string
  ProcedureReturn strCode$
 
EndProcedure



Procedure ConvertBinary(strCode$, Array Byte.a(1))
 
  Protected.i p, Length
 
  ;Step through the randomly generated string of hex pairs by two And convert To binary
  ;while placing those binary values into an Array
 
  Length = Len(strCode$)
 
  For p = 1 To Length Step 2
     Byte(p >> 1) = Val("$" + Mid(strCode$, p, 2))  ; >> 1 is faster than / 2
  Next
 
EndProcedure



Define Password$, i.i
Dim PasswordArray.a(7)  ; 0...7 -> 8 elements

Password$ = CreatePassword()
Debug Password$

ConvertBinary(Password$, PasswordArray())

For i = 0 To 7
  Debug RSet(Hex(PasswordArray(i)), 2, "0")
Next i

If CreateConfigFile("192.168.0.1", Password$)
  Debug "Ok"
Else
  Debug "Failed"
EndIf


I can not try your complete stuff at the moment.

Bernd


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Sun Aug 16, 2015 6:23 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Dec 15, 2008 11:15 pm
Posts: 142
Location: Nashville, TN
infratec,

Thanks for the tips, I'll change those ASAP.


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Sun Aug 16, 2015 7:13 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
Why not simply convert a random quad to hex for the password generation ?
Code:
Procedure.s CreatePassword()
 
  Protected randomQuad.q
 
  RandomData(@randomQuad, 8)
  ProcedureReturn RSet(Hex(randomQuad), 16, "0")
 
EndProcedure

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Tue Aug 18, 2015 8:07 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 9:24 am
Posts: 582
Location: Almaty (Kazakhstan)
can you help me too? project was in Visual Basic 6. it have some nice library for sound - OPN_DLL.dll http://mnp.tut.su/file/OPN_DLL.dll

but i am not understand how to convert notes to this format. it have some strange "And", "Or" command when it is not "If" command. and "\" and "^"... it is a little confuse me.

Image

Code:
Enumeration
  #Window
 
  #Do
  #Re
  #Mi
  #Fa
  #Sol
  #Lya
  #Sii
EndEnumeration

;Private Declare Function OpenOPNDriver Lib "OPN_DLL" (ByVal Chips As Byte) As Byte
;Private Declare Sub CloseOPNDriver Lib "OPN_DLL" ()
;Private Declare Sub OPN_Write Lib "OPN_DLL" (ByVal ChipID As Byte, ByVal Register As Integer, _
;    ByVal Data As Byte)
;Private Declare Sub OPN_Mute Lib "OPN_DLL" (ByVal ChipID As Byte, ByVal MuteMask As Byte)

OPNhdll = OpenLibrary(0, "OPN_DLL.dll")

If OPNhdll
  Prototype OpenDriver(int.i)
  Prototype CloseDriver()
  Prototype OPNWrite(int.i,int2.i,int3.i) 
 

  Global OpenOPNDriver.OpenDriver = GetFunction(0, "OpenOPNDriver")
  Global CloseOPNDriver.CloseDriver = GetFunction(0, "CloseOPNDriver")
  Global OPN_Write.OPNWrite = GetFunction(0, "OPN_Write") 
EndIf

;{ setup
   OpenOPNDriver(1)
   
   OPN_Write(0, $30, $74)
   OPN_Write(0, $34, $72)
   OPN_Write(0, $38, $74)
   OPN_Write(0, $3C, $71)

   OPN_Write(0, $40, $23)
   OPN_Write(0, $44, $26)
   OPN_Write(0, $48, $2A)
   OPN_Write(0, $4C, $00)

   OPN_Write(0, $50, $1F)
   OPN_Write(0, $54, $1F)
   OPN_Write(0, $58, $19)
   OPN_Write(0, $5C, $12)

   OPN_Write(0, $60, $00)
   OPN_Write(0, $64, $00)
   OPN_Write(0, $68, $0E)
   OPN_Write(0, $6C, $07)

   OPN_Write(0, $70, $00)
   OPN_Write(0, $74, $00)
   OPN_Write(0, $78, $00)
   OPN_Write(0, $7C, $00)

   OPN_Write(0, $80, $07)
   OPN_Write(0, $84, $08)
   OPN_Write(0, $88, $24)
   OPN_Write(0, $8C, $18)

   OPN_Write(0, $90, $00)
   OPN_Write(0, $94, $00)
   OPN_Write(0, $98, $00)
   OPN_Write(0, $9C, $00)

   OPN_Write(0, $B0, $3B)
   OPN_Write(0, $B4, $04)

   OPN_Write(0, $B4, $C0)
;}


;Private Function GetOPNNote(ByVal Note As Byte, ByVal Pitch As Integer) As Integer
Procedure.i GetOPNNote(Note.b, Pitch.i)

;    Dim FreqHz As Double
;    Dim BlkNum As Integer
;    Dim FNum As Double
;    Dim CurNote As Double
   
;    CurNote = Note + Pitch / 128#
     CurNote = Note + Pitch / 128# - what this # For visual basic 6.0 means????
   
;    FreqHz = 440# * 2# ^ ((CurNote - 69) / 12#)
     FreqHz = 440# * 2# ^ ((CurNote - 69) / 12#) - what this ^ ??????
   
;    ' must be Note, not CurNote, to avoid changing octaves
;    BlkNum = (Note \ 12) - 1
     BlkNum = (Note \ 12) - 1  - why this \ not / ?????
     
;    If BlkNum < &H0 Then
     If BlkNum < $0
;        BlkNum = &H0
        BlkNum = $0
;    ElseIf BlkNum > &H7 Then
     ElseIf BlkNum > $7
;        BlkNum = &H7
       BlkNum = $7
;    End If
     EndIf

;    'FNum = (144 * FreqHz * 2 ^ 20 / 7670454) / 2 ^ (BlkNum - 1)
;    FNum = (144 * FreqHz / 7670454) * 2 ^ (21 - BlkNum)
     FNum = (144 * FreqHz / 7670454) * 2 ^ (21 - BlkNum)  - again ^
;    FNum = Int(FNum + 0.5)
     FNum = FNum + 0.5

;    If FNum < 0 Then
     If FNum < 0
;        FNum = 0
       FNum = 0
;    ElseIf FNum > &H7FF Then
     ElseIf FNum > $7FF
;        FNum = &H7FF
       FNum = $7FF
;    End If
     EndIf
   
;    GetOPNNote = FNum Or BlkNum * &H800 - it is probably return. what is Or means?
     ProcedureReturn FNum

;End Function
EndProcedure


If OpenWindow(#Window, 100, 100, 430, 160, "piano", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
 
  ButtonGadget(#Do, 20, 50, 30, 70, "Do")
 
  ButtonGadget(#Re, 80, 50, 30, 70, "Re")
 
  ButtonGadget(#Mi, 140, 50, 30, 70, "Mi")
 
  ButtonGadget(#Fa, 200, 50, 30, 70, "Fa")
 
  ButtonGadget(#Sol, 260, 50, 30, 70, "Sol")
 
  ButtonGadget(#Lya, 320, 50, 30, 70, "Lya")
 
  ButtonGadget(#Sii, 380, 50, 30, 70, "Si")
 
  Repeat
   
    Event = WaitWindowEvent()
   
    Select Event

       Case #PB_Event_Gadget
         
         Select EventGadget()
           Case #Do ; 90 for example
             ;FNum = GetOPNNote(PreviewOctave * 12 + PreviewNote, 0)
             ;Call OPN_Write(&H0, &HA4, (FNum And &H7F00) / &H100)
             ;Call OPN_Write(&H0, &HA0, FNum And &HFF)
             
             ; set note
             FNum = GetOPNNote(PreviewOctave * 12 + 90, 0)
             OPN_Write(0, $A4, (FNum And $7F00) / $100) - what this And means???
             OPN_Write(0, $A0, FNum And $FF) - same And

             ; play, pause, stop
             OPN_Write(0, $28, $F0)
             Delay(500)
             OPN_Write(0, $28, $00)

             
         EndSelect
         
       Case #PB_Event_CloseWindow
         Quit = 1
     EndSelect
   Until Quit = 1
   
   CloseOPNDriver()
   CloseLibrary(0)
   
EndIf


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Tue Aug 18, 2015 8:37 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
SeregaZ wrote:
can you help me too? project was in Visual Basic 6. it have some nice library for sound - OPN_DLL.dll http://mnp.tut.su/file/OPN_DLL.dll

but i am not understand how to convert notes to this format. it have some strange "And", "Or" command when it is not "If" command. and "\" and "^"... it is a little confuse me.

Image

I think it should be something like this
Code:
Enumeration
  #Window
 
  #Do
  #Re
  #Mi
  #Fa
  #Sol
  #Lya
  #Sii
EndEnumeration

;Private Declare Function OpenOPNDriver Lib "OPN_DLL" (ByVal Chips As Byte) As Byte
;Private Declare Sub CloseOPNDriver Lib "OPN_DLL" ()
;Private Declare Sub OPN_Write Lib "OPN_DLL" (ByVal ChipID As Byte, ByVal Register As Integer, _
;    ByVal Data As Byte)
;Private Declare Sub OPN_Mute Lib "OPN_DLL" (ByVal ChipID As Byte, ByVal MuteMask As Byte)

OPNhdll = OpenLibrary(0, "OPN_DLL.dll")

If OPNhdll
  Prototype OpenDriver(int.i)
  Prototype CloseDriver()
  Prototype OPNWrite(int.i,int2.i,int3.i) 
 

  Global OpenOPNDriver.OpenDriver = GetFunction(0, "OpenOPNDriver")
  Global CloseOPNDriver.CloseDriver = GetFunction(0, "CloseOPNDriver")
  Global OPN_Write.OPNWrite = GetFunction(0, "OPN_Write") 
EndIf

;{ setup
   OpenOPNDriver(1)
   
   OPN_Write(0, $30, $74)
   OPN_Write(0, $34, $72)
   OPN_Write(0, $38, $74)
   OPN_Write(0, $3C, $71)

   OPN_Write(0, $40, $23)
   OPN_Write(0, $44, $26)
   OPN_Write(0, $48, $2A)
   OPN_Write(0, $4C, $00)

   OPN_Write(0, $50, $1F)
   OPN_Write(0, $54, $1F)
   OPN_Write(0, $58, $19)
   OPN_Write(0, $5C, $12)

   OPN_Write(0, $60, $00)
   OPN_Write(0, $64, $00)
   OPN_Write(0, $68, $0E)
   OPN_Write(0, $6C, $07)

   OPN_Write(0, $70, $00)
   OPN_Write(0, $74, $00)
   OPN_Write(0, $78, $00)
   OPN_Write(0, $7C, $00)

   OPN_Write(0, $80, $07)
   OPN_Write(0, $84, $08)
   OPN_Write(0, $88, $24)
   OPN_Write(0, $8C, $18)

   OPN_Write(0, $90, $00)
   OPN_Write(0, $94, $00)
   OPN_Write(0, $98, $00)
   OPN_Write(0, $9C, $00)

   OPN_Write(0, $B0, $3B)
   OPN_Write(0, $B4, $04)

   OPN_Write(0, $B4, $C0)
;}


Procedure.i GetOPNNote(Note.i, Pitch.i)
 
  Protected.d FreqHz, CurNote
  Protected.i BlkNum, FNum
 
  CurNote = Note + Pitch / 128
  FreqHz = 440 * Pow(2, (CurNote - 69) / 12)
 
  BlkNum = Note / 12 - 1
  If BlkNum < 0
    BlkNum = 0
  ElseIf BlkNum > 7
    BlkNum = 7
  EndIf

  FNum = Round((144 * FreqHz / 7670454) * Pow(2, 21 - BlkNum), #PB_Round_Nearest)
  If FNum < 0
    FNum = 0
  ElseIf FNum > $7FF
    FNum = $7FF
  EndIf
   
  ProcedureReturn FNum | (BlkNum * $800)

EndProcedure


If OpenWindow(#Window, 100, 100, 430, 160, "piano", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
 
  ButtonGadget(#Do, 20, 50, 30, 70, "Do")
 
  ButtonGadget(#Re, 80, 50, 30, 70, "Re")
 
  ButtonGadget(#Mi, 140, 50, 30, 70, "Mi")
 
  ButtonGadget(#Fa, 200, 50, 30, 70, "Fa")
 
  ButtonGadget(#Sol, 260, 50, 30, 70, "Sol")
 
  ButtonGadget(#Lya, 320, 50, 30, 70, "Lya")
 
  ButtonGadget(#Sii, 380, 50, 30, 70, "Si")
 
  Repeat
   
    Event = WaitWindowEvent()
   
    Select Event

       Case #PB_Event_Gadget
         
         Select EventGadget()
           Case #Do ; 90 for example
             ;FNum = GetOPNNote(PreviewOctave * 12 + PreviewNote, 0)
             ;Call OPN_Write(&H0, &HA4, (FNum And &H7F00) / &H100)
             ;Call OPN_Write(&H0, &HA0, FNum And &HFF)
             
             ; set note
             FNum = GetOPNNote(PreviewOctave * 12 + 90, 0)
             OPN_Write(0, $A4, FNum >> 8)
             OPN_Write(0, $A0, FNum & $FF)

             ; play, pause, stop
             OPN_Write(0, $28, $F0)
             Delay(500)
             OPN_Write(0, $28, $00)

             
         EndSelect
         
       Case #PB_Event_CloseWindow
         Quit = 1
     EndSelect
   Until Quit = 1
   
   CloseOPNDriver()
   CloseLibrary(0)
   
EndIf

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Tue Aug 18, 2015 8:52 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 9:24 am
Posts: 582
Location: Almaty (Kazakhstan)
FNum >> 8 i read something about it... it some kind of shift, right?
FNum & $FF what this & means? some kind of +, but more as + for string, not mathematiks?


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Tue Aug 18, 2015 9:01 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3710
Location: Netherlands
SeregaZ wrote:
FNum >> 8 i read something about it... it some kind of shift, right?
FNum & $FF what this & means? some kind of +, but more as + for string, not mathematiks?

>> 8 is a shift operation that does the same as the original code you posted (get the high byte of FNum).
& is a bitwise and operation. In this case it keeps only the low byte of FNum.
| is a bitwise or operation.

Visual basic ^ is for exponentiation.
Visual basic \ is an integer division.

_________________
macOS 10.15 Catalina, Windows 10


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Tue Aug 18, 2015 9:10 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 9:24 am
Posts: 582
Location: Almaty (Kazakhstan)
thanks a lot for explanations :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Help converting from Visual Basic
PostPosted: Sat Jan 02, 2016 8:26 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 20, 2009 9:24 am
Posts: 582
Location: Almaty (Kazakhstan)
my work is going far and time is come for converting operation. and after a tests i can see - probably this procedure have some a little wrong things.

by this procedure
Code:
FNum = GetOPNNote($10, 0)
Debug "$A4 " + Hex(FNum >> 8)
Debug "$A0 " + Hex(FNum & $FF)


shows
$A4 = 3
$A0 = 2B

but another programm (i think that programm is correct) shows:
$A4 = B
$A0 = 2B

where can be this little mistake? is that problem of rounding?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye