Skip to content

Commit e7dfd4c

Browse files
committed
Add option to control the window scale
1 parent 5400d12 commit e7dfd4c

File tree

6 files changed

+26
-10
lines changed

6 files changed

+26
-10
lines changed

src/core.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ void free_block(gb_block *block)
1010
munmap(block->mem, block->size);
1111
}
1212

13-
bool init_vm(gb_vm *vm, const char *filename, int opt_level, bool init_io)
13+
bool init_vm(gb_vm *vm,
14+
const char *filename,
15+
int opt_level,
16+
int scale,
17+
bool init_io)
1418
{
1519
if (!gb_memory_init(&vm->memory, filename))
1620
return false;
@@ -90,7 +94,7 @@ bool init_vm(gb_vm *vm, const char *filename, int opt_level, bool init_io)
9094

9195
if (init_io) {
9296
/* both audio and lcd will be initialized if init_io is true*/
93-
if (!init_window(&vm->lcd))
97+
if (!init_window(&vm->lcd, scale))
9498
return false;
9599

96100
vm->draw_frame = true;

src/core.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,12 @@ typedef struct {
3131

3232
void free_block(gb_block *block);
3333

34-
bool init_vm(gb_vm *vm, const char *filename, int opt_level, bool init_io);
3534
bool run_vm(gb_vm *vm);
35+
bool init_vm(gb_vm *vm,
36+
const char *filename,
37+
int opt_level,
38+
int scale,
39+
bool init_io);
3640
bool free_vm(gb_vm *vm);
3741

3842
#endif

src/lcd.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ static int render_thread_function(void *ptr)
181181
return 0;
182182
}
183183

184-
bool init_window(gb_lcd *lcd)
184+
bool init_window(gb_lcd *lcd, int scale)
185185
{
186186
SDL_Init(SDL_INIT_VIDEO);
187+
int width = 160 * scale;
188+
int height = 144 * scale;
187189
lcd->win = SDL_CreateWindow("jitboy", SDL_WINDOWPOS_UNDEFINED,
188-
SDL_WINDOWPOS_UNDEFINED, 160 * 3, 144 * 3,
190+
SDL_WINDOWPOS_UNDEFINED, width, height,
189191
SDL_WINDOW_OPENGL);
190192
if (!lcd->win) {
191193
LOG_ERROR("Window could not be created! SDL_Error: %s\n",

src/lcd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef struct {
1313
bool fullscreen;
1414
} gb_lcd;
1515

16-
bool init_window(gb_lcd *lcd);
16+
bool init_window(gb_lcd *lcd, int scale);
1717
void deinit_window(gb_lcd *lcd);
1818
void update_line(uint8_t *mem);
1919
void toggle_fullscreen(gb_lcd *lcd);

src/main.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ static void usage(const char *exe)
1111
printf(
1212
"Usage: %s [OPTIONS]\n"
1313
"Options:\n"
14-
" -O, --opt-level=LEVEL Set the optimization level (default: 0)\n",
14+
" -O, --opt-level=LEVEL Set the optimization level (default: 0)\n"
15+
" -s, --scale=SCALE Set the scale of the window (default: 3)\n",
1516
exe);
1617
}
1718

@@ -48,16 +49,21 @@ int main(int argc, char *argv[])
4849
}
4950

5051
int opt_level = 0;
52+
int scale = 3;
5153
int c;
5254
const struct option long_options[] = {
5355
{"opt-level", required_argument, NULL, 'O'},
56+
{"scale", required_argument, NULL, 's'},
5457
{NULL, 0, NULL, 0} // Terminating element
5558
};
56-
while ((c = getopt_long(argc, argv, "O:", long_options, NULL)) != -1) {
59+
while ((c = getopt_long(argc, argv, "O:s:", long_options, NULL)) != -1) {
5760
switch (c) {
5861
case 'O':
5962
sscanf(optarg, "%i", &opt_level);
6063
break;
64+
case 's':
65+
sscanf(optarg, "%i", &scale);
66+
break;
6167
case '?':
6268
default:
6369
usage(argv[0]);
@@ -77,7 +83,7 @@ int main(int argc, char *argv[])
7783

7884
/* initialize memory */
7985
gb_vm *vm = malloc(sizeof(gb_vm));
80-
if (!init_vm(vm, argv[optind], opt_level, true)) {
86+
if (!init_vm(vm, argv[optind], opt_level, scale, true)) {
8187
LOG_ERROR("Fail to initialize\n");
8288
exit(1);
8389
}

tests/instr_test.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void gbz80_init(size_t tester_instruction_mem_size,
3737
instruction_mem = tester_instruction_mem;
3838

3939
vm = malloc(sizeof(gb_vm));
40-
if (!init_vm(vm, NULL, 0, false)) {
40+
if (!init_vm(vm, NULL, 0, 0, false)) {
4141
LOG_ERROR("Fail to initialize\n");
4242
exit(1);
4343
}

0 commit comments

Comments
 (0)