~intarga/i8080e

a8ee04bff4d693ad3ba7f05df76b17abdfa63450 — Ingrid 1 year, 2 months ago 4679a79
use uint_t instead of unsigned char everywhere
4 files changed, 19 insertions(+), 16 deletions(-)

M src/cpu.c
M src/disassembler.c
M src/disassembler.h
M src/main.c
M src/cpu.c => src/cpu.c +6 -6
@@ 128,7 128,7 @@ int DAA(Cpu_state *state) {

int MOV(Cpu_state *state, uint8_t reg1, uint8_t reg2) {
    int cyc = 5;
    unsigned char byte;
    uint8_t byte;

    if (reg2 == M) {
        cyc = 7;


@@ 535,8 535,8 @@ int SPHL(Cpu_state *state) {
// -- Immediate instructions --

int LXI(Cpu_state *state, uint8_t reg) {
    unsigned char byte1 = read_memory(state, state->pc + 1);
    unsigned char byte2 = read_memory(state, state->pc + 2);
    uint8_t byte1 = read_memory(state, state->pc + 1);
    uint8_t byte2 = read_memory(state, state->pc + 2);

    if (reg == SP) {
        state->sp = (byte2 << 8) | byte1;


@@ 552,7 552,7 @@ int LXI(Cpu_state *state, uint8_t reg) {

int MVI(Cpu_state *state, uint8_t reg) {
    int cyc = 7;
    unsigned char byte = read_memory(state, state->pc + 1);
    uint8_t byte = read_memory(state, state->pc + 1);

    if (reg == M) {
        cyc = 10;


@@ 832,7 832,7 @@ int CALL(Cpu_state *state) {
    if (5 == get_immediate_address(state)) {
        if (state->regs[C] == 9) {
            uint16_t offset = (state->regs[D]<<8) | (state->regs[E]);
            unsigned char *str = &read_memory(state, offset+3);
            uint8_t *str = &read_memory(state, offset+3);

            while (*str != '$')
                printf("%c", *str++);


@@ 1047,7 1047,7 @@ int HLT(Cpu_state *state) {
// -- The emulation nation --

int emulate_op(Cpu_state *state) {
    unsigned char op_code = read_memory(state, state->pc);
    uint8_t op_code = read_memory(state, state->pc);

    int cyc = 0;


M src/disassembler.c => src/disassembler.c +6 -5
@@ 1,8 1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include "disassembler.h"

int disassemble_op(unsigned char *memory, int pc) {
    unsigned char* op_code = &memory[pc];
int disassemble_op(uint8_t *memory, int pc) {
    uint8_t *op_code = &memory[pc];
    int op_bytes = 1;

    printf("%04x ", pc);


@@ 286,7 287,7 @@ int disassemble_op(unsigned char *memory, int pc) {
    return op_bytes;
}

unsigned char *read_rom(char *filename, int *fsize) {
uint8_t *read_rom(char *filename, int *fsize) {
    FILE *f = fopen(filename, "rb");
    if (!f) {
        printf("Could not open %s\n", filename);


@@ 297,7 298,7 @@ unsigned char *read_rom(char *filename, int *fsize) {
    *fsize = ftell(f);
    fseek(f, 0, SEEK_SET);

    unsigned char *buffer = malloc(*fsize);
    uint8_t *buffer = malloc(*fsize);

    int bytes_read = fread(buffer, 1, *fsize, f);
    fclose(f);


@@ 313,7 314,7 @@ unsigned char *read_rom(char *filename, int *fsize) {
/*
int main() {
    int fsize = 0;
    unsigned char *buffer = read_rom("rom/invaders", &fsize);
    uint8_t *buffer = read_rom("rom/invaders", &fsize);

    int pc = 0;
    while (pc < fsize) {

M src/disassembler.h => src/disassembler.h +3 -1
@@ 1,1 1,3 @@
int disassemble_op(unsigned char *codebuffer, int pc);
#include<stdint.h>

int disassemble_op(uint8_t *codebuffer, int pc);

M src/main.c => src/main.c +4 -4
@@ 24,7 24,7 @@ typedef struct {
    Port *port;
} Arcade_system;

void load_rom_file(char *filename, unsigned char *memory) {
void load_rom_file(char *filename, uint8_t *memory) {
    FILE *f = fopen(filename, "rb");
    if (!f) {
        printf("Could not open %s\n", filename);


@@ 45,8 45,8 @@ void load_rom_file(char *filename, unsigned char *memory) {
    }
}

unsigned char *initalise_memory(char *rom_path) {
    unsigned char *memory = malloc(sizeof(unsigned char) * 0x4000);
uint8_t *initalise_memory(char *rom_path) {
    uint8_t *memory = malloc(sizeof(uint8_t) * 0x4000);
    memset(memory, 0, 0x4000);

#if CPUDIAG


@@ 162,7 162,7 @@ int invaders_OUT(Arcade_system *system) {
}

int invaders_op(Arcade_system *system) {
    unsigned char op_code = read_memory(system->state, system->state->pc);
    uint8_t op_code = read_memory(system->state, system->state->pc);
    int cyc = 0;

    switch (op_code) {