Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     ; Initialization
  2.     *= $200     ; Start at $200 -> 512
  3.    
  4. io_clrw = $E000
  5. io_putc = $E001
  6. io_putn = $E002
  7. io_puth = $E003
  8. io_getc = $E004
  9. io_chol = $E005
  10. io_cvel = $E006
  11.    
  12.     ; Start Calculator System
  13.     STA io_clrw ; Clean Screen
  14.     LDY #$0
  15.  
  16. InputLoop: ; <--------------------------------------------------+
  17.     JSR Input       ;               |
  18.     ;JSR Output     ;               |
  19.     PHA         ;               |
  20.     JSR IsNumber        ;               |
  21.     JSR Outhex      ;               |
  22.     PLA         ;               |
  23.     STA InputString, Y  ;               |
  24.     INY         ;               |
  25.                 ;               |
  26.                 ; if Input == KEY_ENTER     |
  27.     CMP #$0D        ;   jmp InputLoopFail ---+  |
  28.     BEQ InputLoopCalc   ; else               |  |
  29.     JMP InputLoop       ;   jmp InputLoop   -----|--+
  30. InputLoopCalc:          ; <--------------------------+
  31.     JSR Error
  32.     JMP Exit        ; -------+
  33. InputLoopError:         ;    |
  34.     JSR Error       ;    |
  35.     JMP Exit        ; -------+
  36.                 ;    |
  37.                 ;    v
  38.                 ;        |
  39. Exit:               ; <------+
  40.     BRK ; End of Program
  41.    
  42.     ; Subroutines   (Standard)
  43.    
  44. Output  ; input: ascii char per Accumulator
  45.     STA io_putc
  46.     RTS
  47.    
  48. Outhex  ; input: ascii char per Acumulator
  49.     STA io_puth
  50.     RTS
  51.  
  52. Input   ; output: ascii char per Accumulator
  53. .Input_wait:
  54.     LDA io_getc
  55.     BEQ .Input_wait
  56.     RTS
  57. Error   ;
  58.     LDA #'E'
  59.     STA io_putc
  60.     LDA #'r'
  61.     STA io_putc
  62.     STA io_putc
  63.     PHA
  64.     LDA #'o'
  65.     STA io_putc
  66.     PLA
  67.     STA io_putc
  68.     RTS
  69.  
  70. IsNumber
  71.     CMP #$39
  72.     BCC .IsNumber_Next
  73.     JMP .IsNumber_Not
  74. .IsNumber_Next:
  75.     CMP #$30
  76.     BCS .IsNumber_True
  77.     JMP .IsNumber_Not
  78. .IsNumber_True:
  79.     LDA #$1 ; True
  80.     JMP .IsNumber_Exit
  81. .IsNumber_Not:
  82.     LDA #$0 ; False
  83.     JMP .IsNumber_Exit
  84. .IsNumber_Exit:
  85.     RTS
  86.    
  87. PrintString
  88.     RTS
  89.    
  90.    
  91.    
  92.     ; Subroutines   (Calc)
  93.    
  94.     ; Global Variables
  95. InputString:    .DB $00
  96.  
  97.     ; Global Constants
  98. KeyEnter:   .BYTE $0D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement