The Let's Play Archive

SHENZHEN I/O

by Quackles

Part 14: Post-Assignment Optimization #1: Holy Crap, It Works!

Holy Crap, It Works!

Omobono posted:

I've managed to fit everything in 14 lines
8 lines for the drinking loop, 5 lines for the clicking loop, one slp instruction at the end.

Suggestions:
I'm fairly sure you need the ACC register for the drink, but the DAT suffices for the click.
The light-up sign has a loop long exactly 10 cycles.
If you send two values before the slp instructions only the last one counts.
Why are you checking for all four cases?

THANK YOU! All four of those suggestions helped me solve it. I was able to create a ¥6 version.





Here's what's going on in all of this:

acc is still a counter, but it goes from 0 to 9 now instead of 0 to 4, and turns over every time unit instead of every 2 time units.

The first six lines manage the drink outputs. Normally, 001 (drink-0) is pushed to the expander (no tests passed - default case). However, if acc is 6 or more, 010 (drink-1) is pushed there instead and we run another test - in the final test, if acc is 7 or 8, 100 (drink-2) is pushed to overwrite the other values.

The next five lines handle the click outputs. dat is used to store 100 or 0, and the three lines in between the two mov dat p# instructions invert it. By putting it in between the two output lines, you can get the value and its inverse output in the same cycle without having to use a not gate.

Finally, add 1 increments the accumulator, but the fact that the cycle is exactly 10 time units lets me be clever. dgt 0 removes all but the last digit of the value of the accumulator - which is basically saying that it takes the accumulator modulo 10. If the accumulator is 0-9, nothing happens. If it's 10, it goes down to 0 again.

And then we have the obligatory slp.

This exercise has helped me think in assembly better. Thank you again!


P.S: A few fun facts and misc. comments:

• The new design uses about 3x as much power as the old one (496 units vs. 171 units for the ¥7 version), but replacement batteries are the fans' problem...

TooMuchAbstraction posted:

This is the kind of thing where I'd usually look into using memory chips. [...] Feed that to a digital I/O splitter and you're done...except that without an MC in the circuit there's no clock, so your animation would be crazy fast.

@TooMuchAbstraction - Good idea, but memory chips don't output automatically. There's gotta be a MC in there somewhere to pull the data. And, like you said, clock speeds.


Aesculus posted:

I hope your stomach is okay

🤔 What? I'm fine.

Aesculus posted:

Also fun fact: The characters on the sign (literally "add oil") is a chant/cheer that roughly works out as "Harder!" or "Faster!" or "More!" depending on context. I guess these signs are supposed to help fans cheer her on during a game?

@Aesculus - That makes sense. Maybe it's got something to do with the name of her sponsored sports drink, whatever it is.