Mercurial > hg > Members > kono > os9 > sbc09
comparison src/makerom.c @ 57:2088fd998865
sbc09 directry clean up
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 23 Jul 2018 16:07:12 +0900 |
parents | makerom.c@9a224bd9b45f |
children | ef5959682d03 |
comparison
equal
deleted
inserted
replaced
56:4fa2bdb0c457 | 57:2088fd998865 |
---|---|
1 /* makerom.c | |
2 Read standard input as S-records and build ROM image file v09.rom | |
3 ROM starts at 0x8000 and is 32K. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <strings.h> | |
9 | |
10 static int sum,charindex; | |
11 unsigned char mem[0x8000]; | |
12 char linebuf[130]; | |
13 | |
14 void | |
15 hexerr() | |
16 { | |
17 fprintf(stderr,"Illegal character in hex number\n"); | |
18 exit(1); | |
19 } | |
20 | |
21 int gethex() | |
22 { | |
23 int c; | |
24 c=linebuf[charindex++]; | |
25 if(c<'0')hexerr(); | |
26 if(c>'9') { if(c<'A')hexerr();else c-=7; } | |
27 c-='0'; | |
28 return c; | |
29 } | |
30 | |
31 int getbyte() | |
32 { | |
33 int b; | |
34 b=gethex(); | |
35 b=b*16+gethex(); | |
36 sum=(sum+b)&0xff; | |
37 return b; | |
38 } | |
39 | |
40 int | |
41 main() | |
42 { | |
43 FILE *romfile; | |
44 unsigned int i,length,addr; | |
45 for(i=0;i<0x8000;i++)mem[i]=0xff; /*set unused locations to FF */ | |
46 for(;;) { | |
47 if(fgets(linebuf,128,stdin)==NULL)break; | |
48 if(strlen(linebuf))linebuf[strlen(linebuf)]=0; | |
49 if(linebuf[0]=='S'&&linebuf[1]=='1') { | |
50 sum=0;charindex=2; | |
51 length=getbyte(); | |
52 if(length<3) { | |
53 fprintf(stderr,"Illegal length in data record\n"); | |
54 exit(1); | |
55 } | |
56 addr=getbyte(); | |
57 addr=(addr<<8)+getbyte(); | |
58 if((long)addr+length-3>0x10000||addr<0x8000) { | |
59 fprintf(stderr,"Address 0x%x out of range\n",addr); | |
60 exit(1); | |
61 } | |
62 for(i=0;i!=length-3;i++)mem[addr-0x8000+i]=getbyte(); | |
63 getbyte(); | |
64 if(sum!=0xff) { | |
65 fprintf(stderr,"Checksum error\n"); | |
66 exit(1); | |
67 } | |
68 } | |
69 } | |
70 romfile=fopen("v09.rom","wb"); | |
71 if(!romfile) { | |
72 fprintf(stderr,"Cannot create file v09.rom\n"); | |
73 exit(1); | |
74 } | |
75 fwrite(mem,0x8000,1,romfile); | |
76 fclose(romfile); | |
77 exit(0); | |
78 } |