Browse code

Prefixed uxn functions

neauoire authored on 01/08/2021 21:46:43
Showing 7 changed files
... ...
@@ -320,7 +320,7 @@ See etc/mkuxn-fast.moon for instructions.
320 320
 #pragma mark - Core
321 321
 
322 322
 int
323
-evaluxn(Uxn *u, Uint16 vec)
323
+uxn_eval(Uxn *u, Uint16 vec)
324 324
 {
325 325
 	Uint8 instr;
326 326
   if(u->dev[0].dat[0xf]) 
... ...
@@ -361,9 +361,9 @@ evaluxn(Uxn *u, Uint16 vec)
361 361
 #ifndef NO_STACK_CHECKS
362 362
 error:
363 363
 	if(u->wst.error)
364
-		return haltuxn(u, u->wst.error, "Working-stack", instr);
364
+		return uxn_halt(u, u->wst.error, "Working-stack", instr);
365 365
 	else
366
-		return haltuxn(u, u->rst.error, "Return-stack", instr);
366
+		return uxn_halt(u, u->rst.error, "Return-stack", instr);
367 367
 #endif
368 368
 }
369 369
 
... ...
@@ -228,7 +228,7 @@ See etc/mkuxn-fast.moon for instructions.
228 228
 #pragma mark - Core
229 229
 
230 230
 int
231
-evaluxn(Uxn *u, Uint16 vec)
231
+uxn_eval(Uxn *u, Uint16 vec)
232 232
 {
233 233
 	Uint8 instr;
234 234
 	if(u->dev[0].dat[0xf]) 
... ...
@@ -257,9 +257,9 @@ evaluxn(Uxn *u, Uint16 vec)
257 257
 #ifndef NO_STACK_CHECKS
258 258
 error:
259 259
 	if(u->wst.error)
260
-		return haltuxn(u, u->wst.error, "Working-stack", instr);
260
+		return uxn_halt(u, u->wst.error, "Working-stack", instr);
261 261
 	else
262
-		return haltuxn(u, u->rst.error, "Return-stack", instr);
262
+		return uxn_halt(u, u->rst.error, "Return-stack", instr);
263 263
 #endif
264 264
 }
265 265
 
... ...
@@ -39,7 +39,7 @@ Uint16 devpeek16(Device *d, Uint16 a) { return (devpeek8(d, a) << 8) + devpeek8(
39 39
 #pragma mark - Core
40 40
 
41 41
 int
42
-evaluxn(Uxn *u, Uint16 vec)
42
+uxn_eval(Uxn *u, Uint16 vec)
43 43
 {
44 44
 	Uint8 instr;
45 45
 	if(u->dev[0].dat[0xf]) 
... ...
@@ -4021,14 +4021,14 @@ evaluxn(Uxn *u, Uint16 vec)
4021 4021
 #ifndef NO_STACK_CHECKS
4022 4022
 error:
4023 4023
 	if(u->wst.error)
4024
-		return haltuxn(u, u->wst.error, "Working-stack", instr);
4024
+		return uxn_halt(u, u->wst.error, "Working-stack", instr);
4025 4025
 	else
4026
-		return haltuxn(u, u->rst.error, "Return-stack", instr);
4026
+		return uxn_halt(u, u->rst.error, "Return-stack", instr);
4027 4027
 #endif
4028 4028
 }
4029 4029
 
4030 4030
 int
4031
-bootuxn(Uxn *u)
4031
+uxn_boot(Uxn *u)
4032 4032
 {
4033 4033
 	unsigned int i;
4034 4034
 	char *cptr = (char *)u;
... ...
@@ -4038,7 +4038,7 @@ bootuxn(Uxn *u)
4038 4038
 }
4039 4039
 
4040 4040
 Device *
4041
-portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
4041
+uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
4042 4042
 {
4043 4043
 	Device *d = &u->dev[id];
4044 4044
 	d->addr = id * 0x10;
... ...
@@ -116,8 +116,8 @@ void (*ops[])(Uxn *u) = {
116 116
 
117 117
 #pragma mark - Core
118 118
 
119
-void
120
-opcuxn(Uxn *u, Uint8 instr)
119
+int
120
+uxn_step(Uxn *u, Uint8 instr)
121 121
 {
122 122
 	Uint8 op = instr & 0x3f, freturn = instr & 0x40, fkeep = instr & 0x80;
123 123
 	u->src = freturn ? &u->rst : &u->wst;
... ...
@@ -129,21 +129,15 @@ opcuxn(Uxn *u, Uint8 instr)
129 129
 		pop8 = pop8_nokeep;
130 130
 	}
131 131
 	(*ops[op])(u);
132
-}
133
-
134
-int
135
-stepuxn(Uxn *u, Uint8 instr)
136
-{
137
-	opcuxn(u, instr);
138 132
 	if(u->wst.error)
139
-		return haltuxn(u, u->wst.error, "Working-stack", instr);
133
+		return uxn_halt(u, u->wst.error, "Working-stack", instr);
140 134
 	if(u->rst.error)
141
-		return haltuxn(u, u->rst.error, "Return-stack", instr);
135
+		return uxn_halt(u, u->rst.error, "Return-stack", instr);
142 136
 	return 1;
143 137
 }
144 138
 
145 139
 int
146
-evaluxn(Uxn *u, Uint16 vec)
140
+uxn_eval(Uxn *u, Uint16 vec)
147 141
 {
148 142
 	if(u->dev[0].dat[0xf])
149 143
 		return 0;
... ...
@@ -152,13 +146,13 @@ evaluxn(Uxn *u, Uint16 vec)
152 146
 	u->rst.error = 0;
153 147
 	if(u->wst.ptr > 0xf8) u->wst.ptr = 0xf8;
154 148
 	while(u->ram.ptr)
155
-		if(!stepuxn(u, u->ram.dat[u->ram.ptr++]))
149
+		if(!uxn_step(u, u->ram.dat[u->ram.ptr++]))
156 150
 			return 0;
157 151
 	return 1;
158 152
 }
159 153
 
160 154
 int
161
-bootuxn(Uxn *u)
155
+uxn_boot(Uxn *u)
162 156
 {
163 157
 	unsigned int i;
164 158
 	char *cptr = (char *)u;
... ...
@@ -168,7 +162,7 @@ bootuxn(Uxn *u)
168 162
 }
169 163
 
170 164
 Device *
171
-portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
165
+uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *d, Uint8 b0, Uint8 w))
172 166
 {
173 167
 	Device *d = &u->dev[id];
174 168
 	d->addr = id * 0x10;
... ...
@@ -43,7 +43,7 @@ struct Uxn;
43 43
 void mempoke16(Uint8 *m, Uint16 a, Uint16 b);
44 44
 Uint16 mempeek16(Uint8 *m, Uint16 a);
45 45
 
46
-int bootuxn(Uxn *c);
47
-int evaluxn(Uxn *u, Uint16 vec);
48
-int haltuxn(Uxn *u, Uint8 error, char *name, int id);
49
-Device *portuxn(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8));
46
+int uxn_boot(Uxn *c);
47
+int uxn_eval(Uxn *u, Uint16 vec);
48
+int uxn_halt(Uxn *u, Uint8 error, char *name, int id);
49
+Device *uxn_port(Uxn *u, Uint8 id, char *name, void (*talkfn)(Device *, Uint8, Uint8));
... ...
@@ -114,7 +114,7 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
114 114
 static const char *errors[] = {"underflow", "overflow", "division by zero"};
115 115
 
116 116
 int
117
-haltuxn(Uxn *u, Uint8 error, char *name, int id)
117
+uxn_halt(Uxn *u, Uint8 error, char *name, int id)
118 118
 {
119 119
 	fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr);
120 120
 	u->ram.ptr = 0;
... ...
@@ -124,11 +124,11 @@ haltuxn(Uxn *u, Uint8 error, char *name, int id)
124 124
 static void
125 125
 run(Uxn *u)
126 126
 {
127
-	if(!evaluxn(u, PAGE_PROGRAM))
127
+	if(!uxn_eval(u, PAGE_PROGRAM))
128 128
 		error("Reset", "Failed");
129 129
 	else if(mempeek16(devconsole->dat, 0))
130 130
 		while(read(0, &devconsole->dat[0x2], 1) > 0)
131
-			evaluxn(u, mempeek16(devconsole->dat, 0));
131
+			uxn_eval(u, mempeek16(devconsole->dat, 0));
132 132
 }
133 133
 
134 134
 static int
... ...
@@ -149,27 +149,27 @@ main(int argc, char **argv)
149 149
 
150 150
 	if(argc < 2)
151 151
 		return error("Input", "Missing");
152
-	if(!bootuxn(&u))
152
+	if(!uxn_boot(&u))
153 153
 		return error("Boot", "Failed");
154 154
 	if(!loaduxn(&u, argv[1]))
155 155
 		return error("Load", "Failed");
156 156
 
157
-	devsystem = portuxn(&u, 0x0, "system", system_talk);
158
-	devconsole = portuxn(&u, 0x1, "console", console_talk);
159
-	portuxn(&u, 0x2, "empty", nil_talk);
160
-	portuxn(&u, 0x3, "empty", nil_talk);
161
-	portuxn(&u, 0x4, "empty", nil_talk);
162
-	portuxn(&u, 0x5, "empty", nil_talk);
163
-	portuxn(&u, 0x6, "empty", nil_talk);
164
-	portuxn(&u, 0x7, "empty", nil_talk);
165
-	portuxn(&u, 0x8, "empty", nil_talk);
166
-	portuxn(&u, 0x9, "empty", nil_talk);
167
-	portuxn(&u, 0xa, "file", file_talk);
168
-	portuxn(&u, 0xb, "datetime", datetime_talk);
169
-	portuxn(&u, 0xc, "empty", nil_talk);
170
-	portuxn(&u, 0xd, "empty", nil_talk);
171
-	portuxn(&u, 0xe, "empty", nil_talk);
172
-	portuxn(&u, 0xf, "empty", nil_talk);
157
+	devsystem = uxn_port(&u, 0x0, "system", system_talk);
158
+	devconsole = uxn_port(&u, 0x1, "console", console_talk);
159
+	uxn_port(&u, 0x2, "empty", nil_talk);
160
+	uxn_port(&u, 0x3, "empty", nil_talk);
161
+	uxn_port(&u, 0x4, "empty", nil_talk);
162
+	uxn_port(&u, 0x5, "empty", nil_talk);
163
+	uxn_port(&u, 0x6, "empty", nil_talk);
164
+	uxn_port(&u, 0x7, "empty", nil_talk);
165
+	uxn_port(&u, 0x8, "empty", nil_talk);
166
+	uxn_port(&u, 0x9, "empty", nil_talk);
167
+	uxn_port(&u, 0xa, "file", file_talk);
168
+	uxn_port(&u, 0xb, "datetime", datetime_talk);
169
+	uxn_port(&u, 0xc, "empty", nil_talk);
170
+	uxn_port(&u, 0xd, "empty", nil_talk);
171
+	uxn_port(&u, 0xe, "empty", nil_talk);
172
+	uxn_port(&u, 0xf, "empty", nil_talk);
173 173
 
174 174
 	run(&u);
175 175
 
... ...
@@ -414,7 +414,7 @@ stdin_handler(void *p)
414 414
 static const char *errors[] = {"underflow", "overflow", "division by zero"};
415 415
 
416 416
 int
417
-haltuxn(Uxn *u, Uint8 error, char *name, int id)
417
+uxn_halt(Uxn *u, Uint8 error, char *name, int id)
418 418
 {
419 419
 	fprintf(stderr, "Halted: %s %s#%04x, at 0x%04x\n", name, errors[error - 1], id, u->ram.ptr);
420 420
 	u->ram.ptr = 0;
... ...
@@ -424,7 +424,7 @@ haltuxn(Uxn *u, Uint8 error, char *name, int id)
424 424
 static void
425 425
 run(Uxn *u)
426 426
 {
427
-	evaluxn(u, 0x0100);
427
+	uxn_eval(u, 0x0100);
428 428
 	redraw(u);
429 429
 	while(1) {
430 430
 		SDL_Event event;
... ...
@@ -440,19 +440,19 @@ run(Uxn *u)
440 440
 			case SDL_KEYDOWN:
441 441
 			case SDL_KEYUP:
442 442
 				doctrl(u, &event, event.type == SDL_KEYDOWN);
443
-				evaluxn(u, mempeek16(devctrl->dat, 0));
443
+				uxn_eval(u, mempeek16(devctrl->dat, 0));
444 444
 				devctrl->dat[3] = 0;
445 445
 				break;
446 446
 			case SDL_MOUSEWHEEL:
447 447
 				devmouse->dat[7] = event.wheel.y;
448
-				evaluxn(u, mempeek16(devmouse->dat, 0));
448
+				uxn_eval(u, mempeek16(devmouse->dat, 0));
449 449
 				devmouse->dat[7] = 0;
450 450
 				break;
451 451
 			case SDL_MOUSEBUTTONUP:
452 452
 			case SDL_MOUSEBUTTONDOWN:
453 453
 			case SDL_MOUSEMOTION:
454 454
 				domouse(&event);
455
-				evaluxn(u, mempeek16(devmouse->dat, 0));
455
+				uxn_eval(u, mempeek16(devmouse->dat, 0));
456 456
 				break;
457 457
 			case SDL_WINDOWEVENT:
458 458
 				if(event.window.event == SDL_WINDOWEVENT_EXPOSED)
... ...
@@ -461,11 +461,11 @@ run(Uxn *u)
461 461
 			default:
462 462
 				if(event.type == stdin_event) {
463 463
 					devconsole->dat[0x2] = event.cbutton.button;
464
-					evaluxn(u, mempeek16(devconsole->dat, 0));
464
+					uxn_eval(u, mempeek16(devconsole->dat, 0));
465 465
 				}
466 466
 			}
467 467
 		}
468
-		evaluxn(u, mempeek16(devscreen->dat, 0));
468
+		uxn_eval(u, mempeek16(devscreen->dat, 0));
469 469
 		if(reqdraw || devsystem->dat[0xe])
470 470
 			redraw(u);
471 471
 		if(!bench) {
... ...
@@ -496,29 +496,29 @@ main(int argc, char **argv)
496 496
 
497 497
 	if(argc < 2)
498 498
 		return error("usage", "uxnemu file.rom");
499
-	if(!bootuxn(&u))
499
+	if(!uxn_boot(&u))
500 500
 		return error("Boot", "Failed to start uxn.");
501 501
 	if(!loaduxn(&u, argv[1]))
502 502
 		return error("Load", "Failed to open rom.");
503 503
 	if(!init())
504 504
 		return error("Init", "Failed to initialize emulator.");
505 505
 
506
-	devsystem = portuxn(&u, 0x0, "system", system_talk);
507
-	devconsole = portuxn(&u, 0x1, "console", console_talk);
508
-	devscreen = portuxn(&u, 0x2, "screen", screen_talk);
509
-	devaudio0 = portuxn(&u, 0x3, "audio0", audio_talk);
510
-	portuxn(&u, 0x4, "audio1", audio_talk);
511
-	portuxn(&u, 0x5, "audio2", audio_talk);
512
-	portuxn(&u, 0x6, "audio3", audio_talk);
513
-	portuxn(&u, 0x7, "---", nil_talk);
514
-	devctrl = portuxn(&u, 0x8, "controller", nil_talk);
515
-	devmouse = portuxn(&u, 0x9, "mouse", nil_talk);
516
-	portuxn(&u, 0xa, "file", file_talk);
517
-	portuxn(&u, 0xb, "datetime", datetime_talk);
518
-	portuxn(&u, 0xc, "---", nil_talk);
519
-	portuxn(&u, 0xd, "---", nil_talk);
520
-	portuxn(&u, 0xe, "---", nil_talk);
521
-	portuxn(&u, 0xf, "---", nil_talk);
506
+	devsystem = uxn_port(&u, 0x0, "system", system_talk);
507
+	devconsole = uxn_port(&u, 0x1, "console", console_talk);
508
+	devscreen = uxn_port(&u, 0x2, "screen", screen_talk);
509
+	devaudio0 = uxn_port(&u, 0x3, "audio0", audio_talk);
510
+	uxn_port(&u, 0x4, "audio1", audio_talk);
511
+	uxn_port(&u, 0x5, "audio2", audio_talk);
512
+	uxn_port(&u, 0x6, "audio3", audio_talk);
513
+	uxn_port(&u, 0x7, "---", nil_talk);
514
+	devctrl = uxn_port(&u, 0x8, "controller", nil_talk);
515
+	devmouse = uxn_port(&u, 0x9, "mouse", nil_talk);
516
+	uxn_port(&u, 0xa, "file", file_talk);
517
+	uxn_port(&u, 0xb, "datetime", datetime_talk);
518
+	uxn_port(&u, 0xc, "---", nil_talk);
519
+	uxn_port(&u, 0xd, "---", nil_talk);
520
+	uxn_port(&u, 0xe, "---", nil_talk);
521
+	uxn_port(&u, 0xf, "---", nil_talk);
522 522
 
523 523
 	/* Write screen size to dev/screen */
524 524
 	mempoke16(devscreen->dat, 2, ppu.width);