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

  1. /* Este script carga un snapshot de disco */
  2. /* Usa los conversores internos del emulador (MIRAGE y PC) */
  3.  
  4.     address command
  5.  
  6.     if ~show(ports,ZXAM_REXX) then do
  7.         requestchoice 'title "ZXAM Script error..." body "No encuentro el puerto del emulador!!" gadgets "AARGH!"'
  8.         exit
  9.         end
  10.  
  11.     /* Almacenar el estado inicial del emulador */
  12.     running=zxamactrun()    /* 1=en marcha */
  13.     zxamstop()              /* lo paramos */
  14.  
  15. /* Usamos el requester del programa para cargar el fichero */
  16.     
  17.     oldname=zxamactname()        /* nombre actual */
  18.     oldformat=zxamactformat()    /* formato actual */
  19.     
  20.     nombre=zxamloadrequester('Elige programa Spectrum...')
  21.     if nombre='' then exit    /* selección cancelada */
  22.     
  23.     bloque=zxampploadfile(nombre)    /* cargamos TODO el fichero */
  24.     
  25.     formato=zxamparseloaded(bloque)        /* reconoce y carga el fichero */
  26.     
  27.     if formato~='' then do
  28.         zxamnameformat(zxamfilepart(nombre),formato)
  29.         exit
  30.         end
  31.     
  32. /* Yep! No es formato mirage ni pc. Aqui debemos poner el código para */
  33. /* reconocer los demás formatos */
  34.  
  35. /* este es simplemente un ejemplo, ya que intenta reconocer el formato MIRAGE */
  36. /* y cargarlo en memoria, colocando los registros adecuadamente */
  37. /* Para cualquier otro formato solo hay que modificar los offsets */
  38. /* para los registros y la memoria */
  39.     if length(bloque)=49179 then do        /* formato MIRAGE (creo...) */
  40.         zxamsetreg(i,c2d(substr(bloque,1,1)))    /* registro i */
  41.         zxamsetreg(lh2,c2d(substr(bloque,2,2)))    /* registro hl' */
  42.         zxamsetreg(ed2,c2d(substr(bloque,4,2)))    /* registro de' */
  43.         zxamsetreg(cb2,c2d(substr(bloque,6,2)))    /* registro bc' */
  44.         zxamsetreg(f2,c2d(substr(bloque,8,1)))    /* registro f' */
  45.         zxamsetreg(a2,c2d(substr(bloque,9,1)))    /* registro a' */
  46.         zxamsetreg(lh,c2d(substr(bloque,10,2)))    /* registro hl */
  47.         zxamsetreg(ed,c2d(substr(bloque,12,2)))    /* registro de */
  48.         zxamsetreg(cb,c2d(substr(bloque,14,2)))    /* registro bc */
  49.         zxamsetreg(yi,c2d(substr(bloque,16,2)))    /* registro iy */
  50.         zxamsetreg(xi,c2d(substr(bloque,18,2)))    /* registro ix */
  51.         zxamsetreg(int,bittst(substr(bloque,20,1),2)) /* estado interrupciones */
  52.         zxamsetreg(r,c2d(substr(bloque,21,1)))    /* registro r */
  53.         zxamsetreg(f,c2d(substr(bloque,22,1)))    /* registro f */
  54.         zxamsetreg(a,c2d(substr(bloque,23,1)))    /* registro a */
  55.         zxamsetreg(ps,c2d(substr(bloque,24,2)))    /* registro sp */
  56.         zxamsetreg(pc,zxamfindbyte(0,201))    /* dir de un RET en ROM */
  57.         zxamsetreg(im,c2d(substr(bloque,26,1)))    /* modo de interrupción */
  58.         zxamsetreg(bor,c2d(substr(bloque,27,1)))    /* color del borde */
  59.         /* colocamos los 48k de RAM */
  60.         zxamputmem(16384,substr(bloque,28,49152))
  61.         
  62.         /* ponemos en la ventana el nombre y el formato */
  63.         zxamnameformat(zxamfilepart(nombre),'mirage')
  64.         zxamnoreload()
  65.         
  66.         exit
  67.         
  68.         end
  69.  
  70.  
  71. /* este es otro ejemplo, que carga un fichero en formato PC */
  72.     if length(bloque)=49190 then do        /* formato PC?? */
  73.         if left(bloque,2)~='SP' then break    /* mismo tamaño pero sin ID! */
  74.         zxamsetreg(cb,c2d(substr(bloque,7,2)))
  75.         zxamsetreg(ed,c2d(substr(bloque,9,2)))
  76.         zxamsetreg(lh,c2d(substr(bloque,11,2)))
  77.         zxamsetreg(f,c2d(substr(bloque,13,1)))
  78.         zxamsetreg(a,c2d(substr(bloque,14,1)))
  79.         zxamsetreg(xi,c2d(substr(bloque,15,2)))
  80.         zxamsetreg(yi,c2d(substr(bloque,17,2)))
  81.         zxamsetreg(cb2,c2d(substr(bloque,19,2)))
  82.         zxamsetreg(ed2,c2d(substr(bloque,21,2)))
  83.         zxamsetreg(lh2,c2d(substr(bloque,23,2)))
  84.         zxamsetreg(f2,c2d(substr(bloque,25,1)))
  85.         zxamsetreg(a2,c2d(substr(bloque,26,1)))
  86.         zxamsetreg(r,c2d(substr(bloque,27,1)))
  87.         zxamsetreg(i,c2d(substr(bloque,28,1)))
  88.         zxamsetreg(ps,c2d(substr(bloque,29,2)))
  89.         zxamsetreg(cp,c2d(substr(bloque,31,2)))
  90.         zxamsetreg(bor,c2d(substr(bloque,35,1)))
  91.         zxamsetreg(int,bittst(substr(bloque,37,1),0))
  92.         zxamsetreg(im,1+bittst(substr(bloque,37,1),1))
  93.         /* colocamos los 48k de RAM */
  94.         zxamputmem(16384,substr(bloque,39,49152))
  95.         
  96.         /* ponemos en la ventana el nombre y el formato */
  97.         zxamnameformat(zxamfilepart(nombre),'PC')
  98.         zxamnoreload()
  99.         
  100.         exit
  101.         
  102.         end
  103.  
  104.  
  105.  
  106. /* al final de todo generamos un error, ya que ninguno de los bloques de */
  107. /* reconocimiento ha podido reconocer el formato */
  108.  
  109.     requestchoice 'title "ZXAM Script error..." body "Formato desconocido!!" gadgets "AARGH!"'
  110.  
  111.     if oldname='' then
  112.         zxamclearnameformat()
  113.     else
  114.         zxamnameformat(oldname,oldformat)
  115.     
  116.     /* dejar el emulador como estaba */
  117.     if running=1 then zxamrun()
  118.  
  119.     exit
  120.