Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print issues (*fixed*)
#3
boriel Wrote:[quote="britlion"]

Print "1"+CHR$(6)+"2" does compile, but the print routine seems to ignore the tab.

I forgot to implement the comma. Will try to implement it this evening.

Regarding the tab, it IS implemented (try TAB). If you want to use TAB with char codes, according to the ZX Spectrum manual, it is a 16 bit (two chars) sequence. So TAB 25 is: PRINT CHR$(6) + CHR$(25) + CHR$(0)

By tab here, I meant the comma tab - jump to mid screen. CHR$(6) should be the same as a comma - so for a spectrum

"1","2" is the same as "1";CHR$(6);"2"

The apostrophe (') is also used in the ZX Spectrum, for "newline", but it won't be implemented, since that character is also used for comments. You will have to use CHR$(13) for that.
[/quote]

Noticed that - but CHR$(13) prints just fine, so there's a workaround, there, at least.

Britlion Wrote:PRINT "1"+"2" is quite a lot shorter - the compiler sees it can combine the strings into one label.

True, the latter is preferable when dealing with constants. But the compiler recognizes *every* constant string, and tries a memory optimization for them, mapping the same string constants to the same memory location. Look:
Quote:Oh, very very clever. I know the java compiler does the exact same thing - every string literal is only used once. This can be handy.

Of course knowing how these are optimized, right now we can write code for size or speed. Hmm. Two different goals, there.

[quote]
I will have a look to this. However, direct color codes should be a little faster (some t-states less).

You are right, it is slightly:

Code:
FUNCTION t AS ULONG
    RETURN INT((65536 * PEEK (23674) + 256 * PEEK(23673) + PEEK (23672)))
END FUNCTION

PRINT at 0,0;t()

FOR N=1 TO 250
PRINT AT 10,10;CHR$(16)+CHR$(1)+"BLUE"+CHR$(16)+CHR$(2)+"RED"
NEXT N

PRINT at 1,0;t()

Takes 41 frames, as printed.

Code:
FUNCTION t AS ULONG
    RETURN INT((65536 * PEEK (23674) + 256 * PEEK(23673) + PEEK (23672)))
END FUNCTION

PRINT at 0,0;t()

FOR N=1 TO 250
PRINT AT 10,10;INK 1;"BLUE";INK 2;"RED"
NEXT N

PRINT at 1,0;t()

Takes 39!

Clearly traditional methods outweigh my clever ones. Bah!

Then again, we have speed vs size again!

boriel Wrote:[quote=Britlion]
Code:
LET A=A+1
LET A=A*2

Does Load, increment, store, multiply, store.

Boriel Wrote:Are you compiling with the -O3 (peephole optimization) flag? -O3 should do what you are suggesting

Code:
ld a, 10
    ld (_A), a
    inc a
    ld (_A), a
    sla a
    ld (_A), a

That's the key bit with -O3 - load, store, inc, store, multiply, store; yes?
Code:
E:\ZXBwork>zxb -A -O3 test.bas
INFO: __PRINTU8 is not defined. No optimization is done.
INFO: PRINT_EOL is not defined. No optimization is done.

E:\ZXBwork>

Not sure Optimization is working right for me. I get the above error messages.

britlion Wrote:(Is it worth optimizing double and triple bitshifts for *4 and *8 and so on? These are common multipliers, if only for screen coordinates.)
[quote="Boriel"]It should. Either for the division.
[/quote]

Awesome. This is one of the advantages of having a larger memory space for a compiler outside the spectrum - we can get far more code tweaks and optimizations in.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)