Author Topic: Programming the CRTC  (Read 2784 times)

0 Members and 1 Guest are viewing this topic.

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.788
  • Country: gb
    • redbox
  • Liked: 406
  • Likes Given: 287
Programming the CRTC
« on: 00:21, 17 February 10 »
I want to setup the CRTC so that the display is shrunk from 40 chars wide to 38 and centred, such as:

Code: [Select]

ld bc,&bc00+1 ;CRTC register 1
out (c),c
ld bc,&bd00+38 ;set width to 38 characters
out (c),c

ld bc,&bc00+2 ;CRTC register 2
out (c),c
ld bc,&bd00+45 ;set horizontal position
out (c),c

I want to do this so that I can then have 1 char either side to print to which isn't visible (similar to when you stretch the width to 50 chars and only 48 are visible).  However, in this case I need to offset the video RAM so that the visible screen starts with &C002 and ends in &C04D.  Then I can write to &C000/1 and &C04E/F without it being seen on the screen.

Is this possible?

Offline Trebmint

  • 464 Plus
  • *****
  • Posts: 466
  • Country: zw
  • Liked: 326
  • Likes Given: 32
Re: Programming the CRTC
« Reply #1 on: 00:38, 17 February 10 »
I assume you're still talking the plus? Therefore you can use the bit 7 of 6804h to mask out the software scroll which turns the first 2 bytes of every line to the border colour. You should in theory only need to do this on one side of the screen not both

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.788
  • Country: gb
    • redbox
  • Liked: 406
  • Likes Given: 287
Re: Programming the CRTC
« Reply #2 on: 01:05, 17 February 10 »
I assume you're still talking the plus? Therefore you can use the bit 7 of 6804h to mask out the software scroll which turns the first 2 bytes of every line to the border colour. You should in theory only need to do this on one side of the screen not both

Yes, I do mean on the Plus and I haven't seen about bit 7 before, will give it a go.

I found an example in the RP11 Diagnostic Cartridge:

Code: [Select]
        ld      a,80h                   ;bring border in by 2
        ld      (6804h),a

        ld      bc,0BC06h
        out     (c),c                   ;point at 6845 vertical displayed reg

        ld      bc,0BD18h               ;normally its 19h (25), make it 24
        out     (c),c                   ;brings bottom border up


Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.788
  • Country: gb
    • redbox
  • Liked: 406
  • Likes Given: 287
Re: Programming the CRTC
« Reply #3 on: 01:15, 17 February 10 »
Appears to work perfectly.

Thanks!

Offline Trebmint

  • 464 Plus
  • *****
  • Posts: 466
  • Country: zw
  • Liked: 326
  • Likes Given: 32
Re: Programming the CRTC
« Reply #4 on: 10:54, 17 February 10 »
If you have the border wrap sorted you can set the screen up to use the magic 32x32 character dimensions for 16384 bytes that gives you the ideal scroller. Plus since it's MOD 32 it makes calculating the charcter positions so much easier.

screentop + ((x_char_pos mod 32)*2) + ((y_char_pos mod 32)*64)

Thats correct isn't it?

Offline redbox

  • Supporter
  • 6128 Plus
  • *
  • Posts: 1.788
  • Country: gb
    • redbox
  • Liked: 406
  • Likes Given: 287
Re: Programming the CRTC
« Reply #5 on: 12:39, 17 February 10 »
If you have the border wrap sorted you can set the screen up to use the magic 32x32 character dimensions for 16384 bytes that gives you the ideal scroller. Plus since it's MOD 32 it makes calculating the charcter positions so much easier.

Yes, I was thinking about this when reading the wiki entries for hardware scrolling and fast sprites on a normal CPC.

I have been writing the routine so that you can scroll left or right from any point and it deals with the wrap around when it occurs.  I do realise though that if I use the 32x32 size screen and only allow scrolling back left once you've gone right I can avoid the wrap around which will make things much faster.  However, this does limit the number of 'screens' you can use for the width of the playing area, but it might be worth it for the speed increase?

If I use the bit 7 trick to hide the first two characters of the border, wouldn't this reduce the visible area to 30x32 though, which is quite small...?

screentop + ((x_char_pos mod 32)*2) + ((y_char_pos mod 32)*64)

Looks right to me, although I haven't been using software sprites yet :)

Offline Trebmint

  • 464 Plus
  • *****
  • Posts: 466
  • Country: zw
  • Liked: 326
  • Likes Given: 32
Re: Programming the CRTC
« Reply #6 on: 15:06, 17 February 10 »
the bit 7 only covers 1 character so it would be 31x32. Really means you can draw just 1 byte width at a time for a vertical strip, which is annoying, but adequate whn doing a 50fps update (not going to move 100 fat pixels a second are you!)

Offline Geco

  • CPC664
  • ***
  • Posts: 78
  • Country: hu
  • Liked: 63
  • Likes Given: 5
Re: Programming the CRTC
« Reply #7 on: 14:27, 07 March 16 »
Hello

I would like to ask if the following code is working on a real CPC also, or can cause HW error ( as I read that writing to &BExx port can cause error) and I should change to other solution?

Code: [Select]
crtcreg ld      a,(hl)
        inc     hl
        or      a
        ret     z
        ld      b,0bdh
crtcwrt outi
        ld      b,0beh
        outi
        dec     a
        jr      nz,crtcwrt
For me it is strange behaviour, but it works on emulators in in this setup, for all other registers I used the normal port values.

Offline arnoldemu

  • Supporter
  • 6128 Plus
  • *
  • Posts: 5.336
  • Country: gb
    • Unofficial Amstrad WWW Resource
  • Liked: 2280
  • Likes Given: 3478
Re: Programming the CRTC
« Reply #8 on: 15:37, 07 March 16 »
Hello

I would like to ask if the following code is working on a real CPC also, or can cause HW error ( as I read that writing to &BExx port can cause error) and I should change to other solution?

Code: [Select]
crtcreg ld      a,(hl)
        inc     hl
        or      a
        ret     z
        ld      b,0bdh
crtcwrt outi
        ld      b,0beh
        outi
        dec     a
        jr      nz,crtcwrt
For me it is strange behaviour, but it works on emulators in in this setup, for all other registers I used the normal port values.
outi decrements b before using the port.
So bd becomes bc and be becomes bd. Code is good.

My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Offline Geco

  • CPC664
  • ***
  • Posts: 78
  • Country: hu
  • Liked: 63
  • Likes Given: 5
Re: Programming the CRTC
« Reply #9 on: 16:37, 07 March 16 »
Thank you very much, I thought that it decrements after :oops: