@@ -230,11 +230,13 @@ class Cpu {
230230 if (keyHandler.keyDown(v[nib1].toInt())) {
231231 skip()
232232 }
233+ log(opcode, " skip if key v[nib1] down" )
233234 }
234235 0xA1 -> {
235236 if (! keyHandler.keyDown(v[nib1].toInt())) {
236237 skip()
237238 }
239+ log(opcode, " skip if key v[nib1] down" )
238240 }
239241 else -> log(opcode, " INVALID" )
240242 }
@@ -245,10 +247,13 @@ class Cpu {
245247 0x0 -> {
246248 when (nib3) {
247249 // FX07 Timer Vx = get_delay() Sets VX to the value of the delay timer
248- 0x7 -> {}
250+ 0x7 -> {
251+ log(opcode, " UNIMPLEMENTED TIMER OPCODE" )
252+ }
249253 // FX0A KeyOp Vx = get_key() A key press is awaited, and then stored in VX
250254 // (blocking operation, all instruction halted until next key event, delay and sound timers should continue processing)
251255 0xA -> {
256+ log(opcode, " wait for key press" )
252257 keyHandler.waiting = true
253258 while (keyHandler.waiting) {
254259 for (keys in keyHandler.keys.indices) {
@@ -266,9 +271,13 @@ class Cpu {
266271 0x1 -> {
267272 when (nib3) {
268273 // FX15 Timer delay_timer(Vx) Sets the delay timer to VX.
269- 0x5 -> {}
274+ 0x5 -> {
275+ log(opcode, " UNIMPLEMENTED TIMER OPCODE" )
276+ }
270277 // FX18 Sound sound_timer(Vx) Sets the sound timer to VX.
271- 0x8 -> {}
278+ 0x8 -> {
279+ log(opcode, " UNIMPLEMENTED SOUND OPCODE" )
280+ }
272281 // FX1E MEM I += Vx Adds VX to I. VF is not affected.
273282 0xE -> {
274283 i = (i.toInt() + v[nib1]).toShort()
@@ -282,6 +291,7 @@ class Cpu {
282291 // Characters 0-F (in hexadecimal) are represented by a 4x5 font
283292 if (nib3 == 0x9 ) {
284293 i = (v[nib1].toInt() * 5 ).toShort()
294+ log(opcode, " i = sprite_addr[v[nib1]]" )
285295 }
286296 else log(opcode, " INVALID" )
287297 }
@@ -301,6 +311,7 @@ class Cpu {
301311 cpu.memory[i.toInt()] = dig1.toByte()
302312 cpu.memory[i.toInt() + 1 ] = dig2.toByte()
303313 cpu.memory[i.toInt() + 2 ] = dig3.toByte()
314+ log(opcode, " set Binary Coded Decimal" )
304315 }
305316 else log(opcode, " INVALID" )
306317 }
@@ -312,6 +323,7 @@ class Cpu {
312323 for (j in 0 .. nib1) {
313324 memory[i.toInt() + j] = v[j]
314325 }
326+ log(opcode, " dump v[0..nib1] to memory" )
315327 }
316328 else log(opcode, " INVALID" )
317329 }
@@ -323,6 +335,7 @@ class Cpu {
323335 for (j in 0 .. nib1) {
324336 v[j] = memory[i.toInt() + j]
325337 }
338+ log(opcode, " load v[0..nib1] from memory" )
326339 }
327340 else log(opcode, " INVALID" )
328341 }
@@ -409,7 +422,7 @@ class Cpu {
409422 }
410423
411424 fun log (opcode : Int , description : String ) {
412- println (" opcode: 0x" + opcode.toString(16 ).uppercase() + " description: " + description)
413425 log = " opcode: 0x" + opcode.toString(16 ).uppercase() + " description: " + description
426+ println (log)
414427 }
415428}
0 commit comments