From: Tom Rauchenwald Date: 2006-08-01T05:01:47+09:00 Subject: Re: [QUIZ SOLUTION] #88 Chip-8 James Edward Gray II writes: > On Jul 30, 2006, at 12:17 PM, Tom Rauchenwald wrote: > >> Hi, >> >> Here is my solution to the current quiz. It has a few flaws, and it >> uses a method call for each statement (which is probably quite slow). >> The nice thing is that you can dump a program and view it in an >> assembler-like way. >> The implementation is quite simple, I don't think i need to explain it >> in detail. I hope i haven't screwed up somewhere :) > > Sure looks good to me. Here's one trivial suggestion though: What bugs me a little bit is that the jmp-code isn't quite right. If i read the spec right, it would be possible to jump to any byte in the source-file, even if it's in the middle of an opcode. With my solution this is not possible. But I realized that after I finished it, and I didn't want to rewrite it. >> if ARGV[0]==nil >> STDERR.puts "Usage: #{$0} \n" >> exit 1 >> end >> if !File.exist? ARGV[0] >> STDERR.puts "Error: File not found.\n" >> exit 1 >> end >> emu = Emulator.new >> emu.scan(ARGV[0]) >> print "Program read: \n" >> print "============= \n" >> emu.dump_prog >> print "\nRunning... \n\n" >> emu.run >> print "Done! Registers: \n" >> print "================ \n" >> emu.dump > > puts() will add a newline character, if it's not already at the end of > the String you pass to it, so you could lose a lot of \n's above if > you like. Thanks, and thanks that you manage this whole quiz-thing and do the summaries and everything. > James Edward Gray II Tom