Skip to content

Commit

Permalink
Переход на логгирование через Timber
Browse files Browse the repository at this point in the history
  • Loading branch information
3cky committed Nov 1, 2019
1 parent 4e66568 commit 91736b2
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 107 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {
implementation 'commons-lang:commons-lang:2.6'
implementation 'com.samskivert:jmustache:1.9'
implementation 'com.andkulikov:transitionseverywhere:2.0.0-alpha01'
implementation 'com.jakewharton.timber:timber:4.7.1'

testImplementation 'junit:junit:4.12'
testImplementation 'commons-io:commons-io:2.4'
Expand Down
22 changes: 10 additions & 12 deletions app/src/main/java/su/comp/bk/arch/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;

import su.comp.bk.R;
import su.comp.bk.arch.cpu.Cpu;
Expand All @@ -47,14 +46,13 @@
import su.comp.bk.arch.memory.RandomAccessMemory;
import su.comp.bk.arch.memory.RandomAccessMemory.Type;
import su.comp.bk.arch.memory.ReadOnlyMemory;
import timber.log.Timber;

/**
* BK001x computer implementation.
*/
public class Computer implements Runnable {

private static final String TAG = Computer.class.getName();

// State save/restore: Computer uptime (in nanoseconds)
private static final String STATE_UPTIME = Computer.class.getName() + "#uptime";

Expand Down Expand Up @@ -648,7 +646,7 @@ public boolean writeMemory(boolean isByteMode, int address, int value) {
*/
public synchronized void start() {
if (!isRunning) {
Log.d(TAG, "starting computer");
Timber.d("starting computer");
this.clockThread = new Thread(this, "ComputerClockThread");
isRunning = true;
clockThread.start();
Expand All @@ -668,7 +666,7 @@ public synchronized void start() {
*/
public void stop() {
if (isRunning) {
Log.d(TAG, "stopping computer");
Timber.d("stopping computer");
audioOutput.stop();
synchronized (this) {
isRunning = false;
Expand All @@ -693,7 +691,7 @@ public boolean isPaused() {
* Pause computer.
*/
public synchronized void pause() {
Log.d(TAG, "pausing computer");
Timber.d("pausing computer");
isPaused = true;
this.notifyAll();
audioOutput.pause();
Expand All @@ -703,7 +701,7 @@ public synchronized void pause() {
* Resume computer.
*/
public synchronized void resume() {
Log.d(TAG, "resuming computer");
Timber.d("resuming computer");
lastUptimeSyncTimestamp = System.nanoTime();
lastCpuTimeSyncTimestamp = cpu.getTime();
isPaused = false;
Expand All @@ -715,7 +713,7 @@ public synchronized void resume() {
* Release computer resources.
*/
public void release() {
Log.d(TAG, "releasing computer");
Timber.d("releasing computer");
audioOutput.release();
if (floppyController != null) {
floppyController.unmountDiskImages();
Expand Down Expand Up @@ -796,24 +794,24 @@ public void doSyncUptime() {

@Override
public void run() {
Log.d(TAG, "computer started");
Timber.d("computer started");
synchronized (this) {
this.notifyAll();
while (isRunning) {
if (isPaused) {
try {
Log.d(TAG, "computer paused");
Timber.d("computer paused");
this.wait();
} catch (InterruptedException e) {
}
Log.d(TAG, "computer resumed");
Timber.d("computer resumed");
} else {
cpu.executeNextOperation();
checkSyncUptime();
}
}
}
Log.d(TAG, "computer stopped");
Timber.d("computer stopped");
}

}
11 changes: 5 additions & 6 deletions app/src/main/java/su/comp/bk/arch/cpu/Cpu.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package su.comp.bk.arch.cpu;

import android.os.Bundle;
import android.util.Log;

import su.comp.bk.arch.Computer;
import su.comp.bk.arch.cpu.addressing.AddressingMode;
import su.comp.bk.arch.cpu.addressing.AutodecrementAddressingMode;
Expand Down Expand Up @@ -85,14 +85,13 @@
import su.comp.bk.arch.cpu.opcode.TstOpcode;
import su.comp.bk.arch.cpu.opcode.WaitOpcode;
import su.comp.bk.arch.cpu.opcode.XorOpcode;
import timber.log.Timber;

/**
* PDP-11 compatible 1801VM1 CPU implementation.
*/
public class Cpu {

private static final String TAG = Cpu.class.getName();

/** SEL1 I/O register address */
public final static int REG_SEL1 = 0177716;
/** SEL2 I/O register address */
Expand Down Expand Up @@ -786,7 +785,7 @@ public void setInterruptWaitMode(boolean isInterruptWaitMode) {
* Set interrupt wait mode flag state.
*/
public void setInterruptWaitMode() {
Log.d(TAG, "entering WAIT mode, PC: 0" + Integer.toOctalString(readRegister(false, PC)));
Timber.d("entering WAIT mode, PC: 0%s", Integer.toOctalString(readRegister(false, PC)));
setInterruptWaitMode(true);
}

Expand All @@ -795,7 +794,7 @@ public void setInterruptWaitMode() {
*/
public void clearInterruptWaitMode() {
if (isInterruptWaitMode()) {
Log.d(TAG, "leaving WAIT mode, PC: 0" + Integer.toOctalString(readRegister(false, PC)));
Timber.d("leaving WAIT mode, PC: 0%s", Integer.toOctalString(readRegister(false, PC)));
}
setInterruptWaitMode(false);
}
Expand Down Expand Up @@ -866,7 +865,7 @@ public void clearDeferredTraceTrap() {
* Execute 1801VM1-specific halt mode entering sequence
*/
public void enterHaltMode() {
Log.d(TAG, "entering HALT mode, PC: 0" + Integer.toOctalString(readRegister(false, PC)));
Timber.d("entering HALT mode, PC: 0%s", Integer.toOctalString(readRegister(false, PC)));
// Set bit 3 in SEL1 register
int sel1 = readMemory(false, REG_SEL1);
if (sel1 != Computer.BUS_ERROR) {
Expand Down
23 changes: 11 additions & 12 deletions app/src/main/java/su/comp/bk/arch/io/AudioOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
import su.comp.bk.arch.Computer;
import su.comp.bk.arch.cpu.Cpu;
import su.comp.bk.arch.cpu.opcode.BaseOpcode;
import timber.log.Timber;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.os.Bundle;
import android.util.Log;

/**
* Audio output (one bit PCM, bit 6 in SEL1 register).
*/
public class AudioOutput implements Device, Runnable {

private static final String TAG = AudioOutput.class.getName();

// Audio output bit
public final static int OUTPUT_BIT = (1 << 6);

Expand Down Expand Up @@ -91,7 +90,7 @@ public AudioOutput(Computer computer, boolean isBk0011m) {
* 1000L / (OUTPUT_SAMPLE_RATE * BaseOpcode.getBaseExecutionTime()));
pcmTimestamps = new long[pcmTimestampsBufferSize];
pcmTimestampsCapacity = pcmTimestamps.length;
Log.d(TAG, "created audio output, player buffer size: " + minBufferSize +
Timber.d("created audio output, player buffer size: " + minBufferSize +
", PCM buffer size: " + pcmTimestampsCapacity);
}

Expand All @@ -110,14 +109,14 @@ public void timer(long cpuTime) {
}

public void start() {
Log.d(TAG, "starting audio output");
Timber.d("starting audio output");
isRunning = true;
audioOutputThread = new Thread(this, "AudioOutputThread");
audioOutputThread.start();
}

public void stop() {
Log.d(TAG, "stopping audio output");
Timber.d("stopping audio output");
isRunning = false;
player.stop();
while (audioOutputThread.isAlive()) {
Expand All @@ -129,17 +128,17 @@ public void stop() {
}

public void pause() {
Log.d(TAG, "pausing audio output");
Timber.d("pausing audio output");
player.pause();
}

public void resume() {
Log.d(TAG, "resuming audio output");
Timber.d("resuming audio output");
player.play();
}

public void release() {
Log.d(TAG, "releasing audio output");
Timber.d("releasing audio output");
player.release();
}

Expand Down Expand Up @@ -177,7 +176,7 @@ private synchronized void putPcmTimestamp(long pcmTimestamp) {
putPcmTimestampIndex %= pcmTimestamps.length;
pcmTimestampsCapacity--;
} else {
Log.w(TAG, "PCM buffer overflow!");
Timber.w("PCM buffer overflow!");
}
}

Expand All @@ -201,7 +200,7 @@ private long cpuTimeToPcmSamples(long cpuTime) {

@Override
public void run() {
Log.d(TAG, "audio output started");
Timber.d("audio output started");
long pcmTimestamp;
int numPcmSamples = 0;
lastPcmTimestamp = computer.getCpu().getTime() - pcmSamplesToCpuTime(samplesBuffer.length);
Expand All @@ -228,7 +227,7 @@ public void run() {
}
player.write(samplesBuffer, 0, samplesBuffer.length);
}
Log.d(TAG, "audio output stopped");
Timber.d("audio output stopped");
}

}
26 changes: 12 additions & 14 deletions app/src/main/java/su/comp/bk/arch/io/FloppyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@
import java.io.RandomAccessFile;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import su.comp.bk.arch.Computer;
import su.comp.bk.util.Crc16;
import timber.log.Timber;

import android.os.Bundle;
import android.util.Log;

/**
* Floppy drive controller (К1801ВП1-128).
*/
public class FloppyController implements Device {

protected static final String TAG = FloppyController.class.getName();

protected boolean isDebugEnabled = false;

/** Control register address */
Expand Down Expand Up @@ -646,7 +644,7 @@ int getCurrentTrackNumber() {
*/
void setCurrentTrack(int trackNumber, FloppyDriveSide trackSide) {
if (isDebugEnabled) {
d(TAG, "set track: " + trackNumber + ", side: " + trackSide);
d("set track: " + trackNumber + ", side: " + trackSide);
}
this.currentTrackNumber = trackNumber;
this.currentTrackSide = trackSide;
Expand Down Expand Up @@ -757,8 +755,8 @@ public void setDebugEnabled(boolean state) {
isDebugEnabled = state;
}

protected static void d(String tag, String message) {
System.out.println("FDD: " + message);
protected static void d(String message) {
Timber.d(message);
}

protected FloppyDrive getFloppyDrive(FloppyDriveIdentifier drive) {
Expand Down Expand Up @@ -829,7 +827,7 @@ public synchronized void restoreState(Bundle inState) {
drive.mountDiskImage(diskImageFileUri, inState.getBoolean(
getFloppyDriveStateKey(STATE_DRIVE_IMAGE_READ_ONLY,driveIdentifier)));
} catch (Exception e) {
Log.e(TAG, "can't remount disk file image: " + diskImageFileUri, e);
Timber.e(e, "can't remount disk file image: %s", diskImageFileUri);
try {
drive.unmountDiskImage();
} catch (Exception e1) {
Expand All @@ -855,7 +853,7 @@ public synchronized int read(long cpuTime, int address) {
@Override
public synchronized boolean write(long cpuTime, boolean isByteMode, int address, int value) {
if (isDebugEnabled) {
d(TAG, "write: " + Integer.toOctalString(address) +
d("write: " + Integer.toOctalString(address) +
", value: " + Integer.toOctalString(value) + ", isByteMode: " + isByteMode);
}
setLastAccessCpuTime(cpuTime);
Expand Down Expand Up @@ -905,7 +903,7 @@ protected int readControlRegister(long cpuTime) {
// Check for data marker position
if (drive.isCurrentTrackDataMarkerPosition(trackPosition)) {
if (isDebugEnabled) {
d(TAG, "marker found, position: " + trackPosition);
d("marker found, position: " + trackPosition);
}
setMarkerFound(true);
setDataReady(true);
Expand All @@ -919,7 +917,7 @@ protected int readControlRegister(long cpuTime) {
// Check was CRC read as last data word
setCrcCorrect(drive.isCurrentTrackDataCrcPosition(getDataReadyReadPosition()));
if (isDebugEnabled) {
d(TAG, "synchronous read completed, position: " + trackPosition +
d("synchronous read completed, position: " + trackPosition +
", dataReadyReadPosition: " + getDataReadyReadPosition() +
", readDataWords: " + numReadDataWords + ", isCrcCorrect: " + isCrcCorrect());
}
Expand Down Expand Up @@ -1118,7 +1116,7 @@ public synchronized void unmountDiskImages() {
unmountDiskImage(drive);
}
} catch (Exception e) {
Log.e(TAG, "Error while unmounting disk image from drive " + drive, e);
Timber.e(e, "Error while unmounting disk image from drive %s", drive);
}
}
}
Expand Down Expand Up @@ -1148,7 +1146,7 @@ protected FloppyDriveIdentifier getSelectedFloppyDriveIdentifier() {
*/
protected void selectFloppyDrive(FloppyDriveIdentifier floppyDriveIdentifier) {
if (isDebugEnabled) {
d(TAG, "selected drive: " + floppyDriveIdentifier);
d("selected drive: " + floppyDriveIdentifier);
}
if (selectedFloppyDriveIdentifier != floppyDriveIdentifier) {
// Cancel synchronous data read
Expand All @@ -1173,7 +1171,7 @@ public synchronized boolean isMotorStarted() {
*/
protected void setMotorStarted(boolean isStarted) {
if (isDebugEnabled) {
d(TAG, "set floppy drives motor state: " + (isStarted ? "STARTED" : "STOPPED"));
d("set floppy drives motor state: " + (isStarted ? "STARTED" : "STOPPED"));
}
this.isMotorStarted = isStarted;
}
Expand Down
Loading

0 comments on commit 91736b2

Please sign in to comment.