//*********************************************************
// ANWENDUNG Alcatel Austria AG
//   Application AVK- Technologiepark
//
// 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".
// V5.0	4.2.98
//	Update for DHS3 R1.5.3 (R2.0)
//	The program scanns the line and if the beginning of the second line
//	is equal to "|????????|???   |" the prgram handles all the parameter
//	in accord to the description for the software R1.5.3 (R2.0).
// 	
//	For calculating the meterpulses this program use 2 digit
//      and 3 digit bhind the dot
//
// V5.1 13.2.98
//      Update for DHS3 R2.0 Page 7
//      The application checks the second line to the string
//      "|????????|??????|" and the first line at the position _date
//      for the string "|??/??/??|". If true the lenth of the "trunk_number"
//      is 6 digits
// V5.2 27.02.98
//      Update duration: cut lz
//      Changes if parameter "P" (type of communication)
//      is a "B" (business communicaton) the modul insert 4 digit of
//      the code number.
// V6.0 06.05.98
//      Changes for AVK Tchnologiepark
//      Records with usernumber "FS000" will be changed to the
//      TRSF. number
//      The duration of the call is given at position 50
//      in the format hhmmss and the costcenter is given at
//      position 34 in the format " ccccccccc"
//      Parameter cccc number of costcenter up to 12 digit (limit DHS3)
//      (remark: normaly the feld duration begin at psition 51
//      and have the format hmmss)
// V6.1 08.06.98
//      Factor for calculating from currency to units changed
//      to 0,936 and 1,06.
//
// V6.2 08.06.98
//      Privatcall aktivatet on projekt numbers
//
// V6.3 10.09.98
//      Adapted for R2.1
//      New headerline, changing in parameter
//
// V6.4 BDI output format changed to normal bdi-format
//      "#define bdi_format_normal"
//
//*********************************************************
//#########################################################
#define bdi_format_normal
//
//#define private
#define begin_suppress   5
#define str_suppress    "................"
//#########################################################
//**********************************************************
//
//*********************************************************
// Strings
//
// s3,s4,s5,s6
// buffer 0
//
//*********************************************************
//
#define mess_startup1   " Alcatel 4400 (DHS 3) to 5200 BCN - BCS SMDR-Koverter V6.4/n"
#define mess_startup2   " for DHS3-BCN                      BY HOERHAGER JOSEF AOHE/n"
#define mess_startup3	" Ready for working !/l/n"
#define transfer_mark_str	"T"
#define isdn_mark               "C"     // replace if necessery
//
#define how_much	"106 " // calc back to impulse
#define how_much_3dg    "0936 "// 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_4       s15,214
#define calc_p1_5	s15,215
#define calc_p2 	s15,220
#define calc_erg	s15,230
#define calc_erg_6dg    s15,232
#define calc_erg_5dg	s15,233
#define calc_erg_3dg    s15,235
#define calc_rest	s15,240
//
//*******************************************************************
//
#ifdef bdi_format_normal
//*********************************************************
// ALCATEL 5200 BCN
// ================
// Defination of BDI-RECORD standard "EXTENSION-LENGTH" = 4
// 
#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,34
#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        4
#define bdi_lduration		5
#define bdi_ldurat_hour         1
#define bdi_ltrunknum           3
#define bdi_ltransmark		1
#define bdi_ltr_extnum		4
#define bdi_lica_wtime		5
#define bdi_lica_durat		5
//
#else
//
//*********************************************************
// ALCATEL 5200 BCN
// ================
// Projeckt number length 16 digit and duaration hour 2 digits
// Defination of BDI-RECORD standard "EXTENSION-LENGTH" = 4
// 
#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,50      //l=6 hhmmss
#define bdi_ica_durat   bdi_str,51      //l=5 in sekunden
#define bdi_duration_h  bdi_str,50
#define bdi_duration_m  bdi_str,52
#define bdi_duration_s  bdi_str,54
#define bdi_trunknum    bdi_str,56
#define bdi_transmark   bdi_str,59
#define bdi_tr_extnum   bdi_str,60
#define bdi_line_end    "/n",bdi_str,64
//
#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        12
#define bdi_lduration           6
#define bdi_ldurat_hour         2
#define bdi_ltrunknum           3
#define bdi_ltransmark		1
#define bdi_ltr_extnum		4
#define bdi_lica_wtime		5
#define bdi_lica_durat		5
//
#endif
//
//***********************************************************
// ALCATEL 4400 (DHS 3)
// Definition of SMDR-RECORD standard up to R1.4
//
#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_comma_3dg     dhs3_str2,58
#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
//
//*********************************************************
// Definition of DHS3 R1.5.3
//
//
#define dhs3_r153_user_num		dhs3_str1,1	//l=8 left
#define dhs3_r153_user_name		dhs3_str1,10	//l=16 left
#define dhs3_r153_code			dhs3_str1,27	//l=12 left
//
#define dhs3_r153_date_1                dhs3_str1,39
#define dhs3_r153_date                  dhs3_str1,40    //l=8
#define dhs3_r153_date_day		dhs3_str1,40	//l=2
#define dhs3_r153_date_month		dhs3_str1,43	//l=2
#define dhs3_r153_date_year		dhs3_str1,46	//l=2
//
#define dhs3_r153_service               dhs3_str1,49    //l=6 not implemented
#define dhs3_r153_cost_center		dhs3_str1,56	//l=5 left
#define dhs3_r153_trgroup_num           dhs3_str1,64    //l=3
#define dhs3_r153_trnode_num            dhs3_str1,68    //l=4
#define dhs3_r153_sbnode_num            dhs3_str1,73    //l=4
#define dhs3_r153_comm_type             dhs3_str1,78    //l=1
//
#define dhs3_r153_transfer_ext		dhs3_str2,1	//l=8 left
#define dhs3_r153_trunk_num		dhs3_str2,10	//l=3 right
#define dhs3_r153_trunk_num_2dg		dhs3_str2,11	//l=2 right
#define dhs3_r153_extern_num 		dhs3_str2,17	//l=20 left
//
#define dhs3_r153_time			dhs3_str2,38	// hh:mm
#define dhs3_r153_time_hour		dhs3_str2,38
#define dhs3_r153_time_minute           dhs3_str2,41
//
#define dhs3_r153_duration		dhs3_str2,44	// hhh:mm:ss
#define dhs3_r153_duration_hour		dhs3_str2,44
#define dhs3_r153_duration_hour_2dg	dhs3_str2,45
#define dhs3_r153_duration_hour_1dg	dhs3_str2,46
#define dhs3_r153_duration_min		dhs3_str2,48
#define dhs3_r153_duration_sec		dhs3_str2,51
//
#define dhs3_r153_cost_schilling	dhs3_str2,54
#define dhs3_r153_cost_len5		dhs3_str2,57
#define dhs3_r153_cost_len4		dhs3_str2,58
#define dhs3_r153_cost_comma 		dhs3_str2,59
#define dhs3_r153_cost_comma_3dg        dhs3_str2,58
#define dhs3_r153_cost_groschen		dhs3_str2,60
//
#define dhs3_r153_bc 			dhs3-str2,63	//l=3 right
#define dhs3_r153_ppp_num		dhs3_str2,63	//(BC.)
#define dhs3_r153_personal_ind          dhs3_str2,67    //l=1 (P,N,B)
#define dhs3_r153_ppp_marking		dhs3_str2,67	//(P)
//
#define dhs3_r153_cmf_code           	dhs3_str2,74    //
#define dhs3_r153_cmf_code_pos       	74
//
#define dhs3_r153_type			dhs3_str2,78	// type of the call
//*********************************************************
// Definition of DHS3 R2.0 Page 7
//
//
#define dhs3_r2p7_user_num              dhs3_str1,1     //l=8 left
#define dhs3_r2p7_user_name             dhs3_str1,10    //l=16 left
#define dhs3_r2p7_code                  dhs3_str1,27    //l=12 left
//
#define dhs3_r2p7_date_1                dhs3_str1,39
#define dhs3_r2p7_date                  dhs3_str1,40    //l=8
#define dhs3_r2p7_date_day              dhs3_str1,40    //l=2
#define dhs3_r2p7_date_month            dhs3_str1,43    //l=2
#define dhs3_r2p7_date_year             dhs3_str1,46    //l=2
//
#define dhs3_r2p7_service               dhs3_str1,49    //l=6 not implemented
#define dhs3_r2p7_cost_center           dhs3_str1,56    //l=5 left
#define dhs3_r2p7_trgroup_num           dhs3_str1,64    //l=3
#define dhs3_r2p7_trnode_num            dhs3_str1,68    //l=4
#define dhs3_r2p7_sbnode_num            dhs3_str1,73    //l=4
#define dhs3_r2p7_comm_type             dhs3_str1,78    //l=1
//
#define dhs3_r2p7_transfer_ext          dhs3_str2,1     //l=8 left
#define dhs3_r2p7_trunk_num             dhs3_str2,10    //l=6 right
#define dhs3_r2p7_trunk_num_2dg         dhs3_str2,14    //l=2 right
#define dhs3_r2p7_extern_num            dhs3_str2,17    //l=20 left
//
#define dhs3_r2p7_time                  dhs3_str2,38    // hh:mm
#define dhs3_r2p7_time_hour             dhs3_str2,38
#define dhs3_r2p7_time_minute           dhs3_str2,41
//
#define dhs3_r2p7_duration              dhs3_str2,44    // hhh:mm:ss
#define dhs3_r2p7_duration_hour         dhs3_str2,44
#define dhs3_r2p7_duration_hour_2dg     dhs3_str2,45
#define dhs3_r2p7_duration_hour_1dg     dhs3_str2,46
#define dhs3_r2p7_duration_min          dhs3_str2,48
#define dhs3_r2p7_duration_sec          dhs3_str2,51
//
#define dhs3_r2p7_cost_schilling        dhs3_str2,54
#define dhs3_r2p7_cost_len5             dhs3_str2,57
#define dhs3_r2p7_cost_len4             dhs3_str2,58
#define dhs3_r2p7_cost_comma            dhs3_str2,59
#define dhs3_r2p7_cost_comma_3dg        dhs3_str2,58
#define dhs3_r2p7_cost_groschen         dhs3_str2,60
//
#define dhs3_r2p7_bc                    dhs3-str2,63    //l=3 right
#define dhs3_r2p7_ppp_num               dhs3_str2,63    //(BC.)
#define dhs3_r2p7_personal_ind          dhs3_str2,67    //l=1 (P,N,O,B)
#define dhs3_r2p7_ppp_marking           dhs3_str2,67    //(P)
//
#define dhs3_r2p7_cmf_code              dhs3_str2,74    //
#define dhs3_r2p7_cmf_code_pos          74
//
#define dhs3_r2p7_type                  dhs3_str2,78    // type of the call
//*********************************************************
// 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,9600,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
    in_str,0 == "|Subscr. |Name" ||       // 1. header line of page DHS3 R1.5.3
    in_str,0 == "|Trf. Sub|Trk   |" ||    // 2. header line of page DHS3 R1.5.3
    in_str,0 == "|Trf. Sub|Trunk |" ||    // 2. header line of page DHS3 R2.1
    in_str,0 == "|Trf.Tln |Amt   |"
   )
*/
	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 for headerlines R1.5.3
//
   compd   "|Subscr. |Name",in_str,0       // 1. header line of page R1.5.3
   jz      main
   compd   "|Trf. Sub|Trk   |",in_str,0    // 2. header line of page R1.5.3
   jz      main
//
// test header for r2.1
//
   compd   "|Trf. Sub|Trunk |",in_str,0    // 2. header line of page R2.1
   jz      main
   compd   "|Trf.Tln |Amt   |",in_str,0
   jz      main
//
//
   compd   "Date",dhs3_r153_date           // 1. header line of page R2.1
   jz      main
   compd   "Hour",dhs3_r153_time           // 2. header line of page R2.1
   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:
        compd   "????//??//?? ",in_str,0
        jz      main
//
// **********************************************
// test if metering input is the second line
/*
      if (in_str,0 == "|????????|???|??|")      // 2.line of metering
*/
	compd	"|????????|???|??|",in_str,0
	jz	dhs3_second_line
//
//*********************************************************
// DHS3 R1.5.3 (R2.0 Page 6)
// same as for R2.1
/*
      if (in_str,0 == "|????????|???   |")      // 2.line of metering
*/
        compd   "|????????|???   |",in_str,0
        jz      dhs3_r153second_line
//
// **********************************************
//*********************************************************
// DHS3 R1.5.3  (R2.0 Page7)
/*
      if (in_str,0 == "|????????|??????|")      // 2.line of metering
*/
        compd   "|????????|??????|",in_str,0
        jnz      save_first_line
        compd   "|??//??//??|",dhs3_r2p7_date_1
        jmp     dhs3_r2p7second_line

//
// **********************************************
// else it is the first line of metering
//
save_first_line:
        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    isdn_mark,bdi_str,0
//
non_isdn_call:
//
// **********************************************
// transfer projekt-number
//
        movs    dhs3_code,bdi_project_num,bdi_lproject_num
        compd   "B",dhs3_personal_ind
        jnz     no_business_call
no_business_call:
//
// **********************************************
// 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     cost_3digit
//
	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_5dg,bdi_meterpulses,5
	jmp	cost_end
//
cost_3digit:
        compd   ".",dhs3_cost_comma_3dg
        jnz     impulse_cost
//
	movd	"        ",calc_p1      // clear dividend
	movd	"        ",calc_p2      // clear divisor
        movd    how_much_3dg,calc_p2
        movs    dhs3_cost_schilling,calc_p1,4   // "SSSS"
        movs    dhs3_cost_comma,calc_p1_4,3     // "SSSSGGG"
	acall	div
	acall	cut_lz
        movs    calc_erg_5dg,bdi_meterpulses,5
	jmp	cost_end
//
impulse_cost:
	movs	dhs3_cost_len5,bdi_meterpulses,5
cost_end:
//
// **********************************************
// transfer duration of call
//
//
        movs    dhs3_duration_min,bdi_duration_m,2
	movs	dhs3_duration_sec,bdi_duration_s,2
        movd    "00000000",calc_erg
// Rel v6.0
#if ( bdi_ldurat_hour == 2)
        movs    dhs3_duration_hour_2dg,bdi_duration_h,bdi_ldurat_hour
//
        movs    bdi_duration_h,calc_erg_6dg,6
        replace " 0",calc_erg_6dg,2
        acall   cut_lz
        movs    calc_erg_6dg,bdi_duration_h,6
#else
        movs    dhs3_duration_hour_1dg,bdi_duration_h,bdi_ldurat_hour
//
        movs    bdi_duration_h,calc_erg_5dg,5
        replace " 0",calc_erg_6dg,2
        acall   cut_lz
        movs    calc_erg_5dg,bdi_duration_h,5
#endif
//
//***********************************************
//###############################################
// 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
//
        compd   "FS00",bdi_ext_num
        jnz     not_replace
        movs    bdi_ext_num,s14,100,4
        movs    bdi_tr_extnum,bdi_ext_num,4
        movs    s14,100,bdi_tr_extnum,4
//
not_replace:
        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
	movd	"      ",calc_p1
        movs    dhs3_duration_min,calc_p1,2
	movd	"60  ",calc_p2
	acall	mull
// minute + secunde
	movd	"      ",calc_p1
	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
//
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
// RELEASE R1.5.3
//
// **********************************************
// second line of metering
//
dhs3_r153second_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
// because the extensionnumber is left justified no translation is necessary
//
        movs    dhs3_r153_user_num,bdi_ext_num,bdi_lext_num
//
// **********************************************
// transfer time
//
        movs    dhs3_r153_time_hour,bdi_time_hour,2
        movs    dhs3_r153_time_minute,bdi_time_minute,2
//
// **********************************************
// transfer date
//
        movs    dhs3_r153_date_day,bdi_date_day,2
        movs    dhs3_r153_date_month,bdi_date_month,2
//
// **********************************************
// transfer trunk number
//
        movd    "        ",calc_p1
        movd    "0       ",calc_p2
        movs    dhs3_r153_trunk_num,calc_p1,6
        acall   add
        acall   cut_lz
	compd	"   ",calc_erg_3dg
	jnz	skip1_r153
	movd	"  0",calc_erg_3dg
skip1_r153:
	movs	calc_erg_3dg,bdi_trunknum,bdi_ltrunknum
//
// **********************************************
// translate transfer call
//
        compd   "    ",dhs3_r153_transfer_ext
        jz      no_r153_tr_call
//
        movs    dhs3_r153_transfer_ext,bdi_tr_extnum,bdi_ltr_extnum
	movd	"F",bdi_transmark
//
no_r153_tr_call:
//
// **********************************************
// set indicator for isdn
//
//        compd   "   ",dhs3_cmf_code
//        jz      non_isdn_call
//        movd    isdn_mark,bdi_str,0
//
//non_isdn_call:
//
// **********************************************
// transfer projekt-number
//
        movs    dhs3_r153_code,bdi_project_num,bdi_lproject_num
        compd   "B",dhs3_r153_personal_ind
        jnz     no_r153business_call
no_r153business_call:
//
// **********************************************
// translate the parameter "P"
//
        compd   "P",dhs3_r153_personal_ind
        jnz     no_r153_privat_call
	movd	"P",bdi_privat_mark
//
no_r153_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_r153_type
        jz      incoming_r153_call
        compd   "F",dhs3_r153_type
        jz      incoming_r153_call
        compd   "J",dhs3_r153_type
        jz      incoming_r153_call
        compd   "K",dhs3_r153_type
        jz      incoming_r153_call
        compd   "M",dhs3_r153_type
        jz      incoming_r153_call
        compd   "N",dhs3_r153_type
        jz      incoming_r153_call
//
// **********************************************
//	      SMDR-RECO is for an
//	      outgoing call.
// **********************************************
// transfer extern_number
//
        movs    dhs3_r153_extern_num,bdi_extern_num,bdi_lextern_num
//
// **********************************************
// translate meter-pulses
// Test if cost are IMPULSE or CURRENCY
//
        compd   ".",dhs3_r153_cost_comma
        jnz     cost_r153_3digit
//
	movd	"        ",calc_p1      // clear dividend
	movd	"        ",calc_p2      // clear divisor
	movd	how_much,calc_p2
        movs    dhs3_r153_cost_schilling,calc_p1,5
        movs    dhs3_r153_cost_groschen,calc_p1_5,2
	acall	div
	acall	cut_lz
        movs    calc_erg_5dg,bdi_meterpulses,5
        jmp     cost_r153_end
//
cost_r153_3digit:
        compd   ".",dhs3_r153_cost_comma_3dg
        jnz     impulse_r153_cost
//
	movd	"        ",calc_p1      // clear dividend
	movd	"        ",calc_p2      // clear divisor
        movd    how_much_3dg,calc_p2
        movs    dhs3_r153_cost_schilling,calc_p1,4   // "SSSS"
        movs    dhs3_r153_cost_comma,calc_p1_4,3     // "SSSSGGG"
	acall	div
	acall	cut_lz
        movs    calc_erg_5dg,bdi_meterpulses,5
        jmp     cost_r153_end
//
impulse_r153_cost:
        movs    dhs3_r153_cost_len5,bdi_meterpulses,5
cost_r153_end:
//
// **********************************************
// transfer duration of call
//
        movs    dhs3_r153_duration_min,bdi_duration_m,2
        movs    dhs3_r153_duration_sec,bdi_duration_s,2
        movd    "00000000",calc_erg
//
#if ( bdi_ldurat_hour == 2)
        movs    dhs3_r153_duration_hour_2dg,bdi_duration_h,bdi_ldurat_hour
        movs    bdi_duration_h,calc_erg_6dg,6
        replace " 0",calc_erg_6dg,2
        acall   cut_lz
        movs    calc_erg_6dg,bdi_duration_h,6
#else
        movs    dhs3_r153_duration_hour_1dg,bdi_duration_h,1
        movs    bdi_duration_h,calc_erg_5dg,5
        replace " 0",calc_erg_6dg,2
        acall   cut_lz
        movs    calc_erg_5dg,bdi_duration_h,5
#endif
//
//***********************************************
//###############################################
// test for private call
//
#ifdef  private
        compd   "   ",dhs3_r153_code         // if there is no pin_code
        jz      not_r153_private
        movd    str_suppress,bdi_str,begin_suppress
not_r153_private:
//
#endif
        jmp     save_call
//###############################################
// **********************************************
// INCOMING CALL
// **********************************************
incoming_r153_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_r153_duration_hour,calc_p1,3
	movd	"3600  ",calc_p2
	acall	mull
        movs    calc_erg,calc_erg_sub,8
// minute x 60
	movd	"      ",calc_p1
        movs    dhs3_r153_duration_min,calc_p1,2
	movd	"60  ",calc_p2
	acall	mull
// minute + secunde
	movd	"      ",calc_p1
	movs	calc_erg,calc_p2,8
        movs    dhs3_r153_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
//
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
//*********************************************************
// RELEASE R1.5.3 (R2.0 Page 7)
//
// **********************************************
// second line of metering
//
dhs3_r2p7second_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
// because the extensionnumber is left justified no translation is necessary
//
        movs    dhs3_r2p7_user_num,bdi_ext_num,bdi_lext_num
//
// **********************************************
// transfer time
//
        movs    dhs3_r2p7_time_hour,bdi_time_hour,2
        movs    dhs3_r2p7_time_minute,bdi_time_minute,2
//
// **********************************************
// transfer date
//
        movs    dhs3_r2p7_date_day,bdi_date_day,2
        movs    dhs3_r2p7_date_month,bdi_date_month,2
//
// **********************************************
// transfer trunk number
//
        movd    "        ",calc_p1
        movd    "0       ",calc_p2
        movs    dhs3_r153_trunk_num,calc_p1,6
        acall   add
	acall	cut_lz
	compd	"   ",calc_erg_3dg
        jnz     skip1_r2p7
	movd	"  0",calc_erg_3dg
skip1_r2p7:
	movs	calc_erg_3dg,bdi_trunknum,bdi_ltrunknum
//
// **********************************************
// translate transfer call
//
        compd   "    ",dhs3_r2p7_transfer_ext
        jz      no_r2p7_tr_call
//
        movs    dhs3_r2p7_transfer_ext,bdi_tr_extnum,bdi_ltr_extnum
        movd    "F",bdi_transmark
//
no_r2p7_tr_call:
//
// **********************************************
// set indicator for isdn
//
//        compd   "   ",dhs3_cmf_code
//        jz      non_isdn_call
//        movd    isdn_mark,bdi_str,0
//
//non_isdn_call:
//
// **********************************************
// transfer projekt-number
//
        movs    dhs3_r2p7_code,bdi_project_num,bdi_lproject_num
        compd   "B",dhs3_r2p7_personal_ind
        jnz     no_r2p7business_call
no_r2p7business_call:
//
// **********************************************
// translate the parameter "P"
//
        compd   "P",dhs3_r2p7_personal_ind
        jnz     no_r2p7_privat_call
	movd	"P",bdi_privat_mark
//
no_r2p7_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_r2p7_type
        jz      incoming_r2p7_call
        compd   "F",dhs3_r2p7_type
        jz      incoming_r2p7_call
        compd   "J",dhs3_r2p7_type
        jz      incoming_r2p7_call
        compd   "K",dhs3_r2p7_type
        jz      incoming_r2p7_call
        compd   "M",dhs3_r2p7_type
        jz      incoming_r2p7_call
        compd   "N",dhs3_r2p7_type
        jz      incoming_r2p7_call
//
// **********************************************
//	      SMDR-RECO is for an
//	      outgoing call.
// **********************************************
// transfer extern_number
//
        movs    dhs3_r2p7_extern_num,bdi_extern_num,bdi_lextern_num
//
// **********************************************
// translate meter-pulses
// Test if cost are IMPULSE or CURRENCY
//
        compd   ".",dhs3_r2p7_cost_comma
        jnz     cost_r2p7_3digit
//
	movd	"        ",calc_p1      // clear dividend
	movd	"        ",calc_p2      // clear divisor
	movd	how_much,calc_p2
        movs    dhs3_r2p7_cost_schilling,calc_p1,5
        movs    dhs3_r2p7_cost_groschen,calc_p1_5,2
	acall	div
	acall	cut_lz
        movs    calc_erg_5dg,bdi_meterpulses,5
        jmp     cost_r2p7_end
//
cost_r2p7_3digit:
        compd   ".",dhs3_r2p7_cost_comma_3dg
        jnz     impulse_r2p7_cost
//
	movd	"        ",calc_p1      // clear dividend
	movd	"        ",calc_p2      // clear divisor
        movd    how_much_3dg,calc_p2
        movs    dhs3_r2p7_cost_schilling,calc_p1,4   // "SSSS"
        movs    dhs3_r2p7_cost_comma,calc_p1_4,3     // "SSSSGGG"
	acall	div
	acall	cut_lz
        movs    calc_erg_5dg,bdi_meterpulses,5
        jmp     cost_r2p7_end
//
impulse_r2p7_cost:
        movs    dhs3_r2p7_cost_len5,bdi_meterpulses,5
cost_r2p7_end:
//
// **********************************************
// transfer duration of call
//
        movs    dhs3_r2p7_duration_min,bdi_duration_m,2
        movs    dhs3_r2p7_duration_sec,bdi_duration_s,2
        movd    "00000000",calc_erg
//
#if ( bdi_ldurat_hour == 2)
        movs    dhs3_r2p7_duration_hour_2dg,bdi_duration_h,bdi_ldurat_hour
        movs    bdi_duration_h,calc_erg_6dg,6
        replace " 0",calc_erg_6dg,2
        acall   cut_lz
        movs    calc_erg_6dg,bdi_duration_h,6
#else
        movs    dhs3_r2p7_duration_hour_1dg,bdi_duration_h,1
        movs    bdi_duration_h,calc_erg_5dg,5
        replace " 0",calc_erg_6dg,2
        acall   cut_lz
        movs    calc_erg_5dg,bdi_duration_h,5
#endif
//
//***********************************************
//###############################################
// test for private call
//
#ifdef  private
        compd   "   ",dhs3_r2p7_code         // if there is no pin_code
        jz      not_r2p7_private
        movd    str_suppress,bdi_str,begin_suppress
not_r2p7_private:
//
#endif
        jmp     save_call
//###############################################
// **********************************************
// INCOMING CALL
// **********************************************
incoming_r2p7_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_r2p7_duration_hour,calc_p1,3
	movd	"3600  ",calc_p2
	acall	mull
        movs    calc_erg,calc_erg_sub,8
// minute x 60
	movd	"      ",calc_p1
        movs    dhs3_r2p7_duration_min,calc_p1,2
	movd	"60  ",calc_p2
	acall	mull
// minute + secunde
	movd	"      ",calc_p1
	movs	calc_erg,calc_p2,8
        movs    dhs3_r2p7_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
