Skip to content

Instantly share code, notes, and snippets.

@drdnar
Created October 8, 2021 19:47
Show Gist options
  • Save drdnar/8d35755c132a4c4d2a02050b1b8dca75 to your computer and use it in GitHub Desktop.
Save drdnar/8d35755c132a4c4d2a02050b1b8dca75 to your computer and use it in GitHub Desktop.
Use clang's inline assembly support to wrap eZ80 LDIR directly
/**
* Wraps eZ80 LDIR instruction.
* @param destination Target address, e.g. &somearr[i - 2]
* @param source Source address, e.g. &somearr[i]
* @param count Number of bytes to move
* @example #define VRAM ((uint16_t*)0xD40000)
* *VRAM = 12345; // Set first word of VRAM
* _ldir(VRAM+1, VRAM, LCD_WIDTH * LCD_HEIGHT - 1); // Copy remaining pixels with LDIR
*/
static inline void _ldir(void* destination, const void* source, size_t count)
{
if (count)
__asm__("ldir"
:
: "l"(source), "e"(destination), "c"(count)
: "a", "cc"
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment