implementation of indirect JMP's bug

This commit is contained in:
Thiago Auler 2017-12-01 08:52:50 -02:00 committed by GitHub
parent 6bb5014964
commit 7cd85b7cdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -389,9 +389,19 @@ void iny()
void jmp() void jmp()
{ {
// jump to new location (indirect) // jump to new location (indirect)
address = read_word(pc); // this jump instruction has a known bug where the MSB does not cross pages
address = read_word(address); // i.e. if the LSB is in address 0xC0FF, then the MSB will be in 0xC000
pc = address; db lsb, msb;
dw lsb_addr, msb_addr;
lsb_addr = read_word(pc);
lsb = read_byte(lsb_addr);
msb_addr = (lsb_addr + 1) & 0x00FF;
msb_addr = (lsb_addr & 0xFF00) | msb_addr;
msb = read_word(msb_addr);
pc = (msb << 8) | lsb;
} }
void jpa() void jpa()