Advertisement
Mysoft

Untitled

Jan 21st, 2017
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             opt 6809
  2.             opt cd
  3.             include const.asm
  4.            
  5. cHState     equ (R01_HSyncFlag|R01_MuxSelLSB|R01_HSyncIrq) ;R01_HDirection|
  6. cVState     equ (R03_VsyncFlag|R03_MuxSelMSB|R03_VsyncIrq) ;R03_VDirection|
  7. cScrStart   equ 1024
  8. cScrEnd     equ 1536
  9.            
  10.             org 32000  
  11.             lda #$FF
  12.             tfr A,DP                            ; DP = 0xFF??
  13.             SETDP $FF
  14.             orcc #(cFirqMask|cIrqMask)          ; Disable Interrupts   ; Disable IRQs
  15.  
  16.             lda <$01                            ;
  17.             ldb <$03                            ;          
  18.             anda #(^cHState)                    ; Disable Hsync Interrupt / Clear Flag          
  19.             ora  #(R01_MuxSelLSB)               ; (Sound Source Cassette)
  20.             sta <$01                            ; (Sound Source cassette)          
  21.             andb #(^cVState)                    ; Disable Vsync Interrupt / Clear Flag
  22.             stb <$03                            ;
  23.  
  24.             lda <$21
  25.             ldb <$23
  26.             ora #R21_DPolarity                  ; Output Direction
  27.             sta <$21    
  28.             orb  #R23_SoundOn                   ; and Enable Sound
  29.             stb <$23                            ;
  30.  
  31. ; **************************************************
  32. ; ************** Setup Initial State ***************
  33. ; **************************************************
  34.            
  35. ; **************************************************
  36. ; **************** Initial Sync UP *****************
  37. ; **************************************************        
  38. ;bne SYNCUP                         ;~03|26 no? then just continue
  39.            
  40. SYNCUP:     ldx #cScrStart+64                   ;~03 start of screen
  41.             ldu #cScrStart                      ;~03
  42.             clr ,U                              ;~06
  43.             bra SYNCBYTE                        ;~03
  44.  
  45. @SYNC9BIT:  tstb                                ;~02|17
  46.             bpl @IS1                            ;~03|20
  47. @IS0:       lsr <$20                            ;~06|06 read 1st sample
  48.             bcc @IS0                            ;~03|09
  49.             lsr <$20                            ;~06|15
  50.             bcc @IS0                            ;~03|18
  51.             lsr <$20                            ;~06|24
  52.             bcc @IS0                            ;~03|27
  53.             bra @SYNCCHK                        ;~03|30
  54. ;;
  55. @IS1:       lsr <$20                            ;~06|06 read 1st sample
  56.             bcs @IS1                            ;~03|09
  57.             lsr <$20                            ;~06|15
  58.             bcs @IS1                            ;~03|18
  59.             lsr <$20                            ;~06|24
  60.             bcs @IS1                            ;~03|27
  61.             bra @SYNCCHK                        ;~03|30
  62. ;;
  63. @SYNCCHK:   sta ,X+                             ;~06|36 store byte on screen
  64.             cmpx #cScrEnd                       ;~04|40 reached end of string?
  65.             beq @DOWRAP                         ;~03|43 yes then go put back on start
  66.             bra @NOWRAP                         ;~03|46|no? then skip putting back
  67. @DOWRAP:    ldx #cScrStart+64                   ;~03|46|yes? then reload to start pos
  68. @NOWRAP:    cmpa #$4B                           ;~02|48 $4B
  69.             beq @STAGE1                         ;~03|51 if char is 4B Assert Stage 1
  70.             tsta                                ;~02|53 $00
  71.             beq @STAGE2                         ;~03|56 if char is 00 Check/Try Stage 2
  72.             inca                                ;~02|58 $FF
  73.             beq @STAGE3                         ;~03|61 if char is FF Check/Try Stage 3        
  74.             clr ,U                              ;~06|67    
  75.             bra @SYNCW70                        ;~03|70    
  76. ;;
  77. @STAGE1:    tst ,U                              ;~06|57 check state
  78.             bne @SYNCW60                        ;~03|60 non zero than already Stage 1
  79.             inc ,U                              ;~06|66 Set state to Stage1 (01)
  80.             jmp @SYNCW70,PCR                    ;~04|70 and go read next byte
  81. ;;
  82. @STAGE2:    tst ,U                              ;~06|62 check state
  83.             beq @SYNCW65                        ;~03|65 zero? than can't proceed
  84.             tst ,U                              ;~06|71
  85.             bmi @SYNCW74                        ;~03|74    
  86.             neg 0,U                             ;~07|81
  87.             tfr D,D                             ;~06|87 Set state to Stage2 (FF)    
  88.             bra SYNCBYTE                        ;~03|90 and go read next byte
  89. ;;
  90. @STAGE3:    tst ,U                              ;~06|67 check state
  91.             bpl @SYNCW70                        ;~03|70 positive? then can't proceed
  92.             jmp START,PCR                       ;~04|74 Sync finished go read bits :)
  93. ;;
  94. @SYNCW60:   stx <$FE                            ;~05|65 +
  95. @SYNCW65:   bra @SYNCW68                        ;~03|68 +
  96. @SYNCW68:   nop                                 ;~02|70 +
  97. @SYNCW70:   bita <$FE                           ;~04|74 +
  98. @SYNCW74:   pshs X,DP                           ;~08|82 +
  99.             puls X,DP                           ;~08|90 > wait til 90 cycles
  100. ;;          
  101. SYNCBYTE:   lda #128                            ;~02|02 holds byte and rotate signal
  102. @SYNCBIT:   ldb <$20                            ;~04|06 read 1st sample
  103.             andb #1                             ;~02|08 add carry to sum
  104.             pshs X,Y,D,DP                       ;~12|20
  105.             puls X,Y,D,DP                       ;~12|32
  106. ;;
  107.             lsr <$20                            ;~06|08 read 2nd sample
  108.             adcb #0                             ;~02|10 add carry to sum
  109.             pshs X,Y,D                          ;~11|20 +
  110.             puls X,Y,D                          ;~11|32 > wait till 30+2 cycles    
  111. ;;
  112.             lsr <$20                            ;~06|08 read 3rd sample
  113.             adcb #254                           ;~02|10 add carry to sum
  114.             rora                                ;~02|12 rotate into byte buffer
  115.             bcs @SYNC9BIT                       ;~03|15 rotated 8 bits? then go sync
  116.             pshs X                              ;~07|22
  117.             puls X                              ;~07|29
  118.             bra @SYNCBIT                        ;~03|32 go read next bit
  119.            
  120. ; **************************************************
  121. ; ******** in Sync can start reading bytes *********
  122. ; **************************************************                                            
  123.                                                 ;   |74 <- jump from there
  124. START:      ldx #cScrStart                      ;~03|77 start screen position
  125.             ldd #$3071                          ;~03|80 chars for 0,1
  126.             pshs D                              ;~07|87 store chars    
  127.             bra NEXTBYTE                        ;~03|90 align to 90 cycles
  128. ;;          
  129. NEXTBYTE:   lda #128                            ;~02|02 holds byte and rotate signal
  130. @NEXTBIT:   ldb <$20                            ;~04|06 read 1st sample
  131.             andb #1                             ;~02|08 add carry to sum
  132.             pshs X,Y,D,DP                       ;~12|20
  133.             puls X,Y,D,DP                       ;~12|32
  134. ;;
  135.             lsr <$20                            ;~06|08 read 2nd sample
  136.             adcb #0                             ;~02|10 add carry to sum
  137.             pshs X,Y,D                          ;~11|20 +
  138.             puls X,Y,D                          ;~11|32 > wait till 30+2 cycles    
  139. ;;
  140.             lsr <$20                            ;~06|08 read 3rd sample
  141.             adcb #254                           ;~02|10 add carry to sum
  142.             rora                                ;~02|12 rotate into byte buffer
  143.             bcs LASTBIT                         ;~03|15 rotated 8 bits? then go sync
  144.             pshs X                              ;~07|22
  145.             puls X                              ;~07|29
  146.             bra @NEXTBIT                        ;~03|32 go read next bit
  147.  
  148. ; ==== AND SO START READING NORMAL BITS ====
  149. LASTBIT:    tstb                                ;~02|17
  150.             bpl @IS1                            ;~03|20
  151. @IS0:       lsr <$20                            ;~06|06 read 1st sample
  152.             bcc @IS0                            ;~03|09
  153.             lsr <$20                            ;~06|15
  154.             bcc @IS0                            ;~03|18
  155.             lsr <$20                            ;~06|24
  156.             bcc @IS0                            ;~03|27
  157.             bra @GOTBYTE                        ;~03|30
  158. ;;
  159. @IS1:       lsr <$20                            ;~06|06 read 1st sample
  160.             bcs @IS1                            ;~03|09
  161.             lsr <$20                            ;~06|15
  162.             bcs @IS1                            ;~03|18
  163.             lsr <$20                            ;~06|24
  164.             bcs @IS1                            ;~03|27
  165.             bra @GOTBYTE                        ;~03|30
  166. ;;
  167. @GOTBYTE:   tsta                                ;~02|32 char is null?
  168.             bne @DOWRITE                        ;~03|35 yes? then skip it
  169.             lda #8                              ;~02|37 waits 9*5 cycles later      
  170.             clr 0,X                             ;~07|44
  171. @REUSE1:    bra @NOWRAP                         ;~03|47 go wait for next byte
  172. ;;
  173. @DOWRITE:   sta ,X+                             ;~06|41 store byte on screen        
  174.             lda #6                              ;~02|43 waits 6*5 cycles later
  175.             bita <$FF                           ;~04|47 plus 4 cycles waiting to align
  176.             cmpx #cScrEnd                       ;~04|51 reached end of string?
  177.             bne @REUSE1                         ;~03|54 yes then go put back on start          
  178.             ldx #cScrStart                      ;~03|57 yes? then reload to start pos
  179. ;;
  180. @NOWRAP:    deca                                ;~02|?? +
  181.             bne @NOWRAP                         ;~03|87 > sync to 85
  182.             bra NEXTBYTE                        ;~03|90 go read another byte
  183.  
  184.            
  185.             end 32000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement