Advertisement
Xandaros

Disk Drive Test

May 2nd, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. !zone Main
  2.     !to "disk_32e5370fc2358b90.img"
  3.     *=0x500
  4.     JMP Main
  5.  
  6. !zone Init {
  7. Init    SEC
  8.     XCE
  9.     REP #$30        ; 16-bit mode
  10.     !al
  11.  
  12.     LDA #$1
  13.     MMU #$0         ; map device 1 to redbus window
  14.     LDA #$300
  15.     MMU #$1         ; redbus window situated at 0x300
  16.     MMU #$2         ; enable redbus
  17.  
  18.     LDA #$400
  19.     MMU #$3         ; external memory situated at 0x400
  20.     MMU #$4         ; enable external memory
  21.  
  22.     LDA #$500
  23.     MMU #$6         ; POR = 0x500, whatever that might be
  24.  
  25.     LDA #0
  26.     JSR Output      ; Clear IO Expander
  27.  
  28.     RTS
  29. }
  30.  
  31. !zone Output {
  32. Output  PHA         ; Only works in 16-bit mode!
  33.     LDA #$3
  34.     MMU #$0
  35.  
  36.     PLA
  37.     STA $302
  38.  
  39.     PHA
  40.     LDA #$1
  41.     MMU #$0
  42.     PLA
  43.     RTS
  44. }
  45.  
  46. !zone {
  47. Main    JSR Init        ; Initial stuff
  48.     LDA #0
  49.     STA $303        ; Hide cursor
  50.  
  51.     SEP #$30        ; 8-bit
  52.     !as
  53.  
  54.     LDA Text
  55.     STA $310        ; Display saved character
  56.  
  57.     REP #$30        ; 16-bit
  58.     !al
  59.  
  60. -   WAI
  61.     LDA #1
  62.     MMU #0          ; Monitor
  63.     LDA $305        ; Amount of keys
  64.     AND #$FF        ; We are in 16 bit mode and we only need one byte. Let's Mask it.
  65.     CMP #0
  66.     BEQ -           ; If there are no key presses, jump back
  67.  
  68.     DEC
  69.  
  70.     STA $304        ; Read last key
  71.  
  72.     LDA $306        ; A = Pressed key
  73.     JSR Output      ; Output the pressed key
  74.  
  75.     SEP #$30
  76.     !as
  77.     STA $310        ; Display pressed key
  78.     REP #$30
  79.     !al
  80.  
  81.     TAY         ; Save the pressed key in Y
  82.  
  83.     LDA #0
  84.     STA $305        ; Reset amount of keys
  85.  
  86.     LDA #2
  87.     MMU #0          ; Disk drive
  88.  
  89.     LDA #128
  90.     STA $D
  91.     LDA #Text
  92.     SBC #$500
  93.  
  94.     DIV $D          ; (Text-0x500)/128 =
  95.     STA $380        ; Disk Sector
  96.  
  97.     SEP #$30        ; 8-bit
  98.     !as
  99.  
  100.     LDA #4
  101.     STA $382        ; Read sector content
  102.  
  103. --  WAI         ; Wait for ready
  104.     LDA $382
  105.     CMP #$FF
  106.     BEQ .Fault      ; Something bad happened. Let's signal the user and panic
  107.     CMP #0
  108.     BNE --          ; Not ready yet, try again
  109.  
  110.     TDA         ; A = remainder of last division
  111.     TAX         ; X = remainder of last division
  112.     TYA         ; A = The key
  113.    
  114.     STA $300, X     ; Save the key into the disk buffer
  115.  
  116.     LDA #5
  117.     STA $382        ; Issue write command to disk drive
  118.  
  119. --  WAI         ; Wait for ready
  120.     LDA $382
  121.     CMP #$FF
  122.     BEQ .Fault      ; Something bad happened
  123.     CMP #0
  124.     BNE --          ; Not read yet
  125.  
  126.     STP         ; Repeating doesn't work for some reason, so let's stop here
  127.  
  128.     ;REP #$30       ; 16-bit
  129.     ;!al
  130.  
  131.     ;JMP -
  132.  
  133. .Fault  REP #$30
  134.     !al
  135.     LDA #$FFFF
  136.     JSR Output
  137.     STP
  138. }
  139.  
  140. !zone Data {
  141. Text    !8 0x20
  142.  
  143. !align 128, 0, 0
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement