BBC BASIC for Windows
« Converting a 40-bit to a 64-bit float? »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:26pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Converting a 40-bit to a 64-bit float?  (Read 191 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Converting a 40-bit to a 64-bit float?
« Reply #5 on: Aug 14th, 2014, 2:16pm »

on Aug 14th, 2014, 11:55am, Richard Russell wrote:
-masm=intel compiler switch.


I had used that switch in conjunction with the -S switch (for outputting an assembly language listing), but I hadn't realised that it affected the inline assembler. Maybe it was obvious, but I'm learning. :)


Quote:
I still haven't quite grasped why you have to.


Mostly personal preference, admittedly. It's for a routine called gPlotPoints (familiar from GFXLIB), where one supplies pointers to a list of X coordinates and to a list of Y coordinates (haven't fully figured out structure array handling and pointers in C yet -- it's early days).

This demo linked-to below shows what gPlotPoints does (it's nothing that you and most others here haven't seen before):

http://www.bb4wgames.com/temp/gplotpointsdemo.zip

Includes two versions - fixed-point (fxp) and 64-bit double (dbl). The source listing (for inspection by the curious) is included below. You can see why your wrapper idea (for converting 40- to 64-bit floats) isn't really suitable in this case as it would be far too slow. As it happens, I'm getting 60 fps for 3000 points on my slow-ish laptop, both for fixed-point and 64-bit double 'mode'. Not bad considering it's BB4W that's updating the coordinates.


David.
--

Code:
      REM Example of using gPlotPoints to plot multiple points.
      REM This uses fixed-point coordinates format.
      REM 3000 points at 60 fps on my 1.66GHz 64-bit Intel Celeron

      *ESC OFF
      MODE 8 : OFF
      ON ERROR REPORT : PRINT " at line "; ERL : END

      INSTALL @lib$ + "GLIB2"
      PROCInitGLIB( @lib$ + "glib2.dll", g{} )

      ON ERROR PROCCleanup : PROCerror
      ON CLOSE PROCCleanup : QUIT

      GetTickCount% = FN`s("GetTickCount")
      REM FN`s() is one of GLIB's internal functions,
      REM but nevertheless comes in handy for our purposes!

      clr% = FNImport("gLerpClr")
      plot% = FNImport("gPlotPoints")

      nPts% = 3000
      DIM x%( nPts%-1 ), y%( nPts%-1 )
      DIM dx%( nPts%-1 ), dy%( nPts%-1 )
      DIM col%( nPts%-1 )

      FOR I% = 0 TO nPts%-1
        x%( I% ) = 640*RND(1) * 2^16
        y%( I% ) = 512*RND(1) * 2^16
        dx%( I% ) = 4*(RND(1)-0.5) * 2^16
        dy%( I% ) = 4*(RND(1)-0.5) * 2^16
        col%( I% ) = RND(&FFFFFF)
      NEXT I%

      maxX% = 640 * 2^16
      maxY% = 512 * 2^16

      fmt% = 2 : REM coordinates format (fixed-point)

      REM 0 = integer
      REM 1 = <reserved>
      REM 2 = 16:16 fixed-point
      REM 3 = 40-bit float (not yet supported)
      REM 4 = 64-bit float

      frames% = 0

      *REFRESH OFF
      SYS GetTickCount% TO time0%
      REPEAT
        SYS clr%, g{}, &803020, &203040
        SYS plot%, g{}, fmt%, ^x%(0), ^y%(0), ^col%(0), nPts%
        FOR I%=0 TO nPts%-1
          x%(I%)+=dx%(I%)
          y%(I%)+=dy%(I%)
          IF x%(I%)<0 OR x%(I%)>=maxX% dx%(I%)*=-1
          IF y%(I%)<0 OR y%(I%)>=maxY% dy%(I%)*=-1
        NEXT
        PROCDisplay(TRUE)
        frames% += 1
        SYS GetTickCount% TO time1%
        IF time1%-time0%>=1000 THEN
          SYS GetTickCount% TO time0%
          SYS "SetWindowText", @hwnd%, STR$nPts%+" points | " + STR$frames% + " fps"
          frames% = 0
        ENDIF
      UNTIL FALSE

      PROCCleanup
      END

      DEF PROCerror
      *REFRESH ON
      CLS : ON : REPORT : PRINT " at line "; ERL;
      REPEAT UNTIL INKEY(1)=0
      ENDPROC
 

User IP Logged

rtr
Guest
xx Re: Converting a 40-bit to a 64-bit float?
« Reply #6 on: Aug 14th, 2014, 3:49pm »

on Aug 14th, 2014, 2:16pm, David Williams wrote:
It's for a routine called gPlotPoints (familiar from GFXLIB), where one supplies pointers to a list of X coordinates and to a list of Y coordinates

So, just specify that the user of the library must declare those arrays/lists either with a % suffix (for the integer version) or a # suffix (for the float version). There is no need to support 40-bit or 80-bit variants, it just adds complication and slows things down (even if the conversion is done in machine code).

I implore you not to release a library which supports only BB4W v5.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls