Previous 15994 Revisions Next

r9730 Sunday 5th December, 2010 at 14:07:19 UTC by Miodrag Milanović
[VT100] It is now possible to enter setup mode
[src/emu]devimage.c diimage.c diimage.h
[src/mess/drivers]vt100.c
[src/osd]osdcore.h
[src/osd/windows]windows.mak winfile.c

src/osd/osdcore.h
r9729r9730
8282   FILERR_ALREADY_OPEN,
8383   FILERR_TOO_MANY_FILES,
8484   FILERR_INVALID_DATA,
85   FILERR_INVALID_ACCESS
85   FILERR_INVALID_ACCESS,
86   FILERR_SOCKET_ERROR
8687};
8788typedef enum _file_error file_error;
8889
src/osd/windows/windows.mak
r9729r9730
235235LDFLAGS += -static-libgcc
236236
237237# add the windows libraries
238LIBS += -luser32 -lgdi32 -ldsound -ldxguid -lwinmm -ladvapi32 -lcomctl32 -lshlwapi -ldinput8
238LIBS += -luser32 -lgdi32 -ldsound -ldxguid -lwinmm -ladvapi32 -lcomctl32 -lshlwapi -ldinput8 -lws2_32
239239
240240ifeq ($(DIRECTINPUT),8)
241241LIBS += -ldinput8
src/osd/windows/winfile.c
r9729r9730
4242// standard windows headers
4343#define WIN32_LEAN_AND_MEAN
4444#include <windows.h>
45#include <winsock.h>
4546#include <winioctl.h>
4647#include <tchar.h>
4748#include <stdlib.h>
r9729r9730
5960//  TYPE DEFINITIONS
6061//============================================================
6162
63enum _osd_file_kind
64{
65   regular_file,
66   socket_file
67};
68
6269struct _osd_file
6370{
71   _osd_file_kind      file_kind;
6472   HANDLE      handle;
73   int      sockfd;
6574   TCHAR      filename[1];
6675};
6776
r9729r9730
7685
7786
7887//============================================================
88//  GLOBALS
89//============================================================
90
91static int socket_count = 0;
92
93
94//============================================================
7995//  INLINE FUNCTIONS
8096//============================================================
8197
r9729r9730
85101}
86102
87103
104INLINE int is_path_to_socket(const char *path)
105{
106   return (_strnicmp(path, "\\\\.\\socket", 10) == 0);
107}
88108
109
110
89111//============================================================
90112//  osd_open
91113//============================================================
r9729r9730
121143      *dst++ = *src;//(*src == '/') ? '\\' : *src;
122144   *dst++ = 0;
123145
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
124206   // select the file open modes
125207   if (openflags & OPEN_FLAG_WRITE)
126208   {
r9729r9730
193275
194276file_error osd_read(osd_file *file, void *buffer, UINT64 offset, UINT32 length, UINT32 *actual)
195277{
196   LONG upper = offset >> 32;
197   DWORD result;
278   if (file->file_kind == regular_file)
279   {
280      LONG upper = offset >> 32;
281      DWORD result;
198282
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)
202300   {
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;
206327   }
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   }
214332}
215333
216334
r9729r9730
220338
221339file_error osd_write(osd_file *file, const void *buffer, UINT64 offset, UINT32 length, UINT32 *actual)
222340{
223   LONG upper = offset >> 32;
224   DWORD result;
341   if (file->file_kind == regular_file)
342   {
343      LONG upper = offset >> 32;
344      DWORD result;
225345
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)
229363   {
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;
233375   }
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   }
241380}
242381
243382
r9729r9730
248387file_error osd_close(osd_file *file)
249388{
250389   // 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
252408   free(file);
253409   return FILERR_NONE;
254410}
src/emu/diimage.c
r9729r9730
292292   "File not found",
293293   "Invalid image",
294294   "File already open",
295   "Socket not openable",
295296   "Unspecified error"
296297};
297298
src/emu/diimage.h
r9729r9730
8383    IMAGE_ERROR_FILENOTFOUND,
8484    IMAGE_ERROR_INVALIDIMAGE,
8585    IMAGE_ERROR_ALREADYOPEN,
86    IMAGE_ERROR_SOCKETNOTFOUND,
8687    IMAGE_ERROR_UNSPECIFIED
8788};
8889
src/emu/devimage.c
r9729r9730
258258            err = IMAGE_ERROR_ALREADYOPEN;
259259            break;
260260
261        case FILERR_SOCKET_ERROR:
262            err = IMAGE_ERROR_SOCKETNOTFOUND;
263            break;
264       
261265        case FILERR_FAILURE:
262266        case FILERR_TOO_MANY_FILES:
263267        case FILERR_INVALID_DATA:
src/mess/drivers/vt100.c
r9729r9730
3434   double send_baud_rate;
3535   double recv_baud_rate;
3636   UINT8 key_scan;
37   UINT8 key_code;
3738};
3839
3940
r9729r9730
5960
6061static ADDRESS_MAP_START( vt180_io , ADDRESS_SPACE_IO, 8)
6162   ADDRESS_MAP_UNMAP_HIGH
63   ADDRESS_MAP_GLOBAL_MASK(0xff)
6264ADDRESS_MAP_END
6365
6466// 0 - XMIT flag H
r9729r9730
7880   return retVal;
7981}
8082
83static 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}
8194
8295static TIMER_CALLBACK(keyboard_callback)
8396{
r9729r9730
90103      "LINEC", "LINED", "LINEE", "LINEF"
91104   };
92105   UINT8 code;
93   if (state->key_scan == 1) {
106   if (state->key_scan) {
94107      for(i = 0; i < 16; i++)
95108      {
96109         code =   input_port_read(machine, keynames[i]);
97110         if (code!=0xff) {
98111            state->keyboard_int = 1;
112            state->key_code = i | bit_sel(code);
99113            cputag_set_input_line(machine, "maincpu", 0, HOLD_LINE);
114            break;
100115         }
101116      }
102117   }
r9729r9730
122137
123138static READ8_HANDLER(vt100_keyboard_r)
124139{
125   return 0x7f;
140   vt100_state *state = space->machine->driver_data<vt100_state>();
141   return state->key_code;
126142}
127143static WRITE8_HANDLER(vt100_baud_rate_w)
128144{
r9729r9730
307323
308324static MACHINE_START(vt100)
309325{
310   timer_pulse(machine, ATTOTIME_IN_HZ(240), NULL, 0, keyboard_callback);
326   timer_pulse(machine, ATTOTIME_IN_HZ(800), NULL, 0, keyboard_callback);
311327}
312328
313329static MACHINE_RESET(vt100)
r9729r9730
391407   MDRV_SCREEN_REFRESH_RATE(60)
392408   MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500)) /* not accurate */
393409   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)
396412   MDRV_GFXDECODE(vt100)
397413   MDRV_PALETTE_LENGTH(2)
398414   MDRV_PALETTE_INIT(monochrome_green)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team