home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / routines / plotxy.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  3.5 KB  |  90 lines

  1. ; A few improvements are noted below, toward the end, marked with "***".
  2. ; They have the staggering effect of reducing the length of the code by 4
  3. ; bytes.
  4.  
  5. ; I also made a note of an optional change which would reduce the code length
  6. ; by 2 more bytes, at the cost of 3 clock cycles in the clear-pixel case.
  7.  
  8. ; \\      Darryl Nester     \/ Assoc. Prof. of Mathematics //
  9. ; \\  nesterd@bluffton.edu  \/       Bluffton College      //
  10. ; \\    ph: 419-358-3483    \/   Bluffton, OH  45817-1196  //
  11.  
  12. ;*********************************************************
  13. ;                    plotxy
  14. ; Routine to turn on or off a single pixel.  Enter with reg BC
  15. ; containing the X,Y value, X = 0-127 Y = 0-63.
  16. ; X,Y origin (0,0) is lower left of screen.
  17. ; If reg A is zero, clear the pixel, if not zero, turn it on.
  18. ; Returns with HL pointing at the LCD byte, reg A containing the byte.
  19. ; BC and DE are preserved.
  20. ;*********************************************************
  21.  
  22.  
  23. plotxy:         push    de                      ;preserve reg
  24.                 push    af                      ;preserve on/off flag
  25.                 ld      a,7
  26.                 and     b                       ;get three LSbits in xpos
  27.  
  28. lookupref:      ld      hl,(PROGRAM_ADDR)
  29.                 ld      de,lookup8
  30.                 add     hl,de                   ;make it a ZSHELL relocate
  31.                 ld      d,0
  32.                 ld      e,a
  33.                 add     hl,de
  34.                 ld      l,(hl)                  ;translate into bit and
  35.                                                 ;preserve it in l
  36.                 ld      a,63
  37.                 sub     c                       ;invert ypos (63-0)
  38.                 ld      d,a
  39.                 ld      a,b                     ;xpos (0-127)
  40.  
  41.                 rlca                            ;double xpos, clear carry
  42.  
  43.                 srl     d
  44.                 rra
  45.                 srl     d
  46.                 rra
  47.                 srl     d
  48.                 rra
  49.                 srl     d
  50.                 rra                             ;16 bit shift right four bits
  51.                                                 ;through carry of da
  52.  
  53.                 ld      e,a                     ;de contains the
  54.                                                 ;offset into LCD mem
  55.                 pop     af
  56.                 and     a
  57.                 ld      a,l             ;*** does not affect flags
  58.                 ld      hl,$fc00        ;*** does not affect flags
  59.                 jr      nz,setpxl               ;if reg a nonzero, go set pixel
  60.                                                 ;zero, clear pixel
  61.                 cpl                             ;invert the byte
  62.                 add     hl,de                   ;point at correct byte
  63.                 and     (hl)                    ;clear the bit
  64. ;***
  65. ;*** Optional change
  66. ;*** replace the next three lines with the line
  67. ;***    .db $11
  68. ;***
  69.                 ld      (hl),a                  ;write it back.
  70.                 pop     de
  71.                 ret
  72.  
  73. setpxl:         add     hl,de                   ;point at correct byte
  74.                 or      (hl)                    ;set the bit
  75.                 ld      (hl),a                  ;write it out
  76.                 pop     de
  77.  
  78.                 ret
  79.  
  80. lookup8:        .db     128
  81.                 .db     64
  82.                 .db     32
  83.                 .db     16
  84.                 .db     8
  85.                 .db     4
  86.                 .db     2
  87.                 .db     1
  88.  
  89.  
  90.