1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
28 #define __EXEC_NOLIBBASE__
29 #define __DOS_NOLIBBASE__
32 #define USED_PLUGIN_API_VERSION 8
33 #include <devices/diskimage.h>
34 #include <proto/exec.h>
35 #include <proto/dos.h>
37 #include "device_locale.h"
38 #include <SDI_compiler.h>
39 #include "rev/diskimage.device_rev.h"
43 extern struct DiskImagePlugin d64_plugin
;
45 PLUGIN_TABLE(&d64_plugin
)
54 BOOL
D64_Init (struct DiskImagePlugin
*Self
, const struct PluginData
*data
);
55 BOOL
D64_CheckImage (struct DiskImagePlugin
*Self
, BPTR file
, CONST_STRPTR name
, QUAD file_size
,
56 const UBYTE
*test
, LONG testsize
);
57 APTR
D64_OpenImage (struct DiskImagePlugin
*Self
, APTR unit
, BPTR file
, CONST_STRPTR name
);
58 void Generic_CloseImage (struct DiskImagePlugin
*Self
, APTR image_ptr
);
59 LONG
Generic_Geometry (struct DiskImagePlugin
*Self
, APTR image_ptr
, struct DriveGeometry
*dg
);
60 LONG
Generic_Read (struct DiskImagePlugin
*Self
, APTR image_ptr
, struct IOStdReq
*io
);
61 LONG
Generic_Write (struct DiskImagePlugin
*Self
, APTR image_ptr
, struct IOStdReq
*io
);
63 struct DiskImagePlugin d64_plugin
= {
64 PLUGIN_NODE(-126, "D64"),
83 static struct Library
*SysBase
;
84 static struct Library
*DOSBase
;
85 static struct DIPluginIFace
*IPlugin
;
87 BOOL
D64_Init (struct DiskImagePlugin
*Self
, const struct PluginData
*data
) {
88 SysBase
= data
->SysBase
;
89 DOSBase
= data
->DOSBase
;
90 IPlugin
= data
->IPlugin
;
94 BOOL
D64_CheckImage (struct DiskImagePlugin
*Self
, BPTR file
, CONST_STRPTR name
, QUAD file_size
,
95 const UBYTE
*test
, LONG testsize
)
108 APTR
D64_OpenImage (struct DiskImagePlugin
*Self
, APTR unit
, BPTR file
, CONST_STRPTR name
) {
110 LONG error
= NO_ERROR
;
112 struct D64Image
*image
= NULL
;
114 file_size
= GetFileSize(file
);
115 if (file_size
== -1) {
120 /* some .d64 disk images have extra data at the end of the file */
131 error
= ERROR_OBJECT_WRONG_TYPE
;
135 image
= AllocVec(sizeof(*image
), MEMF_CLEAR
);
137 error
= ERROR_NO_FREE_STORE
;
141 image
->total_bytes
= file_size
;
143 image
->block_size
= 256;
144 image
->total_blocks
= image
->total_bytes
>> 8;
151 Plugin_CloseImage(Self
, image
);
156 IPlugin_SetDiskImageError(unit
, error
, 0);