|
|
|
|
@@ -70,9 +70,6 @@ uint8_t tile_height = 8;
|
|
|
|
|
|
|
|
|
|
font_t fonts[MAX_FONTS];
|
|
|
|
|
font_t *current_font;
|
|
|
|
|
FILE *file = NULL;
|
|
|
|
|
//uint8_t file_mode = 0;
|
|
|
|
|
bool file_ignore_comma=true;
|
|
|
|
|
|
|
|
|
|
char main_lua_file[200] = "main.lua";
|
|
|
|
|
bool override_ini = false;
|
|
|
|
|
@@ -90,7 +87,6 @@ namespace ds {
|
|
|
|
|
uint8_t back_color = 0;
|
|
|
|
|
int origin[2] = {0, 0};
|
|
|
|
|
int clip[4] = {0, 0, screen_width-1, screen_height-1}; // clip (x1,y1,x2,y2) calculat intersectat amb el tamany de la surface 'dest'
|
|
|
|
|
int clp[4] = {0, 0, screen_width, screen_height}; // clip (x1,y1,w,h) que ha especificat l'usuari
|
|
|
|
|
uint8_t trans = 0;
|
|
|
|
|
uint16_t fill_pattern = 0b1111111111111111;
|
|
|
|
|
bool fill_trans = false;
|
|
|
|
|
@@ -114,14 +110,14 @@ int pitch;
|
|
|
|
|
uint32_t palette[256] = { 0xFF1a1c2c, 0xFF5d275d, 0xFFb13e53, 0xFFef7d57, 0xFFffcd75, 0xFFa7f070, 0xFF38b764, 0xFF257179,
|
|
|
|
|
0xFF29366f, 0xFF3b5dc9, 0xFF41a6f6, 0xFF73eff7, 0xFFf4f4f4, 0xFF94b0c2, 0xFF566c86, 0xFF333c57 };
|
|
|
|
|
|
|
|
|
|
const char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
|
|
|
|
|
|
char base64font[241] = "00@B@]0X__OnZDYK[G10:9BTDEG5j20@1h000RB:_]OBjW?odl]Wlil9_oTT__omT@@02:DA477ADid@Z=nm]_[g9a[]oIi?;a9m]_mBjGB[M]99o_][]e]M"
|
|
|
|
|
"_?A]c_[eiLGBZ]e]mZ]o]Z]mlW:O9IABdTdZ000hR00__H[7?iH]3Oih;1?mXm5GjhB3M]897o]H]5^Mhm1ZchM5>LhB2]eXm2]oXZ5mlh<gJbBBJbJP?0Zm";
|
|
|
|
|
uint16_t font[96];
|
|
|
|
|
|
|
|
|
|
char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAVIc+dJHMMM/h/qBgBgVqq+//eIUi/dJzhAAhzAAA/eM"
|
|
|
|
|
"AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA";
|
|
|
|
|
//const char base64[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
|
//
|
|
|
|
|
//char base64font[241] = "00@B@]0X__OnZDYK[G10:9BTDEG5j20@1h000RB:_]OBjW?odl]Wlil9_oTT__omT@@02:DA477ADid@Z=nm]_[g9a[]oIi?;a9m]_mBjGB[M]99o_][]e]M"
|
|
|
|
|
// "_?A]c_[eiLGBZ]e]mZ]o]Z]mlW:O9IABdTdZ000hR00__H[7?iH]3Oih;1?mXm5GjhB3M]897o]H]5^Mhm1ZchM5>LhB2]eXm2]oXZ5mlh<gJbBBJbJP?0Zm";
|
|
|
|
|
//uint16_t font[96];
|
|
|
|
|
//
|
|
|
|
|
//char base64glyphs[193] = "/h/AqV/hhhh/GMYYMGz/t/eS33H477wsjjswY4IOPHEFFVVVAVAVAVIc+dJHMMM/h/qBgBgVqq+//eIUi/dJzhAAhzAAA/eM"
|
|
|
|
|
// "AMShAAAQsjAAAwsjAAAeSzAAAcU3AAAEqRAAABVaiAAMezhAAAAAMAADH4wAASb2SAAMAttAQYcefACGOe+AAAVVAAAAbbAA";
|
|
|
|
|
|
|
|
|
|
//Uint8 keymapping[6] = { SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_Z, SDL_SCANCODE_X };
|
|
|
|
|
const bool *keys;
|
|
|
|
|
@@ -245,23 +241,14 @@ void reinit() {
|
|
|
|
|
ds::back_color = 0;
|
|
|
|
|
ds::origin[0] = ds::origin[1] = 0;
|
|
|
|
|
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = screen_width-1; ds::clip[3] = screen_height-1;
|
|
|
|
|
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = screen_width; ds::clp[3] = screen_height;
|
|
|
|
|
ds::trans=0;
|
|
|
|
|
ds::fill_pattern = 0b1111111111111111;
|
|
|
|
|
ds::fill_trans = false;
|
|
|
|
|
for (unsigned int i=1; i<MAX_SURFACES; ++i) freesurf(i);
|
|
|
|
|
/*{
|
|
|
|
|
if (surfaces[i].p != NULL) free(surfaces[i].p);
|
|
|
|
|
surfaces[i].p = NULL;
|
|
|
|
|
if (surfaces[i].name != NULL) free(surfaces[i].name);
|
|
|
|
|
surfaces[i].name = NULL;
|
|
|
|
|
}
|
|
|
|
|
surfaces.clear();*/
|
|
|
|
|
for (unsigned int i=0; i<MAX_SURFACES; ++i) freesurf(i);
|
|
|
|
|
setdest(newsurf(screen_width, screen_height));
|
|
|
|
|
dest_surface = screen_surface;
|
|
|
|
|
|
|
|
|
|
for (int i=0;i<256;++i) ds::draw_palette[i]=i;
|
|
|
|
|
if (file!=NULL) fclose(file);
|
|
|
|
|
file = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void initaudio() {
|
|
|
|
|
@@ -410,10 +397,6 @@ int surfh(uint8_t surface) {
|
|
|
|
|
|
|
|
|
|
void recalculate_clip()
|
|
|
|
|
{
|
|
|
|
|
ds::clip[0] = ds::clp[0];
|
|
|
|
|
ds::clip[1] = ds::clp[1];
|
|
|
|
|
ds::clip[2] = ds::clp[2]+ds::clp[0]-1;
|
|
|
|
|
ds::clip[3] = ds::clp[3]+ds::clp[1]-1;
|
|
|
|
|
if (ds::clip[0]<0) ds::clip[0]=0;
|
|
|
|
|
if (ds::clip[1]<0) ds::clip[1]=0;
|
|
|
|
|
if (ds::clip[2]>=dest_surface->w) ds::clip[2]=dest_surface->w-1;
|
|
|
|
|
@@ -572,8 +555,6 @@ void createDisplay() {
|
|
|
|
|
windowID = SDL_GetWindowID(mini_win);
|
|
|
|
|
SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
|
|
|
|
mini_ren = SDL_CreateRenderer(mini_win, NULL);
|
|
|
|
|
//SDL_CreateWindowAndRenderer(512,512,0,&mini_win,&mini_ren);
|
|
|
|
|
//SDL_SetRenderLogicalPresentation(mini_ren, screen_width, screen_height);
|
|
|
|
|
if (screen_cursor) SDL_ShowCursor(); else SDL_HideCursor();
|
|
|
|
|
mini_bak = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen_width, screen_height);
|
|
|
|
|
SDL_SetTextureScaleMode(mini_bak, SDL_SCALEMODE_NEAREST);
|
|
|
|
|
@@ -585,15 +566,13 @@ void createDisplay() {
|
|
|
|
|
}
|
|
|
|
|
mini_shadertex = SDL_CreateTexture(mini_ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, screen_width*screen_zoom, screen_height*screen_zoom);
|
|
|
|
|
SDL_SetTextureScaleMode(mini_shadertex, SDL_SCALEMODE_NEAREST);
|
|
|
|
|
|
|
|
|
|
//int filesize;
|
|
|
|
|
//char *shaderfile = file_getfilebuffer("lynx.glsl", filesize);
|
|
|
|
|
shader::init(mini_win, mini_shadertex, nullptr);
|
|
|
|
|
//SDL_GetWindowPosition(mini_win, &windowpos_x, &windowpos_y);
|
|
|
|
|
|
|
|
|
|
log_msg(LOG_OK, "Graphics subsystem initialized\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void destroyDisplay() {
|
|
|
|
|
SDL_DestroyTexture(mini_shadertex);
|
|
|
|
|
SDL_DestroyTexture(mini_bak);
|
|
|
|
|
SDL_DestroyRenderer(mini_ren);
|
|
|
|
|
SDL_DestroyWindow(mini_win);
|
|
|
|
|
@@ -620,12 +599,11 @@ int main(int argc,char*argv[]){
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
log_msg(LOG_UNSALTED, "MINI v%s\n",MINI_VERSION);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Gestió de arguments
|
|
|
|
|
// ===============================================================
|
|
|
|
|
if (argc>1)
|
|
|
|
|
{
|
|
|
|
|
if (argv[1][0]=='-' && argv[1][1]=='-') {
|
|
|
|
|
@@ -634,7 +612,6 @@ int main(int argc,char*argv[]){
|
|
|
|
|
createNewProject();
|
|
|
|
|
exit(0);
|
|
|
|
|
} else if (strcmp(command, "version")==0) {
|
|
|
|
|
//createNewProject();
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
} else if (strstr(argv[1], ".lua")!=nullptr) {
|
|
|
|
|
@@ -646,35 +623,32 @@ int main(int argc,char*argv[]){
|
|
|
|
|
} else if (strstr(argv[1], ".jf2")!=nullptr) {
|
|
|
|
|
file_setresourcefilename(argv[1]);
|
|
|
|
|
file_setsource(SOURCE_FILE);
|
|
|
|
|
//strcpy(main_lua_file, argv[1]);
|
|
|
|
|
//strcpy(window_title, argv[1]);
|
|
|
|
|
//override_ini = true;
|
|
|
|
|
} else {
|
|
|
|
|
char path[256] = "./";
|
|
|
|
|
strcat(path, argv[1]);
|
|
|
|
|
file_setresourcefolder(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//screen_surface = &surfaces.emplace_back();
|
|
|
|
|
while (!should_quit) {
|
|
|
|
|
should_exit=false;
|
|
|
|
|
|
|
|
|
|
// initfont()
|
|
|
|
|
|
|
|
|
|
int bi = 0;
|
|
|
|
|
for (int ci=0; ci<96; ci+=2) {
|
|
|
|
|
font[ci] = base64font[bi] - 48 + ( ( base64font[bi+1] - 48 ) << 6) + ( ( ( base64font[bi+2] - 48 ) & 7 ) << 12 );
|
|
|
|
|
font[ci+1] = ( ( base64font[bi+2] - 48 ) >> 3 ) + ( ( base64font[bi+3] - 48 ) << 3 ) + ( ( base64font[bi+4] - 48 ) << 9 );
|
|
|
|
|
bi += 5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef MACOS_BUNDLE
|
|
|
|
|
char res_file[255] = "";
|
|
|
|
|
strcpy(res_file, dirname(argv[0]));
|
|
|
|
|
strcat(res_file, "/../Resources/data.jrf");
|
|
|
|
|
file_setresourcefilename(res_file);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
while (!should_quit) {
|
|
|
|
|
should_exit=false;
|
|
|
|
|
|
|
|
|
|
// initfont()
|
|
|
|
|
|
|
|
|
|
//int bi = 0;
|
|
|
|
|
//for (int ci=0; ci<96; ci+=2) {
|
|
|
|
|
// font[ci] = base64font[bi] - 48 + ( ( base64font[bi+1] - 48 ) << 6) + ( ( ( base64font[bi+2] - 48 ) & 7 ) << 12 );
|
|
|
|
|
// font[ci+1] = ( ( base64font[bi+2] - 48 ) >> 3 ) + ( ( base64font[bi+3] - 48 ) << 3 ) + ( ( base64font[bi+4] - 48 ) << 9 );
|
|
|
|
|
// bi += 5;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
// READ INI
|
|
|
|
|
if (!override_ini)
|
|
|
|
|
{
|
|
|
|
|
read_ini();
|
|
|
|
|
@@ -691,8 +665,6 @@ int main(int argc,char*argv[]){
|
|
|
|
|
if (sound_enabled) JA_EnableSound(strcmp(sound_enabled, "true")==0?true:false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setdest(newsurf(screen_width, screen_height));
|
|
|
|
|
|
|
|
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD);
|
|
|
|
|
|
|
|
|
|
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
|
|
|
|
@@ -703,10 +675,6 @@ int main(int argc,char*argv[]){
|
|
|
|
|
|
|
|
|
|
initGamePad();
|
|
|
|
|
|
|
|
|
|
//Mix_Init(MIX_INIT_OGG);
|
|
|
|
|
|
|
|
|
|
SDL_Event mini_eve;
|
|
|
|
|
|
|
|
|
|
reinit();
|
|
|
|
|
initaudio();
|
|
|
|
|
|
|
|
|
|
@@ -725,9 +693,11 @@ int main(int argc,char*argv[]){
|
|
|
|
|
mouse_wheel = 0;
|
|
|
|
|
double_click = false;
|
|
|
|
|
has_text_input = false;
|
|
|
|
|
|
|
|
|
|
while(!should_exit) {
|
|
|
|
|
if (update_mode==UPDATE_WAIT) SDL_WaitEvent(NULL);
|
|
|
|
|
else if (update_mode==UPDATE_TIMEOUT) SDL_WaitEventTimeout(NULL, timeout);
|
|
|
|
|
SDL_Event mini_eve;
|
|
|
|
|
while(SDL_PollEvent(&mini_eve)) {
|
|
|
|
|
if (mini_eve.type == SDL_EVENT_QUIT) { should_exit=true; should_quit=true; break; }
|
|
|
|
|
if (mini_eve.type == SDL_EVENT_TEXT_INPUT) {
|
|
|
|
|
@@ -738,13 +708,6 @@ int main(int argc,char*argv[]){
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
if (mini_eve.key.scancode == SDL_SCANCODE_F12) {
|
|
|
|
|
reloadsurfs();
|
|
|
|
|
//if (lua_is_playing()) {
|
|
|
|
|
// lua_quit();
|
|
|
|
|
// quitaudio();
|
|
|
|
|
// reinit();
|
|
|
|
|
//} else {
|
|
|
|
|
// should_exit=true;
|
|
|
|
|
//}
|
|
|
|
|
} else if (mini_eve.key.scancode == SDL_SCANCODE_F11) {
|
|
|
|
|
lua_toggle_debug();
|
|
|
|
|
} else if (mini_eve.key.scancode == SDL_SCANCODE_F5) {
|
|
|
|
|
@@ -849,12 +812,6 @@ void simple_pset(int x, int y, uint8_t color) {
|
|
|
|
|
|
|
|
|
|
void cls(uint8_t color) {
|
|
|
|
|
const uint8_t col = ds::draw_palette[color];
|
|
|
|
|
/*for (int y=ds::clip[1]; y<=ds::clip[3];++y) {
|
|
|
|
|
for (int x=ds::clip[0]; x<=ds::clip[2];++x) {
|
|
|
|
|
simple_pset(x,y,col);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
SDL_memset(dest_surface->p, col, dest_surface->size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1059,63 +1016,6 @@ void fillp(uint16_t pat, bool transparent) {
|
|
|
|
|
ds::fill_pattern = pat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_symbol(char sym, int x, int y) {
|
|
|
|
|
switch(sym) {
|
|
|
|
|
case 1: pset(x, y-3); pset(x+1, y-2); break;
|
|
|
|
|
case 2: pset(x+1, y-2); pset(x+2, y-3); break;
|
|
|
|
|
case 3: pset(x+1, y+5); break;
|
|
|
|
|
case 4: pset(x, y-2); pset(x+1, y-2); pset(x+2, y-2); break;
|
|
|
|
|
case 5: pset(x, y-2); pset(x+1, y-1); break;
|
|
|
|
|
case 6: pset(x+1, y-1); pset(x+2, y-2); break;
|
|
|
|
|
case 7: pset(x, y-1); pset(x+1, y-1); pset(x+2, y-1); break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_char(char chr, int x, int y) {
|
|
|
|
|
int xi = 0, yi = 0;
|
|
|
|
|
uint16_t val = 1;
|
|
|
|
|
while(1) {
|
|
|
|
|
if (font[chr-32] & val) pset(x+xi, y+yi);
|
|
|
|
|
if (xi<2) xi++; else { if (yi==4) return; else { xi=0; yi++; } }
|
|
|
|
|
val <<= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void print_char_hv(char chr, int x, int y) {
|
|
|
|
|
int xi = 0, yi = 0;
|
|
|
|
|
uint16_t val = 1;
|
|
|
|
|
while(1) {
|
|
|
|
|
if (font[chr-32] & val) pset(x+(2-xi), y+(4-yi));
|
|
|
|
|
if (xi<2) xi++; else { if (yi==4) return; else { xi=0; yi++; } }
|
|
|
|
|
val <<= 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char t195_char[]={65,65,0,0,0,0,0,67,69,69,0,0,73,73,0,0,0,78,79,79,0,0,0,0,0,85,85,0,0,0,0,0,97,97,0,0,0,0,0,99,101,101,0,0,105,105,0,0,0,110,111,111,0,0,0,0,0,117,117,0,0,0,0,0};
|
|
|
|
|
const char t195_symbol[]={1,2,0,0,0,0,0,3,1,2,0,0,1,2,0,0,0,4,1,2,0,0,0,0,0,1,2,0,0,0,0,0,5,6,0,0,0,0,0,3,5,6,0,0,5,6,0,0,0,7,5,6,0,0,0,0,0,5,6,0,0,0,0,0};
|
|
|
|
|
|
|
|
|
|
void print(const char *str, int x, int y) {
|
|
|
|
|
int pos=0;
|
|
|
|
|
for (size_t i=0; i < SDL_strlen(str); ++i) {
|
|
|
|
|
if ((unsigned char)str[i]==194) {
|
|
|
|
|
i++;
|
|
|
|
|
if ((unsigned char)str[i]==161) print_char_hv('!', x+pos*4, y);
|
|
|
|
|
else if ((unsigned char)str[i]==191) print_char_hv('?', x+pos*4, y);
|
|
|
|
|
} else if ((unsigned char)str[i]==195) {
|
|
|
|
|
i++;
|
|
|
|
|
print_char(t195_char[(unsigned char)str[i]-128], x+pos*4, y);
|
|
|
|
|
print_symbol(t195_symbol[(unsigned char)str[i]-128], x+pos*4, y);
|
|
|
|
|
} else {
|
|
|
|
|
print_char(str[i], x+pos*4, y);
|
|
|
|
|
}
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void old_print(const char *str, int x, int y, uint8_t color) {
|
|
|
|
|
ds::pen_color=color;
|
|
|
|
|
print(str, x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const uint8_t printchar(uint8_t c, int x, int y) {
|
|
|
|
|
char_t &chr = current_font->chars[c];
|
|
|
|
|
blit(chr.x, chr.y, chr.w, chr.h, x, y-chr.base);
|
|
|
|
|
@@ -1150,12 +1050,12 @@ void print(const char* str, int x, int y, uint8_t color) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clip(int x, int y, int w, int h) {
|
|
|
|
|
ds::clp[0] = x; ds::clp[1] = y; ds::clp[2] = w; ds::clp[3] = h;
|
|
|
|
|
ds::clip[0] = x; ds::clip[1] = y; ds::clip[2] = w-x-1; ds::clip[3] = h-y-1;
|
|
|
|
|
recalculate_clip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void clip() {
|
|
|
|
|
ds::clp[0] = ds::clp[1] = 0; ds::clp[2] = dest_surface->w; ds::clp[3] = dest_surface->h;
|
|
|
|
|
ds::clip[0] = ds::clip[1] = 0; ds::clip[2] = dest_surface->w-1; ds::clip[3] = dest_surface->h-1;
|
|
|
|
|
recalculate_clip();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -1776,10 +1676,6 @@ bool beat(int16_t i) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int rnd(int x) {
|
|
|
|
|
return rand()%x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getfps() {
|
|
|
|
|
return fps;
|
|
|
|
|
}
|