X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=ROM2%2Fasm.h;h=41e9fe2752b7e8a6515760137ef4d06ad1bd99cd;hb=2e7a8beb908896930042bc0564fbd16f3e0b0b62;hp=3e8cc09491c30cfd104a2018e27751882404be46;hpb=cef1445c4f1ebaa38f9e6561b4fd15f164a27dcd;p=uccvend-snackrom.git diff --git a/ROM2/asm.h b/ROM2/asm.h index 3e8cc09..41e9fe2 100644 --- a/ROM2/asm.h +++ b/ROM2/asm.h @@ -5,26 +5,41 @@ /* 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 will fail if the value is not an immediate. + * the assembler should fail if the value is not an immediate. */ -extern inline void bset(void* addr, u8 mask) { - asm volatile ( - "ldx %0\n" - "bset 00,x,%1" - : /* outputs */ - : "p" (addr), "g" (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 */ + // ); } -extern inline void bclr(void* addr, u8 mask) { - asm volatile ( - "ldx %0\n" - "bclr 00,x,%1" - : /* outputs */ - : "p" (addr), "g" (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 ("cli"); +} + +extern inline void unlock() { + asm volatile ("sei"); } #endif /* _ASM_H_ */