Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     *= $0       ; $00 = Zeropage, $10 = Stack
  2.    
  3.     .START Main
  4. Zahl1   .DB $00
  5.     *= * + 2    ; byte Zahl1[2]
  6. Zahl2   .DB $00
  7.     *= * + 2    ; byte Zahl2[2]
  8. Real1   .DB $00
  9.             ; byte Real1
  10. Real2   .DB $00
  11.             ; byte Real2
  12. InputMsg .BYTE "Eingabe: ", $0
  13.    
  14.     *= $200
  15. io_area = $e000
  16. io_cls  = io_area + 0   ; io_cls()
  17. io_putc = io_area + 1   ; io_putc()
  18. io_putr = io_area + 2   ; io_putr()
  19. io_puth = io_area + 3   ; io_puth()
  20. io_getc = io_area + 4   ; io_getc()
  21.  
  22. mul_a   = $2006
  23. mul_b   = $2007
  24. mul_el  = $2000
  25. mul_eh  = $2001
  26. mul_ex  = $2002
  27.    
  28. Main:          
  29.             ; main()
  30.     LDY #$0
  31.             ; Y = 0x1
  32. .GetKey        
  33.             ; while(Y < 2)
  34.     LDA io_getc
  35.     BEQ .GetKey
  36.             ;   if !io_getc()   goto GetKey
  37.     TAX
  38.     TYA
  39.     PHA
  40.     TXA
  41.             ;   [Push] Y by X=A -> A=Y -> [Push] A -> A=X
  42.     PHA
  43.     PHA     ;   [Push] A,A
  44.     JSR IsNumber
  45.     PLA
  46.     BEQ .GetKey
  47.             ;   if !IsNumber(A) goto GetKey else
  48.     PLA
  49.     STA io_putc
  50.             ;   [Pop] A, io_putc()
  51.     TAX
  52.     PLA
  53.     TAY
  54.    
  55.     TXA
  56.             ;   [Pop] Y by X=A -> [Pop] A -> Y = A -> A = X
  57.     SEC
  58.     SBC #$30
  59.             ;   A = A - 0x30
  60.     STA Zahl1, Y
  61.             ;   Zahl1[Y] = A
  62.            
  63.     TYA
  64.     CMP #$2
  65.     BEQ .GetKeyEnd
  66.     INY
  67.     JMP .GetKey
  68.             ;   if Y == 2   goto GetKeyEnd  else
  69.             ;                       Y++
  70.             ;                       goto GetKey
  71.    
  72. .GetKeyEnd
  73.     LDY #$0
  74.     LDA Zahl1, Y
  75.     STA mul_a
  76.     LDA #$64
  77.     STA mul_b
  78.     JSR Mul
  79.     LDA mul_el
  80.     STA Real1
  81.             ; Real1 = Mul(Zahl1[0], 0x64)
  82.     LDY #$1
  83.     LDA Zahl1, Y
  84.     STA mul_a
  85.     LDA #$a
  86.     STA mul_b
  87.     JSR Mul
  88.     LDA mul_el
  89.     CLC
  90.     ADC Real1
  91.     STA Real1
  92.             ; Real1 = Real1 + Mul(Zahl1[1], 0xA)
  93.     LDY #$2
  94.     LDA Zahl1, Y
  95.     CLC
  96.     ADC Real1
  97.     STA Real1
  98.             ; Real1 = Real1 + Zahl1[2]
  99.        
  100.             ; io_puth(Real1)
  101.            
  102.     LDY $0
  103.             ; Y = 0x0
  104.            
  105. .GetKey2           
  106.             ; while(Y < 2)
  107.     LDA io_getc
  108.     BEQ .GetKey2   
  109.             ;   if !io_getc()   goto GetKey
  110.     TAX
  111.     TYA
  112.     PHA
  113.     TXA
  114.             ;   [Push] Y by X=A -> A=Y -> [Push] A -> A=X
  115.     PHA
  116.     PHA     ;   [Push] A,A
  117.     JSR IsNumber
  118.     PLA
  119.     BEQ .GetKey2
  120.             ;   if !IsNumber(A) goto GetKey else
  121.     PLA
  122.     STA io_putc
  123.             ;   [Pop] A, io_putc()
  124.     TAX
  125.     PLA
  126.     TAY
  127.    
  128.     TXA
  129.             ;   [Pop] Y by X=A -> [Pop] A -> Y = A -> A = X
  130.     SEC
  131.     SBC #$30
  132.             ;   A = A - 0x30
  133.     STA Zahl2, Y
  134.             ;   Zahl2[Y] = A
  135.            
  136.     TYA
  137.     CMP #$2
  138.     BEQ .GetKeyEnd2
  139.     INY
  140.     JMP .GetKey2
  141.             ;   if Y == 2   goto GetKeyEnd  else
  142.             ;                       Y++
  143.             ;                       goto GetKey
  144.    
  145. .GetKeyEnd2
  146.     LDY #$0
  147.     LDA Zahl2, Y
  148.     STA mul_a
  149.     LDA #$64
  150.     STA mul_b
  151.     JSR Mul
  152.     LDA mul_el
  153.     STA Real2
  154.             ; Real2 = Mul(Zahl2[0], 0x64)
  155.     LDY #$1
  156.     LDA Zahl2, Y
  157.     STA mul_a
  158.     LDA #$a
  159.     STA mul_b
  160.     JSR Mul
  161.     LDA mul_el
  162.     CLC
  163.     ADC Real2
  164.     STA Real2
  165.             ; Real2 = Real2 + Mul(Zahl2[1], 0xA)
  166.     LDY #$2
  167.     LDA Zahl2, Y
  168.     CLC
  169.     ADC Real2
  170.     STA Real2
  171.             ; Real2 = Real2 + Zahl2[2]
  172.    
  173.     LDA Real2      
  174.     STA io_puth
  175.             ; io_puth(Real2)
  176.    
  177.     BRK    
  178.             ; BRK()
  179.            
  180.     ; End of Programm, HALT
  181.    
  182. DisplayS:
  183.             ; Display() ---> Later
  184.     RTS
  185.  
  186.  
  187. IsNumber:
  188.             ; IsNumber()
  189.     PLA
  190.     TAX
  191.     PLA
  192.     TAY
  193.             ; X, Y = [Top], [Top]
  194.    
  195.     PLA
  196.             ; A = [Top]
  197.     CMP #$30
  198.     BCC .IsNumber_False
  199.     CMP #$3a
  200.     BCS .IsNumber_False
  201.             ; if A < 0x30 && A >= 0x3a goto IsNumber_False
  202.     LDA #$1
  203.     PHA
  204.     JMP .IsNumber_Return
  205.             ; return 0x1;
  206. .IsNumber_False
  207.     LDA #$0
  208.     PHA
  209.             ; return 0x0;
  210. .IsNumber_Return
  211.     TYA
  212.     PHA
  213.     TXA
  214.     PHA
  215.     RTS
  216.  
  217. Add_16:        
  218.             ; Add_16()
  219.     CLC
  220.     LDA $2000
  221.     ADC $2002
  222.     STA $2000
  223.             ; *(0x2000) = *(0x2000) + *(0x2002)
  224.     LDA $2001
  225.     ADC $2003
  226.     STA $2001
  227.     RTS
  228.             ; return *(0x2001) = *(0x2001) + *(0x2003)
  229.    
  230. Mul:       
  231.             ; Mul()
  232.  
  233.     LDY #$00
  234.     STY $2000
  235.     STY $2001
  236.             ; *(0x2000), *(0x2001) = 0x0
  237.     LDA $2007
  238.     BEQ .Mul_Exit
  239.    
  240.     STY $2003
  241.  
  242. .Mul_Init_Multiplicant
  243.  
  244.     LDY $2006
  245.     STY $2002
  246.    
  247. .Mul_Next_Digit
  248.     LSR
  249.    
  250.     TAY
  251.     BCC .Mul_Skip_Add
  252.             ; if *(0x2007) << 1 < [Pop] A   goto SKIP_ADD
  253.    
  254. .Mul_Add
  255.     JSR Add_16
  256.             ; ADD_16()
  257.  
  258. .Mul_Skip_Add
  259. .Mul_Shift
  260.             ; SkipAdd() = Shift()
  261.     ASL $2002
  262.     ROL $2003
  263.    
  264.     TYA
  265.     BNE .Mul_Next_Digit
  266. .Mul_Exit
  267.     RTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement