2 * Copyright (C) Prikol Software 1996-1997
3 * Copyright (C) Aleksey Volynskov 1996-1997
4 * Copyright (C) <ARembo@gmail.com> 2011
5 * Copyright (C) fgsfds 2019
7 * This file is part of the Doom2D PSX project.
9 * Doom2D PSX is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * Doom2D PSX is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/> or
20 * write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
40 #include <sys/types.h>
46 // length of morse stuff in vblanks
52 #define SINADDR 0x1100
53 #define SINCH SPU_16CH
55 // ERR_ messages are now defined in error.h
57 extern SpuVoiceAttr chanattr
;
59 static const u_char morse
[][5] = {
61 { DAH
, DAH
, DAH
, DAH
, DAH
, }, // 0
62 { DIT
, DAH
, DAH
, DAH
, DAH
, }, // 1
63 { DIT
, DIT
, DAH
, DAH
, DAH
, }, // 2
64 { DIT
, DIT
, DIT
, DAH
, DAH
, }, // 3
65 { DIT
, DIT
, DIT
, DIT
, DAH
, }, // 4
66 { DIT
, DIT
, DIT
, DIT
, DIT
, }, // 5
67 { DAH
, DIT
, DIT
, DIT
, DIT
, }, // 6
68 { DAH
, DAH
, DIT
, DIT
, DIT
, }, // 7
69 { DAH
, DAH
, DAH
, DIT
, DIT
, }, // 8
70 { DAH
, DAH
, DAH
, DAH
, DIT
, }, // 9
73 { DAH
, DIT
, DIT
, DIT
, }, // B
74 { DAH
, DIT
, DAH
, DIT
, }, // C
75 { DAH
, DIT
, DIT
, }, // D
77 { DIT
, DIT
, DAH
, DIT
, }, // F
78 { DAH
, DAH
, DIT
, }, // G
79 { DIT
, DIT
, DIT
, DIT
, }, // H
81 { DIT
, DAH
, DAH
, DAH
, }, // J
82 { DAH
, DIT
, DAH
, }, // K
83 { DIT
, DAH
, DIT
, DIT
, }, // L
86 { DAH
, DAH
, DAH
, }, // O
87 { DIT
, DAH
, DAH
, DIT
, }, // P
88 { DAH
, DAH
, DIT
, DAH
, }, // Q
89 { DIT
, DAH
, DIT
, }, // R
90 { DIT
, DIT
, DIT
, }, // S
92 { DIT
, DIT
, DAH
, }, // U
93 { DIT
, DIT
, DIT
, DAH
, }, // V
94 { DIT
, DAH
, DAH
, }, // W
95 { DAH
, DIT
, DIT
, DAH
, }, // X
96 { DAH
, DIT
, DAH
, DAH
, }, // Y
97 { DAH
, DAH
, DIT
, DIT
, }, // Z
100 static const u_char sinewave
[] = {
101 0x26, 0x06, 0x30, 0x10, 0x01, 0x11, 0x01, 0x21,
102 0x10, 0x21, 0x20, 0x11, 0x21, 0x11, 0x12, 0x21,
103 0x27, 0x02, 0x24, 0x33, 0x34, 0x43, 0x33, 0x44,
104 0x33, 0x35, 0x53, 0x43, 0x34, 0x35, 0x44, 0x44,
105 0x27, 0x02, 0x34, 0x35, 0x35, 0x44, 0x44, 0x34,
106 0x35, 0x44, 0x34, 0x44, 0x43, 0x43, 0x34, 0x43,
107 0x27, 0x02, 0x33, 0x24, 0x34, 0x33, 0x42, 0x32,
108 0x23, 0x23, 0x32, 0x22, 0x13, 0x22, 0x12, 0x22,
109 0x28, 0x02, 0x32, 0x32, 0x22, 0x22, 0x21, 0x20,
110 0x01, 0x01, 0x00, 0x00, 0x0f, 0x0e, 0xef, 0xfe,
111 0x27, 0x02, 0xff, 0xef, 0xff, 0xef, 0xfe, 0xfd,
112 0xee, 0xee, 0xfd, 0xdd, 0xde, 0xde, 0xdd, 0xce,
113 0x27, 0x02, 0xce, 0xdd, 0xdd, 0xdc, 0xcd, 0xdc,
114 0xcd, 0xdc, 0xcc, 0xdc, 0xcc, 0xcc, 0xbd, 0xcd,
115 0x27, 0x02, 0xdb, 0xcc, 0xdc, 0xcb, 0xcd, 0xdb,
116 0xdc, 0xdb, 0xcc, 0xcd, 0xdc, 0xcc, 0xdd, 0xdc,
117 0x27, 0x02, 0xcd, 0xdd, 0xdd, 0xec, 0xdd, 0xed,
118 0xdd, 0xee, 0xdd, 0xdf, 0xdf, 0xfe, 0xee, 0xfe,
119 0x28, 0x03, 0xce, 0xde, 0xee, 0xfe, 0xee, 0xe0,
120 0xf0, 0x0f, 0x00, 0x10, 0x00, 0x02, 0x12, 0x12,
125 // shits out an error message and locks up
126 void ERR_panic(char *msg
) {
127 RECT clearRect
= { 0, 0, SCRW
, SCRH
*2 };
132 SpuSetKey(SPU_OFF
, SPU_ALLCH
);
138 SetDefDispEnv(&disp
, 0, 0, SCRW
, SCRH
);
139 disp
.isinter
= disp
.isrgb24
= 0;
140 disp
.screen
.y
= SCRY
;
141 disp
.screen
.h
= SCRH
;
142 SetDefDrawEnv(&draw
, 0, 0, SCRW
, SCRH
);
146 ClearImage(&clearRect
, 80, 0, 0);
151 printf("FATAL ERROR: %s\n", msg
);
155 SpuSetTransferMode(SpuTransByDMA
);
156 SpuSetTransferStartAddr(SINADDR
);
157 SpuWrite((u_char
*)sinewave
, sizeof(sinewave
));
158 SpuIsTransferCompleted(SPU_TRANSFER_WAIT
);
162 chanattr
.voice
= SINCH
;
163 chanattr
.mask
= SPU_VOICE_VOLL
| SPU_VOICE_VOLR
| SPU_VOICE_WDSA
|
165 chanattr
.addr
= SINADDR
;
166 chanattr
.pitch
= 0x3FFF;
167 chanattr
.volume
.left
= chanattr
.volume
.right
= 0x2FFF;
168 SpuSetVoiceAttr(&chanattr
);
173 // have to do this because regular VSync(n) tends to time out and die
174 #define VSYNCN(x) t = x; while (t-- > 0) VSync(0)
178 for (i
= 0; i
< 256 && msg
[i
]; ++i
) {
179 int c
= toupper(msg
[i
]);
182 if (c
>= '0' && c
<= '9')
184 else if (c
>= 'A' && c
<= 'Z')
187 c
= 'M' - 'A' + 10; // `M`inus
193 for (j
= 0; j
< 5 && morse
[c
][j
]; ++j
) {
194 SpuSetKey(SPU_ON
, SINCH
);
196 SpuSetKey(SPU_OFF
, SINCH
);
205 void ERR_close_all(void) {
214 void ERR_quit(void) {
218 // if(!(p=malloc(4000)))
219 puts("ERR_quit()\n");
221 // F_loadres(F_getresid("ENDOOM"),p,0,4000);
222 // memcpy((void*)0xB8000,p,4000);free(p);gotoxy(1,24);