home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_09_1986_Transactor_Publishing.d64
/
comp2.pal
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2023-02-26
|
5KB
|
233 lines
100 sys 700 ;activate pal 64 assembler
110 ; picture compressor
120 ; optimizes hi-res pic
130 ; and saves on disk
140 ; this version saves from memory
150 ; at $2000:
160 ; sys(*),"d:filename"
170 ; or loads to load addr:
180 ; sys(*+3),"filename"
190 ;
200 ; save"@0:comp2.pal",8
210 ;
220 .opt oo
230 *=$c000
240 ;
250 jmp compress
260 jmp decomp
270 ;
280 picture .word $2000 ;bitmap loc'n
290 repcount .byte 1 ;counts repetition
300 newbyt .byte 0 ;current mem byte
310 prevbyt .byte 0 ;previous byte
320 sendflag .byte 0 ;comp/decomp flag
330 banksav .byte 0 ;orig loc 1 value
340 endpic .word 0 ;end of bitmap
350 ;
360 piclen =8000 ;bitmap byte length
370 picptr =$fb
380 ;kernel routines:
390 setlfs =$ffba
400 setnam =$ffbd
410 open =$ffc0
420 chrout =$ffd2
430 getin =$ffe4
440 close =$ffc3
450 chkout =$ffc9
460 chkin =$ffc6
470 clrchn =$ffcc
480 readst =$ffb7
490 ;
500 compress =*
510 lda #1
520 sta sendflag
530 ldy #1 ;secondary address
540 bne cp1
550 ;
560 decomp =*
570 lda #0
580 sta sendflag
590 ldy #2 ;secondary address
600 cp1 =*
610 ;
620 lda 1 ;bank select reg
630 sta banksav ;store for later
640 lda #8 ;file #8
650 tax ;device #8
660 jsr setlfs ;open 8,8,1 or 2
670 jsr $aefd ;check for comma
680 jsr $ad9e ;evaluate expression
690 jsr $ad8f ;check for string
700 ldy #0
710 lda ($64),y ;string length
720 pha: iny
730 lda ($64),y ;string addr low
740 tax: iny
750 lda ($64),y ;string addr hi
760 tay: pla
770 jsr setnam ;filename=above string
780 jsr open ;open file
790 ldx #8 ;file #8 for chkin/out
800 ;
810 ldy #0
820 lda sendflag ;compress or load
830 beq nosnd ;nosnd=load
840 jsr chkout ;output to file
850 lda picture
860 jsr chrout ;start addr lo
870 lda picture+1
880 jsr chrout ;start addr hi
890 jsr sendpic ;send picture to file
900 jmp ss1 ;close files and exit
910 nosnd =*
920 jsr chkin ;get load addr first
930 jsr getin
940 sta picptr ;load addr lo
950 jsr getin
960 sta picptr+1 ;load addr hi
970 jsr getpic ;get picture
980 ss1 =*
990 ;
1000 jsr clrchn ;clear i/o channels
1010 lda #8
1020 jsr close ;close file #8
1030 rts ;all finished!
1040 ;
1050 ;
1060 sendpic =* ;compress picture
1070 lda picture ;start addr lo
1080 sta picptr
1090 clc
1100 adc #<piclen ;find last pic byte
1110 sta endpic ;last byte lo
1120 lda picture+1
1130 sta picptr+1 ;start addr hi
1140 adc #>piclen
1150 sta endpic+1 ;last byte hi
1160 ;
1170 jsr getbyt ;read byte from mem
1180 sta prevbyt ;initialize prev byte
1190 ldy #1 ;get 2nd byte next
1200 ;
1210 nextout =*
1220 jsr outbyte ;fetch byte or group
1230 ;
1240 lda picptr+1 ;see if at pic end
1250 cmp endpic+1
1260 bne sp1
1270 lda picptr
1280 cmp endpic
1290 bcc nextout ;do next byte
1300 rts
1310 sp1 =*
1320 bcc nextout ;do next byte
1330 jsr writerep ;write last group
1340 rts ;all bytes done
1350 ;
1360 ;
1370 outbyte =* ;check next byte
1380 jsr getbyt ;read byte from mem
1390 sta newbyt
1400 cmp prevbyt ;compare to previous
1410 bne diff ;different"?
1420 ;
1430 inc repcount ;same, inc count
1440 bne ok ;[177]255 repetiti[145]s"?
1450 dec repcount ;set to 255
1460 jsr writerep ;write repeat code
1470 lda #1 ;restart count
1480 sta repcount
1490 ok =*
1500 jmp obfin ;finished outbyte
1510 ;
1520 diff =* ;new byte different
1530 lda repcount ;check count
1540 cmp #4 ;3 or more the same"?
1550 bcs docode ;yes, s[128] rep code
1560 ;no, just [153] byte n times
1570 tax ;# reps [129] loop
1580 lda prevbyt ;byte [164] repeat
1590 cmp #254 ;ctrl byte"?
1600 beq docode ;yes, must code it
1610 ;
1620 nlp =* ;repeat loop
1630 lda prevbyt
1640 jsr chrout ;send byte
1650 dex ;do .x times
1660 bne nlp
1670 lda #1 ;restart count
1680 sta repcount
1690 jmp obfin ;finished subrtn
1700 ;
1710 docode =* ;write repeat code
1720 jsr writerep
1730 lda #1 ;restart count
1740 sta repcount
1750 ;
1760 obfin =*
1770 lda newbyt
1780 sta prevbyt ;prev=new
1790 inc picptr ;next address
1800 bne ob1
1810 inc picptr+1
1820 ob1 =*
1830 rts
1840 ;
1850 ;
1860 writerep =* ;write repeat code
1870 lda #254 ;special control byte
1880 jsr chrout
1890 lda prevbyt ;byte to repeat
1900 jsr chrout
1910 lda repcount ;number of reps
1920 jsr chrout
1930 rts
1940 ;
1950 ;
1960 getbyt =*
1970 sei ;disable interrupts
1980 lda 1 ;cpu bank register
1990 and #$fc ;select ram
2000 sta 1
2010 lda (picptr),y ;read byte
2020 pha
2030 lda banksav ;get original state
2040 sta 1 ;and restore
2050 cli
2060 pla
2070 rts
2080 ;
2090 ;
2100 getpic =* ;uncompress
2110 jsr getin
2120 cmp #254 ;rep indicator
2130 beq getrep
2140 ;normal byte, just store it
2150 sta (picptr),y
2160 inc picptr ;next address
2170 bne gr0
2180 inc picptr+1
2190 gr0 =*
2200 jmp gpfin
2210 ;
2220 getrep =*
2230 jsr getin ;byte to repeat
2240 pha
2250 jsr getin ;# of repetitions
2260 tax
2270 pla
2280 replp =* ;repeat byte n times
2290 sta (picptr),y
2300 inc picptr ;next address
2310 bne gr1
2320 inc picptr+1
2330 gr1 =*
2340 dex
2350 bne replp
2360 ;
2370 gpfin =*
2380 jsr readst ;read disk status
2390 beq getpic ;do until end-of-file
2400 rts
2410 .end