]> git.pld-linux.org Git - packages/fuse.git/blob - fuse-1.1.1.patch
- support for FDD3000, taken from fdd3000e
[packages/fuse.git] / fuse-1.1.1.patch
1 diff -Naru fuse-1.1.1/fuse.c fuse-1.1.1.fdd3000/fuse.c
2 --- fuse-1.1.1/fuse.c   2013-05-16 22:26:23.000000000 +0200
3 +++ fuse-1.1.1.fdd3000/fuse.c   2014-02-14 08:28:21.228997802 +0100
4 @@ -274,6 +274,7 @@
5    rzx_init();
6    psg_init();
7    beta_init();
8 +  tim397_init();
9    opus_init();
10    plusd_init();
11    disciple_init();
12 diff -Naru fuse-1.1.1/machines/machines_periph.c fuse-1.1.1.fdd3000/machines/machines_periph.c
13 --- fuse-1.1.1/machines/machines_periph.c       2013-05-16 22:26:11.000000000 +0200
14 +++ fuse-1.1.1.fdd3000/machines/machines_periph.c       2014-02-14 08:30:34.228014927 +0100
15 @@ -201,6 +201,7 @@
16    periph_set_present( PERIPH_TYPE_FULLER, PERIPH_PRESENT_OPTIONAL );
17    periph_set_present( PERIPH_TYPE_ZXPRINTER, PERIPH_PRESENT_OPTIONAL );
18    periph_set_present( PERIPH_TYPE_DISCIPLE, PERIPH_PRESENT_OPTIONAL );
19 +  periph_set_present( PERIPH_TYPE_TIM397, PERIPH_PRESENT_OPTIONAL );
20  }
21  
22  /* The set of peripherals available on the 128K and similar machines */
23 diff -Naru fuse-1.1.1/Makefile.in fuse-1.1.1.fdd3000/Makefile.in
24 --- fuse-1.1.1/Makefile.in      2013-05-30 00:21:33.000000000 +0200
25 +++ fuse-1.1.1.fdd3000/Makefile.in      2014-02-14 08:33:02.997237928 +0100
26 @@ -232,7 +232,7 @@
27  LEX_OUTPUT_ROOT = @LEX_OUTPUT_ROOT@
28  LIBOBJS = @LIBOBJS@
29  LIBPNG_CONFIG = @LIBPNG_CONFIG@
30 -LIBS = @LIBS@
31 +LIBS = @LIBS@ -lrt
32  LIBSPEC_CFLAGS = @LIBSPEC_CFLAGS@
33  LIBSPEC_HAVE_AUDIOFILE = @LIBSPEC_HAVE_AUDIOFILE@
34  LIBSPEC_HAVE_BZ2 = @LIBSPEC_HAVE_BZ2@
35 diff -Naru fuse-1.1.1/memory.c fuse-1.1.1.fdd3000/memory.c
36 --- fuse-1.1.1/memory.c 2013-05-16 22:26:23.000000000 +0200
37 +++ fuse-1.1.1.fdd3000/memory.c 2014-02-14 08:21:36.769616238 +0100
38 @@ -37,6 +37,7 @@
39  #include "memory.h"
40  #include "module.h"
41  #include "peripherals/disk/opus.h"
42 +#include "peripherals/disk/ti_m397.h"
43  #include "peripherals/spectranet.h"
44  #include "peripherals/ula.h"
45  #include "settings.h"
46 diff -Naru fuse-1.1.1/menu.c fuse-1.1.1.fdd3000/menu.c
47 --- fuse-1.1.1/menu.c   2013-05-16 22:26:23.000000000 +0200
48 +++ fuse-1.1.1.fdd3000/menu.c   2014-02-14 08:21:36.769616238 +0100
49 @@ -36,6 +36,7 @@
50  #include "peripherals/disk/beta.h"
51  #include "peripherals/disk/disciple.h"
52  #include "peripherals/disk/opus.h"
53 +#include "peripherals/disk/ti_m397.h"
54  #include "peripherals/disk/plusd.h"
55  #include "peripherals/ide/divide.h"
56  #include "peripherals/ide/simpleide.h"
57 @@ -224,7 +225,8 @@
58    case 18: menu_select_roms_with_title( "+D",              42, 1 ); return;
59    case 19: menu_select_roms_with_title( "DISCiPLE",        43, 1 ); return;
60    case 20: menu_select_roms_with_title( "Opus Discovery",  44, 1 ); return;
61 -  case 21: menu_select_roms_with_title( "SpeccyBoot",      45, 1 ); return;
62 +  case 21: menu_select_roms_with_title( "Timex M397",      45, 1 ); return;
63 +  case 22: menu_select_roms_with_title( "SpeccyBoot",      46, 1 ); return;
64  
65    }
66  
67 diff -Naru fuse-1.1.1/menu_data.dat fuse-1.1.1.fdd3000/menu_data.dat
68 --- fuse-1.1.1/menu_data.dat    2013-05-16 22:26:23.000000000 +0200
69 +++ fuse-1.1.1.fdd3000/menu_data.dat    2014-02-14 08:21:36.769616238 +0100
70 @@ -101,7 +101,8 @@
71  Options/Select ROMs/+_D..., Item,, menu_options_selectroms_select,, 18
72  Options/Select ROMs/DISCiP_LE..., Item,, menu_options_selectroms_select,, 19
73  Options/Select ROMs/_Opus Discovery..., Item,, menu_options_selectroms_select,, 20
74 -Options/Select ROMs/Specc_yBoot..., Item,, menu_options_selectroms_select,, 21
75 +Options/Select ROMs/_Timex M397..., Item,, menu_options_selectroms_select,, 21
76 +Options/Select ROMs/Specc_yBoot..., Item,, menu_options_selectroms_select,, 22
77  
78  Options/_Filter..., Item,,, menu_filter_detail
79  
80 diff -Naru fuse-1.1.1/peripherals/disk/Makefile.am fuse-1.1.1.fdd3000/peripherals/disk/Makefile.am
81 --- fuse-1.1.1/peripherals/disk/Makefile.am     2013-05-16 22:26:03.000000000 +0200
82 +++ fuse-1.1.1.fdd3000/peripherals/disk/Makefile.am     2014-02-14 08:21:36.769616238 +0100
83 @@ -37,6 +37,7 @@
84                     opus.c \
85                     plusd.c \
86                     upd_fdc.c \
87 +                   ti_m397.c \
88                     wd_fdc.c
89  
90  noinst_HEADERS = beta.h \
91 @@ -47,4 +48,5 @@
92                  opus.h \
93                  plusd.h \
94                  upd_fdc.h \
95 +                ti_m397.h \
96                  wd_fdc.h
97 diff -Naru fuse-1.1.1/peripherals/disk/Makefile.in fuse-1.1.1.fdd3000/peripherals/disk/Makefile.in
98 --- fuse-1.1.1/peripherals/disk/Makefile.in     2013-05-24 22:56:08.000000000 +0200
99 +++ fuse-1.1.1.fdd3000/peripherals/disk/Makefile.in     2014-02-14 08:32:46.900294664 +0100
100 @@ -75,7 +75,7 @@
101  libdisk_a_LIBADD =
102  am_libdisk_a_OBJECTS = beta.$(OBJEXT) crc.$(OBJEXT) disciple.$(OBJEXT) \
103         disk.$(OBJEXT) fdd.$(OBJEXT) opus.$(OBJEXT) plusd.$(OBJEXT) \
104 -       upd_fdc.$(OBJEXT) wd_fdc.$(OBJEXT)
105 +       upd_fdc.$(OBJEXT) ti_m397.$(OBJEXT) wd_fdc.$(OBJEXT)
106  libdisk_a_OBJECTS = $(am_libdisk_a_OBJECTS)
107  DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
108  depcomp = $(SHELL) $(top_srcdir)/depcomp
109 @@ -281,6 +281,7 @@
110                     opus.c \
111                     plusd.c \
112                     upd_fdc.c \
113 +                   ti_m397.c \
114                     wd_fdc.c
115  
116  noinst_HEADERS = beta.h \
117 @@ -291,6 +292,7 @@
118                  opus.h \
119                  plusd.h \
120                  upd_fdc.h \
121 +                ti_m397.h \
122                  wd_fdc.h
123  
124  all: all-am
125 @@ -349,6 +351,7 @@
126  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/opus.Po@am__quote@
127  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/plusd.Po@am__quote@
128  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upd_fdc.Po@am__quote@
129 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ti_m397.Po@am__quote@
130  @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wd_fdc.Po@am__quote@
131  
132  .c.o:
133 diff -Naru fuse-1.1.1/peripherals/disk/ti_m397.c fuse-1.1.1.fdd3000/peripherals/disk/ti_m397.c
134 --- fuse-1.1.1/peripherals/disk/ti_m397.c       1970-01-01 01:00:00.000000000 +0100
135 +++ fuse-1.1.1.fdd3000/peripherals/disk/ti_m397.c       2014-02-14 08:53:54.159789884 +0100
136 @@ -0,0 +1,562 @@
137 +/******************************************************************************
138 + This file is a part od FDD3000 Emulator
139 +
140 + Copyright (C) 2013 by SÅ‚awomir Szczyrba <sszczyrba@gmail.com>
141 + Copyright (C) 2014 by Stefano Bodrato <stefano_bodrato hotmail dt com>
142 +
143 + This program is free software: you can redistribute it and/or modify it under
144 + the terms of the GNU Lesser General Public License as published by the Free
145 + Software Foundation, either version 2 of the License, or (at your option) any
146 + later version.
147 +    
148 + This program is distributed in the hope that it will be useful, but WITHOUT
149 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
150 + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
151 + details.
152 +
153 + You should have received a copy of the GNU Lesser General Public License
154 + along with this program. If not, see <http://www.gnu.org/licenses/lgpl.html>
155 +******************************************************************************/
156 +
157 +
158 +#include <config.h>
159 +
160 +#include <libspectrum.h>
161 +
162 +#include <string.h>
163 +
164 +#include "compat.h"
165 +#include "machine.h"
166 +#include "module.h"
167 +#include "ti_m397.h"
168 +#include "peripherals/printer.h"
169 +#include "settings.h"
170 +#include "ui/ui.h"
171 +#include "unittests/unittests.h"
172 +//#include "utils.h"
173 +#include "wd_fdc.h"
174 +#include "options.h"   /* needed for get combo options */
175 +#include "z80/z80.h"
176 +
177 +
178 +#include <errno.h>
179 +#include <fcntl.h>
180 +#include <signal.h>
181 +#include <stdio.h>
182 +#include <string.h>
183 +#include <sys/stat.h>        /* For mode constants */
184 +#include <sys/types.h>
185 +#include <unistd.h>
186 +
187 +
188 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
189 +
190 +#include <windows.h>
191 +#include <tchar.h>
192 +
193 +#else
194 +
195 +#include <semaphore.h>
196 +#ifndef SEM_FAILED
197 +#define SEM_FAILED -1
198 +#endif
199 +#include <sys/mman.h>
200 +#include <sys/ipc.h>
201 +#include <sys/msg.h>
202 +#include <sys/socket.h>
203 +
204 +#endif
205 +
206 +
207 +
208 +/* IPC */
209 +
210 +typedef struct tFdd2TiLink {
211 +    uint8_t  fdd2ti;
212 +    uint8_t  ti2fdd;
213 +    uint8_t  fddAlive;
214 +    uint8_t  tiAlive;
215 +} fdd2TiLink;
216 +
217 +fdd2TiLink * fddlink;
218 +
219 +
220 +uint8_t data;
221 +int ipc, connected;
222 +char * path;
223 +
224 +
225 +
226 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
227 +
228 +HANDLE fdd2tiF, fdd2tiE, ti2fddF, ti2fddE, fddAlive;
229 +HANDLE shm, shmf;
230 +DWORD dwRetVal = 0;
231 +
232 +TCHAR *shmId = _T("\\fdd.data");
233 +//TCHAR shmId[]=TEXT("Global\\fdd.data");
234 +TCHAR szTempFileName[MAX_PATH];  
235 +TCHAR lpTempPathBuffer[MAX_PATH];
236 +
237 +TCHAR fdd2tiE_Id[]=TEXT("Global\\fdd.fdd2ti.empty");
238 +TCHAR fdd2tiF_Id[]=TEXT("Global\\fdd.fdd2ti.full");
239 +TCHAR ti2fddE_Id[]=TEXT("Global\\fdd.ti2fdd.empty");
240 +TCHAR ti2fddF_Id[]=TEXT("Global\\fdd.ti2fdd.full");
241 +TCHAR fddAlive_Id[]=TEXT("Global\\fdd.alive");   
242 +/*
243 +TCHAR * fddAlive_Id = "fdd.alive";
244 +TCHAR * fdd2tiE_Id = "fdd.fdd2ti.empty";
245 +TCHAR * fdd2tiF_Id = "fdd.fdd2ti.full";
246 +TCHAR * ti2fddE_Id = "fdd.ti2fdd.empty";
247 +TCHAR * ti2fddF_Id = "fdd.ti2fdd.full";
248 +*/
249 +#else
250 +
251 +sem_t   *fdd2tiF,*fdd2tiE,*ti2fddF,*ti2fddE,*fddAlive;
252 +int   shm;
253 +const char * shmId = "fdd.data";
254 +
255 +const char * fddAlive_Id = "fdd.alive";
256 +const char * fdd2tiE_Id = "fdd.fdd2ti.empty";
257 +const char * fdd2tiF_Id = "fdd.fdd2ti.full";
258 +const char * ti2fddE_Id = "fdd.ti2fdd.empty";
259 +const char * ti2fddF_Id = "fdd.ti2fdd.full";
260 +
261 +#endif
262 +
263 +int8_t fddRead() {
264 +    uint8_t data=0;
265 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
266 +       WaitForSingleObject(ti2fddF,INFINITE);
267 +    data=fddlink->fdd2ti;
268 +       ReleaseSemaphore(ti2fddE,1,NULL);
269 +#else
270 +    sem_wait(fdd2tiF);
271 +    data=fddlink->fdd2ti;
272 +    sem_post(fdd2tiE);
273 +#endif
274 +    return data;
275 +}
276 +
277 +void fddWrite(int8_t d) {
278 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
279 +       WaitForSingleObject(ti2fddE,INFINITE);
280 +    fddlink->ti2fdd=d;
281 +       ReleaseSemaphore(ti2fddF,1,NULL);
282 +#else
283 +    sem_wait(ti2fddE);
284 +    fddlink->ti2fdd=d;
285 +    sem_post(ti2fddF);
286 +#endif
287 +}
288 +
289 +uint8_t fddIsAlive() {
290 +    uint8_t ok;
291 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
292 +       WaitForSingleObject(fddAlive,INFINITE);
293 +    ok=fddlink->fddAlive&fddlink->tiAlive;
294 +       ReleaseSemaphore(fddAlive,1,NULL);
295 +#else
296 +    sem_wait(fddAlive);
297 +    ok=fddlink->fddAlive&fddlink->tiAlive;
298 +    sem_post(fddAlive);
299 +#endif
300 +    return ok;
301 +}
302 +
303 +void cleanUp() {
304 +    int i;
305 +    if(!ipc) { return; }
306 +    ipc=0;
307 +    connected=0;
308 +
309 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
310 +
311 +       WaitForSingleObject(fddAlive,INFINITE);
312 +    fddlink->tiAlive=0;
313 +    i=fddlink->fddAlive;
314 +       ReleaseSemaphore(fddAlive,1,NULL);
315 +
316 +//    semResetAll();
317 +    CloseHandle(fddAlive);
318 +    CloseHandle(ti2fddF);
319 +    CloseHandle(ti2fddE);
320 +    CloseHandle(fdd2tiF);
321 +    CloseHandle(fdd2tiE);
322 +
323 +    UnmapViewOfFile(fddlink);
324 +    if(!i) {
325 +               CloseHandle(shm);
326 +               CloseHandle(shmf);
327 +    }
328 +
329 +#else
330 +
331 +    sem_wait(fddAlive);
332 +    fddlink->tiAlive=0;
333 +    i=fddlink->fddAlive;
334 +    sem_post(fddAlive);
335 +
336 +//    semResetAll();
337 +    sem_close(fddAlive);
338 +    sem_close(ti2fddF);
339 +    sem_close(ti2fddE);
340 +    sem_close(fdd2tiF);
341 +    sem_close(fdd2tiE);
342 +
343 +    munmap(fddlink,sizeof(fdd2TiLink));
344 +    if(!i) {
345 +        sem_unlink(fdd2tiE_Id);
346 +        sem_unlink(fdd2tiF_Id);
347 +        sem_unlink(ti2fddE_Id);
348 +        sem_unlink(ti2fddF_Id);
349 +        sem_unlink(fddAlive_Id);
350 +        shm_unlink(shmId);
351 +    }
352 +
353 +#endif
354 +
355 +}
356 +
357 +int openShm() {
358 +    int trunc;
359 +    if(!ipc) {
360 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
361 +               //shmfile=ev.value("TMP",ev.value("TEMP","."))+"\\fdd.data";
362 +
363 +                //  Gets the temp path env string (no guarantee it's a valid path).
364 +               dwRetVal = GetTempPath(MAX_PATH, lpTempPathBuffer); // buffer for path 
365 +               if (dwRetVal > MAX_PATH || (dwRetVal == 0))
366 +               {
367 +//                     fprintf(stderr,"tim397_openShm: GetTempPath failed\n");
368 +                       return (-1);
369 +               }
370 +               snprintf(szTempFileName,MAX_PATH,"%s%s",lpTempPathBuffer,shmId);                
371 +
372 +               shmf = CreateFile(szTempFileName, GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);          
373 +
374 +               if (shmf == INVALID_HANDLE_VALUE) 
375 +               { 
376 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: CreateFile failed\n");
377 +                       return (-1);
378 +               } 
379 +
380 +               shm = CreateFileMapping(
381 +                                       shmf,//INVALID_HANDLE_VALUE,    // use paging file
382 +                                       NULL,                    // default security
383 +                                       PAGE_READWRITE,          // read/write access
384 +                                       0,                       // maximum object size (high-order DWORD)
385 +                                       256,                     // maximum object size (low-order DWORD)
386 +                                       NULL);//TEXT("Global\\shmFdd"));                  // name of mapping object
387 +               if(shm==NULL){
388 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: CreateFileMapping failed\n");
389 +                       CloseHandle(shmf);
390 +                       return (-1);
391 +               }
392 +        //fddlink=(fdd2TiLink*)mmap(0,sizeof(fdd2TiLink),PROT_READ|PROT_WRITE,MAP_SHARED,shm,0);
393 +               fddlink = (fdd2TiLink*)MapViewOfFile(shm,   // handle to map object
394 +                                       FILE_MAP_ALL_ACCESS, // read/write permission
395 +                                       0,
396 +                                       0,
397 +                                       sizeof(fdd2TiLink));
398 +               if(fddlink==NULL){
399 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: MapViewOfFile (mmap) failed\n");
400 +                       CloseHandle(shm);
401 +                       CloseHandle(shmf);
402 +                       return (-1);
403 +               }
404 +
405 +               fdd2tiE=OpenSemaphore(SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, TRUE, fdd2tiE_Id);
406 +               fdd2tiF=OpenSemaphore(SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, TRUE, fdd2tiF_Id);
407 +               ti2fddE=OpenSemaphore(SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, TRUE, ti2fddE_Id);
408 +               ti2fddF=OpenSemaphore(SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, TRUE, ti2fddF_Id);
409 +               fddAlive=OpenSemaphore(SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, TRUE, fddAlive_Id);
410 +
411 +               if ((fdd2tiE==NULL) || (fdd2tiF==NULL) || 
412 +                       (ti2fddE==NULL) || (ti2fddF==NULL) || (fddAlive==NULL)) {
413 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: semaphore creation failed\n");
414 +                       return (-1);
415 +               }
416 +
417 +#else
418 +        shm = shm_open(shmId, O_RDWR, 0666);
419 +        if (-1==shm) { 
420 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: shm_open failed\n");
421 +                       return (-1);
422 +               }
423 +        trunc=ftruncate(shm,sizeof(fdd2TiLink));
424 +        if (-1==trunc) { 
425 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: ftruncate failed\n");
426 +                       return (-1);
427 +               }
428 +        fddlink=(fdd2TiLink*)mmap(0,sizeof(fdd2TiLink),PROT_READ|PROT_WRITE,MAP_SHARED,shm,0);
429 +        if(fddlink==MAP_FAILED) {
430 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: mmap failed\n");
431 +                       return (-1);
432 +               }
433 +        close(shm);
434 +
435 +        fdd2tiE=sem_open(fdd2tiE_Id,O_RDWR,0666,1);
436 +        fdd2tiF=sem_open(fdd2tiF_Id,O_RDWR,0666,0);
437 +        ti2fddE=sem_open(ti2fddE_Id,O_RDWR,0666,1);
438 +        ti2fddF=sem_open(ti2fddF_Id,O_RDWR,0666,0);
439 +        fddAlive=sem_open(fddAlive_Id,O_RDWR,0666,1);
440 +               if ((fdd2tiE==SEM_FAILED) || (fdd2tiF==SEM_FAILED) || 
441 +                       (ti2fddE==SEM_FAILED) || (ti2fddF==SEM_FAILED) || (fddAlive==SEM_FAILED)) {
442 +                       //ui_error( UI_ERROR_ERROR, "tim397_openShm: semaphore creation failed\n");
443 +                       return (-1);
444 +               }
445 +#endif
446 +               
447 +        ipc=1;
448 +    }
449 +    if(ipc&&(!connected)) {
450 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
451 +               WaitForSingleObject(fddAlive,INFINITE);
452 +        if(fddlink->fddAlive){ fddlink->tiAlive=1; connected=1; }
453 +               ReleaseSemaphore(fddAlive,1,NULL);
454 +#else
455 +        sem_wait(fddAlive);
456 +        if(fddlink->fddAlive){ fddlink->tiAlive=1; connected=1; }
457 +        sem_post(fddAlive);
458 +#endif
459 +    }
460 +       return (0);
461 +}
462 +
463 +
464 +
465 +/*************************************************************************/
466 +
467 +libspectrum_byte tim397_io_read( libspectrum_word port, int *attached ) { 
468 +    libspectrum_byte b = 0;
469 +//ui_error( UI_ERROR_ERROR, "Reading from port: %u\n",port);
470 +    if(ipc&&connected) {
471 +//ui_error( UI_ERROR_ERROR, "Reading from port: %u\n",port);
472 +        if(fddIsAlive()) { b=fddRead(); } else  { connected=0; /*semResetAll();*/ return 0; }
473 +        *attached = 1;
474 +    }
475 +    return b;
476 +}
477 +
478 +void tim397_io_write( libspectrum_word port, libspectrum_byte b ) {
479 +//ui_error( UI_ERROR_ERROR, "Writing %u to port: %u\n",b,port);
480 +    if(ipc&&connected) { 
481 +//ui_error( UI_ERROR_ERROR, "Writing %u to port: %u\n",b,port);
482 +//             if ((port&&0xff) == 0xef)
483 +       if(fddIsAlive()) { fddWrite(b); } else  { connected=0; /*semResetAll();*/ }
484 +    }
485 +}
486 +
487 +/*************************************************************************/
488 +
489 +static void tim397_reset( int hard_reset );
490 +static void tim397_memory_map( void );
491 +static void tim397_enabled_snapshot( libspectrum_snap *snap );
492 +static void tim397_from_snapshot( libspectrum_snap *snap );
493 +static void tim397_to_snapshot( libspectrum_snap *snap );
494 +static void tim397_activate( void );
495 +
496 +
497 +/* Two 8Kb memory chunks accessible by the Z80 when /ROMCS is low */
498 +static memory_page tim397_memory_map_romcs_rom[ MEMORY_PAGES_IN_8K ];
499 +static memory_page tim397_memory_map_romcs_ram[ MEMORY_PAGES_IN_8K ];
500 +static int tim397_memory_source;
501 +
502 +int tim397_available = 0;
503 +int tim397_active = 0;
504 +
505 +static libspectrum_byte *tim397_ram;
506 +static int memory_allocated = 0;
507 +
508 +static module_info_t tim397_module_info = {
509 +  tim397_reset,
510 +  tim397_memory_map,
511 +  tim397_enabled_snapshot,
512 +  tim397_from_snapshot,
513 +  tim397_to_snapshot
514 +};
515 +
516 +void
517 +tim397_page( void )
518 +{
519 +       tim397_active = 1;
520 +       machine_current->ram.romcs = 1;
521 +       machine_current->memory_map();
522 +       //ui_error( UI_ERROR_ERROR, "tim397_page, PC: $%x\n",m397_pageflag);
523 +       ui_statusbar_update( UI_STATUSBAR_ITEM_DISK, UI_STATUSBAR_STATE_ACTIVE );
524 +}
525 +
526 +void
527 +tim397_unpage( void )
528 +{
529 +       tim397_active = 0;
530 +       machine_current->ram.romcs = 0;
531 +       machine_current->memory_map();
532 +       //ui_error( UI_ERROR_ERROR, "tim397_unpage, PC: $%x\n",z80.pc.w);
533 +       ui_statusbar_update( UI_STATUSBAR_ITEM_DISK, UI_STATUSBAR_STATE_INACTIVE );
534 +}
535 +
536 +static void
537 +tim397_memory_map( void )
538 +{
539 +  if( !tim397_active ) return;
540 +  memory_map_romcs_8k( 0x0000, tim397_memory_map_romcs_rom );
541 +  memory_map_romcs_8k( 0x2000, tim397_memory_map_romcs_ram );
542 +//  ui_error( UI_ERROR_ERROR, "tim397_memory_map, PC: $%x\n",z80.pc.w);
543 +}
544 +
545 +static const periph_port_t tim397_ports[] = {
546 +  { 0x00ff, 0x00ef, tim397_io_read, tim397_io_write },
547 +  { 0, 0, NULL, NULL }
548 +};
549 +
550 +static const periph_t tim397_periph = {
551 +  &settings_current.ti_m397,
552 +  tim397_ports,
553 +  1,
554 +  tim397_activate
555 +};
556 +
557 +int
558 +tim397_init( void )
559 +{
560 +  int i;
561 +  module_register( &tim397_module_info );
562 +
563 +  tim397_memory_source = memory_source_register( "TI_M397" );
564 +
565 +  for( i = 0; i < MEMORY_PAGES_IN_8K; i++ )
566 +    tim397_memory_map_romcs_rom[ i ].source = tim397_memory_source;
567 +  for( i = 0; i < MEMORY_PAGES_IN_8K; i++ )
568 +    tim397_memory_map_romcs_ram[ i ].source = tim397_memory_source;
569 +
570 +  periph_register( PERIPH_TYPE_TIM397, &tim397_periph );
571 +  ipc=0;
572 +
573 +  fprintf(stderr,"tim397_init\n");
574 +
575 +  return 0;
576 +}
577 +
578 +
579 +static void
580 +tim397_reset( int hard_reset )
581 +{
582 +
583 +  tim397_active = 0;
584 +  tim397_available = 0;
585 +  int i;
586 +
587 +  if( !periph_is_active( PERIPH_TYPE_TIM397 ) ) {
588 +    ui_statusbar_update( UI_STATUSBAR_ITEM_DISK,
589 +                         UI_STATUSBAR_STATE_NOT_AVAILABLE );
590 +    return;
591 +  }
592 +
593 +  if (openShm()!=0) {
594 +    settings_current.ti_m397 = 0;
595 +    periph_activate_type( PERIPH_TYPE_TIM397, 0 );
596 +//    ui_error( UI_ERROR_ERROR, "Link to FDD3000 emulator failed\n");
597 +    return;
598 +  }
599 +
600 +  if( machine_load_rom_bank( tim397_memory_map_romcs_rom, 0,
601 +                             settings_current.rom_tim397,
602 +                             settings_default.rom_tim397, 0x2000 ) ) {
603 +    settings_current.ti_m397 = 0;
604 +    periph_activate_type( PERIPH_TYPE_TIM397, 0 );
605 +    ui_statusbar_update( UI_STATUSBAR_ITEM_DISK,
606 +                         UI_STATUSBAR_STATE_NOT_AVAILABLE );
607 +    return;
608 +  }
609 +  
610 +  machine_current->ram.romcs = 0;
611 +  
612 +  for( i = 0; i < MEMORY_PAGES_IN_8K; i++ ) {
613 +       tim397_memory_map_romcs_ram[ i ].page = &tim397_ram[ i * MEMORY_PAGE_SIZE ];
614 +       tim397_memory_map_romcs_ram[ i ].writable = 1;
615 +  }
616 +
617 +  tim397_available = 1;
618 +  tim397_active = 0;
619 +
620 +  if( hard_reset ) {
621 +       memset( tim397_ram, 0, 0x2000 );
622 +  }
623
624 +  machine_current->memory_map();
625 +  ui_statusbar_update( UI_STATUSBAR_ITEM_DISK, UI_STATUSBAR_STATE_INACTIVE );
626 +  fprintf(stderr,"tim397_reset\n");
627 +}
628 +
629 +void
630 +tim397_end( void )
631 +{
632 +    tim397_available = 0;
633 +
634 +    if(ipc&&connected) {
635 +#if defined (__MINGW32__) || defined (_WIN32) || defined (_WIN32_) || defined (__WIN32__)
636 +       WaitForSingleObject(fddAlive,INFINITE);
637 +       fddlink->tiAlive=0;
638 +       ReleaseSemaphore(fddAlive,1,NULL);
639 +#else
640 +    sem_wait(fddAlive);
641 +       fddlink->tiAlive=0;
642 +    sem_post(fddAlive);
643 +#endif
644 +    }
645 +    ipc=0;
646 +    connected=0;
647 +    cleanUp();
648 +    fprintf(stderr,"tim397_end\n");
649 +}
650 +
651 +static void
652 +tim397_activate( void )
653 +{
654 +  if( !memory_allocated ) {
655 +    tim397_ram = memory_pool_allocate_persistent( 0x2000, 1 );
656 +    memory_allocated = 1;
657 +  }
658 +}
659 +
660 +int
661 +tim397_unittest( void )
662 +{
663 +  int r = 0;
664 +
665 +  tim397_page();
666 +
667 +  r += unittests_assert_16k_page( 0x0000, tim397_memory_source, 0 );
668 +  r += unittests_assert_16k_ram_page( 0x4000, 5 );
669 +  r += unittests_assert_16k_ram_page( 0x8000, 2 );
670 +  r += unittests_assert_16k_ram_page( 0xc000, 0 );
671 +
672 +  tim397_unpage();
673 +
674 +  r += unittests_paging_test_48( 2 );
675 +
676 +  return r;
677 +}
678 +
679 +
680 +static void
681 +tim397_enabled_snapshot( libspectrum_snap *snap )
682 +{
683 +  return;
684 +}
685 +
686 +static void
687 +tim397_from_snapshot( libspectrum_snap *snap )
688 +{
689 +  return;
690 +}
691 +
692 +static void
693 +tim397_to_snapshot( libspectrum_snap *snap GCC_UNUSED )
694 +{
695 +  //if( !periph_is_active( PERIPH_TYPE_TIM397 ) ) return;
696 +  return;
697 +}
698 +
699 diff -Naru fuse-1.1.1/peripherals/disk/ti_m397.h fuse-1.1.1.fdd3000/peripherals/disk/ti_m397.h
700 --- fuse-1.1.1/peripherals/disk/ti_m397.h       1970-01-01 01:00:00.000000000 +0100
701 +++ fuse-1.1.1.fdd3000/peripherals/disk/ti_m397.h       2014-02-14 08:31:43.972546695 +0100
702 @@ -0,0 +1,28 @@
703 +/*
704 +    TIM397.h: Routines for handling the Timex TIM397 
705 +*/
706 +
707 +#ifndef FUSE_TIM397_H
708 +#define FUSE_TIM397_H
709 +
710 +#include <config.h>
711 +
712 +#include <libspectrum.h>
713 +
714 +#include "fdd.h"
715 +
716 +extern int tim397_available;  /* Is the tim397 available for use? */
717 +extern int tim397_active;     /* tim397 enabled? */
718 +
719 +int tim397_init( void );
720 +void tim397_end( void );
721 +
722 +void tim397_page( void );
723 +void tim397_unpage( void );
724 +
725 +libspectrum_byte tim397_io_read( libspectrum_word port, int *attached );
726 +void tim397_io_write( libspectrum_word port, libspectrum_byte b );
727 +
728 +int tim397_unittest( void );
729 +
730 +#endif                  /* #ifndef FUSE_tim397_H */
731 diff -Naru fuse-1.1.1/periph.h fuse-1.1.1.fdd3000/periph.h
732 --- fuse-1.1.1/periph.h 2013-05-24 22:42:22.000000000 +0200
733 +++ fuse-1.1.1.fdd3000/periph.h 2014-02-14 08:21:36.769616238 +0100
734 @@ -65,6 +65,7 @@
735    PERIPH_TYPE_SPECCYBOOT,     /* SpeccyBoot interface */
736    PERIPH_TYPE_SPECDRUM,       /* SpecDrum interface */
737    PERIPH_TYPE_SPECTRANET,     /* Spectranet interface */
738 +  PERIPH_TYPE_TIM397,         /* FDD3000 disk interface */
739    PERIPH_TYPE_ULA,            /* Standard ULA */
740    PERIPH_TYPE_ULA_FULL_DECODE,/* Standard ULA responding only to 0xfe */
741    PERIPH_TYPE_UPD765,         /* +3 uPD765 FDC */
742 diff -Naru fuse-1.1.1/settings.dat fuse-1.1.1.fdd3000/settings.dat
743 --- fuse-1.1.1/settings.dat     2013-05-16 22:26:23.000000000 +0200
744 +++ fuse-1.1.1.fdd3000/settings.dat     2014-02-14 08:27:14.978179040 +0100
745 @@ -64,6 +64,7 @@
746  interface2, boolean, 1
747  snapsasz80, null, 0
748  opus, boolean, 0
749 +ti_m397, boolean, 0
750  pal_tv2x, boolean, 0
751  movie_compr, string, NULL
752  movie_start, string, NULL
753 @@ -235,6 +236,7 @@
754  rom_plusd, string, "plusd.rom",
755  rom_disciple, string, "disciple.rom",
756  rom_opus, string, "opus.rom",
757 +rom_tim397, string, "ti_m397.rom",
758  rom_speccyboot, string, "speccyboot-1.4.rom",
759  
760  drive_plus3a_type, string, NULL
761 diff -Naru fuse-1.1.1/settings.pl fuse-1.1.1.fdd3000/settings.pl
762 --- fuse-1.1.1/settings.pl      2013-05-24 22:42:22.000000000 +0200
763 +++ fuse-1.1.1.fdd3000/settings.pl      2014-02-14 08:25:30.881179995 +0100
764 @@ -762,7 +762,8 @@
765    case 42: return &( settings->rom_plusd );
766    case 43: return &( settings->rom_disciple );
767    case 44: return &( settings->rom_opus );
768 -  case 45: return &( settings->rom_speccyboot );
769 +  case 45: return &( settings->rom_tim397 );
770 +  case 46: return &( settings->rom_speccyboot );
771    default: return NULL;
772    }
773  }
774 diff -Naru fuse-1.1.1/ui/options.dat fuse-1.1.1.fdd3000/ui/options.dat
775 --- fuse-1.1.1/ui/options.dat   2013-05-24 22:42:22.000000000 +0200
776 +++ fuse-1.1.1.fdd3000/ui/options.dat   2014-02-14 08:21:36.769616238 +0100
777 @@ -64,6 +64,7 @@
778  Checkbox, (B)eta 128 interface, beta128, INPUT_KEY_b
779  Checkbox, Beta 128 (a)uto-boot in 48K machines, beta128_48boot, INPUT_KEY_a
780  Checkbox, (O)pus Discovery interface, opus, INPUT_KEY_o
781 +Checkbox, FDD(3)000 / M397 interface, ti_m397, INPUT_KEY_3
782  Postcheck, periph_postcheck
783  Posthook, periph_posthook
784  
785 diff -Naru fuse-1.1.1/ui/ui.h fuse-1.1.1.fdd3000/ui/ui.h
786 --- fuse-1.1.1/ui/ui.h  2013-05-16 22:26:23.000000000 +0200
787 +++ fuse-1.1.1.fdd3000/ui/ui.h  2014-02-14 08:21:36.769616238 +0100
788 @@ -39,6 +39,7 @@
789  #include "peripherals/disk/beta.h"
790  #include "peripherals/disk/disciple.h"
791  #include "peripherals/disk/opus.h"
792 +#include "peripherals/disk/ti_m397.h"
793  #include "peripherals/disk/plusd.h"
794  #include "ui/scaler/scaler.h"
795  
796 @@ -211,6 +212,7 @@
797    UI_MENU_ITEM_MEDIA_DISK_OPUS_2_EJECT,
798    UI_MENU_ITEM_MEDIA_DISK_OPUS_2_FLIP_SET,
799    UI_MENU_ITEM_MEDIA_DISK_OPUS_2_WP_SET,
800 +  UI_MENU_ITEM_MEDIA_DISK_TIM397,
801    UI_MENU_ITEM_MEDIA_IDE,
802    UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT,
803    UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT_MASTER_EJECT,
804 diff -Naru fuse-1.1.1/ui.c fuse-1.1.1.fdd3000/ui.c
805 --- fuse-1.1.1/ui.c     2013-05-16 22:26:23.000000000 +0200
806 +++ fuse-1.1.1.fdd3000/ui.c     2014-02-14 08:51:58.576646341 +0100
807 @@ -548,6 +549,8 @@
808      "/Media/Disk/Opus/Drive 2/Write protect/Enable",
809      "/Media/Disk/Opus/Drive 2/Write protect/Disable", 1 },
810  
811 +  { UI_MENU_ITEM_MEDIA_DISK_TIM397, "/Media/Disk/Timex M397" },
812 +
813    { UI_MENU_ITEM_MEDIA_IDE, "/Media/IDE" },
814  
815    { UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT, "/Media/IDE/Simple 8-bit" },
816 diff -Naru fuse-1.1.1/z80/coretest.c fuse-1.1.1.fdd3000/z80/coretest.c
817 --- fuse-1.1.1/z80/coretest.c   2013-05-16 22:26:16.000000000 +0200
818 +++ fuse-1.1.1.fdd3000/z80/coretest.c   2014-02-14 08:21:36.769616238 +0100
819 @@ -459,6 +459,21 @@
820    abort();
821  }
822  
823 +int tim397_available = 0;
824 +int tim397_active = 0;
825 +
826 +void
827 +tim397_page( void )
828 +{
829 +  abort();
830 +}
831 +
832 +void
833 +tim397_unpage( void )
834 +{
835 +  abort();
836 +}
837 +
838  int plusd_available = 0;
839  int plusd_active = 0;
840  
841 diff -Naru fuse-1.1.1/z80/z80_checks.h fuse-1.1.1.fdd3000/z80/z80_checks.h
842 --- fuse-1.1.1/z80/z80_checks.h 2013-05-16 22:26:16.000000000 +0200
843 +++ fuse-1.1.1.fdd3000/z80/z80_checks.h 2014-02-14 08:23:42.063410052 +0100
844 @@ -2,6 +2,7 @@
845  SETUP_CHECK( rzx, rzx_playback )
846  SETUP_CHECK( debugger, debugger_mode != DEBUGGER_MODE_INACTIVE )
847  SETUP_CHECK( beta, beta_available )
848 +SETUP_CHECK( tim397, tim397_available )
849  SETUP_CHECK( plusd, plusd_available )
850  SETUP_CHECK( disciple, disciple_available )
851  SETUP_CHECK( if1p, if1_available )
852 diff -Naru fuse-1.1.1/z80/z80_ops.c fuse-1.1.1.fdd3000/z80/z80_ops.c
853 --- fuse-1.1.1/z80/z80_ops.c    2013-05-16 22:26:16.000000000 +0200
854 +++ fuse-1.1.1.fdd3000/z80/z80_ops.c    2014-02-14 08:23:33.485342586 +0100
855 @@ -36,6 +36,7 @@
856  #include "peripherals/disk/disciple.h"
857  #include "peripherals/disk/opus.h"
858  #include "peripherals/disk/plusd.h"
859 +#include "peripherals/disk/ti_m397.h"
860  #include "peripherals/ide/divide.h"
861  #include "peripherals/if1.h"
862  #include "peripherals/spectranet.h"
863 @@ -176,6 +177,18 @@
864      }
865  
866      END_CHECK
867 +
868 +    CHECK( tim397, tim397_available )
869 +
870 +    if( tim397_active ) {
871 +      if( PC == 0x0604 ) {
872 +        tim397_unpage();
873 +      }
874 +    } else if( PC == 0x0000 || PC == 0x0008 ) {
875 +      tim397_page();
876 +    }
877 +
878 +    END_CHECK
879  
880      CHECK( plusd, plusd_available )
881  
This page took 0.215925 seconds and 3 git commands to generate.