<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=Z80%3AVAT_Routines</id>
	<title>Z80:VAT Routines - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=Z80%3AVAT_Routines"/>
	<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=Z80:VAT_Routines&amp;action=history"/>
	<updated>2026-06-03T05:43:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=Z80:VAT_Routines&amp;diff=136&amp;oldid=prev</id>
		<title>KermMartian: Created page with &quot;The VAT is the wonderful place in RAM where information about every variable can be found. The OS offers a handful of bcalls for dealing with the VAT, but sometimes they may s...&quot;</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=Z80:VAT_Routines&amp;diff=136&amp;oldid=prev"/>
		<updated>2016-02-05T06:40:31Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;The VAT is the wonderful place in RAM where information about every variable can be found. The OS offers a handful of bcalls for dealing with the VAT, but sometimes they may s...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The VAT is the wonderful place in RAM where information about every variable can be found. The OS offers a handful of bcalls for dealing with the VAT, but sometimes they may seem too slow or too limited. Here are some routines that might be useful.&lt;br /&gt;
&lt;br /&gt;
= SearchVarBC =&lt;br /&gt;
This clever routine allows you to search for an OS named variable (like Pic1, Str7, and the like) whose name is in BC. For example, if BC was 0160h, it would look for Pic2 since the hex for Pic2 is 6001h. It is also pretty small and fast and has the same outputs as rFindSym&lt;br /&gt;
&lt;br /&gt;
    SearchVarBC:&lt;br /&gt;
         ld hl,$FE60       ;This is at the end of the VAT (or beginning, depending on how you look at it)&lt;br /&gt;
    SVBCLoop:&lt;br /&gt;
         ld a,c            ;Check the first byte of the name&lt;br /&gt;
         cp (hl)           ;Compare to the byte at HL&lt;br /&gt;
         dec hl            ;HL points to the next byte of the name&lt;br /&gt;
         jr nz,VarNoMatch  ;No match, so check the next var&lt;br /&gt;
         ld a,b&lt;br /&gt;
         cp (hl)&lt;br /&gt;
         jr z,VarMatch     ;Yay, both bytes matched&lt;br /&gt;
    VarNoMatch:&lt;br /&gt;
         ld de,-8&lt;br /&gt;
         add hl,de         ;We essentially subtracted 8 from HL, pointing to the next var&lt;br /&gt;
         ex de,hl          ;Swap HL and DE, we need to check if we are at the end of the VAT&lt;br /&gt;
         ld hl,(9830h)     ;This RAM address holds the location of the end of the symbol VAT&lt;br /&gt;
         sbc hl,de         ;Subtract HL and DE. Normally, we need to worry about the c flag, but here we don&amp;#039;t (c is always set, subtracting 1 more from HL). If HL=DE, then HL-DE=0, so the z flag will be set&lt;br /&gt;
         ex de,hl          ;re swap HL and DE, so HL is appropriate&lt;br /&gt;
         scf               ;Set Carry Flag (we just do this to pass info to the callee)&lt;br /&gt;
         jr nz,SVBCLoop&lt;br /&gt;
    VarMatch:&lt;br /&gt;
         ld c,3            ;Length of var name&lt;br /&gt;
         inc hl&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld b,(hl)         ;flash page the var is on&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld d,(hl)         ;High byte of the var address&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld e,(hl)         ;low byte of the var address&lt;br /&gt;
         inc hl&lt;br /&gt;
         inc hl&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld a,(hl)         ;The variable type&lt;br /&gt;
         ret&lt;br /&gt;
&lt;br /&gt;
= ChkFindVar =&lt;br /&gt;
This routine is for searching for lists, programs, appvars, and other user-defined variables. This has a subroutine that allows you to use another RAM location other than OP1. This is useful as you won&amp;#039;t need to copy the name to OP1. Combined with SearchVarBC, an alternative to bcall(_ChkFindSym) can be created, with the same outputs.&lt;br /&gt;
&lt;br /&gt;
    ;===============================================================&lt;br /&gt;
    ChkFindVar:&lt;br /&gt;
    ;===============================================================&lt;br /&gt;
    ;Inputs:&lt;br /&gt;
    ;     OP1 contains the var name to search for&lt;br /&gt;
    ;Outputs:&lt;br /&gt;
    ;     A is the type&lt;br /&gt;
    ;     B is the flashpage&lt;br /&gt;
    ;     C is the name length&lt;br /&gt;
    ;     DE points to the size bytes&lt;br /&gt;
    ;     HL points to the symentry&lt;br /&gt;
    ;Destroys:&lt;br /&gt;
    ;     Last 2 bytes in OP1&lt;br /&gt;
    ;===============================================================&lt;br /&gt;
         ld de,8478h&lt;br /&gt;
    ChkFindVarAtDE:    ;(you can call here instead with DE pointing to the var name)&lt;br /&gt;
         ld bc,9&lt;br /&gt;
         ld a,(de)&lt;br /&gt;
         and 1Fh&lt;br /&gt;
         ld (de),a&lt;br /&gt;
         ld hl,OP2-1&lt;br /&gt;
         cp 5&lt;br /&gt;
         jr nz,$+4&lt;br /&gt;
         ld (hl),6&lt;br /&gt;
         cp 6&lt;br /&gt;
         jr nz,$+4&lt;br /&gt;
         ld (hl),5&lt;br /&gt;
         ex de,hl&lt;br /&gt;
         ld a,b&lt;br /&gt;
         push hl&lt;br /&gt;
         cpir&lt;br /&gt;
         jr z,$+3&lt;br /&gt;
           dec c&lt;br /&gt;
         ld a,7&lt;br /&gt;
         sub c&lt;br /&gt;
         ld (OP2-2),a&lt;br /&gt;
         pop hl&lt;br /&gt;
         rst 10h&lt;br /&gt;
         ld hl,(9830h)&lt;br /&gt;
    CompareOverLoop:&lt;br /&gt;
         ld de,8478h&lt;br /&gt;
    CompareLoop:&lt;br /&gt;
         ld bc,(982Eh)&lt;br /&gt;
         or a&lt;br /&gt;
         sbc hl,bc&lt;br /&gt;
         add hl,bc&lt;br /&gt;
         ccf&lt;br /&gt;
         ret z&lt;br /&gt;
         ld a,(de)&lt;br /&gt;
         ld bc,-6&lt;br /&gt;
         cp (hl)&lt;br /&gt;
         jr z,TypeMatch&lt;br /&gt;
         ld a,(OP2-1)&lt;br /&gt;
         cp (hl)&lt;br /&gt;
         jr z,TypeMatch&lt;br /&gt;
           add hl,bc&lt;br /&gt;
           ld c,(hl)&lt;br /&gt;
           inc c&lt;br /&gt;
           inc b&lt;br /&gt;
           or a&lt;br /&gt;
           sbc hl,bc&lt;br /&gt;
           jr CompareLoop&lt;br /&gt;
    NotMatch:&lt;br /&gt;
       pop af&lt;br /&gt;
       or a&lt;br /&gt;
       sbc hl,bc&lt;br /&gt;
       jr CompareOverLoop&lt;br /&gt;
    TypeMatch:&lt;br /&gt;
         add hl,bc&lt;br /&gt;
         push hl&lt;br /&gt;
         ld a,(OP2-2)&lt;br /&gt;
         ld c,(hl)&lt;br /&gt;
         dec hl&lt;br /&gt;
         inc b&lt;br /&gt;
         cp c&lt;br /&gt;
         jr nz,NotMatch&lt;br /&gt;
         inc de&lt;br /&gt;
    CompareName:&lt;br /&gt;
         ld a,(de)&lt;br /&gt;
         inc de&lt;br /&gt;
         cpd&lt;br /&gt;
         jr nz,NotMatch&lt;br /&gt;
         jp pe,CompareName&lt;br /&gt;
    FoundVar:&lt;br /&gt;
         pop hl&lt;br /&gt;
         ld c,(hl)&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld b,(hl)&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld d,(hl)&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld e,(hl)&lt;br /&gt;
         inc hl&lt;br /&gt;
         inc hl&lt;br /&gt;
         inc hl&lt;br /&gt;
         ld a,(hl)&lt;br /&gt;
         ret&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{lowercase}}&lt;br /&gt;
[[Category:Z80 Assembly]]&lt;br /&gt;
[[Category:Z80 Heaven]]&lt;/div&gt;</summary>
		<author><name>KermMartian</name></author>
	</entry>
</feed>