;Entry_ADFRecord
;---------------
;Records DiscOp information to file
;
;Entry:
; R0 - command tail
; R12 - pointer to module private word

.Entry_ADFRecord
 STMFD   R13!, {R1-R11, R14}
 LDR     R12, [R12, #0]

 LDR     R1, [R12, #recording_addr - VARS]
 TEQ     R1, #0					;are we already recording?
 LDMNEFD R13!, {R1-R11, PC}			;YES, exit

 MOV     R1, R0
 BL      release_filename_recording
 BL      allocate_filename			;R0=filename
 LDMVSFD R13!, {R1-R11, PC}

 #if Recording_immediate == 0
   MOV     R1, R0				;filename
   MOV     R0, #&8F				;create new file
   SWI     XOS_Find				;PRM2-78
   BVS     _exit				;exit on error

   MOV     R1, R0				;file handle
   MOV     R0, #0				;close file
   SWI     XOS_Find				;PRM2-77
   BVS     _exit				;exit on error

   MOV     R0, #Module_Claim			;request memory
   MOV     R3, #Max_Recording_Size
   SWI     XOS_Module				;PRM1-237
   STRVC   R2, [R12, #recording_addr - VARS]	;notify code we're recording
   STRVC   R2, [R12, #recording_ptr - VARS]
 #else
   STR     R12, [R12, #recording_addr - VARS]	;notify code we're recording
   MOV     R1, #0
   STR     R1, [R12, #recording_ptr - VARS]
 #endif

 ._exit
LDMFD   R13!, {R1-R11, PC}




;Entry_ADFStop
;-------------
;Saves a DiscOp recording
;
;Entry:
; R0 - command tail
; R12 - pointer to module private word

.Entry_ADFStop
 STMFD   R13!, {R0-R11, R14}
 LDR     R12, [R12, #0]

#if Recording_immediate == 0
 LDR     R10, [R12, #recording_addr - VARS]
 TEQ     R10, #0				;are we recording?
 LDMEQFD R13!, {R0-R11, PC}			;NO, exit

 BL      resetVectors				;reset key vectors
 LDR     R1, [R12, #record_filename - VARS]
 MOV     R0, #&8F				;create new file
 SWI     XOS_Find				;PRM2-78
 BVS     _exit					;exit on error
 MOV     R1, R0					;file handle

 LDR     R3, [R12, #recording_ptr - VARS]	;load current pointer
 MOV     R2, R10				;..and start of buffer
 SUB     R3, R3, R2				;length to save
 MOV     R0, #2					;current file pointer
 SWI     XOS_GBPB				;PRM2-68
 MOV     R0, #0					;close file
 SWI     XOS_Find				;PRM2-77

 ._exit
 BL      resetVectors				;reset key vectors
 BL      release_filename_recording
#endif

 SUBS    R0, R0, R0				;clear V
 STR     R0, [R12, #recording_addr - VARS]
LDMFD   R13!, {R0-R11, PC}
