Created
June 11, 2021 04:32
-
-
Save charasyn/66531d5b5a98b53f20ff913183a701cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// cooprocks123e, 2021 | |
// 100% public domain meme | |
// ... well, as much as this dance is public domain | |
// https://www.youtube.com/watch?v=om_POD45fCs | |
// https://www.youtube.com/watch?v=BB2WTMpXjS4 | |
// use the other bits of the code however you want though | |
// thanks to everyone on the PK Hack discord <3 | |
import movscr_codes // Movement script code defines | |
import asm65816 | |
// Unused RAM addresses used for communicating from | |
// Controller to Minions | |
define comm1 = 0x2894 | |
define comm2 = 0x2895 | |
define comm3 = 0x1ad0 | |
// Command to update the comm variables and wait, which | |
// shows a certain animation frame for a certain amount | |
// of time | |
command meme(wt,a,b,c) { | |
"[15 {short comm1} {byte a} {byte b}]" | |
mov_mem8(comm3,c) | |
mov_wait(wt) | |
} | |
// Controller code containing the animation | |
sprCtrl: { | |
// Spawn minions 1 through 3 | |
movasm_create_obj(1, 899) | |
movasm_create_obj(14, 900) | |
movasm_create_obj(16, 901) | |
ondraw(0x9ff0) // RTS - Hide this sprite | |
// Todo: Is there a better way to hide a sprite?? | |
meme(120,1,0,0) // Just pause for 2 sec | |
meme(4,9,0,0) | |
meme(4,3,0,0) | |
meme(4,11,0,0) | |
startloop(10) | |
// This could probably be turned into a table or smth | |
// but I don't care because it works | |
meme(12,5,0,0) | |
meme(12,11,0,0) | |
meme(12,5,0,0) | |
meme(12,13,0,0) | |
meme(12,5,0,0) | |
meme(4,13,0,0) | |
meme(4,7,0,0) | |
meme(4,14,0,0) | |
meme(4,1,0,0) | |
meme(12,9,0,0) | |
meme(12,1,0,0) | |
meme(12,15,0,0) | |
meme(12,1,0,0) | |
meme(4,9,0,0) | |
meme(4,3,0,0) | |
meme(4,11,0,0) | |
meme(12,0,9,0) | |
meme(6,0,74,0) // <-- Move left 1px! 10+64 | |
meme(6,0,11,0) | |
meme(6,0,12,0) | |
meme(6,0,9,0) | |
meme(6,0,74,0) // <-- Move left 1px! 10+64 | |
meme(6,0,11,0) | |
meme(6,0,12,0) | |
meme(12,0,9,0) | |
meme(8,0,16,0) | |
meme(4,0,9,0) | |
meme(8,0,16,0) | |
meme(16,0,13,0) | |
meme(6,0,9,0) | |
meme(8,0,16,0) | |
meme(4,0,9,0) | |
meme(8,0,16,0) | |
meme(16,0,1,0) | |
meme(6,0,9,0) | |
meme(8,0,16,0) | |
meme(4,0,9,0) | |
meme(8,0,16,0) | |
meme(8,0,9,0) | |
meme(16,0,0,33) // <-- Move right 8px! 1+32 | |
meme(6,0,9,0) | |
meme(8,0,16,0) | |
meme(4,0,9,0) | |
meme(8,0,16,0) | |
meme(8,0,9,0) | |
meme(16,0,0,23) // <-- Move left 8px! 7+16 | |
endloop | |
// Non-infinite loop so that we can show cleanup working | |
// Send -1 over comm so that minions delete themselves | |
meme(0, -1, -1, -1) | |
ondraw(0xa3a4) // Make ourselves visible again | |
halt | |
} | |
// Minions just initialize, read the comm value, and | |
// run common code. | |
sprMinion1: { | |
mov_jsr(sprMinion_init) | |
loop: | |
mov_reg_mem(comm1) | |
mov_jsr(sprMinion_main) | |
mov_jmp(loop) | |
} | |
sprMinion2: { | |
mov_jsr(sprMinion_init) | |
loop: | |
mov_reg_mem(comm2) | |
mov_jsr(sprMinion_main) | |
mov_jmp(loop) | |
} | |
sprMinion3: { | |
mov_jsr(sprMinion_init) | |
loop: | |
mov_reg_mem(comm3) | |
mov_jsr(sprMinion_main) | |
mov_jmp(loop) | |
} | |
sprMinion_init: { | |
zerovel | |
// Idk what these two do, I copied it from | |
// a vanilla movement routine | |
asmcall(0xc0c7db) | |
asmcall(0xc0c353) | |
// Invalid value - next time we call UpdateGfx | |
// it will definitely update | |
setanim(16) | |
onmove(0x9ff0) // RTS | |
ondraw(0x9ff0) // RTS | |
asmcall(sprMinion_asmStorePosition) | |
mov_rts | |
} | |
sprMinion_main: { | |
reg_and(0x00ff) | |
jeq(hide) | |
reg_add(-1) | |
mov_var_reg(2) | |
reg_and(0x0080) | |
jne(destroy) | |
asmcall(sprMinion_asmUpdateGfx) | |
ondraw(0xa3a4) | |
mov_jmp(return) | |
hide: | |
ondraw(0x9ff0) // RTS | |
return: | |
mov_wait(1) | |
mov_rts | |
destroy: | |
movasm_destroy_thisobj | |
mov_end | |
} | |
sprMinion_asmStorePosition: { | |
// What we have in X is the script index | |
// What we need is the object index (in 0x88?) | |
LDY_d(0x88) | |
LDA_y(0x0B8E) // X | |
STA_y(0x0F4E) // VAR[4] | |
LDA_y(0x0BCA) // Y | |
STA_y(0x0F8A) // VAR[5] | |
RTL | |
} | |
sprMinion_asmUpdateGfx: { | |
// X is the script index, we need the object index (from $88) | |
LDY_d(0x88) | |
LDA_y(0x0ed6) // VAR[2] = new anim # | |
CMP_y(0x10f2) | |
BNE(1) | |
RTL // Return if animation # has not changed | |
// Copy VAR[2] to animation # | |
STA_y(0x10f2) | |
// Finish computing graphics table ptr | |
AND_i(0x000f) | |
ASL | |
CLC | |
ADC_y(0x29ca) | |
STA_d(0x02) | |
// Check if we need to offset left by 1px | |
LDX_y(0x0ed6) | |
LDA_y(0x0F4E) // Load global X pos from VAR[4] | |
CPX_i(0x0040) // Move left 1px bit | |
BCC_a(noLeft1) | |
// Modify global X position in A | |
DEC | |
BRA_a(noPosChange) | |
noLeft1: | |
CPX_i(0x0020) // Move right 8px bit | |
BCC_a(noRight8) | |
// Modify global X position in A | |
ADC_i(7) // Carry is set since we just did a BCC | |
BRA_a(noPosChange) | |
noRight8: | |
CPX_i(0x0010) // Move left 8px bit | |
BCC_a(noPosChange) | |
// Modify global X position in A | |
SBC_i(8) | |
noPosChange: | |
// Store X position into table | |
STA_y(0x0B8E) | |
// Load rest of values as expected by UNKNOWN_C0A3A4_UNKNOWN13 | |
STY_d(0x08) | |
LDA_y(0x2aba) | |
STA_d(0x00) | |
LDA_y(0x2a7e) | |
STA_a(0x0092) | |
LDA_y(0x298e) | |
STA_a(0x0097) | |
LDA_y(0x2a06) | |
STA_d(0x04) | |
// Go to UNKNOWN_C0A3A4_UNKNOWN13 to finish uploading gfx | |
JML(0xC0A501) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment