Browse code

Keep vectors in memory instead of constantly peek16()

neauoire authored on 22/09/2021 19:16:16
Showing 2 changed files
... ...
@@ -29,6 +29,7 @@ typedef struct {
29 29
 typedef struct Device {
30 30
 	struct Uxn *u;
31 31
 	Uint8 addr, dat[16], *mem;
32
+	Uint16 vector;
32 33
 	int (*talk)(struct Device *d, Uint8, Uint8);
33 34
 } Device;
34 35
 
... ...
@@ -376,8 +376,12 @@ system_talk(Device *d, Uint8 b0, Uint8 w)
376 376
 static int
377 377
 console_talk(Device *d, Uint8 b0, Uint8 w)
378 378
 {
379
-	if(w && b0 > 0x7)
380
-		write(b0 - 0x7, (char *)&d->dat[b0], 1);
379
+	if(w) {
380
+		if(b0 == 0x1)
381
+			d->vector = peek16(d->dat, 0x0);
382
+		if(b0 > 0x7)
383
+			write(b0 - 0x7, (char *)&d->dat[b0], 1);
384
+	}
381 385
 	return 1;
382 386
 }
383 387
 
... ...
@@ -392,6 +396,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
392 396
 		}
393 397
 	else
394 398
 		switch(b0) {
399
+		case 0x1: d->vector = peek16(d->dat, 0x0); break;
395 400
 		case 0x5:
396 401
 			if(!FIXED_SIZE) return set_size(peek16(d->dat, 0x2), peek16(d->dat, 0x4), 1);
397 402
 			break;
... ...
@@ -491,6 +496,8 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w)
491 496
 static int
492 497
 nil_talk(Device *d, Uint8 b0, Uint8 w)
493 498
 {
499
+	if(w && b0 == 0x1)
500
+		d->vector = peek16(d->dat, 0x0);
494 501
 	(void)d;
495 502
 	(void)b0;
496 503
 	(void)w;
... ...
@@ -525,7 +532,7 @@ run(Uxn *u)
525 532
 			case SDL_KEYDOWN:
526 533
 			case SDL_KEYUP:
527 534
 				doctrl(&event, event.type == SDL_KEYDOWN);
528
-				uxn_eval(u, peek16(devctrl->dat, 0));
535
+				uxn_eval(u, devctrl->vector);
529 536
 				devctrl->dat[3] = 0;
530 537
 				break;
531 538
 			case SDL_MOUSEWHEEL:
... ...
@@ -533,7 +540,7 @@ run(Uxn *u)
533 540
 			case SDL_MOUSEBUTTONDOWN:
534 541
 			case SDL_MOUSEMOTION:
535 542
 				domouse(&event);
536
-				uxn_eval(u, peek16(devmouse->dat, 0));
543
+				uxn_eval(u, devmouse->vector);
537 544
 				break;
538 545
 			case SDL_WINDOWEVENT:
539 546
 				if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
... ...
@@ -542,12 +549,12 @@ run(Uxn *u)
542 549
 			default:
543 550
 				if(event.type == stdin_event) {
544 551
 					devconsole->dat[0x2] = event.cbutton.button;
545
-					uxn_eval(u, peek16(devconsole->dat, 0));
552
+					uxn_eval(u, devconsole->vector);
546 553
 				} else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY)
547 554
 					uxn_eval(u, peek16((devaudio0 + (event.type - audio0_event))->dat, 0));
548 555
 			}
549 556
 		}
550
-		uxn_eval(u, peek16(devscreen->dat, 0));
557
+		uxn_eval(u, devscreen->vector);
551 558
 		if(reqdraw || ppu.redraw || devsystem->dat[0xe])
552 559
 			redraw(u);
553 560
 		if(!BENCH) {