From 09cd066256cd607235e8441990ed2b135de3a895 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Mon, 18 Jan 2021 22:06:22 +0100 Subject: [PATCH] started work on monitor GO/JSR commands --- src/kernal/board_m65/mega65_proxies_monitor.s | 16 ++++ src/mon_m65/bsmon.s | 19 +--- src/mon_m65/imports.s | 2 + src/mon_m65/mon_command_fill.s | 2 - src/mon_m65/mon_command_jmp_jsr.s | 93 +++++++++++++++++++ 5 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 src/mon_m65/mon_command_jmp_jsr.s diff --git a/src/kernal/board_m65/mega65_proxies_monitor.s b/src/kernal/board_m65/mega65_proxies_monitor.s index f16f829c..0a2f9f95 100644 --- a/src/kernal/board_m65/mega65_proxies_monitor.s +++ b/src/kernal/board_m65/mega65_proxies_monitor.s @@ -19,6 +19,7 @@ proxy_M1_CHROUT: ; FALLTROUGH +proxy_M1_jmpout_ret: ; reused by monitor proxy_M1_end: jmp map_MON_1 @@ -40,3 +41,18 @@ proxy_M1_memwrite: jsr map_NORMAL sta [Long__TMP], z bra proxy_M1_end + + +; JMP/JSR to user code + +proxy_M1_jmpout: + + plz ; ZR + ply ; YR + plx ; XR + pla ; BP + tab + pla ; AC + plp ; SR + + jmp map_NORMAL diff --git a/src/mon_m65/bsmon.s b/src/mon_m65/bsmon.s index cfeb070b..966e74c8 100644 --- a/src/mon_m65/bsmon.s +++ b/src/mon_m65/bsmon.s @@ -197,9 +197,9 @@ Jump_Table: !word Mon_Compare ; C !word Mon_Disassemble ; D !word Mon_Fill ; F - !word Mon_Go ; G XXX to be debugged/adapted + !word Mon_Go ; G XXX to be finished/bugfixed !word Mon_Hunt ; H - !word Mon_JSR ; J XXX to be debugged/adapted + !word Mon_JSR ; J XXX to be finished/bugfixed !word Mon_Memory ; M !word Mon_Register ; R !word Mon_Transfer ; T @@ -400,21 +400,6 @@ Print_Bits: PLZ RTS - -; ***** -Mon_Go: -; ***** - - ; XXX to be rewritten for Open ROMs! - jmp Main - -; ****** -Mon_JSR: -; ****** - - ; XXX to be rewritten for Open ROMs! - jmp Main - ; *********** Dump_4_Bytes: ; *********** diff --git a/src/mon_m65/imports.s b/src/mon_m65/imports.s index 07ea79b5..a981faf6 100644 --- a/src/mon_m65/imports.s +++ b/src/mon_m65/imports.s @@ -12,6 +12,8 @@ ;; #ALIAS# monitor_exit = KERNAL_0.m65_shadow_BZP ;; #ALIAS# monitor_memread_helper = KERNAL_0.proxy_M1_memread ;; #ALIAS# monitor_memwrite_helper = KERNAL_0.proxy_M1_memwrite +;; #ALIAS# monitor_jmpout = KERNAL_0.proxy_M1_jmpout +;; #ALIAS# monitor_jmpout_ret = KERNAL_0.proxy_M1_jmpout_ret ;; #ALIAS# CHRIN = KERNAL_0.proxy_M1_CHRIN ;; #ALIAS# CHROUT = KERNAL_0.proxy_M1_CHROUT diff --git a/src/mon_m65/mon_command_fill.s b/src/mon_m65/mon_command_fill.s index a872097a..75db2c4f 100644 --- a/src/mon_m65/mon_command_fill.s +++ b/src/mon_m65/mon_command_fill.s @@ -2,9 +2,7 @@ ; Based on BSM (Bit Shifter's Monitor) -; ******* Mon_Fill: -; ******* jsr Get_Param_Range ; Long_PC = target +bcs Mon_Error ; Long_CT = count diff --git a/src/mon_m65/mon_command_jmp_jsr.s b/src/mon_m65/mon_command_jmp_jsr.s new file mode 100644 index 00000000..573dca3a --- /dev/null +++ b/src/mon_m65/mon_command_jmp_jsr.s @@ -0,0 +1,93 @@ + +; Based on BSM (Bit Shifter's Monitor) + + +Mon_JSR: + + + lda #$00 + sta Addr_Mode + + jsr Get_Val_To_LAC ; Long_AC = jump address + +beq Mon_Error + + ; Push return addresses + + lda #>(Mon_JSR_ret-1) ; XXX return routine should JSR, to store address + pha + lda #<(Mon_JSR_ret-1) + pha + + lda #>(monitor_jmpout_ret-1) + pha + lda #<(monitor_jmpout_ret-1) + pha + + bra Mon_Go_JSR_comon + +Mon_Go: + + lda #$00 + sta Addr_Mode + + jsr Get_Val_To_LAC ; Long_AC = jump address + +bne Mon_Go_JSR_comon + + lda PCL ; use PC as jump address + sta Long_AC+0 + lda PCH + sta Long_AC+0 + + ; FALLTROUGH + +Mon_Go_JSR_comon: + + lda Addr_Mode ; only first 64KB is supported as target + +bne Mon_Error + + lda PCH ; push target address for RTS + sta Long_TMP+1 + lda PCL + sta Long_TMP+0 + dew Long_TMP+0 + + lda Long_TMP+1 + pha + lda Long_TMP+0 + pha + + ; Prepare registers + + lda SR + pha + lda AC + pha + lda BP + pha + lda XR + pha + lda YR + pha + lda ZR + pha + + jmp monitor_jmpout + +Mon_JSR_ret: + + ; Retrieve registers + ; XXX address! + + pha + php + pla + sta SR + pla + sta AC + tba + sta BP + stx XR + sty YR + stz ZR + + jmp Mon_Register