neilsf / xc-basic3

A BASIC cross compiler for MOS 6502-based machines
MIT License
42 stars 5 forks source link

v3.2.0 on Mega65 fails with memory setup #228

Closed BruderJo closed 1 year ago

BruderJo commented 1 year ago

Hi I tested the compiler with a simple print "Hello World"

the program generates unreadable random nonsens on screen. Nevertheless, I could read the string at it's $BFxx location with the monitor program. The library code of STRMOV and PrintStr works as expected.

After changing the library file "stack.asm" the result was fine and the hello program sent greetings. I reduced the STACKFRAME_TOP from $BF00 to $7F00. It seems there is a difference between reading & writing bytes to locations above $8000 (upper 32K)

My environment is: Mega665 emulator with Xemu 20220426121838-master, Mega65 rom version is 920377; desktop is a Mac (MacOS 10.15.7)

neilsf commented 1 year ago

I have no issues with the original memory setup. I'm using a newer version of the emulator: Xemu: 20230201214849 official-build ROM version: 920377 Can you upgrade xemu and try again?

BruderJo commented 1 year ago

I updated Xemu, but the result is the same. Even on a windows laptop. Printstring reads from $BFF3 in bank 2.

a simple test

D 1600 1612
. 1600  A9 0C    LDA  #$0C
. 1602  8D F0 BF STA  $BFF0
. 1605  8D F0 7F STA  $7FF0
. 1608  8D F1 BF STA  $BFF1
. 160B  AD F1 BF LDA  $BFF1
. 160E  8D F1 7F STA  $7FF1
. 1611  60       RTS
. 1612  00       BRK
M BFF0 BFFF
>BFF0 0C 0C 00 0C C8 45 4C 4C 4F 20 D7 4F 52 4C 44 2E
M 7FF0 7FFF
>7FF0 0C 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00

expected: $7FF1 = 0c

This means: memory access is somehow broken. Nothing wrong with your compiler

neilsf commented 1 year ago

Interesting. The exact same code works for me as expected.

BruderJo commented 1 year ago

I asked in a forum to bring some light in this mapping issue. forum64.de

it is related to the default mappings and the simple solution is to disable the C64 ROM (funny, but it works) I included a POKE 1,53 into the startup code and the "hello" program worked as expected. This issue is solved now.

As the forum is in german language: if you need some english translation, just ask.

bash-3.2$ diff -c sys.asm_orig sys.asm 
*** sys.asm_orig        Sat Jun  3 23:41:10 2023
--- sys.asm     Sat Jun 10 18:17:37 2023
***************
*** 39,44 ****
--- 39,47 ----
                sta $01
        ENDIF
      IF TARGET == mega65
+       lda #53
+       sta $01
+ 
          IF USESPR
            jsr sprinit_m65
          ENDIF
***************
*** 232,235 ****
        eor .TRIG
        and .MASK
        beq .loop
!       ENDM
\ No newline at end of file
--- 235,238 ----
        eor .TRIG
        and .MASK
        beq .loop
!       ENDM
dansanderson commented 1 year ago

FYI: We're considering changing the MEGA65 boot state to make this the default. It's a backwards incompatible change so would need to be tested carefully, and setting it explicitly from the program would make it work with previous ROMs. https://github.com/MEGA65/mega65-rom-public/issues/61