Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/sixtyfive-oh-two|the CHICKEN 5 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags:eggs]] [[toc:]] == sixtyfive-oh-two === Introduction An emulator for the [[https://en.wikipedia.org/wiki/6502|6502]] CPU. Only the pure CPU is emulated, no hardware-interaction model is provided. The opcode-interpreter is implemented in [[crunch]], and so a C++ compiler must be installed on your system. The interpreter-code is pre-compiled and included in the egg as compiling it takes quite a while. Compiling the C++ code needs {{crunch.h}}, so the [[crunch]] extension must be installed. === Procedures <procedure>(make-processor #!key memory registers)</procedure> Returns a record structure representing a single 6502 processor. {{memory}} should be an u8vector that is used as RAM, usually of length 65546. {{registers}} should be an 7 element u8vector, where the elements hold the values of the registers, according to the following table: <table> <tr><th>Index</th><th>Register</th></tr> <tr><td>0</td><td>{{A}}</td></tr> <tr><td>1</td><td>{{X}}</td></tr> <tr><td>2</td><td>{{Y}}</td></tr> <tr><td>3</td><td>{{P}}</td></tr> <tr><td>4</td><td>{{S}}</td></tr> <tr><td>5</td><td>{{PC}} (low byte)</td></tr> <tr><td>6</td><td>{{PC}} (high byte)</td></tr> </table> <procedure>(processor? X)</procedure> Returns {{#t}} if {{X}} is a {{processor}} record or {{#f}} otherwise. <procedure>(processor-memory P)</procedure> <procedure>(processor-memory-set! P U8VECTOR)</procedure> <procedure>(processor-registers P)</procedure> <procedure>(processor-registers-set! P U8VECTOR)</procedure> Accessors for the {{processor}} record. <procedure>(reset! P)</procedure> Resets the CPU represented by P by setting {{A}}, {{X}}, {{Y}} to zero, {{P}} to {{#x20}}, {{S}} to {{#xff}} and {{PC}} to the 16-bit address stored at location {{#xfffc}}. <procedure>(execute! P #!key cycles)</procedure> Executes instructions for processor {{P}} with the state currently active in the processor record. Execution continues endlessly or after at least {{cycles}} CPU cycles have been consumed (instructions always run to completion). <procedure>(interrupt! P VEC)</procedure> Triggers an interrupt for processor {{P}} by pushing the {{PC}} and {{P}} registers, setting the interrupt flag and continuing execution at the address stored at the memory location given in {{VEC}}. === Examples Say you need a fast way of multiplying an 8-bit quantity with 10, then you could do: <enscript highlight=scheme> (use sixtyfive-oh-two srfi-4 lolevel utils miscmacros) ;; Fast Multiply by 10 ;; By Leo Nechaev (leo@ogpi.orsk.ru), 28 October 2000. ; * = $1000 ; LDA #18 ; JSR MULT10 ; L1: ; JMP L1 ; MULT10: ; ASL A ;multiply by 2 ; STA TEMP ;temp store in TEMP ; ASL A ;again multiply by 2 (*4) ; ASL A ;again multiply by 2 (*8) ; CLC ; ADC TEMP ;as result, A = x*8 + x*2 ; RTS (define mult10 '#${a9 12 20 08 10 4c 05 10 0a 8d 00 20 0a 0a 18 6d 00 20 60}) (define p (make-processor)) (move-memory! mult10 (processor-memory p) (blob-size mult10) 0 #x1000) (define regs (processor-registers p)) (u8vector-set! regs 5 #x00) ; PC = #x1000 (u8vector-set! regs 6 #x10) (execute! p cycles: 100) (pp regs) (assert (= 180 (u8vector-ref regs 0))) </enscript> The {{sixtyfive-oh-two}} egg also contains a copy of the [[http://www.forth.org/|FIG]] Forth interpreter for the 6502. Download the code by entering chicken-install -retrieve -test sixtyfive-oh-two and check out the "test" subdirectory. More examples, the sources for the interpreter and hardware emulation code can be found in the egg SVN repository: [[http://code.call-cc.org/svn/chicken-eggs/release/4/sixtyfive-oh-two/stuff/]] (user: {{anonymous}}, password: empty). === Authors Felix Winkelmann === License (c)2012 Felix Winkelmann Available under a 3-clause BSD license. === Version History ; 0.1 : initial release
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 3 from 4?