MCOPY convpic5.mac KEEP convpic convpicture START LCLA &LUP LONGA ON LONGI ON *-------------------------------------------------------------- * Convert v5.40 for ShowPic NDA v5.x by Dave Leffler * Converts 320 mode graphics screen to 640 mode * should retain approximate colors for normal 320 mode palette * or change to 16 level gray scale (semi-intelligent). *-------------------------------------------------------------- * Calling procedure (pascal): * * const * color = 0; * gray = 1; * mode320 = 2; * palette320 = 3; * mode640 = 4; * palette640 = 5; * * type * inparm = record * Pictptr : ptr; * color : integer; * end; * inparmptr = ^inparm; * function convpic(inparmptr):integer;extern; {returns error #} * * var inprm : inparm; * inptr : inparmptr; * converted : integer; * * inptr := @inprm; * inptr.Pictptr := graphiclocation; * inptr.color := gray; * converted := convpic(inptr); * *-------------------------------------------------------------- bytes_local EQU 4 # of bytes in local zero page OBJ $00 screen_ptr ds 4 OBJEND convpict ENTRY subroutine (4:parms_table),bytes_local PHB PHK PLB LDA [parms_table] STA screen_ptr LDY #2 LDA [parms_table],y STA screen_ptr+2 LDY #4 LDA [parms_table],y STA color JSR convcol longa on BCS anerror stz error anerror ANOP PLB Restore user data bank return 2:error Unwind the stack * Check for type of conversion convcol lda color asl a tax jsr (routines,x) ;do what the user wants bcs anerror1 rts anerror1 lda #$DA01 sta error rts Routines dc a'begincolor' dc a'begingray' dc a'setmode320' dc a'setpal320' dc a'setmode640' dc a'setpal640' dc a'anerror1' setmode320 anop lda #$7F7F ldy #$7d00 d0001 and [screen_ptr],y sta [screen_ptr],y iny iny cpy #$7e00 bne d0001 clc rts setmode640_1 anop ;640 mode palette 1 lda #$8080 ldy #$7d00 d0002 sta [screen_ptr],y iny iny cpy #$7e00 bne d0002 clc rts setmode640 anop lda #$8080 ldy #$7d00 d0003 ora [screen_ptr],y sta [screen_ptr],y iny iny cpy #$7e00 bne d0003 clc rts setpal320 jsr setmode320 ldx #0 ldy #$7e00 setpal320a lda color320,x set palette sta [screen_ptr],y inx inx iny iny cpx #$20 bne setpal320a clc rts setpal640 jsr setmode640_1 ldx #0 ldy #$7e00 setpal640a lda color640,x set palette sta [screen_ptr],y inx inx iny iny cpx #$20 bne setpal640a clc rts ; This is the routine for converting to gray scale ; The first part here combines the color bytes in ; the palette to come up with a luminence level begingray anop ldy #$7d00 lda [screen_ptr],y get current scb and #$8080 beq d2000 ;not 320 mode sec rts ; won't attempt to process d2000 jsr setmode640_1 ldx #0 short m again lda [screen_ptr],y ;Add R, G, & B together sta broken ; to come up with intensity and #$0f sta convrt lda broken lsr a lsr a lsr a lsr a clc adc convrt sta convrt iny lda [screen_ptr],y clc adc convrt sta oldpalette,x iny inx cpx #$10 bne again ; This part sorts and sets up an offset index for the color conversion ldx #0 lda #0 short i ;set indexes to short d022 sta tograyoffset,x ;set initial index factor inc a ; for sort inx cmp #$10 bne d022 ldy #0 d023 lda oldpalette,y tyx inx ;x = y + 1 d025 cmp oldpalette,x blt greaterthan lda oldpalette,y ;swap color values sta temp lda oldpalette,x sta oldpalette,y lda temp sta oldpalette,x lda tograyoffset,y ;swap index values sta temp lda tograyoffset,x sta tograyoffset,y lda temp sta tograyoffset,x lda oldpalette,y greaterthan inx cpx #$10 ;increment inner loop bne d025 iny cpy #$f ;increment outer loop bne d023 ; This part changes the palette to gray long m long i ldx #0 ldy #$7e00 d2002 lda gray640,x ;set palette to gray sta [screen_ptr],y inx inx iny iny cpx #$20 bne d2002 ; This part converts the picture lda #0 zero out accumulator tay short m d2003 lda [screen_ptr],y adjust screen colors sty picoffset short i sta broken and #$0f ldx #$ff d2007 inx cmp tograyoffset,x bne d2007 lda togray,x sta convrt lda broken lsr a lsr a lsr a lsr a ldx #$ff d2009 inx cmp tograyoffset,x bne d2009 lda togray,x asl a asl a asl a asl a ora convrt long i ldy picoffset sta [screen_ptr],y iny cpy #$7d00 bne d2003 clc long m rts ; This routine converts the picture from the 320 mode colors ; to 640 mode comparable colors. It makes every assumption ; that the normal 320 mode palette is being used. Due to the ; limitations of 640 mode only have 4 colors and 320 mode ; having 16 colors, it is impossible to convert most palettes ; but this works great for normal 320 mode pictures, especially ; Print Shop GS graphics (icons) begincolor anop ldy #$7d00 lda [screen_ptr],y get current scb and #$8080 beq d1000 ;not 320 mode sec rts ; won't attempt to process d1000 jsr setpal640 lda #0 zero out accumulator tay short m d1003 lda [screen_ptr],y adjust screen colors sta broken and #$0f tax lda tocolor,x sta convrt lda broken lsr a lsr a lsr a lsr a tax lda tocolor,x asl a asl a asl a asl a ora convrt sta [screen_ptr],y iny cpy #$7d00 bne d1003 long m clc rts * Below is a standard 640 mode palette color640 dc h'00 00 00 0f f0 00 ff 0f 00 00 0f 00 f0 0f ff 0f' dc h'00 00 00 0f f0 00 ff 0f 00 00 0f 00 f0 0f ff 0f' tocolor dc h'00 03 02 05 01 08 06 04 07 0e 0a 0d 05 09 0c 0f' gray640 dc h'00 00 33 03 66 06 ff 0f 00 00 aa 0a cc 0c ff 0f' dc h'00 00 33 03 66 06 ff 0f 00 00 aa 0a cc 0c ff 0f' togray dc h'00 04 08 01 02 05 06 09 0a 03 0c 07 0b 0d 0e 0f' color320 dc h'00 00 77 07 41 08 2c 07 0f 00 80 00 70 0f 00 0d' dc h'a9 0f f0 0f e0 00 df 04 af 0d 8f 07 cc 0c ff 0f' tograyoffset ds 16 oldpalette ds 16 picoffset ds 2 temp ds 1 color DS 2 error DS 2 broken ds 2 holds converted bytes convrt ds 2 holds color corrected bytes END