BartmanAbyss / vscode-amiga-debug

One-stop Visual Studio Code Extension to compile, debug and profile Amiga C/C++ programs compiled by the bundled gcc 12.2 with the bundled WinUAE/FS-UAE.
GNU General Public License v3.0
314 stars 39 forks source link

CIA resource functions not working #56

Closed tehKaiN closed 2 years ago

tehKaiN commented 3 years ago

Consider following code:

#include <proto/cia.h>

// ...

// Query CIA ICR bits set by OS for later CIA takeover restore
struct Library *pCiaA = OpenResource(CIAANAME);
WORD wCurrentIcr = AbleICR(pCiaA, 0);

It results with compiler error, because AbleICR is defined as LP2NB macro call, which isn't defined anywhere. All cia.h functions are affected (AddICRVector, RemICRVector, AbleICR, SetICR) because LP3NB and LP3NRNB aren't defined too.

tehKaiN commented 3 years ago

@BartmanAbyss fixed it! There's a problem in the header files.

in resources/cia.h there's:

#define AbleICR(___resource, ___mask) \
      LP2NB(0x12, WORD, AbleICR , struct Library *, ___resource, a6, WORD, ___mask, d0)

and in macros.h:

/* Only cia.resource/AbleICR() and cia.resource/SetICR() */
#define LP2UB(offs, rt, name, t1, v1, r1, t2, v2, r2)        \
({                                \
   t1 _##name##_v1 = (v1);                    \
   t2 _##name##_v2 = (v2);                    \
   rt _##name##_re2 =                        \
   ({                                \
      register volatile int _d1 __asm("d1");                \
      register volatile int _a0 __asm("a0");                \
      register volatile int _a1 __asm("a1");                \
               register rt _##name##_re __asm("d0");            \
      register volatile t1 _n1 __asm(#r1) = _##name##_v1;        \
      register volatile t2 _n2 __asm(#r2) = _##name##_v2;        \
      __asm volatile ("jsr %%a6@(-"#offs":W)"            \
      : "=r" (_##name##_re), "=r" (_d1), "=r" (_a0), "=r" (_a1)    \
      : "r"(_n1), "rf"(_n2)                    \
      : "fp0", "fp1", "cc", "memory");                \
      _##name##_re;                        \
   });                                \
   _##name##_re2;                        \
})

changing name in macros.h to LP2NB fixed it. I looked at Bebbo's macros.h and he uses the exactly same macros but with NB names. Same with remaining UB macros in macros.h - changing to NB fixes the issue.