In the moments leading up to St. Paul police fatally shooting a man earlier this month, the suspect fired two gunshots in the apartment in a fit of rage and then pointed the gun at his roommate's head, investigators disclosed in a newly filed court document.

The first glimpse into 43-year-old William "Billy" Hughes' actions before he was shot Aug. 5 came in a search warrant application filed Tuesday by the state Bureau of Criminal Apprehension (BCA) in Ramsey County District Court. The warrant seeks the retrieval of data from two cellphones found in the apartment belonging to Hughes.

The shooting occurred shortly after 2:30 a.m. at an apartment building in the 900 block of St. Anthony Avenue, after the roommate called 911 to report gunfire on the second floor.

Two officers entered an enclosed porch and knocked on one of two interior doors leading to the apartment, the BCA has said. Hughes came out the other door, and the officers shot him.

St. Paul officials pledged on Aug. 7 to expedite the release of body camera footage and 911 audio from the encounter, with Police Chief Todd Axtell saying the video could be made public sometime in mid-August.

According to the search warrant application:

The roommate said Hughes fell out of his "elevated bed," became angry and shot two or three rounds into the wall.

Hughes then trained the gun on the roommate's head and started talking about the color of the roommate's hat. The roommate fled the room and called police.

The court filing also revealed that Hughes said in text messages to relatives this past spring that he was contemplating suicide. They explained that Hughes "had an ongoing medical condition that limited his quality of life. [Hughes'] medical condition was diagnosed as a terminal illness," the filing made by the BCA read.

Investigators are hoping that the contents of Hughes' two cellphones will shed more light on his frame of mind that prompted those texts months ago. Results from analysis of the phones are pending.

The two officers who shot and killed Hughes in the Summit-University neighborhood have been identified as Matthew Jones and Vincent Adams.

Both have been with the department for five years and were placed on standard administrative leave as the BCA investigates what led them to firing the weapons. Jones and Adams have since returned to duty, police spokesman Steve Linders said Wednesday.

When the investigation is complete, the BCA will turn its findings over without recommendation to the Ramsey County Attorney's Office for review. The BCA is asking that anybody who saw or captured the shooting on video to call (651) 793-7000.

Hughes was the third person in the Twin Cities to die this year after being shot by police. His shooting came less than a week after the release of body camera footage of the June 23 fatal police shooting of Thurman Blevins by two Minneapolis police officers. Hours after the release, Hennepin County Attorney Mike Freeman announced that he wouldn't charge the officers in the case.