prcalc.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef _PRCALC_H
  2. #define _PRCALC_H
  3. #include <stdint.h>
  4. #include <math.h>
  5. #include <stdlib.h>
  6. #define STACK_SIZE 1024
  7. #define CARRY 1
  8. #define NEGATIVE 2
  9. #define OVERFLOW 4
  10. typedef enum BOOL {FALSE, TRUE} _PRC_BOOL;
  11. /*
  12. * A -> general purpose register
  13. * B -> general purpose register
  14. * SP -> stack pointer. index where the stack is positioned
  15. * FLAGS -> 8 bit operation result flags (LSB)
  16. * 1 -> Carry bit
  17. * 2 -> Negative
  18. * 4 -> Overflow
  19. * 8 ->
  20. * 16 ->
  21. * 32 ->
  22. * 64 ->
  23. * 128 ->
  24. */
  25. typedef struct prc_registers {
  26. uint64_t A;
  27. uint64_t B;
  28. uint16_t SP;
  29. uint8_t FLAGS;
  30. } __prc_registers;
  31. typedef uint64_t __prc_stack[STACK_SIZE];
  32. typedef struct prc_context {
  33. __prc_registers registers;
  34. __prc_stack stack;
  35. } prc_context;
  36. typedef enum PRC_ERROR {OK, STACK_OVERFLOW, STACK_EMPTY, STATE_UNDEFINED} PRC_ERROR;
  37. typedef enum PRC_OPERATION {ADD, SUB, MUL, DIV} __PRC_OPERATION;
  38. PRC_ERROR prc_init_context(prc_context *ctx);
  39. PRC_ERROR prc_push(prc_context *ctx, uint64_t val);
  40. PRC_ERROR prc_pop(prc_context *ctx, uint64_t *val);
  41. PRC_ERROR prc_set_a(prc_context *ctx, uint64_t val);
  42. PRC_ERROR prc_set_b(prc_context *ctx, uint64_t val);
  43. PRC_ERROR prc_swap(prc_context *ctx);
  44. PRC_ERROR prc_add_stack (prc_context *ctx);
  45. PRC_ERROR prc_mul_stack (prc_context *ctx);
  46. #endif //_PRCALC_H