?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.     ifdef GS
  2.     macro GS_WaitCommand
  3. .wait
  4.     in a, (GeneralSound.CMD)
  5.     rrca
  6.     jr c, .wait
  7.     endm
  8.  
  9.     macro GS_WaitData
  10. .wait
  11.     in a, (GeneralSound.CMD)
  12.     rlca
  13.     jr c, .wait
  14.     endm
  15.  
  16.     macro GS_SendCommand nn
  17.     ld a, nn : out (GeneralSound.CMD), a
  18.     endm
  19.  
  20.     module GeneralSound
  21. ;; Control ports
  22. CMD  = 187
  23. DATA = 179
  24.  
  25. ;; Commands
  26. CMD_WARM_RESET      = #F3
  27. CMD_COLD_RESET      = #F4
  28. CMD_LOAD_MODULE     = #30
  29. CMD_PLAY_MODULE     = #31
  30. CMD_STOP_MODULE     = #32
  31. CMD_CONTINUE_MODULE = #33
  32. CMD_OPEN_STREAM     = #D1
  33. CMD_CLOSE_STREAM    = #D2
  34.  
  35. ; A - 0 warm reset, other - cold
  36. init:
  37.     and a : jr nz, .cold
  38.     GS_SendCommand CMD_WARM_RESET
  39.     ret
  40. .cold
  41.     GS_SendCommand CMD_COLD_RESET
  42.     ret
  43.  
  44. ;; Initializes loading module
  45. loadModule:
  46.     GS_SendCommand CMD_LOAD_MODULE
  47.     GS_WaitCommand
  48.     GS_SendCommand CMD_OPEN_STREAM
  49.     GS_WaitCommand
  50.     ret
  51.  
  52. ;; Use it for streaming mod file
  53. sendByte:
  54.     out (DATA), a
  55.     GS_WaitData
  56.     ret
  57.  
  58. ;; Call it when module was loaded
  59. finishLoadingModule:
  60.     GS_SendCommand CMD_CLOSE_STREAM
  61.     GS_WaitCommand
  62. rewind:
  63.     ld a, 1 : out (DATA), a
  64.     GS_SendCommand CMD_PLAY_MODULE
  65.     GS_WaitCommand
  66.     ld a, 1, (state),a
  67.     ret
  68.  
  69. ;; Works like pause too
  70. stopModule:
  71.     xor a : ld (state), a
  72.     GS_SendCommand CMD_STOP_MODULE
  73.     ret
  74.  
  75. continueModule:
  76.     ld a, 1 : ld (state), a
  77.     GS_SendCommand CMD_CONTINUE_MODULE
  78.     ret
  79.  
  80. ; Pauses resumes
  81. toggleModule:
  82.     call Console.waitForKeyUp
  83.     ld a, (state) : and a
  84.     jr z, continueModule
  85.     jr stopModule
  86.  
  87. state db 0
  88.     endmodule
  89.  
  90.     endif