Use the volatile keyword with all inline assembly to make sure the optimizer does not discard any of it.

This commit is contained in:
Jeremy Rand 2018-10-21 14:29:18 -04:00
parent 204e9c119a
commit 70189e1567
4 changed files with 18 additions and 18 deletions

View File

@ -74,7 +74,7 @@ static char displayBuffer[] =
static void playSound(int8_t freq, int8_t duration) static void playSound(int8_t freq, int8_t duration)
{ {
while (duration > 0) { while (duration > 0) {
asm ("STA %w", 0xc030); asm volatile ("STA %w", 0xc030);
while (freq > 0) { while (freq > 0) {
freq--; freq--;
} }
@ -365,13 +365,13 @@ static tAction getNextAction(void)
void textMode(void) void textMode(void)
{ {
clrscr(); clrscr();
asm ("STA %w", 0xc051); asm volatile ("STA %w", 0xc051);
} }
void graphicsMode(void) void graphicsMode(void)
{ {
asm ("STA %w", 0xc050); asm volatile ("STA %w", 0xc050);
} }
@ -479,7 +479,7 @@ void redrawUI(void)
} }
// Mixed text and graphics mode // Mixed text and graphics mode
asm ("STA %w", 0xc053); asm volatile ("STA %w", 0xc053);
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printState(); printState();
} }

View File

@ -30,11 +30,11 @@ static uint8_t joystickTemp;
static bool isButtonPressed(int8_t buttonNum) static bool isButtonPressed(int8_t buttonNum)
{ {
if (buttonNum) { if (buttonNum) {
__asm__("LDA %w", BTN1); __asm__ volatile("LDA %w", BTN1);
__asm__("STA %v", joystickTemp); __asm__ volatile("STA %v", joystickTemp);
} else { } else {
__asm__("LDA %w", BTN0); __asm__ volatile("LDA %w", BTN0);
__asm__("STA %v", joystickTemp); __asm__ volatile("STA %v", joystickTemp);
} }
return ((joystickTemp > 127) ? true : false); return ((joystickTemp > 127) ? true : false);
} }
@ -42,22 +42,22 @@ static bool isButtonPressed(int8_t buttonNum)
static uint8_t joystickLeftRight(void) static uint8_t joystickLeftRight(void)
{ {
__asm__("BIT %w", ROM_SWITCH); __asm__ volatile("BIT %w", ROM_SWITCH);
__asm__("LDX #0"); __asm__ volatile("LDX #0");
__asm__("JSR %w", PREAD); __asm__ volatile("JSR %w", PREAD);
__asm__("STY %v", joystickTemp); __asm__ volatile("STY %v", joystickTemp);
__asm__("BIT %w", RAM_SWITCH); __asm__ volatile("BIT %w", RAM_SWITCH);
return joystickTemp; return joystickTemp;
} }
static uint8_t joystickUpDown(void) static uint8_t joystickUpDown(void)
{ {
__asm__("BIT %w", ROM_SWITCH); __asm__ volatile("BIT %w", ROM_SWITCH);
__asm__("LDX #1"); __asm__ volatile("LDX #1");
__asm__("JSR %w", PREAD); __asm__ volatile("JSR %w", PREAD);
__asm__("STY %v", joystickTemp); __asm__ volatile("STY %v", joystickTemp);
__asm__("BIT %w", RAM_SWITCH); __asm__ volatile("BIT %w", RAM_SWITCH);
return joystickTemp; return joystickTemp;
} }

Binary file not shown.