-
Notifications
You must be signed in to change notification settings - Fork 0
/
Config.lean
82 lines (74 loc) · 2.2 KB
/
Config.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Raylib
import Chip8.Const
set_option autoImplicit false
namespace Chip8
inductive QuirkMemIndex where
/-- Keep `I` unchanged -/
| Keep
/-- Set index to the address of the last accessed mem cell. `I := I + X` -/
| AddX
/-- Set index to the address one past the last accessed mem cell. `I := I + X + 1` -/
| AddX1
structure Config where
instructions_per_sec : Float
ramSizeS : Σ (ramSize : UInt16), PLift (ramPrefixSize ≤ ramSize) := Sigma.mk 4096 $ PLift.up $ by decide
/-- Maximum size of the stack (levels of nesting) -/
stackSize : Nat
displayWidth : Nat := 64
displayHeight : Nat := 32
color0 : Raylib.Color
color1 : Raylib.Color
/--
Controls the behavior of [BNNN].
`false`: jump to `NNN` + `V0` (COSMAC VIP).
`true`: jump to `NNN` + `VX` (CHIP48/SCHIP).
-/
quirkJumpOffset : Bool := false
/--
Controls the behavior of [8XY6] and [8XYE].
`false`: `VX := VY <<< 1` (COSMAC VIP).
`true`: `VX := VX <<< 1` (CHIP48/SCHIP).
-/
quirkShift : Bool := false
/--
Controls the behavior of [FX1E].
`false`: `VF` is not affected.
`true`: `VF` is set on "overflow" (0x1000).
-/
quirkIndexAdd : Bool := false
/--
Controls `I` changes during [FX55] and [FX65].
-/
quirkMemIndex : QuirkMemIndex := QuirkMemIndex.AddX1
/--
Controls the behavior of bitwise operators [8XY1] (AND), [8XY2] (OR) and [8XY3] (XOR).
`false`: `VF` is not affected.
`true`: `VF` is set to zero.
-/
quirkBitwiseFlag : Bool := true
/--
Wait for screen refresh before executing [DXYN] (Display) instruction.
-/
quirkDisplayInt : Bool := true
/--
Whether [FX0A] (Get Key) waits for the key to be released.
-/
quirkGetKeyRel : Bool := true
/-- Adds [00FD] instruction: exit -/
extExit : Bool := false
def Config.ramSize (cfg : Config) : UInt16 :=
cfg.ramSizeS.fst
def Config.ramSize_prefix (cfg : Config) : ramPrefixSize ≤ cfg.ramSize :=
cfg.ramSizeS.snd.down
def presetCosmacVip : Config where
instructions_per_sec := 600 -- roughly
stackSize := 12
color0 := .black
color1 := .green
instance instInhabitedConfig : Inhabited Config where
default := { presetCosmacVip with
quirkIndexAdd := true
stackSize := 128
color1 := .raywhite
}
end Chip8