Hi,
I've just started my home brew PS2 hacking -- first of all thanks to all of you who provided invaluable information that helped me get going.
I managed to run my code using independence exploit and Xploder.
Too bad naplink doesn't seem to recognize my cable, but I've got a
network adaptor and I'm gonna try using it for development.
I'm developing a simple demo and I'm struggling with basic video mode
setting. I'm trying to setup a basic 640x512 PAL mode, and here's what
I've got so far:
I'm using SetGsCrt syscall to set the mode (interlaced=1, mode=3, frame_field=0). Then I stuff some magic numbers into DISPLAY2.
I'm using standard double buffering technique, polling for vsync
using CSR register.
It all kinda works, but the are a couple of things I'm trying to nail down:
- the image flickers as if I was running 10-15 Hz refresh rate. What am I
doing wrong? Certainly there is a bit of flickering when I play games in
this video mode, but not as bad as my demo.
- The screen is shifted a bit to the left and there is uninitialized crap
at the bottom of the screen. This probably has to do with how to initialize
DISPLAY2 register, but I've tried following the tutorials and using
the PS2 Linux code (ps2gs.c) to compute them -- it's always a bit off.
What are the definite guidelines on how to set this up?
- Anyone knows how can I avoid vsync polling and setup interrupt handler
for this?
Thanks, any help appreciated!
640x512 PAL mode
-
- Posts: 564
- Joined: Sat Jan 17, 2004 10:22 am
- Location: Sweden
- Contact:
dunno where you got mode = 3 from, I give SetGsCrt 1 for pal.
Personally I set display to 0x1FF9FF01840290 wich centers it pretty nicely on my tft's, tv's and projector.
personally I use polling for VR so far, as one should keep things within a frame ;)
otherwise just register a vrhandler, something like this ( im sure there are some sources out there, pillgen or somesuch that sets up a vrhandler ).
# disable interrupts
di
# install handler
ori a0, zero, 0x2
la a1, vrFunction
move a2, zero
ori v1, zero, 0x10
syscall
nop
# save handler id
la a0, vrId
sw v0, 0(a0)
# enable it
ori a0, zero, 2
ori v1, zero, 0x14
syscall
nop
# enable interrupts
ei
Personally I set display to 0x1FF9FF01840290 wich centers it pretty nicely on my tft's, tv's and projector.
personally I use polling for VR so far, as one should keep things within a frame ;)
otherwise just register a vrhandler, something like this ( im sure there are some sources out there, pillgen or somesuch that sets up a vrhandler ).
# disable interrupts
di
# install handler
ori a0, zero, 0x2
la a1, vrFunction
move a2, zero
ori v1, zero, 0x10
syscall
nop
# save handler id
la a0, vrId
sw v0, 0(a0)
# enable it
ori a0, zero, 2
ori v1, zero, 0x14
syscall
nop
# enable interrupts
ei
Kung VU
About the flicker - 640x512 PAL is interlaced. You have a 50 Hz field rate, and a 25 Hz frame rate. If your routine to wait for the vertical blank was assuming a 50 Hz field rate when the bit monitored was giving you a 25 Hz frame rate, it's possible you're actually winding up with a 12.5 Hz synchronizing routine. Another possibility is that your routine takes longer than one frame, so then waiting on the frame end gives you a two frame delay, also giving a 12.5 Hz synchronization.
C source for setting up a vr handler (taken from BP Demo Harness stuff, and probably from somewhere else before ;P)
int vb_id;
int vblank_handler(int cause)
{
/* Do sommit, i.e. Signal a sema */
asm("sync.l ; ei");
return 0;
}
void enable_vblank()
{
DI();
vb_id = AddIntcHandler(2, vblank_handler, 0);
EnableIntc(2);
EI();
}
void disable_vblank()
{
DisableIntc(2);
RemoveIntcHandler(2, vb_id);
}
int vb_id;
int vblank_handler(int cause)
{
/* Do sommit, i.e. Signal a sema */
asm("sync.l ; ei");
return 0;
}
void enable_vblank()
{
DI();
vb_id = AddIntcHandler(2, vblank_handler, 0);
EnableIntc(2);
EI();
}
void disable_vblank()
{
DisableIntc(2);
RemoveIntcHandler(2, vb_id);
}
Excellent, thank you! I also found ito lib to be a great source for learning
- cleanly written and commented.
As for the flickering: good points J.F., although now I'm thinking I was imagining things being used to high refresh rates on the monitor :)
Alright! I've got the basics nailed down, it's time to do some 3D! :)
It'd be cool to see an absolutely basic 3D demo, .e.g rotating cube
or something, that uses VU units properly etc. I'm going through the docs
now, If I ever make something useful I'll try to publish it for everyone.
- cleanly written and commented.
As for the flickering: good points J.F., although now I'm thinking I was imagining things being used to high refresh rates on the monitor :)
Alright! I've got the basics nailed down, it's time to do some 3D! :)
It'd be cool to see an absolutely basic 3D demo, .e.g rotating cube
or something, that uses VU units properly etc. I'm going through the docs
now, If I ever make something useful I'll try to publish it for everyone.