summaryrefslogtreecommitdiff
path: root/devel/as31/patches/patch-aa
blob: 10b369a4fbff0f02b98026a2aea67f642476b0e1 (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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
$NetBSD: patch-aa,v 1.2 2012/07/03 18:13:26 joerg Exp $

--- emitter.c.orig	2012-07-03 10:49:15.000000000 +0000
+++ emitter.c
@@ -19,6 +19,8 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 /* ----------------------------------------------------------------------
  * DECLARE your own open(), close(), addr(), and byte() routines here.
@@ -30,6 +32,8 @@ static int open2(), close2(), addr2(), b
 static int open3(), close3(), addr3(), byte3();
 static int open4(), close4(), addr4(), byte4();
 
+void dumpline(unsigned long, unsigned char *, int);
+
 /* ----------------------------------------------------------------------
  * ADD an entry to this table to register your
  * output format routines. Give your object format
@@ -67,8 +71,8 @@ emitusage()
 	fprintf(stderr, ".\n");
 }
 
-emitopen(file,ftype,arg)
-char *file,*ftype,*arg;
+void
+emitopen(char *file, char *ftype, char *arg)
 {
 	int i;
 	if( ftype ) {
@@ -94,14 +98,12 @@ emitclose()
 	(*formtab[format].e_close)();
 }
 
-emitaddr(a)
-unsigned long int a;
+void emitaddr(unsigned long a)
 {
 	(*formtab[format].e_addr)(a);
 }
 
-emitbyte(b)
-int b;
+void emitbyte(int b)
 {
 	(*formtab[format].e_byte)(b);
 }
@@ -180,9 +182,9 @@ unsigned char b;
 		if( pos != -666 ) fprintf(fout,"\n");
 		newaddr = 0;
 		pos = 15;
-		fprintf(fout,"%06x: ",addr+offset);
+		fprintf(fout,"%06lx: ",addr+offset);
 	} else if( pos == 15 ) {
-		fprintf(fout,"%06x: ",addr+offset);
+		fprintf(fout,"%06lx: ",addr+offset);
 	}
 
 	fprintf(fout,"%02x ", b&0xff );
@@ -225,7 +227,7 @@ unsigned long int a;
 static byte2(b)
 unsigned char b;
 {
-	fprintf(fout,"%04x: %02x\n", addr, b&0xff );
+	fprintf(fout,"%04lx: %02x\n", addr, b&0xff );
 	addr += 1;
 }
 
@@ -283,6 +285,7 @@ unsigned char b;
 	addr += 1;
 }
 
+void
 dumpline(a,b,len)
 unsigned long a;
 unsigned char *b;
@@ -292,7 +295,7 @@ int len;
 
 	if(len <= 0 ) return;
 
-	fprintf(fout,"%04x: ",a);
+	fprintf(fout,"%04lx: ",a);
 
 	for(i=0; i<8; i++ ) {
 		if( i <= len )
@@ -394,32 +397,47 @@ static byte4(b)
 	}
 }
 
+srec_wrbyte(byte)
+{
+	check4 += byte;
+	fprintf(fout, "%02X", byte & 0xff);
+}
+
 finishline()
 {
 	int i;
 
-	check4 = index4 + (address4 & 0xff) + ((address4>>8) & 0xff) + 4;
+	check4 = 0;
 
 	switch(format4) {
 	case '2':
-		fprintf(fout, "S1%02X%04X", index4 + 4,	address4 & 0xffff);
+		fprintf(fout, "S1");
+		srec_wrbyte(index4 + 2 + 1);
+		srec_wrbyte(address4 >> 8);
+		srec_wrbyte(address4);
 		break;
 	case '3':
-		fprintf(fout, "S2%02X%06X", index4 + 6, address4 & 0xffffff);
-		check4 += ((address4>>16) & 0xff) + 2;
+		fprintf(fout, "S2");
+		srec_wrbyte(index4 + 3 + 1);
+		srec_wrbyte(address4 >> 16);
+		srec_wrbyte(address4 >> 8);
+		srec_wrbyte(address4);
 		break;
 	case '4':
-		fprintf(fout, "S3%02X%08X", index4 + 8, address4);
-		check4 += ((address4>>16) & 0xff) +((address4>>24) & 0xff) + 4;
+		fprintf(fout, "S3");
+		srec_wrbyte(index4 + 4 + 1);
+		srec_wrbyte(address4 >> 24);
+		srec_wrbyte(address4 >> 16);
+		srec_wrbyte(address4 >> 8);
+		srec_wrbyte(address4);
 		break;
 	}
 
-	for(i=0; i<index4; i++) {
-		fprintf(fout, "%02X", buf4[i] & 0xff);
-		check4 += buf4[i];
-	}
+	for(i=0; i<index4; i++)
+		srec_wrbyte(buf4[i]);
 
-	fprintf(fout, "%02X\n", (~check4 & 0xff) );
+	srec_wrbyte(~check4);
+	fprintf(fout, "\n");
 	index4 = 0;
 }