I know it was a rethoric question but since you mentioned my name...
I believe the minimum implementation is 17 bytes
I know it was a rethoric question but since you mentioned my name...
* (Gets popcorn and waits for the optimization to begin)
It’s late and I’m tired, but I can’t for the life of me to get it below twenty:
Code: Select all
ld bc,352
ld de,$5800+352
ld hl,$5800
ld a,48
loop ld (hl),15
ld (de),a
inc de
cpi
jp pe,loop
Code: Select all
ld hl, $5800
ld de, $5801
ld bc, 352
ld (hl), 15
ldir
ld bc, 351
ld (hl), 48
ldir
Code: Select all
ld hl,$5800
ld a,15
call fill
ld a,48
fill ld bc,352
loop ld (hl),a
cpi
ret po
jr loop
On smaller, underpowered systems like the Spectrum, coding is always a compromise between optimizing for speed or size. Sometimes, both can be achieved simultaneously, but only if the code is not very optimized to begin with. I am much more skilled at optimizing for speed, rather than size, so take my suggestion with a grain of salt, but for the most part, the trick with many complex math calculations is to resort to look-up tables of pre-calculated values.TMD2003 wrote: ↑Sun Oct 04, 2020 3:49 pm seeing as the Z80 has to work out functions like SIN and EXP using simple arithmetic until the result fills up all the available decimal places correctly, I'll see if I can (eventually) translate the BASIC programs for the Euler-Mascheroni constant and the (very slowly converging) Gregory-Leibniz formula for pi.
Agreed!Dr beep wrote: ↑Sun Oct 04, 2020 5:05 pm
I would suggest a simple program that uses RST 16 to display a character and slowly expand that code into a moving character and finally a controlled moving character. This will give you ideas how to show progress and how input can be used in games.
First job is to get familiar with the input and output on a ZX Spectrum
Mostly, yes.
Well, this is a very specific case that has to do with the Spectrum’s operating system. BC (sometimes referred to as the Byte Counter) is used in block copy/compare/input/output operations and the B register itself is used by the DJNZ instruction.
DE (sometimes referred to as the DEstination) is also used in block copy operations and points to the destination address of a byte (or block of bytes) to be copied to.
HL is the most versatile of the register pairs. It is somewhat similar to the A register, as it is the place where the results of arithmetic operations will be stored (e.g. ADD HL,DE, SBC HL,BC). It is also the only register pair that can point to a byte in memory to be loaded directly with a value (e.g. LD (HL),n) or used in conjunction with the stack pointer SP.
Code: Select all
org $fefe
ld hl, 22528
ld de, 22528+352
ld bc, $610F
ld a, 48
call x1
x1:
call $0cf0
Cheater!
It strategically places the code so that the POP BC in the ROM’s subroutine loads the correct values into the B and C registers, namely—the low and high bytes of the memory address immediately after the CALL $0cf0 instruction.
Please do!