|
| 1 | +.MODEL tiny |
| 2 | + |
| 3 | +.STACK 100h |
| 4 | + |
| 5 | +PALETTE_INDEX EQU 3c8h |
| 6 | +PALETTE_DATA EQU 3c9h |
| 7 | +INPUT_STATUS EQU 3dah |
| 8 | +HRETRACE EQU 01h |
| 9 | +VRETRACE EQU 08h |
| 10 | + |
| 11 | +.DATA |
| 12 | + bpos db 00 |
| 13 | + sine db 128,131,134,137,140,143,146,149 |
| 14 | + db 152,156,159,162,165,168,171,174 |
| 15 | + db 176,179,182,185,188,191,193,196 |
| 16 | + db 199,201,204,206,209,211,213,216 |
| 17 | + db 218,220,222,224,226,228,230,232 |
| 18 | + db 234,235,237,239,240,242,243,244 |
| 19 | + db 246,247,248,249,250,251,251,252 |
| 20 | + db 253,253,254,254,254,255,255,255 |
| 21 | + db 255,255,255,255,254,254,253,253 |
| 22 | + db 252,252,251,250,249,248,247,246 |
| 23 | + db 245,244,242,241,239,238,236,235 |
| 24 | + db 233,231,229,227,225,223,221,219 |
| 25 | + db 217,215,212,210,207,205,202,200 |
| 26 | + db 197,195,192,189,186,184,181,178 |
| 27 | + db 175,172,169,166,163,160,157,154 |
| 28 | + db 151,148,145,142,138,135,132,129 |
| 29 | + db 126,123,120,117,113,110,107,104 |
| 30 | + db 101,98,95,92,89,86,83,80 |
| 31 | + db 77,74,71,69,66,63,60,58 |
| 32 | + db 55,53,50,48,45,43,40,38 |
| 33 | + db 36,34,32,30,28,26,24,22 |
| 34 | + db 20,19,17,16,14,13,11,10 |
| 35 | + db 9,8,7,6,5,4,3,3 |
| 36 | + db 2,2,1,1,0,0,0,0 |
| 37 | + db 0,0,0,1,1,1,2,2 |
| 38 | + db 3,4,4,5,6,7,8,9 |
| 39 | + db 11,12,13,15,16,18,20,21 |
| 40 | + db 23,25,27,29,31,33,35,37 |
| 41 | + db 39,42,44,46,49,51,54,56 |
| 42 | + db 59,62,64,67,70,73,76,79 |
| 43 | + db 81,84,87,90,93,96,99,103 |
| 44 | + db 106,109,112,115,118,121,124,128 |
| 45 | + endSine db 00 |
| 46 | + cop1Pos dw 00 |
| 47 | + cop2Pos dw 00 |
| 48 | + cop3Pos dw 00 |
| 49 | + r db 00 |
| 50 | + g db 00 |
| 51 | + b db 00 |
| 52 | + |
| 53 | +.CODE |
| 54 | + ;used for keypress exit |
| 55 | + include STDFUNC.ASM |
| 56 | + |
| 57 | +MAIN PROC |
| 58 | + ;initialize the program |
| 59 | + mov ax,SEG _DATA |
| 60 | + mov ds, ax |
| 61 | + |
| 62 | + mov ax, 13h |
| 63 | + int 10h |
| 64 | + |
| 65 | +_loop: |
| 66 | + ;sine table offset pointer |
| 67 | + mov di, 00h |
| 68 | +__loop: |
| 69 | + ;read the sine from the sine list |
| 70 | + mov cx, word ptr [sine+di] ;set bar 2 to offset 0 in the sine lost |
| 71 | + mov [cop2Pos], cx ;store the bar begin pos in cop2Pos |
| 72 | + |
| 73 | + mov si, di |
| 74 | + add si, 20 ;set bar 1 to offset 20 in the sine list |
| 75 | + and si, 00ffh ;keep only lowest 8 bits (bar pos is 0-255) |
| 76 | + mov cx, word ptr [sine+si] ;read the bar begin pos from the sine list |
| 77 | + mov [cop1Pos], cx ;store the bar begin pos in var cop1Pos |
| 78 | + |
| 79 | + add si, 20 ;set bar 3 to offset 20 from cop1Pos in sine list |
| 80 | + and si, 00ffh ;keep only the lowest 8 bits (bar pos is 0-255) |
| 81 | + mov cx, word ptr [sine+si] ;store the bar beging pos from sine list |
| 82 | + mov [cop3Pos], cx ;stire the bar begin pos in var cop3Pos |
| 83 | + |
| 84 | + ;wait for the vertical retrace, then we can redraw the next frame |
| 85 | + call vertRetrace |
| 86 | + |
| 87 | + mov cx, 0h |
| 88 | +_lines: |
| 89 | + mov [r], 0 |
| 90 | + mov [g], 0 |
| 91 | + mov [b], 0 |
| 92 | + |
| 93 | + mov bx, [cop1Pos] |
| 94 | + call drawBar |
| 95 | + mov [r], al |
| 96 | + |
| 97 | + mov bx,[cop2Pos] |
| 98 | + call drawBar |
| 99 | + mov [b], al |
| 100 | + |
| 101 | + mov bx, [cop3Pos] |
| 102 | + call drawBar |
| 103 | + mov [g], al |
| 104 | + |
| 105 | + ;set the color as long as we are on the current line |
| 106 | + call setBarColor |
| 107 | + |
| 108 | + inc cx ;increment line count |
| 109 | + cmp cx, 350 |
| 110 | + jnz _lines |
| 111 | + sti |
| 112 | + |
| 113 | + ;if key pressed then exit |
| 114 | + call KeyPressExit |
| 115 | + |
| 116 | + ;Increment DI to point to the next entry in the sine list |
| 117 | + inc di |
| 118 | + cmp di, (endSine-sine) |
| 119 | + jnz _h3 |
| 120 | + jmp _loop |
| 121 | +_h3: |
| 122 | + jmp __loop |
| 123 | +MAIN ENDP |
| 124 | + |
| 125 | +; |
| 126 | +; @Desc: Wait for a vertical retrace of the electron beam |
| 127 | +; @Input: None |
| 128 | +; |
| 129 | +; @Globbers: dx, al |
| 130 | +; @Returns: None |
| 131 | + |
| 132 | +vertRetrace PROC |
| 133 | + ;wait for a vertical retrace |
| 134 | + cli |
| 135 | + mov dx, INPUT_STATUS |
| 136 | + |
| 137 | +_v1: in al, dx |
| 138 | + and al, VRETRACE |
| 139 | + jnz _v1 |
| 140 | + |
| 141 | +_v2: in al, dx |
| 142 | + and al, VRETRACE |
| 143 | + jz _v2 |
| 144 | + sti |
| 145 | + |
| 146 | + ret |
| 147 | +vertRetrace ENDP |
| 148 | + |
| 149 | +; |
| 150 | +; @Desc: Wait for a horizontal retrace of the electron beam |
| 151 | +; @Input: None |
| 152 | +; |
| 153 | +; @Globbers: dx, al |
| 154 | +; @Returns: None |
| 155 | +horizRetrace PROC |
| 156 | + ;wait for horizontal retrace |
| 157 | + cli |
| 158 | + mov dx, INPUT_STATUS |
| 159 | + |
| 160 | +_h1: in al, dx |
| 161 | + and al, HRETRACE |
| 162 | + jnz _h1 |
| 163 | + |
| 164 | +_h2: in al, dx |
| 165 | + and al, HRETRACE |
| 166 | + jz _h2 |
| 167 | + |
| 168 | + ret |
| 169 | +horizRetrace ENDP |
| 170 | + |
| 171 | +; |
| 172 | +; @Desc: Draw a shaded copper bar |
| 173 | +; @Input: BX start rasterline of the copper bar |
| 174 | +; CX current rasterline |
| 175 | +; @Globbers: AX |
| 176 | +; @Returns: Returns the shade of the bar in AL |
| 177 | +drawBar PROC |
| 178 | + and bx, 00ffh ;only keep low byte (sine goes from 0-255) |
| 179 | + cmp cx, bx ;is rasterline somewhere between our bar? |
| 180 | + jae bar ;yes? draw the bar line |
| 181 | + mov al,00h ;no? draw the black background |
| 182 | + ret |
| 183 | + bar: |
| 184 | + add bx, 30 ;draw a bar 30 lines wide |
| 185 | + cmp cx, bx |
| 186 | + jg colOff ;is scanline beyond the bar, then draw black |
| 187 | + jz barLastLine ;last line has a brighter tint but not ffh |
| 188 | + ;suggesting light from below the bar |
| 189 | + mov al, 0e0h |
| 190 | + sub bx,20 ;top shade brighter shade of the bar |
| 191 | + cmp cx, bx |
| 192 | + push cx |
| 193 | + jg subC |
| 194 | + sub cx, bx ;shade darker based of width |
| 195 | + add al, cl ;1byte move result to cl |
| 196 | + jmp short dcd |
| 197 | + subC: |
| 198 | + sub cx, bx |
| 199 | + sub al, cl |
| 200 | + dcd: |
| 201 | + pop cx ;restore line counter |
| 202 | + ret |
| 203 | + barLastLine: |
| 204 | + mov al,0d0h |
| 205 | + ret |
| 206 | + colOff: |
| 207 | + mov al,00h |
| 208 | + ret |
| 209 | +drawBar ENDP |
| 210 | + |
| 211 | +setBarColor PROC |
| 212 | + ;now set the color of the scan line to black |
| 213 | + mov dx, PALETTE_INDEX |
| 214 | + mov al, 00h |
| 215 | + out dx, al |
| 216 | + |
| 217 | + ;this is the current scanline so set the color not to black |
| 218 | + mov al, byte ptr [r] |
| 219 | + mov dx, PALETTE_DATA |
| 220 | + out dx, al |
| 221 | + |
| 222 | + mov al, byte ptr [g] |
| 223 | + mov dx, PALETTE_DATA |
| 224 | + out dx, al |
| 225 | + |
| 226 | + mov al, byte ptr [b] |
| 227 | + mov dx, PALETTE_DATA |
| 228 | + out dx, al |
| 229 | + ret |
| 230 | + |
| 231 | +SetBarColor ENDP |
| 232 | +END MAIN |
0 commit comments