Search code examples
assemblyc64

How to display alternate lines of text in 2 columns?


I have this part of code where all text lines come to the screen at once. Now I want for each lines to come on the screen from the other side (ie. first line from left, second from right etc.). Can anyone help?

Start                   SEI
                        LDX #$01
                        STX $0286
                        DEX
                        STX $D020
                        STX $D021
                        JSR $E544

mainLoop               LDA #$FA
waitRaster             CMP $D012
                        BNE waitRaster
waitRaster2            CMP $D012
                        BEQ waitRaster2

                        LDA #$0F
                        STA $D020
                        JSR UpdateThings
                        INC $D020
                        JMP mainLoop

UpdateThings        ; is state 0 ?
                        LDA State
                        BNE nextState
                    ; yes, call Move Text to Screen routine
                        JSR MoveTextIn
nextState              RTS

I tried with some change here..

MoveTextIn              LDX 02
                        LDY Counter
loop                   ; LDA TextLines1+(1*40),x
                       ; STA $0400+(1*40),X
                        LDA TextLines2+(1*40),y 
                        STA $0400+(1*40),X
                       ; LDA TextLines+(5*40),Y 
                       ; STA $0400+(5*40),X
                        INX 
                        INY
                        CPY #$28
                        BNE loop
and there....
                       ; LDX #$27
                        TXA
                        SEC 
                        SBC Counter
                        TAY

and again here...

loop2                   ;LDA TextLines1+(0*40),x
                        ;STA $0400+(0*40),X
                        LDA TextLines2+(0*40),y 
                        STA $0400+(0*40),X
                        ;LDA TextLines+(4*40),Y 
                        ;STA $0400+(4*40),X
                        DEX 
                        DEY
                        BPL loop2

                        LDA Counter
                        BEQ TextMoveDone

                        DEC Counter
                        RTS
TextMoveDone            INC State
                        RTS

State                   !byte 0

Counter                 !byte $10

TextLines1              !scr "!x-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-xx!"
TextLines2              !scr "!x      commodore master soft         x!"
                        !scr "!        -------------------           !"
                        !scr "!         somewhere in 2019.           !"
                        !scr "!          ----------------            !"
                        !scr "! -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-  !"

Solution

  • I'm copying my solution below. I think it is self explanatory.

    counter must be set to zero before jumping to MoveTextIn

    MoveTextIn
    shiftRight      ldx #$00
                    lda textLines1+(0*40),x
                    sta $0400+(0*40),x
                    lda textLines1(2*40),x
                    sta $0400+(2*40),x
                    lda textLines1(4*40),x
                    sta $0400+(4*40),x
    
                    inx
                    cmp #$40
                    bne shiftRight
    
    shiftLeft       lda textLines1+(1*40),x
                    sta $0400+(1*40),x
                    lda textLines1(3*40),x
                    sta $0400+(3*40),x
                    lda textLines1(5*40),x
                    sta $0400+(5*40),x
    
                    dex
                    bne shiftLeft
    
    copyRight       ldx counter
                    lda textLines1+(1*40),x
                    sta $0400+(1*40)-1
                    lda textLines1+(3*40),x
                    sta $0400+(3*40)-1
                    lda textLines1+(5*40),x
                    sta $0400+(5*40)-1
    
    copyLeft        sec
                    lda #$40
                    sbc counter
                    tax
                    lda textLines1+(0*40),x
                    sta $0400+(0*40)-1
                    lda textLines1+(2*40),x
                    sta $0400+(2*40)-1
                    lda textLines1+(4*40),x
                    sta $0400+(4*40)-1
    
                    inc counter
                    lda counter
                    cmp #$40
                    beq textMoveDone
                    rts
    
    textMoveDone    inc state
                    rts