Blitz (63/81)

From:David McMinn
Date:16 Mar 2001 at 11:15:03
Subject:Re: How to optimize...?

Hi David

> I've changed your statement so that it uses a buffer instead of a string. I hope
> this works, but you'll need to test it.

I've been playing around and the original code I sent will not work. In fact it
will crash. Sorry, my brain must have been somewhere else when I wrote the
code. I've rewritten the code I sent, and it should work this time.

; This is needed for hacking the string pointers
NEWTYPE.string
s.s
End NEWTYPE

Statement MyShowText{adr.l} ; y and x are pos of TextPrint
y=0:x=0:txtc=255 ; txtc is the color of Font

; A fixed buffer which we can write the string into
; This uses space on the stack, so you do not want to make it too
; big. You could also make this a global variable and use it in
; this statement with SHARED. We start at position 4 so we have
; some space to store a longword for the string length before it.
; This replaces the a$ and b$ in your loop
Dim buffer.b(1600)
bufpos.w = 4

; This is quite hacky, and is probably quite bad to do, but it means
; we do not need to poke and peek entire strings from memory. We would
; not have to do this if the FNSPrint command accepted pointers to
; memory as well as strings. I hope it works.
blah.string\s = ""
str_backup.l = NPeekL(&blah)
NPokeL &blah,&buffer(4)

; Why do you have +88 here?
For mem.l=0 To 50*30+88 ; PrintText is 50*30
If NPeekB(mem.l+adr.l)=$a Then y+8:mem.l+1:x=0
If NPeekB(mem.l+adr.l)=$25:mem.l+1:chg=1
If NPeekB(mem.l+adr.l)=$30 AND chg=1
txtf=0:chg=0:mem.l+1
buffer(4)=NPeekB(mem.l+adr.l):buffer(5)=0
bufpos=5 : NPokeL &buffer(0),1
EndIf

If NPeekB(mem.l+adr.l)=$31 AND chg=1
txtf=1:chg=0
bufpos = 4
Repeat
mem.l+1
membyte = NPeekB(mem.l+adr.l)
buffer(bufpos) = membyte
bufpos + 1
Until membyte=$25
buffer(bufpos-1)=0
NPokeL &buffer(0),bufpos
mem.l+1
EndIf

If chg=1
Select NPeekB(mem.l+adr.l)
Case $61: txtc=255
Case $62: txtc=254
Case $63: txtc=253
End Select
EndIf
EndIf

FNSPrint txtf,220+x,y,blah\s,0,txtc
If txtf=0 Then x+8
Next mem

; Restore the memory we previous hacked into the string
NPokeL &blah, str_backup
End Statement



|) /\ \/ ][ |) |\/| c |\/| ][ |\| |\| | dave@blitz-2000.co.uk
http://members.nbci.com/david_mcminn | ICQ=16827694
'Feel the Force, motherf**ker' - Samuel L. Jackson, Jedi

---------------------------------------------------------------------
To unsubscribe, e-mail: blitz-list/-unsubscribe@netsoc.ucd.ie
For additional commands, e-mail: blitz-list/-help@netsoc.ucd.ie