Annotation of uae/src/uaelib.c, revision 1.1.1.11

1.1       root        1: /*
                      2:  * UAE - The U*nix Amiga Emulator
1.1.1.3   root        3:  *
1.1       root        4:  * UAE Library v0.1
1.1.1.3   root        5:  *
1.1       root        6:  * (c) 1996 Tauno Taipaleenmaki <[email protected]>
                      7:  *
1.1.1.3   root        8:  * Change UAE parameters and other stuff from inside the emulation.
1.1       root        9:  */
                     10: 
                     11: #include "sysconfig.h"
                     12: #include "sysdeps.h"
                     13: 
                     14: #include <assert.h>
                     15: #include <string.h>
                     16: 
                     17: #include "config.h"
                     18: #include "options.h"
1.1.1.9   root       19: #include "threaddep/thread.h"
1.1.1.3   root       20: #include "uae.h"
                     21: #include "include/memory.h"
1.1       root       22: #include "custom.h"
                     23: #include "newcpu.h"
                     24: #include "xwin.h"
                     25: #include "autoconf.h"
                     26: #include "disk.h"
1.1.1.3   root       27: #include "debug.h"
                     28: #include "gensound.h"
                     29: #include "picasso96.h"
1.1       root       30: 
                     31: /*
                     32:  * Returns UAE Version
                     33:  */
1.1.1.4   root       34: static uae_u32 emulib_GetVersion (void)
1.1       root       35: {
1.1.1.3   root       36:     return version;
1.1       root       37: }
                     38: 
                     39: /*
                     40:  * Resets your amiga
                     41:  */
1.1.1.4   root       42: static uae_u32 emulib_HardReset (void)
1.1       root       43: {
1.1.1.11! root       44:     uae_reset(1);
1.1.1.3   root       45:     return 0;
1.1       root       46: }
                     47: 
1.1.1.4   root       48: static uae_u32 emulib_Reset (void)
1.1       root       49: {
1.1.1.11! root       50:     uae_reset(0);
1.1.1.3   root       51:     return 0;
1.1       root       52: }
                     53: 
                     54: /*
                     55:  * Enables SOUND
                     56:  */
1.1.1.3   root       57: static uae_u32 emulib_EnableSound (uae_u32 val)
1.1       root       58: {
1.1.1.3   root       59:     if (!sound_available || currprefs.produce_sound == 2)
1.1       root       60:        return 0;
                     61: 
1.1.1.3   root       62:     currprefs.produce_sound = val;
1.1       root       63:     return 1;
                     64: }
                     65: 
                     66: /*
                     67:  * Enables FAKE JOYSTICK
                     68:  */
1.1.1.3   root       69: static uae_u32 emulib_EnableJoystick (uae_u32 val)
1.1       root       70: {
1.1.1.5   root       71:     currprefs.jport0 = val & 255;
                     72:     currprefs.jport1 = (val >> 8) & 255;
1.1       root       73:     return 1;
                     74: }
                     75: 
                     76: /*
                     77:  * Sets the framerate
                     78:  */
1.1.1.3   root       79: static uae_u32 emulib_SetFrameRate (uae_u32 val)
1.1       root       80: {
1.1.1.3   root       81:     if (val == 0)
1.1       root       82:        return 0;
1.1.1.3   root       83:     else if (val > 20)
1.1       root       84:        return 0;
                     85:     else {
1.1.1.6   root       86:        currprefs.gfx_framerate = val;
1.1       root       87:        return 1;
                     88:     }
                     89: }
                     90: 
                     91: /*
                     92:  * Changes keyboard language settings
                     93:  */
1.1.1.3   root       94: static uae_u32 emulib_ChangeLanguage (uae_u32 which)
1.1       root       95: {
1.1.1.8   root       96:     if (which > 6)
1.1       root       97:        return 0;
                     98:     else {
1.1.1.3   root       99:        switch (which) {
1.1       root      100:         case 0:
1.1.1.3   root      101:            currprefs.keyboard_lang = KBD_LANG_US;
1.1       root      102:            break;
                    103:         case 1:
1.1.1.8   root      104:            currprefs.keyboard_lang = KBD_LANG_DK;
1.1       root      105:            break;
                    106:         case 2:
1.1.1.8   root      107:            currprefs.keyboard_lang = KBD_LANG_DE;
1.1       root      108:            break;
                    109:         case 3:
1.1.1.8   root      110:            currprefs.keyboard_lang = KBD_LANG_SE;
1.1       root      111:            break;
                    112:         case 4:
1.1.1.8   root      113:            currprefs.keyboard_lang = KBD_LANG_FR;
1.1       root      114:            break;
1.1.1.2   root      115:         case 5:
1.1.1.8   root      116:            currprefs.keyboard_lang = KBD_LANG_IT;
                    117:            break;
                    118:         case 6:
1.1.1.3   root      119:            currprefs.keyboard_lang = KBD_LANG_ES;
1.1.1.2   root      120:            break;
1.1       root      121:         default:
                    122:            break;
                    123:        }
                    124:        return 1;
                    125:     }
                    126: }
                    127: 
1.1.1.3   root      128: /* The following ones don't work as we never realloc the arrays... */
1.1       root      129: /*
1.1.1.3   root      130:  * Changes chip memory size
1.1       root      131:  *  (reboots)
                    132:  */
1.1.1.3   root      133: static uae_u32 emulib_ChgCMemSize (uae_u32 memsize)
1.1       root      134: {
1.1.1.3   root      135:     if (memsize != 0x80000 && memsize != 0x100000 &&
1.1       root      136:        memsize != 0x200000) {
                    137:        memsize = 0x200000;
1.1.1.10  root      138:        write_log ("Unsupported chipmem size!\n");
1.1       root      139:     }
1.1.1.2   root      140:     m68k_dreg(regs, 0) = 0;
1.1.1.3   root      141: 
1.1.1.4   root      142:     currprefs.chipmem_size = memsize;
1.1.1.11! root      143:     uae_reset(0);
1.1       root      144:     return 1;
                    145: }
                    146: 
                    147: /*
1.1.1.3   root      148:  * Changes slow memory size
1.1       root      149:  *  (reboots)
                    150:  */
1.1.1.3   root      151: static uae_u32 emulib_ChgSMemSize (uae_u32 memsize)
1.1       root      152: {
1.1.1.3   root      153:     if (memsize != 0x80000 && memsize != 0x100000 &&
                    154:        memsize != 0x180000 && memsize != 0x1C0000) {
                    155:        memsize = 0;
1.1.1.10  root      156:        write_log ("Unsupported bogomem size!\n");
1.1.1.3   root      157:     }
1.1       root      158: 
1.1.1.3   root      159:     m68k_dreg(regs, 0) = 0;
1.1.1.4   root      160:     currprefs.bogomem_size = memsize;
1.1.1.11! root      161:     uae_reset (0);
1.1.1.3   root      162:     return 1;
1.1       root      163: }
                    164: 
                    165: /*
1.1.1.3   root      166:  * Changes fast memory size
                    167:  *  (reboots)
1.1       root      168:  */
1.1.1.3   root      169: static uae_u32 emulib_ChgFMemSize (uae_u32 memsize)
1.1       root      170: {
1.1.1.3   root      171:     if (memsize != 0x100000 && memsize != 0x200000 &&
                    172:        memsize != 0x400000 && memsize != 0x800000) {
                    173:        memsize = 0;
1.1.1.10  root      174:        write_log ("Unsupported fastmem size!\n");
1.1.1.3   root      175:     }
                    176:     m68k_dreg(regs, 0) = 0;
1.1.1.4   root      177:     currprefs.fastmem_size = memsize;
1.1.1.11! root      178:     uae_reset (0);
1.1.1.3   root      179:     return 0;
1.1       root      180: }
                    181: 
                    182: /*
                    183:  * Inserts a disk
                    184:  */
1.1.1.4   root      185: static uae_u32 emulib_InsertDisk (uaecptr name, uae_u32 drive)
1.1       root      186: {
1.1.1.3   root      187:     int i = 0;
                    188:     char real_name[256];
                    189: 
1.1       root      190:     if (drive > 3)
                    191:        return 0;
                    192: 
1.1.1.3   root      193:     while ((real_name[i] = get_byte (name + i)) != 0 && i++ != 254)
                    194:        ;
1.1       root      195: 
1.1.1.3   root      196:     if (i == 255)
                    197:        return 0; /* ENAMETOOLONG */
1.1       root      198: 
1.1.1.3   root      199:     strcpy (changed_prefs.df[drive], real_name);
1.1       root      200: 
1.1.1.3   root      201:     return 1;
1.1       root      202: }
                    203: 
                    204: /*
                    205:  * Exits the emulator
                    206:  */
1.1.1.4   root      207: static uae_u32 emulib_ExitEmu (void)
1.1       root      208: {
1.1.1.3   root      209:     uae_quit ();
                    210:     return 1;
1.1       root      211: }
                    212: 
                    213: /*
                    214:  * Gets UAE Configuration
                    215:  */
1.1.1.4   root      216: static uae_u32 emulib_GetUaeConfig (uaecptr place)
1.1       root      217: {
1.1.1.3   root      218:     int i,j;
1.1       root      219: 
1.1.1.4   root      220:     put_long (place, version);
                    221:     put_long (place + 4, allocated_chipmem);
                    222:     put_long (place + 8, allocated_bogomem);
                    223:     put_long (place + 12, allocated_fastmem);
1.1.1.6   root      224:     put_long (place + 16, currprefs.gfx_framerate);
1.1.1.4   root      225:     put_long (place + 20, currprefs.produce_sound);
1.1.1.5   root      226:     put_long (place + 24, currprefs.jport0 | (currprefs.jport1 << 8));
1.1.1.4   root      227:     put_long (place + 28, currprefs.keyboard_lang);
                    228:     if (disk_empty (0))
                    229:        put_byte (place + 32, 0);
1.1.1.3   root      230:     else
1.1.1.4   root      231:        put_byte (place + 32, 1);
                    232:     if (disk_empty (1))
                    233:        put_byte (place + 33, 0);
1.1.1.3   root      234:     else
1.1.1.4   root      235:        put_byte (place + 33, 1);
1.1.1.3   root      236:     if (disk_empty(2))
1.1.1.4   root      237:        put_byte (place + 34, 0);
1.1.1.3   root      238:     else
1.1.1.4   root      239:        put_byte (place + 34, 1);
1.1.1.3   root      240:     if (disk_empty(3))
1.1.1.4   root      241:        put_byte (place + 35, 0);
1.1.1.3   root      242:     else
1.1.1.4   root      243:        put_byte (place + 35, 1);
1.1.1.3   root      244: 
                    245:     for (i = 0; i < 256; i++) {
1.1.1.4   root      246:        put_byte ((place + 36 + i), currprefs.df[0][i]);
                    247:        put_byte ((place + 36 + i + 256), currprefs.df[1][i]);
                    248:        put_byte ((place + 36 + i + 512), currprefs.df[2][i]);
                    249:        put_byte ((place + 36 + i + 768), currprefs.df[3][i]);
1.1.1.3   root      250:     }
                    251:     return 1;
1.1       root      252: }
                    253: 
                    254: /*
                    255:  * Sets UAE Configuration
1.1.1.3   root      256:  *
1.1       root      257:  * NOT IMPLEMENTED YET
                    258:  */
1.1.1.4   root      259: static uae_u32 emulib_SetUaeConfig (uaecptr place)
1.1       root      260: {
1.1.1.3   root      261:     return 1;
1.1       root      262: }
                    263: 
                    264: /*
                    265:  * Gets the name of the disk in the given drive
                    266:  */
1.1.1.4   root      267: static uae_u32 emulib_GetDisk (uae_u32 drive, uaecptr name)
1.1       root      268: {
                    269:     int i;
1.1.1.3   root      270:     if (drive > 3)
1.1       root      271:        return 0;
                    272: 
1.1.1.3   root      273:     for (i = 0;i < 256; i++) {
                    274:        put_byte (name + i, currprefs.df[drive][i]);
1.1       root      275:     }
                    276:     return 1;
                    277: }
                    278: 
                    279: /*
                    280:  * Enter debugging state
                    281:  */
1.1.1.4   root      282: static uae_u32 emulib_Debug (void)
1.1       root      283: {
1.1.1.3   root      284:     activate_debugger ();
1.1       root      285:     return 1;
                    286: }
                    287: 
1.1.1.3   root      288: /* We simply find the first "text" hunk, get the offset of its actual code segment (20 bytes away)
                    289:  * and add that offset to the base address of the object.  Now we've got code to execute.
                    290:  *
                    291:  * @@@ Brian: does anything actually use this yet?
1.1.1.5   root      292:  * @@@ Bernd: Not yet.  It needs to get much better.  Should spawn off a seperate task to handle the
                    293:  *            function, and then somehow "signal" the Amiga caller that completion or error has
                    294:  *            occurred.  I don't know how to do that, so right now it is a synchronous call.  Yuck!
                    295:  *            Would be nice to implement jpg decompression functionality for the Amiga which used
                    296:  *            the UAE Host to do all the work, for example.
                    297:  * @@@ Brian: I disabled it to prevent people from starting to use it - if that happens, we're
                    298:  *            stuck with this.
1.1.1.3   root      299:  */
                    300: static uae_u32 FindFunctionInObject (uae_u8 *objectptr)
1.1       root      301: {
1.1.1.3   root      302:     uae_u8 *text_hdr;
                    303:     uae_u8 offset;
                    304:     text_hdr = (uae_u8 *)strstr ("text", (char *)objectptr);
                    305:     if (text_hdr != 0) {
                    306:        offset = *(text_hdr + 19);
                    307:        return (uae_u32)(objectptr + offset);
                    308:     }
                    309:     return 0;
1.1       root      310: }
                    311: 
1.1.1.3   root      312: #define CREATE_NATIVE_FUNC_PTR uae_u32 (* native_func)( uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, \
                    313:                                                 uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32)
                    314: #define SET_NATIVE_FUNC(x) native_func = (uae_u32 (*)(uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32, uae_u32))(x)
                    315: #define CALL_NATIVE_FUNC( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6 ) if(native_func) native_func( d1,d2,d3,d4,d5,d6,d7,a1,a2,a3,a4,a5,a6 )
                    316: /* A0 - Contains a ptr to the native .obj data.  This ptr is Amiga-based. */
                    317: /*      We simply find the first function in this .obj data, and execute it. */
1.1.1.4   root      318: static uae_u32 emulib_ExecuteNativeCode (void)
1.1.1.3   root      319: {
1.1.1.5   root      320: #if 0
1.1.1.3   root      321:     uaecptr object_AAM = m68k_areg( regs, 0 );
                    322:     uae_u32 d1 = m68k_dreg( regs, 1 );
                    323:     uae_u32 d2 = m68k_dreg( regs, 2 );
                    324:     uae_u32 d3 = m68k_dreg( regs, 3 );
                    325:     uae_u32 d4 = m68k_dreg( regs, 4 );
                    326:     uae_u32 d5 = m68k_dreg( regs, 5 );
                    327:     uae_u32 d6 = m68k_dreg( regs, 6 );
                    328:     uae_u32 d7 = m68k_dreg( regs, 7 );
                    329:     uae_u32 a1 = m68k_areg( regs, 1 );
                    330:     uae_u32 a2 = m68k_areg( regs, 2 );
                    331:     uae_u32 a3 = m68k_areg( regs, 3 );
                    332:     uae_u32 a4 = m68k_areg( regs, 4 );
                    333:     uae_u32 a5 = m68k_areg( regs, 5 );
                    334:     uae_u32 a6 = m68k_areg( regs, 6 );
                    335: 
                    336:     uae_u8* object_UAM = NULL;
                    337:     CREATE_NATIVE_FUNC_PTR;
                    338: 
                    339:     if( get_mem_bank( object_AAM ).check( object_AAM, 1 ) )
                    340:        object_UAM = get_mem_bank( object_AAM).xlateaddr( object_AAM );
                    341: 
                    342:     if( object_UAM )
                    343:     {
                    344:        SET_NATIVE_FUNC( FindFunctionInObject( object_UAM ) );
                    345:        CALL_NATIVE_FUNC( d1, d2, d3, d4, d5, d6, d7, a1, a2, a3, a4, a5, a6);
                    346:     }
                    347:     return 1;
1.1.1.5   root      348: #endif
                    349:     return 0;
1.1.1.3   root      350: }
                    351: 
                    352: static uae_u32 uaelib_demux (void)
1.1       root      353: {
1.1.1.3   root      354: #define ARG0 (get_long (m68k_areg (regs, 7) + 4))
                    355: #define ARG1 (get_long (m68k_areg (regs, 7) + 8))
                    356: #define ARG2 (get_long (m68k_areg (regs, 7) + 12))
                    357: #define ARG3 (get_long (m68k_areg (regs, 7) + 16))
                    358: 
                    359:     switch (ARG0) {
                    360:      case 0: return emulib_GetVersion ();
                    361:      case 1: return emulib_GetUaeConfig (ARG1);
                    362:      case 2: return emulib_SetUaeConfig (ARG1);
                    363:      case 3: return emulib_HardReset ();
                    364:      case 4: return emulib_Reset ();
                    365:      case 5: return emulib_InsertDisk (ARG1, ARG2);
                    366:      case 6: return emulib_EnableSound (ARG1);
                    367:      case 7: return emulib_EnableJoystick (ARG1);
                    368:      case 8: return emulib_SetFrameRate (ARG1);
                    369:      case 9: return emulib_ChgCMemSize (ARG1);
                    370:      case 10: return emulib_ChgSMemSize (ARG1);
                    371:      case 11: return emulib_ChgFMemSize (ARG1);
                    372:      case 12: return emulib_ChangeLanguage (ARG1);
                    373:        /* The next call brings bad luck */
                    374:      case 13: return emulib_ExitEmu ();
                    375:      case 14: return emulib_GetDisk (ARG1, ARG2);
                    376:      case 15: return emulib_Debug ();
                    377: 
                    378: #ifdef PICASSO96
1.1.1.4   root      379:      case 16: return picasso_FindCard ();
                    380:      case 17: return picasso_FillRect ();
                    381:      case 18: return picasso_SetSwitch ();
                    382:      case 19: return picasso_SetColorArray ();
                    383:      case 20: return picasso_SetDAC ();
                    384:      case 21: return picasso_SetGC ();
                    385:      case 22: return picasso_SetPanning ();
                    386:      case 23: return picasso_CalculateBytesPerRow ();
                    387:      case 24: return picasso_BlitPlanar2Chunky ();
                    388:      case 25: return picasso_BlitRect ();
                    389:      case 26: return picasso_SetDisplay ();
                    390:      case 27: return picasso_BlitTemplate ();
                    391:      case 28: return picasso_BlitRectNoMaskComplete ();
                    392:      case 29: return picasso_InitCard ();
                    393:      case 30: return picasso_BlitPattern ();
                    394:      case 31: return picasso_InvertRect ();
                    395:      case 32: return picasso_BlitPlanar2Direct ();
                    396:      case 34: return picasso_WaitVerticalSync ();
                    397:      case 35: return allocated_gfxmem ? 1 : 0;
1.1.1.3   root      398: #endif
1.1       root      399: 
1.1.1.4   root      400:      case 69: return emulib_ExecuteNativeCode ();
1.1       root      401:     }
                    402:     return 0;
                    403: }
                    404: 
                    405: /*
                    406:  * Installs the UAE LIBRARY
                    407:  */
1.1.1.4   root      408: void emulib_install (void)
1.1       root      409: {
1.1.1.3   root      410:     uaecptr a = here ();
1.1.1.10  root      411:     org (RTAREA_BASE + 0xFF60);
1.1.1.3   root      412:     calltrap (deftrap (uaelib_demux));
                    413:     dw (RTS);
                    414:     org (a);
1.1       root      415: }

unix.superglobalmegacorp.com

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