summaryrefslogtreecommitdiffstats
path: root/pcm-asm/pcm-asm.c
blob: 665f3447761a3ed2173926b567b582ea8808313b (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (C) 2016-2017 Paul Kocialkowski <contact@paulk.fr>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <pcm/pcm.h>
#include "pcm-asm.h"

struct pcm_ops pcm_ops = {
	.asm_write = pcm_asm_write,
	.disasm_write = NULL,
	.data = NULL,
};

int pcm_asm_write(void *data, unsigned int value, char *mnemonic)
{
	binary_print(value);
	printf("0x%08x ; %s\n", value, mnemonic);

	return 0;
}

int main(int argc, char *argv[])
{
	unsigned int count;
	unsigned int i;
	int rc;

	if (argc < 2)
		return 1;

	rc = pcm_ops_register(&pcm_ops);
	if (rc < 0) {
		fprintf(stderr, "Unable to set PCM OPS\n");
		return 1;
	}

	count = argc - 1;
	i = 1;

	while (count > 0) {
		rc = pcm_op_asm(&argv[i], count);
		if (rc < 0) {
			fprintf(stderr, "Unknown or incomplete mnemonic: %s\n", argv[i]);
			return 1;
		}

		count -= 1 + rc;
		i += 1 + rc;

		if (count > 0)
			printf("\n");
	}

	return 0;
}