CPPFLAGS=-DCONFDIR=\".\" -DDISKSDIR=\".\" -I.
-#CXXFLAGS=-Wfatal-errors
+CXXFLAGS=-g
fuzix_sim: \
iodevices/unix_terminal.o \
#ifndef _EMU_H
#define _EMU_H 1
+#include <assert.h>
#include <stdint.h>
#include <string.h>
typedef uint8_t u8;
public:
virtual void device_start() = 0;
virtual void device_reset() = 0;
+};
+
+class cpu_device : public device_t {
+public:
+ int *m_icountptr;
+
+ cpu_device() : m_icountptr(NULL) {}
virtual uint32_t execute_min_cycles() const = 0;
virtual uint32_t execute_max_cycles() const = 0;
virtual uint32_t execute_input_lines() const = 0;
virtual void execute_run() = 0;
virtual void execute_burn(int32_t cycles) = 0;
virtual void execute_set_input(int inputnum, int state) = 0;
- virtual bool memory_translate(int spacenum, int intention, offs_t &address) = 0;
-};
-
-class cpu_device : public device_t {
+ void set_icountptr(int &icount) {
+ assert(!m_icountptr);
+ m_icountptr = &icount;
+ }
};
class machine_config {
* 51 - client socket #1 data
*/
+#include <assert.h> // temporary
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
{
addrh = addrh; /* to avoid compiler warning */
+#if 1
+ return (*port_in[addrl])();
+#else
io_port = addrl;
io_data = (*port_in[addrl]) ();
//printf("input %02x from port %02x\r\n", io_data, io_port);
return(io_data);
+#endif
}
/*
{
addrh = addrh; /* to avoid compiler warning */
+#if 0
io_port = addrl;
io_data = data;
+#endif
busy_loop_cnt[0] = 0;
static BYTE io_trap_in(void)
{
if (i_flag) {
+#if 1
+ assert(false);
+#else
cpu_error = IOTRAPIN;
cpu_state = STOPPED;
+#endif
}
return((BYTE) 0xff);
}
data = data; /* to avoid compiler warning */
if (i_flag) {
+#if 1
+ assert(false);
+#else
cpu_error = IOTRAPOUT;
cpu_state = STOPPED;
+#endif
}
}
host = gethostbyname(&cs_host[0]);
if ((cs = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
perror("create client socket");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
memset((void *) &sin, 0, sizeof(sin));
sin.sin_port = htons(cs_port);
if (connect(cs, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
perror("connect client socket");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
if (setsockopt(cs, IPPROTO_TCP, TCP_NODELAY,
return((BYTE) 0);
} else {
perror("read console 1");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
}
return((BYTE) 0);
} else {
perror("read console 2");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
}
return((BYTE) 0);
} else {
perror("read console 3");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
}
return((BYTE) 0);
} else {
perror("read console 4");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
}
#ifdef NETWORKING
if (read(cs, &c, 1) != 1) {
perror("read client socket");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
#ifdef CNETDEBUG
goto again;
} else {
perror("write console 0");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
}
goto again;
} else {
perror("write console 1");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
#endif
goto again;
} else {
perror("write console 2");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
#endif
goto again;
} else {
perror("write console 3");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
#endif
goto again;
} else {
perror("write console 4");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
#endif
goto again;
} else {
perror("write client socket");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
#endif
goto again;
} else {
perror("write printer");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
}
}
}
if (aux_in == 0) {
if ((aux_in = open("auxiliaryin.txt", O_RDONLY)) == -1){
perror("open auxiliaryin.txt");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return((BYTE) 0);
}
}
if (aux_out == 0) {
if ((aux_out = creat("auxiliaryout.txt", 0644)) == -1) {
perror("open auxiliaryout.txt");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return;
}
}
if (data > MAXSEG) {
printf("Try to init %d banks, available %d banks\r\n",
data, MAXSEG);
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return;
}
for (i = 1; i < data; i++) {
if ((memory[i] = (BYTE *)malloc(segsize)) == NULL) {
printf("can't allocate memory for bank %d\r\n", i);
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return;
}
}
static void mmus_out(BYTE data)
{
if (data > maxbnk - 1) {
+#if 1
+ printf("try to select unallocated bank %d\r\n", data);
+ assert(false);
+#else
printf("%04x: try to select unallocated bank %d\r\n", PC, data);
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return;
}
selbnk = data;
{
if (memory[1] != NULL) {
printf("Not possible to resize already allocated segments\r\n");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return;
}
segsize = data << 8;
static void hwctl_out(BYTE data)
{
if (data & 128) {
+#if 1
+ assert(false);
+#else
cpu_error = IOHALT;
cpu_state = STOPPED;
+#endif
return;
}
{
sig = sig; /* to avoid compiler warning */
+#if 0
int_int = 1;
int_data = 0xff; /* RST 38H for IM 0, 0FFH for IM 2 */
+#endif
}
#if defined(NETWORKING) && defined(TCPASYNC)
* 03-FEB-17 added ROM initialisation
*/
+#include <assert.h> // temporary
#include <stdlib.h>
#include <stdio.h>
#include "sim.h"
/* allocate the first 64KB bank, so that we have some memory */
if ((memory[0] = (BYTE *)malloc(65536)) == NULL) {
printf("can't allocate memory for bank 0\r\n");
+#if 1
+ assert(false);
+#else
cpu_error = IOERROR;
cpu_state = STOPPED;
+#endif
return;
}
maxbnk = 1;
};
#endif
-#ifndef isxdigit
-#define isxdigit(c) ((c<='f'&&c>='a')||(c<='F'&&c>='A')||(c<='9'&&c>='0'))
-#endif
+#include <ctype.h>
+//#ifndef isxdigit
+//#define isxdigit(c) ((c<='f'&&c>='a')||(c<='F'&&c>='A')||(c<='9'&&c>='0'))
+//#endif
/*
* Structure for the disk images
* the user interface ( mon() ) is called.
*/
+#include <assert.h> // temporary
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "config.h"
//#include "../../frontpanel/frontpanel.h"
#include "memory.h"
+#include "z180/z180.h"
#define BUFSIZE 256 /* buffer size for file I/O */
*/
static void init_cpu(void)
{
+#if 1
+ z180_device *z180_dev = new z180_device();
+ z180_dev->device_start();
+ *z180_dev->m_icountptr = 0;
+
+ class memory_address_space : public address_space {
+ virtual u8 read_byte(offs_t address) override {
+ return memrdr((WORD)address);
+ }
+ virtual void write_byte(offs_t address, u8 data) override {
+ memwrt((WORD)address, (BYTE)data);
+ }
+ };
+ z180_dev->m_program = new memory_address_space();
+
+ BYTE io_in(BYTE addrl, BYTE addrh);
+ void io_out(BYTE addrl, BYTE addrh, BYTE data);
+ class io_address_space : public address_space {
+ virtual u8 read_byte(offs_t address) override {
+ return io_in((BYTE)address, (BYTE)(address >> 8));
+ }
+ virtual void write_byte(offs_t address, u8 data) override {
+ io_out((BYTE)address, (BYTE)(address >> 8), (BYTE)data);
+ }
+ };
+ z180_dev->m_iospace = new io_address_space();
+
+ z180_dev->device_reset();
+ cpu_dev = z180_dev;
+#else
/* same for i8080 and Z80 */
PC = 0;
SP = rand() % 65536;
IX = rand() % 65536;
IY = rand() % 65536;
}
+#endif
}
/*
*/
void reset_cpu(void)
{
+#if 1
+ cpu_dev->device_reset();
+#else
IFF = int_int = int_nmi = int_protection = int_mode = 0;
int_data = -1;
I = 0;
R = 0L;
}
+#endif
}
/*
*/
static void save_core(void)
{
+#if 1
+ assert(false);
+#else
int fd;
if ((fd = open("core.z80", O_WRONLY | O_CREAT, 0600)) == -1) {
write(fd, (char *) &IY, sizeof(IY));
write(fd, (char *) mem_base(), 65536);
close(fd);
+#endif
}
/*
*/
int load_core(void)
{
+#if 1
+ assert(false);
+#else
int fd;
if ((fd = open("core.z80", O_RDONLY)) == -1) {
close(fd);
return(0);
+#endif
}
/*
*/
int load_file(char *s)
{
+#if 1
+ assert(false);
+#else
char fn[LENCMD];
BYTE fileb[5];
register char *pfn = fn;
close(fd);
return (load_hex(fn));
}
+#endif
}
+#if 0
/*
* Loader for binary images with Mostek header.
* Format of the first 3 bytes:
else
return(1);
}
+#endif
#include "simglb.h"
#include "memory.h"
#include "iodevices/unix_terminal.h"
+#include "z180/z180.h"
int boot(void);
set_unix_terminal();
/* start CPU emulation */
+#if 1
+ assert(cpu_dev);
+ while (true) {
+ *cpu_dev->m_icountptr += 1000;
+ cpu_dev->execute_run();
+ //fputc('.', stderr);
+ }
+#else
cpu_state = CONTIN_RUN;
cpu_error = NONE;
switch(cpu) {
case Z80:
-#if 1
- assert(false);
-#else
cpu_z80();
-#endif
break;
case I8080:
-#if 1
- assert(false);
-#else
cpu_8080();
-#endif
break;
}
+#endif
/* reset terminal */
reset_unix_terminal();
+#if 0
/* check for CPU emulation errors and report */
switch (cpu_error) {
case NONE:
printf("\nUnknown error %d\n", cpu_error);
break;
}
+#endif
}
/*
*/
#include <stddef.h>
+#include "emu.h"
#include "sim.h"
#define MAXCHAN 5 /* max number of channels for I/O busy detect */
*/
int cpu = DEFAULT_CPU;
+#if 1
+cpu_device *cpu_dev;
+#else
/*
* CPU Registers
*/
BYTE io_port; /* I/O port used */
BYTE io_data; /* data on I/O port */
+#endif
int busy_loop_cnt[MAXCHAN]; /* counters for I/O busy loop detection */
+#if 0
BYTE cpu_state; /* state of CPU emulation */
int cpu_error; /* error status of CPU emulation */
int int_mode; /* CPU interrupt mode (IM 0, IM 1, IM 2) */
int int_data = -1; /* data from interrupting device on data bus */
int int_protection; /* to delay interrupts after EI */
BYTE bus_request; /* request address/data bus from CPU */
+#endif
int tmax; /* max t-states to execute in 10ms */
/*
extern int cpu;
+#if 1
+#include "emu.h"
+extern cpu_device *cpu_dev;
+#else
extern BYTE A, B, C, D, E, H, L, A_, B_, C_, D_, E_, H_, L_, I, IFF;
extern WORD PC, SP, IX, IY;
extern int F, F_;
extern BYTE cpu_state, bus_request;
extern int int_data;
+#endif
-extern int s_flag, l_flag, m_flag, x_flag, break_flag, i_flag, f_flag,
+extern int s_flag, l_flag, m_flag, x_flag, i_flag, f_flag;
+#if 0
+extern int break_flag,
cpu_error, int_nmi, int_int, int_mode, parity[], sb_next,
int_protection;
+#endif
#ifdef Z80_UNDOC
extern int u_flag;
* term_int() : handler for signal SIGTERM when process is killed
*/
+#include <assert.h> // temporary
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
{
sig = sig; /* to avoid compiler warning */
+#if 1
+ assert(false);
+#else
cpu_error = USERINT;
cpu_state = STOPPED;
+#endif
}
static void quit_int(int sig)
{
sig = sig; /* to avoid compiler warning */
+#if 1
+ assert(false);
+#else
cpu_error = USERINT;
cpu_state = STOPPED;
+#endif
}
static void term_int(int sig)
*****************************************************************************/
-#include "emu.h"
+//#include "emu.h"
#include "z180.h"
//#include "z180dasm.h"
#include "debugger.h"
//nickDEFINE_DEVICE_TYPE(Z180, z180_device, "z180", "Zilog Z180")
-//nickz180_device::z180_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+z180_device::z180_device(/*const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock*/)
//nick : cpu_device(mconfig, Z180, tag, owner, clock)
//nick , z80_daisy_chain_interface(mconfig, *this)
//nick , m_program_config("program", ENDIANNESS_LITTLE, 8, 20, 0)
//nick , m_io_config("io", ENDIANNESS_LITTLE, 8, 16, 0)
//nick , m_decrypted_opcodes_config("program", ENDIANNESS_LITTLE, 8, 20, 0)
-//nick{
-//nick}
+{
+}
//nickstd::unique_ptr<util::disasm_interface> z180_device::create_disassembler()
//nick{
//nick save_item(NAME(m_ioltemp));
//nick
//nick save_item(NAME(m_mmu));
-//nick
-//nick set_icountptr(m_icount);
+
+ set_icountptr(m_icount);
}
/****************************************************************************
#pragma once
+#include "emu.h"
#include "machine/z80daisy.h"
{
public:
// construction/destruction
- z180_device(const machine_config &mconfig, const char *_tag, device_t *_owner, uint32_t _clock);
+ z180_device(/*const machine_config &mconfig, const char *_tag, device_t *_owner, uint32_t _clock*/);
bool get_tend0();
bool get_tend1();
-protected:
+//nickprotected:
// device-level overrides
virtual void device_start() override;
virtual void device_reset() override;
// device_disasm_interface overrides
//nick virtual std::unique_ptr<util::disasm_interface> create_disassembler() override;
-private:
+//nickprivate:
//nick address_space_config m_program_config;
//nick address_space_config m_io_config;
//nick address_space_config m_decrypted_opcodes_config;
uint8_t m_dma1_cnt; /* dma1 counter / divide by 20 */
address_space *m_program;
//nick memory_access_cache<0, 0, ENDIANNESS_LITTLE> *m_cache;
- address_space *m_oprogram;
+//nick address_space *m_oprogram;
//nick memory_access_cache<0, 0, ENDIANNESS_LITTLE> *m_ocache;
address_space *m_iospace;
uint8_t m_rtemp;
***************************************************************/
inline u8 z180_device::IN(u16 port)
{
+#if 0 // temporary
if(((port ^ IO_IOCR) & 0xffc0) == 0)
return z180_readcontrol(port);
+#endif
m_extra_cycles += ((IO_DCNTL & (Z180_DCNTL_IWI1 | Z180_DCNTL_IWI0)) >> 4) + 1; // external I/O wait states
return m_iospace->read_byte(port);
}
***************************************************************/
inline void z180_device::OUT(u16 port, u8 value)
{
+#if 0 // temporary
if (((port ^ IO_IOCR) & 0xffc0) == 0) {
z180_writecontrol(port,value);
} else
+#endif
{
m_extra_cycles += ((IO_DCNTL & (Z180_DCNTL_IWI1 | Z180_DCNTL_IWI0)) >> 4) + 1; // external I/O wait states
m_iospace->write_byte(port, value);