Kirk Gramcko

Possible to make routine accept near or far pointers? MC9S12XEP100

Discussion created by Kirk Gramcko on Oct 6, 2010
Latest reply on Oct 10, 2010 by CompilerGuru



I am using MC9S12XEP100 and using the banked memory model in my current project.


I recently got paging working in a few projects, but on my current project I now have an issue. Maybe I am asking for the impossible...but I am wondering if there is a way to write a routine such that I can pass in a pointer regardless of whether it is a __near or __far pointer.


The reason for this is that we have a lot of legacy code and it uses a lot of "common" code that is shared among many, many different projects. Recently, some of these projects have been converted to use the banked model in order to gain access to additional RAM space. However, most other projects have plenty of RAM and need not use paging. So, it would be nice if these routines would work in either case.


Below is an example routine that simply copies a string from ptr1 to ptr2. It has a source pointer and a destination pointer. I would like to be able to call it in various ways. For example, when ptr1is a near pointer and ptr2 is far, or vice versa, or both are near pointers, or both are far pointers, etc...


byte CopyString (byte *ptr1, byte *ptr2)
    byte count = 0;
    while (*ptr2++ = *ptr1++)


    return (count);


Is what I am asking possible? It would sure make life easier with regard to the enormous amount of legacy code that already uses these common routines. Even casting the parameters when the call is made would require editing  a lot of code in a lot of different projects.


Thanks in advance for any helpful advice.