Skip to content

Commit 3079647

Browse files
committed
Add back old scroll routines as Scroll...Aligned.
These are slightly faster and smaller, but operates aligned to columns.
1 parent 1c70ae1 commit 3079647

3 files changed

Lines changed: 868 additions & 2 deletions

File tree

src/lib/arch/zx48k/stdlib/scroll.bas

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,322 @@ EMPTYLINE:
717717
end asm
718718
end sub
719719

720+
721+
' ----------------------------------------------------------------
722+
' sub ScrollRightAligned
723+
' pixel by pixel right scroll.
724+
' scrolls 1 pixel right the window defined by (x1, y1, x2, y2)
725+
' This scroll is aligned to columns.
726+
' x1 and x2 are divided by 8 and rounded down (floor) to get the column number (0..31)
727+
' ----------------------------------------------------------------
728+
sub fastcall ScrollRightAligned(x1 as uByte, y1 as uByte, x2 as Ubyte, y2 as Ubyte)
729+
asm
730+
push namespace core
731+
732+
PROC
733+
LOCAL LOOP1
734+
LOCAL LOOP2
735+
736+
; a = x1
737+
pop hl ; RET address
738+
pop bc ; b = y1
739+
pop de ; d = x2
740+
ex (sp), hl ; h = y2, (sp) = RET address. Stack ok now
741+
742+
ld c, a ; BC = y1x1
743+
ld a, d
744+
sub c
745+
ret c ; x1 > x2
746+
747+
srl a
748+
srl a
749+
srl a
750+
inc a
751+
ld e, a ; e = (x2 - x1) / 8 + 1
752+
753+
ld a, h
754+
sub b
755+
ret c ; y1 > y2
756+
757+
inc a
758+
ld d, a ; d = y2 - y1 + 1
759+
760+
ld b, h ; BC = y2x1
761+
ld a, 191
762+
LOCAL __PIXEL_ADDR
763+
__PIXEL_ADDR EQU 22ACh
764+
call __PIXEL_ADDR
765+
res 6, h ; Starts from 0
766+
ld bc, (SCREEN_ADDR)
767+
add hl, bc ; Now current offset
768+
769+
LOOP1:
770+
push hl
771+
ld b, e ; C cols
772+
or a ; clear carry flag
773+
LOOP2:
774+
rr (hl)
775+
inc hl
776+
djnz LOOP2
777+
pop hl
778+
779+
dec d
780+
ret z
781+
call SP.PixelDown
782+
jp LOOP1
783+
ENDP
784+
785+
pop namespace
786+
end asm
787+
end sub
788+
789+
790+
' ----------------------------------------------------------------
791+
' sub ScrolLeftAligned
792+
' pixel by pixel left scroll
793+
' scrolls 1 pixel left the window defined by (x1, y1, x2, y2)
794+
' This scroll is aligned to columns.
795+
' x1 and x2 are divided by 8 and rounded down (floor) to get the column number (0..31)
796+
' ----------------------------------------------------------------
797+
sub fastcall ScrollLeftAligned(x1 as uByte, y1 as uByte, x2 as Ubyte, y2 as Ubyte)
798+
asm
799+
push namespace core
800+
801+
PROC
802+
LOCAL LOOP1
803+
LOCAL LOOP2
804+
805+
; a = x1
806+
pop hl ; RET address
807+
pop bc ; b = y1
808+
pop de ; d = x2
809+
ex (sp), hl ; h = y2, (sp) = RET address. Stack ok now
810+
811+
ld c, a ; BC = y1x1
812+
ld a, d
813+
sub c
814+
ret c ; x1 > x2
815+
816+
srl a
817+
srl a
818+
srl a
819+
inc a
820+
ld e, a ; e = (x2 - x1) / 8 + 1
821+
822+
ld a, h
823+
sub b
824+
ret c ; y1 > y2
825+
826+
ld c, d
827+
inc a
828+
ld d, a ; d = y2 - y1 + 1
829+
830+
ld b, h ; BC = y2x1
831+
ld a, 191
832+
LOCAL __PIXEL_ADDR
833+
__PIXEL_ADDR EQU 22ACh
834+
call __PIXEL_ADDR
835+
res 6, h ; Starts from 0
836+
ld bc, (SCREEN_ADDR)
837+
add hl, bc ; Now current offset
838+
839+
LOOP1:
840+
push hl
841+
ld b, e ; C cols
842+
or a ; clear carry flag
843+
LOOP2:
844+
rl (hl)
845+
dec hl
846+
djnz LOOP2
847+
pop hl
848+
849+
dec d
850+
ret z
851+
call SP.PixelDown
852+
jp LOOP1
853+
ENDP
854+
855+
pop namespace
856+
end asm
857+
end sub
858+
859+
860+
' ----------------------------------------------------------------
861+
' sub ScrolUpAligned
862+
' pixel by pixel up scroll
863+
' scrolls 1 pixel up the window defined by (x1, y1, x2, y2)
864+
' This scroll is aligned to columns.
865+
' x1 and x2 are divided by 8 and rounded down (floor) to get the column number (0..31)
866+
' ----------------------------------------------------------------
867+
sub fastcall ScrollUpAligned(x1 as uByte, y1 as uByte, x2 as Ubyte, y2 as Ubyte)
868+
asm
869+
push namespace core
870+
871+
PROC
872+
LOCAL LOOP1
873+
874+
; a = x1
875+
pop hl ; RET address
876+
pop bc ; b = y1
877+
pop de ; d = x2
878+
ex (sp), hl ; h = y2, (sp) = RET address. Stack ok now
879+
880+
ld c, a ; BC = y1x1
881+
ld a, d
882+
sub c
883+
ret c ; x1 > x2
884+
885+
srl a
886+
srl a
887+
srl a
888+
inc a
889+
ld e, a ; e = (x2 - x1) / 8 + 1
890+
ex af, af' ; save it for later
891+
892+
ld a, h
893+
sub b
894+
ret c ; y1 > y2
895+
896+
inc a
897+
ld d, a ; d = y2 - y1 + 1
898+
899+
ld b, h ; BC = y2x1
900+
ld a, 191
901+
LOCAL __PIXEL_ADDR
902+
__PIXEL_ADDR EQU 22ACh
903+
call __PIXEL_ADDR
904+
res 6, h ; Starts from 0
905+
ld bc, (SCREEN_ADDR)
906+
add hl, bc ; Now current offset
907+
908+
ld a, d ; Num. of scan lines
909+
ld b, 0
910+
exx
911+
ld b, a ; Scan lines counter
912+
ex af, af' ; Recovers cols
913+
ld c, a
914+
jp LOOP_START
915+
916+
LOOP1:
917+
exx
918+
ld d, h
919+
ld e, l
920+
ld c, a ; C cols
921+
call SP.PixelDown
922+
push hl
923+
ldir
924+
pop hl
925+
exx
926+
ld a, c ; Recovers C Cols
927+
LOCAL LOOP_START
928+
LOOP_START:
929+
djnz LOOP1
930+
931+
; Clears bottom line
932+
exx
933+
ld (hl), 0
934+
ld d, h
935+
ld e, l
936+
inc de
937+
ld c, a
938+
dec c
939+
ret z
940+
ldir
941+
ENDP
942+
943+
pop namespace
944+
end asm
945+
end sub
946+
947+
948+
' ----------------------------------------------------------------
949+
' sub ScrolDownAligned
950+
' pixel by pixel down scroll
951+
' scrolls 1 pixel down the window defined by (x1, y1, x2, y2)
952+
' This scroll is aligned to columns.
953+
' x1 and x2 are divided by 8 and rounded down (floor) to get the column number (0..31)
954+
' ----------------------------------------------------------------
955+
sub fastcall ScrollDownAligned(x1 as uByte, y1 as uByte, x2 as Ubyte, y2 as Ubyte)
956+
asm
957+
push namespace core
958+
959+
PROC
960+
LOCAL LOOP1
961+
962+
; a = x1
963+
pop hl ; RET address
964+
pop bc ; b = y1
965+
pop de ; d = x2
966+
ex (sp), hl ; h = y2, (sp) = RET address. Stack ok now
967+
968+
ld c, a ; BC = y1x1
969+
ld a, d
970+
sub c
971+
ret c ; x1 > x2
972+
973+
srl a
974+
srl a
975+
srl a
976+
inc a
977+
ld e, a ; e = (x2 - x1) / 8 + 1
978+
ex af, af' ; save it for later
979+
980+
ld a, h
981+
sub b
982+
ret c ; y1 > y2
983+
984+
inc a
985+
ld d, a ; d = y2 - y1 + 1
986+
987+
ld a, 191
988+
LOCAL __PIXEL_ADDR
989+
__PIXEL_ADDR EQU 22ACh
990+
call __PIXEL_ADDR
991+
res 6, h ; Starts from 0
992+
ld bc, (SCREEN_ADDR)
993+
add hl, bc ; Now current offset
994+
995+
ld a, d ; Num. of scan lines
996+
ld b, 0
997+
exx
998+
ld b, a ; Scan lines counter
999+
ex af, af' ; Recovers cols
1000+
ld c, a
1001+
jp LOOP_START
1002+
1003+
LOOP1:
1004+
exx
1005+
ld d, h
1006+
ld e, l
1007+
ld c, a ; C cols
1008+
call SP.PixelUp
1009+
push hl
1010+
ldir
1011+
pop hl
1012+
exx
1013+
ld a, c ; Recovers C Cols
1014+
LOCAL LOOP_START
1015+
LOOP_START:
1016+
djnz LOOP1
1017+
1018+
; Clears top line
1019+
exx
1020+
ld (hl), 0
1021+
ld d, h
1022+
ld e, l
1023+
inc de
1024+
ld c, a
1025+
dec c
1026+
ret z
1027+
ldir
1028+
1029+
ENDP
1030+
1031+
pop namespace
1032+
end asm
1033+
end sub
1034+
1035+
7201036
#pragma pop(case_insensitive)
7211037

7221038
REM the following is required, because it defines SCREEN_ADDR and SCREEN_ATTR_ADDR

0 commit comments

Comments
 (0)