@@ -169,6 +169,7 @@ clear_bytes:
169169 jr nz , . 1
170170 ret
171171
172+ label XXX
172173tty_delete_line:
173174 ld a , (tty_cursory)
174175 cp SCREEN_HEIGHT - 1
@@ -185,22 +186,20 @@ tty_delete_line:
185186 sub b ; calculate number of text lines to move
186187 ld b , a
187188 ; 1
188- add a ; 0
189- add a ; 0
190189 add a
191190 add b ; 1
192- ld d , a ; b = number of scanlines to move
191+ ld d , a ; b = number of three-line chunks to move
193192
194- ld bc , - SCREEN_WIDTH
193+ ld bc , - ( SCREEN_WIDTH* 3 )
195194 add hl , bc ; compensate for preincrement in loop
196195. 1
197- ld bc , SCREEN_WIDTH * (CHAR_HEIGHT + 1 )
196+ ld bc , SCREEN_WIDTH * (CHAR_HEIGHT + 3 )
198197 add hl , bc
199- call read_scanline
198+ call read_chunk
200199
201200 ld bc , - (SCREEN_WIDTH * CHAR_HEIGHT)
202201 add hl , bc
203- call write_scanline
202+ call write_chunk
204203
205204 dec d
206205 jr nz , . 1
@@ -217,27 +216,26 @@ tty_insert_line:
217216 cp SCREEN_HEIGHT - 1
218217 jr z , on_last_line ; skip scroll if there's nothing to do
219218
220- ld hl , SCREEN_WIDTH * SCREEN_HEIGHT * CHAR_HEIGHT - SCREEN_WIDTH
219+ ; Source vdeo memory address.
220+ ld hl , SCREEN_WIDTH * SCREEN_HEIGHT * CHAR_HEIGHT - SCREEN_WIDTH * 3
221221
222222 ld b , a
223223 ld a , SCREEN_HEIGHT - 1
224224 sub b ; calculate number of text lines to move
225225 ld b , a
226226 ; 1
227- add a ; 0
228- add a ; 0
229227 add a
230228 add b ; 1
231- ld d , a ; b = number of scanlines to move
229+ ld d , a ; b = number of three-line chunks to move
232230
233231. 1
234- call read_scanline
232+ call read_chunk
235233
236234 ld bc , - (SCREEN_WIDTH * CHAR_HEIGHT)
237235 add hl , bc
238- call write_scanline
236+ call write_chunk
239237
240- ld bc , SCREEN_WIDTH * (CHAR_HEIGHT - 1 )
238+ ld bc , SCREEN_WIDTH * (CHAR_HEIGHT - 3 )
241239 add hl , bc
242240
243241 dec d
@@ -252,63 +250,49 @@ tty_insert_line:
252250 ld hl , SCREEN_WIDTH * 1 * CHAR_HEIGHT
253251 jp clear_bytes
254252
255- ; Loads the scanline at video memory address HL into the buffer.
256- read_scanline:
257- push hl
258- out0l PORT_VIDEO_ADDR_LO
259- out0h PORT_VIDEO_ADDR_HI
260- ld hl , video_buffer
261- out0l MAR1L
262- out0h MAR1H
263- ld a , 6
264- out0a MAR1B
265- ld hl , SCREEN_WIDTH
266- out0l BCR1L
267- out0h BCR1H
268- ld hl , PORT_VIDEO_DATA_R
269- out0l IAR1L
270- out0h IAR1H
253+ ; Loads the chunk at video memory address HL into the buffer.
254+ read_chunk:
255+ ld a , PORT_VIDEO_DATA_R
256+ call setup_dma
271257 ld a , 01000110b ; One memory wait state, 0 I/O wait state, I/O->memory
272258 out0a DCNTL
273259 ld a , 10010000b ; DE1 enable, DWE0 disable
274260 out0a DST AT ; perform the transfer
275-
276- . 1
261+ wait_for_dma_end:
277262 in0a DST AT
278263 and 10000000b ; test for DMA completion
279- jr nz , . 1
280-
281- pop hl
264+ jr nz , wait_for_dma_end
282265 ret
283266
284- ; Writes the scanline at video memory address HL from the buffer.
285- write_scanline:
286- push hl
287- out0l PORT_VIDEO_ADDR_LO
288- out0h PORT_VIDEO_ADDR_HI
289- ld hl , video_buffer
290- out0l MAR1L
291- out0h MAR1H
292- ld a , 6
293- out0a MAR1B
294- ld hl , SCREEN_WIDTH
295- out0l BCR1L
296- out0h BCR1H
297- ld hl , PORT_VIDEO_DATA_W
298- out0l IAR1L
299- out0h IAR1H
267+ ; Writes the chunk at video memory address HL from the buffer.
268+ write_chunk:
269+ ld a , PORT_VIDEO_DATA_W
270+ call setup_dma
300271 ld a , 01000100b ; One memory wait state, 0 I/O wait state, memory->I/O
301272 out0a DCNTL
302273 ld a , 10010000b ; DE1 enable, DWE0 disable
303274 out0a DST AT ; perform the transfer
275+ jr wait_for_dma_end
304276
305- . 1
306- in0a DST AT
307- and 10000000b ; test for DMA completion
308- jr nz , . 1
309-
277+ ; On entry: HL is the video memory address, and A is the I/O port.
278+ setup_dma:
279+ ld (scanline_dma + IAR1L - MAR1L) , a
280+ out0l PORT_VIDEO_ADDR_LO
281+ out0h PORT_VIDEO_ADDR_HI
282+ push hl
283+ ld b , scanline_dma.end - scanline_dma
284+ ld c , MAR1L
285+ ld hl , scanline_dma
286+ otimr
310287 pop hl
311288 ret
289+ scanline_dma:
290+ dw video_buffer ; MAR1
291+ db 0x06 ; MAR1B
292+ dw PORT_VIDEO_DATA_W ; IAR1
293+ db 0 ; unused
294+ dw SCREEN_WIDTH * 3 ; BCR1
295+ scanline_dma.end:
312296
313297toggle_cursor:
314298 ld de , (tty_cursorx)
@@ -348,7 +332,7 @@ CUROFF:
348332 ret
349333
350334video_buffer:
351- ds 91
335+ ds 91 * 3
352336
353337font_table:
354338 include "font.inc"
0 commit comments