remove display_properties.S and define LMGetMainDevice(), detect display in vga_init()

This commit is contained in:
Laurent Vivier 2007-03-31 07:26:05 +00:00
parent 454089d8df
commit 272ac39b96
8 changed files with 125 additions and 194 deletions

View File

@ -10,6 +10,7 @@
#include <macos/quickdraw.h>
#include <libmacos.h>
#include "misc.h"
#include "vga.h"
QDGlobals qd;
@ -382,20 +383,15 @@ vga_scroll()
int
vga_init()
{
int ret;
unsigned long base, video;
GDHandle hdl;
volatile PixMapPtr pm;
InitGraf(&qd.thePort);
ret = glue_display_properties(&base,
&vga.row_bytes,
&vga.width,
&vga.height,
&vga.depth,
&video);
vga.base = (unsigned char*)base;
vga.video = (unsigned char*)video;
if (ret)
hdl = LMGetMainDevice();
if ( (hdl == (GDHandle)0xAAAAAAAA) || (hdl == NULL) ||
((**hdl).gdPMap == NULL) || ((*(**hdl).gdPMap)->baseAddr == NULL) )
{
vga.base = qd.screenBits.baseAddr;
vga.row_bytes = qd.screenBits.rowBytes;
@ -404,8 +400,20 @@ vga_init()
vga.height = qd.screenBits.bounds.bottom -
qd.screenBits.bounds.top;
vga.depth = 1;
} else {
pm = *(**hdl).gdPMap;
vga.video = (unsigned char *)pm->baseAddr;
vga.row_bytes = pm->rowBytes & 0x3fff;
vga.width = pm->bounds.right - pm->bounds.left;
vga.height = pm->bounds.bottom - pm->bounds.top;
vga.depth = pm->pixelSize;
if (vga.depth == 15)
vga.depth = 16;
}
vga.base = vga.video + pm->bounds.top * vga.row_bytes + pm->bounds.left * (vga.depth >> 3);
vga.pos_x = 0;
vga.pos_y = 0;
vga.siz_w = vga.width / 8;

View File

@ -10,8 +10,7 @@ CPPFLAGS = -I$(TOP) -DARCH_M68K
LIBRARY = libmacos.a
SOURCES = display_properties.S \
CloseDriver.c OpenDriver.c SerGetBuf.c
SOURCES = CloseDriver.c OpenDriver.c SerGetBuf.c
HEADERS = libmacos.h \
macos/devices.h macos/errors.h macos/events.h macos/files.h \

View File

@ -1,165 +0,0 @@
/*
*
* (c) 2004,2005 Laurent Vivier <Laurent@lvivier.info>
*
*/
.cpu 68000
.align 2
/* #include <ConditionalMacros.h>
* #include <Quickdraw.h>
*/
.globl glue_display_properties
.type glue_display_properties,@function
/*
* int
* glue_display_properties(unsigned long *base, unsigned long *row_bytes,
* unsigned long *width, unsigned long *height,
* unsigned long *depth, unsigned long* video)
*/
glue_display_properties:
/*
* GDHandle hdl;
* volatile PixMapPtr pm;
*/
link.w %a6,#-4
movem.l %a2-%a4, %sp@-
movm.l #0x3c,-(%sp)
move.l 28(%a6),%a3 /* unsigned long *video */
move.l 12(%a6),%a5 /* unsigned long *row_bytes */
move.l 24(%a6),%a4 /* unsigned long *depth */
/* hdl = LMGetMainDevice(); */
move.l 0x08A4,%a0
/* if (hdl == 0xAAAAAAAA || hdl == NULL || (**hdl).gdPMap == NULL)
* return;
*/
cmpa.l #0xAAAAAAAA, %a0
jbeq .exit_error
cmpa.l #0, %a0
jbeq .exit_error
move.l (%a0),%a0
tst.l 22(%a0)
jbeq .exit_error
/* pm = *(**hdl).gdPMap; */
move.l 22(%a0),%a0
/* if (pm->baseAddr == NULL)
* return;
*/
move.l (%a0),-4(%a6)
move.l -4(%a6),%a0
tst.l (%a0)
jbeq .exit_error
/* *video = (unsigned char *)pm->baseAddr; */
move.l -4(%a6),%a0
move.l (%a0),(%a3)
/* *row_bytes = pm->rowBytes & 0x3fff; */
move.l -4(%a6),%a0
move.w 4(%a0),%d0
and.l #16383,%d0
move.l %d0,(%a5)
/* *width = pm->bounds.right - pm->bounds.left; */
move.l -4(%a6),%a0
move.w 12(%a0),%a2
move.l -4(%a6),%a1
move.l 16(%a6),%a0
sub.w 8(%a1),%a2
move.l %a2,(%a0)
/* *height = pm->bounds.bottom - pm->bounds.top; */
move.l -4(%a6),%a0
move.w 10(%a0),%a2
move.l -4(%a6),%a1
move.l 20(%a6),%a0
sub.w 6(%a1),%a2
move.l %a2,(%a0)
/* *depth = pm->pixelSize; */
move.l -4(%a6),%a0
move.w 32(%a0),%a0
move.l %a0,(%a4)
/* if (*depth == 15) *depth = 16; */
moveq.l #15,%d0
cmp.l %a0,%d0
jbne .not_15
moveq.l #16,%d0
move.l %d0,(%a4)
.not_15:
/* (*base) = (*video) */
move.l (%a3),%d0
move.l 8(%a6),%a3 /* unsigned long *base */
move.l %d0,(%a3)
/* (*base) = (*video) + pm->bounds.top * *row_bytes; */
move.l -4(%a6),%a0
move.w 6(%a0),%d0
/* add 68000 support,
*
* row_bytes can be stored on a short
*
*/
move.l (%a5), %d1
muls.w %d1, %d0
add.l %d0,(%a3)
/* (*base) += pm->bounds.left * ((*depth) >> 3); */
move.l -4(%a6),%a0
move.w 8(%a0),%d1
move.l (%a4),%d0
lsr.l #3,%d0
/* add 68000 support,
*
* NOTE: depth can be stored on a short
*
*/
muls.w %d0, %d1
add.l %d1,(%a3)
.exit:
movm.l (%sp)+,#0x3c00
movem.l %sp@+, %a2-%a4
unlk %a6
moveq.l #0, %d0
rts
.exit_error:
movm.l (%sp)+,#0x3c00
movem.l %sp@+, %a2-%a4
unlk %a6
moveq.l #-1, %d0
rts

View File

@ -3,8 +3,3 @@
* (c) 2004, 2005 Laurent Vivier <Laurent@lvivier.info>
*
*/
extern int glue_display_properties(unsigned long *base,
unsigned long *row_bytes,
unsigned long *width, unsigned long *height,
unsigned long *depth, unsigned long *video);

View File

@ -32,4 +32,5 @@
#define LMGetUnitTableEntryCount() (*(short*)0x1d2)
#define LMGetUTableBase() (*(unsigned long*)0x11c)
#define LMGetDrvQHdr() ( (QHdrPtr) 0x0308)
#define LMGetMainDevice() ( *(GDHandle*) 0x08A4)
#endif /* __MACOS_LOWMEM_H__ */

View File

@ -6,6 +6,7 @@
#ifndef __MACOS_QUICKDRAW_H__
#define __MACOS_QUICKDRAW_H__
#include <macos/types.h>
#include <macos/traps.h>
@ -54,6 +55,86 @@ typedef struct QDGlobals QDGlobals;
typedef struct QDGlobals* QDGlobalsPtr;
typedef struct QDGlobalsPtr* QDGlobalsHandle;
typedef struct ITab {
long iTabSeed;
short iTabRes;
Byte iTTable[1];
} ITab;
typedef ITab* ITabPtr;
typedef ITabPtr* ITabHandle;
typedef void** SProcHndl;
typedef void** CProcHndl;
typedef struct RGBColor {
unsigned short red;
unsigned short green;
unsigned short blue;
} RGBColor;
typedef struct ColorSpec {
short value;
RGBColor rgb;
} ColorSpec;
typedef ColorSpec* ColorSpecPtr;
typedef ColorSpec CSpecArray[1];
typedef struct ColorTable {
long ctSeed;
short ctFlags;
short ctSize;
CSpecArray ctTable;
} ColorTable;
typedef ColorTable* CTabPtr;
typedef CTabPtr* CTabHandle;
typedef struct PixMap {
void* baseAddr;
short rowBytes;
Rect bounds;
short pmVersion;
short packType;
long packSize;
Fixed hRes;
Fixed vRes;
short pixelType;
short pixelSize;
short cmpCount;
short cmpSize;
OSType pixelFormat;
CTabHandle pmTable;
void* pmExt;
} PixMap;
typedef PixMap* PixMapPtr;
typedef PixMapPtr* PixMapHandle;
typedef struct GDevice GDevice;
typedef GDevice* GDPtr;
typedef GDPtr* GDHandle;
struct GDevice {
short gdRefNum;
short gdID;
short gdType;
ITabHandle gdItable;
short gdResPref;
SProcHndl gdSearchProc;
CProcHndl gdCompProc;
short gdFlags;
PixMapHandle gdPMap; /* PixMapHandle */
long gdRefCon;
GDHandle gdNextGD;
Rect gdRect;
long gdMode;
short gdCCBytes;
short gdCCDepth;
Handle gdCCXData;
Handle gdCCXMask;
Handle gdExt;
};
#ifdef __mc68000__
static inline void InitGraf(void * port)
{

View File

@ -16,6 +16,8 @@ typedef unsigned int u_int32_t;
typedef signed int int32_t;
#endif /* _SYS_TYPES_H */
typedef u_int8_t Byte;
typedef int32_t Fixed;
typedef int16_t OSErr;
typedef unsigned long FourCharCode;
typedef FourCharCode OSType;
@ -23,6 +25,9 @@ typedef unsigned char Str255[256];
typedef const unsigned char * ConstStr255Param;
typedef unsigned char Str27[28];
typedef char* Ptr;
typedef Ptr* Handle;
enum {
false = 0,
true = 1

View File

@ -383,20 +383,15 @@ vga_scroll()
int
vga_init()
{
int ret;
unsigned long base, video;
GDHandle hdl;
volatile PixMapPtr pm;
InitGraf(&qd.thePort);
ret = glue_display_properties(&base,
&vga.row_bytes,
&vga.width,
&vga.height,
&vga.depth,
&video);
vga.base = (unsigned char*)base;
vga.video = (unsigned char*)video;
if (ret)
hdl = LMGetMainDevice();
if ( (hdl == (GDHandle)0xAAAAAAAA) || (hdl == NULL) ||
((**hdl).gdPMap == NULL) || ((*(**hdl).gdPMap)->baseAddr == NULL) )
{
vga.base = qd.screenBits.baseAddr;
vga.row_bytes = qd.screenBits.rowBytes;
@ -405,8 +400,20 @@ vga_init()
vga.height = qd.screenBits.bounds.bottom -
qd.screenBits.bounds.top;
vga.depth = 1;
} else {
pm = *(**hdl).gdPMap;
vga.video = (unsigned char *)pm->baseAddr;
vga.row_bytes = pm->rowBytes & 0x3fff;
vga.width = pm->bounds.right - pm->bounds.left;
vga.height = pm->bounds.bottom - pm->bounds.top;
vga.depth = pm->pixelSize;
if (vga.depth == 15)
vga.depth = 16;
}
vga.base = vga.video + pm->bounds.top * vga.row_bytes + pm->bounds.left * (vga.depth >> 3);
vga.pos_x = 0;
vga.pos_y = 0;
vga.siz_w = vga.width / 8;