abstract the difference between the rowspans in various bitmaps

This commit is contained in:
Jorj Bauer 2017-02-28 08:15:11 -05:00
parent 2060f366e5
commit c2e117745f
11 changed files with 53 additions and 29 deletions

View File

@ -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++) { \

View File

@ -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);

View File

@ -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,

View File

@ -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) {

View File

@ -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<DISPLAYHEIGHT; y++) {
for (int x=0; x<DISPLAYWIDTH; x++) {
uint8_t *p = &displayBitmap[(y * DBITMAP_WIDTH + x)*3];
drawPixel(x, y, p[0], p[1], p[2]);
}
}
@ -141,7 +141,7 @@ void SDLDisplay::blit(AiieRect r)
for (uint8_t y=0; y<192; y++) {
for (uint16_t x=0; x<280; x++) {
uint16_t pixel = (y*320+x)/2;
uint16_t pixel = (y*DISPLAYRUN+x)/2;
uint8_t colorIdx;
if (x & 1) {
colorIdx = videoBuffer[pixel] & 0x0F;

View File

@ -9,6 +9,10 @@
#include "physicaldisplay.h"
#define SDLDISPLAY_WIDTH (320*2)
#define SDLDISPLAY_HEIGHT (240*2)
enum {
M_NORMAL = 0,
M_SELECTED = 1,

View File

@ -1,10 +1,7 @@
#include <stdio.h>
#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;
}

View File

@ -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<TEENSY_DHEIGHT; y++) {
for (int x=0; x<TEENSY_DWIDTH; x++) {
uint8_t r = pgm_read_byte(&displayBitmap[(y * DBITMAP_WIDTH + x)*3 + 0]);
uint8_t g = pgm_read_byte(&displayBitmap[(y * DBITMAP_WIDTH + x)*3 + 1]);
uint8_t b = pgm_read_byte(&displayBitmap[(y * DBITMAP_WIDTH + x)*3 + 2]);
uint16_t color16 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 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;

View File

@ -4,6 +4,9 @@
#include <Arduino.h>
#include "physicaldisplay.h"
#define TEENSY_DHEIGHT 240
#define TEENSY_DWIDTH 320
enum {
M_NORMAL = 0,
M_SELECTED = 1,

View File

@ -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(); }

3
vm.h
View File

@ -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; }