size = { 200, 400 }

defineProperty("lan_gear_warn", globalPropertyi("cl300/lan_gear_warn"))

defineProperty("ice_test", globalPropertyi("cl300/ice_test"))
defineProperty("rudlim_test", globalPropertyi("cl300/rudlim_test"))
defineProperty("probs_test",  globalPropertyi("cl300/probs_test"))
defineProperty("mfd_pan_cas", globalPropertyi("cl300/mfd_pan_cas"))
defineProperty("config_warn", globalPropertyi("cl300/config_warn"))
defineProperty("cabalt_warn", globalPropertyi("cl300/cabalt_warn"))

defineProperty("red_cas",    globalPropertyi("cl300/red_cas"))
defineProperty("yellow_cas", globalPropertyi("cl300/yellow_cas"))
defineProperty("has_cas",    globalPropertyi("cl300/has_cas")) -- JackZero: New dataref

cas_texts  = {}
cas_colors = {}
for i = 1,25 do
	cas_texts[i]  = globalPropertys("cl300/cas_line_"..i.."_text")
	cas_colors[i] = globalPropertyi("cl300/cas_line_"..i.."_color")
	defineProperty("cas_line_"..i.."_text",  cas_texts[i])
	defineProperty("cas_line_"..i.."_color", cas_colors[i])
end

defineProperty("pulse", globalPropertyi("sim/graphics/animation/lights/normal[0]"))
defineProperty("night_lights", globalPropertyi("sim/graphics/scenery/percent_lights_on"))
defineProperty("dcp_radar", globalPropertyi("cl300/dcp_radar"))
defineProperty("dcp_1_2", globalPropertyi("cl300/dcp_1_2"))
defineProperty("dcp_dmeh", globalPropertyi("cl300/dcp_dmeh"))
defineProperty("left_bat_h", globalPropertyi("cl300/left_bat_h"))
defineProperty("right_bat_h", globalPropertyi("cl300/right_bat_h"))
defineProperty("bus_tie_h", globalPropertyf("cl300/bus_tie_h"))
defineProperty("autopilot_mode", globalPropertyi("sim/cockpit/autopilot/autopilot_mode"))
defineProperty("flaprqst", globalPropertyf("sim/flightmodel/controls/flaprqst"))

defineProperty("ENGN_running_l", globalPropertyi("sim/flightmodel/engine/ENGN_running[0]"))
defineProperty("ENGN_running_r", globalPropertyi("sim/flightmodel/engine/ENGN_running[1]"))
defineProperty("reverser_on_1", globalPropertyi("sim/cockpit2/annunciators/reverser_on[0]"))
defineProperty("reverser_on_2", globalPropertyi("sim/cockpit2/annunciators/reverser_on[1]"))
defineProperty("prop_mode_0", globalPropertyi("sim/cockpit2/engine/actuators/prop_mode[0]")) -- JackZero: Added
defineProperty("prop_mode_1", globalPropertyi("sim/cockpit2/engine/actuators/prop_mode[1]")) -- JackZero: Added
defineProperty("thrust_reverser_deploy_ratio_0", globalPropertyf("sim/flightmodel2/engines/thrust_reverser_deploy_ratio[0]")) -- JackZero: Added
defineProperty("thrust_reverser_deploy_ratio_1", globalPropertyf("sim/flightmodel2/engines/thrust_reverser_deploy_ratio[1]")) -- JackZero: Added


defineProperty("radio_altimeter_height_ft_pilot", globalPropertyf("sim/cockpit2/gauges/indicators/radio_altimeter_height_ft_pilot"))
defineProperty("carets", globalPropertyi("cl300/carets"))
defineProperty("sbrk_h", globalPropertyf("cl300/sbrk_h"))
defineProperty("m_fuel_total", globalPropertyi("sim/flightmodel/weight/m_fuel_total"))

defineProperty("cabin_altitude_ft", globalPropertyf("sim/cockpit2/pressurization/indicators/cabin_altitude_ft"))
defineProperty("pressure_diffential_psi", globalPropertyf("sim/cockpit2/pressurization/indicators/pressure_diffential_psi"))

defineProperty("taws_ter_h", globalPropertyi("cl300/taws_ter_h"))
defineProperty("taws_flp_h", globalPropertyi("cl300/taws_flp_h"))
defineProperty("taws_gs_h", globalPropertyi("cl300/taws_gs_h"))
defineProperty("yaw_damper_on", globalPropertyi("sim/cockpit2/switches/yaw_damper_on"))
defineProperty("APU_generator_on", globalPropertyi("sim/cockpit2/electrical/APU_generator_on"))
defineProperty("APU_running", globalPropertyi("sim/cockpit2/electrical/APU_running"))
defineProperty("nws_h", globalPropertyi("cl300/nws_h"))
defineProperty("aircond_airsource", globalPropertyi("cl300/aircond_airsource"))
defineProperty("dcu_a_h", globalPropertyi("cl300/dcu_a_h"))
defineProperty("dcu_b_h", globalPropertyi("cl300/dcu_b_h"))
defineProperty("fire_autoapr_h", globalPropertyi("cl300/fire_autoapr_h"))
defineProperty("autopilot_disconnect", globalPropertyi("sim/cockpit/warnings/annunciators/autopilot_disconnect"))
defineProperty("bleed_status", globalPropertyi("cl300/bleed_status"))
defineProperty("customslider3_r", globalPropertyf("cl300/customslider3_r"))
defineProperty("customslider2_r", globalPropertyf("cl300/customslider2_r"))
defineProperty("customslider4_r", globalPropertyf("cl300/customslider4_r"))
defineProperty("pressure_ditch_h", globalPropertyi("cl300/pressure_ditch_h"))
defineProperty("pressure_emer_depr_h", globalPropertyi("cl300/pressure_emer_depr_h"))
defineProperty("antice_engn_r_h", globalPropertyi("cl300/antice_engn_r_h"))
defineProperty("antice_engn_l_h", globalPropertyi("cl300/antice_engn_l_h"))
defineProperty("fire_engn_r_h", globalPropertyi("cl300/fire_engn_r_h"))
defineProperty("fire_engn_l_h", globalPropertyi("cl300/fire_engn_l_h"))
defineProperty("en_but_run_l", globalPropertyi("cl300/en_but_run_l"))
defineProperty("en_but_run_r", globalPropertyi("cl300/en_but_run_r"))
defineProperty("fuel_balanced", globalPropertyi("cl300/fuel_balanced"))
defineProperty("fuel_xflow_up_h", globalPropertyi("cl300/fuel_xflow_up_h"))
defineProperty("fuel_xflow_dn_h", globalPropertyi("cl300/fuel_xflow_dn_h"))
defineProperty("fuel_xpump_l", globalPropertyi("cl300/fuel_xpump_l"))
defineProperty("fuel_xpump_r", globalPropertyi("cl300/fuel_xpump_r"))
defineProperty("electr_gen_l_h", globalPropertyi("cl300/electr_gen_l_h"))
defineProperty("electr_gen_r_h", globalPropertyi("cl300/electr_gen_r_h"))
defineProperty("ground_sp_h", globalPropertyi("cl300/ground_sp_h"))
defineProperty("aux_hpump_h", globalPropertyi("cl300/aux_hpump_h"))
defineProperty("l_hpump_h", globalPropertyi("cl300/l_hpump_h"))
defineProperty("r_hpump_h", globalPropertyi("cl300/r_hpump_h"))
defineProperty("ptu_h", globalPropertyi("cl300/ptu_h"))
defineProperty("hydr_l_sov_h", globalPropertyi("cl300/hydr_l_sov_h"))
defineProperty("hydr_r_sov_h", globalPropertyi("cl300/hydr_r_sov_h"))
defineProperty("hd_r_engn_state", globalPropertyi("cl300/hd_r_engn_state")) -- JackZero: Changed to new dataref
defineProperty("pressure_man_h", globalPropertyi("cl300/pressure_man_h"))
defineProperty("parkbrake", globalPropertyf("sim/flightmodel/controls/parkbrake"))
defineProperty("onground_all", globalPropertyf("sim/flightmodel/failures/onground_all"))
defineProperty("oxigen_ox", globalPropertyi("cl300/oxigen_ox"))
defineProperty("pitch_d_2", globalPropertyi("cl300/pitch_d_2"))
defineProperty("aircond_ramair_h", globalPropertyi("cl300/aircond_ramair_h"))
defineProperty("flight_spoil_h", globalPropertyi("cl300/flight_spoil_h"))
defineProperty("trim_stab", globalPropertyi("cl300/trim_stab"))
defineProperty("electr_stbi_h", globalPropertyi("cl300/electr_stbi_h"))
defineProperty("antice_wing_h", globalPropertyi("cl300/antice_wing_h"))
defineProperty("antice_wngsource_r", globalPropertyi("cl300/antice_wngsource_r"))
defineProperty("bleed_xbleed_h", globalPropertyi("cl300/bleed_xbleed_h"))
defineProperty("ice", globalPropertyi("sim/cockpit2/annunciators/ice"))
defineProperty("rel_ice_detect", globalPropertyi("sim/operation/failures/rel_ice_detect"))
defineProperty("airdat1_fault", globalPropertyi("cl300/airdat1_fault"))
defineProperty("airdat2_fault", globalPropertyi("cl300/airdat2_fault"))
defineProperty("ground_sp_h", globalPropertyi("cl300/ground_sp_h"))
defineProperty("fuel_imbalanced", globalPropertyi("cl300/fuel_imbalanced"))
defineProperty("rel_genera0", globalPropertyi("sim/operation/failures/rel_genera0"))
defineProperty("rel_genera1", globalPropertyi("sim/operation/failures/rel_genera1"))
defineProperty("outbrks_low", globalPropertyi("cl300/outbrks_low"))
defineProperty("brks_low", globalPropertyi("cl300/brks_low"))
defineProperty("antice_probe_l_h", globalPropertyi("cl300/antice_probe_l_h"))
defineProperty("antice_probe_r_h", globalPropertyi("cl300/antice_probe_r_h"))
defineProperty("antice_wings_xbleed_valve", globalPropertyi("cl300/antice_wings_xbleed_valve"))
defineProperty("trim_pusher_h", globalPropertyi("cl300/trim_pusher_h"))
defineProperty("fuel_pump_l_astate", globalPropertyi("cl300/fuel_pump_l_astate"))
defineProperty("fuel_pump_r_astate", globalPropertyi("cl300/fuel_pump_r_astate"))
defineProperty("electr_ess_p_status", globalPropertyi("cl300/electr_ess_p_status"))
defineProperty("rel_startr0", globalPropertyi("sim/operation/failures/rel_startr0"))
defineProperty("rel_startr1", globalPropertyi("sim/operation/failures/rel_startr1"))
defineProperty("elevator_trim", globalPropertyf("sim/cockpit2/controls/elevator_trim"))
defineProperty("aileron_trim", globalPropertyf("sim/cockpit2/controls/aileron_trim"))
defineProperty("rudder_trim", globalPropertyf("sim/cockpit2/controls/rudder_trim"))
defineProperty("flaprqst", globalPropertyf("sim/flightmodel/controls/flaprqst"))
defineProperty("gear_warn", globalPropertyi("cl300/gear_warn"))
defineProperty("rel_engfir0", globalPropertyi("sim/operation/failures/rel_engfir0"))
defineProperty("rel_engfir1", globalPropertyi("sim/operation/failures/rel_engfir1"))
defineProperty("rel_lbrakes", globalPropertyi("sim/operation/failures/rel_lbrakes"))
defineProperty("rel_rbrakes", globalPropertyi("sim/operation/failures/rel_rbrakes"))
defineProperty("rel_ignitr0", globalPropertyi("sim/operation/failures/rel_ignitr0")) -- JackZero: Added for ENG IGN FAULT
defineProperty("rel_ignitr1", globalPropertyi("sim/operation/failures/rel_ignitr1")) -- JackZero: Added for ENG IGN FAULT

defineProperty("rembf1", globalPropertyi("cl300/rembf1"))
defineProperty("rembf2", globalPropertyi("cl300/rembf2"))
defineProperty("rembf4", globalPropertyi("cl300/rembf4"))
defineProperty("rembf6", globalPropertyi("cl300/rembf6"))
defineProperty("rembf7", globalPropertyi("cl300/rembf7"))
defineProperty("rembf8", globalPropertyi("cl300/rembf8"))
defineProperty("rembf11", globalPropertyi("cl300/rembf11"))
defineProperty("rembf12", globalPropertyi("cl300/rembf12"))
defineProperty("rel_AOA", globalPropertyf("sim/operation/failures/rel_AOA"))
defineProperty("rel_ice_detect", globalPropertyf("sim/operation/failures/rel_ice_detect"))
defineProperty("rel_pitot", globalPropertyf("sim/operation/failures/rel_pitot"))
defineProperty("rel_pitot2", globalPropertyf("sim/operation/failures/rel_pitot2"))
defineProperty("rel_engfai0", globalPropertyf("sim/operation/failures/rel_engfai0"))
defineProperty("rel_engfai1", globalPropertyf("sim/operation/failures/rel_engfai1"))

defineProperty("elt_h", globalPropertyi("cl300/elt_h"))
defineProperty("emeright_h", globalPropertyf("cl300/emeright_h"))


local font1 = loadFont('font_7.fnt')
defineProperty("msgs", loadImage("menu1.png", 396, 329, 50, 24))

local wengns_antice   = 0
local wngxbleed       = 0
local passdoor        = 0
local cargodoor       = 0
local emerex          = 0
local flt_dep_status  = 0
local fuel_low        = 0
local park_b_w        = 0
local park_b_y        = 0
local ice_det         = 0
local cab_alt_status  = 0
local delta_p         = 0

local ail_trim_warn   = 0
local rud_trim_warn   = 0
local stb_trim_warn   = 0
local autop_warn      = 0
local flaps_warn      = 0
local spoil_warn      = 0
local pitch_disc_warn = 0
local roll_disc_warn  = 0

--[[
JackZero: I've done a complete rework of the code. The original code was extremely bulky (14.500 lines of code instead of now ~300).

Note to developers:
First off, some performance considerations: Since the main part of the code is only executed if a CAS message changes, the code isn't
extremely performance critical because in most frames, it will not run at all or at most for one or two messages. 
The CAS messages are shown as a list, with new messages being added on top. Therefore its essential to save the order in which the messages
appeared AND keep an eye on the order in which they are generated so they aren't wildly mixed in case of multiple messages appearing in the same 
frame (e.g. loading cold and dark).

The original code tracked the list position of every possible CAS message. Therefore it could simply remove the message from the list of shown
messages, instead of having to parse the whole list. This however meant that every time, a message changed, the positions all possible messages
needed to be checked and possibly shifted. Since there are many possible messages but only few are actually shown, it probably faster not to 
store the positions and instead just parse the list of shown messages for the message to delete. 
In addition, in order to determin if a message changed, the original code stored the previous states of the relevant datarefs instead of the 
previous state of the CAS message. It basically looked like this:

    if <calculation with current values> ~= <calculation with stored values> then
        -- message changed
        if <calculation with current values> then
            -- show message
        else
            -- remove message
        end
    end
    
Obviously, if we store the state of the CAS message instead of the datarefs, we don't need to repeat the calculation with the old values
every frame. In addition, if we wrap everything in a function (since the rest of the code (now) is identical for all messages), we also 
need to calculate the new state only once and pass that to the function call, therefore reducing again the calculations done every frame.
-]]

color_white  = {0.8,0.8,0.8,0xFFFFFF}
color_cyan   = {0.0,0.8,0.8,0x00FFFF}
color_red    = {0.8,0.0,0.0,0xFF0000}
color_yellow = {0.8,0.8,0.0,0xFFFF00}

line_text  = {}
line_color = {}

for i = 1,25 do
    line_text[i] = ""
    line_color[i] = color_red
end
 
line_red    = {}
line_yellow = {}
line_cyan   = {}
line_white  = {}

last_white = {}
last_yellow = {}
last_cyan   = {}
last_red    = {}

function updateList(lines, previous, index, state, message)
    if previous[index] == state then return end
    previous[index] = state
    if state then
        table.insert(lines, 1, message)
    else
        for l = 1,#lines do
            if lines[l] == message then
                table.remove(lines, l)
                break
            end
        end
    end
end

function update()

-- FLIGHT CONFIGURATION WARNINGS
stb_trim_warn   = 0
ail_trim_warn   = 0
rud_trim_warn   = 0
autop_warn      = 0
flaps_warn      = 0
spoil_warn      = 0
pitch_disc_warn = 0
roll_disc_warn  = 0

if get(onground_all) == 1 and (get(ENGN_running_l) > 0 or get(ENGN_running_r) > 0) then
	-- JackZero: Checking reverser_on_1/2 alone isn't sufficient
	local reverse_l = (get(reverser_on_1) > 0 or get(prop_mode_0) ~= 1 or get(thrust_reverser_deploy_ratio_0) > 0.1) 
	local reverse_r = (get(reverser_on_2) > 0 or get(prop_mode_1) ~= 1 or get(thrust_reverser_deploy_ratio_1) > 0.1)
	if get(carets) >= 2 and get(carets) < 5 and not reverse_l and not reverse_r  then
		-- throttle at APR, TO or CLB power, no reversers => takeoff
		stb_trim_warn = ((get(elevator_trim) < -0.33 or get(elevator_trim) > 0.035) and 1 or 0)
        ail_trim_warn = ((get(aileron_trim) < -0.01 or get(aileron_trim) > 0.01) and 1 or 0)
        rud_trim_warn = ((get(rudder_trim) < -0.01 or get(rudder_trim) > 0.01) and 1 or 0)
        autop_warn = ((get(autopilot_mode) > 1) and 1 or 0)
        flaps_warn = ((get(flaprqst) < 0.3 or get(flaprqst) > 0.7) and 1 or 0) -- flaps 1 or 2
        spoil_warn = ((get(sbrk_h) > 0.05) and 1 or 0)
        pitch_disc_warn = ((get(pitch_d_2) ~= 0) and 1 or 0)
        roll_disc_warn  = ((get(flight_spoil_h) == 1) and 1 or 0)
		set(config_warn, (stb_trim_warn+ail_trim_warn+rud_trim_warn+autop_warn+flaps_warn+spoil_warn+pitch_disc_warn+roll_disc_warn > 0) and 1 or 0)
	else
		set(config_warn, 0)
	end
elseif get(onground_all) == 0 then
	set(config_warn, get(parkbrake) > 0 and 1 or 0)
else
	set(config_warn, 0)
end


--CABIN ALTITUDE
if get(cabin_altitude_ft) > 9400 then
    cab_alt_status = 2
elseif get(cabin_altitude_ft) > 8500 then
	cab_alt_status = 1
else
	cab_alt_status = 0
end
set(cabalt_warn, cab_alt_status)

--CABIN DELTA P
if get(pressure_diffential_psi) < -0.5 or get(pressure_diffential_psi) > 9.2 then delta_p = 1 else delta_p = 0 end

-- CARGO DOOR
if get(customslider3_r) > 0.2 then
	if get(onground_all) == 0 or get(en_but_run_l) > 0 then
		cargodoor = 2
    else
		cargodoor = 1
    end
else
	cargodoor = 0
end

-- PASSENGER DOOR
if get(customslider2_r) > 0.2 then
	if get(onground_all) == 0 or get(en_but_run_l) > 0 then
        passdoor = 2
    else
        passdoor = 1
	end
else
	passdoor = 0
end

-- ICE
wengns_antice = 4 * get(antice_wing_h) + 2 * get(antice_engn_l_h) + get(antice_engn_r_h)

if get(ice) == 1 then
	if wengns_antice == 7 then
        ice_det = 1
    else
        ice_det = 2
    end
else
    ice_det = 0
end

-- MESSAGES ----------------------------------------------------------------------------------

-- RED 
updateList(line_red, last_red,  1, get(electr_ess_p_status) == 1, 					"ESSENTIAL POWER ONLY")
updateList(line_red, last_red,  2, cab_alt_status == 2,           					"CABIN ALTITUDE")
updateList(line_red, last_red,  3, delta_p == 1,                  					"CABIN DELTA P")
updateList(line_red, last_red,  4, get(parkbrake) == 1 and get(onground_all) == 0, 	"PARK/EMER BRAKE ON")
updateList(line_red, last_red,  5, stb_trim_warn == 1,   							"CONFIG STAB TRIM")
updateList(line_red, last_red,  6, ail_trim_warn == 1,   							"CONFIG AILERON TRIM")
updateList(line_red, last_red,  7, rud_trim_warn == 1,   							"CONFIG RUDDER TRIM")
updateList(line_red, last_red,  8, autop_warn == 1,      							"CONFIG AUTOPILOT")
updateList(line_red, last_red,  9, flaps_warn == 1,      							"CONFIG FLAPS")
updateList(line_red, last_red, 10, spoil_warn == 1 ,     							"CONFIG SPOILERS")
updateList(line_red, last_red, 11, get(gear_warn) == 1,  							"GEAR")
updateList(line_red, last_red, 12, pitch_disc_warn == 1, 							"PITCH DISCONNECT")
updateList(line_red, last_red, 13, roll_disc_warn == 1,  							"ROLL DISCONNECT")
updateList(line_red, last_red, 14, get(rel_engfir0) == 6, 							"L ENGINE FIRE")
updateList(line_red, last_red, 15, get(rel_engfir1) == 6, 							"R ENGINE FIRE")
updateList(line_red, last_red, 16, get(rel_lbrakes) == 6 or get(rel_lbrakes) == 6, 	"NORM BRAKES FAIL")
updateList(line_red, last_red, 17, get(lan_gear_warn) == 1, 						"LANDING GEAR")

-- YELLOW
updateList(line_yellow, last_yellow,  1, cargodoor == 2,  						"CARGO DOOR")
updateList(line_yellow, last_yellow,  2, passdoor == 2,   						"PASSENGER DOOR")
updateList(line_yellow, last_yellow,  3, get(customslider4_r) > 0.2, 			"EMERGENCY EXIT")
updateList(line_yellow, last_yellow,  4, get(elt_h) == 1,            			"ELT ON")
updateList(line_yellow, last_yellow,  5, get(emeright_h) == 0,       			"EMER LIGHTS OFF")
updateList(line_yellow, last_yellow,  6, get(emeright_h) == 2,       			"EMER LIGHTS ON")
updateList(line_yellow, last_yellow,  7, ice_det == 2 or get(ice_test) == 1, 	"ICE DETECTED")
updateList(line_yellow, last_yellow,  8, get(rel_ice_detect) == 6,   			"ICE DETECTOR FAIL")
updateList(line_yellow, last_yellow,  9, get(airdat1_fault) == 1 ,   			"AIR DATA 1 FAULT")
updateList(line_yellow, last_yellow, 10, get(airdat2_fault) == 1,    			"AIR DATA 2 FAULT")
updateList(line_yellow, last_yellow, 11, get(sbrk_h) > 0.1 and get(onground_all) == 0 and (get(carets) >= 2 or get(radio_altimeter_height_ft_pilot) < 500), "FLT SPOILERS DEPLOY")
updateList(line_yellow, last_yellow, 12, get(ground_sp_h) == 3,      			"GND SPLRS NOT ARMED")
updateList(line_yellow, last_yellow, 13, get(fuel_imbalanced) == 1,  			"FUEL IMBALANCE")
updateList(line_yellow, last_yellow, 14, get(m_fuel_total) < 635,    			"FUEL QUANTITY LOW")
updateList(line_yellow, last_yellow, 15, get(rel_genera0) == 6,      			"L GEN FAIL")
updateList(line_yellow, last_yellow, 16, get(rel_genera1) == 6,      			"R GEN FAIL")
updateList(line_yellow, last_yellow, 17, get(brks_low) == 1,         			"INBD BRAKE PRESS LO")
updateList(line_yellow, last_yellow, 18, get(outbrks_low) == 1,      			"OUTBD BRAKE PRESS LO")
updateList(line_yellow, last_yellow, 19, get(brks_low) == 1,         			"PK/EMER BRK PRESS LO")
updateList(line_yellow, last_yellow, 20, get(rel_startr0) == 6,      			"L STARTER FAIL")
updateList(line_yellow, last_yellow, 21, get(rel_startr1) == 6,      			"R STARTER FAIL")
updateList(line_yellow, last_yellow, 22, get(antice_probe_l_h) == 0, 			"L PROBE HEAT OFF")
updateList(line_yellow, last_yellow, 23, get(antice_probe_r_h) == 0, 			"R PROBE HEAT OFF")
updateList(line_yellow, last_yellow, 24, cab_alt_status == 1,        			"CABIN ALTITUDE")
updateList(line_yellow, last_yellow, 25, get(electr_stbi_h) == 0,    			"STALL PROTECT FAIL")

-- CYAN
updateList(line_cyan, last_cyan,  1, ice_det == 1, 								"ICE DETECTED")
updateList(line_cyan, last_cyan,  2, get(antice_wings_xbleed_valve) == 1, 		"WING SOURCE XBLEED")
updateList(line_cyan, last_cyan,  3, get(fuel_pump_l_astate) == 1,        		"L FUEL PUMP ON")
updateList(line_cyan, last_cyan,  4, get(fuel_pump_r_astate) == 1,        		"R FUEL PUMP ON")
updateList(line_cyan, last_cyan,  5, get(electr_stbi_h) == 0,             		"RUDDER LIMITER FAULT")
updateList(line_cyan, last_cyan,  6, get(hd_r_engn_state) == 0,          		"FLAPS RATE LOW") -- JackZero: Changed to new Dataref
updateList(line_cyan, last_cyan,  7, get(rel_ignitr0) > 3,                		"L ENG IGN FAULT")
updateList(line_cyan, last_cyan,  8, get(rel_ignitr1) > 3,                		"R ENG IGN FAULT")



 -- JackZero: Added for ENG IGN FAULT
 
-- WHITE
updateList(line_white, last_white,  1, get(taws_ter_h) == 0,    								"TAWS TERR OFF")
updateList(line_white, last_white,  2, get(taws_flp_h) == 0,    								"TAWS FLAPS OFF")
updateList(line_white, last_white,  3, get(taws_gs_h) == 0,     								"TAWS GS OFF")
updateList(line_white, last_white,  4, get(yaw_damper_on) == 0, 								"YAW DAMPER OFF")
updateList(line_white, last_white,  5, get(APU_generator_on) == 0 and get(APU_running) == 1, 	"APU GEN OFF")
updateList(line_white, last_white,  6, get(nws_h) == 0,                 						"NWS OFF")
updateList(line_white, last_white,  7, get(aircond_airsource) == 0,     						"AIR SOURCE OFF")
updateList(line_white, last_white,  8, get(dcu_a_h) == 0,               						"AURAL WARN A MUTED")
updateList(line_white, last_white,  9, get(dcu_b_h) == 0,               						"AURAL WARN B MUTED")
updateList(line_white, last_white, 10, get(fire_autoapr_h) == 0,        						"AUTO APR OFF")
updateList(line_white, last_white, 11, get(autopilot_disconnect) == 1,  						"AUTOPILOT DISCONNECT")
updateList(line_white, last_white, 12, get(left_bat_h) == 0,            						"L BATT OFF")
updateList(line_white, last_white, 13, get(right_bat_h) == 0,           						"R BATT OFF")
updateList(line_white, last_white, 14, get(bus_tie_h) == 0,             						"BUS TIE MAN OPEN") -- JackZero: CAS message should appear on manual untie (0), not auto tie (1)
updateList(line_white, last_white, 15, get(bleed_status) == 0,          						"BLEED OFF")
updateList(line_white, last_white, 16, cargodoor == 1,                  						"CARGO DOOR")
updateList(line_white, last_white, 17, passdoor == 1,                   						"PASSENGER DOOR")
updateList(line_white, last_white, 18, get(pressure_ditch_h) == 1,      						"DITCHING ON")
updateList(line_white, last_white, 19, get(pressure_emer_depr_h) == 1,  						"EMER DEPRESS ON")
updateList(line_white, last_white, 20, wengns_antice == 7,                             			"WING/ENG ANTI-ICE ON")
updateList(line_white, last_white, 21, wengns_antice < 7 and wengns_antice >= 4,       			"WING ANTI-ICE ON")
updateList(line_white, last_white, 22, wengns_antice < 7 and (wengns_antice % 4) == 3, 			"ENGN ANTI-ICE ON")
updateList(line_white, last_white, 23, (wengns_antice % 4) == 2,                       			"L ENGN ANTI-ICE ON")
updateList(line_white, last_white, 24, (wengns_antice % 4) == 1,                       			"R ENGN ANTI-ICE ON")
updateList(line_white, last_white, 25, get(fire_engn_r_h) == 1,     							"R ENG FUEL SOV CLSD")
updateList(line_white, last_white, 26, get(fire_engn_l_h) == 1,     							"L ENG FUEL SOV CLSD")
updateList(line_white, last_white, 27, get(en_but_run_l) == 0,      							"L ENGINE SHUTDOWN")
updateList(line_white, last_white, 28, get(en_but_run_r) == 0,      							"R ENGINE SHUTDOWN")
updateList(line_white, last_white, 29, get(fuel_balanced) == 1,     							"FUEL BALANCED")
updateList(line_white, last_white, 30, get(fuel_xflow_up_h) == 1,   							"FUEL GRAV XFLOW OPEN")
updateList(line_white, last_white, 31, get(fuel_xpump_l) == 0,      							"L FUEL PUMP OFF")
updateList(line_white, last_white, 32, get(fuel_xpump_r) == 0,      							"R FUEL PUMP OFF")
updateList(line_white, last_white, 33, get(fuel_xpump_r) == 2,      							"R FUEL PUMP ON")
updateList(line_white, last_white, 34, get(fuel_xpump_l) == 2,      							"L FUEL PUMP ON")
updateList(line_white, last_white, 35, get(fuel_xflow_dn_h) == 1,   							"FUEL XFER OPEN")
updateList(line_white, last_white, 36, get(electr_gen_l_h) == 0,    							"L GEN OFF")
updateList(line_white, last_white, 37, get(electr_gen_r_h) == 0,    							"R GEN OFF")
updateList(line_white, last_white, 38, get(ground_sp_h) == 0,       							"GND SPOILERS OFF")
updateList(line_white, last_white, 39, get(aux_hpump_h) ~= 1 or get(l_hpump_h) ~= 1 or get(r_hpump_h) ~= 1 or get(ptu_h) ~= 1, "HYD PUMP NOT AUTO")
updateList(line_white, last_white, 40, get(hydr_l_sov_h) == 0,      							"L HYD SOV CLOSED")
updateList(line_white, last_white, 41, get(hydr_r_sov_h) == 0,      							"R HYD SOV CLOSED")
updateList(line_white, last_white, 42, get(pressure_man_h) == 1,    							"MANUAL PRESS ON")
updateList(line_white, last_white, 43, get(aircond_airsource) == 2, 							"PACK ONLY")
updateList(line_white, last_white, 44, get(aircond_airsource) == 3, 							"TRIM AIR ONLY")
updateList(line_white, last_white, 45, get(parkbrake) == 1 and get(onground_all) == 1, 			"PARK/EMER BRAKE ON")
updateList(line_white, last_white, 46, get(oxigen_ox) == 0,         							"PAX OXYGEN OFF")
updateList(line_white, last_white, 47, get(oxigen_ox) == 2,         							"PAX OXYGEN ON")
updateList(line_white, last_white, 48, get(pitch_d_2) ~= 0,         							"PITCH DISCONNECT")
updateList(line_white, last_white, 49, get(aircond_ramair_h) == 1,  							"RAM AIR ON")
updateList(line_white, last_white, 50, get(flight_spoil_h) == 1,    							"ROLL SPOILERS OFF")
updateList(line_white, last_white, 51, get(trim_stab) == 2,         							"SEC STAB TRIM ON")
updateList(line_white, last_white, 52, get(trim_stab) == 1,         							"STAB TRIM OFF")
updateList(line_white, last_white, 53, get(electr_stbi_h) == 0,     							"STBY INST OFF")
updateList(line_white, last_white, 54, get(antice_wngsource_r) ~= 1 and get(antice_wings_xbleed_valve) == 0, "WING SOURCE-XBLEED")
updateList(line_white, last_white, 55, get(bleed_xbleed_h) == 1,    							"XBLEED OPEN")
updateList(line_white, last_white, 56, get(trim_pusher_h) == 0,     							"STALL PUSHER OFF")
updateList(line_white, last_white, 57, get(probs_test) == 1,        							"PROBE HEAT TEST OK")
updateList(line_white, last_white, 58, get(rudlim_test) == 1,       							"RUD LIMITER IN TEST")

set(red_cas, #line_red)
set(yellow_cas, #line_yellow)
set(has_cas, #line_red + #line_yellow + #line_cyan + #line_white)

local n = 1
for i = n, math.min(25, #line_red) do
    line_color[i] = color_red
    line_text[i]  = line_red[i - n + 1]
	set(cas_colors[i], color_red[4])
	set(cas_texts[i],  line_red[i - n + 1])
end
n = n + #line_red

for i = n, math.min(25, #line_yellow + n - 1) do
    line_color[i] = color_yellow
    line_text[i]  = line_yellow[i - n + 1]
	set(cas_colors[i], color_yellow[4])
	set(cas_texts[i],  line_yellow[i - n + 1])
end
n = n + #line_yellow

for i = n, math.min(25, #line_cyan + n - 1) do
    line_color[i] = color_cyan
    line_text[i]  = line_cyan[i - n + 1]
	set(cas_colors[i], color_cyan[4])
	set(cas_texts[i], line_cyan[i - n + 1])
end
n = n + #line_cyan

for i = n, math.min(25, #line_white + n - 1) do
    line_color[i] = color_white
    line_text[i]  = line_white[i - n + 1]
	set(cas_colors[i], color_white[4])
	set(cas_texts[i], line_white[i - n + 1])
end
n = n + #line_white

for i = n, 25 do
    line_color[i] = color_white
    line_text[i] = ""
	set(cas_colors[i], color_white[4])
	set(cas_texts[i], "")
end

end
--]=]

components = {
-- msgs
		textureLit {
        position = { 22, 370, 50, 24 },
        image = (msgs),
		visible = function()
		return get(has_cas) ~= 0 and get(mfd_pan_cas) ~= 0
		end,

    },
};

function draw()

drawAll(components)

if get(mfd_pan_cas) == 0 then
drawText(font1, 6, 370, line_text[ 1],  line_color[ 1][1],line_color[ 1][2],line_color[ 1][3])
drawText(font1, 6, 355, line_text[ 2],  line_color[ 2][1],line_color[ 2][2],line_color[ 2][3])
drawText(font1, 6, 340, line_text[ 3],  line_color[ 3][1],line_color[ 3][2],line_color[ 3][3])
drawText(font1, 6, 325, line_text[ 4],  line_color[ 4][1],line_color[ 4][2],line_color[ 4][3])
drawText(font1, 6, 310, line_text[ 5],  line_color[ 5][1],line_color[ 5][2],line_color[ 5][3])
drawText(font1, 6, 295, line_text[ 6],  line_color[ 6][1],line_color[ 6][2],line_color[ 6][3])
drawText(font1, 6, 280, line_text[ 7],  line_color[ 7][1],line_color[ 7][2],line_color[ 7][3])
drawText(font1, 6, 265, line_text[ 8],  line_color[ 8][1],line_color[ 8][2],line_color[ 8][3])
drawText(font1, 6, 250, line_text[ 9],  line_color[ 9][1],line_color[ 9][2],line_color[ 9][3])
drawText(font1, 6, 235, line_text[10],  line_color[10][1],line_color[10][2],line_color[10][3])
drawText(font1, 6, 220, line_text[11],  line_color[11][1],line_color[11][2],line_color[11][3])
drawText(font1, 6, 205, line_text[12],  line_color[12][1],line_color[12][2],line_color[12][3])
drawText(font1, 6, 190, line_text[13],  line_color[13][1],line_color[13][2],line_color[13][3])
drawText(font1, 6, 175, line_text[14],  line_color[14][1],line_color[14][2],line_color[14][3])
drawText(font1, 6, 160, line_text[15],  line_color[15][1],line_color[15][2],line_color[15][3])
drawText(font1, 6, 145, line_text[16],  line_color[16][1],line_color[16][2],line_color[16][3])
drawText(font1, 6, 130, line_text[17],  line_color[17][1],line_color[17][2],line_color[17][3])
drawText(font1, 6, 115, line_text[18],  line_color[18][1],line_color[18][2],line_color[18][3])
drawText(font1, 6, 100, line_text[19],  line_color[19][1],line_color[19][2],line_color[19][3])
drawText(font1, 6, 85,  line_text[20],  line_color[20][1],line_color[20][2],line_color[20][3])
drawText(font1, 6, 70,  line_text[21],  line_color[21][1],line_color[21][2],line_color[21][3])
drawText(font1, 6, 55,  line_text[22],  line_color[22][1],line_color[22][2],line_color[22][3])
drawText(font1, 6, 40,  line_text[23],  line_color[23][1],line_color[23][2],line_color[23][3])
drawText(font1, 6, 25,  line_text[24],  line_color[24][1],line_color[24][2],line_color[24][3])
drawText(font1, 6, 10,  line_text[25],  line_color[25][1],line_color[25][2],line_color[25][3])
end

end


