mirror of https://github.com/pret/pokecrystal.git
Use maskbits more, and clarify its usage
This commit is contained in:
parent
22b607b664
commit
cc95d1208d
|
@ -105,9 +105,16 @@
|
||||||
const MAPRADIO_LETS_ALL_SING
|
const MAPRADIO_LETS_ALL_SING
|
||||||
const MAPRADIO_ROCKET
|
const MAPRADIO_ROCKET
|
||||||
|
|
||||||
|
; These tables in engine/radio.asm are all sized to a power of 2
|
||||||
|
; so there's no need for a rejection sampling loop
|
||||||
|
NUM_OAKS_MON_TALK_ADVERBS EQU 16 ; OaksPkmnTalk8.Adverbs
|
||||||
|
NUM_OAKS_MON_TALK_ADJECTIVES EQU 16 ; OaksPkmnTalk9.Adjectives
|
||||||
|
NUM_PNP_PEOPLE_ADJECTIVES EQU 16 ; PeoplePlaces5.Adjectives
|
||||||
|
NUM_PNP_PLACES_ADJECTIVES EQU 16 ; PeoplePlaces7.Adjectives
|
||||||
|
|
||||||
; BuenasPasswordTable sizes (see data/radio/buenas_passwords.asm)
|
; BuenasPasswordTable sizes (see data/radio/buenas_passwords.asm)
|
||||||
NUM_PASSWORD_CATEGORIES EQU 11
|
NUM_PASSWORD_CATEGORIES EQU 11
|
||||||
NUM_PASSWORDS_PER_CATEGORY EQU 3
|
NUM_PASSWORDS_PER_CATEGORY EQU 3
|
||||||
|
|
||||||
; GetBuenasPassword.StringFunctionJumpTable indexes (see engine/radio.asm)
|
; GetBuenasPassword.StringFunctionJumpTable indexes (see engine/radio.asm)
|
||||||
const_def
|
const_def
|
||||||
|
|
|
@ -348,11 +348,13 @@ OPT_MaryText1:
|
||||||
db "@"
|
db "@"
|
||||||
|
|
||||||
OaksPkmnTalk8:
|
OaksPkmnTalk8:
|
||||||
|
; 0-15 are all valid indexes into .Adverbs,
|
||||||
|
; so no need for a retry loop
|
||||||
call Random
|
call Random
|
||||||
and $f ; 0-15 are all the valid indexes into .Descriptors
|
maskbits NUM_OAKS_MON_TALK_ADVERBS +- 1
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
ld hl, .Descriptors
|
ld hl, .Adverbs
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
|
@ -361,7 +363,8 @@ OaksPkmnTalk8:
|
||||||
ld a, OAKS_POKEMON_TALK_9
|
ld a, OAKS_POKEMON_TALK_9
|
||||||
jp NextRadioLine
|
jp NextRadioLine
|
||||||
|
|
||||||
.Descriptors:
|
.Adverbs:
|
||||||
|
; there are NUM_OAKS_MON_TALK_ADVERBS entries
|
||||||
dw .sweetadorably
|
dw .sweetadorably
|
||||||
dw .wigglyslickly
|
dw .wigglyslickly
|
||||||
dw .aptlynamed
|
dw .aptlynamed
|
||||||
|
@ -460,11 +463,13 @@ OaksPkmnTalk8:
|
||||||
db "@"
|
db "@"
|
||||||
|
|
||||||
OaksPkmnTalk9:
|
OaksPkmnTalk9:
|
||||||
|
; 0-15 are all valid indexes into .Adjectives,
|
||||||
|
; so no need for a retry loop
|
||||||
call Random
|
call Random
|
||||||
and $f ; 0-15 are all the valid indexes into .Descriptors
|
maskbits NUM_OAKS_MON_TALK_ADJECTIVES +- 1
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
ld hl, .Descriptors
|
ld hl, .Adjectives
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
|
@ -481,7 +486,8 @@ OaksPkmnTalk9:
|
||||||
.ok
|
.ok
|
||||||
jp NextRadioLine
|
jp NextRadioLine
|
||||||
|
|
||||||
.Descriptors:
|
.Adjectives:
|
||||||
|
; there are NUM_OAKS_MON_TALK_ADJECTIVES entries
|
||||||
dw .cute
|
dw .cute
|
||||||
dw .weird
|
dw .weird
|
||||||
dw .pleasant
|
dw .pleasant
|
||||||
|
@ -1158,7 +1164,7 @@ PnP_Text3:
|
||||||
|
|
||||||
PeoplePlaces4: ; People
|
PeoplePlaces4: ; People
|
||||||
call Random
|
call Random
|
||||||
and $7f
|
maskbits NUM_TRAINER_CLASSES +- 1
|
||||||
inc a
|
inc a
|
||||||
cp NUM_TRAINER_CLASSES - 1
|
cp NUM_TRAINER_CLASSES - 1
|
||||||
jr nc, PeoplePlaces4
|
jr nc, PeoplePlaces4
|
||||||
|
@ -1199,11 +1205,13 @@ PnP_Text4:
|
||||||
db "@"
|
db "@"
|
||||||
|
|
||||||
PeoplePlaces5:
|
PeoplePlaces5:
|
||||||
|
; 0-15 are all valid indexes into .Adjectives,
|
||||||
|
; so no need for a retry loop
|
||||||
call Random
|
call Random
|
||||||
and $f ; 0-15 are all the valid indexes into .Descriptors
|
maskbits NUM_PNP_PEOPLE_ADJECTIVES +- 1
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
ld hl, .Descriptors
|
ld hl, .Adjectives
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
|
@ -1221,7 +1229,8 @@ PeoplePlaces5:
|
||||||
.ok
|
.ok
|
||||||
jp NextRadioLine
|
jp NextRadioLine
|
||||||
|
|
||||||
.Descriptors:
|
.Adjectives:
|
||||||
|
; there are NUM_PNP_PEOPLE_ADJECTIVES entries
|
||||||
dw PnP_cute
|
dw PnP_cute
|
||||||
dw PnP_lazy
|
dw PnP_lazy
|
||||||
dw PnP_happy
|
dw PnP_happy
|
||||||
|
@ -1346,11 +1355,13 @@ PnP_Text5:
|
||||||
db "@"
|
db "@"
|
||||||
|
|
||||||
PeoplePlaces7:
|
PeoplePlaces7:
|
||||||
|
; 0-15 are all valid indexes into .Adjectives,
|
||||||
|
; so no need for a retry loop
|
||||||
call Random
|
call Random
|
||||||
and $f ; 0-15 are all the valid indexes into .Descriptors
|
maskbits NUM_PNP_PLACES_ADJECTIVES +- 1
|
||||||
ld e, a
|
ld e, a
|
||||||
ld d, 0
|
ld d, 0
|
||||||
ld hl, .Descriptors
|
ld hl, .Adjectives
|
||||||
add hl, de
|
add hl, de
|
||||||
add hl, de
|
add hl, de
|
||||||
ld a, [hli]
|
ld a, [hli]
|
||||||
|
@ -1369,7 +1380,8 @@ PeoplePlaces7:
|
||||||
.ok
|
.ok
|
||||||
jp PrintRadioLine
|
jp PrintRadioLine
|
||||||
|
|
||||||
.Descriptors:
|
.Adjectives:
|
||||||
|
; there are NUM_PNP_PLACES_ADJECTIVES entries
|
||||||
dw PnP_cute
|
dw PnP_cute
|
||||||
dw PnP_lazy
|
dw PnP_lazy
|
||||||
dw PnP_happy
|
dw PnP_happy
|
||||||
|
@ -1553,7 +1565,7 @@ BuenasPassword4:
|
||||||
; There are only 11 groups to choose from.
|
; There are only 11 groups to choose from.
|
||||||
.greater_than_11
|
.greater_than_11
|
||||||
call Random
|
call Random
|
||||||
maskbits NUM_PASSWORD_CATEGORIES
|
maskbits NUM_PASSWORD_CATEGORIES +- 1
|
||||||
cp NUM_PASSWORD_CATEGORIES
|
cp NUM_PASSWORD_CATEGORIES
|
||||||
jr nc, .greater_than_11
|
jr nc, .greater_than_11
|
||||||
; Store it in the high nybble of e.
|
; Store it in the high nybble of e.
|
||||||
|
@ -1562,7 +1574,7 @@ BuenasPassword4:
|
||||||
; For each group, choose one of the three passwords.
|
; For each group, choose one of the three passwords.
|
||||||
.greater_than_three
|
.greater_than_three
|
||||||
call Random
|
call Random
|
||||||
maskbits NUM_PASSWORDS_PER_CATEGORY
|
maskbits NUM_PASSWORDS_PER_CATEGORY +- 1
|
||||||
cp NUM_PASSWORDS_PER_CATEGORY
|
cp NUM_PASSWORDS_PER_CATEGORY
|
||||||
jr nc, .greater_than_three
|
jr nc, .greater_than_three
|
||||||
; The high nybble of wBuenasPassword will now contain the password group index, and the low nybble contains the actual password.
|
; The high nybble of wBuenasPassword will now contain the password group index, and the low nybble contains the actual password.
|
||||||
|
|
|
@ -39,15 +39,17 @@ ENDM
|
||||||
mobile EQUS "ret"
|
mobile EQUS "ret"
|
||||||
|
|
||||||
maskbits: MACRO
|
maskbits: MACRO
|
||||||
|
; masks just enough bits to cover the argument
|
||||||
|
; e.g. "maskbits %00010100" becomes "and %00011111"
|
||||||
; example usage in rejection sampling:
|
; example usage in rejection sampling:
|
||||||
; .loop
|
; .loop
|
||||||
; call Random
|
; call Random
|
||||||
; maskbits 30
|
; maskbits 30 +- 1
|
||||||
; cp 30
|
; cp 30
|
||||||
; jr nc, .loop
|
; jr nc, .loop
|
||||||
x = 1
|
x = 1
|
||||||
rept 8
|
rept 8
|
||||||
if \1 > x
|
if x < (\1)
|
||||||
x = (x + 1) * 2 +- 1
|
x = (x + 1) * 2 +- 1
|
||||||
endc
|
endc
|
||||||
endr
|
endr
|
||||||
|
|
Loading…
Reference in New Issue