83Plus:BCALLs:8030

From WikiTI
Jump to: navigation, search

Synopsis

Unofficial Name: FindGroupedField

BCALL Address: 8030

Search for a given field within a "group."

Inputs

  • AHL = address (first type byte) to start searching
  • DE = field to search for (e.g. 0A10 to search for the calculator ID)

Outputs

  • HL = address of the first data byte (not the first type byte) of the first matching field
  • BC = length of the field
  • NZ set if not found.

Destroys

Comments

This routine will stop when it reaches any field of a different major field type. Unless you are explicitly searching for a minor-type-1 field, it will also stop when it reaches one.

The behavior of this routine is perhaps best illustrated by an example. Public keys are stored on the certificate page as a series of two fields: an 071 field which contains the key ID (e.g. 0104) and an 073 field which contains the key itself.

So to find a particular public key, you want to first scan through the 071 fields to find the key ID you're looking for. You then want to find the first 073 field following this one, but you want to stop before you get to another 071 field, or any other unrelated field. "Unrelated" in this case means non-major-type-7, since only major-type-7 fields are allowed within the public key block.

Unlike most of the field search routines, this routine calls GetFieldSize after finding the field, so HL points to the first data byte and BC is the length of the field.

Example

Find public key number 0104 (requires Flash write-enabled):

 ; Find the certificate patch block
 ld de,0300h
 B_CALL FindFirstCertificateField
 ret nz

 ; Find the public key block (a subfield of the certificate patch block)
 ld a,7eh           ; or 1e, or 3e, depending on model
 ld de,0700h
 B_CALL FindSubField
 ret nz

 ; Enter the public key block
 inc hl
 ld a,7eh
 B_CALL GetFieldSize

 ; Find our public key
Loop:
 ld a,7eh
 ld de,0710h
 B_CALL FindGroupedField
 ret nz
 ; HL -> key number, BC = length thereof
 ; check if it is 0104
 ld a,7eh
 B_CALL LoadAIndPaged
 cp 1
 jr nz,Skip
 inc hl
 dec bc
 ld a,7eh
 B_CALL LoadAIndPaged
 cp 4
 jr nz,Skip
 inc hl
 dec bc
 ld a,b
 or c
 jr z,Found0104
Skip:
 add hl,bc
 jr Loop
Found0104:
 ld a,7eh
 ld de,0730h
 B_CALL FindGroupedField
 ; HL -> modulus; BC = length