home *** CD-ROM | disk | FTP | other *** search
/ ittybittycomputers.com / www.ittybittycomputers.com.tar / www.ittybittycomputers.com / IttyBitty / TinyBasic / TB.asm < prev    next >
Assembly Source File  |  2008-12-31  |  32KB  |  1,275 lines

  1. ; OMS-02 Firmware
  2. ;
  3. ; Bill O'Neill - Last update: 2008/12/06
  4. ;
  5. ; Tiny Basic and minimal Monitor (BIOS)
  6. ;
  7. ; This version is for the assembler that comes with
  8. ; Michal Kowalski's 6502 emulator.  To run it, load it
  9. ; into the emulator, assemle it, begin debug mode then,
  10. ; set the PC to $1CF0 then run.
  11. ;
  12. ; The emulator was used to help figure out Tiny Basic
  13. ; and this code is only documented to that extent.
  14. ;
  15. ; It should be easy enough to configure this to run any-
  16. ; where in memory or convert it to assemble with any 6502
  17. ; assembler.  The current location is being used as this is
  18. ; to be placed into a controller I designed (OMS-02) around
  19. ; a 6507 CPU (a 6502 variant) that has only 8k off memory.
  20. ; The memory map for the OMS-02 is;
  21. ;
  22. ; $0000-$0FFF     RAM
  23. ; $1000-$13FF     I/O space (ACIA is at $1200)
  24. ; $1400-$1FFF     Tiny Basic and simple monitor
  25. ;
  26. ;
  27. ; Next steps:
  28. ;        Write a BREAK routine that will enable a break if any charater is typed at the console
  29. ;        More comments to document this code
  30. ;        Investigate using assembler variables and directives to make it easy to re-locate this code
  31. ;
  32. ;
  33.  
  34.     .org      $1000                 ; Address of first byte of EPROM in the system
  35.  
  36. SOROM
  37.  
  38.  
  39. ;
  40. ; Tiny Basic starts here
  41. ;
  42.     .org      $1400                 ; Start of Basic.  First 1K of ROM is shaded by I/O on the OMS-02
  43.  
  44. SOBAS
  45.  
  46. C_00BC   =     $00BC                 ; These are needed because my assembler
  47. C_20     =     $20                   ; does not hanle standard 6502 notation
  48. C_22     =     $22                   ; properly
  49. C_24     =     $24                   ;
  50. C_2A     =     $2A                   ; I may just fix this someday - HA!
  51. C_2C     =     $2C                   ;
  52. C_2E     =     $2E                   ;
  53. C_B8     =     $B8                   ;
  54. C_BC     =     $BC                   ;
  55. C_C1     =     $C1                   ;
  56. C_C2     =     $C2                   ;
  57. C_C6     =     $C6                   ;
  58.  
  59. SR_V_L   =     SOBAS + $1E             ; Base address for subroutine vector lo byte
  60. SR_V_H   =     SOBAS + $1F             ; Base address for subroutine vector hi byte
  61.  
  62. CV       jmp      COLD_S            ; Cold start vector
  63. WV       jmp      WARM_S            ; Warm start vector
  64. IN_V     jmp      RCCHR             ; Input routine address. 
  65. OUT_V    jmp      SNDCHR            ; Output routine address.
  66. BREAK    nop                        ; Begin dummy break routine
  67.          clc                        ; Clear the carry flag
  68.          rts                        ; End break routine
  69. ;
  70. ; Some codes
  71. ;
  72. BSC      .db $5f                       ; Backspace code
  73. LSC      .db $18                       ; Line cancel code
  74. PCC      .db $80                       ; Pad character control
  75. TMC      .db $00                       ; Tape mode control
  76. SSS      .db $04                       ; Spare Stack size. (was $04 but documentation suggests $20 ?)
  77.  
  78. ;
  79. ; Code fragment
  80. ; Seems to store or retreive a byte to/from memory and the accumulator
  81. ; Don't know what calls it
  82.          stx $C3
  83.          bcc LBL008
  84.          stx $C3
  85.          sta (C_C2),Y
  86.          rts
  87. LBL008   lda (C_C2),Y
  88.          ldy #$00
  89.          rts
  90.  
  91.  
  92.          .dd $6215, $6415, $D815, $0516, $3316, $FD15                   ; These seem to be addresses associated with the IL branch instructions
  93.  
  94.          .dd $9F17, $421B, $3F1B, $7A17, $FC18, $9517, $9F17, $9F17     ; This appears to be a table of
  95.          .dd $BD1A, $C11A, $8A1A, $9B1A, $E91A, $6117, $5117, $411A     ; execution addresses to jump to ML routines
  96.          .dd $521A, $4F1A, $621A, $E719, $CD16, $0617, $9F17, $1518     ; that handle the the IL instructions.
  97.          .dd $A717, $B716, $BF16, $8318, $A116, $9F17, $9F17, $A818     ; You cannot add code to or relocate this program
  98.          .dd $4F1B, $4D1B, $0719, $AA14, $3717, $BD14, $1B1B, $B11A     ; without updating these
  99.  
  100.          .dd $2041, $5420           ; No idea ????
  101.  
  102.          .db $80                    ; No idea
  103.          
  104. LBL002   .db $70                    ; $70 - lo byte of IL address
  105. LBL003   .db $1B                    ; $1B - hi byte of IL address
  106.                                     ; I should figure out a way to
  107.                                     ; calculate these at assembly to
  108.                                     ; help make this re-locatable.
  109.  
  110. ;
  111. ;Begin Cold Start
  112. ;
  113. ;
  114. ;
  115. ;Load start of free ram ($0200) into locations $0020 and $0022
  116. ;
  117. COLD_S   lda #$00                   ; Load accumulator with $00
  118.          sta $20                    ; Store $00 in $20
  119.          sta $22                    ; Store $00 in $22
  120.          lda #$02                   ; Load accumulator with $02
  121.          sta $21                    ; Store $02 in $21
  122.          sta $23                    ; Store $02 in $23
  123. ;
  124. ;
  125. ; Begin test for free ram
  126. ;
  127.          ldy #$01                   ; Load register Y with $01
  128. MEM_T    lda (C_22),Y               ; Load accumulator With the contents of a byte of memory
  129.          tax                        ; Save it to X
  130.          eor #$FF                   ; Next 4 instuctions test to see if this memeory location
  131.          sta (C_22),Y               ; is ram by trying to write something new to it - new value
  132.          cmp (C_22),Y               ; gets created by XORing the old value with $FF - store the
  133.          php                        ; result of the test on the stack to look at later
  134.          txa                        ; Retrieve the old memory value
  135.          sta (C_22),Y               ; Put it back where it came from
  136.          inc $22                    ; Increment $22 (for next memory location)
  137.          bne SKP_PI                 ; Goto $14A6 if we don't need to increment page
  138.          inc $23                    ; Increment $23 (for next memory page)
  139. SKP_PI   plp                        ; Now look at the result of the memory test
  140.          beq MEM_T                  ; Go test the next mempry location if the last one was ram
  141.          dey                        ; If last memory location did not test as ram, decrement Y (should be $00 now)
  142.          cld                        ; Make sure we're not in decimal mode
  143.          lda $20                    ; Load up the low-order by of the start of free ram
  144.          adc SSS                    ; Add to the spare stack size
  145.          sta $24                    ; Store the result in $0024
  146.          tya                        ; Retrieve Y
  147.          adc $21                    ; And add it to the high order byte of the start of free ram (this does not look right)
  148.          sta $25                    ; Store the result in $0025
  149.          tya                        ; Retrieve Y again
  150.          sta (C_20),Y               ; Store A in the first byte of program memory
  151.          iny                        ; Increment Y
  152.          sta (C_20),Y               ; Store A in the second byte of program memory
  153. ;
  154. ;Begin Warm Start;
  155. ;
  156. WARM_S   lda $22
  157.          sta $C6
  158.          sta $26
  159.          lda $23
  160.          sta $C7
  161.          sta $27
  162.          jsr LBL001                 ; Go print CR, LF and pad charachters
  163. LBL014   lda LBL002
  164.          sta $2A
  165.          lda LBL003
  166.          sta $2B
  167.          lda #$80
  168.          sta $C1
  169.          lda #$30
  170.          sta $C0
  171.          ldx #$00
  172.          stx $BE
  173.          stx $C2
  174.          dex
  175.          txs
  176. LBL006   cld
  177.          jsr LBL004                 ; Go read a byte from the TBIL table
  178.          jsr LBL005
  179.          jmp LBL006
  180. ;
  181. ;
  182. ;
  183.          .db $83                    ; No idea about this
  184.          .db $65                    ; No idea about this
  185. ;
  186. ;
  187. ; Routine to service the TBIL Instructions
  188. ;
  189. LBL005   cmp #$30                   ;
  190.          bcs LBL011                 ; If it's $30 or higher, it's a Branch or Jump - go handle it
  191.          cmp #$08                   ; 
  192.          bcc LBL007                 ; If it's less than $08 it's a stack exchange - go handle it
  193.          asl                        ; Multiply the OP code by 2 
  194.          tax                        ; Transfer it to X
  195. LBL022   lda SR_V_H,X               ; Get the hi byte of the OP Code handling routine
  196.          pha                        ; and save it on the stack
  197.          lda SR_V_L,X               ; Get the lo byte
  198.          pha                        ; and save it on the stack
  199.          php                        ; save the processor status too
  200.          rti                        ; now go execute the OP Code handling routine
  201. ;
  202. ;
  203. ; Routine to handle the stack exchange 
  204. ;
  205. LBL007   adc $C1
  206.          tax
  207.          lda (C_C1),Y
  208.          pha
  209.          lda $00,X
  210.          sta (C_C1),Y
  211.          pla
  212.          sta $00,X
  213.          rts
  214. ;
  215. ;
  216. ;
  217. LBL015   jsr LBL001                 ; Go print CR, LF and pad charachters
  218.          lda #$21                   ; Load an ASCII DC2
  219.          jsr OUT_V                  ; Go print it
  220.          lda $2A                    ; Load the current TBIL pointer (lo) 
  221.          sec                        ; Set the carry flag
  222.          sbc LBL002                 ; Subtract the TBIL table origin (lo)
  223.          tax                        ; Move the difference to X
  224.          lda $2B                    ; Load the current TBIL pointer (hi)
  225.          sbc LBL003                 ; Subtract the TBIL table origin (hi)
  226.          jsr LBL010
  227.          lda $BE
  228.          beq LBL012
  229.          lda #$7E
  230.          sta $2A
  231.          lda #$20
  232.          sta $2B
  233.          jsr LBL013
  234.          ldx $28
  235.          lda $29
  236.          jsr LBL010
  237. LBL012   lda #$07                   ; ASCII Bell
  238.          jsr OUT_V                  ; Go ring Bell
  239.          jsr LBL001                 ; Go print CR, LF and pad charachters
  240. LBL060   lda $26
  241.          sta $C6
  242.          lda $27
  243.          sta $C7
  244.          jmp LBL014
  245. ;
  246. ;
  247. ;
  248. LBL115   ldx #$7C
  249. LBL048   cpx $C1
  250. LBL019   bcc LBL015
  251.          ldx $C1
  252.          inc $C1
  253.          inc $C1
  254.          clc
  255.          rts
  256. ;
  257. ;
  258. ;
  259.          dec $BD
  260. LBL027   lda $BD
  261.          beq LBL015
  262. LBL017   lda $BC
  263.          sta $2A
  264.          lda $BD
  265.          sta $2B
  266.          rts
  267. ;
  268. ; Branch handling routine
  269. ;
  270. LBL011   cmp #$40                      ;
  271.          bcs LBL016                 ; If it's not a Jump, go to branch handler
  272.          pha
  273.          jsr LBL004                 ; Go read a byte from the TBIL table
  274.          adc LBL002
  275.          sta $BC
  276.          pla
  277.          pha
  278.          and #$07
  279.          adc LBL003
  280.          sta $BD
  281.          pla
  282.          and #$08
  283.          bne LBL017
  284.          lda $BC
  285.          ldx $2A
  286.          sta $2A
  287.          stx $BC
  288.          lda $BD
  289.          ldx $2B
  290.          sta $2B
  291.          stx $BD
  292. LBL126   lda $C6
  293.          sbc #$01
  294.          sta $C6
  295.          bcs LBL018
  296.          dec $C7
  297. LBL018   cmp $24
  298.          lda $C7
  299.          sbc $25
  300.          bcc LBL019
  301.          lda $BC
  302.          sta (C_C6),Y
  303.          iny
  304.          lda $BD
  305.          sta (C_C6),Y
  306.          rts
  307. ;
  308. ;Branch handler
  309. ;
  310. LBL016   pha
  311.          lsr
  312.          lsr
  313.          lsr
  314.          lsr
  315.          and #$0E
  316.          tax
  317.          pla
  318.          cmp #$60
  319.          and #$1F
  320.          bcs LBL020
  321.          ora #$E0
  322. LBL020   clc
  323.          beq LBL021
  324.          adc $2A
  325.          sta $BC
  326.          tya
  327.          adc $2B
  328. LBL021   sta $BD
  329.          JMP LBL022
  330. ;
  331. ;
  332. ;
  333.          lda $2C
  334.          sta $B8
  335.          lda $2D
  336.          sta $B9
  337. LBL025   jsr LBL023
  338.          jsr LBL024
  339.          eor (C_2A),Y
  340.          tax
  341.          jsr LBL004                 ; Go read a byte from the TBIL table
  342.          txa
  343.          beq LBL025
  344.          asl
  345.          beq LBL026
  346.          lda $B8
  347.          sta $2C
  348.          lda $B9
  349.          sta $2D
  350. LBL028   jmp LBL027
  351.          jsr LBL023
  352.          cmp #$0D
  353.          bne LBL028
  354. LBL026   rts
  355. ;
  356. ;
  357. ;
  358.          jsr LBL023
  359.          cmp #$5B
  360.          bcs LBL028
  361.          cmp #$41
  362.          bcc LBL028
  363.          asl
  364.          jsr LBL029
  365. LBL024   ldy #$00
  366.          lda (C_2C),Y
  367.          inc $2C
  368.          bne LBL030
  369.          inc $2D
  370. LBL030   cmp #$0D
  371.          clc
  372.          rts
  373. ;
  374. ;
  375. ;
  376. LBL031   jsr LBL024
  377. LBL023   lda (C_2C),Y
  378.          cmp #$20
  379.          beq LBL031
  380.          cmp #$3A
  381.          clc
  382.          bpl LBL032
  383.          cmp #$30
  384. LBL032   rts
  385. ;
  386. ;
  387. ;
  388.          jsr LBL023
  389.          bcc LBL028
  390.          sty $BC
  391.          sty $BD
  392. LBL033   lda $BC
  393.          ldx $BD
  394.          asl $BC
  395.          rol $BD
  396.          asl $BC
  397.          rol $BD
  398.          clc
  399.          adc $BC
  400.          sta $BC
  401.          txa
  402.          adc $BD
  403.          asl $BC
  404.          rol
  405.          sta $BD
  406.          jsr LBL024
  407.          and #$0F
  408.          adc $BC
  409.          sta $BC
  410.          tya
  411.          adc $BD
  412.          sta $BD
  413.          jsr LBL023
  414.          bcs LBL033
  415.          jmp LBL034
  416. LBL061   jsr LBL035
  417.          lda $BC
  418.          ora $BD
  419.          beq LBL036
  420. LBL065    lda $20
  421.          sta $2C
  422.          lda $21
  423.          sta $2D
  424. LBL040   jsr LBL037
  425.          beq LBL038
  426.          lda $28
  427.          cmp $BC
  428.          lda $29
  429.          sbc $BD
  430.          bcs LBL038
  431. LBL039   jsr LBL024
  432.          bne LBL039
  433.          jmp LBL040
  434. LBL038   lda $28
  435.          eor $BC
  436.          bne LBL041
  437.          lda $29
  438.          eor $BD
  439. LBL041   rts
  440. ;
  441. ;
  442. ;
  443. LBL043   jsr LBL042
  444. LBL013   jsr LBL004                 ; Entry point for TBIL PC (print literal) - Go read a byte from the TBIL table
  445.          bpl LBL043                 ; 
  446. LBL042   inc $BF
  447.          bmi LBL044
  448.          jmp OUT_V                  ; Go print it
  449. LBL044   dec $BF
  450. LBL045   rts
  451. ;
  452. ;
  453. ;
  454. LBL046   cmp #$22
  455.          beq LBL045
  456.          jsr LBL042
  457.          jsr LBL024
  458.          bne LBL046
  459. LBL036   jmp LBL015
  460. LBL047   lda #$20
  461.          jsr LBL042
  462.          lda $BF
  463.          and #$87
  464.          bmi LBL045
  465.          bne LBL047
  466.          rts
  467. ;
  468. ;
  469. ;
  470.          ldx #$7B
  471.          jsr LBL048
  472.          inc $C1
  473.          inc $C1
  474.          inc $C1
  475.          sec
  476.          lda $03,X
  477.          sbc $00,X
  478.          sta $00,X
  479.          lda $04,X
  480.          sbc $01,X
  481.          bvc LBL052
  482.          eor #$80
  483.          ora #$01
  484. LBL052   bmi LBL053
  485.          bne LBL054
  486.          ora $00,X
  487.          beq LBL049
  488. LBL054   lsr $02,X
  489. LBL049   lsr $02,X
  490. LBL053   lsr $02,X
  491.          bcc LBL050
  492. LBL004   ldy #$00                   ; Read a byte from the TBIL Table
  493.          lda (C_2A),Y               ;
  494.          inc $2A                    ; Increment TBIL Table pointer as required
  495.          bne LBL051                 ;
  496.          inc $2B                    ;
  497. LBL051   ora #$00                   ; Check for $00 and set the 'Z' flag acordingly
  498. LBL050   rts                        ; Return
  499. ;
  500. ;
  501. ;
  502.          lda $BE
  503.          beq LBL055
  504. LBL056   jsr LBL024
  505.          bne LBL056
  506.          jsr LBL037
  507.          beq LBL057
  508. LBL062   jsr LBL058
  509.          jsr BREAK
  510.          bcs LBL059
  511.          lda $C4
  512.          sta $2A
  513.          lda $C5
  514.          sta $2B
  515.          rts
  516. ;
  517. ;
  518. ;
  519. LBL059   lda LBL002
  520.          sta $2A
  521.          lda LBL003
  522.          sta $2B
  523. LBL057   jmp LBL015
  524. LBL055   sta $BF
  525.          jmp LBL060
  526.          lda $20
  527.          sta $2C
  528.          lda $21
  529.          sta $2D
  530.          jsr LBL037
  531.          beq LBL057
  532.          lda $2A
  533.          sta $C4
  534.          lda $2B
  535.          sta $C5
  536. LBL058   lda #$01
  537.          sta $BE
  538.          rts
  539. ;
  540. ;
  541. ;
  542.          jsr LBL061
  543.          beq LBL062
  544. LBL066   lda $BC
  545.          sta $28
  546.          lda $BD
  547.          sta $29
  548.          jmp LBL015
  549.          jsr LBL063
  550.          jsr LBL064
  551.          jsr LBL065
  552.          bne LBL066
  553.          rts
  554. ;
  555. ;
  556. ;
  557. LBL037   jsr LBL024
  558.          sta $28
  559.          jsr LBL024
  560.          sta $29
  561.          ora $28
  562.          rts
  563. ;
  564. ;
  565. ;
  566.          jsr LBL035
  567.          jsr LBL034
  568. LBL034   lda $BD
  569. LBL131   jsr LBL029
  570.          lda $BC
  571. LBL029   ldx $C1
  572.          dex
  573.          sta $00,X
  574.          stx $C1
  575.          cpx $C0
  576.          bne LBL067
  577. LBL068   jmp LBL015
  578. LBL097   ldx $C1
  579.          cpx #$80
  580.          bpl LBL068
  581.          lda $00,X
  582.          inc $C1
  583. LBL067   rts
  584. ;
  585. ;
  586. ;
  587. LBL010   sta $BD
  588.          stx $BC
  589.          jmp LBL069
  590.          ldx $C1
  591.          lda $01,X
  592.          bpl LBL070
  593.          jsr LBL071
  594.          lda #$2D
  595.          jsr LBL042
  596. LBL070   jsr LBL035
  597. LBL069   lda #$1F
  598.          sta $B8
  599.          sta $BA
  600.          lda #$2A
  601.          sta $B9
  602.          sta $BB
  603.          ldx $BC
  604.          ldy $BD
  605.          sec
  606. LBL072   inc $B8
  607.          txa
  608.          sbc #$10
  609.          tax
  610.          tya
  611.          sbc #$27
  612.          tay
  613.          bcs LBL072
  614. LBL073   dec $B9
  615.          txa
  616.          adc #$E8
  617.          tax
  618.          tya
  619.          adc #$03
  620.          tay
  621.          bcc LBL073
  622.          txa
  623. LBL074   sec
  624.          inc $BA
  625.          sbc #$64
  626.          bcs LBL074
  627.          dey
  628.          bpl LBL074
  629. LBL075   dec $BB
  630.          adc #$0A
  631.          bcc LBL075
  632.          ora #$30
  633.          sta $BC
  634.          lda #$20
  635.          sta $BD
  636.          ldx #$FB
  637. LBL199   stx $C3
  638.          lda $BD,X
  639.          ora $BD
  640.          cmp #$20
  641.          beq LBL076
  642.          ldy #$30
  643.          sty $BD
  644.          ora $BD
  645.          jsr LBL042
  646. LBL076   ldx $C3
  647.          inx
  648.          bne LBL199
  649.          rts
  650. ;
  651. ;
  652. ;
  653.          lda $2D
  654.          pha
  655.          lda $2C
  656.          pha
  657.          lda $20
  658.          sta $2C
  659.          lda $21
  660.          sta $2D
  661.          lda $24
  662.          ldx $25
  663.          jsr LBL077
  664.          beq LBL078
  665.          jsr LBL077
  666. LBL078   lda $2C
  667.          sec
  668.          sbc $B6
  669.          lda $2D
  670.          sbc $B7
  671.          bcs LBL079
  672.          jsr LBL037
  673.          beq LBL079
  674.          ldx $28
  675.          lda $29
  676.          jsr LBL010
  677.          lda #$20
  678. LBL080   jsr LBL042
  679.          jsr BREAK
  680.          bcs LBL079
  681.          jsr LBL024
  682.          bne LBL080
  683.          jsr LBL081
  684.          jmp LBL078
  685. LBL077   sta $B6
  686.          inc $B6
  687.          bne LBL082
  688.          inx
  689. LBL082   stx $B7
  690.          ldy $C1
  691.          cpy #$80
  692.          beq LBL083
  693.          jsr LBL061
  694. LBL099   lda $2C
  695.          ldx $2D
  696.          sec
  697.          sbc #$02
  698.          bcs LBL084
  699.          dex
  700. LBL084   sta $2C
  701.          jmp LBL085
  702. LBL079   pla
  703.          sta $2C
  704.          pla
  705.          sta $2D
  706. LBL083   rts
  707. LBL081   lda $BF
  708.          bmi LBL083
  709. ;
  710. ;
  711. ; Routine to handle CR, LF and pad characters in the ouput
  712. ;
  713. LBL001   lda #$0D                   ; Load up a CR
  714.          jsr OUT_V                  ; Go print it
  715.          lda PCC                    ; Load the pad character code
  716.          and #$7F                   ; Test to see - 
  717.          sta $BF                    ; how many pad charachters to print
  718.          beq LBL086                 ; Skip if 0
  719. LBL088   jsr LBL087                 ; Go print pad charcter
  720.          dec $BF                    ; One less
  721.          bne LBL088                 ; Loop until 0
  722. LBL086   lda #$0A                   ; Load up a LF
  723.          jmp LBL089                 ; Go print it
  724. ;
  725. ;
  726. ;
  727. LBL092   ldy TMC
  728. LBL091   sty $BF
  729.          bcs LBL090
  730.          lda #$30                   ; Entry pont for TBIL GL (get input line)
  731.          sta $2C
  732.          sta $C0
  733.          sty $2D
  734.          jsr LBL034
  735. LBL090   eor $80
  736.          sta $80
  737.          jsr IN_V
  738.          ldy #$00
  739.          ldx $C0
  740.          and #$7F
  741.          beq LBL090
  742.          cmp #$7F
  743.          beq LBL090
  744.          cmp #$13
  745.          beq LBL091
  746.          cmp #$0A
  747.          beq LBL092
  748.          cmp LSC
  749.          beq LBL093
  750.          cmp BSC
  751.          bne LBL094
  752.          cpx #$30
  753.          bne LBL095
  754. LBL093   ldx $2C
  755.          sty $BF
  756.          lda #$0D
  757. LBL094   cpx $C1
  758.          bmi LBL096
  759.          lda #$07
  760.          jsr LBL042
  761.          jmp LBL090
  762. LBL096   sta $00,X
  763.          inx
  764.          inx
  765. LBL095   dex
  766.          stx $C0
  767.          cmp #$0D
  768.          bne LBL090
  769.          jsr LBL081
  770. LBL035   jsr LBL097
  771.          sta $BC
  772.          jsr LBL097
  773.          sta $BD
  774.          rts
  775. ;
  776. ;
  777. ;
  778.          jsr LBL098
  779.          jsr LBL061
  780.          php
  781.          jsr LBL099
  782.          sta $B8
  783.          stx $B9
  784.          lda $BC
  785.          sta $B6
  786.          lda $BD
  787.          sta $B7
  788.          ldx #$00
  789.          plp
  790.          bne LBL100
  791.          jsr LBL037
  792.          dex
  793.          dex
  794. LBL101   dex
  795.          jsr LBL024
  796.          bne LBL101
  797. LBL100   sty $28
  798.          sty $29
  799.          jsr LBL098
  800.          lda #$0D
  801.          cmp (C_2C),Y
  802.          beq LBL102
  803.          inx
  804.          inx
  805.          inx
  806. LBL103   inx
  807.          iny
  808.          cmp (C_2C),Y
  809.          bne LBL103
  810.          lda $B6
  811.          sta $28
  812.          lda $B7
  813.          sta $29
  814. LBL102   lda $B8
  815.          sta $BC
  816.          lda $B9
  817.          sta $BD
  818.          clc
  819.          ldy #$00
  820.          txa
  821.          beq LBL104
  822.          bpl LBL105
  823.          adc $2E
  824.          sta $B8
  825.          lda $2F
  826.          sbc #$00
  827.          sta $B9
  828. LBL109   lda (C_2E),Y
  829.          sta (C_B8),Y
  830.          ldx $2E
  831.          cpx $24
  832.          bne LBL106
  833.          lda $2F
  834.          cmp $25
  835.          beq LBL107
  836. LBL106   inx
  837.          stx $2E
  838.          bne LBL108
  839.          inc $2F
  840. LBL108   inc $B8
  841.          bne LBL109
  842.          inc $B9
  843.          bne LBL109
  844. LBL105   adc $24
  845.          sta $B8
  846.          sta $2E
  847.          tya
  848.          adc $25
  849.          sta $B9
  850.          sta $2F
  851.          lda $2E
  852.          sbc $C6
  853.          lda $2F
  854.          sbc $C7
  855.          bcc LBL110
  856.          dec $2A
  857.          jmp LBL015
  858. LBL110   lda (C_24),Y
  859.          sta (C_2E),Y
  860.          ldx $24
  861.          bne LBL111
  862.          dec $25
  863. LBL111   dec $24
  864.          ldx $2E
  865.          bne LBL112
  866.          dec $2F
  867. LBL112   dex
  868.          stx $2E
  869.          cpx $BC
  870.          bne LBL110
  871.          ldx $2F
  872.          cpx $BD
  873.          bne LBL110
  874. LBL107   lda $B8
  875.          sta $24
  876.          lda $B9
  877.          sta $25
  878. LBL104   lda $28
  879.          ora $29
  880.          beq LBL113
  881.          lda $28
  882.          sta (C_BC),Y
  883.          iny
  884.          lda $29
  885.          sta (C_BC),Y
  886. LBL114   iny
  887.          sty $B6
  888.          jsr LBL024
  889.          php
  890.          ldy $B6
  891.          sta (C_BC),Y
  892.          plp
  893.          bne LBL114
  894. LBL113   jmp LBL014
  895.          jsr LBL115
  896.          lda $03,X
  897.          and #$80
  898.          beq LBL116
  899.          lda #$FF
  900. LBL116   sta $BC
  901.          sta $BD
  902.          pha
  903.          adc $02,X
  904.          sta $02,X
  905.          pla
  906.          pha
  907.          adc $03,X
  908.          sta $03,X
  909.          pla
  910.          eor $01,X
  911.          sta $BB
  912.          bpl LBL117
  913.          jsr LBL118
  914. LBL117   ldy #$11
  915.          lda $00,X
  916.          ora $01,X
  917.          bne LBL119
  918.          jmp LBL015
  919. LBL119   sec
  920.          lda $BC
  921.          sbc $00,X
  922.          pha
  923.          lda $BD
  924.          sbc $01,X
  925.          pha
  926.          eor $BD
  927.          bmi LBL120
  928.          pla
  929.          sta $BD
  930.          pla
  931.          sta $BC
  932.          sec
  933.          jmp LBL121
  934. LBL120   pla
  935.          pla
  936.          clc
  937. LBL121   rol $02,X
  938.          rol $03,X
  939.          rol $BC
  940.          rol $BD
  941.          dey
  942.          bne LBL119
  943.          lda $BB
  944.          bpl LBL122
  945. LBL071   ldx $C1
  946. LBL118   sec
  947.          tya
  948.          sbc $00,X
  949.          sta $00,X
  950.          tya
  951.          sbc $01,X
  952.          sta $01,X
  953. LBL122   rts
  954. ;
  955. ;
  956. ;
  957.          jsr LBL071
  958.          jsr LBL115
  959.          lda $00,X
  960.          adc $02,X
  961.          sta $02,X
  962.          lda $01,X
  963.          adc $03,X
  964.          sta $03,X
  965.          rts
  966. ;
  967. ;
  968. ;
  969.          jsr LBL115
  970.          ldy #$10
  971.          lda $02,X
  972.          sta $BC
  973.          lda $03,X
  974.          sta $BD
  975. LBL124   asl $02,X
  976.          rol $03,X
  977.          rol $BC
  978.          rol $BD
  979.          bcc LBL123
  980.          clc
  981.          lda $02,X
  982.          adc $00,X
  983.          sta $02,X
  984.          lda $03,X
  985.          adc $01,X
  986.          sta $03,X
  987. LBL123   dey
  988.          bne LBL124
  989.          rts
  990. ;
  991. ;
  992. ;
  993.          jsr LBL097
  994.          tax
  995.          lda $00,X
  996.          ldy $01,X
  997.          dec $C1
  998.          ldx $C1
  999.          sty $00,X
  1000.          jmp LBL029
  1001.          ldx #$7D
  1002.          jsr LBL048
  1003.          lda $01,X
  1004.          pha
  1005.          lda $00,X
  1006.          pha
  1007.          jsr LBL097
  1008.          tax
  1009.          pla
  1010.          sta $00,X
  1011.          pla
  1012.          sta $01,X
  1013.          rts
  1014.          jsr LBL063
  1015.          lda $BC
  1016.          sta $2A
  1017.          lda $BD
  1018.          sta $2B
  1019.          rts
  1020. ;
  1021. ;
  1022. ;
  1023.          ldx #$2C                   ; Entry point to Save Basic Pointer SB
  1024.          bne LBL125
  1025.          ldx #$2E
  1026. LBL125   lda $00,X
  1027.          cmp #$80
  1028.          bcs LBL098
  1029.          lda $01,X
  1030.          bne LBL098
  1031.          lda $2C
  1032.          sta $2E
  1033.          lda $2D
  1034.          sta $2F
  1035.          rts
  1036. ;
  1037. ;
  1038. ;
  1039. LBL098   lda $2C
  1040.          ldy $2E
  1041.          sty $2C
  1042.          sta $2E
  1043.          lda $2D
  1044.          ldy $2F
  1045.          sty $2D
  1046.          sta $2F
  1047.          ldy #$00
  1048.          rts
  1049. ;
  1050. ;
  1051. ;
  1052.          lda $28
  1053.          sta $BC
  1054.          lda $29
  1055.          sta $BD
  1056.          jsr LBL126
  1057.          lda $C6
  1058.          sta $26
  1059.          lda $C7
  1060. LBL064   sta $27
  1061. LBL129   rts
  1062. ;
  1063. ;
  1064. ;
  1065. LBL063   lda (C_C6),Y
  1066.          sta $BC
  1067.          jsr LBL127
  1068.          lda (C_C6),Y
  1069.          sta $BD
  1070. LBL127   inc $C6
  1071.          bne LBL128
  1072.          inc $C7
  1073. LBL128   lda $22
  1074.          cmp $C6
  1075.          lda $23
  1076.          sbc $C7
  1077.          bcs LBL129
  1078.          jmp LBL015
  1079.          jsr LBL130
  1080.          sta $BC
  1081.          tya
  1082.          jmp LBL131
  1083. LBL130   jsr LBL035
  1084.          lda $BC
  1085.          sta $B6
  1086.          jsr LBL035
  1087.          lda $BD
  1088.          sta $B7
  1089.          ldy $BC
  1090.          jsr LBL035
  1091.          ldx $B7
  1092.          lda $B6
  1093.          clc
  1094.          jmp (C_00BC)
  1095.          jsr LBL132
  1096. LBL132   jsr LBL004                 ; Go read a byte from the TBIL Table
  1097.          jmp LBL029
  1098. LBL085   stx $2D
  1099.          cpx #$00
  1100.          rts
  1101. ;
  1102. ;
  1103. ;
  1104.          ldy #$02
  1105.          sty $BC
  1106.          ldy #$29
  1107.          sty $BD
  1108.          ldy #$00
  1109.          lda (C_BC),Y
  1110.          cmp #$08
  1111.          bne LBL133
  1112.          jmp LBL117
  1113. LBL133   rts
  1114. ;
  1115. ;
  1116. ; Subroutine to decide which pad character to print
  1117. ;
  1118. LBL089   jsr OUT_V                  ; Entry point with a charater to print first
  1119. LBL087   lda #$FF                   ; Normal entry point - Set pad to $FF
  1120.          bit PCC                    ; Check if the pad flag is on
  1121.          bmi LBL134                 ; Skip it if not
  1122.          lda #$00                   ; set pad to $00
  1123. LBL134   jmp OUT_V                  ; Go print it
  1124.  
  1125.  
  1126. ;
  1127. ; TBIL Tables
  1128. ;
  1129. ILTBL    .DB $24, $3A, $91, $27, $10, $E1, $59, $C5, $2A, $56, $10, $11, $2C, $8B, $4C
  1130.          .DB $45, $D4, $A0, $80, $BD, $30, $BC, $E0, $13, $1D, $94, $47, $CF, $88, $54
  1131.          .DB $CF, $30, $BC, $E0, $10, $11, $16, $80, $53, $55, $C2, $30, $BC, $E0, $14
  1132.          .DB $16, $90, $50, $D2, $83, $49, $4E, $D4, $E5, $71, $88, $BB, $E1, $1D, $8F
  1133.          .DB $A2, $21, $58, $6F, $83, $AC, $22, $55, $83, $BA, $24, $93, $E0, $23, $1D
  1134.          .DB $30, $BC, $20, $48, $91, $49, $C6, $30, $BC, $31, $34, $30, $BC, $84, $54
  1135.          .DB $48, $45, $CE, $1C, $1D, $38, $0D, $9A, $49, $4E, $50, $55, $D4, $A0, $10
  1136.          .db $E7, $24, $3F, $20, $91, $27, $E1, $59, $81, $AC, $30, $BC, $13, $11, $82
  1137.          .db $AC, $4D, $E0, $1D, $89, $52, $45, $54, $55, $52, $CE, $E0, $15, $1D, $85
  1138.          .db $45, $4E, $C4, $E0, $2D, $98, $4C, $49, $53, $D4, $EC, $24, $00, $00, $00
  1139.          .db $00, $0A, $80, $1F, $24, $93, $23, $1D, $30, $BC, $E1, $50, $80, $AC, $59
  1140.          .db $85, $52, $55, $CE, $38, $0A, $86, $43, $4C, $45, $41, $D2, $2B, $84, $52
  1141.          .db $45, $CD, $1D, $A0, $80, $BD, $38, $14, $85, $AD, $30, $D3, $17, $64, $81
  1142.          .db $AB, $30, $D3, $85, $AB, $30, $D3, $18, $5A, $85, $AD, $30, $D3, $19, $54
  1143.          .db $2F, $30, $E2, $85, $AA, $30, $E2, $1A, $5A, $85, $AF, $30, $E2, $1B, $54
  1144.          .db $2F, $98, $52, $4E, $C4, $0A, $80, $80, $12, $0A, $09, $29, $1A, $0A, $1A
  1145.          .db $85, $18, $13, $09, $80, $12, $01, $0B, $31, $30, $61, $72, $0B, $04, $02
  1146.          .db $03, $05, $03, $1B, $1A, $19, $0B, $09, $06, $0A, $00, $00, $1C, $17, $2F
  1147.          .db $8F, $55, $53, $D2, $80, $A8, $30, $BC, $31, $2A, $31, $2A, $80, $A9, $2E
  1148.          .db $2F, $A2, $12, $2F, $C1, $2F, $80, $A8, $30, $BC, $80, $A9, $2F, $83, $AC
  1149.          .db $38, $BC, $0B, $2F, $80, $A8, $52, $2F, $84, $BD, $09, $02, $2F, $8E, $BC
  1150.          .db $84, $BD, $09, $93, $2F, $84, $BE, $09, $05, $2F, $09, $91, $2F, $80, $BE
  1151.          .DB $84, $BD, $09, $06, $2F, $84, $BC, $09, $95, $2F, $09, $04, $2F, $00, $00
  1152.          .db $00
  1153. ;
  1154. ; End of Tiny Basic
  1155.  
  1156.  
  1157.  
  1158.  
  1159.          .org $1CF0    ; Address of main program
  1160.  
  1161. FBLK
  1162. ;
  1163. ; Set some symbols
  1164. ;
  1165. ACIARW   = $1200                    ; Base address of ACIA
  1166. ACIAST   = ACIARW+$01               ; ACIA status register 
  1167. ACIACM   = ACIARW+$02               ; ACIA commnad register
  1168. ACIACN   = ACIARW+$03               ; ACIA control register
  1169.  
  1170. ;
  1171. ; Begin base system initialization
  1172. ;
  1173.          sta ACIAST                 ; Do a soft reset on the ACIA
  1174.          lda #$0B                   ; Set it up for :
  1175.          sta ACIACM                 ;        no echo, no parity, RTS low, No IRQ, DTR low
  1176.          lda #$1A                   ; and :
  1177.          sta ACIACN                 ;        2400, 8 bits, 1 stop bit, external Rx clock
  1178.          jsr CLRSC                  ; Go clear the screen
  1179.          ldx #$00                   ; Offset for welcome message and prompt
  1180.          jsr SNDMSG                 ; Go print it
  1181. ST_LP    JSR RCCHR                  ; Go get a character from the console
  1182.          cmp #$43                   ; Check for 'C'
  1183.          BNE IS_WRM                 ; If not branch to next check
  1184.          jmp COLD_S                 ; Otherwise cold-start Tiny Basic
  1185. IS_WRM   cmp #$57                   ; Check for 'W'
  1186.          BNE PRMPT                  ; If not, branch to re-prompt them
  1187.          jmp WARM_S                 ; Otherwise warm-start Tiny Basic
  1188. PRMPT    ldx #$2F                   ; Offset of prompt
  1189.          jsr SNDMSG                 ; Go print the prompt     
  1190.          jmp ST_LP                  ; Go get the response
  1191.  
  1192.  
  1193.          .org $1E00    ; Address of message area
  1194. MBLK
  1195.  
  1196. ;
  1197. ; The message block begins at $1E00 and is at most 256 bytes long.
  1198. ; Messages terminate with an FF.
  1199. ;
  1200.          .db "OMEGA MICRO SYSTEMS"
  1201.          .db  $0D, $0A, $0A
  1202.          .db "OMS-02 T-Basic Controller"
  1203.          .db  $0D, $0A, $0A
  1204.          .db "Boot (C/W)? "
  1205.          .db  $07, $FF
  1206.     
  1207.      .org $1F00    ;address of subroutine area
  1208. SBLK
  1209. ;
  1210. ; Begin BIOS subroutines
  1211. ;
  1212.  
  1213. ;
  1214. ; Clear the screen
  1215. ;
  1216. CLRSC    ldx #$19                   ; Load X - we're going tp print 25 lines
  1217.          lda #$0D                   ; CR
  1218.          jsr SNDCHR                 ; Send a carriage retuen
  1219.          lda #$0A                   ; LF
  1220. CSLP     jsr SNDCHR                 ; Send the line feed
  1221.          dex                        ; One less to do
  1222.          bne CSLP                   ; Go send another untill we're done
  1223.          rts                        ; Return
  1224.  
  1225. ;
  1226. ; Print a message.
  1227. ; This sub expects the messsage offset from MBLK in X.
  1228. ;
  1229. SNDMSG   lda MBLK,X                 ; Get a character from teh message block
  1230.          cmp #$FF                   ; Look for end of message marker
  1231.          beq EXSM                   ; Finish up if it is
  1232.          jsr SNDCHR                 ; Otherwise send the character
  1233.          inx                        ; Increment the pointer
  1234.          jmp SNDMSG                 ; Go get next character
  1235. EXSM     rts                        ; Return
  1236.  
  1237. ;
  1238. ; Get a character from the ACIA
  1239. ; Runs into SNDCHR to provide echo
  1240. ;
  1241. RCCHR    ;lda ACIAST                ; Read the ACAI status to (for OMS-02)
  1242.          ;and #$08                  ; Check if there is character in the receiver (for OMS-02)
  1243.          ;beq RCCHR                 ; Loop util we get one (for OMS-02)
  1244.          ;lda ACIARW                ; Load it into the accumulator (for OMS-02)
  1245.          LDA $E004                  ; Check if a character typed (for emulator)
  1246.          BEQ RCCHR                  ; Loop until we get one (for emulator)
  1247.  
  1248. ;
  1249. ;Send a character to the ACIA
  1250. ;
  1251. SNDCHR   sta $FE                    ; Save the character to be printed
  1252.          cmp #$FF                   ; Check for a bunch of characters
  1253.          BEQ EXSC                   ; that we don't want to print to
  1254.          cmp #$00                      ; the terminal and discard them to
  1255.          BEQ EXSC                      ; clean up the output
  1256.          cmp #$91                      ;
  1257.          BEQ EXSC                      ;
  1258.          cmp #$93                      ;
  1259.          BEQ EXSC                      ;
  1260.          cmp #$80                      ;
  1261.          BEQ EXSC                      ;
  1262. SCLP     ;lda ACIAST                ; Check ACIA Status  (don't need for emulator)
  1263.          ;and #$10                  ; See if transmiter it busy (don't need for emulator)
  1264.          ;beq SCLP                  ; Wait for it (don't need for emulator)
  1265.          lda $FE                    ; Restore the character
  1266.          ;sta ACIARW                ; Transmit it (for OMS-02)
  1267.          STA $E001                  ; Transmit it (for emulator)
  1268. EXSC     rts                        ; Return
  1269.  
  1270.          .org $1FFC                 ; Address of reset vector (for 6507 not required for emulator)
  1271. RSVEC
  1272.          .db $F0, $1C               ; Reset vector
  1273.  
  1274.         .org $3000                  ; Address of last byte of EPROM
  1275. EOROM