diff --git a/SMILEBASIC/graphic.d b/SMILEBASIC/graphic.d index 3706380..274facb 100644 --- a/SMILEBASIC/graphic.d +++ b/SMILEBASIC/graphic.d @@ -200,6 +200,7 @@ class Graphic } @property void useGRP(int page) { + glBindFramebufferEXT(GL_FRAMEBUFFER, this.GRP[page].buffer); usePage[petitcom.displaynum] = page; } @property void showGRP(int page) @@ -434,6 +435,18 @@ class Graphic glDisable(GL_ALPHA_TEST); glDisable(GL_DEPTH_TEST); } + int drc = 0; + void display(int display) + { + void chScreen(int x, int y, int w, int h) + { + glViewport(x, y, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(x, x + w - 1, y, y + h - 1, -256, 1024);//wakaranai + } + chScreen(writeArea[display].x, writeArea[display].y, writeArea[display].w, writeArea[display].h); + } void draw2() { if (!GRP[0].glTexture) @@ -561,6 +574,7 @@ class Graphic glDisable(GL_TEXTURE_2D); glDisable(GL_ALPHA_TEST); glDisable(GL_DEPTH_TEST); + drc++; } DrawMessage[] drawMessageQueue = new DrawMessage[1]; int drawMessageLength; @@ -568,9 +582,9 @@ class Graphic bool flushRequired; void updateVM() { - if (flushRequired) + if (drc) glFlush(); - flushRequired = false; + drc = 0; } void sendDrawMessage(DrawMessage dm) { @@ -580,7 +594,6 @@ class Graphic } drawMessageQueue[0] = dm; draw2(); - flushRequired = true; } void sendDrawMessage(DrawType type, byte page, short x, short y, uint color) { @@ -606,26 +619,57 @@ class Graphic dm.display = cast(byte)petitcom.displaynum; sendDrawMessage(dm); } + uint convertColor(uint color) + { + return petitcom.toGLColor(this.GRP[0].textureFormat, color & 0xFFF8F8F8); + } //TODO:範囲チェック void gpset(int page, int x, int y, uint color) { - sendDrawMessage(DrawType.PSET, cast(byte)page, cast(short)x, cast(short)y, color); + color = convertColor(color); + glBegin(GL_POINTS); + glColor4ubv(cast(ubyte*)&color); + glVertex2f(x, y); + glEnd(); + drc++; } void gline(int page, int x, int y, int x2, int y2, uint color) { - sendDrawMessage(DrawType.LINE, cast(byte)page, cast(short)x, cast(short)y, cast(short)x2, cast(short)y2, color); + color = convertColor(color); + glBegin(GL_LINES); + glColor4ubv(cast(ubyte*)&color); + glVertex2f(x, y); + glVertex2f(x2, y2); + glEnd(); + drc++; } void gbox(int page, int x, int y, int x2, int y2, uint color) { - sendDrawMessage(DrawType.BOX, cast(byte)page, cast(short)x, cast(short)y, cast(short)x2, cast(short)y2, color); + color = convertColor(color); + glBegin(GL_LINE_LOOP); + glColor4ubv(cast(ubyte*)&color); + glVertex2f(x, y); + glVertex2f(x, y2); + glVertex2f(x2, y2); + glVertex2f(x2, y); + glEnd(); + drc++; } void gfill(int page, int x, int y, int x2, int y2, uint color) { - sendDrawMessage(DrawType.FILL, cast(byte)page, cast(short)x, cast(short)y, cast(short)x2, cast(short)y2, color); + color = convertColor(color); + glBegin(GL_QUADS); + glColor4ubv(cast(ubyte*)&color); + glVertex2f(x, y); + glVertex2f(x, y2); + glVertex2f(x2, y2); + glVertex2f(x2, y); + glEnd(); + drc++; } void gcls(int page, uint color) { - sendDrawMessage(DrawType.FILL, cast(byte)page, 0, 0, cast(short)(width - 1), cast(short)(height - 1), color); + gfill(page, 0, 0, width - 1, height - 1, color); } void gpaint(int page, int x, int y, uint color) { diff --git a/SMILEBASIC/petitcomputer.d b/SMILEBASIC/petitcomputer.d index 8fcc54c..b755782 100644 --- a/SMILEBASIC/petitcomputer.d +++ b/SMILEBASIC/petitcomputer.d @@ -302,7 +302,6 @@ class PetitComputer { console.loadFontTable(); } - display(0); writeln("OK"); } int currentScreenWidth; @@ -316,6 +315,7 @@ class PetitComputer displaynum = number; console.display(number); + graphic.display(number); } SDL_Renderer* renderer; int vsyncFrame; @@ -703,14 +703,6 @@ class PetitComputer console.render(); graphic.render(); - if(xscreenmode == 2) - { - chScreen(0, 0, 320, 480); - } - if(xscreenmode == 1) - { - chScreen(0, 240, 400, 240); - } version(test) glLoadIdentity(); version(test) glRotatef(rot_test_deg, rot_test_x, rot_test_y, rot_test_z); @@ -940,6 +932,7 @@ class PetitComputer renderCondition.wait(); } graphic.initVM(); + display(0); xscreen(0, 512, 4); auto startTicks = SDL_GetTicks(); Parser parser; @@ -1093,11 +1086,12 @@ class PetitComputer { uint elapse; startTicks = SDL_GetTicks(); + int oldmaincnt = maincnt; //do { try { - for(int i = 0; i < 128 && !vsyncFrame && running; i++) + for(int i = 0; !quit && maincnt == oldmaincnt && !vsyncFrame && running; i++) { //writefln("%04X:%s", vm.pc, vm.getCurrent); running = vm.runStep();