Compact 64 column print routine

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Compact 64 column print routine

Post by Ast A. Moore »

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!!!!! :D
Damn clever, that! I was just thinking in more straightforward terms: LD IXh,D/LD D,IXh.
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.
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Compact 64 column print routine

Post by Ast A. Moore »

Morkin wrote: Thu Mar 22, 2018 1:30 pm
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 byte is sacred...! :D
Sir Clive gets quite ira–a–ate . . .
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.
User avatar
Einar Saukas
Bugaboo
Posts: 3070
Joined: Wed Nov 15, 2017 2:48 pm

Re: Compact 64 column print routine

Post by Einar Saukas »

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!!!!! :D
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.
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: Compact 64 column print routine

Post by arkannoyed »

Very true!

Sometimes we all have pointless goals!
User avatar
arkannoyed
Manic Miner
Posts: 435
Joined: Mon Feb 05, 2018 9:56 am
Location: Northamptonshire

Re: Compact 64 column print routine

Post by arkannoyed »

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
          
User avatar
Ast A. Moore
Rick Dangerous
Posts: 2640
Joined: Mon Nov 13, 2017 3:16 pm

Re: Compact 64 column print routine

Post by Ast A. Moore »

arkannoyed wrote: Thu Mar 22, 2018 3:56 pm a little bit faster
Now we’re talking!
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.
Post Reply