<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-574530735080888819</id><updated>2011-04-21T20:56:47.322+02:00</updated><title type='text'>Writing a 6502 emulator from scratch</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>8</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-931189433325983431</id><published>2009-03-26T12:51:00.011+01:00</published><updated>2009-03-26T13:08:51.852+01:00</updated><title type='text'></title><content type='html'>In this project i have written more macros than ever before. The main reason is the similarities between opcodes, that the way the read operands are similar. By using macros the opcode implementations can be kept down to 2-3 lines of code instead of 6-7, which makes it much easier to maintain. It is also generally faster implementing it as macros as real functions.&lt;br /&gt;&lt;br /&gt;Below you can see macros helping with data retrieval. The code is a bit more linebreaked here, just to fit the stupid fixed blog width.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:9px;"&gt;// Macros for addressing modes&lt;br /&gt;#define READ_BYTE_IMM()     read_byte( PC++ )&lt;br /&gt;&lt;br /&gt;// Read addresses&lt;br /&gt;#define READ_ADDR_ZP()    (READ_BYTE_IMM())&lt;br /&gt;#define READ_ADDR_ZP_X()  ((READ_BYTE_IMM() + X) &amp; 0xff)&lt;br /&gt;#define READ_ADDR_ZP_Y()  ((READ_BYTE_IMM() + Y) &amp; 0xff)&lt;br /&gt;&lt;br /&gt;#define READ_ADDR_ABS()   (READ_BYTE_IMM() \&lt;br /&gt;                           | READ_BYTE_IMM()&lt;&lt;8)&lt;br /&gt;#define READ_ADDR_ABS_X() (READ_ADDR_ABS() + X)&lt;br /&gt;#define READ_ADDR_ABS_Y() (READ_ADDR_ABS() + Y)&lt;br /&gt;&lt;br /&gt;#define READ_ADDR_IND_X() (read_word_zp(\&lt;br /&gt;                             READ_BYTE_IMM() + X))&lt;br /&gt;#define READ_ADDR_IND_Y() (read_word_zp(\&lt;br /&gt;                             READ_BYTE_IMM()) + Y)&lt;br /&gt;&lt;br /&gt;#define READ_JUMP_ADDR()  (b1 = READ_BYTE_IMM(), b1 &amp; \&lt;br /&gt;                0x80 ? (PC - ((b1 ^ 0xff)+1)) : (PC + b1))&lt;br /&gt;&lt;br /&gt;// Read data&lt;br /&gt;#define READ_BYTE_ZP()    read_byte_zp(READ_ADDR_ZP())&lt;br /&gt;#define READ_BYTE_ZP_X()  read_byte_zp(READ_ADDR_ZP_X())&lt;br /&gt;#define READ_BYTE_ZP_Y()  read_byte_zp(READ_ADDR_ZP_Y())&lt;br /&gt;&lt;br /&gt;#define READ_BYTE_ABS()   read_byte(READ_ADDR_ABS())&lt;br /&gt;#define READ_BYTE_ABS_X() read_byte(READ_ADDR_ABS_X())&lt;br /&gt;#define READ_BYTE_ABS_Y() read_byte(READ_ADDR_ABS_Y())&lt;br /&gt;&lt;br /&gt;#define READ_BYTE_IND_X() read_byte(READ_ADDR_IND_X())&lt;br /&gt;#define READ_BYTE_IND_Y() read_byte(READ_ADDR_IND_Y())&lt;br /&gt;&lt;br /&gt;#define PUSH_BYTE_STACK(b) (memory-&gt;mem[ (SP--) \&lt;br /&gt;                            | STACK_BOTTOM ] = (b))&lt;br /&gt;#define POP_BYTE_STACK(b)  memory-&gt;mem[ (++SP)  \&lt;br /&gt;                            | STACK_BOTTOM ]&lt;br /&gt;&lt;br /&gt;// Macros for flag handling&lt;br /&gt;#define SET_FLAG_NZ(B)     (N = Z = B)&lt;br /&gt;&lt;br /&gt;#define IS_ZERO            (!Z)&lt;br /&gt;#define IS_NEGATIVE        (!!(N &amp; 0x80))&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This allows opcode implementations like:&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:10px;"&gt; // And accumulator with memory&lt;br /&gt; case AND_IMM:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_IMM());&lt;br /&gt;     break;&lt;br /&gt; case AND_ZP:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_ZP());&lt;br /&gt;     break;&lt;br /&gt; case AND_ZP_X:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_ZP_X());&lt;br /&gt;     break;&lt;br /&gt; case AND_ABS:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_ABS());&lt;br /&gt;     break;&lt;br /&gt; case AND_ABS_X:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_ABS_X());&lt;br /&gt;     break;&lt;br /&gt; case AND_ABS_Y:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_ABS_Y());&lt;br /&gt;     break;&lt;br /&gt; case AND_IND_X:&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_IND_X());&lt;br /&gt;     break;&lt;br /&gt; case AND_IND_Y :&lt;br /&gt;     SET_FLAG_NZ(A &amp;amp;= READ_BYTE_IND_Y());&lt;br /&gt;     break;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;and&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-size:10px;"&gt; case JMP_ABS:&lt;br /&gt;     PC = READ_ADDR_ABS();&lt;br /&gt;     break;&lt;br /&gt; case JMP_IND:&lt;br /&gt;     PC = read_word(READ_ADDR_ABS());&lt;br /&gt;     break;&lt;br /&gt;&lt;br /&gt; case JSR:&lt;br /&gt;     PUSH_BYTE_STACK( PC+1 &gt;&gt; 8 );&lt;br /&gt;     PUSH_BYTE_STACK( PC+1 );&lt;br /&gt;     PC = READ_ADDR_ABS();&lt;br /&gt;     break;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Nice!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-931189433325983431?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/931189433325983431/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/in-this-project-i-have-written-more.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/931189433325983431'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/931189433325983431'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/in-this-project-i-have-written-more.html' title=''/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-4039416205570153026</id><published>2009-03-26T12:46:00.003+01:00</published><updated>2009-03-26T12:50:24.395+01:00</updated><title type='text'>Booting Basic!</title><content type='html'>Some week ago I tried to load the Basic ROM from an Oric1 and run it with my CPU emulator. First it behaved a bit strange. It didn't return from subroutines as expected. After some debugging  I found  that I had forgotten to add the necessary one to the PC stored on stack when doing RTS. After fixing that it seems to run! I need to read some more on the Oric ROM:s to actually know that it does what expected, but sweet progression after all!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-4039416205570153026?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/4039416205570153026/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/booting-basic.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/4039416205570153026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/4039416205570153026'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/booting-basic.html' title='Booting Basic!'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-8396236239823360883</id><published>2009-03-13T22:12:00.002+01:00</published><updated>2009-03-13T22:29:12.315+01:00</updated><title type='text'>Total recall</title><content type='html'>&lt;p&gt;First time ever syndome... When completing the flag handling and the decimal arithmetic mode I realized that my opcode implementations were inefficient. I had already used macros for such things as memory address decoding and memory retrieval, but still every opcode was around 4-6 lines of code, code that had to be correct and maintained. I have now rewritten it with better macros and the opcodes are now around 2-3 lines of code. The execution speed, mainly be using a more lazy flag approach, seems to be faster as well. Yesterday I implemented the decimal version of the ADC and ABC functions, allowing addition and subtraction decimally. I borrowed some idead, mainly the binary arithmetics, from &lt;a href="http://frodo.cebix.net/"&gt;Frodo&lt;/a&gt; here. &lt;/p&gt;&lt;p&gt;Plans now are to add a new thread to my emulator, allowing access to memory and registers during execution. I need something like that to test and debug my processor. &lt;/p&gt;&lt;p&gt;After that I will implement some initial binary loading for my memory class. I should at least add a function that loads binaries to specified memory locations. There seems to be binary formats for this that I probably want to support as well. &lt;/p&gt;&lt;p&gt;Good is that my CPU seems to be fully implemented! Now I need to investigate the rest!&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-8396236239823360883?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/8396236239823360883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/total-recall.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/8396236239823360883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/8396236239823360883'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/total-recall.html' title='Total recall'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-8394117541014438461</id><published>2009-03-11T13:31:00.008+01:00</published><updated>2009-03-11T13:48:23.795+01:00</updated><title type='text'>Waving flags</title><content type='html'>&lt;p&gt;Yesterday I read some on performance tuning for emulator programming. I realized that I did at least one thing in a not optimal way. The N and Z flags, telling if the last operation resulted in a negative or zero result, should be handled lazy. My opcodes had macros calculating those flags for all instructions where it was applicable. That means that I called "Z = !!result" and "N = !!(result &amp;amp; 0x80)" a lot of times. Those flags are only read through branch instructions and used in a few other cases. Now the flags internally contain the value of the latest operation that can affect them. Then, when needed, I decode them as shown above.&lt;/p&gt;&lt;p&gt;I need to refactor some of the memory decoding handling. It has shown out to not be optimal when flag handling comes in count. I still need to add handling of the C and V flag, but after reading some on it it should be no big problem. Other things yet to fix is decimal mode. The 6502 can be set in a decimal mode where arithmetic operations go by base 10 instead of 16. &lt;/p&gt;&lt;p&gt;Finally a nice Oric 1 motherboard:&lt;/p&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_x2_pGkLOu0g/SbexcfKXPAI/AAAAAAAAADY/-xN8jXHCkyE/s1600-h/board3.jpg"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 266px;" src="http://2.bp.blogspot.com/_x2_pGkLOu0g/SbexcfKXPAI/AAAAAAAAADY/-xN8jXHCkyE/s400/board3.jpg" border="0" alt="" id="BLOGGER_PHOTO_ID_5311909388466207746" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-8394117541014438461?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/8394117541014438461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/yesterday-i-read-some-on-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/8394117541014438461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/8394117541014438461'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/yesterday-i-read-some-on-performance.html' title='Waving flags'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_x2_pGkLOu0g/SbexcfKXPAI/AAAAAAAAADY/-xN8jXHCkyE/s72-c/board3.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-2536281508369382902</id><published>2009-03-10T01:10:00.003+01:00</published><updated>2009-03-10T01:39:50.999+01:00</updated><title type='text'>Interrupts!</title><content type='html'>Time to quit for the night. I now have interrupts working as expected. The following small program runs fine:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;.ORG $1000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   ; initial IRQ/BRK interrupt vector to handler 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;LDA #$00&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;  STA $FFFE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;LDA #$04&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;STA $FFFF&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;  ; Nestled loop, 16*16&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;LDY #$10&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;LDX #$10&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;DEX&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;BNE #-3&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;BRK&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt;NOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;  DEY&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;BNE #-10&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;  ; Set interrupt vector to handler 2&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;LDA #$00&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;STA $FFFE&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;LDA #$05&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;STA $FFFF&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;BRK&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;.ORG $0400&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;; interrupt handler 1&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;NOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;NOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;NOP&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   RTI&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;.ORG $0500&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;  ; interrupt handler 2 - loop forever&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;&lt;/span&gt;&lt;span style="font-family:courier new;"&gt;   &lt;/span&gt;&lt;span style="font-family:courier new;"&gt;JMP $0500&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;I really need an assembler for my small programs. It is pretty painful to assembler them by hand. I also need to add more testing of my opcodes. Guess this might be the time for me to learn unit testing.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-2536281508369382902?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/2536281508369382902/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/interrupts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/2536281508369382902'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/2536281508369382902'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/interrupts.html' title='Interrupts!'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-1651620820556698763</id><published>2009-03-09T22:08:00.007+01:00</published><updated>2009-03-09T22:24:15.273+01:00</updated><title type='text'>Macros</title><content type='html'>Good progression this far! All the op-codes are now implemented. I have written more C macros than I ever thought I would do, but with 151 op codes with similar contents it really helps! I still need to go through them all to make sure they act correctly on flags, but I am able to run more and more advanced programs. It was very nice to see a nestled loop with software BRK-interrupts to work properly!&lt;br /&gt;&lt;br /&gt;Some things still puzzle me. Why should the JSR instruction store only PC+2 (JSR uses 3 bytes) on stack and RTS add that one byte again? Especially since interrupts store the correct address to next instruction, so that RTI can directly read it to PC. If someone reads this and knows, please tell!&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_x2_pGkLOu0g/SbWISDWxugI/AAAAAAAAADQ/66RoTvW85eo/s1600-h/apple2.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 336px;" src="http://1.bp.blogspot.com/_x2_pGkLOu0g/SbWISDWxugI/AAAAAAAAADQ/66RoTvW85eo/s400/apple2.png" alt="" id="BLOGGER_PHOTO_ID_5311301179273230850" border="0" /&gt;&lt;/a&gt;&lt;center&gt;Another 6502 based beauty, the Apple II.&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-1651620820556698763?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/1651620820556698763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/macros.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/1651620820556698763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/1651620820556698763'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/macros.html' title='Macros'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_x2_pGkLOu0g/SbWISDWxugI/AAAAAAAAADQ/66RoTvW85eo/s72-c/apple2.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-4438849378674043751</id><published>2009-03-09T00:11:00.002+01:00</published><updated>2009-03-09T00:20:32.248+01:00</updated><title type='text'>Instructions</title><content type='html'>&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;Some&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;days&lt;/span&gt; I &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;started&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;my&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;work&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;on&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;this&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;project.&lt;/span&gt; I &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;will&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;write&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;it in C++&lt;/span&gt; under Linux, &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;my&lt;/span&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_12"&gt;favo&lt;/span&gt;rite platform. I began trying to write it in KDevelop, the integrated development environment used by the KDE project. But after some hours I realized that I missed my Emacs editor so much that I switched to my normal setup with Emacs and make. I am pretty sure that KDevelop is a great environment, but I love Emacs and the productivity I get there.&lt;br /&gt;&lt;br /&gt;As a first thing I created classes for a MOS6502 processor and for Memory. I then copies a list of opcodes from a 6502 FAQ and created defines for each opcode mapped to the hexcode, so I can use that instead of hexcodes in my emulator. I then began the big work to implement the opcodes. I have now implemented LDA, LDX, LDY, STA, STX, STY and ADC with all the available addressing modes. I have also implemented some parts of the Memory class. Together with registers A, X and Y as well as program counter I managed to run a small assembler program today. The first program running in my emulator ever was:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; LDA #80&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; STA $1000&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family: courier new;"&gt; BRK&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-4438849378674043751?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/4438849378674043751/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/instructions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/4438849378674043751'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/4438849378674043751'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/instructions.html' title='Instructions'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-574530735080888819.post-572772513535195060</id><published>2009-03-09T00:00:00.000+01:00</published><updated>2009-03-09T00:09:42.900+01:00</updated><title type='text'>Starting up</title><content type='html'>A week ago I got a strange urge. I had cleaned up some in my computer collection room and when I was looking at some of my computers I realized that it probably would be very fun to write a computer emulator from scratch. This blog will all be about that.&lt;br /&gt;&lt;br /&gt;My first computer, which I got when I was about 8 years old, was an Oric 1. It is a small computer from the company &lt;a href="http://en.wikipedia.org/wiki/Tangerine_Computer_Systems"&gt;Tangerine Computer Systems&lt;/a&gt;. What computer could be a better target for an emulator than my first computer? The goal with this project is to once again play Scuba Diver and Hunchback, like I did 25 years ago. I know that there already are several emulators for this machine, for example Euphoric, but that doesn't matter. I want to do this all for the joy of doing it!&lt;br /&gt;&lt;br /&gt;In this blog I will summarize what I learn on the road. I will write about ideas, problems, solutions and tricks that I find. I hope that it might be of some value for other people that get the strange idea that it would be fun to write an emulator.&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_x2_pGkLOu0g/SbRP9T-gzbI/AAAAAAAAACw/IEhm3ERgj88/s1600-h/Oric1.jpg"&gt;&lt;img style="cursor: pointer; width: 400px; height: 241px;" src="http://4.bp.blogspot.com/_x2_pGkLOu0g/SbRP9T-gzbI/AAAAAAAAACw/IEhm3ERgj88/s400/Oric1.jpg" alt="" id="BLOGGER_PHOTO_ID_5310957775329742258" border="0" /&gt;&lt;/a&gt;&lt;/center&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/574530735080888819-572772513535195060?l=6502-emulator.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://6502-emulator.blogspot.com/feeds/572772513535195060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/starting-up.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/572772513535195060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/574530735080888819/posts/default/572772513535195060'/><link rel='alternate' type='text/html' href='http://6502-emulator.blogspot.com/2009/03/starting-up.html' title='Starting up'/><author><name>Anders Karlsson</name><uri>http://www.blogger.com/profile/06921144185321389878</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_x2_pGkLOu0g/SbRP9T-gzbI/AAAAAAAAACw/IEhm3ERgj88/s72-c/Oric1.jpg' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
