Post Reply 
Emu48 Javascript ?
01-20-2018, 12:53 AM (This post was last modified: 01-20-2018 12:56 AM by TheKaneB.)
Post: #12
RE: Emu48 Javascript ?
That's the easy part.
The emulator engine should have some sort of framebuffer for the display, which usually is just a byte array in the form of:

int displayHeight = 160; // or whatever
int displayWidth = 120;
uint8 * frameBuffer = (uint8 *)malloc(sizeof(uint8) * displayHeight * displayWidth);

The emulator will set / clear a pixel with code like this:

void setPixel(int x, int y, uint8 value) {
frameBuffer[x + y*frameBufferWidth] = value;
}

When the rendering is completed, the C code should call some kind of callback function telling the UI code that it's time to refresh the display, and it will pass the frameBuffer object.

That's the right time to handle the object over to the canvas routine. You will just copy the pixels and apply the necessary scale and filter.

Please note that after the engine will be converted from C to JS using EmScripten, the framebuffer object will be converted to a similar javascript array in the form:

frameBuffer = [1, 0, 0, 1, 1, 1, 0, 0, ....]; // we just have monochrome pixels here

so the glue code to render it into canvas will be very short:

var canvas = document.createElement("canvas"),
ctx = canvas.getContext("2d"),

// Get a pointer to the current location in the image.
var palette = ctx.getImageData(0,0,160,120); //x,y,w,h
// Wrap your array as a Uint8ClampedArray
palette.data.set(new Uint8ClampedArray(frameBuffer));
// Repost the data.
ctx.putImageData(palette,0,0);

Actually, you might want to scale the pixel values from 1 to 255 and invert their values (ie: a clear pixel will have value 0, but 0 is usually associated with black and you want white instead).
Anyway, that's just little details that you can figure out once you know exactly the data format of the framebuffer.

Software Failure: Guru Meditation

--
Antonio
IU2KIY
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Emu48 Javascript ? - sunhp - 01-16-2018, 04:38 PM
RE: Emu48 Javascript ? - TheKaneB - 01-16-2018, 05:51 PM
RE: Emu48 Javascript ? - sunhp - 01-18-2018, 11:18 PM
RE: Emu48 Javascript ? - TheKaneB - 01-18-2018, 11:27 PM
RE: Emu48 Javascript ? - TheKaneB - 01-18-2018, 11:29 PM
RE: Emu48 Javascript ? - sunhp - 01-18-2018, 11:43 PM
RE: Emu48 Javascript ? - TheKaneB - 01-19-2018, 09:06 AM
RE: Emu48 Javascript ? - sunhp - 01-19-2018, 03:55 PM
RE: Emu48 Javascript ? - sunhp - 01-19-2018, 10:48 PM
RE: Emu48 Javascript ? - TheKaneB - 01-19-2018, 11:14 PM
RE: Emu48 Javascript ? - sunhp - 01-20-2018, 12:38 AM
RE: Emu48 Javascript ? - TheKaneB - 01-20-2018 12:53 AM
RE: Emu48 Javascript ? - TheKaneB - 01-20-2018, 01:13 AM
RE: Emu48 Javascript ? - sunhp - 01-20-2018, 01:11 PM
RE: Emu48 Javascript ? - TheKaneB - 01-20-2018, 05:20 PM
RE: Emu48 Javascript ? - sunhp - 01-21-2018, 12:00 AM
RE: Emu48 Javascript ? - TheKaneB - 01-21-2018, 12:17 AM
RE: Emu48 Javascript ? - sunhp - 01-21-2018, 01:56 PM
RE: Emu48 Javascript ? - sunhp - 01-21-2018, 09:07 PM
RE: Emu48 Javascript ? - sunhp - 01-21-2018, 09:23 PM
RE: Emu48 Javascript ? - TheKaneB - 01-21-2018, 10:29 PM
RE: Emu48 Javascript ? - sunhp - 01-22-2018, 11:43 AM
RE: Emu48 Javascript ? - TheKaneB - 01-22-2018, 11:59 AM
RE: Emu48 Javascript ? - sunhp - 01-22-2018, 01:44 PM
RE: Emu48 Javascript ? - sunhp - 01-27-2018, 12:21 AM
RE: Emu48 Javascript ? - TheKaneB - 01-28-2018, 12:13 AM
RE: Emu48 Javascript ? - sunhp - 01-28-2018, 12:24 AM
RE: Emu48 Javascript ? - sunhp - 01-30-2018, 11:41 PM
RE: Emu48 Javascript ? - compsystems - 01-31-2018, 01:50 AM
RE: Emu48 Javascript ? - sunhp - 01-31-2018, 09:52 AM
RE: Emu48 Javascript ? - sunhp - 02-01-2018, 06:10 PM
RE: Emu48 Javascript ? - TheKaneB - 02-01-2018, 10:45 PM
RE: Emu48 Javascript ? - sunhp - 02-02-2018, 03:52 PM
RE: Emu48 Javascript ? - TheKaneB - 02-02-2018, 05:46 PM
RE: Emu48 Javascript ? - sunhp - 02-02-2018, 06:20 PM
RE: Emu48 Javascript ? - pier4r - 02-02-2018, 08:54 PM
RE: Emu48 Javascript ? - brickviking - 02-02-2018, 09:59 PM
RE: Emu48 Javascript ? - sunhp - 02-03-2018, 04:44 PM
RE: Emu48 Javascript ? - compsystems - 02-04-2018, 02:22 PM
RE: Emu48 Javascript ? - sunhp - 02-04-2018, 08:10 PM
RE: Emu48 Javascript ? - Eric Rechlin - 02-04-2018, 03:33 PM
RE: Emu48 Javascript ? - sunhp - 02-04-2018, 08:07 PM
RE: Emu48 Javascript ? - compsystems - 03-10-2018, 03:27 PM



User(s) browsing this thread: 1 Guest(s)