-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSystem.h
179 lines (142 loc) · 3.96 KB
/
System.h
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/dos.h>
#include <dos/dos.h>
#include <exec/execbase.h>
#include <exec/memory.h>
#include <hardware/cia.h>
#include <hardware/custom.h>
#include <hardware/dmabits.h>
#include <hardware/intbits.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/view.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <devices/timer.h>
#include <devices/input.h>
#include <proto/timer.h>
#include <clib/exec_protos.h>
#define GETLONG(var) (*(volatile ULONG*)&var)
#define BPL0 (26 * 2) + 1
#define BPL1 (28 * 2) + 1
#define BPL2 (30 * 2) + 1
#define BPL3 (32 * 2) + 1
#define BPL4 (34 * 2) + 1
#define BPL5 (36 * 2) + 1
#define SPR1 (10 * 2) + 1
#define BITMAPLINEBYTES 40
#define BITMAPLINEBYTESI 40
#define BITMAPLINEBYTESB 38
#define CWIDTH 320
#define CHEIGHT 180
#define CWIDTH2 160
#define CHEIGHT2 90
#define WIDTH 320
#define HEIGHT 180
UWORD *cop1, *cop2;
UWORD GetVBR[] = {0x4e7a, 0x0801, 0x4e73}; // MOVEC.L VBR,D0 RTE
extern struct ExecBase *SysBase;
struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;
struct copinit *oldCopinit;
struct ViewPort *oldViewPort;
struct CIA *cia = (struct CIA *) 0xBFE001;
struct Custom *custom = (struct Custom *)0xdff000;
struct MsgPort *inputMP;
struct IOStdReq *inputReq;
struct Interrupt inputHandler;
BYTE inputDevice = -1;
#ifdef IEEESP
struct Library *MathIeeeSingBasBase;
struct Library *MathIeeeSingTransBase;
#else
struct Library *MathBase;
struct Library *MathTransBase;
#endif
UBYTE NameString[]="InputHandlerBugas";
static ULONG vbcounter = 0;
static ULONG vbinc = 0;
static ULONG cvb = 0;
static ULONG cvbinc = 0;
struct Interrupt *vbint = NULL;
UWORD oldInt, oldDMA;
struct View *oldview;
ULONG vposr;
void *vbr;
UBYTE palflag;
ULONG clist[2];
UBYTE *bplptr[2];
ULONG clearColor = 0;
BYTE dbcount = 0;
#define waitVBlank() \
do { \
vposr = GETLONG(custom->vposr); \
} while ((vposr & 0x1FF00) >= 0x12F00); \
do { \
vposr = GETLONG(custom->vposr); \
} while ((vposr & 0x1FF00) < 0x12F00); \
#define WaitBlitter() while (GETLONG(custom->dmaconr) & DMAF_BLTDONE){}
static LONG __interrupt __saveds VBServer(void) {
vbcounter++;
vbinc++;
return 0;
}
static LONG __interrupt __saveds NullInputHandler(void)
{
return 0;
}
int installVBInterrupt(void)
{
if(vbint = AllocMem(sizeof(struct Interrupt), MEMF_PUBLIC|MEMF_CLEAR)) {
vbint->is_Node.ln_Type = NT_INTERRUPT;
vbint->is_Node.ln_Pri = -60;
vbint->is_Node.ln_Name = "VB-Bugas";
vbint->is_Data = (APTR)&vbcounter;
vbint->is_Code = (VOID (*)())VBServer;
AddIntServer(INTB_VERTB, vbint);
}
else {
printf("Not enough memory.\n");
return 0;
}
return 1;
}
void removeVBInterrupt(void)
{
RemIntServer(INTB_VERTB, vbint);
FreeMem(vbint, sizeof(struct Interrupt));
}
void installInputHandler(void) {
if ((inputMP = CreateMsgPort()))
{
if ((inputReq = CreateIORequest(inputMP, sizeof(*inputReq))))
{
inputDevice = OpenDevice("input.device", 0, (struct IORequest *)inputReq, 0);
if (inputDevice == 0)
{
inputHandler.is_Node.ln_Type = NT_INTERRUPT;
inputHandler.is_Node.ln_Pri = 127;
inputHandler.is_Data = 0;
inputHandler.is_Code = (APTR)NullInputHandler;
inputHandler.is_Node.ln_Name=NameString;
inputReq->io_Command = IND_ADDHANDLER;
inputReq->io_Data = &inputHandler;
DoIO((struct IORequest *)inputReq);
}
}
}
}
void removeInputHandler(void) {
if (inputDevice == 0)
{
inputReq->io_Data = &inputHandler;
inputReq->io_Command = IND_REMHANDLER;
DoIO((struct IORequest *)inputReq);
CloseDevice((struct IORequest *)inputReq);
}
if (inputReq)
DeleteIORequest(inputReq);
if (inputMP)
DeleteMsgPort(inputMP);
}