-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
mojozork-libretro.c
1660 lines (1440 loc) · 63.8 KB
/
mojozork-libretro.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* MojoZork; a simple, just-for-fun implementation of Infocom's Z-Machine.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <setjmp.h>
#include <assert.h>
#include "libretro.h"
#define MOJOZORK_LIBRETRO 1
#include "mojozork.c"
#include "mojozork-libretro-font.h"
// Touch input should work on any platform, but on several desktop platforms
// this RETRO_DEVICE_POINTER just gives you mouse input atm, so rather
// than risk the confusion, we turn off touch support if you aren't on
// Android for now.
#if defined(__ANDROID__)
#define IGNORE_TOUCH_INPUT 0
#else
#define IGNORE_TOUCH_INPUT 1
#endif
#define TEST_TOUCH_WITH_MOUSE 0
#if TEST_TOUCH_WITH_MOUSE
static int16_t scale_mouse_to_touch_coords(const int16_t m, const int16_t maxsize)
{
float normalized = ((((float)m) / ((float)maxsize)) * 2.0f) - 1.0f; // make it -1.0f to 1.0f
if (normalized < -1.0f) { normalized = -1.0f; } else if (normalized > 1.0f) { normalized = 1.0f; } // just in case.
return (int16_t) (normalized * 0x7fff);
}
#endif
// !!! FIXME: almost _all_ of our serialization state bulk is the
// !!! FIXME: scrollback buffer (at about 71 bytes per line, 5000 lines of
// !!! FIXME: scrollback is ~355 kilobytes). A more efficient serialization
// !!! FIXME: here could go a long way. Maybe compress it, since it'll
// !!! FIXME: crunch down to almost nothing, and have a set buffer size that
// !!! FIXME: will likely hold it all that's much smaller than the
// !!! FIXME: uncompressed data?
// !!! FIXME:
// !!! FIXME: ...but perhaps this bulk isn't a big deal when this isn't
// !!! FIXME: exactly a thing that benefits from frame-by-frame snapshots.
#define FRAMEBUFFER_WIDTH 640
#define FRAMEBUFFER_HEIGHT 480
#define VIRTUAL_KEYBOARD_HEIGHT 105
#define FRAMEBUFFER_PIXELS (FRAMEBUFFER_WIDTH * FRAMEBUFFER_HEIGHT)
#define TERMINAL_CHAR_WIDTH (LIBRETROFONT_WIDTH / 256)
#define TERMINAL_CHAR_HEIGHT LIBRETROFONT_HEIGHT
#define TERMINAL_WIDTH (FRAMEBUFFER_WIDTH / TERMINAL_CHAR_WIDTH)
#define TERMINAL_HEIGHT (FRAMEBUFFER_HEIGHT / TERMINAL_CHAR_HEIGHT)
#define VIDEO_WIDTH (TERMINAL_WIDTH * TERMINAL_CHAR_WIDTH)
#define VIDEO_HEIGHT (TERMINAL_HEIGHT * TERMINAL_CHAR_HEIGHT)
#define VIDEO_X_OFFSET ((FRAMEBUFFER_WIDTH - VIDEO_WIDTH) / 2)
#define VIDEO_Y_OFFSET ((FRAMEBUFFER_HEIGHT - VIDEO_HEIGHT) / 2)
#define SCROLLBACK_LINES 5000
static const uint16_t glyph_color[2] = { 0x0000, 0xFFFF };
// these are indexes into glyph_color; values outside the array are transparent (not drawn).
#define MOUSE_CURSOR_WIDTH 10
#define MOUSE_CURSOR_HEIGHT 16
static const uint8_t mouse_cursor[] = {
9, 1, 9, 9, 9, 9, 9, 9, 9, 9,
1, 0, 1, 9, 9, 9, 9, 9, 9, 9,
1, 0, 0, 1, 9, 9, 9, 9, 9, 9,
1, 0, 0, 0, 1, 9, 9, 9, 9, 9,
1, 0, 0, 0, 0, 1, 9, 9, 9, 9,
1, 0, 0, 0, 0, 0, 1, 9, 9, 9,
1, 0, 0, 0, 0, 0, 0, 1, 9, 9,
1, 0, 0, 0, 0, 0, 0, 0, 1, 9,
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 9,
1, 0, 0, 1, 0, 0, 1, 9, 9, 9,
1, 0, 1, 9, 1, 0, 0, 1, 9, 9,
9, 1, 9, 9, 1, 0, 0, 1, 9, 9,
9, 9, 9, 9, 9, 1, 0, 0, 1, 9,
9, 9, 9, 9, 9, 1, 0, 0, 1, 9,
9, 9, 9, 9, 9, 9, 1, 1, 9, 9,
};
typedef struct
{
const char *sym;
enum retro_key key;
int x;
int y;
int w;
int h;
} VirtualKeyboardKey;
static uint16_t frame_buffer[FRAMEBUFFER_PIXELS];
static struct retro_log_callback logging;
static retro_log_printf_t log_cb;
static float last_aspect;
static float last_sample_rate;
static char scrollback[SCROLLBACK_LINES][TERMINAL_WIDTH];
static int32_t scrollback_read_pos = SCROLLBACK_LINES - TERMINAL_HEIGHT;
static int32_t scrollback_count = TERMINAL_HEIGHT;
static int32_t cursor_position = TERMINAL_WIDTH * (TERMINAL_HEIGHT-1);
static int32_t terminal_word_start = -1;
static int32_t virtual_keyboard_height = 0;
static bool virtual_keyboard_enabled = false;
static uint16_t virtual_keyboard_image[VIRTUAL_KEYBOARD_HEIGHT * FRAMEBUFFER_WIDTH];
static const VirtualKeyboardKey *virtual_keyboard_key_highlighted = NULL;
static bool virtual_keyboard_key_pressed = false;
static char status_bar[TERMINAL_WIDTH + 1];
static char upper_window[TERMINAL_HEIGHT * TERMINAL_WIDTH];
static int32_t upper_window_cursor_position = 0;
static bool frontend_supports_frame_dupe = false;
static const VirtualKeyboardKey virtual_keyboard_keys[5][11] = {
{
{ "1", RETROK_1, 136, 2, 23, 17 },
{ "2", RETROK_2, 168, 2, 23, 17 },
{ "3", RETROK_3, 200, 2, 23, 17 },
{ "4", RETROK_4, 232, 2, 23, 17 },
{ "5", RETROK_5, 264, 2, 23, 17 },
{ "6", RETROK_6, 296, 2, 23, 17 },
{ "7", RETROK_7, 328, 2, 23, 17 },
{ "8", RETROK_8, 360, 2, 23, 17 },
{ "9", RETROK_9, 392, 2, 23, 17 },
{ "0", RETROK_0, 424, 2, 23, 17 },
{ "del", RETROK_BACKSPACE, 459, 2, 55, 17 }
},
{
{ "q", RETROK_q, 136, 23, 23, 17 },
{ "w", RETROK_w, 168, 23, 23, 17 },
{ "e", RETROK_e, 200, 23, 23, 17 },
{ "r", RETROK_r, 232, 23, 23, 17 },
{ "t", RETROK_t, 264, 23, 23, 17 },
{ "y", RETROK_y, 296, 23, 23, 17 },
{ "u", RETROK_u, 328, 23, 23, 17 },
{ "i", RETROK_i, 360, 23, 23, 17 },
{ "o", RETROK_o, 392, 23, 23, 17 },
{ "p", RETROK_p, 424, 23, 23, 17 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 }
},
{
{ "a", RETROK_a, 136, 44, 23, 17 },
{ "s", RETROK_s, 168, 44, 23, 17 },
{ "d", RETROK_d, 200, 44, 23, 17 },
{ "f", RETROK_f, 232, 44, 23, 17 },
{ "g", RETROK_g, 264, 44, 23, 17 },
{ "h", RETROK_h, 296, 44, 23, 17 },
{ "j", RETROK_j, 328, 44, 23, 17 },
{ "k", RETROK_k, 360, 44, 23, 17 },
{ "l", RETROK_l, 392, 44, 23, 17 },
{ ";", RETROK_SEMICOLON, 424, 44, 23, 17 },
{ "enter", RETROK_RETURN, 459, 44, 55, 17 }
},
{
{ "z", RETROK_z, 136, 65, 23, 17 },
{ "x", RETROK_x, 168, 65, 23, 17 },
{ "c", RETROK_c, 200, 65, 23, 17 },
{ "v", RETROK_v, 232, 65, 23, 17 },
{ "b", RETROK_b, 264, 65, 23, 17 },
{ "n", RETROK_n, 296, 65, 23, 17 },
{ "m", RETROK_m, 328, 65, 23, 17 },
{ ",", RETROK_COMMA, 360, 65, 23, 17 },
{ ".", RETROK_PERIOD, 392, 65, 23, 17 },
{ "?", RETROK_QUESTION, 424, 65, 23, 17 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 }
},
{
{ "space", RETROK_SPACE, 200, 86, 183, 17 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 },
{ NULL, RETROK_UNKNOWN, 0, 0, 0, 0 }
}
};
typedef enum
{
CURRENTINPUTDEV_KEYBOARD,
CURRENTINPUTDEV_MOUSE,
CURRENTINPUTDEV_CONTROLLER,
CURRENTINPUTDEV_TOUCH
} CurrentInputDevice;
static CurrentInputDevice current_input_device = CURRENTINPUTDEV_KEYBOARD;
static int32_t mouse_x = -1;
static int32_t mouse_y = -1;
static int32_t touch_scrolling = -1;
static int32_t previous_touch_x = 0;
static int32_t previous_touch_y = 0;
static bool mouse_button_down = false;
static bool touch_pressed = false;
typedef struct
{
bool up;
bool down;
bool left;
bool right;
bool a;
bool b;
bool x;
bool y;
bool select;
bool start;
bool l1;
bool l2;
bool l3;
bool r1;
bool r2;
bool r3;
} ControllerState;
// controller_x and _y are positions _on the virtual keyboard_, so when you go
// down to the spacebar and then back up, you end up back on the key you started on.
// These are not coordinates in screen space!
static int32_t controller_x = 0;
static int32_t controller_y = 0;
static int last_controller_direction = 0;
static ControllerState current_controller_state;
static void fallback_log(enum retro_log_level level, const char *fmt, ...)
{
(void)level;
va_list va;
va_start(va, fmt);
vfprintf(stderr, fmt, va);
va_end(va);
}
static retro_environment_t environ_cb;
static void init_virtual_keyboard_image(void)
{
for (int i = 0; i < (sizeof (virtual_keyboard_image) / sizeof (virtual_keyboard_image[0])); i++) {
virtual_keyboard_image[i] = 0x001F;
}
for (int keyy = 0; keyy < (sizeof (virtual_keyboard_keys) / sizeof (virtual_keyboard_keys[0])); keyy++) {
for (int keyx = 0; keyx < (sizeof (virtual_keyboard_keys[0]) / sizeof (virtual_keyboard_keys[0][0])); keyx++) {
const VirtualKeyboardKey *k = &virtual_keyboard_keys[keyy][keyx];
if (k->sym == NULL) {
continue;
}
const char *sym = k->sym;
const size_t slen = strlen(sym);
uint16_t *dst = virtual_keyboard_image + ((FRAMEBUFFER_WIDTH * k->y) + k->x);
const int h = k->h;
const int w = k->w;
for (int y = 0; y < h; y++) {
memset(dst, '\0', w * sizeof (uint16_t));
dst += FRAMEBUFFER_WIDTH;
}
dst = (virtual_keyboard_image + ((FRAMEBUFFER_WIDTH * k->y) + k->x));
dst += ((h - TERMINAL_CHAR_HEIGHT) / 2) * FRAMEBUFFER_WIDTH;
dst += (w - (slen * TERMINAL_CHAR_WIDTH)) / 2;
for (int fy = 0; fy < TERMINAL_CHAR_HEIGHT; fy++) {
uint16_t *next_dst = dst + FRAMEBUFFER_WIDTH;
for (int x = 0; x < slen; x++) {
const uint32_t ch = (uint32_t) (unsigned char) sym[x];
const uint8_t *glyph = &libretrofont_data[(ch * TERMINAL_CHAR_WIDTH) + (LIBRETROFONT_WIDTH * fy)];
for (int fx = 0; fx < TERMINAL_CHAR_WIDTH; fx++) {
*(dst++) = glyph_color[glyph[fx]];
}
}
dst = next_dst;
}
}
}
}
void retro_init(void)
{
init_virtual_keyboard_image();
}
void retro_deinit(void) {}
unsigned retro_api_version(void) { return RETRO_API_VERSION; }
void retro_set_controller_port_device(unsigned port, unsigned device)
{
//log_cb(RETRO_LOG_INFO, "Plugging device %u into port %u.\n", device, port);
}
void retro_get_system_info(struct retro_system_info *info)
{
memset(info, 0, sizeof (*info));
info->library_name = "mojozork";
info->library_version = "0.2";
info->need_fullpath = false;
info->valid_extensions = "dat|z1|z3";
}
static retro_video_refresh_t video_cb;
static retro_audio_sample_t audio_cb;
static retro_audio_sample_batch_t audio_batch_cb;
static retro_input_poll_t input_poll_cb;
static retro_input_state_t input_state_cb;
void retro_get_system_av_info(struct retro_system_av_info *info)
{
const float aspect = ((float) FRAMEBUFFER_WIDTH) / ((float) FRAMEBUFFER_HEIGHT);
const float sampling_rate = 30000.0f;
info->geometry.base_width = FRAMEBUFFER_WIDTH;
info->geometry.base_height = FRAMEBUFFER_HEIGHT;
info->geometry.max_width = FRAMEBUFFER_WIDTH;
info->geometry.max_height = FRAMEBUFFER_HEIGHT;
info->geometry.aspect_ratio = aspect;
last_aspect = aspect;
last_sample_rate = sampling_rate;
}
static void RETRO_CALLCONV frame_time_callback(retro_usec_t usec);
static void RETRO_CALLCONV keyboard_callback(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
void retro_set_environment(retro_environment_t cb)
{
environ_cb = cb;
if (cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &logging))
log_cb = logging.log;
else
log_cb = fallback_log;
static const struct retro_controller_description controller = { "Generic game controller", RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 0) };
static const struct retro_controller_info ports[] = {
{ &controller, 1 },
{ NULL, 0 },
};
cb(RETRO_ENVIRONMENT_SET_CONTROLLER_INFO, (void *) ports);
struct retro_frame_time_callback ftcb;
ftcb.callback = frame_time_callback;
ftcb.reference = 1000000 / 15; // !!! FIXME: 15?
cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, (void *) &ftcb);
struct retro_keyboard_callback kbcb;
kbcb.callback = keyboard_callback;
cb(RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK, (void *) &kbcb);
frontend_supports_frame_dupe = false;
cb(RETRO_ENVIRONMENT_GET_CAN_DUPE, &frontend_supports_frame_dupe);
}
void retro_set_audio_sample(retro_audio_sample_t cb) { audio_cb = cb; }
void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; }
void retro_set_input_poll(retro_input_poll_t cb) { input_poll_cb = cb; }
void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; }
static void check_variables(void) {}
static void writestr(const char *str);
static jmp_buf jmpbuf;
static void step_zmachine(void)
{
if (setjmp(jmpbuf) == 0) { // if non-zero, ZMachine called GState->die() during runInstruction.
const int initial_quit_state = GState->quit;
GState->step_completed = initial_quit_state;
while (!GState->step_completed) {
runInstruction();
}
if (GState->quit && (initial_quit_state == 0)) {
writestr("\n\n*** GAME HAS ENDED ***\n");
}
}
}
static void enable_virtual_keyboard(const bool enable)
{
if (virtual_keyboard_enabled != enable) {
virtual_keyboard_enabled = enable;
virtual_keyboard_key_highlighted = NULL;
virtual_keyboard_key_pressed = false;
}
}
static void update_frame_buffer(void)
{
// we draw from the bottom to the top, so if we have a partial row of characters, we can
// just stop drawing once we hit the top.
const char *terminal_buffer = scrollback[scrollback_read_pos];
const char *term_src = terminal_buffer + (TERMINAL_WIDTH * (TERMINAL_HEIGHT - 1));
uint16_t *orig_dst = frame_buffer + ((VIDEO_Y_OFFSET * FRAMEBUFFER_WIDTH) + VIDEO_X_OFFSET);
uint16_t *end_dst = orig_dst + (FRAMEBUFFER_WIDTH * FRAMEBUFFER_HEIGHT);
uint16_t *dst = end_dst - FRAMEBUFFER_WIDTH;
memset(frame_buffer, '\0', sizeof (frame_buffer));
if (GState->status_bar_enabled) {
orig_dst += FRAMEBUFFER_WIDTH * TERMINAL_CHAR_HEIGHT;
}
orig_dst += FRAMEBUFFER_WIDTH * TERMINAL_CHAR_HEIGHT * GState->upper_window_line_count;
if (virtual_keyboard_height > 0) {
dst -= FRAMEBUFFER_WIDTH * (virtual_keyboard_height - 1); // minus one because dst was already set to write at the start of the last row.
memcpy(dst, virtual_keyboard_image, FRAMEBUFFER_WIDTH * virtual_keyboard_height * sizeof (uint16_t));
}
// !!! FIXME: move this to a subroutine
for (int y = TERMINAL_HEIGHT - 1; y >= 1; y--) {
for (int fy = TERMINAL_CHAR_HEIGHT - 1; (fy >= 0) && (dst > orig_dst); fy--) {
uint16_t *next_dst = dst - FRAMEBUFFER_WIDTH; // draw rows bottom to top.
for (int x = 0; x < TERMINAL_WIDTH; x++) {
const uint32_t ch = (uint32_t) (unsigned char) term_src[x];
const uint8_t *glyph = &libretrofont_data[(ch * TERMINAL_CHAR_WIDTH) + (LIBRETROFONT_WIDTH * fy)];
for (int fx = 0; fx < TERMINAL_CHAR_WIDTH; fx++) {
*(dst++) = glyph_color[glyph[fx]];
}
}
dst = next_dst;
}
term_src -= TERMINAL_WIDTH; // draw rows bottom to top.
}
// !!! FIXME: move this to a subroutine
if (GState->upper_window_line_count) {
const char *term_src = upper_window + (TERMINAL_WIDTH * (GState->upper_window_line_count - 1));
orig_dst = frame_buffer + ((VIDEO_Y_OFFSET * FRAMEBUFFER_WIDTH) + VIDEO_X_OFFSET);
if (GState->status_bar_enabled) {
orig_dst += FRAMEBUFFER_WIDTH * TERMINAL_CHAR_HEIGHT;
}
for (int y = TERMINAL_HEIGHT - 1; y >= 1; y--) {
for (int fy = TERMINAL_CHAR_HEIGHT - 1; (fy >= 0) && (dst > orig_dst); fy--) {
uint16_t *next_dst = dst - FRAMEBUFFER_WIDTH; // draw rows bottom to top.
for (int x = 0; x < TERMINAL_WIDTH; x++) {
const uint32_t ch = (uint32_t) (unsigned char) term_src[x];
const uint8_t *glyph = &libretrofont_data[(ch * TERMINAL_CHAR_WIDTH) + (LIBRETROFONT_WIDTH * fy)];
for (int fx = 0; fx < TERMINAL_CHAR_WIDTH; fx++) {
*(dst++) = glyph_color[glyph[fx]];
}
}
dst = next_dst;
}
term_src -= TERMINAL_WIDTH; // draw rows bottom to top.
}
}
// draw the status bar.
if (GState->status_bar_enabled) {
dst = orig_dst;
orig_dst -= FRAMEBUFFER_WIDTH * TERMINAL_CHAR_HEIGHT;
for (int fy = TERMINAL_CHAR_HEIGHT - 1; (fy >= 0) && (dst > orig_dst); fy--) {
uint16_t *next_dst = dst - FRAMEBUFFER_WIDTH; // draw rows bottom to top.
for (int x = 0; x < TERMINAL_WIDTH; x++) {
const uint32_t ch = (uint32_t) (unsigned char) GState->status_bar[x];
const uint8_t *glyph = &libretrofont_data[(ch * TERMINAL_CHAR_WIDTH) + (LIBRETROFONT_WIDTH * fy)];
for (int fx = 0; fx < TERMINAL_CHAR_WIDTH; fx++) {
*(dst++) = glyph_color[glyph[fx] ? 0 : 1];
}
}
dst = next_dst;
}
}
// fully displayed? add highlighting.
if (virtual_keyboard_height == VIRTUAL_KEYBOARD_HEIGHT) {
if (virtual_keyboard_key_highlighted) {
const int w = virtual_keyboard_key_highlighted->w;
const int h = virtual_keyboard_key_highlighted->h;
const uint16_t color = virtual_keyboard_key_pressed ? 0x07E0 : 0xFFFF;
uint16_t *orig_ptr = (end_dst - (FRAMEBUFFER_WIDTH * (virtual_keyboard_height))) + ((FRAMEBUFFER_WIDTH * virtual_keyboard_key_highlighted->y) + virtual_keyboard_key_highlighted->x);
uint16_t *ptr;
uint16_t *ptr2;
ptr = orig_ptr;
ptr2 = ptr + (FRAMEBUFFER_WIDTH * (h - 1));
for (int i = 0; i < w; i++) {
*(ptr++) = color;
*(ptr2++) = color;
}
ptr = orig_ptr;
ptr2 = ptr + (w - 1);
for (int i = 0; i < h; i++) {
*ptr = color;
*ptr2 = color;
ptr += FRAMEBUFFER_WIDTH;
ptr2 += FRAMEBUFFER_WIDTH;
}
}
}
if ((current_input_device == CURRENTINPUTDEV_MOUSE) || TEST_TOUCH_WITH_MOUSE) {
int maxy = FRAMEBUFFER_HEIGHT - mouse_y;
if (maxy > MOUSE_CURSOR_HEIGHT) { maxy = MOUSE_CURSOR_HEIGHT; }
int maxx = FRAMEBUFFER_WIDTH - mouse_x;
if (maxx > MOUSE_CURSOR_WIDTH) { maxx = MOUSE_CURSOR_WIDTH; }
const uint8_t *cursor = mouse_cursor;
dst = frame_buffer + (mouse_y * FRAMEBUFFER_WIDTH) + mouse_x;
for (int y = 0; y < maxy; y++) {
const uint8_t *next_cursor = cursor + MOUSE_CURSOR_WIDTH;
uint16_t *next_dst = dst + FRAMEBUFFER_WIDTH;
for (int x = 0; x < maxx; x++) {
const int pixel = (int) *(cursor++);
if (pixel < (sizeof (glyph_color) - 1)) {
*dst = glyph_color[pixel];
}
dst++;
}
cursor = next_cursor;
dst = next_dst;
}
}
}
static retro_usec_t prev_runtime_usecs = 0;
static retro_usec_t runtime_usecs = 0;
static void RETRO_CALLCONV frame_time_callback(retro_usec_t usec)
{
prev_runtime_usecs = runtime_usecs;
runtime_usecs += usec;
}
static bool must_update_frame_buffer = true;
static uint8 *next_inputbuf = NULL; // where to write the next input for this player.
static uint8 next_inputbuflen = 0;
static uint16 next_operands[2]; // to save off the READ operands for later.
static int next_inputbuf_pos = 0;
static bool input_ready = 0;
static void scroll_back_page(void)
{
int32_t offset = TERMINAL_HEIGHT - GState->upper_window_line_count;
if (GState->status_bar_enabled) {
offset--;
}
scrollback_read_pos -= offset - (virtual_keyboard_height / TERMINAL_CHAR_HEIGHT);
if (scrollback_read_pos < (SCROLLBACK_LINES - scrollback_count)) {
scrollback_read_pos = SCROLLBACK_LINES - scrollback_count;
}
must_update_frame_buffer = true;
}
static void scroll_forward_page(void)
{
const int maxpos = SCROLLBACK_LINES - TERMINAL_HEIGHT;
int32_t offset = TERMINAL_HEIGHT - GState->upper_window_line_count;
if (GState->status_bar_enabled) {
offset--;
}
scrollback_read_pos += offset - (virtual_keyboard_height / TERMINAL_CHAR_HEIGHT);
if (scrollback_read_pos > maxpos) {
scrollback_read_pos = maxpos;
}
must_update_frame_buffer = true;
}
static void scroll_back_line(void)
{
if (scrollback_read_pos > (SCROLLBACK_LINES - scrollback_count)) {
scrollback_read_pos--;
must_update_frame_buffer = true;
}
}
static void scroll_forward_line(void)
{
const int maxpos = SCROLLBACK_LINES - TERMINAL_HEIGHT;
if (scrollback_read_pos < maxpos) {
scrollback_read_pos++;
must_update_frame_buffer = true;
}
}
static bool handle_keypress(const bool down, const unsigned keycode, const uint32_t ch)
{
char *terminal_buffer = scrollback[SCROLLBACK_LINES - TERMINAL_HEIGHT];
if (!down) { // don't care about keyup events.
return false;
} else if (keycode == RETROK_UP) {
scroll_back_line();
return true;
} else if (keycode == RETROK_DOWN) {
scroll_forward_line();
return true;
} else if (keycode == RETROK_PAGEUP) {
scroll_back_page();
return true;
} else if (keycode == RETROK_PAGEDOWN) {
scroll_forward_page();
return true;
} else if (input_ready) { // drop keys if we have a buffer of input waiting to process. You'd have to type _really_ fast to get bit by this, though!
return false;
} else if (GState && GState->quit) {
return false; // ignore input if game has ended.
} else if (keycode == RETROK_BACKSPACE) {
if (next_inputbuf_pos > 0) {
next_inputbuf_pos--;
terminal_buffer[cursor_position--] = (char) ' ';
scrollback_read_pos = SCROLLBACK_LINES - TERMINAL_HEIGHT; // if we are in scrollback, snap back to the present time.
}
return true;
} else if ((keycode == RETROK_KP_ENTER) || (keycode == RETROK_RETURN)) {
input_ready = true;
next_inputbuf[next_inputbuf_pos++] = (uint8_t) '\0';
scrollback_read_pos = SCROLLBACK_LINES - TERMINAL_HEIGHT; // if we are in scrollback, snap back to the present time.
return true;
} else if ((ch < 32) || (ch >= 127)) { // basic ASCII only, sorry.
return false;
} else if ((next_inputbuf_pos >= next_inputbuflen) || (cursor_position >= ((TERMINAL_WIDTH * TERMINAL_HEIGHT) - 2))) {
return false; // drop this, they're typing too much.
}
scrollback_read_pos = SCROLLBACK_LINES - TERMINAL_HEIGHT; // if we are in scrollback, snap back to the present time.
next_inputbuf[next_inputbuf_pos++] = (uint8_t) ch;
terminal_buffer[cursor_position++] = (char) ch;
return true;
}
static void handle_mouse_wheel(const int16_t x, const int16_t y, const int16_t wheelup, const int16_t wheeldown)
{
current_input_device = CURRENTINPUTDEV_MOUSE;
enable_virtual_keyboard(true);
if (y < (FRAMEBUFFER_HEIGHT - virtual_keyboard_height)) { // only deal with scrolling if in the terminal, not the keyboard.
const int16_t direction = wheeldown - wheelup; // zero == motion cancelled out, negative == scroll back, positive == scroll forward.
if (direction < 0) {
scroll_back_line();
} else if (direction > 0) {
scroll_forward_line();
}
}
}
static void update_virtual_key_under_position(const int x, const int y)
{
if (!virtual_keyboard_enabled || (virtual_keyboard_height != VIRTUAL_KEYBOARD_HEIGHT)) {
virtual_keyboard_key_highlighted = NULL;
virtual_keyboard_key_pressed = false;
return;
} else if (virtual_keyboard_key_pressed) {
return; // don't change highlighting if something is pressed down, even if we move off it.
}
const int16_t yoffset = (FRAMEBUFFER_HEIGHT - virtual_keyboard_height);
for (int keyy = 0; keyy < (sizeof (virtual_keyboard_keys) / sizeof (virtual_keyboard_keys[0])); keyy++) {
for (int keyx = 0; keyx < (sizeof (virtual_keyboard_keys[0]) / sizeof (virtual_keyboard_keys[0][0])); keyx++) {
const VirtualKeyboardKey *k = &virtual_keyboard_keys[keyy][keyx];
const int realy = k->y + yoffset;
if ( (x >= k->x) && (x < (k->x + k->w)) && (y >= realy) && (y < (realy + k->h)) ) {
if (virtual_keyboard_key_highlighted != k) {
virtual_keyboard_key_highlighted = k;
must_update_frame_buffer = true;
}
return;
}
}
}
virtual_keyboard_key_highlighted = NULL;
must_update_frame_buffer = true;
}
static void update_virtual_key_under_mouse_cursor(void)
{
if (current_input_device == CURRENTINPUTDEV_MOUSE) { // don't touch this if we aren't using a mouse.
update_virtual_key_under_position(mouse_x, mouse_y);
}
}
static void handle_mouse_press(const int16_t x, const int16_t y, const bool pressed)
{
if (mouse_button_down == pressed) {
return; // nothing's changed.
}
mouse_button_down = pressed;
must_update_frame_buffer = true;
if (pressed) { // mouse presses claim the current input.
current_input_device = CURRENTINPUTDEV_MOUSE;
enable_virtual_keyboard(true);
} else if (current_input_device != CURRENTINPUTDEV_MOUSE) {
return; // might be a mouseup _after_ something else claimed the current input.
}
// only process input on the virtual keyboard when it's fully exposed, not when disabled or sliding in/out.
if (!virtual_keyboard_enabled || (virtual_keyboard_height != VIRTUAL_KEYBOARD_HEIGHT)) {
return;
}
if (pressed) {
if (virtual_keyboard_key_highlighted) {
virtual_keyboard_key_pressed = true;
}
} else {
if (virtual_keyboard_key_highlighted && virtual_keyboard_key_pressed) {
const int16_t yoffset = (FRAMEBUFFER_HEIGHT - virtual_keyboard_height);
const VirtualKeyboardKey *k = virtual_keyboard_key_highlighted;
const int realy = k->y + yoffset;
if ( (x >= k->x) && (x < (k->x + k->w)) && (y >= realy) && (y < (realy + k->h)) ) { // still in the pressed key when letting go? Click.
//log_cb(RETRO_LOG_INFO, "Mouse released on '%s'.\n", k->sym);
handle_keypress(true, k->key, ((((int) k->key) >= 32) && (((int) k->key) < 127)) ? (char) k->key : 0);
handle_keypress(false, k->key, ((((int) k->key) >= 32) && (((int) k->key) < 127)) ? (char) k->key : 0);
}
virtual_keyboard_key_pressed = false;
update_virtual_key_under_mouse_cursor();
}
}
}
static void handle_touch(const int16_t touchx, const int16_t touchy, const bool pressed)
{
// adjust position to screen coordinates...
const int32_t x = pressed ? ((int32_t) ((((((float) touchx) / ((float) 0x7FFF)) + 1.0f) / 2.0f) * FRAMEBUFFER_WIDTH)) : previous_touch_x;
const int32_t y = pressed ? ((int32_t) ((((((float) touchy) / ((float) 0x7FFF)) + 1.0f) / 2.0f) * FRAMEBUFFER_HEIGHT)) : previous_touch_y;
previous_touch_x = x;
previous_touch_y = y;
if (touch_pressed && pressed) { // already touching, maybe treat it as a scrolling operation?
if (!virtual_keyboard_enabled || (virtual_keyboard_height != VIRTUAL_KEYBOARD_HEIGHT)) {
return; // ignore scrolling if the keyboard is still sliding in.
}
// only allow scrolling if touch started in game area and not the virtual keyboard.
if ((touch_scrolling == -1) && (y < (FRAMEBUFFER_HEIGHT - VIRTUAL_KEYBOARD_HEIGHT))) {
touch_scrolling = y;
}
if (touch_scrolling == -1) {
return; // not a scroll operation, we're done here.
}
int32_t difference = touch_scrolling - ((int32_t) y);
const int32_t difference_threshold = TERMINAL_CHAR_HEIGHT;
if (difference < 0) { // touch is moving down the screen.
while (difference < -difference_threshold) {
scroll_back_line();
touch_scrolling += difference_threshold;
difference += difference_threshold;
}
} else if (difference > 0) { // touch is moving up the screen.
while (difference > difference_threshold) {
scroll_forward_line();
touch_scrolling -= difference_threshold;
difference -= difference_threshold;
}
}
return; // we're done here for now.
}
// scrolling is processed, now see if there's activity on the virtual keyboard.
if (touch_pressed == pressed) {
return; // nothing's changed.
}
touch_pressed = pressed;
touch_scrolling = -1; // reset this because it's either a new touch or a released touch.
if (pressed) { // touches claim the current input.
current_input_device = CURRENTINPUTDEV_TOUCH;
enable_virtual_keyboard(true);
} else if (current_input_device != CURRENTINPUTDEV_TOUCH) {
return; // might be a release _after_ something else claimed the current input.
}
// only process input on the virtual keyboard when it's fully exposed, not when disabled or sliding in/out.
if (!virtual_keyboard_enabled || (virtual_keyboard_height != VIRTUAL_KEYBOARD_HEIGHT)) {
return;
}
if (pressed) {
update_virtual_key_under_position(x, y);
if (virtual_keyboard_key_highlighted) {
//log_cb(RETRO_LOG_INFO, "Touch pressed on '%s'.\n", virtual_keyboard_key_highlighted->sym);
virtual_keyboard_key_pressed = true;
}
} else {
if (virtual_keyboard_key_highlighted && virtual_keyboard_key_pressed) {
const int16_t yoffset = (FRAMEBUFFER_HEIGHT - virtual_keyboard_height);
const VirtualKeyboardKey *k = virtual_keyboard_key_highlighted;
const int realy = k->y + yoffset;
if ( (x >= k->x) && (x < (k->x + k->w)) && (y >= realy) && (y < (realy + k->h)) ) { // still in the pressed key when letting go? Click.
//log_cb(RETRO_LOG_INFO, "Touch released on '%s'.\n", k->sym);
handle_keypress(true, k->key, ((((int) k->key) >= 32) && (((int) k->key) < 127)) ? (char) k->key : 0);
handle_keypress(false, k->key, ((((int) k->key) >= 32) && (((int) k->key) < 127)) ? (char) k->key : 0);
}
virtual_keyboard_key_pressed = false;
virtual_keyboard_key_highlighted = NULL;
must_update_frame_buffer = true;
}
}
}
static bool process_keyboard_callback(bool down, unsigned keycode, uint32_t ch)
{
current_input_device = CURRENTINPUTDEV_KEYBOARD;
enable_virtual_keyboard(false);
// RetroArch on several platforms will not return a character code, only a keycode,
// so in that case, we treat the keycode as a value from a US keyboard. It's not
// a perfect solution, but it's all we can do.
if ( (ch == 0) && ((keycode >= 32) && (keycode <= 126)) ) {
ch = (uint32_t) keycode; // the keycodes map to US ASCII anyhow.
}
return handle_keypress(down, keycode, ch);
}
static void RETRO_CALLCONV keyboard_callback(bool down, unsigned keycode, uint32_t ch, uint16_t key_modifiers)
{
must_update_frame_buffer = process_keyboard_callback(down, keycode, ch);
}
static void query_controller_state(ControllerState *state)
{
state->up = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP) != 0;
state->down = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN) != 0;
state->left = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT) != 0;
state->right = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT) != 0;
state->a = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A) != 0;
state->b = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B) != 0;
state->x = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X) != 0;
state->y = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y) != 0;
state->select = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT) != 0;
state->start = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START) != 0;
state->l1 = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L) != 0;
state->l2 = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2) != 0;
state->l3 = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3) != 0;
state->r1 = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R) != 0;
state->r2 = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2) != 0;
state->r3 = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3) != 0;
}
static void handle_controller_input(void)
{
ControllerState newstate;
query_controller_state(&newstate);
bool has_new_input = false;
ControllerState new_press;
#define CHECK_IF_NEW_PRESS(field) \
if ((new_press.field = (newstate.field && !current_controller_state.field)) != false) { \
/*log_cb(RETRO_LOG_INFO, "Controller input '" #field "' newly pressed!\n");*/ \
has_new_input = true; \
}
CHECK_IF_NEW_PRESS(up);
CHECK_IF_NEW_PRESS(down);
CHECK_IF_NEW_PRESS(left);
CHECK_IF_NEW_PRESS(right);
CHECK_IF_NEW_PRESS(a);
CHECK_IF_NEW_PRESS(b);
CHECK_IF_NEW_PRESS(x);
CHECK_IF_NEW_PRESS(y);
CHECK_IF_NEW_PRESS(select);
CHECK_IF_NEW_PRESS(start);
CHECK_IF_NEW_PRESS(l1);
CHECK_IF_NEW_PRESS(l2);
CHECK_IF_NEW_PRESS(l3);
CHECK_IF_NEW_PRESS(r1);
CHECK_IF_NEW_PRESS(r2);
CHECK_IF_NEW_PRESS(r3);
#undef CHECK_IF_NEW_PRESS
if (has_new_input) {
current_input_device = CURRENTINPUTDEV_CONTROLLER;
enable_virtual_keyboard(true);
}
memcpy(¤t_controller_state, &newstate, sizeof (newstate));
if (current_input_device != CURRENTINPUTDEV_CONTROLLER) {
return; // ignore the rest of this if we aren't using a controller.
}
// this is all subject to change.
if (new_press.l1) { // scroll forward
scroll_back_line();
} else if (new_press.l2) { // scroll back
scroll_back_page();
} else if (new_press.r1) { // scroll forward
scroll_forward_line();
} else if (new_press.r2) { // scroll back
scroll_forward_page();
}
// only process input on the virtual keyboard when it's fully exposed, not when disabled or sliding in/out.
if (!virtual_keyboard_enabled || (virtual_keyboard_height != VIRTUAL_KEYBOARD_HEIGHT)) {
return;
}
if (!virtual_keyboard_key_pressed) { // can't move to a new key or use a shortcut while one is pressed.
if (new_press.up) {
last_controller_direction = -1;
if (controller_y == 0) {
controller_y = (sizeof (virtual_keyboard_keys) / sizeof (virtual_keyboard_keys[0])) - 1;
} else {
controller_y--;
}
} else if (new_press.down) {
last_controller_direction = -1;
if (controller_y == ((sizeof (virtual_keyboard_keys) / sizeof (virtual_keyboard_keys[0])) - 1)) {
controller_y = 0;
} else {
controller_y++;
}
} else if (new_press.left) {
last_controller_direction = -1;
if (controller_x == 0) {
controller_x = (sizeof (virtual_keyboard_keys[0]) / sizeof (virtual_keyboard_keys[0][0])) - 1;
} else {
controller_x--;
}
} else if (new_press.right) {
last_controller_direction = 1;
if (controller_x == ((sizeof (virtual_keyboard_keys[0]) / sizeof (virtual_keyboard_keys[0][0])) - 1)) {
controller_x = 0;
} else {
controller_x++;
}
}
int adjusted_x = controller_x;
while (virtual_keyboard_keys[controller_y][adjusted_x].sym == NULL) {
if ((last_controller_direction < 0) && (adjusted_x == 0)) {
adjusted_x = (sizeof (virtual_keyboard_keys[0]) / sizeof (virtual_keyboard_keys[0][0])) - 1;
} else if ((last_controller_direction > 0) && (adjusted_x == ((sizeof (virtual_keyboard_keys[0]) / sizeof (virtual_keyboard_keys[0][0])) - 1))) {
adjusted_x = 0;
} else {
adjusted_x += last_controller_direction;
}
}
// only allow one of these events per-frame to avoid confusion.
if (virtual_keyboard_key_highlighted != &virtual_keyboard_keys[controller_y][adjusted_x]) {
virtual_keyboard_key_highlighted = &virtual_keyboard_keys[controller_y][adjusted_x];
must_update_frame_buffer = true;
} else if (new_press.b) { // press the virtual key.
const VirtualKeyboardKey *k = virtual_keyboard_key_highlighted;
handle_keypress(true, k->key, ((((int) k->key) >= 32) && (((int) k->key) < 127)) ? (char) k->key : 0);
handle_keypress(false, k->key, ((((int) k->key) >= 32) && (((int) k->key) < 127)) ? (char) k->key : 0);
virtual_keyboard_key_pressed = true;
must_update_frame_buffer = true;
} else if (new_press.y) { // treat this as backspace on the keyboard.
handle_keypress(true, RETROK_BACKSPACE, 0);
handle_keypress(false, RETROK_BACKSPACE, 0);
must_update_frame_buffer = true;
} else if (new_press.a) { // treat this as space on the keyboard.
handle_keypress(true, RETROK_SPACE, ' ');
handle_keypress(false, RETROK_SPACE, ' ');
must_update_frame_buffer = true;
} else if (new_press.x) { // treat this as ENTER on the keyboard.
handle_keypress(true, RETROK_RETURN, 0);
handle_keypress(false, RETROK_RETURN, 0);
must_update_frame_buffer = true;
}
} else {
if (!newstate.b) {
virtual_keyboard_key_pressed = false;
must_update_frame_buffer = true;
}
}
}
static void writestr_mojozork_libretro(const char *str, const uintptr slen);
static int update_input(void) // returns non-zero if the screen changed.
{
input_poll_cb();
static bool first_run = true;