mirror of https://github.com/mlaux/gb6.git
almost there, tile ram is empty for some reason
This commit is contained in:
parent
eb779f3690
commit
9601b9f7da
|
@ -48,14 +48,14 @@ GLuint make_output_texture() {
|
||||||
return image_texture;
|
return image_texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char output_image[160 * 144 * 4];
|
unsigned char output_image[256 * 256 * 4];
|
||||||
|
|
||||||
void convert_output(struct lcd *lcd) {
|
void convert_output(struct lcd *lcd) {
|
||||||
int x, y;
|
int x, y;
|
||||||
int out_index = 0;
|
int out_index = 0;
|
||||||
for (y = 0; y < 144; y++) {
|
for (y = 0; y < 256; y++) {
|
||||||
for (x = 0; x < 160; x++) {
|
for (x = 0; x < 256; x++) {
|
||||||
int val = lcd->pixels[y * 160 + x];
|
int val = lcd->buf[y * 256 + x];
|
||||||
int fill = val ? 255 : 0;
|
int fill = val ? 255 : 0;
|
||||||
output_image[out_index++] = val;
|
output_image[out_index++] = val;
|
||||||
output_image[out_index++] = val;
|
output_image[out_index++] = val;
|
||||||
|
@ -77,10 +77,10 @@ void fill_memory_editor(struct dmg *dmg)
|
||||||
// Main code
|
// Main code
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct cpu cpu;
|
struct cpu cpu = { 0 };
|
||||||
struct rom rom;
|
struct rom rom = { 0 };
|
||||||
struct dmg dmg;
|
struct dmg dmg = { 0 };
|
||||||
struct lcd lcd;
|
struct lcd lcd = { 0 };
|
||||||
|
|
||||||
int executed;
|
int executed;
|
||||||
|
|
||||||
|
@ -237,8 +237,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
convert_output(dmg.lcd);
|
convert_output(dmg.lcd);
|
||||||
glBindTexture(GL_TEXTURE_2D, texture);
|
glBindTexture(GL_TEXTURE_2D, texture);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 160, 144, 0, GL_RGBA, GL_UNSIGNED_BYTE, output_image);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, output_image);
|
||||||
ImGui::Image((void*)(intptr_t) texture, ImVec2(160, 144));
|
ImGui::Image((void*)(intptr_t) texture, ImVec2(256, 256));
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,7 @@ int main(int argc, char *argv[])
|
||||||
fill_memory_editor(&dmg);
|
fill_memory_editor(&dmg);
|
||||||
|
|
||||||
editor.DrawWindow("Memory", full_address_space, 0x10000, 0x0000);
|
editor.DrawWindow("Memory", full_address_space, 0x10000, 0x0000);
|
||||||
|
editor.DrawWindow("LCD", dmg.lcd->buf, 0x2000, 0);
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
|
|
31
src/dmg.c
31
src/dmg.c
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "rom.h"
|
#include "rom.h"
|
||||||
|
@ -82,6 +83,36 @@ void dmg_step(void *_dmg)
|
||||||
if (next_scanline == 144) {
|
if (next_scanline == 144) {
|
||||||
// vblank has started, draw all the stuff from ram into the lcd
|
// vblank has started, draw all the stuff from ram into the lcd
|
||||||
|
|
||||||
|
int lcdc = lcd_read(dmg->lcd, REG_LCDC);
|
||||||
|
int bg_base = (lcdc & LCDC_BG_TILE_MAP) ? 0x9c00 : 0x9800;
|
||||||
|
int window_base = (lcdc & LCDC_WINDOW_TILE_MAP) ? 0x9c00 : 0x9800;
|
||||||
|
int use_unsigned = lcdc & LCDC_BG_TILE_DATA;
|
||||||
|
int tilebase = use_unsigned ? 0x8000 : 0x9000;
|
||||||
|
|
||||||
|
printf("base is %04x\n", bg_base);
|
||||||
|
|
||||||
|
int k, off = 0;
|
||||||
|
for (k = 0; k < 1024; k++) {
|
||||||
|
int tile = dmg_read(dmg, bg_base + k);
|
||||||
|
int eff_addr;
|
||||||
|
if (use_unsigned) {
|
||||||
|
eff_addr = tilebase + 16 * tile;
|
||||||
|
} else {
|
||||||
|
eff_addr = tilebase + 16 * (signed char) tile;
|
||||||
|
}
|
||||||
|
int b, i;
|
||||||
|
for (b = 0; b < 16; b += 2) {
|
||||||
|
int data1 = dmg_read(dmg, eff_addr + b);
|
||||||
|
int data2 = dmg_read(dmg, eff_addr + b + 1);
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
// monochrome for now
|
||||||
|
dmg->lcd->buf[off] |= (data1 & (1 << i)) ? 1 : 0;
|
||||||
|
dmg->lcd->buf[off] |= (data2 & (1 << i)) ? 1 : 0;
|
||||||
|
off++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// now copy 256x256 buf to 160x144 based on window registers
|
// now copy 256x256 buf to 160x144 based on window registers
|
||||||
lcd_copy(dmg->lcd);
|
lcd_copy(dmg->lcd);
|
||||||
lcd_draw(dmg->lcd);
|
lcd_draw(dmg->lcd);
|
||||||
|
|
|
@ -59,7 +59,7 @@ void lcd_put_pixel(struct lcd *lcd, u8 x, u8 y, u8 value)
|
||||||
void lcd_copy(struct lcd *lcd)
|
void lcd_copy(struct lcd *lcd)
|
||||||
{
|
{
|
||||||
// use all the registers to compute the pixel data
|
// use all the registers to compute the pixel data
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int lcd_step(struct lcd *lcd)
|
int lcd_step(struct lcd *lcd)
|
||||||
|
|
Loading…
Reference in New Issue