wonx/UNIXSerialPort.c
Hiroaki Sakai c0b964b4f4 Added dummy function of _asm_*().
Set FP_OFF ​(), FP_SEG() for the callback function at interrupt setting in WonderWitch
Adjust appropriately according to the setting method.  (Fit to wwterm)

UNIXTimer.c: UNIXTimer_Unpause()
((unix_timer -> pause == 1) && (unix_timer -> interrupt_in_pause == 0))
Fixed a bug that was not unix_timer-> pause--; when it was.
(It was not unposted when interrupt was not applied during pause)

Serial receive interrupt, keyboard interrupt added.  (corresponding to wwterm, operation confirmed)
Added UNIXSerialPort class.

With this, at WonderWitch,
com_intvector.callback = (void (near *) ()) FP_OFF ​​(com_handler);
com_intvector.cs = _ asm_inline ("\tmov \tax, cs");
com_intvector.ds = _ asm_inline ("\tmov \tax, ds");
sys_interrupt_set_hook (SYS_INT_RECEIVEREADY,
& com_intvector, & com_last_intvector);
Interrupt setting like that shown in Fig.

For warning, add WonX_Warning ().
Move WonX_Error () to WonX.c.

comm_send_string (), text_put_string (), text_put_substring () When executed
Fix output message.

Implement cursor display function.  (Add WWCursor class) (Do not blink. Display only)
When displaying the cursor, text information inside WWDisplay_DrawLCDPanel ()
Since we need to be able to read it, we will discontinue the WonXText class and add the WWText class
I moved to a member of the WWDisplay class.

In palette_get_color (), transparent color is displayed when executing WWPalette_GetMappedColors ()
Since it was not considered to be returned as -1, palette_get_color ()
Fixed a bug where return value was wrong value.

Character color palette, LCD color palette initial value, with WonderWitch
It was made to coincide with the initial value.

As a sample, add wwterm - b 05.  (Add wwterm target to Makefile)

Version 1.1 - from wonx-1.1.tar.gz
2018-03-07 23:07:04 +00:00

181 lines
5.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*****************************************************************************/
/* ここから */
/*****************************************************************************/
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include "UNIXSerialPortP.h"
#include "WonX.h"
#include "etc.h"
/*****************************************************************************/
/* メンバ関数の定義 */
/*****************************************************************************/
/*---------------------------------------------------------------------------*/
/* ポートの open/close */
/*---------------------------------------------------------------------------*/
int UNIXSerialPort_Open(UNIXSerialPort unix_serial_port)
{
unix_serial_port->opened = 1;
return (0);
}
int UNIXSerialPort_Close(UNIXSerialPort unix_serial_port)
{
unix_serial_port->opened = 0;
return (0);
}
int UNIXSerialPort_IsOpened(UNIXSerialPort unix_serial_port)
{ return (unix_serial_port->opened != 0); }
int UNIXSerialPort_IsClosed(UNIXSerialPort unix_serial_port)
{ return (unix_serial_port->opened == 0); }
/*---------------------------------------------------------------------------*/
/* 受信データがあるかどうか */
/*---------------------------------------------------------------------------*/
/*
* タイムアウト時間をミリ秒単位で指定.
* 0 のときは,即時
* -1 のときは,無期限待ち
*/
int UNIXSerialPort_IsDataExisting(UNIXSerialPort unix_serial_port,
int timeout)
{
fd_set bitmap;
struct timeval t;
struct timeval * t_p;
#if 0
int c;
#endif
if (UNIXSerialPort_IsClosed(unix_serial_port)) return (0);
/*
* 0 のときは,即時
* -1 のときは,無期限待ち
*/
if (timeout == -1) {
t_p = NULL;
} else {
t.tv_sec = timeout / 1000;
t.tv_usec = (timeout % 1000) * 1000;
t_p = &t;
}
/*
* FreeBSD3.4 で実験したところ,
* アラームシグナルを使用する場合select()でのブロック中に
* アラームシグナルが発生するとその直後にselect()もタイムアウト
* してしまうので,注意.
* (select() がタイムアウトした後にアラームシグナルが発生する場合は,
* 正常に動作した)
* 論理上は問題が無いが,期待した時間だけ待ってくれないという現象が
* 起きる可能性がある.
*/
#if 0
/* 読み飛ばしたい文字があるときは,こっちのコードを使う */
do {
FD_ZERO(&bitmap);
FD_SET(fileno(stdin), &bitmap);
select(fileno(stdin) + 1, &bitmap, NULL, NULL, t_p);
if (!FD_ISSET(fileno(stdin), &bitmap))
return (0);
c = fgetc(stdin);
} while (0); /* 読み飛ばしたい文字があるときはここでcをチェックする */
ungetc(c, stdin);
#else
FD_ZERO(&bitmap);
FD_SET(fileno(stdin), &bitmap);
select(fileno(stdin) + 1, &bitmap, NULL, NULL, t_p);
if (!FD_ISSET(fileno(stdin), &bitmap))
return (0);
#endif
return (1);
}
/*---------------------------------------------------------------------------*/
/* 受信 */
/*---------------------------------------------------------------------------*/
int UNIXSerialPort_ReceiveCharacter(UNIXSerialPort unix_serial_port,
int timeout)
{
int c;
if (UNIXSerialPort_IsClosed(unix_serial_port)) return (-1);
c = UNIXSerialPort_IsDataExisting(unix_serial_port, timeout)
? fgetc(stdin) : -1;
c = (c == '\n') ? '\r' : c; /* \r のエミュレーション */
return (c);
}
/*---------------------------------------------------------------------------*/
/* 送信 */
/*---------------------------------------------------------------------------*/
int UNIXSerialPort_SendCharacter(UNIXSerialPort unix_serial_port,
unsigned char c)
{
if (UNIXSerialPort_IsClosed(unix_serial_port)) return (0);
wonx_print_character(stdout, c);
return (1);
}
/*---------------------------------------------------------------------------*/
/* オブジェクトの作成 */
/*---------------------------------------------------------------------------*/
UNIXSerialPort UNIXSerialPort_Create()
{
UNIXSerialPort unix_serial_port;
unix_serial_port = (UNIXSerialPort)malloc(sizeof(_UNIXSerialPort));
if (unix_serial_port == NULL)
WonX_Error("UNIXSerialPort_Create", "Cannot allocate memory.");
unix_serial_port->opened = 0;
return (unix_serial_port);
}
/*---------------------------------------------------------------------------*/
/* オブジェクトの削除 */
/*---------------------------------------------------------------------------*/
UNIXSerialPort UNIXSerialPort_Destroy(UNIXSerialPort unix_serial_port)
{
if (unix_serial_port == NULL)
WonX_Error("UNIXSerialPort_Destroy", "Object is not created.");
if (UNIXSerialPort_IsOpened(unix_serial_port))
UNIXSerialPort_Close(unix_serial_port);
free(unix_serial_port);
return (NULL);
}
/*****************************************************************************/
/* ここまで */
/*****************************************************************************/
/*****************************************************************************/
/* End of File. */
/*****************************************************************************/