2 * Copyright 2020-2021 Niklas Ekström
5 #include <exec/types.h>
6 #include <exec/execbase.h>
7 #include <exec/devices.h>
8 #include <exec/errors.h>
9 #include <exec/ports.h>
10 #include <libraries/dos.h>
11 #include <proto/exec.h>
16 #include "fix_mem_region.h"
18 char device_name[] = A314_NAME;
19 char id_string[] = A314_NAME " 1.1 (28 Nov 2020)";
21 struct ExecBase *SysBase;
25 static struct Library *init_device(__reg("a6") struct ExecBase *sys_base, __reg("a0") BPTR seg_list, __reg("d0") struct Library *dev)
27 SysBase = *(struct ExecBase **)4;
28 saved_seg_list = seg_list;
30 // We are being called from InitResident() in initializers.asm.
31 // MakeLibrary() was executed before we got here.
33 dev->lib_Node.ln_Type = NT_DEVICE;
34 dev->lib_Node.ln_Name = device_name;
35 dev->lib_Flags = LIBF_SUMUSED | LIBF_CHANGED;
37 dev->lib_Revision = 0;
38 dev->lib_IdString = (APTR)id_string;
40 // AddDevice() is executed after we return.
44 static BPTR expunge(__reg("a6") struct Library *dev)
46 // There is currently no support for unloading a314.device.
48 if (TRUE) //dev->lib_OpenCnt != 0)
50 dev->lib_Flags |= LIBF_DELEXP;
55 BPTR seg_list = saved_seg_list;
56 Remove(&dev->lib_Node);
57 FreeMem((char *)dev - dev->lib_NegSize, dev->lib_NegSize + dev->lib_PosSize);
62 static void open(__reg("a6") struct Library *dev, __reg("a1") struct A314_IORequest *ior, __reg("d0") ULONG unitnum, __reg("d1") ULONG flags)
66 if (dev->lib_OpenCnt == 1 && !running)
70 ior->a314_Request.io_Error = IOERR_OPENFAIL;
71 ior->a314_Request.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
78 ior->a314_Request.io_Error = 0;
79 ior->a314_Request.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
82 static BPTR close(__reg("a6") struct Library *dev, __reg("a1") struct A314_IORequest *ior)
84 ior->a314_Request.io_Device = NULL;
85 ior->a314_Request.io_Unit = NULL;
89 if (dev->lib_OpenCnt == 0 && (dev->lib_Flags & LIBF_DELEXP))
95 static void begin_io(__reg("a6") struct Library *dev, __reg("a1") struct A314_IORequest *ior)
97 PutMsg(&task_mp, (struct Message *)ior);
98 ior->a314_Request.io_Flags &= ~IOF_QUICK;
101 static ULONG abort_io(__reg("a6") struct Library *dev, __reg("a1") struct A314_IORequest *ior)
103 // There is currently no support for aborting an IORequest.
107 static ULONG device_vectors[] =
115 (ULONG)translate_address_a314,
119 ULONG auto_init_tables[] =
121 sizeof(struct Library),
122 (ULONG)device_vectors,