home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / mbug / mbug120.arc / PASCAL.LBR / PIXELS.PZS / PIXELS.PAS
Pascal/Delphi Source File  |  1979-12-31  |  10KB  |  197 lines

  1. { File PIXELS :  sets, resets, inverts and tests pixels }
  2. { on a 160 x 72 pixel graphic screen on a Microbee only. }
  3. { Used by all line, arc and region filling procedures. }
  4. { Requires Include file LORES , ie will not run on its own. }
  5. { Written partly in Turbo Pascal and partly in Z80 machine language "Inline". }
  6. { Version 1.1  24.3.85   K OHare }
  7. { Version 1.2  13.4.85   K OHare }
  8. {.PL59}
  9. {.PA}
  10.  
  11. Procedure Setpixel (x,y: byte) ;
  12.  
  13. var
  14. row, column, bit, mask, m, n,
  15. old_character, new_character : byte;
  16.  
  17. address : integer;
  18.  
  19. begin
  20.      row := divthree[y];  column := divtwo[x];
  21.      bit := modtwo[x] + modthree[y] + modthree[y];
  22.      mask := twopower[bit] + 128;
  23.  
  24.  { Get character from screen and process }
  25. {     address := screen_start + row*80 + column;      }
  26. {     old_character := mem[address];                  }
  27. {                                                     }
  28. {     if old_character < 128 then old_character := 0; }
  29. {     new_character := old_character OR mask;         }
  30. {     mem[address] := new_character;                  }
  31.  
  32. Inline ( $26/$00/              { LD    H,0                                  }
  33.          $3A/row/              { LD    A,(row)                              }
  34.          $6F/                  { LD    L,A           ;HL := row             }
  35.          $44/                  { LD    B,H                                  }
  36.          $4D/                  { LD    C,L           ;BC := row             }
  37.          $29/                  { ADD   HL,HL         ;The next 7 lines      }
  38.          $29/                  { ADD   HL,HL         ;multiply row by 80    }
  39.          $09/                  { ADD   HL,BC         ;leaving the result    }
  40.          $29/                  { ADD   HL,HL         ;in HL.                }
  41.          $29/                  { ADD   HL,HL                                }
  42.          $29/                  { ADD   HL,HL                                }
  43.          $29/                  { ADD   HL,HL         ;HL := row x 80        }
  44.          $3A/column/           { LD    A,(column)                           }
  45.          $4F/                  { LD    C,A                                  }
  46.          $06/$00/              { LD    B,0                                  }
  47.          $09/                  { ADD   HL,BC         ;add column to 80xrow  }
  48.          $01/screen_start/     { LD    BC,screen_start                      }
  49.          $09/                  { ADD   HL,BC         ;and add screen base   }
  50.          $7E/                  { LD    A,(HL)        ;get old_character     }
  51.          $CB/$7F/              { BIT   7,A           ;Is it ROM or PCG?     }
  52.          $20/$01/              { JR    NZ,+1         ;If ROM then           }
  53.          $AF/                  { XOR   A             ;set old_character :=0 }
  54.          $4F/                  { LD    C,A                                  }
  55.          $3A/mask/             { LD    A,(mask)                             }
  56.          $47/                  { LD    B,A                                  }
  57.          $79/                  { LD    A,C                                  }
  58.          $B0/                  { OR    B             ;old_character OR mask }
  59.          $77)                  { LD    (HL),A        ;new_character         }
  60.  
  61. end;  { Procedure Setpixel }
  62. {.PA}
  63.  
  64. Procedure reset_pixel( x,y : byte);
  65.  
  66. var
  67. row, column, bit, mask, m, n,
  68. old_character, new_character : byte;
  69.  
  70. address : integer;
  71.  
  72. begin
  73.      row := divthree[y];  column := divtwo[x];
  74.      bit := modtwo[x] + modthree[y] + modthree[y];
  75.      mask := twopower[bit] + 128;
  76.  
  77.  { Get character from screen and process }
  78. {     address := screen_start + row*80 + column;}
  79. {     old_character := mem[address];}
  80.  
  81. {     if old_character < 128 then old_character := 0;}
  82. {     new_character := (old_character AND (NOT mask)) OR 128;}
  83. {     mem[address] := new_character;}
  84.  
  85. Inline ( $26/$00/              { LD    H,0                                  }
  86.          $3A/row/              { LD    A,(row)                              }
  87.          $6F/                  { LD    L,A           ;HL := row             }
  88.          $44/                  { LD    B,H                                  }
  89.          $4D/                  { LD    C,L           ;BC := row             }
  90.          $29/                  { ADD   HL,HL         ;The next 7 lines      }
  91.          $29/                  { ADD   HL,HL         ;multiply row by 80    }
  92.          $09/                  { ADD   HL,BC         ;leaving the result    }
  93.          $29/                  { ADD   HL,HL         ;in HL.                }
  94.          $29/                  { ADD   HL,HL                                }
  95.          $29/                  { ADD   HL,HL                                }
  96.          $29/                  { ADD   HL,HL         ;HL := row x 80        }
  97.          $3A/column/           { LD    A,(column)                           }
  98.          $4F/                  { LD    C,A                                  }
  99.          $06/$00/              { LD    B,0                                  }
  100.          $09/                  { ADD   HL,BC         ;add column to 80xrow  }
  101.          $01/screen_start/     { LD    BC,screen_start                      }
  102.          $09/                  { ADD   HL,BC         ;and add screen base   }
  103.          $7E/                  { LD    A,(HL)        ;get old_character     }
  104.          $CB/$7F/              { BIT   7,A           ;Is it ROM or PCG?     }
  105.          $20/$01/              { JR    NZ,+1         ;If ROM then           }
  106.          $AF/                  { XOR   A             ;set old_character :=0 }
  107.          $4F/                  { LD    C,A                                  }
  108.          $3A/mask/             { LD    A,(mask)                             }
  109.          $2F/                  { CPL                 ;A := NOT MASK         }
  110.          $47/                  { LD    B,A                                  }
  111.          $79/                  { LD    A,C                                  }
  112.          $A0/                  { AND   B             ;old_character AND mask}
  113.          $77)                  { LD    (HL),A        ;new_character         }
  114.  
  115. end;  { Procedure reset_pixel }
  116. {.PA}
  117.  
  118. Function Test_pixel (x,y : byte) : boolean;
  119.  
  120. var
  121. row, column, bit, mask, m, n,
  122. old_character, new_character : byte;
  123.  
  124. address : integer;
  125.  
  126. begin
  127.      row := divthree[y];  column := divtwo[x];
  128.      bit := modtwo[x] + modthree[y] + modthree[y];
  129.      mask := twopower[bit] + 128;
  130.  
  131.  { Get character from screen and process }
  132.      address := screen_start + row*80 + column;
  133.      old_character := mem[address];
  134.  
  135.      if old_character < 128 then old_character := 0;
  136.      new_character := old_character AND mask;
  137.      if new_character = 0 then test_pixel := false  { pixel not set }
  138.                           else test_pixel := true;  { pixel set }
  139.  
  140. end;  { Function test_pixel }
  141. {.PA}
  142.  
  143. Procedure invert_pixel (x,y : byte);
  144.  
  145. var
  146. row, column, bit, mask, m, n,
  147. old_character, new_character : byte;
  148.  
  149. address : integer;
  150.  
  151. begin
  152.      row := divthree[y];  column := divtwo[x];
  153.      bit := modtwo[x] + modthree[y] + modthree[y];
  154.      mask := twopower[bit] + 128;
  155.  
  156.  { Get character from screen and process }
  157. {     address := screen_start + row*80 + column;}
  158. {     old_character := mem[address];}
  159.  
  160. {     if old_character < 128 then old_character := 0;}
  161. {     new_character := (old_character XOR mask) OR 128;}
  162. {     mem[address] := new_character;                     }
  163.  
  164.  
  165. Inline ( $26/$00/              { LD    H,0                                  }
  166.          $3A/row/              { LD    A,(row)                              }
  167.          $6F/                  { LD    L,A           ;HL := row             }
  168.          $44/                  { LD    B,H                                  }
  169.          $4D/                  { LD    C,L           ;BC := row             }
  170.          $29/                  { ADD   HL,HL         ;The next 7 lines      }
  171.          $29/                  { ADD   HL,HL         ;multiply row by 80    }
  172.          $09/                  { ADD   HL,BC         ;leaving the result    }
  173.          $29/                  { ADD   HL,HL         ;in HL.                }
  174.          $29/                  { ADD   HL,HL                                }
  175.          $29/                  { ADD   HL,HL                                }
  176.          $29/                  { ADD   HL,HL         ;HL := row x 80        }
  177.          $3A/column/           { LD    A,(column)                           }
  178.          $4F/                  { LD    C,A                                  }
  179.          $06/$00/              { LD    B,0                                  }
  180.          $09/                  { ADD   HL,BC         ;add column to 80xrow  }
  181.          $01/screen_start/     { LD    BC,screen_start                      }
  182.          $09/                  { ADD   HL,BC         ;and add screen base   }
  183.          $7E/                  { LD    A,(HL)        ;get old_character     }
  184.          $CB/$7F/              { BIT   7,A           ;Is it ROM or PCG?     }
  185.          $20/$01/              { JR    NZ,+1         ;If ROM then           }
  186.          $AF/                  { XOR   A             ;set old_character :=0 }
  187.          $4F/                  { LD    C,A                                  }
  188.          $3A/mask/             { LD    A,(mask)                             }
  189.          $47/                  { LD    B,A                                  }
  190.          $79/                  { LD    A,C                                  }
  191.          $A8/                  { XOR   B             ;old_character XOR mask}
  192.          $F6/$80/              { OR    $80           ;make sure its a PCG   }
  193.          $E6/$BF/              { AND   $BF                                  }
  194.          $77)                  { LD    (HL),A        ;new_character         }
  195.  
  196. end;  { Procedure Invert_pixel }
  197.