0% found this document useful (0 votes)
25 views5 pages

MODEM

The document discusses using IOLib.LIB to communicate with serial ports and handle modem functions. It provides sample code to initialize a serial port, send and receive data, and handle escape sequences for terminal control codes like cursor positioning and text colors.

Uploaded by

jnfgames1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views5 pages

MODEM

The document discusses using IOLib.LIB to communicate with serial ports and handle modem functions. It provides sample code to initialize a serial port, send and receive data, and handle escape sequences for terminal control codes like cursor positioning and text colors.

Uploaded by

jnfgames1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

/*

MODEM.PRG is a sample use of the IOLib.LIB

Standard ports list and their IRQs


Com port HEX DECIMAL IRQ
COM1: 3F8h 1016 4
COM2: 2F8h 760 3
COM3: 3E8h 1000 4 or 7
COM4: 2E8h 744 3 or 5 or 7
COM 3 and 4 may use another IRQ. Any IRQ from 2 to 7 may be used.
IRQ 8 to 15 is also available but requiers an AT286 or higher
IRQ15 may not be available to many 286 systems. SOME IRQs have
other uses like your FLOPPY AND HARD drives see your ROMBIOS hand book.
*/
#include "IOLib.ch"

PUBLIC nkey,cChr,IRQ
PUBLIC inbuf,fgcl:=10,bgcl:=0
*EXIT PROCEDURE cleanup
SETCANCEL(.f.)
SET CONFIRM ON
CLS

EscSpool:=""
GotEsc:=.f.
IRQ:=3
SET CURSOR ON
*4K BUFFER
*inbuf:=space(4000)

IF !INIT_PORT(COM2,115200/115200,EIGHT_DATA_BITS,NO_PARITY,;
ONE_STOP_BIT,IRQ,8192)
? "No init! Wrong data"
QUIT
ENDIF
IF ISWORKING()
setcolor("10/")
? "Interrupt is working!"
ELSE
? "Nothing yet..."
ENDIF
? ""
minit="ATX3E1&C1M1W1"+CHR(13)
OUTCHR(@minit)
outchr("ATDT021333314644"+CHR(13))

inkey(2)
//minit:=REPLICATE("test ",30)
//OUTCHR(@minit)

FOR tmp = 1 to 20
@ ROW(),0 say OUTBUFSIZE()
IF OUTBUFSIZE()=0
EXIT
ENDIF
INKEY(.1)
NEXT
nkey:=0
setcolor(TRIM(STR(fgcl))+"/"+TRIM(STR(bgcl)))
mr=ROW()
mc=COL()
SET CURSOR OFF
mline:=ISONLINE()
@ MAXROW(),0 SAY " "+IF(ISONLINE()=.t.,"OnLine ","OffLine")+" � "+IOLIB_VER()+" �
DTR "+IF(SETDTR()=.t.,"on ","off")+"Alt-H=Help " COLOR "W+/R"
@ mr,mc SAY ""
SET CURSOR ON

do while !nkey=301 && Alt-X


nkey:=INKEY()
IF INKEY()=-9
OUTC(0)
END IF
IF nKey=18 &&PgUp
XMODEM_TX()
ELSEIF nKey=3 &&PgDn
XMODEM_RX()
ELSEIF nkey>0 .and. nkey<256
OUTC(nkey)
ELSEIF nKey=291 && Alt-H
mscr:=SAVESCREEN(5,5,20,65)
@ 5,5,20,65 box "�ͻ���Ⱥ " color "w+/b"
@ 5,25 say "[ ClipModem Help ]" color "w+/b"
@ 6,7 say "KEY | Command Snytax" color "w+/b"
@ 7,7 say "Alt-X | Exit program" color "w+/b"
@ 8,7 say "Alt-D | Dial directory?" color "w+/b"
@ 9,7 say "PgDn | Receive file" color "w+/b"
@ 10,7 say "PgUp | Send file" color "w+/b"
@ 12,7 say "IN-Buffer MAX size= "+LTRIM(STR(SIZEO()-1)) color "w+/b"
@ 14,8 say "This is a sample only, don't do much.... " color "w+/b"
@ 19,7 SAY "Press Any Key to return to terminal......" color "15*/9"
set cursor off
do while INKEY()=0
@ 6,35 say "Current status is "+IF(ISONLINE()," ONLINE","OFFLINE") color "w+/b"
@ 7,35 say " DTR = "+IF(SETDTR(),"ON","OFF") color "w+/b"
@ 8,35 say " RTS = "+IF(SETRTS(),"ON","OFF") color "w+/b"
@ 9,35 say " DSR = "+IF(DSR(),"ON","OFF") color "w+/b"
@ 10,35 say " CTS = "+IF(CTS(),"ON","OFF") color "w+/b"
@ 11,35 say "BUFFER = "+LTRIM(STR(INBUFSIZE()))+" " color "w+/b"
@ 12,35 say "BUFFER = "+LTRIM(STR(OUTBUFSIZE()))+" " color "w+/b"
@ MAXROW(),0 SAY " "+IF(ISONLINE()=.t.,"OnLine ","OffLine")+" � "+IOLIB_VER()+" �
DTR "+IF(SETDTR()=.t.,"on ","off")+"Alt-H=Help " COLOR "W+/R"
ENDDO
set cursor on
RESTSCREEN(5,5,20,65,mscr)
SETDTR(.F.)
ENDIF

cChr:=INCHR(1)
IF !cChr=NIL
IF ASC(cChr)=10 .and. ROW()>MAXROW()-2
SCROLL(0,0,MAXROW()-1,79,1)
ELSEIF ASC(cChr)=27
EscSpool:=chr(27)
gotEsc:=.T.
ELSEIF gotEsc
EscSpool:=EscSpool+cChr
IF ISALPHA(cChr)
ANSI(EscSpool,cChr)
gotEsc:=.F.
ELSEIF LEN(EscSpool)>15 .or. !SUBSTR(EscSpool,2,1)=="["
gotEsc:=.f.
?? EscSpool
ENDIF
ELSE
IF COL()=MAXCOL() .AND. ROW()=MAXROW()-1
SCROLL(0,0,MAXROW()-1,79,1)
@ ROW(),0 SAY ""
ENDIF
?? cChr

ENDIF
ENDIF
IF ROW()=MAXROW() .OR. !mline=ISONLINE()
mr=ROW()
mc=COL()
SET CURSOR OFF
@ MAXROW(),0 SAY " "+IF(ISONLINE()=.t.,"OnLine ","OffLine")+" � "+IOLIB_VER()+"
� DTR "+IF(SETDTR()=.t.,"on ","off")+"Alt-H=Help " COLOR "W+/R"
IF mr=MAXROW()
mr=MAXROW()-1
ENDIF
@ mr,mc SAY ""

SET CURSOR ON
mline:=ISONLINE()
ENDIF

enddo
setdtr(.f.)
QUIT

*******************************************
* ANSI() may have bugs
*
*
*

FUNCTION ANSI(cString,cterm)
LOCAL x,cSpec,nRow:=ROW(),nCol:=COL(),cfg:=NIL,cbg:=NIL
LOCAL nfg:=NIL,nbg:=NIL,cbuf:=""
LOCAL cClrs:={},lBright:=.f.
*@ 24,70 SAY cString COLOR "w+/r"
cString:=SUBSTR(cString,3)

DO CASE
CASE cString=="2J"
@ 0,0 CLEAR TO MAXROW()-1,MAXCOL()
nRow:=0
nCol:=0
CASE cString=="0m"
fgcl:=7
bgcl:=0
setcolor("7/0")

CASE cterm=="p"
*^&*$(^ trying to remap your keyboard!
CASE cString=="A"
nRow:=nRow-1
CASE cString=="B"
nRow:=nRow+1
CASE cString=="C"
nCol:=nCol+1
CASE cString=="D"
nCol:=nCol-1
CASE cString=="H" .or. cString=="f"
nRow:=0
nCol:=0
CASE cString=="K"
@ nRow,nCol CLEAR TO nRow,MAXCOL()
CASE cterm=="A"
nRow:=nRow-VAL(cString)
CASE cterm=="B"
nRow:=nRow+VAL(cString)
CASE cterm=="C"
nCol:=nCol+VAL(cString)
CASE cterm=="D"
nCol:=nCol-VAL(cString)
CASE cterm=="H" .OR. cterm=="f"
nRow:=VAL(cString)
cString:=SUBSTR(cString,AT(";",cString)+1 )
nCol:=VAL(cString)
CASE cterm=="m" && change color
cbuf:=SUBSTR(cString,1,LEN(cString)-1)
x=1
DO WHILE LEN(cbuf)>0
AADD(cClrs,VAL(cBuf))
IF AT(";",cbuf)=0
EXIT
ENDIF
cBuf:=SUBSTR(cBuf,AT(";",cbuf)+1)
ENDDO
bright:=IF(fgcl>7,.T.,.F.)
blink:=IF(bgcl>7,.T.,.F.)
FOR x=1 to LEN(cClrs)
DO CASE
CASE cClrs[x]==NIL
CASE cClrs[x]==0
bright:=.f.
blink:=.f.
bgcl:=0
CASE cClrs[x]==1
bright:=.t.
CASE cClrs[x]==5
blink:=.t.
CASE cClrs[x]==7
nFg:=NIL
nbg:=NIL
fgcl:=0
bgcl:=7
bright:=.f.
blink:=.f.
EXIT
CASE cClrs[x]>39
nBg:=ASCAN({40,44,42,46,41,45,43,47}, (cClrs[x]))-1
CASE cClrs[x]>29
nFg:=ASCAN({30,34,32,36,31,35,33,37} ,cClrs[x])-1
ENDCASE
NEXT
fgcl:=IF(nfg=NIL,fgcl,nfg)
fgcl:=IF(bright .and. fgcl<8 ,fgcl+8,fgcl)
bgcl:=IF(nbg=NIL,bgcl,nbg)
bgcl:=IF(blink .and. bgcl<8 ,bgcl+8,bgcl)

setcolor(TRIM(STR(fgcl))+IF(blink,"*/","/")+TRIM(STR(bgcl)))
OTHERWISE
* @ 24,10 say " "+ cString+" "
ENDCASE

nRow:=IF(nRow=MAXROW(),MAXROW()-1,nRow)
nRow:=IF(nRow<0,0,nRow)
nCol:=IF(nCol>MAXCOL(),MAXCOL(),nCol)
nCol:=IF(nCol<0,0,nCol)
@ nRow,nCol SAY ""

RETURN NIL

EXIT PROCEDURE cleanup()


@ MAXROW(),0 say ""
IF ISWORKING()
? "Interrupt is working!"
ELSE
? "It did not work!"
ENDIF
UNINT_PORT()
? "Port Uninitialized............."
RETURN

You might also like