Jump to content


source code for JSW

members only source code jsw

42 replies to this topic

#41 IRF


    Advanced Member

  • Contributor
  • 4,202 posts

Posted 11 July 2019 - 05:59 PM

For consistency and elegance, wouldn't it be best, in the case of operations which are self-modified by the code, to insert NOP command(s) (opcode #00) wherever they appear in the source code listing?  That way the default value held at the pertinent address(es) would be zero, as is the case with the operands that are self-modified.


e.g. For your example of a direction label, list it in the source code as:


S_M_C_direction: NOP


And then use: LD A, #3C [for INC A] or LD A, #3D [for DEC A] or XOR A [to restore the default NOP]

followed by: LD (S_M_C_direction), A

for movement in whichever direction (or no direction).

Edited by IRF, 11 July 2019 - 07:13 PM.

#42 Norman Sword

Norman Sword

    Advanced Member

  • Member
  • PipPipPip
  • 223 posts

Posted 11 July 2019 - 10:53 PM

 I would imagine you would end up with a large rule book.

example 1:-
S_M_C_counter1: equ $+1

    ld a,12

    inc a

    and 7
    or 8

   ld (S_M_C_counter1),a

here the value varies between 8 and 15:- your example has failed, we never have a value of zero in the variable


example 2:-


S_M_C_opcode: inc a


direction_switch equ $3c xor $3d          ; this is ("inc a") xor ("dec a")


   ld hl,S_M_C_opcode

   ld a,(hl)

   xor direction_switch

  ld (hl),a


here the opcode varies between either  "inc a" or "dec a". the code is switching direction. again never zero




The circumstances can change from once instance to another.

The S_M_C_ is alerting you to code that is modifying.

The $-$ is making the statement that the value will be changed before the opcode is executed.


In a lot of instances we must have an opcode or an initial value. In those cases the value is inserted or the opcode written out.


I suppose it is similar to saying a block move is always in this format:-

ld hl,source

ld de,destination

ld bc, count



when the reality says it is a lot of the time, but the variations are vast.





Edited by Norman Sword, 11 July 2019 - 11:35 PM.

#43 IRF


    Advanced Member

  • Contributor
  • 4,202 posts

Posted 12 July 2019 - 12:27 AM

Thanks Norman.

As it happens, in example 1, if the initial value held by S_M_C_counter1 was zero, then it would quickly be overwritten by 8 and then it would return to the intended pattern of the operand incrementing during each pass through the code (looping back from 15 to 8).
(The initial value of zero might have an adverse impact though, depending on the context - especially if the variable is picked up by the program before it is first modified. e.g. an out-of-range guardian crashing into a wall at the edge of a room?)

But I can see that in example 2, if you had a default value of zero stored at S_M_C_opcode, then execution of the code would never cause the labelled address to reach either of its intended operations (INC A or DEC A).
Instead, the address S_M_C_opcode would toggle between acting as a NOP (00), and the 01 opcode - which would have the unintended effect of picking up the next pair of bytes which follow on from S_M_C_opcode, and loading those values into the BC register-pair!

Edited by IRF, 12 July 2019 - 12:41 AM.

Also tagged with one or more of these keywords: members only, source code, jsw

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users