prcalc.h 1.3 KB

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