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

  1. /* This script is used to load/save from .TAP files */
  2.  
  3. /* To convert .header/.bytes files to .TAP you must use a block copier, */
  4. /* like DUPLITAPE, using 'Load Mode -> Disk' and 'Save Mode -> ARexx' */
  5.  
  6.     /* check if the emulator is present */
  7.     address command
  8.     
  9.     if ~show(ports,ZXAM_REXX) then do
  10.         requestchoice 'title "ZXAM Script error..." body "I couldnt find the emulator port!!" gadgets "AARGH!"'
  11.         exit
  12.         end
  13.  
  14.     ZXAMTapeSetResult(2)   /* result=error */
  15.  
  16.     /* Check the operation that must be done */
  17.     
  18.     oper=ZXAMTapeAction()
  19.     if oper=0 then exit   /* Script started manually */
  20.     if oper=3 then signal actionsave   /* SAVE */
  21.  
  22.     /* LOAD or VERIFY */
  23. actionload:
  24.     nombre=ZXAMTapeLoadName()   /* Name of the .TAP actually selected */
  25.  
  26.         ZXAMTapeSetLoadName('')
  27.  
  28.     /* LOAD requester if no .TAP file is selected */
  29.     if nombre='' then do
  30.        oldpath=zxamactloadpath()
  31.        oldpattern=zxamactpattern()
  32.        zxamloadpath("ram:")
  33.        zxampattern('#?.TAP')
  34.        ZXAMControlToFront()
  35.        nombre=zxamloadrequester("Select the .TAP file for LOAD...")
  36.        ZXAMTapeSetLoadOffset(0)
  37.        ZXAMEmulToFront()
  38.        zxamloadpath(oldpath)
  39.        zxampattern(oldpattern)
  40.     end
  41.  
  42.     if nombre='' then exit 0    /* CANCEL */
  43.  
  44.     /* open the file */
  45.     if ~open('fichero',nombre,'R') then exit 0
  46.     
  47.     /* Move to the adequate place of the file */
  48.     filepos=ZXAMTapeLoadOffset()
  49.  
  50.     /* If there are problems, select another .TAP file */
  51.     if filepos~=seek('fichero',filepos,'B') then do
  52.        dummy=close('fichero')
  53.        signal actionload
  54.     end
  55.     
  56.     /* read the size of the actual block */
  57.     size=readch('fichero',2)
  58.     if length(size)~=2 then do
  59.     dummy=close('fichero')
  60.     signal actionload
  61.     end
  62.     
  63.     /* open the temporary file */
  64.     if ~open('destino','t:zxamtemp','W') then exit 0
  65.     
  66.     size=c2d(reverse(size)) /* fomato invertido Z80 */
  67.     
  68.     /* load the block */
  69.     block=readch('fichero',size)
  70.     
  71.     /* save it to the temporary file */
  72.     dummy=writech('destino',block)
  73.     
  74.     ZXAMTapeSetLoadName(nombre)
  75.     ZXAMTapeSetLoadOffset(seek('fichero',0,'C'))
  76.  
  77.     ZXAMTapeSetResult(1,'t:zxamtemp')
  78.     
  79.     dummy=close('fichero')
  80.     dummy=close('destino')
  81.     
  82.     exit
  83.  
  84.  
  85.     /* SAVE */
  86. actionsave: 
  87.     nombre=ZXAMTapeSaveName()
  88.  
  89.         ZXAMTapeSetSaveName("")
  90.  
  91.     if ((zxamtapeflag()=0)&(zxampeek(zxamtapeaddress())=0)&(zxamtapesize()=17)) then nombre=''
  92.  
  93.     /* SAVE requester */
  94.     if nombre='' then do
  95.        oldpath=zxamactsavepath()
  96.        oldpattern=zxamactpattern()
  97.        zxamsavepath("ram:")
  98.        zxampattern('#?.TAP')
  99.        ZXAMControlToFront()
  100.        nombre=zxamsaverequester("Select the .TAP file for SAVE...")
  101.        ZXAMTapeSetSaveOffset(0)
  102.        ZXAMEmulToFront()
  103.        zxamsavepath(oldpath)
  104.        zxampattern(oldpattern)
  105.     end
  106.     if nombre='' then exit 0    /* CANCEL */
  107.  
  108.     if ~exists(nombre) then
  109.       /* create the file */
  110.       if ~open('fichero',nombre,'WRITE') then exit
  111.       else nop
  112.     else
  113.       /* open the file in APPEND mode */
  114.       if ~open('fichero',nombre,'APPEND') then exit
  115.       else nop
  116.     endif
  117.     /* Extract from the spectrum's memory the block to save */
  118.     block=d2c(zxamtapeflag())
  119.     if zxamtapesize()~=0 then block=insert(block,zxamgetmem(zxamtapeaddress(),zxamtapesize()))
  120.     block=insert(block,d2c(zxamchecksumstring(block)))
  121.     /* append the block size */
  122.     size=zxamtapesize()+2
  123.     size=d2c(size)
  124.     if length(size)=1 then size=insert(d2c(0),size)
  125.     /* convert to inverted Z80 format */
  126.     size=reverse(size)
  127.     block=insert(size,block)
  128.     /* save the block */
  129.     dummy=writech('fichero',block)
  130.     
  131.     ZXAMTapeSetSaveName(nombre)
  132.  
  133.     ZXAMTapeSetResult(1)
  134.     
  135.     dummy=close('fichero')
  136.     
  137.     exit
  138.  
  139.