Annotation of uae/src/rpc.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.