Initial public source release
Split reusable rendering and format support into vectorail-core and vectorail-gc.
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned char u8;
|
||||
typedef int i32;
|
||||
|
||||
__declspec(dllimport) void *__stdcall CreateFileA(const char *name, u32 access, u32 share,
|
||||
void *security, u32 creation,
|
||||
u32 flags, void *template_file);
|
||||
__declspec(dllimport) u32 __stdcall SetFilePointer(void *file, i32 distance,
|
||||
i32 *distance_high, u32 method);
|
||||
__declspec(dllimport) int __stdcall WriteFile(void *file, const void *buffer, u32 bytes,
|
||||
u32 *written, void *overlapped);
|
||||
__declspec(dllimport) int __stdcall CloseHandle(void *object);
|
||||
|
||||
#define GENERIC_WRITE 0x40000000u
|
||||
#define FILE_SHARE_READ_WRITE 0x00000003u
|
||||
#define OPEN_ALWAYS 4u
|
||||
#define FILE_ATTRIBUTE_NORMAL 0x00000080u
|
||||
#define FILE_END 2u
|
||||
#define INVALID_HANDLE_VALUE ((void *)-1)
|
||||
|
||||
#define FT_OK 0u
|
||||
#define FT_INVALID_HANDLE 1u
|
||||
#define FT_LIST_NUMBER_ONLY 0x80000000u
|
||||
#define FT_LIST_BY_INDEX 0x40000000u
|
||||
|
||||
static void *g_handle = (void *)0x46544449u; /* "FTDI" */
|
||||
static u32 g_log_count;
|
||||
|
||||
static char *append_char(char *p, char c)
|
||||
{
|
||||
*p++ = c;
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *append_text(char *p, const char *s)
|
||||
{
|
||||
while (*s) {
|
||||
*p++ = *s++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static char *append_hex(char *p, u32 value)
|
||||
{
|
||||
static const char digits[] = "0123456789abcdef";
|
||||
int i;
|
||||
p = append_text(p, "0x");
|
||||
for (i = 7; i >= 0; --i) {
|
||||
*p++ = digits[(value >> (i * 4)) & 0xf];
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void log4(const char *name, u32 a, u32 b, u32 c, u32 d)
|
||||
{
|
||||
char line[192];
|
||||
char *p;
|
||||
u32 written;
|
||||
void *file;
|
||||
|
||||
if (g_log_count++ > 20000) {
|
||||
return;
|
||||
}
|
||||
|
||||
p = line;
|
||||
p = append_text(p, name);
|
||||
p = append_char(p, '(');
|
||||
p = append_hex(p, a);
|
||||
p = append_text(p, ", ");
|
||||
p = append_hex(p, b);
|
||||
p = append_text(p, ", ");
|
||||
p = append_hex(p, c);
|
||||
p = append_text(p, ", ");
|
||||
p = append_hex(p, d);
|
||||
p = append_text(p, ")\r\n");
|
||||
|
||||
file = CreateFileA("Z:\\tmp\\ftd2xx_shim.log", GENERIC_WRITE, FILE_SHARE_READ_WRITE,
|
||||
0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
|
||||
if (file == INVALID_HANDLE_VALUE) {
|
||||
return;
|
||||
}
|
||||
SetFilePointer(file, 0, 0, FILE_END);
|
||||
WriteFile(file, line, (u32)(p - line), &written, 0);
|
||||
CloseHandle(file);
|
||||
}
|
||||
|
||||
static void copy_text(char *dst, const char *src, u32 max)
|
||||
{
|
||||
u32 i;
|
||||
if (!dst || !max) {
|
||||
return;
|
||||
}
|
||||
for (i = 0; i + 1 < max && src[i]; ++i) {
|
||||
dst[i] = src[i];
|
||||
}
|
||||
dst[i] = 0;
|
||||
}
|
||||
|
||||
int __attribute__((stdcall)) DllMain(void *module, unsigned long reason, void *reserved)
|
||||
{
|
||||
(void)module;
|
||||
(void)reason;
|
||||
(void)reserved;
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_Open(i32 device_number, void **handle_out)
|
||||
{
|
||||
log4("FT_Open", (u32)device_number, (u32)handle_out, 0, 0);
|
||||
if (handle_out) {
|
||||
*handle_out = g_handle;
|
||||
}
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_OpenEx(void *arg, u32 flags, void **handle_out)
|
||||
{
|
||||
log4("FT_OpenEx", (u32)arg, flags, (u32)handle_out, 0);
|
||||
if (handle_out) {
|
||||
*handle_out = g_handle;
|
||||
}
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_Close(void *handle)
|
||||
{
|
||||
log4("FT_Close", (u32)handle, 0, 0, 0);
|
||||
return handle ? FT_OK : FT_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_Read(void *handle, void *buffer, u32 bytes, u32 *read_out)
|
||||
{
|
||||
u32 i;
|
||||
log4("FT_Read", (u32)handle, (u32)buffer, bytes, (u32)read_out);
|
||||
if (buffer) {
|
||||
for (i = 0; i < bytes; ++i) {
|
||||
((u8 *)buffer)[i] = 0;
|
||||
}
|
||||
}
|
||||
if (read_out) {
|
||||
*read_out = 0;
|
||||
}
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_Write(void *handle, const void *buffer, u32 bytes, u32 *written_out)
|
||||
{
|
||||
log4("FT_Write", (u32)handle, (u32)buffer, bytes, (u32)written_out);
|
||||
if (written_out) {
|
||||
*written_out = bytes;
|
||||
}
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_ListDevices(void *arg1, void *arg2, u32 flags)
|
||||
{
|
||||
log4("FT_ListDevices", (u32)arg1, (u32)arg2, flags, 0);
|
||||
if (flags & FT_LIST_NUMBER_ONLY) {
|
||||
if (arg1) {
|
||||
*(u32 *)arg1 = 1;
|
||||
}
|
||||
} else if ((flags & FT_LIST_BY_INDEX) && arg2) {
|
||||
copy_text((char *)arg2, "FTD2XX-GC-RFID", 32);
|
||||
} else if (arg1) {
|
||||
*(u32 *)arg1 = 1;
|
||||
}
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_GetStatus(void *handle, u32 *rx_bytes, u32 *tx_bytes, u32 *event_status)
|
||||
{
|
||||
log4("FT_GetStatus", (u32)handle, (u32)rx_bytes, (u32)tx_bytes, (u32)event_status);
|
||||
if (rx_bytes) {
|
||||
*rx_bytes = 0;
|
||||
}
|
||||
if (tx_bytes) {
|
||||
*tx_bytes = 0;
|
||||
}
|
||||
if (event_status) {
|
||||
*event_status = 0;
|
||||
}
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_W32_CreateFile(const char *name, u32 access, u32 share,
|
||||
void *security, u32 creation,
|
||||
u32 flags, void *template_file)
|
||||
{
|
||||
log4("FT_W32_CreateFile", (u32)name, access, share, creation);
|
||||
(void)security;
|
||||
(void)flags;
|
||||
(void)template_file;
|
||||
return (u32)g_handle;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_EE_Read(void *handle, void *data)
|
||||
{
|
||||
log4("FT_EE_Read", (u32)handle, (u32)data, 0, 0);
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_EE_Program(void *handle, void *data)
|
||||
{
|
||||
log4("FT_EE_Program", (u32)handle, (u32)data, 0, 0);
|
||||
return FT_OK;
|
||||
}
|
||||
|
||||
u32 __attribute__((stdcall)) FT_ResetDevice(void *handle) { log4("FT_ResetDevice", (u32)handle, 0, 0, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_SetBaudRate(void *handle, u32 baud) { log4("FT_SetBaudRate", (u32)handle, baud, 0, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_SetDataCharacteristics(void *handle, u8 word_length, u8 stop_bits, u8 parity) { log4("FT_SetDataCharacteristics", (u32)handle, word_length, stop_bits, parity); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_Purge(void *handle, u32 mask) { log4("FT_Purge", (u32)handle, mask, 0, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_SetTimeouts(void *handle, u32 read_ms, u32 write_ms) { log4("FT_SetTimeouts", (u32)handle, read_ms, write_ms, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_SetEventNotification(void *handle, u32 mask, void *event) { log4("FT_SetEventNotification", (u32)handle, mask, (u32)event, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_SetLatencyTimer(void *handle, u8 timer) { log4("FT_SetLatencyTimer", (u32)handle, timer, 0, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_SetUSBParameters(void *handle, u32 in_size, u32 out_size) { log4("FT_SetUSBParameters", (u32)handle, in_size, out_size, 0); return FT_OK; }
|
||||
u32 __attribute__((stdcall)) FT_CyclePort(void *handle) { log4("FT_CyclePort", (u32)handle, 0, 0, 0); return FT_OK; }
|
||||
Reference in New Issue
Block a user