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