summaryrefslogtreecommitdiff
path: root/expansionoff.c
blob: c0aab8162f63a14709ba394ffe88661cafe09ea1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
  disable Zorro-II/III Expansions by software
  
  (C) 2019 Henryk Richter

  This tool can either mark expansions as invalid
  (Shutup flag) or remove them from the active expansion
  board list. Please note that this is in software
  only and won't help if the hidden (presumably broken)
  devices interfere with the operation of other boards.

  A more reliable way to disable Zorro devices would
  need to patch expansion.library, which is beyond the
  scope of this tool.

  compilation:
   m68k-amigaos-gcc expansionoff.c -o expansionoff -noixemul -Wall -s
  or 
   sc expansionoff.c link

*/
#include <string.h>
#include <dos/dos.h>
#include <dos/exall.h>
#include <proto/dos.h>
#include <exec/memory.h>
#include <proto/exec.h>
#include <libraries/expansion.h>
#include <libraries/configvars.h>
#define __NOLIBBASE__
#include <proto/expansion.h>


struct Library *ExpansionBase; /* struct ExpansionBase *ExpansionBase; */

/* don't use amiga.lib */
#define REMOVE(n)        ((void)(\
        ((struct Node *)n)->ln_Pred->ln_Succ = ((struct Node *)n)->ln_Succ,\
        ((struct Node *)n)->ln_Succ->ln_Pred = ((struct Node *)n)->ln_Pred ))


/*----------------- options template -----------------------------------------*/
#define OPT_TEMPLATE "MANUFACTURER=VENDOR/K/N/A,DEVICE=DEV/K/N/A,SHUTUP=S/S,REMOVE=R/S"

struct progopts {
	ULONG *vendor;
	ULONG *dev;
	ULONG shutup;
	ULONG remove;
};
const char opt_template[];

int main( int argc, char**argv )
{
	struct progopts opts;
	struct RDArgs *rdargs;
	ULONG syntax;
	ULONG rcount=0,scount=0;
	struct ConfigDev *cfg = (0),*cfg2;

	ExpansionBase = OpenLibrary( (STRPTR)EXPANSIONNAME, 34 );
	if( !ExpansionBase )
	{
		Printf("Cannot open expansion.library v34\n");
		return 10;
	}

	do 
	{
		memset( &opts, 0, sizeof( struct progopts ));
		syntax=1;
		if( (rdargs = ReadArgs( (char*)opt_template,(LONG*)&opts,NULL) ) )
		{
			if( (opts.vendor) && (opts.dev) )
				syntax = 0;	
		}

		if( syntax )
		{
		   Printf("Syntax: %s\n",(ULONG)opt_template);
		   break;
		}

		cfg = FindConfigDev( cfg, *opts.vendor, *opts.dev );
		if( !cfg )
		{
		   Printf("Board %ld %ld not found\n",*opts.vendor, *opts.dev);
		   break;
		}

		while( (cfg) )
		{
		   cfg2 = FindConfigDev( cfg, *opts.vendor, *opts.dev );
		   
		   if( opts.remove )
		   {
			Disable();
			REMOVE(cfg);
			Enable();
			rcount++;
			Printf("rem\n");
		   }
		   else
		   {
			cfg->cd_Flags |= CDF_SHUTUP;
			scount++;
		   }

		   cfg = cfg2;
		}
	}
	while(0);

	Printf("Done. Removed %ld boards, Shutup %ld boards\n",rcount,scount);

	if( rdargs ) FreeArgs(rdargs);

	CloseLibrary( (struct Library*)ExpansionBase );
	return 0;
}

/* some strings down here */
const char opt_template[] = OPT_TEMPLATE;
const char verstring[] = "$VER: expansionoff 1.0 (03.06.2019) Disable Zorro Expansions (C) Henryk Richter";