Example Intro and HalPromIde24

Started by Frank Brübach, April 24, 2024, 09:33:10 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Frank Brübach

Byte Array example

' -- byte array example
'
pim strsrc as pstring
strsrc = "Hello, Animal World!"

Dim byteArray() as byte at strptr(strsrc)

  pim i,j as pro
  pim s,t as pstring
  j=1
  s=space 600
  for i=1 to 20
    t=chr(9)+str(byteArray[i]) ":  " + chr(byteArray[i])
    mid (s,j)=t
    j+=len t
  next

  p? left s,j
[/]

Frank Brübach

Array examples how to reduce a String Text

' array reducing for a string
'
pindex 0

Dim txt() as zstring = "Hello World " + Chr(0)
dim i as integer
 
For i = 0 to Len(txt)-2 ''Len(txt)-1 if pindex is not active
   
    p? txt(i) + Chr(txt(i))
Next

' output: hello world ello world llo world lo world o world
' output: world orld rld ld d 

Frank Brübach

#47
Window winapi GUI (SDK)

  ' -- windows gui test, halProment, 19-05-2024 --
  '
  take diverprom
 
  '--------------------------------------------------------------------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as pro
  '====================================================================

  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax
  with wc
  .style = CS_HREDRAW or CS_VREDRAW
  .lpfnWndProc = @WndProc
  .cbClsExtra =0
  .cbWndExtra =0   
  .hInstance =inst
  .hIcon=LoadIcon 0, IDI_APPLICATION
  .hCursor=LoadCursor 0,IDC_ARROW
  .hbrBackground = GetStockObject WHITE_BRUSH
  .lpszMenuName = null
  .lpszClassName = strptr "Demo"
  end with
  sys r=RegisterClass (@wc)
 
  Wwd = 520 : Wht = 400
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
  '
  hwnd = CreateWindowEx 0,wc.lpszClassName,"HalProment Basic",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  if not hwnd
    mbox "Unable to create window"
    exit function
  end if
  '
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd
  '
  sys bRet
  '
  do while bRet := GetMessage (@wm, 0, 0, 0)
    if bRet = -1 then
      'show an error message
    else
      TranslateMessage @wm
      DispatchMessage @wm
    end if
  wend
  end Function

  dim as rect crect

  '------------------------------------------------------------------
  function WndProc (pro hWnd, wMsg, wParam, lparam ) as pro callback
  '==================================================================

    static as pro hdc
    static as pstring txt
    static as PaintStruct Paintst
 
    '==========
    select wMsg
    '==========
       
      '--------------
      case WM_CREATE
      '=============
      GetClientRect hWnd,cRect

      '-------------- 
      case WM_DESTROY
      '===============
         
      PostQuitMessage 0
       
      '------------
      case WM_PAINT
      '============

      GetClientRect  hWnd, cRect
      hDC=BeginPaint hWnd, Paintst
      SetBkColor  hdc,black 'yellow
      SetTextColor hdc,green 'red
      DrawText hDC,"Hello Animal World!",-1,cRect,%DT_SINGLELINE or %DT_CENTER or %DT_VCENTER
      EndPaint hWnd,Paintst
      function = 1
 
      '-------------- 
      case WM_KEYDOWN
      '==============

      '============           
      Select wParam
      '============

    Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

      End Select

      '--------       
      case else
      '========
         
        function=DefWindowProc hWnd,wMsg,wParam,lParam
       
    end select

  end function

'  WinMain inst,0,cmdline,SW_NORMAL  '' both lines are working
  WinMain 1,0,1,SW_NORMAL

Frank Brübach

#48
Finally the big step to 64 Bit architecture
Thanks Charles for His great rtl32.inc and rtl64.inc Files :-)

All examples you can find in *.rar folder below
If you have any questions please ask thx, frank

'' -- halProment Basic 64 bit test, 26-5-24, 29-05-24, by frank bruebch
'' -- you must compile this example with menu compile/quickrun produces an exe file
''

$ FileName "test64-2.exe"
#include "$\inc\pro64.inc" ''

Declare Function MessageBox Lib "user32.dll" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Sys

byte val1
byte val2
int result 
   
    val1=4
    val2=6 '

    'mov eax,val1 
    mov eax,val2  ''multiply (or add) eax by ebx  "
    'mul val1 'ebx
    add eax,5  '' here add 5
    mov result,eax

zstring tit[]="HalProment Basic 64 bit"
zstring msg[]="Hello dear Animal World! " + str(result)

'' halProment Basic 64 bit
''

sub  rsp,40h
mov  r9,  0     
lea  r8,  tit 
lea  rdx, msg 
mov  rcx, 0
call messagebox     
add  rsp, 40h
''
''
'' output: Hello dear Animal World! 11 (add) ' 24 (multiply)
''

#ifdef mode64bit
#print "Producing 64-bit code output"
print "Producing 64-bit code output"
#else
#print "Producing 32-bit code output"
#endif

'' result: "Producing 64-bit code output" ' all ok :-)


PS you can Download the latest Update under GitHub too

Frank Brübach

Here is a little sizeof example

Print SizeOf(Byte) ' returns 1

Type mybar
    a As Integer '4
    b as float '4
    c as long '4
    d As Double '8
    e as ulong '4
    f as short '2
    g as byte '1
End Type

dim myfoo as mybar
print SizeOf(myfoo) ' returns 32
 

Chris Chancellor

#50
I would luv the compiler to be a 64bit one.

It looks similar to O2,   can I port O2 codes into Frank Basic ?
Thanxx a lot


Frank Brübach

#51
Hello Chris thx for Feedback..
yes nearly 90 / 92 percent at the Moment are compatible with o2 Code.

Whats the meaning of "luv"?  Lift and Transport?

Regards Frank 

Karen Zibowski

Hi Frank

What are the challenges to convert from PB to FrankBasic ?  Do you have a guide to convert from Powerbasic
to FrankBasic ?

Does FrankBasic has an IDE ?

Thank you
Regards
Karen

Frank Brübach

#53
Hello Karen :)

Its Not such a big step a Lot of commands and Syntax are equal to Powerbasic and freebasic.

The Name of my Compiler is "halProment Basic" , the Ide calls halPromide24.

You can Download the *.rar File some Posts before (post #48) there are a Lot of examples for Testing .. you can create Exe File too with Last update4 and there is a 64bit DLL too..

You will find a similar Powerbasic example too in my example folder ;)

All Work in Progress. If you have more questions please ask Here. Its all in Beta Version, but advanced..

Thanks, Frank
PS you can Download via GitHub Last Update 4 too

Frank Brübach

@karen

PS a guide doesn't exist yet at this Moment .. its a Hobby Project and If there's more time I will build such a Help File..


Frank Brübach

Hello all.. much more to come with a new Update with my Last Post later

How to create an EXE File?

' --> atestcalc 2 example
' --> create an Exe file with halProment
' --> menu/compile/Run compiling 32 bit
'
#fily "atestcal.exe"

dim s,st as string
dim a,b,c,d,e as long
a=10
b=20
c=30
d=a*b
e=d*c

s= "hello batman " + str(d)
st= "hello superman " + str(e)

print s ' result 200
print st ' result 6000

'-------------------------- //
'
pstring s1,st1
pro a,b,c,d,e ' pim as a,b,c,d,e as long
a=10
b=20
c=30
d=a*b
e=d*c

s1 = "hello batman1 " + str(d)
st1= "hello superman1 " + str(e)

print s1 ' result 200
print st1 ' result 6000

Frank Brübach

CByte example for riunding Numbers and Auto converting Strings

' -> cbyte example, rounded numbers or converting strings
' halProment
'
'dim cb as cbyte

cbyte cb
cb=45.2 ' 45
print cb

cb=72.6
print cb ' 73

cb="-72"
print cb ' -72

cb="-122.5"
print cb ' -123

cb=255
print cb '-1

cb=260
print cb '4


Frank Brübach

A Byte Array examples

' -- byte array example
'
pim strsrc as pstring
strsrc = "Hello, Animal World!"

Dim byteArray() as byte at strptr(strsrc)

  pim i,j as pro
  pim s,t as pstring
  j=1
  s=space 600
  for i=1 to 20
    t=chr(9)+str(byteArray[i]) ":  " + chr(byteArray[i])
    mid (s,j)=t
    j+=len t
  next

  p? left s,j


Frank Brübach

#58
Powerbasic Looks a Like example with inc File

A new Update you can find below with all examples for Testing

If you have question about halProment or the halPromide24 (IDE) please ask :)

Regards, Frank

' poba looks like calculation, halProment, 2-6-24
'
''#COMPILE EXE
#DIMALL

include once "poba.inc"

FUNCTION PBMAIN() AS LONG
    LOCAL a,b,c AS LONG
    a=20
    b=40
    c=a*b
    MSGBOX "calculation test: "+str(c)  ' result 800
END FUNCTION

Include File
'
'poba.inc
'
'-------------- //
def msgbox mbox

pro a
if not a then
call pbmain()
end if

Frank Brübach

Array Reducing a Text for a String

' array reducing text for a string
'
pindex 0

Dim txt() as zstring = "Hello World " + Chr(0)
dim i as integer
 
For i = 0 to Len(txt)-2 ''Len(txt)-1 if pindex is not active
   
    p? txt(i) + Chr(txt(i))
Next

' output: hello world ello world llo world lo world o world
' output: world orld rld ld d