Skip to content

Commit f90507a

Browse files
committed
Add short note about BRK and PHP about reserved and break flags
Explicitly increment the PC for the junk BRK byte.
1 parent e0a3ed4 commit f90507a

File tree

6 files changed

+21
-9
lines changed

6 files changed

+21
-9
lines changed

bitey/cpu/instruction/brk.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,24 @@ def instruction_execute(self, cpu, memory, value=None, address=None):
3434
self.set_flags(cpu.flags, cpu.registers)
3535

3636
# super().execute(cpu, memory)
37+
3738
# Push the instruction after the next on the stack
39+
# The BRK instruction is two bytes long
40+
# The second byte is padding that can be thrown away
41+
#
42+
# But we explicitly increment the PC here to make it clear
43+
# what is happening
44+
cpu.registers["PC"].inc()
3845
pc = cpu.registers["PC"].get()
39-
cpu.stack_push_address(memory, pc + 1)
46+
47+
cpu.stack_push_address(memory, pc)
4048

4149
# save all the flags on the stack
4250
#
43-
# TODO: Describe the reason for the OR with 0b00110000 (the
44-
# Break and Expansion flags)
51+
# The behavior of the Break flag (B) and Expansion or Reserved
52+
# flag (E) is not fully specified in official documentation.
53+
# But Visual6502 shows it as being set and several external
54+
# tests assume that it is set, so we set it for PHP and BRK.
4555
#
4656
# https://github.com/Klaus2m5/6502_65C02_functional_tests/issues/13
4757
# http://forum.6502.org/viewtopic.php?f=2&t=2241&hilit=request+for+verification&start=30#p20914

bitey/cpu/instruction/php.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ class PHP(Instruction):
1212
"""
1313

1414
def instruction_execute(self, cpu, memory, value, address=None):
15-
# TODO: Describe the reason for the OR with 0b00110000 (the
16-
# Break and Expansion flags)
15+
# The behavior of the Break flag (B) and Expansion or Reserved
16+
# flag (E) during PHP is not documented behavior but
17+
# Visual6502 shows it as being set and several external tests
18+
# assume that it is set, so we set it for PHP and BRK.
1719
#
1820
# https://github.com/Klaus2m5/6502_65C02_functional_tests/issues/13
1921
# http://forum.6502.org/viewtopic.php?f=2&t=2241&hilit=request+for+verification&start=30#p20914

chip/6502.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@
296296
{
297297
"opcode": 0,
298298
"addressing_mode": "implied",
299-
"bytes": 1
299+
"bytes": 2
300300
}
301301
]
302302
},

chip/cmos-6502.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299
{
300300
"opcode": 0,
301301
"addressing_mode": "implied",
302-
"bytes": 1
302+
"bytes": 2
303303
}
304304
]
305305
},

chip/kim-1-6502.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
{
301301
"opcode": 0,
302302
"addressing_mode": "implied",
303-
"bytes": 1
303+
"bytes": 2
304304
}
305305
]
306306
},

chip/nmos-6502.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@
303303
{
304304
"opcode": 0,
305305
"addressing_mode": "implied",
306-
"bytes": 1
306+
"bytes": 2
307307
}
308308
]
309309
},

0 commit comments

Comments
 (0)