Programming Challenge

Discussion about ZX80 / ZX81 Software
RWAP
Posts: 1348
Joined: Thu May 08, 2008 8:42 am
Location: Stoke-on-Trent, UK
Contact:

Programming Challenge

Post by RWAP »

Has anyone thought about a ZX81 entry for the programming challenge at:

https://codegolf.stackexchange.com/ques ... aele-cecco
Lardo Boffin
Posts: 2160
Joined: Sat Nov 26, 2016 2:42 am

Re: Programming Challenge

Post by Lardo Boffin »

I think I will give it a go in Z80 and see how far I get!

I am currently up to 118 bytes to get the message on the screen as required (including code for a pause).

Now I just need to get the message text to shift one character every time the pause ends...

Or put another way - just the hard bit to do!
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
Lardo Boffin
Posts: 2160
Joined: Sat Nov 26, 2016 2:42 am

Re: Programming Challenge

Post by Lardo Boffin »

Well, here is my attempt.

I make it 164 bytes based on the start of the line 0 REM and ending with the second line's end of line $76 character. I'm sure I could reduce this by 10 to 20 bytes but maybe another day.... Its just occurred to me I probably don't need the $FF at the end of the text string either so that should 163 bytes. :oops:

Still, its slightly lower than the Spectrum BASIC 187 bytes! :P

This runs on a 1K zeddy in EightyOne emulator but I have not had time to try it on actual hardware yet.

I don't have an account on the code golf website so I guess this is as far as it goes!

The source code: -

Code: Select all

main	
	ld hl,happyBirthday
	ld bc,(Line2Text+7)
	add hl,bc
	ex de,hl
	ld b,12
 	ld hl,(D_FILE)
	inc hl
firstLine
	ld a,(de)
	ld (hl),a
	inc hl
	inc de
	djnz firstLine
	ld b,4
	dec hl
rightVertical
	push de
	ld de,13
	add hl,de
	pop de
	ld a,(de)
	ld (hl),a	
	inc de	
	djnz rightVertical
	dec hl
	ld b,11
lastLine
	ld a,(de)
	ld (hl),a
	dec hl
	inc de
	djnz lastLine
	ld b,3
	inc hl
leftVertical
	push de
	ld de,13
	sbc hl,de
	pop de
	ld a,(de)
	ld (hl),a	
	inc de	
	djnz leftVertical
	
delayCode
	ld   hl,FRAMES         ; fetch timer                 
   	ld   a,(hl)                                          
    	sub  10                ; wait 10 full frames (0.1 of a second)
delayLoop        
	cp  (hl) 
    	jr   nz,delayLoop
endOfMain	
	ld a,(Line2Text+7)
	inc a
	cp 30
	jr nz,notLooping
	ld a,0
notLooping	
	ld (Line2Text+7),a
	jp main
happyBirthday
	DEFB	_H,_A,_P,_P,_Y,__,_B,_I,_R,_T,_H,_D,_A,_Y,__,_R,_A,_F,_F,_A,_E,_L,_E,__,_C,_E,_C,_C,_O,__,_H,_A,_P,_P,_Y,__,_B,_I,_R,_T,_H,_D,_A,_Y,__,_R,_A,_F,_F,_A,_E,_L,_E,__,_C,_E,_C,_C,_O,__,$ff
I haven't included the bits to add in line 1 and line 2 etc. but have included the bytes they take up in the byte count.

Lardo
Attachments
hpybrthd.p
(975 Bytes) Downloaded 225 times
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Programming Challenge

Post by PokeMon »

Well you could spar a few bytes with using LDIR or at least LDI instruction for moving data. See Z80 manual/datasheet. And the last part contains two identical strings - this can be shortened with resetting pointers. ;)
Lardo Boffin
Posts: 2160
Joined: Sat Nov 26, 2016 2:42 am

Re: Programming Challenge

Post by Lardo Boffin »

PokeMon wrote: Thu May 11, 2017 5:15 pm Well you could spar a few bytes with using LDIR or at least LDI instruction for moving data. See Z80 manual/datasheet. And the last part contains two identical strings - this can be shortened with resetting pointers. ;)
Yes - the string was where I figured I could save a good few bytes. I doubled the size to make it easier to code and avoid wrap arounds. In my defence I got to that bit at around midnight last night and had run out of brain power! :shock:
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
dr beep
Posts: 2060
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Programming Challenge

Post by dr beep »

Lardo Boffin wrote: Thu May 11, 2017 4:33 pm

Code: Select all

	ld a,(Line2Text+7)
	inc a
	cp 30
	jr nz,notLooping
	ld a,0
notLooping	
	ld (Line2Text+7),a
	jp main
I haven't included the bits to add in line 1 and line 2 etc. but have included the bytes they take up in the byte count.

Lardo
Above part Can be (-2)

Code: Select all

	ld a,(Line2Text+7)
	inc a
seta	ld (Line2Text+7),a
	sub 30
	jr z,seta
	jp main
Lardo Boffin
Posts: 2160
Joined: Sat Nov 26, 2016 2:42 am

Re: Programming Challenge

Post by Lardo Boffin »

dr beep wrote: Fri May 12, 2017 12:42 pm
Lardo Boffin wrote: Thu May 11, 2017 4:33 pm

Code: Select all

	ld a,(Line2Text+7)
	inc a
	cp 30
	jr nz,notLooping
	ld a,0
notLooping	
	ld (Line2Text+7),a
	jp main
I haven't included the bits to add in line 1 and line 2 etc. but have included the bytes they take up in the byte count.

Lardo
Above part Can be (-2)

Code: Select all

	ld a,(Line2Text+7)
	inc a
seta	ld (Line2Text+7),a
	sub 30
	jr z,seta
	jp main
That's clever!
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
PokeMon
Posts: 2264
Joined: Sat Sep 17, 2011 6:48 pm

Re: Programming Challenge

Post by PokeMon »

Anyway - never use LD A,0 - XOR A instead.
Except you need the flags ...
Lardo Boffin
Posts: 2160
Joined: Sat Nov 26, 2016 2:42 am

Re: Programming Challenge

Post by Lardo Boffin »

PokeMon wrote: Fri May 12, 2017 6:37 pm Anyway - never use LD A,0 - XOR A instead.
Except you need the flags ...
You are correct - I had since changed that one!
ZX80
ZX81 iss 1 (bugged ROM, kludge fix, normal, rebuilt)
TS 1000 iss 3, ZXPand AY and +, ZX8-CCB, ZX-KDLX & ChromaSCART
Tatung 81 + Wespi
TS 1500 & 2000
Spectrum 16k (iss 1 s/n 862)
Spectrum 48ks plus a DIVMMC future and SPECTRA
User avatar
kmurta
Posts: 302
Joined: Tue Sep 01, 2009 5:04 am
Location: Belo Horizonte - BR
Contact:

Re: Programming Challenge

Post by kmurta »

An other option, with 144 bytes in two Basic lines (123 bytes of z80 codes):

Code: Select all

upside:
        ld hl,msg
        ld de,(16396)   ; screen address
        inc de
        ld bc,12
        ldir

rightside:
        ex de,hl
        dec hl
        ld b,4
rsloop:
        push bc
        ld bc,33
        add hl,bc
        ld a,(de)
        ld (hl),a
        inc de
        pop bc
        djnz rsloop

underside:
        ex de,hl
        ld bc,13
        add hl,bc
        dec bc
        lddr

leftside:
        ex de,hl
        inc hl
        ld b,3

lsloop:
        push bc
        ld bc,33
        sbc hl,bc
        ld a,(de)
        ld (hl),a
        dec de
        pop bc
        djnz lsloop

rotatemsg:
        ld hl,msg
        ld d,h
        ld e,l
        ld a,(hl)
        push af
        ld a,(msg+29)
        inc hl
        ld bc,14
        ldir
        ld hl,msg+28
        ld d,h
        ld e,l
        inc de
        ld bc,14
        lddr
        ld (hl),a
        pop af
        ld (de),a

delay:
        ld hl,FRAMES
        ld a,(hl)
        sub 10
dlyloop:
        cp (hl)
        jr nz,dlyloop

        jr upside

msg:    dbzx 'HAPPY BIRTHDAY  OCCEC ELEAFFAR'
rcecco.p
(1022 Bytes) Downloaded 243 times
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/
Post Reply