forked from tonk-labs/dappicom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tonk-labs#21 from Prabhat1308/main
feat: Add implementation of INY and DEY opcode changes to dey fix Signed-off-by: Prabhat1308 <[email protected]> feat: add opcodes clc cld cli clv Signed-off-by: Prabhat1308 <[email protected]> reolve merge conflicts Signed-off-by: Prabhat1308 <[email protected]> fix: merge issues Signed-off-by: Prabhat1308 <[email protected]>
- Loading branch information
Showing
11 changed files
with
930 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
authors = [""] | ||
compiler_version = "0.1" | ||
compiler_version = ">=0.1" | ||
|
||
[dependencies] | ||
opcodes = { path = "../opcodes" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,135 @@ | ||
use dep::helpers; | ||
use dep::std; | ||
|
||
fn check_op( | ||
//PC = 8203 | ||
//X = 8201 | ||
//Y = 8202 | ||
//A = 8200 | ||
//SR = 8205 | ||
//M = 8204 | ||
|
||
fn main( | ||
r: Field, | ||
op_sorted_step: [Field; 21], | ||
op_sorted_addr: [Field; 21], | ||
op_sorted_val: [Field; 21], | ||
op_sorted_op_rw: [Field; 21] | ||
) -> Field { | ||
// TODO: implemented mode retrieval here for the opcode read | ||
// we don't generalize this because each opcode will only have a few modes | ||
// and we want to keep the total constraints down rather than needlessly | ||
// checking for other opcodes every time | ||
|
||
let mode: Field = 0; //stubbed for now, we assume the mode is retreived in logic above | ||
let mut sub_arr_step: [Field; 7] = [0,0,0,0,0,0,0]; | ||
let mut sub_arr_addr: [Field; 7] = [0,0,0,0,0,0,0]; | ||
let mut sub_arr_val: [Field; 7] = [0,0,0,0,0,0,0]; | ||
let mut sub_arr_op_rw: [Field; 7] = [0,0,0,0,0,0,0]; | ||
for i in 0..7 { | ||
sub_arr_step[i] = op_sorted_step[i]; | ||
sub_arr_addr[i] = op_sorted_addr[i]; | ||
sub_arr_val[i] = op_sorted_val[i]; | ||
sub_arr_op_rw[i] = op_sorted_op_rw[i]; | ||
op_sorted_step: [Field; 7], | ||
op_sorted_addr: [Field; 7], | ||
op_sorted_val: [Field; 7], | ||
op_sorted_op_rw: [Field; 7] | ||
) -> pub Field { | ||
|
||
//check the program counter | ||
assert(op_sorted_addr[0] == 8203); | ||
assert(op_sorted_op_rw[0] == 0); | ||
let pc = op_sorted_val[0]; | ||
|
||
//check the opcode | ||
assert(op_sorted_val[1] == 24); //0x18 | ||
assert(op_sorted_op_rw[1] == 0); | ||
|
||
//update the PC | ||
assert(op_sorted_addr[2] == 8203); | ||
assert(op_sorted_op_rw[2] == 1); | ||
assert(op_sorted_val[2] == pc + 1); | ||
|
||
let mut sub_arr_addr: [Field; 2] = [0,0]; | ||
let mut sub_arr_val: [Field; 2] = [0,0]; | ||
let mut sub_arr_op_rw: [Field; 2] = [0,0]; | ||
let offset = 3; | ||
for i in 0..2 { | ||
sub_arr_addr[i] = op_sorted_addr[offset + i]; | ||
sub_arr_val[i] = op_sorted_val[offset + i]; | ||
sub_arr_op_rw[i] = op_sorted_op_rw[offset + i]; | ||
} | ||
let address_and_value: [Field; 2] = helpers::get_addressing( | ||
mode, | ||
sub_arr_step, | ||
|
||
helpers::imp( | ||
sub_arr_addr, | ||
sub_arr_val, | ||
sub_arr_op_rw | ||
); | ||
|
||
// TODO: implement the rest of the op code checks here | ||
//read status register | ||
assert(op_sorted_addr[5] == 8205); | ||
assert(op_sorted_op_rw[5] == 0); | ||
let sr = op_sorted_val[5]; | ||
|
||
let mut status = helpers::convert_to_status(sr); | ||
|
||
//clear the interrupt flag. | ||
status = helpers::clear_carry_bit(status); | ||
let comp_status = helpers::status_to_num(status); | ||
|
||
// TODO: handle case of padding | ||
//write on status register | ||
assert(op_sorted_addr[6] == 8205); | ||
assert(op_sorted_op_rw[6] == 1); | ||
assert(op_sorted_val[6] == comp_status); | ||
|
||
// Compute permutation and return it | ||
helpers::compute_permutation( | ||
helpers::compute_permutation_7( | ||
r, | ||
op_sorted_step, | ||
op_sorted_addr, | ||
op_sorted_val, | ||
op_sorted_op_rw | ||
) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_0() -> Field { | ||
main( | ||
1, | ||
[343432, 343433, 343434, 343435, 343436, 343437, 343438], | ||
[8203, 79, 8203, 8203, 80, 8205, 8205], | ||
[49231, 24, 49232, 49232, 224, 38, 38], | ||
[0, 0, 1, 0, 0, 0, 1] | ||
) | ||
} | ||
#[test] | ||
fn test_1() -> Field { | ||
main( | ||
1, | ||
[343492, 343493, 343494, 343495, 343496, 343497, 343498], | ||
[8203, 79, 8203, 8203, 80, 8205, 8205], | ||
[49231, 24, 49232, 49232, 224, 1, 0], | ||
[0, 0, 1, 0, 0, 0, 1] | ||
) | ||
} | ||
#[test] | ||
fn test_2() -> Field { | ||
main( | ||
1, | ||
[343552, 343553, 343554, 343555, 343556, 343557, 343558], | ||
[8203, 79, 8203, 8203, 80, 8205, 8205], | ||
[49231, 24, 49232, 49232, 224, 255, 254], | ||
[0, 0, 1, 0, 0, 0, 1] | ||
) | ||
} | ||
#[test] | ||
fn test_3() -> Field { | ||
main( | ||
1, | ||
[343612, 343613, 343614, 343615, 343616, 343617, 343618], | ||
[8203, 79, 8203, 8203, 80, 8205, 8205], | ||
[49231, 24, 49232, 49232, 224, 123, 122], | ||
[0, 0, 1, 0, 0, 0, 1] | ||
) | ||
} | ||
#[test] | ||
fn test_4() -> Field { | ||
main( | ||
1, | ||
[343672, 343673, 343674, 343675, 343676, 343677, 343678], | ||
[8203, 79, 8203, 8203, 80, 8205, 8205], | ||
[49231, 24, 49232, 49232, 224, 0, 0], | ||
[0, 0, 1, 0, 0, 0, 1] | ||
) | ||
} | ||
#[test] | ||
fn test_5() -> Field { | ||
main( | ||
1, | ||
[343732, 343733, 343734, 343735, 343736, 343737, 343738], | ||
[8203, 79, 8203, 8203, 80, 8205, 8205], | ||
[49231, 24, 49232, 49232, 224, 36, 36], | ||
[0, 0, 1, 0, 0, 0, 1] | ||
) | ||
} | ||
|
||
|
Oops, something went wrong.