8080-Emulator  0.1
An Intel 8080 emulator for Space Invaders
Classes | Macros | Enumerations | Functions
cpu_8080.h File Reference

This file simulates and disassembles part of 8080 processor. More...

#include <inttypes.h>
#include "memory_8080.h"
Include dependency graph for cpu_8080.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  program_status_word
 program_status_word: An exdended PSW for easy checks and sets of PSW without flagging. More...
 
struct  cpu_state
 cpu_state: This structure keeps runtime state of all the registers in the CPU. More...
 

Macros

#define UNUSED   __attribute__((unused))
 
#define ALL_BUT_AUX_FLAG   (SIGN_FLAG | ZERO_FLAG | PARITY_FLAG | CARRY_FLAG)
 All but the aux flag options.
 

Enumerations

enum  flag_bits {
  SIGN_FLAG = 1 << 0 , ZERO_FLAG = 1 << 1 , AUX_FLAG = 1 << 3 , PARITY_FLAG = 1 << 5 ,
  CARRY_FLAG = 1 << 7
}
 ENUMS for PSW_FLAGS.
 
enum  condition_flags {
  NZ_check = 0x0 , Z_check = 0x1 , NC_check = 0x2 , C_check = 0x3 ,
  PO_check = 0x4 , PE_check = 0x5 , P_check = 0x6 , M_check = 0x7
}
 different condition checks for JMP, conditional OPS More...
 

Functions

cpu_stateinit_cpu_8080 (uint16_t pc, uint8_t(*in_cb)(uint8_t), void(*out_cb)(uint8_t, uint8_t))
 Initialize a new cpu_8080 instance structure. Everything is initialized to 0. More...
 
int exec_inst (cpu_state *cpu)
 Executes the instruction pc is pointing to after incrementing it. More...
 
int decompile_inst (cpu_state *cpu, uint16_t *next_inst)
 Recompile mode. More...
 
void io_machine_OUT (uint8_t port, uint8_t data)
 Function to write data to the IO port. More...
 
uint8_t io_machine_IN (uint8_t port)
 Function to read a byte of data from the port. More...
 
void print_state (const cpu_state cpu)
 Print the state of CPU. More...
 

Detailed Description

This file simulates and disassembles part of 8080 processor.

Author
Pranay Garg (prana.nosp@m.yga@.nosp@m.andre.nosp@m.w.cm.nosp@m.u.edu)
Version
0.1
Date
2020-12-20

Macro Definition Documentation

◆ UNUSED

#define UNUSED   __attribute__((unused))

GCC header for unused variables Werror bypass

Enumeration Type Documentation

◆ condition_flags

different condition checks for JMP, conditional OPS

Enumerator
NZ_check 

not zero (Z = 0)

Z_check 

zero (2 = 1)

NC_check 

no carry (CY = 0)

C_check 

carry (CY = 1)

PO_check 

parity odd (P = 0)

PE_check 

parity even (P = 1)

P_check 

plus (Sign = 0)

M_check 

minus(Sign = 1)

Function Documentation

◆ decompile_inst()

int decompile_inst ( cpu_state cpu,
uint16_t *  next_inst 
)

Recompile mode.

Parameters
cpu
next_inst
Returns
int

◆ exec_inst()

int exec_inst ( cpu_state cpu)

Executes the instruction pc is pointing to after incrementing it.

Parameters
cpu
Returns
int

◆ init_cpu_8080()

cpu_state* init_cpu_8080 ( uint16_t  pc,
uint8_t(*)(uint8_t)  in_cb,
void(*)(uint8_t, uint8_t)  out_cb 
)

Initialize a new cpu_8080 instance structure. Everything is initialized to 0.

Parameters
pcProgram counter initialization
in_cb
out_cb
Returns
cpu_state* Pointer to the Malloced CPU state.
Note
  • the user is responsible for freeing the memory (for the CPU) once it's done
  • expects base to be initialized by the user to a 64KB aligned memory
Returns
cpu_state*

◆ io_machine_IN()

uint8_t io_machine_IN ( uint8_t  port)

Function to read a byte of data from the port.

Parameters
portfrom which the data is read
Returns
uint8_t

◆ io_machine_OUT()

void io_machine_OUT ( uint8_t  port,
uint8_t  data 
)

Function to write data to the IO port.

Parameters
portwhere the data is written to
datawhich is written

◆ print_state()

void print_state ( const cpu_state  cpu)

Print the state of CPU.

Parameters
cpu