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

  1. /* Este script es un mini-monitor de CM creado por Leonardo Cocaña Galán */
  2. /* Montado a partir de varios de los ejemplos que acompañan el ZXAM, y */
  3. /* con aportación propia, por supuesto! */
  4. /* Con el tiempo será bastante mejorado... */
  5.  
  6.     /* comprobamos si el emulador está presente */
  7.     address command
  8.     
  9.     if ~show(ports,ZXAM_REXX) then do
  10.         requestchoice 'title "ZXAM Script error..." body "No encuentro el puerto del emulador!!" gadgets "AARGH!"'
  11.         exit
  12.         end
  13.  
  14.     /* Almacenar el estado inicial del emulador */
  15.     running=zxamactrun()    /* 1=en marcha */
  16.     zxamstop()              /* lo paramos */
  17.  
  18.     /* abrimos la ventana de salida */
  19.     if ~open('fichero','con:0/11/640/256/Ejemplo de uso de ZXAMDisassemble()','W') then exit
  20.     
  21.     dir=zxamgetreg(pc)
  22.     call desambla(dir,16)
  23.     call registros()
  24.  
  25. bucle:    /* debemos seguir? */
  26.     call print ('(S)eguir,(N)ewDir,Set(PC),(P)oke,P(E)ek,(R)un,')
  27.     dummy=writech('fichero','0a'x)
  28.     call print ('(T)race,Brea(K)Point,Re(L)oad,(B)asic,(Q)uit,(F)ind: ')
  29.     respuesta=input()
  30.     respuesta=upper(respuesta)    
  31.     if (respuesta='S'|respuesta='') then do 
  32.     call desambla(dir,16)
  33.     call registros ()
  34.     end
  35.     if respuesta='Q' then signal cleanup
  36.     if respuesta='N' then call newdir()
  37.     if respuesta='P' then call poke()
  38.     if respuesta='R' then do 
  39.         zxamrun()
  40.         dir=zxamgetreg(pc)
  41.         call desambla(dir,16)
  42.         call registros()
  43.     end
  44.     if respuesta='L' then do 
  45.         call reload
  46.         dir=zxamgetreg(pc)
  47.         call desambla(dir,16)
  48.         call registros()
  49.         end
  50.     if respuesta='B' then do 
  51.         call listbasic
  52.         signal bucle
  53.         end
  54.     if respuesta='PC' then     call setpc
  55.         if respuesta='F'  then  call Findblock
  56.     if respuesta='E'  then  call peek
  57.     if respuesta='T' then do 
  58.         dummy=zxamtrace()
  59.         dir=zxamgetreg(pc)
  60.         call desambla(dir,16)
  61.         call registros()
  62.         end
  63.     if respuesta='K' then call breakpoint
  64. signal bucle
  65.  
  66. Desambla:
  67.  
  68. Parse arg direccion,linias
  69. do i=1 to linias 
  70.         linea=zxamdisassemble(direccion,'d')        /* desensambla en decimal */
  71.         dummy=writech('fichero',substr(linea,2))
  72.         dummy=writech('fichero','0a'x)
  73.         direccion=(direccion+left(linea,1))            /* suma bytes que ocupa la inst */
  74.         if direccion>65535 then direccion=direccion-65536    
  75. dir = direccion
  76. end i
  77.  
  78. return
  79. registros:
  80. dummy=writech('fichero','0a'x)
  81. dummy=writech('fichero','BC  'zxamgetreg(bc,h))
  82. dummy=writech('fichero','     DE  'zxamgetreg(de,h))
  83. dummy=writech('fichero','     HL  'zxamgetreg(hl,h))
  84. dummy=writech('fichero',"     BC' "zxamgetreg(bc2,h))
  85. dummy=writech('fichero',"     DE' "zxamgetreg(de2,h))
  86. dummy=writech('fichero',"     HL' "zxamgetreg(hl2,h))
  87. dummy=writech('fichero','0a'x)
  88.         
  89. dummy=writech('fichero','IX  'zxamgetreg(ix,h))
  90. dummy=writech('fichero','     IY  'zxamgetreg(iy,h))
  91. dummy=writech('fichero','     SP  'zxamgetreg(sp,h))
  92. dummy=writech('fichero','     PC  'zxamgetreg(pc,h))
  93. dummy=writech('fichero','      I  'zxamgetreg('i',h))
  94. dummy=writech('fichero','        R  'zxamgetreg(r,h))
  95. dummy=writech('fichero','0a'x)
  96. dummy=writech('fichero'," A  "zxamgetreg(a,h))
  97. dummy=writech('fichero',"        F  "zxamgetreg(f,h))
  98. dummy=writech('fichero',"        A' "zxamgetreg(a2,h))
  99. dummy=writech('fichero',"        F' "zxamgetreg(f2,h))
  100.  
  101. dummy=writech('fichero','       IM'zxamgetreg(im))
  102. dummy=writech('fichero','          INT 'zxamgetreg(int))
  103.  
  104. dummy=writech('fichero','0a'x)
  105. dummy=writech('fichero','0a'x)
  106.         
  107. dummy=writech('fichero','S   Z   -   H   -  P/V  N   C')
  108. dummy=writech('fichero','0a'x)
  109.         
  110. dummy=writech('fichero',bittst(d2c(zxamgetreg(f)),7))
  111. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),6))
  112. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),5))
  113. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),4))
  114. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),3))
  115. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),2))
  116. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),1))
  117. dummy=writech('fichero','   'bittst(d2c(zxamgetreg(f)),0))
  118. dummy=writech('fichero','0a'x)
  119. dummy=writech('fichero','0a'x)
  120. return
  121. cleanup:
  122.  
  123.     dummy=close('fichero')
  124.  
  125.     /* dejar el emulador como estaba */
  126.     if running=1 then zxamrun()
  127.  
  128.     exit
  129. newdir:
  130. call print ('Dirección PC: ')
  131. dir=input()
  132. if (dir>65535 | dir<0)  then signal newdir
  133. call desambla(dir,16)
  134. call registros()
  135. return
  136.  
  137. peek:
  138. call print ('PEEK: ')
  139. pek=input()
  140. if (dir>65535 | dir<0)  then signal peek
  141. call print (zxampeek(pek))
  142. dummy=writech('fichero','0a'x)
  143. return
  144. poke:
  145. call print ('POKE ')
  146. pok=input()
  147. if length(pok)<7 then signal error_long
  148. dirpoke=left(pok,(lastpos(",",pok)-1))
  149. valor=right(pok,(length(pok)-lastpos(',',pok)))
  150. if (dirpoke<16384 | dirpoke>65535) then signal error_dir
  151. if (valor<0 |valor>255) then signal error_val
  152. zxampoke(dirpoke,valor)
  153. return
  154.  
  155. Print:
  156. parse arg texto
  157. dummy=writech('fichero',texto)
  158. return
  159.  
  160. Input:
  161. return readln('fichero')
  162.  
  163. Reload:
  164. zxamparseloaded(zxampploadfile(zxamjoinpathname(zxamactloadpath(),zxamactname())))
  165. return
  166.  
  167. Listbasic:
  168. /* este script saca el listado del BASIC presente en la memoria del */
  169. /* Spectrum y lo graba como fichero */
  170.     
  171.  
  172.     /* debemos listar el BASIC. primero lo localizamos */
  173.     
  174.     /* dir inicio del BASIC (variable PROG) */
  175.     baselist=zxamdpeek(23635)
  176.     
  177.     /* longitud del programa BASIC (con variable VARS) */
  178.     endlist=zxamdpeek(23627)
  179.     
  180.     /* calculamos tamaño */
  181.     longbasic=endlist-baselist
  182.     if longbasic=0 then do
  183.         requestchoice '>nil: title "ZXAM Script error..." body "No hay programa BASIC!!" gadgets "AARGH!"'
  184.         return
  185.         end
  186.     
  187.     /* cogemos toda el area BASIC */
  188.     bloquebasic=zxamgetmem(baselist,endlist-baselist)
  189.  
  190.  
  191.     do forever    
  192.     /* procesamos la linea */
  193.         
  194.         /* imprimimos numero de linea */
  195.         numlinea=c2d(left(bloquebasic,2))
  196.         dummy=writech('fichero','  'numlinea)
  197.         longline=c2d(reverse(substr(bloquebasic,3,2))) /* fomato invertido Z80 */
  198.         do i=5 to 4+longline    /* para procesar los caracteres de la linea */
  199.         if substr(bloquebasic,i,1)='0e'x then do
  200.             i=i+5
  201.             iterate
  202.             end
  203.         dummy=writech('fichero',zxambasictoken(substr(bloquebasic,i,1)))
  204.         
  205.         
  206.         end i
  207.         
  208.     dummy=writech('fichero','0a'x)
  209.     
  210.     bloquebasic=right(bloquebasic,length(bloquebasic)-(longline+4))
  211.     if bloquebasic='' then break
  212.     end
  213. return
  214.  
  215. Setpc:
  216.  
  217. call print ('PC :')
  218. pcdir=input()
  219. if (pcdir>65535 | pcdir<0) then signal setpc
  220. zxamsetreg(pc,pcdir)
  221. dir=zxamgetreg(pc)
  222. call desambla(dir,16)
  223. call registros()
  224. return
  225.  
  226. Error_dir:
  227.  
  228. Call Print ('ERROR DIRECCION FUERA DE MARGEN (16384-65535)')
  229. dummy=writech('fichero','0a'x)
  230. Signal poke
  231.  
  232. Error_val:
  233.  
  234. Call print ('ERROR VALOR FUERA DE MARGEN (0-255)')
  235. dummy=writech('fichero','0a'x)
  236. Signal poke
  237.  
  238. Error_long:
  239.  
  240. Call print ('ERROR PARAMETROS INCORRECTO (POKE 60000,255)')
  241. dummy=Writech('fichero','0a'x)
  242. signal poke
  243.  
  244. error_noblock:
  245.  
  246. call print ('BLOQUE DE DATOS NO ENCONTRADO')
  247. dummy=writech('fichero','0a'x)
  248. return
  249.  
  250. Findblock:
  251. direc=0
  252. call print ('Inserte datos a buscar (hex):') 
  253. block=x2c(input())
  254. bucle1:
  255. call busca(direc)
  256. if direc<=-1 then do
  257. call error_noblock
  258. return
  259. end
  260. call desambla(direc,3)
  261. direc=dir
  262. signal bucle1
  263. return
  264. busca:
  265. parse arg comienzo
  266. direc=zxamfindblock(comienzo,block)
  267. return
  268.  
  269. breakpoint:
  270. call print('Direccion Break Point: ')
  271. break=input()
  272. if (break<0 |break>65535) then signal breakpoint
  273. zxambreakpoint(break)
  274. return
  275.