davidgiven / cpm65

CP/M for the 6502
BSD 2-Clause "Simplified" License
276 stars 25 forks source link

ATBASIC ERROR in string substrings #163

Open okwatts opened 2 months ago

okwatts commented 2 months ago

If you try and extract a substring using A$(4,5) it appears that it is treated as a numeric and the left Bracket is used as exponentiation. ie if B$="AB" and you print B$(1) you get 5.20200002e+53 Edit: This is on nano6502. This is for printing. If you let A$=B$(1) then print A$ you get the correct result.

ivop commented 1 month ago

I can not reproduce this:

atari000

Could you show the exact steps you took and its output?

okwatts commented 1 month ago

Here is a photo of my screen.

On Thu, Oct 3, 2024, 12:55 p.m. Ivo van Poorten @.***> wrote:

I can not reproduce this:

atari000.png (view on web) https://github.com/user-attachments/assets/f9f058f0-7682-47bc-aa3a-513f4168d86d

Could you show the exact steps you took and its output?

— Reply to this email directly, view it on GitHub https://github.com/davidgiven/cpm65/issues/163#issuecomment-2392216949, or unsubscribe https://github.com/notifications/unsubscribe-auth/APALSOMZP6QRTXAGSRBJFRTZZWOMFAVCNFSM6AAAAABNVWEK2CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJSGIYTMOJUHE . You are receiving this because you authored the thread.Message ID: @.***>

venomix666 commented 1 month ago

I can reproduce it on the BBC Micro (using b-em), see screenshot below, but not on the Atari800 (using the atari800 emulator).

atbasic_error_bbcmicro

venomix666 commented 1 month ago

I can also reproduce it on the Oric, VIC20 and PET (all emulated) - so somehow it seems to only work on the Atari. Strange!

ivop commented 1 month ago

I suppose some Atari dependency is still left in the source code (Altirra was originally written solely for the Atari), hence it working correctly on the Atari but not on other systems.

davidgiven commented 1 month ago

I have vague memories that Atari basic uses hardware to generate random numbers, and that doesn't work on the CP/M-65 port, so it's plausible that there's some other Atari-specific code I've missed. But it's too long ago now and I'd have no idea what it is.

ivop commented 1 month ago

Yes, it reads the Atari Pokey chip's RANDOM register, which is a 17-bit LFSR. I see you replaced that with lda #0 in funRnd :smile:

I could add sfc16 from here. That would add better random numbers than the original on the Atari :wink: A simple 16-bit LFSR could also be done, if adding 180 bytes would be too large. xorshift16 for example.

This printing of a sub-string bug does not seem related though. I have no idea where to search for it.