Skip to content

Commit

Permalink
Fix fc_nyblswap on LLVM (#60)
Browse files Browse the repository at this point in the history
With a constraint "a", %0 will expand to "A" in the asm, meaning
"ld%0" will become "ldA" without any address.  But since we have
constrained the operand to already be in A, there is no need to add
any load or store instructions anyway, so just remove them.

Also the global variable "swp" is not needed either, so remove that as well
when using LLVM.
  • Loading branch information
zeldin authored Aug 2, 2024
1 parent 73d9775 commit 1235d9f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/fcio.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,11 @@ void fc_init(
fc_textcolor(COLOR_GREEN);
}

static unsigned char swp;
unsigned char fc_nyblswap(unsigned char in) // oh why?!
{
swp = in;
#ifdef __CC65__
static unsigned char swp;
swp = in;
__asm__("lda %v", swp);
__asm__("asl a");
__asm__("adc #$80");
Expand All @@ -204,21 +204,20 @@ unsigned char fc_nyblswap(unsigned char in) // oh why?!
__asm__("adc #$80");
__asm__("rol a");
__asm__("sta %v", swp);
return swp;
#elif defined(__clang__)
#pragma GCC warning "LLVM assembly needs to be checked in fc_nyblswap()"
asm volatile("ld%0\n"
"asl a\n"
asm volatile("asl a\n"
"adc #$80\n"
"rol a\n"
"asl a\n"
"adc #$80\n"
"rol a\n"
"st%0"
: "+a"(swp));
: "+a"(in));
return in;
#else
#pragma GCC warning "fc_nyblswap() is not implemented for this compiler"
return in;
#endif
return swp;
}

void fc_flash(byte f)
Expand Down

0 comments on commit 1235d9f

Please sign in to comment.