Compact 64 column print routine
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Don't you just hate it when you find another place to save a byte...but it means reorganizing code for about an hour!
Oh, and how fortunate that the change to the routine and swapping a few registers around lets me hide the '3' character in there too, thus saving another byte!
Now fully working and down to 95 bytes!
I really need to comment the source, which I promise I'll do and tidy it up a bit.
Oh, and how fortunate that the change to the routine and swapping a few registers around lets me hide the '3' character in there too, thus saving another byte!
Now fully working and down to 95 bytes!
I really need to comment the source, which I promise I'll do and tidy it up a bit.
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
And heres the code, actually commented this time! Well, I suppose theres always a first time for everything!
Code: Select all
;15 bit 64 column format
;
;super compact 5 byte high characters
;
;BC holds screen address, HI-byte -1
;DE is message address
;End of Message byte is any value with BIT 7 set
;message must be an even number of characters long (padded with space if reqd.)
;Call routine at 0FA00h (64000d)
;
;97 bytes if we include the trailing 00h,00h (space CHR)
;95 bytes otherwise
;
;Characters A-Z...0-9..spc.
;
;Arkannoyed March 2018
;
;Special Thanks to Einar!
org 0f9fah
ld de,example_message
ld bc,3f00h ;screen address hi-byte must start -1
start:
ld a,(de) ;CHR byte into A
ld (get_bytes+1),a;write it to direct input (HL) load
inc de ;next CHR
add a,a ;test bit 7 for end marker
ret c ;RET if end of message
sbc a,h ;useless instruction!!
push bc ;together these 2 instructions create CHR 3 (9Ch,C5h)
;db %10011100,%11000101 ;3 code 56h ;9ch,0c5h
;3 = code 07h
get_bytes:
ld hl,(0fa00h) ;get 2 data bytes
lp0:
inc b ;down 1 screen line
ld a,(bc) ;SCReen byte into A
or 10h ;set the marker for 4 bits
add a,a ;add the space between chars
lp1:
add hl,hl ;propagate the data into the Carry
rla ;and then the result into A
jr nc,lp1 ;repeat if we've not put the marker into the Carry
ld (bc),a ;replace the SCReen byte
bit 2,b ;test if we've done 5 bytes
jr z,lp0 ;repeat if not
pop bc ;restore SCReen address
ld a,e ;message address LO byte into A
and 01h ;test if odd or even
add a,c ;add the result to A
ld c,a ;update the SCReen address
;db %11000110,%01110011 ;E code 20h ;0c6h,73h
add a,73h ;code for CHR E = doesn't do anything to affect the routine
db 18h ;jr start vector DCh which is the first byte of CHR D
db %11011100,%11010110 ;D code 23h ;0dch,0d6h
db %11011010,%01010111 ;A code 25h ;0dah,57h
db %01011100,%11010111 ;B code 27h ;5ch,0d7h
db %01000110,%01110010 ;C code 29h ;46h,72h
db %00100100,%01001001 ;I code 2bh * ;24h,49h
db %01110011 ;F code 2ch ;49h,73h
db %11010100,%01010110 ;O code 2eh * ;0d4h,56h
db %01110010 ;G code 2fh ;56h,72h
db %11011010,%10110111 ;H code 31h ;0dah,0b7h
db %00100100,%11101001 ;T code 33h * ;24h,0e9h
db %10110110 ;V code 34h ;0e9h,0b6h
db %11011100,%11100100 ;J code 36h ;0dch,0e4h
db %01011010,%10110111 ;K code 38h ;5ah,0b7h
db %01001110,%10010010 ;L code 3ah ;4eh,92h
db %11011010,%10111111 ;M code 3ch ;0dah,0bfh
db %01001000,%11010111 ;P code 3eh ;48h,0d7h
db %01011010,%11010111 ;R code 40h * ;5ah,0d7h
db %01010110 ;Q code 41h ;0d7h,56h
db %00011100,%01110001 ;S code 43h ;1ch,71h
db %11010100,%10110110 ;U code 45h ;0d4h,0b6h
db %11111010,%10110111 ;W code 47h ;0fah,0b7h
db %01011010,%10110101 ;X code 49h ;5ah,0b5h
db %00100100,%10110101 ;Y code 4bh ;24h,0b5h
db %01001110,%11100101 ;Z code 4dh ;4eh,0e5h
db %11011010,%11010110 ;N code 4fh * ;0dah,0d6h
db %11010110 ;0 code 50h ;0d6h,0d6h
db %00101110,%01011001 ;1 code 52h ;2eh,59h
db %01001110,%11000101 ;2 code 54h ;4eh,0c5h
db %00011100,%11110011 ;5 code 56h * ;1ch,0f3h
db %10010010 ;4 code 57h ;0f3h,92h
db %10100100,%11100100 ;7 code 59h ;0a4h,0e4h
db %10010100,%01010101 ;9 code 5bh * ;9ch,55h
db %01010101 ;8 code 5ch * ;55h,55h
db %01010011 ;6 code 5dh * ;55h,53h
db %00000000,%00000000 ;spc cd 5fh ;00h,00h
example_message:
db 25h,27h,29h,23h,20h,2ch,2fh,31h,2bh,36h,38h,3ah,3ch,4fh,2eh,3eh,41h,40h,43h,33h,45h,34h,47h,49h,4bh,4dh,50h,52h,54h,07h,57h,56h,5dh,59h,5ch,5bh,5fh,0ffh
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
..And probably the final one today, saving another byte by changing the shape of the '9' to share it with 'L'
94 bytes!
94 bytes!
Code: Select all
db %11011100,%11010110 ;D code 23h ;0dch,0d6h
db %11011010,%01010111 ;A code 25h ;0dah,57h
db %01011100,%11010111 ;B code 27h ;5ch,0d7h
db %01000110,%01110010 ;C code 29h ;46h,72h
db %00100100,%01001001 ;I code 2bh * ;24h,49h
db %01110011 ;F code 2ch ;49h,73h
db %11010100,%01010110 ;O code 2eh * ;0d4h,56h
db %01110010 ;G code 2fh ;56h,72h
db %11011010,%10110111 ;H code 31h ;0dah,0b7h
db %00100100,%11101001 ;T code 33h * ;24h,0e9h
db %10110110 ;V code 34h ;0e9h,0b6h
db %11011100,%11100100 ;J code 36h ;0dch,0e4h
db %01011010,%10110111 ;K code 38h ;5ah,0b7h
db %01001110,%10010010 ;L code 3ah ;4eh,92h
db %01010101 ;9 code 3bh * ;92h,55h
db %01010101 ;8 code 3ch * ;55h,55h
db %01010011 ;6 code 3dh * ;55h,53h
db %11011010,%10111111 ;M code 3fh ;0dah,0bfh
db %01001000,%11010111 ;P code 41h ;48h,0d7h
db %01011010,%11010111 ;R code 43h * ;5ah,0d7h
db %01010110 ;Q code 44h ;0d7h,56h
db %00011100,%01110001 ;S code 46h ;1ch,71h
db %11010100,%10110110 ;U code 48h ;0d4h,0b6h
db %11111010,%10110111 ;W code 4ah ;0fah,0b7h
db %01011010,%10110101 ;X code 4ch ;5ah,0b5h
db %00100100,%10110101 ;Y code 4eh ;24h,0b5h
db %01001110,%11100101 ;Z code 50h ;4eh,0e5h
db %11011010,%11010110 ;N code 52h * ;0dah,0d6h
db %11010110 ;0 code 53h ;0d6h,0d6h
db %00101110,%01011001 ;1 code 55h ;2eh,59h
db %01001110,%11000101 ;2 code 57h ;4eh,0c5h
db %00011100,%11110011 ;5 code 59h * ;1ch,0f3h
db %10010010 ;4 code 5ah ;0f3h,92h
db %10100100,%11100100 ;7 code 5ch ;0a4h,0e4h
db %00000000,%00000000 ;spc cd 5eh ;00h,00h
example_message:
db 25h,27h,29h,23h,20h,2ch,2fh,31h,2bh,36h,38h,3ah,3fh,52h,2eh,41h,44h,43h,46h,33h,48h,34h,4ah,4ch,4eh,50h,53h,55h,57h,07h,5ah,59h,3dh,5ch,3ch,3bh,5eh,0ffh
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Oh well! Never say never!
by sharing A and B, a slight modification to B, but it still looks like B!
93 bytes.
by sharing A and B, a slight modification to B, but it still looks like B!
93 bytes.
Code: Select all
db %11011100,%11010110 ;D code 23h ;0dch,0d6h
db %11011010,%01010111 ;A code 25h ;0dah,57h
db %11010111 ;B code 26h ;57h,0d7h
db %01000110,%01110010 ;C code 28h ;46h,72h
db %00100100,%01001001 ;I code 2ah * ;24h,49h
db %01110011 ;F code 2bh ;49h,73h
db %11010100,%01010110 ;O code 2dh * ;0d4h,56h
db %01110010 ;G code 2eh ;56h,72h
db %11011010,%10110111 ;H code 30h ;0dah,0b7h
db %00100100,%11101001 ;T code 32h * ;24h,0e9h
db %10110110 ;V code 33h ;0e9h,0b6h
db %11011100,%11100100 ;J code 35h ;0dch,0e4h
db %01011010,%10110111 ;K code 37h ;5ah,0b7h
db %01001110,%10010010 ;L code 39h ;4eh,92h
db %01010101 ;9 code 3ah * ;92h,55h
db %01010101 ;8 code 3bh * ;55h,55h
db %01010011 ;6 code 3ch * ;55h,53h
db %11011010,%10111111 ;M code 3eh ;0dah,0bfh
db %01001000,%11010111 ;P code 40h ;48h,0d7h
db %01011010,%11010111 ;R code 42h * ;5ah,0d7h
db %01010110 ;Q code 43h ;0d7h,56h
db %00011100,%01110001 ;S code 45h ;1ch,71h
db %11010100,%10110110 ;U code 47h ;0d4h,0b6h
db %11111010,%10110111 ;W code 49h ;0fah,0b7h
db %01011010,%10110101 ;X code 4bh ;5ah,0b5h
db %00100100,%10110101 ;Y code 4dh ;24h,0b5h
db %01001110,%11100101 ;Z code 4fh ;4eh,0e5h
db %11011010,%11010110 ;N code 51h * ;0dah,0d6h
db %11010110 ;0 code 52h ;0d6h,0d6h
db %00101110,%01011001 ;1 code 54h ;2eh,59h
db %01001110,%11000101 ;2 code 56h ;4eh,0c5h
db %00011100,%11110011 ;5 code 58h * ;1ch,0f3h
db %10010010 ;4 code 59h ;0f3h,92h
db %10100100,%11100100 ;7 code 5bh ;0a4h,0e4h
db %00000000,%00000000 ;spc cd 5dh ;00h,00h
example_message:
db 25h,26h,28h,23h,20h,2bh,2eh,30h,2ah,35h,37h,39h,3eh,51h,2dh,40h,43h,42h,45h,32h,47h,33h,49h,4bh,4dh,4fh,52h,54h,56h,07h,59h,58h,3ch,5bh,3bh,3ah,5dh,0ffh
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Now 92 bytes. Getting closer to Djnz48’s initial attempt of 89. Only 3 to go, though Im out of ideas as to where to save any more at the moment.
Re: Compact 64 column print routine
You can probably shave off 2 more bytes by changing your ORG address, so that 'get_bytes+1' matches the definition of a letter. Maybe W?
You can also reduce the overal footprint by using the 7th bit of the last char in message instead of adding an entire byte to end the message.
This will improve the footprint for each added message.
Alternatively you can concat messages and mark the first character 7th bit as terminator of previous message, if the test is not done on first char or is only done after processing increment.
NOTE :This obviously precludes single char messages.
You can also reduce the overal footprint by using the 7th bit of the last char in message instead of adding an entire byte to end the message.
This will improve the footprint for each added message.
Alternatively you can concat messages and mark the first character 7th bit as terminator of previous message, if the test is not done on first char or is only done after processing increment.
NOTE :This obviously precludes single char messages.
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Altering the way the message terminates is possible but not without making the routine larger. Nice idea regarding the address being substituted for a character data set, however it does seriously restrict the number of locations that the routine can be located at. Currently it can go pretty much anywhere. Even hidden in 3 attr blanked lines of the screen maybe at the bottom! We could cheat a little and use ‘S’ and ‘5’ A’s the same character, also ‘0’ and ‘O’, but I don’t like doing that. That would though take it under 90 bytes! I think 92 might just be about the best I can do. Maybe time to add in the lower case characters and see how it grows in size.
Re: Compact 64 column print routine
Have you considered using delta encoding to reduce the size of the font? In this modified font, each row only has up to four possible rows that can follow it. That means that you can store the first row using 3 bits, then use 2 bits each for the remaining four rows, giving 11 bits overall per character. It's still not a particularly nice size to work with, but it might be possible to find more characters that can be merged together with this method.
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Ahhh, yes, I like that. I have been considering some sort of compression, and I'd struggled to manage an overall improvement over the whole font. Although this makes a few changes that are less than ideal, its certainly a possibility. I've adapted a data structure from my 3D Chess engine, where the routine reads just 1 bit per byte. It relies upon being able to address only up to 32 bytes with interleaved data.
I've managed to encode 31 of 37 characters to fit within the allowed size so far. The routine to display them is currently 50 bytes.
Do, its incomplete, but a total of 50 bytes prog and 40 bytes data, making 90. The '5' and '0' could use 'S' and 'O' instead I suppose, and maybe even 'I' could be '1', which would save a bit more, but still fall just short.
I could encode this CHR set with its in line compression and see what I get.
I've managed to encode 31 of 37 characters to fit within the allowed size so far. The routine to display them is currently 50 bytes.
Do, its incomplete, but a total of 50 bytes prog and 40 bytes data, making 90. The '5' and '0' could use 'S' and 'O' instead I suppose, and maybe even 'I' could be '1', which would save a bit more, but still fall just short.
I could encode this CHR set with its in line compression and see what I get.
Re: Compact 64 column print routine
Eventually, but it shouldn't be very different, since we just need to test after processing the char.arkannoyed wrote: ↑Sun Mar 18, 2018 5:21 pm Altering the way the message terminates is possible but not without making the routine larger. ...
Probably just need to move a few instructions, and not much else (assuming we do not lose the contents of the string char).
If it's the test flag we need, a simple pair of EX.AF,AF' might do the trick.
The savings will come one byte for each extra message.
Making the code really dense, does not help you much if you have a lot more data than code. It's a balance, between the too.
Re: Compact 64 column print routine
If you want to move away from a direct representation of an alphabet..
Why not abstract it a level and use a visual representation of Morse.. that would dramatically reduce the code size.
super compact method...
Be really cold war 80s and use a combination of Morse, + one time number pad to generate your message thereby only needing the characters 0-9... Assuming you did it like a number station you would only need a few blocks of 5 digits. Very compact message encoding that way. But of course suffers from readability issues.
Why not abstract it a level and use a visual representation of Morse.. that would dramatically reduce the code size.
super compact method...
Be really cold war 80s and use a combination of Morse, + one time number pad to generate your message thereby only needing the characters 0-9... Assuming you did it like a number station you would only need a few blocks of 5 digits. Very compact message encoding that way. But of course suffers from readability issues.
Re: Compact 64 column print routine
I see another crap game entry!
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Isn't it annoying when you find a way of storing data in an even more efficient and compact way, but then can't get the routine to decode it small enough to make a difference! Grrrrrr!!!!!!!!
The data is now 41 bytes for the 37 characters, but the best I can do with the print routine is 54 bytes, giving a total of 95.
The data is now 41 bytes for the 37 characters, but the best I can do with the print routine is 54 bytes, giving a total of 95.
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
So, having failed so far to get any smaller than 92 bytes, though I do have some investigating to do in terms of decoding the data format, so I might still achieve a smaller size, I thought I'd do the obvious and alter the routine to actually manage without any CHR set data.
The Character codes are actually the bitmap for each character, so 32768 possible characters!
The only downside is that each character code is 2 bytes. This is fine if you've only a few lines of text to display perhaps.
Now the terminating character at the end of the message just has BIT 0 set to 1.
The print routine is now 31 bytes, CALLed with BC=message address, and DE= SCReen address (-1 from the Hi-byte)
The Character codes are actually the bitmap for each character, so 32768 possible characters!
The only downside is that each character code is 2 bytes. This is fine if you've only a few lines of text to display perhaps.
Now the terminating character at the end of the message just has BIT 0 set to 1.
The print routine is now 31 bytes, CALLed with BC=message address, and DE= SCReen address (-1 from the Hi-byte)
Code: Select all
;interleaved 3 bit data format for 64 column text
;using the actual data for the character instead
;of the character code
;BC=message address
;DE=SCReen address -1 from the Hi-byte
;messages terminate with BIT 0 of the second byte set
;all other letters MUST have BIT 0 as 0
;
;Arkannoyed March 2018
;
;31 bytes
;
org 0fa00h
ld bc,msg
ld de,3f00h
start:
ld a,(bc) ;get msg chr byte
ld h,a
inc bc
ld a,(bc)
ld l,a
inc bc
push de
lp0:
inc d
ld a,(de)
or 10h
add a,a
lp1:
add hl,hl
adc a,a
jr nc,lp1
ld (de),a
bit 2,d
jr z,lp0
pop de
add hl,hl
ret c
bit 1,c
jr nz,start
inc e
jr start
msg:
db %10110111,%11011010,%11110011,%01001110,%10010010,%01001110,%10010010,%01001110 ;HELL
db %01110110,%11011100,%00000000,%00000000,%11101001,%00100100,%01110110,%11011100 ;O TO
db %00000000,%00000000,%01110111,%11011010,%10010010,%01001110,%10010010,%01001110 ; ALL
db %00000000,%00000000,%01110111,%11011010,%11101001,%00100100,%00000000,%00000000 ; AT
db %01110001,%00011100,%11010111,%01001000,%11110011,%01001110,%01110010,%01000110 ;SPEC
db %11101001,%00100100,%11010111,%01011010,%10110110,%11011100,%10111111,%11011010 ;TRUM
db %00000000,%00000000,%01110010,%01000110,%01110110,%11011100,%10111111,%11011010 ; COM
db %11010111,%01001000,%10110110,%11011100,%11101001,%00100100,%11101001,%00101110 ;PUTI
db %11010110,%11011010,%01110010,%01010110,%01001001,%00000100,%00000000,%00000001 ;NG!
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Compact 64 column print routine
If you align your message with a 256-byte page boundary, you can speed things up by four T states per character by replacing the two INC BCs with INC Cs.
You could also gain 5 T states by storing D temporarily elsewhere (not the stack), but that’d add two bytes to the code, and I know you wouldn’t like that.
You could also gain 5 T states by storing D temporarily elsewhere (not the stack), but that’d add two bytes to the code, and I know you wouldn’t like that.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Yes, but I just wanted to keep it free to handle messages placed anywhere in memory, and speed isn't really the point of the exercise really!
I agree with you about having to PUSH/ POP stuff, irritates the hell out of me. In an ideal world, the routine would be fully relocatable, which it is, and ignore the stack completely, which it fails slightly on.
Given that your average CHR set is a few hundred bytes long, in cases where you're only perhaps going to print a few lines, and not too many different characters, even at 2 bytes per character, it'll be quite efficient. All its really doing is printing 3 x 5 bit sprites, with a 1 bit space between.
Actually this routine including the message and BC+DE to initialise it is only 109 bytes
Using the 92 byte version would add 37 bytes for the message and 6 to initialise it, giving 135 bytes!
I agree with you about having to PUSH/ POP stuff, irritates the hell out of me. In an ideal world, the routine would be fully relocatable, which it is, and ignore the stack completely, which it fails slightly on.
Given that your average CHR set is a few hundred bytes long, in cases where you're only perhaps going to print a few lines, and not too many different characters, even at 2 bytes per character, it'll be quite efficient. All its really doing is printing 3 x 5 bit sprites, with a 1 bit space between.
Actually this routine including the message and BC+DE to initialise it is only 109 bytes
Using the 92 byte version would add 37 bytes for the message and 6 to initialise it, giving 135 bytes!
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Compact 64 column print routine
Yes, when you just need to preserve a single 8-bit register, it seems wasteful.arkannoyed wrote: ↑Thu Mar 22, 2018 1:08 pm I agree with you about having to PUSH/ POP stuff, irritates the hell out of me.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
It could actually be achieved with 1 extra byte thus
RES 2,D
dec D
instead of PUSH DE & POP DE and then no need for the stack any longer, Freeeeeeeedddddoooooooommmmmmmm!!!!!
RES 2,D
dec D
instead of PUSH DE & POP DE and then no need for the stack any longer, Freeeeeeeedddddoooooooommmmmmmm!!!!!
Re: Compact 64 column print routine
Every byte is sacred...!Ast A. Moore wrote: ↑Thu Mar 22, 2018 1:24 pmYes, when you just need to preserve a single 8-bit register, it seems wasteful.arkannoyed wrote: ↑Thu Mar 22, 2018 1:08 pm I agree with you about having to PUSH/ POP stuff, irritates the hell out of me.
My Speccy site: thirdharmoniser.com
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Compact 64 column print routine
Damn clever, that! I was just thinking in more straightforward terms: LD IXh,D/LD D,IXh.arkannoyed wrote: ↑Thu Mar 22, 2018 1:28 pm It could actually be achieved with 1 extra byte thus
RES 2,D
dec D
instead of PUSH DE & POP DE and then no need for the stack any longer, Freeeeeeeedddddoooooooommmmmmmm!!!!!
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- Ast A. Moore
- Rick Dangerous
- Posts: 2641
- Joined: Mon Nov 13, 2017 3:16 pm
Re: Compact 64 column print routine
Sir Clive gets quite ira–a–ate . . .Morkin wrote: ↑Thu Mar 22, 2018 1:30 pmEvery byte is sacred...!Ast A. Moore wrote: ↑Thu Mar 22, 2018 1:24 pm Yes, when you just need to preserve a single 8-bit register, it seems wasteful.
Every man should plant a tree, build a house, and write a ZX Spectrum game.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
Author of A Yankee in Iraq, a 50 fps shoot-’em-up—the first game to utilize the floating bus on the +2A/+3,
and zasm Z80 Assembler syntax highlighter.
- Einar Saukas
- Bugaboo
- Posts: 3144
- Joined: Wed Nov 15, 2017 2:48 pm
Re: Compact 64 column print routine
Your routine is designed to be accessed with CALL (it exits with RET) so it's implicitly using the stack anyway. I see no advantage spending an extra byte to reduce stack usage.arkannoyed wrote: ↑Thu Mar 22, 2018 1:28 pm It could actually be achieved with 1 extra byte thus
RES 2,D
dec D
instead of PUSH DE & POP DE and then no need for the stack any longer, Freeeeeeeedddddoooooooommmmmmmm!!!!!
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Very true!
Sometimes we all have pointless goals!
Sometimes we all have pointless goals!
- arkannoyed
- Manic Miner
- Posts: 438
- Joined: Mon Feb 05, 2018 9:56 am
- Location: Northamptonshire
Re: Compact 64 column print routine
Same size (31 bytes), but a little bit faster as I've removed the central loop, where unrolling it is actually the same size!
Code: Select all
start:
ld a,(bc) ;get msg chr byte
ld h,a
inc bc
ld a,(bc)
ld l,a
inc bc
push de
lp0:
inc d
ld a,(de)
add a,a
add hl,hl
adc a,a
add hl,hl
adc a,a
add hl,hl
adc a,a
ld (de),a
bit 2,d
jr z,lp0
pop de
add hl,hl
ret c
bit 1,c
jr nz,start
inc e
jr start