Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

i_opencbm_vice.c

Go to the documentation of this file.
00001 /*
00002  *      This program is free software; you can redistribute it and/or
00003  *      modify it under the terms of the GNU General Public License
00004  *      as published by the Free Software Foundation; either version
00005  *      2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 2005 Spiro Trikaliotis
00008  *
00009  *  Parts are Copyright
00010  *      Jouko Valta <jopi(at)stekt(dot)oulu(dot)fi>
00011  *      Andreas Boose <boose(at)linux(dot)rz(dot)fh-hannover(dot)de>
00012 */
00013 
00026 #include <windows.h>
00027 #include <windowsx.h>
00028 
00030 #define DBG_USERMODE
00031 
00033 #ifndef DBG_PROGNAME
00034     #define DBG_PROGNAME "OPENCBM.DLL"
00035 #endif // #ifndef DBG_PROGNAME
00036 
00037 #include "debug.h"
00038 
00039 #include <winioctl.h>
00040 #include "cbmioctl.h"
00041 
00042 #include <stdlib.h>
00043 #include <stddef.h>
00044 
00045 #include "i_opencbm.h"
00046 
00047 #include "version.h"
00048 #include "archlib.h"
00049 
00050 #include "vice_comm.h"
00051 
00052 /*-------------------------------------------------------------------*/
00053 /*--------- REGISTRY FUNCTIONS --------------------------------------*/
00054 
00076 LONG
00077 RegGetDWORD(IN HKEY RegKey, IN char *SubKey, OUT LPDWORD Value)
00078 {
00079     DWORD valueLen;
00080     DWORD lpType;
00081     DWORD value;
00082     DWORD rc;
00083 
00084     FUNC_ENTER();
00085 
00086     FUNC_PARAM((DBG_PREFIX "Subkey = '%s'", SubKey));
00087 
00088     valueLen = sizeof(value);
00089 
00090     rc = RegQueryValueEx(RegKey, SubKey, NULL, &lpType, (LPBYTE)&value, &valueLen);
00091 
00092     DBG_ASSERT(valueLen == 4);
00093 
00094     if ((rc == ERROR_SUCCESS) && (valueLen == 4))
00095     {
00096         DBG_SUCCESS((DBG_PREFIX "RegGetDWORD"));
00097         *Value = value;
00098     }
00099     else
00100     {
00101         DBG_ERROR((DBG_PREFIX "RegGetDWORD failed, returning -1"));
00102         rc = -1;
00103     }
00104 
00105     FUNC_LEAVE_INT(rc);
00106 }
00107 
00108 
00122 static int
00123 cbm_get_default_port(VOID)
00124 {
00125     FUNC_ENTER();
00126     FUNC_LEAVE_INT(0);
00127 }
00128 
00129 #if DBG
00130 
00137 VOID
00138 cbm_i_get_debugging_flags(VOID)
00139 {
00140     DWORD ret;
00141     HKEY RegKey;
00142 
00143     FUNC_ENTER();
00144 
00145     // Open a registry key to HKLM<%REGKEY_SERVICE%>
00146 
00147     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
00148                      CBM_REGKEY_SERVICE,
00149                      0,
00150                      KEY_QUERY_VALUE,
00151                      &RegKey)
00152        )
00153     {
00154         DBG_WARN((DBG_PREFIX "RegOpenKeyEx() failed!"));
00155         FUNC_LEAVE();
00156     }
00157 
00158     // now, get the number of the port to use
00159 
00160     if (RegGetDWORD(RegKey, CBM_REGKEY_SERVICE_DLL_DEBUGFLAGS, &ret) != ERROR_SUCCESS)
00161     {
00162         DBG_WARN((DBG_PREFIX "No " CBM_REGKEY_SERVICE "\\" CBM_REGKEY_SERVICE_DLL_DEBUGFLAGS
00163             " value, leaving default."));
00164     }
00165     else
00166     {
00167         DbgFlags = ret;
00168     }
00169 
00170     // We're done, close the registry handle.
00171 
00172     RegCloseKey(RegKey);
00173 
00174     FUNC_LEAVE();
00175 }
00176 
00177 #endif // #if DBG
00178 
00195 const char *
00196 cbmarch_get_driver_name(int PortNumber)
00197 {
00199     static char driverName[] = "opencbm-vice";
00200 
00201     FUNC_ENTER();
00202 
00203     FUNC_LEAVE_STRING(driverName);
00204 }
00205 
00226 int
00227 cbmarch_driver_open(CBM_FILE *HandleDevice, int PortNumber)
00228 {
00229     const unsigned char sys[] = "SYS8192\r";
00230     const unsigned char syslen = sizeof(sys)-1;
00231 
00232     const unsigned char buffer[] = { 
00233         0x4c, 0x00, 0x20    // 2000 JMP $2000
00234     };
00235 
00236     int success;
00237 
00238     FUNC_ENTER();
00239 
00240     success = viceinit();
00241 
00242     if (success)
00243     {
00244         vicepause();
00245         vicewritememory(0x2000, sizeof(buffer), buffer);
00246         viceresume();
00247         vicewaittrap();
00248 
00249         vicepause();
00250         vicewritememory(631, syslen, sys);
00251         viceresume();
00252         vicewaittrap();
00253 
00254         vicepause();
00255         vicewritememory(198, 1, &syslen);
00256         viceresume();
00257         vicewaittrap();
00258     }
00259 
00260     FUNC_LEAVE_INT(success ? 0 : 1);
00261 }
00262 
00277 void
00278 cbmarch_driver_close(CBM_FILE HandleDevice)
00279 {
00280     FUNC_ENTER();
00281 
00282     vicerelease();
00283 
00284     FUNC_LEAVE();
00285 }

Generated on Sun Apr 30 18:45:52 2006 for opencbm by  doxygen 1.4.2