Some more Newbie questions

Post programming questions related to the CPC Here!
Post Reply
User avatar
Gee-k
Posts: 28
Joined: Sat May 04, 2019 9:35 am
Location: Scotland
Contact:

Some more Newbie questions

Post by Gee-k » Wed Feb 12, 2020 6:24 pm

Hi hi. It's been a while since I had time to even think about the program that i've been "writing" for months (aka. doing a few lines then putting it away for a few weeks and then coming back to it and doing a few more lines. Over and over.)

I'm looking to draw some images and have managed to follow the sprite routine in one of the chibi tutorials for the CPC. So I now have the start of my logo on screen and I can plonk it in the spot where I want it.
The thing i'm thinking about though is; Is this this best way to draw to the screen for a logo? or is there a quicker easier way?

Code: Select all

org &8000

ld de,&0010
ld hl,&00A0

call &BC1D

ld de,TestSprite
ld b,51

SpriteNextLine:
push hl
ld c,11	;width

SpriteNextByte:
ld a,(de)
ld (hl),a

inc de
inc hl

dec c
jr nz,SpriteNextByte

pop hl

call &bc26

djnz SpriteNextLine

ret

TestSprite:
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000
db %11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000
And yeah... I did hand write out the binary in notepad.
It's a bit large at the moment. I do have an edited down version on my home computer.

I have a feeling that this method should only be used for making sprites that move about the screen or are animated. But then again, thinking about it, it might be good for them to be sprites like this as I could then animate them slightly in the future if I wished to do so.

Everyones thoughts and feelings would be appreciated.
You don't fail, You learn how it's not done.
https://www.gee-k.net : Where I blog about my random geeky goings on.

User avatar
akuyou
Posts: 563
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Some more Newbie questions

Post by akuyou » Thu Feb 13, 2020 3:41 am

Theres no firmware function I know of to do the sprite for you

If you want 'Simpler' you could maybe use LDIR to copy each line, it copies BC bytes from HL to DE:

Code: Select all

	org &8000
	ld de,&0010
	ld hl,&00A0
	call &BC1D

	ex de,hl
	ld hl,TestSprite
	ld ixl,51
SpriteNextLine:
	push de
		ld bc,11	;width
		ldir 
	pop de
	ex de,hl
	call &bc26
	ex de,hl
	dec ixl
	jr nz, SpriteNextLine
ret
If you want 'Quicker' in terms of speed, you want probably want to misuse the stack like this
(note, I've added a zero byte to each line of your sprite to make it even

Code: Select all

	org &8000

	ld de,&0010
	ld hl,&00A0

	call &BC1D

	ld c,51		;Height

	di
	ld ix,0			;Back up stack pointer
	add ix,sp

	ld sp,TestSprite	;Misuse stack as a data reader
				;No PUSHES/POPS or CALLS possible
SpriteNextLine:
	ld b,6			;Width in bytes

	ld a,h	;Backup HL into IY
	ld iyh,a
	ld a,l
	ld iyl,a


SpriteNextByte:
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl
	djnz,SpriteNextByte


	ld a,iyl ;Get back HL
	ld l,a

	ld a,iyh ;Calculate Next Line
	add &08
	ld h,a
	bit 7,h	
	jp nz,GetNextLineDone
	ld a,&50
	add l
	ld l,a
	ld a,&c0
	adc h
	ld h,a	
GetNextLineDone:
	dec c
	jr nz, SpriteNextLine

	ld sp,ix	;Restore stack
	ei
ret

TestSprite:
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11100000,%00000000,%00000000,%00000000,%00000000,%01110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%10000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11000000,%00110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11100000,%00000000,%00000000,%00000000,%00000000,%00110000,%11110000,%11110000,%10000000,0
db %11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%01110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%10000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
db %00000000,%00000000,%00110000,%11110000,%11110000,%11110000,%11110000,%11110000,%11110000,%00000000,%00000000,0
Or even unwrap the loop for more speed!

Code: Select all

	org &8000

	ld de,&0010
	ld hl,&00A0

	call &BC1D

	ld iyl,51		;Height

	di
	ld ix,0			;Back up stack pointer
	add ix,sp

	ld sp,TestSprite	;Misuse stack as a data reader
				;No PUSHES/POPS or CALLS possible
SpriteNextLine:
	ld b,h	;Backup HL into BC
	ld c,l


SpriteNextByte:
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl
	pop de	;Pop 2 bytes off stack and show to screen
	ld (hl),e
	inc hl
	ld (hl),d
	inc hl

	ld h,b
	ld l,c

	ld a,h		;Calculate Next Line
	add &08
	ld h,a
	bit 7,h	
	jp nz,GetNextLineDone
	ld a,&50
	add l
	ld l,a
	ld a,&c0
	adc h
	ld h,a	
GetNextLineDone:
	dec iyl
	jr nz, SpriteNextLine

	ld sp,ix	;Restore stack
	ei
ret
I've just knocked these up in my lunchbreak, I'm sure someone out there can do better!
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

User avatar
Gee-k
Posts: 28
Joined: Sat May 04, 2019 9:35 am
Location: Scotland
Contact:

Re: Some more Newbie questions

Post by Gee-k » Thu Feb 13, 2020 7:58 am

akuyou wrote: Thu Feb 13, 2020 3:41 am I've just knocked these up in my lunchbreak, I'm sure someone out there can do better!
let me take a few days to look over what you've done to then understand it haha!
You don't fail, You learn how it's not done.
https://www.gee-k.net : Where I blog about my random geeky goings on.

User avatar
akuyou
Posts: 563
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Some more Newbie questions

Post by akuyou » Thu Feb 13, 2020 11:03 pm

Well to be fair, it's basically a simpler version of the code I had to figure out for ChibiAkumas, so I've done it before!

if you've not looked at it yet, take a look at this tutorial... it covers Stack Misuse and unwrapped loops

https://www.chibiakumas.com/z80/index.php#Lesson8

Good Luck!
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Post Reply

Return to “Amstrad CPC Assembly Programming”