From a974b4a763bb5805946a62fe7bbb321b7c98e01a Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 3 Sep 2020 20:28:38 +0200 Subject: [PATCH] added way to detect MEGA65 from the BASIC --- doc/Extended-BASIC.md | 4 ++ src/basic/basic_commands/cmd_if.s | 11 ++++ .../basic_commands/helper_if_mega65_38K.s | 52 ++++++++++++++++++ .../basic_commands/helper_if_mega65_46K_50K.s | 54 +++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 src/basic/basic_commands/helper_if_mega65_38K.s create mode 100644 src/basic/basic_commands/helper_if_mega65_46K_50K.s diff --git a/doc/Extended-BASIC.md b/doc/Extended-BASIC.md index 44c31c97..3de5a66d 100644 --- a/doc/Extended-BASIC.md +++ b/doc/Extended-BASIC.md @@ -103,3 +103,7 @@ Same as `SYS`, but does not switch to C64 compatibility mode. ### `GO 64`, `GO 65` (MEGA65) Switches machine to C64 compatibility mode or to MEGA65 native mode. Performs `CLR` + +### `IF MEGA65 THEN`, `IF MEGA65 GOTO` (MEGA65) + +Special check for running under MEGA65. The `MEGA65` string is not tokenized, therefore it will be listed properly even under original BASIC V2. `MEGA65` is not a variable here - it is still possible to normally use the `ME` variable. diff --git a/src/basic/basic_commands/cmd_if.s b/src/basic/basic_commands/cmd_if.s index 1c52ad63..7e3a4488 100644 --- a/src/basic/basic_commands/cmd_if.s +++ b/src/basic/basic_commands/cmd_if.s @@ -5,6 +5,13 @@ cmd_if: +#if ROM_LAYOUT_M65 + + jsr helper_if_mega65 + bcc cmd_if_true + +#endif + // Calculate expression jsr FRMEVL @@ -14,6 +21,10 @@ cmd_if: lda FAC1_exponent beq_16 cmd_rem + // FALLTROUGH + +cmd_if_true: + // Condition fulfilled - look for GOTO or THEN jsr fetch_character_skip_spaces diff --git a/src/basic/basic_commands/helper_if_mega65_38K.s b/src/basic/basic_commands/helper_if_mega65_38K.s new file mode 100644 index 00000000..fd93f63e --- /dev/null +++ b/src/basic/basic_commands/helper_if_mega65_38K.s @@ -0,0 +1,52 @@ +// #LAYOUT# M65 BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +#if CONFIG_MEMORY_MODEL_38K + +helper_if_mega65: + + // Injest all spaces + + ldy #$00 +!: + lda (TXTPTR), Y + cmp #$20 + bne !+ + inw TXTPTR + bra !- +!: + + // Check for MEGA65 untokenized keyword + + ldy #$05 +!: + lda (TXTPTR), Y + cmp str_mega65, Y + bne_16 helper_if_mega65_fail + dey + bpl !- + + // Increment TXTPTR by 6 + + clc + lda TXTPTR+0 + adc #$06 + sta TXTPTR+0 + bcc !+ + inc TXTPTR+1 +!: + // Report successful check + + clc + rts + +helper_if_mega65_fail: + + sec + rts + +str_mega65: + + .byte $4D, $45, $47, $41, $36, $35 + +#endif diff --git a/src/basic/basic_commands/helper_if_mega65_46K_50K.s b/src/basic/basic_commands/helper_if_mega65_46K_50K.s new file mode 100644 index 00000000..24b76024 --- /dev/null +++ b/src/basic/basic_commands/helper_if_mega65_46K_50K.s @@ -0,0 +1,54 @@ +// #LAYOUT# M65 BASIC_0 #TAKE-HIGH +// #LAYOUT# * * #IGNORE + +// This has to go $E000 or above - routine below banks out the main BASIC ROM! + +#if CONFIG_MEMORY_MODEL_46K || CONFIG_MEMORY_MODEL_50K + +helper_if_mega65: + + // Unmap BASIC lower ROM + + lda #$26 + sta CPU_R6510 + + // Injest all spaces + + ldy #$00 +!: + lda (TXTPTR), Y + cmp #$20 + bne !+ + inw TXTPTR + bra !- +!: + + // Check for MEGA65 untokenized keyword + + ldy #$05 +!: + lda (TXTPTR), Y + cmp str_mega65, Y + bne_16 remap_BASIC_sec_rts + dey + bpl !- + + // Increment TXTPTR by 6 + + clc + lda TXTPTR+0 + adc #$06 + sta TXTPTR+0 + bcc !+ + inc TXTPTR+1 +!: + // Report successful check + + jmp remap_BASIC_clc_rts + +str_mega65: + + .byte $4D, $45, $47, $41, $36, $35 + + +#endif