Skip to content

Commit

Permalink
Basic: Added initial LOAD/SAVE support
Browse files Browse the repository at this point in the history
  • Loading branch information
visrealm committed Dec 18, 2023
1 parent d283dae commit 79dca01
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 31 deletions.
124 changes: 123 additions & 1 deletion code/6502/basic/basic_hbc56_core.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
lda #>fread
sta VEC_IN + 1

; change output vector
lda #<nullOut
sta VEC_OUT
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
lda #>fwrite
sta VEC_OUT + 1

jsr LAB_14BD ; call list function


lda $7f04 ; close file

; revert output vector
lda #<hbc56Out
sta VEC_OUT
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
lda #>hbc56In
sta VEC_IN + 1

; revert output vector
lda #<hbc56Out
sta VEC_OUT
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)
Expand Down
60 changes: 30 additions & 30 deletions code/6502/basic/makefile
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 79dca01

Please sign in to comment.