Deciphering some BASIC (discovering CommunITel Modem commands)

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
User avatar
danielj
Posts: 6693
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Deciphering some BASIC (discovering CommunITel Modem commands)

Post by danielj » Mon May 21, 2018 6:30 pm

I'm trying to divine the operation of the CommunITel modem, the key to some of its behaviours seem to be locked up here in this BASIC program - can anyone help with what some of the lines are doing? Specifically, lines 260 (seems to be setting up various things for what? the USR&FFF4 call?), line 310, and 340-390. Also, am I right about 220-250? I'm really not sure why you'd stick characters in the serial input buffer?

Code: Select all

  130 DEFPROCcallALT
  140 *FX21,1 --- Flush Serial input Buffer 
  150 *FX7,4 --- Receive 1200baud
  160 *FX8,4 --- Send 1200 baud
  170 *FX3,7 --- output to rs423
  180 VDU&8D 
  190 time%=TIME:REPEAT:UNTIL TIME=time%+5 --- Pause
  200 *FX21,1
  210 VDU&41,&4C,&54,&0D - send "ALT<CR>"
  220 *FX138,1,13 <CR> in serial input buffer
  230 *FX138,1,78 N in serial input buffer
  240 *FX138,1,80 P in serial input buffer
  250 *FX138,1,13 <CR> in serial input buffer
  260 I%=0:A%=&80:X%=254:Y%=255 - What's going on here?
  270 *FX3 - is this the same as *FX3,0?
  280 *FX2,1 - Read from RS423 
  290 REPEAT
  300 I%=I%+1
  310 UNTIL ((USR(&FFF4) AND &FF00) DIV&100) OR I%>500 - What's going on here?
  320 IF I%>500 THEN PROCdumb_modem ELSE 340 -- I assume that after 500 iterations of no response then 
  330 IF modem=2 THEN ENDPROC ELSE GOTO 140 - Retest...
  340 time%=TIME:REPEAT:UNTIL TIME=time%+50:I%=0::REPEAT
  350 c%?I%=INKEY(0)AND&7F:I%=I%+1 - is this reading from the modem?
  360 UNTIL ((USR(&FFF4) AND &FF00) DIV &100)=0 
  370 c%?I%=&0D
  380 end%=c%+I%-3
  390 IF $end%<>CHR$(10)+"++" THEN PROCwrong_modem
  400 *FX2,0 - input from keyboard, disable RS423
  410 *FX3,4 - output to screen only
  420 ENDPROC

User avatar
hoglet
Posts: 7697
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Deciphering some BASIC

Post by hoglet » Mon May 21, 2018 6:54 pm

Yes, A%, X% and Y% are being setup to do the OSBYTE call in the UNTIL statement.

See OSBYTE &80:
http://stardot.org.uk/mirrors/www.bbcdo ... f#page=151

X%=254 is reading the status of the RS423 input buffer.

It returns the number of characters in the buffer in X%, which is returned from the USR in bits 15...8.

User avatar
danielj
Posts: 6693
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: Deciphering some BASIC

Post by danielj » Mon May 21, 2018 7:21 pm

Thanks Dave - getting there then. I'm still confused as to why on earth would you be putting characters into the serial input buffer.

I think I need a copy of the dacom 2123 autoanswer modem manual - but I can't find one for toffee...

d.

User avatar
jgharston
Posts: 3296
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Deciphering some BASIC

Post by jgharston » Mon May 21, 2018 7:56 pm

Code: Select all

130 DEFPROCcallALT
  140 *FX21,1   --- Flush Serial input Buffer
  150 *FX7,4    --- Receive 1200baud
  160 *FX8,4    --- Send 1200 baud
  170 *FX3,7    --- output to rs423
  180 VDU &8D
  190 time%=TIME:REPEAT:UNTIL TIME=time%+5 --- Pause 0.05s
  200 *FX21,1   --- Flush Serial input buffer again
  210 VDU &41,&4C,&54,&0D - send "ALT<CR>"
  220 *FX138,1,13 -- <CR> in serial input buffer
  230 *FX138,1,78 -- N in serial input buffer
  240 *FX138,1,80 -- P in serial input buffer
  250 *FX138,1,13 -- <CR> in serial input buffer
  260 I%=0:A%=&80:X%=254:Y%=255 - What's going on here?
  270 *FX3       -- output to VDU
  280 *FX2,1     -- input from serial
  290 REPEAT
  300 I%=I%+1
  310 UNTIL ((USR(&FFF4) AND &FF00) DIV&100) OR I%>500 - What's going on here?
  would have been simpler to do:
      UNTIL ADVAL(-2) OR I%>500  --  loop 500 times or until serin not empty
      lines 220-250 ensure serin is not empty, it will contain <CR>NP<CR>
  
  320 IF I%>500 THEN PROCdumb_modem ELSE 340 -- I assume that after 500 iterations of no response then
  330 IF modem=2 THEN ENDPROC ELSE GOTO 140  -- Retest...
  340 time%=TIME:REPEAT:UNTIL TIME=time%+50  -- Pause 0.5s
      :I%=0:REPEAT
  350 c%?I%=INKEY(0)AND&7F:I%=I%+1 -- read bytes from serin, dropping bit 7
  360 UNTIL ((USR(&FFF4) AND &FF00) DIV &100)=0
  again....
      UNTIL ADVAL(-2)=0  --  loop until serin is empty (all bytes read)

  370 c%?I%=&0D
  380 end%=c%+I%-3
  390 IF $end%<>CHR$(10)+"++" THEN PROCwrong_modem
  400 *FX2,0 - input from keyboard, disable RS423
  410 *FX3,4 - output to screen only
  420 ENDPROC
So, it outputs ALT<CR>, puts <CR>NP<CR> into the input buffer, pauses a bit to allow anything to respond to the ALT<CR> command, then reads everything that is in the input buffer - which will be <CR>NP<CR> plus whatever response any modem will have returned. If the last three characters are not CHR$10+"++" then PROCwrong_modem is called.

I can only think it puts <CR>NP<CR> into the serial input buffer to ensure there is something to read back, and something that does not end in "++" so the PROCwrong_modem is called if there is no response.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
hoglet
Posts: 7697
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Deciphering some BASIC

Post by hoglet » Mon May 21, 2018 8:02 pm

This does seem a little strange.... especially stuffing characters into the RS423 input buffer, then waiting for it to empty.

I wonder if there is some other piece of software running on the Beeb that's interacting with the RS423 interface.

Could this BASIC program be trying to fool the other piece of software into thinking the model has certain capabilities?

Can you give a bit more context as to where this BASIC program came from?

User avatar
danielj
Posts: 6693
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: Deciphering some BASIC

Post by danielj » Mon May 21, 2018 8:11 pm

Sure - it's the modem test code from CommunITel - (in the Pcoder file) - CommunITel doesn't seem to speak hayes, it speaks Tandata, so I'm trying to work out how the modem is meant to respond in order to get it to work with communitel (ideally not having to hack the communitel software at all) - there is no online documentation for this standard at all so far as I can tell, so it might be a case of reversing it all from communitel :( . If anyone has a copy of the manual for one of these tandata or dacom autoanswer modems, that would be really handy.

Complete listing below:

Code: Select all

   10 PROCwindowclean:VDU31,4,22:PRINTSPC(10);"Testing Modem           ";
   20 HIMEM=&6000
   30 REM*FX229,1
   40 Q%=PAGE
   50 DIM c% 80
   60 DIM command 80
   70 PROCcallALT:PROCmessage
   80 $c%="RUN "+$V%+"."+"Pcode"
   90 X%=c%:Y%=c%DIV256
  100 CALL &FFF7
  110 END
  120 :
  130 DEFPROCcallALT
  140 *FX21,1 --- Flush Serial input Buffer 
  150 *FX7,4 --- Receive 1200baud
  160 *FX8,4 --- Send 1200 baud
  170 *FX3,7 --- output to rs423
  180 VDU&8D 
  190 time%=TIME:REPEAT:UNTIL TIME=time%+5 --- Pause
  200 *FX21,1
  210 VDU&41,&4C,&54,&0D - send "ALT<CR>"
  220 *FX138,1,13 <CR> in serial input buffer
  230 *FX138,1,78 N in serial input buffer
  240 *FX138,1,80 P in serial input buffer
  250 *FX138,1,13 <CR> in serial input buffer
  260 I%=0:A%=&80:X%=254:Y%=255 - What's going on here?
  270 *FX3 - is this the same as *FX3,0?
  280 *FX2,1 - Read from RS423 
  290 REPEAT
  300 I%=I%+1
  310 UNTIL ((USR(&FFF4) AND &FF00) DIV&100) OR I%>500 - What's going on here?
  320 IF I%>500 THEN PROCdumb_modem ELSE 340 -- I assume that after 500 iterations of no response then 
  330 IF modem=2 THEN ENDPROC ELSE GOTO 140 - Retest...
  340 time%=TIME:REPEAT:UNTIL TIME=time%+50:I%=0::REPEAT
  350 c%?I%=INKEY(0)AND&7F:I%=I%+1 - is this reading from the modem?
  360 UNTIL ((USR(&FFF4) AND &FF00) DIV &100)=0 
  370 c%?I%=&0D
  380 end%=c%+I%-3
  390 IF $end%<>CHR$(10)+"++" THEN PROCwrong_modem
  400 *FX2,0 - input from keyboard, disable RS423
  410 *FX3,4 - output to screen only
  420 ENDPROC
  430 :
  440 DEFPROCdumb_modem
  450 *FX2,0
  460 *FX3,4
  470 PROCwindowclean:VDU31,4,22:PRINT"     No response from modem."
  480 VDU31,0,16
  490 PRINT"  ÉPress:"
  500 PRINT"  Ü1. to retest CommunITel/DTI modem"
  510 PRINT"  Ü2. if you are using a dumb modem"
  520 REPEAT:VDU7:key$=GET$:UNTIL key$="1" OR key$="2"
  530 IF key$="2" THEN PROCsetup_dumb
  540 modem=VAL(key$)
  550 ENDPROC
  560 :
  570 DEFPROCwrong_modem
  580 *FX2
  590 *FX3,4
  600 PROCwindowclean:VDU7,31,0,17:PRINT'"ÅThis is NOT aÜCommunITel/DTIÅmodem."
  610 PRINT"  ÜIt probablyÅWONTÜwork! ...Good Luck"
  620 K%=INKEY(500)
  630 ENDPROC
  640 :
  650 DEFPROCsetup_dumb
  660 *KEY0"|FA90,0|M"
  670 PROCwindowclean:VDU31,9,17:PRINT"To use with dumb modem"'"ÉPressàáCTRL/f0âÉwhen Terminal is ready";
  680 K%=INKEY(500)
  690 *FX2,0
  700 *FX3,0
  710 ENDPROC
  720 :
  730 DEFPROCoscli(string$)
  740 $command=string$
  750 X%=command:Y%=command DIV 256
  760 CALL &FFF7
  770 ENDPROC
  780 :
  790 DEFPROCwindowclean
  800 VDU28,0,20,39,15,12,26
  810 ENDPROC
  820 :
  830 DEFPROCmessage
  840 PROCloading
  850 ENDPROC
  860 :
  870 DEFPROCloading
  880 VDU31,8,22,131:PRINT"Program now loading...";
  890 ENDPROC

User avatar
danielj
Posts: 6693
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: Deciphering some BASIC

Post by danielj » Wed May 23, 2018 5:27 pm

So this is a bit more helpful! flaxcottage has helpfully scanned some documentation that confirms that the modem is speaking 1200/1200 to the beeb no matter what rate it's connected at. And I've had a rummage in more of the programs on the commmunitel disk:
It looks like you have a number of strings that determine baud;
V23T
V21T
V23T
V21C
ALT<CR>NP<CR>[baud]<CR> seems to set it up initially, and
[baud] [number] [&0D] seems to be the dial command.
[&01][&01][&01][&01] seems to be hang up.

I'm missing the "pickup" command, and also the messages it's expecting the modem to send, although I'm suspecting
RINGING and CONNECTED form part of it all:
commands.png

Code: Select all

   10 REM DaCom RS423 termainal 00.41.20.10.85 (C) Chris Johnson
   20 MODE3:IFHIMEM<&8000 THENHIMEM=&3000
   30 PROCinit:ONERRORPROCerror
   40 REPEAT:A%=FNkey:IFA%=0 ELSEIFA%<&80 PROCtx_byte(A%) ELSEPROCfn(A%-&7F)
   50 IFADVAL(-2) VDUFNrx_byte
   60 UNTILFALSE
   70 DEFPROCerror:PRINT:IFERR<>17 ANDERR<45 VDU7,3:REPORT:PRINT" at line ";ERL':ENDPROC
   80 IFERR>44 REPORT:ENDPROC
   90 IFfn%=FALSE OSCLI"FX220 27":CLEAR:MODE7:CHAIN"$.VSMENU"
  100 *FX220
  110 fn%=FALSE:ENDPROC
  120 DEFPROCinit:DIMcode% &FF,wkspc% &FF:fn%=FALSE:osbyte%=&FFF4:PROCasemble:PRINT'"CommunITel DTI modem utility"'"Scrolling text terminal V2.0"'"SHIFT f0 for help"'
  130 *FX220
  140 *FX15
  150 *FX2,2
  160 *FX7,4
  170 *FX8,4
  180 baud$="V23T":dial$="0000000000":PROCtx_string(CHR$13+"ALT"+CHR$13+"NP"+CHR$13+baud$+CHR$13):TIME=0:REPEATUNTILTIME>50:*FX15
  190 ENDPROC
  200 DEFPROCfn(F%) LOCALi$:fn%=TRUE:*FX220 27
  210 ONF%GOSUB240,280,300,320,330,350,360,380 ELSEVDU7
  220 fn%=FALSE:*FX220
  230 ENDPROC
  240 PRINT'"Function keys"'"============="''"CTRL @ To return to menu"'"ESCAPE to abort a function"'
  250 PRINT"Obtained by SHIFT + fn key no. :-"
  260 PRINT"0 : Help"'"1 : OSCLI Command"'"2 : Printer on/off"'"3 : Change screen mode"'"4 : Dial out"'"5 : Disconnect"'"6 : Delete to start of line"'"7 : Change baud rates"'
  270 RETURN
  280 INPUTLINE'"*"i$:OSCLIi$
  290 PRINT:RETURN
  300 LOCALA%:A%=&75:IFUSRosbyte%AND&100 VDU3:PRINT''"Printer off"' ELSEPRINT''"Printer on"':VDU2
  310 RETURN
  320 INPUT''"New screen mode ? "i$:VDU22,VALi$,10:RETURN
  330 PRINT''"No. to dial (CR = ";dial$;")":INPUTi$:IFi$>"" dial$=i$
  340 PROCtx_string(baud$+" "+dial$+CHR$&D):RETURN
  350 PROCtx_string(STRING$(4,CHR$1)):RETURN
  360 IFPOS>2 PROCtx_string(STRING$(POS-2,CHR$8))
  370 RETURN
  380 PRINT'"Please enter number of desired rate:"'
  390 PRINT"1. 1200/75 Originate"'"2. 300/300 Originate"'"3. 1200/75 Answer"'"4. 300/300 Answer"'
  400 REPEAT G%=GET-48:UNTILG%>0ANDG%<5
  410 baud$=MID$("V23TV21TV23TV21C",G%*4-3,4)
  420 PRINT"Option ";G%;" selected."':RETURN
  430 :
  440 DEFFNkey =USRkey%AND&FF
  450 :
  460 DEFPROCtx_string(i$) LOCALP%
  470 $wkspc%=i$:FORP%=0TOLENi$-1:PROCtx_byte(wkspc%?P%):NEXT
  480 ENDPROC
  490 :
  500 DEFPROCtx_byte(A%) CALLtxb%:ENDPROC
  510 :
  520 DEFFNrx_byte =USRrxb%AND&FF
  530 :
  540 DEFPROCasemble LOCALP%,Z%
  550 FORZ%=0TO2STEP2:P%=code%
  560 [OPTZ%
  570 .rxb% LDA #&91
  580 .nothing LDX #1:JSR osbyte%:BCC gotone:BIT &FF:BPL nothing
  590 .gotone TYA:JSR ctrl:RTS
  600 .txb% PHA:LDA #&80
  610 .noroom LDX #&FD:JSR osbyte%:CPX #0:BNE insert:BIT &FF:BPL noroom
  620 .insert PLA:TAY:LDA #&8A:LDX #2:JMP osbyte%
  630 .key% LDA #&81:LDX #0:LDY #0:JSR osbyte%:BCS invalid:TXA:JSR ctrl:CMP #&7F:BNE notdel:LDA #8
  640 .notdel RTS
  650 .ctrl CMP #32:BCS notctrl:CMP #7:BCC invalid:CMP #14:BCS invalid
  660 .notctrl RTS
  670 .invalid LDA #0:RTS
  680 ]
  690 NEXT:ENDPROC

User avatar
1024MAK
Posts: 8110
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Deciphering some BASIC

Post by 1024MAK » Wed May 23, 2018 6:54 pm

danielj wrote:So this is a bit more helpful! flaxcottage has helpfully scanned some documentation that confirms that the modem is speaking 1200/1200 to the beeb no matter what rate it's connected at.
Do you mean that the DTE<->DCE speed is fixed, while the line (DCE<->DCE, MODEM to MODEM) speed is controlled by the MODEM and set via commands from the DTE?

That means that the MODEM used is considerably more complex than a simple 'dumb' FSK type.

Some of the more complex MODEMs actually send bursts of data between themselves and the DTE. So the hardware flow control has to work correctly for these. End to end flow control being via embedded control codes in the data transmission (if used). E.g. XON, XOFF control.

Mark

User avatar
danielj
Posts: 6693
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: Deciphering some BASIC (discovering CommunITel Modem commands)

Post by danielj » Wed May 23, 2018 8:06 pm

Yup, that's what it looks like - and if you look at the code posted above, you'll see that it doesn't ever change the tx/rx speed to the beeb. Just sets both to 1200 and leaves it at that.

The aim here is simply to get the wifi modem giving the responses and responding to the commands that communitel expects, for detection, dialing out, and picking up. The first two I feel fairly confident I can do, the last one is where I'm not sure yet...

d.

User avatar
1024MAK
Posts: 8110
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: Deciphering some BASIC (discovering CommunITel Modem commands)

Post by 1024MAK » Wed May 23, 2018 9:03 pm

I don't remember the term "picking-up" from when I worked with MODEMs years ago. I do remember "off-hook" , "answer mode" and "auto-answer"...

Mark

User avatar
danielj
Posts: 6693
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: Deciphering some BASIC (discovering CommunITel Modem commands)

Post by danielj » Wed May 23, 2018 9:33 pm

I might be colloquialising :D

Post Reply