* = $801 basic byte 11,8,10,0,158,50,48,54,49,0,0,0 ;program "10 sys 2061" for autostart schermo = $4a0 scroll = $d016 sei ;disable interrupts (they are not required) lda #$00 tax sta flag sta row_count lda #$15 sta $d018 ;upper-case characters lda #$20 ;space character to clear the text screen ldy #$05 ;color for border sty $d020 iny ;color for background sty $d021 clear_loop sta $400,x ;clears screen and sprite pointers sta $500,x ;(no need to clear sprite pointers but this is sta $600,x ;to keep the code shorter) sta $700,x inx bne clear_loop lda #$01 ;sets characters colour to white clear_loop2 sta $d800,x ;writes to the color RAM (is useless to write to sta $d900,x ;unused locations $dbe8 - $dbff but again, this is sta $da00,x ;to keep the code shorter) sta $db00,x inx bne clear_loop2 lda #testo sta loop+2 lda #schermo sta matrix+2 zero_y ldy #$27 ;counter for one line of characters ($27 = 39 decimal) loop4 lda $d011 ;waits for raster out of viewable area bpl loop4 loop lda testo, y ;loads one character of textline in A beq end1 jmp matrix end1 jmp end matrix sta schermo, y ;stores character on screen memory dey ;the entire text line has been written? bpl loop ;if not, load the next character ldx #$c7 ;prepare maximum value of x scroll register lda flag ;do we have to fine scroll up or down? bne fine_up fine_down lda #$10 ;prepare y scroll to minimum (downwards) sta y_count jmp loop5 fine_up lda #$17 ;prepare y scroll to maximum (upwards) sta y_count loop5 stx scroll ;sets x scroll lda y_count sta $d011 ;set y scroll loop6 lda $d011 ;waits for raster on viewable area bmi loop6 dex ;prepares for next value of x scroll register lda flag ;are we moving up or down? bne next_val_up next_val_down inc y_count ;increment y_count to go down jmp loop2 next_val_up dec y_count ;decrement y_count to go up loop2 lda $d011 bpl loop2 ;wait for raster on non-viewable area again cpx #$bf ;have we done with x fine scrolling? bne loop5 ;if not, x fine scrolling again inc loop+1 ;now ready to coarse scroll the text (self modifying code ;that increments by one the location of the first character ;of the text that will be loaded) beq inc_hi ;if it wraps to zero, then increment high byte load_flag lda flag ;again, selects right code for moving up or down ;this code is needed to perform Y coarse scrolling bne row_up lda row_count ;have we reached the limit to the bottom of the screen? cmp #$0e beq switch_flag ;if that is the case, revert y movement jsr delete_row ;clear the old text line previously printed on the screen clc ;one row down lda matrix+1 ;adds $28 (40 decimal) to the address on the video matrix adc #$28 ;characters will be stored from (16 bit addition) sta matrix+1 lda matrix+2 adc #$00 sta matrix+2 inc row_count ;increments by one current row jmp zero_y row_up lda row_count ;have we reached the limit to the top of the screen? cmp #$04 beq switch_flag ;if that is the case, revert y movement jsr delete_row ;clear the old text line previously printed on the screen sec ;one row up lda matrix+1 ;subtracts $28 (40 decimal) to the address on the video matrix sbc #$28 ;characters will be stored from (16 bit subtraction) sta matrix+1 lda matrix+2 sbc #$00 sta matrix+2 dec row_count ;decrements by one current row jmp zero_y ;goes to coarse scroll again end lda #$c8 ;sets 40 columns mode sta scroll lda #$9b ;sets 25 lines mode sta $d011 cli rts inc_hi inc loop+2 ;increments high byte of location "testo" ;for self-modifying code jmp load_flag switch_flag lda flag eor #$01 ;flips flag (its value changes from 0 to 1 and viceversa, sta flag ;repeatedely) jmp zero_y ;resets y register to read another line of text delete_row lda matrix+1 ;self modifying code (it decides what row to delete) sta modify+1 lda matrix+2 sta modify+2 ldx #$27 lda #$20 modify sta schermo,x ;location schermo is dummy, as the code is dex ;self-modifying bpl modify rts testo scru " " scru "hello there! this is a very simple example of a smooth " scru "text scroller coded in assembly language. interrupts were " scru "not used so that the code is more clear. of course, interrupt " scru "handling can be added. i have tried to mimic the basic text " scru "scroller i posted some time ago for the sake of clarity. " scru "be sure to have fun with your commodore 64 and/or any " scru "retrocomputer you like! thank you for visiting! see you soon! " scru " marcello/retro64 blog. " scru " " scru "@" row_count byte 0 flag byte 0 y_count byte 0