; Initial load segment for the fnchat.exe executable. Sets MEMTOP and
; RAMTOP to $C000, disables BASIC (on XL/XE), disables ANTIC DMA (not
; really), then returns so the rest of the .xex continues to load.

 *= $2000
memsetup
 ; close the E: device
 lda #$0c   ; CIO CLOSE command
 sta $0342  ; ICCOM
 ldx #0     ; channel 0
 jsr $E456  ; CIOV

 ; disable BASIC (XL/XE only)
 lda $d301  ; PORTB
 ora #$02
 sta $d301

 ; set up everything else
 lda #$C0
 sta $6a    ; RAMTOP
 sta $02e6  ; MEMTOP high
 lda #0
 sta $02e5  ; MEMTOP low
 ;sta $022f  ; SDMCTL (turn off screen)

 ; give the SDMCTL change time to get applied by the OS
 lda $14    ; RTCLOK+2
loop
 cmp $14    ; wait until next frame
 beq loop
 rts

 *= $02e2  ; INITAD
 .word memsetup
