def update_state(self, blocks):
block_version = None
char_offset = None
group_type = None
curr_AB = {0: None, 2: None, None:None}
last_AB = {0: None, 2: None, None:None}
for block in blocks:
blkid = block['ID']
if blkid == "A":
self.PIs.append(block['PI'])
char_offset = None
if blkid == "B":
group_type = block['group_type']
block_version = block['version_AB']
if blkid == "B" and group_type == 0:
curr_AB[group_type] = block['text_AB']
char_offset = block['text_segment'] * 2
if blkid == "B" and group_type == 2:
char_offset = block['text_segment'] * 4
if (curr_AB[group_type] != None) and (block['text_AB'] != curr_AB[group_type]) and (char_offset == 0) and (block_version == 'A'):
print("CLEARING")
self.cur_state[curr_AB[group_type]^1] = ['_']*64
curr_AB[group_type] = block['text_AB']
if (char_offset is not None) and (blkid == "C") and (group_type == 0) and (block_version == 'B'):
self.PIs.append((ord(block['B1'])<<8)+ord(block['B0']))
if char_offset is not None and (blkid == "C") and (group_type == 2):
self.cur_state[curr_AB[group_type]][char_offset] = block['B0']
self.cur_state[curr_AB[group_type]][char_offset+1] = block['B1']
if char_offset is not None and (blkid == "D") and (group_type == 2):
self.cur_state[curr_AB[group_type]][char_offset+2] = block['B0']
self.cur_state[curr_AB[group_type]][char_offset+3] = block['B1']
if (char_offset is not None) and (blkid == "D") and (group_type == 0) and (block_version == 'B'):
self.cur_state[curr_AB[group_type]][char_offset] = block['B0']
self.cur_state[curr_AB[group_type]][char_offset+1] = block['B1']
if (char_offset is not None) and (blkid == "D") and (group_type == 0) and (block_version == 'A'):
self.cur_state[curr_AB[group_type]][char_offset+10] = block['B0']
self.cur_state[curr_AB[group_type]][char_offset+11] = block['B1']
if group_type in (0,2):
#print(blkid, group_type, curr_AB[group_type], block_version)
print(' '.join([str(x) for x in block.values()]))
#print('\n'.join([''.join(x) for x in self.prog_name]))
if blkid == "D":
print('\n'.join([''.join(x) for x in self.cur_state]).replace('\r','?'))
group_type == None
char_offset = None
try:
self.PI = hex(statistics.mode(self.PIs))[2:]
except statistics.StatisticsError:
self.PI = hex(self.PIs[0])[2:]
self.callsign = picode.rdscall(self.PI)
print(self.callsign)