home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / emu / LoadRAM.lha / LoadRAM.rexx
Encoding:
OS/2 REXX Batch file  |  1994-05-03  |  1.5 KB  |  58 lines

  1. /* Load file into RAM V1.0 */
  2. parse source mycall .
  3. if mycall=FUNCTION then trace l
  4. call open(file,arg(1))
  5. call readch(file,2)
  6. if RESULT="ffff"x then do /* Recognize special file */
  7.     from=c2d(reverse(readch(file,2)))
  8.     len=c2d(reverse(readch(file,2)))-from+1
  9. end
  10. else if RESULT="0A47"x then do /* Recognize GL file */
  11.     call seek(file,5,B)
  12.     from=c2d(reverse(readch(file,2)))
  13.     say "CALL "from
  14.     call seek(file,20,B)
  15.     len=c2d(reverse(readch(file,2)))
  16.     call seek(file,128,B)
  17. end
  18. else do /* Suppose basic file */
  19.     from=2049
  20.     len=c2d(RESULT)
  21. end
  22. /*
  23. if ~show('l','rexxsupport.library') then
  24.     call addlib('rexxsupport.library',0,-30)
  25. call forbid
  26. */
  27. do for 10 until RESULT~=0
  28.     call findprocess("applem000")
  29. end
  30. if RESULT=0 then exit 1
  31. call findseg(RESULT)
  32. call export(d2c(c2d(import(d2c(RESULT+150,4),4))+from,4),readch(file,len))
  33. exit 0
  34.  
  35. FINDPROCESS: /* Based on c't 89/3 p. 142 */
  36. ExecBase=c2d(import('00000004'x,4))
  37. TaskWait=c2d(import(d2c(ExecBase+420,4),4))
  38. do while TaskWait~=0
  39.     if c2d(import(d2c(TaskWait+8,4),1))=13 &,
  40.        c2d(import(d2c(TaskWait+140,4),4))~=0 then do
  41.         CLI=c2d(import(d2c(TaskWait+172,4),4))
  42.         CommandName=c2d(import(d2c(CLI*4+16,4),4))
  43.         CommandName=import(d2c(CommandName*4+1,4))
  44.         if abbrev(reverse(CommandName),reverse(arg(1))) then leave
  45.     end
  46.     TaskWait=c2d(import(d2c(TaskWait,4),4))
  47. end
  48. return TaskWait
  49.  
  50. FINDSEG: /* Based on Xoper hunks */
  51. seglist=import(d2c(arg(1)+172,4),4)
  52. seglist=c2d(seglist)*4+60
  53. do 2
  54.     seglist=import(d2c(seglist,4),4)
  55.     seglist=c2d(seglist)*4
  56. end
  57. return seglist
  58.