Skip to content

Commit 60c6296

Browse files
committed
Add bios without logo
1 parent c64fd76 commit 60c6296

8 files changed

Lines changed: 487 additions & 0 deletions

File tree

23.4 KB
Loading
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
// include Vircon libraries
2+
#include "audio.h"
3+
#include "video.h"
4+
#include "time.h"
5+
#include "string.h"
6+
#include "misc.h"
7+
8+
// include project libraries
9+
#include "ErrorInfo.h"
10+
11+
12+
// ---------------------------------------------------------
13+
// GENERAL DEFINITIONS
14+
// ---------------------------------------------------------
15+
16+
17+
// BIOS-required regions; these
18+
// may safely be used by programs
19+
#define first_region_font 0
20+
#define region_white_pixel 256
21+
22+
// other non-required regions, used
23+
// to draw the logo and error screens
24+
#define region_console 300
25+
#define region_cartridge 301
26+
#define region_down_arrow 302
27+
#define region_white_square 303
28+
29+
// colors for error screens
30+
#define error_colors_background 0xFF8D4130
31+
#define error_colors_title color_yellow
32+
#define error_colors_description color_white
33+
#define error_colors_values 0xFF8080FF
34+
35+
36+
// ---------------------------------------------------------
37+
// SUPPORT FUNCTIONS
38+
// ---------------------------------------------------------
39+
40+
41+
void draw_message_screen( error_message* message )
42+
{
43+
clear_screen( error_colors_background );
44+
set_multiply_color( color_white );
45+
select_texture( -1 );
46+
47+
// write title
48+
set_multiply_color( error_colors_title );
49+
print_at( 49, 37, message->title );
50+
51+
// draw horizontal line
52+
select_region( region_white_square );
53+
set_drawing_scale( 640/2, 1 );
54+
draw_region_zoomed_at( 0, 60 );
55+
set_drawing_scale( 1, 1 );
56+
57+
// write description
58+
set_multiply_color( error_colors_description );
59+
print_at( 49, 95, message->description );
60+
}
61+
62+
// ---------------------------------------------------------
63+
64+
void print_hex_value( int x, int y, int* name, int value )
65+
{
66+
// convert the number to hex
67+
int[ 10 ] hex_string;
68+
itoa( value, hex_string, 16 );
69+
70+
// join all text parts
71+
int[ 60 ] text;
72+
strcpy( text, name );
73+
strcat( text, " = 0x" );
74+
strcat( text, hex_string );
75+
76+
// print the text
77+
print_at( x, y, text );
78+
}
79+
80+
// ---------------------------------------------------------
81+
82+
bool cartridge_connected()
83+
{
84+
asm
85+
{
86+
"in R0, CAR_Connected"
87+
}
88+
}
89+
90+
// ---------------------------------------------------------
91+
92+
void request_cartridge()
93+
{
94+
// write a custom message as if it was an error
95+
error_message no_cartridge_message =
96+
{
97+
"NO CARTRIDGE FOUND",
98+
"To play a game, please power off\n"
99+
"your console and insert a game\n"
100+
"cartridge compatible with Vircon32."
101+
};
102+
103+
draw_message_screen( &no_cartridge_message );
104+
105+
// draw console diagram
106+
set_multiply_color( color_white );
107+
select_region( region_console );
108+
draw_region_at( 400, 207 );
109+
110+
select_region( region_cartridge );
111+
draw_region_at( 469, 76 );
112+
113+
select_region( region_down_arrow );
114+
draw_region_at( 497, 149 );
115+
116+
// ensure everything gets drawn
117+
end_frame();
118+
}
119+
120+
121+
// ---------------------------------------------------------
122+
// ERROR HANDLER FUNCTION
123+
// ---------------------------------------------------------
124+
125+
126+
void error_handler()
127+
{
128+
// do not initialize these!
129+
// or else R0 will be overwritten
130+
int error_code;
131+
int instruction_pointer;
132+
int instruction;
133+
int immediate_value;
134+
135+
// save registers to variables
136+
asm
137+
{
138+
"mov {error_code}, R0"
139+
"mov {instruction_pointer}, R1"
140+
"mov {instruction}, R2"
141+
"mov {immediate_value}, R3"
142+
}
143+
144+
// ensure everything gets drawn
145+
end_frame();
146+
147+
// write the appropriate message for this error code
148+
if( error_code >= 0 && error_code < (int)error_unknown )
149+
draw_message_screen( &error_messages[ error_code ] );
150+
151+
else
152+
draw_message_screen( &error_messages[ error_unknown ] );
153+
154+
// now print the related hex values
155+
set_multiply_color( error_colors_values );
156+
print_hex_value( 49, 160, "Instruction Pointer", instruction_pointer );
157+
print_hex_value( 49, 180, "Instruction", instruction );
158+
print_hex_value( 49, 200, "Immediate Value", immediate_value );
159+
160+
// stop any sound
161+
stop_all_channels();
162+
}
163+
164+
165+
// ---------------------------------------------------------
166+
// MAIN FUNCTION
167+
// ---------------------------------------------------------
168+
169+
void main( void )
170+
{
171+
// very small wait before starting,
172+
// to ensure a black screen is seen
173+
clear_screen( color_black );
174+
sleep( 15 );
175+
176+
// ------------------------------------
177+
// PART 1: DEFINE ALL TEXTURE REGIONS
178+
// ------------------------------------
179+
180+
select_texture( -1 );
181+
182+
// all characters of the text font
183+
define_region_matrix( first_region_font, 1,1, 10,20, 1,1, 32,8, 0 );
184+
185+
// white pixel
186+
select_region( region_white_pixel );
187+
define_region_topleft( 315,169, 315,169 );
188+
189+
// console
190+
select_region( region_console );
191+
define_region_topleft( 1,164, 199,299 );
192+
193+
// cartridge
194+
select_region( region_cartridge );
195+
define_region_topleft( 203,164, 284,237 );
196+
197+
// down arrow
198+
select_region( region_down_arrow );
199+
define_region_topleft( 288,164, 311,223 );
200+
201+
// white square
202+
select_region( region_white_square );
203+
define_region_topleft( 315,164, 316,165 );
204+
205+
// ------------------------------------
206+
// PART 7: JUMP TO CARTRIDGE
207+
// ------------------------------------
208+
209+
// if no cartrige is connected, show an alert screen and stop
210+
if( !cartridge_connected() )
211+
{
212+
request_cartridge();
213+
exit();
214+
}
215+
216+
// ensure that any video parameters we might have used
217+
// are restored to their expected defaults at startup
218+
set_multiply_color( color_white );
219+
select_region( 0 );
220+
221+
// jump to first position in cartridge program rom
222+
asm{ "jmp 0x20000000" }
223+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2+
<rom-definition version="1.0">
3+
<rom type="bios" title="Vircon32 BIOS without logo" version="1.0" />
4+
<binary path="obj/BiosWithoutLogo.vbin" />
5+
<textures>
6+
<texture path="obj/BiosNoLogoTexture.vtex" />
7+
</textures>
8+
<sounds>
9+
<sound path="obj/DummyBiosSound.vsnd" />
10+
</sounds>
11+
</rom-definition>
60 Bytes
Binary file not shown.

Bios/BiosWithoutLogo/ErrorInfo.h

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// ---------------------------------------------------------
2+
// HARDWARE ERROR CODES
3+
// ---------------------------------------------------------
4+
5+
6+
enum error_codes
7+
{
8+
error_memory_read = 0,
9+
error_memory_write,
10+
error_port_read,
11+
error_port_write,
12+
error_stack_overflow,
13+
error_stack_underflow,
14+
error_division,
15+
error_arc_cosine,
16+
error_arc_tangent_2,
17+
error_logarithm,
18+
error_power,
19+
error_unknown
20+
};
21+
22+
23+
// ---------------------------------------------------------
24+
// MESSAGES FOR EACH ERROR
25+
// ---------------------------------------------------------
26+
27+
28+
struct error_message
29+
{
30+
int[ 50 ] title;
31+
int[ 150 ] description;
32+
};
33+
34+
// ---------------------------------------------------------
35+
36+
error_message[ 12 ] error_messages =
37+
{
38+
{
39+
"ERROR: INVALID MEMORY READ",
40+
"Program attempted to read from a memory address\n"
41+
"that does not exist or is in a write-only device."
42+
},
43+
{
44+
"ERROR: INVALID MEMORY WRITE",
45+
"Program attempted to write on a memory address\n"
46+
"that does not exist or is in a read-only device."
47+
},
48+
{
49+
"ERROR: INVALID PORT READ",
50+
"Program attempted to read from a port number\n"
51+
"that does not exist or is set as write-only."
52+
},
53+
{
54+
"ERROR: INVALID PORT WRITE",
55+
"Program attempted to write on a port number\n"
56+
"that does not exist or is set as read-only."
57+
},
58+
{
59+
"ERROR: STACK OVERFLOW",
60+
"Program pushed too many values in the stack\n"
61+
"and available RAM memory was exhausted."
62+
},
63+
{
64+
"ERROR: STACK UNDERFLOW",
65+
"Program popped too many values from the stack\n"
66+
"and all data stored in stack was exhausted."
67+
},
68+
{
69+
"ERROR: DIVISION BY ZERO",
70+
"Program attempted to perform a division or\n"
71+
"modulus operation where the divisor was zero."
72+
},
73+
{
74+
"ERROR: ARC COSINE OUT OF RANGE",
75+
"Program attempted to perform an arc cosine\n"
76+
"operation when the argument was not in [-1,+1]."
77+
},
78+
{
79+
"ERROR: ARC TANGENT NOT DEFINED",
80+
"Program attempted to perform an arc tangent\n"
81+
"operation when both of the arguments were 0."
82+
},
83+
{
84+
"ERROR: LOGARITHM OUT OF RANGE",
85+
"Program attempted to perform a logarithm\n"
86+
"operation when the argument is not positive."
87+
},
88+
{
89+
"ERROR: POWER HAS NO REAL SOLUTION",
90+
"Program attempted to perform a power operation\n"
91+
"when base was negative and exponent non integer."
92+
},
93+
{
94+
"UNKNOWN ERROR",
95+
"Program caused a hardware error with an error\n"
96+
"code that was not recognized by the BIOS."
97+
}
98+
};

Bios/BiosWithoutLogo/Make.bat

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@echo off
2+
3+
REM create obj and bin folders if non exiting, since
4+
REM the development tools will not create them themselves
5+
if not exist obj mkdir obj
6+
if not exist bin mkdir bin
7+
8+
echo.
9+
echo Compile the C code
10+
echo --------------------------
11+
REM compilation of a BIOS requires argument -b
12+
compile BiosWithoutLogo.c -o obj\BiosWithoutLogo.asm -b || goto :failed
13+
14+
echo.
15+
echo Assemble the ASM code
16+
echo --------------------------
17+
REM assembly of a BIOS requires argument -b
18+
assemble obj\BiosWithoutLogo.asm -o obj\BiosWithoutLogo.vbin -b || goto :failed
19+
20+
echo.
21+
echo Convert the PNG texture
22+
echo --------------------------
23+
png2vircon BiosNoLogoTexture.png -o obj\BiosNoLogoTexture.vtex || goto :failed
24+
25+
echo.
26+
echo Convert the WAV sound
27+
echo --------------------------
28+
wav2vircon DummyBiosSound.wav -o obj\DummyBiosSound.vsnd || goto :failed
29+
30+
echo.
31+
echo Pack the ROM
32+
echo --------------------------
33+
packrom BiosWithoutLogo.xml -o bin\BiosWithoutLogo.v32 || goto :failed
34+
35+
goto :succeeded
36+
37+
:failed
38+
echo.
39+
echo BUILD FAILED
40+
exit /b %errorlevel%
41+
42+
:succeeded
43+
echo.
44+
echo BUILD SUCCESSFUL
45+
exit /b
46+
47+
@echo on

0 commit comments

Comments
 (0)