File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -292,6 +292,10 @@ impl Computer {
292292 touched_addresses
293293 }
294294
295+ // pub fn load_values_to_ram(&mut self, values: Vec<Value>) {
296+
297+ // }
298+
295299 pub fn clock_cycle ( & mut self ) -> bool {
296300 // Stage 1: Fetch
297301 let ram_index = self . registers . program_counter ;
Original file line number Diff line number Diff line change @@ -17,12 +17,18 @@ fn main() -> Result<(), color_eyre::Report> {
1717 Command :: Run { file } => {
1818 let program = std:: fs:: read_to_string ( file) ?;
1919 let machine_code = assembler:: assemble ( & program) ?;
20- let machine_code_array: & [ Value ; 100 ] = & machine_code. clone ( ) . try_into ( ) . map_err ( |_| {
21- eyre ! ( "Assembled machine code does ({} letterboxes) not fit into memory (100 letterboxes max)." , & machine_code. len( ) )
22- } ) ?;
20+
21+ // Initialize memory with the machine code
22+ let mut machine_code_array: [ Value ; 100 ] = [ Value :: zero ( ) ; 100 ] ;
23+ if & machine_code. len ( ) > & machine_code_array. len ( ) {
24+ return Err ( eyre ! ( "Program too large to fit in memory" ) ) ;
25+ }
26+ for i in 0 ..machine_code. len ( ) {
27+ machine_code_array[ i] = machine_code[ i] ;
28+ }
29+
2330 let mut computer = Computer :: new ( ComputerConfig {
24- // FIXME
25- ram : machine_code_array. clone ( ) ,
31+ ram : machine_code_array,
2632 ..ComputerConfig :: default ( )
2733 } ) ;
2834 computer. run ( ) ;
You can’t perform that action at this time.
0 commit comments