summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-06-09 16:07:09 +0530
committervin <git@vineetk.net>2024-06-09 16:07:09 +0530
commitc417bf2276dc1427d0fb747b66baa9aba22c235f (patch)
treea3475bbf43976ed5c77e20534cb7f51a3cdf38ef /cpu.c
parent4db0a8163e6641923466da99ff84d34dfdca44fa (diff)
add memory writing functions
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/cpu.c b/cpu.c
index c5b35f6..076e887 100644
--- a/cpu.c
+++ b/cpu.c
@@ -51,20 +51,34 @@ uint8_t program[] = { 0xa9, 0xc0, 0xaa, 0xe8, 0x00 };
51 51
52uint32_t cycles = 0; 52uint32_t cycles = 0;
53 53
54uint8_t 54static uint8_t
55peek(uint16_t addr) 55peek(uint16_t addr)
56{ 56{
57 return memory[addr]; 57 return memory[addr];
58} 58}
59 59
60uint16_t 60static uint16_t
61peek16(uint16_t addr) 61peek16(uint16_t addr)
62{ 62{
63 /* bytes are stored in little-endian (low then high) */ 63 /* bytes are stored in little-endian (low then high) */
64 return (uint16_t)memory[addr] | ((uint16_t)memory[addr + 1] << 8); 64 return (uint16_t)memory[addr] | ((uint16_t)memory[addr + 1] << 8);
65} 65}
66 66
67uint8_t 67static void
68memwrite(uint16_t addr, uint8_t byte)
69{
70 memory[addr] = b;
71}
72
73static void
74memwrite16(uint16_t addr, uint16_t word)
75{
76 /* bytes are stored in little-endian (low then high) */
77 memory[addr] = word & 0xFF;
78 memory[addr + 1] = (word & 0xFF00) >> 8;
79}
80
81static uint8_t
68opcode_arg(enum addressing_mode mode) 82opcode_arg(enum addressing_mode mode)
69{ 83{
70 uint8_t arg, val; 84 uint8_t arg, val;
@@ -597,7 +611,7 @@ unp(uint8_t arg)
597/* TODO: complete this */ 611/* TODO: complete this */
598} 612}
599 613
600void 614static void
601interpret(void) 615interpret(void)
602{ 616{
603 uint8_t opcode; 617 uint8_t opcode;