Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions src/arch/z80/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ def visit_WHILE_DO(self, node):
# Drawing Primitives PLOT, DRAW, DRAW3, CIRCLE
# -----------------------------------------------------------------------------------------------------
def visit_PLOT(self, node):
self.norm_attr()
TMP_HAS_ATTR = self.check_attr(node, 2)
yield TMP_HAS_ATTR
yield node.children[0]
Expand All @@ -708,9 +709,9 @@ def visit_PLOT(self, node):
self.ic_fparam(node.children[1].type_, node.children[1].t)
self.runtime_call(RuntimeLabel.PLOT, 0)
self.HAS_ATTR = TMP_HAS_ATTR is not None
self.norm_attr()

def visit_DRAW(self, node):
self.norm_attr()
TMP_HAS_ATTR = self.check_attr(node, 2)
yield TMP_HAS_ATTR
yield node.children[0]
Expand All @@ -719,9 +720,9 @@ def visit_DRAW(self, node):
self.ic_fparam(node.children[1].type_, node.children[1].t)
self.runtime_call(RuntimeLabel.DRAW, 0)
self.HAS_ATTR = TMP_HAS_ATTR is not None
self.norm_attr()

def visit_DRAW3(self, node):
self.norm_attr()
TMP_HAS_ATTR = self.check_attr(node, 3)
yield TMP_HAS_ATTR
yield node.children[0]
Expand All @@ -732,9 +733,9 @@ def visit_DRAW3(self, node):
self.ic_fparam(node.children[2].type_, node.children[2].t)
self.runtime_call(RuntimeLabel.DRAW3, 0)
self.HAS_ATTR = TMP_HAS_ATTR is not None
self.norm_attr()

def visit_CIRCLE(self, node):
self.norm_attr()
TMP_HAS_ATTR = self.check_attr(node, 3)
yield TMP_HAS_ATTR
yield node.children[0]
Expand All @@ -745,7 +746,6 @@ def visit_CIRCLE(self, node):
self.ic_fparam(node.children[2].type_, node.children[2].t)
self.runtime_call(RuntimeLabel.CIRCLE, 0)
self.HAS_ATTR = TMP_HAS_ATTR is not None
self.norm_attr()

# endregion

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

def visit_PRINT(self, node):
self.norm_attr()
for i in node.children:
yield i

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

for i in node.children:
if i.token in self.ATTR_TMP or self.has_control_chars(i):
self.HAS_ATTR = True
break

if node.eol:
if self.HAS_ATTR:
self.runtime_call(RuntimeLabel.PRINT_EOL_ATTR, 0)
self.HAS_ATTR = False
else:
self.runtime_call(RuntimeLabel.PRINT_EOL, 0)
else:
self.norm_attr()
self.runtime_call(RuntimeLabel.PRINT_EOL, 0)

def visit_PRINT_AT(self, node):
yield node.children[0]
Expand Down Expand Up @@ -1463,7 +1453,6 @@ def visit_FUNCTION(self, node):
for i in node.body:
yield i

self.norm_attr()
self.ic_label("%s__leave" % node.mangled)

# Now free any local string from memory.
Expand Down
7 changes: 0 additions & 7 deletions src/arch/z80/translatorvisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,10 @@ def _visit(self, node):
if node.token in self.ATTR_TMP:
return self.visit_ATTR_TMP(node)

if node.token not in self.ATTR and isinstance(node, symbols.SENTENCE):
self.norm_attr()

return TranslatorInstVisitor._visit(self, node)

def norm_attr(self):
"""Normalize attr state"""
if not self.HAS_ATTR:
return

self.HAS_ATTR = False
self.runtime_call(RuntimeLabel.COPY_ATTR, 0)

@staticmethod
Expand Down
7 changes: 3 additions & 4 deletions src/arch/zx48k/library-asm/print.asm
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
ld (DFCC), hl

ld hl, (DFCCL) ; current ATTR Pos
push hl
call __SET_ATTR
pop hl
inc hl
ld (DFCCL),hl
ld (DFCCL), hl
dec hl
call __SET_ATTR
exx
ret

Expand Down
7 changes: 3 additions & 4 deletions src/arch/zxnext/library-asm/print.asm
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
ld (DFCC), hl

ld hl, (DFCCL) ; current ATTR Pos
push hl
call __SET_ATTR
pop hl
inc hl
ld (DFCCL),hl
ld (DFCCL), hl
dec hl
call __SET_ATTR
exx
ret

Expand Down
140 changes: 70 additions & 70 deletions tests/functional/zx48k/astore16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ _obj.__DATA__:
ld (hl), 15
inc hl
ld (hl), 39
call .core.COPY_ATTR
ld a, (_i)
ld l, a
ld h, 0
Expand Down Expand Up @@ -244,7 +245,8 @@ TMP_ARR_PTR:
DW 0 ; temporary storage for pointer to tables
ENDP
pop namespace
#line 51 "zx48k/astore16.bas"
#line 52 "zx48k/astore16.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
; vim:ts=4:sw=4:et:
; PRINT command routine
Expand Down Expand Up @@ -594,60 +596,6 @@ BRIGHT_TMP:
#line 1 "/zxbasic/src/arch/zx48k/library-asm/over.asm"
; Sets OVER flag in P_FLAG permanently
; Parameter: OVER flag in bit 0 of A register
#line 1 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
#line 4 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
push namespace core
COPY_ATTR:
; Just copies current permanent attribs into temporal attribs
; and sets print mode
PROC
LOCAL INVERSE1
LOCAL __REFRESH_TMP
INVERSE1 EQU 02Fh
ld hl, (ATTR_P)
ld (ATTR_T), hl
ld hl, FLAGS2
call __REFRESH_TMP
ld hl, P_FLAG
call __REFRESH_TMP
__SET_ATTR_MODE: ; Another entry to set print modes. A contains (P_FLAG)
LOCAL TABLE
LOCAL CONT2
rra ; Over bit to carry
ld a, (FLAGS2)
rla ; Over bit in bit 1, Over2 bit in bit 2
and 3 ; Only bit 0 and 1 (OVER flag)
ld c, a
ld b, 0
ld hl, TABLE
add hl, bc
ld a, (hl)
ld (PRINT_MODE), a
ld hl, (P_FLAG)
xor a ; NOP -> INVERSE0
bit 2, l
jr z, CONT2
ld a, INVERSE1 ; CPL -> INVERSE1
CONT2:
ld (INVERSE_MODE), a
ret
TABLE:
nop ; NORMAL MODE
xor (hl) ; OVER 1 MODE
and (hl) ; OVER 2 MODE
or (hl) ; OVER 3 MODE
#line 67 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
__REFRESH_TMP:
ld a, (hl)
and 0b10101010
ld c, a
rra
or c
ld (hl), a
ret
ENDP
pop namespace
#line 4 "/zxbasic/src/arch/zx48k/library-asm/over.asm"
push namespace core
OVER:
PROC
Expand Down Expand Up @@ -889,11 +837,10 @@ INVERSE_MODE: ; 00 -> NOP -> INVERSE 0
inc hl
ld (DFCC), hl
ld hl, (DFCCL) ; current ATTR Pos
push hl
call __SET_ATTR
pop hl
inc hl
ld (DFCCL),hl
ld (DFCCL), hl
dec hl
call __SET_ATTR
exx
ret
; ------------- SPECIAL CHARS (< 32) -----------------
Expand All @@ -912,7 +859,7 @@ __PRINT_0Dh: ; Called WHEN printing CHR$(13)
push hl
call __SCROLL_SCR
pop hl
#line 210 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 209 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
1:
ld l, 1
__PRINT_EOL_END:
Expand Down Expand Up @@ -1029,14 +976,14 @@ __PRINT_BOLD:
__PRINT_BOLD2:
call BOLD_TMP
jp __PRINT_RESTART
#line 354 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 353 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
__PRINT_ITA:
ld hl, __PRINT_ITA2
jp __PRINT_SET_STATE
__PRINT_ITA2:
call ITALIC_TMP
jp __PRINT_RESTART
#line 364 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 363 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
LOCAL __BOLD
__BOLD:
push hl
Expand All @@ -1054,7 +1001,7 @@ __BOLD:
pop hl
ld de, MEM0
ret
#line 385 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 384 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
LOCAL __ITALIC
__ITALIC:
push hl
Expand All @@ -1079,12 +1026,12 @@ __ITALIC:
pop hl
ld de, MEM0
ret
#line 413 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 412 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
LOCAL __SCROLL_SCR
#line 487 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 486 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
__SCROLL_SCR EQU 0DFEh ; Use ROM SCROLL
#line 488 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 489 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 490 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
PRINT_COMMA:
call __LOAD_S_POSN
ld a, e
Expand Down Expand Up @@ -1127,9 +1074,9 @@ PRINT_AT: ; Changes cursor to ROW, COL
LOCAL __PRINT_TABLE
LOCAL __PRINT_TAB, __PRINT_TAB1, __PRINT_TAB2
LOCAL __PRINT_ITA2
#line 546 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 545 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
LOCAL __PRINT_BOLD2
#line 552 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
#line 551 "/zxbasic/src/arch/zx48k/library-asm/print.asm"
__PRINT_TABLE: ; Jump table for 0 .. 22 codes
DW __PRINT_NOP ; 0
DW __PRINT_NOP ; 1
Expand Down Expand Up @@ -1157,7 +1104,60 @@ __PRINT_TABLE: ; Jump table for 0 .. 22 codes
DW __PRINT_TAB ; 23 TAB
ENDP
pop namespace
#line 52 "zx48k/astore16.bas"
#line 3 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
#line 4 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
push namespace core
COPY_ATTR:
; Just copies current permanent attribs into temporal attribs
; and sets print mode
PROC
LOCAL INVERSE1
LOCAL __REFRESH_TMP
INVERSE1 EQU 02Fh
ld hl, (ATTR_P)
ld (ATTR_T), hl
ld hl, FLAGS2
call __REFRESH_TMP
ld hl, P_FLAG
call __REFRESH_TMP
__SET_ATTR_MODE: ; Another entry to set print modes. A contains (P_FLAG)
LOCAL TABLE
LOCAL CONT2
rra ; Over bit to carry
ld a, (FLAGS2)
rla ; Over bit in bit 1, Over2 bit in bit 2
and 3 ; Only bit 0 and 1 (OVER flag)
ld c, a
ld b, 0
ld hl, TABLE
add hl, bc
ld a, (hl)
ld (PRINT_MODE), a
ld hl, (P_FLAG)
xor a ; NOP -> INVERSE0
bit 2, l
jr z, CONT2
ld a, INVERSE1 ; CPL -> INVERSE1
CONT2:
ld (INVERSE_MODE), a
ret
TABLE:
nop ; NORMAL MODE
xor (hl) ; OVER 1 MODE
and (hl) ; OVER 2 MODE
or (hl) ; OVER 3 MODE
#line 67 "/zxbasic/src/arch/zx48k/library-asm/copy_attr.asm"
__REFRESH_TMP:
ld a, (hl)
and 0b10101010
ld c, a
rra
or c
ld (hl), a
ret
ENDP
pop namespace
#line 53 "zx48k/astore16.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printu16.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printi16.asm"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/printnum.asm"
Expand Down Expand Up @@ -1305,5 +1305,5 @@ __PRINTU_LOOP:
ENDP
pop namespace
#line 2 "/zxbasic/src/arch/zx48k/library-asm/printu16.asm"
#line 53 "zx48k/astore16.bas"
#line 55 "zx48k/astore16.bas"
END
Loading