Home Micro Programmer's Manual

Table of Contents

1 6502 Assembly

The Home Micro uses a MOS Technology 6502 or compatible CPU. To generate code for the CPU to execute, programs are written in 6502 assembly language and translated to machine code using an assembler.

A tutorial on 6502 assembly language can be found at http://obelisk.me.uk/6502/index.html

To convert human-readable assembly language programs into binary code the computer can run, we use an assembler. Programs in the Home Micro repository have been tested with the freely available assembler xa. This assembler can be installed on Raspbian using

sudo aptitude install xa65

2 Simple Program

Here is a simple program for the Home Micro 1000:

        pagesize = 32
        cls = $e003

        * = $0000
        .byt "HM",0,1
        .word _start
        .word pagesize
        .word _endhdr
        .word _end-_start
        .word _start
        .word 0
_endhdr:
        * = $0300
_start:
        jsr cls
        lda #$a0
        sta $2000
        lda #$05
        sta $2001
_halt:
        jmp _halt
_end:

The first few lines of the code define a number of constants. This way, we can use the names in the code, instead of the numeric values. This makes the code easier to read and modify.

The next part is the program header. It describes how to load and run the program and is discussed in more detail in the 3 chapter.

The part of the program that actually does things is after the _start label. It first calls the procedure cls, which clears the screen. It then writes a few bytes to the beginning of video memory, causing some dot patterns to appear. Finally, it enters an infinite loop, repeatedly jumping to the _halt label.

3 Program Header

At startup, the Home Micro looks for a cartridge to load a program from. The program is identified by a header, whose format is given below. As is usual for the 6502, values that span multiple bytes are stored least significant byte first; for example, $1080 would be stored as $80, $10.

Start Length Description
0 2 magic "HM"
2 2 version $00, $01
4 2 entry point
6 2 bytes per page
8 2 position of first byte on cartridge
10 2 number of bytes to load
12 2 address at which to load first byte
14 2 reserved (set to 0)

For example, a header of

48 4D
00 01
00 20
20 00
40 00
00 10
00 30
00 00

would cause the ROM to start reading at cartridge address 64 ($0400) and load 4096 bytes ($1000) into memory starting at address 768 ($0300). Once done loading, it would jump to address 512 ($0200). It would also store 32 ($0020) in the variable that holds the cartridge page size. This value is used when writing to the cartridge.

4 Register and Memory Usage

  • Freely available to user programs:
    • $00 through $7f.
    • $300 through $17ff.
    • $4000 through $57ff.
    • $8000 through $bfff.
  • Available, but not preserved by ROM procedures:
    • Registers a, x, and y.
    • Memory locations $a0 through $af.
  • Available when not used for video (see [Video Modes] for details):
    • $1800 through $3fff.
    • $5800 through $7fff.
  • Reserved memory ranges:
    • $80 through $9f.
    • $b0 through $ff.
    • $200 through $2ff.
    • $c000 through $dfff.
  • ROM:
    • $e000 through $ffff.

5 Video Modes

Mode Bit/Char Pixels Colors Tiles
0 bitmap 320x200 2 no
1 bitmap 160x200 4 no
2 bitmap 320x200 2 yes
3 bitmap 160x200 4 yes
4 character 320x200 2 no
5 character 160x200 4 no
6 character 320x200 2 yes
7 character 160x200 4 yes
-        
9 character 160x200 16 no

5.1 Memory Usage

  • Color tiles enabled (modes 2, 3, 6, 7):
    • $1800..$1be7
    • Alternate: $5800..$5be7
  • Bitmap modes (modes 0..3):
    • $2000..$3f3f.
    • Alternate: $6000..$7f3f.
  • Character modes (modes 4..9):
    • $2000..$23e7.
    • Alternate: $6000..$63e7.
  • Custom character set:
    • Lower: $2800..$2fff.
    • Upper: $6800..$6fff.

5.2 Memory Layout

In bitmap mode:

 $2000 
 $2001 
 $2002 
 $2003 
 $2004 
 $2005 
 $2006 
 $2007 
 $2008 
 $2009 
 $200a 
 $200b 
 $200c 
 $200d 
 $200e 
 $200f 
 $2010 
 $2011 
 $2012 
 $2013 
 $2014 
 $2015 
 $2016 
 $2017 
 .... 
 .... 
 .... 
 .... 
 .... 
 .... 
 .... 
 .... 
 $2138 
 $2139 
 $213a 
 $213b 
 $213c 
 $213d 
 $213e 
 $213f 
 $2140 
 $2141 
 ....  
 $2147 
 $2148 
 $2149 
 ....  
 $214f 
 $2150 
 $2151 
 ....  
 $2157 
 .... 
 .... 
 .... 
 .... 
 $2278 
 $2279 
 ....  
 $227f 
 ....    ....    ....    ....   ....  
 $3e00 
 ....  
 $3e07 
 $3e08 
 ....  
 $3e0f 
 $3e10 
 ....  
 $3e17 
 .... 
 .... 
 .... 
 $3f38 
 ....  
 $3f3f 

In character mode:

$2000 $2001 $2002 …. $2027
$2028 $2029 $202a …. $202f
…. …. …. …. ….
$23c0 $23c1 $23c2 …. $23e7