Skip to content

Commit

Permalink
Rename EXPERIMENTAL_CGB to CGB. Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
veikkos committed Apr 14, 2019
1 parent 895f129 commit a56f972
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 63 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ matrix:
- sudo apt-get install -y libsdl2-dev --no-install-suggests --no-install-recommends
script:
- mkdir build && cd build
- cmake ..
- cmake -DCGB=OFF ..
- make
compiler: clang
- language: c
before_script:
- sudo apt-get install -y libsdl2-dev --no-install-suggests --no-install-recommends
script:
- mkdir build && cd build
- cmake ..
- cmake -DCGB=OFF ..
- make
compiler: gcc
- language: c
before_script:
- sudo apt-get install -y libsdl2-dev --no-install-suggests --no-install-recommends
script:
- mkdir build && cd build
- cmake -DEXPERIMENTAL_CGB=ON ..
- cmake -DCGB=ON ..
- make
compiler: clang
- language: c
before_script:
- sudo apt-get install -y libsdl2-dev --no-install-suggests --no-install-recommends
script:
- mkdir build && cd build
- cmake -DEXPERIMENTAL_CGB=ON ..
- cmake -DCGB=ON ..
- make
compiler: gcc
- language: android
Expand Down
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
cmake_minimum_required(VERSION 2.8.12)
project(chester)

option (EXPERIMENTAL_CGB "Experimental CGB support." OFF)
option (CGB "CGB support." ON)

if (EXPERIMENTAL_CGB)
if (CGB)
message(STATUS "")
message(STATUS " *************************************")
message(STATUS " * Enabled experimental CGB support! *")
message(STATUS " ************************************* ")
message(STATUS " ************************")
message(STATUS " * Enabled CGB support! *")
message(STATUS " ************************ ")
message(STATUS "")

add_definitions(-DEXPERIMENTAL_CGB)
add_definitions(-DCGB)

option (COLOR_CORRECTION "Emulate original display colors." OFF)
option (COLOR_CORRECTION "Emulate original display colors." ON)

if (COLOR_CORRECTION)
add_definitions(-DCOLOR_CORRECTION)
Expand Down
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ Chester has not been extensively tested. However, it doesn't have any major know

## What it does ##

Chester does play several tested ROM-only, MBC1 and MBC3 games. It supports in-game saving for battery backed MBC1/MBC3 cartridges. Its accurate CPU instruction implementation passes Blargg's CPU instruction tests.
Chester does play several tested ROM-only, MBC1, MBC3 and MBC5 games. It also supports Game Boy Color games and in-game saving for battery backed cartridges. Its accurate CPU instruction implementation passes Blargg's CPU instruction tests.

## What is it missing ##

Most of the emulators have some inaccuracies but it doesn't mean they aren't usable in practise. Chester also has its limitations. It's missing sound support, (very) accurate instruction and memory timing, (very) accurate timers, full support for many cartridge types, full GPU accuracy... And probably few other things.
Most of the emulators have some inaccuracies but it doesn't mean they aren't usable in practise. Chester also has its limitations. It's missing sound support, (very) accurate instruction and memory timing, (very) accurate timers, full support for some cartridge types, full GPU accuracy... And probably few other things.

## Dependencies ##

Expand Down Expand Up @@ -77,6 +77,21 @@ $ cd android/ChesterApp/
$ ./gradlew build
```

### Build options ###

| | Description | Options |
|------------------|----------------------------------------------|--------------|
| CGB | Game Boy Color support | **ON** / OFF |
| COLOR_CORRECTION | Primitive color correction if CGB is enabled | **ON** / OFF |

**Bolded** is default value.

Usage e.g.

```
$ cmake -DCGB=OFF ..
```

## Tested platforms ##

* Ubuntu 14.04 LTS
Expand Down
2 changes: 1 addition & 1 deletion android/ChesterApp/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.4.1)

file(GLOB ChesterSrcs ../../../src/lib/*.c)

add_definitions(-DEXPERIMENTAL_CGB -DCOLOR_CORRECTION -DRGBA8888)
add_definitions(-DCGB -DCOLOR_CORRECTION -DRGBA8888)

add_library(native-lib
SHARED
Expand Down
2 changes: 1 addition & 1 deletion src/lib/chester.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool init(chester *chester, const char* rom, const char* save_path, const char*

mmu_set_rom(&chester->mem, chester->rom, type, rom_size);

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
switch (chester->rom[0x0143])
{
case 0x80:
Expand Down
8 changes: 4 additions & 4 deletions src/lib/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void cpu_reset(registers *reg)
reg->pc = 0x0100;
reg->sp = 0xFFFE;

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
reg->af = 0x11B0;
#else
reg->af = 0x01B0;
Expand All @@ -28,7 +28,7 @@ void cpu_reset(registers *reg)
reg->timer.tick = 0;
reg->timer.div = 0;

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
reg->speed_shifter = 0;
#endif
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ int cpu_next_command(registers *reg, memory *mem)
{
reg->clock.last.t = 4;

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
// CPU speed switch check
uint8_t *key1 = &mem->high_empty[MEM_KEY1_ADDR - MEM_HIGH_EMPTY_START_ADDR];
if (*key1 & MEM_KEY1_PREPARE_SPEED_SWITCH_BIT)
Expand Down Expand Up @@ -2245,7 +2245,7 @@ int cpu_next_command(registers *reg, memory *mem)
return 1;
}

#if EXPERIMENTAL_CGB
#if CGB
reg->clock.last.t >>= reg->speed_shifter;
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/lib/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct registers_s {
struct {
unsigned int tick, div, t_timer;
} timer;
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
uint8_t speed_shifter;
#endif
};
Expand Down
46 changes: 23 additions & 23 deletions src/lib/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void gpu_debug_print(gpu *g, level l)
}
#endif

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
#ifdef COLOR_CORRECTION
// Adaptation of http://alienryderflex.com/saturation.html by Darel Rex Finley
static inline void change_saturation(uint8_t *r, uint8_t *g, uint8_t *b, const double change)
Expand Down Expand Up @@ -149,13 +149,13 @@ static inline const uint8_t *get_mono_color(const unsigned int raw_color,

static inline const uint8_t *get_color_data(const unsigned int raw_color,
const uint8_t mono_palette
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, const uint8_t *color_palette
#endif
)
{
return
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
color_palette ?
get_color(raw_color, color_palette) :
#endif
Expand All @@ -171,7 +171,7 @@ void write_texture(uint8_t line,
bool priority,
bool x_flip,
uint8_t mono_palette
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, const uint8_t *color_palette,
bool bg_priority
#endif
Expand Down Expand Up @@ -207,14 +207,14 @@ void write_texture(uint8_t line,
if (transparent)
{
if (raw_color &&
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
row_data[x_position] != PRIORITY_COLOR &&
#endif
(priority ||
(!row_data[x_position])))
{
memcpy(texture + output_pixel_offset, get_color_data(raw_color, mono_palette
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, color_palette
#endif
), 3);
Expand All @@ -228,15 +228,15 @@ void write_texture(uint8_t line,
else
{
memcpy(texture + output_pixel_offset, get_color_data(raw_color, mono_palette
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, color_palette
#endif
), 3);
texture[output_pixel_offset + 3] = 255;
if (row_data)
{
row_data[x_position] =
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
bg_priority && raw_color ?
PRIORITY_COLOR :
#endif
Expand All @@ -249,19 +249,19 @@ void write_texture(uint8_t line,

static inline uint16_t get_tile_data(memory *mem,
const uint16_t address
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, const uint8_t tile_vram_bank_number
#endif
)
{
uint16_t tile_data = mem->video_ram
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
[tile_vram_bank_number]
#endif
[address];

tile_data += mem->video_ram
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
[tile_vram_bank_number]
#endif
[address + 1] << 8;
Expand Down Expand Up @@ -289,7 +289,7 @@ static inline void process_background_tiles(memory *mem,
const uint16_t tile_base_addr = tile_data_addr + (line_modulo * 2);
uint16_t addr =
tile_map_addr + (line_offset * 32) - 0x8000;
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
const uint16_t base_addr = addr;
const uint8_t* color_palette = NULL;
bool horizontal_flip = false;
Expand All @@ -299,15 +299,15 @@ static inline void process_background_tiles(memory *mem,
#endif

const uint8_t mono_palette =
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
mem->cgb_mode ? 0 :
#endif
mmu_read_byte(mem, MEM_BGP_ADDR);

for(tile_pos=0; tile_pos<32; ++tile_pos)
{
uint8_t id = mem->video_ram
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
[MEM_CHARACTER_CODE_BANK_INDEX]
#endif
[addr++];
Expand All @@ -316,7 +316,7 @@ static inline void process_background_tiles(memory *mem,
if (tile_data_addr == MEM_TILE_ADDR_1)
id += 128;

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
if (mem->cgb_mode)
{
const uint8_t bg_map = mem->video_ram[MEM_ATTRIBUTES_CODE_BANK_INDEX][base_addr + tile_pos];
Expand All @@ -336,7 +336,7 @@ static inline void process_background_tiles(memory *mem,

tile_data = get_tile_data(mem,
tile_base_addr_final
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
+ vertical_flip_data_offset
, tile_vram_bank_number
#endif
Expand All @@ -349,13 +349,13 @@ static inline void process_background_tiles(memory *mem,
row_data,
false,
true,
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
horizontal_flip,
#else
false,
#endif
mono_palette
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, color_palette,
priority
#endif
Expand Down Expand Up @@ -384,7 +384,7 @@ static inline void process_sprite_attributes(memory *mem,
}sprite_attributes;
// Read sprites back to front to get priority correct
attribute_map_addr += number_of_sprites * sprite_attributes_len - 1;
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
const uint8_t* color_palette = NULL;
uint8_t tile_vram_bank_number = 0;
#endif
Expand Down Expand Up @@ -413,7 +413,7 @@ static inline void process_sprite_attributes(memory *mem,
const bool y_flip = sprite_attributes.flags & OBJ_Y_FLIP_FLAG;
uint8_t sprite_line = (line - sprite_attributes.pos.y) % height;

#ifdef EXPERIMENTAL_CGB
#ifdef CGB
if (mem->cgb_mode)
{
const uint8_t palette_num = sprite_attributes.flags & PALETTE_NUM_MASK;
Expand All @@ -424,7 +424,7 @@ static inline void process_sprite_attributes(memory *mem,
{
#endif
mono_palette = mmu_read_byte(mem, mono_palette_address);
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
}
#endif

Expand All @@ -439,7 +439,7 @@ static inline void process_sprite_attributes(memory *mem,

tile_data = get_tile_data(mem,
tile_base_addr_final
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, tile_vram_bank_number
#endif
);
Expand All @@ -453,7 +453,7 @@ static inline void process_sprite_attributes(memory *mem,
priority,
x_flip,
mono_palette
#ifdef EXPERIMENTAL_CGB
#ifdef CGB
, color_palette,
false
#endif
Expand Down
Loading

0 comments on commit a56f972

Please sign in to comment.