Lockup

General FreeBASIC programming questions.
Post Reply
Darkseid2020
Posts: 3
Joined: Mar 17, 2023 16:56

Lockup

Post by Darkseid2020 »

I'm not sure if I'm posting in the right place as I'm not a beginner nor am I a pro. So I've got a bit of an issue with the code I'm converting little by little from a QB program. So far it's been going fine until I came to a certain Sub Program, the previous ones works fine, it's plain and simple. But the next one I tried seems to lockup the entire program. I'm not sure if I'm just blind and overlooking some thing that's obvious and your face or just plain stupid for not seeing it, so I need an extra pair of eyes on the code.

This program uses a custom font file, that I did not make. Some very brilliant QB programmer with the name Jarek, I believe, made a button routine that uses this custom QB font. I got it from http://qbasicgui.datacomponents.net/79_button2.html you'll need either the Impact.qbf or Jarek.qbf to test this.

The first Sub is a custom mouse routine, the second one opens the font files. And the last one is a custom print routine. You should run the buttons.bas file it in QB first to see what it should look like (I used it in QB 4.5, but I believe plain old QBasid should work as well). Copy the following code and then compile with FreeBasic. I'm doing all of this on Linux Mint, I haven't tried to compile it on Windows but I did compile it in Dosbox and it gives me the same results. Once compile run it and you'll see that all the sub programs work as expected but once you uncomment the the fPrint sub it locks up the entire program. I have to close the Terminal to kill the program.

Please look it over and let me know what it is I'm not seeing. Any help would be greatly appreciated.

Here is the code, call the file test.bas to keep it simple:

Code: Select all

' *****MOUSE RUTIN*****
DECLARE SUB MRun ( sg As Integer )
'if sg is 0 then you can see the mouse coordinates on screen and the status of
'the mouse buttons If you put this in between do and loop it communicate whit the
'mouse.

DECLARE SUB fOpen ( File As String, FileNum As Integer)
DECLARE SUB fprint ( Text As String, Textx As Integer, Texty As Integer, TextColor As Integer, FontNum as Integer, cur As Integer )
'text$       The text you want
'textx%      The x positions of the text
'texty%      the y positions of the text
'colour%     The text color
'file%       The file NR See down below  (in the fopen)
'cur%        My own special effect if its bigger than 0 it will do stripes and make it little bold
Type TMouse
    
    Res		As Integer
    X		As Integer
    Y		As Integer
    Wheel	As Integer
    Clip	As Integer
    
    Union
        
        mButtons As Integer
        
        Type
        
            mLeft:1		As Integer
            mRight:1		As Integer
            mMiddle:1	As Integer
        
        End Type
        
    End Union
    
End Type

Common Shared Mouse As TMouse

SUB MRun ( sg As Integer )

	' this part just communicates with the mouse SUB
	Mouse.Res = GetMouse( Mouse.X, Mouse.Y, Mouse.Wheel, Mouse.Clip )
	
	#ifdef __FB_DOS__
        Print "Mouse or mouse driver not available"
	#else
        Print "Mouse not available or not on window"
	#endif
		
	'if sg is 0 then you can see the mouse status on the screen
	IF sg = 0 THEN
	
		LOCATE 1, 1: PRINT USING "Resolusion: ###"; Mouse.Res
		LOCATE 2, 1: PRINT USING "X:### Y:### wheel: +### clip: ##"; Mouse.X; Mouse.Y; Mouse.Wheel; Mouse.Clip
		Locate 3, 1: Print "Buttons:"; Mouse.mButtons
		LOCATE 4, 1: PRINT "Button1:"; Mouse.mLeft
		LOCATE 5, 1: PRINT "Button2:"; Mouse.mRight
		Locate 6, 1: Print "Button3:"; Mouse.mMiddle
		
	END IF
	
 END SUB
 
SUB fOpen ( File As String, FileNum as Integer )
	
	OPEN File FOR RANDOM AS FileNum LEN = 2 
	
END SUB

SUB fprint ( Text As String, Textx As Integer, Texty As Integer, TextColor As Integer, FontNum As Integer, cur As Integer )
  
	Dim lpi As Integer, fws As Integer, fls As Integer, Count As Integer, M As Integer
	Dim a1 As Integer, a2	As Integer, n As Integer, z As Integer, bb As Integer, l As Integer, p As Integer
	
	GET #FontNum, 1, lpi
	GET #FontNum, 2, fws
	GET #FontNum, 3, fls
	
	FOR Count = 1 TO LEN( Text )
		M = ASC(MID$( Text, Count, 1)) - 29
		IF M > 3 THEN
			GET #FontNum, M, a1
			GET #FontNum, M + 1, a2
		
			FOR n = a1 TO a2 - 1 STEP lpi
				FOR z = 0 TO lpi - 1
					bb = bb + 1
					GET #FontNum, n + z, l
					LINE (p + Textx, (16 * z) + Texty)-(p + Textx, (16 * z) + 15 + texty), TextColor, , l
				NEXT z
				p = p + 1 + cur
			NEXT n
			p = p + fls
		ELSE
			p = p + fws
		END IF
	NEXT Count
  
END SUB


Dim Impact as Integer, Jarek as Integer

Impact = FreeFile
Jarek = FreeFile

fOpen( "Impact.qbf", Impact )
fOpen( "Jarek.qbf", Jarek )

ScreenRes 640, 480, 32

' fPrint ("Hello World", 100, 100, 15, Impact, 0)
Do
	MRun (0)
Loop until Inkey$ = chr$(27)
end
fxm
Moderator
Posts: 12197
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Lockup

Post by fxm »

1st correction (otherwise, with code above, Impact = Jarek = 1):

Code: Select all

Dim Impact as Integer, Jarek as Integer

Impact = FreeFile
fOpen( "Impact.qbf", Impact )
Jarek = FreeFile
fOpen( "Jarek.qbf", Jarek )

2nd correction:

Code: Select all

	Mouse.Res = GetMouse( Mouse.X, Mouse.Y, Mouse.Wheel, Mouse.mButtons, Mouse.Clip )
Darkseid2020
Posts: 3
Joined: Mar 17, 2023 16:56

Re: Lockup

Post by Darkseid2020 »

Thank fxm for catching the mistake I made with the mouse routine, and I made the correction to the code but the fPrint sub still locks up the program, so I'm still stuck.
fxm wrote: Mar 17, 2023 19:06 1st correction (otherwise, with code above, Impact = Jarek = 1):

Code: Select all

Dim Impact as Integer, Jarek as Integer

Impact = FreeFile
fOpen( "Impact.qbf", Impact )
Jarek = FreeFile
fOpen( "Jarek.qbf", Jarek )

2nd correction:

Code: Select all

	Mouse.Res = GetMouse( Mouse.X, Mouse.Y, Mouse.Wheel, Mouse.mButtons, Mouse.Clip )
fxm
Moderator
Posts: 12197
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Lockup

Post by fxm »

Maybe:
Dim lpi As Short, fws As Short, fls As Short, Count As Integer, M As Integer
Dim a1 As Short, a2 As Short, n As Integer, z As Integer, bb As Integer, l As Short, p As Integer

because:
OPEN File FOR RANDOM AS FileNum LEN = 2
Darkseid2020
Posts: 3
Joined: Mar 17, 2023 16:56

Re: Lockup

Post by Darkseid2020 »

It works, thank you, thank you, thank you a thousand times over. This has been a migraine for the most of the day. I'll add you to the credits of the project I'm working on. Again thank you.
fxm wrote: Mar 17, 2023 20:24 Maybe:
Dim lpi As Short, fws As Short, fls As Short, Count As Integer, M As Integer
Dim a1 As Short, a2 As Short, n As Integer, z As Integer, bb As Integer, l As Short, p As Integer

because:
OPEN File FOR RANDOM AS FileNum LEN = 2
Post Reply