How would I reference the struct array? I've spun my wheels long enough on this. Below gives me compile error:
wankertest.asm(115) : error A2026: constant expected

When I use a reg like ecx instead of NUM, gives me - invalid scale value.
When I hardcode the value, it compiles ok (not tested yet).



.data?
SPRITEBANK STRUCT
BNKNO DWORD 0 ;which bank number is this
SX DWORD 0 ;screen xres
SY DWORD 0 ;screen yres, eg. 256x128
SPX DWORD 0 ;sprite xres
SPY DWORD 0 ;sprite yres, eg. 64x64
ANIM DWORD 32 DUP (0) ;animation holder
fName DB 32 DUP(0) ;filename, for future use of maploading
SPRITEBANK ends

SBNK SPRITEBANK 7 DUP (<>) ;simple sprite struct array

SIZEOFSBNK equ SIZEOF SPRITEBANK


.code
:::

mov ecx,NUM
ASSUME edx:PTR SPRITEBANK
mov SBNK.HBMP,eax ;<======= constant expression expected??
ASSUME edx:NOTHING
Posted on 2003-10-24 04:46:28 by drarem
1. Is "NUM" your .const value ???

2. "When I use a reg like ecx instead of NUM, gives me - invalid scale value.":
It's becouse this construction :
index == 1 or (power of 2)
displ == <-2*1024^3 , 2*1024^3>
Posted on 2003-10-24 17:25:20 by AceEmbler
For an array element that has a size other than 1, 2, 4, or 8, you must do the index multiplication yourself.

imul ecx,SIZEOFSBNK ; scale index to offset value
mov SBNK.HBMP,eax

If for loop or other reasons you don't want to alter ECX, then the CPU provides another form of multiplication.

imul esi,ecx,SIZEOFSBNK ; store scaled value in temporary ESI
mov SBNK.HBMP,eax
Posted on 2003-10-24 18:35:44 by tenkey
Thanks much for the replies, I've found another way after letting my brain rest for 24 hours, checking out the imul as you suggested and searching this forum once more..

CreateBMP proc BNUM:DWORD, w:DWORD, h:DWORD
LOCAL BMP:DWORD

invoke CreateCompatibleBitmap,WND.hDC,w,h
mov BMP,eax

mov ecx,BNUM
imul ecx,SIZEOFSBNK

m2m ,
m2m ,BNUM

ret
CreateBMP endp

And it appears to work :) I use a function called SetDC to set it to the appropriate bitmap in the structure prior to usage.

SetDC proc BNUM:DWORD, BDC:DWORD
invoke CreateCompatibleDC,WND.hDC ;yes I know this creates a dilemma - will move it to my initialization functions later
mov ecx,BDC
mov ,eax
mov BDC,eax ;all 3 are needed to populate BDC which is called via ADDR

mov ecx,BNUM
imul ecx,SIZEOFSBNK
invoke SelectObject,BDC,

ret
SetDC endp

Two quick final questions:

1) How do you tell if a bitmap exists so it can be deleted on cleanup, .IF == NULL ?

2) Although I declared this:
SBNK SPRITEBANK 7 DUP (<>) (see first post for structure)

I can use 15,16, etc.. indexes and get valid bitmap pointers without crashing. Of course if I try 100+ it crashes with a read error. What gives there?
Posted on 2003-10-24 22:07:11 by drarem
http://www.web.ms11.net/drarem/WankerLib.zip

This is pretty much all I had time for today, kiddies.. the .exe is 6k, total zip is 10k - consists of two bitmaps, one program icon, and a test program compiled from the lib..

press arrow keys to move blocky image around.. It uses 4 dc's (will not exceed 4) and 5 bitmaps - no memory leaks thanks to memproof.

what you're seeing is a tile from bitmap1 and bitmap2 as it draws them combining them into the backdc, then overlaying that with the moveable blocky image.

To initialize, I use the following:

    .elseif uMsg == WM_CREATE

invoke GetDC,hWin
mov WND.hDC,eax

call mainloop

invoke BackBuffer,800,600
;initialize both the memDC and backDC for triple buffering..
;TODO: go to dirty rectangles and think about dropping a DC

szText fName2,"test1.bmp"
invoke LoadBANK,ADDR fName2,2 ;load the first bitmap
invoke SetDCBNK, 2, bDC

szText fName3,"test.bmp"
invoke LoadBANK,ADDR fName3,3 ;load the second bitmap
invoke SetDCBNK, 3, bDC ; - only one Sprite DC will I allow, so use it wisely

INITRECT WND.hRECT,0,0,800,600


I hope to get to a point where I can do as below, but that is after I do the code for the sprite masks.

invoke Sprite, WND.memDC, 1, nx, ny, bDC

Would there be an interest in this GDI library? If so supply comments and crits, otherwise I will keep it to meself.

Here is the code for the map drawing. I know it aint much but I feel like I've made a little progress. Thanks again, asm community :)

DrawMap proc

LOCAL e:DWORD
LOCAL f:DWORD
LOCAL g:DWORD

mov e,0
mov f,0
FLT600:
mov e,0
ELT800:
.IF g >= 2
invoke SetDCBNK,2, bDC
mov g,0
.else
invoke SetDCBNK,3, bDC
.ENDIF
inc g
invoke BitBlt,WND.backDC,e,f,64,64,bDC,128,0,SRCCOPY

add e,64
cmp e,768
jl ELT800 ;if e < 800 then jump to ELT800 to draw out line of tiles
add f,64
cmp f,576 ; else compare f with 600
jl FLT600 ;if f < 600 then jump to FLT600 and reset e to 0
ret
DrawMap endp
Posted on 2003-10-25 04:01:26 by drarem
Of course, this GDI library is interesting. :)

BTW, I think you could better try accessing your array from a loop:


push esi
mov esi,offset SBNK
assume esi:ptr SPRITEBANK
.repeat
;
; Here goes the code that works on each sprite bank.
; Access the struct's items like this:
; mov [esi].BNKNO,eax
;
; If you don't want the "assume" statement, do this:
; mov [esi].SBNK.BNKNO,eax
;
add esi,sizeof SBNK
.until esi == offset SBNK + sizeof SBNK
assume esi:nothing
pop esi

Hope it helps. :)
Posted on 2003-10-25 10:38:04 by QvasiModo