initial commit

main
Henri Vasserman 2021-04-10 22:30:51 +03:00
commit af5522ca01
7 changed files with 467 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
build/

13
CMakeLists.txt Normal file
View File

@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.18)
project(xormod C)
find_package(SDL2)
add_executable(xormod
"xormod.c"
"font.c"
"EGA8x8.c"
)
target_link_libraries(xormod SDL2::SDL2)

187
EGA8x8.c Normal file
View File

@ -0,0 +1,187 @@
unsigned char font_data[] = {
0x42, 0x4d, 0x82, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x00,
0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,
0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0x18, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00,
0x00, 0x00, 0x00, 0xfc, 0xfc, 0xfc, 0x18, 0xd8, 0x30, 0x00, 0x00, 0x00,
0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x18, 0xd8,
0x30, 0xdc, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x30,
0x60, 0x18, 0x18, 0x18, 0x00, 0x76, 0x00, 0x18, 0x18, 0xec, 0x6c, 0x78,
0x3c, 0x00, 0xfc, 0x30, 0x30, 0x30, 0x18, 0x18, 0xfc, 0x00, 0x38, 0x18,
0x00, 0x0c, 0x6c, 0x60, 0x3c, 0x00, 0x00, 0xfc, 0x18, 0x60, 0x1b, 0x18,
0x00, 0xdc, 0x6c, 0x00, 0x00, 0x0c, 0x6c, 0x30, 0x3c, 0x00, 0xfc, 0x30,
0x30, 0x30, 0x1b, 0x18, 0x30, 0x76, 0x6c, 0x00, 0x00, 0x0c, 0x6c, 0x18,
0x00, 0x00, 0x00, 0x30, 0x60, 0x18, 0x0e, 0x18, 0x30, 0x00, 0x38, 0x00,
0x00, 0x0f, 0x78, 0x70, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00,
0xc0, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x76, 0xc0,
0xc0, 0x6c, 0xfc, 0x70, 0x60, 0x18, 0x30, 0x38, 0xee, 0x78, 0x00, 0x60,
0x38, 0xcc, 0xdc, 0xf8, 0xc0, 0x6c, 0xcc, 0xd8, 0x7c, 0x18, 0x78, 0x6c,
0x6c, 0xcc, 0x7e, 0x7e, 0x60, 0xcc, 0xc8, 0xcc, 0xc0, 0x6c, 0x60, 0xd8,
0x66, 0x18, 0xcc, 0xc6, 0x6c, 0xcc, 0xdb, 0xdb, 0xc0, 0xcc, 0xdc, 0xf8,
0xc0, 0x6c, 0x30, 0xd8, 0x66, 0x18, 0xcc, 0xfe, 0xc6, 0x7c, 0xdb, 0xdb,
0xf8, 0xcc, 0x76, 0xcc, 0xcc, 0x6c, 0x60, 0x7e, 0x66, 0xdc, 0x78, 0xc6,
0xc6, 0x18, 0x7e, 0x7e, 0xc0, 0xcc, 0x00, 0x78, 0xfc, 0xfe, 0xcc, 0x00,
0x66, 0x76, 0x30, 0x6c, 0x6c, 0x30, 0x00, 0x0c, 0x60, 0xcc, 0x00, 0x00,
0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xfc, 0x38, 0x38, 0x1c, 0x00, 0x06,
0x38, 0x78, 0x00, 0x18, 0x36, 0x00, 0x00, 0x18, 0x36, 0x36, 0x18, 0x00,
0x18, 0xff, 0xff, 0xf0, 0x0f, 0x00, 0x00, 0x18, 0x36, 0x00, 0x00, 0x18,
0x36, 0x36, 0x18, 0x00, 0x18, 0xff, 0xff, 0xf0, 0x0f, 0x00, 0x00, 0x18,
0x36, 0x00, 0x00, 0x18, 0x36, 0x36, 0x18, 0x00, 0x18, 0xff, 0xff, 0xf0,
0x0f, 0x00, 0xff, 0xff, 0xff, 0x3f, 0x1f, 0x1f, 0x3f, 0xff, 0xff, 0xf8,
0x1f, 0xff, 0xff, 0xf0, 0x0f, 0x00, 0x36, 0x00, 0x00, 0x36, 0x18, 0x18,
0x00, 0x36, 0x18, 0x18, 0x00, 0xff, 0x00, 0xf0, 0x0f, 0xff, 0x36, 0xff,
0x00, 0x36, 0x1f, 0x1f, 0x00, 0x36, 0xff, 0x18, 0x00, 0xff, 0x00, 0xf0,
0x0f, 0xff, 0x36, 0x00, 0x00, 0x36, 0x18, 0x00, 0x00, 0x36, 0x18, 0x18,
0x00, 0xff, 0x00, 0xf0, 0x0f, 0xff, 0x36, 0x00, 0x00, 0x36, 0x18, 0x00,
0x00, 0x36, 0x18, 0x18, 0x00, 0xff, 0x00, 0xf0, 0x0f, 0xff, 0x00, 0x00,
0x18, 0x18, 0x00, 0x18, 0x18, 0x36, 0x00, 0x36, 0x00, 0x36, 0x36, 0x00,
0x36, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x18, 0x36, 0x00, 0x36,
0x00, 0x36, 0x36, 0x00, 0x36, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18,
0x18, 0x36, 0x00, 0x36, 0x00, 0x36, 0x36, 0x00, 0x36, 0x00, 0x1f, 0xff,
0xff, 0x1f, 0xff, 0xff, 0x1f, 0x37, 0x3f, 0x37, 0xff, 0xf7, 0x37, 0xff,
0xf7, 0xff, 0x18, 0x18, 0x00, 0x18, 0x00, 0x18, 0x18, 0x36, 0x30, 0x30,
0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x18, 0x00, 0x18,
0x1f, 0x36, 0x37, 0x3f, 0xf7, 0xff, 0x37, 0xff, 0xf7, 0xff, 0x18, 0x18,
0x00, 0x18, 0x00, 0x18, 0x18, 0x36, 0x36, 0x00, 0x36, 0x00, 0x36, 0x00,
0x36, 0x18, 0x18, 0x18, 0x00, 0x18, 0x00, 0x18, 0x18, 0x36, 0x36, 0x00,
0x36, 0x00, 0x36, 0x00, 0x36, 0x18, 0x88, 0xaa, 0xee, 0x18, 0x18, 0x18,
0x36, 0x36, 0x18, 0x36, 0x36, 0x36, 0x00, 0x00, 0x00, 0x18, 0x22, 0x55,
0xdb, 0x18, 0x18, 0x18, 0x36, 0x36, 0x18, 0x36, 0x36, 0x36, 0x00, 0x00,
0x00, 0x18, 0x88, 0xaa, 0x77, 0x18, 0x18, 0x18, 0x36, 0x36, 0x18, 0x36,
0x36, 0x36, 0x00, 0x00, 0x00, 0x18, 0x22, 0x55, 0xdb, 0x18, 0xf8, 0xf8,
0xf6, 0xfe, 0xf8, 0xf6, 0x36, 0xf6, 0xfe, 0xfe, 0xf8, 0xf8, 0x88, 0xaa,
0xee, 0x18, 0x18, 0x18, 0x36, 0x00, 0x18, 0x06, 0x36, 0x06, 0x06, 0x36,
0x18, 0x00, 0x22, 0x55, 0xdb, 0x18, 0x18, 0xf8, 0x36, 0x00, 0xf8, 0xf6,
0x36, 0xfe, 0xf6, 0x36, 0xf8, 0x00, 0x88, 0xaa, 0x77, 0x18, 0x18, 0x18,
0x36, 0x00, 0x00, 0x36, 0x36, 0x00, 0x36, 0x36, 0x18, 0x00, 0x22, 0x55,
0xdb, 0x18, 0x18, 0x18, 0x36, 0x00, 0x00, 0x36, 0x36, 0x00, 0x36, 0x36,
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x7e, 0x78, 0x78, 0x7e, 0xcc, 0xcc,
0x00, 0x00, 0x78, 0x00, 0x00, 0xcc, 0xcf, 0x18, 0x00, 0x00, 0xcc, 0x30,
0xcc, 0xcc, 0xcc, 0xdc, 0x7e, 0x7c, 0xcc, 0xc0, 0x0c, 0x66, 0x6f, 0x18,
0x33, 0xcc, 0x7c, 0x30, 0xcc, 0xcc, 0xcc, 0xfc, 0x00, 0x00, 0xc0, 0xc0,
0x0c, 0x33, 0x37, 0x18, 0x66, 0x66, 0x0c, 0x30, 0x78, 0xcc, 0xf8, 0xec,
0x3e, 0x38, 0x60, 0xfc, 0xfc, 0xde, 0xdb, 0x18, 0xcc, 0x33, 0x78, 0x70,
0x00, 0x00, 0x00, 0xcc, 0x6c, 0x6c, 0x30, 0x00, 0x00, 0xcc, 0xcc, 0x00,
0x66, 0x66, 0x00, 0x00, 0x1c, 0x1c, 0xf8, 0x00, 0x6c, 0x6c, 0x00, 0x00,
0x00, 0xc6, 0xc6, 0x18, 0x33, 0xcc, 0x1c, 0x38, 0x00, 0x00, 0x00, 0xfc,
0x3c, 0x38, 0x30, 0x00, 0x00, 0xc3, 0xc3, 0x18, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x18, 0x00, 0x30,
0xc7, 0x70, 0xfc, 0x7f, 0xce, 0x78, 0x78, 0x78, 0x7e, 0x7e, 0x0c, 0x18,
0x78,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x78, 0x3c, 0x78, 0x78, 0x78, 0x78, 0x3c, 0x78,
0x78, 0x70, 0x38, 0x70, 0x6c, 0x00, 0xcc, 0xcc, 0x00, 0xc3, 0x00, 0x00,
0x30, 0x00, 0xc3, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x38, 0x30, 0x78, 0x00,
0x1c, 0x7e, 0xcc, 0xe0, 0x30, 0x00, 0x7e, 0xcc, 0xe0, 0xcc, 0x7c, 0xe0,
0xc6, 0x30, 0xf0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x0c, 0xf0, 0xf8, 0x18, 0x76,
0x30, 0x6c, 0xc6, 0x0c, 0xfc, 0x1c, 0x18, 0xe0, 0x00, 0xfe, 0x7c, 0x7c,
0x60, 0x0c, 0x34, 0xcc, 0x78, 0xfe, 0x6c, 0x7c, 0x64, 0x30, 0x18, 0x30,
0x00, 0xc6, 0x66, 0xcc, 0x66, 0x78, 0x30, 0xcc, 0xcc, 0xfe, 0x38, 0xcc,
0x30, 0x30, 0x18, 0x30, 0x00, 0xc6, 0x66, 0xcc, 0x76, 0xc0, 0x30, 0xcc,
0xcc, 0xd6, 0x6c, 0xcc, 0x98, 0xe0, 0x00, 0x1c, 0x00, 0x6c, 0xdc, 0x76,
0xdc, 0x7c, 0x7c, 0xcc, 0xcc, 0xc6, 0xc6, 0xcc, 0xfc, 0x30, 0x18, 0x30,
0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x30, 0x18, 0x30, 0xdc, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x18, 0xe0, 0x76, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x76, 0xdc, 0x78, 0x76, 0x78, 0xf0, 0x0c, 0xe6, 0x78,
0xcc, 0xe6, 0x78, 0xc6, 0xcc, 0x78, 0x00, 0xcc, 0x66, 0xcc, 0xcc, 0xc0,
0x60, 0x7c, 0x66, 0x30, 0xcc, 0x6c, 0x30, 0xd6, 0xcc, 0xcc, 0x00, 0x7c,
0x66, 0xc0, 0xcc, 0xfc, 0x60, 0xcc, 0x66, 0x30, 0x0c, 0x78, 0x30, 0xfe,
0xcc, 0xcc, 0x00, 0x0c, 0x7c, 0xcc, 0x7c, 0xcc, 0xf0, 0xcc, 0x76, 0x30,
0x0c, 0x6c, 0x30, 0xfe, 0xcc, 0xcc, 0x18, 0x78, 0x60, 0x78, 0x0c, 0x78,
0x60, 0x76, 0x6c, 0x70, 0x0c, 0x66, 0x30, 0xcc, 0xf8, 0x78, 0x30, 0x00,
0x60, 0x00, 0x0c, 0x00, 0x6c, 0x00, 0x60, 0x00, 0x00, 0x60, 0x30, 0x00,
0x00, 0x00, 0x30, 0x00, 0xe0, 0x00, 0x1c, 0x00, 0x38, 0x00, 0xe0, 0x30,
0x0c, 0xe0, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xf0, 0x1c,
0xe6, 0x78, 0x78, 0xfc, 0x30, 0xc6, 0xc6, 0x78, 0xfe, 0x78, 0x02, 0x78,
0x00, 0x00, 0x60, 0x78, 0x66, 0xcc, 0x30, 0xcc, 0x78, 0xee, 0x6c, 0x30,
0x66, 0x60, 0x06, 0x18, 0x00, 0x00, 0x60, 0xdc, 0x6c, 0x1c, 0x30, 0xcc,
0xcc, 0xfe, 0x38, 0x30, 0x32, 0x60, 0x0c, 0x18, 0x00, 0x00, 0x7c, 0xcc,
0x7c, 0x70, 0x30, 0xcc, 0xcc, 0xd6, 0x38, 0x78, 0x18, 0x60, 0x18, 0x18,
0xc6,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00, 0x00, 0x60, 0x00, 0x00,
0x00, 0x00, 0x7c, 0xfc, 0xfc, 0x78, 0x1e, 0x78, 0x78, 0x30, 0x78, 0x70,
0x30, 0x30, 0x18, 0x00, 0x60, 0x30, 0xe6, 0x30, 0xcc, 0xcc, 0x0c, 0xcc,
0xcc, 0x30, 0xcc, 0x18, 0x30, 0x30, 0x30, 0xfc, 0x30, 0x00, 0xf6, 0x30,
0x60, 0x0c, 0xfe, 0x0c, 0xcc, 0x30, 0xcc, 0x0c, 0x00, 0x00, 0x60, 0x00,
0x18, 0x30, 0xde, 0x30, 0x38, 0x38, 0xcc, 0x0c, 0xf8, 0x18, 0x78, 0x7c,
0x00, 0x00, 0xc0, 0x00, 0x0c, 0x18, 0xce, 0x30, 0x0c, 0x0c, 0x6c, 0xf8,
0xc0, 0x0c, 0xcc, 0xcc, 0x30, 0x30, 0x60, 0xfc, 0x18, 0x0c, 0xc6, 0x70,
0xcc, 0xcc, 0x3c, 0xc0, 0x60, 0xcc, 0xcc, 0xcc, 0x30, 0x30, 0x30, 0x00,
0x30, 0xcc, 0x7c, 0x30, 0x78, 0x78, 0x1c, 0xfc, 0x38, 0xfc, 0x78, 0x78,
0x00, 0x00, 0x18, 0x00, 0x60, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x30,
0x00, 0x6c, 0x30, 0xc6, 0x76, 0x00, 0x18, 0x60, 0x00, 0x00, 0x30, 0x00,
0x30, 0x80, 0x00, 0x00, 0x00, 0x6c, 0xf8, 0x66, 0xcc, 0x00, 0x30, 0x30,
0x66, 0x30, 0x30, 0x00, 0x30, 0xc0, 0x00, 0x30, 0x00, 0xfe, 0x0c, 0x30,
0xdc, 0x00, 0x60, 0x18, 0x3c, 0x30, 0x00, 0x00, 0x00, 0x60, 0x00, 0x30,
0x00, 0x6c, 0x78, 0x18, 0x76, 0x00, 0x60, 0x18, 0xff, 0xfc, 0x00, 0xfc,
0x00, 0x30, 0x00, 0x78, 0x6c, 0xfe, 0xc0, 0xcc, 0x38, 0xc0, 0x60, 0x18,
0x3c, 0x30, 0x00, 0x00, 0x00, 0x18, 0x00, 0x78, 0x6c, 0x6c, 0x7c, 0xc6,
0x6c, 0x60, 0x30, 0x30, 0x66, 0x30, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x30,
0x6c, 0x6c, 0x30, 0x00, 0x38, 0x60, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00,
0x00, 0x06, 0x00, 0x00, 0x18, 0x00, 0x00, 0x78, 0x00, 0xff, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x3c, 0x66, 0x1b, 0xcc,
0x7e, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x0e,
0x7e, 0x00, 0x1b, 0x38, 0x7e, 0x3c, 0x18, 0x3c, 0x18, 0x30, 0xfe, 0x24,
0xff, 0x18, 0xf8, 0x3e, 0x18, 0x66, 0x1b, 0x6c, 0x7e, 0x7e, 0x18, 0x7e,
0x0c, 0x60, 0xc0, 0x66, 0xff, 0x3c, 0xfe, 0xfe, 0x18, 0x66, 0x7b, 0x6c,
0x00, 0x18, 0x18, 0x18, 0xfe, 0xfe, 0xc0, 0xff, 0x7e, 0x7e, 0xf8, 0x3e,
0x7e, 0x66, 0xdb, 0x38, 0x00, 0x7e, 0x7e, 0x18, 0x0c, 0x60, 0xc0, 0x66,
0x3c, 0xff, 0xe0, 0x0e, 0x3c, 0x66, 0xdb, 0x63, 0x00, 0x3c, 0x3c, 0x18,
0x18, 0x30, 0x00, 0x24, 0x18, 0xff, 0x80, 0x02, 0x18, 0x66, 0x7f, 0x3e,
0x00, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e,
0x7e, 0x00, 0x00, 0x7c, 0x7c, 0x00, 0xff, 0x00, 0xff, 0x78, 0x18, 0xe0,
0xc0, 0x99, 0x00, 0x81, 0xff, 0x10, 0x10, 0x38, 0x38, 0x00, 0xff, 0x3c,
0xc3, 0xcc, 0x7e, 0xf0, 0xe6, 0x5a, 0x00, 0x99, 0xe7, 0x38, 0x38, 0x7c,
0x7c, 0x18, 0xe7, 0x66, 0x99, 0xcc, 0x18, 0x70, 0x67, 0x3c, 0x00, 0xbd,
0xc3, 0x7c, 0x7c, 0xfe, 0xfe, 0x3c, 0xc3, 0x42, 0xbd, 0xcc, 0x3c, 0x30,
0x63, 0xe7, 0x00, 0x81, 0xff, 0xfe, 0xfe, 0xfe, 0x7c, 0x3c, 0xc3, 0x42,
0xbd, 0x7d, 0x66, 0x30, 0x63, 0xe7, 0x00, 0xa5, 0xdb, 0xfe, 0x7c, 0x38,
0x38, 0x18, 0xe7, 0x66, 0x99, 0x0f, 0x66, 0x3f, 0x7f, 0x3c, 0x00, 0x81,
0xff, 0xfe, 0x38, 0x7c, 0x10, 0x00, 0xff, 0x3c, 0xc3, 0x07, 0x66, 0x33,
0x63, 0x5a, 0x00, 0x7e, 0x7e, 0x6c, 0x10, 0x38, 0x10, 0x00, 0xff, 0x00,
0xff, 0x0f, 0x3c, 0x3f, 0x7f, 0x99
};
unsigned int font_data_len = 2178;
unsigned int font_w = 8;
unsigned int font_h = 8;

7
EGA8x8.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
extern unsigned char font_data[];
extern unsigned int font_data_len;
extern unsigned int font_w;
extern unsigned int font_h;

33
font.c Normal file
View File

@ -0,0 +1,33 @@
#include "EGA8x8.h"
#include <SDL2/SDL.h>
SDL_Texture *load_font(SDL_Renderer *renderer) {
SDL_Surface *s = SDL_LoadBMP_RW(SDL_RWFromConstMem(font_data, font_data_len), 1);
SDL_SetColorKey(s, SDL_TRUE, SDL_MapRGB(s->format, 255, 0, 255));
SDL_Texture *font_texture = SDL_CreateTextureFromSurface(renderer, s);
SDL_FreeSurface(s);
return font_texture;
}
void draw_text(SDL_Renderer *renderer, SDL_Texture *font,
char *text, size_t len, int x, int y, uint8_t r, uint8_t g, uint8_t b) {
if (font == NULL) return;
SDL_SetTextureColorMod(font, r, g, b);
SDL_Rect src = { .w = font_w, .h = font_h },
dst = { .x = x, .y = y, .w = font_w, .h = font_h };
for (size_t i = 0; i < len; i++) {
char c = text[i];
if (c == 0) break;
if (c == '\n') {
dst.x = x;
dst.y += font_h;
continue;
}
src.x = (c & 0xf) * font_w;
src.y = (c >> 4) * font_h;
SDL_RenderCopy(renderer, font, &src, &dst);
dst.x += font_w;
}
}

9
font.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <SDL2/SDL.h>
#define RC(r, c) (c)*font_w, (r)*font_h
SDL_Texture *load_font(SDL_Renderer *renderer);
void draw_text(SDL_Renderer *renderer, SDL_Texture *font,
char *text, size_t len, int x, int y, uint8_t r, uint8_t g, uint8_t b);

217
xormod.c Normal file
View File

@ -0,0 +1,217 @@
#include "font.h"
#include "EGA8x8.h"
#include <stdio.h>
#include <SDL2/SDL.h>
#define SWAP(a, b) ({ \
__typeof(a) tmp = (a); \
(a) = (b); \
(b) = tmp; \
})
typedef struct {
int x1;
int y1;
int x2;
int y2;
int w;
int h;
SDL_Surface *surface;
SDL_Texture *texture;
uint32_t *pixels;
uint32_t color;
} Picture;
static void Picture_render(Picture *p, SDL_Renderer *rend);
static Picture *Picture_new(SDL_Renderer *rend,
int x, int y, int w, int h, uint32_t color) {
Picture *p = calloc(1, sizeof(Picture));
p->x1 = x;
p->x2 = x + w;
p->y1 = y;
p->y2 = y + h;
p->w = w;
p->h = h;
p->pixels = malloc(w * h * sizeof(uint32_t));
p->color = color;
p->surface = SDL_CreateRGBSurfaceWithFormatFrom(
p->pixels, w, h, 32, w * sizeof(uint32_t),
SDL_PIXELFORMAT_RGBA32);
Picture_render(p, rend);
return p;
}
typedef uint32_t uint32_4 __attribute__ ((vector_size (4 * sizeof(uint32_t))));
static void Picture_render(Picture *p, SDL_Renderer *rend) {
for (int j = p->y1, r = 0; j < p->y2; j++) {
uint32_4 y = {j, j, j, j};
for (int i = p->x1; i < p->x2; i+=4, r+=4) {
uint32_4 x = {i, i + 1, i + 2, i + 3};
uint32_4 z = (x ^ y) % 9;
uint32_4 f = (z==0) & p->color;
memcpy(&p->pixels[r], (uint32_t*)&f, sizeof(f));
}
}
if (p->texture) SDL_DestroyTexture(p->texture);
p->texture = SDL_CreateTextureFromSurface(rend, p->surface);
SDL_SetTextureBlendMode(p->texture, SDL_BLENDMODE_NONE);
}
static void Picture_move(Picture *p, int x, int y) {
p->x1 += x;
p->x2 += x;
p->y1 += y;
p->y2 += y;
}
struct int2 { int x; int y; };
int main() {
unsigned w = 1280, h = 720;
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
fprintf(stderr, "Can't init: %s\n", SDL_GetError());
return -1;
}
SDL_Window *window = SDL_CreateWindow("xormod",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h,
SDL_WINDOW_OPENGL /*SDL_WINDOW_FULLSCREEN */);
if (window == NULL) {
fprintf(stderr, "Can't open window: %s\n", SDL_GetError());
return -1;
}
SDL_GetWindowSize(window, &w, &h);
SDL_Renderer *rend = SDL_CreateRenderer(window, -1,
/*SDL_RENDERER_PRESENTVSYNC | */SDL_RENDERER_ACCELERATED);
SDL_Texture *font = load_font(rend);
Picture *pictures[4];
enum { P_TOPLEFT, P_TOPRGHT, P_BOTLEFT, P_BOTRGHT };
pictures[P_TOPLEFT] = Picture_new(rend, 0, 0, w, h, 0xff7fffff);
pictures[P_TOPRGHT] = Picture_new(rend, w, 0, w, h, 0xffff7fff);
pictures[P_BOTLEFT] = Picture_new(rend, 0, h, w, h, 0xffffff7f);
pictures[P_BOTRGHT] = Picture_new(rend, w, h, w, h, 0xff7fff7f);
struct int2 off = { 0, 0 };
struct int2 mouse_prev = { -1, -1 };
int running = 1;
while (running) {
const uint8_t *keys = SDL_GetKeyboardState(NULL);
if (keys[SDL_SCANCODE_ESCAPE] || keys[SDL_SCANCODE_Q]) {
break;
}
if (keys[SDL_SCANCODE_LEFT]) {
off.x -= 5;
}
if (keys[SDL_SCANCODE_RIGHT]) {
off.x += 5;
}
if (keys[SDL_SCANCODE_UP]) {
off.y -= 5;
}
if (keys[SDL_SCANCODE_DOWN]) {
off.y += 5;
}
struct int2 mouse;
if (SDL_GetMouseState(&mouse.x, &mouse.y) & SDL_BUTTON(SDL_BUTTON_LEFT)) {
if (mouse_prev.x != -1 ) {
off.x -= mouse.x - mouse_prev.x;
off.y -= mouse.y - mouse_prev.y;
}
mouse_prev = mouse;
} else if (mouse_prev.x != -1) {
mouse_prev = (struct int2) { -1, -1 };
}
if (off.y < pictures[P_TOPLEFT]->y1) {
SWAP(pictures[P_TOPLEFT], pictures[P_BOTLEFT]);
SWAP(pictures[P_TOPRGHT], pictures[P_BOTRGHT]);
Picture_move(pictures[P_TOPLEFT], 0, -2*h);
Picture_move(pictures[P_TOPRGHT], 0, -2*h);
Picture_render(pictures[P_TOPLEFT], rend);
Picture_render(pictures[P_TOPRGHT], rend);
}
if (off.x < pictures[P_TOPLEFT]->x1) {
SWAP(pictures[P_TOPLEFT], pictures[P_TOPRGHT]);
SWAP(pictures[P_BOTLEFT], pictures[P_BOTRGHT]);
Picture_move(pictures[P_TOPLEFT], -2*w, 0);
Picture_move(pictures[P_BOTLEFT], -2*w, 0);
Picture_render(pictures[P_TOPLEFT], rend);
Picture_render(pictures[P_BOTLEFT], rend);
}
if (off.y > pictures[P_BOTRGHT]->y1) {
SWAP(pictures[P_TOPLEFT], pictures[P_BOTLEFT]);
SWAP(pictures[P_TOPRGHT], pictures[P_BOTRGHT]);
Picture_move(pictures[P_BOTLEFT], 0, 2*h);
Picture_move(pictures[P_BOTRGHT], 0, 2*h);
Picture_render(pictures[P_BOTLEFT], rend);
Picture_render(pictures[P_BOTRGHT], rend);
}
if (off.x > pictures[P_BOTRGHT]->x1) {
SWAP(pictures[P_TOPLEFT], pictures[P_TOPRGHT]);
SWAP(pictures[P_BOTLEFT], pictures[P_BOTRGHT]);
Picture_move(pictures[P_TOPRGHT], 2*w, 0);
Picture_move(pictures[P_BOTRGHT], 2*w, 0);
Picture_render(pictures[P_TOPRGHT], rend);
Picture_render(pictures[P_BOTRGHT], rend);
}
//SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
//SDL_RenderClear(rend);
for (int i = 0; i < 4; i++) {
Picture *p = pictures[i];
SDL_Rect dst = {
p->x1 - off.x, p->y1 - off.y, w, h,
};
SDL_RenderCopy(rend, p->texture, NULL, &dst);
}
//char buf[72];
//SDL_SetRenderDrawColor(rend, 0, 0, 0, 255);
//SDL_RenderFillRect(rend, &(SDL_Rect) { 0, 0, sizeof(buf)*font_w, 7*font_h });
//size_t len = snprintf(buf, sizeof(buf), "off.x: %d, off.y: %d", off.x, off.y);
//draw_text(rend, font, buf, len, RC(1, 1), 255, 255, 255);
//char *q[] = {"TL", "TR", "BL", "BR"};
//for (int i = 0; i < 4; i++) {
// Picture *p = pictures[i];
// len = snprintf(buf, sizeof(buf), "%s| x1: %05d, x2: %05d, y1: %05d, y2: %05d, p: %p",
// q[i], p->x1, p->x2, p->y1, p->y2, p);
// draw_text(rend, font, buf, len, RC(2+i, 1), 255, 255, 255);
//}
SDL_RenderPresent(rend);
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
running = 0;
}
}
}
SDL_DestroyRenderer(rend);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}