Today 12:34
Forum: Proton Plus Compiler v3
Starter: joesaliba
Views: 0
Replies: 6
Yesterday 23:47
Forum: Proton Plus Compiler v3
Starter: johngb
Views: 0
Replies: 11
Yesterday 16:26
Forum: Proton Plus Compiler v3
Starter: Dave-S
Views: 0
Replies: 9
Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Help with Macros71 days old

  1. #1
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,328
    Thumbs Up
    Received: 49
    Given: 123
    Total Downloaded
    2.37 GB

    0 Not allowed!

    Default Help with Macros

    In the past I have created a few simple macros with the excellent "Proton Macro Generator" by John Barret.

    Now I need something a little more complex and I'm lost. I want the macro to be used as

    MacroName "a string of characters"

    and to return the address of the first character (in this case "a") an some word variable.

    If it's possible to do this using the generator and if you've time to walk thro the steps that would be great. Otherwise just the macro would be much appreciated.


    Edit. It occurs to me that it might be helpful to explain what I'm trying to do. I'm writing a compile time debugging tool. I currently have two similar macros that the user adds to the source under test and recompiles. Obviously the additional stuff that is added must be simple, quick to type and not likely to introduce even more bugs. For example my existing macro is used

    Dump n (where n is a byte value which is a pointer to the source)

    that value is passed to the PC client and it uses it, the parsed source and a dump of RAM to determine where the dump happened and the values of all variables.

    I think it might be useful for the code under test to display a string. But the need for simplicity precludes a separate CDATA or such.

    Before anyone asks, yes I am aware of the single stepping debugger but sometimes that overkill and anyway I can't get it work (finger trouble on my end I'm sure).

    From reading old posts I suspect it may not be possible to use a quoted string. Any alternatives?

    Further edit. Not sure if this will help or just muddy the water but here's my existing (working) macro
    Code:
      Dump Macro  P1
      #if (Prm_Count > 1)
          #error "Dump - Too many parameters"
      #else
          #if (Prm_Count < 1)
              #error "Dump - Too few parameters"
          #else
              #if(Prm_1 != Byte) && (Prm_1 != Num8) && (Prm_1 != Num16) && (Prm_1 != Num32)
                  #error "Dump - DumpNum(Param1) Should be a Byte variable or number"
              #endif
              #if (Prm_1 == Byte)
                  Byte_Byte P1, D_DumpID
              #endif
              #if (Prm_1 == Num8)
                  Num_Byte P1, D_DumpID
              #endif
              #if (Prm_1 == Num16)
                  Num_Byte P1, D_DumpID
              #endif
              #if (Prm_1 == Num32)
                  Num_Byte P1, D_DumpID
              #endif
          D_WaitFlag = 0                            ' silly billy
              GoSub D_Dump
          #endif
      #endif
      Endm
    Last edited by towlerg; 11th September 2017 at 14:46.
    George

  2. #2
    Article Author johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,124
    Thumbs Up
    Received: 66
    Given: 0
    Total Downloaded
    1.09 GB

    1 Not allowed!

    Default Re: Help with Macros

    The only vars you can pass with a macro are byte, word, Dword, float and their signed equivalents so I think you are asking the impossible. You can pass the address of an array/string into a macro or get it returned from a macro but I don't believe there is a mechanism in macros to pass a string. You will have to write your string away in memory and reference it in the macro. You could have a table of descriptor text from which you can choose from the index passed to the macro but I don't think that is really what you are after.

    Sorry I cant help any further.
    JohnB

  3. #3
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,328
    Thumbs Up
    Received: 49
    Given: 123
    Total Downloaded
    2.37 GB

    0 Not allowed!

    Default Re: Help with Macros

    Thanks John, even a positive negative is helpful.
    George

  4. #4
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    583
    Thumbs Up
    Received: 76
    Given: 2
    Total Downloaded
    1.93 GB

    1 Not allowed!

    Default Re: Help with Macros

    Hi George,
    I do not understand what you want to do exactly.
    But in my GPS code demo, I had written a macro with input of a string. I do not know if it will be useful.
    In this case the name & size of the string are already defined.

    Example:
    ' Definition variables: String ,Float, Float

    $define ConvQTHtoLatLong(pString, pLAT, PLON) '
    InpQTHStrg = pString '
    GoSub ConvertLocToCoordinates_Sub '
    pLAT = LATloc_Dd '
    pLON = LONloc_Dd

    Using the macro:
    ConvQTHtoLatLong("JN11BL", Latitude, Longitude)

    Regards
    ALberto
    [U]73's de Alberto ea3agv[/U]

  5. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,328
    Thumbs Up
    Received: 49
    Given: 123
    Total Downloaded
    2.37 GB

    0 Not allowed!

    Default Re: Help with Macros

    Hi Alberto

    seems like thats exactley what I'm tring to do

    To use your example I want to use the macro

    ConvQTHtoLatLong "JN11BL"

    and return a pointer to the J in the string in a variable and I guess I'd also need the length of the string (didn't think of that before). Looks like the string in your examle is fixed.

    Can I omit the brackets? (less typing).

    I didn't know about Pstring.

    Where did you find info about macros? they are barely mentioned in the manual
    George

  6. #6
    Article Author johngb's Avatar
    Join Date
    Oct 2003
    Posts
    2,124
    Thumbs Up
    Received: 66
    Given: 0
    Total Downloaded
    1.09 GB

    1 Not allowed!

    Default Re: Help with Macros

    In Alberto's example he used the pre-processor, whereas you were trying to this with an assemble macro. Arguably you could replace all the assembler macros with pre-processor directives which would make it more consistent.
    JohnB

  7. #7
    Prolific Poster joesaliba's Avatar
    Join Date
    Sep 2004
    Posts
    2,625
    Thumbs Up
    Received: 59
    Given: 18
    Total Downloaded
    2.27 GB

    1 Not allowed!

    Default Re: Help with Macros

    George,

    pString is a name that Alberto gave to his routine. I use the same method with variable length of string.
    Regards

    Joseph

  8. #8
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    583
    Thumbs Up
    Received: 76
    Given: 2
    Total Downloaded
    1.93 GB

    1 Not allowed!

    Default Re: Help with Macros

    Hi George,
    Using the built-in ISIS in the compiler, which is great, you can try some things.
    I've tried writing a macro that could summarize your needs, I expect.
    Brackets define the String, it is mandatory.

    Example:
    Code:
    '    Include "Proton18_4.inc"
    '    Include "Proton18_8.inc"
        Include "Proton18_16.inc"    
        
        Dim MyString As String * 25 ' The string must be large enough for all strings.
        Dim MyStringPointer As Byte ' Or a Word
        Dim LenghtOfString As Byte
        
        '---------------------------------------------------------------------------
        GoTo Main
        ' Place for macros
        $define TestString(pString, pStrgPointer, pStrgLenght) '
        Clear MyString                   '
        MyString = pString               '
        pStrgPointer = VarPtr MyString   '
        pStrgLenght = Len(MyString)
        
        '---------------------------------------------------------------------------    
        Main:
        Cls
    (*
        What the macros does.
        Clear MyString                      ' Write 0's in the string.
        MyString = "Hello World"            ' Load a string into a defined string.
        MyStringPointer = Varptr MyString   ' The pointer is always the same because the string is defined yet.
        LenghtOfString = Len(MyString)      ' Lenght of the loaded string.
    *)    
    
        TestString("Hello World", MyStringPointer, LenghtOfString)
    
        Print At 1,1, "Address: ", Dec MyStringPointer   ' Address in RAM memory
        Print At 2,1, "Lenght: ", Dec LenghtOfString    
    
        ' Another test
        DelayMS 3000
        TestString("Testing a String", MyStringPointer, LenghtOfString)
    
        Print At 1,1, "Address: ", Dec MyStringPointer
        Print At 2,1, "Lenght: ", Dec LenghtOfString 
    
        End
    Regards
    Alberto
    Last edited by AlbertoFS; 12th September 2017 at 19:37.
    [U]73's de Alberto ea3agv[/U]

  9. #9
    Senior Member AlbertoFS's Avatar
    Join Date
    Apr 2005
    Posts
    583
    Thumbs Up
    Received: 76
    Given: 2
    Total Downloaded
    1.93 GB

    1 Not allowed!

    Default Re: Help with Macros

    Sorry, maybe you wanted it this way.
    Code:
    '    Include "Proton18_4.inc"
    '    Include "Proton18_8.inc"
        Include "Proton18_16.inc"    
        
        Dim MyStringPointer As Byte
        Dim LenghtOfString As Byte
    '    Dim MyString1 As String * 11
    '    Dim MyString2 As String * 16
    '    Dim MyString3 As String * 17
    
        Dim MyString1 As String * 30
        Dim MyString2 As String * 30
        Dim MyString3 As String * 30        
        '---------------------------------------------------------------------------
        GoTo Main
        ' Place for macros
        $define TestString(pString, pStrgPointer, pStrgLenght) '
        pStrgPointer = VarPtr pString                          '
        pStrgLenght = Len(pString)
        
        '---------------------------------------------------------------------------    
        Main:
    (*
        What the macro does.
        MyStringPointer = Varptr MyString1   ' The pointer is always the same because the string is defined yet.
        LenghtOfString = Len(MyString1)      ' Lenght of the loaded string.
    *)    
        MyString1 = "Hello World"
        MyString2 = "Testing a string"
        MyString3 = "Macro for Strings" 
    
        TestString(MyString1, MyStringPointer, LenghtOfString)
        HRSOut "Address String1: ", Dec MyStringPointer,13,10
        HRSOut "Lenght String1:  ", Dec LenghtOfString,13,10    
        HRSOut 13,10
    
        ' Another test
        TestString(MyString2, MyStringPointer, LenghtOfString)
        HRSOut "Address String2: ", Dec MyStringPointer,13,10
        HRSOut "Lenght String2:  ", Dec LenghtOfString,13,10    
        HRSOut 13,10
        
        ' Another test    
        TestString(MyString3, MyStringPointer, LenghtOfString)
        HRSOut "Address String3: ", Dec MyStringPointer,13,10
        HRSOut "Lenght String3:  ", Dec LenghtOfString,13,10    
        
        End
    Regards
    Alberto
    [U]73's de Alberto ea3agv[/U]

  10. #10
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    1,328
    Thumbs Up
    Received: 49
    Given: 123
    Total Downloaded
    2.37 GB

    0 Not allowed!

    Default Re: Help with Macros

    @Johnb You are working under the delusion that I know the difference between a macro and the preprocessor, which sadly is not the case. The level of confusion re. macros, Proton preprocessor and MPASM # thingies is hard to quantify, so lets just say terminal.

    @Alberto stupid of me to want a string, pointer and length. If I have the string in a variable by default I have a pointer and the length is just LEN. In an earlier post I asked where to got info re. macros. So as we're using the Proton preprocessor not macros let me ask again, where did you get info about Proton preprocessor? in particular passing parameters, there's nothing in the manual.

    Just looked in manual for macro and found a bunch of Amicus macros. Are they macros or are they preprocessor (looks like preprocessor but called macros) for example "Amicus18_ADC.inc" ?
    George

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Timer Macros
    By johngb in forum Proton Plus Compiler v3
    Replies: 1
    Last Post: 30th December 2011, 20:01
  2. MACROS - Please be gentle
    By Barry in forum Proton Plus Compiler v3
    Replies: 3
    Last Post: 29th January 2010, 01:14
  3. [SOLVED !] SD Macros
    By Mike B in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 17th October 2008, 00:53
  4. Help with macros
    By the.fox in forum Proton Plus Compiler v3
    Replies: 4
    Last Post: 14th April 2005, 19:55

Members who have read this thread since 8th November 2017, 16:35 : 1

Actions :  (Set Date)  (Clear Date)

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts