home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1988 / 03 / doline.inc < prev    next >
Encoding:
Text File  |  1988-01-05  |  6.7 KB  |  139 lines

  1. {*********************************************************}
  2. {*                   DOLINE.INC                          *}
  3. {*                                                       *}
  4. {* Integer-DDA als Inline-Code für Z80 Turbo Pascal      *}
  5. {*    (C) Heinz Hagemeyer & PASCAL INTERNATIONAL         *}
  6.  
  7. PROCEDURE do_line (x1,y1,x2,y2  : INTEGER);
  8.  
  9. {Die in der Routine gebrauchten Z80-Codes
  10.  werden hier als Konstanten definiert :          }
  11. CONST           inc_bc    =  $03;
  12.                 inc_hl    =  $23;
  13.                 dec_bc    =  $0B;
  14.  
  15. BEGIN
  16.   INLINE
  17. (
  18.                  {  ;Fuer Normalfall (dx > dy und m > 0)   }
  19.                  {  ;Code's eintragen :                    }
  20. $3E/inc_bc/      {ld   a,inc_bc  ;Code inc bc ( y := y+1 ) }
  21. $32/*+129/       {ld   (incy),a  ;und                      }
  22. $3E/inc_hl/      {ld   a,inc_hl  ;Code inc hl ( x := x+1)  }
  23. $32/*+114/       {ld   (incx),a  ;auf Verdacht eintragen   }
  24.                  {  ;Ist x1 > x2, dann werden die          }
  25.                  {  ;beiden Punkte vertauscht :            }
  26. $ED/$5B/x1/      {ld   de,(x1)   ;dx :=  x2 - x1           }
  27. $2A/x2/          {ld   hl,(x2)   ;dx < 0  ?                }
  28. $97/             {sub  a                                   }
  29. $ED/$52/         {sbc  hl,de                               }
  30. $30/$1B/         {jr   nc,test_dy ;nein, dann teste dy     }
  31. $19/             {add  hl,de     ;ja, dann tausche         }
  32. $ED/$53/x2/      {ld   (x2),de   ;x1 mit x2                }
  33. $22/x1/          {ld   (x1),hl                             }
  34. $EB/             {ex   de,hl                               }
  35. $ED/$52/         {sbc  hl,de     ;dx :=  x1 - x2           }
  36. $ED/$4B/y1/      {ld   bc,(y1)   ;und tausche              }
  37. $ED/$5B/y2/      {ld   de,(y2)   ;y1 mit y2                }
  38. $ED/$53/y1/      {ld   (y1),de                             }
  39. $ED/$43/y2/      {ld   (y2),bc                             }
  40.                  {test_dy:       ;dy < 0 ?                 }
  41.  
  42. $E5/             {push  hl       ;dx retten                }
  43. $ED/$5B/y1/      {ld    de,(y1)  ;dy :=  y2 - y1           }
  44. $2A/y2/          {ld    hl,(y2)                            }
  45. $ED/$52/         {sbc   hl,de                              }
  46. $30/$09/         {jr    nc,dy_g_0 ;Wenn dy > 0 ,
  47.                                    dann Sprung ( m > 0 !)  }
  48.  
  49.                  {                ;sonst :                 }
  50. $19/             {add   hl,de     ;dy :=  y1 - y2          }
  51. $EB/             {ex    de,hl                              }
  52. $ED/$52/         {sbc   hl,de                              }
  53.                  {             Code in Routine aendern     }
  54. $3E/dec_bc/      {ld    a,dec_bc  ;dec bc (= y-1)          }
  55. $32/*+64/        {ld    (incy),a  ;eintragen               }
  56.  
  57.                  {dy_g_0                                   }
  58.  
  59. $D1/             {pop   de        ;de :=  dx               }
  60. $D5/             {push  de        ;dx retten               }
  61. $E5/             {push            ;dy retten               }
  62. $ED/$52/         {sbc   hl,d      ;hl :=  dy - dx          }
  63. $38/$0F/         {jr    c,weiter  ;Wenn dx>dy, dann Sprung }
  64.  
  65.                  {                ;sonst                   }
  66. $D1/             {pop   de        ;de :=  dy  |  tausche   }
  67. $E1/             {pop   hl        ;hl :=  dx  |  dx mit dy }
  68. $D5/             {push  de        ;dy retten  |  auf dem   }
  69. $E5/             {push  hl        ;dx retten  |  Stapel    }
  70.  
  71.                  {       und aendere Code's entsprechend   }
  72.  
  73. $3A/*+50/        {ld    a,(incy)  ;Code y+1 (oder y-1)     }
  74. $32/*+37/        {ld    (incx),a  ; statt x+1 und          }
  75. $3E/inc_hl/      {ld    a,inc_hl  ;Code x+1 statt y+1      }
  76. $32/*+42/        {ld    (incy),a  ;(oder y-1) in eintragen }
  77.  
  78.                  {  weiter                                 }
  79.  
  80. {****************************************************      }
  81. {*       2. Registersatz    1. Registersatz         *      }
  82. {*                                                  *      }
  83. {*        BC = DX   (DY)      HL = X                *      }
  84. {*        DE = DY   (DX)      BC = Y                *      }
  85. {*        HL = DSUM           DE = Steps            *      }
  86. {****************************************************      }
  87.  
  88. $D1/             {pop   de        ;de :=  dy (dx)          }
  89. $C1/             {pop   bc        ;bc :=  dx (dy)          }
  90. $C5/             {push  bc        ;rette steps 
  91.                                   ;(wegen 1. Registersatz!)}
  92. $60/             {ld    h,b       ;hl :=  dsum = dx/2      }
  93. $69/             {ld    l,c                                }
  94. $CB/$3C/         {srl   h                                  }
  95. $CB/$1D/         {rr    l                                  }
  96. $D9/             {exx             ;1. Registersatz !       }
  97. $2A/x1/          {ld    hl,(x1)                            }
  98. $ED/$4B/y1/      {ld    bc,(y1)                            }
  99. $D1/             {pop   de        ;steps holen             }
  100. $CD/STATUS/      {call  status    ;siehe Begleittext       }
  101.             { repeat              ;Punkt ausgeben          }
  102.  
  103. $D5/             {push  de        ;steps retten            }
  104. $C5/             {push  bc        ;y retten                }
  105. $E5/             {push  hl        ;x retten                }
  106. $CD/PUNKT+16/    {call  punkt + 16;BC = Y HL = X 
  107.                                   ; (Vergl. Begleittext)   }
  108. $E1/             {pop   hl        ;x holen                 }
  109. $C1/             {pop   bc        ;y holen                 }
  110. $D1/             {pop   de        ;steps holen             }
  111.  
  112.                  {incx:           ;Im Normalfall x :=  x+1 }
  113.  
  114. $23/             {inc   hl        ;hier wird Code 
  115.                                   ;eingetragen             }
  116. $D9/             {exx             ;2 Registersatz          }
  117. $19/             {add   hl,de     ;dsum :=  dsum + dy      }
  118. $ED/$42/         {sbc   hl,bc     ;dsum >= dx ?            }
  119. $38/$05/         {jr    c,step    ;nein, nur step in x     }
  120. $ED/$42/         {sbc   hl,bc     ;ja, dsum :=  dsum - dx  }
  121. $D9/             {exx             ;1. Registersatz         }
  122.  
  123.                  {incy:           ;im Normalfall y := y+1  }
  124.  
  125. $03/             {inc   bc        ;hier wird Code 
  126.                                   ;eingetragen             }
  127. $D9/             {exx             ;2. Registersatz         }
  128.  
  129.                  {step:                                    }
  130.  
  131. $09/             {add   hl,bc     ;Korrektur w. sbc hl,bc  }
  132. $D9/             {exx             ;1. Registersatz         }
  133. $1B/             {dec   de        ;steps := steps - 1      }
  134. $CB/$7A/         {bit   7,d       ;etwa negativ ?          }
  135. $28/$E4);        {jr    z,repeat  ;nein, dann noch'n Punkt }
  136.                  {                ;sonst fertig            }
  137.  
  138. END { do_line };
  139.