From 0859674cdc69faf0e1d52ba117c10a1abd49a1c3 Mon Sep 17 00:00:00 2001 From: Spence Date: Sat, 1 Jan 2022 16:36:41 -0800 Subject: [PATCH] consolidate add_item function --- Pirates Folly.gb | Bin 32768 -> 32768 bytes main.asm | 210 +++++++++++++++++++++++++++-------------------- utils.c | 18 ++-- 3 files changed, 131 insertions(+), 97 deletions(-) diff --git a/Pirates Folly.gb b/Pirates Folly.gb index 57c90ae721a6fd31450d0eb10978a10daa5eaf71..645161580976f885fd75b86b0377a0fa9e69441a 100644 GIT binary patch delta 1389 zcmZ`&ZERCj7``8EN5``5b__~2qg`d$im-m%w)eByibD9|O2}XsgWYr?5EsTYr2BAP z2^dV&g?SSG7{VlKOe9$%Kc+vH_1@aWyXFu-a*4>t$&-tP((oNn4Lu3;<2QHHy+dJ{c(87XQ zGDxw~6xsMCHNKA=1ZjVeS!WH)8mA^~M4ssj=x`kex0?y^a8R7d(J0f z#JdO63t39@gw-w_>q?C{G-DmnkrJZ8QlN3-G@{cB)rd&_yTI}|qEq+YMpUZyua{#R zJyV6T)~dp&d&|7jS{Q95qnvMK!F~{tzT~k}EyT_f-L6sx*O1SL5PfnvR1Cqd0tO9x z{Ys5<9?@)WBVbrG&G;P=5n|1wqM8)brn(S#BlrVZ1hLRn-oe5}7S6G-z&nc%I{wHk zb-lK z58v}Eg|jC3Eua*7P4FiMr%Z4ms0`13n-9T@!H|Y5C%VZxQD+FOJ=%gh(&2pA*rL@E zBlk16FMfw5DnwW6@OV6l@Xj=jdDVMNFNToacXAL;#0^@BSrAod@fNnrz#ZN}CIABzQloQ%;Y~M!DRT8s(pNEx61H~8DTZ;x)I=ATLZVxYB;c{Lc7?EAav(eJI)+4uv zRWFaEvF0~X5Z7@f%!U>c$ry1f+~dk4M}^wnO=`->N*&%(+%P6yU-9nQ^qR$!QP);2u!DFX`*iP3`hr*|f+uC-Jzhw?o-G|ar_|H%WlqC2Zh?aW*5 zN1MqzfZ-bLn^m3QLDWqe;4s%%Rk48q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C1t6Wb9bq86)YB;9O**QHkaM+t69 zNA<}d^Ug&9ctZB;D`;E*T*%&|5P(>j{8z8#?%eKps3H+Ycc#8NK4II@H=f)f%a3Z=uUj ZrW2aO@$$Yf6H!p#&6)7|5d19c`3HlqJCXnZ diff --git a/main.asm b/main.asm index d7e0863..10bfa3d 100644 --- a/main.asm +++ b/main.asm @@ -10197,58 +10197,84 @@ ___str_6: .db 0x09 .ascii "%u" .db 0x00 -;utils.c:197: void add_item(const unsigned char item) { +;utils.c:197: void add_item(const unsigned char item, const unsigned char x, ; --------------------------------- ; Function add_item ; --------------------------------- _add_item:: -;utils.c:199: if (p.weapons[0] == -1) +;utils.c:200: if (p.weapons[0] == -1) { ld bc, #_p + 20 ld a, (bc) inc a jr NZ, 00102$ -;utils.c:200: p.weapons[0] = item; +;utils.c:201: p.weapons[0] = item; ldhl sp, #2 ld a, (hl) ld (bc), a - ret + jr 00103$ 00102$: -;utils.c:202: p.weapons[1] = item; +;utils.c:203: p.weapons[1] = item; ld de, #(_p + 21) ldhl sp, #2 ld a, (hl) ld (de), a -;utils.c:203: } +00103$: +;utils.c:206: map[x][y] = item - 64; + ldhl sp, #3 + ld c, (hl) + ld b, #0x00 + ld l, c + ld h, b + add hl, hl + add hl, hl + add hl, hl + add hl, bc + add hl, hl + ld bc,#_map + add hl,bc + ld c, l + ld b, h + ldhl sp, #4 + ld a, (hl-) + dec hl + add a, c + ld c, a + ld a, #0x00 + adc a, b + ld b, a + ld a, (hl) + add a, #0xc0 + ld (bc), a +;utils.c:207: } ret -;utils.c:205: void change_item() { +;utils.c:209: void change_item() { ; --------------------------------- ; Function change_item ; --------------------------------- _change_item:: -;utils.c:206: const char _w = p.weapons[0]; +;utils.c:210: const char _w = p.weapons[0]; ld hl, #_p + 20 ld c, (hl) -;utils.c:207: p.weapons[0] = p.weapons[1]; +;utils.c:211: p.weapons[0] = p.weapons[1]; ld de, #_p + 21 ld a, (de) ld (hl), a -;utils.c:208: p.weapons[1] = _w; +;utils.c:212: p.weapons[1] = _w; ld a, c ld (de), a -;utils.c:209: } +;utils.c:213: } ret -;utils.c:211: void interact() { +;utils.c:215: void interact() { ; --------------------------------- ; Function interact ; --------------------------------- _interact:: - dec sp - dec sp -;utils.c:216: for (char x = -2; x <= 0; x++) - ldhl sp, #0 + add sp, #-4 +;utils.c:220: for (char x = -2; x <= 0; x++) + ldhl sp, #3 ld (hl), #0xfe 00109$: - ldhl sp, #0 + ldhl sp, #3 ld e, (hl) xor a, a ld d, a @@ -10265,11 +10291,13 @@ _interact:: scf 00141$: jr C, 00111$ -;utils.c:217: for (char y = -3; y <= -1; y++) { - ldhl sp, #0 +;utils.c:221: for (char y = -3; y <= -1; y++) { + ldhl sp, #3 ld a, (hl) add a, #0x0a - ld c, a + ldhl sp, #0 + ld (hl), a + ld c, (hl) ld b, #0x00 ld l, c ld h, b @@ -10280,16 +10308,20 @@ _interact:: add hl, hl ld bc,#_map add hl,bc - ld c, l - ld b, h - ldhl sp, #1 - ld (hl), #0xfd + push hl + ld a, l + ldhl sp, #3 + ld (hl), a + pop hl + ld a, h + ldhl sp, #2 + ld (hl), a + ld c, #0xfd 00106$: - ldhl sp, #1 - ld e, (hl) + ld e, c ld a,#0xff ld d,a - sub a, (hl) + sub a, c bit 7, e jr Z, 00142$ bit 7, d @@ -10302,73 +10334,73 @@ _interact:: scf 00143$: jr C, 00110$ -;utils.c:219: const unsigned char pos_y = y + center_y / sprite_size; - ldhl sp, #1 - ld a, (hl) +;utils.c:223: const unsigned char pos_y = y + center_y / sprite_size; + ld a, c add a, #0x09 -;utils.c:220: const unsigned char _i = map[pos_x][pos_y]; - ld l, a - ld h, #0x00 - add hl, bc + ld b, a +;utils.c:224: const unsigned char item = map[pos_x][pos_y]; + ldhl sp,#1 + ld a, (hl+) + ld e, a ld d, (hl) -;utils.c:221: if (_i >= 64) { - ld a, d - sub a, #0x40 + ld l, b + ld h, #0x00 + add hl, de + ld e, l + ld d, h + ld a, (de) +;utils.c:225: if (item >= 64) { + cp a, #0x40 jr C, 00107$ -;utils.c:222: add_item(_i); - push hl +;utils.c:226: add_item(item, pos_x, pos_y); + push bc push bc - push de - push de inc sp - call _add_item + ldhl sp, #3 + ld h, (hl) +; spillPairReg hl +; spillPairReg hl + push hl inc sp - pop de - pop bc - pop hl -;utils.c:224: map[pos_x][pos_y] = _i - 64; - ld a, d - add a, #0xc0 - ld (hl), a -;utils.c:225: display_map(); - push bc + push af + inc sp + call _add_item + add sp, #3 call _display_map pop bc 00107$: -;utils.c:217: for (char y = -3; y <= -1; y++) { - ldhl sp, #1 - inc (hl) +;utils.c:221: for (char y = -3; y <= -1; y++) { + inc c jr 00106$ 00110$: -;utils.c:216: for (char x = -2; x <= 0; x++) - ldhl sp, #0 +;utils.c:220: for (char x = -2; x <= 0; x++) + ldhl sp, #3 inc (hl) - jr 00109$ + jp 00109$ 00111$: -;utils.c:228: } - inc sp - inc sp +;utils.c:230: } + add sp, #4 ret -;utils.c:230: void attack() {} +;utils.c:232: void attack() {} ; --------------------------------- ; Function attack ; --------------------------------- _attack:: ret -;utils.c:232: void update_position(unsigned char j) { +;utils.c:234: void update_position(unsigned char j) { ; --------------------------------- ; Function update_position ; --------------------------------- _update_position:: add sp, #-14 -;utils.c:233: bool update = false; +;utils.c:235: bool update = false; ldhl sp, #0 ld (hl), #0x00 -;utils.c:234: unsigned char _x = p.x[0]; +;utils.c:236: unsigned char _x = p.x[0]; ld a, (#_p + 0) ldhl sp, #12 ld (hl), a -;utils.c:235: unsigned char _y = p.y[0]; +;utils.c:237: unsigned char _y = p.y[0]; ld de, #(_p + 8) ld a, (de) ldhl sp, #1 @@ -10386,39 +10418,39 @@ _update_position:: ld a, (hl) ldhl sp, #13 ld (hl), a -;utils.c:236: if (j & J_RIGHT) +;utils.c:238: if (j & J_RIGHT) ldhl sp, #16 ld c, (hl) bit 0, c jr Z, 00104$ -;utils.c:237: _x++; +;utils.c:239: _x++; ldhl sp, #12 inc (hl) jr 00105$ 00104$: -;utils.c:238: else if (j & J_LEFT) +;utils.c:240: else if (j & J_LEFT) bit 1, c jr Z, 00105$ -;utils.c:239: _x--; +;utils.c:241: _x--; ldhl sp, #12 dec (hl) 00105$: -;utils.c:240: if (j & J_UP) +;utils.c:242: if (j & J_UP) bit 2, c jr Z, 00109$ -;utils.c:241: _y--; +;utils.c:243: _y--; ldhl sp, #13 dec (hl) jr 00110$ 00109$: -;utils.c:242: else if (j & J_DOWN) +;utils.c:244: else if (j & J_DOWN) bit 3, c jr Z, 00110$ -;utils.c:243: _y++; +;utils.c:245: _y++; ldhl sp, #13 inc (hl) 00110$: -;utils.c:244: if (_x != p.x[0]) { +;utils.c:246: if (_x != p.x[0]) { ld de, #_p ld a, (de) ldhl sp, #5 @@ -10440,9 +10472,9 @@ _update_position:: ld (hl+), a ld (hl+), a ld (hl), a -;utils.c:247: p.steps++; +;utils.c:249: p.steps++; ld bc, #_p + 16 -;utils.c:244: if (_x != p.x[0]) { +;utils.c:246: if (_x != p.x[0]) { ldhl sp, #5 ld a, (hl) ldhl sp, #9 @@ -10464,7 +10496,7 @@ _update_position:: sub a, (hl) jr Z, 00114$ 00159$: -;utils.c:245: p.x[1] = p.x[0]; +;utils.c:247: p.x[1] = p.x[0]; ld de, #(_p + 4) ldhl sp, #5 ld a, (hl+) @@ -10476,7 +10508,7 @@ _update_position:: ld a, (hl+) ld (de), a inc de -;utils.c:246: p.x[0] = _x; +;utils.c:248: p.x[0] = _x; ld a, (hl+) ld (de), a ld de, #_p @@ -10491,7 +10523,7 @@ _update_position:: inc de ld a, (hl) ld (de), a -;utils.c:247: p.steps++; +;utils.c:249: p.steps++; ld e, c ld d, b ld a, (de) @@ -10547,12 +10579,12 @@ _update_position:: inc bc ld a, (hl) ld (bc), a -;utils.c:248: update = true; +;utils.c:250: update = true; ldhl sp, #0 ld (hl), #0x01 jp 00115$ 00114$: -;utils.c:249: } else if (_y != p.y[0]) { +;utils.c:251: } else if (_y != p.y[0]) { ldhl sp, #13 ld a, (hl) ldhl sp, #10 @@ -10582,7 +10614,7 @@ _update_position:: sub a, (hl) jr Z, 00115$ 00160$: -;utils.c:252: p.y[1] = p.y[0]; +;utils.c:254: p.y[1] = p.y[0]; ld de, #(_p + 12) ldhl sp, #1 ld a, (hl+) @@ -10596,7 +10628,7 @@ _update_position:: inc de ld a, (hl) ld (de), a -;utils.c:253: p.y[0] = _y; +;utils.c:255: p.y[0] = _y; ld de, #(_p + 8) ldhl sp, #10 ld a, (hl+) @@ -10610,7 +10642,7 @@ _update_position:: inc de ld a, (hl) ld (de), a -;utils.c:254: p.steps++; +;utils.c:256: p.steps++; ld e, c ld d, b ld a, (de) @@ -10666,21 +10698,21 @@ _update_position:: inc bc ld a, (hl) ld (bc), a -;utils.c:255: update = true; +;utils.c:257: update = true; ldhl sp, #0 ld (hl), #0x01 00115$: -;utils.c:257: if (update == true) { +;utils.c:259: if (update == true) { ldhl sp, #0 ld a, (hl) dec a jr NZ, 00118$ -;utils.c:258: generate_map_side(); +;utils.c:260: generate_map_side(); call _generate_map_side -;utils.c:259: display_map(); +;utils.c:261: display_map(); call _display_map 00118$: -;utils.c:261: } +;utils.c:263: } add sp, #14 ret ;main.c:12: void main() { diff --git a/utils.c b/utils.c index 50e3c88..7213a44 100644 --- a/utils.c +++ b/utils.c @@ -194,12 +194,16 @@ void show_menu() { printf("\n\n\trandom:\t%u", noise(p.x[0], p.y[0])); } -void add_item(const unsigned char item) { +void add_item(const unsigned char item, const unsigned char x, + const unsigned char y) { // fill primary or replace secondary - if (p.weapons[0] == -1) + if (p.weapons[0] == -1) { p.weapons[0] = item; - else + } else { p.weapons[1] = item; + } + // item - 64 is the terrain tile + map[x][y] = item - 64; } void change_item() { @@ -217,11 +221,9 @@ void interact() { for (char y = -3; y <= -1; y++) { const unsigned char pos_x = x + center_x / sprite_size; const unsigned char pos_y = y + center_y / sprite_size; - const unsigned char _i = map[pos_x][pos_y]; - if (_i >= 64) { - add_item(_i); - // item - 64 is the correct terrain tile - map[pos_x][pos_y] = _i - 64; + const unsigned char item = map[pos_x][pos_y]; + if (item >= 64) { + add_item(item, pos_x, pos_y); display_map(); } }