From 79dca016f2bf5fb9a11da530b308f5862e01884e Mon Sep 17 00:00:00 2001 From: Troy Schrapel Date: Thu, 23 Nov 2023 16:33:53 +1030 Subject: [PATCH] Basic: Added initial LOAD/SAVE support --- code/6502/basic/basic_hbc56_core.asm | 124 ++++++++++++++++++++++++++- code/6502/basic/makefile | 60 ++++++------- 2 files changed, 153 insertions(+), 31 deletions(-) diff --git a/code/6502/basic/basic_hbc56_core.asm b/code/6502/basic/basic_hbc56_core.asm index 02b9654..0ce9921 100644 --- a/code/6502/basic/basic_hbc56_core.asm +++ b/code/6502/basic/basic_hbc56_core.asm @@ -20,6 +20,8 @@ BASIC_XPOS = HBC56_USER_ZP_START + 4 BASIC_YPOS = HBC56_USER_ZP_START + 5 BASIC_COLOR = HBC56_USER_ZP_START + 6 +LOAD_BYTE = HBC56_USER_ZP_START + 7 + ; put the IRQ and NMI code in RAM so that it can be changed IRQ_vec = VEC_SV+2 ; IRQ code vector NMI_vec = IRQ_vec+$0A ; NMI code vector @@ -45,20 +47,140 @@ LAB_stlp jmp LAB_COLD +hbc56OpenFile: + JSR LAB_EVEX ; evaluate string, get length in A (and Y) + lda Dtypef + bne + + ldx #$02 + jmp LAB_XERR ++ + JSR LAB_22B6 ; pop string off descriptor stack, or from top of string + ; space returns with A = length, X=pointer low byte, + ; Y=pointer high byte + stx SAVE_X + sty SAVE_Y + tay + lda #0 + sta (SAVE_X), y + + lda #SAVE_X + sta $7f04 ; open file by name + rts + ; ----------------------------------------------------------------------------- ; hybc56Load - EhBASIC load subroutine (for HBC-56) (TBA) ; ----------------------------------------------------------------------------- hbc56Load + jsr hbc56OpenFile + + ; save stack since NEW destroys it + tsx + inx + lda $100,x + sta SAVE_A + inx + lda $100,x + sta SAVE_Y + + jsr LAB_1463 ; NEW + + ; restore stack + lda SAVE_Y + pha + lda SAVE_A + pha + + lda #3 ;; how many newlines + sta SAVE_A + + ; change input vector + lda #fread + sta VEC_IN + 1 + + ; change output vector + lda #nullOut + sta VEC_OUT + 1 + rts + ; ----------------------------------------------------------------------------- ; hybc56Save - EhBASIC save subroutine (for HBC-56) (TBA) ; ----------------------------------------------------------------------------- hbc56Save + jsr hbc56OpenFile + + ; change output vector + lda #fwrite + sta VEC_OUT + 1 + + jsr LAB_14BD ; call list function + + + lda $7f04 ; close file + + ; revert output vector + lda #hbc56Out + sta VEC_OUT + 1 + + rts + +nullOut: + rts + +fwrite: + cmp #$0a + bne + + lda #$0d + sta $7f05 + lda #$0a ++ + sta $7f05 + rts + +fread: + lda SAVE_A + beq + + dec SAVE_A + lda #$0d + sec + rts ++ + + lda $7f05 ; read byte from file + bne + + + lda $7f04 ; close file + + +tmsConsolePrint "\n Ready\n" + + ; revert input vector + lda #hbc56In + sta VEC_IN + 1 + + ; revert output vector + lda #hbc56Out + sta VEC_OUT + 1 + + lda #$0d ++ + sec rts ; ----------------------------------------------------------------------------- -; vector table - gets copied to VEC_IN in RAM +; vector table - gets copied to VEC_CC in RAM ; ----------------------------------------------------------------------------- LAB_vec !word hbc56In ; check for break (Ctrl+C) diff --git a/code/6502/basic/makefile b/code/6502/basic/makefile index 40f0bca..58e27bb 100644 --- a/code/6502/basic/makefile +++ b/code/6502/basic/makefile @@ -1,30 +1,30 @@ -# Troy's HBC-56 - BASIC makefile -# -# Copyright (c) 2021 Troy Schrapel -# -# This code is licensed under the MIT license -# -# https://github.com/visrealm/hbc-56 -# -# - -ROOT_PATH=../ - -default: basic_tms - -#basic_lcd.o: DISABLE_KERNEL_MODULES = TMS9918 -basic_tms.o: DISABLE_KERNEL_MODULES = LCD -basic_uart.o: DISABLE_KERNEL_MODULES = LCD - -include $(ROOT_PATH)makefile - -%: %.o - copy /Y $<* ..\..\..\emulator\wasm\roms - $(HBC56EMU) --rom $< - -%lcd: %lcd.o - copy /Y $<* ..\..\..\emulator\wasm\roms - $(HBC56EMU) --lcd $(LCD_MODEL) --rom $< - -clean: - $(RM) *.o *.lmap +# Troy's HBC-56 - BASIC makefile +# +# Copyright (c) 2021 Troy Schrapel +# +# This code is licensed under the MIT license +# +# https://github.com/visrealm/hbc-56 +# +# + +ROOT_PATH=../ + +default: basic_tms + +#basic_lcd.o: DISABLE_KERNEL_MODULES = TMS9918 +basic_tms.o: DISABLE_KERNEL_MODULES = LCD +basic_uart.o: DISABLE_KERNEL_MODULES = LCD + +include $(ROOT_PATH)makefile + +%: %.o +#copy /Y $<* ..\..\..\emulator\wasm\roms + $(HBC56EMU) --rom $< + +%lcd: %lcd.o +#copy /Y $<* ..\..\..\emulator\wasm\roms + $(HBC56EMU) --lcd $(LCD_MODEL) --rom $< + +clean: + $(RM) *.o *.lmap