<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

static typedef struct instruction 
{
	//Bits			[15:12] [11:10]			  [9:5]         [4:0]
	//Data			        |SIZE(BYTES EXCL. OPCODE) |DURATION(CC) |FLAGS(Even Parity, Zero, Sign, Aux Carry, Carry)
	//uint16_t data;
	uint8_t size;
	uint8_t flags;
	uint8_t duration;
	uint32_t (*instFunc)(void); //Function that emulates instruction; returns duration of instruction
	char *name;		//Instruction mnemonic		
} inst;

static uint8_t const *mem = (uint8_t)malloc(4000*sizeof(uint8_t));

static uint8_t gpr[10];

static uint8_t const *B = gpr+0;
static uint8_t const *C = gpr+1;
static uint8_t const *D = gpr+2;
static uint8_t const *E = gpr+3;
static uint8_t const *H = gpr+4;
static uint8_t const *L = gpr+5;
//Accumulator
static uint8_t const *A = gpr+6;
//FLAGS - Carry | Aux Carry | Sign | Zero | Even Parity
//BIT   - 0     | 1         | 2    | 3    | 4 
static uint8_t const *status = gpr+7;
//Registers Z and W can only be used for instruction execution
//These registers are not directly accessible to the programmer
static uint8_t const *Z = gpr+8;
static uint8_t const *W = gpr+9;

//B+C
static uint16_t const *Bp = (uint16_t*)(gpr+0);
//D+E
static uint16_t const *Dp = (uint16_t*)(gpr+2);
//H+L
static uint16_t const *Hp = (uint16_t*)(gpr+4);
//A+status
static uint16_t const *PSW = (uint16_t*)(gpr+6);

//use offset method so that if I read the value of the pc or sp, I get the emulated address and not the actual address of the host computer
static uint8_t pc;
static uint8_t sp;

//Control I/O Signals of 8080
//SIGNALS - WR'(0) | DBIN(O) | INTE(O) | INT(I) | HOLD ACK(O) | HOLD(I) | WAIT (0) | READY(I) | SYNC(O) | RESET(I) 
//BIT     - 0      | 1       | 2       | 3      | 4           | 5       | 6        | 7        | 8       | 9
static uint16_t control;

//Signals presented on the 8800 front panel
//SIGNALS - INTE | PROT | MEMR | INP | M1 | OUT | HLTA | STACK | WO'  | INT(A) | WAIT | HLDA | RESET
//BIT     - 0    | 1    | 2    | 3   | 4  | 5   | 6    | 7     | 8    | 9      | 10   | 11   | 12
static uint16_t indicator;

static uint8_t inst_reg;
static uint32_t time = 0;

/*machine cycle operations
//FETCH - reads next program instruction, and stores it in the instruction register; then increments the pc
void fetch(uint8_t* pc){
	inst_reg = *pc;
	pc = pc+1;
}

//MEMORY READ - reads data/address at adr to the register or register pair indicated by the select (0 = r, 1 = rp)   
void memR(uint8_t* adr, uint8_t* dr, uint8_t select){
	if(select == 1)
	{
		dr[1] = adr[1];
		return;
	}

	dr[0] = *adr;
}

//MEMORY WRITE - writes data in source register or source register pair (sr) as indicated by the select (0 = r, 1 = rp) to address (adr)  
void memW(uint8_t* adr, uint8_t* sr, uint8_t select){
	if(select == 1)
	{
		adr[1] = sr[1];
		return;
	}

	adr[0] = sr[0];
}

//STACK READ - reads data/address stored on stack to the register or register pair indicated by the select (0 = r, 1 = rp)
void stackR(uint8_t* sp, uint8_t* dr, uint8_t select){
	if(select == 1)
	{
		dr[1] = sp[1];
		dr[0] = sp[0];
		sp += 2;
		return;
	}

	dr[0] = sp[0];
	sp += 1;
}

//STACK WRITE - writes data stored in source register or register pair (sr) as indiacted by select (0 = r, 1 = rp) to stack
void stackW(uint8_t* sp, uint8_t* sr, uint8_t select){
	if(select == 1)
	{
		sp -= 2;
		sp[1] = sr[1];
		sp[0] = sr[0];
		return;
	}

	sp[0] = sr[0];
}	

//INPUT READ:w
*/

//8080 Instruction Set -> size, flags, duration, function, name
static inst inst_set[246] = {		//	mnemonic      	SIZE,DURATION,FLAGS (EP, Z, S, AC, C)
/*
{0x0080,,"NOP"} 		//0	NOP 		S0,D4,F00000	0000 0000 1000 0000
{0x0940,,"LXI B, D16"}		//1	LXI B		S2,D10,F00000   0000 1001 0100 0000
{0x00E0,,"STAX B"}		//2	STAX B		S0,D7,F00000    0000 0000 1110 0000
{0x00A0,,"INX B"}		//3	INX B		S0,D5,F00000	0000 0000 1010 0000
{0x00BF,,"INR B"}		//4	INR B		S0,D5,F11110	0000 0000 1011 1111
{0x00BF,,"DCR B"}		//5	DCRB		S0,D5,F11110		"
{0x04E0,,"MVI B D8"}		//6	MVI B D8	S1,D7,F00000	0000 0100 1110 0000
{0x0081,,"RLC"}			//7	RLC		S0,D4,F00001	0000 0000 1000 0001
				//8
{0x0141,,"DAD B"}		//9	DAD B		S0,D10,F00001	0000 0001 0100 0001
{0x00E0,,"LDAX B"}		//10	LDAX B		S0,D7,F00000	0000 0000 1110 0000
{0x00A0,,"DCX B"}		//11	DCX B		S0,D5,F00000	0000 0000 1010 0000
{0x00DE,,"INR C"}		//12	INR C		S0,D5,F11110	0000 0000 1011 1110
*/
{0x00000, }
};

void main(){
	while(1)
	{
		inst_reg = mem[pc]	
	}
	free(mem);			
}

//Instruction-Emulating Functions
//Data Transfer<commit_msg>Cleaned out compile errors from current code. Now planning to establish 2 arrays: one for instruction data and one for instruction function pointers. The instruction data will be passed by to the functions.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef struct i_data 
{
	//Bits			[15:12] [11:10]			  [9:5]         [4:0]
	//Data			        |SIZE(BYTES EXCL. OPCODE) |DURATION(CC) |FLAGS(Even Parity, Zero, Sign, Aux Carry, Carry)
	//uint16_t data;
	uint8_t size;
	uint8_t flags;
	uint8_t duration;
	uint32_t (*instFunc)(void); //Function that emulates instruction; returns duration of instruction
	char *name;		//Instruction mnemonic		
} data;

typedef void (*inst)(data);

uint8_t *mem;

static uint8_t gpr[10];

static uint8_t *B = gpr+0;
static uint8_t *C = gpr+1;
static uint8_t *D = gpr+2;
static uint8_t *E = gpr+3;
static uint8_t *H = gpr+4;
static uint8_t *L = gpr+5;
//Accumulator
static uint8_t *A = gpr+6;
//FLAGS - Carry | Aux Carry | Sign | Zero | Even Parity
//BIT   - 0     | 1         | 2    | 3    | 4 
static uint8_t *status = gpr+7;
//Registers Z and W can only be used for instruction execution
//These registers are not directly accessible to the programmer
static uint8_t *Z = gpr+8;
static uint8_t *W = gpr+9;

//B+C
static uint16_t *Bp = (uint16_t*)(gpr+0);
//D+E
static uint16_t *Dp = (uint16_t*)(gpr+2);
//H+L
static uint16_t *Hp = (uint16_t*)(gpr+4);
//A+status
static uint16_t *PSW = (uint16_t*)(gpr+6);

//use offset method so that if I read the value of the pc or sp, I get the emulated address and not the actual address of the host computer
static uint8_t pc;
static uint8_t sp;

//Control I/O Signals of 8080
//SIGNALS - WR'(0) | DBIN(O) | INTE(O) | INT(I) | HOLD ACK(O) | HOLD(I) | WAIT (0) | READY(I) | SYNC(O) | RESET(I) 
//BIT     - 0      | 1       | 2       | 3      | 4           | 5       | 6        | 7        | 8       | 9
static uint16_t control;

//Signals presented on the 8800 front panel
//SIGNALS - INTE | PROT | MEMR | INP | M1 | OUT | HLTA | STACK | WO'  | INT(A) | WAIT | HLDA | RESET
//BIT     - 0    | 1    | 2    | 3   | 4  | 5   | 6    | 7     | 8    | 9      | 10   | 11   | 12
static uint16_t indicator;

static uint8_t inst_reg;
static uint32_t time = 0;


//8080 Instruction Set -> size, flags, duration, function, name
//static data inst_data[246] = {		//	mnemonic      	SIZE,DURATION,FLAGS (EP, Z, S, AC, C)
/*
{0x0080,,"NOP"} 		//0	NOP 		S0,D4,F00000	0000 0000 1000 0000
{0x0940,,"LXI B, D16"}		//1	LXI B		S2,D10,F00000   0000 1001 0100 0000
{0x00E0,,"STAX B"}		//2	STAX B		S0,D7,F00000    0000 0000 1110 0000
{0x00A0,,"INX B"}		//3	INX B		S0,D5,F00000	0000 0000 1010 0000
{0x00BF,,"INR B"}		//4	INR B		S0,D5,F11110	0000 0000 1011 1111
{0x00BF,,"DCR B"}		//5	DCRB		S0,D5,F11110		"
{0x04E0,,"MVI B D8"}		//6	MVI B D8	S1,D7,F00000	0000 0100 1110 0000
{0x0081,,"RLC"}			//7	RLC		S0,D4,F00001	0000 0000 1000 0001
				//8
{0x0141,,"DAD B"}		//9	DAD B		S0,D10,F00001	0000 0001 0100 0001
{0x00E0,,"LDAX B"}		//10	LDAX B		S0,D7,F00000	0000 0000 1110 0000
{0x00A0,,"DCX B"}		//11	DCX B		S0,D5,F00000	0000 0000 1010 0000
{0x00DE,,"INR C"}		//12	INR C		S0,D5,F11110	0000 0000 1011 1110
*/
/*
{0x00000, }
};

static inst inst_set[246] = {

}
*/

void main(){
	mem = (uint8_t*)malloc(4000*sizeof(uint8_t));

	while(1)
	{
		inst_reg = mem[pc];	
	}
	free(mem);			
}

//Instruction-Emulating Functions
//Data Transfer
{'fraction_non_alphanumeric': 0.14222503160556257, 'fraction_numerical': 0.12439949431099874, 'mean_word_length': 2.9654135338345866, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3896867', 'n_tokens_mistral': 4091, 'n_tokens_neox': 3428, 'n_words': 1048}