Skip to content

Commit

Permalink
replace register mcfg to moff (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles authored Jul 25, 2021
1 parent 8d710c4 commit 63a6177
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
6 changes: 3 additions & 3 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` `mcfg` `muse` `mmax` `tmin` `mode` |
| 6 | **[MODE_MEMORY](#mode-memory)** | main memory controller | `nill` `free` `aloc` `moff` `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,8 +98,8 @@ CheatSheet
| :--: | :---: | :-: | :---------- |
| `free` | 1 | 001 | realese memory |
| `aloc` | 2 | 010 | reserve memory and set a value |
| `mcfg` | 3 | 011 | set memory config |
| `muse` | 4 | 100 | add memory config |
| `moff` | 3 | 011 | memory config remove mask |
| `muse` | 4 | 100 | memory config append mask |
| `mmax` | 5 | 101 | set max value allowed in memory |
| `mmin` | 6 | 110 | set min value allowed in memory |

Expand Down
2 changes: 1 addition & 1 deletion src/3bc_header.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ 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_mcfg(PARAMS_DEFINE);
void cpu_memory_moff(PARAMS_DEFINE);
void cpu_memory_muse(PARAMS_DEFINE);
void cpu_memory_mmin(PARAMS_DEFINE);
void cpu_memory_mmax(PARAMS_DEFINE);
Expand Down
4 changes: 2 additions & 2 deletions src/3bc_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define NB08 0b010

#define STRO 0b011
#define MCFG 0b011
#define MOFF 0b011
#define PULL 0b011
#define ZGTO 0b011
#define NB10 0B011
Expand Down Expand Up @@ -88,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_PACK6(MODE_MEMORY, cpu_memory_free, cpu_memory_aloc, cpu_memory_mcfg, cpu_memory_muse, cpu_memory_mmax, cpu_memory_mmin)
CPU_PACK6(MODE_MEMORY, cpu_memory_free, cpu_memory_aloc, cpu_memory_moff, 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
6 changes: 4 additions & 2 deletions src/cpu_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ void cpu_memory_aloc(PARAMS_DEFINE)
driver_memory_data_set(address, value);
}

void cpu_memory_mcfg(PARAMS_DEFINE)
void cpu_memory_moff(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
driver_memory_conf_set(address, value);
/** config remove mask (and not) */
driver_memory_conf_set(address, driver_memory_conf_get(address) &~ value);
}

void cpu_memory_muse(PARAMS_DEFINE)
{
REQUIRED_ADDRESS
/** config append mask (or) */
driver_memory_conf_set(address, driver_memory_conf_get(address) | value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpreter_syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bool interpreter_syntax_registers(const char* string, signed long int* value)
PARSER_PACK('p', 'u', 'l', 'l', value, PULL);
PARSER_PACK('p', 'u', 's', 'h', value, PUSH);

PARSER_PACK('m', 'c', 'f', 'g', value, MCFG);
PARSER_PACK('m', 'o', 'f', 'f', value, MOFF);
PARSER_PACK('m', 'm', 'a', 'x', value, MMAX);
PARSER_PACK('m', 'm', 'i', 'n', value, MMIN);

Expand Down
45 changes: 23 additions & 22 deletions tests/cpu.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,35 @@ def test_mode_5
def test_mode_6
console_input = [
"mode.0.6,mmin.1.0,mmax.1.1,aloc.1.2,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,mcfg.1.0b1110,aloc.1.0,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,mcfg.1.0b1110,aloc.1.2,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,mcfg.1.0b1110,aloc.1.4,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,mcfg.1.0b1110,aloc.1.6,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,mcfg.1.0b1110,aloc.1.8,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,mcfg.1.0b1110,aloc.1.10,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.1,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.2,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.3,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.4,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.5,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.10,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.11,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.12,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.13,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.14,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.19,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.20,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.21,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.22,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,mcfg.1.0b1110,aloc.1.23,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,muse.1.0b1110,aloc.1.0,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,muse.1.0b1110,aloc.1.2,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,muse.1.0b1110,aloc.1.4,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,muse.1.0b1110,aloc.1.6,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,muse.1.0b1110,aloc.1.8,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.8,mmax.1.9,muse.1.0b1110,aloc.1.10,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.1,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.2,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.3,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.4,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.5,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.10,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.11,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.12,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.13,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.14,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.19,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.20,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.21,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.22,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,mmin.1.11,mmax.1.13,muse.1.0b1110,aloc.1.23,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,muse.1.16,muse.1.128,aloc.1.0xFF,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,muse.1.16,aloc.1.0xFF,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,muse.1.32,muse.1.128,aloc.1.0xFF,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,muse.1.32,aloc.1.0xFF,mode.0.2,stri.1.0,mode.0.6,free.1.0",
"mode.0.6,muse.1.32,moff.1.32,aloc.1.0xFF,mode.0.2,stri.1.0,mode.0.6,free.1.0"
]
stdout, stderr, status = Open3.capture3("./3bc.test.bin", :stdin_data => console_input.join("\n"))
assert_equal "1888888131112131113111213111311121311255100", stdout
assert_equal "1888888131112131113111213111311121311255100255", stdout
assert_equal 0, status
end

Expand Down
2 changes: 1 addition & 1 deletion tests/fails.test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_number_dirty
end

def test_invalid_memory_config
for console_input in ['mode.0.6,mcfg.1.8','mode.0.6,mcfg.1.10','mode.0.6,mcfg.1.12','mode.0.6,mcfg.1.192','mode.0.6,mcfg.1.80','mode.0.6,mcfg.1.48','mode.0.6,mcfg.1.128']
for console_input in ['mode.0.6,muse.1.8','mode.0.6,muse.1.10','mode.0.6,muse.1.12','mode.0.6,muse.1.192','mode.0.6,muse.1.80','mode.0.6,muse.1.48','mode.0.6,muse.1.128']
stdout, stderr, status = Open3.capture3("./3bc.test.bin", :stdin_data => console_input)
assert_match /ERROR CODE\: (0x3BC017)/, stderr
assert_equal 15, status.exitstatus
Expand Down

0 comments on commit 63a6177

Please sign in to comment.