-
Notifications
You must be signed in to change notification settings - Fork 1
/
pnp.py
executable file
·182 lines (150 loc) · 4.13 KB
/
pnp.py
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
#!/usr/bin/python
#~ Source file
source = 'testeur_UM.pnp'
#~ Floppy disk
#~ disk = '/dev/fd0'
disk = 'biscotte'
#~ Use Bank
bank = 'bank4'
#~ Y axis direction
yaxisdir = -1
#~ Loops
loops = 1
#~ Added lines
addLines = 3+loops
#~ Precidot or Nova
target = "nova"
#~ Bank address
hexAddr = {}
hexAddr['bank1'] = 0x04000
hexAddr['bank2'] = 0x16206
hexAddr['bank3'] = 0x28206
hexAddr['bank4'] = 0x3A000
#~ package to magasin
pack2Mag = {}
pack2Mag['SO08'] = 1
pack2Mag['SO12'] = 2
pack2Mag['SO14'] = 3
pack2Mag['SO16'] = 4
pack2Mag['SO20'] = 5
pack2Mag['SO24'] = 6
pack2Mag['SO28'] = 7
pack2Mag['SOT23'] = 8
pack2Mag['SOT89'] = 9
pack2Mag['SOT143'] = 10
pack2Mag['SOT194'] = 11
pack2Mag['SOT223'] = 12
pack2Mag['SOD80'] = 13
pack2Mag['SOD87'] = 14
pack2Mag['0805'] = 15
pack2Mag['1206'] = 16
pack2Mag['1210'] = 17
pack2Mag['1812'] = 18
pack2Mag['2220'] = 19
#~ =====================================================================
def intToHex(i):
ret = []
ret.append(format("%02X" % (int(i) & 0x00ff)))
ret.append(format("%02X" % ((int(i)/0xff) & 0xff)))
return ret
def hexToInt(lbx,hbx):
lb = int(ord(lbx))
hb = int(ord(hbx))
return [lb+hb*256,lb,hb]
#~ =====================================================================
def writeToFloppy(t):
for i in range(0,len(t)):
h = intToHex(t[i])
f.write(h[0].decode("hex"))
f.write(h[1].decode("hex"))
def pushDots(data):
#~ Write to floppy
f.seek(hexAddr[bank],ABSOLUTE)
f.seek(0x208,RELATIVE)
for i in range(0,loops):
writeToFloppy([0,0,0,0])
writeToFloppy([0,10,0,0])
writeToFloppy([0,1,loops,0])
for n in range(0,len(data)):
#~ Inverse Y axis if needed
data[n][1] = yaxisdir * data[n][1]
writeToFloppy(data[n])
writeToFloppy([0,2,0,0])
#~ Nb lignes
f.seek(hexAddr[bank],ABSOLUTE)
f.seek(0x32,RELATIVE)
writeToFloppy([len(data)+addLines,len(data)+addLines])
def pushComp(data):
#~ Write to floppy
f.seek(hexAddr[bank],ABSOLUTE)
f.seek(0x208,RELATIVE)
for i in range(0,loops):
writeToFloppy([0,0,0,0])
writeToFloppy([0,10,0,0])
writeToFloppy([0,1,loops,0])
for n in range(0,len(data)):
#~ Inverse Y axis if needed
data[n][1] = yaxisdir * data[n][1]
writeToFloppy(data[n])
writeToFloppy([0,2,0,0])
#~ Nb lignes
f.seek(hexAddr[bank],ABSOLUTE)
f.seek(0x32,RELATIVE)
writeToFloppy([len(data)+addLines,len(data)+addLines])
#~ =====================================================================
#~ Imports
import sys
import re
import pprint
#~ Pretty Print
pp = pprint.PrettyPrinter(indent=4)
#~ Constants
ABSOLUTE = 0
RELATIVE = 1
#~ Floppy dev
f = open(disk,'rw+')
#~ Eagle RegExp
p = re.compile('^-composant-(.+)-package-(.+)-X-(.+)-Y-(.*)-rot-(.*)$')
p2 = re.compile('^-Pin--X-(.+)-Y-(.*)$')
#~ Get Eagle file lines
lines = [line.strip() for line in open(source)]
composants = {}
pins = []
#~ Read Lines
for line in lines:
line = line.rstrip()
if "-composant-" in line:
m = p.match(line)
if m:
comp = m.group(1)
composants[comp]=list(m.group(2,5,3,4))
if ( composants[comp][0] in pack2Mag.keys() ):
composants[comp][0] = pack2Mag[composants[comp][0]]
else:
print "no pack "+composants[comp][0]+" in bank, remove item "+comp
del(composants[comp])
else:
print "Ignored line: "+line
if "-Pin-" in line:
m = p2.match(line)
if m:
pins.append(list((1,200)+m.group(1,2)))
else:
print "Ignored line: "+line
#~ Print Pins
#~ Write to Floppy
if ( target == "precidot" ):
pushDots(pins)
else:
pp.pprint(composants)
pushComp(composants.values())
#~ Read the floppy to check the result
#~ f.seek(hexAddr[bank],ABSOLUTE)
#~ f.seek(0x208,RELATIVE)
#~ for pinid in range(0,len(pins)+addLines):
#~ sys.stdout.write("0x%04X = " % (pinid*4))
#~ for i in range(0,4):
#~ val = hexToInt(f.read(1),f.read(1))
#~ sys.stdout.write(" - %6d [%02X,%02X]" % ( val[0], val[1], val[2]))
#~ print ""
f.close()