Connect to a PC

Discuss game and other programming topics not specifically covered in another forum

Moderator: Programming Moderators

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Tue Jan 07, 2020 11:23 am

I tried the Spec 2.12.5. The crash is gone now. I can use an image as in your command line.
However, with or without image, my UART routines are not getting called.

(The new Tick() command gets called.)

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Connect to a PC

Postby SevenFFF » Tue Jan 07, 2020 5:37 pm

Chris Kirby says his is now working.

But mine has stopped working with 2.12.5. In both nextrom and non-nextrom modes Init, Tick and Quit fire but Read and Write don't.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Sun Apr 05, 2020 2:47 pm

I just downloaded Cspect v2.12.9.
For me the UART is now working !!!

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Connect to a PC

Postby SevenFFF » Sun Apr 05, 2020 3:24 pm

2.12.5 plugin callbacks did all work for when I went back and retested the other day. I don’t know why I had those earlier issues. I suspect I had a stale interface dll (Plugin.dll) still referenced somewhere be perhaps the interface member order had changed (read and write have always been present but are now at the end of the member list).

Emulated and physical UARTs have always worked for me, but I now use a replacement UART plugin I wrote because the internal CSpect routines were casting binary bytes to ASCII and converting many of them to 0x3f ‘?’ chars.

This has been fixed in 2.12.9, but I still need to run my replacement UART for now as this also connects the ESP reset and GPIO register bits to the serial port RTS and DTR, allowing me to switch a physical ESP in and out of programming mode from CSpect.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

User avatar
xc8
Posts: 56
Joined: Fri Jun 02, 2017 10:37 pm
Location: B'ham
Contact:

Re: Connect to a PC

Postby xc8 » Sun Apr 05, 2020 4:41 pm

SevenFFF wrote:
Thu Jan 02, 2020 6:42 pm
...that Wine can map Windows COM ports to physical Linux ports,......
for sure its possible - I dont use linux anymore- I followed the info from this link mainly to use an external Yamaha tone generator with some midi apps (over serial)

(lol - reply to some months old comment, but maybe someone find it useful)
+++
ATZ

Zxspooks
Posts: 47
Joined: Wed Apr 29, 2020 9:39 pm

Re: Connect to a PC

Postby Zxspooks » Sun May 31, 2020 12:35 pm

Maziac wrote:
Sun Apr 05, 2020 2:47 pm
I just downloaded Cspect v2.12.9.
For me the UART is now working !!!
Hi can you help or direct me to somewhere i can get details on how to get this working, please, TIA

User avatar
Maziac
Posts: 110
Joined: Sun Jul 09, 2017 5:56 am

Re: Connect to a PC

Postby Maziac » Sun May 31, 2020 1:27 pm

Yes, I can.
Here is the main code I used for the UART in CSpect.

Code: Select all

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plugin;

namespace UartSocketPlugin
{
    /**
     * The plugin emulates the ZXNext UART.
     * All send/received bytes are transmitted to a socket.
     * This can be used to e.g. connect a debugger to CSpect via the UART.
     * 
     * Notes:
     * - The baudrate doesn't matter. I.e. the data is transmitted to the socket always at maximum speed independent of the set baudrate.
     * - The bit 1 of the state register is always 0. I.e. the TX data is immediately transferred to the socket.

     * - The receive FIFO is "infinite" in size.i.e. bit 2 of the state register is always 0.
     * - The receive FIFO is cleared on every new connection.
     * - Bit 0 of the state register is 0 if the receive FIFO is empty, otherwise 1.
     */
    public class Main : iPlugin
    {
        public const ushort PORT_UART_TX = 0x133b;
        public const ushort PORT_UART_RX = 0x143b;
        //public const ushort PORT_UART_CONTROL = 0x153b;

        public iCSpect CSpect;
        public Settings Settings;

        public int InstructionCounter;

        // USed to collect thebytes before sending.
        protected List<byte> writeBuffer;

        /**
         * Initialization. Called by CSpect.
         * Returns a list with the ports to be registered.
         */
        public List<sIO> Init(iCSpect _CSpect)
        {
            Log.WriteLine("v{0} started.", typeof(Main).Assembly.GetName().Version);

            // Init write buffer
            writeBuffer = new List<byte>();

            // Read settings file (port)
            Settings = Settings.Load();
            Log.Enabled = Settings.LogEnabled;

            //Server.Listen(Settings.Port);
            AsynchronousSocketListener.Port = Settings.Port;
            AsynchronousSocketListener.StartListening();

            CSpect = _CSpect;
            InstructionCounter = 0;


            // create a list of the ports we're interested in
            List<sIO> ports = new List<sIO>();
            ports.Add(new sIO(PORT_UART_TX, eAccess.Port_Read));        // Status: bit0=fifo empty, bit1=state, bit2=fifo full
            ports.Add(new sIO(PORT_UART_TX, eAccess.Port_Write));       // TX
            ports.Add(new sIO(PORT_UART_RX, eAccess.Port_Read));

            if(Log.Enabled)
                Log.WriteLine("UartSocket ports registered.");

            return ports;
        }


        /**
         * Called by CSpect to quit the plugin.
         */
        public void Quit()
        {
            // If the program is stopped the socket is closed anyway.
            Log.WriteLine("Terminated.");
        }


        /**
         * Called every frame.
         */
        public void Tick()
        {
        }
        

        /**
         * Writes a TX byte (_value).
         * The bytes are collected until enough (length) data has been received.
         * If no client is connected nothing happens, the byte is not cached.
         */
        public bool Write(eAccess _type, int _port, byte _value)
        {
            //Console.WriteLine("Write to port 0x{0:X4}: {1:X2}", _port, _value); 
            // _type is not check as we registered only for port.
            switch (_port)
            {
                case PORT_UART_TX:
                    // Collect bytes until the length and then length bytes are collected.
                    writeBuffer.Add(_value);
                    if (false && Log.Enabled)
                        Log.WriteLine("Write to port UART_TX (0x{0:X4}): 0x{1:X2}, writeBuffer.Count={2}", PORT_UART_TX, _value, writeBuffer.Count);
                    int count = writeBuffer.Count;
                    if (count >= 4)
                    {
                        // Get length
                        int length = writeBuffer[0] + 256 * writeBuffer[1] + 256 * 256 * writeBuffer[2] + 256 * 256 * 256 * writeBuffer[3];
                        // Check if all bytes collected
                        if(count-4>=length)
                        {
                            // All collected -> Send
                            if (false && Log.Enabled)
                                Log.WriteLine("Sent Buffer: Length={0}. Buffer[0]= {1}", writeBuffer.Count, writeBuffer[0]);
                            AsynchronousSocketListener.Send(writeBuffer.ToArray());
                            // Prepare new buffer
                            writeBuffer.Clear();
                        }

                    }
                    break;
            }
            return true;
        }


        /**
         * Reads the state or reads a byte from the receive fifo.
         * _isvalid is set to true if the returned value could be provided.
         */
        public byte Read(eAccess _type, int _port, out bool _isvalid)
        {
            //Console.WriteLine("Read from port 0x{0:X4}", _port);
            switch (_port)
            {
                case PORT_UART_TX:
                    {
                        // Reading from TX returns the status.
                        // bit0=fifo empty, bit1=state, bit2=fifo full
                        int fifoCount = AsynchronousSocketListener.UartData.Count;
                        byte state = (byte)((fifoCount > 0) ? 1 : 0);
                        // The other bits: TX is always transmitted immediately and the Uart receive buffer is infinite in size (never full).
                        _isvalid = true;
                        if (false && Log.Enabled)
                        {
                            if (fifoCount > 0)
                                Log.WriteLine("--Read status from port UART_TX (0x{0:X4}): 0x{1:X2}, fifo-count={2}", PORT_UART_TX, state, fifoCount);
                        }
                        return state;
                    }

                case PORT_UART_RX:
                    {
                        // Reading a byte for the receive fifo.
                        int data = AsynchronousSocketListener.GetFirstData();
                        byte value = (data >= 0) ? (byte)data : (byte)0;
                        _isvalid = true;
                        if (false && Log.Enabled)
                            Log.WriteLine("Read from port UART_RX (0x{0:X4}): 0x{1:X2}", PORT_UART_RX, value);
                        return value;
                    }
            }
            _isvalid = false;
            return 0;
        }
    }
}


The code on the other side connects to a socket, please ignore that part.

Zxspooks
Posts: 47
Joined: Wed Apr 29, 2020 9:39 pm

Re: Connect to a PC

Postby Zxspooks » Sun May 31, 2020 2:24 pm

Maziac wrote:
Sun May 31, 2020 1:27 pm
Yes, I can.
Here is the main code I used for the UART in CSpect.

Code: Select all

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plugin;

namespace UartSocketPlugin
{
    /**
     * The plugin emulates the ZXNext UART.
     * All send/received bytes are transmitted to a socket.
     * This can be used to e.g. connect a debugger to CSpect via the UART.
     * 
     * Notes:
     * - The baudrate doesn't matter. I.e. the data is transmitted to the socket always at maximum speed independent of the set baudrate.
     * - The bit 1 of the state register is always 0. I.e. the TX data is immediately transferred to the socket.

     * - The receive FIFO is "infinite" in size.i.e. bit 2 of the state register is always 0.
     * - The receive FIFO is cleared on every new connection.
     * - Bit 0 of the state register is 0 if the receive FIFO is empty, otherwise 1.
     */
    public class Main : iPlugin
    {
        public const ushort PORT_UART_TX = 0x133b;
        public const ushort PORT_UART_RX = 0x143b;
        //public const ushort PORT_UART_CONTROL = 0x153b;

        public iCSpect CSpect;
        public Settings Settings;

        public int InstructionCounter;

        // USed to collect thebytes before sending.
        protected List<byte> writeBuffer;

        /**
         * Initialization. Called by CSpect.
         * Returns a list with the ports to be registered.
         */
        public List<sIO> Init(iCSpect _CSpect)
        {
            Log.WriteLine("v{0} started.", typeof(Main).Assembly.GetName().Version);

            // Init write buffer
            writeBuffer = new List<byte>();

            // Read settings file (port)
            Settings = Settings.Load();
            Log.Enabled = Settings.LogEnabled;

            //Server.Listen(Settings.Port);
            AsynchronousSocketListener.Port = Settings.Port;
            AsynchronousSocketListener.StartListening();

            CSpect = _CSpect;
            InstructionCounter = 0;


            // create a list of the ports we're interested in
            List<sIO> ports = new List<sIO>();
            ports.Add(new sIO(PORT_UART_TX, eAccess.Port_Read));        // Status: bit0=fifo empty, bit1=state, bit2=fifo full
            ports.Add(new sIO(PORT_UART_TX, eAccess.Port_Write));       // TX
            ports.Add(new sIO(PORT_UART_RX, eAccess.Port_Read));

            if(Log.Enabled)
                Log.WriteLine("UartSocket ports registered.");

            return ports;
        }


        /**
         * Called by CSpect to quit the plugin.
         */
        public void Quit()
        {
            // If the program is stopped the socket is closed anyway.
            Log.WriteLine("Terminated.");
        }


        /**
         * Called every frame.
         */
        public void Tick()
        {
        }
        

        /**
         * Writes a TX byte (_value).
         * The bytes are collected until enough (length) data has been received.
         * If no client is connected nothing happens, the byte is not cached.
         */
        public bool Write(eAccess _type, int _port, byte _value)
        {
            //Console.WriteLine("Write to port 0x{0:X4}: {1:X2}", _port, _value); 
            // _type is not check as we registered only for port.
            switch (_port)
            {
                case PORT_UART_TX:
                    // Collect bytes until the length and then length bytes are collected.
                    writeBuffer.Add(_value);
                    if (false && Log.Enabled)
                        Log.WriteLine("Write to port UART_TX (0x{0:X4}): 0x{1:X2}, writeBuffer.Count={2}", PORT_UART_TX, _value, writeBuffer.Count);
                    int count = writeBuffer.Count;
                    if (count >= 4)
                    {
                        // Get length
                        int length = writeBuffer[0] + 256 * writeBuffer[1] + 256 * 256 * writeBuffer[2] + 256 * 256 * 256 * writeBuffer[3];
                        // Check if all bytes collected
                        if(count-4>=length)
                        {
                            // All collected -> Send
                            if (false && Log.Enabled)
                                Log.WriteLine("Sent Buffer: Length={0}. Buffer[0]= {1}", writeBuffer.Count, writeBuffer[0]);
                            AsynchronousSocketListener.Send(writeBuffer.ToArray());
                            // Prepare new buffer
                            writeBuffer.Clear();
                        }

                    }
                    break;
            }
            return true;
        }


        /**
         * Reads the state or reads a byte from the receive fifo.
         * _isvalid is set to true if the returned value could be provided.
         */
        public byte Read(eAccess _type, int _port, out bool _isvalid)
        {
            //Console.WriteLine("Read from port 0x{0:X4}", _port);
            switch (_port)
            {
                case PORT_UART_TX:
                    {
                        // Reading from TX returns the status.
                        // bit0=fifo empty, bit1=state, bit2=fifo full
                        int fifoCount = AsynchronousSocketListener.UartData.Count;
                        byte state = (byte)((fifoCount > 0) ? 1 : 0);
                        // The other bits: TX is always transmitted immediately and the Uart receive buffer is infinite in size (never full).
                        _isvalid = true;
                        if (false && Log.Enabled)
                        {
                            if (fifoCount > 0)
                                Log.WriteLine("--Read status from port UART_TX (0x{0:X4}): 0x{1:X2}, fifo-count={2}", PORT_UART_TX, state, fifoCount);
                        }
                        return state;
                    }

                case PORT_UART_RX:
                    {
                        // Reading a byte for the receive fifo.
                        int data = AsynchronousSocketListener.GetFirstData();
                        byte value = (data >= 0) ? (byte)data : (byte)0;
                        _isvalid = true;
                        if (false && Log.Enabled)
                            Log.WriteLine("Read from port UART_RX (0x{0:X4}): 0x{1:X2}", PORT_UART_RX, value);
                        return value;
                    }
            }
            _isvalid = false;
            return 0;
        }
    }
}


The code on the other side connects to a socket, please ignore that part.
Thnak you, sorry my bad I actually meant the cspect emulator I couldn't find anything on here, unless I've missed it. and the you tube videos I have looked at aren't that clear.

User avatar
SevenFFF
Posts: 565
Joined: Mon Jun 05, 2017 5:30 pm
Location: USA

Re: Connect to a PC

Postby SevenFFF » Sun May 31, 2020 2:26 pm

There’s a file called CSpectReadme.txt inside the zip that explains everyrhing.
Robin Verhagen-Guest
SevenFFF / Threetwosevensixseven / colonel32
NXtel NXTP ESP Update ESP Reset CSpect Plugins

Z80Man
Posts: 21
Joined: Wed Jul 08, 2020 5:53 am

Re: Connect to a PC

Postby Z80Man » Fri Jul 10, 2020 9:17 am

Dan Antohi has written a very nice file transfer protocol to link his ZX Interface 1 bis to a PC for file storage and printing.

I'll ask him about porting it into a dot command for the Next... Since he's using the same Wi-Fi module, it shouldn't be complicated, plus it would probably be nice if there was some kind of standard established on the PC side for data exchange, especially considering I'm probably not the only one being concerned with transfering all my microdrives and +D discs to EsxDOS...

For the microdrives part, I've bought a Vdrive ZX, but the SD card contents may not been directly readable by the Next, so a PC might probably be useful as an intermediate to sort files and send them back to the Next own storage.


Who is online

Users browsing this forum: No registered users and 1 guest