Compact 64 column print routine

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
RMartins
Manic Miner
Posts: 331
Joined: Thu Nov 16, 2017 3:26 pm

Re: Compact 64 column print routine

Post by RMartins » Tue Feb 27, 2018 2:28 pm

Alessandro wrote:
Tue Feb 27, 2018 8:06 am
...
RMartins wrote:
Mon Feb 26, 2018 9:54 pm
Is it just me, or the two top corners sprites, are not correctly aligned ?
I mean in the sense that the bottom ones, have the curly parts in an exact diagonal to each other.
The picture does not have 4:3 proportions, hence the slight misalignment, which is more evident here; when you watch it on a monitor/TV full screen, it's less noticeable.
I may have not explained myself well enough.
The top corner sprites, do not appear to be vertical flips of the bottom ones, hence the curly things, seem different.
0 x

User avatar
Alessandro
Manic Miner
Posts: 245
Joined: Wed Nov 15, 2017 11:10 am
Location: Messina, Italy
Contact:

Re: Compact 64 column print routine

Post by Alessandro » Tue Feb 27, 2018 4:37 pm

Now I understand what you mean. Mind you, I had not noticed that myself.

If you look again at the picture, I revised the "frame", also by adding an inner black line to make it stand out even more. (You might need to erase your browser cache before reloading the page to see the new picture.)

However I won't be adding it to my already existing multi-language files, that would mean uploading them again, then updating the SC database, and it's not worth the hassle. I will use the new "frame" with the next releases and updates.

Now, will you actually play the games? ;)
1 x

User avatar
RMartins
Manic Miner
Posts: 331
Joined: Thu Nov 16, 2017 3:26 pm

Re: Compact 64 column print routine

Post by RMartins » Tue Feb 27, 2018 7:59 pm

Alessandro wrote:
Tue Feb 27, 2018 4:37 pm
...

Now, will you actually play the games? ;)
Nice ...

Fixing that, was not a pre condition for me playing the game :)

I usually keep a list of recently released games, so that when I have some free play time, I can try them.
It's always good to see what others have come up with, either to improve our own game design skills, or learn new tricks, while enjoying playing Spectrum :)
1 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Compact 64 column print routine

Post by arkannoyed » Mon Mar 05, 2018 5:03 pm

I like the creative use of RRD/RLD. I just wish they were faster instructions!

Anyway, I thought I'd throw my hat into the ring sort of thing.

I use a method of encoding the characters that stores vertical lines, then adding a vertical 'space' between each character.

Its a similar way to how I store the font in my proportional scroller.

So, routine needs HL with screen address and BC with the message address when CALLed.

the combined print routine and 74 character 'font' based upon the one posted earlier here, is 210 bytes currently, but could be optimised probably a little more.

Certainly slower though.

Image

Code: Select all

org 0fa00h

direct_dat:
          db 19h,25h,3fh,25h,19h,25h,19h,7dh,19h,7dh,51h,41h,79h,05h,7dh,11h
          db 7dh,31h,7dh,25h,19h,25h,3dh,51h,3dh,31h,3dh,21h,1dh,7dh,55h,29h
          db 55h,29h,29h,29h,39h,45h,45h,79h,05h,79h,7dh,45h,39h,45h,5dh,7dh
          db 55h,45h,7dh,45h,7dh,05h,05h,7dh,11h,6dh,11h,6dh,7dh,41h,3dh,0dh
          db 3dh,43h,01h,43h,3dh,39h,45h,39h,05h,3dh,7dh,51h,21h,55h,39h,05h
          db 39h,55h,39h,55h,09h,39h,4dh,35h,7dh,51h,2dh,11h,2dh,35h,25h,55h
          db 49h,41h,7dh,41h,55h,21h,61h,1dh,61h,01h,61h,4dh,55h,65h,19h,25h
          db 25h,19h,2dh,35h,01h,3dh,51h,1bh,2bh,3dh,19h,25h,7dh,21h,1dh,01h
          db 5dh,01h,1dh,21h,13h,5dh,01h,79h,25h,15h,35h,29h,3bh,0bh,3dh,4dh
          db 55h,25h,45h,55h,29h,71h,11h,3dh,75h,55h,49h,4dh,51h,61h,01h,75h
          db 01h,05h,01h,25h,01h,01h,01h,03h,05h,11h,11h,11h,39h,11h,7dh,11h,2dh

          ;177 bytes CHR set

          ;A=16,B=1d,C=24,D=2a,E=2f,F=09,G=2c,H=0e,I=31,J=25,K=37,L=34,M=10,N=3c,O=45,P=4a,Q=55,R=58,S=5e,T=61,U=0c,V=27,W=07,X=39,Y=66,Z=6b
          ;a=14,b=12,c=6e,d=7a,e=71,f=74,g=77,h=7c,i=7f,j=84,k=b0,l=0b,m=18,n=1a,o=04,p=02,q=00,r=81,s=89,t=86,u=47,v=4e,w=3e,x=5a,y=8c,z=5c
          ;0=50,1=33,2=8f,3=92,4=95,5=98,6=52,7=9b,8=1f,9=4c
          ;!=9e,"=68,.=a0,,=a6,:=a2,+=ab,-=a9,(=40,)=42,==21,?=63,SPC=a4

start:
          ld d,0fah             ;Hi-byte of CHR set+ EOM marker
s_rpt:
          ld a,(bc)             ;get CHR code
          ld e,a                ;CHR code is x3 to save having to do it in routine
          cp d                  ;SUB 0FAh, use D reg value to mark the string end
          ret nc                ;RET if 0FAh detected
          push bc               ;save MSG position
          ld b,04h              ;counter

          ld a,01h              ;set space line with end marker
pr_lp0:
          and a                 ;clear Carry
          ld c,h                ;save SCReen position
init0:
          inc h
          rl (hl)               ;bit into (HL)
          add a,a               ;next data BIT
          jr nz,init0           ;repeat if not 00

          ld h,c                ;restore SCReen address
          ld a,(de)             ;get data byte
          inc e                 ;next
          djnz pr_lp0           ;next line

          pop bc                ;restore MGS address
          inc bc                ;next CHR byte
          ld a,c                ;check
          and 01h               ;mask BIT 0
          add a,l               ;add result to L
          ld l,a                ;INC 1 or 0
          jr s_rpt              ;next CHR rpt.
          
target:
          ld hl,3f00h           ;SCReen address
          ld bc,message         ;MSG address
          call start
          ret
          
message:  ;example message 'Hi To All At Spectrum Computing'
          db 0eh,7fh,0a4h,61h,04h,0a4h,16h,0bh,0bh,0a4h,16h,86h,0a4h,5eh,02h,71h,6eh,86h,81h,47h,18h,0a4h,24h,04h,18h,02h,47h,86h,7fh,1ah,77h,0fah
I'll have a further faff around with the character map and see if I can gain a few more bytes 8-)
3 x

User avatar
Nomad
Manic Miner
Posts: 600
Joined: Thu Dec 28, 2017 12:38 pm

Re: Compact 64 column print routine

Post by Nomad » Mon Mar 05, 2018 5:20 pm

That is all kinds of awesome. :lol:
1 x

User avatar
djnzx48
Microbot
Posts: 195
Joined: Wed Dec 06, 2017 2:13 am
Location: New Zealand

Re: Compact 64 column print routine

Post by djnzx48 » Tue Mar 06, 2018 9:00 am

Ah nice, so you basically store the font 'sideways' and draw it column by column. Solves the problem of wasted gaps in between letters, and a simple AND could be used to mask off the unused top and bottom pixels to use them for other stuff. Having to preprocess the text before printing is a downside but at least it gives you an easy way of checking whether L needs to be incremented or not. I'll definitely be giving your routine a closer look.
1 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Compact 64 column print routine

Post by arkannoyed » Tue Mar 06, 2018 10:06 am

Bit 0 of each data byte is set as and end market for the print loop. Whereas we could use 3 bytes for each character, there are some that can be found within the data as a sort of bonus. As we’re only addressing the data within a 256 byte area, there’s the possibility to use direct address lo-bytes as the character codes. With some additional manual rearrangement of the data, I managed to save 45 bytes. I’m sure with some more tweaking I could more efficiently pack the data and find a few more matches within it, saving even more.

The way it decides when to inc to the next screen byte is a bit crude. We check the message position and inc to the next right byte when it’s on an even byte. There might be a better way to do it, I haven’t found one....yet.

So the main routine is 33 bytes and can manage to print within screen thirds, so could potentially do 512 characters at once.
1 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Compact 64 column print routine

Post by arkannoyed » Tue Mar 06, 2018 11:15 am

I knew there was a better way of deciding when to increment the screen address. Really its obvious!!

If we just /2 (SRA L) the screen address, then we divide the Lo-byte by 2, as we've 2 characters per byte printed.

The only downside is that we can now only print 256 characters in a single string, but thats still 4 lines of continuous text, so probably not much of a problem.

So now down to 31 bytes! :D

Code: Select all

start:
          ld d,0fah             ;Hi-byte of CHR set+ EOM marker
s_rpt:
          ld a,(bc)             ;get CHR code
          ld e,a                ;CHR code is x3 to save having to do it in routine
          cp d                  ;SUB 0FAh, use D reg value to mark the string end
          ret z                ;RET if 0FAh detected
          push bc               ;save MSG position
          ld b,04h              ;counter

          ld a,01h              ;set space line with end marker
pr_lp0:
          push hl
          sra l
          and a                  ;clear Carry
init0:
          inc h
          rl (hl)               ;bit into (HL)
          add a,a               ;next data BIT
          jr nz,init0           ;repeat if not 00

          pop hl                ;restore SCReen address
          ld a,(de)             ;get data byte
          inc e                 ;next
          djnz pr_lp0           ;next line

          pop bc                ;restore MGS address
          inc bc                ;next CHR byte
          inc l                 ;next SCR addr
          jr s_rpt              ;next CHR rpt.
1 x

Bizzley
Dizzy
Posts: 59
Joined: Thu Nov 16, 2017 10:47 am

Re: Compact 64 column print routine

Post by Bizzley » Tue Mar 06, 2018 11:42 am

Copied and Pasted your latest change and with a message string that is an odd length in size (like the example message used previously) the last character is printed in the wrong place. This might be down to my bad typing but can you check it out? Ta.
0 x

User avatar
arkannoyed
Microbot
Posts: 111
Joined: Mon Feb 05, 2018 9:56 am

Re: Compact 64 column print routine

Post by arkannoyed » Tue Mar 06, 2018 11:45 am

Yes, in cases where the last character gets spaced apart from the rest of the text, then add a space at the end (code A4h in this case), before the terminating code (FAh)

Sorry, should've mentioned that! :o
0 x

Post Reply