Add ./n.sh which assumes it can access a built FUZIX in ../FUZIX to make images
authorNick Downing <nick@ndcode.org>
Tue, 7 May 2019 11:18:25 +0000 (21:18 +1000)
committerNick Downing <nick@ndcode.org>
Tue, 7 May 2019 11:18:25 +0000 (21:18 +1000)
Makefile
debugger.h
depend.sh
n.sh [new file with mode: 0755]
sim/iosim.cpp
sim/sim0.cpp
sim/simglb.cpp
sim/simglb.h
z180/z180dasm.cpp
z180/z180dasm.h
z180/z180ops.h

index 7ec727e..e2e7ade 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,8 @@ sim/simctl.o \
 sim/simfun.o \
 sim/simglb.o \
 sim/simint.o \
-z180/z180.o
+z180/z180.o \
+z180/z180dasm.o
        ${CXX} ${CXXFLAGS} -o $@ $^
 
 iodevices/unix_terminal.o: iodevices/unix_terminal.cpp
@@ -26,6 +27,7 @@ sim/simfun.o: sim/simfun.cpp
 sim/simglb.o: sim/simglb.cpp
 sim/simint.o: sim/simint.cpp
 z180/z180.o: z180/z180.cpp
+z180/z180dasm.o: z180/z180dasm.cpp
 
 %.rel: %.asm
        bin/asz80 -o $<
@@ -48,3 +50,4 @@ clean:
 -include sim/simctl.dep
 -include sim/config.dep
 -include z180/z180.dep
+-include z180/z180dasm.dep
index a1a6fd9..0cdc64a 100644 (file)
@@ -2,7 +2,19 @@
 #define _DEBUGGER_H 1
 
 #if 0 // set to 1 to enable debugging printf
-#define debugger_instruction_hook(addr) fprintf(stderr, "%04x\n", addr);
+#include <stdio.h>
+#include "sim/sim.h"
+#include "sim/simglb.h"
+
+#define debugger_instruction_hook(addr) \
+  do { \
+    fprintf(stderr, "%04x ", addr); \
+    cpu_dis->disassemble( \
+      ((struct z180_device *)cpu_dev)->m_PC.d, \
+      *(struct z180_device *)cpu_dev \
+    ); \
+    fprintf(stderr, "\n"); \
+  } while (0);
 #else
 #define debugger_instruction_hook(addr)
 #endif
index b6f9f89..b7b81fc 100755 (executable)
--- a/depend.sh
+++ b/depend.sh
@@ -9,3 +9,4 @@ g++ -DCONFDIR=\".\" -DDISKSDIR=\".\" -I. -MM -MQ sim/simfun.o -o sim/simfun.dep
 g++ -DCONFDIR=\".\" -DDISKSDIR=\".\" -I. -MM -MQ sim/simglb.o -o sim/simglb.dep sim/simglb.cpp
 g++ -DCONFDIR=\".\" -DDISKSDIR=\".\" -I. -MM -MQ sim/simint.o -o sim/simint.dep sim/simint.cpp
 g++ -DCONFDIR=\".\" -DDISKSDIR=\".\" -I. -MM -MQ z180/z180.o -o z180/z180.dep z180/z180.cpp
+g++ -DCONFDIR=\".\" -DDISKSDIR=\".\" -I. -MM -MQ z180/z180dasm.o -o z180/z180dasm.dep z180/z180dasm.cpp
diff --git a/n.sh b/n.sh
new file mode 100755 (executable)
index 0000000..1c7973a
--- /dev/null
+++ b/n.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+rm -f disks/*.dsk
+mkdir --parents disks
+dd if=/dev/zero of=disks/drivea.dsk bs=128 count=2002
+dd if=../FUZIX/Kernel/platform-v8080/bootblock of=disks/drivea.dsk bs=128 conv=notrunc
+dd if=../FUZIX/Kernel/fuzix.bin of=disks/drivea.dsk bs=128 seek=1508 conv=notrunc
+cat <<EOF |(cd ../FUZIX/Standalone/filesystem-src && ./build-filesystem ../../../fuzix_sim/disks/drivei.dsk 256 8192)
+y
+y
+EOF
+dd if=/dev/zero of=disks/drivej.dsk bs=128 count=32768
index ef52cde..c365bee 100644 (file)
@@ -2285,14 +2285,24 @@ static void fdco_out(BYTE data)
                if (read(*disks[drive].fd, buf, 128) != 128)
                        status = 5;
                else {
+ //fprintf(stderr, "W%04x ", (dmadh << 8) + dmadl);
                        for (i = 0; i < 128; i++)
+ //{
+ // fprintf(stderr, "%02x", buf[i]);
                                dma_write((dmadh << 8) + dmadl + i, buf[i]);
+ //}
+ //fprintf(stderr, "\n");
                        status = 0;
                }
                break;
        case 1: /* write */
+ //fprintf(stderr, "R%04x ", (dmadh << 8) + dmadl);
                for (i = 0; i < 128; i++)
+ //{
                        buf[i] = dma_read((dmadh << 8) + dmadl + i);
+ // fprintf(stderr, "%02x", buf[i]);
+ //}
+ //fprintf(stderr, "\n");
                if (write(*disks[drive].fd, buf, 128) != 128)
                        status = 6;
                else
index 8731e05..3f21c8b 100644 (file)
@@ -345,9 +345,20 @@ static void init_cpu(void)
 
  class sim_memory_address_space : public address_space {
   virtual u8 read_byte(offs_t address) override {
+#if 0
+ u8 data = (u8)memrdr((uint32_t)address);
+ if (address == 0xb88f || address == 0xb890)
+  fprintf(stderr, "R%05x=%02x\n", address, data);
+ return data;
+#else
    return (u8)memrdr((uint32_t)address);
+#endif
   }
   virtual void write_byte(offs_t address, u8 data) override {
+#if 0
+ if (address == 0xb88f || address == 0xb890)
+  fprintf(stderr, "W%05x=%02x\n", address, data);
+#endif
    memwrt((uint32_t)address, (BYTE)data);
   }
  };
@@ -367,6 +378,7 @@ static void init_cpu(void)
 
  z180_dev->device_reset();
  cpu_dev = z180_dev;
+ cpu_dis = new z180_disassembler(); // make this generic not Z180 specific
 #else
        /* same for i8080 and Z80 */
        PC = 0;
index 13bac38..f78a72e 100644 (file)
@@ -51,6 +51,7 @@
 #include <stddef.h>
 #include "emu.h"
 #include "sim.h"
+#include "z180/z180dasm.h"
 
 #define MAXCHAN 5      /* max number of channels for I/O busy detect */
 
@@ -61,6 +62,7 @@ int cpu = DEFAULT_CPU;
 
 #if 1
 cpu_device *cpu_dev;
+z180_disassembler *cpu_dis; // make this generic not Z180 specific
 #else
 /*
  *     CPU Registers
index 8910426..053eea5 100644 (file)
@@ -52,7 +52,9 @@ extern int    cpu;
 
 #if 1
 #include "emu.h"
+#include "z180/z180dasm.h"
 extern cpu_device *cpu_dev;
+extern z180_disassembler *cpu_dis; // make this generic not Z180 specific
 #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;
index 521ec1b..55ec7ae 100644 (file)
 #include "emu.h"
 #include "z180dasm.h"
 
+// horrible hacks to get inline routines to compile
+#define DISASSEMBLER 1 // horrible hack
+#define _PCD    m_PC.d
+#define _PC     m_PC.w.l
+#define IO(n)       m_io[(n)-Z180_CNTLA0]
+#define IO_DCNTL    IO(Z180_DCNTL)
+#include "z180ops.h"
+
 const char *const z180_disassembler::s_mnemonic[] = {
        "adc"  ,"add"  ,"and"  ,"bit"  ,"call" ,"ccf"  ,"cp"   ,"cpd"  ,
        "cpdr" ,"cpi"  ,"cpir" ,"cpl"  ,"daa"  ,"db"   ,"dec"  ,"di"   ,
@@ -372,48 +380,54 @@ int z180_disassembler::offs(int8_t offset)
 /****************************************************************************
  * Disassemble opcode at PC and return number of bytes it takes
  ****************************************************************************/
-offs_t z180_disassembler::disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer &params)
+//offs_t z180_disassembler::disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer &params)
+offs_t z180_disassembler::disassemble(offs_t pc, z180_device &dev)
 {
        const z80dasm *d;
        const char *src, *ixy;
        int8_t offset = 0;
        uint8_t op, op1 = 0;
        uint16_t ea;
-       offs_t pos = pc;
-       uint32_t flags = 0;
+       //offs_t pos = pc;
+       //uint32_t flags = 0;
 
        ixy = "oops!!";
 
-       op = opcodes.r8(pos++);
+       offs_t pc_save = dev._PCD;
+       int m_extra_cycles_save = dev.m_extra_cycles;
+       dev._PCD = pc;
+       dev.m_extra_cycles = 0;
+
+       op = dev.ROP(); //opcodes.r8(pos++);
 
        switch (op)
        {
        case 0xcb:
-               op = opcodes.r8(pos++);
+               op = dev.ROP(); //opcodes.r8(pos++);
                d = &mnemonic_cb[op];
                break;
        case 0xed:
-               op1 = opcodes.r8(pos++);
+               op1 = dev.ROP(); //opcodes.r8(pos++);
                d = &mnemonic_ed[op1];
                break;
        case 0xdd:
                ixy = "ix";
-               op1 = opcodes.r8(pos++);
+               op1 = dev.ROP(); //opcodes.r8(pos++);
                if( op1 == 0xcb )
                {
-                       offset = (int8_t) params.r8(pos++);
-                       op1 = params.r8(pos++); /* fourth byte from opbase.ram! */
+                       offset = (int8_t) dev.ARG(); //params.r8(pos++);
+                       op1 = dev.ARG(); //params.r8(pos++); /* fourth byte from opbase.ram! */
                        d = &mnemonic_xx_cb[op1];
                }
                else d = &mnemonic_xx[op1];
                break;
        case 0xfd:
                ixy = "iy";
-               op1 = opcodes.r8(pos++);
+               op1 = dev.ROP(); //opcodes.r8(pos++);
                if( op1 == 0xcb )
                {
-                       offset = (int8_t) params.r8(pos++);
-                       op1 = params.r8(pos++); /* fourth byte from opbase.ram! */
+                       offset = (int8_t) dev.ARG(); //params.r8(pos++);
+                       op1 = dev.ARG(); //params.r8(pos++); /* fourth byte from opbase.ram! */
                        d = &mnemonic_xx_cb[op1];
                }
                else d = &mnemonic_xx[op1];
@@ -425,73 +439,77 @@ offs_t z180_disassembler::disassemble(std::ostream &stream, offs_t pc, const dat
 
        if( d->arguments )
        {
-               util::stream_format(stream, "%-5s ", s_mnemonic[d->mnemonic]);
+               fprintf/*util::stream_format*/(stderr/*stream*/, "%-5s ", s_mnemonic[d->mnemonic]);
                src = d->arguments;
                while( *src )
                {
                        switch( *src )
                        {
                        case '?':   /* illegal opcode */
-                               util::stream_format(stream, "$%02x,$%02x", op, op1);
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%02x,$%02x", op, op1);
                                break;
                        case 'A':
-                               ea = params.r16(pos);
-                               pos += 2;
-                               util::stream_format(stream, "$%04X", ea);
+                               ea = dev.ARG16(); //params.r16(pos);
+                               //pos += 2;
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%04X", ea);
                                break;
                        case 'B':   /* Byte op arg */
-                               ea = params.r8(pos++);
-                               util::stream_format(stream, "$%02X", ea);
+                               ea = dev.ARG(); //params.r8(pos++);
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%02X", ea);
                                break;
                        case 'N':   /* Immediate 16 bit */
-                               ea = params.r16(pos);
-                               pos += 2;
-                               util::stream_format(stream, "$%04X", ea);
+                               ea = dev.ARG16(); //params.r16(pos);
+                               //pos += 2;
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%04X", ea);
                                break;
                        case 'O':   /* Offset relative to PC */
-                               offset = (int8_t) params.r8(pos++);
-                               util::stream_format(stream, "$%05X", pc + offset + 2);
+                               offset = (int8_t) dev.ARG(); //params.r8(pos++);
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%05X", pc + offset + 2);
                                break;
                        case 'P':   /* Port number */
-                               ea = params.r8(pos++);
-                               util::stream_format(stream, "$%02X", ea);
+                               ea = dev.ARG(); //params.r8(pos++);
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%02X", ea);
                                break;
                        case 'V':   /* Restart vector */
                                ea = op & 0x38;
-                               util::stream_format(stream, "$%02X", ea);
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%02X", ea);
                                break;
                        case 'W':   /* Memory address word */
-                               ea = params.r16(pos);
-                               pos += 2;
-                               util::stream_format(stream, "$%05X", ea);
+                               ea = dev.ARG16(); //params.r16(pos);
+                               //pos += 2;
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "$%05X", ea);
                                break;
                        case 'X':
-                               offset = (int8_t) params.r8(pos++);
+                               offset = (int8_t) dev.ARG(); //params.r8(pos++);
                        case 'Y':
-                               util::stream_format(stream,"(%s%c$%02x)", ixy, sign(offset), offs(offset));
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "(%s%c$%02x)", ixy, sign(offset), offs(offset));
                                break;
                        case 'I':
-                               util::stream_format(stream, "%s", ixy);
+                               fprintf/*util::stream_format*/(stderr/*stream*/, "%s", ixy);
                                break;
                        default:
-                               stream << *src;
+                               fputc(*src, stderr); //stream << *src;
                        }
                        src++;
                }
        }
        else
        {
-               util::stream_format(stream, "%s", s_mnemonic[d->mnemonic]);
+               fprintf/*util::stream_format*/(stderr/*stream*/, "%s", s_mnemonic[d->mnemonic]);
        }
 
-       if (d->mnemonic == zCALL || d->mnemonic == zCPDR || d->mnemonic == zCPIR || d->mnemonic == zDJNZ ||
-               d->mnemonic == zHLT  || d->mnemonic == zINDR || d->mnemonic == zINIR || d->mnemonic == zLDDR ||
-               d->mnemonic == zLDIR || d->mnemonic == zOTDR || d->mnemonic == zOTIR || d->mnemonic == zRST)
-               flags = STEP_OVER;
-       else if (d->mnemonic == zRETN || d->mnemonic == zRET || d->mnemonic == zRETI)
-               flags = STEP_OUT;
+       //if (d->mnemonic == zCALL || d->mnemonic == zCPDR || d->mnemonic == zCPIR || d->mnemonic == zDJNZ ||
+       //      d->mnemonic == zHLT  || d->mnemonic == zINDR || d->mnemonic == zINIR || d->mnemonic == zLDDR ||
+       //      d->mnemonic == zLDIR || d->mnemonic == zOTDR || d->mnemonic == zOTIR || d->mnemonic == zRST)
+       //      flags = STEP_OVER;
+       //else if (d->mnemonic == zRETN || d->mnemonic == zRET || d->mnemonic == zRETI)
+       //      flags = STEP_OUT;
 
-       return (pos - pc) | flags | SUPPORTED;
+       pc = dev._PCD;
+       dev._PCD = pc_save;
+       dev.m_extra_cycles = m_extra_cycles_save;
+       
+       return pc; //(pos - pc) | flags | SUPPORTED;
 }
 
 u32 z180_disassembler::opcode_alignment() const
index a13c7d9..21b0a45 100644 (file)
 #ifndef MAME_CPU_Z180_Z180DASM_H
 #define MAME_CPU_Z180_Z180DASM_H
 
+#include "z180/z180.h"
+
 #pragma once
 
-class z180_disassembler : public util::disasm_interface
+class z180_disassembler //nick: public util::disasm_interface
 {
 public:
        z180_disassembler() = default;
        virtual ~z180_disassembler() = default;
 
-       virtual u32 opcode_alignment() const override;
-       virtual offs_t disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer &params) override;
+       virtual u32 opcode_alignment() const; //nick override;
+       //virtual offs_t disassemble(std::ostream &stream, offs_t pc, const data_buffer &opcodes, const data_buffer &params) override;
+       virtual offs_t disassemble(offs_t pc, z180_device &dev);
 
 private:
        struct z80dasm {
index 7abef5e..f4c1277 100644 (file)
@@ -1,3 +1,4 @@
+#ifndef DISASSEMBLER
 // license:BSD-3-Clause
 // copyright-holders:Juergen Buchmueller
 /***************************************************************
@@ -71,6 +72,7 @@ void z180_device::z180_mmu()
                m_mmu[page] = (addr & 0xfffff);
        }
 }
+#endif
 
 
 #define MMU_REMAP_ADDR(addr) (m_mmu[((addr)>>12)&15]|((addr)&4095))
@@ -154,6 +156,7 @@ uint32_t z180_device::ARG16()
 #endif
 }
 
+#ifndef DISASSEMBLER
 /***************************************************************
  * Calculate the effective address m_ea of an opcode using
  * IX+offset resp. IY+offset addressing.
@@ -967,3 +970,4 @@ uint8_t z180_device::SET(uint8_t bit, uint8_t value)
        m_icount = 0;                                           \
        m_HALT = 2;                                                 \
 }
+#endif