src/osd/windows/winfile.c
| r9729 | r9730 | |
| 42 | 42 | // standard windows headers |
| 43 | 43 | #define WIN32_LEAN_AND_MEAN |
| 44 | 44 | #include <windows.h> |
| 45 | #include <winsock.h> |
| 45 | 46 | #include <winioctl.h> |
| 46 | 47 | #include <tchar.h> |
| 47 | 48 | #include <stdlib.h> |
| r9729 | r9730 | |
| 59 | 60 | // TYPE DEFINITIONS |
| 60 | 61 | //============================================================ |
| 61 | 62 | |
| 63 | enum _osd_file_kind |
| 64 | { |
| 65 | regular_file, |
| 66 | socket_file |
| 67 | }; |
| 68 | |
| 62 | 69 | struct _osd_file |
| 63 | 70 | { |
| 71 | _osd_file_kind file_kind; |
| 64 | 72 | HANDLE handle; |
| 73 | int sockfd; |
| 65 | 74 | TCHAR filename[1]; |
| 66 | 75 | }; |
| 67 | 76 | |
| r9729 | r9730 | |
| 76 | 85 | |
| 77 | 86 | |
| 78 | 87 | //============================================================ |
| 88 | // GLOBALS |
| 89 | //============================================================ |
| 90 | |
| 91 | static int socket_count = 0; |
| 92 | |
| 93 | |
| 94 | //============================================================ |
| 79 | 95 | // INLINE FUNCTIONS |
| 80 | 96 | //============================================================ |
| 81 | 97 | |
| r9729 | r9730 | |
| 85 | 101 | } |
| 86 | 102 | |
| 87 | 103 | |
| 104 | INLINE int is_path_to_socket(const char *path) |
| 105 | { |
| 106 | return (_strnicmp(path, "\\\\.\\socket", 10) == 0); |
| 107 | } |
| 88 | 108 | |
| 109 | |
| 110 | |
| 89 | 111 | //============================================================ |
| 90 | 112 | // osd_open |
| 91 | 113 | //============================================================ |
| r9729 | r9730 | |
| 121 | 143 | *dst++ = *src;//(*src == '/') ? '\\' : *src; |
| 122 | 144 | *dst++ = 0; |
| 123 | 145 | |
| 146 | // attempt to open a socket connection |
| 147 | if (is_path_to_socket(path)) |
| 148 | { |
| 149 | WSADATA wsaData; |
| 150 | char hostname[256]; |
| 151 | struct hostent *localhost; |
| 152 | struct sockaddr_in sai; |
| 153 | int flag = 1; |
| 154 | int port; |
| 155 | |
| 156 | (*file)->file_kind = socket_file; |
| 157 | |
| 158 | if( socket_count == 0 ) |
| 159 | { |
| 160 | if (WSAStartup(MAKEWORD(1,1), &wsaData) != 0) |
| 161 | { |
| 162 | filerr = FILERR_INVALID_ACCESS; |
| 163 | goto error; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | socket_count++; |
| 168 | |
| 169 | sscanf( path+strlen("\\\\.\\socket"), ":%255[^:]:%d", hostname, &port ); |
| 170 | |
| 171 | if (((*file)->sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) |
| 172 | { |
| 173 | filerr = FILERR_SOCKET_ERROR; |
| 174 | goto error; |
| 175 | } |
| 176 | |
| 177 | if (setsockopt((*file)->sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag)) == -1) |
| 178 | { |
| 179 | filerr = FILERR_SOCKET_ERROR; |
| 180 | goto error; |
| 181 | } |
| 182 | |
| 183 | localhost = gethostbyname(hostname); |
| 184 | |
| 185 | memset(&sai, 0, sizeof(sai)); |
| 186 | sai.sin_family = AF_INET; |
| 187 | sai.sin_port = htons(port); |
| 188 | sai.sin_addr = *((struct in_addr *)localhost->h_addr); |
| 189 | |
| 190 | if (connect((*file)->sockfd, (struct sockaddr *)&sai, sizeof(struct sockaddr)) == -1) |
| 191 | { |
| 192 | filerr = FILERR_SOCKET_ERROR; |
| 193 | goto error; |
| 194 | } |
| 195 | |
| 196 | *filesize = 0; |
| 197 | |
| 198 | filerr = FILERR_NONE; |
| 199 | goto error; |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | (*file)->file_kind = regular_file; |
| 204 | } |
| 205 | |
| 124 | 206 | // select the file open modes |
| 125 | 207 | if (openflags & OPEN_FLAG_WRITE) |
| 126 | 208 | { |
| r9729 | r9730 | |
| 193 | 275 | |
| 194 | 276 | file_error osd_read(osd_file *file, void *buffer, UINT64 offset, UINT32 length, UINT32 *actual) |
| 195 | 277 | { |
| 196 | | LONG upper = offset >> 32; |
| 197 | | DWORD result; |
| 278 | if (file->file_kind == regular_file) |
| 279 | { |
| 280 | LONG upper = offset >> 32; |
| 281 | DWORD result; |
| 198 | 282 | |
| 199 | | // attempt to set the file pointer |
| 200 | | result = SetFilePointer(file->handle, (UINT32)offset, &upper, FILE_BEGIN); |
| 201 | | if (result == INVALID_SET_FILE_POINTER) |
| 283 | // attempt to set the file pointer |
| 284 | result = SetFilePointer(file->handle, (UINT32)offset, &upper, FILE_BEGIN); |
| 285 | if (result == INVALID_SET_FILE_POINTER) |
| 286 | { |
| 287 | DWORD error = GetLastError(); |
| 288 | if (error != NO_ERROR) |
| 289 | return win_error_to_file_error(error); |
| 290 | } |
| 291 | |
| 292 | // then perform the read |
| 293 | if (!ReadFile(file->handle, buffer, length, &result, NULL)) |
| 294 | return win_error_to_file_error(GetLastError()); |
| 295 | if (actual != NULL) |
| 296 | *actual = result; |
| 297 | return FILERR_NONE; |
| 298 | } |
| 299 | else if (file->file_kind == socket_file) |
| 202 | 300 | { |
| 203 | | DWORD error = GetLastError(); |
| 204 | | if (error != NO_ERROR) |
| 205 | | return win_error_to_file_error(error); |
| 301 | ssize_t result; |
| 302 | struct timeval timeout; |
| 303 | fd_set readfds; |
| 304 | |
| 305 | FD_ZERO(&readfds); |
| 306 | FD_SET(file->sockfd, &readfds); |
| 307 | timeout.tv_sec = timeout.tv_usec = 0; |
| 308 | |
| 309 | if (select(file->sockfd + 1, &readfds, NULL, NULL, &timeout) < 0) |
| 310 | { |
| 311 | return win_error_to_file_error(GetLastError()); |
| 312 | } |
| 313 | else if (FD_ISSET(file->sockfd, &readfds)) |
| 314 | { |
| 315 | result = recv(file->sockfd, (char *)buffer, length, 0); |
| 316 | } |
| 317 | else |
| 318 | return FILERR_FAILURE; |
| 319 | |
| 320 | if (result < 0) |
| 321 | return win_error_to_file_error(GetLastError()); |
| 322 | |
| 323 | if (actual != NULL ) |
| 324 | *actual = result; |
| 325 | |
| 326 | return FILERR_NONE; |
| 206 | 327 | } |
| 207 | | |
| 208 | | // then perform the read |
| 209 | | if (!ReadFile(file->handle, buffer, length, &result, NULL)) |
| 210 | | return win_error_to_file_error(GetLastError()); |
| 211 | | if (actual != NULL) |
| 212 | | *actual = result; |
| 213 | | return FILERR_NONE; |
| 328 | else |
| 329 | { |
| 330 | return FILERR_INVALID_ACCESS; |
| 331 | } |
| 214 | 332 | } |
| 215 | 333 | |
| 216 | 334 | |
| r9729 | r9730 | |
| 220 | 338 | |
| 221 | 339 | file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 length, UINT32 *actual) |
| 222 | 340 | { |
| 223 | | LONG upper = offset >> 32; |
| 224 | | DWORD result; |
| 341 | if (file->file_kind == regular_file) |
| 342 | { |
| 343 | LONG upper = offset >> 32; |
| 344 | DWORD result; |
| 225 | 345 | |
| 226 | | // attempt to set the file pointer |
| 227 | | result = SetFilePointer(file->handle, (UINT32)offset, &upper, FILE_BEGIN); |
| 228 | | if (result == INVALID_SET_FILE_POINTER) |
| 346 | // attempt to set the file pointer |
| 347 | result = SetFilePointer(file->handle, (UINT32)offset, &upper, FILE_BEGIN); |
| 348 | if (result == INVALID_SET_FILE_POINTER) |
| 349 | { |
| 350 | DWORD error = GetLastError(); |
| 351 | if (error != NO_ERROR) |
| 352 | return win_error_to_file_error(error); |
| 353 | } |
| 354 | |
| 355 | // then perform the read |
| 356 | if (!WriteFile(file->handle, buffer, length, &result, NULL)) |
| 357 | return win_error_to_file_error(GetLastError()); |
| 358 | if (actual != NULL) |
| 359 | *actual = result; |
| 360 | return FILERR_NONE; |
| 361 | } |
| 362 | else if (file->file_kind == socket_file) |
| 229 | 363 | { |
| 230 | | DWORD error = GetLastError(); |
| 231 | | if (error != NO_ERROR) |
| 232 | | return win_error_to_file_error(error); |
| 364 | UINT32 result; |
| 365 | |
| 366 | result = send(file->sockfd, (const char *)buffer, length, 0); |
| 367 | |
| 368 | if (result < 0) |
| 369 | return win_error_to_file_error(GetLastError()); |
| 370 | |
| 371 | if (actual != NULL ) |
| 372 | *actual = result; |
| 373 | |
| 374 | return FILERR_NONE; |
| 233 | 375 | } |
| 234 | | |
| 235 | | // then perform the read |
| 236 | | if (!WriteFile(file->handle, buffer, length, &result, NULL)) |
| 237 | | return win_error_to_file_error(GetLastError()); |
| 238 | | if (actual != NULL) |
| 239 | | *actual = result; |
| 240 | | return FILERR_NONE; |
| 376 | else |
| 377 | { |
| 378 | return FILERR_INVALID_ACCESS; |
| 379 | } |
| 241 | 380 | } |
| 242 | 381 | |
| 243 | 382 | |
| r9729 | r9730 | |
| 248 | 387 | file_error osd_close(osd_file *file) |
| 249 | 388 | { |
| 250 | 389 | // close the file handle and free the file structure |
| 251 | | CloseHandle(file->handle); |
| 390 | if (file->file_kind == regular_file) |
| 391 | { |
| 392 | CloseHandle(file->handle); |
| 393 | } |
| 394 | else if (file->file_kind == socket_file) |
| 395 | { |
| 396 | closesocket(file->sockfd); |
| 397 | socket_count--; |
| 398 | |
| 399 | if( socket_count == 0 ) |
| 400 | { |
| 401 | WSACleanup(); |
| 402 | } |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | } |
| 407 | |
| 252 | 408 | free(file); |
| 253 | 409 | return FILERR_NONE; |
| 254 | 410 | } |
src/mess/drivers/vt100.c
| r9729 | r9730 | |
| 34 | 34 | double send_baud_rate; |
| 35 | 35 | double recv_baud_rate; |
| 36 | 36 | UINT8 key_scan; |
| 37 | UINT8 key_code; |
| 37 | 38 | }; |
| 38 | 39 | |
| 39 | 40 | |
| r9729 | r9730 | |
| 59 | 60 | |
| 60 | 61 | static ADDRESS_MAP_START( vt180_io , ADDRESS_SPACE_IO, 8) |
| 61 | 62 | ADDRESS_MAP_UNMAP_HIGH |
| 63 | ADDRESS_MAP_GLOBAL_MASK(0xff) |
| 62 | 64 | ADDRESS_MAP_END |
| 63 | 65 | |
| 64 | 66 | // 0 - XMIT flag H |
| r9729 | r9730 | |
| 78 | 80 | return retVal; |
| 79 | 81 | } |
| 80 | 82 | |
| 83 | static UINT8 bit_sel(UINT8 data) { |
| 84 | if (!BIT(data,7)) return 0x70; |
| 85 | if (!BIT(data,6)) return 0x60; |
| 86 | if (!BIT(data,5)) return 0x50; |
| 87 | if (!BIT(data,4)) return 0x40; |
| 88 | if (!BIT(data,3)) return 0x30; |
| 89 | if (!BIT(data,2)) return 0x20; |
| 90 | if (!BIT(data,1)) return 0x10; |
| 91 | if (!BIT(data,0)) return 0x00; |
| 92 | return 0; |
| 93 | } |
| 81 | 94 | |
| 82 | 95 | static TIMER_CALLBACK(keyboard_callback) |
| 83 | 96 | { |
| r9729 | r9730 | |
| 90 | 103 | "LINEC", "LINED", "LINEE", "LINEF" |
| 91 | 104 | }; |
| 92 | 105 | UINT8 code; |
| 93 | | if (state->key_scan == 1) { |
| 106 | if (state->key_scan) { |
| 94 | 107 | for(i = 0; i < 16; i++) |
| 95 | 108 | { |
| 96 | 109 | code = input_port_read(machine, keynames[i]); |
| 97 | 110 | if (code!=0xff) { |
| 98 | 111 | state->keyboard_int = 1; |
| 112 | state->key_code = i | bit_sel(code); |
| 99 | 113 | cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE); |
| 114 | break; |
| 100 | 115 | } |
| 101 | 116 | } |
| 102 | 117 | } |
| r9729 | r9730 | |
| 122 | 137 | |
| 123 | 138 | static READ8_HANDLER(vt100_keyboard_r) |
| 124 | 139 | { |
| 125 | | return 0x7f; |
| 140 | vt100_state *state = space->machine->driver_data<vt100_state>(); |
| 141 | return state->key_code; |
| 126 | 142 | } |
| 127 | 143 | static WRITE8_HANDLER(vt100_baud_rate_w) |
| 128 | 144 | { |
| r9729 | r9730 | |
| 307 | 323 | |
| 308 | 324 | static MACHINE_START(vt100) |
| 309 | 325 | { |
| 310 | | timer_pulse(machine, ATTOTIME_IN_HZ(240), NULL, 0, keyboard_callback); |
| 326 | timer_pulse(machine, ATTOTIME_IN_HZ(800), NULL, 0, keyboard_callback); |
| 311 | 327 | } |
| 312 | 328 | |
| 313 | 329 | static MACHINE_RESET(vt100) |
| r9729 | r9730 | |
| 391 | 407 | MDRV_SCREEN_REFRESH_RATE(60) |
| 392 | 408 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */ |
| 393 | 409 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_INDEXED16) |
| 394 | | MDRV_SCREEN_SIZE(80*10, 30*10) |
| 395 | | MDRV_SCREEN_VISIBLE_AREA(0, 80*10-1, 0, 30*10-1) |
| 410 | MDRV_SCREEN_SIZE(132*10, 30*10) |
| 411 | MDRV_SCREEN_VISIBLE_AREA(0, 132*10-1, 0, 30*10-1) |
| 396 | 412 | MDRV_GFXDECODE(vt100) |
| 397 | 413 | MDRV_PALETTE_LENGTH(2) |
| 398 | 414 | MDRV_PALETTE_INIT(monochrome_green) |