Language…
8 users online: ClaudioPlays, GiraffeKiller, Graham, isaix, its_4life, Mega, Tsquare07, WONIU - Guests: 72 - Bots: 113
Users: 66,304 (2,253 active)
Latest user: ClaudioPlays

How to bring an 8-bit address in a 16-bit loop?

This is the code I wrote before. it work fine as intended.
Code
WindowingControl:
	LDY #$00
	LDX #$00
.loop01
	CPY !BoxYendRam
	BEQ .Draw01

	CPY !BoxYendRam
	BPL .NotDraw01

	CPY !BoxYstartRam
	BPL .Draw01

.NotDraw01
	LDA #$FF
	STA !WindowingRam,x
	LDA #$00
	STA !WindowingRam+1,x
	JMP .Skip01

.Draw01
	LDA !BoxXstartRam
	STA !WindowingRam,x
	LDA !BoxXendRam
	STA !WindowingRam+1,x
	JMP .Skip01

.Skip01
	INX #$02
	INY #$01
	CPY #$70
	BNE .loop01

	LDX #$00
.loop02
	CPY !BoxYendRam
	BEQ .Draw02

	CPY !BoxYendRam
	BPL .NotDraw02

	CPY !BoxYstartRam
	BPL .Draw02

.NotDraw02
	LDA #$FF
	STA !WindowingRam+224,x
	LDA #$00
	STA !WindowingRam+225,x
	JMP .Skip02

.Draw02
	LDA !BoxXstartRam
	STA !WindowingRam+224,x
	LDA !BoxXendRam
	STA !WindowingRam+225,x
	JMP .Skip02

.Skip02
	INX #$02
	INY #$01
	CPY #$E0
	BNE .loop02

	RTS


However, I thought this was inefficient, so I changed it as follows. But this code isn't work fine.

Code
WindowingControl:
	REP #$10
	LDY #$0000 : LDX #$0000
.loop
	CPY !BoxYendRam
	BEQ .Draw

	CPY !BoxYendRam
	BPL .NotDraw

	CPY !BoxYstartRam
	BPL .Draw				;It doesn't work

.NotDraw
	LDA #$FF
	STA !WindowingRam,x

	INX

	LDA #$00
	STA !WindowingRam,x

	JMP .Skip

.Draw
	LDA !BoxXstartRam
	STA !WindowingRam,x

	INX

	LDA !BoxXendRam
	STA !WindowingRam,x

	JMP .Skip

.Skip
	INY : INX
	CPX #$01C0
	BNE .loop

	SEP #$10

	RTS


You've got the index registers (X and Y) in 16-bit mode, but you're still comparing to the same free ram locations, which are presumably only 8-bit values, which won't work. You'd likely have to expand those to be 16-bit values as well, which may or may not be ideal. I'm having a little trouble following what this is supposed to be doing exactly, but there might be a cleaner overall approach as well, which I might be able to suggest to you with a little more detail.

Edit: I think I see what the code is doing here...give me a few and maybe I can come up with another idea for simplifying.
Here's another approach:

Code
WindowingControl:
    ldx #$00
    lda #$00 : xba
    rep #$10

    lda !BoxYStartRam
    beq +
    tay                       ; YStart lines
    rep #$20
    lda #$00FF                ; write FF 00
    jsr WriteWords
    lda #$0000
    sep #$20

+
    lda !BoxYEndRam
    sec : sbc !BoxYStartRam : inc  ; YEnd - Ystart + 1 lines...this must be >= 0 or it will break horribly
    beq +
    tay
    lda !BoxXEndRam : xba : lda !BoxXStartRam   ; you can make this a single lda after the rep #$20 if these addresses are guaranteed consecutive
    rep #$20
    jsr WriteWords
    lda #$0000
    sep #$20

+
    lda.b #223
    sec : sbc !BoxYEndRam     ; 223 - YEnd lines
    beq +
    tay
    rep #$20
    lda #$00FF
    jsr WriteWords

+
    sep #$30
    rts
    

; Writes the 16-bit value in A to !WindowingRam at the 16-bit offset in X, Y times (Y > 0!)
; updates the offset after exiting

WriteWords:
-
    sta !WindowingRam,x
    inx #2
    dey
    bne -
.Return
    rts


Rather than checking to see if the current line number is within a specific range every single time through the loop, this simply has a helper routine that writes a the same 16-bit value a specified number of times. This routine is called once for the region above the window, once within the window, and once more below it.

There are some tricks that could speed this up even more, but I think this is already a significant improvement.
Further simplifications could be made if you're willing to arrange your freeram to store the YStart/YEnd values as 16-bit, and the X values consecutively.
Thanks. This work fine.

This code seems to work too.
Code
TYA
CMP !RAM
BPL .Goto