CPU-Z80-Disassembler

 view release on metacpan or  search on metacpan

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

; start of the next routine to calculate the length to reclaim.

;; DIFFER
DIFFER:
        and a                   ; prepare for true subtraction.
        sbc hl,de               ; subtract the two pointers.
        ld b,h                  ; transfer result
        ld c,l                  ; to BC register pair.
        add hl,de               ; add back
        ex de,hl                ; and switch pointers
        ret                     ; return values are the length of area in BC,
                                ; low pointer (previous) in HL,
                                ; high pointer (next) in DE.

; -----------------------
; Handle reclaiming space
; -----------------------
;

;; RECLAIM-1
RECLAIM_1:
        call DIFFER             ; routine DIFFER immediately above

;; RECLAIM-2
RECLAIM_2:
        push bc

        ld a,b
        cpl
        ld b,a
        ld a,c
        cpl
        ld c,a
        inc bc

        call POINTERS           ; routine POINTERS
        ex de,hl
        pop hl

        add hl,de
        push de
        ldir                    ; copy bytes

        pop hl
        ret

; ----------------------------------------
; Read line number of line in editing area
; ----------------------------------------
; This routine reads a line number in the editing area returning the number
; in the BC register or zero if no digits exist before commands.
; It is called from LINE-SCAN to check the syntax of the digits.
; It is called from MAIN-3 to extract the line number in preparation for
; inclusion of the line in the BASIC program area.
;
; Interestingly the calculator stack is moved from its normal place at the
; end of dynamic memory to an adequate area within the system variables area.
; This ensures that in a low memory situation, that valid line numbers can
; be extracted without raising an error and that memory can be reclaimed
; by deleting lines. If the stack was in its normal place then a situation
; arises whereby the Spectrum becomes locked with no means of reclaiming space.

;; E-LINE-NO
E_LINE_NO:
        ld hl,(0x5C59)          ; load HL from system variable E_LINE.

        dec hl                  ; decrease so that NEXT_CHAR can be used
                                ; without skipping the first digit.

        ld (0x5C5D),hl          ; store in the system variable CH_ADD.

        rst 0x20                ; NEXT-CHAR skips any noise and white-space
                                ; to point exactly at the first digit.

        ld hl,0x5C92            ; use MEM-0 as a temporary calculator stack
                                ; an overhead of three locations are needed.
        ld (0x5C65),hl          ; set new STKEND.

        call INT_TO_FP          ; routine INT-TO-FP will read digits till
                                ; a non-digit found.
        call FP_TO_BC           ; routine FP-TO-BC will retrieve number
                                ; from stack at membot.
        jr c,E_L_1              ; forward to E-L-1 if overflow i.e. > 65535.
                                ; 'Nonsense in BASIC'

        ld hl,0xD8F0            ; load HL with value -9999
        add hl,bc               ; add to line number in BC

;; E-L-1
E_L_1:
        jp c,REPORT_C           ; to REPORT-C 'Nonsense in BASIC' if over.
                                ; Note. As ERR_SP points to ED_ERROR
                                ; the report is never produced although
                                ; the RST $08 will update X_PTR leading to
                                ; the error marker being displayed when
                                ; the ED_LOOP is reiterated.
                                ; in fact, since it is immediately
                                ; cancelled, any report will do.

; a line in the range 0 - 9999 has been entered.

        jp SET_STK              ; jump back to SET-STK to set the calculator
                                ; stack back to its normal place and exit
                                ; from there.

; ---------------------------------
; Report and line number outputting
; ---------------------------------
; Entry point OUT-NUM-1 is used by the Error Reporting code to print
; the line number and later the statement number held in BC.
; If the statement was part of a direct command then -2 is used as a
; dummy line number so that zero will be printed in the report.
; This routine is also used to print the exponent of E-format numbers.
;
; Entry point OUT-NUM-2 is used from OUT-LINE to output the line number
; addressed by HL with leading spaces if necessary.

;; OUT-NUM-1
OUT_NUM_1:
        push de                 ; save the
        push hl                 ; registers.



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