Author Topic: Chameleon BASIC  (Read 13929 times)

0 Members and 3 Guests are viewing this topic.

JRS

  • Guest
Chameleon BASIC
« on: November 18, 2014, 01:12:17 AM »
Quote
This project was adopted from KoolB 16.  An abandoned project on yahoo.  It's kind of funny because this project was almost ahead of rapid Q.

Chameleon BASIC will be the new and better Visual Basic. With such features as compatibility with GWBasic thru VB6. Possibly overriding VB.NET as I've build VB6 applications compatible with VB.NET in VB6. VB.NET Requires a runtime, this will not be a problem in Chameleon as it will run native to Windows. I'm also thinking of ports to Java and .NET.

This is a BASIC to ASM compiler for Windows. Charles & Mike should find this interesting.


.

Mike Lobanovsky

  • Guest
Re: Chameleon BASIC
« Reply #1 on: November 18, 2014, 05:33:33 AM »
Nice find, John, thanks!

It's got a long way to go out of its craddle as a Windows BASIC yet but it's indeed a kool start -- it works! :D

JRS

  • Guest
Re: Chameleon BASIC
« Reply #2 on: November 18, 2014, 08:46:25 AM »
Love those tiny executables. Looks like a fun project and a good way to learn ASM.


Mike Lobanovsky

  • Guest
Re: Chameleon BASIC
« Reply #3 on: November 18, 2014, 01:00:29 PM »
The smallest unoptimized and unpacked exes start at some 40KB -- that's not so small at all. Nasm optimization can bring the size down almost twice but not always. Further minification is possible only with the aid of UPX -- the most usable exe packer around that usually doesn't trigger off the pack of AV bloodhounds at VirusTotal dot com.

JRS

  • Guest
Re: Chameleon BASIC
« Reply #4 on: November 18, 2014, 01:40:21 PM »
I tried to call the koolb.dll with SB DYC which worked until I closed the dialog. (exception error) The default DYC example which in essence is doing the same thing works fine. Something strange happening on the return. I even tried calling the EXIT function before exiting SB with no luck.

This works.
Code: Script BASIC
  1. include dyc.bas
  2.  
  3. a$ = "message text" & chr$(0)
  4. print dyc::dyc("ms,i,USER32.DLL,MessageBox,PZZL",0,a$,"title",3)
  5.  

This doesn't return without an exception error. I wonder if it's expecting a bstr?
Code: Script BASIC
  1. include dyc.bas
  2.  
  3. a$ = "Hello Chameleon BASIC from Script BASIC" & chr$(0)
  4. print dyc::dyc("ms,i,koolb.dll,MESSAGE,Z",a$)
  5.  

Code: Text
  1. ' KoolB DLL (requires new KoolB compiler)
  2. $AppType DLL
  3.  
  4. ' RapidQ calls the KoolB DLL, which in turn calls the WinAPI MessageBox function
  5. Declare Function MessageBox Lib "User32.dll" Alias "MessageBoxA" (I As Integer, S As String, S2 As String, I2 As Integer) As Integer
  6.  
  7. ' Preserve names as much as possible (ie, don't mangle)
  8. $Mangle OFF
  9.  
  10. ' Our sample function
  11. Function Message (S As String) As Integer
  12.   Result = MessageBox(0, S, "KoolB DLL showing you a little message:", 0)
  13. End Function
  14.  
  15. $Mangle ON
  16.  



Mike Lobanovsky

  • Guest
Re: Chameleon BASIC
« Reply #5 on: November 18, 2014, 02:22:08 PM »
Nope, it expects an ASCIIZ string or it wouldn't show the message. I confirm the DLL is broken. It also has a non-standard layout of sections in its binary image.

P.S. The type of first parameter in your call to MessageBox isn't correct. It is of C type HANDLE that evaluates to BASIC's Long rather than pointer as in your PZZL. It should be LZZL.

JRS

  • Guest
Re: Chameleon BASIC
« Reply #6 on: November 18, 2014, 02:37:15 PM »
Thanks again Mike for the help and determining if this BASIC is worth the effort.


JRS

  • Guest
Re: Chameleon BASIC
« Reply #7 on: November 18, 2014, 07:15:09 PM »
I seem to be having better luck creating .exe programs using the examples provided.

FYI The .asm files are line terminating with &H0d0d0a instead of &H0d0a.

Code: Visual Basic
  1. '*******************
  2. '* ColorBlocks.bas *
  3. '*******************
  4.  
  5. $AppType GUI
  6. $Optimize Off
  7. $Compress Off
  8.  
  9. $Include "Windows.inc"
  10.  
  11. $Resource IDI_COLORBLOCKS As "ColorBlocks.ico"
  12.  
  13. $Const xSteps = 5
  14. $Const ySteps = 4
  15.  
  16. Dim message As MSG
  17. Dim rct As RECT
  18. Dim wcex As WNDCLASSEX
  19. Dim ps As PAINTSTRUCT
  20. Dim hInst As Integer
  21. Dim hWindow As Integer
  22. Dim xSize As Integer
  23. Dim ySize As Integer
  24. Dim strClassName As String
  25. Dim strAppTitle As String
  26.  
  27. Function OnSize(hWnd As Integer, uMsg As Integer, _
  28.                 wParam As Integer, lParam As Integer) As Integer
  29.   xSize = LoWord(lParam) / xSteps
  30.   ySize = HiWord(lParam) / ySteps
  31.   Result = 0
  32. End Function
  33.  
  34. Function OnPaint(hWnd As Integer, uMsg As Integer, _
  35.                 wParam As Integer, lParam As Integer) As Integer
  36.   Dim hdc As Integer
  37.   Dim PalIndex As Integer
  38.   Dim i As Integer
  39.   Dim j As Integer
  40.   Dim hPen As Integer
  41.   Dim hPenPrevious As Integer
  42.   Dim hBrush As Integer
  43.   Dim hBrushPrevious As Integer
  44.  
  45.   hdc = BeginPaint(hWnd, ps)
  46.   j = 0
  47.   while j < ySteps  
  48.     i = 0
  49.     while i < xSteps
  50.       PalIndex = j * xSteps + 0x01000000 + i
  51.       hPen = CreatePen(PS_SOLID, 1, PalIndex)
  52.       hPenPrevious = SelectObject(hdc, hPen)
  53.       hBrush = CreateSolidBrush(PalIndex)
  54.       hBrushPrevious = SelectObject(hdc, hBrush)
  55.       rct.left = i * xSize
  56.       rct.top = j * ySize
  57.       rct.right = (i + 1) * xSize - 1
  58.       rct.bottom = (j + 1) * ySize - 1
  59.       Rectangle(hdc, rct.left, rct.top, rct.right,rct.bottom)
  60.       DeleteObject(hPenPrevious)
  61.       DeleteObject(hBrushPrevious)
  62.       i = i + 1
  63.     Wend
  64.   j = j + 1
  65.   Wend
  66.   EndPaint(hWnd, ps)
  67.   Result = 0
  68. End Function
  69.  
  70. Function OnClose(hWnd As Integer, uMsg As Integer, _
  71.                  wParam As Integer, lParam As Integer) As Integer
  72.   If MessageBox(hWnd, "Exit application?", _
  73.                  strAppTitle, MB_YESNO + MB_ICONQUESTION) = IDYES Then
  74.     DestroyWindow(hWnd)
  75.     Result = 0
  76.   Else  
  77.     Result = 1
  78.   End If
  79. End Function
  80.    
  81. Function WindowProc(hWnd As Integer, uMsg As Integer, _
  82.                     wParam As Integer, lParam As Integer) As Integer
  83.   If uMsg = WM_SIZE Then
  84.     Result = OnSize(hWnd, uMsg, wParam, lParam)
  85.   ElseIf uMsg = WM_PAINT Then
  86.     Result = OnPaint(hWnd, uMsg, wParam, lParam)
  87.   ElseIf uMsg = WM_CLOSE Then
  88.     Result = OnClose(hWnd, uMsg, wParam, lParam)
  89.   ElseIf uMsg = WM_DESTROY Then
  90.     PostQuitMessage(0)
  91.     Result = 0
  92.   Else
  93.     Result = DefWindowProc(hWnd, uMsg, wParam, lParam)
  94.   End If
  95. End Function
  96.  
  97. '***
  98.  
  99. strAppTitle = "Color Blocks"
  100. strClassName = "KoolBClass"
  101.  
  102. hInst = GetModuleHandle(0)
  103. wcex.cbSize = SizeOf(WNDCLASSEX)
  104. wcex.style = CS_VREDRAW + CS_HREDRAW + CS_CLASSDC
  105. wcex.lpfnwndproc = CodePtr(WindowProc)
  106. wcex.cbClsExtra = 0
  107. wcex.cbWndExtra = 0
  108. wcex.hInstance = hInst
  109. wcex.hIcon = LoadIcon(hInst, MakeIntResource(IDI_COLORBLOCKS))
  110. wcex.hCursor = LoadCursor(0, MakeIntResource(IDC_ARROW))
  111. wcex.hbrBackground = GetStockObject(WHITE_BRUSH)
  112. wcex.lpszMenuName = ""
  113. wcex.lpszClassName = strClassName
  114. wcex.hIconSm = 0
  115.  
  116. If (RegisterClassEx(wcex)) = 0 Then
  117.   MessageBox(0, "RegisterClassEx failed.", strAppTitle, MB_OK)
  118.   ExitProcess(0)
  119. End If
  120.  
  121. hWindow = CreateWindowEx(WS_EX_APPWINDOW + WS_EX_WINDOWEDGE, _
  122.                          strClassName, strAppTitle, _
  123.                          WS_OVERLAPPEDWINDOW + WS_VISIBLE, _
  124.                          CW_USEDEFAULT, CW_USEDEFAULT, _
  125.                          583, 488, _
  126.                          0, 0, wcex.hInstance, 0)
  127. If hWindow = 0 Then
  128.   MessageBox(0, "CreateWindowEx failed.", strAppTitle, MB_OK)
  129.   ExitProcess(0)
  130. End If
  131.  
  132. While GetMessage(message, 0, 0, 0) > 0
  133.   TranslateMessage(message)
  134.   DispatchMessage(message)
  135. Wend
  136.  


C:\Chameleon\Examples\ColorBlocks>compile ColorBlocks.bas

C:\Chameleon\Examples\ColorBlocks>C:\Chameleon\Bin\Chameleon.exe "ColorBlocks.bas" C:\Chameleon\Inc\ Pause

          Welcome to Chameleon BASIC
Currently compiling "ColorBlocks.bas":
 - Compile time  ->  0.065000 seconds
 - Assemble time ->  0.272000 seconds
 - Linking time  ->  0.181000 seconds
   -------------------------------
 - Total time    ->  0.518000 seconds
Press any key to continue . . .
C:\Chameleon\Examples\ColorBlocks>ColorBlocks

C:\Chameleon\Examples\ColorBlocks>dir *.exe
 Volume in drive C has no label.
 Volume Serial Number is 1415-F200

 Directory of C:\Chameleon\Examples\ColorBlocks

11/18/2014  07:10 PM            26,624 ColorBlocks.exe
               1 File(s)         26,624 bytes
               0 Dir(s)  68,366,262,272 bytes free

C:\Chameleon\Examples\ColorBlocks>


The ASM source for ColoBlocks is attached in a zip.

.
« Last Edit: November 18, 2014, 08:17:54 PM by John »

JRS

  • Guest
Re: Chameleon BASIC
« Reply #8 on: November 18, 2014, 09:23:16 PM »
Good News!

I recompiled the koolb.dll instead of using the pre-compiled version that came with the distribution and it worked with SB DYC.



.

JRS

  • Guest
Re: Chameleon BASIC
« Reply #9 on: November 18, 2014, 09:55:07 PM »
I recompiled the Chameleon BASIC compiler with Visual Studio 2008. It removed the IIS support as it had been deprecated. I assume the the existing compiler was compiled with Visual Studio 6.


C:\sb22\koolb>C:\Chameleon\Bin\Chameleon.exe "koolb.bas" C:\Chameleon\Inc\

          Welcome to Chameleon BASIC
Currently compiling "koolb.bas":
 - Compile time  ->  0.030000 seconds
 - Assemble time ->  0.110000 seconds
 - Linking time  ->  0.080000 seconds
   -------------------------------
 - Total time    ->  0.220000 seconds
C:\sb22\koolb>scriba kbhello.sb
1
C:\sb22\koolb>


Maybe it's just me but the compiler seems a little faster with the recompile.

@Mike - Can you whip up a benchmark that would run in Chameleon BASIC, O2 and C?

.
« Last Edit: November 18, 2014, 10:15:02 PM by John »

JRS

  • Guest
Re: Chameleon BASIC
« Reply #10 on: November 19, 2014, 05:09:22 PM »
Sure would be nice if a keyword list exist for Chameleon BASIC. The project hasn't been updated since last year this time.

I personally don't have any interest in this other than learning how a compiler/assembler/linker works. I'm not hearing much from Mike or anything from Charles so any further interest in this is at your own risk. Seems it would be a good project for the PowerBASIC folks to work on and improve.


JRS

  • Guest
Re: Chameleon BASIC
« Reply #11 on: November 19, 2014, 11:12:07 PM »
Quote from: Mike
The smallest unoptimized and unpacked exes start at some 40KB

The colorblock example compiles to 26,624 bytes uncompressed. That's not bad for a Windows program with no runtime dependencies. (6,656 bytes compressed/optimize option On)

Code: [Select]
$Compress Off

Attached is the KoolB original project. At least it has docs.  :D

.
« Last Edit: November 19, 2014, 11:50:33 PM by John »

JRS

  • Guest
Re: Chameleon BASIC
« Reply #12 on: November 20, 2014, 09:10:03 AM »
If I could get a conformation from Mike or Charles (or any other O2 forum member) that Chameleon BASIC is of any value, I would put resources behind it to help it along. I'm not a ASM programmer but always wanted to learn.


Mike Lobanovsky

  • Guest
Re: Chameleon BASIC
« Reply #13 on: November 20, 2014, 10:55:46 AM »
John,

I have absolutely no time to have a closer look at this BASIC now. But since it targets Nasm that's a good assembler and it also works, it certainly has value at least as a learning material. Assembler is good to know for a language developer. In fact, I think one can't be a serious language developer without at least basic assembly knowledge. Look at Charles. :)

(Sorry, can't stay here any longer tonight. But I'll be keeping an eye on your progress. :) )

JRS

  • Guest
Re: Chameleon BASIC
« Reply #14 on: November 20, 2014, 11:18:13 AM »
Thanks Mike!

That gives me enough to maybe throw some resources at it. I still have the old www.basic-compiler.com site (old BCX effort) for a forum and could create a Bitbucket repository to track any new development. Let me know when you have more time to look at this.

I'm thinking of calling this fork of the project BASM. There doesn't seems to be any reference to BASIC and ASM using this name.

@Charles - It would be great if you would provide your feedback and if it is a worth while project. What keeps my interest is this started as a tutorial and seems to have a fragmented following.
« Last Edit: November 20, 2014, 01:39:01 PM by John »