//
//*********************************************************
// GDC - Handler
//*********************************************************
//#define schottenpoint
//
// load into modul3
//
#include "smdrmess.inc"
#include "tickmess.inc"
#include "gdcglob.txt"
#include "message.inc"
#define debug_l1
#define debug_input
#define debug_output
#define comma		// if comma def ","
//#define werbung
#define werbetext	" Alcatel Austria AG "
//
#ifdef small_gdc
#define string_version  " Small-G-D-C  V0.9c Modul 3 Ready/n"
#else
#define string_version  " G-D-C  V0.9c Modul 3 Ready/n"
#endif
#define printer_default         "001110911111001"
//                               abcdefghijklmno
//*********************************************************
// local parameter
//*********************************************************
// counter
// used counter 14
//	counter 15 from os
//
#define dbs_number	0
#define dbs_count	1
#define page1_line      2
#define page1_state     3
#define cnt_ret         4

#define page_lf_cnt	5
#define update_cnt	6
#define mess_counter	7
#define page2_line	8
#define page2_state	9
//
//*********************************************************
//
        setbaud 1,9600,8,n,1
	setp	0x7f02,0x01
	mode_reco
//
// INIT
//
	setl	11,2
	setc	page1_line,1
	setc	page1_state,0
	setc	page2_line,1
	setc	page2_state,0
	movc	page1_line,page_calc1
	movc	page2_line,page_calc2
	movd	"000 ",input_state
	movd	"000 ",old_state
	setc	update_cnt,255
	call	update_bled
	call	init_b6
//
// test for first run
//
        compd   "GDC09Euro/n",first_run
        jz      skip_auto_in
//
        call    init_first
        call    init_buffer
//
skip_auto_in:
        setrts  off
	sett	10
	wait	tf_sign
#ifdef small_gdc
        movd    " Small-G-D-C  V0.9c (Modul 3) *GDC09c.DW3* by J. Hoerhager AOPE/n",wstr_m36,0
#else
        movd    " G-D-C  V0.9c (Modul 3) *GDC09c.DW3* by J. Hoerhager AOPE/n",wstr_m36,0
#endif
        out     wstr_m36,0,c4
	movd	"Installed expanded memory =     blocks a 32 KByte/n",wstr_m36,100
	getp	expand_mem,dec
	movs	s15,240,wstr_m36,128,3
	out	wstr_m36,100,c4
	compd	"064",wstr_m36,128
	jz	error_main
        movd    "ERROR ERROR ERROR on expanded memory !!!!!!/n",wstr_m36,100
        out     wstr_m36,100,c4
#ifdef  small_gdc
        movd    " Starting GDC in smallmode!!!!!!/n",wstr_m36,100
        out     wstr_m36,100,c4
        setl    6,1             // signal small GDC
        jmp     error_main
#else
        sett    100
	setl	7,2
	wait	tf_sign
//
// reset if no expanded memory is installed
//
	acall	0000
#endif
//
//*****************************************************
//
error_main:
	setp	0x7f02,0x01
	mode_reco
	movd	string_version,wstr_m36,100
	out	wstr_m36,100,c4
//
// ********************************************************
//
main:
	sett	100
//
main_1:
	setl	11,1
	setrts	on
	wait	ans_sign,tf_sign,im_sign
	case	ans_sign,test_im_sign
//
//*************************************
// message from modul 1 via buffer "input_b"
//
	setl	11,2
	readb	wstr_m3,0,input_b
	jz	main_1			// if buffer is empty wait
//
#ifdef debug_input
	out	wstr_m3,0,c4
#endif
//
	compd	"/n",wstr_m3,0          // only cr
	jz     main_send_sig
//
	jr	input_state
	jmp	state_0 	//common
	jmp	state_1 	//ticket
	jmp	state_2
	jmp	state_3
	jmp	state_4
	jmp	state_5
	jmp	state_6
	jmp	state_7
	jmp	state_8
	jmp	state_9
	jmp	state_10	// ticket line 1
	jmp	state_11	// ticket line 2
	jmp	state_12	// ticket line 3
        jmp     state_13        // ticket line 4
	jmp	state_14	// ticket line 5
	jmp	state_15	// ticket line 6
	jmp	state_16	// ticket line 7 ... 17 (checkin ticket)
	jmp	state_17	// Ticket line for telefonzelle
	jmp	state_18
	jmp	state_19
	jmp	state_20	// ticket line 7 ... 12 (checkout ticket)

//
state_0:
#ifdef debug_l1
	movd	" State_0_modul_3/n",wstr_m36,200
	out	wstr_m36,200,c4
#endif
	movd	"000 ",input_state
	compd	"-----",wstr_m3,0
	jz	head_line1
//
	compd	"^L/n",wstr_m3,0
	jz	main_send_sig
//
//***************************************************************************
//
	comps	r26_smout_n3,wstr_m3,0,11
	jz	smdr_out
	comps	r26_smout_t3,wstr_m3,0,11
	jz	smdr_out
	comps	r26_smout_d3,wstr_m3,0,11
	jz	smdr_out
	comps	r26_smout_c3,wstr_m3,0,11
	jz	smdr_out
//*************************************************
	comps	r26_smout_n2,wstr_m3,0,11
	jz	smdr_2dg_out
	comps	r26_smout_t2,wstr_m3,0,11
	jz	smdr_2dg_out
	comps	r26_smout_d2,wstr_m3,0,11
	jz	smdr_2dg_out
	comps	r26_smout_c2,wstr_m3,0,11
	jz	smdr_2dg_out
//***********************************************
	comps	r26_rstate_3,wstr_m3,0,14
	jz	room_state
	comps	r26_rstate_2,wstr_m3,0,14
	jz	room_2dg_state
//
	comps	r311_rstate_3,wstr_m3,0,16
	jz	r311_roomstate
	comps	r312_rstate_3,wstr_m3,0,10
	jz	r312_roomstate
//
//**********************************************
	comps	r26_wakeup_3,wstr_m3,0,14
	jz	termin
	comps	r26_wakeup_2,wstr_m3,0,14
	jz	termin_2dg
//
	comps	r311_wakeup_3,wstr_m3,0,20
	jz	r311_wakeup
	comps	r312_wakeup_3,wstr_m3,0,14
	jz	r312_wakeup
//
//***********************************************
//
	comps	r311_smout_n3,wstr_m3,0,16
	jz	r311_smout
	comps	r311_smout_t3,wstr_m3,0,16
	jz	r311_smout
	comps	r311_smout_c3,wstr_m3,0,16
	jz	r311_smout
//
	comps	r312_smout_n3,wstr_m3,0,11
	jz	r312_smout
	comps	r312_smout_t3,wstr_m3,0,11
	jz	r312_smout
	comps	r312_smout_c3,wstr_m3,0,11
	jz	r312_smout
//***********************************************
// WP_HEADER
//
/*
        comps   r26_headl_1,wstr_m3,0,11
	jz	main_send_sig
	comps	r26_headl_2,wstr_m3,0,11
	jz	main_send_sig
//
	comps	r31_headl_1,wstr_m3,0,17
	jz	main_send_sig
	comps	r31_headl_2,wstr_m3,0,17
	jz	main_send_sig
*/
//
//***********************************************
// incomming calls
//
	comps	r26_smin_n3,wstr_m3,0,11
	jz	smdr_in
	comps	r26_smin_t3,wstr_m3,0,11
	jz	smdr_in
	comps	r26_smin_d3,wstr_m3,0,11
	jz	smdr_in
//
	comps	r26_smin_n2,wstr_m3,0,11
        jz      smdr_2dg_in
	comps	r26_smin_t2,wstr_m3,0,11
        jz      smdr_2dg_in
	comps	r26_smin_d2,wstr_m3,0,11
        jz      smdr_2dg_in
//
	comps	r311_smin_n3,wstr_m3,0,16
	jz	r311_smin
	comps	r311_smin_t3,wstr_m3,0,16
	jz	r311_smin
//
	comps	r312_smin_n3,wstr_m3,0,11
	jz	r312_smin
	comps	r312_smin_t3,wstr_m3,0,11
	jz	r312_smin
//***********************************************
// move away the hotel_name
//
	comps	hotel_name,wstr_m3,0,10
	jz	main_send_sig
//
	movs	print_other,printer,1
	call	print_messim
	jz	main_send_sig
//
//*********************************************************
//
state_1:
state_2:
state_3:
state_4:
state_5:
state_6:
state_7:
state_8:
state_9:
state_18:
state_19:
	jmp	main_send_sig
//*********************************************************
// terminruf
//
r311_wakeup:
        call    form_r311
        jmp     do_termin
//
//*************************************
r312_wakeup:
        call    form_r312
        jmp     do_termin//
//*************************************
//
termin_2dg:
//
	movs	wstr_m3,3,wstr_m3,2,4
//
termin:
        call    form_r26_3dg
//
do_termin:
//        movd    "00000000",calc_erg
//        movd    "00000000",geb_aktu
//        movd    "        ",dhs2_cost
	movd	"/n",dhs2_cr_pos                // write end of reco
//
	movs	print_wakeup,printer,1

	call	print_smdrim
	jmp	main_send_sig
//*********************************************************
// Zimmerstatus
//
r311_roomstate:
        call    form_r311
//
        call    t_zusatzkosten
        jz      do_smdr_out
//
        jmp     do_room
//
//*************************************
r312_roomstate:
        call    form_r312
        call    t_zusatzkosten
        jz      do_smdr_out
//
        jmp     do_room
//
//*************************************
room_2dg_state:
	movs	wstr_m3,3,wstr_m3,2,4
//
room_state:
//
// format it
//
        call    form_r26_3dg
//
        call    t_zusatzkosten
        jz      do_smdr_out
//
do_room:
        compd   "Zusatzkosten",dhs2_extern
        jz      main_send_sig
do_1_room:
//        movd    "00000000",calc_erg
//        movd    "00000000",geb_aktu
//        movd    "         ",dhs2_cost
	movd	"/n",dhs2_cr_pos         // write end of reco
//
// check if status is from config extension?
//
#ifdef  debug_l1
	out	wstr_m3,0,c4
#endif
	compd	config_tln,dhs2_tln_num
	jz	st_config
//
// save room state on tln
//
	movs	print_room_state,printer,1	// desination of room_state
//
	movd	"002 0 ",dbs_para
	acall	pfirst_dbs
	movs	dhs2_tln_num,dbs_search_str,4
	acall	find_dbs
	jnz	room_err
	acall	read11_dbs
	compd	"R",s11,_ext_type
	jz	room_st_save
//
room_st_save:
	movs	dhs2_zi_status,s11,_room_state,4
	movd	"R",s11,_ext_type
	acall	write11_dbs
	call	print_smdrim
	jmp	main_send_sig
//
room_err:
	movs	print_err,printers,1
	call	print_smdrim
	movs	msg_48009,wstr_m3,0,48	//" Subscriber not found in EXT_DBS!/n"
	call	print_smdrim
	jmp	main_send_sig
//
//*********************************************************
//*********************************************************
// ROOM STATE from configuration extension
st_config:
//
// if roomstate begins with "0"
// code using
// else extension
//
	movs	print_manuell,printer,1      // desination of mauell prints
//
	movs	dhs2_in,0,dhs2_save,100
	replace "- ",dhs2_zi_status_number,4
	compd	"0",dhs2_zi_status_number
	jnz	zi_extension
//
// room state some codes:
//
//***********************************************
//***********************************************
//
// print all smdr for rooms
//
	compd	"010",dhs2_zi_status_number
	jz	st_010
//
// print open sum of rooms
//
	compd	"011",dhs2_zi_status_number
	jz	st_011
//
// print closed sum of rooms
//
	compd	"012",dhs2_zi_status_number
	jz	st_012
//
// print room-state
//
	compd	"013",dhs2_zi_status_number
	jz	st_013
//
// clear closed summ of rooms
//
	compd	"019",dhs2_zi_status_number
	jz	st_019
//***********************************************
//***********************************************
//
// immediate printout of all barphone
//
	compd	"020",dhs2_zi_status_number
	jz	st_020
//
// print open sum of barphone
//
	compd	"021",dhs2_zi_status_number
	jz	st_021
//
// print closed sum of barphone
//
	compd	"022",dhs2_zi_status_number
	jz	st_022
//
// clear closed sum of barphone
//
	compd	"029",dhs2_zi_status_number
	jz	st_029
//***********************************************
//***********************************************
//
// immediate printout of all phonebooth records
//
	compd	"030",dhs2_zi_status_number
	jz	st_030
//
// print open sum of phonebooth
//
	compd	"031",dhs2_zi_status_number
	jz	st_031
//
// print closed sum of phonebooth
//
	compd	"032",dhs2_zi_status_number
	jz	st_032
//
// clear closed sum of phonebooth
//
	compd	"039",dhs2_zi_status_number
	jz	st_039
//***********************************************
//***********************************************
//
// immediate printout of all administration records
//
	compd	"040",dhs2_zi_status_number
	jz	st_040
//
// print open sum of administration
//
	compd	"041",dhs2_zi_status_number
	jz	st_041
//
// print closed sum of administration
//
	compd	"042",dhs2_zi_status_number
	jz	st_042
//
// print administration with billing
//
        compd   "048",dhs2_zi_status_number
        jz      st_048
//
// clear closed sum of administration
//
	compd	"049",dhs2_zi_status_number
	jz	st_049
//***********************************************
//***********************************************
// print miniticket
//
	compd	"08?",dhs2_zi_status_number
	jz	st_08x
//***********************************************
//***********************************************
//
	compd	"091",dhs2_zi_status_number
	jz	st_091
//
	compd	"092",dhs2_zi_status_number
	jz	st_092
//
	compd	"099",dhs2_zi_status_number
	jz	st_099
//
	jmp	main_send_sig
//
st_099:
	call	do_ff1_ff
	jmp	main_send_sig
//
st_091:
	movd	"copy buffer1/n",wstr_m3,0
	call	print1_m3
	jmp	main_send_sig
//
st_092:
	movd	"copy buffer2/n",wstr_m3,0
	call	print2_m3
	jmp	main_send_sig
//
//***********************************************
//***********************************************
// Print a small ticket for log.extension x
//
st_08x:
//
	movs	print_single_ticket,printer,1	   // desination of single ticket
//
	movs	dhs2_zi_status_1dg,dbs_search_str,1
	movd	"2 4 ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	code_not_def
	acall	read11_dbs
	compd	"255",s11,_tln_bottom
	jz	tln_no_calls
	movs	s11,_tln_bottom,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
// formating the aktureco
//
	movs	dbs_str,_smdr_cost,geb_aktu,5
	movs	dbs_str,_smdr_gr,geb_aktu_gr,3
//
// now printing
//
	call	test_form_ff
	call	load_h60
	call	print_load
	movs	hotel_name,wstr_m3,2,20
	call	print_load
	movs	dbs_str,_smdr_date,wstr_m3,2,14
	call	print_load
	call	print_load
	movs	msg_32001,wstr_m3,2,32	//"Einzelgespraechsrechnung vom",wstr_m3,2
	call	print_load
	movs	msg_32002,wstr_m3,2,32	//"Teilnehmer:",wstr_m3,2
        movs    s11,_tln,wstr_m3,34,4
	call	print_load
	call	print_load
	movs	msg_32003,wstr_m3,2,32	//"Gewaehlte Rufnummer:",wstr_m3,2
	movs	dbs_str,_smdr_extern,wstr_m3,34,20
	replace ". ",wstr_m3,34,20
	call	print_load
	movs	msg_32004,wstr_m3,2,32	//"Gespraechsdauer:",wstr_m3,2
	movs	dbs_str,_smdr_duration,wstr_m3,34,8
	call	print_load
	call	print_load
	movs	msg_32005,wstr_m3,2,32	//"Gespraechskosten:",wstr_m3,2
	movs	dbs_str,_smdr_cost,wstr_m3,34,9
//
        movs    msg_03002,wstr_m3,44,3  //"EUR"
        compd   "3",calc_euro
        jz      x80_print_euro
        compd   "2",calc_euro
        jz      x80_print_euro
        movs    msg_03001,wstr_m3,44,3  //"ATS"
x80_print_euro:
        call    print_load
	movs	msg_32007,wstr_m3,2,32	//"  inklusive MWST (20.00%):",wstr_m3,2
//
// calculate 20% MWST
//
//	  movs	  geb_aktu,calc_p1,8
//	  movd	  "10 ",calc_p2
//	  acall   mul
//	  movs	  calc_erg,calc_p1,8
//	  movd	  "12 ",calc_p2
//	  acall   div
//
//	  movs	  calc_erg,calc_p2,8
//	  movs	  geb_aktu,calc_p1,8
//	  acall   subb
//
//	  compd   "00000000",calc_erg
//	  jnz	  st8x_erg001
//	  movd	  "    ",calc_erg
//	  jmp	  st8x_erg002
//st8x_erg001:
//	  acall   cut_lz
//	  compd   "     ",calc_erg
//	  jnz	  st8x_erg002
//	  movd	  "    0",calc_erg
//st8x_erg002:
//	  movs	  calc_erg,wstr_m3,34,5
//
#ifdef	comma
//	  movd	  ",",wstr_m3,39
#else
//	  movd	  ".",wstr_m3,39
#endif
//	  movs	  calc_erg_3dg,wstr_m3,40,3
//
//	  movd	  "ATS",wstr_m3,44
	call	print_load
	call	print_load
	movs	msg_32008,wstr_m3,2,32	//"Danke fuer Ihren Besuch!",wstr_m3,2
	call	pr_ticket
	call	load_h60
#ifdef werbung
	movd	werbetext,wstr_m3,35
#endif
	call	pr_ticket
	call	pr_formfeed
	jmp	main_send_sig
//
//*********************************************************
// that code is not defined
//
code_not_def:
	call	test_form_ff
	call	load_h60
	call	print_load
	movs	msg_48002,wstr_m3,2,48	//"Keine Rufnummer zugeordnet zu Code:",wstr_m3,2
	movs	dhs2_savezi_status_number,wstr_m3,50,3
	call	pr_ticket
	call	load_h60
	call	pr_ticket
	call	pr_formfeed
	jmp	main_send_sig
//
//*********************************************************
// the extension defined under that code has no call
//
tln_no_calls:
	call	test_form_ff
	call	load_h60
	call	print_load
	movs	msg_48003,wstr_m3,2,48	//"Keine Gespraeche eingetragen fuer Teilnehmer:",wstr_m3,2
        movs    s11,_tln,wstr_m3,50,4
	call	pr_ticket
	call	load_h60
	call	pr_ticket
	call	pr_formfeed
	jmp	main_send_sig
//
print_load:
	call	pr_ticket
	call	load_def60
	ret
//***********************************************
//***********************************************
// room
// Zimmerliste aller offenen Gebuehren
//
st_011:
	call	do_st_011
	jmp	main_send_sig
//
do_st_011:
	call	print_lfmess
	call	print_trlmess
	movs	msg_64001,wstr_m3,0,64	//" Liste offener Gebuehren          bis:                              /n",wstr_m3,0
	movs	dhs2_save_date,wstr_m3,39,15
	call	print_messim
	call	print_lfmess
	movs	msg_32009,wstr_m3,0,32	//" fuer Zimmertelefone:/n",wstr_m3,0
	call	print_clmess
//
        movd    "0???",extension_num
	movd	"00000000 ",geb_total
	movd	"002 1 ",dbs_para
	movd	"R ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_011:
pr_2sp_open:
	acall	find_dbs
	jnz	st_end2_011
	acall	read11_dbs
        comps   s11,_tln,extension_num,4
	jz	st_01_011
	call	print_clmess
//
st_01_011:
	movs	s11,_tln,extension_num,4
        movd    "???",extension1_num
        movs    s11,_tln,wstr_m3,10,4
        movd    "...",wstr_m3,15
	movs	s11,_cost_open,calc_erg,8
	call	form_erg_m3_45
        movs    wstr_m3,45,wstr_m3,19,9
	movd	"         ",wstr_m3,45
	call	calc_total_open
//
	acall	pnext_dbs
	acall	find_dbs
	jnz	st_end1_011
	acall	read11_dbs
        comps   s11,_tln,extension_num,4
	jz	st_02_011
	call	print_clmess
	call	print_lfmess
	jmp	st_01_011
//
st_02_011:
        movs    s11,_tln,wstr_m3,36,4
	movd	"...",wstr_m3,41
	movs	s11,_cost_open,calc_erg,8
	call	form_erg_m3_45
	call	calc_total_open
	acall	pnext_dbs
	call	print_clmess
	jmp	st_l1_011
//
st_end1_011:
        call    print_clmess
st_end2_011:
print_sum_m3_45:
        call    print_trlmess
//        call    print_lfmess
	movs	msg_64002,wstr_m3,0,64	//" Summe offener Gebuehren                 ATS        /n",wstr_m3,0
	movs	geb_total,calc_erg,8
	call	form_erg_m3_45
//
//------> calc euro
//
        compd   "0",calc_euro
        jz      skip_st011_1
        compd   "1",calc_euro
        jz      skip_st011_1
        movd    "EUR",wstr_m3,41
skip_st011_1:
        call    print_messim
//
//------> calc euro
//
        compd   "1",calc_euro
        jnz     skip_st011_2
        movs    wstr_m3,45,param_1,9    //load input parameter
        call    ats_to_euro
        movs    param_ergr9,wstr_m3,45,9
        movs    msg_03002,wstr_m3,41,3  //"EUR"
        movd    "                                  ",wstr_m3,0
        call    print_messim
        jmp     skip_st011_3
skip_st011_2:
        compd   "2",calc_euro
        jnz     skip_st011_3
        movs    wstr_m3,45,param_1,9    //load input parameter
        call    euro_to_ats
        movs    param_ergr9,wstr_m3,45,9
        movs    msg_03001,wstr_m3,41,3  //"ATS"
        movd    "                                  ",wstr_m3,0
        call    print_messim
        jmp     skip_st011_3
skip_st011_3:
//

        call    print_listemess
//
	ret
//
//***********************************************
//***********************************************
// Liste offener Gebuehren Bartelefon
//
st_021:
	call	do_st_021
	jmp	main_send_sig
//
do_st_021:
	call	print_lfmess
	call	print_trlmess
	movs	msg_64001,wstr_m3,0,64	//" Liste offener Gebuehren          bis:                              /n",wstr_m3,0
	movs	dhs2_save_date,wstr_m3,39,15
	call	print_messim
	call	print_lfmess
	movs	msg_32011,wstr_m3,0,32	//" fuer Bartelefon(e):/n",wstr_m3,0
	call	print_clmess
	call	print_lfmess
//
	movd	"00000000 ",geb_total
	movd	"002 1 ",dbs_para
	movd	"B ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_021:
pr_1sp_open:
	acall	find_dbs
	jnz	st_end2_021
	acall	read11_dbs
	movd	"                                                                    /n",wstr_m3,0
        movs    s11,_tln,wstr_m3,19,4
	movd	".................",wstr_m3,24
	movs	s11,_cost_open,calc_erg,8
	call	form_erg_m3_45
	call	calc_total_open
	call	print_messim
//
	acall	pnext_dbs
	jmp	st_l1_021
st_end1_021:
st_end2_021:
//
        call    print_sum_m3_45
//
        ret
//***********************************************
//***********************************************
//
print_listemess:
	call	print_trlmess
	movs	msg_32010,wstr_m3,0,32	//movd	  " ENDE DER LISTE!/n",wstr_m3,0
	call	print_messim
	call	pr_formfeed
//
	ret
//
//***********************************************
//***********************************************
// liste offener Gebuehren Telefonzellen
//
st_031:
	call	do_st_031
	jmp	main_send_sig
//
do_st_031:
	call	print_lfmess
	call	print_trlmess
	movs	msg_64001,wstr_m3,0,64	//" Liste offener Gebuehren          bis:                              /n",wstr_m3,0
	movs	dhs2_save_date,wstr_m3,39,15
	call	print_messim
	call	print_lfmess
	movs	msg_32012,wstr_m3,0,32	//" fuer Telefonzelle(n):/n",wstr_m3,0
	call	print_clmess
	call	print_lfmess
//
	movd	"00000000 ",geb_total
	movd	"002 1 ",dbs_para
	movd	"P ",dbs_search_str
//
	acall	pfirst_dbs
	jmp	pr_1sp_open
/*****
*****/
//
//***********************************************
//***********************************************
// Liste aller offenen Gebuehren fuer Betriebsteilnehmer
//
st_041:
	call	do_st_041
	jmp	main_send_sig
//
do_st_041:
	call	print_lfmess
	call	print_trlmess
	movs	msg_64001,wstr_m3,0,64	//" Liste offener Gebuehren          bis:                              /n",wstr_m3,0
	movs	dhs2_save_date,wstr_m3,39,15
	call	print_messim
	call	print_lfmess
	movs	msg_32013,wstr_m3,0,32	//" fuer Betriebsteilnehmer:/n",wstr_m3,0
	call	print_clmess
	call	print_lfmess
//
        movd    "0???",extension_num
	movd	"00000000 ",geb_total
	movd	"002 1 ",dbs_para
	movd	"A ",dbs_search_str
//
	acall	pfirst_dbs
	jmp	pr_2sp_open
//
/*****
*****/
//
//***********************************************
//***********************************************
// Zimmerliste aller verrechneten Gebuehren
//
st_012:
	call	do_st_012
	jmp	main_send_sig
//
do_st_012:
	call	print_lfmess
	call	print_trlmess
	movs	msg_48004,wstr_m3,0,48	//" Liste abgerechneter Gebuehren:/n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                             bis:                              /n",wstr_m3,0
	movs	last_date_time,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_32009,wstr_m3,0,32	//" fuer Zimmertelefone:/n",wstr_m3,0
	call	print_clmess
//
        movd    "0???",extension_num
	movd	"00000000 ",geb_total
	movd	"00000000 ",geb_aktu
	movd	"002 1 ",dbs_para
	movd	"R ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_012:
pr_2sp_closed:
	acall	find_dbs
	jnz	st_end2_012
	acall	read11_dbs
        comps   s11,_tln,extension_num,4
	jz	st_01_012
	call	print_clmess
//
st_01_012:
	movs	s11,_tln,extension_num,4
        movd    "???",extension1_num
        movs    s11,_tln,wstr_m3,10,4
        movd    "...",wstr_m3,15
	movs	s11,_cost_closed,calc_erg,8
	call	form_erg_m3_45
        movs    wstr_m3,45,wstr_m3,19,9
	movd	"         ",wstr_m3,45
	call	calc_total_closed
//
	acall	pnext_dbs
	acall	find_dbs
	jnz	st_end1_012
	acall	read11_dbs
        comps   s11,_tln,extension_num,4
	jz	st_02_012
	call	print_clmess
	call	print_lfmess
	jmp	st_01_012
//
st_02_012:
        movs    s11,_tln,wstr_m3,36,4
	movd	"...",wstr_m3,41
	movs	s11,_cost_closed,calc_erg,8
	call	form_erg_m3_45
	call	calc_total_closed
	acall	pnext_dbs
	call	print_clmess
	jmp	st_l1_012
//
st_end1_012:
	call	print_clmess
st_end2_012:
//
//        call    print_sum_m3_45
//
print_sum_st12_45:
        call    print_trlmess
//        call    print_lfmess
        movs    msg_64004,wstr_m3,0,64  //" Summe offener Gebuehren                 ATS        /n",wstr_m3,0
	movs	geb_total,calc_erg,8
	call	form_erg_m3_45
//
//------> calc euro
//
        compd   "0",calc_euro
        jz      skip_st012_1
        compd   "1",calc_euro
        jz      skip_st012_1
        movd    "EUR",wstr_m3,41
skip_st012_1:
        call    print_messim
//
//------> calc euro
//
        compd   "1",calc_euro
        jnz     skip_st012_2
        movs    wstr_m3,45,param_1,9    //load input parameter
        call    ats_to_euro
        movs    param_ergr9,wstr_m3,45,9
        movs    msg_03002,wstr_m3,41,3  //"EUR"
        movd    "                                  ",wstr_m3,0
        call    print_messim
        jmp     skip_st012_3
skip_st012_2:
        compd   "2",calc_euro
        jnz     skip_st012_3
        movs    wstr_m3,45,param_1,9    //load input parameter
        call    euro_to_ats
        movs    param_ergr9,wstr_m3,45,9
        movs    msg_03001,wstr_m3,41,3  //"ATS"
        movd    "                                  ",wstr_m3,0
        call    print_messim
        jmp     skip_st012_3
skip_st012_3:
//

        call    print_listemess
//
	ret
//
//
//***********************************************
//***********************************************
// Liste offener Gebuehren Bartelefon
//
st_022:
	call	do_st_022
	jmp	main_send_sig
//
do_st_022:
	call	print_lfmess
	call	print_trlmess
	movs	msg_48004,wstr_m3,0,48	//" Liste abgerechneter Gebuehren:/n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                             bis:                              /n",wstr_m3,0
	movs	last_date_bar,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_32011,wstr_m3,0,32	//" fuer Bartelefon(e):/n",wstr_m3,0
	call	print_clmess
	call	print_lfmess
//
	movd	"00000000 ",geb_total
	movd	"002 1 ",dbs_para
	movd	"B ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_022:
pr_1sp_closed:
	acall	find_dbs
	jnz	st_end2_022
	acall	read11_dbs
	movd	"                                                                    /n",wstr_m3,0
        movs    s11,_tln,wstr_m3,19,4
	movd	".................",wstr_m3,24
	movs	s11,_cost_closed,calc_erg,8
	call	form_erg_m3_45
	call	calc_total_closed
	call	print_messim
//
//
	acall	pnext_dbs
	jmp	st_l1_022
st_end1_022:
st_end2_022:
//
        call    print_sum_st12_45
//
/*
//        call    print_lfmess
	call	print_trlmess
	movs	msg_64004,wstr_m3,0,64	//" Summe abgerechneter Gebuehren             ATS                           /n",wstr_m3,0
	movs	geb_total,calc_erg,8
	call	form_erg_m3_45
	call	print_messim
//
//------> calc euro
//
        compd   "1",calc_euro
        jnz     skip_st22
        movs    wstr_m3,45,param_1,9    //load input parameter
        call    ats_to_euro
        movs    param_ergr9,wstr_m3,45,9
        movs    msg_03002,wstr_m3,41,3
        movd    "                                  ",wstr_m3,0
        call    print_messim
skip_st22:
//
//
	call	print_listemess
//
*/
        ret
//
//***********************************************
//***********************************************
// liste verrechneter Gebuehren Telefonzellen
//
st_032:
	call	do_st_032
	jmp	main_send_sig
//
do_st_032:
	call	print_lfmess
	call	print_trlmess
	movs	msg_48004,wstr_m3,0,48	//" Liste abgerechneter Gebuehren:/n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                        bis:                              /n",wstr_m3,0
	movs	last_date_telef,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_32012,wstr_m3,0,32	//" fuer Telefonzelle(n):/n",wstr_m3,0
	call	print_clmess
	call	print_lfmess
//
	movd	"00000000 ",geb_total
	movd	"002 1 ",dbs_para
	movd	"P ",dbs_search_str
//
	acall	pfirst_dbs
	jmp	pr_1sp_closed
//
/*****
*****/
//
//***********************************************
//***********************************************
//***********************************************
// Betriebsteilnehmerliste aller verrechneten Gebuehren
//
st_042:
	call	do_st_042
	jmp	main_send_sig
//
do_st_042:
	call	print_lfmess
	call	print_trlmess
	movs	msg_48004,wstr_m3,0,48	//" Liste abgerechneter Gebuehren:/n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                          bis:                              /n",wstr_m3,0
	movs	last_date_betrieb,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_32013,wstr_m3,0,32	//" fuer Betriebsteilnehmer:/n",wstr_m3,0
	call	print_clmess
//
        movd    "0???",extension_num
	movd	"00000000 ",geb_total
	movd	"00000000 ",geb_aktu
	movd	"002 1 ",dbs_para
	movd	"A ",dbs_search_str
//
	acall	pfirst_dbs
	jmp	pr_2sp_closed
//
/*****
*****/
//
//***********************************************
//***********************************************
// loesche der verrechneten Gebuehren
// fuer Zimmer
//
st_019:
	call	do_st_019
	jmp	main_send_sig
//
do_st_019:
	call	print_lfmess
	call	print_trlmess
	movs	msg_32014,wstr_m3,0,32	//" Abgerechnete Gebuehren /n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                             bis:                              /n",wstr_m3,0
	movs	last_date_time,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
        movs    msg_48005,wstr_m3,0,48  //" fuer Zimmertelefon(e) geloescht!/n",wstr_m3,0
	call	print_messim
//        call    print_trlmess
	movs	dhs2_save_date,last_date_time,15

//
	movd	"002 1 ",dbs_para
	movd	"R ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_019:
	acall	find_dbs
	jnz	st_end1_019
	acall	read11_dbs
	movd	"00000000",s11,_cost_closed
//
	acall	write11_dbs
	acall	pnext_dbs
	jmp	st_l1_019
st_end1_019:
	call	print_listemess
//
	ret
//
//***********************************************
//***********************************************
// loesche der verrechneten Gebuehren
// fuer Bartelefone
//
st_029:
	call	do_st_029
	jmp	main_send_sig
//
do_st_029:
	call	print_lfmess
	call	print_trlmess
	movs	msg_32014,wstr_m3,0,32	//" Abgerechnete Gebuehren /n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                             bis:                              /n",wstr_m3,0
	movs	last_date_bar,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_48006,wstr_m3,0,48	//" fuer Bartelefon(e) geloescht!/n",wstr_m3,0
	call	print_messim
//        call    print_trlmess
	movs	dhs2_save_date,last_date_bar,15

//
	movd	"002 1 ",dbs_para
	movd	"B ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_029:
	acall	find_dbs
	jnz	st_end1_029
	acall	read11_dbs
	movd	"00000000",s11,_cost_closed
//
	acall	write11_dbs
	acall	pnext_dbs
	jmp	st_l1_029
st_end1_029:
	call	print_listemess
//
	ret
//
//***********************************************
//***********************************************
// loesche der verrechneten Gebuehren
// fuer Telefonzelle
//
st_039:
	call	do_st_039
	jmp	main_send_sig
//
do_st_039:
	call	print_lfmess
	call	print_trlmess
	movs	msg_32014,wstr_m3,0,32	//" Abgerechnete Gebuehren /n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                             bis:                              /n",wstr_m3,0
	movs	last_date_telef,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_48007,wstr_m3,0,48	//" fuer Telefonzelle(n) geloescht!/n",wstr_m3,0
	call	print_messim
//        call    print_trlmess
	movs	dhs2_save_date,last_date_telef,15

//
	movd	"002 1 ",dbs_para
	movd	"P ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_039:
	acall	find_dbs
	jnz	st_end1_039
	acall	read11_dbs
	movd	"00000000",s11,_cost_closed
//
	acall	write11_dbs
	acall	pnext_dbs
	jmp	st_l1_039
st_end1_039:
	call	print_listemess
//
	ret
//
//***********************************************
//***********************************************
// loesche der verrechneten Gebuehren
// fuer Betriebsteilnehmer
//
st_049:
	call	do_st_049
	jmp	main_send_sig
//
do_st_049:
	call	print_lfmess
	call	print_trlmess
	movs	msg_32014,wstr_m3,0,32	//" Abgerechnete Gebuehren /n",wstr_m3,0
	call	print_messim
	call	print_lfmess
	movs	msg_64003,wstr_m3,0,64	//" vom:                             bis:                              /n",wstr_m3,0
	movs	last_date_betrieb,wstr_m3,6,15
	movs	dhs2_save_date,wstr_m3,35,15
	call	print_messim
	call	print_lfmess
	movs	msg_48008,wstr_m3,0,48	//" fuer Betriebsteilnehmer geloescht!/n",wstr_m3,0
	call	print_messim
//        call    print_trlmess
	movs	dhs2_save_date,last_date_betrieb,15

//
	movd	"002 1 ",dbs_para
	movd	"A ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_049:
	acall	find_dbs
	jnz	st_end1_049
	acall	read11_dbs
	movd	"00000000",s11,_cost_closed
//
	acall	write11_dbs
	acall	pnext_dbs
	jmp	st_l1_049
st_end1_049:
	call	print_listemess
//
	ret
//
//***********************************************
//***********************************************
// immediate printout of room state
//
st_013:
	call	print_lfmess
//
	movd	"002 1 ",dbs_para
	movd	"R ",dbs_search_str
//
	call	pr_status_head
	acall	pfirst_dbs
st_l1_013:
	compc	page2_line,p_length
	jnz	st_02_13
	call	pr_status_head
st_02_13:
	acall	find_dbs
	jnz	st_end1_013
	acall	read11_dbs
	movs	s11,_tln,wstr_m3,2,4
	compd	"I",s11,_checkin_flag
	jz	st_03_13
	movs	msg_20001,wstr_m3,20,20 //"check-out          ",wstr_m3,20
	jmp	st_04_13
st_03_13:
	movs	msg_20002,wstr_m3,20,20 //"           check-in",wstr_m3,20
st_04_13:
	movs	s11,_room_state,wstr_m3,43,4
	call	print_messim
	acall	pnext_dbs
	jmp	st_l1_013
st_end1_013:
	call	print_listemess
//
	jmp	main_send_sig
//***********************************************
//***********************************************
// print administration mauell with billing
//
st_048:
	call	print_trennl
        movs    msg_80006,wstr_m3,0,80  //" Manueller Gebuehrenausdruck fuer Betriebsteilnehmer und Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	call	print_trennl
        movd    "M",print_type
        call    pr_adminm_clear
        movd    " ",print_type
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
        jmp     main_send_sig
//
//***********************************************
//***********************************************
// immediate printout of all rooms
//
st_010:
	call	print_lfsmdr
	movs	msg_64005,wstr_m3,0,64	//" Gebuehrenliste aller Zimmertelefone         ohne Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	movd	"00000000 ",geb_total
//
	movd	"002 1 ",dbs_para
	movd	"R ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_010:
	acall	find_dbs
	jnz	st_end1_010
	acall	read11_dbs
	movs	s11,_tln,extension_num,4

	movd	"0",print_mark          // no print messages

        movd    "M",print_type
	call	pr_tln_s11_nocl
        movd    " ",print_type

	movd	"002 1 ",dbs_para
	movd	"R ",dbs_search_str

	call	calc_total_open
	acall	pnext_dbs
	jmp	st_l1_010
st_end1_010:
	call	print_ges
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	jmp	main_send_sig
//
//***********************************************
//***********************************************
// immediate printout of barphone
//
st_020:
	call	print_lfsmdr
	movs	msg_64006,wstr_m3,0,64	//" Gebuehrenliste Bartelefon(e)             ohne Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	movd	"00000000 ",geb_total
//
	movd	"002 1 ",dbs_para
	movd	"B ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_020:
	acall	find_dbs
	jnz	st_end1_020
	acall	read11_dbs
	movs	s11,_tln,extension_num,4

	movd	"0",print_mark          // no print messages

        movd    "M",print_type
	call	pr_tln_s11_nocl
        movd    " ",print_type

	movd	"002 1 ",dbs_para
	movd	"B ",dbs_search_str

	call	calc_total_open
	acall	pnext_dbs
	jmp	st_l1_020
st_end1_020:
	call	print_ges
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	jmp	main_send_sig
//
//***********************************************
//***********************************************
// immediate printout of phonebooth
//
st_030:
	call	print_lfsmdr
	movs	msg_64007,wstr_m3,0,64	//" Gebuehrenliste Telefonzelle(n)         ohne Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	movd	"00000000 ",geb_total
//
	movd	"002 1 ",dbs_para
	movd	"P ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_030:
	acall	find_dbs
	jnz	st_end1_030
	acall	read11_dbs
	movs	s11,_tln,extension_num,4

	movd	"0",print_mark          // no print messages

        movd    "M",print_type
	call	pr_tln_s11_nocl
        movd    " ",print_type

	movd	"002 1 ",dbs_para
	movd	"P ",dbs_search_str

	call	calc_total_open
	acall	pnext_dbs
	jmp	st_l1_030
st_end1_030:
	call	print_ges
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	jmp	main_send_sig
//
//***********************************************
//***********************************************
// immediate printout of all administration
//
st_040:
	call	print_lfsmdr
	movs	msg_64008,wstr_m3,0,64	//" Gebuehrenliste aller Betriebsteilnehmer   ohne Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	movd	"00000000 ",geb_total
//
	movd	"002 1 ",dbs_para
	movd	"A ",dbs_search_str
//
	acall	pfirst_dbs
st_l1_040:
	acall	find_dbs
	jnz	st_end1_040
	acall	read11_dbs
	movs	s11,_tln,extension_num,4

	movd	"0",print_mark          // no print messages

        movd    "M",print_type
	call	pr_tln_s11_nocl
        movd    " ",print_type

	movd	"002 1 ",dbs_para
	movd	"A ",dbs_search_str

	call	calc_total_open
	acall	pnext_dbs
	jmp	st_l1_040
st_end1_040:
	call	print_ges
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	jmp	main_send_sig
//
//***********************************************
//***********************************************
//
zi_extension:
        compd   "9",dhs2_zi_status_number
        jnz     zi_exten_3dg
        movd    "    ",extension_num
        movs    dhs2_zi_status_2dg,extension_num,3
        movs    extension_num,dhs2_zi_status_number,4
zi_exten_3dg:
        movs    dhs2_zi_status_number,extension_num,4
//
// if first digit is 0 print clearing
// else print with no clearing
//
	compd	"0",dhs2_zi_status
	jz	zi_pr_clearing
//
	call	print_trennl
	movs	msg_64009,wstr_m3,0,64	//" Gebuehrenliste fuer Teilnehmer:        ohne Abrechnung!/n",wstr_m3,0
	movs	extension_num,wstr_m3,33,4
	call	print_smdrim

	movd	"1",print_mark          // no print messages

	call	pr_tln_nocl
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	jmp	main_send_sig
//
zi_pr_clearing:
	call	print_trennl
	movs	msg_64010,wstr_m3,0,64	//" Gebuehrenliste fuer Teilnehmer:         und Abrechnung!/n",wstr_m3,0
	movs	extension_num,wstr_m3,33,4
	call	print_smdrim

	movd	"1",print_mark          // no print messages

	call	pr_tln_cl
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	jmp	main_send_sig
//
//
//***********************************************
//
form_erg_m3_45:
	compd	"00000000",calc_erg
	jnz	form_erg001
        movd    "    ",calc_erg
	jmp	form_erg002
form_erg001:
	acall	cut_lz
        compd   "     ",calc_erg
	jnz	form_erg002
        movd    "    0",calc_erg
form_erg002:
        movs    calc_erg,wstr_m3,46,5
//
#ifdef	comma
        movd    ",",wstr_m3,51
#else
        movd    ".",wstr_m3,51
#endif
        movs    calc_erg_3dg,wstr_m3,52,2
	ret
//***********************************************
print_clmess:
	call	print_messim
	movd	"                                                                              /n",wstr_m3,0
	ret
//
print_lfmess:
	movd	"/n",wstr_m3,0
	call	print_messim
	movd	"  ",wstr_m3,0
	ret
//
print_lfsmdr:
	movd	"/n",wstr_m3,0
	call	print_smdrim
	movd	"  ",wstr_m3,0
	ret
//
//***********************************************
//
line_fill_m3:
	movd	"-------------------------------------------------------------------------------/n",wstr_m3,0
	ret
//
print_trlmess:
	call	line_fill_m3
	call	print_messim
	ret
//*********************************************************
//
test_form_ff:
        compd   "2",printer
        jz      test_pr2_ff
        movd    "        ",calc_p1
	movc	page1_line,calc_p1
	movd	page_length_ticket,calc_p2
	acall	comp
	compd	"GT",calc_erg_flag
        jnz     head1_skip
	call	do_ff1_ff
head1_skip:
	ret
//
test_pr2_ff:
        movd    "        ",calc_p1
        movc    page2_line,calc_p1
	movd	page_length_ticket,calc_p2
	acall	comp
	compd	"GT",calc_erg_flag
        jnz     head2_skip
        call    do_ff2_ff
head2_skip:
	ret
//
//*********************************************************
// headline 1 test which headline
//
head_line1:
	compd	"---/n",wstr_m3,58
	jnz	head1_line1
//
//*************************************
// first line or last line of a ticket
// init ticket buffer
//
	call	init_b6
	writeb	wstr_m3,0,ticket_b	// send to buffer
//
#ifdef debug_l1
	movd	" State_010_modul_3/n",wstr_m36,200
	out	wstr_m36,200,c4
#endif
	movd	"010 ",input_state      // next state line 2
main_send_sig:
	sendsig ans_sign,c3
	jmp	main
//*************************************
// other headline
//
head1_line1:
	movs	print_other,printer,1
	compd	"---/n",wstr_m3,77
	jnz	main_send_sig
//
// headline from gebsumm printout
//
	call	print_messim
	jmp	main_send_sig
//
//*********************************************************
state1_0:
	movs	print_other,printer,1
	call	pr_ticket_b
	jmp	state_0
//
//*********************************************************
//
t_ticket_eol:
	compd	"  |/n",wstr_m3,58
	jz     sk_10_state
	compd	"  !/n",wstr_m3,58
sk_10_state:
	ret
//*********************************************************
// state 10 ticketoutput
// line customer
//
state_10:
	call	t_ticket_eol
	jnz	state1_0
	writeb	wstr_m3,0,ticket_b
	movd	"011 ",input_state
//
// save hotel_name
	movs	wstr_m3,2,hotel_name,20
	jmp	main_send_sig
//*************************************
// ticket line with date
//
state_11:
	call	t_ticket_eol
	jnz	state1_0
	writeb	wstr_m3,0,ticket_b
	movd	"012 ",input_state
	jmp	main_send_sig
//*************************************
// ticket line empty line
//
state_12:
	call	t_ticket_eol
	jnz	state1_0
	writeb	wstr_m3,0,ticket_b
	movd	"013 ",input_state
	jmp	main_send_sig
//*************************************
// ticket line NAME
//
state_13:
	call	t_ticket_eol
	jnz	state1_0
	call	t_ti_name
	jnz	 test_st_17		 // test for Telefonzelle

	writeb	wstr_m3,0,ticket_b
	movd	"014 ",input_state
	jmp	main_send_sig
//
//*************************************
// first line of phone booth
//
test_st_17:
	call	t_ti_cabin_set
	jnz	state1_0
	movd	"017 ",input_state
	writeb	wstr_m3,0,ticket_b
	jmp	main_send_sig
//
//*************************************
// Phone_booth_ticket
// read as long as ticket into the buffer
//
state_17:
	call	t_ticket_eol
	jnz	state_l17
	writeb	wstr_m3,0,ticket_b
	jmp	main_send_sig
//
// last line of phone_booth
//
state_l17:
	compd	"---/n",wstr_m3,58
	jnz	state_p17
#ifdef werbung
	movd	werbetext,wstr_m3,35
#endif
	movs	print_phone_ticket,printer,1
//
state_p17:
	writeb	wstr_m3,0,ticket_b
	call	pr_ticket_b
	movd	"000 ",input_state
	jmp	main_send_sig
//
//*************************************
// ticket line Zimmernummer
// save extension number
//
state_14:
	call	t_ticket_eol
	jnz	state1_0
	call	t_ti_room
	jnz	state1_0
	movs	wstr_m3,34,extension_num,4
	writeb	wstr_m3,0,ticket_b
	movd	"015 ",input_state
	jmp	main_send_sig
//*************************************
// ticket line Sprache if checkin
//	    or Anzahl if checkout
//          or Vorkasse if checkout
//
state_15:
	call	t_ticket_eol
	jnz	state1_0
	call	t_ti_language
	jnz	test_checkout
	writeb	wstr_m3,0,ticket_b
//
	movd	"016 ",input_state
	jmp	main_send_sig
//
test_checkout:
	call	t_ti_deposit	//or number of communications
	jnz	test_anzahl
//
//        compd   language_de,language
//        jnz     test_depos_skip
//
// --------> calc Euro
        call    ticket_euro
test_depos_skip:
//
        writeb  wstr_m3,0,ticket_b
	movd	"020 ",input_state
	jmp	main_send_sig
//
test_anzahl:
	call	t_ti_number
        jnz     test_empty_line
//
        compd   language_de,language
        jnz     test_anz_skip
        movd    "Anzahl der Gespraeche :",wstr_m3,2
test_anz_skip:
//
        writeb  wstr_m3,0,ticket_b
	movd	"020 ",input_state
	jmp	main_send_sig
//*************************************
test_empty_line:
        compd   "|     ",wstr_m3,0
        jz     sk_e10_state
        compd   "!     ",wstr_m3,0
        jnz     state1_0
sk_e10_state:
	writeb	wstr_m3,0,ticket_b
// same state
        jmp     main_send_sig
//
//*************************************
// ticket checkin for extension stored in extension number
// wait for ticket last line
//
state_16:
	call	t_ticket_eol
	jnz	state_l16
//***********************************************
        compd   language_de,language
        jnz     state_16_skip
//
        compd   "Amts",wstr_m3,2
        jnz     tge_l11
        movd    "Amtsgespraeche :",wstr_m3,2
        jmp     state_16_skip
tge_l11:
//
        compd   "Vorkasse",wstr_m3,2
        jnz     tge_l11a
// --------> calc Euro
        call    ticket_euro
tge_l11a:
//
        compd   "Gespr",wstr_m3,2
        jnz     tge_l12
        movd    "Gespraechskosten :",wstr_m3,2
// --------> calc Euro
        call    ticket_euro
        jmp     state_16_skip
tge_l12:
//
        compd   "   inclusive",wstr_m3,2
        jnz     tge_l13
// --------> calc Euro
        call    ticket_euro
        jmp     state_16_skip
tge_l13:
//
        compd   "Anzahl",wstr_m3,2
        jnz     tge_l14
        movd    "Anzahl der Gespraeche :",wstr_m3,2
        jmp     state_16_skip
tge_l14:
//
        compd   "Danke f",wstr_m3,2
        jnz     tge_l15
        movd    "Danke fuer Ihren Besuch!",wstr_m3,2
        jmp     state_16_skip
tge_l15:
//
state_16_skip:
        writeb  wstr_m3,0,ticket_b
	jmp	main_send_sig
//
state_l16:
	compd	"---/n",wstr_m3,58
	jz	state_16skip
	writeb	wstr_m3,0,ticket_b
	call	pr_ticket_b
	movd	"000 ",input_state
	jmp	main_send_sig
//
state_16skip:
#ifdef werbung
	movd	werbetext,wstr_m3,35
#endif
	writeb	wstr_m3,0,ticket_b
	movs	print_ci_ticket,printer,1
//	  call	  pr_ticket_b
//
//*************************************
// last line of ticket received
// open dbs 2 for extension number
// save extension checkin
// and print all smdr records without delete
//
checkin_again:
	call	read_tln_dbs	// read extension configuration
	jnz	checkin_err	// extension not defined in DBS

        compd   "A",s11,_ext_type
        jnz     checkin1_skip
        movd    "R",s11,_ext_type   // change extension to room
checkin1_skip:
        compd   "255",s11,_tln_top      // smdr records?
	jz	checkin_no
//
// if check-in of a subscriber and the subscriber have some calls
// make a printout.
//
checkin_print:
	movd	"1",printer     // enable the printout for a ci ticket
	call	pr_ticket_b
//
	call	smdrhead1_print
        movs    s11,_tln_top,dbs_para,9
checkin_loop:
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	movs	dbs_str,_link_pointer,dbs_para,9
	compd	"255",dbs_str,_link_pointer,8
	jnz	checkin_loop
//
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
//
checkin_save:
	movd	"I",s11,_checkin_flag
	call	write_tln_dbs
	movd	"000 ",input_state
//
	call	pr_formfeed
//
	jmp	main_send_sig

//
checkin_no:
	compd	"0",printer
	jnz	checkin_1skip
	compd	"I",s11,_checkin_flag
	jnz	checkin_save
checkin_1skip:
	movd	"1",printer     // enable the printout for a ci ticket
	call	pr_ticket_b
	movs	msg_32015,wstr_m3,0,32	//" Keine Gespraeche!/n",wstr_m3,0
	call	pr_ticket
	jmp	checkin_save
//
checkin_err:
	movs	msg_48009,wstr_m3,0,48	//" Subscriber not found in EXT_DBS!/n",wstr_m3,0
	writeb	wstr_m3,0,ticket_b
	call	test_tln_free		// test if there is space in tln_dbs
	jz	ci_tln_insert
err_ci_insert:
	movs	msg_48010,wstr_m3,0,48	//" FATAL ERROR EXT_DBS is full!/n",wstr_m3,0
	writeb	wstr_m3,0,ticket_b
	movd	"1",printer
	call	pr_ticket_b
	call	pr_formfeed
	movd	"000 ",input_state
	jmp	main_send_sig

//
ci_tln_insert:
	call	ins_tln_room
	jnz	err_ci_insert
	movs	msg_48011,wstr_m3,0,48	//" Subscriber inserted as 'ROOM-EXTENSION'!/n",wstr_m3,0
	writeb	wstr_m3,0,ticket_b
	movd	"1",printer     // enable the printout for a ci ticket
	jmp	checkin_again


//*********************************************************
//*********************************************************
// Checkout ticket
//
// open dbs 2 tln data
// save status checkout
// calulate cost_colsed and clear cost_open
// print smdr records
// unlink tln_top and link free_pool_last
// until all records are printed
//
state_20:
// first wait for end of ticket
//
	compd	"---/n",wstr_m3,58
	jz	state_20skip
//
        compd   language_de,language
        jnz     st_20_skip
//
        compd   "Anz",wstr_m3,2
        jnz     tge_l201
        movd    "Anzahl der Gespraeche :",wstr_m3,2
        jmp     st_20_skip
tge_l201:
//
        compd   "Gesamt",wstr_m3,2
        jnz     tge_l202
// -----> calc Euro
        call    ticket_euro
        jmp     st_20_skip
tge_l202:
//
        compd   "   incl",wstr_m3,2
        jnz     tge_l203
// -----> calc Euro
        call    ticket_euro
        jmp     st_20_skip
tge_l203:
//
        compd   "Soll",wstr_m3,2
        jnz     tge_l204
// -----> calc Euro
        call    ticket_euro
        jmp     st_20_skip
tge_l204:
//
        compd   "Gutha",wstr_m3,2
        jnz     tge_l205
// -----> calc Euro
        call    ticket_euro
        jmp     st_20_skip
tge_l205:
//
st_20_skip:
        writeb  wstr_m3,0,ticket_b
	jmp	main_send_sig
state_20skip:
#ifdef	werbung
	movd	werbetext,wstr_m3,35
#endif
	writeb	wstr_m3,0,ticket_b
	movs	print_co_ticket,printer,1
//
//*************************************
// test if extension has smdr-data
//
	call	read_tln_dbs	// read extension configuration
	jnz	checkout_err
	compd	"255",s11,_tln_top      // smdr records?
	jz	checkout_no
	movd	"1",printer
	call	pr_formfeed

	call	pr_ticket_b

	movd	"/n",wstr_m3,0
	call	pr_ticket
	call	smdrhead1_print
//
checkout_loop:
	movs	s11,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	call	unlink_tln
	call	link_free
	compd	"255",s11,_tln_top
	jnz	checkout_loop
	movs	s11,_cost_closed,calc_p1,8
	movs	s11,_cost_open,calc_p2,8
	acall	add
	movs	calc_erg,s11,_cost_closed,8
	movd	"00000000",s11,_cost_open
//
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n!",wstr_m3,0
	call	print_smdrim
//
	call	pr_formfeed
//
checkout_save:
	movd	"O",s11,_checkin_flag
	call	write_tln_dbs
	movd	"000 ",input_state
//
	jmp	main_send_sig

//
checkout_no:
	call	pr_ticket_b
	movs	msg_32015,wstr_m3,0,32	//" Keine Gespraeche!/n",wstr_m3,0
	call	pr_ticket
	jmp	checkout_save
//
checkout_err:
	movd	"1",printer
	movs	msg_48009,wstr_m3,0,48	//" Subscriber not found in EXT-DBS!/n",wstr_m3,0
	writeb	wstr_m3,0,ticket_b
	call	pr_ticket_b
	call	pr_formfeed
	movd	"000 ",input_state
	jmp	main_send_sig
//
//*********************************************************
// print the ticket-buffer
//
pr_ticket_b:
	movs	wstr_m3,0,dhs2_save,150
        call    test_form_ff
pr_ticket_l:
	readb	wstr_m3,0,ticket_b
	jz	pr_ticket_e
	call	pr_ticket
	jmp	pr_ticket_l
pr_ticket_e:
	movs	dhs2_save,wstr_m3,0,150
	ret
//

//*********************************************************
//*********************************************************
// SMDR RECO
//
r311_smin:
        call    form_r311
        jmp     do_smdr_in
//
//*************************************
r312_smin:
        call    form_r312
        jmp     do_smdr_in
//
//*************************************
//
smdr_2dg_in:
	movs	wstr_m3,3,wstr_m3,2,4

smdr_in:
        call    form_r26_3dg
do_smdr_in:
        movd    "00000000",calc_erg
        movd    "00000000",geb_aktu
	movd	"         ",dhs2_cost
	movd	"/n",dhs2_cr_pos         // write end of reco
//
	movs	print_incomming,printer,1

	call	print_smdrim
	jmp	main_send_sig
//
//*********************************************************
//
r311_smout:
        call    form_r311
        jmp     do_smdr_out
//
//*************************************
r312_smout:
        call    form_r312
        jmp     do_smdr_out
//
//*************************************
smdr_2dg_out:
	movs	wstr_m3,3,wstr_m3,2,4

smdr_out:
        call    form_r26_3dg
do_smdr_out:
        call    save_smdr               // store smdr in cell
	jmp	main_send_sig
//*********************************************************
//*********************************************************
//
test_im_sign:
	case	im_sign,test_tf_sign
	setl	11,2
//
// command from channel 4
//
	in	wstr_m36,100
	movd	"Okay wait/n",wstr_m36,0
	out	wstr_m36,0,c4
//
// init commands
//
	compd	"init free_pool",wstr_m36,100
	jz	go_init_cell
	compd	"init ext_dbs",wstr_m36,100
	jz	go_init_tln
	compd	"init buffers",wstr_m36,100
	jz	go_buff_init
	compd	"set printers=",wstr_m36,100
	jz	go_set_printers
        compd   "set printer?=",wstr_m36,100
        jz      go_set_single_printer
        compd   "set hotel_name=",wstr_m36,100
	jz	go_set_hotel
	compd	"set linefeeds=",wstr_m36,100
	jz	go_set_linefeeds
	compd	"set ext ",wstr_m36,100
	jz	go_set_tln
        compd   "set euro=",wstr_m36,100
        jz      go_set_euro
//
// display commands
//
	compd	"disp ext_dbs",wstr_m36,100
	jz	go_tln_display
	compd	"disp config",wstr_m36,100
	jz	go_cfg_display
	compd	"disp ext ",wstr_m36,100
	jz	go_tln_n_display
	compd	"disp reco ",wstr_m36,100
	jz	go_reco_n_display
	compd	"cha ext ",wstr_m36,100
	jz	go_cha_tln
	compd	"del ext ",wstr_m36,100
	jz	go_del_tln
//
        compd   "emul ????/n",wstr_m36,100
        jz      go_emul
//
        movd    " command not found/n",wstr_m36,100
	out	wstr_m36,100,c4
//
main_message:
	movd	string_version,wstr_m36,100
	anss	wstr_m36,100
	jmp	main
//
// *****************************************************
test_tf_sign:
	setl	11,2
        sendsig ans_sign,c3
        jmp     main
//
//******************************************************
//******************************************************
//******************************************************
//******************************************************
//******************************************************
go_set_euro:
        compd   "set euro=",wstr_m36,100
        compd   "0",wstr_m36,109
        jz      set_euro
        compd   "1",wstr_m36,109
        jz      set_euro
        compd   "2",wstr_m36,109
        jz      set_euro
        compd   "3",wstr_m36,109
        jz      set_euro
        movd    " Error parameter/n",wstr_m36,100
	out	wstr_m36,100,c4
        jmp     main_message
set_euro:
        movs    wstr_m36,109,calc_euro,1
        jmp     main_message
//
//******************************************************
go_emul:
        movs    wstr_m36,105,dhs2_zi_status,4
        acall   read_dt
        movd    "  //  //   xx:xx  ",dhs2_date
        movs    dt_str_year,dhs2_year,2
        movs    dt_str_month,dhs2_month,2
        movs    dt_str_day,dhs2_day,2
        movs    dt_str_hour,dhs2_hour,2
        movs    dt_str_minute,dhs2_minute,2
        movd    string_version,wstr_m36,100
	anss	wstr_m36,100
        jmp     st_config
//
//******************************************************
//
//			   11111111112222222222333333
//		 012345678901234567890123456789012345
//
// init the dbs for extensions
// init the dbs for dataelements
// init all the buffers
//
go_init_cell:
//
        call    init_first
        call    init_buffer
        jmp     main_message
//
init_first:
// init the dbs for the data_elements
	clear	free_pool_first 	// string s12
	clear	last_date_betrieb	// string s11
	call	dbs_pool_init
	call	dbs_tln_init
	movd	"1",printers            // number of printers
        movd    printer_default,print_string
	movd	"00 ",language
	movd	"00 ",language_old
        movd    "00 ",page_lf_number
        movd    "   3 ",print_mark
              // print_mark
               // print_type
                // print_category
//               // convert to EURO
//                // enable print zerro summ
        movd    "GDC09Euro/n",first_run
        ret
//
go_buff_init:
        call    init_buffer
        jmp     main_message
//
init_buffer:
        call    init_b0
	call	init_b1
	call	init_b2
	call	init_b3
	call	init_b4
	call	init_b5
        ret
//
go_init_tln:
	call	dbs_tln_init
	jmp	main_message
//
go_tln_display:
	call	tln_display
	jmp	main_message
//
go_tln_n_display:
	movd	"2 0 ",dbs_para
	acall	pfirst_dbs
	movd	" EXTENSION CONFIGURATION /n",wstr_m36,0
	out	wstr_m36,0,c4
	movd	"     ",dbs_search_str
        movs    wstr_m36,109,dbs_search_str,4
	acall	find_dbs
	jz	disp_tln_n
	movd	" Extension not found in EXT-DBS!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
go_reco_n_display:
	compd	"??? ???/n",wstr_m36,111
	jnz	tln_err_para
	movd	"          ",dbs_para
	movs	wstr_m36,111,dbs_para,7
	acall	preco_dbs
	jnz	reco_err_reco
	acall	read_dbs
	movd	"/n",dbs_str,90
	out	dbs_str,0,c4
	jmp	main_message
//
reco_err_reco:
	movd	" ERROR record not found!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
disp_tln_n:
	acall	read_dbs
	out	dbs_str,0,c4
	jmp	main_message
//
go_cfg_display:
	call	cfg_display
	jmp	main_message
//
go_set_printers:
	compd	"???????????????/n",wstr_m36,113
	jz	printer_set
go_pr_error:
        movd    " ERROR on printer configuration!/n",wstr_m36,100
	out	wstr_m36,100,c4
	jmp	main_message
//
go_set_single_printer:
//                 012345678901234567890
//        compd   "set printer?=",wstr_m36,100
        compd   "a",wstr_m36,111
        jnz     skip_pr_a
        movs    wstr_m36,113,print_ci_ticket,1  //a
        jmp     main_message
skip_pr_a:
        compd   "b",wstr_m36,111
        jnz     skip_pr_b
        movs    wstr_m36,113,print_co_ticket,1  //b
        jmp     main_message
skip_pr_b:
        compd   "c",wstr_m36,111
        jnz     skip_pr_c
        movs    wstr_m36,113,print_phone_ticket,1       //c
        jmp     main_message
skip_pr_c:
        compd   "d",wstr_m36,111
        jnz     skip_pr_d
        movs    wstr_m36,113,print_room_state,1 //d
        jmp     main_message
skip_pr_d:
        compd   "e",wstr_m36,111
        jnz     skip_pr_e
        movs    wstr_m36,113,print_wakeup,1     //e
        jmp     main_message
skip_pr_e:
        compd   "f",wstr_m36,111
        jnz     skip_pr_f
        movs    wstr_m36,113,print_other,1      //f
        jmp     main_message
skip_pr_f:
        compd   "g",wstr_m36,111
        jnz     skip_pr_g
        movs    wstr_m36,113,print_incomming,1  //g
        jmp     main_message
skip_pr_g:
        compd   "h",wstr_m36,111
        jnz     skip_pr_h
        movs    wstr_m36,113,print_manuell,1    //h
        jmp     main_message
skip_pr_h:
        compd   "i",wstr_m36,111
        jnz     skip_pr_i
        movs    wstr_m36,113,print_auto,1       //i
        jmp     main_message
skip_pr_i:
        compd   "j",wstr_m36,111
        jnz     skip_pr_j
        movs    wstr_m36,113,print_single_ticket,1      //j
        jmp     main_message
skip_pr_j:
        compd   "k",wstr_m36,111
        jnz     skip_pr_k
        movs    wstr_m36,113,print_err,1        //k
        jmp     main_message
skip_pr_k:
        compd   "l",wstr_m36,111
        jnz     skip_pr_l
        movs    wstr_m36,113,print_immediate,1  //l
        jmp     main_message
skip_pr_l:
        compd   "m",wstr_m36,111
        jnz     skip_pr_m
        movs    wstr_m36,113,print_m,1          //m
        jmp     main_message
skip_pr_m:
        compd   "n",wstr_m36,111
        jnz     skip_pr_n
        movs    wstr_m36,113,print_zusatzkosten,1       //n
        jmp     main_message
skip_pr_n:
        compd   "o",wstr_m36,111
        jnz     skip_pr_o
        movs    wstr_m36,113,form_feed_printers,1       //o
        jmp     main_message
skip_pr_o:
        jmp     go_pr_error
//
printer_set:
	movs	wstr_m36,113,print_string,15
	jmp	main_message
//
//
go_set_hotel:
	movd	"                    ",hotel_name
	movs	wstr_m36,115,hotel_name,20
	replace "/n ",hotel_name,20
	jmp	main_message
//
go_set_linefeeds:
	movd	"    ",page_lf_number
	movs	wstr_m36,114,page_lf_number,2
	replace "/n ",page_lf_number,3
	jmp	main_message
//
//******************************************
// tln set (ins)
//     del
//     change
//
go_set_tln:
        //       nnnnRSM7Nxxxx
        compd   "?????????xxxx",wstr_m36,108
	jnz	tln_err_para
	movs	wstr_m36,108,dbs_search_str,4
	movd	"002 0 ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jz	tln_err_found
	call	test_tln_free
	jnz	tln_err_nospace
	call	find_ins_point
	jnz	tln_err_ins
	movs	wstr_m36,108,dbs_str,0,13
	call	dbs_write
	call	ins_write
	jnz	tln_err_ins
	jmp	main_message
//
//*************************************
// delete a extension
//
go_del_tln:
	movd	"     ",dbs_search_str
        movs    wstr_m36,108,dbs_search_str,4
	compd	"999",dbs_search_str
	jz	error_not_possible
	movd	"002 0 ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	tln_err_notfound
//
	acall	read11_dbs
	compd	"255",s11,_tln_top
	jz	go_del_1tln
	movs	dbs_search_str,extension_num,4
	call	pr_tln_cl
	movd	"002 0 ",dbs_para
	movs	extension_num,dbs_search_str,4
	acall	pfirst_dbs
	acall	find_dbs
go_del_1tln:
	call	del_write
	jnz	tln_err_ins
	jmp	main_message
//
//*************************************
// change the configuration of an extension
//
go_cha_tln:
        compd   "???????????xx",wstr_m36,108
	jnz	tln_err_para
	movs	wstr_m36,108,dbs_search_str,4
	compd	"999",dbs_search_str
	jz	error_not_possible
	movd	"002 0 ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	tln_err_notfound
	acall	read11_dbs
	movs	wstr_m36,112,s11,_ext_type,9
	acall	write11_dbs
	jmp	main_message
//
//
tln_err_ins:
	movd	"ERROR on insert\delete of extension!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
tln_err_nospace:
	movd	"ERROR no space in EXT-DBS!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
tln_err_notfound:
	movd	"Extension not found in EXT-DBS!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
error_not_possible:
	movd	"ERROR do not change or delete extension 999 !/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
tln_err_found:
	movd	"Extension allready defined!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
tln_err_para:
	movd	"ERROR in parameter!/n",wstr_m36,0
	out	wstr_m36,0,c4
	jmp	main_message
//
//********************************************************************
//********************************************************************
// subroutinen
//********************************************************************
//********************************************************************
// Save a formated SMDR Reco in the TLN-DBS
// input:       wstr_m3,0 input data_string to save
//              calc_erg: the cost of the call
//              geb_aktu: the cost of the call
save_smdr:
	call	form_erg_cost
	movd	"/n",dhs2_cr_pos         // write end of reco
//
	movs	dhs2_date,date_last,9	// save last date
//****************************************************
// test if printing
// save the string of the smdr-reco
//
	movs	dhs2_in,0,dhs2_save,100
//
	movs	print_auto,printer,1
        compd   "0",printer             // if printauto =0 no automatic print
        jz      cs_saveit
        movd    "0",print_mark          // no print messages
//
	comps	date_last,old_date,6	// day and month equal?
	jz	cs_saveit
	comps	date_last_month,old_date_month,2
	jz	cs_test_day
//
// printout the extension configurated as BAR "B"
// and clear the records
//
        movd    "B  ",dbs_search_str    //search for barphone
	movd	"002 1     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	nom_barphone
//
	call	print_trennl
	movs	msg_64011,wstr_m3,0,64	//" Taeglicher Gebuehrenausdruck fuer Bartelefon(e) und Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	call	print_trennl
	call	pr_bar_clear
//
nom_barphone:
        movd    "M  ",dbs_search_str    //search for administration monthly
	movd	"002 3     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	nod_adminphone
//
	call	print_trennl
	movs	msg_80004,wstr_m3,0,80	//" Monatlicher Gebuehrenausdruck fuer Betriebsteilnehmer und Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	call	print_trennl
	call	pr_adminm_clear
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
        call    pr_formfeed
	jmp	cs_saveit
//
cs_test_day:
	comps	date_last_day,old_date_day,2
	jz	cs_saveit
//
        movd    "B  ",dbs_search_str    //search for Barphone
	movd	"002 1     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	nod_barphone
//
	call	print_trennl
	movs	msg_64011,wstr_m3,0,64	//" Taeglicher Gebuehrenausdruck fuer Bartelefon(e) und Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	call	print_trennl
	call	pr_bar_clear
nod_barphone:
        movd    "D  ",dbs_search_str    //search for administration daily
	movd	"002 3     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	nod_adminphone
//
	call	print_trennl
	movs	msg_80005,wstr_m3,0,80	//" Taeglicher Gebuehrenausdruck fuer Betriebsteilnehmer und Abrechnung!/n",wstr_m3,0
	call	print_smdrim
	call	print_trennl
	call	pr_admind_clear
	call	print_trennl
	movs	msg_32010,wstr_m3,0,32	//" ENDE DER LISTE!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
nod_adminphone:
//
cs_saveit:
	movs	date_last,old_date,9
//
// restore the smdr_string
//
	movs	dhs2_save,dhs2_in,0,100
//****************************************************
// **************************
// now open dbs for tln and search for that extension
//
tln_dbs_search:
	movs	dhs2_tln_num,dbs_search_str,4
	movd	"002 0     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	tln_not_found
	acall	read11_dbs
	acall	getr_dbs
	movs	dbs_para,tln_pointer,9
//
//***************************
// calc open cost sum
//
	movs	geb_aktu,calc_p2,8
	movs	s11,_cost_open,calc_p1,8
	acall	add
	movs	calc_erg,s11,_cost_open,8
//
//***************************
//
        compd   "N",s11,_gen_save
        jz      skip_save
//
        call    write_smdr      //save smdr-data in cell
	jnz	err_smdr_save
//
skip_save:
//
//***************************
// test aktion for extension
//
	movs	print_immediate,printer,1
//
	compd	"R",s11,_ext_type
	jz	room_tln
	compd	"P",s11,_ext_type
	jz	phone_booth
	compd	"B",s11,_ext_type
	jz	bar_tln
//***********************************************
// if extension = Administration
// all the other are administartion extension
//
	compd	"I",s11,_print_flag
        cz      admin_i_do
        compd   "T",s11,_print_flag
        cz      admin_t_do
        jmp     csave_smdr
//
admin_i_do:
        call    print_smdrim
        ret
//
admin_t_do:
        call    single_ticket
        ret
//
//***************************
csave_smdr:
	movs	tln_pointer,dbs_para,9
	acall	preco_dbs
	acall	write11_dbs
	ret
//
//*********************************************************
//
room_tln:
	compd	"I",s11,_print_flag
	cz	print_smdrim
        compd   "T",s11,_print_flag
        cz      room_t_do
//
	jmp	csave_smdr
//
room_t_do:
        call    single_ticket
        ret
//
phone_booth:
	compd	"I",s11,_print_flag
	cz	print_smdrim
        compd   "T",s11,_print_flag
        cz      phone_t_do
//
	jmp	csave_smdr
//
phone_t_do:
        call    single_ticket
        ret
//
bar_tln:
	compd	"I",s11,_print_flag
        cz      print_smdrim
        compd   "T",s11,_print_flag
        cz      bar_t_do
//
	jmp	csave_smdr
//
bar_t_do:
        call    single_ticket
        ret
//***********************************************
// extension not found in DBS2
// try to insert the extension number
// as administration extension
//
tln_not_found:
	movs	print_err,printer,1
//
	call	print_smdrim
	movs	wstr_m3,0,wstr_m3,100,85	// save the smdr data
	movs	msg_48009,wstr_m3,0,48	//" Subscriber not found in EXT-DBS!/n"
	call	print_smdrim
	call	test_tln_free		// test if there is space in tln_dbs
	jz	tln_insert1
err_tln_insert:
	movs	msg_48010,wstr_m3,0,48	//" FATAL ERROR EXT-DBS is full!/n"
	call	print_smdrim
	ret
//
tln_insert1:
	call	ins_tln_admin
	jnz	err_tln_insert
	movs	msg_48012,wstr_m3,0,48	//" Subscriber inserted as 'ADMIN-EXTENSION'!/n"
	call	print_smdrim
	movs	wstr_m3,100,wstr_m3,0,85	// restore smdr
	jmp	tln_dbs_search
//*************************************
err_smdr_save:
	call	print_smdrim
	movs	msg_48013,wstr_m3,0,48	//" FATAL ERROR FREE_POOL_BUFFER FULL!!!/n",wstr_m3,0
	call	print_smdrim
	call	pr_formfeed
	ret





//************************************************************************
//************************************************************************
// printout all extension with configuration "A" and "M"
// (on month changing print a list for all extension)
// send the list to the printer2
// at the end write a line with the total sum of the calls
// if the extension has no calls send a line with "Keine Gespraeche!/n"
//
pr_adminm_clear:
	movd	"A  ",dbs_search_str    //search for administration
	movd	"002 1     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	pr_amcl_err
//
	movd	"00000000",geb_total

pr_amcl_loop:
	acall	read11_dbs
        compd   "M",print_type          //if type of print is manuel
        jz      pr_adm_1
        compd   "M",s11,_print_periode
        jz      pr_adm_1
        compd   "D",s11,_print_periode
        jnz     pr_amcl_next
pr_adm_1:
        acall   getr_dbs
	movs	dbs_para,tln_pointer,9	// save pointer to dbs
	compd	"255",s11,_tln_top      // smdr records?
	jz	pr_amcl_no_calls
pr_amcl_l1:
	movs	s11,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	call	unlink_tln
	call	link_free
	compd	"255",s11,_tln_top
	jnz	pr_amcl_l1
//
pr_amcl_sum:
        call    print_sum
	call	calc_total_sum
	call	calc_closed_sum
//
	movs	tln_pointer,dbs_para,9
	acall	preco_dbs
	acall	write11_dbs	// save extension
pr_amcl_next:
	acall	pnext_dbs
	movd	"002 1     ",dbs_para
	acall	find_dbs	// search next admin
	jz	pr_amcl_loop
//
// end of printout
// print the total summ
//
	call	print_ges
	ret
//
pr_amcl_no_calls:
        compd   "M",print_type          //if type of print is manuel
        jz      pr_amcl_sum
        jmp     pr_amcl_next
//
pr_adcl_err:
pr_amcl_err:
	movs	msg_64012,wstr_m3,0,64	//" Keine ADMINISTRATIONS-TEILNEHMER definiert!!!/n",wstr_m3,0
	call	print_smdrim
	ret
//
//************************************************************************
// printout all extension with configuration "A" and "D"
// ( all extensions with printout per day)
// send the list to the printer2
// at the end write a line with the total sum of the calls
// if the extension has no calls send a line with "Keine Gespraeche!/n"
//
pr_admind_clear:
	movd	"A  ",dbs_search_str    //search for administration
	movd	"002 1     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	pr_adcl_err
//
	movd	"00000000",geb_total

pr_adcl_loop:
	acall	read11_dbs
	compd	"D",s11,_print_periode
	jnz	pr_adcl_next
	acall	getr_dbs
	movs	dbs_para,tln_pointer,9	// save pointer to dbs
	compd	"255",s11,_tln_top      // smdr records?
	jz	pr_adcl_no_calls
pr_adcl_l1:
	movs	s11,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	call	unlink_tln
	call	link_free
	compd	"255",s11,_tln_top
	jnz	pr_adcl_l1
	call	print_sum
	call	calc_total_sum
	call	calc_closed_sum
//
	movs	tln_pointer,dbs_para,9
	acall	preco_dbs
	acall	write11_dbs	// save extension
pr_adcl_next:
	acall	pnext_dbs
	movd	"002 1     ",dbs_para
	acall	find_dbs	// search next admin
	jz	pr_adcl_loop
//
// end of printout
// print the total summ
//
	call	print_ges
	ret
//
pr_adcl_no_calls:
	jmp	pr_adcl_next
//
//*******************************************************************
// Printout the bar-extensions
// write a header-line	   (print2_messim)
// ( Gebuehrenliste Bartelefon(e) )
// printout geb-header-line (print2_smdrim)
// printout the smdr-data and clear
// printout the sum of the bar-phone
// printout a hyphen
// printout thze next phone
// after the last phone printout the totalsum
// and a hyphen
//*******************************************************************
// if the extension has no calls send a line with "Keine Gespraeche!/n"
//
pr_bar_clear:
	movd	"B  ",dbs_search_str    //search for administration
	movd	"002 1     ",dbs_para
	acall	pfirst_dbs
	acall	find_dbs
	jnz	pr_barcl_err
//
	movd	"00000000",geb_total
//
pr_barcl_loop:
	acall	read11_dbs
	acall	getr_dbs
	movs	dbs_para,tln_pointer,9	// save pointer to dbs
	compd	"255",s11,_tln_top      // smdr records?
	jz	pr_barcl_no_calls
pr_barcl_l1:
	movs	s11,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	call	unlink_tln
	call	link_free
	compd	"255",s11,_tln_top
	jnz	pr_barcl_l1
pr_barcl_prsum:
        call    print_sum
	call	calc_total_sum
	call	calc_closed_sum
//
	movs	tln_pointer,dbs_para,9
	acall	preco_dbs
	acall	write11_dbs	// save extension
pr_barcl_next:
	acall	pnext_dbs
	movd	"002 1     ",dbs_para
	acall	find_dbs	// search next admin
	jz	pr_barcl_loop
//
// end of printout
// print the total summ
//
	call	print_ges
	ret
//
pr_barcl_no_calls:
        compd   "M",print_type          //if type of print is manuel
        jz      pr_barcl_prsum
        movd    " BAR-Telefon            keine Gespraeche/n",wstr_m3,0
	movs	s11,_tln,wstr_m3,14,3
	call	print_smdrim
	call	print_trennl
	jmp	pr_barcl_next
//
pr_barcl_err:
	movs	msg_64013,wstr_m3,0,64	//" Kein(e) BAR-Telefon(e) definiert!!!/n",wstr_m3,0
	call	print_smdrim
	ret
//
//*********************************************************
//*********************************************************
// Print all the records of a extension
// on printer without clearing
// input:	extension_num = extension number
//
pr_tln_nocl:
	call	read_tln_dbs	// read extension configuration
	jnz	pr2_nocl_err

pr_tln_s11_nocl:
	compd	"255",s11,_tln_top      // smdr records?
	jz	pr2_nocl_noreco
	movs	s11,_tln_top,dbs_para,9
pr2_nocl_loop:
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	movs	dbs_str,_link_pointer,dbs_para,9
	compd	"255",dbs_str,_link_pointer,8
	jnz	pr2_nocl_loop
//
pr2_nocl_l1:
        call    print_sum
//
	ret
//
pr2_nocl_noreco:
        compd   "M",print_type          //if type of print is manuel
        jz      pr2_nocl_l1
	compd	"0",print_mark
	jz	pr2_nocl_exit
	movs	msg_32015,wstr_m3,0,32	//" Keine Gespraeche!/n",wstr_m3,0
	call	print_smdrim
pr2_nocl_exit:
	ret
//
pr2_nocl_err:
//	  movd	  " Teilnehmer nicht gefunden in TLN_DBS!/n",wstr_m3,0
//	  call	  print2_smdrim
	ret
//***********************************************
//*********************************************************
// Print all the records of a extension
// on printer with clearing and calculation the closed_sum
// input:	extension_num = extension number
//
pr_tln_cl:
	call	read_tln_dbs	// read extension configuration
	jnz	pr2_cl_err

	compd	"255",s11,_tln_top      // smdr records?
	jz	pr2_cl_noreco
pr2_cl_loop:
	movs	s11,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	dbs_str,_smdr_data,wstr_m3,0,82
	call	print_smdrim
	call	unlink_tln
	call	link_free
	compd	"255",s11,_tln_top
	jnz	pr2_cl_loop
//
pr2_cl_prsum:
        call    print_sum
	call	calc_closed_sum
//
	call	write_tln_dbs
	ret
//
pr2_cl_noreco:
        compd   "M",print_type          //if type of print is manuel
        jz      pr2_cl_prsum
        compd   "0",print_mark
	jz	pr2_cl_exit
	movs	msg_32015,wstr_m3,0,32	//" Keine Gespraeche!/n",wstr_m3,0
	call	print_smdrim
pr2_cl_exit:
	ret
//
pr2_cl_err:
//	  movd	  " Teilnehmer nicht gefunden in TLN_DBS!/n",wstr_m3,0
//	  call	  print2_smdrim
	ret
//***********************************************
//***********************************************
//***********************************************
form_erg_cost:
	compd	"00000000",calc_erg
	jnz	form_erg_cost1
        movd    "     ",calc_erg
	jmp	form_erg_cost2
form_erg_cost1:
	acall	cut_lz
        replace " 0",calc_erg_4dg,4
form_erg_cost2:
        movs    calc_erg,dhs2_cost_1,5
//
#ifdef	comma
	movd	",",dhs2_dot
#else
	movd	".",dhs2_dot
#endif
        movs    calc_erg_3dg,dhs2_gr,2
	ret
//
//***********************************************
//
print_sum:
	call	load_def80
        compd   "1",print_zerro
        jz      print_do_sum
        compd   "00000000",s11,_cost_open
        jnz     print_do_sum
        ret
print_do_sum:
//                                         01234567890123456789
        movs    msg_20003,wstr_m3,0,20  //" TLN .         SUMME",wstr_m3,0
        movs    s11,_tln,wstr_m3,5,4    // setup extension number
        movs    s11,_cost_open,calc_erg,8
	call	form_erg_cost
	movd	"/n",dhs2_cr_pos         // write end of reco
        compd   "0",calc_euro
        jz      print_do_ats
        compd   "1",calc_euro
        jz      print_do_ats
//
        movs    msg_03002,wstr_m3,_pos_ats_name,3 //"EUR"
        compd   "2",calc_euro
        jnz     skip_print_sum
//
        movs    wstr_m3,_dhs2_cost,param_1,9    //load input parameter
        call    euro_to_ats
        movs    param_ergr10,wstr_m3,_pos_euro_value,10
        movs    msg_03001,wstr_m3,_pos_euro_name,3 //"ATS"
//
        jmp     skip_print_sum
//
print_do_ats:
        movs    msg_03001,wstr_m3,_pos_ats_name,3 //"ATS"
//-------> calc euro
//
        compd   "1",calc_euro
        jnz     skip_print_sum
        movs    wstr_m3,_dhs2_cost,param_1,9    //load input parameter
        call    ats_to_euro
        movs    param_ergr10,wstr_m3,_pos_euro_value,10
        movs    msg_03002,wstr_m3,_pos_euro_name,3
skip_print_sum:
        call    print_smdrim
	call	print_trennl
	ret
//
//***********************************************
//
calc_total_sum:
calc_total_open:
	movs	s11,_cost_open,calc_p1,8
	movs	geb_total,calc_p2,8
	acall	add
	movs	calc_erg,geb_total,8
	ret
//
//*******************************************************************
calc_total_closed:
	movs	s11,_cost_closed,calc_p1,8
	movs	geb_total,calc_p2,8
	acall	add
	movs	calc_erg,geb_total,8
	ret
//
//***********************************************
//
calc_closed_sum:
	movs	s11,_cost_open,calc_p2,8
	movs	s11,_cost_closed,calc_p1,8
	acall	add
	movs	calc_erg,s11,_cost_closed,8
	movd	"00000000",s11,_cost_open
	ret
//
//***********************************************
//
print_ges:
	compd	"00000000",geb_total
	jz	print2_eges
	call	load_def80
	movs	msg_20004,wstr_m3,0,20	//" GESAMTSUMME       "
	movs	geb_total,calc_erg,8
	call	form_erg_cost
	movd	"/n",dhs2_cr_pos         // write end of reco
//
        compd   "0",calc_euro
        jz      print_ges_ats
        compd   "1",calc_euro
        jz      print_ges_ats
//
        movs    msg_03002,wstr_m3,_pos_ats_name,3 //"EUR"
        compd   "2",calc_euro
        jnz     skip_print_ges
//
        movs    wstr_m3,_dhs2_cost,param_1,9    //load input parameter
        call    euro_to_ats
        movs    param_ergr10,wstr_m3,_pos_euro_value,10
        movs    msg_03001,wstr_m3,_pos_euro_name,3 //"ATS"
//
        jmp     skip_print_ges
//
print_ges_ats:
        movs    msg_03001,wstr_m3,_pos_ats_name,3 //"ATS"
//-------> calc euro
//
        compd   "1",calc_euro
        jnz     skip_print_ges
        movs    wstr_m3,_dhs2_cost,param_1,9    //load input parameter
        call    ats_to_euro
        movs    param_ergr10,wstr_m3,_pos_euro_value,10
        movs    msg_03002,wstr_m3,_pos_euro_name,3
skip_print_ges:
//
        call    print_smdrim
	call	print_trennl
print2_eges:
	ret
//
//*******************************************************************
load_h60:
  movd    "-------------------------------------------------------------/n",wstr_m3,0
  ret
//
//
//*******************************************************************
load_def60:
  movd    "|                                                           |/n",wstr_m3,0
  ret
//
//
//*******************************************************************
load_def80:
	movd	"                                                                               /n",wstr_m3,0
	ret
//
//
//*******************************************************************
//
print_trennl:
	call	line_fill_m3
	call	print_smdrim
	ret
//
//*******************************************************************
// print_smdrim
//
// send a printout to the associated printer
// if def printers = 2
//    send the printout to printer_2
// elseif printers=1
//    send the printout to printer_1 (out_b)
// elseif printers=9
//	save reco
// endif
//
print_smdrim:
// select printer
//
	compd	"1",printers
	jz	send_to_pr1
	compd	"2",printers
	jz	send_to_pr2
	compd	"9",printers
	jz	send_to_save
	ret
//
//*************************************
//
send_to_save:
	call	save_smdr
	ret
//
//*************************************
//
send_to_pr2:
check2_head:
	compc	page2_state,2
	jz	check2_length
//
new_page2:
	call	ff2_printer
	call	smdrhead2_print
//
check2_length:
	compc	page2_line,p_length
	jz	new_page2
//
	call	print2_m3
	ret
//
//*************************************
//
send_to_pr1:
check1_head:
	compc	page1_state,2
	jz	check1_length
//
new_page1:
	call	ff1_printer
	call	smdrhead1_print
//
check1_length:
	compc	page1_line,p_length
	jz	new_page1
//
	call	print1_m3
	ret
//
//*************************************
//
//*************************************
// print_messim
//
// send a printout to the associated printer
//   without a header
// pagex_state = 4
// if def printers = 2
//    send the printout to printer_2
// elseif printers=1
//    send the printout to printer_1 (out_b)
// endif
//
print_messim:
// select printer
//
	compd	"1",printers
	jz	send_p1_mess
	compd	"2",printers
	jz	send_p2_mess
	ret
//
//*************************************
//
send_p2_mess:
	compc	page2_state,4
	jz	check2_mess_length
//
new_page2_mess:
	call	ff2_printer
	setc	page2_state,4	// printer to mess mode
//
check2_mess_length:
	compc	page2_line,p_length
	jz	new_page2_mess
//
#ifdef debug_l1
	movd	" modul_3_call_print2_m3/n",wstr_m36,200
	out	wstr_m36,200,c4
#endif
	call	print2_m3

	ret
//
//*************************************
//
send_p1_mess:
	compc	page1_state,4
	jz	check1_mess_length
//
new_page1_mess:
	call	ff1_printer
	setc	page1_state,4	// printer to mess mode
//
check1_mess_length:
	compc	page1_line,p_length
	jz	new_page1_mess
//
	call	print1_m3
	ret
//
//*************************************
//
/*****
pr1_smdr:
	compc	page1_state,2
	jz	check1_smdr_length
	call	smdrhead1_print
	jmp	check1_smdr_length
//
new_page1_smdr:
	call	ff1_printer
	call	smdrhead1_print
//
check1_smdr_length:
	compc	page1_line,p_length
	jz	new_page1_smdr
//
	call	print1_m3
	ret

*****/

//
//*************************************
//*************************************
pr_ticket:
// select printer
//
	compd	"1",printers
	jz	pr1_ticket
	compd	"2",printers
	jz	pr2_ticket
	ret
//
//*************************************
// Print a ticket to printer 1
//
pr2_ticket:
        compc   page2_state,3   // is allready page in ticket mode
        jz      pr2_go_ticket
//
//*************************************
// print a form feed
//
new_pr2_ticket:
        call    ff2_printer
        setc    page2_state,3   // printer to ticket mode
//
pr2_go_ticket:
        compc   page2_line,p_length
        jz      new_pr2_ticket
//
        call    print2_m3
	ret
//*********************************************************
//
pr1_ticket:
	compc	page1_state,3	// is allready page in ticket mode
	jz	pr1_go_ticket
//
//*************************************
// print a form feed
//
new_pr1_ticket:
	call	ff1_printer
	setc	page1_state,3	// printer to ticket mode
//
pr1_go_ticket:
	compc	page1_line,p_length
	jz	new_pr1_ticket
//
	call	print1_m3
	ret

//***********************************************
pr_status_head:
	call	print_trlmess
//	movd				  "-------------------------------------------------------------------------------/n",wstr_m3,0
	movs	msg_80001,wstr_m3,0,80	//"| Zimmernummer    | Checkout - in        | Status                             |/n",wstr_m3,0
	call	print_messim
//	movd				  "-------------------------------------------------------------------------------/n",wstr_m3,0
	call	print_trlmess
	movd	"                                                                                /n",wstr_m3,0
	ret
//***********************************************
//*************************************
// pr_formfeed
//
// send a formfeed to the associated printer
// if def printers = 2
//    send the formfeed to printer_2
// else
//    send the formfeed to printer_1 (out_b)
// endif
//
pr_formfeed:
// select printer
// how manny printers
//
	compd	"1",printers
	jz	ff1_printer
	compd	"2",printers
	jz	ff2_printer
	ret
//
//*************************************
//*************************************
//
ff1_printer:
	movc	page1_line,page_calc_sub	// page counter to string
	comps	page_calc1,page_calc_sub,3	// line_page = line last ff
	jz	eff1_printer
	compc	page1_line,p_length		// on end of the page send FF
        jz      do_ff1_ff                       // skip_zone
	movc	page_lf_number,page_lf_cnt	// number of lf
	compc	page_lf_cnt,0			// if number of lf=0 send FF
	jz	do_ff1_ff
	movd	"/n",wstr_m36,100
go_lff1_ff:
	call	print1_m36
	compc	page1_line,p_length		// on end of the page send FF
	jz	do_ff1_ff
	decc	page_lf_cnt
	jnz	go_lff1_ff
	movc	page1_line,page_calc_sub
	movc	page_calc_sub,page_lf_cnt	// test rest of the page
test_lff1_ff:
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff1_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff1_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff1_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff1_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff1_ff
//
	jmp	eff1_printer
//
do_ff1_ff:
        compd   "1",form_feed_printers
        jz      ff1_skip
        compd   "3",form_feed_printers
        jz      ff1_skip
        movd    "^L/n",wstr_m36,100
        call    print1_m36
ff1_skip:
	setc	page1_line,1		// line 1
	setc	page1_state,1		// new page
//
eff1_printer:
	movc	page1_line,page_calc1	// copy position
	ret
//
smdrhead1_print:
	movd	geb_head,wstr_m36,100
	call	print1_m36
	movs	msg_80002,wstr_m36,100,80
	call	print1_m36
	movs	msg_80003,wstr_m36,100,80
        compd   "0",calc_euro
        jz      skip_smdrhe
        compd   "1",calc_euro
        jz      skip_smdrhe
        movs    msg_03002,wstr_m36,170,3 //"EUR"
skip_smdrhe:
        call    print1_m36
	movd	geb_head,wstr_m36,100
	call	print1_m36
	setc	page1_state,2		// page_state 2 (smdr head print)
	ret
//*************************************
//*************************************
//
ff2_printer:
	movc	page2_line,page_calc_sub	// page counter to string
	comps	page_calc2,page_calc_sub,3	// line_page = line last ff
	jz	eff2_printer
	compc	page2_line,p_length		// on end of the page send FF
	jz	do_ff2_ff
	movc	page_lf_number,page_lf_cnt	// number of lf
	compc	page_lf_cnt,0			// if number of lf=0 send FF
	jz	do_ff2_ff
	movd	"/n",wstr_m36,100
go_lff2_ff:
	call	print2_m36
	compc	page2_line,p_length		// on end of the page send FF
	jz	do_ff2_ff
	decc	page_lf_cnt
	jnz	go_lff2_ff
	movc	page2_line,page_calc_sub
	movc	page_calc_sub,page_lf_cnt	// test rest of the page
test_lff2_ff:
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff2_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff2_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff2_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff2_ff
//
	incc	page_lf_cnt
	compc	page_lf_cnt,p_length		 // on end of the page send FF
	jz	do_ff2_ff
//
	jmp	eff2_printer
//
do_ff2_ff:
        compd   "2",form_feed_printers
        jz      ff2_skip
        compd   "3",form_feed_printers
        jz      ff2_skip
	movd	"^L/n",wstr_m36,100
	call	print2_m36
ff2_skip:
	setc	page2_line,1		// line 1
	setc	page2_state,1		// new page
	movd	"001 ",page_calc2
//
eff2_printer:
	movc	page2_line,page_calc2
	ret
//
smdrhead2_print:
	movd	geb_head,wstr_m36,100
	call	print2_m36
	movs	msg_80002,wstr_m36,100,80
	call	print2_m36
	movs	msg_80003,wstr_m36,100,80
        compd   "0",calc_euro
        jz      skip_smdrh2
        compd   "1",calc_euro
        jz      skip_smdrh2
        movs    msg_03002,wstr_m36,170,3 //"EUR"
skip_smdrh2:
	call	print2_m36
	movd	geb_head,wstr_m36,100
	call	print2_m36
	setc	page2_state,2		// page_state 2 (smdr head print)
	ret


//
//***********************************************
print1_m36:
#ifdef debug_output
	out	wstr_m36,100,c4
#endif
print11_m36:
	writeb	wstr_m36,100,printer_1
	jz	eprint1
	wait	tx_sign
	jmp	print11_m36
//
eprint1:
	incc	page1_line
	sendsig ans_sign,c0
	wait	tx_sign
	ret
//
//***********************************************
print1_m3:
#ifdef debug_output
	out	wstr_m3,0,c4
#endif
print12_m3:
	writeb	wstr_m3,0,printer_1
	jz	eprint1
	wait	tx_sign
	jmp	print12_m3
//
//***********************************************
print2_m36:
#ifdef debug_output
	out	wstr_m36,100,c4
#endif
print21_m36:
	writeb	wstr_m36,100,printer_2
	jz	eprint2
	wait	tx_sign
	jmp	print21_m36
//
eprint2:
	incc	page2_line
	sendsig ans_sign,c2
	wait	tx_sign
	ret
//
//***********************************************
print2_m3:
#ifdef debug_output
	out	wstr_m3,0,c4
#endif
print22_m3:
	writeb	wstr_m3,0,printer_2
	jz	eprint2
	wait	tx_sign
	jmp	print22_m3
//







//*************************************
//*************************************
// read extension dbs to s11
// and save pointer in "tln_pointer"
// input: ext_num = rufnummer
read_tln_dbs:
	movd	"002 0     ",dbs_para
	movs	extension_num,dbs_search_str,4
	acall	pfirst_dbs
	acall	find_dbs
	jz	found_read_tln
	ret
found_read_tln:
	acall	read11_dbs
	acall	getr_dbs
	movs	dbs_para,tln_pointer,9
	jmp	z_ret


//*************************************
// write extension dbs from s11
// and to pointer in "tln_pointer"
//
write_tln_dbs:
	movs	tln_pointer,dbs_para,9
	acall	preco_dbs
	acall	write11_dbs
	ret








//
//*************************************
// write smdr to cell_dbs
//
write_smdr:
	compd	"Gebuhrenzuordnung",dhs2_extern
	jnz	write_1_smdr
//
// search for extension type "P"
//
	movd	"002 1     ",dbs_para
	movd	"P",dbs_search_str
	acall	pfirst_dbs
search_p_loop:
	acall	find_dbs
	jnz	wr_p_not_found
	acall	read_dbs
	acall	getr_dbs
	movs	dbs_para,tln_point_sub,9
	call	search_reco
	jz	z_ret			// record found and linked to extension
					// and unlinked from phone extension
	movs	tln_point_sub,dbs_para,9
	acall	preco_dbs
	acall	pnext_dbs
	movd	"002 1     ",dbs_para
	movd	"P",dbs_search_str
	jmp	search_p_loop
wr_p_not_found:
//
// search for extension type "B"
//
	movd	"002 1     ",dbs_para
	movd	"B",dbs_search_str
	acall	pfirst_dbs
search_b_loop:
	acall	find_dbs
	jnz	wr_b_not_found
	acall	read_dbs
	acall	getr_dbs
	movs	dbs_para,tln_point_sub,9
	call	search_reco
	jz	z_ret			// record found and linked to extension
					// and unlinked from phone extension
	movs	tln_point_sub,dbs_para,9
	acall	preco_dbs
	acall	pnext_dbs
	movd	"002 1     ",dbs_para
	movd	"B",dbs_search_str
	jmp	search_b_loop
wr_b_not_found:
//
write_1_smdr:
	call	unlink_free		// get a free cell
	jnz	err_write_smdr
	movs	dhs2_in,0,dbs_str,_smdr_data,81   // write data to cell
	call	link_tln
	jmp	z_ret
err_write_smdr:
	ret
//
//*************************************
// search reco
// input: dbs_str tln_dbs
//        dhs2_in(wstr_m3,0) reco to find
//
// output:	z-flag Z reco found and linked to tln_pointer
//			reco is equal in date,time and costs
//
//
search_reco:
//
// tln have no cells
//
	compd	"255",dbs_str,_tln_top
	jz	nz_ret			// empty list
	comps	dbs_str,_tln_top,dbs_str,_tln_bottom,9
	jnz	search_3_reco
//
// tln have only one cell
//
	movs	dbs_str,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	comps	dhs2_date,dbs_str,_smdr_date,23
	jnz	nz_ret
	comps	dhs2_cost,dbs_str,_smdr_cost,9
	jnz	nz_ret
	movs	dbs_para,aktu_reco,9	// pointer to cell
	movs	dbs_str,_smdr_data,dbs_str,_smdr_dienst,4
	movs	dhs2_tln,dbs_str,_smdr_data,4
	movs	msg_02001,dbs_str,_smdr_type,2	// "GZ"
	acall	write_dbs
	movs	tln_point_sub,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movd	"255",dbs_str,_tln_top
	movd	"255",dbs_str,_tln_bottom
	movs	dbs_str,_cost_open,calc_p1,8
	movs	geb_aktu,calc_p2,8
	acall	subb
	movs	calc_erg,dbs_str,_cost_open,8
	acall	write_dbs
	movs	aktu_reco,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	jmp	link_tln
//
// tln have more than one cell
//
search_3_reco:
	movs	dbs_str,_tln_top,aktu_reco,9
	movs	dbs_str,_tln_top,ext_point_top,9
	movs	dbs_str,_tln_bottom,ext_point_bott,9
	movd	"255",ext_pree_point
//
search_loop:
	movs	aktu_reco,dbs_para,9
//
	acall	preco_dbs
	acall	read_dbs
	comps	dhs2_date,dbs_str,_smdr_date,23
	jnz	search_3_next
	comps	dhs2_cost,dbs_str,_smdr_cost,9
	jnz	search_3_next
	//
	movs	dbs_str,_smdr_data,dbs_str,_smdr_dienst,4
	movs	dhs2_tln,dbs_str,_smdr_data,4
	movs	msg_02001,dbs_str,_smdr_type,2	// "GZ"
	acall	write_dbs
//
// unlink cell from top?
//
	comps	aktu_reco,ext_point_top,9
	jnz	search_3_1
	movs	dbs_str,_link_pointer,ext_point_top,9
	jmp	search_3_link
//
search_3_1:
//
// unlink from bottom?
//
	comps	aktu_reco,ext_point_bott,9
	jnz	search_3_2
	movs	ext_pree_point,ext_point_bott,9
	movs	ext_point_bott,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movd	"255",dbs_str,_link_pointer
	acall	write_dbs
	jmp	search_3_link
//
search_3_2:
//
// unlink from the middle
//
	movs	ext_pree_point,dbs_para,9
	movs	dbs_str,_link_pointer,ext_pree_point,9
	acall	preco_dbs
	acall	read_dbs
	movs	ext_pree_point,dbs_str,_link_pointer,9
	acall	write_dbs
	jmp	search_3_link
//
// switch to next cell
//
search_3_next:
	movs	aktu_reco,ext_pree_point,9
	movs	dbs_str,_link_pointer,aktu_reco,9
	compd	"255",aktu_reco
	jnz	search_loop
	jmp	nz_ret
//
search_3_link:
	movs	tln_point_sub,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	ext_point_top,dbs_str,_tln_top,9
	movs	ext_point_bott,dbs_str,_tln_bottom,9
	movs	dbs_str,_cost_open,calc_p1,8
	movs	geb_aktu,calc_p2,8
	acall	subb
	movs	calc_erg,dbs_str,_cost_open,8
	acall	write_dbs
	movs	aktu_reco,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	jmp	link_tln
	//
//*************************************
// link cell to bottom of TLN_SMDR tab
// input:	aktu_reco: pointer to cell
//		tln reco in s11
//		dbs_string pos data filled with data to save
// output:	cell linked to _tln_bottom
//		reco_counter ++
// using:	dbs_para,dbs_str,calc_erg
//
link_tln:
	compd	"255",s11,_tln_top              // SMDR_pool is empty
	jz	tln_to_empty
tln_ln_write:
	movs	aktu_reco,dbs_para,9
	acall	preco_dbs
	movd	"255",dbs_str,_link_pointer
	acall	write_dbs
//
	movs	s11,_tln_bottom,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	aktu_reco,dbs_str,_link_pointer,9
	movs	aktu_reco,s11,_tln_bottom,9
	acall	write_dbs
	jmp	tln_pcount
tln_to_empty:
	movs	aktu_reco,dbs_para,9
	acall	preco_dbs
	movd	"255",dbs_str,_link_pointer
	acall	write_dbs
//
	movs	aktu_reco,s11,_tln_top,9
	movs	aktu_reco,s11,_tln_bottom,9
tln_pcount:
//	  movs	  s11,_number_of_calls,calc_erg,8
//	  acall   inc_erg
//	  movs	  calc_erg,s11,_number_of_calls,8
//
	jmp	z_ret
//***********************************************
// unlink top tln_top
//   funktion: get one reco from the tln_top
//	       input: s11 tln_tab config
//
//	       output: flag_z = Z if a cell was found
//		       aktu_reco points to that cell
//		       s14 = data
//
//		       flag_z = NZ if there was no free_cell found
//
//	       using:  dbs_para,dbs_str,calc_p1,calc_p2,calc_erg
//
unlink_tln:
	compd	"255",s11,_tln_top
	jz	err_tln_unlink
	comps	s11,_tln_top,s11,_tln_bottom,8	      // pointer to same loc
	jz	unlink_tln_last
	movs	s11,_tln_top,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	s11,_tln_top,aktu_reco,9
	movs	dbs_str,_link_pointer,s11,_tln_top,9
//	  movs	  s11,_number_of_calls,calc_erg,8
//	  acall   dec_erg
//	  movs	  calc_erg,s11,_number_of_calls,8
//
        jmp     unlink_save_ext         // V gdc09c
//
//        jmp     z_ret
//
err_tln_unlink:
	jz	nz_ret
//
unlink_tln_last:
	movs	s11,_tln_top,aktu_reco,8
	movd	"255 ",s11,_tln_top
	movd	"255 ",s11,_tln_bottom
//	  movs	  s11,_number_of_calls,calc_erg,8
//	  acall   dec_erg
//	  movs	  calc_erg,s11,_number_of_calls,8
//
// version gdc09c
unlink_save_ext:
        movs    tln_pointer,dbs_para,9
	acall	preco_dbs
	acall	write11_dbs	// save extension
// end gdc09c
        jmp     z_ret
//
//*************************************
// link cell to bottom of free_pool
// input:	aktu_reco: pointer to cell
// output:	cell linked to free_pool
//		reco_counter ++
// using:	dbs_para,dbs_str,calc_erg
//
//
link_free:
	compd	"255",free_pool_first           // pool is empty
	jz	link_to_empty
	movs	free_pool_last,dbs_para,9
	acall	preco_dbs
	movs	aktu_reco,dbs_str,_link_pointer,9
	acall	write_dbs
	movs	aktu_reco,free_pool_last,9
	jmp	link_pcount
link_to_empty:
	movs	aktu_reco,free_pool_first,9
	movs	aktu_reco,free_pool_last,9
link_pcount:
	movs	reco_count_free,calc_erg,8
	acall	inc_erg
	movs	calc_erg,reco_count_free,8
//
	call	update_bled
	jmp	z_ret

//***********************************************
// unlink top free_pool
//   funktion: get one reco from the free_pool
//	       input: -
//	       output: flaf_z = Z if a free-cell was found
//		       aktu_reco points to that cell
//
//		       flag_z = NZ if there was no no free-cell found
//
//	       using:  dbs_para,dbs_str,calc_p1,calc_p2,calc_erg
//
unlink_free:
	call	update_bled
	comps	free_pool_first,free_pool_last,8	// pointer to same loc
	jz	unlink_f_last
	movs	free_pool_first,dbs_para,9
	acall	preco_dbs
	acall	read_dbs
	movs	free_pool_first,aktu_reco,9
	movs	dbs_str,_link_pointer,free_pool_first,9
	movs	reco_count_free,calc_erg,8
	acall	dec_erg
	movs	calc_erg,reco_count_free,8
//
	jmp	z_ret
//
unlink_f_last:
	compd	"255",free_pool_first
	jz	nz_ret
//
	movs	free_pool_first,aktu_reco,8
	movd	"255 ",free_pool_first
	movd	"255 ",free_pool_last
	movs	reco_count_free,calc_erg,8
	acall	dec_erg
	movs	calc_erg,reco_count_free,8
	jmp	z_ret
//
//***********************************************
// z_ret
z_ret:
	setc	cnt_ret,1
	decc	cnt_ret
	ret
//***********************************************
// NZ_ret
nz_ret:
	setc	cnt_ret,0
	decc	cnt_ret
	ret
//***********************************************
//
dbs_pool_init:
	setc	dbs_count,n_dbs_moduls	//number dbs-modules
#ifdef small_gdc
        setc    dbs_number,004          //dbs number first extended
	movd	"00000000 ",calc_erg
        movd    "004 0000 ",free_pool_first
        movd    "004 0000 ",free_pool_last
        movd    "004 0000 ",aktu_reco
	movd	"00000000 ",reco_count_free     // clear reco count
#else
        setc    dbs_number,128          //dbs number first extended
	movd	"00000000 ",calc_erg
	movd	"128 0000 ",free_pool_first
	movd	"128 0000 ",free_pool_last
	movd	"128 0000 ",aktu_reco
	movd	"00000000 ",reco_count_free     // clear reco count
#endif
//
// init DBS
//
init_loop:
	movd	" INIT DBS          /n",wstr_m3,0
	movc	dbs_number,wstr_m3,10
	out	wstr_m3,0,c4
//
	movd	dbs_config,dbs_para		// setup dbs config
	movc	dbs_number,dbs_para		// select dbs
	acall	open_dbs
//		 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
	movd	"                                                                                         /n",s14,0
	acall	pfirst_dbs
	movc	dbs_number,dbs_str,0		//set dbs number
//
set_dbs_loop:
	acall	inc_erg
	movs	calc_erg_4dg,dbs_str,_reco,4	// set reconumber
	acall	write_dbs
	acall	pnext_dbs
	jz	set_dbs_loop
//
set_to_next:
	movs	reco_count_free,calc_p1,8	// calculate new
	movs	calc_erg,calc_p2,8		// free recos
	acall	add
	movs	calc_erg,reco_count_free,8
	incc	dbs_number			// dbs number ++
	decc	dbs_count			// dbs counter --
	jnz	set_next_point
//
// setup dbs elements end
//
	movd	"255",dbs_str,0
	acall	write_dbs
	movd	"        ",dbs_para_reco
	acall	getr_dbs
	movs	dbs_para,free_pool_last,9      // set last pointer
	movd	"          Free Cells in SMDR DBS!/n",wstr_m36,100
	movs	reco_count_free,wstr_m36,100,8
	out	wstr_m36,100,c4
	ret

//
set_next_point:
	movd	"00000000 ",calc_erg
	movc	dbs_number,dbs_str,0		//set dbs number
	movs	calc_erg_4dg,dbs_str,_reco,4	//set reconumber
	acall	write_dbs
	jmp	init_loop

//************************************************
// 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
//
//************************************************
// Buffer 1 init
//
// Aufruf:	 call	 Init_b1
//
init_b1:
	setp	0Xd310,badr_1_high	//beginn adresse high
	setp	0Xd311,0x00		//beginn adresse low
//
	setp	0Xd312,lbuff_1_high	//bufferlaenge high
	setp	0Xd313,0x00		//bufferlaenge low
//
	setp	0Xd314,lbuff_1_high	//anzahl bytes free high
	setp	0Xd315,0x00		//anzahl bytes free low
//
	setp	0Xd316,badr_1_high	//input zeiger high
	setp	0Xd317,0x00		//input zeiger low
//
	setp	0Xd318,lbuff_1_high	//input laenge bis bufferende high
	setp	0Xd319,0x00		//input laenge bis bufferende low
//
	setp	0Xd31A,badr_1_high	//output zeiger high
	setp	0Xd31B,0x00		//output zeiger low
//
	setp	0Xd31C,lbuff_1_high	//output laenge bis bufferende high
	setp	0Xd31D,0x00		//output laenge bis bufferende low
//
	setp	0Xd31E,modnum_1 	//modulnummer falls in modulmem
//
	ret
//
//************************************************
// Buffer 2 init
//
// Aufruf:	 call	 Init_b2
//
init_b2:
	setp	0Xd320,badr_2_high	//beginn adresse high
	setp	0Xd321,0x00		//beginn adresse low
//
	setp	0Xd322,lbuff_2_high	//bufferlaenge high
	setp	0Xd323,0x00		//bufferlaenge low
//
	setp	0Xd324,lbuff_2_high	//anzahl bytes free high
	setp	0Xd325,0x00		//anzahl bytes free low
//
	setp	0Xd326,badr_2_high	//input zeiger high
	setp	0Xd327,0x00		//input zeiger low
//
	setp	0Xd328,lbuff_2_high	//input laenge bis bufferende high
	setp	0Xd329,0x00		//input laenge bis bufferende low
//
	setp	0Xd32A,badr_2_high	//output zeiger high
	setp	0Xd32B,0x00		//output zeiger low
//
	setp	0Xd32C,lbuff_2_high	//output laenge bis bufferende high
	setp	0Xd32D,0x00		//output laenge bis bufferende low
//
	setp	0Xd32E,modnum_2 	//modulnummer falls in modulmem
//
	ret
//
//************************************************
// Buffer 3 init
//
// Aufruf:	 call	 Init_b3
//
init_b3:
	setp	0Xd330,badr_3_high	//beginn adresse high
	setp	0Xd331,0x00		//beginn adresse low
//
	setp	0Xd332,lbuff_3_high	//bufferlaenge high
	setp	0Xd333,0x00		//bufferlaenge low
//
	setp	0Xd334,lbuff_3_high	//anzahl bytes free high
	setp	0Xd335,0x00		//anzahl bytes free low
//
	setp	0Xd336,badr_3_high	//input zeiger high
	setp	0Xd337,0x00		//input zeiger low
//
	setp	0Xd338,lbuff_3_high	//input laenge bis bufferende high
	setp	0Xd339,0x00		//input laenge bis bufferende low
//
	setp	0Xd33A,badr_3_high	//output zeiger high
	setp	0Xd33B,0x00		//output zeiger low
//
	setp	0Xd33C,lbuff_3_high	//output laenge bis bufferende high
	setp	0Xd33D,0x00		//output laenge bis bufferende low
//
	setp	0Xd33E,modnum_3 	//modulnummer falls in modulmem
//
	ret
//
//************************************************
// Buffer 4 init
//
// Aufruf:	 call	 Init_b4
//
init_b4:
	setp	0Xd340,badr_4_high	//beginn adresse high
	setp	0Xd341,0x00		//beginn adresse low
//
	setp	0Xd342,lbuff_4_high	//bufferlaenge high
	setp	0Xd343,0x00		//bufferlaenge low
//
	setp	0Xd344,lbuff_4_high	//anzahl bytes free high
	setp	0Xd345,0x00		//anzahl bytes free low
//
	setp	0Xd346,badr_4_high	//input zeiger high
	setp	0Xd347,0x00		//input zeiger low
//
	setp	0Xd348,lbuff_4_high	//input laenge bis bufferende high
	setp	0Xd349,0x00		//input laenge bis bufferende low
//
	setp	0Xd34A,badr_4_high	//output zeiger high
	setp	0Xd34B,0x00		//output zeiger low
//
	setp	0Xd34C,lbuff_4_high	//output laenge bis bufferende high
	setp	0Xd34D,0x00		//output laenge bis bufferende low
//
	setp	0Xd34E,modnum_4 	//modulnummer falls in modulmem
//
	ret
//
//************************************************
// Buffer 5 init
//
// Aufruf:	 call	 Init_b5
//
init_b5:
	setp	0Xd350,badr_5_high	//beginn adresse high
	setp	0Xd351,0x00		//beginn adresse low
//
	setp	0Xd352,lbuff_5_high	//bufferlaenge high
	setp	0Xd353,0x00		//bufferlaenge low
//
	setp	0Xd354,lbuff_5_high	//anzahl bytes free high
	setp	0Xd355,0x00		//anzahl bytes free low
//
	setp	0Xd356,badr_5_high	//input zeiger high
	setp	0Xd357,0x00		//input zeiger low
//
	setp	0Xd358,lbuff_5_high	//input laenge bis bufferende high
	setp	0Xd359,0x00		//input laenge bis bufferende low
//
	setp	0Xd35A,badr_5_high	//output zeiger high
	setp	0Xd35B,0x00		//output zeiger low
//
	setp	0Xd35C,lbuff_5_high	//output laenge bis bufferende high
	setp	0Xd35D,0x00		//output laenge bis bufferende low
//
	setp	0Xd35E,modnum_5 	//modulnummer falls in modulmem
//
	ret
//
//************************************************
// Buffer 6 init
//
// Aufruf:	 call	 Init_b6
//
init_b6:
	setp	0Xd360,badr_6_high	//beginn adresse high
	setp	0Xd361,0x00		//beginn adresse low
//
	setp	0Xd362,lbuff_6_high	//bufferlaenge high
	setp	0Xd363,0x00		//bufferlaenge low
//
	setp	0Xd364,lbuff_6_high	//anzahl bytes free high
	setp	0Xd365,0x00		//anzahl bytes free low
//
	setp	0Xd366,badr_6_high	//input zeiger high
	setp	0Xd367,0x00		//input zeiger low
//
	setp	0Xd368,lbuff_6_high	//input laenge bis bufferende high
	setp	0Xd369,0x00		//input laenge bis bufferende low
//
	setp	0Xd36A,badr_6_high	//output zeiger high
	setp	0Xd36B,0x00		//output zeiger low
//
	setp	0Xd36C,lbuff_6_high	//output laenge bis bufferende high
	setp	0Xd36D,0x00		//output laenge bis bufferende low
//
	setp	0Xd36E,modnum_6 	//modulnummer falls in modulmem
//
	ret
//
//***********************************************************************
// configuration display
//
cfg_display:
	movd	"          ... free_pool_first/n",wstr_m36,0
	movs	free_pool_first,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... free_pool_last/n",wstr_m36,0
	movs	free_pool_last,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... reco_count_free/n",wstr_m36,0
	movs	reco_count_free,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... aktu_reco/n",wstr_m36,0
	movs	aktu_reco,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... date_last/n",wstr_m36,0
	movs	date_last,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"                 ... printers/n",wstr_m36,0
	movs	print_string,wstr_m36,0,15
	out	wstr_m36,0,c4
//
        movd    "          ... EURO_Parameter/n",wstr_m36,0
        movs    calc_euro,wstr_m36,0,1
	out	wstr_m36,0,c4
//
	movd	"          ... geb_aktu/n",wstr_m36,0
	movs	geb_aktu,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... tln_pointer/n",wstr_m36,0
	movs	tln_pointer,wstr_m36,0,9
	out	wstr_m36,0,c4
//
	movd	"          ... extension_num/n",wstr_m36,0
	movs	extension_num,wstr_m36,0,4
	out	wstr_m36,0,c4
//
	movd	"          ... input_state/n",wstr_m36,0
	movs	input_state,wstr_m36,0,4
	out	wstr_m36,0,c4
//
	movd	"          ... old_state/n",wstr_m36,0
	movs	old_state,wstr_m36,0,4
	out	wstr_m36,0,c4
//
	movd	"          ... old_date/n",wstr_m36,0
	movs	old_date,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... tln_point_sub/n",wstr_m36,0
	movs	tln_point_sub,wstr_m36,0,9
	out	wstr_m36,0,c4
//
	movd	"          ... ext_point_top/n",wstr_m36,0
	movs	ext_point_top,wstr_m36,0,9
	out	wstr_m36,0,c4
//
	movd	"          ... ext_point_bott/n",wstr_m36,0
	movs	ext_point_bott,wstr_m36,0,9
	out	wstr_m36,0,c4
//
	movd	"          ... ext_pree_point/n",wstr_m36,0
	movs	ext_pree_point,wstr_m36,0,9
	out	wstr_m36,0,c4
//
	movd	"          ... geb_total/n",wstr_m36,0
	movs	geb_total,wstr_m36,0,8
	out	wstr_m36,0,c4
//
	movd	"          ... status_pointer/n",wstr_m36,0
	movs	status_pointer,wstr_m36,0,9
	out	wstr_m36,0,c4
//
	movd	"                ... last_date_time/n",wstr_m36,0
	movs	last_date_time,wstr_m36,0,15
	out	wstr_m36,0,c4
//
	movd	"                ... last_date_telef/n",wstr_m36,0
	movs	last_date_telef,wstr_m36,0,15
	out	wstr_m36,0,c4
//
	movd	"                ... last_date_bar/n",wstr_m36,0
	movs	last_date_bar,wstr_m36,0,15
	out	wstr_m36,0,c4
//
	movd	"           ... page_calc1/n",wstr_m36,0
	movs	page_calc1,wstr_m36,0,3
	out	wstr_m36,0,c4
//
	movd	"           ... page_calc2/n",wstr_m36,0
	movs	page_calc2,wstr_m36,0,3
	out	wstr_m36,0,c4
//
	movd	"           ... page_calc_sub/n",wstr_m36,0
	movs	page_calc_sub,wstr_m36,0,3
	out	wstr_m36,0,c4
//
	movd	"           ... page_lf_number/n",wstr_m36,0
	movs	page_lf_number,wstr_m36,0,3
	out	wstr_m36,0,c4
//
	movd	"                    ... hotel_name/n",wstr_m36,0
	movs	hotel_name,wstr_m36,0,20
	replace "/n ",wstr_m36,0,20
	out	wstr_m36,0,c4
//
	movd	"           ... page1_state/n",wstr_m36,0
	movc	page1_state,wstr_m36,0
	out	wstr_m36,0,c4
//
	movd	"           ... page1_line/n",wstr_m36,0
	movc	page1_line,wstr_m36,0
	out	wstr_m36,0,c4
//
	movd	"           ... page2_state/n",wstr_m36,0
	movc	page2_state,wstr_m36,0
	out	wstr_m36,0,c4
//
	movd	"           ... page2_line/n",wstr_m36,0
	movc	page2_line,wstr_m36,0
	out	wstr_m36,0,c4
//
	movd	"           ... language/n",wstr_m36,0
	movs	language,wstr_m36,0,3
	out	wstr_m36,0,c4
//
	ret
//***********************************************
// display the TLN dbs
//
tln_display:
	movd	"2 ",dbs_para
	acall	pfirst_dbs
	movd	" EXTENSION TABLE /n",wstr_m36,0
	out	wstr_m36,0,c4
//
tln_ldisplay:
	acall	read_dbs
        compd   "    ",dbs_str,_tln
	jz	tln_edisplay
	movd	"/n",dbs_str,_tln_cr_pos
	out	dbs_str,0,c4
	acall	pnext_dbs
	jz	tln_ldisplay
//
tln_edisplay:
	movd	" END OF TABLE/n",wstr_m36,0
	out	wstr_m36,0,c4
//
	ret
//*********************************************************
// test TLN_DBS for free Reco
//
test_tln_free:
	movd	"002 119 ",dbs_para
	acall	preco_dbs
	acall	read_dbs
	compd	"    ",dbs_str,_tln
	ret
//
//*********************************************************
// insert a tln configuration as room-extension
// input: dbs_search_str= extension-number to insert
//
ins_tln_room:
	call	find_ins_point
	jnz	err_tln_room
//
	movs	dbs_search_str,dbs_str,_tln,4
        movd    "RSXxxxxxx ",dbs_str,_ext_type
	call	dbs_write		// new extension written
	call	ins_write		// save all extension below
//
err_tln_room:
	ret
//
//*********************************************************
// insert a tln configuration
// input: dbs_search_str= extension-number to insert
//
ins_tln_admin:
	call	find_ins_point
	jnz	err_tln_admin
//
	movs	dbs_search_str,dbs_str,_tln,4
#ifdef small_gdc
        movd    "ASDxxxxxx ",dbs_str,_ext_type
#else
        movd    "ASMxxxxxx ",dbs_str,_ext_type
#endif
        call    dbs_write               // new extension written
	call	ins_write		// save all extension below
//
err_tln_admin:
	ret
//
//
//***********************************************
// input: dbs_search_str = extension-number
// output:	if Z-Flag Z
//			insert_point found
//			s11,0 = tln_dbs_string
//		if Z-Flag NZ
//			error
//
find_ins_point:
	movd	"      ",calc_p2
	movd	"      ",calc_p1
	movs	dbs_search_str,calc_p2,4
	movd	"002  ",dbs_para
	acall	pfirst_dbs
ins_find:
	acall	read11_dbs
	movs	s11,_tln,calc_p1,4
	acall	comp
	compd	"LT",calc_erg_flag
	jnz	insert_point
        compd   "999",s11,_tln
        jz      insert_point
        acall   pnext_dbs
	jnz	ins_error
	jmp	ins_find
//
insert_point:
	jmp	z_ret
//
ins_error:
	ret
//
//***********************************************
// input:	s11,0 = string to write at position
// funktion:
//	read the aktuell position
//	save it
//	and write the stored extension to that position
//	point to next
//	loop until extension = "   "
//
ins_write:
	movs	s11,0,dbs_str,0,100	// old to write buffer
	acall	read11_dbs		// read new
	acall	write_dbs		// save buffer
	acall	pnext_dbs		// point to next reco
	jnz	err_ins_write
	compd	"    ",s11,_tln
	jnz	ins_write
err_ins_write:
	ret
//*********************************************************
// input:	dbs_para = position to delete
// funktion:
//    do
//	point to next reco
//	read the aktuell position
//	point to prvious reco
//	and write the stored extension to that position
//	point to next
//    until extension = "999"
//    clear reco (overwrite "             ")
//
del_write:
	acall	pnext_dbs
	jnz	err_del_write
	acall	read_dbs		// read new
	acall	pprev_dbs
	acall	write_dbs		// save buffer
	acall	pnext_dbs		// point to next reco
	jnz	err_del_write
	compd	"999",dbs_str,_tln
	jnz	del_write
	movd	"                                          ",dbs_str,0
	acall	write_dbs
err_del_write:
	ret
//
//*********************************************************
// display the buffer leds
//	led 12,13,14,15
//
update_bled:
	incc	update_cnt
	jnz	e_update
	movs	reco_count_free,calc_p1,8
#ifdef small_gdc
        movd    "1400 ",calc_p2
#else
        movd    "19585 ",calc_p2
#endif
        acall   comp
	compd	"LT",calc_erg_flag
	jz	t_16788
	setl	1,0
	setl	2,0
	setl	3,0
	setl	4,0
e_update:
	ret
//
t_16788:
#ifdef small_gdc
        movd    "1260 ",calc_p2
#else
        movd    "16788 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_13991
	setl	1,2
	setl	2,0
	setl	3,0
	setl	4,0
	ret
//
t_13991:
#ifdef small_gdc
        movd    "1080 ",calc_p2
#else
	movd	"13991 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_11194
	setl	1,1
	setl	2,0
	setl	3,0
	setl	4,0
	ret
//
t_11194:
#ifdef small_gdc
        movd    "900 ",calc_p2
#else
        movd    "11194 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_8397
	setl	1,1
	setl	2,2
	setl	3,0
	setl	4,0
	ret
//
t_8397:
#ifdef small_gdc
        movd    "720 ",calc_p2
#else
        movd    "8397 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_5600
	setl	1,1
	setl	2,1
	setl	3,0
	setl	4,0
	ret
//
t_5600:
#ifdef small_gdc
        movd    "540 ",calc_p2
#else
        movd    "5600 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_2803
	setl	1,1
	setl	2,1
	setl	3,2
	setl	4,0
	ret
//
t_2803:
#ifdef small_gdc
        movd    "360 ",calc_p2
#else
        movd    "2803 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_1500
	setl	1,1
	setl	2,1
	setl	3,1
	setl	4,0
	ret
//
t_1500:
#ifdef small_gdc
        movd    "180 ",calc_p2
#else
        movd    "1500 ",calc_p2
#endif
	acall	comp
	compd	"LT",calc_erg_flag
	jz	t_100
	setl	1,1
	setl	2,1
	setl	3,1
	setl	4,2
	ret
//
t_100:
	setl	1,1
	setl	2,1
	setl	3,1
	setl	4,1
	ret
//
//*********************************************************
// TLN-DBS:
// in modul 2
// begin	0x4000	(16384)
//		Maximale recolaenge bei 120 records 130 bytes
// recos	120
// elements	21
// element0	extension-number l=4		offset 0
// element1	flag 1 l=1			offset 4
// element2	flag 2 l=1			offset 5
// element3	flag 3 l=1			offset 6
// element4	flag 4 l=1			offset 7
// element5	flag 5 l=1			offset 8
// element6	flag 6 l=1			offset 9
// element7	flag 7 l=1			offset 10
// element8	flag 8 l=1			offset 11
// element9	flag 9 l=1			offset 12
// element10	cost_open l=10			offset 13
// element11	cost_closed l=10		offset 23
// element12	password l=5			offset 33
// element13	number_of_calls l=4		offset 38
// element14	dnd_flag l=1			offset 42
// element15	massage_waiting_flag l=1	offset 43
// element16	pointers l=4x9=36		offset 44
// element17	flag 10 l=1			offset 80
// element18	flag 11 l=1			offset 81
// element19	flag 12 l=1			offset 82
// element20	romm_state l=4			offset 83
//						offset 87
dbs_tln_init:
	movd	"2 16384 120 21 4 1 1 1 1 1 1 1 1 1 10 10 5 4 1 1 36 1 1 1 4  ",s15,100
	acall	open_dbs
	movd	"                                                                                                                     ",s14,0
	acall	init_dbs
	acall	pfirst_dbs
;
; Tabelle fuer TLN
;      TLN Rufnummer (3 digit + 1 Space fix)
;      |   FLAG 1 TYPE A...administration
;      |   |	       R...Room
;      |   |	       P...Phone booth
;      |   |	       B...Bar phone
;      |   |Flag 2 PRINT_FLAG S...Standard, I...Immediate
;      |   ||Flag 3 Printing periode
;      |   |||Flag 4 Logische Extension number (0-9) For print ticket
;      |   ||||Flag 5 - 9
;      |   |||||    cost_open ( offene Kosten 10 digigt (auto init))
;      |   |||||    |	      cost_closed (bereits verrechnete Kosten 10 digit (auto init))
;      |   |||||    |	      |
//movd	"110 ASM0xxxxx ",s14,0
//call	dbs_write
//
//movd	"112 RSx1xxxxx ",s14,0
//call	dbs_write
//
//movd	"122 PSD2xxxxx ",s14,0
//call	dbs_write
//
movd  "999 SSxxxxxxx ",s14,0    // defines the last extension (must)
call  dbs_write
ret

dbs_write:
	movd	"00000000  00000000     1 000 NN255 0000 255 0000 255 0000 255 0000 xxx0000  /n",s14,_cost_open
	acall	write_dbs
	acall	pnext_dbs
	jz	dbs_wr_ok
	movd	"Runtime-error DBS3 too small!!/n",s14,150
	out	s14,150,c4
dbs_wr_ok:
	ret
//
//*********************************************************
//
t_zusatzkosten:
        compd   "1",print_zusatzkosten
        jnz     rt_zusatzkosten
        compd   "Zusatzkosten",dhs2_extern
rt_zusatzkosten:
	ret
//
//*********************************************************
//
t_ti_name:
#ifdef	gb_ti_name
	compd	gb_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fr_ti_name
	compd	fr_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	de_ti_name
	compd	de_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	it_ti_name
	compd	it_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	se_ti_name
	compd	se_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	be_ti_name
	compd	be_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	ct_ti_name
	compd	ct_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	dk_ti_name
	compd	dk_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	es_ti_name
	compd	es_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fi_ti_name
	compd	fi_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	nl_ti_name
	compd	nl_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	no_ti_name
	compd	no_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	pt_ti_name
	compd	pt_ti_name,wstr_m3,0
	jz	t_ti_exit
#endif
//
t_ti_exit:
	ret
//
//***********************************************
//
t_ti_cabin_set:
#ifdef	gb_ti_cabin_set
	compd	gb_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fr_ti_cabin_set
	compd	fr_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	de_ti_cabin_set
	compd	de_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	it_ti_cabin_set
	compd	it_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	se_ti_cabin_set
	compd	se_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	be_ti_cabin_set
	compd	be_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	ct_ti_cabin_set
	compd	ct_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	dk_ti_cabin_set
	compd	dk_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	es_ti_cabin_set
	compd	es_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fi_ti_cabin_set
	compd	fi_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	nl_ti_cabin_set
	compd	nl_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	no_ti_cabin_set
	compd	no_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	pt_ti_cabin_set
	compd	pt_ti_cabin_set,wstr_m3,0
	jz	t_ti_exit
#endif
//
	ret
//
//***********************************************
//
t_ti_room:
#ifdef	gb_ti_room
	compd	gb_ti_room,wstr_m3,0
	jz	lang_gb_set
#endif
#ifdef	fr_ti_room
	compd	fr_ti_room,wstr_m3,0
	jz	lang_fr_set
#endif
#ifdef	se_ti_room
	compd	se_ti_room,wstr_m3,0
	jz	lang_se_set
#endif
#ifdef	be_ti_room
	compd	be_ti_room,wstr_m3,0
	jz	lang_be_set
#endif
#ifdef	ct_ti_room
	compd	ct_ti_room,wstr_m3,0
	jz	lang_ct_set
#endif
#ifdef	de_ti_room
	compd	de_ti_room,wstr_m3,0
	jz	lang_de_set
#endif
#ifdef	dk_ti_room
	compd	dk_ti_room,wstr_m3,0
	jz	lang_dk_set
#endif
#ifdef	es_ti_room
	compd	es_ti_room,wstr_m3,0
	jz	lang_es_set
#endif
#ifdef	fi_ti_room
	compd	fi_ti_room,wstr_m3,0
	jz	lang_fi_set
#endif
#ifdef	it_ti_room
        compd   it_ti_room,wstr_m3,0
	jz	lang_it_set
#endif
#ifdef	nl_ti_room
	compd	nl_ti_room,wstr_m3,0
	jz	lang_nl_set
#endif
#ifdef	no_ti_room
	compd	no_ti_room,wstr_m3,0
	jz	lang_no_set
#endif
#ifdef	pt_ti_room
        compd   pt_ti_room,wstr_m3,0
	jz	lang_pt_set
#endif
	ret
//
//***********************************************
//
t_ti_language:
#ifdef	gb_ti_language
	compd	gb_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fr_ti_language
	compd	fr_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	de_ti_language
	compd	de_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	it_ti_language
	compd	it_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	se_ti_language
	compd	se_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	be_ti_language
	compd	be_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	ct_ti_language
	compd	ct_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	dk_ti_language
	compd	dk_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	es_ti_language
	compd	es_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fi_ti_language
	compd	fi_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	nl_ti_language
	compd	nl_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	no_ti_language
	compd	no_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	pt_ti_language
	compd	pt_ti_language,wstr_m3,0
	jz	t_ti_exit
#endif
//
	ret
//
//***********************************************
//
t_ti_deposit:
#ifdef  gb_ti_deposit
	compd	gb_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fr_ti_deposit
	compd	fr_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	de_ti_deposit
	compd	de_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	it_ti_deposit
	compd	it_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	se_ti_deposit
	compd	se_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	be_ti_deposit
	compd	be_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	ct_ti_deposit
	compd	ct_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	dk_ti_deposit
	compd	dk_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	es_ti_deposit
	compd	es_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fi_ti_deposit
	compd	fi_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	nl_ti_deposit
	compd	nl_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	no_ti_deposit
	compd	no_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	pt_ti_deposit
	compd	pt_ti_deposit,wstr_m3,0
	jz	t_ti_exit
#endif
//
//
	ret
//
//***********************************************
//
t_ti_number:
#ifdef	gb_ti_number
	compd	gb_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fr_ti_number
	compd	fr_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	de_ti_number
	compd	de_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	it_ti_number
	compd	it_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	se_ti_number
	compd	se_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	be_ti_number
	compd	be_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	ct_ti_number
	compd	ct_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	dk_ti_number
	compd	dk_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	es_ti_number
	compd	es_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	fi_ti_number
	compd	fi_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	nl_ti_number
	compd	nl_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	no_ti_number
	compd	no_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
#ifdef	pt_ti_number
	compd	pt_ti_number,wstr_m3,0
	jz	t_ti_exit
#endif
//
//
	ret
//***********************************************
//
lang_fr_set:
	movd	language_fr,language
//	  compd   language_fr,language
	ret
lang_de_set:
	movd	language_de,language
//	  compd   language_de,language
	ret
lang_gb_set:
	movd	language_gb,language
//	  compd   language_gb,language
	ret
lang_se_set:
	movd	language_se,language
//	  compd   language_se,language
	ret
lang_be_set:
	movd	language_be,language
//	  compd   language_be,language
	ret
lang_ct_set:
	movd	language_ct,language
//	  compd   language_ct,language
	ret
lang_dk_set:
	movd	language_dk,language
//	  compd   language_dk,language
	ret
lang_es_set:
	movd	language_es,language
//	  compd   language_es,language
	ret
lang_fi_set:
	movd	language_fi,language
//	  compd   language_fi,language
	ret
lang_it_set:
	movd	language_it,language
//	  compd   language_it,language
	ret
lang_nl_set:
	movd	language_nl,language
//	  compd   language_nl,language
	ret
lang_no_set:
	movd	language_no,language
//	  compd   language_no,language
	ret
lang_pt_set:
	movd	language_pt,language
//	  compd   language_pt,language
	ret
//*********************************************************
//
form_r311:
        movs    r311_dhs2_tln_in,dhs2_tln,5     // "A111 "
        movs    r311_dhs2_type_in,dhs2_type,3   // "-->"
        movs    r311_dhs2_line_in,dhs2_line_number,28   //"N00 28/05/98 13:41 00:00:03 "
        movs    r311_dhs2_dienst_in,dhs2_dienst,7       //"ST TXI "
        movs    r311_dhs2_extern_in,dhs2_extern,27      //"027587234................. "
        movs    r311_dhs2_cost_in,dhs2_cost,10          //"0.00      "
        jmp     form_cost
//
form_r312:
        movs    r312_dhs2_tln_in,dhs2_tln,5     // "A111 "
        movs    r312_dhs2_type_in,dhs2_type,3   // "-->"
        movs    r312_dhs2_line_in,dhs2_line_number,28   //"N00 28/05/98 13:41 00:00:03 "
        movs    r312_dhs2_dienst_in,dhs2_dienst,7       //"ST TXI "
        movs    r312_dhs2_extern_in,dhs2_extern,27      //"027587234................. "
        movs    r312_dhs2_cost_in,dhs2_cost,10          //"0.00      "
        jmp     form_cost
//
form_r26_3dg:
        movs    dhs2_tln_in,dhs2_tln,36         // format smdr_string
	movs	dhs2_dienst_in,dhs2_dienst,34	//
        movs    dhs2_cost_in,dhs2_cost,10
//
form_cost:
        compd   ".",dhs2_dot1_
	jz	format_1
        compd   ".",dhs2_dot2_
	jz	format_2
        compd   ".",dhs2_dot3_
	jz	format_3
        compd   ".",dhs2_dot4_
	jz	format_4
        compd   ".",dhs2_dot5_
	jz	format_5
        compd   ".",dhs2_dot6_
	jz	format_6
format_6:
	movd	"00000000",calc_p1
	movd	"00  ",calc_p2
//        movs    dhs2_cost,calc_p1,6
//        movs    dhs2_gr6_,calc_p2,2
	jmp	format_end
format_5:
        compd   " ",dhs2_comma5_
	jnz	format_5_1
        movd    "0",dhs2_comma5_
format_5_1:
	movd	"00000000 ",calc_p1
	movd	"000  ",calc_p2
        movs    dhs2_cost,calc_p1,5
        movs    dhs2_gr5_,calc_p2,3
	jmp	format_end
format_4:
        compd   " ",dhs2_comma4_
	jnz	format_4_1
        movd    "0",dhs2_comma4_
format_4_1:
	movd	"0000000 ",calc_p1
	movd	"000  ",calc_p2
        movs    dhs2_cost,calc_p1,4
        movs    dhs2_gr4_,calc_p2,3
	jmp	format_end
format_3:
        compd   " ",dhs2_comma3_
	jnz	format_3_1
        movd    "0",dhs2_comma3_
format_3_1:
	movd	"000000 ",calc_p1
	movd	"000  ",calc_p2
        movs    dhs2_cost,calc_p1,3
        movs    dhs2_gr3_,calc_p2,3
	jmp	format_end
format_2:
        compd   " ",dhs2_comma2_
	jnz	format_2_1
        movd    "0",dhs2_comma2_
format_2_1:
	movd	"00000 ",calc_p1
	movd	"000  ",calc_p2
        movs    dhs2_cost,calc_p1,2
        movs    dhs2_gr2_,calc_p2,3
	jmp	format_end
format_1:
        compd   " ",dhs2_comma1_
	jnz	format_1_1
        movd    "0",dhs2_comma1_
format_1_1:
	movd	"0000 ",calc_p1
	movd	"000  ",calc_p2
        movs    dhs2_cost,calc_p1,1
        movs    dhs2_gr1_,calc_p2,3
format_end:
	acall	add
	movs	calc_erg,geb_aktu,8
        movd    "        ",dhs2_cost
        ret
//
//***********************************************
// to_right	input: param_1 string to justify to right
//		output: param_2 justified string
//			param_1 cleared
//		lenght: 20 char
//     using: counter 10,11,12
//
to_right:
//               01234567890123456789
        movd    "                    >/n",param_2
//      out     param_1,c4
//
// first skip over space in parameter 1
//
        setc    12,0    // char counter
        setc    11,20   // max char for search
        setc    10,200  // set source pointer
//
spl_to_right:
        compd   " ",s_param,c10
        jnz     f_to_right
        incc    10
        decc    11
        jnz     spl_to_right
        ret
//
// find end of the parameter (next space)
//
f_to_right:
        compd   " ",s_param,c10
        jz      f1_to_right
        incc    10
        incc    12              // number of char in parameter ++
        decc    11
        jnz     f_to_right
//
f1_to_right:
	setc	11,239	//destination
        decc    10
lto_right:
        compd   " ",s_param,c10
	jnz	mto_right
	decc	10
	decc	12
	jnz	lto_right
//               01234567890123456789
        movd    "                    ",param_1
//        out     param_1,c4
        ret
//
mto_right:
        movs    s_param,c10,s_param,c11,1
	decc	10
	decc	11
	decc	12
        jnz     mto_right
//               01234567890123456789
        movd    "                    ",param_1
//        out     param_1,c4
	ret
//***********************************************
// to_left     input: param_1 string to justify to left
//		output: param_2 justified string
//			param_1 cleared
//		lenght: 20 char
//     using: counter 10,11,12
//
to_left:
//               01234567890123456789
        movd    "                    >/n",param_2
	setc	12,20	//number of char
	setc	10,200	//source
	setc	11,220	//destination
lto_left:
        compd   " ",s_param,c10
	jnz	mto_left
	incc	10
	decc	12
        jnz     lto_left
eto_left:
//               01234567890123456789
        movd    "                    ",param_1
	ret
//
mto_left:
        movs    s_param,c10,s_param,c11,1

        incc    10
	incc	11
	decc	12
        jz      eto_left
        compd   " ",s_param,c10
        jz      eto_left
        compd   "/n",s_param,c10
        jz      eto_left
        jmp     mto_left
//***********************************************
// Calculate EURO
//
//      input:  param_1 value in EURO left or right
//              with 2 or 3 comma
//              comma "," or "."
//      output: param_erg       value in ATS with 2 comma
//              comma ","
//
euro_to_ats:
        movd    "                    ",param_c1
        call    to_right        //"10,20" > "   10,20"
        replace ".,",param_2,20 //" 10.20" > " 10,20"
        compd   ",",param_2r3
        jz      to_ats2comma
//
        compd   ",",param_2r4
        jnz     error_comma
//
// 3 digit comma
//
        movd    "00000   ",calc_p1
        movd    "000 ",calc_p2
        movs    param_2r9,calc_p1,5
        movs    param_2r3,calc_p2,3
        jmp     to_ats_common
//
to_ats2comma:
        movd    "00000   ",calc_p1
        movd    "000 ",calc_p2
        movs    param_2r8,calc_p1,5
        movs    param_2r2,calc_p2,2
        jmp     to_ats_common
//
to_ats_common:
//               1234567890
        movd    "       ,  ",param_ergr10

        movs    calc_p2,param_1,8
        movd    "13 ",calc_p2
        acall   mul
        movd    "00000000",param_2
        movs    calc_erg_6dg,param_2,6
//
        movd    "76 ",calc_p2
        acall   mul
        movs    calc_erg,param_erg,8
//
        movd    "03 ",calc_p2
        acall   mul
        movd    "        ",calc_p2
        movs    calc_erg,calc_p2,6
        movs    param_erg,calc_p1,8
        movd    "       ",param_erg
        movs    calc_erg_2dg,param_erg,2
        acall   add
        movs    calc_erg,calc_p1,8
        movs    param_2,calc_p2,8
        acall   add
        movs    calc_erg,param_2,8
//
        movs    param_1,calc_p1,8
        movd    "1376 ",calc_p2
        acall   mul
        movd    "        ",param_1
        movs    calc_erg,param_1,5
        movd    "        ",calc_p1
        movd    "000 ",calc_p2
        movs    calc_erg_3dg,calc_p1,3
        movs    param_erg,calc_p2,2
        acall   add
        movd    "        ",calc_p1
        movd    "        ",calc_p2
        movs    calc_erg,calc_p1,5
        movs    param_1,calc_p2,5
        //
        movs    calc_erg_3dg,param_1,3
        //
        acall   add
        movs    calc_erg,calc_p1,8
        movs    param_2,calc_p2,8
        acall   add
        acall   cut_lz
        movs    calc_erg,param_2,8
        movd    "        ",calc_p1
        movs    param_1,calc_p1,3
        movd    "500 ",calc_p2
        acall   comp
        compd   "GT",calc_erg_flag
        jnz     to_atsend
//
        movs    param_2,calc_erg,8
        acall   inc_erg
        acall   cut_lz
        jmp     to_1_atsend
//
to_atsend:
        movs    param_2,calc_erg,8
to_1_atsend:
        replace " 0",calc_erg_3dg,3
        movs    calc_erg,param_ergr9,6
        movs    calc_erg_2dg,param_ergr2,2

        ret
//
//****************************************************
//      input:  param_1 value in ATS left or right
//              with 2 or 3 comma
//              comma "," or "."
//      output: param_erg       value in EURO with 2 comma
//              comma ","
//
//
ats_to_euro:
        call    to_right        //"10,20" > "   10,20"
        replace ".,",param_2,20 //" 10.20" > " 10,20"
        compd   ",",param_2r3
        jz      to_eur2comma
//
        compd   ",",param_2r4
        jnz     error_comma
//
// 3 digit comma
//
        movd    "00000000",calc_p1
        movd    "000 ",calc_p2
        movs    param_2r9,calc_p1,5
        movs    param_2r3,calc_p2,3
        jmp     to_euro_common
//
to_eur2comma:
        movd    "00000000",calc_p1
        movd    "000 ",calc_p2
        movs    param_2r8,calc_p1,5
        movs    param_2r2,calc_p2,2
        jmp     to_euro_common
//
to_euro_common:
//               1234567890
        movd    "       ,  ",param_ergr10
        acall   add
        movs    calc_erg,calc_p1,8
//
        movd    "13760 ",calc_p2
        acall   div
        acall   cut_lz
        movs    calc_erg_7dg,param_ergr10,7
//
        movs    calc_rest,calc_p1,8
        movd    "100 ",calc_p2
        acall   mul
//
        movs    calc_erg,calc_p1,8
        movd    "13760 ",calc_p2
        acall   div
        movs    calc_erg_2dg,param_ergr2,2
//
        movs    calc_rest,calc_p1,8
        movd    "6880 ",calc_p2
        acall   comp
        compd   "GT",calc_erg_flag
        jnz     to_eurend
//
        movd    "        ",calc_erg
        movs    param_ergr2,calc_erg_2dg,2
        acall   inc_erg
        movs    calc_erg_2dg,param_ergr2,2
        compd   "000000",calc_erg
        jz      to_eurend
//
        movs    param_ergr10,calc_erg_7dg,7
        acall   inc_erg
        acall   cut_lz
        movs    calc_erg_7dg,param_ergr10,7
error_comma:
to_eurend:
        ret
//
//***********************************************
// Print a single ticket
//
single_ticket:
	movs	print_single_ticket,printer,1	   // desination of single ticket
//
        movs    wstr_m3,0,dbs_str,9,100          // save string
//
// now printing
//
	call	test_form_ff
	call	load_h60
	call	print_load
	movs	hotel_name,wstr_m3,2,20
	call	print_load
	movs	dbs_str,_smdr_date,wstr_m3,2,14
	call	print_load
	call	print_load
        movs    msg_32001,wstr_m3,2,32  //"Einzelgespraechsrechnung von",wstr_m3,2
	call	print_load
	movs	msg_32002,wstr_m3,2,32	//"Teilnehmer:",wstr_m3,2
        movs    dbs_str,_smdr_tln,wstr_m3,34,3
	call	print_load
	call	print_load
	movs	msg_32003,wstr_m3,2,32	//"Gewaehlte Rufnummer:",wstr_m3,2
	movs	dbs_str,_smdr_extern,wstr_m3,34,20
	replace ". ",wstr_m3,34,20
	call	print_load
	movs	msg_32004,wstr_m3,2,32	//"Gespraechsdauer:",wstr_m3,2
	movs	dbs_str,_smdr_duration,wstr_m3,34,8
	call	print_load
	call	print_load
	movs	msg_32005,wstr_m3,2,32	//"Gespraechskosten:",wstr_m3,2
	movs	dbs_str,_smdr_cost,wstr_m3,34,9
	movs	msg_03001,wstr_m3,44,3	//"ATS"
        compd   "0",calc_euro
        jz      skip_single_t
        compd   "1",calc_euro
        jz      skip_single_t
        movs    msg_03002,wstr_m3,44,3  //"EUR"
skip_single_t:
        call    ticket_euro
        call    print_load
        movs    msg_32007,wstr_m3,2,32  //"  inklusive MWST (20%)",wstr_m3,2
//
// calculate 20% MWST
//
//	  movs	  geb_aktu,calc_p1,8
//	  movd	  "10 ",calc_p2
//	  acall   mul
//	  movs	  calc_erg,calc_p1,8
//	  movd	  "12 ",calc_p2
//	  acall   div
//
//	  movs	  calc_erg,calc_p2,8
//	  movs	  geb_aktu,calc_p1,8
//	  acall   subb
//
//	  compd   "00000000",calc_erg
//	  jnz	  st8x_erg001
//	  movd	  "    ",calc_erg
//	  jmp	  st8x_erg002
//st8x_erg001:
//	  acall   cut_lz
//	  compd   "     ",calc_erg
//	  jnz	  st8x_erg002
//	  movd	  "    0",calc_erg
//st8x_erg002:
//	  movs	  calc_erg,wstr_m3,34,5
//
#ifdef	comma
//	  movd	  ",",wstr_m3,39
#else
//	  movd	  ".",wstr_m3,39
#endif
//	  movs	  calc_erg_3dg,wstr_m3,40,3
//
//	  movd	  "ATS",wstr_m3,44
	call	print_load
	call	print_load
	movs	msg_32008,wstr_m3,2,32	//"Danke fuer Ihren Besuch!",wstr_m3,2
	call	pr_ticket
	call	load_h60
#ifdef werbung
	movd	werbetext,wstr_m3,35
#endif
	call	pr_ticket
	call	pr_formfeed
        ret
//
//*********************************************************
//
ticket_euro:
//
//------> calc euro
//
        replace ".,",wstr_m3,34,15
//
        compd   "0",calc_euro
        jz      skip_ticket_euro
        compd   "3",calc_euro
        jz      skip_ticket_euro
        compd   "1",calc_euro
        jz      calc_ticket_euro
//
        movd    "                    ",param_1
        movs    wstr_m3,34,param_1,9    //load input parameter
        call    euro_to_ats
        movs    param_ergr8,wstr_m3,48,8
        movs    msg_03001,wstr_m3,57,3  // "ATS"
        jmp     skip_ticket_euro
calc_ticket_euro:
        movs    wstr_m3,34,param_1,9    //load input parameter
        call    ats_to_euro
        movs    param_ergr8,wstr_m3,48,8
        movs    msg_03002,wstr_m3,57,3  // "EUR"
skip_ticket_euro:
//
        ret
//
//*********************************************************
//
zzz:
end
