LF: Problem with some loops
[Prev][Next][Index][Thread]
LF: Problem with some loops
Could someone help me out with this program? I'm trying to draw a
map on the screen, but the program keeps crashing (Protected memory
violation). It theoretically _shoudl_ work, but realistically it
doesn't.
-------------------------------------------------------------------
@program prog_code,prog_name
;************** Start of Fargo program ***************
prog_code:
jsr graylib[on] ; Turn greyscale on
move.l a6,greyplane ; A6 holds the address to the greyscale
bsr ClearScreen ; Clear the screen. You must make your own
move.l #0,d0
move.l #0,d1
move.l #0,d3
move.l #0,d4
move.l #12,d6
move.l #7,d7
bsr drawmap
jsr flib[idle_loop]
rts
drawmap:
bsr put_row
add #1,d4
add #16,d1
dbra d7,drawmap
rts
put_row:
bsr get_element
nop
bsr PutSprite
add #16,d0
add #1,d3
dbra d6,put_row
rts
get_element:
lea table1(pc),a0
mulu.w #13,d4
add.w d4,a0
add.w d3,a0
clr.l d2
move.b (a0),d2
rts
PutSprite:
movem.l d0-d3/a0-a2,-(a7)
lea tileset1(PC),a0
lsl.l #6,d2
adda.l d2,a0
lsl.w #1,d1
move.l d1,d2
lsl.w #4,d2
sub.w d1,d2
move.b d0,d1
and.w #$FFF0,d0
lsr.b #3,d0
add.w d0,d2
and.b #$0F,d1
sub.b #16,d1
neg d1
moveq #15,d0
lea $4440,a1
move.l greyplane,a2
adda.l d2,a1
adda.l d2,a2
move.l #$FFFF0000,d3
rol.l d1,d3
PS_PutRow:
clr.l d2
move.w (a0)+,d2
lsl.l d1,d2
and.l d3,(a1)
or.l d2,(a1)
clr.l d2
move.w (a0)+,d2
lsl.l d1,d2
and.l d3,(a2)
or.l d2,(a2)
lea 30(a1),a1
lea 30(a2),a2
dbra d0,PS_PutRow
movem.l (a7)+,d0-d3/a0-a2
rts
ClearScreen:
movem.l d0/a0-a1,-(a7) ; Push all registers used
move.l #959,d0 ; The screen is $F00 bytes
move.l greyplane,a0 ; Make A0 point at the greyscale plane
move.l #$4440,a1 ; and A1 to the LCD memory (plane 0)
RepClr:
clr.l (a0)+ ; Clear a longword, increase A0 with 4
clr.l (a1)+ ; Clear a longword, increase A1 with 4
dbra d0,RepClr ; Repeat
movem.l (a7)+,d0/a0-a1 ; Pop the registers
rts
;*****************************************************
; Program data
;*****************************************************
tileset1 incbin tileset1.bin
greyplane dc.l 0
table1
dc.b 0,0,0,3,3,3,3,3,3,0,0,0,0
dc.b 0,1,0,3,3,3,3,3,3,0,1,0,1
dc.b 0,0,1,2,2,2,2,2,2,1,1,0,0
dc.b 0,1,0,2,2,2,2,2,2,0,0,0,0
dc.b 0,0,0,2,2,4,2,2,4,0,0,1,0
dc.b 0,0,0,0,0,0,1,0,1,0,1,1,0
dc.b 1,0,1,0,1,1,0,0,0,1,0,0,1
prog_name: dc.b "Array test program",0
;*************** End of Fargo program ****************
reloc_open
add_library flib
add_library graylib
add_library romlib
reloc_close
end
---------------------------------------------------------
A ZIP file containing the ASM file and the BIN file I used for the
sprites is included.
------------------------------------------------
Apocalypse_92
neilbj@cset.isu.edu
http://www.geocities.com/SiliconValley/Way/2305/
Geocities Silicon Valley Community Leader
------------------------------------------------