Skip to content

Commit 80ad42d

Browse files
Implement DPEEK/DPOKE
1 parent 65fed54 commit 80ad42d

8 files changed

Lines changed: 86 additions & 7 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ basic_vc83_serial: basic_vc83_serial.o
7878
$(PRINT_SIZE)
7979

8080
basic_vc83_serial.mem: basic_vc83_serial
81-
srec_cat $< -Binary -offset 0x0400 -Output $@ -VMem 8
81+
if command -v srec_cat >/dev/null; then srec_cat $< -Binary -offset 0x0400 -Output $@ -VMem 8; else echo "srec_cat not installed"; touch $@; fi
8282

8383
# Rule for version.inc
8484
version.inc: FORCE

constants.m4

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ def(ST_DATA, 20)
4242
def(ST_READ, 21)
4343
def(ST_RESTORE, 22)
4444
def(ST_POKE, 23)
45-
def(ST_END, 24)
46-
def(ST_INPUT, 25)
47-
def(ST_IF_THEN, 26)
45+
def(ST_DPOKE, 24)
46+
def(ST_END, 25)
47+
def(ST_INPUT, 26)
48+
def(ST_IF_THEN, 27)
49+
4850

4951
comment Binary operator tokens: combine with TOKEN_OP
5052

expect_tests/list.exp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ spawn_basic
1010
# Formatting of expressions in LIST
1111

1212
test {
13-
NEW
1413
100 PRINT 1
1514
101 PRINT X
1615
102 PRINT X+1
@@ -53,10 +52,17 @@ LIST
5352
118 PRINT "HELLO" AND "WORLD"
5453
}
5554

55+
test {
56+
NEW
57+
} {
58+
READY
59+
}
60+
5661
# DATA and REM retain all characters
5762

5863
test {
5964
10 DATA 1,2,3
65+
6066
20 DATA TEXT WITHOUT QUOTES, "TEXT WITH QUOTES", 3.14159, !@#
6167
LIST
6268
} {

expect_tests/peek_poke.exp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,51 @@ PRINT PEEK(ADDR, 1)
4040
} {
4141
ERR: ARITY?
4242
}
43+
44+
# DPEEK and DPOKE
45+
46+
test {
47+
NEW
48+
} {
49+
READY
50+
}
51+
52+
test {
53+
10 LET A$="HELLO"
54+
20 LET ADDR=ADR(A$)
55+
30 PRINT DPEEK(ADDR)
56+
40 DPOKE ADDR,18761
57+
50 PRINT A$
58+
RUN
59+
} {
60+
17736
61+
IILLO
62+
63+
READY
64+
}
65+
66+
test {
67+
PRINT DPEEK()
68+
} {
69+
ERR: SYNTAX
70+
}
71+
72+
test {
73+
PRINT DPEEK(ADDR, 1)
74+
} {
75+
ERR: ARITY?
76+
}
77+
78+
test {
79+
DPOKE ADDR
80+
} {
81+
ERR: SYNTAX
82+
}
83+
84+
test {
85+
DPOKE ADDR, 1, 2
86+
} {
87+
ERR: SYNTAX
88+
}
89+
90+

functions.s

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ function_table:
2525
.byte 1 | PROLOG_POP_FP | EPILOG_PUSH_INT
2626
.word fun_peek-1
2727
.byte 1 | PROLOG_POP_INT | EPILOG_PUSH_INT
28+
.word fun_dpeek-1
29+
.byte 1 | PROLOG_POP_INT | EPILOG_PUSH_INT
2830
.word fun_adr-1
2931
.byte 1 | PROLOG_POP_STRING | EPILOG_PUSH_INT
3032
.word fun_usr-1
@@ -172,6 +174,15 @@ fun_len:
172174
ldx #0 ; Zero-extend to 16 bits; for len we receive the string length in A
173175
rts
174176

177+
fun_dpeek:
178+
jsr fun_peek ; Leaves pointer in BC and Y=0
179+
pha
180+
iny
181+
lda (BC),y ; Get high byte
182+
tax
183+
pla
184+
rts
185+
175186
.bss
176187

177188
rnd_value: .res .sizeof(Float::t)

parser.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,8 @@ statement_name_table:
864864
JUMP pvm_opt_number
865865
: name_table_entry "POKE"
866866
JUMP pvm_arg_2
867+
: name_table_entry "DPOKE"
868+
JUMP pvm_arg_2
867869
: name_table_entry "END"
868870
: name_table_entry "INPUT"
869871
TRY @vars
@@ -949,6 +951,7 @@ function_name_table:
949951
: name_table_entry "VAL"
950952
: name_table_entry "FRE"
951953
: name_table_entry "PEEK"
954+
: name_table_entry "DPEEK"
952955
: name_table_entry "ADR"
953956
: name_table_entry "USR"
954957
: name_table_entry "INT"

poke.s

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@
77
exec_poke:
88
jsr evaluate_argument_list
99
jsr pop_int_fp0 ; Pop the value
10-
pha ; Push the low byte; high byte doesn't matter
10+
stax DE ; Save
1111
jsr pop_int_fp0 ; Pop the address
1212
stax BC ; Park it
1313
ldy #0 ; Prepare to store
14-
pla ; Recover the value
14+
lda D
1515
sta (BC),y ; Store it
1616
rts
17+
18+
exec_dpoke:
19+
jsr exec_poke ; Leaves high byte in E and Y=0
20+
iny
21+
lda E
22+
sta (BC),y ; Store it
23+
rts
24+

statements.s

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ statement_vectors:
4444
.word exec_read-1
4545
.word exec_restore-1
4646
.word exec_poke-1
47+
.word exec_dpoke-1
4748
.word exec_end-1
4849
.word exec_input-1
4950
.word exec_if-1

0 commit comments

Comments
 (0)