old-computer-simulator

godot game
git clone git://git.evenfri.pw/old-computer-simulator.git
Log | Files | Refs

emu.h (1202B)


      1 #ifndef EMU_H
      2 #define EMU_H
      3 
      4 #include <stdlib.h>
      5 #include <stdint.h>
      6 #include <stdio.h>
      7 #include <string.h>
      8 #include <stdbool.h>
      9 
     10 #include "dat.h"
     11 
     12 #if defined(__GNUC__) || defined(__clang__)
     13   #define EXPORT __attribute__((visibility("default")))
     14 #else
     15   #define EXPORT
     16 #endif
     17 
     18 typedef unsigned char byte;
     19 
     20 #define FLAG_SET(e, bit) ((e)->f |= (1u << (bit)))
     21 #define FLAG_CLR(e, bit) ((e)->f &= ~(1u << (bit)))
     22 #define FLAG_GET(e, bit) (((e)->f >> (bit)) & 1u)
     23 #define FLAG_PUT(e, bit, v) \
     24   ((e)->f = (v) ? ((e)->f |  (1u << (bit))) \
     25                 : ((e)->f & ~(1u << (bit))))
     26 
     27 static inline int parity_even(uint8_t x) {
     28   int ones = 0;
     29   for (int i = 0; i < 8; i++) ones += (x >> i) & 1;
     30   return (ones & 1) == 0;
     31 }
     32 
     33 #ifdef __cplusplus
     34 extern "C" {
     35 #endif
     36 
     37 EXPORT emu_t* emu_create(void);
     38 EXPORT int emu_load_program(emu_t *e, const char *filename);
     39 EXPORT void emu_destroy(emu_t *e);
     40 EXPORT int emu_step(emu_t *e);
     41 EXPORT void emu_mem_write(emu_t *e, uint16_t addr, byte val);
     42 EXPORT byte emu_mem_read(emu_t *e, uint16_t addr);
     43 EXPORT int emu_get_pc(emu_t *e);
     44 EXPORT void emu_set_pc(emu_t *e, int pc);
     45 EXPORT byte emu_get_reg(emu_t *e, byte c);
     46 
     47 #ifdef __cplusplus
     48 }
     49 #endif
     50 
     51 #endif /* EMU_H */