A85: TestBit routine (help!)
[Prev][Next][Index][Thread]
A85: TestBit routine (help!)
I have a little bit (no pun intended =) of a problem. I wrote this
routine for a game I'm making (TI-85, USGARD 1.5) and I just can't get
it to work. I'm at my wit's end with this stupid code so any help would
be REALLY appreciated!
Here's how it starts out: First, I use the first eight bytes of text
mem (TEXT_MEM to TEXT_MEM+7) for variables. Here's that part:
call RANDOM
ld (TEXT_MEM),a
call RANDOM
ld (TEXT_MEM+1),a
call RANDOM
ld (TEXT_MEM+2),a
call RANDOM
ld (TEXT_MEM+3),a
call RANDOM
ld (TEXT_MEM+4),a
call RANDOM
ld (TEXT_MEM+5),a
call RANDOM
ld (TEXT_MEM+6),a
call RANDOM
ld (TEXT_MEM+7),a
I know that the RANDOM rom call isn't too great of a random number
generator but I can't get the other routine to work as of yet (but thats
a whole other story). What I WANT this code to do is place an eight bit
random number into the text mem and have those correspond to blocks on
the screen. The screen consists of 64 possible block positions (8x8),
each block 8x8 pixels. Just for kicks heres the block in binary...
Block:
.db 8,8
.db %00000000
.db %01111110
.db %01111110
.db %01111110
.db %01111110
.db %01111110
.db %01111110
.db %00000000
Each bit in the text mem corresponds to a block on the screen (8x8 mem
and 8x8 blocks). Now heres the routine to check if a certain block is
lit or not (bc contains current screen coordinates in PutSprite format
(hex)):
TestBit:
ld a,c ; c is the row coord (either 0, 8, 16, 24, 32,
40, 48, or 56)
cp 0
jr z,Row0
cp 8
jr z,Row1
cp 16
jr z,Row2
cp 24
jr z,Row3
cp 32
jr z,Row4
cp 40
jr z,Row5
cp 48
jr z,Row6
cp 56
jr z,Row7
Row0:
ld hl,(TEXT_MEM)
jr Col
Row1:
ld hl,(TEXT_MEM+1)
jr Col
Row2:
ld hl,(TEXT_MEM+2)
jr Col
Row3:
ld hl,(TEXT_MEM+3)
jr Col
Row4:
ld hl,(TEXT_MEM+4)
jr Col
Row5:
ld hl,(TEXT_MEM+5)
jr Col
Row6:
ld hl,(TEXT_MEM+6)
jr Col
Row7:
ld hl,(TEXT_MEM+7)
jr Col
Col:
ld c,a ; put row coord back into c
ld a,b ; column coord, same possible positions as the
row coord
cp 0
jr z,Col0
cp 8
jr z,Col1
cp 16
jr z,Col2
cp 24
jr z,Col3
cp 32
jr z,Col4
cp 40
jr z,Col5
cp 48
jp z,&Col6
cp 56
jp z,&Col7
Col0:
ld b,a
bit 7,l
ret
Col1:
ld b,a
bit 6,l
ret
Col2:
ld b,a
bit 5,l
ret
Col3:
ld b,a
bit 4,l
ret
Col4:
ld b,a
bit 3,l
ret
Col5:
ld b,a
bit 2,l
ret
Col6:
ld b,a
bit 1,l
ret
Col7:
ld b,a
bit 0,l
ret
I hope you can kind of get an idea of whats happening through my
horrible coding =P
BTW, do any flags get changed with a ret? That might be some of the
problem...
I know I am asking a lot and I know that my code is horrible and
unoptimized but if anyone could at least push me in the right direction
I would be forever in debt!
Thanks,
- Jim (rublej@geocities.com)
P.S... if you haven't already figured it out, the game will be a
LightsOut type with random blocks
Follow-Ups: