fixed check for NTSC and PAL using execbase

was wrong indirection, address 4 is struct ExecBase ** and not
struct ExecBase *
This commit is contained in:
Wei-ju Wu 2016-09-22 06:09:44 -07:00
parent 1235d15acb
commit 9667769954
3 changed files with 51 additions and 21 deletions

View File

@ -10,10 +10,12 @@
#include "common.h"
extern struct Custom custom;
extern struct Library *GfxBase;
extern struct GfxBase *GfxBase;
static struct Screen *wbscreen;
static ULONG oldresolution;
struct ExecBase **exec_base_ptr = (struct ExecBase **) (4L);
static void ApplySpriteFix(void)
{
if (wbscreen = LockPubScreen(WB_SCREEN_NAME)) {
@ -48,7 +50,7 @@ static void UnapplySpriteFix(void)
BOOL init_display(void)
{
UWORD lib_version = ((struct Library *) GfxBase)->lib_Version;
UWORD lib_version = GfxBase->LibNode.lib_Version;
BOOL is_pal;
LoadView(NULL); // clear display, reset hardware registers
@ -62,8 +64,9 @@ BOOL init_display(void)
} else {
// Note: FS-UAE reports 0 this, so essentially, there is no information
// for 1.x
printf("PAL/NTSC: %d\n", (int) ((struct ExecBase *) EXEC_BASE)->VBlankFrequency);
is_pal = ((struct ExecBase *) EXEC_BASE)->VBlankFrequency == VFREQ_PAL;
int vblank_freq = (*exec_base_ptr)->VBlankFrequency;
printf("Gfx Lib version: %u, Vertical Blank Frequency: %d\n", lib_version, vblank_freq);
is_pal = vblank_freq == VFREQ_PAL;
}
return is_pal;
}
@ -71,7 +74,7 @@ BOOL init_display(void)
void reset_display(void)
{
struct View *current_view = ((struct GfxBase *) GfxBase)->ActiView;
UWORD lib_version = ((struct Library *) GfxBase)->lib_Version;
UWORD lib_version = GfxBase->LibNode.lib_Version;
if (lib_version >= 39) UnapplySpriteFix();
LoadView(current_view);
WaitTOF();

View File

@ -3,6 +3,7 @@
#define __COMMON_DEFS_H__
// Custom Chip Registers
#define DMACON 0x096
#define BPL1PTH 0x0e0
#define BPL1PTL 0x0e2
#define BPL2PTH 0x0e4
@ -27,8 +28,6 @@
#define DIWSTOP_VALUE_PAL 0x2cc1
#define DIWSTOP_VALUE_NTSC 0xf4c1
#define EXEC_BASE (4L)
// max priority for this task
#define TASK_PRIORITY 127

View File

@ -3,21 +3,29 @@
#include <stdio.h>
#include "common.h"
#include "kingtut.h"
#define NUM_COLORS 32
#define NUM_BITPLANES 5
/*
* A simple setup to display a sprite.
*/
extern struct Custom custom;
char VERSION_STRING[] = "\0$VER: sprites 1.0 (21.09.2016)\0";
static UWORD __chip coplist_pal[] = {
COP_MOVE(SPR0PTH, 0x0000),
COP_MOVE(SPR0PTL, 0x0000),
COP_WAIT_END,
COP_WAIT_END
};
static UWORD __chip coplist_ntsc[] = {
COP_MOVE(SPR0PTL, 0x0000),
COP_MOVE(SPR0PTH, 0x0000),
static UWORD __chip coplist[] = {
COP_MOVE(BPL1PTH, 0),
COP_MOVE(BPL1PTL, 0),
COP_MOVE(BPL2PTH, 0),
COP_MOVE(BPL2PTL, 0),
COP_MOVE(BPL3PTH, 0),
COP_MOVE(BPL3PTL, 0),
COP_MOVE(BPL4PTH, 0),
COP_MOVE(BPL4PTL, 0),
COP_MOVE(BPL5PTH, 0),
COP_MOVE(BPL5PTL, 0),
COP_MOVE(SPR0PTH, 0),
COP_MOVE(SPR0PTL, 0),
COP_WAIT_END,
COP_WAIT_END
};
@ -39,12 +47,32 @@ int main(int argc, char **argv)
struct Task *current_task = FindTask(NULL);
BYTE old_prio = SetTaskPri(current_task, TASK_PRIORITY);
BOOL is_pal = init_display();
coplist_ntsc[1] = ((ULONG) spdat0) & 0xffff;
coplist_ntsc[3] = (((ULONG) spdat0) >> 16) & 0xffff;
coplist_pal[1] = ((ULONG) spdat0) & 0xffff;
coplist_pal[3] = (((ULONG) spdat0) >> 16) & 0xffff;
custom.cop1lc = is_pal ? (ULONG) coplist_pal : (ULONG) coplist_ntsc;
custom.bplcon0 = 0x5200; // use bitplane 1-5 = BPU 101, composite color enable
custom.bplcon1 = 0; // horizontal scroll value = 0 for all playfields
custom.bplcon2 = 0x24; // sprites have priority over playfields
custom.bpl1mod = 0; // modulo = 0 for odd bitplanes
custom.ddfstrt = DDFSTRT_VALUE;
custom.ddfstop = DDFSTOP_VALUE;
custom.diwstrt = DIWSTRT_VALUE;
custom.diwstop = DIWSTOP_VALUE;
for (int i = 0; i < NUM_COLORS; i++) {
custom.color[i] = image_colors[i];
}
// Initialize copper list with image data address
for (int i = 0; i < NUM_BITPLANES; i++) {
ULONG addr = (ULONG) &(image_data[i * 20 * NUM_RASTER_LINES]);
coplist[i * 4 + 1] = (addr >> 16) & 0xffff;
coplist[i * 4 + 3] = addr & 0xffff;
}
coplist[21] = (((ULONG) spdat0) >> 16) & 0xffff;
coplist[23] = ((ULONG) spdat0) & 0xffff;
//custom.dmacon = 0x8020;
custom.cop1lc = (ULONG) coplist;
custom.copjmp1 = 1;
waitmouse();