~swisschili/toolchain-6502

ref: 6a923012793c195cbc1bdbd5e4d6f6c3b680f37b toolchain-6502/as/main.c -rw-r--r-- 760 bytes
6a923012swissChili Build .deb package, try to fix endianness issues 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "as.h"

#include <stdio.h>
#include <stdlib.h>
#include <bits/getopt_core.h>
#include <unistd.h>

int main(int argc, char **argv)
{
	char c;
	FILE *in = stdin,
		*out = stdout;

	while ((c = getopt(argc, argv, "i:o:")) != -1)
	{
		switch (c)
		{
		case 'i':
			in = fopen(optarg, "r");
			break;
		case 'o':
			out = fopen(optarg, "w");
			break;
		case 'h':
		case '?':
			printf("6502 assembler\n"
				   "Usage:\n"
				   "    -i <input> set input file (default stdin)\n"
				   "    -o <output> set output file (default stdout)\n");
		}
	}

	fseek(in, 0, SEEK_END);
	ssize_t len = ftell(in);
	fseek(in, 0, SEEK_SET);

	char *text = malloc(len + 1);
	fread(text, len, 1, in);
	text[len] = 0;

	uint32_t built = assemble(text, out);

	free(text);
}