Skip to content

Commit

Permalink
Arduino GPIO support & hash changes (#169)
Browse files Browse the repository at this point in the history
* rename (tcfg, tmax, tmin to mcfg, mmax, mmin) & add register muse

* add support gpio´s framework arduino

* now hash only start with ':' instead of being in quotes '"'

* add more tests to invalid memory configs

* add more tests to gpios memory config
  • Loading branch information
RodrigoDornelles authored Jul 24, 2021
1 parent 685831e commit 8d710c4
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 98 deletions.
9 changes: 5 additions & 4 deletions docs/cheatsheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CheatSheet
| 3 | **[MODE_INPUT](#mode-input)** | console input keyboard | `nill` `stri` `strc` `stro` `strx` `mode` |
| 4 | **[MODE_INPUT_SILENT](#mode-input-silent)** | console input keyboard (silent) | `nill` `stri` `strc` `stro` `strx` `mode` |
| 5 | **[MODE_INPUT_PASSWORD](#mode-input-password)** | console input keyboard (password) | `nill` `stri` `strc` `stro` `strx` `mode` |
| 6 | **[MODE_MEMORY](#mode-memory)** | main memory controller | `nill` `free` `aloc` `tcfg` `tmin` `tmax` `mode` |
| 6 | **[MODE_MEMORY](#mode-memory)** | main memory controller | `nill` `free` `aloc` `mcfg` `muse` `mmax` `tmin` `mode` |
| 7 | **[MODE_MEMORY_PTR](#mode-memory-ptr)** | pointers memory controller | `nill` `free` `aloc` `pull` `push` `mode` |
| 8 | **[MODE_MEMORY_AUX](#mode-memory-aux)** | aux memory controller | `nill` `free` `aloc` `pull` `push` `mode` |
| 9 | **[MODE_JUMP](#mode-jump)** | logical jumps between labels | `nill` `goto` `fgto` `zgto` `pgto` `ngto` `mode` |
Expand Down Expand Up @@ -98,9 +98,10 @@ CheatSheet
| :--: | :---: | :-: | :---------- |
| `free` | 1 | 001 | realese memory |
| `aloc` | 2 | 010 | reserve memory and set a value |
| `tcfg` | 3 | 011 | set config memory type |
| `tmax` | 4 | 100 | set max value in memory |
| `tmin` | 5 | 101 | set min value in memory |
| `mcfg` | 3 | 011 | set memory config |
| `muse` | 4 | 100 | add memory config |
| `mmax` | 5 | 101 | set max value allowed in memory |
| `mmin` | 6 | 110 | set min value allowed in memory |

## MODE MEMORY PTR ##

Expand Down
48 changes: 24 additions & 24 deletions examples/fibonacci.3bc
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@ STRC NILL 'I'
STRC NILL 'B'
STRC NILL ':'

# INPUT VAR "FIB:"
# INPUT VAR :FIB
MODE NILL 0d03
STRI "FIB:" NILL
STRI :FIB NILL

# FUNCTION "FIB_FUNC"
# PRINT VAR "NEXT"
# FUNCTION :FIB_FUNC
# PRINT VAR :NEXT
MODE NILL 2
NILL NILL "FIB_FUNC"
NILL NILL :FIB_FUNC
STRC NILL '\n'
STRI "NEXT" NILL
STRI :NEXT NILL

# "NEXT" = "NEXT" + "PREV"
# :NEXT = :NEXT + :PREV
MODE NILL 0d08
PUSH "NEXT" NILL
PUSH :NEXT NILL
MODE NILL 0d11
MATH "PREV" NILL
MATH :PREV NILL
MODE NILL 0d08
PULL "NEXT" NILL
PULL :NEXT NILL

# "PREV" = "PREV" - "NEXT"
# :PREV = :PREV - :NEXT
MODE NILL 0d08
PUSH "NEXT" NILL
PUSH :NEXT NILL
MODE NILL 0d12
MATH "PREV" NILL
MATH :PREV NILL
MODE NILL 0d08
PULL "PREV" NILL
PULL :PREV NILL

# IF "NEXT" == 0
# "NEXT" = 1
# IF :NEXT == 0
# :NEXT = 1
MODE NILL 0d08
PUSH "NEXT" NILL
PUSH :NEXT NILL
MODE NILL 0d09
PGTO NILL SKIP
MODE NILL 0d06
ALOC "NEXT" 1
ALOC :NEXT 1
NILL NILL SKIP

# "FIB:" = "FIB:" - 1
# IF "FIB:" > 0
# CALL "FIB_FUNC" RECURSIVE
# :FIB = :FIB - 1
# IF :FIB > 0
# CALL :FIB_FUNC RECURSIVE
MODE NILL 0d08
PUSH "FIB:" NILL
PUSH :FIB NILL
MODE NILL 0d12
MATH NILL 1
MODE NILL 0d08
PULL "FIB:" NILL
PULL :FIB NILL
MODE NILL 0d09
PGTO NILL "FIB_FUNC"
PGTO NILL :FIB_FUNC
14 changes: 7 additions & 7 deletions examples/pointers.3bc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
MODE NILL 0d06
ALOC "a1" 0d07
ALOC "a2" 0d00
ALOC "p1" "a1"
ALOC "p2" "a2"
ALOC :a1 0d07
ALOC :a2 0d00
ALOC :p1 :a1
ALOC :p2 :a2

MODE NILL 0d07
PUSH "p1" NILL
PULL "p2" NILL
PUSH :p1 NILL
PULL :p2 NILL

MODE NILL 0d02
STRI "a2" NILL
STRI :a2 NILL
5 changes: 5 additions & 0 deletions src/3bc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#ifdef _3BC_PC_WINDOWS
#include <conio.h>
#endif
#ifdef _3BC_ARDUINO
#include <Arduino.h>
#endif


/** headers **/
#include "3bc_errors.h"
Expand Down Expand Up @@ -59,6 +63,7 @@
#ifdef __cplusplus
/**
* when require C++ adpatations
* TODO: remove
*/
#include "lang_plus.cpp"
#endif
Expand Down
11 changes: 7 additions & 4 deletions src/3bc_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ void cpu_jump_ngto(PARAMS_DEFINE);
/** FILE: cpu_memory.c **/
void cpu_memory_free(PARAMS_DEFINE);
void cpu_memory_aloc(PARAMS_DEFINE);
void cpu_memory_tcfg(PARAMS_DEFINE);
void cpu_memory_tmin(PARAMS_DEFINE);
void cpu_memory_tmax(PARAMS_DEFINE);
void cpu_memory_mcfg(PARAMS_DEFINE);
void cpu_memory_muse(PARAMS_DEFINE);
void cpu_memory_mmin(PARAMS_DEFINE);
void cpu_memory_mmax(PARAMS_DEFINE);
void cpu_memory_ptr_free(PARAMS_DEFINE);
void cpu_memory_ptr_aloc(PARAMS_DEFINE);
void cpu_memory_ptr_pull(PARAMS_DEFINE);
Expand Down Expand Up @@ -121,8 +122,10 @@ data_3bc_t driver_memory_vmax_get(address_3bc_t address);
data_3bc_t driver_memory_vmin_get(address_3bc_t address);
data_3bc_t driver_memory_conf_get(address_3bc_t address);
address_3bc_t driver_memory_pointer(address_3bc_t address);
void driver_memory_gpio(struct memory_node_s* node);
void driver_memory_lineup(struct memory_node_s* node);
void tape_memory_free(address_3bc_t address);
void driver_memory_reload(struct memory_node_s* node);
void driver_memory_free(address_3bc_t address);

/** FILE: driver_power.c **/
#ifdef _3BC_COMPUTER
Expand Down
13 changes: 9 additions & 4 deletions src/3bc_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@
#define GET_ANY_PARAM (address?driver_memory_data_get(address):value)
#endif

#define MEM_CONFIG_MAX_VALUE (0b0010)
#define MEM_CONFIG_MIN_VALUE (0b0100)
#define MEM_CONFIG_NORMALIZE (0b1000)
#define MEM_CONFIG_RESERVED (0b00000001) /** unused for a while **/
#define MEM_CONFIG_MAX_VALUE (0b00000010) /** exists maximum value **/
#define MEM_CONFIG_MIN_VALUE (0b00000100) /** exists minimum value **/
#define MEM_CONFIG_NORMALIZE (0b00001000) /** transform clamp to map **/
#define MEM_CONFIG_GPIO_SEND (0b00010000) /** digital output **/
#define MEM_CONFIG_GPIO_READ (0b00100000) /** digital input **/
#define MEM_CONFIG_GPIO_PULL (0b01000000) /** pullup input **/
#define MEM_CONFIG_GPIO_ANAL (0b10000000) /** analogic/pwd **/

/**
* FUNCTIONS MACROS
Expand Down Expand Up @@ -139,5 +144,5 @@
#define CPU_PACK3(mode,a,b,c) {&cpu_null,&a,&b,&c,&cpu_not_exist,&cpu_not_exist,&cpu_not_exist,&cpu_mode},
#define CPU_PACK4(mode,a,b,c,d) {&cpu_null,&a,&b,&c,&d,&cpu_not_exist,&cpu_not_exist,&cpu_mode},
#define CPU_PACK5(mode,a,b,c,d,e) {&cpu_null,&a,&b,&c,&d,&e,&cpu_not_exist,&cpu_mode},
#define CPU_PACK6(mode,a,b,c,d,e,f) {&cpu_null,&a,&b,&c,&d,&e,&cpu_mode},
#define CPU_PACK6(mode,a,b,c,d,e,f) {&cpu_null,&a,&b,&c,&d,&e,&f,&cpu_mode},
#endif
9 changes: 5 additions & 4 deletions src/3bc_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,22 @@
#define NB08 0b010

#define STRO 0b011
#define TCFG 0b011
#define MCFG 0b011
#define PULL 0b011
#define ZGTO 0b011
#define NB10 0B011

#define STRX 0b100
#define PGTO 0b100
#define TMAX 0b100
#define MUSE 0b100
#define SPIN 0b100
#define NB16 0b100

#define TMIN 0b101
#define MMAX 0b101
#define NGTO 0b101
#define PUSH 0b101

#define MMIN 0b110
/**
* case of separate compilation in different statistical libraries,
* only FILE: tape_program.c must know this variable
Expand All @@ -87,7 +88,7 @@ function_3bc_t instructions(cpumode_3bc_t mode, register_3bc_t reg)
CPU_PACK4(MODE_INPUT, cpu_input_stri, cpu_input_strc, cpu_input_stro, cpu_input_strx)
CPU_PACK4(MODE_INPUT_SILENT, cpu_input_silent_stri, cpu_input_silent_strc, cpu_input_silent_stro, cpu_input_silent_strx)
CPU_PACK4(MODE_INPUT_PASSWORD, cpu_input_password_stri, cpu_input_password_strc, cpu_input_password_stro, cpu_input_password_strx)
CPU_PACK5(MODE_MEMORY, cpu_memory_free, cpu_memory_aloc, cpu_memory_tcfg, cpu_memory_tmax, cpu_memory_tmin)
CPU_PACK6(MODE_MEMORY, cpu_memory_free, cpu_memory_aloc, cpu_memory_mcfg, cpu_memory_muse, cpu_memory_mmax, cpu_memory_mmin)
CPU_PACK5(MODE_MEMORY_PTR, cpu_memory_ptr_free, cpu_memory_ptr_aloc, cpu_memory_ptr_pull, cpu_memory_ptr_spin, cpu_memory_ptr_push)
CPU_PACK5(MODE_MEMORY_AUX, cpu_memory_aux_free, cpu_memory_aux_aloc, cpu_memory_aux_pull, cpu_memory_aux_spin, cpu_memory_aux_push)
CPU_PACK5(MODE_JUMP,cpu_jump_goto, cpu_jump_fgto, cpu_jump_zgto, cpu_jump_pgto, cpu_jump_ngto)
Expand Down
16 changes: 11 additions & 5 deletions src/cpu_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void cpu_memory_free(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
VALIDATE_NOT_VALUES
tape_memory_free(address);
driver_memory_free(address);
}

void cpu_memory_aloc(PARAMS_DEFINE)
Expand All @@ -13,19 +13,25 @@ void cpu_memory_aloc(PARAMS_DEFINE)
driver_memory_data_set(address, value);
}

void cpu_memory_tcfg(PARAMS_DEFINE)
void cpu_memory_mcfg(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
driver_memory_conf_set(address, value);
}

void cpu_memory_tmin(PARAMS_DEFINE)
void cpu_memory_muse(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
driver_memory_conf_set(address, driver_memory_conf_get(address) | value);
}

void cpu_memory_mmin(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
driver_memory_vmin_set(address, value);
}

void cpu_memory_tmax(PARAMS_DEFINE)
void cpu_memory_mmax(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
driver_memory_vmax_set(address, value);
Expand All @@ -35,7 +41,7 @@ void cpu_memory_ptr_free(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
VALIDATE_NOT_VALUES
tape_memory_free(POINTER(address));
driver_memory_free(POINTER(address));
}

void cpu_memory_ptr_aloc(PARAMS_DEFINE)
Expand Down
Loading

0 comments on commit 8d710c4

Please sign in to comment.