1000 ; RGB_COMPRESS›1010 ; by Clay Halliwell›1020 ; -----------------›1030 ; USR(addr,outdev#,width,height)›1040 ; (output: bytes written or›1050 ;  error code if <256)›1060 ;›1070 ; O.S. EQUATES›1080 ICCOM =$0342›1090 ICBAL =$0344›1100 ICBAH =$0345›1110 ICBLL =$0348›1120 ICBLH =$0349›1130 CIOV  =$E456›1140 FR0   =$00D4›1150 HPOS0 =$D000›1160 GRAFP0=$D00D›1170 PCOLR0=$2C0›1180 SAVMSC=$58›1190 ;›1200 ; CONSTANTS›1210 PUTCHR=$0B›1220 ;›1230 ; VARIABLES›1240 OUTDEV=218›1250 WIDTH =219›1260 HEIGHT=220›1270 COUNT =221›1280 SAME  =222›1290 STACK =223›1300 LAST  =224›1310 XCOR  =225›1320 YCOR  =226›1330 SX    =227›1340 SY    =228›1350 PX    =229›1360 PY    =230›1370 ADDR  =231›1380 ADDR2 =233›1390 NYBS  =235›1400 NYBBLE=236›1410 TYPE  =237›1420 INDEX =238›1430 PIX   =239›1440 PRVPIX=242›1450 ;›1460  *=$5F50›1470 ;›1480  PLA›1490  PLA›1500  PLA›1510  ASL A›1520  ASL A›1530  ASL A›1540  ASL A›1550  STA OUTDEV›1560  PLA›1570  PLA›1580  STA WIDTH›1590  PLA›1600  PLA›1610  STA HEIGHT›1620 ;›1630  TSX            ; save RTS addr›1640  STX STACK›1650 ;›1660  LDA #0›1670  STA XCOR›1680  STA YCOR›1690  STA FR0›1700  STA FR0+1›1710  STA LAST›1720  STA HPOS0›1730  STA NYBS›1740  STA NYBBLE›1750  LDA #3›1760  STA GRAFP0›1770  LDA #10›1780  STA PCOLR0›1790 ;›1800 SCANLITERAL›1810  JSR INIT›1820  LDA LAST›1830  BEQ SCLIT›1840  STA COUNT      ; value of LAST›1850  BNE WRITELITERAL›1860 SCLIT›1870  JSR GETPIX›1880  LDA SAME›1890  BEQ WRITELITERAL›1900  INC COUNT›1910  LDA COUNT›1920  CMP #22›1930  BEQ WRITELITERAL›1940  LDA LAST›1950  BEQ SCLIT›1960 ;›1970 WRITELITERAL›1980  JSR RESET›1990  LDA COUNT›2000  BEQ SCANREPEAT›2010  LDA #8         ; set LIT bit›2020  JSR PUTCOUNT›2030 LITLOOP›2040  JSR GETPIX›2050  LDX #0›2060  JSR PUTRGB›2070  DEC COUNT›2080  BNE LITLOOP›2090 ;›2100 ;›2110 SCANREPEAT›2120  JSR INIT›2130  LDA LAST›2140  BEQ SCREP›2150  JSR RESET›2160  JMP SCANLITERAL›2170 SCREP›2180  JSR GETPIX›2190  LDA SAME›2200  BNE WRITEREPEAT›2210  INC COUNT›2220  LDA COUNT›2230  CMP #22›2240  BEQ FALLTHRU›2250  LDA LAST›2260  BEQ SCREP›2270 ;›2280 FALLTHRU›2290  LDA XCOR›2300  STA PX›2310  LDA YCOR›2320  STA PY›2330 ;›2340 WRITEREPEAT›2350  LDA COUNT›2360  BNE REPDATA›2370  JSR RESET›2380  JMP SCANLITERAL›2390 REPDATA›2400  LDA #0         ; clr LIT bit›2410  JSR PUTCOUNT›2420  LDX #3›2430  JSR PUTRGB›2440 ;›2450  LDA PX›2460  STA XCOR›2470  LDA PY›2480  STA YCOR›2490  JMP SCANREPEAT›2500 ;›2510 ;›2520 INIT›2530  LDA #0›2540  STA COUNT›2550  LDA XCOR›2560  STA SX›2570  LDA YCOR›2580  STA SY›2590  LDA LAST›2600  BNE DONEXIT›2610  JSR GETPIX›2620  JSR NEWPRV›2630  RTS›2640 DONEXIT›2650  LDX STACK›2660  TXS›2670  LDA #0›2680  STA HPOS0›2690  JSR PUTNYB     ; dump buffer›2700  RTS›2710 ;›2720 RESET›2730  LDA SX›2740  STA XCOR›2750  LDA SY›2760  STA YCOR›2770  JSR CHKX       ; update LAST›2780  RTS›2790 ;›2800 GETPIX›2810  LDA #0›2820  STA SAME›2830  JSR NEWPRV›2840  LDX #2›2850  STX INDEX›2860 GLOOP›2870  LDX INDEX›2880  LDA SCREEN,X›2890  STA SAVMSC+1›2900  JSR LOCATE›2910  LDX INDEX›2920  STA PIX,X›2930  CMP PRVPIX,X›2940  BEQ GNEXT›2950  LDA #1›2960  STA SAME›2970 GNEXT›2980  DEC INDEX›2990  BPL GLOOP›3000  JSR BUMPCURSOR›3010  LDA PIX›3020  RTS›3030 ;›3040 NEWPRV›3050  LDA PIX›3060  STA PRVPIX›3070  LDA PIX+1›3080  STA PRVPIX+1›3090  LDA PIX+2›3100  STA PRVPIX+2›3110  RTS›3120 ;›3130 LOCATE›3140  LDA YCOR       ; new x40!›3150  TAY›3160  LSR A›3170  LSR A›3180  LSR A›3190  STA ADDR+1›3200  LSR A›3210  LSR A›3220  STA ADDR2+1›3230  TYA›3240  ASL A›3250  ASL A›3260  ASL A›3270  STA ADDR2›3280  ASL A›3290  ASL A›3300  STA ADDR›3310 ;›3320  CLC›3330  LDA ADDR›3340  ADC ADDR2›3350  STA ADDR›3360  LDA ADDR+1›3370  ADC ADDR2+1›3380  STA ADDR+1›3390 ;›3400  CLC            ; add scrnaddr›3410  LDA ADDR›3420  ADC SAVMSC›3430  STA ADDR›3440  LDA ADDR+1›3450  ADC SAVMSC+1›3460  STA ADDR+1›3470 ;›3480  LDA XCOR›3490  LSR A          ; /2›3500  PHP            ; save carry bit›3510  TAY›3520  LDA (ADDR),Y›3530  PLP            ; restore carry›3540  BCS SAVPIX     ; odd pixel›3550  LSR A›3560  LSR A›3570  LSR A›3580  LSR A›3590 SAVPIX›3600  AND #$0F       ; clr hi nybble›3610  RTS›3620 ;›3630 BUMPCURSOR›3640  LDA YCOR›3650  STA PY›3660  LDA XCOR›3670  STA PX›3680  INC YCOR       ; update X,Y›3690  LDA YCOR›3700  CMP HEIGHT›3710  BNE CHKX›3720  LDA #0›3730  STA YCOR›3740  INC XCOR›3750 ;›3760  LDA XCOR       ; column pointer›3770  ASL A›3780  CLC›3790  ADC #42›3800  STA HPOS0›3810 ;›3820 CHKX›3830  LDY #0›3840  LDA XCOR›3850  CMP WIDTH›3860  BNE LEXIT›3870  LDY #1›3880 LEXIT›3890  STY LAST›3900  RTS›3910 ;›3920 PUTCOUNT›3930  STA TYPE›3940  LDA COUNT›3950  CMP #7›3960  BCC TINYCOUNT›3970  LDA TYPE›3980  JSR PUTNYB›3990  SEC›4000  LDA COUNT›4010  SBC #7›4020  JSR PUTNYB›4030  RTS›4040 TINYCOUNT›4050  ORA TYPE›4060  JSR PUTNYB›4070  RTS›4080 ;›4090 PUTRGB›4100  STX INDEX›4110  LDA PIX+2,X›4120  JSR PUTNYB     ; put RED›4130  LDX INDEX›4140  LDA PIX+1,X›4150  JSR PUTNYB     ; put GRN›4160  LDX INDEX›4170  LDA PIX,X›4180  JSR PUTNYB     ; put BLU›4190  RTS›4200 ;›4210 PUTNYB›4220  BIT NYBS›4230  BMI NYBFULL›4240  ASL A›4250  ASL A›4260  ASL A›4270  ASL A›4280  STA NYBBLE›4290  LDA #128›4300  STA NYBS›4310  RTS›4320 NYBFULL›4330  ORA NYBBLE›4340  JSR PUT›4350  LDA #0›4360  STA NYBS›4370  INC FR0        ; bytes total›4380  BNE NDONE›4390  INC FR0+1›4400 NDONE›4410  RTS›4420 ;›4430 PUT›4440  PHA›4450  LDX OUTDEV›4460  LDA #PUTCHR›4470  STA ICCOM,X›4480  LDA #0›4490  STA ICBLL,X›4500  STA ICBLH,X›4510  PLA›4520  JSR CIOV›4530  BMI ERROR›4540  RTS›4550 ;›4560 ERROR›4570  LDX STACK›4580  TXS›4590  STY FR0        ; error code›4600  LDA #0›4610  STA FR0+1›4620  STA HPOS0›4630  RTS›4640 ;›4650 SCREEN›4660  .BYTE $41,$61,$81›