CPU-Z80-Disassembler

 view release on metacpan or  search on metacpan

t/data/zx48_base.asm  view on Meta::CPAN

        defb 0x01               ; ;exchange      sx, sy.
        defb 0x31               ; ;duplicate     sx, sy, sy.
        defb 0xE0               ; ;get-mem-0     sx, sy, sy, sx.
        defb 0x01               ; ;exchange      sx, sy, sx, sy.
        defb 0x31               ; ;duplicate     sx, sy, sx, sy, sy.
        defb 0xE0               ; ;get-mem-0     sx, sy, sx, sy, sy, sx.

;   Locations mem-1 and mem-2 are the relative x and y values which are updated
;   after each line is drawn. Since we are drawing a vertical line then the rx
;   value in mem-1 is zero and the ry value in mem-2 is the full chord.

        defb 0xA0               ; ;stk-zero      sx, sy, sx, sy, sy, sx, 0.
        defb 0xC1               ; ;st-mem-1      sx, sy, sx, sy, sy, sx, 0.
        defb 0x02               ; ;delete        sx, sy, sx, sy, sy, sx.

;   Although the three pairs of x/y values are the same for a circle, they 
;   will be labelled terminating, absolute and start coordinates.

        defb 0x38               ; ;end-calc      tx, ty, ax, ay, sy, sx.

;   Use the exponent manipulating trick again to double the value of mem-2.

        inc (iy+0x62)           ; Increment MEM-2-1st doubling half chord.

;   Note. this first vertical chord is drawn at the radius so circles are
;   slightly displaced to the right.
;   It is only necessary to place the values (sx) and (sy) in the system 
;   variable COORDS to ensure that drawing commences at the correct pixel.
;   Note. a couple of LD (COORDS),A instructions would have been quicker, and 
;   simpler, than using LD (COORDS),HL.

        call FIND_INT1          ; routine FIND-INT1 fetches sx from stack to A.

        ld l,a                  ; place X value in L.
        push hl                 ; save the holding register.

        call FIND_INT1          ; routine FIND-INT1 fetches sy to A

        pop hl                  ; restore the holding register.
        ld h,a                  ; and place y value in high byte.

        ld (0x5C7D),hl          ; Update the COORDS system variable.
                                ;               tx, ty, ax, ay.

        pop bc                  ; restore the chord count
                                ; values 4,8,12,16,20,24,28 or 32.

        jp DRW_STEPS            ; forward to DRW-STEPS
                                ;               tx, ty, ax, ay.

;   Note. the jump to DRW-STEPS is just to decrement B and jump into the 
;   middle of the arc-drawing loop. The arc count which includes the first 
;   vertical arc draws one less than the perceived number of arcs. 
;   The final arc offsets are obtained by subtracting the final COORDS value
;   from the initial sx and sy values which are kept at the base of the
;   calculator stack throughout the arc loop. 
;   This ensures that the final line finishes exactly at the starting pixel 
;   removing the possibility of any inaccuracy.
;   Since the initial sx and sy values are not required until the final arc
;   is drawn, they are not shown until then.
;   As the calculator stack is quite busy, only the active parts are shown in 
;   each section.


; ------------------
; THE 'DRAW' COMMAND
; ------------------
;   The Spectrum's DRAW command is overloaded and can take two parameters sets.
;
;   With two parameters, it simply draws an approximation to a straight line
;   at offset x,y using the LINE-DRAW routine.
;
;   With three parameters, an arc is drawn to the point at offset x,y turning 
;   through an angle, in radians, supplied by the third parameter.
;   The arc will consist of 4 to 252 straight lines each one of which is drawn 
;   by calls to the DRAW-LINE routine.

;; DRAW
DRAW:
        rst 0x18                ; GET-CHAR
        cp 0x2C                 ; is it the comma character ?
        jr z,DR_3_PRMS          ; forward, if so, to DR-3-PRMS

;   There are two parameters e.g. DRAW 255,175

        call CHECK_END          ; routine CHECK-END

        jp LINE_DRAW            ; jump forward to LINE-DRAW

; ---

;    There are three parameters e.g. DRAW 255, 175, .5
;    The first two are relative coordinates and the third is the angle of 
;    rotation in radians (A).

;; DR-3-PRMS
DR_3_PRMS:
        rst 0x20                ; NEXT-CHAR skips over the 'comma'.

        call EXPT_1NUM          ; routine EXPT-1NUM stacks the rotation angle.

        call CHECK_END          ; routine CHECK-END

;   Now enter the calculator and store the complete rotation angle in mem-5 

        rst 0x28                ; ; FP-CALC      x, y, A.
        defb 0xC5               ; ;st-mem-5      x, y, A.

;   Test the angle for the special case of 360 degrees.

        defb 0xA2               ; ;stk-half      x, y, A, 1/2.
        defb 0x04               ; ;multiply      x, y, A/2.
        defb 0x1F               ; ;sin           x, y, sin(A/2).
        defb 0x31               ; ;duplicate     x, y, sin(A/2),sin(A/2)
        defb 0x30               ; ;not           x, y, sin(A/2), (0/1).
        defb 0x30               ; ;not           x, y, sin(A/2), (1/0).
        defb 0x00               ; ;jump-true     x, y, sin(A/2).

        defb 0x06               ; ;forward to L23A3, DR-SIN-NZ
                                ; if sin(r/2) is not zero.



( run in 0.829 second using v1.01-cache-2.11-cpan-39bf76dae61 )