#include <stdio.h>

int get_address(char *self, char *arg) {
	unsigned int got;

	if(sscanf(arg, "0x%x", &got) != 1)
		if(sscanf(arg, "$%x", &got) != 1)
			if(sscanf(arg, "%d", &got) != 1) {
				fprintf(stderr, "Invalid address '%s'\n", arg);
				return -1;
			}

	if(got >= 0x10000) {
		if(self) fprintf(stderr, "%s: ", self);
		fprintf(stderr, "Address '%s' not in range $0000-$FFFF\n", arg);
		return -1;
	}

	return (int)got;
}


