;Copywrite 2000 Samuel Stearley sstear70@calvin.edu ;VERSION HISTORY OF THIS FILE: ;________________________________________________________ ;v1 -First release ;v1.1 -Second release, I found out that a68k was not ; optomizing certain brancing routines to the ; short form so I force it with the .s suffix. ;Rle stands for "Run Length Encoding" Imagine that an entire line ;of a picture you want to copy to the video memory is clear. ;So that line is really 30 zero bytes in a row. With rle that ;will condense into: A) a tag. B) the value to repeat. And ;C) the number of times to repeat it. That is 3 bytes instead ;of 30. So you really only get good compression with rle if ;there is a lot of white space on the screen. ;I based it on the z80 rle decompression routine by David Phillips ;that I found at tcpa.calc.org. Feel free to use it, but please ;thank me if you do. ;A RLE decompression routine written in C can be found in the ;bg_ source files of tichess. The code below is 32 bytes and ;I do not think that the C equivilent will be as small or as ;fast. But because the algorthym is very simple the speed ;differences will not be noticed. ;--------------------------------------------------- ;Inputs: ; d0- Size of buffer to decompress to minus one. ; a0- Pointer to the rle compressed data ; a1- Pointer to the buffer to decompress to. ;Destroys: ; d0,d1,d2,a0,a1 ;--------------------------------------------------- rle_loop: move.b (a0)+,d1 ;get next byte cmp.b #$91,d1 ;is it a run? beq.s decode_run ;then decode the run move.b d1,(a1)+ ;else store it to memory continue_rle: dbra d0,rle_loop rts decode_run: move.b (a0)+,d1 ;get byte to repeat move.b (a0)+,d2 ;get how many time to repeat continue_run: move.b d1,(a1)+ ;move it subq.b #1,d2 ;decrease run variable dbeq d0,continue_run ;go until the run is done or number of bytes is done beq.s continue_rle ;see if it was the run that was done or the number ; of bytes to decompress. If it was the run that ; ended then the last execution of the dbeq did not ; not decrement d0, but it still needs to be ; decremented. rts ;---------------------------------------------------------------------- ;---------------------------------------------------------------------- ;---------------------------------------------------------------------- ;This is an rle decompression routine that will decompress ;straight to the video memory. It takes into acount the ;fact that with the ti89 you have to skip 10 bytes to get ;to the next line of video memory. Just give it a pointer ;in a0 to the rle compressed picture. The compressed picture ;should be 160 by 100 pixels. It is optomized for size, not ;speed so the "check_line_end" function is not inlined. ;The rle decompression routine in the tichess code for the ;89 also takes into account the 10 bytes that needs to be ;skipped. ;It will destroy: d0,d1,d2,d3,a0,a1 lea LCD_MEM,a1 moveq #20,d3 ;----decompress picture to video memory---- move.w #1999,d0 ;decompress 2000 bytes rle_loop: move.b (a0)+,d1 ;get next byte cmp.b #$91,d1 ;is it a run? beq.s decode_run ;then decode the run move.b d1,(a1)+ ;else store it to video memory bsr.s check_line_end continue_rle: dbra d0,rle_loop rts decode_run: move.b (a0)+,d1 ;get byte to repeat move.b (a0)+,d2 ;get how many time to repeat continue_run: move.b d1,(a1)+ ;move it bsr.s check_line_end subq.b #1,d2 dbeq d0,continue_run ;go until the run is done or number of bytes is done beq.s continue_rle ;see if it was the run that was done or the number ; of bytes to decompress to. If it was the run that ; ended then the last execution of the dbeq did not ; not decrement d0, but it still needs to be ; decrimented. rts check_line_end: subq.w #1,d3 bne.s stay_on_line moveq #20,d3 lea 10(a1),a1 stay_on_line: rts