V9958 scrolling. This got to be easier...

By Daemos

Paragon (2044)

Daemos의 아바타

11-02-2011, 20:17

Ok so lately I have been fidling around with the magic register 26 and 27 to obtain smooth per pixel scrolling and I have got it to work. Scrolls both right and left and it just looks very nice. However the amount of code I had to write to get this to work is ridicoulus. Tons of branching and comparing. This cannot be right. There has got to be a more efficient way to do this.

Please dont ask me why using the V9958 stuff because the awnser will be. I didn't go through hours of soldering and days of prepping to just NOT use these newly added registers WinkHannibal

so here is the code. Go ahaid and laugh at it and after you are finished doing that tell me what can be done to make this terror more easy. Wink


;wait until space is pressed for exit of left/right key for scrolling
WAIT:
        LD    HL,&HFBED
        LD    A,(HL)
        BIT   0,A
        RET   Z


        HALT ;to make the scrolling slow down a little bit

        LD    E,A

        BIT   4,A
        CALL  Z,SCROLL



        BIT   7,A
        CALL  Z,SCROLR



        JR    WAIT


;scroll to right
SCROLR:


        DI
        LD    HL,SCRLA
        LD    A,(HL)
        DEC   A
        LD    C,A
        CP    255
        CALL  Z,SCRSR
        LD    (HL),A
        OUT   (&H99),A
        LD    A,27+128
        OUT   (&H99),A


        LD    HL,SCRLB
        LD    A,(HL)
        OUT   (&H99),A
        LD    A,26+128
        OUT   (&H99),A
        EI

        LD    A,C ;did we reach 0??
        CP    0

        RET   NZ

SCRSR: ;yes then set the proper values

        LD    HL,SCRLB
        LD    A,(HL)
        INC   A
        LD    (HL),A
        LD    HL,SCRLA
        LD    (HL),8

        LD    HL,SCRLB
        LD    A,(HL)
        CP    64
        LD    C,0


        RET   NZ

        LD    (HL),0

        RET


;scrollen to left
SCROLL:

        DI

        LD    HL,SCRLA
        LD    A,(HL)
        INC   A
        CP    9
        CALL  Z,DECSC
        CP    8
        LD    (HL),A
        CALL  Z,DECSC

        LD    HL,SCRLB
        LD    A,(HL)
        OUT   (&H99),A
        LD    A,26+128
        OUT   (&H99),A



        LD    HL,SCRLA
        LD    A,(HL)

        LD    (HL),A
        OUT   (&H99),A
        LD    A,27+128
        OUT   (&H99),A
        EI

        SET   7,A ;secure arrow keys from strugling

        RET
DECSC:

        LD    (HL),A
        LD    HL,SCRLA
        LD    (HL),0


        LD    HL,SCRLB
        LD    A,(HL)
        DEC   A
        LD    (HL),A


        LD    HL,SCRLB
        LD    A,(HL)
        CP    0
        RET   NZ

        LD    (HL),64 ;register 26 limit reached

        RET

SCRLA:
        DB    8
SCRLB:
        DB    0

end


Login or 등록 to post comments

By Metalion

Paragon (1622)

Metalion의 아바타

11-02-2011, 21:12

It does not seem to me as a ridiculous amount of code ... Assembly is never a piece of cake !
After all, you do 2 routines, one to scroll right and one to scroll left.

Of course, it can be optimized, and you could gain some opcodes here and there, but apart from that, you've got the main idea.

To be honest, I don't really know how the 2 scroll registers from the V9958 work. So I might be missing an obvious optimization to feed them the correct values.

EDIT : I think that one way to optimize it would be to use only one scrolling routine, and to use it to scroll right or left depending on a variable that would either increase ($01) or decrease ($FF) your scroll registers.

By Daemos

Paragon (2044)

Daemos의 아바타

11-02-2011, 23:31


EDIT : I think that one way to optimize it would be to use only one scrolling routine, and to use it to scroll right or left depending on a variable that would either increase ($01) or decrease ($FF) your scroll registers.

Good point!! I didn´t think about that one. I could do the increase and decrease outside of the scrolling routine and therefore take care of the double routines eliminating the need for all kind of failsafe mechanisms which I had to utilise in this code.