Difference between revisions of "Z80 Routines:Graphic:Fastcopy"
m (minor changes) |
m ("faster" fastcopy) |
||
Line 84: | Line 84: | ||
</nowiki> | </nowiki> | ||
− | '''ld (hl),0''' takes 10 cycles, so we can | + | '''ld (hl),0''' takes 10 cycles, so we can replace both '''inc hl''' (6 cycles) whit '''nop''' (4 cycles) and thus load 12 into de instead of 10. |
==Safe Copy== | ==Safe Copy== |
Revision as of 08:35, 6 November 2008
IonFastcopy
Warning: The routines presented below may fail on some calculators due to manufacturing defects. Before using any of the routines below, read the safecopy section below.
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
- 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 replace both inc hl (6 cycles) whit nop (4 cycles) and thus load 12 into de instead of 10.
Safe Copy
Many calculators recently manufactured by TI contained a buggy LCD driver, which had different (or varying) delays required to interface with it. Using the fast copy routines above with the LCDs will cause the LCD to display garbled information. However, we can do some additional hardware work to solve this problem, by waiting until we know the LCD is ready to accept a command:
- Bit 7 of Port 10 tells us that the lcd can accept an instruction
- SE Only: Bit 1 of Port 2 tells us that how long since the last lcd access
The 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 f,(c) is an unofficial instruction. ;It must be noted that you cannot specify any other register. Only f works. ;You may have to add it in order for the routine to work. ;if addinstr doesn't work, you may manually insert the opcodes .db 0EDh,070h .addinstr IN F,(C) 70ED 2 NOP 1 SafeCopy: di ;DI is only required if an interrupt will alter the lcd. ld hl,PlotSScreen ;This can be commented out or another entry placed after it ;so the buffer can be provided by option. ld c,$10 ld a,$80 setrow: in f,(c) jp m,setrow out ($10),a ld de,12 ld a,$20 col: in f,(c) jp m,col out ($10),a push af ld b,64 row: ld a,(hl) rowwait: in f,(c) jp m,rowwait out ($11),a add hl,de djnz row pop af dec h dec h dec h inc hl inc a cp $2c jp nz,col ret