UrForth: fixed some bugs, added simple benchmark
[urasm.git] / libs / mac_scrmac_fast.zas
blob44cf310b208119e8712abc1010cddb540000dc4f
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; AF is dead
3 ;; inreg and outreg can be the same, and even A itself
4 ;;
5 MACRO scr2attr_fast inregh, outregh=
6   IF marg2str(=inregh[0]) == "a"
7     ; do nothing
8   ELSE
9     ld    a,=inregh[0]
10   ENDIF
11   ;23t
12   or    #87       ; 7
13   rra             ; 4
14   rra             ; 4
15   srl   a         ; 8
16   ;26t
17   ;rrca            ; 4
18   ;rrca            ; 4
19   ;rrca            ; 4
20   ;and   #03       ; 7
21   ;or    #58       ; 7
22   IF marg2str(=outregh) != ""
23     IF marg2str(=outregh[0]) == "a"
24       ; do nothing
25     ELSE
26       ld    =outregh[0],a
27     ENDIF
28   ELSE
29     IF marg2str(=inregh[0]) == "a"
30       ; do nothing
31     ELSE
32       ld    =inregh[0],a
33     ENDIF
34   ENDIF
35 ENDM scr2attr_fast
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; AF is dead
40 ;; if "useret" is not zero, use "ret" instead of "jp/jr"
41 ;; if "useret" is negative, use "jr" instead of "jp"
43 MACRO scrdown_rr regpair, useret=0
44   inc   h
45   ld    a,h
46   and   #07
47   jp    nz,.save_downhlok
48   ld    a,l
49   sub   #E0
50   ld    l,a
51   sbc   a,a
52   and   #F8
53   add   a,h
54   ld    h,a
56   inc   =regpair[0]
57   ld    a,=regpair[0]
58   and   #07
59   IF =useret == 0
60     ret   nz
61   ELSEIF =useret < 0
62     jr    nz,c,..nofix
63   ELSE
64     jp    nz,c,..nofix
65   ENDIF
66   ld    a,=regpair[1]
67   sub   #e0
68   ld    =regpair[1],a
69   sbc   a,a
70   and   #f8
71   add   a,=regpair[0]
72   ld    =regpair[0],a
73 ..nofix:
74 ENDM scrdown_rr
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; AF is dead
79 ;; if "useret" is not zero, use "ret" instead of "jp/jr"
80 ;; if "useret" is negative, use "jr" instead of "jp"
82 MACRO scrup_rr regpair, useret=0
83   ld   a,=regpair[0]
84   dec  =regpair[0]
85   and  #07
86   IF =useret == 0
87     ret   nz
88   ELSEIF =useret < 0
89     jr    nz,c,..nofix
90   ELSE
91     jp    nz,c,..nofix
92   ENDIF
93   ld   a,=regpair[1]
94   sub  32
95   ld   =regpair[1],a
96   IF =useret == 0
97     ret   c
98   ELSEIF =useret < 0
99     jr    c,..nofix
100   ELSE
101     jp    c,..nofix
102   ENDIF
103   ld   a,=regpair[0]
104   add  a,8
105   ld   =regpair[0],a
106 ..nofix:
107 ENDM scrup_rr
110 MACRO scr_char_xy_rr regdest16, xr8, yr8
111   ld    a,=yr8
112   IF marg2str(=regdest16[0]) == marg2str(=yr8)
113     push  af
114   ENDIF
115   and   #18
116   or    #40
117   ld    =regdest16[0],a
118   IF marg2str(=regdest16[0]) == marg2str(=yr8)
119     pop   af
120   ELSE
121     ld    a,=yr8
122   ENDIF
123   rrca
124   rrca
125   rrca
126   and   #E0
127   or    =xr8
128   ld    =regdest16[1],a
129 ENDM scr_char_xy_rr
132 ; regdest16 should not overlap with xr8 or yr8
133 MACRO scr_pix_xy_rr regdest16, xr8, yr8
134   ld    a,=yr8
135   or    a
136   rra
137   scf
138   rra
139   or    a
140   rra
141   xor   =yr8
142   and   #F8
143   xor   =yr8
144   ld    =regdest16[0],a
145   ld    a,=xr8
146   rlca
147   rlca
148   rlca
149   xor   =yr8
150   and   #C7
151   xor   =yr8
152   rlca
153   rlca
154   ld    =regdest16[1],a
155   ;ld    a,=xr8
156   ;and   #07
157 ENDM scr_pix_xy_rr