Code Snippets: Difference between revisions

From F256 Foenix
Jump to navigationJump to search
No edit summary
mNo edit summary
Line 7: Line 7:
proc xpeek(addr)<br>
proc xpeek(addr)<br>
local block:block=addr\8192:local prevblock<br>
local block:block=addr\8192:local prevblock<br>
local offset:offset=addr%8192<br>
local offset:offset=addr&$1fff<br>
?0=179:prevblock=?$E:?$E=block:?1=4<br>
?0=179:prevblock=?$E:?$E=block:?1=4<br>
peekvalue=peek($C000+offset)<br>
peekvalue=peek($C000+offset)<br>
Line 16: Line 16:
proc xpoke(addr,value)<br>
proc xpoke(addr,value)<br>
local block:block=addr\8192:local prevblock<br>
local block:block=addr\8192:local prevblock<br>
local offset:offset=addr%8192<br>
local offset:offset=addr&$1fff<br>
?0=179:prevblock=?$E:?$E=block:?1=4<br>
?0=179:prevblock=?$E:?$E=block:?1=4<br>
?($C000+offset)=value<br>
?($C000+offset)=value<br>

Revision as of 20:35, 15 May 2025

Index of SUPERBASIC Code Snippets (Hopefully this will be sorted by Topic when they grow)

Poking and Peeking Memory in a different Bank

SUPERBASIC uses a lot of the memory available, so when you want to store data on a different Bank you want to POKE or PEEK outside the normal memory range, to do so you can use the following PROCEDURES. PLease note that these are not by any means a fast way to do it since we reconfigure the memory LUT so that the memory under the registers location ($C000-$DF00) points to the address that we want to poke or peek on the fly, after that we get or set the content of the memory address and restore the segments so that the Kernel does not blow up after returning. Contrary to what I initially believed it works!.

REM "XPEEK - value is stored in peekvalue variable"
proc xpeek(addr)
local block:block=addr\8192:local prevblock
local offset:offset=addr&$1fff
?0=179:prevblock=?$E:?$E=block:?1=4
peekvalue=peek($C000+offset)
?1=0:?$E=prevblock
endproc

REM "XPOKE"
proc xpoke(addr,value)
local block:block=addr\8192:local prevblock
local offset:offset=addr&$1fff
?0=179:prevblock=?$E:?$E=block:?1=4
?($C000+offset)=value
?1=0:?$E=prevblock
endproc

Print Text at X,Y Position

Chances are that you need to print text at a specific position in the screen, SUPERBASIC doesn't have a LOCATE command, so the best next thing is to use this routine to print at a certain X,Y coordinate onscreen. Oh you are not not using an 80 column screen mode?, don't worry the routine will compensate automagically!

proc printat(x,y,a$)
col=(?$D001)&2:if col=0 then col=1
local pos:pos=x+y*80\col:?1=2:rem "Set I/O to text memory"
for c=0 to len(a$)-1:?(pos+c+$C000)=asc(mid$(a$,c+1,1)):next
?1=0
endproc