1) 지식 창고는 본인이 작성한 콘텐츠(팁/노하우/리소스/강좌 등)을 무료 혹은 가상화폐인 납포인트를 통해 공유하는 공간입니다.
2) 본인이 작성한 콘텐츠에 대해서만 지식 창고에 등록할 수 있으며, 저작권에 위배되는 콘텐츠는 사전경고 없이 삭제될 수 있습니다.
3) 콘텐츠 구매 및 첨부파일 다운로드는 회원그룹 '연구원' 이상 가능하오니, 경험치를 쌓아 진급한 후에 이용 부탁드립니다.
4) 무료 콘텐츠의 본문은 구매절차 없이 즉시 이용할 수 있으며, 판매 납포인트가 있는 콘텐츠는 구매 후 이용할 수 있습니다.
5) 콘텐츠 판매에 따른 납포인트 수익은 지정한 비율(50%)에 따라 판매자에게 지급하며, 납포인트 수익을 통해 진급을 빨리할 수 있습니다.
6) 구매 후 평가를 하면 구매 납포인트의 20%를 돌려 드립니다.
판매자 | 아크마 | 판매 납포인트 | 무료 | 평점 | 0점 / 총 0명 참여 |
---|
DOS 모드라서 ...요새는 사용할지 모르겟네요..
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <io.h>
#include <alloc.h>
#include <process.h>
#include <fcntl.h>
#include <sys\stat.h>
//#include <time.h>
#include "lkey.h"
#define TRUE 1
#define FALSE 0
#define TOP_X 65
#define TOP_Y 15
#define XX 30
#define YY 7
#define WIN_MAX 9
#define MAX_POPUP 6
#define DIRECT 11
#define POPUP 22
#define CR 0x0D
#define LF 0x0A
#define CRLF 0xDA
#define COM1 0
#define COM2 1
#define COM3 2
#define COM4 3
#define COM1BASE 0x3F8
#define COM2BASE 0x2F8
#define COM3BASE 0x3E8
#define COM4BASE 0x2E8
#define COM13_INTERRUPT 0x0C
#define COM24_INTERRUPT 0x0B
// 인터럽트 마스크 레지스터의 COM1과 COM2에 해당하는
// 4비트와 3비트의 값을 바꿀 때 사용할 값
#define MASKON13 0xEF
#define MASKON24 0xF7
#define MASKOFF13 0x10
#define MASKOFF24 0x08
#define DATABIT7 0x02
#define DATABIT8 0x03
#define STOPBIT1 0x00
#define STOPBIT2 0x04
#define PARITYNONE 0x00
#define PARITYODD 0x08
#define PARITYEVEN 0x18
#define BPS1200 1200L
#define BPS2400 2400L
#define BPS4800 4800L
#define BPS9600 9600L
#define BPS19200 19200L
#define BPS38400 38400L
#define BPS57600 57600L
#define BPS115200 115200L
// UART 레지스터를 가리키기 위한 오프셋
#define LCR_OFFSET 3
#define MCR_OFFSET 4
#define IER_OFFSET 1
#define LSR_OFFSET 5
#define MSR_OFFSET 6
// PIC 칩에 있는 레지스터의 포트 번호
#define PICMASK 0x21
#define PICEIO 0x20
// 데이터 저장을 위한 버퍼와 버퍼 정보 변수
#define BUFFER_LENGTH 4096
typedef unsigned char byte;
typedef unsigned int word;
word first,last;
int PORT=COM4,DATA=DATABIT8,STOP=STOPBIT1,PARITY=PARITYNONE;
byte CR_LF = CR;
long SPEED = BPS115200;
unsigned char buffer[BUFFER_LENGTH];
int base_addr; // 직렬 포트 기본 주소
int port_int_no; // 직렬 포트 인터럽트 벡터 번호
int imr_on; // 인터럽트 마스크 레지스터를 바꾸기 위한 값
int imr_off;
word far *VS=(word far *)0XB8000000;
word *pop;
union REGS r;
char Compiler_filename[13]="",Editor_filename[30]="",HEX_filename[13]="";
char Source_filename[13]="",Dosshell_filename[30]="",status_bar[20];
char altkey[4][70]={"","","",""};
char popup_select=0,call_mode=POPUP;
char in_popup=FALSE,to_popup=FALSE;
byte old_mcr,old_msr,old_sec;
int capture; // file handle
byte *memcap;
char memcap_ok=FALSE;
word cap_len=0;
char in_capture=FALSE,hot_key=FALSE;
byte cap_file[13]="X";
char env_change=FALSE;
long filesize;
static void interrupt (*old_isr_09)();
static void interrupt isr_09();
void interrupt (*old_intr)();
void interrupt port_interrupt();
void init_serial_port(int port, unsigned char databit, unsigned char stopbit, unsigned char parity, long bps);
void init_modem(void);
void close_modem(void);
void send_character(unsigned char ch);
void send_string(unsigned char *str);
int is_reday_to_receive(void);
unsigned char receive_character(void);
void flush_buffer(void);
//int detect_carrier(void);
void make_popup(void); // ALT키 눌렀을때 호출되는 메뉴
void toggle_blink(char n); // 밝은배경색 쓰기위해
void restore_popup(void); // 메뉴제거,메모리 반납
void popup_key_delay(void); // 메뉴에서 키값 읽기
char Enter_process(void); // 메뉴에서 엔터키 쳤을때
void read_ini(void); // 환경설정 INI 화일 읽기
void scroll_up(void); // 24라인까지 스크롤
void is_ready_scroll(char); // 커서가 24라인으로 가면 스크롤
void make_status_bar(void); // 맨아래 상태바(속도,포트,...)
void call_dosshell(void);
void toggle_att(byte top_x, byte top_y, byte bottom_x, byte bottom_y, char bb);
void good_bye(void);
void alt_macro_exec(char *macro);
void reset_config(void);
void win_enter(char num);
char key_delay(char num,char x,char y,char *arr[]);
void get_filename(char mode,char *name);
void save_ini(void);
void save_env(void);
void mem_cpy(byte *mm,int off,byte *str,byte len);
void main(void)
{
unsigned char ch;
int key;
old_isr_09=getvect(0x09);
setvect(0x09,isr_09);
cls(0x07);
gotoxy(1,1);
read_ini();
toggle_blink(0);
// 직렬 포트 초기화
init_serial_port(PORT, DATA, STOP, PARITY, SPEED);
init_modem(); // 포트 초기화
send_character(CR);
delay(100);
flush_buffer();
while(1) {
if(is_reday_to_receive()) { // 문자가 버퍼에 있으면
ch = receive_character();
if(wherey()==23 && ch==LF) scroll_up();
else if(wherey()==23 && wherex()==80) {
scroll_up();
gotoxy(1,23);
}
else printf("%c",ch);
if(in_capture) {
if(cap_len==4097) { write(capture,memcap,4096); cap_len=0;}
if(memcap_ok) *(memcap+cap_len++)=ch;
//else fprintf(capture,"%c",ch);
}
while (first!=last) flush_buffer();
}
if(to_popup) {
make_popup();
to_popup=FALSE;
}
if (kbhit()) { // 키보드 입력이 있으면
in_popup=TRUE;
ch=getch();
if(ch) send_character(ch);
else {
key = getch()+256;
//if(ch==82 || ch==71 || ch==79 || ch==73 || ch==81) {
call_mode=DIRECT;
switch(key) {
case INSERT :
case EDITOR :
popup_select=0;
Enter_process();
break;
case HOME :
case COMPILE:
popup_select=1;
Enter_process();
break;
case END :
call_dosshell();
break;
case PGUP :
case SEND :
popup_select=2;
Enter_process();
break;
case PGDOWN :
case CAPTURE:
case ALT_L :
popup_select=3;
Enter_process();
break;
case SETUP :
popup_select=4;
Enter_process();
break;
case ALT_F1 :
case ALT_F2 :
case ALT_F3 :
case ALT_F4 :
alt_macro_exec(altkey[key-360]);
break;
case ALT_X :
good_bye();
break;
} //end of switch()
call_mode=POPUP;
} // end of else if
in_popup=FALSE;
} // end of if
} // end of while()
}
void call_dosshell(void)
{
cls(0x07);
toggle_blink(1);
if(spawnlp(P_WAIT,Dosshell_filename,NULL)==-1) {
// Error message
}
cls(0x07);
toggle_blink(0);
make_status_bar();
gotoxy(1,1);
}
void init_serial_port(int port, unsigned char databit, unsigned char stopbit, unsigned char parity, long bps)
{
char ch, old_lcr;
unsigned int divisor;
unsigned char high, low;
// 각 직렬 포트의 기본 주소, 인터럽트 벡터 번호, 인터럽트 마스크
// 레지스터를 바꾸기 위한 값을 셋팅 - 포트 입출력할 때 사용
switch(port) {
case COM1 :
base_addr = COM1BASE;
port_int_no = COM13_INTERRUPT;
imr_on = MASKON13;
imr_off = MASKOFF13;
break;
case COM2 :
base_addr = COM2BASE;
port_int_no = COM24_INTERRUPT;
imr_on = MASKON24;
imr_off = MASKOFF24;
break;
case COM3 :
base_addr = COM3BASE;
port_int_no = COM13_INTERRUPT;
imr_on = MASKON13;
imr_off = MASKOFF13;
break;
case COM4 :
base_addr = COM4BASE;
port_int_no = COM24_INTERRUPT;
imr_on = MASKON24;
imr_off = MASKOFF24;
break;
}
// 라인 제어 레지스터의 값 셋팅
ch = databit | stopbit | parity;
outportb(base_addr + LCR_OFFSET, ch);
// 모뎀 속도 셋팅
divisor = (unsigned int) (1843200L / (bps * 16L));
high = (unsigned char) (divisor >> 8);
low = (unsigned char) divisor;
// 라인 제어 레지스터의 비트 1번 DLAB를 1롤 셋팅 (0x80 = 10000000b)
old_lcr = inportb(base_addr + LCR_OFFSET);
outportb(base_addr + LCR_OFFSET, old_lcr | 0x80);
// DLL과 DLH에 모뎀 속도 값 보내기
outportb(base_addr, low);
outportb(base_addr + 1, high);
// 라인 제어 레지스터의 비트 1번 DLAB를 다시 0으로 셋팅 (0x7F = 01111111b)
old_lcr = inportb(base_addr + LCR_OFFSET);
outportb(base_addr + LCR_OFFSET, old_lcr & 0x7F);
}
void interrupt port_interrupt()
{
unsigned char ch;
// last = 가장 최근에 들어온 데이터를 가리키는 변수
if(last == BUFFER_LENGTH) last = 0;
// 포트에서 데이터를 읽어와 저장
ch = inportb(base_addr);
if(ch) buffer[last++] = ch;
if(ch == CR && CR_LF == CRLF) {
if(last == BUFFER_LENGTH) last = 0;
buffer[last++] = LF;
}
// PIC의 EIO 인터럽트에 인터럽트가 끝났다는 신호 보내기
outportb(PICEIO, 0x20);
}
void init_modem(void)
{
unsigned char old_imr;
// 포트에서 발생하는 인터럽트 재정의
old_intr = getvect(port_int_no);
setvect(port_int_no, port_interrupt);
// 모뎀 제어 레지스터 셋팅 (0x0B = 00001011b)
old_mcr = inportb(base_addr + MCR_OFFSET);
outportb(base_addr + MCR_OFFSET, 0x0B);
// 인터럽트 허용 레지스터 셋팅 (0x01 = 00000001b)
outportb(base_addr + IER_OFFSET, 0x01);
// 버퍼 정보 셋팅
first = last = 0;
// 모뎀 상태 레지스터 셋팅 (0x30 = 00110000b)
old_msr = inportb(base_addr + MSR_OFFSET);
outportb(base_addr + MSR_OFFSET, old_msr | 0x30);
// 인터럽트 마스크 레지스터 셋팅
old_imr = inportb(PICMASK);
outportb(PICMASK, old_imr & imr_on);
// 라인 청소
delay(200);
inportb(base_addr);
inportb(base_addr);
}
void close_modem(void)
{
unsigned char old_imr;
// 인터럽트 허용 레지스터 셋팅
outportb(base_addr + IER_OFFSET, 0x00);
outportb(base_addr + MCR_OFFSET, old_mcr);
outportb(base_addr + MSR_OFFSET, old_msr);
// 인터럽트 마스크 레지스터 셋팅
old_imr = inportb(PICMASK);
outportb(PICMASK, old_imr | imr_off);
// 인터럽트 핸들러 회복
setvect(port_int_no, old_intr);
// 버퍼 메모리 해제
//free(buffer);
}
void send_character(unsigned char ch)
{
char lsr;
do {
// UART의 전송 대기 레지스터가 비워질 때까지
lsr = inport(base_addr + LSR_OFFSET) & 0x20;
} while(lsr == 0);
outportb(base_addr, ch); // 문자 전송
}
void send_string(unsigned char *str)
{
while(*str) send_character(*str++);
}
int is_reday_to_receive(void) {
if(first == last) return 0;
else return 1;
}
unsigned char receive_character(void)
{
// first = 데이터를 읽어올 곳을 가리키는 변수
if(first == BUFFER_LENGTH) first = 0;
// 버퍼 읽기
return buffer[first++];
}
/***********************************************************
* void flush_buffer()
* - 버퍼에 있는 모든 문자를 출력하는 함수
* 입력 : 없음
* 출력 : 없음
* 리턴값 : 없음
***********************************************************/
void flush_buffer(void)
{
while (first!=last) {
if(first == BUFFER_LENGTH) first = 0;
if(wherey()==23 && buffer[first]==LF) scroll_up();
else if(wherey()==23 && wherex()==80) {
scroll_up();
gotoxy(1,23);
}
else printf("%c",buffer[first]);
if(in_capture) {
if(cap_len==4097) { write(capture,memcap,4096); cap_len=0;}
if(memcap_ok) *(memcap+cap_len++)=buffer[first];
}
//fprintf(capture,"%c",buffer[first]);
first++;
}
}
/***********************************************************
* int DetectCarrier()
* - 데이터 캐리어가 검출되었는 확인하는 함수
* - 데이터 캐리어가 검출되면 전화가 연결된 것을 의미
* 입력 : 없음
* 출력 : 없음
* 리턴값 : 1 - 검출
***********************************************************
int detect_carrier(void)
{
return inportb(base_addr + MSR_OFFSET) & 0x80;
}
*/
void toggle_blink(char n) // n값이 0이면 배경색 깜박임 없음
{
r.x.ax=0x1003;
r.h.bl=n;
int86(0x10,&r,&r);
}
void make_popup(void)
{
char m,n;
word *pp;
in_popup=TRUE;
cursor_off();
pp=pop=(word *)malloc(14*2*(MAX_POPUP+3));
for(n=0;n<MAX_POPUP+3;n++) for(m=0;m<14;m++)
*pp++=*(VS+(TOP_Y+n)*80+TOP_X+m); // 메뉴만들곳의 화면 저장
set_att(65,23,78,23,B_BORA | WHITE);
double_box(TOP_X,TOP_Y,TOP_X+13,TOP_Y+MAX_POPUP+1,B_LBORA | WWHITE,0);
sprint(TOP_X+1,TOP_Y+1 ,B_LBORA | BLACK,"Edit file");
sprint(TOP_X+1,TOP_Y+2 ,B_LBORA | BLACK,"Compile");
sprint(TOP_X+1,TOP_Y+3,B_LBORA | BLACK,"Send file");
sprint(TOP_X+1,TOP_Y+4,B_LBORA | BLACK,"Capture data");
sprint(TOP_X+1,TOP_Y+5,B_LBORA | BLACK,"Setup");
sprint(TOP_X+1,TOP_Y+6,B_LBORA | BLACK,"Exit");
set_att(TOP_X+1,TOP_Y+1,TOP_X+1,TOP_Y+3,B_LBORA | L_BLUE);
set_att(TOP_X+3,TOP_Y+4,TOP_X+3,TOP_Y+4,B_LBORA | L_BLUE);
set_att(TOP_X+4,TOP_Y+5,TOP_X+4,TOP_Y+5,B_LBORA | L_BLUE);
set_att(TOP_X+2,TOP_Y+6,TOP_X+2,TOP_Y+6,B_LBORA | L_BLUE);
//set_att(51,8+popup_select,64,8+popup_select,B_NORMAL | WWHITE);
toggle_att(TOP_X+1,TOP_Y+1+popup_select,TOP_X+12,TOP_Y+1+popup_select,1);
popup_key_delay();
in_popup=FALSE;
}
void popup_key_delay(void)
{
char stop=0;
int ch;
while(!stop){ //STOP -> 0:Normal 1:ESC 2:ENTER
r.h.ah=0x02;
int86(0x16,&r,&r);
if(r.h.al & CTRL) {
send_character(CR);
break;
}
if(kbhit()) {
ch=get_key();
switch( ch ) {
case KESC : stop=1;
send_character(CR);
break;
case ENTER :
stop=2;
if(Enter_process()) continue;
break;
case DOWN :
if(popup_select==MAX_POPUP-1) break;
toggle_att(TOP_X+1,TOP_Y+1+popup_select,TOP_X+12,TOP_Y+1+popup_select,0);
popup_select++;
toggle_att(TOP_X+1,TOP_Y+1+popup_select,TOP_X+12,TOP_Y+1+popup_select,1);
break;
case UP :
if(!popup_select) break;
toggle_att(TOP_X+1,TOP_Y+1+popup_select,TOP_X+12,TOP_Y+1+popup_select,0);
popup_select--;
toggle_att(TOP_X+1,TOP_Y+1+popup_select,TOP_X+12,TOP_Y+1+popup_select,1);
break;
case EDITOR :
stop=2;
popup_select=0;
if(Enter_process()) continue;
break;
case COMPILE:
stop=2;
popup_select=1;
if(Enter_process()) continue;
break;
case SEND :
stop=2;
popup_select=2;
if(Enter_process()) continue;
break;
case CAPTURE:
case ALT_L :
stop=2;
popup_select=3;
if(Enter_process()) continue;
break;
case SETUP :
stop=2;
popup_select=4;
if(Enter_process()) continue;
break;
case ALT_F1 :
case ALT_F2 :
case ALT_F3 :
case ALT_F4 :
stop=2;
restore_popup();
alt_macro_exec(altkey[ch-360]);
break;
case ALT_X :
good_bye();
break;
default : continue;
}
}
}
if(stop!=2) restore_popup();
}
void good_bye(void)
{
setvect(0x09,old_isr_09);
if(env_change) save_ini();
toggle_blink(1);
if(pop!=NULL) restore_popup();
close_modem();
clear(0,23,79,24,0x07);
cursor_on();
gotoxy(1,24);
exit(0);
}
void restore_popup(void) // 메뉴화면 원래대로 복구
{
char m,n;
word *pp=pop;
for(n=0;n<MAX_POPUP+3;n++) for(m=0;m<14;m++)
*(VS+(TOP_Y+n)*80+TOP_X+m)=*pp++;
free(pop);
pop=NULL;
cursor_on();
}
int get_key(void) // 키값이 있을때는 그값을..
{ // 없을때는 다음값에 256더한값.(즉 확장키)
int ch;
ch=getch();
if(!ch) ch=getch()+256;
return ch;
}
char Enter_process(void) // return 1-> continue , 0-> break
{
byte data[70];
FILE *fp;
char value,temp[3],cp=1,cx,cy;
struct date d;
if(popup_select<0 || popup_select>MAX_POPUP-1) return 1;
if(pop!=NULL) restore_popup();
switch(popup_select) {
case 0 :
cls(0x07);
toggle_blink(1);
if(spawnlp(P_WAIT,Editor_filename,Editor_filename,Source_filename,NULL)==-1) {
// Error message
toggle_blink(0);
make_status_bar();
make_popup();
return 1;
}
toggle_blink(0);
cls(0x07);
make_status_bar();
gotoxy(1,1);
popup_select=1;
make_popup();
return 1;
case 1 :
cls(0x07);
toggle_blink(1);
gotoxy(1,1);
system(Compiler_filename);
printf("\nPress any key to return...");
r.h.ah=0;
int86(0x16,&r,&r);
cls(0x07);
toggle_blink(0);
make_status_bar();
gotoxy(1,1);
send_character(CR);
return 0; // stop
case 2 :
get_filename(1,HEX_filename);
if((fp=fopen(HEX_filename,"rt"))==NULL) {
// File open box
}
sprintf(data," %12s ",HEX_filename);
sprint(35,24,B_LRED | WWHITE,data);
while(fscanf(fp,"%s\n",data)!=-1) {
send_string(data);
}
send_character(CR);
fclose(fp);
delay(500);
flush_buffer();
return 0; // stop
case 3 :
if(in_capture) {
in_capture=FALSE;
memcap_ok=FALSE;
if(cap_len) write(capture,memcap,cap_len);
cap_len=0;
free(memcap);
sprint(66,24,B_LBLUE | WWHITE,"?AJOU UNIV. ?);
set_att(79,24,79,24,B_LBLUE | BLACK);
close(capture);
strcpy(cap_file,"X");
}
else {
hot_key=TRUE+1;
getdate(&d);
itoa(d.da_mon,temp,10);
if(d.da_mon<10) {
cap_file[cp++]='0';
cap_file[cp++]=temp[0];
}
else {
cap_file[cp++]=temp[0];
cap_file[cp++]=temp[1];
}
//strcat(cap_file,temp);
itoa(d.da_day,temp,10);
if(d.da_day<10) {
cap_file[cp++]='0';
cap_file[cp++]=temp[0];
}
else {
cap_file[cp++]=temp[0];
cap_file[cp++]=temp[1];
}
//strcat(cap_file,temp);
in_capture=TRUE;
cap_file[cp]='\0';
strcat(cap_file,".CAP");
get_filename(1,cap_file);
sprint(67,24,B_LRED | WWHITE," ");
sprint(73-strlen(cap_file)/2,24,B_LRED | WWHITE,cap_file);
capture=open(cap_file,O_WRONLY | O_TEXT | O_CREAT,S_IWRITE);
memcap=(byte *)malloc(4096);
if(memcap!=NULL) memcap_ok=TRUE;
//if(memcap_ok==FALSE) printf("error");
}
return 0;
case 4 :
cx=wherex();
cy=wherey();
close_modem();
reset_config();
init_serial_port(PORT, DATA, STOP, PARITY, SPEED);
init_modem(); // 포트 초기화
//cls(0x07);
make_status_bar();
gotoxy(cx,cy);
send_character(CR);
return 0;
case 5 :
good_bye();
break;
}
return 1;
}
void reset_config(void)
{
word *win1,*ww;
char m,n,win1_select=0;
char stop=0;
int ch;
cursor_off();
env_change=TRUE;
ww=win1=(word *)malloc(17*2*(WIN_MAX+3));
for(n=0;n<WIN_MAX+3;n++) for(m=0;m<17;m++)
*win1++=*(VS+(YY+n)*80+XX+m);
win1=ww;
double_box(XX,YY,XX+14,YY+WIN_MAX+1,B_BLUE | WWHITE,1);
sprint(XX+2,YY+1,B_BLUE | YELLOW,"Port");
sprint(XX+2,YY+2,B_BLUE | YELLOW,"Baud rate");
sprint(XX+2,YY+3,B_BLUE | YELLOW,"Data bit");
sprint(XX+2,YY+4,B_BLUE | YELLOW,"Stop bit");
sprint(XX+2,YY+5,B_BLUE | YELLOW,"Parity bit");
sprint(XX+2,YY+6,B_BLUE | YELLOW,"CR + LF");
sprint(XX+2,YY+7,B_BLUE | YELLOW,"Source file");
sprint(XX+2,YY+8,B_BLUE | YELLOW,"HEX file");
sprint(XX+2,YY+9,B_BLUE | YELLOW,"Compiler");
set_att(XX+1,YY+1,XX+13,YY+1,B_YELLOW | BLACK);
while(!stop){ //STOP -> 0:Normal 1:ESC 2:ENTER
r.h.ah=0x02;
int86(0x16,&r,&r);
if(r.h.al & CTRL) break; // CTRL 키가 눌리면 메뉴종료
if(kbhit() ) {
ch=get_key();
switch( ch ) {
case KESC : stop=1;
break;
case ENTER :
win_enter(win1_select);
break;
case DOWN :
if(win1_select==WIN_MAX-1) break;
set_att(XX+1,YY+1+win1_select,XX+13,YY+1+win1_select,B_BLUE | YELLOW);
win1_select++;
set_att(XX+1,YY+1+win1_select,XX+13,YY+1+win1_select,B_YELLOW | BLACK);
break;
case UP :
if(!win1_select) break;
set_att(XX+1,YY+1+win1_select,XX+13,YY+1+win1_select,B_BLUE | YELLOW);
win1_select--;
set_att(XX+1,YY+1+win1_select,XX+13,YY+1+win1_select,B_YELLOW | BLACK);
break;
default : continue;
}
}
}
for(n=0;n<WIN_MAX+3;n++) for(m=0;m<17;m++)
*(VS+(YY+n)*80+XX+m)=*win1++;
free(ww);
cursor_on();
}
void win_enter(char num)
{
char selected=0;
if(num == 0) {
char *arr[]={"COM1","COM2","COM3","COM4"};
selected=key_delay(num,6,6,arr);
if(selected!=0x7F) PORT=selected;
}
else if(num == 1) {
char *arr[]={"1200","2400","4800","9600","19200","38400","57600","115200"};
selected=key_delay(num,8,10,arr);
switch(selected) {
case 0 : SPEED=1200; break;
case 1 : SPEED=2400; break;
case 2 : SPEED=4800; break;
case 3 : SPEED=9600; break;
case 4 : SPEED=19200; break;
case 5 : SPEED=38400; break;
case 6 : SPEED=57600; break;
case 7 : SPEED=115200; break;
}
}
else if(num == 2) {
char *arr[]={"8 Bit","7 Bit"};
selected=key_delay(num,7,4,arr);
if(selected==0) DATA=DATABIT8;
else if(selected==1) DATA=DATABIT7;
}
else if(num == 3) {
char *arr[]={"1 Bit","2 Bit"};
selected=key_delay(num,7,4,arr);
if(selected==0) STOP=STOPBIT1;
else if(selected==1) STOP=STOPBIT2;
}
else if(num == 4) {
char *arr[]={"NONE","ODD","EVEN"};
selected=key_delay(num,6,5,arr);
if(selected==0) PARITY=PARITYNONE;
else if(selected==1) PARITY=PARITYODD;
else if(selected==2) PARITY=PARITYEVEN;
}
else if(num == 5) {
char *arr[]={"CR=CR","CR=CR+LF"};
selected=key_delay(num,10,4,arr);
if(selected==0) CR_LF = CR;
else if(selected==1) CR_LF = CRLF;
}
else if(num == 6) get_filename(0,Source_filename);
else if(num == 7) get_filename(0,HEX_filename);
else if(num == 8) get_filename(0,Compiler_filename);
}
char key_delay(char num,char x,char y,char *arr[])
{
word *win2,*ww;
char m,n,select=0;
char stop=0,value=0x7F; // 0x7F for ESC key
int ch;
ww=win2=(word *)malloc((x+2)*2*(y+1));
for(n=0;n<y+1;n++) for(m=0;m<x+2;m++)
*win2++=*(VS+(YY+1+num+n)*80+XX+15+m);
win2=ww;
double_box(XX+15,YY+1+num,XX+15+x-1,YY+1+num+y-1,B_BLUE | YELLOW,1);
for(m=0;m<y-2;m++)
sprint(XX+16,YY+2+num+m,B_BLUE | WWHITE,arr[m]);
set_att(XX+16,YY+2+num,XX+16+x-3,YY+2+num,B_WWHITE | BLACK);
while(!stop){ //STOP -> 0:Normal 1:ESC 2:ENTER
if(kbhit() ) {
ch=get_key();
switch( ch ) {
case KESC :
stop=1;
break;
case ENTER :
stop=1;
value=select;
break;
case DOWN :
if(select==y-3) break;
set_att(XX+16,YY+2+num+select,XX+16+x-3,YY+2+num+select,B_BLUE | WWHITE);
select++;
set_att(XX+16,YY+2+num+select,XX+16+x-3,YY+2+num+select,B_WWHITE | BLACK);
break;
case UP :
if(!select) break;
set_att(XX+16,YY+2+num+select,XX+16+x-3,YY+2+num+select,B_BLUE | WWHITE);
select--;
set_att(XX+16,YY+2+num+select,XX+16+x-3,YY+2+num+select,B_WWHITE | BLACK);
break;
default : continue;
}
}
}
for(n=0;n<y+1;n++) for(m=0;m<x+2;m++)
*(VS+(YY+1+num+n)*80+XX+15+m)=*win2++;
free(ww);
return value;
}
void get_filename(char mode,char *name)
{
#define TX 33
#define TY 7
word *open_box,*bb;
char m,n,cx,cy,cp=0,stop=0,retry=1;
byte temp[13];
byte far *vs=(byte far *)0xB8000000;
struct ffblk ffblk;
cx=wherex();
cy=wherey();
bb=open_box=(word *)malloc(18*2*6);
for(n=0;n<6;n++) for(m=0;m<18;m++)
*open_box++=*(VS+(TY+n)*80+TX+m);
open_box=bb;
double_box(TX,TY,TX+15,TY+4,B_BORA | WWHITE,1);
sprint(TX+1,TY+1,B_BORA | WWHITE,"Enter filename");
hs_line(TX+1,TY+1,14,B_BORA | WWHITE);
if(mode) {
strcpy(temp,name);
set_att(TX+2,TY+3,TX+13,TY+3,B_WWHITE | BLACK);
sprint(TX+2,TY+3,B_WWHITE | BLACK,name);
set_att(TX+2,TY+3,TX+2+strlen(name)-1,TY+3,B_SKY | BLACK);
}
while(retry) {
if(!mode) {
sprint(TX+2,TY+3,B_WWHITE | BLACK," ");
set_att(TX+2,TY+3,TX+13,TY+3,B_WWHITE | BLACK);
}
cursor_on();
m=0;
while(!stop) { // stop=0 :continue, 1:Escape, 2:Enter
if(mode && !cp && !m) gotoxy(TX+2+strlen(name)+1,TY+3+1);
else gotoxy(TX+3+cp,TY+4);
r.h.ah=0;
int86(0x16,&r,&r);
if(mode && !cp && r.h.al!=13) {
sprint(TX+2,TY+3,B_WWHITE | BLACK," ");
m=1;
gotoxy(TX+3,TY+4);
}
switch( r.h.al ) { // ASCII code
case 27 : // ESC
stop=1;
retry=0;
break;
case 13 : // Enter
if(mode) {
if(cp) {
temp[cp]='\0';
if(!in_capture) env_change=TRUE;
}
}
else temp[cp]='\0';
stop=2;
break;
case 8 : // Bspace
if(cp==0) break;
else {
//if(cp==12) cursor_on();
cp--;
temp[cp]=NULL;
*(vs+(TY+3)*160+(TX+2+cp)*2)=' ';
break;
}
default :
if( r.h.al==46 || (r.h.al>=48 && r.h.al<=57) ||
(r.h.al>=95 && r.h.al<=122) || (r.h.al>=64 && r.h.al<=90)
|| (r.h.al>=35 && r.h.al<=38) || r.h.al==126 || r.h.al==45 ||
r.h.al==33 || r.h.al==94 || r.h.al==40 || r.h.al==41) {
if(cp==12) break;
//if(r.h.ah>=57 || r.h.ah==15) break; // TAB ?돘 떋뱖퐈 툪턅
temp[cp]=toupper(r.h.al);
*(vs+(TY+3)*160+(TX+2+cp)*2)=toupper(r.h.al);
cp++;
//if(cp==12) cursor_off();
}
break;
}
} // end of while(!stop)
if(stop==2) {
if(!mode) stop=findfirst(temp,&ffblk,0xFF);
if(stop==-1) {
sound(500);
delay(50);
nosound();
set_att(TX+2,TY+3,TX+13,TY+3,B_RED | WWHITE);
cursor_off();
sprint(TX+2,TY+3,B_YELLOW | RED," Open error ");
getch();
cp=0;
stop=0;
}
else {
strcpy(name,temp);
retry=0;
}
} // end of if(stop==2)
} // end of while(retry)
if(!mode) cursor_off();
gotoxy(cx,cy);
for(n=0;n<6;n++) for(m=0;m<18;m++)
*(VS+(TY+n)*80+TX+m)=*open_box++;
free(bb);
}
void read_ini(void)
{
FILE *fp;
char p,q,ch;
char string[81],remain[81];
int bpss;
fp=fopen("XEXTALK.INI","rt");
if(fp==NULL) {
printf("INI file open Error !!\n");
good_bye();
}
do{
for(p=0;p<80;p++) {
ch=fgetc(fp);
if(ch=='=' || ch==0x0A || ch==EOF) break;
string[p]=toupper(ch);
if(ch==' ') p--;
}
string[p]='\0';
if(string[0]=='\0') break;
else if(string[0]==';') continue;
else {
if(ch=='=') {
for(q=0;q<80;q++) { // remainder
ch=fgetc(fp);
if(ch==0x0A || ch==EOF) break;
remain[q]=toupper(ch);
if(ch==' ') q--;
}
remain[q]='\0';
for(p=0;p<q;p++) if(remain[p]==';') break;
if(p!=q) remain[p]='\0';
}
if(!strcmp(string,"SOURCEFILE")) strcpy(Source_filename,remain);
else if(!strcmp(string,"HEXFILE")) strcpy(HEX_filename,remain);
else if(!strcmp(string,"COMPILE")) strcpy(Compiler_filename,remain);
else if(!strcmp(string,"EDITORFILE")) strcpy(Editor_filename,remain);
else if(!strcmp(string,"DOSSHELL")) strcpy(Dosshell_filename,remain);
else if(!strncmp(string,"ALT",3)) {
bpss=string[5]-'1';
if(bpss>3) continue;
strcpy(altkey[bpss],remain);
}
else if(!strcmp(string,"PORT")) {
if(!strcmp(remain,"COM2")) PORT=COM2;
else if(!strcmp(remain,"COM1")) PORT=COM1;
else if(!strcmp(remain,"COM4")) PORT=COM4;
else if(!strcmp(remain,"COM3")) PORT=COM3;
}
else if(!strcmp(string,"DATABIT")) {
if(!strcmp(remain,"8")) DATA=DATABIT8;
else if(!strcmp(remain,"7")) DATA=DATABIT7;
}
else if(!strcmp(string,"STOPBIT")) {
if(!strcmp(remain,"1")) STOP=STOPBIT1;
else if(!strcmp(remain,"2")) STOP=STOPBIT2;
}
else if(!strcmp(string,"PARITY")) {
if(!strcmp(remain,"NONE")) PARITY=PARITYNONE;
else if(!strcmp(remain,"ODD")) PARITY=PARITYODD;
else if(!strcmp(remain,"EVEN")) PARITY=PARITYEVEN;
}
else if(!strcmp(string,"SPEED")) {
remain[3]='\0'; // for integer
bpss=atoi(remain);
switch(bpss) {
case 115 : SPEED=BPS115200; break;
case 576 : SPEED=BPS57600; break;
case 384 : SPEED=BPS38400; break;
case 192 : SPEED=BPS19200; break;
case 960 : SPEED=BPS9600; break;
case 480 : SPEED=BPS4800; break;
case 240 : SPEED=BPS2400; break;
case 120 : SPEED=BPS1200; break;
}
}
else if(!strcmp(string,"CR_LF")) {
if(!strcmp(remain,"CR")) CR_LF = CR;
else if(!strcmp(remain,"CR+LF")) CR_LF = CRLF;
}
else continue;
}
} while(1);
fclose(fp);
make_status_bar();
}
void make_status_bar(void)
{
char off,temp[13];
byte far *vs=(byte far *)0xB8000000;
//set_att(0,0,79,22,B_GRAY | BLACK);
set_att(0,23,79,23,B_WWHITE | BLACK);
sprint(0,23,B_WWHITE | BLACK,"?INSERT-Edit쿓OME-Compile쿐ND-DosShell쿛GUP-Send쿛GDOWN-Capture?ALT - ECSPUX ?);
set_att(2,23,7,23,B_WWHITE | RED);
set_att(14,23,17,23,B_WWHITE | RED);
set_att(27,23,29,23,B_WWHITE | RED);
set_att(40,23,43,23,B_WWHITE | RED);
set_att(50,23,55,23,B_WWHITE | RED);
set_att(66,23,68,23,B_WWHITE | RED);
for(off=0;off<14;off+=2) *(vs+23*160+72*2+1+off)=B_WWHITE | (off);
set_att(0,24,79,24,B_LBLUE | WWHITE);
sprint(0,24,B_LBLUE | BLACK,"?);
sprint(1,24,B_LBLUE | WWHITE," Copyleft (C) XeX ?);
sprintf(temp," %12s ",Source_filename);
sprint(20,24,B_LRED | WWHITE,temp);
sprint(34,24,B_LBLUE | WWHITE,"?);
sprintf(temp," %12s ",HEX_filename);
sprint(35,24,B_LRED | WWHITE,temp);
sprint(49,24,B_LBLUE | WWHITE,"?);
sprint(50,24,B_LBLUE | YELLOW," ");
sprintf(status_bar,"%d",PORT+1);
sprintf(temp,"-%ld",SPEED);
strcat(status_bar,temp);
sprintf(temp,"-%d",DATA+5);
strcat(status_bar,temp);
switch(STOP) {
case STOPBIT1 : sprintf(temp,"-%c",'1'); break;
case STOPBIT2 : sprintf(temp,"-%c",'2'); break;
}
strcat(status_bar,temp);
switch(PARITY) {
case PARITYNONE : sprintf(temp,"-%c",'N'); break;
case PARITYODD : sprintf(temp,"-%c",'O'); break;
case PARITYEVEN : sprintf(temp,"-%c",'E'); break;
}
strcat(status_bar,temp);
sprint(51,24,B_LBLUE | YELLOW,status_bar);
if(in_capture) {
sprint(66,24,B_LRED | WWHITE,"? ?);
set_att(66,24,66,24,B_LBLUE | WWHITE);
sprint(73-strlen(cap_file)/2,24,B_LRED | WWHITE,cap_file);
}
else sprint(66,24,B_LBLUE | WWHITE,"?AJOU UNIV. ?);
set_att(79,24,79,24,B_LBLUE | BLACK);
gotoxy(1,1);
}
void scroll_up(void)
{
char m,n;
for(m=0;m<22;m++) for(n=0;n<80;n++)
*(VS+m*80+n)=*(VS+(m+1)*80+n);
for(m=0;m<80;m++) *(VS+22*80+m)=0x0720;
//gotoxy(wherex(),wherey()-1);
}
void toggle_att(byte top_x, byte top_y, byte bottom_x, byte bottom_y, char bb)
{
byte far *vseg =(byte far *)0xb8000000;
byte i,j,x;
char cc;
vseg += top_x*2 + top_y*160 + 1;
if(bb==1) cc=16; // bb => blank
else cc=-16;
for( j=0; j <= (bottom_y-top_y); j++ ){
for( i=0; i <= (bottom_x-top_x); i++){
x = *vseg;
*vseg = x + cc;
vseg+=2;
}
vseg-=(bottom_x-top_x+1)*2;
vseg+=160;
}
}
void alt_macro_exec(char *macro)
{
char m=0,n=0;
char command[10]="";
FILE *fp;
byte data[70];
while(macro[m++]!=NULL) {
switch(macro[m]) {
case '|' :
command[n++]=0X0D;
command[n]='\0';
send_string(command);
delay(300);
n=0;
break;
case '$' :
delay(100);
break;
case '#' :
if((fp=fopen(HEX_filename,"rt"))==NULL) {
// File open box
}
else {
while(fscanf(fp,"%s\n",data)!=-1) send_string(data);
send_character(CR);
fclose(fp);
delay(500);
flush_buffer();
}
break;
default :
command[n++]=macro[m];
continue;
}
}
}
static void interrupt isr_09(void)
{
unsigned char key;
__emit__(0xfa);
key=inportb(0x60);
if(key==184 && !in_popup ) {
if(!in_capture) {
if(!hot_key) to_popup=TRUE;
else {
hot_key=FALSE;
to_popup=FALSE;
}
}
else {
if(hot_key>1) {
hot_key--;
to_popup=FALSE;
}
else to_popup=TRUE;
}
}
else to_popup=FALSE;
(*old_isr_09)();
__emit__(0xfb);
}
void save_ini(void)
{
#define XP 30
#define YP 7
word *save,*ss;
byte m,n;
ss=save=(word *)malloc(4*23*2);
for(n=0;n<4;n++) for(m=0;m<23;m++)
*save++=*(VS+(YP+n)*80+XP+m);
save=ss;
sound(700);
delay(50);
nosound();
double_box(XP,YP,XP+20,YP+2,B_BORA | WWHITE,1);
sprint(XP+1,YP+1,B_BORA | WWHITE,"Save Changes? (Y/n)");
set_att(XP+16,YP+1,XP+16,YP+1,B_BORA | BLACK);
m=1;
while(m) {
r.h.ah=0;
int86(0x16,&r,&r);
switch(r.h.ah) {
case 21 : // yes
case 28 : save_env();
case 49 : m=0; break;
default : continue;
}
}
for(n=0;n<4;n++) for(m=0;m<23;m++)
*(VS+(YP+n)*80+XP+m)=*save++;
free(ss);
}
void save_env(void)
{
int handle;
struct ffblk file;
char string[81],name[20],data[20],p,q,m,ch;
int cp=0,tp=0,rp;
byte *mem;
findfirst("XEXTALK.INI",&file,0xFF);
filesize=file.ff_fsize;
handle=open("XEXTALK.INI",O_RDWR | O_BINARY);
mem=(byte *)malloc(filesize+100);
read(handle,mem,filesize);
close(handle);
//rename("XEXTALK.INI","XEXTALK.BAK");
while(1) {
if(tp>=filesize) break;
for(p=0,cp=tp;cp<tp+80;cp++,p++) {
ch=*(mem+cp);
if(ch==0x0A || cp==filesize) break;
string[p]=toupper(ch);
}
string[p]='\0';
tp+=strlen(string)+1;
if(string[0]=='\0') break;
else if(string[0]==';') continue;
else {
for(m=0;;m++) {
if(string[m]=='=') break;
name[m]=string[m];
}
name[m]='\0';
cp=strlen(string)-m;
rp=tp-cp+1;
for(m=0;;m++) {
if(string[m]==' ') break;
name[m]=string[m];
}
name[m]='\0';
if(!strcmp(name,"SOURCEFILE")) {
sprintf(data,"%-12s",Source_filename);
mem_cpy(mem,rp,data,strlen(data));
}
else if(!strcmp(name,"HEXFILE")) {
sprintf(data,"%-12s",HEX_filename);
mem_cpy(mem,rp,data,strlen(data));
}
else if(!strcmp(name,"COMPILE")) {
sprintf(data,"%-12s",Compiler_filename);
mem_cpy(mem,rp,data,strlen(data));
}
else if(!strcmp(name,"EDITORFILE")) continue;
else if(!strcmp(name,"DOSSHELL")) continue;
else if(!strncmp(name,"ALT",3)) continue;
else if(!strcmp(name,"PORT")) {
switch(PORT) {
case COM2 : mem_cpy(mem,rp,"COM2",4); break;
case COM1 : mem_cpy(mem,rp,"COM1",4); break;
case COM3 : mem_cpy(mem,rp,"COM3",4); break;
case COM4 : mem_cpy(mem,rp,"COM4",4); break;
}
}
else if(!strcmp(name,"DATABIT")) {
if(DATA==DATABIT8) *(mem+rp)='8';
else if(DATA==DATABIT7) *(mem+rp)='7';
}
else if(!strcmp(name,"STOPBIT")) {
if(STOP==STOPBIT1) *(mem+rp)='1';
else if(STOP==STOPBIT2) *(mem+rp)='2';
}
else if(!strcmp(name,"PARITY")) {
if(PARITY==PARITYNONE) mem_cpy(mem,rp,"NONE",4);
else if(PARITY==PARITYODD) mem_cpy(mem,rp,"ODD ",4);
else if(PARITY==PARITYEVEN) mem_cpy(mem,rp,"EVEN",4);
}
else if(!strcmp(name,"CR_LF")) {
if(CR_LF==CRLF) mem_cpy(mem,rp,"CR+LF",5);
else if(CR_LF==CR) mem_cpy(mem,rp,"CR ",5);
}
else if(!strcmp(name,"SPEED")) {
switch(SPEED) {
case BPS115200: mem_cpy(mem,rp,"115200",6); break;
case BPS57600 : mem_cpy(mem,rp,"57600 ",6); break;
case BPS38400 : mem_cpy(mem,rp,"38400 ",6); break;
case BPS19200 : mem_cpy(mem,rp,"19200 ",6); break;
case BPS9600 : mem_cpy(mem,rp,"9600 ",6); break;
case BPS4800 : mem_cpy(mem,rp,"4800 ",6); break;
case BPS2400 : mem_cpy(mem,rp,"2400 ",6); break;
case BPS1200 : mem_cpy(mem,rp,"1200 ",6); break;
}
}
}
}
handle=open("XEXTALK.INI",O_WRONLY | O_BINARY );
write(handle,mem,filesize);
free(mem);
close(handle);
}
void mem_cpy(byte *mm,int off,byte *str,byte len)
{
byte m,n;
int cp;
for(n=0;n<len;n++) if(*(mm+off+n)==';' || *(mm+off+n)==0x0D) {
for(cp=filesize;cp>=off+n;cp--) *(mm+cp+len-n)=*(mm+cp);
filesize+=len-n;
break;
}
for(m=0;m<len;m++) *(mm+off+m)=*(str+m);
}