MCPcopy Create free account
hub / github.com/CE-Programming/CEmu / control_write

Function control_write

core/control.c:78–213  ·  view source on GitHub ↗

Write to the 0x0XXX range of ports */

Source from the content-addressed store, hash-verified

76
77/* Write to the 0x0XXX range of ports */
78static void control_write(const uint16_t pio, const uint8_t byte, bool poke) {
79 unsigned int i;
80 uint8_t index = (uint8_t)pio;
81 (void)poke;
82
83 switch (index) {
84 case 0x00:
85 control.ports[index] = byte & 0x93;
86 if (byte & (1 << 4)) {
87 cpu_crash("writing to bit 4 of port 0");
88 }
89 /* Setting this bit turns off the calc (not implemented yet) */
90 if (byte & (1 << 6)) {
91 control.off = true;
92 }
93 switch (control.readBatteryStatus) {
94 case 3: /* Battery Level is 0 */
95 control.readBatteryStatus = control.setBatteryStatus == BATTERY_0 ? 0 : byte & 0x80 ? 5 : 0;
96 break;
97 case 5: /* Battery Level is 1 */
98 control.readBatteryStatus = control.setBatteryStatus == BATTERY_1 ? 0 : byte & 0x80 ? 0 : 7;
99 break;
100 case 7: /* Battery Level is 2 */
101 control.readBatteryStatus = control.setBatteryStatus == BATTERY_2 ? 0 : byte & 0x80 ? 9 : 0;
102 break;
103 case 9: /* Battery Level is 3 (Or 4) */
104 control.readBatteryStatus = control.setBatteryStatus == BATTERY_3 ? 0 : byte & 0x80 ? 0 : 11;
105 break;
106 }
107 break;
108 case 0x01:
109 control.ports[index] = byte & 19;
110 control.cpuSpeed = byte & 3;
111 switch(control.cpuSpeed) {
112 case 0:
113 set_cpu_clock(6e6); /* 6 MHz */
114 break;
115 case 1:
116 set_cpu_clock(12e6); /* 12 MHz */
117 break;
118 case 2:
119 set_cpu_clock(24e6); /* 24 MHz */
120 break;
121 case 3:
122 set_cpu_clock(48e6); /* 48 MHz */
123 break;
124 default:
125 break;
126 }
127 break;
128 case 0x05:
129 if ((control.ports[index] & ~byte) & (1 << 6)) {
130 cpu_crash("resetting bit 6 of port 5");
131 }
132 control.ports[index] = byte & 0x1F;
133 break;
134 case 0x06:
135 control.protectedPortsUnlocked = byte & 7;

Callers

nothing calls this directly

Calls 8

cpu_crashFunction · 0.85
set_cpu_clockFunction · 0.85
protected_ports_unlockedFunction · 0.85
panel_hw_resetFunction · 0.85
spi_device_selectFunction · 0.85
lcd_disableFunction · 0.85
bus_randFunction · 0.85
lcd_updateFunction · 0.85

Tested by

no test coverage detected