Programming Challenge

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

Programming Challenge

Post by RWAP » Wed May 10, 2017 10:45 am

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

https://codegolf.stackexchange.com/ques ... aele-cecco

Lardo Boffin
Posts: 655
Joined: Sat Nov 26, 2016 1:42 am

Re: Programming Challenge

Post by Lardo Boffin » Wed May 10, 2017 11:46 pm

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!
ZX81 iss 1 (bugged ROM, kludge fix, normal, kit)
Iss 3 with ZXVid, another in nearly perfect box
TS 1000 iss 3, ZXPand AY, ZX8-CCB & ZX-KDLX
TS 1500
TS 2000
Spectrum 16k (iss 1 s/n 1499)
Spectrum 48k
Toastrack + DIVMMC future

Lardo Boffin
Posts: 655
Joined: Sat Nov 26, 2016 1:42 am

Re: Programming Challenge

Post by Lardo Boffin » Thu May 11, 2017 3:33 pm

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 7 times
ZX81 iss 1 (bugged ROM, kludge fix, normal, kit)
Iss 3 with ZXVid, another in nearly perfect box
TS 1000 iss 3, ZXPand AY, ZX8-CCB & ZX-KDLX
TS 1500
TS 2000
Spectrum 16k (iss 1 s/n 1499)
Spectrum 48k
Toastrack + DIVMMC future

User avatar
PokeMon
Posts: 2169
Joined: Sat Sep 17, 2011 5:48 pm

Re: Programming Challenge

Post by PokeMon » Thu May 11, 2017 4: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. ;)

Lardo Boffin
Posts: 655
Joined: Sat Nov 26, 2016 1:42 am

Re: Programming Challenge

Post by Lardo Boffin » Thu May 11, 2017 4:25 pm

PokeMon wrote:
Thu May 11, 2017 4: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:
ZX81 iss 1 (bugged ROM, kludge fix, normal, kit)
Iss 3 with ZXVid, another in nearly perfect box
TS 1000 iss 3, ZXPand AY, ZX8-CCB & ZX-KDLX
TS 1500
TS 2000
Spectrum 16k (iss 1 s/n 1499)
Spectrum 48k
Toastrack + DIVMMC future

dr beep
Posts: 1047
Joined: Thu Jun 16, 2011 7:35 am
Location: Boxmeer

Re: Programming Challenge

Post by dr beep » Fri May 12, 2017 11:42 am

Lardo Boffin wrote:
Thu May 11, 2017 3: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: 655
Joined: Sat Nov 26, 2016 1:42 am

Re: Programming Challenge

Post by Lardo Boffin » Fri May 12, 2017 4:20 pm

dr beep wrote:
Fri May 12, 2017 11:42 am
Lardo Boffin wrote:
Thu May 11, 2017 3: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!
ZX81 iss 1 (bugged ROM, kludge fix, normal, kit)
Iss 3 with ZXVid, another in nearly perfect box
TS 1000 iss 3, ZXPand AY, ZX8-CCB & ZX-KDLX
TS 1500
TS 2000
Spectrum 16k (iss 1 s/n 1499)
Spectrum 48k
Toastrack + DIVMMC future

User avatar
PokeMon
Posts: 2169
Joined: Sat Sep 17, 2011 5:48 pm

Re: Programming Challenge

Post by PokeMon » Fri May 12, 2017 5:37 pm

Anyway - never use LD A,0 - XOR A instead.
Except you need the flags ...

Lardo Boffin
Posts: 655
Joined: Sat Nov 26, 2016 1:42 am

Re: Programming Challenge

Post by Lardo Boffin » Fri May 12, 2017 9:01 pm

PokeMon wrote:
Fri May 12, 2017 5: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!
ZX81 iss 1 (bugged ROM, kludge fix, normal, kit)
Iss 3 with ZXVid, another in nearly perfect box
TS 1000 iss 3, ZXPand AY, ZX8-CCB & ZX-KDLX
TS 1500
TS 2000
Spectrum 16k (iss 1 s/n 1499)
Spectrum 48k
Toastrack + DIVMMC future

User avatar
kmurta
Posts: 123
Joined: Tue Sep 01, 2009 4:04 am
Location: Belo Horizonte - BR
Contact:

Re: Programming Challenge

Post by kmurta » Fri May 12, 2017 9:25 pm

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 12 times
1 x ZX81, 2 x TK85 , 1 TK82C, 1 TK95, 1 x Ringo R470, 1 x Alphacom 32 printer, 1 x ZXpand
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest