Pseudo-Random Numbers ROM Zone Finder Pro

Este programa es una versión de Pseudo-Random Numbers ROM Zone Finder escrita en ZX BASIC. Es mi primer programa en dicho lenguaje.

Lo escribí por el gusto de empezar a familiarizarme con el compilador ZX Basic, algo que quería hacer desde hacía tiempo.

Pantallazos

No hay ninguna diferencia entre el aspecto de este programa y el de su versión original en Sinclair BASIC, salvo el «Pro» final del nombre.

Pantalla de presentación:

Varios momentos de la búsqueda del mejor rango:

El resultado:

Listado


' Pseudo-Random Number ROM Zone Finder Pro
' Copyright (C) 2010 Marcos Cruz
' http://programandala.net

' License:
' http://programandala.net/license

' Written in ZX Basic (http://zxbasic.net)
' for the Sinclair ZX Spectrum.
' Compile command:
' zxb.py -tBaZ prnrzfp.bas

' 2010-04-09 First version, ported from Sinclair Basic.

' -----------------------
' Constants:

dim first as uinteger = 0 ' first ROM block address to be examined
dim last as uinteger = 16384-255: ' last ROM block address to be examined
dim maxY as ubyte = 192 ' max y graph coord in the ZX Spectrum (under ZX Basic)
dim titlePaper as ubyte = 6 ' yellow
dim blankLine as string 
let blankLine = "                                " ' screen wide blank string

' -----------------------
' Variables:

dim y as integer
dim i as ubyte 
dim n as ubyte 
dim b as uinteger
dim workLine as ubyte
dim count as ubyte
dim maxCount as ubyte
dim bestZone as uinteger
dim a as uinteger

' -----------------------
' Screen

paper 7
ink 0
bright 0
flash 0
inverse 0
over 0
cls 
border titlePaper
print inverse 1;"Pseudo-Random Numbers"
print inverse 1;"ROM Zone Finder Pro"
print "(C) 2010 Marcos Cruz"
print "http://programandala.net"
for i=0 TO 4
	print at i,0; over 1; ink 8; paper titlePaper;blankLine;
next i
let workLine=5
print at workLine,0;

' -----------------------
' About

print "This program searches for a 256-"
print "byte zone in the ZX Spectrum ROM"
print "with the highest number of"
print "different values, in order"
print "to be used as a lookup table in"
print "a pseudo-random number generator"
print "routine in Z80 assembler."
print
print "It was written mainly for fun."
print
print "It's distributed under the terms"
print "of the Programandala License:"
print "http://programandala.net/license"
print
print "Press any key to start."
pause 0

' -----------------------
' Explore

let count=0
let maxCount=0
let bestZone=0
clearExploringScreen()

for a=first TO last
	print at workLine,15;a;"-";a+255
	for b=0 TO 255
		let n=peek (a+b)
		if not(point(n,y)) then 
			plot n,y
			let count=count+1
		end if
	next b
	if count>maxCount then 
		let maxCount=count
		let bestZone=a
		printBestRange()
	end if
	let count=0
	let y=y-1
	if y<0 then 
		clearExploringScreen()
		printBestRange()
	end if
next a

' -----------------------
' Result

clearWorkingSpace()
print "Finished."
print "Best range found: ";bestZone;"-";bestZone+255
print "Different values: ";maxCount
stop 

' -----------------------
' Subroutines

sub clearExploringScreen
	' Clear the exploring screen
	clearWorkingSpace()
	print "Current range:"
	let y=maxY-8*(workLine+2)-2
end sub

sub printBestRange
	' Print the best range so far
	print at workLine+1,0;"Best so far: ";bestZone;"-";bestZone+255;" (";maxCount;")"
end sub

sub clearWorkingSpace
	' Clear the working space
	for i=23 TO workLine step -1
		print at i,0;blankLine;
	next i
	print at workLine,0;
end sub


Descarga

Glosario

BASIC
Beginner's All-Purpose Symbolic Instruction Code (código polivalente de instrucciones simbólicas para principiantes)
ROM
Read Only Memory (memoria inalterable)