Righto, quick summary of the task :
Generating a lookup table containing the memory location of the immediate left byte for each line of the mode 5 screen. First entry bottom row of the screen, last entry top row of the screen.
My reasoning for generating the table is that looking up the start address of the row will be the quickest method, as discussed here in the forums already by others, and rather than waste 512bytes in my executable, I'll get the program as part of it's environmental setup to generate the table in two low pages. Speed is not important, the setup code area to be working space or other when the core of the program is executing.
Great stuff.
I have a start value of &7EC7 - the byte at bottom left of the screen containing pixels (x,y) = (0,0) (1,0) (2,0) (3,0), at 'number', low byte, high byte as expected and you can see from the snippet below. The loop that decreases the value by 1 each time works fine, then for the eigth step which is a step of 313 (320 bytes per line as per the memory layout used in the Beeb), I do the following, as the odd one is already dealt to in my singles loop - sloppy, but I'm not to worried about elegance right now, I only have to reduce it by 312.
Code:
lda number ; get low byte
sec ; set carry <the obvious place>
sbc #&38 ; subtract 56
sta number ; store new low byte
lda number+1 ; grab high byte
sbc #1 ; subtract 1 (+ 1 if there was a carry above)
sta number+1 ; store new high byte
(My appologies for the kiddie comments, I don't usually comment individual instructions, just looking real hard at what is going on now).
My problem seems to be that if 'number' contains 0, the first subtract does not appear to unset the carry flag so that the second SBC will add 1 + NOT(C). Checking for negative fails too - I've tried right down to inserting 'cmp #0:bne skip:dec number+1:skip' at the obvious place, and I know that the cmp is superfluous...
I have a BASIC program to focus on the table generation - it was the easiest way for me to see what was going on. I've attached a copy for you to download and laugh at. Slight difference is that for this one it double steps (every two lines) while I was playing with alterations to responses to flags and working out if there was something strange going on in BeebEm - there is not, it's me.
This is for a horizontal line drawing routine rather than a sprite plotter - I can draw the lines fine, and other things I thought were more complex at the time, now I am just going round in circles with this simple stuff
Some guidance would be greatly appreciated - and let me know where I've been a fool so I'll try harder next time.
Thanks.