Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
1,354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Given a screen address, returns the same position on the previous (higher
  2. ; on-screen) scanline.
  3. ;
  4. ; Spectrum screen memory addresses have the form:
  5. ;
  6. ; +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
  7. ; | 15 | 14 | 13 | 12 | 11 | 10 |  9 |  8 |  7 |  6 |  5 |  4 |  3 |  2 |  1 |  0 |
  8. ; |  0 -  1 -  0 | Y7 - Y6 | Y2 - Y1 - Y0 | Y5 - Y4 - Y3 | X4 - X3 - X2 - X1 - X0 |
  9. ; +--------------+---------+--------------+--------------+------------------------+
  10. ;
  11. ; To calculate the address of the previous scanline (that is, the scanline
  12. ; higher up) we test two of the fields in sequence and subtract accordingly:
  13. ;
  14. ; Y2-Y1-Y0: If this field is non-zero it's an easy case: we can just decrement
  15. ;           the top byte (e.g. using DEC H). Only the bottom three bits of Y
  16. ;           will be affected.
  17. ;
  18. ; Y5-Y4-Y3: If this field is zero we can add $FFE0 (-32) to HL. This is like
  19. ;           adding "-1" to the field from bits 5 upwards. Since Y2-Y1-Y0 and
  20. ;           Y5-Y4-Y3 are both zero here we don't care about bits propagating
  21. ;           across boundaries.
  22. ;
  23. ;           Otherwise we add $06E0 (0000 0110 1110 0000) to HL. This will add
  24. ;           "-1" to the Y5-Y4-Y3 field, which will carry out into Y0 for all
  25. ;           possible values. Simultaneously it adds "-1" to the Y2-Y1-Y0 field
  26. ;           - which is zero - so the complete field becomes 111. Thus the
  27. ;           complete field is decremented.
  28. ;
  29. ; Used by the routine at wave_morale_flag.
  30. ;
  31. ; I:HL Original screen address.
  32. ; O:HL Updated screen address.
  33. get_prev_scanline:
  34.   LD A,H            ; If Y2-Y1-Y0 zero jump to the complicated case
  35.   AND $07           ;
  36.   JR Z,complicated  ;
  37. ; Easy case.
  38.   DEC H             ; Just decrement the high byte of the address to go back a
  39.                     ; scanline
  40.   RET               ; Return
  41. ; Complicated case.
  42. complicated:
  43.   LD DE,$06E0       ; Load DE with $06E0 by default
  44.   LD A,L            ; Is L < 32?
  45.   CP $20            ;
  46.   JR NC,lt_32       ; Jump if not
  47.   LD D,$FF          ; If so bits Y5-Y4-Y3 are clear. Load DE with $FFE0 (-32)
  48. lt_32:
  49.   ADD HL,DE         ; Add
  50.   RET               ; Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement