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