; ---------------------------------------------------------------------------
 ; Constants
 
+SCREEN_XSIZE    = 40            ; screen columns
+SCREEN_YSIZE    = 28            ; screen rows
+
+FUNCTKEY        = $A5
+
 FNAME_LEN       = 16            ; maximum length of file-name
 
 
 ; ---------------------------------------------------------------------------
 ; Low memory
 
+MODEKEY         := $0209
 CAPSLOCK        := $020C
 PATTERN         := $0213
 IRQVec          := $0245
+JOINFLAG        := $025A        ; 0 = don't joiu, $4A = join BASIC programs
+VERIFYFLAG      := $025B        ; 0 = load, 1 = verify
 CURS_Y          := $0268
 CURS_X          := $0269
 STATUS          := $026A
 TIMER3          := $0276
+CFILE_NAME      := $027F
 CFOUND_NAME     := $0293
+FILESTART       := $02A9
+FILEEND         := $02AB
+AUTORUN         := $02AD        ; $00 = only load, $C7 = autorun
+LANGFLAG        := $02AE        ; $00 = BASIC, $80 = machine code
 KEYBUF          := $02DF
 PARAM1          := $02E1        ; & $02E2
 PARAM2          := $02E3        ; & $02E4
 
 ;
-; Ullrich von Bassewitz, 2003-04-13
+; 2003-04-13, Ullrich von Bassewitz
+; 2013-07-16, Greg King
 ;
 ; Screen size variables
 ;
 
         .export         screensize
+        .include        "atmos.inc"
 
 .proc   screensize
 
-        ldx     #40
-        ldy     #28
+        ldx     #SCREEN_XSIZE
+        ldy     #SCREEN_YSIZE
         rts
 
 .endproc
 
-; Stefan Haubenthal, 2012-05-06
-; based on code by Twilighte
+; Based on code by Twilighte.
+; 2012-05-06, Stefan Haubenthal
+; 2013-07-22, Greg King
+;
 ; void __fastcall__ atmos_load(const char* name);
 
         .export         _atmos_load
         .import         store_filename
 
+        .include        "atmos.inc"
+
 
 .proc   _atmos_load
 
         sei
         jsr     store_filename
         ldx     #$00
-        stx     $02ad
-        stx     $02ae
-        stx     $025a
-        stx     $025b
+        stx     AUTORUN         ; don't try to run the file
+        stx     LANGFLAG        ; BASIC
+        stx     JOINFLAG        ; don't join it to another BASIC program
+        stx     VERIFYFLAG      ; load the file
         jsr     cload_bit
         cli
         rts
 
-; Stefan Haubenthal, 2012-05-06
-; based on code by Twilighte
+; Based on code by Twilighte.
+; 2012-05-06, Stefan Haubenthal
+; 2013-07-22, Greg King
+;
 ; void __fastcall__ atmos_save(const char* name, const void* start, const void* end);
 
         .export         _atmos_save
         .import         popax, store_filename
 
+        .include        "atmos.inc"
+
 
 .proc   _atmos_save
 
         sei
-        sta     $02ab   ; file end lo
-        stx     $02ac   ; file end hi
+        sta     FILEEND
+        stx     FILEEND+1
         jsr     popax
-        sta     $02a9   ; file start lo
-        stx     $02aa   ; file start hi
+        sta     FILESTART
+        stx     FILESTART+1
         jsr     popax
         jsr     store_filename
         lda     #00
-        sta     $02ad
+        sta     AUTORUN
         jsr     csave_bit
         cli
         rts
 
 ;
-; Ullrich von Bassewitz, 2003-04-13
+; 2003-04-13, Ullrich von Bassewitz
+; 2013-07-26, Greg King
 ;
 ; char cgetc (void);
 ;
         .include        "atmos.inc"
 
 
-
 ; ------------------------------------------------------------------------
 ;
 
 
 @L2:    and     #$7F            ; Mask out avail flag
         sta     KEYBUF
-        ldy     $209
-        cpy     #$A5
+        ldy     MODEKEY
+        cpy     #FUNCTKEY
         bne     @L3
         ora     #$80            ; FUNCT pressed
 
 
 ;
-; Ullrich von Bassewitz, 2003-04-13
+; 2003-04-13, Ullrich von Bassewitz
+; 2013-07-16, Greg King
 ;
 
         .export         _clrscr
 
 ; Clear full pages. Y is still zero
 
-        ldx     #>(28*40)
+        ldx     #>(SCREEN_YSIZE * SCREEN_XSIZE)
         lda     #' '
 @L1:    sta     (ptr2),y
         iny                     ; Bump low byte of address
 
 @L2:    sta     (ptr2),y
         iny
-        cpy     #<(28*40)
+        cpy     #<(SCREEN_YSIZE * SCREEN_XSIZE)
         bne     @L2
         rts
 
 
 ;
-; Ullrich von Bassewitz, 2003-04-13
+; 2003-04-13, Ullrich von Bassewitz
+; 2013-07-16, Greg King
 ;
 ; void cputcxy (unsigned char x, unsigned char y, char c);
 ; void cputc (char c);
 
 advance:
         iny
-        cpy     #40
+        cpy     #SCREEN_XSIZE
         bne     L3
         inc     CURS_Y          ; new line
         ldy     #0              ; + cr
 
 .rodata
 ScrTabLo:
-        .repeat 28, Line
-                .byte   <(SCREEN + Line * 40)
+        .repeat SCREEN_YSIZE, Line
+                .byte   <(SCREEN + Line * SCREEN_XSIZE)
         .endrep
 
 ScrTabHi:
-        .repeat 28, Line
-                .byte   >(SCREEN + Line * 40)
+        .repeat SCREEN_YSIZE, Line
+                .byte   >(SCREEN + Line * SCREEN_XSIZE)
         .endrep
 
 
+; Helper function
+
         .export         store_filename
         .importzp       ptr1
 
+        .include        "atmos.inc"
+
 store_filename:
         sta     ptr1
         stx     ptr1+1
-        ldy     #$0f   ;store filename
+        ldy     #FNAME_LEN - 1  ; store filename
 :       lda     (ptr1),y
-        sta     $027f,y
+        sta     CFILE_NAME,y
         dey
         bpl     :-
         rts
 
 ; Graphics driver for the 240x200x2 monochrome mode on the Atmos
 ;
 ; Stefan Haubenthal <polluks@sdf.lonestar.org>
-; 2013-07-15, Greg King <gregdk@users.sf.net>
+; 2013-07-16, Greg King <gregdk@users.sf.net>
 ;
 
         .include        "zeropage.inc"
 ;
 
 CONTROL:
-        sta     $213
+        sta     PATTERN
         lda     #TGI_ERR_OK
         sta     ERROR
         rts