Setting CRTC

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:

Setting CRTC

Post by Kitsune Mifune » Wed Nov 06, 2019 1:54 pm

Sorry if this seems really thick, but I've been trying to play around with the CRTC to adjust the screen width and get a 256x192 size, but I can't seem to get a grasp on how to input the register and values.

'c' sets the register right? and 'a' the value of the register? I've been trying to use the small CRTC function to do it but I'm just not seeing any change on the screen. I did have a look at the lesson but I was having a bit of trouble digesting it all, so I thought I'd just try something simple to start with.

I'm guessing it needs more than just this though. Also, I'm not quite sure if I'm calling it in the right place, but I did try it both inside my main loop and beforehand in the screen setup initialisation.

Code: Select all

SET_CRTC:
	ld c,&03	; Load Register (&03 = H & V Sync Widths)
	ld a,134 	; Load value (Set Speccy screen size of 256x192) %10000110 ; - 134

	ld b,&bc
	out (c),c
	inc b
	out (c),a
RET
Programming: 90% failures, 10% victories, and 100% hair loss!

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

Re: Setting CRTC

Post by akuyou » Wed Nov 06, 2019 8:36 pm

'Sync Width' is the size of the sync pulse (the offscreen bits) You want to change Reg 1 - Hdisp

This will change the width of the screen to 32 characters wide.

Code: Select all

	ld c,&01	; Load Register (&01 = H Disp)
	ld a,32 	; Load value (Set Speccy screen size of 32 chars)
	ld b,&bc
	out (c),c
	inc b
	out (c),a
Beware! The firmware screen routines is not going to be much use anymore though after this - it doesn't understand this screen layout.

Here's a full set of Speccy Screen registers to sort everything out. these were used in my platform specific series to set the screen up.

Code: Select all

		defb &3f	; R0 - Horizontal Total
		defb 32	 	; R1 - Horizontal Displayed  (32 chars wide)
		defb 42		; R2 - Horizontal Sync Position (centralises screen)
		defb &86	; R3 - Horizontal and Vertical Sync Widths
		defb 38		; R4 - Vertical Total
		defb 0		; R5 - Vertical Adjust
		defb 24		; R6 - Vertical Displayed (24 chars tall)
		defb 31		; R7 - Vertical Sync Position (centralises screen)
		defb 0		; R8 - Interlace
		defb 7		; R9 - Max Raster 
		defb 0		; R10 - Cursor (not used)
		defb 0		; R11 - Cursor (not used)
		defb &30	; R12 - Screen start (start at &c000)
		defb &00 	; R13 - Screen start
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: Setting CRTC

Post by Kitsune Mifune » Thu Nov 07, 2019 8:31 am

Excellent, I'll try this out when I get in tonight.

I'm actually just about to rip apart my sprite draw and screen setup routines to get rid of the firmware, so it's good timing.

I'm going to try and adapt your code in the "Bitmap Graphics on the Amstrad CPC" lesson, which admittedly is a little daunting but I think I know what to do.

One question about that last part though (I can start a new thread for this if need be): when I was using the firmware to get a screen position it used 'de' for X-Pos and 'hl' for Y-pos, but your one uses 'bc' for both. That's fine, but can I still use my variables in it if I separate the upper and lower parts? It's just so I can re-use the code for drawing and plotting multiple things as the player and enemies all have their own custom X/Y variables which will be loaded into the general SPRITE_XPOS/SPRITE_YPOS ones when they call the draw code.

Or would it be better to just make a new singular variable for all the objects like "SPRITE_XY"? ( I know I use a lot of variable labels as it helps my dyscalculia riddled brain read the code a lot easier, but I'll cut it down later).

Thanks again for all the help. I'd be lost without this forum.

eg:

Code: Select all

ld bc,&0350
; Becomes
ld bc,(SPRITE_XPOS,SPRITE_YPOS)
or

Code: Select all

ld bc,&0350
; Becomes
ld bc,(SPRITE_XY)
Programming: 90% failures, 10% victories, and 100% hair loss!

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

Re: Setting CRTC

Post by akuyou » Fri Nov 08, 2019 12:06 pm

The Amstrad code works in pixels, so the screen is 320x200
My code works in Bytes, so the screen is 80x200

Using just one bytes for co-ordinates is more efficient, as the 8 bit cpu works with bytes faster than words, but your characters will probably move too fast across the screen...

Oh, and if you're looking to get rid of the firware, here's a 'firmare free' version of the super simple BMP example just for you!
CPC_Bitmap_FirmwareFree.7z
(1.31 KiB) Downloaded 382 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: Setting CRTC

Post by Kitsune Mifune » Fri Nov 08, 2019 12:45 pm

Oh dude, you are a star!

I had literally just finished integrating your code from the lesson for the screen position (the GetScreenPos call to the code with the two screen tables) and it worked fine, but I was having bother writing something for the draw code to jump down a line to simulate the &BC26 firmware call. I had it half working but I couldn't get it complete.

This new code works beautifully, and everything looks great in the new Speccy screen size (the sprite was being diced earlier). Needless to say, the CRTC stuff you helped me with earlier works fine now too.

I'm going to try and really understand what everything is doing rather than just pasting it in and leaving it, but you've saved me a huge headache today, so once again thanks! :)
Programming: 90% failures, 10% victories, and 100% hair loss!

Post Reply

Return to “Amstrad CPC Assembly Programming”