User Tools

Site Tools


base:rather_small_and_rather_fast_screen_offset_component_splitter
;  in: 10-bit value in hi.A
; out: x=input % 40
;      y=input / 40
;      a=clobbered
;
.proc splitOffset
         sta sm2+1
         lsr HI
         ror
         lsr HI
         ror
         lsr HI
         ror
         lsr HI
         ror
         lsr HI
         ror
         tax           ;x=in/32
         ldy divtab,x  ;y=x/1.25 = in/40 + rounding errors
         tya
         asl
         asl
         asl           ;a=y*8
         sta sm1+1
         asl
         asl           ;a=<(y*32)
         clc
sm1:     adc #$00      ;<(y*8+y*32) = <(y*40)
         sec
sm2:     sbc #$00      ;<(y*40-in)
         eor #$ff      ;<(in-y*40-1)
         tax           ;x=<(in-y*40-1)
         inx           ;x=<(in-y*40) = in%40 + rounding errors
         cpx #40       ;due to x/40 != int(x/32)/1.25 we might get a rounding error that we fix here
         bcc :+
            txa
            .byte $cb,40 ;axs/sbx #40
            iny
         :
         rts

divtab:  .byte $00,$00,$01,$02,$03,$04,$04,$05,$06,$07,$08,$08,$09,$0a,$0b,$0c,$0c,$0d,$0e,$0f,$10,$10,$11,$12,$13,$14,$14,$15,$16,$17,$18,$18
.endproc
base/rather_small_and_rather_fast_screen_offset_component_splitter.txt · Last modified: 2015-04-17 04:33 by 127.0.0.1