Advertisement
Zeda

Rectangle_Erase

Mar 10th, 2014
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GBUF_LSB = 40h
  2. GBUF_MSB = 93h
  3.  
  4. Rectangle_erase:
  5. ;    DE = (x,y)
  6. ;    BC = (height,width)
  7. ;Uses 2 bytes of RAM: (FirstByte), (LastByte)
  8.     push de
  9.     push bc
  10.     push bc
  11.     ld a,d
  12.     call ComputeByte
  13.     cpl             ;used for WHITE
  14.     ld (FirstByte),a
  15.     ex (sp),hl
  16.     ld a,d
  17.     neg
  18.     and 7
  19.     jr nz,$+4
  20.     ld a,8
  21.     ld b,a
  22.     ld a,l
  23.     sub b
  24.     ex (sp),hl
  25.     ld c,a
  26.     call ComputeByte
  27. ;   cpl
  28.     ld (LastByte),a
  29.     ld b,a
  30.     sra c \ sra c \ sra c
  31.     inc c
  32.  
  33.     ld a,d
  34.     ld d,0
  35.     ld h,d
  36.     ld l,e
  37.     add hl,hl
  38.     add hl,de
  39.     add hl,hl
  40.     add hl,hl
  41.     and %11111000
  42.     rra \ rra \ rra
  43.     add a,GBUF_LSB
  44.     ld e,a
  45.     ld d,GBUF_MSB
  46.     add hl,de
  47. ;HL points to the first byte   
  48.     pop de
  49. ;D is the height
  50. ;E is the number of bytes wide
  51.     inc c
  52.     dec c
  53.     jr nz,RectOverLoop-1
  54.         ld a,(FirstByte)
  55.         or b
  56.         ld c,a      ;value
  57.         ld b,d      ;height
  58.         ld de,12
  59.             ld a,c
  60.             and (hl)
  61.             ld (hl),a
  62.             add hl,de
  63.             djnz $-4
  64.             pop bc
  65.             pop de
  66.             ret
  67.     ld e,c
  68. RectOverLoop:
  69.     ld b,e
  70.     ld c,12
  71.     ld a,(FirstByte)
  72. RectLoop:
  73.     and (hl)
  74.     ld (hl),a
  75.     inc hl
  76.     dec c
  77.     jr z,ExitLoop
  78.     xor a           ;should be 'ld a,255' for other modes
  79.     djnz RectLoop
  80.     ld a,(lastByte)
  81.     and (hl)
  82.     ld (hl),a
  83.     add hl,bc
  84. ExitLoop:
  85.     dec d
  86.     jr nz,RectOverLoop
  87.     pop bc
  88.     pop de
  89.     ret
  90.  
  91. ComputeByte:
  92.     and 7
  93.     ld b,a
  94.     ld a,80h
  95.     jr z,$+5
  96.       rrca
  97.       djnz $-1
  98.     add a,a
  99.     dec a
  100.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement