Mercurial > hg > index.cgi
annotate src/print.s @ 85:663d8e77b579
Implmement BCD floating point and update number parsing and printing
Implements a BCD floating point system with 10 decimal digits of precistion
and an exponent range of -63 to +63. Also include parsing integer and
floating point values and printing them out.
author | William Astle <lost@l-w.ca> |
---|---|
date | Sun, 15 Oct 2023 22:15:36 -0600 |
parents | bb50ac9fdf37 |
children |
rev | line source |
---|---|
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
1 *pragmapush list |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
2 *pragma list |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
4 ; Print out an unsigned 16 bit value in D to the selected output stream |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
5 print_uint16d pshs d,x,y,u ; save number and make some temporaries on the stack |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
6 leay 2,s ; point to start of buffer |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
7 ldu #10000 ; do the 10000s digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
8 bsr print_uint16d4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
9 ldu #1000 ; do the 1000s digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
10 bsr print_uint16d4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
11 ldu #100 ; do the 100s digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
12 bsr print_uint16d4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
13 ldu #10 ; do the 10s digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
14 bsr print_uint16d4 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
15 puls d ; get back number residue and clean up stack |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
16 addb #0x30 ; convert 1s digit to number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
17 stb ,y ; stash it |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
18 clr 1,y ; NUL terminate it |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
19 leay ,s ; point to start of converted number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
20 print_uint16d0 lda ,y ; get digit at start |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
21 cmpa #0x30 ; zero digit? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
22 bne print_uint16d1 ; brif not - we can just show the number from here |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
23 ldb 1,y ; end of number? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
24 beq print_uint16d1 ; brif so - show the zero anyway |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
25 leay 1,y ; move past the zero |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
26 bra print_uint16d0 ; see if we have more zeroes to skip |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
27 print_uint16d1 lda ,y+ ; get number digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
28 beq print_uint16d2 ; brif end of number |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
29 jsr writechr ; output the digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
30 bra print_uint16d1 ; handle next digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
31 print_uint16d2 leas 6,s ; clean up the stack |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
32 rts |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
33 print_uint16d4 lda #0x30-1 ; init digit value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
34 pshs a,u ; save the digit position and digit value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
35 ldd 5,s ; get back residue |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
36 print_uint16d5 inc ,s ; bump digit |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
37 subd 1,s ; subtract out place value |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
38 bcc print_uint16d5 ; brif we haven't got the right digit yet |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
39 addd 1,s ; restore residue |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
40 std 5,s ; save new residue |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
41 puls a,u ; get back digit and place value off stack |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
42 sta ,y+ ; save digit in buffer |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
43 rts |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
44 |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
45 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
46 ; PRINT command |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
47 cmd_print beq cmd_printeol ; brif no argument - do a newline |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
48 cmd_print0 cmpa #'; ; semicolon? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
49 bne cmd_print1 ; brif not |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
50 jsr nextchar ; skip the semicolon |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
51 bne cmd_print0 ; brif not end of the statement |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
52 rts |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
53 cmd_print1 jsr eval_expr ; evaluate the expression |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
54 ldb val0+val.type ; get value type |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
55 cmpb #valtype_int ; integer? |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
56 beq cmd_printint ; brif so - print integer |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
57 cmpb #valtype_float ; floatingp point? |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
58 beq cmd_printfps ; brif so - print floating point |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
59 lda #'! ; flag unknown expression type |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
60 jsr console_outchr |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
61 jsr console_outchr |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
62 jsr console_outchr |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
63 cmd_printnext jsr curchar ; see what we have here |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
64 bra cmd_print ; and go process |
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
65 cmd_printeol jmp console_outnl ; do a newline and return |
85
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
66 cmd_printint jsr int_toascii ; convert val0 to string |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
67 cmd_printstrb ldx #strbuff ; point to resulting string |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
68 jsr console_outstr ; output the string |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
69 bra cmd_printnext ; go handle next stuff |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
70 cmd_printfps jsr fps_toascii ; convert val0 to string |
663d8e77b579
Implmement BCD floating point and update number parsing and printing
William Astle <lost@l-w.ca>
parents:
80
diff
changeset
|
71 bra cmd_printstrb ; go output the resulting string |
75
5f8f0b0781e8
Split some code into separate files for easier management (3)
William Astle <lost@l-w.ca>
parents:
diff
changeset
|
72 *pragmapop list |