├── .gitignore ├── README.md ├── day01-ez80 ├── .gitignore ├── README.md ├── elf_calories.asm ├── elf_calories_input.inc ├── elf_calories_input.txt └── output.jpg ├── day02-atmega328p ├── README.md ├── output.jpg └── rock_paper_scissors │ ├── rock_paper_scissors.ino │ └── rps.S ├── day03-xtensa ├── README.md └── rucksack │ ├── input.S │ ├── rucksack.S │ └── rucksack.ino ├── day04-arm7tmdi ├── .gitignore ├── Makefile ├── README.md ├── output.jpg └── source │ ├── input.s │ └── main.s ├── day05-jazelle ├── .gitignore ├── Makefile ├── README.md ├── output.jpg └── source │ ├── bytecode.h │ ├── input.c │ ├── jz.h │ ├── jz.s │ ├── main.c │ ├── solve_bytecode.s │ └── test_bytecode.s ├── day06-mipsel ├── README.md ├── build.sh ├── input.txt ├── main.S └── output.jpg ├── day07-mips ├── README.md ├── build.sh ├── input.txt ├── main.S ├── output.jpg └── sample_input.txt ├── day08-teak ├── .gitignore ├── Makefile ├── README.md ├── firm │ └── source ├── output.jpg └── source │ ├── input.c │ └── main.c ├── day09-powerpc ├── .gitignore ├── Makefile ├── README.md ├── output_cheating.jpg ├── output_part1.jpg └── source │ ├── input.c │ ├── main.c │ └── solve.s ├── day10-pica200 ├── .gitignore ├── Makefile ├── README.md ├── output.jpg └── source │ ├── input.c │ ├── main.c │ ├── program.g.pica │ └── program.v.pica └── day11-i586 ├── .gitignore ├── build.sh ├── debug.c ├── input.txt ├── main.S ├── monkey.h ├── output.jpg └── sample_input.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # File I use for monstrous objdump output and such 2 | */a.txt 3 | 4 | # Used for various messing around on the sample input to help make a strategy for the real solution 5 | */fuck.py 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | As a fun challenge for this year's [advent of code](https://adventofcode.com/), I decided to try solving each day's challenge in assembly for a different architecture, and obtaining that day's solution by running the code on a physical processor of that architecture. For each day that I solve, I will be uploading my code and details of what device it was run on here. 2 | 3 | To be honest, I haven't given too much thought to the detailed rules of this challenge, so I may add additional stipulations or exceptions as necessary, but here's what I'm going with so far: 4 | - I am loosely defining "different architecture" as "different first item in an LLVM target triple." This means I get to count armv4, v5, etc as all different architectures, which should make this significantly more possible for me. This can still get a little fuzzy in some cases of course, so I'm deciding most things on a case-by-case basis. 5 | - The physical processor used must actually match the architecutre used, so writing a solution in "armv4" assembly then running it in the aarch32 mode of an armv8 CPU would not be allowed. This is to encourage finding a wide variety of hardware to use, rather than 5 different modern smartphones. 6 | - Calling into higher level or library code is only allowed when it is necessary to communicate with the outside world, like to print some output or read the input file from somewhere. I have allowed myself to make use of the number-to-text functionality of printf-y library functions where available, because writing 25 itoa implementations isn't very exciting. 7 | - Emulators and similar may be used to debug the code on the AoC sample input or other manufactured test cases, but attempts at getting the solution with the real puzzle input may only be made on the target hardware. 8 | 9 | I doubt anyone else reading this is crazy and masochistic enough to attempt this challenge with me, but if you do, I would love to see what devices you end up running everything on. In any case, good luck and have fun with AoC this year! 10 | -------------------------------------------------------------------------------- /day01-ez80/.gitignore: -------------------------------------------------------------------------------- 1 | # System header, obtainable from ez80.readthedocs.io 2 | ti84pce.inc 3 | 4 | # Build files 5 | *.lst 6 | *.8xp 7 | -------------------------------------------------------------------------------- /day01-ez80/README.md: -------------------------------------------------------------------------------- 1 | Day 1 was completed in Zilog eZ80 assembly and run a TI-84 Plus CE calculator. The code was assembled using [SPASM-ng](https://github.com/alberthdev/spasm-ng) (`spasm -E -T elf_calories.asm elfcal.8xp`), then uploaded to the hardware using the official TI Connect CE software. [output.jpg](output.jpg) shows the output of the program being run on hardware. 2 | -------------------------------------------------------------------------------- /day01-ez80/elf_calories.asm: -------------------------------------------------------------------------------- 1 | #include "ti84pce.inc" 2 | 3 | .assume ADL=1 4 | .org userMem-2 5 | .db tExtTok,tAsm84CeCmp 6 | 7 | 8 | main: 9 | call _homeup 10 | call _ClrScrnFull 11 | 12 | ; Save these at hardcoded locations so we can restore them no matter where the stack is 13 | ld (iy_save), IY 14 | ld (sp_save), SP 15 | 16 | ;ld IX, test_string 17 | ;ld A, 0 18 | ;ld HL, 0 19 | ;call atoi_acc 20 | ;call disp_save_hl 21 | ;push BC 22 | ;pop HL 23 | ;call disp_save_hl 24 | 25 | ;ld DE, $4222 26 | ;ld A, $6 27 | ;call small_mul 28 | ;push DE 29 | ;pop HL 30 | ;call disp_save_hl 31 | 32 | ld IX, input 33 | main_outer_loop: 34 | ld HL, 0 35 | main_inner_loop: 36 | ld A, '\n' 37 | call atoi_acc 38 | add IX, BC 39 | ld A, (IX) 40 | cp A, '\n' 41 | jp NZ, main_problem 42 | inc IX 43 | ld A, (IX) 44 | inc IX 45 | cp A, '\n' 46 | jr Z, main_inner_break 47 | cp A, 0 48 | jr Z, main_outer_break 49 | dec IX 50 | jr main_inner_loop 51 | main_inner_break: 52 | ;call disp_save_hl 53 | ld IY, top_three 54 | ld A, 3 55 | main_top_three_loop: 56 | ld DE, (IY) 57 | push HL 58 | scf 59 | ccf 60 | sbc HL, DE 61 | pop HL 62 | jr C, main_not_highest 63 | main_dethrone_loop: 64 | ld DE, (IY) 65 | ld (IY), HL 66 | ld BC, 3 67 | add IY, BC 68 | dec A 69 | jr Z, main_outer_loop 70 | push DE 71 | pop HL 72 | jr main_dethrone_loop 73 | main_not_highest: 74 | ld BC, 3 75 | add IY, BC 76 | dec A 77 | jr NZ, main_top_three_loop 78 | jr main_outer_loop 79 | main_outer_break: 80 | ld HL, part1_string 81 | call _PutS 82 | ld HL, (top_three) 83 | call disp_save_hl 84 | 85 | ld HL, part2_string 86 | call _PutS 87 | ld IY, top_three 88 | ld A, 3 89 | ld HL, 0 90 | main_add_loop: 91 | ld DE, (IY) 92 | add HL, DE 93 | ld BC, 3 94 | add IY, BC 95 | dec A 96 | jr NZ, main_add_loop 97 | call disp_save_hl 98 | 99 | main_end: 100 | ld IY, (iy_save) 101 | ld SP, (sp_save) 102 | call _GetKey 103 | call _ClrScrnFull 104 | res donePrgm, (IY+doneFlags) 105 | ret 106 | 107 | main_problem: 108 | call disp_save_hl 109 | push DE 110 | pop HL 111 | call disp_save_hl 112 | ld HL, problem_string 113 | call _PutS 114 | jr main_end 115 | 116 | problem_string: 117 | .db "Oopsie, something went wrong. Good luck figuring out why!",0 118 | part1_string: 119 | .db "Part 1: ",0 120 | part2_string: 121 | .db " Part 2: ",0 122 | 123 | iy_save: 124 | .long 0 125 | sp_save: 126 | .long 0 127 | 128 | top_three: 129 | .long 0 130 | .long 0 131 | .long 0 132 | 133 | ; TI is rather clobber-happy with this one (and also needs the original IY) 134 | disp_save_hl: 135 | push AF 136 | push DE 137 | push HL 138 | push IY 139 | ld IY, (iy_save) 140 | call _DispHL 141 | pop IY 142 | pop HL 143 | pop DE 144 | pop AF 145 | ret 146 | 147 | 148 | ; Takes string terminated by value in A in IX, returns length in BC. IX points to terminator. Clobbers flags. 149 | strlen: 150 | ld BC, 0 151 | 152 | strlen_loop: 153 | cp A, (IX) 154 | ret Z 155 | inc BC 156 | inc IX 157 | jr strlen_loop 158 | 159 | 160 | ; Multiplies 24-bit number in DE with 8-bit number in A, returning result in DE. Clobbers A and flags. 161 | small_mul: 162 | push HL 163 | ld HL, 0 164 | 165 | small_mul_loop: 166 | tst A, $FF 167 | jr Z, small_mul_break 168 | add HL, DE 169 | dec A 170 | jr small_mul_loop 171 | 172 | small_mul_break: 173 | push HL 174 | pop DE 175 | pop HL 176 | ret 177 | 178 | ; Takes string terminated by value in A in IX, adds number to HL and strlen in BC. Clobbers flags, IY, and A. UB if number does not fit in 24 bits or string contains non-decimal chars. 179 | atoi_acc: 180 | push DE 181 | ;ld HL, 0 182 | 183 | call strlen 184 | push BC 185 | ld IY, pow10s 186 | 187 | atoi_loop: 188 | dec IX 189 | ld A, (IX) 190 | sub A, '0' 191 | ld DE, (IY) 192 | call small_mul 193 | add HL, DE 194 | jp C, main_problem ; Check for overflow 195 | ld DE, 3 196 | add IY, DE 197 | dec C ; Assuming strlen returned <256, which it would have to for the number to fit. Decrementing a reg pair doesn't update cond flags, wtf! 198 | jr NZ, atoi_loop 199 | 200 | pop BC 201 | pop DE 202 | ret 203 | 204 | pow10s: 205 | .long 1 206 | .long 10 207 | .long 100 208 | .long 1000 209 | .long 10000 210 | .long 100000 211 | .long 1000000 212 | .long 10000000 213 | 214 | ;test_string: 215 | ; .db "2703700",0 216 | 217 | input: 218 | #include "elf_calories_input.inc" 219 | .db 0 -------------------------------------------------------------------------------- /day01-ez80/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day01-ez80/output.jpg -------------------------------------------------------------------------------- /day02-atmega328p/README.md: -------------------------------------------------------------------------------- 1 | Day 2 was completed on the ATmega328P in (a clone of) an Arduino Uno. While it would have been within the rules of this challenge to simply send the calculated answer to a PC over USB, where's the fun in that? I figured it would be more in the spirit of Arduino-ness to display the answers on an LCD, so I did: [output.jpg](output.jpg). 2 | -------------------------------------------------------------------------------- /day02-atmega328p/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day02-atmega328p/output.jpg -------------------------------------------------------------------------------- /day02-atmega328p/rock_paper_scissors/rock_paper_scissors.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int rs = 12, en = 11, d4 = 2, d5 = 3, d6 = 4, d7 = 5; 4 | LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 5 | 6 | extern "C" { 7 | uint32_t solve(void); 8 | } 9 | 10 | void setup() { 11 | lcd.begin(16, 2); 12 | 13 | uint32_t solution = solve(); 14 | 15 | lcd.print("Part 1: "); 16 | lcd.print(solution >> 16); 17 | lcd.setCursor(0, 1); 18 | lcd.print("Part 2: "); 19 | lcd.print(solution & 0xFFFF); 20 | } 21 | 22 | void loop() { 23 | delay(100); 24 | } 25 | -------------------------------------------------------------------------------- /day03-xtensa/README.md: -------------------------------------------------------------------------------- 1 | Day 3 was completed on an ESP8266MOD chip in an Arduino NodeMCU module. I'm not entirely sure of the proper name for the CPU in this thing, but the GNU binutils for it were prefixed with `xtensa-lx106-elf-` so that's what I'm going with. Unfortunately I didn't have time to do anything cute for the answer output this time, so it was simply grabbed from a serial terminal on my laptop. 2 | -------------------------------------------------------------------------------- /day03-xtensa/rucksack/input.S: -------------------------------------------------------------------------------- 1 | .section .rodata 2 | 3 | .global input_file 4 | input_file: 5 | //.ascii "wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn\nttgJtRGJQctTZtZT\nCrZsJsPPZsGzwwsLwLmpwMDw\n\0" 6 | //.ascii "vJrwpWtwJgWrhcsFMMfFFhFp\njqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL\nPmmdzqPrVvPwwTWBwg\nwMqvLMZHhHMvwLHjbvcjnnSBnvTQFn\nttgJtRGJQctTZtZT\nCrZsJsPPZsGzwwsLwLmpwMDw\n\0" 7 | 8 | .ascii "dWlhclDHdFvDCCDfFq\n" 9 | .ascii "mGdZBZBwRGjZMFgvTvgtvv\n" 10 | .ascii "jwwJrzdzGdSbGGnNlzWczHzPHPhn\n" 11 | .ascii "cczcbMBszhzzDBTBPPPGjtvtlt\n" 12 | .ascii "LqJLfpwdLnvQLRGQjGtj\n" 13 | .ascii "gSgnSJJCGSGpGSrwgfhchmmmHzcrHDmbrmMm\n" 14 | .ascii "bVjstCsSstCLCrbSLnMpdMndcLddcqcpHR\n" 15 | .ascii "wPZJQJwtBfJZmgBwPTcpTdcnfHMppcGMdG\n" 16 | .ascii "gmFJzwPJJtszvNhCNC\n" 17 | .ascii "DmjZDMZWDqGRqqRpHmmRLTTNTPTfCQJQQLJHTClc\n" 18 | .ascii "FtzfvrfFwVgtzztgBLJNcNlTcTVNNQLN\n" 19 | .ascii "vgsdbzzrwtqWfWRpZDdZ\n" 20 | .ascii "rJhqRhLHhdcQqdHqfQGfPGstgGPlWttM\n" 21 | .ascii "DzCpDDmnNCmBZBZnVBmZzBGPfsbglfNPwgPGPMWsWWft\n" 22 | .ascii "BZFnlmpBpBzDzVZmhFHFrrrchhRqTdrc\n" 23 | .ascii "DWCCWFNqdGFdPVcb\n" 24 | .ascii "HllttQsTRlJlsblrHlhdmPLVcVcTccndLvPLmL\n" 25 | .ascii "HSlstHgJltghhRrzNBNDzSwMjNZwNb\n" 26 | .ascii "dzGSHCWSsGVVSdHVHHWWVVDCgJDpQqLTTRJpgmTLRmJTTpTR\n" 27 | .ascii "BvNjMPZMBtBBMvvNMNttlhLQqCJpLmhTRQqQJgRJLQQg\n" 28 | .ascii "llNncBlMCwwMnwPZrGsVHzcfFGdHGFGs\n" 29 | .ascii "JfZhphMMQmFzDTDjSdrQjQ\n" 30 | .ascii "sqHCbCwBVtbqbCqtrWdjzlSJTlrTSWBn\n" 31 | .ascii "bHcwbGCGRssNscwtHNbwvmRFvpFFJFvLZMmPLFfv\n" 32 | .ascii "qBCrzznVmDCmMMDNgrgcrvHHcgbQcW\n" 33 | .ascii "TTTsdJRTRhhlsgbvbdCFdbWvbQ\n" 34 | .ascii "JhGGlfRlJsnCMDMqjmfV\n" 35 | .ascii "rqLLvDLtStDLQhQDQrQhhNdsmWdmmjjnssPnTMnTzfTsWT\n" 36 | .ascii "ZRFFpgCgppcBcnjTsjTMTfPFMP\n" 37 | .ascii "GCZpGlwJwBgGHcJhSSHLDDrNqrMtNq\n" 38 | .ascii "FsPFqsDNZFNnZrcBmWfWWQ\n" 39 | .ascii "lSnRlRTvgrWtctTmft\n" 40 | .ascii "SMbGbbvnGlnSDwGqLwNCqNVD\n" 41 | .ascii "dPQDcBwJJDgDTPgGgQTBVjSsmLhLTrLmjSLpjSLh\n" 42 | .ascii "MvvZRHtMtbCNvCNCNtNvbRfBSMSrjmLpjnjmVhrVSLsnnmSh\n" 43 | .ascii "qHZtbBZfRztbHbCzNRHPQgJPJgGgglFPPFqdQD\n" 44 | .ascii "MsBsVDspRPfPlhMl\n" 45 | .ascii "zWnCFzHbSCwqNmPSjmGlsmfN\n" 46 | .ascii "FnHnFbFzsHHCCgzCzbBptVppgvvVgVrpBrJt\n" 47 | .ascii "pTLntptZjQLfVDjQTDlVJCSWNCPSCCsSNmFlNslm\n" 48 | .ascii "BBHbqGHHqgwSWSCCWwZWWZ\n" 49 | .ascii "qRzbhhbzzrHdRRHhRHvzZjfrVTrppVQttDfcQTfp\n" 50 | .ascii "DHsdHPHHsHMsRmhMZZQBtljgZGtC\n" 51 | .ascii "NFnCbFznLVJbVrjhQthjGBLZBjGL\n" 52 | .ascii "wNrfFJJbCpNnfbdwDSDHsvsHmsmH\n" 53 | .ascii "jLZRjnMMjJhJnvtQbdHfHZbvHQ\n" 54 | .ascii "mBzwptCWlcFCwsHSTpQfQHQfrpTb\n" 55 | .ascii "mNltzmsCNmFzGwCBllGRgRgqjgLMnGqjnPjV\n" 56 | .ascii "ZqqcqmVVtbcBMFfFMcQfgphJ\n" 57 | .ascii "HLWLDvWjjLwTWzzvGLThQQshQllgJDJgfbffJQ\n" 58 | .ascii "vHzLvrwwzGzTRGzzLLRPRwRdSVdnBBdSbBSVStbNmnrmZS\n" 59 | .ascii "TWVVvPSgwWSqcRgRwbRRcqshsfFzzzChTGNHzHhhhCsG\n" 60 | .ascii "njZrjMLlpmDmGfSGtrNttzCF\n" 61 | .ascii "ZQBmZdDBZRRPRSBgcb\n" 62 | .ascii "TpntvdpnZDptnbnTDGtSFSlFmzCzzmSFRjqlZj\n" 63 | .ascii "MWrNcWRMlgqzMjzq\n" 64 | .ascii "NPwsPNrBNcVHNNcJHBNBcJwwttDvGVnDptVRtbnTtGvVGtGG\n" 65 | .ascii "tsbbvvSfnqvzQLLBjfMLdd\n" 66 | .ascii "gJRmRNmJNchgmmrFJhFgWJQMwBnjwrMBVQwQTBdLdVQj\n" 67 | .ascii "GcGpGGRGJgqstvpbnCqb\n" 68 | .ascii "rsHcrbZHBTTtLtNSwwHLLJ\n" 69 | .ascii "mFqhWVsjsVCjQlNJGMwMlMMGMh\n" 70 | .ascii "QggzffQRCfgVFWzzCQffqfZpZDcRvTTBTvvZnsdnddcn\n" 71 | .ascii "bPFMFFBpMlFfMZMpHGNSrNctJcPSSchJchPt\n" 72 | .ascii "zCgwnmgzQDnQgdWWQRgqSrqLSqSgssLNJhgJ\n" 73 | .ascii "rQCQQTrRRmDBFfbHBFHZbT\n" 74 | .ascii "fzfPQsGrrMMjtHtBHs\n" 75 | .ascii "SwNNDqwhWpVTwbDGGDmwSVhZRZHdbCtgBjCRjMtbBHtRMd\n" 76 | .ascii "vVTGvVGNvPPvQvfncJ\n" 77 | .ascii "cwzMJbclHDPqfJQPfq\n" 78 | .ascii "rrqjjTBrqqBjRCgTjrRjNrsGPDhDFGCfWGfPFfFPGWfD\n" 79 | .ascii "BZTTSTZgjbSwVptvpq\n" 80 | .ascii "PPPPJpvpJsJwPHHPsJdTNZRZZZjTFFmRRRNjZd\n" 81 | .ascii "qbWVfChDCDnVVDGfnSFNNjRLmNfBNLQjLjmBRm\n" 82 | .ascii "DhFDhbnWCDhGcbJPPwrsrMwrvlvc\n" 83 | .ascii "lFSDTwHTSwlTNwFFlwNcFFpjLZvZqvnqLPnnWbgngbbncqbZ\n" 84 | .ascii "rzQfMzRGrRGJCffBMGdGsJZWWnqWVqdPPgNvvVZWPWWn\n" 85 | .ascii "RJrttBtNQCsNzTpShhHFDwFlth\n" 86 | .ascii "QNzQFjNFrQPNbmPpqTTDGswWmB\n" 87 | .ascii "ggHRcSlcCVCSzMVqDGwgqTWpsmqwqG\n" 88 | .ascii "cltzCZtLClHRRtMZZLQjfNvtrJfhvrddvNNd\n" 89 | .ascii "mcfWHffBFnQRQlTFdv\n" 90 | .ascii "wssSLVbbzDVbzbggzSzNshNMnvnljRdvQRlMBjvQdnCj\n" 91 | .ascii "bhDzVSSJDDJhDLBwtbDzzbbWppfpcmWGmprqqGtqprcHPp\n" 92 | .ascii "rpVFrZpgHWSZrFPqhzwcqPwmcVBD\n" 93 | .ascii "vMTnQJjQLCbljvvQzTMbTjPNdBLwwDhmhNNqPwmmhhBh\n" 94 | .ascii "jvGjjQJnrspGHgFz\n" 95 | .ascii "sjssjtZlcphZHwWvcrHTwWJH\n" 96 | .ascii "qDdzzrFNNNDGdFDzzVBVVvfWJPfgPmgWPgvwVH\n" 97 | .ascii "nqMQGDrnLGnqqLNqjtCZZjsMhZhCMbtl\n" 98 | .ascii "JJJsLFmzsrFlSpzPscjgHhnRnmvcjqRvvj\n" 99 | .ascii "fCMQbCbTjjqTGhjc\n" 100 | .ascii "bfdbWdCddfBbtCfbfbqVWQQpPlBrJLJJSSLwppFssFzLzp\n" 101 | .ascii "pdbbzlffWtJbgQwhcphQcCCg\n" 102 | .ascii "vHvLFvVLvSfFRLnRFRNHjPjggcssQcjjsnwhsPCC\n" 103 | .ascii "vGVGGFFVHLTvDRHDmBbTzfZWMdJZlfMm\n" 104 | .ascii "wjCbjQgjTQhNNzgWQCWrDFMZmZDZDCrrMDpLpL\n" 105 | .ascii "czGSPznnRGGJGGlVVRVBGGlBmDDcMDFDDZLqfffZFrrZqFpZ\n" 106 | .ascii "JPGlvBSJHVGnVsjvQjjzwdwjzd\n" 107 | .ascii "MFlWQHDTpnpsFNNQllWFWlhzjGgrgDzGGhGGjvmZDZrh\n" 108 | .ascii "PtTPcTLbBCVPTRVcvhjmmhVhSZGGgvZg\n" 109 | .ascii "JLPfCwPbTbBPJCfblplMpqWsMpMwWHQn\n" 110 | .ascii "QbHVBBzWtzHBNtBwQSgqhqSbFgRLjhmqqj\n" 111 | .ascii "ZnCnMcdsDnJTncggFJwRmSwgRFmL\n" 112 | .ascii "sTMZpGDvsZcMpcvTCPHwzrfzrpzHpWBrWz\n" 113 | .ascii "PMdJWwJWHFWJnNzbDlfbCfMvbl\n" 114 | .ascii "rZgttrFptFFcBtccbbCDvgfbGCGGgGDz\n" 115 | .ascii "QsZBmsrFscrVrjQJjJQRJWWLwq\n" 116 | .ascii "GwNNJwwRThwrWfhh\n" 117 | .ascii "SmQqmzsjHssQzCbvsmSSzsQTjWpFTTfFfThchhFTBBfppB\n" 118 | .ascii "mmbHbmtmCzzQZzQRdZJhNMdMlRMglh\n" 119 | .ascii "rrsPbncQvvgnnrTdGDVcCdpZHHZp\n" 120 | .ascii "RwwwhjLLqtJFwjzwtwmwwGpDZVdGDVdZBZDFHdHZCp\n" 121 | .ascii "zhzwLhhfffLtjNChgWbbrbnMvPrMrrfv\n" 122 | .ascii "tQMtQtTSBFtSmQSttMggMtbtnTnPrZvrnzNNTGZvrZZdLdnL\n" 123 | .ascii "HqhwDpDcwlHqpVrrFzvFGpZrrzrP\n" 124 | .ascii "RwlhhjwRCjVfjDbMtFWBWJMgWjWm\n" 125 | .ascii "WpWVlWzsGlBJpspNclNlhhhmgzrdtzQMQttzMmtt\n" 126 | .ascii "RfnPRLTPDHRdPbwvvntnSrFgmvnmtm\n" 127 | .ascii "CwqRDCCwqCwbCTqJcJBNcZqdVcBlpJ\n" 128 | .ascii "tpfnNBsGGNRppRCgfgRRCRQJGMPPWdwMJdWFFwjVzGPJ\n" 129 | .ascii "chLSchLTbLqvqcZLlvvLqbmldMzFFWdzVSFWFMzQVJwjQjdM\n" 130 | .ascii "rLqqcjDrcvhRsDfHDtNNnN\n" 131 | .ascii "DjZjvTTDqrtTZZSMcdRdmRJrcJNc\n" 132 | .ascii "HWgPGVhFPgnSVtnJcdMs\n" 133 | .ascii "FPLfBwCWGPfCwfLHCCDBZlbDpBjvqTtDzzDj\n" 134 | .ascii "FJNqNFgNFssqGGqBsTlMVcgVrCwLwlhcrw\n" 135 | .ascii "fRZzDmDZvvDdZbtdpDZmbrThrLMCvcChwwlSTrvMSr\n" 136 | .ascii "zmfZmtZmpDmbfWRDDZdqFljqnNQjGWnsjFqGsG\n" 137 | .ascii "rMdMWddmJmvdSdmWfWMddpVRqRFVHRRqMRRPQMRqRq\n" 138 | .ascii "tDGtGGhLjLLZNLjjNgNthGtqHTVqRVVpPDRpHHVRQVRPPR\n" 139 | .ascii "ZlLtzNjgsZZlssLgtjNpfWfJvlJrrvCJfBmBfn\n" 140 | .ascii "hqpWvFJsJFNHhqMWNhWvWRmmDcDMLcwZnjcwnjRnjn\n" 141 | .ascii "LdrlgCCrSSTrTnwRjmwRQZwdwG\n" 142 | .ascii "PVlfClrLlLlfggtBPzHHhHFbWzJNbvqJFNqF\n" 143 | .ascii "TbbQtnDtbGGjGlGsGHpJJmFWFJJrBWWFlWrS\n" 144 | .ascii "CZzzNzzhddNchhMhhRVjpCBwBrCvJvpmSCvrwJ\n" 145 | .ascii "fhZZhddRjRgZzMZRzPjPTsLGQtHLTHTbDPQTtqPT\n" 146 | .ascii "nHnWsQNQQWTWQshwjBJJJmHwFBwm\n" 147 | .ascii "VZZpfbffZVvbSbGfBhSwmtmmJlmjJFJJ\n" 148 | .ascii "bpphpMfMvMzDbMGZgQNrrngzdTsNqWdd\n" 149 | .ascii "VPNddVTPPmdnVcPVZcdTmcDbQTFjMpjtFzbMtFjzsFTssT\n" 150 | .ascii "lJCllWCrgvRlgwlJfRRvSzjSjQpbzMHpbwMQpszM\n" 151 | .ascii "fRhGBBJJCgrNLsNPNVVhNq\n" 152 | .ascii "pLrVDgbNbjVplpsltHBqWSqhSQcHDttH\n" 153 | .ascii "MCdCwCGTmnTmmmvTTCwCqNhHQhRWcwHWBRHSqSQH\n" 154 | .ascii "TNTFFPfffTvFTJvTPCPTFfGdzVjspVLZglJbsbZpVblrzjlb\n" 155 | .ascii "cdPzFrldgcdCrnlznPzrBNRssLLBbVNVZsLHRHdm\n" 156 | .ascii "wTQQwvvtqwqcGvTZmVHBbVLLBbRV\n" 157 | .ascii "GWJSGfJWcjQwhQQWjqJhhGfgpMnMzDnpMlPpMnDlMrzl\n" 158 | .ascii "pMhqTTsSpdBPpNBshsdMMTQFvFlQtQWCRQlCllVFqVqG\n" 159 | .ascii "dfcbnmrnjzRFvGQQGvfv\n" 160 | .ascii "mDrjLLLcJjLhpZSSJMdpph\n" 161 | .ascii "NGZNwqFqZhhcFSCfRzwdzRfCzVRw\n" 162 | .ascii "QTTmBTsWQWJPPCvzvpHPzdvVFR\n" 163 | .ascii "bsmWTBbQDbmbLQQMsWWQchgqLqhGGGGZLhSFjhqS\n" 164 | .ascii "HgmGlgsvBBDgBGCdHHvHwCGwhZJWhTjSdhTSFFFhJtSJTJhT\n" 165 | .ascii "RQfVrfQNszMQfpMzpNnfLbtjhtSbWJWFWtFFtFJtFSZq\n" 166 | .ascii "PNzLfnLnBCPHgsgC\n" 167 | .ascii "mTZGgCdNSNmCQLLpPnDhRlGhpV\n" 168 | .ascii "vWJHWFsfHMWBBFbBsjfjHrFfLRRLPPnpLthttRVPLSnhSPbS\n" 169 | .ascii "fzMrBjWfBrzsZCZmSTgQzcNN\n" 170 | .ascii "mgmCZCMgmnZmZgBZpgpJfbQfwSQPDTdfdwSDfwhn\n" 171 | .ascii "sHhcrWLcFlzHcHRNNFvNFcFPwDDTWdddDdqWbSTWDPTTQS\n" 172 | .ascii "RNsslsRrNcRNvNRFFNvVsghZBJtVCCtCtGghjhGBGG\n" 173 | .ascii "gchrcRRdnRwPPnvQ\n" 174 | .ascii "CVCCSrDjFHjVDbBLFGGBSvwnwNMnMsPPNsNPvwPQVM\n" 175 | .ascii "lHLCTHGDCbbjFTTzdWlpcqfgcrdzZg\n" 176 | .ascii "fRDPsDsqqJttttJSzPDgJWQCbQQbGMWCCnGGPVGVQQ\n" 177 | .ascii "rTTBvZhrvBnWWDWCbZWW\n" 178 | .ascii "cwLlTLpjTwBFLLhgfRRfmRqRDmRdjq\n" 179 | .ascii "sprGGPTrJTsGPzszqGzNtTtpfbQddQSQSDFDFvvbZvwFbbfN\n" 180 | .ascii "LWWCMVmwMmgWFQfFDDvZDgdF\n" 181 | .ascii "mlMmRVCWVMmmHRjVCmjHWRhMzpTtlrlPzrtzwlsGPrpwtrJp\n" 182 | .ascii "tsfwwfjfdfrtrClfvwvvLnTHNmvLHcNccRNcvNWH\n" 183 | .ascii "qQSqZqFQRBzghDFncHgmccHNmWcNmM\n" 184 | .ascii "SQJphFJzRDSsdpVlllrCrw\n" 185 | .ascii "vGQqLQFvBvLvdNnvjnvNDc\n" 186 | .ascii "TRJwmWmZWlCCmzznbNhhbDhRgj\n" 187 | .ascii "CCTtDTlmDTWTmDmZZlVLLsFfstfFFLsBLQfF\n" 188 | .ascii "cfWflMmWWlWfPWBhBlQtLmmvrrrvCLjvRTjLLwwr\n" 189 | .ascii "gSgbsbgHdsjzHbqbdVDLZLvTZwLTvSrZrFvZLw\n" 190 | .ascii "sdbJqDNdjJNdsJBpBWpJlMcfcB\n" 191 | .ascii "FHlMHPqDLlPctgHSnttCSC\n" 192 | .ascii "zhrmBrTwJTjBmQcSQvQqbtwGvg\n" 193 | .ascii "jBjmBmJjjjRZTBzhhrBJLDdZqfpDMdfWWlDDLMlV\n" 194 | .ascii "zPVdbsBzZdwqJGhrLTvNNJqH\n" 195 | .ascii "tmmCgCPCDDnptHDjNvGvhrDvLv\n" 196 | .ascii "pRWRlpSpPllClnpbQVQwFFVSQFVBZz\n" 197 | .ascii "nDrCvmvMnMSmsCvblBzzCZplbJlTbZ\n" 198 | .ascii "FNRtFWRfcGqFGQbzlZTQqQTBbd\n" 199 | .ascii "GRwFfNtwFRNFGMvBsnnwMMMBjn\n" 200 | .ascii "LVTBjjlJCDrnJzJNQR\n" 201 | .ascii "GsGGsggGpfhgpchgdqzbMzzhzQRnnMRrNzzR\n" 202 | .ascii "PwWFqFGpwWpdWgfsGggdmjCVHPHlCCCVZNCjVmVj\n" 203 | .ascii "qVTsCWwbCsPlCVfcbvfPDgLzbzDDhrzRrjgZghgr\n" 204 | .ascii "ntmHmNpSQNGtntNttmSdSdBdjrrDLQZQLLhRrFFFRDTFZhDF\n" 205 | .ascii "mtMtBNTSNBpNJStMGSdHppNcVWPsWvqVcsVJfwwqlqWqlc\n" 206 | .ascii "vvWzLvvdpZDvhTpcrLcTTLpdwSPnCfJwCMnQSMwSnCGJrnwr\n" 207 | .ascii "ttHVmVNNsHBBRsHbMMwwnjnjBfjJwCMP\n" 208 | .ascii "tsVllgNVqbRlfplldDvDWT\n" 209 | .ascii "mLjLsQqLQqsBRvvlRBLRlT\n" 210 | .ascii "bhgtDDhCtmptmTTS\n" 211 | .ascii "nfmdbggwGWrfsPzfWq\n" 212 | .ascii "JpWDcSGJpGzsHPSSlbbd\n" 213 | .ascii "wVRqVZwwRwPDwbDddH\n" 214 | .ascii "VtVVVLthLVtVgfQLRTNtqDcCcJBmmWMWWprpFrcBJWNp\n" 215 | .ascii "dhhhDtmLdttdPlslGlRFjfzBBpzzRpGJ\n" 216 | .ascii "QMrVMwbVrrbvVVCrvcnqQQrrSMBJfpjFSzfjJFMFRWSpjjFG\n" 217 | .ascii "cwvbHHbCqVchRDHgDsPTdt\n" 218 | .ascii "CgVNCtDsDtJGZZGqMMGhDq\n" 219 | .ascii "cLRnSHgWcRdLHWSSRLjQdlHBTTPcPwwhzqzTMBPTwhPPwP\n" 220 | .ascii "HnnnglnWWgdRjlmQNsNFmJCFJFvsJsNN\n" 221 | .ascii "hfccLbjhfSRbfDZjFRJzrlvlwwlnnFrWwzqr\n" 222 | .ascii "TCsPLNtQdpdQQVtVNvJNJWlzJzwlrvJl\n" 223 | .ascii "pHtPsPtPtCQfbRHHDHhMLh\n" 224 | .ascii "nWRWgLtWnfTcZNNsscfd\n" 225 | .ascii "JMGzMVJwMVTvzVQFGHMMmPdddsPsCjldlHPcScNPsP\n" 226 | .ascii "vGrMQQmmvTQzMJpghWRWgpbbBqLbLR\n" 227 | .ascii "WSbhFbPTpRfTfPdhpfbhSbfPQLzlQlzlHvtQsvlltlsgHdgQ\n" 228 | .ascii "pZcGJDZNGcVrJwrDrrnvtNvlNzsgtgzvvsgt\n" 229 | .ascii "qmJZZJcBqwrMJcVbWfSPPWpmpjmSCF\n" 230 | .ascii "jHVjjCcpNrDgjsfB\n" 231 | .ascii "ndqllRvJQtqlQQTRWllFNDrsMZBfDBLvNMNDfsbZ\n" 232 | .ascii "qTFnWJqdWRdqWRlnTRnQGnTmwwSHCzpcGNmHNcPVcHGmCz\n" 233 | .ascii "pZCpBhDfvgBVZQGMMVZVlq\n" 234 | .ascii "sLsLTTSssjPnTNbFGRGFPVHqMMRF\n" 235 | .ascii "TsNSccnjLdcsLjdmjWvWvBhfmvWpCGhGhD\n" 236 | .ascii "VWFFFPMpPVSMbTppHTnHTbRH\n" 237 | .ascii "DtvfNdBNddDNSLjsvDTTHnzzHwrTrwsrwqbT\n" 238 | .ascii "dgBLNffdgjjtfBQSvgNjNDlvMcQJmJJmZCMmVVVZFPFcPMGG\n" 239 | .ascii "VWsQLHMVVSNRShWLhNSNLjbbbddbpDZDddcbZdDRztpd\n" 240 | .ascii "FPlhhgPvThGFJndnnCCnJzzdCp\n" 241 | .ascii "qrTfmllGvfvGqwNMMMsffsQsNh\n" 242 | .ascii "NsmFqNlmnQRbCFsmJgSffpPcbvSfrVvpgS\n" 243 | .ascii "LhZGDZhhwtDHMwDdHGhDjDpTzzPdzgTvcPvpSSpPrdrv\n" 244 | .ascii "jgHMjBLhwtZMHMHmJNNJNFlBqlBJNn\n" 245 | .ascii "bznSQggscgMcSTTfJbSQzQFwClMhmCmthClvMwFLwhZL\n" 246 | .ascii "BRWBPBVVPjPNVHpVqlqrvtwFqmmLqltZmL\n" 247 | .ascii "WDVddNHNvRgccgsDsgbT\n" 248 | .ascii "sNgnQLtLLLPPnsPpqdqjBclpGWjcWjBG\n" 249 | .ascii "rVCChSZhVrrwqVDVHSHmMjldGfJGfHddJGJlfGjGJj\n" 250 | .ascii "CVZmDvZCmmhFVVrCgTNbbnQFgbsqNqNQ\n" 251 | .ascii "WmMmSSfJNRRPfJRMRMtllCgdStgbgttgCdDd\n" 252 | .ascii "QGBrvzwBczlgqCtDbvDq\n" 253 | .ascii "QQpBGFrLQjQzGVVRNjPmNNWMbW\n" 254 | .ascii "gGljnJhnJtllpNVCHWcccdTdjdmB\n" 255 | .ascii "bLfSQDSMSHmBnwCB\n" 256 | .ascii "LFMDrbFfFQZQRzLZnbgtlsRGtltpgNhgPpPG\n" 257 | .ascii "cRThZZchCThtgTRhZTRtjWFjWNwqCjGmwFjqqffC\n" 258 | .ascii "DPDPGzPMHDbrpqjfwrjqmjmp\n" 259 | .ascii "JVHHDdVdVbvGMdnVdQVdDbHcRZllhRtgStRLThRSTcBTvc\n" 260 | .ascii "lQWPSBrrPZGgPglGssDfHnWsfDFHHvHh\n" 261 | .ascii "TDCqpttptJNLtwNpbwTqzqHshsvsMMFnmHMNfssmvmvf\n" 262 | .ascii "JCjqVpDtrBjQjrlj\n" 263 | .ascii "wFGWGpFLvCczNSWWsz\n" 264 | .ascii "tlfgtftjlbtHHlDBsBzmQQnsQDQsCn\n" 265 | .ascii "gjfrsVqVgPlfqhvLdvdwZhGq\n" 266 | .ascii "pHpZHBSvRvRCBBZCTMngRnWndnRmWcgg\n" 267 | .ascii "jsfrfrjJFDwDDMMggMCGWGcfmG\n" 268 | .ascii "qbCszCjtCjQsQrtZVBHBHvBvqLZvlp\n" 269 | .ascii "scFzsPScNgNPNgQzpttlCBCwpLrMLCrDdljLwq\n" 270 | .ascii "TjfGZZjVwMZwMLwr\n" 271 | .ascii "vnGbWTvTmFRjQFQPsb\n" 272 | .ascii "bVLrzqrzJVgJbbtVrWJVgppcBCzBvdzwBCCBHDcBvc\n" 273 | .ascii "hflPQnMQmQSRlQMPNRTHwwHHHqpHpdfwdBCp\n" 274 | .ascii "hFhZMhqSNMNbrZgWWGWJjZ\n" 275 | .ascii "NJsgNjJlMHQrwnRgSRPwrP\n" 276 | .ascii "tqpQtTFpFvbGpzTTWSrnSbrhwChCnRfrCf\n" 277 | .ascii "GtcvGqQpttzcqdFzWppDsZMJjBBsBJcBNmBjMsLJ\n" 278 | .ascii "lGfZGZhFfhdSWqmFFWSS\n" 279 | .ascii "wDRDPLcDnjtWbSmqrSCSLC\n" 280 | .ascii "MPwmtVnVMjztznHPgQhQfJfvvHHGggQZ\n" 281 | .ascii "llTspLllCHmLHHndldqHdlLQQPSBQczZSFDDQZSNGcGG\n" 282 | .ascii "jMhwvVrRjbRhFBZNGPcGNN\n" 283 | .ascii "wVtrrtRwrfrwftjVjwWvMrRpsqsnsHsBglslCmTsdWdHTd\n" 284 | .ascii "vPvmTGgDPRvGpDPGPqGHQnWJQJMBBzJBlBQWlHWl\n" 285 | .ascii "bfbwNsmwFdLjbfrrLsSfLNQtMllznBzJQZMQtMlZZnnF\n" 286 | .ascii "frssSscssNfScCjfSCwjsDmRDpGmDRDvvvVcvRDvRp\n" 287 | .ascii "LtlPZPjBTbWsWJVJVzdT\n" 288 | .ascii "nnprqhrqmzfrSrphqfCChVVGVDJWgSHHWgWsRDVHWd\n" 289 | .ascii "nrmppNqhcCrfMchcMCncqbzPZvlvlwbBNjPjtNjZjL\n" 290 | .ascii "FPWsFdSspVbbbtWVvl\n" 291 | .ascii "CCHnnfHHvCwtVMhzlzDllC\n" 292 | .ascii "LrGnjGfgfvcwfgrLrBjrBLgwdBTSRBFsRZdRsSqFFSFSSPPp\n" 293 | .ascii "whGCLqsrjgGhhGFqrCCFGCGzTRTZJcNnzlLTnznNHcnzTH\n" 294 | .ascii "ddvVmbfvdvVbDVQdvvdSzpNcnJzlzSRHNJpnJcSc\n" 295 | .ascii "BPdvfQdWtPDDPfDvDQVVPmbhssCGGMqgFCFMqGMWgMjrRw\n" 296 | .ascii "PSLbGmWPSPLQbMTPWGFWltthdDdrmBDHhdDdczzDRh\n" 297 | .ascii "VfCngVfgsZwCftrZdhcZrdNDzz\n" 298 | .ascii "CjVJJJqnJwQhWPPLQlGj\n" 299 | .ascii "ntnnQmTQTQGVWGNGNNlClG\n" 300 | .ascii "jDffjMSvqjHzHHzwNVwNVcCddPVNdD\n" 301 | .ascii "ZszJsrrZMjsHqqvZJLRQCbTRQbJmThbt\n" 302 | .ascii "BgLHgFDsJNWgQgflWd\n" 303 | .ascii "mnVVcCHnCGRcVnZSjmlthftMQddlfhQctNfW\n" 304 | .ascii "qbSGqmHSTFprvpvTTL\n" 305 | .ascii "dvdTMvvpdLpTcSLvdLLMmhfFBftwCNhRwRNjtCTRCf\n" 306 | .ascii "lshQWgsgrHHqlFfRqFjRFfFwCB\n" 307 | .ascii "rsgHQbJbrsGHHlgQHgJrlHrPZdhdpMZGDSDpdPLcZhdvhZ\n" 308 | .ascii "\0" 309 | -------------------------------------------------------------------------------- /day03-xtensa/rucksack/rucksack.S: -------------------------------------------------------------------------------- 1 | .section .text 2 | 3 | .align 4 4 | .global solve 5 | solve: 6 | addi a1, a1, -16 7 | s32i a10, a1, 12 8 | s32i a9, a1, 8 9 | s32i a8, a1, 4 10 | s32i a0, a1, 0 11 | 12 | .literal inp, input_file 13 | .literal letters, present_letters 14 | l32r a3, inp 15 | l32r a7, letters 16 | movi a8, 0 17 | movi a9, 0 18 | movi a10, 0 19 | 20 | main_loop: 21 | l8ui a2, a3, 0 22 | beqz a2, main_loop_break 23 | 24 | movi a4, 0 25 | strlen_loop: 26 | beqi a2, '\n', strlen_break 27 | addi a4, a4, 1 28 | add a5, a4, a3 29 | l8ui a2, a5, 0 30 | j strlen_loop 31 | strlen_break: 32 | 33 | srli a4, a4, 1 34 | movi a6, 0 35 | first_half_loop: 36 | add a5, a3, a6 37 | l8ui a2, a5, 0 38 | call0 letter_to_index_a2 39 | add a5, a7, a2 40 | movi a2, 1 41 | s8i a2, a5, 0 42 | 43 | ssl a10 44 | movi a2, 1 45 | sll a2, a2 46 | l8ui a0, a5, 52 47 | or a0, a0, a2 48 | s8i a0, a5, 52 49 | 50 | addi a6, a6, 1 51 | bne a6, a4, first_half_loop 52 | 53 | second_half_loop: 54 | add a5, a3, a6 55 | l8ui a2, a5, 0 56 | beqi a2, '\n', second_half_break 57 | call0 letter_to_index_a2 58 | add a5, a7, a2 59 | l8ui a0, a5, 0 60 | beqz a0, second_half_not_it 61 | movi a0, 0 62 | s8i a0, a5, 0 63 | addi a2, a2, 1 64 | add a8, a8, a2 65 | 66 | second_half_not_it: 67 | ssl a10 68 | movi a2, 1 69 | sll a2, a2 70 | l8ui a0, a5, 52 71 | or a0, a0, a2 72 | s8i a0, a5, 52 73 | 74 | addi a6, a6, 1 75 | j second_half_loop 76 | second_half_break: 77 | /*addi a2, a2, 1 78 | add a8, a8, a2*/ 79 | 80 | add a3, a3, a4 81 | add a3, a3, a4 82 | addi a3, a3, 1 83 | 84 | movi a2, 0 85 | movi a4, 0 86 | memset_loop: 87 | add a5, a7, a4 88 | s32i a2, a5, 0 89 | addi a4, a4, 4 90 | movi a0, 52 91 | bne a0, a4, memset_loop 92 | 93 | addi a10, a10, 1 94 | blti a10, 3, main_loop 95 | movi a10, 0 96 | find_common_loop: 97 | add a5, a7, a10 98 | l8ui a2, a5, 52 99 | beqi a2, 0b111, find_common_break 100 | addi a10, a10, 1 101 | j find_common_loop 102 | find_common_break: 103 | addi a10, a10, 1 104 | add a9, a9, a10 105 | movi a10, 0 106 | 107 | movi a2, 0 108 | movi a4, 0 109 | memset2_loop: 110 | add a5, a7, a4 111 | s32i a2, a5, 52 112 | addi a4, a4, 4 113 | movi a0, 52 114 | bne a0, a4, memset2_loop 115 | 116 | j main_loop 117 | main_loop_break: 118 | mov a3, a8 119 | mov a2, a9 120 | 121 | main_done: 122 | l32i a10, a1, 12 123 | l32i a9, a1, 8 124 | l32i a8, a1, 4 125 | l32i a0, a1, 0 126 | addi a1, a1, 16 127 | ret 128 | 129 | main_problem: 130 | movi a2, 999999 131 | j main_done 132 | 133 | .align 4 134 | letter_to_index_a2: 135 | bbsi a2, 5, lowercase 136 | addi a2, a2, (-('A') + 26) 137 | j letter_conv_done 138 | lowercase: 139 | addi a2, a2, -('a') 140 | letter_conv_done: 141 | ret 142 | 143 | .section .bss 144 | 145 | .align 4 146 | present_letters: 147 | .skip 52, 0 148 | 149 | badge_flags: 150 | .skip 52, 0 151 | -------------------------------------------------------------------------------- /day03-xtensa/rucksack/rucksack.ino: -------------------------------------------------------------------------------- 1 | extern "C" { 2 | uint64_t solve(void); 3 | } 4 | 5 | void setup() { 6 | Serial.begin(38400); 7 | 8 | Serial.println("\nおはよう世界"); 9 | 10 | uint64_t solution = solve(); 11 | 12 | Serial.print("Part 1: "); 13 | Serial.println(solution >> 32); 14 | Serial.print("Part 2: "); 15 | Serial.println(solution & 0xFFFFFFFF); 16 | } 17 | 18 | void loop() { 19 | delay(100); 20 | } 21 | -------------------------------------------------------------------------------- /day04-arm7tmdi/.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | *.elf 3 | *.gba 4 | build/ -------------------------------------------------------------------------------- /day04-arm7tmdi/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITARM)),) 7 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM) 8 | endif 9 | 10 | include $(DEVKITARM)/gba_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output, if this ends with _mb a multiboot image is generated 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | #--------------------------------------------------------------------------------- 19 | TARGET := camp_cleanup 20 | BUILD := build 21 | SOURCES := source 22 | DATA := 23 | INCLUDES := 24 | 25 | #--------------------------------------------------------------------------------- 26 | # options for code generation 27 | #--------------------------------------------------------------------------------- 28 | ARCH := -mthumb -mthumb-interwork 29 | 30 | CFLAGS := -g -Wall -O3\ 31 | -mcpu=arm7tdmi -mtune=arm7tdmi\ 32 | -fomit-frame-pointer\ 33 | -ffast-math \ 34 | $(ARCH) 35 | 36 | CFLAGS += $(INCLUDE) 37 | 38 | ASFLAGS := $(ARCH) 39 | LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map 40 | 41 | #--------------------------------------------------------------------------------- 42 | # path to tools - this can be deleted if you set the path to the toolchain in windows 43 | #--------------------------------------------------------------------------------- 44 | export PATH := $(DEVKITARM)/bin:$(PATH) 45 | 46 | #--------------------------------------------------------------------------------- 47 | # any extra libraries we wish to link with the project 48 | #--------------------------------------------------------------------------------- 49 | LIBS := -lgba 50 | 51 | #--------------------------------------------------------------------------------- 52 | # list of directories containing libraries, this must be the top level containing 53 | # include and lib 54 | #--------------------------------------------------------------------------------- 55 | LIBDIRS := $(LIBGBA) 56 | 57 | #--------------------------------------------------------------------------------- 58 | # no real need to edit anything past this point unless you need to add additional 59 | # rules for different file extensions 60 | #--------------------------------------------------------------------------------- 61 | ifneq ($(BUILD),$(notdir $(CURDIR))) 62 | #--------------------------------------------------------------------------------- 63 | 64 | export OUTPUT := $(CURDIR)/$(TARGET) 65 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 66 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 67 | 68 | export DEPSDIR := $(CURDIR)/$(BUILD) 69 | 70 | #--------------------------------------------------------------------------------- 71 | # automatically build a list of object files for our project 72 | #--------------------------------------------------------------------------------- 73 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 74 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 75 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 76 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 77 | 78 | #--------------------------------------------------------------------------------- 79 | # use CXX for linking C++ projects, CC for standard C 80 | #--------------------------------------------------------------------------------- 81 | ifeq ($(strip $(CPPFILES)),) 82 | #--------------------------------------------------------------------------------- 83 | export LD := $(CC) 84 | #--------------------------------------------------------------------------------- 85 | else 86 | #--------------------------------------------------------------------------------- 87 | export LD := $(CXX) 88 | #--------------------------------------------------------------------------------- 89 | endif 90 | #--------------------------------------------------------------------------------- 91 | 92 | export OFILES := $(addsuffix .o,$(BINFILES)) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 93 | 94 | #--------------------------------------------------------------------------------- 95 | # build a list of include paths 96 | #--------------------------------------------------------------------------------- 97 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 98 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 99 | -I$(CURDIR)/$(BUILD) 100 | 101 | #--------------------------------------------------------------------------------- 102 | # build a list of library paths 103 | #--------------------------------------------------------------------------------- 104 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 105 | 106 | .PHONY: $(BUILD) clean 107 | 108 | #--------------------------------------------------------------------------------- 109 | $(BUILD): 110 | @[ -d $@ ] || mkdir -p $@ 111 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 112 | 113 | all : $(BUILD) 114 | #--------------------------------------------------------------------------------- 115 | clean: 116 | @echo clean ... 117 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba 118 | 119 | #--------------------------------------------------------------------------------- 120 | else 121 | 122 | DEPENDS := $(OFILES:.o=.d) 123 | 124 | #--------------------------------------------------------------------------------- 125 | # main targets 126 | #--------------------------------------------------------------------------------- 127 | $(OUTPUT).gba : $(OUTPUT).elf 128 | 129 | $(OUTPUT).elf : $(OFILES) 130 | 131 | %.o : %.pcx 132 | @echo $(notdir $<) 133 | @$(bin2o) 134 | 135 | -include $(DEPENDS) 136 | 137 | #--------------------------------------------------------------------------------- 138 | endif 139 | #--------------------------------------------------------------------------------- 140 | -------------------------------------------------------------------------------- /day04-arm7tmdi/README.md: -------------------------------------------------------------------------------- 1 | The assembly for day 4 was built into a GBA ROM image and run on a New 2DS XL under [open_agb_firm](https://github.com/profi200/open_agb_firm). Contrary to how it may seem, this is not emulation; the various models of the 3DS contain a physical ARM7 (v4) processor used exclusively for running GBA, NDS, and DSi software. Output picture: [output.jpg](output.jpg). 2 | -------------------------------------------------------------------------------- /day04-arm7tmdi/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day04-arm7tmdi/output.jpg -------------------------------------------------------------------------------- /day04-arm7tmdi/source/main.s: -------------------------------------------------------------------------------- 1 | #define IRQ_VBLANK (1<<0) 2 | 3 | .section .text 4 | 5 | .global main 6 | main: 7 | //; main never returns so we don't have to preserve anything 8 | bl irqInit 9 | mov r0, #IRQ_VBLANK 10 | bl irqEnable 11 | 12 | bl consoleDemoInit 13 | ldr r0, =reset_console_string 14 | bl iprintf 15 | 16 | ldr r0, =hello_world_string 17 | bl iprintf 18 | 19 | ldr r0, =input_file 20 | mov r10, #0 21 | mov r11, #0 22 | main_loop: 23 | //add r11, #1 24 | ldrb r1, [r0] 25 | cmp r1, #0 26 | beq main_loop_break 27 | 28 | bl atoi_ish 29 | mov r5, r0 30 | mov r0, r1 31 | bl atoi_ish 32 | mov r6, r0 33 | mov r0, r1 34 | bl atoi_ish 35 | mov r7, r0 36 | mov r0, r1 37 | bl atoi_ish 38 | mov r8, r0 39 | mov r0, r1 40 | 41 | /*push {r0} 42 | ldr r0, =debug_string 43 | mov r1, r5 44 | mov r2, r6 45 | ldr r0, =input_file 46 | bl iprintf 47 | pop {r0}*/ 48 | 49 | cmp r5, r8 50 | bhi main_p1_logic 51 | cmp r6, r7 52 | blo main_p1_logic 53 | add r11, #1 54 | 55 | main_p1_logic: 56 | cmp r5, r7 57 | addeq r10, #1 58 | beq main_loop 59 | blo main_p1_lo 60 | cmp r6, r8 61 | addle r10, #1 62 | b main_loop 63 | main_p1_lo: 64 | cmp r6, r8 65 | addge r10, #1 66 | b main_loop 67 | main_loop_break: 68 | 69 | ldr r0, =part1_string 70 | mov r1, r10 71 | bl iprintf 72 | 73 | ldr r0, =part2_string 74 | mov r1, r11 75 | bl iprintf 76 | 77 | wfi_die_loop: 78 | swi 5 79 | b wfi_die_loop 80 | 81 | .ltorg 82 | 83 | //; takes string in r0, returns number in r0 and end ptr + 1 in r1. stops on anything that's not a decimal number 84 | atoi_ish: 85 | mov r1, r0 86 | mov r0, #0 87 | mov r2, #10 88 | atoi_loop: 89 | ldrb r3, [r1], #1 90 | subs r3, #'0' 91 | cmp r3, #9 92 | bxhi lr 93 | mla r0, r2, r0, r3 94 | b atoi_loop 95 | 96 | .section .rodata 97 | 98 | reset_console_string: 99 | .ascii "\x1b[2J\0" 100 | hello_world_string: 101 | .ascii "\x1b[10;10HHello World!\0" 102 | part1_string: 103 | .ascii "\x1b[0;0HPart 1: %u\0" 104 | part2_string: 105 | .ascii "\x1b[1;0HPart 2: %u\0" 106 | /*debug_string: 107 | .ascii "\x1b[8;0H0x%X 0x%X 0x%X 0x%X\0"*/ -------------------------------------------------------------------------------- /day05-jazelle/.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | build/ 3 | *.elf 4 | *.3dsx 5 | *.smdh -------------------------------------------------------------------------------- /day05-jazelle/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITARM)/3ds_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | # GRAPHICS is a list of directories containing graphics files 19 | # GFXBUILD is the directory where converted graphics files will be placed 20 | # If set to $(BUILD), it will statically link in the converted 21 | # files as if they were data files. 22 | # 23 | # NO_SMDH: if set to anything, no SMDH file is generated. 24 | # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) 25 | # APP_TITLE is the name of the app stored in the SMDH file (Optional) 26 | # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) 27 | # APP_AUTHOR is the author of the app stored in the SMDH file (Optional) 28 | # ICON is the filename of the icon (.png), relative to the project folder. 29 | # If not set, it attempts to use one of the following (in this order): 30 | # - .png 31 | # - icon.png 32 | # - /default_icon.png 33 | #--------------------------------------------------------------------------------- 34 | TARGET := supply_stacks 35 | BUILD := build 36 | SOURCES := source 37 | DATA := data 38 | INCLUDES := include 39 | GRAPHICS := gfx 40 | GFXBUILD := $(BUILD) 41 | #ROMFS := romfs 42 | #GFXBUILD := $(ROMFS)/gfx 43 | 44 | #--------------------------------------------------------------------------------- 45 | # options for code generation 46 | #--------------------------------------------------------------------------------- 47 | ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft 48 | 49 | CFLAGS := -g -Wall -Os -mword-relocations \ 50 | -ffunction-sections \ 51 | $(ARCH) 52 | 53 | CFLAGS += $(INCLUDE) -D__3DS__ 54 | 55 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 56 | 57 | ASFLAGS := -g $(ARCH) 58 | LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 59 | 60 | LIBS := -lctru -lm 61 | 62 | #--------------------------------------------------------------------------------- 63 | # list of directories containing libraries, this must be the top level containing 64 | # include and lib 65 | #--------------------------------------------------------------------------------- 66 | LIBDIRS := $(CTRULIB) 67 | 68 | 69 | #--------------------------------------------------------------------------------- 70 | # no real need to edit anything past this point unless you need to add additional 71 | # rules for different file extensions 72 | #--------------------------------------------------------------------------------- 73 | ifneq ($(BUILD),$(notdir $(CURDIR))) 74 | #--------------------------------------------------------------------------------- 75 | 76 | export OUTPUT := $(CURDIR)/$(TARGET) 77 | export TOPDIR := $(CURDIR) 78 | 79 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 80 | $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \ 81 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 82 | 83 | export DEPSDIR := $(CURDIR)/$(BUILD) 84 | 85 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 86 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 87 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 88 | PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) 89 | SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) 90 | GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s))) 91 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 92 | 93 | #--------------------------------------------------------------------------------- 94 | # use CXX for linking C++ projects, CC for standard C 95 | #--------------------------------------------------------------------------------- 96 | ifeq ($(strip $(CPPFILES)),) 97 | #--------------------------------------------------------------------------------- 98 | export LD := $(CC) 99 | #--------------------------------------------------------------------------------- 100 | else 101 | #--------------------------------------------------------------------------------- 102 | export LD := $(CXX) 103 | #--------------------------------------------------------------------------------- 104 | endif 105 | #--------------------------------------------------------------------------------- 106 | 107 | #--------------------------------------------------------------------------------- 108 | ifeq ($(GFXBUILD),$(BUILD)) 109 | #--------------------------------------------------------------------------------- 110 | export T3XFILES := $(GFXFILES:.t3s=.t3x) 111 | #--------------------------------------------------------------------------------- 112 | else 113 | #--------------------------------------------------------------------------------- 114 | export ROMFS_T3XFILES := $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES)) 115 | export T3XHFILES := $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES)) 116 | #--------------------------------------------------------------------------------- 117 | endif 118 | #--------------------------------------------------------------------------------- 119 | 120 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 121 | 122 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \ 123 | $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ 124 | $(addsuffix .o,$(T3XFILES)) 125 | 126 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 127 | 128 | export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \ 129 | $(addsuffix .h,$(subst .,_,$(BINFILES))) \ 130 | $(GFXFILES:.t3s=.h) 131 | 132 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 133 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 134 | -I$(CURDIR)/$(BUILD) 135 | 136 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 137 | 138 | export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh) 139 | 140 | ifeq ($(strip $(ICON)),) 141 | icons := $(wildcard *.png) 142 | ifneq (,$(findstring $(TARGET).png,$(icons))) 143 | export APP_ICON := $(TOPDIR)/$(TARGET).png 144 | else 145 | ifneq (,$(findstring icon.png,$(icons))) 146 | export APP_ICON := $(TOPDIR)/icon.png 147 | endif 148 | endif 149 | else 150 | export APP_ICON := $(TOPDIR)/$(ICON) 151 | endif 152 | 153 | ifeq ($(strip $(NO_SMDH)),) 154 | export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh 155 | endif 156 | 157 | ifneq ($(ROMFS),) 158 | export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) 159 | endif 160 | 161 | .PHONY: all clean 162 | 163 | #--------------------------------------------------------------------------------- 164 | all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES) 165 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 166 | 167 | $(BUILD): 168 | @mkdir -p $@ 169 | 170 | ifneq ($(GFXBUILD),$(BUILD)) 171 | $(GFXBUILD): 172 | @mkdir -p $@ 173 | endif 174 | 175 | ifneq ($(DEPSDIR),$(BUILD)) 176 | $(DEPSDIR): 177 | @mkdir -p $@ 178 | endif 179 | 180 | #--------------------------------------------------------------------------------- 181 | clean: 182 | @echo clean ... 183 | @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD) 184 | 185 | #--------------------------------------------------------------------------------- 186 | $(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s 187 | #--------------------------------------------------------------------------------- 188 | @echo $(notdir $<) 189 | @tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x 190 | 191 | #--------------------------------------------------------------------------------- 192 | else 193 | 194 | #--------------------------------------------------------------------------------- 195 | # main targets 196 | #--------------------------------------------------------------------------------- 197 | $(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS) 198 | 199 | $(OFILES_SOURCES) : $(HFILES) 200 | 201 | $(OUTPUT).elf : $(OFILES) 202 | 203 | #--------------------------------------------------------------------------------- 204 | # you need a rule like this for each extension you use as binary data 205 | #--------------------------------------------------------------------------------- 206 | %.bin.o %_bin.h : %.bin 207 | #--------------------------------------------------------------------------------- 208 | @echo $(notdir $<) 209 | @$(bin2o) 210 | 211 | #--------------------------------------------------------------------------------- 212 | .PRECIOUS : %.t3x 213 | #--------------------------------------------------------------------------------- 214 | %.t3x.o %_t3x.h : %.t3x 215 | #--------------------------------------------------------------------------------- 216 | @echo $(notdir $<) 217 | @$(bin2o) 218 | 219 | #--------------------------------------------------------------------------------- 220 | # rules for assembling GPU shaders 221 | #--------------------------------------------------------------------------------- 222 | define shader-as 223 | $(eval CURBIN := $*.shbin) 224 | $(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d) 225 | echo "$(CURBIN).o: $< $1" > $(DEPSFILE) 226 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h 227 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h 228 | echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h 229 | picasso -o $(CURBIN) $1 230 | bin2s $(CURBIN) | $(AS) -o $*.shbin.o 231 | endef 232 | 233 | %.shbin.o %_shbin.h : %.v.pica %.g.pica 234 | @echo $(notdir $^) 235 | @$(call shader-as,$^) 236 | 237 | %.shbin.o %_shbin.h : %.v.pica 238 | @echo $(notdir $<) 239 | @$(call shader-as,$<) 240 | 241 | %.shbin.o %_shbin.h : %.shlist 242 | @echo $(notdir $<) 243 | @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file))) 244 | 245 | #--------------------------------------------------------------------------------- 246 | %.t3x %.h : %.t3s 247 | #--------------------------------------------------------------------------------- 248 | @echo $(notdir $<) 249 | @tex3ds -i $< -H $*.h -d $*.d -o $*.t3x 250 | 251 | -include $(DEPSDIR)/*.d 252 | 253 | #--------------------------------------------------------------------------------------- 254 | endif 255 | #--------------------------------------------------------------------------------------- 256 | -------------------------------------------------------------------------------- /day05-jazelle/README.md: -------------------------------------------------------------------------------- 1 | Day 5 was completed in... Java? For those unaware, [Jazelle DBX](https://en.m.wikipedia.org/wiki/Jazelle) is a hardware extension present in some ARMv5, v6, and v7 processors that allows for direct execution of Java bytecode. Only some instructions are implemented in hardware (the others return to ARM mode where a JVM would usually handle them), so I restricted myself to the ones handled in hardware and solved day 5 in hand-written bytecode. This bytecode was run on the ARMv6k in a New 2DS XL: [output.jpg](output.jpg). Thanks to [Sono's libjz](https://github.com/SonoSooS/libjz) and [this page](https://hackspire.org/index.php/Jazelle) for providing documentation and reference code necessary to making this work. 2 | -------------------------------------------------------------------------------- /day05-jazelle/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day05-jazelle/output.jpg -------------------------------------------------------------------------------- /day05-jazelle/source/bytecode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef __ASSEMBLER__ 4 | #error This file is only to be included from assembly source files 5 | #endif 6 | 7 | #define NO_ARGS(mnem, opcode) \ 8 | .macro mnem; \ 9 | .byte opcode; \ 10 | .endm 11 | 12 | #define ARG_1(mnem, opcode) \ 13 | .macro mnem arg0; \ 14 | .byte opcode, \arg0; \ 15 | .endm 16 | 17 | #define ARG_2(mnem, opcode) \ 18 | .macro mnem arg0, arg1; \ 19 | .byte opcode, \arg0, \arg1; \ 20 | .endm 21 | 22 | #define ARG_3(mnem, opcode) \ 23 | .macro mnem arg0, arg1, arg2; \ 24 | .byte opcode, \arg0, \arg1, \arg2; \ 25 | .endm 26 | 27 | #define ARG_4(mnem, opcode) \ 28 | .macro mnem arg0, arg1, arg2, arg3; \ 29 | .byte opcode, \arg0, \arg1, \arg2, \arg3; \ 30 | .endm 31 | 32 | #define ARG_LAB(mnem, opcode) \ 33 | .macro mnem lab; \ 34 | .byte opcode; \ 35 | .byte (((\lab - . + 1) >> 8) & 0xFF); \ 36 | .byte ((\lab - . + 2) & 0xFF); \ 37 | /*// This check would be great to have but it errors with non-constant expression and I have no idea why 38 | .if ((((\lab - . + 2) >> 16) != (-1 >> 16)) && (((\lab - . + 2) >> 16) != 0)); \ 39 | .err "Didn't fit"; \ 40 | .endif;*/ \ 41 | .endm 42 | 43 | // https://en.wikipedia.org/wiki/List_of_Java_bytecode_instructions 44 | 45 | NO_ARGS(iconst_m1, 0x02) 46 | NO_ARGS(iconst_0, 0x03) 47 | NO_ARGS(iconst_1, 0x04) 48 | NO_ARGS(iconst_2, 0x05) 49 | NO_ARGS(iconst_3, 0x06) 50 | NO_ARGS(iconst_4, 0x07) 51 | NO_ARGS(iconst_5, 0x08) 52 | ARG_1(bipush, 0x10) @ byte gets sign extended 53 | 54 | NO_ARGS(istore_0, 0x3B) 55 | NO_ARGS(istore_1, 0x3C) 56 | NO_ARGS(istore_2, 0x3D) 57 | NO_ARGS(istore_3, 0x3E) 58 | ARG_1(istore, 0x36) 59 | 60 | NO_ARGS(astore_0, 0x4B) 61 | NO_ARGS(astore_1, 0x4C) 62 | NO_ARGS(astore_2, 0x4D) 63 | NO_ARGS(astore_3, 0x4E) 64 | ARG_1(astore, 0x3A) 65 | 66 | NO_ARGS(iload_0, 0x1A) 67 | NO_ARGS(iload_1, 0x1B) 68 | NO_ARGS(iload_2, 0x1C) 69 | NO_ARGS(iload_3, 0x1D) 70 | ARG_1(iload, 0x15) 71 | 72 | NO_ARGS(aload_0, 0x2A) 73 | NO_ARGS(aload_1, 0x2B) 74 | NO_ARGS(aload_2, 0x2C) 75 | NO_ARGS(aload_3, 0x2D) 76 | ARG_1(aload, 0x19) 77 | 78 | NO_ARGS(iaload, 0x2E) 79 | NO_ARGS(baload, 0x33) 80 | NO_ARGS(iastore, 0x4F) 81 | NO_ARGS(bastore, 0x54) 82 | 83 | NO_ARGS(arraylength, 0xBE) 84 | 85 | NO_ARGS(iadd, 0x60) 86 | NO_ARGS(isub, 0x64) 87 | NO_ARGS(imul, 0x68) 88 | //NO_ARGS(idiv, 0x6C) // Not hardware-implemented 89 | NO_ARGS(ishl, 0x78) 90 | NO_ARGS(ishr, 0x7A) 91 | NO_ARGS(iushr, 0x7C) 92 | NO_ARGS(iand, 0x7E) 93 | NO_ARGS(ior, 0x80) 94 | NO_ARGS(ixor, 0x82) 95 | 96 | ARG_2(iinc, 0x84) 97 | 98 | ARG_LAB(ifeq, 0x99) 99 | ARG_LAB(ifne, 0x9A) 100 | ARG_LAB(iflt, 0x9B) 101 | ARG_LAB(ifge, 0x9C) 102 | ARG_LAB(ifgt, 0x9D) 103 | ARG_LAB(ifle, 0x9E) 104 | ARG_LAB(if_icmpeq, 0x9F) 105 | ARG_LAB(if_icmpne, 0xA0) 106 | ARG_LAB(if_icmplt, 0xA1) 107 | ARG_LAB(if_icmpge, 0xA2) 108 | ARG_LAB(if_icmpgt, 0xA3) 109 | ARG_LAB(if_icmple, 0xA4) 110 | ARG_LAB(goto, 0xA7) 111 | 112 | ARG_LAB(jsr, 0xA8) 113 | ARG_1(ret, 0xA9) 114 | 115 | // This is the only not-hardware-implented instruction I'm using, 116 | // and it's only used for the purpose of returning to ARM mode once we're all done 117 | NO_ARGS(ireturn, 0xAC) -------------------------------------------------------------------------------- /day05-jazelle/source/input.c: -------------------------------------------------------------------------------- 1 | //const char input_file[] = " [D] \n[N] [C] \n[Z] [M] [P]\n 1 2 3 \n\nmove 1 from 2 to 1\nmove 3 from 1 to 3\nmove 2 from 2 to 1\nmove 1 from 1 to 2\n"; 2 | const char input_file[] = " [L] [H] [W]\n [J] [Z] [J] [Q] [Q]\n[S] [M] [C] [T] [F] [B]\n[P] [H] [B] [D] [G] [B] [P]\n[W] [L] [D] [D] [J] [W] [T] [C]\n[N] [T] [R] [T] [T] [T] [M] [M] [G]\n[J] [S] [Q] [S] [Z] [W] [P] [G] [D]\n[Z] [G] [V] [V] [Q] [M] [L] [N] [R]\n 1 2 3 4 5 6 7 8 9 \n\nmove 1 from 3 to 5\nmove 2 from 2 to 8\nmove 4 from 1 to 3\nmove 2 from 1 to 4\nmove 1 from 7 to 1\nmove 2 from 9 to 7\nmove 4 from 5 to 9\nmove 7 from 8 to 9\nmove 2 from 5 to 2\nmove 1 from 2 to 9\nmove 1 from 1 to 8\nmove 1 from 2 to 7\nmove 3 from 8 to 2\nmove 6 from 9 to 7\nmove 5 from 4 to 1\nmove 7 from 9 to 5\nmove 1 from 4 to 5\nmove 4 from 1 to 7\nmove 1 from 8 to 1\nmove 4 from 7 to 9\nmove 1 from 5 to 8\nmove 9 from 9 to 3\nmove 1 from 8 to 9\nmove 1 from 1 to 5\nmove 4 from 3 to 2\nmove 10 from 5 to 3\nmove 8 from 2 to 8\nmove 7 from 8 to 3\nmove 9 from 7 to 5\nmove 1 from 9 to 3\nmove 3 from 6 to 4\nmove 3 from 7 to 6\nmove 1 from 8 to 7\nmove 1 from 1 to 8\nmove 1 from 4 to 7\nmove 5 from 7 to 6\nmove 14 from 3 to 7\nmove 16 from 3 to 9\nmove 1 from 8 to 4\nmove 2 from 4 to 9\nmove 1 from 3 to 7\nmove 1 from 6 to 8\nmove 15 from 7 to 2\nmove 10 from 9 to 7\nmove 7 from 2 to 4\nmove 1 from 2 to 7\nmove 11 from 6 to 7\nmove 5 from 5 to 9\nmove 15 from 7 to 8\nmove 1 from 7 to 2\nmove 2 from 9 to 7\nmove 4 from 5 to 1\nmove 5 from 4 to 9\nmove 6 from 2 to 4\nmove 2 from 2 to 5\nmove 2 from 1 to 4\nmove 1 from 1 to 5\nmove 3 from 5 to 6\nmove 8 from 7 to 9\nmove 9 from 4 to 9\nmove 1 from 4 to 8\nmove 11 from 9 to 7\nmove 4 from 6 to 1\nmove 17 from 8 to 7\nmove 26 from 7 to 1\nmove 1 from 4 to 8\nmove 24 from 1 to 7\nmove 22 from 9 to 3\nmove 1 from 8 to 2\nmove 6 from 3 to 4\nmove 2 from 1 to 2\nmove 1 from 7 to 9\nmove 16 from 7 to 3\nmove 1 from 9 to 5\nmove 6 from 4 to 1\nmove 1 from 2 to 7\nmove 6 from 3 to 2\nmove 1 from 5 to 4\nmove 6 from 3 to 5\nmove 1 from 4 to 1\nmove 3 from 1 to 4\nmove 4 from 5 to 4\nmove 7 from 1 to 7\nmove 6 from 4 to 3\nmove 1 from 1 to 6\nmove 1 from 2 to 5\nmove 1 from 1 to 7\nmove 15 from 3 to 1\nmove 2 from 2 to 7\nmove 3 from 5 to 8\nmove 9 from 7 to 5\nmove 8 from 5 to 7\nmove 3 from 8 to 5\nmove 1 from 6 to 9\nmove 5 from 7 to 8\nmove 3 from 2 to 4\nmove 2 from 2 to 5\nmove 4 from 3 to 7\nmove 5 from 8 to 3\nmove 1 from 5 to 8\nmove 5 from 3 to 1\nmove 2 from 5 to 7\nmove 1 from 9 to 8\nmove 1 from 5 to 8\nmove 19 from 1 to 4\nmove 19 from 7 to 1\nmove 7 from 1 to 4\nmove 1 from 7 to 4\nmove 3 from 3 to 5\nmove 22 from 4 to 5\nmove 3 from 8 to 3\nmove 7 from 1 to 8\nmove 3 from 3 to 5\nmove 3 from 3 to 6\nmove 3 from 6 to 9\nmove 3 from 9 to 1\nmove 1 from 3 to 4\nmove 2 from 8 to 9\nmove 25 from 5 to 6\nmove 4 from 1 to 5\nmove 5 from 5 to 4\nmove 2 from 8 to 2\nmove 1 from 9 to 2\nmove 3 from 5 to 7\nmove 12 from 6 to 8\nmove 1 from 7 to 3\nmove 7 from 8 to 1\nmove 1 from 5 to 7\nmove 1 from 3 to 8\nmove 2 from 7 to 4\nmove 6 from 8 to 5\nmove 10 from 6 to 3\nmove 2 from 6 to 2\nmove 1 from 6 to 3\nmove 17 from 4 to 6\nmove 3 from 3 to 9\nmove 3 from 8 to 4\nmove 1 from 7 to 5\nmove 1 from 3 to 8\nmove 1 from 2 to 5\nmove 10 from 1 to 7\nmove 3 from 2 to 7\nmove 2 from 1 to 8\nmove 15 from 6 to 3\nmove 7 from 5 to 9\nmove 9 from 9 to 5\nmove 1 from 9 to 3\nmove 2 from 3 to 5\nmove 3 from 8 to 6\nmove 1 from 9 to 3\nmove 11 from 5 to 8\nmove 9 from 3 to 8\nmove 1 from 5 to 6\nmove 9 from 8 to 5\nmove 10 from 7 to 5\nmove 5 from 5 to 3\nmove 4 from 6 to 8\nmove 2 from 6 to 8\nmove 2 from 5 to 6\nmove 1 from 2 to 1\nmove 9 from 5 to 3\nmove 2 from 7 to 5\nmove 3 from 5 to 4\nmove 1 from 4 to 1\nmove 2 from 4 to 3\nmove 1 from 7 to 1\nmove 2 from 1 to 7\nmove 3 from 4 to 5\nmove 2 from 7 to 3\nmove 14 from 3 to 9\nmove 13 from 3 to 1\nmove 8 from 1 to 4\nmove 6 from 1 to 2\nmove 11 from 8 to 6\nmove 4 from 3 to 9\nmove 2 from 9 to 2\nmove 1 from 5 to 2\nmove 6 from 4 to 9\nmove 6 from 8 to 9\nmove 6 from 9 to 4\nmove 2 from 4 to 7\nmove 4 from 4 to 6\nmove 4 from 2 to 9\nmove 2 from 7 to 9\nmove 2 from 2 to 1\nmove 3 from 5 to 3\nmove 2 from 1 to 7\nmove 1 from 5 to 2\nmove 7 from 9 to 7\nmove 2 from 2 to 8\nmove 10 from 6 to 5\nmove 5 from 5 to 6\nmove 9 from 7 to 8\nmove 3 from 3 to 9\nmove 4 from 5 to 1\nmove 10 from 9 to 3\nmove 7 from 6 to 2\nmove 5 from 3 to 9\nmove 3 from 1 to 7\nmove 1 from 4 to 7\nmove 1 from 4 to 9\nmove 1 from 3 to 7\nmove 1 from 2 to 1\nmove 1 from 5 to 1\nmove 1 from 1 to 7\nmove 3 from 6 to 3\nmove 3 from 3 to 4\nmove 6 from 7 to 4\nmove 3 from 9 to 8\nmove 9 from 8 to 1\nmove 3 from 8 to 1\nmove 13 from 9 to 5\nmove 2 from 2 to 8\nmove 4 from 8 to 3\nmove 11 from 1 to 2\nmove 14 from 2 to 6\nmove 6 from 3 to 8\nmove 4 from 9 to 7\nmove 10 from 5 to 3\nmove 2 from 7 to 3\nmove 1 from 1 to 8\nmove 1 from 1 to 7\nmove 1 from 7 to 8\nmove 1 from 1 to 4\nmove 8 from 4 to 2\nmove 2 from 5 to 1\nmove 1 from 1 to 9\nmove 1 from 7 to 3\nmove 1 from 9 to 5\nmove 1 from 4 to 2\nmove 1 from 4 to 6\nmove 1 from 7 to 3\nmove 11 from 6 to 9\nmove 4 from 2 to 5\nmove 4 from 2 to 5\nmove 10 from 5 to 6\nmove 9 from 9 to 5\nmove 1 from 9 to 2\nmove 2 from 8 to 4\nmove 1 from 9 to 6\nmove 5 from 2 to 1\nmove 5 from 8 to 6\nmove 4 from 1 to 9\nmove 1 from 8 to 1\nmove 3 from 9 to 4\nmove 5 from 5 to 1\nmove 1 from 9 to 7\nmove 11 from 6 to 3\nmove 4 from 4 to 9\nmove 9 from 6 to 5\nmove 2 from 6 to 5\nmove 3 from 9 to 1\nmove 1 from 4 to 8\nmove 4 from 1 to 3\nmove 3 from 5 to 4\nmove 2 from 4 to 9\nmove 2 from 9 to 4\nmove 1 from 9 to 8\nmove 6 from 5 to 4\nmove 1 from 7 to 8\nmove 3 from 5 to 2\nmove 3 from 8 to 5\nmove 1 from 2 to 1\nmove 24 from 3 to 9\nmove 2 from 2 to 1\nmove 10 from 1 to 7\nmove 18 from 9 to 8\nmove 5 from 3 to 7\nmove 5 from 9 to 5\nmove 12 from 7 to 2\nmove 1 from 7 to 6\nmove 8 from 4 to 7\nmove 1 from 4 to 5\nmove 12 from 5 to 9\nmove 1 from 6 to 9\nmove 3 from 2 to 8\nmove 5 from 7 to 3\nmove 21 from 8 to 7\nmove 3 from 3 to 8\nmove 11 from 9 to 5\nmove 10 from 5 to 6\nmove 3 from 7 to 2\nmove 3 from 6 to 4\nmove 2 from 3 to 1\nmove 2 from 3 to 5\nmove 1 from 1 to 7\nmove 1 from 1 to 4\nmove 3 from 4 to 1\nmove 1 from 9 to 1\nmove 1 from 4 to 3\nmove 3 from 5 to 8\nmove 1 from 9 to 6\nmove 4 from 2 to 3\nmove 6 from 8 to 6\nmove 1 from 9 to 3\nmove 7 from 2 to 4\nmove 5 from 4 to 5\nmove 1 from 2 to 6\nmove 3 from 1 to 9\nmove 3 from 9 to 4\nmove 1 from 1 to 9\nmove 2 from 5 to 3\nmove 3 from 5 to 2\nmove 4 from 7 to 2\nmove 2 from 4 to 3\nmove 2 from 2 to 3\nmove 2 from 4 to 8\nmove 5 from 2 to 3\nmove 6 from 6 to 4\nmove 8 from 7 to 3\nmove 4 from 4 to 5\nmove 1 from 3 to 1\nmove 2 from 8 to 6\nmove 7 from 7 to 5\nmove 1 from 9 to 1\nmove 14 from 3 to 6\nmove 4 from 7 to 1\nmove 6 from 5 to 3\nmove 4 from 1 to 2\nmove 9 from 3 to 5\nmove 1 from 7 to 2\nmove 2 from 3 to 7\nmove 1 from 4 to 8\nmove 1 from 4 to 9\nmove 3 from 3 to 6\nmove 9 from 5 to 2\nmove 1 from 8 to 9\nmove 1 from 1 to 7\nmove 1 from 9 to 3\nmove 1 from 4 to 8\nmove 1 from 9 to 4\nmove 3 from 5 to 1\nmove 2 from 1 to 9\nmove 1 from 4 to 9\nmove 15 from 6 to 9\nmove 3 from 3 to 5\nmove 2 from 1 to 3\nmove 2 from 7 to 4\nmove 5 from 6 to 5\nmove 6 from 2 to 9\nmove 1 from 7 to 2\nmove 2 from 4 to 6\nmove 2 from 3 to 1\nmove 1 from 1 to 6\nmove 1 from 8 to 3\nmove 1 from 3 to 9\nmove 3 from 5 to 1\nmove 3 from 6 to 2\nmove 6 from 5 to 3\nmove 6 from 6 to 8\nmove 4 from 1 to 6\nmove 12 from 9 to 7\nmove 4 from 6 to 8\nmove 1 from 5 to 1\nmove 2 from 8 to 2\nmove 2 from 2 to 1\nmove 5 from 3 to 6\nmove 3 from 1 to 6\nmove 5 from 8 to 6\nmove 1 from 3 to 6\nmove 5 from 2 to 7\nmove 8 from 9 to 4\nmove 15 from 7 to 8\nmove 5 from 6 to 3\nmove 1 from 3 to 8\nmove 15 from 8 to 3\nmove 7 from 2 to 9\nmove 1 from 7 to 4\nmove 10 from 9 to 5\nmove 4 from 6 to 4\nmove 3 from 8 to 6\nmove 1 from 8 to 6\nmove 1 from 7 to 3\nmove 10 from 6 to 9\nmove 7 from 3 to 2\nmove 10 from 9 to 7\nmove 8 from 5 to 7\nmove 8 from 3 to 7\nmove 1 from 5 to 9\nmove 1 from 6 to 8\nmove 1 from 5 to 4\nmove 1 from 8 to 6\nmove 5 from 3 to 8\nmove 9 from 4 to 2\nmove 1 from 9 to 2\nmove 4 from 2 to 3\nmove 2 from 2 to 9\nmove 2 from 4 to 8\nmove 4 from 9 to 1\nmove 1 from 4 to 9\nmove 1 from 7 to 8\nmove 9 from 2 to 1\nmove 1 from 2 to 5\nmove 1 from 5 to 3\nmove 1 from 9 to 3\nmove 4 from 3 to 6\nmove 4 from 8 to 9\nmove 2 from 3 to 6\nmove 2 from 6 to 9\nmove 1 from 4 to 8\nmove 3 from 6 to 3\nmove 2 from 6 to 5\nmove 1 from 5 to 2\nmove 2 from 2 to 1\nmove 9 from 7 to 3\nmove 7 from 3 to 9\nmove 9 from 9 to 8\nmove 10 from 7 to 1\nmove 3 from 9 to 3\nmove 3 from 3 to 1\nmove 5 from 8 to 3\nmove 1 from 9 to 3\nmove 1 from 5 to 6\nmove 3 from 8 to 4\nmove 1 from 8 to 4\nmove 2 from 8 to 2\nmove 7 from 3 to 8\nmove 4 from 4 to 2\nmove 1 from 4 to 6\nmove 1 from 8 to 1\nmove 5 from 7 to 5\nmove 2 from 6 to 7\nmove 3 from 8 to 7\nmove 2 from 2 to 1\nmove 23 from 1 to 6\nmove 2 from 3 to 5\nmove 1 from 3 to 6\nmove 1 from 7 to 2\nmove 22 from 6 to 4\nmove 5 from 2 to 7\nmove 6 from 5 to 3\nmove 17 from 4 to 1\nmove 5 from 8 to 2\nmove 23 from 1 to 7\nmove 5 from 3 to 1\nmove 15 from 7 to 2\nmove 2 from 3 to 4\nmove 1 from 8 to 4\nmove 5 from 1 to 9\nmove 6 from 7 to 1\nmove 8 from 4 to 6\nmove 4 from 9 to 5\nmove 3 from 5 to 7\nmove 1 from 9 to 1\nmove 7 from 7 to 4\nmove 7 from 1 to 5\nmove 10 from 2 to 3\nmove 4 from 2 to 4\nmove 6 from 2 to 8\nmove 7 from 6 to 7\nmove 7 from 3 to 1\nmove 3 from 6 to 2\nmove 5 from 8 to 7\nmove 7 from 5 to 7\nmove 1 from 5 to 6\nmove 1 from 6 to 2\nmove 2 from 3 to 4\nmove 1 from 3 to 7\nmove 1 from 2 to 6\nmove 3 from 7 to 6\nmove 1 from 8 to 3\nmove 4 from 4 to 2\nmove 2 from 4 to 9\nmove 2 from 1 to 7\nmove 1 from 4 to 9\nmove 1 from 3 to 5\nmove 4 from 6 to 1\nmove 3 from 4 to 5\nmove 2 from 4 to 1\nmove 8 from 7 to 1\nmove 1 from 4 to 1\nmove 6 from 2 to 3\nmove 1 from 2 to 4\nmove 4 from 3 to 2\nmove 1 from 4 to 5\nmove 3 from 2 to 5\nmove 11 from 7 to 5\nmove 2 from 9 to 1\nmove 8 from 7 to 4\nmove 2 from 3 to 5\nmove 1 from 2 to 1\nmove 8 from 4 to 1\nmove 1 from 9 to 4\nmove 7 from 5 to 4\nmove 22 from 1 to 5\nmove 5 from 4 to 2\nmove 6 from 1 to 7\nmove 4 from 2 to 7\nmove 19 from 5 to 4\nmove 1 from 7 to 6\nmove 3 from 1 to 6\nmove 3 from 7 to 9\nmove 1 from 2 to 4\nmove 20 from 4 to 6\nmove 13 from 5 to 9\nmove 2 from 1 to 3\nmove 10 from 9 to 8\nmove 3 from 9 to 4\nmove 1 from 8 to 1\nmove 1 from 1 to 8\nmove 1 from 3 to 1\nmove 2 from 9 to 2\n"; 3 | -------------------------------------------------------------------------------- /day05-jazelle/source/jz.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include 4 | //#include 5 | 6 | s32 enable_jazelle_hardware(void); 7 | //s32 get_thing(void); 8 | s32 do_jazelle(void* workmem, const u8* bytecode, void* arr1, void* arr2); 9 | 10 | extern u8 test_bytecode[]; 11 | extern u8 solve_bytecode[]; -------------------------------------------------------------------------------- /day05-jazelle/source/jz.s: -------------------------------------------------------------------------------- 1 | .section .text 2 | 3 | .align 4 4 | .global do_jazelle 5 | do_jazelle: @ Takes buffer for jazelle stuff in r0, bytecode address in r1, input arrays to pass to jazelle in r2 and r3 6 | push {r4-r11, lr} 7 | 8 | mov r5, r0 @ Handler table pointer (must be 1024-byte aligned) 9 | add r6, r5, #0x800 @ Stack pointer 10 | add r7, r5, #0x900 @ Local variables pointer 11 | 12 | mov lr, r1 13 | 14 | @ Fill the entire instr table with that label, so we know if an unimplemented instr was encountered 15 | adr r0, unimpl_instr 16 | ldr r1, =(0x400 - 4) 17 | fill_loop: 18 | str r0, [r5, r1] 19 | subs r1, #4 20 | bpl fill_loop 21 | 22 | @ Different handler for a few exceptions 23 | adr r0, null_ptr 24 | str r0, [r5, #0x400] 25 | adr r0, array_index 26 | str r0, [r5, #0x404] 27 | 28 | @ Set handler for ireturn bytecode 29 | adr r0, ireturn 30 | str r0, [r5, #0xAC * 4] 31 | 32 | mov r8, #0 33 | 34 | mov r0, r2 35 | mov r1, r3 36 | orr r5, #(2 << 2) @ There are two words in the stack in r0 and r1 37 | 38 | @ Execute the bytecode 39 | adr r12, jazelle_unavailable 40 | bxj r12 41 | 42 | ireturn: 43 | @ Get result off the stack and return it 44 | ldr r0, [r6, #-4]! 45 | pop {r4-r11, pc} 46 | 47 | jazelle_unavailable: 48 | mov r0, #-1 49 | pop {r4-r11, pc} 50 | 51 | unimpl_instr: 52 | mov r0, #420 53 | pop {r4-r11, pc} 54 | 55 | null_ptr: 56 | mov r0, #69 57 | pop {r4-r11, pc} 58 | 59 | array_index: 60 | mov r0, #70 61 | pop {r4-r11, pc} 62 | 63 | .ltorg 64 | 65 | .align 4 66 | .global enable_jazelle_hardware 67 | enable_jazelle_hardware: 68 | mov r0, #2 69 | mcr p14, 7, r0, c1, c0, 0 70 | mov r0, #1 71 | orr r0, #(1 << 29) @ array objects contain their elements directly, or something 72 | mcr p14, 7, r0, c2, c0, 0 73 | mov r0, #(1 << 8) @ the array data is 1 word from the start of the array 74 | mcr p14, 7, r0, c3, c0, 0 75 | bx lr 76 | 77 | /*.global get_thing 78 | get_thing: 79 | mrc p14, 7, r0, c3, c0, 0 80 | ldr r1, =thing 81 | str r0, [r1] 82 | bx lr*/ 83 | 84 | .ltorg 85 | -------------------------------------------------------------------------------- /day05-jazelle/source/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | Hello World example made by Aurelio Mannara for libctru 3 | This code was modified for the last time on: 12/12/2014 21:00 UTC+1 4 | */ 5 | 6 | #include <3ds.h> 7 | #include 8 | #include 9 | #include 10 | 11 | #include "jz.h" 12 | 13 | static void die_exit(bool die) { 14 | printf("\nPress start to exit\n"); 15 | 16 | // Main loop 17 | while (aptMainLoop()) 18 | { 19 | //Scan all the inputs. This should be done once for each frame 20 | hidScanInput(); 21 | 22 | //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) 23 | u32 kDown = hidKeysDown(); 24 | 25 | if (kDown & KEY_START) break; // break in order to return to hbmenu 26 | 27 | // Flush and swap framebuffers 28 | gfxFlushBuffers(); 29 | gfxSwapBuffers(); 30 | 31 | //Wait for VBlank 32 | gspWaitForVBlank(); 33 | } 34 | 35 | gfxExit(); 36 | if (die) svcExitProcess(); 37 | } 38 | 39 | //u32 thing = 0; 40 | extern const char input_file[]; 41 | 42 | int main(int argc, char **argv) { 43 | gfxInitDefault(); 44 | consoleInit(GFX_TOP, NULL); 45 | printf("Hello World!\n"); 46 | 47 | svcBackdoor(enable_jazelle_hardware); 48 | printf("jazelle hardware is on!\n"); 49 | 50 | /*svcBackdoor(get_thing); 51 | printf("thing: 0x%lX\n", thing);*/ 52 | 53 | void* input_buf = NULL; 54 | void* workmem = memalign(1024, 0x2000); 55 | if (!workmem) { 56 | printf("memalign ded\n"); 57 | goto exit; 58 | } 59 | 60 | s32 arr[] = {1, 42}; 61 | s32 ret = do_jazelle(workmem, test_bytecode, arr, NULL); 62 | printf("test bytecode gave: %ld\n", ret); 63 | if (ret != 47) { 64 | printf("something went wrong with the test bytecode\n"); 65 | goto exit; 66 | } 67 | 68 | size_t len = strlen(input_file); 69 | input_buf = memalign(4, sizeof(u32) + len + 1); 70 | if (!input_buf) { 71 | printf("memalign died for %zu\n", len); 72 | goto exit; 73 | } 74 | *(u32*)input_buf = len + 1; 75 | memcpy(input_buf + 4, input_file, len + 1); 76 | char output_buf[30]; 77 | *(u32*)output_buf = sizeof(output_buf) - sizeof(u32); 78 | ret = do_jazelle(workmem, solve_bytecode, input_buf, output_buf); 79 | printf("\nsolve bytecode returned: %ld\n\n", ret); 80 | printf("Output Buffer: %s\n", output_buf + sizeof(u32)); 81 | 82 | exit: 83 | if (workmem) free(workmem); 84 | if (input_buf) free(input_buf); 85 | die_exit(false); 86 | return 0; 87 | } 88 | -------------------------------------------------------------------------------- /day05-jazelle/source/solve_bytecode.s: -------------------------------------------------------------------------------- 1 | #include "bytecode.h" 2 | 3 | .section .text 4 | 5 | @local variable allocations: 6 | @ 0,1: return addresses 7 | @ 2: input array reference 8 | @ 3: output array reference 9 | @ 4-9: temporary whatever 10 | @ 10: debugging nonsense 11 | @ 11: index into the input array for parsing the operations 12 | @ 12-20: used in main for various purposes, preserved across calls 13 | @ 21: index into output array 14 | @ 22: used to track if we're doing part1 or part2 15 | @ 0x3F: number of stacks (we actually have this many + 1, one is used to track movements) 16 | @ 0x40: ints that are organized to form an array of bytes, starting with the lower 8 bits of int 0 17 | @ the first n_stacks bytes are the current length of each stack, followed by 64-byte arrays for the stack data 18 | 19 | @ solves AoC :D 20 | .global solve_bytecode 21 | solve_bytecode: 22 | @ We are passed two arrays in the stack: one for the input file and one for the output string. 23 | astore_2 24 | astore_3 25 | 26 | iconst_0 27 | istore 21 28 | iconst_0 29 | istore 22 30 | 31 | reset_repeat: 32 | 33 | @ First, we need to figure out how many stacks there are 34 | @ There will be a newline after (4*(nstacks-1)) + 3 bytes from the input start, so look for that 35 | iconst_1 36 | istore 0x3F 37 | iconst_3 38 | istore 12 39 | get_nstacks_loop: 40 | aload_2 41 | iload 12 42 | baload 43 | bipush '\n' 44 | isub 45 | ifeq get_nstacks_break 46 | iinc 0x3F, 1 47 | iinc 12, 4 48 | goto get_nstacks_loop 49 | get_nstacks_break: 50 | 51 | @ 0 out lengths of all the stacks 52 | iconst_0 53 | istore 7 54 | lengths_0_loop: 55 | iload 7 56 | iconst_0 57 | jsr local_var_array_store 58 | iinc 7, 1 59 | iload 0x3F 60 | iload 7 61 | isub 62 | ifne lengths_0_loop 63 | 64 | @ Next, find the bottom of the stacks in the input and so we can start pushing values from there 65 | @ There will be a double newline after the numbers under the stacks, so look for that then back up one line 66 | iload 12 @ Get the index of that first newline from earlier 67 | istore 7 68 | iinc 12, 1 @ Inc this so it's now the length of a line in the first part of the input 69 | find_bottom_loop: 70 | iload 7 71 | iload 12 72 | iadd 73 | istore 7 74 | 75 | aload_2 76 | iload 7 77 | iconst_1 78 | iadd 79 | baload 80 | bipush '\n' 81 | isub 82 | ifne find_bottom_loop 83 | @ We now have the index of the first of the two newlines 84 | 85 | @ Calculate the index of the first number in the "move x from x to x" input section and save it for later 86 | iload 7 87 | bipush 7 88 | iadd 89 | istore 11 90 | 91 | @ Subtract appropriately so this value now points to the first actual letter of the bottom line of the stack data in the input 92 | iload 7 93 | iload 12 94 | iconst_1 95 | ishl 96 | isub 97 | iconst_2 98 | iadd 99 | istore 13 100 | 101 | @ Initialize the local stacks with the initial data from the input 102 | read_init_data_outer_loop: 103 | iconst_0 104 | istore 20 105 | read_init_data_inner_loop: 106 | aload_2 107 | iload 13 108 | baload 109 | istore 4 110 | iload 4 111 | bipush ' ' 112 | if_icmpeq skip_push 113 | iload 20 114 | iload 4 115 | jsr local_stack_push 116 | skip_push: 117 | iinc 13, 4 118 | iinc 20, 1 119 | iload 20 120 | iload 0x3F 121 | isub 122 | ifne read_init_data_inner_loop 123 | //read_init_data_inner_break: 124 | iload 13 125 | iload 12 126 | iconst_1 127 | ishl 128 | isub 129 | istore 13 130 | iload 13 131 | ifgt read_init_data_outer_loop 132 | 133 | iload 22 134 | ifne do_part2_operations_outer_loop 135 | 136 | do_part1_operations_outer_loop: 137 | jsr atoi 138 | istore 12 @ Number of items to move 139 | iinc 11, 6 @ Skip " from " 140 | jsr atoi 141 | iconst_1 142 | isub @ Convert to 0 indexed 143 | istore 13 144 | iinc 11, 4 @ Skip " to " 145 | jsr atoi 146 | iconst_1 147 | isub @ Convert to 0 indexed 148 | istore 14 149 | do_part1_operations_inner_loop: 150 | iload 14 151 | iload 13 152 | jsr local_stack_pop 153 | jsr local_stack_push 154 | iinc 12, -1 155 | iload 12 156 | ifne do_part1_operations_inner_loop 157 | //do_part1_operations_inner_break: 158 | iinc 11, 6 @ Skip "\nmove " 159 | iload 11 160 | aload_2 161 | arraylength 162 | if_icmplt do_part1_operations_outer_loop 163 | goto skip_part2 164 | 165 | do_part2_operations_outer_loop: 166 | jsr atoi 167 | istore 12 @ Number of items to move 168 | iinc 11, 6 @ Skip " from " 169 | jsr atoi 170 | iconst_1 171 | isub @ Convert to 0 indexed 172 | istore 13 173 | iinc 11, 4 @ Skip " to " 174 | jsr atoi 175 | iconst_1 176 | isub @ Convert to 0 indexed 177 | istore 14 178 | iload 12 179 | istore 15 180 | do_part2_operations_inner_loop_1: 181 | iload 0x3F 182 | iload 13 183 | jsr local_stack_pop 184 | jsr local_stack_push 185 | iinc 15, -1 186 | iload 15 187 | ifne do_part2_operations_inner_loop_1 188 | 189 | iload 12 190 | istore 15 191 | do_part2_operations_inner_loop_2: 192 | iload 14 193 | iload 0x3F 194 | jsr local_stack_pop 195 | jsr local_stack_push 196 | iinc 15, -1 197 | iload 15 198 | ifne do_part2_operations_inner_loop_2 199 | 200 | iinc 11, 6 @ Skip "\nmove " 201 | iload 11 202 | aload_2 203 | arraylength 204 | if_icmplt do_part2_operations_outer_loop 205 | 206 | skip_part2: 207 | 208 | @ Pop off the top of each stack and store those in the output buffer 209 | iconst_0 210 | istore 7 211 | read_output_loop: 212 | iload 7 213 | jsr local_stack_pop 214 | istore 4 215 | aload_3 216 | iload 21 217 | iload 4 218 | bastore 219 | iinc 7, 1 220 | iinc 21, 1 221 | iload 7 222 | iload 0x3F 223 | if_icmpne read_output_loop 224 | 225 | iload 22 226 | ifne return_lab 227 | iinc 22, 1 228 | aload_3 229 | iload 21 230 | bipush ' ' 231 | bastore 232 | iinc 21, 1 233 | goto reset_repeat @ Reread the entire input data into the stacks again for part 2 234 | 235 | return_lab: 236 | aload_3 237 | iload 21 238 | iconst_0 239 | bastore 240 | 241 | ireturn 242 | 243 | @ Takes index in local var 11, into array ref in local var 2, returns integer on the stack and updates local var to point to the first found non-decimal char 244 | @ Clobbers: 0, 4, 5 245 | atoi: 246 | istore_0 @ Store return address 247 | iconst_0 248 | istore 4 249 | atoi_loop: 250 | aload_2 251 | iload 11 252 | baload 253 | istore 5 254 | iload 5 255 | bipush '0' 256 | if_icmplt atoi_break 257 | iload 5 258 | bipush '9' 259 | if_icmpgt atoi_break 260 | iload 4 261 | bipush 10 262 | imul 263 | iload 5 264 | bipush '0' 265 | isub 266 | iadd 267 | istore 4 268 | iinc 11, 1 269 | goto atoi_loop 270 | atoi_break: 271 | iload 4 272 | ret 0 273 | 274 | @ Takes index of stack and int value to store 275 | @ Clobbers: 0, 1, 4, 5, 6, 7, 8, 9 276 | local_stack_push: 277 | istore_0 @ Store return address 278 | istore 4 @ Store value to store 279 | istore 6 @ Store index 280 | 281 | iload 6 282 | jsr local_var_array_load @ Get current length of target stack 283 | istore 7 284 | 285 | iload 6 286 | bipush 6 287 | ishl @ Multiply index by 64 288 | iload 0x3F 289 | iconst_1 290 | iadd 291 | iadd @ Add number of stacks (advance past stack lengths) 292 | iload 7 293 | iadd @ Add current length of stack, we now have the index at which to store the new value 294 | 295 | iload 4 296 | jsr local_var_array_store @ Store it 297 | 298 | iload 6 299 | iinc 7, 1 @ Increment stack size 300 | iload 7 301 | jsr local_var_array_store 302 | 303 | ret 0 304 | 305 | 306 | @ Takes index of stack, returns value popped 307 | @ Clobbers: 0, 1, 4, 5, 6, 8, 9 308 | local_stack_pop: 309 | istore_0 @ Store return address 310 | istore 6 @ Store index 311 | 312 | iload 6 313 | jsr local_var_array_load @ Get current length of target stack 314 | iconst_1 315 | isub @ Subtract 1 from it, so it is now the index in the stack of the item we want to pop, and the new length 316 | istore 4 317 | 318 | iload 6 319 | bipush 6 320 | ishl @ Multiply index by 64 321 | iload 0x3F 322 | iconst_1 323 | iadd 324 | iadd @ Add number of stacks (advance past stack lengths) 325 | iload 4 326 | iadd @ Add index of item to pop 327 | 328 | jsr local_var_array_load @ Get the value 329 | 330 | iload 6 331 | iload 4 332 | jsr local_var_array_store @ Store new stack size 333 | 334 | ret 0 335 | 336 | 337 | @ Takes an index on the stack, uses a stupid hack to read the local variable index 0x40+(arg/4), then extracts the (arg%4)th byte from it and returns it on the stack 338 | @ Clobbers: 1, 5, 8, 9 339 | local_var_array_load: 340 | istore 8 @ Store return address 341 | istore 9 @ Store index 342 | iload 9 343 | iconst_2 344 | iushr 345 | iconst_2 346 | ishl @ Chop off the 2 lowest bits of the index (round down to multiple of 4) 347 | jsr stupid_load_next_instr @ Get the absolute address of the next instruction 348 | stupid_load_next_instr: 349 | istore_1 350 | iload_1 351 | iadd @ Add rounded index passed 352 | istore 5 @ Store this in a local var 353 | iinc 1, (stupid_load_after_table - stupid_load_next_instr) @ Set up the address to return to from the table 354 | iinc 5, (stupid_load_table - stupid_load_next_instr) @ This value now points to the appropriate instruction in the table 355 | ret 5 @ Jump into the table 356 | stupid_load_after_table: 357 | iload 9 358 | iconst_3 359 | iand @ Get index % 4 360 | iconst_3 361 | ishl @ Multiply by 8 362 | iushr @ Shift the value we loaded from the array to the right such that the target byte is now in the lowest 8 bits 363 | bipush -1 364 | bipush 24 365 | iushr 366 | iand @ Mask so we now have only this byte in an int 367 | ret 8 @ Return it 368 | 369 | @ Same thing as previous func, but takes index and value to store 370 | @ Clobbers: 1, 4, 5, 8, 9 371 | local_var_array_store: 372 | istore 8 @ Store return address 373 | istore 4 @ Store value to store 374 | istore 9 @ Store index 375 | iload 9 376 | iconst_2 377 | iushr 378 | iconst_2 379 | ishl @ Chop off the 2 lowest bits of the index (round down to multiple of 4) 380 | jsr stupid_store_next_instr @ Get the absolute address of the next instruction 381 | stupid_store_next_instr: 382 | istore_1 383 | iload_1 384 | iadd @ Add rounded index 385 | istore 5 @ Store this in a local var 386 | iinc 1, (stupid_store_after_table - stupid_store_next_instr) @ Set up the address to return to from the table 387 | iinc 5, (stupid_load_table - stupid_store_next_instr) @ This value now points to the appropriate instruction in the table 388 | ret 5 @ Jump into the load table 389 | stupid_store_after_table: 390 | iload 9 391 | iconst_3 392 | iand @ Get index % 4 393 | iconst_3 394 | ishl @ Multiply by 8 395 | istore 9 396 | bipush -1 397 | bipush 24 398 | iushr 399 | iload 9 400 | ishl 401 | bipush -1 402 | ixor 403 | iand @ We have now masked out the byte we're trying to modify to 0 404 | iload 4 405 | iload 9 406 | ishl 407 | ior @ We now have the final int to write back to local storage 408 | 409 | iload 8 410 | istore_1 411 | iload 5 412 | bipush ((stupid_store_table - stupid_load_table) >> 4) 413 | iconst_4 414 | ishl 415 | iadd @ This just advances our old index into the load table to instead point into the store table. Didn't fit in signed 8 bits so couldn't use iinc 416 | istore 5 417 | ret 5 @ Jump into the store table, and return to the caller from there 418 | 419 | @ Generates stupid tables of instructions. Args are inclusive. 420 | .macro rept_with_ret instr, from, to 421 | \instr \from 422 | ret 1 423 | \instr \from+1 424 | ret 1 425 | \instr \from+2 426 | ret 1 427 | \instr \from+3 428 | ret 1 429 | .if \to-\from 430 | rept_with_ret \instr, "(\from+4)",\to 431 | .endif 432 | .endm 433 | 434 | stupid_load_table: 435 | rept_with_ret iload, 0x40, 0xFC 436 | 437 | stupid_store_table: 438 | rept_with_ret istore, 0x40, 0xFC -------------------------------------------------------------------------------- /day05-jazelle/source/test_bytecode.s: -------------------------------------------------------------------------------- 1 | #include "bytecode.h" 2 | 3 | .section .text 4 | 5 | @ tests simple bytecode functionality and array loading 6 | .global test_bytecode 7 | test_bytecode: 8 | @ we are passed an array reference on the stack 9 | iconst_0 10 | @ load index 0 from it 11 | iaload 12 | @ add 5 to that value 13 | bipush 5 14 | iadd 15 | @ return it 16 | ireturn 17 | -------------------------------------------------------------------------------- /day06-mipsel/README.md: -------------------------------------------------------------------------------- 1 | This one was a few days late, and I still haven't finished day 5. This is partially because I'm getting busy with college finals, partially because I had some unexpected hiccups getting any code to run on the device for day 6, and also because I picked a rather extreme option for day 5. The next few days will probably continue to come in late, but ~~I still intend to complete everything before the 25th.~~ *Hello from the 26th! Let's just ignore what past me said here, yeah?* 2 | 3 | Anyway, day 6 was run on the MIPS 24KEc in a Netgear WN3000RP v3 WiFi extender running OpenWrt Linux. Getting things to compile for this machine was a bit of an adventure that led me to commit acts of insanity such as patching `libc.a` with a hex editor, but that's irrelevant to the code which actually solves the puzzle. Output screenshot: [ouptut.jpg](output.jpg). 4 | -------------------------------------------------------------------------------- /day06-mipsel/build.sh: -------------------------------------------------------------------------------- 1 | mipsel-linux-gnu-gcc -static -march=24kec *.S -o tuning-trouble 2 | -------------------------------------------------------------------------------- /day06-mipsel/input.txt: -------------------------------------------------------------------------------- 1 | rvnvzvhzzjgjgffclllnhhtltptgptgpttjhttsllmbbphbpbzpbpjjcwjwqwccnrrtvrtrfrwffnqffsggwzzhtzhthqhffmrrzsrrnrtrqqbllhrlrjrvvrvvgdgjgfjjtzznffrfvfggswgssccpcwpccstcsstwssgzssswsgwsgsnsshcsscsffcwcmmhmsmrsrddwhhszsfsjfsfccwssvdssmzzwrzzjfzzvzzfsfsvshschhvlhhvmvpvhhstsdtstgtrrtjjcssgfssnsnfsnscnsslvvqbbhthqtqzqmzmjjfmmbdmmzdmdpmpnnfjnnrwnwbwrrwjrrttfzzlwwfmmnhhqlhqqbnqnqznncmmhfmfftsfszssftstggppfddtztltctqcqjcqcmclcnccdgcggvmvvcsstztbzttsccmgcghcczfzszbzmbmjjggsqgghbhjjhhrrjljmllczlzzqssjfjqfjfmfdfgffczfzwwpfwpwbbftbffplphhfcftctlcclhlnlhnhlhnhqnhhjbjmmtpmmlsmllvhhjghhmzzwpzprrjrzzvrvcvqvssgssnccmgmppfhfwhhczhhprhrffpvvqrqvqccdhdvvvssvdvwdwwzggfvfnvvqvwwzwmzzvttgzzwjjfvvpvffqpqhqrrwccjbjppbzbrbrrphrhgrhhzbbhrrblbjjznnlccsffpcfpcfpfddfwddbffczztzsttzsstddrqdqqchqccrlccfcwwghwhnhbhjbhhzrrgprrftrffqlljlslggzdzvvrgvgcgnnngtnggdcgddhjhchqcqfqwfwjffqppblbddgmdgmddrnddjtdjttgzgpzggwvwjvwwhdwwbvvtftcfttpftpfpzfznnchnhrrdtdbtdbdppsjsgsttptsptssnwntwnnsshqqgnnqnddhjjtqqjhhmghmhmsstrrhmmwvvlssprsrbbswsddbnntmtbmtbmmtmrrffvjffdrffnttbffbccgchghjgjwwshwswdswdsdsrdsdjdvjjgbjbssptpddzbdddqdpdspswssjrjwwcbbvsspnspslpplzlqlccvlvfllntlntnqnrqnqpqlqflfrfsfgsfswwptwwgqggrhghzghhrthtzhzsswhhzffpsffhnnrvnrvvhmmlvvqsslddhcddsllpmpggrhrcrbbmnmjmqmlmpmrrqwqhqrqhrrgrqqsrrpjpdjppzhphthddlzdzhddjvdjdcjcncnvnzzvwzvzgzjggcllvpllgdgqqdvvwnvwvwqqvwvvrbbtqqwhdztqfzzcqrshjzwqnpdsshmpjzwqdptbvfqzmfnbtlgbbsjbqgnblhbbpsfdzvcmpzfwczcnbdndsjzccjcqnrdglwfrvwtnjwpvpvvgwtmnpzhbwnbqwznmdvdrsjnlsfrpcnhlbmlgmrcjbbvhqnvbrmlnfttjllstqnqqnhqrzrhfqjbfbwfhhjzwtwzjmszzhjnjbhrlbnnpfvdmlftjnfsfnvddqfhqqlljrthptvmhbqrdmdcmljwgbrqrjwcrtmvjgqtblnslgbjmdsrrpgfsctrhwlwnszpljhrfnsfpcsgczzltgsztclhgcqljrcmbbpdlztncnrnrmgrttplcnldfqddqhznmcczbmwvsztmwmcqnrzmlmqchnhnhrrhhfntjzqcbnttspptqwvphlbtpfcbhdqzbhsbvhmsqbsdntwpcrnzvmbgqsgttbqhhblfjpmvfcrzhfnzwrzbzgsdfqndzzhfdnrvsnvfbptthjnhgljhrvwwrlbnfpvvjdjchcgbhfrqvszhrhqvtzplwsptvdhqwlzhcjpclmmrlccvgvtgsfpnjhqhrbqglznpdhmsqwwsbmhmlsmmvvghsmplqjchrfctltmnqnddzqjfpljwljbdqjcqdqzwsbcclqsmsmlstvljwwtfmpnhqzqfjghjfchjccqrchsvngvrnwfwttsnvrdlfvwfptsjcpslvvpmjclfcpljqjszptsgsmntzrdjbgrzmgvzddqrlsndjzzqbznqnphbnwfhtjjlwjpsvffrdrbsbttpgrvmqrdndqvlgzcpfbttvqdgvrmtvfclcbcwllthmdzjcflwpnrsqzrjdzbvqgzsqvjjpjjpnjtcjqhcfbjdqndlcwzhcbjtgtlvtdwctdnqcbcgsmrcrmwjntdwbjdbzmshbvlspjfdbvmlrbdzlmlggthvphnrqlrcdsqpsgqcmpgmgdzvdqlmcldvztpsbmpwjgjfhswplwrvwpbwbsgsvlhdvmpzwnnbwjwmshwcnqfqjdpchfjjcbdnslqchhnznpqpnnctznbtccclgjhmnngdjlmqnzpsdptqqcrblmrlnnpgvrfrtmbjnmspfrbwpclhgtbsghndrjfbggsplvcjnhjjbqzsfdpfnvchzjgbhdqgddfgddvzdcrjlntnsmscqwmpptqgbnvtsvpjvmhcfpbfrpzqbpfhlbjrmbmvdvvnvfqsndglvhfrqcsbsbbprscrbfthzcwcdrprqrwjzwrpblfllpwzlhmqvltjgpcjzpzwbltgwsrgrrhzcqfpvhcprdhnzcfphqrwcvtpcbppjwzmmwjhbvwbblnbwvcqzvlfzjhgmlnhlhrbsplfctggfbhbgwpncznvtmdtqqmjsvsnrlqswzvflrfsncgpdcndlwrfrqwqnqtjmsphwsgzhdjpnsdgrbrfhbfdrntwvgvbwnvwnrmdbhqgrglbfwprflnrljrwsgwtpgtmfhvvghtzndvwlzjchhmlwcncmpvrslrglzjcnhfdqhcrljhgbzpssvdnmfwzstmvrztgpsscfswltnbwrrtcnvbswmmjbmnnnvqwjzhprfnvlbvzzdvbwlwchrvqnwwpbnttbhfdvjjvzsznhczjcncmcrmwtrlsvbwpsrcwqdvgcfjsbqnwmjmtcgpnmcbfbcqhzrjbtlpvwzhjqqprbdnbgzfwlprlcspwjwnfftldqzbcgqnjtglvbpqffdvjbpslqcdzwdnmncvcwfshdhsmssttqfrsbnjgmhfqzlgrbpdfqtfdwslsgphfzzgbzjssfbgnwztzmczplqwjmhtlflpvqqqmrvlllhngtfgsvbbnvhzqbcgpmnlsmpwqwgqfjpzplzjhrslwzrsrgjgpppjlnhrnggcdzvspsztnschnqftgffbtvrpzndzpqmtsfmwgnrvpmtgpvnmqfmwgcvlznwqnjnjwpgnqfjwtdhhmztlvlcvrlzmlpmjdvdnzwbfsshfsvbbhqsmphjhqtlnvlsmvwlqvfqpnjnzlgmdvwzzrllmcgwtqdwphhbwmlrqhqrfmdvtqswvsllqvwmfbbpllsbjbvgsmrcgqvfgsnszfrdlcjbtfgcbclhmzlmqlnhmslcmgrcvjjlbpsjjcznzqwmztcgdgbmrlgwzjzzjrpndfrdzztzzgmsrcnwrvqrdcczrbhdpfjwvqsmbrcvllvjrrbrsqnzldltdgzscjrssvdhzhnvltpgfdfcvfbtqmphdzhpzgjhjbwsmdlbqqgcrhjrwhgvfgdllmmlnpsbtvdrrzmltfwgrcsfrrsdbdmjtrwhnlgcrgjgmbzvzvqbflvbrsqcssjgsvpjmlhtcggzwbvddmwwtfdrlltjqcpwnthczzlzdszvtmrmhbpcgstvrsnmbdcmjzsvnncmgmlnrzzhfvmblgptwwwbrmtcczjwcqmvdrsvfjgqqvghnhbntqcdrppfmvdzbcjvztrnpdhmdpmnvsnzzldvdfqbdrwqqqqsmswthwpjwdrflszbspqhpfwztjjcbdsrftdsrsfdltnfztcslmbsghgrtcscrfmptqplwpmtqdzthgfjhbqdnsffrpjmgczmrlfvzcjttwtmtqfbtlqrttvjdwhfgcgcclrlswmzhzbfhjrggnhwtnffnqqcvldlttvvgrbcqbmqzvtflfmdblhdbzphrqtbshvp 2 | -------------------------------------------------------------------------------- /day06-mipsel/main.S: -------------------------------------------------------------------------------- 1 | .section .text 2 | 3 | .global main 4 | .type main, @function 5 | main: 6 | 7 | addi $sp, $sp, -8 8 | sw $s0, 4($sp) 9 | sw $ra, 0($sp) 10 | lw $s0, 4($a1) // argv[1] 11 | 12 | lui $a0, %hi(hello_world_string) 13 | addiu $a0, $a0, %lo(hello_world_string) 14 | jal printf 15 | 16 | add $t0, $zero, $s0 17 | addi $s0, $zero, 0 18 | addi $t2, $zero, 0 19 | addi $t5, $zero, 0 20 | addi $t6, $zero, 13 21 | lui $t8, %hi(part2_buffer) 22 | addiu $t8, $t8, %lo(part2_buffer) 23 | 24 | main_loop: 25 | lb $t1, ($t0) 26 | addi $t0, $t0, 1 27 | addi $t5, $t5, 1 28 | beq $t1, $zero, main_problem // if we hit the null terminator, something went wrong 29 | sll $t2, $t2, 8 30 | or $t2, $t2, $t1 31 | add $t7, $t8, $t6 32 | sb $t1, ($t7) 33 | addi $t6, $t6, -1 34 | bgez $t6, skip_wrap 35 | addi $t6, $zero, 13 36 | skip_wrap: 37 | 38 | // If we already got the answer to part1, skip it 39 | bnez $s0, part1_check_skip 40 | 41 | // If we haven't read 4 chars yet, can't have a match yet 42 | srl $t3, $t2, 24 43 | beq $t3, $zero, main_loop 44 | 45 | // Check if any of the 4 bytes of $t2 match each other 46 | add $t3, $zero, $t2 47 | part1_check_loop: 48 | andi $t1, $t3, 0xFF 49 | srl $t3, $t3, 8 50 | beq $t3, $zero, part1_check_hit 51 | 52 | andi $t4, $t3, 0xFF 53 | beq $t1, $t4, main_loop 54 | srl $t4, $t3, 8 55 | andi $t4, $t4, 0xFF 56 | beq $t1, $t4, main_loop 57 | srl $t4, $t3, 16 58 | beq $t1, $t4, main_loop 59 | j part1_check_loop 60 | part1_check_hit: 61 | add $s0, $zero, $t5 62 | part1_check_skip: 63 | 64 | // If we haven't read 14 chars yet, can't have a part 2 match yet 65 | addi $t3, $t5, -14 66 | bltz $t3, main_loop 67 | 68 | addi $t3, $zero, 13 69 | part2_outer_loop: 70 | add $t7, $t8, $t3 71 | lb $t1, ($t7) 72 | addi $t4, $t3, -1 73 | part2_inner_loop: 74 | add $t7, $t8, $t4 75 | lb $t7, ($t7) 76 | beq $t7, $t1, main_loop 77 | addi $t4, $t4, -1 78 | bgez $t4, part2_inner_loop 79 | 80 | addi $t3, $t3, -1 81 | bgtz $t3, part2_outer_loop 82 | 83 | main_break: 84 | lui $a0, %hi(part1_string) 85 | addiu $a0, $a0, %lo(part1_string) 86 | add $a1, $zero, $s0 87 | add $s0, $zero, $t5 88 | jal printf 89 | lui $a0, %hi(part2_string) 90 | addiu $a0, $a0, %lo(part2_string) 91 | add $a1, $zero, $s0 92 | jal printf 93 | 94 | main_end: 95 | add $v0, $zero, $zero 96 | lw $ra, 0($sp) 97 | lw $s0, 4($sp) 98 | addi $sp, $sp, 8 99 | jr $ra 100 | 101 | main_problem: 102 | lui $a0, %hi(problem_string) 103 | addiu $a0, $a0, %lo(problem_string) 104 | add $a1, $zero, $t2 105 | jal printf 106 | j main_end 107 | 108 | 109 | .section .bss 110 | 111 | part2_buffer: 112 | .space 14 113 | 114 | .section .rodata 115 | 116 | hello_world_string: 117 | .ascii "bunny!\n\0" 118 | part1_string: 119 | .ascii "Part 1: %u\n\0" 120 | part2_string: 121 | .ascii "Part 2: %u\n\0" 122 | problem_string: 123 | .ascii "Something went wrong t2: %X\n\0" -------------------------------------------------------------------------------- /day06-mipsel/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day06-mipsel/output.jpg -------------------------------------------------------------------------------- /day07-mips/README.md: -------------------------------------------------------------------------------- 1 | Day 7 was completed on the Broadcom BMIPS4350 in an old Verizon-branded DSL modem-router (model number GT784WNV) running OpenWrt Linux. I guess it's kinda lame of me to do two days in row both in MIPS and both on networky things running OpenWrt, but this one was big ~~girl~~ endian MIPS so it's definitely within the rules, and I had to fight even harder with libc to get anything to run on this one and ended up giving up and using `-nostdlib`, so I guess that struggle is what I get for being a bit lame. Output screenshot: [ouptut.jpg](output.jpg). 2 | -------------------------------------------------------------------------------- /day07-mips/build.sh: -------------------------------------------------------------------------------- 1 | mips-linux-gnu-gcc -nostdlib -mno-gpopt -mno-abicalls -march=mips32 *.S -o no-space 2 | -------------------------------------------------------------------------------- /day07-mips/input.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir dpllhlcv 4 | 284723 hznrlfhh.tnz 5 | dir mgjdlmrz 6 | dir njstc 7 | dir nzwbc 8 | dir qzzfvdh 9 | dir smvhphf 10 | $ cd dpllhlcv 11 | $ ls 12 | 11223 bplz.rdp 13 | dir gpmlznd 14 | dir pgcctrb 15 | dir wmsl 16 | $ cd gpmlznd 17 | $ ls 18 | dir lwzcss 19 | 83678 nzwbc.rgv 20 | dir rhdllvm 21 | 94635 wpglzlrf.htl 22 | $ cd lwzcss 23 | $ ls 24 | dir bttplh 25 | $ cd bttplh 26 | $ ls 27 | dir rzj 28 | $ cd rzj 29 | $ ls 30 | 59866 nzwbc.psj 31 | $ cd .. 32 | $ cd .. 33 | $ cd .. 34 | $ cd rhdllvm 35 | $ ls 36 | dir mvqfrq 37 | $ cd mvqfrq 38 | $ ls 39 | 41266 prvl 40 | $ cd .. 41 | $ cd .. 42 | $ cd .. 43 | $ cd pgcctrb 44 | $ ls 45 | dir dgpfcftj 46 | $ cd dgpfcftj 47 | $ ls 48 | 101757 tzjthwc 49 | $ cd .. 50 | $ cd .. 51 | $ cd wmsl 52 | $ ls 53 | 215238 bvlvn.pgf 54 | dir hhtztpm 55 | 197563 hznrlfhh.tnz 56 | dir tzjthwc 57 | $ cd hhtztpm 58 | $ ls 59 | 196378 djfbm.djl 60 | 203856 ltnwbvg.rqz 61 | 266242 mjrlm 62 | dir ngjd 63 | dir wmsl 64 | $ cd ngjd 65 | $ ls 66 | 289546 mjrlm 67 | $ cd .. 68 | $ cd wmsl 69 | $ ls 70 | 153439 qqb.qmd 71 | 25326 tzjthwc 72 | $ cd .. 73 | $ cd .. 74 | $ cd tzjthwc 75 | $ ls 76 | dir lhccf 77 | 235335 nzwbc 78 | dir wgnhhl 79 | dir wmsl 80 | $ cd lhccf 81 | $ ls 82 | dir nzwbc 83 | 100347 rrrj.wzl 84 | dir zfwffjn 85 | $ cd nzwbc 86 | $ ls 87 | dir wmsl 88 | $ cd wmsl 89 | $ ls 90 | 102053 nzwbc.qbd 91 | $ cd .. 92 | $ cd .. 93 | $ cd zfwffjn 94 | $ ls 95 | dir mrd 96 | 23992 rrrj.jcz 97 | dir vnwpddtf 98 | $ cd mrd 99 | $ ls 100 | 139407 qqwlrbsw.zfn 101 | $ cd .. 102 | $ cd vnwpddtf 103 | $ ls 104 | 287771 dgpfcftj.wpm 105 | 59212 qqb.qmd 106 | $ cd .. 107 | $ cd .. 108 | $ cd .. 109 | $ cd wgnhhl 110 | $ ls 111 | 120460 rrrj 112 | $ cd .. 113 | $ cd wmsl 114 | $ ls 115 | 17612 rlsswjw.wbr 116 | 132954 ttbswbhs.ffs 117 | dir zpldfrj 118 | $ cd zpldfrj 119 | $ ls 120 | 180679 qljrrlm.clw 121 | $ cd .. 122 | $ cd .. 123 | $ cd .. 124 | $ cd .. 125 | $ cd .. 126 | $ cd mgjdlmrz 127 | $ ls 128 | 79173 dng.qrc 129 | dir fnfw 130 | dir hwb 131 | dir nfqzjs 132 | dir qdgplmrt 133 | dir znrnj 134 | $ cd fnfw 135 | $ ls 136 | dir bhjm 137 | 263282 bplz.rdp 138 | dir dhsvtfc 139 | dir hlh 140 | dir nzwbc 141 | 177780 ttbswbhs.ffs 142 | 28452 tzjthwc.wlq 143 | 19548 wmsl.rmd 144 | $ cd bhjm 145 | $ ls 146 | dir bpl 147 | 57561 dgpfcftj 148 | dir glplnd 149 | 170692 hwsjhwvf.rmv 150 | dir rrrj 151 | dir tlltjd 152 | dir tzjthwc 153 | dir wmsl 154 | $ cd bpl 155 | $ ls 156 | dir btpglc 157 | 275227 fmbpzn 158 | 9798 mjztf.nlg 159 | 190388 nzwbc 160 | dir tzjthwc 161 | $ cd btpglc 162 | $ ls 163 | 276105 rrrj.rhl 164 | $ cd .. 165 | $ cd tzjthwc 166 | $ ls 167 | dir hqmw 168 | 280196 hznrlfhh.tnz 169 | 51545 mjrlm 170 | 228230 wmsl 171 | $ cd hqmw 172 | $ ls 173 | 163168 mchnt.pls 174 | $ cd .. 175 | $ cd .. 176 | $ cd .. 177 | $ cd glplnd 178 | $ ls 179 | 147261 bplz.rdp 180 | 267191 hznrlfhh.tnz 181 | $ cd .. 182 | $ cd rrrj 183 | $ ls 184 | dir dgpfcftj 185 | dir fwdw 186 | 277548 hnz 187 | 164103 nvcsdq.tpj 188 | 265477 qzwsg.ccl 189 | dir tnpjsgnq 190 | dir tpvttzv 191 | 209300 wmsl.wtq 192 | $ cd dgpfcftj 193 | $ ls 194 | dir dqtbltwp 195 | $ cd dqtbltwp 196 | $ ls 197 | 27856 tzjthwc.gnr 198 | $ cd .. 199 | $ cd .. 200 | $ cd fwdw 201 | $ ls 202 | 166347 fgtfj.pnc 203 | 140486 mspn.wcw 204 | 26602 nzwbc.dhb 205 | 81490 qqb.qmd 206 | $ cd .. 207 | $ cd tnpjsgnq 208 | $ ls 209 | dir gbddb 210 | dir gpqssnq 211 | $ cd gbddb 212 | $ ls 213 | 1587 qqb.qmd 214 | $ cd .. 215 | $ cd gpqssnq 216 | $ ls 217 | 33979 fmjpw.mtp 218 | $ cd .. 219 | $ cd .. 220 | $ cd tpvttzv 221 | $ ls 222 | dir bqvzmb 223 | $ cd bqvzmb 224 | $ ls 225 | 79211 fdhjztlv 226 | 72991 wgvqvdp.pzp 227 | $ cd .. 228 | $ cd .. 229 | $ cd .. 230 | $ cd tlltjd 231 | $ ls 232 | 58096 swqcsnw 233 | $ cd .. 234 | $ cd tzjthwc 235 | $ ls 236 | 66628 pzrdpc.fpc 237 | $ cd .. 238 | $ cd wmsl 239 | $ ls 240 | 43111 hznrlfhh.tnz 241 | 114356 rrrj.rlf 242 | 169873 zpwhgzvc.wql 243 | $ cd .. 244 | $ cd .. 245 | $ cd dhsvtfc 246 | $ ls 247 | dir cwbq 248 | 201361 dgpfcftj 249 | 291508 jjjjwcw 250 | 445 pfdvf.pmj 251 | 135732 qpc.gsw 252 | 115597 wlgrtn.mjb 253 | dir wmsl 254 | $ cd cwbq 255 | $ ls 256 | dir ccgdn 257 | dir gcfbqh 258 | 173860 hznrlfhh.tnz 259 | 97790 mjrlm 260 | dir qtfhz 261 | dir tpgj 262 | dir tph 263 | $ cd ccgdn 264 | $ ls 265 | dir blnzrjm 266 | 46502 fgmntg.crb 267 | dir fwdpw 268 | dir nbldsrfq 269 | 11175 nwj.fht 270 | 208129 qqb.qmd 271 | dir wpj 272 | $ cd blnzrjm 273 | $ ls 274 | 121398 gvs 275 | 201215 pdppzscr.vph 276 | dir pwj 277 | 3861 smwrnw.hqp 278 | dir tzjthwc 279 | 220659 wzccnw.lsc 280 | $ cd pwj 281 | $ ls 282 | 279141 bwj.ntc 283 | 15325 jvqwhwmh.brq 284 | $ cd .. 285 | $ cd tzjthwc 286 | $ ls 287 | 25191 jdgphj 288 | 70354 rrrj.szq 289 | 256692 wmsl 290 | $ cd .. 291 | $ cd .. 292 | $ cd fwdpw 293 | $ ls 294 | 28780 prhjf 295 | $ cd .. 296 | $ cd nbldsrfq 297 | $ ls 298 | 57352 dcrhr 299 | $ cd .. 300 | $ cd wpj 301 | $ ls 302 | 51243 jmdn.bzh 303 | $ cd .. 304 | $ cd .. 305 | $ cd gcfbqh 306 | $ ls 307 | 92250 crmpsc.rbf 308 | 284234 tzjthwc 309 | $ cd .. 310 | $ cd qtfhz 311 | $ ls 312 | 164311 hznrlfhh.tnz 313 | 137031 mjrlm 314 | $ cd .. 315 | $ cd tpgj 316 | $ ls 317 | 210570 jdpv.fpw 318 | $ cd .. 319 | $ cd tph 320 | $ ls 321 | dir hptp 322 | dir rrrj 323 | $ cd hptp 324 | $ ls 325 | 272964 qqb.qmd 326 | 147435 svrcpb 327 | $ cd .. 328 | $ cd rrrj 329 | $ ls 330 | 145269 btzl.vcs 331 | 156500 tzjthwc.ddw 332 | 236073 vsrghnhl.wdc 333 | $ cd .. 334 | $ cd .. 335 | $ cd .. 336 | $ cd wmsl 337 | $ ls 338 | 62697 mjrlm 339 | dir psndpb 340 | 33688 tzjthwc.hjc 341 | 100902 tzjthwc.rnm 342 | $ cd psndpb 343 | $ ls 344 | dir dbm 345 | dir fbmfpndf 346 | dir fstgbcrc 347 | 272771 lszgqt 348 | 136189 mjrlm 349 | 166606 qqb.qmd 350 | dir vptjzdt 351 | $ cd dbm 352 | $ ls 353 | dir nzwbc 354 | dir tzjthwc 355 | $ cd nzwbc 356 | $ ls 357 | dir ffmrngmj 358 | $ cd ffmrngmj 359 | $ ls 360 | 299742 nrwrptz.cmp 361 | $ cd .. 362 | $ cd .. 363 | $ cd tzjthwc 364 | $ ls 365 | 268152 pln 366 | $ cd .. 367 | $ cd .. 368 | $ cd fbmfpndf 369 | $ ls 370 | 186758 bplz.rdp 371 | $ cd .. 372 | $ cd fstgbcrc 373 | $ ls 374 | 4975 hznrlfhh.tnz 375 | 59093 mjrlm 376 | dir nzwbc 377 | 279246 qqb.qmd 378 | $ cd nzwbc 379 | $ ls 380 | 152443 nzwbc 381 | $ cd .. 382 | $ cd .. 383 | $ cd vptjzdt 384 | $ ls 385 | 117403 ttbswbhs.ffs 386 | $ cd .. 387 | $ cd .. 388 | $ cd .. 389 | $ cd .. 390 | $ cd hlh 391 | $ ls 392 | 96676 rrrj.mfv 393 | $ cd .. 394 | $ cd nzwbc 395 | $ ls 396 | 192533 njwsbs.srq 397 | $ cd .. 398 | $ cd .. 399 | $ cd hwb 400 | $ ls 401 | 44576 dshmsgj.cnd 402 | 70710 tdcgvdv.phs 403 | $ cd .. 404 | $ cd nfqzjs 405 | $ ls 406 | 18103 tfwmgdj 407 | $ cd .. 408 | $ cd qdgplmrt 409 | $ ls 410 | 163549 mjrlm 411 | $ cd .. 412 | $ cd znrnj 413 | $ ls 414 | dir dgpfcftj 415 | 53146 mzbpjgd.lmp 416 | 202250 vmtdc 417 | $ cd dgpfcftj 418 | $ ls 419 | dir cdgrjlz 420 | 238240 fmtclb.vfq 421 | $ cd cdgrjlz 422 | $ ls 423 | 89863 dpnzsq.dbd 424 | 259686 mjrlm 425 | 50165 qqb.qmd 426 | $ cd .. 427 | $ cd .. 428 | $ cd .. 429 | $ cd .. 430 | $ cd njstc 431 | $ ls 432 | 70592 bplz.rdp 433 | 100122 ccdp.lpw 434 | dir jnffc 435 | dir jnrrwt 436 | 21922 lcr.mqp 437 | dir mdts 438 | 9581 rwdnfc.zqq 439 | dir zchc 440 | $ cd jnffc 441 | $ ls 442 | 54279 vbvpzw.rst 443 | 147514 vzshqq.qpb 444 | $ cd .. 445 | $ cd jnrrwt 446 | $ ls 447 | 51615 bplz.rdp 448 | dir fvmgmn 449 | dir wjrqnlr 450 | $ cd fvmgmn 451 | $ ls 452 | 159538 sntlcs.vms 453 | $ cd .. 454 | $ cd wjrqnlr 455 | $ ls 456 | dir dvcqnv 457 | dir jnjzlhhw 458 | 135325 mjrlm 459 | 94135 qqb.qmd 460 | $ cd dvcqnv 461 | $ ls 462 | 66408 mjrlm 463 | $ cd .. 464 | $ cd jnjzlhhw 465 | $ ls 466 | 89668 bplz.rdp 467 | dir btcjthr 468 | $ cd btcjthr 469 | $ ls 470 | dir sbcwwvj 471 | dir tzjthwc 472 | 280405 zjf.fqt 473 | $ cd sbcwwvj 474 | $ ls 475 | dir wmsl 476 | $ cd wmsl 477 | $ ls 478 | 31258 vfwqsw 479 | $ cd .. 480 | $ cd .. 481 | $ cd tzjthwc 482 | $ ls 483 | dir dgpfcftj 484 | $ cd dgpfcftj 485 | $ ls 486 | 281485 lhnnjrcq 487 | $ cd .. 488 | $ cd .. 489 | $ cd .. 490 | $ cd .. 491 | $ cd .. 492 | $ cd .. 493 | $ cd mdts 494 | $ ls 495 | 191614 ttbswbhs.ffs 496 | $ cd .. 497 | $ cd zchc 498 | $ ls 499 | dir rrrj 500 | $ cd rrrj 501 | $ ls 502 | 102230 ttbswbhs.ffs 503 | $ cd .. 504 | $ cd .. 505 | $ cd .. 506 | $ cd nzwbc 507 | $ ls 508 | 30185 bplz.rdp 509 | dir dgpfcftj 510 | 238614 hfg.tsw 511 | 215453 lzvmwg.crp 512 | dir mfbhtb 513 | dir nbdn 514 | dir nzw 515 | 77355 qqb.qmd 516 | 114201 wmsl 517 | dir zcv 518 | $ cd dgpfcftj 519 | $ ls 520 | 258786 dhdmsqfs.jhs 521 | dir ltrg 522 | dir nzwbc 523 | 18568 qqb.qmd 524 | $ cd ltrg 525 | $ ls 526 | dir nzwbc 527 | dir wmsl 528 | $ cd nzwbc 529 | $ ls 530 | 72334 fhd 531 | $ cd .. 532 | $ cd wmsl 533 | $ ls 534 | dir rvt 535 | $ cd rvt 536 | $ ls 537 | 232235 nzwbc 538 | $ cd .. 539 | $ cd .. 540 | $ cd .. 541 | $ cd nzwbc 542 | $ ls 543 | 29531 rnl 544 | $ cd .. 545 | $ cd .. 546 | $ cd mfbhtb 547 | $ ls 548 | 21538 sjrwtjcq 549 | $ cd .. 550 | $ cd nbdn 551 | $ ls 552 | 120432 bplz.rdp 553 | 180737 hjsv 554 | 295982 mjrlm 555 | dir rscwnwt 556 | 13218 vzjtg.hhp 557 | 1332 zjwf.spw 558 | $ cd rscwnwt 559 | $ ls 560 | 268727 fnvfrbzg.wmw 561 | 155540 jgfvpmp 562 | 242598 rrrj 563 | 47339 vqqqmg.dss 564 | $ cd .. 565 | $ cd .. 566 | $ cd nzw 567 | $ ls 568 | 135129 hfbptj.rsq 569 | dir nhzg 570 | dir qshfn 571 | $ cd nhzg 572 | $ ls 573 | 219375 tzjthwc.gsl 574 | $ cd .. 575 | $ cd qshfn 576 | $ ls 577 | dir pnjhczqg 578 | dir tzjthwc 579 | 279385 whsdfns 580 | 141044 wmsl.tpl 581 | $ cd pnjhczqg 582 | $ ls 583 | 141321 rlgtn.jvh 584 | dir wrh 585 | $ cd wrh 586 | $ ls 587 | 143304 sfvrld.nsz 588 | $ cd .. 589 | $ cd .. 590 | $ cd tzjthwc 591 | $ ls 592 | dir lnhmfb 593 | 168870 qqb.qmd 594 | 178464 rrrj.qml 595 | 201521 rwdwv.gnn 596 | 21171 vznflldw.zrf 597 | $ cd lnhmfb 598 | $ ls 599 | dir dzzdvmtl 600 | dir ttnm 601 | $ cd dzzdvmtl 602 | $ ls 603 | dir mrg 604 | $ cd mrg 605 | $ ls 606 | 174378 rrrj.lnh 607 | $ cd .. 608 | $ cd .. 609 | $ cd ttnm 610 | $ ls 611 | 272667 hznrlfhh.tnz 612 | 251551 wmsl.ggr 613 | 97289 wmsl.phl 614 | $ cd .. 615 | $ cd .. 616 | $ cd .. 617 | $ cd .. 618 | $ cd .. 619 | $ cd zcv 620 | $ ls 621 | dir cwsqwt 622 | dir dgpfcftj 623 | 256838 dntqvr.snf 624 | dir nbq 625 | dir nzbdsvt 626 | 293181 rrrj.lvd 627 | $ cd cwsqwt 628 | $ ls 629 | 141770 bbrgtfh.zmf 630 | 100359 mjrlm 631 | 96547 qqb.qmd 632 | 176620 ttbswbhs.ffs 633 | $ cd .. 634 | $ cd dgpfcftj 635 | $ ls 636 | 82245 pqjjnjrw 637 | 295247 rrrj.lfw 638 | $ cd .. 639 | $ cd nbq 640 | $ ls 641 | 132140 bwdvjv.gwq 642 | dir gbjtzhj 643 | dir mfsr 644 | dir nzwbc 645 | 248867 rrrj 646 | 226784 sjtsjgrb 647 | 94475 tjh.vft 648 | dir tzjthwc 649 | 149501 tzjthwc.rgb 650 | $ cd gbjtzhj 651 | $ ls 652 | 43689 rrrj.msh 653 | $ cd .. 654 | $ cd mfsr 655 | $ ls 656 | 30068 sntz.lqw 657 | dir tch 658 | dir zzgtsqvh 659 | $ cd tch 660 | $ ls 661 | dir tzjthwc 662 | $ cd tzjthwc 663 | $ ls 664 | 289238 sjwjdmd 665 | $ cd .. 666 | $ cd .. 667 | $ cd zzgtsqvh 668 | $ ls 669 | 289069 tzjthwc.mql 670 | $ cd .. 671 | $ cd .. 672 | $ cd nzwbc 673 | $ ls 674 | 138407 hgtr.hst 675 | $ cd .. 676 | $ cd tzjthwc 677 | $ ls 678 | 173287 tclm.zqt 679 | $ cd .. 680 | $ cd .. 681 | $ cd nzbdsvt 682 | $ ls 683 | 89301 ttbswbhs.ffs 684 | $ cd .. 685 | $ cd .. 686 | $ cd .. 687 | $ cd qzzfvdh 688 | $ ls 689 | 102585 dgpfcftj.fbr 690 | dir nzwbc 691 | dir rrrj 692 | dir tzjthwc 693 | dir vgnlftjr 694 | dir vjqzf 695 | dir zhmgmmv 696 | $ cd nzwbc 697 | $ ls 698 | 252665 ffq.sjv 699 | 87232 hznrlfhh.tnz 700 | dir lfpltbmd 701 | dir lmnvgrm 702 | 223794 mjrlm 703 | dir qnfp 704 | dir wdn 705 | $ cd lfpltbmd 706 | $ ls 707 | dir dgpfcftj 708 | 59516 frtspbh 709 | $ cd dgpfcftj 710 | $ ls 711 | 264780 bplz.rdp 712 | 169819 nmwvbqlr.dpd 713 | 9212 whtcbl.zzb 714 | $ cd .. 715 | $ cd .. 716 | $ cd lmnvgrm 717 | $ ls 718 | 12367 nwc.qbd 719 | dir rrrj 720 | dir wmsl 721 | $ cd rrrj 722 | $ ls 723 | 269510 tctgzc 724 | $ cd .. 725 | $ cd wmsl 726 | $ ls 727 | 138765 bdgpp.fwd 728 | 298221 fljmgctv 729 | 90883 hwmwtln 730 | 2731 jnhrtbqs 731 | $ cd .. 732 | $ cd .. 733 | $ cd qnfp 734 | $ ls 735 | 78470 ddbcjwg.wqc 736 | dir ldq 737 | dir ljv 738 | dir nzwbc 739 | 254734 qrwct.rvp 740 | dir wmsl 741 | 95613 wmsl.wgv 742 | $ cd ldq 743 | $ ls 744 | 268677 ttbswbhs.ffs 745 | dir wmsl 746 | $ cd wmsl 747 | $ ls 748 | dir wfqbv 749 | $ cd wfqbv 750 | $ ls 751 | 268503 tgrlfscv.vbn 752 | 222733 vwlcnm.wqq 753 | $ cd .. 754 | $ cd .. 755 | $ cd .. 756 | $ cd ljv 757 | $ ls 758 | 184758 gjddvvbs.zjq 759 | 278919 mjrlm 760 | 241428 nzwbc.fsf 761 | dir wdfwp 762 | $ cd wdfwp 763 | $ ls 764 | 100960 jnhpmp 765 | 204739 sfhjbnq.jpr 766 | 110857 twrzzn.tpm 767 | $ cd .. 768 | $ cd .. 769 | $ cd nzwbc 770 | $ ls 771 | 171647 glrd 772 | $ cd .. 773 | $ cd wmsl 774 | $ ls 775 | 39475 frptpcd.cbf 776 | dir mnd 777 | 258387 tzjthwc 778 | $ cd mnd 779 | $ ls 780 | dir wmsl 781 | $ cd wmsl 782 | $ ls 783 | dir rrrj 784 | $ cd rrrj 785 | $ ls 786 | 124041 rmrqhf 787 | $ cd .. 788 | $ cd .. 789 | $ cd .. 790 | $ cd .. 791 | $ cd .. 792 | $ cd wdn 793 | $ ls 794 | 220196 gpp.qdd 795 | 71184 jsjcvvmd.mdc 796 | 228140 rrrj.cqm 797 | $ cd .. 798 | $ cd .. 799 | $ cd rrrj 800 | $ ls 801 | 165549 qgd.pgt 802 | 206913 rrrj.whw 803 | 56087 ttbswbhs.ffs 804 | $ cd .. 805 | $ cd tzjthwc 806 | $ ls 807 | dir cjrtl 808 | dir cmqzqrc 809 | dir dgpfcftj 810 | dir gmlgztg 811 | 16349 hgjnnw.nwp 812 | dir qflmtrgh 813 | dir snjv 814 | 118210 ttbswbhs.ffs 815 | dir vsq 816 | 211036 zsflzpg 817 | $ cd cjrtl 818 | $ ls 819 | 157605 frfb.flq 820 | 182254 gqtprzlg 821 | dir lldcwcf 822 | 86395 ttbswbhs.ffs 823 | dir wmsl 824 | $ cd lldcwcf 825 | $ ls 826 | 279487 bplz.rdp 827 | 229071 djzs 828 | $ cd .. 829 | $ cd wmsl 830 | $ ls 831 | dir dnfztwvj 832 | $ cd dnfztwvj 833 | $ ls 834 | 211224 hznrlfhh.tnz 835 | $ cd .. 836 | $ cd .. 837 | $ cd .. 838 | $ cd cmqzqrc 839 | $ ls 840 | dir bsfqcv 841 | dir dgpfcftj 842 | dir nzwbc 843 | $ cd bsfqcv 844 | $ ls 845 | 62520 ltzblpc 846 | $ cd .. 847 | $ cd dgpfcftj 848 | $ ls 849 | 144915 bdv.snn 850 | 170427 rrrj.qfg 851 | 287416 tzjthwc 852 | $ cd .. 853 | $ cd nzwbc 854 | $ ls 855 | 223973 zvssq.lch 856 | $ cd .. 857 | $ cd .. 858 | $ cd dgpfcftj 859 | $ ls 860 | dir pzfnlzbj 861 | $ cd pzfnlzbj 862 | $ ls 863 | 190720 dgpfcftj.ffm 864 | $ cd .. 865 | $ cd .. 866 | $ cd gmlgztg 867 | $ ls 868 | 234781 bplz.rdp 869 | 29314 nzwbc.mgl 870 | 86928 qqb.qmd 871 | 262374 rrrj.qlm 872 | $ cd .. 873 | $ cd qflmtrgh 874 | $ ls 875 | dir rrrj 876 | dir wrm 877 | $ cd rrrj 878 | $ ls 879 | dir wftzbw 880 | $ cd wftzbw 881 | $ ls 882 | dir chzs 883 | $ cd chzs 884 | $ ls 885 | dir dfhzcft 886 | $ cd dfhzcft 887 | $ ls 888 | 93504 mjrlm 889 | $ cd .. 890 | $ cd .. 891 | $ cd .. 892 | $ cd .. 893 | $ cd wrm 894 | $ ls 895 | 13708 jzgqvthh 896 | 138652 mlwflb 897 | 145161 szfzs.clj 898 | 297793 ttbswbhs.ffs 899 | $ cd .. 900 | $ cd .. 901 | $ cd snjv 902 | $ ls 903 | dir grq 904 | 92025 nzwbc 905 | dir rrrj 906 | dir wmsl 907 | $ cd grq 908 | $ ls 909 | 189188 jzccjh.lsl 910 | dir nzwbc 911 | 97611 pngngj 912 | dir tzjthwc 913 | dir wjcjqc 914 | $ cd nzwbc 915 | $ ls 916 | 12818 vzc 917 | $ cd .. 918 | $ cd tzjthwc 919 | $ ls 920 | dir cfwvmwr 921 | 54762 dgpfcftj 922 | 179432 gbt.whg 923 | dir njsfv 924 | 220002 whr.jqn 925 | $ cd cfwvmwr 926 | $ ls 927 | 227691 pfgmbsjd 928 | $ cd .. 929 | $ cd njsfv 930 | $ ls 931 | 39114 fpjqqcsp.czm 932 | 289813 mjrlm 933 | 279549 qqb.qmd 934 | $ cd .. 935 | $ cd .. 936 | $ cd wjcjqc 937 | $ ls 938 | 258155 ttbswbhs.ffs 939 | $ cd .. 940 | $ cd .. 941 | $ cd rrrj 942 | $ ls 943 | 277036 bdgws 944 | dir dgpfcftj 945 | 269322 dgpfcftj.zgt 946 | dir fsqdnl 947 | 33872 qqb.qmd 948 | $ cd dgpfcftj 949 | $ ls 950 | 172038 mzjmmddr.fnl 951 | $ cd .. 952 | $ cd fsqdnl 953 | $ ls 954 | 250732 zczcgq.lbb 955 | $ cd .. 956 | $ cd .. 957 | $ cd wmsl 958 | $ ls 959 | 84076 nzwbc.pmp 960 | 196119 rrrj.gph 961 | 104986 ttbswbhs.ffs 962 | dir zmvrrdps 963 | $ cd zmvrrdps 964 | $ ls 965 | 170723 wmsl.mpg 966 | $ cd .. 967 | $ cd .. 968 | $ cd .. 969 | $ cd vsq 970 | $ ls 971 | 136431 hznrlfhh.tnz 972 | 195767 mrrc.tst 973 | $ cd .. 974 | $ cd .. 975 | $ cd vgnlftjr 976 | $ ls 977 | 29769 mjrlm 978 | 53024 wmsl.nhr 979 | 123863 wps.hhq 980 | $ cd .. 981 | $ cd vjqzf 982 | $ ls 983 | dir dgpfcftj 984 | dir gnnstzc 985 | 45701 lgrst.fhc 986 | 265249 spdrmtbd.pnd 987 | 182349 ttbswbhs.ffs 988 | $ cd dgpfcftj 989 | $ ls 990 | 47874 mvlb.gbn 991 | $ cd .. 992 | $ cd gnnstzc 993 | $ ls 994 | 105525 lbqh.pst 995 | 13456 rrrj.hlm 996 | 62170 vll.cft 997 | $ cd .. 998 | $ cd .. 999 | $ cd zhmgmmv 1000 | $ ls 1001 | dir fvwm 1002 | 165656 qtjnmzrd.grm 1003 | $ cd fvwm 1004 | $ ls 1005 | dir dgpfcftj 1006 | $ cd dgpfcftj 1007 | $ ls 1008 | 214069 qqb.qmd 1009 | $ cd .. 1010 | $ cd .. 1011 | $ cd .. 1012 | $ cd .. 1013 | $ cd smvhphf 1014 | $ ls 1015 | 202817 dvtblw.wsr 1016 | -------------------------------------------------------------------------------- /day07-mips/main.S: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MAX_DEPTH 64 6 | #define PART1_TARGET_SIZE 100000 7 | #define PART2_NEEDED_SIZE (70000000 - 30000000) 8 | 9 | .section .text 10 | 11 | .balign 4 12 | .global __start 13 | __start: 14 | 15 | .set noreorder 16 | 17 | lw s0, 8(sp) // argv[1] (sp+0 is argc) 18 | 19 | addi a0, zero, 1 // stdout 20 | lui a1, %hi(hello_world_string) 21 | ori a1, a1, %lo(hello_world_string) 22 | addi a2, zero, (hello_world_end - hello_world_string) 23 | addi v0, zero, __NR_write 24 | syscall 25 | 26 | add s4, zero, zero // Will be set to non-zero when it's time for part 2; stores minimum needed size 27 | do_it_again: 28 | lui s3, %hi(dir_sizes) 29 | ori s3, s3, %lo(dir_sizes) 30 | add s1, zero, zero // Part 1 sum 31 | addi s2, zero, -1 // Tracks smallest found size for part 2 32 | srl s2, s2, 1 // Set to signed max 33 | main_loop: 34 | lb t0, 0(s0) 35 | beq t0, zero, main_break 36 | addi t0, -'\n' 37 | beq t0, zero, main_break 38 | nop 39 | lb t1, 2(s0) 40 | jal skip_line 41 | lb t2, 5(s0) 42 | addi t1, t1, -'c' 43 | beq t1, zero, cd_cmd 44 | nop 45 | ls_loop: 46 | lb t0, 0(s0) 47 | addi t0, t0, -'d' 48 | beq t0, zero, dir_entry 49 | nop 50 | jal atoi 51 | add t2, zero, s0 52 | beq s0, t2, main_loop 53 | nop 54 | lw t0, 0(s3) 55 | add t0, t0, v0 56 | sw t0, 0(s3) 57 | dir_entry: 58 | jal skip_line 59 | nop 60 | j ls_loop 61 | nop 62 | cd_cmd: 63 | addi t2, t2, -'.' 64 | beq t2, zero, cd_dotdot 65 | nop 66 | addi s3, s3, 4 67 | j main_loop 68 | sw zero, 0(s3) 69 | cd_dotdot: 70 | addi s3, s3, -4 71 | lw t0, 4(s3) 72 | lw t2, 0(s3) 73 | lui t1, (PART1_TARGET_SIZE >> 16) 74 | ori t1, t1, (PART1_TARGET_SIZE & 0xFFFF) 75 | sub t1, t0, t1 76 | beq s4, zero, not_part2_dotdot 77 | nop 78 | sub t4, t0, s4 79 | bltz t4, not_part2_dotdot 80 | sub t4, s2, t0 81 | blez t4, not_part2_dotdot 82 | nop 83 | add s2, zero, t0 84 | not_part2_dotdot: 85 | add t2, t0, t2 86 | bgtz t1, main_loop 87 | sw t2, 0(s3) 88 | j main_loop 89 | add s1, s1, t0 90 | main_break: 91 | 92 | lui t8, %hi(dir_sizes) 93 | ori t8, t8, %lo(dir_sizes) 94 | finish_loop: 95 | beq s3, t8, finish_break 96 | nop 97 | addi s3, s3, -4 98 | lw t0, 4(s3) 99 | lw t2, 0(s3) 100 | lui t1, (PART1_TARGET_SIZE >> 16) 101 | ori t1, t1, (PART1_TARGET_SIZE & 0xFFFF) 102 | sub t1, t0, t1 103 | beq s4, zero, not_part2_finish 104 | nop 105 | sub t4, t0, s4 106 | bltz t4, not_part2_finish 107 | sub t4, s2, t0 108 | blez t4, not_part2_finish 109 | nop 110 | add s2, zero, t0 111 | not_part2_finish: 112 | add t2, t0, t2 113 | bgtz t1, finish_loop 114 | sw t2, 0(s3) 115 | j finish_loop 116 | add s1, s1, t0 117 | finish_break: 118 | 119 | bne s4, zero, part2_done 120 | nop 121 | lw s4, 0(s3) 122 | lui t0, (PART2_NEEDED_SIZE >> 16) 123 | ori t0, t0, (PART2_NEEDED_SIZE & 0xFFFF) 124 | sub s4, s4, t0 125 | j do_it_again 126 | lw s0, 8(sp) 127 | part2_done: 128 | 129 | addi a0, zero, 1 // stdout 130 | lui a1, %hi(part1_string) 131 | ori a1, a1, %lo(part1_string) 132 | addi a2, zero, (part1_end - part1_string) 133 | addi v0, zero, __NR_write 134 | syscall 135 | 136 | add a0, zero, s1 137 | lui a1, %hi(str_buf_end) 138 | jal itoa 139 | ori a1, a1, %lo(str_buf_end) 140 | 141 | addi a0, zero, 1 142 | add a2, zero, v0 143 | addi v0, zero, __NR_write 144 | syscall 145 | 146 | lui a1, %hi(part2_string) 147 | ori a1, a1, %lo(part2_string) 148 | addi a2, zero, (part2_end - part2_string) 149 | addi v0, zero, __NR_write 150 | syscall 151 | 152 | add a0, zero, s2 153 | lui a1, %hi(str_buf_end) 154 | jal itoa 155 | ori a1, a1, %lo(str_buf_end) 156 | 157 | addi a0, zero, 1 158 | add a2, zero, v0 159 | addi v0, zero, __NR_write 160 | syscall 161 | 162 | lui a1, %hi(newline) 163 | ori a1, a1, %lo(newline) 164 | addi a2, zero, 1 165 | addi v0, zero, __NR_write 166 | syscall 167 | 168 | .align 4 169 | quit: 170 | addi a0, zero, 0 171 | addi v0, zero, __NR_exit 172 | syscall 173 | 174 | j quit 175 | nop 176 | 177 | 178 | // Advances s0 past the next newline, clobbers t0 179 | skip_line: 180 | lb t0, 0(s0) 181 | beq t0, zero, skip_line_break 182 | addi t0, t0, -'\n' 183 | bne t0, zero, skip_line 184 | skip_line_break: 185 | addi s0, s0, 1 186 | jr ra 187 | nop 188 | 189 | 190 | // Does not follow ABI; input ptr in s0, returns in v0, advances s0 to first non-decimal found, clobbers t0, t1 191 | atoi: 192 | add v0, zero, zero 193 | atoi_loop: 194 | lb t0, 0(s0) 195 | addi t1, t0, -'9' 196 | bgtz t1, atoi_break 197 | addi t1, t0, -'0' 198 | bltz t1, atoi_break 199 | addi t0, zero, 10 200 | mult t0, v0 201 | mflo v0 202 | add v0, v0, t1 203 | j atoi_loop 204 | addi s0, s0, 1 205 | atoi_break: 206 | jr ra 207 | nop 208 | 209 | // Number in a0, end of an out buf in a1, returns length in v0 and mutates a1 to point to the start of what was written to the buf, clobbers t0 210 | itoa: 211 | add v0, zero, zero 212 | itoa_loop: 213 | addi a1, a1, -1 214 | addi v0, v0, 1 215 | addi t0, zero, 10 216 | div a0, t0 217 | mflo a0 218 | mfhi t0 219 | addi t0, t0, '0' 220 | bne a0, zero, itoa_loop 221 | sb t0, 0(a1) 222 | jr ra 223 | nop 224 | 225 | // Stops on first null or newline; clobbers t0, t1, t2 226 | hash_str: 227 | add v0, zero, zero 228 | add t2, zero, zero 229 | hash_loop: 230 | lb t0, 0(a0) 231 | beq t0, zero, hash_break 232 | addi t1, t0, -'\n' 233 | beq t1, zero, hash_break 234 | sllv t0, t0, t2 // t2 will be 8 or 0 235 | xor v0, v0, t0 236 | xori t2, t2, 8 // switch t2 237 | j hash_loop 238 | addi a0, a0, 1 239 | hash_break: 240 | jr ra 241 | nop 242 | /* 243 | // clobbers t0, t1, t2 244 | hash_table_set_bit: 245 | lui t1, %hi(hash_table) 246 | ori t1, t1, %lo(hash_table) 247 | srl t0, a0, 3 248 | add t0, t1, t0 249 | lb t2, 0(t0) 250 | andi a0, a0, 7 251 | addi t1, zero, 1 252 | sllv t1, t1, a0 253 | or t2, t2, t1 254 | jr ra 255 | sb t2, 0(t0) 256 | 257 | // clobbers t0, t1, t2 258 | hash_table_get_bit: 259 | lui t1, %hi(hash_table) 260 | ori t1, t1, %lo(hash_table) 261 | srl t0, a0, 3 262 | add t0, t1, t0 263 | lb t2, 0(t0) 264 | andi a0, a0, 7 265 | srlv t2, t2, a0 266 | jr ra 267 | andi v0, t2, 1*/ 268 | 269 | .section .bss 270 | 271 | dir_sizes: 272 | .skip MAX_DEPTH * 4 273 | cur_path: 274 | .skip MAX_DEPTH * 20 275 | str_buf: 276 | .skip 10; str_buf_end: 277 | //hash_table: 278 | // .skip (1 << (16 - 3)) 279 | 280 | .section .rodata 281 | 282 | hello_world_string: 283 | .ascii "BEEG bunny"; newline: .ascii "\n"; hello_world_end: 284 | part1_string: 285 | .ascii "Part 1: "; part1_end: 286 | part2_string: 287 | .ascii "\nPart 2: "; part2_end: 288 | -------------------------------------------------------------------------------- /day07-mips/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day07-mips/output.jpg -------------------------------------------------------------------------------- /day07-mips/sample_input.txt: -------------------------------------------------------------------------------- 1 | $ cd / 2 | $ ls 3 | dir a 4 | 14848514 b.txt 5 | 8504156 c.dat 6 | dir d 7 | $ cd a 8 | $ ls 9 | dir e 10 | 29116 f 11 | 2557 g 12 | 62596 h.lst 13 | $ cd e 14 | $ ls 15 | 584 i 16 | $ cd .. 17 | $ cd .. 18 | $ cd d 19 | $ ls 20 | 4060174 j 21 | 8033020 d.log 22 | 5626152 d.ext 23 | 7214296 k 24 | -------------------------------------------------------------------------------- /day08-teak/.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | build/ 3 | *.elf 4 | *.3dsx 5 | *.smdh -------------------------------------------------------------------------------- /day08-teak/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITARM)/3ds_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) 19 | #--------------------------------------------------------------------------------- 20 | TARGET := treetop-tree-house 21 | BUILD := build 22 | SOURCES := source 23 | DATA := data 24 | INCLUDES := include 25 | #ROMFS := romfs 26 | 27 | #--------------------------------------------------------------------------------- 28 | # options for code generation 29 | #--------------------------------------------------------------------------------- 30 | ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft 31 | 32 | CFLAGS := -g -Wall -O2 -mword-relocations \ 33 | -fomit-frame-pointer -ffunction-sections \ 34 | $(ARCH) 35 | 36 | CFLAGS += $(INCLUDE) -D__3DS__ 37 | 38 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 39 | 40 | ASFLAGS := -g $(ARCH) 41 | LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 42 | 43 | LIBS := -lctru -lm 44 | 45 | #--------------------------------------------------------------------------------- 46 | # list of directories containing libraries, this must be the top level containing 47 | # include and lib 48 | #--------------------------------------------------------------------------------- 49 | LIBDIRS := $(CTRULIB) 50 | 51 | 52 | ifneq ($(BUILD),$(notdir $(CURDIR))) 53 | #--------------------------------------------------------------------------------- 54 | 55 | export OUTPUT := $(CURDIR)/$(TARGET) 56 | export TOPDIR := $(CURDIR) 57 | 58 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 59 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 60 | 61 | export DEPSDIR := $(CURDIR)/$(BUILD) 62 | 63 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 64 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 65 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 66 | PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) 67 | SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) 68 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) cdc.bin 69 | 70 | #--------------------------------------------------------------------------------- 71 | # use CXX for linking C++ projects, CC for standard C 72 | #--------------------------------------------------------------------------------- 73 | ifeq ($(strip $(CPPFILES)),) 74 | #--------------------------------------------------------------------------------- 75 | export LD := $(CC) 76 | #--------------------------------------------------------------------------------- 77 | else 78 | #--------------------------------------------------------------------------------- 79 | export LD := $(CXX) 80 | #--------------------------------------------------------------------------------- 81 | endif 82 | #--------------------------------------------------------------------------------- 83 | 84 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 85 | $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ 86 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 87 | 88 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 89 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 90 | -I$(CURDIR)/$(BUILD) 91 | 92 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 93 | 94 | .PHONY: $(BUILD) clean all 95 | 96 | #--------------------------------------------------------------------------------- 97 | all: $(BUILD) 98 | 99 | $(BUILD): 100 | @[ -d $@ ] || mkdir -p $@ 101 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 102 | 103 | #--------------------------------------------------------------------------------- 104 | clean: 105 | @echo clean ... 106 | @rm -fr $(BUILD) $(TARGET).cxi $(TARGET).cia $(TARGET).elf $(TARGET).3dsx $(TARGET).smdh 107 | 108 | 109 | #--------------------------------------------------------------------------------- 110 | else 111 | 112 | DEPENDS := $(OFILES:.o=.d) 113 | 114 | #--------------------------------------------------------------------------------- 115 | # main targets 116 | #--------------------------------------------------------------------------------- 117 | all: $(OUTPUT).3dsx 118 | 119 | ifeq ($(strip $(NO_SMDH)),) 120 | $(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh 121 | else 122 | $(OUTPUT).3dsx : $(OUTPUT).elf 123 | endif 124 | 125 | $(OUTPUT).elf : $(OFILES) 126 | 127 | #--------------------------------------------------------------------------------- 128 | # you need a rule like this for each extension you use as binary data 129 | #--------------------------------------------------------------------------------- 130 | %.bin.o : %.bin 131 | #--------------------------------------------------------------------------------- 132 | @echo $(notdir $<) 133 | @$(bin2o) 134 | 135 | #--------------------------------------------------------------------------------- 136 | # rules for assembling GPU shaders 137 | #--------------------------------------------------------------------------------- 138 | define shader-as 139 | $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) 140 | picasso -o $(CURBIN) $1 141 | bin2s $(CURBIN) | $(AS) -o $@ 142 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h 143 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h 144 | echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h 145 | endef 146 | 147 | %.shbin.o : %.v.pica %.g.pica 148 | @echo $(notdir $^) 149 | @$(call shader-as,$^) 150 | 151 | %.shbin.o : %.v.pica 152 | @echo $(notdir $<) 153 | @$(call shader-as,$<) 154 | 155 | %.shbin.o : %.shlist 156 | @echo $(notdir $<) 157 | @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) 158 | 159 | cdc.bin: ../firm/source 160 | makedsp1 $< $@ 161 | 162 | -include $(DEPENDS) 163 | 164 | #--------------------------------------------------------------------------------------- 165 | endif 166 | #--------------------------------------------------------------------------------------- 167 | -------------------------------------------------------------------------------- /day08-teak/README.md: -------------------------------------------------------------------------------- 1 | Day 8 was run on an XpertTeak, the DSP chip used in the various models of the Nintendo 3DS. [teakra](https://github.com/wwylele/teakra) was used to assemble the solution code, and the 3dsx code in the `hwtest` folder of the teakra repo was used as a base for uploading code to the DSP. Solutions were obtained by running on my trusty New 2DS XL: [output.jpg](output.jpg). 2 | -------------------------------------------------------------------------------- /day08-teak/firm/source: -------------------------------------------------------------------------------- 1 | segment p 0000 2 | br 0x0000$0800 always// reset vector 3 | br 0x0000$3000 always 4 | br 0x0000$3000 always 5 | br 0x0000$3000 always // int0 6 | data 0000 7 | data 0000 8 | data 0000 9 | data 0000 10 | data 0000 11 | data 0000 12 | br 0x0000$3000 always // int1 13 | data 0000 14 | data 0000 15 | data 0000 16 | data 0000 17 | data 0000 18 | data 0000 19 | br 0x0000$3000 always // int2 20 | 21 | segment p 0800 22 | load 0x0080u8 page // pre-write shutdown sequence 23 | clr b0 always 24 | mov b0l [page:0x00c8u8] // T_REPLY2 25 | 26 | load 0x0000u8 page 27 | // wait for ARM11 to say go 28 | mov [page:0x0000u8] r0 29 | cmpv 0x$FFFF r0 30 | brr 0xfffc neq 31 | 32 | // Say hello :) 33 | mov 0x$6968 r0 // "hi" 34 | mov r0 [page:0x0001u8] 35 | mov r0 [page:0x0002u8] 36 | mov 0x$3A20 r0 // " :" 37 | mov r0 [page:0x0003u8] 38 | mov 0x$0044 r0 // "D\0" 39 | mov r0 [page:0x0004u8] 40 | 41 | // First, find length of one line of input (look for newline) 42 | mov 0x$0000 r7 43 | addv 0x$0001 r7 44 | mov 0x$0000 y0 45 | mov r7 r0 46 | call 0x0000$1000 always 47 | cmpv 0x$000A r0 // '\n' 48 | brr 0xfff6 neq // to "addv 0x$0001 r7" 49 | 50 | mov 0x$0000 r4 // counter of visible trees (part 1) 51 | mov r4 [page:0x0012u8] // part 2 highest value; 2 words because it gets that big 52 | mov r4 [page:0x0013u8] 53 | br 0x0000$0900 always 54 | 55 | segment p 0900 56 | mov 0x$0000 r6 // y 57 | mov 0x$0000 r5 // x 58 | // For each coordinate (inner and outer loop) 59 | mov 0x$0000 r0 60 | mov r0 [page:0x0020u8] // Flag to track if this tree is visible 61 | clr b1 always 62 | mov r5 r0 63 | mov r6 y0 64 | call 0x0000$1000 always 65 | mov r0 a1 66 | 67 | // 4 loops - go in each direction and check for visibility 68 | 69 | // -x 70 | mov r5 r3 71 | subv 0x$0001 r3 72 | brr 0x0004 ge // to "swap a0<->b1"; skip flag set block, don't break 73 | mov 0x$0001 r0 74 | mov r0 [page:0x0020u8] 75 | brr 0x0009 always // break this loop 76 | swap a0<->b1 77 | add 0x0001u8 a0 78 | swap a0<->b1 79 | mov r3 r0 80 | mov r6 y0 81 | call 0x0000$1000 always 82 | cmp r0 a1 83 | brr 0xfff0 gt // to "subv 0x$0001 r3" 84 | 85 | push b1l 86 | pop y1 87 | clr b1 always 88 | 89 | // +x 90 | mov r5 r3 91 | addv 0x$0001 r3 92 | mov r7 a0 93 | cmp r3 a0 94 | brr 0x0004 neq // to "swap a0<->b1"; skip flag set block, don't break 95 | mov 0x$0001 r0 96 | mov r0 [page:0x0020u8] 97 | brr 0x0009 always // break this loop 98 | swap a0<->b1 99 | add 0x0001u8 a0 100 | swap a0<->b1 101 | mov r3 r0 102 | mov r6 y0 103 | call 0x0000$1000 always 104 | cmp r0 a1 105 | brr 0xffee gt // to "addv 0x$0001 r3" 106 | 107 | swap a0<->b1 108 | push y1 109 | pop y0 110 | push a1 111 | clr a1 always 112 | mpy y0 a0l a1 113 | pop a1 114 | clr b0 always 115 | add p0 b0 116 | mov b0l y1 117 | clr b1 always 118 | 119 | // -y 120 | mov r6 r3 121 | subv 0x$0001 r3 122 | brr 0x0004 ge // to "swap a0<->b1"; skip flag set block, don't break 123 | mov 0x$0001 r0 124 | mov r0 [page:0x0020u8] 125 | brr 0x0009 always // break this loop 126 | swap a0<->b1 127 | add 0x0001u8 a0 128 | swap a0<->b1 129 | mov r5 r0 130 | mov r3 y0 131 | call 0x0000$1000 always 132 | cmp r0 a1 133 | brr 0xfff0 gt // to "subv 0x$0001 r3" 134 | 135 | swap a0<->b1 136 | push y1 137 | pop y0 138 | push a1 139 | clr a1 always 140 | mpy y0 a0l a1 141 | pop a1 142 | clr b0 always 143 | add p0 b0 144 | mov b0l y1 145 | clr b1 always 146 | 147 | // +y 148 | mov r6 r3 149 | addv 0x$0001 r3 150 | mov r7 a0 151 | cmp r3 a0 152 | brr 0x0004 neq // to "swap a0<->b1"; skip flag set block, don't break 153 | mov 0x$0001 r0 154 | mov r0 [page:0x0020u8] 155 | brr 0x0009 always // break this loop 156 | swap a0<->b1 157 | add 0x0001u8 a0 158 | swap a0<->b1 159 | mov r5 r0 160 | mov r3 y0 161 | call 0x0000$1000 always 162 | cmp r0 a1 163 | brr 0xffee gt // to "addv 0x$0001 r3" 164 | 165 | // The mpy instruction was coughing up garbage with results that didn't fit in 16 bits, so do this one manually 166 | swap a1<->b1 167 | push y1 168 | clr b0 always 169 | pop b0l 170 | dec a1 always 171 | clr b0 lt 172 | clr a0 always 173 | rep a1l 174 | add b0 a0 175 | 176 | // Check if this is the new highest scenic score 177 | // cmp a0, a1 does not seem to behave correctly, so compare high and low manually 178 | mov [page:0x0013u8] a1 179 | mov a1h [page:0x0018u8] 180 | cmp a0h a1 181 | brr 0x0006 gt 182 | brr 0x0003 lt 183 | mov [page:0x0012u8] a1 184 | cmp a0l a1 185 | brr 0x0002 ge 186 | mov a0h [page:0x0013u8] 187 | mov a0l [page:0x0012u8] 188 | 189 | // Check visibility flag for part 1 190 | mov [page:0x0020u8] r0 191 | cmpv 0x$0000 r0 192 | brr 0x0002 eq 193 | addv 0x$0001 r4 194 | 195 | // Inner loop check 196 | addv 0x$0001 r5 197 | mov r7 a0 198 | cmp r5 a0 199 | br 0x0000$0904 neq // to "mov 0x$0000 r0"; repeat inner loop 200 | 201 | // Outer loop check 202 | addv 0x$0001 r6 203 | mov r7 a0 204 | cmp r6 a0 205 | br 0x0000$0902 neq // to "mov 0x$0000 r5"; repeat outer loop 206 | 207 | // Give results for part 1 back to ARM11 (part 2 is already in memory) 208 | mov r4 [page:0x0010u8] 209 | br 0x0000$0f00 always 210 | 211 | segment p 0F00 212 | // Tell ARM11 we're done, then loop forever 213 | load 0x0000u8 page 214 | mov 0x$0000 r0 215 | mov r0 [page:0x0000u8] 216 | brr 0xffff always 217 | 218 | 219 | // read char from input; x in r0, y in y0; returns in r0; clobbers x0, r1, a0, b0, p0 220 | segment p 1000 221 | mov r7 b0 222 | addv 0x$0001 b0l 223 | mpy y0 b0l a0 224 | clr b0 always 225 | add p0 b0 226 | mov r0 a0 227 | add b0 a0 228 | mov a0l r0 229 | shr a0 always 230 | mov a0l r1 231 | addv 0x$1000 r1 232 | mov [r1] r1 233 | mov r0 a0 234 | and 0x$0001 a0 235 | brr 0x0004 neq // to "mov r1 a0" 236 | mov r1 a0 237 | and 0x$00FF a0 238 | brr 0x0003 always // to "mov a0l r0" 239 | mov r1 a0 240 | shr4 a0 always 241 | shr4 a0 always 242 | mov a0l r0 243 | ret always -------------------------------------------------------------------------------- /day08-teak/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day08-teak/output.jpg -------------------------------------------------------------------------------- /day08-teak/source/input.c: -------------------------------------------------------------------------------- 1 | //const char input[] = "30373\n25512\n65332\n33549\n35390\n"; 2 | const char input[] = "201111211202111301212201403141040230323033312212134523125000140404300230341330300221220012110101011\n011220103113221111202122124010033421404432343233535151335133353340034134034332440001110102010010220\n122121120300202230411332402004044235424325455343231124521355323541403402031010313440121321321322221\n200021211323122312440342411331012332252341254144425451345233324423152201041200212200331121111210011\n022213121203213301221100041021415245132424534145512125411151335224315551123141404223410032032000022\n101131310332214402243114310442325141344331525541232153453225442351235123130234413214313330121121101\n101102011001014411302320032155533351421345311554341111544153414344211242545240114004311012303003230\n101023122212322231421422241433315213542415532226334465642351151321144451152132311230002433230001110\n101102012000130221414322332331245251153242654525425363234533655232423135443124134230202313201000123\n113023100223214000232555442143243135556634652423636245645335623323351235221252344243002420033131123\n021023012400222133115232154155255455226363244263663662564362455342612241224452135301204334403311211\n011011120014313211333124154235235522553465256455435352362343343356452125515224121432404101240133203\n011310103034221123212123555245622666563625344356454344325522453265262433154414231333142413311331323\n303301320412010454251154421242542562366466364652264364325544554624545256254413534434331434344310311\n211332131030004243315521542363644424356453643345544752562524552255353324654134525543231434112230100\n002102403432244535421254566353326346446265345654366646566543552562536326635315453214125414141214102\n331140031313041444123423526426422252527375577546753455777737547626364645566461554234123523430311313\n330401323101512253253516526653653542734767336644345445665364743533364355534236521342413154132413122\n330411204212311445244535522655343573747374364345564574375763553465534526662642244443311121403103124\n023332003431144254543626226245566455744465356337347475347374637637653442626233624414255134423423042\n244210400021232153266652252325756653575474576355747475663555354556777566436342344532415443212134234\n243022342335541213565253544236755753776564447733743446775775654547533666422423326624134345443023202\n400214112533143341263455565263566576767643378645664845674353474533736575624522664521123334133420203\n314412035353435253634446462463763443376476847467648547566465453356757464475343435464134531133123324\n210413325433315134452365563547564744658868746684566644877466576346553654766362254362221413424430422\n440400434542543525543663633667763537556667668747746756785587458767563547637623326226661151144334010\n203031334152125642466635547657766584664687848767577545486757587488654373354446324524564152231113112\n241001452244343336664255646743677756848545865758665674685886656454447657464556245442364333553250131\n014023224515325454455574567445744885857785756585855854887668646555746475564455722536445351532451133\n240034522142434662453346666663547675448567854897757695674874464454475574464737776424553231541143102\n202432344512662423437374345345446848546655697769865799957684557848684543374647545532223321334341333\n123325111441445225523673536445447568774877677796777678697975965546774547536673437544656344512135444\n310254211535525232233446556788846647746897588857688579889788855477655648566666635426236522424112342\n034313254213653456477557533774786647669769587699976668986696667747555648883667447465462526444143342\n143141533334542466354344755484874754698685556789559989587957999587645467546553365742323424612353420\n023355513126235334753777564744657489776767789956675687857787669856547584455737646446352333233414322\n223531421366552557666573477756875578695968796778976887859959556598778688876655735777332545512434212\n324553233365452565557437476777687565788999986896686778796755558896856684686773556344634525262453452\n213242455253625376773454787557859959899988899999978889797885876979769647857487767764545335245255213\n153212131552226337374543645684765767796896876966989866686867979876788867784675754744525622655431425\n043231154325334367553646774578457959887979898666866967789799775569887978674668454463732263426513135\n335542344226645477333775676444769565755967887779666696689698896656597875884556557743462633443124152\n335323556552426765767775874764689686976988996666779796996969887796587577847457535454643262525413534\n031342356243536356663654658854697858887697788666879779897996867856867654685767655656766443625531132\n335345116666525747477647458845785958767699688899778878776776988777668657478884857465753336533142152\n431315146645532647447566887678656986686996889897797878877768979656986556466744563333546332255135135\n345455244545432335674458658587555587989897879999798888988976986779787768754855836367363664566413353\n512151454564534653477764765466595799679979878789789879998767887865797755765458674344355656253343334\n223351266325633575663774564489796879687898688978997788798999779796767956656764647364636656442223522\n453333263535357446366584455459557799968998879988898977978787696768578657875454473547567326532334111\n522431356454444356554374544846975859978878977879979897898976787967789578746656874774547443245541214\n524451243233255555453685476745875568898798878799987879899778979895889689545784464464664644546653534\n351343243662255667567757864679695778779676778997998897779866887675677768667848643753754363345434313\n422125253344236737334386654576687898997799677887987777887686867895579866465457665345774366464351334\n421312154235324535653777678786976887577869769887898799897698686878966689468464555357752255363554413\n134231353356532647544747466746997955968966989988799777786898667996595997676454734577542423644111423\n254152156456563434474788846574786769698798686897989989968667786695865858667776755455566654264132134\n325554124554345334573567875686789766777879789968978788797868997657598864755765764646452636426312235\n054421142246245654657458647846877765696688798786967788769769989568865887586878654537663362654432212\n313445116364256444775744655676857696698998799776867668888686999587568854476648764345346236246232241\n143114554233652245375455887678668996669686996999796887877777686757966588885786556444465552442533324\n251331534446564265464364486744686986675876988887767766688896987878765756544754746565355566534235144\n043312335432626344536643484678579666899596766779666899678676979556965588747766665377565544465543531\n242445211324566636637644588748444588767957766968968978786788586989657745475556775355542555362121442\n243253334442556446446767754567476657566957796656988796979699968699856846446535677455225423345132114\n431231245536522344674653635685865849787997986689665576586668667768645854645567336572252526524445114\n431352413545636624334373564776844687557987796967657766857786797968874766656443453336264564435235253\n320554134146445446354475753477858558775599755977987865757897668588588666485457344365453335234122310\n333244132156433233245637373688448784459857795676588655998585696485786865554473364636554335355224153\n113345451542245623453737457745456844757575897756758966757557585554868888643374344325656234154414322\n444045515145356432335647545655765786587886758778866688968984877775888576477747477332355221552413204\n111132223523345626324747765577376687656748476986565687576768448558884573773436752362454612221523223\n022004333435234546566255554533348546676766478456868467444674448586545655467537436553554433123421120\n333231125332152663266433667535537778555667876464765456758647764446877656465367323254523253352510413\n122420553331452433333353464676537646864677748867574756565588454444657764464332235454635225432522004\n120442052444321222226423365375645435468656658447866466574856466886677654746522644365264535531343440\n421404315233111265423463525657764565658784687768567656464684688763534555373553346542234345145442244\n331231242152133344456244633655545655745345664668565885467456447677744435752654334432232553354400240\n203040023155425242246555225235473556554656638646764676455766756555576576336522336454124215215404311\n020211430251454452662234222644467675755747776474545447746753537773655567623542436262213453434423110\n121222320253353333233652252225333343646436546477634345533376676557363636362664225322253234514301234\n131331122021145511555626563643364773337345554777664437674344775376757362452454652245212143131222333\n333033033132243135213222343542265476344656453763774355443644566737723253264252451243142121312244244\n002204430244435144434515354453332632665637375363445456667774576662453443646454532431524140202312242\n121314024424022223215424644426642356264655357667436346735353466356245254264535315425323522230030301\n021012030013043135124451434556465446663353754754774574457663344656553456246613524313152023413220330\n323211122442404125421353336334324324563564625653556556652432462453235325362525324531133444231304313\n221212242244240214314234323556334553353656452662622464552256465443444565421332134313540102100220131\n003121311143322334241133533143446663652225433332652353542523664466644655215235421122322101243201202\n302132313044423014553344334444135543546462343625633335635554425246463354552555544450021401441212013\n211320002042341321404351332421424422345645623225243263532425463422453534224512413420003024103010003\n121321233203044310220544225434555523322652465244626362265436622244421244514121221412000233313302001\n033330113222134212123014455534453323452146635634333522662322621122442141151325121244124021100331010\n003211203200004004334013134312421412135211541122652523655533352215155345414442033214440410020130131\n000310132331000133341101412343222324131145425545545422415232421245514432554132410203120223330322031\n010222121001201110014203011212115523421525414334222144411533424243442552424243301203331330320011211\n202210333132013102411304342331452231412212555243242135532222244343234442033031110220213320300213112\n021110333231201113044040042034211335553321154444412432243122252145522223420412102042311030021122200\n212222233011232310420321434331332422434543133323345512355241515513414041433311311240302022331021120\n"; -------------------------------------------------------------------------------- /day08-teak/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | 5 | #include "cdc_bin.h" 6 | 7 | // set MSB to get Luma3DS mapping for all-access, strong order 8 | vu16* const dspP = (vu16*)(0x1FF00000 | (1 << 31)); 9 | vu16* const dspD = (vu16*)(0x1FF40000 | (1 << 31)); 10 | 11 | extern const char input[]; 12 | 13 | int main() { 14 | gfxInitDefault(); 15 | 16 | consoleInit(GFX_TOP, NULL); 17 | 18 | printf("Hello!\n"); 19 | 20 | 21 | 22 | Result res = dspInit(); 23 | printf("dspInit: %08lX\n", res); 24 | if (R_FAILED(res)) 25 | goto end; 26 | bool loaded = false; 27 | res = DSP_LoadComponent(cdc_bin, cdc_bin_size, 0xFF, 0xFF, &loaded); 28 | printf("DSP_LoadComponent: %08lX\n", res); 29 | if (!loaded || R_FAILED(res)) { 30 | printf("Failed to load DSP binary\n"); 31 | goto end; 32 | } 33 | 34 | strcpy((void*) (dspD + 0x1000), input); 35 | dspD[0] = 0xFFFF; 36 | printf("Waiting for the DSP to finish...\n\n"); 37 | while (dspD[0] == 0xFFFF) 38 | svcSleepThread(10 * 1000 * 1000); 39 | 40 | printf("DSP says %s\n", (char*) (dspD + 1)); 41 | printf("Part 1: %hu\n", dspD[0x10]); 42 | printf("Part 2: %lu\n", *((u32*) (dspD + 0x12))); // This one got quite large 43 | printf("debug: %hu %hu %hu %hu\n", dspD[0x18], dspD[0x19], dspD[0x1A], dspD[0x1B]); 44 | 45 | end: 46 | printf("\nPress start to exit\n"); 47 | 48 | while (aptMainLoop()) { 49 | hidScanInput(); 50 | 51 | u32 kDown = hidKeysDown(); 52 | 53 | if (kDown & KEY_START) 54 | break; 55 | 56 | // Flush and swap framebuffers 57 | gfxFlushBuffers(); 58 | gfxSwapBuffers(); 59 | 60 | // Wait for VBlank 61 | gspWaitForVBlank(); 62 | } 63 | 64 | dspExit(); 65 | gfxExit(); 66 | 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /day09-powerpc/.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | *.elf 3 | *.dol 4 | build/ -------------------------------------------------------------------------------- /day09-powerpc/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Clear the implicit built in rules 3 | #--------------------------------------------------------------------------------- 4 | .SUFFIXES: 5 | #--------------------------------------------------------------------------------- 6 | ifeq ($(strip $(DEVKITPPC)),) 7 | $(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") 8 | endif 9 | 10 | include $(DEVKITPPC)/wii_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # INCLUDES is a list of directories containing extra header files 17 | #--------------------------------------------------------------------------------- 18 | TARGET := rope-bridge 19 | BUILD := build 20 | SOURCES := source 21 | DATA := data 22 | INCLUDES := 23 | 24 | #--------------------------------------------------------------------------------- 25 | # options for code generation 26 | #--------------------------------------------------------------------------------- 27 | 28 | CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) 29 | CXXFLAGS = $(CFLAGS) 30 | 31 | LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map 32 | 33 | #--------------------------------------------------------------------------------- 34 | # any extra libraries we wish to link with the project 35 | #--------------------------------------------------------------------------------- 36 | LIBS := -lwiiuse -lbte -logc -lm 37 | 38 | #--------------------------------------------------------------------------------- 39 | # list of directories containing libraries, this must be the top level containing 40 | # include and lib 41 | #--------------------------------------------------------------------------------- 42 | LIBDIRS := 43 | 44 | #--------------------------------------------------------------------------------- 45 | # no real need to edit anything past this point unless you need to add additional 46 | # rules for different file extensions 47 | #--------------------------------------------------------------------------------- 48 | ifneq ($(BUILD),$(notdir $(CURDIR))) 49 | #--------------------------------------------------------------------------------- 50 | 51 | export OUTPUT := $(CURDIR)/$(TARGET) 52 | 53 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 54 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 55 | 56 | export DEPSDIR := $(CURDIR)/$(BUILD) 57 | 58 | #--------------------------------------------------------------------------------- 59 | # automatically build a list of object files for our project 60 | #--------------------------------------------------------------------------------- 61 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 62 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 63 | sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 64 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) 65 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 66 | 67 | #--------------------------------------------------------------------------------- 68 | # use CXX for linking C++ projects, CC for standard C 69 | #--------------------------------------------------------------------------------- 70 | ifeq ($(strip $(CPPFILES)),) 71 | export LD := $(CC) 72 | else 73 | export LD := $(CXX) 74 | endif 75 | 76 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 77 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o) 78 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 79 | 80 | export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES))) 81 | 82 | #--------------------------------------------------------------------------------- 83 | # build a list of include paths 84 | #--------------------------------------------------------------------------------- 85 | export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ 86 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 87 | -I$(CURDIR)/$(BUILD) \ 88 | -I$(LIBOGC_INC) 89 | 90 | #--------------------------------------------------------------------------------- 91 | # build a list of library paths 92 | #--------------------------------------------------------------------------------- 93 | export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 94 | 95 | export OUTPUT := $(CURDIR)/$(TARGET) 96 | .PHONY: $(BUILD) clean 97 | 98 | #--------------------------------------------------------------------------------- 99 | $(BUILD): 100 | @[ -d $@ ] || mkdir -p $@ 101 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 102 | 103 | #--------------------------------------------------------------------------------- 104 | clean: 105 | @echo clean ... 106 | @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol 107 | 108 | #--------------------------------------------------------------------------------- 109 | run: 110 | wiiload $(TARGET).dol 111 | 112 | 113 | #--------------------------------------------------------------------------------- 114 | else 115 | 116 | DEPENDS := $(OFILES:.o=.d) 117 | 118 | #--------------------------------------------------------------------------------- 119 | # main targets 120 | #--------------------------------------------------------------------------------- 121 | $(OUTPUT).dol: $(OUTPUT).elf 122 | $(OUTPUT).elf: $(OFILES) 123 | 124 | $(OFILES_SOURCES) : $(HFILES) 125 | 126 | #--------------------------------------------------------------------------------- 127 | # This rule links in binary data with the .jpg extension 128 | #--------------------------------------------------------------------------------- 129 | %.jpg.o %_jpg.h : %.jpg 130 | #--------------------------------------------------------------------------------- 131 | @echo $(notdir $<) 132 | $(bin2o) 133 | 134 | -include $(DEPENDS) 135 | 136 | #--------------------------------------------------------------------------------- 137 | endif 138 | #--------------------------------------------------------------------------------- 139 | -------------------------------------------------------------------------------- /day09-powerpc/README.md: -------------------------------------------------------------------------------- 1 | Day 9 was completed in PowerPC assembly and built into an executable for the Nintendo Wii. Part 1 was run on a real Wii, and that output is [here](output_part1.jpg). Due to some unfortunate circumstances, I no longer had access to my Wii by the time I finished part 2, so I cheated and used Dolphin to get that solution: [output_cheating.jpg](output_cheating.jpg). I have no doubts that the finished code for solving both parts would have worked fine on real hardware too. 2 | -------------------------------------------------------------------------------- /day09-powerpc/output_cheating.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day09-powerpc/output_cheating.jpg -------------------------------------------------------------------------------- /day09-powerpc/output_part1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day09-powerpc/output_part1.jpg -------------------------------------------------------------------------------- /day09-powerpc/source/input.c: -------------------------------------------------------------------------------- 1 | //const char input[] = "R 4\n"; 2 | //const char input[] = "R 4\nU 4\nL 3\nD 1\nR 4\nD 1\nL 5\nR 2\n"; 3 | //const char input[] = "R 4\nU 4\nL 3\nD 1\nR 4\nD 1\nL 5\nR 2\n"; 4 | //const char input[] = "R 5\nU 8\nL 8\nD 3\nR 17\nD 10\nL 15\nL 10\nU 10\nU 10\n"; 5 | //const char input[] = "D 10\nL 1\nU 1\nR 2\nL 1\nU 1\nL 1\nR 2\nU 1\nD 2\nL 2\nD 1\nL 1\nR 1\nL 1\nU 1\nD 1\nR 2\nL 2\nU 1\nR 2\nL 1\nR 1\nU 2\nD 1\nR 2\nL 1\nU 2\nD 1\nR 2\nL 1\nD 1\nR 1\nU 1\nR 1\nL 1\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7\nL 6\nU 13\nD 18\nU 17\nR 11\nU 19\nD 5\nL 3\nU 6\nD 3\nU 9\nR 8\nL 7\nR 16\nL 15\nD 12\nU 10\nL 16\nR 17\nU 12\nL 1\nD 5\nL 9\nU 12\nL 2\nD 18\nL 1\nR 1\nL 2\nR 2\nL 9\nU 18\nR 8\nD 8\nR 4\nL 16\nU 6\nR 11\nD 13\nR 1\nD 14\nL 6\nD 14\nR 8\nL 5\nD 6\nL 14\nU 11\nL 5\nR 8\nD 11\nL 6\nU 17\nR 15\nL 13\nU 16\nD 2\nR 8\nD 5\nL 8\nD 7\nR 5\nU 10\nL 19\nR 7\nD 16\nR 1\nL 12\nD 8\nL 8\nR 10\nL 10\nU 1\nR 10\nU 15\n"; 7 | -------------------------------------------------------------------------------- /day09-powerpc/source/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | static void *xfb = NULL; 7 | static GXRModeObj *rmode = NULL; 8 | 9 | extern const char input[]; 10 | 11 | u64 solve(const char *input); 12 | 13 | int main(int argc, char **argv) { 14 | // init stuff taken from dkp example 15 | VIDEO_Init(); 16 | WPAD_Init(); 17 | rmode = VIDEO_GetPreferredMode(NULL); 18 | xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode)); 19 | console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ); 20 | VIDEO_Configure(rmode); 21 | VIDEO_SetNextFramebuffer(xfb); 22 | VIDEO_SetBlack(FALSE); 23 | VIDEO_Flush(); 24 | VIDEO_WaitVSync(); 25 | if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync(); 26 | 27 | printf("\n\nHello world, and thanks for all the fish\n\n"); 28 | 29 | u64 ret = solve(input); 30 | printf("Part 1: %llu\n", ret >> 32); 31 | printf("Part 2: %llu\n", ret & ((1ULL << 32) - 1)); 32 | 33 | printf("\nPress home to exit\n"); 34 | 35 | while(1) { 36 | WPAD_ScanPads(); 37 | u32 pressed = WPAD_ButtonsDown(0); 38 | if ( pressed & WPAD_BUTTON_HOME ) exit(0); 39 | 40 | VIDEO_WaitVSync(); 41 | } 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /day09-powerpc/source/solve.s: -------------------------------------------------------------------------------- 1 | .section .text 2 | 3 | #define FLAGS_DIM_BITS 9 4 | #define FLAGS_DIM (1 << FLAGS_DIM_BITS) 5 | 6 | .global solve 7 | solve: 8 | //addi sp, sp, -4 9 | 10 | mr 8, 3 11 | lis 10, flags_mid@ha 12 | la 10, flags_mid@l(10) 13 | lis 11, tails_arr@ha 14 | la 11, tails_arr@l(11) 15 | 16 | main_loop: 17 | lbz 3, 0(8) 18 | cmpi 7, 0, 3, 0 19 | beq 7, main_break 20 | lbz 4, 2(8) 21 | lbz 0, 3(8) 22 | cmpi 7, 0, 0, '\n' 23 | beq 7, not_two_digit 24 | // way too tired to write a proper atoi right now, please have mercy 25 | mr 4, 0 26 | subi 4, 4, '0' 27 | addi 4, 4, 10 28 | addi 8, 8, 5 29 | b two_digit_done 30 | not_two_digit: 31 | addi 8, 8, 4 32 | subi 4, 4, '0' 33 | two_digit_done: 34 | 35 | cmpi 7, 0, 3, 'U' 36 | beq 7, is_u 37 | cmpi 7, 0, 3, 'D' 38 | beq 7, is_d 39 | cmpi 7, 0, 3, 'L' 40 | beq 7, is_l 41 | is_r: 42 | li 3, 1 43 | b dirs_done 44 | is_l: 45 | li 3, -1 46 | b dirs_done 47 | is_u: 48 | li 3, -FLAGS_DIM 49 | b dirs_done 50 | is_d: 51 | li 3, FLAGS_DIM 52 | dirs_done: 53 | 54 | inner_loop: 55 | add 10, 10, 3 56 | mr 6, 10 57 | li 12, 0 58 | tail_loop: 59 | add 9, 11, 12 60 | lwz 9, 0(9) 61 | 62 | andi. 0, 6, FLAGS_DIM - 1 63 | andi. 5, 9, FLAGS_DIM - 1 64 | sub 5, 0, 5 65 | 66 | srwi 0, 6, FLAGS_DIM_BITS 67 | srwi 7, 9, FLAGS_DIM_BITS 68 | sub 7, 0, 7 69 | 70 | cmpi 0, 0, 5, 2 71 | cmpi 1, 0, 5, -2 72 | cmpi 5, 0, 7, 2 73 | cmpi 6, 0, 7, -2 74 | 75 | // always not equal 76 | cmpi 7, 0, 11, 0 77 | 78 | beq 0, update_tail_xp2 79 | beq 1, update_tail_xm2 80 | x2_ret: 81 | beq 5, update_tail_yp2 82 | beq 6, update_tail_ym2 83 | 84 | bne 7, tail_loop_break 85 | b update_tail 86 | 87 | update_tail_xp2: 88 | subi 5, 5, 1 89 | cmp 7, 0, 5, 5 90 | b x2_ret 91 | update_tail_xm2: 92 | addi 5, 5, 1 93 | cmp 7, 0, 5, 5 94 | b x2_ret 95 | update_tail_yp2: 96 | subi 7, 7, 1 97 | b update_tail 98 | update_tail_ym2: 99 | addi 7, 7, 1 100 | 101 | update_tail: 102 | slwi 7, 7, FLAGS_DIM_BITS 103 | add 9, 9, 5 104 | add 9, 9, 7 105 | add 5, 11, 12 106 | stw 9, 0(5) 107 | mr 6, 9 108 | 109 | addi 12, 12, 4 110 | cmpi 7, 0, 12, (9*4) 111 | bne 7, tail_loop 112 | tail_loop_break: 113 | 114 | lwz 9, 0(11) 115 | lbz 0, 0(9) 116 | ori 0, 0, 1 117 | stb 0, 0(9) 118 | 119 | lwz 9, (8*4)(11) 120 | lbz 0, 0(9) 121 | ori 0, 0, 2 122 | stb 0, 0(9) 123 | 124 | subi 4, 4, 1 125 | cmpi 7, 0, 4, 0 126 | bne 7, inner_loop 127 | 128 | b main_loop 129 | main_break: 130 | 131 | lis 10, flags@ha 132 | la 10, flags@l(10) 133 | li 3, 0 134 | li 4, 0 135 | lis 5, (1 << ((FLAGS_DIM_BITS * 2) - 16)) 136 | //li 5, 0xA 137 | count_loop: 138 | lbz 0, 0(10) 139 | andi. 6, 0, 1 140 | beq 0, skip_inc_part1 141 | addi 3, 3, 1 142 | skip_inc_part1: 143 | andi. 6, 0, 2 144 | beq 0, skip_inc_part2 145 | addi 4, 4, 1 146 | skip_inc_part2: 147 | addi 10, 10, 1 148 | subi 5, 5, 1 149 | cmpi 7, 0, 5, 0 150 | bne 7, count_loop 151 | 152 | blr 153 | 154 | 155 | .section .data 156 | 157 | .balign 4 158 | tails_arr: 159 | .rept 9 160 | .long flags_mid 161 | .endr 162 | 163 | .section .bss 164 | 165 | .balign FLAGS_DIM 166 | flags: 167 | .skip (FLAGS_DIM * (FLAGS_DIM / 2)) + (FLAGS_DIM / 2), 0 168 | flags_mid: 169 | .skip (FLAGS_DIM * (FLAGS_DIM / 2)) - (FLAGS_DIM / 2), 0 -------------------------------------------------------------------------------- /day10-pica200/.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | build/ 3 | *.elf 4 | *.3dsx 5 | *.smdh -------------------------------------------------------------------------------- /day10-pica200/Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITARM)/3ds_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | # GRAPHICS is a list of directories containing graphics files 19 | # GFXBUILD is the directory where converted graphics files will be placed 20 | # If set to $(BUILD), it will statically link in the converted 21 | # files as if they were data files. 22 | # 23 | # NO_SMDH: if set to anything, no SMDH file is generated. 24 | # ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) 25 | # APP_TITLE is the name of the app stored in the SMDH file (Optional) 26 | # APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) 27 | # APP_AUTHOR is the author of the app stored in the SMDH file (Optional) 28 | # ICON is the filename of the icon (.png), relative to the project folder. 29 | # If not set, it attempts to use one of the following (in this order): 30 | # - .png 31 | # - icon.png 32 | # - /default_icon.png 33 | #--------------------------------------------------------------------------------- 34 | TARGET := crt 35 | BUILD := build 36 | SOURCES := source 37 | DATA := data 38 | INCLUDES := include 39 | GRAPHICS := gfx 40 | GFXBUILD := $(BUILD) 41 | #ROMFS := romfs 42 | #GFXBUILD := $(ROMFS)/gfx 43 | 44 | #--------------------------------------------------------------------------------- 45 | # options for code generation 46 | #--------------------------------------------------------------------------------- 47 | ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft 48 | 49 | CFLAGS := -g -Wall -O2 -mword-relocations \ 50 | -ffunction-sections \ 51 | $(ARCH) 52 | 53 | CFLAGS += $(INCLUDE) -D__3DS__ 54 | 55 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 56 | 57 | ASFLAGS := -g $(ARCH) 58 | LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 59 | 60 | LIBS := -lcitro3d -lctru -lm 61 | 62 | #--------------------------------------------------------------------------------- 63 | # list of directories containing libraries, this must be the top level containing 64 | # include and lib 65 | #--------------------------------------------------------------------------------- 66 | LIBDIRS := $(CTRULIB) 67 | 68 | 69 | #--------------------------------------------------------------------------------- 70 | # no real need to edit anything past this point unless you need to add additional 71 | # rules for different file extensions 72 | #--------------------------------------------------------------------------------- 73 | ifneq ($(BUILD),$(notdir $(CURDIR))) 74 | #--------------------------------------------------------------------------------- 75 | 76 | export OUTPUT := $(CURDIR)/$(TARGET) 77 | export TOPDIR := $(CURDIR) 78 | 79 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 80 | $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \ 81 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 82 | 83 | export DEPSDIR := $(CURDIR)/$(BUILD) 84 | 85 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 86 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 87 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 88 | PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) 89 | SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) 90 | GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s))) 91 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 92 | 93 | #--------------------------------------------------------------------------------- 94 | # use CXX for linking C++ projects, CC for standard C 95 | #--------------------------------------------------------------------------------- 96 | ifeq ($(strip $(CPPFILES)),) 97 | #--------------------------------------------------------------------------------- 98 | export LD := $(CC) 99 | #--------------------------------------------------------------------------------- 100 | else 101 | #--------------------------------------------------------------------------------- 102 | export LD := $(CXX) 103 | #--------------------------------------------------------------------------------- 104 | endif 105 | #--------------------------------------------------------------------------------- 106 | 107 | #--------------------------------------------------------------------------------- 108 | ifeq ($(GFXBUILD),$(BUILD)) 109 | #--------------------------------------------------------------------------------- 110 | export T3XFILES := $(GFXFILES:.t3s=.t3x) 111 | #--------------------------------------------------------------------------------- 112 | else 113 | #--------------------------------------------------------------------------------- 114 | export ROMFS_T3XFILES := $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES)) 115 | export T3XHFILES := $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES)) 116 | #--------------------------------------------------------------------------------- 117 | endif 118 | #--------------------------------------------------------------------------------- 119 | 120 | export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 121 | 122 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \ 123 | $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ 124 | $(addsuffix .o,$(T3XFILES)) 125 | 126 | export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) 127 | 128 | export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \ 129 | $(addsuffix .h,$(subst .,_,$(BINFILES))) \ 130 | $(GFXFILES:.t3s=.h) 131 | 132 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 133 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 134 | -I$(CURDIR)/$(BUILD) 135 | 136 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 137 | 138 | export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh) 139 | 140 | ifeq ($(strip $(ICON)),) 141 | icons := $(wildcard *.png) 142 | ifneq (,$(findstring $(TARGET).png,$(icons))) 143 | export APP_ICON := $(TOPDIR)/$(TARGET).png 144 | else 145 | ifneq (,$(findstring icon.png,$(icons))) 146 | export APP_ICON := $(TOPDIR)/icon.png 147 | endif 148 | endif 149 | else 150 | export APP_ICON := $(TOPDIR)/$(ICON) 151 | endif 152 | 153 | ifeq ($(strip $(NO_SMDH)),) 154 | export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh 155 | endif 156 | 157 | ifneq ($(ROMFS),) 158 | export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) 159 | endif 160 | 161 | .PHONY: all clean 162 | 163 | #--------------------------------------------------------------------------------- 164 | all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES) 165 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 166 | 167 | $(BUILD): 168 | @mkdir -p $@ 169 | 170 | ifneq ($(GFXBUILD),$(BUILD)) 171 | $(GFXBUILD): 172 | @mkdir -p $@ 173 | endif 174 | 175 | ifneq ($(DEPSDIR),$(BUILD)) 176 | $(DEPSDIR): 177 | @mkdir -p $@ 178 | endif 179 | 180 | #--------------------------------------------------------------------------------- 181 | clean: 182 | @echo clean ... 183 | @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD) 184 | 185 | #--------------------------------------------------------------------------------- 186 | $(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s 187 | #--------------------------------------------------------------------------------- 188 | @echo $(notdir $<) 189 | @tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x 190 | 191 | #--------------------------------------------------------------------------------- 192 | else 193 | 194 | #--------------------------------------------------------------------------------- 195 | # main targets 196 | #--------------------------------------------------------------------------------- 197 | $(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS) 198 | 199 | $(OFILES_SOURCES) : $(HFILES) 200 | 201 | $(OUTPUT).elf : $(OFILES) 202 | 203 | #--------------------------------------------------------------------------------- 204 | # you need a rule like this for each extension you use as binary data 205 | #--------------------------------------------------------------------------------- 206 | %.bin.o %_bin.h : %.bin 207 | #--------------------------------------------------------------------------------- 208 | @echo $(notdir $<) 209 | @$(bin2o) 210 | 211 | #--------------------------------------------------------------------------------- 212 | .PRECIOUS : %.t3x 213 | #--------------------------------------------------------------------------------- 214 | %.t3x.o %_t3x.h : %.t3x 215 | #--------------------------------------------------------------------------------- 216 | @echo $(notdir $<) 217 | @$(bin2o) 218 | 219 | #--------------------------------------------------------------------------------- 220 | # rules for assembling GPU shaders 221 | #--------------------------------------------------------------------------------- 222 | define shader-as 223 | $(eval CURBIN := $*.shbin) 224 | $(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d) 225 | echo "$(CURBIN).o: $< $1" > $(DEPSFILE) 226 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h 227 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h 228 | echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h 229 | picasso -o $(CURBIN) $1 230 | bin2s $(CURBIN) | $(AS) -o $*.shbin.o 231 | endef 232 | 233 | %.shbin.o %_shbin.h : %.v.pica %.g.pica 234 | @echo $(notdir $^) 235 | @$(call shader-as,$^) 236 | 237 | %.shbin.o %_shbin.h : %.v.pica 238 | @echo $(notdir $<) 239 | @$(call shader-as,$<) 240 | 241 | %.shbin.o %_shbin.h : %.shlist 242 | @echo $(notdir $<) 243 | @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file))) 244 | 245 | #--------------------------------------------------------------------------------- 246 | %.t3x %.h : %.t3s 247 | #--------------------------------------------------------------------------------- 248 | @echo $(notdir $<) 249 | @tex3ds -i $< -H $*.h -d $*.d -o $*.t3x 250 | 251 | -include $(DEPSDIR)/*.d 252 | 253 | #--------------------------------------------------------------------------------------- 254 | endif 255 | #--------------------------------------------------------------------------------------- 256 | -------------------------------------------------------------------------------- /day10-pica200/README.md: -------------------------------------------------------------------------------- 1 | Day 10 was solved using a geometry shader for the PICA200, the GPU used in the Nintendo 3DS. The code was run, as I'm sure you can guess if you've read the previous days, on my New 2DS XL: [output.jpg](output.jpg). A couple notes about this one: 2 | 3 | - I had to cheat a bit to make this work; I preprocessed the input file on the CPU slightly, simply tokenizing the instructions and converting arguments to `addx` into floats. I feel a bit bad for doing this, but I couldn't think of any sane way to pass the raw input file to the GPU. 4 | - This GPU has nothing like a compute shader and can only output to the framebuffer, so the only way I could get the answer for part 1 back to the CPU was by encoding it as a color then reading the framebuffer memory on the CPU. So, that ugly orange color you see in the background of the top screen is actually the answer for part 1. 5 | - I swear didn't know what part 2 was going to be when I decided to do this one with a GPU. It just happened to line up really nicely. 6 | -------------------------------------------------------------------------------- /day10-pica200/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day10-pica200/output.jpg -------------------------------------------------------------------------------- /day10-pica200/source/input.c: -------------------------------------------------------------------------------- 1 | //const char input[] = "addx 15\naddx -11\naddx 6\naddx -3\naddx 5\naddx -1\naddx -8\naddx 13\naddx 4\nnoop\naddx -1\naddx 5\naddx -1\naddx 5\naddx -1\naddx 5\naddx -1\naddx 5\naddx -1\naddx -35\naddx 1\naddx 24\naddx -19\naddx 1\naddx 16\naddx -11\nnoop\nnoop\naddx 21\naddx -15\nnoop\nnoop\naddx -3\naddx 9\naddx 1\naddx -3\naddx 8\naddx 1\naddx 5\nnoop\nnoop\nnoop\nnoop\nnoop\naddx -36\nnoop\naddx 1\naddx 7\nnoop\nnoop\nnoop\naddx 2\naddx 6\nnoop\nnoop\nnoop\nnoop\nnoop\naddx 1\nnoop\nnoop\naddx 7\naddx 1\nnoop\naddx -13\naddx 13\naddx 7\nnoop\naddx 1\naddx -33\nnoop\nnoop\nnoop\naddx 2\nnoop\nnoop\nnoop\naddx 8\nnoop\naddx -1\naddx 2\naddx 1\nnoop\naddx 17\naddx -9\naddx 1\naddx 1\naddx -3\naddx 11\nnoop\nnoop\naddx 1\nnoop\naddx 1\nnoop\nnoop\naddx -13\naddx -19\naddx 1\naddx 3\naddx 26\naddx -30\naddx 12\naddx -1\naddx 3\naddx 1\nnoop\nnoop\nnoop\naddx -9\naddx 18\naddx 1\naddx 2\nnoop\nnoop\naddx 9\nnoop\nnoop\nnoop\naddx -1\naddx 2\naddx -37\naddx 1\naddx 3\nnoop\naddx 15\naddx -21\naddx 22\naddx -6\naddx 1\nnoop\naddx 2\naddx 1\nnoop\naddx -10\nnoop\nnoop\naddx 20\naddx 1\naddx 2\naddx 2\naddx -6\naddx -11\nnoop\nnoop\nnoop\n"; 2 | const char input[] = "noop\naddx 24\naddx -19\nnoop\nnoop\nnoop\naddx 5\nnoop\naddx 1\naddx 5\naddx -1\naddx 5\naddx 1\naddx 14\naddx -9\naddx -1\naddx 5\nnoop\naddx 2\naddx -20\naddx 24\naddx -36\naddx -2\nnoop\naddx 3\naddx 2\naddx 5\naddx 21\naddx -16\nnoop\naddx 2\naddx 15\naddx -14\naddx 2\naddx 5\naddx 2\naddx -4\naddx 5\naddx -8\naddx 15\naddx 2\naddx 3\naddx -2\naddx -38\nnoop\naddx 3\naddx 4\nnoop\naddx 7\nnoop\nnoop\naddx -2\naddx 5\naddx -16\naddx 21\nnoop\naddx -10\naddx 11\naddx 2\naddx 5\naddx 4\nnoop\nnoop\naddx -6\naddx 7\nnoop\naddx 3\naddx -36\nnoop\naddx 5\nnoop\naddx 20\naddx -19\naddx 5\naddx 4\nnoop\naddx -2\naddx 3\nnoop\naddx 4\nnoop\naddx -1\naddx 5\naddx 3\naddx -28\naddx 30\nnoop\naddx 6\nnoop\nnoop\naddx 1\naddx -38\naddx 40\naddx -33\naddx 20\naddx -19\naddx 2\nnoop\naddx 28\naddx -23\naddx 5\naddx 2\naddx 2\naddx 3\naddx -2\naddx 5\naddx 2\naddx -7\naddx 12\naddx -2\nnoop\naddx 3\naddx -38\nnoop\naddx 24\naddx -17\nnoop\naddx 5\nnoop\nnoop\naddx 1\naddx -8\naddx 13\nnoop\nnoop\naddx 2\naddx 5\naddx 2\naddx 6\naddx -5\naddx 4\nnoop\naddx 1\naddx 2\nnoop\naddx 3\nnoop\nnoop\n"; 3 | -------------------------------------------------------------------------------- /day10-pica200/source/main.c: -------------------------------------------------------------------------------- 1 | #include <3ds.h> 2 | #include 3 | #include 4 | #include 5 | 6 | #include "program_shbin.h" 7 | 8 | #define CLEAR_COLOR 0x000000FF 9 | 10 | #define DISPLAY_TRANSFER_FLAGS \ 11 | (GX_TRANSFER_FLIP_VERT(0) | GX_TRANSFER_OUT_TILED(0) | GX_TRANSFER_RAW_COPY(0) | \ 12 | GX_TRANSFER_IN_FORMAT(GX_TRANSFER_FMT_RGBA8) | GX_TRANSFER_OUT_FORMAT(GX_TRANSFER_FMT_RGB8) | \ 13 | GX_TRANSFER_SCALING(GX_TRANSFER_SCALE_NO)) 14 | 15 | static DVLB_s* program_dvlb; 16 | static shaderProgram_s program; 17 | static int uLoc_projection, uLoc_input; 18 | static C3D_Mtx projection; 19 | 20 | static void sceneInit(void) 21 | { 22 | program_dvlb = DVLB_ParseFile((u32*)program_shbin, program_shbin_size); 23 | shaderProgramInit(&program); 24 | shaderProgramSetVsh(&program, &program_dvlb->DVLE[0]); 25 | shaderProgramSetGsh(&program, &program_dvlb->DVLE[1], 4); 26 | C3D_BindProgram(&program); 27 | 28 | // Get the location of the uniforms 29 | uLoc_projection = shaderInstanceGetUniformLocation(program.geometryShader, "projection"); 30 | uLoc_input = shaderInstanceGetUniformLocation(program.geometryShader, "input"); 31 | 32 | // Configure attributes for use with the vertex shader 33 | // Attribute format and element count are ignored in immediate mode 34 | C3D_AttrInfo* attrInfo = C3D_GetAttrInfo(); 35 | AttrInfo_Init(attrInfo); 36 | AttrInfo_AddLoader(attrInfo, 0, GPU_FLOAT, 3); // v0=position 37 | //AttrInfo_AddLoader(attrInfo, 1, GPU_FLOAT, 3); // v1=color 38 | 39 | // Compute the projection matrix 40 | Mtx_OrthoTilt(&projection, 0.0, 400.0, 0.0, 240.0, 0.0, 1.0, true); 41 | 42 | // Configure the first fragment shading substage to just pass through the vertex color 43 | // See https://www.opengl.org/sdk/docs/man2/xhtml/glTexEnv.xml for more insight 44 | C3D_TexEnv* env = C3D_GetTexEnv(0); 45 | C3D_TexEnvInit(env); 46 | C3D_TexEnvSrc(env, C3D_Both, GPU_PRIMARY_COLOR, 0, 0); 47 | C3D_TexEnvFunc(env, C3D_Both, GPU_REPLACE); 48 | } 49 | 50 | //static bool firstrun = true; 51 | 52 | //#define POINT_TO_FB_OFF(x, y) (3 * (((x) * 240) + y)) 53 | 54 | extern const char input[]; 55 | 56 | static void runSolveShader(void) 57 | { 58 | // Update the uniforms 59 | C3D_FVUnifMtx4x4(GPU_GEOMETRY_SHADER, uLoc_projection, &projection); 60 | //C3D_BoolUnifSet (GPU_GEOMETRY_SHADER, uLoc_onlyvert, firstrun); 61 | //firstrun = false; 62 | 63 | C3D_FVec* inputArr = C3D_FVUnifWritePtr(GPU_GEOMETRY_SHADER, uLoc_input, 80); 64 | const char* inputPtr = input; 65 | for (size_t i = 0; i < 160; i++) { 66 | const size_t arrIdx = i >> 1; 67 | const size_t cIdx = (i & 1) << 1; 68 | 69 | if (*inputPtr == '\0') { 70 | inputArr[arrIdx].c[cIdx] = 0.0f; 71 | inputArr[arrIdx].c[cIdx + 1] = 0.0f; 72 | break; 73 | } else if (*inputPtr == 'n') { 74 | inputArr[arrIdx].c[cIdx] = 1.0f; 75 | inputArr[arrIdx].c[cIdx + 1] = 0.0f; 76 | } else if (*inputPtr == 'a') { 77 | inputArr[arrIdx].c[cIdx] = 2.0f; 78 | int val; 79 | if (sscanf(inputPtr, "addx %d\n", &val) != 1) { 80 | printf("sscanf ded\n"); 81 | return; 82 | } 83 | inputArr[arrIdx].c[cIdx + 1] = (float) val; 84 | } else { 85 | printf("a problem, there is: %c\n", *inputPtr); 86 | return; 87 | } 88 | 89 | while (*(inputPtr++) != '\n'); 90 | } 91 | 92 | C3D_ImmDrawBegin(GPU_GEOMETRY_PRIM); 93 | C3D_ImmSendAttrib(0.0f, 0.0f, 0.5f, 0.0f); 94 | C3D_ImmSendAttrib(400.0f, 0.0f, 0.5f, 0.0f); 95 | C3D_ImmSendAttrib(0.0f, 240.0f, 0.5f, 0.0f); 96 | C3D_ImmSendAttrib(400.0f, 240.0f, 0.5f, 0.0f); 97 | C3D_ImmDrawEnd(); 98 | } 99 | 100 | static void sceneExit(void) 101 | { 102 | // Free the shader program 103 | shaderProgramFree(&program); 104 | DVLB_Free(program_dvlb); 105 | } 106 | 107 | int main() 108 | { 109 | // Initialize graphics 110 | gfxInitDefault(); 111 | C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); 112 | C3D_CullFace(GPU_CULL_NONE); 113 | 114 | // Initialize the render target 115 | C3D_RenderTarget* target = C3D_RenderTargetCreate(240, 400, GPU_RB_RGBA8, GPU_RB_DEPTH24_STENCIL8); 116 | C3D_RenderTargetSetOutput(target, GFX_TOP, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); 117 | 118 | // Initialize the scene 119 | sceneInit(); 120 | 121 | consoleInit(GFX_BOTTOM, NULL); 122 | printf("picaCHUUUU\n\n"); 123 | 124 | vu8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL); 125 | 126 | C3D_FrameBegin(C3D_FRAME_SYNCDRAW); 127 | C3D_RenderTargetClear(target, C3D_CLEAR_ALL, CLEAR_COLOR, 0); 128 | C3D_FrameDrawOn(target); 129 | runSolveShader(); 130 | C3D_FrameEnd(0); 131 | 132 | 133 | svcSleepThread(20 * 1000 * 1000); 134 | //printf("value: %hhu %hhu %hhu\n", fb[2], fb[1], fb[0]); 135 | printf("Part 1: %d\n", (fb[0] << 16) | (fb[1] << 8) | fb[2]); 136 | 137 | // Main loop 138 | while (aptMainLoop()) { 139 | hidScanInput(); 140 | 141 | // Respond to user input 142 | u32 kDown = hidKeysDown(); 143 | if (kDown & KEY_START) 144 | break; // break in order to return to hbmenu 145 | } 146 | 147 | // Deinitialize the scene 148 | sceneExit(); 149 | 150 | // Deinitialize graphics 151 | C3D_Fini(); 152 | gfxExit(); 153 | return 0; 154 | } 155 | -------------------------------------------------------------------------------- /day10-pica200/source/program.g.pica: -------------------------------------------------------------------------------- 1 | .gsh point c0 2 | 3 | ; Matrix set up by CPU to convert natural coordinates to the framebuffer 4 | .fvec projection[4] 5 | 6 | ; Processed puzzle input 7 | .fvec input[80] 8 | 9 | ; Simple constants 10 | .constf sconst0(40.0, 1.0, 256.0, 0.00390625) 11 | .constf sconst1(-256.0, 8.0, -12.0, 0.0) 12 | .constf sconst2(-40.0, 0.0, 0.0, 0.0) 13 | .alias forty sconst0.xxxx 14 | .alias nforty sconst2.xxxx 15 | .alias one sconst0.yyyy 16 | .alias two56 sconst0.zzzz 17 | .alias one256 sconst0.wwww ; 1/256 18 | .alias n256 sconst1.xxxx 19 | .alias eight sconst1.yyyy 20 | .alias n12 sconst1.zzzz 21 | .alias zero sconst1.wwww 22 | .alias xeight sconst1.ywww 23 | .alias yn12 sconst1.wzww 24 | .alias xy8n12 sconst1.yzww 25 | 26 | .constf cycles0 (20, 60, 100, 140) 27 | .constf cycles1 (180, 220, 0, 0) 28 | 29 | .constf part2start (40, 156, 0.2, 1.0) 30 | .constf part2end (360, 84, 0.2, 1.0) 31 | 32 | .consti loops (79, 0, 1, 0) 33 | 34 | ; Outputs 35 | .out outpos position 36 | .out outclr color 37 | 38 | .entry gmain 39 | .proc gmain 40 | mov r15, zero 41 | mov r15.x, one 42 | mov r12, part2start 43 | 44 | for loops 45 | mov r14, input[aL] 46 | 47 | mov r13.xy, r14.wz 48 | call handleInput 49 | cmp zero, eq, eq, r13 50 | breakc cmp.x 51 | 52 | mov r13.xy, r14.yx 53 | call handleInput 54 | cmp zero, eq, eq, r13 55 | breakc cmp.x 56 | .end 57 | 58 | ; Split the final sum (16-bit) into 2 bytes, r15.x and r15.y 59 | mov r15.x, r15.y 60 | mov r15.yzw, zero 61 | loop_256: 62 | cmp two56, gt, gt, r15.x 63 | jmpc cmp.x, break_256 64 | add r15.x, n256, r15.x 65 | add r15.y, one, r15.y 66 | jmpc !cmp.x, loop_256 67 | break_256: 68 | 69 | ; Encode the final sum into a color 70 | mov r0, one256 71 | mul r0, r15, r0 72 | mov r0.a, one 73 | mov r15, r0 74 | 75 | ; Draw triangles with that color, which the CPU will read 76 | call rectFromInput 77 | 78 | end 79 | .end 80 | 81 | .proc handleInput 82 | cmp zero, eq, eq, r13.x 83 | ifc cmp.x 84 | mov r13, zero 85 | .end 86 | jmpc cmp.x, handleInput_ret 87 | 88 | call doCycle 89 | cmp one, eq, eq, r13.x 90 | jmpc cmp.x, handleInput_ret 91 | 92 | call doCycle 93 | add r15.x, r13.y, r15.x 94 | handleInput_ret: 95 | nop 96 | .end 97 | 98 | .proc doCycle 99 | mov r1, zero 100 | 101 | ; Get r15.z mod 40 (if there's an instruction to do this idk what it is) 102 | mov r0.y, r15.z 103 | loop_40: 104 | cmp forty, gt, gt, r0.y 105 | jmpc cmp.x, break_40 106 | add r0.y, nforty, r0.y 107 | jmpc !cmp.x, loop_40 108 | break_40: 109 | 110 | ; Check if the sprite overlaps the currently drawn pixel, somewhat lazily 111 | cmp r15.x, eq, eq, r0.y 112 | jmpc cmp.x, part2_match 113 | add r0.x, one, r15.x 114 | nop 115 | cmp r0.x, eq, eq, r0.y 116 | jmpc cmp.x, part2_match 117 | add r0.x, one, r0.y 118 | nop 119 | cmp r15.x, eq, eq, r0.x 120 | jmpc cmp.x, part2_match 121 | jmpc !cmp.x, part2_draw 122 | 123 | part2_match: 124 | mov r1, one 125 | part2_draw: 126 | ; Draw a rectangle (2 triangles) to represent one CRT pixel 127 | mov r0, r12 128 | setemit 0 129 | mov outclr, r1 130 | call emitPoint 131 | add r0, xeight, r12 132 | setemit 1 133 | mov outclr, r1 134 | call emitPoint 135 | add r0, yn12, r12 136 | setemit 2, prim 137 | mov outclr, r1 138 | call emitPoint 139 | add r0, xeight, r12 140 | setemit 0 141 | mov outclr, r1 142 | call emitPoint 143 | add r0, yn12, r12 144 | setemit 1 145 | mov outclr, r1 146 | call emitPoint 147 | add r0, xy8n12, r12 148 | setemit 2, prim 149 | mov outclr, r1 150 | call emitPoint 151 | 152 | ; Advance r12 to the corner of the next CRT pixel rect 153 | add r12.x, eight, r12.x 154 | cmp part2end.x, eq, eq, r12.x 155 | ifc cmp.x 156 | mov r12.x, part2start.x 157 | add r12.y, n12, r12.y 158 | .end 159 | ; Incrememnt cycle counter so it now contains the actual cycle number 160 | add r15.z, one, r15.z 161 | 162 | ; Check if this is one of the cycles of interest for part 1 163 | cmp cycles0.x, eq, eq, r15.z 164 | jmpc cmp.x, part1_match 165 | cmp cycles0.y, eq, eq, r15.z 166 | jmpc cmp.x, part1_match 167 | cmp cycles0.z, eq, eq, r15.z 168 | jmpc cmp.x, part1_match 169 | cmp cycles0.w, eq, eq, r15.z 170 | jmpc cmp.x, part1_match 171 | cmp cycles1.x, eq, eq, r15.z 172 | jmpc cmp.x, part1_match 173 | cmp cycles1.y, eq, eq, r15.z 174 | jmpc cmp.x, part1_match 175 | jmpc !cmp.x, doCycle_ret 176 | part1_match: 177 | mul r0.x, r15.x, r15.z 178 | add r15.y, r0.x, r15.y 179 | doCycle_ret: 180 | nop 181 | .end 182 | 183 | .proc rectFromInput 184 | ; This just draws two big triangles according to the received positions 185 | setemit 0 186 | mov r0, v0 187 | mov outclr, r15 188 | call emitPoint 189 | setemit 1 190 | mov r0, v1 191 | mov outclr, r15 192 | call emitPoint 193 | setemit 2, prim 194 | mov r0, v2 195 | mov outclr, r15 196 | call emitPoint 197 | setemit 0 198 | mov r0, v1 199 | mov outclr, r15 200 | call emitPoint 201 | setemit 1 202 | mov r0, v2 203 | mov outclr, r15 204 | call emitPoint 205 | setemit 2, prim 206 | mov r0, v3 207 | mov outclr, r15 208 | call emitPoint 209 | .end 210 | 211 | .proc emitPoint 212 | dp4 outpos.x, projection[0], r0 213 | dp4 outpos.y, projection[1], r0 214 | dp4 outpos.z, projection[2], r0 215 | dp4 outpos.w, projection[3], r0 216 | emit 217 | .end -------------------------------------------------------------------------------- /day10-pica200/source/program.v.pica: -------------------------------------------------------------------------------- 1 | ; Example PICA200 vertex shader 2 | 3 | ; Constants 4 | .constf myconst(0.0, 1.0, -1.0, -0.5) 5 | .alias zeros myconst.xxxx ; Vector full of zeros 6 | .alias ones myconst.yyyy ; Vector full of ones 7 | 8 | ; Outputs - since we are also using a geoshader the output type isn't really used 9 | .out outpos position 10 | 11 | ; Inputs (defined as aliases for convenience) 12 | .alias inpos v0 13 | 14 | .entry vmain 15 | .proc vmain 16 | ; Pass through both inputs to the geoshader 17 | mov outpos.xyz, inpos 18 | mov outpos.w, ones 19 | 20 | ; We're finished 21 | end 22 | .end 23 | -------------------------------------------------------------------------------- /day11-i586/.gitignore: -------------------------------------------------------------------------------- 1 | mitm 2 | -------------------------------------------------------------------------------- /day11-i586/build.sh: -------------------------------------------------------------------------------- 1 | gcc -m32 --no-plt -nostartfiles -mmanual-endbr debug.c main.S -o mitm 2 | -------------------------------------------------------------------------------- /day11-i586/debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "monkey.h" 6 | 7 | extern monkey monkey_array[MAX_MONKEYS]; 8 | 9 | _Static_assert(sizeof(monkey_array) == MAX_MONKEYS * MONKEY_SIZE); 10 | 11 | void c_debug(uint32_t eax, uint32_t ecx, uint32_t edx) { 12 | printf("\nC debug called with eax %u, ecx %u, edx %u\n", eax, ecx, edx); 13 | bool die = false; 14 | for (int i = 0; i < 8; i++) { 15 | printf("Monkey %d: %u items, %u times, t: %u, u: %u\n", i, monkey_array[i].n_items, monkey_array[i].insp_total, monkey_array[i].true_target, monkey_array[i].false_target); 16 | if (monkey_array[i].n_items > 16) 17 | die = true; 18 | for (int j = 0; j < 16; j++) { 19 | printf("%016llX ", monkey_array[i].items_part2[j]); 20 | } 21 | printf("\n"); 22 | } 23 | if (die) 24 | __builtin_trap(); 25 | } -------------------------------------------------------------------------------- /day11-i586/input.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 85, 77, 77 3 | Operation: new = old * 7 4 | Test: divisible by 19 5 | If true: throw to monkey 6 6 | If false: throw to monkey 7 7 | 8 | Monkey 1: 9 | Starting items: 80, 99 10 | Operation: new = old * 11 11 | Test: divisible by 3 12 | If true: throw to monkey 3 13 | If false: throw to monkey 5 14 | 15 | Monkey 2: 16 | Starting items: 74, 60, 74, 63, 86, 92, 80 17 | Operation: new = old + 8 18 | Test: divisible by 13 19 | If true: throw to monkey 0 20 | If false: throw to monkey 6 21 | 22 | Monkey 3: 23 | Starting items: 71, 58, 93, 65, 80, 68, 54, 71 24 | Operation: new = old + 7 25 | Test: divisible by 7 26 | If true: throw to monkey 2 27 | If false: throw to monkey 4 28 | 29 | Monkey 4: 30 | Starting items: 97, 56, 79, 65, 58 31 | Operation: new = old + 5 32 | Test: divisible by 5 33 | If true: throw to monkey 2 34 | If false: throw to monkey 0 35 | 36 | Monkey 5: 37 | Starting items: 77 38 | Operation: new = old + 4 39 | Test: divisible by 11 40 | If true: throw to monkey 4 41 | If false: throw to monkey 3 42 | 43 | Monkey 6: 44 | Starting items: 99, 90, 84, 50 45 | Operation: new = old * old 46 | Test: divisible by 17 47 | If true: throw to monkey 7 48 | If false: throw to monkey 1 49 | 50 | Monkey 7: 51 | Starting items: 50, 66, 61, 92, 64, 78 52 | Operation: new = old + 3 53 | Test: divisible by 2 54 | If true: throw to monkey 5 55 | If false: throw to monkey 1 56 | -------------------------------------------------------------------------------- /day11-i586/main.S: -------------------------------------------------------------------------------- 1 | .intel_syntax noprefix 2 | 3 | #include "monkey.h" 4 | 5 | .section .text 6 | 7 | //Layout of a monkey struct is 8 | // 0: operation type (0 for add literal, 1 for mul literal, 2 for old * old) 9 | // 4: literal operand, ignored for type 2 10 | // 8: test divisor 11 | // 12: target if true 12 | // 16: target if false 13 | // 20: total number of items inspected 14 | // 24: current number of items 15 | // 28: array of item worry levels for part 1 16 | // 156: array of item infos, MAX_MONKEYS bytes each, storing the remainder mod each monkey divisor 17 | 18 | .global _start 19 | _start: 20 | push offset hello_world_string 21 | call puts 22 | add esp, 4 23 | 24 | pop eax // argc 25 | cmp eax, 2 26 | je args_correct 27 | mov eax, 0[esp] // argv[0] 28 | push eax 29 | push offset args_wrong_string 30 | call printf 31 | add esp, 8 32 | call exit 33 | args_correct: 34 | 35 | push ebx 36 | push edi 37 | push esi 38 | push ebp 39 | 40 | mov eax, 20 41 | push eax // number of rounds to count; tracks part1 vs part2 42 | 43 | do_it_again: 44 | mov ebp, 24[esp] // argv[1], the puzzle input. what's a base pointer? :p 45 | xor edx, edx // monkey counter 46 | 47 | process_input_loop: 48 | imul edi, edx, MONKEY_SIZE 49 | add edi, offset monkey_array // current monkey pointer 50 | inc edx 51 | add ebp, 28 // skip "Monkey X:\n Starting items: " 52 | xor ecx, ecx 53 | mov [edi+20], ecx 54 | starting_items_loop: 55 | call atoi 56 | mov [edi+28+ecx*4], eax 57 | mov al, [ebp] 58 | inc ecx 59 | add ebp, 2 // skip ", " 60 | cmp al, ',' 61 | je starting_items_loop 62 | starting_items_break: 63 | mov [edi+24], ecx // store number of items 64 | add ebp, 22 // skip " Operation: new = old " 65 | mov al, [ebp] 66 | add ebp, 2 67 | xor ecx, ecx 68 | cmp al, '*' 69 | jne imm_op 70 | inc ecx 71 | cmp byte ptr [ebp], 'o' 72 | jne imm_op 73 | // old * old case 74 | inc ecx 75 | add ebp, 3 // skip "old" 76 | jmp skip_imm_op 77 | imm_op: 78 | call atoi 79 | mov [edi+4], eax // store immediate operand 80 | skip_imm_op: 81 | mov [edi], ecx // store operand type 82 | add ebp, 22 // skip "\n Test: divisible by " 83 | call atoi 84 | mov [edi+8], eax // store divisor 85 | add ebp, 30 // skip "\n If true: throw to monkey " 86 | call atoi 87 | mov [edi+12], eax 88 | add ebp, 31 // skip "\n If false: throw to monkey " 89 | call atoi 90 | mov [edi+16], eax 91 | // check for end of input 92 | cmp byte ptr [ebp], 0 93 | je process_input_break 94 | cmp byte ptr [ebp], 0 95 | je process_input_break 96 | add ebp, 2 97 | cmp byte ptr [ebp], 0 98 | jne process_input_loop 99 | process_input_break: 100 | 101 | push edx // save total monkey count so edx can be used as scratch 102 | sub esp, 4 103 | 104 | cmp dword ptr [esp+8], 20 105 | je skip_part2_items 106 | 107 | mov dword ptr [esp], 0 108 | part2_items_outer_loop: 109 | imul edi, [esp], MONKEY_SIZE 110 | add edi, offset monkey_array 111 | xor ebp, ebp 112 | part2_items_items_loop: 113 | cmp ebp, [edi+24] 114 | je part2_items_items_break 115 | mov ebx, [edi+28+ebp*4] 116 | xor ecx, ecx 117 | part2_items_inner_loop: 118 | imul esi, ecx, MONKEY_SIZE 119 | add esi, offset monkey_array 120 | mov esi, [esi+8] 121 | mov eax, ebx 122 | xor edx, edx 123 | idiv esi 124 | lea esi, [edi+156+ebp*8] 125 | mov [esi+ecx], dl 126 | // inner loop break check 127 | inc ecx 128 | cmp ecx, [esp+4] 129 | jne part2_items_inner_loop 130 | inc ebp 131 | jmp part2_items_items_loop 132 | part2_items_items_break: 133 | inc dword ptr [esp] 134 | mov eax, [esp+4] 135 | cmp [esp], eax 136 | jne part2_items_outer_loop 137 | 138 | skip_part2_items: 139 | 140 | xor ebp, ebp // outer loop (round) counter. base pointer? I barely know her! 141 | simul_outer_loop: 142 | //mov eax, ebp 143 | //call debug 144 | mov dword ptr [esp], 0 // inner loop (monkey) counter 145 | simul_inner_loop: 146 | imul edi, [esp], MONKEY_SIZE 147 | add edi, offset monkey_array // current monkey pointer 148 | xor ecx, ecx // item loop counter 149 | simul_item_loop: 150 | cmp ecx, [edi+24] 151 | je simul_item_break 152 | cmp dword ptr [esp+8], 20 153 | jne simul_do_part2 154 | mov eax, [edi+28+ecx*4] 155 | cmp dword ptr [edi], 1 156 | je p1_imm_mul 157 | js p1_imm_add 158 | imul eax, eax 159 | jmp p1_op_done 160 | p1_imm_mul: 161 | imul eax, [edi+4] 162 | jmp p1_op_done 163 | p1_imm_add: 164 | add eax, [edi+4] 165 | p1_op_done: 166 | xor edx, edx 167 | mov ebx, 3 168 | idiv ebx 169 | mov ebx, eax // save real worry value 170 | xor edx, edx 171 | idiv dword ptr [edi+8] 172 | cmp edx, 0 173 | je p1_divisible 174 | mov eax, [edi+16] 175 | jmp p1_div_test_done 176 | p1_divisible: 177 | mov eax, [edi+12] 178 | p1_div_test_done: 179 | imul eax, MONKEY_SIZE 180 | add eax, offset monkey_array 181 | mov edx, [eax+24] 182 | mov [eax+28+edx*4], ebx 183 | inc dword ptr [eax+24] 184 | jmp simul_item_loop_inc 185 | simul_do_part2: 186 | push ebp 187 | xor ebp, ebp 188 | simul_innermost_loop: 189 | lea esi, [edi+156+ecx*8] 190 | movzx eax, byte ptr [esi+ebp] 191 | cmp dword ptr [edi], 1 192 | je p2_imm_mul 193 | js p2_imm_add 194 | imul eax, eax 195 | jmp p2_op_done 196 | p2_imm_mul: 197 | imul eax, [edi+4] 198 | jmp p2_op_done 199 | p2_imm_add: 200 | add eax, [edi+4] 201 | p2_op_done: 202 | imul esi, ebp, MONKEY_SIZE 203 | add esi, offset monkey_array 204 | mov ebx, [esi+8] 205 | xor edx, edx 206 | idiv ebx 207 | lea esi, [edi+156+ecx*8] 208 | mov [esi+ebp], dl 209 | inc ebp 210 | cmp ebp, [esp+8] 211 | jne simul_innermost_loop 212 | // innermost loop end 213 | mov eax, [esp+4] 214 | mov al, [esi+eax] 215 | cmp al, 0 216 | je p2_divisible 217 | mov eax, [edi+16] 218 | jmp p2_div_test_done 219 | p2_divisible: 220 | mov eax, [edi+12] 221 | p2_div_test_done: 222 | imul eax, MONKEY_SIZE 223 | add eax, offset monkey_array 224 | mov edx, [eax+24] 225 | mov ebx, [esi] 226 | mov [eax+156+edx*8], ebx 227 | mov ebx, [esi+4] 228 | mov [eax+156+edx*8+4], ebx 229 | inc dword ptr [eax+24] 230 | pop ebp 231 | simul_item_loop_inc: 232 | inc ecx 233 | jmp simul_item_loop 234 | simul_item_break: 235 | xor eax, eax 236 | mov [edi+24], eax 237 | add [edi+20], ecx 238 | // check for inner loop break 239 | inc dword ptr [esp] 240 | mov eax, [esp+4] 241 | cmp dword ptr [esp], eax 242 | jne simul_inner_loop 243 | // check for outer loop break 244 | inc ebp 245 | cmp ebp, [esp+8] 246 | jne simul_outer_loop 247 | 248 | mov edx, [esp+4] 249 | add esp, 8 250 | 251 | xor esi, esi // highest 252 | xor ecx, ecx // second highest 253 | find_top_two_loop: 254 | dec edx 255 | cmp edx, 0 256 | js find_top_two_break 257 | imul edi, edx, MONKEY_SIZE 258 | add edi, offset monkey_array 259 | mov eax, [edi+20] 260 | cmp esi, eax 261 | js new_highest 262 | cmp ecx, eax 263 | jns find_top_two_loop 264 | mov ecx, eax 265 | jmp find_top_two_loop 266 | new_highest: 267 | mov ecx, esi 268 | mov esi, eax 269 | jmp find_top_two_loop 270 | find_top_two_break: 271 | 272 | cmp dword ptr [esp], 20 273 | jne part2 274 | 275 | imul ecx, esi 276 | push ecx 277 | push offset part1_string 278 | call printf 279 | add esp, 8 280 | 281 | mov dword ptr [esp], 10000 282 | jmp do_it_again 283 | 284 | part2: 285 | //call debug 286 | 287 | add esp, 4 288 | 289 | mov eax, ecx 290 | mul esi 291 | push edx 292 | push eax 293 | push offset part2_string 294 | call printf 295 | add esp, 8 296 | 297 | pop ebp 298 | pop esi 299 | pop edi 300 | pop ebx 301 | xor eax, eax 302 | call exit 303 | 304 | // String in ebp; advances ebp to first nonascii, returns number in eax, clobbers ebx 305 | atoi: 306 | xor eax, eax 307 | atoi_loop: 308 | movzx ebx, byte ptr [ebp] 309 | sub ebx, '0' 310 | js atoi_break 311 | cmp ebx, 10 312 | jns atoi_break 313 | imul eax, 10 314 | inc ebp 315 | add eax, ebx 316 | jmp atoi_loop 317 | atoi_break: 318 | ret 319 | 320 | // Advances ebp past first newline, clobbers al 321 | skip_line: 322 | mov al, [ebp] 323 | inc ebp 324 | cmp al, '\n' 325 | jne skip_line 326 | ret 327 | 328 | debug: 329 | push edx 330 | push ecx 331 | push eax 332 | call c_debug 333 | pop eax 334 | pop ecx 335 | pop edx 336 | ret 337 | 338 | .section .rodata 339 | 340 | hello_world_string: 341 | .ascii "i386? more like i<3legacybloat86 amirite\n\0" 342 | args_wrong_string: 343 | .ascii "Usage: %s \n\0" 344 | part1_string: 345 | .ascii "Part 1: %u\n\0" 346 | part2_string: 347 | .ascii "Part 2: %llu\n\0" // big numbers! 348 | //debug_string: 349 | // .ascii "Debug: %d\n\0" 350 | 351 | 352 | .section .bss 353 | 354 | .global monkey_array 355 | monkey_array: 356 | .skip MAX_MONKEYS * MONKEY_SIZE 357 | -------------------------------------------------------------------------------- /day11-i586/monkey.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MAX_ITEMS 32 4 | #define MAX_MONKEYS 8 5 | 6 | #define MONKEY_SIZE (28 + (MAX_ITEMS * (MAX_MONKEYS + 4))) 7 | 8 | #ifndef __ASSEMBLER__ 9 | typedef struct monkey { 10 | uint32_t op_type; 11 | uint32_t operand; 12 | uint32_t divisor; 13 | uint32_t true_target; 14 | uint32_t false_target; 15 | uint32_t insp_total; 16 | uint32_t n_items; 17 | uint32_t items_part1[MAX_ITEMS]; 18 | uint64_t items_part2[MAX_ITEMS]; 19 | } __attribute__((packed, aligned(4))) monkey; 20 | 21 | _Static_assert(sizeof(monkey) == MONKEY_SIZE); 22 | _Static_assert(sizeof(monkey) - sizeof(((monkey*)0)->items_part2) == 156); 23 | #endif -------------------------------------------------------------------------------- /day11-i586/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspargas2/advent-of-code-2022/b0be2aad3ec864395cce8c9e64f77dbb4e52285d/day11-i586/output.jpg -------------------------------------------------------------------------------- /day11-i586/sample_input.txt: -------------------------------------------------------------------------------- 1 | Monkey 0: 2 | Starting items: 79, 98 3 | Operation: new = old * 19 4 | Test: divisible by 23 5 | If true: throw to monkey 2 6 | If false: throw to monkey 3 7 | 8 | Monkey 1: 9 | Starting items: 54, 65, 75, 74 10 | Operation: new = old + 6 11 | Test: divisible by 19 12 | If true: throw to monkey 2 13 | If false: throw to monkey 0 14 | 15 | Monkey 2: 16 | Starting items: 79, 60, 97 17 | Operation: new = old * old 18 | Test: divisible by 13 19 | If true: throw to monkey 1 20 | If false: throw to monkey 3 21 | 22 | Monkey 3: 23 | Starting items: 74 24 | Operation: new = old + 3 25 | Test: divisible by 17 26 | If true: throw to monkey 0 27 | If false: throw to monkey 1 28 | --------------------------------------------------------------------------------