MightyPirates / TIS-3D

TIS-100 inspired low-tech computing in Minecraft.
https://www.curseforge.com/minecraft/mc-mods/tis-3d
Other
109 stars 35 forks source link

Module output not quite working #178

Closed walksanatora closed 1 year ago

walksanatora commented 1 year ago

so i have the following stepOutput function

    private void stepOutput() {
        this.cancelWrite();
        if (outbuf.size() > 0) {
            boolean hasWritten = false;
            short val = outbuf.get(0);
            TISString.LOGGER.info("Writing value {} mode {}",val,mode);
            for (final Port port : Port.VALUES) {
                final Pipe sendingPipe = getCasing().getSendingPipe(getFace(), port);
                if (!sendingPipe.isWriting()) {
                    TISString.LOGGER.info("writing {} {}",val,port);
                    sendingPipe.beginWrite(val);
                    hasWritten = true;
                }
            }
            if (hasWritten) {outbuf.remove(0);}
        }
    }

any in my logs i get

[02Mar2023 16:17:03.894] [Server thread/INFO] [tisstring/]: Writing value 50 mode INT
[02Mar2023 16:17:03.901] [Server thread/INFO] [tisstring/]: writing 50 LEFT
[02Mar2023 16:17:03.901] [Server thread/INFO] [tisstring/]: writing 50 RIGHT
[02Mar2023 16:17:03.904] [Server thread/INFO] [tisstring/]: writing 50 UP
[02Mar2023 16:17:03.907] [Server thread/INFO] [tisstring/]: writing 50 DOWN
[02Mar2023 16:17:03.911] [Server thread/INFO] [tisstring/]: Writing value 45 mode UNIT
[02Mar2023 16:17:03.913] [Server thread/INFO] [tisstring/]: writing 45 LEFT
[02Mar2023 16:17:03.915] [Server thread/INFO] [tisstring/]: writing 45 RIGHT
[02Mar2023 16:17:03.916] [Server thread/INFO] [tisstring/]: writing 45 UP
[02Mar2023 16:17:03.916] [Server thread/INFO] [tisstring/]: writing 45 DOWN
[02Mar2023 16:17:03.942] [Server thread/INFO] [tisstring/]: Writing value 53 mode INT
[02Mar2023 16:17:03.943] [Server thread/INFO] [tisstring/]: writing 53 LEFT
[02Mar2023 16:17:03.944] [Server thread/INFO] [tisstring/]: writing 53 RIGHT
[02Mar2023 16:17:03.945] [Server thread/INFO] [tisstring/]: writing 53 UP
[02Mar2023 16:17:03.945] [Server thread/INFO] [tisstring/]: writing 53 DOWN
[02Mar2023 16:17:03.946] [Server thread/INFO] [tisstring/]: Writing value 50 mode UNIT
[02Mar2023 16:17:03.946] [Server thread/INFO] [tisstring/]: writing 50 LEFT
[02Mar2023 16:17:03.947] [Server thread/INFO] [tisstring/]: writing 50 RIGHT
[02Mar2023 16:17:03.948] [Server thread/INFO] [tisstring/]: writing 50 UP
[02Mar2023 16:17:03.948] [Server thread/INFO] [tisstring/]: writing 50 DOWN
[02Mar2023 16:17:03.991] [Server thread/INFO] [tisstring/]: Writing value 0 mode INT
[02Mar2023 16:17:03.991] [Server thread/INFO] [tisstring/]: writing 0 LEFT
[02Mar2023 16:17:03.992] [Server thread/INFO] [tisstring/]: writing 0 RIGHT
[02Mar2023 16:17:03.992] [Server thread/INFO] [tisstring/]: writing 0 UP
[02Mar2023 16:17:03.993] [Server thread/INFO] [tisstring/]: writing 0 DOWN
[02Mar2023 16:17:03.993] [Server thread/INFO] [tisstring/]: Writing value 53 mode UNIT
[02Mar2023 16:17:03.993] [Server thread/INFO] [tisstring/]: writing 53 LEFT
[02Mar2023 16:17:03.994] [Server thread/INFO] [tisstring/]: writing 53 RIGHT
[02Mar2023 16:17:03.994] [Server thread/INFO] [tisstring/]: writing 53 UP
[02Mar2023 16:17:03.994] [Server thread/INFO] [tisstring/]: writing 53 DOWN
[02Mar2023 16:17:04.040] [Server thread/INFO] [tisstring/]: Writing value 0 mode UNIT
[02Mar2023 16:17:04.041] [Server thread/INFO] [tisstring/]: writing 0 LEFT
[02Mar2023 16:17:04.041] [Server thread/INFO] [tisstring/]: writing 0 RIGHT
[02Mar2023 16:17:04.042] [Server thread/INFO] [tisstring/]: writing 0 UP
[02Mar2023 16:17:04.042] [Server thread/INFO] [tisstring/]: writing 0 DOWN

but then the Terminal module which i placed above has no text displayed on it (UNIT and INT are two diffrent modules, and two seperate displays) the module impl is at https://github.com/walksanatora/tis-stringify/blob/master/src/main/java/net/walksanator/tisstring/modules/stringmodule/StringModule.java

fnuecke commented 1 year ago

What's the motivation behind the cancelWrite?

Why I'm asking: writes are not immediate, they need to be consumed by a read. Think of it as kind of a handshake. I know it's a bit awkward, but this system is required to ensure consistency in the number of cycles moves take, independent of module update order.

So as I understand it, this module is beginning writes but never allows the reading module to finish the read.

If it's to ensure the code point is only written to one side, consider using the hooks for finished writes instead. See the queue module for reference on that. Edit: saw that's already in there. Should be enough I think.

walksanatora commented 1 year ago

so i changed it but now it is only outputting one char image left module is mov -25 up and right is mov 25 up (then aHLT: JMP HLT to halt the program) but it only outputs one 0 could this because i am reading value 0 of the StringBuilder

walksanatora commented 1 year ago

the only thing on the two upper screens is two 0s

walksanatora commented 1 year ago

after a quick code change now 4/5

walksanatora commented 1 year ago

it is outputting 7 4s on the left monitor, and 5 5s on the right

walksanatora commented 1 year ago

got it working