home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Emulation / ZXAMSpectrum / ZXAM_Rexx / English / LoadFile.zxam < prev    next >
Text File  |  1995-07-31  |  4KB  |  117 lines

  1. /* this script load a snapshot from disk */
  2. /* Uses the internal loaders of emulator (MIRAGE & PC) */
  3.  
  4.     address command
  5.  
  6.     if ~show(ports,ZXAM_REXX) then do
  7.         requestchoice 'title "ZXAM Script error..." body "I can''t find the emulator''s port!!" gadgets "AARGH!"'
  8.         exit
  9.         end
  10.  
  11.     /* store the initial status of the emulator */
  12.     running=zxamactrun()    /* 1=running */
  13.     zxamstop()              /* stop the emulation */
  14.  
  15. /* We use the emulator's filerequester */
  16.     
  17.     /* old window status */
  18.     oldname=zxamactname()
  19.     oldformat=zxamactformat()
  20.     
  21.     nombre=zxamloadrequester('Select a snapshot...')
  22.     if nombre='' then exit    /* CANCEL */
  23.     
  24.     bloque=zxampploadfile(nombre)    /* load the whole file */
  25.     
  26.     formato=zxamparseloaded(bloque)        /* parse the file if known format */
  27.     
  28.     if formato~='' then do            /* known format */
  29.         zxamnameformat(zxamfilepart(nombre),formato)
  30.         exit
  31.         end
  32.     
  33. /* Yep! Unknown format. Here you can put the relevant code for loading of */
  34. /* other formats */
  35.  
  36. /* This is an example of how to implement a format (mirage, in this case) */
  37.     if length(bloque)=49179 then do        /* MIRAGE (I think...) */
  38.         zxamsetreg(i,c2d(substr(bloque,1,1)))    /* register i */
  39.         zxamsetreg(lh2,c2d(substr(bloque,2,2)))    /* register hl' */
  40.         zxamsetreg(ed2,c2d(substr(bloque,4,2)))    /* register de' */
  41.         zxamsetreg(cb2,c2d(substr(bloque,6,2)))    /* register bc' */
  42.         zxamsetreg(f2,c2d(substr(bloque,8,1)))    /* register f' */
  43.         zxamsetreg(a2,c2d(substr(bloque,9,1)))    /* register a' */
  44.         zxamsetreg(lh,c2d(substr(bloque,10,2)))    /* register hl */
  45.         zxamsetreg(ed,c2d(substr(bloque,12,2)))    /* register de */
  46.         zxamsetreg(cb,c2d(substr(bloque,14,2)))    /* register bc */
  47.         zxamsetreg(yi,c2d(substr(bloque,16,2)))    /* register iy */
  48.         zxamsetreg(xi,c2d(substr(bloque,18,2)))    /* register ix */
  49.         zxamsetreg(int,bittst(substr(bloque,20,1),2)) /* interrupt status */
  50.         zxamsetreg(r,c2d(substr(bloque,21,1)))    /* register r */
  51.         zxamsetreg(f,c2d(substr(bloque,22,1)))    /* register f */
  52.         zxamsetreg(a,c2d(substr(bloque,23,1)))    /* register a */
  53.         zxamsetreg(ps,c2d(substr(bloque,24,2)))    /* register sp */
  54.         zxamsetreg(pc,zxamfindbyte(0,201))    /* address of a RET in ROM */
  55.         zxamsetreg(im,c2d(substr(bloque,26,1)))    /* interrupt mode */
  56.         zxamsetreg(bor,c2d(substr(bloque,27,1)))    /* border color */
  57.         /* put the 48k of RAM */
  58.         zxamputmem(16384,substr(bloque,28,49152))
  59.         
  60.         /* put name a formt in the window */
  61.         zxamnameformat(zxamfilepart(nombre),'mirage')
  62.         zxamnoreload()
  63.         
  64.         exit
  65.         
  66.         end
  67.  
  68.  
  69. /* this examle loads a PC snapshot */
  70.     if length(bloque)=49190 then do        /* format PC?? */
  71.         if left(bloque,2)~='SP' then break    /* same size, but no ID */
  72.         zxamsetreg(cb,c2d(substr(bloque,7,2)))
  73.         zxamsetreg(ed,c2d(substr(bloque,9,2)))
  74.         zxamsetreg(lh,c2d(substr(bloque,11,2)))
  75.         zxamsetreg(f,c2d(substr(bloque,13,1)))
  76.         zxamsetreg(a,c2d(substr(bloque,14,1)))
  77.         zxamsetreg(xi,c2d(substr(bloque,15,2)))
  78.         zxamsetreg(yi,c2d(substr(bloque,17,2)))
  79.         zxamsetreg(cb2,c2d(substr(bloque,19,2)))
  80.         zxamsetreg(ed2,c2d(substr(bloque,21,2)))
  81.         zxamsetreg(lh2,c2d(substr(bloque,23,2)))
  82.         zxamsetreg(f2,c2d(substr(bloque,25,1)))
  83.         zxamsetreg(a2,c2d(substr(bloque,26,1)))
  84.         zxamsetreg(r,c2d(substr(bloque,27,1)))
  85.         zxamsetreg(i,c2d(substr(bloque,28,1)))
  86.         zxamsetreg(ps,c2d(substr(bloque,29,2)))
  87.         zxamsetreg(cp,c2d(substr(bloque,31,2)))
  88.         zxamsetreg(bor,c2d(substr(bloque,35,1)))
  89.         zxamsetreg(int,bittst(substr(bloque,37,1),0))
  90.         zxamsetreg(im,1+bittst(substr(bloque,37,1),1))
  91.         /* put the 48k of RAM */
  92.         zxamputmem(16384,substr(bloque,39,49152))
  93.         
  94.         /* put new name and format */
  95.         zxamnameformat(zxamfilepart(nombre),'PC')
  96.         zxamnoreload()
  97.         
  98.         exit
  99.         
  100.         end
  101.  
  102.  
  103. /* if program reached this point means that the format is totally unknown */
  104. /* load error! */
  105.     
  106.     requestchoice 'title "ZXAM Script error..." body "Unknown format!!" gadgets "AARGH!"'
  107.  
  108.     if oldname='' then
  109.         zxamclearnameformat()
  110.     else
  111.         zxamnameformat(oldname,oldformat)
  112.  
  113.     /* restore the status */
  114.     if running=1 then zxamrun()
  115.  
  116.     exit
  117.