English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 09 March 2015, 22:06   #1
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
Question Detect NTSC or PAL

Hi!

I've been following this section with joy and for a few years ago I decided to re-boot my coding on Amiga. After some routines and effect made in assembler I found that the init-code that I was using was *erhm*, well, not that system friendly.

I started to write a brand new init-code and so far so good. Since I have a Indivision AGA MK1 I use two different modes. NTSC for Workbench and PAL for games/demos. It might be a better way but since the Indivison only supports either PAL, NTSC or HighGFX I had to used one for each "mode".

One part of the init-code should contain a routine that detects the original screen mode and saves it when a "Indivision" flag is defined in the top of the code.

This was harder than I though. No matter what I do, I get PAL??!

I made a quick routine where I test different to detect the screen and it looks like the code below.

When it is executed D0 returns with the value $00320032 (50 50) and gd_DisplayFlags sets D1 to $00000014 (picture CRSnap007.png).

Code:
; *******************************************
;	$VER: LibraryTest.s  0.1 (09.03.15)
;	AUTHOR: Highpuff iKod.se
; *******************************************

		incdir	"include:old/"
		;include "dos/dos_lib.i"
		include	"exec/exec_lib.i"
		include "graphics/graphics_lib.i"

		;include	"dos/dosextens.i"
		include	"exec/execbase.i"
		include	"graphics/gfxbase.i"


; *********************************************
;		Main Code AREA
; *********************************************

		Section MainCode,code

MainCode:	movem.l	d0-a6,-(sp)

		move.l	$4.w,a6
		move.l	a6,Execbase

		lea.l	GfxName,a1
		moveq	#39,d0
		jsr	_LVOOpenLibrary(a6)
		beq	.Error
		move.l	d0,Gfxbase
		
		lea.l	DosName,a1
		moveq	#39,d0
		jsr	_LVOOpenLibrary(a6)
		beq	.Error
		move.l	d0,Dosbase

		clr.l	d0
		clr.l	d1

		move.l	Execbase,a6
		move.b	PowerSupplyFrequency(a6),d0
		swap	d0
		move.b	VBlankFrequency(a6),d0

		move.l	Gfxbase,a6
		move.w	gb_DisplayFlags(a6),d1
		
		move.l	Gfxbase,d0
		beq	.noGfxLib
		move.l	d0,a1
		jsr	_LVOCloseLibrary(a6)
.noGfxLib:
		move.l	Dosbase,d0
		beq	.noDosLib
		move.l	d0,a1
		jsr	_LVOCloseLibrary(a6)
.noDosLib:

.Error:		movem.l	(sp)+,d0-a6
		rts
		
; *********************************************
;		Data AREA
; *********************************************

		Section	MainData,data

MainData:
		dc.b	"$VER: LibraryTest.s 0.1 (09.03.15)",0
GfxName:	dc.b	"graphics.library",0
DosName:	dc.b	"dos.library",0

		cnop	0,4

Execbase:	dc.l	0
Gfxbase:	dc.l	0
Dosbase:	dc.l	0

		end
My Amiga has the following specification:
  • Amiga 4000 Desktop
  • Phase 5 Cyberstorm PPC 060/50Mhz 128MB RAM
  • Phase 5 Cybervision
  • Indivison AGA MK1
  • 60GB SSD to SCSI via ACard 7730A

Pictures of the screen config:





highpuff is offline  
Old 10 March 2015, 08:57   #2
Blueberry
Registered User
 
Join Date: Dec 2007
Location: Aarhus / Denmark
Posts: 44
If the purpose is just to restore the original screenmode when your demo exits, the "proper" way of doing it is like this:

- Save the gb_ActiView field in GraphicsBase. This points to the current View, as managed by graphics.library.
- Call LoadView(0). This tells graphics.library to reset the view to default (PAL or NTSC, you can't rely on which).
- move.w #$0020,$dff1dc to force display to PAL.
- Call WaitTOF twice (makes sure any remaining odd/even field copperlists have completed).
- Bang the hardware as you like
- When done, call LoadView with the original (saved) view. This restores the original screenmode.

This procedure works from any screenmode, including RTG modes.

Getting all parts of the init code to fit together properly in the right order can be a bit tricky. Take a look at my init code, as discussed here: http://ada.untergrund.net/?p=boardthread&id=444 - it closes and restores the system robustly, sets op a vblank interrupt, and a few other useful things. Use it as is or just for inspiration.
Blueberry is offline  
Old 10 March 2015, 10:40   #3
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
@Blueberry:

So if I save the gb_Actiview + gb_copinit and do all the rest all by the book and later in my code bang hardware $dff1dc with #$0020 and force my view to PAL, will the system be restore the saved gb_Actiview or do I need to set $dff1dc to #$0000 as well?

Or.. What the heck! I will try tonight (Suddenly the meeting I currently attend got very booring and I wish I was home).

Thanks so far
highpuff is offline  
Old 11 March 2015, 17:12   #4
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
@Blueberry:
I tried it now and if I do as you told me, like the list below.

- Save the gb_ActiView + gb_copinit fields in GraphicsBase. This points to the current View, as managed by graphics.library.
- Call LoadView(0). This tells graphics.library to reset the view to default (PAL or NTSC, you can't rely on which).
- move.w #$0020,$dff1dc to force display to PAL.
- Call WaitTOF twice (makes sure any remaining odd/even field copperlists have completed).
- Bang the hardware as you like
- When done, call LoadView with the original (saved) view. This restores the original screenmode.

If I then put #$20 in $dff1dc in my copperlist and then exit the system, it does not restore $dff1dc to $0. It seems like this register is not set either in gb_ActiView and gb_copinit.
highpuff is offline  
Old 12 March 2015, 15:11   #5
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Call RemakeDisplay before putting gb_copinit back in (read gb_copinit AFTER RemakeDisplay). Settings related to the display generator, such as vertical and horizontal frequencies, are global for the entire screen and are kept out of the Copper program inside the View.

If you want to force PAL, then it might be a better idea to check if you're on ECS and Kickstart 2.0 or higher, and just call OpenScreen with PAL_MONITOR_ID and get a blank screen without title-bar, bitmap etc. before hitting the hardware. This way you can let the system deal with all the stuff related to the display generator, which is probably a safer bet.

BTW, The display mode you get when calling LoadView(NULL) is the one you booted into, so if you f.ex. have a PAL machine and select NTSC via the early startup menu, and run 31kHz VGA in Workbench, then calling LoadView(NULL) will give you the NTSC.
Leffmann is offline  
Old 13 March 2015, 21:31   #6
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
I might have done something wrong now, but so far it did not work. This is the schema.

- Call _LVORemakeDisplay
- Read&Store gb_copinit

- yada yada

- Call _LVORemakeDisplay
- Read&Restore gb_copinit

Still the same, I need to set $dff1dc to $0 else I do get a PAL-screen in Workbench.

I will try some more tonight and during the weekend. Thanks so far!
highpuff is offline  
Old 13 March 2015, 22:51   #7
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Try this:
Code:
LoadView(NULL)
WaitTOF()
WaitTOF()
...
Restore interrupt and DMA settings
RemakeDisplay()
cop1lc = GfxBase->copinit
It works fine in WinUAE and on my A1200, and restores from PAL or NTSC back to PAL, NTSC, VGA etc. correctly, though I don't have an Indivision to test with.
Attached Files
File Type: lha test.lha (1.7 KB, 156 views)
Leffmann is offline  
Old 14 March 2015, 15:44   #8
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
Tried it in asmOne with latest includes and older ones. I cannot say that it does not work, but it also hangs the system on exit.

It does go back to NTSC so now I need to see what it is that causes the hang.
highpuff is offline  
Old 14 March 2015, 17:48   #9
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,643
did you forget a Permit() call before exit? or restore of intena?
hooverphonique is offline  
Old 14 March 2015, 18:05   #10
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
No, they are there and it is working with I remove the call to IntuitionBase/RemakeDisplay.

The exit does this:

1) Restore old DMA
2) Restore old INT
3) Restore old REQ
4) Exec/Permit

5) Intuition/RemakeDisplay

6) gb_inicop->$dff080
7) Kickstart CopJmp
8) Close IntuitionLib
9) Close GraphicsLib

Since this is only because I use Indivision MK1 with two separate displaymodes between games/demos and Workbench I think I will stay with my manual routine.

But it would be nice to have a routine that detects the screen mode that was before execution of the code and then be able to restore it. Else.. Cheap solution, buy a LCD that supports 15,6KHz Horizontal ( Thanks Hewitson for the reminder )

Last edited by highpuff; 15 March 2015 at 10:44. Reason: Small error in text
highpuff is offline  
Old 15 March 2015, 02:50   #11
Hewitson
Registered User
 
Hewitson's Avatar
 
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,773
Quote:
Originally Posted by highpuff View Post
Cheap solution, buy a LCD that supports 15,6KHz vertical
Horizontal
Hewitson is offline  
Old 15 March 2015, 10:44   #12
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
Quote:
Originally Posted by Hewitson View Post
Horizontal
Damn it... Fixed!
highpuff is offline  
Old 17 March 2015, 19:42   #13
Leffmann
 
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
Does the small test program I posted above crash too? Could you post your code?
Leffmann is offline  
Old 18 March 2015, 11:55   #14
mark_k
Registered User
 
Join Date: Aug 2004
Location:
Posts: 3,351
Quote:
Originally Posted by highpuff View Post
But it would be nice to have a routine that detects the screen mode that was before execution of the code and then be able to restore it.
I can't help thinking there must be a way to do that. But I don't know it. There doesn't seem to be a system_beamcon0 value in GfxBase for instance.

What you could do on exiting, is force the system to write to BEAMCON0 itself. If you load an NTSC View, then load a PAL View, then restore the original View, the system should write to BEAMCON0.
mark_k is offline  
Old 18 March 2015, 17:23   #15
highpuff
Registered User
 
highpuff's Avatar
 
Join Date: Jan 2014
Location: Göteborg
Posts: 43
@Leffman: (or should I call you Master from now?)

I tried the C-application that you shared in this thread and it worked in Workbench. It seems that I made a huge bo-bo. Above the pointer to the Intuition library I had a dc.w, that SHOULD have been a dc.l, meaning that the I pointer was overwritten in a early phase.

My bad The break I had from coding on Amiga for a "few" years seem to have certain negative effects. Like my vision etc :P

Thanks again!

Last edited by highpuff; 18 March 2015 at 17:25. Reason: Spelling
highpuff is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
PAL vs. NTSC jimmyd35 project.TOSEC (amiga only) 1 29 April 2013 03:23
NTSC A500 Pal/NTSC mod pics kipper2k Hardware pics 2 29 March 2009 07:56
NTSC to PAL ...what's next? NfernalNfluence support.Hardware 7 28 July 2007 12:19
Pal/ntsc Marcuz request.UAE Wishlist 16 20 July 2007 10:07
Ntsc / Pal killergorilla project.SPS (was CAPS) 3 09 July 2003 18:25

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 21:16.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10294 seconds with 14 queries