Announcement

Collapse
No announcement yet.

Absolute Types

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Absolute Types

    I'm trying to use types to extract information at fixed locations
    in memory.
    For example to modify the PBVUSERAREA.
    I can do it this way.
    Code:
         TYPE PBVUSERTYPE
              Check AS BYTE
              Action AS BYTE
              Level AS BYTE
              Retval AS BYTE
              Caller AS STRING * 12
              Spare AS STRING * 16
         END TYPE
    
         DIM Pu AS PBVUSERTYPE
         Q$=PBVUSERAREA
         LSET Pu=Q$
         Pu.Caller="MYPROG.BAS"
         PBVUSERAREA=Pu
    
    I thought it may be easier to DIM the type at an absolute address
    
         DIM ABSOLUTE Pu AS PBVUSERTYPE AT VARPTR32(PBVUSERAREA)/16
    
    but the compiler complained.
    
    Is my syntax wrong, or it just can't be done.
    
    Any comments appreciated.
    
    Dave
    
    <[email protected]>
    ------------------




    [This message has been edited by Dave Stanton (edited October 26, 2000).]
    Dave.

    You're never too old to learn something stupid.

  • #2
    Sorry, but there is no native way to get a pointer to the pbvUserArea internal variable... you'll have to stick with the conventional assignment method.

    Of course, if you copy the data in pbvUserArea to your UDT, you can use a pointer to the UDT... just not to pbvUserArea itself.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Thanks Lance, you'r still awake, no rest for the wicked.
      Dave.


      ------------------
      Dave.

      You're never too old to learn something stupid.

      Comment


      • #4
        Dave, it's only 10:45pm in New Zealand (I telecommute to work!). NZ is almost a whole day ahead of the US (Pacific time), because NZ is at GMT+12:00.

        Living in NZ does have benefits... we see the new year in before the rest of the world!



        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment


        • #5
          I know, I'm in the Emerald City (Sydney).
          I take your point about the PBVUSERAREA, but how would I go
          using a TYPE over the BIOS area, for example.
          Code:
          TYPE Kbdbuftype
               Unused   AS STRING * 10
               Nextchar AS WORD
               Lastchar AS WORD
               Kbdbuf   AS STRING * 16   
          END TYPE
          
          Using  
          
             DIM ABSOLUTE Kb AS Kbdbuftype AT &H41
          
          doesn't want to compile.
          Any thoughts?

          Dave

          ------------------


          [This message has been edited by Dave Stanton (edited October 26, 2000).]
          Dave.

          You're never too old to learn something stupid.

          Comment


          • #6
            You can DIM ABSOLUTE a single UDT by making a one-element array:
            Code:
            DIM foo (0) AS whatever AT whereever
            Then you can move the data using a pointer to element 0.

            But why bother? Just use a dataname as UdtType PTR

            (But why you are dividing VARPTR32 by 16 is a mystery to me)

            MCM

            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              MCM
              I'm probably wrong, but I understood that DIM AT required a segment
              address; VARPTR returns the full Segment : offset.
              Seg=VARPTR\16 reduces the offset to usually <16.
              Thanks for your pointers (sorry)

              Dave



              ------------------


              [This message has been edited by Dave Stanton (edited October 27, 2000).]
              Dave.

              You're never too old to learn something stupid.

              Comment


              • #8
                Duh. I forgot that in PB/DOS, you DIM AT "segment" rather than as in PB/Win, where you DIM AT "absoluteaddress."

                It's just that I never used divide by 16 to get the segment from a VARPTR32.

                Under DOS, the segment is just VARSEG (variable).

                MCM
                Michael Mattias
                Tal Systems Inc. (retired)
                Racine WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Michael,
                  Actually, I was wrong.
                  For a segment with the minimum offset, I should have used.
                  Code:
                       Xseg???= VARSEG(PBVUSERAREA)+VARPTR(PBVUSERAREA)\16
                  but as arrays always start at an offset of 0 in a sement

                  Code:
                      DIM ABSOLUTE Pu(0) AS PBVUSERTYPE AT VARSEG(PBVUSERAREA)
                  works well.
                  Thanks.

                  Dave



                  ------------------
                  Dave.

                  You're never too old to learn something stupid.

                  Comment


                  • #10
                    Hmmm... I stand corrected... I have always believed it was not possible to get access to the pbvUserArea block that way.

                    Cute solution!


                    ------------------
                    Lance
                    PowerBASIC Support
                    mailto:[email protected][email protected]</A>
                    Lance
                    mailto:[email protected]

                    Comment


                    • #11
                      Isn't it easier to just...

                      DIM Udt AS UdtType
                      DIM UDTPtr AS UdtType PTR
                      UDTPtr = VARPTR32(pbvUserArea)
                      UDT= @UdtPtr

                      MCM


                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Magic Michael,
                        Thank you
                        Dave

                        ------------------
                        Dave.

                        You're never too old to learn something stupid.

                        Comment

                        Working...
                        X