summaryrefslogblamecommitdiffstats
path: root/src/emu/asm.c
blob: caca72a51247895ebaa2e729e790c322e642df05 (plain) (tree)
































                                                                                                         
#include <stdio.h>
#include <stdint.h>

#include "cpu.h"
#include "log.h"
#include "opc.h"

uint32_t compile(const char *line)
{
	char mnem[4];
	int32_t a = 0, b = 0, c = 0;

	/* arithmetic & logic */
	if (sscanf(line, "%3s r%2d, r%2d, r%2d", mnem, &a, &b, &c) == 4)
		return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | ((c & 0x1F) << 11);

	/* load/store & branch */
	if (sscanf(line, "%3s r%2d, r%2d, %d", mnem, &a, &b, &c) == 4)
		return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | (c & 0xFFFF);

	if (sscanf(line, "%3s r%2d, %d", mnem, &b, &c) == 3)
		return mnemonic2opc(mnem) | ((b & 0x1F) << 16) | (c & 0xFFFF);

	/* jump */
	if (sscanf(line, "%3s r%2d", mnem, &a) == 2)
		return mnemonic2opc(mnem) | ((a & 0x1F) << 21);

	/* misc */
	if (sscanf(line, "%3s", mnem) == 1)
		return mnemonic2opc(mnem);

	return 0xFFFFFFFF;
}