-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy paths192hex8_offset0x8000_even.c
282 lines (228 loc) · 6.01 KB
/
s192hex8_offset0x8000_even.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
// [TURBO9_HEADER_START]
//////////////////////////////////////////////////////////////////////////////
// Turbo9 Microprocessor IP
//////////////////////////////////////////////////////////////////////////////
// Website: www.turbo9.org
// Contact: team[at]turbo9[dot]org
//////////////////////////////////////////////////////////////////////////////
// [TURBO9_LICENSE_START]
// BSD-1-Clause
//
// Copyright (c) 2020-2023
// Kevin Phillipson
// Michael Rywalt
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// [TURBO9_LICENSE_END]
//////////////////////////////////////////////////////////////////////////////
// Engineer: Kevin Phillipson
// Description: s19 to hex file converter
//
//////////////////////////////////////////////////////////////////////////////
// History:
// 07.14.2023 - Kevin Phillipson
// File header added
//
//////////////////////////////////////////////////////////////////////////////
// [TURBO9_HEADER_END]
/*
; --==========================> Gator uProccessor <===========================--
; -- File: s192hex8.c
; -- Engineer: Kevin Phillipson
; -- Date: 03.28.07
; -- Revision: 10.03.20
; -- Description:
;
; THIS IS OLD CODE AND SHOULD PROBABLY BE REWRITTEN, BUT IT WORKS.
;
; --==========================================================================--
*/
#include <stdio.h>
#include <string.h>
#define WIDTH 8
#define BUF_SIZE 16
#define MEM_OFFSET 0x8000
#define MEM_END 0xFFFF
#define MEM_SIZE 0x10000
typedef unsigned char u08;
typedef signed char s08;
typedef unsigned short u16;
typedef signed short s16;
typedef unsigned long u32;
typedef signed long s32;
u08 hex2bin(u08 hex_digit);
u08 bin2hex(u08 nibble);
s16 load_buffer(void);
void crlf(void);
void lf(void);
u08 buffer[BUF_SIZE];
s16 eof_buf[BUF_SIZE];
int main(void)
{
u32 addr_idx = 0;
u32 idx = 0;
u08 num_bytes;
u08 tmp;
u16 hex_file_addr;
u32 hex_file_depth = 0;
u32 raw_idx = 0;
u32 raw_addr[MEM_SIZE];
u08 raw_data[MEM_SIZE];
s08 flush;
u08 state = 0;
for (idx = 0; idx < MEM_SIZE; idx++)
raw_addr[idx] = 0xFFFFFFFF; // Mark as unused
for (idx = 0; idx < BUF_SIZE; idx++)
buffer[idx] = 0x00;
for (idx = 0; idx < BUF_SIZE; idx++)
eof_buf[idx] = 0x00;
while (load_buffer() != EOF)
{
flush = 0;
switch(state)
{
case 0:
if (strncmp(buffer,"S1",2) == 0)
{
num_bytes = (hex2bin(buffer[2]) << 4) +
(hex2bin(buffer[3])) - 3;
hex_file_addr = (hex2bin(buffer[4]) << 12) +
(hex2bin(buffer[5]) << 8) +
(hex2bin(buffer[6]) << 4) +
(hex2bin(buffer[7]));
flush = 8;
state = 1;
}
break;
case 1:
if (num_bytes != 0)
{
if (hex_file_addr > hex_file_depth)
{
hex_file_depth = hex_file_addr;
}
raw_addr[raw_idx] = hex_file_addr;
raw_data[raw_idx] = (hex2bin(buffer[0]) << 4) +
(hex2bin(buffer[1]));
raw_idx++;
hex_file_addr++;
num_bytes--;
flush = 2;
if (num_bytes == 0)
{
state = 0;
}
}
else
{
state = 0;
}
break;
default:
state = 0;
break;
}
for (idx = 1; idx < flush; idx++)
load_buffer();
}
for (addr_idx = MEM_OFFSET; addr_idx <= MEM_END; addr_idx++)
{
// DEADBEEF
switch(addr_idx % 4)
{
case 0:
tmp = 0xDE;
break;
case 1:
tmp = 0xAD;
break;
case 2:
tmp = 0xBE;
break;
default:
tmp = 0xEF;
break;
}
for (idx = 0; idx < raw_idx; idx++)
{
if (raw_addr[idx] == addr_idx)
tmp = raw_data[idx];
}
if ((addr_idx&0x00000001) == 0) //even
{
putchar(bin2hex((tmp >> 4) & 0x0F));
putchar(bin2hex((tmp >> 0) & 0x0F));
lf();
}
}
return(0);
}
s16 load_buffer(void)
{
s16 tmp;
for (tmp = 0; tmp < BUF_SIZE-1; tmp++)
buffer[tmp] = buffer[tmp+1];
for (tmp = 0; tmp < BUF_SIZE-1; tmp++)
eof_buf[tmp] = eof_buf[tmp+1];
if (eof_buf[BUF_SIZE-1] != EOF) //
{
tmp = getchar();
//make ucase
if((tmp >= 0x61) && (tmp <= 0x7A))
tmp = tmp - 0x20;
}
else
{
tmp = EOF;
}
buffer[BUF_SIZE-1] = tmp;
eof_buf[BUF_SIZE-1] = tmp;
return eof_buf[0];
}
void lf(void)
{
putchar(0x0A);
}
void crlf(void)
{
putchar(0x0D);
putchar(0x0A);
}
u08 hex2bin(u08 hex_digit)
{
u08 nibble;
if ((hex_digit >= 0x30) && (hex_digit <= 0x39))
nibble = hex_digit - 0x30;
else
if ((hex_digit >= 0x41) && (hex_digit <= 0x46))
nibble = hex_digit - 0x37;
else
nibble = 0xFF;
return nibble;
}
u08 bin2hex(u08 nibble)
{
u08 hex_digit;
if (nibble < 0x0A)
hex_digit = nibble + 0x30;
else
hex_digit = nibble + 0x37;
return hex_digit;
}