smartboard: add safeguards for invalid read

This commit is contained in:
hap 2021-04-16 16:48:22 +02:00
parent 2bf61d8078
commit 50c0632bfb
3 changed files with 22 additions and 13 deletions

View File

@ -36,6 +36,7 @@ notes:
TODO:
- bootrom disable timer shouldn't be needed, real ARM has already fetched the next opcode
- sound is too high pitched, same problem as in risc2500
- "disable leds" setting breaks smartboard controls
******************************************************************************/

View File

@ -225,16 +225,21 @@ uint8_t tasc_sb30_device::spawn_cb(offs_t offset)
uint8_t tasc_sb30_device::read()
{
int x = (m_position & 0x3f) / 8;
int y = (m_position & 0x3f) % 8;
int piece_id = m_board->read_sensor(7 - x, 7 - y);
if (m_position < 0x40)
{
int x = 7 - m_position / 8;
int y = 7 - m_position % 8;
int piece_id = m_board->read_sensor(x, y);
// each piece is identified by a single bit in a 32-bit sequence, if multiple bits are active the MSB is used
uint32_t sb30_id = 0;
if (piece_id > 0)
sb30_id = 1UL << (piece_id - 1);
// each piece is identified by a single bit in a 32-bit sequence, if multiple bits are active the MSB is used
uint32_t sb30_id = 0;
if (piece_id > 0)
sb30_id = 1UL << (piece_id - 1);
return BIT(sb30_id, m_shift & 0x1f);
return BIT(sb30_id, m_shift & 0x1f);
}
return 0;
}
void tasc_sb30_device::write(uint8_t data)
@ -244,15 +249,18 @@ void tasc_sb30_device::write(uint8_t data)
if (BIT(data, 6) && !BIT(m_data, 6))
{
int x = (m_position & 0x3f) / 8;
int y = (m_position & 0x3f) % 8;
m_out_leds[y][x] = BIT(data, 7);
if (m_position < 0x40)
{
int x = m_position / 8;
int y = m_position % 8;
m_out_leds[y][x] = BIT(data, 7);
}
}
if (!BIT(data, 7) && BIT(m_data, 7))
{
m_position++;
if (m_position & 0x40)
if (m_position >= 0x40)
{
m_shift++;
if (m_position & 1)

View File

@ -47,7 +47,7 @@ private:
output_finder<8,8> m_out_leds;
emu_timer * m_leds_off_timer;
uint8_t m_data;
uint8_t m_position;
uint32_t m_position;
uint8_t m_shift;
};