Page 2 of 3
Re: include pokew and peekw in basic?
Posted: Thu Apr 11, 2024 5:27 pm
by mortarm
Can't say I'm familiar with POKEW/PEEKW. Google wasn't much help either <GASP!>
Re: include pokew and peekw in basic?
Posted: Thu Apr 11, 2024 5:37 pm
by ahenry3068
mortarm wrote: ↑Thu Apr 11, 2024 5:27 pm
Can't say I'm familiar with POKEW/PEEKW. Google wasn't much help either <GASP!>
Just a commonly accepted term for BASIC programmers meaning PEEK Word & POKE Word.
(a 16 bit value)
The normal POKE and PEEK statements operate on 8 bit values. (bytes)
Re: include pokew and peekw in basic?
Posted: Thu Apr 11, 2024 7:32 pm
by funkheld
Aren't integers W% in basic slow because they are converted back to float before use?
greeting
Re: include pokew and peekw in basic?
Posted: Thu Apr 11, 2024 8:45 pm
by ahenry3068
funkheld wrote: ↑Thu Apr 11, 2024 7:32 pm
Aren't integers W% in basic slow because they are converted back to float before use?
greeting
Yes for Math functions but not super slower. There are tradeoffs in all code.
I often use Integers for larger Arrays because they take up much less Memory.
In this case the PeekW & PokeW functions work more quickly because no Basic Math is being done here, Only Pointers, Peeks & Pokes.
Re: include pokew and peekw in basic?
Posted: Thu Apr 11, 2024 8:51 pm
by ahenry3068
You may find this useful too. Peek.String returns a "Pascal" type string. So in this context it only works for retrieving a string
Poked by Poke.String. I'm using this to work with Strings stored in Banked Ram so I don't have to work the BASIC string Heap.
I'm keeping track of the Pointers in an Integer Array. Pokes String in S$ to SAddr. Peek.String returns string previously Poked at SAddr in S$. MEM.COPY is the System ROM routine memory_copy ($FEE7)
DEF FN SW(W)=W + 65536 * (W > 32767)
POKE.STRING:
L=LEN(S$)
Addr=SAddr+1
POKE SAddr, L
POKE R1L, FN SW(ADDR) AND $00FF
POKE R1H, INT(ADDR/256)
P=POINTER(S$)
POKE R0L, PEEK(P+1)
POKE R0H, PEEK(P+2)
POKE R2L, L
POKE R2H, 0
SYS MEM.COPY
RETURN
PEEK.STRING:
L=PEEK(SAddr)
REM Here I'm using BASIC String Code to make sure I have
REM exactly enough room for the MEM.COPY. By making S$
REM a string of Spaces the right size.
S$=RPT$(32,L)
ADDR=SAddr+1
POKE R0L, FN SW(ADDR) AND $00FF
POKE R0H, INT(ADDR/256)
P=POINTER(S$)
POKE R1L, PEEK(P+1)
POKE R1H, PEEK(P+2)
POKE R2L, L
POKE R2H, 0
SYS MEM.COPY
RETURN
Re: include pokew and peekw in basic?
Posted: Fri Apr 12, 2024 3:46 pm
by funkheld
hello, thanks for help with pokek/peekw.
I didn't understand string poke.
greeting.
Re: include pokew and peekw in basic?
Posted: Fri Apr 12, 2024 3:53 pm
by ahenry3068
funkheld wrote: ↑Fri Apr 12, 2024 3:46 pm
hello, thanks for help with pokek/peekw.
I didn't understand string poke.
greeting.
BANK 2
SAddr=$A000
S$="HELLO WORLD":GOSUB POKE.STRING
SAddr=$A000+LEN(S$)+1
S$="GOODBYE WORLD":GOSUB POKE.STRING
REM Do what you want with S$ here.
BANK 2
SAddr=$A000:GOSUB PEEK.STRING
PRINT S$
SAddr=$A000+LEN(S$)+1
GOSUB PEEK.STRING
PRINT S$
BANK could be any available BANK also. It does not have to be 2.
Re: include pokew and peekw in basic?
Posted: Fri Apr 12, 2024 5:49 pm
by funkheld
Thanks for the great explanation.
now I have learned it.
greeting
Re: include pokew and peekw in basic?
Posted: Fri Apr 12, 2024 6:04 pm
by funkheld
here is one error.
this is 37 :
POKE R1H, INT(ADDR/256)
thanks
greeting
-------------------------------------------
R0L=$02
R0H=$03
R0=R0L
R1L=$04
R1H=$05
R1=R1L
R2L=$06
R2H=$07
R2=R2L
R3L=$08
R3H=$09
R3=R3L
MEM.COPY =$FEE7
DEF FN SW(W)=W + 65536 * (W > 32767)
BANK 2
SAddr=$A000
S$="HELLO WORLD":GOSUB POKE.STRING
SAddr=$A000+LEN(S$)+1
S$="GOODBYE WORLD":GOSUB POKE.STRING
REM Do what you want with S$ here.
BANK 2
SAddr=$A000:GOSUB PEEK.STRING
PRINT S$
SAddr=$A000+LEN(S$)+1
GOSUB PEEK.STRING
PRINT S$
POKE.STRING:
L=LEN(S$)
Addr=SAddr+1
POKE SAddr, L
POKE R1L, FN SW(ADDR) AND $00FF
POKE R1H, INT(ADDR/256)
P=POINTER(S$)
POKE R0L, PEEK(P+1)
POKE R0H, PEEK(P+2)
POKE R2L, L
POKE R2H, 0
SYS MEM.COPY
RETURN
PEEK.STRING:
L=PEEK(SAddr)
S$=RPT$(32,L)
ADDR=SAddr+1
POKE R0L, FN SW(ADDR) AND $00FF
POKE R0H, INT(ADDR/256)
P=POINTER(S$)
POKE R1L, PEEK(P+1)
POKE R1H, PEEK(P+2)
POKE R2L, L
POKE R2H, 0
SYS MEM.COPY
RETURN
----------------------------------
Re: include pokew and peekw in basic?
Posted: Fri Apr 12, 2024 7:09 pm
by ahenry3068
funkheld wrote: ↑Fri Apr 12, 2024 6:04 pm
here is one error.
this is 37 :
POKE R1H, INT(ADDR/256)
thanks
greeting
-------------------------------------------
R0L=$02
R0H=$03
R0=R0L
R1L=$04
R1H=$05
R1=R1L
R2L=$06
R2H=$07
R2=R2L
R3L=$08
R3H=$09
R3=R3L
MEM.COPY =$FEE7
DEF FN SW(W)=W + 65536 * (W > 32767)
BANK 2
SAddr=$A000
S$="HELLO WORLD":GOSUB POKE.STRING
SAddr=$A000+LEN(S$)+1
S$="GOODBYE WORLD":GOSUB POKE.STRING
REM Do what you want with S$ here.
BANK 2
SAddr=$A000:GOSUB PEEK.STRING
PRINT S$
SAddr=$A000+LEN(S$)+1
GOSUB PEEK.STRING
PRINT S$
POKE.STRING:
L=LEN(S$)
Addr=SAddr+1
POKE SAddr, L
POKE R1L, FN SW(ADDR) AND $00FF
POKE R1H, INT(ADDR/256)
P=POINTER(S$)
POKE R0L, PEEK(P+1)
POKE R0H, PEEK(P+2)
POKE R2L, L
POKE R2H, 0
SYS MEM.COPY
RETURN
PEEK.STRING:
L=PEEK(SAddr)
S$=RPT$(32,L)
ADDR=SAddr+1
POKE R0L, FN SW(ADDR) AND $00FF
POKE R0H, INT(ADDR/256)
P=POINTER(S$)
POKE R1L, PEEK(P+1)
POKE R1H, PEEK(P+2)
POKE R2L, L
POKE R2H, 0
SYS MEM.COPY
RETURN
----------------------------------
I don't understand your error. It's a RETURN without gosub. Can you attach the complete code ?
Also if your using BASLOAD. Line number in the TOKENIZED code does not directly equate to the Source file.
Do a LIST 37 to see the code line that gave the error.