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