Mode Handler

These routines are the core of the user interface. At all times the program is set to be in a particular mode. Examples of modes include waiting for a keypress at a menu, reading in a password, or setting up the data for use by another mode. On every pass through the main loop, a short routine is called by looking up the mode number in the jump table. Once a mode's task has been completed or otherwise terminated, it will then change the mode to suit the next required operation.

Download:
; /////////////////////////////////////////////////////////// ; // Mode Handlers ; // (c) 1999 Geoff Knagge, Andrew Carr, Mark Lynn ; // last modified : 22/10/1999 ; // ; // Supporting Website : ; // http://members.xoom.com/gogogeoff/uni/elec270/ ; // ; /////////////////////////////////////////////////////////// ;!///////////////////////// setmode: ; input : mode in C push hl lxi hl,modecode mov m,c pop hl ret nomode: rst 1 ; called by a redundant mode ;!/////////////////////////// mode 02 - menu handler MenuSet: ; Input: C contains the menu code push hl push bc push af lxi hl, MenuTable mvi b,0 ; BC = menu code mvi a,0F ; for a = 15 to 1 MenL1: dad bc ; HL += BC dcr a cpi 0 jnz MenL1 SHLD menuPointer; mov c,m ; load the screen to be displayed call LCD_setMsg ; tell the lcd driver which one mvi c,ST_MENU call setmode ; change the program mode to menu idle lxi hl, menutime mov m,b ; set menu timeout counter to 0 pop af pop bc pop hl ret MenuHandler: ; called by main program loop for mode ST_MENU. call keyget cpi KS_NONE jz MenuJ1 inr a mov c,a mvi b,0 lhld menupointer dad bc ; point hl to mode for this key mov a,m ; get the mode cpi 0 ; zero means invalid key jz MenuJ1 mov c,a call setmode; MenuJ1: lhld menupointer lxi bc,0D dad bc mov a,m cpi 0 ; 0 means no timeout jz menuj4 ; no timeout for this menu mov c,a ; c = timeout lda menutime ; a = how long this menus been on cmp c jnz menuj4 ; times do not match inx hl mov c,m call setmode menuj4: ret ;/////////////////////// Mode 3 - handled by passwordin.asm ;!/////////////////////////// mode 04 - 0B : setup zones 1-8 Z_setactive: ; set the active zone and change messages ; input a= zone, 00 = zone 1 push af sta z_active adi 31 ; convert zone number to an ASCII code sta m_Z1 sta m_Z2 sta m_Z3 sta m_Z4 sta m_Z5 sta m_Z6 sta m_Z7 sta m_Z8 pop af ret Z_setup: lda modecode ; a = mode number (zone + 4) sui 04 ; so 00 = zone 1 call z_setactive mvi c,01 ; menu code call menuset call SZglock ; input A = zone cpi 0 jz Z_sj1 ; locked mvi A,0E ; line code for "disarm zone" sta z_al4 mvi A,ST_Dpw ; status will be "Disarm Password" sta Z_ao jmp Z_sj2 Z_sj1: ; not locked mvi A,0D ; line code for "arm zone" sta z_al4 mvi A,ST_Apw ; status will be "Arm Password" sta Z_ao Z_sj2: ret ;/////////////////////////// mode 0C : get arming password Z_ardata: .byte 00,0C,10,0E,ST_MAIN,ST_MAIN,ST_MAIN,0FF Z_apw: lxi hl,z_active mov a,m inr a ; password 01+zone lxi hl,z_ardata mov m,a dcr a call SZgindicator ; load show indicator flag call pa_setup ret ;/////////////////////////// mode 0D : get disarming password Z_didata: .byte 00,0C,11,0F,10,10,33,0FF Z_dpw: lxi hl,z_active mov a,m adi 09 ; password 09+zone lxi hl,z_didata mov m,a sbi 09 call SZgindicator ; load show indicator flag call pa_setup ret ;/////////////////////////// mode 0E : Correct arm code... Z_arm: lxi hl,z_active mov a,m call SZ_lock mvi c,sc_ZA ; show zone armed message mvi a,ST_main ; next mode call ww_set ; wait for a keypress ret ;/////////////////////////// mode 0F : correct disarm code... Z_disarm: lxi hl,z_active mov a,m call SZ_unlock mvi c,sc_ZD ; show zone armed message mvi a,ST_main ; next mode call ww_set ; wait for a keypress ret ;!/////////////////////////// mode 10 - 30 : set menus 00-20 P_mset: lda modecode; sui 10 mov c,a call menuset ret ;/////////////////////////// mode 31,32 : in passwords.asm ;/////////////////////////// mode 33 : wrong code 3 times P3times: mvi c,0 call menuSet ; return to main menu mvi c,5 call au_mode ; sound a 2 second Khz tone ret; ;/////////////////////////// mode 34 - 3B : configure zones 1-8 Z_cdata: .byte 00,23,11,13,10,10,33,0FF P_Zconfig: lxi hl,modecode; mov a,m sui 34 ; so 00 = zone 1 call z_setactive adi 09 ; password 09+zone lxi hl,z_cdata mov m,a sui 09 call SZgindicator ; load show indicator flag call pa_setup ret ;/////////////////////////// mode 3C : Window maxsecurity On P_WSmax: lxi hl,z_active mov a,m call SZ_maxSecure ; set the bit mvi c,sc_mxw call lcd_setMsg ; confirmation message mvi c,3E call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// mode 3D : Window maxsecurity Off P_WSmin: lxi hl,z_active mov a,m call SZ_minSecure ; set the bit mvi c,sc_mnw call lcd_setMsg ; confirmation message mvi c,3E call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// mode 3E : Wait 2 seconds, then Zconfig menu P_wwait: lxi hl,pw_timer mov a,m cpi 0 ; has timer counted down to 0? jnz pewwait ; no... finished mvi c,st_zconfig ; yes, init Zconfig menu call setmode Pewwait:ret ;/////////////////////////// mode 3F : misc setup get password Z_msdata: .byte 00,3C,78,st_misc,10,10,33,0FF P_Zsconfig: lxi hl,z_msdata mvi a,0FF ; show indicator call pa_setup ret ;/////////////////////////// Mode 40 - 47 : select doors 1-8 P_DSel: lxi hl,modecode mov a,m ; get the mode that called this routine sbi 40 ; find the corresponding door number call z_setactive mvi c,st_dc ; set door configure menu call setmode ret ;/////////////////////////// Mode 48 : set door controlling zone menu P_DSCZ: lxi hl,Z_active mov c,m ; get door that we're configuring call SDgCtZone ; get old controlling zone adi 31 ; convert to ascii lxi hl,old_zone ; save in message line mov m,a mvi c,23 ; mode to setup chooser menu call setmode ret ;/////////////////////////// Mode 49-51 : set door controlling zone P_DSCt: lxi hl,modecode mov a,m sui 49 lxi hl,z_active mov c,m ; c = door number call SD_unlock ; make sure the door is unlocked call SD_unsecure ; make sure the door is unsecured call SD_CtZone lxi hl,new_zone adi 31 mov m,a sbi 31 ; back to raw zone number call SZglock ; is the zone locked cpi 00 jz p1dsct ; no, do nothing more call SD_relock ; yes, lock the door p1dsct: mvi c,sc_cts call lcd_setMsg ; confirmation message mvi c,0C6 call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// Mode 52 : set door connecting zone menu P_DSnZ: lxi hl,Z_active mov c,m ; get door that we're configuring call SDgCnZone ; get old connecting zone adi 31 ; convert to ascii lxi hl,old_zone ; save in message line mov m,a mvi c,24 ; mode to setup chooser menu call setmode ret ;/////////////////////////// Mode 53-5A : set door connecting zone P_DSCn: lxi hl,modecode mov a,m sui 53 lxi hl,z_active mov c,m ; c = door number call SD_unsecure call SD_CnZone lxi hl,new_zone adi 31 mov m,a mvi c,sc_cns call lcd_setMsg ; confirmation message mvi c,0C6 call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// Mode 5B - 62 : select windows 1-8 P_WSel: lxi hl,modecode mov a,m ; get the mode that called this routine sui 5B ; find the corresponding door number call z_setactive mvi c,st_wc ; set window configure menu call setmode ret ;/////////////////////////// Mode 63 : set window controlling zone menu P_WSCZ: lxi hl,Z_active mov c,m ; get window that we're configuring call SWgCtZone ; get old controlling zone adi 31 ; convert to ascii lxi hl,old_zone ; save in message line mov m,a mvi c,25 ; mode to setup chooser menu call setmode ret ;/////////////////////////// Mode 64-6C : set window controlling zone P_WSCt: lxi hl,modecode mov a,m sui 64 lxi hl,z_active mov c,m ; c = window number call SW_CtZone lxi hl,new_zone adi 31 mov m,a mvi c,sc_wcs call lcd_setMsg ; confirmation message mvi c,0C6 call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// Mode 6D-6F : set panic mode P_panMode: lxi hl,modecode mov a,m sui 6C lxi hl,panicMode mov m,a adi 56 lxi hl,pan_show mov m,a mvi c,sc_pns call lcd_setMsg ; confirmation message mvi c,0C6 call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// Mode 70-72 : set intrusion mode P_inMode: lxi hl,modecode mov a,m sui 6F lxi hl,IntrusionMode mov m,a adi 56 lxi hl,in_show mov m,a mvi c,sc_ins call lcd_setMsg ; confirmation message mvi c,0C6 call setmode ; pause lxi hl,pw_timer mvi a,2 mov m,a ret ;//////////////////////////// Time adjusters - modes 73 - 7A ta_min : .byte 00 ta_hr : .byte 00 ta2init: ; adjust auto arming time lxi hl,z_active mov c,m mvi b,0 lxi hl,a_times dad bc dad bc mov d,m ; d = hours inx hl mov e,m ; e = minutes lxi hl,ta_min mov m,e lxi hl,ta_hr mov m,d mvi c,27 call setmode ; set mode to adjust menu 2 mov a,d lxi hl,aatime call c_decode ; write hours in ascii inx hl inx hl inx hl mov a,e call c_decode ; write minutes in ascii ret ta1init: ; adjust system time lxi hl,c_min mov b,m lxi hl,ta_min mov m,b lxi hl,c_hour mov a,m lxi hl,ta_hr mov m,a mvi c,26 call setmode ; set mode to adjust menu 1 mov c,a ; save hours lxi hl,systime call c_decode ; write a as ascii at HL inx hl inx hl inx hl mov a,b ; a = minutes call c_decode ; decode that too ret A_Times: .byte 0,0 ; Zone 1 Auto arming start .byte 0,0 ; Zone 2 Auto arming start .byte 0,0 ; Zone 3 Auto arming start .byte 0,0 ; Zone 4 Auto arming start .byte 0,0 ; Zone 5 Auto arming start .byte 0,0 ; Zone 6 Auto arming start .byte 0,0 ; Zone 7 Auto arming start .byte 0,0 ; Zone 8 Auto arming start ta2set: lxi hl,ta_min mov d,m ; D = new minutes lxi hl,ta_hr mov e,m ; E = new hours lxi hl,z_active mov c,m ; c = zone number mvi b,0 ; BC = active zone lxi hl,A_times dad bc dad bc ; HL = arming time for this zone mov m,e ; save hours inx hl mov m,d ; save minutes mvi c,st_aarm; back to menu call setmode ret ta1set: lxi hl,ta_min mov a,m lxi hl,c_min mov m,a lxi hl,ta_hr mov a,m lxi hl,c_hour mov m,a lxi hl,c_sec mvi a,0 mov m,a call c_refresh mvi c,st_misc call setmode ret ta_hru: lxi hl,ta_hr mov a,m inr a cpi 18 jnz ta_ehr mvi a,0 ta_ehr: mov m,a lxi hl,systime call c_decode ; write a as ascii at HL lxi hl,aatime call c_decode mvi c,st_menu call setmode ret ta_hrd: lxi hl,ta_hr mov a,m dcr a cpi 0FF jnz ta_ehr mvi a,17 jmp ta_ehr ta_mu: lxi hl,ta_min mov a,m inr a cpi 3C jnz ta_em mvi a,0 ta_em: mov m,a lxi hl,systime inx hl inx hl inx hl call c_decode ; write a as ascii at HL lxi hl,aatime inx hl inx hl inx hl call c_decode mvi c,st_menu call setmode ret ta_md: lxi hl,ta_min mov a,m dcr a cpi 0FF jnz ta_em mvi a,3B jmp ta_em ;//////////////////////// modes 7B-85 a_ints: .byte 0 ; Zone 1 interval .byte 0 ; Zone 2 interval .byte 0 ; Zone 3 interval .byte 0 ; Zone 4 interval .byte 0 ; Zone 5 interval .byte 0 ; Zone 6 interval .byte 0 ; Zone 7 interval .byte 0 ; Zone 8 interval a_sint: lxi hl,modecode mov a,m sui 7B ; A = button pressed lxi hl,z_active mov c,m mvi b,0 ; BC = zone being configured lxi hl,a_ints dad bc ; HL = correct entry in table mov m,a adi 2B ; menu data line for button [0] lxi hl,a_aid mov m,a ; copies menu entry to feedback mvi c,sc_aai call lcd_setmsg mvi c,st_aaw ; wait call setmode lxi hl,pw_timer mvi a,2 mov m,a ret ;/////////////////////////// mode 86 : Wait 2 seconds, then Aarm menu P_aaw: lxi hl,pw_timer mov a,m cpi 0 ; has timer counted down to 0? jnz peaaw ; no... finished mvi c,st_aarm ; yes, init Aarm menu call setmode Peaaw:ret ;////////////////////////// mode 87,88: set 3 times flag P_3times: lxi hl,modecode mov a,m sui 87 lxi hl,a3times mov m,a mvi c,st_misc call setmode ret ;///////////////////////// PH_fire: .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 PH_panic: .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 PH_intrusion: .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 PH_input: .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 PH_target: .word 0 ; points to number buffer PH_iFire: ; init fire lxi hl,ph_fire shld ph_target lxi hl,MS_pha mvi a,80 mov m,a jmp ph_init PH_ipanic: ; init panic lxi hl,ph_panic shld ph_target lxi hl,MS_pha mvi a,7F mov m,a jmp ph_init PH_iintrusion: lxi hl,ph_intrusion shld ph_target lxi hl,MS_pha mvi a,81 mov m,a jmp ph_init ph_cnt: .byte 0 phtar: .byte 0 ph_d2a: ; data at BC to ascii at DE, 15 characters, spaces fill unused push af push hl mov h,b ; hl = bc mov l,c mov a,m ; m = num chars lxi hl,phtar mov m,a ; save target num mvi a,0 lxi hl,ph_cnt mov m,a ; reset counter inx bc ph2d2a: lxi hl,phtar ; does count = num of characters cmp m jz ph3d2a ; yes, fill the rest with spaces mov h,b mov l,c ; hl = bc mov a,m ; a = data adi 30 ; convert to ASCII mov h,d ; hl = de mov l,e mov m,a ; save it lxi hl,ph_cnt mov a,m ; load count inr a ; increment inx de inx bc mov m,a jmp ph2d2a ph3d2a: cpi 0F ; does count = 15 jz ph4d2a ; yes, finished mvi a,20 mov h,d ; hl = de mov l,e mov m,a ; save it lxi hl,ph_cnt mov a,m ; load count inr a ; increment inx de mov m,a jmp ph3d2a ph4d2a: pop hl pop af ret ph_update: ; updates the ascii feedback push bc push de push hl lxi bc,ph_input lxi de,new_ph call ph_d2a lhld ph_target mov b,h mov c,l lxi de,old_ph call ph_d2a pop hl pop de pop bc ret ph_init: mvi a,0 lxi hl,ph_input mov m,a ; set length to zero call ph_update mvi c,28 call setmode ret ph_numpressed: ; // modes 8c - 95 lxi hl,modecode mov a,m sui 8C mov e,a lxi hl,ph_input mov a,m cpi 0F ; is buffer already full? jz pheNumpressed inr a mov m,a mov c,a mvi b,0 dad bc mov m,e call ph_update pheNumpressed: mvi c,st_menu call setmode ret ph_entered: lhld ph_target lxi bc,ph_input mvi a,0 ph2ent: push hl mov h,b mov l,c ; HL = BC (input buffer) mov e,m ; load character pop hl ; restore HL = output buffer mov m,e ; save character inx bc inx hl inr a cpi 10 jnz ph2ent mvi c,st_misc call setmode ret ;//////////////////////// Password changing routines pc_table: .byte 00,00,00,0FF,00,00 pc_okmode: .byte 00 pc_init: ; password changing init ; input : C = mode if ok, B = mode if cancelled ; D = line 1 of display lxi hl,pc_table mvi a,97 mov m,a inx hl mov m,b inx hl inx hl inx hl mov m,d inx hl mvi e,85 mov m,e lxi hl,pc_okmode mov m,c lxi hl,pc_table mvi a,0FF call pw_init call pw_rst ret pc_st2: ; password change, step 2 mvi c,11 call pa_set lxi hl,pc_table mvi a,98 mov m,a inx hl inx hl inx hl inx hl inx hl mvi e,86 mov m,e lxi hl,pc_table mvi a,0FF call pw_init call pw_rst ret pc_st3: ; password change, step 3 ; if they match, go to changing mode ; otherwise, show an error screen and cancel mvi c,11 call pa_compare cpi 00 jz pc_st4 mvi c,sc_pme call lcd_setmsg ; show error message mvi c,99 call setmode ; wait for 2 seconds lxi hl,pw_timer mvi a,2 mov m,a ret pc_st4: lxi hl,pc_okmode mov c,m call setmode ret pc_st5: lxi hl,pw_timer mov a,m cpi 0 ; has timer counted down to 0? jnz pc_st6 ; no... finished lxi hl,pc_table inx hl mov c,m ; load cancel mode call setmode pc_st6:ret ;//////////////////////////////////////////// mode 9C yy_az1: ; change zone's arming password mvi d,89 mvi B,st_zaccess mvi c,9A call pc_init ret ;//////////////////////////////////////////// mode 9A yy_az2: ; mode 9A calls this lxi hl,z_active mov a,m adi 01 mov c,a call pa_set mvi c,st_zaccess call setmode ret ;//////////////////////////////////////////// mode 9D yy_dz1: ; change zone's disarming password mvi d,8A mvi B,st_zaccess mvi c,9B call pc_init ret ;//////////////////////////////////////////// mode 9B yy_dz2: ; mode 9B calls this lxi hl,z_active mov a,m adi 09 mov c,a call pa_set mvi c,st_zaccess call setmode ret ;//////////////////////////////////////////// modes 9e yy_da1: ; change all zone's disarming password mvi d,8C mvi B,st_access mvi c,9F call pc_init ret ;//////////////////////////////////////////// mode 9F yy_da2: ; mode 9F calls this mvi a,9 yy_da3: mov c,a call pa_set ; change password inr a ; next zone cpi 11 ; gone too high yet? jnz yy_da3 ; set zone mvi c,st_access call setmode ret ;//////////////////////////////////////////// modes a0 yy_aa1: ; change all zone's arming passwords mvi d,8B mvi B,st_access mvi c,0A1 call pc_init ret ;//////////////////////////////////////////// mode A1 yy_aa2: mvi a,1 yy_aa3: mov c,a call pa_set ; change password inr a ; next zone cpi 9 ; gone too high yet? jnz yy_aa3 ; set zone mvi c,st_access call setmode ret ;//////////////////////////////////////////// modes a2,a3 yy_m1: ; change master password mvi d,8D mvi B,st_access mvi c,0A3 call pc_init ret yy_m2: ; mode A3 calls this mvi c,0 call pa_set ; change password mvi c,st_access call setmode ret ;//////////////////////////////////////////// modes A4, A5 sm_set: lda modecode sui 0A4 sta smokeStat lda c_min sta smoketime mvi c,st_config call setmode ret ;/////////////////////////////////// mode A6 dia_init: call ala_off mvi c,2A call setmode ret ;/////////////////////////////////// mode A7 dia_done: call ala_on mvi c,st_misc call setmode ret ;/////////////////////////////////// mode A8-AF dia_DL: lda modecode sui 0A8 mov c,a call SDgLock cpi 00 jz dia1dl call sd_relock jmp dia2dl dia1dl: ; locked call sd_unlock dia2dl: mvi c,st_menu call setmode ret ;/////////////// mode B0 - save door lock status, then run menu di_dls: .byte 0 dia_sd: lda SD_lock sta di_dls mvi c,2B call setmode ret ;/////////////// mode B1 - restore door lock status, then run menu dia_rd: lda di_dls sta SD_lock call SD_rst mvi c,2A call setmode ret ;//////////////// modes B2-BB test sounds au_tst: lda modecode sui 0B2 mov c,a call au_mode mvi a,0 sta menutime mvi c,ST_menu call setmode ret ;//////////////// modes BC-c5 test blinker bl_tst: lda modecode sui 0BC mov c,a call bl_mode mvi a,0 sta menutime mvi c,ST_menu call setmode ret ;/////////////////////////// mode C6 : Wait 2 seconds, then misc menu M_wwait: lxi hl,pw_timer mov a,m cpi 0 ; has timer counted down to 0? jnz pewwait ; no... finished mvi c,st_misc ; yes, init Zconfig menu call setmode Mewwait:ret ;///////////////////////// mode C7 : Scrolling Speed slower scsps: lxi hl,lcdscp; inx hl mov a,m cpi 0F8 jz scespf adi 08 mov m,a scespf: mvi c,ST_menu call setmode ret ;///////////////////////// mode C8 : Scrolling Speed faster scspf: lxi hl,lcdscp; inx hl mov a,m cpi 20 jz scispf sui 08 mov m,a scispf: mvi c,ST_menu call setmode ret ;//////////////////////////// Mode C9 - smoke alarm password yy_s1: mvi d,0AB mvi B,st_access mvi c,0CA call pc_init ret ;///////////////////////////// Mode CA yy_s2: ; mode CA calls this mvi c,12 call pa_set ; change password mvi c,st_access call setmode ret ;//////////////////////////// Mode CB - panic alarm password yy_p1: mvi d,0AC mvi B,st_access mvi c,0CC call pc_init ret ;///////////////////////////// Mode CC yy_p2: ; mode CA calls this mvi c,13 call pa_set ; change password mvi c,st_access call setmode ret ;/////////////////////////// mode CD : get smoke password -menu Z_smpdata: .byte 12,0AB,11,0CE,ST_MAIN,ST_MAIN,ST_MAIN,0FF Z_spg: lxi hl,z_smpdata mvi A,0FF call pa_setup ret ;///////////////////////// Mode CE: show smoke disable screne z_sss: mvi C,sc_smd mvi a,0A5 call ww_set ret ;///////////////////////// Mode D0: show panic off screen z_ppp: mvi C,sc_pad call lcd_setmsg mvi c,0D1 call setmode ret ;///////////////////////// Mode D1: wait for a keypress to stop panic z_ppp2: call keyget cpi KS_none jz z_ppp3; mvi C,0D4 ; call setmode ; store the new mode z_ppp3: ret; ;///////////// Mode D2: Smoke alarm - password accepted v_s_ok: mvi a,01 sta smokestat mvi a,0 sta smoked lda c_mins sta smoketime call taRestoreState ret ;///////////// Mode D3: Smoke alarm - password cancelled v_s_data: .byte 12, 0, 0AB, 0D7, 0D3, 0D3, 0D3, 0FF; v_s_cancel: lxi hl,v_s_data mvi a,0FF call pa_setup call pw_rst ; reset timeout ret ;///////////// Mode D4: Panic alarm - password accepted v_p_ok: xra a ; A = 0 sta tq1 ; clear tq byte sta panic ; clear panic flag call taRestoreState ret ;///////////// Mode D5: Panic alarm - password cancelled v_p_data: .byte 13, 0, 0AC, 0D8, 0D5, 0D5, 0D5, 0FF; v_p_cancel: lxi hl,v_p_data mvi a,0FF call pa_setup call pw_rst ; reset timeout ret ;/////////// Mode D7: wait for key, then mode D2 v_swa: mvi a,0D2 mvi c,SC_smd ; smode alarm disable screen call ww_set ret ;/////////// Mode D8: wait for key, then mode D4 v_swp: mvi a,0D4 mvi c,sc_pad ;panic off screen call ww_set ret ;//////////// Mode D9: "normal" zone alarm triggered v_z1data: .byte 00, 0, 0B9, 0DC, 0D9, 0D9, 0D9, 0FF; v_z1trig: lda a_zone adi 9 sta v_z1data ; set password we want adi 28 ; convert zone to ASCII sta vv_zb ; save it in the prompt lda intrusionmode ani 1 ; check the audible alarm bit cpi 0 jz vzzss ; not set, no beeper mvi c,AL_zone call au_mode ; set beeper vzzss: lxi hl,v_z1data lda a_zone call SZgindicator ; show characters?? call pa_setup call pw_rst ; reset timeout ret ;//////////// Mode DA: timeout zone alarm triggered v_z2data: .byte 00, 0, 0BA, 0DC, 0DD, 0DB, 0DD, 01B; v_z2trig: lda a_zone adi 9 sta v_z2data ; set password we want adi 28 ; convert zone to ASCII sta vv_zt ; save it in the prompt mvi c,AL_time call au_mode ; set beeper lxi hl,v_z2data lda a_zone call SZgindicator ; show characters?? call pa_setup call pw_rst ; reset timeout ret ;//////////// Mode DB: relay between zone alarms ; This mode is entered when mode DA times out, and causes the ; normal alarm sequence to occur. It is also the place where ; a call to send a UART message should be made. v_relay: mvi c,0D9 call setmode mvi e,4 ; alarm mode 4 - timeout expired lda v_door ; load violated door number mov c,a ; c = offending door call u_intrusion ; passing parameters E and C ret ;///////////// Mode DC : disarm an alarmed zone v_zdisarm: lda a_zone ; get zone thats causing trouble mov b,a call SZ_unlock ; disarm it ;// need to check all doors windows, and mask off tq ;// bits for the ones controlled by this zone lxi hl,t_masks mvi c,0 lxi de,0FFFF vzd2: call SDgCtZone ; get door's controlling zone cmp b ; is it the alarmed zone? jnz vzd1 ; no, check windows mov a,d ; A = door bits xra m ; if so, clear the bit mov d,a ; D = new door bits vzd1: call SWgCtZone ; get window's controlling zone cmp b ; is it the alarmed zone? jnz vzd3 ; no, check next lot mov a,e ; A = window bits xra m ; if so, clear the bit mov e,a ; E = new door bits call SW_unsecure; unsecure the window vzd3: inr c ; next door inx hl ; next mask mvi a,8 ; number of doors cmp c ; have we checked them all? jnz vzd2 ; no, do the next lda tq2 ana e sta tq2 lda tq3 ana d sta tq3 lda tq4 ana d sta tq4 ;// stop alarms mvi c,0 call au_mode ; switch off beeper call bl_mode ; switch off blinker ;// would also send a "disarmed" UART message call taRestoreState ret ;///////////// Mode DD : timeout had a cancel condition v_z2can: lxi hl,v_z2data lda a_zone call SZgindicator ; show characters?? call pa_setup ret ;////////////// Mode DE : Set "show status" mode ssss: mvi c,sc_sss call lcd_setmsg mvi c,0DF call setmode ret ;////////////// Mode DF : system status screen sss1: call keyget cpi KS_none jnz sss2 ; key pressed... change mode ;///// Codes: S = secure, L=locked and unsecure, ;///// O=open&unlocked, C=closed & unlocked ;//////////////// Zones mvi c,0 lxi hl,sssZ sssz4: mov a,c call SZgsecure cpi 00 jnz sssz1 ; jump if secure mov a,c call SZgLock cpi 00 jnz sssZ2 ; jump if locked mvi A,20 ; ASCII space jmp sssZ3 sssz2: mvi A,4C ; ASCII "L" jmp sssZ3 sssz1: mvi A,53 ; ASCII "S" sssz3: mov m,a inx hl inr c mvi a,8 cmp c jnz sssz4 ;//////////////// Doors mvi c,0 lxi hl,sssD sssd4: mov a,c call SDgsecure cpi 00 jnz sssd1 ; jump if secure mov a,c call SDgLock cpi 00 jz sssd2 ; jump if locked mov a,c call sDgOpen cpi 00 jz sssd5 ; jump if closed mvi A,4F ; ASCII "O" jmp sssd3 sssd5: mvi A,43 ; ASCII "C" jmp sssd3 sssd2: mvi A,4C ; ASCII "L" jmp sssd3 sssd1: mvi A,53 ; ASCII "S" sssd3: mov m,a inx hl inr c mvi a,8 cmp c jnz sssd4 ;//////////////// Windows mvi c,0 lxi hl,sssW sssw4: mov a,c call SWgsecure cpi 00 jnz sssw1 ; jump if secure mov a,c call SWgLock cpi 00 jnz sssw2 ; jump if locked mov a,c call sWgOpen cpi 00 jz sssw5 ; jump if closed mvi A,4F ; ASCII "O" jmp sssw3 sssw5: mvi A,43 ; ASCII "C" jmp sssw3 sssw2: mvi A,4C ; ASCII "L" jmp sssw3 sssw1: mvi A,53 ; ASCII "S" sssw3: mov m,a inx hl inr c mvi a,8 cmp c jnz sssw4 ;//////////////////// ret sss2: mvi c,st_main call setmode ret ;////////////////////////// Mode E0 - wait for a keypress ww_mode: .byte 0 ww_set: push af call lcd_setmsg ;inputs: C = screen number sta ww_mode ; A = mode to change to mvi a,0E0 sta modecode pop af ret ww_wait:call keyget ; called by mode E0 cpi ks_none jz ww_end lda ww_mode sta modecode ww_end: ret ;////////////////////////// Mode E1 - indicators on iii_on: lda z_active lxi bc,0 mov c,a lxi hl,Zonedata dad bc mov a,m ori 40 mov m,a mvi c,st_zconfig call setmode ret ;////////////////////////// Mode E2 - indicators off iii_off: lda z_active lxi bc,0 mov c,a lxi hl,Zonedata dad bc mov a,m ani 0A0 mov m,a mvi c,st_zconfig call setmode ret

This is page designed, maintained and
(C)opyright 1999 by Geoff Knagge