Added support for running from the command line

Implemented scissoring for points and sprites
Updated README
This commit is contained in:
PSI-Rockin 2018-02-02 19:26:28 -05:00
parent d1eac802ea
commit b0c3d1b98e
6 changed files with 48 additions and 16 deletions

View file

@ -17,14 +17,14 @@ EmuWindow::EmuWindow(QWidget *parent) : QMainWindow(parent)
}
int EmuWindow::init()
int EmuWindow::init(const char* bios_name, const char* file_name)
{
//Initialize emulator
e.reset();
ifstream BIOS_file("bios.bin", ios::binary | ios::in);
ifstream BIOS_file(bios_name, ios::binary | ios::in);
if (!BIOS_file.is_open())
{
printf("Failed to load PS2 BIOS.\n");
printf("Failed to load PS2 BIOS from %s\n", bios_name);
return 1;
}
printf("Loaded PS2 BIOS.\n");
@ -34,7 +34,6 @@ int EmuWindow::init()
e.load_BIOS(BIOS);
delete[] BIOS;
BIOS = nullptr;
const char* file_name = "ps2tut/ps2tut_01/demo1.elf";
ifstream ELF_file(file_name, ios::binary | ios::in);
if (!ELF_file.is_open())

View file

@ -14,7 +14,7 @@ class EmuWindow : public QMainWindow
bool is_running;
public:
explicit EmuWindow(QWidget *parent = nullptr);
int init();
int init(const char* bios_name, const char* ELF_name);
bool running();
void emulate();

View file

@ -661,8 +661,14 @@ void GraphicsSynthesizer::render_point()
color |= vtx_queue[0].rgbaq.r << 16;
color |= vtx_queue[0].rgbaq.g << 8;
color |= vtx_queue[0].rgbaq.b;
printf("\nCoords: (%d, %d)", point[0] >> 4, point[1] >> 4);
draw_pixel(point[0], point[1], color, vtx_queue[0].coords[2], PRIM.alpha_blend);
SCISSOR* scissor = &current_ctx->scissor;
printf("\nCoords: (%d, %d, %d)", point[0] >> 4, point[1] >> 4, point[2]);
if (point[0] >= scissor->x1 && point[0] <= scissor->x2 && point[1] >= scissor->y1 && point[1] <= scissor->y2)
draw_pixel(point[0], point[1], color, point[2], PRIM.alpha_blend);
else
{
printf("\nScissor: (%d, %d) (%d, %d)", scissor->x1, scissor->y1, scissor->x2, scissor->y2);
}
}
void GraphicsSynthesizer::render_line()
@ -722,12 +728,12 @@ void GraphicsSynthesizer::render_sprite()
for (int32_t y = y1; y < y2; y += 0x10)
{
if (y < 0 || (y >> 4) > current_ctx->scissor.y2)
if (y < current_ctx->scissor.y1 || y > current_ctx->scissor.y2)
continue;
uint16_t pix_v = interpolate(y, v1, y1, v2, y2) >> 4;
for (int32_t x = x1; x < x2; x += 0x10)
{
if (x < 0)
if (x < current_ctx->scissor.x1 || x > current_ctx->scissor.x2)
continue;
uint16_t pix_u = interpolate(x, u1, x1, u2, x2) >> 4;
uint32_t tex_coord = current_ctx->tex0.texture_base + pix_u;

View file

@ -49,10 +49,11 @@ void GSContext::set_xyoffset(uint64_t value)
void GSContext::set_scissor(uint64_t value)
{
scissor.x1 = value & 0x7FF;
scissor.x2 = (value >> 16) & 0x7FF;
scissor.y1 = (value >> 32) & 0x7FF;
scissor.y2 = (value >> 48) & 0x7FF;
//Shift by four to compensate for the 4 decimal bits in vertex coords
scissor.x1 = (value & 0x7FF) << 4;
scissor.x2 = ((value >> 16) & 0x7FF) << 4;
scissor.y1 = ((value >> 32) & 0x7FF) << 4;
scissor.y2 = ((value >> 48) & 0x7FF) << 4;
printf("\nSCISSOR: $%08X_%08X", value >> 32, value & 0xFFFFFFFF);
}

View file

@ -7,8 +7,18 @@ int main(int argc, char** argv)
{
QApplication a(argc, argv);
EmuWindow* window = new EmuWindow();
if (window->init())
return 1;
if (argc >= 3)
{
const char* bios_name = argv[1];
const char* ELF_name = argv[2];
if (window->init(bios_name, ELF_name))
return 1;
}
else
{
printf("Arguments: bios_file ELF_file\n");
return 0;
}
while (window->running())
{
a.processEvents();

View file

@ -1 +1,17 @@
A little side project of mine, when I feel like tinkering with it. Not intended for general use.
# DobieStation
A young PS2 emulator with plans for an optimized Android port, as well as a fast, accurate, and easy-to-use PC port. Basic homebrew is capable of running, but nothing else yet. Not intended for general use.
## Compiling
DobieStation uses Qt 5 and currently only supports qmake.
### Building with qmake
```
cd DobieStation/DobieStation
qmake DobieStation.pro
make
```
## Using the Emulator
DobieStation requires a copy of the PS2 BIOS, which must be dumped from your PS2, and can only be run from the command line. Loading files from the GUI will be supported in the near future.
DobieStation takes two arguments from the command line: the name of the BIOS file, and the name of an ELF file.