The text of a manual · part 40 of 42
JANUS PSK for C/C++ Reference Manual, Version 2.1, pages 391 to 400
Pages 391 to 400 of 414
The original document is the PDF (690 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Intermec J2020, Intermec J2010 and Intermec J2050
Page 391
numpad.cpp
B
B-39
Page 392
numpad.cpp
KP_Func(KP_NUMPAD, KP_OFF, &rbuff);
// make sure we can get menu choice ch = ' '; while(ch != ESC) { ch = getch(); switch(ch) { case '1': KP_Func(KP_NUMPAD, KP_OFF, &rbuff); ch = ESC; break; case '2': KP_Func(KP_NUMPAD, KP_ON_NUM_ON, &rbuff); ch = ESC; break; case '3': KP_Func(KP_NUMPAD, KP_ON_NUM_OFF, &rbuff); ch = ESC; break; }; } clrscr(); exit(0); } // Execute requested keypad function IM_UINT KP_Func(IM_UCHAR func, IM_UCHAR subfunc, RESP_BUFF *resp) { _ES = FP_SEG(resp); _BX = FP_OFF(resp); _AH = func; _AL = subfunc; _CL = 0x01; geninterrupt(KEYPAD_Int); return(_AH); }
B-40
// keypad function // subfunction // keypad mode switching permitted
Page 393
phterm.cpp
B phterm.cpp /* phterm.cpp * * This program demonstrates how to use interrupts and protocol. It requires a * Janus running PHIMEC.EXE and a connection to something else using an INTERMEC * protocol. * * Written: Aug. 12, 1993 as PHCOMM, derived PHTERM Feb. 28, 1994 * Last Modified: March 1, 1994 * Author: Ray Rogers * Compiler: Borland C++ 3.1, small model */ #include "stdio.h" #include "string.h" #include "dos.h" #include "conio.h" #include "stdlib.h" #include "im20lib.h" // Defines #define COM_Int 0x14 #define LCD_Int 0x79 #define SOUND_Int 0x7c #define VIDEO_Int 0x10 #define ESC 0x1b #define TXBUFFSIZE 512 #define RXBUFFSIZE 512 #define COM_PORT 3 #define LOUD 3 #define NORMAL 2 #define LOW 1 #define BOOL IM_UINT #define TRUE 1 #define FOREVER TRUE typedef struct { IM_UCHAR volume; IM_UINT pitch; IM_UINT duration; IM_UINT off_time; } IM_BEEP_PARAMS;
// Communications interrupt // LCD size mode manager interrupt // sound generation interrupt // video interrupt // char 27, Escape // transmit buffer size // receive buffer size // default to com port 0 for Janus // loud volume for beep // normal volume for beep // low volume for beep
// beeper sound structure
// struct for window control on JANUS typedef struct { IM_UCHAR ur; // upper row IM_UCHAR uc; // upper column IM_UCHAR lr; // lower row IM_UCHAR lc; // lower column IM_UCHAR cr; // current row, relative to this window IM_UCHAR cc; // current column, relative to this window } JANUS_WINDOW; // Global Variables IM_UINT vm_mode; IM_UINT vm_params; IM_COM_DATA_BUFFER s_struct; IM_COM_DATA_BUFFER r_struct;
// saves original video mode // saves original video parameters // send structure // receive structure
B-41
Page 394
phterm.cpp
IM_UCHAR
B-42 s_buff[TXBUFFSIZE];
// send buffer
Page 395
phterm.cpp
B
IM_UCHAR r_buff[RXBUFFSIZE]; // receive buffer JANUS_WINDOW iw = {0, 0, 0, 19, 0, 0}; // input window JANUS_WINDOW ow = {3, 0, 14, 19, 0, 0}; // output window // Prototypes IM_UINT Ck_RX_Buffer_Status(IM_UINT portid); IM_UINT TX_Buffer(IM_UINT portid); IM_UINT RX_Buffer(IM_UINT portid); IM_UINT Set_Video_Mode(void); IM_UINT Make_Noise(IM_UCHAR, IM_UINT, IM_UINT, IM_UINT); IM_UINT Get_Input(void); void Reset_Video_Mode(void); void Cancel_TX(IM_UINT port); void Cancel_RX(IM_UINT port); void Pos_Cursor(JANUS_WINDOW *, IM_UINT, IM_UINT); void Shift_Left(IM_UINT); void Blank_Input(void); void Ck_y(JANUS_WINDOW *); void main() { if(Set_Video_Mode()) // set video mode, sound beep and exit on failure { Make_Noise(LOUD, 2000, 200, 20); // loud, high pitch Make_Noise(NORMAL, 500, 250, 20); // normal, low pitch exit(1); } Pos_Cursor(&ow, 0, -1); printf("%s", "____________________"); ow.cr = 0; Pos_Cursor(&iw, 0, 0); r_buff[0] = '\0'; RX_Buffer(COM_PORT);
// read the comm line
// main processing loop, exit loop on ESC key while(FOREVER) { if(Get_Input() == ESC) // get input from keyboard or comm line break; TX_Buffer(COM_PORT); }
// end main loop
Reset_Video_Mode(); Cancel_TX(COM_PORT); Cancel_RX(COM_PORT);
// return video mode to original settings // shut down interface to protocol handler
Make_Noise(LOUD, 1000, 200, 20); Make_Noise(NORMAL, 250, 250, 20);
// loud, high pitch // normal, low pitch exit(0); } // Prepare input line for new input by clearing out the old void Blank_Input() { Pos_Cursor(&iw, 0, 0); printf("%s", " "); Pos_Cursor(&iw, 0, 0); }
B-43
Page 396
phterm.cpp
B-44
Page 397
phterm.cpp
B
// Cancel the RX buffer void Cancel_RX(IM_UINT port) { _DX = port; _AH = 0x84; geninterrupt(COM_Int); } // Cancel the TX buffer void Cancel_TX(IM_UINT port) { _DX = port; _AH = 0x85; geninterrupt(COM_Int); } //Check the receive buffer is a misnomer for this function since it actually instructs //the protocol handler to receive a packet. After that, you must check //protocol_xfer_status periodically to see if anything has been received yet. IM_UINT Ck_RX_Buffer_Status(IM_UINT port) { r_struct.command = IM_CU_RECV_AGAIN; // set the cmd to receive *(r_struct.data_ptr) = '\0'; r_struct.comm_length = 0; _DX = port; _AH = 0x17;
// select the com port // check com port receive buffer status function geninterrupt(COM_Int); return(r_struct.protocol_xfer_status); } // Check the row position that is about to be used for displaying a line // received from the comm port. If it is the bottom of the screen, scroll // the window to make room. void Ck_y(JANUS_WINDOW *jw) { if(jw->ur+jw->cr > jw->lr) { jw->cr--; _AH = 0x06; // video scroll function _AL = 1; // number of lines to scroll _CH = jw->ur; // upper left row _CL = jw->uc; // upper left column _DH = jw->lr; // lower right row _DL = jw->lc; // lower right col _BH = 0x07; // normal video mode geninterrupt(VIDEO_Int); } } // Position the cursor outside the defined text window void Pos_Cursor(JANUS_WINDOW *jw, IM_UINT loc, IM_UINT row) { jw->cr = row; jw->cc = loc; _DH = jw->ur+row; // row _DL = jw->uc+loc; // column
B-45
Page 398
phterm.cpp
_BH = 0; // page _AH = 0x02; // position cursor function geninterrupt(VIDEO_Int); // video } // Get the next input string from the keyboard while watching for input from the comm line IM_UINT Get_Input() { IM_UINT x, ch; ch = x = 0; iw.cc = 0; while(ch != ESC && ch != '\r') { if(kbhit()) { ch = getch();
// keybd input ends with CR or ESC
// use getch(), then printf() because JANUS if(ch == '\r') Blank_Input(); // clears input line for clean start else if(iw.uc+iw.cc >= iw.lc) Shift_Left(x); // input exceeds line length, scroll left else Pos_Cursor(&iw, iw.cc, 0); printf("%c", ch); if(ch == '\b') { x--; iw.cc--; } else { iw.cc++; s_buff[x++] = ch; } }
// doesn't like getche() or cputs() // backspace is the only supported editing key if(r_struct.protocol_xfer_status == 0x0601)
// 0x0601 is comm buffer done from // last recv request
{ *(r_struct.data_ptr + r_struct.comm_length) = '\0'; // add null to receive Ck_y(&ow); // buffer Pos_Cursor(&ow, 0, ow.cr); ow.cr++; printf("%s\n\r", r_buff); // print buffer contents Pos_Cursor(&iw, 0, 0); Ck_RX_Buffer_Status(COM_PORT); // issue request for next packet } } strcpy(&s_buff[x], "\n"); return(ch);
// add a line feed and a null character
} // read the receive buffer IM_UINT RX_Buffer(IM_UINT port) { r_struct.command = IM_CU_RECEIVE; // set the cmd to receive r_struct.user_length = RXBUFFSIZE; r_struct.data_ptr = (IM_UCHAR far *) r_buff;
B-46
Page 399
phterm.cpp
B r_struct.protocol_mode = IM_USE_PROTOCOL;
B-47
Page 400
phterm.cpp
_ES = FP_SEG((IM_COM_DATA_BUFFER far *) &r_struct); _BX = FP_OFF((IM_COM_DATA_BUFFER far *) &r_struct); _DX = port; _AH = 0x60;
// select the com port // receive buffer geninterrupt(COM_Int); return(r_struct.protocol_xfer_status); } // transmit the transmit buffer IM_UINT TX_Buffer(IM_UINT port) { s_struct.command = IM_CU_TRANSMIT; // set the cmd to transmit s_struct.data_ptr = (IM_UCHAR far *) s_buff; s_struct.user_length = strlen((IM_UCHAR far *) s_buff); s_struct.protocol_mode = IM_USE_PROTOCOL; _ES = FP_SEG((IM_COM_DATA_BUFFER far *) &s_struct); _BX = FP_OFF((IM_COM_DATA_BUFFER far *) &s_struct); _DX = port; _AH = 0x50;
// select the com port // transmit buffer geninterrupt(COM_Int); return(s_struct.protocol_xfer_status); } // Make a noise to indicate a failure condition of some kind has occurred IM_UINT Make_Noise(IM_UCHAR volume, IM_UINT pitch, IM_UINT duration, IM_UINT off_time) { static IM_BEEP_PARAMS Beeper; // beeper sound structure Beeper.volume = volume; // loud Beeper.pitch = pitch; // HZ Beeper.duration = duration; // ms Beeper.off_time = off_time; // ms _ES = FP_SEG((IM_BEEP_PARAMS far *) &Beeper); _BX = FP_OFF((IM_BEEP_PARAMS far *) &Beeper);
// points to beeper structure // points to beeper structure
_CX = _DX = 0; _AX = 0x64;
// to be safe // sound function geninterrupt(SOUND_Int);
// generate the noise return(_AX); } // Set the video mode to 20x16 IM_UINT Set_Video_Mode() { _AH = 0x02; _AL = 0x03;
B-48
// function 2 of int 79h // get current video mode geninterrupt(LCD_Int);
// LCD display size mode manager interrupt vm_mode = _AH; vm_params = _BX;
// save the current video mode // save original video parameters
_AH = 0x02; _AL = 0x01;
// function 2 of int 79h // set mode to 20x16