News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Recent posts

#61
Windows Projects / Hyper - Divide using multiplic...
Last post by i Z ! - August 30, 2024, 07:29:57 AM
Found a relatively quick way to divide. It's approximate, but close enough  :smiley:

VB
Option Explicit Off
Imports HyperLib

'!!! For this code to work, because of the numeric methods used, "Skip integer overflow checks" option must be checked in the Advanced compile settings

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Hyper.displayMode = Hyper.displayModeType.inDecimalBase2_64
        Hyper.maxDigitsInString = 7 'display range

        ' input some random numbers for a and d ->
        Dim a As New Hyper(-251, -253)    'assign 3 * 8 bytes for a, with its least exponent (2^64)^(-253)                 
        a(-252) = -79786875757656175
        a(-253) = 79978687575765619 '
        a(-251) = 7978687575765619

        Dim d As New Hyper(-444, -444) 'reserve 8 bytes for the divisor
        d(-444) = 1 + (2 ^ 53)
        d(-5) = 1 + 2 ^ 44 'mantissa automatically gets extended when assigning values at exponents out of current range; now the size of "d" is ((444-5) * 8) bytes

        Debug.WriteLine("")

        Dim rdiv As Hyper = QuickDivide(a, d)

        Debug.WriteLine("=================== result:")
        Debug.WriteLine(rdiv)

        rdiv *= d

        Debug.WriteLine("=================== check:")
        Debug.WriteLine(rdiv)

    End Sub



    Private Function QuickDivide(dividend As Hyper, d As Hyper) As Hyper
        Return dividend * ReciprocalVal(d)
    End Function
    Private Function ReciprocalVal(d As Hyper) As Hyper

        precision% = 1444 'number of 64-bit digits to extract. Must be larger than exponent range
        precision2% = 222 'may be zero

        Dim r As New Hyper(precision, 0) ' New Hyper(0, 0)
        Dim bp, r1 As Hyper

        hiExp% = d.FindHighExponent
        lowExp% = d.FindLowExponent
        lowVal& = d(lowExp)
        If lowVal And 1 = 0 Then
            Debug.WriteLine("even nr")
            'if the least significant bit is 0, then we can help ourselves with dividing/multiplying the dividend, and then the result, by 2^n.

            d(lowExp - 1) = 1
            lowVal = 1
            lowExp -= 1
        End If
        mq& = GetMagicNr(lowVal)
        pos% = lowExp '
        d.Round(-pos)
        d.PartSize = 0
        bp = New Hyper("1")
        pos1% = 0

mainloop:
        ' get the sequence which, when multiplied by divisor, nullifies itself

        r1 = New Hyper(pos1, pos1)
        r1(pos1) = bp(pos1) * mq

        r(pos1) = r1(pos1)
        bp -= d * r1
        bp.Negate()

        pos1 += 1

        If pos1 > precision Then GoTo nx
        'reciprocal values of large numbers tend to repeat at very large intervals, so we'll be satisfied with our precision                

        GoTo mainloop

nx:
        r1 = r * d

        hi% = r1.FindHighExponent
        r.Divide(r1(hi), precision2)
        r.PartSize = hi + r1.PartSize + r.PartSize + lowExp  '.PartSize           
        d.PartSize = -lowExp

        Debug.WriteLine("--=-=-=-=- recip*d:")
        Debug.WriteLine(r * d) 'should output close to 1
        Debug.WriteLine(r)
        Debug.WriteLine("--=-=-=-=-")

        Return r
    End Function

    Private Function GetMagicNr&(a&)

        ' Magic number or "reciprocal integer" - GET THE 64-BIT NUMBER WHICH, when multiplied by the lowest digit, gives 1 as the remainder of 2^64              
        ' Only for odd numbers.

        bt& = 1 'bit tester
        d& = a 'bit mask

        r& = 0 : i& = 0 : r0& = 0

        For i = 0 To 63

            If bt And r Then GoTo skip

            r += d
            r0 = r0 Or bt
skip:
            bt <<= 1 : d <<= 1
        Next

        Return r0
    End Function

End Class

Also posted on github


P.S.: I recently noticed that full decimal representation has bugs, I removed the default property from it. Who needs it anyway :)
#62
The Campus / Re: Creating a Game Using MASM...
Last post by NoCforMe - August 30, 2024, 07:01:42 AM
To the OP: I can help you with graphics not using the Irvine library, which apparently is not the best tool in the toolbox ...
#63
The Campus / Re: Creating a Game Using MASM...
Last post by NoCforMe - August 30, 2024, 06:48:46 AM
OK (red face here). But still, does that automatically make it a homework assignment? (Which I agree we shouldn't be doing for anyone. Answer questions, sure, but we're not Chat GPT here, at the service of every student too goddamn lazy to do the work ...)
#64
MASM64 SDK / Re: cmd_tail
Last post by Rockphorr - August 30, 2024, 01:34:40 AM
Quote from: HSE on June 12, 2024, 11:59:09 PM
Quote from: sinsi on June 12, 2024, 12:01:27 AMDoes len take into account the zero terminator?

:thumbsup: Fantastic Sinsi. That it's the point.

Then must be:
    mov r12, rvcall(GetCommandLine)
    mov r13, len(r12)
    add r13, 1
    mov r14, alloc(r13)


Why uses add instead inc ?
#65
Game Development / Re: Game of Life
Last post by tenkey - August 30, 2024, 01:26:04 AM
Quote from: tenkey on August 25, 2024, 01:52:38 AMAn interesting question is if UASM PROC args, USES, LOCALs, INVOKE, and RET properly work together--involving issues I had to consider when constructing STRUCTs for local (stack) data.

The automatic generation of STACKBASE:RSP code is broken, so there will not be a UASM version of Life. I have some ideas for fixing it.

There is an almost MASM-compatible interface with STACKBASE:RBP (default), but that's not what I'm aiming for.
#66
Showcase / Re: MediaPlayer
Last post by fearless - August 30, 2024, 12:27:08 AM
Thanks.

@jj2007 - unfortunately the Microsoft Media Foundation doesn't seem to support .ogg files. Just these one listed here: https://learn.microsoft.com/en-us/windows/win32/medfound/supported-media-formats-in-media-foundation

Drag and drop is included in it, but from reports it seems it might not be working for some people. I found a few interesting forum posts and blogs relating to drag and drop not working properly: https://forum.pellesc.de/index.php?topic=5852.0 and https://helgeklein.com/blog/how-to-enable-drag-and-drop-for-an-elevated-mfc-application-on-vistawindows-7/

So I guess I will look into that and use the findings there to adjust, and hopefully it will work for others. Currently I'm running Win10 Pro with a user with admin rights and UAC disabled, which is probably why it seems to work for me.

@greenozon - working on Unicode versions right now, which hopefully will tackle the issues raised on the github repo.
#67
Showcase / Re: MediaPlayer
Last post by greenozon - August 29, 2024, 10:04:51 PM
Wow, exciting work, congrats!

PS can't eat japanese hieroglyphs  in movies names any chance?
#68
The Campus / Re: Creating a Game Using MASM...
Last post by sinsi - August 29, 2024, 10:02:49 PM
Quote from: NoCforMe on August 29, 2024, 08:46:39 PM
Quote from: jj2007 on August 29, 2024, 03:37:12 PM... and the Irvine library.

Where do you get that from, JJ? The OP didn't mention it at all. Are you a mind reader?

Maybe the thread title?  :biggrin:
#69
The Campus / Re: Creating a Game Using MASM...
Last post by NoCforMe - August 29, 2024, 08:46:39 PM
Quote from: jj2007 on August 29, 2024, 03:37:12 PM... and the Irvine library.

Where do you get that from, JJ? The OP didn't mention it at all. Are you a mind reader?

Pardon me; I must be going blind in my old age ...
#70
The Campus / Re: Creating a Game Using MASM...
Last post by Vortex - August 29, 2024, 06:55:43 PM
Hi beauharlan,

Handling bitmap images :

Tutorial 25: Simple Bitmap

http://www.interq.or.jp/chubu/r6/masm32/tute/tute025.html