Skip to content

Commit

Permalink
Save to memory with masking
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Oct 6, 2023
1 parent 681181e commit 9e463b4
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ printer.log
*.lst
*.txt
*.neonst
*.SAV
*.log
/x-*
10 changes: 8 additions & 2 deletions emulator/DebugView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ void DebugView_DoDraw(HDC hdc)
::PatBlt(hdc, x, 0, 4, cyHeight, PATCOPY);
x += 4;
int xMemmap = x;
x += cxChar * 24;
::PatBlt(hdc, x, 0, 4, cyHeight, PATCOPY);
x += 4;
int xHRandUR = x;
::SelectObject(hdc, hOldBrush);

DebugView_DrawProcessor(hdc, pDebugPU, xProc + cxChar, cyLine / 2, arrR, arrRChanged, oldPsw);
Expand All @@ -316,12 +320,14 @@ void DebugView_DoDraw(HDC hdc)
DebugView_DrawMemoryForRegister(hdc, 6, pDebugPU, xStack + cxChar / 2, cyLine / 2, oldSP);

int nWatches = DebugView_DrawWatches(hdc, pDebugPU, xPorts + cxChar, cyLine / 2);
//DebugView_DrawHRandUR(hdc, xPorts + cxChar, cyLine / 2);
DebugView_DrawPorts(hdc, xPorts + cxChar, cyLine / 2 + (nWatches > 0 ? 2 + nWatches : 0) * cyLine);

DebugView_DrawBreakpoints(hdc, xBreaks + cxChar / 2, cyLine / 2);

DebugView_DrawMemoryMap(hdc, xMemmap + cxChar / 2, 0, pDebugPU);

DebugView_DrawHRandUR(hdc, xHRandUR + cxChar, cyLine / 2);

SetTextColor(hdc, colorOld);
SetBkColor(hdc, colorBkOld);
SelectObject(hdc, hOldFont);
Expand Down Expand Up @@ -431,7 +437,7 @@ void DebugView_DrawAddressAndValue(HDC hdc, const CProcessor* pProc, uint16_t ad

int addrtype = ADDRTYPE_DENY;
uint16_t value = g_pBoard->GetWordView(address, pProc->IsHaltMode(), FALSE, &addrtype);
if (addrtype == ADDRTYPE_RAM)
if (addrtype <= ADDRTYPE_RAM4) // ADDRTYPE_RAM, ADDRTYPE_RAM2, ADDRTYPE_RAM4
{
DrawOctalValue(hdc, x, y, value);
}
Expand Down
54 changes: 48 additions & 6 deletions emulator/emubase/Board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,35 @@ uint8_t CMotherboard::GetRAMByte(uint32_t offset) const
{
return m_pRAM[offset];
}
void CMotherboard::SetRAMWord(uint32_t offset, uint16_t word)
void CMotherboard::SetRAMWord2(uint32_t offset, uint16_t word)
{
*((uint16_t*)(m_pRAM + offset)) = word;
uint16_t* p = (uint16_t*)(m_pRAM + offset);
uint16_t mask =
((word & 0x0003) == 0 ? 0 : 0x0003) | ((word & 0x000C) == 0 ? 0 : 0x000C) |
((word & 0x0030) == 0 ? 0 : 0x0030) | ((word & 0x00C0) == 0 ? 0 : 0x00C0) |
((word & 0x0300) == 0 ? 0 : 0x0300) | ((word & 0x0C00) == 0 ? 0 : 0x0C00) |
((word & 0x3000) == 0 ? 0 : 0x3000) | ((word & 0xC000) == 0 ? 0 : 0xC000);
*p = (word & mask) | (*p & ~mask);
}
void CMotherboard::SetRAMByte(uint32_t offset, uint8_t byte)
void CMotherboard::SetRAMWord4(uint32_t offset, uint16_t word)
{
m_pRAM[offset] = byte;
uint16_t* p = (uint16_t*)(m_pRAM + offset);
uint16_t mask =
((word & 0x000F) == 0 ? 0 : 0x000F) | ((word & 0x00F0) == 0 ? 0 : 0x00F0) |
((word & 0x0F00) == 0 ? 0 : 0x0F00) | ((word & 0xF000) == 0 ? 0 : 0xF000);
*p = (word & mask) | (*p & ~mask);
}
void CMotherboard::SetRAMByte2(uint32_t offset, uint8_t byte)
{
uint8_t mask =
((byte & 0x03) == 0 ? 0 : 0x03) | ((byte & 0x0C) == 0 ? 0 : 0x0C) |
((byte & 0x30) == 0 ? 0 : 0x30) | ((byte & 0xC0) == 0 ? 0 : 0xC0);
m_pRAM[offset] = (byte & mask) | (m_pRAM[offset] & ~mask);
}
void CMotherboard::SetRAMByte4(uint32_t offset, uint8_t byte)
{
uint8_t mask = ((byte & 0x0F) == 0 ? 0 : 0x0F) | ((byte & 0xF0) == 0 ? 0 : 0xF0);
m_pRAM[offset] = (byte & mask) | (m_pRAM[offset] & ~mask);
}

uint16_t CMotherboard::GetROMWord(uint16_t offset) const
Expand Down Expand Up @@ -559,6 +581,8 @@ uint16_t CMotherboard::GetWordView(uint16_t address, bool okHaltMode, bool okExe
switch (addrtype)
{
case ADDRTYPE_RAM:
case ADDRTYPE_RAM2:
case ADDRTYPE_RAM4:
return GetRAMWord(offset & ~1);
case ADDRTYPE_ROM:
return GetROMWord(offset & 0xfffe);
Expand Down Expand Up @@ -591,6 +615,8 @@ uint16_t CMotherboard::GetWord(uint16_t address, bool okHaltMode, bool okExec)
switch (addrtype)
{
case ADDRTYPE_RAM:
case ADDRTYPE_RAM2:
case ADDRTYPE_RAM4:
return GetRAMWord(offset & ~1);
case ADDRTYPE_ROM:
return GetROMWord(offset & 0xfffe);
Expand Down Expand Up @@ -626,6 +652,8 @@ uint8_t CMotherboard::GetByte(uint16_t address, bool okHaltMode)
switch (addrtype)
{
case ADDRTYPE_RAM:
case ADDRTYPE_RAM2:
case ADDRTYPE_RAM4:
return GetRAMByte(offset);
case ADDRTYPE_ROM:
return GetROMByte(offset & 0xffff);
Expand Down Expand Up @@ -664,6 +692,12 @@ void CMotherboard::SetWord(uint16_t address, bool okHaltMode, uint16_t word)
case ADDRTYPE_RAM:
SetRAMWord(offset, word);
return;
case ADDRTYPE_RAM2:
SetRAMWord2(offset, word);
return;
case ADDRTYPE_RAM4:
SetRAMWord4(offset, word);
return;
case ADDRTYPE_ROM: // Writing to ROM
//DebugLogFormat(_T("%c%06ho\tSETWORD ROM (%06ho)\n"), HU_INSTRUCTION_PC, address);
//m_pCPU->MemoryError();
Expand Down Expand Up @@ -700,6 +734,12 @@ void CMotherboard::SetByte(uint16_t address, bool okHaltMode, uint8_t byte)
case ADDRTYPE_RAM:
SetRAMByte(offset, byte);
return;
case ADDRTYPE_RAM2:
SetRAMByte2(offset, byte);
return;
case ADDRTYPE_RAM4:
SetRAMByte4(offset, byte);
return;
case ADDRTYPE_ROM: // Writing to ROM
//DebugLogFormat(_T("%c%06ho\tSETBYTE ROM (%06ho)\n"), HU_INSTRUCTION_PC, address);
//m_pCPU->MemoryError();
Expand Down Expand Up @@ -775,8 +815,10 @@ int CMotherboard::TranslateAddress(uint16_t address, bool okHaltMode, bool /*okE
}

*pOffset = longaddr;
//ASSERT(longaddr < m_nRamSizeBytes);
return ADDRTYPE_RAM;
uint16_t maskmode = memreg & 3;
if (maskmode == 0)
return ADDRTYPE_RAM;
return (maskmode & 2) == 0 ? ADDRTYPE_RAM2 : ADDRTYPE_RAM4;
}

uint8_t CMotherboard::GetPortByte(uint16_t address)
Expand Down
18 changes: 12 additions & 6 deletions emulator/emubase/Board.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ enum NeonConfiguration

// TranslateAddress result code
#define ADDRTYPE_RAM 0 // RAM
#define ADDRTYPE_ROM 1 // ROM
#define ADDRTYPE_IO 4 // I/O port
#define ADDRTYPE_EMUL 8 // I/O port emulation, USER mode only
#define ADDRTYPE_RAM2 1 // RAM with masking 2bit/pixel on write
#define ADDRTYPE_RAM4 2 // RAM with masking 4bit/pixel on write
#define ADDRTYPE_ROM 4 // ROM
#define ADDRTYPE_IO 16 // I/O port
#define ADDRTYPE_EMUL 32 // I/O port emulation, USER mode only
#define ADDRTYPE_DENY 128 // Access denied

//floppy debug
Expand Down Expand Up @@ -110,7 +112,7 @@ class PIT8253

//////////////////////////////////////////////////////////////////////

// Souz-Neon computer
// Soyuz-Neon computer
class CMotherboard
{
public: // Construct / destruct
Expand All @@ -133,8 +135,12 @@ class CMotherboard
public: // Memory access
uint16_t GetRAMWord(uint32_t offset) const;
uint8_t GetRAMByte(uint32_t offset) const;
void SetRAMWord(uint32_t offset, uint16_t word);
void SetRAMByte(uint32_t offset, uint8_t byte);
void SetRAMWord(uint32_t offset, uint16_t word) { *((uint16_t*)(m_pRAM + offset)) = word; }
void SetRAMWord2(uint32_t offset, uint16_t word);
void SetRAMWord4(uint32_t offset, uint16_t word);
void SetRAMByte(uint32_t offset, uint8_t byte) { m_pRAM[offset] = byte; }
void SetRAMByte2(uint32_t offset, uint8_t byte);
void SetRAMByte4(uint32_t offset, uint8_t byte);
uint16_t GetROMWord(uint16_t offset) const;
uint8_t GetROMByte(uint16_t offset) const;
uint32_t GetRamSizeBytes() const { return m_nRamSizeBytes; }
Expand Down

0 comments on commit 9e463b4

Please sign in to comment.