Skip to content

Instantly share code, notes, and snippets.

@swenson
Created April 25, 2015 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swenson/8a3c9028bcc4e8be46b5 to your computer and use it in GitHub Desktop.
Save swenson/8a3c9028bcc4e8be46b5 to your computer and use it in GitHub Desktop.
A 6502 disassembler and debugger (written as part of a NES emulator)
do_a_trap
mov esi, [trap]
test esi, 0x10000
jnz normal_trap
test esi, 0x20000
jnz register_trap
jmp near return_no_cigar
normal_trap
cmp si, [_PC]
jnz near return_no_cigar
mov [trap], dword 0x0
mov [debug], dword 0xFFFFFFFF
jmp do_normal_trace
register_trap
shr esi, 24
and esi, 0x5F
cmp si, 'A'
jz near register_A_trap
cmp si, 'X'
jz near register_X_trap
cmp si, 'Y'
jz near register_Y_trap
jmp near return_no_cigar
register_A_trap
mov eax, [_A]
cmp al, [trap]
jnz near return_no_cigar
mov [trap], dword 0
mov [debug], dword 0xFFFFFFFF
jmp do_normal_trace
register_X_trap
mov eax, [_X]
cmp al, [trap]
jnz near return_no_cigar
mov [trap], dword 0
mov [debug], dword 0xFFFFFFFF
jmp do_normal_trace
register_Y_trap
mov eax, [_Y]
cmp al, [trap]
jnz near return_no_cigar
mov [trap], dword 0
mov [debug], dword 0xFFFFFFFF
jmp do_normal_trace
debug_next
startop 1
clean_debug
mov eax, [trap]
test eax, 0xFFFF0000
jnz near do_a_trap
do_normal_trace
test [debug], byte 0xFF
jz near return_no_cigar
call do_scrolling_mirroringQ
movq mm7, [color_black]
mov ecx, 800
mov edi, 0xA0000+231*256
moqedimm8
movq [edi], mm7
add edi, 8
dec ecx
jnz moqedimm8
%include "debugadd.asm"
skip_addr
%ifdef new_kb_handler
cmp [key_pressed], dword 0
jz skip_addr
cmp [key_set+30], byte 1 ; a
;jz near do_A_trap
cmp [key_set+32], byte 1 ; y
;jz near do_Y_trap
cmp [key_set+45], byte 1 ; x
;jz near do_X_trap
cmp [key_set+47], byte 1 ; v
jz near do_int_debug
cmp [key_set+23], byte 1 ; i
jz near trap_int
cmp [key_set+20], byte 1 ; t
;jz set_up_trap
cmp [key_set+16], byte 1 ; q
jz near mem_end
mov ebx, 0xFFFFFFFF
cmp [key_set+1], byte 1 ; ESC
cmovz ebx, [byte_0]
mov [debug], ebx
wait_till_thru
cmp [key_pressed], dword 0
jnz wait_till_thru
%else
xor eax, eax
int 0x16
mov ecx, -1
cmp ah, 1
cmovz ecx, [byte_0]
mov [debug], ecx
cmp ah, 30 ; a
jz near do_A_trap
cmp ah, 21 ; y
jz near do_Y_trap
cmp ah, 45 ; x
jz near do_X_trap
cmp ah, 47 ; v
jz near do_int_debug
cmp ah, 23 ; i
jz near trap_int
cmp ah, 20 ; t
jz set_up_trap
cmp ah, 16 ; q
jz near mem_end
%endif
continue_keyb
jmp return_no_cigar
return_no_cigar
endop 1
set_up_trap
movq mm7, [color_black]
mov ecx, 4
mov edx, 8
mov edi, 0xA0000+31744+112
moq7
movq [edi], mm7
add edi, 8
dec ecx
jnz moq7
add edi, 224
mov ecx, 4
dec edx
jnz moq7
mov ebx, 124
mov edx, 112
mov esi, trap_buffer
go_at_it_some_more
xor eax, eax
int 0x16
cmp ah, 1
jz near clean_debug
cmp ah, 14
jz near take_back
cmp ah, 28
jz near clean_it_up
push esi
mov esi, 0xA0000+31744
movq [esi+edx], mm7
movq [esi+edx+256], mm7
movq [esi+edx+512], mm7
movq [esi+edx+768], mm7
movq [esi+edx+1024], mm7
movq [esi+edx+1280], mm7
movq [esi+edx+1536], mm7
movq [esi+edx+1792], mm7
pop esi
push eax
push edx
push dword 124
push dword 241
call print_char
add esp, 16
mov [esi], al
cmp edx, 136
jz near go_at_it_some_more
inc esi
add edx, 8
untake_care
jmp go_at_it_some_more
take_care_of_this
sub edx, 8
dec esi
jmp untake_care
take_back
cmp esi, trap_buffer
jz near clean_debug
dec esi
mov [esi], dword 0
sub edx, 8
jmp near go_at_it_some_more
clean_it_up
mov eax, [trap_buffer]
mov ebx, [trap_buffer+1]
mov ecx, [trap_buffer+2]
mov edx, [trap_buffer+3]
and eax, 0xFF
and ebx, 0xFF
and ecx, 0xFF
and edx, 0xFF
push eax
call convert_hex_to_normal
pop eax
push ebx
call convert_hex_to_normal
pop ebx
push ecx
call convert_hex_to_normal
pop ecx
push edx
call convert_hex_to_normal
pop edx
shl eax, 12
shl ebx, 8
shl ecx, 4
or edx, ecx
or ebx, eax
or edx, ebx
and edx, 0xFFFF
or edx, 0x10000
mov [trap], edx
mov [debug], dword 0
call display_screen
jmp return_no_cigar
do_int_debug
mov [clicks], dword 115
mov [framelines], dword 1
call display_screen
jmp return_no_cigar
trap_int
mov [debug_int], dword 0xFFFFFFFF
mov [debug], dword 0x0
call display_screen
jmp return_no_cigar
do_A_trap
mov edx, 'A'
jmp do_register_trap_number
do_X_trap
mov edx, 'X'
jmp do_register_trap_number
do_Y_trap
mov edx, 'Y'
jmp do_register_trap_number
do_register_trap_number
movq mm7, [color_black]
mov ecx, 2
mov eax, 8
mov edi, 0xA0000+31744+120
moq72
movq [edi], mm7
add edi, 8
dec ecx
jnz moq72
add edi, 240
mov ecx, 2
dec eax
jnz moq72
mov esi, trap_buffer
mov ecx, 120
reg_go_at_it
xor eax, eax
int 0x16
cmp ah, 1 ; esc
jz near clean_debug
cmp ah, 14 ; backspace
jz near take_back_reg
cmp ah, 28 ; enter
jz near clean_it_up_reg
push esi
mov esi, 0xA0000+31744
movq [esi+ecx], mm7
movq [esi+ecx+256], mm7
movq [esi+ecx+512], mm7
movq [esi+ecx+768], mm7
movq [esi+ecx+1024], mm7
movq [esi+ecx+1280], mm7
movq [esi+ecx+1536], mm7
movq [esi+ecx+1792], mm7
pop esi
push eax
push ecx
push dword 124
push dword 241
call print_char
add esp, 16
mov [esi], al
cmp ecx, 128
jz near reg_go_at_it
inc esi
add ecx, 8
jmp reg_go_at_it
take_back_reg
mov [esi], byte 0
cmp esi, trap_buffer
jz near reg_go_at_it
dec esi
mov [esi], byte 0
sub ecx, 8
jmp near reg_go_at_it
clean_it_up_reg
mov eax, [trap_buffer]
mov ebx, [trap_buffer+1]
and eax, 0xFF
and ebx, 0xFF
push eax
call convert_hex_to_normal
pop eax
push ebx
call convert_hex_to_normal
pop ebx
shl eax, 4
or eax, ebx
and eax, 0xFF
or eax, 0x20000
mov [trap], eax
mov [trap+3], dl
mov [debug], dword 0
call display_screen
jmp return_no_cigar
%ifdef new_kb_handler
%else
putflagsp
%endif
xor ecx, ecx
mov edi, 0xE900+0xA0000-256*9
movq mm7, [byte_0]
movqllop
movq [edi], mm7
movq [edi+0x100], mm7
movq [edi+0x200], mm7
movq [edi+0x300], mm7
movq [edi+0x400], mm7
movq [edi+0x500], mm7
movq [edi+0x600], mm7
movq [edi+0x700], mm7
paddb mm7, [qword_01010101]
add edi, 8
inc ecx
cmp ecx, 32
jnz movqllop
mov eax, [vblank_cycles]
mov ebx, [vblank_cycles]
mov ecx, eax
mov edx, ebx
and eax, 0xF
shr ebx, 4
shr ecx, 8
shr edx, 12
and ebx, 0xF
and ecx, 0xF
and edx, 0xF
add eax, hex_numbers
add ecx, hex_numbers
add edx, hex_numbers
add ebx, hex_numbers
push dword [eax]
push dword [ebx]
push dword [ecx]
push dword [edx]
push dword '$'
push dword ' '
push dword ':'
push dword 't'
push dword 'n'
push dword 'I'
push dword ' '
mov eax, [framelines]
mov ebx, [framelines]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword [ebx]
push dword [eax]
push dword '$'
push dword ' '
push dword ','
mov eax, [clicks]
mov ebx, [clicks]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword [ebx]
push dword [eax]
push dword '$'
push dword ' '
push dword ':'
push dword 'e'
push dword 'n'
push dword 'i'
push dword 'l'
push dword 'n'
push dword 'a'
push dword 'c'
push dword 'S'
push dword 0
push dword 232
push dword 241
call print_char
add esp, 16
push dword 8
push dword 232
push dword 241
call print_char
add esp, 16
push dword 16
push dword 232
push dword 241
call print_char
add esp, 16
push dword 24
push dword 232
push dword 241
call print_char
add esp, 16
push dword 32
push dword 232
push dword 241
call print_char
add esp, 16
push dword 40
push dword 232
push dword 241
call print_char
add esp, 16
push dword 48
push dword 232
push dword 241
call print_char
add esp, 16
push dword 56
push dword 232
push dword 241
call print_char
add esp, 16
push dword 64
push dword 232
push dword 241
call print_char
add esp, 16
push dword 72
push dword 232
push dword 241
call print_char
add esp, 16
push dword 80
push dword 232
push dword 241
call print_char
add esp, 16
push dword 88
push dword 232
push dword 241
call print_char
add esp, 16
push dword 96
push dword 232
push dword 241
call print_char
add esp, 16
push dword 104
push dword 232
push dword 241
call print_char
add esp, 16
push dword 112
push dword 232
push dword 241
call print_char
add esp, 16
push dword 120
push dword 232
push dword 241
call print_char
add esp, 16
push dword 128
push dword 232
push dword 241
call print_char
add esp, 16
push dword 136
push dword 232
push dword 241
call print_char
add esp, 16
push dword 144
push dword 232
push dword 241
call print_char
add esp, 16
push dword 152
push dword 232
push dword 241
call print_char
add esp, 16
push dword 160
push dword 232
push dword 241
call print_char
add esp, 16
push dword 168
push dword 232
push dword 241
call print_char
add esp, 16
push dword 176
push dword 232
push dword 241
call print_char
add esp, 16
push dword 184
push dword 232
push dword 241
call print_char
add esp, 16
push dword 192
push dword 232
push dword 241
call print_char
add esp, 16
push dword 200
push dword 232
push dword 241
call print_char
add esp, 16
push dword 208
push dword 232
push dword 241
call print_char
add esp, 16
push dword 216
push dword 232
push dword 241
call print_char
add esp, 16
push dword 224
push dword 232
push dword 241
call print_char
add esp, 16
mov eax, [_P]
mov ebx, [_P]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword ' '
push dword [ebx]
push dword [eax]
push dword '$'
push dword ' '
push dword ':'
push dword 'P'
mov eax, [_Y]
mov ebx, [_Y]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword ' '
push dword [ebx]
push dword [eax]
push dword '$'
push dword ' '
push dword ':'
push dword 'Y'
mov eax, [_X]
mov ebx, [_X]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword ' '
push dword [ebx]
push dword [eax]
push dword '$'
push dword ' '
push dword ':'
push dword 'X'
mov eax, [_A]
mov ebx, [_A]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword ' '
push dword [ebx]
push dword [eax]
push dword '$'
push dword ' '
push dword ':'
push dword 'A'
push dword 0
push dword 240
push dword 241
call print_char
add esp, 16
push dword 8
push dword 240
push dword 241
call print_char
add esp, 16
push dword 16
push dword 240
push dword 241
call print_char
add esp, 16
push dword 24
push dword 240
push dword 241
call print_char
add esp, 16
push dword 32
push dword 240
push dword 241
call print_char
add esp, 16
push dword 40
push dword 240
push dword 241
call print_char
add esp, 16
push dword 48
push dword 240
push dword 241
call print_char
add esp, 16
push dword 56
push dword 240
push dword 241
call print_char
add esp, 16
push dword 64
push dword 240
push dword 241
call print_char
add esp, 16
push dword 72
push dword 240
push dword 241
call print_char
add esp, 16
push dword 80
push dword 240
push dword 241
call print_char
add esp, 16
push dword 88
push dword 240
push dword 241
call print_char
add esp, 16
push dword 96
push dword 240
push dword 241
call print_char
add esp, 16
push dword 104
push dword 240
push dword 241
call print_char
add esp, 16
push dword 112
push dword 240
push dword 241
call print_char
add esp, 16
push dword 120
push dword 240
push dword 241
call print_char
add esp, 16
push dword 128
push dword 240
push dword 241
call print_char
add esp, 16
push dword 136
push dword 240
push dword 241
call print_char
add esp, 16
push dword 144
push dword 240
push dword 241
call print_char
add esp, 16
push dword 152
push dword 240
push dword 241
call print_char
add esp, 16
push dword 160
push dword 240
push dword 241
call print_char
add esp, 16
push dword 168
push dword 240
push dword 241
call print_char
add esp, 16
push dword 176
push dword 240
push dword 241
call print_char
add esp, 16
push dword 184
push dword 240
push dword 241
call print_char
add esp, 16
push dword 192
push dword 240
push dword 241
call print_char
add esp, 16
push dword 200
push dword 240
push dword 241
call print_char
add esp, 16
push dword 208
push dword 240
push dword 241
call print_char
add esp, 16
push dword 216
push dword 240
push dword 241
call print_char
add esp, 16
push dword '['
push dword 0
push dword 248
push dword 241
call print_char
add esp, 16
push dword ' '
push dword ':'
push dword ']'
xor ecx, ecx
rep_pc_out
mov ebx, [_PC]
mov edx, ecx
shl ecx, 2
shr ebx, cl
mov ecx, edx
and ebx, 0xF
add ebx, '0'
cmp ebx, '9'
jna just_dontadd
add ebx, 'A'-'0'-10
just_dontadd
push ebx
inc ecx
cmp ecx, 4
jnz rep_pc_out
push dword 8
push dword 248
push dword 241
call print_char
add esp, 16
push dword 16
push dword 248
push dword 241
call print_char
add esp, 16
push dword 24
push dword 248
push dword 241
call print_char
add esp, 16
push dword 32
push dword 248
push dword 241
call print_char
add esp, 16
push dword 40
push dword 248
push dword 241
call print_char
add esp, 16
push dword 48
push dword 248
push dword 241
call print_char
add esp, 16
push dword 52
push dword 248
push dword 241
call print_char
add esp, 16
mov esi, [_PC]
xor ebx, ebx
mov edi, [_pcmem]
mov bl, [esi+edi]
mov edx, ebx
shl ebx, 2
add ebx, table_mnm
mov eax, [ebx]
rol eax, 8
push eax
rol eax, 8
push eax
rol eax, 8
push eax
rol eax, 8
push eax
push dword 60
push dword 248
push dword 241
call print_char
add esp, 16
push dword 68
push dword 248
push dword 241
call print_char
add esp, 16
push dword 76
push dword 248
push dword 241
call print_char
add esp, 16
push dword 84
push dword 248
push dword 241
call print_char
add esp, 16
shl edx, 2
add edx, table_addr
call [edx]
jmp skip_addr
_XX
retn
_AU
push dword 'A'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
retn
_IM
mov ebx, [esi+edi+1]
mov ecx, [esi+edi+1]
and ebx, 0xF
shr ecx, 4
and ecx, 0xF
add ebx, hex_numbers
add ecx, hex_numbers
push dword [ebx]
push dword [ecx]
push dword '$'
push dword '#'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
retn
_ZP
mov ebx, [esi+edi+1]
mov ecx, [esi+edi+1]
and ebx, 0xF
shr ecx, 4
and ecx, 0xF
add ebx, hex_numbers
add ecx, hex_numbers
push dword [ebx]
push dword [ecx]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
retn
_ZX
mov ebx, [esi+edi+1]
mov ecx, [esi+edi+1]
and ebx, 0xF
shr ecx, 4
and ecx, 0xF
add ecx, hex_numbers
add ebx, hex_numbers
push dword 'X'
push dword ','
push dword [ebx]
push dword [ecx]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
retn
_ZY
mov ebx, [esi+edi+1]
mov ecx, [esi+edi+1]
and ebx, 0xF
shr ecx, 4
and ecx, 0xF
add ebx, hex_numbers
add ecx, hex_numbers
push dword 'Y'
push dword ','
push dword [ebx]
push dword [ecx]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
retn
_AS
mov eax, [esi+edi+1]
mov ecx, [esi+edi+2]
mov ebx, eax
mov edx, ecx
shr eax, 4
shr ecx, 4
and ebx, 0xF
and edx, 0xF
and eax, 0xF
and ecx, 0xF ; ecx:edx:eax:ebx
add eax, hex_numbers
add ebx, hex_numbers
add ecx, hex_numbers
add edx, hex_numbers
push dword [ebx]
push dword [eax]
push dword [edx]
push dword [ecx]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
retn
_AX
mov eax, [esi+edi+1]
mov ecx, [esi+edi+2]
mov ebx, eax
mov edx, ecx
shr eax, 4
shr ecx, 4
and ebx, 0xF
and edx, 0xF
and eax, 0xF
and ecx, 0xF ; ecx:edx:eax:ebx
add eax, hex_numbers
add ebx, hex_numbers
add ecx, hex_numbers
add edx, hex_numbers
push dword 'X'
push dword ','
push dword [ebx]
push dword [eax]
push dword [edx]
push dword [ecx]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
push dword 132
push dword 248
push dword 241
call print_char
add esp, 16
push dword 140
push dword 248
push dword 241
call print_char
add esp, 16
retn
_AY
mov eax, [esi+edi+1]
mov ecx, [esi+edi+2]
mov ebx, eax
mov edx, ecx
shr eax, 4
shr ecx, 4
and ebx, 0xF
and edx, 0xF
and eax, 0xF
and ecx, 0xF ; ecx:edx:eax:ebx
add eax, hex_numbers
add ebx, hex_numbers
add ecx, hex_numbers
add edx, hex_numbers
push dword 'Y'
push dword ','
push dword [ebx]
push dword [eax]
push dword [edx]
push dword [ecx]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
push dword 132
push dword 248
push dword 241
call print_char
add esp, 16
push dword 140
push dword 248
push dword 241
call print_char
add esp, 16
retn
_IX
mov eax, [esi+edi+1]
mov ebx, [esi+edi+1]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword ')'
push dword 'X'
push dword ','
push dword [ebx]
push dword [eax]
push dword '$'
push dword '('
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
push dword 132
push dword 248
push dword 241
call print_char
add esp, 16
push dword 140
push dword 248
push dword 241
call print_char
add esp, 16
retn
_IY
mov eax, [esi+edi+1]
mov ebx, [esi+edi+1]
shr eax, 4
and ebx, 0xF
and eax, 0xF
add ebx, hex_numbers
add eax, hex_numbers
push dword 'Y'
push dword ','
push dword ')'
push dword [ebx]
push dword [eax]
push dword '$'
push dword '('
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
push dword 132
push dword 248
push dword 241
call print_char
add esp, 16
push dword 140
push dword 248
push dword 241
call print_char
add esp, 16
retn
_IA
mov eax, [esi+edi+1]
mov ecx, [esi+edi+2]
mov ebx, eax
mov edx, ecx
shr eax, 4
shr ecx, 4
and ebx, 0xF
and edx, 0xF
and eax, 0xF
and ecx, 0xF
add ebx, hex_numbers
add edx, hex_numbers
add ecx, hex_numbers
add eax, hex_numbers
push dword ')'
push dword [ebx]
push dword [eax]
push dword [edx]
push dword [ecx]
push dword '$'
push dword '('
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
push dword 132
push dword 248
push dword 241
call print_char
add esp, 16
push dword 140
push dword 248
push dword 241
call print_char
add esp, 16
retn
_RE
mov ebx, [esi+edi+1]
and ebx, 0xFF
mov ecx, esi
add esi, 2
test ebx, 0x80
jnz near negate_RE
add esi, ebx
mov eax, esi
mov ebx, esi
mov ecx, esi
shr eax, 12
shr ebx, 8
shr ecx, 4
and esi, 0xF
and eax, 0xF
and ebx, 0xF
and ecx, 0xF
add esi, hex_numbers
add eax, hex_numbers
add ebx, hex_numbers
add ecx, hex_numbers
push dword [esi]
push dword [ecx]
push dword [ebx]
push dword [eax]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
retn
negate_RE
neg bl
sub esi, ebx
mov eax, esi
mov ebx, esi
mov ecx, esi
shr eax, 12
shr ebx, 8
shr ecx, 4
and esi, 0xF
and eax, 0xF
and ebx, 0xF
and ecx, 0xF
add esi, hex_numbers
add eax, hex_numbers
add ebx, hex_numbers
add ecx, hex_numbers
push dword [esi]
push dword [ecx]
push dword [ebx]
push dword [eax]
push dword '$'
push dword 92
push dword 248
push dword 241
call print_char
add esp, 16
push dword 100
push dword 248
push dword 241
call print_char
add esp, 16
push dword 108
push dword 248
push dword 241
call print_char
add esp, 16
push dword 116
push dword 248
push dword 241
call print_char
add esp, 16
push dword 124
push dword 248
push dword 241
call print_char
add esp, 16
retn
; This is a full Opcode Table
table_of_codes
;dd _00,_01,_02,_03,_04,_05,_06,_07,_08,_09,_0A,_0B,_0C,_0D,_0E,_0F
;dd _10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_1A,_1B,_1C,_1D,_1E,_1F
;dd _20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_2A,_2B,_2C,_2D,_2E,_2F
;dd _30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_3A,_3B,_3C,_3D,_3E,_3F
;dd _40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_4A,_4B,_4C,_4D,_4E,_4F
;dd _50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_5A,_5B,_5C,_5D,_5E,_5F
;dd _60,_61,_62,_63,_64,_65,_66,_67,_68,_69,_6A,_6B,_6C,_6D,_6E,_6F
;dd _70,_71,_72,_73,_74,_75,_76,_77,_78,_79,_7A,_7B,_7C,_7D,_7E,_7F
;dd _80,_81,_82,_83,_84,_85,_86,_87,_88,_89,_8A,_8B,_8C,_8D,_8E,_8F
;dd _90,_91,_92,_93,_94,_95,_96,_97,_98,_99,_9A,_9B,_9C,_9D,_9E,_9F
;dd _A0,_A1,_A2,_A3,_A4,_A5,_A6,_A7,_A8,_A9,_AA,_AB,_AC,_AD,_AE,_AF
;dd _B0,_B1,_B2,_B3,_B4,_B5,_B6,_B7,_B8,_B9,_BA,_BB,_BC,_BD,_BE,_BF
;dd _C0,_C1,_C2,_C3,_C4,_C5,_C6,_C7,_C8,_C9,_CA,_CB,_CC,_CD,_CE,_CF
;dd _D0,_D1,_D2,_D3,_D4,_D5,_D6,_D7,_D8,_D9,_DA,_DB,_DC,_DD,_DE,_DF
;dd _E0,_E1,_E2,_E3,_E4,_E5,_E6,_E7,_E8,_E9,_EA,_EB,_EC,_ED,_EE,_EF
;dd _F0,_F1,_F2,_F3,_F4,_F5,_F6,_F7,_F8,_F9,_FA,_FB,_FC,_FD,_FE,_FF
; This is for the 6502
dd _00,_01,_IOP,_IOP,_IOP,_05,_06,_IOP,_08,_09,_0A,_IOP,_IOP,_0D,_0E,_IOP
dd _10,_11,_IOP,_IOP,_IOP,_15,_16,_IOP,_18,_19,_IOP,_IOP,_IOP,_1D,_1E,_IOP
dd _20,_21,_IOP,_IOP,_24,_25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,_11,_12,_IOP,_14,_15,_16,_IOP,_18,_19,_1A,_IOP,_1C,_1D,_1E,_IOP
;dd _20,_21,_IOP,_IOP,_24,_25,_26,_IOP,_28,_29,_2A,_IOP,_2C,_2D,_2E,_IOP
;dd _30,_31,_32,_IOP,_34,_35,_36,_IOP,_38,_39,_3A,_IOP,_3C,_3D,_3E,_IOP
;dd _40,_41,_IOP,_IOP,_IOP,_45,_46,_IOP,_48,_49,_4A,_IOP,_4C,_4D,_4E,_IOP
;dd _50,_51,_52,_IOP,_IOP,_55,_56,_IOP,_58,_59,_5A,_IOP,_IOP,_5D,_5E,_IOP
;dd _60,_61,_IOP,_IOP,_64,_65,_66,_IOP,_68,_69,_6A,_IOP,_6C,_6D,_6E,_IOP
;dd _70,_71,_72,_IOP,_74,_75,_76,_IOP,_78,_79,_7A,_IOP,_7C,_7D,_7E,_IOP
;dd _80,_81,_IOP,_IOP,_84,_85,_86,_IOP,_88,_89,_8A,_IOP,_8C,_8D,_8E,_IOP
;dd _90,_91,_92,_IOP,_94,_95,_96,_IOP,_98,_99,_9A,_IOP,_9C,_9D,_9E,_IOP
;dd _A0,_A1,_A2,_IOP,_A4,_A5,_A6,_IOP,_A8,_A9,_AA,_IOP,_AC,_AD,_AE,_IOP
;dd _B0,_B1,_B2,_IOP,_B4,_B5,_B6,_IOP,_B8,_B9,_BA,_IOP,_BC,_BD,_BE,_IOP
;dd _C0,_C1,_IOP,_IOP,_C4,_C5,_C6,_IOP,_C8,_C9,_CA,_IOP,_CC,_CD,_CE,_IOP
;dd _D0,_D1,_D2,_IOP,_IOP,_D5,_D6,_IOP,_D8,_D9,_DA,_IOP,_IOP,_DD,_DE,_IOP
;dd _E0,_E1,_IOP,_IOP,_E4,_E5,_E6,_IOP,_E8,_E9,_EA,_IOP,_EC,_ED,_EE,_IOP
;dd _F0,_F1,_F2,_IOP,_IOP,_F5,_F6,_IOP,_F8,_F9,_FA,_IOP,_IOP,_FD,_FE,_IOP
; Timing in clocks for each instruction
table_of_clicks
db 7,6,2,8,3,3,5,5,3,2,2,2,4,4,6,6
db 2,5,2,8,4,4,6,6,2,4,2,7,5,5,7,7
db 6,6,2,8,3,3,5,5,4,2,2,2,4,4,6,6
db 2,5,2,8,4,4,6,6,2,4,2,7,5,5,7,7
db 6,6,2,8,3,3,5,5,3,2,2,2,3,4,6,6
db 2,5,2,8,4,4,6,6,2,4,2,7,5,5,7,7
db 6,6,2,8,3,3,5,5,4,2,2,2,5,4,6,6
db 2,5,2,8,4,4,6,6,2,4,2,7,5,5,7,7 ; borrowed from Marat's M6502 code
db 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4
db 2,6,2,6,4,4,4,4,2,5,2,5,5,5,5,5
db 2,6,2,6,3,3,3,3,2,2,2,2,4,4,4,4
db 2,5,2,5,4,4,4,4,2,4,2,5,4,4,4,4
db 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6
db 2,5,2,8,4,4,6,6,2,4,2,7,5,5,7,7
db 2,6,2,8,3,3,5,5,2,2,2,2,4,4,6,6
db 2,5,2,8,4,4,6,6,2,4,2,7,5,5,7,7
_adc EQU "ADC "
_and EQU "AND "
_asl EQU "ASL "
_bcc EQU "BCC "
_bcs EQU "BCS "
_beq EQU "BEQ "
_bit EQU "BIT "
_bmi EQU "BMI "
_bne EQU "BNE "
_bpl EQU "BPL "
_brk EQU "BRK "
_bvc EQU "BVC "
_bvs EQU "BVS "
_clc EQU "CLC "
_cld EQU "CLD "
_cli EQU "CLI "
_clv EQU "CLV "
_cmp EQU "CMP "
_cpx EQU "CPX "
_cpy EQU "CPY "
_dec EQU "DEC "
_dex EQU "DEX "
_dey EQU "DEY "
_eor EQU "EOR "
_inc EQU "INC "
_inx EQU "INX "
_iny EQU "INY "
_jmp EQU "JMP "
_jsr EQU "JSR "
_lda EQU "LDA "
_ldx EQU "LDX "
_ldy EQU "LDY "
_lsr EQU "LSR "
_nop EQU "NOP "
_ora EQU "ORA "
_pha EQU "PHA "
_php EQU "PHP "
_phx EQU "PHX "
_phy EQU "PHY "
_pla EQU "PLA "
_plp EQU "PLP "
_plx EQU "PLX "
_ply EQU "PLY "
_rol EQU "ROL "
_ror EQU "ROR "
_rti EQU "RTI "
_rts EQU "RTS "
_sbc EQU "SBC "
_sec EQU "SEC "
_sed EQU "SED "
_sei EQU "SEI "
_sta EQU "STA "
_stx EQU "STX "
_sty EQU "STY "
_tax EQU "TAX "
_tay EQU "TAY "
_tsx EQU "TSX "
_txa EQU "TXA "
_txs EQU "TXS "
_tya EQU "TYA "
_que EQU "??? "
; Mnemonics for each intstruction
table_mnm
dd _brk,_ora,_que,_que,_que,_ora,_asl,_que,_php,_ora,_asl,_que,_que,_ora,_asl,_que
dd _bpl,_ora,_que,_que,_que,_ora,_asl,_que,_clc,_ora,_que,_que,_que,_ora,_asl,_que
dd _jsr,_and,_que,_que,_bit,_and,_rol,_que,_plp,_and,_rol,_que,_bit,_and,_rol,_que
dd _bmi,_and,_que,_que,_que,_and,_rol,_que,_sec,_and,_que,_que,_que,_and,_rol,_que
dd _rti,_eor,_que,_que,_que,_eor,_lsr,_que,_pha,_eor,_lsr,_que,_jmp,_eor,_lsr,_que
dd _bvc,_eor,_que,_que,_que,_eor,_lsr,_que,_cli,_eor,_que,_que,_que,_eor,_lsr,_que
dd _rts,_adc,_que,_que,_que,_adc,_ror,_que,_pla,_adc,_ror,_que,_jmp,_adc,_ror,_que
dd _bvs,_adc,_que,_que,_que,_adc,_ror,_que,_sei,_adc,_que,_que,_que,_adc,_ror,_que
dd _que,_sta,_que,_que,_sty,_sta,_stx,_que,_dey,_que,_txa,_que,_sty,_sta,_stx,_que
dd _bcc,_sta,_que,_que,_sty,_sta,_stx,_que,_tya,_sta,_txs,_que,_que,_sta,_que,_que
dd _ldy,_lda,_ldx,_que,_ldy,_lda,_ldx,_que,_tay,_lda,_tax,_que,_ldy,_lda,_ldx,_que
dd _bcs,_lda,_que,_que,_ldy,_lda,_ldx,_que,_clv,_lda,_tsx,_que,_ldy,_lda,_ldx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S,_AS,_XX
dd _RE,_IY,_XX,_XX,_ZX,_ZX,_ZY,_XX,_XX,_AY,_XX,_XX,_AX,_AX,_AY,_XX
dd _IM,_IX,_XX,_XX,_ZP,_ZP,_ZP,_XX,_XX,_IM,_XX,_XX,_AS,_AS,_AS,_XX
dd _RE,_IY,_XX,_XX,_XX,_ZX,_ZX,_XX,_XX,_AY,_XX,_XX,_XX,_AX,_AX,_XX
dd _IM,_IX,_XX,_XX,_ZP,_ZP,_ZP,_XX,_XX,_IM,_XX,_XX,_AS,_AS,_AS,_XX
dd _RE,_IY,_XX,_XX,_XX,_ZX,_ZX,_XX,_XX,_AY,_XX,_XX,_XX,_AX,_AX,_XX
; This is the table that contains the offsets for the register traps
table_registers
dd _2000,_2001,_2002,_2003,_2004,_2005,_2006,_2007
dd _4000,_4001,_4002,_4003,_4004,_4005,_4006,_4007,_4008,_4009,_400A,_400B
dd _400C,_400D,_400E,_400F,_4010,_4011,_4012,_4013,_4014,_4015,_4016,_4017
table_read_registers
dd _R2000,_R2001,_R2002,_R2003,_R2004,_R2005,_R2006,_R2007
dd _R4000,_R4001,_R4002,_R4003,_R4004,_R4005,_R4006,_R4007,_R4008,_R4009,_R400A,_R400B
dd _R400C,_R400D,_R400E,_R400F,_R4010,_R4011,_R4012,_R4013,_R4014,_R4015,_R4016,_R4017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment