Skip to content

Commit b06efdc

Browse files
committed
Invert reset/power switch behaviour
1 parent e4ccb76 commit b06efdc

File tree

4 files changed

+27
-31
lines changed

4 files changed

+27
-31
lines changed

mod/src/main/kotlin/gay/object/mlogv32/ProcessorAccess.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ProcessorAccess(
3434
val registers: MemoryBuild,
3535
val csrs: LogicBuild,
3636
val errorOutput: MessageBuild,
37-
val resetSwitch: SwitchBuild,
37+
val powerSwitch: SwitchBuild,
3838
val pauseSwitch: SwitchBuild,
3939
val singleStepSwitch: SwitchBuild,
4040
uartFifoModulo: Int,
@@ -255,7 +255,7 @@ class ProcessorAccess(
255255
registers = buildVar<MemoryBuild>(build, "cell1") ?: return null,
256256
csrs = buildVar<LogicBuild>(build, "processor17") ?: return null,
257257
errorOutput = buildVar<MessageBuild>(build, "message1") ?: return null,
258-
resetSwitch = buildVar<SwitchBuild>(build, "switch1") ?: return null,
258+
powerSwitch = buildVar<SwitchBuild>(build, "switch1") ?: return null,
259259
pauseSwitch = buildVar<SwitchBuild>(build, "switch2") ?: return null,
260260
singleStepSwitch = buildVar<SwitchBuild>(build, "switch3") ?: return null,
261261
uartFifoModulo = positiveIntVar(build, "UART_FIFO_MODULO") ?: return null,
@@ -352,7 +352,7 @@ data class StartRequest(
352352
) : Request() {
353353
override suspend fun handle(processor: ProcessorAccess, rx: ByteReadChannel, tx: ByteWriteChannel) = runOnMainThread {
354354
processor.singleStepSwitch.configure(singleStep)
355-
processor.resetSwitch.configure(false)
355+
processor.powerSwitch.configure(true)
356356
SuccessResponse("Processor started.")
357357
}
358358
}
@@ -366,10 +366,10 @@ data class WaitRequest(
366366
override suspend fun handle(processor: ProcessorAccess, rx: ByteReadChannel, tx: ByteWriteChannel): Response {
367367
while (true) {
368368
delay(1000/60) // 1 tick
369-
val (stopped, paused) = runOnMainThread {
370-
processor.resetSwitch.enabled to processor.pauseSwitch.enabled
369+
val (running, paused) = runOnMainThread {
370+
processor.powerSwitch.enabled to processor.pauseSwitch.enabled
371371
}
372-
if (this.stopped && stopped) {
372+
if (this.stopped && !running) {
373373
return SuccessResponse("Processor has stopped.")
374374
}
375375
if (this.paused && paused) {
@@ -405,7 +405,7 @@ data class SerialRequest(
405405
var overflowCount = 0
406406

407407
val fromUart = runOnMainThread {
408-
if (stopOnHalt && processor.resetSwitch.enabled) {
408+
if (stopOnHalt && !processor.powerSwitch.enabled) {
409409
throw RuntimeException("Processor stopped!")
410410
}
411411

@@ -443,7 +443,7 @@ data class SerialRequest(
443443
@SerialName("unpause")
444444
data object UnpauseRequest : Request() {
445445
override suspend fun handle(processor: ProcessorAccess, rx: ByteReadChannel, tx: ByteWriteChannel) = runOnMainThread {
446-
require(!processor.resetSwitch.enabled) { "Processor is not running!" }
446+
require(processor.powerSwitch.enabled) { "Processor is not running!" }
447447
processor.pauseSwitch.configure(false)
448448
SuccessResponse("Processor unpaused.")
449449
}
@@ -453,7 +453,7 @@ data object UnpauseRequest : Request() {
453453
@SerialName("stop")
454454
data object StopRequest : Request() {
455455
override suspend fun handle(processor: ProcessorAccess, rx: ByteReadChannel, tx: ByteWriteChannel) = runOnMainThread {
456-
processor.resetSwitch.configure(true)
456+
processor.powerSwitch.configure(false)
457457
processor.pauseSwitch.configure(false)
458458
processor.singleStepSwitch.configure(false)
459459
SuccessResponse("Processor stopped.")
@@ -465,7 +465,7 @@ data object StopRequest : Request() {
465465
data object StatusRequest : Request() {
466466
override suspend fun handle(processor: ProcessorAccess, rx: ByteReadChannel, tx: ByteWriteChannel) = runOnMainThread {
467467
StatusResponse(
468-
running = !processor.resetSwitch.enabled,
468+
running = processor.powerSwitch.enabled,
469469
paused = processor.pauseSwitch.enabled,
470470
errorOutput = processor.errorOutput.message?.toString() ?: "",
471471
pc = processor.build.executor.optionalVar("pc")?.numu(),

src/debugger.mlog.jinja

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,13 @@ reset:
3333
set UART0 bank1
3434
set UART1 bank2
3535

36-
set DEBUGGER_RESET_SWITCH switch1
37-
3836
# wait until everything is properly initialized
3937
jump reset strictEqual CPU null
4038
jump reset strictEqual REGISTERS null
4139
jump reset strictEqual CSRS null
4240
jump reset strictEqual DISPLAY null
4341
jump reset strictEqual UART0 null
4442
jump reset strictEqual UART1 null
45-
jump reset strictEqual DEBUGGER_RESET_SWITCH null
4643

4744
set i -1
4845
reset__find_lookup_start:
@@ -55,7 +52,7 @@ reset__find_lookup_start:
5552

5653
set LOOKUP_START i
5754

58-
control enabled DEBUGGER_RESET_SWITCH false
55+
control enabled switch1 true
5956

6057
draw clear 0 0 0
6158
drawflush DISPLAY
@@ -99,8 +96,8 @@ reset__find_lookup_start:
9996
#{{'\n'}} {{ print(35, 0) }}
10097

10198
loop:
102-
sensor enabled DEBUGGER_RESET_SWITCH @enabled
103-
jump reset equal enabled true
99+
sensor enabled switch1 @enabled
100+
jump reset equal enabled false
104101

105102
set mark_memory_id 0
106103

src/main.constants.jinja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{% set CONFIG = 'processor19' %}
1010

1111
{% set ERROR_OUTPUT = 'message1' %}
12-
{% set RESET_SWITCH = 'switch1' %}
12+
{% set POWER_SWITCH = 'switch1' %}
1313
{% set PAUSE_SWITCH = 'switch2' %}
1414
{% set SINGLE_STEP_SWITCH = 'switch3' %}
1515

src/main.mlog.jinja

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
#% extends 'main.constants.jinja'
33
#% block contents
44

5+
# disable the power switch, then reset
6+
halt:
7+
control enabled {{POWER_SWITCH}} false
8+
9+
# wait until the power switch is enabled, then reset/start
510
reset:
611
set STATE "reset" # for debug output
712

@@ -20,10 +25,9 @@ reset:
2025

2126
op idiv ICACHE_START_VAR RAM_SIZE 4
2227

23-
# loop until the reset switch is linked and disabled
24-
jump reset strictEqual {{RESET_SWITCH}} null
25-
sensor enabled {{RESET_SWITCH}} @enabled
26-
jump reset equal enabled true
28+
# loop until the power switch is linked and enabled
29+
sensor enabled {{POWER_SWITCH}} @enabled
30+
jump reset equal enabled false
2731

2832
# load reloadable config options
2933
op add ret @counter 1
@@ -309,15 +313,10 @@ end_instruction__no_overflow:
309313
op add pc pc 4
310314

311315
end_instruction_trap:
312-
# halt if the reset switch was manually enabled
313-
sensor enabled {{RESET_SWITCH}} @enabled
314-
jump main notEqual enabled true
315-
316-
# enable the reset switch, wait until it's disabled, then reset the processor
317-
# this must stay directly after end_instruction
318-
halt:
319-
control enabled {{RESET_SWITCH}} true
320-
jump reset always
316+
# halt if the power switch was manually disabled
317+
sensor enabled {{POWER_SWITCH}} @enabled
318+
jump main equal enabled true
319+
jump halt always
321320

322321
# exceptions
323322

@@ -2060,7 +2059,7 @@ set {{CSRS}} null
20602059
set {{INCR}} null
20612060
set {{CONFIG}} null
20622061
set {{ERROR_OUTPUT}} null
2063-
set {{RESET_SWITCH}} null
2062+
set {{POWER_SWITCH}} null
20642063
set {{PAUSE_SWITCH}} null
20652064
set {{SINGLE_STEP_SWITCH}} null
20662065
set {{DISPLAY}} null

0 commit comments

Comments
 (0)