void draw_single(t_vec *mosfets, size_t i);
void update_nodes(t_vec *nodes);
+int should_open(t_type type, t_state state);
int sim_step(t_vec *nodes, t_vec *mosfets);
void print_start(void);
}
if (mosfet->gate)
{
- if (!mosfet->is_opened)
- ft_printf("%4u%s-%s%c-\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type);
- else
+ if (mosfet->is_opened && should_open(mosfet->type, mosfet->gate->state))
ft_printf("%4u%s-%s%c%s|%s\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type, state_color_escape(mosfet->source->state), g_default_ac);
+ else if (should_open(mosfet->type, mosfet->gate->state))
+ ft_printf("%4u%s-%s%c\\\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type);
+ else if (mosfet->is_opened)
+ ft_printf("%4u%s-%s%c%s\\%s\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type, state_color_escape(mosfet->source->state), g_default_ac);
+ else
+ ft_printf("%4u%s-%s%c-\n", mosfet->gate->id, state_color_escape(mosfet->gate->state), g_default_ac, mosfet->type);
}
else
ft_printf("%sNULL--%s%c\n", g_red_ac, g_default_ac, mosfet->type);
#include "FET_sim.h"
#include "libft.h"
+int should_open(t_type type, t_state state)
+{
+ return ((type == p && state == on) || (type == n && state == off));
+}
+
// Maybe an error should be return when gate is NULL
static void update_mosfet(t_mosfet *mosfet)
{
- t_state state;
-
if (!mosfet->gate)
{
mosfet->is_opened = 0;
return ;
}
- state = mosfet->gate->state;
- if (mosfet->type == p && state == on)
- mosfet->is_opened = 1;
- else if (mosfet->type == n && state == off)
- mosfet->is_opened = 1;
- else
- mosfet->is_opened = 0;
+ mosfet->is_opened = should_open(mosfet->type, mosfet->gate->state);
return ;
}
int sim_step(t_vec *nodes, t_vec *mosfets)
{
- update_nodes(nodes);
update_mosfets(mosfets);
+ update_nodes(nodes);
return (1);
}