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