Menu

#442 AY RS232 interface for 128/+2/+3

future
open
nobody
None
5
2024-06-02
2024-05-25
Vic Chwe
No

I would like to propose a patch which enables physical serial devices
to be connected to the AY8912 pins. It builds on top of Paul Osmialowski's
proposal (patch #426)
. With this patch I am able to use ESP-12 module connected to the host machine inside FUSE emulating 128/+2/+3 (see attached screenshot).

It re-uses exiting RS232 "writing" code, from printer.c but implements a
proper bit banging at the appropriate speed. It should work at any speed available on the actual hardware (up to 115200). However, the bit banging timing constant has to be compiled in, so it can operate only with the pre-define set of baud rates.

Test with my own serial "terminal" code and MRF gopher browser.

The patch consists of two parts: rs232-adapter.patch -- the core logic itself, and fuse-ay-rs232.patch -- naive integration attempt.

Unresolved question:

I am using event subsystem to simulate monotonic timer. I am not that familiar with FUSE internals and I have not found a monotinic times. If one exists, it should be used instead of "monotonic_tstates" (see ay_rs232_next_bit()) and AY_RS232_EVENT_DRIVEN should be undefined.

What needs to be done:
- better naming, this is essentially an adapter representing external serial device
- hotplugging of the RX/TX FIFO's/files
- UI infra, all the menu bells and whistles, specifically baud rate selection and input/output file/fifo selection.

How to test:
1. Apply both patches
2. Compile FUSE and run it with --rs232-baud SPEED parameter, where SPEED in one of the following: 50, 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200

NOTE: I/O is unconditionally directed to the hardcoded file objects called "rs232-rx" (FUSE reads incoming data here) and "rs232-tx" (FUSE writes bytes here).

NOTE: RS232 baud rate selected in FUSE is NOT related to the physical I/O configuration, FUSE's setting only defines the rate at which bits are presented to the AY emulation layer.

Example:

mkfifo rs232-rx rs232-tx
socat /dev/ttyUSB0,b9600,raw,echo=0 - < rs232-tx > rs232-rx &
fuse -m plus3 --rs232-baud 9600 _DISK WITH RS232 ENABLED SW_
4 Attachments

Discussion

  • Vic Chwe

    Vic Chwe - 2024-05-29

    Almost complete functional changes. Remaining tasks:

    • UI
    • replace existing serial printer emulation
    • multiplatform support (at least making sure it compiles anywhere)
    • cleanup code :)

    The following settings available (command line only):

    --ay-io-device TYPE - where TYPE is None, RS232 or MIDI
    for MIDI the following options available:
    --ay-io-midi-tx FILE - attach MIDI receiver (e.g. amidicat http://krellan.com/amidicat/ )
    for RS232 the following options available:
    --ay-io-rs232-baud - choose the speed of EMULATED RS232 device, this is the baud rate you select on Speccy, one of 50, 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200 (9600 is the default)
    --ay-io-rs232-rx FILE - attach source of the incoming bytes
    --ay-io-rs232-tx FILE - attach destination for the outgoing bytes

    'rx' file is opened for reading, 'tx' file is opened for writing. If both 'rx' and 'tx' point to the same file it is opened only once in read-write mode. Which makes it possible to use serial device directly. However, in this case you need to make sure device is configured properly, e.g. using stty or any other means.

    You can supply all of the available command line switches and choose between MIDI and RS232 during runtime using Options -> Peripherals -> AY IO Port.. (NOTE: Speccy has a single socket for RS232 and MIDI and uses conflicting pins, it is impossible to connect both RS232 and MIDI at the same time to the 128/+2/+3 models).

    MIDI example (don't forget to launch a MIDI synth and attach aMIDIcat output):

    mkfifo midi-tx
    amidicat midi-tx &
    fuse -m 128 --ay-io-device MIDI --ay-io-midi-tx midi-tx zxmidip3.trd
    

    Direct physical port access:

    fuse -m 128 --ay-io-device RS232 --ay-io-rs232-baud 57600 --ay-io-rs232-rx /dev/ttyUSB0 --ay-io-rs232-tx /dev/ttyUSB0 uart.tap
    

    Indirect physical port access:

    mkfifo rs232-rx rs232-tx
    socat /dev/ttyUSB0,b115200,raw,echo=0 - < rs232-tx > rs232-rx &
    fuse -m scorpion --ay-io-device RS232 --ay-io-rs232-baud 9600 --ay-io-rs232-rx rs232-rx --ay-io-rs232-tx rs232-tx MRF.TRD
    

    Note: physical port baud rate is completely independent from the FUSE's internal baud rate.

    Patch is tested with the following software:
    - ZX MIDI Player - https://github.com/UzixLS/zx-midiplayer
    - MRF Gopher Client - https://github.com/Kulicheg/MRF
    - Simple serial "terminal" - https://codeberg.org/TIsland/zx-uart-ay
    - CP/M Plus and QTPLUS3

    Updated: May 30, 2024 - fixed a bug in DTS signal handling, that was breaking CP/M because, unlike modern software, it expects full handshake enabled by default.

     

    Last edit: Vic Chwe 2024-05-30
  • Vic Chwe

    Vic Chwe - 2024-05-30

    The patch is not compatible with the modern high speed software, like sercp. I presume the tstates-based "timer emulation" is not precise enough. If I tweak the code to send each bit every 90 tstates for 38400 and every 30 tstates for 115200, the sercp 0.8 works. However, lookin at the sercp code, it actually spends 91 and 31 tstates polling each bit at 38400 and 115200 respectively.

    However, it seems to be compatible with anything using ROM or CP/M routines for RS232/MIDI comms.


     
  • Vic Chwe

    Vic Chwe - 2024-06-02

    (Hopefully) the final version of the patch, includes UI elements and man page.

    Things that can be improved:
    - printer support can be streamlined, I did not touch existing printer code on purpose
    - Win32 port

     

    Last edit: Vic Chwe 2024-06-02

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.