2021-12-25 15:18:17 +00:00
|
|
|
/* ReC98
|
|
|
|
* -----
|
|
|
|
* VSync interrupt handler
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma option -2 -Z-
|
|
|
|
#pragma warn -aus
|
|
|
|
|
|
|
|
#include "platform.h"
|
|
|
|
#include "x86real.h"
|
|
|
|
#include "pc98.h"
|
2022-08-10 21:15:51 +00:00
|
|
|
#include "planar.h"
|
2022-08-08 23:38:13 +00:00
|
|
|
#include "th01/hardware/vsync.hpp"
|
2021-12-25 15:18:17 +00:00
|
|
|
|
2022-08-10 21:15:51 +00:00
|
|
|
extern bool vsync_initialized = false;
|
|
|
|
extern bool16 vsync_callback_is_set = false;
|
2021-12-25 15:18:17 +00:00
|
|
|
|
2022-08-10 21:15:51 +00:00
|
|
|
static int32_t unused_7 = 7; // ZUN bloat
|
|
|
|
static int32_t unused_0 = 0; // ZUN bloat
|
2021-12-25 15:18:17 +00:00
|
|
|
|
2022-08-10 21:15:51 +00:00
|
|
|
static pixel_t RES_X_HALF = (RES_X / 2);
|
|
|
|
static pixel_t RES_Y_HALF = (RES_Y / 2);
|
|
|
|
|
|
|
|
// Unused mouse cursor (?!)
|
|
|
|
// -------------------
|
|
|
|
|
|
|
|
// (These meanings are just a guess.)
|
|
|
|
static screen_x_t MOUSE_MIN_X = 0;
|
|
|
|
static screen_y_t MOUSE_MIN_Y = 0;
|
|
|
|
static screen_x_t MOUSE_MAX_X = (RES_X - 1);
|
|
|
|
static screen_x_t MOUSE_MAX_Y = (RES_Y - 1);
|
|
|
|
static int8_t mouse_unused = 0;
|
|
|
|
#include "th01/sprites/mousecur.csp"
|
|
|
|
// -------------------
|
|
|
|
|
|
|
|
int z_vsync_Count1;
|
|
|
|
int z_vsync_Count2;
|
|
|
|
static void interrupt (*vsync_callback_old)(...);
|
|
|
|
static void (*vsync_callback)(void);
|
2021-12-25 15:18:17 +00:00
|
|
|
|
2022-08-08 23:38:13 +00:00
|
|
|
static void interrupt vsync_intfunc(...)
|
2021-12-25 15:18:17 +00:00
|
|
|
{
|
|
|
|
pixel_t res_x_half = RES_X_HALF;
|
|
|
|
pixel_t res_y_half = RES_Y_HALF;
|
2022-08-10 21:15:51 +00:00
|
|
|
z_vsync_Count1++;
|
|
|
|
z_vsync_Count2++;
|
2021-12-25 15:18:17 +00:00
|
|
|
if(vsync_callback_is_set) {
|
|
|
|
vsync_callback();
|
|
|
|
}
|
|
|
|
outportb(0x00, 0x20); // End of Interrupt
|
|
|
|
outportb(0x64, 0); // VSync interrupt trigger
|
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_init(void)
|
|
|
|
{
|
2022-08-08 23:38:13 +00:00
|
|
|
if(vsync_initialized == false) {
|
|
|
|
vsync_initialized = true;
|
2021-12-25 15:18:17 +00:00
|
|
|
disable();
|
|
|
|
vsync_callback_old = getvect(0x0A);
|
|
|
|
setvect(0x0A, vsync_intfunc);
|
|
|
|
|
|
|
|
// Disable all interrupts from 0x08 to 0x0F except for 0x0A
|
2022-08-08 23:38:13 +00:00
|
|
|
outportb(0x02, (inportb(0x02) & 0xFB));
|
2021-12-25 15:18:17 +00:00
|
|
|
|
|
|
|
outportb(0x64, 0); // VSync interrupt trigger
|
|
|
|
enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_exit(void)
|
|
|
|
{
|
2022-08-08 23:38:13 +00:00
|
|
|
if(vsync_initialized == true) {
|
|
|
|
vsync_initialized = false;
|
2021-12-25 15:18:17 +00:00
|
|
|
disable();
|
|
|
|
|
|
|
|
// Reenable all interrupts from 0x08 to 0x0F except for 0x0A
|
2022-08-08 23:38:13 +00:00
|
|
|
outportb(0x02, (inportb(0x02) | 0x04));
|
2021-12-25 15:18:17 +00:00
|
|
|
|
|
|
|
setvect(0x0a, vsync_callback_old);
|
|
|
|
enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void z_vsync_wait(void)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
_AL = inportb(0x60);
|
|
|
|
} while((_AL & 0x20) != 0);
|
|
|
|
do {
|
|
|
|
_AL = inportb(0x60);
|
|
|
|
} while((_AL & 0x20) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_callback_set(void (*vsync_callback_new)())
|
|
|
|
{
|
2022-08-10 21:15:51 +00:00
|
|
|
vsync_callback_is_set = false;
|
2021-12-25 15:18:17 +00:00
|
|
|
vsync_callback = vsync_callback_new;
|
2022-08-10 21:15:51 +00:00
|
|
|
vsync_callback_is_set = true;
|
2021-12-25 15:18:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void vsync_callback_clear(void)
|
|
|
|
{
|
2022-08-10 21:15:51 +00:00
|
|
|
vsync_callback_is_set = false;
|
2021-12-25 15:18:17 +00:00
|
|
|
}
|