2015-09-05 20:06:46 +00:00
|
|
|
/* ReC98
|
|
|
|
* -----
|
|
|
|
* VSync interrupt handler
|
|
|
|
*/
|
|
|
|
|
2020-10-03 16:20:41 +00:00
|
|
|
#pragma option -2 -Z-
|
2015-09-05 20:06:46 +00:00
|
|
|
#pragma warn -aus
|
|
|
|
|
2020-11-07 19:16:17 +00:00
|
|
|
#include "platform.h"
|
2021-02-07 20:03:00 +00:00
|
|
|
#include "x86real.h"
|
2020-11-07 19:16:17 +00:00
|
|
|
#include "pc98.h"
|
2020-10-01 14:34:46 +00:00
|
|
|
#include "th01/hardware/vsync.h"
|
|
|
|
|
2015-09-05 20:06:46 +00:00
|
|
|
extern char vsync_initialized;
|
|
|
|
extern int vsync_callback_is_set;
|
|
|
|
|
2020-08-21 18:13:08 +00:00
|
|
|
extern pixel_t RES_X_HALF;
|
|
|
|
extern pixel_t RES_Y_HALF;
|
2015-09-05 20:06:46 +00:00
|
|
|
|
|
|
|
extern int vsync_unused;
|
|
|
|
extern void interrupt (*vsync_callback_old)(void);
|
|
|
|
extern void (*vsync_callback)(void);
|
|
|
|
|
|
|
|
static void interrupt vsync_intfunc(void)
|
|
|
|
{
|
2020-08-21 18:13:08 +00:00
|
|
|
pixel_t res_x_half = RES_X_HALF;
|
|
|
|
pixel_t res_y_half = RES_Y_HALF;
|
2015-09-05 20:06:46 +00:00
|
|
|
vsync_frame++;
|
|
|
|
vsync_unused++;
|
|
|
|
if(vsync_callback_is_set) {
|
|
|
|
vsync_callback();
|
|
|
|
}
|
2020-11-06 21:24:00 +00:00
|
|
|
outportb(0x00, 0x20); // End of Interrupt
|
|
|
|
outportb(0x64, 0); // VSync interrupt trigger
|
2015-09-05 20:06:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_init(void)
|
|
|
|
{
|
|
|
|
if(vsync_initialized == 0) {
|
|
|
|
vsync_initialized = 1;
|
|
|
|
disable();
|
|
|
|
vsync_callback_old = getvect(0x0A);
|
|
|
|
setvect(0x0A, vsync_intfunc);
|
|
|
|
|
|
|
|
// Disable all interrupts from 0x08 to 0x0F except for 0x0A
|
2020-11-06 21:24:00 +00:00
|
|
|
outportb(0x02, inportb(0x02) & 0xFB);
|
2015-09-05 20:06:46 +00:00
|
|
|
|
2020-11-06 21:24:00 +00:00
|
|
|
outportb(0x64, 0); // VSync interrupt trigger
|
2015-09-05 20:06:46 +00:00
|
|
|
enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_exit(void)
|
|
|
|
{
|
|
|
|
if(vsync_initialized == 1) {
|
|
|
|
vsync_initialized = 0;
|
|
|
|
disable();
|
|
|
|
|
|
|
|
// Reenable all interrupts from 0x08 to 0x0F except for 0x0A
|
2020-11-06 21:24:00 +00:00
|
|
|
outportb(0x02, inportb(0x02) | 0x04);
|
2015-09-05 20:06:46 +00:00
|
|
|
|
|
|
|
setvect(0x0a, vsync_callback_old);
|
|
|
|
enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void z_vsync_wait(void)
|
|
|
|
{
|
|
|
|
do {
|
2020-11-06 21:24:00 +00:00
|
|
|
_AL = inportb(0x60);
|
2015-09-05 20:06:46 +00:00
|
|
|
} while((_AL & 0x20) != 0);
|
|
|
|
do {
|
2020-11-06 21:24:00 +00:00
|
|
|
_AL = inportb(0x60);
|
2015-09-05 20:06:46 +00:00
|
|
|
} while((_AL & 0x20) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_callback_set(void (*vsync_callback_new)())
|
|
|
|
{
|
|
|
|
vsync_callback_is_set = 0;
|
|
|
|
vsync_callback = vsync_callback_new;
|
|
|
|
vsync_callback_is_set = 1;
|
|
|
|
}
|
2020-11-04 11:33:59 +00:00
|
|
|
|
|
|
|
void vsync_callback_clear(void)
|
|
|
|
{
|
|
|
|
vsync_callback_is_set = 0;
|
|
|
|
}
|