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

  1. /* This script is a mini-monitor created by Leonardo Cocaña Galán */
  2. /* Created from some example scripts of ZXAM, and some ownmade work, */
  3. /* of course! */
  4. /* Will be greatly enhanced.... */
  5.  
  6.     /* check if the emulator is there */
  7.     address command
  8.     
  9.     if ~show(ports,ZXAM_REXX) then do
  10.         requestchoice 'title "ZXAM Script error..." body "I couldn't find the emulator's port!!" gadgets "AARGH!"'
  11.         exit
  12.         end
  13.  
  14.     /* store the initial status of the emulator */
  15.     running=zxamactrun()    /* 1=running */
  16.     zxamstop()              /* stop the emulation */
  17.  
  18.     /* open the output window */
  19.     if ~open('fichero','con:0/11/640/256/Example of a simple monitor','W') then exit
  20.     
  21.     dir=zxamgetreg(pc)
  22.     call desambla(dir,16)
  23.     call registros()
  24.  
  25. bucle:    /* more? */
  26.     call print ('Disas(S)emble,(N)ewAdd,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')
  71.         dummy=writech('fichero',substr(linea,2))
  72.         dummy=writech('fichero','0a'x)
  73.         direccion=(direccion+left(linea,1))
  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.     /* restore the status */
  126.     if running=1 then zxamrun()
  127.  
  128.     exit
  129. newdir:
  130. call print ('New 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. /* this script extracts the BASIC listing in the spectrum's memory... */
  169.     
  170.     /* start address BASIC (variable PROG) */
  171.     baselist=zxamdpeek(23635)
  172.     
  173.     /* length BASIC (with variable VARS) */
  174.     endlist=zxamdpeek(23627)
  175.     
  176.     /* calculate size */
  177.     longbasic=endlist-baselist
  178.     if longbasic=0 then do
  179.         requestchoice '>nil: title "ZXAM Script error..." body "No BASIC program!!" gadgets "AARGH!"'
  180.         return
  181.         end
  182.     
  183.     /* get the whole BASIC area */
  184.     bloquebasic=zxamgetmem(baselist,endlist-baselist)
  185.  
  186.  
  187.     do forever    
  188.     /* process a line */
  189.         
  190.         numlinea=c2d(left(bloquebasic,2))
  191.         dummy=writech('fichero','  'numlinea)
  192.         longline=c2d(reverse(substr(bloquebasic,3,2)))
  193.         do i=5 to 4+longline    
  194.         if substr(bloquebasic,i,1)='0e'x then do
  195.             i=i+5
  196.             iterate
  197.             end
  198.         dummy=writech('fichero',zxambasictoken(substr(bloquebasic,i,1)))
  199.         
  200.         
  201.         end i
  202.         
  203.     dummy=writech('fichero','0a'x)
  204.     
  205.     bloquebasic=right(bloquebasic,length(bloquebasic)-(longline+4))
  206.     if bloquebasic='' then break
  207.     end
  208. return
  209.  
  210. Setpc:
  211.  
  212. call print ('PC :')
  213. pcdir=input()
  214. if (pcdir>65535 | pcdir<0) then signal setpc
  215. zxamsetreg(pc,pcdir)
  216. dir=zxamgetreg(pc)
  217. call desambla(dir,16)
  218. call registros()
  219. return
  220.  
  221. Error_dir:
  222.  
  223. Call Print ('ERROR: ADDRESS OUT OF RANGE (16384-65535)')
  224. dummy=writech('fichero','0a'x)
  225. Signal poke
  226.  
  227. Error_val:
  228.  
  229. Call print ('ERROR: VALUE OUT OF RANGE (0-255)')
  230. dummy=writech('fichero','0a'x)
  231. Signal poke
  232.  
  233. Error_long:
  234.  
  235. Call print ('ERROR: WRONG PARAMETERS (POKE 60000,255)')
  236. dummy=Writech('fichero','0a'x)
  237. signal poke
  238.  
  239. error_noblock:
  240.  
  241. call print ('DATA BLOCK NOT FOUND')
  242. dummy=writech('fichero','0a'x)
  243. return
  244.  
  245. Findblock:
  246. direc=0
  247. call print ('Enter data to search (hex):') 
  248. block=x2c(input())
  249. bucle1:
  250. call busca(direc)
  251. if direc<=-1 then do
  252. call error_noblock
  253. return
  254. end
  255. call desambla(direc,3)
  256. direc=dir
  257. signal bucle1
  258. return
  259. busca:
  260. parse arg comienzo
  261. direc=zxamfindblock(comienzo,block)
  262. return
  263.  
  264. breakpoint:
  265. call print('Break Point address: ')
  266. break=input()
  267. if (break<0 |break>65535) then signal breakpoint
  268. zxambreakpoint(break)
  269. return
  270.