Re: A85: Memory Loading


[Prev][Next][Index][Thread]

Re: A85: Memory Loading




Here's the main chunks of where the bug is...

Board    = TEXT_MEM             ;where the board is stored in text mem

;b  = x-coordinates
;c  = y-coordinates
;e  = row XOR mask
;hl = row in board

 ld     bc,0                    ;PutSprite position
 ld     e,128                   ;for position mask in Draw_XOR_Block
 ld     hl,Board                ;load board mem to hl

PlaceMove:                      ;if 2nd was pressed inside game loop...
 push   bc
 push   de
 push   hl

 ld     a,b                     ;load x-cord into a
 or     a                       ;is it zero?
 jr     z,InvertCurrentPos      ;if yes, goto InvertCurrentPos

 ld     a,b                     ;get the x-cord from b
 sub    8                       ;decrease by 8 (get to left position)
 ld     b,a                     ;load it back to b

 rlc    e                       ;Memory:
 ld     a,(hl)                  ;  o
 xor    e                       ; xoo
 ld     (hl),a                  ;  o

 call   &Draw_Block             ;draw it

 ld     a,b                     ;get x-cord from b
 add    a,8                     ;increase by 8 (get back to center
position)
 ld     b,a                     ;x-cord back to b

 rrc    e                       ;get memory back to center position

InvertCurrentPos:
 ld     a,(hl)                  ;get byte from board
 xor    e                       ;invert current position in memory
 ld     (hl),a                  ;load it back to hl

 call   &Draw_XOR_Block         ;back to origional block
 call   &Draw_Block             ;invert it
 call   &Draw_XOR_Block         ;back to XOR masked block

InvertRight:
 ld     a,b                     ;get x-cord to a
 cp     56                      ;is it 56?
 jr     z,InvertUp              ;if yes, go to InvertUp

 ld     a,b                     ;get x-cord to a
 add    a,8                     ;increase by 8 (get to right position)
 ld     b,a                     ;load x-cord back to b

 rrc    e                       ;rotate memory byte right
 ld     a,(hl)                  ;get byte from board
 xor    e                       ;invert it in memory
 ld     (hl),a                  ;load it back into hl

 call   &Draw_Block             ;invert block

 ld     a,b                     ;x-cord into a
 sub    8                       ;get center position
 ld     b,a                     ;x-cord back to b

 rlc    e                       ;rotate memory byte left

InvertUp:
 ld     a,c                     ;y-cord to a
 or     a                       ;zero?
 jr     z,InvertDown            ;if yes, go to InvertDown

 ld     a,c                     ;y-cord to a
 sub    8                       ;go to top position
 ld     c,a                     ;y-cord back to c

 dec    hl                      ;get to previous row
 ld     a,(hl)                  ;get byte from board
 xor    e                       ;invert top position
 ld     (hl),a                  ;load it back into hl

 call   &Draw_Block             ;invert block

 ld     a,c                     ;y-cord to a
 add    a,8                     ;go to center position
 ld     c,a                     ;y-cord back to c

 inc    hl                      ;next row down

InvertDown:
 ld     a,c                     ;y-cord to c
 cp     56                      ;is it 56?
 jr     z,InvertDone            ;if yes, go to InvertDone

 ld     a,c                     ;y-cord to a
 add    a,8                     ;increase it by 8 (get bottom position)
 ld     c,a                     ;y-cord back to c

 pop    de                    ;de should be the way it was going into
PlaceMove but without these two
 push   de                    ;lines the keypressing is all messed up.
Go figure...
 inc    hl                      ;hl points to next row
 ld     a,(hl)                  ;get byte from board
 xor    e                       ;invert bottom position
 ld     (hl),a                  ;load it back into hl

 call   &Draw_Block             ;invert block

InvertDone:
 pop    hl                      ;load hl
 pop    de                      ;load de
 pop    bc                      ;load bc
 jp     &GameLoop

Block:
.db 8,8
.db %01111100
.db %11000010
.db %10111110
.db %10111110
.db %10111110
.db %10111110
.db %01111100
.db %00000000

XOR_Block:
.db 8,8
.db %01111100
.db %11111110
.db %11111110
.db %11111110
.db %11111110
.db %11111110
.db %01111100
.db %00000000

.end


Yeah this is probably horribly unoptomized but this is my first Z80 asm
program and plus I haven't gotten to the optimization stage yet.  You'll
have to forgive the messed up spacing... it was made in DOS Edit.
First off, this is part of the LightsOut game I'm making (for those of
you who've played it before... rather like Toggles but with multiple
levels).  The Board var uses the first eight bytes of the text mem for
the board storage (8x8 board, each block is 8x8 more or less).  HL
points to the current board row, BC are the x and y coordinates
respectively, and E is the XOR mask for the current row (like say you
are at the 2nd from the left position in a row.  E now contains binary
01000000 so it can be used to invert the positions it needs to.
What I'm having trouble with is that when you call PlaceMove from the
gameloop, everything shows up OK on the screen but it never changes the
Board memory.  There may be a few more bugs in there too but this is the
one I'm trying to kill now.  Any help whatsoever would be greatly
appreciated!

 - Jim

btw, I hope I don't come across as a freeloader trying to get everyone
else to write my code for me but I've been working on this little sucker
for months  =)


References: