|
| 1 | +#PixelScroll |
| 2 | + |
| 3 | +# pixelScroll.bas |
| 4 | + |
| 5 | +Does what it says on the tin! Scrolls the screen by the set number of pixels, |
| 6 | +leaving blank pixel rows beyond it. Attributes are untouched. |
| 7 | + |
| 8 | +It's fast - it uses the screen tables method. You'll need the relevant screen tables |
| 9 | + files - https://dl.dropbox.com/u/4903664/ScreenTables.7z |
| 10 | + |
| 11 | +``` |
| 12 | +SUB PixelScrollUp(numOfLines as uByte) |
| 13 | +ASM |
| 14 | +; BLPixelTable is where the table starts |
| 15 | +
|
| 16 | +AND A ; Flags off A |
| 17 | +JP Z, BLPixelScrollUpEnd ; We were asked to scroll zero. Quit! |
| 18 | +CP 192 |
| 19 | +JP NC, BLPixelScrollUpEnd ; We can't scroll more than 191 lines up. Quit! |
| 20 | +
|
| 21 | +LD C,A ; Current Line |
| 22 | +LD B,A ; Jump |
| 23 | +PUSH BC ; Save Line count. |
| 24 | +
|
| 25 | +BLPixelScrollUpMainLoop: |
| 26 | +
|
| 27 | +; screen address routine |
| 28 | +LD H,BLPixelTable/256 |
| 29 | +LD L,C |
| 30 | +LD D,(HL) |
| 31 | +INC H |
| 32 | +LD E,(HL) ; DE is source address |
| 33 | +
|
| 34 | +;LD H,BLPixelTable/256 |
| 35 | +DEC H ; get H back to pixeltable. |
| 36 | +
|
| 37 | +LD A,C |
| 38 | +SUB B ; A is now destination line number |
| 39 | +LD L,A |
| 40 | +LD A,(HL) |
| 41 | +INC H |
| 42 | +LD L,(HL) ; HL: is destination line address |
| 43 | +LD H,A ; |
| 44 | +EX DE,HL ; Swap! ; HL=Source Address. DE=Dest address. |
| 45 | + |
| 46 | +
|
| 47 | +```; A small version has these two lines instead of the pile of LDI: |
| 48 | +; ld bc,32 ; 32 bytes to transfer |
| 49 | +; ldir |
| 50 | +
|
| 51 | +;(A very small version would calculate screen addresses, instead of use the table!) |
| 52 | +
|
| 53 | +; A fast version has these 32 LDIs instead: (About 27% faster) - but uses up 28 bytes more. |
| 54 | +LDI |
| 55 | +LDI |
| 56 | +LDI |
| 57 | +LDI |
| 58 | +LDI |
| 59 | +LDI |
| 60 | +LDI |
| 61 | +LDI |
| 62 | +LDI |
| 63 | +LDI |
| 64 | +LDI |
| 65 | +LDI |
| 66 | +LDI |
| 67 | +LDI |
| 68 | +LDI |
| 69 | +LDI |
| 70 | +LDI |
| 71 | +LDI |
| 72 | +LDI |
| 73 | +LDI |
| 74 | +LDI |
| 75 | +LDI |
| 76 | +LDI |
| 77 | +LDI |
| 78 | +LDI |
| 79 | +LDI |
| 80 | +LDI |
| 81 | +LDI |
| 82 | +LDI |
| 83 | +LDI |
| 84 | +LDI |
| 85 | +LDI |
| 86 | +
|
| 87 | +POP BC |
| 88 | +INC C |
| 89 | +LD A,C |
| 90 | +CP 192 |
| 91 | +PUSH BC ; Save count again. |
| 92 | +
|
| 93 | +JP C, BLPixelScrollUpMainLoop ; Not carry? then We hit the bottom of the screen. Need zeroes. |
| 94 | +
|
| 95 | +; blank remaining rows |
| 96 | +POP BC ; Balance Stack |
| 97 | +LD C,B ; Push diff into C |
| 98 | +LD A,192 |
| 99 | +SUB C ; A now shows row num of the top row to clear. |
| 100 | +CP 192 ; are we done |
| 101 | +JP Z,BLPixelScrollUpEnd |
| 102 | +LD D,0 |
| 103 | + |
| 104 | +BLPixelScrollUpClearBigLoop: |
| 105 | + |
| 106 | +LD H,BLPixelTable/256 |
| 107 | +LD L,A |
| 108 | +LD C,(HL) |
| 109 | +INC H |
| 110 | +LD L,(HL) |
| 111 | +LD H,C ; HL is current row |
| 112 | +LD B,32 ; 32 bytes |
| 113 | +BLPixelScrollUpClearLoop: |
| 114 | +LD (HL),D |
| 115 | +INC L |
| 116 | +DJNZ BLPixelScrollUpClearLoop |
| 117 | +
|
| 118 | +INC A |
| 119 | +CP 192 |
| 120 | + |
| 121 | +JP C, BLPixelScrollUpClearBigLoop |
| 122 | +JP BLPixelScrollUpEnd |
| 123 | +
|
| 124 | +END ASM |
| 125 | +#include once "ScreenTables.bas" |
| 126 | +ASM |
| 127 | +
|
| 128 | +BLPixelScrollUpEnd: |
| 129 | +END ASM |
| 130 | +END SUB |
| 131 | +``` |
| 132 | + |
| 133 | + |
| 134 | +## Usage |
| 135 | + |
| 136 | +Example: |
| 137 | + |
| 138 | +``` |
| 139 | +PixelScrollUp(2) |
| 140 | +``` |
| 141 | + |
| 142 | +Will scroll the screen up by 2 pixels. |
0 commit comments