Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!wuarchive!udel!princeton!phoenix!tbrakitz From: tbrakitz@phoenix.Princeton.EDU (Byron Rakitzis) Newsgroups: comp.sys.apple2 Subject: Re: Xapple2 Message-ID: <14340@phoenix.Princeton.EDU> Date: 7 Mar 90 18:06:15 GMT References: <53040@bbn.COM> <53134@bbn.COM> Reply-To: tbrakitz@phoenix.Princeton.EDU (Byron Rakitzis) Organization: Princeton University, NJ Lines: 37 In article <53134@bbn.COM> kanarick@vax.bbn.com (Craig M. Kanarick) writes: >Basically, I have written, in C, a 6502 emulator. It has an array of >16-bit values, and is the memory of the Apple. I also have 5 16-bit >registers, and a program counter. Basically, the emulator is just a >big case statement, each branch being one 6502 instruction (yes, there >are a lot, because each instruction/addressing mode pair is a seperate >branch). I am about halfway done with this part. Essentially, I just I wrote a rudimentary 6502 emulator in C last summer which I have not gotten around to debugging yet. The code is really messy, and I'm not very proud of it, but there's a MUCH better way to go about finding the next instruction! 1) I keep a 256-valued array of struct containing the info: instruction, addressing mode, cycles. This way, by checking the array for any particular opcode, I can determine in constant time what the instruction, opcode is supposed to be. 2) (the sneaky part) the "instruction" datum is simply an index to another array of pointer to function! So, each function is an instruction which does the obvious thing (load, rol whatever) and the trick is to set up the addressing mode first (just pass the right pointers to accumulator, memory, whatever) and then in one statement execute_instruction[x](), go there! If anybody wants the code they are free to have it, but it doesn't work and I really can't be bothered to look at it. It was written in great haste at the end of the summer, but most of the grungy work is done. -- Just try taking your VAX down to Jiffy-Lube these days! Byron "Bo knows parallel computational geometry" Rakitzis. (tbrakitz@phoenix.Princeton.EDU)