Many people have wondered how to link other languages into Quickbasic. Some think it is not possible but to my knowledge C, Fortran, and of course ASM of been succesfully intergrated with QB code. To do this you need to compile this code into a library.
To demonstrate how we are going to make a mini library that does two things:
1. Sets the Screen Mode to Mode 0013h (Screen 13)
2. Sets the Screen Mode back to 003h (Screen 0)
Here is the ASM source code to this library:
.MODEL LARGE, BASIC .386 .DATA .CODE PUBLIC InitVGA InitVGA PROC MOV AX, 0013h ; Put 0013h into AX INT 10h ; Call Interrupt 10 InitVGA ENDP PUBLIC InitText InitText PROC MOV AX, 0003h ; Put 0003h into AX INT 10h ; Call Interrupt 10 InitText ENDP END
I am not going in depth on how exactly the above code works but I may in my next article. So assuming you cut that code out and compiled it using MASM or TASM into .obj code we can go on.
Now that we have our object code we need to convert it into a library. So we run our handy Lib utility that comes with Quickbasic 4.5 .
C:\qb45>lib Microsoft (R) Library Manager Version 3.14 Copyright (C) Microsoft Corp 1983-1988. All rights reserved. Library name:Mylib Library does not exist. Create? (y/n) y Operations:Lib.obj List file:nul
And then we need to link it into a QuickLibrary so we can use it from QB's IDE.
C:\qb45>link /q /st:300 Mylib.lib Microsoft (R) Overlay Linker Versio Copyright (C) Microsoft Corp 1983-19 Run File [MYLIB.QLB]: List File [NUL.MAP]: Libraries [.LIB]: bqlb45.lib qb.lib
And there we have it. A working Quickbasic library. But we have one final set to do before we can use the library.
Open up QB with your library loaded (QB /L Mylib) and type these lines in:
Declare Sub InitVGA () Declare Sub InitText ()
Save the file as Mylib.bi and create a new file. In this file type:
'$Dynamic '$include: 'mylib.bi'
and voila! You can now use the functions in your library. Note that you do not have to put your declarations in the bi file if your library is small like this one but I recommend doing it this way to keep your code easily readable.