Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,328 @@
|
||||
========================================================================
|
||||
DYNAMIC LINK LIBRARY : acia Project Overview
|
||||
========================================================================
|
||||
|
||||
Acia.dll is a Vcc add-on that attempts to emulate the Deluxe RS232
|
||||
program pack. It allows connection to windows serial ports and a
|
||||
tcpip server. It also allows reading/writing windows files and
|
||||
interaction with the Vcc console.
|
||||
|
||||
Issues
|
||||
------
|
||||
1) Baud rates are not very accurate.
|
||||
2) No hardware flow control other than RxF and TxE signals
|
||||
3) DLL does not exit if Vcc crashes. (Issue with all Vcc Dll's)
|
||||
4) No detection of serial port "modem" events when reading:
|
||||
Break, ring, CTS, DSR, RX and DX changes, etc.
|
||||
|
||||
Would be nice
|
||||
-------------
|
||||
1) Support for second sc6551 device
|
||||
|
||||
Acia Quick Start
|
||||
----------------
|
||||
To use acia.dll insert it in the cartridge slot or a MPI slot.
|
||||
This will cause "Acia Config" to be added to the Cartridge menu.
|
||||
Clicking on this menu item allows selection of one of the acia
|
||||
modes: Console, File read, File write, TCPIP (client), and COMx.
|
||||
The Name and Port fields are used to set parameters for modes
|
||||
that require them. The text mode check box when checked causes
|
||||
acia.dll to do CR <-> CRLF translations when using the file
|
||||
read and write modes. The default mode is CONSOLE.
|
||||
|
||||
For a quick test leave the ACIA config mode set to console
|
||||
and enter and run the following basic program. (You can cut
|
||||
and paste using Vcc Edit -> Paste Basic Code)
|
||||
|
||||
10 POKE &HFF6A,1
|
||||
20 IF (PEEK(&HFF69) AND 8)=0 THEN 20
|
||||
30 PRINT CHR$(PEEK(&HFF68));
|
||||
40 GOTO20
|
||||
|
||||
The Vcc console should come up. The console is a CMD type window
|
||||
that is connected to the ACIA. Anything typed in the console
|
||||
will be read and printed by the basic program. To close the
|
||||
console POKE &FF6A,0 or press F5 from the Vcc window.
|
||||
|
||||
The following program does the opposite, characters typed in the
|
||||
Vcc window are written to the console and CR writes CRLF:
|
||||
|
||||
10 POKE &HFF6A,1
|
||||
20 K$=INKEY$: IF K$="" THEN 20
|
||||
30 C=ASC(K$)
|
||||
40 IF (PEEK(&HFF69) AND 16)=0 THEN 40
|
||||
50 POKE &HFF68,C
|
||||
60 IF C<>13 THEN 20
|
||||
70 C=10: GOTO 40
|
||||
|
||||
Console mode is most useful when using Os9 which is described later.
|
||||
|
||||
Radio Shack Deluxe RS232 program Pak
|
||||
-------------------------------------
|
||||
|
||||
If the file "rs232.rom" is in the Vcc execution directory it will
|
||||
be automatically loaded when acia.dll is selected but not started.
|
||||
To start it do "EXEC &HE010" from RSDOS command prompt. The rom
|
||||
is a copy of the 4K rom from the Radio Shack Deluxe RS232 program
|
||||
Pack. If a different ROM is used it must be 4096 bytes long. Note
|
||||
that if acia.dll is in a MPI slot but not selected it can still be
|
||||
used but the pack rom will not be accessible. To exec the rom
|
||||
type EXEC&HE010 at the basic prompt. Note that the pak currently
|
||||
has trouble with the "goto basic" function on Vcc which limits its
|
||||
usefulness. Suggestions for a solution would be appreciated.
|
||||
|
||||
SC6551 Operation
|
||||
----------------
|
||||
|
||||
The sc6551 emulation is controlled one of two blocks of port addresses,
|
||||
0xFF68-0xFF6B or 0xFF68-0xFF6F, the block used is selected by a Acia
|
||||
config dialog Radio button. The CPU controls the sc6551 by writing
|
||||
to these addresses and gets status and data from the sc6551 by reading
|
||||
them. A sc6551 datasheet will explain these in detail - what follows is
|
||||
a brief explaination of the most important bits to acia.dll.
|
||||
|
||||
0xFF68 (0xFF6C) is the data register. A write to the address will transmit
|
||||
a byte of data and a read will receive a byte of data.
|
||||
|
||||
0xFF69 (0xFF6D) is the status byte. The CPU reads this port to determine
|
||||
the status of the sc6551. Bits 0, 1, and 2 of the status byte are
|
||||
error indicators. Bit 3 indicates that a data byte is ready to read.
|
||||
Bit 4 indicates that the sc6551 is ready to transmit a byte. Bits
|
||||
5 and 6 are modem and data set ready bits, and Bit 7 indicates the
|
||||
sc6551 has asserted and IRQ. Acia.dll does not set the error bits and
|
||||
bits 5 and 6 are always clear to indicate mode and data ready states.
|
||||
|
||||
Data flow is controlled by status bit 3 (RxF) and bit 4 (TxE). When
|
||||
the CPU wants to send data it first must verify bit 4 (TxE) is set before
|
||||
writing to the data register, and when it wants to recieve data it must
|
||||
first check that bit 3 (RxF) is set before reading the data register.
|
||||
|
||||
Acia.dll will assert an IRQ and set status bit 7 when data becomes ready
|
||||
to read if Bit 1 of the command register (0xFF6A (0xFF6E)) is clear. The coco can
|
||||
use the interrupt to reduce input polling.
|
||||
|
||||
0xFF6A (0xFF6E) is the command register. Bit 0 of the command register is the
|
||||
DTR bit. This bit enables or disables the sc6551. If this bit is set
|
||||
by the coco CPU then communications are active (open) and if it is
|
||||
cleared communications are inactive (closed). Other command register
|
||||
bits set IRQ behavior and parity. Refer to data sheet for details.
|
||||
|
||||
0xFF6B (0xFF6F) is the control register. Bits 0-3 of the control register set
|
||||
the baud rate according to the following table. Datasheet rates that
|
||||
are not supported by acia.dll have replaced by the next higher value.
|
||||
Acia.dll uses screen sync signal to time the input speeds. These
|
||||
are only approximate and if F8 is toggled (Screen refresh throttle)
|
||||
the rates are invalid.
|
||||
|
||||
val rate val rate
|
||||
0 MAX 8 1200
|
||||
1 75 9 2400
|
||||
2 75 10 2400
|
||||
3 110 11 4800
|
||||
4 300 12 4899
|
||||
5 300 13 9600
|
||||
6 300 14 9600
|
||||
7 600 15 19200
|
||||
|
||||
Bits 5 and 6 of 0xFF6B (0xFF6F) set the data length and Bit 7 sets the number
|
||||
of stop bits. B5-6: 00=8 01=7 10=6 11=5 len. B7 0=1, 1=2 stops.
|
||||
|
||||
Basic programs can enable acia by poking 1 to &HFF6A and disable it by
|
||||
poking 0. They can then peek &HFF69 and test the result for RxF by
|
||||
anding 8 or test for TxE by anding 16. Then peek &HFF68 to read data
|
||||
and poke &HFF68 to write it.
|
||||
|
||||
To demonstrate here is a simple Basic program that will read data
|
||||
from the emulated acia:
|
||||
|
||||
10 POKE &HFF6A,1
|
||||
20 S=PEEK(&HFF69) AND 8
|
||||
30 IF S=0 THEN 20
|
||||
40 PRINT CHR$(PEEK(&HFF68));
|
||||
50 GOTO20
|
||||
|
||||
To test it set the Acia Config dialog to read a text file from the PC.
|
||||
(Filename is relative to user directory). When the program is run
|
||||
Basic will print it's contents. If you press break and then continue
|
||||
the program will resume printing where it left off. If you poke 0 to
|
||||
&HFF6A acia will close the file and when the program is run again it
|
||||
will reopen and start from the file's beginning.
|
||||
|
||||
Since the baud rate has not been set acia defaults to 0 which is max
|
||||
speed. In this case the program's output is throttled by the PRINT
|
||||
rate. If F8 is toggled it runs much faster.
|
||||
|
||||
This simple program does not check for end of file so you have to use
|
||||
break to end it because acia.dll will endlessly send EOF and CR
|
||||
sequences as basic attempts to read past the end of file.
|
||||
|
||||
More detail on file read mode can be found later in this document.
|
||||
|
||||
RS232.ROM
|
||||
---------
|
||||
|
||||
If the file "rs232.rom" is in the Vcc execution directory it will
|
||||
be automatically loaded when acia.dll is selected but not started.
|
||||
(make sure Autostart Cart in Misc Config dialog is unchecked)
|
||||
To start it do "EXEC &HE010" from RSDOS command prompt. The rom
|
||||
is a copy of the 4K rom from the Radio Shack Deluxe RS232 program
|
||||
Pack. The RS232 rom is only usefull if FF68 (RS-232 Pak) is selected
|
||||
in the config dialog. If a different ROM is used it must be 4096
|
||||
bytes long. Note that if acia.dll is in a MPI slot but not selected
|
||||
it can still be used but the pack rom will not be accessible.
|
||||
|
||||
Communications Modes
|
||||
--------------------
|
||||
|
||||
Communications modes are set using the Acia Interface config dialog
|
||||
which can be reached from the Vcc Cartridge menu when the DLL is
|
||||
loaded. The dialog has radio buttons for Console, File read,
|
||||
File write, TCPIP, and COMx modes of operation. When activated
|
||||
Console mode brings up the Vcc console window. File write mode
|
||||
causes all data output to go to a file. File read mode does the
|
||||
reverse; data is input from a file. TCPIP mode establishes a
|
||||
client connection with a network server and Comx mode establishes
|
||||
a connection with a windows serial port. When File read or Write
|
||||
mode is selected the filename relative to user home directory
|
||||
must be inserted into the Name field. When COMx mode is selected
|
||||
the port name (eg: COM3) must be placed in the Name field with no
|
||||
leading blanks. When TCPIP mode is selected the server address
|
||||
must be in the Name field and the port number in the Port field.
|
||||
Additional detail of these modes follows.
|
||||
|
||||
Console mode
|
||||
------------
|
||||
|
||||
Console mode can be useful when using (Nitr)Os9 and the t2 device
|
||||
and associated sc6551 driver. t2 and sc6551 must both be loaded at
|
||||
boot (in the boot track) to work properly. The t2 device can also
|
||||
be used for testing purposes, which is why it was originally created.
|
||||
Note that the stock t2 driver assumes the Acia Address is FF68.
|
||||
|
||||
Caution: There can only be one console associated with Vcc. Conflicts
|
||||
will occur is the console is used for other purposes, such as for
|
||||
debug logging.
|
||||
|
||||
/t2 settings for Windows conso1le should be as follows:
|
||||
|
||||
xmode /t2
|
||||
-upc -bsb bsl echo lf null=0 pause pag=32 bsp=08
|
||||
del=18 eor=0D eof=1B reprint=09 dup=19 psc=17 abort=03
|
||||
quit=05 bse=08 bell=07 type=80 baud=06 xon=11 xoff=13
|
||||
|
||||
Some of these settings are not honored by the sc6551 driver.
|
||||
Xon, Xoff, and baud xmode settings seem to have no effect.
|
||||
|
||||
The console uses standard OS9 text window settings. Acia.dll
|
||||
will translate many OS9 text screen control codes to do the
|
||||
proper console functions. Colors default to white on black.
|
||||
Only colors 0-7 are supported.
|
||||
|
||||
To launch a shell simply do: shell i=/t2 and the console
|
||||
will come up. Typing "ex" in the console window causes the
|
||||
console to close.
|
||||
|
||||
The console handles scrolling fairly well. The windows system
|
||||
automatically moves the console window within the screen buffer
|
||||
to keep the cursor visible. This causes text to appear to scroll
|
||||
as long as the cursor is within the boundaries of the buffer.
|
||||
|
||||
By default the windows screen buffer is large but eventually it
|
||||
becomes full. To handle this acia.dll deletes lines from the top of
|
||||
the buffer when the cursor tries to move to a line below the bottom.
|
||||
This affects full screen editors. They use cursor move sequences
|
||||
to control positioning within the screen boundaries but must scroll
|
||||
text when the cursor tries to move beyond the screen boundaries.
|
||||
|
||||
Vim (fixed tsedit) works pretty well. It takes care of deleting lines
|
||||
from the top of the screen when the cursor nears the bottom and
|
||||
replaces the lines when scrolling up. Vim seems to be hard coded to
|
||||
24 lines so the screen must be at least 24 lines long. (changing
|
||||
tspars or typing v to set the screen type does not work for me)
|
||||
|
||||
Scred assumes the terminal will delete lines from the top of the
|
||||
screen when the cursor is at the bottom of the screen. (emphasis on
|
||||
screen) This means screen length must match what scred thinks for
|
||||
it to work properly. Since acia.dll console does the delete based
|
||||
on buffer size it actually is that size that scred must be aware of.
|
||||
Fix it to set the screen buffer to a reasonable size and use scred's
|
||||
-l=<screen buffer len> argument. (500 lines still seems to work
|
||||
but I don't use scred much). The size of the buffer can be changed
|
||||
from the windows properties menu in the console title bar.
|
||||
|
||||
I did a brief check of uemacs. It seems to work okay except I find
|
||||
the lack of support of arrow keys annoying and I am too used to
|
||||
vi's use of hjkl for cursor position to adapt to emacs.
|
||||
|
||||
|
||||
File Read and File Write Modes
|
||||
------------------------------
|
||||
|
||||
File modes allow reading or writing to/from a windows file. After
|
||||
selecting the appropriate radio button in the Acia Interface config
|
||||
dialog the file name relative to user home directory should be
|
||||
entered in the Name field. For example: "test\myfile.txt" in the
|
||||
name field refers to %USERPROFILE%\test\myfile.txt
|
||||
|
||||
There are two file modes, File Read and File Write. Read mode
|
||||
causes acia to receive characters from the file specified and
|
||||
write mode sends charactes. Writes in read mode are ignored
|
||||
and reads in write mode returns nulls.
|
||||
|
||||
It is sometimes best to turn off local echo and pause on the
|
||||
os9 /t2 device to avoid I/O errors, eg: xmode /t2 -echo -pause
|
||||
|
||||
Text mode. When text mode is checked end of line translations
|
||||
(CR <-> CRLF). This is recommended when using /t2 in os9 unless
|
||||
attempting to write binary files to windows. Reading binary files
|
||||
is difficult under os9 because the sc6551 driver does not report
|
||||
end of file conditions. To avoid hangs acia.dll returns a <CR><ESC>
|
||||
sequence when an attempt is made to read past the end of a file
|
||||
regardless of text mode settings.
|
||||
|
||||
Sending command output to a file can be done with something like
|
||||
'dir -e > /t2' If doing a long listing it is better to place the
|
||||
output in a os9 file and copy that to /t2, for example:
|
||||
|
||||
dir -e -x > cmds.list
|
||||
copy cmds.list /t2
|
||||
|
||||
When using other programs to read or write files it is important
|
||||
to note that setting DTR opens the file and clearing DTR closes
|
||||
it. The NitrOS9 driver takes care of this but many terminal
|
||||
programs do not. DTR is controlled by bit 0 in 0xFF6A (0xFF6E).
|
||||
|
||||
TCPIP Mode
|
||||
----------
|
||||
|
||||
TCPIP mode causes acia to do a client connection to a tcpip server.
|
||||
After selecting TCPIP radio button on the Acia config dialog the
|
||||
server hostname or IP address should be entered in the Name field
|
||||
(default is localhost) and the server port in the Port field. Setting
|
||||
bit 0 in 0xFF6A (0xFF6E) opens the connection and clearing it closes it.
|
||||
|
||||
Testing tcpip mode was done using netcat on Linux as a server.
|
||||
On Linux ' nc -l -p 48000' 48000 is the port number I am using.
|
||||
After launching a shell connected to /t2 on (Nitr)Os9 the Linux
|
||||
session becomes a terminal connected to Os9.
|
||||
|
||||
Also Twilight Term (TWI-TERM.BIN) was used to test connection with
|
||||
a telnet BBS on the internet. (Set the address on the BBS in the
|
||||
acia interface config name field and 23 in the port field)
|
||||
|
||||
COMx Serial Port Mode
|
||||
----------------------
|
||||
|
||||
After selecting COMx radio button the port name should be entered
|
||||
in the Name field, for example "COM3". Leading blanks will not
|
||||
work, port name must be left justified.
|
||||
|
||||
Valid baud rates are 110,300,600,1200,2400,4800,9600,19200
|
||||
|
||||
Testing of the COM port mode was done using a com0com port emulator
|
||||
in windows along with putty. com0com is used to 'wire' two psuedo
|
||||
port COM20 and COM21 together. I used acia.dll to connect to COM20
|
||||
and PuTTy to connect to COM21. This allowed me to simulate connecting
|
||||
with a terminal. Also tested with a USRobotics faxmodem via a Radio
|
||||
Shack USB to serial adapter and the legacy USBSER driver.
|
||||
|
||||
@@ -0,0 +1,616 @@
|
||||
//#define USE_LOGGING
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// NOTE: Due to changes in interupt handling this version will not work
|
||||
// properly before VCC 2.1.9.2 (Console mode Nitros9 using /t2 broken)
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#include "acia.h"
|
||||
#include <vcc/util/limits.h>
|
||||
#include <vcc/util/DialogOps.h>
|
||||
#include <vcc/util/logger.h>
|
||||
#include <vcc/bus/cartridge_menu.h>
|
||||
#include <vcc/util/settings.h>
|
||||
|
||||
// Access the settings object
|
||||
static VCC::Util::settings* gpSettings = nullptr;
|
||||
VCC::Util::settings& Setting() {return *gpSettings;}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Local Functions
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
LRESULT CALLBACK Config(HWND, UINT, WPARAM, LPARAM);
|
||||
void LoadConfig();
|
||||
void SaveConfig();
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Pak host
|
||||
//------------------------------------------------------------------------
|
||||
slot_id_type gSlotId;
|
||||
|
||||
PakAssertInteruptHostCallback AssertInt = nullptr;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Globals
|
||||
//------------------------------------------------------------------------
|
||||
static HINSTANCE gModuleInstance; // DLL handle
|
||||
static HWND g_hDlg = nullptr; // Config dialog
|
||||
static char IniSect[MAX_LOADSTRING]; // Ini file section
|
||||
|
||||
// Status for Vcc status line
|
||||
char AciaStat[32];
|
||||
|
||||
// Some strings for config dialog
|
||||
char *IOModeTxt[] = {"RW","R","W"};
|
||||
char *ComTypeTxt[] = {"CONS","FILE","TCP","COM"};
|
||||
|
||||
int AciaBasePort; // Base port for sc6651 (0x68 or 0x6C)
|
||||
int AciaComType; // Console,file,tcpip,wincom
|
||||
int AciaComMode; // Duplex,read,write
|
||||
int AciaTextMode; // CR and EOF translations 0=none 1=text
|
||||
int AciaLineInput; // Console line mode 0=Normal 1=Linemode
|
||||
char AciaTcpPort[32]; // TCP port 1024-65536
|
||||
char AciaComPort[32]; // Windows Serial port eg COM20
|
||||
char AciaTcpHost[MAX_PATH]; // Tcpip hostname
|
||||
char AciaFileRdPath[MAX_PATH]; // Path for file reads
|
||||
char AciaFileWrPath[MAX_PATH]; // Path for file writes
|
||||
|
||||
static unsigned char Rom[8192];
|
||||
unsigned char LoadExtRom(const char *);
|
||||
|
||||
static VCC::Bus::cartridge_menu AciaMenu {};
|
||||
bool get_menu_item(menu_item_entry* item, size_t index);
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// DLL Entry point
|
||||
//------------------------------------------------------------------------
|
||||
BOOL APIENTRY
|
||||
DllMain(HINSTANCE hinst, DWORD reason, LPVOID foo)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH)
|
||||
{
|
||||
gModuleInstance = hinst;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) const char* PakGetName()
|
||||
{
|
||||
static char string_buffer[MAX_LOADSTRING];
|
||||
|
||||
LoadString(gModuleInstance, IDS_MODULE_NAME, string_buffer, MAX_LOADSTRING);
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
__declspec(dllexport) const char* PakGetCatalogId()
|
||||
{
|
||||
static char string_buffer[MAX_LOADSTRING];
|
||||
|
||||
LoadString(gModuleInstance, IDS_CATNUMBER, string_buffer, MAX_LOADSTRING);
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
__declspec(dllexport) const char* PakGetDescription()
|
||||
{
|
||||
static char string_buffer[MAX_LOADSTRING];
|
||||
|
||||
LoadString(gModuleInstance, IDS_DESCRIPTION, string_buffer, MAX_LOADSTRING);
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakInitialize(
|
||||
slot_id_type SlotId,
|
||||
const char* const configuration_path,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks* const callbacks)
|
||||
{
|
||||
gSlotId = SlotId;
|
||||
AssertInt = callbacks->assert_interrupt;
|
||||
|
||||
gpSettings = new VCC::Util::settings(configuration_path);
|
||||
LoadConfig();
|
||||
LoadExtRom("RS232.ROM");
|
||||
sc6551_init();
|
||||
}
|
||||
__declspec(dllexport) void PakTerminate()
|
||||
{
|
||||
CloseCartDialog(g_hDlg);
|
||||
sc6551_close();
|
||||
AciaStat[0]='\0';
|
||||
}
|
||||
|
||||
__declspec(dllexport) bool PakGetMenuItem(menu_item_entry* item, size_t index)
|
||||
{
|
||||
return get_menu_item(item, index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export write to port
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) void
|
||||
PakWritePort(unsigned char Port,unsigned char Data)
|
||||
{
|
||||
sc6551_write(Data,Port);
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export read from port
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) unsigned char
|
||||
PakReadPort(unsigned char Port)
|
||||
{
|
||||
return sc6551_read(Port);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export module reset
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) void PakReset()
|
||||
{
|
||||
sc6551_close();
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export pak rom read
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) unsigned char PakReadMemoryByte(unsigned short Address)
|
||||
{
|
||||
return(Rom[Address & 8191]);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Load Rom. Returns 1 if loaded
|
||||
//-----------------------------------------------------------------------
|
||||
unsigned char LoadExtRom(const char *FilePath)
|
||||
{
|
||||
FILE *file;
|
||||
int cnt = 0;
|
||||
memset(Rom, 0xff, 8191);
|
||||
file = fopen(FilePath, "rb");
|
||||
if (file) {
|
||||
unsigned char *p = Rom;
|
||||
while (cnt++ < 4096) {
|
||||
if (feof(file)) break;
|
||||
*p++ = fgetc(file);
|
||||
}
|
||||
fclose(file);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export Heartbeat (HSYNC)
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) void PakProcessHorizontalSync()
|
||||
{
|
||||
sc6551_heartbeat();
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export return module status for VCC status line
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) void PakGetStatus(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
strncpy(text_buffer, AciaStat, buffer_size);
|
||||
text_buffer[16] = '\n';
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Dll export run config dialog
|
||||
//-----------------------------------------------------------------------
|
||||
extern "C"
|
||||
__declspec(dllexport) void PakMenuItemClicked(unsigned char /*MenuID*/)
|
||||
{
|
||||
HWND owner = GetActiveWindow();
|
||||
CreateDialog(gModuleInstance,(LPCTSTR)IDD_PROPPAGE,owner,(DLGPROC)Config);
|
||||
ShowWindow(g_hDlg,1);
|
||||
return;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Return acia menu items
|
||||
//-----------------------------------------------------------------------
|
||||
bool get_menu_item(menu_item_entry* item, size_t index) {
|
||||
if (!item) return false;
|
||||
if (index == 0) {
|
||||
AciaMenu.clear();
|
||||
AciaMenu.add("", 0, MIT_Seperator);
|
||||
AciaMenu.add("ACIA Config", ControlId(16), MIT_StandAlone);
|
||||
}
|
||||
return AciaMenu.copy_item(*item, index);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Load saved config from ini file
|
||||
//----------------------------------------------------------------------
|
||||
void LoadConfig()
|
||||
{
|
||||
AciaComType=Setting().read("Acia","AciaComType",
|
||||
COM_CONSOLE);
|
||||
AciaComMode=Setting().read("Acia","AciaComMode",
|
||||
COM_MODE_DUPLEX);
|
||||
AciaBasePort=Setting().read("Acia","AciaBasePort",
|
||||
BASE_PORT_RS232);
|
||||
AciaTextMode=Setting().read("Acia","AciaTextMode",0);
|
||||
Setting().read("Acia","AciaComPort","COM3",
|
||||
AciaComPort,32);
|
||||
Setting().read("Acia","AciaFileRdPath","AciaFile.txt",
|
||||
AciaFileRdPath, MAX_PATH);
|
||||
Setting().read("Acia","AciaFileWrPath","AciaFile.txt",
|
||||
AciaFileWrPath, MAX_PATH);
|
||||
Setting().read("Acia","AciaTcpHost","localhost",
|
||||
AciaTcpHost, MAX_PATH);
|
||||
Setting().read("Acia","AciaTcpPort","48000",
|
||||
AciaTcpPort,32);
|
||||
|
||||
// String for Vcc status line
|
||||
switch (AciaComType) {
|
||||
case COM_FILE:
|
||||
if (AciaComMode == COM_MODE_READ)
|
||||
sprintf(AciaStat,"Acia R");
|
||||
else
|
||||
sprintf(AciaStat,"Acia W");
|
||||
break;
|
||||
case COM_TCPIP:
|
||||
sprintf(AciaStat,"Acia tcpip");
|
||||
break;
|
||||
case COM_WINCOM:
|
||||
sprintf(AciaStat,"Acia %s",AciaComPort);
|
||||
break;
|
||||
case COM_CONSOLE:
|
||||
default:
|
||||
sprintf(AciaStat,"Acia Cons");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Save config to ini file
|
||||
//----------------------------------------------------------------------
|
||||
void SaveConfig()
|
||||
{
|
||||
Setting().write("Acia","AciaBasePort",AciaBasePort);
|
||||
Setting().write("Acia","AciaComType",AciaComType);
|
||||
Setting().write("Acia","AciaComMode",AciaComMode);
|
||||
Setting().write("Acia","AciaTcpPort",AciaTcpPort);
|
||||
Setting().write("Acia","AciaTextMode",AciaTextMode);
|
||||
Setting().write("Acia","AciaComPort",AciaComPort);
|
||||
Setting().write("Acia","AciaFileRdPath",AciaFileRdPath);
|
||||
Setting().write("Acia","AciaFileWrPath",AciaFileWrPath);
|
||||
Setting().write("Acia","AciaTcpHost",AciaTcpHost);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Config dialog.
|
||||
// Radio Buttons: (I/O Type) :
|
||||
// IDC_T_CONS I/O is to windows console
|
||||
// IDC_T_FILE_R Input from file (Output to bit bucket)
|
||||
// IDC_T_FILE_W Output to file, Input returns null
|
||||
// IDC_T_TCP I/O to TCPIP port
|
||||
// IDC_T_COM I/O to windows COM port
|
||||
// Text Boxes
|
||||
// IDC_PORT Port for TCP and COM Number
|
||||
// IDC_NAME File name for FILE_R and FILE_W Host name for TCPIP
|
||||
// Check Box
|
||||
// IDC_TEXTMODE Translate CR <> CRLF if checked
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
LRESULT CALLBACK Config(HWND hDlg,UINT msg,WPARAM wParam,LPARAM /*lParam*/)
|
||||
{
|
||||
int button;
|
||||
HWND hCtl;
|
||||
int port;
|
||||
switch (msg) {
|
||||
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hDlg);
|
||||
g_hDlg = nullptr;
|
||||
return TRUE;
|
||||
|
||||
case WM_INITDIALOG:
|
||||
|
||||
// Kill previous instance
|
||||
DestroyWindow(g_hDlg);
|
||||
g_hDlg = hDlg;
|
||||
|
||||
CenterDialog(hDlg);
|
||||
|
||||
// Set Button as per Base Port
|
||||
switch (AciaBasePort) {
|
||||
case BASE_PORT_RS232:
|
||||
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
|
||||
CheckDlgButton(hDlg,IDC_T_MODEM,BST_UNCHECKED);
|
||||
break;
|
||||
case BASE_PORT_MODEM:
|
||||
CheckDlgButton(hDlg,IDC_T_RS232,BST_UNCHECKED);
|
||||
CheckDlgButton(hDlg,IDC_T_MODEM,BST_CHECKED);
|
||||
break;
|
||||
default:
|
||||
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
|
||||
CheckDlgButton(hDlg,IDC_T_MODEM,BST_UNCHECKED);
|
||||
AciaBasePort = BASE_PORT_RS232;
|
||||
break;
|
||||
}
|
||||
|
||||
// Set Radio Button as per com type
|
||||
switch (AciaComType) {
|
||||
|
||||
case COM_FILE:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
if (AciaComMode == COM_MODE_READ) {
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaFileRdPath);
|
||||
button = IDC_T_FILE_R;
|
||||
sprintf(AciaStat,"Acia file R");
|
||||
} else {
|
||||
// If file mode default to write
|
||||
AciaComMode = COM_MODE_WRITE;
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaFileWrPath);
|
||||
button = IDC_T_FILE_W;
|
||||
sprintf(AciaStat,"Acia file W");
|
||||
}
|
||||
SetDlgItemText(hDlg,IDC_PORT,"");
|
||||
break;
|
||||
|
||||
case COM_TCPIP:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),TRUE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
button = IDC_T_TCP;
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaTcpHost);
|
||||
SetDlgItemText(hDlg,IDC_PORT,AciaTcpPort);
|
||||
sprintf(AciaStat,"Acia tcpip");
|
||||
break;
|
||||
|
||||
case COM_WINCOM:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
button = IDC_T_COM;
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaComPort);
|
||||
sprintf(AciaStat,"Acia %s",AciaComPort);
|
||||
break;
|
||||
|
||||
case COM_CONSOLE:
|
||||
default:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),FALSE);
|
||||
button = IDC_T_CONS;
|
||||
AciaComType = COM_CONSOLE;
|
||||
SetDlgItemText(hDlg,IDC_NAME,"");
|
||||
SetDlgItemText(hDlg,IDC_PORT,"");
|
||||
sprintf(AciaStat,"Acia Console");
|
||||
break;
|
||||
}
|
||||
CheckRadioButton(hDlg,IDC_T_CONS,IDC_T_COM,button);
|
||||
|
||||
// Text mode check box
|
||||
hCtl = GetDlgItem(hDlg,IDC_TXTMODE);
|
||||
SendMessage(hCtl,BM_SETCHECK,AciaTextMode,0);
|
||||
|
||||
return TRUE;
|
||||
|
||||
case WM_COMMAND:
|
||||
|
||||
button = LOWORD(wParam);
|
||||
switch (button) {
|
||||
|
||||
// Close sc6551 before changing base port or com type
|
||||
case IDC_T_RS232:
|
||||
sc6551_close();
|
||||
AciaBasePort = BASE_PORT_RS232;
|
||||
break;
|
||||
|
||||
case IDC_T_MODEM:
|
||||
sc6551_close();
|
||||
AciaBasePort = BASE_PORT_MODEM;
|
||||
break;
|
||||
|
||||
case IDC_T_CONS:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),FALSE);
|
||||
sc6551_close();
|
||||
AciaComType = COM_CONSOLE;
|
||||
AciaComMode = COM_MODE_DUPLEX;
|
||||
SetDlgItemText(hDlg,IDC_NAME,"");
|
||||
SetDlgItemText(hDlg,IDC_PORT,"");
|
||||
break;
|
||||
|
||||
case IDC_T_FILE_R:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
sc6551_close();
|
||||
AciaComType = COM_FILE;
|
||||
AciaComMode = COM_MODE_READ;
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaFileRdPath);
|
||||
SetDlgItemText(hDlg,IDC_PORT,"");
|
||||
break;
|
||||
|
||||
case IDC_T_FILE_W:
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
sc6551_close();
|
||||
AciaComType = COM_FILE;
|
||||
AciaComMode = COM_MODE_WRITE;
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaFileWrPath);
|
||||
SetDlgItemText(hDlg,IDC_PORT,"");
|
||||
break;
|
||||
|
||||
case IDC_T_TCP: // tcpip
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),TRUE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
sc6551_close();
|
||||
AciaComType = COM_TCPIP;
|
||||
AciaComMode = COM_MODE_DUPLEX;
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaTcpHost);
|
||||
SetDlgItemText(hDlg,IDC_PORT,AciaTcpPort);
|
||||
break;
|
||||
|
||||
case IDC_T_COM: // COMx
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_PORT),FALSE);
|
||||
EnableWindow(GetDlgItem(hDlg,IDC_NAME),TRUE);
|
||||
sc6551_close();
|
||||
AciaComType = COM_WINCOM;
|
||||
AciaComMode = COM_MODE_DUPLEX;
|
||||
SetDlgItemText(hDlg,IDC_PORT,"");
|
||||
SetDlgItemText(hDlg,IDC_NAME,AciaComPort);
|
||||
break;
|
||||
|
||||
case IDOK:
|
||||
case IDAPPLY:
|
||||
// Text mode check box
|
||||
hCtl = GetDlgItem(hDlg,IDC_TXTMODE);
|
||||
AciaTextMode = SendMessage(hCtl,BM_GETCHECK,0,0);
|
||||
|
||||
// Validate parameters
|
||||
switch (AciaComType) {
|
||||
case COM_CONSOLE:
|
||||
sprintf(AciaStat,"Acia Console");
|
||||
break;
|
||||
case COM_FILE:
|
||||
if (AciaComMode == COM_MODE_READ) {
|
||||
GetDlgItemText(hDlg,IDC_NAME,AciaFileRdPath,MAX_PATH);
|
||||
sprintf(AciaStat,"Acia file R");
|
||||
} else if (AciaComMode == COM_MODE_WRITE) {
|
||||
GetDlgItemText(hDlg,IDC_NAME,AciaFileWrPath,MAX_PATH);
|
||||
sprintf(AciaStat,"Acia file W");
|
||||
}
|
||||
break;
|
||||
case COM_TCPIP:
|
||||
GetDlgItemText(hDlg,IDC_NAME,AciaTcpHost,MAX_PATH);
|
||||
port = GetDlgItemInt(hDlg,IDC_PORT,nullptr,0);
|
||||
if ((port < 1) || (port > 65536)) {
|
||||
MessageBox(hDlg,"TCP Port must be 1 thru 65536",
|
||||
"Error", MB_OK|MB_ICONEXCLAMATION);
|
||||
return TRUE;
|
||||
}
|
||||
snprintf(AciaTcpPort,16,"%d",port);
|
||||
sprintf(AciaStat,"Acia tcpip");
|
||||
break;
|
||||
case COM_WINCOM:
|
||||
GetDlgItemText(hDlg,IDC_NAME,AciaComPort,32);
|
||||
sprintf(AciaStat,"Acia %s",AciaComPort);
|
||||
break;
|
||||
}
|
||||
|
||||
SaveConfig();
|
||||
|
||||
// Okay exits the dialog
|
||||
if (button==IDOK) {
|
||||
DestroyWindow(hDlg);
|
||||
g_hDlg = nullptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case IDHELP:
|
||||
break;
|
||||
|
||||
case IDCANCEL:
|
||||
DestroyWindow(hDlg);
|
||||
g_hDlg = nullptr;
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Dispatch I/0 to communication type used.
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
int com_open() {
|
||||
switch (AciaComType) {
|
||||
case COM_CONSOLE:
|
||||
return console_open();
|
||||
case COM_FILE:
|
||||
return file_open();
|
||||
case COM_TCPIP:
|
||||
return tcpip_open();
|
||||
case COM_WINCOM:
|
||||
return wincom_open();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void com_close() {
|
||||
switch (AciaComType) {
|
||||
case COM_CONSOLE:
|
||||
console_close();
|
||||
break;
|
||||
case COM_FILE:
|
||||
file_close();
|
||||
break;
|
||||
case COM_TCPIP:
|
||||
tcpip_close();
|
||||
break;
|
||||
case COM_WINCOM:
|
||||
wincom_close();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// com_write will block until some data is written or error
|
||||
int com_write(const char * buf, int len) {
|
||||
switch (AciaComType) {
|
||||
case COM_CONSOLE:
|
||||
return console_write(buf,len);
|
||||
case COM_FILE:
|
||||
return file_write(buf,len);
|
||||
case COM_TCPIP:
|
||||
return tcpip_write(buf,len);
|
||||
case COM_WINCOM:
|
||||
return wincom_write(buf,len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// com_read will block until some data is read or error
|
||||
int com_read(char * buf,int len) { // returns bytes read
|
||||
switch (AciaComType) {
|
||||
case COM_CONSOLE:
|
||||
return console_read(buf,len);
|
||||
case COM_FILE:
|
||||
return file_read(buf,len);
|
||||
case COM_TCPIP:
|
||||
return tcpip_read(buf,len);
|
||||
case COM_WINCOM:
|
||||
return wincom_read(buf,len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
#ifndef __ACIA_H_
|
||||
#define __ACIA_H_
|
||||
|
||||
// FIXME: This should be defined on the command line
|
||||
#define DIRECTINPUT_VERSION 0x0800
|
||||
#include <vcc/bus/cpak_cartridge_definitions.h>
|
||||
#include <Windows.h>
|
||||
#include <windowsx.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <dinput.h>
|
||||
#include "resource.h"
|
||||
|
||||
|
||||
// Text mode EOF character
|
||||
constexpr auto EOFCHR = 0x1Bu;
|
||||
|
||||
// Base Ports
|
||||
constexpr auto BASE_PORT_RS232 = 0x68u;
|
||||
constexpr auto BASE_PORT_MODEM = 0x6Cu;
|
||||
|
||||
// Communications type and mode enumerations
|
||||
enum com_type {
|
||||
COM_CONSOLE,
|
||||
COM_FILE,
|
||||
COM_TCPIP,
|
||||
COM_WINCOM
|
||||
};
|
||||
enum com_mode {
|
||||
COM_MODE_DUPLEX,
|
||||
COM_MODE_READ,
|
||||
COM_MODE_WRITE,
|
||||
};
|
||||
|
||||
// Handles for I/O threads
|
||||
extern HANDLE hInputThread;
|
||||
extern HANDLE hOutputThread;
|
||||
extern HANDLE hStopInput;
|
||||
extern HANDLE hStopOutput;
|
||||
|
||||
extern int AciaBasePort; // Base port for sc6651 (0x68 or 0x6C)
|
||||
extern int AciaComType; // Console,file,tcpip,wincom
|
||||
extern int AciaComMode; // Duplex,read,write
|
||||
extern int AciaTextMode; // CR and EOF translations 0=none 1=text
|
||||
extern int AciaLineInput; // Console line mode 0=Normal 1=Linemode
|
||||
extern char AciaTcpPort[32]; // TCP port 1024-65536
|
||||
extern char AciaComPort[32]; // Windows Serial port eg COM20
|
||||
extern char AciaTcpHost[MAX_PATH]; // Tcpip hostname
|
||||
extern char AciaFileRdPath[MAX_PATH]; // Path for file reads
|
||||
extern char AciaFileWrPath[MAX_PATH]; // Path for file writes
|
||||
|
||||
extern PakAssertInteruptHostCallback AssertInt;
|
||||
extern slot_id_type gSlotId;
|
||||
|
||||
// Device
|
||||
extern void sc6551_init();
|
||||
extern void sc6551_close();
|
||||
extern void sc6551_heartbeat();
|
||||
extern unsigned char sc6551_read(unsigned char data);
|
||||
extern void sc6551_write(unsigned char data, unsigned short port);
|
||||
|
||||
// Comunications hooks
|
||||
extern int com_open();
|
||||
extern void com_close();
|
||||
extern int com_write(const char*,int);
|
||||
extern int com_read(char*,int);
|
||||
|
||||
// Console
|
||||
extern int console_open();
|
||||
extern void console_close();
|
||||
extern int console_read(char*,int);
|
||||
extern int console_write(const char*,int);
|
||||
|
||||
// File
|
||||
extern int file_open();
|
||||
extern void file_close();
|
||||
extern int file_read(char*,int);
|
||||
extern int file_write(const char*,int);
|
||||
|
||||
// Tcpip
|
||||
extern int tcpip_open();
|
||||
extern void tcpip_close();
|
||||
extern int tcpip_read(char*,int);
|
||||
extern int tcpip_write(const char*,int);
|
||||
|
||||
// WinCom
|
||||
extern int wincom_open();
|
||||
extern void wincom_close();
|
||||
extern int wincom_read(char*,int);
|
||||
extern int wincom_write(const char*,int);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,162 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// acia.rc
|
||||
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Dialog
|
||||
//
|
||||
|
||||
IDD_PROPPAGE DIALOGEX 0, 0, 202, 185
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Acia Interface"
|
||||
FONT 8, "MS Sans Serif", 0, 0, 0x0
|
||||
BEGIN
|
||||
GROUPBOX "Type",IDC_STATIC,8,8,90,84,BS_CENTER
|
||||
CONTROL "CONSOLE", IDC_T_CONS, "Button",BS_AUTORADIOBUTTON|WS_GROUP,
|
||||
16,18,75,12
|
||||
CONTROL "FILE READ", IDC_T_FILE_R,"Button",BS_AUTORADIOBUTTON,
|
||||
16,31,75,12
|
||||
CONTROL "FILE WRITE",IDC_T_FILE_W,"Button",BS_AUTORADIOBUTTON,
|
||||
16,46,75,12
|
||||
CONTROL "TCPIP", IDC_T_TCP, "Button",BS_AUTORADIOBUTTON,
|
||||
16,60,75,12
|
||||
CONTROL "COMx", IDC_T_COM, "Button",BS_AUTORADIOBUTTON,
|
||||
16,74,75,12
|
||||
|
||||
GROUPBOX "Acia Address",IDC_STATIC,104,18,90,51,BS_CENTER
|
||||
CONTROL "FF68 (RS-232 Pak)",IDC_T_RS232,"Button",BS_AUTORADIOBUTTON|WS_GROUP,
|
||||
108,31,75,12
|
||||
CONTROL "FF6C (Modem Pak)", IDC_T_MODEM,"Button",BS_AUTORADIOBUTTON,
|
||||
108,46,75,12
|
||||
|
||||
LTEXT "Name:", IDC_STATIC,14,102, 20, 11
|
||||
EDITTEXT IDC_NAME, 40,100, 120,12,ES_AUTOHSCROLL|ES_LEFT
|
||||
LTEXT "Port:",IDC_STATIC, 14,120, 20, 11
|
||||
EDITTEXT IDC_PORT, 40,118, 30, 12,ES_AUTOHSCROLL|ES_NUMBER
|
||||
|
||||
CONTROL "Text Mode",IDC_TXTMODE,"Button",BS_AUTOCHECKBOX,
|
||||
18,136,50,12
|
||||
|
||||
DEFPUSHBUTTON "Ok", IDOK, 23,155,45,20
|
||||
PUSHBUTTON "APPLY", IDAPPLY, 75,155,45,20
|
||||
PUSHBUTTON "Cancel",IDCANCEL,128,155,45,20
|
||||
END
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// DESIGNINFO
|
||||
//
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
GUIDELINES DESIGNINFO
|
||||
BEGIN
|
||||
IDD_PROPPAGE, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 167
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 155
|
||||
END
|
||||
END
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Version
|
||||
//
|
||||
|
||||
#include <winver.h>
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 2,1,9,3
|
||||
PRODUCTVERSION 2,1,9,3
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS VS_FF_DEBUG
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS VOS__WINDOWS32
|
||||
FILETYPE VFT_DLL
|
||||
FILESUBTYPE VFT2_UNKNOWN
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Tandy Deluxe RS232 Pak"
|
||||
VALUE "CompanyName", "BitRot Software"
|
||||
VALUE "FileDescription", "acia"
|
||||
VALUE "FileVersion", "2.1.9.3"
|
||||
VALUE "InternalName", "SC6551 Interface"
|
||||
VALUE "LegalCopyright", "Copyright © 2023"
|
||||
VALUE "OriginalFilename", "acia.dll"
|
||||
VALUE "ProductName", "acia"
|
||||
VALUE "ProductVersion", "26-3124"
|
||||
VALUE "SpecialBuild", "Tandy Deluxe RS232 Pak"
|
||||
END
|
||||
END
|
||||
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_MODULE_NAME "RS232 Pak"
|
||||
IDS_CATNUMBER "26-2226"
|
||||
IDS_DESCRIPTION "Emulates 6551 UART. Communicate with windows terminal console, PC serial ports, Internet telnet servers, or read and write to a file."
|
||||
IDS_VERSION "1.00"
|
||||
END
|
||||
|
||||
#endif // English (United States) resources
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Legacy|Win32">
|
||||
<Configuration>Legacy</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<SccProjectName />
|
||||
<SccLocalPath />
|
||||
<ProjectGuid>{337BE96D-E8B6-4409-BBFD-0AD8C49AF94B}</ProjectGuid>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\vcc-base.props" />
|
||||
<Import Project="..\vcc-legacy.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\vcc-base.props" />
|
||||
<Import Project="..\vcc-release.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\vcc-base.props" />
|
||||
<Import Project="..\vcc-debug.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
<LibraryPath>C:\Program Files %28x86%29\Windows Kits\8.1\Lib\winv6.3\um\x86;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;ACIA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ResourceCompile />
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
<AdditionalDependencies>WS2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<FullProgramDatabaseFile>
|
||||
</FullProgramDatabaseFile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_USRDLL;ACIA_EXPORTS;_LEGACY_VCC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/arch:SSE</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
<AdditionalDependencies>WS2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;ACIA_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/arch:SSE</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<ResourceCompile />
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
<AdditionalDependencies>WS2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="acia.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<ClCompile Include="console.cpp" />
|
||||
<ClCompile Include="sc6551.cpp" />
|
||||
<ClCompile Include="file.cpp" />
|
||||
<ClCompile Include="tcpip.cpp" />
|
||||
<ClCompile Include="wincom.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="acia.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="acia.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\libcommon\libcommon.vcxproj">
|
||||
<Project>{e0aa25bd-5527-475f-8d8b-b549a6311b0c}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,626 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Console I/O
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#include "acia.h"
|
||||
|
||||
// Macros for key state modifiers
|
||||
#define modshift(state) (state & SHIFT_PRESSED)
|
||||
#define modctrl(state) (state & (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED))
|
||||
#define modalt(state) (state & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED))
|
||||
#define modextend(state) (state & ENHANCED_KEY)
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// private functions
|
||||
//------------------------------------------------------------------
|
||||
void console_scroll(int);
|
||||
void console_insertline();
|
||||
void console_deleteline();
|
||||
void console_move(int,int);
|
||||
void console_right();
|
||||
void console_left();
|
||||
void console_down();
|
||||
void console_up();
|
||||
void console_cls();
|
||||
void console_cleol();
|
||||
void console_cleob();
|
||||
void console_cr();
|
||||
void console_eraseline();
|
||||
void console_background(int);
|
||||
void console_forground(int);
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Globals
|
||||
//------------------------------------------------------------------
|
||||
HANDLE hConIn = nullptr; // Com input handle
|
||||
HANDLE hConOut = nullptr; // Com output handle
|
||||
CONSOLE_SCREEN_BUFFER_INFO Csbi; // Console buffer info
|
||||
|
||||
INPUT_RECORD KeyEvents[128]; // Buffer for keyboard records
|
||||
INPUT_RECORD *EventsPtr=KeyEvents; // Buffer pointer
|
||||
int Event_Cnt = 0; // Buffer count
|
||||
|
||||
// Table to translate CoCo color to console color
|
||||
// {white,blue,black,green,red,yellow,magenta,cyan}
|
||||
int color_tbl[8] = {0xF,0x1,0x0,0X2,0xC,0xE,0xD,0xB};
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Open Console
|
||||
//----------------------------------------------------------------
|
||||
|
||||
int
|
||||
console_open() {
|
||||
DWORD mode;
|
||||
|
||||
// Make sure console is closed first
|
||||
if ( hConOut != nullptr) console_close();
|
||||
if ( hConIn != nullptr) console_close();
|
||||
AllocConsole();
|
||||
|
||||
// Disable the close button and "Close" context menu item of the
|
||||
// Console window to prevent inadvertant exit of the emulator
|
||||
HWND hwnd = GetConsoleWindow();
|
||||
HMENU hmenu = GetSystemMenu(hwnd, FALSE);
|
||||
EnableMenuItem(hmenu, SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
|
||||
|
||||
hConIn=GetStdHandle(STD_INPUT_HANDLE);
|
||||
|
||||
// Allow quick edit and echo when in line mode
|
||||
mode = ENABLE_ECHO_INPUT |
|
||||
ENABLE_LINE_INPUT |
|
||||
ENABLE_QUICK_EDIT_MODE;
|
||||
SetConsoleMode(hConIn,mode);
|
||||
|
||||
FlushConsoleInputBuffer(hConIn);
|
||||
|
||||
// Default to raw mode.
|
||||
AciaLineInput = 0;
|
||||
|
||||
hConOut=GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
SetConsoleTitle("VCC Console");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Close Console
|
||||
//------------------------------------------------------------------
|
||||
|
||||
void console_close() {
|
||||
FreeConsole();
|
||||
hConOut = nullptr;
|
||||
hConIn = nullptr;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Read console. Blocks until at least one char is read.
|
||||
//----------------------------------------------------------------
|
||||
int console_read(char * buf, int len) {
|
||||
|
||||
char txt[64]; // For debug messages to win title
|
||||
|
||||
int ascii; // Ascii char code (zero for control codes)
|
||||
int scode; // windows scan code for key press
|
||||
int state; // key state flags (modifiers, extended keys)
|
||||
|
||||
int keypress_cnt = 0;
|
||||
unsigned char chr;
|
||||
|
||||
// Abort if console not open or no space in buffer
|
||||
if ( hConIn == nullptr) return 0;
|
||||
if (len < 1) return 0;
|
||||
|
||||
// If line mode return next line from keyboard buffer (blocks)
|
||||
if (AciaLineInput) {
|
||||
DWORD cnt = 0;
|
||||
ReadConsole(hConIn,buf,len,&cnt,nullptr);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
// If not line mode loop until at least one key press is found
|
||||
for(;;) {
|
||||
|
||||
// If Event buffer is empty load it (blocks)
|
||||
if (Event_Cnt < 1) {
|
||||
EventsPtr = KeyEvents;
|
||||
DWORD cnt = 0;
|
||||
ReadConsoleInput(hConIn,KeyEvents,128,&cnt);
|
||||
Event_Cnt = cnt;
|
||||
if (Event_Cnt < 1) return 0;
|
||||
}
|
||||
|
||||
// Process events in buffer. Only care about key down events.
|
||||
while (Event_Cnt--) {
|
||||
if (EventsPtr->Event.KeyEvent.bKeyDown) {
|
||||
ascii = EventsPtr->Event.KeyEvent.uChar.AsciiChar;
|
||||
scode = EventsPtr->Event.KeyEvent.wVirtualScanCode;
|
||||
state = EventsPtr->Event.KeyEvent.dwControlKeyState;
|
||||
|
||||
// Standard Ascii character
|
||||
if (ascii) {
|
||||
chr = ascii;
|
||||
if (modalt(state)) { // alt trans to graph chars
|
||||
chr += 128;
|
||||
} else if (chr == 0x1B) { // Map escape to break (^E)
|
||||
chr = 0x05;
|
||||
} else if (chr == 0x1A) { // Map ^Z to EOF (escape)
|
||||
chr = 0x1B;
|
||||
}
|
||||
*buf++ = chr;
|
||||
keypress_cnt++;
|
||||
|
||||
// Function key. Process per scancode.
|
||||
} else {
|
||||
|
||||
// Set highbit of scan code if extended key
|
||||
if modextend(state) scode += 0x80;
|
||||
switch(scode) {
|
||||
case DIK_UP:
|
||||
case DIK_NUMPAD8:
|
||||
if (modshift(state))
|
||||
*buf++ = 0x1C; // shift up
|
||||
else
|
||||
*buf++ = 0x0C; // up
|
||||
keypress_cnt++;
|
||||
break;
|
||||
case DIK_DOWN:
|
||||
case DIK_NUMPAD2:
|
||||
if (modshift(state))
|
||||
*buf++ = 0x1A; // shift down
|
||||
else
|
||||
*buf++ = 0x0A; // down
|
||||
keypress_cnt++;
|
||||
break;
|
||||
case DIK_LEFT:
|
||||
case DIK_NUMPAD4:
|
||||
if (modshift(state))
|
||||
*buf++ = 0x18; // shift left
|
||||
else if (modctrl(state))
|
||||
*buf++ = 0x10; // control left
|
||||
else
|
||||
*buf++ = 0x08; // right
|
||||
keypress_cnt++;
|
||||
break;
|
||||
case DIK_RIGHT:
|
||||
case DIK_NUMPAD6:
|
||||
if (modshift(state))
|
||||
*buf++ = 0x19; // shift right
|
||||
else if (modctrl(state))
|
||||
*buf++ = 0x11; // control right
|
||||
else
|
||||
*buf++ = 0x09; // right
|
||||
keypress_cnt++;
|
||||
break;
|
||||
case DIK_F1:
|
||||
case DIK_F2:
|
||||
case DIK_F3:
|
||||
case DIK_F4:
|
||||
case DIK_F5:
|
||||
case DIK_F6:
|
||||
case DIK_F7:
|
||||
case DIK_F8:
|
||||
case DIK_F9:
|
||||
case DIK_F10:
|
||||
case DIK_F11:
|
||||
case DIK_F12:
|
||||
sprintf(txt,"F-%x",scode);
|
||||
SetConsoleTitle(txt);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Done with event
|
||||
EventsPtr++;
|
||||
// Return if input buffer full
|
||||
if (keypress_cnt == len) return keypress_cnt;
|
||||
}
|
||||
// Done processing events.
|
||||
// Return if at least one keystroke
|
||||
if (keypress_cnt > 0) return keypress_cnt;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
// Write to Console
|
||||
//----------------------------------------------------------------
|
||||
|
||||
// Terminal control sequence names
|
||||
enum {
|
||||
SEQ_NONE,
|
||||
SEQ_GOTOXY, // Position cursor to X,Y
|
||||
SEQ_COMMAND, // A command sequence
|
||||
SEQ_CONTROL, // A control sequence
|
||||
SEQ_BCOLOR, // Set background color
|
||||
SEQ_BOLDSW, // Set character attrib (TODO)
|
||||
SEQ_BORDER, // Set border color
|
||||
SEQ_FCOLOR, // Set forground color
|
||||
SEQ_CURSOR // Cursor on/off (TODO)
|
||||
};
|
||||
int SeqType = SEQ_NONE;
|
||||
int SeqArgsNeeded = 0;
|
||||
int SeqArgsCount = 0;
|
||||
char SeqArgs[8];
|
||||
|
||||
int console_write(const char *buf, int len) {
|
||||
|
||||
int cnt = 0;
|
||||
int chr;
|
||||
|
||||
DWORD tmp;
|
||||
char cc[80];
|
||||
|
||||
// Abort if console not open
|
||||
if ( hConOut == nullptr) return 0;
|
||||
|
||||
while (cnt < len) {
|
||||
chr = *buf++;
|
||||
cnt++;
|
||||
|
||||
// Do we need to finish a command sequence?
|
||||
if (SeqArgsNeeded) {
|
||||
// Save the the chr as command arg
|
||||
SeqArgs[SeqArgsCount++] = chr;
|
||||
|
||||
// If not done get more
|
||||
if (SeqArgsCount < SeqArgsNeeded) continue; // return cnt;
|
||||
|
||||
// Sequence complete
|
||||
SeqArgsNeeded = 0;
|
||||
SeqArgsCount = 0;
|
||||
|
||||
// Process the sequence
|
||||
switch (SeqType) {
|
||||
case SEQ_CONTROL:
|
||||
switch (SeqArgs[0]) {
|
||||
case 0x20: // Reverse video on
|
||||
case 0x21: // Reverse video off
|
||||
case 0x22: // Underline on
|
||||
case 0x23: // Underline off
|
||||
case 0x24: // Blinking on
|
||||
case 0x25: // Blinking off
|
||||
break;
|
||||
case 0x30: // Insert line
|
||||
console_insertline();
|
||||
break;
|
||||
case 0x31: // Delete line
|
||||
console_deleteline();
|
||||
break;
|
||||
case 0x40: // Line mode off
|
||||
SetConsoleTitle("VCC Console");
|
||||
AciaLineInput = 0;
|
||||
break;
|
||||
case 0x41: // Line mode on
|
||||
SetConsoleTitle("VCC Console Line Mode");
|
||||
AciaLineInput = 1;
|
||||
break;
|
||||
default:
|
||||
sprintf(cc,"~1F%02X~",SeqArgs[0]); // not handled
|
||||
WriteConsole(hConOut,cc,6,&tmp,nullptr);
|
||||
}
|
||||
break;
|
||||
case SEQ_GOTOXY:
|
||||
// row,col bias is 32
|
||||
console_move(SeqArgs[0]-32, SeqArgs[1]-32);
|
||||
break;
|
||||
case SEQ_COMMAND:
|
||||
// Arg is another sequence
|
||||
switch (SeqArgs[0]) {
|
||||
case 0x32:
|
||||
SeqType = SEQ_FCOLOR;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
case 0x33:
|
||||
SeqType = SEQ_BCOLOR;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
case 0x34:
|
||||
SeqType = SEQ_BORDER;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
case 0x3d:
|
||||
SeqType = SEQ_BOLDSW;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
default:
|
||||
sprintf(cc,"~1B%02X~",SeqArgs[0]); // not handled
|
||||
WriteConsole(hConOut,cc,strlen(cc),&tmp,nullptr);
|
||||
}
|
||||
break;
|
||||
case SEQ_FCOLOR:
|
||||
console_forground(chr);
|
||||
break;
|
||||
case SEQ_BCOLOR:
|
||||
console_background(chr);
|
||||
break;
|
||||
case SEQ_BORDER:
|
||||
case SEQ_BOLDSW:
|
||||
break;
|
||||
}
|
||||
//return cnt;
|
||||
continue;
|
||||
}
|
||||
|
||||
// write printable chr to console
|
||||
if (isprint(chr)) {
|
||||
WriteConsole(hConOut,&chr,1,&tmp,nullptr);
|
||||
//return cnt;
|
||||
continue;
|
||||
}
|
||||
|
||||
// write chars with high bit set to console (utf8)
|
||||
if (chr > 128) {
|
||||
WriteConsole(hConOut,&chr,1,&tmp,nullptr);
|
||||
continue;
|
||||
//return cnt;
|
||||
}
|
||||
|
||||
// process non printable
|
||||
switch (chr) {
|
||||
case 0x0:
|
||||
break;
|
||||
case 0x1: // cursor home
|
||||
console_move(0,0);
|
||||
break;
|
||||
case 0x2:
|
||||
SeqType = SEQ_GOTOXY;
|
||||
SeqArgsNeeded = 2;
|
||||
break;
|
||||
case 0x3: // clear line
|
||||
console_eraseline();
|
||||
break;
|
||||
case 0x4: // clear to end of line
|
||||
console_cleol();
|
||||
break;
|
||||
case 0x5:
|
||||
SeqType = SEQ_CURSOR;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
case 0x6: // vt
|
||||
console_right();
|
||||
break;
|
||||
case 0x7: // bell
|
||||
WriteConsole(hConOut,&chr,1,&tmp,nullptr);
|
||||
break;
|
||||
case 0x8: // backspace
|
||||
console_left();
|
||||
break;
|
||||
case 0x9: // up arrow
|
||||
console_up();
|
||||
break;
|
||||
case 0xA: // line feed
|
||||
console_down();
|
||||
break;
|
||||
case 0xB: // clear to end of screen
|
||||
console_cleob();
|
||||
break;
|
||||
case 0xC: // clear screen
|
||||
console_cls();
|
||||
break;
|
||||
case 0xD: // carriage return
|
||||
console_cr();
|
||||
break;
|
||||
case 0xE: // Unknown code
|
||||
case 0x15: // Unknown code
|
||||
break;
|
||||
case 0x1B: // Screen command
|
||||
SeqType = SEQ_COMMAND;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
case 0x1F: // Text control
|
||||
SeqType = SEQ_CONTROL;
|
||||
SeqArgsNeeded = 1;
|
||||
break;
|
||||
default: // unhandled
|
||||
sprintf(cc,"~%02X~",chr);
|
||||
WriteConsole(hConOut,cc,4,&tmp,nullptr);
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Console control functions
|
||||
//------------------------------------------------------------------
|
||||
|
||||
// Scroll the screen buffer. Delete lines from top or bottom
|
||||
// of the buffer depending on the sign of the lines parameter.
|
||||
// Negative number deletes lines from the top.
|
||||
void console_scroll(int lines) {
|
||||
SMALL_RECT rect;
|
||||
SMALL_RECT clip;
|
||||
COORD loc;
|
||||
CHAR_INFO fill;
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
rect.Left = 0;
|
||||
rect.Top = 0;
|
||||
rect.Right = Csbi.dwSize.X;
|
||||
rect.Bottom = Csbi.dwSize.Y;
|
||||
clip = rect;
|
||||
fill.Char.UnicodeChar = TEXT(' ');
|
||||
fill.Attributes = Csbi.wAttributes;
|
||||
loc.X = 0;
|
||||
loc.Y = (SHORT) lines;
|
||||
ScrollConsoleScreenBuffer(hConOut,&rect,&clip,loc,&fill);
|
||||
}
|
||||
|
||||
// Insert line at cursor
|
||||
void console_insertline() {
|
||||
SMALL_RECT rect;
|
||||
COORD dest;
|
||||
CHAR_INFO fill;
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
|
||||
fill.Char.UnicodeChar = TEXT(' ');
|
||||
fill.Attributes = Csbi.wAttributes;
|
||||
rect.Left = 0;
|
||||
dest.X = 0;
|
||||
rect.Right = Csbi.dwSize.X;
|
||||
rect.Top = Csbi.dwCursorPosition.Y;
|
||||
rect.Bottom = Csbi.dwSize.Y-1;
|
||||
dest.Y = Csbi.dwCursorPosition.Y+1;
|
||||
ScrollConsoleScreenBuffer(hConOut,&rect,nullptr,dest,&fill);
|
||||
}
|
||||
|
||||
// Delete line at cursor
|
||||
void console_deleteline() {
|
||||
SMALL_RECT rect;
|
||||
COORD dest;
|
||||
CHAR_INFO fill;
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
|
||||
fill.Char.UnicodeChar = TEXT(' ');
|
||||
fill.Attributes = Csbi.wAttributes;
|
||||
rect.Left = 0;
|
||||
dest.X = 0;
|
||||
rect.Right = Csbi.dwSize.X;
|
||||
|
||||
rect.Top = Csbi.dwCursorPosition.Y+1;
|
||||
rect.Bottom = Csbi.dwSize.Y;
|
||||
dest.Y = Csbi.dwCursorPosition.Y;
|
||||
ScrollConsoleScreenBuffer(hConOut,&rect,nullptr,dest,&fill);
|
||||
}
|
||||
|
||||
// Move cursor to x, y location
|
||||
void console_move(int x, int y) {
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
if ((x >= 0) && (x <= Csbi.dwSize.X)) Csbi.dwCursorPosition.X = x;
|
||||
if ((y >= 0) && (y <= Csbi.dwSize.Y)) Csbi.dwCursorPosition.Y = y;
|
||||
SetConsoleCursorPosition(hConOut, Csbi.dwCursorPosition);
|
||||
}
|
||||
|
||||
// Move cursor right
|
||||
void console_right() {
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
Csbi.dwCursorPosition.X += 1;
|
||||
SetConsoleCursorPosition(hConOut, Csbi.dwCursorPosition);
|
||||
}
|
||||
|
||||
// Move cursor left
|
||||
void console_left() {
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
Csbi.dwCursorPosition.X -= 1;
|
||||
SetConsoleCursorPosition(hConOut, Csbi.dwCursorPosition);
|
||||
}
|
||||
|
||||
// Move cursor down
|
||||
void console_down() {
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
if ((Csbi.dwCursorPosition.Y+1) >= Csbi.dwSize.Y) {
|
||||
console_scroll(-1);
|
||||
} else {
|
||||
Csbi.dwCursorPosition.Y += 1;
|
||||
SetConsoleCursorPosition(hConOut, Csbi.dwCursorPosition);
|
||||
}
|
||||
}
|
||||
|
||||
// Move cursor up
|
||||
void console_up() {
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
if ( Csbi.dwCursorPosition.Y == 0 ) return;
|
||||
Csbi.dwCursorPosition.Y -= 1;
|
||||
SetConsoleCursorPosition(hConOut, Csbi.dwCursorPosition);
|
||||
}
|
||||
|
||||
// Clear console buffer and home cursor
|
||||
void console_cls()
|
||||
{
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
console_scroll(-Csbi.dwSize.Y);
|
||||
console_move(0,0);
|
||||
}
|
||||
|
||||
// Clear to end of line
|
||||
void console_cleol() {
|
||||
DWORD cnt, tmp;
|
||||
COORD loc;
|
||||
TCHAR fill = TEXT(' ');
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
loc.X = Csbi.dwCursorPosition.X;
|
||||
loc.Y = Csbi.dwCursorPosition.Y;
|
||||
cnt = Csbi.dwSize.X - loc.X;
|
||||
if (cnt > 0) {
|
||||
FillConsoleOutputCharacter(hConOut,fill,cnt,loc,&tmp);
|
||||
}
|
||||
}
|
||||
|
||||
// Clear to end of buffer
|
||||
void console_cleob() {
|
||||
DWORD val;
|
||||
COORD loc;
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
loc.X = Csbi.dwCursorPosition.X;
|
||||
loc.Y = Csbi.dwCursorPosition.Y;
|
||||
DWORD cnt = (Csbi.dwSize.X - loc.X) +
|
||||
(Csbi.dwSize.Y - loc.Y) * Csbi.dwSize.X;
|
||||
TCHAR fill = TEXT(' ');
|
||||
if (cnt > 0) {
|
||||
FillConsoleOutputCharacter(hConOut,fill,cnt,loc,&val);
|
||||
}
|
||||
}
|
||||
|
||||
// Carriage return (move cursor to first column)
|
||||
void console_cr() {
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
Csbi.dwCursorPosition.X = 0;
|
||||
SetConsoleCursorPosition(hConOut, Csbi.dwCursorPosition);
|
||||
}
|
||||
|
||||
// Erase line
|
||||
void console_eraseline() {
|
||||
console_cr();
|
||||
console_cleol();
|
||||
}
|
||||
|
||||
// Set background color
|
||||
void console_background(int coco_color) {
|
||||
WORD color;
|
||||
WORD atrib;
|
||||
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
atrib = Csbi.wAttributes & 0xFF0F; //mask out background
|
||||
|
||||
if (coco_color > 7) // Background defaults to black
|
||||
color = 0;
|
||||
else
|
||||
color = color_tbl[coco_color];
|
||||
|
||||
atrib |= ( color << 4 );
|
||||
SetConsoleTextAttribute ( hConOut, atrib );
|
||||
}
|
||||
|
||||
// Set forground color
|
||||
void console_forground(int coco_color) {
|
||||
WORD color;
|
||||
WORD atrib;
|
||||
|
||||
GetConsoleScreenBufferInfo(hConOut, &Csbi);
|
||||
atrib = Csbi.wAttributes & 0xFFF0; //mask out foreground
|
||||
|
||||
if (coco_color > 7) // Background defaults to white
|
||||
color = 15;
|
||||
else
|
||||
color = color_tbl[coco_color];
|
||||
|
||||
atrib |= color;
|
||||
SetConsoleTextAttribute ( hConOut, atrib );
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Input from or Output to windows file
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "acia.h"
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
FILE * FileStream = nullptr;
|
||||
|
||||
// Open file. Binary mode so windows does not try to do line end LF
|
||||
// translations. (OS9 uses CR for line endings) File path is
|
||||
// relative to %USERPROFILE%
|
||||
|
||||
int file_open()
|
||||
{
|
||||
char filepath[MAX_PATH];
|
||||
strncpy(filepath,getenv("USERPROFILE"),MAX_PATH);
|
||||
strncat(filepath,"\\",MAX_PATH);
|
||||
switch (AciaComMode) {
|
||||
case COM_MODE_READ:
|
||||
strncat(filepath,AciaFileRdPath,MAX_PATH);
|
||||
FileStream = fopen(filepath,"rb");
|
||||
// FIXME: This is needed and should not be commented out. Wrap it conditional
|
||||
// either here or in the debug log functions.
|
||||
//PrintLogF("Opened %s %d\n",filepath,FileStream);
|
||||
break;
|
||||
case COM_MODE_WRITE:
|
||||
strcat(filepath,AciaFileWrPath);
|
||||
FileStream = fopen(filepath,"wb");
|
||||
// FIXME: This is needed and should not be commented out. Wrap it conditional
|
||||
// either here or in the debug log functions.
|
||||
//PrintLogF("Opened %s %d\n",filepath,FileStream);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void file_close()
|
||||
{
|
||||
// FIXME: This is needed and should not be commented out. Wrap it conditional
|
||||
// either here or in the debug log functions.
|
||||
//PrintLogF("Close %d\n",FileStream);
|
||||
if(FileStream) fclose(FileStream);
|
||||
FileStream = nullptr;
|
||||
}
|
||||
|
||||
// Read file. If text remove LF characters
|
||||
int file_read(char* buf,int siz)
|
||||
{
|
||||
// FIXME: This is needed and should not be commented out. Wrap it conditional
|
||||
// either here or in the debug log functions.
|
||||
//PrintLogF("Read %d %d\n",FileStream, siz);
|
||||
int PrevChrCR=0; // True if last char read was a carriage return
|
||||
|
||||
if (FileStream == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int count;
|
||||
|
||||
if (AciaTextMode) {
|
||||
count = 0;
|
||||
int chr = 0;
|
||||
|
||||
while ((count < siz) && (chr != EOF)) {
|
||||
chr = fgetc(FileStream);
|
||||
if (chr == EOF) {
|
||||
if (!PrevChrCR) buf[count++] = '\r';
|
||||
buf[count++] = EOFCHR;
|
||||
} else {
|
||||
if ( (chr != '\n') || !PrevChrCR ) buf[count++] = chr;
|
||||
PrevChrCR = (chr == '\r') ? 1 : 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
count = fread(buf,1,siz,FileStream);
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
// Write file. If text skip LF chars and convert CR to CRLF
|
||||
int file_write(const char* buf,int siz)
|
||||
{
|
||||
// FIXME: This is needed and should not be commented out. Wrap it conditional
|
||||
// either here or in the debug log functions.
|
||||
//PrintLogF("Write %d %d\n",FileStream, siz);
|
||||
int count = 0;
|
||||
if (FileStream && (siz > 0)) {
|
||||
if (AciaTextMode) {
|
||||
for (int n=0; n<siz; n++) {
|
||||
count++;
|
||||
char chr = buf[n];
|
||||
if (chr != '\n') fputc(chr,FileStream);
|
||||
if (chr == '\r') fputc('\n',FileStream);
|
||||
}
|
||||
} else {
|
||||
count = fwrite(buf,1,siz,FileStream);
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by acia.rc
|
||||
//
|
||||
#define IDS_MODULE_NAME 1
|
||||
#define IDS_VERSION 2
|
||||
#define IDS_CATNUMBER 3
|
||||
#define IDS_DESCRIPTION 4
|
||||
#define IDD_PROPPAGE 102
|
||||
|
||||
#define IDC_PORT 1010
|
||||
#define IDC_NAME 1011
|
||||
#define IDC_TXTMODE 1012
|
||||
#define IDAPPLY 1013
|
||||
|
||||
#define IDC_T_CONS 1020
|
||||
#define IDC_T_FILE_R 1021
|
||||
#define IDC_T_FILE_W 1022
|
||||
#define IDC_T_TCP 1023
|
||||
#define IDC_T_COM 1024
|
||||
|
||||
#define IDC_T_RS232 1030
|
||||
#define IDC_T_MODEM 1031
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1050
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,342 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#include "acia.h"
|
||||
#include "sc6551.h"
|
||||
#include "../../../src/core/Interrupts.h"
|
||||
#include <vcc/util/logger.h>
|
||||
#include <atomic>
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Handles and buffers for I/O threads
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
HANDLE hInputThread;
|
||||
HANDLE hOutputThread;
|
||||
HANDLE hStopInput;
|
||||
HANDLE hStopOutput;
|
||||
|
||||
// sc6551 registers
|
||||
unsigned char StatReg;
|
||||
unsigned char CmdReg;
|
||||
unsigned char CtlReg;
|
||||
|
||||
// Input
|
||||
constexpr auto IBUFSIZ = 1024u;
|
||||
DWORD WINAPI sc6551_input_thread(LPVOID);
|
||||
char InBuf[IBUFSIZ];
|
||||
char *InRptr = InBuf;
|
||||
int Icnt = 0;
|
||||
|
||||
// Output
|
||||
constexpr auto OBUFSIZ = 1024u;
|
||||
DWORD WINAPI sc6551_output_thread(LPVOID);
|
||||
char OutBuf[OBUFSIZ];
|
||||
char *OutWptr = OutBuf;
|
||||
int Wcnt = 0;
|
||||
|
||||
// Atomic flag for interlock
|
||||
std::atomic_flag Ilock{};
|
||||
|
||||
int sc6551_opened = 0;
|
||||
|
||||
unsigned int HBcounter = 0; // used to pace I/O
|
||||
|
||||
unsigned int IntClock;
|
||||
static unsigned int DataLen;
|
||||
static unsigned int StopBits;
|
||||
static unsigned int EchoOn;
|
||||
static unsigned int EnParity;
|
||||
static unsigned int Parity;
|
||||
static unsigned int BaudRate;
|
||||
|
||||
// BaudDelay table for supported rates. These are approximate.
|
||||
// If accuracy becomes an issue could use audio sample timer.
|
||||
// Corresponds with { X, 75, 75, 110, 300, 300, 300, 600,
|
||||
// 1200,2400,2400,4800,4800,9600,9600,19200 };
|
||||
|
||||
int BaudDelay[16] = { 0, 620, 620, 500, 250, 250, 250, 125,
|
||||
60, 30, 30, 15, 15, 7, 7, 3 };
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Nicely terminate an I/O thread
|
||||
//------------------------------------------------------------------------
|
||||
void sc6551_terminate_thread(HANDLE hthread, HANDLE hstop)
|
||||
{
|
||||
if (hthread) {
|
||||
// Tell thread to exit
|
||||
SetEvent(hstop);
|
||||
// If that fails force it
|
||||
if (WaitForSingleObject(hthread,500) == WAIT_TIMEOUT) {
|
||||
DLOG_F("FORCE TERMINATE %d\n",hthread);
|
||||
TerminateThread(hthread,1);
|
||||
WaitForSingleObject(hthread,500);
|
||||
}
|
||||
CloseHandle(hthread);
|
||||
hthread = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Init sc6551. This gets called when the DLL is loaded
|
||||
//------------------------------------------------------------------------
|
||||
void sc6551_init()
|
||||
{
|
||||
IntClock = 0;
|
||||
DataLen = 0;
|
||||
StopBits = 0;
|
||||
EchoOn = 0;
|
||||
EnParity = 0;
|
||||
Parity = 0;
|
||||
BaudRate = 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Open sc6551. This gets called when DTR is raised.
|
||||
//------------------------------------------------------------------------
|
||||
void sc6551_open()
|
||||
{
|
||||
DWORD id;
|
||||
|
||||
if (sc6551_opened == 1) return;
|
||||
|
||||
// Open comunication
|
||||
com_open();
|
||||
|
||||
// Create I/O threads
|
||||
hInputThread = CreateThread(nullptr,0,sc6551_input_thread, nullptr,0,&id);
|
||||
hOutputThread = CreateThread(nullptr,0,sc6551_output_thread,nullptr,0,&id);
|
||||
|
||||
// Create events to control them
|
||||
hStopInput = CreateEvent(nullptr,TRUE,FALSE,nullptr);
|
||||
hStopOutput = CreateEvent(nullptr,TRUE,FALSE,nullptr);
|
||||
|
||||
// Clear status register and mark buffers empty
|
||||
InRptr = InBuf;
|
||||
OutWptr = OutBuf;
|
||||
Icnt = 0;
|
||||
Wcnt = 0;
|
||||
|
||||
sc6551_opened = 1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Close sc6551. This gets called when DTR is cleared
|
||||
//------------------------------------------------------------------------
|
||||
void sc6551_close()
|
||||
{
|
||||
if (sc6551_opened) {
|
||||
sc6551_terminate_thread(hInputThread, hStopInput);
|
||||
sc6551_terminate_thread(hOutputThread, hStopOutput);
|
||||
CloseHandle(hStopInput);
|
||||
CloseHandle(hStopOutput);
|
||||
com_close();
|
||||
Icnt = 0;
|
||||
Wcnt = 0;
|
||||
sc6551_opened = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Input thread
|
||||
//------------------------------------------------------------------------
|
||||
DWORD WINAPI sc6551_input_thread(LPVOID /*param*/)
|
||||
{
|
||||
DLOG_F("START-IN %d\n",hInputThread);
|
||||
Icnt = 0;
|
||||
while(TRUE) {
|
||||
if (Icnt == 0) {
|
||||
InRptr = InBuf;
|
||||
if (AciaComMode == COM_MODE_WRITE) {
|
||||
*InBuf = '\0';
|
||||
Icnt = 1;
|
||||
} else {
|
||||
int cnt = com_read(InBuf,IBUFSIZ);
|
||||
if (cnt < 1) {
|
||||
// EOF regardless TODO User config
|
||||
cnt = 2;
|
||||
InBuf[0] = '\r';
|
||||
InBuf[1] = EOFCHR;
|
||||
}
|
||||
DLOG_F("R %d\n",cnt);
|
||||
Icnt = cnt;
|
||||
}
|
||||
} else {
|
||||
if (WaitForSingleObject(hStopInput,100) != WAIT_TIMEOUT) {
|
||||
if (Icnt > 0) Sleep(1000);
|
||||
DLOG_F("TERMINATE-IN\n");
|
||||
ExitThread(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Output thread.
|
||||
//------------------------------------------------------------------------
|
||||
DWORD WINAPI sc6551_output_thread(LPVOID /*param*/)
|
||||
{
|
||||
Wcnt = 0;
|
||||
OutWptr = OutBuf;
|
||||
|
||||
DLOG_F("START-OUT %d\n",hOutputThread);
|
||||
|
||||
while(TRUE) {
|
||||
if (Wcnt > 0) {
|
||||
// Need interlock for TxE, OutWptr, and Wcnt
|
||||
if (!Ilock.test_and_set()) {
|
||||
StatReg &= ~StatTxE;
|
||||
if (AciaComMode != COM_MODE_READ) {
|
||||
const char * ptr = OutBuf;
|
||||
while (Wcnt > 0) {
|
||||
int cnt = com_write(ptr,Wcnt);
|
||||
DLOG_F("W %d\n",cnt);
|
||||
if (cnt < 1) break; //TODO Deal with write error
|
||||
Wcnt -= cnt;
|
||||
ptr += cnt;
|
||||
}
|
||||
}
|
||||
Wcnt = 0;
|
||||
OutWptr = OutBuf;
|
||||
Ilock.clear();
|
||||
}
|
||||
}
|
||||
|
||||
int rc = WaitForSingleObject(hStopOutput,100);
|
||||
if (rc != WAIT_TIMEOUT) {
|
||||
DLOG_F("TERMINATE-OUT\n");
|
||||
ExitThread(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Use Heartbeat (HSYNC) to time receives and interrupts
|
||||
// If accuracy becomes an issue could use audio sample timer instead.
|
||||
//
|
||||
// StatRxF 0x08 Data ready to read;
|
||||
// StatTxE 0x10 Buffer ready to write;
|
||||
// StatDCD 0x20 Data Carier detected if clr
|
||||
// StatDSR 0x40 Data set Ready if clr
|
||||
// StatIRQ 0x80 IRQ set
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
void sc6551_heartbeat()
|
||||
{
|
||||
// Countdown to receive next byte
|
||||
if (HBcounter-- < 1) {
|
||||
HBcounter = BaudDelay[BaudRate];
|
||||
// Set RxF if there is data buffered
|
||||
if (Icnt) {
|
||||
StatReg |= StatRxF;
|
||||
// Assert CART if interrupts not disabled or already asserted.
|
||||
if (!((CmdReg & CmdRxI) || (StatReg & StatIRQ))) {
|
||||
AssertInt(gSlotId, INT_CART, IS_NMI);
|
||||
StatReg |= StatIRQ;
|
||||
}
|
||||
}
|
||||
// Set TxE if write buffer not full (interlocked)
|
||||
if (!Ilock.test_and_set()) {
|
||||
if (Wcnt < OBUFSIZ) StatReg |= StatTxE; //0x10
|
||||
Ilock.clear();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Port Read
|
||||
// MPI calls port reads for each slot in sequence. The CPU gets the
|
||||
// first non zero reply if any.
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
unsigned char sc6551_read(unsigned char port)
|
||||
{
|
||||
unsigned char data = 0; // Default zero
|
||||
switch (port-AciaBasePort) {
|
||||
// Read data
|
||||
case 0:
|
||||
// If data avail and RxF is set return the data
|
||||
if ((Icnt > 0) && (StatReg & StatRxF)) {
|
||||
data = *InRptr++;
|
||||
Icnt--;
|
||||
}
|
||||
// Clear RxF until timer resets it
|
||||
StatReg &= ~StatRxF; //0x08
|
||||
break;
|
||||
// Read status register
|
||||
case 1:
|
||||
data = StatReg;
|
||||
StatReg &= ~StatIRQ;
|
||||
break;
|
||||
// Read command register
|
||||
case 2:
|
||||
data = CmdReg;
|
||||
break;
|
||||
// Read control register
|
||||
case 3:
|
||||
data = CtlReg;
|
||||
break;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Port Write
|
||||
//------------------------------------------------------------------------
|
||||
void sc6551_write(unsigned char data,unsigned short port)
|
||||
{
|
||||
switch (port-AciaBasePort) {
|
||||
// Data
|
||||
case 0:
|
||||
StatReg &= ~StatTxE; //0x10
|
||||
*OutWptr++ = data;
|
||||
Wcnt++;
|
||||
break;
|
||||
// Write status does a reset
|
||||
case 1:
|
||||
DLOG_F("Reset\n");
|
||||
StatReg = 0;
|
||||
break;
|
||||
// Write Command register
|
||||
case 2:
|
||||
CmdReg = data;
|
||||
EchoOn = (CmdReg & 0x10) >> 4;
|
||||
Parity = (CmdReg & 0xE0) >> 5;
|
||||
EnParity = Parity & 1;
|
||||
Parity = Parity >> 1;
|
||||
if (CmdReg & CmdDTR) {
|
||||
sc6551_open();
|
||||
} else {
|
||||
sc6551_close();
|
||||
}
|
||||
break;
|
||||
// Write Control register
|
||||
case 3:
|
||||
CtlReg = data;
|
||||
BaudRate = CtlReg & 0x0F;
|
||||
IntClock = (CtlReg & 0x10) >> 4;
|
||||
DataLen = 8 - ((CtlReg & 0x60) >> 5);
|
||||
StopBits = (((CtlReg & 0x80) >> 7) == 0) ? 0 : 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
// Defines
|
||||
//------------------------------------------------------------------
|
||||
// Status Register
|
||||
// b0 Par Rx parity error
|
||||
// b1 Frm Rx framing error
|
||||
// B2 Ovr Rx data over run
|
||||
// b3 RxF Rx Data register full
|
||||
// b4 TxE Tx Data register empty
|
||||
// b5 DCD Data carrier (clear=active)
|
||||
// b6 DSR Data set ready (clear=active)
|
||||
// b7 IRQ Interrupt read status
|
||||
constexpr auto StatPar = 0x01u;
|
||||
constexpr auto StatFrm = 0x02u;
|
||||
constexpr auto StatOvr = 0x04u;
|
||||
constexpr auto StatRxF = 0x08u;
|
||||
constexpr auto StatTxE = 0x10u;
|
||||
constexpr auto StatDCD = 0x20u;
|
||||
constexpr auto StatDSR = 0x40u;
|
||||
constexpr auto StatIRQ = 0x80u;
|
||||
|
||||
// Command register
|
||||
// b0 DTR Enable receive and interupts (set=enabled)
|
||||
// b1 RxI Receiver IRQ control by StatRxF (set=disabled)
|
||||
// b2-3 TIRB Transmit IRQ control
|
||||
// 00 trans disabled,01 enabled,10 disabled,11 break
|
||||
// b4 Echo Set=Activated
|
||||
// b5-7 Par Parity control
|
||||
// xx0 none, 001 Odd, 011 Even, 101 mark, 111 space
|
||||
constexpr auto CmdDTR = 0x01u;
|
||||
constexpr auto CmdRxI = 0x02u;
|
||||
constexpr auto CmdTIRB = 0x0Cu;
|
||||
constexpr auto TIRB_Off = 0x00u;
|
||||
constexpr auto TIRB_On = 0x04u;
|
||||
constexpr auto TIRB_RTS = 0x08u;
|
||||
constexpr auto TIRB_Brk = 0x0Cu;
|
||||
|
||||
// Control Register
|
||||
// b0-3 Baud rate
|
||||
// { X,60,75,110,
|
||||
// 135,150,300,600,
|
||||
// 1200,1800,2400,3600,
|
||||
// 4800,7200,9600,19200 }
|
||||
// b4 Rcv Clock source 0=X 1=intenal
|
||||
// b5-6 Data len 00=8 01=7 10=6 11=5
|
||||
// b7 Stop bits 0=1, 1-2
|
||||
// Parity is index to [odd,even,mark,space]
|
||||
// BaudRate is index to [19200,50,75,110,135,150,300,600,1200,
|
||||
// 1800,2400,3600,4800 7200,9600,19200]
|
||||
@@ -0,0 +1,140 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Input from or Output to tcpip server
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#include <WinSock2.h>
|
||||
#include <Ws2tcpip.h>
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include "acia.h"
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
// socket
|
||||
static SOCKET Socket = INVALID_SOCKET;
|
||||
|
||||
//Close
|
||||
void tcpip_close()
|
||||
{
|
||||
DLOG_C("tcpip_close Socket %d\n",Socket);
|
||||
if (Socket != INVALID_SOCKET) closesocket(Socket);
|
||||
Socket = INVALID_SOCKET;
|
||||
WSACleanup();
|
||||
}
|
||||
|
||||
// Open
|
||||
int tcpip_open()
|
||||
{
|
||||
WSADATA wsaData;
|
||||
if (Socket != INVALID_SOCKET) tcpip_close();
|
||||
|
||||
if ((WSAStartup(0x202, &wsaData)) != 0) {
|
||||
WSACleanup();
|
||||
return -1;
|
||||
}
|
||||
struct addrinfo hints;
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
|
||||
struct addrinfo *result = nullptr;
|
||||
if (getaddrinfo(AciaTcpHost, AciaTcpPort, &hints, &result) != 0) {
|
||||
DLOG_C("tcpip_open getaddrinfo fail %s %s\n",AciaTcpHost,AciaTcpPort);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (auto p = result; p != nullptr; p = p->ai_next) {
|
||||
Socket = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
|
||||
if (Socket == INVALID_SOCKET) {
|
||||
freeaddrinfo(result);
|
||||
DLOG_C("tcpip_open Fail\n");
|
||||
return -1;
|
||||
}
|
||||
if (connect(Socket, p->ai_addr, p->ai_addrlen) != 0) {
|
||||
closesocket(Socket);
|
||||
Socket = INVALID_SOCKET;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
freeaddrinfo(result);
|
||||
|
||||
DLOG_C("tcpip_open Socket %d\n",Socket);
|
||||
|
||||
if (Socket == INVALID_SOCKET)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Read
|
||||
int tcpip_read(char* buf, int siz)
|
||||
{
|
||||
int cnt = 0;
|
||||
if (Socket == INVALID_SOCKET) tcpip_open();
|
||||
|
||||
while (cnt < 1) {
|
||||
cnt = recv(Socket,buf,siz,0);
|
||||
if (AciaTextMode && (cnt == 0)) {
|
||||
buf[cnt++] = EOFCHR;
|
||||
break;
|
||||
}
|
||||
if (cnt < 1) Sleep(100);
|
||||
}
|
||||
|
||||
// Fix line endings
|
||||
if (AciaTextMode) {
|
||||
for (int i=0;i<cnt;i++) if (buf[i]==10) buf[i]=13;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
//Write
|
||||
int tcpip_write(const char* buf, int siz)
|
||||
{
|
||||
char CRLF[3]="\r\n";
|
||||
|
||||
int cnt = 0;
|
||||
int rc;
|
||||
|
||||
if (Socket == INVALID_SOCKET) tcpip_open();
|
||||
while (siz-- > 0) {
|
||||
if (AciaTextMode) {
|
||||
if (*buf != '\n') {
|
||||
rc = send(Socket,buf,1,0);
|
||||
if (rc != 1) break;
|
||||
}
|
||||
if (*buf == '\r') {
|
||||
rc = send(Socket,CRLF,2,0);
|
||||
if (rc != 2) break;
|
||||
}
|
||||
} else {
|
||||
rc = send(Socket,buf,1,0);
|
||||
if (rc != 1) break;
|
||||
}
|
||||
buf++;
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
//------------------------------------------------------------------
|
||||
// Copyright E J Jaquay 2022
|
||||
//
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute it
|
||||
// and/or modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) is distributed in the hope that it will be
|
||||
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License for more details. You should have
|
||||
// received a copy of the GNU General Public License along with VCC
|
||||
// (Virtual Color Computer). If not see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
//------------------------------------------------------------------
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Input from or Output to windows com port
|
||||
//------------------------------------------------------------------
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include "acia.h"
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
HANDLE hReadEvent;
|
||||
HANDLE hWriteEvent;
|
||||
HANDLE hComPort=INVALID_HANDLE_VALUE;
|
||||
|
||||
int writeport(const char *buf,int siz);
|
||||
|
||||
static unsigned int BaudRate;
|
||||
static unsigned int EnParity;
|
||||
static unsigned int Parity;
|
||||
static unsigned int DataLen;
|
||||
static unsigned int StopBits;
|
||||
|
||||
//=====================================================
|
||||
// Open COM port. Port I/O must be asyncronous (overlapped)
|
||||
// otherwise pending reads will block pending writes
|
||||
//=====================================================
|
||||
int wincom_open()
|
||||
{
|
||||
DCB PortDCB;
|
||||
static int bt[16]={38400, 110, 110, 110, 300, 300, 300, 600,
|
||||
1200,2400,2400,4800,4800,9600,9600,19200};
|
||||
|
||||
hReadEvent = CreateEvent(nullptr,TRUE,FALSE,nullptr);
|
||||
hWriteEvent = CreateEvent(nullptr,TRUE,FALSE,nullptr);
|
||||
|
||||
char portname[64];
|
||||
sprintf(portname,"\\\\.\\%s",AciaComPort);
|
||||
hComPort = CreateFileA(portname,
|
||||
GENERIC_READ | GENERIC_WRITE, 0, nullptr,
|
||||
OPEN_EXISTING, FILE_FLAG_OVERLAPPED,nullptr);
|
||||
if (hComPort==INVALID_HANDLE_VALUE) return -1; // msgbox?
|
||||
|
||||
// Port settings
|
||||
SecureZeroMemory(&PortDCB,sizeof(PortDCB));
|
||||
PortDCB.DCBlength = sizeof(PortDCB);
|
||||
GetCommState(hComPort,&PortDCB);
|
||||
PortDCB.BaudRate = (BaudRate > 16) ? 9600 : bt[BaudRate];
|
||||
PortDCB.fParity = EnParity;
|
||||
PortDCB.Parity = EnParity ? 0 : Parity;
|
||||
PortDCB.ByteSize = DataLen;
|
||||
PortDCB.StopBits = (StopBits == 0) ? 0 : 2;
|
||||
SetCommState(hComPort,&PortDCB);
|
||||
// FIXME: This is needed and should not be commented out. Wrap it conditional
|
||||
// either here or in the debug log functions.
|
||||
// PrintLogF("Baud:%d,Parity:%d,Data:%d,Stop:%d\n",
|
||||
// BaudRate,Parity,DataLen,StopBits);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//=====================================================
|
||||
// Close COM port
|
||||
//=====================================================
|
||||
void wincom_close()
|
||||
{
|
||||
if (hComPort) CloseHandle(hComPort);
|
||||
hComPort = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
//=====================================================
|
||||
// Read from com port. If text remove LF characters
|
||||
//=====================================================
|
||||
|
||||
int wincom_read(char* buf,int siz)
|
||||
{
|
||||
int rc;
|
||||
DWORD cnt = 0;
|
||||
if (hComPort == INVALID_HANDLE_VALUE) return -1;
|
||||
|
||||
OVERLAPPED read_ovl = {0};
|
||||
read_ovl.hEvent = hReadEvent;
|
||||
|
||||
// Read at least one char
|
||||
while (cnt < 1) {
|
||||
rc = ReadFile(hComPort,buf,siz,&cnt,&read_ovl);
|
||||
if (rc == 0) {
|
||||
if (GetLastError() != ERROR_IO_PENDING) return -1;
|
||||
WaitForSingleObject(hReadEvent,INFINITE);
|
||||
rc = GetOverlappedResult(hComPort, &read_ovl, &cnt, TRUE);
|
||||
if (cnt < 0) return -1;
|
||||
}
|
||||
}
|
||||
// If text mode convert every LF to CR
|
||||
if (AciaTextMode) {
|
||||
for (unsigned int i=0;i<cnt;i++) if (buf[i]==10) buf[i]=13;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
//=====================================================
|
||||
// Write to com port. If text mode convert line endings
|
||||
//=====================================================
|
||||
int wincom_write(const char* buf,int siz)
|
||||
{
|
||||
int cnt = 0;
|
||||
if (hComPort == INVALID_HANDLE_VALUE) return -1;
|
||||
|
||||
if (AciaTextMode) {
|
||||
// Convert endings. Skip LF and convert CR to CRLF.
|
||||
// writeport is much faster with large writes. Code
|
||||
// here maximizes write sizes without re-buffering.
|
||||
while(cnt < siz) {
|
||||
// search for a CR or LF
|
||||
const char* ptr, * tbuf;
|
||||
char chr;
|
||||
int tsiz;
|
||||
ptr = tbuf = buf + cnt;
|
||||
for (tsiz = 0; tsiz < siz-cnt; tsiz++) {
|
||||
chr = *ptr++;
|
||||
if (chr == '\r' || chr == '\n') break;
|
||||
}
|
||||
// write buffer up to but excluding the chr found
|
||||
if (tsiz) {
|
||||
int len = writeport(tbuf,tsiz);
|
||||
if (len < 1) return -1;
|
||||
cnt += len;
|
||||
// loop if write was short
|
||||
if (len != tsiz) continue;
|
||||
}
|
||||
// Skip LF or convert CR to CRLF
|
||||
switch (chr) {
|
||||
case '\r': // CR
|
||||
writeport("\r\n",2);
|
||||
case '\n': // LF
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cnt = writeport(buf,siz);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
//=====================================================
|
||||
// Write function for overlapped I/O
|
||||
//=====================================================
|
||||
int writeport(const char *buf,int siz) {
|
||||
OVERLAPPED ovl = {0};
|
||||
ovl.hEvent = hWriteEvent;
|
||||
DWORD cnt;
|
||||
int rc;
|
||||
rc = WriteFile(hComPort,buf,siz,&cnt,&ovl);
|
||||
if (rc == 0) {
|
||||
if (GetLastError() != ERROR_IO_PENDING) return -1;
|
||||
WaitForSingleObject(hWriteEvent,INFINITE);
|
||||
GetOverlappedResult(hComPort, &ovl, &cnt, TRUE);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user