Skip to content

Commit b4f0726

Browse files
committed
Big changes to everything.
1 parent 5a111b2 commit b4f0726

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1236
-1164
lines changed

src/main/java/ca/craigthomas/yacoco3e/components/BranchInstruction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public BranchInstruction(int opcode,
3737

3838
public int call(IOController io) {
3939
if (operation.apply(io).equals(true)) {
40-
io.regs.pc.add(byteRead.isNegative() ? byteRead.getSignedShort() : byteRead.getShort());
40+
io.regs.pc.add(byteRead.isNegative() ? byteRead.getSigned() : byteRead.get());
4141
}
4242
return ticks;
4343
}

src/main/java/ca/craigthomas/yacoco3e/components/ByteInstruction.java

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,11 @@ public int call(IOController io) {
5151
*/
5252
public static void negate(IOController io, UnsignedByte memoryByte, UnsignedWord address) {
5353
io.regs.cc.and(~(CC_N | CC_Z | CC_V | CC_C));
54-
55-
if (memoryByte.equalsInt(0x80)) {
56-
io.regs.cc.or(CC_V);
57-
io.regs.cc.or(CC_N);
58-
io.regs.cc.or(CC_C);
59-
memoryByte.set(0x80);
60-
io.writeByte(address, memoryByte);
61-
return;
62-
}
63-
64-
if (memoryByte.equalsInt(0x00)) {
65-
io.regs.cc.or(CC_Z);
66-
memoryByte.set(0);
67-
io.writeByte(address, memoryByte);
68-
return;
69-
}
70-
71-
memoryByte.compliment();
72-
memoryByte.add(1);
73-
io.regs.cc.or(memoryByte.isMasked(0x80) ? CC_V : 0);
54+
io.regs.cc.or(memoryByte.get() == 0x80 ? CC_V : 0);
55+
io.regs.cc.or(memoryByte.get() != 0x00 ? CC_C : 0);
56+
memoryByte.set(0x100 - memoryByte.get());
7457
io.regs.cc.or(memoryByte.isNegative() ? CC_N : 0);
75-
io.regs.cc.or(CC_C);
58+
io.regs.cc.or(memoryByte.isZero() ? CC_Z : 0);
7659
io.writeByte(address, memoryByte);
7760
}
7861

src/main/java/ca/craigthomas/yacoco3e/components/ByteRegisterInstruction.java

Lines changed: 60 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,19 @@ public static void logicalAndCC(IOController io, UnsignedByte registerByte, Unsi
126126
* Adds the specified value to the specified register.
127127
*/
128128
public static void addByte(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
129-
int signedResult = registerByte.getSignedShort() + memoryByte.getSignedShort();
130-
UnsignedByte result = new UnsignedByte(registerByte.getShort() + memoryByte.getShort());
131-
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C | CC_H));
132-
io.regs.cc.or(((registerByte.getShort() ^ memoryByte.getShort() ^ result.getShort()) & 0x10) > 0 ? CC_H : 0);
133-
io.regs.cc.or(result.isZero() ? CC_Z : 0);
134-
io.regs.cc.or(result.isNegative() ? CC_N : 0);
135-
io.regs.cc.or(signedResult > 127 || signedResult < -127 ? CC_V : 0);
136-
io.regs.cc.or(((registerByte.getShort() + memoryByte.getShort()) & 0x100) > 0 ? CC_C : 0);
129+
int result = registerByte.get() + memoryByte.get();
130+
boolean half_carry = (registerByte.get() & 0xF) + (memoryByte.get() & 0xF) >= 0x10;
131+
boolean overflow = ((registerByte.get() ^ memoryByte.get() ^ 0x80) & (registerByte.get() ^ result) & 0x80) > 0;
132+
boolean carry = (result & 0x100) > 0;
133+
137134
registerByte.set(result);
135+
136+
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C | CC_H));
137+
io.regs.cc.or(half_carry ? CC_H : 0);
138+
io.regs.cc.or(carry ? CC_C : 0);
139+
io.regs.cc.or(overflow ? CC_V : 0);
140+
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
141+
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
138142
}
139143

140144
/**
@@ -143,56 +147,29 @@ public static void addByte(IOController io, UnsignedByte registerByte, UnsignedB
143147
* specified register.
144148
*/
145149
public static void addWithCarry(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
146-
UnsignedByte carry = new UnsignedByte((io.regs.cc.isMasked(CC_C)) ? 1 : 0);
147-
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C | CC_H));
148-
149-
// Check for overflow condition
150-
int signedResult = registerByte.getSignedShort() + carry.getSignedShort();
151-
int overflow = signedResult > 127 || signedResult < -127 ? CC_V : 0;
152-
153-
// Check for carry condition if we add the carry value
154-
if (((registerByte.getShort() + carry.getShort()) & 0x100) > 0) {
155-
io.regs.cc.or(CC_C);
156-
}
150+
int carryBit = io.regs.cc.isMasked(CC_C) ? 1 : 0;
151+
int result = registerByte.get() + memoryByte.get() + carryBit;
152+
boolean half_carry = (registerByte.get() & 0xF) + (memoryByte.get() & 0xF) + (carryBit & 0xF) >= 0x10;
153+
boolean overflow = ((registerByte.get() ^ memoryByte.get() ^ 0x80) & (registerByte.get() ^ result) & 0x80) > 0;
154+
boolean carry = (result & 0x100) > 0;
157155

158-
// Check for half carry condition on the carry bit addition
159-
UnsignedByte test = new UnsignedByte((registerByte.getShort() & 0xF) + (carry.getShort() & 0xF));
160-
if (test.isMasked(0x10)) {
161-
io.regs.cc.or(CC_H);
162-
}
163-
164-
// Add the carry bit
165-
registerByte.set(new UnsignedByte(registerByte.getShort() + carry.getShort()));
166-
167-
// Check for overflow condition of the actual byte
168-
signedResult = registerByte.getSignedShort() + memoryByte.getSignedShort();
169-
overflow |= signedResult > 127 || signedResult < -127 ? CC_V : 0;
170-
171-
// Check for carry condition if we add the actual byte now
172-
if (((registerByte.getShort() + memoryByte.getShort()) & 0x100) > 0) {
173-
io.regs.cc.or(CC_C);
174-
}
175-
176-
// Check for half carry condition on the second byte addition
177-
test = new UnsignedByte((registerByte.getShort() & 0xF) + (memoryByte.getShort() & 0xF));
178-
if (test.isMasked(0x10)) {
179-
io.regs.cc.or(CC_H);
180-
}
156+
registerByte.set(result);
181157

182-
// Add the second byte
183-
registerByte.set(new UnsignedByte(registerByte.getShort() + memoryByte.getShort()));
158+
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C | CC_H));
159+
io.regs.cc.or(half_carry ? CC_H : 0);
160+
io.regs.cc.or(carry ? CC_C : 0);
161+
io.regs.cc.or(overflow ? CC_V : 0);
184162
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
185163
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
186-
io.regs.cc.or(overflow);
187164
}
188165

189166
/**
190167
* Logically AND the register byte with a memory byte and tests the byte for zero
191168
* condition or negative condition. Register contents are left unchanged.
192169
*/
193170
public static void bitTest(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
194-
UnsignedByte value = new UnsignedByte(registerByte.getShort());
195-
value.and(memoryByte.getShort());
171+
UnsignedByte value = new UnsignedByte(registerByte.get());
172+
value.and(memoryByte.get());
196173
io.regs.cc.and(~(CC_N | CC_Z | CC_V));
197174
io.regs.cc.or(value.isZero() ? CC_Z : 0);
198175
io.regs.cc.or(value.isNegative() ? CC_N : 0);
@@ -202,23 +179,24 @@ public static void bitTest(IOController io, UnsignedByte registerByte, UnsignedB
202179
* Compares the two bytes and sets the appropriate register sets.
203180
*/
204181
public static void compareByte(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
205-
io.regs.cc.and(~(CC_N | CC_Z | CC_V | CC_C));
206-
boolean byte1WasNegative = registerByte.isNegative();
207-
boolean byte2WasNegative = memoryByte.isNegative();
208-
UnsignedByte result = new UnsignedByte(registerByte.getShort() + memoryByte.twosCompliment().getShort());
209-
io.regs.cc.or(registerByte.getShort() < memoryByte.getShort() ? CC_C : 0);
210-
io.regs.cc.or(result.isZero() ? CC_Z : 0);
211-
io.regs.cc.or(result.isNegative() ? CC_N : 0);
212-
boolean overflow = (!byte1WasNegative && byte2WasNegative && result.isNegative()) || (byte1WasNegative && !byte2WasNegative && !result.isNegative());
182+
int result = registerByte.get() - memoryByte.get();
183+
UnsignedByte resultByte = new UnsignedByte(result);
184+
boolean overflow = ((registerByte.get() ^ memoryByte.get()) & (registerByte.get() ^ result) & 0x80) > 0;
185+
boolean carry = registerByte.get() < memoryByte.get();
186+
187+
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C));
188+
io.regs.cc.or(carry ? CC_C : 0);
213189
io.regs.cc.or(overflow ? CC_V : 0);
190+
io.regs.cc.or(resultByte.isZero() ? CC_Z : 0);
191+
io.regs.cc.or(resultByte.isNegative() ? CC_N : 0);
214192
}
215193

216194
/**
217195
* Performs a correction to the A register to transform the value into
218196
* a proper BCD form.
219197
*/
220198
public static void decimalAdditionAdjust(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
221-
int fullByte = registerByte.getShort();
199+
int fullByte = registerByte.get();
222200
int mostSignificantNibble = fullByte & 0xF0;
223201
int leastSignificantNibble = fullByte & 0x0F;
224202
int adjustment = 0;
@@ -234,10 +212,10 @@ public static void decimalAdditionAdjust(IOController io, UnsignedByte registerB
234212

235213
UnsignedByte result = new UnsignedByte(adjustment);
236214
io.regs.cc.and(~(CC_C | CC_N | CC_Z));
237-
if (((io.regs.a.getShort() + result.getShort()) & 0x100) > 0) {
215+
if (((io.regs.a.get() + result.get()) & 0x100) > 0) {
238216
io.regs.cc.or(CC_C);
239217
}
240-
io.regs.a.set(new UnsignedByte(io.regs.a.getShort() + result.getShort()));
218+
io.regs.a.set(new UnsignedByte(io.regs.a.get() + result.get()));
241219
io.regs.cc.or(io.regs.a.isZero() ? CC_Z : 0);
242220
io.regs.cc.or(io.regs.a.isNegative() ? CC_N : 0);
243221
}
@@ -247,42 +225,42 @@ public static void decimalAdditionAdjust(IOController io, UnsignedByte registerB
247225
* Subtracts the byte value from the specified register.
248226
*/
249227
public static void subtractByte(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
228+
int result = registerByte.get() - memoryByte.get();
229+
boolean overflow = ((registerByte.get() ^ memoryByte.get()) & (registerByte.get() ^ result) & 0x80) > 0;
230+
boolean carry = registerByte.get() < memoryByte.get();
231+
232+
registerByte.set(result);
233+
250234
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C));
251-
boolean byte1WasNegative = registerByte.isNegative();
252-
boolean byte2WasNegative = memoryByte.isNegative();
253-
io.regs.cc.or(registerByte.getShort() < memoryByte.getShort() ? CC_C : 0);
254-
registerByte.set(new UnsignedByte(registerByte.getShort() + memoryByte.twosCompliment().getShort()));
235+
io.regs.cc.or(carry ? CC_C : 0);
236+
io.regs.cc.or(overflow ? CC_V : 0);
255237
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
256238
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
257-
boolean overflow = (!byte1WasNegative && byte2WasNegative && registerByte.isNegative()) || (byte1WasNegative && !byte2WasNegative && !memoryByte.isNegative());
258-
io.regs.cc.or(overflow ? CC_V : 0);
259239
}
260240

261241
/**
262242
* Subtracts the byte value and the carry from the specified value.
263243
*/
264244
public static void subtractByteWithCarry(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
265-
UnsignedByte carry = new UnsignedByte(io.regs.cc.isMasked(CC_C) ? 1 : 0);
245+
int carryBit = io.regs.cc.isMasked(CC_C) ? 1 : 0;
246+
int result = registerByte.get() - memoryByte.get() - carryBit;
247+
boolean overflow = ((registerByte.get() ^ memoryByte.get() ^ 0x80) & (registerByte.get() ^ result) & 0x80) > 0;
248+
boolean carry = registerByte.get() < (memoryByte.get() + carryBit);
249+
250+
registerByte.set(result);
251+
266252
io.regs.cc.and(~(CC_N | CC_V | CC_Z | CC_C));
267-
boolean byte1WasNegative = registerByte.isNegative();
268-
boolean byte2WasNegative = memoryByte.isNegative();
269-
io.regs.cc.or(registerByte.getShort() < memoryByte.getShort() ? CC_C : 0);
270-
registerByte.set(new UnsignedByte(registerByte.getShort() + memoryByte.twosCompliment().getShort()));
271-
boolean overflow = (!byte1WasNegative && byte2WasNegative && registerByte.isNegative()) || (byte1WasNegative && !byte2WasNegative && !registerByte.isNegative());
272-
byte1WasNegative = registerByte.isNegative();
273-
io.regs.cc.or(registerByte.getShort() < carry.getShort() ? CC_C : 0);
274-
registerByte.set(new UnsignedByte(registerByte.getShort() + carry.twosCompliment().getShort()));
275-
overflow |= !byte1WasNegative && registerByte.isNegative() || byte1WasNegative && !registerByte.isNegative();
253+
io.regs.cc.or(carry ? CC_C : 0);
254+
io.regs.cc.or(overflow ? CC_V : 0);
276255
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
277256
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
278-
io.regs.cc.or(overflow ? CC_V : 0);
279257
}
280258

281259
/**
282260
* Performs an exclusive OR of the register and the byte value.
283261
*/
284262
public static void exclusiveOr(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
285-
registerByte.set(new UnsignedByte(registerByte.getShort() ^ memoryByte.getShort()));
263+
registerByte.set(new UnsignedByte(registerByte.get() ^ memoryByte.get()));
286264
io.regs.cc.and(~(CC_N | CC_V | CC_Z));
287265
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
288266
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
@@ -312,19 +290,18 @@ public static void clear(IOController io, UnsignedByte registerByte, UnsignedByt
312290
*/
313291
public static void increment(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
314292
io.regs.cc.and(~(CC_N | CC_Z | CC_V));
315-
boolean wasNegative = registerByte.isNegative();
293+
io.regs.cc.or(registerByte.isMasked(0x7F) ? CC_V : 0);
316294
registerByte.add(1);
317295
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
318296
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
319-
io.regs.cc.or(registerByte.isNegative() != wasNegative ? CC_V : 0);
320297
}
321298

322299
/**
323300
* Decrements the byte value by one.
324301
*/
325302
public static void decrement(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
326303
io.regs.cc.and(~(CC_N | CC_Z | CC_V));
327-
io.regs.cc.or(registerByte.isZero() ? CC_V : 0);
304+
io.regs.cc.or(registerByte.isMasked(0x80) ? CC_V : 0);
328305
registerByte.add(0xFF);
329306
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
330307
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
@@ -432,25 +409,10 @@ public static void testByte(IOController io, UnsignedByte registerByte, Unsigned
432409
*/
433410
public static void negate(IOController io, UnsignedByte registerByte, UnsignedByte memoryByte, UnsignedWord address) {
434411
io.regs.cc.and(~(CC_N | CC_Z | CC_V | CC_C));
435-
436-
if (registerByte.equalsInt(0x80)) {
437-
io.regs.cc.or(CC_V);
438-
io.regs.cc.or(CC_N);
439-
io.regs.cc.or(CC_C);
440-
registerByte.set(0x80);
441-
return;
442-
}
443-
444-
if (registerByte.equalsInt(0x00)) {
445-
io.regs.cc.or(CC_Z);
446-
registerByte.set(0);
447-
return;
448-
}
449-
450-
registerByte.compliment();
451-
registerByte.add(1);
452-
io.regs.cc.or(registerByte.isMasked(0x80) ? CC_V : 0);
412+
io.regs.cc.or(registerByte.get() == 0x80 ? CC_V : 0);
413+
io.regs.cc.or(registerByte.get() != 0x00 ? CC_C : 0);
414+
registerByte.set(0x100 - registerByte.get());
453415
io.regs.cc.or(registerByte.isNegative() ? CC_N : 0);
454-
io.regs.cc.or(CC_C);
416+
io.regs.cc.or(registerByte.isZero() ? CC_Z : 0);
455417
}
456418
}

src/main/java/ca/craigthomas/yacoco3e/components/DiskDrive.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public int getTrack() {
119119
* @param track the track to move to
120120
*/
121121
public void setTrack(UnsignedByte track) {
122-
currentTrack = track.getShort();
122+
currentTrack = track.get();
123123
}
124124

125125
/**
@@ -137,7 +137,7 @@ public int getSector() {
137137
* @param sector the current sector we should move to
138138
*/
139139
public void setSector(UnsignedByte sector) {
140-
currentSector = sector.getShort();
140+
currentSector = sector.get();
141141
}
142142

143143
/**
@@ -314,7 +314,7 @@ public void fireInterrupt() {
314314
* @param command the command to execute
315315
*/
316316
public void executeCommand(UnsignedByte command) {
317-
int intCommand = command.getShort() >> 4;
317+
int intCommand = command.get() >> 4;
318318
boolean verify = command.isMasked(0x04);
319319

320320
/* Set busy flag on the status register */
@@ -489,7 +489,7 @@ public void restore(boolean verify) {
489489
* @param verify whether verify should be run
490490
*/
491491
public void seek(boolean verify) {
492-
int trackToSeek = dataRegisterIn.getShort();
492+
int trackToSeek = dataRegisterIn.get();
493493
if (currentTrack > trackToSeek) {
494494
direction = -1;
495495
}

src/main/java/ca/craigthomas/yacoco3e/components/DiskTrack.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public int getNumberOfSectors() {
5050
* @param value the value to write to the sector
5151
*/
5252
public void writeData(int sector, UnsignedByte value) {
53-
sectors[sector].writeSectorData((byte) value.getShort());
53+
sectors[sector].writeSectorData((byte) value.get());
5454
}
5555

5656
/**
@@ -115,7 +115,7 @@ public boolean hasMoreIdBytes(int sector) {
115115
* @param mark the value of the mark
116116
*/
117117
public void writeDataMark(int sector, UnsignedByte mark) {
118-
sectors[sector].writeDataMark((byte) mark.getShort());
118+
sectors[sector].writeDataMark((byte) mark.get());
119119
}
120120

121121
/**
@@ -201,7 +201,7 @@ public void writeTrack(UnsignedByte value) {
201201
}
202202

203203
/* Check to see if we have a byte that has a different interpretation */
204-
byte byteValue = (byte) value.getShort();
204+
byte byteValue = (byte) value.get();
205205
if (doubleDensity) {
206206
switch (byteValue) {
207207
case (byte) 0xF5:
@@ -267,6 +267,6 @@ public int getLogicalSector(int sector) {
267267
}
268268

269269
public void writeSectorId(int sector, UnsignedByte value) {
270-
sectors[sector].writeId((byte) value.getShort());
270+
sectors[sector].writeId((byte) value.get());
271271
}
272272
}

0 commit comments

Comments
 (0)