Author Topic: bcx to Oxygen basic  (Read 4780 times)

0 Members and 1 Guest are viewing this topic.

Emil_halim

  • Guest
bcx to Oxygen basic
« on: March 31, 2013, 11:47:40 AM »
Hi all,

I have a function from BCX that i want to convert to work with Oxygen

here it is
Code: [Select]
char *AppExePath (void)
{
 static char strtmp[ 2048 ];
 register int i;
 i=GetModuleFileName(GetModuleHandle(0),strtmp, 2048);
 while(i && strtmp[i] != 0x5C)
   i--;
 strtmp[i+1] = 0;
 return strtmp;
}


Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #1 on: March 31, 2013, 12:06:52 PM »

i was think that , Oxygen will understand c function , so what is the minimal changes to make the previous
function to work with Oxygen basic?

Charles Pegge

  • Guest
Re: bcx to Oxygen basic
« Reply #2 on: March 31, 2013, 03:34:34 PM »
Close. (Stand-alone example)

extern lib kernel32.dll
! GetModuleHandle   alias "GetModuleHandleA"  
! GetModuleFileName alias "GetModuleFileNameA"
end extern

sys x 'workaround for strange glitch


char* AppExePath(void)
{
  static char strtmp[2048]
  sys i
  i=GetModuleFileName(GetModuleHandle(0), strptr strtmp, 2048)
  while asc(strtmp,i) != 0x5c
    i--
  wend
  mid strtmp,i+1,chr 0
  return strtmp
}

print AppExePath
« Last Edit: April 01, 2013, 04:29:34 AM by Charles Pegge »

Charles Pegge

  • Guest
Re: bcx to Oxygen basic
« Reply #3 on: April 01, 2013, 04:24:48 AM »
Closer:

extern lib kernel32.dll
! GetModuleHandle   alias "GetModuleHandleA"  
! GetModuleFileName alias "GetModuleFileNameA"
end extern

sys x 'workaround for strange glitch

char* AppExePath(void)
{
  indexbase 1
  static byte b[512]
  sys i=GetModuleFileName(GetModuleHandle(0), @b, 512)
  while b[ i ] != 0x5c
    i--
  wend
  b[ i+1 ]=0
  = @b 'low level
  return
}


print AppExePath


I have corrected the glitch, so I will post an update to Oxygen.

Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #4 on: April 01, 2013, 10:52:48 AM »

very nice work Charles,

this example works very well , but when i put this function "AppExePath" in my code , it compiled okay but did not run.

when comment it , every thing is okay , that drive my crazy  >:(

any help please   

Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #5 on: April 01, 2013, 11:11:39 AM »

to be more specific

this work okay
Code: [Select]

print AppExePath()

string cmd,File,AppPath
sys ii
  cmd = GetCommandLine()
  ii=instr(cmd," ")
  if ii
    ii++
    File=mid(cmd,ii,len(cmd)-ii+1)
  end if


but this ont
Code: [Select]
string cmd,File,AppPath
sys ii
  cmd = GetCommandLine()
  ii=instr(cmd," ")
  if ii
    ii++
    File=mid(cmd,ii,len(cmd)-ii+1)
  end if

print AppExePath()


Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #6 on: April 01, 2013, 11:39:50 AM »

after many tries i successefly it worked.

there was two things

first , when using this , it did not work
Code: [Select]
extern lib kernel32.dll
! GetModuleHandle   alias "GetModuleHandleA"   
! GetModuleFileName alias "GetModuleFileNameA"
end extern
   
but this work
Code: [Select]
! GetCommandLine lib "kernel32.dll" alias "GetCommandLineA" () as char* 
! GetModuleFileName lib "kernel32.dll" alias "GetModuleFileNameA" (sys a,char* b,sys c) as int

second ,this not work
Code: [Select]
sys i=GetModuleFileName(GetModuleHandle(0), @b, 512)

but this works
Code: [Select]
push 512 : addr eax , b :  push eax : GetModuleHandle(0) : push eax
  call GetModuleFileName
  mov i , eax

i think @b did not return the correct address in long code , but do wrok with shourt code , strange things
is'nt it?

Charles is there a BUG

Charles Pegge

  • Guest
Re: bcx to Oxygen basic
« Reply #7 on: April 01, 2013, 12:53:23 PM »
Hi Emil,

Try the latest update. Should be clear of the declarations bug.

This works, but you will need to do some parsing work on the CmmandLine file: (stripping quote marks)

extern lib kernel32.dll

! GetCommandLine    alias "GetCommandLineA"
! GetModuleFileName alias "GetModuleFileNameA"
! GetModuleHandle   alias "GetModuleHandleA"  

end extern


'includepath "$\inc\"
'include "minwin.inc"


char* AppExePath()
{
  static byte b[256]
  sys i
  a=GetModuleHandle(0)
  i=GetModuleFileName(a, @b, 256)
  while b[ i ] != 0x5c
    i--
  wend
  b[ i+1 ]=0
  = @b
  return
}

print AppExePath


string cmd,File,AppPath
sys ii
  cmd = cast zstring GetCommandLine()
  ii=instr(cmd," ")
  if ii
    ii++
    File=mid(cmd,ii,len(cmd)-ii+1)
  end if

print file
« Last Edit: April 01, 2013, 12:59:45 PM by Charles Pegge »

Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #8 on: April 02, 2013, 07:51:57 AM »

Hi Charles,

no luck , after updating has the same error.

Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #9 on: April 02, 2013, 09:03:46 AM »

okay , it works now , do not ask me why , because i really do not know.

Does Oxygen unstable ? 

Charles Pegge

  • Guest
Re: bcx to Oxygen basic
« Reply #10 on: April 02, 2013, 10:48:03 AM »
Sometimes, I think the OS picks up the wrong DLL.

And don't forget, this is alpha software. There are more permutations than many languages have. Error trapping is not very tight at this stage of its development, so you have to code defensively, and test your program as you grow it.

The other extreme would be to have a very strict language with only one coding style. IronJawBasic ? :)

Charles

 

JRS

  • Guest
Re: bcx to Oxygen basic
« Reply #11 on: April 02, 2013, 10:58:36 AM »
Quote
IronJawBasic

There is a Blunt-Axe Basic to ASM translator Steve wrote so I think that base is covered. Please continue on with the O2 destiny as you see it.

Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #12 on: April 02, 2013, 12:42:33 PM »

Okay , i was playing with your getword function that split the line code into tokens.

so i start a new one , getline , based on getword , but it does not act like i want

here it is ,
Quote
function getline(s as string, b as sys) as string 
'================================================   
  sys c,bb
  bb=b
  do 
    c=asc(s,b) 
    if c=0 then exit do 
    if c=13 and asc(s,b+1)=10 then exit do
    b+=1 
  end do 
  if b>bb then return mid(s,bb,b-bb) 
end function     

sys i = 1
string lin
    do
       lin =  getline(src,i)
       if not lin then exit do
       print lin
    end do
 

so what code be wrong here?

Charles Pegge

  • Guest
Re: bcx to Oxygen basic
« Reply #13 on: April 02, 2013, 04:13:22 PM »
Emil,

You just need to skip the crlf

function getline(s as string, b as sys) as string 
  '
  sys c,bb
  bb=b
  do 
    c=asc(s,b) 
    if c=0 then exit do 
    if c=13 and asc(s,b+1)=10 then exit do
    b+=1 
  end do 
  if b>bb
    function=mid(s,bb,b-bb) 
    b+=2
  end if
end function     

string src=
"1 one
2 two
3 three"

sys i = 1
string lin

    do
       lin =  getline(src,i)
       if not lin then exit do
       print lin
    end do

Emil_halim

  • Guest
Re: bcx to Oxygen basic
« Reply #14 on: April 03, 2013, 04:48:13 AM »

Hi Charles ,

when getline function find a blank line the loop end ignoring the rest of string , so i changed it like this
Code: [Select]
function getline(s as string, b as sys) as string 
=================================================
  sys c,bb
  bb=b
  do 
    c=asc(s,b) 
    if c=0 then exit do 
    if c=13 then b+=1 : exit do
    b+=1 
  end do 
  if asc(s,b)=10 then b+=1
  return mid(s,bb,b-bb)
end function     
 

so it works well but when using it with my next function the program end in the middel and execution did
not reach to end end of function , any help please?
Code: [Select]
void processAllLayer(string file)
{
   sys i = 1
   string src , lin
   for i = 1 to  LayerNo
     print "processing... " file chr(10) "by" chr(10) LayName[i]
     src = getfile(file)
     
     do
       lin =  getline(src,i)
       if not lin then exit do
       print lin
     end do
          '<------------------------------- program end here????????
     if ActiveLayer[i] then
           addr eax , src
           push eax
           call procProcess[i]
           push  eax   : push  eax
           putfile  file, cast bstring eax
           call freememory
     end if
   next
}