Désespoir de cause :
|==================================================================
| ComputeIcons
|==================================================================
| Calc the coordinate of a list of icons and save them in a table
|
| input a0 icon list
| output nothing
| destroy d0-d2/a0-a1
|==================================================================
ComputeIcons:
movem.l %d3-%d6,-(%sp)
moveq.l #-1,%d3 |counter of tiles
move.w LcdWidth(%fp),%d4
move.w LcdHeight(%fp),%d5
|==================================================================
| Read icon data and prepare registers
|==================================================================
addq.l #2,%a0 |skip first index
ComputeIconsLoop:
move.w (%a0)+,%d2 |flag
move.w (%a0)+,%d0 |x
move.w (%a0)+,%d1 |y
|==================================================================
| Check for hz center
|==================================================================
btst.l #2,%d2 |Hz center ?
beq.s NoHzCenter |no
move.w %d4,%d6
lsr.w #1,%d6 |LCD_WIDTH/2
add.w %d6,%d0 |update x
bra.s ComputeIcon
NoHzCenter:
|==================================================================
| Check for vert center
|==================================================================
btst.l #3,%d2 |Vert center ?
beq.s NoVertCenter |no
move.w %d5,%d6 |else get LCD_Height
lsr.w #1,%d6 |LCD_Height/2
add.w %d6,%d1 |update x
bra.s ComputeIcon
NoVertCenter:
|==================================================================
| Check for abcisse origin
|==================================================================
btst.l #0,%d2 |x org ?
beq.s OrgXLeft |yes
add.w %d4,%d0 |and add it
OrgXLeft:
|==================================================================
| Check for ordinate origin
|==================================================================
btst.l #1,%d2 |y org ?
beq.s OrgYTop |yes
add.w %d5,%d1 |and add it
OrgYTop:
|==================================================================
| Save coordinates and draw the tile
|==================================================================
ComputeIcon:
move.w %d1,-(%sp) |save y
move.w %d0,-(%sp) |save x
addq.l #1,%d3 |increase counter
cmpi.w #0xffff,(%a0)+ |end of list ? (and skip index)
bne.s ComputeIconsLoop |no, compute next one
|==================================================================
| Create coordinates table and quit
|==================================================================
move.l ICONS_COORD_PTR(%fp),-(%sp) |push previous handle ptr
beq.s NotCreated |not created yet
RC HeapFreePtr |else delete it
NotCreated:
move.l %d3,%d4 |counter for copy
addq.l #1,%d4 |number of entries
lsl.l #2,%d4 |size of handle to create
addq.l #2,%d4 |add size of #icons
move.l %d4,(%sp) |push it over old handle ptr
RC HeapAllocPtr |try to alloc and lock
addq.l #4,%sp |pop arg
move.l %a0,ICONS_COORD_PTR(%fp) |test and save it
bne.s TableCreated |ok
moveq.l #ERROR_MEMORY,%d0 |error code
bra Quit |and quit
TableCreated:
move.w %d3,(%a0) |save counter at the beginning of the table
adda.l %d4,%a0 |end of list
FillTable:
move.l (%sp)+,-(%a0) |get {x,y}, fixing sp
dbra.w %d3,FillTable |loop for each icon
movem.l (%sp)+,%d3-%d6
rts
Surtout su quelqu'un voit une coquille, qu'il n'hésite pas à me faire signe
L'allocation se fait dans la dernière partie (create coordinates table and quit), et le handle est rempli avec son nombre d'éléments (offset 0), puis des longwords. Le compteur est d3, initialisé à -1 aavnt la boucle et incrémenté à chaque fois.