commit 5c7eb4f
zzo38
·
2022-11-05 22:00:23 +0000 UTC
parent 44703a1
Do not set the display size until it is known.
1 files changed,
+37,
-31
M
main.c
M
main.c
+37,
-31
1@@ -579,6 +579,21 @@ static Uint8 datetime_in(Device*dev,Uint8 id) {
2 }
3 }
4
5+static void set_cursor(void) {
6+ if(hide_cursor) SDL_ShowCursor(paused || !use_mouse);
7+}
8+
9+static Uint32 timer_callback(Uint32 interval) {
10+ if(!timer_expired) {
11+ SDL_Event e;
12+ timer_expired=1;
13+ e.type=SDL_USEREVENT;
14+ SDL_PushEvent(&e);
15+ timer_expired=1;
16+ }
17+ return interval;
18+}
19+
20 static void set_screen_mode(int w,int h) {
21 picture_changed=size_changed=0;
22 free(bglayer);
23@@ -589,6 +604,17 @@ static void set_screen_mode(int w,int h) {
24 scr_h=h;
25 screen=SDL_SetVideoMode(w*zoom,h*zoom,8,scrflags);
26 if(!screen) errx(1,"Cannot set screen mode: %s",SDL_GetError());
27+ if(!bglayer) {
28+ if(timer_rate) SDL_SetTimer(timer_rate,timer_callback);
29+ if(audio_option) {
30+ if(SDL_OpenAudio(&audiospec,0)) errx(1,"Cannot initialize SDL audio: %s",SDL_GetError());
31+ SDL_PauseAudio(0);
32+ }
33+ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
34+ SDL_WM_SetCaption(rom_name,rom_name);
35+ set_cursor();
36+ SDL_EnableUNICODE(1);
37+ }
38 SDL_SetColors(screen,colors+palet*8,0,8);
39 bglayer=calloc(w*h,2);
40 if(!bglayer) err(1,"Memory allocation error");
41@@ -680,17 +706,6 @@ static void audio_out(Device*dev,Uint8 id) {
42 SDL_UnlockAudio();
43 }
44
45-static Uint32 timer_callback(Uint32 interval) {
46- if(!timer_expired) {
47- SDL_Event e;
48- timer_expired=1;
49- e.type=SDL_USEREVENT;
50- SDL_PushEvent(&e);
51- timer_expired=1;
52- }
53- return interval;
54-}
55-
56 static Uint32 envelope(const UxnAudio*a) {
57 // Returns a number from 0 to 64.
58 Uint32 t=a->envtime;
59@@ -770,10 +785,6 @@ static void redraw(void) {
60 SDL_Flip(screen);
61 }
62
63-static void set_cursor(void) {
64- if(hide_cursor) SDL_ShowCursor(paused || !use_mouse);
65-}
66-
67 static int run_screen(void) {
68 SDL_Event e;
69 int i,j,k;
70@@ -931,24 +942,18 @@ int main(int argc,char**argv) {
71 if(default_height<1 || default_width<1) errx(1,"Screen size out of range");
72 if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|(audio_option?SDL_INIT_AUDIO:0))) errx(1,"Cannot initialize SDL: %s",SDL_GetError());
73 atexit(SDL_Quit);
74- set_screen_mode(default_width,default_height);
75- SDL_EnableUNICODE(1);
76 device[2].out=screen_out;
77- PUT16(device[2].d+2,default_width);
78- PUT16(device[2].d+4,default_height);
79- if(timer_rate) SDL_SetTimer(timer_rate,timer_callback);
80- if(audio_option) {
81- if(SDL_OpenAudio(&audiospec,0)) errx(1,"Cannot initialize SDL audio: %s",SDL_GetError());
82- SDL_PauseAudio(0);
83- }
84- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL);
85- SDL_WM_SetCaption(rom_name,rom_name);
86- set_cursor();
87+ scr_w=default_width;
88+ scr_h=default_height;
89+ PUT16(device[2].d+2,scr_w);
90+ PUT16(device[2].d+4,scr_h);
91+ size_changed=1;
92 }
93 if(use_console) device[1].out=console_out;
94 if(device[12].d[15]) device[12].d[15]=0; else device[12].in=datetime_in;
95 if(optind+1<argc) strncpy(uxnfile0.name,argv[optind+1],4095);
96 if(optind+2<argc) strncpy(uxnfile1.name,argv[optind+2],4095);
97+ restart:
98 run(0x0100);
99 if(device[1].d[0] || device[1].d[1]) for(i=optind+1;i<argc;i++) {
100 for(j=0;argv[i][j];j++) {
101@@ -960,13 +965,14 @@ int main(int argc,char**argv) {
102 }
103 if(device[15].out==extension_out) run(GET16(device[15].d));
104 if(use_screen) {
105+ if(size_changed) set_screen_mode(scr_w,scr_h);
106 while(run_screen()) {
107 for(i=0;i<15;i++) for(j=0;j<16;j++) device[i].d[j]=0;
108 load_rom();
109- PUT16(device[2].d+2,default_width);
110- PUT16(device[2].d+4,default_height);
111- set_screen_mode(default_width,default_height);
112- run(0x0100);
113+ // PUT16(device[2].d+2,default_width);
114+ // PUT16(device[2].d+4,default_height);
115+ // set_screen_mode(default_width,default_height);
116+ goto restart;
117 }
118 } else {
119 while((device[1].d[0] || device[1].d[1]) && ((i=getchar())>=0)) {