I'm trying to print some rows of a char from the top and bottom, first row turns out as expected but next one doesn't print. I add 40 chars to "Currentline" to get the prog to print the next row, well - that was what I thought would work. It won't print, but if I set "Currentline" to 40 from the start it prints on the next row.
What am I doing wrong?
/*
****************************************
* Really awesome code by Cri33e - 2022 *
****************************************
*/
*=$2000 // Startas med sys8192
.var ScreenCTop_Adress = $d7ff
.var ScreenCBottom_Adress = $dbbf
.var ScreenTop_Adress = $03ff
.var ScreenBottom_Adress = $07bf
.var Currentline = 0
.var Char_color = 3
.var HowManyRows = 4
Next_row:
lda #Char_color
ldy #20
ldx #40
loop1:
sta ScreenCTop_Adress+Currentline,x
sta ScreenCBottom_Adress-Currentline,x
tya
sta ScreenTop_Adress+Currentline,x
sta ScreenBottom_Adress-Currentline,x
lda #Char_color
dex
bne loop1
lda Currentline + 40
sta Currentline
ldx HowManyRows
dex
stx HowManyRows
bne Next_row
rts
enter code here
I see the following problems:
.vardirective does not do what you think it does (at least forCurrentlineandHowManyRows). I think it's just a preprocessing directive similar to#definein C. You should use the.DBdirective along with a memory label.lda Currentline + 40will not do what you think it will. It loads the accumulator with the value from the memory address specified byCurrentlineoffset by 40 bytes.sta ScreenCTop_Adress+Currentline,xwill not work. It will store the value in the accumulator at the address equal to theScreenCTop_Adress+ the address ofCurrentlineplus the value in X.Your code needs a significant rewrite in order to make it work, and because screen RAM and colour RAM are larger than 256 bytes each, it can't be done properly without using pointers in the zero-page and indirect addressing. However, just for the fun of it I'll attempt a rewrite that doesn't use the zero-page, since I don't know what portion of the zero-page is available to you. I'll also try to make it as similar to your code as possible, but a LOT needs to be changed. I warn you, the result will be ugly and by no means the right solution. Also, I'm not testing this.
EDIT: Thirty seconds after posting this answer, I thought of a much cleaner way of doing this, still without using the zero-page. I realized I could use inline pointers to the start of the row in screen RAM and colour RAM. This shortens the code considerably.