Using QB4.5 Quick Libraries

General FreeBASIC programming questions.
dodicat
Posts: 6720
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Using QB4.5 Quick Libraries

Postby dodicat » Feb 22, 2013 12:34

Just for curiosity, did my second messagebox code (the shell one) run in your qb4.5 with Win 7?
Did it run in FreeBASIC?

If you go to the Quickbasic cafe website there are loads of QB library examples, some made by members and admins of this forum.
Some have 16 bit assembler code included.
Quickbasic cafe page for some qb libraries:

http://www.qbasic.net/en/qbasic-downloa ... aphics.htm
I Daniel
Posts: 43
Joined: May 13, 2010 10:34
Location: Centurion, South Africa

Re: Using QB4.5 Quick Libraries

Postby I Daniel » Feb 23, 2013 8:54

Don
The QBCafe Forum has been temporarily unavailable for the past week.

I downloaded just about everything from that forum, and even if "dated" it sure has some brilliant tips for present day programmers, but if someone wants to use a so-called end of line language it's is his business and not mine but if I can help I will.

So maybe I should say you should try QB64, but unfortunately you will end up with, when you include the dependencies, a +6 Meg or so program, but then again if it works it works.

Do you know where I can download the "MSG.BAS" program to see what is in it. (Looks like I have been searching in the wrong places) It probably contains mouse and graphics routines. The DECLARE statements will already be a pointer to routines in the PRO.QLB
My Cuz Theunis says you can send it to him as an attachment - theunis.jansen@gmail.com. He says if anyone tries to spam him or is nasty then bad luck he will just report it as spam and then gmail.com will block all messages from those senders.
We are not people who steal other peoples programs. When it comes to QB4.5 we just like to help where ever we can. Times are hard for far too many throughout the world, so if you can't sell your program as is then send that E-Mail and if possible we will help.

It is so that the *QLB libraries are specific to the QB Compiler and the format is, I assume, different from that of a DLL (even if QLB was the Microsoft forerunner for their DLL's. You could try to link them when compiling but the chances that it will work is, I would say, Zero.

QLB is the compiled (16bit) version of the routines written in BASIC or whatever...
I Daniel
Posts: 43
Joined: May 13, 2010 10:34
Location: Centurion, South Africa

Re: Using QB4.5 Quick Libraries

Postby I Daniel » Feb 23, 2013 13:18

The Fb help file has the following to say :

"FreeBASIC is written for 32-bit operating systems and a 32 bit DOS extender, and cannot utilize code which depends on 16-bit DOS, 16 bit assembly or memory model (segment & offset, XMS/EMS, ...). "

This means QB quick libraries wont work with FB..
TJF
Posts: 3604
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Using QB4.5 Quick Libraries

Postby TJF » Feb 23, 2013 14:07

I Daniel wrote:This means QB quick libraries wont work with FB..

A 16-Bit library doesn't work out-of-the-box. But you can load it as a binary file and start the functions by assembler code (when the code is executable on modern CPUs).

I haven't seen examples for that yet. Maybe because it's as much work as re-doing the program (and making it cross-platform with a modern GUI toolkit in one shot).
marcov
Posts: 3019
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Using QB4.5 Quick Libraries

Postby marcov » Feb 23, 2013 15:24

TJF wrote:
I Daniel wrote:This means QB quick libraries wont work with FB..

A 16-Bit library doesn't work out-of-the-box. But you can load it as a binary file and start the functions by assembler code (when the code is executable on modern CPUs).


16-bit code loaded and run that way afaik will mostly crash in less than the blink of an eye. The memory model is also different, and soon as the 16-bit code loads DS and accesses something it will come crashing down.

I haven't seen examples for that yet. Maybe because it's as much work as re-doing the program (and making it cross-platform with a modern GUI toolkit in one shot).


For anything non trivial, either go towards virtualization, port at the source level, or keep dedicated 32-bit machines in place.

XP is running out, and I wouldn't advise vista, but There are 32-bit Windows 8 versions available, and those are likely to be supported into the 2020's, as is W7.

Note that porting at the source level of code that was never meant to be portable isn't trivial either. Moreover, the new product would inherit its arcane treats. Therefore, I would recommend one of the other methods (virtualization (dosbox?) or ordaining 32-bit machines) to keep the binary running to buy time while you reengineer from scratch based on software principles from the last 20 years.
Last edited by marcov on Feb 24, 2013 12:25, edited 1 time in total.
DonW
Posts: 40
Joined: Feb 16, 2013 0:56
Location: Longview, WA

Re: Using QB4.5 Quick Libraries

Postby DonW » Feb 24, 2013 5:39

I Daniel,

Today I received an email from Theunis offering to help me with the message box issue, so I sent him examples of how I use the QuickPak Pro "MsgBox.BAS" routine in my application. It in turn calls several assembler subroutines from PRO.LIB. I sure there's ways to emulate the same thing with pure BASIC code, and I think that Theunis wants to rise to the challange. Thanks for hooking me up with him.

Regards, Don
DonW
Posts: 40
Joined: Feb 16, 2013 0:56
Location: Longview, WA

Re: Using QB4.5 Quick Libraries

Postby DonW » Feb 24, 2013 6:23

dodicat wrote:You can directly call kernel32.dll in freebasic for a message box.
But I can't get it to work in QB.

Code: Select all

Declare Function msg lib "kernel32.dll" Alias "MessageBoxW"(n1 As Integer,s1 As Wstring,s2 As Wstring,n2 As Integer) As Integer:Sleep 1


msg(0,"hello","Box",0)


But this works in QB with Win XP (without the #lang "qb" of course.

Code: Select all

#lang "qb"

sub messagebox(msg$)
     shell ("msg * "+ msg$)
 end sub
 
 messagebox("hello")


Thanks for the suggestions. I tried both of your examples using FBIde, and both of them produce a "Windows" style message box in the console window. However, the latter example only worked with freebasic, not QB4.5.

My QB4.5 application uses totally text based screens, so the QuickPak Pro library routine produces nice text based message boxes. If I knew how to insert a screen print in my reply, It would help you to see what I'm doing in QB.

Don
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Re: Using QB4.5 Quick Libraries

Postby Theunis Jansen » Feb 28, 2013 9:41

I searched for BLOAD and the programs I found, including the conversion ones, did not work. Apparently the palette and Screen mode of the original BSV file must be known. So I tried every Screen Mode 0 to 21 but No Go. I jut cant load a BASIC BSAVE file. If I use -e in FBIDE it just bombs out, without it I get a blank screen.

The question is is there an equivalent or a work around for VARSEG in FB. The docs just say not available in FB.
What about DIM ANY as Ptr (don't know the exact format). Could this be used ?
If so a snippet will be appreciated.
Or has someone perhaps written a FB module/Lib to BLOAD BSV files.
My old brain is starting to smoke trying to find a solution.

I have searched far and wide but they evade my efforts. Surely this would have been something that was a necessity for compatibility with QB.

FB's BLOAD loads BMP files. To run a program and take screen shots of every BSV usually ends up as a jpg, and then to convert them to BMP is sometimes x10, or more, the size of the BSV.
RockTheSchock
Posts: 232
Joined: Mar 12, 2006 16:25

Re: Using QB4.5 Quick Libraries

Postby RockTheSchock » Feb 28, 2013 15:06

is is there an equivalent or a work around for VARSEG in FB. The docs just say not available in FB.


VARSEG, DEF SEG, PEEK, POKE and CALL INTERRUPT are all used to read or write directly to memory or call directly 16-bit machine code from QB. Freebasic runs in 32 bit mode. There is no chance to use directly from FB (or any other 32 bit compiler) 16 bit specific code. At least if the application should also run directly in a 64 bit enviroment.

The best thing you can do is to replace the specific function block. We could help you if would explain exactly what type of input box you want, but here is an example, It's simple with no input checks. It will be buggy!

EDIT:
I replaced the TextField function with a better Version.


Code: Select all

Function TextFieldBackground(row As Integer, col As Integer, size As Integer) As String
   Dim text As String
   
   Dim i As Integer
   Dim j As Integer
   
   For i = row To row+2
      For j = col To col+size+2
         text=text+chr(Screen(i,j))         
      Next      
   Next
   Return text
End Function

Function TextField(row As Integer, col As Integer, size As Integer, maxsize As Integer=50) As String
   Dim text As String
   Dim changed As Integer
   Dim background As String
         
   Dim key As String
   Dim askey As Integer
   
   Dim oldrow As Integer
   Dim oldcol As Integer
   
   Dim curpos As Integer
   curpos=1
   
   'Save CusorState
   oldrow = CsrLin()
   oldcol = Pos()
   
   background = TextFieldBackground(row, col, size)   

   'Draw Box
   Locate row,col
   Print Chr(201);String(size,205);Chr(187)
   Locate row+1,col
   Print Chr(186);Space(size);Chr(186)
   Locate row+2,col
   Print Chr(200);String(size,205);Chr(188)   
   
   'Set blinking cursor at right position
   Locate row+1,col+1,1
   Do
      key   = InKey()
      askey = Asc(key)
      
      Select Case askey
         Case 32 To 127 'All readable chars
            If Len(text)<maxsize Then
               text=text+key
               If curpos<=size Then curpos = curpos+1
               changed = 1
            EndIf            
         Case 13          'Return
            Exit Do
         Case 27         'Escape
            text = ""
            Exit Do
         Case 8         'Backspace
            If Len(text)>0 Then
               text = Left(text,Len(text)-1)
               curpos=curpos-1
               If curpos<1 Then curpos=1
               If Len(text)>=size Then curpos=size+1
               changed = 1
            End if
      End Select
      
      If changed Then
         Locate row+1,col+1
         Print Right(text,size)+Space(size-Len(Text));
         Locate row+1,col+curpos
         changed=0   
      EndIf
      
   Loop
   
   'Restore Background
   Locate row,col
   Print Left(background,size+2)
   Locate row+1,col
   Print Mid(background,size+4,size+2)   
   Locate row+2,col
   Print Mid(background,size*2+7,size+2)
   
   Locate oldrow,oldcol,0
   Return text
End Function

'------------------------------

Dim i As Integer

Screen 0
Width 80,25

For i = 1 To 80*25   
   Print chr((i Mod 26)+65);
Next

Locate 20,1
Print "Hello World!"


Print TextField(2,10,20)

Sleep

Last edited by RockTheSchock on Feb 28, 2013 15:56, edited 1 time in total.
counting_pine
Site Admin
Posts: 6229
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Using QB4.5 Quick Libraries

Postby counting_pine » Feb 28, 2013 15:53

Theunis Jansen wrote:Or has someone perhaps written a FB module/Lib to BLOAD BSV files.
My old brain is starting to smoke trying to find a solution.

I have searched far and wide but they evade my efforts. Surely this would have been something that was a necessity for compatibility with QB.

FB's BLOAD loads BMP files. To run a program and take screen shots of every BSV usually ends up as a jpg, and then to convert them to BMP is sometimes x10, or more, the size of the BSV.

It should be at least easy to write a function that can take "cross-platform" screenshots in QB.
e.g. loop over every x,y in the image and "Print #f, Point(x,y)". Then reading back is essentially the reverse process using Input # instead of Print #.

DOSBox is good at taking actual screenshots. I think Ctrl-F5 is the shortcut. It saves them as PNG; I think there would be outrage if it used JPG..

I remember looking at the old .bsv format once. I don't recall actually writing a function that could read them, but I don't think it would be too difficult. The main problem I think was that each scanline could be split into different planes, but that's not too difficult to unravel.
If it would be helpful I could probably write a reader function for them, given a little time..
RockTheSchock
Posts: 232
Joined: Mar 12, 2006 16:25

Re: Using QB4.5 Quick Libraries

Postby RockTheSchock » Feb 28, 2013 16:45

The 16 bit memory addressing works segmented in 64KB blocks. So DOS have 10 Segments -> 640 KB for Programms and from 640KB to 1024KB for Drivers and other hardware related stuff.

I assume you are using Screen 0 as Display with 80 columns and 25 rows. So you can change the segment where you can peek and poke arround to the TextMode block with

Screen 0
DEF SEG=&HB800

If i remember right, if you want two read the first char on screen you can use
screen(row,col) or you can peek(1)

if you want the color you can use
color(row,col) or peek(0)

http://www.antonis.de/faq/qbmonfaq-date ... 26044.html

BSAVE actually saves from memory a block to a file
BLOAD writes to memory from a file

So in screen 0 width 80,25 you have 80*25*2 bytes of textmode memory.


the position where to read or write is set by def seg.

for "Screen 13" VGA mode the memory format is different
http://www.petesqbsite.com/sections/tut ... tutor1.htm
marcov
Posts: 3019
Joined: Jun 16, 2005 9:45
Location: Eindhoven, NL
Contact:

Re: Using QB4.5 Quick Libraries

Postby marcov » Feb 28, 2013 22:29

RockTheSchock wrote:The 16 bit memory addressing works segmented in 64KB blocks. So DOS have 10 Segments -> 640 KB for Programms and from 640KB to 1024KB for Drivers and other hardware related stuff.


And don't forget the HMA, 64kb starting from 1MB-16 byte :-)

To be honest, some 32-bit dosextenders map the 16-bit memory space into the 32-bit memory space. It is just that go32v2 does not (but accesses via %fs iirc)
Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Re: Using QB4.5 Quick Libraries

Postby Theunis Jansen » Mar 01, 2013 14:07

The DOSBOX screenshots work perfectly. The PNG file size is the same as that of the BSV. (4Kb for the fullscreen - 80x25). Is there any precompiled PNG Library for FB that I can use that has a BI to include. With simple command such as : LOAD_PNG "Picture.png - for use with #Lang "fblite"
That is something like Bload "Picture.BMP" which works fine. Converting the BSV of 4Kb to Bmp ends up with a 247Kb file.

If there is such a LIB would it be possible to add it to FB as an internal LIB and not a DLL? Yeah yeah I am a lazy old man.
That is after using the DOSBOX screenshot PNG and converting it to BMP (uncompressed is the only way FB reads it - I checked the Help file for this)
There are 48 BSV files to convert and then I must find the relevant BSV. I have read them all into a file Using = Dir /B > "filename" and I can check them one by one with a FOR....NEXT Loop.
Jonge
Posts: 130
Joined: Jul 17, 2012 17:51
Location: Norway
Contact:

Re: Using QB4.5 Quick Libraries

Postby Jonge » Mar 01, 2013 14:59

Theunis Jansen
Posts: 248
Joined: Jul 01, 2010 9:35

Re: Using QB4.5 Quick Libraries

Postby Theunis Jansen » Mar 01, 2013 16:46

Thanks Jonge.

I must have had something on my 4-eyes to miss that one. Or maybe i fell asleep in front of the computer. (It happens when I stay awake until 2 or 3 AM)

Reading from post one onwards will probably, between snoozes, take the whole day but I do have the time.

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests