Advertisement
Zeda

Rectangle

Mar 10th, 2014
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Rectangle_erase:
  2.     ld hl,$A62F
  3.     jr Rectangle
  4. Rectangle_or:
  5.     ld hl,$B6
  6.     jr Rectangle
  7. Rectangle_xor:
  8.     ld hl,$AE
  9. Rectangle:
  10. ;    DE = (x,y)
  11. ;    BC = (height,width)
  12.     ld (smc_logic1),hl
  13.     ld (smc_logic0),hl
  14.     push de
  15.     push bc
  16.     push bc
  17.     ld a,d
  18.     call ComputeByte
  19.     ld (smc_FirstByte),a
  20.     ex (sp),hl
  21.     ld a,d
  22.     neg
  23.     and 7
  24.     ld b,a
  25.     ld a,l
  26.     sub b
  27.     ex (sp),hl
  28.     ld c,a
  29.     call ComputeByte
  30.     cpl
  31.     ld (smc_LastByte),a
  32.     ld b,a
  33.     sra c \ sra c \ sra c
  34.     inc c
  35. ;   ld a,c
  36. ;   and %11111000
  37. ;   rra \ rra \ rra
  38. ;   inc a
  39. ;   ld c,a
  40.  
  41.     ld a,d
  42.     ld d,0
  43.     ld h,d
  44.     ld l,e
  45.     add hl,hl
  46.     add hl,de
  47.     add hl,hl
  48.     add hl,hl
  49.     and %11111000
  50.     rra \ rra \ rra
  51.     add a,GBUF_LSB
  52.     ld e,a
  53.     ld d,GBUF_MSB
  54.     add hl,de
  55. ;HL points to the first byte   
  56.     pop de
  57. ;D is the height
  58. ;E is the number of bytes wide
  59.     inc c
  60.     dec c
  61.     jr nz,RectOverLoop-1
  62.         ld a,(smc_FirstByte)
  63.         and b
  64.         ld c,a      ;value
  65.         ld b,d      ;height
  66.         ld de,12
  67.             ld a,c
  68. smc_logic1:
  69.     nop
  70.             or (hl)
  71.             ld (hl),a
  72.             add hl,de
  73.             djnz $-5
  74.             pop bc
  75.             pop de
  76.             ret
  77.     ld e,c
  78. RectOverLoop:
  79.     ld b,e
  80.     ld c,12
  81.     .db 3Eh       ;start of ld a,*
  82. smc_FirstByte:
  83.     .db 0
  84. RectLoop:
  85. smc_logic0:
  86.     nop
  87.     or (hl)
  88.     ld (hl),a
  89.     inc hl
  90.     dec c
  91.     jr z,ExitLoop
  92.     ld a,-1
  93.     djnz RectLoop
  94. ;    jp p,$+4
  95. ;    dec b
  96.     .db 3Eh       ;start of ld a,*
  97. smc_LastByte:
  98.     .db 0
  99.     or (hl)
  100.     ld (hl),a
  101.     add hl,bc
  102. ExitLoop:
  103.     dec d
  104.     jr nz,RectOverLoop
  105.     pop bc
  106.     pop de
  107.     ret
  108.  
  109. ComputeByte:
  110.     and 7
  111.     ld b,a
  112.     ld a,80h
  113.     jr z,$+5
  114.       rrca
  115.       djnz $-1
  116.     add a,a
  117.     dec a
  118.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement