Programming Challenge
Programming Challenge
Has anyone thought about a ZX81 entry for the programming challenge at:
https://codegolf.stackexchange.com/ques ... aele-cecco
https://codegolf.stackexchange.com/ques ... aele-cecco
Rich Mellor
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module
Also Involved in:
Icephorm
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module
Also Involved in:
Icephorm
-
- Posts: 2256
- Joined: Sat Nov 26, 2016 2:42 am
Re: Programming Challenge
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!
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
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
-
- Posts: 2256
- Joined: Sat Nov 26, 2016 2:42 am
Re: Programming Challenge
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.
Still, its slightly lower than the Spectrum BASIC 187 bytes!
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: -
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
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.

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

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
Lardo
- Attachments
-
- hpybrthd.p
- (975 Bytes) Downloaded 322 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
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
Re: Programming Challenge
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. 

-
- Posts: 2256
- Joined: Sat Nov 26, 2016 2:42 am
Re: Programming Challenge
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!

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
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
Re: Programming Challenge
Above part Can be (-2)Lardo Boffin wrote: ↑Thu May 11, 2017 4:33 pmI 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.Code: Select all
ld a,(Line2Text+7) inc a cp 30 jr nz,notLooping ld a,0 notLooping ld (Line2Text+7),a jp main
Lardo
Code: Select all
ld a,(Line2Text+7)
inc a
seta ld (Line2Text+7),a
sub 30
jr z,seta
jp main
-
- Posts: 2256
- Joined: Sat Nov 26, 2016 2:42 am
Re: Programming Challenge
That's clever!dr beep wrote: ↑Fri May 12, 2017 12:42 pmAbove part Can be (-2)Lardo Boffin wrote: ↑Thu May 11, 2017 4:33 pmI 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.Code: Select all
ld a,(Line2Text+7) inc a cp 30 jr nz,notLooping ld a,0 notLooping ld (Line2Text+7),a jp main
Lardo
Code: Select all
ld a,(Line2Text+7) inc a seta ld (Line2Text+7),a sub 30 jr z,seta jp main
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
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
Re: Programming Challenge
Anyway - never use LD A,0 - XOR A instead.
Except you need the flags ...
Except you need the flags ...
-
- Posts: 2256
- Joined: Sat Nov 26, 2016 2:42 am
Re: Programming Challenge
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
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
Re: Programming Challenge
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'
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/
ZeXtender board, Joy81 - Programmable Joystick Controller, Turbo Sound 81
http://zx81.eu5.org
https://toddysoftware.itch.io/