Skip to content

Commit

Permalink
[C decompilation] [th01] VSync interrupt handler
Browse files Browse the repository at this point in the history
Time to get back into this.
  • Loading branch information
nmlgc committed Sep 5, 2015
1 parent 75b8765 commit 14e69ce
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 830 deletions.
6 changes: 3 additions & 3 deletions Makefile.mak
Expand Up @@ -28,17 +28,17 @@ th05:: $(TH05:\=bin\th05\)
bin\th01\zunsoft.com: th01\zunsoft.c
$(CC) $(CFLAGS) -mt -lt -nbin\th01\ $** masters.lib

bin\th01\op.exe: bin\th01\op.obj th01\op_04.c th01\op_10.c th01\op_11.c th01\op_12.cpp
bin\th01\op.exe: bin\th01\op.obj th01\op_03.c th01\op_04.c th01\op_10.c th01\op_11.c th01\op_12.cpp
$(CC) $(CFLAGS) -ml -3 -nbin\th01\ -eOP.EXE @&&|
$**
|

bin\th01\reiiden.exe: bin\th01\reiiden.obj th01\main_04.c th01\main_12.c th01\main_13.c th01\main_14.c th01\main_16.c
bin\th01\reiiden.exe: bin\th01\reiiden.obj th01\main_03.c th01\main_04.c th01\main_12.c th01\main_13.c th01\main_14.c th01\main_16.c
$(CC) $(CFLAGS) -ml -3 -nbin\th01\ -eREIIDEN.EXE @&&|
$**
|

bin\th01\fuuin.exe: bin\th01\fuuin.obj th01\fuuin_06.c th01\fuuin_11.c th01\fuuin_12.c th01\fuuin_13.c
bin\th01\fuuin.exe: bin\th01\fuuin.obj th01\fuuin_05.c th01\fuuin_06.c th01\fuuin_11.c th01\fuuin_12.c th01\fuuin_13.c
$(CC) $(CFLAGS) -ml -3 -nbin\th01\ -eFUUIN.EXE @&&|
$**
|
Expand Down
7 changes: 7 additions & 0 deletions th01/fuuin_05.c
@@ -0,0 +1,7 @@
/* ReC98
* -----
* Code segment #5 of TH01's FUUIN.EXE
*/

#include "th01/hardware/vsync.c"
#include "th01/hardware/vsyncclr.c"
80 changes: 80 additions & 0 deletions th01/hardware/vsync.c
@@ -0,0 +1,80 @@
/* ReC98
* -----
* VSync interrupt handler
*/

#include "th01/th01.h"

#pragma option -2
#pragma warn -aus

extern char vsync_initialized;
extern int vsync_callback_is_set;

extern int RES_X_HALF;
extern int RES_Y_HALF;

extern int vsync_frame;
extern int vsync_unused;
extern void interrupt (*vsync_callback_old)(void);
extern void (*vsync_callback)(void);

static void interrupt vsync_intfunc(void)
{
int res_x_half = RES_X_HALF;
int res_y_half = RES_Y_HALF;
vsync_frame++;
vsync_unused++;
if(vsync_callback_is_set) {
vsync_callback();
}
OUTB(0x00, 0x20); // End of Interrupt
OUTB(0x64, 0); // VSync interrupt trigger
}

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
OUTB(0x02, INPB(0x02) & 0xFB);

OUTB(0x64, 0); // VSync interrupt trigger
enable();
}
}

void vsync_exit(void)
{
if(vsync_initialized == 1) {
vsync_initialized = 0;
disable();

// Reenable all interrupts from 0x08 to 0x0F except for 0x0A
OUTB(0x02, INPB(0x02) | 0x04);

setvect(0x0a, vsync_callback_old);
enable();
}
}

void z_vsync_wait(void)
{
do {
_AL = INPB(0x60);
} while((_AL & 0x20) != 0);
do {
_AL = INPB(0x60);
} 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;
}
5 changes: 5 additions & 0 deletions th01/hardware/vsync[bss].asm
@@ -0,0 +1,5 @@
public _vsync_frame, _vsync_unused, _vsync_callback_old, _vsync_callback
_vsync_frame dw ?
_vsync_unused dw ?
_vsync_callback_old dd ?
_vsync_callback dd ?
46 changes: 46 additions & 0 deletions th01/hardware/vsync[data].asm
@@ -0,0 +1,46 @@
public _vsync_initialized, _vsync_callback_is_set, _RES_X_HALF, _RES_Y_HALF
_vsync_initialized db 0
_vsync_callback_is_set dw 0
dd 7
dd 0
_RES_X_HALF dw 320
_RES_Y_HALF dw 200

; Unused?
dw 0
dw 0
dw 639
dw 399
dw 0C000h
dw 0E000h
dw 0F000h
dw 0F800h
dw 0FC00h
dw 0FE00h
dw 0FF00h
dw 0FF80h
dw 0FFC0h
dw 0FFE0h
dw 0FE00h
dw 0EF00h
dw 0CF00h
dw 780h
dw 780h
dw 300h
dw 0
dw 4000h
dw 6000h
dw 7000h
dw 7800h
dw 7C00h
dw 7E00h
dw 7F00h
dw 7F80h
dw 7C00h
dw 6C00h
dw 4600h
dw 600h
dw 300h
dw 300h
dw 0
db 0
12 changes: 12 additions & 0 deletions th01/hardware/vsyncclr.c
@@ -0,0 +1,12 @@
/* ReC98
* -----
* VSync interrupt callback clear function. In REIIDEN.EXE, this function needs
* to be put into a segment separate from vsync.c.
*/

extern int vsync_callback_is_set;

void vsync_callback_clear(void)
{
vsync_callback_is_set = 0;
}
6 changes: 6 additions & 0 deletions th01/main_03.c
@@ -0,0 +1,6 @@
/* ReC98
* -----
* Code segment #3 of TH01's REIIDEN.EXE
*/

#include "th01/hardware/vsync.c"
1 change: 1 addition & 0 deletions th01/main_04.c
Expand Up @@ -3,4 +3,5 @@
* Code segment #4 of TH01's REIIDEN.EXE
*/

#include "th01/hardware/vsyncclr.c"
#include "th01/ztext.c"
7 changes: 7 additions & 0 deletions th01/op_03.c
@@ -0,0 +1,7 @@
/* ReC98
* -----
* Code segment #3 of TH01's OP.EXE
*/

#include "th01/hardware/vsync.c"
#include "th01/hardware/vsyncclr.c"

0 comments on commit 14e69ce

Please sign in to comment.