Hi, I'm posting my solution here to archive it.
It was tested on MSX1, MSX2+ and MSX Turbo R.
; ====== Run MSX-BASIC CLEAR from BLOAD,R to auto protect the assembly program on High Memory ========= ; =================================================================================================== ; By Carlos Olivi (Jun/2019) ; Problem: When you directly call MSX-BASIC 'CLEAR' Handler in assembly, it don't back to assembly program. ; Method: Create a special Return for CLEAR Handle (here called BAS.CLEAR) intercepting RUNLOOP by HNEWS hook. ; Target: Program for a BLOAD ,R execution. pop hl ; [6CF3H] Skip the return point of BLOAD,R handler pop hl ; [8XXXH] Get the current MSX-BASIC program pointer exx ; Save the program pointer on HL'. (*You also could save it in memory) ld a,0c3h ; [JP] ld (HNEWS+0),a ; (4601H) Hook of Runloop New Statement in MSX-BASIC ld hl,retFromCLEAR ; [FF3EH] ld (HNEWS+1),hl ; Force to return here on the Runloop called immediately after CLEAR handler ; Change HIMEM directly and run CLEAR with "200" because CLEAR X automatically update all vars. according HIMEM ld hl,0D000H ; Set new Address for HIMEM here <============================================== ld (HIMEM),hl ; Set HIMEM directly to avoid the need to string conversion to CLEAR statement ld hl,STCLEAR ; CLEAR statement string add a,h ; Set NZ flag to inform that CLEAR has arguments call BAS.CLEAR ; (64AFH) BASIC CLEAR Handler. (Maybe also: LD IX,BAS.CLEAR | CALL CALBAS) retFromCLEAR ld a,0c9h ; [RET] ld (HNEWS),a ; Clear HNEWS (*can be improved, restoring previous values from previous app.) pop hl ; INC SP*2 to fix SP exactly like a standart CLEAR call (*it seems unnecessary) exx ; Restore BASIC program pointer from HL' to HL jp BAS.RUNLOOP ; (4601H) Runloop New Statement. Back to BASIC and proceed to next statement. STCLEAR db "200",0 ; CLEAR command line "CLEAR200" (Note: 200 is the default inital value for CLEAR)
Login or register to post comments