; ---------- NewValues NewChrs bytes cRows ; 25 NewCols bytes cRows OldValues bytes 255*cCombinedRows ; 50 ValueAnd bytes 255*cRows, 15*cRows Scheduler bytes cTotalUniqueRW ; 92 cRowCnt = cCombinedRows - 1 ScanValues ; Init Scheduler address lda #<Scheduler sta StoreToScheduler + 1 lda #>Scheduler sta StoreToScheduler + 2 ldx #0 @Loop lda NewValues,X beq @Next ; Marked as handled, so skip cmp OldValues,X beq @Next ; No difference, so skip ; Add to scheduler sta OldValues,X jsr StoreToScheduler ; Add the Load Value to Scheduler ; Search for duplicate Char and Colour Load Values txa tay jmp @Index ; Store index of New Value before search @SLoop lda NewValues,Y beq @Cont ; Marked as handled, so skip cmp OldValues,Y beq @Cont ; No difference, so skip ; Compare value with original and ValueAnd,Y cmp NewValues,X bne @Cont ; Mark NewValue as having been handled lda NewValues,Y sta OldValues,Y lda #0 sta NewValues,Y ; Add the Index Value to Scheduler tya @Index jsr StoreToScheduler @Cont iny cpy #cCombinedRows bne @SLoop ; Add Index Terminator to Scheduler lda #0 jsr StoreToScheduler @Next inx cpx #cCombinedRows bne @Loop ; Add Value Terminator to Scheduler lda #0 jmp StoreToScheduler StoreToScheduler @SMC sta $FFFF inc @SMC + 1 bne @Exit inc @SMC + 2 @Exit rts
that seems super complicated. this is the loop with (,x)
GroupValues ldx #255 stx GroupCount ldx #49 @Loop1 lda NewValues,X ; Get a value cmp OldValues,X ; Compare with old values beq @Next sta OldValues,X ; Modify OldValues tay lda GroupLinkPtr,Y ; sta GroupLinks,X ; Terminator or index bpl @Another ; Has it been encountered before? No = Bit7 ; store Current rX Index to GroupLinkStart. This is copied to the next group member's link table @New inc GroupCount ldy GroupCount txa sta GroupLinkStart,Y ldy NewValues,X ; Change Link at LinkPtr then put new index to LinkPtr @Another txa sta GroupLinkPtr,Y @Next dex bpl @Loop1
ldx #0 stx zCodePtr @Loop2 ldy GroupCount bmi @Cleanup ; No new chars dec GroupCount ldx GroupLinkStart,Y ldy NewValues,X ldx GroupLinkPtr,Y ; Most recent Link Index found for that group lda #255 sta GroupLinkPtr,Y ; Cleanup as we go ; -------------------- ; Write lda #nn ; ldy zCodePtr lda #cLDA_imm sta (zVecCode),Y iny lda NewValues,X sta (zVecCode),Y iny sty zCodePtr ;TestEndOfBuf prior to each STA @Loop2I ldy zCodePtr lda zCodeEOB + 1 bne @Cont ; HI > 0, so skip rest of test cpy zCodeEOB bmi @Cont ; LO < BufEnd, so exit (eg $4000 < $40FF) @Reset jsr CodeBufReset ldy zCodePtr ; -------------------- ; Write sta $nnnn ; @Cont lda #cSTA_x sta (zVecCode),Y iny lda RowLO,X sta (zVecCode),Y iny lda RowHI,X sta (zVecCode),Y iny sty zCodePtr lda GroupLinks,X ; Get index of next group element tax bpl @Loop2I jmp @Loop2 ; Cleanup @Cleanup ldy zCodePtr lda #cINX sta (zVecCode),Y iny lda #cRTS sta (zVecCode),Y sty zCodePtr