Advertisement
IsoKilo

AXM68k Compliant Debugger.asm

May 19th, 2023
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
M68000 Assembler 8.62 KB | Source Code | 0 0
  1.  
  2. ; ===============================================================
  3. ; ---------------------------------------------------------------
  4. ; Error handling and debugging modules
  5. ; 2016-2017, Vladikcomper
  6. ; 2023, Kilo (Modified to function with AXM68k modified assembler)
  7. ; ---------------------------------------------------------------
  8. ; Debugging macros definitions file
  9. ; ---------------------------------------------------------------
  10.  
  11.  
  12. ; ===============================================================
  13. ; ---------------------------------------------------------------
  14. ; Constants
  15. ; ---------------------------------------------------------------
  16.  
  17. ; ----------------------------
  18. ; Arguments formatting flags
  19. ; ----------------------------
  20.  
  21. ; General arguments format flags
  22. hex     equ     $80             ; flag to display as hexadecimal number
  23. deci    equ     $90             ; flag to display as decimal number
  24. bin     equ     $A0             ; flag to display as binary number
  25. sym     equ     $B0             ; flag to display as symbol (treat as offset, decode into symbol +displacement, if present)
  26. symdisp equ     $C0             ; flag to display as symbol's displacement alone (DO NOT USE, unless complex formatting is required, see notes below)
  27. str     equ     $D0             ; flag to display as string (treat as offset, insert string from that offset)
  28.  
  29. ; NOTES:
  30. ;   * By default, the "sym" flag displays both symbol and displacement (e.g.: "Map_Sonic+$2E")
  31. ;       In case, you need a different formatting for the displacement part (different text color and such),
  32. ;       use "sym|split", so the displacement won't be displayed until symdisp is met
  33. ;   * The "symdisp" can only be used after the "sym|split" instance, which decodes offset, otherwise, it'll
  34. ;       display a garbage offset.
  35. ;   * No other argument format flags (hex, dec, bin, str) are allowed between "sym|split" and "symdisp",
  36. ;       otherwise, the "symdisp" results are undefined.
  37. ;   * When using "str" flag, the argument should point to string offset that will be inserted.
  38. ;       Arguments format flags CAN NOT be used in the string (as no arguments are meant to be here),
  39. ;       only console control flags (see below).
  40.  
  41.  
  42. ; Additional flags ...
  43. ; ... for number formatters (hex, dec, bin)
  44. signed  equ     8               ; treat number as signed (display + or - before the number depending on sign)
  45.  
  46. ; ... for symbol formatter (sym)
  47. split   equ     8               ; DO NOT write displacement (if present), skip and wait for "symdisp" flag to write it later (optional)
  48. forced  equ     4               ; display "<unknown>" if symbol was not found, otherwise, plain offset is displayed by the displacement formatter
  49.  
  50. ; ... for symbol displacement formatter (symdisp)
  51. weak    equ     8               ; DO NOT write plain offset if symbol is displayed as "<unknown>"
  52.  
  53. ; Argument type flags:
  54. ; - DO NOT USE in formatted strings processed by macros, as these are included automatically
  55. ; - ONLY USE when writting down strings manually with DC.B
  56. byte    equ     0
  57. word    equ     1
  58. long    equ     3
  59.  
  60. ; -----------------------
  61. ; Console control flags
  62. ; -----------------------
  63.  
  64. ; Plain control flags: no arguments following
  65. endl    equ     $E0             ; "End of line": flag for line break
  66. cr      equ     $E6             ; "Carriage return": jump to the beginning of the line
  67. pal0    equ     $E8             ; use palette line #0
  68. pal1    equ     $EA             ; use palette line #1
  69. pal2    equ     $EC             ; use palette line #2
  70. pal3    equ     $EE             ; use palette line #3
  71.  
  72. ; Parametrized control flags: followed by 1-byte argument
  73. setw    equ     $F0             ; set line width: number of characters before automatic line break
  74. setoff  equ     $F4             ; set tile offset: lower byte of base pattern, which points to tile index of ASCII character 00
  75. setpat  equ     $F8             ; set tile pattern: high byte of base pattern, which determines palette flags and $100-tile section id
  76. setx    equ     $FA             ; set x-position
  77.  
  78.  
  79.  
  80. ; ---------------------------------------------------------------
  81. ; Macros
  82. ; ---------------------------------------------------------------
  83.  
  84. RaiseError &
  85.     macro   string, console_program, opts
  86.  
  87.     pea     *(pc)
  88.     move.w  sr, -(sp)
  89.     __FSTRING_GenerateArgumentsCode \string
  90.     jsr     ErrorHandler
  91.     __FSTRING_GenerateDecodedString \string
  92.     if strlen("\console_program")           ; if console program offset is specified ...
  93.         dc.b    \opts+_eh_enter_console|(((*&1)^1)*_eh_align_offset)    ; add flag "_eh_align_offset" if the next byte is at odd offset ...
  94.         even                                                            ; ... to tell Error handler to skip this byte, so it'll jump to ...
  95.         jmp     \console_program                                        ; ... an aligned "jmp" instruction that calls console program itself
  96.     else
  97.         dc.b    \opts+0                     ; otherwise, just specify \opts for error handler, +0 will generate dc.b 0 ...
  98.         even                                ; ... in case \opts argument is empty or skipped
  99.     endc
  100.     even
  101.  
  102.     endm
  103.  
  104. ; ---------------------------------------------------------------
  105. Console &
  106.     macro
  107.  
  108.     if strcmp("\0","write")|strcmp("\0","writeline")
  109.         move.w  sr, -(sp)
  110.         __FSTRING_GenerateArgumentsCode \1
  111.         movem.l a0-a2/d7, -(sp)
  112.         if (__sp>0)
  113.             lea     4*4(sp), a2
  114.         endc
  115.         lea     @str\@(pc), a1
  116.         jsr     ErrorHandler.__global__console_\0\_formatted
  117.         movem.l (sp)+, a0-a2/d7
  118.         if (__sp>8)
  119.             lea     __sp(sp), sp
  120.         elseif (__sp>0)
  121.             addq.w  #__sp, sp
  122.         endc
  123.         move.w  (sp)+, sr
  124.         bra.w   @instr_end\@
  125.     @str\@:
  126.         __FSTRING_GenerateDecodedString \1
  127.         even
  128.     @instr_end\@:
  129.  
  130.     elseif strcmp("\0","run")
  131.         jsr     ErrorHandler.__extern__console_only
  132.         jsr     \1
  133.         bra.s   *
  134.  
  135.     elseif strcmp("\0","setxy")
  136.         move.w  sr, -(sp)
  137.         movem.l d0-d1, -(sp)
  138.         move.w  \2, -(sp)
  139.         move.w  \1, -(sp)
  140.         jsr     ErrorHandler.__global__console_setposasxy_stack
  141.         addq.w  #4, sp
  142.         movem.l (sp)+, d0-d1
  143.         move.w  (sp)+, sr
  144.  
  145.     elseif strcmp("\0","breakline")
  146.         move.w  sr, -(sp)
  147.         jsr     ErrorHandler.__global__console_startnewline
  148.         move.w  (sp)+, sr
  149.  
  150.     else
  151.         inform  2,"""\0"" isn't a member of ""Console"""
  152.  
  153.     endc
  154.     endm
  155.  
  156. ; ---------------------------------------------------------------
  157. __ErrorMessage &
  158.     macro   string, opts
  159.         __FSTRING_GenerateArgumentsCode \string
  160.         jsr     ErrorHandler
  161.         __FSTRING_GenerateDecodedString \string
  162.         dc.b    \opts+0
  163.         even
  164.  
  165.     endm
  166.  
  167. ; ---------------------------------------------------------------
  168. __FSTRING_GenerateArgumentsCode &
  169.     macro   string
  170.  
  171.     __pos:  =   instr(\string,'%<')     ; token position
  172.     __stack:=       0                       ; size of actual stack
  173.     __sp:   =       0                       ; stack displacement
  174.  
  175.     ; Parse string itself
  176.     while (__pos)
  177.  
  178.         ; Retrive expression in brackets following % char
  179.         __endpos:   =       instr(__pos+1,\string,'>')
  180.         __midpos:   =       instr(__pos+5,\string,' ')
  181.         if (__midpos<1)|(__midpos>__endpos)
  182.             __midpos: = __endpos
  183.         endc
  184.         __substr:   substr  __pos+1+1,__endpos-1,\string            ; .type ea param
  185.         __type:     substr  __pos+1+1,__pos+1+1+1,\string           ; .type
  186.  
  187.         ; Expression is an effective address (e.g. %(.w d0 hex) )
  188.         if "\__type">>8="."
  189.             __operand:  substr  __pos+1+1,__midpos-1,\string            ; .type ea
  190.             __param:    substr  __midpos+1,__endpos-1,\string           ; param
  191.  
  192.             if "\__type"=".b"
  193.                 pushp   "move\__operand\,1(sp)"
  194.                 pushp   "subq.w #2, sp"
  195.                 __stack: = __stack+2
  196.                 __sp: = __sp+2
  197.  
  198.             elseif "\__type"=".w"
  199.                 pushp   "move\__operand\,-(sp)"
  200.                 __stack: = __stack+1
  201.                 __sp: = __sp+2
  202.  
  203.             elseif "\__type"=".l"
  204.                 pushp   "move\__operand\,-(sp)"
  205.                 __stack: = __stack+1
  206.                 __sp: = __sp+4
  207.  
  208.             else
  209.                 fatal 'Unrecognized type in string operand: %<\__substr>'
  210.             endc
  211.         endc
  212.  
  213.         __pos:  =       instr(__pos+1,\string,'%<')
  214.     endw
  215.  
  216.     ; Generate stack code
  217.     rept __stack
  218.         popp    __command
  219.         \__command
  220.     endr
  221.  
  222.     endm
  223.  
  224. ; ---------------------------------------------------------------
  225. __FSTRING_GenerateDecodedString &
  226.     macro string
  227.  
  228.     __lpos: =       1                       ; start position
  229.     __pos:  =   instr(\string,'%<')     ; token position
  230.  
  231.     while (__pos)
  232.  
  233.         ; Write part of string before % token
  234.         __substr:   substr  __lpos,__pos-1,\string
  235.         dc.b    "\__substr"
  236.  
  237.         ; Retrive expression in brakets following % char
  238.         __endpos:   =       instr(__pos+1,\string,'>')
  239.         __midpos:   =       instr(__pos+5,\string,' ')
  240.         if (__midpos<1)|(__midpos>__endpos)
  241.             __midpos: = __endpos
  242.         endc
  243.         __type:     substr  __pos+1+1,__pos+1+1+1,\string           ; .type
  244.  
  245.         ; Expression is an effective address (e.g. %<.w d0 hex> )
  246.         if "\__type">>8="."    
  247.             __param:    substr  __midpos+1,__endpos-1,\string           ; param
  248.             if strlen("\__param")<1
  249.                 __param: substr ,,"hex"         ; if param is ommited, set it to "hex"
  250.             endc
  251.             if "\__type"=".b"
  252.                 dc.b    \__param
  253.             elseif "\__type"=".w"
  254.                 dc.b    \__param|1
  255.             else
  256.                 dc.b    \__param|3
  257.             endc
  258.  
  259.         ; Expression is an inline constant (e.g. %<endl> )
  260.         else
  261.             __substr:   substr  __pos+1+1,__endpos-1,\string
  262.             dc.b    \__substr
  263.         endc
  264.  
  265.         __lpos: =       __endpos+1
  266.         __pos:  =       instr(__pos+1,\string,'%<')
  267.     endw
  268.  
  269.     ; Write part of string before the end
  270.     __substr:   substr  __lpos,,\string
  271.     dc.b    "\__substr"
  272.     dc.b    0
  273.  
  274.     endm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement