Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CHR or CHR$ crashing running Spectrum
#1
Hi,

I do my first steps into ZX Basic and found this crashing
e.g. X128 Spectrum Emulator when I compile this an run it:

FOR A=0 TO 255
PRINT CHR$ (PEEK(A));
NEXT A

Seems printing some CHR$ is like sending some control codes ...
Can work around this when I just use "printable" Characters above e.g. > CHR$ 32 and < CHR$ 127

And just le me say: I love your ZX Basic !
Reply
#2
Yes, it crash the print routine. Thanks, will check for it. :roll:
Also, using basic returns an K Invalid Colour error.
You can use control color codes as with normal PRINT, since it saves memory and can, sometimes, be faster than INK, FLASH, etc.
So color codes can be useful.
Reply
#3
Can I please come back to this and ask if you can have a look at it?

Trying further I discover strangely that running the resulting code on different Spectrum-Emulators (SpecEmu, Fuse)
displays different results on crashing. But this maybe have to do with different Hardware-Addons selected in Emulators.

Which emulator do you use for testing?

Also, PRINT not seems to be very fast. Do you know of a way to maybe speed this up?
E.g. with a PRINT function that prints "without colours or so"?
Update: I will give the printing routine from:
<!-- m --><a class="postlink" href="https://wos.meulie.net/pub/sinclair/books/a/AdvancedSpectrumMachineLanguage.pdf">https://wos.meulie.net/pub/sinclair/boo ... nguage.pdf</a><!-- m -->
a try, if this can speed something further up for me.

On the WIKI <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Print42.bas">http://www.boriel.com/wiki/en/index.php ... rint42.bas</a><!-- m -->
I maybe find a typo: I think the example should read "print42(STRING)" instead of "printat42(STRING)".
There maybe also the same typo on the Print64-Wiki-Page: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Print64.bas">http://www.boriel.com/wiki/en/index.php ... rint64.bas</a><!-- m -->
Reply
#4
The library ( <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library#Text_Handling_Library">http://www.boriel.com/wiki/en/index.php ... ng_Library</a><!-- m --> ) has putchars ( <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Putchars.bas">http://www.boriel.com/wiki/en/index.php ... tchars.bas</a><!-- m --> ), which can drop a single character to the screen as well. It doesn't deal with attributes, which would require a separate function ( like, say <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:WindowPaint">http://www.boriel.com/wiki/en/index.php ... indowPaint</a><!-- m --> ) to do that.

The downside is you have to point it at the data to print on the screen - though there's no reason this can't come from the ROM character table, based on the character set system variable address. You could make a wrapper function that calculates all the numbers and uses puchars at the core.

Or of course write a new fastprint function, perhaps using screen tables ( <!-- l --><a class="postlink-local" href="http://www.boriel.com/forum/how-to-tutorials/topic493.html">how-to-tutorials/topic493.html</a><!-- l --> ) , and add it to the library?

By the way the fastest you are going to get is a method like <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:PutTile">http://www.boriel.com/wiki/en/index.php ... ICTongueutTile</a><!-- m -->
- but this does require a 2 character wide set of data to drop the screen as it uses push and pop to pull 16 bits at a time.
Reply
#5
britlion Wrote:The library ( <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library#Text_Handling_Library">http://www.boriel.com/wiki/en/index.php ... ng_Library</a><!-- m --> ) has putchars ( <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Putchars.bas">http://www.boriel.com/wiki/en/index.php ... tchars.bas</a><!-- m --> ), which can drop a single character to the screen as well. It doesn't deal with attributes, which would require a separate function ( like, say <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:WindowPaint">http://www.boriel.com/wiki/en/index.php ... indowPaint</a><!-- m --> ) to do that.
...
Thanks for your suggestions, I´ll have a try with putchars as my next attempts!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)