I wrote a quick routine to shift a quarter of PlotSScreen down, but it doesn't work and ends up putting garbage on the last row (and corrupting things below that, I'm assuming). I've run it through my head a few times, and I can't figure out where I went wrong, so here's my code:
Z80 Assembly wrote:
ShiftDown:
xor A
ld B, A
ld A, 31
DownStart:
ld C, 6
add HL, BC
ex DE, HL
ld HL, -12
add HL, DE
lddr
dec A
jr nz, UpStart
ret
I'm even more confused because it's almost exactly the reverse of another routine that shifts a quarter of the screen up, which works:
Z80 Assembly wrote:
ShiftUp:
xor A
ld B, A
ld A, 31
UpStart:
ld C, 6
sbc HL, BC
ex DE, HL
ld HL, 12
add HL, DE
ldir
dec A
jr nz, UpStart
ret
Does anyone see where I went wrong in the first block? The input for ShiftUp is PlotSScreen + 6 to shift the first quarter of the screen, and the input for ShiftDown to shift the same block is supposed to be PlotSScreen + (768 / 2) - 1 - 12.
Hmm, where on the screen is the quarter that you want to shift? Is it like the upper left, upper right, or whatever?
Input goes in HL. For ShiftUp, it's the first byte in the block plus six; for ShiftDown, the last byte in the block minus six.
Hmm, but what section of the screen needs to be shifted? (I can never seem to read code easily unless I make it or know exactly what it is supposed to do)
It depends on what's in HL. For ShiftUp, it points to the first byte in the block to be shifted plus six (PlotSScreen + 6 for the top-left, PlotSScreen + 12 for the top-right), while for ShiftDown, it points to the last byte in the block to be shifted minus six (PlotSScreen + (768 / 2) - 1 - 12 for the top-left, PlotSScreen + (768 / 2) - 1 - 6 for the top-right).
Oh, I see! Unless I made a typo, this should work (for shifting down):

Code:

ShiftDown:
     ld de,173h
     add hl,de
     ex de,hl
     ld hl,12
     add hl,de
     ex de,hl
     ld a,31
     ld b,0
ShiftDownLoop:
       ld c,6
       sbc hl,bc
       ex de,hl
       sbc hl,bc
       ex de,hl
       lddr
       dec a
       jr nz,ShiftDownLoop
       ld b,6
       inc hl
       ld (hl),a
       djnz $-2
       ret


it might not be the most efficient way, but it works Smile

Code:
xor A
ld B, A
What do you have against ld b,0? Smile You can load immediate values to a, b, c, d, e, h, l, bc, de, hl, and ix.

I believe the problem may lie in your use of lddr? I'll have to look more closely, though.
xor a resets the carry flag, which saves an instruction when he uses sbc hl,bc later. But I guess that doesn't apply to the first code Razz
He could have been resetting the c flag for the sbc Wink
That's exactly why I used it. I wrote ShiftUp first, then forgot to change that when I copied it to ShiftDown.
Deep Thought wrote:
That's exactly why I used it. I wrote ShiftUp first, then forgot to change that when I copied it to ShiftDown.
Oh good, that's good to hear. Smile That's quite clever actually, well done!

Hehe, would I be a sunuvagun to point out that DownStart jumps to UpStart, not DownStart? Smile
Aaand that's my entire problem Razz Thanks KermM.
Lovely! Nice catch KermM!
Deep Thought wrote:
Aaand that's my entire problem Razz Thanks KermM.
Haha, no problem. I've certainly run into copypasta problems once or twice in the past, so I feel your pain here. Smile May I ask what project this is for, if you'd care to share (and if it's for anything)? Perhaps something that deserves a Your Projects topic?

Edit: Cheers, Xeda. Smile
It's another entry for zContest that I'm keeping secret for now. It's an Axe game, but I'm free to use all the assembly I want Smile
Deep Thought wrote:
It's another entry for zContest that I'm keeping secret for now. It's an Axe game, but I'm free to use all the assembly I want Smile
Intriguing, I had thought that using ASM in Axe programs was not the easiest? Although as I'm not an Axe coder myself, I can't fairly evaluate that. Best of luck on it, then, and I look forward to seeing it in the contest. Feel free to re-use this topic or make another one if you run into other ASM problems, of course.
Has to be hex, but I'm assembling and unsquishing the code for the most part. Counting hex bytes is fun too Smile And thanks.
Deep Thought wrote:
Has to be hex, but I'm assembling and unsquishing the code for the most part. Counting hex bytes is fun too Smile And thanks.
Haha, that sounds quite interesting; I'm intrigued to find out why you would need to do that. Can you reveal if you're entering in the ASM or Ex-BASIC category?
The bulk of the code is Axe, so it's xBASIC. I just count bytes when I need to fix something quickly and I'm far from a computer.
Deep Thought wrote:
The bulk of the code is Axe, so it's xBASIC. I just count bytes when I need to fix something quickly and I'm far from a computer.
Would you be able to use one of the on-calculator ASM IDEs to generate the code you need if you have to adjust your pure ASM bits? Or wouldn't that quite do the trick?
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement