Advertisement
Cthutu

Dot support

Apr 30th, 2020
1,561
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;----------------------------------------------------------------------------------------------------------------------
  2. ;; DOT command initialisation and shutdown
  3. ;;----------------------------------------------------------------------------------------------------------------------
  4.  
  5. rreg            macro   reg
  6.                 ld      bc,IO_REG_SELECT
  7.                 ld      a,reg
  8.                 out     (c),a
  9.                 ld      bc,IO_REG_ACCESS
  10.                 in      a,(c)
  11.                 endm
  12.  
  13. reg             macro   r,n
  14.                 nextreg r,n
  15.                 endm
  16.  
  17. page            macro   slot, page
  18.                 nextreg $50+slot,page
  19.                 endm
  20.  
  21. ;;----------------------------------------------------------------------------------------------------------------------
  22. ;; Saves state
  23.  
  24. OldSP           dw      0       ; Original SP
  25. OldIY           dw      0       ; Original IY
  26. OldMMUs         ds      6       ; Original MMU state
  27. OldSpeed        db      0       ; Original clock speed
  28.  
  29. ;;----------------------------------------------------------------------------------------------------------------------
  30. ;; dotStart
  31. ;;
  32. ;; Run after SP has first been saved and set up:
  33. ;;
  34. ;;              ld (OldSP),sp
  35. ;;              ld sp,$....
  36. ;;
  37.  
  38. dotStart:
  39.                 ; Wait for the keyboard to be fully released
  40.                 in      a,($fe)
  41.                 cpl
  42.                 and     15
  43.                 jr      nz,dotStart
  44.  
  45.                 ; Store IY
  46.                 ld      (OldIY),iy
  47.  
  48.                 ; Store the MMU state
  49.                 rreg    NR_MMU2
  50.                 ld      (OldMMUs+0),a
  51.                 rreg    NR_MMU3
  52.                 ld      (OldMMUs+1),a
  53.                 rreg    NR_MMU4
  54.                 ld      (OldMMUs+2),a
  55.                 rreg    NR_MMU5
  56.                 ld      (OldMMUs+3),a
  57.                 rreg    NR_MMU6
  58.                 ld      (OldMMUs+4),a
  59.                 rreg    NR_MMU7
  60.                 ld      (OldMMUs+5),a
  61.  
  62.                 ; Set the state of the MMU to a known state.
  63.                 ; This pages in the ULA and sysvars pages.
  64.                 page    2,$0a
  65.                 page    3,$0b
  66.  
  67.                 ; Set the clock speed to 28MHz (because why the hell not?)
  68.                 rreg    NR_CLOCK_SPEED
  69.                 and     3
  70.                 ld      (OldSpeed),a
  71.                 nextreg NR_CLOCK_SPEED,3
  72.  
  73.                 ret
  74.  
  75. ;;----------------------------------------------------------------------------------------------------------------------
  76. ;; dotEnd
  77. ;;
  78. ;; Don't forget to restore interrupts.
  79. ;;
  80.  
  81. dotEnd:
  82.                 di
  83.  
  84.                 ; Restore MMU state
  85.                 ld      a,(OldMMUs+0)
  86.                 page    2,a
  87.                 ld      a,(OldMMUs+1)
  88.                 page    3,a
  89.                 ld      a,(OldMMUs+2)
  90.                 page    4,a
  91.                 ld      a,(OldMMUs+3)
  92.                 page    5,a
  93.                 ld      a,(OldMMUs+4)
  94.                 page    6,a
  95.                 ld      a,(OldMMUs+5)
  96.                 page    7,a
  97.  
  98.                 ld      sp,(OldSP)
  99.                 ld      iy,(OldIY)
  100.                 ld      a,(OldSpeed)
  101.                 reg     NR_CLOCK_SPEED,a
  102.                 ei
  103.                 halt
  104.                 and     a
  105.                 ret
  106. ;;----------------------------------------------------------------------------------------------------------------------
  107. ;; getArg
  108. ;; Obtain the next argument and initialise a null terminated buffer with that argument.
  109. ;;
  110. ;; Input:
  111. ;;      HL = command line
  112. ;;      DE = destination buffer for next argument (256 bytes max)
  113. ;; Output:
  114. ;;      CF = 0: no argument, 1: argument found
  115. ;;      HL = command line following this argument
  116. ;;      BC = length of argument (1..255)
  117.  
  118. getArg:
  119.                 ld      bc,0            ; Initialise size to 0
  120.                 ld      a,h
  121.                 or      l
  122.                 ret     z               ; No arguments
  123. .l1:
  124.                 ld      a,(hl)          ; Fetch next character from command line
  125.                 inc     hl
  126.                 and     a               ; $00 found?
  127.                 ret     z               ; We're done here!
  128.                 cp      $0d             ; Newline?
  129.                 ret     z               ; Also, done here!
  130.                 cp      ':'             ; Colon?
  131.                 ret     z               ; This also finishes.
  132.                 cp      ' '
  133.                 jr      z,.l1           ; Skip spaces
  134.                 cp      '"'             ; Now let's handle quotes
  135.                 jr      z,.quoted
  136.  
  137. .unquoted:
  138.                 ld      (de),a          ; Actual character we want to store
  139.                 inc     de
  140.                 inc     c               ; Increment length (maximum will be 255)
  141.                 jr      z,.bad_size     ; Don't allow >255
  142.  
  143.                 ld      a,(hl)
  144.                 and     a
  145.                 jr      z,.complete
  146.                 cp      $0d
  147.                 jr      z,.complete
  148.                 cp      ':'
  149.                 jr      z,.complete
  150.                 cp      '"'             ; This quote indicates next arg
  151.                 jr      z,.complete
  152.  
  153.                 inc     hl
  154.                 cp      ' '
  155.                 jr      nz,.unquoted
  156.  
  157. .complete:
  158.                 xor     a
  159.                 ld      (de),a          ; terminate the string
  160.  
  161.                 scf                     ; Found argument
  162.                 ret
  163.  
  164. .quoted:
  165.                 ld      a,(hl)
  166.                 and     a
  167.                 jr      z,.complete
  168.                 cp      $0d
  169.                 jr      z,.complete
  170.                 inc     hl
  171.                 cp      '"'
  172.                 jr      z,.complete     ; Found matching quote
  173.  
  174.                 ld      (de),a
  175.                 inc     de
  176.                 inc     c
  177.                 jr      z,.bad_size     ; Don't allow >255
  178.                 jr      .quoted
  179.  
  180. .bad_size:
  181.                 and     a
  182.                 ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement