memory handling changes:

- no assert when accessing memory beyond boundaries, bus should take
  care of this

- getting (slowly) rid of camelcasing
This commit is contained in:
folkert van heusden 2024-04-29 22:43:53 +02:00
parent a2acf902c7
commit b139ddfd92
Signed by untrusted user who does not match committer: folkert
GPG key ID: 6B6455EDFEED3BD1
4 changed files with 18 additions and 18 deletions

16
bus.cpp
View file

@ -525,9 +525,9 @@ uint16_t bus::read(const uint16_t addr_in, const word_mode_t word_mode, const rm
uint16_t temp = 0; uint16_t temp = 0;
if (word_mode == wm_byte) if (word_mode == wm_byte)
temp = m->readByte(m_offset); temp = m->read_byte(m_offset);
else else
temp = m->readWord(m_offset); temp = m->read_word(m_offset);
if (!peek_only) DOLOG(debug, false, "READ from %06o/%07o %c %c: %o (%s)", addr_in, m_offset, space == d_space ? 'D' : 'I', word_mode == wm_byte ? 'B' : 'W', temp, mode_selection == rm_prev ? "prev" : "cur"); if (!peek_only) DOLOG(debug, false, "READ from %06o/%07o %c %c: %o (%s)", addr_in, m_offset, space == d_space ? 'D' : 'I', word_mode == wm_byte ? 'B' : 'W', temp, mode_selection == rm_prev ? "prev" : "cur");
@ -1039,9 +1039,9 @@ write_rc_t bus::write(const uint16_t addr_in, const word_mode_t word_mode, uint1
} }
if (word_mode == wm_byte) if (word_mode == wm_byte)
m->writeByte(m_offset, value); m->write_byte(m_offset, value);
else else
m->writeWord(m_offset, value); m->write_word(m_offset, value);
return { false }; return { false };
} }
@ -1056,7 +1056,7 @@ void bus::writePhysical(const uint32_t a, const uint16_t value)
throw 12; throw 12;
} }
else { else {
m->writeWord(a, value); m->write_word(a, value);
} }
} }
@ -1068,7 +1068,7 @@ uint16_t bus::readPhysical(const uint32_t a)
throw 13; throw 13;
} }
uint16_t value = m->readWord(a); uint16_t value = m->read_word(a);
DOLOG(debug, false, "physicalREAD %06o from %o", value, a); DOLOG(debug, false, "physicalREAD %06o from %o", value, a);
@ -1092,7 +1092,7 @@ void bus::writeWord(const uint16_t a, const uint16_t value, const d_i_space_t s)
uint8_t bus::readUnibusByte(const uint32_t a) uint8_t bus::readUnibusByte(const uint32_t a)
{ {
uint8_t v = m->readByte(a); uint8_t v = m->read_byte(a);
DOLOG(debug, false, "readUnibusByte[%08o]=%03o", a, v); DOLOG(debug, false, "readUnibusByte[%08o]=%03o", a, v);
return v; return v;
} }
@ -1100,5 +1100,5 @@ uint8_t bus::readUnibusByte(const uint32_t a)
void bus::writeUnibusByte(const uint32_t a, const uint8_t v) void bus::writeUnibusByte(const uint32_t a, const uint8_t v)
{ {
DOLOG(debug, false, "writeUnibusByte[%08o]=%03o", a, v); DOLOG(debug, false, "writeUnibusByte[%08o]=%03o", a, v);
m->writeByte(a, v); m->write_byte(a, v);
} }

View file

@ -1,13 +1,14 @@
// (C) 2018-2023 by Folkert van Heusden // (C) 2018-2024 by Folkert van Heusden
// Released under MIT license // Released under MIT license
#if defined(ESP32) #if defined(ESP32)
#include <Arduino.h> #include <Arduino.h>
#endif #endif
#include <string.h> #include <cstring>
#include "memory.h" #include "memory.h"
memory::memory(const uint32_t size) : size(size) memory::memory(const uint32_t size) : size(size)
{ {
#if defined(ESP32) #if defined(ESP32)

View file

@ -2,8 +2,7 @@
// Released under MIT license // Released under MIT license
#pragma once #pragma once
#include <assert.h> #include <cstdint>
#include <stdint.h>
#include "gen.h" #include "gen.h"
@ -26,9 +25,9 @@ public:
static memory *deserialize(const json_t *const j); static memory *deserialize(const json_t *const j);
#endif #endif
uint16_t readByte(const uint32_t a) const { return m[a]; } uint16_t read_byte(const uint32_t a) const { return m[a]; }
void writeByte(const uint32_t a, const uint16_t v) { assert(a < size); m[a] = v; } void write_byte(const uint32_t a, const uint16_t v) { if (a < size) m[a] = v; }
uint16_t readWord(const uint32_t a) const { return m[a] | (m[a + 1] << 8); } uint16_t read_word(const uint32_t a) const { return m[a] | (m[a + 1] << 8); }
void writeWord(const uint32_t a, const uint16_t v) { assert(a < size - 1); m[a] = v; m[a + 1] = v >> 8; } void write_word(const uint32_t a, const uint16_t v) { if(a < size - 1) { m[a] = v; m[a + 1] = v >> 8; } }
}; };

View file

@ -113,14 +113,14 @@ void tm_11::writeWord(const uint16_t addr, uint16_t v)
if (fread(xfer_buffer, 1, reclen, fh) != reclen) if (fread(xfer_buffer, 1, reclen, fh) != reclen)
DOLOG(info, true, "failed: %s", strerror(errno)); DOLOG(info, true, "failed: %s", strerror(errno));
for(int i=0; i<reclen; i++) for(int i=0; i<reclen; i++)
m -> writeByte(registers[(TM_11_MTCMA - TM_11_BASE) / 2] + i, xfer_buffer[i]); m->write_byte(registers[(TM_11_MTCMA - TM_11_BASE) / 2] + i, xfer_buffer[i]);
offset += reclen; offset += reclen;
v = 128; // TODO set error if error v = 128; // TODO set error if error
} }
else if (func == 2) { // write else if (func == 2) { // write
for(int i=0; i<reclen; i++) for(int i=0; i<reclen; i++)
xfer_buffer[i] = m -> readByte(registers[(TM_11_MTCMA - TM_11_BASE) / 2] + i); xfer_buffer[i] = m->read_byte(registers[(TM_11_MTCMA - TM_11_BASE) / 2] + i);
fwrite(xfer_buffer, 1, reclen, fh); fwrite(xfer_buffer, 1, reclen, fh);
offset += reclen; offset += reclen;
v = 128; // TODO v = 128; // TODO