|
Post by Emil_halim on Apr 13, 2018 11:17:54 GMT 1
Hi All
many years ago , i was making an Extension for GFA BASIC. so now i restart working.
1- because GFA Basic is lacking of preprocess , such as C/C++ , ASM ,...
I toke the cpp of lcc compiler and preprocess of FASM then start modifying them and extend GFA Editor to apply the preprocess on GFA BASIC program.
2- Also in previous preprocess i made i system that allow including obj file in our GFA BASIC , the idea is that decompiling the obj file to asm code then inserting them into GFA BASIC , they recompiled with GFA it self. but i stuck with some problems
3- i toke SmallerC c compiler , no floating point, changed it so that , i can insert some c code with my GFA basic code , then extension will extract the c code and compile it to asm code which inserted into GFA BASIC code.
Example Prefix-EndPrefix preprocess
// // Prefix Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
Dim var%
var% = 10
GoSub powervar
Print var%
Sleep 1000
End
powervar: #prefix ". " mov eax, var% imul eax, eax mov var%, eax ret #endprefix
|
|
|
Post by Emil_halim on Apr 13, 2018 11:45:49 GMT 1
Here is an other prefix demo , i used it when declare the type
// // Prefix Demo2 // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
Type BoolTrouble #prefix "- Bool " a0 a1 a2 a3 a4 a5 a6 a7 ' <- 8th bool in a row #endprefix EndType
Dim bl As BoolTrouble
Message bl.a0 bl.a0 = True Message bl.a0 bl.a7 = False ' and V:bl.a0, 8
|
|
|
Post by Emil_halim on Apr 13, 2018 12:12:34 GMT 1
Here is an other define demo like c/c++
// // Define Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
#define ONE 1 #define TWO #define GFAExt "GFA Extension is very good" #define Pwr2(x) x*x #define len(x,y) Sqrt(x*x+y*y)
Dim x = ONE
# ifdef TWO x = 10 # EndIf
Print ONE Print TWO Print Pwr2(10) + x + Pwr2(20) print len(3,4)
MsgBox GFAExt
Do Sleep Until Me Is Nothing
|
|
|
Post by scalion on Apr 13, 2018 15:05:18 GMT 1
hi, It's a good idea. But is that working when run in interpretor mode ?
|
|
|
Post by Emil_halim on Apr 13, 2018 16:14:23 GMT 1
Hi
yes , the idea here is i have made this code in editor extension
Sub gfa_F8 ' GFA Ext Compile Local YES , temp$ = App.Path & "\tempNam.G32" YES = MsgBox( "Start , GFA BASIC EXT ", MB_ICONQUESTION | MB_YESNO ) If YES Gfa_Save Gfa_SaveFile temp$ System "F:\gb32\Bin\GFA_Ext.exe" & " " & temp$ , Wait // Kill Yes , Silent, temp$ EndIf End Sub so you can insert the GFA Extended code into the editor then press F8 which force the editor to show a MessageBox that ask you to continue , then call GFA_Ext console program that processes the code then it will open a new Editor that hold the final GFA code. you can run that final code as usual for the editor.
|
|
|
Post by Emil_halim on Apr 14, 2018 15:38:43 GMT 1
Hi All
Here is an other include Demo.
actually the #include just like C/C++ is very useful , it allows us to make our GFA Basic a parts, so now with GFA Extension you can divide your entire program into small parts.
in this demo i put all the type in separate inc file windows.inc
// // windows.inc file //
Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type
/* types for WM_PAINT message*/ Type PAINTSTRUCT hdc As Long fErase As Long rcPaint As RECT fRestore As Long fIncUpdate As Long rgbReserved As Byte End Type
Type POINTAPI x As Long y As Long End Type
/* main window types*/ Type WNDCLASS style As Long lpfnWndProc As Long cbClsExtra As Long cbWndExtra2 As Long hInstance As Long hIcon As Long hCursor As Long hbrBackground As Long lpszMenuName As Long lpszClassName As Long End Type
Type MSG hwnd As Long MessageVar As Long ' Original: Message As Long; Message is reserved in GB 32 wParam As Long lParam As Long time As Long pt As POINTAPI End Type
and the main program in an other file
// // windon Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
#include "windows.inc"
Global szAppName As String = App.Name + #0 Global hWndMain As Handle Global ghInstance As Int = App.hInstance
WinMain(ghInstance, _CmdLine$, SW_SHOW)
Procedure WinMain(hInstance As Handle, szCmdLine As String, iCmdShow As Int)
Local msg As MSG Local wndclass As WNDCLASS
/* Register the window class*/ #prefix "wndclass." style = CS_HREDRAW | CS_VREDRAW lpfnWndProc = ProcAddr(WndProc) cbClsExtra = 0 cbWndExtra2 = 0 hInstance = hInstance hIcon = 0 hCursor = LoadResCursor(Null, IDC_ARROW) hbrBackground = GetStockObject(BLACK_BRUSH) 'COLOR_APPWORKSPACE + 1 lpszMenuName = Null lpszClassName = V:szAppName #endprefix
If !RegisterClass(wndclass) Then Message("error ") hWndMain = CreateWindowEx(WS_EX_TOPMOST, V:szAppName, "DirectX Example Window", _ WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), _ Null, Null, hInstance, Null)
~ShowWindow(hWndMain, iCmdShow) ~UpdateWindow(hWndMain) While (GetMessage(msg, Null, 0, 0)) ~TranslateMessage(msg) ~DispatchMessage(msg) Wend ~DestroyWindow(hWndMain) ~UnregisterClass(szAppName, hInstance) EndProc
Procedure WndProc(hWnd As Handle, uMsg As Int, wParam As Int, lParam As Int) Naked Local RetVal As Int = 0 Select uMsg Case WM_CLOSE, WM_DESTROY ~PostQuitMessage(0) Asm mov eax, [RetVal] Default RetVal = DefWindowProc(hWnd, uMsg, wParam, lParam) Asm mov eax, [RetVal] EndSelect EndProc
see you in new demo Enjoy GFA Extension
|
|
|
Post by scalion on Apr 17, 2018 7:35:29 GMT 1
Hi It's a very good work you do. It gives me a lot of ideas, I will put online in the library or demos section later.
|
|
|
Post by Emil_halim on Apr 17, 2018 17:22:21 GMT 1
Hi
you are very welcome.
BTW , already implemented system just like Pascal units , but not test yet.
you can puts your repeated code in file stored in lib folder in GFA Bin , the you can type #uses lib1,lib2..... with out file extension so system will include lib2.lib then include lib1.lib.... etc.
|
|
|
Post by Emil_halim on Apr 17, 2018 19:28:36 GMT 1
Hi all
Here is an other demo , incBin , which let you include a binary file into your code .
automatically it put a label at the first of included data , the label name is like the name of binary file without extension.
also , i allow entrypoint in GFA like masm , it is a label with 'Start" name.
// // incbin Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
#include "windows.inc"
Dim bfh As Pointer To BITMAPFILEHEADER Dim bih As Pointer To BITMAPINFOHEADER Dim rgba As Pointer To RGBQUAD Dim bi As BITMAPINFO
Start: // Enrtypoint here
OpenW 1
Pointer bfh = LabelAddr(hgm) Pointer(bih) = LabelAddr(hgm) + SizeOf(BITMAPFILEHEADER) Pointer(rgba) = LabelAddr(hgm) + SizeOf(BITMAPFILEHEADER) + SizeOf(BITMAPINFOHEADER)
If bfh.bfType != 0x4d42 Then Print "not bmp file" : End If bih.biCompression != BI_RGB Then End 'If bih.biBitCount != 24 Then End
Print "image width = " & bih.biWidth Print "image height = " & bih.biHeight
Do Sleep Until Me Is Nothing End
// here we insert hgm.bmp bin file #incbin "hgm.bmp"
you can extend this demo and load the image from memory 'your incbin label' and put it on your window.
see you later with new demo
|
|
|
Post by Emil_halim on Apr 20, 2018 13:41:11 GMT 1
Hi All
Here is an other macro demo.
the macro system is like any asm macro , still in first step.
this demo show you , how to patch your GFA basic code , consider the following Example , it will prints 3 and this is normal
Dim x As Int Start: OpenW # 1 x = 2 Inc x Print x //prints 3 Do Sleep Until Me Is Nothing End
so after patching it , it prints 5
// // macro Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
MACRO Inc !X Asm add [!X],3 ENDM
Dim x As Int Start: OpenW # 1 x = 2 Inc x Print x //prints 5 Do Sleep Until Me Is Nothing End
of course macro system is usually useful in creating code not to patch code
also note well , the Start label here is always needed to tell GFA Extension of the enterypoint.
see you later with an other demo.
|
|
|
Post by Emil_halim on Apr 20, 2018 14:50:29 GMT 1
Hi All
this time i used macro system with debug .
// // Debug macro Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
'patching Inc keyword MACRO Inc !X Asm add [!X],3 Debug.Print !X ENDM
Dim x As Int Start: Debug.Show x = 2 Inc x Do Sleep Until Me Is Nothing End
see you later with an other demo.
|
|
|
Post by Emil_halim on Apr 20, 2018 15:45:42 GMT 1
Hi All
this time i will show you , How to Extend your existing GFA keyword to make additional job.
in old days , i was using AmosPro in amige computer , the was add basic keyword that allow adding some value to a certain variable and keep the final values within max & min range.
here i will apply this to the Inc keyword of GFA Basic , so it increase the variable by one and check the results against Max and Min Values.
// // Extend macro Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
'Extend Inc keyword MACRO Inc !X,!MAX,!MIN Inc !X If !X < !MIN Then !X = !MIN If !X > !MAX Then !X = !MAX ENDM
Dim x As Int Start: OpenW # 1 x = 2 ' Increase x and keep it within range max 30 to min 10 Inc x,30,10
Print x Do Sleep Until Me Is Nothing End
see you in next demo.
|
|
|
Post by Emil_halim on Apr 22, 2018 19:47:00 GMT 1
Hi All
Now , the Macro System allows you to set a default value of macro parameters. Also it allows you to use '%if - %endif' inside the macro body , nested '%if-%endif' allowed.
Here is a demo that showing you the new features.
// // Extend macro Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
'Extend Inc keyword MACRO Inc !x,!MAX=100,!MIN=0 Inc !x If !x < !MIN Then !x = !MIN %if !MIN eq 10 Print !MIN ; " is 10" %if !x neq 40 Print !x ; " is not 40" %endif %endif If !x > !MAX Then !x = !MAX ENDM
Dim x As Int Start: OpenW # 1 x = 2 Inc x,30,10 Print x // print 10 Inc x,150,40 Print x // print 40 Inc x Print x // print 41 Do Sleep Until Me Is Nothing End
see you with an other demo.
|
|
|
Post by Emil_halim on Apr 25, 2018 8:03:51 GMT 1
Hi All
This time i will show you that, inserting c code with our GFA Basic code and how to call it.
The problem i have is , when writing a c function like this
int power(int c) The GFA Editor convert it automatically to
int power(Int(c)) which is wrong c function body start. so is there a way to stop Editor changing inserted code?
Ok , here is our demo , as you see ,your c code must be inside tow term '!!' , so that the GFA_Ext can determine where is the c code. Note well , after term !! , you can put a comments . also i put c function body start in two separate line for stoping automatic Editor changing
// // Smallc Demo // // GFA Extension By Emil Halim // // press F8 then yes in MsgBox //
Start:
Dim var As Int var = 10
var = C:(LabelAddr(powervar))(var)
Print var
Sleep 3000 End
!! start c code
int powervar(int x) { return x * x; }
!! end c code
|
|
|
Post by Emil_halim on Apr 27, 2018 11:34:02 GMT 1
Hi All
This time i test my uses (like-Pascal-units) system ,which is.
There is a lib folder in my Extension , that will hold and collect useful pieces GFA code which we always reusing it. then you can easily include it in your code.
Here in this Demo l toke the GB32DSPlay.g32 by John Findlay and divided it into two parts , one is DirectSound.lib which has all the DirectSound Interface stuff, and the other part is demo itself in GB32DSPlay.g32
'################################################################################# '# # '# "This code is Freeware for Non-Commercial use, if you use it commercially # '# contact the author." (John Findlay) # '# # '# GB32DSPlay.g32 # '# # '# Uses the DirectSound Interface. # '# # '# DirectSound consts, structures, error codes, API's and methods are included. # '# Also the winmm.dll API's are included for WAV file manipulation. # '# # '# John Findlay e-mail -> John.Findlay@Byte-it.net # '# or Jayef@Compuserve.com # '# # '#-------------------------------------------------------------------------------# '# The following Global 128 bit vars are defined in order to allow the other # '# DirectSound Interfaces to be used. # '#-------------------------------------------------------------------------------# '# CLSID_DirectSound CLSID_DirectSoundCapture # '# IID_IDirectSound IID_IKsPropertySet # '# IID_IDirectSoundNotify IID_IDirectSoundCapture # '# IID_IDirectSoundCaptureBuffer IID_IDirectSound3DListener # '# IID_IDirectSound3DBuffer IID_IDirectSoundBuffer # '# # '#################################################################################
Start: InitDSModule() DSXGetModVers()
Global lpDS As Int ' Direct Sound Object Global lpDSBPrimary As Int ' Primary Surface Global nFile As FILEINFO ' Our File Info
LoadForm frmMain Hidden Do Sleep Until Me Is Nothing End
Sub frmMain_Load Local dsRet As Int dsRet = InitDirectSound(frmMain.hWnd) If dsRet = S_OK frmMain.Left = 20 * Screen.TwipsPerPixelX frmMain.Top = 18 * Screen.TwipsPerPixelY cmdPlay.Enabled = False tmr1.Enabled = True frmMain.Show Else DestroyDSObjects() End EndIf EndSub
Sub cmdLoad_Click StopDSBuffer(True) cdOpen.FileName = "" cdOpen.FileTitle = "" cdOpen.DefExt = "WAV" cdOpen.Filter = "Wave Files|*.WAV|All Files|*.*" cdOpen.Title = "Open a Sound File" cdOpen.Flags = cdoHideReadOnly + cdoFileMustExist If GetFileAttributes(WinDir$ + "\Media") != -1 Then ChDir WinDir$ + "\Media" cdOpen.ShowOpen If cdOpen.FileName MemBFill V:nFile, SizeOf(FILEINFO), 0 nFile.FileName = cdOpen.FileName If WaveLoadFile(cdOpen.FileName) != OK Message "Error loading file, make sure it is the correct type.", "Error", MB_ICONEXCLAMATION cmdPlay.Enabled = False lab1.Text = "No File Loaded" Exit Sub EndIf If NewDSBuffer() != DS_OK Message "Can't create a new DirectSound Buffer.", "Error", MB_ICONEXCLAMATION ~mFree(nFile.lpData) : nFile.lpData = Null Exit Sub EndIf lab1.BackColor = RGB(255, 255, 255) lab1.Caption = cdOpen.FileName cmdPlay.Enabled = True EndIf EndSub
Sub cmdPlay_Click If nFile.fPlaying = 0 PlayDSBuffer() cmdPlay.Caption = "Stop" cmdLoad.Enabled = False Else StopDSBuffer(True) cmdPlay.Caption = "Play" cmdLoad.Enabled = True EndIf EndSub
Sub cmdClose_Click StopDSBuffer(True) FreeFileInfo() DestroyDSObjects() frmMain.Close EndSub
Sub tmr1_Timer If !IsSoundPlaying() nFile.fPlaying = 0 If cmdPlay.Caption = "Stop" cmdPlay.Caption = "Play" cmdLoad.Enabled = True EndIf EndIf End Sub
#uses DirectSound
so look at the last line
#uses DirectSound
The Keyword #uses will include DirectSound.lib which located in Ext lib folder.
you can use many included files with uses keyword.
See you with next demo.
|
|
|
Post by Emil_halim on Apr 28, 2018 19:32:45 GMT 1
Thank you very much.
Programming Idea has no end.
|
|