summaryrefslogtreecommitdiff
path: root/cpu.c
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-06-09 13:11:05 +0530
committervin <git@vineetk.net>2024-06-09 13:11:05 +0530
commit76b9059b2e299dca5a96cf94f21038002f4dad3a (patch)
tree13057c696da6140f2bf8569578a9ef4e2494a2b6 /cpu.c
parent207c6903f57f2364770c466dbe9807581ef96dc5 (diff)
add blank todo opcode functions based on opcode json
Diffstat (limited to 'cpu.c')
-rw-r--r--cpu.c425
1 files changed, 406 insertions, 19 deletions
diff --git a/cpu.c b/cpu.c
index bb6370b..4aeaaf6 100644
--- a/cpu.c
+++ b/cpu.c
@@ -110,7 +110,7 @@ opcode_arg(enum addressing_mode mode)
110 return val; 110 return val;
111} 111}
112 112
113void 113static void
114adc(uint8_t arg) 114adc(uint8_t arg)
115{ 115{
116 uint16_t sum; // 16-bit sum makes it easier to determine carry flag 116 uint16_t sum; // 16-bit sum makes it easier to determine carry flag
@@ -125,43 +125,198 @@ adc(uint8_t arg)
125 STATUS_UPDATE_NEGATIVE(regs.a); 125 STATUS_UPDATE_NEGATIVE(regs.a);
126} 126}
127 127
128void 128static void
129sbc(uint8_t arg) 129and(uint8_t arg)
130{ 130{
131 /* SBC is described online as ADC with argument as two's complement */ 131/* TODO: complete this */
132 adc(~arg + 1);
133} 132}
134 133
135void 134static void
136brk(void) 135asl(uint8_t arg)
136{
137/* TODO: complete this */
138}
139
140static void
141bbr(uint8_t arg)
142{
143/* TODO: complete this */
144}
145
146static void
147bbs(uint8_t arg)
148{
149/* TODO: complete this */
150}
151
152static void
153bcc(uint8_t arg)
154{
155/* TODO: complete this */
156}
157
158static void
159bcs(uint8_t arg)
160{
161/* TODO: complete this */
162}
163
164static void
165beq(uint8_t arg)
166{
167/* TODO: complete this */
168}
169
170static void
171bit(uint8_t arg)
172{
173/* TODO: complete this */
174}
175
176static void
177bmi(uint8_t arg)
178{
179/* TODO: complete this */
180}
181
182static void
183bne(uint8_t arg)
184{
185/* TODO: complete this */
186}
187
188static void
189bpl(uint8_t arg)
190{
191/* TODO: complete this */
192}
193
194static void
195bra(uint8_t arg)
196{
197/* TODO: complete this */
198}
199
200static void
201brk()
137{ 202{
138 /* $00 */
139 /* TODO: push regs.pc and regs.status to stack and load IRQ vector */ 203 /* TODO: push regs.pc and regs.status to stack and load IRQ vector */
140 regs.status.brk = 1; 204 regs.status.brk = 1;
141 return; 205 exit(0);
142} 206}
143 207
144void 208static void
145tax(void) 209bvc(uint8_t arg)
146{ 210{
147 /* $AA */ 211/* TODO: complete this */
148 regs.x = regs.a; 212}
149 213
150 STATUS_UPDATE_ZERO(regs.x); 214static void
151 STATUS_UPDATE_NEGATIVE(regs.x); 215bvs(uint8_t arg)
216{
217/* TODO: complete this */
152} 218}
153 219
154void 220static void
155inx(void) 221clc(uint8_t arg)
222{
223/* TODO: complete this */
224}
225
226static void
227cld(uint8_t arg)
228{
229/* TODO: complete this */
230}
231
232static void
233cli(uint8_t arg)
234{
235/* TODO: complete this */
236}
237
238static void
239clv(uint8_t arg)
240{
241/* TODO: complete this */
242}
243
244static void
245cmp(uint8_t arg)
246{
247/* TODO: complete this */
248}
249
250static void
251cpx(uint8_t arg)
252{
253/* TODO: complete this */
254}
255
256static void
257cpy(uint8_t arg)
258{
259/* TODO: complete this */
260}
261
262static void
263dec(uint8_t arg)
264{
265/* TODO: complete this */
266}
267
268static void
269dex(uint8_t arg)
270{
271/* TODO: complete this */
272}
273
274static void
275dey(uint8_t arg)
276{
277/* TODO: complete this */
278}
279
280static void
281eor(uint8_t arg)
282{
283/* TODO: complete this */
284}
285
286static void
287inc(uint8_t arg)
288{
289/* TODO: complete this */
290}
291
292static void
293inx()
156{ 294{
157 /* $E8 */
158 regs.x++; 295 regs.x++;
159 296
160 STATUS_UPDATE_ZERO(regs.x); 297 STATUS_UPDATE_ZERO(regs.x);
161 STATUS_UPDATE_NEGATIVE(regs.x); 298 STATUS_UPDATE_NEGATIVE(regs.x);
162} 299}
163 300
164void 301static void
302iny(uint8_t arg)
303{
304/* TODO: complete this */
305}
306
307static void
308jmp(uint8_t arg)
309{
310/* TODO: complete this */
311}
312
313static void
314jsr(uint8_t arg)
315{
316/* TODO: complete this */
317}
318
319static void
165lda(uint8_t arg) 320lda(uint8_t arg)
166{ 321{
167 printf("arg1 $%02X\n", arg); 322 printf("arg1 $%02X\n", arg);
@@ -171,6 +326,238 @@ lda(uint8_t arg)
171 STATUS_UPDATE_NEGATIVE(regs.a); 326 STATUS_UPDATE_NEGATIVE(regs.a);
172} 327}
173 328
329static void
330ldx(uint8_t arg)
331{
332/* TODO: complete this */
333}
334
335static void
336ldy(uint8_t arg)
337{
338/* TODO: complete this */
339}
340
341static void
342lsr(uint8_t arg)
343{
344/* TODO: complete this */
345}
346
347static void
348nop(uint8_t arg)
349{
350/* TODO: complete this */
351}
352
353static void
354ora(uint8_t arg)
355{
356/* TODO: complete this */
357}
358
359static void
360pha(uint8_t arg)
361{
362/* TODO: complete this */
363}
364
365static void
366php(uint8_t arg)
367{
368/* TODO: complete this */
369}
370
371static void
372phx(uint8_t arg)
373{
374/* TODO: complete this */
375}
376
377static void
378phy(uint8_t arg)
379{
380/* TODO: complete this */
381}
382
383static void
384pla(uint8_t arg)
385{
386/* TODO: complete this */
387}
388
389static void
390plp(uint8_t arg)
391{
392/* TODO: complete this */
393}
394
395static void
396plx(uint8_t arg)
397{
398/* TODO: complete this */
399}
400
401static void
402ply(uint8_t arg)
403{
404/* TODO: complete this */
405}
406
407static void
408rmb(uint8_t arg)
409{
410/* TODO: complete this */
411}
412
413static void
414rol(uint8_t arg)
415{
416/* TODO: complete this */
417}
418
419static void
420ror(uint8_t arg)
421{
422/* TODO: complete this */
423}
424
425static void
426rti(uint8_t arg)
427{
428/* TODO: complete this */
429}
430
431static void
432rts(uint8_t arg)
433{
434/* TODO: complete this */
435}
436
437static void
438sbc(uint8_t arg)
439{
440 /* SBC is described online as ADC with argument as two's complement */
441 adc(~arg + 1);
442}
443
444static void
445sec(uint8_t arg)
446{
447/* TODO: complete this */
448}
449
450static void
451sed(uint8_t arg)
452{
453/* TODO: complete this */
454}
455
456static void
457sei(uint8_t arg)
458{
459/* TODO: complete this */
460}
461
462static void
463smb(uint8_t arg)
464{
465/* TODO: complete this */
466}
467
468static void
469sta(uint8_t arg)
470{
471/* TODO: complete this */
472}
473
474static void
475stp(uint8_t arg)
476{
477/* TODO: complete this */
478}
479
480static void
481stx(uint8_t arg)
482{
483/* TODO: complete this */
484}
485
486static void
487sty(uint8_t arg)
488{
489/* TODO: complete this */
490}
491
492static void
493stz(uint8_t arg)
494{
495/* TODO: complete this */
496}
497
498static void
499tax()
500{
501 regs.x = regs.a;
502
503 STATUS_UPDATE_ZERO(regs.x);
504 STATUS_UPDATE_NEGATIVE(regs.x);
505}
506
507static void
508tay(uint8_t arg)
509{
510/* TODO: complete this */
511}
512
513static void
514trb(uint8_t arg)
515{
516/* TODO: complete this */
517}
518
519static void
520tsb(uint8_t arg)
521{
522/* TODO: complete this */
523}
524
525static void
526tsx(uint8_t arg)
527{
528/* TODO: complete this */
529}
530
531static void
532txa(uint8_t arg)
533{
534/* TODO: complete this */
535}
536
537static void
538txs(uint8_t arg)
539{
540/* TODO: complete this */
541}
542
543static void
544tya(uint8_t arg)
545{
546/* TODO: complete this */
547}
548
549static void
550wai(uint8_t arg)
551{
552/* TODO: complete this */
553}
554
555static void
556unp(uint8_t arg)
557{
558/* TODO: complete this */
559}
560
174void 561void
175interpret(void) 562interpret(void)
176{ 563{