Z80 Routines:Graphic:Fastcopy

From WikiTI
Revision as of 09:58, 26 April 2005 by Jim e (Talk | contribs)

Jump to: navigation, search


The Fastcopy routine is used to copy the content of the Graph Buffer to the screen. It concerns all TI-z80 calculators, except TI-85 and TI-86, that has a special RAM area directly mapped to the screen.

Fastcopy is widely used, because the rom call _GrBufCpy waits too long between each output to the LCD driver. Using Fastcopy instead of _GrBufCpy increases significantly the speed of a program if it refreshes often the display (such as a lot of games). Most shells have this routine as built-in (ION, MirageOS, Venus ...).

Here is Joe Wingbermuehle's version, which is the one used in ION.

;-----> Copy the gbuf to the screen (fast)
;Input: nothing
;Output:graph buffer is copied to the screen
fastCopy:
 di
 ld a,$80
 out ($10),a
 ld hl,gbuf-12-(-(12*64)+1)
 ld a,$20
 ld c,a
 inc hl
 dec hl
fastCopyAgain:
 ld b,64
 inc c
 ld de,-(12*64)+1
 out ($10),a
 add hl,de
 ld de,10
fastCopyLoop:
 add hl,de
 inc hl
 inc hl
 inc de
 ld a,(hl)
 out ($11),a
 dec de
 djnz fastCopyLoop
 ld a,c
 cp $2B+1
 jr nz,fastCopyAgain
 ret


Remarks and Improvements

  • The di instruction is dispensable.
  • Some instructions in Joe Wingbermuehle's Fastcopy are only there for having enough delay between two outputs to the LCD driver. One can modify Fastcopy to change these useless instructions into instructions that will clear the Graph Buffer at the same time :
;-----> Copy the gbuf to the screen and clear graph buffer (fast)
;Input: nothing
;Output:graph buffer is copied to the screen and subsequently cleared
fastCopy:
 di
 ld a,$80
 out ($10),a
 ld hl,gbuf-12-(-(12*64)+1)
 ld a,$20
 ld c,a
 inc hl
 dec hl
fastCopyAgain:
 ld b,64
 inc c
 ld de,-(12*64)+1
 out ($10),a
 add hl,de
 ld de,11
fastCopyLoop:
 add hl,de
 inc hl
 inc de
 ld a,(hl)
 ld (hl),0    ; clears the graph buffer at the same time
 out ($11),a
 dec de
 djnz fastCopyLoop
 ld a,c
 cp $2B+1
 jr nz,fastCopyAgain
 ret

ld (hl),0 takes 10 cycles, so we can do with one less inc hl (6 cycles) and thus load 11 into de instead of 10.


Safe Copy

With the buggy lcd drivers and Silver Edition calculators speed, counting tstates can not always be reliable. So rather then assume that the LCD driver can accept an instruction, we can wait indefinately untill the driver is ready.

  • bit 1 of port 2 tells us that the lcd can accept an instruction
  • bit 7 of port 11 tells us that the lcd can accept an instruction

TI-OS and other apps generally use port 2 but being that bit 7 is sign bit we can use that as faster method of waiting.

;-----> Copy the gbuf to the screen, guaranteed 
;Input: nothing
;Output:graph buffer is copied to the screen, no matter the speed settings
;
;in (c) is an undefined instruction.
;You may have to add it in order for the routine to work.

 .addinstr IN	(C)	70ED	2	NOP	1

SafeCopy:	
	di
	ld c,$10
	ld a,$80
setrow:
	in (c)
	jp m,setrow
	out ($10),a
	ld hl,gbuf
	ld de,12
	ld a,$20
col:
	in (c)
	jp m,col
	out ($10),a
	ex af,af'
	ld b,64
row:
	ld a,(hl)
rowwait:
	in (c)
	jp m,rowwait
	out ($11),a
	add hl,de
	djnz row
	ex af,af'
	dec h
	dec h
	dec h
	inc hl
	inc a
	cp $2c
	jp nz,col
	ret