Blitz3D+ Command Reference

PokeShort bank,offset,value

Parameters

bank - bank handle returned by CreateBank

offset - position in the bank to write to, in bytes

value - value to store; only the low 16 bits (0-65535) are kept

Description

Writes a short into a bank.

A short occupies 2 bytes of the bank. Only the low 16 bits of the value are stored (0 to 65535 survive exactly), and PeekShort returns them unsigned. Any byte offset is fine, but both bytes must fit inside the bank (last valid offset is BankSize-2) or a runtime error is raised.

See also: PeekShort, PokeByte, PokeInt, PokeFloat.

Example

; PokeShort Example
; -----------------

; A player save-game record packed into a memory bank.
; Field sizes: byte=1, short=2, int=4, float=4 bytes.
;
;   offset 0   flags   (byte,  1 byte )
;   offset 1   hp      (short, 2 bytes)
;   offset 3   score   (int,   4 bytes)
;   offset 7   x_pos   (float, 4 bytes)   = 11 bytes in total

save=CreateBank(11)

; Pack the record - PokeShort writes the 2-byte hp field
; at offset 1 (values 0-65535); the other Pokes fill the rest
PokeByte save,0,5
PokeShort save,1,250
PokeInt save,3,1234567
PokeFloat save,7,17.25

; Unpack the record - each Peek reads its field back
Print "Player record in a "+BankSize(save)+" byte bank:"
Print ""
Print "offset 0   flags (byte)  = "+PeekByte(save,0)
Print "offset 1   hp    (short) = "+PeekShort(save,1)
Print "offset 3   score (int)   = "+PeekInt(save,3)
Print "offset 7   x_pos (float) = "+PeekFloat(save,7)

; Dump every byte so the layout is visible
; (ints and floats are stored low byte first)
dump$=""
For i=0 To BankSize(save)-1
    dump$=dump$+PeekByte(save,i)+" "
Next
Print ""
Print "Raw bytes: "+dump$

; Release the memory when done
FreeBank save

Print ""
Print "Press any key to close the example"
WaitKey

End

Index