From: Oliver Schmidt 
Date: Sat, 4 May 2013 20:10:48 +0000 (+0200)
Subject: Replaced whole bunch for Makefiles with a single generic Makefile.
X-Git-Tag: V2.14~29
X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=008b4c4e1d952cc71b082f121b7e6d3d9e43132c;p=cc65
Replaced whole bunch for Makefiles with a single generic Makefile.
- No complex shell logic.
- "Source file shadowing" for all targets via vpath.
- Dependency handling.
- True incremental build.
- Don't write into source directories.
- Easy cleanup by just removing 'wrk'.
---
diff --git a/libsrc/apple2/Makefile b/libsrc/apple2/Makefile
deleted file mode 100644
index 791aa6dc4..000000000
--- a/libsrc/apple2/Makefile
+++ /dev/null
@@ -1,182 +0,0 @@
-#
-# makefile for CC65 runtime library
-#
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= apple2
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	%.c
-	@$(CC) $(CFLAGS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-mou.o: %.mou
-	@$(CO) -o $(*)-mou.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-mou.s
-
-%-ser.o: %.ser
-	@$(CO) -o $(*)-ser.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-ser.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.mou:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.ser:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-#--------------------------------------------------------------------------
-# Object files
-
-C_OBJS=	closedir.o		\
-	opendir.o		\
-	readdir.o		\
-	rewinddir.o
-
-S_OBJS=	_scrsize.o		\
-	break.o			\
-	cclear.o		\
-	cgetc.o			\
-	chline.o		\
-	close.o			\
-	clrscr.o		\
-	color.o			\
-	cout.o			\
-	cputc.o			\
-	crt0.o			\
-	ctype.o			\
-	curdevice.o		\
-	cvline.o		\
-	devicedir.o		\
-	dioclose.o		\
-	diocommon.o		\
-	dioopen.o		\
-	dioread.o		\
-	diosectcount.o		\
-	diosectsize.o		\
-	diowrite.o		\
-	dosdetect.o		\
-	exec.o			\
-	exehdr.o		\
-	filedes.o		\
-	filename.o		\
-	get_ostype.o		\
-	getdevice.o		\
-	gotoxy.o		\
-	gotoy.o			\
-	home.o			\
-	initcwd.o		\
-	iobuf.o			\
-	irq.o			\
-	isdevice.o		\
-	joy_stat_stddrv.o	\
-	joy_stddrv.o		\
-	kbhit.o			\
-	mainargs.o		\
-	mcbdefault.o		\
-	mli.o			\
-	mouse_stat_stddrv.o	\
-	mouse_stddrv.o		\
-	open.o			\
-	oserrlist.o		\
-	oserror.o		\
-	randomize.o		\
-	rdkey.o			\
-	read.o			\
-	reboot.o		\
-	revers.o		\
-	rwcommon.o		\
-	syschdir.o		\
-	sysmkdir.o		\
-	sysremove.o		\
-	sysrename.o		\
-	sysrmdir.o		\
-	systime.o		\
-	sysuname.o		\
-	tgi_colors.o		\
-	tgi_stat_stddrv.o	\
-	tgi_stddrv.o		\
-	toascii.o		\
-	vtabz.o			\
-	wherex.o		\
-	wherey.o		\
-	write.o			\
-	$(EMDS:.emd=-emd.o)	\
-	$(JOYS:.joy=-joy.o)	\
-	$(MOUS:.mou=-mou.o)	\
-	$(SERS:.ser=-ser.o)	\
-	$(TGIS:.tgi=-tgi.o)
-
-S_EXTRA_OBJS=			\
-	extra/iobuf-0800.o
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS = apple2-auxmem.emd
-
-JOYS = apple2-stdjoy.joy
-
-MOUS = apple2-stdmou.mou
-
-SERS = apple2-ssc.ser
-
-TGIS = apple2-280-192-8.tgi apple2-40-48-16.tgi
-
-#--------------------------------------------------------------------------
-# Targets
-
-.PHONY:	all clean zap
-
-all:	$(C_OBJS) $(S_OBJS) $(S_EXTRA_OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) $(S_EXTRA_OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(MOUS:.mou=.o) $(MOUS:.mou=-mou.s) \
-	       $(SERS:.ser=.o) $(SERS:.ser=-ser.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
diff --git a/libsrc/apple2/apple2-280-192-8.fnt b/libsrc/apple2/apple2-280-192-8.fnt
deleted file mode 100644
index 5f23de569..000000000
Binary files a/libsrc/apple2/apple2-280-192-8.fnt and /dev/null differ
diff --git a/libsrc/apple2/apple2-280-192-8.s b/libsrc/apple2/apple2-280-192-8.s
deleted file mode 100644
index b8e315f18..000000000
--- a/libsrc/apple2/apple2-280-192-8.s
+++ /dev/null
@@ -1,445 +0,0 @@
-;
-; Graphics driver for the 280x192x8 mode on the Apple II
-;
-; Stefan Haubenthal 
-; Oliver Schmidt 
-;
-
-	.include	"zeropage.inc"
-
-	.include	"tgi-kernel.inc"
-	.include	"tgi-error.inc"
-	.include	"apple2.inc"
-
-; ------------------------------------------------------------------------
-
-; Zero page stuff
-
-HBASL	:=	$26
-HMASK	:=	$30
-PAGE	:=	$E6
-SCALE	:=	$E7
-ROT	:=	$F9
-
-; Graphics entry points, by cbmnut (applenut??) cbmnut@hushmail.com
-
-TEXT    :=	$F399	; Return to text screen
-HGR2    :=	$F3D8	; Initialize and clear hi-res page 2.
-HGR     :=	$F3E2	; Initialize and clear hi-res page 1.
-HCLR    :=	$F3F2	; Clear the current hi-res screen to black.
-BKGND   :=	$F3F6	; Clear the current hi-res screen to the
-                        ; last plotted color (from ($1C).
-HPOSN   :=	$F411	; Positions the hi-res cursor without
-                        ; plotting a point.
-                        ; Enter with (A) = Y-coordinate, and
-                        ; (Y,X) = X-coordinate.
-HPLOT   :=	$F457	; Calls HPOSN and tries to plot a dot at
-                        ; the cursor's position.  If you are
-                        ; trying to plot a non-white color at
-                        ; a complementary color position, no
-                        ; dot will be plotted.
-HLIN    :=	$F53A	; Draws a line from the last plotted
-                        ; point or line destination to:
-                        ; (X,A) = X-coordinate, and
-                        ; (Y) = Y-coordinate.
-HFIND   :=	$F5CB	; Converts the hi-res coursor's position
-                        ; back to X- and Y-coordinates; stores
-                        ; X-coordinate at $E0,E1 and Y-coordinate
-                        ; at $E2.
-DRAW    :=	$F601	; Draws a shape.  Enter with (Y,X) = the
-                        ; address of the shape table, and (A) =
-                        ; the rotation factor.  Uses the current
-                        ; color.
-XDRAW   :=	$F65D	; Draws a shape by inverting the existing
-                        ; color of the dots the shape draws over.
-                        ; Same entry parameters as DRAW.
-SETHCOL :=	$F6EC	; Set the hi-res color to (X), where (X)
-                        ; must be between 0 and 7.
-
-; ------------------------------------------------------------------------
-
-; Variables mapped to the zero page segment variables. Some of these are
-; used for passing parameters to the driver.
-
-X1	:=	ptr1
-Y1	:=	ptr2
-X2	:=	ptr3
-Y2	:=	ptr4
-
-; ------------------------------------------------------------------------
-
-	.segment	"JUMPTABLE"
-
-; Header. Includes jump table and constants.
-
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
-
-	.byte	$74, $67, $69	; "tgi"
-	.byte	TGI_API_VERSION	; TGI API version number
-	.word	280		; X resolution
-	.word	192		; Y resolution
-	.byte	8		; Number of drawing colors
-pages:	.byte	2		; Number of screens available
-	.byte	7		; System font X size
-	.byte	8		; System font Y size
-	.word   $00EA		; Aspect ratio (based on 4/3 display)
-        .byte   0               ; TGI driver flags
-
-; Next comes the jump table. With the exception of IRQ, all entries must be
-; valid and may point to an RTS for test versions (function not implemented).
-
-       	.addr   INSTALL
-       	.addr   UNINSTALL
-       	.addr   INIT
-       	.addr   DONE
-       	.addr   GETERROR
-       	.addr   CONTROL
-       	.addr   CLEAR
-       	.addr   SETVIEWPAGE
-       	.addr   SETDRAWPAGE
-       	.addr   SETCOLOR
-       	.addr   SETPALETTE
-       	.addr   GETPALETTE
-       	.addr   GETDEFPALETTE
-       	.addr   SETPIXEL
-       	.addr   GETPIXEL
-       	.addr   LINE
-       	.addr   BAR
-       	.addr   TEXTSTYLE
-       	.addr   OUTTEXT
-        .addr   0               ; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-
-	.bss
-
-; Absolute variables used in the code
-
-ERROR:	.res	1		; Error code
-
-; ------------------------------------------------------------------------
-
-	.rodata
-
-; Constants and tables
-
-DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
-
-FONT:
-	; Beagle Bros Shape Mechanic font F.ASCII.SMALL
-	; modified to exactly reproduce the text glyphs
-	.incbin	"../apple2/apple2-280-192-8.fnt"
-
-; ------------------------------------------------------------------------
-
-	.code
-
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-; Must set an error code: NO
-INSTALL:
-	.ifdef  __APPLE2ENH__
-	; No page switching if 80 column store is enabled
-	bit	RD80COL
-	bpl	:+
-	lda	#$01
-	sta	pages
-:	.endif
-
-	; Fall through
-
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL but is probably empty most of the time.
-; Must set an error code: NO
-UNINSTALL:
-	rts
-
-; INIT: Changes an already installed device from text mode to graphics mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is only called once, so any code that is needed
-; to initializes variables and so on must go here. Setting palette and
-; clearing the screen is not needed because this is called by the graphics
-; kernel later.
-; The graphics kernel will never call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-; Must set an error code: YES
-INIT:
-	; Switch into graphics mode
-	bit	MIXCLR
-	bit	HIRES
-	bit	TXTCLR
-
-	; Beagle Bros Shape Mechanic fonts don't
-	; scale well so use fixed scaling factor
-	lda	#$01
-	sta	SCALE
-
-	; Done, reset the error code
-	lda	#TGI_ERR_OK
-	sta	ERROR
-	rts
-
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel will never call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-; Must set an error code: NO
-DONE:
-	; Switch into text mode
-	bit	TXTSET
-	bit	LOWSCR
-
-	.ifdef  __APPLE2ENH__
-	; Limit SET80COL-HISCR to text
-	bit	LORES
-	.endif
-
-	; Reset the text window top
-	lda	#$00
-	sta	WNDTOP
-	rts
-
-; GETERROR: Return the error code in A and clear it.
-GETERROR:
-	lda	ERROR
-	ldx	#TGI_ERR_OK
-	stx	ERROR
-	rts
-
-; CONTROL: Platform/driver specific entry point.
-; Must set an error code: YES
-CONTROL:
-	; Check data msb and code to be 0
-	ora	ptr1+1
-	bne	err
-
-	; Check data lsb to be [0..1]
-	lda	ptr1
-	cmp	#1+1
-	bcs	err
-
-	; Set text window top
-	tax
-	beq	:+
-	lda	#20
-:	sta	WNDTOP
-
-	; Switch 4 lines of text
-	.assert MIXCLR + 1 = MIXSET, error
-	lda	MIXCLR,x	; No BIT absolute,X available
-
-	; Done, reset the error code
-	lda	#TGI_ERR_OK
-	beq	:+		; Branch always
-
-	; Done, set the error code
-err:	lda	#TGI_ERR_INV_ARG
-:	sta	ERROR
-	rts
-
-; CLEAR: Clears the screen.
-; Must set an error code: NO
-CLEAR:
-	bit	$C082		; Switch in ROM
-	jsr	HCLR
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-; Must set an error code: NO (will only be called if page ok)
-SETVIEWPAGE:
-	tax
-	.assert LOWSCR + 1 = HISCR, error
-	lda	LOWSCR,x	; No BIT absolute,X available
-	rts
-
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-; Must set an error code: NO (will only be called if page ok)
-SETDRAWPAGE:
-	tax
-	beq	:+
-	lda	#>$4000		; Page 2
-	.byte	$2C		; BIT absolute
-:	lda	#>$2000		; Page 1
-	sta	PAGE
-	rts
-
-; SETCOLOR: Set the drawing color (in A). The new color is already checked
-; to be in a valid range (0..maxcolor-1).
-; Must set an error code: NO (will only be called if color ok)
-SETCOLOR:
-	bit	$C082		; Switch in ROM
-	tax
-	jsr	SETHCOL
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported
-; Must set an error code: YES
-SETPALETTE:
-	lda	#TGI_ERR_INV_FUNC
-	sta	ERROR
-	rts
-
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-; Must set an error code: NO
-GETPALETTE:
-	; Fall through
-
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes, otherwise the caller has no way to determine the colors
-; of the (not changeable) palette.
-; Must set an error code: NO (all drivers must have a default palette)
-GETDEFPALETTE:
-	lda	#DEFPALETTE
-	rts
-
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The coordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-; Must set an error code: NO
-SETPIXEL:
-	bit	$C082		; Switch in ROM
-	ldx	X1
-	ldy	X1+1
-	lda	Y1
-	jsr	HPLOT
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; GETPIXEL: Read the color value of a pixel and return it in A/X. The
-; coordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-GETPIXEL:
-	bit	$C082		; Switch in ROM
-	ldx	X1
-	ldy	X1+1
-	lda	Y1
-	jsr	HPOSN
-	lda	(HBASL),y
-	and	HMASK
-	asl
-	beq	:+		; 0 (black)
-	lda	#$03		; 3 (white)
-:	bcc	:+
-	adc	#$03		; += 4 (black -> black2, white -> white2)
-:	ldx	#$00
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
-; X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Must set an error code: NO
-LINE:
-	bit	$C082		; Switch in ROM
-	ldx	X1
-	ldy	X1+1
-	lda	Y1
-	jsr	HPOSN
-	lda	X2
-	ldx	X2+1
-	ldy	Y2
-	jsr	HLIN
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the coordinates before calling the driver, so on entry the following
-; conditions are valid:
-;	X1 <= X2
-;	Y1 <= Y2
-;	(X1 >= 0) && (X1 < XRES)
-;	(X2 >= 0) && (X2 < XRES)
-;	(Y1 >= 0) && (Y1 < YRES)
-;	(Y2 >= 0) && (Y2 < YRES)
-; Must set an error code: NO
-BAR:
-	inc	Y2
-:	lda	Y2
-	pha
-  	lda	Y1
-	sta	Y2
-	jsr	LINE
-	pla
-	sta	Y2
-	inc	Y1
-	cmp	Y1
-	bne	:-
-	rts
-
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
-; direction is passend in X/Y, the text direction is passed in A.
-; Must set an error code: NO
-TEXTSTYLE:
-	cmp	#TGI_TEXT_VERTICAL
-	bne	:+
-	lda	#48
-:	sta	ROT
-	rts
-
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero terminated
-; string with address in ptr3.
-; Must set an error code: NO
-OUTTEXT:
-	bit	$C082		; Switch in ROM
-	lda	X1
-	ldy	X1+1
-	ldx	ROT
-	php			; Save Z flag
-	beq	:+		; Not horizontal
-	sec
-	sbc	#$07		; Adjust X
-	bcs	:+
-	dey
-:	tax
-	lda	Y1
-	plp			; Restore Z flag
-	bne	:+		; Not vertical
-	sec
-	sbc	#$07		; Adjust Y
-:	jsr	HPOSN
-	clc
-	lda	FONT+2*99	; "connection char"
-	adc	#FONT
-	sta	ptr4+1
-	ldy	#$00
-:	lda	(ptr3),y
-	beq	:+
-	sty	tmp1		; Save string index
-	sec
-	sbc	#$1F		; No control chars
-	asl			; Offset * 2
-	tay
-	clc
-	lda	FONT,y
-	adc	#FONT
-	tay
-	lda	ROT
-	jsr	DRAW		; Draw char from string
-	ldx	ptr4
-	ldy	ptr4+1
-	lda	ROT
-	jsr	DRAW		; Draw "connection char"
-	ldy	tmp1		; Restore string index
-	iny
-	bne	:-		; Branch always
-:	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
diff --git a/libsrc/apple2/apple2-40-48-16.s b/libsrc/apple2/apple2-40-48-16.s
deleted file mode 100644
index 135c883bc..000000000
--- a/libsrc/apple2/apple2-40-48-16.s
+++ /dev/null
@@ -1,347 +0,0 @@
-;
-; Graphics driver for the 40x48x16 mode on the Apple II
-;
-; Stefan Haubenthal 
-; Oliver Schmidt 
-;
-
-	.include	"zeropage.inc"
-
-	.include	"tgi-kernel.inc"
-	.include	"tgi-error.inc"
-	.include	"apple2.inc"
-
-; ------------------------------------------------------------------------
-
-; Zero page stuff
-
-H2	:=	$2C
-COLOR	:=	$30
-
-; ROM entry points
-
-TEXT    :=	$F399
-PLOT	:=	$F800
-HLINE	:=	$F819
-CLRSC2	:=	$F838
-SETCOL	:=	$F864
-SCRN	:=	$F871
-SETGR	:=	$FB40
-HOME	:=	$FC58
-
-; Used for passing parameters to the driver
-
-X1	:=	ptr1
-Y1	:=	ptr2
-X2	:=	ptr3
-Y2	:=	ptr4
-
-; ------------------------------------------------------------------------
-
-	.segment	"JUMPTABLE"
-
-; Header. Includes jump table and constants.
-
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
-
-	.byte	$74, $67, $69	; "tgi"
-	.byte	TGI_API_VERSION	; TGI API version number
-	.word	40		; X resolution
-	.word	48		; Y resolution
-	.byte	16		; Number of drawing colors
-	.byte	1		; Number of screens available
-	.byte	8		; System font X size
-	.byte	8		; System font Y size
-	.word   $0198		; Aspect ratio (based on 4/3 display)
-        .byte   0               ; TGI driver flags
-
-; Next comes the jump table. With the exception of IRQ, all entries must be
-; valid and may point to an RTS for test versions (function not implemented).
-
-       	.addr   INSTALL
-       	.addr   UNINSTALL
-       	.addr   INIT
-       	.addr   DONE
-       	.addr   GETERROR
-       	.addr   CONTROL
-       	.addr   CLEAR
-       	.addr   SETVIEWPAGE
-       	.addr   SETDRAWPAGE
-       	.addr   SETCOLOR
-       	.addr   SETPALETTE
-       	.addr   GETPALETTE
-       	.addr   GETDEFPALETTE
-       	.addr   SETPIXEL
-       	.addr   GETPIXEL
-       	.addr   LINE
-       	.addr   BAR
-       	.addr   TEXTSTYLE
-       	.addr   OUTTEXT
-        .addr   0               ; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-
-	.bss
-
-ERROR:	.res	1		; Error code
-MIX:	.res	1		; 4 lines of text
-
-; ------------------------------------------------------------------------
-
-	.rodata
-
-DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
-	    .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
-
-TGI2COL:    .byte $00, $0C, $03, $0F, $01, $09, $06, $02
-	    .byte $04, $05, $07, $08, $0A, $0B, $0D, $0E
-
-COL2TGI:    .byte $00, $04, $07, $02, $08, $09, $06, $0A
-	    .byte $0B, $05, $0C, $0D, $01, $0E, $0F, $03
-
-MAXY:	.byte 47, 39
-
-; ------------------------------------------------------------------------
-
-	.code
-
-; INIT: Changes an already installed device from text mode to graphics mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is only called once, so any code that is needed
-; to initializes variables and so on must go here. Setting palette and
-; clearing the screen is not needed because this is called by the graphics
-; kernel later.
-; The graphics kernel will never call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-; Must set an error code: YES
-INIT:
-	; Switch into graphics mode
-	bit	$C082		; Switch in ROM
-	jsr	SETGR
-	bit	MIXCLR
-	bit	$C080		; Switch in LC bank 2 for R/O
-
-	; Done, reset the error code
-	lda	#TGI_ERR_OK
-	sta	ERROR
-	sta	MIX
-
-	; Fall through
-
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-; Must set an error code: NO
-INSTALL:
-	; Fall through
-
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL but is probably empty most of the time.
-; Must set an error code: NO
-UNINSTALL:
-	; Fall through
-
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-; Must set an error code: NO (will only be called if page ok)
-SETVIEWPAGE:
-	; Fall through
-
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-; Must set an error code: NO (will only be called if page ok)
-SETDRAWPAGE:
-	; Fall through
-
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
-; direction is passend in X/Y, the text direction is passed in A.
-; Must set an error code: NO
-TEXTSTYLE:
-	; Fall through
-
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero terminated
-; string with address in ptr3.
-; Must set an error code: NO
-OUTTEXT:
-	rts
-
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel will never call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-; Must set an error code: NO
-DONE:
-	bit	$C082		; Switch in ROM
-	jsr	TEXT
-	jsr	HOME
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; GETERROR: Return the error code in A and clear it.
-GETERROR:
-	lda	ERROR
-	ldx	#TGI_ERR_OK
-	stx	ERROR
-	rts
-
-; CLEAR: Clears the screen.
-; Must set an error code: NO
-CLEAR:
-	bit	$C082		; Switch in ROM
-	lda	COLOR		; Save current drawing color
-	pha
-	ldx	MIX
-	ldy	MAXY,x		; Max Y depends on 4 lines of text
-	jsr	CLRSC2
-	pla
-	sta	COLOR		; Restore current drawing color
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; SETCOLOR: Set the drawing color (in A). The new color is already checked
-; to be in a valid range (0..maxcolor-1).
-; Must set an error code: NO (will only be called if color ok)
-SETCOLOR:
-	bit	$C082		; Switch in ROM
-	tax
-	lda	TGI2COL,x
-	jsr	SETCOL
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; CONTROL: Platform/driver specific entry point.
-; Must set an error code: YES
-CONTROL:
-	; Check data msb and code to be 0
-	ora	ptr1+1
-	bne	err
-
-	; Check data lsb to be [0..1]
-	lda	ptr1
-	cmp	#1+1
-	bcs	err
-	bit	$C082		; Switch in ROM
-
-	; Switch 4 lines of text
-	tax
-	.assert MIXCLR + 1 = MIXSET, error
-	lda	MIXCLR,x	; No BIT absolute,X available
-
-	; Save current switch setting
-	txa
-	sta	MIX
-	bne	text
-
-	; Clear 8 lines of graphics
-	lda	COLOR		; Save current drawing color
-	pha
-	lda	#39		; Rightmost column
-	sta	H2
-	ldx	#40		; First line
-:	txa
-	ldy	#$00		; Leftmost column
-	sty	COLOR		; Black
-	jsr	HLINE		; Preserves X
-	inx
-	cpx	#47+1		; Last line
-	bcc	:-
-	pla
-	sta	COLOR		; Restore current drawing color
-	bcs	:+		; Branch always
-
-	; Clear 4 lines of text
-text:	jsr	HOME
-:	bit	$C080		; Switch in LC bank 2 for R/O
-
-	; Done, reset the error code
-	lda	#TGI_ERR_OK
-	beq	:+		; Branch always
-
-	; Done, set the error code
-err:	lda	#TGI_ERR_INV_ARG
-:	sta	ERROR
-	rts
-
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported
-; Must set an error code: YES
-SETPALETTE:
-	lda	#TGI_ERR_INV_FUNC
-	sta	ERROR
-	rts
-
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-; Must set an error code: NO
-GETPALETTE:
-	; Fall through
-
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes, otherwise the caller has no way to determine the colors
-; of the (not changeable) palette.
-; Must set an error code: NO (all drivers must have a default palette)
-GETDEFPALETTE:
-	lda	#DEFPALETTE
-	rts
-
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The coordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-; Must set an error code: NO
-SETPIXEL:
-	bit	$C082		; Switch in ROM
-	ldy	X1
-	lda	Y1
-	jsr	PLOT
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; GETPIXEL: Read the color value of a pixel and return it in A/X. The
-; coordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-GETPIXEL:
-	bit	$C082		; Switch in ROM
-	ldy	X1
-	lda	Y1
-	jsr	SCRN
-	tax
-	lda	COL2TGI,x
-	ldx	#$00
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the coordinates before calling the driver, so on entry the following
-; conditions are valid:
-;	X1 <= X2
-;	Y1 <= Y2
-;	(X1 >= 0) && (X1 < XRES)
-;	(X2 >= 0) && (X2 < XRES)
-;	(Y1 >= 0) && (Y1 < YRES)
-;	(Y2 >= 0) && (Y2 < YRES)
-; Must set an error code: NO
-BAR:
-	bit	$C082		; Switch in ROM
-	lda	X2
-	sta	H2
-	inc	Y2
-	ldx	Y1
-:	txa
-	ldy	X1
-	jsr	HLINE		; Preserves X
-	inx
-	cpx	Y2
-	bcc	:-
-	bit	$C080		; Switch in LC bank 2 for R/O
-	rts
-
-; ------------------------------------------------------------------------
-
-.include	"../tgi/tgidrv_line.inc"
diff --git a/libsrc/apple2/apple2-auxmem.s b/libsrc/apple2/apple2-auxmem.s
deleted file mode 100644
index 7a72cfc85..000000000
--- a/libsrc/apple2/apple2-auxmem.s
+++ /dev/null
@@ -1,235 +0,0 @@
-;
-; Extended memory driver for the Apple II auxiliary memory
-;
-; Stefan Haubenthal, 2003-12-12
-; Ullrich von Bassewitz, 2002-12-02
-;
-
-	.include	"zeropage.inc"
-
-	.include	"em-kernel.inc"
-	.include	"em-error.inc"
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-; Driver signature
-
-	.byte	$65, $6d, $64		; "emd"
-	.byte	EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-	.word	INSTALL
-	.word	DEINSTALL
-	.word	PAGECOUNT
-	.word	MAP
-	.word	USE
-	.word	COMMIT
-	.word	COPYFROM
-	.word	COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BASE	= $0200
-AUXCARD	= $C30C				; Card signature
-AUXMOVE	= $C311				; Auxiliary move routine
-PAGES	= ($C000 - BASE) / 256
-
-; ------------------------------------------------------------------------
-; Data.
-
-.data
-curpage:	.byte	$FF		; Current page number (invalid)
-
-.bss
-window:		.res	256		; Memory "window"
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-	ldx	#0
-	lda	AUXCARD
-	and	#$f0
-	cmp	#$80
-	bne	@L1
-	lda	#EM_ERR_OK
-	rts
-@L1:	lda	#EM_ERR_NO_DEVICE
-;	rts
-
-; ------------------------------------------------------------------------
-; DEINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-DEINSTALL:
-	rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-	lda	#PAGES
-	rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:	sta	curpage			; Remember the new page
-
-	clc
-	adc	#>BASE
-	sta	ptr1+1
-	ldy	#$00
-	sty	ptr1
-
-	lda	#window
-	sta	ptr2+1
-
-; Transfer one page
-
-	clc				; Direction flag
-	jsr	transfer		; Transfer one page
-
-; Return the memory window
-
-	lda	#window		; Return the window address
-
-; Done
-
-done:	rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:	sta	curpage			; Remember the page
-	lda	#window		; Return the window
-	rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda	curpage			; Get the current page
-	cmp	#$FF
-	beq	done			; Jump if no page mapped
-
-	clc
-	adc	#>BASE
-	sta	ptr2+1
-	ldy	#$00
-	sty	ptr2
-
-	lda	#window
-	sta	ptr1+1
-	lda	#<$FF
-	sta	ptr4
-	lda	#>$FF
-	sta	ptr4+1
-	sec				; Direction flag
-
-; Transfer one page/all bytes
-
-transfer:
-	php
-	clc
-	lda	ptr1
-	sta	$3C
-	adc	ptr4
-	sta	$3E
-	lda	ptr1+1
-	sta	$3D
-	adc	ptr4+1
-	sta	$3F
-	lda	ptr2
-	sta	$42
-	lda	ptr2+1
-	sta	$43
-	plp
-	jmp	AUXMOVE
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-	sta	ptr3
-	stx	ptr3+1			; Save the passed em_copy pointer
-
-	ldy	#EM_COPY::OFFS
-	lda	(ptr3),y
-	sta	ptr1
-	ldy	#EM_COPY::PAGE
-	lda	(ptr3),y
-	clc
-	adc	#>BASE
-	sta	ptr1+1			; From
-
-	ldy	#EM_COPY::BUF
-	lda	(ptr3),y
-	sta	ptr2
-	iny
-	lda	(ptr3),y
-	sta	ptr2+1			; To
-	clc				; Direction flag
-
-common: ldy	#EM_COPY::COUNT
-	lda	(ptr3),y		; Get bytes in last page
-	sta	ptr4
-	iny
-	lda	(ptr3),y		; Get number of pages
-	sta	ptr4+1
-
-	jmp	transfer
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO: sta	ptr3
-	stx	ptr3+1			; Save the passed em_copy pointer
-
-	ldy	#EM_COPY::OFFS
-	lda	(ptr3),y
-	sta	ptr2
-	ldy	#EM_COPY::PAGE
-	lda	(ptr3),y
-	clc
-	adc	#>BASE
-	sta	ptr2+1			; To
-
-	ldy	#EM_COPY::BUF
-	lda	(ptr3),y
-	sta	ptr1
-	iny
-	lda	(ptr3),y
-	sta	ptr1+1			; From
-
-	sec				; Direction flag
-	jmp	common
diff --git a/libsrc/apple2/apple2-ssc.s b/libsrc/apple2/apple2-ssc.s
deleted file mode 100644
index cb9ff2ec1..000000000
--- a/libsrc/apple2/apple2-ssc.s
+++ /dev/null
@@ -1,435 +0,0 @@
-;
-; Serial driver for the Apple II Super Serial Card.
-;
-; Oliver Schmidt, 21.04.2005
-;
-; The driver is based on the cc65 rs232 module, which in turn is based on
-; Craig Bruce device driver for the Switftlink/Turbo-232.
-;
-; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
-;
-; This software is Public Domain.  It is in Buddy assembler format.
-;
-; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
-; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
-; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
-; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
-;
-; The code assumes that the kernal + I/O are in context.  On the C128, call
-; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
-; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
-; interrupt handling assumes that the 65816 is in 6502-emulation mode.
-;
-
-	.include	"zeropage.inc"
-	.include	"ser-kernel.inc"
-	.include	"ser-error.inc"
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-	.segment	"JUMPTABLE"
-
-	; Driver signature
-	.byte	$73, $65, $72		; "ser"
-	.byte	SER_API_VERSION 	; Serial API version number
-
-	; Jump table.
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	OPEN
-	.addr	CLOSE
-	.addr	GET
-	.addr	PUT
-	.addr	STATUS
-	.addr	IOCTL
-	.addr	IRQ
-
-;----------------------------------------------------------------------------
-; I/O definitions
-
-ACIA		= $C088
-ACIA_DATA	= ACIA+0	; Data register
-ACIA_STATUS	= ACIA+1	; Status register
-ACIA_CMD	= ACIA+2	; Command register
-ACIA_CTRL	= ACIA+3	; Control register
-
-;----------------------------------------------------------------------------
-; Global variables
-
-	.bss
-
-RecvHead:	.res	1	; Head of receive buffer
-RecvTail:	.res	1	; Tail of receive buffer
-RecvFreeCnt:	.res	1	; Number of bytes in receive buffer
-SendHead:	.res	1	; Head of send buffer
-SendTail:	.res	1	; Tail of send buffer
-SendFreeCnt:	.res	1	; Number of bytes in send buffer
-
-Stopped:	.res	1	; Flow-stopped flag
-RtsOff: 	.res	1	;
-
-RecvBuf:	.res	256	; Receive buffers: 256 bytes
-SendBuf:	.res	256	; Send buffers: 256 bytes
-
-Index:		.res	1	; I/O register index
-
-	.data
-
-Slot:	.byte	$02		; Default to SSC in slot 2
-
-	.rodata
-
-	; Tables used to translate RS232 params into register values
-BaudTable:			; bit7 = 1 means setting is invalid
-	.byte	$FF		; SER_BAUD_45_5
-	.byte	$01		; SER_BAUD_50
-	.byte	$02		; SER_BAUD_75
-	.byte	$03		; SER_BAUD_110
-	.byte	$04		; SER_BAUD_134_5
-	.byte	$05		; SER_BAUD_150
-	.byte	$06		; SER_BAUD_300
-	.byte	$07		; SER_BAUD_600
-	.byte	$08		; SER_BAUD_1200
-	.byte	$09		; SER_BAUD_1800
-	.byte	$0A		; SER_BAUD_2400
-	.byte	$0B		; SER_BAUD_3600
-	.byte	$0C		; SER_BAUD_4800
-	.byte	$0D		; SER_BAUD_7200
-	.byte	$0E		; SER_BAUD_9600
-	.byte	$0F		; SER_BAUD_19200
-	.byte	$FF		; SER_BAUD_38400
-	.byte	$FF		; SER_BAUD_57600
-	.byte	$FF		; SER_BAUD_115200
-	.byte	$FF		; SER_BAUD_230400
-BitTable:
-	.byte	$60		; SER_BITS_5
-	.byte	$40		; SER_BITS_6
-	.byte	$20		; SER_BITS_7
-	.byte	$00		; SER_BITS_8
-StopTable:
-	.byte	$00		; SER_STOP_1
-	.byte	$80		; SER_STOP_2
-ParityTable:
-	.byte	$00		; SER_PAR_NONE
-	.byte	$20		; SER_PAR_ODD
-	.byte	$60		; SER_PAR_EVEN
-	.byte	$A0		; SER_PAR_MARK
-	.byte	$E0		; SER_PAR_SPACE
-IdOfsTable:
-	.byte	$05		; Pascal 1.0 ID byte
-	.byte	$07		; Pascal 1.0 ID byte
-	.byte	$0B		; Pascal 1.1 generic signature byte
-	.byte	$0C		; Device signature byte
-IdValTable:
-	.byte	$38		; Fixed
-	.byte	$18		; Fixed
-	.byte	$01		; Fixed
-	.byte	$31		; Serial or parallel I/O card type 1
-
-IdTableLen	= * - IdValTable
-
-	.code
-
-;----------------------------------------------------------------------------
-; INSTALL: Is called after the driver is loaded into memory. If possible,
-; check if the hardware is present. Must return an SER_ERR_xx code in a/x.
-;
-; Since we don't have to manage the IRQ vector on the Apple II, this is
-; actually the same as:
-;
-; UNINSTALL: Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-;
-; and:
-;
-; CLOSE: Close the port and disable interrupts. Called without parameters.
-; Must return an SER_ERR_xx code in a/x.
-
-INSTALL:
-UNINSTALL:
-CLOSE:
-	ldx	Index		; Check for open port
-	beq	:+
-
-	; Deactivate DTR and disable 6551 interrupts
-	lda	#%00001010
-	sta	ACIA_CMD,x
-
-	; Done, return an error code
-:	lda	#$C000
-	ora	Slot
-	sta	ptr2+1
-	
-	; Check Pascal 1.1 Firmware Protocol ID bytes
-:	ldy	IdOfsTable,x
-	lda	IdValTable,x
-	cmp	(ptr2),y
-	bne	NoDevice
-	inx
-	cpx	#IdTableLen
-	bcc	:-
-	
-	; Convert slot to I/O register index
-	lda	Slot
-	asl
-	asl
-	asl
-	asl
-	tax
-
-	; Check if the handshake setting is valid
-	ldy	#SER_PARAMS::HANDSHAKE	; Handshake
-	lda	(ptr1),y
-	cmp	#SER_HS_HW		; This is all we support
-	bne	InvParam
-
-	; Initialize buffers
-	ldy	#$00
-	sty	Stopped
-	sty	RecvHead
-	sty	RecvTail
-	sty	SendHead
-	sty	SendTail
-	dey				; Y = 255
-	sty	RecvFreeCnt
-	sty	SendFreeCnt
-
-	; Set the value for the control register, which contains stop bits,
-	; word length and the baud rate.
-	ldy	#SER_PARAMS::BAUDRATE
-	lda	(ptr1),y		; Baudrate index
-	tay
-	lda	BaudTable,y		; Get 6551 value
-	bmi	InvBaud 		; Branch if rate not supported
-	sta	tmp1
-
-	ldy	#SER_PARAMS::DATABITS	; Databits
-	lda	(ptr1),y
-	tay
-	lda	BitTable,y
-	ora	tmp1
-	sta	tmp1
-
-	ldy	#SER_PARAMS::STOPBITS	; Stopbits
-	lda	(ptr1),y
-	tay
-	lda	StopTable,y
-	ora	tmp1
-	ora	#%00010000		; Receiver clock source = baudrate
-	sta	ACIA_CTRL,x
-
-	; Set the value for the command register. We remember the base value
-	; in RtsOff, since we will have to manipulate ACIA_CMD often.
-	ldy	#SER_PARAMS::PARITY	; Parity
-	lda	(ptr1),y
-	tay
-	lda	ParityTable,y
-	ora	#%00000001		; DTR active
-	sta	RtsOff
-	ora	#%00001000		; Enable receive interrupts
-	sta	ACIA_CMD,x
-
-	; Done
-	stx	Index			; Mark port as open
-	lda	#SER_ERR_NO_DEVICE
-	rts
-
-	; Invalid parameter
-InvParam:lda	#SER_ERR_INIT_FAILED
-	rts
-
-	; Baud rate not available
-InvBaud:lda	#SER_ERR_BAUD_UNAVAIL
-	rts
-
-;----------------------------------------------------------------------------
-; GET: Will fetch a character from the receive buffer and store it into the
-; variable pointed to by ptr1. If no data is available, SER_ERR_NO_DATA is
-; returned.
-
-GET:
-	ldx	Index
-	ldy	SendFreeCnt	; Send data if necessary
-	iny			; Y == $FF?
-	beq	:+
-	lda	#$00		; TryHard = false
-	jsr	TryToSend
-
-	; Check for buffer empty
-:	lda	RecvFreeCnt	; (25)
-	cmp	#$FF
-	bne	:+
-	lda	#SER_ERR_NO_DATA
-	rts
-
-	; Check for flow stopped & enough free: release flow control
-:	ldy	Stopped 	; (34)
-	beq	:+
-	cmp	#63
-	bcc	:+
-	lda	#$00
-	sta	Stopped
-	lda	RtsOff
-	ora	#%00001000
-	sta	ACIA_CMD,x
-
-	; Get byte from buffer
-:	ldy	RecvHead	; (41)
-	lda	RecvBuf,y
-	inc	RecvHead
-	inc	RecvFreeCnt
-	ldx	#$00		; (59)
-	sta	(ptr1,x)
-	txa			; Return code = 0
-	rts
-
-;----------------------------------------------------------------------------
-; PUT: Output character in A.
-; Must return an SER_ERR_xx code in a/x.
-
-PUT:
-	ldx	Index
-
-	; Try to send
-	ldy	SendFreeCnt
-	iny			; Y = $FF?
-	beq	:+
-	pha
-	lda	#$00		; TryHard = false
-	jsr	TryToSend
-	pla
-
-	; Put byte into send buffer & send
-:	ldy	SendFreeCnt
-	bne	:+
-	lda	#SER_ERR_OVERFLOW
-	rts
-
-:	ldy	SendTail
-	sta	SendBuf,y
-	inc	SendTail
-	dec	SendFreeCnt
-	lda	#$FF		; TryHard = true
-	jsr	TryToSend
-	lda	#SER_ERR_INV_IOCTL
-	rts
-
-;----------------------------------------------------------------------------
-; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
-; registers are already saved, no parameters are passed, but the carry flag
-; is clear on entry. The routine must return with carry set if the interrupt
-; was handled, otherwise with carry clear.
-
-IRQ:
-	ldx	Index		; Check for open port
-	beq	Done
-	lda	ACIA_STATUS,x	; Check ACIA status for receive interrupt
-	and	#$08
-	beq	Done		; Jump if no ACIA interrupt
-	lda	ACIA_DATA,x	; Get byte from ACIA
-	ldy	RecvFreeCnt	; Check if we have free space left
-	beq	Flow		; Jump if no space in receive buffer
-	ldy	RecvTail	; Load buffer pointer
-	sta	RecvBuf,y	; Store received byte in buffer
-	inc	RecvTail	; Increment buffer pointer
-	dec	RecvFreeCnt	; Decrement free space counter
-	ldy	RecvFreeCnt	; Check for buffer space low
-	cpy	#33
-	bcc	Flow		; Assert flow control if buffer space low
-	rts			; Interrupt handled (carry already set)
-
-	; Assert flow control if buffer space too low
-Flow:	lda	RtsOff
-	sta	ACIA_CMD,x
-	sta	Stopped
-	sec			; Interrupt handled
-Done:	rts
-
-;----------------------------------------------------------------------------
-; Try to send a byte. Internal routine. A = TryHard
-
-TryToSend:
-	sta	tmp1		; Remember tryHard flag
-Again:	lda	SendFreeCnt
-	cmp	#$FF
-	beq	Quit		; Bail out
-
-	; Check for flow stopped
-	lda	Stopped
-	bne	Quit		; Bail out
-
-	; Check that ACIA is ready to send
-	lda	ACIA_STATUS,x
-	and	#$10
-	bne	Send
-	bit	tmp1		; Keep trying if must try hard	
-	bmi	Again
-Quit:	rts
-
-	; Send byte and try again
-Send:	ldy	SendHead
-	lda	SendBuf,y
-	sta	ACIA_DATA,x
-	inc	SendHead
-	inc	SendFreeCnt
-	jmp	Again
diff --git a/libsrc/apple2/apple2-stdjoy.s b/libsrc/apple2/apple2-stdjoy.s
deleted file mode 100644
index 1608f5acc..000000000
--- a/libsrc/apple2/apple2-stdjoy.s
+++ /dev/null
@@ -1,129 +0,0 @@
-;
-; Standard joystick driver for the Apple ][. May be used multiple times
-; when statically linked to the application.
-;
-; Ullrich von Bassewitz, 2003-05-02
-; Oliver Schmidt, 2008-02-25
-; Using the readjoy code from Stefan Haubenthal
-;
-
- 	.include 	"zeropage.inc"
-
-      	.include 	"joy-kernel.inc"
-        .include        "joy-error.inc"
-        .include        "apple2.inc"
-
-; ------------------------------------------------------------------------
-
-; Constants
-
-THRESHOLD =	20	; Deviation from center triggering movement
-
-; ------------------------------------------------------------------------
-
-; ROM entry points
-
-PREAD  	:=  	$FB1E	; Read paddle in X, return AD conv. value in Y
-
-; ------------------------------------------------------------------------
-
-; Header. Includes jump table.
-
-	.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $6A, $6F, $79	; "joy"
-        .byte   JOY_API_VERSION	; Driver API version number
-
-; Button state masks (8 values)
-
-        .byte   $10
-        .byte   $20
-        .byte   $04
-        .byte   $08
-        .byte   $40
-        .byte   $80
-        .byte   $00             ; Future expansion
-        .byte   $00             ; Future expansion
-
-; Jump table
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   COUNT
-        .addr   READJOY
-        .addr   0               ; IRQ not used
-
-; ------------------------------------------------------------------------
-
-	.code
-
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-INSTALL:
-        lda     #JOY_ERR_OK
-	; Fall through
-
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-UNINSTALL:
-        rts
-
-; COUNT: Return the total number of available joysticks in a/x.
-COUNT:
-        lda     #$02		; Number of joysticks we support
-        ldx     #$00
-        rts
-
-; READ: Read a particular joystick passed in A.
-READJOY:
-        bit	$C082		; Switch in ROM
-	and    	#$01            ; Restrict joystick number
-
-	; Read horizontal paddle
-	asl			; Joystick number -> paddle number
-	tax	     		; Set paddle number (0, 2)
-        jsr     PREAD           ; Read paddle value
-        lda	#$00		; 0 0 0 0 0 0 0 0
-        cpy     #127 - THRESHOLD
-        ror			; !LEFT 0 0 0 0 0 0 0
-        cpy     #127 + THRESHOLD
-        ror			; RIGHT !LEFT 0 0 0 0 0 0
-
-	; Read vertical paddle
-        pha
-        inx			; Set paddle number (1, 3)
-        jsr     PREAD           ; Read paddle value
-        pla
-        cpy     #127 - THRESHOLD
-        ror			; !UP RIGHT !LEFT 0 0 0 0 0
-        cpy     #127 + THRESHOLD
-        ror			; DOWN !UP RIGHT !LEFT 0 0 0 0
-
-	; Read primary button
-	tay
-        lda     BUTN0-1,x	; Check button (1, 3)
-        asl
-        tya
-        ror			; FIRE DOWN !UP RIGHT !LEFT 0 0 0
-
-	; Read secondary button
-	tay
-	inx
-	txa
-	and	#$03		; IIgs has fourth button at TAPEIN
-	tax
-        lda     BUTN0-1,x	; Check button (2, 0)
-        asl
-        tya
-	ror			; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
-
-	; Finalize
-        eor     #%00010100      ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
-        ldx     #$00
-	bit	$C080		; Switch in LC bank 2 for R/O
-        rts
diff --git a/libsrc/apple2/apple2-stdmou.s b/libsrc/apple2/apple2-stdmou.s
deleted file mode 100644
index af44a48ff..000000000
--- a/libsrc/apple2/apple2-stdmou.s
+++ /dev/null
@@ -1,434 +0,0 @@
-;
-; Driver for the AppleMouse II Card.
-;
-; Oliver Schmidt, 03.09.2005
-;
-
-	.include	"zeropage.inc"
-	.include	"mouse-kernel.inc"
-	.include	"apple2.inc"
-
-; ------------------------------------------------------------------------
-
-SETMOUSE	= $12	; Sets mouse mode
-SERVEMOUSE	= $13	; Services mouse interrupt
-READMOUSE	= $14	; Reads mouse position
-CLEARMOUSE	= $15	; Clears mouse position to 0 (for delta mode)
-POSMOUSE	= $16	; Sets mouse position to a user-defined pos
-CLAMPMOUSE	= $17	; Sets mouse bounds in a window
-HOMEMOUSE	= $18	; Sets mouse to upper-left corner of clamp win
-INITMOUSE	= $19	; Resets mouse clamps to default values and
-			; sets mouse position to 0,0
-
-pos1_lo 	:= $0478
-pos1_hi 	:= $0578
-pos2_lo 	:= $04F8
-pos2_hi 	:= $05F8
-status		:= $0778
-
-; ------------------------------------------------------------------------
-
-	.segment	"JUMPTABLE"
-
-	; Driver signature
-	.byte	$6D, $6F, $75		; "mou"
-	.byte	MOUSE_API_VERSION	; Mouse driver API version number
-
-	; Jump table.
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	HIDE
-	.addr	SHOW
-	.addr	SETBOX
-	.addr	GETBOX
-	.addr	MOVE
-	.addr	BUTTONS
-	.addr	POS
-	.addr	INFO
-	.addr	IOCTL
-	.addr	IRQ
-
-        ; Mouse driver flags
-        .byte   MOUSE_FLAG_EARLY_IRQ
-
-	; Callback table, set by the kernel before INSTALL is called
-CHIDE:	jmp	$0000			; Hide the cursor
-CSHOW:	jmp	$0000			; Show the cursor
-CMOVEX: jmp	$0000			; Move the cursor to X coord
-CMOVEY: jmp	$0000			; Move the cursor to Y coord
-
-; ------------------------------------------------------------------------
-
-	.bss
-
-box:	.tag	MOUSE_BOX
-info:	.tag	MOUSE_INFO
-slot:	.res	1
-visible:.res	1
-
-; ------------------------------------------------------------------------
-
-	.rodata
-
-offsets:.byte	$05		; Pascal 1.0 ID byte
-	.byte	$07		; Pascal 1.0 ID byte
-	.byte	$0B		; Pascal 1.1 generic signature byte
-	.byte	$0C		; Device signature byte
-
-values: .byte	$38		; Fixed
-	.byte	$18		; Fixed
-	.byte	$01		; Fixed
-	.byte	$20		; X-Y pointing device type 0
-
-size	= * - values
-
-inibox:	.word	  0		; MinX
-	.word	  0		; MinY
-	.word	279		; MaxX
-	.word	191		; MaxY
-
-; ------------------------------------------------------------------------
-
-	.data
-
-firmware:
-	; Lookup and patch firmware address lobyte
-lookup: ldy	$FF00,x 	; Patched at runtime
-	sty	jump+1		; Modify code below
-
-	; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
-	; "Enter all mouse routines (...) with the X register set to $Cn
-	;  and Y register set to $n0, where n = the slot number."
-xparam: ldx	#$FF		; Patched at runtime
-yparam: ldy	#$FF		; Patched at runtime
-
-jump:	jmp	$FFFF		; Patched at runtime
-
-; ------------------------------------------------------------------------
-
-	.code
-
-; INSTALL: Is called after the driver is loaded into memory. If possible,
-; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X.
-INSTALL:
-	lda	#<$C000
-	sta	ptr1
-	lda	#>$C000
-	sta	ptr1+1
-
-	; Search for AppleMouse II firmware in slots 1 - 7
-next:	inc	ptr1+1
-	lda	ptr1+1
-	cmp	#>$C800
-	bcc	:+
-
-	; Mouse firmware not found
-	lda	#MOUSE_ERR_NO_DEVICE
-	rts
-
-	; Check Pascal 1.1 Firmware Protocol ID bytes
-:	ldx	#size - 1
-:	ldy	offsets,x
-	lda	values,x
-	cmp	(ptr1),y
-	bne	next
-	dex
-	bpl	:-
-
-	; Get and patch firmware address hibyte
-	lda	ptr1+1
-	sta	lookup+2
-	sta	xparam+1
-	sta	jump+2
-
-	; Disable interrupts now because setting the slot number makes 
-	; the IRQ handler (maybe called due to some non-mouse IRQ) try
-	; calling the firmware which isn't correctly set up yet
-	sei
-
-	; Convert to and save slot number
-	and	#$0F
-	sta	slot
-
-	; Convert to and patch I/O register index
-	asl
-	asl
-	asl
-	asl
-	sta	yparam+1
-	
-	; The AppleMouse II Card needs the ROM switched in
-	; to be able to detect an Apple //e and use RDVBL
-	bit	$C082
-
-	; Reset mouse hardware
-	ldx	#INITMOUSE
-	jsr	firmware
-	
-	; Switch in LC bank 2 for R/O
-	bit	$C080
-
-	; Turn mouse on
-	lda	#%00000001
-	ldx	#SETMOUSE
-	jsr	firmware
-
-	; Set initial mouse clamps
-	lda	#inibox
-	jsr	SETBOX
-
-	; Set initial mouse position
-	ldx	slot
-	lda	#<(279 / 2)
-	sta	pos1_lo,x
-	lda	#>(279 / 2)
-	sta	pos1_hi,x
-	lda	#<(191 / 2)
-	sta	pos2_lo,x
-	lda	#>(191 / 2)
-	sta	pos2_hi,x
-	ldx	#POSMOUSE
-	jsr	firmware
-
-	; Update cursor
-	jsr	update
-
-	; Turn VBL interrupt on
-	lda	#%00001001
-	ldx	#SETMOUSE
-common:	jsr	firmware
-
-	; Enable interrupts and return success
-	cli
-	lda	#MOUSE_ERR_OK
-	rts
-
-; UNINSTALL: Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-UNINSTALL:
-	; Hide cursor
-	sei
-	jsr	CHIDE
-
-	; Turn mouse off
-	lda	#%00000000
-	ldx	#SETMOUSE
-	bne	common		; Branch always
-
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in A/X.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-SETBOX:
-	sta	ptr1
-	stx	ptr1+1
-        
-	; Set x clamps
-	ldx	#$00
-	ldy	#MOUSE_BOX::MINX
-	jsr	:+
-	
-	; Set y clamps
-	ldx	#$01
-	ldy	#MOUSE_BOX::MINY
-
-	; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
-	; "Disable interrupts before placing position information in the
-	;  screen holes."
-:	sei
-
-	; Set low clamp
-	lda	(ptr1),y
-	sta	box,y
-	sta	pos1_lo
-	iny
-	lda	(ptr1),y
-	sta	box,y 	
-	sta	pos1_hi
-
-	; Skip one word
-	iny
-	iny
-
-	; Set high clamp
-	iny
-	lda	(ptr1),y
-	sta	box,y 	
-	sta	pos2_lo
-	iny
-	lda	(ptr1),y
-	sta	box,y 	
-	sta	pos2_hi
-
-	txa
-	ldx	#CLAMPMOUSE
-	bne	common		; Branch always
-
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in A/X.
-GETBOX:
-	sta	ptr1
-	stx	ptr1+1
-
-	ldy	#.sizeof(MOUSE_BOX)-1
-:	lda	box,y
-	sta	(ptr1),y
-	dey
-	bpl	:-
-	rts
-
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: x on the stack and y in A/X. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-MOVE:
-	ldy	slot
-	sei
-
-	; Set y
-	sta	pos2_lo,y
-	txa
-	sta	pos2_hi,y
-
-	tya
-	tax
-	ldy	#$00		; Start at top of stack
-
-	; Set x
-	lda	(sp),y
-	iny
-	sta	pos1_lo,x
-	lda	(sp),y
-	sta	pos1_hi,x
-
-	; Update cursor
-	jsr	update
-
-	ldx	#POSMOUSE
-	bne	common		; Branch always
-
-; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a
-; counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required	besides	hiding the mouse cursor.
-; No return code required.
-HIDE:
-	dec	visible
-	sei
-	jsr	CHIDE
-	cli
-	rts
-
-; SHOW:	Is called to show the mouse cursor. The mouse kernel manages a
-; counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required	besides	enabling the mouse cursor.
-; No return code required.
-SHOW:
-	inc	visible
-	rts
-
-; BUTTONS: Return the button mask in A/X.
-BUTTONS:
-	lda	info + MOUSE_INFO::BUTTONS
-	ldx	#$00
-	rts
-
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-POS:
-	ldy	#.sizeof(MOUSE_POS)-1
-	bne	copy		; Branch always
-
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-INFO:
-	ldy	#.sizeof(MOUSE_INFO)-1
-copy:	sei
-:	lda	info,y
-	sta	(ptr1),y
-	dey
-	bpl	:-
-	cli
-	rts
-
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an MOUSE_ERR_xx code in A/X.
-IOCTL:
-	lda     #MOUSE_ERR_INV_IOCTL
-	rts
-
-; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
-; registers are already saved, no parameters are passed, but the carry flag
-; is clear on entry. The routine must return with carry set if the interrupt
-; was handled, otherwise with carry clear.
-IRQ:
-	; Check for installed mouse
-	lda	slot
-	beq	done
-
-	; Check for mouse interrupt
-	ldx	#SERVEMOUSE
-	jsr	firmware
-	bcc	:+
-	clc			; Interrupt not handled
-done:	rts
-
-:	ldx	#READMOUSE
-	jsr	firmware
-
-	; Get status
-	ldy	slot
-	lda	status,y
-	tax			; Save status
-
-	; Extract button down values
-	asl			;  C = Button 0 is currently down
-	and	#%00100000	; !Z = Button 1 is currently down
-
-	; Set button mask
-	beq	:+
-	lda	#MOUSE_BTN_RIGHT
-:	bcc	:+
-	ora	#MOUSE_BTN_LEFT
-:	sta	info + MOUSE_INFO::BUTTONS
-
-	; Check for mouse movement
-	txa			; Restore status
-	and	#%00100000	; X or Y changed since last READMOUSE
-	beq	:+
-
-	; Remove the cursor at the old position
-update:	jsr	CHIDE
-
-	; Get and set the new X position
-	ldy	slot
-	lda	pos1_lo,y
-	ldx	pos1_hi,y
-	sta	info + MOUSE_POS::XCOORD
-	stx	info + MOUSE_POS::XCOORD+1
-	jsr	CMOVEX
-
-	; Get and set the new Y position
-	ldy	slot
-	lda	pos2_lo,y
-	ldx	pos2_hi,y
-	sta	info + MOUSE_POS::YCOORD
-	stx	info + MOUSE_POS::YCOORD+1
-	jsr	CMOVEY
-
-	; Check for visibility
-:	lda	visible
-	beq	:+
-
-	; Draw the cursor at the new position
-	jsr	CSHOW
-:	sec			; Interrupt handled
-	rts
diff --git a/libsrc/apple2/emd/a2.auxmem.s b/libsrc/apple2/emd/a2.auxmem.s
new file mode 100644
index 000000000..7a72cfc85
--- /dev/null
+++ b/libsrc/apple2/emd/a2.auxmem.s
@@ -0,0 +1,235 @@
+;
+; Extended memory driver for the Apple II auxiliary memory
+;
+; Stefan Haubenthal, 2003-12-12
+; Ullrich von Bassewitz, 2002-12-02
+;
+
+	.include	"zeropage.inc"
+
+	.include	"em-kernel.inc"
+	.include	"em-error.inc"
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment	"JUMPTABLE"
+
+; Driver signature
+
+	.byte	$65, $6d, $64		; "emd"
+	.byte	EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+	.word	INSTALL
+	.word	DEINSTALL
+	.word	PAGECOUNT
+	.word	MAP
+	.word	USE
+	.word	COMMIT
+	.word	COPYFROM
+	.word	COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+BASE	= $0200
+AUXCARD	= $C30C				; Card signature
+AUXMOVE	= $C311				; Auxiliary move routine
+PAGES	= ($C000 - BASE) / 256
+
+; ------------------------------------------------------------------------
+; Data.
+
+.data
+curpage:	.byte	$FF		; Current page number (invalid)
+
+.bss
+window:		.res	256		; Memory "window"
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+	ldx	#0
+	lda	AUXCARD
+	and	#$f0
+	cmp	#$80
+	bne	@L1
+	lda	#EM_ERR_OK
+	rts
+@L1:	lda	#EM_ERR_NO_DEVICE
+;	rts
+
+; ------------------------------------------------------------------------
+; DEINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+DEINSTALL:
+	rts
+
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+	lda	#PAGES
+	rts
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:	sta	curpage			; Remember the new page
+
+	clc
+	adc	#>BASE
+	sta	ptr1+1
+	ldy	#$00
+	sty	ptr1
+
+	lda	#window
+	sta	ptr2+1
+
+; Transfer one page
+
+	clc				; Direction flag
+	jsr	transfer		; Transfer one page
+
+; Return the memory window
+
+	lda	#window		; Return the window address
+
+; Done
+
+done:	rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:	sta	curpage			; Remember the page
+	lda	#window		; Return the window
+	rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: lda	curpage			; Get the current page
+	cmp	#$FF
+	beq	done			; Jump if no page mapped
+
+	clc
+	adc	#>BASE
+	sta	ptr2+1
+	ldy	#$00
+	sty	ptr2
+
+	lda	#window
+	sta	ptr1+1
+	lda	#<$FF
+	sta	ptr4
+	lda	#>$FF
+	sta	ptr4+1
+	sec				; Direction flag
+
+; Transfer one page/all bytes
+
+transfer:
+	php
+	clc
+	lda	ptr1
+	sta	$3C
+	adc	ptr4
+	sta	$3E
+	lda	ptr1+1
+	sta	$3D
+	adc	ptr4+1
+	sta	$3F
+	lda	ptr2
+	sta	$42
+	lda	ptr2+1
+	sta	$43
+	plp
+	jmp	AUXMOVE
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYFROM:
+	sta	ptr3
+	stx	ptr3+1			; Save the passed em_copy pointer
+
+	ldy	#EM_COPY::OFFS
+	lda	(ptr3),y
+	sta	ptr1
+	ldy	#EM_COPY::PAGE
+	lda	(ptr3),y
+	clc
+	adc	#>BASE
+	sta	ptr1+1			; From
+
+	ldy	#EM_COPY::BUF
+	lda	(ptr3),y
+	sta	ptr2
+	iny
+	lda	(ptr3),y
+	sta	ptr2+1			; To
+	clc				; Direction flag
+
+common: ldy	#EM_COPY::COUNT
+	lda	(ptr3),y		; Get bytes in last page
+	sta	ptr4
+	iny
+	lda	(ptr3),y		; Get number of pages
+	sta	ptr4+1
+
+	jmp	transfer
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO: sta	ptr3
+	stx	ptr3+1			; Save the passed em_copy pointer
+
+	ldy	#EM_COPY::OFFS
+	lda	(ptr3),y
+	sta	ptr2
+	ldy	#EM_COPY::PAGE
+	lda	(ptr3),y
+	clc
+	adc	#>BASE
+	sta	ptr2+1			; To
+
+	ldy	#EM_COPY::BUF
+	lda	(ptr3),y
+	sta	ptr1
+	iny
+	lda	(ptr3),y
+	sta	ptr1+1			; From
+
+	sec				; Direction flag
+	jmp	common
diff --git a/libsrc/apple2/joy/a2.stdjoy.s b/libsrc/apple2/joy/a2.stdjoy.s
new file mode 100644
index 000000000..1608f5acc
--- /dev/null
+++ b/libsrc/apple2/joy/a2.stdjoy.s
@@ -0,0 +1,129 @@
+;
+; Standard joystick driver for the Apple ][. May be used multiple times
+; when statically linked to the application.
+;
+; Ullrich von Bassewitz, 2003-05-02
+; Oliver Schmidt, 2008-02-25
+; Using the readjoy code from Stefan Haubenthal
+;
+
+ 	.include 	"zeropage.inc"
+
+      	.include 	"joy-kernel.inc"
+        .include        "joy-error.inc"
+        .include        "apple2.inc"
+
+; ------------------------------------------------------------------------
+
+; Constants
+
+THRESHOLD =	20	; Deviation from center triggering movement
+
+; ------------------------------------------------------------------------
+
+; ROM entry points
+
+PREAD  	:=  	$FB1E	; Read paddle in X, return AD conv. value in Y
+
+; ------------------------------------------------------------------------
+
+; Header. Includes jump table.
+
+	.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $6A, $6F, $79	; "joy"
+        .byte   JOY_API_VERSION	; Driver API version number
+
+; Button state masks (8 values)
+
+        .byte   $10
+        .byte   $20
+        .byte   $04
+        .byte   $08
+        .byte   $40
+        .byte   $80
+        .byte   $00             ; Future expansion
+        .byte   $00             ; Future expansion
+
+; Jump table
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   COUNT
+        .addr   READJOY
+        .addr   0               ; IRQ not used
+
+; ------------------------------------------------------------------------
+
+	.code
+
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an JOY_ERR_xx code in a/x.
+INSTALL:
+        lda     #JOY_ERR_OK
+	; Fall through
+
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+UNINSTALL:
+        rts
+
+; COUNT: Return the total number of available joysticks in a/x.
+COUNT:
+        lda     #$02		; Number of joysticks we support
+        ldx     #$00
+        rts
+
+; READ: Read a particular joystick passed in A.
+READJOY:
+        bit	$C082		; Switch in ROM
+	and    	#$01            ; Restrict joystick number
+
+	; Read horizontal paddle
+	asl			; Joystick number -> paddle number
+	tax	     		; Set paddle number (0, 2)
+        jsr     PREAD           ; Read paddle value
+        lda	#$00		; 0 0 0 0 0 0 0 0
+        cpy     #127 - THRESHOLD
+        ror			; !LEFT 0 0 0 0 0 0 0
+        cpy     #127 + THRESHOLD
+        ror			; RIGHT !LEFT 0 0 0 0 0 0
+
+	; Read vertical paddle
+        pha
+        inx			; Set paddle number (1, 3)
+        jsr     PREAD           ; Read paddle value
+        pla
+        cpy     #127 - THRESHOLD
+        ror			; !UP RIGHT !LEFT 0 0 0 0 0
+        cpy     #127 + THRESHOLD
+        ror			; DOWN !UP RIGHT !LEFT 0 0 0 0
+
+	; Read primary button
+	tay
+        lda     BUTN0-1,x	; Check button (1, 3)
+        asl
+        tya
+        ror			; FIRE DOWN !UP RIGHT !LEFT 0 0 0
+
+	; Read secondary button
+	tay
+	inx
+	txa
+	and	#$03		; IIgs has fourth button at TAPEIN
+	tax
+        lda     BUTN0-1,x	; Check button (2, 0)
+        asl
+        tya
+	ror			; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
+
+	; Finalize
+        eor     #%00010100      ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
+        ldx     #$00
+	bit	$C080		; Switch in LC bank 2 for R/O
+        rts
diff --git a/libsrc/apple2/mou/a2.stdmou.s b/libsrc/apple2/mou/a2.stdmou.s
new file mode 100644
index 000000000..af44a48ff
--- /dev/null
+++ b/libsrc/apple2/mou/a2.stdmou.s
@@ -0,0 +1,434 @@
+;
+; Driver for the AppleMouse II Card.
+;
+; Oliver Schmidt, 03.09.2005
+;
+
+	.include	"zeropage.inc"
+	.include	"mouse-kernel.inc"
+	.include	"apple2.inc"
+
+; ------------------------------------------------------------------------
+
+SETMOUSE	= $12	; Sets mouse mode
+SERVEMOUSE	= $13	; Services mouse interrupt
+READMOUSE	= $14	; Reads mouse position
+CLEARMOUSE	= $15	; Clears mouse position to 0 (for delta mode)
+POSMOUSE	= $16	; Sets mouse position to a user-defined pos
+CLAMPMOUSE	= $17	; Sets mouse bounds in a window
+HOMEMOUSE	= $18	; Sets mouse to upper-left corner of clamp win
+INITMOUSE	= $19	; Resets mouse clamps to default values and
+			; sets mouse position to 0,0
+
+pos1_lo 	:= $0478
+pos1_hi 	:= $0578
+pos2_lo 	:= $04F8
+pos2_hi 	:= $05F8
+status		:= $0778
+
+; ------------------------------------------------------------------------
+
+	.segment	"JUMPTABLE"
+
+	; Driver signature
+	.byte	$6D, $6F, $75		; "mou"
+	.byte	MOUSE_API_VERSION	; Mouse driver API version number
+
+	; Jump table.
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	HIDE
+	.addr	SHOW
+	.addr	SETBOX
+	.addr	GETBOX
+	.addr	MOVE
+	.addr	BUTTONS
+	.addr	POS
+	.addr	INFO
+	.addr	IOCTL
+	.addr	IRQ
+
+        ; Mouse driver flags
+        .byte   MOUSE_FLAG_EARLY_IRQ
+
+	; Callback table, set by the kernel before INSTALL is called
+CHIDE:	jmp	$0000			; Hide the cursor
+CSHOW:	jmp	$0000			; Show the cursor
+CMOVEX: jmp	$0000			; Move the cursor to X coord
+CMOVEY: jmp	$0000			; Move the cursor to Y coord
+
+; ------------------------------------------------------------------------
+
+	.bss
+
+box:	.tag	MOUSE_BOX
+info:	.tag	MOUSE_INFO
+slot:	.res	1
+visible:.res	1
+
+; ------------------------------------------------------------------------
+
+	.rodata
+
+offsets:.byte	$05		; Pascal 1.0 ID byte
+	.byte	$07		; Pascal 1.0 ID byte
+	.byte	$0B		; Pascal 1.1 generic signature byte
+	.byte	$0C		; Device signature byte
+
+values: .byte	$38		; Fixed
+	.byte	$18		; Fixed
+	.byte	$01		; Fixed
+	.byte	$20		; X-Y pointing device type 0
+
+size	= * - values
+
+inibox:	.word	  0		; MinX
+	.word	  0		; MinY
+	.word	279		; MaxX
+	.word	191		; MaxY
+
+; ------------------------------------------------------------------------
+
+	.data
+
+firmware:
+	; Lookup and patch firmware address lobyte
+lookup: ldy	$FF00,x 	; Patched at runtime
+	sty	jump+1		; Modify code below
+
+	; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
+	; "Enter all mouse routines (...) with the X register set to $Cn
+	;  and Y register set to $n0, where n = the slot number."
+xparam: ldx	#$FF		; Patched at runtime
+yparam: ldy	#$FF		; Patched at runtime
+
+jump:	jmp	$FFFF		; Patched at runtime
+
+; ------------------------------------------------------------------------
+
+	.code
+
+; INSTALL: Is called after the driver is loaded into memory. If possible,
+; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X.
+INSTALL:
+	lda	#<$C000
+	sta	ptr1
+	lda	#>$C000
+	sta	ptr1+1
+
+	; Search for AppleMouse II firmware in slots 1 - 7
+next:	inc	ptr1+1
+	lda	ptr1+1
+	cmp	#>$C800
+	bcc	:+
+
+	; Mouse firmware not found
+	lda	#MOUSE_ERR_NO_DEVICE
+	rts
+
+	; Check Pascal 1.1 Firmware Protocol ID bytes
+:	ldx	#size - 1
+:	ldy	offsets,x
+	lda	values,x
+	cmp	(ptr1),y
+	bne	next
+	dex
+	bpl	:-
+
+	; Get and patch firmware address hibyte
+	lda	ptr1+1
+	sta	lookup+2
+	sta	xparam+1
+	sta	jump+2
+
+	; Disable interrupts now because setting the slot number makes 
+	; the IRQ handler (maybe called due to some non-mouse IRQ) try
+	; calling the firmware which isn't correctly set up yet
+	sei
+
+	; Convert to and save slot number
+	and	#$0F
+	sta	slot
+
+	; Convert to and patch I/O register index
+	asl
+	asl
+	asl
+	asl
+	sta	yparam+1
+	
+	; The AppleMouse II Card needs the ROM switched in
+	; to be able to detect an Apple //e and use RDVBL
+	bit	$C082
+
+	; Reset mouse hardware
+	ldx	#INITMOUSE
+	jsr	firmware
+	
+	; Switch in LC bank 2 for R/O
+	bit	$C080
+
+	; Turn mouse on
+	lda	#%00000001
+	ldx	#SETMOUSE
+	jsr	firmware
+
+	; Set initial mouse clamps
+	lda	#inibox
+	jsr	SETBOX
+
+	; Set initial mouse position
+	ldx	slot
+	lda	#<(279 / 2)
+	sta	pos1_lo,x
+	lda	#>(279 / 2)
+	sta	pos1_hi,x
+	lda	#<(191 / 2)
+	sta	pos2_lo,x
+	lda	#>(191 / 2)
+	sta	pos2_hi,x
+	ldx	#POSMOUSE
+	jsr	firmware
+
+	; Update cursor
+	jsr	update
+
+	; Turn VBL interrupt on
+	lda	#%00001001
+	ldx	#SETMOUSE
+common:	jsr	firmware
+
+	; Enable interrupts and return success
+	cli
+	lda	#MOUSE_ERR_OK
+	rts
+
+; UNINSTALL: Is called before the driver is removed from memory.
+; No return code required (the driver is removed from memory on return).
+UNINSTALL:
+	; Hide cursor
+	sei
+	jsr	CHIDE
+
+	; Turn mouse off
+	lda	#%00000000
+	ldx	#SETMOUSE
+	bne	common		; Branch always
+
+; SETBOX: Set the mouse bounding box. The parameters are passed as they come
+; from the C program, that is, a pointer to a mouse_box struct in A/X.
+; No checks are done if the mouse is currently inside the box, this is the job
+; of the caller. It is not necessary to validate the parameters, trust the
+; caller and save some code here. No return code required.
+SETBOX:
+	sta	ptr1
+	stx	ptr1+1
+        
+	; Set x clamps
+	ldx	#$00
+	ldy	#MOUSE_BOX::MINX
+	jsr	:+
+	
+	; Set y clamps
+	ldx	#$01
+	ldy	#MOUSE_BOX::MINY
+
+	; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse:
+	; "Disable interrupts before placing position information in the
+	;  screen holes."
+:	sei
+
+	; Set low clamp
+	lda	(ptr1),y
+	sta	box,y
+	sta	pos1_lo
+	iny
+	lda	(ptr1),y
+	sta	box,y 	
+	sta	pos1_hi
+
+	; Skip one word
+	iny
+	iny
+
+	; Set high clamp
+	iny
+	lda	(ptr1),y
+	sta	box,y 	
+	sta	pos2_lo
+	iny
+	lda	(ptr1),y
+	sta	box,y 	
+	sta	pos2_hi
+
+	txa
+	ldx	#CLAMPMOUSE
+	bne	common		; Branch always
+
+; GETBOX: Return the mouse bounding box. The parameters are passed as they
+; come from the C program, that is, a pointer to a mouse_box struct in A/X.
+GETBOX:
+	sta	ptr1
+	stx	ptr1+1
+
+	ldy	#.sizeof(MOUSE_BOX)-1
+:	lda	box,y
+	sta	(ptr1),y
+	dey
+	bpl	:-
+	rts
+
+; MOVE: Move the mouse to a new position. The position is passed as it comes
+; from the C program, that is: x on the stack and y in A/X. The C wrapper will
+; remove the parameter from the stack on return.
+; No checks are done if the new position is valid (within the bounding box or
+; the screen). No return code required.
+MOVE:
+	ldy	slot
+	sei
+
+	; Set y
+	sta	pos2_lo,y
+	txa
+	sta	pos2_hi,y
+
+	tya
+	tax
+	ldy	#$00		; Start at top of stack
+
+	; Set x
+	lda	(sp),y
+	iny
+	sta	pos1_lo,x
+	lda	(sp),y
+	sta	pos1_hi,x
+
+	; Update cursor
+	jsr	update
+
+	ldx	#POSMOUSE
+	bne	common		; Branch always
+
+; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a
+; counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently visible and should get hidden. For most drivers,
+; no special action is required	besides	hiding the mouse cursor.
+; No return code required.
+HIDE:
+	dec	visible
+	sei
+	jsr	CHIDE
+	cli
+	rts
+
+; SHOW:	Is called to show the mouse cursor. The mouse kernel manages a
+; counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently hidden and should become visible. For most drivers,
+; no special action is required	besides	enabling the mouse cursor.
+; No return code required.
+SHOW:
+	inc	visible
+	rts
+
+; BUTTONS: Return the button mask in A/X.
+BUTTONS:
+	lda	info + MOUSE_INFO::BUTTONS
+	ldx	#$00
+	rts
+
+; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
+; No return code required.
+POS:
+	ldy	#.sizeof(MOUSE_POS)-1
+	bne	copy		; Branch always
+
+; INFO: Returns mouse position and current button mask in the MOUSE_INFO
+; struct pointed to by ptr1. No return code required.
+INFO:
+	ldy	#.sizeof(MOUSE_INFO)-1
+copy:	sei
+:	lda	info,y
+	sta	(ptr1),y
+	dey
+	bpl	:-
+	cli
+	rts
+
+; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
+; specific data in ptr1, and the ioctl code in A.
+; Must return an MOUSE_ERR_xx code in A/X.
+IOCTL:
+	lda     #MOUSE_ERR_INV_IOCTL
+	rts
+
+; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
+; registers are already saved, no parameters are passed, but the carry flag
+; is clear on entry. The routine must return with carry set if the interrupt
+; was handled, otherwise with carry clear.
+IRQ:
+	; Check for installed mouse
+	lda	slot
+	beq	done
+
+	; Check for mouse interrupt
+	ldx	#SERVEMOUSE
+	jsr	firmware
+	bcc	:+
+	clc			; Interrupt not handled
+done:	rts
+
+:	ldx	#READMOUSE
+	jsr	firmware
+
+	; Get status
+	ldy	slot
+	lda	status,y
+	tax			; Save status
+
+	; Extract button down values
+	asl			;  C = Button 0 is currently down
+	and	#%00100000	; !Z = Button 1 is currently down
+
+	; Set button mask
+	beq	:+
+	lda	#MOUSE_BTN_RIGHT
+:	bcc	:+
+	ora	#MOUSE_BTN_LEFT
+:	sta	info + MOUSE_INFO::BUTTONS
+
+	; Check for mouse movement
+	txa			; Restore status
+	and	#%00100000	; X or Y changed since last READMOUSE
+	beq	:+
+
+	; Remove the cursor at the old position
+update:	jsr	CHIDE
+
+	; Get and set the new X position
+	ldy	slot
+	lda	pos1_lo,y
+	ldx	pos1_hi,y
+	sta	info + MOUSE_POS::XCOORD
+	stx	info + MOUSE_POS::XCOORD+1
+	jsr	CMOVEX
+
+	; Get and set the new Y position
+	ldy	slot
+	lda	pos2_lo,y
+	ldx	pos2_hi,y
+	sta	info + MOUSE_POS::YCOORD
+	stx	info + MOUSE_POS::YCOORD+1
+	jsr	CMOVEY
+
+	; Check for visibility
+:	lda	visible
+	beq	:+
+
+	; Draw the cursor at the new position
+	jsr	CSHOW
+:	sec			; Interrupt handled
+	rts
diff --git a/libsrc/apple2/ser/a2.ssc.s b/libsrc/apple2/ser/a2.ssc.s
new file mode 100644
index 000000000..cb9ff2ec1
--- /dev/null
+++ b/libsrc/apple2/ser/a2.ssc.s
@@ -0,0 +1,435 @@
+;
+; Serial driver for the Apple II Super Serial Card.
+;
+; Oliver Schmidt, 21.04.2005
+;
+; The driver is based on the cc65 rs232 module, which in turn is based on
+; Craig Bruce device driver for the Switftlink/Turbo-232.
+;
+; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
+;
+; This software is Public Domain.  It is in Buddy assembler format.
+;
+; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
+; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
+; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
+; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
+;
+; The code assumes that the kernal + I/O are in context.  On the C128, call
+; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
+; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
+; interrupt handling assumes that the 65816 is in 6502-emulation mode.
+;
+
+	.include	"zeropage.inc"
+	.include	"ser-kernel.inc"
+	.include	"ser-error.inc"
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+	.segment	"JUMPTABLE"
+
+	; Driver signature
+	.byte	$73, $65, $72		; "ser"
+	.byte	SER_API_VERSION 	; Serial API version number
+
+	; Jump table.
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	OPEN
+	.addr	CLOSE
+	.addr	GET
+	.addr	PUT
+	.addr	STATUS
+	.addr	IOCTL
+	.addr	IRQ
+
+;----------------------------------------------------------------------------
+; I/O definitions
+
+ACIA		= $C088
+ACIA_DATA	= ACIA+0	; Data register
+ACIA_STATUS	= ACIA+1	; Status register
+ACIA_CMD	= ACIA+2	; Command register
+ACIA_CTRL	= ACIA+3	; Control register
+
+;----------------------------------------------------------------------------
+; Global variables
+
+	.bss
+
+RecvHead:	.res	1	; Head of receive buffer
+RecvTail:	.res	1	; Tail of receive buffer
+RecvFreeCnt:	.res	1	; Number of bytes in receive buffer
+SendHead:	.res	1	; Head of send buffer
+SendTail:	.res	1	; Tail of send buffer
+SendFreeCnt:	.res	1	; Number of bytes in send buffer
+
+Stopped:	.res	1	; Flow-stopped flag
+RtsOff: 	.res	1	;
+
+RecvBuf:	.res	256	; Receive buffers: 256 bytes
+SendBuf:	.res	256	; Send buffers: 256 bytes
+
+Index:		.res	1	; I/O register index
+
+	.data
+
+Slot:	.byte	$02		; Default to SSC in slot 2
+
+	.rodata
+
+	; Tables used to translate RS232 params into register values
+BaudTable:			; bit7 = 1 means setting is invalid
+	.byte	$FF		; SER_BAUD_45_5
+	.byte	$01		; SER_BAUD_50
+	.byte	$02		; SER_BAUD_75
+	.byte	$03		; SER_BAUD_110
+	.byte	$04		; SER_BAUD_134_5
+	.byte	$05		; SER_BAUD_150
+	.byte	$06		; SER_BAUD_300
+	.byte	$07		; SER_BAUD_600
+	.byte	$08		; SER_BAUD_1200
+	.byte	$09		; SER_BAUD_1800
+	.byte	$0A		; SER_BAUD_2400
+	.byte	$0B		; SER_BAUD_3600
+	.byte	$0C		; SER_BAUD_4800
+	.byte	$0D		; SER_BAUD_7200
+	.byte	$0E		; SER_BAUD_9600
+	.byte	$0F		; SER_BAUD_19200
+	.byte	$FF		; SER_BAUD_38400
+	.byte	$FF		; SER_BAUD_57600
+	.byte	$FF		; SER_BAUD_115200
+	.byte	$FF		; SER_BAUD_230400
+BitTable:
+	.byte	$60		; SER_BITS_5
+	.byte	$40		; SER_BITS_6
+	.byte	$20		; SER_BITS_7
+	.byte	$00		; SER_BITS_8
+StopTable:
+	.byte	$00		; SER_STOP_1
+	.byte	$80		; SER_STOP_2
+ParityTable:
+	.byte	$00		; SER_PAR_NONE
+	.byte	$20		; SER_PAR_ODD
+	.byte	$60		; SER_PAR_EVEN
+	.byte	$A0		; SER_PAR_MARK
+	.byte	$E0		; SER_PAR_SPACE
+IdOfsTable:
+	.byte	$05		; Pascal 1.0 ID byte
+	.byte	$07		; Pascal 1.0 ID byte
+	.byte	$0B		; Pascal 1.1 generic signature byte
+	.byte	$0C		; Device signature byte
+IdValTable:
+	.byte	$38		; Fixed
+	.byte	$18		; Fixed
+	.byte	$01		; Fixed
+	.byte	$31		; Serial or parallel I/O card type 1
+
+IdTableLen	= * - IdValTable
+
+	.code
+
+;----------------------------------------------------------------------------
+; INSTALL: Is called after the driver is loaded into memory. If possible,
+; check if the hardware is present. Must return an SER_ERR_xx code in a/x.
+;
+; Since we don't have to manage the IRQ vector on the Apple II, this is
+; actually the same as:
+;
+; UNINSTALL: Is called before the driver is removed from memory.
+; No return code required (the driver is removed from memory on return).
+;
+; and:
+;
+; CLOSE: Close the port and disable interrupts. Called without parameters.
+; Must return an SER_ERR_xx code in a/x.
+
+INSTALL:
+UNINSTALL:
+CLOSE:
+	ldx	Index		; Check for open port
+	beq	:+
+
+	; Deactivate DTR and disable 6551 interrupts
+	lda	#%00001010
+	sta	ACIA_CMD,x
+
+	; Done, return an error code
+:	lda	#$C000
+	ora	Slot
+	sta	ptr2+1
+	
+	; Check Pascal 1.1 Firmware Protocol ID bytes
+:	ldy	IdOfsTable,x
+	lda	IdValTable,x
+	cmp	(ptr2),y
+	bne	NoDevice
+	inx
+	cpx	#IdTableLen
+	bcc	:-
+	
+	; Convert slot to I/O register index
+	lda	Slot
+	asl
+	asl
+	asl
+	asl
+	tax
+
+	; Check if the handshake setting is valid
+	ldy	#SER_PARAMS::HANDSHAKE	; Handshake
+	lda	(ptr1),y
+	cmp	#SER_HS_HW		; This is all we support
+	bne	InvParam
+
+	; Initialize buffers
+	ldy	#$00
+	sty	Stopped
+	sty	RecvHead
+	sty	RecvTail
+	sty	SendHead
+	sty	SendTail
+	dey				; Y = 255
+	sty	RecvFreeCnt
+	sty	SendFreeCnt
+
+	; Set the value for the control register, which contains stop bits,
+	; word length and the baud rate.
+	ldy	#SER_PARAMS::BAUDRATE
+	lda	(ptr1),y		; Baudrate index
+	tay
+	lda	BaudTable,y		; Get 6551 value
+	bmi	InvBaud 		; Branch if rate not supported
+	sta	tmp1
+
+	ldy	#SER_PARAMS::DATABITS	; Databits
+	lda	(ptr1),y
+	tay
+	lda	BitTable,y
+	ora	tmp1
+	sta	tmp1
+
+	ldy	#SER_PARAMS::STOPBITS	; Stopbits
+	lda	(ptr1),y
+	tay
+	lda	StopTable,y
+	ora	tmp1
+	ora	#%00010000		; Receiver clock source = baudrate
+	sta	ACIA_CTRL,x
+
+	; Set the value for the command register. We remember the base value
+	; in RtsOff, since we will have to manipulate ACIA_CMD often.
+	ldy	#SER_PARAMS::PARITY	; Parity
+	lda	(ptr1),y
+	tay
+	lda	ParityTable,y
+	ora	#%00000001		; DTR active
+	sta	RtsOff
+	ora	#%00001000		; Enable receive interrupts
+	sta	ACIA_CMD,x
+
+	; Done
+	stx	Index			; Mark port as open
+	lda	#SER_ERR_NO_DEVICE
+	rts
+
+	; Invalid parameter
+InvParam:lda	#SER_ERR_INIT_FAILED
+	rts
+
+	; Baud rate not available
+InvBaud:lda	#SER_ERR_BAUD_UNAVAIL
+	rts
+
+;----------------------------------------------------------------------------
+; GET: Will fetch a character from the receive buffer and store it into the
+; variable pointed to by ptr1. If no data is available, SER_ERR_NO_DATA is
+; returned.
+
+GET:
+	ldx	Index
+	ldy	SendFreeCnt	; Send data if necessary
+	iny			; Y == $FF?
+	beq	:+
+	lda	#$00		; TryHard = false
+	jsr	TryToSend
+
+	; Check for buffer empty
+:	lda	RecvFreeCnt	; (25)
+	cmp	#$FF
+	bne	:+
+	lda	#SER_ERR_NO_DATA
+	rts
+
+	; Check for flow stopped & enough free: release flow control
+:	ldy	Stopped 	; (34)
+	beq	:+
+	cmp	#63
+	bcc	:+
+	lda	#$00
+	sta	Stopped
+	lda	RtsOff
+	ora	#%00001000
+	sta	ACIA_CMD,x
+
+	; Get byte from buffer
+:	ldy	RecvHead	; (41)
+	lda	RecvBuf,y
+	inc	RecvHead
+	inc	RecvFreeCnt
+	ldx	#$00		; (59)
+	sta	(ptr1,x)
+	txa			; Return code = 0
+	rts
+
+;----------------------------------------------------------------------------
+; PUT: Output character in A.
+; Must return an SER_ERR_xx code in a/x.
+
+PUT:
+	ldx	Index
+
+	; Try to send
+	ldy	SendFreeCnt
+	iny			; Y = $FF?
+	beq	:+
+	pha
+	lda	#$00		; TryHard = false
+	jsr	TryToSend
+	pla
+
+	; Put byte into send buffer & send
+:	ldy	SendFreeCnt
+	bne	:+
+	lda	#SER_ERR_OVERFLOW
+	rts
+
+:	ldy	SendTail
+	sta	SendBuf,y
+	inc	SendTail
+	dec	SendFreeCnt
+	lda	#$FF		; TryHard = true
+	jsr	TryToSend
+	lda	#SER_ERR_INV_IOCTL
+	rts
+
+;----------------------------------------------------------------------------
+; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
+; registers are already saved, no parameters are passed, but the carry flag
+; is clear on entry. The routine must return with carry set if the interrupt
+; was handled, otherwise with carry clear.
+
+IRQ:
+	ldx	Index		; Check for open port
+	beq	Done
+	lda	ACIA_STATUS,x	; Check ACIA status for receive interrupt
+	and	#$08
+	beq	Done		; Jump if no ACIA interrupt
+	lda	ACIA_DATA,x	; Get byte from ACIA
+	ldy	RecvFreeCnt	; Check if we have free space left
+	beq	Flow		; Jump if no space in receive buffer
+	ldy	RecvTail	; Load buffer pointer
+	sta	RecvBuf,y	; Store received byte in buffer
+	inc	RecvTail	; Increment buffer pointer
+	dec	RecvFreeCnt	; Decrement free space counter
+	ldy	RecvFreeCnt	; Check for buffer space low
+	cpy	#33
+	bcc	Flow		; Assert flow control if buffer space low
+	rts			; Interrupt handled (carry already set)
+
+	; Assert flow control if buffer space too low
+Flow:	lda	RtsOff
+	sta	ACIA_CMD,x
+	sta	Stopped
+	sec			; Interrupt handled
+Done:	rts
+
+;----------------------------------------------------------------------------
+; Try to send a byte. Internal routine. A = TryHard
+
+TryToSend:
+	sta	tmp1		; Remember tryHard flag
+Again:	lda	SendFreeCnt
+	cmp	#$FF
+	beq	Quit		; Bail out
+
+	; Check for flow stopped
+	lda	Stopped
+	bne	Quit		; Bail out
+
+	; Check that ACIA is ready to send
+	lda	ACIA_STATUS,x
+	and	#$10
+	bne	Send
+	bit	tmp1		; Keep trying if must try hard	
+	bmi	Again
+Quit:	rts
+
+	; Send byte and try again
+Send:	ldy	SendHead
+	lda	SendBuf,y
+	sta	ACIA_DATA,x
+	inc	SendHead
+	inc	SendFreeCnt
+	jmp	Again
diff --git a/libsrc/apple2/tgi/a2.hi.fnt b/libsrc/apple2/tgi/a2.hi.fnt
new file mode 100644
index 000000000..5f23de569
Binary files /dev/null and b/libsrc/apple2/tgi/a2.hi.fnt differ
diff --git a/libsrc/apple2/tgi/a2.hi.s b/libsrc/apple2/tgi/a2.hi.s
new file mode 100644
index 000000000..ce2814a1c
--- /dev/null
+++ b/libsrc/apple2/tgi/a2.hi.s
@@ -0,0 +1,445 @@
+;
+; Graphics driver for the 280x192x8 mode on the Apple II
+;
+; Stefan Haubenthal 
+; Oliver Schmidt 
+;
+
+	.include	"zeropage.inc"
+
+	.include	"tgi-kernel.inc"
+	.include	"tgi-error.inc"
+	.include	"apple2.inc"
+
+; ------------------------------------------------------------------------
+
+; Zero page stuff
+
+HBASL	:=	$26
+HMASK	:=	$30
+PAGE	:=	$E6
+SCALE	:=	$E7
+ROT	:=	$F9
+
+; Graphics entry points, by cbmnut (applenut??) cbmnut@hushmail.com
+
+TEXT    :=	$F399	; Return to text screen
+HGR2    :=	$F3D8	; Initialize and clear hi-res page 2.
+HGR     :=	$F3E2	; Initialize and clear hi-res page 1.
+HCLR    :=	$F3F2	; Clear the current hi-res screen to black.
+BKGND   :=	$F3F6	; Clear the current hi-res screen to the
+                        ; last plotted color (from ($1C).
+HPOSN   :=	$F411	; Positions the hi-res cursor without
+                        ; plotting a point.
+                        ; Enter with (A) = Y-coordinate, and
+                        ; (Y,X) = X-coordinate.
+HPLOT   :=	$F457	; Calls HPOSN and tries to plot a dot at
+                        ; the cursor's position.  If you are
+                        ; trying to plot a non-white color at
+                        ; a complementary color position, no
+                        ; dot will be plotted.
+HLIN    :=	$F53A	; Draws a line from the last plotted
+                        ; point or line destination to:
+                        ; (X,A) = X-coordinate, and
+                        ; (Y) = Y-coordinate.
+HFIND   :=	$F5CB	; Converts the hi-res coursor's position
+                        ; back to X- and Y-coordinates; stores
+                        ; X-coordinate at $E0,E1 and Y-coordinate
+                        ; at $E2.
+DRAW    :=	$F601	; Draws a shape.  Enter with (Y,X) = the
+                        ; address of the shape table, and (A) =
+                        ; the rotation factor.  Uses the current
+                        ; color.
+XDRAW   :=	$F65D	; Draws a shape by inverting the existing
+                        ; color of the dots the shape draws over.
+                        ; Same entry parameters as DRAW.
+SETHCOL :=	$F6EC	; Set the hi-res color to (X), where (X)
+                        ; must be between 0 and 7.
+
+; ------------------------------------------------------------------------
+
+; Variables mapped to the zero page segment variables. Some of these are
+; used for passing parameters to the driver.
+
+X1	:=	ptr1
+Y1	:=	ptr2
+X2	:=	ptr3
+Y2	:=	ptr4
+
+; ------------------------------------------------------------------------
+
+	.segment	"JUMPTABLE"
+
+; Header. Includes jump table and constants.
+
+; First part of the header is a structure that has a magic and defines the
+; capabilities of the driver
+
+	.byte	$74, $67, $69	; "tgi"
+	.byte	TGI_API_VERSION	; TGI API version number
+	.word	280		; X resolution
+	.word	192		; Y resolution
+	.byte	8		; Number of drawing colors
+pages:	.byte	2		; Number of screens available
+	.byte	7		; System font X size
+	.byte	8		; System font Y size
+	.word   $00EA		; Aspect ratio (based on 4/3 display)
+        .byte   0               ; TGI driver flags
+
+; Next comes the jump table. With the exception of IRQ, all entries must be
+; valid and may point to an RTS for test versions (function not implemented).
+
+       	.addr   INSTALL
+       	.addr   UNINSTALL
+       	.addr   INIT
+       	.addr   DONE
+       	.addr   GETERROR
+       	.addr   CONTROL
+       	.addr   CLEAR
+       	.addr   SETVIEWPAGE
+       	.addr   SETDRAWPAGE
+       	.addr   SETCOLOR
+       	.addr   SETPALETTE
+       	.addr   GETPALETTE
+       	.addr   GETDEFPALETTE
+       	.addr   SETPIXEL
+       	.addr   GETPIXEL
+       	.addr   LINE
+       	.addr   BAR
+       	.addr   TEXTSTYLE
+       	.addr   OUTTEXT
+        .addr   0               ; IRQ entry is unused
+
+; ------------------------------------------------------------------------
+
+	.bss
+
+; Absolute variables used in the code
+
+ERROR:	.res	1		; Error code
+
+; ------------------------------------------------------------------------
+
+	.rodata
+
+; Constants and tables
+
+DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
+
+FONT:
+	; Beagle Bros Shape Mechanic font F.ASCII.SMALL
+	; modified to exactly reproduce the text glyphs
+	.incbin	"a2.hi.fnt"
+
+; ------------------------------------------------------------------------
+
+	.code
+
+; INSTALL routine. Is called after the driver is loaded into memory. May
+; initialize anything that has to be done just once. Is probably empty
+; most of the time.
+; Must set an error code: NO
+INSTALL:
+	.ifdef  __APPLE2ENH__
+	; No page switching if 80 column store is enabled
+	bit	RD80COL
+	bpl	:+
+	lda	#$01
+	sta	pages
+:	.endif
+
+	; Fall through
+
+; UNINSTALL routine. Is called before the driver is removed from memory. May
+; clean up anything done by INSTALL but is probably empty most of the time.
+; Must set an error code: NO
+UNINSTALL:
+	rts
+
+; INIT: Changes an already installed device from text mode to graphics mode.
+; Note that INIT/DONE may be called multiple times while the driver
+; is loaded, while INSTALL is only called once, so any code that is needed
+; to initializes variables and so on must go here. Setting palette and
+; clearing the screen is not needed because this is called by the graphics
+; kernel later.
+; The graphics kernel will never call INIT when a graphics mode is already
+; active, so there is no need to protect against that.
+; Must set an error code: YES
+INIT:
+	; Switch into graphics mode
+	bit	MIXCLR
+	bit	HIRES
+	bit	TXTCLR
+
+	; Beagle Bros Shape Mechanic fonts don't
+	; scale well so use fixed scaling factor
+	lda	#$01
+	sta	SCALE
+
+	; Done, reset the error code
+	lda	#TGI_ERR_OK
+	sta	ERROR
+	rts
+
+; DONE: Will be called to switch the graphics device back into text mode.
+; The graphics kernel will never call DONE when no graphics mode is active,
+; so there is no need to protect against that.
+; Must set an error code: NO
+DONE:
+	; Switch into text mode
+	bit	TXTSET
+	bit	LOWSCR
+
+	.ifdef  __APPLE2ENH__
+	; Limit SET80COL-HISCR to text
+	bit	LORES
+	.endif
+
+	; Reset the text window top
+	lda	#$00
+	sta	WNDTOP
+	rts
+
+; GETERROR: Return the error code in A and clear it.
+GETERROR:
+	lda	ERROR
+	ldx	#TGI_ERR_OK
+	stx	ERROR
+	rts
+
+; CONTROL: Platform/driver specific entry point.
+; Must set an error code: YES
+CONTROL:
+	; Check data msb and code to be 0
+	ora	ptr1+1
+	bne	err
+
+	; Check data lsb to be [0..1]
+	lda	ptr1
+	cmp	#1+1
+	bcs	err
+
+	; Set text window top
+	tax
+	beq	:+
+	lda	#20
+:	sta	WNDTOP
+
+	; Switch 4 lines of text
+	.assert MIXCLR + 1 = MIXSET, error
+	lda	MIXCLR,x	; No BIT absolute,X available
+
+	; Done, reset the error code
+	lda	#TGI_ERR_OK
+	beq	:+		; Branch always
+
+	; Done, set the error code
+err:	lda	#TGI_ERR_INV_ARG
+:	sta	ERROR
+	rts
+
+; CLEAR: Clears the screen.
+; Must set an error code: NO
+CLEAR:
+	bit	$C082		; Switch in ROM
+	jsr	HCLR
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+; Must set an error code: NO (will only be called if page ok)
+SETVIEWPAGE:
+	tax
+	.assert LOWSCR + 1 = HISCR, error
+	lda	LOWSCR,x	; No BIT absolute,X available
+	rts
+
+; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+; Must set an error code: NO (will only be called if page ok)
+SETDRAWPAGE:
+	tax
+	beq	:+
+	lda	#>$4000		; Page 2
+	.byte	$2C		; BIT absolute
+:	lda	#>$2000		; Page 1
+	sta	PAGE
+	rts
+
+; SETCOLOR: Set the drawing color (in A). The new color is already checked
+; to be in a valid range (0..maxcolor-1).
+; Must set an error code: NO (will only be called if color ok)
+SETCOLOR:
+	bit	$C082		; Switch in ROM
+	tax
+	jsr	SETHCOL
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; SETPALETTE: Set the palette (not available with all drivers/hardware).
+; A pointer to the palette is passed in ptr1. Must set an error if palettes
+; are not supported
+; Must set an error code: YES
+SETPALETTE:
+	lda	#TGI_ERR_INV_FUNC
+	sta	ERROR
+	rts
+
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
+; Must set an error code: NO
+GETPALETTE:
+	; Fall through
+
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes, otherwise the caller has no way to determine the colors
+; of the (not changeable) palette.
+; Must set an error code: NO (all drivers must have a default palette)
+GETDEFPALETTE:
+	lda	#DEFPALETTE
+	rts
+
+; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
+; color. The coordinates passed to this function are never outside the
+; visible screen area, so there is no need for clipping inside this function.
+; Must set an error code: NO
+SETPIXEL:
+	bit	$C082		; Switch in ROM
+	ldx	X1
+	ldy	X1+1
+	lda	Y1
+	jsr	HPLOT
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; GETPIXEL: Read the color value of a pixel and return it in A/X. The
+; coordinates passed to this function are never outside the visible screen
+; area, so there is no need for clipping inside this function.
+GETPIXEL:
+	bit	$C082		; Switch in ROM
+	ldx	X1
+	ldy	X1+1
+	lda	Y1
+	jsr	HPOSN
+	lda	(HBASL),y
+	and	HMASK
+	asl
+	beq	:+		; 0 (black)
+	lda	#$03		; 3 (white)
+:	bcc	:+
+	adc	#$03		; += 4 (black -> black2, white -> white2)
+:	ldx	#$00
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
+; X2/Y2 = ptr3/ptr4 using the current drawing color.
+; Must set an error code: NO
+LINE:
+	bit	$C082		; Switch in ROM
+	ldx	X1
+	ldy	X1+1
+	lda	Y1
+	jsr	HPOSN
+	lda	X2
+	ldx	X2+1
+	ldy	Y2
+	jsr	HLIN
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
+; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
+; Contrary to most other functions, the graphics kernel will sort and clip
+; the coordinates before calling the driver, so on entry the following
+; conditions are valid:
+;	X1 <= X2
+;	Y1 <= Y2
+;	(X1 >= 0) && (X1 < XRES)
+;	(X2 >= 0) && (X2 < XRES)
+;	(Y1 >= 0) && (Y1 < YRES)
+;	(Y2 >= 0) && (Y2 < YRES)
+; Must set an error code: NO
+BAR:
+	inc	Y2
+:	lda	Y2
+	pha
+  	lda	Y1
+	sta	Y2
+	jsr	LINE
+	pla
+	sta	Y2
+	inc	Y1
+	cmp	Y1
+	bne	:-
+	rts
+
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
+; direction is passend in X/Y, the text direction is passed in A.
+; Must set an error code: NO
+TEXTSTYLE:
+	cmp	#TGI_TEXT_VERTICAL
+	bne	:+
+	lda	#48
+:	sta	ROT
+	rts
+
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero terminated
+; string with address in ptr3.
+; Must set an error code: NO
+OUTTEXT:
+	bit	$C082		; Switch in ROM
+	lda	X1
+	ldy	X1+1
+	ldx	ROT
+	php			; Save Z flag
+	beq	:+		; Not horizontal
+	sec
+	sbc	#$07		; Adjust X
+	bcs	:+
+	dey
+:	tax
+	lda	Y1
+	plp			; Restore Z flag
+	bne	:+		; Not vertical
+	sec
+	sbc	#$07		; Adjust Y
+:	jsr	HPOSN
+	clc
+	lda	FONT+2*99	; "connection char"
+	adc	#FONT
+	sta	ptr4+1
+	ldy	#$00
+:	lda	(ptr3),y
+	beq	:+
+	sty	tmp1		; Save string index
+	sec
+	sbc	#$1F		; No control chars
+	asl			; Offset * 2
+	tay
+	clc
+	lda	FONT,y
+	adc	#FONT
+	tay
+	lda	ROT
+	jsr	DRAW		; Draw char from string
+	ldx	ptr4
+	ldy	ptr4+1
+	lda	ROT
+	jsr	DRAW		; Draw "connection char"
+	ldy	tmp1		; Restore string index
+	iny
+	bne	:-		; Branch always
+:	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
diff --git a/libsrc/apple2/tgi/a2.lo.s b/libsrc/apple2/tgi/a2.lo.s
new file mode 100644
index 000000000..edea841be
--- /dev/null
+++ b/libsrc/apple2/tgi/a2.lo.s
@@ -0,0 +1,347 @@
+;
+; Graphics driver for the 40x48x16 mode on the Apple II
+;
+; Stefan Haubenthal 
+; Oliver Schmidt 
+;
+
+	.include	"zeropage.inc"
+
+	.include	"tgi-kernel.inc"
+	.include	"tgi-error.inc"
+	.include	"apple2.inc"
+
+; ------------------------------------------------------------------------
+
+; Zero page stuff
+
+H2	:=	$2C
+COLOR	:=	$30
+
+; ROM entry points
+
+TEXT    :=	$F399
+PLOT	:=	$F800
+HLINE	:=	$F819
+CLRSC2	:=	$F838
+SETCOL	:=	$F864
+SCRN	:=	$F871
+SETGR	:=	$FB40
+HOME	:=	$FC58
+
+; Used for passing parameters to the driver
+
+X1	:=	ptr1
+Y1	:=	ptr2
+X2	:=	ptr3
+Y2	:=	ptr4
+
+; ------------------------------------------------------------------------
+
+	.segment	"JUMPTABLE"
+
+; Header. Includes jump table and constants.
+
+; First part of the header is a structure that has a magic and defines the
+; capabilities of the driver
+
+	.byte	$74, $67, $69	; "tgi"
+	.byte	TGI_API_VERSION	; TGI API version number
+	.word	40		; X resolution
+	.word	48		; Y resolution
+	.byte	16		; Number of drawing colors
+	.byte	1		; Number of screens available
+	.byte	8		; System font X size
+	.byte	8		; System font Y size
+	.word   $0198		; Aspect ratio (based on 4/3 display)
+        .byte   0               ; TGI driver flags
+
+; Next comes the jump table. With the exception of IRQ, all entries must be
+; valid and may point to an RTS for test versions (function not implemented).
+
+       	.addr   INSTALL
+       	.addr   UNINSTALL
+       	.addr   INIT
+       	.addr   DONE
+       	.addr   GETERROR
+       	.addr   CONTROL
+       	.addr   CLEAR
+       	.addr   SETVIEWPAGE
+       	.addr   SETDRAWPAGE
+       	.addr   SETCOLOR
+       	.addr   SETPALETTE
+       	.addr   GETPALETTE
+       	.addr   GETDEFPALETTE
+       	.addr   SETPIXEL
+       	.addr   GETPIXEL
+       	.addr   LINE
+       	.addr   BAR
+       	.addr   TEXTSTYLE
+       	.addr   OUTTEXT
+        .addr   0               ; IRQ entry is unused
+
+; ------------------------------------------------------------------------
+
+	.bss
+
+ERROR:	.res	1		; Error code
+MIX:	.res	1		; 4 lines of text
+
+; ------------------------------------------------------------------------
+
+	.rodata
+
+DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07
+	    .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F
+
+TGI2COL:    .byte $00, $0C, $03, $0F, $01, $09, $06, $02
+	    .byte $04, $05, $07, $08, $0A, $0B, $0D, $0E
+
+COL2TGI:    .byte $00, $04, $07, $02, $08, $09, $06, $0A
+	    .byte $0B, $05, $0C, $0D, $01, $0E, $0F, $03
+
+MAXY:	.byte 47, 39
+
+; ------------------------------------------------------------------------
+
+	.code
+
+; INIT: Changes an already installed device from text mode to graphics mode.
+; Note that INIT/DONE may be called multiple times while the driver
+; is loaded, while INSTALL is only called once, so any code that is needed
+; to initializes variables and so on must go here. Setting palette and
+; clearing the screen is not needed because this is called by the graphics
+; kernel later.
+; The graphics kernel will never call INIT when a graphics mode is already
+; active, so there is no need to protect against that.
+; Must set an error code: YES
+INIT:
+	; Switch into graphics mode
+	bit	$C082		; Switch in ROM
+	jsr	SETGR
+	bit	MIXCLR
+	bit	$C080		; Switch in LC bank 2 for R/O
+
+	; Done, reset the error code
+	lda	#TGI_ERR_OK
+	sta	ERROR
+	sta	MIX
+
+	; Fall through
+
+; INSTALL routine. Is called after the driver is loaded into memory. May
+; initialize anything that has to be done just once. Is probably empty
+; most of the time.
+; Must set an error code: NO
+INSTALL:
+	; Fall through
+
+; UNINSTALL routine. Is called before the driver is removed from memory. May
+; clean up anything done by INSTALL but is probably empty most of the time.
+; Must set an error code: NO
+UNINSTALL:
+	; Fall through
+
+; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+; Must set an error code: NO (will only be called if page ok)
+SETVIEWPAGE:
+	; Fall through
+
+; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+; Must set an error code: NO (will only be called if page ok)
+SETDRAWPAGE:
+	; Fall through
+
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
+; direction is passend in X/Y, the text direction is passed in A.
+; Must set an error code: NO
+TEXTSTYLE:
+	; Fall through
+
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero terminated
+; string with address in ptr3.
+; Must set an error code: NO
+OUTTEXT:
+	rts
+
+; DONE: Will be called to switch the graphics device back into text mode.
+; The graphics kernel will never call DONE when no graphics mode is active,
+; so there is no need to protect against that.
+; Must set an error code: NO
+DONE:
+	bit	$C082		; Switch in ROM
+	jsr	TEXT
+	jsr	HOME
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; GETERROR: Return the error code in A and clear it.
+GETERROR:
+	lda	ERROR
+	ldx	#TGI_ERR_OK
+	stx	ERROR
+	rts
+
+; CLEAR: Clears the screen.
+; Must set an error code: NO
+CLEAR:
+	bit	$C082		; Switch in ROM
+	lda	COLOR		; Save current drawing color
+	pha
+	ldx	MIX
+	ldy	MAXY,x		; Max Y depends on 4 lines of text
+	jsr	CLRSC2
+	pla
+	sta	COLOR		; Restore current drawing color
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; SETCOLOR: Set the drawing color (in A). The new color is already checked
+; to be in a valid range (0..maxcolor-1).
+; Must set an error code: NO (will only be called if color ok)
+SETCOLOR:
+	bit	$C082		; Switch in ROM
+	tax
+	lda	TGI2COL,x
+	jsr	SETCOL
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; CONTROL: Platform/driver specific entry point.
+; Must set an error code: YES
+CONTROL:
+	; Check data msb and code to be 0
+	ora	ptr1+1
+	bne	err
+
+	; Check data lsb to be [0..1]
+	lda	ptr1
+	cmp	#1+1
+	bcs	err
+	bit	$C082		; Switch in ROM
+
+	; Switch 4 lines of text
+	tax
+	.assert MIXCLR + 1 = MIXSET, error
+	lda	MIXCLR,x	; No BIT absolute,X available
+
+	; Save current switch setting
+	txa
+	sta	MIX
+	bne	text
+
+	; Clear 8 lines of graphics
+	lda	COLOR		; Save current drawing color
+	pha
+	lda	#39		; Rightmost column
+	sta	H2
+	ldx	#40		; First line
+:	txa
+	ldy	#$00		; Leftmost column
+	sty	COLOR		; Black
+	jsr	HLINE		; Preserves X
+	inx
+	cpx	#47+1		; Last line
+	bcc	:-
+	pla
+	sta	COLOR		; Restore current drawing color
+	bcs	:+		; Branch always
+
+	; Clear 4 lines of text
+text:	jsr	HOME
+:	bit	$C080		; Switch in LC bank 2 for R/O
+
+	; Done, reset the error code
+	lda	#TGI_ERR_OK
+	beq	:+		; Branch always
+
+	; Done, set the error code
+err:	lda	#TGI_ERR_INV_ARG
+:	sta	ERROR
+	rts
+
+; SETPALETTE: Set the palette (not available with all drivers/hardware).
+; A pointer to the palette is passed in ptr1. Must set an error if palettes
+; are not supported
+; Must set an error code: YES
+SETPALETTE:
+	lda	#TGI_ERR_INV_FUNC
+	sta	ERROR
+	rts
+
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
+; Must set an error code: NO
+GETPALETTE:
+	; Fall through
+
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes, otherwise the caller has no way to determine the colors
+; of the (not changeable) palette.
+; Must set an error code: NO (all drivers must have a default palette)
+GETDEFPALETTE:
+	lda	#DEFPALETTE
+	rts
+
+; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
+; color. The coordinates passed to this function are never outside the
+; visible screen area, so there is no need for clipping inside this function.
+; Must set an error code: NO
+SETPIXEL:
+	bit	$C082		; Switch in ROM
+	ldy	X1
+	lda	Y1
+	jsr	PLOT
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; GETPIXEL: Read the color value of a pixel and return it in A/X. The
+; coordinates passed to this function are never outside the visible screen
+; area, so there is no need for clipping inside this function.
+GETPIXEL:
+	bit	$C082		; Switch in ROM
+	ldy	X1
+	lda	Y1
+	jsr	SCRN
+	tax
+	lda	COL2TGI,x
+	ldx	#$00
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
+; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
+; Contrary to most other functions, the graphics kernel will sort and clip
+; the coordinates before calling the driver, so on entry the following
+; conditions are valid:
+;	X1 <= X2
+;	Y1 <= Y2
+;	(X1 >= 0) && (X1 < XRES)
+;	(X2 >= 0) && (X2 < XRES)
+;	(Y1 >= 0) && (Y1 < YRES)
+;	(Y2 >= 0) && (Y2 < YRES)
+; Must set an error code: NO
+BAR:
+	bit	$C082		; Switch in ROM
+	lda	X2
+	sta	H2
+	inc	Y2
+	ldx	Y1
+:	txa
+	ldy	X1
+	jsr	HLINE		; Preserves X
+	inx
+	cpx	Y2
+	bcc	:-
+	bit	$C080		; Switch in LC bank 2 for R/O
+	rts
+
+; ------------------------------------------------------------------------
+
+.include	"../../tgi/tgidrv_line.inc"
diff --git a/libsrc/apple2enh/Makefile b/libsrc/apple2enh/Makefile
deleted file mode 100644
index f27d2fdcd..000000000
--- a/libsrc/apple2enh/Makefile
+++ /dev/null
@@ -1,187 +0,0 @@
-#
-# makefile for CC65 runtime library
-#
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= apple2enh
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I../apple2 -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I ../apple2 -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	../apple2/%.c
-	@$(CC) -o $(notdir $(*).s) $(CFLAGS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	../apple2/%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-extra/%.o: ../apple2/extra/%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-mou.o: %.mou
-	@$(CO) -o $(*)-mou.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-mou.s
-
-%-ser.o: %.ser
-	@$(CO) -o $(*)-ser.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-ser.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd: 	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.mou:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.ser:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-#--------------------------------------------------------------------------
-# Object files
-
-C_OBJS=	closedir.o		\
-	opendir.o		\
-	readdir.o		\
-	rewinddir.o
-
-S_OBJS=	_scrsize.o		\
-	break.o			\
-	cclear.o		\
-	cgetc.o			\
-	chline.o		\
-	close.o			\
-	clrscr.o		\
-	color.o			\
-	cout.o			\
-	cputc.o			\
-	crt0.o			\
-	ctype.o			\
-	curdevice.o		\
-	cvline.o		\
-	devicedir.o		\
-	dioclose.o		\
-	diocommon.o		\
-	dioopen.o		\
-	dioread.o		\
-	diosectcount.o		\
-	diosectsize.o		\
-	diowrite.o		\
-	dosdetect.o		\
-	exec.o			\
-	exehdr.o		\
-	filedes.o		\
-	filename.o		\
-	get_ostype.o		\
-	getdevice.o		\
-	gotoxy.o		\
-	gotoy.o			\
-	home.o			\
-	initcwd.o		\
-	iobuf.o			\
-	irq.o			\
-	isdevice.o		\
-	joy_stat_stddrv.o	\
-	joy_stddrv.o		\
-	kbhit.o			\
-	mainargs.o		\
-	mcbdefault.o		\
-	mli.o			\
-	mouse_stat_stddrv.o	\
-	mouse_stddrv.o		\
-	open.o			\
-	oserrlist.o		\
-	oserror.o		\
-	randomize.o		\
-	rdkey.o			\
-	read.o			\
-	reboot.o		\
-	revers.o		\
-	rwcommon.o		\
-	syschdir.o		\
-	sysmkdir.o		\
-	sysremove.o		\
-	sysrename.o		\
-	sysrmdir.o		\
-	systime.o		\
-	sysuname.o		\
-	textframe.o		\
-	tgi_colors.o		\
-	tgi_stat_stddrv.o	\
-	tgi_stddrv.o		\
-	toascii.o		\
-	videomode.o		\
-	vtabz.o			\
-	wherex.o		\
-	wherey.o		\
-	write.o			\
-	$(EMDS:.emd=-emd.o)	\
-	$(JOYS:.joy=-joy.o)	\
-	$(MOUS:.mou=-mou.o)	\
-	$(SERS:.ser=-ser.o)	\
-	$(TGIS:.tgi=-tgi.o)
-
-S_EXTRA_OBJS=			\
-	extra/iobuf-0800.o
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS = apple2-auxmem.emd
-
-JOYS = apple2-stdjoy.joy
-
-MOUS = apple2-stdmou.mou
-
-SERS = apple2-ssc.ser
-
-TGIS = apple2-280-192-8.tgi apple2-40-48-16.tgi
-
-#--------------------------------------------------------------------------
-# Targets
-
-.PHONY:	all clean zap
-
-all:	$(C_OBJS) $(S_OBJS) $(S_EXTRA_OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(C_OBJS:.o=.s) $(C_OBJS) $(S_OBJS) $(S_EXTRA_OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(MOUS:.mou=.o) $(MOUS:.mou=-mou.s) \
-	       $(SERS:.ser=.o) $(SERS:.ser=-ser.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
diff --git a/libsrc/atari/Makefile b/libsrc/atari/Makefile
deleted file mode 100644
index 8c8619283..000000000
--- a/libsrc/atari/Makefile
+++ /dev/null
@@ -1,171 +0,0 @@
-#
-# makefile for CC65 Atari runtime library
-#
-# NUMDRVS - number of supported drives (max. 16)
-#           4 bytes for each device are statically allocated
-# LINEBUF - support line buffered reads from E: (the number specifies
-#           the length of the buffer)
-# UCASE_FILENAME - all filenames get uppercased
-# DEFAULT_DEVICE - if the string passed to the uppercase function doesn't
-#                  include a device (":" at position 2 or 3), provide "Dn:"
-#                  as a default disk device
-#                  n is the value of DEFAULT_DEVICE, unless DYNAMIC_DD is
-#                  also set, in which case it's overridden by a runtime
-#                  check (on SpartaDOS only)
-#                  needs UCASE_FILENAME to be defined, otherwise no effect
-# DYNAMIC_DD     - determine default disk device at runtime (SpartaDOS only)
-#                  needs DEFAULT_DEVICE to be defined, otherwise no effect
-
-ATARIDEFS =  -DNUMDRVS=4 -DUCASE_FILENAME=1 -DDEFAULT_DEVICE=1 -DLINEBUF=80
-ATARIDEFS += -DDYNAMIC_DD=1
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= atari
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	%.c
-	@$(CC) $(CFLAGS) $(ATARIDEFS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	%.s
-	@$(AS) -g -o $@ $(AFLAGS) $(ATARIDEFS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o atari_tgi_common.inc
-	@$(LD) -o $@ -t module $< ../runtime/zeropage.o
-
-
-#--------------------------------------------------------------------------
-# Object files
-
-OBJS = 	_scrsize.o              \
-	break.o                 \
-	cclear.o                \
-	cgetc.o                 \
-	chline.o                \
-	clock.o                 \
-	close.o                 \
-	clrscr.o                \
-	color.o                 \
-	cputc.o                 \
-	crt0.o                  \
-	ctype.o                 \
-	cvline.o                \
-	dio_cts.o               \
-	dio_stc.o               \
-	diopncls.o              \
-	dioqsize.o              \
-	dioread.o               \
-	diowrite.o              \
-	diowritev.o             \
-	do_oserr.o              \
-	dosdetect.o             \
-	fdtable.o               \
-	fdtab.o                 \
-	fdtoiocb.o              \
-	getargs.o               \
-	getdefdev.o             \
-	getfd.o                 \
-	gotox.o                 \
-	gotoy.o                 \
-	gotoxy.o                \
-	graphics.o              \
-	initcwd.o               \
-	inviocb.o               \
-	irq.o                   \
-	joy_stat_stddrv.o       \
-	joy_stddrv.o            \
-	kbhit.o                 \
-	lseek.o                 \
-	mul40.o                 \
-	open.o                  \
-	oserrlist.o             \
-	oserror.o               \
-	ostype.o                \
-	posixdirent.o           \
-	randomize.o             \
-	read.o                  \
-	revers.o                \
-	rwcommon.o              \
-	savevec.o               \
-	scroll.o                \
-	setcolor.o              \
-	siocall.o               \
-	syschdir.o              \
-	sysmkdir.o              \
-	sysremove.o             \
-	sysrmdir.o              \
-	systime.o               \
-	sysuname.o              \
-	tgi_colors.o            \
-	tgi_stat_stddrv.o       \
-	tgi_stddrv.o            \
-	toascii.o               \
-	tvtype.o                \
-	ucase_fn.o              \
-	wherex.o                \
-	wherey.o                \
-	write.o                 \
-	$(EMDS:.emd=-emd.o)     \
-	$(JOYS:.joy=-joy.o)     \
-	$(TGIS:.tgi=-tgi.o)
-
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS = atari-130xe.emd
-
-JOYS = atari-stdjoy.joy atari-multijoy.joy
-
-TGIS = atari-3.tgi atari-4.tgi atari-5.tgi atari-6.tgi atari-7.tgi atari-8.tgi \
-       atari-9.tgi atari-10.tgi atari-11.tgi atari-14.tgi atari-15.tgi atari-8p2.tgi \
-       atari-9p2.tgi atari-10p2.tgi atari-15p2.tgi
-
-#--------------------------------------------------------------------------
-# Targets
-
-all:	$(OBJS) $(EMDS) $(JOYS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(TGIS)
diff --git a/libsrc/atari/Makefile.inc b/libsrc/atari/Makefile.inc
new file mode 100644
index 000000000..a20e1909e
--- /dev/null
+++ b/libsrc/atari/Makefile.inc
@@ -0,0 +1,16 @@
+# NUMDRVS        - number of supported drives (max. 16)
+#                  4 bytes for each device are statically allocated
+# LINEBUF        - support line buffered reads from E: (the number specifies
+#                  the length of the buffer)
+# UCASE_FILENAME - all filenames get uppercased
+# DEFAULT_DEVICE - if the string passed to the uppercase function doesn't
+#                  include a device (":" at position 2 or 3), provide "Dn:"
+#                  as a default disk device
+#                  n is the value of DEFAULT_DEVICE, unless DYNAMIC_DD is
+#                  also set, in which case it's overridden by a runtime
+#                  check (on SpartaDOS only)
+#                  needs UCASE_FILENAME to be defined, otherwise no effect
+# DYNAMIC_DD     - determine default disk device at runtime (SpartaDOS only)
+#                  needs DEFAULT_DEVICE to be defined, otherwise no effect
+
+CFLAGS += -Wa -DNUMDRVS=4,-DLINEBUF=80,-DUCASE_FILENAME=1,-DDEFAULT_DEVICE=1,-DDYNAMIC_DD=1
diff --git a/libsrc/atari/atari-10.s b/libsrc/atari/atari-10.s
deleted file mode 100644
index a7da93b97..000000000
--- a/libsrc/atari/atari-10.s
+++ /dev/null
@@ -1,79 +0,0 @@
-;
-; Graphics driver for the 80x192x9 (CIO mode 10, ANTIC mode F, GTIA mode $80) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 10
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 9
-; Pixels per byte
-	ppb = 2
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0330				; based on 4/3 display
-; Free memory needed
-	mem_needed = 7147
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11110000, %00001111
-	masks:					; Color masks
-		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00001111, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96, $68, $C4, $74, $EE, $4A
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	sta	PCOLR0,y
-	dey
-	bpl     loop
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-10p2.s b/libsrc/atari/atari-10p2.s
deleted file mode 100644
index e29ff601c..000000000
--- a/libsrc/atari/atari-10p2.s
+++ /dev/null
@@ -1,79 +0,0 @@
-;
-; Graphics driver for the 80x192x9 (CIO mode 10, ANTIC mode F, GTIA mode $80) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 10
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 9
-; Pixels per byte
-	ppb = 2
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0330				; based on 4/3 display
-; Free memory needed
-	mem_needed = 15339
-; Number of screen pages
-	pages = 2
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11110000, %00001111
-	masks:					; Color masks
-		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00001111, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96, $68, $C4, $74, $EE, $4A
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	sta	PCOLR0,y
-	dey
-	bpl     loop
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-11.s b/libsrc/atari/atari-11.s
deleted file mode 100644
index 2e2dfd842..000000000
--- a/libsrc/atari/atari-11.s
+++ /dev/null
@@ -1,71 +0,0 @@
-;
-; Graphics driver for the 80x192x16h (CIO mode 11, ANTIC mode F, GTIA mode $C0) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 11
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 16
-; Pixels per byte
-	ppb = 2
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0330				; based on 4/3 display
-; Free memory needed
-	mem_needed = 7147
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11110000, %00001111
-	masks:					; Color masks
-		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $aa, $bb, $cc, $dd, $ee, $ff
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00001111, %00000000
-	default_palette:
-		.byte	$00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; No palettes
-        lda     #TGI_ERR_INV_FUNC
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-130xe.s b/libsrc/atari/atari-130xe.s
deleted file mode 100644
index 6951bd346..000000000
--- a/libsrc/atari/atari-130xe.s
+++ /dev/null
@@ -1,483 +0,0 @@
-;
-; Extended memory driver for the Atari 130XE memory standard
-; Shawn Jefferson, 2012-08-11
-;
-; Banking Register $D301:
-; Bit 7: Self-Test on/off
-; Bit 6: Unused
-; Bit 5: Antic sees bank
-; Bit 4: CPU sees bank
-; Bit 3: bank control
-; Bit 2: bank control
-; Bit 1: BASIC on/off
-; Bit 0: OS RAM on/off
-; 
-; Masks: %11100011  $E3     Bank 0
-;        %11100111  $E7     Bank 1
-;        %11101011  $EB     Bank 2
-;        %11101111  $EF     Bank 3
-;        %11111111  $FF     Off
-;
-; Based on the Extended memory driver for the Apple II auxiliary memory
-;  by
-; Stefan Haubenthal, 2003-12-12
-; Ullrich von Bassewitz, 2002-12-02
-;
-
-	.include        "zeropage.inc"
-
-	.include        "em-kernel.inc"
-	.include        "em-error.inc"
-
-
-	.macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-	.byte   $65, $6d, $64           ; "emd"
-	.byte   EMD_API_VERSION         ; EM API version number
-
-; Jump table.
-
-	.word   INSTALL
-	.word   DEINSTALL
-	.word   PAGECOUNT
-	.word   MAP
-	.word   USE
-	.word   COMMIT
-	.word   COPYFROM
-	.word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BANK    = $4000                         ; bank window
-STACK   = $0100                         ; stack location 
-PAGES   = 256                           ; 4 x 16k banks
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-.rodata
-banks:          .byte $E3,$E7,$EB,$EF   ; 130XE banks for cpu banking
-
-stacktest:      sei
-		ldy banks
-		sty $D301
-		tax                     ; A is set by caller
-		inx
-		stx $4000               ; change $4000
-		ldy #$FF                ; STACK+13
-		sty $D301
-		cmp $4000               ; changed?
-		beq @1
-		sec                     ; error
-		bcs @2
-@1:             clc
-@2:             sta $4000               ; restore
-		cli
-		rts
-stacktest_end: 
-
-stackcopy:      sei                     ; disable interrupts
-@1:             dex                     ; pre-decrement (full page x=0)
-		ldy #$FF                ; this will be replaced  STACK+3
-		sty $D301               ; set bank 
-		lda $FF00,x             ; address to copy from   STACK+8,+9
-		ldy #$FF                ; this will be replaced  STACK+11
-		sty $D301 
-		sta $FF00,x             ; address to copy to     STACK+16,+17
-		cpx #0 
-		bne @1
-		ldy #$FF                ; portb_save             STACK+23
-		sty $D301
-		cli                     ; enable interrupts
-		rts
-stackcopy_end:
-
-stackcopy_byte: sei
-		ldy #$FF                ; STACK+2
-		sty $D301
-		lda $FFFF               ; STACK+7 +8
-		ldy #$FF                ; STACK+10
-		sty $D301
-		sta $FFFF               ; STACK+15 +16
-		ldy #$FF                ; STACK+18
-		sty $D301
-		cli
-		rts
-stackcopy_byte_end: 
-
-
-.data
-curpage:        .byte   $FF             ; Current page number in bank (invalid)
-curbank:        .byte   $FF             ; Current bank number
-
-.bss
-window:         .res    256             ; Memory "window"
-portb_save:     .res    1               ; portb state
-
-.code
-
-install_transfer:
-		ldx #stackcopy_end - stackcopy - 1
-@1:             lda stackcopy,x
-		sta STACK,x
-		dex
-		bpl @1
-		rts
-
-install_byte_transfer:
-		ldx #stackcopy_byte_end - stackcopy_byte - 1
-@2:             lda stackcopy_byte,x
-		sta STACK,x
-		dex
-		bpl @2
-		rts
-
-install_test:
-		ldx #stacktest_end - stacktest - 1
-@3:             lda stacktest,x
-		sta STACK,x
-		dex
-		bpl @3
-		rts
-
-setpage:
-		tax                             ; save page
-		and     #$C0                    ; mask out bank
-		clc
-		ror
-		ror                             ; divide by 64
-		ror                             ; 64 pages in each bank
-		ror
-		ror
-		ror
-		sta     curbank                 ; Remember the new bank
-		txa                             ; bring back page
-		and     #$3F                    ; mask out page
-		sta     curpage                 ; curpage in bank
-		rts
-
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-	lda     $D301                   ; save state of portb
-	sta     portb_save
-	tay 
-
-	jsr     install_test            ; doesn't touch Y
-	sty     STACK+13
-
-	lda     $4000                   ; test for extended memory
-	jsr     STACK
-	bcs     @1 
-	lda     #EM_ERR_OK
-	rts
-@1:     lda     #EM_ERR_NO_DEVICE
-	rts
-
-; ------------------------------------------------------------------------
-; DEINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-DEINSTALL:
-	rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-	lda     #PAGES
-	rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    jsr setpage                     ; extract the bank/page
-	add     #>BANK                  ; $4000 + page  (carry is cleared)
-	sta     ptr1+1
-	;ldy     #$00
-	;sty     ptr1
-
-	lda     #window
-	sta     ptr2+1
-
-; Transfer one page
-
-	jsr     install_transfer        ; Transfer one page
-
-	ldx     curbank
-	lda     banks,x
-	sta     STACK+3                 ; set bank to copy from
-;        lda     ptr1
-;        sta     STACK+8 
-	lda     ptr1+1
-	sta     STACK+9                 ; set copy from address
-	lda     portb_save
-	sta     STACK+11                ; set portb restore
-	sta     STACK+23                ; set final portb restore
-	lda     ptr2
-	sta     STACK+16
-	lda     ptr2+1
-	sta     STACK+17                ; set copy to address 
-
-	ldx     #0                      ; full page copy
-	jsr     STACK                   ; do the copy! 
-
-; Return the memory window
-
-	lda     #window                ; Return the window address
-
-	rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    ;sta     curpage                 ; Remember the page
-	jsr setpage                     ; extract bank/page
-	lda     #window                ; Return the window
-	rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda     curpage                 ; Get the current page
-	cmp     #$FF
-	beq     commit_done             ; Jump if no page mapped
-
-	clc
-	add     #>BANK
-	sta     ptr2+1
-	;ldy     #$00
-	;sty     ptr2
-
-	lda     #window
-	sta     ptr1+1
-
-; Transfer one page/all bytes
-
-	jsr     install_transfer        ; Transfer one page
-
-	lda     portb_save
-	sta     STACK+3                 ; set bank to copy from
-	sta     STACK+23                ; set final portb restore
-	lda     ptr1
-	sta     STACK+8 
-	lda     ptr1+1
-	sta     STACK+9                 ; set copy from address
-	ldx     curbank
-	lda     banks,x
-	sta     STACK+11                ; set bank to copy to
-	;lda     ptr2
-	;sta     STACK+16
-	lda     ptr2+1
-	sta     STACK+17                ; set copy to address 
-
-	ldx     #0                      ; full page copy
-	jsr     STACK                   ; do the copy! 
-
-commit_done:
-	rts
-
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-COPYFROM:
-	sta     ptr3
-	stx     ptr3+1                  ; Save the passed em_copy pointer
-
-	jsr     install_byte_transfer   ; install the stack copy routine
-
-	ldy     #EM_COPY::OFFS
-	lda     (ptr3),y
-	sta     STACK+7                 ; offset goes into BANK low 
-
-	ldy     #EM_COPY::PAGE
-	lda     (ptr3),y
-	sta     tmp1                    ; save page for later
-	;add     #>BANK
-	;sta     STACK+8                 ; BANK + page goes into BANK high
-
-	ldy     #EM_COPY::BUF
-	lda     (ptr3),y
-	sta     STACK+15                ; buffer goes into dest low
-	iny
-	lda     (ptr3),y
-	sta     STACK+16                ; buffer goes into dest high
-
-	ldy     #EM_COPY::COUNT
-	lda     (ptr3),y                ; Get bytes in last page
-	sta     ptr4
-	iny
-	lda     (ptr3),y                ; Get number of pages
-	sta     ptr4+1
-
-	lda     tmp1                    ; extract bank/page
-	jsr     setpage                 ; sets curbank/curpage
-	lda     curpage
-	add     #>BANK                  ; add to BANK address
-	sta     STACK+8                 ; current page in bank
-	ldx     curbank
-	lda     banks,x 
-	sta     STACK+2                 ; set bank in stack 
-	lda     portb_save 
-	sta     STACK+10                ; set bank restore in stack
-	sta     STACK+18                ; set final restore too
-
-copyfrom_copy:
-	lda     ptr4                    ; check if count is zero
-	bne     @4
-	lda     ptr4+1
-	beq     done
-
-@4:     jsr     STACK                   ; copy one byte
-
-	sec
-	lda     ptr4
-	sub     #1
-	sta     ptr4
-	bcs     @1
-	lda     ptr4+1
-	beq     @1
-	sub     #1
-	sta     ptr4+1
-
-@1:     inc     STACK+7                 ; increment address in BANK
-	bne     @2
-	inc     STACK+8
-	lda     STACK+8
-	cmp     #$80                    ; we stepped outside bank
-	bne     @2
-
-	inc     curbank                 ; get next bank
-	ldx     curbank
-	lda     banks,x
-	sta     STACK+2                 ; set new bank
-	lda     #$40                    ; set address back to $4000
-	sta     STACK+8
-
-@2:     inc     STACK+15                ; increment buffer address
-	bne     @3
-	inc     STACK+16
-
-@3:     jmp     copyfrom_copy           ; copy another byte 
-
-done:
-	rts
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-	sta     ptr3
-	stx     ptr3+1                  ; Save the passed em_copy pointer
-
-	jsr     install_byte_transfer   ; install the stack copy routine
-
-	ldy     #EM_COPY::OFFS
-	lda     (ptr3),y
-	sta     STACK+15                 ; offset goes into BANK low 
-
-	ldy     #EM_COPY::PAGE
-	lda     (ptr3),y
-	sta     tmp1                    ; save page for later
-	;add     #>BANK
-	;sta     STACK+16                ; BANK + page goes into BANK high
-
-	ldy     #EM_COPY::BUF
-	lda     (ptr3),y
-	sta     STACK+7                ; buffer goes into dest low
-	iny
-	lda     (ptr3),y
-	sta     STACK+8                ; buffer goes into dest high
-
-	ldy     #EM_COPY::COUNT
-	lda     (ptr3),y                ; Get bytes in last page
-	sta     ptr4
-	iny
-	lda     (ptr3),y                ; Get number of pages
-	sta     ptr4+1
-
-	lda     tmp1                    ; extract bank/page
-	jsr     setpage                 ; sets curbank/curpage
-	lda     curpage
-	add     #>BANK                  ; add to BANK address
-	sta     STACK+16                ; current page in bank
-	ldx     curbank
-	lda     banks,x 
-	sta     STACK+10                ; set bank in stack 
-	lda     portb_save 
-	sta     STACK+2                 ; set bank restore in stack
-	sta     STACK+18                ; set final restore too
-
-copyto_copy:
-	lda     ptr4                    ; check if count is zero
-	bne     @4
-	lda     ptr4+1
-	beq     done
-
-@4:     jsr     STACK                   ; copy one byte
-
-	sec
-	lda     ptr4
-	sub     #1
-	sta     ptr4
-	bcs     @1
-	lda     ptr4+1
-	beq     @1
-	sub     #1
-	sta     ptr4+1
-
-@1:     inc     STACK+15               ; increment address in BANK
-	bne     @2
-	inc     STACK+16
-	lda     STACK+16
-	cmp     #$80                    ; we stepped outside bank
-	bne     @2
-
-	inc     curbank                 ; get next bank
-	ldx     curbank
-	lda     banks,x
-	sta     STACK+10                ; set new bank
-	lda     #$40                    ; set address back to $4000
-	sta     STACK+16
-
-@2:     inc     STACK+7                ; increment buffer address
-	bne     @3
-	inc     STACK+8
-
-@3:     jmp     copyto_copy           ; copy another byte 
-
diff --git a/libsrc/atari/atari-14.s b/libsrc/atari/atari-14.s
deleted file mode 100644
index ebd243067..000000000
--- a/libsrc/atari/atari-14.s
+++ /dev/null
@@ -1,84 +0,0 @@
-;
-; Graphics driver for the 160x192x2 (CIO mode 14, ANTIC mode C) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 14
-; X resolution
-	x_res = 160
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 2
-; Pixels per byte
-	ppb = 8
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0198				; based on 4/3 display
-; Free memory needed
-	mem_needed = 3305
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
-	masks:					; Color masks
-		.byte	%00000000, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
-	default_palette:
-		.byte	$00, $0E
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-15.s b/libsrc/atari/atari-15.s
deleted file mode 100644
index 08497db37..000000000
--- a/libsrc/atari/atari-15.s
+++ /dev/null
@@ -1,88 +0,0 @@
-;
-; Graphics driver for the 160x192x2 (CIO mode 15, ANTIC mode E) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 15
-; X resolution
-	x_res = 160
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 4
-; Pixels per byte
-	ppb = 4
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0198				; based on 4/3 display
-; Free memory needed
-	mem_needed = 7147
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11000000, %00110000, %00001100, %00000011
-	masks:					; Color masks
-		.byte	%00000000, %01010101, %10101010, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-	lda	palette + 2
-	sta	COLOR1
-	lda	palette + 3
-	sta	COLOR2
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-15p2.s b/libsrc/atari/atari-15p2.s
deleted file mode 100644
index a3cdd7726..000000000
--- a/libsrc/atari/atari-15p2.s
+++ /dev/null
@@ -1,88 +0,0 @@
-;
-; Graphics driver for the 160x192x2 (CIO mode 15, ANTIC mode E) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 15
-; X resolution
-	x_res = 160
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 4
-; Pixels per byte
-	ppb = 4
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0198				; based on 4/3 display
-; Free memory needed
-	mem_needed = 15339
-; Number of screen pages
-	pages = 2
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11000000, %00110000, %00001100, %00000011
-	masks:					; Color masks
-		.byte	%00000000, %01010101, %10101010, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-	lda	palette + 2
-	sta	COLOR1
-	lda	palette + 3
-	sta	COLOR2
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-3.s b/libsrc/atari/atari-3.s
deleted file mode 100644
index 24dca69de..000000000
--- a/libsrc/atari/atari-3.s
+++ /dev/null
@@ -1,88 +0,0 @@
-;
-; Graphics driver for the 40x24x4 (CIO mode 3, ANTIC mode 8) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 3
-; X resolution
-	x_res = 40
-; Y resolution
-	y_res = 24
-; Number of colors
-	colors = 4
-; Pixels per byte
-	ppb = 4
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 1
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11000000, %00110000, %00001100, %00000011
-	masks:					; Color masks
-		.byte	%00000000, %01010101, %10101010, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-	lda	palette + 2
-	sta	COLOR1
-	lda	palette + 3
-	sta	COLOR2
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-4.s b/libsrc/atari/atari-4.s
deleted file mode 100644
index 785e742e5..000000000
--- a/libsrc/atari/atari-4.s
+++ /dev/null
@@ -1,84 +0,0 @@
-;
-; Graphics driver for the 80x48x2 (CIO mode 4, ANTIC mode 9) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 4
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 48
-; Number of colors
-	colors = 2
-; Pixels per byte
-	ppb = 8
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 1
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
-	masks:					; Color masks
-		.byte	%00000000, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
-	default_palette:
-		.byte	$00, $0E
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-5.s b/libsrc/atari/atari-5.s
deleted file mode 100644
index c8c699753..000000000
--- a/libsrc/atari/atari-5.s
+++ /dev/null
@@ -1,88 +0,0 @@
-;
-; Graphics driver for the 80x48x4 (CIO mode 5, ANTIC mode A) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 5
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 48
-; Number of colors
-	colors = 4
-; Pixels per byte
-	ppb = 4
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 185
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11000000, %00110000, %00001100, %00000011
-	masks:					; Color masks
-		.byte	%00000000, %01010101, %10101010, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-	lda	palette + 2
-	sta	COLOR1
-	lda	palette + 3
-	sta	COLOR2
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-6.s b/libsrc/atari/atari-6.s
deleted file mode 100644
index 091b698d4..000000000
--- a/libsrc/atari/atari-6.s
+++ /dev/null
@@ -1,84 +0,0 @@
-;
-; Graphics driver for the 160x96x2 (CIO mode 6, ANTIC mode B) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 6
-; X resolution
-	x_res = 160
-; Y resolution
-	y_res = 96
-; Number of colors
-	colors = 2
-; Pixels per byte
-	ppb = 8
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 1193
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
-	masks:					; Color masks
-		.byte	%00000000, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
-	default_palette:
-		.byte	$00, $0E
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-7.s b/libsrc/atari/atari-7.s
deleted file mode 100644
index 95a05d4e8..000000000
--- a/libsrc/atari/atari-7.s
+++ /dev/null
@@ -1,88 +0,0 @@
-;
-; Graphics driver for the 160x96x4 (CIO mode 7, ANTIC mode D) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 7
-; X resolution
-	x_res = 160
-; Y resolution
-	y_res = 96
-; Number of colors
-	colors = 4
-; Pixels per byte
-	ppb = 4
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 3209
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11000000, %00110000, %00001100, %00000011
-	masks:					; Color masks
-		.byte	%00000000, %01010101, %10101010, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
-	default_palette:
-		.byte	$00, $0E, $32, $96
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR4
-	lda	palette + 1
-	sta	COLOR0
-	lda	palette + 2
-	sta	COLOR1
-	lda	palette + 3
-	sta	COLOR2
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-8.s b/libsrc/atari/atari-8.s
deleted file mode 100644
index fe97a5a0a..000000000
--- a/libsrc/atari/atari-8.s
+++ /dev/null
@@ -1,83 +0,0 @@
-;
-; Graphics driver for the 320x192x2 (CIO mode 8, ANTIC mode F) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 8
-; X resolution
-	x_res = 320
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 2
-; Pixels per byte
-	ppb = 8
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 7147
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
-	masks:					; Color masks
-		.byte	%00000000, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
-	default_palette:
-		.byte	$00, $0E
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR2
-	lda	palette + 1
-	sta	COLOR1
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-8p2.s b/libsrc/atari/atari-8p2.s
deleted file mode 100644
index 162aa4460..000000000
--- a/libsrc/atari/atari-8p2.s
+++ /dev/null
@@ -1,83 +0,0 @@
-;
-; Graphics driver for the 320x192x2 (CIO mode 8, ANTIC mode F) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 8
-; X resolution
-	x_res = 320
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 2
-; Pixels per byte
-	ppb = 8
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $00CC				; based on 4/3 display
-; Free memory needed
-	mem_needed = 15339
-; Number of screen pages
-	pages = 2
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
-	masks:					; Color masks
-		.byte	%00000000, %11111111
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
-	default_palette:
-		.byte	$00, $0E
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Copy the palette
-	ldy     #colors - 1
-loop:	lda     (ptr1),y
-	sta     palette,y
-	dey
-	bpl     loop
-
-	; Get the color entries from the palette
-	lda	palette
-	sta	COLOR2
-	lda	palette + 1
-	sta	COLOR1
-
-	; Done, reset the error code
-        lda     #TGI_ERR_OK
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-9.s b/libsrc/atari/atari-9.s
deleted file mode 100644
index 38e23702a..000000000
--- a/libsrc/atari/atari-9.s
+++ /dev/null
@@ -1,71 +0,0 @@
-;
-; Graphics driver for the 80x192x16b (CIO mode 9, ANTIC mode F, GTIA mode $40) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 9
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 16
-; Pixels per byte
-	ppb = 2
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0330				; based on 4/3 display
-; Free memory needed
-	mem_needed = 7147
-; Number of screen pages
-	pages = 1
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11110000, %00001111
-	masks:					; Color masks
-		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $aa, $bb, $cc, $dd, $ee, $ff
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00001111, %00000000
-	default_palette:
-		.byte	$00, $0F, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; No palettes
-        lda     #TGI_ERR_INV_FUNC
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-9p2.s b/libsrc/atari/atari-9p2.s
deleted file mode 100644
index f8418f112..000000000
--- a/libsrc/atari/atari-9p2.s
+++ /dev/null
@@ -1,71 +0,0 @@
-;
-; Graphics driver for the 80x192x16b (CIO mode 9, ANTIC mode F, GTIA mode $40) on the Atari.
-;
-; Fatih Aygun (2009)
-;
-
-	.include	"atari.inc"
-	.include 	"zeropage.inc"
-
-	.include 	"tgi-kernel.inc"
-	.include        "tgi-error.inc"
-
-	.macpack        generic
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Constants and tables
-	;
-	; ----------------------------------------------------------------------
-
-; Graphics mode
-	grmode = 9
-; X resolution
-	x_res = 80
-; Y resolution
-	y_res = 192
-; Number of colors
-	colors = 16
-; Pixels per byte
-	ppb = 2
-; Screen memory size in bytes
-	scrsize = x_res * y_res / ppb
-; Pixel aspect ratio
-	aspect = $0330				; based on 4/3 display
-; Free memory needed
-	mem_needed = 15339
-; Number of screen pages
-	pages = 2
-
-.rodata
-	mask_table:				; Mask table to set pixels
-		.byte	%11110000, %00001111
-	masks:					; Color masks
-		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $aa, $bb, $cc, $dd, $ee, $ff
-	bar_table:				; Mask table for BAR
-		.byte	%11111111, %00001111, %00000000
-	default_palette:
-		.byte	$00, $0F, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E
-
-.code
-
-; ******************************************************************************
-
-.proc SETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETPALETTE: Set the palette (in ptr1)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; No palettes
-        lda     #TGI_ERR_INV_FUNC
-        sta     error
-        rts
-.endproc
-
-.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/atari-multijoy.s b/libsrc/atari/atari-multijoy.s
deleted file mode 100644
index 863737beb..000000000
--- a/libsrc/atari/atari-multijoy.s
+++ /dev/null
@@ -1,115 +0,0 @@
-;
-; MultiJoy joystick driver for the Atari. May be used multiple times when linked
-; to the statically application.
-;
-; Ullrich von Bassewitz, 2002-12-21
-; Stefan Haubenthal, 2009-04-10
-; Using code from Carsten Strotmann and help from Christian Groessler
-;
-
-	.include	"zeropage.inc"
-
-	.include	"joy-kernel.inc"
-	.include	"joy-error.inc"
-	.include	"atari.inc"
-
-	.macpack	generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-; Driver signature
-
-	.byte	$6A, $6F, $79		; "joy"
-	.byte	JOY_API_VERSION		; Driver API version number
-
-; Button state masks (8 values)
-
-	.byte	$02			; JOY_UP
-	.byte	$04			; JOY_DOWN
-	.byte	$08			; JOY_LEFT
-	.byte	$10			; JOY_RIGHT
-	.byte	$01			; JOY_FIRE
-	.byte	$00			; JOY_FIRE2 not available
-	.byte	$00			; Future expansion
-	.byte	$00			; Future expansion
-
-; Jump table.
-
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	COUNT
-	.addr	READJOY
-	.addr	0			; IRQ entry not used
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT	= 8		; Number of joysticks we support
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-	lda	#$30
-	sta	PACTL
-	lda	#$F0
-	sta	PORTA
-	lda	#$34
-	sta	PACTL
-	lda	#JOY_ERR_OK
-	ldx	#0
-;	rts			; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-	rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-	lda	#JOY_COUNT
-	ldx	#0
-	rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READJOY:
-	asl	a
-	asl	a
-	asl	a
-	asl	a
-	sta	PORTA
-
-; Read joystick
-
-	lda	PORTA		; get position
-	and	#%00001111
-	asl	a
-	ora	TRIG0		; add button information
-	eor	#%00011111
-	ldx	#0		; fix X
-	rts
diff --git a/libsrc/atari/atari-stdjoy.s b/libsrc/atari/atari-stdjoy.s
deleted file mode 100644
index 53eff79fe..000000000
--- a/libsrc/atari/atari-stdjoy.s
+++ /dev/null
@@ -1,112 +0,0 @@
-;
-; Standard joystick driver for the Atari. May be used multiple times when linked
-; to the statically application.
-;
-; Ullrich von Bassewitz, 2002-12-21
-; Using the readjoy code from Christian Groessler
-;
-
-	.include	"zeropage.inc"
-
-	.include	"joy-kernel.inc"
-	.include	"joy-error.inc"
-	.include	"atari.inc"
-
-	.macpack	generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-; Driver signature
-
-	.byte	$6A, $6F, $79		; "joy"
-	.byte	JOY_API_VERSION		; Driver API version number
-
-; Button state masks (8 values)
-
-	.byte	$01			; JOY_UP
-	.byte	$02			; JOY_DOWN
-	.byte	$04			; JOY_LEFT
-	.byte	$08			; JOY_RIGHT
-	.byte	$10			; JOY_FIRE
-	.byte	$00			; JOY_FIRE2 not available
-	.byte	$00			; Future expansion
-	.byte	$00			; Future expansion
-
-; Jump table.
-
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	COUNT
-	.addr	READJOY
-	.addr	0			; IRQ entry not used
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT	= 4		; Number of joysticks we support
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-	lda	#JOY_ERR_OK
-	ldx	#0
-;	rts			; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-	rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-	lda	#JOY_COUNT
-	ldx	$fcd8
-	cpx	#$a2
-	beq	_400800
-	lsr	a		; XL and newer machines only have 2 ports
-_400800:
-	ldx	#0
-	rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READJOY:
-	and	#3		; fix joystick number
-	tax			; Joystick number (0-3) into X
-
-; Read joystick
-
-	lda	STRIG0,x	; get button
-	asl	a
-	asl	a
-	asl	a
-	asl	a
-	ora	STICK0,x	; add position information
-	eor	#$1F
-	ldx	#0		; fix X
-	rts
diff --git a/libsrc/atari/atari_tgi_common.inc b/libsrc/atari/atari_tgi_common.inc
deleted file mode 100644
index 9e9f74aa4..000000000
--- a/libsrc/atari/atari_tgi_common.inc
+++ /dev/null
@@ -1,1483 +0,0 @@
-;
-; Generic Atari graphics driver
-;
-
-.macpack longbranch
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Header. Includes jump table and constants.
-	;
-	; ----------------------------------------------------------------------
-
-.segment        "JUMPTABLE"
-
-; Header
-
-	.byte   $74, $67, $69		; "tgi"
-	.byte   TGI_API_VERSION		; TGI API version number
-	.word   x_res			; X resolution
-	.word   y_res			; Y resolution
-	.byte   colors			; Number of drawing colors
-	.byte   pages			; Number of screens available
-	.byte   8			; System font X size
-	.byte   8			; System font Y size
-	.word	aspect			; Aspect ratio
-        .byte   0                       ; TGI driver flags
-
-; Function table
-
-	.addr   INSTALL
-	.addr   UNINSTALL
-	.addr   INIT
-	.addr   DONE
-	.addr   GETERROR
-	.addr   CONTROL
-	.addr   CLEAR
-	.addr   SETVIEWPAGE
-	.addr   SETDRAWPAGE
-	.addr   SETCOLOR
-	.addr   SETPALETTE
-	.addr   GETPALETTE
-	.addr   GETDEFPALETTE
-	.addr   SETPIXEL
-	.addr   GETPIXEL
-	.addr   LINE
-	.addr   BAR
-	.addr   TEXTSTYLE
-	.addr   OUTTEXT
-	.addr   0			; IRQ entry is unused
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Parameters
-	;
-	; ----------------------------------------------------------------------
-
-	x1	:= ptr1
-	y1	:= ptr2
-	x2	:= ptr3
-	y2	:= ptr4
-	radius	:= tmp1
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Global variables
-	;
-	; ----------------------------------------------------------------------
-
-	sptr	:= regsave + 2
-
-.bss
-	error:
-		.res	1	; Error code
-
-.if ::grmode = 9 || ::grmode = 11
-	palette = default_palette
-.else
-	palette:
-		.res	colors	; The current palette
-.endif
-
-	mask:
-		.res	1	; Current pixel mask
-	griocb:
-		.res	1	; IOCB channel number for graphics
-
-.if pages = 2
-	p0scr:
-		.res	1	; High byte of screen address for screen page 0
-	p0dls:
-		.res	1	; High byte of display list address for screen page 0
-				; Page 1's addresses are 8K higher
-.endif
-
-.data
-	mag_x:
-		.byte	1	; Horizontal text scaling factor
-	mag_y:
-		.byte	1	; Vertical text scaling factor
-	mag_x8:
-		.word	8	; Horizontal text scaling factor * 8
-	mag_y8:
-		.word	8	; Vertical text scaling factor * 8
-	text_dir:
-		.byte	0	; Text direction,
-
-.code
-
-; ******************************************************************************
-
-.macro	put_pixel
-
-	; ----------------------------------------------------------------------
-	;
-	; Put a pixel at (sptr),y using x as the bit mask offset
-	;
-	; ----------------------------------------------------------------------
-
-	lda	(sptr),y
-	eor	mask
-	and	mask_table,x
-	eor	(sptr),y
-	sta	(sptr),y
-.endmacro
-
-; ******************************************************************************
-
-.rodata
-screen_device:
-	.byte "S:",$9B		; Device code for screen
-screen_device_length := * - screen_device
-
-.code
-
-.proc INIT
-
-	; ----------------------------------------------------------------------
-	;
-	; INIT: Switch to graphics mode
-	;
-	; ----------------------------------------------------------------------
-
-
-.code
-	; Initialize drawing color
-
-.if ::ppb = 8
-	ldx	#$FF
-.elseif ::ppb = 4
-	ldx	#$55
-.elseif ::ppb = 2
-	ldx	#$11
-.endif
-
-	stx	mask
-
-	; Find a free IOCB
-	lda	#$70
-search: tax
-	ldy	ICHID,x
-	cpy	#$FF
-	beq	found
-	sub	#$10
-	bcs	search
-
-	; Not enough resources available (free IOCB or memory)
-	; enter with C cleared!
-nores:	lda	#TGI_ERR_NO_RES
-	bcc	exit
-
-found:	; Check if enough RAM is available
-	lda	#0
-	sub	#mem_needed
-	cmp	APPMHI + 1
-	bcc	nores
-	bne	switch
-	cpy	APPMHI
-	bcc	nores			; not enough memory
-
-	; Switch into graphics mode
-switch:	lda	#OPEN
-	sta	ICCOM,x
-	lda	#OPNIN | OPNOT
-	sta	ICAX1,x
-	lda	#::grmode
-	sta	ICAX2,x
-	lda	#screen_device
-	sta	ICBAH,x
-	lda	#screen_device_length
-	sta	ICBLH,x
-	jsr	CIOV
-
-.if ::pages = 2
-	; Reserve 8K of high memory
-	lda	RAMTOP
-	sub	#32
-	sta	RAMTOP
-	; Close and reopen graphics
-	lda	#CLOSE
-	sta	ICCOM,x
-	jsr	CIOV
-	; Reopen graphics
-	lda	#OPEN
-	sta	ICCOM,x
-	lda	#OPNIN | OPNOT
-	sta	ICAX1,x
-	lda	#::grmode
-	sta	ICAX2,x
-	lda	#screen_device
-	sta	ICBAH,x
-	lda	#screen_device_length
-	sta	ICBLH,x
-	jsr	CIOV
-	; Save screen pointers
-	lda	SAVMSC + 1
-	sta	p0scr
-	lda	SDLSTH
-	sta	p0dls
-.endif ; ::pages = 2
-
-	stx	griocb
-
-	; Reset the error code and return
-        lda     #TGI_ERR_OK
-exit:	sta     error
-        rts
-.endproc
-
-; ******************************************************************************
-
-.proc DONE
-
-	; ----------------------------------------------------------------------
-	;
-	; DONE: Switch back to text mode
-	;
-	; ----------------------------------------------------------------------
-
-.code
-
-.if ::pages = 2
-	; Free 8K of high memory
-	lda	RAMTOP
-	add	#32
-	sta	RAMTOP
-.endif
-
-	; Clear griocb
-	lda	#$FF
-	ldx	griocb
-	sta	griocb
-
-	; Close the S: device
-	lda	#CLOSE
-	sta	ICCOM,x
-	jsr	CIOV
-
-	; Reopen it in Graphics 0
-	lda	#OPEN
-	sta	ICCOM,x
-	lda	#OPNIN | OPNOT
-	sta	ICAX1,x
-	lda	#0
-	sta	ICAX2,x
-	lda	#screen_device
-	sta	ICBAH,x
-	lda	#screen_device_length
-	sta	ICBLH,x
-	jsr	CIOV
-
-	; Now close it again; we don't need it anymore :)
-	lda	#CLOSE
-	sta	ICCOM,x
-	jmp	CIOV
-.endproc
-
-; ******************************************************************************
-
-.proc GETERROR
-
-	; ----------------------------------------------------------------------
-	;
-	; GETERROR: Return the error code in A and clear it
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	ldx	#TGI_ERR_OK
-	lda	error
-	stx	error
-	rts
-.endproc
-
-; ******************************************************************************
-
-.proc CLEAR
-
-	; ----------------------------------------------------------------------
-	;
-	; CLEAR: Clear the screen
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	; Load the screen address in sptr
-	lda	SAVMSC
-	sta	sptr
-	lda	SAVMSC + 1
-	sta	sptr + 1
-
-	; Fill with zero
-	lda	#0
-	tay
-
-.if >::scrsize > 0
-	; Clear full pages if any
-	ldx	#>::scrsize
-loop1:	sta	(sptr),y
-	iny
-	bne	loop1
-	inc	sptr + 1
-	dex
-	bne	loop1
-.endif
-
-.if <::scrsize > 0
-	; Clear the rest, if any
-loop2:	sta	(sptr),y
-	iny
-	cpy	#<::scrsize
-	bne	loop2
-.endif
-
-        rts
-.endproc
-
-; ******************************************************************************
-
-.proc GETPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; GETPALETTE: Return the current palette in A/X
-	;
-	; ----------------------------------------------------------------------
-
-.code
-        lda     #palette
-        rts
-.endproc
-
-; ******************************************************************************
-
-.proc GETDEFPALETTE
-
-	; ----------------------------------------------------------------------
-	;
-	; GETDEFPALETTE: Return the default palette in A/X
-	;
-	; ----------------------------------------------------------------------
-
-.code
-        lda     #default_palette
-        rts
-.endproc
-
-; ******************************************************************************
-
-.proc SETCOLOR
-
-	; ----------------------------------------------------------------------
-	;
-	; SETCOLOR: Set the drawing color (in A)
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	tax
-
-.if ::grmode = 9
-	; Map colors like this: 0 -> 0, 1 -> 15, 2 -> 1, 3 -> 2 etc.
-	beq	cont
-	cpx	#1
-	bne	map
-	ldx	#16
-map:	dex
-cont:
-.endif
-
-	lda	masks,x
-	sta	mask
-	rts
-.endproc
-
-; ******************************************************************************
-
-.proc CALC
-
-	; ----------------------------------------------------------------------
-	;
-	; CALC: Calculate the screen address
-	;	in
-	;		x1 (ptr1)	x coordinate
-	;		y1 (ptr2)	y coordinate
-	;	out
-	;		sptr + y	screen address
-	;		x		bit mask index
-	;
-	; ----------------------------------------------------------------------
-
-.bss
-	temp:	.res	1
-.code
-	; calculate line offset
-	lda	y1 + 1
-	sta	temp
-	lda	y1
-
-.if ::x_res / ::ppb = 40
-	yrep = 3
-.elseif ::x_res / ::ppb = 20
-	yrep = 2
-.elseif ::x_res / ::ppb = 10
-	yrep = 1
-.endif
-
-.repeat	yrep
-	asl	a
-	rol	temp
-.endrepeat
-
-	sta	sptr
-	ldx	temp
-	stx	sptr + 1
-
-.repeat	2
-	  asl	a
-	  rol	temp
-.endrepeat
-
-	add	sptr
-	sta	sptr
-	lda	temp
-	adc	sptr + 1
-	sta	sptr + 1
-
-	; calculate bit mask offset
-	lda	x1
-	and	#ppb - 1
-	tax
-
-	; calculate row offset
-	lda	x1 + 1
-	sta	temp
-	lda	x1
-
-.if ::ppb = 8
-	xrep = 3
-.elseif ::ppb = 4
-	xrep = 2
-.elseif ::ppb = 2
-	xrep = 1
-.endif
-
-.repeat	xrep
-	lsr	temp
-	ror	a
-.endrepeat
-
-	tay
-
-	; sptr += SAVMSC
-	lda	SAVMSC
-	add	sptr
-	sta	sptr
-	lda	SAVMSC + 1
-	adc	sptr + 1
-	sta	sptr + 1
-
-	; We're done!
-	rts
-.endproc
-
-; ******************************************************************************
-
-.proc SETPIXEL
-
-	; ----------------------------------------------------------------------
-	;
-	; Draw one pixel at x1, y1
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	jsr	CALC
-	put_pixel
-	rts
-.endproc
-
-; ******************************************************************************
-
-.proc GETPIXEL
-
-	; ----------------------------------------------------------------------
-	;
-	; GETPIXEL: Read the color value of a pixel and return it in A/X
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	jsr	CALC
-	lda	(sptr),y
-	and	mask_table,x
-
-.if ::ppb = 8
-	beq	zero
-	lda	#1
-zero:	ldx	#0
-	rts
-.elseif ::ppb = 4
-loop:	cpx	#3
-	beq	done4
-	lsr	a
-	lsr	a
-	inx
-	bne	loop
-done4:	and	#$03
-	ldx	#0
-	rts
-.elseif ::ppb = 2
-	dex
-	bne	shift
-	and	#$0F
-	jmp	exit
-shift:	lsr	a
-	lsr	a
-	lsr	a
-	lsr	a
-
-exit:
-
-.if ::grmode = 9
-	; Mode 9 mapping
-	; Map colors like this: 0 -> 0, 15 -> 1, 2 -> 3, 3 -> 4 etc.
-	beq	done9
-	cmp	#15
-	bne	map9
-	lda	#0
-map9:	add	#1
-done9:
-.endif
-
-.if ::grmode = 10
-	; Mode 10 mapping
-	; Map out of range colors like this:
-	;  9 -> 8
-	; 10 -> 8
-	; 11 -> 8
-	; 12 -> 0
-	; 13 -> 1
-	; 14 -> 2
-	; 15 -> 3
-	cmp	#9
-	bcc	done10
-	sub	#12
-	bcs	done10
-	lda	#8
-done10:
-.endif ; ::grmode = 10
-
-	; Done!
-	ldx	#0
-	rts
-.endif	; ::ppb = 2
-
-.endproc
-
-; ******************************************************************************
-
-.proc LINE
-
-	; ----------------------------------------------------------------------
-	;
-	; LINE: Draw a line from x1,y1 to x2,y2
-	;
-	; ----------------------------------------------------------------------
-
-.ifdef USE_CIO_LINE
-
-	; position ptr1, ptr2
-	lda	x1
-	sta	OLDCOL
-	lda	x1 + 1
-	sta	OLDCOL + 1
-	lda	y1
-	sta	OLDROW
-	; plot
-	jsr	SETPIXEL
-	; position ptr3,ptr4
-	lda	x2
-	sta	COLCRS
-	lda	x2 + 1
-	sta	COLCRS + 1
-	lda	y2
-	sta	ROWCRS
-	; drawto
-	ldx	griocb
-	lda	#DRAWLN
-	sta	ICCOM,x
-	lda	mask
-
-.if ::grmode = 10
-	and	#$0f
-.else
-	and	#colors - 1
-.endif
-
-	sta	ATACHR
-	jmp	CIOV
-
-.else	; USE_CIO_LINE
-
-; locals
-
-	dx	:=	sreg
-	dy	:=	y1
-	dx2	:=	x2
-	dy2	:=	y2
-	iy	:=	tmp1
-	err	:=	tmp3
-
-.code
-	; dx = x2 - x1
-	lda	x2
-	sub	x1
-	sta	dx
-	lda	x2 + 1
-	sbc	x1 + 1
-	sta	dx + 1
-	; if dx is positive, no problem
-	bcs	dx_positive
-
-	; if dx is negative, swap x1,y1 with x2,y2
-	lda	x1	; x1 <-> x2, low byte
-	ldx	x2
-	sta	x2
-	stx	x1
-	lda	x1 + 1	; x1 <-> x2, high byte
-	ldx	x2 + 1
-	sta	x2 + 1
-	stx	x1 + 1
-	lda	y1	; y1 <-> y2, low byte
-	ldx	y2
-	sta	y2
-	stx	y1
-	lda	y1 + 1	; y1 <-> y2, high byte
-	ldx	y2 + 1
-	sta	y2 + 1
-	stx	y1 + 1
-	; Calculate again
-	jmp	LINE
-
-dx_positive:
-	; Calculate coords
-	jsr	CALC
-
-	; dy = y2 - y1
-	lda	y2
-	sub	y1
-	sta	dy
-	lda	y2 + 1
-	sbc	y1 + 1
-	sta	dy + 1
-
-	; if dy is negative
-	bcs	dy_positive
-	; dy = -dy
-	lda	#0
-	sub	dy
-	sta	dy
-	lda	#0
-	sbc	dy + 1
-	sta	dy + 1
-	; iy = -row_size
-	lda	#<(65536 - x_res / ppb)
-	sta	iy
-	lda	#>(65536 - x_res / ppb)
-	sta	iy + 1
-	bne	skip_iy_1		; always
-
-dy_positive:
-	; iy = row_size
-	lda	#<(x_res / ppb)
-	sta	iy
-	lda	#>(x_res / ppb)
-	sta	iy + 1
-skip_iy_1:
-
-	; dx2 = dx * 2
-	lda	dx
-	asl	a
-	sta	dx2
-	lda	dx + 1
-	rol	a
-	sta	dx2 + 1
-
-	; dy2 = dy * 2
-	lda	dy
-	asl	a
-	sta	dy2
-	lda	dy + 1
-	rol	a
-	sta	dy2 + 1
-
-	; if dx >= dy
-	lda	dx
-	cmp	dy
-	lda	dx + 1
-	sbc	dy + 1
-	bcc	dy_major
-
-	; dx is the major axis
-
-	; err = dy2 - dx
-	lda	dy2
-	sub	dx
-	sta	err
-	lda	dy2 + 1
-	sbc	dx + 1
-	sta	err + 1
-
-	.scope
-loop:	; main loop
-	put_pixel
-	; if err >= 0
-	lda	err + 1
-	bmi	err_neg
-	; err -= dx2
-	lda	err
-	sub	dx2
-	sta	err
-	lda	err + 1
-	sbc	dx2 + 1
-	sta	err + 1
-	; move_vertical (iy)
-	lda	sptr
-	add	iy
-	sta	sptr
-	lda	sptr + 1
-	adc	iy + 1
-	sta	sptr + 1
-err_neg:
-	; err += dy2
-	lda	err
-	add	dy2
-	sta	err
-	lda	err + 1
-	adc	dy2 + 1
-	sta	err + 1
-	; move_right
-	inx
-	cpx	#ppb
-	bne	end_move
-	ldx	#0
-	iny
-	bne	end_move
-	inc	sptr + 1
-end_move:
-	; loop while dx-- >= 0
-	lda	dx
-	ora	dx + 1
-	beq	exit
-	dec	dx
-	lda	dx
-	cmp	#$FF
-	bne	loop
-	dec	dx + 1
-	jmp	loop
-exit:	rts
-	.endscope
-
-dy_major:
-	; dy is the major axis
-
-	; err = dx2 - dy;
-	lda	dx2
-	sub	dy
-	sta	err
-	lda	dx2 + 1
-	sbc	dy + 1
-	sta	err + 1
-
-	.scope
-loop:	; main loop
-	put_pixel
-	; if err >= 0
-	lda	err + 1
-	bmi	end_move
-	; err -= dy2
-	lda	err
-	sub	dy2
-	sta	err
-	lda	err + 1
-	sbc	dy2 + 1
-	sta	err + 1
-	; move_right
-	inx
-	cpx	#ppb
-	bne	end_move
-	ldx	#0
-	iny
-	bne	end_move
-	inc	sptr + 1
-end_move:
-	; err += dx2
-	lda	err
-	add	dx2
-	sta	err
-	lda	err + 1
-	adc	dx2 + 1
-	sta	err + 1
-	; move_vertical(iy)
-	lda	sptr
-	add	iy
-	sta	sptr
-	lda	sptr + 1
-	adc	iy + 1
-	sta	sptr + 1
-	; loop while dy-- >= 0
-	lda	dy
-	ora	dy + 1
-	beq	exit
-	dec	dy
-	lda	dy
-	cmp	#$FF
-	bne	loop
-	dec	dy + 1
-	jmp	loop
-exit:	rts
-	.endscope
-.endif	; USE_CIO_LINE
-.endproc
-
-; ******************************************************************************
-
-.proc clipped_bar
-
-	; ----------------------------------------------------------------------
-	;
-	; Clip and draw bar, this function will disappear when text clipping
-	; will be done int the TGI kernel
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	lda	y1 + 1
-	bne	off
-	lda	y1
-	cmp	#y_res
-	bcs	off
-
-	lda	x1 + 1
-
-.if >(::x_res - 1) > 0
-	cmp	#>x_res
-	bcc	check2
-.endif
-
-	bne	off
-	lda	x1
-	cmp	#(::x_res - 1) > 0
-	cmp	#>x_res
-	bcc	BAR
-.endif
-
-	bne	off
-	lda	x2
-	cmp	#(::x_res - 1) > 0
-	lda	x2 + 1
-	sta	x1 + 1
-.endif
-
-	jsr	CALC
-	; Save the values
-	tya
-	add	sptr
-	sta	sptr
-	bcc	skips
-	inc	sptr + 1
-skips:	inx
-	lda	bar_table,x
-	eor	#$FF
-	sta	rmask
-	; Calculate memory difference between x1 and x2
-	lda	sptr
-	sub	lmem
-	sta	dx
-loop:	; Main loop
-	ldy	#0
-	ldx	dx
-	beq	same
-	; Left
-	lda	(lmem),y
-	eor	mask
-	and	lmask
-	eor	(lmem),y
-	sta	(lmem),y
-	iny
-	; Between
-	lda	mask
-	jmp	next
-btwn:	sta	(lmem),y
-	iny
-next:	dex
-	bne	btwn
-	; Right
-	lda	(lmem),y
-	eor	mask
-	and	rmask
-	eor	(lmem),y
-	sta	(lmem),y
-	jmp	cont
-same:	; Same byte
-	lda	lmask
-	and	rmask
-	sta	fmask
-	lda	(lmem),y
-	eor	mask
-	and	fmask
-	eor	(lmem),y
-	sta	(lmem),y
-cont:	; Go to next row
-	lda	lmem
-	add	#<(x_res / ppb)
-	sta	lmem
-	bcc	skipm
-	inc	lmem + 1
-skipm:	; Loop while --dy > 0
-	dec	dy
-	bne	loop
-
-	rts
-
-.endproc
-
-; ******************************************************************************
-
-.proc TEXTSTYLE
-
-	; ----------------------------------------------------------------------
-	;
-	; TEXTSTYLE: Set text style. Scale factors in X and Y and direction in A
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	stx	mag_x
-	sty     mag_y
-	; Save text direction in bit 8 so that we can use BIT instruction later
-	lsr	a
-	ror	a
-	sta     text_dir
-	; Save 8 * scaling factors
-	lda	#0
-	sta	mag_x8 + 1
-	sta	mag_y8 + 1
-	; Save 8 * mag_x
-	txa
-
-	.repeat	3
-	asl	a
-	rol	mag_x8 + 1
-	.endrepeat
-
-	sta	mag_x8
-	; Save 8 * mag_y
-	tya
-
-	.repeat	3
-	asl	a
-	rol	mag_y8 + 1
-	.endrepeat
-
-	sta	mag_y8
-	; Done!
-	rts
-.endproc
-
-; ******************************************************************************
-
-.proc OUTTEXT
-
-	; ----------------------------------------------------------------------
-	;
-	; OUTTEXT: Draw text at x1, y1. String is in ptr3
-	;
-	; ----------------------------------------------------------------------
-
-; locals
-	string	:= tmp1
-	cols	:= tmp3
-	pixels	:= tmp4
-	font	:= regsave
-.rodata
-	ataint:	.byte	64,0,32,96
-.bss
-	rows:	.res	1
-
-.if >(::x_res - 1) > 0
-	oldx1:	.res	2
-	oldx2:	.res	2
-.else
-	oldx1:	.res	1
-	oldx2:	.res	1
-.endif
-
-	oldy1:	.res	1
-	oldy2:	.res	1
-	inv:	.res	1
-
-.code
-	; Don't draw zero sized characters
-	lda	mag_x
-	ora	mag_y
-	bne	not0
-	rts
-
-not0:	; Save string address, ptr3 is needed by BAR
-	lda	ptr3
-	sta	string
-	lda	ptr3 + 1
-	sta	string + 1
-
-	bit	text_dir
-	bmi	vert
-
-	; Calculate x2
-	lda	mag_x
-	sub	#1
-	add	x1
-	sta	x2
-
-.if >(::x_res - 1) > 0
-	lda	x1 + 1
-	adc	#0
-	sta	x2 + 1
-.else
-	lda	#0
-	sta	x2 + 1
-.endif
-
-	; Calculate y2 and adjust y1
-	dec	y1
-	lda	y1
-	sta	y2
-	sub	mag_y
-	add	#1
-	sta	y1
-	lda	#0
-	sta	y2 + 1
-
-	jmp	while
-
-	; Calculate for vertical text
-vert:	lda	x1
-	sub	#1
-	sta	x2
-	lda	x1 + 1
-	sbc	#0
-	sta	x2 + 1
-	lda	x1
-	sub	mag_y
-	sta	x1
-	lda	x1 + 1
-	sbc	#0
-	sta	x1 + 1
-
-	lda	mag_x
-	sub	#1
-	add	y1
-	sta	y2
-	lda	#0
-	sta	y2 + 1
-	jmp	while
-
-	; Main loop
-loop:	inc	string
-	bne	skiph
-	inc	string + 1
-skiph:	; Save coords
-	bit	text_dir
-	bmi	scvert
-
-	ldx	y1
-	stx	oldy1
-	ldx	y2
-	stx	oldy2
-	jmp	draw
-
-scvert:	ldx	x1
-	stx	oldx1
-	ldx	x2
-	stx	oldx2
-
-.if >(::x_res - 1) > 0
-	ldx	x1 + 1
-	stx	oldx1 + 1
-	ldx	x2 + 1
-	stx	oldx2 + 1
-.endif
-
-	; Draw one character
-	; Convert to ANTIC code
-draw:	tay
-	rol	a
-	rol	a
-	rol	a
-	rol	a
-	and	#3
-	tax
-	tya
-	and	#$9f
-	ora	ataint,x
-	; Save and clear inverse video bit
-	sta	inv
-	and	#$7F
-	; Calculate font data address
-	sta	font
-	lda	#0
-	sta	font + 1
-
-	.repeat 3
-	asl	font
-	rol	a
-	.endrepeat
-
-	adc	CHBAS
-	sta	font + 1
-	; Save old coords
-	bit	text_dir
-	bpl	hor
-	lda	y1
-	sta	oldy1
-	lda	y2
-	sta	oldy2
-	jmp	cont
-hor:	lda	x1
-	sta	oldx1
-	lda	x2
-	sta	oldx2
-
-.if >(::x_res - 1) > 0
-	lda	x1 + 1
-	sta	oldx1 + 1
-	lda	x2 + 1
-	sta	oldx2 + 1
-.endif
-
-	; Get glyph pixels
-cont:	ldy	#7
-	; Put one row of the glyph
-putrow:	sty	rows
-	lda	(font),y
-	bit	inv
-	bpl	noinv
-	eor	#$FF
-noinv:	sta	pixels
-	lda	#7
-	sta	cols
-	; Put one column of the row
-putcol:	asl	pixels
-	bcc	next_col
-	lda	x1
-	pha
-	lda	x1 + 1
-	pha
-	jsr	clipped_bar
-	pla
-	sta	x1 + 1
-	pla
-	sta	x1
-next_col:
-	; Go to next column
-	; increase x coords
-	bit	text_dir
-	bmi	vertinc
-
-	lda	mag_x
-	add	x1
-	sta	x1
-	bcc	L1
-	inc	x1 + 1
-L1:	lda	mag_x
-	add	x2
-	sta	x2
-	bcc	L2
-	inc	x2 + 1
-	jmp	L2
-
-vertinc:
-	lda	y1
-	sub	mag_x
-	sta	y1
-	lda	y2
-	sub	mag_x
-	sta	y2
-L2:
-	dec	cols
-	bpl	putcol
-next_row:
-	; Go to next row
-	bit	text_dir
-	bmi	verty
-
-	lda	y1
-	sub	mag_y
-	sta	y1
-	bcs	L3
-	dec	y1 + 1
-L3:	lda	y2
-	sub	mag_y
-	sta	y2
-	bcs	L6
-	dec	y2 + 1
-L4:	jmp	L6
-
-verty:	lda	x1
-	sub	mag_y
-	sta	x1
-	bcs	L5
-	dec	x1 + 1
-L5:	lda	x2
-	sub	mag_y
-	sta	x2
-	bcs	L6
-	dec	x2 + 1
-L6:
-	; Restore old values
-	bit	text_dir
-	bpl	reshor
-	lda	oldy1
-	sta	y1
-	lda	oldy2
-	sta	y2
-	jmp	nextrow
-reshor:	lda	oldx1
-	sta	x1
-	lda	oldx2
-	sta	x2
-
-.if >(::x_res - 1) > 0
-	lda	oldx1 + 1
-	sta	x1 + 1
-	lda	oldx2 + 1
-	sta	x2 + 1
-.endif
-
-	; Next row
-nextrow:
-	ldy	rows
-	dey
-	jpl	putrow
-
-	; Restore coords
-	bit	text_dir
-	bmi	resvert
-
-	ldx	oldy1
-	stx	y1
-	ldx	oldy2
-	stx	y2
-	ldx	#0
-	stx	y1 + 1
-	stx	y2 + 1
-
-	lda	mag_x8
-	add	x1
-	sta	x1
-	lda	mag_x8 + 1
-	adc	x1 + 1
-	sta	x1 + 1
-	lda	mag_x8
-	add	x2
-	sta	x2
-	lda	mag_x8 + 1
-	adc	x2 + 1
-	sta	x2 + 1
-
-	jmp	while
-
-resvert:
-	ldx	oldx1
-	stx	x1
-	ldx	oldx2
-	stx	x2
-
-.if >(::x_res - 1) > 0
-	ldx	oldx1 + 1
-	stx	x1 + 1
-	ldx	oldx2 + 1
-	stx	x2 + 1
-.endif
-
-	lda	y1
-	sub	mag_x8
-	sta	y1
-	lda	y1 +1
-	sbc	mag_x8 + 1
-	sta	y1 + 1
-	lda	y2
-	sub	mag_x8
-	sta	y2
-	lda	y2 +1
-	sbc	mag_x8 + 1
-	sta	y2 + 1
-
-	; End of loop
-while:	ldy	#0
-	lda	(string),y
-	jne	loop		; Check for null character
-	rts
-
-.endproc
-
-.if pages = 2
-; ******************************************************************************
-
-.proc SETVIEWPAGE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETVIEWPAGE, page in A
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	tax
-	beq	cont
-	lda	#32
-
-cont:	add	p0dls
-	cmp	SDLSTH
-	beq	done		; We're already in the desired page
-
-	ldx	RTCLOK + 2
-	sta	SDLSTH
-
-	; Wait until next VBLANK
-wait:	cpx	RTCLOK + 2
-	beq	wait
-
-	; Done
-done:	rts
-.endproc
-
-; ******************************************************************************
-
-.proc SETDRAWPAGE
-
-	; ----------------------------------------------------------------------
-	;
-	; SETDRAWPAGE, page in A
-	;
-	; ----------------------------------------------------------------------
-
-.code
-	tax
-	beq	cont
-	lda	#32
-cont:	add	p0scr
-	sta	SAVMSC + 1
-	rts
-.endproc
-.endif
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Unimplemented functions that require an error code
-	;
-	; ----------------------------------------------------------------------
-
-CONTROL:
-	lda	#TGI_ERR_INV_FUNC
-	sta	error
-	; fall through
-
-; ******************************************************************************
-
-	; ----------------------------------------------------------------------
-	;
-	; Unimplemented functions that don't require an error code
-	;
-	; ----------------------------------------------------------------------
-
-INSTALL:
-UNINSTALL:
-
-.if pages = 1
-SETVIEWPAGE:
-SETDRAWPAGE:
-.endif
-
-        rts
diff --git a/libsrc/atari/emd/atr130xe.s b/libsrc/atari/emd/atr130xe.s
new file mode 100644
index 000000000..6951bd346
--- /dev/null
+++ b/libsrc/atari/emd/atr130xe.s
@@ -0,0 +1,483 @@
+;
+; Extended memory driver for the Atari 130XE memory standard
+; Shawn Jefferson, 2012-08-11
+;
+; Banking Register $D301:
+; Bit 7: Self-Test on/off
+; Bit 6: Unused
+; Bit 5: Antic sees bank
+; Bit 4: CPU sees bank
+; Bit 3: bank control
+; Bit 2: bank control
+; Bit 1: BASIC on/off
+; Bit 0: OS RAM on/off
+; 
+; Masks: %11100011  $E3     Bank 0
+;        %11100111  $E7     Bank 1
+;        %11101011  $EB     Bank 2
+;        %11101111  $EF     Bank 3
+;        %11111111  $FF     Off
+;
+; Based on the Extended memory driver for the Apple II auxiliary memory
+;  by
+; Stefan Haubenthal, 2003-12-12
+; Ullrich von Bassewitz, 2002-12-02
+;
+
+	.include        "zeropage.inc"
+
+	.include        "em-kernel.inc"
+	.include        "em-error.inc"
+
+
+	.macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+	.byte   $65, $6d, $64           ; "emd"
+	.byte   EMD_API_VERSION         ; EM API version number
+
+; Jump table.
+
+	.word   INSTALL
+	.word   DEINSTALL
+	.word   PAGECOUNT
+	.word   MAP
+	.word   USE
+	.word   COMMIT
+	.word   COPYFROM
+	.word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+BANK    = $4000                         ; bank window
+STACK   = $0100                         ; stack location 
+PAGES   = 256                           ; 4 x 16k banks
+
+
+; ------------------------------------------------------------------------
+; Data.
+
+.rodata
+banks:          .byte $E3,$E7,$EB,$EF   ; 130XE banks for cpu banking
+
+stacktest:      sei
+		ldy banks
+		sty $D301
+		tax                     ; A is set by caller
+		inx
+		stx $4000               ; change $4000
+		ldy #$FF                ; STACK+13
+		sty $D301
+		cmp $4000               ; changed?
+		beq @1
+		sec                     ; error
+		bcs @2
+@1:             clc
+@2:             sta $4000               ; restore
+		cli
+		rts
+stacktest_end: 
+
+stackcopy:      sei                     ; disable interrupts
+@1:             dex                     ; pre-decrement (full page x=0)
+		ldy #$FF                ; this will be replaced  STACK+3
+		sty $D301               ; set bank 
+		lda $FF00,x             ; address to copy from   STACK+8,+9
+		ldy #$FF                ; this will be replaced  STACK+11
+		sty $D301 
+		sta $FF00,x             ; address to copy to     STACK+16,+17
+		cpx #0 
+		bne @1
+		ldy #$FF                ; portb_save             STACK+23
+		sty $D301
+		cli                     ; enable interrupts
+		rts
+stackcopy_end:
+
+stackcopy_byte: sei
+		ldy #$FF                ; STACK+2
+		sty $D301
+		lda $FFFF               ; STACK+7 +8
+		ldy #$FF                ; STACK+10
+		sty $D301
+		sta $FFFF               ; STACK+15 +16
+		ldy #$FF                ; STACK+18
+		sty $D301
+		cli
+		rts
+stackcopy_byte_end: 
+
+
+.data
+curpage:        .byte   $FF             ; Current page number in bank (invalid)
+curbank:        .byte   $FF             ; Current bank number
+
+.bss
+window:         .res    256             ; Memory "window"
+portb_save:     .res    1               ; portb state
+
+.code
+
+install_transfer:
+		ldx #stackcopy_end - stackcopy - 1
+@1:             lda stackcopy,x
+		sta STACK,x
+		dex
+		bpl @1
+		rts
+
+install_byte_transfer:
+		ldx #stackcopy_byte_end - stackcopy_byte - 1
+@2:             lda stackcopy_byte,x
+		sta STACK,x
+		dex
+		bpl @2
+		rts
+
+install_test:
+		ldx #stacktest_end - stacktest - 1
+@3:             lda stacktest,x
+		sta STACK,x
+		dex
+		bpl @3
+		rts
+
+setpage:
+		tax                             ; save page
+		and     #$C0                    ; mask out bank
+		clc
+		ror
+		ror                             ; divide by 64
+		ror                             ; 64 pages in each bank
+		ror
+		ror
+		ror
+		sta     curbank                 ; Remember the new bank
+		txa                             ; bring back page
+		and     #$3F                    ; mask out page
+		sta     curpage                 ; curpage in bank
+		rts
+
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+	lda     $D301                   ; save state of portb
+	sta     portb_save
+	tay 
+
+	jsr     install_test            ; doesn't touch Y
+	sty     STACK+13
+
+	lda     $4000                   ; test for extended memory
+	jsr     STACK
+	bcs     @1 
+	lda     #EM_ERR_OK
+	rts
+@1:     lda     #EM_ERR_NO_DEVICE
+	rts
+
+; ------------------------------------------------------------------------
+; DEINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+DEINSTALL:
+	rts
+
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+	lda     #PAGES
+	rts
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:    jsr setpage                     ; extract the bank/page
+	add     #>BANK                  ; $4000 + page  (carry is cleared)
+	sta     ptr1+1
+	;ldy     #$00
+	;sty     ptr1
+
+	lda     #window
+	sta     ptr2+1
+
+; Transfer one page
+
+	jsr     install_transfer        ; Transfer one page
+
+	ldx     curbank
+	lda     banks,x
+	sta     STACK+3                 ; set bank to copy from
+;        lda     ptr1
+;        sta     STACK+8 
+	lda     ptr1+1
+	sta     STACK+9                 ; set copy from address
+	lda     portb_save
+	sta     STACK+11                ; set portb restore
+	sta     STACK+23                ; set final portb restore
+	lda     ptr2
+	sta     STACK+16
+	lda     ptr2+1
+	sta     STACK+17                ; set copy to address 
+
+	ldx     #0                      ; full page copy
+	jsr     STACK                   ; do the copy! 
+
+; Return the memory window
+
+	lda     #window                ; Return the window address
+
+	rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:    ;sta     curpage                 ; Remember the page
+	jsr setpage                     ; extract bank/page
+	lda     #window                ; Return the window
+	rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: lda     curpage                 ; Get the current page
+	cmp     #$FF
+	beq     commit_done             ; Jump if no page mapped
+
+	clc
+	add     #>BANK
+	sta     ptr2+1
+	;ldy     #$00
+	;sty     ptr2
+
+	lda     #window
+	sta     ptr1+1
+
+; Transfer one page/all bytes
+
+	jsr     install_transfer        ; Transfer one page
+
+	lda     portb_save
+	sta     STACK+3                 ; set bank to copy from
+	sta     STACK+23                ; set final portb restore
+	lda     ptr1
+	sta     STACK+8 
+	lda     ptr1+1
+	sta     STACK+9                 ; set copy from address
+	ldx     curbank
+	lda     banks,x
+	sta     STACK+11                ; set bank to copy to
+	;lda     ptr2
+	;sta     STACK+16
+	lda     ptr2+1
+	sta     STACK+17                ; set copy to address 
+
+	ldx     #0                      ; full page copy
+	jsr     STACK                   ; do the copy! 
+
+commit_done:
+	rts
+
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+COPYFROM:
+	sta     ptr3
+	stx     ptr3+1                  ; Save the passed em_copy pointer
+
+	jsr     install_byte_transfer   ; install the stack copy routine
+
+	ldy     #EM_COPY::OFFS
+	lda     (ptr3),y
+	sta     STACK+7                 ; offset goes into BANK low 
+
+	ldy     #EM_COPY::PAGE
+	lda     (ptr3),y
+	sta     tmp1                    ; save page for later
+	;add     #>BANK
+	;sta     STACK+8                 ; BANK + page goes into BANK high
+
+	ldy     #EM_COPY::BUF
+	lda     (ptr3),y
+	sta     STACK+15                ; buffer goes into dest low
+	iny
+	lda     (ptr3),y
+	sta     STACK+16                ; buffer goes into dest high
+
+	ldy     #EM_COPY::COUNT
+	lda     (ptr3),y                ; Get bytes in last page
+	sta     ptr4
+	iny
+	lda     (ptr3),y                ; Get number of pages
+	sta     ptr4+1
+
+	lda     tmp1                    ; extract bank/page
+	jsr     setpage                 ; sets curbank/curpage
+	lda     curpage
+	add     #>BANK                  ; add to BANK address
+	sta     STACK+8                 ; current page in bank
+	ldx     curbank
+	lda     banks,x 
+	sta     STACK+2                 ; set bank in stack 
+	lda     portb_save 
+	sta     STACK+10                ; set bank restore in stack
+	sta     STACK+18                ; set final restore too
+
+copyfrom_copy:
+	lda     ptr4                    ; check if count is zero
+	bne     @4
+	lda     ptr4+1
+	beq     done
+
+@4:     jsr     STACK                   ; copy one byte
+
+	sec
+	lda     ptr4
+	sub     #1
+	sta     ptr4
+	bcs     @1
+	lda     ptr4+1
+	beq     @1
+	sub     #1
+	sta     ptr4+1
+
+@1:     inc     STACK+7                 ; increment address in BANK
+	bne     @2
+	inc     STACK+8
+	lda     STACK+8
+	cmp     #$80                    ; we stepped outside bank
+	bne     @2
+
+	inc     curbank                 ; get next bank
+	ldx     curbank
+	lda     banks,x
+	sta     STACK+2                 ; set new bank
+	lda     #$40                    ; set address back to $4000
+	sta     STACK+8
+
+@2:     inc     STACK+15                ; increment buffer address
+	bne     @3
+	inc     STACK+16
+
+@3:     jmp     copyfrom_copy           ; copy another byte 
+
+done:
+	rts
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO:
+	sta     ptr3
+	stx     ptr3+1                  ; Save the passed em_copy pointer
+
+	jsr     install_byte_transfer   ; install the stack copy routine
+
+	ldy     #EM_COPY::OFFS
+	lda     (ptr3),y
+	sta     STACK+15                 ; offset goes into BANK low 
+
+	ldy     #EM_COPY::PAGE
+	lda     (ptr3),y
+	sta     tmp1                    ; save page for later
+	;add     #>BANK
+	;sta     STACK+16                ; BANK + page goes into BANK high
+
+	ldy     #EM_COPY::BUF
+	lda     (ptr3),y
+	sta     STACK+7                ; buffer goes into dest low
+	iny
+	lda     (ptr3),y
+	sta     STACK+8                ; buffer goes into dest high
+
+	ldy     #EM_COPY::COUNT
+	lda     (ptr3),y                ; Get bytes in last page
+	sta     ptr4
+	iny
+	lda     (ptr3),y                ; Get number of pages
+	sta     ptr4+1
+
+	lda     tmp1                    ; extract bank/page
+	jsr     setpage                 ; sets curbank/curpage
+	lda     curpage
+	add     #>BANK                  ; add to BANK address
+	sta     STACK+16                ; current page in bank
+	ldx     curbank
+	lda     banks,x 
+	sta     STACK+10                ; set bank in stack 
+	lda     portb_save 
+	sta     STACK+2                 ; set bank restore in stack
+	sta     STACK+18                ; set final restore too
+
+copyto_copy:
+	lda     ptr4                    ; check if count is zero
+	bne     @4
+	lda     ptr4+1
+	beq     done
+
+@4:     jsr     STACK                   ; copy one byte
+
+	sec
+	lda     ptr4
+	sub     #1
+	sta     ptr4
+	bcs     @1
+	lda     ptr4+1
+	beq     @1
+	sub     #1
+	sta     ptr4+1
+
+@1:     inc     STACK+15               ; increment address in BANK
+	bne     @2
+	inc     STACK+16
+	lda     STACK+16
+	cmp     #$80                    ; we stepped outside bank
+	bne     @2
+
+	inc     curbank                 ; get next bank
+	ldx     curbank
+	lda     banks,x
+	sta     STACK+10                ; set new bank
+	lda     #$40                    ; set address back to $4000
+	sta     STACK+16
+
+@2:     inc     STACK+7                ; increment buffer address
+	bne     @3
+	inc     STACK+8
+
+@3:     jmp     copyto_copy           ; copy another byte 
+
diff --git a/libsrc/atari/joy/atarimj8.s b/libsrc/atari/joy/atarimj8.s
new file mode 100644
index 000000000..863737beb
--- /dev/null
+++ b/libsrc/atari/joy/atarimj8.s
@@ -0,0 +1,115 @@
+;
+; MultiJoy joystick driver for the Atari. May be used multiple times when linked
+; to the statically application.
+;
+; Ullrich von Bassewitz, 2002-12-21
+; Stefan Haubenthal, 2009-04-10
+; Using code from Carsten Strotmann and help from Christian Groessler
+;
+
+	.include	"zeropage.inc"
+
+	.include	"joy-kernel.inc"
+	.include	"joy-error.inc"
+	.include	"atari.inc"
+
+	.macpack	generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment	"JUMPTABLE"
+
+; Driver signature
+
+	.byte	$6A, $6F, $79		; "joy"
+	.byte	JOY_API_VERSION		; Driver API version number
+
+; Button state masks (8 values)
+
+	.byte	$02			; JOY_UP
+	.byte	$04			; JOY_DOWN
+	.byte	$08			; JOY_LEFT
+	.byte	$10			; JOY_RIGHT
+	.byte	$01			; JOY_FIRE
+	.byte	$00			; JOY_FIRE2 not available
+	.byte	$00			; Future expansion
+	.byte	$00			; Future expansion
+
+; Jump table.
+
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	COUNT
+	.addr	READJOY
+	.addr	0			; IRQ entry not used
+
+; ------------------------------------------------------------------------
+; Constants
+
+JOY_COUNT	= 8		; Number of joysticks we support
+
+
+; ------------------------------------------------------------------------
+; Data.
+
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an JOY_ERR_xx code in a/x.
+;
+
+INSTALL:
+	lda	#$30
+	sta	PACTL
+	lda	#$F0
+	sta	PORTA
+	lda	#$34
+	sta	PACTL
+	lda	#JOY_ERR_OK
+	ldx	#0
+;	rts			; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+	rts
+
+
+; ------------------------------------------------------------------------
+; COUNT: Return the total number of available joysticks in a/x.
+;
+
+COUNT:
+	lda	#JOY_COUNT
+	ldx	#0
+	rts
+
+; ------------------------------------------------------------------------
+; READ: Read a particular joystick passed in A.
+;
+
+READJOY:
+	asl	a
+	asl	a
+	asl	a
+	asl	a
+	sta	PORTA
+
+; Read joystick
+
+	lda	PORTA		; get position
+	and	#%00001111
+	asl	a
+	ora	TRIG0		; add button information
+	eor	#%00011111
+	ldx	#0		; fix X
+	rts
diff --git a/libsrc/atari/joy/ataristd.s b/libsrc/atari/joy/ataristd.s
new file mode 100644
index 000000000..53eff79fe
--- /dev/null
+++ b/libsrc/atari/joy/ataristd.s
@@ -0,0 +1,112 @@
+;
+; Standard joystick driver for the Atari. May be used multiple times when linked
+; to the statically application.
+;
+; Ullrich von Bassewitz, 2002-12-21
+; Using the readjoy code from Christian Groessler
+;
+
+	.include	"zeropage.inc"
+
+	.include	"joy-kernel.inc"
+	.include	"joy-error.inc"
+	.include	"atari.inc"
+
+	.macpack	generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment	"JUMPTABLE"
+
+; Driver signature
+
+	.byte	$6A, $6F, $79		; "joy"
+	.byte	JOY_API_VERSION		; Driver API version number
+
+; Button state masks (8 values)
+
+	.byte	$01			; JOY_UP
+	.byte	$02			; JOY_DOWN
+	.byte	$04			; JOY_LEFT
+	.byte	$08			; JOY_RIGHT
+	.byte	$10			; JOY_FIRE
+	.byte	$00			; JOY_FIRE2 not available
+	.byte	$00			; Future expansion
+	.byte	$00			; Future expansion
+
+; Jump table.
+
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	COUNT
+	.addr	READJOY
+	.addr	0			; IRQ entry not used
+
+; ------------------------------------------------------------------------
+; Constants
+
+JOY_COUNT	= 4		; Number of joysticks we support
+
+
+; ------------------------------------------------------------------------
+; Data.
+
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an JOY_ERR_xx code in a/x.
+;
+
+INSTALL:
+	lda	#JOY_ERR_OK
+	ldx	#0
+;	rts			; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+	rts
+
+
+; ------------------------------------------------------------------------
+; COUNT: Return the total number of available joysticks in a/x.
+;
+
+COUNT:
+	lda	#JOY_COUNT
+	ldx	$fcd8
+	cpx	#$a2
+	beq	_400800
+	lsr	a		; XL and newer machines only have 2 ports
+_400800:
+	ldx	#0
+	rts
+
+; ------------------------------------------------------------------------
+; READ: Read a particular joystick passed in A.
+;
+
+READJOY:
+	and	#3		; fix joystick number
+	tax			; Joystick number (0-3) into X
+
+; Read joystick
+
+	lda	STRIG0,x	; get button
+	asl	a
+	asl	a
+	asl	a
+	asl	a
+	ora	STICK0,x	; add position information
+	eor	#$1F
+	ldx	#0		; fix X
+	rts
diff --git a/libsrc/atari/tgi/atari10.s b/libsrc/atari/tgi/atari10.s
new file mode 100644
index 000000000..a7da93b97
--- /dev/null
+++ b/libsrc/atari/tgi/atari10.s
@@ -0,0 +1,79 @@
+;
+; Graphics driver for the 80x192x9 (CIO mode 10, ANTIC mode F, GTIA mode $80) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 10
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 9
+; Pixels per byte
+	ppb = 2
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0330				; based on 4/3 display
+; Free memory needed
+	mem_needed = 7147
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11110000, %00001111
+	masks:					; Color masks
+		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00001111, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96, $68, $C4, $74, $EE, $4A
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	sta	PCOLR0,y
+	dey
+	bpl     loop
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari11.s b/libsrc/atari/tgi/atari11.s
new file mode 100644
index 000000000..2e2dfd842
--- /dev/null
+++ b/libsrc/atari/tgi/atari11.s
@@ -0,0 +1,71 @@
+;
+; Graphics driver for the 80x192x16h (CIO mode 11, ANTIC mode F, GTIA mode $C0) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 11
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 16
+; Pixels per byte
+	ppb = 2
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0330				; based on 4/3 display
+; Free memory needed
+	mem_needed = 7147
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11110000, %00001111
+	masks:					; Color masks
+		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $aa, $bb, $cc, $dd, $ee, $ff
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00001111, %00000000
+	default_palette:
+		.byte	$00, $10, $20, $30, $40, $50, $60, $70, $80, $90, $A0, $B0, $C0, $D0, $E0, $F0
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; No palettes
+        lda     #TGI_ERR_INV_FUNC
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari14.s b/libsrc/atari/tgi/atari14.s
new file mode 100644
index 000000000..ebd243067
--- /dev/null
+++ b/libsrc/atari/tgi/atari14.s
@@ -0,0 +1,84 @@
+;
+; Graphics driver for the 160x192x2 (CIO mode 14, ANTIC mode C) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 14
+; X resolution
+	x_res = 160
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 2
+; Pixels per byte
+	ppb = 8
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0198				; based on 4/3 display
+; Free memory needed
+	mem_needed = 3305
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
+	masks:					; Color masks
+		.byte	%00000000, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
+	default_palette:
+		.byte	$00, $0E
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari15.s b/libsrc/atari/tgi/atari15.s
new file mode 100644
index 000000000..08497db37
--- /dev/null
+++ b/libsrc/atari/tgi/atari15.s
@@ -0,0 +1,88 @@
+;
+; Graphics driver for the 160x192x2 (CIO mode 15, ANTIC mode E) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 15
+; X resolution
+	x_res = 160
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 4
+; Pixels per byte
+	ppb = 4
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0198				; based on 4/3 display
+; Free memory needed
+	mem_needed = 7147
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11000000, %00110000, %00001100, %00000011
+	masks:					; Color masks
+		.byte	%00000000, %01010101, %10101010, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+	lda	palette + 2
+	sta	COLOR1
+	lda	palette + 3
+	sta	COLOR2
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari3.s b/libsrc/atari/tgi/atari3.s
new file mode 100644
index 000000000..24dca69de
--- /dev/null
+++ b/libsrc/atari/tgi/atari3.s
@@ -0,0 +1,88 @@
+;
+; Graphics driver for the 40x24x4 (CIO mode 3, ANTIC mode 8) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 3
+; X resolution
+	x_res = 40
+; Y resolution
+	y_res = 24
+; Number of colors
+	colors = 4
+; Pixels per byte
+	ppb = 4
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 1
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11000000, %00110000, %00001100, %00000011
+	masks:					; Color masks
+		.byte	%00000000, %01010101, %10101010, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+	lda	palette + 2
+	sta	COLOR1
+	lda	palette + 3
+	sta	COLOR2
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari4.s b/libsrc/atari/tgi/atari4.s
new file mode 100644
index 000000000..785e742e5
--- /dev/null
+++ b/libsrc/atari/tgi/atari4.s
@@ -0,0 +1,84 @@
+;
+; Graphics driver for the 80x48x2 (CIO mode 4, ANTIC mode 9) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 4
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 48
+; Number of colors
+	colors = 2
+; Pixels per byte
+	ppb = 8
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 1
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
+	masks:					; Color masks
+		.byte	%00000000, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
+	default_palette:
+		.byte	$00, $0E
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari5.s b/libsrc/atari/tgi/atari5.s
new file mode 100644
index 000000000..c8c699753
--- /dev/null
+++ b/libsrc/atari/tgi/atari5.s
@@ -0,0 +1,88 @@
+;
+; Graphics driver for the 80x48x4 (CIO mode 5, ANTIC mode A) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 5
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 48
+; Number of colors
+	colors = 4
+; Pixels per byte
+	ppb = 4
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 185
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11000000, %00110000, %00001100, %00000011
+	masks:					; Color masks
+		.byte	%00000000, %01010101, %10101010, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+	lda	palette + 2
+	sta	COLOR1
+	lda	palette + 3
+	sta	COLOR2
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari6.s b/libsrc/atari/tgi/atari6.s
new file mode 100644
index 000000000..091b698d4
--- /dev/null
+++ b/libsrc/atari/tgi/atari6.s
@@ -0,0 +1,84 @@
+;
+; Graphics driver for the 160x96x2 (CIO mode 6, ANTIC mode B) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 6
+; X resolution
+	x_res = 160
+; Y resolution
+	y_res = 96
+; Number of colors
+	colors = 2
+; Pixels per byte
+	ppb = 8
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 1193
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
+	masks:					; Color masks
+		.byte	%00000000, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
+	default_palette:
+		.byte	$00, $0E
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari7.s b/libsrc/atari/tgi/atari7.s
new file mode 100644
index 000000000..95a05d4e8
--- /dev/null
+++ b/libsrc/atari/tgi/atari7.s
@@ -0,0 +1,88 @@
+;
+; Graphics driver for the 160x96x4 (CIO mode 7, ANTIC mode D) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 7
+; X resolution
+	x_res = 160
+; Y resolution
+	y_res = 96
+; Number of colors
+	colors = 4
+; Pixels per byte
+	ppb = 4
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 3209
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11000000, %00110000, %00001100, %00000011
+	masks:					; Color masks
+		.byte	%00000000, %01010101, %10101010, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+	lda	palette + 2
+	sta	COLOR1
+	lda	palette + 3
+	sta	COLOR2
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari8.s b/libsrc/atari/tgi/atari8.s
new file mode 100644
index 000000000..fe97a5a0a
--- /dev/null
+++ b/libsrc/atari/tgi/atari8.s
@@ -0,0 +1,83 @@
+;
+; Graphics driver for the 320x192x2 (CIO mode 8, ANTIC mode F) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 8
+; X resolution
+	x_res = 320
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 2
+; Pixels per byte
+	ppb = 8
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 7147
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
+	masks:					; Color masks
+		.byte	%00000000, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
+	default_palette:
+		.byte	$00, $0E
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR2
+	lda	palette + 1
+	sta	COLOR1
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari9.s b/libsrc/atari/tgi/atari9.s
new file mode 100644
index 000000000..38e23702a
--- /dev/null
+++ b/libsrc/atari/tgi/atari9.s
@@ -0,0 +1,71 @@
+;
+; Graphics driver for the 80x192x16b (CIO mode 9, ANTIC mode F, GTIA mode $40) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 9
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 16
+; Pixels per byte
+	ppb = 2
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0330				; based on 4/3 display
+; Free memory needed
+	mem_needed = 7147
+; Number of screen pages
+	pages = 1
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11110000, %00001111
+	masks:					; Color masks
+		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $aa, $bb, $cc, $dd, $ee, $ff
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00001111, %00000000
+	default_palette:
+		.byte	$00, $0F, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; No palettes
+        lda     #TGI_ERR_INV_FUNC
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atari_tgi_common.inc b/libsrc/atari/tgi/atari_tgi_common.inc
new file mode 100644
index 000000000..9e9f74aa4
--- /dev/null
+++ b/libsrc/atari/tgi/atari_tgi_common.inc
@@ -0,0 +1,1483 @@
+;
+; Generic Atari graphics driver
+;
+
+.macpack longbranch
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Header. Includes jump table and constants.
+	;
+	; ----------------------------------------------------------------------
+
+.segment        "JUMPTABLE"
+
+; Header
+
+	.byte   $74, $67, $69		; "tgi"
+	.byte   TGI_API_VERSION		; TGI API version number
+	.word   x_res			; X resolution
+	.word   y_res			; Y resolution
+	.byte   colors			; Number of drawing colors
+	.byte   pages			; Number of screens available
+	.byte   8			; System font X size
+	.byte   8			; System font Y size
+	.word	aspect			; Aspect ratio
+        .byte   0                       ; TGI driver flags
+
+; Function table
+
+	.addr   INSTALL
+	.addr   UNINSTALL
+	.addr   INIT
+	.addr   DONE
+	.addr   GETERROR
+	.addr   CONTROL
+	.addr   CLEAR
+	.addr   SETVIEWPAGE
+	.addr   SETDRAWPAGE
+	.addr   SETCOLOR
+	.addr   SETPALETTE
+	.addr   GETPALETTE
+	.addr   GETDEFPALETTE
+	.addr   SETPIXEL
+	.addr   GETPIXEL
+	.addr   LINE
+	.addr   BAR
+	.addr   TEXTSTYLE
+	.addr   OUTTEXT
+	.addr   0			; IRQ entry is unused
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Parameters
+	;
+	; ----------------------------------------------------------------------
+
+	x1	:= ptr1
+	y1	:= ptr2
+	x2	:= ptr3
+	y2	:= ptr4
+	radius	:= tmp1
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Global variables
+	;
+	; ----------------------------------------------------------------------
+
+	sptr	:= regsave + 2
+
+.bss
+	error:
+		.res	1	; Error code
+
+.if ::grmode = 9 || ::grmode = 11
+	palette = default_palette
+.else
+	palette:
+		.res	colors	; The current palette
+.endif
+
+	mask:
+		.res	1	; Current pixel mask
+	griocb:
+		.res	1	; IOCB channel number for graphics
+
+.if pages = 2
+	p0scr:
+		.res	1	; High byte of screen address for screen page 0
+	p0dls:
+		.res	1	; High byte of display list address for screen page 0
+				; Page 1's addresses are 8K higher
+.endif
+
+.data
+	mag_x:
+		.byte	1	; Horizontal text scaling factor
+	mag_y:
+		.byte	1	; Vertical text scaling factor
+	mag_x8:
+		.word	8	; Horizontal text scaling factor * 8
+	mag_y8:
+		.word	8	; Vertical text scaling factor * 8
+	text_dir:
+		.byte	0	; Text direction,
+
+.code
+
+; ******************************************************************************
+
+.macro	put_pixel
+
+	; ----------------------------------------------------------------------
+	;
+	; Put a pixel at (sptr),y using x as the bit mask offset
+	;
+	; ----------------------------------------------------------------------
+
+	lda	(sptr),y
+	eor	mask
+	and	mask_table,x
+	eor	(sptr),y
+	sta	(sptr),y
+.endmacro
+
+; ******************************************************************************
+
+.rodata
+screen_device:
+	.byte "S:",$9B		; Device code for screen
+screen_device_length := * - screen_device
+
+.code
+
+.proc INIT
+
+	; ----------------------------------------------------------------------
+	;
+	; INIT: Switch to graphics mode
+	;
+	; ----------------------------------------------------------------------
+
+
+.code
+	; Initialize drawing color
+
+.if ::ppb = 8
+	ldx	#$FF
+.elseif ::ppb = 4
+	ldx	#$55
+.elseif ::ppb = 2
+	ldx	#$11
+.endif
+
+	stx	mask
+
+	; Find a free IOCB
+	lda	#$70
+search: tax
+	ldy	ICHID,x
+	cpy	#$FF
+	beq	found
+	sub	#$10
+	bcs	search
+
+	; Not enough resources available (free IOCB or memory)
+	; enter with C cleared!
+nores:	lda	#TGI_ERR_NO_RES
+	bcc	exit
+
+found:	; Check if enough RAM is available
+	lda	#0
+	sub	#mem_needed
+	cmp	APPMHI + 1
+	bcc	nores
+	bne	switch
+	cpy	APPMHI
+	bcc	nores			; not enough memory
+
+	; Switch into graphics mode
+switch:	lda	#OPEN
+	sta	ICCOM,x
+	lda	#OPNIN | OPNOT
+	sta	ICAX1,x
+	lda	#::grmode
+	sta	ICAX2,x
+	lda	#screen_device
+	sta	ICBAH,x
+	lda	#screen_device_length
+	sta	ICBLH,x
+	jsr	CIOV
+
+.if ::pages = 2
+	; Reserve 8K of high memory
+	lda	RAMTOP
+	sub	#32
+	sta	RAMTOP
+	; Close and reopen graphics
+	lda	#CLOSE
+	sta	ICCOM,x
+	jsr	CIOV
+	; Reopen graphics
+	lda	#OPEN
+	sta	ICCOM,x
+	lda	#OPNIN | OPNOT
+	sta	ICAX1,x
+	lda	#::grmode
+	sta	ICAX2,x
+	lda	#screen_device
+	sta	ICBAH,x
+	lda	#screen_device_length
+	sta	ICBLH,x
+	jsr	CIOV
+	; Save screen pointers
+	lda	SAVMSC + 1
+	sta	p0scr
+	lda	SDLSTH
+	sta	p0dls
+.endif ; ::pages = 2
+
+	stx	griocb
+
+	; Reset the error code and return
+        lda     #TGI_ERR_OK
+exit:	sta     error
+        rts
+.endproc
+
+; ******************************************************************************
+
+.proc DONE
+
+	; ----------------------------------------------------------------------
+	;
+	; DONE: Switch back to text mode
+	;
+	; ----------------------------------------------------------------------
+
+.code
+
+.if ::pages = 2
+	; Free 8K of high memory
+	lda	RAMTOP
+	add	#32
+	sta	RAMTOP
+.endif
+
+	; Clear griocb
+	lda	#$FF
+	ldx	griocb
+	sta	griocb
+
+	; Close the S: device
+	lda	#CLOSE
+	sta	ICCOM,x
+	jsr	CIOV
+
+	; Reopen it in Graphics 0
+	lda	#OPEN
+	sta	ICCOM,x
+	lda	#OPNIN | OPNOT
+	sta	ICAX1,x
+	lda	#0
+	sta	ICAX2,x
+	lda	#screen_device
+	sta	ICBAH,x
+	lda	#screen_device_length
+	sta	ICBLH,x
+	jsr	CIOV
+
+	; Now close it again; we don't need it anymore :)
+	lda	#CLOSE
+	sta	ICCOM,x
+	jmp	CIOV
+.endproc
+
+; ******************************************************************************
+
+.proc GETERROR
+
+	; ----------------------------------------------------------------------
+	;
+	; GETERROR: Return the error code in A and clear it
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	ldx	#TGI_ERR_OK
+	lda	error
+	stx	error
+	rts
+.endproc
+
+; ******************************************************************************
+
+.proc CLEAR
+
+	; ----------------------------------------------------------------------
+	;
+	; CLEAR: Clear the screen
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Load the screen address in sptr
+	lda	SAVMSC
+	sta	sptr
+	lda	SAVMSC + 1
+	sta	sptr + 1
+
+	; Fill with zero
+	lda	#0
+	tay
+
+.if >::scrsize > 0
+	; Clear full pages if any
+	ldx	#>::scrsize
+loop1:	sta	(sptr),y
+	iny
+	bne	loop1
+	inc	sptr + 1
+	dex
+	bne	loop1
+.endif
+
+.if <::scrsize > 0
+	; Clear the rest, if any
+loop2:	sta	(sptr),y
+	iny
+	cpy	#<::scrsize
+	bne	loop2
+.endif
+
+        rts
+.endproc
+
+; ******************************************************************************
+
+.proc GETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; GETPALETTE: Return the current palette in A/X
+	;
+	; ----------------------------------------------------------------------
+
+.code
+        lda     #palette
+        rts
+.endproc
+
+; ******************************************************************************
+
+.proc GETDEFPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; GETDEFPALETTE: Return the default palette in A/X
+	;
+	; ----------------------------------------------------------------------
+
+.code
+        lda     #default_palette
+        rts
+.endproc
+
+; ******************************************************************************
+
+.proc SETCOLOR
+
+	; ----------------------------------------------------------------------
+	;
+	; SETCOLOR: Set the drawing color (in A)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	tax
+
+.if ::grmode = 9
+	; Map colors like this: 0 -> 0, 1 -> 15, 2 -> 1, 3 -> 2 etc.
+	beq	cont
+	cpx	#1
+	bne	map
+	ldx	#16
+map:	dex
+cont:
+.endif
+
+	lda	masks,x
+	sta	mask
+	rts
+.endproc
+
+; ******************************************************************************
+
+.proc CALC
+
+	; ----------------------------------------------------------------------
+	;
+	; CALC: Calculate the screen address
+	;	in
+	;		x1 (ptr1)	x coordinate
+	;		y1 (ptr2)	y coordinate
+	;	out
+	;		sptr + y	screen address
+	;		x		bit mask index
+	;
+	; ----------------------------------------------------------------------
+
+.bss
+	temp:	.res	1
+.code
+	; calculate line offset
+	lda	y1 + 1
+	sta	temp
+	lda	y1
+
+.if ::x_res / ::ppb = 40
+	yrep = 3
+.elseif ::x_res / ::ppb = 20
+	yrep = 2
+.elseif ::x_res / ::ppb = 10
+	yrep = 1
+.endif
+
+.repeat	yrep
+	asl	a
+	rol	temp
+.endrepeat
+
+	sta	sptr
+	ldx	temp
+	stx	sptr + 1
+
+.repeat	2
+	  asl	a
+	  rol	temp
+.endrepeat
+
+	add	sptr
+	sta	sptr
+	lda	temp
+	adc	sptr + 1
+	sta	sptr + 1
+
+	; calculate bit mask offset
+	lda	x1
+	and	#ppb - 1
+	tax
+
+	; calculate row offset
+	lda	x1 + 1
+	sta	temp
+	lda	x1
+
+.if ::ppb = 8
+	xrep = 3
+.elseif ::ppb = 4
+	xrep = 2
+.elseif ::ppb = 2
+	xrep = 1
+.endif
+
+.repeat	xrep
+	lsr	temp
+	ror	a
+.endrepeat
+
+	tay
+
+	; sptr += SAVMSC
+	lda	SAVMSC
+	add	sptr
+	sta	sptr
+	lda	SAVMSC + 1
+	adc	sptr + 1
+	sta	sptr + 1
+
+	; We're done!
+	rts
+.endproc
+
+; ******************************************************************************
+
+.proc SETPIXEL
+
+	; ----------------------------------------------------------------------
+	;
+	; Draw one pixel at x1, y1
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	jsr	CALC
+	put_pixel
+	rts
+.endproc
+
+; ******************************************************************************
+
+.proc GETPIXEL
+
+	; ----------------------------------------------------------------------
+	;
+	; GETPIXEL: Read the color value of a pixel and return it in A/X
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	jsr	CALC
+	lda	(sptr),y
+	and	mask_table,x
+
+.if ::ppb = 8
+	beq	zero
+	lda	#1
+zero:	ldx	#0
+	rts
+.elseif ::ppb = 4
+loop:	cpx	#3
+	beq	done4
+	lsr	a
+	lsr	a
+	inx
+	bne	loop
+done4:	and	#$03
+	ldx	#0
+	rts
+.elseif ::ppb = 2
+	dex
+	bne	shift
+	and	#$0F
+	jmp	exit
+shift:	lsr	a
+	lsr	a
+	lsr	a
+	lsr	a
+
+exit:
+
+.if ::grmode = 9
+	; Mode 9 mapping
+	; Map colors like this: 0 -> 0, 15 -> 1, 2 -> 3, 3 -> 4 etc.
+	beq	done9
+	cmp	#15
+	bne	map9
+	lda	#0
+map9:	add	#1
+done9:
+.endif
+
+.if ::grmode = 10
+	; Mode 10 mapping
+	; Map out of range colors like this:
+	;  9 -> 8
+	; 10 -> 8
+	; 11 -> 8
+	; 12 -> 0
+	; 13 -> 1
+	; 14 -> 2
+	; 15 -> 3
+	cmp	#9
+	bcc	done10
+	sub	#12
+	bcs	done10
+	lda	#8
+done10:
+.endif ; ::grmode = 10
+
+	; Done!
+	ldx	#0
+	rts
+.endif	; ::ppb = 2
+
+.endproc
+
+; ******************************************************************************
+
+.proc LINE
+
+	; ----------------------------------------------------------------------
+	;
+	; LINE: Draw a line from x1,y1 to x2,y2
+	;
+	; ----------------------------------------------------------------------
+
+.ifdef USE_CIO_LINE
+
+	; position ptr1, ptr2
+	lda	x1
+	sta	OLDCOL
+	lda	x1 + 1
+	sta	OLDCOL + 1
+	lda	y1
+	sta	OLDROW
+	; plot
+	jsr	SETPIXEL
+	; position ptr3,ptr4
+	lda	x2
+	sta	COLCRS
+	lda	x2 + 1
+	sta	COLCRS + 1
+	lda	y2
+	sta	ROWCRS
+	; drawto
+	ldx	griocb
+	lda	#DRAWLN
+	sta	ICCOM,x
+	lda	mask
+
+.if ::grmode = 10
+	and	#$0f
+.else
+	and	#colors - 1
+.endif
+
+	sta	ATACHR
+	jmp	CIOV
+
+.else	; USE_CIO_LINE
+
+; locals
+
+	dx	:=	sreg
+	dy	:=	y1
+	dx2	:=	x2
+	dy2	:=	y2
+	iy	:=	tmp1
+	err	:=	tmp3
+
+.code
+	; dx = x2 - x1
+	lda	x2
+	sub	x1
+	sta	dx
+	lda	x2 + 1
+	sbc	x1 + 1
+	sta	dx + 1
+	; if dx is positive, no problem
+	bcs	dx_positive
+
+	; if dx is negative, swap x1,y1 with x2,y2
+	lda	x1	; x1 <-> x2, low byte
+	ldx	x2
+	sta	x2
+	stx	x1
+	lda	x1 + 1	; x1 <-> x2, high byte
+	ldx	x2 + 1
+	sta	x2 + 1
+	stx	x1 + 1
+	lda	y1	; y1 <-> y2, low byte
+	ldx	y2
+	sta	y2
+	stx	y1
+	lda	y1 + 1	; y1 <-> y2, high byte
+	ldx	y2 + 1
+	sta	y2 + 1
+	stx	y1 + 1
+	; Calculate again
+	jmp	LINE
+
+dx_positive:
+	; Calculate coords
+	jsr	CALC
+
+	; dy = y2 - y1
+	lda	y2
+	sub	y1
+	sta	dy
+	lda	y2 + 1
+	sbc	y1 + 1
+	sta	dy + 1
+
+	; if dy is negative
+	bcs	dy_positive
+	; dy = -dy
+	lda	#0
+	sub	dy
+	sta	dy
+	lda	#0
+	sbc	dy + 1
+	sta	dy + 1
+	; iy = -row_size
+	lda	#<(65536 - x_res / ppb)
+	sta	iy
+	lda	#>(65536 - x_res / ppb)
+	sta	iy + 1
+	bne	skip_iy_1		; always
+
+dy_positive:
+	; iy = row_size
+	lda	#<(x_res / ppb)
+	sta	iy
+	lda	#>(x_res / ppb)
+	sta	iy + 1
+skip_iy_1:
+
+	; dx2 = dx * 2
+	lda	dx
+	asl	a
+	sta	dx2
+	lda	dx + 1
+	rol	a
+	sta	dx2 + 1
+
+	; dy2 = dy * 2
+	lda	dy
+	asl	a
+	sta	dy2
+	lda	dy + 1
+	rol	a
+	sta	dy2 + 1
+
+	; if dx >= dy
+	lda	dx
+	cmp	dy
+	lda	dx + 1
+	sbc	dy + 1
+	bcc	dy_major
+
+	; dx is the major axis
+
+	; err = dy2 - dx
+	lda	dy2
+	sub	dx
+	sta	err
+	lda	dy2 + 1
+	sbc	dx + 1
+	sta	err + 1
+
+	.scope
+loop:	; main loop
+	put_pixel
+	; if err >= 0
+	lda	err + 1
+	bmi	err_neg
+	; err -= dx2
+	lda	err
+	sub	dx2
+	sta	err
+	lda	err + 1
+	sbc	dx2 + 1
+	sta	err + 1
+	; move_vertical (iy)
+	lda	sptr
+	add	iy
+	sta	sptr
+	lda	sptr + 1
+	adc	iy + 1
+	sta	sptr + 1
+err_neg:
+	; err += dy2
+	lda	err
+	add	dy2
+	sta	err
+	lda	err + 1
+	adc	dy2 + 1
+	sta	err + 1
+	; move_right
+	inx
+	cpx	#ppb
+	bne	end_move
+	ldx	#0
+	iny
+	bne	end_move
+	inc	sptr + 1
+end_move:
+	; loop while dx-- >= 0
+	lda	dx
+	ora	dx + 1
+	beq	exit
+	dec	dx
+	lda	dx
+	cmp	#$FF
+	bne	loop
+	dec	dx + 1
+	jmp	loop
+exit:	rts
+	.endscope
+
+dy_major:
+	; dy is the major axis
+
+	; err = dx2 - dy;
+	lda	dx2
+	sub	dy
+	sta	err
+	lda	dx2 + 1
+	sbc	dy + 1
+	sta	err + 1
+
+	.scope
+loop:	; main loop
+	put_pixel
+	; if err >= 0
+	lda	err + 1
+	bmi	end_move
+	; err -= dy2
+	lda	err
+	sub	dy2
+	sta	err
+	lda	err + 1
+	sbc	dy2 + 1
+	sta	err + 1
+	; move_right
+	inx
+	cpx	#ppb
+	bne	end_move
+	ldx	#0
+	iny
+	bne	end_move
+	inc	sptr + 1
+end_move:
+	; err += dx2
+	lda	err
+	add	dx2
+	sta	err
+	lda	err + 1
+	adc	dx2 + 1
+	sta	err + 1
+	; move_vertical(iy)
+	lda	sptr
+	add	iy
+	sta	sptr
+	lda	sptr + 1
+	adc	iy + 1
+	sta	sptr + 1
+	; loop while dy-- >= 0
+	lda	dy
+	ora	dy + 1
+	beq	exit
+	dec	dy
+	lda	dy
+	cmp	#$FF
+	bne	loop
+	dec	dy + 1
+	jmp	loop
+exit:	rts
+	.endscope
+.endif	; USE_CIO_LINE
+.endproc
+
+; ******************************************************************************
+
+.proc clipped_bar
+
+	; ----------------------------------------------------------------------
+	;
+	; Clip and draw bar, this function will disappear when text clipping
+	; will be done int the TGI kernel
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	lda	y1 + 1
+	bne	off
+	lda	y1
+	cmp	#y_res
+	bcs	off
+
+	lda	x1 + 1
+
+.if >(::x_res - 1) > 0
+	cmp	#>x_res
+	bcc	check2
+.endif
+
+	bne	off
+	lda	x1
+	cmp	#(::x_res - 1) > 0
+	cmp	#>x_res
+	bcc	BAR
+.endif
+
+	bne	off
+	lda	x2
+	cmp	#(::x_res - 1) > 0
+	lda	x2 + 1
+	sta	x1 + 1
+.endif
+
+	jsr	CALC
+	; Save the values
+	tya
+	add	sptr
+	sta	sptr
+	bcc	skips
+	inc	sptr + 1
+skips:	inx
+	lda	bar_table,x
+	eor	#$FF
+	sta	rmask
+	; Calculate memory difference between x1 and x2
+	lda	sptr
+	sub	lmem
+	sta	dx
+loop:	; Main loop
+	ldy	#0
+	ldx	dx
+	beq	same
+	; Left
+	lda	(lmem),y
+	eor	mask
+	and	lmask
+	eor	(lmem),y
+	sta	(lmem),y
+	iny
+	; Between
+	lda	mask
+	jmp	next
+btwn:	sta	(lmem),y
+	iny
+next:	dex
+	bne	btwn
+	; Right
+	lda	(lmem),y
+	eor	mask
+	and	rmask
+	eor	(lmem),y
+	sta	(lmem),y
+	jmp	cont
+same:	; Same byte
+	lda	lmask
+	and	rmask
+	sta	fmask
+	lda	(lmem),y
+	eor	mask
+	and	fmask
+	eor	(lmem),y
+	sta	(lmem),y
+cont:	; Go to next row
+	lda	lmem
+	add	#<(x_res / ppb)
+	sta	lmem
+	bcc	skipm
+	inc	lmem + 1
+skipm:	; Loop while --dy > 0
+	dec	dy
+	bne	loop
+
+	rts
+
+.endproc
+
+; ******************************************************************************
+
+.proc TEXTSTYLE
+
+	; ----------------------------------------------------------------------
+	;
+	; TEXTSTYLE: Set text style. Scale factors in X and Y and direction in A
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	stx	mag_x
+	sty     mag_y
+	; Save text direction in bit 8 so that we can use BIT instruction later
+	lsr	a
+	ror	a
+	sta     text_dir
+	; Save 8 * scaling factors
+	lda	#0
+	sta	mag_x8 + 1
+	sta	mag_y8 + 1
+	; Save 8 * mag_x
+	txa
+
+	.repeat	3
+	asl	a
+	rol	mag_x8 + 1
+	.endrepeat
+
+	sta	mag_x8
+	; Save 8 * mag_y
+	tya
+
+	.repeat	3
+	asl	a
+	rol	mag_y8 + 1
+	.endrepeat
+
+	sta	mag_y8
+	; Done!
+	rts
+.endproc
+
+; ******************************************************************************
+
+.proc OUTTEXT
+
+	; ----------------------------------------------------------------------
+	;
+	; OUTTEXT: Draw text at x1, y1. String is in ptr3
+	;
+	; ----------------------------------------------------------------------
+
+; locals
+	string	:= tmp1
+	cols	:= tmp3
+	pixels	:= tmp4
+	font	:= regsave
+.rodata
+	ataint:	.byte	64,0,32,96
+.bss
+	rows:	.res	1
+
+.if >(::x_res - 1) > 0
+	oldx1:	.res	2
+	oldx2:	.res	2
+.else
+	oldx1:	.res	1
+	oldx2:	.res	1
+.endif
+
+	oldy1:	.res	1
+	oldy2:	.res	1
+	inv:	.res	1
+
+.code
+	; Don't draw zero sized characters
+	lda	mag_x
+	ora	mag_y
+	bne	not0
+	rts
+
+not0:	; Save string address, ptr3 is needed by BAR
+	lda	ptr3
+	sta	string
+	lda	ptr3 + 1
+	sta	string + 1
+
+	bit	text_dir
+	bmi	vert
+
+	; Calculate x2
+	lda	mag_x
+	sub	#1
+	add	x1
+	sta	x2
+
+.if >(::x_res - 1) > 0
+	lda	x1 + 1
+	adc	#0
+	sta	x2 + 1
+.else
+	lda	#0
+	sta	x2 + 1
+.endif
+
+	; Calculate y2 and adjust y1
+	dec	y1
+	lda	y1
+	sta	y2
+	sub	mag_y
+	add	#1
+	sta	y1
+	lda	#0
+	sta	y2 + 1
+
+	jmp	while
+
+	; Calculate for vertical text
+vert:	lda	x1
+	sub	#1
+	sta	x2
+	lda	x1 + 1
+	sbc	#0
+	sta	x2 + 1
+	lda	x1
+	sub	mag_y
+	sta	x1
+	lda	x1 + 1
+	sbc	#0
+	sta	x1 + 1
+
+	lda	mag_x
+	sub	#1
+	add	y1
+	sta	y2
+	lda	#0
+	sta	y2 + 1
+	jmp	while
+
+	; Main loop
+loop:	inc	string
+	bne	skiph
+	inc	string + 1
+skiph:	; Save coords
+	bit	text_dir
+	bmi	scvert
+
+	ldx	y1
+	stx	oldy1
+	ldx	y2
+	stx	oldy2
+	jmp	draw
+
+scvert:	ldx	x1
+	stx	oldx1
+	ldx	x2
+	stx	oldx2
+
+.if >(::x_res - 1) > 0
+	ldx	x1 + 1
+	stx	oldx1 + 1
+	ldx	x2 + 1
+	stx	oldx2 + 1
+.endif
+
+	; Draw one character
+	; Convert to ANTIC code
+draw:	tay
+	rol	a
+	rol	a
+	rol	a
+	rol	a
+	and	#3
+	tax
+	tya
+	and	#$9f
+	ora	ataint,x
+	; Save and clear inverse video bit
+	sta	inv
+	and	#$7F
+	; Calculate font data address
+	sta	font
+	lda	#0
+	sta	font + 1
+
+	.repeat 3
+	asl	font
+	rol	a
+	.endrepeat
+
+	adc	CHBAS
+	sta	font + 1
+	; Save old coords
+	bit	text_dir
+	bpl	hor
+	lda	y1
+	sta	oldy1
+	lda	y2
+	sta	oldy2
+	jmp	cont
+hor:	lda	x1
+	sta	oldx1
+	lda	x2
+	sta	oldx2
+
+.if >(::x_res - 1) > 0
+	lda	x1 + 1
+	sta	oldx1 + 1
+	lda	x2 + 1
+	sta	oldx2 + 1
+.endif
+
+	; Get glyph pixels
+cont:	ldy	#7
+	; Put one row of the glyph
+putrow:	sty	rows
+	lda	(font),y
+	bit	inv
+	bpl	noinv
+	eor	#$FF
+noinv:	sta	pixels
+	lda	#7
+	sta	cols
+	; Put one column of the row
+putcol:	asl	pixels
+	bcc	next_col
+	lda	x1
+	pha
+	lda	x1 + 1
+	pha
+	jsr	clipped_bar
+	pla
+	sta	x1 + 1
+	pla
+	sta	x1
+next_col:
+	; Go to next column
+	; increase x coords
+	bit	text_dir
+	bmi	vertinc
+
+	lda	mag_x
+	add	x1
+	sta	x1
+	bcc	L1
+	inc	x1 + 1
+L1:	lda	mag_x
+	add	x2
+	sta	x2
+	bcc	L2
+	inc	x2 + 1
+	jmp	L2
+
+vertinc:
+	lda	y1
+	sub	mag_x
+	sta	y1
+	lda	y2
+	sub	mag_x
+	sta	y2
+L2:
+	dec	cols
+	bpl	putcol
+next_row:
+	; Go to next row
+	bit	text_dir
+	bmi	verty
+
+	lda	y1
+	sub	mag_y
+	sta	y1
+	bcs	L3
+	dec	y1 + 1
+L3:	lda	y2
+	sub	mag_y
+	sta	y2
+	bcs	L6
+	dec	y2 + 1
+L4:	jmp	L6
+
+verty:	lda	x1
+	sub	mag_y
+	sta	x1
+	bcs	L5
+	dec	x1 + 1
+L5:	lda	x2
+	sub	mag_y
+	sta	x2
+	bcs	L6
+	dec	x2 + 1
+L6:
+	; Restore old values
+	bit	text_dir
+	bpl	reshor
+	lda	oldy1
+	sta	y1
+	lda	oldy2
+	sta	y2
+	jmp	nextrow
+reshor:	lda	oldx1
+	sta	x1
+	lda	oldx2
+	sta	x2
+
+.if >(::x_res - 1) > 0
+	lda	oldx1 + 1
+	sta	x1 + 1
+	lda	oldx2 + 1
+	sta	x2 + 1
+.endif
+
+	; Next row
+nextrow:
+	ldy	rows
+	dey
+	jpl	putrow
+
+	; Restore coords
+	bit	text_dir
+	bmi	resvert
+
+	ldx	oldy1
+	stx	y1
+	ldx	oldy2
+	stx	y2
+	ldx	#0
+	stx	y1 + 1
+	stx	y2 + 1
+
+	lda	mag_x8
+	add	x1
+	sta	x1
+	lda	mag_x8 + 1
+	adc	x1 + 1
+	sta	x1 + 1
+	lda	mag_x8
+	add	x2
+	sta	x2
+	lda	mag_x8 + 1
+	adc	x2 + 1
+	sta	x2 + 1
+
+	jmp	while
+
+resvert:
+	ldx	oldx1
+	stx	x1
+	ldx	oldx2
+	stx	x2
+
+.if >(::x_res - 1) > 0
+	ldx	oldx1 + 1
+	stx	x1 + 1
+	ldx	oldx2 + 1
+	stx	x2 + 1
+.endif
+
+	lda	y1
+	sub	mag_x8
+	sta	y1
+	lda	y1 +1
+	sbc	mag_x8 + 1
+	sta	y1 + 1
+	lda	y2
+	sub	mag_x8
+	sta	y2
+	lda	y2 +1
+	sbc	mag_x8 + 1
+	sta	y2 + 1
+
+	; End of loop
+while:	ldy	#0
+	lda	(string),y
+	jne	loop		; Check for null character
+	rts
+
+.endproc
+
+.if pages = 2
+; ******************************************************************************
+
+.proc SETVIEWPAGE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETVIEWPAGE, page in A
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	tax
+	beq	cont
+	lda	#32
+
+cont:	add	p0dls
+	cmp	SDLSTH
+	beq	done		; We're already in the desired page
+
+	ldx	RTCLOK + 2
+	sta	SDLSTH
+
+	; Wait until next VBLANK
+wait:	cpx	RTCLOK + 2
+	beq	wait
+
+	; Done
+done:	rts
+.endproc
+
+; ******************************************************************************
+
+.proc SETDRAWPAGE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETDRAWPAGE, page in A
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	tax
+	beq	cont
+	lda	#32
+cont:	add	p0scr
+	sta	SAVMSC + 1
+	rts
+.endproc
+.endif
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Unimplemented functions that require an error code
+	;
+	; ----------------------------------------------------------------------
+
+CONTROL:
+	lda	#TGI_ERR_INV_FUNC
+	sta	error
+	; fall through
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Unimplemented functions that don't require an error code
+	;
+	; ----------------------------------------------------------------------
+
+INSTALL:
+UNINSTALL:
+
+.if pages = 1
+SETVIEWPAGE:
+SETDRAWPAGE:
+.endif
+
+        rts
diff --git a/libsrc/atari/tgi/atr10p2.s b/libsrc/atari/tgi/atr10p2.s
new file mode 100644
index 000000000..e29ff601c
--- /dev/null
+++ b/libsrc/atari/tgi/atr10p2.s
@@ -0,0 +1,79 @@
+;
+; Graphics driver for the 80x192x9 (CIO mode 10, ANTIC mode F, GTIA mode $80) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 10
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 9
+; Pixels per byte
+	ppb = 2
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0330				; based on 4/3 display
+; Free memory needed
+	mem_needed = 15339
+; Number of screen pages
+	pages = 2
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11110000, %00001111
+	masks:					; Color masks
+		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00001111, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96, $68, $C4, $74, $EE, $4A
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	sta	PCOLR0,y
+	dey
+	bpl     loop
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atr15p2.s b/libsrc/atari/tgi/atr15p2.s
new file mode 100644
index 000000000..a3cdd7726
--- /dev/null
+++ b/libsrc/atari/tgi/atr15p2.s
@@ -0,0 +1,88 @@
+;
+; Graphics driver for the 160x192x2 (CIO mode 15, ANTIC mode E) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 15
+; X resolution
+	x_res = 160
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 4
+; Pixels per byte
+	ppb = 4
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0198				; based on 4/3 display
+; Free memory needed
+	mem_needed = 15339
+; Number of screen pages
+	pages = 2
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11000000, %00110000, %00001100, %00000011
+	masks:					; Color masks
+		.byte	%00000000, %01010101, %10101010, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00111111, %00001111, %00000011, %00000000
+	default_palette:
+		.byte	$00, $0E, $32, $96
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR4
+	lda	palette + 1
+	sta	COLOR0
+	lda	palette + 2
+	sta	COLOR1
+	lda	palette + 3
+	sta	COLOR2
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atr8p2.s b/libsrc/atari/tgi/atr8p2.s
new file mode 100644
index 000000000..162aa4460
--- /dev/null
+++ b/libsrc/atari/tgi/atr8p2.s
@@ -0,0 +1,83 @@
+;
+; Graphics driver for the 320x192x2 (CIO mode 8, ANTIC mode F) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 8
+; X resolution
+	x_res = 320
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 2
+; Pixels per byte
+	ppb = 8
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $00CC				; based on 4/3 display
+; Free memory needed
+	mem_needed = 15339
+; Number of screen pages
+	pages = 2
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%10000000, %01000000, %00100000, %00010000, %00001000, %00000100, %00000010, %00000001
+	masks:					; Color masks
+		.byte	%00000000, %11111111
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %01111111, %00111111, %00011111, %00001111, %00000111, %00000011, %00000001, %00000000
+	default_palette:
+		.byte	$00, $0E
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; Copy the palette
+	ldy     #colors - 1
+loop:	lda     (ptr1),y
+	sta     palette,y
+	dey
+	bpl     loop
+
+	; Get the color entries from the palette
+	lda	palette
+	sta	COLOR2
+	lda	palette + 1
+	sta	COLOR1
+
+	; Done, reset the error code
+        lda     #TGI_ERR_OK
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atari/tgi/atr9p2.s b/libsrc/atari/tgi/atr9p2.s
new file mode 100644
index 000000000..f8418f112
--- /dev/null
+++ b/libsrc/atari/tgi/atr9p2.s
@@ -0,0 +1,71 @@
+;
+; Graphics driver for the 80x192x16b (CIO mode 9, ANTIC mode F, GTIA mode $40) on the Atari.
+;
+; Fatih Aygun (2009)
+;
+
+	.include	"atari.inc"
+	.include 	"zeropage.inc"
+
+	.include 	"tgi-kernel.inc"
+	.include        "tgi-error.inc"
+
+	.macpack        generic
+
+; ******************************************************************************
+
+	; ----------------------------------------------------------------------
+	;
+	; Constants and tables
+	;
+	; ----------------------------------------------------------------------
+
+; Graphics mode
+	grmode = 9
+; X resolution
+	x_res = 80
+; Y resolution
+	y_res = 192
+; Number of colors
+	colors = 16
+; Pixels per byte
+	ppb = 2
+; Screen memory size in bytes
+	scrsize = x_res * y_res / ppb
+; Pixel aspect ratio
+	aspect = $0330				; based on 4/3 display
+; Free memory needed
+	mem_needed = 15339
+; Number of screen pages
+	pages = 2
+
+.rodata
+	mask_table:				; Mask table to set pixels
+		.byte	%11110000, %00001111
+	masks:					; Color masks
+		.byte	$00, $11, $22, $33, $44, $55, $66, $77, $88, $99, $aa, $bb, $cc, $dd, $ee, $ff
+	bar_table:				; Mask table for BAR
+		.byte	%11111111, %00001111, %00000000
+	default_palette:
+		.byte	$00, $0F, $01, $02, $03, $04, $05, $06, $07, $08, $09, $0A, $0B, $0C, $0D, $0E
+
+.code
+
+; ******************************************************************************
+
+.proc SETPALETTE
+
+	; ----------------------------------------------------------------------
+	;
+	; SETPALETTE: Set the palette (in ptr1)
+	;
+	; ----------------------------------------------------------------------
+
+.code
+	; No palettes
+        lda     #TGI_ERR_INV_FUNC
+        sta     error
+        rts
+.endproc
+
+.include "atari_tgi_common.inc"
diff --git a/libsrc/atmos/Makefile b/libsrc/atmos/Makefile
deleted file mode 100644
index 6aa68c1c3..000000000
--- a/libsrc/atmos/Makefile
+++ /dev/null
@@ -1,141 +0,0 @@
-#
-# makefile for CC65 runtime library
-#
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= atmos
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	%.c
-	@$(CC) $(CFLAGS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-mou.o: %.mou
-	@$(CO) -o $(*)-mou.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-mou.s
-
-%-ser.o: %.ser
-	@$(CO) -o $(*)-ser.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-ser.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.mou:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.ser:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-#--------------------------------------------------------------------------
-# Object files
-
-OBJS  =	_scrsize.o              \
-        atmos_load.o            \
-        atmos_save.o            \
-        cclear.o                \
-        cgetc.o                 \
-        chline.o                \
-        clock.o                 \
-        clrscr.o                \
-        color.o                 \
-        cputc.o                 \
-        crt0.o                  \
-        ctype.o                 \
-        cvline.o                \
-        gotox.o                 \
-        gotoxy.o                \
-        gotoy.o                 \
-        irq.o                   \
-        joy_stat_stddrv.o       \
-        joy_stddrv.o            \
-        kbhit.o                 \
-        mainargs.o              \
-        oserrlist.o             \
-        oserror.o               \
-        revers.o                \
-        store_filename.o        \
-        systime.o               \
-        sysuname.o              \
-        tgi_colors.o            \
-        tgi_stat_stddrv.o       \
-        tgi_stddrv.o            \
-        toascii.o               \
-        wherex.o                \
-        wherey.o                \
-        write.o                 \
-        $(EMDS:.emd=-emd.o)     \
-        $(JOYS:.joy=-joy.o)     \
-        $(MOUS:.mou=-mou.o)     \
-        $(SERS:.ser=-ser.o)     \
-        $(TGIS:.tgi=-tgi.o)
-
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS =
-
-JOYS = atmos-pase.joy
-
-MOUS =
-
-SERS = atmos-acia.ser
-
-TGIS = atmos-240-200-2.tgi atmos-228-200-3.tgi
-
-#--------------------------------------------------------------------------
-# Targets
-
-.PHONY:	all clean zap
-
-all: 	$(OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(MOUS:.mou=.o) $(MOUS:.mou=-mou.s) \
-	       $(SERS:.ser=.o) $(SERS:.ser=-ser.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
diff --git a/libsrc/atmos/atmos-228-200-3.s b/libsrc/atmos/atmos-228-200-3.s
deleted file mode 100644
index 03a9ce7df..000000000
--- a/libsrc/atmos/atmos-228-200-3.s
+++ /dev/null
@@ -1,426 +0,0 @@
-;
-; Graphics driver for the 228x200x3 palette mode on the Atmos
-;
-; Stefan Haubenthal 
-; 2012-08-11, Greg King 
-;
-
-	.include	"zeropage.inc"
-
-	.include	"tgi-kernel.inc"
-	.include	"tgi-error.inc"
-	.include	"atmos.inc"
-
-	.macpack	generic
-
-XSIZE	=	6		; System font width
-YSIZE	=	8		; System font height
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table and constants.
-
-.segment	"JUMPTABLE"
-
-; The first part of the header is a structure that has a signature,
-; and defines the capabilities of the driver.
-
-	.byte	"tgi"
-	.byte	TGI_API_VERSION	; TGI API version number
-	.word	228		; x resolution
-	.word	200		; y resolution
-	.byte	3		; Number of drawing colors
-	.byte	1		; Number of screens available
-	.byte	XSIZE		; System font x size
-	.byte	YSIZE		; System font y size
-	.word	$011C		; Aspect ratio (based on 4/3 display)
-	.byte	0		; TGI driver flags
-
-; Next comes the jump table. Currently, all entries must be valid;
-; and, may point to an RTS, for test versions (function not implemented).
-
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	INIT
-	.addr	DONE
-	.addr	GETERROR
-	.addr	CONTROL
-	.addr	CLEAR
-	.addr	SETVIEWPAGE
-	.addr	SETDRAWPAGE
-	.addr	SETCOLOR
-	.addr	SETPALETTE
-	.addr	GETPALETTE
-	.addr	GETDEFPALETTE
-	.addr	SETPIXEL
-	.addr	GETPIXEL
-	.addr	LINE
-	.addr	BAR
-	.addr	TEXTSTYLE
-	.addr	OUTTEXT
-	.addr	0		; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-; Data.
-
-; Variables mapped to the zero-page segment variables. These are
-; used for passing parameters to the driver.
-
-X1	:=	ptr1
-Y1	:=	ptr2
-X2	:=	ptr3
-Y2	:=	ptr4
-
-; Absolute variables used in the code
-
-.bss
-
-ERROR:		.res	1	; Error code
-MODE:		.res	1	; Graphics mode
-PALETTE:	.res	2
-
-; Constants and table
-; BASIC 1.1 addresses
-PATTERN	:=	$213
-PARAM1	:=	$2E1		; & $2E2
-PARAM2	:=	$2E3		; & $2E4
-PARAM3	:=	$2E5		; & $2E6
-TEXT	:=	$EC21
-HIRES	:=	$EC33
-CURSET	:=	$F0C8
-CURMOV	:=	$F0FD
-DRAW	:=	$F110
-CHAR	:=	$F12D
-POINT	:=	$F1C8
-PAPER	:=	$F204
-INK	:=	$F210
-
-.rodata
-
-; Default colors: black background, white foreground
-; (The third "color" actually flips a pixel
-; between the foreground and background colors.)
-;
-DEFPALETTE:	.byte	0, 1
-
-.code
-
-; ------------------------------------------------------------------------
-; INIT: Changes an already installed device from text mode to graphics mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is called only once. So, any code that is needed
-; to initialize variables and so on must go here. Setting palette and
-; clearing the screen are not needed because they are called by the graphics
-; kernel later.
-; The graphics kernel never will call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-;
-; Must set an error code: YES
-;
-
-INIT:
-
-; Switch into graphics mode.
-
-	jsr	HIRES
-
-; Done, reset the error code.
-
-; ------------------------------------------------------------------------
-; GETERROR: Return the error code in A, and clear it.
-
-GETERROR:
-	ldx	#TGI_ERR_OK
-	lda	ERROR
-	stx	ERROR
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-;
-; Must set an error code: NO
-;
-
-INSTALL:
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL, but probably is empty most of the time.
-;
-; Must set an error code: NO
-;
-
-UNINSTALL:
-	rts
-
-; ------------------------------------------------------------------------
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel never will call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-;
-; Must set an error code: NO
-;
-
-DONE	:=	TEXT
-
-; ------------------------------------------------------------------------
-; CONTROL: Platform-/driver-specific entry point.
-;
-; Must set an error code: YES
-;
-
-CONTROL:
-	sta	PATTERN
-	lda	#TGI_ERR_OK
-	sta	ERROR
-	rts
-
-; ------------------------------------------------------------------------
-; CLEAR: Clears the screen.
-;
-; Must set an error code: NO
-;
-
-CLEAR	:=	HIRES
-
-; ------------------------------------------------------------------------
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number already is checked to be valid, by the graphics kernel.
-;
-; Must set an error code: NO (will be called only if page OK)
-;
-
-SETVIEWPAGE:
-
-; ------------------------------------------------------------------------
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number already is checked to be valid, by the graphics kernel.
-;
-; Must set an error code: NO (will be called only if page OK)
-;
-
-SETDRAWPAGE:
-	rts
-
-; ------------------------------------------------------------------------
-; SETCOLOR: Set the drawing color (in A). The new color already is checked
-; to be in a valid range (0..maxcolor-1).
-;
-; Must set an error code: NO (will be called only if color OK)
-;
-
-SETCOLOR:
-	sta	MODE
-	rts
-
-; ------------------------------------------------------------------------
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported.
-;
-; Must set an error code: YES
-;
-
-SETPALETTE:
-	ldy	#0
-	jsr	flipcolor
-	sty	PARAM1+1
-	jsr	PAPER
-	ldy	#1
-	jsr	flipcolor
-	dey			; TGI_ERR_OK
-	sty	ERROR
-	sty	PARAM1+1
-	jmp	INK
-
-flipcolor:
-	lda	(ptr1),y
-	sta	PALETTE,y
-	cmp	#1
-	beq	@flip
-	cmp	#7
-	bne	@keep
-@flip:	eor	#1 ^ 7
-@keep:	sta	PARAM1
-	rts
-
-; ------------------------------------------------------------------------
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-;
-; Must set an error code: NO
-;
-
-GETPALETTE:
-	lda	#PALETTE
-	rts
-
-; ------------------------------------------------------------------------
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes; otherwise, the caller has no way to determine the colors
-; of the (not changeable) palette.
-;
-; Must set an error code: NO (all drivers must have a default palette)
-;
-
-GETDEFPALETTE:
-	lda	#DEFPALETTE
-	rts
-
-; ------------------------------------------------------------------------
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The co-ordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-;
-; Must set an error code: NO
-;
-
-SETPIXEL:
-	lda	Y1
-	sta	PARAM2
-	lda	MODE
-mymode:	sta	PARAM3
-	lda	X1
-	add	#2 * XSIZE	; Skip screen attribute columns
-	sta	PARAM1
-	lda	#0
-	sta	PARAM1+1
-	sta	PARAM2+1
-	sta	PARAM3+1
-	jmp	CURSET
-
-; ------------------------------------------------------------------------
-; GETPIXEL: Read the color value of a pixel, and return it in A/X. The
-; co-ordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-
-GETPIXEL:
-	lda	X1
-	sta	PARAM1
-	lda	Y1
-	sta	PARAM2
-	lda	#0
-	sta	PARAM1+1
-	sta	PARAM2+1
-	jsr	POINT
-	lda	PARAM1
-	and	#%00000001
-	ldx	#0
-	rts
-
-; ------------------------------------------------------------------------
-; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
-; X2/Y2 = ptr3/ptr4, using the current drawing color.
-;
-; Must set an error code: NO
-;
-
-LINE:
-	jsr	SETPIXEL
-	lda	X2
-	sub	X1
-	sta	PARAM1
-	lda	X2+1
-	sbc	X1+1
-	sta	PARAM1+1
-	lda	Y2
-	sub	Y1
-	sta	PARAM2
-	lda	Y2+1
-	sbc	Y1+1
-	sta	PARAM2+1
-	lda	MODE
-	sta	PARAM3
-	ldx	#>0
-	stx	PARAM3+1
-	jmp	DRAW
-
-; ------------------------------------------------------------------------
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4, using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the co-ordinates before calling the driver; so, on entry, the following
-; conditions are valid:
-;	X1 <= X2
-;	Y1 <= Y2
-;	(X1 >= 0) && (X1 < XRES)
-;	(X2 >= 0) && (X2 < XRES)
-;	(Y1 >= 0) && (Y1 < YRES)
-;	(Y2 >= 0) && (Y2 < YRES)
-;
-; Must set an error code: NO
-;
-
-BAR:
-	inc	Y2
-@L1:	lda	Y2
-	pha
-	lda	Y1
-	sta	Y2
-	jsr	LINE
-	pla
-	sta	Y2
-	inc	Y1
-	cmp	Y1
-	bne	@L1
-	rts
-
-; ------------------------------------------------------------------------
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in the x
-; and y directions is passend in X/Y, the text direction is passed in A.
-;
-; Must set an error code: NO
-;
-
-TEXTSTYLE:
-	rts
-
-
-; ------------------------------------------------------------------------
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero-terminated
-; string with its address in ptr3.
-;
-; Must set an error code: NO
-;
-
-OUTTEXT:
-	lda	Y1
-	sub	#(YSIZE - 1)
-	sta	PARAM2
-	lda	#3		; (Move graphics cursor; don't draw)
-	jsr	mymode
-
-	ldy	#0
-@next:	lda	(ptr3),y
-	beq	@end
-	sta	PARAM1
-	lda	#0
-	sta	PARAM2
-	sta	PARAM1+1
-	sta	PARAM2+1
-	sta	PARAM3+1
-	lda	MODE
-	sta	PARAM3
-	tya
-	pha
-	jsr	CHAR
-	lda	#XSIZE
-	sta	PARAM1
-	lda	#0
-	sta	PARAM2
-	sta	PARAM1+1
-	sta	PARAM2+1
-	sta	PARAM3+1
-	lda	#3
-	sta	PARAM3
-	jsr	CURMOV
-	pla
-	tay
-	iny
-	bne	@next
-@end:	rts
diff --git a/libsrc/atmos/atmos-240-200-2.s b/libsrc/atmos/atmos-240-200-2.s
deleted file mode 100644
index 9027b3340..000000000
--- a/libsrc/atmos/atmos-240-200-2.s
+++ /dev/null
@@ -1,403 +0,0 @@
-;
-; Graphics driver for the 240x200x2 monochrome mode on the Atmos
-;
-; Stefan Haubenthal 
-; 2012-08-11, Greg King 
-;
-
-	.include	"zeropage.inc"
-
-	.include	"tgi-kernel.inc"
-	.include	"tgi-error.inc"
-	.include	"atmos.inc"
-
-	.macpack	generic
-
-XSIZE	=	6			; System font width
-YSIZE	=	8			; System font height
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table and constants.
-
-.segment	"JUMPTABLE"
-
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
-
-	.byte	$74, $67, $69		; "tgi"
-	.byte	TGI_API_VERSION		; TGI API version number
-	.word	240			; X resolution
-	.word	200			; Y resolution
-	.byte	2			; Number of drawing colors
-	.byte	1			; Number of screens available
-	.byte	XSIZE			; System font X size
-	.byte	YSIZE			; System font Y size
-        .word   $011C                   ; Aspect ratio (based on 4/3 display)
-        .byte   0                       ; TGI driver flags
-
-; Next comes the jump table. Currently all entries must be valid and may point
-; to an RTS for test versions (function not implemented).
-
-       	.addr   INSTALL
-       	.addr   UNINSTALL
-       	.addr   INIT
-       	.addr   DONE
-       	.addr   GETERROR
-       	.addr   CONTROL
-       	.addr   CLEAR
-       	.addr   SETVIEWPAGE
-       	.addr   SETDRAWPAGE
-       	.addr   SETCOLOR
-       	.addr   SETPALETTE
-       	.addr   GETPALETTE
-       	.addr   GETDEFPALETTE
-       	.addr   SETPIXEL
-       	.addr   GETPIXEL
-       	.addr   LINE
-       	.addr   BAR
-       	.addr   TEXTSTYLE
-       	.addr   OUTTEXT
-        .addr   0                       ; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-; Data.
-
-; Variables mapped to the zero page segment variables. Some of these are
-; used for passing parameters to the driver.
-
-X1		= ptr1
-Y1		= ptr2
-X2		= ptr3
-Y2		= ptr4
-
-; Absolute variables used in the code
-
-.bss
-
-ERROR:		.res	1	; Error code
-MODE:		.res	1	; Graphics mode
-
-; Constants and tables
-PARAM1		= $2E1
-PARAM2		= $2E3
-PARAM3		= $2E5
-TEXT		= $EC21
-HIRES		= $EC33
-CURSET		= $F0C8
-CURMOV		= $F0FD
-DRAW		= $F110
-CHAR		= $F12D
-POINT		= $F1C8
-PAPER		= $F204
-INK		= $F210
-
-.rodata
-
-DEFPALETTE:	.byte	0, 1
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-;
-; Must set an error code: NO
-;
-
-INSTALL:
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL but is probably empty most of the time.
-;
-; Must set an error code: NO
-;
-
-UNINSTALL:
-	rts
-
-; ------------------------------------------------------------------------
-; INIT: Changes an already installed device from text mode to graphics
-; mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is only called once, so any code that is needed
-; to initializes variables and so on must go here. Setting palette and
-; clearing the screen is not needed because this is called by the graphics
-; kernel later.
-; The graphics kernel will never call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-;
-; Must set an error code: YES
-;
-
-INIT:
-
-; Switch into graphics mode
-
-	jsr	HIRES
-
-; Done, reset the error code
-
-	lda	#TGI_ERR_OK
-	sta	ERROR
-	rts
-
-; ------------------------------------------------------------------------
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel will never call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-;
-; Must set an error code: NO
-;
-
-DONE		= TEXT
-
-; ------------------------------------------------------------------------
-; GETERROR: Return the error code in A and clear it.
-
-GETERROR:
-	ldx	#TGI_ERR_OK
-	lda	ERROR
-	stx	ERROR
-	rts
-
-; ------------------------------------------------------------------------
-; CONTROL: Platform/driver specific entry point.
-;
-; Must set an error code: YES
-;
-
-CONTROL:
-	sta	$213
-	lda	#TGI_ERR_OK
-	sta	ERROR
-	rts
-
-; ------------------------------------------------------------------------
-; CLEAR: Clears the screen.
-;
-; Must set an error code: NO
-;
-
-CLEAR		= HIRES
-
-; ------------------------------------------------------------------------
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETVIEWPAGE:
-
-; ------------------------------------------------------------------------
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETDRAWPAGE:
-	rts
-
-; ------------------------------------------------------------------------
-; SETCOLOR: Set the drawing color (in A). The new color is already checked
-; to be in a valid range (0..maxcolor-1).
-;
-; Must set an error code: NO (will only be called if color ok)
-;
-
-SETCOLOR:
-	sta	MODE
-	rts
-
-; ------------------------------------------------------------------------
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported
-;
-; Must set an error code: YES
-;
-
-SETPALETTE:
-	lda	#TGI_ERR_INV_FUNC	; This resolution has no palette
-	sta	ERROR
-	rts
-
-; ------------------------------------------------------------------------
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-;
-; Must set an error code: NO
-;
-
-GETPALETTE:
-
-; ------------------------------------------------------------------------
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes, otherwise the caller has no way to determine the colors
-; of the (not changeable) palette.
-;
-; Must set an error code: NO (all drivers must have a default palette)
-;
-
-GETDEFPALETTE:
-	lda	#DEFPALETTE
-	rts
-
-; ------------------------------------------------------------------------
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The coordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-;
-; Must set an error code: NO
-;
-
-SETPIXEL:
-	lda	Y1
-	sta	PARAM2
-	lda	MODE
-mymode:	sta	PARAM3
-	lda	X1
-	sta	PARAM1
-	lda	#0
-	sta	PARAM1+1
-	sta	PARAM2+1
-	sta	PARAM3+1
-	jmp	CURSET
-
-; ------------------------------------------------------------------------
-; GETPIXEL: Read the color value of a pixel and return it in A/X. The
-; coordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-
-GETPIXEL:
-	lda	X1
-	sta	PARAM1
-	lda	Y1
-	sta	PARAM2
-	lda	#0
-	sta	PARAM1+1
-	sta	PARAM2+1
-	jsr	POINT
-	lda	PARAM1
-	and	#%00000001
-	ldx	#0
-	rts
-
-; ------------------------------------------------------------------------
-; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
-; X2/Y2 = ptr3/ptr4 using the current drawing color.
-;
-; Must set an error code: NO
-;
-
-LINE:
-	jsr	SETPIXEL
-	lda	X2
-	sub	X1
-	sta	PARAM1
-	lda	X2+1
-	sbc	X1+1
-	sta	PARAM1+1
-	lda	Y2
-	sub	Y1
-	sta	PARAM2
-	lda	Y2+1
-	sbc	Y1+1
-	sta	PARAM2+1
-	lda	MODE
-	sta	PARAM3
-	ldx	#>0
-	stx	PARAM3+1
-	jmp	DRAW
-
-; ------------------------------------------------------------------------
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the coordinates before calling the driver, so on entry the following
-; conditions are valid:
-;	X1 <= X2
-;	Y1 <= Y2
-;	(X1 >= 0) && (X1 < XRES)
-;	(X2 >= 0) && (X2 < XRES)
-;	(Y1 >= 0) && (Y1 < YRES)
-;	(Y2 >= 0) && (Y2 < YRES)
-;
-; Must set an error code: NO
-;
-
-BAR:
-	inc	Y2
-@L1:	lda	Y2
-	pha
-  	lda	Y1
-	sta	Y2
-	jsr	LINE
-	pla
-	sta	Y2
-	inc	Y1
-	cmp	Y1
-	bne	@L1
-	rts
-
-; ------------------------------------------------------------------------
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
-; direction is passend in X/Y, the text direction is passed in A.
-;
-; Must set an error code: NO
-;
-
-TEXTSTYLE:
-	rts
-
-
-; ------------------------------------------------------------------------
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero terminated
-; string with address in ptr3.
-;
-; Must set an error code: NO
-;
-
-OUTTEXT:
-	lda	Y1
-	sub	#(YSIZE - 1)
-	sta	PARAM2
-	lda	#3		; (Move graphics cursor; don't draw)
-	jsr	mymode
-
-	ldy	#0
-@next:	lda	(ptr3),y
-	beq	@end
-	sta	PARAM1
-	lda	#0
-	sta	PARAM2
-	sta	PARAM1+1
-	sta	PARAM2+1
-	sta	PARAM3+1
-	lda	MODE
-	sta	PARAM3
-	tya
-	pha
-	jsr	CHAR
-	lda	#XSIZE
-	sta	PARAM1
-	lda	#0
-	sta	PARAM2
-	sta	PARAM1+1
-	sta	PARAM2+1
-	sta	PARAM3+1
-	lda	#3
-	sta	PARAM3
-	jsr	CURMOV
-	pla
-	tay
-	iny
-	bne	@next
-@end:	rts
diff --git a/libsrc/atmos/atmos-acia.s b/libsrc/atmos/atmos-acia.s
deleted file mode 100644
index c2b48c9fc..000000000
--- a/libsrc/atmos/atmos-acia.s
+++ /dev/null
@@ -1,374 +0,0 @@
-;
-; Serial driver for the Telestrat integrated serial controller and the
-; Atmos with a serial add-on.
-;
-; Stefan Haubenthal, 2012-03-05
-;
-; The driver is based on the cc65 rs232 module, which in turn is based on
-; Craig Bruce device driver for the Switftlink/Turbo-232.
-;
-; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
-;
-; This software is Public Domain.  It is in Buddy assembler format.
-;
-; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
-; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
-; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
-; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
-;
-; The code assumes that the kernal + I/O are in context.  On the C128, call
-; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
-; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
-; interrupt handling assumes that the 65816 is in 6502-emulation mode.
-;
-
-	.include	"zeropage.inc"
-	.include	"ser-kernel.inc"
-	.include	"ser-error.inc"
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-	.segment	"JUMPTABLE"
-
-	; Driver signature
-	.byte	$73, $65, $72		; "ser"
-	.byte	SER_API_VERSION		; Serial API version number
-
-	; Jump table.
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	OPEN
-	.addr	CLOSE
-	.addr	GET
-	.addr	PUT
-	.addr	STATUS
-	.addr	IOCTL
-	.addr	IRQ
-
-;----------------------------------------------------------------------------
-; I/O definitions
-
-ACIA		= $031C
-ACIA_DATA	= ACIA+0	; Data register
-ACIA_STATUS	= ACIA+1	; Status register
-ACIA_CMD	= ACIA+2	; Command register
-ACIA_CTRL	= ACIA+3	; Control register
-
-;----------------------------------------------------------------------------
-; Global variables
-
-	.bss
-
-RecvHead:	.res	1	; Head of receive buffer
-RecvTail:	.res	1	; Tail of receive buffer
-RecvFreeCnt:	.res	1	; Number of bytes in receive buffer
-SendHead:	.res	1	; Head of send buffer
-SendTail:	.res	1	; Tail of send buffer
-SendFreeCnt:	.res	1	; Number of bytes in send buffer
-
-Stopped:	.res	1	; Flow-stopped flag
-RtsOff:		.res	1	;
-
-RecvBuf:	.res	256	; Receive buffers: 256 bytes
-SendBuf:	.res	256	; Send buffers: 256 bytes
-
-Index:		.res	1	; I/O register index
-
-	.rodata
-
-	; Tables used to translate RS232 params into register values
-BaudTable:			; bit7 = 1 means setting is invalid
-	.byte	$FF		; SER_BAUD_45_5
-	.byte	$01		; SER_BAUD_50
-	.byte	$02		; SER_BAUD_75
-	.byte	$03		; SER_BAUD_110
-	.byte	$04		; SER_BAUD_134_5
-	.byte	$05		; SER_BAUD_150
-	.byte	$06		; SER_BAUD_300
-	.byte	$07		; SER_BAUD_600
-	.byte	$08		; SER_BAUD_1200
-	.byte	$09		; SER_BAUD_1800
-	.byte	$0A		; SER_BAUD_2400
-	.byte	$0B		; SER_BAUD_3600
-	.byte	$0C		; SER_BAUD_4800
-	.byte	$0D		; SER_BAUD_7200
-	.byte	$0E		; SER_BAUD_9600
-	.byte	$0F		; SER_BAUD_19200
-	.byte	$FF		; SER_BAUD_38400
-	.byte	$FF		; SER_BAUD_57600
-	.byte	$FF		; SER_BAUD_115200
-	.byte	$FF		; SER_BAUD_230400
-BitTable:
-	.byte	$60		; SER_BITS_5
-	.byte	$40		; SER_BITS_6
-	.byte	$20		; SER_BITS_7
-	.byte	$00		; SER_BITS_8
-StopTable:
-	.byte	$00		; SER_STOP_1
-	.byte	$80		; SER_STOP_2
-ParityTable:
-	.byte	$00		; SER_PAR_NONE
-	.byte	$20		; SER_PAR_ODD
-	.byte	$60		; SER_PAR_EVEN
-	.byte	$A0		; SER_PAR_MARK
-	.byte	$E0		; SER_PAR_SPACE
-
-	.code
-
-;----------------------------------------------------------------------------
-; INSTALL: Is called after the driver is loaded into memory. If possible,
-; check if the hardware is present. Must return an SER_ERR_xx code in a/x.
-;
-; Since we don't have to manage the IRQ vector on the Telestrat/Atmos, this is
-; actually the same as:
-;
-; UNINSTALL: Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-;
-; and:
-;
-; CLOSE: Close the port and disable interrupts. Called without parameters.
-; Must return an SER_ERR_xx code in a/x.
-
-INSTALL:
-UNINSTALL:
-CLOSE:
-	ldx	Index		; Check for open port
-	beq	:+
-
-	; Deactivate DTR and disable 6551 interrupts
-	lda	#%00001010
-	sta	ACIA_CMD,x
-
-	; Done, return an error code
-:	lda	#SER_ERR_INIT_FAILED
-	rts
-
-	; Baud rate not available
-InvBaud:lda	#SER_ERR_BAUD_UNAVAIL
-	rts
-
-;----------------------------------------------------------------------------
-; GET: Will fetch a character from the receive buffer and store it into the
-; variable pointed to by ptr1. If no data is available, SER_ERR_NO_DATA is
-; returned.
-
-GET:
-	ldy	SendFreeCnt	; Send data if necessary
-	iny			; Y == $FF?
-	beq	:+
-	lda	#$00		; TryHard = false
-	jsr	TryToSend
-
-	; Check for buffer empty
-:	lda	RecvFreeCnt	; (25)
-	cmp	#$FF
-	bne	:+
-	lda	#SER_ERR_NO_DATA
-	rts
-
-	; Check for flow stopped & enough free: release flow control
-:	ldy	Stopped		; (34)
-	beq	:+
-	cmp	#63
-	bcc	:+
-	lda	#$00
-	sta	Stopped
-	lda	RtsOff
-	ora	#%00001000
-	sta	ACIA_CMD
-
-	; Get byte from buffer
-:	ldy	RecvHead	; (41)
-	lda	RecvBuf,y
-	inc	RecvHead
-	inc	RecvFreeCnt
-	ldx	#$00		; (59)
-	sta	(ptr1,x)
-	txa			; Return code = 0
-	rts
-
-;----------------------------------------------------------------------------
-; PUT: Output character in A.
-; Must return an SER_ERR_xx code in a/x.
-
-PUT:
-	; Try to send
-	ldy	SendFreeCnt
-	iny			; Y = $FF?
-	beq	:+
-	pha
-	lda	#$00		; TryHard = false
-	jsr	TryToSend
-	pla
-
-	; Put byte into send buffer & send
-:	ldy	SendFreeCnt
-	bne	:+
-	lda	#SER_ERR_OVERFLOW
-	rts
-
-:	ldy	SendTail
-	sta	SendBuf,y
-	inc	SendTail
-	dec	SendFreeCnt
-	lda	#$FF		; TryHard = true
-	jsr	TryToSend
-	lda	#SER_ERR_INV_IOCTL
-	rts
-
-;----------------------------------------------------------------------------
-; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
-; registers are already saved, no parameters are passed, but the carry flag
-; is clear on entry. The routine must return with carry set if the interrupt
-; was handled, otherwise with carry clear.
-
-IRQ:
-	ldx	Index		; Check for open port
-	beq	Done
-	lda	ACIA_STATUS,x	; Check ACIA status for receive interrupt
-	and	#$08
-	beq	Done		; Jump if no ACIA interrupt
-	lda	ACIA_DATA,x	; Get byte from ACIA
-	ldy	RecvFreeCnt	; Check if we have free space left
-	beq	Flow		; Jump if no space in receive buffer
-	ldy	RecvTail	; Load buffer pointer
-	sta	RecvBuf,y	; Store received byte in buffer
-	inc	RecvTail	; Increment buffer pointer
-	dec	RecvFreeCnt	; Decrement free space counter
-	ldy	RecvFreeCnt	; Check for buffer space low
-	cpy	#33
-	bcc	Flow		; Assert flow control if buffer space low
-	rts			; Interrupt handled (carry already set)
-
-	; Assert flow control if buffer space too low
-Flow:	lda	RtsOff
-	sta	ACIA_CMD,x
-	sta	Stopped
-	sec			; Interrupt handled
-Done:	rts
-
-;----------------------------------------------------------------------------
-; Try to send a byte. Internal routine. A = TryHard
-
-TryToSend:
-	sta	tmp1		; Remember tryHard flag
-Again:	lda	SendFreeCnt
-	cmp	#$FF
-	beq	Quit		; Bail out
-
-	; Check for flow stopped
-	lda	Stopped
-	bne	Quit		; Bail out
-
-	; Check that ACIA is ready to send
-	lda	ACIA_STATUS
-	and	#$10
-	bne	Send
-	bit	tmp1		; Keep trying if must try hard
-	bmi	Again
-Quit:	rts
-
-	; Send byte and try again
-Send:	ldy	SendHead
-	lda	SendBuf,y
-	sta	ACIA_DATA
-	inc	SendHead
-	inc	SendFreeCnt
-	jmp	Again
diff --git a/libsrc/atmos/atmos-pase.s b/libsrc/atmos/atmos-pase.s
deleted file mode 100644
index 18ac7b887..000000000
--- a/libsrc/atmos/atmos-pase.s
+++ /dev/null
@@ -1,125 +0,0 @@
-;
-; P.A.S.E. joystick driver for the Atmos
-; May be used multiple times when linked to the statically application.
-;
-; Stefan Haubenthal, 2009-12-21
-; Based on Ullrich von Bassewitz, 2002-12-20
-;
-
-	.include	"joy-kernel.inc"
-	.include	"joy-error.inc"
-;	.include	"atmos.inc"
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-; Driver signature
-
-	.byte	$6A, $6F, $79		; "joy"
-	.byte	JOY_API_VERSION		; Driver API version number
-
-; Button state masks (8 values)
-
-	.byte	$10			; JOY_UP
-	.byte	$08			; JOY_DOWN
-	.byte	$01			; JOY_LEFT
-	.byte	$02			; JOY_RIGHT
-	.byte	$20			; JOY_FIRE
-	.byte	$00			; Future expansion
-	.byte	$00			; Future expansion
-	.byte	$00			; Future expansion
-
-; Jump table.
-
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	COUNT
-	.addr	READ
-	.addr	0			; IRQ entry unused
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT	= 2		; Number of joysticks we support
-
-PRA		= $0301
-DDRA		= $0303
-PRA2		= $030F
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-temp1:	.byte	$00
-temp2:	.byte	$00
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-	lda	#JOY_ERR_OK
-	ldx	#0
-;	rts			; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-	rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-	lda	#JOY_COUNT
-	ldx	#0
-	rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:
-	tay
-
-	lda	PRA
-	pha
-	lda	DDRA
-	pha
-	lda	#%11000000
-	sta	DDRA
-	lda	#%10000000
-	sta	PRA2
-	lda	PRA2
-	sta	temp1
-	lda	#%01000000
-	sta	PRA2
-	lda	PRA
-	sta	temp2
-	pla
-	sta	DDRA
-	pla
-	sta	PRA2
-
-	ldx	#0
-	tya
-	bne	@L1
-	lda	temp1
-	eor	#$FF
-	rts
-@L1:	lda	temp2
-	eor	#$FF
-	rts
diff --git a/libsrc/atmos/joy/atmos-pase.s b/libsrc/atmos/joy/atmos-pase.s
new file mode 100644
index 000000000..18ac7b887
--- /dev/null
+++ b/libsrc/atmos/joy/atmos-pase.s
@@ -0,0 +1,125 @@
+;
+; P.A.S.E. joystick driver for the Atmos
+; May be used multiple times when linked to the statically application.
+;
+; Stefan Haubenthal, 2009-12-21
+; Based on Ullrich von Bassewitz, 2002-12-20
+;
+
+	.include	"joy-kernel.inc"
+	.include	"joy-error.inc"
+;	.include	"atmos.inc"
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment	"JUMPTABLE"
+
+; Driver signature
+
+	.byte	$6A, $6F, $79		; "joy"
+	.byte	JOY_API_VERSION		; Driver API version number
+
+; Button state masks (8 values)
+
+	.byte	$10			; JOY_UP
+	.byte	$08			; JOY_DOWN
+	.byte	$01			; JOY_LEFT
+	.byte	$02			; JOY_RIGHT
+	.byte	$20			; JOY_FIRE
+	.byte	$00			; Future expansion
+	.byte	$00			; Future expansion
+	.byte	$00			; Future expansion
+
+; Jump table.
+
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	COUNT
+	.addr	READ
+	.addr	0			; IRQ entry unused
+
+; ------------------------------------------------------------------------
+; Constants
+
+JOY_COUNT	= 2		; Number of joysticks we support
+
+PRA		= $0301
+DDRA		= $0303
+PRA2		= $030F
+
+; ------------------------------------------------------------------------
+; Data.
+
+.bss
+temp1:	.byte	$00
+temp2:	.byte	$00
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an JOY_ERR_xx code in a/x.
+;
+
+INSTALL:
+	lda	#JOY_ERR_OK
+	ldx	#0
+;	rts			; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+	rts
+
+
+; ------------------------------------------------------------------------
+; COUNT: Return the total number of available joysticks in a/x.
+;
+
+COUNT:
+	lda	#JOY_COUNT
+	ldx	#0
+	rts
+
+; ------------------------------------------------------------------------
+; READ: Read a particular joystick passed in A.
+;
+
+READ:
+	tay
+
+	lda	PRA
+	pha
+	lda	DDRA
+	pha
+	lda	#%11000000
+	sta	DDRA
+	lda	#%10000000
+	sta	PRA2
+	lda	PRA2
+	sta	temp1
+	lda	#%01000000
+	sta	PRA2
+	lda	PRA
+	sta	temp2
+	pla
+	sta	DDRA
+	pla
+	sta	PRA2
+
+	ldx	#0
+	tya
+	bne	@L1
+	lda	temp1
+	eor	#$FF
+	rts
+@L1:	lda	temp2
+	eor	#$FF
+	rts
diff --git a/libsrc/atmos/ser/atmos-acia.s b/libsrc/atmos/ser/atmos-acia.s
new file mode 100644
index 000000000..c2b48c9fc
--- /dev/null
+++ b/libsrc/atmos/ser/atmos-acia.s
@@ -0,0 +1,374 @@
+;
+; Serial driver for the Telestrat integrated serial controller and the
+; Atmos with a serial add-on.
+;
+; Stefan Haubenthal, 2012-03-05
+;
+; The driver is based on the cc65 rs232 module, which in turn is based on
+; Craig Bruce device driver for the Switftlink/Turbo-232.
+;
+; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
+;
+; This software is Public Domain.  It is in Buddy assembler format.
+;
+; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
+; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
+; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
+; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
+;
+; The code assumes that the kernal + I/O are in context.  On the C128, call
+; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
+; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
+; interrupt handling assumes that the 65816 is in 6502-emulation mode.
+;
+
+	.include	"zeropage.inc"
+	.include	"ser-kernel.inc"
+	.include	"ser-error.inc"
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+	.segment	"JUMPTABLE"
+
+	; Driver signature
+	.byte	$73, $65, $72		; "ser"
+	.byte	SER_API_VERSION		; Serial API version number
+
+	; Jump table.
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	OPEN
+	.addr	CLOSE
+	.addr	GET
+	.addr	PUT
+	.addr	STATUS
+	.addr	IOCTL
+	.addr	IRQ
+
+;----------------------------------------------------------------------------
+; I/O definitions
+
+ACIA		= $031C
+ACIA_DATA	= ACIA+0	; Data register
+ACIA_STATUS	= ACIA+1	; Status register
+ACIA_CMD	= ACIA+2	; Command register
+ACIA_CTRL	= ACIA+3	; Control register
+
+;----------------------------------------------------------------------------
+; Global variables
+
+	.bss
+
+RecvHead:	.res	1	; Head of receive buffer
+RecvTail:	.res	1	; Tail of receive buffer
+RecvFreeCnt:	.res	1	; Number of bytes in receive buffer
+SendHead:	.res	1	; Head of send buffer
+SendTail:	.res	1	; Tail of send buffer
+SendFreeCnt:	.res	1	; Number of bytes in send buffer
+
+Stopped:	.res	1	; Flow-stopped flag
+RtsOff:		.res	1	;
+
+RecvBuf:	.res	256	; Receive buffers: 256 bytes
+SendBuf:	.res	256	; Send buffers: 256 bytes
+
+Index:		.res	1	; I/O register index
+
+	.rodata
+
+	; Tables used to translate RS232 params into register values
+BaudTable:			; bit7 = 1 means setting is invalid
+	.byte	$FF		; SER_BAUD_45_5
+	.byte	$01		; SER_BAUD_50
+	.byte	$02		; SER_BAUD_75
+	.byte	$03		; SER_BAUD_110
+	.byte	$04		; SER_BAUD_134_5
+	.byte	$05		; SER_BAUD_150
+	.byte	$06		; SER_BAUD_300
+	.byte	$07		; SER_BAUD_600
+	.byte	$08		; SER_BAUD_1200
+	.byte	$09		; SER_BAUD_1800
+	.byte	$0A		; SER_BAUD_2400
+	.byte	$0B		; SER_BAUD_3600
+	.byte	$0C		; SER_BAUD_4800
+	.byte	$0D		; SER_BAUD_7200
+	.byte	$0E		; SER_BAUD_9600
+	.byte	$0F		; SER_BAUD_19200
+	.byte	$FF		; SER_BAUD_38400
+	.byte	$FF		; SER_BAUD_57600
+	.byte	$FF		; SER_BAUD_115200
+	.byte	$FF		; SER_BAUD_230400
+BitTable:
+	.byte	$60		; SER_BITS_5
+	.byte	$40		; SER_BITS_6
+	.byte	$20		; SER_BITS_7
+	.byte	$00		; SER_BITS_8
+StopTable:
+	.byte	$00		; SER_STOP_1
+	.byte	$80		; SER_STOP_2
+ParityTable:
+	.byte	$00		; SER_PAR_NONE
+	.byte	$20		; SER_PAR_ODD
+	.byte	$60		; SER_PAR_EVEN
+	.byte	$A0		; SER_PAR_MARK
+	.byte	$E0		; SER_PAR_SPACE
+
+	.code
+
+;----------------------------------------------------------------------------
+; INSTALL: Is called after the driver is loaded into memory. If possible,
+; check if the hardware is present. Must return an SER_ERR_xx code in a/x.
+;
+; Since we don't have to manage the IRQ vector on the Telestrat/Atmos, this is
+; actually the same as:
+;
+; UNINSTALL: Is called before the driver is removed from memory.
+; No return code required (the driver is removed from memory on return).
+;
+; and:
+;
+; CLOSE: Close the port and disable interrupts. Called without parameters.
+; Must return an SER_ERR_xx code in a/x.
+
+INSTALL:
+UNINSTALL:
+CLOSE:
+	ldx	Index		; Check for open port
+	beq	:+
+
+	; Deactivate DTR and disable 6551 interrupts
+	lda	#%00001010
+	sta	ACIA_CMD,x
+
+	; Done, return an error code
+:	lda	#SER_ERR_INIT_FAILED
+	rts
+
+	; Baud rate not available
+InvBaud:lda	#SER_ERR_BAUD_UNAVAIL
+	rts
+
+;----------------------------------------------------------------------------
+; GET: Will fetch a character from the receive buffer and store it into the
+; variable pointed to by ptr1. If no data is available, SER_ERR_NO_DATA is
+; returned.
+
+GET:
+	ldy	SendFreeCnt	; Send data if necessary
+	iny			; Y == $FF?
+	beq	:+
+	lda	#$00		; TryHard = false
+	jsr	TryToSend
+
+	; Check for buffer empty
+:	lda	RecvFreeCnt	; (25)
+	cmp	#$FF
+	bne	:+
+	lda	#SER_ERR_NO_DATA
+	rts
+
+	; Check for flow stopped & enough free: release flow control
+:	ldy	Stopped		; (34)
+	beq	:+
+	cmp	#63
+	bcc	:+
+	lda	#$00
+	sta	Stopped
+	lda	RtsOff
+	ora	#%00001000
+	sta	ACIA_CMD
+
+	; Get byte from buffer
+:	ldy	RecvHead	; (41)
+	lda	RecvBuf,y
+	inc	RecvHead
+	inc	RecvFreeCnt
+	ldx	#$00		; (59)
+	sta	(ptr1,x)
+	txa			; Return code = 0
+	rts
+
+;----------------------------------------------------------------------------
+; PUT: Output character in A.
+; Must return an SER_ERR_xx code in a/x.
+
+PUT:
+	; Try to send
+	ldy	SendFreeCnt
+	iny			; Y = $FF?
+	beq	:+
+	pha
+	lda	#$00		; TryHard = false
+	jsr	TryToSend
+	pla
+
+	; Put byte into send buffer & send
+:	ldy	SendFreeCnt
+	bne	:+
+	lda	#SER_ERR_OVERFLOW
+	rts
+
+:	ldy	SendTail
+	sta	SendBuf,y
+	inc	SendTail
+	dec	SendFreeCnt
+	lda	#$FF		; TryHard = true
+	jsr	TryToSend
+	lda	#SER_ERR_INV_IOCTL
+	rts
+
+;----------------------------------------------------------------------------
+; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All
+; registers are already saved, no parameters are passed, but the carry flag
+; is clear on entry. The routine must return with carry set if the interrupt
+; was handled, otherwise with carry clear.
+
+IRQ:
+	ldx	Index		; Check for open port
+	beq	Done
+	lda	ACIA_STATUS,x	; Check ACIA status for receive interrupt
+	and	#$08
+	beq	Done		; Jump if no ACIA interrupt
+	lda	ACIA_DATA,x	; Get byte from ACIA
+	ldy	RecvFreeCnt	; Check if we have free space left
+	beq	Flow		; Jump if no space in receive buffer
+	ldy	RecvTail	; Load buffer pointer
+	sta	RecvBuf,y	; Store received byte in buffer
+	inc	RecvTail	; Increment buffer pointer
+	dec	RecvFreeCnt	; Decrement free space counter
+	ldy	RecvFreeCnt	; Check for buffer space low
+	cpy	#33
+	bcc	Flow		; Assert flow control if buffer space low
+	rts			; Interrupt handled (carry already set)
+
+	; Assert flow control if buffer space too low
+Flow:	lda	RtsOff
+	sta	ACIA_CMD,x
+	sta	Stopped
+	sec			; Interrupt handled
+Done:	rts
+
+;----------------------------------------------------------------------------
+; Try to send a byte. Internal routine. A = TryHard
+
+TryToSend:
+	sta	tmp1		; Remember tryHard flag
+Again:	lda	SendFreeCnt
+	cmp	#$FF
+	beq	Quit		; Bail out
+
+	; Check for flow stopped
+	lda	Stopped
+	bne	Quit		; Bail out
+
+	; Check that ACIA is ready to send
+	lda	ACIA_STATUS
+	and	#$10
+	bne	Send
+	bit	tmp1		; Keep trying if must try hard
+	bmi	Again
+Quit:	rts
+
+	; Send byte and try again
+Send:	ldy	SendHead
+	lda	SendBuf,y
+	sta	ACIA_DATA
+	inc	SendHead
+	inc	SendFreeCnt
+	jmp	Again
diff --git a/libsrc/atmos/tgi/atmos-228-200-3.s b/libsrc/atmos/tgi/atmos-228-200-3.s
new file mode 100644
index 000000000..03a9ce7df
--- /dev/null
+++ b/libsrc/atmos/tgi/atmos-228-200-3.s
@@ -0,0 +1,426 @@
+;
+; Graphics driver for the 228x200x3 palette mode on the Atmos
+;
+; Stefan Haubenthal 
+; 2012-08-11, Greg King 
+;
+
+	.include	"zeropage.inc"
+
+	.include	"tgi-kernel.inc"
+	.include	"tgi-error.inc"
+	.include	"atmos.inc"
+
+	.macpack	generic
+
+XSIZE	=	6		; System font width
+YSIZE	=	8		; System font height
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table and constants.
+
+.segment	"JUMPTABLE"
+
+; The first part of the header is a structure that has a signature,
+; and defines the capabilities of the driver.
+
+	.byte	"tgi"
+	.byte	TGI_API_VERSION	; TGI API version number
+	.word	228		; x resolution
+	.word	200		; y resolution
+	.byte	3		; Number of drawing colors
+	.byte	1		; Number of screens available
+	.byte	XSIZE		; System font x size
+	.byte	YSIZE		; System font y size
+	.word	$011C		; Aspect ratio (based on 4/3 display)
+	.byte	0		; TGI driver flags
+
+; Next comes the jump table. Currently, all entries must be valid;
+; and, may point to an RTS, for test versions (function not implemented).
+
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	INIT
+	.addr	DONE
+	.addr	GETERROR
+	.addr	CONTROL
+	.addr	CLEAR
+	.addr	SETVIEWPAGE
+	.addr	SETDRAWPAGE
+	.addr	SETCOLOR
+	.addr	SETPALETTE
+	.addr	GETPALETTE
+	.addr	GETDEFPALETTE
+	.addr	SETPIXEL
+	.addr	GETPIXEL
+	.addr	LINE
+	.addr	BAR
+	.addr	TEXTSTYLE
+	.addr	OUTTEXT
+	.addr	0		; IRQ entry is unused
+
+; ------------------------------------------------------------------------
+; Data.
+
+; Variables mapped to the zero-page segment variables. These are
+; used for passing parameters to the driver.
+
+X1	:=	ptr1
+Y1	:=	ptr2
+X2	:=	ptr3
+Y2	:=	ptr4
+
+; Absolute variables used in the code
+
+.bss
+
+ERROR:		.res	1	; Error code
+MODE:		.res	1	; Graphics mode
+PALETTE:	.res	2
+
+; Constants and table
+; BASIC 1.1 addresses
+PATTERN	:=	$213
+PARAM1	:=	$2E1		; & $2E2
+PARAM2	:=	$2E3		; & $2E4
+PARAM3	:=	$2E5		; & $2E6
+TEXT	:=	$EC21
+HIRES	:=	$EC33
+CURSET	:=	$F0C8
+CURMOV	:=	$F0FD
+DRAW	:=	$F110
+CHAR	:=	$F12D
+POINT	:=	$F1C8
+PAPER	:=	$F204
+INK	:=	$F210
+
+.rodata
+
+; Default colors: black background, white foreground
+; (The third "color" actually flips a pixel
+; between the foreground and background colors.)
+;
+DEFPALETTE:	.byte	0, 1
+
+.code
+
+; ------------------------------------------------------------------------
+; INIT: Changes an already installed device from text mode to graphics mode.
+; Note that INIT/DONE may be called multiple times while the driver
+; is loaded, while INSTALL is called only once. So, any code that is needed
+; to initialize variables and so on must go here. Setting palette and
+; clearing the screen are not needed because they are called by the graphics
+; kernel later.
+; The graphics kernel never will call INIT when a graphics mode is already
+; active, so there is no need to protect against that.
+;
+; Must set an error code: YES
+;
+
+INIT:
+
+; Switch into graphics mode.
+
+	jsr	HIRES
+
+; Done, reset the error code.
+
+; ------------------------------------------------------------------------
+; GETERROR: Return the error code in A, and clear it.
+
+GETERROR:
+	ldx	#TGI_ERR_OK
+	lda	ERROR
+	stx	ERROR
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. May
+; initialize anything that has to be done just once. Is probably empty
+; most of the time.
+;
+; Must set an error code: NO
+;
+
+INSTALL:
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory. May
+; clean up anything done by INSTALL, but probably is empty most of the time.
+;
+; Must set an error code: NO
+;
+
+UNINSTALL:
+	rts
+
+; ------------------------------------------------------------------------
+; DONE: Will be called to switch the graphics device back into text mode.
+; The graphics kernel never will call DONE when no graphics mode is active,
+; so there is no need to protect against that.
+;
+; Must set an error code: NO
+;
+
+DONE	:=	TEXT
+
+; ------------------------------------------------------------------------
+; CONTROL: Platform-/driver-specific entry point.
+;
+; Must set an error code: YES
+;
+
+CONTROL:
+	sta	PATTERN
+	lda	#TGI_ERR_OK
+	sta	ERROR
+	rts
+
+; ------------------------------------------------------------------------
+; CLEAR: Clears the screen.
+;
+; Must set an error code: NO
+;
+
+CLEAR	:=	HIRES
+
+; ------------------------------------------------------------------------
+; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
+; The page number already is checked to be valid, by the graphics kernel.
+;
+; Must set an error code: NO (will be called only if page OK)
+;
+
+SETVIEWPAGE:
+
+; ------------------------------------------------------------------------
+; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
+; The page number already is checked to be valid, by the graphics kernel.
+;
+; Must set an error code: NO (will be called only if page OK)
+;
+
+SETDRAWPAGE:
+	rts
+
+; ------------------------------------------------------------------------
+; SETCOLOR: Set the drawing color (in A). The new color already is checked
+; to be in a valid range (0..maxcolor-1).
+;
+; Must set an error code: NO (will be called only if color OK)
+;
+
+SETCOLOR:
+	sta	MODE
+	rts
+
+; ------------------------------------------------------------------------
+; SETPALETTE: Set the palette (not available with all drivers/hardware).
+; A pointer to the palette is passed in ptr1. Must set an error if palettes
+; are not supported.
+;
+; Must set an error code: YES
+;
+
+SETPALETTE:
+	ldy	#0
+	jsr	flipcolor
+	sty	PARAM1+1
+	jsr	PAPER
+	ldy	#1
+	jsr	flipcolor
+	dey			; TGI_ERR_OK
+	sty	ERROR
+	sty	PARAM1+1
+	jmp	INK
+
+flipcolor:
+	lda	(ptr1),y
+	sta	PALETTE,y
+	cmp	#1
+	beq	@flip
+	cmp	#7
+	bne	@keep
+@flip:	eor	#1 ^ 7
+@keep:	sta	PARAM1
+	rts
+
+; ------------------------------------------------------------------------
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
+;
+; Must set an error code: NO
+;
+
+GETPALETTE:
+	lda	#PALETTE
+	rts
+
+; ------------------------------------------------------------------------
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes; otherwise, the caller has no way to determine the colors
+; of the (not changeable) palette.
+;
+; Must set an error code: NO (all drivers must have a default palette)
+;
+
+GETDEFPALETTE:
+	lda	#DEFPALETTE
+	rts
+
+; ------------------------------------------------------------------------
+; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
+; color. The co-ordinates passed to this function are never outside the
+; visible screen area, so there is no need for clipping inside this function.
+;
+; Must set an error code: NO
+;
+
+SETPIXEL:
+	lda	Y1
+	sta	PARAM2
+	lda	MODE
+mymode:	sta	PARAM3
+	lda	X1
+	add	#2 * XSIZE	; Skip screen attribute columns
+	sta	PARAM1
+	lda	#0
+	sta	PARAM1+1
+	sta	PARAM2+1
+	sta	PARAM3+1
+	jmp	CURSET
+
+; ------------------------------------------------------------------------
+; GETPIXEL: Read the color value of a pixel, and return it in A/X. The
+; co-ordinates passed to this function are never outside the visible screen
+; area, so there is no need for clipping inside this function.
+
+GETPIXEL:
+	lda	X1
+	sta	PARAM1
+	lda	Y1
+	sta	PARAM2
+	lda	#0
+	sta	PARAM1+1
+	sta	PARAM2+1
+	jsr	POINT
+	lda	PARAM1
+	and	#%00000001
+	ldx	#0
+	rts
+
+; ------------------------------------------------------------------------
+; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
+; X2/Y2 = ptr3/ptr4, using the current drawing color.
+;
+; Must set an error code: NO
+;
+
+LINE:
+	jsr	SETPIXEL
+	lda	X2
+	sub	X1
+	sta	PARAM1
+	lda	X2+1
+	sbc	X1+1
+	sta	PARAM1+1
+	lda	Y2
+	sub	Y1
+	sta	PARAM2
+	lda	Y2+1
+	sbc	Y1+1
+	sta	PARAM2+1
+	lda	MODE
+	sta	PARAM3
+	ldx	#>0
+	stx	PARAM3+1
+	jmp	DRAW
+
+; ------------------------------------------------------------------------
+; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
+; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4, using the current drawing color.
+; Contrary to most other functions, the graphics kernel will sort and clip
+; the co-ordinates before calling the driver; so, on entry, the following
+; conditions are valid:
+;	X1 <= X2
+;	Y1 <= Y2
+;	(X1 >= 0) && (X1 < XRES)
+;	(X2 >= 0) && (X2 < XRES)
+;	(Y1 >= 0) && (Y1 < YRES)
+;	(Y2 >= 0) && (Y2 < YRES)
+;
+; Must set an error code: NO
+;
+
+BAR:
+	inc	Y2
+@L1:	lda	Y2
+	pha
+	lda	Y1
+	sta	Y2
+	jsr	LINE
+	pla
+	sta	Y2
+	inc	Y1
+	cmp	Y1
+	bne	@L1
+	rts
+
+; ------------------------------------------------------------------------
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in the x
+; and y directions is passend in X/Y, the text direction is passed in A.
+;
+; Must set an error code: NO
+;
+
+TEXTSTYLE:
+	rts
+
+
+; ------------------------------------------------------------------------
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero-terminated
+; string with its address in ptr3.
+;
+; Must set an error code: NO
+;
+
+OUTTEXT:
+	lda	Y1
+	sub	#(YSIZE - 1)
+	sta	PARAM2
+	lda	#3		; (Move graphics cursor; don't draw)
+	jsr	mymode
+
+	ldy	#0
+@next:	lda	(ptr3),y
+	beq	@end
+	sta	PARAM1
+	lda	#0
+	sta	PARAM2
+	sta	PARAM1+1
+	sta	PARAM2+1
+	sta	PARAM3+1
+	lda	MODE
+	sta	PARAM3
+	tya
+	pha
+	jsr	CHAR
+	lda	#XSIZE
+	sta	PARAM1
+	lda	#0
+	sta	PARAM2
+	sta	PARAM1+1
+	sta	PARAM2+1
+	sta	PARAM3+1
+	lda	#3
+	sta	PARAM3
+	jsr	CURMOV
+	pla
+	tay
+	iny
+	bne	@next
+@end:	rts
diff --git a/libsrc/atmos/tgi/atmos-240-200-2.s b/libsrc/atmos/tgi/atmos-240-200-2.s
new file mode 100644
index 000000000..9027b3340
--- /dev/null
+++ b/libsrc/atmos/tgi/atmos-240-200-2.s
@@ -0,0 +1,403 @@
+;
+; Graphics driver for the 240x200x2 monochrome mode on the Atmos
+;
+; Stefan Haubenthal 
+; 2012-08-11, Greg King 
+;
+
+	.include	"zeropage.inc"
+
+	.include	"tgi-kernel.inc"
+	.include	"tgi-error.inc"
+	.include	"atmos.inc"
+
+	.macpack	generic
+
+XSIZE	=	6			; System font width
+YSIZE	=	8			; System font height
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table and constants.
+
+.segment	"JUMPTABLE"
+
+; First part of the header is a structure that has a magic and defines the
+; capabilities of the driver
+
+	.byte	$74, $67, $69		; "tgi"
+	.byte	TGI_API_VERSION		; TGI API version number
+	.word	240			; X resolution
+	.word	200			; Y resolution
+	.byte	2			; Number of drawing colors
+	.byte	1			; Number of screens available
+	.byte	XSIZE			; System font X size
+	.byte	YSIZE			; System font Y size
+        .word   $011C                   ; Aspect ratio (based on 4/3 display)
+        .byte   0                       ; TGI driver flags
+
+; Next comes the jump table. Currently all entries must be valid and may point
+; to an RTS for test versions (function not implemented).
+
+       	.addr   INSTALL
+       	.addr   UNINSTALL
+       	.addr   INIT
+       	.addr   DONE
+       	.addr   GETERROR
+       	.addr   CONTROL
+       	.addr   CLEAR
+       	.addr   SETVIEWPAGE
+       	.addr   SETDRAWPAGE
+       	.addr   SETCOLOR
+       	.addr   SETPALETTE
+       	.addr   GETPALETTE
+       	.addr   GETDEFPALETTE
+       	.addr   SETPIXEL
+       	.addr   GETPIXEL
+       	.addr   LINE
+       	.addr   BAR
+       	.addr   TEXTSTYLE
+       	.addr   OUTTEXT
+        .addr   0                       ; IRQ entry is unused
+
+; ------------------------------------------------------------------------
+; Data.
+
+; Variables mapped to the zero page segment variables. Some of these are
+; used for passing parameters to the driver.
+
+X1		= ptr1
+Y1		= ptr2
+X2		= ptr3
+Y2		= ptr4
+
+; Absolute variables used in the code
+
+.bss
+
+ERROR:		.res	1	; Error code
+MODE:		.res	1	; Graphics mode
+
+; Constants and tables
+PARAM1		= $2E1
+PARAM2		= $2E3
+PARAM3		= $2E5
+TEXT		= $EC21
+HIRES		= $EC33
+CURSET		= $F0C8
+CURMOV		= $F0FD
+DRAW		= $F110
+CHAR		= $F12D
+POINT		= $F1C8
+PAPER		= $F204
+INK		= $F210
+
+.rodata
+
+DEFPALETTE:	.byte	0, 1
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. May
+; initialize anything that has to be done just once. Is probably empty
+; most of the time.
+;
+; Must set an error code: NO
+;
+
+INSTALL:
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory. May
+; clean up anything done by INSTALL but is probably empty most of the time.
+;
+; Must set an error code: NO
+;
+
+UNINSTALL:
+	rts
+
+; ------------------------------------------------------------------------
+; INIT: Changes an already installed device from text mode to graphics
+; mode.
+; Note that INIT/DONE may be called multiple times while the driver
+; is loaded, while INSTALL is only called once, so any code that is needed
+; to initializes variables and so on must go here. Setting palette and
+; clearing the screen is not needed because this is called by the graphics
+; kernel later.
+; The graphics kernel will never call INIT when a graphics mode is already
+; active, so there is no need to protect against that.
+;
+; Must set an error code: YES
+;
+
+INIT:
+
+; Switch into graphics mode
+
+	jsr	HIRES
+
+; Done, reset the error code
+
+	lda	#TGI_ERR_OK
+	sta	ERROR
+	rts
+
+; ------------------------------------------------------------------------
+; DONE: Will be called to switch the graphics device back into text mode.
+; The graphics kernel will never call DONE when no graphics mode is active,
+; so there is no need to protect against that.
+;
+; Must set an error code: NO
+;
+
+DONE		= TEXT
+
+; ------------------------------------------------------------------------
+; GETERROR: Return the error code in A and clear it.
+
+GETERROR:
+	ldx	#TGI_ERR_OK
+	lda	ERROR
+	stx	ERROR
+	rts
+
+; ------------------------------------------------------------------------
+; CONTROL: Platform/driver specific entry point.
+;
+; Must set an error code: YES
+;
+
+CONTROL:
+	sta	$213
+	lda	#TGI_ERR_OK
+	sta	ERROR
+	rts
+
+; ------------------------------------------------------------------------
+; CLEAR: Clears the screen.
+;
+; Must set an error code: NO
+;
+
+CLEAR		= HIRES
+
+; ------------------------------------------------------------------------
+; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+;
+; Must set an error code: NO (will only be called if page ok)
+;
+
+SETVIEWPAGE:
+
+; ------------------------------------------------------------------------
+; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+;
+; Must set an error code: NO (will only be called if page ok)
+;
+
+SETDRAWPAGE:
+	rts
+
+; ------------------------------------------------------------------------
+; SETCOLOR: Set the drawing color (in A). The new color is already checked
+; to be in a valid range (0..maxcolor-1).
+;
+; Must set an error code: NO (will only be called if color ok)
+;
+
+SETCOLOR:
+	sta	MODE
+	rts
+
+; ------------------------------------------------------------------------
+; SETPALETTE: Set the palette (not available with all drivers/hardware).
+; A pointer to the palette is passed in ptr1. Must set an error if palettes
+; are not supported
+;
+; Must set an error code: YES
+;
+
+SETPALETTE:
+	lda	#TGI_ERR_INV_FUNC	; This resolution has no palette
+	sta	ERROR
+	rts
+
+; ------------------------------------------------------------------------
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
+;
+; Must set an error code: NO
+;
+
+GETPALETTE:
+
+; ------------------------------------------------------------------------
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes, otherwise the caller has no way to determine the colors
+; of the (not changeable) palette.
+;
+; Must set an error code: NO (all drivers must have a default palette)
+;
+
+GETDEFPALETTE:
+	lda	#DEFPALETTE
+	rts
+
+; ------------------------------------------------------------------------
+; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
+; color. The coordinates passed to this function are never outside the
+; visible screen area, so there is no need for clipping inside this function.
+;
+; Must set an error code: NO
+;
+
+SETPIXEL:
+	lda	Y1
+	sta	PARAM2
+	lda	MODE
+mymode:	sta	PARAM3
+	lda	X1
+	sta	PARAM1
+	lda	#0
+	sta	PARAM1+1
+	sta	PARAM2+1
+	sta	PARAM3+1
+	jmp	CURSET
+
+; ------------------------------------------------------------------------
+; GETPIXEL: Read the color value of a pixel and return it in A/X. The
+; coordinates passed to this function are never outside the visible screen
+; area, so there is no need for clipping inside this function.
+
+GETPIXEL:
+	lda	X1
+	sta	PARAM1
+	lda	Y1
+	sta	PARAM2
+	lda	#0
+	sta	PARAM1+1
+	sta	PARAM2+1
+	jsr	POINT
+	lda	PARAM1
+	and	#%00000001
+	ldx	#0
+	rts
+
+; ------------------------------------------------------------------------
+; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
+; X2/Y2 = ptr3/ptr4 using the current drawing color.
+;
+; Must set an error code: NO
+;
+
+LINE:
+	jsr	SETPIXEL
+	lda	X2
+	sub	X1
+	sta	PARAM1
+	lda	X2+1
+	sbc	X1+1
+	sta	PARAM1+1
+	lda	Y2
+	sub	Y1
+	sta	PARAM2
+	lda	Y2+1
+	sbc	Y1+1
+	sta	PARAM2+1
+	lda	MODE
+	sta	PARAM3
+	ldx	#>0
+	stx	PARAM3+1
+	jmp	DRAW
+
+; ------------------------------------------------------------------------
+; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
+; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
+; Contrary to most other functions, the graphics kernel will sort and clip
+; the coordinates before calling the driver, so on entry the following
+; conditions are valid:
+;	X1 <= X2
+;	Y1 <= Y2
+;	(X1 >= 0) && (X1 < XRES)
+;	(X2 >= 0) && (X2 < XRES)
+;	(Y1 >= 0) && (Y1 < YRES)
+;	(Y2 >= 0) && (Y2 < YRES)
+;
+; Must set an error code: NO
+;
+
+BAR:
+	inc	Y2
+@L1:	lda	Y2
+	pha
+  	lda	Y1
+	sta	Y2
+	jsr	LINE
+	pla
+	sta	Y2
+	inc	Y1
+	cmp	Y1
+	bne	@L1
+	rts
+
+; ------------------------------------------------------------------------
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
+; direction is passend in X/Y, the text direction is passed in A.
+;
+; Must set an error code: NO
+;
+
+TEXTSTYLE:
+	rts
+
+
+; ------------------------------------------------------------------------
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero terminated
+; string with address in ptr3.
+;
+; Must set an error code: NO
+;
+
+OUTTEXT:
+	lda	Y1
+	sub	#(YSIZE - 1)
+	sta	PARAM2
+	lda	#3		; (Move graphics cursor; don't draw)
+	jsr	mymode
+
+	ldy	#0
+@next:	lda	(ptr3),y
+	beq	@end
+	sta	PARAM1
+	lda	#0
+	sta	PARAM2
+	sta	PARAM1+1
+	sta	PARAM2+1
+	sta	PARAM3+1
+	lda	MODE
+	sta	PARAM3
+	tya
+	pha
+	jsr	CHAR
+	lda	#XSIZE
+	sta	PARAM1
+	lda	#0
+	sta	PARAM2
+	sta	PARAM1+1
+	sta	PARAM2+1
+	sta	PARAM3+1
+	lda	#3
+	sta	PARAM3
+	jsr	CURMOV
+	pla
+	tay
+	iny
+	bne	@next
+@end:	rts
diff --git a/libsrc/c128/Makefile b/libsrc/c128/Makefile
deleted file mode 100644
index 90153a57e..000000000
--- a/libsrc/c128/Makefile
+++ /dev/null
@@ -1,147 +0,0 @@
-#
-# makefile for CC65 runtime library
-#
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= c128
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	%.c
-	@$(CC) $(CFLAGS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-mou.o: %.mou
-	@$(CO) -o $(*)-mou.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-mou.s
-
-%-ser.o: %.ser
-	@$(CO) -o $(*)-ser.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-ser.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.mou:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.ser:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-#--------------------------------------------------------------------------
-# Object files
-
-OBJS =	_scrsize.o              \
-        break.o                 \
-        c64mode.o               \
-        cgetc.o                 \
-        clrscr.o                \
-        conio.o                 \
-        crt0.o                  \
-        color.o                 \
-        cputc.o                 \
-        devnum.o                \
-        fast.o                  \
-        get_tv.o                \
-        irq.o                   \
-        joy_stat_stddrv.o       \
-        joy_stddrv.o            \
-        kbhit.o                 \
-        kernal.o                \
-        mainargs.o              \
-        mcbdefault.o            \
-        mouse_stat_stddrv.o     \
-        mouse_stddrv.o          \
-        randomize.o             \
-        revers.o                \
-        slow.o                  \
-        status.o                \
-        systime.o               \
-        sysuname.o              \
-        tgi_colors.o            \
-        tgi_stat_stddrv.o       \
-        tgi_stddrv.o            \
-        toggle_videomode.o      \
-        videomode.o             \
-        $(EMDS:.emd=-emd.o)     \
-        $(JOYS:.joy=-joy.o)     \
-        $(MOUS:.mou=-mou.o)     \
-        $(SERS:.ser=-ser.o)     \
-        $(TGIS:.tgi=-tgi.o)
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS =  c128-georam.emd         \
-        c128-ram.emd            \
-        c128-ram2.emd           \
-        c128-ramcart.emd        \
-        c128-reu.emd            \
-        c128-vdc.emd
-
-JOYS =  c128-ptvjoy.joy         \
-        c128-stdjoy.joy
-
-MOUS =  c128-1351.mou           \
-        c128-joymouse.mou       \
-        c128-potmouse.mou
-
-SERS =  c128-swlink.ser
-
-TGIS =  c128-640-200-2.tgi      \
-        c128-640-480-2.tgi
-
-#--------------------------------------------------------------------------
-# Targets
-
-.PHONY:	all clean zap
-
-all:	$(OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(MOUS:.mou=.o) $(MOUS:.mou=-mou.s) \
-	       $(SERS:.ser=.o) $(SERS:.ser=-ser.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
diff --git a/libsrc/c128/c128-1351.s b/libsrc/c128/c128-1351.s
deleted file mode 100644
index 999c57090..000000000
--- a/libsrc/c128/c128-1351.s
+++ /dev/null
@@ -1,428 +0,0 @@
-;
-; Driver for the 1351 proportional mouse. Parts of the code are from
-; the Commodore 1351 mouse users guide.
-;
-; Ullrich von Bassewitz, 2003-12-29, 2009-09-26
-;
-
-        .include        "zeropage.inc"
-        .include        "mouse-kernel.inc"
-	.include	"c128.inc"
-
-        .macpack        generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-HEADER:
-
-; Driver signature
-
-        .byte   $6d, $6f, $75           ; "mou"
-        .byte   MOUSE_API_VERSION       ; Mouse driver API version number
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   HIDE
-        .addr   SHOW
-        .addr   SETBOX
-        .addr   GETBOX
-        .addr   MOVE
-        .addr   BUTTONS
-        .addr   POS
-        .addr   INFO
-        .addr   IOCTL
-        .addr   IRQ
-
-; Mouse driver flags
-
-        .byte   MOUSE_FLAG_LATE_IRQ
-
-; Callback table, set by the kernel before INSTALL is called
-
-CHIDE:  jmp     $0000                   ; Hide the cursor
-CSHOW:  jmp     $0000                   ; Show the cursor
-CMOVEX: jmp     $0000                   ; Move the cursor to X coord
-CMOVEY: jmp     $0000                   ; Move the cursor to Y coord
-
-
-;----------------------------------------------------------------------------
-; Constants
-
-SCREEN_HEIGHT   = 200
-SCREEN_WIDTH    = 320
-
-;----------------------------------------------------------------------------
-; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the SETBOX and GETBOX routines, so don't
-; reorder them.
-
-.bss
-
-Vars:
-OldPotX:   	.res   	1	     	; Old hw counter values
-OldPotY:	.res   	1
-
-YPos:           .res    2               ; Current mouse position, Y
-XPos:           .res    2               ; Current mouse position, X
-XMin:		.res	2	     	; X1 value of bounding box
-YMin:		.res	2	     	; Y1 value of bounding box
-XMax:		.res	2	     	; X2 value of bounding box
-YMax:		.res	2	     	; Y2 value of bounding box
-
-OldValue:	.res   	1	     	; Temp for MoveCheck routine
-NewValue:	.res   	1	     	; Temp for MoveCheck routine
-
-; Default values for above variables
-
-.rodata
-
-.proc   DefVars
-        .byte   0, 0                    ; OldPotX/OldPotY
-        .word   SCREEN_HEIGHT/2         ; YPos
-        .word   SCREEN_WIDTH/2          ; XPos
-        .word   0                       ; XMin
-        .word   0                       ; YMin
-        .word   SCREEN_WIDTH            ; XMax
-        .word   SCREEN_HEIGHT           ; YMax
-.endproc
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an MOUSE_ERR_xx code in a/x.
-
-INSTALL:
-
-; Initialize variables. Just copy the default stuff over
-
-        ldx     #.sizeof(DefVars)-1
-@L1:    lda     DefVars,x
-        sta     Vars,x
-        dex
-        bpl     @L1
-
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
-
-        sei
-        jsr     CHIDE
-        lda     XPos
-        ldx     XPos+1
-        jsr     CMOVEX
-        lda     YPos
-        ldx     YPos+1
-        jsr     CMOVEY
-        cli
-
-; Done, return zero (= MOUSE_ERR_OK)
-
-        ldx     #$00
-        txa
-        rts                             ; Run into UNINSTALL instead
-
-;----------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-
-UNINSTALL       = HIDE                  ; Hide cursor on exit
-
-;----------------------------------------------------------------------------
-; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required besides hiding the mouse cursor.
-; No return code required.
-
-HIDE:   sei
-        jsr     CHIDE
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required besides enabling the mouse cursor.
-; No return code required.
-
-SHOW:   sei
-        jsr     CSHOW
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in a/x.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-
-SETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     (ptr1),y
-        sta     XMin,y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in a/x.
-
-GETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     XMin,y
-        sta     (ptr1),y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-;
-
-MOVE:   sei                             ; No interrupts
-
-        sta     YPos
-        stx     YPos+1                  ; New Y position
-        jsr     CMOVEY                  ; Set it
-
-        ldy     #$01
-        lda     (sp),y
-        sta     XPos+1
-        tax
-        dey
-        lda     (sp),y
-        sta     XPos                    ; New X position
-
-        jsr     CMOVEX			; Move the cursor
-
-	cli                             ; Allow interrupts
-       	rts
-
-;----------------------------------------------------------------------------
-; BUTTONS: Return the button mask in a/x.
-
-BUTTONS:
-        lda	#$7F
-     	sei
-     	sta	CIA1_PRA
-     	lda	CIA1_PRB                ; Read joystick #0
-     	cli
-        ldx     #0
-     	and	#$1F
-     	eor	#$1F
-        rts
-
-;----------------------------------------------------------------------------
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-
-POS:    ldy    	#MOUSE_POS::XCOORD      ; Structure offset
-
-	sei	    			; Disable interrupts
-	lda     XPos			; Transfer the position
-	sta	(ptr1),y
-	lda	XPos+1
-	iny
-	sta	(ptr1),y
-      	lda	YPos
-        iny
-        sta     (ptr1),y
-	lda	YPos+1
-	cli	    			; Enable interrupts
-
-        iny
-        sta     (ptr1),y                ; Store last byte
-
-    	rts	    			; Done
-
-;----------------------------------------------------------------------------
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-;
-; We're cheating here to keep the code smaller: The first fields of the
-; mouse_info struct are identical to the mouse_pos struct, so we will just
-; call _mouse_pos to initialize the struct pointer and fill the position
-; fields.
-
-INFO:   jsr	POS
-
-; Fill in the button state
-
-    	jsr     BUTTONS                 ; Will not touch ptr1
-    	ldy	#MOUSE_INFO::BUTTONS
-    	sta	(ptr1),y
-
-      	rts
-
-;----------------------------------------------------------------------------
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an error code in a/x.
-;
-
-IOCTL:  lda     #MOUSE_ERR_INV_IOCTL
-        rts
-
-;----------------------------------------------------------------------------
-; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
-; (so be careful). The routine MUST return carry set if the interrupt has been
-; 'handled' - which means that the interrupt source is gone. Otherwise it
-; MUST return carry clear.
-;
-
-IRQ:    lda	SID_ADConv1		; Get mouse X movement
-      	ldy	OldPotX
-      	jsr	MoveCheck  		; Calculate movement vector
-      	sty	OldPotX
-
-; Skip processing if nothing has changed
-
-        bcc     @SkipX
-
-; Calculate the new X coordinate (--> a/y)
-
-       	add	XPos
-      	tay	      			; Remember low byte
-      	txa
-      	adc	XPos+1
-    	tax
-
-; Limit the X coordinate to the bounding box
-
-   	cpy	XMin
-   	sbc	XMin+1
-   	bpl	@L1
-       	ldy    	XMin
-       	ldx	XMin+1
-    	jmp	@L2
-@L1:	txa
-
-    	cpy	XMax
-    	sbc	XMax+1
-    	bmi	@L2
-    	ldy	XMax
-    	ldx	XMax+1
-@L2:	sty	XPos
-   	stx	XPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEX
-
-; Calculate the Y movement vector
-
-@SkipX: lda	SID_ADConv2	 	; Get mouse Y movement
- 	ldy	OldPotY
- 	jsr	MoveCheck	 	; Calculate movement
- 	sty	OldPotY
-
-; Skip processing if nothing has changed
-
-        bcc     @SkipY
-
-; Calculate the new Y coordinate (--> a/y)
-
-      	sta	OldValue
-      	lda	YPos
-      	sub	OldValue
-      	tay
-      	stx	OldValue
-      	lda	YPos+1
-      	sbc	OldValue
-      	tax
-
-; Limit the Y coordinate to the bounding box
-
-   	cpy	YMin
- 	sbc	YMin+1
- 	bpl	@L3
-       	ldy    	YMin
-       	ldx	YMin+1
-    	jmp	@L4
-@L3:	txa
-
-    	cpy	YMax
-    	sbc	YMax+1
-    	bmi	@L4
-    	ldy	YMax
-    	ldx	YMax+1
-@L4:	sty	YPos
- 	stx	YPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEY
-
-; Done
-
-        clc                     ; Interrupt not "handled"
-@SkipY: rts
-
-; --------------------------------------------------------------------------
-;
-; Move check routine, called for both coordinates.
-;
-; Entry:   	y = old value of pot register
-;     	   	a = current value of pot register
-; Exit:	   	y = value to use for old value
-;     	   	x/a = delta value for position
-;
-
-MoveCheck:
-      	sty	OldValue
-      	sta	NewValue
-      	ldx 	#$00
-
-      	sub	OldValue	   	; a = mod64 (new - old)
-      	and	#%01111111
-      	cmp	#%01000000	   	; if (a > 0)
-      	bcs	@L1 		   	;
-      	lsr	a   		   	;   a /= 2;
-      	beq	@L2 		   	;   if (a != 0)
-      	ldy   	NewValue     	   	;     y = NewValue
-        sec
-      	rts   	    		   	;   return
-
-@L1:  	ora   	#%11000000	   	; else or in high order bits
-      	cmp   	#$FF		   	; if (a != -1)
-      	beq   	@L2
-      	sec
-      	ror   	a   		   	;   a /= 2
-       	dex			   	;   high byte = -1 (X = $FF)
-      	ldy   	NewValue
-        sec
-      	rts
-
-@L2:   	txa			   	; A = $00
-        clc
-      	rts
-
diff --git a/libsrc/c128/c128-640-200-2.s b/libsrc/c128/c128-640-200-2.s
deleted file mode 100644
index ecc4c8437..000000000
--- a/libsrc/c128/c128-640-200-2.s
+++ /dev/null
@@ -1,778 +0,0 @@
-;
-; Graphics driver for the 640x200x2 mode on the C128 VDC
-; Maciej 'YTM/Elysium' Witkowiak 
-; 23.12.2002
-; 2004-04-04, Greg King
-;
-; NOTES:
-; For any smart monkey that will try to optimize this: PLEASE do tests on
-; real VDC, not only VICE.
-;
-; Only DONE routine contains C128-mode specific stuff, everything else will
-; work in C64-mode of C128 (C64 needs full VDC init then).
-;
-; With special initialization and CALC we can get 320x200 double-pixel mode.
-;
-; Color translation values for BROWN and GRAY3 are obviously wrong, they
-; could be replaced by equiv. of ORANGE and GRAY2 but this would give only
-; 14 of 16 colors available.
-;
-; Register 25 ($19) is said to require different value for VDC v1, but I
-; couldn't find what it should be.
-
-	.include     	"zeropage.inc"
-
-      	.include     	"tgi-kernel.inc"
-        .include        "tgi-error.inc"
-
-
-        .macpack        generic
-
-; ------------------------------------------------------------------------
-; Constants
-
-VDC_ADDR_REG	  = $D600		  ; VDC address
-VDC_DATA_REG	  = $D601		  ; VDC data
-
-VDC_DSP_HI	  = 12			  ; registers used
-VDC_DSP_LO	  = 13
-VDC_DATA_HI	  = 18
-VDC_DATA_LO	  = 19
-VDC_VSCROLL	  = 24
-VDC_HSCROLL	  = 25
-VDC_COLORS	  = 26
-VDC_CSET	  = 28
-VDC_COUNT	  = 30
-VDC_DATA	  = 31
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table and constants.
-
-.segment        "JUMPTABLE"
-
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
-
-        .byte   $74, $67, $69           ; "tgi"
-        .byte   TGI_API_VERSION         ; TGI API version number
-xres:   .word   640                     ; X resolution
-yres:   .word   200                     ; Y resolution
-        .byte   2                       ; Number of drawing colors
-pages:	.byte   1                       ; Number of screens available
-        .byte   8                       ; System font X size
-        .byte   8                       ; System font Y size
-        .word   $006A                   ; Aspect ratio (based on 4/3 display)
-        .byte   0                       ; TGI driver flags
-
-; Next comes the jump table. Currently all entries must be valid and may point
-; to an RTS for test versions (function not implemented).
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   INIT
-        .addr   DONE
-       	.addr   GETERROR
-        .addr   CONTROL
-        .addr   CLEAR
-        .addr   SETVIEWPAGE
-        .addr   SETDRAWPAGE
-        .addr   SETCOLOR
-        .addr   SETPALETTE
-        .addr   GETPALETTE
-        .addr   GETDEFPALETTE
-        .addr   SETPIXEL
-        .addr   GETPIXEL
-        .addr   LINE
-        .addr   BAR
-        .addr   TEXTSTYLE
-        .addr   OUTTEXT
-        .addr   0                       ; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-; Data.
-
-; Variables mapped to the zero page segment variables. Some of these are
-; used for passing parameters to the driver.
-
-X1              = ptr1
-Y1              = ptr2
-X2              = ptr3
-Y2              = ptr4
-
-ADDR		= tmp1
-TEMP		= tmp3
-TEMP2		= tmp4		; HORLINE
-TEMP3		= sreg		; HORLINE
-
-; Absolute variables used in the code
-
-.bss
-
-SCRBASE:	.res	1	; High byte of screen base
-
-ERROR:  	.res	1     	; Error code
-PALETTE:        .res    2       ; The current palette
-
-BITMASK:        .res    1       ; $00 = clear, $FF = set pixels
-
-OLDCOLOR:	.res	1	; colors before entering gfx mode
-
-; Text output stuff
-TEXTMAGX:       .res    1
-TEXTMAGY:       .res    1
-TEXTDIR:        .res    1
-
-; Constants and tables
-
-.rodata
-
-DEFPALETTE:     .byte   $00, $0f        ; White on black
-PALETTESIZE     = * - DEFPALETTE
-
-BITTAB:         .byte   $80,$40,$20,$10,$08,$04,$02,$01
-
-BITMASKL:	.byte	%11111111, %01111111, %00111111, %00011111
-		.byte   %00001111, %00000111, %00000011, %00000001
-
-BITMASKR:	.byte	%10000000, %11000000, %11100000, %11110000
-		.byte	%11111000, %11111100, %11111110, %11111111
-
-; color translation table (indexed by VIC color)
-COLTRANS:	.byte $00, $0f, $08, $06, $0a, $04, $02, $0c
-		.byte $0d, $0b, $09, $01, $0e, $05, $03, $07
-		; colors BROWN and GRAY3 are wrong
-
-; VDC initialization table (reg),(val),...,$ff
-InitVDCTab:
-		.byte VDC_DSP_HI, 0		; viewpage 0 as default
-		.byte VDC_DSP_LO, 0
-		.byte VDC_HSCROLL, $87
-		.byte $ff
-
-SCN80CLR:	.byte 27,88,147,27,88,0
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-;
-; Must set an error code: NO
-;
-
-INSTALL:
-	; check for VDC version and update register $19 value
-
-	; check for VDC ram size and update number of available screens
-
-	ldx	#VDC_CSET	; determine size of RAM...
-	jsr	VDCReadReg
-	sta	tmp1
-	ora	#%00010000
-	jsr	VDCWriteReg	; turn on 64k
-
-	jsr	settestadr1	; save original value of test byte
-	jsr	VDCReadByte
-	sta	tmp2
-
-	lda	#$55		; write $55 here
-	ldy	#ptr1
-	jsr	test64k		; read it here and there
-	lda	#$aa		; write $aa here
-	ldy	#ptr2
-	jsr	test64k		; read it here and there
-
-	jsr	settestadr1
-	lda	tmp2
-	jsr	VDCWriteByte	; restore original value of test byte
-
-	lda	ptr1		; do bytes match?
-	cmp	ptr1+1
-	bne	@have64k
-	lda	ptr2
-	cmp	ptr2+1
-	bne	@have64k
-
-	ldx	#VDC_CSET
-	lda	tmp1
-	jsr	VDCWriteReg	; restore 16/64k flag
-	jmp	@endok		; and leave default values for 16k
-
-@have64k:
-	lda	#4
-	sta	pages
-@endok:
-	lda     #0
-	sta	SCRBASE		; draw page 0 as default
-        rts
-
-test64k:
-	sta	tmp1
-	sty	ptr3
-	lda	#0
-	sta	ptr3+1
-	jsr	settestadr1
-	lda	tmp1
-	jsr	VDCWriteByte		; write $55
-	jsr	settestadr1
-	jsr	VDCReadByte		; read here
-	pha
-	jsr	settestadr2
-	jsr	VDCReadByte		; and there
-	ldy	#1
-	sta	(ptr3),y
-	pla
-	dey
-	sta	(ptr3),y
-	rts
-
-settestadr1:
-	ldy	#$02			; test page 2 (here)
-	.byte	$2c
-settestadr2:
-	ldy	#$42			; or page 64+2 (there)
-	lda	#0
-	jmp	VDCSetSourceAddr
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL but is probably empty most of the time.
-;
-; Must set an error code: NO
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; INIT: Changes an already installed device from text mode to graphics
-; mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is only called once, so any code that is needed
-; to initializes variables and so on must go here. Setting palette and
-; clearing the screen is not needed because this is called by the graphics
-; kernel later.
-; The graphics kernel will never call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-;
-; Must set an error code: YES
-;
-
-INIT:
-
-; Initialize variables
-
-@L1:    ldx     #$FF
-        stx     BITMASK
-
-; Remeber current color value
-	ldx	#VDC_COLORS
-	jsr	VDCReadReg
-	sta	OLDCOLOR
-
-; Switch into graphics mode (set view page 0)
-
-	ldy	#0
-@L2:	ldx	InitVDCTab,y
-	bmi	@L3
-	iny
-	lda	InitVDCTab,y
-	jsr	VDCWriteReg
-	iny
-	bne	@L2
-@L3:
-
-; Done, reset the error code
-
-        lda     #TGI_ERR_OK
-        sta     ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel will never call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-;
-; Must set an error code: NO
-;
-
-DONE:
-	; This part is C128-mode specific
-	jsr $e179		; reload character set and setup VDC
-	jsr $ff62
-	lda $d7			; in 80-columns?
-	bne @L01
-@L0:	lda SCN80CLR,y
-	beq @L1
-	jsr $ffd2		; print \xe,clr,\xe
-	iny
-	bne @L0
-@L01:	lda #147
-	jsr $ffd2		; print clr
-@L1:	lda #0			; restore view page
-	ldx #VDC_DSP_HI
-	jsr VDCWriteReg
-	lda OLDCOLOR
-	ldx #VDC_COLORS
-	jsr VDCWriteReg		; restore color (background)
-	lda #$47
-	ldx #VDC_HSCROLL
-       	jmp VDCWriteReg		; switch to text screen
-
-; ------------------------------------------------------------------------
-; GETERROR: Return the error code in A and clear it.
-
-GETERROR:
-       	ldx	#TGI_ERR_OK
-	lda	ERROR
-	stx	ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; CONTROL: Platform/driver specific entry point.
-;
-; Must set an error code: YES
-;
-
-CONTROL:
-	lda	#TGI_ERR_INV_FUNC
-	sta	ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; CLEAR: Clears the screen.
-;
-; Must set an error code: NO
-;
-
-CLEAR:
-	lda	#0
-	ldy	SCRBASE
-	jsr	VDCSetSourceAddr
-	lda	#0
-	ldx	#VDC_VSCROLL
-	jsr	VDCWriteReg			; set fill mode
-	lda	#0
-	jsr	VDCWriteByte			; put 1rst byte (fill value)
-	ldy	#62				; 62 times
-	lda	#0				; 256 bytes
-	ldx	#VDC_COUNT
-@L1:	jsr	VDCWriteReg
-	dey
-	bne	@L1
-	lda	#127
-	jmp	VDCWriteReg			; 1+62*256+127=16000=(640*256)/8
-
-; ------------------------------------------------------------------------
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETVIEWPAGE:
-	clc
-	ror
-	ror
-	ror
-	ldx	#VDC_DSP_HI
-	jmp	VDCWriteReg
-
-; ------------------------------------------------------------------------
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETDRAWPAGE:
-	clc
-	ror
-	ror
-	ror
-	sta	SCRBASE
-	rts
-
-; ------------------------------------------------------------------------
-; SETCOLOR: Set the drawing color (in A). The new color is already checked
-; to be in a valid range (0..maxcolor-1).
-;
-; Must set an error code: NO (will only be called if color ok)
-;
-
-SETCOLOR:
-        tax
-        beq     @L1
-        lda     #$FF
-@L1:    sta     BITMASK
-        rts
-
-; ------------------------------------------------------------------------
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported
-;
-; Must set an error code: YES
-;
-
-SETPALETTE:
-        ldy     #PALETTESIZE - 1
-@L1:    lda     (ptr1),y        ; Copy the palette
-        and     #$0F            ; Make a valid color
-        sta     PALETTE,y
-        dey
-        bpl     @L1
-
-; Get the color entries from the palette
-
-        ldy     PALETTE+1       ; Foreground color
-	lda	COLTRANS,y
-        asl     a
-        asl     a
-        asl     a
-        asl     a
-        ldy     PALETTE         ; Background color
-	ora	COLTRANS,y
-
-	ldx	#VDC_COLORS
-       	jsr     VDCWriteReg
-        lda     #TGI_ERR_OK     ; Clear error code
-        sta     ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-;
-; Must set an error code: NO
-;
-
-GETPALETTE:
-        lda     #PALETTE
-        rts
-
-; ------------------------------------------------------------------------
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes, otherwise the caller has no way to determine the colors
-; of the (not changeable) palette.
-;
-; Must set an error code: NO (all drivers must have a default palette)
-;
-
-GETDEFPALETTE:
-        lda     #DEFPALETTE
-        rts
-
-; ------------------------------------------------------------------------
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The coordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-;
-; Must set an error code: NO
-;
-
-SETPIXEL:
-        jsr     CALC            ; Calculate coordinates
-
-	stx	TEMP
-	lda	ADDR
-	ldy	ADDR+1
-	jsr	VDCSetSourceAddr
-	jsr	VDCReadByte
-	ldx	TEMP
-
-	sta	TEMP
-        eor     BITMASK
-        and     BITTAB,X
-	eor	TEMP
-	pha
-	lda	ADDR
-	ldy	ADDR+1
-	jsr	VDCSetSourceAddr
-	pla
-	jsr	VDCWriteByte
-
-@L9:    rts
-
-; ------------------------------------------------------------------------
-; GETPIXEL: Read the color value of a pixel and return it in A/X. The
-; coordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-
-
-GETPIXEL:
-        jsr     CALC            ; Calculate coordinates
-
-	stx	TEMP		; preserve X
-	lda	ADDR
-	ldy	ADDR+1
-	jsr	VDCSetSourceAddr
-	jsr	VDCReadByte
-	ldx	TEMP
-
-        ldy     #$00
-        and     BITTAB,X
-        beq     @L1
-        iny
-
-@L1:    tya                     ; Get color value into A
-        ldx     #$00            ; Clear high byte
-        rts
-
-; ------------------------------------------------------------------------
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the coordinates before calling the driver, so on entry the following
-; conditions are valid:
-;       X1 <= X2
-;       Y1 <= Y2
-;       (X1 >= 0) && (X1 < XRES)
-;       (X2 >= 0) && (X2 < XRES)
-;       (Y1 >= 0) && (Y1 < YRES)
-;       (Y2 >= 0) && (Y2 < YRES)
-;
-; Must set an error code: NO
-;
-
-BAR:
-	inc	Y2
-	bne	HORLINE
-	inc	Y2+1
-
-; Original code for a horizontal line
-
-HORLINE:
-	lda X1
-	pha
-	lda X1+1
-	pha
-	jsr CALC		; get data for LEFT
-	lda BITMASKL,x		; remember left address and bitmask
-	pha
-	lda ADDR
-	pha
-	lda ADDR+1
-	pha
-
-	lda X2
-	sta X1
-	lda X2+1
-	sta X1+1
-	jsr CALC		; get data for RIGHT
-	lda BITMASKR,x
-	sta TEMP3
-
-	pla			; recall data for LEFT
-	sta X1+1
-	pla
-	sta X1			; put left address into X1
-	pla
-
-	cmp #%11111111		; if left bit <> 0
-	beq @L1
-	sta TEMP2		; do left byte only...
-	lda X1
-	ldy X1+1
-	jsr VDCSetSourceAddr
-	jsr VDCReadByte
-	sta TEMP
-	eor BITMASK
-	and TEMP2
-	eor TEMP
-	pha
-	lda X1
-	ldy X1+1
-	jsr VDCSetSourceAddr
-	pla
-	jsr VDCWriteByte
-	inc X1			; ... and proceed
-	bne @L1
-	inc X1+1
-
-	; do right byte (if Y2=0 ++ADDR and skip)
-@L1:	lda TEMP3
-	cmp #%11111111		; if right bit <> 7
-	bne @L11
-	inc ADDR		; right bit = 7 - the next one is the last
-	bne @L10
-	inc ADDR+1
-@L10:	bne @L2
-
-@L11:	lda ADDR		; do right byte only...
-	ldy ADDR+1
-	jsr VDCSetSourceAddr
-	jsr VDCReadByte
-	sta TEMP
-	eor BITMASK
-	and TEMP3
-	eor TEMP
-	pha
-	lda ADDR
-	ldy ADDR+1
-	jsr VDCSetSourceAddr
-	pla
-	jsr VDCWriteByte
-
-@L2:				; do the fill in the middle
-	lda ADDR		; calculate offset in full bytes
-	sec
-	sbc X1
-	beq @L3			; if equal - there are no more bytes
-	sta ADDR
-
-	lda X1			; setup for the left side
-	ldy X1+1
-	jsr VDCSetSourceAddr
-	lda BITMASK		; get color
-	jsr VDCWriteByte	; put 1st value
-	ldx ADDR
-	dex
-	beq @L3			; 1 byte already written
-
-	stx ADDR		; if there are more bytes - fill them...
-	ldx #VDC_VSCROLL
-	lda #0
-	jsr VDCWriteReg		; setup for fill
-	ldx #VDC_COUNT
-	lda ADDR
-	jsr VDCWriteReg		; ... fill them NOW!
-
-@L3:	pla
-	sta X1+1
-	pla
-	sta X1
-
-; End of horizontal line code
-
-	inc	Y1
-	bne	@L4
-	inc	Y1+1
-@L4:	lda	Y1
-	cmp	Y2
-	bne	@L5
-	lda	Y1+1
-	cmp	Y2+1
-	bne	@L5
-	rts
-
-@L5:	jmp	HORLINE
-
-
-; ------------------------------------------------------------------------
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
-; direction is passend in X/Y, the text direction is passed in A.
-;
-; Must set an error code: NO
-;
-
-TEXTSTYLE:
-        stx     TEXTMAGX
-        sty     TEXTMAGY
-        sta     TEXTDIR
-        rts
-
-
-; ------------------------------------------------------------------------
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero terminated
-; string with address in ptr3.
-;
-; Must set an error code: NO
-;
-
-OUTTEXT:
-        rts
-
-; ------------------------------------------------------------------------
-; Calculate all variables to plot the pixel at X1/Y1.
-;------------------------
-;< X1,Y1 - pixel
-;> ADDR - address of card
-;> X - bit number (X1 & 7)
-CALC:
-	lda	Y1+1
-	sta	ADDR+1
-	lda	Y1
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1		; Y*4
-	clc
-	adc	Y1
-	sta	ADDR
-	lda	Y1+1
-	adc	ADDR+1
-	sta	ADDR+1		; Y*4+Y=Y*5
-	lda	ADDR
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1
-	sta	ADDR		; Y*5*16=Y*80
-	lda	X1+1
-	sta	TEMP
-	lda	X1
-	lsr	TEMP
-	ror
-	lsr	TEMP
-	ror
-	lsr	TEMP
-	ror
-	clc
-	adc	ADDR
-	sta	ADDR
-	lda	ADDR+1		; ADDR = Y*80+x/8
-	adc	TEMP
-	sta	ADDR+1
-	lda	ADDR+1
-	adc	SCRBASE
-	sta	ADDR+1
-	lda	X1
-	and	#7
-	tax
-	rts
-
-;-------------
-; VDC helpers
-
-VDCSetSourceAddr:
-	pha
-	tya
-	ldx	#VDC_DATA_HI
-	jsr	VDCWriteReg
-	pla
-	ldx	#VDC_DATA_LO
-	bne	VDCWriteReg
-
-VDCReadByte:
-	ldx	#VDC_DATA
-VDCReadReg:
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	lda	VDC_DATA_REG
-	rts
-
-VDCWriteByte:
-	ldx	#VDC_DATA
-VDCWriteReg:
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	sta	VDC_DATA_REG
-	rts
-
-; ------------------------------------------------------------------------
-
-	.include     	"../tgi/tgidrv_line.inc"
diff --git a/libsrc/c128/c128-640-480-2.s b/libsrc/c128/c128-640-480-2.s
deleted file mode 100644
index 021b95245..000000000
--- a/libsrc/c128/c128-640-480-2.s
+++ /dev/null
@@ -1,792 +0,0 @@
-;
-; Graphics driver for the 640x480x2 mode on the C128 VDC 64k
-; (values for this mode based on Fred Bowen's document)
-; Maciej 'YTM/Elysium' Witkowiak 
-; 23.12.2002
-; 2004-04-04, Greg King
-;
-; NOTES:
-; For any smart monkey that will try to optimize this: PLEASE do tests on
-; real VDC, not only VICE.
-;
-; Only DONE routine contains C128-mode specific stuff, everything else will
-; work in C64-mode of C128 (C64 needs full VDC init then).
-;
-; With special initialization and CALC we can get 320x200 double-pixel mode.
-;
-; Color translation values for BROWN and GRAY3 are obviously wrong, they
-; could be replaced by equiv. of ORANGE and GRAY2 but this would give only
-; 14 of 16 colors available.
-;
-; Register 25 ($19) is said to require different value for VDC v1, but I
-; couldn't find what it should be.
-
-	.include     	"zeropage.inc"
-
-      	.include     	"tgi-kernel.inc"
-        .include        "tgi-error.inc"
-
-
-        .macpack        generic
-
-; ------------------------------------------------------------------------
-; Constants
-
-VDC_ADDR_REG	  = $D600		  ; VDC address
-VDC_DATA_REG	  = $D601		  ; VDC data
-
-VDC_DSP_HI	  = 12			  ; registers used
-VDC_DSP_LO	  = 13
-VDC_DATA_HI	  = 18
-VDC_DATA_LO	  = 19
-VDC_VSCROLL	  = 24
-VDC_HSCROLL	  = 25
-VDC_COLORS	  = 26
-VDC_CSET	  = 28
-VDC_COUNT	  = 30
-VDC_DATA	  = 31
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table and constants.
-
-.segment        "JUMPTABLE"
-
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
-
-        .byte   $74, $67, $69           ; "tgi"
-        .byte   TGI_API_VERSION         ; TGI API version number
-xres:   .word   640                     ; X resolution
-yres:   .word   480                     ; Y resolution
-        .byte   2                       ; Number of drawing colors
-pages:	.byte   0                       ; Number of screens available
-        .byte   8                       ; System font X size
-        .byte   8                       ; System font Y size
-        .word   $0100                   ; Aspect ratio (based on 4/3 display)
-        .byte   0                       ; TGI driver flags
-
-; Next comes the jump table. Currently all entries must be valid and may point
-; to an RTS for test versions (function not implemented).
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   INIT
-        .addr   DONE
-       	.addr   GETERROR
-        .addr   CONTROL
-        .addr   CLEAR
-        .addr   SETVIEWPAGE
-        .addr   SETDRAWPAGE
-        .addr   SETCOLOR
-        .addr   SETPALETTE
-        .addr   GETPALETTE
-        .addr   GETDEFPALETTE
-        .addr   SETPIXEL
-        .addr   GETPIXEL
-        .addr   LINE
-        .addr   BAR
-        .addr   TEXTSTYLE
-        .addr   OUTTEXT
-        .addr   0                       ; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-; Data.
-
-; Variables mapped to the zero page segment variables. Some of these are
-; used for passing parameters to the driver.
-
-X1              = ptr1
-Y1              = ptr2
-X2              = ptr3
-Y2              = ptr4
-
-ADDR		= tmp1
-TEMP		= tmp3
-TEMP2		= tmp4		; HORLINE
-TEMP3		= sreg		; HORLINE
-
-; Absolute variables used in the code
-
-.bss
-
-ERROR:  	.res	1     	; Error code
-PALETTE:        .res    2       ; The current palette
-
-BITMASK:        .res    1       ; $00 = clear, $FF = set pixels
-
-OLDCOLOR:	.res	1	; colors before entering gfx mode
-
-; Text output stuff
-TEXTMAGX:       .res    1
-TEXTMAGY:       .res    1
-TEXTDIR:        .res    1
-
-; Constants and tables
-
-.rodata
-
-DEFPALETTE:     .byte   $00, $0f        ; White on black
-PALETTESIZE     = * - DEFPALETTE
-
-BITTAB:         .byte   $80,$40,$20,$10,$08,$04,$02,$01
-
-BITMASKL:	.byte	%11111111, %01111111, %00111111, %00011111
-		.byte   %00001111, %00000111, %00000011, %00000001
-
-BITMASKR:	.byte	%10000000, %11000000, %11100000, %11110000
-		.byte	%11111000, %11111100, %11111110, %11111111
-
-; color translation table (indexed by VIC color)
-COLTRANS:	.byte $00, $0f, $08, $06, $0a, $04, $02, $0c
-		.byte $0d, $0b, $09, $01, $0e, $05, $03, $07
-		; colors BROWN and GRAY3 are wrong
-
-; VDC initialization table (reg),(val),...,$ff
-InitVDCTab:
-		.byte VDC_DSP_HI, 0		; viewpage 0 as default
-		.byte VDC_DSP_LO, 0
-		.byte VDC_HSCROLL, $87
-		.byte 2, $66
-		.byte 4, $4c
-		.byte 5, $06
-		.byte 6, $4c
-		.byte 7, $47
-		.byte 8, $03
-		.byte 9, $06
-		.byte 27, $00
-		.byte $ff
-
-SCN80CLR: 	.byte 27,88,147,27,88,0
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-;
-; Must set an error code: NO
-;
-
-INSTALL:
-	; check for VDC version and update register $19 value
-
-	; check for VDC ram size and update number of available screens
-
-	ldx	#VDC_CSET	; determine size of RAM...
-	jsr	VDCReadReg
-	sta	tmp1
-	ora	#%00010000
-	jsr	VDCWriteReg	; turn on 64k
-
-	jsr	settestadr1	; save original value of test byte
-	jsr	VDCReadByte
-	sta	tmp2
-
-	lda	#$55		; write $55 here
-	ldy	#ptr1
-	jsr	test64k		; read it here and there
-	lda	#$aa		; write $aa here
-	ldy	#ptr2
-	jsr	test64k		; read it here and there
-
-	jsr	settestadr1
-	lda	tmp2
-	jsr	VDCWriteByte	; restore original value of test byte
-
-	lda	ptr1		; do bytes match?
-	cmp	ptr1+1
-	bne	@have64k
-	lda	ptr2
-	cmp	ptr2+1
-	bne	@have64k
-
-	ldx	#VDC_CSET
-	lda	tmp1
-	jsr	VDCWriteReg	; restore 16/64k flag
-	jmp	@endok		; and leave default values for 16k
-
-@have64k:
-	lda	#1
-	sta	pages
-@endok:
-        rts
-
-test64k:
-	sta	tmp1
-	sty	ptr3
-	lda	#0
-	sta	ptr3+1
-	jsr	settestadr1
-	lda	tmp1
-	jsr	VDCWriteByte		; write $55
-	jsr	settestadr1
-	jsr	VDCReadByte		; read here
-	pha
-	jsr	settestadr2
-	jsr	VDCReadByte		; and there
-	ldy	#1
-	sta	(ptr3),y
-	pla
-	dey
-	sta	(ptr3),y
-	rts
-
-settestadr1:
-	ldy	#$02			; test page 2 (here)
-	.byte	$2c
-settestadr2:
-	ldy	#$42			; or page 64+2 (there)
-	lda	#0
-	jmp	VDCSetSourceAddr
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL but is probably empty most of the time.
-;
-; Must set an error code: NO
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; INIT: Changes an already installed device from text mode to graphics
-; mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is only called once, so any code that is needed
-; to initializes variables and so on must go here. Setting palette and
-; clearing the screen is not needed because this is called by the graphics
-; kernel later.
-; The graphics kernel will never call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-;
-; Must set an error code: YES
-;
-
-INIT:
-	lda	pages			; is there enough memory?
-	bne	@L1			; Jump if there is one screen
-	lda	#TGI_ERR_INV_MODE	; Error
-	bne	@L9
-
-; Initialize variables
-
-@L1:    ldx     #$FF
-        stx     BITMASK
-
-; Remeber current color value
-	ldx	#VDC_COLORS
-	jsr	VDCReadReg
-	sta	OLDCOLOR
-
-; Switch into graphics mode (set view page 0)
-
-	ldy	#0
-@L2:	ldx	InitVDCTab,y
-	bmi	@L3
-	iny
-	lda	InitVDCTab,y
-	jsr	VDCWriteReg
-	iny
-	bne	@L2
-@L3:
-
-; Done, reset the error code
-
-        lda     #TGI_ERR_OK
-@L9:    sta     ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel will never call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-;
-; Must set an error code: NO
-;
-
-DONE:
-	; This part is C128-mode specific
-	jsr $e179		; reload character set and setup VDC
-	jsr $ff62
-	lda $d7			; in 80-columns?
-	bne @L01
-@L0:	lda SCN80CLR,y
-	beq @L1
-	jsr $ffd2		; print \xe,clr,\xe
-	iny
-	bne @L0
-@L01:	lda #147
-	jsr $ffd2		; print clr
-@L1:	lda #0			; restore view page
-	ldx #VDC_DSP_HI
-	jsr VDCWriteReg
-	lda OLDCOLOR
-	ldx #VDC_COLORS
-	jsr VDCWriteReg		; restore color (background)
-	lda #$47
-	ldx #VDC_HSCROLL
-       	jmp VDCWriteReg		; switch to text screen
-
-; ------------------------------------------------------------------------
-; GETERROR: Return the error code in A and clear it.
-
-GETERROR:
-       	ldx	#TGI_ERR_OK
-	lda	ERROR
-	stx	ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; CONTROL: Platform/driver specific entry point.
-;
-; Must set an error code: YES
-;
-
-CONTROL:
-	lda	#TGI_ERR_INV_FUNC
-	sta	ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; CLEAR: Clears the screen.
-;
-; Must set an error code: NO
-;
-
-CLEAR:
-	lda	#0
-	tay
-	jsr	VDCSetSourceAddr
-	lda	#0
-	ldx	#VDC_VSCROLL
-	jsr	VDCWriteReg			; set fill mode
-	lda	#0
-	jsr	VDCWriteByte			; put 1rst byte (fill value)
-	ldy	#159				; 159 times
-	lda	#0				; 256 bytes
-	ldx	#VDC_COUNT
-@L1:	jsr	VDCWriteReg
-	dey
-	bne	@L1
-	rts
-
-; ------------------------------------------------------------------------
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETVIEWPAGE:
-	rts
-
-; ------------------------------------------------------------------------
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETDRAWPAGE:
-	rts
-
-; ------------------------------------------------------------------------
-; SETCOLOR: Set the drawing color (in A). The new color is already checked
-; to be in a valid range (0..maxcolor-1).
-;
-; Must set an error code: NO (will only be called if color ok)
-;
-
-SETCOLOR:
-        tax
-        beq     @L1
-        lda     #$FF
-@L1:    sta     BITMASK
-        rts
-
-; ------------------------------------------------------------------------
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported
-;
-; Must set an error code: YES
-;
-
-SETPALETTE:
-        ldy     #PALETTESIZE - 1
-@L1:    lda     (ptr1),y        ; Copy the palette
-        and     #$0F            ; Make a valid color
-        sta     PALETTE,y
-        dey
-        bpl     @L1
-
-; Get the color entries from the palette
-
-        ldy     PALETTE+1       ; Foreground color
-	lda	COLTRANS,y
-        asl     a
-        asl     a
-        asl     a
-        asl     a
-        ldy     PALETTE         ; Background color
-	ora	COLTRANS,y
-
-	ldx	#VDC_COLORS
-       	jsr     VDCWriteReg
-        lda     #TGI_ERR_OK     ; Clear error code
-        sta     ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-;
-; Must set an error code: NO
-;
-
-GETPALETTE:
-        lda     #PALETTE
-        rts
-
-; ------------------------------------------------------------------------
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes, otherwise the caller has no way to determine the colors
-; of the (not changeable) palette.
-;
-; Must set an error code: NO (all drivers must have a default palette)
-;
-
-GETDEFPALETTE:
-        lda     #DEFPALETTE
-        rts
-
-; ------------------------------------------------------------------------
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The coordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-;
-; Must set an error code: NO
-;
-
-SETPIXEL:
-        jsr     CALC            ; Calculate coordinates
-
-	stx	TEMP
-	lda	ADDR
-	ldy	ADDR+1
-	jsr	VDCSetSourceAddr
-	jsr	VDCReadByte
-	ldx	TEMP
-
-	sta	TEMP
-        eor     BITMASK
-        and     BITTAB,X
-	eor	TEMP
-	pha
-	lda	ADDR
-	ldy	ADDR+1
-	jsr	VDCSetSourceAddr
-	pla
-	jsr	VDCWriteByte
-
-@L9:    rts
-
-; ------------------------------------------------------------------------
-; GETPIXEL: Read the color value of a pixel and return it in A/X. The
-; coordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-
-
-GETPIXEL:
-        jsr     CALC            ; Calculate coordinates
-
-	stx	TEMP		; preserve X
-	lda	ADDR
-	ldy	ADDR+1
-	jsr	VDCSetSourceAddr
-	jsr	VDCReadByte
-	ldx	TEMP
-
-        ldy     #$00
-        and     BITTAB,X
-        beq     @L1
-        iny
-
-@L1:    tya                     ; Get color value into A
-        ldx     #$00            ; Clear high byte
-        rts
-
-; ------------------------------------------------------------------------
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the coordinates before calling the driver, so on entry the following
-; conditions are valid:
-;       X1 <= X2
-;       Y1 <= Y2
-;       (X1 >= 0) && (X1 < XRES)
-;       (X2 >= 0) && (X2 < XRES)
-;       (Y1 >= 0) && (Y1 < YRES)
-;       (Y2 >= 0) && (Y2 < YRES)
-;
-; Must set an error code: NO
-;
-
-BAR:
-	inc	Y2
-	bne	HORLINE
-	inc	Y2+1
-
-; Original code for a horizontal line
-
-HORLINE:
-	lda X1
-	pha
-	lda X1+1
-	pha
-	jsr CALC		; get data for LEFT
-	lda BITMASKL,x		; remember left address and bitmask
-	pha
-	lda ADDR
-	pha
-	lda ADDR+1
-	pha
-
-	lda X2
-	sta X1
-	lda X2+1
-	sta X1+1
-	jsr CALC		; get data for RIGHT
-	lda BITMASKR,x
-	sta TEMP3
-
-	pla			; recall data for LEFT
-	sta X1+1
-	pla
-	sta X1			; put left address into X1
-	pla
-
-	cmp #%11111111		; if left bit <> 0
-	beq @L1
-	sta TEMP2		; do left byte only...
-	lda X1
-	ldy X1+1
-	jsr VDCSetSourceAddr
-	jsr VDCReadByte
-	sta TEMP
-	eor BITMASK
-	and TEMP2
-	eor TEMP
-	pha
-	lda X1
-	ldy X1+1
-	jsr VDCSetSourceAddr
-	pla
-	jsr VDCWriteByte
-	inc X1			; ... and proceed
-	bne @L1
-	inc X1+1
-
-	; do right byte (if Y2=0 ++ADDR and skip)
-@L1:	lda TEMP3
-	cmp #%11111111		; if right bit <> 7
-	bne @L11
-	inc ADDR		; right bit = 7 - the next one is the last
-	bne @L10
-	inc ADDR+1
-@L10:	bne @L2
-
-@L11:	lda ADDR		; do right byte only...
-	ldy ADDR+1
-	jsr VDCSetSourceAddr
-	jsr VDCReadByte
-	sta TEMP
-	eor BITMASK
-	and TEMP3
-	eor TEMP
-	pha
-	lda ADDR
-	ldy ADDR+1
-	jsr VDCSetSourceAddr
-	pla
-	jsr VDCWriteByte
-
-@L2:				; do the fill in the middle
-	lda ADDR		; calculate offset in full bytes
-	sec
-	sbc X1
-	beq @L3			; if equal - there are no more bytes
-	sta ADDR
-
-	lda X1			; setup for the left side
-	ldy X1+1
-	jsr VDCSetSourceAddr
-	lda BITMASK		; get color
-	jsr VDCWriteByte	; put 1st value
-	ldx ADDR
-	dex
-	beq @L3			; 1 byte already written
-
-	stx ADDR		; if there are more bytes - fill them...
-	ldx #VDC_VSCROLL
-	lda #0
-	jsr VDCWriteReg		; setup for fill
-	ldx #VDC_COUNT
-	lda ADDR
-	jsr VDCWriteReg		; ... fill them NOW!
-
-@L3:	pla
-	sta X1+1
-	pla
-	sta X1
-
-; End of horizontal line code
-
-	inc	Y1
-	bne	@L4
-	inc	Y1+1
-@L4:	lda	Y1
-	cmp	Y2
-	bne	@L5
-	lda	Y1+1
-	cmp	Y2+1
-	bne	@L5
-	rts
-
-@L5:	jmp	HORLINE
-
-
-; ------------------------------------------------------------------------
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
-; direction is passend in X/Y, the text direction is passed in A.
-;
-; Must set an error code: NO
-;
-
-TEXTSTYLE:
-        stx     TEXTMAGX
-        sty     TEXTMAGY
-        sta     TEXTDIR
-        rts
-
-
-; ------------------------------------------------------------------------
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero terminated
-; string with address in ptr3.
-;
-; Must set an error code: NO
-;
-
-OUTTEXT:
-        rts
-
-; ------------------------------------------------------------------------
-; Calculate all variables to plot the pixel at X1/Y1.
-;------------------------
-;< X1,Y1 - pixel
-;> ADDR - address of card
-;> X - bit number (X1 & 7)
-CALC:
-	lda	Y1
-	pha
-	lda	Y1+1
-	pha
-	lsr
-	ror	Y1		; Y=Y/2
-	sta	Y1+1
-	sta	ADDR+1
-	lda	Y1
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1		; Y*4
-	clc
-	adc	Y1
-	sta	ADDR
-	lda	Y1+1
-	adc	ADDR+1
-	sta	ADDR+1		; Y*4+Y=Y*5
-	lda	ADDR
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1
-	asl
-	rol	ADDR+1
-	sta	ADDR		; Y*5*16=Y*80
-	lda	X1+1
-	sta	TEMP
-	lda	X1
-	lsr	TEMP
-	ror
-	lsr	TEMP
-	ror
-	lsr	TEMP
-	ror
-	clc
-	adc	ADDR
-	sta	ADDR
-	lda	ADDR+1		; ADDR = Y*80+x/8
-	adc	TEMP
-	sta	ADDR+1
-	pla
-	sta	Y1+1
-	pla
-	sta	Y1
-	and	#1
-	beq	@even		; even line - no offset
-	lda	ADDR
-	clc
-	adc	#<21360
-	sta	ADDR
-	lda	ADDR+1
-	adc	#>21360
-	sta	ADDR+1		; odd lines are 21360 bytes farther
-@even:	lda	X1
-	and	#7
-	tax
-	rts
-
-;-------------
-; VDC helpers
-
-VDCSetSourceAddr:
-	pha
-	tya
-	ldx	#VDC_DATA_HI
-	jsr	VDCWriteReg
-	pla
-	ldx	#VDC_DATA_LO
-	bne	VDCWriteReg
-
-VDCReadByte:
-	ldx	#VDC_DATA
-VDCReadReg:
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	lda	VDC_DATA_REG
-	rts
-
-VDCWriteByte:
-	ldx	#VDC_DATA
-VDCWriteReg:
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	sta	VDC_DATA_REG
-	rts
-
-; ------------------------------------------------------------------------
-
-	.include     	"../tgi/tgidrv_line.inc"
diff --git a/libsrc/c128/c128-georam.s b/libsrc/c128/c128-georam.s
deleted file mode 100644
index 23c3469c5..000000000
--- a/libsrc/c128/c128-georam.s
+++ /dev/null
@@ -1,349 +0,0 @@
-;
-; Extended memory driver for the GEORAM cartridge. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2002-11-29
-;
-; GEORAM page size checking routine by
-; Marco van den Heuvel, 2010-01-21
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"em-kernel.inc"
-        .include        "em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-        .word   COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-GR_WINDOW       = $DE00                 ; Address of GEORAM window
-GR_PAGE_LO      = $DFFE                 ; Page register low
-GR_PAGE_HI      = $DFFF                 ; Page register high
-
-; ------------------------------------------------------------------------
-; Data.
-
-.data
-
-pagecount:      .res    2               ; Number of available pages
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-       	ldx     GR_WINDOW
-        cpx     GR_WINDOW
-        bne     @notpresent
-        inc     GR_WINDOW
-       	cpx     GR_WINDOW
-       	beq     @notpresent
-
-       	lda     #4
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has64k
-       	lda     #8
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has128k
-       	lda     #16
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has256k
-       	lda     #32
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has512k
-       	lda     #64
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has1024k
-       	lda     #128
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has2048k
-       	ldx     #>16384
-        bne     @setok
-
-@has64k:
-       	ldx     #>256
-       	bne     @setok
-@has128k:
-       	ldx     #>512
-       	bne     @setok
-@has256k:
-       	ldx     #>1024
-       	bne     @setok
-@has512k:
-       	ldx     #>2048
-       	bne     @setok
-@has1024k:
-       	ldx     #>4096
-       	bne     @setok
-@has2048k:
-       	ldx     #>8192
-       	bne     @setok
-
-@notpresent:
-       	lda     #EM_ERR_NO_DEVICE
-	rts
-
-@setok:
-       	lda     #0
-       	sta     pagecount
-       	stx     pagecount+1
-       	lda     #EM_ERR_OK
-	rts
-
-check:
-       	ldx     #0
-       	stx     GR_PAGE_LO
-       	stx     GR_PAGE_HI
-       	ldy     GR_WINDOW
-       	iny
-       	sta     GR_PAGE_HI
-       	sty     GR_WINDOW
-       	ldx     #0
-       	stx     GR_PAGE_HI
-;	rts                     ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-; The GeoRAM cartridge does not copy but actually map the window, so USE is
-; identical to MAP.
-
-USE     = MAP
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta     tmp1
-        txa
-        asl     tmp1
-        rol     a
-        asl     tmp1
-        rol     a
-
-        sta     GR_PAGE_HI
-        lda     tmp1
-        lsr     a
-        lsr     a
-        sta     GR_PAGE_LO
-
-        lda     #GR_WINDOW
-
-; Use the RTS from COMMIT below to save a precious byte of storage
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     GR_WINDOW,x
-        sta     (ptr2),y
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:    inc     tmp1            ; Bump low page register
-        bit     tmp1            ; Check for overflow in bit 6
-        bvc     @L6             ; Jump if no overflow
-        inc     tmp2
-@L5:    lda     tmp2
-        sta     GR_PAGE_HI
-@L6:    lda     tmp1
-        sta     GR_PAGE_LO
-        jmp     @L3
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     (ptr2),y
-        sta     GR_WINDOW,x
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:    inc     tmp1            ; Bump low page register
-        bit     tmp1            ; Check for overflow in bit 6
-        bvc     @L6             ; Jump if no overflow
-        inc     tmp2
-@L5:    lda     tmp2
-        sta     GR_PAGE_HI
-@L6:    lda     tmp1
-        sta     GR_PAGE_LO
-        jmp     @L3
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-
-setup:  sta     ptr1
-        stx     ptr1+1          ; Save passed pointer
-
-; Get the page number from the struct and adjust it so that it may be used
-; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
-
-        ldy     #EM_COPY::PAGE+1
-        lda     (ptr1),y
-        sta     tmp2
-        dey
-        lda     (ptr1),y
-        asl     a
-        rol     tmp2
-        asl     a
-        rol     tmp2
-        lsr     a
-        lsr     a
-        sta     tmp1
-
-; Get the buffer pointer into ptr2
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr1),y
-        sta     ptr2
-        iny
-        lda     (ptr1),y
-        sta     ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy     #EM_COPY::COUNT
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3
-        iny
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3+1
-
-; Get the page offset into X and clear Y
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr1),y
-        tax
-        ldy     #$00
-
-; Done
-
-        rts
-
-
diff --git a/libsrc/c128/c128-joymouse.s b/libsrc/c128/c128-joymouse.s
deleted file mode 100644
index 0cceaa7f1..000000000
--- a/libsrc/c128/c128-joymouse.s
+++ /dev/null
@@ -1,415 +0,0 @@
-;
-; Driver for a "joystick mouse".
-;
-; Ullrich von Bassewitz, 2004-04-05, 2009-09-26
-;
-
-        .include        "zeropage.inc"
-        .include        "mouse-kernel.inc"
-	.include	"c128.inc"
-
-        .macpack        generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-HEADER:
-
-; Driver signature
-
-        .byte   $6d, $6f, $75           ; "mou"
-        .byte   MOUSE_API_VERSION       ; Mouse driver API version number
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   HIDE
-        .addr   SHOW
-        .addr   SETBOX
-        .addr   GETBOX
-        .addr   MOVE
-        .addr   BUTTONS
-        .addr   POS
-        .addr   INFO
-        .addr   IOCTL
-        .addr   IRQ
-
-; Mouse driver flags
-
-        .byte   MOUSE_FLAG_LATE_IRQ
-
-; Callback table, set by the kernel before INSTALL is called
-
-CHIDE:  jmp     $0000                   ; Hide the cursor
-CSHOW:  jmp     $0000                   ; Show the cursor
-CMOVEX: jmp     $0000                   ; Move the cursor to X coord
-CMOVEY: jmp     $0000                   ; Move the cursor to Y coord
-
-
-;----------------------------------------------------------------------------
-; Constants
-
-SCREEN_HEIGHT   = 200
-SCREEN_WIDTH    = 320
-
-.enum   JOY
-        UP      = $01
-        DOWN    = $02
-        LEFT    = $04
-        RIGHT   = $08
-        FIRE    = $10
-.endenum
-
-;----------------------------------------------------------------------------
-; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the SETBOX and GETBOX routines, so don't
-; reorder them.
-
-.bss
-
-Vars:
-YPos:           .res    2               ; Current mouse position, Y
-XPos:           .res    2               ; Current mouse position, X
-XMin:		.res  	2	     	; X1 value of bounding box
-YMin:		.res  	2	     	; Y1 value of bounding box
-XMax:		.res  	2	     	; X2 value of bounding box
-YMax:		.res  	2	     	; Y2 value of bounding box
-Buttons:	.res  	1		; Button mask
-
-; Temporary value used in the int handler
-
-Temp:           .res    1
-
-; Default values for above variables
-
-.rodata
-
-.proc   DefVars
-        .word   SCREEN_HEIGHT/2         ; YPos
-        .word   SCREEN_WIDTH/2          ; XPos
-        .word   0                       ; XMin
-        .word   0                       ; YMin
-        .word   SCREEN_WIDTH            ; XMax
-        .word   SCREEN_HEIGHT           ; YMax
-	.byte	0			; Buttons
-.endproc
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an MOUSE_ERR_xx code in a/x.
-
-INSTALL:
-
-; Initialize variables. Just copy the default stuff over
-
-        ldx     #.sizeof(DefVars)-1
-@L1:    lda     DefVars,x
-        sta     Vars,x
-        dex
-        bpl     @L1
-
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
-
-        sei
-        jsr     CHIDE
-        lda     XPos
-        ldx     XPos+1
-        jsr     CMOVEX
-        lda     YPos
-        ldx     YPos+1
-        jsr     CMOVEY
-        cli
-
-; Done, return zero (= MOUSE_ERR_OK)
-
-        ldx     #$00
-        txa
-        rts
-
-;----------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-
-UNINSTALL       = HIDE                  ; Hide cursor on exit
-
-;----------------------------------------------------------------------------
-; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required besides hiding the mouse cursor.
-; No return code required.
-
-HIDE:   sei
-        jsr     CHIDE
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required besides enabling the mouse cursor.
-; No return code required.
-
-SHOW:   sei
-        jsr     CSHOW
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in a/x.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-
-SETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     (ptr1),y
-        sta     XMin,y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in a/x.
-
-GETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     XMin,y
-        sta     (ptr1),y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-;
-
-MOVE:   sei                             ; No interrupts
-
-        sta     YPos
-        stx     YPos+1                  ; New Y position
-        jsr     CMOVEY                  ; Set it
-
-        ldy     #$01
-        lda     (sp),y
-        sta     XPos+1
-        tax
-        dey
-        lda     (sp),y
-        sta     XPos                    ; New X position
-
-        jsr     CMOVEX			; Move the cursor
-
-	cli                             ; Allow interrupts
-       	rts
-
-;----------------------------------------------------------------------------
-; BUTTONS: Return the button mask in a/x.
-
-BUTTONS:
-	lda	Buttons
-	ldx	#$00
-	rts
-
-;----------------------------------------------------------------------------
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-
-POS:    ldy    	#MOUSE_POS::XCOORD      ; Structure offset
-
-	sei	    			; Disable interrupts
-	lda     XPos			; Transfer the position
-	sta	(ptr1),y
-	lda	XPos+1
-	iny
-	sta	(ptr1),y
-      	lda	YPos
-        iny
-        sta     (ptr1),y
-	lda	YPos+1
-	cli	    			; Enable interrupts
-
-        iny
-        sta     (ptr1),y                ; Store last byte
-
-    	rts	    			; Done
-
-;----------------------------------------------------------------------------
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-;
-; We're cheating here to keep the code smaller: The first fields of the
-; mouse_info struct are identical to the mouse_pos struct, so we will just
-; call _mouse_pos to initialize the struct pointer and fill the position
-; fields.
-
-INFO:   jsr	POS
-
-; Fill in the button state
-
-       	lda	Buttons
-    	ldy	#MOUSE_INFO::BUTTONS
-    	sta	(ptr1),y
-
-      	rts
-
-;----------------------------------------------------------------------------
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an error code in a/x.
-;
-
-IOCTL:  lda     #MOUSE_ERR_INV_IOCTL
-        rts
-
-;----------------------------------------------------------------------------
-; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
-; (so be careful). The routine MUST return carry set if the interrupt has been
-; 'handled' - which means that the interrupt source is gone. Otherwise it
-; MUST return carry clear.
-;
-
-IRQ:	lda	#$7F
-     	sta	CIA1_PRA
-     	lda	CIA1_PRB                ; Read joystick #0
-        and     #$1F
-	eor	#$1F  	       		; Make all bits active high
-        sta     Temp
-
-; Check for a pressed button and place the result into Buttons
-
-        ldx     #$00                    ; Assume no button pressed
-        and     #JOY::FIRE              ; Check fire button
-        beq     @L0                     ; Jump if not pressed
-        ldx     #MOUSE_BTN_LEFT         ; Left (only) button is pressed
-@L0:    stx     Buttons
-
-; Check left/right
-
-        lda     Temp                    ; Read joystick #0
-       	and    	#(JOY::LEFT | JOY::RIGHT)
-        beq     @SkipX			;
-
-; We will cheat here and rely on the fact that either the left, OR the right
-; bit can be active
-
-       	and     #JOY::RIGHT             ; Check RIGHT bit
-       	bne	@Right
-      	lda	#$FF
-      	tax
-      	bne	@AddX                   ; Branch always
-@Right:	lda	#$01
-      	ldx	#$00
-
-; Calculate the new X coordinate (--> a/y)
-
-@AddX:  add     XPos
-      	tay	      			; Remember low byte
-      	txa
-      	adc	XPos+1
-    	tax
-
-; Limit the X coordinate to the bounding box
-
-   	cpy	XMin
-   	sbc	XMin+1
-   	bpl	@L1
-       	ldy    	XMin
-       	ldx	XMin+1
-    	jmp	@L2
-@L1:	txa
-
-    	cpy	XMax
-    	sbc	XMax+1
-    	bmi	@L2
-    	ldy	XMax
-    	ldx	XMax+1
-@L2:	sty	XPos
-   	stx	XPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEX
-
-; Calculate the Y movement vector
-
-@SkipX: lda     Temp                    ; Read joystick #0
-       	and    	#(JOY::UP | JOY::DOWN)  ; Check up/down
-        beq     @SkipY		 	;
-
-; We will cheat here and rely on the fact that either the up, OR the down
-; bit can be active
-
-       	lsr     a                       ; Check UP bit
-       	bcc	@Down
-      	lda	#$FF
-      	tax
-      	bne	@AddY
-@Down:	lda	#$01
-    	ldx	#$00
-
-; Calculate the new Y coordinate (--> a/y)
-
-@AddY: 	add    	YPos
-      	tay	      			; Remember low byte
-      	txa
-      	adc	YPos+1
-    	tax
-
-; Limit the Y coordinate to the bounding box
-
-   	cpy	YMin
- 	sbc	YMin+1
- 	bpl	@L3
-       	ldy    	YMin
-       	ldx	YMin+1
-    	jmp	@L4
-@L3:	txa
-
-    	cpy	YMax
-    	sbc	YMax+1
-    	bmi	@L4
-    	ldy	YMax
-    	ldx	YMax+1
-@L4:	sty	YPos
- 	stx	YPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEY
-
-; Done
-
-@SkipY: clc                             ; Interrupt not "handled"
-        rts
-
diff --git a/libsrc/c128/c128-potmouse.s b/libsrc/c128/c128-potmouse.s
deleted file mode 100644
index c6f7a1f86..000000000
--- a/libsrc/c128/c128-potmouse.s
+++ /dev/null
@@ -1,390 +0,0 @@
-;
-; Driver for a potentiometer "mouse" e.g. Koala Pad
-;
-; Ullrich von Bassewitz, 2004-03-29, 2009-09-26
-; Stefan Haubenthal, 2006-08-20
-;
-
-	.include	"zeropage.inc"
-	.include	"mouse-kernel.inc"
-	.include	"c128.inc"
-
-	.macpack	generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-HEADER:
-
-; Driver signature
-
-	.byte	$6d, $6f, $75		; "mou"
-	.byte	MOUSE_API_VERSION	; Mouse driver API version number
-
-; Jump table.
-
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	HIDE
-	.addr	SHOW
-	.addr	SETBOX
-        .addr   GETBOX
-	.addr	MOVE
-	.addr	BUTTONS
-	.addr	POS
-	.addr	INFO
-	.addr	IOCTL
-	.addr	IRQ
-
-; Callback table, set by the kernel before INSTALL is called
-
-CHIDE:	jmp	$0000			; Hide the cursor
-CSHOW:	jmp	$0000			; Show the cursor
-CMOVEX: jmp	$0000			; Move the cursor to X coord
-CMOVEY: jmp	$0000			; Move the cursor to Y coord
-
-
-;----------------------------------------------------------------------------
-; Constants
-
-SCREEN_HEIGHT	= 200
-SCREEN_WIDTH	= 320
-
-.enum	JOY
-	UP	= $01
-	DOWN	= $02
-	LEFT	= $04
-	RIGHT	= $08
-	FIRE	= $10
-.endenum
-
-;----------------------------------------------------------------------------
-; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the SETBOX and GETBOX routines, so don't
-; reorder them.
-
-.bss
-
-Vars:
-YPos:		.res	2		; Current mouse position, Y
-XPos:		.res	2		; Current mouse position, X
-XMin:		.res	2		; X1 value of bounding box
-YMin:		.res	2		; Y1 value of bounding box
-XMax:		.res	2		; X2 value of bounding box
-YMax:		.res	2		; Y2 value of bounding box
-Buttons:	.res	1		; Button mask
-
-; Temporary value used in the int handler
-
-Temp:		.res	1
-
-; Default values for above variables
-
-.rodata
-
-.proc	DefVars
-	.word	SCREEN_HEIGHT/2		; YPos
-	.word	SCREEN_WIDTH/2		; XPos
-	.word	0			; XMin
-	.word	0			; YMin
-	.word	SCREEN_WIDTH		; XMax
-	.word	SCREEN_HEIGHT		; YMax
-	.byte	0			; Buttons
-.endproc
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an MOUSE_ERR_xx code in a/x.
-
-INSTALL:
-
-; Initialize variables. Just copy the default stuff over
-
-	ldx	#.sizeof(DefVars)-1
-@L1:	lda	DefVars,x
-	sta	Vars,x
-	dex
-	bpl	@L1
-
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
-
-	sei
-	jsr	CHIDE
-	lda	XPos
-	ldx	XPos+1
-	jsr	CMOVEX
-	lda	YPos
-	ldx	YPos+1
-	jsr	CMOVEY
-	cli
-
-; Done, return zero (= MOUSE_ERR_OK)
-
-	ldx	#$00
-	txa
-	rts
-
-;----------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-
-UNINSTALL	= HIDE			; Hide cursor on exit
-
-;----------------------------------------------------------------------------
-; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required besides hiding the mouse cursor.
-; No return code required.
-
-HIDE:	sei
-	jsr	CHIDE
-	cli
-	rts
-
-;----------------------------------------------------------------------------
-; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required besides enabling the mouse cursor.
-; No return code required.
-
-SHOW:	sei
-	jsr	CSHOW
-	cli
-	rts
-
-;----------------------------------------------------------------------------
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in a/x.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-
-SETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     (ptr1),y
-        sta     XMin,y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in a/x.
-
-GETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     XMin,y
-        sta     (ptr1),y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-;
-
-MOVE:	sei				; No interrupts
-
-	sta	YPos
-	stx	YPos+1			; New Y position
-	jsr	CMOVEY			; Set it
-
-	ldy	#$01
-	lda	(sp),y
-	sta	XPos+1
-	tax
-	dey
-	lda	(sp),y
-	sta	XPos			; New X position
-
-	jsr	CMOVEX			; Move the cursor
-
-	cli				; Allow interrupts
-	rts
-
-;----------------------------------------------------------------------------
-; BUTTONS: Return the button mask in a/x.
-
-BUTTONS:
-	lda	Buttons
-	ldx	#$00
-	rts
-
-;----------------------------------------------------------------------------
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-
-POS:	ldy	#MOUSE_POS::XCOORD	; Structure offset
-
-	sei				; Disable interrupts
-	lda	XPos			; Transfer the position
-	sta	(ptr1),y
-	lda	XPos+1
-	iny
-	sta	(ptr1),y
-	lda	YPos
-	iny
-	sta	(ptr1),y
-	lda	YPos+1
-	cli				; Enable interrupts
-
-	iny
-	sta	(ptr1),y		; Store last byte
-
-	rts				; Done
-
-;----------------------------------------------------------------------------
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-;
-; We're cheating here to keep the code smaller: The first fields of the
-; mouse_info struct are identical to the mouse_pos struct, so we will just
-; call _mouse_pos to initialize the struct pointer and fill the position
-; fields.
-
-INFO:	jsr	POS
-
-; Fill in the button state
-
-	lda	Buttons
-	ldy	#MOUSE_INFO::BUTTONS
-	sta	(ptr1),y
-
-	rts
-
-;----------------------------------------------------------------------------
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an error code in a/x.
-;
-
-IOCTL:	lda	#MOUSE_ERR_INV_IOCTL
-	rts
-
-;----------------------------------------------------------------------------
-; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
-; (so be careful).
-;
-
-IRQ:	lda	#$7F
-	sta	CIA1_PRA
-	lda	CIA1_PRB		; Read port #1
-	and	#%00001100
-	eor	#%00001100		; Make all bits active high
-	asl
-	sta	Buttons
-	lsr
-	lsr
-	lsr
-	and	#%00000001
-	ora	Buttons
-	sta	Buttons
-	ldx	#%01000000
-	stx	CIA1_PRA
-	ldy	#0
-:	dey
-	bne	:-
-	ldx	SID_ADConv1
-	stx	XPos
-	ldx	SID_ADConv2
-	stx	YPos
-
-	lda	#$FF
-	tax
-	bne	@AddX			; Branch always
-	lda	#$01
-	ldx	#$00
-
-; Calculate the new X coordinate (--> a/y)
-
-@AddX:	add	XPos
-	tay				; Remember low byte
-	txa
-	adc	XPos+1
-	tax
-
-; Limit the X coordinate to the bounding box
-
-	cpy	XMin
-	sbc	XMin+1
-	bpl	@L1
-	ldy	XMin
-	ldx	XMin+1
-	jmp	@L2
-@L1:	txa
-
-	cpy	XMax
-	sbc	XMax+1
-	bmi	@L2
-	ldy	XMax
-	ldx	XMax+1
-@L2:	sty	XPos
-	stx	XPos+1
-
-; Move the mouse pointer to the new X pos
-
-	tya
-	jsr	CMOVEX
-
-	lda	#$FF
-	tax
-	bne	@AddY
-@Down:	lda	#$01
-	ldx	#$00
-
-; Calculate the new Y coordinate (--> a/y)
-
-@AddY:	add	YPos
-	tay				; Remember low byte
-	txa
-	adc	YPos+1
-	tax
-
-; Limit the Y coordinate to the bounding box
-
-	cpy	YMin
-	sbc	YMin+1
-	bpl	@L3
-	ldy	YMin
-	ldx	YMin+1
-	jmp	@L4
-@L3:	txa
-
-	cpy	YMax
-	sbc	YMax+1
-	bmi	@L4
-	ldy	YMax
-	ldx	YMax+1
-@L4:	sty	YPos
-	stx	YPos+1
-
-; Move the mouse pointer to the new X pos
-
-	tya
-	jmp	CMOVEY
diff --git a/libsrc/c128/c128-ptvjoy.s b/libsrc/c128/c128-ptvjoy.s
deleted file mode 100644
index e101997f1..000000000
--- a/libsrc/c128/c128-ptvjoy.s
+++ /dev/null
@@ -1,152 +0,0 @@
-;
-; PTV-4 Player joystick driver for the C128
-;
-; Ullrich von Bassewitz, 2003-09-28, using the C64 driver from
-; Groepaz/Hitmen, 2002-12-23, which is
-; obviously based on Ullrichs driver :)
-;
-
-        .include "zeropage.inc"
-
-        .include "joy-kernel.inc"
-        .include "joy-error.inc"
-        .include "c128.inc"
-
-        .macpack generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-        .segment "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $6A, $6F, $79           ; "joy"
-        .byte   JOY_API_VERSION         ; Driver API version number
-
-; Button state masks (8 values)
-
-        .byte   $01                     ; JOY_UP
-        .byte   $02                     ; JOY_DOWN
-        .byte   $04                     ; JOY_LEFT
-        .byte   $08                     ; JOY_RIGHT
-        .byte   $10                     ; JOY_FIRE
-        .byte   $00                     ; JOY_FIRE2 unavailable
-        .byte   $00                     ; Future expansion
-        .byte   $00                     ; Future expansion
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   COUNT
-        .addr   READ
-        .addr   0                       ; IRQ entry unused
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT       = 4             ; Number of joysticks we support
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda     #JOY_ERR_OK
-;	rts                     ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-        lda     #JOY_COUNT
-        rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:   tax	                ; Joystick number into X
-        bne     joy2
-
-; Read joystick 1
-
-joy1:   lda	#$7F
-        sei
-        sta	CIA1_PRA
-        lda	CIA1_PRB
-        cli
-        and	#$1F
-        eor	#$1F
-        rts
-
-; Read joystick 2
-
-joy2:   dex
-        bne     joy3
-
-        lda 	#$E0
-        ldy 	#$FF
-        sei
-        sta 	CIA1_DDRA
-        lda 	CIA1_PRA
-        sty 	CIA1_DDRA
-        cli
-        and 	#$1F
-        eor 	#$1F
-        rts
-
-; Read joystick 3
-
-joy3:
-        lda     #%10000000      ; cia 2 port B Data-Direction
-        sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
-
-        dex
-        bne     joy4
-
-        lda     #$80            ; cia 2 port B read/write
-        sta     CIA2_PRB        ; (output one at PB7)
-
-        lda     CIA2_PRB        ; cia 2 port B read/write
-        and     #$1f            ; get bit 4-0 (PB4-PB0)
-        eor     #$1f
-        rts
-
-; Read joystick 4
-
-joy4:
-        lda     #$00            ; cia 2 port B read/write
-        sta     CIA2_PRB        ; (output zero at PB7)
-
-        lda     CIA2_PRB        ; cia 2 port B read/write
-        and     #$0f            ; get bit 3-0 (PB3-PB0)
-        sta     tmp1            ; joy 4 directions
-
-        lda     CIA2_PRB        ; cia 2 port B read/write
-        and     #%00100000      ; get bit 5 (PB5)
-        lsr
-        ora     tmp1
-        eor     #$1f
-
-        ldx #0
-        rts
diff --git a/libsrc/c128/c128-ram.s b/libsrc/c128/c128-ram.s
deleted file mode 100644
index 1211c444d..000000000
--- a/libsrc/c128/c128-ram.s
+++ /dev/null
@@ -1,288 +0,0 @@
-;
-; Extended memory driver for the C128 RAM in bank #1. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2002-12-04
-;
-
-	.include  	"zeropage.inc"
-
-      	.include  	"em-kernel.inc"
-        .include        "em-error.inc"
-        .include        "c128.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BASE	= $400
-TOPMEM  = $FF00
-PAGES  	= (TOPMEM - BASE) / 256
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-curpage:        .res    1               ; Current page number
-
-window:         .res    256             ; Memory "window"
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        ldx     #$FF
-        stx     curpage
-        stx     curpage+1               ; Invalidate the current page
-        inx
-        txa                             ; A = X = EM_ERR_OK
-        rts
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     #PAGES
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta     curpage
-        stx     curpage+1               ; Remember the new page
-
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#$00
-        sty    	ptr1
-
-        lda     #window                ; Return the window address
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta     curpage
-        stx     curpage+1               ; Remember the page
-        lda     #window                ; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda     curpage			; Get the current page
-        ldx     curpage+1
-        bmi     done                    ; Jump if no page mapped
-
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#$00
-        sty    	ptr1
-
-        lda     #BASE
-        sta     ptr1+1                  ; From
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr2
-        iny
-        lda     (ptr3),y
-        sta     ptr2+1                  ; To
-
-        lda     #BASE
-        sta     ptr1+1                  ; To
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr2
-        iny
-        lda     (ptr3),y
-        sta     ptr2+1                  ; From
-
-        lda     #BASE
-        sta     ptr1+1
-        ldy     #$00
-        sty     ptr1
-        lda     #window                ; Return the window address
-        cli
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta     curpage
-        stx     curpage+1               ; Remember the page
-        lda     #window                ; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: sei
-        lda     curpage			; Get the current page
-        ldx     curpage+1
-        bmi     done                    ; Jump if no page mapped
-
-        jsr     calculate_bank_and_correct_page
-        stx     curbank
-
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#$00
-        sty     ptr1
-
-        lda     #
-; 06,22.12.2002
-;
-
-
-	.include	"zeropage.inc"
-
-      	.include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-	.word	USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-RAMC_WINDOW       = $DF00               ; Address of RamCart window
-RAMC_PAGE_LO      = $DE00               ; Page register low
-RAMC_PAGE_HI      = $DE01               ; Page register high (only for RC128)
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-
-pagecount:      .res    2               ; Number of pages available
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-	ldx	RAMC_WINDOW
-	cpx	RAMC_WINDOW
-	bne	@notpresent
-
-	lda	#0
-	sta	RAMC_PAGE_LO
-	sta	RAMC_PAGE_HI
-	ldx	RAMC_WINDOW
-	cpx	RAMC_WINDOW
-	bne	@notpresent
-	lda	#2
-	sta	RAMC_WINDOW
-	cmp	RAMC_WINDOW
-	beq	@cont
-	cpx	RAMC_WINDOW
-	beq	@readonly
-@cont:	ldy	#1
-	sty	RAMC_PAGE_HI
-	sty	RAMC_WINDOW
-	dey
-	sty	RAMC_PAGE_HI
-	iny
-	cpy	RAMC_WINDOW
-	beq	@rc64
-	; we're on rc128
-	ldx	#>512
-	bne	@setsize
-@rc64:	ldx	#>256
-@setsize:
-	lda	#0
-	sta	pagecount
-	stx	pagecount+1
-        lda     #EM_ERR_OK
-        rts
-@notpresent:
-@readonly:
-	lda	#EM_ERR_NO_DEVICE
-;	rts                             ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-; The RamCart cartridge does not copy but actually map the window, so USE is
-; identical to MAP.
-
-USE     = MAP
-
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta	RAMC_PAGE_LO
-	stx	RAMC_PAGE_HI
-        lda     #RAMC_WINDOW
-
-; Use the RTS from COMMIT below to save a precious byte of storage
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     RAMC_WINDOW,x
-        sta     (ptr2),y
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:  	inc	tmp1
-	bne	@L5
-	inc	tmp2
-@L5:	lda	tmp1
-	sta	RAMC_PAGE_LO
-	lda	tmp2
-	sta	RAMC_PAGE_HI
-	jmp	@L3
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     (ptr2),y
-        sta     RAMC_WINDOW,x
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:  	inc	tmp1
-	bne	@L5
-	inc	tmp2
-@L5:	lda	tmp1
-	sta	RAMC_PAGE_LO
-	lda	tmp2
-	sta	RAMC_PAGE_HI
-	jmp	@L3
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-
-setup:  sta     ptr1
-        stx     ptr1+1          ; Save passed pointer
-
-; Get the page number from the struct and adjust it so that it may be used
-; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
-
-        ldy     #EM_COPY::PAGE+1
-        lda     (ptr1),y
-        sta     tmp2
-        dey
-        lda     (ptr1),y
-        sta     tmp1
-
-; Get the buffer pointer into ptr2
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr1),y
-        sta     ptr2
-        iny
-        lda     (ptr1),y
-        sta     ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy     #EM_COPY::COUNT
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3
-        iny
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3+1
-
-; Get the page offset into X and clear Y
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr1),y
-        tax
-        ldy     #$00
-
-; Done
-
-        rts
-
diff --git a/libsrc/c128/c128-reu.s b/libsrc/c128/c128-reu.s
deleted file mode 100644
index 4f86f6aee..000000000
--- a/libsrc/c128/c128-reu.s
+++ /dev/null
@@ -1,236 +0,0 @@
-;
-; Extended memory driver for the Commodore REU. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2002-11-29
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"em-kernel.inc"
-        .include        "em-error.inc"
-	.include	"c128.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-REU_STATUS      = $DF00                 ; Status register
-REU_COMMAND     = $DF01                 ; Command register
-REU_C64ADDR     = $DF02                 ; C64 base address register
-REU_REUADDR     = $DF04                 ; REU base address register
-REU_COUNT       = $DF07                 ; Transfer count register
-REU_IRQMASK     = $DF09                 ; IRQ mask register
-REU_CONTROL     = $DF0A                 ; Control register
-REU_TRIGGER     = $FF00                 ; REU command trigger
-
-OP_COPYFROM     = $ED
-OP_COPYTO       = $EC
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-pagecount:      .res    2               ; Number of pages available
-curpage:        .res    2               ; Current page number
-
-window:         .res    256             ; Memory "window"
-
-reu_params:     .word 	$0000  		; Host address, lo, hi
-		.word 	$0000		; Exp  address, lo, hi
-                .byte	$00		; Expansion  bank no.
-       	       	.word  	$0000  		; # bytes to move, lo, hi
-       		.byte 	$00    		; Interrupt mask reg.
-       		.byte 	$00    		; Adress control reg.
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        ldx     #$00                    ; High byte of return code
-        lda     #$55
-        sta     REU_REUADDR
-        cmp     REU_REUADDR             ; Check for presence of REU
-        bne     nodevice
-        asl     a                       ; A = $AA
-        sta     REU_REUADDR
-        cmp     REU_REUADDR             ; Check for presence of REU
-        bne     nodevice
-
-        ldy     #>(128*4)               ; Assume 128KB
-        lda     REU_STATUS
-        and     #$10                    ; Check size bit
-        beq     @L1
-        ldy     #>(256*4)               ; 256KB when size bit is set
-@L1:    sty     pagecount+1
-
-        ldy     #$FF
-        sty     curpage
-        sty     curpage+1               ; Invalidate the current page
-        txa                             ; X = A = EM_ERR_OK
-        rts
-
-; No REU found
-
-nodevice:
-        lda     #EM_ERR_NO_DEVICE
-;       rts                             ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta     curpage
-        stx     curpage+1               ; Remember the new page
-
-        ldy     #OP_COPYFROM
-        jsr     common                  ; Copy the window
-
-        lda     #window                ; Return the window address
-done:   rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta     curpage
-        stx     curpage+1               ; Remember the page
-        lda     #window                ; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda     curpage
-        ldx     curpage+1               ; Do we have a page mapped?
-        bmi     done                    ; Jump if no page mapped
-
-        ldy     #OP_COPYTO
-common: sty     tmp1
-
-        ldy     #window
-        sty     REU_C64ADDR+1
-
-        ldy     #0
-        sty     REU_REUADDR+0
-        sta     REU_REUADDR+1
-        stx     REU_REUADDR+2
-
-        sty     REU_COUNT+0
-        ldy     #1
-        sty     REU_COUNT+1             ; Move 256 bytes
-        bne     transfer1               ; Transfer 256 bytes into REU
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        ldy     #OP_COPYFROM
-        .byte   $2C
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        ldy     #OP_COPYTO
-        sty     tmp1
-
-; Remember the passed pointer
-
-        sta     ptr1
-        stx     ptr1+1          ; Save the pointer
-
-; The structure passed to the functions has the same layout as the registers
-; of the Commodore REU, so register programming is easy.
-
-        ldy     #7-1
-@L1:    lda     (ptr1),y
-        sta     REU_C64ADDR,y
-        dey
-        bpl     @L1
-
-; Invalidate the page in the memory window
-
-        sty     curpage+1       ; Y = $FF
-
-; Reload the REU command and start the transfer
-
-transfer1:
-        ldy     tmp1
-
-; Transfer subroutine for the REU. Expects command in Y.
-
-transfer:
-        sty    	REU_COMMAND     ; Issue command
-
-        ldy    	MMU_CR		; Save the current MMU settings
-	lda	#MMU_CFG_RAM0  	;
-  	sei          	  	;
-        sta	MMU_CR		; Enable RAM in bank #0
-        lda     REU_TRIGGER     ; Don't change $FF00
-        sta 	REU_TRIGGER     ; Start the transfer...
-
-        sty     MMU_CR          ; Restore the old configuration
-        cli
-        rts
-
diff --git a/libsrc/c128/c128-stdjoy.s b/libsrc/c128/c128-stdjoy.s
deleted file mode 100644
index 241e223e7..000000000
--- a/libsrc/c128/c128-stdjoy.s
+++ /dev/null
@@ -1,121 +0,0 @@
-;
-; Standard joystick driver for the C128. May be used multiple times when linked
-; to the statically application.
-
-;
-; Ullrich von Bassewitz, 2002-12-21
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"joy-kernel.inc"
-        .include        "joy-error.inc"
-        .include        "c128.inc"
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $6A, $6F, $79		; "joy"
-        .byte   JOY_API_VERSION		; Driver API version number
-
-; Button state masks (8 values)
-
-        .byte   $01                     ; JOY_UP
-        .byte   $02                     ; JOY_DOWN
-        .byte   $04                     ; JOY_LEFT
-        .byte   $08                     ; JOY_RIGHT
-        .byte   $10                     ; JOY_FIRE
-        .byte   $00                     ; JOY_FIRE2 unavailable
-        .byte   $00                     ; Future expansion
-        .byte   $00                     ; Future expansion
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   COUNT
-        .addr   READ
-        .addr   0                       ; IRQ entry not used
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT       = 2             ; Number of joysticks we support
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda     #JOY_ERR_OK
-;	rts                     ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-        lda     #JOY_COUNT
-        rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:   tax			; Joystick number into X
-	bne    	joy2
-
-; Read joystick 1
-
-joy1:	lda	#$7F
-     	sei
-     	sta	CIA1_PRA
-     	lda	CIA1_PRB
-     	cli
-     	and	#$1F
-     	eor	#$1F
-     	rts
-
-; Read joystick 2
-
-joy2:	ldx	#0
-	lda	#$E0
-	ldy	#$FF
-	sei
-	sta	CIA1_DDRA
-	lda	CIA1_PRA
-	sty	CIA1_DDRA
-	cli
-	and	#$1F
-	eor	#$1F
-	rts
-
-
diff --git a/libsrc/c128/c128-swlink.s b/libsrc/c128/c128-swlink.s
deleted file mode 100644
index 558d80db8..000000000
--- a/libsrc/c128/c128-swlink.s
+++ /dev/null
@@ -1,498 +0,0 @@
-;
-; Serial driver for the C128 using a Swiftlink or Turbo-232 cartridge.
-;
-; Ullrich von Bassewitz, 2003-04-18
-;
-; The driver is based on the cc65 rs232 module, which in turn is based on
-; Craig Bruce device driver for the Switftlink/Turbo-232.
-;
-; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
-;
-; This software is Public Domain.  It is in Buddy assembler format.
-;
-; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
-; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
-; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
-; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
-;
-; The code assumes that the kernal + I/O are in context.  On the C128, call
-; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
-; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
-; interrupt handling assumes that the 65816 is in 6502-emulation mode.
-;
-
-        .include        "zeropage.inc"
-        .include        "ser-kernel.inc"
-        .include        "ser-error.inc"
-	.include	"c128.inc"
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $73, $65, $72           ; "ser"
-        .byte   SER_API_VERSION         ; Serial API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   OPEN
-        .word   CLOSE
-        .word   GET
-        .word   PUT
-        .word   STATUS
-        .word   IOCTL
-	.word	IRQ
-
-;----------------------------------------------------------------------------
-; I/O definitions
-
-ACIA   	        = $DE00
-ACIA_DATA       = ACIA+0        ; Data register
-ACIA_STATUS     = ACIA+1        ; Status register
-ACIA_CMD        = ACIA+2        ; Command register
-ACIA_CTRL       = ACIA+3        ; Control register
-
-;----------------------------------------------------------------------------
-;
-; Global variables
-;
-
-; We reuse the RS232 zero page variables for the driver, since the ROM
-; routines cannot be used together with this driver (may also use $A0F
-; and following in case of problems).
-RecvHead        := $A7          ; Head of receive buffer
-RecvTail        := $A8          ; Tail of receive buffer
-RecvFreeCnt     := $A9          ; Number of bytes in receive buffer
-SendHead        := $AA          ; Head of send buffer
-SendTail        := $AB          ; Tail of send buffer
-SendFreeCnt     := $B4          ; Number of bytes free in send buffer
-Stopped         := $B5          ; Flow-stopped flag
-RtsOff          := $B6          ;
-
-; Send and receive buffers: 256 bytes each
-RecvBuf         := $0C00        ; Use the ROM buffers
-SendBuf         := $0D00
-
-.rodata
-
-; Tables used to translate RS232 params into register values
-
-BaudTable:                      ; bit7 = 1 means setting is invalid
-        .byte   $FF             ; SER_BAUD_45_5
-        .byte   $FF             ; SER_BAUD_50
-        .byte   $FF             ; SER_BAUD_75
-        .byte   $FF             ; SER_BAUD_110
-        .byte   $FF             ; SER_BAUD_134_5
-        .byte   $02             ; SER_BAUD_150
-        .byte   $05             ; SER_BAUD_300
-        .byte   $06             ; SER_BAUD_600
-        .byte   $07             ; SER_BAUD_1200
-        .byte   $FF             ; SER_BAUD_1800
-        .byte   $08             ; SER_BAUD_2400
-        .byte   $09             ; SER_BAUD_3600
-        .byte   $0A             ; SER_BAUD_4800
-        .byte   $0B             ; SER_BAUD_7200
-        .byte   $0C             ; SER_BAUD_9600
-        .byte   $0E             ; SER_BAUD_19200
-        .byte   $0F             ; SER_BAUD_38400
-        .byte   $FF             ; SER_BAUD_57600
-        .byte   $FF             ; SER_BAUD_115200
-        .byte   $FF             ; SER_BAUD_230400
-
-BitTable:
-        .byte   $60             ; SER_BITS_5
-        .byte   $40             ; SER_BITS_6
-        .byte   $20             ; SER_BITS_7
-        .byte   $00             ; SER_BITS_8
-
-StopTable:
-        .byte   $00             ; SER_STOP_1
-        .byte   $80             ; SER_STOP_2
-
-ParityTable:
-        .byte   $00             ; SER_PAR_NONE
-        .byte   $20             ; SER_PAR_ODD
-        .byte   $60             ; SER_PAR_EVEN
-        .byte   $A0             ; SER_PAR_MARK
-        .byte   $E0             ; SER_PAR_SPACE
-
-.code
-
-;----------------------------------------------------------------------------
-; Interrupt stub that is copied into low RAM. The startup code uses a special
-; memory configuration with just kernal and I/O enabled (anything else is RAM).
-; The NMI handler in ROM will switch back to a configuration where just the
-; low 16K RAM are accessible. So we have to copy a smal piece of code into
-; low RAM that enables the cc65 configuration and then jumps to the real NMI
-; handler.
-
-NmiStubOrig     := *
-
-.org    $1150                           ; BASIC graphics area
-.proc   NmiStub
-
-	lda     #MMU_CFG_CC65		; Bank 0 with kernal ROM...
-	sta    	MMU_CR                  ; ...enable
-        jsr     NmiHandler              ; Call the actual NMI handler
-       	lda     #$00                    ; Get ROM config...
-	sta    	MMU_CR                  ; ...and enable it
-Vector  := *+1
-        .byte   $4C                     ; Jump to the saved IRQ vector
-
-.endproc
-.reloc
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an SER_ERR_xx code in a/x.
-
-INSTALL:
-
-; Deactivate DTR and disable 6551 interrupts
-
-      	lda     #%00001010
-       	sta    	ACIA_CMD
-
-; Copy the NMI stub into low memory
-
-        ldy     #.sizeof (NmiStub)-1
-@L1:    lda     NmiStubOrig,y
-        sta     NmiStub,y
-        dey
-        bpl     @L1
-
-; Set up the nmi vector
-
-   	lda   	NMIVec
-   	ldy   	NMIVec+1
-   	sta   	NmiStub::Vector+0
-   	sty   	NmiStub::Vector+1
-   	lda   	#NmiStub
-SetNMI: sta 	NMIVec
-   	sty 	NMIVec+1
-
-; Done, return an error code
-
-        lda     #SER_ERR_INIT_FAILED
-	rts
-
-; Baud rate not available
-
-InvBaud:
-        lda     #SER_ERR_BAUD_UNAVAIL
-        rts
-
-;----------------------------------------------------------------------------
-; CLOSE: Close the port, disable interrupts and flush the buffer. Called
-; without parameters. Must return an error code in a/x.
-;
-
-CLOSE:
-
-; Stop interrupts, drop DTR
-
-      	lda     #%00001010
-       	sta    	ACIA_CMD
-
-; Initalize buffers. Returns zero in a
-
-        jsr     InitBuffers
-
-; Return OK
-
-        lda     #SER_ERR_NO_DATA
-   	rts
-
-; Check for flow stopped & enough free: release flow control
-
-@L2:  	ldx 	Stopped                 ; (34)
-   	beq 	@L3
-   	cmp 	#63
-   	bcc 	@L3
-   	lda 	#$00
-   	sta 	Stopped
-   	lda 	RtsOff
-   	ora 	#%00001000
-   	sta	ACIA_CMD
-
-; Get byte from buffer
-
-@L3:  	ldx 	RecvHead                ; (41)
-       	lda 	RecvBuf,x
-      	inc 	RecvHead
-   	inc 	RecvFreeCnt
-       	ldx 	#$00                    ; (59)
-   	sta    	(ptr1,x)
-       	txa				; Return code = 0
-   	rts
-
-;----------------------------------------------------------------------------
-; PUT: Output character in A.
-; Must return an error code in a/x.
-;
-
-PUT:
-
-; Try to send
-
-        ldx 	SendFreeCnt
-       	inx                             ; X = $ff?
-   	beq 	@L2
-   	pha
-   	lda 	#$00
-   	jsr 	TryToSend
-   	pla
-
-; Put byte into send buffer & send
-
-@L2:  	ldx 	SendFreeCnt
-   	bne 	@L3
-   	lda 	#SER_ERR_INV_IOCTL
-        rts
-
-;----------------------------------------------------------------------------
-; IRQ: Not used on the C128
-;
-
-IRQ     = $0000
-
-;----------------------------------------------------------------------------
-;
-; NMI handler
-; C128 NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=33, ROMexit=30
-; C64  NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=34, ROMexit=29
-;
-; timing: normal=76+43+9=128 cycles, assertFlow=76+52+9=137 cycles
-;
-; C128 @ 115.2k: 177 cycles avail (fast)
-; C64  @  57.6k: 177 cycles avail, worstAvail=177-43? = 134
-; SCPU @ 230.4k: 868 cycles avail: for a joke!
-;
-; Note: Because of the C128 banking, a small stub has to go into low memory,
-; since the ROM NMI entry point switches to a configuration, where only the
-; low 16K of RAM are visible. The entry code switches into the standard cc65
-; configuration (I/O + 16K kernal) and then jumps here. Registers are already
-; saved by the ROM code.
-
-NmiHandler:
-       	lda    	ACIA_STATUS     ;(4) ;status ;check for byte received
-     	and 	#$08           	;(2)
-       	beq    	@L9  		;(2*)
-     	cld
-        lda 	ACIA_DATA       ;(4)  data  ;get byte and put into receive buffer
-    	ldy 	RecvTail 	;(4)
-    	ldx 	RecvFreeCnt  	;(4)
-       	beq    	@L9  		;(2*) Jump if no space in receive buffer
-    	sta 	RecvBuf,y 	;(5)
-    	inc 	RecvTail        ;(6)
-    	dec 	RecvFreeCnt     ;(6)
-    	cpx 	#33            	;(2)  check for buffer space low
-       	bcc    	@L2            	;(2*)
-       	rts
-
-; Assert flow control
-
-@L2:  	lda 	RtsOff       	;(3) assert flow control if buffer space too low
-    	sta 	ACIA_CMD	;(4) command
-    	sta 	Stopped      	;(3)
-@L9:    rts
-
-;----------------------------------------------------------------------------
-; Try to send a byte. Internal routine. A = TryHard
-
-.proc   TryToSend
-
-   	sta 	tmp1	       	; Remember tryHard flag
-@L0:   	lda 	SendFreeCnt
-    	cmp 	#$ff
-    	beq 	@L3	       	; Bail out
-
-; Check for flow stopped
-
-@L1:	lda 	Stopped
-       	bne    	@L3	       	; Bail out
-
-; Check that swiftlink is ready to send
-
-@L2:   	lda	ACIA_STATUS
-    	and 	#$10
-    	bne 	@L4
-    	bit 	tmp1	       	;keep trying if must try hard
-       	bmi 	@L0
-@L3:	rts
-
-; Send byte and try again
-
-@L4:  	ldx 	SendHead
-    	lda 	SendBuf,x
-    	sta	ACIA_DATA
-    	inc 	SendHead
-    	inc 	SendFreeCnt
-    	jmp 	@L0
-
-.endproc
-
-
-;----------------------------------------------------------------------------
-; Initialize buffers
-
-InitBuffers:
-        ldx 	#0
-        stx     Stopped
-       	stx 	RecvHead
-    	stx 	RecvTail
-      	stx 	SendHead
-    	stx 	SendTail
-        dex                             ; X = 255
-       	stx    	RecvFreeCnt
-      	stx 	SendFreeCnt
-        rts
-
-
diff --git a/libsrc/c128/c128-vdc.s b/libsrc/c128/c128-vdc.s
deleted file mode 100644
index d2b6b9d8b..000000000
--- a/libsrc/c128/c128-vdc.s
+++ /dev/null
@@ -1,381 +0,0 @@
-;
-; Extended memory driver for the VDC RAM available on all C128 machines
-; (based on code by Ullrich von Bassewitz)
-; Maciej 'YTM/Elysium' Witkowiak 
-; 06,20.12.2002
-
-	.include	"zeropage.inc"
-
-      	.include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   DEINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-	.word	USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-VDC_ADDR_REG	  = $D600		  ; VDC address
-VDC_DATA_REG	  = $D601		  ; VDC data
-
-VDC_DATA_HI	  = 18			  ; used registers
-VDC_DATA_LO	  = 19
-VDC_CSET	  = 28
-VDC_DATA	  = 31
-
-; ------------------------------------------------------------------------
-; Data.
-
-.data
-
-pagecount:      .word  64 		   ; $0000-$3fff as 16k default
-curpage:	.word  $ffff		   ; currently mapped-in page (invalid)
-
-.bss
-
-window:		.res	256		   ; memory window
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-	; do test for VDC presence here???
-
-	ldx	#VDC_CSET	; determine size of RAM...
-	jsr	vdcgetreg
-	sta	tmp1
-	ora	#%00010000
-	jsr	vdcputreg	; turn on 64k
-
-	jsr	settestadr1	; save original value of test byte
-	jsr	vdcgetbyte
-	sta	tmp2
-
-	lda	#$55		; write $55 here
-	ldy	#ptr1
-	jsr	test64k		; read it here and there
-	lda	#$aa		; write $aa here
-	ldy	#ptr2
-	jsr	test64k		; read it here and there
-
-	jsr	settestadr1
-	lda	tmp2
-	jsr	vdcputbyte	; restore original value of test byte
-
-	lda	ptr1		; do bytes match?
-	cmp	ptr1+1
-	bne	@have64k
-	lda	ptr2
-	cmp	ptr2+1
-	bne	@have64k
-
-	ldx	#VDC_CSET
-	lda	tmp1
-	jsr	vdcputreg	; restore 16/64k flag
-	jmp	@endok		; and leave default values for 16k
-
-@have64k:
-	lda	#<256
-	ldx	#>256
-	sta	pagecount
-	stx	pagecount+1
-@endok:
-	lda     #EM_ERR_OK
-        rts
-
-test64k:
-	sta	tmp1
-	sty	ptr3
-	lda	#0
-	sta	ptr3+1
-	jsr	settestadr1
-	lda	tmp1
-	jsr	vdcputbyte		; write $55
-	jsr	settestadr1
-	jsr	vdcgetbyte		; read here
-	pha
-	jsr	settestadr2
-	jsr	vdcgetbyte		; and there
-	ldy	#1
-	sta	(ptr3),y
-	pla
-	dey
-	sta	(ptr3),y
-	rts
-
-settestadr1:
-	ldy	#$02			; test page 2 (here)
-	.byte	$2c
-settestadr2:
-	ldy	#$42			; or page 64+2 (there)
-	lda	#0
-	jmp	vdcsetsrcaddr
-
-; ------------------------------------------------------------------------
-; DEINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-DEINSTALL:
-    	;on C128 restore font and clear the screen?
-        rts
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:	sta	curpage
-	stx	curpage+1
-	sta	ptr1+1
-	ldy	#0
-	sty	ptr1
-
-	lda	#window
-	sta	ptr2+1
-
-	jsr	transferin
-
-        lda     #window
-	rts
-
-; copy a single page from (ptr1):VDCRAM to (ptr2):RAM
-
-transferin:
-	lda	ptr1
-	ldy	ptr1+1
-	jsr	vdcsetsrcaddr		; set source address in VDC
-	ldy	#0
-	ldx	#VDC_DATA
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	lda	VDC_DATA_REG		; get 2 bytes at a time to speed-up
-	sta	(ptr2),y		; (in fact up to 8 bytes could be fetched with special VDC config)
-	iny
-	lda	VDC_DATA_REG
-	sta	(ptr2),y
-	iny
-	bne	@L0
-	rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta     curpage
-        stx     curpage+1               ; Remember the page
-        lda     #window                ; Return the window
-done:   rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT:
-	lda	curpage			; jump if no page mapped
-	ldx	curpage+1
-	bmi	done
-	sta	ptr1+1
-	ldy	#0
-	sty	ptr1
-
-	lda	#window
-	sta	ptr2+1
-
-; fall through to transferout
-
-; copy a single page from (ptr2):RAM to (ptr1):VDCRAM
-
-transferout:
-	lda	ptr1
-	ldy	ptr1+1
-	jsr	vdcsetsrcaddr		; set source address in VDC
-	ldy	#0
-	ldx	#VDC_DATA
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	lda	(ptr2),y		; speedup does not work for writing
-	sta	VDC_DATA_REG
-	iny
-	bne	@L0
-	rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-	jsr	setup
-	beq	@L2			; Skip if no full pages
-
-; Copy full pages
-
-@L1:    jsr     transferin
-        inc     ptr1+1
-        inc     ptr2+1
-        dec     tmp1
-        bne     @L1
-
-; Copy the remainder of the page
-
-@L2:    ldy     #EM_COPY::COUNT
-        lda     (ptr3),y                ; Get bytes in last page
-        beq     @L4
-        sta	tmp1
-
-; Transfer the bytes in the last page
-
-    	ldy	#0
-@L3:	jsr	vdcgetbyte
-	sta	(ptr2),y
-	iny
-	dec	tmp1
-	lda	tmp1
-	bne	@L3
-@L4:	rts
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-	jsr	setup
-	beq	@L2			; Skip if no full pages
-
-; Copy full pages
-
-@L1:    jsr     transferout
-        inc     ptr1+1
-        inc     ptr2+1
-        dec     tmp1
-        bne     @L1
-
-; Copy the remainder of the page
-
-@L2:    ldy     #EM_COPY::COUNT
-        lda     (ptr3),y                ; Get bytes in last page
-        beq     @L4
-        sta	tmp1
-
-; Transfer the bytes in the last page
-
-    	ldy	#0
-@L3:	lda	(ptr2),y
-	jsr	vdcputbyte
-	iny
-	dec	tmp1
-	lda	tmp1
-	bne	@L3
-@L4:	rts
-
-;-------------------------------------------------------------------------
-; Helper functions to handle VDC ram
-;
-
-vdcsetsrcaddr:
-	ldx	#VDC_DATA_LO
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	sta	VDC_DATA_REG
-	dex
-	tya
-	stx	VDC_ADDR_REG
-	sta	VDC_DATA_REG
-	rts
-
-vdcgetbyte:
-	ldx	#VDC_DATA
-vdcgetreg:
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	lda	VDC_DATA_REG
-	rts
-
-vdcputbyte:
-	ldx	#VDC_DATA
-vdcputreg:
-	stx	VDC_ADDR_REG
-@L0:	bit	VDC_ADDR_REG
-	bpl	@L0
-	sta	VDC_DATA_REG
-	rts
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-;
-
-setup:
-	sta     ptr3
-        stx     ptr3+1                  ; Save the passed em_copy pointer
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr3),y
-        sta     ptr1
-        ldy     #EM_COPY::PAGE
-        lda     (ptr3),y
-        sta     ptr1+1                  ; From
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr2
-        iny
-        lda     (ptr3),y
-        sta     ptr2+1                  ; To
-
-	ldy     #EM_COPY::COUNT+1
-        lda     (ptr3),y                ; Get number of pages
-        sta     tmp1
-	rts
-
diff --git a/libsrc/c128/emd/c128-georam.s b/libsrc/c128/emd/c128-georam.s
new file mode 100644
index 000000000..23c3469c5
--- /dev/null
+++ b/libsrc/c128/emd/c128-georam.s
@@ -0,0 +1,349 @@
+;
+; Extended memory driver for the GEORAM cartridge. Driver works without
+; problems when statically linked.
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+; GEORAM page size checking routine by
+; Marco van den Heuvel, 2010-01-21
+;
+
+	.include 	"zeropage.inc"
+
+      	.include 	"em-kernel.inc"
+        .include        "em-error.inc"
+
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $65, $6d, $64           ; "emd"
+        .byte   EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   UNINSTALL
+        .word   PAGECOUNT
+        .word   MAP
+        .word   USE
+        .word   COMMIT
+        .word   COPYFROM
+        .word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+GR_WINDOW       = $DE00                 ; Address of GEORAM window
+GR_PAGE_LO      = $DFFE                 ; Page register low
+GR_PAGE_HI      = $DFFF                 ; Page register high
+
+; ------------------------------------------------------------------------
+; Data.
+
+.data
+
+pagecount:      .res    2               ; Number of available pages
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+       	ldx     GR_WINDOW
+        cpx     GR_WINDOW
+        bne     @notpresent
+        inc     GR_WINDOW
+       	cpx     GR_WINDOW
+       	beq     @notpresent
+
+       	lda     #4
+       	jsr     check
+       	cpy     GR_WINDOW
+       	beq     @has64k
+       	lda     #8
+       	jsr     check
+       	cpy     GR_WINDOW
+       	beq     @has128k
+       	lda     #16
+       	jsr     check
+       	cpy     GR_WINDOW
+       	beq     @has256k
+       	lda     #32
+       	jsr     check
+       	cpy     GR_WINDOW
+       	beq     @has512k
+       	lda     #64
+       	jsr     check
+       	cpy     GR_WINDOW
+       	beq     @has1024k
+       	lda     #128
+       	jsr     check
+       	cpy     GR_WINDOW
+       	beq     @has2048k
+       	ldx     #>16384
+        bne     @setok
+
+@has64k:
+       	ldx     #>256
+       	bne     @setok
+@has128k:
+       	ldx     #>512
+       	bne     @setok
+@has256k:
+       	ldx     #>1024
+       	bne     @setok
+@has512k:
+       	ldx     #>2048
+       	bne     @setok
+@has1024k:
+       	ldx     #>4096
+       	bne     @setok
+@has2048k:
+       	ldx     #>8192
+       	bne     @setok
+
+@notpresent:
+       	lda     #EM_ERR_NO_DEVICE
+	rts
+
+@setok:
+       	lda     #0
+       	sta     pagecount
+       	stx     pagecount+1
+       	lda     #EM_ERR_OK
+	rts
+
+check:
+       	ldx     #0
+       	stx     GR_PAGE_LO
+       	stx     GR_PAGE_HI
+       	ldy     GR_WINDOW
+       	iny
+       	sta     GR_PAGE_HI
+       	sty     GR_WINDOW
+       	ldx     #0
+       	stx     GR_PAGE_HI
+;	rts                     ; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+        lda     pagecount
+        ldx     pagecount+1
+        rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+; The GeoRAM cartridge does not copy but actually map the window, so USE is
+; identical to MAP.
+
+USE     = MAP
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:    sta     tmp1
+        txa
+        asl     tmp1
+        rol     a
+        asl     tmp1
+        rol     a
+
+        sta     GR_PAGE_HI
+        lda     tmp1
+        lsr     a
+        lsr     a
+        sta     GR_PAGE_LO
+
+        lda     #GR_WINDOW
+
+; Use the RTS from COMMIT below to save a precious byte of storage
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: rts
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYFROM:
+        jsr     setup
+
+; Setup is:
+;
+;   - ptr1 contains the struct pointer
+;   - ptr2 contains the linear memory buffer
+;   - ptr3 contains -(count-1)
+;   - tmp1 contains the low page register value
+;   - tmp2 contains the high page register value
+;   - X contains the page offset
+;   - Y contains zero
+
+        jmp     @L5
+
+@L1:    lda     GR_WINDOW,x
+        sta     (ptr2),y
+        iny
+        bne     @L2
+        inc     ptr2+1
+@L2:    inx
+        beq     @L4
+
+; Bump count and repeat
+
+@L3:    inc     ptr3
+        bne     @L1
+        inc     ptr3+1
+        bne     @L1
+        rts
+
+; Bump page register
+
+@L4:    inc     tmp1            ; Bump low page register
+        bit     tmp1            ; Check for overflow in bit 6
+        bvc     @L6             ; Jump if no overflow
+        inc     tmp2
+@L5:    lda     tmp2
+        sta     GR_PAGE_HI
+@L6:    lda     tmp1
+        sta     GR_PAGE_LO
+        jmp     @L3
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO:
+        jsr     setup
+
+; Setup is:
+;
+;   - ptr1 contains the struct pointer
+;   - ptr2 contains the linear memory buffer
+;   - ptr3 contains -(count-1)
+;   - tmp1 contains the low page register value
+;   - tmp2 contains the high page register value
+;   - X contains the page offset
+;   - Y contains zero
+
+        jmp     @L5
+
+@L1:    lda     (ptr2),y
+        sta     GR_WINDOW,x
+        iny
+        bne     @L2
+        inc     ptr2+1
+@L2:    inx
+        beq     @L4
+
+; Bump count and repeat
+
+@L3:    inc     ptr3
+        bne     @L1
+        inc     ptr3+1
+        bne     @L1
+        rts
+
+; Bump page register
+
+@L4:    inc     tmp1            ; Bump low page register
+        bit     tmp1            ; Check for overflow in bit 6
+        bvc     @L6             ; Jump if no overflow
+        inc     tmp2
+@L5:    lda     tmp2
+        sta     GR_PAGE_HI
+@L6:    lda     tmp1
+        sta     GR_PAGE_LO
+        jmp     @L3
+
+; ------------------------------------------------------------------------
+; Helper function for COPYFROM and COPYTO: Store the pointer to the request
+; structure and prepare data for the copy
+
+setup:  sta     ptr1
+        stx     ptr1+1          ; Save passed pointer
+
+; Get the page number from the struct and adjust it so that it may be used
+; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
+
+        ldy     #EM_COPY::PAGE+1
+        lda     (ptr1),y
+        sta     tmp2
+        dey
+        lda     (ptr1),y
+        asl     a
+        rol     tmp2
+        asl     a
+        rol     tmp2
+        lsr     a
+        lsr     a
+        sta     tmp1
+
+; Get the buffer pointer into ptr2
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr1),y
+        sta     ptr2
+        iny
+        lda     (ptr1),y
+        sta     ptr2+1
+
+; Get the count, calculate -(count-1) and store it into ptr3
+
+        ldy     #EM_COPY::COUNT
+        lda     (ptr1),y
+        eor     #$FF
+        sta     ptr3
+        iny
+        lda     (ptr1),y
+        eor     #$FF
+        sta     ptr3+1
+
+; Get the page offset into X and clear Y
+
+        ldy     #EM_COPY::OFFS
+        lda     (ptr1),y
+        tax
+        ldy     #$00
+
+; Done
+
+        rts
+
+
diff --git a/libsrc/c128/emd/c128-ram.s b/libsrc/c128/emd/c128-ram.s
new file mode 100644
index 000000000..1211c444d
--- /dev/null
+++ b/libsrc/c128/emd/c128-ram.s
@@ -0,0 +1,288 @@
+;
+; Extended memory driver for the C128 RAM in bank #1. Driver works without
+; problems when statically linked.
+;
+; Ullrich von Bassewitz, 2002-12-04
+;
+
+	.include  	"zeropage.inc"
+
+      	.include  	"em-kernel.inc"
+        .include        "em-error.inc"
+        .include        "c128.inc"
+
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $65, $6d, $64           ; "emd"
+        .byte   EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   UNINSTALL
+        .word   PAGECOUNT
+        .word   MAP
+        .word   USE
+        .word   COMMIT
+	.word	COPYFROM
+        .word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+BASE	= $400
+TOPMEM  = $FF00
+PAGES  	= (TOPMEM - BASE) / 256
+
+; ------------------------------------------------------------------------
+; Data.
+
+.bss
+curpage:        .res    1               ; Current page number
+
+window:         .res    256             ; Memory "window"
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+        ldx     #$FF
+        stx     curpage
+        stx     curpage+1               ; Invalidate the current page
+        inx
+        txa                             ; A = X = EM_ERR_OK
+        rts
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+        lda     #PAGES
+        rts
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:    sta     curpage
+        stx     curpage+1               ; Remember the new page
+
+        clc
+        adc	#>BASE
+        sta	ptr1+1
+        ldy	#$00
+        sty    	ptr1
+
+        lda     #window                ; Return the window address
+        rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:    sta     curpage
+        stx     curpage+1               ; Remember the page
+        lda     #window                ; Return the window
+        rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: lda     curpage			; Get the current page
+        ldx     curpage+1
+        bmi     done                    ; Jump if no page mapped
+
+        clc
+        adc	#>BASE
+        sta	ptr1+1
+        ldy	#$00
+        sty    	ptr1
+
+        lda     #BASE
+        sta     ptr1+1                  ; From
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr3),y
+        sta     ptr2
+        iny
+        lda     (ptr3),y
+        sta     ptr2+1                  ; To
+
+        lda     #BASE
+        sta     ptr1+1                  ; To
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr3),y
+        sta     ptr2
+        iny
+        lda     (ptr3),y
+        sta     ptr2+1                  ; From
+
+        lda     #BASE
+        sta     ptr1+1
+        ldy     #$00
+        sty     ptr1
+        lda     #window                ; Return the window address
+        cli
+        rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:    sta     curpage
+        stx     curpage+1               ; Remember the page
+        lda     #window                ; Return the window
+        rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: sei
+        lda     curpage			; Get the current page
+        ldx     curpage+1
+        bmi     done                    ; Jump if no page mapped
+
+        jsr     calculate_bank_and_correct_page
+        stx     curbank
+
+        clc
+        adc	#>BASE
+        sta	ptr1+1
+        ldy	#$00
+        sty     ptr1
+
+        lda     #
+; 06,22.12.2002
+;
+
+
+	.include	"zeropage.inc"
+
+      	.include	"em-kernel.inc"
+        .include	"em-error.inc"
+
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $65, $6d, $64           ; "emd"
+        .byte   EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   UNINSTALL
+        .word   PAGECOUNT
+        .word   MAP
+	.word	USE
+        .word   COMMIT
+	.word	COPYFROM
+        .word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+RAMC_WINDOW       = $DF00               ; Address of RamCart window
+RAMC_PAGE_LO      = $DE00               ; Page register low
+RAMC_PAGE_HI      = $DE01               ; Page register high (only for RC128)
+
+; ------------------------------------------------------------------------
+; Data.
+
+.bss
+
+pagecount:      .res    2               ; Number of pages available
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+	ldx	RAMC_WINDOW
+	cpx	RAMC_WINDOW
+	bne	@notpresent
+
+	lda	#0
+	sta	RAMC_PAGE_LO
+	sta	RAMC_PAGE_HI
+	ldx	RAMC_WINDOW
+	cpx	RAMC_WINDOW
+	bne	@notpresent
+	lda	#2
+	sta	RAMC_WINDOW
+	cmp	RAMC_WINDOW
+	beq	@cont
+	cpx	RAMC_WINDOW
+	beq	@readonly
+@cont:	ldy	#1
+	sty	RAMC_PAGE_HI
+	sty	RAMC_WINDOW
+	dey
+	sty	RAMC_PAGE_HI
+	iny
+	cpy	RAMC_WINDOW
+	beq	@rc64
+	; we're on rc128
+	ldx	#>512
+	bne	@setsize
+@rc64:	ldx	#>256
+@setsize:
+	lda	#0
+	sta	pagecount
+	stx	pagecount+1
+        lda     #EM_ERR_OK
+        rts
+@notpresent:
+@readonly:
+	lda	#EM_ERR_NO_DEVICE
+;	rts                             ; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+        lda     pagecount
+        ldx     pagecount+1
+        rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+; The RamCart cartridge does not copy but actually map the window, so USE is
+; identical to MAP.
+
+USE     = MAP
+
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:    sta	RAMC_PAGE_LO
+	stx	RAMC_PAGE_HI
+        lda     #RAMC_WINDOW
+
+; Use the RTS from COMMIT below to save a precious byte of storage
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: rts
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYFROM:
+        jsr     setup
+
+; Setup is:
+;
+;   - ptr1 contains the struct pointer
+;   - ptr2 contains the linear memory buffer
+;   - ptr3 contains -(count-1)
+;   - tmp1 contains the low page register value
+;   - tmp2 contains the high page register value
+;   - X contains the page offset
+;   - Y contains zero
+
+        jmp     @L5
+
+@L1:    lda     RAMC_WINDOW,x
+        sta     (ptr2),y
+        iny
+        bne     @L2
+        inc     ptr2+1
+@L2:    inx
+        beq     @L4
+
+; Bump count and repeat
+
+@L3:    inc     ptr3
+        bne     @L1
+        inc     ptr3+1
+        bne     @L1
+        rts
+
+; Bump page register
+
+@L4:  	inc	tmp1
+	bne	@L5
+	inc	tmp2
+@L5:	lda	tmp1
+	sta	RAMC_PAGE_LO
+	lda	tmp2
+	sta	RAMC_PAGE_HI
+	jmp	@L3
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO:
+        jsr     setup
+
+; Setup is:
+;
+;   - ptr1 contains the struct pointer
+;   - ptr2 contains the linear memory buffer
+;   - ptr3 contains -(count-1)
+;   - tmp1 contains the low page register value
+;   - tmp2 contains the high page register value
+;   - X contains the page offset
+;   - Y contains zero
+
+        jmp     @L5
+
+@L1:    lda     (ptr2),y
+        sta     RAMC_WINDOW,x
+        iny
+        bne     @L2
+        inc     ptr2+1
+@L2:    inx
+        beq     @L4
+
+; Bump count and repeat
+
+@L3:    inc     ptr3
+        bne     @L1
+        inc     ptr3+1
+        bne     @L1
+        rts
+
+; Bump page register
+
+@L4:  	inc	tmp1
+	bne	@L5
+	inc	tmp2
+@L5:	lda	tmp1
+	sta	RAMC_PAGE_LO
+	lda	tmp2
+	sta	RAMC_PAGE_HI
+	jmp	@L3
+
+; ------------------------------------------------------------------------
+; Helper function for COPYFROM and COPYTO: Store the pointer to the request
+; structure and prepare data for the copy
+
+setup:  sta     ptr1
+        stx     ptr1+1          ; Save passed pointer
+
+; Get the page number from the struct and adjust it so that it may be used
+; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
+
+        ldy     #EM_COPY::PAGE+1
+        lda     (ptr1),y
+        sta     tmp2
+        dey
+        lda     (ptr1),y
+        sta     tmp1
+
+; Get the buffer pointer into ptr2
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr1),y
+        sta     ptr2
+        iny
+        lda     (ptr1),y
+        sta     ptr2+1
+
+; Get the count, calculate -(count-1) and store it into ptr3
+
+        ldy     #EM_COPY::COUNT
+        lda     (ptr1),y
+        eor     #$FF
+        sta     ptr3
+        iny
+        lda     (ptr1),y
+        eor     #$FF
+        sta     ptr3+1
+
+; Get the page offset into X and clear Y
+
+        ldy     #EM_COPY::OFFS
+        lda     (ptr1),y
+        tax
+        ldy     #$00
+
+; Done
+
+        rts
+
diff --git a/libsrc/c128/emd/c128-reu.s b/libsrc/c128/emd/c128-reu.s
new file mode 100644
index 000000000..4f86f6aee
--- /dev/null
+++ b/libsrc/c128/emd/c128-reu.s
@@ -0,0 +1,236 @@
+;
+; Extended memory driver for the Commodore REU. Driver works without
+; problems when statically linked.
+;
+; Ullrich von Bassewitz, 2002-11-29
+;
+
+	.include 	"zeropage.inc"
+
+      	.include 	"em-kernel.inc"
+        .include        "em-error.inc"
+	.include	"c128.inc"
+
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $65, $6d, $64           ; "emd"
+        .byte   EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   UNINSTALL
+        .word   PAGECOUNT
+        .word   MAP
+        .word   USE
+        .word   COMMIT
+	.word	COPYFROM
+        .word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+REU_STATUS      = $DF00                 ; Status register
+REU_COMMAND     = $DF01                 ; Command register
+REU_C64ADDR     = $DF02                 ; C64 base address register
+REU_REUADDR     = $DF04                 ; REU base address register
+REU_COUNT       = $DF07                 ; Transfer count register
+REU_IRQMASK     = $DF09                 ; IRQ mask register
+REU_CONTROL     = $DF0A                 ; Control register
+REU_TRIGGER     = $FF00                 ; REU command trigger
+
+OP_COPYFROM     = $ED
+OP_COPYTO       = $EC
+
+
+; ------------------------------------------------------------------------
+; Data.
+
+.bss
+pagecount:      .res    2               ; Number of pages available
+curpage:        .res    2               ; Current page number
+
+window:         .res    256             ; Memory "window"
+
+reu_params:     .word 	$0000  		; Host address, lo, hi
+		.word 	$0000		; Exp  address, lo, hi
+                .byte	$00		; Expansion  bank no.
+       	       	.word  	$0000  		; # bytes to move, lo, hi
+       		.byte 	$00    		; Interrupt mask reg.
+       		.byte 	$00    		; Adress control reg.
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+        ldx     #$00                    ; High byte of return code
+        lda     #$55
+        sta     REU_REUADDR
+        cmp     REU_REUADDR             ; Check for presence of REU
+        bne     nodevice
+        asl     a                       ; A = $AA
+        sta     REU_REUADDR
+        cmp     REU_REUADDR             ; Check for presence of REU
+        bne     nodevice
+
+        ldy     #>(128*4)               ; Assume 128KB
+        lda     REU_STATUS
+        and     #$10                    ; Check size bit
+        beq     @L1
+        ldy     #>(256*4)               ; 256KB when size bit is set
+@L1:    sty     pagecount+1
+
+        ldy     #$FF
+        sty     curpage
+        sty     curpage+1               ; Invalidate the current page
+        txa                             ; X = A = EM_ERR_OK
+        rts
+
+; No REU found
+
+nodevice:
+        lda     #EM_ERR_NO_DEVICE
+;       rts                             ; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+        lda     pagecount
+        ldx     pagecount+1
+        rts
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:    sta     curpage
+        stx     curpage+1               ; Remember the new page
+
+        ldy     #OP_COPYFROM
+        jsr     common                  ; Copy the window
+
+        lda     #window                ; Return the window address
+done:   rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:    sta     curpage
+        stx     curpage+1               ; Remember the page
+        lda     #window                ; Return the window
+        rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: lda     curpage
+        ldx     curpage+1               ; Do we have a page mapped?
+        bmi     done                    ; Jump if no page mapped
+
+        ldy     #OP_COPYTO
+common: sty     tmp1
+
+        ldy     #window
+        sty     REU_C64ADDR+1
+
+        ldy     #0
+        sty     REU_REUADDR+0
+        sta     REU_REUADDR+1
+        stx     REU_REUADDR+2
+
+        sty     REU_COUNT+0
+        ldy     #1
+        sty     REU_COUNT+1             ; Move 256 bytes
+        bne     transfer1               ; Transfer 256 bytes into REU
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYFROM:
+        ldy     #OP_COPYFROM
+        .byte   $2C
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO:
+        ldy     #OP_COPYTO
+        sty     tmp1
+
+; Remember the passed pointer
+
+        sta     ptr1
+        stx     ptr1+1          ; Save the pointer
+
+; The structure passed to the functions has the same layout as the registers
+; of the Commodore REU, so register programming is easy.
+
+        ldy     #7-1
+@L1:    lda     (ptr1),y
+        sta     REU_C64ADDR,y
+        dey
+        bpl     @L1
+
+; Invalidate the page in the memory window
+
+        sty     curpage+1       ; Y = $FF
+
+; Reload the REU command and start the transfer
+
+transfer1:
+        ldy     tmp1
+
+; Transfer subroutine for the REU. Expects command in Y.
+
+transfer:
+        sty    	REU_COMMAND     ; Issue command
+
+        ldy    	MMU_CR		; Save the current MMU settings
+	lda	#MMU_CFG_RAM0  	;
+  	sei          	  	;
+        sta	MMU_CR		; Enable RAM in bank #0
+        lda     REU_TRIGGER     ; Don't change $FF00
+        sta 	REU_TRIGGER     ; Start the transfer...
+
+        sty     MMU_CR          ; Restore the old configuration
+        cli
+        rts
+
diff --git a/libsrc/c128/emd/c128-vdc.s b/libsrc/c128/emd/c128-vdc.s
new file mode 100644
index 000000000..d2b6b9d8b
--- /dev/null
+++ b/libsrc/c128/emd/c128-vdc.s
@@ -0,0 +1,381 @@
+;
+; Extended memory driver for the VDC RAM available on all C128 machines
+; (based on code by Ullrich von Bassewitz)
+; Maciej 'YTM/Elysium' Witkowiak 
+; 06,20.12.2002
+
+	.include	"zeropage.inc"
+
+      	.include	"em-kernel.inc"
+        .include	"em-error.inc"
+
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $65, $6d, $64           ; "emd"
+        .byte   EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   DEINSTALL
+        .word   PAGECOUNT
+        .word   MAP
+	.word	USE
+        .word   COMMIT
+	.word	COPYFROM
+        .word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+VDC_ADDR_REG	  = $D600		  ; VDC address
+VDC_DATA_REG	  = $D601		  ; VDC data
+
+VDC_DATA_HI	  = 18			  ; used registers
+VDC_DATA_LO	  = 19
+VDC_CSET	  = 28
+VDC_DATA	  = 31
+
+; ------------------------------------------------------------------------
+; Data.
+
+.data
+
+pagecount:      .word  64 		   ; $0000-$3fff as 16k default
+curpage:	.word  $ffff		   ; currently mapped-in page (invalid)
+
+.bss
+
+window:		.res	256		   ; memory window
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+	; do test for VDC presence here???
+
+	ldx	#VDC_CSET	; determine size of RAM...
+	jsr	vdcgetreg
+	sta	tmp1
+	ora	#%00010000
+	jsr	vdcputreg	; turn on 64k
+
+	jsr	settestadr1	; save original value of test byte
+	jsr	vdcgetbyte
+	sta	tmp2
+
+	lda	#$55		; write $55 here
+	ldy	#ptr1
+	jsr	test64k		; read it here and there
+	lda	#$aa		; write $aa here
+	ldy	#ptr2
+	jsr	test64k		; read it here and there
+
+	jsr	settestadr1
+	lda	tmp2
+	jsr	vdcputbyte	; restore original value of test byte
+
+	lda	ptr1		; do bytes match?
+	cmp	ptr1+1
+	bne	@have64k
+	lda	ptr2
+	cmp	ptr2+1
+	bne	@have64k
+
+	ldx	#VDC_CSET
+	lda	tmp1
+	jsr	vdcputreg	; restore 16/64k flag
+	jmp	@endok		; and leave default values for 16k
+
+@have64k:
+	lda	#<256
+	ldx	#>256
+	sta	pagecount
+	stx	pagecount+1
+@endok:
+	lda     #EM_ERR_OK
+        rts
+
+test64k:
+	sta	tmp1
+	sty	ptr3
+	lda	#0
+	sta	ptr3+1
+	jsr	settestadr1
+	lda	tmp1
+	jsr	vdcputbyte		; write $55
+	jsr	settestadr1
+	jsr	vdcgetbyte		; read here
+	pha
+	jsr	settestadr2
+	jsr	vdcgetbyte		; and there
+	ldy	#1
+	sta	(ptr3),y
+	pla
+	dey
+	sta	(ptr3),y
+	rts
+
+settestadr1:
+	ldy	#$02			; test page 2 (here)
+	.byte	$2c
+settestadr2:
+	ldy	#$42			; or page 64+2 (there)
+	lda	#0
+	jmp	vdcsetsrcaddr
+
+; ------------------------------------------------------------------------
+; DEINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+DEINSTALL:
+    	;on C128 restore font and clear the screen?
+        rts
+
+; ------------------------------------------------------------------------
+; PAGECOUNT: Return the total number of available pages in a/x.
+;
+
+PAGECOUNT:
+        lda     pagecount
+        ldx     pagecount+1
+        rts
+
+; ------------------------------------------------------------------------
+; MAP: Map the page in a/x into memory and return a pointer to the page in
+; a/x. The contents of the currently mapped page (if any) may be discarded
+; by the driver.
+;
+
+MAP:	sta	curpage
+	stx	curpage+1
+	sta	ptr1+1
+	ldy	#0
+	sty	ptr1
+
+	lda	#window
+	sta	ptr2+1
+
+	jsr	transferin
+
+        lda     #window
+	rts
+
+; copy a single page from (ptr1):VDCRAM to (ptr2):RAM
+
+transferin:
+	lda	ptr1
+	ldy	ptr1+1
+	jsr	vdcsetsrcaddr		; set source address in VDC
+	ldy	#0
+	ldx	#VDC_DATA
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	lda	VDC_DATA_REG		; get 2 bytes at a time to speed-up
+	sta	(ptr2),y		; (in fact up to 8 bytes could be fetched with special VDC config)
+	iny
+	lda	VDC_DATA_REG
+	sta	(ptr2),y
+	iny
+	bne	@L0
+	rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:    sta     curpage
+        stx     curpage+1               ; Remember the page
+        lda     #window                ; Return the window
+done:   rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT:
+	lda	curpage			; jump if no page mapped
+	ldx	curpage+1
+	bmi	done
+	sta	ptr1+1
+	ldy	#0
+	sty	ptr1
+
+	lda	#window
+	sta	ptr2+1
+
+; fall through to transferout
+
+; copy a single page from (ptr2):RAM to (ptr1):VDCRAM
+
+transferout:
+	lda	ptr1
+	ldy	ptr1+1
+	jsr	vdcsetsrcaddr		; set source address in VDC
+	ldy	#0
+	ldx	#VDC_DATA
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	lda	(ptr2),y		; speedup does not work for writing
+	sta	VDC_DATA_REG
+	iny
+	bne	@L0
+	rts
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYFROM:
+	jsr	setup
+	beq	@L2			; Skip if no full pages
+
+; Copy full pages
+
+@L1:    jsr     transferin
+        inc     ptr1+1
+        inc     ptr2+1
+        dec     tmp1
+        bne     @L1
+
+; Copy the remainder of the page
+
+@L2:    ldy     #EM_COPY::COUNT
+        lda     (ptr3),y                ; Get bytes in last page
+        beq     @L4
+        sta	tmp1
+
+; Transfer the bytes in the last page
+
+    	ldy	#0
+@L3:	jsr	vdcgetbyte
+	sta	(ptr2),y
+	iny
+	dec	tmp1
+	lda	tmp1
+	bne	@L3
+@L4:	rts
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO:
+	jsr	setup
+	beq	@L2			; Skip if no full pages
+
+; Copy full pages
+
+@L1:    jsr     transferout
+        inc     ptr1+1
+        inc     ptr2+1
+        dec     tmp1
+        bne     @L1
+
+; Copy the remainder of the page
+
+@L2:    ldy     #EM_COPY::COUNT
+        lda     (ptr3),y                ; Get bytes in last page
+        beq     @L4
+        sta	tmp1
+
+; Transfer the bytes in the last page
+
+    	ldy	#0
+@L3:	lda	(ptr2),y
+	jsr	vdcputbyte
+	iny
+	dec	tmp1
+	lda	tmp1
+	bne	@L3
+@L4:	rts
+
+;-------------------------------------------------------------------------
+; Helper functions to handle VDC ram
+;
+
+vdcsetsrcaddr:
+	ldx	#VDC_DATA_LO
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	sta	VDC_DATA_REG
+	dex
+	tya
+	stx	VDC_ADDR_REG
+	sta	VDC_DATA_REG
+	rts
+
+vdcgetbyte:
+	ldx	#VDC_DATA
+vdcgetreg:
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	lda	VDC_DATA_REG
+	rts
+
+vdcputbyte:
+	ldx	#VDC_DATA
+vdcputreg:
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	sta	VDC_DATA_REG
+	rts
+
+; ------------------------------------------------------------------------
+; Helper function for COPYFROM and COPYTO: Store the pointer to the request
+; structure and prepare data for the copy
+;
+
+setup:
+	sta     ptr3
+        stx     ptr3+1                  ; Save the passed em_copy pointer
+
+        ldy     #EM_COPY::OFFS
+        lda     (ptr3),y
+        sta     ptr1
+        ldy     #EM_COPY::PAGE
+        lda     (ptr3),y
+        sta     ptr1+1                  ; From
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr3),y
+        sta     ptr2
+        iny
+        lda     (ptr3),y
+        sta     ptr2+1                  ; To
+
+	ldy     #EM_COPY::COUNT+1
+        lda     (ptr3),y                ; Get number of pages
+        sta     tmp1
+	rts
+
diff --git a/libsrc/c128/joy/c128-ptvjoy.s b/libsrc/c128/joy/c128-ptvjoy.s
new file mode 100644
index 000000000..e101997f1
--- /dev/null
+++ b/libsrc/c128/joy/c128-ptvjoy.s
@@ -0,0 +1,152 @@
+;
+; PTV-4 Player joystick driver for the C128
+;
+; Ullrich von Bassewitz, 2003-09-28, using the C64 driver from
+; Groepaz/Hitmen, 2002-12-23, which is
+; obviously based on Ullrichs driver :)
+;
+
+        .include "zeropage.inc"
+
+        .include "joy-kernel.inc"
+        .include "joy-error.inc"
+        .include "c128.inc"
+
+        .macpack generic
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+        .segment "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $6A, $6F, $79           ; "joy"
+        .byte   JOY_API_VERSION         ; Driver API version number
+
+; Button state masks (8 values)
+
+        .byte   $01                     ; JOY_UP
+        .byte   $02                     ; JOY_DOWN
+        .byte   $04                     ; JOY_LEFT
+        .byte   $08                     ; JOY_RIGHT
+        .byte   $10                     ; JOY_FIRE
+        .byte   $00                     ; JOY_FIRE2 unavailable
+        .byte   $00                     ; Future expansion
+        .byte   $00                     ; Future expansion
+
+; Jump table.
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   COUNT
+        .addr   READ
+        .addr   0                       ; IRQ entry unused
+
+; ------------------------------------------------------------------------
+; Constants
+
+JOY_COUNT       = 4             ; Number of joysticks we support
+
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an JOY_ERR_xx code in a/x.
+;
+
+INSTALL:
+        lda     #JOY_ERR_OK
+;	rts                     ; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; COUNT: Return the total number of available joysticks in a/x.
+;
+
+COUNT:
+        lda     #JOY_COUNT
+        rts
+
+; ------------------------------------------------------------------------
+; READ: Read a particular joystick passed in A.
+;
+
+READ:   tax	                ; Joystick number into X
+        bne     joy2
+
+; Read joystick 1
+
+joy1:   lda	#$7F
+        sei
+        sta	CIA1_PRA
+        lda	CIA1_PRB
+        cli
+        and	#$1F
+        eor	#$1F
+        rts
+
+; Read joystick 2
+
+joy2:   dex
+        bne     joy3
+
+        lda 	#$E0
+        ldy 	#$FF
+        sei
+        sta 	CIA1_DDRA
+        lda 	CIA1_PRA
+        sty 	CIA1_DDRA
+        cli
+        and 	#$1F
+        eor 	#$1F
+        rts
+
+; Read joystick 3
+
+joy3:
+        lda     #%10000000      ; cia 2 port B Data-Direction
+        sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
+
+        dex
+        bne     joy4
+
+        lda     #$80            ; cia 2 port B read/write
+        sta     CIA2_PRB        ; (output one at PB7)
+
+        lda     CIA2_PRB        ; cia 2 port B read/write
+        and     #$1f            ; get bit 4-0 (PB4-PB0)
+        eor     #$1f
+        rts
+
+; Read joystick 4
+
+joy4:
+        lda     #$00            ; cia 2 port B read/write
+        sta     CIA2_PRB        ; (output zero at PB7)
+
+        lda     CIA2_PRB        ; cia 2 port B read/write
+        and     #$0f            ; get bit 3-0 (PB3-PB0)
+        sta     tmp1            ; joy 4 directions
+
+        lda     CIA2_PRB        ; cia 2 port B read/write
+        and     #%00100000      ; get bit 5 (PB5)
+        lsr
+        ora     tmp1
+        eor     #$1f
+
+        ldx #0
+        rts
diff --git a/libsrc/c128/joy/c128-stdjoy.s b/libsrc/c128/joy/c128-stdjoy.s
new file mode 100644
index 000000000..241e223e7
--- /dev/null
+++ b/libsrc/c128/joy/c128-stdjoy.s
@@ -0,0 +1,121 @@
+;
+; Standard joystick driver for the C128. May be used multiple times when linked
+; to the statically application.
+
+;
+; Ullrich von Bassewitz, 2002-12-21
+;
+
+	.include 	"zeropage.inc"
+
+      	.include 	"joy-kernel.inc"
+        .include        "joy-error.inc"
+        .include        "c128.inc"
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $6A, $6F, $79		; "joy"
+        .byte   JOY_API_VERSION		; Driver API version number
+
+; Button state masks (8 values)
+
+        .byte   $01                     ; JOY_UP
+        .byte   $02                     ; JOY_DOWN
+        .byte   $04                     ; JOY_LEFT
+        .byte   $08                     ; JOY_RIGHT
+        .byte   $10                     ; JOY_FIRE
+        .byte   $00                     ; JOY_FIRE2 unavailable
+        .byte   $00                     ; Future expansion
+        .byte   $00                     ; Future expansion
+
+; Jump table.
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   COUNT
+        .addr   READ
+        .addr   0                       ; IRQ entry not used
+
+; ------------------------------------------------------------------------
+; Constants
+
+JOY_COUNT       = 2             ; Number of joysticks we support
+
+
+; ------------------------------------------------------------------------
+; Data.
+
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an JOY_ERR_xx code in a/x.
+;
+
+INSTALL:
+        lda     #JOY_ERR_OK
+;	rts                     ; Run into UNINSTALL instead
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; Can do cleanup or whatever. Must not return anything.
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; COUNT: Return the total number of available joysticks in a/x.
+;
+
+COUNT:
+        lda     #JOY_COUNT
+        rts
+
+; ------------------------------------------------------------------------
+; READ: Read a particular joystick passed in A.
+;
+
+READ:   tax			; Joystick number into X
+	bne    	joy2
+
+; Read joystick 1
+
+joy1:	lda	#$7F
+     	sei
+     	sta	CIA1_PRA
+     	lda	CIA1_PRB
+     	cli
+     	and	#$1F
+     	eor	#$1F
+     	rts
+
+; Read joystick 2
+
+joy2:	ldx	#0
+	lda	#$E0
+	ldy	#$FF
+	sei
+	sta	CIA1_DDRA
+	lda	CIA1_PRA
+	sty	CIA1_DDRA
+	cli
+	and	#$1F
+	eor	#$1F
+	rts
+
+
diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s
new file mode 100644
index 000000000..999c57090
--- /dev/null
+++ b/libsrc/c128/mou/c128-1351.s
@@ -0,0 +1,428 @@
+;
+; Driver for the 1351 proportional mouse. Parts of the code are from
+; the Commodore 1351 mouse users guide.
+;
+; Ullrich von Bassewitz, 2003-12-29, 2009-09-26
+;
+
+        .include        "zeropage.inc"
+        .include        "mouse-kernel.inc"
+	.include	"c128.inc"
+
+        .macpack        generic
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+HEADER:
+
+; Driver signature
+
+        .byte   $6d, $6f, $75           ; "mou"
+        .byte   MOUSE_API_VERSION       ; Mouse driver API version number
+
+; Jump table.
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   HIDE
+        .addr   SHOW
+        .addr   SETBOX
+        .addr   GETBOX
+        .addr   MOVE
+        .addr   BUTTONS
+        .addr   POS
+        .addr   INFO
+        .addr   IOCTL
+        .addr   IRQ
+
+; Mouse driver flags
+
+        .byte   MOUSE_FLAG_LATE_IRQ
+
+; Callback table, set by the kernel before INSTALL is called
+
+CHIDE:  jmp     $0000                   ; Hide the cursor
+CSHOW:  jmp     $0000                   ; Show the cursor
+CMOVEX: jmp     $0000                   ; Move the cursor to X coord
+CMOVEY: jmp     $0000                   ; Move the cursor to Y coord
+
+
+;----------------------------------------------------------------------------
+; Constants
+
+SCREEN_HEIGHT   = 200
+SCREEN_WIDTH    = 320
+
+;----------------------------------------------------------------------------
+; Global variables. The bounding box values are sorted so that they can be
+; written with the least effort in the SETBOX and GETBOX routines, so don't
+; reorder them.
+
+.bss
+
+Vars:
+OldPotX:   	.res   	1	     	; Old hw counter values
+OldPotY:	.res   	1
+
+YPos:           .res    2               ; Current mouse position, Y
+XPos:           .res    2               ; Current mouse position, X
+XMin:		.res	2	     	; X1 value of bounding box
+YMin:		.res	2	     	; Y1 value of bounding box
+XMax:		.res	2	     	; X2 value of bounding box
+YMax:		.res	2	     	; Y2 value of bounding box
+
+OldValue:	.res   	1	     	; Temp for MoveCheck routine
+NewValue:	.res   	1	     	; Temp for MoveCheck routine
+
+; Default values for above variables
+
+.rodata
+
+.proc   DefVars
+        .byte   0, 0                    ; OldPotX/OldPotY
+        .word   SCREEN_HEIGHT/2         ; YPos
+        .word   SCREEN_WIDTH/2          ; XPos
+        .word   0                       ; XMin
+        .word   0                       ; YMin
+        .word   SCREEN_WIDTH            ; XMax
+        .word   SCREEN_HEIGHT           ; YMax
+.endproc
+
+.code
+
+;----------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present.
+; Must return an MOUSE_ERR_xx code in a/x.
+
+INSTALL:
+
+; Initialize variables. Just copy the default stuff over
+
+        ldx     #.sizeof(DefVars)-1
+@L1:    lda     DefVars,x
+        sta     Vars,x
+        dex
+        bpl     @L1
+
+; Be sure the mouse cursor is invisible and at the default location. We
+; need to do that here, because our mouse interrupt handler doesn't set the
+; mouse position if it hasn't changed.
+
+        sei
+        jsr     CHIDE
+        lda     XPos
+        ldx     XPos+1
+        jsr     CMOVEX
+        lda     YPos
+        ldx     YPos+1
+        jsr     CMOVEY
+        cli
+
+; Done, return zero (= MOUSE_ERR_OK)
+
+        ldx     #$00
+        txa
+        rts                             ; Run into UNINSTALL instead
+
+;----------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; No return code required (the driver is removed from memory on return).
+
+UNINSTALL       = HIDE                  ; Hide cursor on exit
+
+;----------------------------------------------------------------------------
+; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
+; a counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently visible and should get hidden. For most drivers,
+; no special action is required besides hiding the mouse cursor.
+; No return code required.
+
+HIDE:   sei
+        jsr     CHIDE
+        cli
+        rts
+
+;----------------------------------------------------------------------------
+; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
+; a counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently hidden and should become visible. For most drivers,
+; no special action is required besides enabling the mouse cursor.
+; No return code required.
+
+SHOW:   sei
+        jsr     CSHOW
+        cli
+        rts
+
+;----------------------------------------------------------------------------
+; SETBOX: Set the mouse bounding box. The parameters are passed as they come
+; from the C program, that is, a pointer to a mouse_box struct in a/x.
+; No checks are done if the mouse is currently inside the box, this is the job
+; of the caller. It is not necessary to validate the parameters, trust the
+; caller and save some code here. No return code required.
+
+SETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     (ptr1),y
+        sta     XMin,y
+        dey
+        bpl     @L1
+
+        cli
+       	rts
+
+;----------------------------------------------------------------------------
+; GETBOX: Return the mouse bounding box. The parameters are passed as they
+; come from the C program, that is, a pointer to a mouse_box struct in a/x.
+
+GETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     XMin,y
+        sta     (ptr1),y
+        dey
+        bpl     @L1
+
+        cli
+       	rts
+
+;----------------------------------------------------------------------------
+; MOVE: Move the mouse to a new position. The position is passed as it comes
+; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
+; remove the parameter from the stack on return.
+; No checks are done if the new position is valid (within the bounding box or
+; the screen). No return code required.
+;
+
+MOVE:   sei                             ; No interrupts
+
+        sta     YPos
+        stx     YPos+1                  ; New Y position
+        jsr     CMOVEY                  ; Set it
+
+        ldy     #$01
+        lda     (sp),y
+        sta     XPos+1
+        tax
+        dey
+        lda     (sp),y
+        sta     XPos                    ; New X position
+
+        jsr     CMOVEX			; Move the cursor
+
+	cli                             ; Allow interrupts
+       	rts
+
+;----------------------------------------------------------------------------
+; BUTTONS: Return the button mask in a/x.
+
+BUTTONS:
+        lda	#$7F
+     	sei
+     	sta	CIA1_PRA
+     	lda	CIA1_PRB                ; Read joystick #0
+     	cli
+        ldx     #0
+     	and	#$1F
+     	eor	#$1F
+        rts
+
+;----------------------------------------------------------------------------
+; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
+; No return code required.
+
+POS:    ldy    	#MOUSE_POS::XCOORD      ; Structure offset
+
+	sei	    			; Disable interrupts
+	lda     XPos			; Transfer the position
+	sta	(ptr1),y
+	lda	XPos+1
+	iny
+	sta	(ptr1),y
+      	lda	YPos
+        iny
+        sta     (ptr1),y
+	lda	YPos+1
+	cli	    			; Enable interrupts
+
+        iny
+        sta     (ptr1),y                ; Store last byte
+
+    	rts	    			; Done
+
+;----------------------------------------------------------------------------
+; INFO: Returns mouse position and current button mask in the MOUSE_INFO
+; struct pointed to by ptr1. No return code required.
+;
+; We're cheating here to keep the code smaller: The first fields of the
+; mouse_info struct are identical to the mouse_pos struct, so we will just
+; call _mouse_pos to initialize the struct pointer and fill the position
+; fields.
+
+INFO:   jsr	POS
+
+; Fill in the button state
+
+    	jsr     BUTTONS                 ; Will not touch ptr1
+    	ldy	#MOUSE_INFO::BUTTONS
+    	sta	(ptr1),y
+
+      	rts
+
+;----------------------------------------------------------------------------
+; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
+; specific data in ptr1, and the ioctl code in A.
+; Must return an error code in a/x.
+;
+
+IOCTL:  lda     #MOUSE_ERR_INV_IOCTL
+        rts
+
+;----------------------------------------------------------------------------
+; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
+; (so be careful). The routine MUST return carry set if the interrupt has been
+; 'handled' - which means that the interrupt source is gone. Otherwise it
+; MUST return carry clear.
+;
+
+IRQ:    lda	SID_ADConv1		; Get mouse X movement
+      	ldy	OldPotX
+      	jsr	MoveCheck  		; Calculate movement vector
+      	sty	OldPotX
+
+; Skip processing if nothing has changed
+
+        bcc     @SkipX
+
+; Calculate the new X coordinate (--> a/y)
+
+       	add	XPos
+      	tay	      			; Remember low byte
+      	txa
+      	adc	XPos+1
+    	tax
+
+; Limit the X coordinate to the bounding box
+
+   	cpy	XMin
+   	sbc	XMin+1
+   	bpl	@L1
+       	ldy    	XMin
+       	ldx	XMin+1
+    	jmp	@L2
+@L1:	txa
+
+    	cpy	XMax
+    	sbc	XMax+1
+    	bmi	@L2
+    	ldy	XMax
+    	ldx	XMax+1
+@L2:	sty	XPos
+   	stx	XPos+1
+
+; Move the mouse pointer to the new X pos
+
+        tya
+        jsr     CMOVEX
+
+; Calculate the Y movement vector
+
+@SkipX: lda	SID_ADConv2	 	; Get mouse Y movement
+ 	ldy	OldPotY
+ 	jsr	MoveCheck	 	; Calculate movement
+ 	sty	OldPotY
+
+; Skip processing if nothing has changed
+
+        bcc     @SkipY
+
+; Calculate the new Y coordinate (--> a/y)
+
+      	sta	OldValue
+      	lda	YPos
+      	sub	OldValue
+      	tay
+      	stx	OldValue
+      	lda	YPos+1
+      	sbc	OldValue
+      	tax
+
+; Limit the Y coordinate to the bounding box
+
+   	cpy	YMin
+ 	sbc	YMin+1
+ 	bpl	@L3
+       	ldy    	YMin
+       	ldx	YMin+1
+    	jmp	@L4
+@L3:	txa
+
+    	cpy	YMax
+    	sbc	YMax+1
+    	bmi	@L4
+    	ldy	YMax
+    	ldx	YMax+1
+@L4:	sty	YPos
+ 	stx	YPos+1
+
+; Move the mouse pointer to the new X pos
+
+        tya
+        jsr     CMOVEY
+
+; Done
+
+        clc                     ; Interrupt not "handled"
+@SkipY: rts
+
+; --------------------------------------------------------------------------
+;
+; Move check routine, called for both coordinates.
+;
+; Entry:   	y = old value of pot register
+;     	   	a = current value of pot register
+; Exit:	   	y = value to use for old value
+;     	   	x/a = delta value for position
+;
+
+MoveCheck:
+      	sty	OldValue
+      	sta	NewValue
+      	ldx 	#$00
+
+      	sub	OldValue	   	; a = mod64 (new - old)
+      	and	#%01111111
+      	cmp	#%01000000	   	; if (a > 0)
+      	bcs	@L1 		   	;
+      	lsr	a   		   	;   a /= 2;
+      	beq	@L2 		   	;   if (a != 0)
+      	ldy   	NewValue     	   	;     y = NewValue
+        sec
+      	rts   	    		   	;   return
+
+@L1:  	ora   	#%11000000	   	; else or in high order bits
+      	cmp   	#$FF		   	; if (a != -1)
+      	beq   	@L2
+      	sec
+      	ror   	a   		   	;   a /= 2
+       	dex			   	;   high byte = -1 (X = $FF)
+      	ldy   	NewValue
+        sec
+      	rts
+
+@L2:   	txa			   	; A = $00
+        clc
+      	rts
+
diff --git a/libsrc/c128/mou/c128-joy.s b/libsrc/c128/mou/c128-joy.s
new file mode 100644
index 000000000..0cceaa7f1
--- /dev/null
+++ b/libsrc/c128/mou/c128-joy.s
@@ -0,0 +1,415 @@
+;
+; Driver for a "joystick mouse".
+;
+; Ullrich von Bassewitz, 2004-04-05, 2009-09-26
+;
+
+        .include        "zeropage.inc"
+        .include        "mouse-kernel.inc"
+	.include	"c128.inc"
+
+        .macpack        generic
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+HEADER:
+
+; Driver signature
+
+        .byte   $6d, $6f, $75           ; "mou"
+        .byte   MOUSE_API_VERSION       ; Mouse driver API version number
+
+; Jump table.
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   HIDE
+        .addr   SHOW
+        .addr   SETBOX
+        .addr   GETBOX
+        .addr   MOVE
+        .addr   BUTTONS
+        .addr   POS
+        .addr   INFO
+        .addr   IOCTL
+        .addr   IRQ
+
+; Mouse driver flags
+
+        .byte   MOUSE_FLAG_LATE_IRQ
+
+; Callback table, set by the kernel before INSTALL is called
+
+CHIDE:  jmp     $0000                   ; Hide the cursor
+CSHOW:  jmp     $0000                   ; Show the cursor
+CMOVEX: jmp     $0000                   ; Move the cursor to X coord
+CMOVEY: jmp     $0000                   ; Move the cursor to Y coord
+
+
+;----------------------------------------------------------------------------
+; Constants
+
+SCREEN_HEIGHT   = 200
+SCREEN_WIDTH    = 320
+
+.enum   JOY
+        UP      = $01
+        DOWN    = $02
+        LEFT    = $04
+        RIGHT   = $08
+        FIRE    = $10
+.endenum
+
+;----------------------------------------------------------------------------
+; Global variables. The bounding box values are sorted so that they can be
+; written with the least effort in the SETBOX and GETBOX routines, so don't
+; reorder them.
+
+.bss
+
+Vars:
+YPos:           .res    2               ; Current mouse position, Y
+XPos:           .res    2               ; Current mouse position, X
+XMin:		.res  	2	     	; X1 value of bounding box
+YMin:		.res  	2	     	; Y1 value of bounding box
+XMax:		.res  	2	     	; X2 value of bounding box
+YMax:		.res  	2	     	; Y2 value of bounding box
+Buttons:	.res  	1		; Button mask
+
+; Temporary value used in the int handler
+
+Temp:           .res    1
+
+; Default values for above variables
+
+.rodata
+
+.proc   DefVars
+        .word   SCREEN_HEIGHT/2         ; YPos
+        .word   SCREEN_WIDTH/2          ; XPos
+        .word   0                       ; XMin
+        .word   0                       ; YMin
+        .word   SCREEN_WIDTH            ; XMax
+        .word   SCREEN_HEIGHT           ; YMax
+	.byte	0			; Buttons
+.endproc
+
+.code
+
+;----------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present.
+; Must return an MOUSE_ERR_xx code in a/x.
+
+INSTALL:
+
+; Initialize variables. Just copy the default stuff over
+
+        ldx     #.sizeof(DefVars)-1
+@L1:    lda     DefVars,x
+        sta     Vars,x
+        dex
+        bpl     @L1
+
+; Be sure the mouse cursor is invisible and at the default location. We
+; need to do that here, because our mouse interrupt handler doesn't set the
+; mouse position if it hasn't changed.
+
+        sei
+        jsr     CHIDE
+        lda     XPos
+        ldx     XPos+1
+        jsr     CMOVEX
+        lda     YPos
+        ldx     YPos+1
+        jsr     CMOVEY
+        cli
+
+; Done, return zero (= MOUSE_ERR_OK)
+
+        ldx     #$00
+        txa
+        rts
+
+;----------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; No return code required (the driver is removed from memory on return).
+
+UNINSTALL       = HIDE                  ; Hide cursor on exit
+
+;----------------------------------------------------------------------------
+; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
+; a counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently visible and should get hidden. For most drivers,
+; no special action is required besides hiding the mouse cursor.
+; No return code required.
+
+HIDE:   sei
+        jsr     CHIDE
+        cli
+        rts
+
+;----------------------------------------------------------------------------
+; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
+; a counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently hidden and should become visible. For most drivers,
+; no special action is required besides enabling the mouse cursor.
+; No return code required.
+
+SHOW:   sei
+        jsr     CSHOW
+        cli
+        rts
+
+;----------------------------------------------------------------------------
+; SETBOX: Set the mouse bounding box. The parameters are passed as they come
+; from the C program, that is, a pointer to a mouse_box struct in a/x.
+; No checks are done if the mouse is currently inside the box, this is the job
+; of the caller. It is not necessary to validate the parameters, trust the
+; caller and save some code here. No return code required.
+
+SETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     (ptr1),y
+        sta     XMin,y
+        dey
+        bpl     @L1
+
+        cli
+       	rts
+
+;----------------------------------------------------------------------------
+; GETBOX: Return the mouse bounding box. The parameters are passed as they
+; come from the C program, that is, a pointer to a mouse_box struct in a/x.
+
+GETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     XMin,y
+        sta     (ptr1),y
+        dey
+        bpl     @L1
+
+        cli
+       	rts
+
+;----------------------------------------------------------------------------
+; MOVE: Move the mouse to a new position. The position is passed as it comes
+; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
+; remove the parameter from the stack on return.
+; No checks are done if the new position is valid (within the bounding box or
+; the screen). No return code required.
+;
+
+MOVE:   sei                             ; No interrupts
+
+        sta     YPos
+        stx     YPos+1                  ; New Y position
+        jsr     CMOVEY                  ; Set it
+
+        ldy     #$01
+        lda     (sp),y
+        sta     XPos+1
+        tax
+        dey
+        lda     (sp),y
+        sta     XPos                    ; New X position
+
+        jsr     CMOVEX			; Move the cursor
+
+	cli                             ; Allow interrupts
+       	rts
+
+;----------------------------------------------------------------------------
+; BUTTONS: Return the button mask in a/x.
+
+BUTTONS:
+	lda	Buttons
+	ldx	#$00
+	rts
+
+;----------------------------------------------------------------------------
+; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
+; No return code required.
+
+POS:    ldy    	#MOUSE_POS::XCOORD      ; Structure offset
+
+	sei	    			; Disable interrupts
+	lda     XPos			; Transfer the position
+	sta	(ptr1),y
+	lda	XPos+1
+	iny
+	sta	(ptr1),y
+      	lda	YPos
+        iny
+        sta     (ptr1),y
+	lda	YPos+1
+	cli	    			; Enable interrupts
+
+        iny
+        sta     (ptr1),y                ; Store last byte
+
+    	rts	    			; Done
+
+;----------------------------------------------------------------------------
+; INFO: Returns mouse position and current button mask in the MOUSE_INFO
+; struct pointed to by ptr1. No return code required.
+;
+; We're cheating here to keep the code smaller: The first fields of the
+; mouse_info struct are identical to the mouse_pos struct, so we will just
+; call _mouse_pos to initialize the struct pointer and fill the position
+; fields.
+
+INFO:   jsr	POS
+
+; Fill in the button state
+
+       	lda	Buttons
+    	ldy	#MOUSE_INFO::BUTTONS
+    	sta	(ptr1),y
+
+      	rts
+
+;----------------------------------------------------------------------------
+; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
+; specific data in ptr1, and the ioctl code in A.
+; Must return an error code in a/x.
+;
+
+IOCTL:  lda     #MOUSE_ERR_INV_IOCTL
+        rts
+
+;----------------------------------------------------------------------------
+; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
+; (so be careful). The routine MUST return carry set if the interrupt has been
+; 'handled' - which means that the interrupt source is gone. Otherwise it
+; MUST return carry clear.
+;
+
+IRQ:	lda	#$7F
+     	sta	CIA1_PRA
+     	lda	CIA1_PRB                ; Read joystick #0
+        and     #$1F
+	eor	#$1F  	       		; Make all bits active high
+        sta     Temp
+
+; Check for a pressed button and place the result into Buttons
+
+        ldx     #$00                    ; Assume no button pressed
+        and     #JOY::FIRE              ; Check fire button
+        beq     @L0                     ; Jump if not pressed
+        ldx     #MOUSE_BTN_LEFT         ; Left (only) button is pressed
+@L0:    stx     Buttons
+
+; Check left/right
+
+        lda     Temp                    ; Read joystick #0
+       	and    	#(JOY::LEFT | JOY::RIGHT)
+        beq     @SkipX			;
+
+; We will cheat here and rely on the fact that either the left, OR the right
+; bit can be active
+
+       	and     #JOY::RIGHT             ; Check RIGHT bit
+       	bne	@Right
+      	lda	#$FF
+      	tax
+      	bne	@AddX                   ; Branch always
+@Right:	lda	#$01
+      	ldx	#$00
+
+; Calculate the new X coordinate (--> a/y)
+
+@AddX:  add     XPos
+      	tay	      			; Remember low byte
+      	txa
+      	adc	XPos+1
+    	tax
+
+; Limit the X coordinate to the bounding box
+
+   	cpy	XMin
+   	sbc	XMin+1
+   	bpl	@L1
+       	ldy    	XMin
+       	ldx	XMin+1
+    	jmp	@L2
+@L1:	txa
+
+    	cpy	XMax
+    	sbc	XMax+1
+    	bmi	@L2
+    	ldy	XMax
+    	ldx	XMax+1
+@L2:	sty	XPos
+   	stx	XPos+1
+
+; Move the mouse pointer to the new X pos
+
+        tya
+        jsr     CMOVEX
+
+; Calculate the Y movement vector
+
+@SkipX: lda     Temp                    ; Read joystick #0
+       	and    	#(JOY::UP | JOY::DOWN)  ; Check up/down
+        beq     @SkipY		 	;
+
+; We will cheat here and rely on the fact that either the up, OR the down
+; bit can be active
+
+       	lsr     a                       ; Check UP bit
+       	bcc	@Down
+      	lda	#$FF
+      	tax
+      	bne	@AddY
+@Down:	lda	#$01
+    	ldx	#$00
+
+; Calculate the new Y coordinate (--> a/y)
+
+@AddY: 	add    	YPos
+      	tay	      			; Remember low byte
+      	txa
+      	adc	YPos+1
+    	tax
+
+; Limit the Y coordinate to the bounding box
+
+   	cpy	YMin
+ 	sbc	YMin+1
+ 	bpl	@L3
+       	ldy    	YMin
+       	ldx	YMin+1
+    	jmp	@L4
+@L3:	txa
+
+    	cpy	YMax
+    	sbc	YMax+1
+    	bmi	@L4
+    	ldy	YMax
+    	ldx	YMax+1
+@L4:	sty	YPos
+ 	stx	YPos+1
+
+; Move the mouse pointer to the new X pos
+
+        tya
+        jsr     CMOVEY
+
+; Done
+
+@SkipY: clc                             ; Interrupt not "handled"
+        rts
+
diff --git a/libsrc/c128/mou/c128-pot.s b/libsrc/c128/mou/c128-pot.s
new file mode 100644
index 000000000..c6f7a1f86
--- /dev/null
+++ b/libsrc/c128/mou/c128-pot.s
@@ -0,0 +1,390 @@
+;
+; Driver for a potentiometer "mouse" e.g. Koala Pad
+;
+; Ullrich von Bassewitz, 2004-03-29, 2009-09-26
+; Stefan Haubenthal, 2006-08-20
+;
+
+	.include	"zeropage.inc"
+	.include	"mouse-kernel.inc"
+	.include	"c128.inc"
+
+	.macpack	generic
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment	"JUMPTABLE"
+
+HEADER:
+
+; Driver signature
+
+	.byte	$6d, $6f, $75		; "mou"
+	.byte	MOUSE_API_VERSION	; Mouse driver API version number
+
+; Jump table.
+
+	.addr	INSTALL
+	.addr	UNINSTALL
+	.addr	HIDE
+	.addr	SHOW
+	.addr	SETBOX
+        .addr   GETBOX
+	.addr	MOVE
+	.addr	BUTTONS
+	.addr	POS
+	.addr	INFO
+	.addr	IOCTL
+	.addr	IRQ
+
+; Callback table, set by the kernel before INSTALL is called
+
+CHIDE:	jmp	$0000			; Hide the cursor
+CSHOW:	jmp	$0000			; Show the cursor
+CMOVEX: jmp	$0000			; Move the cursor to X coord
+CMOVEY: jmp	$0000			; Move the cursor to Y coord
+
+
+;----------------------------------------------------------------------------
+; Constants
+
+SCREEN_HEIGHT	= 200
+SCREEN_WIDTH	= 320
+
+.enum	JOY
+	UP	= $01
+	DOWN	= $02
+	LEFT	= $04
+	RIGHT	= $08
+	FIRE	= $10
+.endenum
+
+;----------------------------------------------------------------------------
+; Global variables. The bounding box values are sorted so that they can be
+; written with the least effort in the SETBOX and GETBOX routines, so don't
+; reorder them.
+
+.bss
+
+Vars:
+YPos:		.res	2		; Current mouse position, Y
+XPos:		.res	2		; Current mouse position, X
+XMin:		.res	2		; X1 value of bounding box
+YMin:		.res	2		; Y1 value of bounding box
+XMax:		.res	2		; X2 value of bounding box
+YMax:		.res	2		; Y2 value of bounding box
+Buttons:	.res	1		; Button mask
+
+; Temporary value used in the int handler
+
+Temp:		.res	1
+
+; Default values for above variables
+
+.rodata
+
+.proc	DefVars
+	.word	SCREEN_HEIGHT/2		; YPos
+	.word	SCREEN_WIDTH/2		; XPos
+	.word	0			; XMin
+	.word	0			; YMin
+	.word	SCREEN_WIDTH		; XMax
+	.word	SCREEN_HEIGHT		; YMax
+	.byte	0			; Buttons
+.endproc
+
+.code
+
+;----------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present.
+; Must return an MOUSE_ERR_xx code in a/x.
+
+INSTALL:
+
+; Initialize variables. Just copy the default stuff over
+
+	ldx	#.sizeof(DefVars)-1
+@L1:	lda	DefVars,x
+	sta	Vars,x
+	dex
+	bpl	@L1
+
+; Be sure the mouse cursor is invisible and at the default location. We
+; need to do that here, because our mouse interrupt handler doesn't set the
+; mouse position if it hasn't changed.
+
+	sei
+	jsr	CHIDE
+	lda	XPos
+	ldx	XPos+1
+	jsr	CMOVEX
+	lda	YPos
+	ldx	YPos+1
+	jsr	CMOVEY
+	cli
+
+; Done, return zero (= MOUSE_ERR_OK)
+
+	ldx	#$00
+	txa
+	rts
+
+;----------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory.
+; No return code required (the driver is removed from memory on return).
+
+UNINSTALL	= HIDE			; Hide cursor on exit
+
+;----------------------------------------------------------------------------
+; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
+; a counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently visible and should get hidden. For most drivers,
+; no special action is required besides hiding the mouse cursor.
+; No return code required.
+
+HIDE:	sei
+	jsr	CHIDE
+	cli
+	rts
+
+;----------------------------------------------------------------------------
+; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
+; a counter for calls to show/hide, and the driver entry point is only called
+; if the mouse is currently hidden and should become visible. For most drivers,
+; no special action is required besides enabling the mouse cursor.
+; No return code required.
+
+SHOW:	sei
+	jsr	CSHOW
+	cli
+	rts
+
+;----------------------------------------------------------------------------
+; SETBOX: Set the mouse bounding box. The parameters are passed as they come
+; from the C program, that is, a pointer to a mouse_box struct in a/x.
+; No checks are done if the mouse is currently inside the box, this is the job
+; of the caller. It is not necessary to validate the parameters, trust the
+; caller and save some code here. No return code required.
+
+SETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     (ptr1),y
+        sta     XMin,y
+        dey
+        bpl     @L1
+
+        cli
+       	rts
+
+;----------------------------------------------------------------------------
+; GETBOX: Return the mouse bounding box. The parameters are passed as they
+; come from the C program, that is, a pointer to a mouse_box struct in a/x.
+
+GETBOX: sta     ptr1
+        stx     ptr1+1                  ; Save data pointer
+
+        ldy     #.sizeof (MOUSE_BOX)-1
+        sei
+
+@L1:    lda     XMin,y
+        sta     (ptr1),y
+        dey
+        bpl     @L1
+
+        cli
+       	rts
+
+;----------------------------------------------------------------------------
+; MOVE: Move the mouse to a new position. The position is passed as it comes
+; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
+; remove the parameter from the stack on return.
+; No checks are done if the new position is valid (within the bounding box or
+; the screen). No return code required.
+;
+
+MOVE:	sei				; No interrupts
+
+	sta	YPos
+	stx	YPos+1			; New Y position
+	jsr	CMOVEY			; Set it
+
+	ldy	#$01
+	lda	(sp),y
+	sta	XPos+1
+	tax
+	dey
+	lda	(sp),y
+	sta	XPos			; New X position
+
+	jsr	CMOVEX			; Move the cursor
+
+	cli				; Allow interrupts
+	rts
+
+;----------------------------------------------------------------------------
+; BUTTONS: Return the button mask in a/x.
+
+BUTTONS:
+	lda	Buttons
+	ldx	#$00
+	rts
+
+;----------------------------------------------------------------------------
+; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
+; No return code required.
+
+POS:	ldy	#MOUSE_POS::XCOORD	; Structure offset
+
+	sei				; Disable interrupts
+	lda	XPos			; Transfer the position
+	sta	(ptr1),y
+	lda	XPos+1
+	iny
+	sta	(ptr1),y
+	lda	YPos
+	iny
+	sta	(ptr1),y
+	lda	YPos+1
+	cli				; Enable interrupts
+
+	iny
+	sta	(ptr1),y		; Store last byte
+
+	rts				; Done
+
+;----------------------------------------------------------------------------
+; INFO: Returns mouse position and current button mask in the MOUSE_INFO
+; struct pointed to by ptr1. No return code required.
+;
+; We're cheating here to keep the code smaller: The first fields of the
+; mouse_info struct are identical to the mouse_pos struct, so we will just
+; call _mouse_pos to initialize the struct pointer and fill the position
+; fields.
+
+INFO:	jsr	POS
+
+; Fill in the button state
+
+	lda	Buttons
+	ldy	#MOUSE_INFO::BUTTONS
+	sta	(ptr1),y
+
+	rts
+
+;----------------------------------------------------------------------------
+; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
+; specific data in ptr1, and the ioctl code in A.
+; Must return an error code in a/x.
+;
+
+IOCTL:	lda	#MOUSE_ERR_INV_IOCTL
+	rts
+
+;----------------------------------------------------------------------------
+; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
+; (so be careful).
+;
+
+IRQ:	lda	#$7F
+	sta	CIA1_PRA
+	lda	CIA1_PRB		; Read port #1
+	and	#%00001100
+	eor	#%00001100		; Make all bits active high
+	asl
+	sta	Buttons
+	lsr
+	lsr
+	lsr
+	and	#%00000001
+	ora	Buttons
+	sta	Buttons
+	ldx	#%01000000
+	stx	CIA1_PRA
+	ldy	#0
+:	dey
+	bne	:-
+	ldx	SID_ADConv1
+	stx	XPos
+	ldx	SID_ADConv2
+	stx	YPos
+
+	lda	#$FF
+	tax
+	bne	@AddX			; Branch always
+	lda	#$01
+	ldx	#$00
+
+; Calculate the new X coordinate (--> a/y)
+
+@AddX:	add	XPos
+	tay				; Remember low byte
+	txa
+	adc	XPos+1
+	tax
+
+; Limit the X coordinate to the bounding box
+
+	cpy	XMin
+	sbc	XMin+1
+	bpl	@L1
+	ldy	XMin
+	ldx	XMin+1
+	jmp	@L2
+@L1:	txa
+
+	cpy	XMax
+	sbc	XMax+1
+	bmi	@L2
+	ldy	XMax
+	ldx	XMax+1
+@L2:	sty	XPos
+	stx	XPos+1
+
+; Move the mouse pointer to the new X pos
+
+	tya
+	jsr	CMOVEX
+
+	lda	#$FF
+	tax
+	bne	@AddY
+@Down:	lda	#$01
+	ldx	#$00
+
+; Calculate the new Y coordinate (--> a/y)
+
+@AddY:	add	YPos
+	tay				; Remember low byte
+	txa
+	adc	YPos+1
+	tax
+
+; Limit the Y coordinate to the bounding box
+
+	cpy	YMin
+	sbc	YMin+1
+	bpl	@L3
+	ldy	YMin
+	ldx	YMin+1
+	jmp	@L4
+@L3:	txa
+
+	cpy	YMax
+	sbc	YMax+1
+	bmi	@L4
+	ldy	YMax
+	ldx	YMax+1
+@L4:	sty	YPos
+	stx	YPos+1
+
+; Move the mouse pointer to the new X pos
+
+	tya
+	jmp	CMOVEY
diff --git a/libsrc/c128/ser/c128-swlink.s b/libsrc/c128/ser/c128-swlink.s
new file mode 100644
index 000000000..558d80db8
--- /dev/null
+++ b/libsrc/c128/ser/c128-swlink.s
@@ -0,0 +1,498 @@
+;
+; Serial driver for the C128 using a Swiftlink or Turbo-232 cartridge.
+;
+; Ullrich von Bassewitz, 2003-04-18
+;
+; The driver is based on the cc65 rs232 module, which in turn is based on
+; Craig Bruce device driver for the Switftlink/Turbo-232.
+;
+; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
+;
+; This software is Public Domain.  It is in Buddy assembler format.
+;
+; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
+; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
+; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
+; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
+;
+; The code assumes that the kernal + I/O are in context.  On the C128, call
+; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
+; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
+; interrupt handling assumes that the 65816 is in 6502-emulation mode.
+;
+
+        .include        "zeropage.inc"
+        .include        "ser-kernel.inc"
+        .include        "ser-error.inc"
+	.include	"c128.inc"
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $73, $65, $72           ; "ser"
+        .byte   SER_API_VERSION         ; Serial API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   UNINSTALL
+        .word   OPEN
+        .word   CLOSE
+        .word   GET
+        .word   PUT
+        .word   STATUS
+        .word   IOCTL
+	.word	IRQ
+
+;----------------------------------------------------------------------------
+; I/O definitions
+
+ACIA   	        = $DE00
+ACIA_DATA       = ACIA+0        ; Data register
+ACIA_STATUS     = ACIA+1        ; Status register
+ACIA_CMD        = ACIA+2        ; Command register
+ACIA_CTRL       = ACIA+3        ; Control register
+
+;----------------------------------------------------------------------------
+;
+; Global variables
+;
+
+; We reuse the RS232 zero page variables for the driver, since the ROM
+; routines cannot be used together with this driver (may also use $A0F
+; and following in case of problems).
+RecvHead        := $A7          ; Head of receive buffer
+RecvTail        := $A8          ; Tail of receive buffer
+RecvFreeCnt     := $A9          ; Number of bytes in receive buffer
+SendHead        := $AA          ; Head of send buffer
+SendTail        := $AB          ; Tail of send buffer
+SendFreeCnt     := $B4          ; Number of bytes free in send buffer
+Stopped         := $B5          ; Flow-stopped flag
+RtsOff          := $B6          ;
+
+; Send and receive buffers: 256 bytes each
+RecvBuf         := $0C00        ; Use the ROM buffers
+SendBuf         := $0D00
+
+.rodata
+
+; Tables used to translate RS232 params into register values
+
+BaudTable:                      ; bit7 = 1 means setting is invalid
+        .byte   $FF             ; SER_BAUD_45_5
+        .byte   $FF             ; SER_BAUD_50
+        .byte   $FF             ; SER_BAUD_75
+        .byte   $FF             ; SER_BAUD_110
+        .byte   $FF             ; SER_BAUD_134_5
+        .byte   $02             ; SER_BAUD_150
+        .byte   $05             ; SER_BAUD_300
+        .byte   $06             ; SER_BAUD_600
+        .byte   $07             ; SER_BAUD_1200
+        .byte   $FF             ; SER_BAUD_1800
+        .byte   $08             ; SER_BAUD_2400
+        .byte   $09             ; SER_BAUD_3600
+        .byte   $0A             ; SER_BAUD_4800
+        .byte   $0B             ; SER_BAUD_7200
+        .byte   $0C             ; SER_BAUD_9600
+        .byte   $0E             ; SER_BAUD_19200
+        .byte   $0F             ; SER_BAUD_38400
+        .byte   $FF             ; SER_BAUD_57600
+        .byte   $FF             ; SER_BAUD_115200
+        .byte   $FF             ; SER_BAUD_230400
+
+BitTable:
+        .byte   $60             ; SER_BITS_5
+        .byte   $40             ; SER_BITS_6
+        .byte   $20             ; SER_BITS_7
+        .byte   $00             ; SER_BITS_8
+
+StopTable:
+        .byte   $00             ; SER_STOP_1
+        .byte   $80             ; SER_STOP_2
+
+ParityTable:
+        .byte   $00             ; SER_PAR_NONE
+        .byte   $20             ; SER_PAR_ODD
+        .byte   $60             ; SER_PAR_EVEN
+        .byte   $A0             ; SER_PAR_MARK
+        .byte   $E0             ; SER_PAR_SPACE
+
+.code
+
+;----------------------------------------------------------------------------
+; Interrupt stub that is copied into low RAM. The startup code uses a special
+; memory configuration with just kernal and I/O enabled (anything else is RAM).
+; The NMI handler in ROM will switch back to a configuration where just the
+; low 16K RAM are accessible. So we have to copy a smal piece of code into
+; low RAM that enables the cc65 configuration and then jumps to the real NMI
+; handler.
+
+NmiStubOrig     := *
+
+.org    $1150                           ; BASIC graphics area
+.proc   NmiStub
+
+	lda     #MMU_CFG_CC65		; Bank 0 with kernal ROM...
+	sta    	MMU_CR                  ; ...enable
+        jsr     NmiHandler              ; Call the actual NMI handler
+       	lda     #$00                    ; Get ROM config...
+	sta    	MMU_CR                  ; ...and enable it
+Vector  := *+1
+        .byte   $4C                     ; Jump to the saved IRQ vector
+
+.endproc
+.reloc
+
+;----------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present.
+; Must return an SER_ERR_xx code in a/x.
+
+INSTALL:
+
+; Deactivate DTR and disable 6551 interrupts
+
+      	lda     #%00001010
+       	sta    	ACIA_CMD
+
+; Copy the NMI stub into low memory
+
+        ldy     #.sizeof (NmiStub)-1
+@L1:    lda     NmiStubOrig,y
+        sta     NmiStub,y
+        dey
+        bpl     @L1
+
+; Set up the nmi vector
+
+   	lda   	NMIVec
+   	ldy   	NMIVec+1
+   	sta   	NmiStub::Vector+0
+   	sty   	NmiStub::Vector+1
+   	lda   	#NmiStub
+SetNMI: sta 	NMIVec
+   	sty 	NMIVec+1
+
+; Done, return an error code
+
+        lda     #SER_ERR_INIT_FAILED
+	rts
+
+; Baud rate not available
+
+InvBaud:
+        lda     #SER_ERR_BAUD_UNAVAIL
+        rts
+
+;----------------------------------------------------------------------------
+; CLOSE: Close the port, disable interrupts and flush the buffer. Called
+; without parameters. Must return an error code in a/x.
+;
+
+CLOSE:
+
+; Stop interrupts, drop DTR
+
+      	lda     #%00001010
+       	sta    	ACIA_CMD
+
+; Initalize buffers. Returns zero in a
+
+        jsr     InitBuffers
+
+; Return OK
+
+        lda     #SER_ERR_NO_DATA
+   	rts
+
+; Check for flow stopped & enough free: release flow control
+
+@L2:  	ldx 	Stopped                 ; (34)
+   	beq 	@L3
+   	cmp 	#63
+   	bcc 	@L3
+   	lda 	#$00
+   	sta 	Stopped
+   	lda 	RtsOff
+   	ora 	#%00001000
+   	sta	ACIA_CMD
+
+; Get byte from buffer
+
+@L3:  	ldx 	RecvHead                ; (41)
+       	lda 	RecvBuf,x
+      	inc 	RecvHead
+   	inc 	RecvFreeCnt
+       	ldx 	#$00                    ; (59)
+   	sta    	(ptr1,x)
+       	txa				; Return code = 0
+   	rts
+
+;----------------------------------------------------------------------------
+; PUT: Output character in A.
+; Must return an error code in a/x.
+;
+
+PUT:
+
+; Try to send
+
+        ldx 	SendFreeCnt
+       	inx                             ; X = $ff?
+   	beq 	@L2
+   	pha
+   	lda 	#$00
+   	jsr 	TryToSend
+   	pla
+
+; Put byte into send buffer & send
+
+@L2:  	ldx 	SendFreeCnt
+   	bne 	@L3
+   	lda 	#SER_ERR_INV_IOCTL
+        rts
+
+;----------------------------------------------------------------------------
+; IRQ: Not used on the C128
+;
+
+IRQ     = $0000
+
+;----------------------------------------------------------------------------
+;
+; NMI handler
+; C128 NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=33, ROMexit=30
+; C64  NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=34, ROMexit=29
+;
+; timing: normal=76+43+9=128 cycles, assertFlow=76+52+9=137 cycles
+;
+; C128 @ 115.2k: 177 cycles avail (fast)
+; C64  @  57.6k: 177 cycles avail, worstAvail=177-43? = 134
+; SCPU @ 230.4k: 868 cycles avail: for a joke!
+;
+; Note: Because of the C128 banking, a small stub has to go into low memory,
+; since the ROM NMI entry point switches to a configuration, where only the
+; low 16K of RAM are visible. The entry code switches into the standard cc65
+; configuration (I/O + 16K kernal) and then jumps here. Registers are already
+; saved by the ROM code.
+
+NmiHandler:
+       	lda    	ACIA_STATUS     ;(4) ;status ;check for byte received
+     	and 	#$08           	;(2)
+       	beq    	@L9  		;(2*)
+     	cld
+        lda 	ACIA_DATA       ;(4)  data  ;get byte and put into receive buffer
+    	ldy 	RecvTail 	;(4)
+    	ldx 	RecvFreeCnt  	;(4)
+       	beq    	@L9  		;(2*) Jump if no space in receive buffer
+    	sta 	RecvBuf,y 	;(5)
+    	inc 	RecvTail        ;(6)
+    	dec 	RecvFreeCnt     ;(6)
+    	cpx 	#33            	;(2)  check for buffer space low
+       	bcc    	@L2            	;(2*)
+       	rts
+
+; Assert flow control
+
+@L2:  	lda 	RtsOff       	;(3) assert flow control if buffer space too low
+    	sta 	ACIA_CMD	;(4) command
+    	sta 	Stopped      	;(3)
+@L9:    rts
+
+;----------------------------------------------------------------------------
+; Try to send a byte. Internal routine. A = TryHard
+
+.proc   TryToSend
+
+   	sta 	tmp1	       	; Remember tryHard flag
+@L0:   	lda 	SendFreeCnt
+    	cmp 	#$ff
+    	beq 	@L3	       	; Bail out
+
+; Check for flow stopped
+
+@L1:	lda 	Stopped
+       	bne    	@L3	       	; Bail out
+
+; Check that swiftlink is ready to send
+
+@L2:   	lda	ACIA_STATUS
+    	and 	#$10
+    	bne 	@L4
+    	bit 	tmp1	       	;keep trying if must try hard
+       	bmi 	@L0
+@L3:	rts
+
+; Send byte and try again
+
+@L4:  	ldx 	SendHead
+    	lda 	SendBuf,x
+    	sta	ACIA_DATA
+    	inc 	SendHead
+    	inc 	SendFreeCnt
+    	jmp 	@L0
+
+.endproc
+
+
+;----------------------------------------------------------------------------
+; Initialize buffers
+
+InitBuffers:
+        ldx 	#0
+        stx     Stopped
+       	stx 	RecvHead
+    	stx 	RecvTail
+      	stx 	SendHead
+    	stx 	SendTail
+        dex                             ; X = 255
+       	stx    	RecvFreeCnt
+      	stx 	SendFreeCnt
+        rts
+
+
diff --git a/libsrc/c128/tgi/c128-vdc.s b/libsrc/c128/tgi/c128-vdc.s
new file mode 100644
index 000000000..e497a5942
--- /dev/null
+++ b/libsrc/c128/tgi/c128-vdc.s
@@ -0,0 +1,778 @@
+;
+; Graphics driver for the 640x200x2 mode on the C128 VDC
+; Maciej 'YTM/Elysium' Witkowiak 
+; 23.12.2002
+; 2004-04-04, Greg King
+;
+; NOTES:
+; For any smart monkey that will try to optimize this: PLEASE do tests on
+; real VDC, not only VICE.
+;
+; Only DONE routine contains C128-mode specific stuff, everything else will
+; work in C64-mode of C128 (C64 needs full VDC init then).
+;
+; With special initialization and CALC we can get 320x200 double-pixel mode.
+;
+; Color translation values for BROWN and GRAY3 are obviously wrong, they
+; could be replaced by equiv. of ORANGE and GRAY2 but this would give only
+; 14 of 16 colors available.
+;
+; Register 25 ($19) is said to require different value for VDC v1, but I
+; couldn't find what it should be.
+
+	.include     	"zeropage.inc"
+
+      	.include     	"tgi-kernel.inc"
+        .include        "tgi-error.inc"
+
+
+        .macpack        generic
+
+; ------------------------------------------------------------------------
+; Constants
+
+VDC_ADDR_REG	  = $D600		  ; VDC address
+VDC_DATA_REG	  = $D601		  ; VDC data
+
+VDC_DSP_HI	  = 12			  ; registers used
+VDC_DSP_LO	  = 13
+VDC_DATA_HI	  = 18
+VDC_DATA_LO	  = 19
+VDC_VSCROLL	  = 24
+VDC_HSCROLL	  = 25
+VDC_COLORS	  = 26
+VDC_CSET	  = 28
+VDC_COUNT	  = 30
+VDC_DATA	  = 31
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table and constants.
+
+.segment        "JUMPTABLE"
+
+; First part of the header is a structure that has a magic and defines the
+; capabilities of the driver
+
+        .byte   $74, $67, $69           ; "tgi"
+        .byte   TGI_API_VERSION         ; TGI API version number
+xres:   .word   640                     ; X resolution
+yres:   .word   200                     ; Y resolution
+        .byte   2                       ; Number of drawing colors
+pages:	.byte   1                       ; Number of screens available
+        .byte   8                       ; System font X size
+        .byte   8                       ; System font Y size
+        .word   $006A                   ; Aspect ratio (based on 4/3 display)
+        .byte   0                       ; TGI driver flags
+
+; Next comes the jump table. Currently all entries must be valid and may point
+; to an RTS for test versions (function not implemented).
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   INIT
+        .addr   DONE
+       	.addr   GETERROR
+        .addr   CONTROL
+        .addr   CLEAR
+        .addr   SETVIEWPAGE
+        .addr   SETDRAWPAGE
+        .addr   SETCOLOR
+        .addr   SETPALETTE
+        .addr   GETPALETTE
+        .addr   GETDEFPALETTE
+        .addr   SETPIXEL
+        .addr   GETPIXEL
+        .addr   LINE
+        .addr   BAR
+        .addr   TEXTSTYLE
+        .addr   OUTTEXT
+        .addr   0                       ; IRQ entry is unused
+
+; ------------------------------------------------------------------------
+; Data.
+
+; Variables mapped to the zero page segment variables. Some of these are
+; used for passing parameters to the driver.
+
+X1              = ptr1
+Y1              = ptr2
+X2              = ptr3
+Y2              = ptr4
+
+ADDR		= tmp1
+TEMP		= tmp3
+TEMP2		= tmp4		; HORLINE
+TEMP3		= sreg		; HORLINE
+
+; Absolute variables used in the code
+
+.bss
+
+SCRBASE:	.res	1	; High byte of screen base
+
+ERROR:  	.res	1     	; Error code
+PALETTE:        .res    2       ; The current palette
+
+BITMASK:        .res    1       ; $00 = clear, $FF = set pixels
+
+OLDCOLOR:	.res	1	; colors before entering gfx mode
+
+; Text output stuff
+TEXTMAGX:       .res    1
+TEXTMAGY:       .res    1
+TEXTDIR:        .res    1
+
+; Constants and tables
+
+.rodata
+
+DEFPALETTE:     .byte   $00, $0f        ; White on black
+PALETTESIZE     = * - DEFPALETTE
+
+BITTAB:         .byte   $80,$40,$20,$10,$08,$04,$02,$01
+
+BITMASKL:	.byte	%11111111, %01111111, %00111111, %00011111
+		.byte   %00001111, %00000111, %00000011, %00000001
+
+BITMASKR:	.byte	%10000000, %11000000, %11100000, %11110000
+		.byte	%11111000, %11111100, %11111110, %11111111
+
+; color translation table (indexed by VIC color)
+COLTRANS:	.byte $00, $0f, $08, $06, $0a, $04, $02, $0c
+		.byte $0d, $0b, $09, $01, $0e, $05, $03, $07
+		; colors BROWN and GRAY3 are wrong
+
+; VDC initialization table (reg),(val),...,$ff
+InitVDCTab:
+		.byte VDC_DSP_HI, 0		; viewpage 0 as default
+		.byte VDC_DSP_LO, 0
+		.byte VDC_HSCROLL, $87
+		.byte $ff
+
+SCN80CLR:	.byte 27,88,147,27,88,0
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. May
+; initialize anything that has to be done just once. Is probably empty
+; most of the time.
+;
+; Must set an error code: NO
+;
+
+INSTALL:
+	; check for VDC version and update register $19 value
+
+	; check for VDC ram size and update number of available screens
+
+	ldx	#VDC_CSET	; determine size of RAM...
+	jsr	VDCReadReg
+	sta	tmp1
+	ora	#%00010000
+	jsr	VDCWriteReg	; turn on 64k
+
+	jsr	settestadr1	; save original value of test byte
+	jsr	VDCReadByte
+	sta	tmp2
+
+	lda	#$55		; write $55 here
+	ldy	#ptr1
+	jsr	test64k		; read it here and there
+	lda	#$aa		; write $aa here
+	ldy	#ptr2
+	jsr	test64k		; read it here and there
+
+	jsr	settestadr1
+	lda	tmp2
+	jsr	VDCWriteByte	; restore original value of test byte
+
+	lda	ptr1		; do bytes match?
+	cmp	ptr1+1
+	bne	@have64k
+	lda	ptr2
+	cmp	ptr2+1
+	bne	@have64k
+
+	ldx	#VDC_CSET
+	lda	tmp1
+	jsr	VDCWriteReg	; restore 16/64k flag
+	jmp	@endok		; and leave default values for 16k
+
+@have64k:
+	lda	#4
+	sta	pages
+@endok:
+	lda     #0
+	sta	SCRBASE		; draw page 0 as default
+        rts
+
+test64k:
+	sta	tmp1
+	sty	ptr3
+	lda	#0
+	sta	ptr3+1
+	jsr	settestadr1
+	lda	tmp1
+	jsr	VDCWriteByte		; write $55
+	jsr	settestadr1
+	jsr	VDCReadByte		; read here
+	pha
+	jsr	settestadr2
+	jsr	VDCReadByte		; and there
+	ldy	#1
+	sta	(ptr3),y
+	pla
+	dey
+	sta	(ptr3),y
+	rts
+
+settestadr1:
+	ldy	#$02			; test page 2 (here)
+	.byte	$2c
+settestadr2:
+	ldy	#$42			; or page 64+2 (there)
+	lda	#0
+	jmp	VDCSetSourceAddr
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory. May
+; clean up anything done by INSTALL but is probably empty most of the time.
+;
+; Must set an error code: NO
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; INIT: Changes an already installed device from text mode to graphics
+; mode.
+; Note that INIT/DONE may be called multiple times while the driver
+; is loaded, while INSTALL is only called once, so any code that is needed
+; to initializes variables and so on must go here. Setting palette and
+; clearing the screen is not needed because this is called by the graphics
+; kernel later.
+; The graphics kernel will never call INIT when a graphics mode is already
+; active, so there is no need to protect against that.
+;
+; Must set an error code: YES
+;
+
+INIT:
+
+; Initialize variables
+
+@L1:    ldx     #$FF
+        stx     BITMASK
+
+; Remeber current color value
+	ldx	#VDC_COLORS
+	jsr	VDCReadReg
+	sta	OLDCOLOR
+
+; Switch into graphics mode (set view page 0)
+
+	ldy	#0
+@L2:	ldx	InitVDCTab,y
+	bmi	@L3
+	iny
+	lda	InitVDCTab,y
+	jsr	VDCWriteReg
+	iny
+	bne	@L2
+@L3:
+
+; Done, reset the error code
+
+        lda     #TGI_ERR_OK
+        sta     ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; DONE: Will be called to switch the graphics device back into text mode.
+; The graphics kernel will never call DONE when no graphics mode is active,
+; so there is no need to protect against that.
+;
+; Must set an error code: NO
+;
+
+DONE:
+	; This part is C128-mode specific
+	jsr $e179		; reload character set and setup VDC
+	jsr $ff62
+	lda $d7			; in 80-columns?
+	bne @L01
+@L0:	lda SCN80CLR,y
+	beq @L1
+	jsr $ffd2		; print \xe,clr,\xe
+	iny
+	bne @L0
+@L01:	lda #147
+	jsr $ffd2		; print clr
+@L1:	lda #0			; restore view page
+	ldx #VDC_DSP_HI
+	jsr VDCWriteReg
+	lda OLDCOLOR
+	ldx #VDC_COLORS
+	jsr VDCWriteReg		; restore color (background)
+	lda #$47
+	ldx #VDC_HSCROLL
+       	jmp VDCWriteReg		; switch to text screen
+
+; ------------------------------------------------------------------------
+; GETERROR: Return the error code in A and clear it.
+
+GETERROR:
+       	ldx	#TGI_ERR_OK
+	lda	ERROR
+	stx	ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; CONTROL: Platform/driver specific entry point.
+;
+; Must set an error code: YES
+;
+
+CONTROL:
+	lda	#TGI_ERR_INV_FUNC
+	sta	ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; CLEAR: Clears the screen.
+;
+; Must set an error code: NO
+;
+
+CLEAR:
+	lda	#0
+	ldy	SCRBASE
+	jsr	VDCSetSourceAddr
+	lda	#0
+	ldx	#VDC_VSCROLL
+	jsr	VDCWriteReg			; set fill mode
+	lda	#0
+	jsr	VDCWriteByte			; put 1rst byte (fill value)
+	ldy	#62				; 62 times
+	lda	#0				; 256 bytes
+	ldx	#VDC_COUNT
+@L1:	jsr	VDCWriteReg
+	dey
+	bne	@L1
+	lda	#127
+	jmp	VDCWriteReg			; 1+62*256+127=16000=(640*256)/8
+
+; ------------------------------------------------------------------------
+; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+;
+; Must set an error code: NO (will only be called if page ok)
+;
+
+SETVIEWPAGE:
+	clc
+	ror
+	ror
+	ror
+	ldx	#VDC_DSP_HI
+	jmp	VDCWriteReg
+
+; ------------------------------------------------------------------------
+; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+;
+; Must set an error code: NO (will only be called if page ok)
+;
+
+SETDRAWPAGE:
+	clc
+	ror
+	ror
+	ror
+	sta	SCRBASE
+	rts
+
+; ------------------------------------------------------------------------
+; SETCOLOR: Set the drawing color (in A). The new color is already checked
+; to be in a valid range (0..maxcolor-1).
+;
+; Must set an error code: NO (will only be called if color ok)
+;
+
+SETCOLOR:
+        tax
+        beq     @L1
+        lda     #$FF
+@L1:    sta     BITMASK
+        rts
+
+; ------------------------------------------------------------------------
+; SETPALETTE: Set the palette (not available with all drivers/hardware).
+; A pointer to the palette is passed in ptr1. Must set an error if palettes
+; are not supported
+;
+; Must set an error code: YES
+;
+
+SETPALETTE:
+        ldy     #PALETTESIZE - 1
+@L1:    lda     (ptr1),y        ; Copy the palette
+        and     #$0F            ; Make a valid color
+        sta     PALETTE,y
+        dey
+        bpl     @L1
+
+; Get the color entries from the palette
+
+        ldy     PALETTE+1       ; Foreground color
+	lda	COLTRANS,y
+        asl     a
+        asl     a
+        asl     a
+        asl     a
+        ldy     PALETTE         ; Background color
+	ora	COLTRANS,y
+
+	ldx	#VDC_COLORS
+       	jsr     VDCWriteReg
+        lda     #TGI_ERR_OK     ; Clear error code
+        sta     ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
+;
+; Must set an error code: NO
+;
+
+GETPALETTE:
+        lda     #PALETTE
+        rts
+
+; ------------------------------------------------------------------------
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes, otherwise the caller has no way to determine the colors
+; of the (not changeable) palette.
+;
+; Must set an error code: NO (all drivers must have a default palette)
+;
+
+GETDEFPALETTE:
+        lda     #DEFPALETTE
+        rts
+
+; ------------------------------------------------------------------------
+; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
+; color. The coordinates passed to this function are never outside the
+; visible screen area, so there is no need for clipping inside this function.
+;
+; Must set an error code: NO
+;
+
+SETPIXEL:
+        jsr     CALC            ; Calculate coordinates
+
+	stx	TEMP
+	lda	ADDR
+	ldy	ADDR+1
+	jsr	VDCSetSourceAddr
+	jsr	VDCReadByte
+	ldx	TEMP
+
+	sta	TEMP
+        eor     BITMASK
+        and     BITTAB,X
+	eor	TEMP
+	pha
+	lda	ADDR
+	ldy	ADDR+1
+	jsr	VDCSetSourceAddr
+	pla
+	jsr	VDCWriteByte
+
+@L9:    rts
+
+; ------------------------------------------------------------------------
+; GETPIXEL: Read the color value of a pixel and return it in A/X. The
+; coordinates passed to this function are never outside the visible screen
+; area, so there is no need for clipping inside this function.
+
+
+GETPIXEL:
+        jsr     CALC            ; Calculate coordinates
+
+	stx	TEMP		; preserve X
+	lda	ADDR
+	ldy	ADDR+1
+	jsr	VDCSetSourceAddr
+	jsr	VDCReadByte
+	ldx	TEMP
+
+        ldy     #$00
+        and     BITTAB,X
+        beq     @L1
+        iny
+
+@L1:    tya                     ; Get color value into A
+        ldx     #$00            ; Clear high byte
+        rts
+
+; ------------------------------------------------------------------------
+; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
+; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
+; Contrary to most other functions, the graphics kernel will sort and clip
+; the coordinates before calling the driver, so on entry the following
+; conditions are valid:
+;       X1 <= X2
+;       Y1 <= Y2
+;       (X1 >= 0) && (X1 < XRES)
+;       (X2 >= 0) && (X2 < XRES)
+;       (Y1 >= 0) && (Y1 < YRES)
+;       (Y2 >= 0) && (Y2 < YRES)
+;
+; Must set an error code: NO
+;
+
+BAR:
+	inc	Y2
+	bne	HORLINE
+	inc	Y2+1
+
+; Original code for a horizontal line
+
+HORLINE:
+	lda X1
+	pha
+	lda X1+1
+	pha
+	jsr CALC		; get data for LEFT
+	lda BITMASKL,x		; remember left address and bitmask
+	pha
+	lda ADDR
+	pha
+	lda ADDR+1
+	pha
+
+	lda X2
+	sta X1
+	lda X2+1
+	sta X1+1
+	jsr CALC		; get data for RIGHT
+	lda BITMASKR,x
+	sta TEMP3
+
+	pla			; recall data for LEFT
+	sta X1+1
+	pla
+	sta X1			; put left address into X1
+	pla
+
+	cmp #%11111111		; if left bit <> 0
+	beq @L1
+	sta TEMP2		; do left byte only...
+	lda X1
+	ldy X1+1
+	jsr VDCSetSourceAddr
+	jsr VDCReadByte
+	sta TEMP
+	eor BITMASK
+	and TEMP2
+	eor TEMP
+	pha
+	lda X1
+	ldy X1+1
+	jsr VDCSetSourceAddr
+	pla
+	jsr VDCWriteByte
+	inc X1			; ... and proceed
+	bne @L1
+	inc X1+1
+
+	; do right byte (if Y2=0 ++ADDR and skip)
+@L1:	lda TEMP3
+	cmp #%11111111		; if right bit <> 7
+	bne @L11
+	inc ADDR		; right bit = 7 - the next one is the last
+	bne @L10
+	inc ADDR+1
+@L10:	bne @L2
+
+@L11:	lda ADDR		; do right byte only...
+	ldy ADDR+1
+	jsr VDCSetSourceAddr
+	jsr VDCReadByte
+	sta TEMP
+	eor BITMASK
+	and TEMP3
+	eor TEMP
+	pha
+	lda ADDR
+	ldy ADDR+1
+	jsr VDCSetSourceAddr
+	pla
+	jsr VDCWriteByte
+
+@L2:				; do the fill in the middle
+	lda ADDR		; calculate offset in full bytes
+	sec
+	sbc X1
+	beq @L3			; if equal - there are no more bytes
+	sta ADDR
+
+	lda X1			; setup for the left side
+	ldy X1+1
+	jsr VDCSetSourceAddr
+	lda BITMASK		; get color
+	jsr VDCWriteByte	; put 1st value
+	ldx ADDR
+	dex
+	beq @L3			; 1 byte already written
+
+	stx ADDR		; if there are more bytes - fill them...
+	ldx #VDC_VSCROLL
+	lda #0
+	jsr VDCWriteReg		; setup for fill
+	ldx #VDC_COUNT
+	lda ADDR
+	jsr VDCWriteReg		; ... fill them NOW!
+
+@L3:	pla
+	sta X1+1
+	pla
+	sta X1
+
+; End of horizontal line code
+
+	inc	Y1
+	bne	@L4
+	inc	Y1+1
+@L4:	lda	Y1
+	cmp	Y2
+	bne	@L5
+	lda	Y1+1
+	cmp	Y2+1
+	bne	@L5
+	rts
+
+@L5:	jmp	HORLINE
+
+
+; ------------------------------------------------------------------------
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
+; direction is passend in X/Y, the text direction is passed in A.
+;
+; Must set an error code: NO
+;
+
+TEXTSTYLE:
+        stx     TEXTMAGX
+        sty     TEXTMAGY
+        sta     TEXTDIR
+        rts
+
+
+; ------------------------------------------------------------------------
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero terminated
+; string with address in ptr3.
+;
+; Must set an error code: NO
+;
+
+OUTTEXT:
+        rts
+
+; ------------------------------------------------------------------------
+; Calculate all variables to plot the pixel at X1/Y1.
+;------------------------
+;< X1,Y1 - pixel
+;> ADDR - address of card
+;> X - bit number (X1 & 7)
+CALC:
+	lda	Y1+1
+	sta	ADDR+1
+	lda	Y1
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1		; Y*4
+	clc
+	adc	Y1
+	sta	ADDR
+	lda	Y1+1
+	adc	ADDR+1
+	sta	ADDR+1		; Y*4+Y=Y*5
+	lda	ADDR
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1
+	sta	ADDR		; Y*5*16=Y*80
+	lda	X1+1
+	sta	TEMP
+	lda	X1
+	lsr	TEMP
+	ror
+	lsr	TEMP
+	ror
+	lsr	TEMP
+	ror
+	clc
+	adc	ADDR
+	sta	ADDR
+	lda	ADDR+1		; ADDR = Y*80+x/8
+	adc	TEMP
+	sta	ADDR+1
+	lda	ADDR+1
+	adc	SCRBASE
+	sta	ADDR+1
+	lda	X1
+	and	#7
+	tax
+	rts
+
+;-------------
+; VDC helpers
+
+VDCSetSourceAddr:
+	pha
+	tya
+	ldx	#VDC_DATA_HI
+	jsr	VDCWriteReg
+	pla
+	ldx	#VDC_DATA_LO
+	bne	VDCWriteReg
+
+VDCReadByte:
+	ldx	#VDC_DATA
+VDCReadReg:
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	lda	VDC_DATA_REG
+	rts
+
+VDCWriteByte:
+	ldx	#VDC_DATA
+VDCWriteReg:
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	sta	VDC_DATA_REG
+	rts
+
+; ------------------------------------------------------------------------
+
+	.include     	"../../tgi/tgidrv_line.inc"
diff --git a/libsrc/c128/tgi/c128-vdc2.s b/libsrc/c128/tgi/c128-vdc2.s
new file mode 100644
index 000000000..7f2dbdf5c
--- /dev/null
+++ b/libsrc/c128/tgi/c128-vdc2.s
@@ -0,0 +1,792 @@
+;
+; Graphics driver for the 640x480x2 mode on the C128 VDC 64k
+; (values for this mode based on Fred Bowen's document)
+; Maciej 'YTM/Elysium' Witkowiak 
+; 23.12.2002
+; 2004-04-04, Greg King
+;
+; NOTES:
+; For any smart monkey that will try to optimize this: PLEASE do tests on
+; real VDC, not only VICE.
+;
+; Only DONE routine contains C128-mode specific stuff, everything else will
+; work in C64-mode of C128 (C64 needs full VDC init then).
+;
+; With special initialization and CALC we can get 320x200 double-pixel mode.
+;
+; Color translation values for BROWN and GRAY3 are obviously wrong, they
+; could be replaced by equiv. of ORANGE and GRAY2 but this would give only
+; 14 of 16 colors available.
+;
+; Register 25 ($19) is said to require different value for VDC v1, but I
+; couldn't find what it should be.
+
+	.include     	"zeropage.inc"
+
+      	.include     	"tgi-kernel.inc"
+        .include        "tgi-error.inc"
+
+
+        .macpack        generic
+
+; ------------------------------------------------------------------------
+; Constants
+
+VDC_ADDR_REG	  = $D600		  ; VDC address
+VDC_DATA_REG	  = $D601		  ; VDC data
+
+VDC_DSP_HI	  = 12			  ; registers used
+VDC_DSP_LO	  = 13
+VDC_DATA_HI	  = 18
+VDC_DATA_LO	  = 19
+VDC_VSCROLL	  = 24
+VDC_HSCROLL	  = 25
+VDC_COLORS	  = 26
+VDC_CSET	  = 28
+VDC_COUNT	  = 30
+VDC_DATA	  = 31
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table and constants.
+
+.segment        "JUMPTABLE"
+
+; First part of the header is a structure that has a magic and defines the
+; capabilities of the driver
+
+        .byte   $74, $67, $69           ; "tgi"
+        .byte   TGI_API_VERSION         ; TGI API version number
+xres:   .word   640                     ; X resolution
+yres:   .word   480                     ; Y resolution
+        .byte   2                       ; Number of drawing colors
+pages:	.byte   0                       ; Number of screens available
+        .byte   8                       ; System font X size
+        .byte   8                       ; System font Y size
+        .word   $0100                   ; Aspect ratio (based on 4/3 display)
+        .byte   0                       ; TGI driver flags
+
+; Next comes the jump table. Currently all entries must be valid and may point
+; to an RTS for test versions (function not implemented).
+
+        .addr   INSTALL
+        .addr   UNINSTALL
+        .addr   INIT
+        .addr   DONE
+       	.addr   GETERROR
+        .addr   CONTROL
+        .addr   CLEAR
+        .addr   SETVIEWPAGE
+        .addr   SETDRAWPAGE
+        .addr   SETCOLOR
+        .addr   SETPALETTE
+        .addr   GETPALETTE
+        .addr   GETDEFPALETTE
+        .addr   SETPIXEL
+        .addr   GETPIXEL
+        .addr   LINE
+        .addr   BAR
+        .addr   TEXTSTYLE
+        .addr   OUTTEXT
+        .addr   0                       ; IRQ entry is unused
+
+; ------------------------------------------------------------------------
+; Data.
+
+; Variables mapped to the zero page segment variables. Some of these are
+; used for passing parameters to the driver.
+
+X1              = ptr1
+Y1              = ptr2
+X2              = ptr3
+Y2              = ptr4
+
+ADDR		= tmp1
+TEMP		= tmp3
+TEMP2		= tmp4		; HORLINE
+TEMP3		= sreg		; HORLINE
+
+; Absolute variables used in the code
+
+.bss
+
+ERROR:  	.res	1     	; Error code
+PALETTE:        .res    2       ; The current palette
+
+BITMASK:        .res    1       ; $00 = clear, $FF = set pixels
+
+OLDCOLOR:	.res	1	; colors before entering gfx mode
+
+; Text output stuff
+TEXTMAGX:       .res    1
+TEXTMAGY:       .res    1
+TEXTDIR:        .res    1
+
+; Constants and tables
+
+.rodata
+
+DEFPALETTE:     .byte   $00, $0f        ; White on black
+PALETTESIZE     = * - DEFPALETTE
+
+BITTAB:         .byte   $80,$40,$20,$10,$08,$04,$02,$01
+
+BITMASKL:	.byte	%11111111, %01111111, %00111111, %00011111
+		.byte   %00001111, %00000111, %00000011, %00000001
+
+BITMASKR:	.byte	%10000000, %11000000, %11100000, %11110000
+		.byte	%11111000, %11111100, %11111110, %11111111
+
+; color translation table (indexed by VIC color)
+COLTRANS:	.byte $00, $0f, $08, $06, $0a, $04, $02, $0c
+		.byte $0d, $0b, $09, $01, $0e, $05, $03, $07
+		; colors BROWN and GRAY3 are wrong
+
+; VDC initialization table (reg),(val),...,$ff
+InitVDCTab:
+		.byte VDC_DSP_HI, 0		; viewpage 0 as default
+		.byte VDC_DSP_LO, 0
+		.byte VDC_HSCROLL, $87
+		.byte 2, $66
+		.byte 4, $4c
+		.byte 5, $06
+		.byte 6, $4c
+		.byte 7, $47
+		.byte 8, $03
+		.byte 9, $06
+		.byte 27, $00
+		.byte $ff
+
+SCN80CLR: 	.byte 27,88,147,27,88,0
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. May
+; initialize anything that has to be done just once. Is probably empty
+; most of the time.
+;
+; Must set an error code: NO
+;
+
+INSTALL:
+	; check for VDC version and update register $19 value
+
+	; check for VDC ram size and update number of available screens
+
+	ldx	#VDC_CSET	; determine size of RAM...
+	jsr	VDCReadReg
+	sta	tmp1
+	ora	#%00010000
+	jsr	VDCWriteReg	; turn on 64k
+
+	jsr	settestadr1	; save original value of test byte
+	jsr	VDCReadByte
+	sta	tmp2
+
+	lda	#$55		; write $55 here
+	ldy	#ptr1
+	jsr	test64k		; read it here and there
+	lda	#$aa		; write $aa here
+	ldy	#ptr2
+	jsr	test64k		; read it here and there
+
+	jsr	settestadr1
+	lda	tmp2
+	jsr	VDCWriteByte	; restore original value of test byte
+
+	lda	ptr1		; do bytes match?
+	cmp	ptr1+1
+	bne	@have64k
+	lda	ptr2
+	cmp	ptr2+1
+	bne	@have64k
+
+	ldx	#VDC_CSET
+	lda	tmp1
+	jsr	VDCWriteReg	; restore 16/64k flag
+	jmp	@endok		; and leave default values for 16k
+
+@have64k:
+	lda	#1
+	sta	pages
+@endok:
+        rts
+
+test64k:
+	sta	tmp1
+	sty	ptr3
+	lda	#0
+	sta	ptr3+1
+	jsr	settestadr1
+	lda	tmp1
+	jsr	VDCWriteByte		; write $55
+	jsr	settestadr1
+	jsr	VDCReadByte		; read here
+	pha
+	jsr	settestadr2
+	jsr	VDCReadByte		; and there
+	ldy	#1
+	sta	(ptr3),y
+	pla
+	dey
+	sta	(ptr3),y
+	rts
+
+settestadr1:
+	ldy	#$02			; test page 2 (here)
+	.byte	$2c
+settestadr2:
+	ldy	#$42			; or page 64+2 (there)
+	lda	#0
+	jmp	VDCSetSourceAddr
+
+; ------------------------------------------------------------------------
+; UNINSTALL routine. Is called before the driver is removed from memory. May
+; clean up anything done by INSTALL but is probably empty most of the time.
+;
+; Must set an error code: NO
+;
+
+UNINSTALL:
+        rts
+
+
+; ------------------------------------------------------------------------
+; INIT: Changes an already installed device from text mode to graphics
+; mode.
+; Note that INIT/DONE may be called multiple times while the driver
+; is loaded, while INSTALL is only called once, so any code that is needed
+; to initializes variables and so on must go here. Setting palette and
+; clearing the screen is not needed because this is called by the graphics
+; kernel later.
+; The graphics kernel will never call INIT when a graphics mode is already
+; active, so there is no need to protect against that.
+;
+; Must set an error code: YES
+;
+
+INIT:
+	lda	pages			; is there enough memory?
+	bne	@L1			; Jump if there is one screen
+	lda	#TGI_ERR_INV_MODE	; Error
+	bne	@L9
+
+; Initialize variables
+
+@L1:    ldx     #$FF
+        stx     BITMASK
+
+; Remeber current color value
+	ldx	#VDC_COLORS
+	jsr	VDCReadReg
+	sta	OLDCOLOR
+
+; Switch into graphics mode (set view page 0)
+
+	ldy	#0
+@L2:	ldx	InitVDCTab,y
+	bmi	@L3
+	iny
+	lda	InitVDCTab,y
+	jsr	VDCWriteReg
+	iny
+	bne	@L2
+@L3:
+
+; Done, reset the error code
+
+        lda     #TGI_ERR_OK
+@L9:    sta     ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; DONE: Will be called to switch the graphics device back into text mode.
+; The graphics kernel will never call DONE when no graphics mode is active,
+; so there is no need to protect against that.
+;
+; Must set an error code: NO
+;
+
+DONE:
+	; This part is C128-mode specific
+	jsr $e179		; reload character set and setup VDC
+	jsr $ff62
+	lda $d7			; in 80-columns?
+	bne @L01
+@L0:	lda SCN80CLR,y
+	beq @L1
+	jsr $ffd2		; print \xe,clr,\xe
+	iny
+	bne @L0
+@L01:	lda #147
+	jsr $ffd2		; print clr
+@L1:	lda #0			; restore view page
+	ldx #VDC_DSP_HI
+	jsr VDCWriteReg
+	lda OLDCOLOR
+	ldx #VDC_COLORS
+	jsr VDCWriteReg		; restore color (background)
+	lda #$47
+	ldx #VDC_HSCROLL
+       	jmp VDCWriteReg		; switch to text screen
+
+; ------------------------------------------------------------------------
+; GETERROR: Return the error code in A and clear it.
+
+GETERROR:
+       	ldx	#TGI_ERR_OK
+	lda	ERROR
+	stx	ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; CONTROL: Platform/driver specific entry point.
+;
+; Must set an error code: YES
+;
+
+CONTROL:
+	lda	#TGI_ERR_INV_FUNC
+	sta	ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; CLEAR: Clears the screen.
+;
+; Must set an error code: NO
+;
+
+CLEAR:
+	lda	#0
+	tay
+	jsr	VDCSetSourceAddr
+	lda	#0
+	ldx	#VDC_VSCROLL
+	jsr	VDCWriteReg			; set fill mode
+	lda	#0
+	jsr	VDCWriteByte			; put 1rst byte (fill value)
+	ldy	#159				; 159 times
+	lda	#0				; 256 bytes
+	ldx	#VDC_COUNT
+@L1:	jsr	VDCWriteReg
+	dey
+	bne	@L1
+	rts
+
+; ------------------------------------------------------------------------
+; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+;
+; Must set an error code: NO (will only be called if page ok)
+;
+
+SETVIEWPAGE:
+	rts
+
+; ------------------------------------------------------------------------
+; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
+; The page number is already checked to be valid by the graphics kernel.
+;
+; Must set an error code: NO (will only be called if page ok)
+;
+
+SETDRAWPAGE:
+	rts
+
+; ------------------------------------------------------------------------
+; SETCOLOR: Set the drawing color (in A). The new color is already checked
+; to be in a valid range (0..maxcolor-1).
+;
+; Must set an error code: NO (will only be called if color ok)
+;
+
+SETCOLOR:
+        tax
+        beq     @L1
+        lda     #$FF
+@L1:    sta     BITMASK
+        rts
+
+; ------------------------------------------------------------------------
+; SETPALETTE: Set the palette (not available with all drivers/hardware).
+; A pointer to the palette is passed in ptr1. Must set an error if palettes
+; are not supported
+;
+; Must set an error code: YES
+;
+
+SETPALETTE:
+        ldy     #PALETTESIZE - 1
+@L1:    lda     (ptr1),y        ; Copy the palette
+        and     #$0F            ; Make a valid color
+        sta     PALETTE,y
+        dey
+        bpl     @L1
+
+; Get the color entries from the palette
+
+        ldy     PALETTE+1       ; Foreground color
+	lda	COLTRANS,y
+        asl     a
+        asl     a
+        asl     a
+        asl     a
+        ldy     PALETTE         ; Background color
+	ora	COLTRANS,y
+
+	ldx	#VDC_COLORS
+       	jsr     VDCWriteReg
+        lda     #TGI_ERR_OK     ; Clear error code
+        sta     ERROR
+        rts
+
+; ------------------------------------------------------------------------
+; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
+; set the palette should return the default palette here, so there's no
+; way for this function to fail.
+;
+; Must set an error code: NO
+;
+
+GETPALETTE:
+        lda     #PALETTE
+        rts
+
+; ------------------------------------------------------------------------
+; GETDEFPALETTE: Return the default palette for the driver in A/X. All
+; drivers should return something reasonable here, even drivers that don't
+; support palettes, otherwise the caller has no way to determine the colors
+; of the (not changeable) palette.
+;
+; Must set an error code: NO (all drivers must have a default palette)
+;
+
+GETDEFPALETTE:
+        lda     #DEFPALETTE
+        rts
+
+; ------------------------------------------------------------------------
+; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
+; color. The coordinates passed to this function are never outside the
+; visible screen area, so there is no need for clipping inside this function.
+;
+; Must set an error code: NO
+;
+
+SETPIXEL:
+        jsr     CALC            ; Calculate coordinates
+
+	stx	TEMP
+	lda	ADDR
+	ldy	ADDR+1
+	jsr	VDCSetSourceAddr
+	jsr	VDCReadByte
+	ldx	TEMP
+
+	sta	TEMP
+        eor     BITMASK
+        and     BITTAB,X
+	eor	TEMP
+	pha
+	lda	ADDR
+	ldy	ADDR+1
+	jsr	VDCSetSourceAddr
+	pla
+	jsr	VDCWriteByte
+
+@L9:    rts
+
+; ------------------------------------------------------------------------
+; GETPIXEL: Read the color value of a pixel and return it in A/X. The
+; coordinates passed to this function are never outside the visible screen
+; area, so there is no need for clipping inside this function.
+
+
+GETPIXEL:
+        jsr     CALC            ; Calculate coordinates
+
+	stx	TEMP		; preserve X
+	lda	ADDR
+	ldy	ADDR+1
+	jsr	VDCSetSourceAddr
+	jsr	VDCReadByte
+	ldx	TEMP
+
+        ldy     #$00
+        and     BITTAB,X
+        beq     @L1
+        iny
+
+@L1:    tya                     ; Get color value into A
+        ldx     #$00            ; Clear high byte
+        rts
+
+; ------------------------------------------------------------------------
+; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
+; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
+; Contrary to most other functions, the graphics kernel will sort and clip
+; the coordinates before calling the driver, so on entry the following
+; conditions are valid:
+;       X1 <= X2
+;       Y1 <= Y2
+;       (X1 >= 0) && (X1 < XRES)
+;       (X2 >= 0) && (X2 < XRES)
+;       (Y1 >= 0) && (Y1 < YRES)
+;       (Y2 >= 0) && (Y2 < YRES)
+;
+; Must set an error code: NO
+;
+
+BAR:
+	inc	Y2
+	bne	HORLINE
+	inc	Y2+1
+
+; Original code for a horizontal line
+
+HORLINE:
+	lda X1
+	pha
+	lda X1+1
+	pha
+	jsr CALC		; get data for LEFT
+	lda BITMASKL,x		; remember left address and bitmask
+	pha
+	lda ADDR
+	pha
+	lda ADDR+1
+	pha
+
+	lda X2
+	sta X1
+	lda X2+1
+	sta X1+1
+	jsr CALC		; get data for RIGHT
+	lda BITMASKR,x
+	sta TEMP3
+
+	pla			; recall data for LEFT
+	sta X1+1
+	pla
+	sta X1			; put left address into X1
+	pla
+
+	cmp #%11111111		; if left bit <> 0
+	beq @L1
+	sta TEMP2		; do left byte only...
+	lda X1
+	ldy X1+1
+	jsr VDCSetSourceAddr
+	jsr VDCReadByte
+	sta TEMP
+	eor BITMASK
+	and TEMP2
+	eor TEMP
+	pha
+	lda X1
+	ldy X1+1
+	jsr VDCSetSourceAddr
+	pla
+	jsr VDCWriteByte
+	inc X1			; ... and proceed
+	bne @L1
+	inc X1+1
+
+	; do right byte (if Y2=0 ++ADDR and skip)
+@L1:	lda TEMP3
+	cmp #%11111111		; if right bit <> 7
+	bne @L11
+	inc ADDR		; right bit = 7 - the next one is the last
+	bne @L10
+	inc ADDR+1
+@L10:	bne @L2
+
+@L11:	lda ADDR		; do right byte only...
+	ldy ADDR+1
+	jsr VDCSetSourceAddr
+	jsr VDCReadByte
+	sta TEMP
+	eor BITMASK
+	and TEMP3
+	eor TEMP
+	pha
+	lda ADDR
+	ldy ADDR+1
+	jsr VDCSetSourceAddr
+	pla
+	jsr VDCWriteByte
+
+@L2:				; do the fill in the middle
+	lda ADDR		; calculate offset in full bytes
+	sec
+	sbc X1
+	beq @L3			; if equal - there are no more bytes
+	sta ADDR
+
+	lda X1			; setup for the left side
+	ldy X1+1
+	jsr VDCSetSourceAddr
+	lda BITMASK		; get color
+	jsr VDCWriteByte	; put 1st value
+	ldx ADDR
+	dex
+	beq @L3			; 1 byte already written
+
+	stx ADDR		; if there are more bytes - fill them...
+	ldx #VDC_VSCROLL
+	lda #0
+	jsr VDCWriteReg		; setup for fill
+	ldx #VDC_COUNT
+	lda ADDR
+	jsr VDCWriteReg		; ... fill them NOW!
+
+@L3:	pla
+	sta X1+1
+	pla
+	sta X1
+
+; End of horizontal line code
+
+	inc	Y1
+	bne	@L4
+	inc	Y1+1
+@L4:	lda	Y1
+	cmp	Y2
+	bne	@L5
+	lda	Y1+1
+	cmp	Y2+1
+	bne	@L5
+	rts
+
+@L5:	jmp	HORLINE
+
+
+; ------------------------------------------------------------------------
+; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
+; direction is passend in X/Y, the text direction is passed in A.
+;
+; Must set an error code: NO
+;
+
+TEXTSTYLE:
+        stx     TEXTMAGX
+        sty     TEXTMAGY
+        sta     TEXTDIR
+        rts
+
+
+; ------------------------------------------------------------------------
+; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
+; current text style. The text to output is given as a zero terminated
+; string with address in ptr3.
+;
+; Must set an error code: NO
+;
+
+OUTTEXT:
+        rts
+
+; ------------------------------------------------------------------------
+; Calculate all variables to plot the pixel at X1/Y1.
+;------------------------
+;< X1,Y1 - pixel
+;> ADDR - address of card
+;> X - bit number (X1 & 7)
+CALC:
+	lda	Y1
+	pha
+	lda	Y1+1
+	pha
+	lsr
+	ror	Y1		; Y=Y/2
+	sta	Y1+1
+	sta	ADDR+1
+	lda	Y1
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1		; Y*4
+	clc
+	adc	Y1
+	sta	ADDR
+	lda	Y1+1
+	adc	ADDR+1
+	sta	ADDR+1		; Y*4+Y=Y*5
+	lda	ADDR
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1
+	asl
+	rol	ADDR+1
+	sta	ADDR		; Y*5*16=Y*80
+	lda	X1+1
+	sta	TEMP
+	lda	X1
+	lsr	TEMP
+	ror
+	lsr	TEMP
+	ror
+	lsr	TEMP
+	ror
+	clc
+	adc	ADDR
+	sta	ADDR
+	lda	ADDR+1		; ADDR = Y*80+x/8
+	adc	TEMP
+	sta	ADDR+1
+	pla
+	sta	Y1+1
+	pla
+	sta	Y1
+	and	#1
+	beq	@even		; even line - no offset
+	lda	ADDR
+	clc
+	adc	#<21360
+	sta	ADDR
+	lda	ADDR+1
+	adc	#>21360
+	sta	ADDR+1		; odd lines are 21360 bytes farther
+@even:	lda	X1
+	and	#7
+	tax
+	rts
+
+;-------------
+; VDC helpers
+
+VDCSetSourceAddr:
+	pha
+	tya
+	ldx	#VDC_DATA_HI
+	jsr	VDCWriteReg
+	pla
+	ldx	#VDC_DATA_LO
+	bne	VDCWriteReg
+
+VDCReadByte:
+	ldx	#VDC_DATA
+VDCReadReg:
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	lda	VDC_DATA_REG
+	rts
+
+VDCWriteByte:
+	ldx	#VDC_DATA
+VDCWriteReg:
+	stx	VDC_ADDR_REG
+@L0:	bit	VDC_ADDR_REG
+	bpl	@L0
+	sta	VDC_DATA_REG
+	rts
+
+; ------------------------------------------------------------------------
+
+	.include     	"../../tgi/tgidrv_line.inc"
diff --git a/libsrc/c16/Makefile b/libsrc/c16/Makefile
deleted file mode 100644
index 7eb6ba756..000000000
--- a/libsrc/c16/Makefile
+++ /dev/null
@@ -1,118 +0,0 @@
-#
-# makefile for CC65 runtime library (C16)
-#
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= c16
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I. -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	%.c
-	@$(CC) $(CFLAGS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-ser.o: %.ser
-	@$(CO) -o $(*)-ser.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-ser.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.ser:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-#--------------------------------------------------------------------------
-# Object files
-
-OBJS =	_scrsize.o              \
-        break.o                 \
-        cgetc.o                 \
-        clrscr.o                \
-        color.o                 \
-        conio.o                 \
-        cputc.o                 \
-        crt0.o                  \
-        devnum.o                \
-        get_tv.o                \
-        irq.o                   \
-        joy_stat_stddrv.o       \
-        joy_stddrv.o            \
-        kbhit.o                 \
-        kclose.o                \
-        kernal.o                \
-        mainargs.o              \
-        randomize.o             \
-        revers.o                \
-        status.o                \
-        systime.o               \
-        sysuname.o              \
-        $(EMDS:.emd=-emd.o)     \
-        $(JOYS:.joy=-joy.o)     \
-        $(SERS:.ser=-ser.o)     \
-        $(TGIS:.tgi=-tgi.o)
-
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS = c16-ram.emd
-
-JOYS = c16-stdjoy.joy
-
-SERS =
-
-TGIS =
-
-#--------------------------------------------------------------------------
-# Targets
-
-.PHONY:	all clean zap
-
-all:	$(OBJS) $(EMDS) $(JOYS) $(SERS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(SERS:.ser=.o) $(SERS:.ser=-ser.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(SERS) $(TGIS)
diff --git a/libsrc/c16/c16-ram.s b/libsrc/c16/c16-ram.s
deleted file mode 100644
index 8f879095c..000000000
--- a/libsrc/c16/c16-ram.s
+++ /dev/null
@@ -1,269 +0,0 @@
-;
-; Extended memory driver for the C16 hidden RAM. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2003-12-15
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"em-kernel.inc"
-        .include        "em-error.inc"
-	.include	"plus4.inc"
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BASE   	= $8000
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-pages:          .res    1               ; Number of pages
-curpage:        .res    1               ; Current page number
-window:         .res    256             ; Memory "window"
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-
-; Determine how much memory is available. We will use all memory above
-; $8000 up to MEMTOP
-
-        sec
-        jsr     $FF99			; MEMTOP: Get top memory into Y/X
-        tya
-        sub     #>BASE                  ; Low 32 K are used
-        bcc     nomem
-        beq     nomem                   ; Offering zero pages is a bad idea
-        sta     pages
-
-        ldx     #$FF
-        stx     curpage                 ; Invalidate the current page
-        inx                             ; X = 0
-        txa                             ; A = X = EM_ERR_OK
-        rts
-
-nomem:  ldx     #>EM_ERR_NO_DEVICE
-        lda     #BASE
-        sta	ptr1+1
-        ldy	#$00
-        sty    	ptr1
-
-        lda	#window
-        sta	ptr2+1
-
-; Transfer one page
-
-        jsr     transfer                ; Transfer one page
-
-; Return the memory window
-
-        lda     #window                ; Return the window address
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta     curpage                 ; Remember the page
-        lda     #window                ; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda     curpage			; Get the current page
-        bmi     done                    ; Jump if no page mapped
-
-        add     #>BASE
-        sta	ptr2+1
-        ldy	#$00
-        sty    	ptr2
-
-        lda	#window
-        sta	ptr1+1
-
-; Transfer one page. Y must be zero on entry. Because we bank out the
-; kernal, we will run the routine with interrupts disabled but leave
-; short breath times. Unroll the following loop to make it somewhat faster.
-
-transfer:
-        sei
-        sta     ENABLE_RAM
-
-	.repeat	8
-        lda	(ptr1),y
-        sta	(ptr2),y
-        iny
-	.endrepeat
-
-        sta     ENABLE_ROM
-        cli
-
-        bne     transfer
-
-; Done
-
-done:   rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        sta     ptr3
-        stx     ptr3+1                  ; Save the passed em_copy pointer
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr3),y
-        sta     ptr1
-        ldy     #EM_COPY::PAGE
-        lda     (ptr3),y
-        add     #>BASE
-        sta     ptr1+1                  ; From
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr2
-        iny
-        lda     (ptr3),y
-        sta     ptr2+1                  ; To
-
-common: ldy     #EM_COPY::COUNT+1
-        lda     (ptr3),y                ; Get number of pages
-        beq     @L2                     ; Skip if no full pages
-        sta     tmp1
-
-; Copy full pages allowing interrupts after each page copied
-
-        ldy     #$00
-@L1:    jsr     transfer
-        inc     ptr1+1
-        inc     ptr2+1
-        dec     tmp1
-        bne     @L1
-
-; Copy the remainder of the page
-
-@L2:    ldy     #EM_COPY::COUNT
-        lda     (ptr3),y                ; Get bytes in last page
-        beq     @L4
-        tax
-
-        sei                             ; Disable ints
-        sta     ENABLE_RAM              ; Bank out the ROM
-
-; Transfer the bytes in the last page
-
-        ldy     #$00
-@L3:    lda	(ptr1),y
-        sta	(ptr2),y
-        iny
-        dex
-        bne     @L3
-
-; Restore the old memory configuration, allow interrupts
-
-        sta     ENABLE_ROM
-        cli
-
-; Done
-
-@L4:    rts
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO: sta     ptr3
-        stx     ptr3+1                  ; Save the passed em_copy pointer
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr3),y
-        sta     ptr2
-        ldy     #EM_COPY::PAGE
-        lda     (ptr3),y
-        add     #>BASE
-        sta     ptr2+1                  ; To
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr1
-        iny
-        lda     (ptr3),y
-        sta     ptr1+1                  ; From
-
-        jmp     common
-
-
diff --git a/libsrc/c16/c16-stdjoy.s b/libsrc/c16/c16-stdjoy.s
deleted file mode 100644
index 506ebaa23..000000000
--- a/libsrc/c16/c16-stdjoy.s
+++ /dev/null
@@ -1,9 +0,0 @@
-;
-; Standard joystick driver for the C16. May be used multiple times when linked
-; to the statically application.
-;
-; Ullrich von Bassewitz, 2002-12-21
-;
-
-	.include	"../plus4/plus4-stdjoy.s"
-
diff --git a/libsrc/c16/emd/c16-ram.s b/libsrc/c16/emd/c16-ram.s
new file mode 100644
index 000000000..8f879095c
--- /dev/null
+++ b/libsrc/c16/emd/c16-ram.s
@@ -0,0 +1,269 @@
+;
+; Extended memory driver for the C16 hidden RAM. Driver works without
+; problems when statically linked.
+;
+; Ullrich von Bassewitz, 2003-12-15
+;
+
+	.include 	"zeropage.inc"
+
+      	.include 	"em-kernel.inc"
+        .include        "em-error.inc"
+	.include	"plus4.inc"
+
+        .macpack        generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment        "JUMPTABLE"
+
+; Driver signature
+
+        .byte   $65, $6d, $64           ; "emd"
+        .byte   EMD_API_VERSION		; EM API version number
+
+; Jump table.
+
+        .word   INSTALL
+        .word   UNINSTALL
+        .word   PAGECOUNT
+        .word   MAP
+        .word   USE
+        .word   COMMIT
+	.word	COPYFROM
+        .word   COPYTO
+
+; ------------------------------------------------------------------------
+; Constants
+
+BASE   	= $8000
+
+; ------------------------------------------------------------------------
+; Data.
+
+.bss
+pages:          .res    1               ; Number of pages
+curpage:        .res    1               ; Current page number
+window:         .res    256             ; Memory "window"
+
+.code
+
+; ------------------------------------------------------------------------
+; INSTALL routine. Is called after the driver is loaded into memory. If
+; possible, check if the hardware is present and determine the amount of
+; memory available.
+; Must return an EM_ERR_xx code in a/x.
+;
+
+INSTALL:
+
+; Determine how much memory is available. We will use all memory above
+; $8000 up to MEMTOP
+
+        sec
+        jsr     $FF99			; MEMTOP: Get top memory into Y/X
+        tya
+        sub     #>BASE                  ; Low 32 K are used
+        bcc     nomem
+        beq     nomem                   ; Offering zero pages is a bad idea
+        sta     pages
+
+        ldx     #$FF
+        stx     curpage                 ; Invalidate the current page
+        inx                             ; X = 0
+        txa                             ; A = X = EM_ERR_OK
+        rts
+
+nomem:  ldx     #>EM_ERR_NO_DEVICE
+        lda     #BASE
+        sta	ptr1+1
+        ldy	#$00
+        sty    	ptr1
+
+        lda	#window
+        sta	ptr2+1
+
+; Transfer one page
+
+        jsr     transfer                ; Transfer one page
+
+; Return the memory window
+
+        lda     #window                ; Return the window address
+        rts
+
+; ------------------------------------------------------------------------
+; USE: Tell the driver that the window is now associated with a given page.
+
+USE:    sta     curpage                 ; Remember the page
+        lda     #window                ; Return the window
+        rts
+
+; ------------------------------------------------------------------------
+; COMMIT: Commit changes in the memory window to extended storage.
+
+COMMIT: lda     curpage			; Get the current page
+        bmi     done                    ; Jump if no page mapped
+
+        add     #>BASE
+        sta	ptr2+1
+        ldy	#$00
+        sty    	ptr2
+
+        lda	#window
+        sta	ptr1+1
+
+; Transfer one page. Y must be zero on entry. Because we bank out the
+; kernal, we will run the routine with interrupts disabled but leave
+; short breath times. Unroll the following loop to make it somewhat faster.
+
+transfer:
+        sei
+        sta     ENABLE_RAM
+
+	.repeat	8
+        lda	(ptr1),y
+        sta	(ptr2),y
+        iny
+	.endrepeat
+
+        sta     ENABLE_ROM
+        cli
+
+        bne     transfer
+
+; Done
+
+done:   rts
+
+; ------------------------------------------------------------------------
+; COPYFROM: Copy from extended into linear memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYFROM:
+        sta     ptr3
+        stx     ptr3+1                  ; Save the passed em_copy pointer
+
+        ldy     #EM_COPY::OFFS
+        lda     (ptr3),y
+        sta     ptr1
+        ldy     #EM_COPY::PAGE
+        lda     (ptr3),y
+        add     #>BASE
+        sta     ptr1+1                  ; From
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr3),y
+        sta     ptr2
+        iny
+        lda     (ptr3),y
+        sta     ptr2+1                  ; To
+
+common: ldy     #EM_COPY::COUNT+1
+        lda     (ptr3),y                ; Get number of pages
+        beq     @L2                     ; Skip if no full pages
+        sta     tmp1
+
+; Copy full pages allowing interrupts after each page copied
+
+        ldy     #$00
+@L1:    jsr     transfer
+        inc     ptr1+1
+        inc     ptr2+1
+        dec     tmp1
+        bne     @L1
+
+; Copy the remainder of the page
+
+@L2:    ldy     #EM_COPY::COUNT
+        lda     (ptr3),y                ; Get bytes in last page
+        beq     @L4
+        tax
+
+        sei                             ; Disable ints
+        sta     ENABLE_RAM              ; Bank out the ROM
+
+; Transfer the bytes in the last page
+
+        ldy     #$00
+@L3:    lda	(ptr1),y
+        sta	(ptr2),y
+        iny
+        dex
+        bne     @L3
+
+; Restore the old memory configuration, allow interrupts
+
+        sta     ENABLE_ROM
+        cli
+
+; Done
+
+@L4:    rts
+
+; ------------------------------------------------------------------------
+; COPYTO: Copy from linear into extended memory. A pointer to a structure
+; describing the request is passed in a/x.
+; The function must not return anything.
+;
+
+COPYTO: sta     ptr3
+        stx     ptr3+1                  ; Save the passed em_copy pointer
+
+        ldy     #EM_COPY::OFFS
+        lda     (ptr3),y
+        sta     ptr2
+        ldy     #EM_COPY::PAGE
+        lda     (ptr3),y
+        add     #>BASE
+        sta     ptr2+1                  ; To
+
+        ldy     #EM_COPY::BUF
+        lda     (ptr3),y
+        sta     ptr1
+        iny
+        lda     (ptr3),y
+        sta     ptr1+1                  ; From
+
+        jmp     common
+
+
diff --git a/libsrc/c16/joy/c16-stdjoy.s b/libsrc/c16/joy/c16-stdjoy.s
new file mode 100644
index 000000000..a448f30e8
--- /dev/null
+++ b/libsrc/c16/joy/c16-stdjoy.s
@@ -0,0 +1,9 @@
+;
+; Standard joystick driver for the C16. May be used multiple times when linked
+; to the statically application.
+;
+; Ullrich von Bassewitz, 2002-12-21
+;
+
+	.include	"../../plus4/joy/plus4-stdjoy.s"
+
diff --git a/libsrc/c64/Makefile b/libsrc/c64/Makefile
deleted file mode 100644
index 31ed04282..000000000
--- a/libsrc/c64/Makefile
+++ /dev/null
@@ -1,148 +0,0 @@
-#
-# makefile for CC65 runtime library
-#
-
-.SUFFIXES: .o .s .c
-
-#--------------------------------------------------------------------------
-# Programs and flags
-
-SYS	= c64
-
-AS	= ../../src/ca65/ca65
-CC	= ../../src/cc65/cc65
-CO	= ../../src/co65/co65
-LD	= ../../src/ld65/ld65
-
-AFLAGS	= -t $(SYS) --forget-inc-paths -I../../asminc
-CFLAGS	= -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
-
-#--------------------------------------------------------------------------
-# Rules
-
-%.o:	%.c
-	@$(CC) $(CFLAGS) $<
-	@$(AS) -o $@ $(AFLAGS) $(*).s
-
-%.o:	%.s
-	@$(AS) -g -o $@ $(AFLAGS) $<
-
-%-emd.o: %.emd
-	@$(CO) -o $(*)-emd.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-emd.s
-
-%-joy.o: %.joy
-	@$(CO) -o $(*)-joy.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-joy.s
-
-%-mou.o: %.mou
-	@$(CO) -o $(*)-mou.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-mou.s
-
-%-ser.o: %.ser
-	@$(CO) -o $(*)-ser.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-ser.s
-
-%-tgi.o: %.tgi
-	@$(CO) -o $(*)-tgi.s --code-label _$(subst -,_,$(*)) $<
-	@$(AS) -o $@ $(AFLAGS) $(*)-tgi.s
-
-%.emd:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.joy:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.mou:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.ser:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-%.tgi:	%.o ../runtime/zeropage.o
-	@$(LD) -o $@ -t module $^
-
-#--------------------------------------------------------------------------
-# Object files
-
-OBJS =  _scrsize.o              \
-        break.o                 \
-        crt0.o                  \
-        cgetc.o                 \
-        clrscr.o                \
-        color.o                 \
-        conio.o                 \
-        cputc.o                 \
-        devnum.o                \
-        get_ostype.o            \
-        get_tv.o                \
-        irq.o                   \
-        joy_stat_stddrv.o       \
-        joy_stddrv.o            \
-        kbhit.o                 \
-        kernal.o                \
-        kplot.o                 \
-        mainargs.o              \
-        mcbdefault.o            \
-        mouse_stat_stddrv.o     \
-        mouse_stddrv.o          \
-        randomize.o             \
-        revers.o                \
-        status.o                \
-        systime.o               \
-        sysuname.o              \
-        tgi_colors.o            \
-        tgi_stat_stddrv.o       \
-        tgi_stddrv.o            \
-        $(EMDS:.emd=-emd.o)     \
-        $(JOYS:.joy=-joy.o)     \
-        $(MOUS:.mou=-mou.o)     \
-        $(SERS:.ser=-ser.o)     \
-        $(TGIS:.tgi=-tgi.o)
-
-#--------------------------------------------------------------------------
-# Drivers
-
-EMDS =  c64-c256k.emd           \
-        c64-dqbb.emd            \
-        c64-georam.emd          \
-        c64-isepic.emd          \
-        c64-ram.emd             \
-        c64-ramcart.emd         \
-        c64-reu.emd             \
-        c64-vdc.emd             \
-        dtv-himem.emd
-
-JOYS =  c64-hitjoy.joy          \
-        c64-numpad.joy          \
-        c64-ptvjoy.joy          \
-        c64-stdjoy.joy
-
-MOUS =  c64-1351.mou            \
-        c64-joymouse.mou        \
-        c64-potmouse.mou
-
-SERS =  c64-swlink.ser
-
-TGIS =  c64-320-200-2.tgi
-
-#--------------------------------------------------------------------------
-# Targets
-
-.PHONY:	all clean zap
-
-all:	$(OBJS) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
-
-../runtime/zeropage.o:
-	$(MAKE) -C $(dir $@) $(notdir $@)
-
-clean:
-	@$(RM) $(OBJS) \
-	       $(EMDS:.emd=.o) $(EMDS:.emd=-emd.s) \
-	       $(JOYS:.joy=.o) $(JOYS:.joy=-joy.s) \
-	       $(MOUS:.mou=.o) $(MOUS:.mou=-mou.s) \
-	       $(SERS:.ser=.o) $(SERS:.ser=-ser.s) \
-	       $(TGIS:.tgi=.o) $(TGIS:.tgi=-tgi.s)
-
-zap:	clean
-	@$(RM) $(EMDS) $(JOYS) $(MOUS) $(SERS) $(TGIS)
diff --git a/libsrc/c64/c64-1351.s b/libsrc/c64/c64-1351.s
deleted file mode 100644
index 8dd5c012c..000000000
--- a/libsrc/c64/c64-1351.s
+++ /dev/null
@@ -1,458 +0,0 @@
-;
-; Driver for the 1351 proportional mouse. Parts of the code are from
-; the Commodore 1351 mouse users guide.
-;
-; 2009-09-26, Ullrich von Bassewitz
-; 2010-02-06, Greg King
-;
-; The driver prevents the keyboard from interfering by changing the
-; keyboard's output port into an input port while the driver reads its
-; controller device.  That disables a wire that is left active by the
-; Kernal.  That wire is used by the STOP-key to break out of BASIC
-; programs -- CC65 programs don't use that feature.  The wire is shared
-; by these keys: STOP, "Q", Commodore, Space, "2", CTRL, Left-Arrow, and
-; "1".  I listed them, in order, from bit 7 over to bit 0.  The
-; rightmost five keys can look like joystick switches.
-;
-; The driver prevents the mouse/joystick from interfering by "blinding"
-; the keyboard scanner while any button/switch is active.  It changes
-; the input port into an output port, then stores all zero-bits in that
-; port's latch.  Reading from an output port sees the bitwise-AND of the
-; latch and the input signals.  Therefore, the scanner thinks that eight
-; keys are being pushed at the same time.  It doesn't know what to do
-; about that condition; so, it does nothing.  The driver lets the
-; scanner see normally, again, when no buttons/switches are active.
-;
-
-        .include        "zeropage.inc"
-        .include        "mouse-kernel.inc"
-	.include	"c64.inc"
-
-        .macpack        generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-HEADER:
-
-; Driver signature
-
-        .byte   $6d, $6f, $75           ; "mou"
-        .byte   MOUSE_API_VERSION       ; Mouse driver API version number
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   HIDE
-        .addr   SHOW
-        .addr   SETBOX
-        .addr   GETBOX
-        .addr   MOVE
-        .addr   BUTTONS
-        .addr   POS
-        .addr   INFO
-        .addr   IOCTL
-        .addr   IRQ
-
-; Mouse driver flags
-
-        .byte   MOUSE_FLAG_LATE_IRQ
-
-; Callback table, set by the kernel before INSTALL is called
-
-CHIDE:  jmp     $0000                   ; Hide the cursor
-CSHOW:  jmp     $0000                   ; Show the cursor
-CMOVEX: jmp     $0000                   ; Move the cursor to X coord
-CMOVEY: jmp     $0000                   ; Move the cursor to Y coord
-
-
-;----------------------------------------------------------------------------
-; Constants
-
-SCREEN_HEIGHT   = YSIZE * 8 - 1		; (origin is zero)
-SCREEN_WIDTH    = XSIZE * 8 - 1
-
-;----------------------------------------------------------------------------
-; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the SETBOX and GETBOX routines, so don't
-; reorder them.
-
-.bss
-
-Vars:
-OldPotX:   	.res   	1	     	; Old hw counter values
-OldPotY:	.res   	1
-
-XPos:           .res    2               ; Current mouse position, X
-YPos:           .res    2               ; Current mouse position, Y
-XMin:		.res	2	     	; X1 value of bounding box
-YMin:		.res	2	     	; Y1 value of bounding box
-XMax:		.res	2	     	; X2 value of bounding box
-YMax:		.res	2	     	; Y2 value of bounding box
-Buttons:	.res	1		; button status bits
-
-OldValue:	.res   	1	     	; Temp for MoveCheck routine
-NewValue:	.res   	1	     	; Temp for MoveCheck routine
-
-; Default values for above variables
-
-.rodata
-
-; (We use ".proc" because we want to define both a label and a scope.)
-
-.proc   DefVars
-        .byte   0, 0                    ; OldPotX/OldPotY
-        .word   SCREEN_WIDTH/2          ; XPos
-        .word   SCREEN_HEIGHT/2         ; YPos
-        .word   0                       ; XMin
-        .word   0                       ; YMin
-        .word   SCREEN_WIDTH            ; XMax
-        .word   SCREEN_HEIGHT           ; YMax
-	.byte	%00000000		; Buttons
-.endproc
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an MOUSE_ERR_xx code in a/x.
-
-INSTALL:
-
-; Initialize variables. Just copy the default stuff over
-
-        ldx     #.sizeof(DefVars)-1
-@L1:    lda     DefVars,x
-        sta     Vars,x
-        dex
-        bpl     @L1
-
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
-
-        sei
-        jsr     CHIDE
-        lda     XPos
-        ldx     XPos+1
-        jsr     CMOVEX
-        lda     YPos
-        ldx     YPos+1
-        jsr     CMOVEY
-        cli
-
-; Done, return zero (= MOUSE_ERR_OK)
-
-        ldx     #$00
-        txa
-        rts
-
-;----------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-
-UNINSTALL       = HIDE                  ; Hide cursor on exit
-
-;----------------------------------------------------------------------------
-; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required besides hiding the mouse cursor.
-; No return code required.
-
-HIDE:   sei
-        jsr     CHIDE
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required besides enabling the mouse cursor.
-; No return code required.
-
-SHOW:   sei
-        jsr     CSHOW
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in a/x.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-
-SETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     (ptr1),y
-        sta     XMin,y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in a/x.
-
-GETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-@L1:    lda     XMin,y
-        sta     (ptr1),y
-        dey
-        bpl     @L1
-       	rts
-
-;----------------------------------------------------------------------------
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-;
-
-MOVE:   sei                             ; No interrupts
-
-        sta     YPos
-        stx     YPos+1                  ; New Y position
-        jsr     CMOVEY                  ; Set it
-
-        ldy     #$01
-        lda     (sp),y
-        sta     XPos+1
-        tax
-        dey
-        lda     (sp),y
-        sta     XPos                    ; New X position
-
-        jsr     CMOVEX			; Move the cursor
-
-	cli                             ; Allow interrupts
-       	rts
-
-;----------------------------------------------------------------------------
-; BUTTONS: Return the button mask in a/x.
-
-BUTTONS:
-	lda	Buttons
-        ldx     #0
-     	and	#$1F
-        rts
-
-;----------------------------------------------------------------------------
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-
-POS:    ldy    	#MOUSE_POS::XCOORD      ; Structure offset
-
-	sei	    			; Disable interrupts
-	lda     XPos			; Transfer the position
-	sta	(ptr1),y
-	lda	XPos+1
-	iny
-	sta	(ptr1),y
-      	lda	YPos
-        iny
-        sta     (ptr1),y
-	lda	YPos+1
-	cli	    			; Enable interrupts
-
-        iny
-        sta     (ptr1),y                ; Store last byte
-
-    	rts	    			; Done
-
-;----------------------------------------------------------------------------
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-;
-; We're cheating here to keep the code smaller: The first fields of the
-; mouse_info struct are identical to the mouse_pos struct, so we will just
-; call _mouse_pos to initialize the struct pointer and fill the position
-; fields.
-
-INFO:   jsr	POS
-
-; Fill in the button state
-
-    	jsr     BUTTONS                 ; Will not touch ptr1
-    	ldy	#MOUSE_INFO::BUTTONS
-    	sta	(ptr1),y
-
-      	rts
-
-;----------------------------------------------------------------------------
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an error code in a/x.
-;
-
-IOCTL:  lda     #MOUSE_ERR_INV_IOCTL
-        rts
-
-;----------------------------------------------------------------------------
-; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
-; (so be careful). The routine MUST return carry set if the interrupt has been
-; 'handled' - which means that the interrupt source is gone. Otherwise it
-; MUST return carry clear.
-;
-
-IRQ:
-
-; Record the state of the buttons.
-; Avoid crosstalk between the keyboard and the mouse.
-
-	ldy	#%00000000		; Set ports A and B to input
-	sty	CIA1_DDRB
-	sty	CIA1_DDRA		; Keyboard won't look like mouse
-	lda	CIA1_PRB		; Read Control-Port 1
-	dec	CIA1_DDRA		; Set port A back to output
-	eor	#%11111111		; Bit goes up when button goes down
-	sta	Buttons
-	beq	@L0			;(bze)
-	dec	CIA1_DDRB		; Mouse won't look like keyboard
-	sty	CIA1_PRB		; Set "all keys pushed"
-
-@L0:    lda	SID_ADConv1		; Get mouse X movement
-      	ldy	OldPotX
-      	jsr	MoveCheck  		; Calculate movement vector
-
-; Skip processing if nothing has changed
-
-        bcc     @SkipX
-      	sty	OldPotX
-
-; Calculate the new X coordinate (--> a/y)
-
-       	add	XPos
-      	tay	      			; Remember low byte
-      	txa
-      	adc	XPos+1
-    	tax
-
-; Limit the X coordinate to the bounding box
-
-   	cpy	XMin
-   	sbc	XMin+1
-   	bpl	@L1
-       	ldy    	XMin
-       	ldx	XMin+1
-    	jmp	@L2
-@L1:	txa
-
-    	cpy	XMax
-    	sbc	XMax+1
-    	bmi	@L2
-    	ldy	XMax
-    	ldx	XMax+1
-@L2:	sty	XPos
-   	stx	XPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEX
-
-; Calculate the Y movement vector
-
-@SkipX: lda	SID_ADConv2	 	; Get mouse Y movement
- 	ldy	OldPotY
- 	jsr	MoveCheck	 	; Calculate movement
-
-; Skip processing if nothing has changed
-
-        bcc     @SkipY
- 	sty	OldPotY
-
-; Calculate the new Y coordinate (--> a/y)
-
-      	sta	OldValue
-      	lda	YPos
-      	sub	OldValue
-      	tay
-      	stx	OldValue
-      	lda	YPos+1
-      	sbc	OldValue
-      	tax
-
-; Limit the Y coordinate to the bounding box
-
-   	cpy	YMin
- 	sbc	YMin+1
- 	bpl	@L3
-       	ldy    	YMin
-       	ldx	YMin+1
-    	jmp	@L4
-@L3:	txa
-
-    	cpy	YMax
-    	sbc	YMax+1
-    	bmi	@L4
-    	ldy	YMax
-    	ldx	YMax+1
-@L4:	sty	YPos
- 	stx	YPos+1
-
-; Move the mouse pointer to the new Y pos
-
-        tya
-        jsr     CMOVEY
-
-; Done
-
-        clc                             ; Interrupt not "handled"
-@SkipY: rts
-
-; --------------------------------------------------------------------------
-;
-; Move check routine, called for both coordinates.
-;
-; Entry:   	y = old value of pot register
-;     	   	a = current value of pot register
-; Exit:	   	y = value to use for old value
-;     	   	x/a = delta value for position
-;
-
-MoveCheck:
-      	sty	OldValue
-      	sta	NewValue
-      	ldx 	#$00
-
-      	sub	OldValue	   	; a = mod64 (new - old)
-      	and	#%01111111
-      	cmp	#%01000000	   	; if (a > 0)
-      	bcs	@L1 		   	;
-      	lsr	a   		   	;   a /= 2;
-      	beq	@L2 		   	;   if (a != 0)
-      	ldy   	NewValue     	   	;     y = NewValue
-        sec
-      	rts   	    		   	;   return
-
-@L1:  	ora   	#%11000000	   	; else, "or" in high-order bits
-      	cmp   	#$FF		   	; if (a != -1)
-      	beq   	@L2
-      	sec
-      	ror   	a   		   	;   a /= 2
-       	dex			   	;   high byte = -1 (X = $FF)
-      	ldy   	NewValue
-        sec
-      	rts
-
-@L2:   	txa			   	; A = $00
-        clc
-      	rts
-
diff --git a/libsrc/c64/c64-320-200-2.s b/libsrc/c64/c64-320-200-2.s
deleted file mode 100644
index 8a206341c..000000000
--- a/libsrc/c64/c64-320-200-2.s
+++ /dev/null
@@ -1,960 +0,0 @@
-;
-; Graphics driver for the 320x200x2 mode on the C64.
-;
-; Based on Stephen L. Judds GRLIB code
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"tgi-kernel.inc"
-        .include        "tgi-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table and constants.
-
-.segment        "JUMPTABLE"
-
-; First part of the header is a structure that has a magic and defines the
-; capabilities of the driver
-
-        .byte   $74, $67, $69           ; "tgi"
-        .byte   TGI_API_VERSION         ; TGI API version number
-        .word   320                     ; X resolution
-        .word   200                     ; Y resolution
-        .byte   2                       ; Number of drawing colors
-        .byte   1                       ; Number of screens available
-        .byte   8                       ; System font X size
-        .byte   8                       ; System font Y size
-        .word   $00D4                   ; Aspect ratio (based on 4/3 display)
-        .byte   0                       ; TGI driver flags
-
-; Next comes the jump table. With the exception of IRQ, all entries must be
-; valid and may point to an RTS for test versions (function not implemented).
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   INIT
-        .addr   DONE
-       	.addr   GETERROR
-        .addr   CONTROL
-        .addr   CLEAR
-        .addr   SETVIEWPAGE
-        .addr   SETDRAWPAGE
-        .addr   SETCOLOR
-        .addr   SETPALETTE
-        .addr   GETPALETTE
-        .addr   GETDEFPALETTE
-        .addr   SETPIXEL
-        .addr   GETPIXEL
-        .addr   LINE
-        .addr   BAR
-        .addr   TEXTSTYLE
-        .addr   OUTTEXT
-        .addr   0                       ; IRQ entry is unused
-
-; ------------------------------------------------------------------------
-; Data.
-
-; Variables mapped to the zero page segment variables. Some of these are
-; used for passing parameters to the driver.
-
-X1              := ptr1
-Y1              := ptr2
-X2              := ptr3
-Y2              := ptr4
-TEXT            := ptr3
-
-ROW             := tmp2         ; Bitmap row...
-COL             := tmp3         ; ...and column, both set by PLOT
-TEMP            := tmp4
-TEMP2           := sreg
-POINT           := regsave
-INRANGE         := regsave+2    ; PLOT variable, $00 = coordinates in range
-
-CHUNK           := X2           ; Used in the line routine
-OLDCHUNK        := X2+1         ; Dito
-
-; Absolute variables used in the code
-
-.bss
-
-ERROR:  	.res	1     	; Error code
-PALETTE:        .res    2       ; The current palette
-
-BITMASK:        .res    1       ; $00 = clear, $FF = set pixels
-
-; INIT/DONE
-OLDD018:        .res    1       ; Old register value
-
-; Line routine stuff
-DX:             .res    2
-DY:             .res    2
-
-; BAR variables
-X1SAVE:         .res    2
-Y1SAVE:         .res    2
-X2SAVE:         .res    2
-Y2SAVE:         .res    2
-
-; Text output stuff
-TEXTMAGX:       .res    1
-TEXTMAGY:       .res    1
-TEXTDIR:        .res    1
-
-; Constants and tables
-
-.rodata
-
-DEFPALETTE:     .byte   $00, $01        ; White on black
-PALETTESIZE     = * - DEFPALETTE
-
-BITTAB:         .byte   $80,$40,$20,$10,$08,$04,$02,$01
-BITCHUNK:       .byte   $FF,$7F,$3F,$1F,$0F,$07,$03,$01
-
-CHARROM         := $D000                ; Character rom base address
-CBASE           := $D000                ; Color memory base address
-VBASE  	       	:= $E000                ; Video memory base address
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. May
-; initialize anything that has to be done just once. Is probably empty
-; most of the time.
-;
-; Must set an error code: NO
-;
-
-INSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory. May
-; clean up anything done by INSTALL but is probably empty most of the time.
-;
-; Must set an error code: NO
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; INIT: Changes an already installed device from text mode to graphics
-; mode.
-; Note that INIT/DONE may be called multiple times while the driver
-; is loaded, while INSTALL is only called once, so any code that is needed
-; to initializes variables and so on must go here. Setting palette and
-; clearing the screen is not needed because this is called by the graphics
-; kernel later.
-; The graphics kernel will never call INIT when a graphics mode is already
-; active, so there is no need to protect against that.
-;
-; Must set an error code: YES
-;
-
-INIT:
-
-; Initialize variables
-
-        ldx     #$FF
-        stx     BITMASK
-
-; Switch into graphics mode
-
-        lda     $DD02           ; Set the data direction regs
-        ora     #3
-        sta     $DD02
-        lda     $DD00
-        and     #$FC            ; Switch to bank 3
-        sta     $DD00
-
-        lda     $D018
-        sta     OLDD018
-        lda     #$48         	; Set color map to $D000, screen to $E000
-        sta     $D018
-
-        lda     $D011        	; And turn on bitmap
-        ora     #$20
-DONE1:  sta     $D011
-
-; Done, reset the error code
-
-        lda     #TGI_ERR_OK
-        sta     ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; DONE: Will be called to switch the graphics device back into text mode.
-; The graphics kernel will never call DONE when no graphics mode is active,
-; so there is no need to protect against that.
-;
-; Must set an error code: NO
-;
-
-DONE:   lda     $DD02           ; Set the data direction regs
-        ora     #3
-        sta     $DD02
-        lda     $DD00
-        ora     #$03            ; Bank 0
-        sta     $DD00
-
-        lda     OLDD018         ; Screen mem --> $0400
-        sta     $D018
-
-        lda     $D011
-        and     #<~$20
-        sta     $D011
-        rts
-
-; ------------------------------------------------------------------------
-; GETERROR: Return the error code in A and clear it.
-
-GETERROR:
-       	ldx	#TGI_ERR_OK
-	lda	ERROR
-	stx	ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; CONTROL: Platform/driver specific entry point.
-;
-; Must set an error code: YES
-;
-
-CONTROL:
-	lda	#TGI_ERR_INV_FUNC
-	sta	ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; CLEAR: Clears the screen.
-;
-; Must set an error code: NO
-;
-
-CLEAR:  ldy     #$00
-        tya
-@L1:    sta     VBASE+$0000,y
-        sta     VBASE+$0100,y
-        sta     VBASE+$0200,y
-        sta     VBASE+$0300,y
-        sta     VBASE+$0400,y
-        sta     VBASE+$0500,y
-        sta     VBASE+$0600,y
-        sta     VBASE+$0700,y
-        sta     VBASE+$0800,y
-        sta     VBASE+$0900,y
-        sta     VBASE+$0A00,y
-        sta     VBASE+$0B00,y
-        sta     VBASE+$0C00,y
-        sta     VBASE+$0D00,y
-        sta     VBASE+$0E00,y
-        sta     VBASE+$0F00,y
-        sta     VBASE+$1000,y
-        sta     VBASE+$1100,y
-        sta     VBASE+$1200,y
-        sta     VBASE+$1300,y
-        sta     VBASE+$1400,y
-        sta     VBASE+$1500,y
-        sta     VBASE+$1600,y
-        sta     VBASE+$1700,y
-        sta     VBASE+$1800,y
-        sta     VBASE+$1900,y
-        sta     VBASE+$1A00,y
-        sta     VBASE+$1B00,y
-        sta     VBASE+$1C00,y
-        sta     VBASE+$1D00,y
-        sta     VBASE+$1E00,y
-        sta     VBASE+$1F00,y
-        iny
-        bne     @L1
-        rts
-
-; ------------------------------------------------------------------------
-; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETVIEWPAGE:
-        rts
-
-; ------------------------------------------------------------------------
-; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n).
-; The page number is already checked to be valid by the graphics kernel.
-;
-; Must set an error code: NO (will only be called if page ok)
-;
-
-SETDRAWPAGE:
-        rts
-
-; ------------------------------------------------------------------------
-; SETCOLOR: Set the drawing color (in A). The new color is already checked
-; to be in a valid range (0..maxcolor-1).
-;
-; Must set an error code: NO (will only be called if color ok)
-;
-
-SETCOLOR:
-        tax
-        beq     @L1
-        lda     #$FF
-@L1:    sta     BITMASK
-        rts
-
-; ------------------------------------------------------------------------
-; SETPALETTE: Set the palette (not available with all drivers/hardware).
-; A pointer to the palette is passed in ptr1. Must set an error if palettes
-; are not supported
-;
-; Must set an error code: YES
-;
-
-SETPALETTE:
-        ldy     #PALETTESIZE - 1
-@L1:    lda     (ptr1),y        ; Copy the palette
-        and     #$0F            ; Make a valid color
-        sta     PALETTE,y
-        dey
-        bpl     @L1
-
-; Get the color entries from the palette
-
-        lda     PALETTE+1       ; Foreground color
-        asl     a
-        asl     a
-        asl     a
-        asl     a
-        ora     PALETTE         ; Background color
-        tax
-
-; Initialize the color map with the new color settings (it is below the
-; I/O area)
-
-       	ldy	#$00
-       	sei
-       	lda	$01	     	; Get ROM config
-       	pha	   	     	; Save it
-       	and    	#%11111100      ; Clear bit 0 and 1
-       	sta	$01
-       	txa                     ; Load color code
-@L2:    sta	CBASE+$0000,y
-   	sta	CBASE+$0100,y
-   	sta	CBASE+$0200,y
-   	sta	CBASE+$0300,y
-   	iny
-   	bne	@L2
-   	pla
-   	sta	$01
-  	cli
-
-; Done, reset the error code
-
-        lda     #TGI_ERR_OK
-        sta     ERROR
-        rts
-
-; ------------------------------------------------------------------------
-; GETPALETTE: Return the current palette in A/X. Even drivers that cannot
-; set the palette should return the default palette here, so there's no
-; way for this function to fail.
-;
-; Must set an error code: NO
-;
-
-GETPALETTE:
-        lda     #PALETTE
-        rts
-
-; ------------------------------------------------------------------------
-; GETDEFPALETTE: Return the default palette for the driver in A/X. All
-; drivers should return something reasonable here, even drivers that don't
-; support palettes, otherwise the caller has no way to determine the colors
-; of the (not changeable) palette.
-;
-; Must set an error code: NO (all drivers must have a default palette)
-;
-
-GETDEFPALETTE:
-        lda     #DEFPALETTE
-        rts
-
-; ------------------------------------------------------------------------
-; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing
-; color. The coordinates passed to this function are never outside the
-; visible screen area, so there is no need for clipping inside this function.
-;
-; Must set an error code: NO
-;
-
-SETPIXEL:
-        jsr     CALC            ; Calculate coordinates
-
-        sei                     ; Get underneath ROM
-        lda     $01
-        pha
-        lda     #$34
-        sta     $01
-
-        lda     (POINT),Y
-        eor     BITMASK
-        and     BITTAB,X
-        eor     (POINT),Y
-        sta     (POINT),Y
-
-        pla
-        sta     $01
-        cli
-
-@L9:    rts
-
-; ------------------------------------------------------------------------
-; GETPIXEL: Read the color value of a pixel and return it in A/X. The
-; coordinates passed to this function are never outside the visible screen
-; area, so there is no need for clipping inside this function.
-
-
-GETPIXEL:
-        jsr     CALC            ; Calculate coordinates
-
-        sei                     ; Get underneath ROM
-        lda     $01
-        pha
-        lda     #$34
-        sta     $01
-
-        lda     (POINT),Y
-        ldy     #$00
-        and     BITTAB,X
-        beq     @L1
-        iny
-
-@L1:    pla
-        sta     $01
-        cli
-
-        tya                     ; Get color value into A
-        ldx     #$00            ; Clear high byte
-        rts
-
-; ------------------------------------------------------------------------
-; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and
-; X2/Y2 = ptr3/ptr4 using the current drawing color.
-;
-; To deal with off-screen coordinates, the current row
-; and column (40x25) is kept track of.  These are set
-; negative when the point is off the screen, and made
-; positive when the point is within the visible screen.
-;
-; X1,X2 etc. are set up above (x2=LINNUM in particular)
-; Format is LINE x2,y2,x1,y1
-;
-; Must set an error code: NO
-;
-
-LINE:
-
-@CHECK: lda     X2           ;Make sure x1=y1?
-        lda     Y1           ;Otherwise dy=y1-y2
-        sec
-        sbc     Y2
-        tay
-        ldx     #$88         ;DEY
-
-@DYPOS: sty     DY              ; 8-bit DY -- FIX ME?
-        stx     YINCDEC
-        stx     XINCDEC
-
-        jsr     CALC            ; Set up .X,.Y,POINT, and INRANGE
-        lda     BITCHUNK,X
-        sta     OLDCHUNK
-        sta     CHUNK
-
-        sei                     ; Get underneath ROM
-        lda     #$34
-        sta     $01
-
-        ldx     DY
-        cpx     DX           ;Who's bigger: dy or dx?
-        bcc     STEPINX      ;If dx, then...
-        lda     DX+1
-        bne     STEPINX
-
-;
-; Big steps in Y
-;
-;   To simplify my life, just use PLOT to plot points.
-;
-;   No more!
-;   Added special plotting routine -- cool!
-;
-;   X is now counter, Y is y-coordinate
-;
-; On entry, X=DY=number of loop iterations, and Y=
-;   Y1 AND #$07
-STEPINY:
-        lda     #00
-        sta     OLDCHUNK     ;So plotting routine will work right
-        lda     CHUNK
-        lsr                  ;Strip the bit
-        eor     CHUNK
-        sta     CHUNK
-        txa
-        bne     @CONT        ;If dy=0 it's just a point
-        inx
-@CONT:  lsr                  ;Init counter to dy/2
-;
-; Main loop
-;
-YLOOP:  sta     TEMP
-
-        lda     INRANGE      ;Range check
-        bne     @SKIP
-
-        lda     (POINT),y    ;Otherwise plot
-        eor     BITMASK
-        and     CHUNK
-        eor     (POINT),y
-        sta     (POINT),y
-@SKIP:
-YINCDEC:
-        iny                  ;Advance Y coordinate
-        cpy     #8
-        bcc     @CONT        ;No prob if Y=0..7
-        jsr     FIXY
-@CONT:  lda     TEMP         ;Restore A
-        sec
-        sbc     DX
-        bcc     YFIXX
-YCONT:  dex                  ;X is counter
-        bne     YLOOP
-YCONT2: lda     (POINT),y    ;Plot endpoint
-        eor     BITMASK
-        and     CHUNK
-        eor     (POINT),y
-        sta     (POINT),y
-YDONE:  lda     #$36
-        sta     $01
-        cli
-        rts
-
-YFIXX:                    ;x=x+1
-        adc     DY
-        lsr     CHUNK
-        bne     YCONT        ;If we pass a column boundary...
-        ror     CHUNK        ;then reset CHUNK to $80
-        sta     TEMP2
-        lda     COL
-        bmi     @C1          ;Skip if column is negative
-        cmp     #39          ;End if move past end of screen
-        bcs     YDONE
-@C1:    lda     POINT        ;And add 8 to POINT
-        adc     #8
-        sta     POINT
-        bcc     @CONT
-        inc     POINT+1
-@CONT:  inc     COL          ;Increment column
-        bne     @C2
-        lda     ROW          ;Range check
-        cmp     #25
-        bcs     @C2
-        lda     #00          ;Passed into col 0
-        sta     INRANGE
-@C2:    lda     TEMP2
-        dex
-        bne     YLOOP
-        beq     YCONT2
-
-;
-; Big steps in X direction
-;
-; On entry, X=DY=number of loop iterations, and Y=
-;   Y1 AND #$07
-
-.bss
-COUNTHI:
-        .byte   $00       ;Temporary counter
-                          ;only used once
-.code
-STEPINX:
-        ldx     DX
-        lda     DX+1
-        sta     COUNTHI
-        cmp     #$80
-        ror                  ;Need bit for initialization
-        sta     Y1           ;High byte of counter
-        txa
-        bne     @CONT        ;Could be $100
-        dec     COUNTHI
-@CONT:  ror
-;
-; Main loop
-;
-XLOOP:  lsr     CHUNK
-        beq     XFIXC        ;If we pass a column boundary...
-XCONT1: sbc     DY
-        bcc     XFIXY        ;Time to step in Y?
-XCONT2: dex
-        bne     XLOOP
-        dec     COUNTHI      ;High bits set?
-        bpl     XLOOP
-
-XDONE:  lsr     CHUNK        ;Advance to last point
-        jsr     LINEPLOT     ;Plot the last chunk
-EXIT:   lda     #$36
-        sta     $01
-        cli
-        rts
-;
-; CHUNK has passed a column, so plot and increment pointer
-; and fix up CHUNK, OLDCHUNK.
-;
-XFIXC:  sta     TEMP
-        jsr     LINEPLOT
-        lda     #$FF
-        sta     CHUNK
-        sta     OLDCHUNK
-        lda     COL
-        bmi     @C1          ;Skip if column is negative
-        cmp     #39          ;End if move past end of screen
-        bcs     EXIT
-@C1:  	lda     POINT
-        adc     #8
-        sta     POINT
-        bcc     @CONT
-        inc     POINT+1
-@CONT:  inc     COL
-        bne     @C2
-        lda     ROW
-        cmp     #25
-        bcs     @C2
-        lda     #00
-        sta     INRANGE
-@C2:    lda     TEMP
-        sec
-        bcs     XCONT1
-;
-; Check to make sure there isn't a high bit, plot chunk,
-; and update Y-coordinate.
-;
-XFIXY:  dec     Y1           ;Maybe high bit set
-        bpl     XCONT2
-        adc     DX
-        sta     TEMP
-        lda     DX+1
-        adc     #$FF         ;Hi byte
-        sta     Y1
-
-        jsr     LINEPLOT     ;Plot chunk
-        lda     CHUNK
-        sta     OLDCHUNK
-
-        lda     TEMP
-XINCDEC:
-        iny                  ;Y-coord
-        cpy     #8           ;0..7 is ok
-        bcc     XCONT2
-        sta     TEMP
-        jsr     FIXY
-        lda     TEMP
-        jmp     XCONT2
-
-;
-; Subroutine to plot chunks/points (to save a little
-; room, gray hair, etc.)
-;
-LINEPLOT:                       ; Plot the line chunk
-        lda     INRANGE
-        bne     @SKIP
-
-        lda     (POINT),Y       ; Otherwise plot
-        eor     BITMASK
-        ora     CHUNK
-        and     OLDCHUNK
-        eor     CHUNK
-        eor     (POINT),Y
-        sta     (POINT),Y
-@SKIP:  rts
-
-;
-; Subroutine to fix up pointer when Y decreases through
-; zero or increases through 7.
-;
-FIXY:   cpy     #255         ;Y=255 or Y=8
-        beq     @DECPTR
-@INCPTR:                     ;Add 320 to pointer
-        ldy     #0           ;Y increased through 7
-        lda     ROW
-        bmi     @C1          ;If negative, then don't update
-        cmp     #24
-        bcs     @TOAST       ;If at bottom of screen then quit
-@C1:   	lda     POINT
-        adc     #<320
-        sta     POINT
-        lda     POINT+1
-        adc     #>320
-        sta     POINT+1
-@CONT1: inc     ROW
-        bne     @DONE
-        lda     COL
-        bpl     @CLEAR
-@DONE:  rts
-
-@DECPTR:                     ;Okay, subtract 320 then
-        ldy     #7           ;Y decreased through 0
-        lda     POINT
-        sec
-        sbc     #<320
-        sta     POINT
-        lda     POINT+1
-        sbc     #>320
-        sta     POINT+1
-@CONT2: dec     ROW
-        bmi     @TOAST
-        lda     ROW
-        cmp     #24
-        bne     @DONE
-        lda     COL
-        bmi     @DONE
-@CLEAR: lda     #00
-        sta     INRANGE
-        rts
-
-@TOAST: pla                  ;Remove old return address
-        pla
-        jmp     EXIT         ;Restore interrupts, etc.
-
-; ------------------------------------------------------------------------
-; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where
-; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color.
-; Contrary to most other functions, the graphics kernel will sort and clip
-; the coordinates before calling the driver, so on entry the following
-; conditions are valid:
-;       X1 <= X2
-;       Y1 <= Y2
-;       (X1 >= 0) && (X1 < XRES)
-;       (X2 >= 0) && (X2 < XRES)
-;       (Y1 >= 0) && (Y1 < YRES)
-;       (Y2 >= 0) && (Y2 < YRES)
-;
-; Must set an error code: NO
-;
-
-; Note: This function needs optimization. It's just a cheap translation of
-; the original C wrapper and could be written much smaller (besides that,
-; calling LINE is not a good idea either).
-
-BAR:	lda     Y2
-        sta     Y2SAVE
-        lda     Y2+1
-        sta     Y2SAVE+1
-
-        lda     X2
-        sta     X2SAVE
-        lda     X2+1
-        sta     X2SAVE+1
-
-        lda     Y1
-        sta     Y1SAVE
-        lda     Y1+1
-        sta     Y1SAVE+1
-
-        lda     X1
-        sta     X1SAVE
-        lda     X1+1
-        sta     X1SAVE+1
-
-@L1:	lda     Y1
-        sta     Y2
-        lda     Y1+1
-        sta     Y2+1
-	jsr     LINE
-
-        lda     Y1SAVE
-        cmp     Y2SAVE
-        bne     @L2
-        lda     Y1SAVE
-        cmp     Y2SAVE
-        beq     @L4
-
-@L2:    inc     Y1SAVE
-        bne     @L3
-        inc     Y1SAVE+1
-
-@L3:    lda     Y1SAVE
-        sta     Y1
-        lda     Y1SAVE+1
-        sta     Y1+1
-
-        lda     X1SAVE
-        sta     X1
-        lda     X1SAVE+1
-        sta     X1+1
-
-        lda     X2SAVE
-        sta     X2
-        lda     X2SAVE+1
-        sta     X2+1
-        jmp     @L1
-
-@L4:    rts
-
-
-; ------------------------------------------------------------------------
-; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y
-; direction is passend in X/Y, the text direction is passed in A.
-;
-; Must set an error code: NO
-;
-
-TEXTSTYLE:
-        stx     TEXTMAGX
-        sty     TEXTMAGY
-        sta     TEXTDIR
-        rts
-
-
-; ------------------------------------------------------------------------
-; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the
-; current text style. The text to output is given as a zero terminated
-; string with address in ptr3.
-;
-; Must set an error code: NO
-;
-
-OUTTEXT:
-
-; Calculate a pointer to the representation of the character in the
-; character ROM 
-
-        ldx     #((>(CHARROM + $0800)) >> 3)
-        ldy     #0
-        lda     (TEXT),y
-        bmi     @L1
-        ldx     #((>(CHARROM + $0000)) >> 3)
-@L1:    stx     ptr4+1
-        asl     a
-        rol     ptr4+1
-        asl     a
-        rol     ptr4+1
-        asl     a
-        rol     ptr4+1
-        sta     ptr4
-
-
-
-
-
-        rts
-
-; ------------------------------------------------------------------------
-; Calculate all variables to plot the pixel at X1/Y1. If the point is out
-; of range, a carry is returned and INRANGE is set to a value !0 zero. If
-; the coordinates are valid, INRANGE is zero and the carry clear.
-
-CALC:   lda     Y1
-        sta     ROW
-        and     #7
-        tay
-        lda     Y1+1
-        lsr                     ; Neg is possible
-        ror     ROW
-        lsr
-        ror     ROW
-        lsr
-        ror     ROW
-
-        lda     #00
-        sta     POINT
-        lda     ROW
-        cmp     #$80
-        ror
-        ror     POINT
-        cmp     #$80
-        ror
-        ror     POINT           ; row*64
-        adc     ROW             ; +row*256
-        clc
-        adc     #>VBASE         ; +bitmap base
-        sta     POINT+1
-
-        lda     X1
-        tax
-        sta     COL
-        lda     X1+1
-        lsr
-        ror     COL
-        lsr
-        ror     COL
-        lsr
-        ror     COL
-
-        txa
-        and     #$F8
-        clc
-        adc     POINT           ; +(X AND #$F8)
-        sta     POINT
-        lda     X1+1
-        adc     POINT+1
-        sta     POINT+1
-        txa
-        and     #7
-        tax
-
-        lda     ROW
-        cmp     #25
-        bcs     @L9
-        lda     COL
-        cmp     #40
-        bcs     @L9
-        lda     #00
-@L9:    sta     INRANGE
-        rts
-
-
diff --git a/libsrc/c64/c64-c256k.s b/libsrc/c64/c64-c256k.s
deleted file mode 100755
index ed8bf7732..000000000
--- a/libsrc/c64/c64-c256k.s
+++ /dev/null
@@ -1,502 +0,0 @@
-;
-; Extended memory driver for the C256K memory expansion
-; Marco van den Heuvel, 2010-01-27
-;
-
-        .include	"zeropage.inc"
-
-        .include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack	generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte	$65, $6d, $64		; "emd"
-        .byte	EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word	INSTALL
-        .word	UNINSTALL
-        .word	PAGECOUNT
-        .word	MAP
-        .word	USE
-        .word	COMMIT
-        .word	COPYFROM
-        .word	COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BASE                    = $4000
-PAGES                   = 3 * 256
-TARGETLOC               = $200          ; Target location for copy/check code
-PIA                     = $DFC0
-
-; ------------------------------------------------------------------------
-; Data.
-
-.data
-
-
-; This function is used to copy code from and to the extended memory
-.proc   copy
-template:
-.org    ::TARGETLOC             ; Assemble for target location
-entry:
-        stx     PIA
-stashop         = $91           ; 'sta' opcode
-operation       := *            ; Location and opcode is patched at runtime
-address         := *+1
-        lda     ($00),y
-        ldx     #$dc
-        stx     PIA
-        rts
-.reloc
-.endproc
-
-; This function is used to check for the existence of the extended memory
-.proc   check
-template:
-.org    ::TARGETLOC
-entry:
-        ldy     #$00            ; Assume hardware not present
-
-        lda     #$fc
-        sta     PIA
-        lda     $01
-        tax
-        and     #$f8
-        sta     $01
-        lda     $4000
-        cmp     $c000
-        bne     done            ; Jump if not found
-        inc     $c000
-        cmp     $4000
-        beq     done            ; Jump if not found
-
-        ; Hardware is present
-        iny
-done:   stx     $01
-        ldx     #$dc
-        stx     PIA
-        rts
-.reloc
-.endproc
-
-
-
-.bss
-
-curpage:        .res   	2       ; Current page number
-curbank:        .res	1	; Current bank
-window:         .res   	256    	; Memory "window"
-
-; Since the functions above are copied to $200, the current contents of this
-; memory area must be saved into backup storage. Allocate enough space.
-backup:         .res   	.max (.sizeof (copy), .sizeof (check))
-
-
-
-.code
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda	PIA+1		; Select Peripheral Registers
-        ora	#4
-        sta	PIA+1
-        tax
-        lda	PIA+3
-        ora	#4
-        sta	PIA+3
-        tay
-
-        lda	#$DC		; Set the default memory bank data
-        sta	PIA
-        lda	#$FE
-        sta	PIA+2
-
-        txa			; Select Data Direction Registers
-        and	#$FB
-        sta	PIA+1
-        tya
-        and	#$FB
-        sta	PIA+3
-
-        lda	#$FF		; Set the ports to output
-        sta	PIA
-        sta	PIA+2
-
-        txa
-        and	#$C7
-        ora	#$30		; Set CA1 and
-        sta	PIA+1		; select Peripheral Registers
-        sty	PIA+3
-
-        jsr	backup_and_setup_check_routine
-        jsr	check::entry
-        cli
-        ldx	#.sizeof (check) - 1
-        jsr	restore_data
-        cpy	#$01
-        beq	@present
-        lda	#EM_ERR_NO_DEVICE
-        rts
-
-@present:
-        lda	#EM_ERR_OK
-;       rts		  	; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda	#PAGES
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:
-        sei
-        sta	curpage	  	; Remember the new page
-        stx	curpage+1
-        jsr	adjust_page_and_bank
-        stx	curbank
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#0
-        sty	ptr1
-        jsr	backup_and_setup_copy_routine
-        ldx	#window      		; Return the window address
-        cli
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta	curpage	      	; Remember the page
-        stx	curpage+1
-        lda	#window      		; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT:
-        sei
-        lda	curpage	      	; Get the current page
-        ldx	curpage+1
-
-        jsr	adjust_page_and_bank
-        stx	curbank
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#0
-        sty	ptr1
-        jsr	backup_and_setup_copy_routine
-        ldx	#BASE
-        sta	ptr4+1
-        lda	tmp2
-        clc
-        adc	#$10
-        sta	tmp2
-        jmp	@L3
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        sei
-        jsr	setup
-        jsr	backup_and_setup_copy_routine
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - ptr4 contains the page memory buffer plus offset
-;   - tmp1 contains zero (to be used for linear memory buffer offset)
-;   - tmp2 contains the bank value
-
-        lda	#BASE
-        sta  	ptr4+1
-        lda  	tmp2
-        clc
-        adc  	#$10
-        sta  	tmp2
-        jmp  	@L3
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-
-setup:
-        sta	ptr1
-        stx	ptr1+1	      				; Save passed pointer
-
-; Get the page number from the struct and adjust it so that it may be used
-; with the hardware. That is: ptr4 has the page address and page offset
-; tmp2 will hold the bank value
-
-        ldy	#EM_COPY::PAGE+1
-        lda	(ptr1),y
-        tax
-        ldy	#EM_COPY::PAGE
-        lda	(ptr1),y
-        jsr	adjust_page_and_bank
-        clc
-        adc	#>BASE
-        sta	ptr4+1
-        stx	tmp2
-
-; Get the buffer pointer into ptr2
-
-        ldy	#EM_COPY::BUF
-        lda	(ptr1),y
-        sta	ptr2
-        iny
-        lda	(ptr1),y
-        sta	ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy	#EM_COPY::COUNT
-        lda	(ptr1),y
-        eor	#$FF
-        sta	ptr3
-        iny
-        lda	(ptr1),y
-        eor	#$FF
-        sta	ptr3+1
-
-; Get the page offset into ptr4 and clear tmp1
-
-        ldy	#EM_COPY::OFFS
-        lda	(ptr1),y
-        sta	ptr4
-        lda	#0
-        sta	tmp1
-
-; Done
-
-        rts
-
-; Helper routines for copying to and from the +256k ram
-
-backup_and_setup_copy_routine:
-        ldx	#.sizeof (copy) - 1
-@L1:
-        lda    	copy::entry,x
-        sta	backup,x
-        lda	copy::template,x
-        sta	copy::entry,x
-        dex
-        bpl	@L1
-        rts
-
-backup_and_setup_check_routine:
-        ldx	#.sizeof (check) - 1
-@L1:
-        lda	check::entry,x
-        sta	backup,x
-        lda	check::template,x
-        sta	check::entry,x
-        dex
-        bpl	@L1
-        rts
-
-restore_copy_routine:
-        ldx	#.sizeof (copy) - 1
-restore_data:
-        lda	backup,x
-        sta	TARGETLOC,x
-        dex
-        bpl	restore_data
-        rts
-
-; Helper routine to correct for the bank and page
-adjust_page_and_bank:
-        sta	tmp4
-        lda	#$0C
-        sta     tmp3
-        lda	tmp4
-        and	#$c0
-        lsr
-        lsr
-        ora	tmp3
-        sta	tmp3
-        txa
-        asl
-        asl
-        asl
-        asl
-        asl
-        asl
-        ora	tmp3
-        tax
-        lda	tmp4
-        and	#$3f
-        rts
diff --git a/libsrc/c64/c64-dqbb.s b/libsrc/c64/c64-dqbb.s
deleted file mode 100755
index 3f581e11a..000000000
--- a/libsrc/c64/c64-dqbb.s
+++ /dev/null
@@ -1,441 +0,0 @@
-;
-; Extended memory driver for the Double Quick Brown Box cartridge
-; Marco van den Heuvel, 2010-01-27
-;
-
-        .include	"zeropage.inc"
-
-        .include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack	generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte	$65, $6d, $64		; "emd"
-        .byte	EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word	INSTALL
-        .word	UNINSTALL
-        .word	PAGECOUNT
-        .word	MAP
-        .word	USE
-        .word	COMMIT
-        .word	COPYFROM
-        .word	COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BASE                    = $8000
-PAGES                   = ($C000 - BASE) / 256
-TARGETLOC               = $200          ; Target location for copy/check code
-CONTROL                 = $DE00
-
-; ------------------------------------------------------------------------
-; Data.
-
-.proc   check
-template:
-.org    ::TARGETLOC             ; Assemble for target location
-entry:
-        lda     $01
-        pha
-        lda     #$37
-        sta     $01
-        ldx     #$14
-        ldy     #$90
-        sty     CONTROL
-        lda     $8000
-        stx     CONTROL
-        cmp     $8000
-        bne     present
-        sty     CONTROL
-        inc     $8000
-        stx     CONTROL
-        cmp     $8000
-        beq     present
-        dec     $8000
-        ldy     #$00
-
-done:   pla
-        sta     $01
-        rts
-
-present:
-        sty     CONTROL
-        ldy     #$01
-        bne     done
-.reloc
-.endproc
-
-
-.proc   copy
-template:
-.org    ::TARGETLOC             ; Assemble for target location
-entry:
-.proc   fetch
-        stx     CONTROL
-        ldx     $01
-        lda     #$37
-        sta     $01
-address         := *+1          ; Patched at runtime
-        lda     ($00),y
-        stx     $01
-        ldx     #$90
-        stx     CONTROL
-        rts
-.endproc
-
-.proc   stash
-        stx     CONTROL
-        ldx     $01
-        ldy     #$37
-        sty     $01
-        ldy     #$00
-address         := *+1          ; Patched at runtime
-        sta     ($00),y
-        stx     $01
-        ldx     #$90
-        stx     CONTROL
-        rts
-.endproc
-.reloc
-.endproc
-
-
-.bss
-
-curpage:        .res	1      		; Current page number
-window:         .res	256		; Memory "window"
-
-; Since the functions above are copied to $200, the current contents of this
-; memory area must be saved into backup storage. Allocate enough space.
-backup:         .res   	.max (.sizeof (copy), .sizeof (check))
-
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        sei
-        jsr	backup_and_setup_check_routine
-        jsr	check::entry
-        cli
-        ldx	#.sizeof (check) - 1
-        jsr	restore_data
-        cpy	#$01
-        beq	@present
-        lda	#EM_ERR_NO_DEVICE
-        rts
-
-@present:
-        lda	#EM_ERR_OK
-;       rts		    	; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda	#PAGES
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:
-        sei
-        sta 	curpage		; Remember the new page
-        clc
-        adc 	#>BASE
-        sta 	ptr1+1
-        ldy 	#0
-        sty 	ptr1
-        jsr 	backup_and_setup_copy_routine
-        ldx 	#window	    	; Return the window address
-        cli
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta	curpage		; Remember the page
-        lda	#window		; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT:
-        sei
-        lda	curpage		; Get the current page
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#0
-        sty	ptr1
-        jsr	backup_and_setup_copy_routine
-        ldx   	#BASE
-        sta	ptr4+1
-
-; Get the buffer pointer into ptr2
-
-        ldy	#EM_COPY::BUF
-        lda	(ptr1),y
-        sta	ptr2
-        iny
-        lda	(ptr1),y
-        sta	ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy	#EM_COPY::COUNT
-        lda	(ptr1),y
-        eor	#$FF
-        sta	ptr3
-        iny
-        lda	(ptr1),y
-        eor	#$FF
-        sta	ptr3+1
-
-; Get the page offset into ptr4 and clear tmp1
-
-        ldy	#EM_COPY::OFFS
-        lda	(ptr1),y
-        sta	ptr4
-        lda	#0
-        sta	tmp1
-
-; Done
-
-        rts
-
-; Helper routines for copying to and from the +256k ram
-
-backup_and_setup_copy_routine:
-        ldx	#.sizeof (copy) - 1
-@L1:
-        lda	copy::entry,x
-        sta	backup,x
-        lda	copy::template,x
-        sta	copy::entry,x
-        dex
-        bpl	@L1
-        rts
-
-backup_and_setup_check_routine:
-        ldx	#.sizeof (check) - 1
-@L1:
-        lda	check::entry,x
-        sta	backup,x
-        lda	check::template,x
-        sta	check::entry,x
-        dex
-        bpl	@L1
-        rts
-
-restore_copy_routine:
-        ldx	#.sizeof (copy) - 1
-restore_data:
-        lda	backup,x
-        sta	TARGETLOC,x
-        dex
-        bpl	restore_data
-        rts
diff --git a/libsrc/c64/c64-georam.s b/libsrc/c64/c64-georam.s
deleted file mode 100644
index 5b1f64b8c..000000000
--- a/libsrc/c64/c64-georam.s
+++ /dev/null
@@ -1,349 +0,0 @@
-;
-; Extended memory driver for the GEORAM cartridge. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2002-11-29
-;
-; GEORAM page size checking routine by
-; Marco van den Heuvel, 2010-01-21
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"em-kernel.inc"
-        .include        "em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-GR_WINDOW       = $DE00                 ; Address of GEORAM window
-GR_PAGE_LO      = $DFFE                 ; Page register low
-GR_PAGE_HI      = $DFFF                 ; Page register high
-
-; ------------------------------------------------------------------------
-; Data.
-
-.data
-
-pagecount:      .res    2               ; Number of available pages
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-       	ldx     GR_WINDOW
-        cpx     GR_WINDOW
-        bne     @notpresent
-        inc     GR_WINDOW
-       	cpx     GR_WINDOW
-       	beq     @notpresent
-
-       	lda     #4
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has64k
-       	lda     #8
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has128k
-       	lda     #16
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has256k
-       	lda     #32
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has512k
-       	lda     #64
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has1024k
-       	lda     #128
-       	jsr     check
-       	cpy     GR_WINDOW
-       	beq     @has2048k
-       	ldx     #>16384
-        bne     @setok
-
-@has64k:
-       	ldx     #>256
-       	bne     @setok
-@has128k:
-       	ldx     #>512
-       	bne     @setok
-@has256k:
-       	ldx     #>1024
-       	bne     @setok
-@has512k:
-       	ldx     #>2048
-       	bne     @setok
-@has1024k:
-       	ldx     #>4096
-       	bne     @setok
-@has2048k:
-       	ldx     #>8192
-       	bne     @setok
-
-@notpresent:
-       	lda     #EM_ERR_NO_DEVICE
-	rts
-
-@setok:
-       	lda     #0
-       	sta     pagecount
-       	stx     pagecount+1
-       	lda     #EM_ERR_OK
-	rts
-
-check:
-       	ldx     #0
-       	stx     GR_PAGE_LO
-       	stx     GR_PAGE_HI
-       	ldy     GR_WINDOW
-       	iny
-       	sta     GR_PAGE_HI
-       	sty     GR_WINDOW
-       	ldx     #0
-       	stx     GR_PAGE_HI
-;	rts                     ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-; The GeoRAM cartridge does not copy but actually map the window, so USE is
-; identical to MAP.
-
-USE     = MAP
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta     tmp1
-        txa
-        asl     tmp1
-        rol     a
-        asl     tmp1
-        rol     a
-
-        sta     GR_PAGE_HI
-        lda     tmp1
-        lsr     a
-        lsr     a
-        sta     GR_PAGE_LO
-
-        lda     #GR_WINDOW
-
-; Use the RTS from COMMIT below to save a precious byte of storage
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     GR_WINDOW,x
-        sta     (ptr2),y
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:    inc     tmp1            ; Bump low page register
-        bit     tmp1            ; Check for overflow in bit 6
-        bvc     @L6             ; Jump if no overflow
-        inc     tmp2
-@L5:    lda     tmp2
-        sta     GR_PAGE_HI
-@L6:    lda     tmp1
-        sta     GR_PAGE_LO
-        jmp     @L3
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     (ptr2),y
-        sta     GR_WINDOW,x
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:    inc     tmp1            ; Bump low page register
-        bit     tmp1            ; Check for overflow in bit 6
-        bvc     @L6             ; Jump if no overflow
-        inc     tmp2
-@L5:    lda     tmp2
-        sta     GR_PAGE_HI
-@L6:    lda     tmp1
-        sta     GR_PAGE_LO
-        jmp     @L3
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-
-setup:  sta     ptr1
-        stx     ptr1+1          ; Save passed pointer
-
-; Get the page number from the struct and adjust it so that it may be used
-; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
-
-        ldy     #EM_COPY::PAGE+1
-        lda     (ptr1),y
-        sta     tmp2
-        dey
-        lda     (ptr1),y
-        asl     a
-        rol     tmp2
-        asl     a
-        rol     tmp2
-        lsr     a
-        lsr     a
-        sta     tmp1
-
-; Get the buffer pointer into ptr2
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr1),y
-        sta     ptr2
-        iny
-        lda     (ptr1),y
-        sta     ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy     #EM_COPY::COUNT
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3
-        iny
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3+1
-
-; Get the page offset into X and clear Y
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr1),y
-        tax
-        ldy     #$00
-
-; Done
-
-        rts
-
-
diff --git a/libsrc/c64/c64-hitjoy.s b/libsrc/c64/c64-hitjoy.s
deleted file mode 100755
index ae09182dc..000000000
--- a/libsrc/c64/c64-hitjoy.s
+++ /dev/null
@@ -1,223 +0,0 @@
-;
-; DXS/HIT-4 Player joystick driver for the C64
-;
-; Groepaz/Hitmen, 2002-12-23
-; obviously based on Ullrichs driver :)
-;
-
-        .include "zeropage.inc"
-
-        .include "joy-kernel.inc"
-        .include "joy-error.inc"
-        .include "c64.inc"
-
-        .macpack generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-        .segment "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $6A, $6F, $79	; "joy"
-        .byte   JOY_API_VERSION	; Driver API version number
-
-; Button state masks (8 values)
-
-        .byte   $01                     ; JOY_UP
-        .byte   $02                     ; JOY_DOWN
-        .byte   $04                     ; JOY_LEFT
-        .byte   $08                     ; JOY_RIGHT
-        .byte   $10                     ; JOY_FIRE
-        .byte   $00                     ; JOY_FIRE2 unavailable
-        .byte   $00                     ; Future expansion
-        .byte   $00                     ; Future expansion
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   COUNT
-        .addr   READ
-        .addr   IRQ
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT       = 4             ; Number of joysticks we support
-
-; ------------------------------------------------------------------------
-; Data. Written in the IRQ, read by the READ routine
-
-.bss
-
-temp3: 	.byte 0
-temp4:	.byte 0
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda     #JOY_ERR_OK
-
-;       rts             ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-; ------------------------------------------------------------------------
-; IRQ entry point. Is called from the C layer as a subroutine in the
-; interrupt. The routine MUST return carry set if the interrupt has been
-; 'handled' - which means that the interrupt source is gone. Otherwise it
-; MUST return carry clear.
-
-IRQ:    ; cia 2 setup
-
-        ldy     #$00            ; port b direction
-        sty     $dd03           ; => input
-
-        sty     $dd05           ; cia2 timer a highbyte
-        sty     $dc05           ; cia1 timer a highbyte
-        iny
-        sty     $dd04           ; cia2 timer a lowbyte
-        sty     $dc04           ; cia1 timer a lowbyte
-
-        lda     #%00010001
-        sta     $dd0e           ; control register a
-                                ; timer: start
-                                ;        continous
-                                ;        forced load
-                                ; serial port: input
-
-        ; cia 1 setup
-        lda     #%01010001
-        sta     $dc0e           ; control register a
-                                ; timer: start
-                                ;        continous
-                                ;        forced load
-                                ; serial port: output
-
-        ; read directions 3
-        lda     $dd01           ;read cia 2 port b
-        and     #$0f
-        sta     temp3
-
-        ; read button 3
-        lda     $dd02           ;cia 2 port a
-        and     #%11111011      ;data direction
-        sta     $dd02           ;=> bit 2 input
-
-        lda     $dd00           ;read cia 2 p.A
-        and     #%00000100      ;check bit 2
-        asl     a
-        asl     a
-        ora     temp3
-        sta     temp3
-
-        ; read directions 4
-        lda     $dd01           ;read cia 2 port b
-        lsr     a
-        lsr     a
-        lsr     a
-        lsr     a
-        sta     temp4
-
-        ; read button 4
-        ldx     #$ff            ;serial data register
-        stx     $dc0c           ;=> writing $ff causes
-                                ;cia to output some
-                                ;count signals at cnt1
-
-        ldx     $dd0c           ;read cia 2 serial in
-        beq     fire            ;button press if zero
-
-        lda     temp4
-        ora     #%00010000
-        sta     temp4
-
-fire:
-        ; Default Value: $40/64 on PAL
-        ;                    $42/66 on NTSC
-        lda     #$41
-        sta     $dc05
-        ; Default Value: $25/37 on PAL
-        ;                    $95/149 on NTSC
-        lda     #0
-        sta     $dc04
-
-        ; We do never "handle" the interrupt, we use it just as a timer.
-        clc
-        rts
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:  lda     #JOY_COUNT
-        rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:   tax            ; Joystick number into X
-        bne joy2
-
-; Read joystick 1
-
-joy1:   lda #$7F
-        sei
-        sta CIA1_PRA
-        lda CIA1_PRB
-        cli
-        and #$1F
-        eor #$1F
-        rts
-
-; Read joystick 2
-
-joy2:   dex
-        bne joy3
-
-        ; ldx	#0
-        lda	#$E0
-        ldy	#$FF
-        sei
-        sta	CIA1_DDRA
-        lda	CIA1_PRA
-        sty	CIA1_DDRA
-        cli
-        and	#$1F
-        eor	#$1F
-        rts
-
-        ; Read joystick 3
-
-joy3:   dex
-        bne     joy4
-
-        lda     temp3
-        eor	#$1F
-        rts
-
-        ; Read joystick 4
-
-joy4:   lda     temp4
-        eor	#$1F
-        ldx     #0
-        rts
-
diff --git a/libsrc/c64/c64-isepic.s b/libsrc/c64/c64-isepic.s
deleted file mode 100755
index 533dfaffa..000000000
--- a/libsrc/c64/c64-isepic.s
+++ /dev/null
@@ -1,270 +0,0 @@
-;
-; Extended memory driver for the ISEPIC cartridge.
-; Marco van den Heuvel, 2010-01-24
-;
-
-        .include	"zeropage.inc"
-
-        .include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack	generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte	$65, $6d, $64		; "emd"
-        .byte	EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word	INSTALL
-        .word	UNINSTALL
-        .word	PAGECOUNT
-        .word	MAP
-        .word	USE
-        .word	COMMIT
-        .word	COPYFROM
-        .word	COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-IP_WINDOW       = $DF00		; Address of ISEPIC window
-IP_CTRL_BASE    = $DE00
-PAGES           = 8
-
-; ------------------------------------------------------------------------
-; Code.
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda	#0
-        sta	IP_CTRL_BASE
-        ldx	IP_WINDOW
-        cpx	IP_WINDOW
-        bne	@notpresent
-        inc	IP_WINDOW
-        cpx	IP_WINDOW
-        beq	@notpresent
-        ldx	IP_WINDOW
-        sta	IP_CTRL_BASE+1
-        inx
-        stx	IP_WINDOW
-        dex
-        sta	IP_CTRL_BASE
-        cpx	IP_WINDOW
-        beq	@setok
-
-@notpresent:
-        lda	#EM_ERR_NO_DEVICE
-        rts
-
-@setok:
-        lda	#EM_ERR_OK
-;       rts				; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda	#PAGES
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-; The Isepic cartridge does not copy but actually map the window, so USE is
-; identical to MAP.
-
-USE     := MAP
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:
-        tax
-        sta	IP_CTRL_BASE,x
-        lda	#IP_WINDOW
-
-; Use the RTS from COMMIT below to save a precious byte of storage
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT:
-        rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        jsr	setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp	@L5
-
-@L1:
-        lda	IP_WINDOW,x
-        sta	(ptr2),y
-        iny
-        bne	@L2
-        inc	ptr2+1
-@L2:
-        inx
-        beq	@L4
-
-; Bump count and repeat
-
-@L3:
-        inc	ptr3
-        bne	@L1
-        inc	ptr3+1
-        bne	@L1
-        rts
-
-; Bump page register
-
-@L4:
-        inc	tmp1		; Bump low page register
-@L5:
-        stx	tmp2
-        ldx	tmp1
-        sta	IP_CTRL_BASE,x
-        ldx	tmp2
-        jmp	@L3
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        jsr	setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp	@L5
-
-@L1:
-        lda	(ptr2),y
-        sta	IP_WINDOW,x
-        iny
-        bne	@L2
-        inc	ptr2+1
-@L2:
-        inx
-        beq	@L4
-
-; Bump count and repeat
-
-@L3:
-        inc	ptr3
-        bne	@L1
-        inc	ptr3+1
-        bne	@L1
-        rts
-
-; Bump page register
-
-@L4:
-        inc	tmp1		; Bump page register
-@L5:
-        stx	tmp2
-        ldx	tmp1
-        sta	IP_CTRL_BASE,x
-        ldx	tmp2
-        jmp	@L3
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-
-setup:
-        sta	ptr1
-        stx	ptr1+1		; Save passed pointer
-
-; Get the page number from the struct and remember it.
-
-        ldy	#EM_COPY::PAGE
-        lda	(ptr1),y
-        sta	tmp1
-
-; Get the buffer pointer into ptr2
-
-        ldy	#EM_COPY::BUF
-        lda	(ptr1),y
-        sta	ptr2
-        iny
-        lda	(ptr1),y
-        sta	ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy	#EM_COPY::COUNT
-        lda	(ptr1),y
-        eor	#$FF
-        sta	ptr3
-        iny
-        lda	(ptr1),y
-        eor	#$FF
-        sta	ptr3+1
-
-; Get the page offset into X and clear Y
-
-        ldy	#EM_COPY::OFFS
-        lda	(ptr1),y
-        tax
-        ldy	#0
-
-; Done
-
-        rts
diff --git a/libsrc/c64/c64-joymouse.s b/libsrc/c64/c64-joymouse.s
deleted file mode 100644
index bd3236129..000000000
--- a/libsrc/c64/c64-joymouse.s
+++ /dev/null
@@ -1,438 +0,0 @@
-;
-; Driver for a "joystick mouse".
-;
-; Ullrich von Bassewitz, 2004-03-29, 2009-09-26
-; 2010-02-08, Greg King
-;
-; The driver prevents the keyboard from interfering by changing the
-; keyboard's output port into an input port while the driver reads its
-; controller device.  That disables a wire that is left active by the
-; Kernal.  That wire is used by the STOP-key to break out of BASIC
-; programs -- CC65 programs don't use that feature.  The wire is shared
-; by these keys: STOP, "Q", Commodore, Space, "2", CTRL, Left-Arrow, and
-; "1".  I listed them, in order, from bit 7 over to bit 0.  The
-; rightmost five keys can look like joystick switches.
-;
-; The driver prevents the mouse/joystick from interfering by "blinding"
-; the keyboard scanner while any button/switch is active.  It changes
-; the input port into an output port, then stores all zero-bits in that
-; port's latch.  Reading from an output port sees the bitwise-AND of the
-; latch and the input signals.  Therefore, the scanner thinks that eight
-; keys are being pushed at the same time.  It doesn't know what to do
-; about that condition; so, it does nothing.  The driver lets the
-; scanner see normally, again, when no buttons/switches are active.
-;
-
-        .include        "zeropage.inc"
-        .include        "mouse-kernel.inc"
-	.include	"c64.inc"
-
-        .macpack        generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-HEADER:
-
-; Driver signature
-
-        .byte   $6d, $6f, $75           ; "mou"
-        .byte   MOUSE_API_VERSION       ; Mouse driver API version number
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   HIDE
-        .addr   SHOW
-        .addr   SETBOX
-        .addr   GETBOX
-        .addr   MOVE
-        .addr   BUTTONS
-        .addr   POS
-        .addr   INFO
-        .addr   IOCTL
-        .addr   IRQ
-
-; Mouse driver flags
-
-        .byte   MOUSE_FLAG_LATE_IRQ
-
-; Callback table, set by the kernel before INSTALL is called
-
-CHIDE:  jmp     $0000                   ; Hide the cursor
-CSHOW:  jmp     $0000                   ; Show the cursor
-CMOVEX: jmp     $0000                   ; Move the cursor to X coord
-CMOVEY: jmp     $0000                   ; Move the cursor to Y coord
-
-
-;----------------------------------------------------------------------------
-; Constants
-
-SCREEN_HEIGHT   = 200
-SCREEN_WIDTH    = 320
-
-.enum   JOY
-        UP      = $01
-        DOWN    = $02
-        LEFT    = $04
-        RIGHT   = $08
-        FIRE    = $10
-.endenum
-
-;----------------------------------------------------------------------------
-; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the SETBOX and GETBOX routines, so don't
-; reorder them.
-
-.bss
-
-Vars:
-YPos:           .res    2               ; Current mouse position, Y
-XPos:           .res    2               ; Current mouse position, X
-XMin:		.res  	2	     	; X1 value of bounding box
-YMin:		.res  	2	     	; Y1 value of bounding box
-XMax:		.res  	2	     	; X2 value of bounding box
-YMax:		.res	2	     	; Y2 value of bounding box
-Buttons:	.res  	1		; Button mask
-
-; Temporary value used in the int handler
-
-Temp:           .res    1
-
-; Default values for above variables
-
-.rodata
-
-.proc   DefVars
-        .word   SCREEN_HEIGHT/2         ; YPos
-        .word   SCREEN_WIDTH/2          ; XPos
-        .word   0                       ; XMin
-        .word   0                       ; YMin
-        .word   SCREEN_WIDTH            ; XMax
-        .word   SCREEN_HEIGHT           ; YMax
-	.byte	0			; Buttons
-.endproc
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an MOUSE_ERR_xx code in a/x.
-
-INSTALL:
-
-; Initialize variables. Just copy the default stuff over
-
-        ldx     #.sizeof(DefVars)-1
-@L1:    lda     DefVars,x
-        sta     Vars,x
-        dex
-        bpl     @L1
-
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
-
-        sei
-        jsr     CHIDE
-        lda     XPos
-        ldx     XPos+1
-        jsr     CMOVEX
-        lda     YPos
-        ldx     YPos+1
-        jsr     CMOVEY
-        cli
-
-; Done, return zero (= MOUSE_ERR_OK)
-
-        ldx     #$00
-        txa
-        rts
-
-;----------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-
-UNINSTALL       = HIDE                  ; Hide cursor on exit
-
-;----------------------------------------------------------------------------
-; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required besides hiding the mouse cursor.
-; No return code required.
-
-HIDE:   sei
-        jsr     CHIDE
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required besides enabling the mouse cursor.
-; No return code required.
-
-SHOW:   sei
-        jsr     CSHOW
-        cli
-        rts
-
-;----------------------------------------------------------------------------
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in a/x.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-
-SETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     (ptr1),y
-        sta     XMin,y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in a/x.
-
-GETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-
-@L1:    lda     XMin,y
-        sta     (ptr1),y
-        dey
-        bpl     @L1
-
-       	rts
-
-;----------------------------------------------------------------------------
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-;
-
-MOVE:   sei                             ; No interrupts
-
-        sta     YPos
-        stx     YPos+1                  ; New Y position
-        jsr     CMOVEY                  ; Set it
-
-        ldy     #$01
-        lda     (sp),y
-        sta     XPos+1
-        tax
-        dey
-        lda     (sp),y
-        sta     XPos                    ; New X position
-
-        jsr     CMOVEX			; Move the cursor
-
-	cli                             ; Allow interrupts
-       	rts
-
-;----------------------------------------------------------------------------
-; BUTTONS: Return the button mask in a/x.
-
-BUTTONS:
-	lda	Buttons
-	ldx	#$00
-	rts
-
-;----------------------------------------------------------------------------
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-
-POS:    ldy    	#MOUSE_POS::XCOORD      ; Structure offset
-
-	sei	    			; Disable interrupts
-	lda     XPos			; Transfer the position
-	sta	(ptr1),y
-	lda	XPos+1
-	iny
-	sta	(ptr1),y
-      	lda	YPos
-        iny
-        sta     (ptr1),y
-	lda	YPos+1
-	cli	    			; Enable interrupts
-
-        iny
-        sta     (ptr1),y                ; Store last byte
-
-    	rts	    			; Done
-
-;----------------------------------------------------------------------------
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-;
-; We're cheating here to keep the code smaller: The first fields of the
-; mouse_info struct are identical to the mouse_pos struct, so we will just
-; call _mouse_pos to initialize the struct pointer and fill the position
-; fields.
-
-INFO:   jsr	POS
-
-; Fill in the button state
-
-       	lda	Buttons
-    	ldy	#MOUSE_INFO::BUTTONS
-    	sta	(ptr1),y
-
-      	rts
-
-;----------------------------------------------------------------------------
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an error code in a/x.
-;
-
-IOCTL:  lda     #MOUSE_ERR_INV_IOCTL
-        rts
-
-;----------------------------------------------------------------------------
-; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
-; (so be careful). The routine MUST return carry set if the interrupt has been
-; 'handled' - which means that the interrupt source is gone. Otherwise it
-; MUST return carry clear.
-;
-
-; Avoid crosstalk between the keyboard and a joystick.
-
-IRQ:	ldy	#%00000000		; Set ports A and B to input
-	sty	CIA1_DDRB
-	sty	CIA1_DDRA		; Keyboard won't look like joystick
-	lda	CIA1_PRB		; Read Control-Port 1
-	dec	CIA1_DDRA		; Set port A back to output
-	eor	#%11111111		; Bit goes up when switch goes down
-	beq	@Save			;(bze)
-	dec	CIA1_DDRB		; Joystick won't look like keyboard
-	sty	CIA1_PRB		; Set "all keys pushed"
-@Save:  sta     Temp
-
-; Check for a pressed button and place the result into Buttons
-
-        ldx     #$00                    ; Assume no button pressed
-        and     #JOY::FIRE              ; Check fire button
-        beq     @L0                     ; Jump if not pressed
-        ldx     #MOUSE_BTN_LEFT         ; Left (only) button is pressed
-@L0:    stx     Buttons
-
-; Check left/right
-
-        lda     Temp                    ; Read joystick #0
-       	and    	#(JOY::LEFT | JOY::RIGHT)
-        beq     @SkipX			;
-
-; We will cheat here and rely on the fact that either the left, OR the right
-; bit can be active
-
-       	and     #JOY::RIGHT             ; Check RIGHT bit
-       	bne	@Right
-      	lda	#$FF
-      	tax
-      	bne	@AddX                   ; Branch always
-@Right:	lda	#$01
-      	ldx	#$00
-
-; Calculate the new X coordinate (--> a/y)
-
-@AddX:  add     XPos
-      	tay	      			; Remember low byte
-      	txa
-      	adc	XPos+1
-    	tax
-
-; Limit the X coordinate to the bounding box
-
-   	cpy	XMin
-   	sbc	XMin+1
-   	bpl	@L1
-       	ldy    	XMin
-       	ldx	XMin+1
-    	jmp	@L2
-@L1:	txa
-
-    	cpy	XMax
-    	sbc	XMax+1
-    	bmi	@L2
-    	ldy	XMax
-    	ldx	XMax+1
-@L2:	sty	XPos
-   	stx	XPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEX
-
-; Calculate the Y movement vector
-
-@SkipX: lda     Temp                    ; Read joystick #0
-       	and    	#(JOY::UP | JOY::DOWN)  ; Check up/down
-        beq     @SkipY		 	;
-
-; We will cheat here and rely on the fact that either the up, OR the down
-; bit can be active
-
-       	lsr     a                       ; Check UP bit
-       	bcc	@Down
-      	lda	#$FF
-      	tax
-      	bne	@AddY
-@Down:	lda	#$01
-    	ldx	#$00
-
-; Calculate the new Y coordinate (--> a/y)
-
-@AddY: 	add    	YPos
-      	tay	      			; Remember low byte
-      	txa
-      	adc	YPos+1
-    	tax
-
-; Limit the Y coordinate to the bounding box
-
-   	cpy	YMin
- 	sbc	YMin+1
- 	bpl	@L3
-       	ldy    	YMin
-       	ldx	YMin+1
-    	jmp	@L4
-@L3:	txa
-
-    	cpy	YMax
-    	sbc	YMax+1
-    	bmi	@L4
-    	ldy	YMax
-    	ldx	YMax+1
-@L4:	sty	YPos
- 	stx	YPos+1
-
-; Move the mouse pointer to the new X pos
-
-        tya
-        jsr     CMOVEY
-
-; Done
-
-@SkipY: clc                             ; Interrupt not handled
-        rts
-
diff --git a/libsrc/c64/c64-numpad.s b/libsrc/c64/c64-numpad.s
deleted file mode 100644
index a224be57a..000000000
--- a/libsrc/c64/c64-numpad.s
+++ /dev/null
@@ -1,115 +0,0 @@
-;
-; Joystick driver using C128 number pad in 64 mode.
-; May be used multiple times when linked to the statically application.
-;
-; Stefan Haubenthal, 2004-01-26
-; Based on Ullrich von Bassewitz, 2002-12-20
-;
-
-	.include	"zeropage.inc"
-
-	.include	"joy-kernel.inc"
-	.include	"joy-error.inc"
-	.include	"c64.inc"
-
-	.macpack	generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-; Driver signature
-
-	.byte	$6A, $6F, $79		; "joy"
-	.byte	JOY_API_VERSION		; Driver API version number
-
-; Button state masks (8 values)
-
-	.byte	$02			; JOY_UP	"8"
-	.byte	$10			; JOY_DOWN	"2"
-	.byte	$20			; JOY_LEFT	"4"
-	.byte	$08			; JOY_RIGHT	"6"
-	.byte	$04			; JOY_FIRE	"5" ENTER
-	.byte	$00			; JOY_FIRE2 unavailable
-	.byte	$00			; Future expansion
-	.byte	$00			; Future expansion
-
-; Jump table.
-
-       	.addr   INSTALL
-       	.addr   UNINSTALL
-       	.addr   COUNT
-       	.addr   READ
-        .addr   0                       ; IRQ entry unused
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT	= 1		; Number of joysticks we support
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda     #JOY_ERR_OK             ; Assume we have a joystick
-        ldx     VIC_CLK_128             ; Test for a C128
-        cpx     #$FF
-        bne     @C128                   ; Jump if we have one
-        lda     #JOY_ERR_NO_DEVICE      ; No C128 -> no numpad
-@C128:  ldx     #0                      ; Set high byte
-
-;	rts			; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-	rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:  lda	#JOY_COUNT
-	ldx	#0
-	rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:	tax			; Clear high byte
-	lda	#$FD
-	ldy	#$FE
-	sei
-	sta	VIC_KBD_128
-	lda	CIA1_PRB
-	and	#%00110000
-	eor	#%00110000
-	lsr
-	lsr
-	sty	VIC_KBD_128
-	eor	CIA1_PRB
-	iny
-	sty	VIC_KBD_128	; Reset to $FF
-	cli
-	and	#%11111110
-	eor	#%11111110
-	rts
-
diff --git a/libsrc/c64/c64-potmouse.s b/libsrc/c64/c64-potmouse.s
deleted file mode 100644
index b49552ae8..000000000
--- a/libsrc/c64/c64-potmouse.s
+++ /dev/null
@@ -1,390 +0,0 @@
-;
-; Driver for a potentiometer "mouse" e.g. Koala Pad
-;
-; Ullrich von Bassewitz, 2004-03-29, 2009-09-26
-; Stefan Haubenthal, 2006-08-20
-;
-
-	.include	"zeropage.inc"
-	.include	"mouse-kernel.inc"
-	.include	"c64.inc"
-
-	.macpack	generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment	"JUMPTABLE"
-
-HEADER:
-
-; Driver signature
-
-	.byte	$6d, $6f, $75		; "mou"
-	.byte	MOUSE_API_VERSION	; Mouse driver API version number
-
-; Jump table.
-
-	.addr	INSTALL
-	.addr	UNINSTALL
-	.addr	HIDE
-	.addr	SHOW
-	.addr	SETBOX
-        .addr   GETBOX
-	.addr	MOVE
-	.addr	BUTTONS
-	.addr	POS
-	.addr	INFO
-	.addr	IOCTL
-	.addr	IRQ
-
-; Callback table, set by the kernel before INSTALL is called
-
-CHIDE:	jmp	$0000			; Hide the cursor
-CSHOW:	jmp	$0000			; Show the cursor
-CMOVEX: jmp	$0000			; Move the cursor to X coord
-CMOVEY: jmp	$0000			; Move the cursor to Y coord
-
-
-;----------------------------------------------------------------------------
-; Constants
-
-SCREEN_HEIGHT	= 200
-SCREEN_WIDTH	= 320
-
-.enum	JOY
-	UP	= $01
-	DOWN	= $02
-	LEFT	= $04
-	RIGHT	= $08
-	FIRE	= $10
-.endenum
-
-;----------------------------------------------------------------------------
-; Global variables. The bounding box values are sorted so that they can be
-; written with the least effort in the SETBOX and GETBOX routines, so don't
-; reorder them.
-
-.bss
-
-Vars:
-YPos:		.res  	2		; Current mouse position, Y
-XPos:		.res  	2		; Current mouse position, X
-XMin:		.res  	2		; X1 value of bounding box
-YMin:		.res  	2		; Y1 value of bounding box
-XMax:		.res  	2		; X2 value of bounding box
-YMax:		.res  	2		; Y2 value of bounding box
-Buttons:	.res  	1		; Button mask
-
-; Temporary value used in the int handler
-
-Temp:		.res  	1
-
-; Default values for above variables
-
-.rodata
-
-.proc	DefVars
-	.word	SCREEN_HEIGHT/2		; YPos
-	.word	SCREEN_WIDTH/2		; XPos
-	.word	0			; XMin
-	.word	0			; YMin
-	.word	SCREEN_WIDTH		; XMax
-	.word	SCREEN_HEIGHT		; YMax
-	.byte	0			; Buttons
-.endproc
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an MOUSE_ERR_xx code in a/x.
-
-INSTALL:
-
-; Initialize variables. Just copy the default stuff over
-
-	ldx	#.sizeof(DefVars)-1
-@L1:	lda	DefVars,x
-	sta	Vars,x
-	dex
-	bpl	@L1
-
-; Be sure the mouse cursor is invisible and at the default location. We
-; need to do that here, because our mouse interrupt handler doesn't set the
-; mouse position if it hasn't changed.
-
-	sei
-	jsr	CHIDE
-	lda	XPos
-	ldx	XPos+1
-	jsr	CMOVEX
-	lda	YPos
-	ldx	YPos+1
-	jsr	CMOVEY
-	cli
-
-; Done, return zero (= MOUSE_ERR_OK)
-
-	ldx	#$00
-	txa
-	rts
-
-;----------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; No return code required (the driver is removed from memory on return).
-
-UNINSTALL	= HIDE			; Hide cursor on exit
-
-;----------------------------------------------------------------------------
-; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently visible and should get hidden. For most drivers,
-; no special action is required besides hiding the mouse cursor.
-; No return code required.
-
-HIDE:	sei
-	jsr	CHIDE
-	cli
-	rts
-
-;----------------------------------------------------------------------------
-; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages
-; a counter for calls to show/hide, and the driver entry point is only called
-; if the mouse is currently hidden and should become visible. For most drivers,
-; no special action is required besides enabling the mouse cursor.
-; No return code required.
-
-SHOW:	sei
-	jsr	CSHOW
-	cli
-	rts
-
-;----------------------------------------------------------------------------
-; SETBOX: Set the mouse bounding box. The parameters are passed as they come
-; from the C program, that is, a pointer to a mouse_box struct in a/x.
-; No checks are done if the mouse is currently inside the box, this is the job
-; of the caller. It is not necessary to validate the parameters, trust the
-; caller and save some code here. No return code required.
-
-SETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     (ptr1),y
-        sta     XMin,y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; GETBOX: Return the mouse bounding box. The parameters are passed as they
-; come from the C program, that is, a pointer to a mouse_box struct in a/x.
-
-GETBOX: sta     ptr1
-        stx     ptr1+1                  ; Save data pointer
-
-        ldy     #.sizeof (MOUSE_BOX)-1
-        sei
-
-@L1:    lda     XMin,y
-        sta     (ptr1),y
-        dey
-        bpl     @L1
-
-        cli
-       	rts
-
-;----------------------------------------------------------------------------
-; MOVE: Move the mouse to a new position. The position is passed as it comes
-; from the C program, that is: X on the stack and Y in a/x. The C wrapper will
-; remove the parameter from the stack on return.
-; No checks are done if the new position is valid (within the bounding box or
-; the screen). No return code required.
-;
-
-MOVE:	sei				; No interrupts
-
-	sta	YPos
-	stx	YPos+1			; New Y position
-	jsr	CMOVEY			; Set it
-
-	ldy	#$01
-	lda	(sp),y
-	sta	XPos+1
-	tax
-	dey
-	lda	(sp),y
-	sta	XPos			; New X position
-
-	jsr	CMOVEX			; Move the cursor
-
-	cli				; Allow interrupts
-	rts
-
-;----------------------------------------------------------------------------
-; BUTTONS: Return the button mask in a/x.
-
-BUTTONS:
-	lda	Buttons
-	ldx	#$00
-	rts
-
-;----------------------------------------------------------------------------
-; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1.
-; No return code required.
-
-POS:	ldy	#MOUSE_POS::XCOORD	; Structure offset
-
-	sei				; Disable interrupts
-	lda	XPos			; Transfer the position
-	sta	(ptr1),y
-	lda	XPos+1
-	iny
-	sta	(ptr1),y
-	lda	YPos
-	iny
-	sta	(ptr1),y
-	lda	YPos+1
-	cli				; Enable interrupts
-
-	iny
-	sta	(ptr1),y		; Store last byte
-
-	rts				; Done
-
-;----------------------------------------------------------------------------
-; INFO: Returns mouse position and current button mask in the MOUSE_INFO
-; struct pointed to by ptr1. No return code required.
-;
-; We're cheating here to keep the code smaller: The first fields of the
-; mouse_info struct are identical to the mouse_pos struct, so we will just
-; call _mouse_pos to initialize the struct pointer and fill the position
-; fields.
-
-INFO:	jsr	POS
-
-; Fill in the button state
-
-	lda	Buttons
-	ldy	#MOUSE_INFO::BUTTONS
-	sta	(ptr1),y
-
-	rts
-
-;----------------------------------------------------------------------------
-; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl
-; specific data in ptr1, and the ioctl code in A.
-; Must return an error code in a/x.
-;
-
-IOCTL:	lda	#MOUSE_ERR_INV_IOCTL
-	rts
-
-;----------------------------------------------------------------------------
-; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context
-; (so be careful).
-;
-
-IRQ:	lda	#$7F
-	sta	CIA1_PRA
-	lda	CIA1_PRB		; Read port #1
-	and	#%00001100
-	eor	#%00001100		; Make all bits active high
-	asl
-	sta	Buttons
-	lsr
-	lsr
-	lsr
-	and	#%00000001
-	ora	Buttons
-	sta	Buttons
-	ldx	#%01000000
-	stx	CIA1_PRA
-	ldy	#0
-:	dey
-	bne	:-
-	ldx	SID_ADConv1
-	stx	XPos
-	ldx	SID_ADConv2
-	stx	YPos
-
-	lda	#$FF
-	tax
-	bne	@AddX			; Branch always
-	lda	#$01
-	ldx	#$00
-
-; Calculate the new X coordinate (--> a/y)
-
-@AddX:	add	XPos
-	tay				; Remember low byte
-	txa
-	adc	XPos+1
-	tax
-
-; Limit the X coordinate to the bounding box
-
-	cpy	XMin
-	sbc	XMin+1
-	bpl	@L1
-	ldy	XMin
-	ldx	XMin+1
-	jmp	@L2
-@L1:	txa
-
-	cpy	XMax
-	sbc	XMax+1
-	bmi	@L2
-	ldy	XMax
-	ldx	XMax+1
-@L2:	sty	XPos
-	stx	XPos+1
-
-; Move the mouse pointer to the new X pos
-
-	tya
-	jsr	CMOVEX
-
-	lda	#$FF
-	tax
-	bne	@AddY
-@Down:	lda	#$01
-	ldx	#$00
-
-; Calculate the new Y coordinate (--> a/y)
-
-@AddY:	add	YPos
-	tay				; Remember low byte
-	txa
-	adc	YPos+1
-	tax
-
-; Limit the Y coordinate to the bounding box
-
-	cpy	YMin
-	sbc	YMin+1
-	bpl	@L3
-	ldy	YMin
-	ldx	YMin+1
-	jmp	@L4
-@L3:	txa
-
-	cpy	YMax
-	sbc	YMax+1
-	bmi	@L4
-	ldy	YMax
-	ldx	YMax+1
-@L4:	sty	YPos
-	stx	YPos+1
-
-; Move the mouse pointer to the new X pos
-
-	tya
-	jmp	CMOVEY
diff --git a/libsrc/c64/c64-ptvjoy.s b/libsrc/c64/c64-ptvjoy.s
deleted file mode 100755
index b4314968e..000000000
--- a/libsrc/c64/c64-ptvjoy.s
+++ /dev/null
@@ -1,151 +0,0 @@
-;
-; PTV-4 Player joystick driver for the C64
-;
-; Groepaz/Hitmen, 2002-12-23
-; obviously based on Ullrichs driver :)
-;
-
-        .include "zeropage.inc"
-
-        .include "joy-kernel.inc"
-        .include "joy-error.inc"
-        .include "c64.inc"
-
-        .macpack generic
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-        .segment "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $6A, $6F, $79   ; "joy"
-        .byte   JOY_API_VERSION	; Driver API version number
-
-; Button state masks (8 values)
-
-        .byte   $01                     ; JOY_UP
-        .byte   $02                     ; JOY_DOWN
-        .byte   $04                     ; JOY_LEFT
-        .byte   $08                     ; JOY_RIGHT
-        .byte   $10                     ; JOY_FIRE
-        .byte   $00                     ; JOY_FIRE2 unavailable
-        .byte   $00                     ; Future expansion
-        .byte   $00                     ; Future expansion
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   COUNT
-        .addr   READ
-        .addr   0                       ; IRQ entry unused
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT       = 4             ; Number of joysticks we support
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda     #JOY_ERR_OK
-;	rts                     ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-        lda     #JOY_COUNT
-        rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:   tax	                ; Joystick number into X
-        bne     joy2
-
-; Read joystick 1
-
-joy1:   lda	#$7F
-        sei
-        sta	CIA1_PRA
-        lda	CIA1_PRB
-        cli
-        and	#$1F
-        eor	#$1F
-        rts
-
-; Read joystick 2
-
-joy2:   dex
-        bne     joy3
-
-        lda 	#$E0
-        ldy 	#$FF
-        sei
-        sta 	CIA1_DDRA
-        lda 	CIA1_PRA
-        sty 	CIA1_DDRA
-        cli
-        and 	#$1F
-        eor 	#$1F
-        rts
-
-; Read joystick 3
-
-joy3:
-        lda     #%10000000      ; cia 2 port B Data-Direction
-        sta     CIA2_DDRB       ; bit 7: out    bit 6-0: in
-
-        dex
-        bne     joy4
-
-        lda     #$80            ; cia 2 port B read/write
-        sta     CIA2_PRB        ; (output one at PB7)
-
-        lda     CIA2_PRB        ; cia 2 port B read/write
-        and     #$1f            ; get bit 4-0 (PB4-PB0)
-        eor     #$1f
-        rts
-
-; Read joystick 4
-
-joy4:   lda     #$00            ; cia 2 port B read/write
-        sta     CIA2_PRB        ; (output zero at PB7)
-
-        lda     CIA2_PRB        ; cia 2 port B read/write
-        and     #$0f            ; get bit 3-0 (PB3-PB0)
-        sta     tmp1            ; joy 4 directions
-
-        lda     CIA2_PRB        ; cia 2 port B read/write
-        and     #%00100000      ; get bit 5 (PB5)
-        lsr
-        ora     tmp1
-        eor     #$1f
-
-        ldx #0
-        rts
-
diff --git a/libsrc/c64/c64-ram.s b/libsrc/c64/c64-ram.s
deleted file mode 100644
index f176eda49..000000000
--- a/libsrc/c64/c64-ram.s
+++ /dev/null
@@ -1,266 +0,0 @@
-;
-; Extended memory driver for the C64 hidden RAM. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2002-12-02
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"em-kernel.inc"
-        .include        "em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-BASE	= $D000
-PAGES  	= ($10000 - BASE) / 256
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-curpage:        .res    1               ; Current page number
-window:         .res    256             ; Memory "window"
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        ldx     #$FF
-        stx     curpage                 ; Invalidate the current page
-        inx                             ; X = 0
-        txa                             ; A = X = EM_ERR_OK
-;       rts                             ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     #PAGES
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta     curpage			; Remember the new page
-
-        clc
-        adc	#>BASE
-        sta	ptr1+1
-        ldy	#$00
-        sty    	ptr1
-
-        lda	#window
-        sta	ptr2+1
-
-; Transfer one page
-
-        jsr     transfer                ; Transfer one page
-
-; Return the memory window
-
-        lda     #window                ; Return the window address
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-
-USE:    sta     curpage                 ; Remember the page
-        lda     #window                ; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda     curpage			; Get the current page
-        bmi     done                    ; Jump if no page mapped
-
-        clc
-        adc	#>BASE
-        sta	ptr2+1
-        ldy	#$00
-        sty    	ptr2
-
-        lda	#window
-        sta	ptr1+1
-
-; Transfer one page. Y must be zero on entry
-
-transfer:
-        ldx    	$01   			; Remember c64 control port
-        txa
-        and     #$F8           		; Bank out ROMs, I/O
-        sei
-        sta    	$01
-
-; Unroll the following loop
-
-loop:	.repeat	8
-	lda	(ptr1),y
-        sta	(ptr2),y
-        iny
-	.endrepeat
-
-        bne     loop
-
-; Restore the old memory configuration, allow interrupts
-
-        stx     $01                     ; Restore the old configuration
-        cli
-
-; Done
-
-done:   rts		  
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        sta     ptr3
-        stx     ptr3+1                  ; Save the passed em_copy pointer
-		       
-        ldy     #EM_COPY::OFFS
-        lda     (ptr3),y
-        sta     ptr1
-        ldy     #EM_COPY::PAGE
-        lda     (ptr3),y
-        clc
-        adc     #>BASE
-        sta     ptr1+1                  ; From
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr2
-        iny
-        lda     (ptr3),y
-        sta     ptr2+1                  ; To
-
-common: ldy     #EM_COPY::COUNT+1
-        lda     (ptr3),y                ; Get number of pages
-        beq     @L2                     ; Skip if no full pages
-        sta     tmp1
-
-; Copy full pages allowing interrupts after each page copied
-
-        ldy     #$00
-@L1:    jsr     transfer
-        inc     ptr1+1
-        inc     ptr2+1
-        dec     tmp1
-        bne     @L1
-
-; Copy the remainder of the page
-
-@L2:    ldy     #EM_COPY::COUNT
-        lda     (ptr3),y                ; Get bytes in last page
-        beq     @L4
-        tax
-
-        lda     $01                     ; Remember c64 control port
-        pha
-        and     #$F8           		; Bank out ROMs, I/O
-        sei
-        sta    	$01
-
-; Transfer the bytes in the last page
-
-        ldy     #$00
-@L3:    lda	(ptr1),y
-        sta	(ptr2),y
-        iny
-        dex
-        bne     @L3
-
-; Restore the old memory configuration, allow interrupts
-
-        pla
-        sta     $01                     ; Restore the old configuration
-        cli
-
-; Done
-
-@L4:    rts
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO: sta     ptr3
-        stx     ptr3+1                  ; Save the passed em_copy pointer
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr3),y
-        sta     ptr2
-        ldy     #EM_COPY::PAGE
-        lda     (ptr3),y
-        clc
-        adc     #>BASE
-        sta     ptr2+1                  ; To
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr3),y
-        sta     ptr1
-        iny
-        lda     (ptr3),y
-        sta     ptr1+1                  ; From
-
-        jmp     common
-
-
diff --git a/libsrc/c64/c64-ramcart.s b/libsrc/c64/c64-ramcart.s
deleted file mode 100644
index 43e42af3b..000000000
--- a/libsrc/c64/c64-ramcart.s
+++ /dev/null
@@ -1,292 +0,0 @@
-;
-; Extended memory driver for the RamCart 64/128KB cartridge. Driver works
-; without problems when statically linked.
-; Code is based on GEORAM code by Ullrich von Bassewitz.
-; Maciej 'YTM/Elysium' Witkowiak 
-; 06,22.12.2002
-;
-
-
-	.include	"zeropage.inc"
-
-      	.include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-	.word	USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-RAMC_WINDOW       = $DF00                 ; Address of RamCart window
-RAMC_PAGE_LO      = $DE00                 ; Page register low
-RAMC_PAGE_HI      = $DE01                 ; Page register high (only for RC128)
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-
-pagecount:      .res    2               ; Number of available pages
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-	ldx	RAMC_WINDOW
-	cpx	RAMC_WINDOW
-	bne	@notpresent
-
-	lda	#0
-	sta	RAMC_PAGE_LO
-	sta	RAMC_PAGE_HI
-	ldx	RAMC_WINDOW
-	cpx	RAMC_WINDOW
-	bne	@notpresent
-	lda	#2
-	sta	RAMC_WINDOW
-	cmp	RAMC_WINDOW
-	beq	@cont
-	cpx	RAMC_WINDOW
-	beq	@readonly
-@cont:	ldy	#1
-	sty	RAMC_PAGE_HI
-	sty	RAMC_WINDOW
-	dey
-	sty	RAMC_PAGE_HI
-	iny
-	cpy	RAMC_WINDOW
-	beq	@rc64
-	; we're on rc128
-	ldx	#>512
-	bne	@setsize
-@rc64:	ldx	#>256
-@setsize:
-	lda	#0
-	sta	pagecount
-	stx	pagecount+1
-        lda     #EM_ERR_OK
-        rts
-@notpresent:
-@readonly:
-	lda	#EM_ERR_NO_DEVICE
-;	rts                             ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-; The RamCart cartridge does not copy but actually map the window, so USE is
-; identical to MAP.
-
-USE     = MAP
-
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta	RAMC_PAGE_LO
-	stx	RAMC_PAGE_HI
-        lda     #RAMC_WINDOW
-
-; Use the RTS from COMMIT below to save a precious byte of storage
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: rts
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     RAMC_WINDOW,x
-        sta     (ptr2),y
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:  	inc	tmp1
-	bne	@L5
-	inc	tmp2
-@L5:	lda	tmp1
-	sta	RAMC_PAGE_LO
-	lda	tmp2
-	sta	RAMC_PAGE_HI
-	jmp	@L3
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        jsr     setup
-
-; Setup is:
-;
-;   - ptr1 contains the struct pointer
-;   - ptr2 contains the linear memory buffer
-;   - ptr3 contains -(count-1)
-;   - tmp1 contains the low page register value
-;   - tmp2 contains the high page register value
-;   - X contains the page offset
-;   - Y contains zero
-
-        jmp     @L5
-
-@L1:    lda     (ptr2),y
-        sta     RAMC_WINDOW,x
-        iny
-        bne     @L2
-        inc     ptr2+1
-@L2:    inx
-        beq     @L4
-
-; Bump count and repeat
-
-@L3:    inc     ptr3
-        bne     @L1
-        inc     ptr3+1
-        bne     @L1
-        rts
-
-; Bump page register
-
-@L4:  	inc	tmp1
-	bne	@L5
-	inc	tmp2
-@L5:	lda	tmp1
-	sta	RAMC_PAGE_LO
-	lda	tmp2
-	sta	RAMC_PAGE_HI
-	jmp	@L3
-
-; ------------------------------------------------------------------------
-; Helper function for COPYFROM and COPYTO: Store the pointer to the request
-; structure and prepare data for the copy
-
-setup:  sta     ptr1
-        stx     ptr1+1          ; Save passed pointer
-
-; Get the page number from the struct and adjust it so that it may be used
-; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
-
-        ldy     #EM_COPY::PAGE+1
-        lda     (ptr1),y
-        sta     tmp2
-        dey
-        lda     (ptr1),y
-        sta     tmp1
-
-; Get the buffer pointer into ptr2
-
-        ldy     #EM_COPY::BUF
-        lda     (ptr1),y
-        sta     ptr2
-        iny
-        lda     (ptr1),y
-        sta     ptr2+1
-
-; Get the count, calculate -(count-1) and store it into ptr3
-
-        ldy     #EM_COPY::COUNT
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3
-        iny
-        lda     (ptr1),y
-        eor     #$FF
-        sta     ptr3+1
-
-; Get the page offset into X and clear Y
-
-        ldy     #EM_COPY::OFFS
-        lda     (ptr1),y
-        tax
-        ldy     #$00
-
-; Done
-
-        rts
-
diff --git a/libsrc/c64/c64-reu.s b/libsrc/c64/c64-reu.s
deleted file mode 100644
index 59dbb7913..000000000
--- a/libsrc/c64/c64-reu.s
+++ /dev/null
@@ -1,236 +0,0 @@
-;
-; Extended memory driver for the Commodore REU. Driver works without
-; problems when statically linked.
-;
-; Ullrich von Bassewitz, 2002-11-29
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"em-kernel.inc"
-        .include        "em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-        .word   USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-REU_STATUS      = $DF00                 ; Status register
-REU_COMMAND     = $DF01                 ; Command register
-REU_C64ADDR     = $DF02                 ; C64 base address register
-REU_REUADDR     = $DF04                 ; REU base address register
-REU_COUNT       = $DF07                 ; Transfer count register
-REU_IRQMASK     = $DF09                 ; IRQ mask register
-REU_CONTROL     = $DF0A                 ; Control register
-REU_TRIGGER     = $FF00                 ; REU command trigger
-
-OP_COPYFROM     = $ED
-OP_COPYTO       = $EC
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-.bss
-pagecount:      .res    2               ; Number of pages available
-curpage:        .res    2               ; Current page number
-
-window:         .res    256             ; Memory "window"
-
-reu_params:     .word 	$0000  		; Host address, lo, hi
-	 	.word 	$0000		; Exp  address, lo, hi
-                .byte	$00		; Expansion  bank no.
-       	       	.word  	$0000  		; # bytes to move, lo, hi
-       	 	.byte 	$00    		; Interrupt mask reg.
-       	 	.byte 	$00    		; Adress control reg.
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        ldx     #$00                    ; High byte of return code
-        lda     #$55
-        sta     REU_REUADDR
-        cmp     REU_REUADDR             ; Check for presence of REU
-        bne     nodevice
-        asl     a                       ; A = $AA
-        sta     REU_REUADDR
-        cmp     REU_REUADDR             ; Check for presence of REU
-        bne     nodevice
-
-        ldy     #>(128*4)               ; Assume 128KB
-        lda     REU_STATUS
-        and     #$10                    ; Check size bit
-        beq     @L1
-        ldy     #>(256*4)               ; 256KB when size bit is set
-@L1:    sty     pagecount+1
-
-        ldy     #$FF
-        sty     curpage
-        sty     curpage+1               ; Invalidate the current page
-        txa                             ; X = A = EM_ERR_OK
-        rts
-
-; No REU found
-
-nodevice:
-        lda     #EM_ERR_NO_DEVICE
-;       rts                             ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x.  The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:    sta     curpage
-        stx     curpage+1               ; Remember the new page
-
-        ldy     #OP_COPYFROM
-        jsr     common                  ; Copy the window
-
-        lda     #window                ; Return the window address
-done:   rts
-
-; ------------------------------------------------------------------------
-; USE: Tell the driver that the window is now associated with a given page.
-					
-USE:    sta     curpage
-        stx     curpage+1               ; Remember the page
-        lda     #window                ; Return the window
-        rts
-
-; ------------------------------------------------------------------------
-; COMMIT: Commit changes in the memory window to extended storage.
-
-COMMIT: lda     curpage
-        ldx     curpage+1               ; Do we have a page mapped?
-        bmi     done                    ; Jump if no page mapped
-
-        ldy     #OP_COPYTO
-common: sty     tmp1
-
-        ldy     #window
-        sty     REU_C64ADDR+1
-
-        ldy     #0
-        sty     REU_REUADDR+0
-        sta     REU_REUADDR+1
-        stx     REU_REUADDR+2
-
-        sty     REU_COUNT+0
-        ldy     #1
-        sty     REU_COUNT+1             ; Move 256 bytes
-        bne     transfer1               ; Transfer 256 bytes into REU
-
-; ------------------------------------------------------------------------
-; COPYFROM: Copy from extended into linear memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYFROM:
-        ldy     #OP_COPYFROM
-        .byte   $2C
-
-; ------------------------------------------------------------------------
-; COPYTO: Copy from linear into extended memory. A pointer to a structure
-; describing the request is passed in a/x.
-; The function must not return anything.
-;
-
-COPYTO:
-        ldy     #OP_COPYTO
-        sty     tmp1
-
-; Remember the passed pointer
-
-        sta     ptr1
-        stx     ptr1+1          ; Save the pointer
-
-; The structure passed to the functions has the same layout as the registers
-; of the Commodore REU, so register programming is easy.
-
-        ldy     #7-1
-@L1:    lda     (ptr1),y
-        sta     REU_C64ADDR,y
-        dey
-        bpl     @L1
-
-; Invalidate the page in the memory window
-
-        sty     curpage+1       ; Y = $FF
-
-; Reload the REU command and start the transfer
-
-transfer1:
-        ldy     tmp1
-
-; Transfer subroutine for the REU. Expects command in Y.
-
-transfer:
-        sty    	REU_COMMAND     ; Issue command
-
-        ldy 	$01       	; Save the value of the c64 control port...
-        tya          	  	;
-        and     #$F8            ; Disable ROMs and I/O.
-  	sei          	  	;
-        sta 	$01
-        lda     REU_TRIGGER     ; Don't change $FF00
-        sta 	REU_TRIGGER     ; Start the transfer...
-
-        sty     $01             ; Restore the old configuration
-        cli
-        rts
-
diff --git a/libsrc/c64/c64-stdjoy.s b/libsrc/c64/c64-stdjoy.s
deleted file mode 100644
index 8bbd7bbf8..000000000
--- a/libsrc/c64/c64-stdjoy.s
+++ /dev/null
@@ -1,121 +0,0 @@
-;
-; Standard joystick driver for the C64. May be used multiple times when linked
-; to the statically application.
-;
-; Ullrich von Bassewitz, 2002-12-20
-;
-
-	.include 	"zeropage.inc"
-
-      	.include 	"joy-kernel.inc"
-        .include        "joy-error.inc"
-        .include        "c64.inc"
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $6A, $6F, $79		; "joy"
-        .byte   JOY_API_VERSION		; Driver API version number
-
-; Button state masks (8 values)
-
-        .byte   $01                     ; JOY_UP
-        .byte   $02                     ; JOY_DOWN
-        .byte   $04                     ; JOY_LEFT
-        .byte   $08                     ; JOY_RIGHT
-        .byte   $10                     ; JOY_FIRE
-        .byte   $00                     ; JOY_FIRE2 unavailable
-        .byte   $00                     ; Future expansion
-        .byte   $00                     ; Future expansion
-
-; Jump table.
-
-        .addr   INSTALL
-        .addr   UNINSTALL
-        .addr   COUNT
-        .addr   READ
-        .addr   0                       ; IRQ entry unused
-
-; ------------------------------------------------------------------------
-; Constants
-
-JOY_COUNT       = 2             ; Number of joysticks we support
-
-
-; ------------------------------------------------------------------------
-; Data.
-
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an JOY_ERR_xx code in a/x.
-;
-
-INSTALL:
-        lda     #JOY_ERR_OK
-
-;	rts                     ; Run into UNINSTALL instead
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-        rts
-
-
-; ------------------------------------------------------------------------
-; COUNT: Return the total number of available joysticks in a/x.
-;
-
-COUNT:
-        lda     #JOY_COUNT
-        rts
-
-; ------------------------------------------------------------------------
-; READ: Read a particular joystick passed in A.
-;
-
-READ:   tax	  		; Joystick number into X
-	bne    	joy2
-
-; Read joystick 1
-
-joy1:	lda	#$7F
-     	sei
-     	sta	CIA1_PRA
-     	lda	CIA1_PRB
-     	cli
-     	and	#$1F
-     	eor	#$1F
-     	rts
-
-; Read joystick 2
-
-joy2:	ldx	#0
-	lda	#$E0
-	ldy	#$FF
-	sei
-	sta	CIA1_DDRA
-	lda	CIA1_PRA
-	sty	CIA1_DDRA
-	cli
-	and	#$1F
-	eor	#$1F
-	rts
-
-
diff --git a/libsrc/c64/c64-swlink.s b/libsrc/c64/c64-swlink.s
deleted file mode 100644
index 9f1b23c5b..000000000
--- a/libsrc/c64/c64-swlink.s
+++ /dev/null
@@ -1,473 +0,0 @@
-;
-; Serial driver for the C64 using a Swiftlink or Turbo-232 cartridge.
-;
-; Ullrich von Bassewitz, 2003-04-18
-;
-; The driver is based on the cc65 rs232 module, which in turn is based on
-; Craig Bruce device driver for the Switftlink/Turbo-232.
-;
-; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998.
-;
-; This software is Public Domain.  It is in Buddy assembler format.
-;
-; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from
-; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232
-; Serial Cartridge.  Both devices are based on the 6551 ACIA chip.  It also
-; supports the "hacked" SwiftLink with a 1.8432 MHz crystal.
-;
-; The code assumes that the kernal + I/O are in context.  On the C128, call
-; it from Bank 15.  On the C64, don't flip out the Kernal unless a suitable
-; NMI catcher is put into the RAM under then Kernal.  For the SuperCPU, the
-; interrupt handling assumes that the 65816 is in 6502-emulation mode.
-;
-
-        .include        "zeropage.inc"
-        .include        "ser-kernel.inc"
-        .include        "ser-error.inc"
-	.include	"c64.inc"
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $73, $65, $72           ; "ser"
-        .byte   SER_API_VERSION         ; Serial API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   OPEN
-        .word   CLOSE
-        .word   GET
-        .word   PUT
-        .word   STATUS
-        .word   IOCTL
-        .word   IRQ
-
-;----------------------------------------------------------------------------
-; I/O definitions
-
-ACIA   	        = $DE00
-ACIA_DATA       = ACIA+0        ; Data register
-ACIA_STATUS     = ACIA+1        ; Status register
-ACIA_CMD        = ACIA+2        ; Command register
-ACIA_CTRL       = ACIA+3        ; Control register
-
-;----------------------------------------------------------------------------
-;
-; Global variables
-;
-
-; We reuse the RS232 zero page variables for the driver, since the ROM
-; routines cannot be used together with this driver.
-RecvHead        = $B5           ; Head of receive buffer
-RecvTail        = $BD           ; Tail of receive buffer
-RecvFreeCnt     = $F7           ; Number of bytes in receive buffer
-SendHead        = $F8           ; Head of send buffer
-SendTail        = $F9           ; Tail of send buffer
-SendFreeCnt     = $FA           ; Number of bytes free in send buffer
-
-.bss
-Stopped:     	.res   	1      	; Flow-stopped flag
-RtsOff:		.res	1      	;
-
-; Send and receive buffers: 256 bytes each
-RecvBuf:	.res	256
-SendBuf:	.res	256
-
-.data
-NmiContinue: 	.byte  	$4c    	; JMP instruction for NMI save -- continue
-NmiSave:     	.res   	2      	; normal NMI handler
-
-.rodata
-
-; Tables used to translate RS232 params into register values
-
-BaudTable:                      ; bit7 = 1 means setting is invalid
-        .byte   $FF             ; SER_BAUD_45_5
-        .byte   $FF             ; SER_BAUD_50
-        .byte   $FF             ; SER_BAUD_75
-        .byte   $FF             ; SER_BAUD_110
-        .byte   $FF             ; SER_BAUD_134_5
-        .byte   $02             ; SER_BAUD_150
-        .byte   $05             ; SER_BAUD_300
-        .byte   $06             ; SER_BAUD_600
-        .byte   $07             ; SER_BAUD_1200
-        .byte   $FF             ; SER_BAUD_1800
-        .byte   $08             ; SER_BAUD_2400
-        .byte   $09             ; SER_BAUD_3600
-        .byte   $0A             ; SER_BAUD_4800
-        .byte   $0B             ; SER_BAUD_7200
-        .byte   $0C             ; SER_BAUD_9600
-        .byte   $0E             ; SER_BAUD_19200
-        .byte   $0F             ; SER_BAUD_38400
-        .byte   $FF             ; SER_BAUD_57600
-        .byte   $FF             ; SER_BAUD_115200
-        .byte   $FF             ; SER_BAUD_230400
-
-BitTable:
-        .byte   $60             ; SER_BITS_5
-        .byte   $40             ; SER_BITS_6
-        .byte   $20             ; SER_BITS_7
-        .byte   $00             ; SER_BITS_8
-
-StopTable:
-        .byte   $00             ; SER_STOP_1
-        .byte   $80             ; SER_STOP_2
-
-ParityTable:
-        .byte   $00             ; SER_PAR_NONE
-        .byte   $20             ; SER_PAR_ODD
-        .byte   $60             ; SER_PAR_EVEN
-        .byte   $A0             ; SER_PAR_MARK
-        .byte   $E0             ; SER_PAR_SPACE
-
-.code
-
-;----------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present.
-; Must return an SER_ERR_xx code in a/x.
-
-INSTALL:
-
-; Deactivate DTR and disable 6551 interrupts
-
-      	lda     #%00001010
-       	sta    	ACIA_CMD
-
-; Set up the nmi vector
-
-   	lda 	NMIVec
-   	ldy 	NMIVec+1
-   	sta 	NmiSave+0
-   	sty 	NmiSave+1
-   	lda 	#NmiHandler
-SetNMI: sta 	NMIVec
-   	sty 	NMIVec+1
-
-; Done, return an error code
-
-        lda     #SER_ERR_INIT_FAILED
-	rts
-
-; Baud rate not available
-
-InvBaud:
-        lda     #SER_ERR_BAUD_UNAVAIL
-        rts
-
-;----------------------------------------------------------------------------
-; CLOSE: Close the port, disable interrupts and flush the buffer. Called
-; without parameters. Must return an error code in a/x.
-;
-
-CLOSE:
-
-; Stop interrupts, drop DTR
-
-      	lda     #%00001010
-       	sta    	ACIA_CMD
-
-; Initalize buffers. Returns zero in a
-
-        jsr     InitBuffers
-
-; Return OK
-
-        lda     #SER_ERR_NO_DATA
-   	rts
-
-; Check for flow stopped & enough free: release flow control
-
-@L2:  	ldx 	Stopped                 ; (34)
-   	beq 	@L3
-   	cmp 	#63
-   	bcc 	@L3
-   	lda 	#$00
-   	sta 	Stopped
-   	lda 	RtsOff
-   	ora 	#%00001000
-   	sta	ACIA_CMD
-
-; Get byte from buffer
-
-@L3:  	ldx 	RecvHead                ; (41)
-       	lda 	RecvBuf,x
-      	inc 	RecvHead
-   	inc 	RecvFreeCnt
-       	ldx 	#$00                    ; (59)
-   	sta    	(ptr1,x)
-       	txa				; Return code = 0
-   	rts
-
-;----------------------------------------------------------------------------
-; PUT: Output character in A.
-; Must return an error code in a/x.
-;
-
-PUT:
-
-; Try to send
-
-        ldx 	SendFreeCnt
-       	inx                             ; X = $ff?
-   	beq 	@L2
-   	pha
-   	lda 	#$00
-   	jsr 	TryToSend
-   	pla
-
-; Put byte into send buffer & send
-
-@L2:  	ldx 	SendFreeCnt
-   	bne 	@L3
-   	lda 	#SER_ERR_INV_IOCTL
-       rts
-
-;----------------------------------------------------------------------------
-; IRQ: Not used on the C64
-;
-
-IRQ     = $0000
-
-;----------------------------------------------------------------------------
-;
-; NMI handler
-; C128 NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=33, ROMexit=30
-; C64  NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=34, ROMexit=29
-;
-; timing: normal=76+43+9=128 cycles, assertFlow=76+52+9=137 cycles
-;
-; C128 @ 115.2k: 177 cycles avail (fast)
-; C64  @  57.6k: 177 cycles avail, worstAvail=177-43? = 134
-; SCPU @ 230.4k: 868 cycles avail: for a joke!
-;
-
-NmiHandler:
-     	pha
-       	lda    	ACIA_STATUS     ;(4) ;status ;check for byte received
-     	and 	#$08           	;(2)
-       	beq    	@L9  		;(2*)
-     	cld
-     	txa
-     	pha
-     	tya
-     	pha
-@L1:	lda 	ACIA_DATA       ;(4)  data  ;get byte and put into receive buffer
-    	ldy 	RecvTail 	;(4)
-    	ldx 	RecvFreeCnt  	;(4)
-      	beq 	@L3  		;(2*) Jump if no space in receive buffer
-    	sta 	RecvBuf,y 	;(5)
-    	inc 	RecvTail        ;(6)
-    	dec 	RecvFreeCnt     ;(6)
-    	cpx 	#33            	;(2)  check for buffer space low
-       	bcc    	@L2            	;(2*)
-    	jmp 	NMIEXIT         ;(3)
-
-; Assert flow control
-
-@L2:  	lda 	RtsOff       	;(3) assert flow control if buffer space too low
-    	sta 	ACIA_CMD	;(4) command
-    	sta 	Stopped      	;(3)
-@L3:    jmp 	NMIEXIT      	;(3)
-
-@L9:	pla
-	jmp 	NmiContinue
-
-;----------------------------------------------------------------------------
-; Try to send a byte. Internal routine. A = TryHard
-
-.proc   TryToSend
-
-   	sta 	tmp1	       	; Remember tryHard flag
-@L0:   	lda 	SendFreeCnt
-    	cmp 	#$ff
-    	beq 	@L3	       	; Bail out
-
-; Check for flow stopped
-
-@L1:	lda 	Stopped
-       	bne    	@L3	       	; Bail out
-
-; Check that swiftlink is ready to send
-
-@L2:   	lda	ACIA_STATUS
-    	and 	#$10
-    	bne 	@L4
-    	bit 	tmp1	       	;keep trying if must try hard
-       	bmi 	@L0
-@L3:	rts
-
-; Send byte and try again
-
-@L4:  	ldx 	SendHead
-    	lda 	SendBuf,x
-    	sta	ACIA_DATA
-    	inc 	SendHead
-    	inc 	SendFreeCnt
-    	jmp 	@L0
-
-.endproc
-
-
-;----------------------------------------------------------------------------
-; Initialize buffers
-
-InitBuffers:
-        ldx 	#0
-        stx     Stopped
-       	stx 	RecvHead
-    	stx 	RecvTail
-      	stx 	SendHead
-    	stx 	SendTail
-        dex                             ; X = 255
-       	stx    	RecvFreeCnt
-      	stx 	SendFreeCnt
-        rts
-
diff --git a/libsrc/c64/c64-vdc.s b/libsrc/c64/c64-vdc.s
deleted file mode 100644
index be1626b1e..000000000
--- a/libsrc/c64/c64-vdc.s
+++ /dev/null
@@ -1,399 +0,0 @@
-;
-; Extended memory driver for the VDC RAM available on all C128 machines
-; (based on code by Ullrich von Bassewitz)
-; Maciej 'YTM/Elysium' Witkowiak 
-; 06,20.12.2002
-;
-; VDC test added by
-; Marco van den Heuvel, 2010-01-22
-;
-
-	.include	"zeropage.inc"
-
-      	.include	"em-kernel.inc"
-        .include	"em-error.inc"
-
-
-        .macpack        generic
-
-
-; ------------------------------------------------------------------------
-; Header. Includes jump table
-
-.segment        "JUMPTABLE"
-
-; Driver signature
-
-        .byte   $65, $6d, $64           ; "emd"
-        .byte   EMD_API_VERSION		; EM API version number
-
-; Jump table.
-
-        .word   INSTALL
-        .word   UNINSTALL
-        .word   PAGECOUNT
-        .word   MAP
-	.word	USE
-        .word   COMMIT
-	.word	COPYFROM
-        .word   COPYTO
-
-; ------------------------------------------------------------------------
-; Constants
-
-VDC_ADDR_REG	  = $D600		  ; VDC address
-VDC_DATA_REG	  = $D601		  ; VDC data
-
-VDC_DATA_HI	  = 18			  ; used registers
-VDC_DATA_LO	  = 19
-VDC_CSET	  = 28
-VDC_DATA	  = 31
-
-; ------------------------------------------------------------------------
-; Data.
-
-.data
-
-pagecount:      .word  64 		   ; $0000-$3fff as 16k default
-curpage:	.word  $ffff		   ; currently mapped-in page (invalid)
-
-.bss
-
-window:		.res	256		   ; memory window
-
-.code
-
-; ------------------------------------------------------------------------
-; INSTALL routine. Is called after the driver is loaded into memory. If
-; possible, check if the hardware is present and determine the amount of
-; memory available.
-; Must return an EM_ERR_xx code in a/x.
-;
-
-INSTALL:
-        ldx     #0
-        ldy     #0
-       	lda     #VDC_CSET	; determine size of RAM...
-       	sta     VDC_ADDR_REG
-
-@L0:    bit     VDC_ADDR_REG
-        bmi     @present
-        inx
-        bne     @L0
-        iny
-        bne     @L0
-	lda    	#EM_ERR_NO_DEVICE
-	rts
-
-@present:
-	ldx    	#VDC_CSET	; determine size of RAM...
-	jsr    	vdcgetreg
-	sta    	tmp1
-	ora    	#%00010000
-	jsr    	vdcputreg	; turn on 64k
-
-	jsr    	settestadr1	; save original value of test byte
-	jsr    	vdcgetbyte
-	sta    	tmp2
-
-	lda    	#$55		; write $55 here
-	ldy    	#ptr1
-	jsr    	test64k		; read it here and there
-	lda    	#$aa		; write $aa here
-	ldy    	#ptr2
-	jsr    	test64k		; read it here and there
-
-	jsr    	settestadr1
-	lda    	tmp2
-	jsr    	vdcputbyte	; restore original value of test byte
-
-	lda    	ptr1		; do bytes match?
-	cmp    	ptr1+1
-	bne    	@have64k
-	lda    	ptr2
-	cmp    	ptr2+1
-	bne    	@have64k
-
-	ldx	#VDC_CSET
-	lda	tmp1
- 	jsr	vdcputreg	; restore 16/64k flag
- 	jmp	@endok		; and leave default values for 16k
-
-@have64k:
- 	lda	#<256
- 	ldx	#>256
- 	sta	pagecount
- 	stx	pagecount+1
-@endok:
-	lda     #EM_ERR_OK
-        rts
-
-test64k:
-	sta	tmp1
-	sty	ptr3
-	lda	#0
-	sta	ptr3+1
-	jsr	settestadr1
-	lda	tmp1
-	jsr	vdcputbyte		; write $55
-	jsr	settestadr1
-	jsr	vdcgetbyte		; read here
-	pha
-	jsr	settestadr2
-	jsr	vdcgetbyte		; and there
-	ldy	#1
-	sta	(ptr3),y
-	pla
-	dey
-	sta	(ptr3),y
-	rts
-
-settestadr1:
-	ldy	#$02			; test page 2 (here)
-	.byte	$2c
-settestadr2:
-	ldy	#$42			; or page 64+2 (there)
-	lda	#0
-	jmp	vdcsetsrcaddr
-
-; ------------------------------------------------------------------------
-; UNINSTALL routine. Is called before the driver is removed from memory.
-; Can do cleanup or whatever. Must not return anything.
-;
-
-UNINSTALL:
-    	;on C128 restore font and clear the screen?
-        rts
-
-; ------------------------------------------------------------------------
-; PAGECOUNT: Return the total number of available pages in a/x.
-;
-
-PAGECOUNT:
-        lda     pagecount
-        ldx     pagecount+1
-        rts
-
-; ------------------------------------------------------------------------
-; MAP: Map the page in a/x into memory and return a pointer to the page in
-; a/x. The contents of the currently mapped page (if any) may be discarded
-; by the driver.
-;
-
-MAP:	sta	curpage
-	stx	curpage+1
-	sta	ptr1+1
-	ldy	#0
-	sty	ptr1
-
-	lda	#window
-	sta	ptr2+1
-
-	jsr	transferin
-
-        lda     #