Skip to content

Commit

Permalink
Co Pro 80x86: Switch from 80286/NMI to 80186/DMA
Browse files Browse the repository at this point in the history
Change-Id: Ie45764747bd3b98f05b962e299eb2acf4a1c9767
  • Loading branch information
hoglet67 committed Mar 18, 2023
1 parent 585d52b commit 33bb8a6
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/copro-80186.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "tube-ula.h"
#include "cpu80186/cpu80186.h"
#include "cpu80186/mem80186.h"
#include "cpu80186/iop80186.h"
#include "startup.h"
#include "utils.h"

Expand Down Expand Up @@ -62,7 +63,8 @@ void copro_80186_emulator()

// NMI is edge sensitive, so only check after mailbox activity
if (tube_irq_copy & NMI_BIT) {
intcall86(2);
// intcall86(2);
x86_dma();
tube_ack_nmi();
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpu80186/Client86_v1_01.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define PATCH_FOR_80286
//#define PATCH_FOR_80286

uint8_t Client86_v1_01[] =
{
Expand Down
2 changes: 1 addition & 1 deletion src/cpu80186/cpu80186.c
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@ void exec86(uint32_t tube_cycles)
break;

case 0x54: /* 54 PUSH eSP */
push(getreg16(regsp)); // 8086 and intel 80186 have a bug where sp-2
push(getreg16(regsp) - 2); // 8086 and intel 80186 have a bug where sp-2
// is push on the stack. AMD 80186 and 286
// onwards doesn't have the -2 bug. This bug
// is used to detect the 186 by the TubeOS
Expand Down
37 changes: 37 additions & 0 deletions src/cpu80186/iop80186.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <stdio.h>
#include "../copro-80186.h"
#include "iop80186.h"
#include "mem80186.h"

#ifdef INCLUDE_DEBUGGER
#include "../cpu_debug.h"
Expand All @@ -36,6 +37,14 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define TUBE_ACCESS(ADDRESS) (((ADDRESS) & 0xFFF1) == 0x0080)
#define TUBE_CONVERT(PORT) (((PORT) >> 1) & 0x0007)



static uint32_t x86sa,x86ss,x86src;
static uint32_t x86da,x86ds,x86dst;
static uint32_t x86ena;
static uint16_t x86imask=0;


// I/O locations
// =============
// &80 Tube R1 Status
Expand All @@ -47,13 +56,41 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// &8C Tube R4 Status
// &8E Tube R4 Data

void x86_dma()
{
if (!(x86ena & 2)) {
return;
}
if (x86src < 0x100) {
write86(x86dst, portin((uint16_t) x86src));
x86dst++;
} else {
portout((uint16_t) x86dst, read86(x86src));
x86src++;
}
}

void portout(uint16_t portnum, uint8_t value)
{
#ifdef INCLUDE_DEBUGGER
if (cpu80186_debug_enabled) {
debug_iowrite(&cpu80186_cpu_debug, portnum, value, 1);
}
#endif
switch (portnum)
{
case 0xFF28: x86imask = value; return;
case 0xFFC0: x86sa = (x86sa & 0xFF00) | value; x86src = x86sa + ((x86ss & 0xF) << 16); return;
case 0xFFC1: x86sa = (x86sa & 0x00FF) | (value << 8); x86src = x86sa + ((x86ss & 0xF) << 16); return;
case 0xFFC2: x86ss = (x86ss & 0xFF00) | value; x86src = x86sa + ((x86ss & 0xF) << 16); return;
case 0xFFC3: x86ss = (x86ss & 0x00FF) | (value << 8); x86src = x86sa + ((x86ss & 0xF) << 16); return;
case 0xFFC4: x86da = (x86da & 0xFF00) | value; x86dst = x86da + ((x86ds & 0xF) << 16); return;
case 0xFFC5: x86da = (x86da & 0x00FF) | (value << 8); x86dst = x86da + ((x86ds & 0xF) << 16); return;
case 0xFFC6: x86ds = (x86ds & 0xFF00) | value; x86dst = x86da + ((x86ds & 0xF) << 16); return;
case 0xFFC7: x86ds = (x86ds & 0x00FF) | (value << 8); x86dst = x86da + ((x86ds & 0xF) << 16); return;
case 0xFFCA: x86ena = (x86ena & 0xFF00) | value; return;
case 0xFFCB: x86ena = (x86ena & 0x00FF) | (value << 8); return;
}
if (TUBE_ACCESS(portnum)) {
copro_80186_tube_write(TUBE_CONVERT(portnum), value);
}
Expand Down
3 changes: 2 additions & 1 deletion src/cpu80186/iop80186.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern void portout (uint16_t portnum, uint8_t value);
extern void portout16 (uint16_t portnum, uint16_t value);
extern uint8_t portin (uint16_t portnum);
extern uint16_t portin16 (uint16_t portnum);
extern uint16_t portin16 (uint16_t portnum);
extern void x86_dma();

0 comments on commit 33bb8a6

Please sign in to comment.