; patch for geoCanvas 64/128 to use Wheels' expansion RAM.
; uses the ca65 assembler, part of the cc65 programming suite.
; http://www.cc65.org/

.out "Source Code (c) 2001-2002 by Todd S. Elliott"

.include "../include/geos/geossym.inc"
.include "../include/geos/geossym2.inc"
.include "../include/geos/diskdrv.inc"
.include "../include/geos/jumptab.inc"
.include "../include/geos/const.inc"
.include "../include/geos/geosmac.ca65.inc"
.include "../include/geos/wheelsym.inc"

; Patches the 64 and 128 versions of geoCanvas to provide memory support under Wheels systems.
; Changes the date stamp of each version from 4/22/94 to 9/2/02 as to differentiate between
; the old version and the new version.
; This new version requires Wheels 64 or 128 and requires at least 64Kb of free expansion RAM.
; The patches are offered 'as is' for the geoCanvas 64 and 128 (4/22/94) versions and have
; absolutely no warranty, implied, direct or otherwise.

; patch $1631 and $1710 with the following code- (64 version)
; patch $047a, $1898, & $1995 with the following code- (128 version)
;	jmp $4fe7

; patch $3e3d with the following code- (64 version)
;	jmp $3ea4
; patch $3ee3 with the following code- (128 version)
;	jmp $3f4a

; patch $3ddd with the following code- (128 version only)
;	nop:nop:nop (removes copy protection check)

; .org $3ea4			; 64 version
.org $3f4a				; 128 version

lb3ea4:
  lda	#(0|64)
  jsr	GetNewKernal		; Call Wheels' expansion RAM routines.
  jsr	GetRAMInfo			; get expansion RAM information.
  lda	r2L				; verify RAM availability
  beq	@1				; abort if expansion RAM isn't available
  lda	r3L				; get RAM bank
;  sta $2410			; for geoCanvas 64 usage
  sta $26b6				; for geoCanvas 128 usage
  lda	#$01				; allocate at least 1 bank
  sta	r2L
  jsr	RamBlkAlloc
  txa					; check error
  bne	@1
  ldx #24				; move the following routine into high memory
@2:  lda lb4fe7,x
  sta $4fe7,x
  dex
  bpl @2
  jmp	RstrKernal			; swap out Wheels Kernal and exit cleanly
;@1:  jmp	$3e55			; 64 version
@1:  jmp	$3efb			; 128 version

lb4fe7:				; execute at $4fe7 - seems to be a safe place
  lda #(0|64)
  jsr GetNewKernal		; get group 0 into memory.
  jsr GetRAMBam			; get the ram bam into the workspace.
;  lda $2410			; get the expansion RAM bank that geoCanvas 64 has been using
  lda $26b6				; get the expansion RAM bank that geoCanvas 128 has been using
  sta r6L				; and free up that bank.
  jsr FreeRAMBlock		; and then free it up.
  jsr PutRAMBam			; write the modified ram bam.
  jsr RstrKernal			; and restore the kernal and memory. 
  jmp EnterDeskTop		; and exits geoCanvas 64

; Enjoy.
; 9/2/02 -Todd Elliott