-
Notifications
You must be signed in to change notification settings - Fork 64
/
cpm.cpp
executable file
·179 lines (149 loc) · 3.65 KB
/
cpm.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifdef BUILD_COCO
#ifdef ESP_PLATFORM
#define CCP_INTERNAL
#include "cpm.h"
#include "fnSystem.h"
#include "fnUART.h"
#include "fnWiFi.h"
#include "fuji.h"
#include "fnFS.h"
#include "fnFsSD.h"
#include "../runcpm/globals.h"
#include "../runcpm/abstraction_fujinet_apple2.h"
#include "../runcpm/ram.h" // ram.h - Implements the RAM
#include "../runcpm/console.h" // console.h - implements console.
#include "../runcpm/cpu.h" // cpu.h - Implements the emulated CPU
#include "../runcpm/disk.h" // disk.h - Defines all the disk access abstraction functions
#include "../runcpm/host.h" // host.h - Custom host-specific BDOS call
#include "../runcpm/cpm.h" // cpm.h - Defines the CPM structures and calls
#ifdef CCP_INTERNAL
# include "../runcpm/ccp.h" // ccp.h - Defines a simple internal CCP
#endif
static void cpmTask(void *arg)
{
Debug_printf("cpmTask()\n");
while (1)
{
Status = Debug = 0;
Break = Step = -1;
RAM = (uint8_t *)malloc(MEMSIZE);
memset(RAM, 0, MEMSIZE);
memset(filename, 0, sizeof(filename));
memset(newname, 0, sizeof(newname));
memset(fcbname, 0, sizeof(fcbname));
memset(pattern, 0, sizeof(pattern));
#ifdef ESP_PLATFORM // OS
vTaskDelay(100);
#endif
_puts(CCPHEAD);
_PatchCPM();
_ccp();
}
}
drivewireCPM::drivewireCPM()
{
rxq = xQueueCreate(2048, sizeof(char));
txq = xQueueCreate(2048, sizeof(char));
}
// drivewireCPM::~drivewireCPM()
// {
// if (cpmTaskHandle != NULL)
// {
// vTaskDelete(cpmTaskHandle);
// }
// vQueueDelete(rxq);
// vQueueDelete(txq);
// }
void drivewireCPM::ready()
{
fnUartBUS.write(0x01);
}
void drivewireCPM::send_response()
{
// Send body
fnUartBUS.write((uint8_t *)response.c_str(),response.length());
// Clear the response
response.clear();
response.shrink_to_fit();
}
void drivewireCPM::boot()
{
#ifdef ESP_PLATFORM
if (cpmTaskHandle != NULL)
{
vTaskDelete(cpmTaskHandle);
cpmTaskHandle = NULL;
}
xTaskCreatePinnedToCore(cpmTask, "cpmtask", 32768, NULL, 20, &cpmTaskHandle, 1);
#endif /* ESP_PLATFORM */
}
void drivewireCPM::read()
{
uint8_t lenh = fnUartBUS.read();
uint8_t lenl = fnUartBUS.read();
uint16_t len = (lenh * 256) + lenl;
uint16_t mw = uxQueueMessagesWaiting(rxq);
if (!len)
return;
if (len > mw)
return;
response.clear();
response.shrink_to_fit();
for (uint16_t i=0; i<mw; i++)
{
char b;
#ifdef ESP_PLATFORM
xQueueReceive(rxq, &b, portMAX_DELAY);
#endif /* ESP_PLATFORM */
response += b;
}
}
void drivewireCPM::write()
{
uint8_t lenh = fnUartBUS.read();
uint8_t lenl = fnUartBUS.read();
uint16_t len = (lenh * 256) + lenl;
for (uint16_t i=0;i<len;i++)
{
char b = fnUartBUS.read();
#ifdef ESP_PLATFORM
xQueueSend(txq, &b, portMAX_DELAY);
#endif /* ESP_PLATFORM */
}
}
void drivewireCPM::status()
{
unsigned short mw = uxQueueMessagesWaiting(rxq);
response.clear();
response.shrink_to_fit();
response += mw << 8 & 0xFF;
response += mw & 0xFF;
}
void drivewireCPM::process()
{
uint8_t cmd = fnUartBUS.read();
switch(cmd)
{
case 0x00:
ready();
break;
case 0x01:
send_response();
break;
case 'B':
boot();
break;
case 'R':
read();
break;
case 'W':
write();
break;
case 'S':
status();
break;
}
}
drivewireCPM theCPM;
#endif /* ESP_PLATFORM */
#endif /* BUILD_COCO */