Screen base in plotting code issue

Post programming questions related to the CPC Here!
Post Reply
Kitsune Mifune
Posts: 33
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Screen base in plotting code issue

Post by Kitsune Mifune » Wed Dec 09, 2020 10:17 am

Hi,

Thought I'd jump back on here as I have a specific question regarding the screen plotting code from the Lesson 6 video (Lookup tables).

My question is, do the screen bases in that code just tell the program where to draw the graphics? Or does it actually set the visible screen?

I'm asking because I'm trying to draw a sprite to memory location &4000 (away from the visible screen, which is manually set at &C000 by setting Reg 12 of the CRTC to &30 which I believe is &C000), but it seems to be spilling over to the visible screen every 8 lines and then going back again (see picture link below).

https://drive.google.com/file/d/15vrQ5t ... sp=sharing

There's nothing in my code that points to &C000 (bar CRTC Reg 12) so I'm unsure what's happening. All I've done is set the main screen base in the plotting code to &40 and the jump back to the top to &4040 (256 wide screen). In fact, it seems to spill over to the visible screen no matter what base address I put in, or even what the CRTC Register is set to.

I've made some great leaps and bounds in the last while with my coding and my game, but this has stumped me for about 4 days now, so any help would be great!

Thanks!
Programming: 90% failures, 10% victories, and 100% hair loss!

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

Re: Screen base in plotting code issue

Post by akuyou » Sun Dec 13, 2020 6:19 am

Looking at the glitch I think you need to change your newline code when you alter the screen base, For example here's the code I use for the screen base being &C000/&8000

The Bit 7 check will only work for the &C000 screen, it needs to be set to Bit 6 if the screen is at &8000
I'm not sure what it would need to be for a screen at &4000 - it's not a configuration I use as this basically makes using the extra 128k ram for sprites impossible.

I don't think the firmware functions can cope with a screen base anywhere except the default, so if you're using &BC26, you will have a problem

Code: Select all

GetNextLine:
	push af

		ld a,h		;Add &08 to H (each CPC line is &0800 bytes below the last
		add &08
		ld h,a
			;Every 8 lines we need to jump back to the top of the memory range to get the correct line
			;The code below will check if we need to do this - yes it's annoying but that's just the way the CPC screen is!
		bit 7,h		;Change this to bit 6,h if your screen is at &8000!
		jp nz,GetNextLineDone
		push bc
			ld bc,&c050	;if we got here we need to jump back to the top of the screen - the command here will do that
			add hl,bc
		pop bc
	GetNextLineDone:
	pop af
	ret
Update:
Ok, I set up a test program, and bit 6,h seems to work

sample attached
Attachments
CPC_Bitmap_FirmwareFree4000.7z
(1.47 KiB) Downloaded 322 times
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

Kitsune Mifune
Posts: 33
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Re: Screen base in plotting code issue

Post by Kitsune Mifune » Mon Dec 14, 2020 12:14 pm

Cheers Keith!

I've been messing around with Bank Switching using the Gate Array (just for practise, not in this current code), so that makes a lot of sense now that you say it, given the &4000 range.

I'm not using the Firmware at all now except to change the border colour and set the palette on initialisation, but I was thinking about getting rid of that too at some point as I now know how to do it by talking directly to the Gate Array (although it only works if I disable all the interrupts).

Anyway, I'm rambling. Thanks for the example. I'll look at it when I get in tonight. :)
Programming: 90% failures, 10% victories, and 100% hair loss!

Kitsune Mifune
Posts: 33
Joined: Tue Oct 22, 2019 6:46 am
Location: Glasgow
Contact:

Re: Screen base in plotting code issue

Post by Kitsune Mifune » Tue Dec 15, 2020 2:57 pm

Just a follow up:

Yep it seems to be working now, and it was the jump back address and the bit check. I was setting the jump back address to &4040, but just leaving it at &C040 and setting only the base address to &40 works.

Code: Select all

GETSCREENPOS:					; Return memory pos in HL of screen co-ord B,C (X,Y)

	push bc
		ld b,0				; Load B with 0 because we only want C
		ld hl,SCREEN_ADDRESS_TABLE
		add hl,bc			; We add twice, because each address has 2 bytes
		add hl,bc

		ld a,(hl)	
		inc l				;INC L not INC HL because we're byte aligned to 2
		ld h,(hl)
		ld l,a
	pop bc
		ld c,b				; Load the Xpos in ('b') into 'c'	
		ld a,(SCREEN_BASE)		; Our table is relative to 0 - so we need to add our screen base (&40)
		ld b,a
		add hl,bc			; This is so it can be used for alt screen buffers
RET

GETNEXTLINE:
		ld a,h
		add a,&08
		ld h,a
		bit 6,h				
		RET nz				

		ld bc,&C040			; If we got here we need to jump back...
		add hl,bc			; ...to the top of the screen - the command here will do that
RET
I also set up a little key press code in a loop to flick between the two ranges at &4000 and &C000 by changing CRTC Reg12 and it works quite well now, so I can see what's on both.

Code: Select all

LOOP:
		ld a,1			; RIGHT CURSOR KEY
		call &BB1E
		jr z, nopress1
			ld bc,&BC0C
			out (c),c	; Choose register (CRTC - R12)
			inc b
			ld a,&10
			out (c),a	; Send Value (&10 = &4000)
		nopress1:

		ld a,8			; LEFT CURSOR KEY
		call &BB1E	
		jr z, nopress2
			ld bc,&BC0C
			out (c),c	; Choose register (CRTC - R12)
			inc b
			ld a,&30
			out (c),a	; Send Value (&30 = &C000)
		nopress2:
	jr LOOP
	
Cheers for the help! :)
Programming: 90% failures, 10% victories, and 100% hair loss!

Post Reply

Return to “Amstrad CPC Assembly Programming”