<commit_before>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_st.c                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: mhaziza <<EMAIL>>            +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2017/03/24 16:02:13 by mhaziza           #+#    #+#             */
/*   Updated: 2017/03/28 20:58:22 by mhaziza          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "../srcs/vm.h"

/*
** Instructions:
** Take a registry and a registry or an indirect and store the value of the
** registry toward a second argument. Its opcode is 0x03. For example, st r1, 42
** store the value of r1 at the address (PC + (42 % IDX_MOD))
*/

#define RR 0x50
#define RI 0x70
// #define ZMASK(c) (c & 0xff)

int get_short(t_env *e, t_cursor *cursor, int r)
{
	unsigned short	ret;

	ret = ((ZMASK(e->a[MODA(r)].hex) << 8) | ZMASK(e->a[MODA(r + 1)].hex));
	return ((short)ret);
}

void	ft_st(t_env *e, t_cursor *cursor)
{
	char	acb;
	int		p1;
	short	p2;
	int		i;
	int		size;
	int		v;

	acb = e->a[cursor->index + 1].hex;
	p1 = e->a[cursor->index + 2].hex;
	p2 = 0;
// printf("p1 %i reg[p1] %x acb %x\n", p1, cursor->reg[p1], acb);
	if (RR == ZMASK(acb))
	{
	//	printf("RR\n");
		p2 = e->a[cursor->index + 3].hex;
		cursor->reg[p2 - 1] = cursor->reg[p1 - 1];
		ft_update_cursor(e, cursor, 4);
	//	printf("reg[p2] %x (expected: ?)\n", cursor->reg[p2]);
	}
	else if (RI == ZMASK(acb))
	{
	//	printf("RI\n");
		p2 = (get_short(e, cursor, cursor->index + 3) & 0xffff);
		// printf("p2 vaut %i\n", p2);
		// printf("p2 vaut %x\n", p2);
		// printf("p2 %i - %#x \n", p2, p2);
		p2 = p2 < 0 && p2 > -IDX_MOD ? p2 : MODX(p2);
		// printf("p2 %i - %#x \n", p2, p2);
		int byte = MODA(get_bytes(e, cursor, MODX(p2)));
		// byte = byte < 0 ? byte + MEM_SIZE : byte;
		// printf("byte %i\n", byte);
		i = -1;
		while (++i < 4)
		{
			v = cursor->index + p2 + i;
			// v = (cursor->index + byte + i < 0) ? cursor->index + byte + i + MEM_SIZE : cursor->index + byte + i;
			// printf("cursor->index %i v %i\n", cursor->index, v);
			e->a[MODA((v))].hex = (cursor->reg[p1 - 1] >> (8 * (3 - i))) & 0xff;
			e->a[MODA((v))].color = cursor->color - 6;
			e->a[MODA((v))].prevcolor = cursor->color - 6;
			e->a[MODA((v))].new_color_count = 50;<commit_msg>missing MODA and check register in st()<commit_after>/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_st.c                                            :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: mhaziza <<EMAIL>>            +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2017/03/24 16:02:13 by mhaziza           #+#    #+#             */
/*   Updated: 2017/03/29 10:31:39 by mhaziza          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "../srcs/vm.h"

/*
** Instructions:
** Take a registry and a registry or an indirect and store the value of the
** registry toward a second argument. Its opcode is 0x03. For example, st r1, 42
** store the value of r1 at the address (PC + (42 % IDX_MOD))
*/

#define RR 0x50
#define RI 0x70
// #define ZMASK(c) (c & 0xff)

int get_short(t_env *e, t_cursor *cursor, int r)
{
	unsigned short	ret;

	ret = ((ZMASK(e->a[MODA(r)].hex) << 8) | ZMASK(e->a[MODA(r + 1)].hex));
	return ((short)ret);
}

void	ft_st(t_env *e, t_cursor *cursor)
{
	char	acb;
	int		p1;
	short	p2;
	int		i;
	int		size;
	int		v;

	acb = e->a[MODA(cursor->index + 1)].hex;
	p1 = e->a[MODA(cursor->index + 2)].hex;
	p2 = 0;
// printf("p1 %i reg[p1] %x acb %x\n", p1, cursor->reg[p1], acb);
	if (RR == ZMASK(acb))
	{
	//	printf("RR\n");
		p2 = e->a[MODA(cursor->index + 3)].hex;
		if (ft_is_reg(p1 - 1, p2 - 1, REG_NUMBER))
			cursor->reg[p2 - 1] = cursor->reg[p1 - 1];
		ft_update_cursor(e, cursor, 4);
	//	printf("reg[p2] %x (expected: ?)\n", cursor->reg[p2]);
	}
	else if (RI == ZMASK(acb))
	{
	//	printf("RI\n");
		p2 = (get_short(e, cursor, cursor->index + 3) & 0xffff);
		// printf("p2 vaut %i\n", p2);
		// printf("p2 vaut %x\n", p2);
		// printf("p2 %i - %#x \n", p2, p2);
		p2 = p2 < 0 && p2 > -IDX_MOD ? p2 : MODX(p2);
		// printf("p2 %i - %#x \n", p2, p2);
		int byte = MODA(get_bytes(e, cursor, MODX(p2)));
		// byte = byte < 0 ? byte + MEM_SIZE : byte;
		// printf("byte %i\n", byte);
		i = -1;
		while (++i < 4)
		{
			v = cursor->index + p2 + i;
			// v = (cursor->index + byte + i < 0) ? cursor->index + byte + i + MEM_SIZE : cursor->index + byte + i;
			// printf("cursor->index %i v %i\n", cursor->index, v);
			e->a[MODA((v))].hex = (cursor->reg[p1 - 1] >> (8 * (3 - i))) & 0xff;
			e->a[MODA((v))].color = cursor->color - 6;
			e->a[MODA((v))].prevcolor = cursor->color - 6;
			e->a[MODA((v))].new_color_count = 50;
{'fraction_non_alphanumeric': 0.25831842576028624, 'fraction_numerical': 0.036493738819320214, 'mean_word_length': 1.7088178294573644, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6838669', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2066, 'n_words': 477}