Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRG send causes BS Monitor's X command to fail #129

Closed
dansanderson opened this issue Jul 29, 2022 · 6 comments
Closed

PRG send causes BS Monitor's X command to fail #129

dansanderson opened this issue Jul 29, 2022 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@dansanderson
Copy link
Collaborator

Test Environment (required)

  • Tools Platform: MacOS
  • Tools Version: 20220519.21-HEAD_n-d9a2452
  • MEGA65 Platform: MEGA65
  • ROM Release: 920376
  • Core Commit: f555316

Describe the bug
Something about the way m65 sends PRG files confuses BS Monitor's X command. The X command is supposed to exit to BASIC, but if the program was sent via m65/M65Connect, X actually goes somewhere else then re-breaks back into the monitor with PC 002005 (which is a weird PC because that's in BASIC memory).

To Reproduce

  1. Transfer any PRG from a PC to the MEGA65. Don't run it or switch modes. m65 -l /dev/cu... somefile.prg
  2. On the MEGA65 at the READY. prompt, type MONITOR. BS Monitor opens.
  3. Type X, hit Return.

Expected behavior
The X command is supposed to exit the monitor and return to BASIC. It works if no program is loaded, or if a program is loaded from disk/SD card. It doesn't matter if the monitor was invoked by the MONITOR command or a brk instruction from the program.

Instead, the monitor attempts to exit, but then re-breaks with the PC at 002005. This appears to be true only if the PRG was transferred by m65/M65Connect. The content of the program does not appear to matter, and you don't have to run the program to reproduce the issue.

Additional context
Here's the beginning of monexit, which is where X goes:

cd9b          monexit
cd9b 20 80 03  jsr restore_system ;Restore system configuration
cd9e ad 05 11  lda save_status  ;Restore BASIC's init status
cda1 8d 04 11  sta init_status
cda4 ea        nop  
cda5 6c 00 11  jmp (system_vector) ;Return to system

(Issue relocated from MEGA65/m65connect#11.)

@dansanderson
Copy link
Collaborator Author

mega65-screen-000000

@dansanderson
Copy link
Collaborator Author

Trying with the refactor-ftp branch, 20220729.00-refact-00e36ae. Can still repro.

% ./bin/m65.osx --debug -l /dev/cu.usbserial-251633006E0EA ~/websites/site-dansanderson.com/content/lab-notes/2022/07/26/mega65-monitor/golml.prg
2022-07-29T07:36:06.785Z DEBG parameter parsing done
2022-07-29T07:36:06.786Z NOTE MEGA65 Cross-Development Tool 20220729.00-refact-00e36ae
2022-07-29T07:36:06.786Z INFO opening serial port /dev/cu.usbserial-251633006E0EA
2022-07-29T07:36:06.788Z DEBG set_serial_speed: 2000000 bps (OSX)
2022-07-29T07:36:06.935Z INFO checking if MEGA65 has RX buffer
2022-07-29T07:36:06.959Z INFO RX buffer detected. Latency will be reduced.
2022-07-29T07:36:06.979Z INFO detecting C64/C65 mode status
2022-07-29T07:36:07.075Z DEBG in C65 mode
2022-07-29T07:36:07.075Z NOTE loading file '/Users/dan/websites/site-dansanderson.com/content/lab-notes/2022/07/26/mega65-monitor/golml.prg'
2022-07-29T07:36:07.091Z INFO LOAD vector from ROM is $f4c4
2022-07-29T07:36:07.139Z DEBG Injecting string into key buffer at $02B0 : DLo"![$0d]
2022-07-29T07:36:07.139Z INFO waiting for breakpoint at $F4C4 to trigger
2022-07-29T07:36:07.155Z INFO breakpoint @ $F4C4 triggered
2022-07-29T07:36:07.235Z INFO requested file is '0:!' (len=3)
2022-07-29T07:36:07.235Z INFO forcing load address to $2001
2022-07-29T07:36:07.235Z DEBG read block for $2001 -- $2290 (656 bytes)
2022-07-29T07:36:07.363Z INFO storing end of program pointer at $82
2022-07-29T07:36:07.363Z INFO returning top of load address = $2291
2022-07-29T07:36:07.411Z NOTE loaded

@dansanderson
Copy link
Collaborator Author

It appears some bytes at $000380 are getting corrupted by the transfer, specifically:

 . 0380  A2 91    LDX  #$91
 . 0382  A0 22    LDY  #$22
 . 0384  18       CLC
 . 0385  60       RTS

These locations need to be preserved for a clean exit from the monitor. Original code before it is overwritten:

 . 0380  AD 10 01 LDA  $0110
 . 0383  AE 11 01 LDX  $0111

@lydon42
Copy link
Member

lydon42 commented Jul 30, 2022

should be fixed in refactor-m65

@lydon42 lydon42 added bug Something isn't working and removed new New report, not classified yet labels Jul 30, 2022
@lydon42 lydon42 self-assigned this Jul 30, 2022
@lydon42 lydon42 added this to the MEGA65 Release 0.95 (Batch 2) milestone Jul 30, 2022
dansanderson added a commit to dansanderson/mega65-tools that referenced this issue Jul 30, 2022
fix: remove DLOAD/breakpoint stuff from prg loading MEGA65#128 MEGA65#129
lydon42 added a commit that referenced this issue Jul 30, 2022
commit d35e7d8
Merge: 019960f 7346959
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 11:16:05 2022 -0700

    Merge pull request #2 from MEGA65/refactor-m65

    fix: remove DLOAD/breakpoint stuff from prg loading #128 #129

commit 7346959
Author: Oliver Graf <ograf@devilsclaw.de>
Date:   Sat Jul 30 20:07:20 2022 +0200

    fix: remove duplicate progress_to_RTI #128

    it's in m65common.c after all!

commit 99caf1a
Author: Oliver Graf <ograf@devilsclaw.de>
Date:   Sat Jul 30 20:02:30 2022 +0200

    fix: removing bunch off flushes and RTI used by screenshot #128

    fflush(stderr) is normally unneeded as stderr is unbuffered.
    progress_to_RTI is only used by screen_shot.c, so put it there.

commit 7cec280
Merge: c913689 24d2cf3
Author: Oliver Graf <ograf@devilsclaw.de>
Date:   Sat Jul 30 19:57:28 2022 +0200

    Merge branch 'dansanderson-refactor-m65' into refactor-m65

commit 24d2cf3
Merge: c913689 019960f
Author: Oliver Graf <ograf@devilsclaw.de>
Date:   Sat Jul 30 19:57:01 2022 +0200

    Merge branch 'refactor-m65' of github.com:dansanderson/mega65-tools into dansanderson-refactor-m65

commit c913689
Author: Oliver Graf <ograf@devilsclaw.de>
Date:   Sat Jul 30 19:37:22 2022 +0200

    fix: remove DLOAD/breakpoint stuff from prg loading #128 #129

commit 019960f
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:29:42 2022 -0700

    Add print_screencode public declaration; remove unused screen_shot externs; fix screen_shot.c screencode table formatting

commit c3e8df0
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:17:46 2022 -0700

    Restore init_cmd_options() special formatting (from merge)

commit a4abcc7
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:14:15 2022 -0700

    Re-removing lines from gitignore (from merge)

commit 3112a07
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:09:53 2022 -0700

    Restoring lost line from Makefile

commit 825375f
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:08:19 2022 -0700

    Removing .vscode

commit 92b2b52
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:07:15 2022 -0700

    Hide .vscode from git

commit 1811c6c
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 10:05:08 2022 -0700

    make format

commit be81c19
Merge: 8aa927b c96121b
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 09:56:20 2022 -0700

    Merge branch 'MEGA65-refactor-m65' into refactor-m65

commit c96121b
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 00:43:10 2022 +0000

    Most of m65dbg, with stubs for serial calls

commit fb8b17d
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Fri Jul 29 23:32:09 2022 +0000

    Moved progress_to_RTI to m65common; relocated shared storage from m65 to screen_shot; moved m65dbg.c to a subdir; make format of changed files only

commit 3f568a4
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Fri Jul 29 22:58:51 2022 +0000

    Starter for m65dbg; Makefile, README, gitignore clean-up

commit 8aa927b
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Sat Jul 30 00:43:10 2022 +0000

    Most of m65dbg, with stubs for serial calls

commit b6aacd8
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Fri Jul 29 23:32:09 2022 +0000

    Moved progress_to_RTI to m65common; relocated shared storage from m65 to screen_shot; moved m65dbg.c to a subdir; make format of changed files only

commit 23a3969
Author: Dan Sanderson <contact@dansanderson.com>
Date:   Fri Jul 29 22:58:51 2022 +0000

    Starter for m65dbg; Makefile, README, gitignore clean-up
@lydon42 lydon42 added the fix test Issue is fixed, confirmation required label Aug 1, 2022
@lydon42
Copy link
Member

lydon42 commented Aug 1, 2022

also fixed in merge2-m65dbg

@dansanderson
Copy link
Collaborator Author

The latest in merge2-m65dbg resolves this issue. Per @lydon42 I'll close this ticket. Thanks very much!

@lydon42 lydon42 removed the fix test Issue is fixed, confirmation required label Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants