|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * RiscPC Interface.
5: *
6: * (c) 1995 Bernd Schmidt
7: * (c) 1996 Gustavo Goedert
8: */
9:
10: #include "sysconfig.h"
11: #include "sysdeps.h"
12:
13: #include "options.h"
1.1.1.4 root 14: #include "threaddep/thread.h"
1.1 root 15: #include "memory.h"
16: #include "custom.h"
17: #include "keyboard.h"
18: #include "xwin.h"
19: #include "keybuf.h"
20: #include "gui.h"
21:
22: typedef char flagtype;
23:
24: extern struct regstruct
25: {
26: ULONG regs[16];
27: CPTR usp,isp,msp;
28: UWORD sr;
29: flagtype t1;
30: flagtype t0;
31: flagtype s;
32: flagtype m;
33: flagtype x;
34: flagtype stopped;
35: int intmask;
36: ULONG pc;
37: #ifdef USE_POINTER
38: UBYTE *pc_p;
39: UBYTE *pc_oldp;
40: #endif
41:
42: ULONG vbr,sfc,dfc;
43:
44: double fp[8];
45: ULONG fpcr,fpsr,fpiar;
46: ULONG spcflags;
47: ULONG kick_mask;
48: } regs;
49:
50:
51: #include "OS:wimp.h"
52: #include "OS:font.h"
53: #include "OS:os.h"
54: #include "OS:osbyte.h"
55: #include "OS:osword.h"
56: #include "OS:sound.h"
57:
58:
59: void gui_process(void);
60:
61:
62: #define A_base 0x300000
63: #define A_switch (A_base+0)
64: #define A_disk (A_base+1)
65: #define A_sonst (A_base+5)
66: #define A_hf (A_base+6)
67: #define A_mount (A_base+7)
68: #define A_rom (A_base+10)
69: #define A_uaeask (A_base+11)
70:
71: int quit_program;
72: int uae_running;
73: int uae_startedup;
74:
75: wimp_MESSAGE_LIST(13) messages=
76: {A_switch, A_disk, A_disk+1, A_disk+2, A_disk+3, A_sonst, A_rom, A_mount,
77: A_mount+1, A_mount+2, A_uaeask, message_PREQUIT, 0};
78:
79: wimp_t taskhandle;
80: wimp_t frontendhandle;
81: wimp_block block;
82: wimp_message mblock;
83: int pollword;
84:
85: os_MODE_SELECTOR(3) uaemode={1,0,0,0,-1,0,128,3,255,-1,0};
86: os_MODE_SELECTOR(3) wimpmode;
87:
88: extern void datavox_type(int channel, int type);
89: extern void datavox_timed(int channel, int timed);
90: extern void datavox_pitch(int channel, int pitch);
91: extern void datavox_set_memory(int channel, char *start, char *end);
92: extern void datavox_set_repeat(int channel, char *start, char *end);
93: extern int datavox_allocate_channel(int key);
94: extern void datavox_de_allocate_channel(int channel, int key);
95:
96: int sratecode;
97: char sbuffer[44100];
98: int deskvoice, uaechannel;
99:
100: extern int uaedevfd, numtracks;
101:
102: char mountpoint[64];
103: char mountdir[256];
104:
105: char *scr;
106: int screenrowbytes,screenrows;
107:
108: char pressed[128];
109: char translate[128]=
110: { 255, 255, 255, AK_LSH, AK_CTRL, AK_LALT, AK_RSH, AK_CTRL, //0
111: AK_RALT, 255, 255, 255, 255, 255, 255, 255, //8
112: AK_Q, AK_3, AK_4, AK_5, AK_F4, AK_8, AK_F7, AK_MINUS, //16
113: 255, AK_LF, AK_NP6, AK_NP7, 255, 255, AK_F10, 255, //24
114: 255, AK_W, AK_E, AK_T, AK_7, AK_I, AK_9, AK_0, //32
115: 255, AK_DN, AK_NP8, AK_NP9, 255,AK_BACKQUOTE, AK_LTGT, AK_BS, //40
116: AK_1, AK_2, AK_D, AK_R, AK_6, AK_U, AK_O, AK_P, //48
117: AK_LBRACKET, AK_UP,AK_NPADD,AK_NPSUB, AK_ENT, 255, 255, AK_RAMI, //56
118: AK_CAPSLOCK, AK_A, AK_X, AK_F, AK_Y, AK_J, AK_K, 255, //64
119: 255, AK_RET,AK_NPDIV, 255,AK_NPDEL, 255, AK_LAMI, AK_QUOTE, //72
120: 255, AK_S, AK_C, AK_G, AK_H, AK_N, AK_L,AK_SEMICOLON, //80
121: AK_RBRACKET, AK_DEL, 255,AK_NPMUL, 255, AK_EQUAL, AK_LTGT, 255, //88
122: AK_TAB, AK_Z, AK_SPC, AK_V, AK_B, AK_M,AK_COMMA, AK_PERIOD, //96
123: AK_SLASH,AK_HELP, AK_NP0, AK_NP1, AK_NP3, 255, 255, 255, //104
124: 255, AK_F1, AK_F2, AK_F3, AK_F5, AK_F6, AK_F8, AK_F9, //112
125: AK_BACKSLASH, AK_RT, AK_NP4, AK_NP5, AK_NP2, 255, 255, 255};//120
126:
127: char dn0[256], dn1[256], dn2[256], dn3[256];
128: int dc0=0, dc1=0, dc2=0, dc3=0;
129:
130: /***************************************************************************/
131:
132:
133: void setup_brkhandler(void)
134: {
135: }
136:
137: void flush_line(int y)
138: {
139: }
140:
141: void flush_block(int a, int b)
142: {
143: }
144:
145: void flush_screen(int a, int b)
146: {
147: }
148:
149: void calc_adjustment(void)
150: {
151: }
152:
153:
154: static int colors_allocated;
155:
156: static int get_color(int r, int g, int b, xcolnr *cnp)
157: {
158: if (colors_allocated == 256)
159: return -1;
160: *cnp = colors_allocated;
161:
162: os_writec(19);
163: os_writec(colors_allocated);
164: os_writec(16);
165: os_writec(r+(r<<4));
166: os_writec(g+(g<<4));
167: os_writec(b+(b<<4));
168: colors_allocated++;
169:
170: return 1;
171: }
172:
173: static void init_colors(void)
174: {
175: int rw = 5, gw = 5, bw = 5;
176: colors_allocated = 0;
177:
178: if (gfxvidinfo.pixbytes == 2)
179: alloc_colors64k(rw, gw, bw, 0, rw, rw+gw);
180: else
181: alloc_colors256(get_color);
182: }
183:
184: void sound_output(char *b, int l)
185: {
186: memcpy(sbuffer, b, l);
187: datavox_set_memory(uaechannel, sbuffer, sbuffer+l);
188: datavox_set_repeat(uaechannel, sbuffer, sbuffer+l);
189: datavox_type(uaechannel, 1);
190: datavox_pitch(uaechannel, sratecode);
191: sound_control(uaechannel, 256+127, 0, 255);
192: }
193:
194: void init_mouse(void)
195: {
196: oswordpointer_bbox_block bbox;
197:
198: bbox.op=oswordpointer_OP_SET_BBOX;
199: bbox.x0=-32768;
200: bbox.y0=-32768;
201: bbox.x1=32767;
202: bbox.y1=32767;
203: oswordpointer_set_bbox(&bbox);
204: }
205:
206: void setwimpmode(void)
207: {
208: wimp_set_mode(&wimpmode);
209: while(osbyte2(145,0,0)!=0);
210: }
211:
212: void setuaemode(void)
213: {
214: os_vdu_var_list varlist[2]={149,-1};
215: int valuelist[1];
216: os_mode m;
217:
218: m=osscreenmode_current();
219: memcpy(&wimpmode, m, os_SIZEOF_MODE_SELECTOR(3));
220:
221: osscreenmode_select(&uaemode);
222: os_read_vdu_variables(varlist, valuelist);
223: scr=(void *)valuelist[0];
224: gfxvidinfo.bufmem=scr;
225:
226: os_remove_cursors();
227:
228: init_colors();
229: init_mouse();
230:
231: flush_block(0, numscrlines-1);
232: }
233:
234: void setwimpsound(void)
235: {
236: int s,t;
237:
238: sound_attach_voice(uaechannel, deskvoice, &s, &t);
239: datavox_de_allocate_channel(uaechannel, taskhandle);
240: }
241:
242: void setuaesound(void)
243: {
244: int s;
245:
246: sound_volume(127);
247: uaechannel=datavox_allocate_channel(taskhandle);
248: printf("%d\n", uaechannel);
249: sound_attach_voice(uaechannel, 0, &s, &deskvoice);
250: sound_attach_named_voice(uaechannel, "DataVox-Voice");
251: }
252:
253: int graphics_init(void)
254: {
255: __uname_control=6;
256:
257: switch(color_mode)
258: {
259: case 1:
260: case 2:
261: case 5:
262: uaemode.log2_bpp=4;
263: gfxvidinfo.pixbytes=2;
264: break;
265: default:
266: uaemode.log2_bpp=3;
267: gfxvidinfo.pixbytes=1;
268: break;
269: }
270:
271: uaemode.xres=gfx_requested_width;
272: uaemode.yres=gfx_requested_height;
273:
274: gfxvidinfo.rowbytes=gfx_requested_width*gfxvidinfo.pixbytes;
275: gfxvidinfo.maxlinetoscr=gfx_requested_width;
276: gfxvidinfo.maxline=gfx_requested_height;
277: gfxvidinfo.maxblocklines=0;
278:
279: setuaemode();
280: setuaesound();
281:
282: return 1;
283: }
284:
285: void graphics_leave(void)
286: {
287: }
288:
289:
290: void readmouse(void)
291: {
292: int x,y;
293: bits buttons;
294: os_t t;
295:
296: os_mouse(&x, &y, &buttons, &t);
297: lastmx=x>>1;
298: lastmy=gfx_requested_height-(y>>1);
299: buttonstate[0]=(buttons & 4)>>2;
300: buttonstate[1]=(buttons & 2)>>1;
301: buttonstate[2]=buttons & 1;
302: newmousecounters=0;
303: }
304:
305:
306: void processkey(char k, char release)
307: {
308: if(k==29 && release==1)
309: {
310: uae_running=0;
311: setwimpmode();
312: setwimpsound();
313: }
314:
315: if(translate[k]!=255)
316: record_key((translate[k]<<1)+release);
317: }
318:
319:
320: void readkeyboard(void)
321: {
322: char c,l,k,q;
323:
324: for(l=0, k=osbyte1(121, 0, 0), q=0; !q; l=k+1, k=osbyte1(121, l, 0))
325: {
326: if(k==0xff)
327: {
328: k=128;
329: q=1;
330: }
331: else
332: {
333: if(pressed[k]==0)
334: {
335: if (translate[k]!=0)
336: processkey(k, 0);
337: pressed[k]=1;
338: }
339: }
340: for(c=l; c<k; c++)
341: {
342: if(pressed[c]!=0)
343: {
344: if (translate[c]!=0)
345: processkey(c, 1);
346: pressed[c]=0;
347: }
348: }
349: }
350: }
351:
352: void handle_events(void)
353: {
354: readmouse();
355: readkeyboard();
356:
357: if(dc0==1)
358: {
359: dc0=0;
360: disk_insert(0, dn0);
361: strncpy(df0, dn0, 255);
362: }
363:
364: if(dc1==1)
365: {
366: dc1=0;
367: disk_insert(1, dn1);
368: strncpy(df1, dn1, 255);
369: }
370:
371: if(dc2==1)
372: {
373: dc2=0;
374: disk_insert(2, dn2);
375: strncpy(df2, dn2, 255);
376: }
377:
378: if(dc3==1)
379: {
380: dc3=0;
381: disk_insert(3, dn3);
382: strncpy(df3, dn3, 255);
383: }
384:
385: if(dc0>1) dc0--;
386: if(dc1>1) dc1--;
387: if(dc2>1) dc2--;
388: if(dc3>1) dc3--;
389:
390: if (uae_running==0)
391: gui_process();
392: }
393:
394: int debuggable(void)
395: {
396: return 0;
397: }
398:
399: int needmousehack(void)
400: {
401: return 0;
402: }
403:
404: void LED(int on)
405: {
406: }
407:
408: static void sigchldhandler(int foo)
409: {
410: }
411:
412:
413: /***************************************************************************/
414:
415:
416: int gui_init(void)
417: {
418: int vout;
419:
420: quit_program=0;
421: uae_running=0;
422: uae_startedup=0;
423:
424: taskhandle=wimp_initialise(wimp_VERSION_RO35, "UAE", &messages, &vout);
425: gui_process();
426:
427: return 0;
428: }
429:
430: void changedisk(int n, char *f)
431: {
432: if(uae_startedup)
433: {
434: switch(n)
435: {
436: case 0:
437: if(strcmp(df0, f)!=0)
438: {
439: strncpy(dn0, f, 255);
440: dc0=3;
441: disk_eject(0);
442: strncpy(df0, "", 255);
443: }
444: break;
445: case 1:
446: if(strcmp(df1, f)!=0)
447: {
448: strncpy(dn1, f, 255);
449: dc1=3;
450: disk_eject(1);
451: strncpy(df1, "", 255);
452: }
453: break;
454: case 2:
455: if(strcmp(df2, f)!=0)
456: {
457: strncpy(dn2, f, 255);
458: dc2=3;
459: disk_eject(2);
460: strncpy(df2, "", 255);
461: }
462: break;
463: case 3:
464: if(strcmp(df3, f)!=0)
465: {
466: strncpy(dn3, f, 255);
467: dc3=3;
468: disk_eject(3);
469: strncpy(df3, "", 255);
470: }
471: break;
472: }
473: }
474: else
475: {
476: switch(n)
477: {
478: case 0:
479: strncpy(df0, f, 255);
480: break;
481: case 1:
482: strncpy(df1, f, 255);
483: break;
484: case 2:
485: strncpy(df2, f, 255);
486: break;
487: case 3:
488: strncpy(df3, f, 255);
489: break;
490: }
491: }
492: }
493:
494: void setsonst(int *reserved)
495: {
496: if(!uae_startedup)
497: {
498: gfx_requested_width=reserved[0];
499: gfx_requested_xcenter=reserved[1];
500: gfx_requested_lores=reserved[2];
501: gfx_requested_height=reserved[3];
502: gfx_requested_ycenter=reserved[4];
503: gfx_requested_linedbl=reserved[5];
504: gfx_requested_correct_aspect=reserved[6];
505: switch(reserved[7])
506: {
507: case 256:
508: color_mode=0;
509: break;
510: case 32768:
511: color_mode=1;
512: break;
513: }
514: framerate=reserved[8];
515: emul_accuracy=reserved[9];
516: blits_32bit_enabled=reserved[10];
517: immediate_blits=reserved[11];
518: fake_joystick=reserved[12];
519: bogomem_size=reserved[14];
520: chipmem_size=reserved[15];
521: fastmem_size=reserved[16];
522: produce_sound=reserved[17];
523: sound_desired_freq=reserved[18];
524: sound_desired_bsiz=reserved[19];
525: }
526: }
527:
528: void sendtofront(int *reserved)
529: {
530: int *words=mblock.data.reserved;
531:
532: mblock.size=256;
533: mblock.sender=taskhandle;
534: mblock.my_ref=778;
535: mblock.your_ref=777;
536: switch(*reserved)
537: {
538: case 0:
539: mblock.action=A_disk;
540: if(dc0==0)
541: strncpy(words, df0, 235);
542: else
543: strncpy(words, dn0, 235);
544: break;
545: case 1:
546: mblock.action=A_disk+1;
547: if(dc0==0)
548: strncpy(words, df1, 235);
549: else
550: strncpy(words, dn1, 235);
551: break;
552: case 2:
553: mblock.action=A_disk+2;
554: if(dc0==0)
555: strncpy(words, df2, 235);
556: else
557: strncpy(words, dn2, 235);
558: break;
559: case 3:
560: mblock.action=A_disk+3;
561: if(dc0==0)
562: strncpy(words, df3, 235);
563: else
564: strncpy(words, dn3, 235);
565: break;
566: }
567: wimp_send_message(wimp_USER_MESSAGE, &mblock, frontendhandle);
568: }
569:
570: void gui_messagereceive(void)
571: {
572: switch(block.message.action)
573: {
574: case message_QUIT:
575: if(uae_startedup)
576: {
1.1.1.2 root 577: set_special (SPCFLAG_BRK);
1.1 root 578: quit_program=1;
579: uae_running=1;
580: }
581: else
582: {
583: if(uaedevfd!=-1)
584: {
585: close(uaedevfd);
586: }
587: wimp_close_down(taskhandle);
588: }
589: break;
590: case A_switch:
591: if(uae_startedup)
592: {
593: uae_running=1;
594: setuaemode();
595: setuaesound();
596: }
597: else
598: {
599: frontendhandle=block.message.sender;
600: uae_startedup=1;
601: uae_running=1;
602: }
603: break;
604: case A_disk:
605: changedisk(0, block.message.data.reserved);
606: break;
607: case A_disk+1:
608: changedisk(1, block.message.data.reserved);
609: break;
610: case A_disk+2:
611: changedisk(2, block.message.data.reserved);
612: break;
613: case A_disk+3:
614: changedisk(3, block.message.data.reserved);
615: break;
616: case A_sonst:
617: setsonst(block.message.data.reserved);
618: break;
619: case A_rom:
620: strncpy(romfile, block.message.data.reserved, 235);
621: break;
622: case A_mount:
623: strncpy(mountpoint, block.message.data.reserved, 63);
624: break;
625: case A_mount+1:
626: strncpy(mountdir, block.message.data.reserved, 235);
627: add_filesys_unit(mountpoint, mountdir, 0);
628: break;
629: case A_mount+2:
630: strncpy(mountdir, block.message.data.reserved, 235);
631: add_filesys_unit(mountpoint, mountdir, 1);
632: break;
633: case A_uaeask:
634: sendtofront(block.message.data.reserved);
635: break;
636: }
637: }
638:
639: void gui_process(void)
640: {
641: wimp_event_no event;
642:
643: while(uae_running==0)
644: {
645: event=wimp_poll(wimp_MASK_NULL, &block, 0);
646:
647: switch(event)
648: {
649: case wimp_USER_MESSAGE:
650: case wimp_USER_MESSAGE_RECORDED:
651: gui_messagereceive();
652: break;
653: }
654: }
655: }
656:
657: void gui_exit(void)
658: {
659: }
660:
661: void gui_led(int led, int on)
662: {
663: }
664:
665: void gui_filename(int num, char *name)
666: {
667: }
668:
669: void gui_handle_events(void)
670: {
671: }
672:
673: int gui_update(void)
674: {
675: }
676:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.