Skip to content

Commit 9dcd082

Browse files
authored
Merge pull request #621 from boriel/fix/print_attr_wrong
Fix/print attr wrong
2 parents 2489ed4 + 8a7a5fa commit 9dcd082

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+21943
-22038
lines changed

src/arch/z80/translator.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,7 @@ def visit_WHILE_DO(self, node):
700700
# Drawing Primitives PLOT, DRAW, DRAW3, CIRCLE
701701
# -----------------------------------------------------------------------------------------------------
702702
def visit_PLOT(self, node):
703+
self.norm_attr()
703704
TMP_HAS_ATTR = self.check_attr(node, 2)
704705
yield TMP_HAS_ATTR
705706
yield node.children[0]
@@ -708,9 +709,9 @@ def visit_PLOT(self, node):
708709
self.ic_fparam(node.children[1].type_, node.children[1].t)
709710
self.runtime_call(RuntimeLabel.PLOT, 0)
710711
self.HAS_ATTR = TMP_HAS_ATTR is not None
711-
self.norm_attr()
712712

713713
def visit_DRAW(self, node):
714+
self.norm_attr()
714715
TMP_HAS_ATTR = self.check_attr(node, 2)
715716
yield TMP_HAS_ATTR
716717
yield node.children[0]
@@ -719,9 +720,9 @@ def visit_DRAW(self, node):
719720
self.ic_fparam(node.children[1].type_, node.children[1].t)
720721
self.runtime_call(RuntimeLabel.DRAW, 0)
721722
self.HAS_ATTR = TMP_HAS_ATTR is not None
722-
self.norm_attr()
723723

724724
def visit_DRAW3(self, node):
725+
self.norm_attr()
725726
TMP_HAS_ATTR = self.check_attr(node, 3)
726727
yield TMP_HAS_ATTR
727728
yield node.children[0]
@@ -732,9 +733,9 @@ def visit_DRAW3(self, node):
732733
self.ic_fparam(node.children[2].type_, node.children[2].t)
733734
self.runtime_call(RuntimeLabel.DRAW3, 0)
734735
self.HAS_ATTR = TMP_HAS_ATTR is not None
735-
self.norm_attr()
736736

737737
def visit_CIRCLE(self, node):
738+
self.norm_attr()
738739
TMP_HAS_ATTR = self.check_attr(node, 3)
739740
yield TMP_HAS_ATTR
740741
yield node.children[0]
@@ -745,7 +746,6 @@ def visit_CIRCLE(self, node):
745746
self.ic_fparam(node.children[2].type_, node.children[2].t)
746747
self.runtime_call(RuntimeLabel.CIRCLE, 0)
747748
self.HAS_ATTR = TMP_HAS_ATTR is not None
748-
self.norm_attr()
749749

750750
# endregion
751751

@@ -759,6 +759,7 @@ def visit_OUT(self, node):
759759
self.ic_out(node.children[0].t, node.children[1].t)
760760

761761
def visit_PRINT(self, node):
762+
self.norm_attr()
762763
for i in node.children:
763764
yield i
764765

@@ -788,19 +789,8 @@ def visit_PRINT(self, node):
788789
}[self.TSUFFIX(i.type_)]
789790
self.runtime_call(label, 0)
790791

791-
for i in node.children:
792-
if i.token in self.ATTR_TMP or self.has_control_chars(i):
793-
self.HAS_ATTR = True
794-
break
795-
796792
if node.eol:
797-
if self.HAS_ATTR:
798-
self.runtime_call(RuntimeLabel.PRINT_EOL_ATTR, 0)
799-
self.HAS_ATTR = False
800-
else:
801-
self.runtime_call(RuntimeLabel.PRINT_EOL, 0)
802-
else:
803-
self.norm_attr()
793+
self.runtime_call(RuntimeLabel.PRINT_EOL, 0)
804794

805795
def visit_PRINT_AT(self, node):
806796
yield node.children[0]
@@ -1463,7 +1453,6 @@ def visit_FUNCTION(self, node):
14631453
for i in node.body:
14641454
yield i
14651455

1466-
self.norm_attr()
14671456
self.ic_label("%s__leave" % node.mangled)
14681457

14691458
# Now free any local string from memory.

src/arch/z80/translatorvisitor.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,10 @@ def _visit(self, node):
181181
if node.token in self.ATTR_TMP:
182182
return self.visit_ATTR_TMP(node)
183183

184-
if node.token not in self.ATTR and isinstance(node, symbols.SENTENCE):
185-
self.norm_attr()
186-
187184
return TranslatorInstVisitor._visit(self, node)
188185

189186
def norm_attr(self):
190187
"""Normalize attr state"""
191-
if not self.HAS_ATTR:
192-
return
193-
194-
self.HAS_ATTR = False
195188
self.runtime_call(RuntimeLabel.COPY_ATTR, 0)
196189

197190
@staticmethod

src/arch/zx48k/library-asm/print.asm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,10 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
176176
ld (DFCC), hl
177177

178178
ld hl, (DFCCL) ; current ATTR Pos
179-
push hl
180-
call __SET_ATTR
181-
pop hl
182179
inc hl
183-
ld (DFCCL),hl
180+
ld (DFCCL), hl
181+
dec hl
182+
call __SET_ATTR
184183
exx
185184
ret
186185

src/arch/zxnext/library-asm/print.asm

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,10 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
176176
ld (DFCC), hl
177177

178178
ld hl, (DFCCL) ; current ATTR Pos
179-
push hl
180-
call __SET_ATTR
181-
pop hl
182179
inc hl
183-
ld (DFCCL),hl
180+
ld (DFCCL), hl
181+
dec hl
182+
call __SET_ATTR
184183
exx
185184
ret
186185

tests/functional/zx48k/astore16.asm

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ _obj.__DATA__:
7676
ld (hl), 15
7777
inc hl
7878
ld (hl), 39
79+
call .core.COPY_ATTR
7980
ld a, (_i)
8081
ld l, a
8182
ld h, 0
@@ -244,7 +245,8 @@ TMP_ARR_PTR:
244245
DW 0 ; temporary storage for pointer to tables
245246
ENDP
246247
pop namespace
247-
#line 51 "zx48k/astore16.bas"
248+
#line 52 "zx48k/astore16.bas"
249+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
248250
#line 1 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
249251
; vim:ts=4:sw=4:et:
250252
; PRINT command routine
@@ -594,60 +596,6 @@ BRIGHT_TMP:
594596
#line 1 "/zxbasic/src/arch/zx48k/library-asm/over.asm"
595597
; Sets OVER flag in P_FLAG permanently
596598
; Parameter: OVER flag in bit 0 of A register
597-
#line 1 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
598-
#line 4 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
599-
push namespace core
600-
COPY_ATTR:
601-
; Just copies current permanent attribs into temporal attribs
602-
; and sets print mode
603-
PROC
604-
LOCAL INVERSE1
605-
LOCAL __REFRESH_TMP
606-
INVERSE1 EQU 02Fh
607-
ld hl, (ATTR_P)
608-
ld (ATTR_T), hl
609-
ld hl, FLAGS2
610-
call __REFRESH_TMP
611-
ld hl, P_FLAG
612-
call __REFRESH_TMP
613-
__SET_ATTR_MODE: ; Another entry to set print modes. A contains (P_FLAG)
614-
LOCAL TABLE
615-
LOCAL CONT2
616-
rra ; Over bit to carry
617-
ld a, (FLAGS2)
618-
rla ; Over bit in bit 1, Over2 bit in bit 2
619-
and 3 ; Only bit 0 and 1 (OVER flag)
620-
ld c, a
621-
ld b, 0
622-
ld hl, TABLE
623-
add hl, bc
624-
ld a, (hl)
625-
ld (PRINT_MODE), a
626-
ld hl, (P_FLAG)
627-
xor a ; NOP -> INVERSE0
628-
bit 2, l
629-
jr z, CONT2
630-
ld a, INVERSE1 ; CPL -> INVERSE1
631-
CONT2:
632-
ld (INVERSE_MODE), a
633-
ret
634-
TABLE:
635-
nop ; NORMAL MODE
636-
xor (hl) ; OVER 1 MODE
637-
and (hl) ; OVER 2 MODE
638-
or (hl) ; OVER 3 MODE
639-
#line 67 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
640-
__REFRESH_TMP:
641-
ld a, (hl)
642-
and 0b10101010
643-
ld c, a
644-
rra
645-
or c
646-
ld (hl), a
647-
ret
648-
ENDP
649-
pop namespace
650-
#line 4 "/zxbasic/src/arch/zx48k/library-asm/over.asm"
651599
push namespace core
652600
OVER:
653601
PROC
@@ -889,11 +837,10 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
889837
inc hl
890838
ld (DFCC), hl
891839
ld hl, (DFCCL) ; current ATTR Pos
892-
push hl
893-
call __SET_ATTR
894-
pop hl
895840
inc hl
896-
ld (DFCCL),hl
841+
ld (DFCCL), hl
842+
dec hl
843+
call __SET_ATTR
897844
exx
898845
ret
899846
; ------------- SPECIAL CHARS (< 32) -----------------
@@ -912,7 +859,7 @@ __PRINT_0Dh: ; Called WHEN printing CHR$(13)
912859
push hl
913860
call __SCROLL_SCR
914861
pop hl
915-
#line 210 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
862+
#line 209 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
916863
1:
917864
ld l, 1
918865
__PRINT_EOL_END:
@@ -1029,14 +976,14 @@ __PRINT_BOLD:
1029976
__PRINT_BOLD2:
1030977
call BOLD_TMP
1031978
jp __PRINT_RESTART
1032-
#line 354 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
979+
#line 353 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1033980
__PRINT_ITA:
1034981
ld hl, __PRINT_ITA2
1035982
jp __PRINT_SET_STATE
1036983
__PRINT_ITA2:
1037984
call ITALIC_TMP
1038985
jp __PRINT_RESTART
1039-
#line 364 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
986+
#line 363 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1040987
LOCAL __BOLD
1041988
__BOLD:
1042989
push hl
@@ -1054,7 +1001,7 @@ __BOLD:
10541001
pop hl
10551002
ld de, MEM0
10561003
ret
1057-
#line 385 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1004+
#line 384 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
10581005
LOCAL __ITALIC
10591006
__ITALIC:
10601007
push hl
@@ -1079,12 +1026,12 @@ __ITALIC:
10791026
pop hl
10801027
ld de, MEM0
10811028
ret
1082-
#line 413 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1029+
#line 412 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
10831030
LOCAL __SCROLL_SCR
1084-
#line 487 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1031+
#line 486 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
10851032
__SCROLL_SCR EQU 0DFEh ; Use ROM SCROLL
1033+
#line 488 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
10861034
#line 489 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1087-
#line 490 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
10881035
PRINT_COMMA:
10891036
call __LOAD_S_POSN
10901037
ld a, e
@@ -1127,9 +1074,9 @@ PRINT_AT: ; Changes cursor to ROW, COL
11271074
LOCAL __PRINT_TABLE
11281075
LOCAL __PRINT_TAB, __PRINT_TAB1, __PRINT_TAB2
11291076
LOCAL __PRINT_ITA2
1130-
#line 546 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1077+
#line 545 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
11311078
LOCAL __PRINT_BOLD2
1132-
#line 552 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1079+
#line 551 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
11331080
__PRINT_TABLE: ; Jump table for 0 .. 22 codes
11341081
DW __PRINT_NOP ; 0
11351082
DW __PRINT_NOP ; 1
@@ -1157,7 +1104,60 @@ __PRINT_TABLE: ; Jump table for 0 .. 22 codes
11571104
DW __PRINT_TAB ; 23 TAB
11581105
ENDP
11591106
pop namespace
1160-
#line 52 "zx48k/astore16.bas"
1107+
#line 3 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
1108+
#line 4 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
1109+
push namespace core
1110+
COPY_ATTR:
1111+
; Just copies current permanent attribs into temporal attribs
1112+
; and sets print mode
1113+
PROC
1114+
LOCAL INVERSE1
1115+
LOCAL __REFRESH_TMP
1116+
INVERSE1 EQU 02Fh
1117+
ld hl, (ATTR_P)
1118+
ld (ATTR_T), hl
1119+
ld hl, FLAGS2
1120+
call __REFRESH_TMP
1121+
ld hl, P_FLAG
1122+
call __REFRESH_TMP
1123+
__SET_ATTR_MODE: ; Another entry to set print modes. A contains (P_FLAG)
1124+
LOCAL TABLE
1125+
LOCAL CONT2
1126+
rra ; Over bit to carry
1127+
ld a, (FLAGS2)
1128+
rla ; Over bit in bit 1, Over2 bit in bit 2
1129+
and 3 ; Only bit 0 and 1 (OVER flag)
1130+
ld c, a
1131+
ld b, 0
1132+
ld hl, TABLE
1133+
add hl, bc
1134+
ld a, (hl)
1135+
ld (PRINT_MODE), a
1136+
ld hl, (P_FLAG)
1137+
xor a ; NOP -> INVERSE0
1138+
bit 2, l
1139+
jr z, CONT2
1140+
ld a, INVERSE1 ; CPL -> INVERSE1
1141+
CONT2:
1142+
ld (INVERSE_MODE), a
1143+
ret
1144+
TABLE:
1145+
nop ; NORMAL MODE
1146+
xor (hl) ; OVER 1 MODE
1147+
and (hl) ; OVER 2 MODE
1148+
or (hl) ; OVER 3 MODE
1149+
#line 67 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
1150+
__REFRESH_TMP:
1151+
ld a, (hl)
1152+
and 0b10101010
1153+
ld c, a
1154+
rra
1155+
or c
1156+
ld (hl), a
1157+
ret
1158+
ENDP
1159+
pop namespace
1160+
#line 53 "zx48k/astore16.bas"
11611161
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printu16.asm"
11621162
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printi16.asm"
11631163
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printnum.asm"
@@ -1305,5 +1305,5 @@ __PRINTU_LOOP:
13051305
ENDP
13061306
pop namespace
13071307
#line 2 "/zxbasic/src/arch/zx48k/library-asm/printu16.asm"
1308-
#line 53 "zx48k/astore16.bas"
1308+
#line 55 "zx48k/astore16.bas"
13091309
END

0 commit comments

Comments
 (0)