Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
proportional text writing
#1
i started to try proportional text writing on zxbasic - it's far incomplete (not printing from strings yet) and slow

test.bas
Code:
#include "lib/NaftaRegular_charmap.bas" dim i,j,adr,v,vq,vq2,x,y,x1,x2,c,c1,xps as uinteger border 6:paper 7:ink 1: bright 1:cls x=3:y=109 for c1=0 to 52 x1=int(x/8) x2=7-(x mod 8) for j=0 to 11 i= ((y+j)*32)+x1 adr=(16384+((i band 31) bor ((i band 224)*8) bor ((i band 1793)/8) bor (i band 6144))) v=peek(uinteger, adr) vq2=(peek(@naftaregularcharmap+(12*c1)+j))*(2^x2) vqbs= ((vq2 band 65280)/256) bor ((vq2 band 255)*256) poke uinteger adr,v bor vqbs next j x=x+peek(@naftaregularcharmapspacing+c1) next c1 pause 0

lib/NaftaRegular_charmap.bas
Code:
goto naftaregularcharmapend naftaregularcharmap: asm defb 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h defb 000h,000h,080h,080h,080h,080h,000h,080h,000h,000h,000h,000h defb 0a0h,0a0h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h defb 000h,000h,050h,0f8h,050h,050h,0f8h,050h,000h,000h,000h,000h defb 040h,040h,0e0h,0c0h,0c0h,060h,060h,0e0h,040h,040h,000h,000h defb 000h,000h,048h,0b0h,050h,028h,034h,048h,000h,000h,000h,000h defb 000h,000h,020h,050h,064h,094h,088h,076h,000h,000h,000h,000h defb 080h,080h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h defb 020h,040h,040h,080h,080h,080h,080h,080h,080h,040h,040h,020h defb 080h,040h,040h,020h,020h,020h,020h,020h,020h,040h,040h,080h defb 000h,040h,0e0h,0a0h,000h,000h,000h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,040h,0e0h,040h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,000h,000h,000h,040h,040h,080h,000h,000h defb 000h,000h,000h,000h,000h,0c0h,000h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,000h,000h,000h,080h,000h,000h,000h,000h defb 000h,000h,010h,020h,020h,040h,040h,080h,000h,000h,000h,000h defb 000h,000h,060h,090h,090h,090h,090h,060h,000h,000h,000h,000h defb 000h,000h,0c0h,040h,040h,040h,040h,040h,000h,000h,000h,000h defb 000h,000h,060h,010h,010h,020h,040h,0f0h,000h,000h,000h,000h defb 000h,000h,060h,010h,020h,010h,010h,0e0h,000h,000h,000h,000h defb 000h,000h,020h,060h,060h,0a0h,0f0h,020h,000h,000h,000h,000h defb 000h,000h,060h,040h,060h,010h,010h,0e0h,000h,000h,000h,000h defb 000h,000h,020h,040h,0e0h,090h,090h,060h,000h,000h,000h,000h defb 000h,000h,0f0h,010h,020h,020h,040h,040h,000h,000h,000h,000h defb 000h,000h,060h,090h,060h,090h,090h,060h,000h,000h,000h,000h defb 000h,000h,060h,090h,090h,070h,020h,040h,000h,000h,000h,000h defb 000h,000h,000h,000h,080h,000h,000h,080h,000h,000h,000h,000h defb 000h,000h,000h,000h,040h,000h,000h,040h,040h,080h,000h,000h defb 000h,000h,000h,000h,040h,080h,040h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,0e0h,000h,0e0h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,080h,040h,080h,000h,000h,000h,000h,000h defb 000h,000h,060h,090h,020h,040h,000h,040h,000h,000h,000h,000h defb 000h,000h,03ch,042h,099h,0a9h,0a9h,0beh,040h,03ch,000h,000h defb 000h,000h,010h,028h,028h,044h,07ch,082h,000h,000h,000h,000h defb 000h,000h,0c0h,0a0h,0c0h,0a0h,0a0h,0c0h,000h,000h,000h,000h defb 000h,000h,038h,040h,080h,080h,040h,038h,000h,000h,000h,000h defb 000h,000h,0e0h,090h,088h,088h,090h,0e0h,000h,000h,000h,000h defb 000h,000h,0c0h,080h,0c0h,080h,080h,0c0h,000h,000h,000h,000h defb 000h,000h,0c0h,080h,0c0h,080h,080h,080h,000h,000h,000h,000h defb 000h,000h,038h,040h,080h,08ch,044h,03ch,000h,000h,000h,000h defb 000h,000h,088h,088h,0f8h,088h,088h,088h,000h,000h,000h,000h defb 000h,000h,080h,080h,080h,080h,080h,080h,000h,000h,000h,000h defb 000h,000h,040h,040h,040h,040h,040h,040h,040h,080h,000h,000h defb 000h,000h,0a0h,0c0h,0c0h,0a0h,0a0h,090h,000h,000h,000h,000h defb 000h,000h,080h,080h,080h,080h,080h,0c0h,000h,000h,000h,000h defb 000h,000h,044h,044h,06ch,0aah,092h,092h,000h,000h,000h,000h defb 000h,000h,084h,0c4h,0a4h,094h,08ch,084h,000h,000h,000h,000h defb 000h,000h,030h,048h,084h,084h,048h,030h,000h,000h,000h,000h defb 000h,000h,0c0h,0a0h,0a0h,0c0h,080h,080h,000h,000h,000h,000h defb 000h,000h,030h,048h,084h,084h,048h,030h,00ch,003h,000h,000h defb 000h,000h,0c0h,0a0h,0a0h,0c0h,0a0h,098h,000h,000h,000h,000h defb 000h,000h,060h,080h,040h,020h,010h,0e0h,000h,000h,000h,000h defb 000h,000h,0f8h,020h,020h,020h,020h,020h,000h,000h,000h,000h defb 000h,000h,088h,088h,088h,088h,088h,070h,000h,000h,000h,000h defb 000h,000h,082h,044h,044h,028h,028h,010h,000h,000h,000h,000h defb 000h,000h,0a2h,055h,055h,02ah,02ah,014h,000h,000h,000h,000h defb 000h,000h,090h,090h,060h,060h,090h,090h,000h,000h,000h,000h defb 000h,000h,088h,050h,020h,020h,020h,020h,000h,000h,000h,000h defb 000h,000h,0fch,008h,010h,020h,040h,0fch,000h,000h,000h,000h defb 0c0h,080h,080h,080h,080h,080h,080h,080h,080h,080h,080h,0c0h defb 000h,000h,080h,040h,040h,020h,020h,010h,000h,000h,000h,000h defb 0c0h,040h,040h,040h,040h,040h,040h,040h,040h,040h,040h,0c0h defb 000h,040h,0a0h,000h,000h,000h,000h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,000h,000h,000h,000h,000h,0fch,000h,000h defb 000h,080h,040h,000h,000h,000h,000h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,060h,020h,0e0h,0f0h,000h,000h,000h,000h defb 080h,080h,080h,080h,0a0h,0d0h,090h,0e0h,000h,000h,000h,000h defb 000h,000h,000h,000h,060h,080h,080h,060h,000h,000h,000h,000h defb 010h,010h,010h,010h,050h,0b0h,090h,070h,000h,000h,000h,000h defb 000h,000h,000h,000h,060h,0f0h,080h,060h,000h,000h,000h,000h defb 000h,030h,040h,040h,0e0h,040h,040h,040h,000h,000h,000h,000h defb 000h,000h,000h,000h,03ch,048h,048h,070h,098h,064h,098h,060h defb 080h,080h,080h,080h,0a0h,0d0h,090h,090h,000h,000h,000h,000h defb 000h,000h,080h,000h,080h,080h,080h,080h,000h,000h,000h,000h defb 000h,000h,040h,000h,040h,040h,040h,040h,040h,040h,040h,080h defb 080h,080h,080h,080h,0a0h,0c0h,0a0h,090h,000h,000h,000h,000h defb 080h,080h,080h,080h,080h,080h,080h,080h,000h,000h,000h,000h defb 000h,000h,000h,000h,0a4h,0dah,092h,092h,000h,000h,000h,000h defb 000h,000h,000h,000h,0a0h,0d0h,090h,090h,000h,000h,000h,000h defb 000h,000h,000h,000h,060h,090h,090h,060h,000h,000h,000h,000h defb 000h,000h,000h,000h,0a0h,0d0h,090h,0e0h,080h,080h,080h,080h defb 000h,000h,000h,000h,050h,0b0h,090h,070h,010h,010h,010h,010h defb 000h,000h,000h,000h,0a0h,0c0h,080h,080h,000h,000h,000h,000h defb 000h,000h,000h,000h,060h,040h,030h,0e0h,000h,000h,000h,000h defb 000h,000h,040h,040h,0e0h,040h,040h,060h,000h,000h,000h,000h defb 000h,000h,000h,000h,090h,090h,0b0h,050h,000h,000h,000h,000h defb 000h,000h,000h,000h,088h,050h,050h,020h,000h,000h,000h,000h defb 000h,000h,000h,000h,0aah,054h,054h,028h,000h,000h,000h,000h defb 000h,000h,000h,000h,090h,060h,060h,090h,000h,000h,000h,000h defb 000h,000h,000h,000h,088h,050h,050h,020h,020h,040h,040h,080h defb 000h,000h,000h,000h,0f0h,020h,040h,0f0h,000h,000h,000h,000h defb 020h,040h,040h,040h,040h,080h,040h,040h,040h,040h,040h,020h defb 080h,080h,080h,080h,080h,080h,080h,080h,080h,080h,080h,080h defb 080h,040h,040h,040h,040h,020h,040h,040h,040h,040h,040h,080h defb 000h,000h,000h,000h,050h,0a0h,000h,000h,000h,000h,000h,000h defb 000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h,000h end asm naftaregularcharmapspacing: asm defb 4,2,4,6,4,7,8,2,4,4,4,4,3,3,2,5 defb 5,3,5,5,5,5,5,5,5,5,2,3,3,4,3,5 defb 9,8,4,6,6,3,3,7,6,2,3,5,3,8,7,7 defb 4,7,5,5,6,6,8,9,5,6,7,3,5,3,4,7 defb 3,5,5,4,5,5,5,8,5,2,3,5,2,8,5,5 defb 5,5,4,5,4,5,6,8,5,6,5,4,2,4,5,4 end asm naftaregularcharmapkerning: asm defb "VA" defb 0FEh defb "AV" defb 0FEh end asm naftaregularcharmapend:
Reply
#2
Inline ASM proportional print routine I published some time ago:
<!-- l --><a class="postlink-local" href="https://forum.boriel.com/how-to-tutorials/topic461.html">how-to-tutorials/topic461.html</a><!-- l -->
It works with all custom fonts too, and offers custom spacing.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#3
LCD Wrote:Inline ASM proportional print routine I published some time ago:
<!-- l --><a class="postlink-local" href="https://forum.boriel.com/how-to-tutorials/topic461.html">how-to-tutorials/topic461.html</a><!-- l -->
It works with all custom fonts too, and offers custom spacing.

thanks LCD, i knew that you told about coding it months ago, but i didn't know that you had it ready - i'll try it now, thanks! Smile
Reply
#4
The code is really fast, but i didn't find the custom space there
On my code, i used a special area just for that (and i'm also thinking about using kernings there as well...)
And on my example i used 12 pixel lines instead of 8
Reply
#5
got a screenshot? Big Grin
Reply
#6
nitrofurano Wrote:The code is really fast, but i didn't find the custom space there
On my code, i used a special area just for that (and i'm also thinking about using kernings there as well...)
And on my example i used 12 pixel lines instead of 8
spacing variables:
xgap: gap between letters in pixels.
spacesize: gap of space
The width of all letters is automaticaly recognised, so it is not possible to define larger gaps for some letters (as this is nonsense), and it works also with narrow fonts like 4x8.
But back to your code:
To speed it up, replace multiplications and divisions with bitshifting.
Replacing
Code:
x1=int(x/8)
with
Code:
x1=x>>3
speeds it already significantly up.
Edit:
Forget what I wrote. I'm stupid...
The biggest downslowing was
Code:
2^x2
And you repeated the same calculation over and over, so defining the x3 variable outside j-loop speeds it up dramaticaly. I even changed it and other calcs to bitshifting for further speedup:
Code:
dim i,j,adr,v,vq,vq2,c,xps,x1,x2,x3,x,y,c1 as uinteger border 6:paper 7:ink 1: bright 1:cls x=3:y=109 for c1=0 to 52 x1=x>>3 x2=7-(x mod 8) x3=1<<x2 if x3=0 then x3=1:end if for j=0 to 11 i= ((y+j)<<5)+x1 adr=(16384+((i band 31) bor ((i band 224)<<3) bor ((i band 1793)>>3) bor (i band 6144))) v=peek(uinteger, adr) vq2=(peek(@naftaregularcharmap+(12*c1)+j))*x3 vqbs= ((vq2 band 65280)>>8) bor ((vq2 band 255)<<8) poke uinteger adr,v bor vqbs next j x=x+peek(@naftaregularcharmapspacing+c1) next c1 pause 0
Hope, you like it.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#7
LCD Wrote:Inline ASM proportional print routine I published some time ago:
<!-- l --><a class="postlink-local" href="https://forum.boriel.com/how-to-tutorials/topic461.html">how-to-tutorials/topic461.html</a><!-- l -->
It works with all custom fonts too, and offers custom spacing.

I think I should mention that LCD's proportional printing routine has been in the library for a while:

<!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:Library">http://www.boriel.com/wiki/en/index.php ... IC:Library</a><!-- m -->

There's quite a lot in there - you should certainly have a look!

BL
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)