Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 520
» Latest member: Firerr
» Forum threads: 2,926
» Forum posts: 27,239

Full Statistics

Latest Threads
QB64PE v4.1 is now live
Forum: Announcements
Last Post: Abazek
2 hours ago
» Replies: 7
» Views: 309
Webcam Pong v0.01
Forum: Works in Progress
Last Post: madscijr
6 hours ago
» Replies: 9
» Views: 139
Brick Smasher 3
Forum: Games
Last Post: SierraKen
Yesterday, 10:39 PM
» Replies: 6
» Views: 115
PCX file format
Forum: Petr
Last Post: Firerr
Yesterday, 09:47 PM
» Replies: 12
» Views: 735
USB Camera?
Forum: Help Me!
Last Post: SpriggsySpriggs
Yesterday, 12:02 AM
» Replies: 33
» Views: 1,426
sound file playback (and ...
Forum: Help Me!
Last Post: Petr
02-26-2025, 06:33 PM
» Replies: 12
» Views: 429
Helicopter Rescue
Forum: Games
Last Post: Trial And Terror
02-26-2025, 02:47 PM
» Replies: 7
» Views: 1,061
Changing string variable ...
Forum: General Discussion
Last Post: Pete
02-26-2025, 02:24 AM
» Replies: 10
» Views: 273
Quick Question (I hope)
Forum: General Discussion
Last Post: SMcNeill
02-26-2025, 01:14 AM
» Replies: 3
» Views: 96
computer vision? capture ...
Forum: Help Me!
Last Post: madscijr
02-25-2025, 06:16 PM
» Replies: 0
» Views: 45

 
  Change Floating Point Precision
Posted by: SMcNeill - 04-20-2022, 02:20 AM - Forum: SMcNeill - No Replies

A quick example of how to change floating point precision in QB64.  This swaps between quick math (which uses hardware math processors) to extended precision math (which uses software processing).  Note that the default qbfpu is quite a bit faster, and for most folks this should be more than sufficient for your needs, as it tracks precision down to about the 15th decimal point.  IF, however, you absolutely have to have greater levels of precision, you can now swap over to extended precision and have about 20 decimal points worth of precision, at a significant reduction of speed.

And, if you need more than 20 decimal points of precision, you're just shit out of luck.  Find a math library for that, or else write a string math handling routine -- your CPU isn't equipped to handle anything more than this, natively.


FPU_Precision.h

Code: (Select All)
void set_dpfpu() { unsigned int mode = 0x37F; asm ("fldcw %0" : : "m" (*&mode));}
void set_qbfpu() { unsigned int mode = 0x27F; asm ("fldcw %0" : : "m" (*&mode));}

QB64 Code:

Code: (Select All)
' FPU_Precision.h needs to be in QB64 folder
$CONSOLE:ONLY
_DEST _CONSOLE
DECLARE CUSTOMTYPE LIBRARY ".\FPU_Precision"
    SUB set_dpfpu 'to toggle to double precision floating point math
    SUB set_qbfpu 'to toggle back to what most folks will see with QB64 64-bit default math
END DECLARE

DIM x AS _FLOAT, y AS _FLOAT


'Let's print our results without screwing with anything first.
x = 5##
y = x / 9##
PRINT USING "QB64 division      #.####################"; y


'Set the double precision math
set_dpfpu
x = 5##
y = x / 9##
PRINT USING "QB64 division      #.####################"; y

'Set the QB64 precision math
set_qbfpu
x = 5##
y = x / 9##
PRINT USING "QB64 division      #.####################"; y

Print this item

  ConvertOffset
Posted by: SMcNeill - 04-20-2022, 02:18 AM - Forum: SMcNeill - No Replies

Code: (Select All)
DIM x AS INTEGER
DIM m AS _MEM
m = _MEM(x)
PRINT m.OFFSET
PRINT ConvertOffset(m.OFFSET)


FUNCTION ConvertOffset&& (value AS _OFFSET)
$CHECKING:OFF
DIM m AS _MEM 'Define a memblock
m = _MEM(value) 'Point it to use value
$IF 64BIT THEN
   'On 64 bit OSes, an OFFSET is 8 bytes in size.  We can put it directly into an Integer64
   _MEMGET m, m.OFFSET,temp&&
    ConvertOffset&& = temp&& 'Get the contents of the memblock and put the values there directly into ConvertOffset&&
$ELSE
   'However, on 32 bit OSes, an OFFSET is only 4 bytes.  We need to put it into a LONG variable first
   _MEMGET m, m.OFFSET, temp& 'Like this
   ConvertOffset&& = temp& 'And then assign that long value to ConvertOffset&&
$END IF
_MEMFREE m 'Free the memblock
$CHECKING:ON
END FUNCTION

Print this item

  Extended Timer and TimeStamp
Posted by: SMcNeill - 04-20-2022, 02:17 AM - Forum: SMcNeill - Replies (3)

Code: (Select All)
SHELL "https://www.epochconverter.com/"
PRINT "Compare to time stamps generated at the website which popped up in your browser.https://www.epochconverter.com/"

CONST MyTimeZone## = 4 * 3600
DO
   _LIMIT 1
   CLS
   PRINT TimeStamp(DATE$, TIMER + MyTimeZone) 'Timezone difference with GMT, which is what the webpage sometimes points to.
   '                                           If the times seem off from the website, you'll want to change the timezone
   '                                           offset to match your current time zone.
   PRINT ExtendedTimer 'Unix Epoch Timer based on local time.
   _DISPLAY
LOOP


FUNCTION TimeStamp## (d$, t##) 'date and timer
   'Based on Unix Epoch time, which starts at year 1970.
   DIM l AS _INTEGER64, l1 AS _INTEGER64, m AS _INTEGER64
   DIM d AS _INTEGER64, y AS _INTEGER64, i AS _INTEGER64
   DIM s AS _FLOAT

   l = INSTR(d$, "-")
   l1 = INSTR(l + 1, d$, "-")
   m = VAL(LEFT$(d$, l))
   d = VAL(MID$(d$, l + 1))
   y = VAL(MID$(d$, l1 + 1))
   IF y < 1970 THEN 'calculate shit backwards
       SELECT CASE m 'turn the day backwards for the month
           CASE 1, 3, 5, 7, 8, 10, 12: d = 31 - d '31 days
           CASE 2: d = 28 - d 'special 28 or 29.
           CASE 4, 6, 9, 11: d = 30 - d '30 days
       END SELECT
       IF y MOD 4 = 0 AND m < 3 THEN 'check for normal leap year, and we're before it...
           d = d + 1 'assume we had a leap year, subtract another day
           IF y MOD 100 = 0 AND y MOD 400 <> 0 THEN d = d - 1 'not a leap year if year is divisible by 100 and not 400
       END IF

       'then count the months that passed after the current month
       FOR i = m + 1 TO 12
           SELECT CASE i
               CASE 2: d = d + 28
               CASE 3, 5, 7, 8, 10, 12: d = d + 31
               CASE 4, 6, 9, 11: d = d + 30
           END SELECT
       NEXT

       'we should now have the entered year calculated.  Now lets add in for each year from this point to 1970
       d = d + 365 * (1969 - y) '365 days per each standard year
       FOR i = 1968 TO y + 1 STEP -4 'from 1968 onwards,backwards, skipping the current year (which we handled previously in the FOR loop)
           d = d + 1 'subtract an extra day every leap year
           IF (i MOD 100) = 0 AND (i MOD 400) <> 0 THEN d = d - 1 'but skipping every year divisible by 100, but not 400
       NEXT
       s## = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
       TimeStamp## = -(s## + 24 * 60 * 60 - t##)
       EXIT FUNCTION
   ELSE
       y = y - 1970
   END IF

   FOR i = 1 TO m 'for this year,
       SELECT CASE i 'Add the number of days for each previous month passed
           CASE 1: d = d 'January doestn't have any carry over days.
           CASE 2, 4, 6, 8, 9, 11: d = d + 31
           CASE 3 'Feb might be a leap year
               IF (y MOD 4) = 2 THEN 'if this year is divisible by 4 (starting in 1972)
                   d = d + 29 'its a leap year
                   IF (y MOD 100) = 30 AND (y MOD 400) <> 30 THEN 'unless..
                       d = d - 1 'the year is divisible by 100, and not divisible by 400
                   END IF
               ELSE 'year not divisible by 4, no worries
                   d = d + 28
               END IF
           CASE 5, 7, 10, 12: d = d + 30
       END SELECT
   NEXT
   d = (d - 1) + 365 * y 'current month days passed + 365 days per each standard year
   FOR i = 2 TO y - 1 STEP 4 'from 1972 onwards, skipping the current year (which we handled previously in the FOR loopp)
       d = d + 1 'add an extra day every leap year
       IF (i MOD 100) = 30 AND (i MOD 400) <> 30 THEN d = d - 1 'but skiping every year divisible by 100, but not 400
   NEXT
   s## = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
   TimeStamp## = (s## + t##)
END FUNCTION

FUNCTION ExtendedTimer##
   'Simplified version of the TimeStamp routine, streamlined to only give positive values based on the current timer.
   'Note:  Only good until the year 2100, as we don't do all the fancy calculations for leap years.
   'A timer should work quickly and efficiently in the background; and the less we do, the less lag we might insert
   'into a program.

   DIM m AS INTEGER, d AS INTEGER, y AS INTEGER
   DIM s AS _FLOAT, day AS STRING
   day = DATE$
   m = VAL(LEFT$(day, 2))
   d = VAL(MID$(day, 4, 2))
   y = VAL(RIGHT$(day, 4)) - 1970
   SELECT CASE m 'Add the number of days for each previous month passed
       CASE 2: d = d + 31
       CASE 3: d = d + 59
       CASE 4: d = d + 90
       CASE 5: d = d + 120
       CASE 6: d = d + 151
       CASE 7: d = d + 181
       CASE 8: d = d + 212
       CASE 9: d = d + 243
       CASE 10: d = d + 273
       CASE 11: d = d + 304
       CASE 12: d = d + 334
   END SELECT
   IF (y MOD 4) = 2 AND m > 2 THEN d = d + 1 'add a day if this is leap year and we're past february
   d = (d - 1) + 365 * y 'current month days passed + 365 days per each standard year
   d = d + (y + 2) \ 4 'add in days for leap years passed
   s = d * 24 * 60 * 60 'Seconds are days * 24 hours * 60 minutes * 60 seconds
   ExtendedTimer## = (s + TIMER)
END FUNCTION

Print this item

  EllipseFill
Posted by: SMcNeill - 04-20-2022, 02:16 AM - Forum: SMcNeill - Replies (2)

Code: (Select All)
SUB EllipseFill (cx AS INTEGER, cy AS INTEGER, rx AS INTEGER, ry AS INTEGER, c AS LONG)
   DIM a AS LONG, b AS LONG
   DIM x AS LONG, y AS LONG
   DIM xx AS LONG, yy AS LONG
   DIM sx AS LONG, sy AS LONG
   DIM e AS LONG

   a = 2 * rx * rx
   b = 2 * ry * ry
   x = rx
   xx = ry * ry * (1 - rx - rx)
   yy = rx * rx
   sx = b * rx

   DO WHILE sx >= sy
       LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
       IF y <> 0 THEN LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF

       y = y + 1
       sy = sy + a
       e = e + yy
       yy = yy + a

       IF (e + e + xx) > 0 THEN
           x = x - 1
           sx = sx - b
           e = e + xx
           xx = xx + b
       END IF
   LOOP

   x = 0
   y = ry
   xx = rx * ry
   yy = rx * rx * (1 - ry - ry)
   e = 0
   sx = 0
   sy = a * ry

   DO WHILE sx <= sy
       LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
       LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF

       DO
           x = x + 1
           sx = sx + b
           e = e + xx
           xx = xx + b
       LOOP UNTIL (e + e + yy) > 0

       y = y - 1
       sy = sy - a
       e = e + yy
       yy = yy + a

   LOOP

END SUB

Print this item

  CircleFill
Posted by: SMcNeill - 04-20-2022, 02:15 AM - Forum: SMcNeill - Replies (2)

Code: (Select All)
SUB CircleFill (CX AS LONG, CY AS LONG, R AS LONG, C AS LONG)
DIM Radius AS LONG, RadiusError AS LONG
DIM X AS LONG, Y AS LONG

Radius = ABS(R)
RadiusError = -Radius
X = Radius
Y = 0

IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB

' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX - X, CY)-(CX + X, CY), C, BF

WHILE X > Y
   RadiusError = RadiusError + Y * 2 + 1
   IF RadiusError >= 0 THEN
       IF X <> Y + 1 THEN
           LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
           LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
       END IF
       X = X - 1
       RadiusError = RadiusError - X * 2
   END IF
   Y = Y + 1
   LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
   LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
WEND

END SUB

Print this item

  Keybone's GUI & CLI (Modular OS/3 0.99 (2017))
Posted by: Keybone - 04-20-2022, 01:43 AM - Forum: Keybone - No Replies

Before I started creating GUIs I worked on a CLI project.
This was the most robust version I came up with.

How to login:

Username: root
Password: Password#

Username: keybone
Password: Password$

Username: guest
Password: (no password)

Passwords are Case-Sensitive

Once logged in you can use the help command with will display on screen an available list of commands.

The GUI can be entered by either typing gui at the prompt or pressing F4. Exit GUI mode by restoring the bomb window, and clicking the bomb.
Note: This GUI version was mostly functional, it just needed a refactoring because it was a pain to write applications using it. Never completed the refactor yet.

Working in GUI:
Restore window (from minimized and maximized)
Maximize window
Minimize window
Move window
Resize window
Raise/Focus window

Not working / not implemented:
Move Icon

Obligatory screenshots:

login prompt
[Image: Screenshot-2022-04-19-21-13-45.png]

login failure
[Image: Screenshot-2022-04-19-21-14-23.png]

command prompt and command output
[Image: Screenshot-2022-04-19-21-15-57.png]

GUI (Bomb and About)
[Image: Screenshot-2022-04-19-21-17-03.png]

GUI (Test Window)
[Image: Screenshot-2022-04-19-21-17-41.png]

Installation:
1) Download OS399a.zip and extract into QB64 Directory (not sub-folder)
2) Compile and run OS3_NEW6.bas



Attached Files
.zip   os399a.zip (Size: 213.69 KB / Downloads: 174)
Print this item

  QB64p Discord invite
Posted by: Richard - 04-19-2022, 11:33 PM - Forum: General Discussion - No Replies

I am already a member of Disco, but just for fun I tried to go there via your sub-forum and got directed to 

ttps://discord.com/invite/2t9HTYK



https://www.dropbox.com/s/r47okclwl0hnji...s.PNG?dl=1

Print this item

  Tutorial
Posted by: johnno56 - 04-19-2022, 09:45 PM - Forum: Help Me! - Replies (7)

... and yes. Before you ask, I have read and worked my way through Terry's tutorials... but my request is specific. I am looking for a tutorial to create a non-scrolling, multi-level, old fashioned platformer. You remember? Coins; Enemies; Lava; Jump-pads; cheesy sound effects... You 'do' remember, right? Aw, man... Is my age slipping again?  I like 'old school'... lol

Any assistance would be appreciated. Thank you.

J

Print this item

  Discussion Board for the Collection of Graphic Programs by TheBOB.
Posted by: Pete - 04-19-2022, 05:53 PM - Forum: TheBOB - Replies (6)

Print this item

  Keybone's GUI ("OS/3 Operating Environment 2.01 ALPHA")
Posted by: Keybone - 04-19-2022, 05:50 PM - Forum: Keybone - No Replies

I created this version of my GUI in the end of 2019. It's still incomplete and has bugs.
Mostly I created this version to show off 2 new themes I made at the time: MacOS and BeOS.
This also includes the Win3.x, Motif-like, and blank themes. Plus many miscellaneous things.

Working:
window moving
window resizing

Non-working:
minimizing window
maximizing window
closing window
raise/focus window

Obligatory Screenshot:

[Image: os3-multitheme-bg.png]


Installation:

1) Copy os3_201a.txt and Gold1.png into your qb64 folder.
2) Rename os3_201a.txt to os3_201a.bas.
3) Compile and run os3_201a.bas

Gold1.png:

[Image: Gold1.png]

os3_201a.bas:



Attached Files
.txt   os3_201a.txt (Size: 69.08 KB / Downloads: 98)
Print this item