-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbintoasm.c
103 lines (77 loc) · 2.06 KB
/
bintoasm.c
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* BinToAsm.c
Converts a binary file into an assembler file for Z80.
Copyright (C) 2004-2015 Miguel I. Garcia Lopez, FloppySoftware
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 2, 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, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
To compile with MESCC:
cc bintoasm
ccopt bintoasm.zsm
zsm bintoasm
hextocom bintoasm
Revisions:
22 Feb 2004 : v1.00
03 Apr 2007 : v1.01 / Minor changes.
10 Apr 2007 : Output 8 bytes in a line instead of 16.
15 May 2007 : v1.02 / Added title & usage help.
04 Sep 2015 : v1.03 / Amended some messages and comments.
*/
#include <mescc.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <fileio.h>
#include <printf.h>
#include <fprintf.h>
#define VERSION "1.03 / 04 Sep 2015\n\n(c) 2004-2015 FloppySoftware"
FILE *fpi, *fpo;
int data, chpos;
unsigned counter;
main(argc, argv)
int argc, argv[];
{
printf("BinToAsm v%s\n\n", VERSION);
if(argc!=3)
{
printf("Usage: bintoasm binfile asmfile\n");
exit(1);
}
if((fpi=fopen(argv[1],"rb"))==NULL)
error("Opening input file");
if((fpo=fopen(argv[2],"w"))==NULL)
error("Opening output file");
counter=chpos=0;
while((data=fgetc(fpi))!=EOF)
{
if(!chpos)
fprintf(fpo, " DEFB");
fprintf(fpo, " %03d", data);
if(++chpos!=8)
fprintf(fpo, ",");
else
{
fprintf(fpo, "\n");
chpos=0;
}
++counter;
}
printf("%d bytes\n", counter);
if(fclose(fpi))
error("Closing input file");
if(fclose(fpo))
error("Closing output file");
}
error(txt)
char *txt;
{
printf("ERROR: %s\n", txt);
exit(1);
}