home *** CD-ROM | disk | FTP | other *** search
/ develop, the CD; issue 1 / Apple_Develop_1989.bin / dynamo / rt.a < prev    next >
Text File  |  1989-12-10  |  18KB  |  1,438 lines

  1. *******************************************************
  2. *                        *
  3. * DYNAMO                        *
  4. *                        *
  5. * Apple II 8-bit runtime library routines.        *
  6. * Copyright (C) 1989 Apple Computer.        *
  7. *                        *
  8. * Written by Eric Soldan, Apple II DTS        *
  9. *                        *
  10. *******************************************************
  11.  
  12.         include    'sys.equ'
  13.         include    'app.config'
  14.  
  15. vsl        equ    varstart
  16. vsh        equ    varstart+hibyte
  17.  
  18. ******************
  19.  
  20.         export    rtreset
  21. rtreset        proc
  22.         export    numtocopy, chrhibiton, chrhibitoff
  23.         export    sign, readendchr, hexpadchr, padhex
  24.         ldy    #255
  25.         sty    numtocopy
  26.         sty    chrhibitoff
  27.         iny
  28.         sty    chrhibiton
  29.         sty    sign
  30.         sty    readendchr
  31.         lda    #'0'
  32.         sta    hexpadchr
  33.         lsr    padhex
  34.         rts
  35. numtocopy    dc.b    255        ;Will be set back to 255 after
  36.                     ;every string copy or append.
  37. chrhibitoff    dc.b    $FF
  38. chrhibiton    dc.b    0
  39. sign        dc.b    0
  40. readendchr    dc.b    0
  41. hexpadchr    dc.b    '0'
  42. padhex        dc.b    0
  43.         endp
  44.  
  45. ***
  46.  
  47.         export    hibitchrs
  48. hibitchrs    PROC
  49.  
  50.         lda    #$80        ;We don't need to set chrhibitoff
  51.         sta    chrhibiton    ;because it will either be a $7F
  52.         rts            ;or $FF, and in either case
  53.         endp            ;chrhibiton will turn it on anyway.
  54.  
  55. ***
  56.  
  57.         export    lowbitchrs
  58. lowbitchrs    PROC
  59.  
  60.         asl    chrhibiton    ;Was a $00 or $80, so this makes it $00.
  61.         lda    #$7F
  62.         sta    chrhibitoff
  63.         rts
  64.         endp
  65.  
  66. ***
  67.  
  68.         export    regchrs
  69. regchrs        PROC
  70.  
  71.         asl    chrhibiton
  72.         lda    #$FF
  73.         sta    chrhibitoff
  74.         rts
  75.         endp
  76.  
  77. ***
  78.  
  79.         export    rtcout
  80. rtcout        proc
  81.  
  82.         stx    @keepx
  83.         and    chrhibitoff
  84.         ora    chrhibiton
  85.         jsr    $FDED
  86.         ldx    @keepx
  87.         rts
  88. @keepx        dc.b    0
  89.         endp
  90.  
  91. ***
  92.  
  93.         export    write
  94. write        proc
  95.         pla
  96.         sta    @getchr+1
  97.         pla
  98.         sta    @getchr+2
  99.         txa
  100.         pha
  101. @loop        inc    @getchr+1
  102.         bne    @getchr
  103.         inc    @getchr+2
  104. @getchr        lda    $2000        ;Address modified.
  105.         beq    @exit
  106.         jsr    rtcout
  107.         jmp    @loop
  108. @exit        pla
  109.         tax
  110.         lda    @getchr+2
  111.         pha
  112.         lda    @getchr+1
  113.         pha
  114.         rts
  115.         endp
  116.  
  117. ***
  118.  
  119.         export    writecr
  120. writecr        proc
  121.         txa
  122.         pha
  123.         lda    #13
  124.         jsr    rtcout
  125.         pla
  126.         tax
  127.         rts
  128.         endp
  129.  
  130. ***
  131.  
  132.         export    wrcstr
  133. wrcstr        proc
  134.         sta    @getchr+1
  135.         sty    @getchr+2
  136.         txa
  137.         pha
  138. @getchr        lda    $2000        ;Address modified.        
  139.         beq    @exit
  140.         jsr    rtcout
  141.         inc    @getchr+1
  142.         bne    @getchr
  143.         inc    @getchr+2
  144.         bne    @getchr        ;Always.
  145. @exit        pla
  146.         tax
  147.         rts
  148.         endp
  149.  
  150. ***
  151. ***
  152. ***
  153.  
  154.         export    signed
  155. signed        proc
  156.         sec
  157.         ror    sign
  158.         rts
  159.         endp
  160.  
  161. ***
  162.  
  163.         export    unsigned
  164. unsigned        proc
  165.         lsr    sign
  166.         rts
  167.         endp
  168.  
  169. ***
  170.  
  171.         export    chngsgn
  172. chngsgn        proc
  173.         lda    vsl,x
  174.         eor    #$FF
  175.         clc
  176.         adc    #1
  177.         sta    vsl,x
  178.         lda    vsh,x
  179.         eor    #$FF
  180.         adc    #0
  181.         sta    vsh,x
  182.         rts
  183.         endp
  184.  
  185. ***
  186.  
  187.         export    decoutl
  188. decoutl        proc
  189.         import    decout
  190.         ldy    #0
  191.         jmp    decout        ;jmp, instead of beq so we can be a lib.
  192.         endp
  193.  
  194. ***
  195.  
  196.         export    vdecout
  197. vdecout        proc
  198.         export    decout
  199.         lda    vsh,x
  200.         tay
  201.         lda    vsl,x
  202.  
  203. decout        sta    @templ
  204.         sty    @temph
  205.         lda    #'0'
  206.         sta    @temp2
  207.         txa
  208.         pha
  209.         bit    sign
  210.         bpl    @pos
  211.         tya
  212.         bpl    @pos
  213.         lda    #'-'
  214.         jsr    rtcout
  215.         lda    @templ
  216.         eor    #$FF
  217.         clc
  218.         adc    #1
  219.         sta    @templ
  220.         lda    @temph
  221.         eor    #$FF
  222.         adc    #0
  223.         sta    @temph
  224. @pos        ldx    #4
  225. @a        lda    #'0'
  226.         sta    @temp
  227. @b        lda    @templ
  228.         sec
  229.         sbc    @decl,x
  230.         tay
  231.         lda    @temph
  232.         sbc    @dech,x
  233.         bcc    @c
  234.         sta    @temph
  235.         sty    @templ
  236.         inc    @temp
  237.         bcs    @b
  238. @c        lda    @temp
  239.         dex
  240.         bmi    @e        ;Last digit -- print no matter what.
  241.         cmp    @temp2
  242.         beq    @a        ;Don't print leading 0's.
  243.         lsr    @temp2        ;Inval leading 0 test.
  244.         jsr    rtcout
  245.         jmp    @a
  246. @e        jsr    rtcout
  247.         pla
  248.         tax
  249.         rts
  250. @decl        dc.b    1
  251.         dc.b    10
  252.         dc.b    100
  253.         dc.b    1000-768
  254.         dc.b    10000-9984
  255. @dech        dc.b    1>>8
  256.         dc.b    10>>8
  257.         dc.b    100>>8
  258.         dc.b    1000>>8
  259.         dc.b    10000>>8
  260. @templ        dc.b    0
  261. @temph        dc.b    0
  262. @temp        dc.b    0
  263. @temp2        dc.b    0
  264.         endp
  265.  
  266. ***
  267.  
  268.         export    hexpad
  269. hexpad        proc
  270.         sta    hexpadchr
  271.         lsr    padhex
  272.         rts
  273.         endp
  274.  
  275. ***
  276.  
  277.         export    hexnopad
  278. hexnopad        proc
  279.         sec
  280.         ror    padhex
  281.         rts
  282.         endp
  283.  
  284. ***
  285.  
  286.         export    hexoutl
  287. hexoutl        proc
  288.         import    hexout
  289.         ldy    #0
  290.         clc
  291.         jmp    hexout+1        ;jmp, instead of beq so we can be a lib.
  292.         endp
  293.  
  294. ***
  295.  
  296.         export    vhexout
  297. vhexout        proc
  298.         export    hexout
  299.         import    hexpadchr
  300.         lda    vsh,x
  301.         tay
  302.         lda    vsl,x
  303.  
  304. hexout        sec
  305.         sta    @templ
  306.         txa
  307.         pha
  308.         ldx    #3
  309.         bcs    @aa
  310.         ldx    #1
  311.         ldy    @templ
  312. @aa        sty    @temph
  313.         lda    padhex
  314.         sta    @padhex
  315.         lda    hexpadchr
  316.         sta    @hexpadchr
  317. @loop        lda    #0
  318.         ldy    #4
  319. @a        asl    @templ
  320.         rol    @temph
  321.         rol    a
  322.         dey
  323.         bne    @a
  324.         tay
  325.         bne    @b
  326.         lda    @padhex
  327.         bmi    @nopad
  328.         lda    @hexpadchr
  329.         jsr    rtcout
  330.         jmp    @nopad
  331. @b        jsr    @doone
  332.         lsr    @padhex
  333.         lda    #'0'
  334.         sta    @hexpadchr
  335. @nopad        dex
  336.         bne    @loop
  337.         lda    @temph
  338.         lsr    a
  339.         lsr    a
  340.         lsr    a
  341.         lsr    a
  342.         tay
  343.         pla
  344.         tax
  345. @doone        lda    @hexdigit,y
  346.         jmp    rtcout
  347. @hexdigit    dc.b    '0123456789ABCDEF'
  348. @padhex        dc.b    0
  349. @hexpadchr    dc.b    0
  350. @templ        dc.b    0
  351. @temph        dc.b    0
  352.         endp
  353.  
  354. ***
  355.  
  356.         export    ldyvar
  357. ldyvar        proc
  358.         lda    vsl,y
  359.         pha
  360.         lda    vsh,y
  361.         tay
  362.         pla
  363.         rts
  364.         endp
  365.  
  366. ***
  367.  
  368.         export    mulconl
  369. mulconl        proc
  370.         import    mulcon
  371.         ldy    #0
  372.         jmp    mulcon        ;jmp, instead of beq so we can be a lib.
  373.         endp
  374.  
  375. ***
  376.  
  377.         export    mulvar
  378. mulvar        proc
  379.         export    mulcon, mulvall, mulvalh
  380.         import    multiply, setcon
  381.         jsr    ldyvar
  382.  
  383. mulcon        pha
  384.         lda    vsl,x
  385.         sta    mulvall
  386.         lda    vsh,x
  387.         sta    mulvalh
  388.         pla
  389.         jsr    multiply
  390.         jmp    setcon
  391. mulvall        dc.b    0
  392. mulvalh        dc.b    0
  393.         endp
  394.  
  395.         export    multiply
  396. multiply        proc
  397.         sta    @templ
  398.         sty    @temph
  399.         lda    #0
  400.         tay
  401. @a        lsr    mulvalh
  402.         ror    mulvall
  403.         bcc    @b
  404.         clc
  405.         adc    @templ
  406.         pha
  407.         tya
  408.         adc    @temph
  409.         tay
  410.         pla
  411. @b        asl    @templ
  412.         rol    @temph
  413.         pha
  414.         lda    mulvalh
  415.         ora    mulvall
  416.         cmp    #1
  417.         pla
  418.         bcs    @a
  419.         rts
  420. @templ        dc.b    0
  421. @temph        dc.b    0
  422.         endp
  423.  
  424.         export    divconl
  425. divconl        proc
  426.         import    divcon
  427.         ldy    #0
  428.         jmp    divcon        ;jmp, instead of beq so we can be a lib.
  429.         endp
  430.  
  431. ***
  432.  
  433.         export    divvar
  434. divvar        proc
  435.         export    divcon
  436.         import    ldyvar
  437.         jsr    ldyvar
  438.  
  439. divcon        sta    @templ
  440.         sty    @temph
  441.         lda    #16
  442.         sta    @temp
  443.         lda    #0
  444.         sta    @temp2
  445.         sta    @temp3
  446. @a        asl    vsl,x
  447.         rol    vsh,x
  448.         rol    @temp2
  449.         rol    @temp3
  450.         lda    @temp2
  451.         sec
  452.         sbc    @templ
  453.         sta    @temp4
  454.         lda    @temp3
  455.         sbc    @temph
  456.         bcc    @b
  457.         sta    @temp3
  458.         lda    @temp4
  459.         sta    @temp2
  460.         inc    vsl,x
  461. @b        dec    @temp
  462.         bne    @a
  463.         lda    @temp2
  464.         ldy    @temp3
  465.         rts
  466. @templ        dc.b    0
  467. @temph        dc.b    0
  468. @temp        dc.b    0
  469. @temp2        dc.b    0
  470. @temp3        dc.b    0
  471. @temp4        dc.b    0
  472.         endp
  473.  
  474. ***
  475.  
  476.         export    addvar
  477. addvar        proc
  478.         export    addcon
  479.         import    ldyvar
  480.         jsr    ldyvar
  481.  
  482. addcon        pha
  483.         clc
  484.         adc    vsl,x
  485.         sta    vsl,x
  486.         tya
  487.         adc    vsh,x
  488.         sta    vsh,x
  489.         pla
  490.         rts
  491.         endp
  492.  
  493. ***
  494.  
  495.         export    addconl
  496. addconl        proc
  497.         ldy    #0
  498.         jmp    addcon        ;jmp, instead of beq so we can be a lib.
  499.         endp
  500.  
  501. ***
  502.  
  503.         export    subvar
  504. subvar        proc
  505.         export    subcon
  506.         import    ldyvar
  507.         jsr    ldyvar
  508.  
  509. subcon        pha
  510.         sta    @temp
  511.         lda    vsl,x
  512.         sec
  513.         sbc    @temp
  514.         sta    vsl,x
  515.         sty    @temp
  516.         lda    vsh,x
  517.         sbc    @temp
  518.         sta    vsh,x
  519.         pla
  520.         rts
  521. @temp        dc.b    0
  522.         endp
  523.  
  524. ***
  525.  
  526.         export    subconl
  527. subconl        proc
  528.         ldy    #0
  529.         jmp    subcon        ;jmp, instead of beq so we can be a lib.
  530.         endp
  531.  
  532. ***
  533.  
  534.         export    setconl
  535. setconl        proc
  536.         export    setcon
  537.         ldy    #0
  538.  
  539. setcon        sta    vsl,x
  540.         pha
  541.         tya
  542.         sta    vsh,x
  543.         pla
  544.         rts
  545.         endp
  546.  
  547. ***
  548.  
  549.         export    setzero
  550. setzero        proc
  551.         lda    #0
  552.         sta    vsh,x
  553.         sta    vsl,x
  554.         rts
  555.         endp
  556.  
  557. ***
  558.  
  559.         export    seteq
  560. seteq        proc
  561.         lda    vsh,y
  562.         sta    vsh,x
  563.         lda    vsl,y
  564.         sta    vsl,x
  565.         rts
  566.         endp
  567.  
  568. ***
  569.  
  570.         export    setvars
  571. setvars        proc
  572.         pla
  573.         sta    @getval+1
  574.         pla
  575.         sta    @getval+2
  576.         txa
  577.         pha
  578.         ldy    #1
  579. @loop        jsr    @getval
  580.         cmp    #255
  581.         beq    @exit
  582.         tax
  583.         jsr    @getval
  584.         sta    vsl,x
  585.         jsr    @getval
  586.         sta    vsh,x
  587.         bcc    @loop        ;Always.
  588. @exit        pla
  589.         tax
  590.         lda    @getval+2
  591.         pha
  592.         lda    @getval+1
  593.         pha
  594.         rts
  595. @getval        lda    $2000,y        ;Address modified.
  596.         inc    @getval+1
  597.         bne    @rts
  598.         inc    @getval+2
  599. @rts        rts
  600.         endp
  601.  
  602. ***
  603.  
  604.         export    xgty
  605. xgty        proc
  606.         import    vifequal, vifsgneq, xlty0
  607.         tya
  608.         pha
  609.         lda    sign
  610.         bpl    @a
  611.         jsr    vifsgneq
  612.         jmp    @b
  613. @a        jsr    vifequal
  614. @b        pla
  615.         tay
  616.         bcs    @rts
  617.         jmp    xlty0        ;jmp, instead of bcc so we can be a lib.
  618. @rts        rts
  619.         endp
  620.  
  621. ***
  622.  
  623.         export    xlty
  624. xlty        proc
  625.         export    xlty0
  626.         import    vifequal, vifsgneq
  627.         tya
  628.         pha
  629.         lda    sign
  630.         bpl    @a
  631.         jsr    vifsgneq
  632.         jmp    @b
  633. @a        jsr    vifequal
  634. @b        pla
  635.         tay
  636.         bcc    xltyrts
  637. xlty0        lda    vsl,x
  638.         pha
  639.         lda    vsl,y
  640.         sta    vsl,x
  641.         pla
  642.         sta    vsl,y
  643.         lda    vsh,x
  644.         pha
  645.         lda    vsh,y
  646.         sta    vsh,x
  647.         pla
  648.         sta    vsh,y
  649. xltyrts        rts
  650.         endp
  651.  
  652. ***
  653.  
  654.         export    ifequal
  655. ifequal        proc
  656.         sta    @lo
  657.         sty    @hi
  658.         lda    vsh,x
  659.         cmp    @hi
  660.         bne    @exit
  661.         lda    vsl,x
  662.         cmp    @lo
  663. @exit        php
  664.         lda    @lo
  665.         plp
  666.         rts            ;eq=eq, cs>=, cc<
  667. @lo        dc.b    0
  668. @hi        dc.b    0
  669.         endp
  670.  
  671. ***
  672.  
  673.         export    vifequal
  674. vifequal        proc
  675.         lda    vsl,y        ;Load up the variable value and go do it.
  676.         pha
  677.         lda    vsh,y
  678.         tay
  679.         pla
  680.         jmp    ifequal
  681.         endp
  682.  
  683. ***
  684.  
  685.         export    ifsgneq
  686. ifsgneq        proc
  687.         sta    @lo        ;Preserve acc.
  688.         tya
  689.         cmp    #$80        ;See if right-side is negative.
  690.         eor    vsh,x        ;See if signs are the same.
  691.         bmi    @exit        ;xreg variable is smaller (signed).
  692.         bcs    @a        ;xreg variable is negativ