2 ## This file is part of the libsigrokdecode project.
4 ## Copyright (C) 2018 fenugrec <fenugrec@users.sourceforge.net>
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation; either version 2 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program; if not, see <http://www.gnu.org/licenses/>.
20 # TODO: Make A12 optional; it's here because of an instrument (HP3478A) that
21 # drives a generic I/O pin to access 8kB of ROM; the MCS-48 only has a 4kB
24 import sigrokdecode as srd
26 class ChannelError(Exception):
29 class Decoder(srd.Decoder):
33 longname = 'Intel MCS-48'
34 desc = 'Intel MCS-48 external memory access protocol.'
42 'desc': 'CPU data line %d' % i
47 'desc': 'CPU address line %d' % i
48 } for i in range(8, 13)
50 {'id': 'ale', 'name': 'ALE', 'desc': 'Address latch enable'},
51 {'id': 'psen', 'name': '/PSEN', 'desc': 'Program store enable'},
54 ('romdata', 'Address:Data'),
57 ('romdata', 'AAAA:DD'),
66 # Flag to make sure we get an ALE pulse first.
70 self.out_ann = self.register(srd.OUTPUT_ANN)
71 self.out_bin = self.register(srd.OUTPUT_BINARY)
73 def newaddr(self, pins):
74 # Falling edge on ALE: reconstruct address.
78 tempaddr |= pins[i] << i
80 self.addr_s = self.samplenum
82 def newdata(self, pins):
83 # Edge on PSEN: get data.
86 tempdata |= pins[i] << i
88 self.data_s = self.samplenum
90 self.put(self.addr_s, self.samplenum, self.out_ann,
91 [0, ['%04X:' % self.addr + '%02X' % self.data]])
92 self.put(self.addr_s, self.samplenum, self.out_bin,
93 [0, bytes([(self.addr >> 8) & 0xFF, self.addr & 0xFF, self.data])])
96 # Sample address on the falling ALE edge.
97 # Save data on falling edge of PSEN.
99 pins = self.wait([{13: 'f'}, {14: 'r'}])
100 # Handle those conditions (one or more) that matched this time.
102 self.newaddr(pins[0:])
104 self.newdata(pins[0:])