include pokew and peekw in basic?
Re: include pokew and peekw in basic?
Can't say I'm familiar with POKEW/PEEKW. Google wasn't much help either <GASP!>
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: include pokew and peekw in basic?
Aren't integers W% in basic slow because they are converted back to float before use?
greeting
greeting
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: include pokew and peekw in basic?
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.
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: include pokew and peekw in basic?
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
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
Last edited by ahenry3068 on Fri Apr 12, 2024 5:44 pm, edited 1 time in total.
Re: include pokew and peekw in basic?
hello, thanks for help with pokek/peekw.
I didn't understand string poke.
greeting.
I didn't understand string poke.
greeting.
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: include pokew and peekw in basic?
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?
Thanks for the great explanation.
now I have learned it.
greeting
now I have learned it.
greeting
Re: include pokew and peekw in basic?
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
----------------------------------
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
----------------------------------
- Attachments
-
- error.jpg (44.59 KiB) Viewed 2215 times
- ahenry3068
- Posts: 1146
- Joined: Tue Apr 04, 2023 9:57 pm
Re: include pokew and peekw in basic?
I don't understand your error. It's a RETURN without gosub. Can you attach the complete code ?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
----------------------------------
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.