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 import sigrokdecode as srd
22 class ChannelError(Exception):
25 class Decoder(srd.Decoder):
29 longname = 'Intel MCS-48'
30 desc = 'Intel MCS-48 external memory access protocol.'
34 tags = ['Retro computing']
36 {'id': 'ale', 'name': 'ALE', 'desc': 'Address latch enable'},
37 {'id': 'psen', 'name': '/PSEN', 'desc': 'Program store enable'},
41 'desc': 'CPU data line %d' % i
42 } for i in range(0, 8)
46 'desc': 'CPU address line %d' % i
47 } for i in range(8, 12)
49 optional_channels = tuple({
52 'desc': 'CPU address line %d' % i
53 } for i in range(12, 13)
56 ('romdata', 'Address:Data'),
59 ('romdata', 'AAAA:DD'),
61 OFF_ALE, OFF_PSEN = 0, 1
62 OFF_DATA_BOT, OFF_DATA_TOP = 2, 10
63 OFF_ADDR_BOT, OFF_ADDR_TOP = 10, 14
64 OFF_BANK_BOT, OFF_BANK_TOP = 14, 15
75 # Flag to make sure we get an ALE pulse first.
79 self.out_ann = self.register(srd.OUTPUT_ANN)
80 self.out_bin = self.register(srd.OUTPUT_BINARY)
82 def newaddr(self, addr, data):
83 # Falling edge on ALE: reconstruct address.
85 addr = sum([bit << i for i, bit in enumerate(addr)])
87 addr |= sum([bit << i for i, bit in enumerate(data)])
89 self.addr_s = self.samplenum
91 def newdata(self, data):
92 # Edge on PSEN: get data.
93 data = sum([bit << i for i, bit in enumerate(data)])
95 self.data_s = self.samplenum
97 anntext = '{:04X}:{:02X}'.format(self.addr, self.data)
98 self.put(self.addr_s, self.data_s, self.out_ann, [0, [anntext]])
99 bindata = self.addr.to_bytes(2, byteorder='big')
100 bindata += self.data.to_bytes(1, byteorder='big')
101 self.put(self.addr_s, self.data_s, self.out_bin, [0, bindata])
104 # Address bits above A11 are optional, and are considered to be A12+.
105 # This logic needs more adjustment when more bank address pins are
106 # to get supported. For now, having just A12 is considered sufficient.
107 has_bank = self.has_channel(self.OFF_BANK_BOT)
108 bank_pin_count = 1 if has_bank else 0
109 # Sample address on the falling ALE edge.
110 # Save data on falling edge of PSEN.
112 pins = self.wait([{self.OFF_ALE: 'f'}, {self.OFF_PSEN: 'r'}])
113 data = pins[self.OFF_DATA_BOT:self.OFF_DATA_TOP]
114 addr = pins[self.OFF_ADDR_BOT:self.OFF_ADDR_TOP]
115 bank = pins[self.OFF_BANK_BOT:self.OFF_BANK_TOP]
117 addr += bank[:bank_pin_count]
118 # Handle those conditions (one or more) that matched this time.
120 self.newaddr(addr, data)