-
Notifications
You must be signed in to change notification settings - Fork 1
/
palpal.c
195 lines (158 loc) · 4.79 KB
/
palpal.c
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -*- coding: shift_jis -*-
*
* Copyright (C) 1994 HIRATA Yasuyuki <[email protected]>,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR (HIRATA Yasuyuki) ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdlib.h>
#include <dos.h>
#include "gr.h"
#include "dos.h"
#include "timer.h"
#include "tsr.h"
#include "yasu.h"
#define PALPALVER "0.01"
#define IDOFS 0x0080
#define IDSTR "$$PALPAL$$"
#define INTERVAL 10
void interrupt palpal(UINT bp, UINT di, UINT si, UINT ds, UINT es,
UINT dx, UINT cx, UINT bx, UINT ax);
void palpal_stay(void);
void palpal_remove(void);
void usage(void);
void error_exit(const char *msg);
extern UINT _heaplen=1; /* 最低値(0だと64kB指定) */
extern UINT _stklen=0x100; /* 少なくしておく */
extern WORD __heapbase; /* HEAPの開始オフセット */
int main(int argc, char **argv)
{
const static char msg[]=
"This is palpal, TSR Version " PALPALVER "\n"
"Copr. 1993-1994, YASU/Project-NCDW/"
"TOKAI Univ. DAIYON HIGHSCHOOL SUKEN\n"
"All rights reserved.\n";
struct dos_time time;
dos_puts_fast(msg);
if((argc==2)&&(argv[1][0]=='-'))
{
dos_get_time(&time);
srand(time.sec|1);
switch(argv[1][1])
{
case 's': /* 常駐 */
case 'S':
palpal_stay();
break;
case 'r': /* 解除 */
case 'R':
palpal_remove();
break;
default: /* 使用法表示 */
usage();
break;
}
return EXIT_SUCCESS;
}
usage();
return EXIT_SUCCESS;
}
/* 割り込みルーチン */
#pragma warn -par /* 使用していない引数にたいする警告抑止 */
void interrupt palpal(UINT bp, UINT di, UINT si, UINT ds, UINT es,
UINT dx, UINT cx, UINT bx, UINT ax)
{
register int i;
static int col[3]={0, 0, 0}; /* アナログrgbの値 */
static signed int pl[3]={0, 0, 0}; /* 毎回この値をcol[n]に足す */
static int counter=0; /* パレットの値を0--10にするためのカウンター */
counter++;
counter%=11;
if(counter==0)
do
{
for(i=0; i<3; i++)
if(rand()%2)
pl[i]=(col[i]==0)?(+1):(-1);
else
pl[i]=0;
}
while(pl[0]==pl[1]==pl[2]==0);
for(i=0; i<3; i++)
col[i]+=pl[i];
do /* V-SYNC待ち */
asm IN AL,0A0H;
while(!(_AL&0x20));
gr_set_pal(0, col[0], col[1], col[2]);
timer_set(INTERVAL, palpal);
/* インターバルタイマーはワンショットなので再設定 */
return;
}
#pragma warn .par
/* 常駐 */
void palpal_stay(void)
{
if(tsr_is_stayed(IDOFS, IDSTR))
error_exit("already stayed.\n");
if(!dos_remove_env())
error_exit("unable to remove env. area.\n");
gr_init();
*((DWORD far *)MK_FP(_psp, IDOFS+sizeof(IDSTR)))=(DWORD)dos_get_vect(0x07);
dos_puts_fast("stayed on memory.\n");
timer_set(INTERVAL, palpal);
tsr_stay(EXIT_SUCCESS, IDOFS, IDSTR, _DS-_psp+(__heapbase/16+16));
return; /* dummy */
}
/* 解除 */
void palpal_remove(void)
{
WORD seg;
if((seg=tsr_get_stayed_seg(IDOFS, IDSTR))==0x0000)
error_exit("not stayed.\n");
dos_set_vect(0x07,
(void interrupt (*)())(*((DWORD far *)MK_FP(seg, IDOFS+sizeof(IDSTR)))));
if(!tsr_remove(IDOFS, IDSTR))
error_exit("unable to remove from memory.\n");
dos_puts_fast("removed from memory.\n");
gr_set_pal(0, 0, 0, 0);
exit(EXIT_SUCCESS);
return;
}
/* 仕様法表示 */
void usage(void)
{
const char msg[]=
"Usage: palpal <option>\n"
" option: -s stay on memory\n"
" -r remove from memory\n"
" -? print help message";
dos_puts_fast(msg);
return;
}
/* エラー終了 */
void error_exit(const char *msg)
{
dos_puts_fast("error: ");
dos_puts_fast(msg);
exit(EXIT_FAILURE);
}