<commit_before>/* jcpu.c -- emulator for the <NAME>'s computer from "But How Do It Know?" */
/* ver.1.0 */

/* This is an emulator of the computer from the book "But How Do It Know?"
 * by <NAME>. Internally airthmetic and logic is done with the C 
 * operators rather than by simulating the whole system and the flags are represented 
 * as separate registers. Externally, it behaves as you would expect from the book. */

/* Author: <NAME> */
#include "jcpu.h"
#include "mach_code.h"

#define RA			0x0C	// & 0x0C for reg a
#define RB			0x03	// & 0x03 for reg b
#define BYTE_MAX	0xFF	// max byte value
#define get_ra_ir() (GREG_OFF + ((regs[IR] & RA) >> 2))	// get the index of reg a from IR
#define get_rb_ir() (GREG_OFF + (regs[IR] & RB))		// get the index of reg b from IR
#define get_instr()	(regs[IR] >> 4)						// get instruction nibble
#define set_zf()	(regs[ZF] = (regs[rb] == 0))		// set the zero flag

byte ram[RAM_S] = {0x00};		// the ram
byte regs[NUM_REGS] = {0x00};	// the registers
fpvv_t * func_arr; 				// pointer to a function pointer

static void load(void);
static void store(void);
static void data(void);
static void jmpr(void);
static void jmp(void);
static void jcond(void);
static void clearf(void);
static void dummy(void);
static void add(void);
static void shr(void);
static void shl(void);
static void not(void);
static void and(void);
static void or(void);
static void xor(void);
static void cmp(void);

void jcpu_load(const byte * code, int csize)
{
	// an array of void function pointers
	static fpvv_t fa[INSTR_COUNT] = {	
		load, store,
		data,
		jmpr, jmp, jcond,
		clearf,
		dummy,
		add, shr, shl, not, and, or, xor, cmp
	};
		  
	func_arr = fa;

	int i;
	for (i = 0; i <= BYTE_MAX && i < csize; ++i)
		ram[i] = code[i];
	
	return;
}

void jcpu_step(void)<commit_msg>Update jcpu.c<commit_after>/* jcpu.c -- emulator for the John Clark Scott's computer from "But How Do It Know?" */
/* ver.1.0 */

/* This is an emulator of the computer from the book "But How Do It Know?"
 * by <NAME>. Internally airthmetic and logic is done with the C 
 * operators rather than by simulating the whole system and the flags are represented 
 * as separate registers. Externally, it behaves as you would expect from the book. */

/* Author: <NAME> */
#include "jcpu.h"
#include "mach_code.h"

#define RA			0x0C	// & 0x0C for reg a
#define RB			0x03	// & 0x03 for reg b
#define BYTE_MAX	0xFF	// max byte value
#define get_ra_ir() (GREG_OFF + ((regs[IR] & RA) >> 2))	// get the index of reg a from IR
#define get_rb_ir() (GREG_OFF + (regs[IR] & RB))		// get the index of reg b from IR
#define get_instr()	(regs[IR] >> 4)						// get instruction nibble
#define set_zf()	(regs[ZF] = (regs[rb] == 0))		// set the zero flag

byte ram[RAM_S] = {0x00};		// the ram
byte regs[NUM_REGS] = {0x00};	// the registers
fpvv_t * func_arr; 				// pointer to a function pointer

static void load(void);
static void store(void);
static void data(void);
static void jmpr(void);
static void jmp(void);
static void jcond(void);
static void clearf(void);
static void dummy(void);
static void add(void);
static void shr(void);
static void shl(void);
static void not(void);
static void and(void);
static void or(void);
static void xor(void);
static void cmp(void);

void jcpu_load(const byte * code, int csize)
{
	/* initialize the function array
	 * load the code in ram */

	// an array of void function pointers
	static fpvv_t fa[INSTR_COUNT] = {	
		load, store,
		data,
		jmpr, jmp, jcond,
		clearf,
		dummy,
		add, shr, shl, not, and, or, xor, cmp
	};
		  
	func_arr = fa;

	int i;
	for (i = 0; i <= BYTE_MAX && i < csize; ++i)
		ram[i] = code[i];
	
	return;
}

void jcpu_step(void)
{'fraction_non_alphanumeric': 0.13250067879446104, 'fraction_numerical': 0.012489818083084442, 'mean_word_length': 3.5650557620817844, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2695512', 'n_tokens_mistral': 1437, 'n_tokens_neox': 1350, 'n_words': 507}