File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -186,6 +186,7 @@ def optimize(initial_memory):
186186 if OPTIONS .optimization .value <= 2 : # if -O2 or lower, do nothing and return
187187 return '\n ' .join (x for x in initial_memory if not RE_PRAGMA .match (x ))
188188
189+ basicblock .BasicBlock .clean_asm_args = OPTIONS .optimization .value > 3
189190 bb = basicblock .BasicBlock (initial_memory )
190191 cleanup_local_labels (bb )
191192 initialize_memory (bb )
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ class BasicBlock(object):
2222 """ A Class describing a basic block
2323 """
2424 __UNIQUE_ID = 0
25+ clean_asm_args = False
2526
2627 def __init__ (self , memory ):
2728 """ Initializes the internal array of instructions.
@@ -84,7 +85,11 @@ def code(self):
8485 def code (self , value ):
8586 assert isinstance (value , (list , tuple ))
8687 assert all (isinstance (x , str ) for x in value )
87- self .mem = [MemCell (asm , i ) for i , asm in enumerate (value )]
88+ if self .clean_asm_args :
89+ self .mem = [MemCell (helpers .simplify_asm_args (asm ), i ) for i , asm in enumerate (value )]
90+ else :
91+ self .mem = [MemCell (asm , i ) for i , asm in enumerate (value )]
92+
8893 self ._bytes = None
8994 self ._sizeof = None
9095 self ._max_tstates = None
Original file line number Diff line number Diff line change @@ -148,3 +148,12 @@ def test_long_block(self):
148148 self .assertFalse (blks [1 ] in blks [2 ].goes_to )
149149 self .assertFalse (blks [1 ] in blks [3 ].goes_to )
150150 self .assertFalse (blks [5 ].goes_to ) # empty
151+
152+ def test_basic_block_clean_ld_hl (self ):
153+ code = """
154+ ld hl, (30001 - 1)
155+ """
156+ basicblock .BasicBlock .clean_asm_args = True
157+ self .blk .code = [x for x in code .split ('\n ' ) if x .strip ()]
158+ self .assertEqual (1 , len (self .blk ))
159+ self .assertEqual (['ld hl, (30000)' ], self .blk .code )
Original file line number Diff line number Diff line change 1+ org 32768
2+ __START_PROGRAM:
3+ di
4+ push ix
5+ push iy
6+ exx
7+ push hl
8+ exx
9+ ld hl , 0
10+ add hl , sp
11+ ld (__CALL_BACK__) , hl
12+ ei
13+ ld a , (_sail)
14+ dec a
15+ jp nz , __LABEL__enddispara
16+ ld a , (_subeEgg)
17+ or a
18+ jp nz , __LABEL__enddispara
19+ ld a , ( 40011 )
20+ ld hl , ( 40042 )
21+ cp h
22+ jp nc , __LABEL__enddispara
23+ ld a , ( 40044 )
24+ ld hl , ( 40011 )
25+ sub h
26+ call __ABS8
27+ ld h , 16
28+ call __LTI8
29+ or a
30+ jp z , __LABEL__enddispara
31+ ld a , ( 40011 )
32+ ld hl , ( 40042 )
33+ sub h
34+ call __ABS8
35+ ld h , 20
36+ call __LTI8
37+ or a
38+ jp nz , __LABEL__enddispara
39+ __LABEL7:
40+ __LABEL5:
41+ __LABEL3:
42+ __LABEL1:
43+ jp __LABEL__enddispara
44+ __END_PROGRAM:
45+ di
46+ ld hl , (__CALL_BACK__)
47+ ld sp , hl
48+ exx
49+ pop hl
50+ pop iy
51+ pop ix
52+ exx
53+ ei
54+ ret
55+ __CALL_BACK__:
56+ DEFW 0
57+ __LABEL__enddispara:
58+ ld bc , 0
59+ jp __END_PROGRAM
60+ #line 1 "abs8.asm"
61+
62+ ; Returns absolute value for 8 bit signed integer
63+ ;
64+ __ABS8:
65+ or a
66+ ret p
67+ neg
68+ ret
69+
70+ #line 49 "opt4_053opt.bas"
71+ #line 1 "lti8.asm"
72+
73+ #line 1 "lei8.asm"
74+
75+ __LEI8: ; Signed <= comparison for 8bit int
76+ ; A <= H (registers)
77+ PROC
78+ LOCAL checkParity
79+ sub h
80+ jr nz , __LTI
81+ inc a
82+ ret
83+
84+ __LTI8: ; Test 8 bit values A < H
85+ sub h
86+
87+ __LTI: ; Generic signed comparison
88+ jp po , checkParity
89+ xor 0x80
90+ checkParity:
91+ ld a , 0 ; False
92+ ret p
93+ inc a ; True
94+ ret
95+ ENDP
96+ #line 2 "lti8.asm"
97+ #line 50 "opt4_053opt.bas"
98+
99+ ZXBASIC_USER_DATA:
100+ _subeEgg:
101+ DEFB 00
102+ _sail:
103+ DEFB 00
104+ ; Defines DATA END --> HEAP size is 0
105+ ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP
106+ ; Defines USER DATA Length in bytes
107+ ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
108+ END
Original file line number Diff line number Diff line change 1+
2+ #define tablaSprites 40000
3+
4+ #define toloX (tablaSprites+ 11 )
5+ #define toloY (tablaSprites+ 12 )
6+ #define eggX (tablaSprites+ 32 + 11 )
7+ #define eggY (tablaSprites+ 32 + 12 )
8+
9+
10+ DIM subeEgg, sail as UByte
11+
12+
13+
14+ if sail= 1 then
15+ if subeEgg= 0 then
16+ if peek(toloX)<peek(eggX) then
17+ if abs(cast( byte ,peek(eggY)-peek(toloY)))< 16 then
18+ if abs(cast( byte ,peek(toloX)-peek(eggX)))< 20 then '24
19+ goto enddispara
20+ end if
21+ end if
22+ end if
23+ end if
24+ end if
25+
26+ goto enddispara
27+ END
28+ enddispara:
29+
You can’t perform that action at this time.
0 commit comments