//*********************************************************
// ANWENDUNG Alcatel Austria AG
//
// Program for converting SMDR-RECORD of the
// ALCATEL 4400 (DHS 3)
// to a CALL-RECORD of the MEETERING of a
// ALCATEL 5200 BCN/BCS (AMANDA).
//
// The portinterface hardware must be changed to
// V24 level.
// Use the pin 2 RXD
//	   pin 3 TXD
//	   pin 5 RTS for hardware handshake to stop
//
//*********************************************************
// By  H”rhager Josef VTE   11/95
//*********************************************************
// Revision:
// V1.0 11/95
//	EA-GENERALI
// V3.0 15/04/96
//	for common use with incoming and outgoing
// V4.0 4.11.96
//      Insert of compiler variable "private"
//      If define private and smdr-reco contains a pincodenumber
//      the converter suppress the called number in the output-reco
//      The called number will be suppresed from the position
//      defined with the compiler variable "begin_suppress".
//      The called number will be replaced with the string
//      "str_suppress". This string "str_suppress" must have the
//      correct lenght, because of the parameter of the variable
//      "begin_suppress".
//*********************************************************
//#########################################################
// version V4.0
//#define private
#define begin_suppress   5
#define str_suppress    "................"
//#########################################################
//**********************************************************
//
//*********************************************************
// Strings
//
// s6,s7,s8,s9
// buffer 0
//
//*********************************************************
//
#define mess_startup1   " Alcatel 4400 (DHS 3) to 5200 BCN - BCS SMDR-Koverter V4.0/n"
#define mess_startup2	" for DHS3-BCN                      BY HOERHAGER JOSEF VTE /n"
#define mess_startup3	" Ready for working !/l/n"
#define transfer_mark_str	"T"
//
#define how_much	"80 " // calc back to impulse
//**********************************************************
//  COMMON AFS DEFINES
//
#define csra	0Xfc81
#define csrb	0Xfc89
#define csrc	0Xfc91
#define csrd	0xfc99
#define baud_300	0X44
#define baud_1200	0X66
#define baud_2400	0X88
#define baud_4800	0X99
#define baud_9600	0Xbb
//
#define hour_to_sec		"3600  "
#define min_to_sec		"60  "
//
#define dbs_str 	s14
#define dbs_str_0	s14,0
#define dbs_search_str	s15,0
#define dbs_para	s15,100
//
#define calc_erg_sub	s15,140
//
#define fdt_str 	s15,150
#define dt_str		s15,180
#define dt_str_year	s15,180
#define dt_str_month	s15,182
#define dt_str_day	s15,184
#define dt_str_weekday	s15,186
#define dt_str_hour	s15,188
#define dt_str_minute	s15,190
#define lfdt_str	21
//
#define calc_erg_flag	s15,204
#define calc_p1 	s15,210
#define calc_p1_5	s15,215
#define calc_p2 	s15,220
#define calc_erg	s15,230
#define calc_erg_3dg	s15,233
#define calc_erg_5dg	s15,233
#define calc_rest	s15,240
//*********************************************************
// ALCATEL 5200 BCN
// ================
// Defination of BDI-RECORD standard
//
#define bdi_str 	s6
#define bdi_init_str	"C                                                  /n"
#define bdi_ext_num	bdi_str,1	//l=4 left
#define bdi_extern_num	bdi_str,5	//l=16 left
#define bdi_meterpulses bdi_str,21	//l=5 right
#define bdi_meterpuls_1 bdi_str,22	//l=4 right
#define bdi_ica_wtime	bdi_str,21	//l=5 in sekunden
#define bdi_time	bdi_str,26	//l=4 hhmm
#define bdi_time_hour	bdi_str,26
#define bdi_time_minute bdi_str,28
#define bdi_date	bdi_str,30	//l=4 ddmm
#define bdi_date_day	bdi_str,30
#define bdi_date_month	bdi_str,32
#define bdi_privat_mark bdi_str,34
#define bdi_project_num bdi_str,35
#define bdi_privat_num	bdi_str,35
#define bdi_duration	bdi_str,38	//l=5 hmmss
#define bdi_ica_durat	bdi_str,38	//l=5 in sekunden
#define bdi_duration_h	bdi_str,38
#define bdi_duration_m	bdi_str,39
#define bdi_duration_s	bdi_str,41
#define bdi_trunknum	bdi_str,43
#define bdi_transmark	bdi_str,46
#define bdi_tr_extnum	bdi_str,47
#define bdi_line_end	"/n",bdi_str,51
//
#define bdi_ica_voice	"INCOMING"
#define bdi_ica_data	"INCOMING-DATA"
//
#define bdi_lext_num		4
#define bdi_lextern_num 	16
#define bdi_lmeterpulses	5
#define bdi_ltime_hour		2
#define bdi_ltime_minute	2
#define bdi_ldate_month 	2
#define bdi_ldate_day		2
#define bdi_lppp_marking	1
#define bdi_lproject_num	3
#define bdi_lduration		5
#define bdi_ltrunknum		3
#define bdi_ltransmark		1
#define bdi_ltr_extnum		4
#define bdi_lica_wtime		5
#define bdi_lica_durat		5
//
//***********************************************************
// ALCATEL 4400 (DHS 3)
// Definition of SMDR-RECORD standard
//
#define in_str			s9
#define date_save		s7
//
#define dhs3_str1		s7
#define dhs3_str2		s8
#define dhs3_init_str		"                                                                                      "
#define dhs3_user_num		dhs3_str1,1	//l=8 right
#define dhs3_user_num_epos	8		//last digit of user-number
#define dhs3_user_name		dhs3_str1,10	//l=16 left
#define dhs3_code		dhs3_str1,41	//l=12 left
#define dhs3_cost_center	dhs3_str1,54	//l=4 left
//
#define dhs3_transfer_ext	dhs3_str2,1	//l=8 left
#define dhs3_trunk_num		dhs3_str2,10	//l=3 right
#define dhs3_trunk_num_2dg	dhs3_str2,11	//l=2 right
#define dhs3_node_num		dhs3_str2,14	//l=2 right
#define dhs3_extern_num 	dhs3_str2,17	//l=20 left
//
#define dhs3_time		dhs3_str2,38	// hh:mm
#define dhs3_time_hour		dhs3_str2,38
#define dhs3_time_minute	dhs3_str2,41
//
#define dhs3_duration		dhs3_str2,44	// hhh:mm:ss
#define dhs3_duration_hour	dhs3_str2,44
#define dhs3_duration_hour_2dg	dhs3_str2,45
#define dhs3_duration_hour_1dg	dhs3_str2,46
#define dhs3_duration_min	dhs3_str2,48
#define dhs3_duration_sec	dhs3_str2,51
//
#define dhs3_cost_schilling	dhs3_str2,54
#define dhs3_cost_len5		dhs3_str2,57
#define dhs3_cost_len4		dhs3_str2,58
#define dhs3_cost_comma 	dhs3_str2,59
#define dhs3_cost_groschen	dhs3_str2,60
//
#define dhs3_bc 		dhs3-str2,63	//l=3 right
#define dhs3_ppp_num		dhs3_str2,63	//(BC.)
#define dhs3_personal_ind	dhs3_str2,67	//l=1 (P,N,O,B)
#define dhs3_ppp_marking	dhs3_str2,67	//(P)
//
#define dhs3_cmf_code           dhs3_str2,74    //
#define dhs3_cmf_code_pos       74
//
#define dhs3_type		dhs3_str2,78	// type of the call
// format:	tt/mm/jj
#define dhs3_date		date_save,200
#define dhs3_date_day		date_save,200
#define dhs3_date_month 	date_save,203
#define dhs3_date_year		date_save,206
//
//*********************************************************
// Buffer 0 definitionen
//***********************************************
#define buffer_m0		0
#define badr_0_high		0x20
#define lbuff_0_high		0x40
#define modnum_0		0x00
//************************************************
//*********************************************************
//  AFS - RESET LABEL:
//
	setbaud 1,1200,8,n,1
	mode_reco
	setrts	off
//
	call	init_b0
//
// send signon mess
//
	movd	mess_startup1,s7,100
	out	s7,100,c4
	movd	mess_startup2,s7,100
	out	s7,100,c4
	movd	mess_startup3,s7,100
	out	s7,100,c4
error_main:
	mode_reco
	jmp	main
//
//**********************************************************
// MAIN PROGRAMM
//
main:
	movd	"                                                                                    ",in_str,0
        movd    bdi_init_str,bdi_str,0
main1:
	sett	200
	setl	9,1	// for modul 1
	setrts	on	//enable out
	wait	rx_sign,im_sign,cntl_sign
	setl	9,2
	case	cntl_sign,test_rx_sign
	compc	14,255
	jz	overrun
	jmp	main1
overrun:
	movd	"ERROR Buffer overrun on input CHANNEL 1/n",s7,100
	writeb	s7,100,0
	jmp	error_main
test_rx_sign:
	case	rx_sign,test_im_sign
//
// stop transmitter of dhs3
//
	setrts	off
//	  wrchar  xoff	  ;
	rds	in_str,0      //read reco from channel
	jz	main1
	compc	15,0
	jz	read_okay
	movd	"ERROR          on input CHANNEL 1/n",s7,100
	movc	15,s7,106
	writeb	s7,100,0
	compc	15,128		//test for break only
	jz	read_okay
	jmp	error_main
read_okay:
	compd	"/n",in_str,80  // test if recoend is okay
	jz	read1_okay
	movd	"reco_end is not okay on channel 1/n",s7,100
	writeb	s7,100,0
	writeb	in_str,0,0
	compd	"??//??//",in_str,0               // Date on first line of page
//
	jnz	main
//
	movs	in_str,0,dhs3_date,10		//save date in string_date
//
	jmp	main
//
read1_okay:
//*********************************************************
	writeb	in_str,0,0	// to buffer (M 3 will print it)
// **********************************************
// test if headerlines
/*
if (in_str,0 == "----------" ||           // Header line seperator
    in_str,0 == "|User    | Username" ||  // 1. header line of page english
    in_str,0 == "|  Trsf. |Tr.|N.|" ||    // 2. header line of page english
    in_str,0 == "|Teiln.  | Name " ||     // 1. header line german
    in_str,0 == "|Umgelegt|Ltg|Kn|" ||    // 2. header line german
    in_str,0 == "|VerbNr  |Amt|Kn|"       // 2. header line austrian
   )
*/
	compd	"----------",in_str,0           // Header line seperator
	jz	main
	compd	"|User    | Username",in_str,0  // 1. header line of page english
	jz	main
	compd	"|  Trsf. |Tr.|N.|",in_str,0    // 2. header line of page english
	jz	main
	compd	"|Teiln.  | Name ",in_str,0     // 1. header line german
	jz	main
	compd	"|Umgelegt|Ltg|Kn|",in_str,0    // 2. header line german
	jz	main
	compd	"|VerbNr  |Amt|Kn|",in_str,0    // 2. header line austrian
	jz   main
//
// **********************************************
// test if line is date
/*
   if (in_str,0 == "??/??/")                    // Date on first line of page
*/
	compd	"??//??//",in_str,0               // Date on first line of page
//
	jnz	dhs3_no_date_line
	movs	in_str,0,dhs3_date,10		//save date in string_date
	jmp	main
//
dhs3_no_date_line:
// **********************************************
// test if metering input is the second line
/*
      if (in_str,0 == "|????????|???|??|")      // 2.line of metering
*/
	compd	"|????????|???|??|",in_str,0
	jz	dhs3_second_line
//
// **********************************************
// else it is the first line of metering
//
	movs	in_str,0,dhs3_str1,0,85
	jmp	main
//
// **********************************************
// second line of metering
//
dhs3_second_line:
	movs	in_str,0,dhs3_str2,0,85 	// 2. line received save it
//
// **********************************************
// DATA RECO RECEIVED
// **********************************************
// CONVERT to BCN-SMDR BDI-RECO
// **********************************************
// common parameter for incoming and outgoing
// ******************************************************************
// ******************************************************************
// init BDI record
//
	movd	bdi_init_str,bdi_str,0	   // clear/set default output data
//
// **********************************************
// translate extension number
//
	movd	"              ",s14,100
        movs    dhs3_user_num,s14,100,8
	setc	10,100
        setc    11,8
find_non_space:
	compd	" ",s14,c10
	jnz	no_space
	incc	10
	decc	11
	jnz	find_non_space
no_space:
	movs	s14,c10,bdi_ext_num,4
//
// **********************************************
// transfer time
//
	movs	dhs3_time_hour,bdi_time_hour,2
	movs	dhs3_time_minute,bdi_time_minute,2
//
// **********************************************
// transfer date
//
	movs	dhs3_date_day,bdi_date_day,2
	movs	dhs3_date_month,bdi_date_month,2
//
// **********************************************
// transfer trunk number
//
	movs	dhs3_trunk_num,bdi_trunknum,bdi_ltrunknum
//
// **********************************************
// translate transfer call
//
	compd	"    ",dhs3_transfer_ext
	jz	no_transfered_call
//
	movs	dhs3_transfer_ext,bdi_tr_extnum,bdi_ltr_extnum
	movd	"F",bdi_transmark
//
no_transfered_call:
//
// **********************************************
// set indicator for isdn
//
	compd	"   ",dhs3_cmf_code
	jz	non_isdn_call
        movd    "I",bdi_str,0
//
non_isdn_call:
//
// **********************************************
// transfer projekt-number
//
	movs	dhs3_code,bdi_project_num,bdi_lproject_num
//
// **********************************************
// translate the parameter "P"
//
	compd	"P",dhs3_personal_ind
	jnz	no_privat_call
	movd	"P",bdi_privat_mark
//
no_privat_call:
//
// **********************************************
// select for incoming or outgoing call
/*
	if (dhs3_typ == E | F | J | K | M | N )
	   call is incoming
	else
	   call is outgoing
	endif
*/
        compd   "E",dhs3_type
	jz	incoming_call
        compd   "F",dhs3_type
	jz	incoming_call
        compd   "J",dhs3_type
	jz	incoming_call
        compd   "K",dhs3_type
	jz	incoming_call
        compd   "M",dhs3_type
	jz	incoming_call
        compd   "N",dhs3_type
	jz	incoming_call
//
// **********************************************
//	      SMDR-RECO is for an
//	      outgoing call.
// **********************************************
// transfer extern_number
//
	movs	dhs3_extern_num,bdi_extern_num,bdi_lextern_num
//
// **********************************************
// translate meter-pulses
// Test if cost are IMPULSE or CURRENCY
//
	compd	".",dhs3_cost_comma
	jnz	impulse_cost
//
	movd	"        ",calc_p1      // clear dividend
	movd	"        ",calc_p2      // clear divisor
	movd	how_much,calc_p2
	movs	dhs3_cost_schilling,calc_p1,5
	movs	dhs3_cost_groschen,calc_p1_5,2
	acall	div
	acall	cut_lz
	movs	calc_erg_3dg,bdi_meterpulses,5
	jmp	cost_end
impulse_cost:
	movs	dhs3_cost_len5,bdi_meterpulses,5
cost_end:
//
// **********************************************
// transfer duration of call
//
	movs	dhs3_duration_hour_1dg,bdi_duration_h,1
	movs	dhs3_duration_min,bdi_duration_m,2
	movs	dhs3_duration_sec,bdi_duration_s,2
//
//***********************************************
//###############################################
// test for private call
//
#ifdef  private
        compd   "   ",dhs3_code         // if there is no pin_code
        jz      not_private
        movd    str_suppress,bdi_str,begin_suppress
not_private:
//
#endif
//###############################################
//***********************************************
//
// **********************************************
// save the call in the buffer
//
save_call:
        movd    bdi_line_end
        buffwr bdi_str,0
loop_buffer_test:
	buffst			// test space of mem
// **********************************************
//
	jnz	main		// space available
// **********************************************
// if no space in the buffer
// send a message to buffer 0
// set led 14,15 flash
//
	movd	"ERROR SMDR-Buffer is full !!!!!!!!!/n",s7,100
	writeb	s7,100,0
	setl	14,2
	setl	15,2
	sett	20
	wait	tf_sign
	jmp	loop_buffer_test
//
// **********************************************
// INCOMING CALL
// **********************************************
incoming_call:
//
// **********************************************
// set string INCOMING
//
	movd	bdi_ica_voice,bdi_extern_num
//
// **********************************************
// DHS 3 does not support a correct indication for
// V24 DATA-CALL. The DHS 3 indicates in the feld
// "P" dhs3_personal_ind with "N" a normal call with "speech"
// and with "D" a call other than "speech".
//	  movd	  bdi_ica_data,bdi_extern_num
//
// **********************************************
// translate duration wait call befor answer
// DHS 3 does not support a indicator for duration until answer
//
	movd	"    0",bdi_ica_wtime
//
// **********************************************
// translate the duration of an incoming call
//
	movd	"      ",calc_p1
// hour x 3600
	movs	dhs3_duration_hour,calc_p1,3
	movd	"3600  ",calc_p2
	acall	mull
        movs    calc_erg,calc_erg_sub,8
// minute x 60
        movs    dhs3_duration_min,calc_p1,2
	movd	"60  ",calc_p2
	acall	mull
// minute + secunde
	movs	calc_erg,calc_p2,8
        movs    dhs3_duration_sec,calc_p1,2
	acall	add
// (minute+secunde) + hour x 60)
	movs	calc_erg,calc_p2,8
	movs	calc_erg_sub,calc_p1,8
	acall	add
	movs	calc_erg_5dg,bdi_ica_durat,bdi_lica_durat
//
	jmp	save_call
//
//*********************************************************
// on im_sign send answer "1ERR_CMD/n"
//
test_im_sign:
	case	im_sign,default_test
	in	s6,100
	out	s6,100,c4
	movd	"1ERR_CMD/n",s6,100
	out	s6,100,c4
	anss	s6,100
	jmp	main
//
// default do nothing
//
default_test:
	jmp	main
//
//************************************************
// Buffer 0 init
//
// Aufruf:	 call	 Init_b0
//
init_b0:
	setp	0XD300,badr_0_high	//beginn adresse high
	setp	0XD301,0x00		//beginn adresse low
//
	setp	0Xd302,lbuff_0_high	//bufferlaenge high
	setp	0XD303,0x00		//bufferlaenge low
//
	setp	0Xd304,lbuff_0_high	//anzahl bytes free high
	setp	0XD305,0x00		//anzahl bytes free low
//
	setp	0Xd306,badr_0_high	//input zeiger high
	setp	0XD307,0x00		//input zeiger low
//
	setp	0Xd308,lbuff_0_high	//input laenge bis bufferende high
	setp	0XD309,0x00		//input laenge bis bufferende low
//
	setp	0Xd30A,badr_0_high	//output zeiger high
	setp	0XD30B,0x00		//output zeiger low
//
	setp	0Xd30C,lbuff_0_high	//output laenge bis bufferende high
	setp	0XD30D,0x00		//output laenge bis bufferende low
//
	setp	0XD30E,modnum_0 	//modulnummer falls in modulmem
//
	ret
//
zzz:
end
