CONST AS UINTEGER ADKB_SETCLR   = 15
CONST AS UINTEGER ADKB_PRECOMP1 = 14
CONST AS UINTEGER ADKB_PRECOMP0 = 13
CONST AS UINTEGER ADKB_MFMPREC  = 12
CONST AS UINTEGER ADKB_UARTBRK  = 11
CONST AS UINTEGER ADKB_WORDSYNC = 10
CONST AS UINTEGER ADKB_MSBSYNC  = 9
CONST AS UINTEGER ADKB_FAST     = 8
CONST AS UINTEGER ADKB_USE3PN   = 7
CONST AS UINTEGER ADKB_USE2P3   = 6
CONST AS UINTEGER ADKB_USE1P2   = 5
CONST AS UINTEGER ADKB_USE0P1   = 4
CONST AS UINTEGER ADKB_USE3VN   = 3
CONST AS UINTEGER ADKB_USE2V3   = 2
CONST AS UINTEGER ADKB_USE1V2   = 1
CONST AS UINTEGER ADKB_USE0V1   = 0

CONST AS UINTEGER ADKF_SETCLR   = 1 SHL 15
CONST AS UINTEGER ADKF_PRECOMP1 = 1 SHL 14
CONST AS UINTEGER ADKF_PRECOMP0 = 1 SHL 13
CONST AS UINTEGER ADKF_MFMPREC	= 1 SHL 12
CONST AS UINTEGER ADKF_UARTBRK  = 1 SHL 11
CONST AS UINTEGER ADKF_WORDSYNC = 1 SHL 10
CONST AS UINTEGER ADKF_MSBSYNC  = 1 SHL 9
CONST AS UINTEGER ADKF_FAST     = 1 SHL 8
CONST AS UINTEGER ADKF_USE3PN   = 1 SHL 7
CONST AS UINTEGER ADKF_USE2P3   = 1 SHL 6
CONST AS UINTEGER ADKF_USE1P2   = 1 SHL 5
CONST AS UINTEGER ADKF_USE0P1   = 1 SHL 4
CONST AS UINTEGER ADKF_USE3VN   = 1 SHL 3
CONST AS UINTEGER ADKF_USE2V3   = 1 SHL 2
CONST AS UINTEGER ADKF_USE1V2   = 1 SHL 1
CONST AS UINTEGER ADKF_USE0V1   = 1 SHL 0

CONST AS UINTEGER ADKF_PRE000NS = 0
CONST AS UINTEGER ADKF_PRE140NS	= ADKF_PRECOMP0
CONST AS UINTEGER ADKF_PRE280NS	= ADKF_PRECOMP1
CONST AS UINTEGER ADKF_PRE560NS	= ADKF_PRECOMP0 OR ADKF_PRECOMP1

CONST AS UINTEGER HSIZEBITS = 6
CONST AS UINTEGER VSIZEBITS = 16
CONST AS UINTEGER HSIZEMASK = &H3f
CONST AS UINTEGER VSIZEMASK = &H3FF
CONST AS UINTEGER MINBYTESPERROW = 128
CONST AS UINTEGER MAXBYTESPERROW = 4096

CONST AS UINTEGER ABC = &H80
CONST AS UINTEGER ABNC = &H40
CONST AS UINTEGER ANBC = &H20
CONST AS UINTEGER ANBNC = &H10
CONST AS UINTEGER NABC = &H8
CONST AS UINTEGER NABNC = &H4
CONST AS UINTEGER NANBC = &H2
CONST AS UINTEGER NANBNC = &H1

CONST AS UINTEGER A_OR_B  = ABC OR ANBC OR NABC  OR  ABNC OR ANBNC OR NABNC
CONST AS UINTEGER A_OR_C  = ABC OR NABC OR ABNC  OR  ANBC OR NANBC OR ANBNC
CONST AS UINTEGER A_XOR_C = NABC OR ABNC    OR  NANBC OR ANBNC
CONST AS UINTEGER A_TO_D  = ABC OR ANBC OR ABNC OR ANBNC

CONST AS UINTEGER BC0B_DEST = 8
CONST AS UINTEGER BC0B_SRCC = 9
CONST AS UINTEGER BC0B_SRCB = 10
CONST AS UINTEGER BC0B_SRCA = 11
CONST AS UINTEGER BC0F_DEST = &H100
CONST AS UINTEGER BC0F_SRCC = &H200
CONST AS UINTEGER BC0F_SRCB = &H400
CONST AS UINTEGER BC0F_SRCA = &H800

CONST AS UINTEGER BC1F_DESC = 2

CONST AS UINTEGER DEST = &H100
CONST AS UINTEGER SRCC = &H200
CONST AS UINTEGER SRCB = &H400
CONST AS UINTEGER SRCA = &H800

CONST AS UINTEGER ASHIFTSHIFT = 12
CONST AS UINTEGER BSHIFTSHIFT = 12

CONST AS UINTEGER LINEMODE = &H1
CONST AS UINTEGER FILL_OR = &H8
CONST AS UINTEGER FILL_XOR = &H10
CONST AS UINTEGER FILL_CARRYIN = &H4
CONST AS UINTEGER ONEDOT = &H2
CONST AS UINTEGER OVFLAG = &H20
CONST AS UINTEGER SIGNFLAG = &H40
CONST AS UINTEGER BLITREVERSE = &H2

CONST AS UINTEGER SUD = &H10
CONST AS UINTEGER SUL = &H8
CONST AS UINTEGER AUL = &H4

CONST AS UINTEGER OCTANT8   = 24
CONST AS UINTEGER OCTANT7   = 4
CONST AS UINTEGER OCTANT6   = 12
CONST AS UINTEGER OCTANT5   = 28
CONST AS UINTEGER OCTANT4   = 20
CONST AS UINTEGER OCTANT3   = 8
CONST AS UINTEGER OCTANT2   = 0
CONST AS UINTEGER OCTANT1   = 16

TYPE bltnode
    AS bltnode PTR         n
    AS FUNCTION AS INTEGER f
    AS BYTE                stat
    AS INTEGER             blitsize
    AS INTEGER             beamsync
    AS FUNCTION AS INTEGER cleanup
END TYPE

CONST AS UINTEGER CLEANUP = &H40
CONST AS UINTEGER CLEANME = CLEANUP

REM FIXME TYPE CIA
REM FIXME     AS volatile     UBYTE   ciapra
REM FIXME     AS UBYTE     pad0[0xff]
REM FIXME     AS volatile     UBYTE   ciaprb
REM FIXME     AS UBYTE     pad1[0xff]
REM FIXME     AS volatile     UBYTE   ciaddra
REM FIXME     AS UBYTE     pad2[0xff]
REM FIXME     AS volatile     UBYTE   ciaddrb
REM FIXME     AS UBYTE     pad3[0xff]
REM FIXME     AS volatile     UBYTE   ciatalo
REM FIXME     AS UBYTE     pad4[0xff]
REM FIXME     AS volatile     UBYTE   ciatahi
REM FIXME     AS UBYTE     pad5[0xff]
REM FIXME     AS volatile     UBYTE   ciatblo
REM FIXME     AS UBYTE     pad6[0xff]
REM FIXME     AS volatile     UBYTE   ciatbhi
REM FIXME     AS UBYTE     pad7[0xff]
REM FIXME     AS volatile     UBYTE   ciatodlow
REM FIXME     AS UBYTE     pad8[0xff]
REM FIXME     AS volatile     UBYTE   ciatodmid
REM FIXME     AS UBYTE     pad9[0xff]
REM FIXME     AS volatile     UBYTE   ciatodhi
REM FIXME     AS UBYTE     pad10[0xff]
REM FIXME     AS volatile     UBYTE   unusedreg
REM FIXME     AS UBYTE     pad11[0xff]
REM FIXME     AS volatile     UBYTE   ciasdr
REM FIXME     AS UBYTE     pad12[0xff]
REM FIXME     AS volatile     UBYTE   ciaicr
REM FIXME     AS UBYTE     pad13[0xff]
REM FIXME     AS volatile     UBYTE   ciacra
REM FIXME     AS UBYTE     pad14[0xff]
REM FIXME     AS volatile     UBYTE   ciacrb
REM FIXME END TYPE

CONST AS UBYTE CIAICRB_TA = 0
CONST AS UBYTE CIAICRB_TB = 1
CONST AS UBYTE CIAICRB_ALRM = 2
CONST AS UBYTE CIAICRB_SP = 3
CONST AS UBYTE CIAICRB_FLG = 4
CONST AS UBYTE CIAICRB_IR = 7
CONST AS UBYTE CIAICRB_SETCLR = 7

CONST AS UBYTE CIACRAB_START = 0
CONST AS UBYTE CIACRAB_PBON = 1
CONST AS UBYTE CIACRAB_OUTMODE = 2
CONST AS UBYTE CIACRAB_RUNMODE = 3
CONST AS UBYTE CIACRAB_LOAD = 4
CONST AS UBYTE CIACRAB_INMODE = 5
CONST AS UBYTE CIACRAB_SPMODE = 6
CONST AS UBYTE CIACRAB_TODIN = 7

CONST AS UBYTE CIACRBB_START = 0
CONST AS UBYTE CIACRBB_PBON = 1
CONST AS UBYTE CIACRBB_OUTMODE = 2
CONST AS UBYTE CIACRBB_RUNMODE = 3
CONST AS UBYTE CIACRBB_LOAD = 4
CONST AS UBYTE CIACRBB_INMODE0 = 5
CONST AS UBYTE CIACRBB_INMODE1 = 6
CONST AS UBYTE CIACRBB_ALARM = 7

CONST AS UBYTE CIAICRF_TA	 = 1 SHL CIAICRB_TA
CONST AS UBYTE CIAICRF_TB	 = 1 SHL CIAICRB_TB
CONST AS UBYTE CIAICRF_ALRM	 = 1 SHL CIAICRB_ALRM
CONST AS UBYTE CIAICRF_SP	 = 1 SHL CIAICRB_SP
CONST AS UBYTE CIAICRF_FLG	 = 1 SHL CIAICRB_FLG
CONST AS UBYTE CIAICRF_IR	 = 1 SHL CIAICRB_IR
CONST AS UBYTE CIAICRF_SETCLR	 = 1 SHL CIAICRB_SETCLR
CONST AS UBYTE CIACRAF_START	 = 1 SHL CIACRAB_START
CONST AS UBYTE CIACRAF_PBON	 = 1 SHL CIACRAB_PBON
CONST AS UBYTE CIACRAF_OUTMODE  = 1 SHL CIACRAB_OUTMODE
CONST AS UBYTE CIACRAF_RUNMODE  = 1 SHL CIACRAB_RUNMODE
CONST AS UBYTE CIACRAF_LOAD	 = 1 SHL CIACRAB_LOAD
CONST AS UBYTE CIACRAF_INMODE	 = 1 SHL CIACRAB_INMODE
CONST AS UBYTE CIACRAF_SPMODE	 = 1 SHL CIACRAB_SPMODE
CONST AS UBYTE CIACRAF_TODIN	 = 1 SHL CIACRAB_TODIN
CONST AS UBYTE CIACRBF_START	 = 1 SHL CIACRBB_START
CONST AS UBYTE CIACRBF_PBON	 = 1 SHL CIACRBB_PBON
CONST AS UBYTE CIACRBF_OUTMODE  = 1 SHL CIACRBB_OUTMODE
CONST AS UBYTE CIACRBF_RUNMODE  = 1 SHL CIACRBB_RUNMODE
CONST AS UBYTE CIACRBF_LOAD	 = 1 SHL CIACRBB_LOAD
CONST AS UBYTE CIACRBF_INMODE0  = 1 SHL CIACRBB_INMODE0
CONST AS UBYTE CIACRBF_INMODE1  = 1 SHL CIACRBB_INMODE1
CONST AS UBYTE CIACRBF_ALARM	 = 1 SHL CIACRBB_ALARM
CONST AS UBYTE CIACRBF_IN_PHI2 = 0
CONST AS UBYTE CIACRBF_IN_CNT	 = CIACRBF_INMODE0
CONST AS UBYTE CIACRBF_IN_TA	 = CIACRBF_INMODE1
CONST AS UBYTE CIACRBF_IN_CNT_TA   = CIACRBF_INMODE0 OR CIACRBF_INMODE1
CONST AS UBYTE CIAB_GAMEPORT1	 = 7
CONST AS UBYTE CIAB_GAMEPORT0	 = 6
CONST AS UBYTE CIAB_DSKRDY	 = 5
CONST AS UBYTE CIAB_DSKTRACK0	 = 4
CONST AS UBYTE CIAB_DSKPROT	 = 3
CONST AS UBYTE CIAB_DSKCHANGE	 = 2
CONST AS UBYTE CIAB_LED	 = 1
CONST AS UBYTE CIAB_OVERLAY	 = 0
CONST AS UBYTE CIAB_COMDTR	 = 7
CONST AS UBYTE CIAB_COMRTS	 = 6
CONST AS UBYTE CIAB_COMCD	 = 5
CONST AS UBYTE CIAB_COMCTS	 = 4
CONST AS UBYTE CIAB_COMDSR	 = 3
CONST AS UBYTE CIAB_PRTRSEL	 = 2
CONST AS UBYTE CIAB_PRTRPOUT	 = 1
CONST AS UBYTE CIAB_PRTRBUSY	 = 0
CONST AS UBYTE CIAB_DSKMOTOR	 = 7
CONST AS UBYTE CIAB_DSKSEL3	 = 6
CONST AS UBYTE CIAB_DSKSEL2	 = 5
CONST AS UBYTE CIAB_DSKSEL1	 = 4
CONST AS UBYTE CIAB_DSKSEL0	 = 3
CONST AS UBYTE CIAB_DSKSIDE	 = 2
CONST AS UBYTE CIAB_DSKDIREC	 = 1
CONST AS UBYTE CIAB_DSKSTEP	 = 0
CONST AS UBYTE CIAF_GAMEPORT1	 = 1 SHL 7
CONST AS UBYTE CIAF_GAMEPORT0	 = 1 SHL 6
CONST AS UBYTE CIAF_DSKRDY	 = 1 SHL 5
CONST AS UBYTE CIAF_DSKTRACK0	 = 1 SHL 4
CONST AS UBYTE CIAF_DSKPROT	 = 1 SHL 3
CONST AS UBYTE CIAF_DSKCHANGE	 = 1 SHL 2
CONST AS UBYTE CIAF_LED	 = 1 SHL 1
CONST AS UBYTE CIAF_OVERLAY	 = 1 SHL 0
CONST AS UBYTE CIAF_COMDTR	 = 1 SHL 7
CONST AS UBYTE CIAF_COMRTS	 = 1 SHL 6
CONST AS UBYTE CIAF_COMCD	 = 1 SHL 5
CONST AS UBYTE CIAF_COMCTS	 = 1 SHL 4
CONST AS UBYTE CIAF_COMDSR	 = 1 SHL 3
CONST AS UBYTE CIAF_PRTRSEL	 = 1 SHL 2
CONST AS UBYTE CIAF_PRTRPOUT	 = 1 SHL 1
CONST AS UBYTE CIAF_PRTRBUSY	 = 1 SHL 0
CONST AS UBYTE CIAF_DSKMOTOR	 = 1 SHL 7
CONST AS UBYTE CIAF_DSKSEL3	 = 1 SHL 6
CONST AS UBYTE CIAF_DSKSEL2	 = 1 SHL 5
CONST AS UBYTE CIAF_DSKSEL1	 = 1 SHL 4
CONST AS UBYTE CIAF_DSKSEL0	 = 1 SHL 3
CONST AS UBYTE CIAF_DSKSIDE	 = 1 SHL 2
CONST AS UBYTE CIAF_DSKDIREC	 = 1 SHL 1
CONST AS UBYTE CIAF_DSKSTEP	 = 1 SHL 0

CONST AS UINTEGER VARVBLANK = &H1000
CONST AS UINTEGER LOLDIS = &H0800
CONST AS UINTEGER CSCBLANKEN = &H0400
CONST AS UINTEGER VARVSYNC = &H0200
CONST AS UINTEGER VARHSYNC = &H0100
CONST AS UINTEGER VARBEAM = &H0080
CONST AS UINTEGER DISPLAYDUAL = &H0040
CONST AS UINTEGER DISPLAYPAL = &H0020
CONST AS UINTEGER VARCSYNC = &H0010
CONST AS UINTEGER CSBLANK = &H0008
CONST AS UINTEGER CSYNCTRUE = &H0004
CONST AS UINTEGER VSYNCTRUE = &H0002
CONST AS UINTEGER HSYNCTRUE = &H0001

CONST AS UINTEGER USE_BPLCON3	= 1
CONST AS UINTEGER BPLCON2_ZDCTEN		 = 1 SHL 10
CONST AS UINTEGER BPLCON2_ZDBPEN		 = 1 SHL 11
CONST AS UINTEGER BPLCON2_ZDBPSEL0	 = 1 SHL 12
CONST AS UINTEGER BPLCON2_ZDBPSEL1	 = 1 SHL 13
CONST AS UINTEGER BPLCON2_ZDBPSEL2	 = 1 SHL 14
CONST AS UINTEGER BPLCON3_EXTBLNKEN	 = 1 SHL 0
CONST AS UINTEGER BPLCON3_EXTBLKZD	 = 1 SHL 1
CONST AS UINTEGER BPLCON3_ZDCLKEN	 = 1 SHL 2
CONST AS UINTEGER BPLCON3_BRDNTRAN	 = 1 SHL 4
CONST AS UINTEGER BPLCON3_BRDNBLNK	 = 1 SHL 5


CONST AS UINTEGER DMAF_SETCLR = &H8000
CONST AS UINTEGER DMAF_AUDIO = &H000F
CONST AS UINTEGER DMAF_AUD0    = &H0001
CONST AS UINTEGER DMAF_AUD1    = &H0002
CONST AS UINTEGER DMAF_AUD2    = &H0004
CONST AS UINTEGER DMAF_AUD3    = &H0008
CONST AS UINTEGER DMAF_DISK = &H0010
CONST AS UINTEGER DMAF_SPRITE = &H0020
CONST AS UINTEGER DMAF_BLITTER = &H0040
CONST AS UINTEGER DMAF_COPPER = &H0080
CONST AS UINTEGER DMAF_RASTER = &H0100
CONST AS UINTEGER DMAF_MASTER = &H0200
CONST AS UINTEGER DMAF_BLITHOG = &H0400
CONST AS UINTEGER DMAF_ALL = &H01FF
CONST AS UINTEGER DMAF_BLTDONE = &H4000
CONST AS UINTEGER DMAF_BLTNZERO = &H2000
CONST AS UINTEGER DMAB_SETCLR = 15
CONST AS UINTEGER DMAB_AUD0 =   0
CONST AS UINTEGER DMAB_AUD1 =   1
CONST AS UINTEGER DMAB_AUD2 =   2
CONST AS UINTEGER DMAB_AUD3 =   3
CONST AS UINTEGER DMAB_DISK = 4
CONST AS UINTEGER DMAB_SPRITE = 5
CONST AS UINTEGER DMAB_BLITTER = 6
CONST AS UINTEGER DMAB_COPPER = 7
CONST AS UINTEGER DMAB_RASTER = 8
CONST AS UINTEGER DMAB_MASTER = 9
CONST AS UINTEGER DMAB_BLITHOG = 10
CONST AS UINTEGER DMAB_BLTDONE = 14
CONST AS UINTEGER DMAB_BLTNZERO = 13

CONST AS UINTEGER  INTB_SETCLR	 = 15
CONST AS UINTEGER  INTB_INTEN	     = 14
CONST AS UINTEGER  INTB_EXTER	     = 13
CONST AS UINTEGER  INTB_DSKSYNC	 = 12
CONST AS UINTEGER  INTB_RBF	     = 11
CONST AS UINTEGER  INTB_AUD3	     = 10
CONST AS UINTEGER  INTB_AUD2	     = 9
CONST AS UINTEGER  INTB_AUD1	     = 8
CONST AS UINTEGER  INTB_AUD0	     = 7
CONST AS UINTEGER  INTB_BLIT	     = 6
CONST AS UINTEGER  INTB_VERTB	     = 5
CONST AS UINTEGER  INTB_COPER	     = 4
CONST AS UINTEGER  INTB_PORTS	     = 3
CONST AS UINTEGER  INTB_SOFTINT	 = 2
CONST AS UINTEGER  INTB_DSKBLK	 = 1
CONST AS UINTEGER  INTB_TBE	 = 0
CONST AS UINTEGER  INTF_SETCLR	 = 1 SHL 15
CONST AS UINTEGER  INTF_INTEN	 = 1 SHL 14
CONST AS UINTEGER  INTF_EXTER	 = 1 SHL 13
CONST AS UINTEGER  INTF_DSKSYNC	 = 1 SHL 12
CONST AS UINTEGER  INTF_RBF	 = 1 SHL 11
CONST AS UINTEGER  INTF_AUD3	 = 1 SHL 10
CONST AS UINTEGER  INTF_AUD2	 = 1 SHL 9
CONST AS UINTEGER  INTF_AUD1	 = 1 SHL 8
CONST AS UINTEGER  INTF_AUD0	 = 1 SHL 7
CONST AS UINTEGER  INTF_BLIT	 = 1 SHL 6
CONST AS UINTEGER  INTF_VERTB	 = 1 SHL 5
CONST AS UINTEGER  INTF_COPER	 = 1 SHL 4
CONST AS UINTEGER  INTF_PORTS	 = 1 SHL 3
CONST AS UINTEGER  INTF_SOFTINT	 = 1 SHL 2
CONST AS UINTEGER  INTF_DSKBLK	 = 1 SHL 1
CONST AS UINTEGER  INTF_TBE	 = 1 SHL 0
