First 6502 microcode

A project log for Isetta TTL computer

Retro computer built from TTL, with 6502 and Z80 instruction set. Includes video system.

roelhroelh 04/22/2023 at 10:160 Comments

A first version of the microcode was made. The microcode is generated with a Javascript program. The script can be downloaded from the file section. An effort was made to make the microcode as clear as possible, the output will be a list of microcode instructions with a good explanation, for all 151 opcodes of the original 6502. It lookes like this:

---- 0xC8 INY reg_y ----
001900 3A84B3 3A84B3 to_t <- inc(reg_y),upd_nz
001902 008301 008301 next
001904 11B403 11B403 reg_y <- acc_t

---- 0x69 ADC imm ----
000D20 D1AB80 D1AB80 to_dpl <- (pc++),irq_to_f
000D22 5D46F0 008301 F:[to_a <- adc(acc_a, dpl),upd_nzc] T:[next]
000D24 000401 5D46F0 F:[interrupt] T:[to_a <- adc(acc_a, dpl),upd_nzc]
000D26 110400 110400 int2

---- 0x65 ADC zp ----
000CA0 D1AB80 D1AB80 to_dpl <- (pc++),irq_to_f
000CA2 5DC5F0 008301 F:[to_a <- adc(acc_a, (0|dpl)),upd_nzc] T:[next]
000CA4 000401 5DC5F0 F:[interrupt] T:[to_a <- adc(acc_a, (0|dpl)),upd_nzc]
000CA6 110400 110400 int2

---- 0x75 ADC zpx ----
000EA0 D18B80 D18B80 to_t <- (pc++),irq_to_f
000EA2 1DA402 1DA402 to_dpl <- add(acc_t, reg_x)
---- end of ea calculation ---
000EA4 5DC5F0 008301 F:[to_a <- adc(acc_a, (0|dpl)),upd_nzc] T:[next]
000EA6 000401 5DC5F0 F:[interrupt] T:[to_a <- adc(acc_a, (0|dpl)),upd_nzc]
000EA8 110400 110400 int2

You can easily generate the full microcode:

Some remarks about the notation:

It is easy to count the number of cycles for each opcode. Just count the lines up to the first instruction that contains 'next', then add one cycle for the instruction after 'next'. So the shown 'ADC zp' opcode takes 3 cycles.

The operation of some instructions will probably still be unclear to you. In that case, check the microcode script that contains a lot of comments about the used instructions.

In the microcode generator, there is a central role for the function 'ins6( a, b, c, d, e, f )'. The name 'ins6' stands for 'instruction with 6 components'. The six components are:

The ins6 simply combines the control-wire values of its arguments, so it would not matter in which order the components are placed. But the comment-printing function 'pr_print' depends on the order of this components.

It is tempting to continue with writing the Z80 micro-instructions, but I will now first make a simulator to check if everything works as intended.