Skip to content

Commit

Permalink
Make it be both an executable and resident module
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikaxelsson committed Oct 31, 2022
1 parent 2d14332 commit 2d5ca5f
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 40 deletions.
20 changes: 14 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
all: NoClick NoClick.mos NoClick.os4

NoClick: NoClick.c Makefile
vc +aos68k -nostdlib -c99 -O1 -sc -D__NOLIBBASE__ -o $@ $<
# The order of the files given to the compiler is important as this order
# will be kept in the resulting executable.
# The file containing the startup function must be first as AmigaOS simply
# starts executing from the start of the first hunk. Then to make it as
# efficient as possible to load this as a resident, the Resident structure
# is placed next, followed by the actual code for the patch and then ending
# it with an empty function used to point/skip to the end in Resident
# structure.
NoClick: Startup.c Resident.c ResidentInit.c NoClick.c ResidentEnd.c ResidentInit.h NoClick.h ResidentEnd.h Makefile
vc +aos68k -nostdlib -O1 -sc -D__NOLIBBASE__ -o $@ Startup.c Resident.c ResidentInit.c NoClick.c ResidentEnd.c

NoClick.mos: NoClick.c Makefile
vc +morphos -nostdlib -O1 -sd -D__NOLIBBASE__ -o $@ $<
NoClick.mos: Startup.c Resident.c ResidentInit.c NoClick.c ResidentEnd.c ResidentInit.h NoClick.h ResidentEnd.h Makefile
vc +morphos -nostdlib -O1 -sd -use-lmw -D__NOLIBBASE__ -o $@ Startup.c Resident.c ResidentInit.c NoClick.c ResidentEnd.c

NoClick.os4: NoClick.c Makefile
vc +aosppc -nostdlib -O1 -sd -D__USE_INLINE__ -D__NOLIBBASE__ -D__NOGLOBALIFACE__ -o $@ $<
NoClick.os4: Startup.c Resident.c ResidentInit.c NoClick.c ResidentEnd.c ResidentInit.h NoClick.h ResidentEnd.h Makefile
vc +aosppc -nostdlib -O1 -sd -use-lmw -D__USE_INLINE__ -D__NOLIBBASE__ -D__NOGLOBALIFACE__ -o $@ Startup.c Resident.c ResidentInit.c NoClick.c ResidentEnd.c

clean:
$(RM) NoClick NoClick.mos NoClick.os4
40 changes: 6 additions & 34 deletions NoClick.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,15 @@

#include <proto/exec.h>

const char Version[] = "$VER: NoClick 1.2 (16.3.2019) by Patrik Axelsson";

#if defined(__MORPHOS__)
ULONG __abox__ = 1;
#endif

#if defined(__amigaos4__)
// Must be named _start in AmigaOS4 binaries.
__saveds int32 _start(STRPTR args, int32 argsLength, struct ExecBase *sysBase) {
struct ExecIFace *IExec = (struct ExecIFace *) sysBase->MainInterface;
IExec->Obtain();
void NoClick(struct ExecIFace *IExec) {
#elif defined(__MORPHOS__)
void NoClick(struct ExecBase *SysBase) {
#else
// In 68k AmigaOS and MorphOS binaries, the symbol name doesn't matter, it just have to be first.
__saveds LONG NoClick(void) {
struct ExecBase *SysBase = *(struct ExecBase **) 4;
// Putting SysBase in a6 is not necessary here, it is just to make vbcc
// produce simpler/better code.
void NoClick(__reg("a6") struct ExecBase *SysBase) {
#endif

struct WBStartup *wbStartupMsg = NULL;
struct Process *thisProcess = (struct Process *) FindTask(NULL);
if(MKBADDR(NULL) == thisProcess->pr_CLI) {
// If started from Workbench, get the startup message
WaitPort(&thisProcess->pr_MsgPort);
wbStartupMsg = (struct WBStartup *) GetMsg(&thisProcess->pr_MsgPort);
}

struct MsgPort *trackDiskPort = CreateMsgPort();
for(ULONG i = 0; i < NUMUNITS; i++) {
struct IOExtTD *trackDiskReq = (struct IOExtTD *) CreateIORequest(trackDiskPort, sizeof(struct IOExtTD));
Expand All @@ -45,16 +29,4 @@ __saveds LONG NoClick(void) {
}
}
DeleteMsgPort(trackDiskPort);

if(NULL != wbStartupMsg) {
Forbid();
// If started from Workbench, reply to the startup message
ReplyMsg((struct Message *) wbStartupMsg);
}

#if defined(__amigaos4__)
IExec->Release();
#endif

return RETURN_OK;
}
16 changes: 16 additions & 0 deletions NoClick.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef _NOCLICK_H_
#define _NOCLICK_H_

#include <exec/execbase.h>

#if defined(__amigaos4__)
void NoClick(struct ExecIFace *IExec);
#elif defined(__MORPHOS__)
void NoClick(struct ExecBase *SysBase);
#else
// Putting SysBase in a6 is not necessary here, it is just to make vbcc
// produce simpler/better code.
void NoClick(__reg("a6") struct ExecBase *SysBase);
#endif

#endif
23 changes: 23 additions & 0 deletions Resident.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <exec/resident.h>

#include "ResidentEnd.h"
#include "ResidentInit.h"

const struct Resident ROMTag = {
.rt_MatchWord = RTC_MATCHWORD,
.rt_MatchTag = (void *) &ROMTag,
.rt_EndSkip = (void *) &EndVariable,
#if defined(__amigaos4__)
.rt_Flags = RTF_COLDSTART | RTF_NATIVE,
#elif defined(__MORPHOS__)
.rt_Flags = RTF_COLDSTART | RTF_PPC,
#else
.rt_Flags = RTF_COLDSTART,
#endif
.rt_Version = 2,
.rt_Type = NT_UNKNOWN, // We just want to run rt_Init
.rt_Pri = 0, // Need to be initialized later than trackdisk at 20
.rt_Name = "NoClick",
.rt_IdString = "NoClick 2.0 (31.10.2022) by Patrik Axelsson",
.rt_Init = (void *) &ResidentInit
};
3 changes: 3 additions & 0 deletions ResidentEnd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This variable is just used as a reference to skip to the end when it is
// scanned for Resident structures.
const int EndVariable = 0;
6 changes: 6 additions & 0 deletions ResidentEnd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef _RESIDENTEND_H_
#define _RESIDENTEND_H_

extern const int EndVariable;

#endif
24 changes: 24 additions & 0 deletions ResidentInit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <exec/execbase.h>
#include <dos/dos.h>
#include <devices/trackdisk.h>

#include <proto/exec.h>

#include "NoClick.h"

#if defined(__amigaos4__)
__saveds void ResidentInit(void *zero, BPTR segList, struct ExecBase *sysBase) {
struct ExecIFace *IExec = (void *) sysBase->MainInterface;
IExec->Obtain();
NoClick(IExec);
IExec->Release();
}
#elif defined(__MORPHOS__)
__saveds void ResidentInit(void *zero, BPTR segList, struct ExecBase *SysBase) {
NoClick(SysBase);
}
#else
__saveds void ResidentInit(__reg("d0") void *zero, __reg("a0") BPTR segList, __reg("a6") struct ExecBase *SysBase) {
NoClick(SysBase);
}
#endif
15 changes: 15 additions & 0 deletions ResidentInit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _RESIDENTINIT_H_
#define _RESIDENTINIT_H_

#include <exec/execbase.h>
#include <dos/dos.h>

#if defined(__amigaos4__)
__saveds void ResidentInit(void *zero, BPTR segList, struct ExecBase *sysBase);
#elif defined(__MORPHOS__)
__saveds void *ResidentInit(void *zero, BPTR segList, struct ExecBase *SysBase);
#else
__saveds void *ResidentInit(__reg("d0") void *zero, __reg("a0") BPTR segList, __reg("a6") struct ExecBase *SysBase);
#endif

#endif
53 changes: 53 additions & 0 deletions Startup.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <exec/exec.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <workbench/startup.h>

#include <proto/exec.h>
#include <proto/dos.h>

#include "NoClick.h"


#if defined(__MORPHOS__)
ULONG __abox__ = 1;
#endif

#if defined(__amigaos4__)
// Must be named _start in AmigaOS4 binaries.
__saveds int32 _start(STRPTR args, int32 argsLength, struct ExecBase *sysBase) {
struct ExecIFace *IExec = (struct ExecIFace *) sysBase->MainInterface;
IExec->Obtain();
#else
// In 68k AmigaOS and MorphOS binaries, the symbol name doesn't matter, it just have to be first.
__saveds LONG Startup(void) {
struct ExecBase *SysBase = *(struct ExecBase **) 4;
#endif

struct WBStartup *wbStartupMsg = NULL;
struct Process *thisProcess = (struct Process *) FindTask(NULL);
if (0 == thisProcess->pr_CLI) {
// If started from Workbench, get the startup message
WaitPort(&thisProcess->pr_MsgPort);
wbStartupMsg = (void *) GetMsg(&thisProcess->pr_MsgPort);
}

#if defined(__amigaos4__)
NoClick(IExec);
#else
NoClick(SysBase);
#endif

if(NULL != wbStartupMsg) {
// This is so Workbench won't unload our segment before we exit
Forbid();
// If started from Workbench, reply to the startup message
ReplyMsg((void *) wbStartupMsg);
}

#if defined(__amigaos4__)
IExec->Release();
#endif

return RETURN_OK;
}

0 comments on commit 2d5ca5f

Please sign in to comment.