-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgemdoscon.c
209 lines (169 loc) · 4.39 KB
/
gemdoscon.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
* TOSEMU - an emulated environment for TOS applications
* Copyright (C) 2014 Johan Thelin <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "gemdoscon_p.h"
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "cpu.h"
#include "utils.h"
#include "m68k.h"
#include "gemdos_p.h"
/* Console I/O functions *****************************************************/
uint32_t GEMDOS_Cconin()
{
FUNC_TRACE_ENTER
return getchar() & 0xff; /* TODO no shift key status, scancode */
}
uint32_t GEMDOS_Cnecin()
{
FUNC_TRACE_ENTER
/* TODO: turn off not echo. */
return getchar() & 0xff; /* TODO no shift key status, scancode */
}
uint32_t GEMDOS_Cconout()
{
FUNC_TRACE_ENTER_ARGS {
printf(" 0x%x '%c'\n", peek_u16(2), peek_u16(2)&0xff);
}
putchar(peek_u16(2)&0xff);
return 0;
}
uint32_t GEMDOS_Cconis()
{
FUNC_TRACE_ENTER
if (console_input_available())
return -1;
else
return 0;
}
uint32_t GEMDOS_Cconos()
{
FUNC_TRACE_ENTER
return -1; /* Always ready */
}
uint32_t GEMDOS_Cconws()
{
uint32_t adr = peek_u32(2);
uint32_t res = 0;
uint8_t ch;
FUNC_TRACE_ENTER_ARGS {
printf(" 0x%x\n", adr);
}
while((ch=m68k_read_disassembler_8(adr++)))
{
putchar(ch);
res++;
}
return res;
}
uint32_t GEMDOS_Cconrs()
{
char buf[257]; /* Max len on ST side is 256 */
/* This is a pointer to a LINE struct, i.e.
*
* typedef struct
* {
* uint8_t maxlen; * Maximum line length *
* uint8_t actuallen; * Current line length *
* int8_t buffer[255]; * Line buffer *
* } LINE;
*/
uint32_t lineptr = peek_u32(2);
uint8_t maxlen = m68k_read_memory_8(lineptr);
fgets(buf, maxlen, stdin);
int len = strlen(buf);
if (len > 0 && buf[len-1] == '\n')
{
/* Remove final \n */
buf[len-1] = '\0';
len --;
}
if (len > maxlen)
{
/* Truncate buffer string if necessary */
len = maxlen;
buf[len] = '\0';
}
m68k_write_memory_8(lineptr+1, len);
char *ptr = buf;
lineptr += 2;
do
{
m68k_write_memory_8(lineptr, *ptr);
ptr ++;
lineptr ++;
} while (*ptr != '\0');
return 0;
}
uint32_t GEMDOS_Crawio()
{
uint32_t w = peek_u16(2);
FUNC_TRACE_ENTER_ARGS {
printf(" 0x%x\n", w);
}
if (w == 0xff)
{
if (console_input_available())
{
struct termios t;
tcflag_t temp;
/* Disable buffering */
tcgetattr(STDIN_FILENO, &t);
temp = t.c_lflag;
t.c_lflag &= ~ICANON;;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
uint32_t res = getchar() & 0xff; /* TODO no shift key status, scancode */
/* Restore echoing */
t.c_lflag = temp ;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
return res;
}
else
return 0;
}
else
{
/* Write character to stdout */
putchar(w&0xff);
}
return 0;
}
uint32_t GEMDOS_Crawcin()
{
/*FUNC_TRACE_ENTER*/
if (console_input_available())
{
struct termios t;
tcflag_t temp;
/* Disable buffering and echoing */
tcgetattr(STDIN_FILENO, &t);
temp = t.c_lflag;
t.c_lflag &= ~( ICANON | ECHO );;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
uint32_t res = getchar() & 0xff; /* TODO no shift key status, scancode */
/* Restore echoing */
t.c_lflag = temp;
tcsetattr(STDIN_FILENO, TCSANOW, &t);
return res;
}
else
return 0;
}