It is currently Mon Oct 20, 2014 4:49 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Custom Video Modes
PostPosted: Mon Feb 20, 2012 12:36 am 
Offline
 Profile

Joined: Fri Nov 07, 2008 2:28 pm
Posts: 65
I've been playing around with custom video modes this weekend:

I've found the well documented 'Mode 8' set up for 80x256:

But what I really want is 160 x 128 so I get square pixels - can anybody suggest what I have to do to get that? The memory savings would really be useful!

How about non-integer scalings like 256x192 - but I don't want letter-boxing - I want the pixels to fill the screen (SNES style)?


- PJ


Code:
10 REM CREATE 'MODE 8'—
20 REM NOTE: NO WINDOWING ALLOWED
30 REM
40 REM NOTE: POKING VDU VARIABLES
50 REM IS GENERALLY ILL ADVISED.
6i MODE 5:REM BASIC MODE
70 REM CONFIGURE VIDEO ULA FOR 10 COLUMN, 16 CHARACTER
8i *FX 154,224
90 ?&360=&F:REM COLOUR MASK
l00 ?&361=1:REM PIXELS PER BYTE—i
110 ?&34F=&20:REM BYTES PER CHARACTER (4 wide x 8 hign
120 ?&363=&55:REM GRAPHICS RIGHT MASK
130 ?&362=&AA:REM GRAPHICS LEFT MASK
140 ?&30A=9:REM NO. OF CHARS PER LINE
150 VDU 20
160 REM DEMO
170 MOVE 0,0:DRAW 640,512:DRAW 1279,0
180 PRINT TAB(1,2);
190 A$="***HelloThere***"
200 COLOUR 129
210 FOR A%=1 TO 16
220  IF A%=9 THEN PRINT TAB(l,8);
230  COLOUR A%-1
240  PRINT MID$(A$,A%,l);
250  NEXT A%
260 PRINT



Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Mon Feb 20, 2012 1:15 am 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 7:02 pm
Posts: 273
PitfallJ wrote:
But what I really want is 160 x 128 so I get square pixels - can anybody suggest what I have to do to get that? The memory savings would really be useful!

The Beeb has no vertical line doubling, so 160x128 would be massively letterboxed and not even remotely square.

Quote:
How about non-integer scalings like 256x192 - but I don't want letter-boxing - I want the pixels to fill the screen (SNES style)?

This isn't possible either - the Beeb's pixel clocks are fairly fixed (16, 8, 4, and 2 MHz) so any custom modes like this will have fairly large vertical & horizontal borders.

If you want the smaller modes and are happy to put up with letterboxing, then you need to talk to the CRTC. The two important registers are R1 (horizontal displayed, in bytes per line - default is 80 in modes 0-3 and 40 in modes 4-7), and R6 (vertical displayed, in character lines - 32 in modes 0-6, 25 in mode 7). R2 and R7 are also important, as they control display position.

The basic code, to set up a 256x192 screen (assuming mode 1), is

Code:
LDA #1
STA $FE00
LDA #64     ;64 bytes per line
STA $FE01
LDA #6
STA $FE00
LDA #24     ;24 character lines, ie 192 lines
STA $FE01

You will need to have interrupts disabled while doing this.


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Mon Feb 20, 2012 1:22 am 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 6:46 pm
Posts: 380
Location: Málaga, Spain
Unfortunately you can't do what you want to do on a Beeb. The pixels are a fixed size, due to the fixed clock frequencies of the video hardware. It's possible to stretch the screen vertically on some VDUs, by simply reducing the number of lines in the PAL frame, e.g.
Code:
MODE 6
?&FE00=9:?&FE01=7

to give a 200 line screen which more or less fills the vertical space... but this won't work on all VDUs and will just result in an unsynched rolling display.

But a 256x192 screen is possible, only with a large-ish border. Many of the Ultimate games do this, e.g. Lunar Jetman, Knight Lore, Alien 8. Presumably to get the screen dimensions the same as the Speccy!


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Mon Feb 20, 2012 9:25 am 
Offline
 Profile

Joined: Tue Apr 08, 2008 11:50 pm
Posts: 12
Both the previous replies are bang on the money. The Beeb has flexible (up to a point) display hardware, but there are still some severe limitations.

The routines I have used here as my examples exactly duplicate the example given, just in a slightly different format.


The code I use to generate a mono display of 256 * 192, 6144 byte display. (In BeebASM assembler syntax). Could be changed to 'mode 1' to approximate some Spectrum games with a little bit of jiggery pokery. The CRTC registers are massaged to centre the display on the screen, meaning you have now got a wide distracting border around your picture. (Well, it's not that bad really).

Code:
;
; mode_setup
;
; setup 256 * 192 video resolution
; and other video chip settings
;
.mode_setup
  ldy #52
.vdu_loop
  lda vdu_stream-1,Y
  jsr oswrch%
  dey
  bne vdu_loop

  rts

; video chip settings
.vdu_stream
; alter v_sync to center the screen vertically
equb &00,&00,&00,&00,&00,&00,&1E,&07,&00,&17
; display height = 24 (characters)
equb &00,&00,&00,&00,&00,&00,&18,&06,&00,&17
; change h_sync to center the display horizontally
equb &00,&00,&00,&00,&00,&00,&2D,&02,&00,&17
; display width = 32 (characters)
equb &00,&00,&00,&00,&00,&00,&20,&01,&00,&17
; turn off cursor
equb &00,&00,&00,&00,&00,&00,&20,&0A,&00,&17
; mode 4
equb &04,&16


Here's a 'widescreen' low res four colour setup for a stalled project of mine. Reducing the screen resolution by so much meant I could have two screen buffers in a 32k Beeb. It initially used a line doubling routine to make the pixels square. (included). Not ideal or optimised, as I would draw the pixels on the odd lines then call the doubler routine. Very slow, as even the un-changed areas on screen are copied.

You will find it quicker for your routines to store the pixel data in consecutive screen addresses when plotting.

Either of these solutions is about the only way you will get a square display in the wide pixel modes with the Beeb hardware.

Unfortunately, this looks severely letterboxed, which is what I was aiming at, but may annoy some!

Code:
; set up 160 * 192 real pixel mode
.chunky_mode
; stream vdu chontrol codes to change to our new mode
  ldy #34
.my_mode
  lda vdu_stream-1,Y
  jsr oswrch%
  dey
  bne my_mode


  rts


.table_data

; data blocks for previous chunks of program that can
; also be destroyed once used.

.vdu_stream
; set colours
equb &00,&00,&00,&06,&02,&13
equb &00,&00,&00,&04,&01,&13
; alter video chip settings
; v_sync to centre screen vertically
equb &00,&00,&00,&00,&00,&00,&1E,&07,&00,&17
; vertical size (characters)
equb &00,&00,&00,&00,&00,&00,&18,&06,&00,&17
; mode 5
equb &05,&16

;
; make pixels in demo mode (160*96) square by copying raster lines
; expects 'screen' start address to be in zero page
; address pointed to by screen%
;
.double
  ldx #&1E
  ldy #&00
.double_loop
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  lda (screen%),y
  iny
  sta (screen%),y
  iny
  bne double_loop
  dex
  beq double_exit
  inc screen%+1
  bne double_loop
.double_exit
  rts


Up to you to furnish the plotting routines, otherwise you will just have blank black screens which do not help to demonstrate success. Also, you have to alter HIMEM and other system values if working in BASIC... or if your code tanks and the error message is displayed via the OS it will of course 'write' it on screen at TAB(0,0), start address of the originally selected donor mode... Demonstrated by repeated pressing of the <return> key until the screen 'wraparound' occurs and the message is displayed - depending on the number of lines you have taken off the display, you won't see the prompt appear until you have hit the <return> this number of times, very frustrating when the program has found itself in another near infinite loop and you don't get the prompt to appear after a hundred presses :o| (Can be fixed with handy pokes).


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Mon Feb 20, 2012 5:55 pm 
Offline
 Profile

Joined: Fri Nov 07, 2008 2:28 pm
Posts: 65
Thanks tons for all the examples - that's a great help to hopefully save myself some memory.

Too bad about the scale thing - I guess that's why I've never seen it in an existing game - I think Boffin had a interesting Mode1 variation where it actually had more than 320 pixels across - never saw that in another game...

- PJ


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Thu Jun 06, 2013 7:13 pm 
Offline
User avatar
 Profile

Joined: Mon Sep 14, 2009 7:50 pm
Posts: 91
Is there a way to do 200 (high - instead of 256) x 160 (wide) in 8/16 Colours ? and where would it be located in memory ? (same place with 4k free at the end, or 4k higher up in memory ? )

I don't mind if its a little letterboxed... Rich says something about VDU displays rolling at 200 lines though above....

Doing this, I might be able to save some memory (4k) if I get back on track with my Aquarius game in the future. (Use a 16K screen instead of 20K screen and would be the same as the c64 resolution then)

Thanks, Colin


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Thu Jun 06, 2013 10:05 pm 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 7:02 pm
Posts: 273
Easy! The below will shrink the screen to 200 lines, and put display start at $4000. This is assuming mode 0/1/2, if you want mode 4/5 then change the last LDA to #0c to put display start at $6000.
Code:
LDA #6
STA $FE00
LDA #25     ;25 character lines, ie 200 lines
STA $FE01
LDA #7
STA $FE00
LDA #$20    ;Adjust vertical screen position
STA $FE01
LDA #12
STA $FE00
LDA #08      ;Display start = $4000
STA $FE01


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Fri Jun 07, 2013 7:02 pm 
Offline
User avatar
 Profile

Joined: Mon Sep 14, 2009 7:50 pm
Posts: 91
Thanks Tom.... That seems to work, mostly, I will have to adjust (suss out !!) my video memory offset now, but it's looking good.... Thanks for the 4K ;-)

Right hand side shows the old 20K screen, Left is the 16K and Origonal Games Screen Resolution which now matches the C64... (with a bit of an offset !!)

Attachment:
resized_aqua.JPG [154.07 KiB]
Downloaded 89 times


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Fri Jun 07, 2013 8:21 pm 
Offline
User avatar
 Profile

Joined: Mon Sep 14, 2009 7:50 pm
Posts: 91
Right... sussed the Background, next the sprites....

I've added a screen clear too, but used an index for the value, so I can see the screen data area.... hence the 'garbage'

Attachment:
aq_sorted.JPG [77.98 KiB]
Downloaded 87 times


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Fri Jun 07, 2013 8:56 pm 
Offline
User avatar
 Profile

Joined: Mon Sep 14, 2009 7:50 pm
Posts: 91
So. Looks spot on now... ;-)

Attachment:
SPOT_ON.PNG [173.87 KiB]
Downloaded 86 times


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Sat Jun 08, 2013 11:54 am 
Offline
User avatar
 Profile

Joined: Tue Mar 04, 2008 6:38 pm
Posts: 25
Looks promising! :)

Did you ever finish the C64 version?


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Sun Jun 09, 2013 6:46 pm 
Offline
 Profile

Joined: Sun Jul 19, 2009 10:11 pm
Posts: 9
Hello Chaps,

So, if I want a 192 x 256 screen in mode 1 I can do this ;-

Code:
   10 MODE 1
   40 ?&FE00=1:?&FE01=48
   50 ?&FE00=10:?&FE01=32


But how do I know where screen memory starts and how do I centre it on the screen ?


Top
 
 Post subject: Re: Custom Video Modes
PostPosted: Sun Jun 09, 2013 9:28 pm 
Offline
User avatar
 Profile

Joined: Mon Jan 07, 2008 7:02 pm
Posts: 273
TopBanana wrote:
So, if I want a 192 x 256 screen in mode 1 I can do this ;-
Code:
   10 MODE 1
   40 ?&FE00=1:?&FE01=48
   50 ?&FE00=10:?&FE01=32

Think you mean
Code:
   10 MODE 1
   40 ?&FE00=1:?&FE01=48
   50 ?&FE00=6:?&FE01=32

Though line 50 is a bit redundant in this case.
Quote:
But how do I know where screen memory starts and how do I centre it on the screen ?

Screen memory starts exactly where it did before - &3000 - as you haven't moved it. CRTC regs 12 and 13 do that, you need to load them like :
Code:
?&FE00=13:?&FE01=(screen_start DIV 8) AND 255
?&FE00=12:?&FE01=(screen_start DIV 8) DIV 256

Screen position is determined by the sync position registers - 2 for horizontal, 7 for vertical. To centre a 192x256 4 colour screen you need :
Code:
?&FE00=2:?&FE01=&52

It's probably best not to do CRTC programming in BASIC incidentally, but in assembler with interrupts disabled.


Top
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron