I'm fairly certain I'm doing something stupidly wrong, so if one of you folks were feeling charitable and could point me in the right direction I'd be much obliged.
Lastly -- yes, it's an awkward way of calling this procedure, but that's because DLL interface I need to use (Blitz's ugly CallDLL, for those interested) specifies this interface -- so while there may be better means by which to do the interface, that's the one I'm stuck with.
Thanks in advance for having a look.
Code: Select all
; 'in' is 3 bytes of info
; byte 0 = x dimension requirement
; byte 1 = y dimension requirement
; byte 2 = level being constructed
; am considering byte 3+ to be a custom "string".
;
; out is pre-sized to meet the x and y dimensions -- fill it up at the end.
Procedure CreateMap(*in, in_size, *out, out_size)
; the in DLL gives the routine x dimension, y dimension and level being created.
xSize.b = PeekB(*in)
ySize.b = PeekB(*in + 1)
level.b = PeekB(*in + 2)
; quick sanity checker to make sure we're getting what we need in the outbank
totalSize = xSize * ySize
If totalSize > out_size
MessageRequester("Map Data Error", "The map bank size is insufficient for the level specified.", #PB_MessageRequester_Ok)
End
EndIf
; now you just do all your nifty keen custom map stuff
; since this is just an example, we make one massive room with no walls.
Dim map$(xSize-1, ySize-1)
For col = 0 To xsize - 1
For row = 0 To ysize - 1
map$(col, row) = ","
Next
Next
; now load up the out bank with the ascii code of the map you've created before
; you drop out of the procedure.
; address offset starts at 0
address.l = 0
; cycling through each row, and then each column per row
For row = 0 To (ySize - 1)
For col = 0 To (xSize - 1)
; grab the ascii code of the character occupying that spot on the map
char.b = Asc(map$(col, row))
; if we've somehow screwed up, crash out
If address > totalsize
MessageRequester("Map Data Error", "Whewps, bad mojo here.", #PB_MessageRequester_Ok)
End
EndIf
; add the character to the line to be displayed
myLine$ = myLine$ + Chr(char)
; poke the character to the out bank
; THIS IS THE OFFENDING BIT
; unREM this line to see it crash beautifully.
PokeB(*out + address, char)
; increment the offset by one
address = address + 1
Next
myLine$ = myLine$ + chr$(13)
Next
MessageRequester("BLANKMAP", myLine$, #PB_MessageRequester_Ok)
EndProcedure
myInMem = AllocateMemory(1, 3)
myOutMem = AllocateMemory(2, 80*24)
PokeB(@myInMem, 80)
PokeB(@myInMem + 1, 24)
PokeB(@myInMem + 2, 2)
CreateMap(@myInMem, 3, @myOutMem, 80*24)
End