Add notes from 2023-08-07
This commit is contained in:
parent
3597ad1b01
commit
de69180456
|
|
@ -0,0 +1,82 @@
|
|||
# Dev notes — 2023-08-07
|
||||
|
||||
## Carry vs overflow
|
||||
|
||||
[Understanding the difference between overflow and carry flags](https://stackoverflow.com/questions/69124873/understanding-the-difference-between-overflow-and-carry-flags)
|
||||
|
||||
> Carry indicates the result isn't mathematically correct when interpreted as unsigned, overflow indicates the result isn't mathematically correct when interpreted as signed.
|
||||
> - 1111 + 0001 = 0000 should set carry (15 + 1 = 0 is false) and clear overflow (-1 + 1 = 0 is true).
|
||||
> - 0111 + 0010 = 1001 should clear carry (7 + 2 = 9 is true) and set overflow (7 + 2 = -7 is false).
|
||||
> - 1001 + 1001 = 0010 should set both (9 + 9 = 2 and -7 + -7 = 2 are both false).
|
||||
|
||||
so <mark>carry is unsigned</mark>
|
||||
and <mark>overflow is signed</mark>
|
||||
|
||||
(which is what i've got, good)
|
||||
|
||||
## add more flags + change flag ops
|
||||
|
||||
### flags register
|
||||
|
||||
Replace the current 'Carry Flag' with a Flags Register.
|
||||
|
||||
Here's a sketch for the bit pattern:
|
||||
|
||||
```
|
||||
hi bit
|
||||
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
|
||||
0 ? negative
|
||||
0 ? zero
|
||||
0 overflow
|
||||
0 carry
|
||||
|
||||
lo bit
|
||||
```
|
||||
|
||||
cf. 6502:
|
||||
|
||||
- NV-BDIZC
|
||||
- 7: Negative, 6: Overflow, 5: none, 4: Break, 3: Decimal, 2: Interrupt disable, 1: Zero, 0: Carry
|
||||
|
||||
### flag opcodes
|
||||
|
||||
- <mark>TODO:</mark> replace `CHP` and `CFC` with `FHP` and `FTG`
|
||||
|
||||
- `FHP n`: hop if flag _n_ is set
|
||||
- eg: `FHP 0` = hop if carry flag set
|
||||
- eg: `FHP 1` = hop if overflow flag set
|
||||
- to keep it simple, we're just giving each flag a number, not fussing with bitmasking or anything
|
||||
- `FTG n`: toggle flag _n_ on/off
|
||||
- eg: if Carry is on, `FTG 0` turns it off
|
||||
- eg: if Overflow is off, `FTG 1` turns it on
|
||||
|
||||
`FHP` and `FTG` can be combined to create `set flag` and `unset flag` routines:
|
||||
|
||||
```
|
||||
@set_carry:
|
||||
FHP 0
|
||||
FTG 0
|
||||
```
|
||||
If Carry is on when this is called, then `FTG` is skipped and Carry remains set. Otherwise, `FTG` sets carry.
|
||||
|
||||
```
|
||||
; call with a return address stored at $01
|
||||
|
||||
@unset_carry:
|
||||
FHP 0 ; 1
|
||||
FHP 0 ; 2
|
||||
FTG 0 ; 3
|
||||
JMP ($01) ; jump back to caller
|
||||
```
|
||||
If Carry is on when this is called, then the execution is: 1, 3, and Carry is turned off.
|
||||
|
||||
If Carry is off, then the execution is: 1, 2, (hop over 3; Carry is still off), jump back to caller.
|
||||
|
||||
## Think about a subroutine stack?
|
||||
|
||||
Maybe?
|
||||
Loading…
Reference in New Issue