gbdb,video: improve logging

Add more runtime toggles and add the ability to log to a file for
faster runs and better searchability.
This commit is contained in:
2018-07-22 16:15:10 -07:00
parent 53cd4ab7e5
commit f659af54e1
5 changed files with 227 additions and 102 deletions

View File

@@ -1,5 +1,6 @@
#include "gbemu/video.h"
#include "gbemu/memory.h"
#include "common/common.h"
#include "common/bmp.h"
#include <string.h>
@@ -30,6 +31,8 @@ static uint8_t color_tbl[4] = {
void gb_video_init(struct gb_video *video, struct gb_memory *memory)
{
memset(video, 0, sizeof(*video));
video->debug_logging = 0;
video->memory = memory;
bmp = bmp_new(BMP_GRAYSCALE, BUFFER_WIDTH, BUFFER_HEIGHT);
@@ -47,14 +50,9 @@ static void gb_video_fetch_tile_data(struct gb_video *video, uint8_t *databuf,
uint16_t addr = tile_addr + (index * TILE_BYTES) + i;
databuf[i] = gb_mem_read(video->memory, addr);
if (log && databuf[i] != 0) {
printf("addr=%x, databuf[%d]=%x\n", addr, i, databuf[i]);
logged = 1;
}
}
if (log && logged) {
printf("\n");
}
}
static void gb_video_screenshot(struct gb_video *video)
@@ -69,7 +67,6 @@ static void gb_video_screenshot(struct gb_video *video)
int log = id == 30;
snprintf(filename, sizeof(filename), "screenshot-%d.bmp", id++);
printf("Rendering screenshot %s\n", filename);
if (!(video->lcdcont & 1)) {
goto out;
@@ -84,11 +81,6 @@ static void gb_video_screenshot(struct gb_video *video)
tile = gb_mem_read(video->memory, addr);
gb_video_fetch_tile_data(video, tile_data, tile, log);
if (log) {
printf("Tile_x=%d, tile_y=%d, addr=%x, tile=%d\n",
tile_x, tile_y, addr, tile);
}
for (i = 0 ; i < TILE_WIDTH * TILE_HEIGHT; i++) {
int offset_x = i % TILE_WIDTH;
int offset_y = i / TILE_WIDTH;
@@ -103,11 +95,6 @@ static void gb_video_screenshot(struct gb_video *video)
total_x = tile_x * TILE_WIDTH + (7 - offset_x);
total_y = tile_y * TILE_HEIGHT + offset_y;
if (log && color != 0) {
printf("offset=%d, total_x=%d, total_y=%d, td_index=%d, color=%d\n",
total_y * BUFFER_WIDTH + total_x, total_x, total_y, td_index, color);
}
buffer[(BUFFER_HEIGHT - total_y) * BUFFER_WIDTH + total_x] = color_tbl[color];
}
}
@@ -134,31 +121,52 @@ void gb_video_cycle(struct gb_video *video, int cycles)
uint8_t gb_video_mem_read(struct gb_video *video, uint16_t addr)
{
uint8_t val;
switch (addr) {
case 0xFF40:
return video->lcdcont;
val = video->lcdcont;
break;
case 0xFF41:
return video->lcdstat;
val = video->lcdstat;
break;
case 0xFF42:
return video->scrolly;
val = video->scrolly;
break;
case 0xFF43:
return video->scrollx;
val = video->scrollx;
break;
case 0xFF44:
return video->curline;
val = video->curline;
break;
case 0xFF45:
return video->cmpline;
val = video->cmpline;
break;
case 0xFF4A:
return video->wndposy;
val = video->wndposy;
break;
case 0xFF4B:
return video->wndposx;
val = video->wndposx;
break;
default:
return 0;
val = 0;
}
if (video->debug_logging) {
gb_log("Read Video[%x]=0x%x\n", addr, val);
}
return val;
}
void gb_video_mem_write(struct gb_video *video, uint16_t addr, uint8_t val)
{
uint8_t *write_addr;
if (video->debug_logging) {
gb_log("Video[%x]=%x\n", addr, val);
}
switch (addr) {
case 0xFF40:
write_addr = &video->lcdcont;