Author Topic: The User Program Variable  (Read 2858 times)

0 Members and 1 Guest are viewing this topic.

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
The User Program Variable
« on: April 28, 2012, 10:02:53 pm »
So, I have started learning Z80 ASM again and I have a question...
In a user program, I know that the first two bytes are size bites, are the next 8 or less the name?, if it is is it null terminated.
Then say I wanted to get the first "line" of the program how would I do that, I've been doing some testing and it hasnt worked out( I think because of something in the first two lines of what I wrote).
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: The User Program Variable
« Reply #1 on: April 28, 2012, 10:05:08 pm »
In a user program, I know that the first two bytes are size bites, are the next 8 or less the name?, if it is is it null terminated.
Nope, the data comes right after the size bytes.

Variable names and flags aren't part of any variable except when it's archived. All that stuff goes in the VAT. (That's why if you have two VAT entries pointing to the same address, you can edit one variable and watch the other change too :D)
« Last Edit: April 28, 2012, 10:06:03 pm by Deep Thought »




Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: The User Program Variable
« Reply #2 on: April 28, 2012, 10:40:48 pm »
If you want to edit the first byte, you can try this:
Code: [Select]
     ld hl,NAME
     rst rMOV9TOOP1
     bcall(_ChkFindSym)
     ret c                ;The program doesn't exist, so exit
     ex de,hl
;Just checking to make sure the size isn't zero, otherwise it will edit unknown data
     ld a,(hl)
     inc hl
     or (hl)
     ret z
     inc hl
     ld (hl),30h     ;or whatever byte you want
     ret
NAME:
     .db 5,"HELLO",0 ;5 means program, 0 terminates
If you want to see more complicated code that edits the first byte of the second line:
Code: [Select]
     ld hl,NAME
     rst rMOV9TOOP1
     bcall(_ChkFindSym)
     ret c
     ex de,hl
;Just checking to make sure the size isn't zero, otherwise it will edit unknown data
     ld c,(hl)
     ld a,c
     inc hl
     or (hl)
     ret z
     ld b,(hl)
     inc hl
;BC is now the size of the program
;HL points to the data
     ld a,3Fh        ;3Fh is the newline token
     cpir            ;Search a max of BC bytes at HL for the first instance of A
     ret po          ;No bytes left in the program
;HL now points to the byte after the start of the second line
;Make sure it isn't another newline. (means Line 2 was empty)
     cp (hl)
     ret z
     ld (hl),30h     ;or whatever byte you want
     ret
NAME:
     .db 5,"HELLO",0

Offline jwalker

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 660
  • Rating: +13/-0
  • Almost everything I have released includes a 'WZ'
    • View Profile
Re: The User Program Variable
« Reply #3 on: April 29, 2012, 03:11:22 pm »
Ok, It works so thanks
« Last Edit: April 29, 2012, 05:50:15 pm by jwalker »
<a href="http://www.nerdtests.com/ft_cg.php?im">
<img src="http://www.nerdtests.com/images/ft/cg.php?val=9612" alt="My computer geek score is greater than 41% of all people in the world! How do you compare? Click here to find out!"> </a>

Support Casio-Scene against the attacks of matt @ matpac.co.uk ! For more information: Casio-Scene shuts down & Matt actions threads