Кодинг для Спектрум и 8бит

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Кодинг для Спектрум и 8бит » Программирование » Задача от Z80 Assembly Programming On The ZX Spectrum


Задача от Z80 Assembly Programming On The ZX Spectrum

Сообщений 1 страница 11 из 11

1

https://scontent-arn2-1.xx.fbcdn.net/v/t1.0-9/41688304_10205078314513207_7174303935195250688_n.jpg?_nc_cat=0&oh=729b17b378f14cc5b936e2addeb2a3d7&oe=5C1DEE21

I miss programming challenges over here, so I'd like to propose one, actually a mini-challenge:

Write a program which paints the following image. Smallest code wins.
Border colour is not relevant.
Square colours are black and bright white. Whether you begin with a white or black square is not relevant.
The program will not return to its caller, keeping the image steady.
The program must be able to run from a ROM memory (so no self-modifying code here)
If a ROM routine is used, its size must be added to the count.
Register values upon program entry are undefined.
Memory content outisde the program is undefined. This includes screen content.
Program must be able to work if assembling it and running it from any location, except range 4000h - 5AFFh

Entries accepted until Sunday, 23:00h GMT . Then, claiming winner (and all participants) must disclose source code.

I've come up with a solution in 24 bytes.

2

У меня пока 18 байт.

3

у меня 17 с jr $.

4

Два таки показали:

Код:
_main:
xor a ; 4t,1b - a=0
ld hl,$5AFF ; 10t,3b - end of attributes memory
_oloop:
ld b,32 ; 7t,2b
_loop:
cpl ; 4t,1b - flip between white $ff and black $00
ld (hl),a ; 7t,1b
dec hl ; 6t,1b
djnz _loop ; 13/8t,2b
cpl ; 4t,1b - extra flip each row to get checker board
bit 3,h ; 8t,2b - check if dropped into pixel space h=$57
jr nz,_oloop ; 12/7t,2b - if >$57 keep going, otherwise end
_endless:
jr _endless ; 12t,2b - loop for eternity or reset whichever sooner
Управление
Нравится · Ответить · Показать перевод · 29 мин.
Tom Dalby
Tom Dalby My 13bytes version which works ok in 48k at least but is useless if you want to do anything else. Not sure writing to the buffers and maybe even the stack is a good idea and may cause crashes but I've left this running at org $8000 and it seems to work ok

_main:
xor a ; 4t,1b - a=0
ld l,a ; 4t,1b
ld h,a ; 4t,1b - make hl=0 so it writes to screen first then overwrites rest of memory up to this code
_oloop:
ld b,32 ; 7t,2b - one row
_loop:
cpl ; 4t,1b - flip between white and black
ld (hl),a ; 7t,1b - into memory
inc hl ; 6t,1b - next mem
djnz _loop ; 13/8t,2b - loop x32
cpl ; 4t,1b - each row requires extra flip for checker board
jr _oloop ; 12t,2b - keeps going till reaches this code then overwrites up to ld (hl),a and then just loops over nop (0) & RST 38H ($ff interrupt) forever

5

Код:
Alex Raider One more entry, different code, also 12 bytes
device zxspectrum48

org #8000

start:	
ld a,l ;1
rrca ;1
sbc a,a ;1

bit 5,l ;2
jr nz, $+3 ;2	
cpl ;1	

ld (hl),a ;1
inc hl ;1
jr start ;2 12 bytes total 

savesna "checkerboard.sna",start

6

Shinny написал(а):

Alex Raider One more entry, different code, also 12 bytes
device zxspectrum48

org #8000

start:
ld a,l ;1
rrca ;1
sbc a,a ;1

bit 5,l ;2
jr nz, $+3 ;2
cpl ;1

ld (hl),a ;1
inc hl ;1
jr start ;2 12 bytes total

savesna "checkerboard.sna",start


Хм. Вроде как код зависит от содержимого регистра HL перед стартом. Если в нем значение выше #5B00, и ниже адреса начала кода, код просто затрет сам себя, не отрисовав никакой картинки.

Отредактировано Jack (2018-09-15 15:58:00)

7

Shinny написал(а):

_main:
xor a ; 4t,1b - a=0
ld l,a ; 4t,1b
ld h,a ; 4t,1b - make hl=0 so it writes to screen first then overwrites rest of memory up to this code
_oloop:
ld b,32 ; 7t,2b - one row
_loop:
cpl ; 4t,1b - flip between white and black
ld (hl),a ; 7t,1b - into memory
inc hl ; 6t,1b - next mem
djnz _loop ; 13/8t,2b - loop x32
cpl ; 4t,1b - each row requires extra flip for checker board
jr _oloop ; 12t,2b - keeps going till reaches this code then overwrites up to ld (hl),a and then just loops over nop (0) & RST 38H ($ff interrupt) forever

Этот код самомодифицируется, хоть и будет работать в ПЗУ.

8

Чото намудрили с правилами. Вот мой вариант:

Код:
;compile with sjasmplus
	device zxspectrum128
        ORG #6000
begin


 ld hl,$5B00
 ;ld h,$5B
 xor a
m2:
 cpl
 ld b,16*2
m1:
 dec hl
 ld (hl),a
 cpl
 djnz m1
 cp (hl)
 jr nz,m2
	jr $
end
	display /d,end-begin
	savesna "!void.sna",begin


Хотя неясно, нужен ret или нет.

9

ret не нужен. Мои варианты:

ORG $8000

XOR A
LD HL,$5C00
LD C,H
L2 LD B,32
L1 DEC HL
LD (HL),A
CPL
DJNZ L1
CPL
DEC C
JR NZ,L2
L3 JR L3

ORG $8000

ld sp,$5c00
xor a
ld c,a
l2 ld b,16

ld h,a
cpl
ld l,a
l1 push hl
djnz l1
dec c
jr nz,l2
l3 jr l3

10

Завтра завершится срок приема работ. Надо будет подождать.

11

похожее на моё, но немного другое решение:

Код:
di
ld	hl,23296
xor	a
l1:	ld	b,32
l2:	dec	hl
ld	(hl),a
cpl
djnz	l2
cpl
cp	h
jr	nz,l1
halt

Вы здесь » Кодинг для Спектрум и 8бит » Программирование » Задача от Z80 Assembly Programming On The ZX Spectrum