~henesy/smolvm

c3aea94a654d51bf8d68e999a5c0971533f5dcb1 — henesy 51 years ago e02005f
more debug output - pixchan drops every other message
2 files changed, 25 insertions(+), 9 deletions(-)

M main.c
M plan9_gui.c
M main.c => main.c +1 -1
@@ 53,7 53,7 @@ threadmain(int argc, char *argv[])
		drawpx(i, width / 2, i % 2);
	}
	
	sleep(20000);
	sleep(50000);

	threadexitsall(nil);
}

M plan9_gui.c => plan9_gui.c +24 -8
@@ 2,6 2,8 @@
#include <libc.h>
#include <thread.h>
#include <draw.h>
#include <mouse.h>
#include <cursor.h>
#include <keyboard.h>
#include "svm.h"



@@ 55,6 57,11 @@ uint	width;

Channel *pixchan;	// For setting individual pixels on the screen

char *entries2[] = {nil};
Menu menu2 = {entries2};
char *entries3[] = {"Exit", nil};
Menu menu3 = {entries3};

// Resize the window to our screen size
void
resize(void)


@@ 75,7 82,6 @@ void
drawer(void *v)
{
	Channel *pixchan = (Channel*)v;
	print("drawer start\n");

	int y, x;
	Image ***pixels;


@@ 93,6 99,8 @@ drawer(void *v)
		{pixchan, &pix, CHANRCV},
		{nil, nil, CHANEND},
	};
	
	int n ;

	// Draw loop
	for(;;){


@@ 100,8 108,11 @@ drawer(void *v)

		switch(alt(alts)){
		case 0:
			recv(pixchan, &pix);
			n = recv(pixchan, &pix);
			if(!n)
				print("drawer = %d\n", n);
			pixels[pix.y][pix.x] = pix.color;
			fprint(2, "drawer: (%d,%d) → %p\n", pix.x, pix.y, pix.color);
			break;

		// TODO - force draw chan?


@@ 156,7 167,7 @@ startgui(uint w)
	
	flushimage(display, 1);

	pixchan = chancreate(sizeof (Coordinate), 0);
	pixchan = chancreate(sizeof (Coordinate), 30);
	proccreate(drawer, pixchan, 4096);

	return;


@@ 174,10 185,15 @@ drawpx(uint x, uint y, int on)
	if(on)
		c = black;

	Coordinate *pix = calloc(1, sizeof (Coordinate));
	*pix = (Coordinate){(Point){x,y}, c};

	send(pixchan, pix);
	Coordinate pix = (Coordinate){
						(Point){x,y}, 
						c};
		
	fprint(2, "drawpx: (%d,%d) → %p\n", pix.x, pix.y, pix.color);
	
	int n = send(pixchan, &pix);
	if(!n)
		print("drawpx = %d\n", n);
}

// Called by event(2) on screen resize events


@@ 187,7 203,7 @@ eresized(int new)
	if(new && getwindow(display, Refnone) < 0)
		sysfatal("err: can't reattach to window after resize - %r");
	
	// TODO - draw the screen forcefully
	// TODO - draw the screen forcefully?
	
	//flushimage(screen->display, 0);
	resize();