-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpu_intrinsics.c
68 lines (65 loc) · 1.39 KB
/
cpu_intrinsics.c
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
//
// cpu_intrinsics.c
// d16-jit
//
// Created by Michael Nolan on 10/8/16.
// Copyright © 2016 Michael Nolan. All rights reserved.
//
#include "cpu_intrinsics.h"
#include "io.h"
#include "timer.h"
#include "sound.h"
void io_store_word(uint16_t addr, uint16_t val){
switch(addr){
case TIMER_DATA:
timer_set(val);
break;
case SOUND_DATA:
IF_MIDI(sound_set(val));
break;
}
}
void write_leds(uint8_t data){
printf("LEDS: ");
for(int i=128;i>0;i=i>>1){
if(i&data)
printf("1");
else
printf("0");
}
printf("\n");
}
void io_store_byte(uint16_t addr, uint8_t val){
switch (addr){
case IO_LED_DATA:
write_leds(val);
break;
case IO_UART_DATA:
cpu_thread_write_byte(val);
break;
default:
fprintf(stderr, "Write to invalid IO address: %x\n",addr);
break;
}
}
uint16_t io_load_word(uint16_t addr){
switch(addr){
case TIMER_DATA:
return timer_get();
default:
fprintf(stderr,"Read from invalid IO address: %x\n",addr);
return 0;
}
}
uint8_t io_load_byte(uint16_t addr){
switch(addr){
case IO_UART_STATUS:
return io_read_status();
case IO_UART_DATA:
return cpu_thread_read_byte();
default:
fprintf(stderr, "Read from invalid IO address: %x\n",addr);
break;
}
return 0;
}