1
ASM / Re: 16x16 sprites?
« on: July 03, 2010, 01:17:56 pm »P.s. I know C is already used elsewere, that is likely to screw it up but i tried to insert a cntr byte by doing:The reason that's not working is that the only 8-bit register you can store into/from an immediate address is A. One way you can get around this is by making "cntr" two bytes instead of one, and then using "ld (cntr), BC".Code: [Select]cntr: .db 0
but then every time I did this:Code: [Select]LD cntr, C
or thisCode: [Select]LD (cntr), C
it threw a error saying: "unrecognized argument"
I also see a few issues with your code, so let's try and tackle them one at a time (The cool thing is that one of them sort of fixes itself and doesn't actually cause a visible problem )
- The first is where you put xpos, ypo, and clip_mask. Although in this case it isn't a problem, under most circumstances it could lead to quite annoying behavior
It's best to put variables like this either at the end of your code or at least somewhere it won't be executed (in the Asm28days example, notice that ypos/xpos/sprite are skipped because of the jr's). The reason for this is that a db/dw directive will actually insert the numbers into the code. Even though the programmer knows they just want to use those locations as storage, the processor will still try and execute it as code. In your case the three consecutive $00's are executed, but since this is the opcode for 'nop' nothing happens.
- The next issue are those "push BC"'s you have. When you use "call", the address of where to return to is pushed onto the same stack as when you push/pop the 16-bit registers. This means that when you use "ret", whatever is at the top of the stack is popped and used as the address to return to. There are a couple places where this will cause a problem:
1) When running through "KeyLoop", you have BC at the top of the stack so when it gets to the "ret z" it starts executing code starting at the value of BC, which is probably not even part of the program. You need to be careful when using the stack and make sure there aren't any conflicts with call/ret.
2) In PutSpr, the first line is a "push BC" and I don't see any "pop BC"'s before the first ret, so weird things are going to happen there as well.
I think the best way to fix these problems for your program is to just use some memory location for "cntr" instead of the stack.
I hope this helps I'm not sure if I got all the bugs, but my computer is being mean to me today so I can't test this on an emulator.