From c2e117745fb0ba5c6563ac75631e155c36d82966 Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Tue, 28 Feb 2017 08:15:11 -0500 Subject: [PATCH] abstract the difference between the rowspans in various bitmaps --- apple/appledisplay.cpp | 24 ++++++++++++++++++++++-- apple/applevm.cpp | 3 --- display-bg.h | 6 ++++-- sdl/aiie.cpp | 4 +++- sdl/sdl-display.cpp | 10 +++++----- sdl/sdl-display.h | 4 ++++ sdl/sdl-paddles.cpp | 9 +++------ teensy/teensy-display.cpp | 12 ++++++------ teensy/teensy-display.h | 3 +++ teensy/teensy.ino | 4 +--- vm.h | 3 ++- 11 files changed, 53 insertions(+), 29 deletions(-) diff --git a/apple/appledisplay.cpp b/apple/appledisplay.cpp index e8f2196..affa6dd 100644 --- a/apple/appledisplay.cpp +++ b/apple/appledisplay.cpp @@ -30,8 +30,10 @@ } \ } +#if DISPLAYRUN == 512 + #define drawPixel(c, x, y) { \ - uint16_t idx = ((y) * DISPLAYWIDTH + (x)) / 2; \ + uint16_t idx = (((y) << 9) + (x)) >> 1; \ if ((x) & 1) { \ videoBuffer[idx] = (videoBuffer[idx] & 0xF0) | (c); \ } else { \ @@ -40,10 +42,28 @@ } #define draw2Pixels(cAB, x, y) { \ - videoBuffer[((y) * DISPLAYWIDTH + (x)) /2] = cAB; \ + videoBuffer[(((y) <<9) + (x)) >> 1] = cAB; \ } +#else + +#define drawPixel(c, x, y) { \ + uint16_t idx = ((y) * DISPLAYRUN + (x)) / 2; \ + if ((x) & 1) { \ + videoBuffer[idx] = (videoBuffer[idx] & 0xF0) | (c); \ + } else { \ + videoBuffer[idx] = (videoBuffer[idx] & 0x0F) | ((c) << 4); \ + } \ + } + +#define draw2Pixels(cAB, x, y) { \ + videoBuffer[((y) * DISPLAYRUN + (x)) /2] = cAB; \ + } + +#endif + + #define DrawLoresPixelAt(c, x, y) { \ uint8_t pixel = c & 0x0F; \ for (uint8_t y2 = 0; y2<4; y2++) { \ diff --git a/apple/applevm.cpp b/apple/applevm.cpp index 63902f6..2ad1df2 100644 --- a/apple/applevm.cpp +++ b/apple/applevm.cpp @@ -23,11 +23,8 @@ AppleVM::AppleVM() parallel = new ParallelCard(); ((AppleMMU *)mmu)->setSlot(1, parallel); - mockingboard = NULL; - /* mockingboard = new Mockingboard(); ((AppleMMU *)mmu)->setSlot(4, mockingboard); - */ #ifdef TEENSYDUINO teensyClock = new TeensyClock((AppleMMU *)mmu); diff --git a/display-bg.h b/display-bg.h index c49fdde..ed9d578 100644 --- a/display-bg.h +++ b/display-bg.h @@ -2,9 +2,11 @@ #define PROGMEM #endif -// 320x240 +#define DBITMAP_HEIGHT 240 +#define DBITMAP_WIDTH 320 + static -uint8_t displayBitmap[] PROGMEM = { +uint8_t displayBitmap[DBITMAP_HEIGHT*DBITMAP_WIDTH*3] PROGMEM = { 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, 0xD9, 0xCA, 0x9F, diff --git a/sdl/aiie.cpp b/sdl/aiie.cpp index f780824..df15594 100644 --- a/sdl/aiie.cpp +++ b/sdl/aiie.cpp @@ -262,11 +262,13 @@ int main(int argc, char *argv[]) uint32_t lenSecs = time(NULL) - startAt; if (lenSecs >= 5) { float fps = loopCount / lenSecs; + #ifdef SHOWFPS char buf[25]; - sprintf(buf, "%f FPS", fps); + sprintf(buf, "%f FPS [delay %u]", fps, usleepcycles); g_display->debugMsg(buf); #endif + if (fps > 60) { usleepcycles *= 2; } else if (fps < 40) { diff --git a/sdl/sdl-display.cpp b/sdl/sdl-display.cpp index ddbd348..53b02de 100644 --- a/sdl/sdl-display.cpp +++ b/sdl/sdl-display.cpp @@ -32,7 +32,7 @@ SDLDisplay::SDLDisplay() screen = SDL_CreateWindow("Aiie!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 320*2, 240*2, + SDLDISPLAY_WIDTH, SDLDISPLAY_HEIGHT, SDL_WINDOW_SHOWN); // SDL_RENDERER_SOFTWARE because, at least on my Mac, this has some @@ -54,9 +54,9 @@ void SDLDisplay::redraw() // bios. Draws the background image. printf("redraw background\n"); - for (int y=0; y<240; y++) { - for (int x=0; x<320; x++) { - uint8_t *p = &displayBitmap[(y * 320 + x)*3]; + for (int y=0; y #include "sdl-paddles.h" -// FIXME: abstract this somewhere - -#define WINDOWHEIGHT (240*2) -#define WINDOWWIDTH (320*2) +#include "sdl-display.h" #include "globals.h" @@ -35,6 +32,6 @@ uint8_t SDLPaddles::paddle1() void SDLPaddles::gotMouseMovement(uint16_t x, uint16_t y) { - p0 = ((float)x / (float)WINDOWWIDTH) * (float) 255.0; - p1 = ((float)y / (float)WINDOWHEIGHT) * (float) 255.0; + p0 = ((float)x / (float)SDLDISPLAY_WIDTH) * (float) 255.0; + p1 = ((float)y / (float)SDLDISPLAY_HEIGHT) * (float) 255.0; } diff --git a/teensy/teensy-display.cpp b/teensy/teensy-display.cpp index 498fa81..5363a92 100644 --- a/teensy/teensy-display.cpp +++ b/teensy/teensy-display.cpp @@ -212,11 +212,11 @@ void TeensyDisplay::redraw() moveTo(0, 0); - for (int y=0; y<240; y++) { - for (int x=0; x<320; x++) { - uint8_t r = pgm_read_byte(&displayBitmap[(y * 320 + x)*3 + 0]); - uint8_t g = pgm_read_byte(&displayBitmap[(y * 320 + x)*3 + 1]); - uint8_t b = pgm_read_byte(&displayBitmap[(y * 320 + x)*3 + 2]); + for (int y=0; y> 3); setPixel(color16); } @@ -391,7 +391,7 @@ void TeensyDisplay::blit(AiieRect r) uint16_t pixel; for (uint8_t y=r.top; y<=r.bottom; y++) { for (uint16_t x=r.left; x<=r.right; x++) { - pixel = y * (DISPLAYWIDTH/2) + (x/2); + pixel = y * (DISPLAYRUN >> 1) + (x >> 1); uint8_t colorIdx; if (!(x & 0x01)) { colorIdx = videoBuffer[pixel] >> 4; diff --git a/teensy/teensy-display.h b/teensy/teensy-display.h index 86bc605..0c524b3 100644 --- a/teensy/teensy-display.h +++ b/teensy/teensy-display.h @@ -4,6 +4,9 @@ #include #include "physicaldisplay.h" +#define TEENSY_DHEIGHT 240 +#define TEENSY_DWIDTH 320 + enum { M_NORMAL = 0, M_SELECTED = 1, diff --git a/teensy/teensy.ino b/teensy/teensy.ino index e67dbe1..cb0246c 100644 --- a/teensy/teensy.ino +++ b/teensy/teensy.ino @@ -26,8 +26,6 @@ volatile float startMicros; FATFS fatfs; /* File system object */ BIOS bios; -uint8_t videoBuffer[DISPLAYWIDTH*DISPLAYHEIGHT/2]; - enum { D_NONE = 0, D_SHOWFPS = 1, @@ -38,7 +36,7 @@ enum { D_SHOWBATTERY = 6, D_SHOWTIME = 7 }; -uint8_t debugMode = D_NONE; +uint8_t debugMode = D_SHOWFPS; static time_t getTeensy3Time() { return Teensy3Clock.get(); } diff --git a/vm.h b/vm.h index ca449d4..d5afe28 100644 --- a/vm.h +++ b/vm.h @@ -10,10 +10,11 @@ #define DISPLAYWIDTH 320 #define DISPLAYHEIGHT 240 +#define DISPLAYRUN 320 // how wide each row is in pixels in the buffer (for faster math) class VM { public: - VM() { mmu=NULL; vmdisplay = NULL; videoBuffer = (uint8_t *)calloc(DISPLAYWIDTH * DISPLAYHEIGHT / 2, 1); hasIRQ = false;} + VM() { mmu=NULL; vmdisplay = NULL; videoBuffer = (uint8_t *)calloc(DISPLAYRUN * DISPLAYHEIGHT / 2, 1); hasIRQ = false;} virtual ~VM() { if (mmu) delete mmu; if (vmdisplay) delete vmdisplay; free(videoBuffer); } virtual void SetMMU(MMU *mmu) { this->mmu = mmu; }