Na tisk 16 bitoveho cisla se da pouzit i rom cast pro kalkulacku. Pokud se nepletu tak stejne si to v basicu uklada jako real.
ZX Spectrum floating-point format: EEEE EEEE SMMM MMMM MMMM MMMM MMMM MMMM MMMM MMMM exp, sign + m, m, m, m ZX Spectrum integer format: 0000 0000 SSSS SSSS LLLL LLLL HHHH HHHH 0000 0000 0, 8x dup S, lo, hi, 0
Takze staci integer spravne nacpat na vrchol kalkulacky a zavolat rutinu pro tisk.
V M4 Forthu kdyz to chci tisknou pres rom to pak vypada takto (v rutine je navic na konci nejaka prace, aby se cislo odstranilo z TOS (HL) a nacetlo se do nej NOS (DE)).
dworkin@dw-A15:~/Programovani/ZX/Forth/M4$ ../check_word.sh 'PUSH(1234) DOTZXROM' push DE ; 1:11 1234 ex DE, HL ; 1:4 1234 ld HL, 1234 ; 3:10 1234 call ZXPRT_S16 ; 3:17 .zxrom ( x -- ) ;------------------------------------------------------------------------------ ; Input: HL ; Output: Print signed decimal number in HL ; Pollutes: AF, BC, HL <- DE, DE <- (SP) ZXPRT_S16: ; zxprt_s16 ( x -- ) push DE ; 1:11 zxprt_s16 ld A, H ; 1:4 zxprt_s16 add A, A ; 1:4 zxprt_s16 sbc A, A ; 1:4 zxprt_s16 sign ld E, A ; 1:4 zxprt_s16 2. byte sign xor A ; 1:4 zxprt_s16 1. byte = 0 ld D, L ; 1:4 zxprt_s16 3. byte lo ld C, H ; 1:4 zxprt_s16 4. byte hi ld B, A ; 1:4 zxprt_s16 5. byte = 0 ld IY, 0x5C3A ; 4:14 zxprt_s16 Re-initialise IY to ERR-NR. call 0x2AB6 ; 3:17 zxprt_s16 call ZX ROM STK store routine call 0x2DE3 ; 3:17 zxprt_s16 call ZX ROM print a floating-point number routine pop HL ; 1:10 zxprt_s16 pop BC ; 1:10 zxprt_s16 load ret pop DE ; 1:10 zxprt_s16 push BC ; 1:11 zxprt_s16 save ret ret ; 1:10 zxprt_u16 ; seconds: 0 ;[32:184]
Stale je to kratsi nez psat vlastni rutinu.
Pokud by to byl unsigned integer tak je to jeste kratsi
dworkin@dw-A15:~/Programovani/ZX/Forth/M4$ ../check_word.sh 'PUSH(1234) UDOTZXROM' push DE ; 1:11 1234 ex DE, HL ; 1:4 1234 ld HL, 1234 ; 3:10 1234 call ZXPRT_U16 ; 3:17 u.zxrom ( u -- ) ;------------------------------------------------------------------------------ ; Input: HL ; Output: Print unsigned decimal number in HL ; Pollutes: AF, BC, HL <- DE, DE <- (SP) ZXPRT_U16: ; zxprt_u16 ( u -- ) push DE ; 1:11 zxprt_u16 ld B, H ; 1:4 zxprt_u16 ld C, L ; 1:4 zxprt_u16 call 0x2D2B ; 3:17 zxprt_u16 call ZX ROM stack BC routine call 0x2DE3 ; 3:17 zxprt_u16 call ZX ROM print a floating-point number routine pop HL ; 1:10 zxprt_u16 pop BC ; 1:10 zxprt_u16 load ret pop DE ; 1:10 zxprt_u16 push BC ; 1:11 zxprt_u16 save ret ret ; 1:10 zxprt_u16 ; seconds: 0 ;[22:146]