-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathbasic_hbc56_core.asm
202 lines (161 loc) · 4.57 KB
/
basic_hbc56_core.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
; Troy's HBC-56 - BASIC
;
; Copyright (c) 2021 Troy Schrapel
;
; This code is licensed under the MIT license
;
; https://github.com/visrealm/hbc-56
;
!src "hbc56kernel.inc"
!src "ehbasic/basic.asm" ; EhBASIC
; For saving registers
SAVE_X = HBC56_USER_ZP_START
SAVE_Y = HBC56_USER_ZP_START + 1
SAVE_A = HBC56_USER_ZP_START + 2
BASIC_XPOS = HBC56_USER_ZP_START + 4
BASIC_YPOS = HBC56_USER_ZP_START + 5
BASIC_COLOR = HBC56_USER_ZP_START + 6
BASIC_MODE = HBC56_USER_ZP_START + 7
LOAD_BYTE = HBC56_USER_ZP_START + 8
; 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
FG = TMS_DK_BLUE
BG = TMS_WHITE
BORDER = TMS_DK_BLUE
; -----------------------------------------------------------------------------
; main entry point
; -----------------------------------------------------------------------------
hbc56Main:
RES_vec:
!ifdef HAVE_TMS9918 {
+tmsColorFgBg FG, BG
sta BASIC_COLOR
}
lda #1
sta BASIC_MODE
jsr hbc56SetupDisplay
; copy I/O vectors
ldy #END_CODE - LAB_vec - 1 ; set index/count
LAB_stlp
lda LAB_vec, Y ; get byte from interrupt code
sta VEC_CC, Y ; save to RAM
dey
bpl LAB_stlp
cli ; enable interrupts
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_CC in RAM
; -----------------------------------------------------------------------------
LAB_vec
!word hbc56In ; check for break (Ctrl+C)
!word hbc56In ; byte in from keyboard
!word hbc56Out ; byte out to screen
!word hbc56Load ; load vector for EhBASIC
!word hbc56Save ; save vector for EhBASIC
END_CODE ; so we know when to stop copying