home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / emulaton / utilities / magicasm / pce_code / docs / as < prev    next >
Encoding:
Text File  |  1998-03-01  |  17.6 KB  |  451 lines

  1.  
  2.  -*[ MAGIC ASM v1.2 ]*-
  3.     ----------------
  4.  
  5.         Magic-ASM is an assembler for the HuC6280, the main CPU of
  6.         the PC Engine console. This processor is based on the well
  7.         known 6502 processor, if you are familiar with it you will
  8.         pass easily to the HuC6820, otherwise a good book on the
  9.         6502 will give you all the bases.
  10.  
  11.         The assembler seems to be bug free but if you find something
  12.         abnormal or if you have a nice idea for improving the program,
  13.         feel free to contact me, my e-mail address is at the bottom
  14.         of this file.
  15.  
  16.  
  17.     History
  18.     -------
  19.  
  20.         v0.1 : 12/Jun/97
  21.  
  22.                - modified an old 6502 assembler
  23.                - added support for most of the HuC6280 instructions
  24.  
  25.         v0.2 : 18/Jun/97
  26.  
  27.                - added the .INCLUDE directive
  28.                - added a trap for divisions by zero
  29.  
  30.         v0.3 : 26/Jun/97
  31.  
  32.                - corrected a bug with undefined symbols
  33.                - rewritten all the symbol routines and added local
  34.                  symbols
  35.                - enhanced a bit the format of the listing file
  36.  
  37.         v0.4 : 02/Jul/97
  38.  
  39.                - added all the missing instructions : BBRi, BBSi
  40.                  TST, TII, TDD, TIN, TIA and TAI
  41.                - changed some error messages
  42.                - added two functions : HIGH, LOW
  43.  
  44.         v1.0 : 06/Jul/97
  45.  
  46.                - rewritten the expression parser
  47.                - added support for PCX file
  48.                - added new functions PAGE and BANK [thanks Dave!]
  49.                - corrected lots of minor bugs
  50.  
  51.         v1.1 : 15/Jul/97 [first release]
  52.  
  53.                - added macro support
  54.                - modified the ORG directive and removed the PAGE
  55.                  directive
  56.                - corrected a few bugs (PCX and MACRO code)
  57.                - added a small demo
  58.  
  59.         v1.2 : 28/Feb/98 [private release]
  60.  
  61.                - fixed a bug in the PCX decoding function;
  62.                  the palette was not always decoded
  63.                - added two new directives: RSSET and RS
  64.                - labels can now be placed everywhere in a line;
  65.                  just add a ':' after the label if it doesn't
  66.                  start on the first column
  67.                - new syntax for binary numbers; the character
  68.                  '_' is now allowed in the number: %1001_1000,
  69.                  it's useful to split different fields
  70.                - many minor bug fixes here and there
  71.                - source codes included
  72.  
  73.  
  74.     Usage
  75.     -----
  76.  
  77.         Usage is very simple, the assembler accept only one argument
  78.         on the command line : the name of an asm file (the .ASM
  79.         extension can be omitted). The assembler will create a
  80.         complete listing file (.LST) if the LIST directive is used
  81.         in the asm file, and a ROM file (.PCE) directly usuable by
  82.         an emulator like VPCE or MagicEngine. The limit for the ROM
  83.         file is 1MB.
  84.  
  85.  
  86.     Instructions set
  87.     ----------------
  88.  
  89.         +------+----------+-----------------------------+
  90.         |      | NVTBDIZC | Description                 |
  91.         +------+----------+-----------------------------+
  92.         | ADC  | XX0---XX | Add with Carry              |
  93.         | AND  | X-0---X- | Logical AND                 |
  94.         | ASL  | X-0---XX | Arithmetic Shift left       |
  95.         | BBRi | --0----- | Branch if Bit Reset         |
  96.         | BBSi | --0----- | Branch if Bit Set           |
  97.         | BCC  | --0----- | Branch if Carry Clear       |
  98.         | BCS  | --0----- | Branch if Carry Set         |
  99.         | BEQ  | --0----- | Branch if Equal             |
  100.         | BIT  | XX0---X- | Bit Test                    |
  101.         | BMI  | --0----- | Branch if Minus             |
  102.         | BNE  | --0----- | Branch if Not Equal         |
  103.         | BPL  | --0----- | Branch if Plus              |
  104.         | BRA  | --0----- | Branch Always               |
  105.         | BRK  | --0----- | Break                       |
  106.         | BSR  | --0----- | Branch Sub Routine          |
  107.         | BVC  | --0----- | Branch if Overflow Clear    |
  108.         | BVS  | --0----- | Branch if Overflow Set      |
  109.         | CLA  | --0----- | Clear A                     |
  110.         | CLC  | --0----0 | Clear Carry flag            |
  111.         | CLD  | --0-0--- | Clear Decimal flag          |
  112.         | CLI  | --0--0-- | Clear Interrupt disable     |
  113.         | CLV  | -00----- | Clear Overflow flag         |
  114.         | CLX  | --0----- | Clear X                     |
  115.         | CLY  | --0----- | Clear Y                     |
  116.         | CMP  | X-0---XX | Compare A with source       |
  117.         | CPX  | X-0---XX | Compare X with source       |
  118.         | CPY  | X-0---XX | Compare Y with source       |
  119.         | CSH  | --0----- | Clock Select High           |
  120.         | CSL  | --0----- | Clock Select Low            |
  121.         | DEC  | X-0---X- | Decrement                   |
  122.         | DEX  | X-0---X- | Decrement X                 |
  123.         | DEY  | X-0---X- | Decrement Y                 |
  124.         | EOR  | X-0---X- | Logical Exclusive OR        |
  125.         | INC  | X-0---X- | Increment                   |
  126.         | INX  | X-0---X- | Increment X                 |
  127.         | INY  | X-0---X- | Increment Y                 |
  128.         | JMP  | --0----- | Jump                        |
  129.         | JSR  | --0----- | Jump to Sub Routine         |
  130.         | LDA  | X-0---X- | Load A                      |
  131.         | LDX  | X-0---X- | Load X                      |
  132.         | LDY  | X-0---X- | Load Y                      |
  133.         | LSR  | 0-0---XX | Logical Shift Right         |
  134.         | NOP  | --0----- | No Operation                |
  135.         | OR   | X-0---X- | Logical inclusive OR        |
  136.         | PHA  | --0----- | Push A                      |
  137.         | PHP  | --0----- | Push P                      |
  138.         | PHX  | --0----- | Push X                      |
  139.         | PHY  | --0----- | Push Y                      |
  140.         | PLA  | X-0---X- | Pull A                      |
  141.         | PLP  | XXXXXXXX | Pull P                      |
  142.         | PLX  | X-0---X- | Pull X                      |
  143.         | PLY  | X-0---X- | Pull Y                      |
  144.         | RMBi | --0----- | Reser Memory Bit            |
  145.         | ROL  | X-0---XX | Rotate Left                 |
  146.         | ROR  | X-0---XX | Rotate Right                |
  147.         | RTI  | XXXXXXXX | Return from Interrupt       |
  148.         | RTS  | --0----- | Return from Sub Routine     |
  149.         | SAX  | --0----- | Swap A and X                |
  150.         | SAY  | --0----- | Swap A and Y                |
  151.         | SBC  | XX0---XX | Substract with Carry        |
  152.         | SEC  | --0----1 | Set Carry flag              |
  153.         | SED  | --0-1--- | Set Decimal flag            |
  154.         | SEI  | --0--1-- | Set Interrupt disable       |
  155.         | SET  | --1----- | Set T flag                  |
  156.         | SMBi | --0----- | Set Memory Bit              |
  157.         | ST0  | --0----- | Store into HuC6270 port 0   |
  158.         | ST1  | --0----- | Store into HuC6270 port 2   |
  159.         | ST2  | --0----- | Store into HuC6270 port 3   |
  160.         | STA  | --0----- | Store A                     |
  161.         | STX  | --0----- | Store X                     |
  162.         | STY  | --0----- | Store Y                     |
  163.         | STZ  | --0----- | Store Zero                  |
  164.         | SXY  | --0----- | Swap X and Y                |
  165.         | TAI  | --0----- | Transfer block              |
  166.         | TAMi | --0----- | Transfer A to MPRi          |
  167.         | TAX  | X-0---X- | Transfer A to X             |
  168.         | TAY  | X-0---X- | Transfer A to Y             |
  169.         | TDD  | --0----- | Transfer block              |
  170.         | TIA  | --0----- | Transfer block              |
  171.         | TII  | --0----- | Transfer block              |
  172.         | TIN  | --0----- | Transfer block              |
  173.         | TMAi | --0----- | Transfer MPRi to A          |
  174.         | TRB  | XX0---X- | Test and Reset Bit          |
  175.         | TSB  | XX0---X- | Test and Set Bit            |
  176.         | TST  | XX0---X- | Test memory                 |
  177.         | TSX  | X-0---X- | Transfer S to X             |
  178.         | TXA  | X-0---X- | Transfer X to A             |
  179.         | TXS  | --0----- | Transfer X to S             |
  180.         | TYA  | X-0---X- | Transfer Y to A             |
  181.         +------+----------+-----------------------------+
  182.  
  183.  
  184.     Operand syntax
  185.     --------------
  186.  
  187.         A        accumulator
  188.         #i       immediate
  189.         #i,<n    immediate and zero page              | 
  190.         #i,<n,X  immediate and zero page indexed by X | TST
  191.         #i,n     immediate and absolute               | 
  192.         #i,n,X   immediate and absolute indexed by X  |
  193.         <n       zero page
  194.         <n,X     zero page indexed by X
  195.         <n,Y     zero page indexed by Y
  196.         <n,r     zero page and relative               | BBRi/BBSi
  197.         [n]      indirect (*)
  198.         [n,X]    indirect pre-indexed by X (*)
  199.         [n],Y    indirect zero page post-indexed by Y
  200.         r        relative                             | BRA/BSR/Bcc
  201.         n        absolute
  202.         n,X      absolute indexed by X
  203.         n,Y      absolute indexed by Y
  204.         n,n,n    source, destination, length          | TAI/TIA/TII/TIN/TDD
  205.  
  206.         (*) can be zero page or absolute
  207.  
  208.  
  209.     Symbols
  210.     -------
  211.  
  212.         Two types of symbol are supported, global symbols and local
  213.         symbols. Local symbols are preceded by a dot '.' and are 
  214.         valid only between two global symbols. A symbol can be 
  215.         followed by a colon ':' but this is not necessary.
  216.  
  217.  
  218.     Expressions
  219.     -----------
  220.  
  221.         The assembler supports very complex expressions. You can
  222.         use as many level of parenthesis as you want and spaces
  223.         between operators and numbers are possible. For the
  224.     priority, the same rules as C apply.
  225.  
  226.         Numbers can be written in four base : hexa ($), octal (&),
  227.         binary (%) and decimal. Character values are also supported
  228.         (ie. 'A') and all the usual operators are present :
  229.         +, -, *, /, %, ^, &, |, ~, <<, >>.
  230.  
  231.         In an expression four predefined functions can be used too :
  232.  
  233.             HIGH(), return the high byte of a number.
  234.  
  235.             LOW(),  return the low byte.
  236.  
  237.             BANK(), return the bank index of a symbol. If no
  238.                     symbol, or more than one, are given, the
  239.                     function return an error.
  240.  
  241.             PAGE(), return the page index of a symbol.
  242.                     See BANK for errors.
  243.  
  244.  
  245.     Macros
  246.     ------
  247.  
  248.         Up to nine parameters, \1 to \9, can be used in a macro call.
  249.         There's also a special parameter \@ that returns a different
  250.         number for each macro; it is used to make local symbols inside
  251.         a macro :
  252.  
  253.             abs     macro
  254.                      lda   \1
  255.                      bpl   .x\@
  256.                      eor   #$FF
  257.                      inc   A
  258.                      sta   \1
  259.             .x\@:
  260.                     endm
  261.  
  262.  
  263.     Directives
  264.     ----------
  265.  
  266.  
  267.         LIST,    tell the assembler that you want a complete listing
  268.                  file. You can later stop temporarily the output with
  269.                  the NOLIST directive and restart it with LIST.
  270.  
  271.         NOLIST,  stop the listing output.
  272.  
  273.         MLIST,   include the macros in the listing file.
  274.  
  275.         NOMLIST, stop expanding macros in the listing file.
  276.  
  277.         EQU,     assign a value to a symbol. The character '=' has
  278.                  the same function too.
  279.  
  280.         BANK,    select a ROM bank (0-127) and reset the location
  281.                  counter to the latest known position in this bank.
  282.  
  283.         ORG,     set the location of the program counter. The thirteen
  284.                  lower bits of the address inform the assembler about
  285.                  the offset in the ROM bank and the third upper bits
  286.                  represent the page index.
  287.  
  288.         DB,      data byte(s).
  289.  
  290.         DW,      data word(s).
  291.  
  292.         RSSET,   set the internal counter of the RS directive to 
  293.                  a specified value.
  294.  
  295.         RS,      assign a value to a symbol; a bit like EQU but here
  296.                  the value assigned is taken from an internal counter
  297.                  and after the assignation this counter is increased
  298.                  by the value specified in the RS directive.
  299.                  It's a very handy way of defining variables, here's
  300.                  a small example:
  301.  
  302.                              .rsset $2000 ; set the initial value of
  303.                                           ; the RS internal counter
  304.                      my_byte .rs 1        ; define a var of 1 byte
  305.                      my_word .rs 2        ;        "        2 bytes
  306.  
  307.         MACRO,   start a macro definition.
  308.  
  309.         ENDM,    end a macro definition.
  310.  
  311.         INCBIN,  include a binary file at the current location. If
  312.                  the file is bigger than a ROM bank, as many successive
  313.                  banks as necessary will be filled and the bank and
  314.                  the location counter will be updated.
  315.  
  316.         INCLUDE, include a source file at the current location.
  317.                  Up to 7 levels are possible.
  318.  
  319.         INCCHR,     extract a part of a PCX file and convert it to
  320.                  the graphic format used by background characters.
  321.                  Three syntaxes are possible :
  322.  
  323.                  INCCHR "pic.pcx"
  324.  
  325.                      without additional parameters, the command
  326.                      convert the whole PCX file.
  327.  
  328.                  INCCHR "pic.pcx",32,4
  329.  
  330.                      tell the assembler to convert only 4 rows
  331.                      of 32 characters (a character size is 8x8).
  332.  
  333.                  INCCHR "pic.pcx",48,16,32,4
  334.  
  335.                      same as above but start extracting characters
  336.                      from coordinate 48,16 (in pixels).
  337.  
  338.         INCSPR,     same as INCCHR but for sprites; note that
  339.                  the size of a sprite character is 16x16.
  340.  
  341.         INCPAL,     extract the palette of a PCX file. If no extra
  342.                  parameters are given all the 256 colors are loaded
  343.                  and converted. The first parameter indicates from
  344.                  what sub-palette to start (a sub-palette is a
  345.                  block of 16 colors). The second parameter is the
  346.                  number of sub-palette to extract; if omitted one
  347.                  is used instead.
  348.  
  349.  
  350.     HuC6280 banks mechanism
  351.     -----------------------
  352.  
  353.         To access more than the usual 64KB, the HuC6280 uses a MMU
  354.         that splits the address space in 8 pages of 8KB. For each
  355.         page there's a 8-bit register (MPRi) that contains the bank
  356.         index for this page. There are two special instructions that
  357.         access the MPRi registers :
  358.  
  359.             TAMi, transfer the content of the accumulator (A) to
  360.                   the MPRi register.
  361.  
  362.             TMAi, transfert the MPRi register to the accumulator.
  363.  
  364.         Banks map :
  365.  
  366.             $00-$7F ROM
  367.             $F7     battery backed RAM
  368.             $F8     RAM
  369.             $FF     I/O page
  370.  
  371.         There's a sort of standard for pages mapping. You are not
  372.         obliged to respect it, but it would be nice if you plan to
  373.         share your source code...
  374.  
  375.             page 0 -> bank $FF (I/O)
  376.             page 1 -> bank $F8 (RAM)
  377.             page 2 ->  |
  378.             page 3 ->  | user
  379.             page 4 ->  | definable
  380.             page 5 ->  |
  381.             page 6 ->  |
  382.             page 7 -> bank $00
  383.  
  384.         NOTE : After a RESET all the pages are mapped to bank $00.
  385.  
  386.  
  387.     PC Engine hardware registers map
  388.     --------------------------------
  389.  
  390.         Details of the I/O page :
  391.  
  392.             $0000-$0003 HuC6270, Video Display Controller (VDC)
  393.             $0400-$0407 AuC6260, Video Colour Encoder (VCE)
  394.             $0800-$080F Programmable Sound Generator (PSG)
  395.             $0C00-$0C01 Timer
  396.             $1000       External port (gamepad)
  397.             $1402       Interrupt disable register
  398.             $1403       Interrupt request register
  399.  
  400.         NOTE : I know, this summary is very simple. :) For a
  401.                detailled description of the PC Engine hardware
  402.                check the homepage of VPCE's author : Jens Ch.
  403.                Restemeier. You won't be disappointed, Jens
  404.                has put all his knowledge of the PC Engine
  405.                in a nice documentation. [Nice job Jens!]
  406.  
  407.             <http://www.geocities.com/SiliconValley/Way/3340/>
  408.  
  409.                Follow the 'projects' link.
  410.  
  411.                Another very interesting and excellent documentation
  412.                to check is the VDC documentation of Emanuel
  413.                Schleussinger. You will find it on his homepage:
  414.  
  415.             <http://www.classicgaming.com/aec/>
  416.  
  417.  
  418.     HuC6280 IRQ vectors
  419.     -------------------
  420.  
  421.         $FFF6   IRQ2   (BRK)
  422.         $FFF8   IRQ1   (VDC)
  423.         $FFFA   TIMER
  424.         $FFFC   NMI
  425.         $FFFE   RESET
  426.  
  427.  
  428.     Thanks to
  429.     ---------
  430.  
  431.         - Jens Ch. Restemeier and Emanuel Schleussinger, for making
  432.             those excellent documentations on the PC Engine hardware.
  433.  
  434.         - J. H. Van Ornum, for his old 6502 assembler (11/May/84).
  435.             I used his sources as a base for the assembler.
  436.  
  437.         - DJ Delorie, for DJGPP.
  438.             If you search for a fast, good and free C compiler,
  439.             go to : <http://www.delorie.com/djgpp>
  440.  
  441.         - Charles Sandmann, for CWSDPMI.
  442.             A pretty good DPMI server.
  443.             <ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2misc/csdpmi*.zip>
  444.  
  445.         and to you if you like this program!
  446.  
  447.  
  448.  ------------
  449.  David Michel <dmichel@easynet.fr>
  450.  
  451.