X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=ROM2%2Fasm.h;h=c99d4a77363bb89e44f71db8e79d1a25ab756dc8;hb=0b1cde693aae432ed16592cc85edfc3ae0d645a2;hp=0c9b7fa776c8217d97255a6a1b51ed34d6943470;hpb=c9763dcb182398266bae1c6a7a848beec1cba35d;p=uccvend-snackrom.git diff --git a/ROM2/asm.h b/ROM2/asm.h index 0c9b7fa..c99d4a7 100644 --- a/ROM2/asm.h +++ b/ROM2/asm.h @@ -3,25 +3,43 @@ #include "types.h" -/* these would be inline functions, but gcc won't believe that mask is a constant - * when passed as a parameter +/* The "g" below really should be an "i", but gcc doesn't believe that it will + * always be an immediate value. Using "g" makes the compiler be quiet, but + * the assembler should fail if the value is not an immediate. */ -#define bset(addr, mask) \ - asm volatile ( \ - "ldx %0\n" \ - "bset 00,x,%1" \ - : /* outputs */ \ - : "p" (addr), "i" (mask) /* inputs */ \ - : "x" /* altered registers */ \ - ); +extern inline void bset(const void* addr, const u8 mask) { + /* The assembly breaks when gcc tries to optimise consecutive calls to + * bset/bclr on the same memory address. Sigh. Either turn off optimisation + * (-O1 without -Os works), or we do it the dumb way. + */ + *(u8*)addr |= mask; + // asm volatile ( + // "ldx %0\n" + // "bset 00,x,%1" + // : /* outputs */ + // : "p" (addr), "g" (mask) /* inputs */ + // : "x" /* altered registers */ + // ); +} -#define bclr(addr, mask) \ - asm volatile ( \ - "ldx %0\n" \ - "bclr 00,x,%1" \ - : /* outputs */ \ - : "p" (addr), "i" (mask) /* inputs */ \ - : "x" /* altered registers */ \ - ); +extern inline void bclr(const void* addr, const u8 mask) { + /* same issue as above */ + *(u8*)addr &= ~mask; + // asm volatile ( + // "ldx %0\n" + // "bclr 00,x,%1" + // : /* outputs */ + // : "p" (addr), "g" (mask) /* inputs */ + // : "x" /* altered registers */ + // ); +} + +extern inline void lock() { + asm volatile ("sei"); +} + +extern inline void unlock() { + asm volatile ("cli"); +} #endif /* _ASM_H_ */