SD: Re: What's wrong with this code?


[Prev][Index][Thread]

SD: Re: What's wrong with this code?




This is a reply l got as assistance to assembly.  lt helps, but l still have
more questions.  The bottom of this mail explained to me how to get text to
display at a certain location.  So, if l wanted to display text at hex
locations 10 (_penRow) and 20 (_penCol) and the text to display is "HELLO",
what would be the exact syntax?


<< Thank you for your lengthy reply.  this really helps me to understand
assembly much better.  The reason that l had the pen locations at $40 was when
l was trying to test to see what made it display in the wrong location.  When
l write this:
 ld hl,40
 does this load a decimal 40 or a hex $40?
 
 Also, l have questions about loading strings of characters, numbers, and
other things into the OP(1-6) registers (let's assume from hl or a).  Also l
understand how to create program variables (or how to name them if l knew how
to load into OP1) but how can l edit the contents or change their value?  
 
 Also, would this overwrite the existing variable (while just messing around
with the _call for creating a new program, string, real, etc. l ended up with
three real numbers, 20 strings, and two pic variables all named "A" because of
however many times l ran the program with the same code).  
 
 Also, when drawing the lines l sometimes have to have the _call lline command
twice just to execute the line function.  And when drawing lpoints it will
display not one but two or three pixels close to each other.
 
 In a message dated 97-12-12 22:44:21 EST, you write:
 
 << There are a couple of problems that I can see.
  First, the memory locations _penCol and _penRow
  are only 1 byte wide each, and the instruction
  ld (_pen*),hl is going to write 2 bytes into
  memory beginning at each location.  Since both
  _penCol and _penRow are defined right next to
  each other in memory (with _penCol at byte
  #C37C and _penRow at #C37D), there are two ways
  that you can get the data you want into them.
  The first is to use 1 byte ld instructions to
  fill them as in:
  ld a,$40 ; this loads the A reg with hex 40
  ld (_penCol),a ; store 1 byte A reg at #C37C
  ld a,$40 ; isn't there already a $40 in A?
  ld (_penRow),a ; store 1 byte A reg at #C37D
  
  or a more efficient way...
  
  ld hl,$4040 ; load H and L regs with $40
  ld (_penCol),hl ; store 2 byte HL reg at #C37C
  
  note that the second method stores the L reg at
  #C37C and the H reg at #C37D.  If you had wanted
  to store a Row=20 and Col=0, you could have done
  ld hl,$2000 ; load H=20 and L=00
  ld (_penCol),hl ;_penCol=L and _penRow=20
  
  Note that the second method only works because
  we happen to know that penCol and penRow are in
  two consecutive bytes of memory.  If they had
  not been together, you would have had to use the
  first method to access each byte separately.
  Also note that when loading or storing the HL
  register pair, that the L (low order byte)
  register byte goes or comes from the first byte
  of the memory location, and the H (high order
  byte) register byte goes or comes from the
  following memory location.
  
  A second item that may or may not be a problem
  is that you are setting both the row and col
  for each item you are displaying. This is going
  to result in a display that looks something like
  
  ---------------------
  X-------------------X
  X---FILE------------X
  X-------------------X
  X--------START------X
  X-------------------X
  
  The final problem I see is that you put your
  "ret" command AFTER your data definitions.
  This means that after the Z80 executes the
  ld hl,FILE
  call _vputs
  commands, it will then try to execute the
  next byte it sees which will be your letter "S"
  in "START" which happens to translate into the
  command "ld d,e".  It will also happily try to
  execute the rest of your data string which is
  what caused the garbage on the screen and the
  hung calculator.  You can fix this by putting
  the "ret" command on the line following the
  "call _vputs" command and before the START:
  label. >>
  >>